@eclipse-docks/extension-canvas 0.8.1 → 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 +8 -0
- package/dist/active-canvas.d.ts.map +1 -1
- package/dist/active-canvas.js +24 -2
- package/dist/active-canvas.js.map +1 -1
- package/dist/canvas-editor.d.ts +13 -0
- package/dist/canvas-editor.d.ts.map +1 -1
- package/dist/canvas-editor.js +144 -29
- package/dist/canvas-editor.js.map +1 -1
- package/dist/canvas-extension.js +28 -4
- package/dist/canvas-extension.js.map +1 -1
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +40 -31
- package/dist/commands.js.map +1 -1
- package/dist/preview-image.d.ts +21 -0
- package/dist/preview-image.d.ts.map +1 -0
- package/dist/preview-image.js +87 -0
- package/dist/preview-image.js.map +1 -0
- 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 +5 -3
- package/skills/eclipse-docks-canvas/SKILL.md +127 -0
- package/skills/eclipse-docks-core/SKILL.md +132 -0
- package/skills/eclipse-docks-lit/SKILL.md +68 -0
- package/skills/eclipse-docks-webawesome/SKILL.md +151 -0
- package/dist/help.d.ts +0 -3
- package/dist/help.d.ts.map +0 -1
- package/dist/help.js +0 -19
- package/dist/help.js.map +0 -1
package/dist/active-canvas.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PreviewShot } from './preview-image';
|
|
1
2
|
export interface ActiveCanvas {
|
|
2
3
|
kind: 'workspace' | 'registered';
|
|
3
4
|
canvasName?: string;
|
|
@@ -5,9 +6,16 @@ export interface ActiveCanvas {
|
|
|
5
6
|
getContent?: () => string | null;
|
|
6
7
|
getFilePath?: () => string | null;
|
|
7
8
|
setSource?: (source: string) => void;
|
|
9
|
+
save?: () => Promise<void>;
|
|
10
|
+
syncFromFile?: () => Promise<boolean>;
|
|
8
11
|
reload?: () => Promise<string>;
|
|
12
|
+
capturePreview?: () => Promise<PreviewShot>;
|
|
9
13
|
getState?: (key: string) => unknown;
|
|
10
14
|
setState?: (key: string, value: unknown) => void;
|
|
11
15
|
}
|
|
12
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[];
|
|
19
|
+
/** Active canvas editor, or any open canvas part when focus has moved elsewhere. */
|
|
20
|
+
export declare function findOpenCanvas(): ActiveCanvas | null;
|
|
13
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":"
|
|
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
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { activeEditorSignal } from "@eclipse-docks/core";
|
|
2
2
|
//#region src/active-canvas.ts
|
|
3
3
|
function readActiveCanvas() {
|
|
4
|
-
|
|
4
|
+
return fromElement(activeEditorSignal.get());
|
|
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
|
+
}
|
|
13
|
+
/** Active canvas editor, or any open canvas part when focus has moved elsewhere. */
|
|
14
|
+
function findOpenCanvas() {
|
|
15
|
+
const active = readActiveCanvas();
|
|
16
|
+
if (active?.capturePreview) return active;
|
|
17
|
+
for (const node of document.querySelectorAll("docks-canvas-editor, docks-canvas-surface")) {
|
|
18
|
+
const mapped = fromElement(node);
|
|
19
|
+
if (mapped?.capturePreview) return mapped;
|
|
20
|
+
}
|
|
21
|
+
return active;
|
|
22
|
+
}
|
|
23
|
+
function fromElement(active) {
|
|
5
24
|
if (!active) return null;
|
|
6
25
|
const localName = active.localName;
|
|
7
26
|
if (localName !== "docks-canvas-editor" && localName !== "docks-canvas-surface") return null;
|
|
@@ -12,12 +31,15 @@ function readActiveCanvas() {
|
|
|
12
31
|
getContent: active.getContent?.bind(active),
|
|
13
32
|
getFilePath: active.getFilePath?.bind(active),
|
|
14
33
|
setSource: active.setSource?.bind(active),
|
|
34
|
+
save: active.save?.bind(active),
|
|
35
|
+
syncFromFile: active.syncFromFile?.bind(active),
|
|
15
36
|
reload: active.reload?.bind(active),
|
|
37
|
+
capturePreview: active.capturePreview?.bind(active),
|
|
16
38
|
getState: active.getState?.bind(active),
|
|
17
39
|
setState: active.setState?.bind(active)
|
|
18
40
|
};
|
|
19
41
|
}
|
|
20
42
|
//#endregion
|
|
21
|
-
export { readActiveCanvas };
|
|
43
|
+
export { connectedWorkspaceEditors, findOpenCanvas, readActiveCanvas };
|
|
22
44
|
|
|
23
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';\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 getState?: (key: string) => unknown;\n setState?: (key: string, value: unknown) => void;\n}\n\nexport function readActiveCanvas(): ActiveCanvas | null {\n const
|
|
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;;AA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
CHANGED
|
@@ -3,6 +3,7 @@ import { nothing, PropertyValues } from '@eclipse-docks/core/externals/lit';
|
|
|
3
3
|
import { DocksMonacoWidget } from '@eclipse-docks/extension-monaco-editor/widget';
|
|
4
4
|
import { CanvasHost } from './host';
|
|
5
5
|
import { CanvasViewElement } from './mount';
|
|
6
|
+
import { PreviewShot } from './preview-image';
|
|
6
7
|
export declare class DocksCanvasSurface extends DocksPart implements EditorContentProvider {
|
|
7
8
|
input?: EditorInput;
|
|
8
9
|
kind: 'workspace' | 'registered';
|
|
@@ -13,6 +14,7 @@ export declare class DocksCanvasSurface extends DocksPart implements EditorConte
|
|
|
13
14
|
protected sourceText: string;
|
|
14
15
|
protected mode: 'preview' | 'source';
|
|
15
16
|
protected previewError?: string;
|
|
17
|
+
private attachingPreview;
|
|
16
18
|
protected previewElement?: CanvasViewElement;
|
|
17
19
|
protected widget?: DocksMonacoWidget;
|
|
18
20
|
protected scrollMode: 'scroller' | 'native' | 'none';
|
|
@@ -21,6 +23,8 @@ export declare class DocksCanvasSurface extends DocksPart implements EditorConte
|
|
|
21
23
|
private contribution?;
|
|
22
24
|
private ready;
|
|
23
25
|
private reloadGeneration;
|
|
26
|
+
private reloadTail;
|
|
27
|
+
private syncToken;
|
|
24
28
|
private compiledSource;
|
|
25
29
|
protected previewStale: boolean;
|
|
26
30
|
connectedCallback(): void;
|
|
@@ -39,12 +43,21 @@ export declare class DocksCanvasSurface extends DocksPart implements EditorConte
|
|
|
39
43
|
getState(key: string): unknown;
|
|
40
44
|
setState(key: string, value: unknown): void;
|
|
41
45
|
setSource(source: string): void;
|
|
46
|
+
syncFromFile(): Promise<boolean>;
|
|
47
|
+
capturePreview(): Promise<PreviewShot>;
|
|
42
48
|
reload(): Promise<string>;
|
|
49
|
+
private reloadLatest;
|
|
50
|
+
private mountSource;
|
|
43
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;
|
|
44
56
|
private onDirty;
|
|
45
57
|
protected updated(changed: PropertyValues): void;
|
|
46
58
|
private onContentChange;
|
|
47
59
|
private toggleMode;
|
|
60
|
+
private attachPreview;
|
|
48
61
|
protected renderToolbar(): typeof nothing | import('lit-html').TemplateResult<1>;
|
|
49
62
|
protected renderContent(): import('lit-html').TemplateResult<1>;
|
|
50
63
|
static styles: import('lit').CSSResult;
|
|
@@ -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,SA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M,CAAC;YAMX,YAAY;YAaZ,WAAW;IAkDzB,OAAO,CAAC,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,19 +1,14 @@
|
|
|
1
|
+
import { attachPreviewShot, rasterizeElement } from "./preview-image.js";
|
|
2
|
+
import { readWorkspaceFile } from "./workspace-file.js";
|
|
1
3
|
import { compileCanvas } from "./compile.js";
|
|
2
4
|
import { createContributionHost, createFileHost } from "./host.js";
|
|
3
5
|
import { elementFromConstructor, mountCompiled } from "./mount.js";
|
|
4
6
|
import { canvasBridges } from "./bridges/urls.js";
|
|
5
|
-
import { readWorkspaceFile } from "./workspace-file.js";
|
|
6
7
|
import __decorate from "./_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
7
|
-
import { DocksPart, File, icon } from "@eclipse-docks/core";
|
|
8
|
+
import { DocksPart, File, TOPIC_WORKSPACE_CHANGED, icon } from "@eclipse-docks/core";
|
|
8
9
|
import { css, customElement, html, nothing, property, query, state } from "@eclipse-docks/core/externals/lit";
|
|
9
|
-
import { Directive, directive } from "lit/directive.js";
|
|
10
10
|
import "@eclipse-docks/extension-monaco-editor/widget";
|
|
11
11
|
//#region src/canvas-editor.ts
|
|
12
|
-
var heldNode = directive(class extends Directive {
|
|
13
|
-
render(node) {
|
|
14
|
-
return node ?? nothing;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
12
|
var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
18
13
|
constructor(..._args) {
|
|
19
14
|
super(..._args);
|
|
@@ -23,6 +18,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
23
18
|
this.showSource = false;
|
|
24
19
|
this.sourceText = "";
|
|
25
20
|
this.mode = "preview";
|
|
21
|
+
this.attachingPreview = false;
|
|
26
22
|
this.scrollMode = "none";
|
|
27
23
|
this.host = {
|
|
28
24
|
getState: (_key, fallback) => fallback,
|
|
@@ -31,8 +27,13 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
31
27
|
};
|
|
32
28
|
this.ready = false;
|
|
33
29
|
this.reloadGeneration = 0;
|
|
30
|
+
this.reloadTail = Promise.resolve();
|
|
31
|
+
this.syncToken = 0;
|
|
34
32
|
this.compiledSource = "";
|
|
35
33
|
this.previewStale = false;
|
|
34
|
+
this.onWorkspaceChanged = () => {
|
|
35
|
+
this.refreshFromFile();
|
|
36
|
+
};
|
|
36
37
|
this.onDirty = (event) => {
|
|
37
38
|
if (!this.ready || event.detail !== true) return;
|
|
38
39
|
if ((this.getContent() ?? "") === this.compiledSource && this.previewElement) return;
|
|
@@ -45,10 +46,31 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
45
46
|
this.sourceText = next;
|
|
46
47
|
this.markDirty(true);
|
|
47
48
|
};
|
|
49
|
+
this.attachPreview = async () => {
|
|
50
|
+
if (this.attachingPreview) return;
|
|
51
|
+
this.attachingPreview = true;
|
|
52
|
+
try {
|
|
53
|
+
const result = await attachPreviewShot(this);
|
|
54
|
+
if (typeof result === "string") {
|
|
55
|
+
this.showError(result);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (result.stored === false) {
|
|
59
|
+
this.showError(String(result.note ?? "Could not attach the preview"));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.showInfo("Attached preview");
|
|
63
|
+
} catch (err) {
|
|
64
|
+
this.showError(err instanceof Error ? err.message : String(err));
|
|
65
|
+
} finally {
|
|
66
|
+
this.attachingPreview = false;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
48
69
|
}
|
|
49
70
|
connectedCallback() {
|
|
50
71
|
super.connectedCallback();
|
|
51
72
|
this.addEventListener("dirty", this.onDirty);
|
|
73
|
+
this.subscribe(TOPIC_WORKSPACE_CHANGED, this.onWorkspaceChanged);
|
|
52
74
|
}
|
|
53
75
|
disconnectedCallback() {
|
|
54
76
|
this.removeEventListener("dirty", this.onDirty);
|
|
@@ -85,6 +107,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
85
107
|
}
|
|
86
108
|
this.mode = this.input?.state?.mode === "source" ? "source" : "preview";
|
|
87
109
|
this.ready = true;
|
|
110
|
+
await this.syncFromFile();
|
|
88
111
|
this.requestUpdate();
|
|
89
112
|
if (this.mode === "preview" || !this.showSource) await this.reload();
|
|
90
113
|
}
|
|
@@ -121,19 +144,74 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
121
144
|
this.host.setState(key, value);
|
|
122
145
|
}
|
|
123
146
|
setSource(source) {
|
|
124
|
-
|
|
147
|
+
const current = this.getContent() ?? "";
|
|
125
148
|
this.sourceText = source;
|
|
126
149
|
const model = this.widget?.getModel();
|
|
127
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);
|
|
128
154
|
this.requestUpdate();
|
|
129
155
|
}
|
|
130
|
-
async
|
|
131
|
-
|
|
132
|
-
if (this.
|
|
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
|
+
}
|
|
169
|
+
async capturePreview() {
|
|
170
|
+
for (let attempt = 0; attempt < 30 && !this.ready; attempt++) await new Promise((resolve) => setTimeout(resolve, 50));
|
|
171
|
+
if (!this.ready) throw new Error("Canvas is still opening");
|
|
172
|
+
await this.reload();
|
|
173
|
+
await this.updateComplete;
|
|
174
|
+
const preview = this.renderRoot.querySelector(".canvas-preview");
|
|
175
|
+
if (!preview) throw new Error("Canvas preview is not rendered");
|
|
176
|
+
if (preview.classList.contains("canvas-hidden") || preview.getBoundingClientRect().width < 2) {
|
|
177
|
+
preview.classList.add("canvas-capture");
|
|
178
|
+
preview.style.width = `${this.clientWidth || 960}px`;
|
|
179
|
+
preview.style.height = `${this.clientHeight || 640}px`;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
await nextFrame();
|
|
183
|
+
await nextFrame();
|
|
184
|
+
const view = this.previewElement;
|
|
185
|
+
if (view?.updateComplete) await view.updateComplete;
|
|
186
|
+
return await rasterizeElement(preview);
|
|
187
|
+
} finally {
|
|
188
|
+
preview.classList.remove("canvas-capture");
|
|
189
|
+
preview.style.width = "";
|
|
190
|
+
preview.style.height = "";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
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) {
|
|
133
211
|
const generation = ++this.reloadGeneration;
|
|
134
212
|
if (this.kind === "registered" && this.contribution) try {
|
|
135
213
|
const mod = await this.contribution.load();
|
|
136
|
-
if (generation !== this.reloadGeneration) return "
|
|
214
|
+
if (generation !== this.reloadGeneration) return "";
|
|
137
215
|
const Ctor = mod.default;
|
|
138
216
|
if (typeof Ctor !== "function" || !(Ctor.prototype instanceof HTMLElement)) {
|
|
139
217
|
this.previewError = "Canvas default export must be an HTMLElement subclass";
|
|
@@ -142,10 +220,10 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
142
220
|
}
|
|
143
221
|
const element = elementFromConstructor(Ctor);
|
|
144
222
|
element.canvasHost = this.host;
|
|
145
|
-
this.replacePreview(element);
|
|
223
|
+
this.replacePreview(element, source);
|
|
146
224
|
return "ready";
|
|
147
225
|
} catch (err) {
|
|
148
|
-
if (generation !== this.reloadGeneration) return "
|
|
226
|
+
if (generation !== this.reloadGeneration) return "";
|
|
149
227
|
this.previewError = err instanceof Error ? err.message : String(err);
|
|
150
228
|
this.requestUpdate();
|
|
151
229
|
return this.previewError;
|
|
@@ -156,7 +234,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
156
234
|
read: readWorkspaceFile,
|
|
157
235
|
bridges: canvasBridges()
|
|
158
236
|
});
|
|
159
|
-
if (generation !== this.reloadGeneration) return "
|
|
237
|
+
if (generation !== this.reloadGeneration) return "";
|
|
160
238
|
if (!compiled.ok) {
|
|
161
239
|
this.previewError = compiled.error;
|
|
162
240
|
this.requestUpdate();
|
|
@@ -165,7 +243,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
165
243
|
const mounted = await mountCompiled(compiled.code);
|
|
166
244
|
if (generation !== this.reloadGeneration) {
|
|
167
245
|
if (mounted.ok) mounted.dispose();
|
|
168
|
-
return "
|
|
246
|
+
return "";
|
|
169
247
|
}
|
|
170
248
|
if (!mounted.ok) {
|
|
171
249
|
this.previewError = mounted.error;
|
|
@@ -173,23 +251,35 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
173
251
|
return mounted.error;
|
|
174
252
|
}
|
|
175
253
|
mounted.element.canvasHost = this.host;
|
|
176
|
-
this.
|
|
177
|
-
this.previewStale = false;
|
|
178
|
-
this.replacePreview(mounted.element, mounted.dispose);
|
|
254
|
+
this.replacePreview(mounted.element, source, mounted.dispose);
|
|
179
255
|
return "ready";
|
|
180
256
|
}
|
|
181
|
-
replacePreview(element, dispose) {
|
|
257
|
+
replacePreview(element, source, dispose) {
|
|
182
258
|
const previous = this.previewDispose;
|
|
183
259
|
this.previewDispose = dispose ?? (() => element.remove());
|
|
184
260
|
this.previewElement = element;
|
|
185
261
|
this.previewError = void 0;
|
|
186
|
-
this.compiledSource =
|
|
187
|
-
this.previewStale =
|
|
262
|
+
this.compiledSource = source;
|
|
263
|
+
this.previewStale = (this.getContent() ?? "") !== source;
|
|
264
|
+
this.placePreview();
|
|
188
265
|
this.requestUpdate();
|
|
189
266
|
previous?.();
|
|
190
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
|
+
}
|
|
191
280
|
updated(changed) {
|
|
192
281
|
super.updated(changed);
|
|
282
|
+
this.placePreview();
|
|
193
283
|
if (this.mode === "source") this.widget?.layout();
|
|
194
284
|
}
|
|
195
285
|
toggleMode() {
|
|
@@ -200,13 +290,25 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
200
290
|
if (next === "preview" && (this.previewStale || !this.previewElement)) this.reload();
|
|
201
291
|
}
|
|
202
292
|
renderToolbar() {
|
|
203
|
-
if (!this.ready
|
|
293
|
+
if (!this.ready) return nothing;
|
|
204
294
|
const toSource = this.mode === "preview";
|
|
205
295
|
const label = toSource ? "Source" : "Preview";
|
|
206
296
|
return html`
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
297
|
+
${this.showSource ? html`
|
|
298
|
+
<wa-button appearance="plain" size="s" title=${label} @click=${() => this.toggleMode()}>
|
|
299
|
+
${icon(toSource ? "code" : "eye", { slot: "start" })}
|
|
300
|
+
${label}
|
|
301
|
+
</wa-button>
|
|
302
|
+
` : nothing}
|
|
303
|
+
<wa-button
|
|
304
|
+
appearance="plain"
|
|
305
|
+
size="s"
|
|
306
|
+
title="Attach a screenshot of the preview"
|
|
307
|
+
?loading=${this.attachingPreview}
|
|
308
|
+
?disabled=${this.attachingPreview}
|
|
309
|
+
@click=${() => this.attachPreview()}>
|
|
310
|
+
${icon("camera", { slot: "start" })}
|
|
311
|
+
Screenshot
|
|
210
312
|
</wa-button>
|
|
211
313
|
`;
|
|
212
314
|
}
|
|
@@ -217,7 +319,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
217
319
|
<div class="canvas-preview ${showPreview ? "" : "canvas-hidden"}">
|
|
218
320
|
${this.previewError ? html`<pre class="canvas-error">${this.previewError}</pre>` : nothing}
|
|
219
321
|
<wa-scroller class="canvas-scroll" orientation="vertical">
|
|
220
|
-
<div class="canvas-mount"
|
|
322
|
+
<div class="canvas-mount"></div>
|
|
221
323
|
</wa-scroller>
|
|
222
324
|
</div>
|
|
223
325
|
${this.showSource ? html`
|
|
@@ -236,6 +338,15 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
236
338
|
:host { display: flex; flex-direction: column; height: 100%; min-height: 0; }
|
|
237
339
|
.canvas-preview { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }
|
|
238
340
|
.canvas-preview.canvas-hidden, docks-monaco-widget.canvas-hidden { display: none; }
|
|
341
|
+
.canvas-preview.canvas-capture {
|
|
342
|
+
display: flex !important;
|
|
343
|
+
position: fixed;
|
|
344
|
+
left: 0;
|
|
345
|
+
top: 0;
|
|
346
|
+
z-index: 2147483000;
|
|
347
|
+
overflow: hidden;
|
|
348
|
+
background: var(--wa-color-surface-default, #fff);
|
|
349
|
+
}
|
|
239
350
|
wa-scroller.canvas-scroll { flex: 1 1 0; min-height: 0; height: 100%; }
|
|
240
351
|
.canvas-mount > * { display: block; }
|
|
241
352
|
docks-monaco-widget { display: block; height: 100%; min-height: 0; }
|
|
@@ -257,6 +368,7 @@ __decorate([property({ type: Boolean })], DocksCanvasSurface.prototype, "showSou
|
|
|
257
368
|
__decorate([state()], DocksCanvasSurface.prototype, "sourceText", void 0);
|
|
258
369
|
__decorate([state()], DocksCanvasSurface.prototype, "mode", void 0);
|
|
259
370
|
__decorate([state()], DocksCanvasSurface.prototype, "previewError", void 0);
|
|
371
|
+
__decorate([state()], DocksCanvasSurface.prototype, "attachingPreview", void 0);
|
|
260
372
|
__decorate([state()], DocksCanvasSurface.prototype, "previewElement", void 0);
|
|
261
373
|
__decorate([query("docks-monaco-widget")], DocksCanvasSurface.prototype, "widget", void 0);
|
|
262
374
|
DocksCanvasSurface = __decorate([customElement("docks-canvas-surface")], DocksCanvasSurface);
|
|
@@ -265,11 +377,14 @@ var DocksCanvasEditor = class DocksCanvasEditor extends DocksCanvasSurface {
|
|
|
265
377
|
const value = this.getContent() ?? "";
|
|
266
378
|
const data = this.input?.data;
|
|
267
379
|
if (data instanceof File) await data.saveContents(value);
|
|
380
|
+
if ((this.mode === "preview" || !this.showSource) && this.previewStale) await this.reload();
|
|
268
381
|
this.markDirty(false);
|
|
269
|
-
if (this.mode === "preview" && this.previewStale) await this.reload();
|
|
270
382
|
}
|
|
271
383
|
};
|
|
272
384
|
DocksCanvasEditor = __decorate([customElement("docks-canvas-editor")], DocksCanvasEditor);
|
|
385
|
+
function nextFrame() {
|
|
386
|
+
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
387
|
+
}
|
|
273
388
|
//#endregion
|
|
274
389
|
export { DocksCanvasEditor, DocksCanvasSurface };
|
|
275
390
|
|
|
@@ -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 { 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() 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 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 protected renderToolbar() {\n if (!this.ready || !this.showSource) return nothing;\n const toSource = this.mode === 'preview';\n const label = toSource ? 'Source' : 'Preview';\n return 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 `;\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 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\ndeclare global {\n interface HTMLElementTagNameMap {\n 'docks-canvas-surface': DocksCanvasSurface;\n 'docks-canvas-editor': DocksCanvasEditor;\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,IAAM,WAAW,UAAU,cAAc,UAAU;CAC/C,OAAO,MAAa;EAChB,OAAO,QAAQ;CACnB;AACJ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AA,KAAA,CAAA;AACNA,WAAA,CAAA,MAAM,qBAAqB,CAAA,GAAA,mBAAA,WAAA,UAAA,KAAA,CAAA;AAb/B,qBAAAA,WAAA,CAAA,cAAc,sBAAsB,CAAA,GAAA,kBAAA;AAkQ9B,IAAM,oBAAN,MAAM,0BAA0B,mBAAmB;CACtD,MAAe,OAAsB;EACjC,MAAM,QAAQ,KAAK,WAAW,KAAK;EACnC,MAAM,OAAO,KAAK,OAAO;EACzB,IAAI,gBAAgB,MAAM,MAAM,KAAK,aAAa,KAAK;EACvD,KAAK,UAAU,KAAK;EACpB,IAAI,KAAK,SAAS,aAAa,KAAK,cAAc,MAAM,KAAK,OAAO;CACxE;AACJ;AATC,oBAAAA,WAAA,CAAA,cAAc,qBAAqB,CAAA,GAAA,iBAAA"}
|
|
1
|
+
{"version":3,"file":"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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AA,MAAM,CAAA,GAAA,mBAAA,WAAA,kBAAA,KAAA,CAAA;AACNA,WAAA,CAAA,MAAM,qBAAqB,CAAA,GAAA,mBAAA,WAAA,UAAA,KAAA,CAAA;AAd/B,qBAAAA,WAAA,CAAA,cAAc,sBAAsB,CAAA,GAAA,kBAAA;AAoY9B,IAAM,oBAAN,MAAM,0BAA0B,mBAAmB;CACtD,MAAe,OAAsB;EACjC,MAAM,QAAQ,KAAK,WAAW,KAAK;EACnC,MAAM,OAAO,KAAK,OAAO;EACzB,IAAI,gBAAgB,MAAM,MAAM,KAAK,aAAa,KAAK;EACvD,KAAK,KAAK,SAAS,aAAa,CAAC,KAAK,eAAe,KAAK,cAAc,MAAM,KAAK,OAAO;EAC1F,KAAK,UAAU,KAAK;CACxB;AACJ;AATC,oBAAAA,WAAA,CAAA,cAAc,qBAAqB,CAAA,GAAA,iBAAA;AAWpC,SAAS,YAA2B;CAChC,OAAO,IAAI,SAAQ,YAAW,4BAA4B,QAAQ,CAAC,CAAC;AACxE"}
|
package/dist/canvas-extension.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SYSTEM_CANVASES, isCanvasContribution } from "./contribution.js";
|
|
2
|
-
import { CANVAS_SKILL } from "./help.js";
|
|
3
2
|
import { listRegisteredCanvases } from "./canvases.js";
|
|
4
3
|
import { registerCanvasTools } from "./canvas-tools.js";
|
|
5
4
|
import { registerCanvasCommands } from "./commands.js";
|
|
6
5
|
import "./canvas-switcher.js";
|
|
7
6
|
import { File, TOOLBAR_MAIN_RIGHT, TOPIC_CONTRIBUTEIONS_CHANGED, contributionRegistry, editorRegistry, subscribe } from "@eclipse-docks/core";
|
|
8
7
|
import { html } from "@eclipse-docks/core/externals/lit";
|
|
8
|
+
import { SYSTEM_SKILLS } from "@eclipse-docks/extension-ai-system/api";
|
|
9
9
|
//#region src/canvas-extension.ts
|
|
10
10
|
editorRegistry.registerEditorInputHandler({
|
|
11
11
|
editorId: "system.canvas-editor",
|
|
@@ -31,6 +31,33 @@ contributionRegistry.registerContribution(TOOLBAR_MAIN_RIGHT, {
|
|
|
31
31
|
label: "Canvases",
|
|
32
32
|
component: () => html`<docks-canvas-switcher></docks-canvas-switcher>`
|
|
33
33
|
});
|
|
34
|
+
var canvasSkills = [
|
|
35
|
+
{
|
|
36
|
+
name: "eclipse-docks-canvas",
|
|
37
|
+
label: "Eclipse Docks canvas",
|
|
38
|
+
load: () => import("../skills/eclipse-docks-canvas/SKILL.md?raw"),
|
|
39
|
+
ranking: 100
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "eclipse-docks-lit",
|
|
43
|
+
label: "Eclipse Docks Lit",
|
|
44
|
+
load: () => import("../skills/eclipse-docks-lit/SKILL.md?raw"),
|
|
45
|
+
ranking: 90
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "eclipse-docks-webawesome",
|
|
49
|
+
label: "Eclipse Docks Web Awesome",
|
|
50
|
+
load: () => import("../skills/eclipse-docks-webawesome/SKILL.md?raw"),
|
|
51
|
+
ranking: 90
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "eclipse-docks-core",
|
|
55
|
+
label: "Eclipse Docks core",
|
|
56
|
+
load: () => import("../skills/eclipse-docks-core/SKILL.md?raw"),
|
|
57
|
+
ranking: 90
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
for (const skill of canvasSkills) contributionRegistry.registerContribution(SYSTEM_SKILLS, skill);
|
|
34
61
|
function registerListedCanvasTools() {
|
|
35
62
|
for (const canvas of listRegisteredCanvases()) registerCanvasTools(canvas);
|
|
36
63
|
}
|
|
@@ -40,9 +67,6 @@ subscribe(TOPIC_CONTRIBUTEIONS_CHANGED, (event) => {
|
|
|
40
67
|
if (event?.target !== "system.canvases") return;
|
|
41
68
|
for (const contribution of contributionRegistry.getContributions(SYSTEM_CANVASES)) if (isCanvasContribution(contribution)) registerCanvasTools(contribution);
|
|
42
69
|
});
|
|
43
|
-
import("@eclipse-docks/extension-ai-system/api").then((ai) => {
|
|
44
|
-
ai.cognitiveRuntime.addSystemPromptEnhancer((prompt) => `${prompt}\n\n${CANVAS_SKILL}`);
|
|
45
|
-
}).catch(() => void 0);
|
|
46
70
|
//#endregion
|
|
47
71
|
|
|
48
72
|
//# sourceMappingURL=canvas-extension.js.map
|