@eclipse-docks/extension-canvas 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/active-canvas.d.ts +4 -0
- package/dist/active-canvas.d.ts.map +1 -1
- package/dist/active-canvas.js +10 -1
- package/dist/active-canvas.js.map +1 -1
- package/dist/canvas-editor.d.ts +9 -0
- package/dist/canvas-editor.d.ts.map +1 -1
- package/dist/canvas-editor.js +69 -25
- package/dist/canvas-editor.js.map +1 -1
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +23 -18
- package/dist/commands.js.map +1 -1
- package/dist/workspace-file.d.ts +2 -2
- package/dist/workspace-file.d.ts.map +1 -1
- package/dist/workspace-file.js +7 -4
- package/dist/workspace-file.js.map +1 -1
- package/package.json +1 -1
- package/skills/eclipse-docks-canvas/SKILL.md +31 -3
- package/skills/eclipse-docks-core/SKILL.md +1 -1
- package/skills/eclipse-docks-webawesome/SKILL.md +2 -1
package/dist/active-canvas.d.ts
CHANGED
|
@@ -6,12 +6,16 @@ export interface ActiveCanvas {
|
|
|
6
6
|
getContent?: () => string | null;
|
|
7
7
|
getFilePath?: () => string | null;
|
|
8
8
|
setSource?: (source: string) => void;
|
|
9
|
+
save?: () => Promise<void>;
|
|
10
|
+
syncFromFile?: () => Promise<boolean>;
|
|
9
11
|
reload?: () => Promise<string>;
|
|
10
12
|
capturePreview?: () => Promise<PreviewShot>;
|
|
11
13
|
getState?: (key: string) => unknown;
|
|
12
14
|
setState?: (key: string, value: unknown) => void;
|
|
13
15
|
}
|
|
14
16
|
export declare function readActiveCanvas(): ActiveCanvas | null;
|
|
17
|
+
/** Connected workspace canvas editors. Optional path keeps only that file. */
|
|
18
|
+
export declare function connectedWorkspaceEditors(path?: string): ActiveCanvas[];
|
|
15
19
|
/** Active canvas editor, or any open canvas part when focus has moved elsewhere. */
|
|
16
20
|
export declare function findOpenCanvas(): ActiveCanvas | null;
|
|
17
21
|
//# sourceMappingURL=active-canvas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-canvas.d.ts","sourceRoot":"","sources":["../src/active-canvas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,WAAW,GAAG,YAAY,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAClC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpD;AAED,wBAAgB,gBAAgB,IAAI,YAAY,GAAG,IAAI,CAEtD;AAED,oFAAoF;AACpF,wBAAgB,cAAc,IAAI,YAAY,GAAG,IAAI,CAQpD"}
|
|
1
|
+
{"version":3,"file":"active-canvas.d.ts","sourceRoot":"","sources":["../src/active-canvas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,WAAW,GAAG,YAAY,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAClC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACpC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpD;AAED,wBAAgB,gBAAgB,IAAI,YAAY,GAAG,IAAI,CAEtD;AAED,8EAA8E;AAC9E,wBAAgB,yBAAyB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CAQvE;AAED,oFAAoF;AACpF,wBAAgB,cAAc,IAAI,YAAY,GAAG,IAAI,CAQpD"}
|
package/dist/active-canvas.js
CHANGED
|
@@ -3,6 +3,13 @@ import { activeEditorSignal } from "@eclipse-docks/core";
|
|
|
3
3
|
function readActiveCanvas() {
|
|
4
4
|
return fromElement(activeEditorSignal.get());
|
|
5
5
|
}
|
|
6
|
+
/** Connected workspace canvas editors. Optional path keeps only that file. */
|
|
7
|
+
function connectedWorkspaceEditors(path) {
|
|
8
|
+
const editors = [...document.querySelectorAll("docks-canvas-editor")].filter((node) => node.isConnected).map((node) => fromElement(node)).filter((item) => !!item && item.editor && item.kind === "workspace");
|
|
9
|
+
if (!path) return editors;
|
|
10
|
+
const normalized = path.replace(/^\/+/, "");
|
|
11
|
+
return editors.filter((item) => (item.getFilePath?.() ?? "").replace(/^\/+/, "") === normalized);
|
|
12
|
+
}
|
|
6
13
|
/** Active canvas editor, or any open canvas part when focus has moved elsewhere. */
|
|
7
14
|
function findOpenCanvas() {
|
|
8
15
|
const active = readActiveCanvas();
|
|
@@ -24,6 +31,8 @@ function fromElement(active) {
|
|
|
24
31
|
getContent: active.getContent?.bind(active),
|
|
25
32
|
getFilePath: active.getFilePath?.bind(active),
|
|
26
33
|
setSource: active.setSource?.bind(active),
|
|
34
|
+
save: active.save?.bind(active),
|
|
35
|
+
syncFromFile: active.syncFromFile?.bind(active),
|
|
27
36
|
reload: active.reload?.bind(active),
|
|
28
37
|
capturePreview: active.capturePreview?.bind(active),
|
|
29
38
|
getState: active.getState?.bind(active),
|
|
@@ -31,6 +40,6 @@ function fromElement(active) {
|
|
|
31
40
|
};
|
|
32
41
|
}
|
|
33
42
|
//#endregion
|
|
34
|
-
export { findOpenCanvas, readActiveCanvas };
|
|
43
|
+
export { connectedWorkspaceEditors, findOpenCanvas, readActiveCanvas };
|
|
35
44
|
|
|
36
45
|
//# sourceMappingURL=active-canvas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"active-canvas.js","names":[],"sources":["../src/active-canvas.ts"],"sourcesContent":["import { activeEditorSignal } from '@eclipse-docks/core';\nimport type { PreviewShot } from './preview-image';\n\ntype CanvasElement = ActiveCanvas & { localName?: string };\n\nexport interface ActiveCanvas {\n kind: 'workspace' | 'registered';\n canvasName?: string;\n editor: boolean;\n getContent?: () => string | null;\n getFilePath?: () => string | null;\n setSource?: (source: string) => void;\n reload?: () => Promise<string>;\n capturePreview?: () => Promise<PreviewShot>;\n getState?: (key: string) => unknown;\n setState?: (key: string, value: unknown) => void;\n}\n\nexport function readActiveCanvas(): ActiveCanvas | null {\n return fromElement(activeEditorSignal.get() as unknown as CanvasElement | null);\n}\n\n/** Active canvas editor, or any open canvas part when focus has moved elsewhere. */\nexport function findOpenCanvas(): ActiveCanvas | null {\n const active = readActiveCanvas();\n if (active?.capturePreview) return active;\n for (const node of document.querySelectorAll('docks-canvas-editor, docks-canvas-surface')) {\n const mapped = fromElement(node as unknown as CanvasElement);\n if (mapped?.capturePreview) return mapped;\n }\n return active;\n}\n\nfunction fromElement(active: CanvasElement | null): ActiveCanvas | null {\n if (!active) return null;\n const localName = active.localName;\n if (localName !== 'docks-canvas-editor' && localName !== 'docks-canvas-surface') return null;\n return {\n kind: active.kind === 'registered' ? 'registered' : 'workspace',\n canvasName: active.canvasName,\n editor: localName === 'docks-canvas-editor',\n getContent: active.getContent?.bind(active),\n getFilePath: active.getFilePath?.bind(active),\n setSource: active.setSource?.bind(active),\n reload: active.reload?.bind(active),\n capturePreview: active.capturePreview?.bind(active),\n getState: active.getState?.bind(active),\n setState: active.setState?.bind(active),\n };\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"active-canvas.js","names":[],"sources":["../src/active-canvas.ts"],"sourcesContent":["import { activeEditorSignal } from '@eclipse-docks/core';\nimport type { PreviewShot } from './preview-image';\n\ntype CanvasElement = ActiveCanvas & { localName?: string };\n\nexport interface ActiveCanvas {\n kind: 'workspace' | 'registered';\n canvasName?: string;\n editor: boolean;\n getContent?: () => string | null;\n getFilePath?: () => string | null;\n setSource?: (source: string) => void;\n save?: () => Promise<void>;\n syncFromFile?: () => Promise<boolean>;\n reload?: () => Promise<string>;\n capturePreview?: () => Promise<PreviewShot>;\n getState?: (key: string) => unknown;\n setState?: (key: string, value: unknown) => void;\n}\n\nexport function readActiveCanvas(): ActiveCanvas | null {\n return fromElement(activeEditorSignal.get() as unknown as CanvasElement | null);\n}\n\n/** Connected workspace canvas editors. Optional path keeps only that file. */\nexport function connectedWorkspaceEditors(path?: string): ActiveCanvas[] {\n const editors = [...document.querySelectorAll('docks-canvas-editor')]\n .filter(node => (node as HTMLElement).isConnected)\n .map(node => fromElement(node as unknown as CanvasElement))\n .filter((item): item is ActiveCanvas => !!item && item.editor && item.kind === 'workspace');\n if (!path) return editors;\n const normalized = path.replace(/^\\/+/, '');\n return editors.filter(item => (item.getFilePath?.() ?? '').replace(/^\\/+/, '') === normalized);\n}\n\n/** Active canvas editor, or any open canvas part when focus has moved elsewhere. */\nexport function findOpenCanvas(): ActiveCanvas | null {\n const active = readActiveCanvas();\n if (active?.capturePreview) return active;\n for (const node of document.querySelectorAll('docks-canvas-editor, docks-canvas-surface')) {\n const mapped = fromElement(node as unknown as CanvasElement);\n if (mapped?.capturePreview) return mapped;\n }\n return active;\n}\n\nfunction fromElement(active: CanvasElement | null): ActiveCanvas | null {\n if (!active) return null;\n const localName = active.localName;\n if (localName !== 'docks-canvas-editor' && localName !== 'docks-canvas-surface') return null;\n return {\n kind: active.kind === 'registered' ? 'registered' : 'workspace',\n canvasName: active.canvasName,\n editor: localName === 'docks-canvas-editor',\n getContent: active.getContent?.bind(active),\n getFilePath: active.getFilePath?.bind(active),\n setSource: active.setSource?.bind(active),\n save: active.save?.bind(active),\n syncFromFile: active.syncFromFile?.bind(active),\n reload: active.reload?.bind(active),\n capturePreview: active.capturePreview?.bind(active),\n getState: active.getState?.bind(active),\n setState: active.setState?.bind(active),\n };\n}\n"],"mappings":";;AAoBA,SAAgB,mBAAwC;CACpD,OAAO,YAAY,mBAAmB,IAAI,CAAoC;AAClF;;AAGA,SAAgB,0BAA0B,MAA+B;CACrE,MAAM,UAAU,CAAC,GAAG,SAAS,iBAAiB,qBAAqB,CAAC,CAAC,CAChE,QAAO,SAAS,KAAqB,WAAW,CAAC,CACjD,KAAI,SAAQ,YAAY,IAAgC,CAAC,CAAC,CAC1D,QAAQ,SAA+B,CAAC,CAAC,QAAQ,KAAK,UAAU,KAAK,SAAS,WAAW;CAC9F,IAAI,CAAC,MAAM,OAAO;CAClB,MAAM,aAAa,KAAK,QAAQ,QAAQ,EAAE;CAC1C,OAAO,QAAQ,QAAO,UAAS,KAAK,cAAc,KAAK,GAAA,CAAI,QAAQ,QAAQ,EAAE,MAAM,UAAU;AACjG;;AAGA,SAAgB,iBAAsC;CAClD,MAAM,SAAS,iBAAiB;CAChC,IAAI,QAAQ,gBAAgB,OAAO;CACnC,KAAK,MAAM,QAAQ,SAAS,iBAAiB,2CAA2C,GAAG;EACvF,MAAM,SAAS,YAAY,IAAgC;EAC3D,IAAI,QAAQ,gBAAgB,OAAO;CACvC;CACA,OAAO;AACX;AAEA,SAAS,YAAY,QAAmD;CACpE,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,YAAY,OAAO;CACzB,IAAI,cAAc,yBAAyB,cAAc,wBAAwB,OAAO;CACxF,OAAO;EACH,MAAM,OAAO,SAAS,eAAe,eAAe;EACpD,YAAY,OAAO;EACnB,QAAQ,cAAc;EACtB,YAAY,OAAO,YAAY,KAAK,MAAM;EAC1C,aAAa,OAAO,aAAa,KAAK,MAAM;EAC5C,WAAW,OAAO,WAAW,KAAK,MAAM;EACxC,MAAM,OAAO,MAAM,KAAK,MAAM;EAC9B,cAAc,OAAO,cAAc,KAAK,MAAM;EAC9C,QAAQ,OAAO,QAAQ,KAAK,MAAM;EAClC,gBAAgB,OAAO,gBAAgB,KAAK,MAAM;EAClD,UAAU,OAAO,UAAU,KAAK,MAAM;EACtC,UAAU,OAAO,UAAU,KAAK,MAAM;CAC1C;AACJ"}
|
package/dist/canvas-editor.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare class DocksCanvasSurface extends DocksPart implements EditorConte
|
|
|
23
23
|
private contribution?;
|
|
24
24
|
private ready;
|
|
25
25
|
private reloadGeneration;
|
|
26
|
+
private reloadTail;
|
|
27
|
+
private syncToken;
|
|
26
28
|
private compiledSource;
|
|
27
29
|
protected previewStale: boolean;
|
|
28
30
|
connectedCallback(): void;
|
|
@@ -41,9 +43,16 @@ export declare class DocksCanvasSurface extends DocksPart implements EditorConte
|
|
|
41
43
|
getState(key: string): unknown;
|
|
42
44
|
setState(key: string, value: unknown): void;
|
|
43
45
|
setSource(source: string): void;
|
|
46
|
+
syncFromFile(): Promise<boolean>;
|
|
44
47
|
capturePreview(): Promise<PreviewShot>;
|
|
45
48
|
reload(): Promise<string>;
|
|
49
|
+
private reloadLatest;
|
|
50
|
+
private mountSource;
|
|
46
51
|
private replacePreview;
|
|
52
|
+
/** The mount has no Lit child part, so replacing its children leaves part markers intact. */
|
|
53
|
+
private placePreview;
|
|
54
|
+
private onWorkspaceChanged;
|
|
55
|
+
private refreshFromFile;
|
|
47
56
|
private onDirty;
|
|
48
57
|
protected updated(changed: PropertyValues): void;
|
|
49
58
|
private onContentChange;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-editor.d.ts","sourceRoot":"","sources":["../src/canvas-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,
|
|
1
|
+
{"version":3,"file":"canvas-editor.d.ts","sourceRoot":"","sources":["../src/canvas-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EAIT,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAa,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAE5F,OAAO,+CAA+C,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAGvF,OAAO,EAA0C,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AACjF,OAAO,EAAyC,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAExF,OAAO,EAAuC,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGxF,qBACa,kBAAmB,SAAQ,SAAU,YAAW,qBAAqB;IAC9C,KAAK,CAAC,EAAE,WAAW,CAAC;IACxC,IAAI,EAAE,WAAW,GAAG,YAAY,CAAe;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,SAAM;IACf,MAAM,SAAM;IACK,UAAU,UAAS;IAEvC,SAAS,CAAC,UAAU,SAAM;IAC1B,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAa;IACjD,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAChC,OAAO,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C,cAAc;IAYtB,6FAA6F;IAC7F,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,kBAAkB,CAExB;YAEY,eAAe;IAM7B,OAAO,CAAC,OAAO,CAMb;IAEF,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc;IAMzC,OAAO,CAAC,eAAe,CAKrB;IAEF,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,aAAa,CAmBnB;IAEF,SAAS,CAAC,aAAa;IAwBvB,SAAS,CAAC,aAAa;IAsBvB,MAAM,CAAC,MAAM,0BAsBX;CACL;AAED,qBACa,iBAAkB,SAAQ,kBAAkB;IACtC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAOvC;AAMD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,sBAAsB,EAAE,kBAAkB,CAAC;QAC3C,qBAAqB,EAAE,iBAAiB,CAAC;KAC5C;CACJ"}
|
package/dist/canvas-editor.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { attachPreviewShot, rasterizeElement } from "./preview-image.js";
|
|
2
|
+
import { readWorkspaceFile } from "./workspace-file.js";
|
|
2
3
|
import { compileCanvas } from "./compile.js";
|
|
3
4
|
import { createContributionHost, createFileHost } from "./host.js";
|
|
4
5
|
import { elementFromConstructor, mountCompiled } from "./mount.js";
|
|
5
6
|
import { canvasBridges } from "./bridges/urls.js";
|
|
6
|
-
import { readWorkspaceFile } from "./workspace-file.js";
|
|
7
7
|
import __decorate from "./_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
8
|
-
import { DocksPart, File, icon } from "@eclipse-docks/core";
|
|
8
|
+
import { DocksPart, File, TOPIC_WORKSPACE_CHANGED, icon } from "@eclipse-docks/core";
|
|
9
9
|
import { css, customElement, html, nothing, property, query, state } from "@eclipse-docks/core/externals/lit";
|
|
10
|
-
import { Directive, directive } from "lit/directive.js";
|
|
11
10
|
import "@eclipse-docks/extension-monaco-editor/widget";
|
|
12
11
|
//#region src/canvas-editor.ts
|
|
13
|
-
var heldNode = directive(class extends Directive {
|
|
14
|
-
render(node) {
|
|
15
|
-
return node ?? nothing;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
12
|
var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
19
13
|
constructor(..._args) {
|
|
20
14
|
super(..._args);
|
|
@@ -33,8 +27,13 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
33
27
|
};
|
|
34
28
|
this.ready = false;
|
|
35
29
|
this.reloadGeneration = 0;
|
|
30
|
+
this.reloadTail = Promise.resolve();
|
|
31
|
+
this.syncToken = 0;
|
|
36
32
|
this.compiledSource = "";
|
|
37
33
|
this.previewStale = false;
|
|
34
|
+
this.onWorkspaceChanged = () => {
|
|
35
|
+
this.refreshFromFile();
|
|
36
|
+
};
|
|
38
37
|
this.onDirty = (event) => {
|
|
39
38
|
if (!this.ready || event.detail !== true) return;
|
|
40
39
|
if ((this.getContent() ?? "") === this.compiledSource && this.previewElement) return;
|
|
@@ -71,6 +70,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
71
70
|
connectedCallback() {
|
|
72
71
|
super.connectedCallback();
|
|
73
72
|
this.addEventListener("dirty", this.onDirty);
|
|
73
|
+
this.subscribe(TOPIC_WORKSPACE_CHANGED, this.onWorkspaceChanged);
|
|
74
74
|
}
|
|
75
75
|
disconnectedCallback() {
|
|
76
76
|
this.removeEventListener("dirty", this.onDirty);
|
|
@@ -107,6 +107,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
107
107
|
}
|
|
108
108
|
this.mode = this.input?.state?.mode === "source" ? "source" : "preview";
|
|
109
109
|
this.ready = true;
|
|
110
|
+
await this.syncFromFile();
|
|
110
111
|
this.requestUpdate();
|
|
111
112
|
if (this.mode === "preview" || !this.showSource) await this.reload();
|
|
112
113
|
}
|
|
@@ -143,12 +144,28 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
143
144
|
this.host.setState(key, value);
|
|
144
145
|
}
|
|
145
146
|
setSource(source) {
|
|
146
|
-
|
|
147
|
+
const current = this.getContent() ?? "";
|
|
147
148
|
this.sourceText = source;
|
|
148
149
|
const model = this.widget?.getModel();
|
|
149
150
|
if (model && model.getValue() !== source) model.setValue(source);
|
|
151
|
+
const next = this.getContent() ?? source;
|
|
152
|
+
this.previewStale = next !== this.compiledSource || !this.previewElement;
|
|
153
|
+
if (next !== current || this.previewStale) this.markDirty(true);
|
|
150
154
|
this.requestUpdate();
|
|
151
155
|
}
|
|
156
|
+
async syncFromFile() {
|
|
157
|
+
for (let attempt = 0; attempt < 30 && !this.ready; attempt++) await new Promise((resolve) => setTimeout(resolve, 50));
|
|
158
|
+
if (!this.ready || this.kind !== "workspace" || !this.entryPath) return false;
|
|
159
|
+
const token = ++this.syncToken;
|
|
160
|
+
const before = this.getContent() ?? "";
|
|
161
|
+
const file = await readWorkspaceFile(this.entryPath);
|
|
162
|
+
if (token !== this.syncToken) return false;
|
|
163
|
+
if (file?.text === void 0) return false;
|
|
164
|
+
const current = this.getContent() ?? "";
|
|
165
|
+
if (current !== before || file.text === current) return false;
|
|
166
|
+
this.setSource(file.text);
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
152
169
|
async capturePreview() {
|
|
153
170
|
for (let attempt = 0; attempt < 30 && !this.ready; attempt++) await new Promise((resolve) => setTimeout(resolve, 50));
|
|
154
171
|
if (!this.ready) throw new Error("Canvas is still opening");
|
|
@@ -173,13 +190,28 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
173
190
|
preview.style.height = "";
|
|
174
191
|
}
|
|
175
192
|
}
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
193
|
+
reload() {
|
|
194
|
+
const run = this.reloadTail.then(() => this.reloadLatest());
|
|
195
|
+
this.reloadTail = run.then(() => void 0, () => void 0);
|
|
196
|
+
return run;
|
|
197
|
+
}
|
|
198
|
+
async reloadLatest() {
|
|
199
|
+
let result = "ready";
|
|
200
|
+
for (let pass = 0; pass < 4; pass++) {
|
|
201
|
+
const source = this.getContent() ?? "";
|
|
202
|
+
if (this.previewElement && !this.previewStale && source === this.compiledSource && !this.previewError) return result;
|
|
203
|
+
result = await this.mountSource(source);
|
|
204
|
+
if (!result) continue;
|
|
205
|
+
if ((this.getContent() ?? "") === source) return result;
|
|
206
|
+
this.previewStale = true;
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
async mountSource(source) {
|
|
179
211
|
const generation = ++this.reloadGeneration;
|
|
180
212
|
if (this.kind === "registered" && this.contribution) try {
|
|
181
213
|
const mod = await this.contribution.load();
|
|
182
|
-
if (generation !== this.reloadGeneration) return "
|
|
214
|
+
if (generation !== this.reloadGeneration) return "";
|
|
183
215
|
const Ctor = mod.default;
|
|
184
216
|
if (typeof Ctor !== "function" || !(Ctor.prototype instanceof HTMLElement)) {
|
|
185
217
|
this.previewError = "Canvas default export must be an HTMLElement subclass";
|
|
@@ -188,10 +220,10 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
188
220
|
}
|
|
189
221
|
const element = elementFromConstructor(Ctor);
|
|
190
222
|
element.canvasHost = this.host;
|
|
191
|
-
this.replacePreview(element);
|
|
223
|
+
this.replacePreview(element, source);
|
|
192
224
|
return "ready";
|
|
193
225
|
} catch (err) {
|
|
194
|
-
if (generation !== this.reloadGeneration) return "
|
|
226
|
+
if (generation !== this.reloadGeneration) return "";
|
|
195
227
|
this.previewError = err instanceof Error ? err.message : String(err);
|
|
196
228
|
this.requestUpdate();
|
|
197
229
|
return this.previewError;
|
|
@@ -202,7 +234,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
202
234
|
read: readWorkspaceFile,
|
|
203
235
|
bridges: canvasBridges()
|
|
204
236
|
});
|
|
205
|
-
if (generation !== this.reloadGeneration) return "
|
|
237
|
+
if (generation !== this.reloadGeneration) return "";
|
|
206
238
|
if (!compiled.ok) {
|
|
207
239
|
this.previewError = compiled.error;
|
|
208
240
|
this.requestUpdate();
|
|
@@ -211,7 +243,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
211
243
|
const mounted = await mountCompiled(compiled.code);
|
|
212
244
|
if (generation !== this.reloadGeneration) {
|
|
213
245
|
if (mounted.ok) mounted.dispose();
|
|
214
|
-
return "
|
|
246
|
+
return "";
|
|
215
247
|
}
|
|
216
248
|
if (!mounted.ok) {
|
|
217
249
|
this.previewError = mounted.error;
|
|
@@ -219,23 +251,35 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
219
251
|
return mounted.error;
|
|
220
252
|
}
|
|
221
253
|
mounted.element.canvasHost = this.host;
|
|
222
|
-
this.
|
|
223
|
-
this.previewStale = false;
|
|
224
|
-
this.replacePreview(mounted.element, mounted.dispose);
|
|
254
|
+
this.replacePreview(mounted.element, source, mounted.dispose);
|
|
225
255
|
return "ready";
|
|
226
256
|
}
|
|
227
|
-
replacePreview(element, dispose) {
|
|
257
|
+
replacePreview(element, source, dispose) {
|
|
228
258
|
const previous = this.previewDispose;
|
|
229
259
|
this.previewDispose = dispose ?? (() => element.remove());
|
|
230
260
|
this.previewElement = element;
|
|
231
261
|
this.previewError = void 0;
|
|
232
|
-
this.compiledSource =
|
|
233
|
-
this.previewStale =
|
|
262
|
+
this.compiledSource = source;
|
|
263
|
+
this.previewStale = (this.getContent() ?? "") !== source;
|
|
264
|
+
this.placePreview();
|
|
234
265
|
this.requestUpdate();
|
|
235
266
|
previous?.();
|
|
236
267
|
}
|
|
268
|
+
/** The mount has no Lit child part, so replacing its children leaves part markers intact. */
|
|
269
|
+
placePreview() {
|
|
270
|
+
const mount = this.renderRoot.querySelector(".canvas-mount");
|
|
271
|
+
const element = this.previewElement;
|
|
272
|
+
if (!mount || !element) return;
|
|
273
|
+
if (mount.childElementCount === 1 && mount.firstElementChild === element) return;
|
|
274
|
+
mount.replaceChildren(element);
|
|
275
|
+
}
|
|
276
|
+
async refreshFromFile() {
|
|
277
|
+
if (!await this.syncFromFile()) return;
|
|
278
|
+
if (this.mode === "preview" || !this.showSource) await this.reload();
|
|
279
|
+
}
|
|
237
280
|
updated(changed) {
|
|
238
281
|
super.updated(changed);
|
|
282
|
+
this.placePreview();
|
|
239
283
|
if (this.mode === "source") this.widget?.layout();
|
|
240
284
|
}
|
|
241
285
|
toggleMode() {
|
|
@@ -275,7 +319,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
275
319
|
<div class="canvas-preview ${showPreview ? "" : "canvas-hidden"}">
|
|
276
320
|
${this.previewError ? html`<pre class="canvas-error">${this.previewError}</pre>` : nothing}
|
|
277
321
|
<wa-scroller class="canvas-scroll" orientation="vertical">
|
|
278
|
-
<div class="canvas-mount"
|
|
322
|
+
<div class="canvas-mount"></div>
|
|
279
323
|
</wa-scroller>
|
|
280
324
|
</div>
|
|
281
325
|
${this.showSource ? html`
|
|
@@ -333,8 +377,8 @@ var DocksCanvasEditor = class DocksCanvasEditor extends DocksCanvasSurface {
|
|
|
333
377
|
const value = this.getContent() ?? "";
|
|
334
378
|
const data = this.input?.data;
|
|
335
379
|
if (data instanceof File) await data.saveContents(value);
|
|
380
|
+
if ((this.mode === "preview" || !this.showSource) && this.previewStale) await this.reload();
|
|
336
381
|
this.markDirty(false);
|
|
337
|
-
if (this.mode === "preview" && this.previewStale) await this.reload();
|
|
338
382
|
}
|
|
339
383
|
};
|
|
340
384
|
DocksCanvasEditor = __decorate([customElement("docks-canvas-editor")], DocksCanvasEditor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-editor.js","names":["_decorate"],"sources":["../src/canvas-editor.ts"],"sourcesContent":["import {\n DocksPart,\n File,\n icon,\n type EditorContentProvider,\n type EditorInput,\n} from '@eclipse-docks/core';\nimport { css, html, nothing, type PropertyValues } from '@eclipse-docks/core/externals/lit';\nimport { customElement, property, query, state } from '@eclipse-docks/core/externals/lit';\nimport { Directive, directive } from 'lit/directive.js';\nimport '@eclipse-docks/extension-monaco-editor/widget';\nimport type { DocksMonacoWidget } from '@eclipse-docks/extension-monaco-editor/widget';\nimport type { CanvasContribution } from './contribution';\nimport { compileCanvas } from './compile';\nimport { createContributionHost, createFileHost, type CanvasHost } from './host';\nimport { elementFromConstructor, mountCompiled, type CanvasViewElement } from './mount';\nimport { canvasBridges } from './bridges/urls';\nimport { attachPreviewShot, rasterizeElement, type PreviewShot } from './preview-image';\nimport { readWorkspaceFile } from './workspace-file';\n\nconst heldNode = directive(class extends Directive {\n render(node?: Node) {\n return node ?? nothing;\n }\n});\n\n@customElement('docks-canvas-surface')\nexport class DocksCanvasSurface extends DocksPart implements EditorContentProvider {\n @property({ attribute: false }) input?: EditorInput;\n @property() kind: 'workspace' | 'registered' = 'workspace';\n @property() canvasName?: string;\n @property() entryPath = '';\n @property() source = '';\n @property({ type: Boolean }) showSource = false;\n\n @state() protected sourceText = '';\n @state() protected mode: 'preview' | 'source' = 'preview';\n @state() protected previewError?: string;\n @state() private attachingPreview = false;\n @state() protected previewElement?: CanvasViewElement;\n @query('docks-monaco-widget') protected widget?: DocksMonacoWidget;\n\n protected scrollMode: 'scroller' | 'native' | 'none' = 'none';\n protected host: CanvasHost = { getState: (_key, fallback) => fallback, setState: () => undefined, openFile: () => undefined };\n private previewDispose?: () => void;\n private contribution?: CanvasContribution;\n private ready = false;\n private reloadGeneration = 0;\n private compiledSource = '';\n protected previewStale = false;\n\n override connectedCallback() {\n super.connectedCallback();\n this.addEventListener('dirty', this.onDirty);\n }\n\n override disconnectedCallback() {\n this.removeEventListener('dirty', this.onDirty);\n this.reloadGeneration++;\n super.disconnectedCallback();\n }\n\n protected async doInitUI() {\n const data = this.input?.data;\n if (data instanceof File) {\n this.kind = 'workspace';\n this.entryPath = data.getWorkspacePath();\n this.showSource = true;\n this.sourceText = String(await data.getContents() ?? '');\n this.host = await createFileHost(data);\n } else if (data && typeof data === 'object' && 'contribution' in data) {\n this.contribution = (data as { contribution: CanvasContribution }).contribution;\n this.kind = 'registered';\n this.canvasName = this.contribution.name;\n this.showSource = this.contribution.source !== undefined;\n if (typeof this.contribution.source === 'function') this.sourceText = await this.contribution.source();\n else this.sourceText = this.contribution.source ?? '';\n this.host = await createContributionHost(this.contribution);\n } else if (this.entryPath || this.source) {\n this.kind = 'workspace';\n this.showSource = false;\n this.sourceText = this.source;\n const workspaceFile = await readWorkspaceFile(this.entryPath);\n if (workspaceFile?.text !== undefined && !this.sourceText) this.sourceText = workspaceFile.text;\n this.host = { getState: (_key, fallback) => fallback, setState: () => undefined, openFile: () => undefined };\n }\n this.mode = this.input?.state?.mode === 'source' ? 'source' : 'preview';\n this.ready = true;\n this.requestUpdate();\n if (this.mode === 'preview' || !this.showSource) await this.reload();\n }\n\n protected doClose() {\n this.reloadGeneration++;\n this.previewDispose?.();\n this.previewDispose = undefined;\n this.widget?.dispose();\n }\n\n getContent(): string | null {\n return this.widget?.getContent() ?? this.sourceText;\n }\n\n getSelection(): string | null {\n return this.widget?.getSelection() ?? null;\n }\n\n getSnippet(lines = 5): { snippet: string; cursorLine: number } | null {\n return this.widget?.getSnippet(lines) ?? null;\n }\n\n getLanguage(): string | null {\n return 'javascript';\n }\n\n isLanguage(lang: string): boolean {\n return lang.toLowerCase() === 'javascript';\n }\n\n getFilePath(): string | null {\n const data = this.input?.data;\n if (data instanceof File) return data.getWorkspacePath();\n return this.entryPath || null;\n }\n\n getState(key: string): unknown {\n return this.host.getState(key);\n }\n\n setState(key: string, value: unknown): void {\n this.host.setState(key, value);\n }\n\n setSource(source: string): void {\n this.previewStale = source !== this.compiledSource;\n this.sourceText = source;\n const model = this.widget?.getModel();\n if (model && model.getValue() !== source) model.setValue(source);\n this.requestUpdate();\n }\n\n async capturePreview(): Promise<PreviewShot> {\n for (let attempt = 0; attempt < 30 && !this.ready; attempt++) {\n await new Promise(resolve => setTimeout(resolve, 50));\n }\n if (!this.ready) throw new Error('Canvas is still opening');\n await this.reload();\n await this.updateComplete;\n const preview = this.renderRoot.querySelector('.canvas-preview') as HTMLElement | null;\n if (!preview) throw new Error('Canvas preview is not rendered');\n const hidden = preview.classList.contains('canvas-hidden') || preview.getBoundingClientRect().width < 2;\n if (hidden) {\n preview.classList.add('canvas-capture');\n preview.style.width = `${this.clientWidth || 960}px`;\n preview.style.height = `${this.clientHeight || 640}px`;\n }\n try {\n await nextFrame();\n await nextFrame();\n const view = this.previewElement as { updateComplete?: Promise<unknown> } | undefined;\n if (view?.updateComplete) await view.updateComplete;\n return await rasterizeElement(preview);\n } finally {\n preview.classList.remove('canvas-capture');\n preview.style.width = '';\n preview.style.height = '';\n }\n }\n\n async reload(): Promise<string> {\n const source = this.getContent() ?? '';\n if (this.previewElement && !this.previewStale && source === this.compiledSource && !this.previewError) return 'ready';\n const generation = ++this.reloadGeneration;\n if (this.kind === 'registered' && this.contribution) {\n try {\n const mod = await this.contribution.load();\n if (generation !== this.reloadGeneration) return 'ready';\n const Ctor = mod.default;\n if (typeof Ctor !== 'function' || !(Ctor.prototype instanceof HTMLElement)) {\n this.previewError = 'Canvas default export must be an HTMLElement subclass';\n this.requestUpdate();\n return this.previewError;\n }\n const element = elementFromConstructor(Ctor);\n element.canvasHost = this.host;\n this.replacePreview(element);\n return 'ready';\n } catch (err) {\n if (generation !== this.reloadGeneration) return 'ready';\n this.previewError = err instanceof Error ? err.message : String(err);\n this.requestUpdate();\n return this.previewError;\n }\n }\n const compiled = await compileCanvas({\n entryPath: this.entryPath || 'canvas.js',\n entrySource: source,\n read: readWorkspaceFile,\n bridges: canvasBridges(),\n });\n if (generation !== this.reloadGeneration) return 'ready';\n if (!compiled.ok) {\n this.previewError = compiled.error;\n this.requestUpdate();\n return compiled.error;\n }\n const mounted = await mountCompiled(compiled.code);\n if (generation !== this.reloadGeneration) {\n if (mounted.ok) mounted.dispose();\n return 'ready';\n }\n if (!mounted.ok) {\n this.previewError = mounted.error;\n this.requestUpdate();\n return mounted.error;\n }\n mounted.element.canvasHost = this.host;\n this.compiledSource = source;\n this.previewStale = false;\n this.replacePreview(mounted.element, mounted.dispose);\n return 'ready';\n }\n\n private replacePreview(element: CanvasViewElement, dispose?: () => void) {\n const previous = this.previewDispose;\n this.previewDispose = dispose ?? (() => element.remove());\n this.previewElement = element;\n this.previewError = undefined;\n this.compiledSource = this.getContent() ?? this.compiledSource;\n this.previewStale = false;\n this.requestUpdate();\n previous?.();\n }\n\n private onDirty = (event: Event) => {\n if (!this.ready || (event as CustomEvent<boolean>).detail !== true) return;\n const source = this.getContent() ?? '';\n if (source === this.compiledSource && this.previewElement) return;\n this.previewStale = true;\n if (this.mode === 'preview' || !this.showSource) void this.reload();\n };\n\n protected updated(changed: PropertyValues) {\n super.updated(changed);\n if (this.mode === 'source') this.widget?.layout();\n }\n\n private onContentChange = () => {\n const next = this.widget?.getContent() ?? this.sourceText;\n this.previewStale = next !== this.compiledSource;\n this.sourceText = next;\n this.markDirty(true);\n };\n\n private toggleMode() {\n if (this.widget) this.sourceText = this.widget.getContent() ?? this.sourceText;\n const next = this.mode === 'preview' ? 'source' : 'preview';\n this.mode = next;\n if (this.input) this.input.state.mode = next;\n if (next === 'preview' && (this.previewStale || !this.previewElement)) void this.reload();\n }\n\n private attachPreview = async () => {\n if (this.attachingPreview) return;\n this.attachingPreview = true;\n try {\n const result = await attachPreviewShot(this);\n if (typeof result === 'string') {\n this.showError(result);\n return;\n }\n if (result.stored === false) {\n this.showError(String(result.note ?? 'Could not attach the preview'));\n return;\n }\n this.showInfo('Attached preview');\n } catch (err) {\n this.showError(err instanceof Error ? err.message : String(err));\n } finally {\n this.attachingPreview = false;\n }\n };\n\n protected renderToolbar() {\n if (!this.ready) return nothing;\n const toSource = this.mode === 'preview';\n const label = toSource ? 'Source' : 'Preview';\n return html`\n ${this.showSource ? html`\n <wa-button appearance=\"plain\" size=\"s\" title=${label} @click=${() => this.toggleMode()}>\n ${icon(toSource ? 'code' : 'eye', { slot: 'start' })}\n ${label}\n </wa-button>\n ` : nothing}\n <wa-button\n appearance=\"plain\"\n size=\"s\"\n title=\"Attach a screenshot of the preview\"\n ?loading=${this.attachingPreview}\n ?disabled=${this.attachingPreview}\n @click=${() => this.attachPreview()}>\n ${icon('camera', { slot: 'start' })}\n Screenshot\n </wa-button>\n `;\n }\n\n protected renderContent() {\n if (!this.ready) return html``;\n const showPreview = !this.showSource || this.mode === 'preview';\n return html`\n <div class=\"canvas-preview ${showPreview ? '' : 'canvas-hidden'}\">\n ${this.previewError ? html`<pre class=\"canvas-error\">${this.previewError}</pre>` : nothing}\n <wa-scroller class=\"canvas-scroll\" orientation=\"vertical\">\n <div class=\"canvas-mount\">${heldNode(this.previewElement)}</div>\n </wa-scroller>\n </div>\n ${this.showSource ? html`\n <docks-monaco-widget\n class=${this.mode === 'source' ? '' : 'canvas-hidden'}\n .value=${this.sourceText}\n .language=${'javascript'}\n .uri=${this.entryPath || this.canvasName || 'canvas.js'}\n @content-change=${this.onContentChange}>\n </docks-monaco-widget>\n ` : nothing}\n `;\n }\n\n static styles = css`\n :host { display: flex; flex-direction: column; height: 100%; min-height: 0; }\n .canvas-preview { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }\n .canvas-preview.canvas-hidden, docks-monaco-widget.canvas-hidden { display: none; }\n .canvas-preview.canvas-capture {\n display: flex !important;\n position: fixed;\n left: 0;\n top: 0;\n z-index: 2147483000;\n overflow: hidden;\n background: var(--wa-color-surface-default, #fff);\n }\n wa-scroller.canvas-scroll { flex: 1 1 0; min-height: 0; height: 100%; }\n .canvas-mount > * { display: block; }\n docks-monaco-widget { display: block; height: 100%; min-height: 0; }\n .canvas-error {\n margin: 0;\n padding: var(--wa-space-s, 8px);\n white-space: pre-wrap;\n color: var(--wa-color-danger-on-quiet, #b42318);\n }\n `;\n}\n\n@customElement('docks-canvas-editor')\nexport class DocksCanvasEditor extends DocksCanvasSurface {\n override async save(): Promise<void> {\n const value = this.getContent() ?? '';\n const data = this.input?.data;\n if (data instanceof File) await data.saveContents(value);\n this.markDirty(false);\n if (this.mode === 'preview' && this.previewStale) await this.reload();\n }\n}\n\nfunction nextFrame(): Promise<void> {\n return new Promise(resolve => requestAnimationFrame(() => resolve()));\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'docks-canvas-surface': DocksCanvasSurface;\n 'docks-canvas-editor': DocksCanvasEditor;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAM,WAAW,UAAU,cAAc,UAAU;CAC/C,OAAO,MAAa;EAChB,OAAO,QAAQ;CACnB;AACJ,CAAC;AAGM,IAAM,qBAAN,MAAM,2BAA2B,UAA2C;;;EAEhC,KAAA,OAAA;EAEvB,KAAA,YAAA;EACH,KAAA,SAAA;EACqB,KAAA,aAAA;EAEV,KAAA,aAAA;EACgB,KAAA,OAAA;EAEZ,KAAA,mBAAA;EAImB,KAAA,aAAA;EAC1B,KAAA,OAAA;GAAE,WAAW,MAAM,aAAa;GAAU,gBAAgB,KAAA;GAAW,gBAAgB,KAAA;EAAU;EAG5G,KAAA,QAAA;EACW,KAAA,mBAAA;EACF,KAAA,iBAAA;EACA,KAAA,eAAA;EAyLN,KAAA,WAAA,UAAiB;GAChC,IAAI,CAAC,KAAK,SAAU,MAA+B,WAAW,MAAM;GAEpE,KADe,KAAK,WAAW,KAAK,QACrB,KAAK,kBAAkB,KAAK,gBAAgB;GAC3D,KAAK,eAAe;GACpB,IAAI,KAAK,SAAS,aAAa,CAAC,KAAK,YAAY,KAAU,OAAO;EACtE;EAOgC,KAAA,wBAAA;GAC5B,MAAM,OAAO,KAAK,QAAQ,WAAW,KAAK,KAAK;GAC/C,KAAK,eAAe,SAAS,KAAK;GAClC,KAAK,aAAa;GAClB,KAAK,UAAU,IAAI;EACvB;EAUwB,KAAA,gBAAA,YAAY;GAChC,IAAI,KAAK,kBAAkB;GAC3B,KAAK,mBAAmB;GACxB,IAAI;IACA,MAAM,SAAS,MAAM,kBAAkB,IAA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canvas-editor.js","names":["_decorate"],"sources":["../src/canvas-editor.ts"],"sourcesContent":["import {\n DocksPart,\n File,\n icon,\n TOPIC_WORKSPACE_CHANGED,\n type EditorContentProvider,\n type EditorInput,\n} from '@eclipse-docks/core';\nimport { css, html, nothing, type PropertyValues } from '@eclipse-docks/core/externals/lit';\nimport { customElement, property, query, state } from '@eclipse-docks/core/externals/lit';\nimport '@eclipse-docks/extension-monaco-editor/widget';\nimport type { DocksMonacoWidget } from '@eclipse-docks/extension-monaco-editor/widget';\nimport type { CanvasContribution } from './contribution';\nimport { compileCanvas } from './compile';\nimport { createContributionHost, createFileHost, type CanvasHost } from './host';\nimport { elementFromConstructor, mountCompiled, type CanvasViewElement } from './mount';\nimport { canvasBridges } from './bridges/urls';\nimport { attachPreviewShot, rasterizeElement, type PreviewShot } from './preview-image';\nimport { readWorkspaceFile } from './workspace-file';\n\n@customElement('docks-canvas-surface')\nexport class DocksCanvasSurface extends DocksPart implements EditorContentProvider {\n @property({ attribute: false }) input?: EditorInput;\n @property() kind: 'workspace' | 'registered' = 'workspace';\n @property() canvasName?: string;\n @property() entryPath = '';\n @property() source = '';\n @property({ type: Boolean }) showSource = false;\n\n @state() protected sourceText = '';\n @state() protected mode: 'preview' | 'source' = 'preview';\n @state() protected previewError?: string;\n @state() private attachingPreview = false;\n @state() protected previewElement?: CanvasViewElement;\n @query('docks-monaco-widget') protected widget?: DocksMonacoWidget;\n\n protected scrollMode: 'scroller' | 'native' | 'none' = 'none';\n protected host: CanvasHost = { getState: (_key, fallback) => fallback, setState: () => undefined, openFile: () => undefined };\n private previewDispose?: () => void;\n private contribution?: CanvasContribution;\n private ready = false;\n private reloadGeneration = 0;\n private reloadTail: Promise<void> = Promise.resolve();\n private syncToken = 0;\n private compiledSource = '';\n protected previewStale = false;\n\n override connectedCallback() {\n super.connectedCallback();\n this.addEventListener('dirty', this.onDirty);\n this.subscribe(TOPIC_WORKSPACE_CHANGED, this.onWorkspaceChanged);\n }\n\n override disconnectedCallback() {\n this.removeEventListener('dirty', this.onDirty);\n this.reloadGeneration++;\n super.disconnectedCallback();\n }\n\n protected async doInitUI() {\n const data = this.input?.data;\n if (data instanceof File) {\n this.kind = 'workspace';\n this.entryPath = data.getWorkspacePath();\n this.showSource = true;\n this.sourceText = String(await data.getContents() ?? '');\n this.host = await createFileHost(data);\n } else if (data && typeof data === 'object' && 'contribution' in data) {\n this.contribution = (data as { contribution: CanvasContribution }).contribution;\n this.kind = 'registered';\n this.canvasName = this.contribution.name;\n this.showSource = this.contribution.source !== undefined;\n if (typeof this.contribution.source === 'function') this.sourceText = await this.contribution.source();\n else this.sourceText = this.contribution.source ?? '';\n this.host = await createContributionHost(this.contribution);\n } else if (this.entryPath || this.source) {\n this.kind = 'workspace';\n this.showSource = false;\n this.sourceText = this.source;\n const workspaceFile = await readWorkspaceFile(this.entryPath);\n if (workspaceFile?.text !== undefined && !this.sourceText) this.sourceText = workspaceFile.text;\n this.host = { getState: (_key, fallback) => fallback, setState: () => undefined, openFile: () => undefined };\n }\n this.mode = this.input?.state?.mode === 'source' ? 'source' : 'preview';\n this.ready = true;\n await this.syncFromFile();\n this.requestUpdate();\n if (this.mode === 'preview' || !this.showSource) await this.reload();\n }\n\n protected doClose() {\n this.reloadGeneration++;\n this.previewDispose?.();\n this.previewDispose = undefined;\n this.widget?.dispose();\n }\n\n getContent(): string | null {\n return this.widget?.getContent() ?? this.sourceText;\n }\n\n getSelection(): string | null {\n return this.widget?.getSelection() ?? null;\n }\n\n getSnippet(lines = 5): { snippet: string; cursorLine: number } | null {\n return this.widget?.getSnippet(lines) ?? null;\n }\n\n getLanguage(): string | null {\n return 'javascript';\n }\n\n isLanguage(lang: string): boolean {\n return lang.toLowerCase() === 'javascript';\n }\n\n getFilePath(): string | null {\n const data = this.input?.data;\n if (data instanceof File) return data.getWorkspacePath();\n return this.entryPath || null;\n }\n\n getState(key: string): unknown {\n return this.host.getState(key);\n }\n\n setState(key: string, value: unknown): void {\n this.host.setState(key, value);\n }\n\n setSource(source: string): void {\n const current = this.getContent() ?? '';\n this.sourceText = source;\n const model = this.widget?.getModel();\n if (model && model.getValue() !== source) model.setValue(source);\n const next = this.getContent() ?? source;\n this.previewStale = next !== this.compiledSource || !this.previewElement;\n if (next !== current || this.previewStale) this.markDirty(true);\n this.requestUpdate();\n }\n\n async syncFromFile(): Promise<boolean> {\n for (let attempt = 0; attempt < 30 && !this.ready; attempt++) {\n await new Promise(resolve => setTimeout(resolve, 50));\n }\n if (!this.ready || this.kind !== 'workspace' || !this.entryPath) return false;\n const token = ++this.syncToken;\n const before = this.getContent() ?? '';\n const file = await readWorkspaceFile(this.entryPath);\n if (token !== this.syncToken) return false;\n if (file?.text === undefined) return false;\n const current = this.getContent() ?? '';\n if (current !== before || file.text === current) return false;\n this.setSource(file.text);\n return true;\n }\n\n async capturePreview(): Promise<PreviewShot> {\n for (let attempt = 0; attempt < 30 && !this.ready; attempt++) {\n await new Promise(resolve => setTimeout(resolve, 50));\n }\n if (!this.ready) throw new Error('Canvas is still opening');\n await this.reload();\n await this.updateComplete;\n const preview = this.renderRoot.querySelector('.canvas-preview') as HTMLElement | null;\n if (!preview) throw new Error('Canvas preview is not rendered');\n const hidden = preview.classList.contains('canvas-hidden') || preview.getBoundingClientRect().width < 2;\n if (hidden) {\n preview.classList.add('canvas-capture');\n preview.style.width = `${this.clientWidth || 960}px`;\n preview.style.height = `${this.clientHeight || 640}px`;\n }\n try {\n await nextFrame();\n await nextFrame();\n const view = this.previewElement as { updateComplete?: Promise<unknown> } | undefined;\n if (view?.updateComplete) await view.updateComplete;\n return await rasterizeElement(preview);\n } finally {\n preview.classList.remove('canvas-capture');\n preview.style.width = '';\n preview.style.height = '';\n }\n }\n\n reload(): Promise<string> {\n const run = this.reloadTail.then(() => this.reloadLatest());\n this.reloadTail = run.then(() => undefined, () => undefined);\n return run;\n }\n\n private async reloadLatest(): Promise<string> {\n let result = 'ready';\n for (let pass = 0; pass < 4; pass++) {\n const source = this.getContent() ?? '';\n if (this.previewElement && !this.previewStale && source === this.compiledSource && !this.previewError) return result;\n result = await this.mountSource(source);\n if (!result) continue;\n if ((this.getContent() ?? '') === source) return result;\n this.previewStale = true;\n }\n return result;\n }\n\n private async mountSource(source: string): Promise<string> {\n const generation = ++this.reloadGeneration;\n if (this.kind === 'registered' && this.contribution) {\n try {\n const mod = await this.contribution.load();\n if (generation !== this.reloadGeneration) return '';\n const Ctor = mod.default;\n if (typeof Ctor !== 'function' || !(Ctor.prototype instanceof HTMLElement)) {\n this.previewError = 'Canvas default export must be an HTMLElement subclass';\n this.requestUpdate();\n return this.previewError;\n }\n const element = elementFromConstructor(Ctor);\n element.canvasHost = this.host;\n this.replacePreview(element, source);\n return 'ready';\n } catch (err) {\n if (generation !== this.reloadGeneration) return '';\n this.previewError = err instanceof Error ? err.message : String(err);\n this.requestUpdate();\n return this.previewError;\n }\n }\n const compiled = await compileCanvas({\n entryPath: this.entryPath || 'canvas.js',\n entrySource: source,\n read: readWorkspaceFile,\n bridges: canvasBridges(),\n });\n if (generation !== this.reloadGeneration) return '';\n if (!compiled.ok) {\n this.previewError = compiled.error;\n this.requestUpdate();\n return compiled.error;\n }\n const mounted = await mountCompiled(compiled.code);\n if (generation !== this.reloadGeneration) {\n if (mounted.ok) mounted.dispose();\n return '';\n }\n if (!mounted.ok) {\n this.previewError = mounted.error;\n this.requestUpdate();\n return mounted.error;\n }\n mounted.element.canvasHost = this.host;\n this.replacePreview(mounted.element, source, mounted.dispose);\n return 'ready';\n }\n\n private replacePreview(element: CanvasViewElement, source: string, dispose?: () => void) {\n const previous = this.previewDispose;\n this.previewDispose = dispose ?? (() => element.remove());\n this.previewElement = element;\n this.previewError = undefined;\n this.compiledSource = source;\n this.previewStale = (this.getContent() ?? '') !== source;\n this.placePreview();\n this.requestUpdate();\n previous?.();\n }\n\n /** The mount has no Lit child part, so replacing its children leaves part markers intact. */\n private placePreview() {\n const mount = this.renderRoot.querySelector('.canvas-mount');\n const element = this.previewElement;\n if (!mount || !element) return;\n if (mount.childElementCount === 1 && mount.firstElementChild === element) return;\n mount.replaceChildren(element);\n }\n\n private onWorkspaceChanged = () => {\n void this.refreshFromFile();\n };\n\n private async refreshFromFile() {\n const changed = await this.syncFromFile();\n if (!changed) return;\n if (this.mode === 'preview' || !this.showSource) await this.reload();\n }\n\n private onDirty = (event: Event) => {\n if (!this.ready || (event as CustomEvent<boolean>).detail !== true) return;\n const source = this.getContent() ?? '';\n if (source === this.compiledSource && this.previewElement) return;\n this.previewStale = true;\n if (this.mode === 'preview' || !this.showSource) void this.reload();\n };\n\n protected updated(changed: PropertyValues) {\n super.updated(changed);\n this.placePreview();\n if (this.mode === 'source') this.widget?.layout();\n }\n\n private onContentChange = () => {\n const next = this.widget?.getContent() ?? this.sourceText;\n this.previewStale = next !== this.compiledSource;\n this.sourceText = next;\n this.markDirty(true);\n };\n\n private toggleMode() {\n if (this.widget) this.sourceText = this.widget.getContent() ?? this.sourceText;\n const next = this.mode === 'preview' ? 'source' : 'preview';\n this.mode = next;\n if (this.input) this.input.state.mode = next;\n if (next === 'preview' && (this.previewStale || !this.previewElement)) void this.reload();\n }\n\n private attachPreview = async () => {\n if (this.attachingPreview) return;\n this.attachingPreview = true;\n try {\n const result = await attachPreviewShot(this);\n if (typeof result === 'string') {\n this.showError(result);\n return;\n }\n if (result.stored === false) {\n this.showError(String(result.note ?? 'Could not attach the preview'));\n return;\n }\n this.showInfo('Attached preview');\n } catch (err) {\n this.showError(err instanceof Error ? err.message : String(err));\n } finally {\n this.attachingPreview = false;\n }\n };\n\n protected renderToolbar() {\n if (!this.ready) return nothing;\n const toSource = this.mode === 'preview';\n const label = toSource ? 'Source' : 'Preview';\n return html`\n ${this.showSource ? html`\n <wa-button appearance=\"plain\" size=\"s\" title=${label} @click=${() => this.toggleMode()}>\n ${icon(toSource ? 'code' : 'eye', { slot: 'start' })}\n ${label}\n </wa-button>\n ` : nothing}\n <wa-button\n appearance=\"plain\"\n size=\"s\"\n title=\"Attach a screenshot of the preview\"\n ?loading=${this.attachingPreview}\n ?disabled=${this.attachingPreview}\n @click=${() => this.attachPreview()}>\n ${icon('camera', { slot: 'start' })}\n Screenshot\n </wa-button>\n `;\n }\n\n protected renderContent() {\n if (!this.ready) return html``;\n const showPreview = !this.showSource || this.mode === 'preview';\n return html`\n <div class=\"canvas-preview ${showPreview ? '' : 'canvas-hidden'}\">\n ${this.previewError ? html`<pre class=\"canvas-error\">${this.previewError}</pre>` : nothing}\n <wa-scroller class=\"canvas-scroll\" orientation=\"vertical\">\n <div class=\"canvas-mount\"></div>\n </wa-scroller>\n </div>\n ${this.showSource ? html`\n <docks-monaco-widget\n class=${this.mode === 'source' ? '' : 'canvas-hidden'}\n .value=${this.sourceText}\n .language=${'javascript'}\n .uri=${this.entryPath || this.canvasName || 'canvas.js'}\n @content-change=${this.onContentChange}>\n </docks-monaco-widget>\n ` : nothing}\n `;\n }\n\n static styles = css`\n :host { display: flex; flex-direction: column; height: 100%; min-height: 0; }\n .canvas-preview { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }\n .canvas-preview.canvas-hidden, docks-monaco-widget.canvas-hidden { display: none; }\n .canvas-preview.canvas-capture {\n display: flex !important;\n position: fixed;\n left: 0;\n top: 0;\n z-index: 2147483000;\n overflow: hidden;\n background: var(--wa-color-surface-default, #fff);\n }\n wa-scroller.canvas-scroll { flex: 1 1 0; min-height: 0; height: 100%; }\n .canvas-mount > * { display: block; }\n docks-monaco-widget { display: block; height: 100%; min-height: 0; }\n .canvas-error {\n margin: 0;\n padding: var(--wa-space-s, 8px);\n white-space: pre-wrap;\n color: var(--wa-color-danger-on-quiet, #b42318);\n }\n `;\n}\n\n@customElement('docks-canvas-editor')\nexport class DocksCanvasEditor extends DocksCanvasSurface {\n override async save(): Promise<void> {\n const value = this.getContent() ?? '';\n const data = this.input?.data;\n if (data instanceof File) await data.saveContents(value);\n if ((this.mode === 'preview' || !this.showSource) && this.previewStale) await this.reload();\n this.markDirty(false);\n }\n}\n\nfunction nextFrame(): Promise<void> {\n return new Promise(resolve => requestAnimationFrame(() => resolve()));\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'docks-canvas-surface': DocksCanvasSurface;\n 'docks-canvas-editor': DocksCanvasEditor;\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBO,IAAM,qBAAN,MAAM,2BAA2B,UAA2C;;;EAEhC,KAAA,OAAA;EAEvB,KAAA,YAAA;EACH,KAAA,SAAA;EACqB,KAAA,aAAA;EAEV,KAAA,aAAA;EACgB,KAAA,OAAA;EAEZ,KAAA,mBAAA;EAImB,KAAA,aAAA;EAC1B,KAAA,OAAA;GAAE,WAAW,MAAM,aAAa;GAAU,gBAAgB,KAAA;GAAW,gBAAgB,KAAA;EAAU;EAG5G,KAAA,QAAA;EACW,KAAA,mBAAA;EACS,KAAA,aAAA,QAAQ,QAAQ;EAChC,KAAA,YAAA;EACK,KAAA,iBAAA;EACA,KAAA,eAAA;EAuOU,KAAA,2BAAA;GAC/B,KAAU,gBAAgB;EAC9B;EAQmB,KAAA,WAAA,UAAiB;GAChC,IAAI,CAAC,KAAK,SAAU,MAA+B,WAAW,MAAM;GAEpE,KADe,KAAK,WAAW,KAAK,QACrB,KAAK,kBAAkB,KAAK,gBAAgB;GAC3D,KAAK,eAAe;GACpB,IAAI,KAAK,SAAS,aAAa,CAAC,KAAK,YAAY,KAAU,OAAO;EACtE;EAQgC,KAAA,wBAAA;GAC5B,MAAM,OAAO,KAAK,QAAQ,WAAW,KAAK,KAAK;GAC/C,KAAK,eAAe,SAAS,KAAK;GAClC,KAAK,aAAa;GAClB,KAAK,UAAU,IAAI;EACvB;EAUwB,KAAA,gBAAA,YAAY;GAChC,IAAI,KAAK,kBAAkB;GAC3B,KAAK,mBAAmB;GACxB,IAAI;IACA,MAAM,SAAS,MAAM,kBAAkB,IAAI;IAC3C,IAAI,OAAO,WAAW,UAAU;KAC5B,KAAK,UAAU,MAAM;KACrB;IACJ;IACA,IAAI,OAAO,WAAW,OAAO;KACzB,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c,qBAAqB,CAAA,GAAA,iBAAA;AAWpC,SAAS,YAA2B;CAChC,OAAO,IAAI,SAAQ,YAAW,4BAA4B,QAAQ,CAAC,CAAC;AACxE"}
|
package/dist/commands.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,KAAK,WAAW,EACnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,KAAK,WAAW,EACnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,OAAO,iBAAiB,CAAC;AAIzB,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,kBAAkB,EAAE,UAAU,SAAK,GAAG,WAAW,CAehG;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMpE;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOpE;AAMD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAYjF;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjE;AAiBD,wBAAgB,sBAAsB,IAAI,IAAI,CAyK7C"}
|
package/dist/commands.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { listRegisteredCanvases } from "./canvases.js";
|
|
2
|
-
import { findOpenCanvas, readActiveCanvas } from "./active-canvas.js";
|
|
2
|
+
import { connectedWorkspaceEditors, findOpenCanvas, readActiveCanvas } from "./active-canvas.js";
|
|
3
3
|
import { attachPreviewShot } from "./preview-image.js";
|
|
4
|
+
import { writeWorkspaceFile } from "./workspace-file.js";
|
|
4
5
|
import "./canvas-editor.js";
|
|
5
6
|
import { File, PANEL_BOTTOM, SIDEBAR_AUXILIARY, SIDEBAR_MAIN, contributionRegistry, editorRegistry, registerAll, workspaceService } from "@eclipse-docks/core";
|
|
6
7
|
import { html } from "@eclipse-docks/core/externals/lit";
|
|
@@ -101,8 +102,11 @@ function registerCanvasCommands() {
|
|
|
101
102
|
if (path) {
|
|
102
103
|
const opened = await openCanvasByPath(path);
|
|
103
104
|
if (opened !== "ready") return opened;
|
|
104
|
-
const
|
|
105
|
-
|
|
105
|
+
const normalized = path.replace(/^\/+/, "");
|
|
106
|
+
const active = await waitForCanvas((item) => item.getFilePath?.()?.replace(/^\/+/, "") === normalized);
|
|
107
|
+
if (!active?.reload) return opened;
|
|
108
|
+
await active.syncFromFile?.();
|
|
109
|
+
return active.reload();
|
|
106
110
|
}
|
|
107
111
|
return "Provide a workspace path or a registered canvas name";
|
|
108
112
|
} }
|
|
@@ -111,32 +115,33 @@ function registerCanvasCommands() {
|
|
|
111
115
|
command: {
|
|
112
116
|
id: "canvas.apply_source",
|
|
113
117
|
name: "Apply canvas source",
|
|
114
|
-
description: "
|
|
118
|
+
description: "Updates an open canvas editor and recompiles its preview without saving. When that canvas is not open in an editor, writes the file instead.",
|
|
115
119
|
parameters: [{
|
|
116
120
|
name: "source",
|
|
117
121
|
description: "Full canvas module source",
|
|
118
122
|
required: true
|
|
119
123
|
}, {
|
|
120
124
|
name: "path",
|
|
121
|
-
description: "Workspace path of the canvas file",
|
|
125
|
+
description: "Workspace path of the canvas file. Required when that canvas is not open in an editor.",
|
|
122
126
|
required: false
|
|
123
127
|
}]
|
|
124
128
|
},
|
|
125
|
-
handler: {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
handler: { execute: async ({ params }) => {
|
|
130
|
+
const source = String(params?.source ?? "");
|
|
131
|
+
const path = (typeof params?.path === "string" ? params.path : void 0) ?? workspaceCanvas()?.getFilePath?.() ?? void 0;
|
|
132
|
+
const targets = path ? connectedWorkspaceEditors(path) : [];
|
|
133
|
+
if (targets.length) {
|
|
134
|
+
let compiled = "ready";
|
|
135
|
+
for (const editor of targets) {
|
|
136
|
+
if (!editor.setSource || !editor.reload) continue;
|
|
137
|
+
editor.setSource(source);
|
|
138
|
+
compiled = await editor.reload();
|
|
135
139
|
}
|
|
136
|
-
|
|
137
|
-
return active.reload();
|
|
140
|
+
return compiled;
|
|
138
141
|
}
|
|
139
|
-
|
|
142
|
+
if (!path) return "Provide a workspace path";
|
|
143
|
+
return writeWorkspaceFile(path, source);
|
|
144
|
+
} }
|
|
140
145
|
});
|
|
141
146
|
registerAll({
|
|
142
147
|
command: {
|
package/dist/commands.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","names":[],"sources":["../src/commands.ts"],"sourcesContent":["import {\n contributionRegistry,\n editorRegistry,\n File,\n registerAll,\n SIDEBAR_AUXILIARY,\n SIDEBAR_MAIN,\n PANEL_BOTTOM,\n workspaceService,\n type EditorInput,\n} from '@eclipse-docks/core';\nimport { html } from '@eclipse-docks/core/externals/lit';\nimport { findOpenCanvas, readActiveCanvas } from './active-canvas';\nimport { listRegisteredCanvases } from './canvases';\nimport type { CanvasContribution } from './contribution';\nimport { attachPreviewShot } from './preview-image';\nimport './canvas-editor';\n\nconst VIEW_SLOTS = new Set([SIDEBAR_MAIN, SIDEBAR_AUXILIARY, PANEL_BOTTOM]);\n\nexport function canvasEditorInput(contribution: CanvasContribution, sourceText = ''): EditorInput {\n const hasSource = contribution.source !== undefined;\n const input = {\n key: `canvas:${contribution.name}`,\n title: contribution.label,\n icon: contribution.icon ?? 'table-columns',\n data: { contribution },\n state: { mode: 'preview' },\n component: () => html``,\n } as EditorInput;\n input.component = (id: string) => hasSource\n ? html`<docks-canvas-editor id=\"${id}\" .input=${input} .source=${sourceText}></docks-canvas-editor>`\n : html`<docks-canvas-surface id=\"${id}\" .input=${input}></docks-canvas-surface>`;\n (input as unknown as { editorId: string }).editorId = 'system.canvas-editor';\n return input;\n}\n\nexport async function openCanvasByName(name: string): Promise<string> {\n const contribution = listRegisteredCanvases().find(item => item.name === name);\n if (!contribution) return `No canvas named ${name}`;\n const sourceText = typeof contribution.source === 'function' ? await contribution.source() : (contribution.source ?? '');\n await editorRegistry.loadEditor(canvasEditorInput(contribution, sourceText));\n return 'ready';\n}\n\nexport async function openCanvasByPath(path: string): Promise<string> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return 'No workspace is open';\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (!(resource instanceof File)) return `Cannot find workspace file \"${path}\"`;\n await editorRegistry.loadEditor(resource, 'system.canvas-editor');\n return 'ready';\n}\n\nfunction viewName(path: string): string {\n return `canvas-view:${path}`;\n}\n\nexport function showCanvasView(slot: string, path: string, source: string): string {\n if (!VIEW_SLOTS.has(slot)) return `Unsupported view slot ${slot}`;\n const name = viewName(path);\n contributionRegistry.unregisterContribution(slot, name);\n contributionRegistry.registerContribution(slot, {\n name,\n label: path.split('/').pop() || path,\n icon: 'table-columns',\n closable: true,\n component: (id: string) => html`<docks-canvas-surface id=\"${id}\" .entryPath=${path} .source=${source}></docks-canvas-surface>`,\n });\n return 'ready';\n}\n\nexport function hideCanvasView(slot: string, path: string): string {\n if (!VIEW_SLOTS.has(slot)) return `Unsupported view slot ${slot}`;\n contributionRegistry.unregisterContribution(slot, viewName(path));\n return 'ready';\n}\n\nfunction workspaceCanvas() {\n const active = readActiveCanvas();\n if (!active?.editor || active.kind !== 'workspace') return null;\n return active;\n}\n\nasync function waitForCanvas(match: (active: NonNullable<ReturnType<typeof readActiveCanvas>>) => boolean) {\n for (let attempt = 0; attempt < 30; attempt++) {\n const active = readActiveCanvas();\n if (active?.reload && match(active)) return active;\n await new Promise(resolve => setTimeout(resolve, 50));\n }\n return null;\n}\n\nexport function registerCanvasCommands(): void {\n registerAll({\n command: {\n id: 'canvas.open',\n name: 'Open canvas',\n description: 'Opens a workspace .canvas.js path or a canvas registered on system.canvases and returns ready or a compile error',\n parameters: [\n { name: 'path', description: 'Workspace path of a .canvas.js file', required: false },\n { name: 'name', description: 'Name of a canvas registered on system.canvases', required: false },\n ],\n },\n handler: {\n execute: async ({ params }) => {\n const name = params?.name as string | undefined;\n const path = params?.path as string | undefined;\n if (name) {\n const opened = await openCanvasByName(name);\n if (opened !== 'ready') return opened;\n const active = await waitForCanvas(item => item.canvasName === name);\n return active?.reload ? active.reload() : opened;\n }\n if (path) {\n const opened = await openCanvasByPath(path);\n if (opened !== 'ready') return opened;\n const active = await waitForCanvas(item => item.kind === 'workspace');\n return active?.reload ? active.reload() : opened;\n }\n return 'Provide a workspace path or a registered canvas name';\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.apply_source',\n name: 'Apply canvas source',\n description: 'Writes source into the active workspace canvas, compiles it, and returns ready or the compile error',\n parameters: [\n { name: 'source', description: 'Full canvas module source', required: true },\n { name: 'path', description: 'Workspace path of the canvas file', required: false },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n if (!active?.setSource || !active.reload) return 'No workspace canvas is active';\n const source = String(params?.source ?? '');\n const path = (params?.path as string | undefined) ?? active.getFilePath?.() ?? undefined;\n if (path) {\n const { writeWorkspaceFile } = await import('./workspace-file');\n const written = await writeWorkspaceFile(path, source);\n if (!written) return `Cannot write workspace file \"${path}\"`;\n }\n active.setSource(source);\n return active.reload();\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.get_source',\n name: 'Get canvas source',\n description: 'Returns the current source buffer of the active workspace canvas',\n parameters: [],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async () => workspaceCanvas()?.getContent?.() ?? '',\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.get_state',\n name: 'Get canvas state',\n description: 'Reads one persisted state value from the active workspace canvas',\n parameters: [{ name: 'key', description: 'State key', required: true }],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => workspaceCanvas()?.getState?.(String(params?.key ?? '')),\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.set_state',\n name: 'Set canvas state',\n description: 'Writes one persisted state value on the active workspace canvas',\n parameters: [\n { name: 'key', description: 'State key', required: true },\n { name: 'value', description: 'JSON value', required: true },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n if (!active?.setState) return 'No workspace canvas is active';\n active.setState(String(params?.key ?? ''), params?.value);\n return 'ready';\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.capture_preview',\n name: 'Capture canvas preview',\n description: 'Renders the open canvas preview to an image, attaches it to the session, and returns it for visual inspection. Content inside an iframe may be blank.',\n parameters: [],\n },\n handler: {\n canExecute: () => !!findOpenCanvas()?.capturePreview,\n execute: async () => {\n const active = findOpenCanvas();\n if (!active) return 'No canvas is open';\n return attachPreviewShot(active);\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.show_as_view',\n name: 'Show canvas as view',\n description: 'Pins the active workspace canvas preview into a sidebar or the bottom panel',\n parameters: [\n { name: 'slot', description: 'sidebar-main, sidebar-auxiliary, or panel-bottom', required: true },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n const path = active?.getFilePath?.();\n if (!active || !path) return 'No workspace canvas is active';\n return showCanvasView(String(params?.slot ?? ''), path, active.getContent?.() ?? '');\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.hide_view',\n name: 'Hide canvas view',\n description: 'Removes a pinned canvas preview from a sidebar or the bottom panel',\n parameters: [\n { name: 'slot', description: 'sidebar-main, sidebar-auxiliary, or panel-bottom', required: true },\n { name: 'path', description: 'Workspace path of the canvas file', required: false },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const path = (params?.path as string | undefined) ?? workspaceCanvas()?.getFilePath?.() ?? '';\n if (!path) return 'No canvas path';\n return hideCanvasView(String(params?.slot ?? ''), path);\n },\n },\n });\n}\n"],"mappings":";;;;;;;AAkBA,IAAM,6BAAa,IAAI,IAAI;CAAC;CAAc;CAAmB;AAAY,CAAC;AAE1E,SAAgB,kBAAkB,cAAkC,aAAa,IAAiB;CAC9F,MAAM,YAAY,aAAa,WAAW,KAAA;CAC1C,MAAM,QAAQ;EACV,KAAK,UAAU,aAAa;EAC5B,OAAO,aAAa;EACpB,MAAM,aAAa,QAAQ;EAC3B,MAAM,EAAE,aAAa;EACrB,OAAO,EAAE,MAAM,UAAU;EACzB,iBAAiB,IAAI;CACzB;CACA,MAAM,aAAa,OAAe,YAC5B,IAAI,4BAA4B,GAAG,WAAW,MAAM,WAAW,WAAW,2BAC1E,IAAI,6BAA6B,GAAG,WAAW,MAAM;CAC3D,MAA2C,WAAW;CACtD,OAAO;AACX;AAEA,eAAsB,iBAAiB,MAA+B;CAClE,MAAM,eAAe,uBAAuB,CAAC,CAAC,MAAK,SAAQ,KAAK,SAAS,IAAI;CAC7E,IAAI,CAAC,cAAc,OAAO,mBAAmB;CAC7C,MAAM,aAAa,OAAO,aAAa,WAAW,aAAa,MAAM,aAAa,OAAO,IAAK,aAAa,UAAU;CACrH,MAAM,eAAe,WAAW,kBAAkB,cAAc,UAAU,CAAC;CAC3E,OAAO;AACX;AAEA,eAAsB,iBAAiB,MAA+B;CAClE,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,EAA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C,CAAC,gBAAgB;GACpC,SAAS,OAAO,EAAE,aAAa;IAC3B,MAAM,SAAS,gBAAgB;IAC/B,MAAM,OAAO,QAAQ,cAAc;IACnC,IAAI,CAAC,UAAU,CAAC,MAAM,OAAO;IAC7B,OAAO,eAAe,OAAO,QAAQ,QAAQ,EAAE,GAAG,MAAM,OAAO,aAAa,KAAK,EAAE;GACvF;EACJ;CACJ,CAAC;CAED,YAAY;EACR,SAAS;GACL,IAAI;GACJ,MAAM;GACN,aAAa;GACb,YAAY,CACR;IAAE,MAAM;IAAQ,aAAa;IAAoD,UAAU;GAAK,GAChG;IAAE,MAAM;IAAQ,aAAa;IAAqC,UAAU;GAAM,CACtF;EACJ;EACA,SAAS;GACL,kBAAkB,CAAC,CAAC,gBAAgB;GACpC,SAAS,OAAO,EAAE,aAAa;IAC3B,MAAM,OAAQ,QAAQ,QAA+B,gBAAgB,CAAC,EAAE,cAAc,KAAK;IAC3F,IAAI,CAAC,MAAM,OAAO;IAClB,OAAO,eAAe,OAAO,QAAQ,QAAQ,EAAE,GAAG,IAAI;GAC1D;EACJ;CACJ,CAAC;AACL"}
|
|
1
|
+
{"version":3,"file":"commands.js","names":[],"sources":["../src/commands.ts"],"sourcesContent":["import {\n contributionRegistry,\n editorRegistry,\n File,\n registerAll,\n SIDEBAR_AUXILIARY,\n SIDEBAR_MAIN,\n PANEL_BOTTOM,\n workspaceService,\n type EditorInput,\n} from '@eclipse-docks/core';\nimport { html } from '@eclipse-docks/core/externals/lit';\nimport { connectedWorkspaceEditors, findOpenCanvas, readActiveCanvas } from './active-canvas';\nimport { listRegisteredCanvases } from './canvases';\nimport type { CanvasContribution } from './contribution';\nimport { attachPreviewShot } from './preview-image';\nimport { writeWorkspaceFile } from './workspace-file';\nimport './canvas-editor';\n\nconst VIEW_SLOTS = new Set([SIDEBAR_MAIN, SIDEBAR_AUXILIARY, PANEL_BOTTOM]);\n\nexport function canvasEditorInput(contribution: CanvasContribution, sourceText = ''): EditorInput {\n const hasSource = contribution.source !== undefined;\n const input = {\n key: `canvas:${contribution.name}`,\n title: contribution.label,\n icon: contribution.icon ?? 'table-columns',\n data: { contribution },\n state: { mode: 'preview' },\n component: () => html``,\n } as EditorInput;\n input.component = (id: string) => hasSource\n ? html`<docks-canvas-editor id=\"${id}\" .input=${input} .source=${sourceText}></docks-canvas-editor>`\n : html`<docks-canvas-surface id=\"${id}\" .input=${input}></docks-canvas-surface>`;\n (input as unknown as { editorId: string }).editorId = 'system.canvas-editor';\n return input;\n}\n\nexport async function openCanvasByName(name: string): Promise<string> {\n const contribution = listRegisteredCanvases().find(item => item.name === name);\n if (!contribution) return `No canvas named ${name}`;\n const sourceText = typeof contribution.source === 'function' ? await contribution.source() : (contribution.source ?? '');\n await editorRegistry.loadEditor(canvasEditorInput(contribution, sourceText));\n return 'ready';\n}\n\nexport async function openCanvasByPath(path: string): Promise<string> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return 'No workspace is open';\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (!(resource instanceof File)) return `Cannot find workspace file \"${path}\"`;\n await editorRegistry.loadEditor(resource, 'system.canvas-editor');\n return 'ready';\n}\n\nfunction viewName(path: string): string {\n return `canvas-view:${path}`;\n}\n\nexport function showCanvasView(slot: string, path: string, source: string): string {\n if (!VIEW_SLOTS.has(slot)) return `Unsupported view slot ${slot}`;\n const name = viewName(path);\n contributionRegistry.unregisterContribution(slot, name);\n contributionRegistry.registerContribution(slot, {\n name,\n label: path.split('/').pop() || path,\n icon: 'table-columns',\n closable: true,\n component: (id: string) => html`<docks-canvas-surface id=\"${id}\" .entryPath=${path} .source=${source}></docks-canvas-surface>`,\n });\n return 'ready';\n}\n\nexport function hideCanvasView(slot: string, path: string): string {\n if (!VIEW_SLOTS.has(slot)) return `Unsupported view slot ${slot}`;\n contributionRegistry.unregisterContribution(slot, viewName(path));\n return 'ready';\n}\n\nfunction workspaceCanvas() {\n const active = readActiveCanvas();\n if (!active?.editor || active.kind !== 'workspace') return null;\n return active;\n}\n\nasync function waitForCanvas(match: (active: NonNullable<ReturnType<typeof readActiveCanvas>>) => boolean) {\n for (let attempt = 0; attempt < 30; attempt++) {\n const active = readActiveCanvas();\n if (active?.reload && match(active)) return active;\n await new Promise(resolve => setTimeout(resolve, 50));\n }\n return null;\n}\n\nexport function registerCanvasCommands(): void {\n registerAll({\n command: {\n id: 'canvas.open',\n name: 'Open canvas',\n description: 'Opens a workspace .canvas.js path or a canvas registered on system.canvases and returns ready or a compile error',\n parameters: [\n { name: 'path', description: 'Workspace path of a .canvas.js file', required: false },\n { name: 'name', description: 'Name of a canvas registered on system.canvases', required: false },\n ],\n },\n handler: {\n execute: async ({ params }) => {\n const name = params?.name as string | undefined;\n const path = params?.path as string | undefined;\n if (name) {\n const opened = await openCanvasByName(name);\n if (opened !== 'ready') return opened;\n const active = await waitForCanvas(item => item.canvasName === name);\n return active?.reload ? active.reload() : opened;\n }\n if (path) {\n const opened = await openCanvasByPath(path);\n if (opened !== 'ready') return opened;\n const normalized = path.replace(/^\\/+/, '');\n const active = await waitForCanvas(item => item.getFilePath?.()?.replace(/^\\/+/, '') === normalized);\n if (!active?.reload) return opened;\n await active.syncFromFile?.();\n return active.reload();\n }\n return 'Provide a workspace path or a registered canvas name';\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.apply_source',\n name: 'Apply canvas source',\n description: 'Updates an open canvas editor and recompiles its preview without saving. When that canvas is not open in an editor, writes the file instead.',\n parameters: [\n { name: 'source', description: 'Full canvas module source', required: true },\n { name: 'path', description: 'Workspace path of the canvas file. Required when that canvas is not open in an editor.', required: false },\n ],\n },\n handler: {\n execute: async ({ params }) => {\n const source = String(params?.source ?? '');\n const requested = typeof params?.path === 'string' ? params.path : undefined;\n const path = requested ?? workspaceCanvas()?.getFilePath?.() ?? undefined;\n const targets = path ? connectedWorkspaceEditors(path) : [];\n if (targets.length) {\n let compiled = 'ready';\n for (const editor of targets) {\n if (!editor.setSource || !editor.reload) continue;\n editor.setSource(source);\n compiled = await editor.reload();\n }\n return compiled;\n }\n if (!path) return 'Provide a workspace path';\n return writeWorkspaceFile(path, source);\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.get_source',\n name: 'Get canvas source',\n description: 'Returns the current source buffer of the active workspace canvas',\n parameters: [],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async () => workspaceCanvas()?.getContent?.() ?? '',\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.get_state',\n name: 'Get canvas state',\n description: 'Reads one persisted state value from the active workspace canvas',\n parameters: [{ name: 'key', description: 'State key', required: true }],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => workspaceCanvas()?.getState?.(String(params?.key ?? '')),\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.set_state',\n name: 'Set canvas state',\n description: 'Writes one persisted state value on the active workspace canvas',\n parameters: [\n { name: 'key', description: 'State key', required: true },\n { name: 'value', description: 'JSON value', required: true },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n if (!active?.setState) return 'No workspace canvas is active';\n active.setState(String(params?.key ?? ''), params?.value);\n return 'ready';\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.capture_preview',\n name: 'Capture canvas preview',\n description: 'Renders the open canvas preview to an image, attaches it to the session, and returns it for visual inspection. Content inside an iframe may be blank.',\n parameters: [],\n },\n handler: {\n canExecute: () => !!findOpenCanvas()?.capturePreview,\n execute: async () => {\n const active = findOpenCanvas();\n if (!active) return 'No canvas is open';\n return attachPreviewShot(active);\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.show_as_view',\n name: 'Show canvas as view',\n description: 'Pins the active workspace canvas preview into a sidebar or the bottom panel',\n parameters: [\n { name: 'slot', description: 'sidebar-main, sidebar-auxiliary, or panel-bottom', required: true },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const active = workspaceCanvas();\n const path = active?.getFilePath?.();\n if (!active || !path) return 'No workspace canvas is active';\n return showCanvasView(String(params?.slot ?? ''), path, active.getContent?.() ?? '');\n },\n },\n });\n\n registerAll({\n command: {\n id: 'canvas.hide_view',\n name: 'Hide canvas view',\n description: 'Removes a pinned canvas preview from a sidebar or the bottom panel',\n parameters: [\n { name: 'slot', description: 'sidebar-main, sidebar-auxiliary, or panel-bottom', required: true },\n { name: 'path', description: 'Workspace path of the canvas file', required: false },\n ],\n },\n handler: {\n canExecute: () => !!workspaceCanvas(),\n execute: async ({ params }) => {\n const path = (params?.path as string | undefined) ?? workspaceCanvas()?.getFilePath?.() ?? '';\n if (!path) return 'No canvas path';\n return hideCanvasView(String(params?.slot ?? ''), path);\n },\n },\n });\n}\n"],"mappings":";;;;;;;;AAmBA,IAAM,6BAAa,IAAI,IAAI;CAAC;CAAc;CAAmB;AAAY,CAAC;AAE1E,SAAgB,kBAAkB,cAAkC,aAAa,IAAiB;CAC9F,MAAM,YAAY,aAAa,WAAW,KAAA;CAC1C,MAAM,QAAQ;EACV,KAAK,UAAU,aAAa;EAC5B,OAAO,aAAa;EACpB,MAAM,aAAa,QAAQ;EAC3B,MAAM,EAAE,aAAa;EACrB,OAAO,EAAE,MAAM,UAAU;EACzB,iBAAiB,IAAI;CACzB;CACA,MAAM,aAAa,OAAe,YAC5B,IAAI,4BAA4B,GAAG,WAAW,MAAM,WAAW,WAAW,2BAC1E,IAAI,6BAA6B,GAAG,WAAW,MAAM;CAC3D,MAA2C,WAAW;CACtD,OAAO;AACX;AAEA,eAAsB,iBAAiB,MAA+B;CAClE,MAAM,eAAe,uBAAuB,CAAC,CAAC,MAAK,SAAQ,KAAK,SAAS,IAAI;CAC7E,IAAI,CAAC,cAAc,OAAO,mBAAmB;CAC7C,MAAM,aAAa,OAAO,aAAa,WAAW,aAAa,MAAM,aAAa,OAAO,IAAK,aAAa,UAAU;CACrH,MAAM,eAAe,WAAW,kBAAkB,cAAc,U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R,SAAS;GACL,IAAI;GACJ,MAAM;GACN,aAAa;GACb,YAAY,CAAC;EACjB;EACA,SAAS;GACL,kBAAkB,CAAC,CAAC,eAAe,CAAC,EAAE;GACtC,SAAS,YAAY;IACjB,MAAM,SAAS,eAAe;IAC9B,IAAI,CAAC,QAAQ,OAAO;IACpB,OAAO,kBAAkB,MAAM;GACnC;EACJ;CACJ,CAAC;CAED,YAAY;EACR,SAAS;GACL,IAAI;GACJ,MAAM;GACN,aAAa;GACb,YAAY,CACR;IAAE,MAAM;IAAQ,aAAa;IAAoD,UAAU;GAAK,CACpG;EACJ;EACA,SAAS;GACL,kBAAkB,CAAC,CAAC,gBAAgB;GACpC,SAAS,OAAO,EAAE,aAAa;IAC3B,MAAM,SAAS,gBAAgB;IAC/B,MAAM,OAAO,QAAQ,cAAc;IACnC,IAAI,CAAC,UAAU,CAAC,MAAM,OAAO;IAC7B,OAAO,eAAe,OAAO,QAAQ,QAAQ,EAAE,GAAG,MAAM,OAAO,aAAa,KAAK,EAAE;GACvF;EACJ;CACJ,CAAC;CAED,YAAY;EACR,SAAS;GACL,IAAI;GACJ,MAAM;GACN,aAAa;GACb,YAAY,CACR;IAAE,MAAM;IAAQ,aAAa;IAAoD,UAAU;GAAK,GAChG;IAAE,MAAM;IAAQ,aAAa;IAAqC,UAAU;GAAM,CACtF;EACJ;EACA,SAAS;GACL,kBAAkB,CAAC,CAAC,gBAAgB;GACpC,SAAS,OAAO,EAAE,aAAa;IAC3B,MAAM,OAAQ,QAAQ,QAA+B,gBAAgB,CAAC,EAAE,cAAc,KAAK;IAC3F,IAAI,CAAC,MAAM,OAAO;IAClB,OAAO,eAAe,OAAO,QAAQ,QAAQ,EAAE,GAAG,IAAI;GAC1D;EACJ;CACJ,CAAC;AACL"}
|
package/dist/workspace-file.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { File } from '@eclipse-docks/core';
|
|
2
1
|
import { CanvasFileBytes } from './compile';
|
|
3
2
|
export declare function readWorkspaceFile(path: string): Promise<CanvasFileBytes | null>;
|
|
4
|
-
|
|
3
|
+
/** Writes a canvas module. Used when that file is not open in an editor. */
|
|
4
|
+
export declare function writeWorkspaceFile(path: string, contents: string): Promise<string>;
|
|
5
5
|
//# sourceMappingURL=workspace-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-file.d.ts","sourceRoot":"","sources":["../src/workspace-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workspace-file.d.ts","sourceRoot":"","sources":["../src/workspace-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAIjD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAerF;AAED,4EAA4E;AAC5E,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASxF"}
|
package/dist/workspace-file.js
CHANGED
|
@@ -27,13 +27,16 @@ async function readWorkspaceFile(path) {
|
|
|
27
27
|
if (typeof blob === "string") return { text: blob };
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
|
+
/** Writes a canvas module. Used when that file is not open in an editor. */
|
|
30
31
|
async function writeWorkspaceFile(path, contents) {
|
|
32
|
+
const normalized = path.replace(/^\/+/, "");
|
|
33
|
+
if (!normalized.endsWith(".canvas.js")) return `Not a canvas file "${path}"`;
|
|
31
34
|
const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();
|
|
32
|
-
if (!workspace) return
|
|
33
|
-
const resource = await workspace.getResource(
|
|
34
|
-
if (!(resource instanceof File)) return
|
|
35
|
+
if (!workspace) return "No workspace is open";
|
|
36
|
+
const resource = await workspace.getResource(normalized, { create: true });
|
|
37
|
+
if (!(resource instanceof File)) return `Cannot write workspace file "${path}"`;
|
|
35
38
|
await resource.saveContents(contents);
|
|
36
|
-
return
|
|
39
|
+
return "ready";
|
|
37
40
|
}
|
|
38
41
|
//#endregion
|
|
39
42
|
export { readWorkspaceFile, writeWorkspaceFile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-file.js","names":[],"sources":["../src/workspace-file.ts"],"sourcesContent":["import { File, workspaceService } from '@eclipse-docks/core';\nimport type { CanvasFileBytes } from './compile';\n\nconst TEXT_EXT = new Set(['js', 'mjs', 'css', 'json', 'svg', 'txt', 'md', 'html', 'csv']);\n\nexport async function readWorkspaceFile(path: string): Promise<CanvasFileBytes | null> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return null;\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (!(resource instanceof File)) return null;\n const ext = path.split('.').pop()?.toLowerCase() ?? '';\n if (TEXT_EXT.has(ext) || path.endsWith('.canvas.js')) {\n const text = await resource.getContents();\n return { text: typeof text === 'string' ? text : String(text ?? '') };\n }\n const blob = await resource.getContents({ blob: true });\n if (blob instanceof Blob) return { bytes: new Uint8Array(await blob.arrayBuffer()) };\n if (blob instanceof Uint8Array) return { bytes: blob };\n if (typeof blob === 'string') return { text: blob };\n return null;\n}\n\nexport async function writeWorkspaceFile(path: string, contents: string): Promise<
|
|
1
|
+
{"version":3,"file":"workspace-file.js","names":[],"sources":["../src/workspace-file.ts"],"sourcesContent":["import { File, workspaceService } from '@eclipse-docks/core';\nimport type { CanvasFileBytes } from './compile';\n\nconst TEXT_EXT = new Set(['js', 'mjs', 'css', 'json', 'svg', 'txt', 'md', 'html', 'csv']);\n\nexport async function readWorkspaceFile(path: string): Promise<CanvasFileBytes | null> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return null;\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (!(resource instanceof File)) return null;\n const ext = path.split('.').pop()?.toLowerCase() ?? '';\n if (TEXT_EXT.has(ext) || path.endsWith('.canvas.js')) {\n const text = await resource.getContents();\n return { text: typeof text === 'string' ? text : String(text ?? '') };\n }\n const blob = await resource.getContents({ blob: true });\n if (blob instanceof Blob) return { bytes: new Uint8Array(await blob.arrayBuffer()) };\n if (blob instanceof Uint8Array) return { bytes: blob };\n if (typeof blob === 'string') return { text: blob };\n return null;\n}\n\n/** Writes a canvas module. Used when that file is not open in an editor. */\nexport async function writeWorkspaceFile(path: string, contents: string): Promise<string> {\n const normalized = path.replace(/^\\/+/, '');\n if (!normalized.endsWith('.canvas.js')) return `Not a canvas file \"${path}\"`;\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return 'No workspace is open';\n const resource = await workspace.getResource(normalized, { create: true });\n if (!(resource instanceof File)) return `Cannot write workspace file \"${path}\"`;\n await resource.saveContents(contents);\n return 'ready';\n}\n"],"mappings":";;AAGA,IAAM,2BAAW,IAAI,IAAI;CAAC;CAAM;CAAO;CAAO;CAAQ;CAAO;CAAO;CAAM;CAAQ;AAAK,CAAC;AAExF,eAAsB,kBAAkB,MAA+C;CACnF,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,EAAE,CAAC;CACrE,IAAI,EAAE,oBAAoB,OAAO,OAAO;CACxC,MAAM,MAAM,KAAK,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,YAAY,KAAK;CACpD,IAAI,SAAS,IAAI,GAAG,KAAK,KAAK,SAAS,YAAY,GAAG;EAClD,MAAM,OAAO,MAAM,SAAS,YAAY;EACxC,OAAO,EAAE,MAAM,OAAO,SAAS,WAAW,OAAO,OAAO,QAAQ,EAAE,EAAE;CACxE;CACA,MAAM,OAAO,MAAM,SAAS,YAAY,EAAE,MAAM,KAAK,CAAC;CACtD,IAAI,gBAAgB,MAAM,OAAO,EAAE,OAAO,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC,EAAE;CACnF,IAAI,gBAAgB,YAAY,OAAO,EAAE,OAAO,KAAK;CACrD,IAAI,OAAO,SAAS,UAAU,OAAO,EAAE,MAAM,KAAK;CAClD,OAAO;AACX;;AAGA,eAAsB,mBAAmB,MAAc,UAAmC;CACtF,MAAM,aAAa,KAAK,QAAQ,QAAQ,EAAE;CAC1C,IAAI,CAAC,WAAW,SAAS,YAAY,GAAG,OAAO,sBAAsB,KAAK;CAC1E,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,MAAM,UAAU,YAAY,YAAY,EAAE,QAAQ,KAAK,CAAC;CACzE,IAAI,EAAE,oBAAoB,OAAO,OAAO,gCAAgC,KAAK;CAC7E,MAAM,SAAS,aAAa,QAAQ;CACpC,OAAO;AACX"}
|
package/package.json
CHANGED
|
@@ -15,9 +15,9 @@ Write a workspace file ending in `.canvas.js`. Default-export a `LitElement` sub
|
|
|
15
15
|
|
|
16
16
|
1. **`canvasHost` is unavailable in `constructor`.** The host sets `this.canvasHost` after construction. Read/write persisted state in `connectedCallback` (after `super`) or later. Always guard: `this.canvasHost?.getState` / `setState`.
|
|
17
17
|
2. Pure JavaScript only — no TypeScript, no decorators. Declare reactive fields with `static properties = { … }`. Initialize plain defaults in `constructor`; hydrate from `canvasHost` only after connect.
|
|
18
|
-
3.
|
|
18
|
+
3. Build controls and chrome with Web Awesome (`wa-button`, `wa-input`, `wa-checkbox`, `wa-card`, `wa-callout`, `wa-spinner`). `import "docks/webawesome"` only registers the elements; a raw `<button>` or `<input>` is not a substitute. Load `eclipse-docks-webawesome` before a non-trivial UI, and use `--wa-color-*` tokens instead of hardcoded colors.
|
|
19
19
|
4. Emit complete, valid JavaScript — no truncated objects or unfinished strings.
|
|
20
|
-
5. Cross-
|
|
20
|
+
5. The page uses `Cross-Origin-Embedder-Policy: require-corp`. A cross-origin response loads only when the request is CORS and the server sends `Access-Control-Allow-Origin`, or when the server sends `Cross-Origin-Resource-Policy: cross-origin`. An `<iframe srcdoc>` inherits this policy; `sandbox="allow-same-origin"` does not exempt it. Keep `docks/lit`, `docks/webawesome`, and `canvasHost` on the LitElement.
|
|
21
21
|
|
|
22
22
|
## Minimal pattern
|
|
23
23
|
|
|
@@ -78,6 +78,34 @@ export default class extends LitElement {
|
|
|
78
78
|
|
|
79
79
|
APIs: `this.canvasHost.getState(key, fallback)`, `this.canvasHost.setState(key, value)`, `this.canvasHost.openFile(path)`.
|
|
80
80
|
|
|
81
|
+
## Cross-origin resources
|
|
82
|
+
|
|
83
|
+
`<img>`, `<link>`, and `<script>` tags without `crossorigin` are no-cors. A no-cors response that omits `Cross-Origin-Resource-Policy` fails with `not-set cross-origin-resource-policy`, even when it sends `Access-Control-Allow-Origin: *`. Moving that URL into an `<iframe srcdoc>` does not change the check. Subresources inside the frame follow the same rule.
|
|
84
|
+
|
|
85
|
+
When the server only sends `Access-Control-Allow-Origin`, request the resource as CORS. `fetch()` already does. For an element, set `crossorigin="anonymous"`. When a library creates the element, set its equivalent option (often `crossOrigin: "anonymous"`). A missing `Access-Control-Allow-Origin` header on that request is a CORS error, not the CORP error.
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<img crossorigin="anonymous" src="https://cdn.example/asset.png" />
|
|
89
|
+
<script crossorigin="anonymous" src="https://cdn.example/lib.js"></script>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
A host that sends neither header cannot be embedded in this page. Pass the string `"anonymous"` to a library option (`crossOrigin: "anonymous"`). A boolean `true` is not that option.
|
|
93
|
+
|
|
94
|
+
## Styles inside the shadow root
|
|
95
|
+
|
|
96
|
+
The canvas renders in a shadow root. A `<link>` or `<style>` added to `document.head` does not apply to nodes inside that root. A widget that positions its own DOM with classes will load its images and still draw them in the wrong place until its stylesheet is on the shadow root.
|
|
97
|
+
|
|
98
|
+
Fetch the stylesheet as CORS and adopt it before constructing the widget:
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
const cssText = await (await fetch(stylesheetUrl, { mode: "cors" })).text();
|
|
102
|
+
const sheet = new CSSStyleSheet();
|
|
103
|
+
sheet.replaceSync(cssText);
|
|
104
|
+
this.shadowRoot.adoptedStyleSheets = [...this.shadowRoot.adoptedStyleSheets, sheet];
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`static styles` is for the host. Do not rely on a document-level stylesheet for DOM the library creates inside the shadow root.
|
|
108
|
+
|
|
81
109
|
## Imports
|
|
82
110
|
|
|
83
111
|
- `docks/lit`, `docks/webawesome`, `docks/core` → running app
|
|
@@ -93,7 +121,7 @@ Before non-trivial UI or shell integration, load companion skills as needed:
|
|
|
93
121
|
|
|
94
122
|
1. `workspace_write` a durable `<root>/….canvas.js` (qualify with a root from `workspace_list`).
|
|
95
123
|
2. `canvas.open` with that path — returns `ready` or the compile/runtime error.
|
|
96
|
-
3.
|
|
124
|
+
3. Change a canvas with `canvas.apply_source`. If that canvas is open in an editor, the editor marks itself dirty and recompiles the preview and does not save. If it is not open in an editor, the tool writes the file. Do not `workspace_write` a canvas that is already open.
|
|
97
125
|
4. Optional: `canvas.capture_preview` to attach a screenshot (iframe contents may be blank).
|
|
98
126
|
|
|
99
127
|
Extension-registered canvases live on `system.canvases` and open by name via `canvas.open`.
|
|
@@ -122,7 +122,7 @@ log.info("ready");
|
|
|
122
122
|
## Canvas notes
|
|
123
123
|
|
|
124
124
|
- Host persistence for a workspace `.canvas.js` is `canvasHost.getState` / `setState`, not `appSettings`, unless you intentionally share app-wide settings.
|
|
125
|
-
- Cross-origin
|
|
125
|
+
- Cross-origin loads follow the canvas skill: CORS plus `Access-Control-Allow-Origin`, or `Cross-Origin-Resource-Policy: cross-origin`. An iframe `srcdoc` does not opt out.
|
|
126
126
|
- Keep UI building blocks on `docks/lit` + `docks/webawesome`; use `docks/core` for shell integration.
|
|
127
127
|
|
|
128
128
|
## Anti-patterns
|
|
@@ -147,4 +147,5 @@ static styles = css`
|
|
|
147
147
|
- Per-component package imports inside `.canvas.js`
|
|
148
148
|
- Using `wa-dropdown` where a form `wa-select` is required
|
|
149
149
|
- Hardcoded colors in CSS/templates instead of `--wa-*` color tokens
|
|
150
|
-
-
|
|
150
|
+
- Hand-rolled `<button>`, `<input>`, or checkbox chrome, or a hardcoded color palette, when `wa-*` and `--wa-color-*` tokens cover it
|
|
151
|
+
- Loading a cross-origin image, style, or script as no-cors when the host omits CORP — request it as CORS (see canvas skill); keep `wa-*` on the host element. A widget stylesheet added to `document.head` does not apply inside the canvas shadow root — adopt it there (see canvas skill)
|