Open Craft editors in standalone tabs and improve addon settings

This commit is contained in:
SantaSpeen committed 2026-10-22 19:02:35 +03:00
1 parent 5cb1b463ea
commit bc9709e500
16 files changed
+277 -162

No files matched your search

+11 -1
View File
@@ -1,5 +1,5 @@
import { expect, it } from "vitest";
import { craftMessage, safeCraftName } from "../craft";
import { craftLocation, craftMessage, safeCraftName } from "../craft";
it("accepts messages only from the specific same-origin editor frame", () => {
const frame = {} as Window,
origin = "https://files.test";
@@ -56,3 +56,13 @@ it("validates save-as filenames without allowing paths or another file type", ()
])
expect(safeCraftName(name, ".xlsx")).toBeNull();
});
it("preserves encoded names in standalone editor links", () => {
const location = craftLocation(
"gridcraft",
"/files/folder%20name/report%20%231%25.xlsx"
);
expect(location.name).toBe("CraftEditor");
expect(location.query.path).toBe("/folder name/report #1%.xlsx");
expect(location.params.addon).toBe("gridcraft");
});
+17
View File
@@ -1,3 +1,20 @@
import type { Router } from "vue-router";
export function craftLocation(id: string, fileURL: string) {
return {
name: "CraftEditor",
params: { addon: id },
query: { path: decodeURIComponent(fileURL.replace(/^\/files/, "")) },
};
}
export function openCraftTab(router: Router, id: string, fileURL: string) {
window.open(
router.resolve(craftLocation(id, fileURL)).href,
"_blank",
"noopener,noreferrer"
);
}
export function safeCraftName(name: unknown, extension: string): string | null {
if (
typeof name !== "string" ||