Integrate graphics, RAW, audio and CAD Craft tools with protected saves
This commit is contained in:
1 parent
6e36b6c4b7
commit
852140c3a7
24 files changed
+600
-74
No files matched your search
@@ -1,5 +1,11 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { craftLocation, craftMessage, safeCraftName } from "../craft";
|
||||
import {
|
||||
addonAccepts,
|
||||
craftSaveExtension,
|
||||
craftLocation,
|
||||
craftMessage,
|
||||
safeCraftName,
|
||||
} from "../craft";
|
||||
it("accepts messages only from the specific same-origin editor frame", () => {
|
||||
const frame = {} as Window,
|
||||
origin = "https://files.test";
|
||||
@@ -66,3 +72,15 @@ it("preserves encoded names in standalone editor links", () => {
|
||||
expect(location.query.path).toBe("/folder name/report #1%.xlsx");
|
||||
expect(location.params.addon).toBe("gridcraft");
|
||||
});
|
||||
|
||||
it("distinguishes editable outputs from import-only formats", () => {
|
||||
const raw = {
|
||||
extension: ".dng",
|
||||
extensions: [".dng", ".jpg"],
|
||||
exports: [".jpg", ".png"],
|
||||
} as import("@/stores/addons").Addon;
|
||||
expect(addonAccepts(raw, "PHOTO.DNG")).toBe(true);
|
||||
expect(craftSaveExtension(raw, "PHOTO.DNG")).toBeUndefined();
|
||||
expect(craftSaveExtension(raw, "edited.jpg")).toBe(".jpg");
|
||||
expect(addonAccepts(raw, "notes.txt")).toBe(false);
|
||||
});
|
||||
@@ -6,7 +6,7 @@ const source = readFileSync(
|
||||
new URL("../../../../http/craft_bridge.js", import.meta.url),
|
||||
"utf8"
|
||||
);
|
||||
function bridge(id = "wordcraft") {
|
||||
function bridge(id = "wordcraft", config?: Record<string, unknown>) {
|
||||
const messages: any[] = [],
|
||||
events = new Map<string, (event: any) => void>();
|
||||
const parent = { postMessage: (message: any) => messages.push(message) };
|
||||
@@ -27,6 +27,7 @@ function bridge(id = "wordcraft") {
|
||||
LocalURL.createObjectURL = () => "blob:test/" + ++counter;
|
||||
LocalURL.revokeObjectURL = vi.fn();
|
||||
const context: any = {
|
||||
__filebrowserCraft: config,
|
||||
parent,
|
||||
location: {
|
||||
pathname: `/addons/${id}/build/index.html`,
|
||||
@@ -145,3 +146,27 @@ it("captures presentation saves but preserves native downloads for unrelated exp
|
||||
link.click();
|
||||
expect(nativeClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("adapts verified graphics, layout, RAW and audio builds without changing office defaults", () => {
|
||||
for (const [id, extension, output] of [
|
||||
["photocraft", ".png", ".pcraft"],
|
||||
["designcraft", ".designcraft", ".designcraft"],
|
||||
["figcraft", ".figcraft", ".figcraft"],
|
||||
["lightcraft", ".dng", ".jpg"],
|
||||
["soundcraft", ".wav", ".scraftz"],
|
||||
]) {
|
||||
const { receive, canvas, messages } = bridge(id, {
|
||||
id,
|
||||
extension,
|
||||
extensions: [extension],
|
||||
exports: [output],
|
||||
});
|
||||
expect(messages[0].type).toBe(id + ":ready");
|
||||
receive({
|
||||
type: id + ":open",
|
||||
name: "source" + extension,
|
||||
bytes: new ArrayBuffer(8),
|
||||
});
|
||||
expect(canvas.dispatchEvent).toHaveBeenCalledTimes(1);
|
||||
}
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Addon } from "@/stores/addons";
|
||||
import type { Router } from "vue-router";
|
||||
|
||||
export function craftLocation(id: string, fileURL: string) {
|
||||
@@ -54,3 +55,18 @@ export function craftMessage(
|
||||
error?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function addonAccepts(addon: Addon, name: string) {
|
||||
return (addon.extensions || [addon.extension]).some((extension) =>
|
||||
name.toLowerCase().endsWith(extension)
|
||||
);
|
||||
}
|
||||
export function craftSaveExtension(
|
||||
addon: Addon,
|
||||
name: unknown
|
||||
): string | undefined {
|
||||
if (typeof name !== "string") return undefined;
|
||||
return (addon.exports || [addon.extension, ".pdf"]).find((extension) =>
|
||||
name.toLowerCase().endsWith(extension)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user