@eclipse-docks/extension-canvas 0.8.5 → 0.8.7
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 +2 -0
- package/dist/active-canvas.d.ts.map +1 -1
- package/dist/active-canvas.js +7 -3
- package/dist/active-canvas.js.map +1 -1
- package/dist/canvas-editor.d.ts +5 -18
- package/dist/canvas-editor.d.ts.map +1 -1
- package/dist/canvas-editor.js +13 -107
- package/dist/canvas-editor.js.map +1 -1
- package/dist/canvas-extension.d.ts.map +1 -1
- package/dist/canvas-extension.js +8 -0
- package/dist/canvas-extension.js.map +1 -1
- package/dist/canvas-part.d.ts +36 -0
- package/dist/canvas-part.d.ts.map +1 -0
- package/dist/canvas-part.js +153 -0
- package/dist/canvas-part.js.map +1 -0
- package/dist/canvas-readonly.d.ts +20 -0
- package/dist/canvas-readonly.d.ts.map +1 -0
- package/dist/canvas-readonly.js +49 -0
- package/dist/canvas-readonly.js.map +1 -0
- package/dist/canvases/tasks.canvas.js +6 -0
- package/dist/canvases/tasks.canvas.js.map +1 -0
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +22 -18
- package/dist/commands.js.map +1 -1
- package/dist/contribution.d.ts +5 -3
- package/dist/contribution.d.ts.map +1 -1
- package/dist/contribution.js +2 -1
- package/dist/contribution.js.map +1 -1
- package/dist/host.js +1 -1
- package/dist/host.js.map +1 -1
- package/dist/skills/eclipse-docks-canvas/SKILL.js +1 -1
- package/dist/skills/eclipse-docks-core/SKILL.js +1 -1
- package/package.json +1 -1
package/dist/active-canvas.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface ActiveCanvas {
|
|
|
14
14
|
setState?: (key: string, value: unknown) => void;
|
|
15
15
|
}
|
|
16
16
|
export declare function readActiveCanvas(): ActiveCanvas | null;
|
|
17
|
+
/** Contributed canvas opened from the dropdown. It is not an editable editor. */
|
|
18
|
+
export declare function isCanvasViewer(active?: ActiveCanvas | null): boolean;
|
|
17
19
|
/** Connected workspace canvas editors. Optional path keeps only that file. */
|
|
18
20
|
export declare function connectedWorkspaceEditors(path?: string): ActiveCanvas[];
|
|
19
21
|
/** Active canvas editor, or any open canvas part when focus has moved elsewhere. */
|
|
@@ -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,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"}
|
|
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,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,MAAM,GAAE,YAAY,GAAG,IAAyB,GAAG,OAAO,CAExF;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,10 @@ import { activeEditorSignal } from "@eclipse-docks/core";
|
|
|
3
3
|
function readActiveCanvas() {
|
|
4
4
|
return fromElement(activeEditorSignal.get());
|
|
5
5
|
}
|
|
6
|
+
/** Contributed canvas opened from the dropdown. It is not an editable editor. */
|
|
7
|
+
function isCanvasViewer(active = readActiveCanvas()) {
|
|
8
|
+
return !!active && !active.editor && active.kind === "registered";
|
|
9
|
+
}
|
|
6
10
|
/** Connected workspace canvas editors. Optional path keeps only that file. */
|
|
7
11
|
function connectedWorkspaceEditors(path) {
|
|
8
12
|
const editors = [...document.querySelectorAll("docks-canvas-editor")].filter((node) => node.isConnected).map((node) => fromElement(node)).filter((item) => !!item && item.editor && item.kind === "workspace");
|
|
@@ -14,7 +18,7 @@ function connectedWorkspaceEditors(path) {
|
|
|
14
18
|
function findOpenCanvas() {
|
|
15
19
|
const active = readActiveCanvas();
|
|
16
20
|
if (active?.capturePreview) return active;
|
|
17
|
-
for (const node of document.querySelectorAll("docks-canvas-editor, docks-canvas-surface")) {
|
|
21
|
+
for (const node of document.querySelectorAll("docks-canvas-editor, docks-canvas-surface, docks-canvas-readonly")) {
|
|
18
22
|
const mapped = fromElement(node);
|
|
19
23
|
if (mapped?.capturePreview) return mapped;
|
|
20
24
|
}
|
|
@@ -23,7 +27,7 @@ function findOpenCanvas() {
|
|
|
23
27
|
function fromElement(active) {
|
|
24
28
|
if (!active) return null;
|
|
25
29
|
const localName = active.localName;
|
|
26
|
-
if (localName !== "docks-canvas-editor" && localName !== "docks-canvas-surface") return null;
|
|
30
|
+
if (localName !== "docks-canvas-editor" && localName !== "docks-canvas-surface" && localName !== "docks-canvas-readonly") return null;
|
|
27
31
|
return {
|
|
28
32
|
kind: active.kind === "registered" ? "registered" : "workspace",
|
|
29
33
|
canvasName: active.canvasName,
|
|
@@ -40,6 +44,6 @@ function fromElement(active) {
|
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
46
|
//#endregion
|
|
43
|
-
export { connectedWorkspaceEditors, findOpenCanvas, readActiveCanvas };
|
|
47
|
+
export { connectedWorkspaceEditors, findOpenCanvas, isCanvasViewer, readActiveCanvas };
|
|
44
48
|
|
|
45
49
|
//# 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 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,
|
|
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/** Contributed canvas opened from the dropdown. It is not an editable editor. */\nexport function isCanvasViewer(active: ActiveCanvas | null = readActiveCanvas()): boolean {\n return !!active && !active.editor && active.kind === 'registered';\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, docks-canvas-readonly')) {\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' && localName !== 'docks-canvas-readonly') 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.captureP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M;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
|
@@ -1,28 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EditorContentProvider } from '@eclipse-docks/core';
|
|
2
2
|
import { nothing, PropertyValues } from '@eclipse-docks/core/externals/lit';
|
|
3
3
|
import { DocksMonacoWidget } from '@eclipse-docks/extension-monaco-editor/widget';
|
|
4
|
-
import {
|
|
5
|
-
import { CanvasViewElement } from './mount';
|
|
4
|
+
import { DocksCanvasPart } from './canvas-part';
|
|
6
5
|
import { PreviewShot } from './preview-image';
|
|
7
|
-
export declare class DocksCanvasSurface extends
|
|
8
|
-
input?: EditorInput;
|
|
6
|
+
export declare class DocksCanvasSurface extends DocksCanvasPart implements EditorContentProvider {
|
|
9
7
|
kind: 'workspace' | 'registered';
|
|
10
|
-
canvasName?: string;
|
|
11
8
|
entryPath: string;
|
|
12
|
-
source: string;
|
|
13
9
|
showSource: boolean;
|
|
14
10
|
protected sourceText: string;
|
|
15
11
|
protected mode: 'preview' | 'source';
|
|
16
|
-
protected previewError?: string;
|
|
17
12
|
private attachingPreview;
|
|
18
|
-
protected previewElement?: CanvasViewElement;
|
|
19
13
|
protected widget?: DocksMonacoWidget;
|
|
20
|
-
protected scrollMode: 'scroller' | 'native' | 'none';
|
|
21
|
-
protected host: CanvasHost;
|
|
22
|
-
private previewDispose?;
|
|
23
14
|
private contribution?;
|
|
24
|
-
private ready;
|
|
25
|
-
private reloadGeneration;
|
|
26
15
|
private reloadTail;
|
|
27
16
|
private syncToken;
|
|
28
17
|
private compiledSource;
|
|
@@ -48,9 +37,7 @@ export declare class DocksCanvasSurface extends DocksPart implements EditorConte
|
|
|
48
37
|
reload(): Promise<string>;
|
|
49
38
|
private reloadLatest;
|
|
50
39
|
private mountSource;
|
|
51
|
-
|
|
52
|
-
/** The mount has no Lit child part, so replacing its children leaves part markers intact. */
|
|
53
|
-
private placePreview;
|
|
40
|
+
protected adoptPreview(source: string): void;
|
|
54
41
|
private onWorkspaceChanged;
|
|
55
42
|
private refreshFromFile;
|
|
56
43
|
private onDirty;
|
|
@@ -60,7 +47,7 @@ export declare class DocksCanvasSurface extends DocksPart implements EditorConte
|
|
|
60
47
|
private attachPreview;
|
|
61
48
|
protected renderToolbar(): typeof nothing | import('lit-html').TemplateResult<1>;
|
|
62
49
|
protected renderContent(): import('lit-html').TemplateResult<1>;
|
|
63
|
-
static styles: import('lit').CSSResult;
|
|
50
|
+
static styles: import('lit').CSSResult[];
|
|
64
51
|
}
|
|
65
52
|
export declare class DocksCanvasEditor extends DocksCanvasSurface {
|
|
66
53
|
save(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-editor.d.ts","sourceRoot":"","sources":["../src/canvas-editor.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"canvas-editor.d.ts","sourceRoot":"","sources":["../src/canvas-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,qBAAqB,EAC7B,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;AAEvF,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGtE,qBACa,kBAAmB,SAAQ,eAAgB,YAAW,qBAAqB;IACxE,IAAI,EAAE,WAAW,GAAG,YAAY,CAA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OAAO,EAAE,cAAc;IAKlD,OAAO,CAAC,eAAe,CAKrB;IAEF,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,aAAa,CAmBnB;IAEF,SAAS,CAAC,aAAa;cAwBJ,aAAa;IAiBhC,MAAM,CAAC,MAAM,4BAYV;CACN;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,32 +1,21 @@
|
|
|
1
|
-
import { attachPreviewShot
|
|
1
|
+
import { attachPreviewShot } from "./preview-image.js";
|
|
2
2
|
import { readWorkspaceFile } from "./workspace-file.js";
|
|
3
|
-
import {
|
|
3
|
+
import { DocksCanvasPart } from "./canvas-part.js";
|
|
4
4
|
import { createContributionHost, createFileHost } from "./host.js";
|
|
5
|
-
import {
|
|
6
|
-
import { canvasBridges } from "./bridges/urls.js";
|
|
7
|
-
import { DocksPart, File, TOPIC_WORKSPACE_CHANGED, icon } from "@eclipse-docks/core";
|
|
5
|
+
import { File, TOPIC_WORKSPACE_CHANGED, icon } from "@eclipse-docks/core";
|
|
8
6
|
import { css, customElement, html, nothing, property, query, state } from "@eclipse-docks/core/externals/lit";
|
|
9
7
|
import "@eclipse-docks/extension-monaco-editor/widget";
|
|
10
8
|
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
11
9
|
//#region src/canvas-editor.ts
|
|
12
|
-
var DocksCanvasSurface = class DocksCanvasSurface extends
|
|
10
|
+
var DocksCanvasSurface = class DocksCanvasSurface extends DocksCanvasPart {
|
|
13
11
|
constructor(..._args) {
|
|
14
12
|
super(..._args);
|
|
15
13
|
this.kind = "workspace";
|
|
16
14
|
this.entryPath = "";
|
|
17
|
-
this.source = "";
|
|
18
15
|
this.showSource = false;
|
|
19
16
|
this.sourceText = "";
|
|
20
17
|
this.mode = "preview";
|
|
21
18
|
this.attachingPreview = false;
|
|
22
|
-
this.scrollMode = "none";
|
|
23
|
-
this.host = {
|
|
24
|
-
getState: (_key, fallback) => fallback,
|
|
25
|
-
setState: () => void 0,
|
|
26
|
-
openFile: () => void 0
|
|
27
|
-
};
|
|
28
|
-
this.ready = false;
|
|
29
|
-
this.reloadGeneration = 0;
|
|
30
19
|
this.reloadTail = Promise.resolve();
|
|
31
20
|
this.syncToken = 0;
|
|
32
21
|
this.compiledSource = "";
|
|
@@ -112,9 +101,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
112
101
|
if (this.mode === "preview" || !this.showSource) await this.reload();
|
|
113
102
|
}
|
|
114
103
|
doClose() {
|
|
115
|
-
|
|
116
|
-
this.previewDispose?.();
|
|
117
|
-
this.previewDispose = void 0;
|
|
104
|
+
super.doClose();
|
|
118
105
|
this.widget?.dispose();
|
|
119
106
|
}
|
|
120
107
|
getContent() {
|
|
@@ -181,9 +168,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
181
168
|
try {
|
|
182
169
|
await nextFrame();
|
|
183
170
|
await nextFrame();
|
|
184
|
-
|
|
185
|
-
if (view?.updateComplete) await view.updateComplete;
|
|
186
|
-
return await rasterizeElement(preview);
|
|
171
|
+
return await this.rasterizePreview();
|
|
187
172
|
} finally {
|
|
188
173
|
preview.classList.remove("canvas-capture");
|
|
189
174
|
preview.style.width = "";
|
|
@@ -207,71 +192,13 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
207
192
|
}
|
|
208
193
|
return result;
|
|
209
194
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const mod = await this.contribution.load();
|
|
214
|
-
if (generation !== this.reloadGeneration) return "";
|
|
215
|
-
const Ctor = mod.default;
|
|
216
|
-
if (typeof Ctor !== "function" || !(Ctor.prototype instanceof HTMLElement)) {
|
|
217
|
-
this.previewError = "Canvas default export must be an HTMLElement subclass";
|
|
218
|
-
this.requestUpdate();
|
|
219
|
-
return this.previewError;
|
|
220
|
-
}
|
|
221
|
-
const element = elementFromConstructor(Ctor);
|
|
222
|
-
element.canvasHost = this.host;
|
|
223
|
-
this.replacePreview(element, source);
|
|
224
|
-
return "ready";
|
|
225
|
-
} catch (err) {
|
|
226
|
-
if (generation !== this.reloadGeneration) return "";
|
|
227
|
-
this.previewError = err instanceof Error ? err.message : String(err);
|
|
228
|
-
this.requestUpdate();
|
|
229
|
-
return this.previewError;
|
|
230
|
-
}
|
|
231
|
-
const compiled = await compileCanvas({
|
|
232
|
-
entryPath: this.entryPath || "canvas.js",
|
|
233
|
-
entrySource: source,
|
|
234
|
-
read: readWorkspaceFile,
|
|
235
|
-
bridges: canvasBridges()
|
|
236
|
-
});
|
|
237
|
-
if (generation !== this.reloadGeneration) return "";
|
|
238
|
-
if (!compiled.ok) {
|
|
239
|
-
this.previewError = compiled.error;
|
|
240
|
-
this.requestUpdate();
|
|
241
|
-
return compiled.error;
|
|
242
|
-
}
|
|
243
|
-
const mounted = await mountCompiled(compiled.code);
|
|
244
|
-
if (generation !== this.reloadGeneration) {
|
|
245
|
-
if (mounted.ok) mounted.dispose();
|
|
246
|
-
return "";
|
|
247
|
-
}
|
|
248
|
-
if (!mounted.ok) {
|
|
249
|
-
this.previewError = mounted.error;
|
|
250
|
-
this.requestUpdate();
|
|
251
|
-
return mounted.error;
|
|
252
|
-
}
|
|
253
|
-
mounted.element.canvasHost = this.host;
|
|
254
|
-
this.replacePreview(mounted.element, source, mounted.dispose);
|
|
255
|
-
return "ready";
|
|
195
|
+
mountSource(source) {
|
|
196
|
+
if (this.kind === "registered" && this.contribution?.load) return this.mountLoadedConstructor(this.contribution.load, source);
|
|
197
|
+
return this.mountCompiledSource(source, this.entryPath || `${this.canvasName || "canvas"}.canvas.js`);
|
|
256
198
|
}
|
|
257
|
-
|
|
258
|
-
const previous = this.previewDispose;
|
|
259
|
-
this.previewDispose = dispose ?? (() => element.remove());
|
|
260
|
-
this.previewElement = element;
|
|
261
|
-
this.previewError = void 0;
|
|
199
|
+
adoptPreview(source) {
|
|
262
200
|
this.compiledSource = source;
|
|
263
201
|
this.previewStale = (this.getContent() ?? "") !== source;
|
|
264
|
-
this.placePreview();
|
|
265
|
-
this.requestUpdate();
|
|
266
|
-
previous?.();
|
|
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
202
|
}
|
|
276
203
|
async refreshFromFile() {
|
|
277
204
|
if (!await this.syncFromFile()) return;
|
|
@@ -279,7 +206,6 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
279
206
|
}
|
|
280
207
|
updated(changed) {
|
|
281
208
|
super.updated(changed);
|
|
282
|
-
this.placePreview();
|
|
283
209
|
if (this.mode === "source") this.widget?.layout();
|
|
284
210
|
}
|
|
285
211
|
toggleMode() {
|
|
@@ -316,12 +242,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
316
242
|
if (!this.ready) return html``;
|
|
317
243
|
const showPreview = !this.showSource || this.mode === "preview";
|
|
318
244
|
return html`
|
|
319
|
-
|
|
320
|
-
${this.previewError ? html`<pre class="canvas-error">${this.previewError}</pre>` : nothing}
|
|
321
|
-
<wa-scroller class="canvas-scroll" orientation="vertical">
|
|
322
|
-
<div class="canvas-mount"></div>
|
|
323
|
-
</wa-scroller>
|
|
324
|
-
</div>
|
|
245
|
+
${this.renderPreview(!showPreview)}
|
|
325
246
|
${this.showSource ? html`
|
|
326
247
|
<docks-monaco-widget
|
|
327
248
|
class=${this.mode === "source" ? "" : "canvas-hidden"}
|
|
@@ -334,9 +255,7 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
334
255
|
`;
|
|
335
256
|
}
|
|
336
257
|
static {
|
|
337
|
-
this.styles = css`
|
|
338
|
-
:host { display: flex; flex-direction: column; height: 100%; min-height: 0; }
|
|
339
|
-
.canvas-preview { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }
|
|
258
|
+
this.styles = [DocksCanvasPart.styles, css`
|
|
340
259
|
.canvas-preview.canvas-hidden, docks-monaco-widget.canvas-hidden { display: none; }
|
|
341
260
|
.canvas-preview.canvas-capture {
|
|
342
261
|
display: flex !important;
|
|
@@ -347,29 +266,16 @@ var DocksCanvasSurface = class DocksCanvasSurface extends DocksPart {
|
|
|
347
266
|
overflow: hidden;
|
|
348
267
|
background: var(--wa-color-surface-default, #fff);
|
|
349
268
|
}
|
|
350
|
-
wa-scroller.canvas-scroll { flex: 1 1 0; min-height: 0; height: 100%; }
|
|
351
|
-
.canvas-mount > * { display: block; }
|
|
352
269
|
docks-monaco-widget { display: block; height: 100%; min-height: 0; }
|
|
353
|
-
|
|
354
|
-
margin: 0;
|
|
355
|
-
padding: var(--wa-space-s, 8px);
|
|
356
|
-
white-space: pre-wrap;
|
|
357
|
-
color: var(--wa-color-danger-on-quiet, #b42318);
|
|
358
|
-
}
|
|
359
|
-
`;
|
|
270
|
+
`];
|
|
360
271
|
}
|
|
361
272
|
};
|
|
362
|
-
_decorate([property({ attribute: false })], DocksCanvasSurface.prototype, "input", void 0);
|
|
363
273
|
_decorate([property()], DocksCanvasSurface.prototype, "kind", void 0);
|
|
364
|
-
_decorate([property()], DocksCanvasSurface.prototype, "canvasName", void 0);
|
|
365
274
|
_decorate([property()], DocksCanvasSurface.prototype, "entryPath", void 0);
|
|
366
|
-
_decorate([property()], DocksCanvasSurface.prototype, "source", void 0);
|
|
367
275
|
_decorate([property({ type: Boolean })], DocksCanvasSurface.prototype, "showSource", void 0);
|
|
368
276
|
_decorate([state()], DocksCanvasSurface.prototype, "sourceText", void 0);
|
|
369
277
|
_decorate([state()], DocksCanvasSurface.prototype, "mode", void 0);
|
|
370
|
-
_decorate([state()], DocksCanvasSurface.prototype, "previewError", void 0);
|
|
371
278
|
_decorate([state()], DocksCanvasSurface.prototype, "attachingPreview", void 0);
|
|
372
|
-
_decorate([state()], DocksCanvasSurface.prototype, "previewElement", void 0);
|
|
373
279
|
_decorate([query("docks-monaco-widget")], DocksCanvasSurface.prototype, "widget", void 0);
|
|
374
280
|
DocksCanvasSurface = _decorate([customElement("docks-canvas-surface")], DocksCanvasSurface);
|
|
375
281
|
var DocksCanvasEditor = class DocksCanvasEditor extends DocksCanvasSurface {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-editor.js","names":[],"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,WA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BAAA,WAAA,kBAAA,KAAA,CAAA;AACN,UAAA,CAAA,MAAM,qBAAqB,CAAA,GAAA,mBAAA,WAAA,UAAA,KAAA,CAAA;AAd/B,qBAAA,UAAA,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,oBAAA,UAAA,CAAA,cAAc,qBAAqB,CAAA,GAAA,iBAAA;AAWpC,SAAS,YAA2B;CAChC,OAAO,IAAI,SAAQ,YAAW,4BAA4B,QAAQ,CAAC,CAAC;AACxE"}
|
|
1
|
+
{"version":3,"file":"canvas-editor.js","names":[],"sources":["../src/canvas-editor.ts"],"sourcesContent":["import {\n File,\n icon,\n TOPIC_WORKSPACE_CHANGED,\n type EditorContentProvider,\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 { DocksCanvasPart } from './canvas-part';\nimport { createContributionHost, createFileHost } from './host';\nimport { attachPreviewShot, type PreviewShot } from './preview-image';\nimport { readWorkspaceFile } from './workspace-file';\n\n@customElement('docks-canvas-surface')\nexport class DocksCanvasSurface extends DocksCanvasPart implements EditorContentProvider {\n @property() kind: 'workspace' | 'registered' = 'workspace';\n @property() entryPath = '';\n @property({ type: Boolean }) showSource = false;\n\n @state() protected sourceText = '';\n @state() protected mode: 'preview' | 'source' = 'preview';\n @state() private attachingPreview = false;\n @query('docks-monaco-widget') protected widget?: DocksMonacoWidget;\n\n private contribution?: CanvasContribution;\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 override doClose() {\n super.doClose();\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 override 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 return await this.rasterizePreview();\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 mountSource(source: string): Promise<string> {\n if (this.kind === 'registered' && this.contribution?.load) {\n return this.mountLoadedConstructor(this.contribution.load, source);\n }\n return this.mountCompiledSource(source, this.entryPath || `${this.canvasName || 'canvas'}.canvas.js`);\n }\n\n protected override adoptPreview(source: string): void {\n this.compiledSource = source;\n this.previewStale = (this.getContent() ?? '') !== source;\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 override 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 override renderContent() {\n if (!this.ready) return html``;\n const showPreview = !this.showSource || this.mode === 'preview';\n return html`\n ${this.renderPreview(!showPreview)}\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 = [DocksCanvasPart.styles, css`\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 docks-monaco-widget { display: block; height: 100%; min-height: 0; }\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":";;;;;;;;;AAiBO,IAAM,qBAAN,MAAM,2BAA2B,gBAAiD;;;EACtC,KAAA,OAAA;EACvB,KAAA,YAAA;EACkB,KAAA,aAAA;EAEV,KAAA,aAAA;EACgB,KAAA,OAAA;EACZ,KAAA,mBAAA;EAIA,KAAA,aAAA,QAAQ,QAAQ;EAChC,KAAA,YAAA;EACK,KAAA,iBAAA;EACA,KAAA,eAAA;EAwKU,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;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,IAAI;IAC3C,IAAI,OAAO,WAAW,UAAU;KAC5B,KAAK,UAAU,MAAM;KACrB;IACJ;IACA,IAAI,OAAO,WAAW,OAAO;KACzB,KAAK,UAAU,OAAO,OAAO,QAAQ,8BAA8B,CAAC;KACpE;IACJ;IACA,KAAK,SAAS,kBAAkB;GACpC,SA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AAA,mBAAA,WAAA,oBAAA,KAAA,CAAA;AACN,UAAA,CAAA,MAAM,qBAAqB,CAAA,GAAA,mBAAA,WAAA,UAAA,KAAA,CAAA;AAT/B,qBAAA,UAAA,CAAA,cAAc,sBAAsB,CAAA,GAAA,kBAAA;AA2S9B,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,oBAAA,UAAA,CAAA,cAAc,qBAAqB,CAAA,GAAA,iBAAA;AAWpC,SAAS,YAA2B;CAChC,OAAO,IAAI,SAAQ,YAAW,4BAA4B,QAAQ,CAAC,CAAC;AACxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-extension.d.ts","sourceRoot":"","sources":["../src/canvas-extension.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"canvas-extension.d.ts","sourceRoot":"","sources":["../src/canvas-extension.ts"],"names":[],"mappings":"AAiBA,OAAO,mBAAmB,CAAC"}
|
package/dist/canvas-extension.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SYSTEM_CANVASES, isCanvasContribution } from "./contribution.js";
|
|
2
2
|
import { listRegisteredCanvases } from "./canvases.js";
|
|
3
|
+
import tasks_canvas_default from "./canvases/tasks.canvas.js";
|
|
3
4
|
import { registerCanvasTools } from "./canvas-tools.js";
|
|
4
5
|
import { registerCanvasCommands } from "./commands.js";
|
|
5
6
|
import "./canvas-switcher.js";
|
|
@@ -61,6 +62,13 @@ for (const skill of canvasSkills) contributionRegistry.registerContribution(SYST
|
|
|
61
62
|
function registerListedCanvasTools() {
|
|
62
63
|
for (const canvas of listRegisteredCanvases()) registerCanvasTools(canvas);
|
|
63
64
|
}
|
|
65
|
+
contributionRegistry.registerContribution(SYSTEM_CANVASES, {
|
|
66
|
+
name: "tasks",
|
|
67
|
+
label: "Tasks",
|
|
68
|
+
icon: "list-check",
|
|
69
|
+
settingsKey: "canvas.docks.demos.tasks",
|
|
70
|
+
source: tasks_canvas_default
|
|
71
|
+
});
|
|
64
72
|
registerCanvasCommands();
|
|
65
73
|
registerListedCanvasTools();
|
|
66
74
|
subscribe(TOPIC_CONTRIBUTEIONS_CHANGED, (event) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-extension.js","names":[],"sources":["../src/canvas-extension.ts"],"sourcesContent":["import {\n contributionRegistry,\n editorRegistry,\n File,\n subscribe,\n TOOLBAR_MAIN_RIGHT,\n TOPIC_CONTRIBUTEIONS_CHANGED,\n type EditorInput,\n type HTMLContribution,\n} from '@eclipse-docks/core';\nimport { html } from '@eclipse-docks/core/externals/lit';\nimport { SYSTEM_SKILLS, type SkillContribution } from '@eclipse-docks/extension-ai-system/api';\nimport { isCanvasContribution, SYSTEM_CANVASES } from './contribution';\nimport { listRegisteredCanvases } from './canvases';\nimport { registerCanvasTools } from './canvas-tools';\nimport { registerCanvasCommands } from './commands';\nimport './canvas-switcher';\n\neditorRegistry.registerEditorInputHandler({\n editorId: 'system.canvas-editor',\n label: 'Canvas',\n icon: 'table-columns',\n ranking: 1100,\n canHandle: (input: unknown) => input instanceof File && input.getName().toLowerCase().endsWith('.canvas.js'),\n handle: async (input: File) => {\n const editorInput = {\n title: input.getName(),\n data: input,\n key: input.getWorkspacePath(),\n icon: 'table-columns',\n state: { mode: 'preview' },\n component: () => html``,\n } as EditorInput;\n editorInput.component = (id: string) => html`<docks-canvas-editor id=\"${id}\" .input=${editorInput}></docks-canvas-editor>`;\n return editorInput;\n },\n});\n\ncontributionRegistry.registerContribution(TOOLBAR_MAIN_RIGHT, {\n name: 'canvas.switcher',\n label: 'Canvases',\n component: () => html`<docks-canvas-switcher></docks-canvas-switcher>`,\n} as HTMLContribution);\n\nconst canvasSkills = [\n {\n name: 'eclipse-docks-canvas',\n label: 'Eclipse Docks canvas',\n load: () => import('./skills/eclipse-docks-canvas/SKILL.md?raw'),\n ranking: 100,\n },\n {\n name: 'eclipse-docks-lit',\n label: 'Eclipse Docks Lit',\n load: () => import('./skills/eclipse-docks-lit/SKILL.md?raw'),\n ranking: 90,\n },\n {\n name: 'eclipse-docks-webawesome',\n label: 'Eclipse Docks Web Awesome',\n load: () => import('./skills/eclipse-docks-webawesome/SKILL.md?raw'),\n ranking: 90,\n },\n {\n name: 'eclipse-docks-core',\n label: 'Eclipse Docks core',\n load: () => import('./skills/eclipse-docks-core/SKILL.md?raw'),\n ranking: 90,\n },\n] as const satisfies ReadonlyArray<SkillContribution>;\n\nfor (const skill of canvasSkills) {\n contributionRegistry.registerContribution(SYSTEM_SKILLS, skill);\n}\n\nfunction registerListedCanvasTools(): void {\n for (const canvas of listRegisteredCanvases()) registerCanvasTools(canvas);\n}\n\nregisterCanvasCommands();\nregisterListedCanvasTools();\nsubscribe(TOPIC_CONTRIBUTEIONS_CHANGED, (event: { target?: string }) => {\n if (event?.target !== SYSTEM_CANVASES) return;\n for (const contribution of contributionRegistry.getContributions(SYSTEM_CANVASES)) {\n if (isCanvasContribution(contribution)) registerCanvasTools(contribution);\n }\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"canvas-extension.js","names":["tasksSource"],"sources":["../src/canvas-extension.ts"],"sourcesContent":["import {\n contributionRegistry,\n editorRegistry,\n File,\n subscribe,\n TOOLBAR_MAIN_RIGHT,\n TOPIC_CONTRIBUTEIONS_CHANGED,\n type EditorInput,\n type HTMLContribution,\n} from '@eclipse-docks/core';\nimport { html } from '@eclipse-docks/core/externals/lit';\nimport { SYSTEM_SKILLS, type SkillContribution } from '@eclipse-docks/extension-ai-system/api';\nimport { isCanvasContribution, SYSTEM_CANVASES } from './contribution';\nimport { listRegisteredCanvases } from './canvases';\nimport tasksSource from './canvases/tasks.canvas.js?raw';\nimport { registerCanvasTools } from './canvas-tools';\nimport { registerCanvasCommands } from './commands';\nimport './canvas-switcher';\n\neditorRegistry.registerEditorInputHandler({\n editorId: 'system.canvas-editor',\n label: 'Canvas',\n icon: 'table-columns',\n ranking: 1100,\n canHandle: (input: unknown) => input instanceof File && input.getName().toLowerCase().endsWith('.canvas.js'),\n handle: async (input: File) => {\n const editorInput = {\n title: input.getName(),\n data: input,\n key: input.getWorkspacePath(),\n icon: 'table-columns',\n state: { mode: 'preview' },\n component: () => html``,\n } as EditorInput;\n editorInput.component = (id: string) => html`<docks-canvas-editor id=\"${id}\" .input=${editorInput}></docks-canvas-editor>`;\n return editorInput;\n },\n});\n\ncontributionRegistry.registerContribution(TOOLBAR_MAIN_RIGHT, {\n name: 'canvas.switcher',\n label: 'Canvases',\n component: () => html`<docks-canvas-switcher></docks-canvas-switcher>`,\n} as HTMLContribution);\n\nconst canvasSkills = [\n {\n name: 'eclipse-docks-canvas',\n label: 'Eclipse Docks canvas',\n load: () => import('./skills/eclipse-docks-canvas/SKILL.md?raw'),\n ranking: 100,\n },\n {\n name: 'eclipse-docks-lit',\n label: 'Eclipse Docks Lit',\n load: () => import('./skills/eclipse-docks-lit/SKILL.md?raw'),\n ranking: 90,\n },\n {\n name: 'eclipse-docks-webawesome',\n label: 'Eclipse Docks Web Awesome',\n load: () => import('./skills/eclipse-docks-webawesome/SKILL.md?raw'),\n ranking: 90,\n },\n {\n name: 'eclipse-docks-core',\n label: 'Eclipse Docks core',\n load: () => import('./skills/eclipse-docks-core/SKILL.md?raw'),\n ranking: 90,\n },\n] as const satisfies ReadonlyArray<SkillContribution>;\n\nfor (const skill of canvasSkills) {\n contributionRegistry.registerContribution(SYSTEM_SKILLS, skill);\n}\n\nfunction registerListedCanvasTools(): void {\n for (const canvas of listRegisteredCanvases()) registerCanvasTools(canvas);\n}\n\ncontributionRegistry.registerContribution(SYSTEM_CANVASES, {\n name: 'tasks',\n label: 'Tasks',\n icon: 'list-check',\n settingsKey: 'canvas.docks.demos.tasks',\n source: tasksSource,\n});\n\nregisterCanvasCommands();\nregisterListedCanvasTools();\nsubscribe(TOPIC_CONTRIBUTEIONS_CHANGED, (event: { target?: string }) => {\n if (event?.target !== SYSTEM_CANVASES) return;\n for (const contribution of contributionRegistry.getContributions(SYSTEM_CANVASES)) {\n if (isCanvasContribution(contribution)) registerCanvasTools(contribution);\n }\n});\n"],"mappings":";;;;;;;;;;AAmBA,eAAe,2BAA2B;CACtC,UAAU;CACV,OAAO;CACP,MAAM;CACN,SAAS;CACT,YAAY,UAAmB,iBAAiB,QAAQ,MAAM,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,YAAY;CAC3G,QAAQ,OAAO,UAAgB;EAC3B,MAAM,cAAc;GAChB,OAAO,MAAM,QAAQ;GACrB,MAAM;GACN,KAAK,MAAM,iBAAiB;GAC5B,MAAM;GACN,OAAO,EAAE,MAAM,UAAU;GACzB,iBAAiB,IAAI;EACzB;EACA,YAAY,aAAa,OAAe,IAAI,4BAA4B,GAAG,WAAW,YAAY;EAClG,OAAO;CACX;AACJ,CAAC;AAED,qBAAqB,qBAAqB,oBAAoB;CAC1D,MAAM;CACN,OAAO;CACP,iBAAiB,IAAI;AACzB,CAAqB;AAErB,IAAM,eAAe;CACjB;EACI,MAAM;EACN,OAAO;EACP,YAAY,OAAO;EACnB,SAAS;CACb;CACA;EACI,MAAM;EACN,OAAO;EACP,YAAY,OAAO;EACnB,SAAS;CACb;CACA;EACI,MAAM;EACN,OAAO;EACP,YAAY,OAAO;EACnB,SAAS;CACb;CACA;EACI,MAAM;EACN,OAAO;EACP,YAAY,OAAO;EACnB,SAAS;CACb;AACJ;AAEA,KAAK,MAAM,SAAS,cAChB,qBAAqB,qBAAqB,eAAe,KAAK;AAGlE,SAAS,4BAAkC;CACvC,KAAK,MAAM,UAAU,uBAAuB,GAAG,oBAAoB,MAAM;AAC7E;AAEA,qBAAqB,qBAAqB,iBAAiB;CACvD,MAAM;CACN,OAAO;CACP,MAAM;CACN,aAAa;CACb,QAAQA;AACZ,CAAC;AAED,uBAAuB;AACvB,0BAA0B;AAC1B,UAAU,+BAA+B,UAA+B;CACpE,IAAI,OAAO,WAAA,mBAA4B;CACvC,KAAK,MAAM,gBAAgB,qBAAqB,iBAAiB,eAAe,GAC5E,IAAI,qBAAqB,YAAY,GAAG,oBAAoB,YAAY;AAEhF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DocksPart, EditorInput } from '@eclipse-docks/core';
|
|
2
|
+
import { PropertyValues } from '@eclipse-docks/core/externals/lit';
|
|
3
|
+
import { CanvasContribution } from './contribution';
|
|
4
|
+
import { CanvasHost } from './host';
|
|
5
|
+
import { CanvasViewElement } from './mount';
|
|
6
|
+
import { PreviewShot } from './preview-image';
|
|
7
|
+
/** Shared preview host for the canvas editor and the read-only contribution canvas. */
|
|
8
|
+
export declare abstract class DocksCanvasPart extends DocksPart {
|
|
9
|
+
input?: EditorInput;
|
|
10
|
+
canvasName?: string;
|
|
11
|
+
source: string;
|
|
12
|
+
protected previewError?: string;
|
|
13
|
+
protected previewElement?: CanvasViewElement;
|
|
14
|
+
protected scrollMode: 'scroller' | 'native' | 'none';
|
|
15
|
+
protected host: CanvasHost;
|
|
16
|
+
protected ready: boolean;
|
|
17
|
+
protected reloadGeneration: number;
|
|
18
|
+
private previewDispose?;
|
|
19
|
+
protected doClose(): void;
|
|
20
|
+
capturePreview(): Promise<PreviewShot>;
|
|
21
|
+
/** Compile workspace or contribution source and mount the exported element. */
|
|
22
|
+
protected mountCompiledSource(source: string, entryPath: string): Promise<string>;
|
|
23
|
+
/** Mount a contribution that already provides its element constructor. */
|
|
24
|
+
protected mountLoadedConstructor(load: NonNullable<CanvasContribution['load']>, source: string): Promise<string>;
|
|
25
|
+
/** Called when a preview element is installed. `source` is the text that produced it. */
|
|
26
|
+
protected adoptPreview(_source: string): void;
|
|
27
|
+
protected replacePreview(element: CanvasViewElement, source: string, dispose?: () => void): void;
|
|
28
|
+
/** The mount has no Lit child part, so replacing its children leaves part markers intact. */
|
|
29
|
+
protected placePreview(): void;
|
|
30
|
+
protected updated(changed: PropertyValues): void;
|
|
31
|
+
protected renderPreview(hidden?: boolean): import('lit-html').TemplateResult<1>;
|
|
32
|
+
protected renderContent(): import('lit-html').TemplateResult<1>;
|
|
33
|
+
protected rasterizePreview(): Promise<PreviewShot>;
|
|
34
|
+
static styles: import('lit').CSSResult;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=canvas-part.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-part.d.ts","sourceRoot":"","sources":["../src/canvas-part.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAE5F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAyC,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGrE,uFAAuF;AACvF,8BAAsB,eAAgB,SAAQ,SAAS;IACnB,KAAK,CAAC,EAAE,WAAW,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,SAAM;IAEf,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,cAAc,CAAC,EAAE,iBAAiB,CAAC;IAEtD,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAU;IAC9D,SAAS,CAAC,IAAI,EAAE,UAAU,CAAoG;IAC9H,SAAS,CAAC,KAAK,UAAS;IACxB,SAAS,CAAC,gBAAgB,SAAK;IAE/B,OAAO,CAAC,cAAc,CAAC,CAAa;IAEpC,SAAS,CAAC,OAAO;IAMX,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAI5C,+EAA+E;cAC/D,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BvF,0EAA0E;cAC1D,sBAAsB,CAAC,IAAI,EAAE,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBtH,yFAAyF;IACzF,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAE7C,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;IAWzF,6FAA6F;IAC7F,SAAS,CAAC,YAAY;IAQtB,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc;IAKzC,SAAS,CAAC,aAAa,CAAC,MAAM,UAAQ;IAWtC,SAAS,CAAC,aAAa;cAKP,gBAAgB,IAAI,OAAO,CAAC,WAAW,CAAC;IASxD,MAAM,CAAC,MAAM,0BAWX;CACL"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { rasterizeElement } from "./preview-image.js";
|
|
2
|
+
import { readWorkspaceFile } from "./workspace-file.js";
|
|
3
|
+
import { compileCanvas } from "./compile.js";
|
|
4
|
+
import { canvasBridges } from "./bridges/urls.js";
|
|
5
|
+
import { elementFromConstructor, mountCompiled } from "./mount.js";
|
|
6
|
+
import { DocksPart } from "@eclipse-docks/core";
|
|
7
|
+
import { css, html, nothing, property, state } from "@eclipse-docks/core/externals/lit";
|
|
8
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
9
|
+
//#region src/canvas-part.ts
|
|
10
|
+
/** Shared preview host for the canvas editor and the read-only contribution canvas. */
|
|
11
|
+
var DocksCanvasPart = class extends DocksPart {
|
|
12
|
+
constructor(..._args) {
|
|
13
|
+
super(..._args);
|
|
14
|
+
this.source = "";
|
|
15
|
+
this.scrollMode = "none";
|
|
16
|
+
this.host = {
|
|
17
|
+
getState: (_key, fallback) => fallback,
|
|
18
|
+
setState: () => void 0,
|
|
19
|
+
openFile: () => void 0
|
|
20
|
+
};
|
|
21
|
+
this.ready = false;
|
|
22
|
+
this.reloadGeneration = 0;
|
|
23
|
+
}
|
|
24
|
+
doClose() {
|
|
25
|
+
this.reloadGeneration++;
|
|
26
|
+
this.previewDispose?.();
|
|
27
|
+
this.previewDispose = void 0;
|
|
28
|
+
}
|
|
29
|
+
async capturePreview() {
|
|
30
|
+
return this.rasterizePreview();
|
|
31
|
+
}
|
|
32
|
+
/** Compile workspace or contribution source and mount the exported element. */
|
|
33
|
+
async mountCompiledSource(source, entryPath) {
|
|
34
|
+
const generation = ++this.reloadGeneration;
|
|
35
|
+
const compiled = await compileCanvas({
|
|
36
|
+
entryPath,
|
|
37
|
+
entrySource: source,
|
|
38
|
+
read: readWorkspaceFile,
|
|
39
|
+
bridges: canvasBridges()
|
|
40
|
+
});
|
|
41
|
+
if (generation !== this.reloadGeneration) return "";
|
|
42
|
+
if (!compiled.ok) {
|
|
43
|
+
this.previewError = compiled.error;
|
|
44
|
+
this.requestUpdate();
|
|
45
|
+
return compiled.error;
|
|
46
|
+
}
|
|
47
|
+
const mounted = await mountCompiled(compiled.code);
|
|
48
|
+
if (generation !== this.reloadGeneration) {
|
|
49
|
+
if (mounted.ok) mounted.dispose();
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
if (!mounted.ok) {
|
|
53
|
+
this.previewError = mounted.error;
|
|
54
|
+
this.requestUpdate();
|
|
55
|
+
return mounted.error;
|
|
56
|
+
}
|
|
57
|
+
mounted.element.canvasHost = this.host;
|
|
58
|
+
this.replacePreview(mounted.element, source, mounted.dispose);
|
|
59
|
+
return "ready";
|
|
60
|
+
}
|
|
61
|
+
/** Mount a contribution that already provides its element constructor. */
|
|
62
|
+
async mountLoadedConstructor(load, source) {
|
|
63
|
+
const generation = ++this.reloadGeneration;
|
|
64
|
+
try {
|
|
65
|
+
const mod = await load();
|
|
66
|
+
if (generation !== this.reloadGeneration) return "";
|
|
67
|
+
const Ctor = mod.default;
|
|
68
|
+
if (typeof Ctor !== "function" || !(Ctor.prototype instanceof HTMLElement)) {
|
|
69
|
+
this.previewError = "Canvas default export must be an HTMLElement subclass";
|
|
70
|
+
this.requestUpdate();
|
|
71
|
+
return this.previewError;
|
|
72
|
+
}
|
|
73
|
+
const element = elementFromConstructor(Ctor);
|
|
74
|
+
element.canvasHost = this.host;
|
|
75
|
+
this.replacePreview(element, source);
|
|
76
|
+
return "ready";
|
|
77
|
+
} catch (err) {
|
|
78
|
+
if (generation !== this.reloadGeneration) return "";
|
|
79
|
+
this.previewError = err instanceof Error ? err.message : String(err);
|
|
80
|
+
this.requestUpdate();
|
|
81
|
+
return this.previewError;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Called when a preview element is installed. `source` is the text that produced it. */
|
|
85
|
+
adoptPreview(_source) {}
|
|
86
|
+
replacePreview(element, source, dispose) {
|
|
87
|
+
const previous = this.previewDispose;
|
|
88
|
+
this.previewDispose = dispose ?? (() => element.remove());
|
|
89
|
+
this.previewElement = element;
|
|
90
|
+
this.previewError = void 0;
|
|
91
|
+
this.adoptPreview(source);
|
|
92
|
+
this.placePreview();
|
|
93
|
+
this.requestUpdate();
|
|
94
|
+
previous?.();
|
|
95
|
+
}
|
|
96
|
+
/** The mount has no Lit child part, so replacing its children leaves part markers intact. */
|
|
97
|
+
placePreview() {
|
|
98
|
+
const mount = this.renderRoot.querySelector(".canvas-mount");
|
|
99
|
+
const element = this.previewElement;
|
|
100
|
+
if (!mount || !element) return;
|
|
101
|
+
if (mount.childElementCount === 1 && mount.firstElementChild === element) return;
|
|
102
|
+
mount.replaceChildren(element);
|
|
103
|
+
}
|
|
104
|
+
updated(changed) {
|
|
105
|
+
super.updated(changed);
|
|
106
|
+
this.placePreview();
|
|
107
|
+
}
|
|
108
|
+
renderPreview(hidden = false) {
|
|
109
|
+
return html`
|
|
110
|
+
<div class="canvas-preview ${hidden ? "canvas-hidden" : ""}">
|
|
111
|
+
${this.previewError ? html`<pre class="canvas-error">${this.previewError}</pre>` : nothing}
|
|
112
|
+
<wa-scroller class="canvas-scroll" orientation="vertical">
|
|
113
|
+
<div class="canvas-mount"></div>
|
|
114
|
+
</wa-scroller>
|
|
115
|
+
</div>
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
renderContent() {
|
|
119
|
+
if (!this.ready) return html``;
|
|
120
|
+
return this.renderPreview();
|
|
121
|
+
}
|
|
122
|
+
async rasterizePreview() {
|
|
123
|
+
await this.updateComplete;
|
|
124
|
+
const preview = this.renderRoot.querySelector(".canvas-preview");
|
|
125
|
+
if (!preview) throw new Error("Canvas preview is not rendered");
|
|
126
|
+
const view = this.previewElement;
|
|
127
|
+
if (view?.updateComplete) await view.updateComplete;
|
|
128
|
+
return rasterizeElement(preview);
|
|
129
|
+
}
|
|
130
|
+
static {
|
|
131
|
+
this.styles = css`
|
|
132
|
+
:host { display: flex; flex-direction: column; height: 100%; min-height: 0; }
|
|
133
|
+
.canvas-preview { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }
|
|
134
|
+
wa-scroller.canvas-scroll { flex: 1 1 0; min-height: 0; height: 100%; }
|
|
135
|
+
.canvas-mount > * { display: block; }
|
|
136
|
+
.canvas-error {
|
|
137
|
+
margin: 0;
|
|
138
|
+
padding: var(--wa-space-s, 8px);
|
|
139
|
+
white-space: pre-wrap;
|
|
140
|
+
color: var(--wa-color-danger-on-quiet, #b42318);
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
_decorate([property({ attribute: false })], DocksCanvasPart.prototype, "input", void 0);
|
|
146
|
+
_decorate([property()], DocksCanvasPart.prototype, "canvasName", void 0);
|
|
147
|
+
_decorate([property()], DocksCanvasPart.prototype, "source", void 0);
|
|
148
|
+
_decorate([state()], DocksCanvasPart.prototype, "previewError", void 0);
|
|
149
|
+
_decorate([state()], DocksCanvasPart.prototype, "previewElement", void 0);
|
|
150
|
+
//#endregion
|
|
151
|
+
export { DocksCanvasPart };
|
|
152
|
+
|
|
153
|
+
//# sourceMappingURL=canvas-part.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-part.js","names":[],"sources":["../src/canvas-part.ts"],"sourcesContent":["import { DocksPart, type EditorInput } from '@eclipse-docks/core';\nimport { css, html, nothing, type PropertyValues } from '@eclipse-docks/core/externals/lit';\nimport { property, state } from '@eclipse-docks/core/externals/lit';\nimport type { CanvasContribution } from './contribution';\nimport { compileCanvas } from './compile';\nimport { canvasBridges } from './bridges/urls';\nimport type { CanvasHost } from './host';\nimport { elementFromConstructor, mountCompiled, type CanvasViewElement } from './mount';\nimport { rasterizeElement, type PreviewShot } from './preview-image';\nimport { readWorkspaceFile } from './workspace-file';\n\n/** Shared preview host for the canvas editor and the read-only contribution canvas. */\nexport abstract class DocksCanvasPart extends DocksPart {\n @property({ attribute: false }) input?: EditorInput;\n @property() canvasName?: string;\n @property() source = '';\n\n @state() protected previewError?: string;\n @state() protected previewElement?: CanvasViewElement;\n\n protected scrollMode: 'scroller' | 'native' | 'none' = 'none';\n protected host: CanvasHost = { getState: (_key, fallback) => fallback, setState: () => undefined, openFile: () => undefined };\n protected ready = false;\n protected reloadGeneration = 0;\n\n private previewDispose?: () => void;\n\n protected doClose() {\n this.reloadGeneration++;\n this.previewDispose?.();\n this.previewDispose = undefined;\n }\n\n async capturePreview(): Promise<PreviewShot> {\n return this.rasterizePreview();\n }\n\n /** Compile workspace or contribution source and mount the exported element. */\n protected async mountCompiledSource(source: string, entryPath: string): Promise<string> {\n const generation = ++this.reloadGeneration;\n const compiled = await compileCanvas({\n entryPath,\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 /** Mount a contribution that already provides its element constructor. */\n protected async mountLoadedConstructor(load: NonNullable<CanvasContribution['load']>, source: string): Promise<string> {\n const generation = ++this.reloadGeneration;\n try {\n const mod = await 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\n /** Called when a preview element is installed. `source` is the text that produced it. */\n protected adoptPreview(_source: string): void {}\n\n protected 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.adoptPreview(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 protected 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 protected updated(changed: PropertyValues) {\n super.updated(changed);\n this.placePreview();\n }\n\n protected renderPreview(hidden = false) {\n return html`\n <div class=\"canvas-preview ${hidden ? '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 `;\n }\n\n protected renderContent() {\n if (!this.ready) return html``;\n return this.renderPreview();\n }\n\n protected async rasterizePreview(): Promise<PreviewShot> {\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 view = this.previewElement as { updateComplete?: Promise<unknown> } | undefined;\n if (view?.updateComplete) await view.updateComplete;\n return rasterizeElement(preview);\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 wa-scroller.canvas-scroll { flex: 1 1 0; min-height: 0; height: 100%; }\n .canvas-mount > * { display: block; }\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"],"mappings":";;;;;;;;;;AAYA,IAAsB,kBAAtB,cAA8C,UAAU;;;EAG/B,KAAA,SAAA;EAKkC,KAAA,aAAA;EAC1B,KAAA,OAAA;GAAE,WAAW,MAAM,aAAa;GAAU,gBAAgB,KAAA;GAAW,gBAAgB,KAAA;EAAU;EAC1G,KAAA,QAAA;EACW,KAAA,mBAAA;;CAI7B,UAAoB;EAChB,KAAK;EACL,KAAK,iBAAiB;EACtB,KAAK,iBAAiB,KAAA;CAC1B;CAEA,MAAM,iBAAuC;EACzC,OAAO,KAAK,iBAAiB;CACjC;;CAGA,MAAgB,oBAAoB,QAAgB,WAAoC;EACpF,MAAM,aAAa,EAAE,KAAK;EAC1B,MAAM,WAAW,MAAM,cAAc;GACjC;GAC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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DocksCanvasPart } from './canvas-part';
|
|
2
|
+
/** Read-only preview for a canvas opened from the canvases dropdown. */
|
|
3
|
+
export declare class DocksCanvasReadonly extends DocksCanvasPart {
|
|
4
|
+
readonly kind: "registered";
|
|
5
|
+
private contribution?;
|
|
6
|
+
/**
|
|
7
|
+
* A part is the active editor only when `save` is overridden.
|
|
8
|
+
* This one writes nothing.
|
|
9
|
+
*/
|
|
10
|
+
save(): Promise<void>;
|
|
11
|
+
protected doInitUI(): Promise<void>;
|
|
12
|
+
private mount;
|
|
13
|
+
private contributedSource;
|
|
14
|
+
}
|
|
15
|
+
declare global {
|
|
16
|
+
interface HTMLElementTagNameMap {
|
|
17
|
+
'docks-canvas-readonly': DocksCanvasReadonly;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=canvas-readonly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-readonly.d.ts","sourceRoot":"","sources":["../src/canvas-readonly.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,wEAAwE;AACxE,qBACa,mBAAoB,SAAQ,eAAe;IACpD,QAAQ,CAAC,IAAI,EAAG,YAAY,CAAU;IAEtC,OAAO,CAAC,YAAY,CAAC,CAAqB;IAE1C;;;OAGG;IACY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;cAEpB,QAAQ;YAeV,KAAK;YAWL,iBAAiB;CAKlC;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,uBAAuB,EAAE,mBAAmB,CAAC;KAChD;CACJ"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DocksCanvasPart } from "./canvas-part.js";
|
|
2
|
+
import { createContributionHost } from "./host.js";
|
|
3
|
+
import { customElement } from "@eclipse-docks/core/externals/lit";
|
|
4
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
5
|
+
//#region src/canvas-readonly.ts
|
|
6
|
+
var DocksCanvasReadonly = class DocksCanvasReadonly extends DocksCanvasPart {
|
|
7
|
+
constructor(..._args) {
|
|
8
|
+
super(..._args);
|
|
9
|
+
this.kind = "registered";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A part is the active editor only when `save` is overridden.
|
|
13
|
+
* This one writes nothing.
|
|
14
|
+
*/
|
|
15
|
+
async save() {}
|
|
16
|
+
async doInitUI() {
|
|
17
|
+
const contribution = (this.input?.data)?.contribution;
|
|
18
|
+
if (!contribution) {
|
|
19
|
+
this.previewError = "No canvas contribution";
|
|
20
|
+
this.ready = true;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.contribution = contribution;
|
|
24
|
+
this.canvasName = contribution.name;
|
|
25
|
+
this.host = await createContributionHost(contribution);
|
|
26
|
+
this.ready = true;
|
|
27
|
+
await this.mount();
|
|
28
|
+
}
|
|
29
|
+
async mount() {
|
|
30
|
+
const contribution = this.contribution;
|
|
31
|
+
if (!contribution) return;
|
|
32
|
+
if (contribution.load) {
|
|
33
|
+
await this.mountLoadedConstructor(contribution.load, this.source);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const source = await this.contributedSource(contribution);
|
|
37
|
+
await this.mountCompiledSource(source, `${contribution.name}.canvas.js`);
|
|
38
|
+
}
|
|
39
|
+
async contributedSource(contribution) {
|
|
40
|
+
if (this.source) return this.source;
|
|
41
|
+
if (typeof contribution.source === "function") return contribution.source();
|
|
42
|
+
return contribution.source ?? "";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
DocksCanvasReadonly = _decorate([customElement("docks-canvas-readonly")], DocksCanvasReadonly);
|
|
46
|
+
//#endregion
|
|
47
|
+
export { DocksCanvasReadonly };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=canvas-readonly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-readonly.js","names":[],"sources":["../src/canvas-readonly.ts"],"sourcesContent":["import { customElement } from '@eclipse-docks/core/externals/lit';\nimport type { CanvasContribution } from './contribution';\nimport { DocksCanvasPart } from './canvas-part';\nimport { createContributionHost } from './host';\n\n/** Read-only preview for a canvas opened from the canvases dropdown. */\n@customElement('docks-canvas-readonly')\nexport class DocksCanvasReadonly extends DocksCanvasPart {\n readonly kind = 'registered' as const;\n\n private contribution?: CanvasContribution;\n\n /**\n * A part is the active editor only when `save` is overridden.\n * This one writes nothing.\n */\n override async save(): Promise<void> {}\n\n protected async doInitUI() {\n const data = this.input?.data as { contribution?: CanvasContribution } | undefined;\n const contribution = data?.contribution;\n if (!contribution) {\n this.previewError = 'No canvas contribution';\n this.ready = true;\n return;\n }\n this.contribution = contribution;\n this.canvasName = contribution.name;\n this.host = await createContributionHost(contribution);\n this.ready = true;\n await this.mount();\n }\n\n private async mount() {\n const contribution = this.contribution;\n if (!contribution) return;\n if (contribution.load) {\n await this.mountLoadedConstructor(contribution.load, this.source);\n return;\n }\n const source = await this.contributedSource(contribution);\n await this.mountCompiledSource(source, `${contribution.name}.canvas.js`);\n }\n\n private async contributedSource(contribution: CanvasContribution): Promise<string> {\n if (this.source) return this.source;\n if (typeof contribution.source === 'function') return contribution.source();\n return contribution.source ?? '';\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'docks-canvas-readonly': DocksCanvasReadonly;\n }\n}\n"],"mappings":";;;;;AAOO,IAAM,sBAAN,MAAM,4BAA4B,gBAAgB;;;EACrC,KAAA,OAAA;;;;;;CAQhB,MAAe,OAAsB,CAAC;CAEtC,MAAgB,WAAW;EAEvB,MAAM,gBADO,KAAK,OAAO,KAAA,EACE;EAC3B,IAAI,CAAC,cAAc;GACf,KAAK,eAAe;GACpB,KAAK,QAAQ;GACb;EACJ;EACA,KAAK,eAAe;EACpB,KAAK,aAAa,aAAa;EAC/B,KAAK,OAAO,MAAM,uBAAuB,YAAY;EACrD,KAAK,QAAQ;EACb,MAAM,KAAK,MAAM;CACrB;CAEA,MAAc,QAAQ;EAClB,MAAM,eAAe,KAAK;EAC1B,IAAI,CAAC,cAAc;EACnB,IAAI,aAAa,MAAM;GACnB,MAAM,KAAK,uBAAuB,aAAa,MAAM,KAAK,MAAM;GAChE;EACJ;EACA,MAAM,SAAS,MAAM,KAAK,kBAAkB,YAAY;EACxD,MAAM,KAAK,oBAAoB,QAAQ,GAAG,aAAa,KAAK,WAAW;CAC3E;CAEA,MAAc,kBAAkB,cAAmD;EAC/E,IAAI,KAAK,QAAQ,OAAO,KAAK;EAC7B,IAAI,OAAO,aAAa,WAAW,YAAY,OAAO,aAAa,OAAO;EAC1E,OAAO,aAAa,UAAU;CAClC;AACJ;AA3CC,sBAAA,UAAA,CAAA,cAAc,uBAAuB,CAAA,GAAA,mBAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/canvases/tasks.canvas.js?raw
|
|
2
|
+
var tasks_canvas_default = "import { LitElement, html, css } from \"docks/lit\";\nimport \"docks/webawesome\";\n\nexport default class extends LitElement {\n static properties = {\n tasks: { state: true },\n query: { state: true },\n grouping: { state: true },\n editingId: { state: true },\n };\n\n static styles = css`\n :host { display:block; min-height:100%; box-sizing:border-box; padding:clamp(18px,4vw,48px); color:var(--wa-color-text-normal); background:var(--wa-color-surface-default); font-family:var(--wa-font-family-body,system-ui,sans-serif); }\n * { box-sizing:border-box; }\n .app { max-width:920px; margin:0 auto; }\n header { display:flex; justify-content:space-between; align-items:flex-start; gap:20px; margin-bottom:30px; }\n .eyebrow { color:var(--wa-color-brand-600); text-transform:uppercase; letter-spacing:.12em; font-size:11px; font-weight:750; margin:0 0 8px; }\n h1 { font-size:clamp(30px,5vw,44px); line-height:1.05; letter-spacing:-.04em; margin:0; }\n .sub { color:var(--wa-color-text-quiet); margin:9px 0 0; }\n .date { color:var(--wa-color-text-quiet); font-size:13px; white-space:nowrap; padding-top:8px; }\n .summary { display:grid; grid-template-columns:1.3fr 1fr; gap:16px; margin-bottom:22px; }\n .panel { border:1px solid var(--wa-color-neutral-200); border-radius:16px; background:var(--wa-color-surface-raised); padding:20px; }\n .progress-top { display:flex; justify-content:space-between; gap:12px; align-items:center; }\n .label { font-size:13px; font-weight:700; }\n .muted { color:var(--wa-color-text-quiet); font-size:13px; }\n .percent { font-weight:750; font-size:22px; letter-spacing:-.03em; }\n .track { height:8px; border-radius:99px; background:var(--wa-color-neutral-100); overflow:hidden; margin-top:15px; }\n .fill { height:100%; border-radius:inherit; background:var(--wa-color-success-600); transition:width .25s ease; }\n .stats { display:grid; grid-template-columns:1fr 1fr; gap:12px; }\n .stat { border-left:2px solid var(--wa-color-neutral-200); padding-left:13px; }\n .stat strong { display:block; font-size:22px; letter-spacing:-.03em; }\n .stat span { color:var(--wa-color-text-quiet); font-size:12px; }\n .composer { display:flex; gap:10px; margin-bottom:14px; }\n wa-input { flex:1; }\n wa-input::part(base) { border-radius:11px; }\n wa-button::part(button) { border-radius:10px; font-weight:650; }\n .toolbar { display:flex; gap:12px; align-items:center; margin:18px 0 12px; }\n .search { flex:1; }\n .filters { display:flex; gap:6px; padding:4px; background:var(--wa-color-neutral-100); border-radius:11px; }\n .filters wa-button::part(button) { border:0; }\n .filters wa-button.active::part(button) { background:var(--wa-color-surface-raised); box-shadow:0 1px 4px #0001; }\n .group-title { display:flex; align-items:center; gap:9px; margin:22px 0 9px; font-size:13px; text-transform:uppercase; letter-spacing:.08em; font-weight:750; color:var(--wa-color-text-quiet); }\n .count { font-size:11px; background:var(--wa-color-neutral-100); padding:3px 7px; border-radius:20px; }\n .list { display:grid; gap:8px; }\n .task { display:flex; align-items:center; gap:12px; padding:13px 14px; border:1px solid var(--wa-color-neutral-200); background:var(--wa-color-surface-raised); border-radius:13px; min-width:0; }\n .check { width:21px; height:21px; flex:none; border-radius:7px; border:1.5px solid var(--wa-color-neutral-400); display:grid; place-items:center; cursor:pointer; color:white; background:transparent; font-size:14px; }\n .check.done { background:var(--wa-color-success-600); border-color:var(--wa-color-success-600); }\n .task-copy { flex:1; min-width:0; }\n .task-name { font-size:14px; font-weight:650; overflow-wrap:anywhere; }\n .task.done .task-name { color:var(--wa-color-text-quiet); text-decoration:line-through; }\n .task-date { color:var(--wa-color-text-quiet); font-size:11px; margin-top:4px; }\n .actions { display:flex; gap:3px; }\n .actions wa-button::part(button) { padding-inline:9px; }\n .empty { padding:30px 15px; text-align:center; color:var(--wa-color-text-quiet); border:1px dashed var(--wa-color-neutral-300); border-radius:13px; }\n .empty b { color:var(--wa-color-text-normal); display:block; margin-bottom:5px; }\n @media(max-width:620px) { .summary { grid-template-columns:1fr; } header { display:block; } .date { padding-top:12px; } .toolbar { flex-wrap:wrap; } .search { flex-basis:100%; } .filters { width:100%; justify-content:space-around; } .composer { align-items:stretch; } .task { padding:11px; } }\n `;\n\n constructor() {\n super();\n this.tasks = [];\n this.query = \"\";\n this.grouping = \"all\";\n this.editingId = null;\n }\n\n connectedCallback() {\n super.connectedCallback();\n const saved = this.canvasHost?.getState(\"tasks\", null);\n if (Array.isArray(saved)) this.tasks = saved;\n }\n\n persist() { this.canvasHost?.setState(\"tasks\", this.tasks); }\n\n addTask() {\n const input = this.renderRoot.querySelector(\"#new-task\");\n const title = String(input?.value ?? \"\").trim();\n if (!title) return;\n this.tasks = [{ id: crypto.randomUUID(), title, done: false, created: Date.now() }, ...this.tasks];\n this.persist();\n input.value = \"\";\n input.focus();\n }\n\n toggle(id) {\n this.tasks = this.tasks.map(t => t.id === id ? { ...t, done: !t.done } : t);\n this.persist();\n }\n\n remove(id) { this.tasks = this.tasks.filter(t => t.id !== id); this.persist(); }\n\n edit(id) {\n const task = this.tasks.find(t => t.id === id);\n if (!task) return;\n const title = window.prompt(\"Edit task\", task.title);\n if (title === null) return;\n if (!title.trim()) return;\n this.tasks = this.tasks.map(t => t.id === id ? { ...t, title: title.trim() } : t);\n this.persist();\n }\n\n filtered() {\n const q = this.query.trim().toLowerCase();\n return this.tasks.filter(t => (!q || t.title.toLowerCase().includes(q)) &&\n (this.grouping === \"all\" || (this.grouping === \"done\" ? t.done : !t.done)));\n }\n\n renderTask(task) {\n return html`<article class=\"task ${task.done ? \"done\" : \"\"}\">\n <button class=\"check ${task.done ? \"done\" : \"\"}\" aria-label=${task.done ? \"Mark incomplete\" : \"Mark complete\"} @click=${() => this.toggle(task.id)}>${task.done ? \"✓\" : \"\"}</button>\n <div class=\"task-copy\"><div class=\"task-name\">${task.title}</div><div class=\"task-date\">Added ${new Date(task.created).toLocaleDateString(undefined,{month:\"short\",day:\"numeric\"})}</div></div>\n <div class=\"actions\"><wa-button appearance=\"plain\" size=\"small\" aria-label=\"Edit task\" @click=${() => this.edit(task.id)}>Edit</wa-button><wa-button appearance=\"plain\" variant=\"danger\" size=\"small\" aria-label=\"Delete task\" @click=${() => this.remove(task.id)}>Delete</wa-button></div>\n </article>`;\n }\n\n render() {\n const done = this.tasks.filter(t => t.done).length;\n const total = this.tasks.length;\n const percent = total ? Math.round(done / total * 100) : 0;\n const visible = this.filtered();\n const activeTasks = visible.filter(t => !t.done);\n const doneTasks = visible.filter(t => t.done);\n const date = new Intl.DateTimeFormat(undefined, { weekday:\"long\", month:\"long\", day:\"numeric\" }).format(new Date());\n return html`<main class=\"app\">\n <header><div><p class=\"eyebrow\">Daily planner</p><h1>Today, with intention.</h1><p class=\"sub\">A little progress adds up. Keep your focus on what matters.</p></div><div class=\"date\">${date}</div></header>\n <section class=\"summary\"><div class=\"panel\"><div class=\"progress-top\"><div><div class=\"label\">Today's progress</div><div class=\"muted\">${done} of ${total} tasks completed</div></div><div class=\"percent\">${percent}%</div></div><div class=\"track\"><div class=\"fill\" style=\"width:${percent}%\"></div></div></div><div class=\"panel stats\"><div class=\"stat\"><strong>${total - done}</strong><span>Still to do</span></div><div class=\"stat\"><strong>${done}</strong><span>Completed</span></div></div></section>\n <section class=\"composer\"><wa-input id=\"new-task\" placeholder=\"What needs your attention today?\" aria-label=\"New task\" @keydown=${e => { if (e.key === \"Enter\") this.addTask(); }}></wa-input><wa-button variant=\"brand\" @click=${() => this.addTask()}>Add task</wa-button></section>\n <div class=\"toolbar\"><wa-input class=\"search\" placeholder=\"Search your tasks…\" aria-label=\"Search tasks\" @keyup=${e => { this.query = e.target.value; }}></wa-input><div class=\"filters\" aria-label=\"Filter tasks\"><wa-button class=${this.grouping === \"all\" ? \"active\" : \"\"} size=\"small\" appearance=\"plain\" @click=${() => this.grouping = \"all\"}>All</wa-button><wa-button class=${this.grouping === \"active\" ? \"active\" : \"\"} size=\"small\" appearance=\"plain\" @click=${() => this.grouping = \"active\"}>To do</wa-button><wa-button class=${this.grouping === \"done\" ? \"active\" : \"\"} size=\"small\" appearance=\"plain\" @click=${() => this.grouping = \"done\"}>Done</wa-button></div></div>\n ${visible.length ? html`${this.grouping === \"all\" || this.grouping === \"active\" ? html`<section><h2 class=\"group-title\">To do <span class=\"count\">${activeTasks.length}</span></h2><div class=\"list\">${activeTasks.length ? activeTasks.map(t => this.renderTask(t)) : html`<div class=\"empty\"><b>Nothing left on your list.</b>Enjoy the breathing room.</div>`}</div></section>` : \"\"}${this.grouping === \"all\" || this.grouping === \"done\" ? html`<section><h2 class=\"group-title\">Completed <span class=\"count\">${doneTasks.length}</span></h2><div class=\"list\">${doneTasks.length ? doneTasks.map(t => this.renderTask(t)) : html`<div class=\"empty\">Completed tasks will show up here.</div>`}</div></section>` : \"\"}` : html`<div class=\"empty\"><b>${this.query ? \"No tasks match your search.\" : \"Your list is clear.\"}</b>${this.query ? \"Try another search or change the filter.\" : \"Add a task above to get started.\"}</div>`}\n </main>`;\n }\n}\n";
|
|
3
|
+
//#endregion
|
|
4
|
+
export { tasks_canvas_default as default };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=tasks.canvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.canvas.js","names":[],"sources":[],"mappings":""}
|
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;AAGzD,OAAO,iBAAiB,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;AACzB,OAAO,mBAAmB,CAAC;AAI3B,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,kBAAkB,EAAE,UAAU,SAAK,GAAG,WAAW,CAahG;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,CA0K7C"}
|
package/dist/commands.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { listRegisteredCanvases } from "./canvases.js";
|
|
2
|
-
import { connectedWorkspaceEditors, findOpenCanvas, readActiveCanvas } from "./active-canvas.js";
|
|
2
|
+
import { connectedWorkspaceEditors, findOpenCanvas, isCanvasViewer, readActiveCanvas } from "./active-canvas.js";
|
|
3
3
|
import { attachPreviewShot } from "./preview-image.js";
|
|
4
4
|
import { writeWorkspaceFile } from "./workspace-file.js";
|
|
5
5
|
import "./canvas-editor.js";
|
|
6
|
+
import "./canvas-readonly.js";
|
|
6
7
|
import { File, PANEL_BOTTOM, SIDEBAR_AUXILIARY, SIDEBAR_MAIN, contributionRegistry, editorRegistry, registerAll, workspaceService } from "@eclipse-docks/core";
|
|
7
8
|
import { html } from "@eclipse-docks/core/externals/lit";
|
|
8
9
|
//#region src/commands.ts
|
|
@@ -12,17 +13,17 @@ var VIEW_SLOTS = /* @__PURE__ */ new Set([
|
|
|
12
13
|
PANEL_BOTTOM
|
|
13
14
|
]);
|
|
14
15
|
function canvasEditorInput(contribution, sourceText = "") {
|
|
15
|
-
const hasSource = contribution.source !== void 0;
|
|
16
16
|
const input = {
|
|
17
17
|
key: `canvas:${contribution.name}`,
|
|
18
18
|
title: contribution.label,
|
|
19
19
|
icon: contribution.icon ?? "table-columns",
|
|
20
20
|
data: { contribution },
|
|
21
21
|
state: { mode: "preview" },
|
|
22
|
+
toolbar: false,
|
|
22
23
|
component: () => html``
|
|
23
24
|
};
|
|
24
|
-
input.component = (id) =>
|
|
25
|
-
input.editorId = "system.canvas-
|
|
25
|
+
input.component = (id) => html`<docks-canvas-readonly id="${id}" .input=${input} .source=${sourceText}></docks-canvas-readonly>`;
|
|
26
|
+
input.editorId = "system.canvas-readonly";
|
|
26
27
|
return input;
|
|
27
28
|
}
|
|
28
29
|
async function openCanvasByName(name) {
|
|
@@ -126,22 +127,25 @@ function registerCanvasCommands() {
|
|
|
126
127
|
required: false
|
|
127
128
|
}]
|
|
128
129
|
},
|
|
129
|
-
handler: {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
editor
|
|
138
|
-
|
|
130
|
+
handler: {
|
|
131
|
+
canExecute: () => !isCanvasViewer(),
|
|
132
|
+
execute: async ({ params }) => {
|
|
133
|
+
const source = String(params?.source ?? "");
|
|
134
|
+
const path = (typeof params?.path === "string" ? params.path : void 0) ?? workspaceCanvas()?.getFilePath?.() ?? void 0;
|
|
135
|
+
const targets = path ? connectedWorkspaceEditors(path) : [];
|
|
136
|
+
if (targets.length) {
|
|
137
|
+
let compiled = "ready";
|
|
138
|
+
for (const editor of targets) {
|
|
139
|
+
if (!editor.setSource || !editor.reload) continue;
|
|
140
|
+
editor.setSource(source);
|
|
141
|
+
compiled = await editor.reload();
|
|
142
|
+
}
|
|
143
|
+
return compiled;
|
|
139
144
|
}
|
|
140
|
-
return
|
|
145
|
+
if (!path) return "Provide a workspace path";
|
|
146
|
+
return writeWorkspaceFile(path, source);
|
|
141
147
|
}
|
|
142
|
-
|
|
143
|
-
return writeWorkspaceFile(path, source);
|
|
144
|
-
} }
|
|
148
|
+
}
|
|
145
149
|
});
|
|
146
150
|
registerAll({
|
|
147
151
|
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 { 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,UAAU,CAAC;CAC3E,OAAO;AACX;AAEA,eAAsB,iBAAiB,MAA+B;CAClE,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,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ACjB,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"}
|
|
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, isCanvasViewer, 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';\nimport './canvas-readonly';\n\nconst VIEW_SLOTS = new Set([SIDEBAR_MAIN, SIDEBAR_AUXILIARY, PANEL_BOTTOM]);\n\nexport function canvasEditorInput(contribution: CanvasContribution, sourceText = ''): EditorInput {\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 toolbar: false,\n component: () => html``,\n } as EditorInput;\n input.component = (id: string) => html`<docks-canvas-readonly id=\"${id}\" .input=${input} .source=${sourceText}></docks-canvas-readonly>`;\n (input as unknown as { editorId: string }).editorId = 'system.canvas-readonly';\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 canExecute: () => !isCanvasViewer(),\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":";;;;;;;;;AAoBA,IAAM,6BAAa,IAAI,IAAI;CAAC;CAAc;CAAmB;AAAY,CAAC;AAE1E,SAAgB,kBAAkB,cAAkC,aAAa,IAAiB;CAC9F,MAAM,QAAQ;EACV,KAAK,UAAU,aAAa;EAC5B,OAAO,aAAa;EACpB,MAAM,aAAa,QAAQ;EAC3B,MAAM,EAAE,aAAa;EACrB,OAAO,EAAE,MAAM,UAAU;EACzB,SAAS;EACT,iBAAiB,IAAI;CACzB;CACA,MAAM,aAAa,OAAe,IAAI,8BAA8B,GAAG,WAAW,MAAM,WAAW,WAAW;CAC9G,MAA2C,WAAW;CACtD,OAAO;AACX;AAEA,eAAsB,iBAAiB,MAA+B;CAClE,MAAM,eAAe,uBAAuB,CAAC,CAAC,MAAK,SAAQ,KAAK,S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,QAAQ,EAAE,GAAG,IAAI;GAC1D;EACJ;CACJ,CAAC;AACL"}
|
package/dist/contribution.d.ts
CHANGED
|
@@ -18,11 +18,13 @@ export interface CanvasToolContribution {
|
|
|
18
18
|
}
|
|
19
19
|
/** A canvas module registered on {@link SYSTEM_CANVASES} and opened from the toolbar dropdown. */
|
|
20
20
|
export interface CanvasContribution extends TabContribution {
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/** Unique app-settings key for this canvas's `canvasHost` state. */
|
|
22
|
+
settingsKey: string;
|
|
23
|
+
/** Constructor module. Omit when `source` is canvas text; the editor compiles that. */
|
|
24
|
+
load?: () => Promise<{
|
|
23
25
|
default: CustomElementConstructor;
|
|
24
26
|
}>;
|
|
25
|
-
/**
|
|
27
|
+
/** Canvas module source. Compiled for the preview; the contribution is not editable. */
|
|
26
28
|
source?: string | (() => Promise<string>);
|
|
27
29
|
tools?: CanvasToolContribution[];
|
|
28
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contribution.d.ts","sourceRoot":"","sources":["../src/contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEzE,wGAAwG;AACxG,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAEjD,MAAM,WAAW,sBAAsB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,OAAO,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5B,CAAC,CAAC;IACH,OAAO,EAAE,CAAC,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE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AE,YAAY,GAAG,YAAY,IAAI,kBAAkB,CAInG"}
|
package/dist/contribution.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
/** Slot for canvases an extension contributes. The toolbar dropdown lists it; it is not a tab group. */
|
|
3
3
|
var SYSTEM_CANVASES = "system.canvases";
|
|
4
4
|
function isCanvasContribution(contribution) {
|
|
5
|
-
|
|
5
|
+
const canvas = contribution;
|
|
6
|
+
return typeof canvas.settingsKey === "string" && canvas.settingsKey.length > 0 && (typeof canvas.load === "function" || canvas.source !== void 0);
|
|
6
7
|
}
|
|
7
8
|
//#endregion
|
|
8
9
|
export { SYSTEM_CANVASES, isCanvasContribution };
|
package/dist/contribution.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contribution.js","names":[],"sources":["../src/contribution.ts"],"sourcesContent":["import type { Contribution, TabContribution } from '@eclipse-docks/core';\n\n/** Slot for canvases an extension contributes. The toolbar dropdown lists it; it is not a tab group. */\nexport const SYSTEM_CANVASES = 'system.canvases';\n\nexport interface CanvasToolContribution {\n id: string;\n name: string;\n description: string;\n parameters?: Array<{\n name: string;\n description: string;\n type?: string;\n required: boolean;\n allowedValues?: string[];\n }>;\n execute: (context: { params?: Record<string, unknown> }) => unknown | Promise<unknown>;\n}\n\n/** A canvas module registered on {@link SYSTEM_CANVASES} and opened from the toolbar dropdown. */\nexport interface CanvasContribution extends TabContribution {\n /**
|
|
1
|
+
{"version":3,"file":"contribution.js","names":[],"sources":["../src/contribution.ts"],"sourcesContent":["import type { Contribution, TabContribution } from '@eclipse-docks/core';\n\n/** Slot for canvases an extension contributes. The toolbar dropdown lists it; it is not a tab group. */\nexport const SYSTEM_CANVASES = 'system.canvases';\n\nexport interface CanvasToolContribution {\n id: string;\n name: string;\n description: string;\n parameters?: Array<{\n name: string;\n description: string;\n type?: string;\n required: boolean;\n allowedValues?: string[];\n }>;\n execute: (context: { params?: Record<string, unknown> }) => unknown | Promise<unknown>;\n}\n\n/** A canvas module registered on {@link SYSTEM_CANVASES} and opened from the toolbar dropdown. */\nexport interface CanvasContribution extends TabContribution {\n /** Unique app-settings key for this canvas's `canvasHost` state. */\n settingsKey: string;\n /** Constructor module. Omit when `source` is canvas text; the editor compiles that. */\n load?: () => Promise<{ default: CustomElementConstructor }>;\n /** Canvas module source. Compiled for the preview; the contribution is not editable. */\n source?: string | (() => Promise<string>);\n tools?: CanvasToolContribution[];\n}\n\nexport function isCanvasContribution(contribution: Contribution): contribution is CanvasContribution {\n const canvas = contribution as CanvasContribution;\n return typeof canvas.settingsKey === 'string' && canvas.settingsKey.length > 0\n && (typeof canvas.load === 'function' || canvas.source !== undefined);\n}\n"],"mappings":";;AAGA,IAAa,kBAAkB;AA2B/B,SAAgB,qBAAqB,cAAgE;CACjG,MAAM,SAAS;CACf,OAAO,OAAO,OAAO,gBAAgB,YAAY,OAAO,YAAY,SAAS,MACrE,OAAO,OAAO,SAAS,cAAc,OAAO,WAAW,KAAA;AACnE"}
|
package/dist/host.js
CHANGED
|
@@ -21,7 +21,7 @@ async function createFileHost(file) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
async function createContributionHost(contribution) {
|
|
24
|
-
const key =
|
|
24
|
+
const key = contribution.settingsKey;
|
|
25
25
|
const stored = await appSettings.get(key);
|
|
26
26
|
return createMemoryHost(stored && typeof stored === "object" ? stored : {}, (state) => {
|
|
27
27
|
appSettings.set(key, state);
|
package/dist/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["import { appSettings, editorRegistry, File, workspaceService } from '@eclipse-docks/core';\nimport type { CanvasContribution } from './contribution';\n\nexport interface CanvasHost {\n getState(key: string, fallback?: unknown): unknown;\n setState(key: string, value: unknown): void;\n openFile(path: string): void;\n}\n\nexport function createMemoryHost(initial: Record<string, unknown>, persist: (state: Record<string, unknown>) => void): CanvasHost {\n const state = { ...initial };\n return {\n getState(key, fallback) {\n return state[key] === undefined ? fallback : state[key];\n },\n setState(key, value) {\n state[key] = value;\n persist(state);\n },\n openFile(path) {\n void openWorkspaceFile(path);\n },\n };\n}\n\nexport async function createFileHost(file: File): Promise<CanvasHost> {\n const initial = await readSidecar(file);\n return createMemoryHost(initial, state => {\n void writeSidecar(file, state);\n });\n}\n\nexport async function createContributionHost(contribution: CanvasContribution): Promise<CanvasHost> {\n const key =
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["import { appSettings, editorRegistry, File, workspaceService } from '@eclipse-docks/core';\nimport type { CanvasContribution } from './contribution';\n\nexport interface CanvasHost {\n getState(key: string, fallback?: unknown): unknown;\n setState(key: string, value: unknown): void;\n openFile(path: string): void;\n}\n\nexport function createMemoryHost(initial: Record<string, unknown>, persist: (state: Record<string, unknown>) => void): CanvasHost {\n const state = { ...initial };\n return {\n getState(key, fallback) {\n return state[key] === undefined ? fallback : state[key];\n },\n setState(key, value) {\n state[key] = value;\n persist(state);\n },\n openFile(path) {\n void openWorkspaceFile(path);\n },\n };\n}\n\nexport async function createFileHost(file: File): Promise<CanvasHost> {\n const initial = await readSidecar(file);\n return createMemoryHost(initial, state => {\n void writeSidecar(file, state);\n });\n}\n\nexport async function createContributionHost(contribution: CanvasContribution): Promise<CanvasHost> {\n const key = contribution.settingsKey;\n const stored = await appSettings.get(key);\n const initial = stored && typeof stored === 'object' ? stored as Record<string, unknown> : {};\n return createMemoryHost(initial, state => {\n void appSettings.set(key, state);\n });\n}\n\nfunction sidecarName(fileName: string): string {\n return fileName.replace(/\\.canvas\\.js$/i, '.canvas.data.json');\n}\n\nasync function readSidecar(file: File): Promise<Record<string, unknown>> {\n const parent = file.getParent();\n if (!parent) return {};\n const resource = await parent.getResource(sidecarName(file.getName()));\n if (!(resource instanceof File)) return {};\n try {\n const parsed = JSON.parse(await resource.getContents());\n return parsed && typeof parsed === 'object' ? parsed as Record<string, unknown> : {};\n } catch {\n return {};\n }\n}\n\nasync function writeSidecar(file: File, state: Record<string, unknown>): Promise<void> {\n const parent = file.getParent();\n if (!parent) return;\n const name = sidecarName(file.getName());\n let resource = await parent.getResource(name);\n if (!(resource instanceof File)) {\n resource = await parent.getResource(name, { create: true }) as File | null;\n }\n if (!(resource instanceof File)) return;\n await resource.saveContents(JSON.stringify(state));\n}\n\nasync function openWorkspaceFile(path: string): Promise<void> {\n const workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\n if (!workspace) return;\n const resource = await workspace.getResource(path.replace(/^\\/+/, ''));\n if (resource instanceof File) await editorRegistry.loadEditor(resource);\n}\n"],"mappings":";;AASA,SAAgB,iBAAiB,SAAkC,SAA+D;CAC9H,MAAM,QAAQ,EAAE,GAAG,QAAQ;CAC3B,OAAO;EACH,SAAS,KAAK,UAAU;GACpB,OAAO,MAAM,SAAS,KAAA,IAAY,WAAW,MAAM;EACvD;EACA,SAAS,KAAK,OAAO;GACjB,MAAM,OAAO;GACb,QAAQ,KAAK;EACjB;EACA,SAAS,MAAM;GACX,kBAAuB,IAAI;EAC/B;CACJ;AACJ;AAEA,eAAsB,eAAe,MAAiC;CAElE,OAAO,iBAAiB,MADF,YAAY,IAAI,IACL,UAAS;EACtC,aAAkB,MAAM,KAAK;CACjC,CAAC;AACL;AAEA,eAAsB,uBAAuB,cAAuD;CAChG,MAAM,MAAM,aAAa;CACzB,MAAM,SAAS,MAAM,YAAY,IAAI,GAAG;CAExC,OAAO,iBADS,UAAU,OAAO,WAAW,WAAW,SAAoC,CAAC,IAC3D,UAAS;EACtC,YAAiB,IAAI,KAAK,KAAK;CACnC,CAAC;AACL;AAEA,SAAS,YAAY,UAA0B;CAC3C,OAAO,SAAS,QAAQ,kBAAkB,mBAAmB;AACjE;AAEA,eAAe,YAAY,MAA8C;CACrE,MAAM,SAAS,KAAK,UAAU;CAC9B,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,MAAM,WAAW,MAAM,OAAO,YAAY,YAAY,KAAK,QAAQ,CAAC,CAAC;CACrE,IAAI,EAAE,oBAAoB,OAAO,OAAO,CAAC;CACzC,IAAI;EACA,MAAM,SAAS,KAAK,MAAM,MAAM,SAAS,YAAY,CAAC;EACtD,OAAO,UAAU,OAAO,WAAW,WAAW,SAAoC,CAAC;CACvF,QAAQ;EACJ,OAAO,CAAC;CACZ;AACJ;AAEA,eAAe,aAAa,MAAY,OAA+C;CACnF,MAAM,SAAS,KAAK,UAAU;CAC9B,IAAI,CAAC,QAAQ;CACb,MAAM,OAAO,YAAY,KAAK,QAAQ,CAAC;CACvC,IAAI,WAAW,MAAM,OAAO,YAAY,IAAI;CAC5C,IAAI,EAAE,oBAAoB,OACtB,WAAW,MAAM,OAAO,YAAY,MAAM,EAAE,QAAQ,KAAK,CAAC;CAE9D,IAAI,EAAE,oBAAoB,OAAO;CACjC,MAAM,SAAS,aAAa,KAAK,UAAU,KAAK,CAAC;AACrD;AAEA,eAAe,kBAAkB,MAA6B;CAC1D,MAAM,YAAY,iBAAiB,iBAAiB,KAAK,MAAM,iBAAiB,aAAa;CAC7F,IAAI,CAAC,WAAW;CAChB,MAAM,WAAW,MAAM,UAAU,YAAY,KAAK,QAAQ,QAAQ,EAAE,CAAC;CACrE,IAAI,oBAAoB,MAAM,MAAM,eAAe,WAAW,QAAQ;AAC1E"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/skills/eclipse-docks-canvas/SKILL.md?raw
|
|
2
|
-
var SKILL_default = "---\nname: eclipse-docks-canvas\ndescription: >-\n Create or edit interactive Eclipse Docks canvases (.canvas.js): LitElement UIs,\n dashboards, todo apps, widgets, maps, and previewable tools. Use when the user\n wants an interactive view, canvas, widget, or .canvas.js file — even if they do\n not say \"canvas\".\n---\n\n# Eclipse Docks canvas\n\nWrite a workspace file ending in `.canvas.js`. Default-export a `LitElement` subclass from `docks/lit`. Do **not** extend `HTMLElement`. Do **not** call `customElements.define` — the host registers the tag.\n\n## Hard rules\n\n1. **`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`.\n2. Pure JavaScript only — no TypeScript, no decorators. Declare reactive fields with `static properties = { … }`. Initialize plain defaults in `constructor`; hydrate from `canvasHost` only after connect.\n3. 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.\n4. Emit complete, valid JavaScript — no truncated objects or unfinished strings.\n5. 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.\n\n## Minimal pattern\n\n```js\nimport { LitElement, html, css } from \"docks/lit\";\nimport \"docks/webawesome\";\n\nexport default class extends LitElement {\n static properties = {\n items: { state: true },\n draft: { state: true },\n };\n\n static styles = css`\n :host { display: block; padding: 1rem; box-sizing: border-box; }\n `;\n\n constructor() {\n super();\n this.items = [];\n this.draft = \"\";\n }\n\n connectedCallback() {\n super.connectedCallback();\n const saved = this.canvasHost?.getState(\"items\", null);\n if (Array.isArray(saved)) this.items = saved;\n }\n\n persist() {\n this.canvasHost?.setState(\"items\", this.items);\n }\n\n addItem() {\n const input = this.renderRoot.querySelector(\"wa-input\");\n const text = String(input?.value ?? \"\").trim();\n if (!text) return;\n this.items = [...this.items, { id: crypto.randomUUID(), text, done: false }];\n this.draft = \"\";\n this.persist();\n }\n\n render() {\n return html`\n <wa-input\n placeholder=\"New item\"\n .value=${this.draft}\n @keydown=${(e) => { if (e.key === \"Enter\") this.addItem(); }}\n ></wa-input>\n <wa-button @click=${() => this.addItem()}>Add</wa-button>\n <ul>\n ${this.items.map((item) => html`<li>${item.text}</li>`)}\n </ul>\n `;\n }\n}\n```\n\nAPIs: `this.canvasHost.getState(key, fallback)`, `this.canvasHost.setState(key, value)`, `this.canvasHost.openFile(path)`.\n\n## Cross-origin resources\n\n`<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.\n\nWhen 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.\n\n```html\n<img crossorigin=\"anonymous\" src=\"https://cdn.example/asset.png\" />\n<script crossorigin=\"anonymous\" src=\"https://cdn.example/lib.js\"><\/script>\n```\n\nA 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.\n\n## Styles inside the shadow root\n\nThe 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.\n\nFetch the stylesheet as CORS and adopt it before constructing the widget:\n\n```js\nconst cssText = await (await fetch(stylesheetUrl, { mode: \"cors\" })).text();\nconst sheet = new CSSStyleSheet();\nsheet.replaceSync(cssText);\nthis.shadowRoot.adoptedStyleSheets = [...this.shadowRoot.adoptedStyleSheets, sheet];\n```\n\n`static styles` is for the host. Do not rely on a document-level stylesheet for DOM the library creates inside the shadow root.\n\n## Imports\n\n- `docks/lit`, `docks/webawesome`, `docks/core` → running app\n- Relative imports → workspace files (compiler inlines them: JSON → value, text/CSS → string, binaries → data URL)\n\nBefore non-trivial UI or shell integration, load companion skills as needed:\n\n- `skills.load` `eclipse-docks-lit` — reactive properties, templates, directives (pure JS)\n- `skills.load` `eclipse-docks-webawesome` — `wa-*` components and layout utilities\n- `skills.load` `eclipse-docks-core` — workspace, editors, commands, dialogs, events\n\n## Workflow\n\n1. `workspace_write` a durable `<root>/….canvas.js` (qualify with a root from `workspace_list`).\n2. `canvas.open` with that path — returns `ready` or the compile/runtime error.\n3. 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.\n4. Optional: `canvas.capture_preview` to attach a screenshot (iframe contents may be blank).\n\nExtension-registered canvases live on `system.canvases` and open by name via `canvas.open
|
|
2
|
+
var SKILL_default = "---\nname: eclipse-docks-canvas\ndescription: >-\n Create or edit interactive Eclipse Docks canvases (.canvas.js): LitElement UIs,\n dashboards, todo apps, widgets, maps, and previewable tools. Use when the user\n wants an interactive view, canvas, widget, or .canvas.js file — even if they do\n not say \"canvas\".\n---\n\n# Eclipse Docks canvas\n\nWrite a workspace file ending in `.canvas.js`. Default-export a `LitElement` subclass from `docks/lit`. Do **not** extend `HTMLElement`. Do **not** call `customElements.define` — the host registers the tag.\n\n## Hard rules\n\n1. **`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`.\n2. Pure JavaScript only — no TypeScript, no decorators. Declare reactive fields with `static properties = { … }`. Initialize plain defaults in `constructor`; hydrate from `canvasHost` only after connect.\n3. 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.\n4. Emit complete, valid JavaScript — no truncated objects or unfinished strings.\n5. 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.\n\n## Minimal pattern\n\n```js\nimport { LitElement, html, css } from \"docks/lit\";\nimport \"docks/webawesome\";\n\nexport default class extends LitElement {\n static properties = {\n items: { state: true },\n draft: { state: true },\n };\n\n static styles = css`\n :host { display: block; padding: 1rem; box-sizing: border-box; }\n `;\n\n constructor() {\n super();\n this.items = [];\n this.draft = \"\";\n }\n\n connectedCallback() {\n super.connectedCallback();\n const saved = this.canvasHost?.getState(\"items\", null);\n if (Array.isArray(saved)) this.items = saved;\n }\n\n persist() {\n this.canvasHost?.setState(\"items\", this.items);\n }\n\n addItem() {\n const input = this.renderRoot.querySelector(\"wa-input\");\n const text = String(input?.value ?? \"\").trim();\n if (!text) return;\n this.items = [...this.items, { id: crypto.randomUUID(), text, done: false }];\n this.draft = \"\";\n this.persist();\n }\n\n render() {\n return html`\n <wa-input\n placeholder=\"New item\"\n .value=${this.draft}\n @keydown=${(e) => { if (e.key === \"Enter\") this.addItem(); }}\n ></wa-input>\n <wa-button @click=${() => this.addItem()}>Add</wa-button>\n <ul>\n ${this.items.map((item) => html`<li>${item.text}</li>`)}\n </ul>\n `;\n }\n}\n```\n\nAPIs: `this.canvasHost.getState(key, fallback)`, `this.canvasHost.setState(key, value)`, `this.canvasHost.openFile(path)`.\n\n## Cross-origin resources\n\n`<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.\n\nWhen 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.\n\n```html\n<img crossorigin=\"anonymous\" src=\"https://cdn.example/asset.png\" />\n<script crossorigin=\"anonymous\" src=\"https://cdn.example/lib.js\"><\/script>\n```\n\nA 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.\n\n## Styles inside the shadow root\n\nThe 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.\n\nFetch the stylesheet as CORS and adopt it before constructing the widget:\n\n```js\nconst cssText = await (await fetch(stylesheetUrl, { mode: \"cors\" })).text();\nconst sheet = new CSSStyleSheet();\nsheet.replaceSync(cssText);\nthis.shadowRoot.adoptedStyleSheets = [...this.shadowRoot.adoptedStyleSheets, sheet];\n```\n\n`static styles` is for the host. Do not rely on a document-level stylesheet for DOM the library creates inside the shadow root.\n\n## Imports\n\n- `docks/lit`, `docks/webawesome`, `docks/core` → running app\n- Relative imports → workspace files (compiler inlines them: JSON → value, text/CSS → string, binaries → data URL)\n\nBefore non-trivial UI or shell integration, load companion skills as needed:\n\n- `skills.load` `eclipse-docks-lit` — reactive properties, templates, directives (pure JS)\n- `skills.load` `eclipse-docks-webawesome` — `wa-*` components and layout utilities\n- `skills.load` `eclipse-docks-core` — workspace, editors, commands, dialogs, events\n\n## Workflow\n\n1. `workspace_write` a durable `<root>/….canvas.js` (qualify with a root from `workspace_list`).\n2. `canvas.open` with that path — returns `ready` or the compile/runtime error.\n3. 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.\n4. Optional: `canvas.capture_preview` to attach a screenshot (iframe contents may be blank).\n\nExtension-registered canvases live on `system.canvases` and open by name via `canvas.open`. That opens a read-only viewer. Do not edit it: `canvas.apply_source`, `canvas.get_source`, `canvas.set_state`, and any tools declared by that canvas are not available while it is active.\n";
|
|
3
3
|
//#endregion
|
|
4
4
|
export { SKILL_default as default };
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/skills/eclipse-docks-core/SKILL.md?raw
|
|
2
|
-
var SKILL_default = "---\nname: eclipse-docks-core\ndescription: >-\n Eclipse Docks core runtime from docks/core: workspace files, editors, commands,\n contributions, dialogs, toasts, settings, and events. Use when a canvas or\n extension needs to open files, register UI, run commands, or talk to the shell.\n---\n\n# Eclipse Docks core (`docks/core`)\n\n```js\nimport {\n workspaceService,\n File,\n editorRegistry,\n commandRegistry,\n registerAll,\n contributionRegistry,\n publish,\n subscribe,\n unsubscribe,\n appSettings,\n toastInfo,\n toastError,\n confirmDialog,\n promptDialog,\n filebrowserDialog,\n} from \"docks/core\";\n```\n\nAlias: `@eclipse-docks/core`. Subpaths map to the same bridges, e.g. `docks/core/parts`, `docks/core/widgets`, `docks/core/externals/lit`.\n\n## Workspace\n\n```js\nconst workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\nconst resource = await workspace.getResource(\"folder/note.md\");\nif (resource instanceof File) {\n const text = await resource.getContents();\n await resource.saveContents(text);\n}\n```\n\n- Paths are workspace-relative (root-prefixed in the composite workspace).\n- Create with `getResource(path, { create: true })` when the API allows.\n- Canvases can also open a path via `this.canvasHost.openFile(path)` without importing core.\n\n## Editors\n\n```js\nawait editorRegistry.loadEditor(file); // default handler\nawait editorRegistry.loadEditor(file, \"system.canvas-editor\");\n```\n\n`EditorInput` objects carry `title`, `key`, `data`, `component`, optional `state`. Prefer opening a `File` when one exists.\n\n## Commands\n\n```js\nregisterAll({\n command: {\n id: \"demo.ping\",\n name: \"Ping\",\n description: \"Demo command\",\n parameters: [],\n },\n handler: {\n execute: async () => \"pong\",\n },\n});\n\nawait commandRegistry.execute(\"demo.ping\", {});\n```\n\nCommands registered this way can surface as AI tools when the cognitive runtime refreshes command tools.\n\n## Contributions\n\n```js\nimport { SIDEBAR_MAIN, TOOLBAR_MAIN_RIGHT } from \"docks/core\";\n\ncontributionRegistry.registerContribution(SIDEBAR_MAIN, {\n name: \"demo.view\",\n label: \"Demo\",\n icon: \"star\",\n component: (id) => /* Lit html template for the view */ null,\n});\n```\n\nCommon slots: sidebars, panel bottom, toolbars, settings. Canvas modules contributed by extensions use `system.canvases` (`SYSTEM_CANVASES` from `@eclipse-docks/extension-canvas/contribution`)
|
|
2
|
+
var SKILL_default = "---\nname: eclipse-docks-core\ndescription: >-\n Eclipse Docks core runtime from docks/core: workspace files, editors, commands,\n contributions, dialogs, toasts, settings, and events. Use when a canvas or\n extension needs to open files, register UI, run commands, or talk to the shell.\n---\n\n# Eclipse Docks core (`docks/core`)\n\n```js\nimport {\n workspaceService,\n File,\n editorRegistry,\n commandRegistry,\n registerAll,\n contributionRegistry,\n publish,\n subscribe,\n unsubscribe,\n appSettings,\n toastInfo,\n toastError,\n confirmDialog,\n promptDialog,\n filebrowserDialog,\n} from \"docks/core\";\n```\n\nAlias: `@eclipse-docks/core`. Subpaths map to the same bridges, e.g. `docks/core/parts`, `docks/core/widgets`, `docks/core/externals/lit`.\n\n## Workspace\n\n```js\nconst workspace = workspaceService.getWorkspaceSync() ?? await workspaceService.getWorkspace();\nconst resource = await workspace.getResource(\"folder/note.md\");\nif (resource instanceof File) {\n const text = await resource.getContents();\n await resource.saveContents(text);\n}\n```\n\n- Paths are workspace-relative (root-prefixed in the composite workspace).\n- Create with `getResource(path, { create: true })` when the API allows.\n- Canvases can also open a path via `this.canvasHost.openFile(path)` without importing core.\n\n## Editors\n\n```js\nawait editorRegistry.loadEditor(file); // default handler\nawait editorRegistry.loadEditor(file, \"system.canvas-editor\");\n```\n\n`EditorInput` objects carry `title`, `key`, `data`, `component`, optional `state`. Prefer opening a `File` when one exists.\n\n## Commands\n\n```js\nregisterAll({\n command: {\n id: \"demo.ping\",\n name: \"Ping\",\n description: \"Demo command\",\n parameters: [],\n },\n handler: {\n execute: async () => \"pong\",\n },\n});\n\nawait commandRegistry.execute(\"demo.ping\", {});\n```\n\nCommands registered this way can surface as AI tools when the cognitive runtime refreshes command tools.\n\n## Contributions\n\n```js\nimport { SIDEBAR_MAIN, TOOLBAR_MAIN_RIGHT } from \"docks/core\";\n\ncontributionRegistry.registerContribution(SIDEBAR_MAIN, {\n name: \"demo.view\",\n label: \"Demo\",\n icon: \"star\",\n component: (id) => /* Lit html template for the view */ null,\n});\n```\n\nCommon slots: sidebars, panel bottom, toolbars, settings. Canvas modules contributed by extensions use `system.canvases` (`SYSTEM_CANVASES` from `@eclipse-docks/extension-canvas/contribution`). Each contribution sets a unique `settingsKey` for its `canvasHost` state. `load()` returns `{ default: CustomElementConstructor }`, or `source` is the canvas module text and the preview compiles it. A contributed canvas is not editable and opens without a toolbar.\n\n## Dialogs & toasts\n\n```js\nconst ok = await confirmDialog(\"Replace file?\");\nconst name = await promptDialog(\"Name?\");\ntoastInfo(\"Saved\");\ntoastError(\"Failed\");\n```\n\n`filebrowserDialog` for folder/file picks; `formDialog` for multi-field forms. Prefer these over ad-hoc `window.prompt` in shell-integrated code.\n\n## Settings & events\n\n```js\nawait appSettings.set(\"demo.flag\", true);\nconst flag = await appSettings.get(\"demo.flag\");\n\nconst id = subscribe(\"topic.name\", (event) => { /* … */ });\npublish(\"topic.name\", { detail: 1 });\nunsubscribe(id);\n```\n\n## Logging\n\n```js\nimport { createLogger } from \"docks/core\";\nconst log = createLogger(\"demo\");\nlog.info(\"ready\");\n```\n\n## Canvas notes\n\n- Host persistence for a workspace `.canvas.js` is `canvasHost.getState` / `setState`, not `appSettings`, unless you intentionally share app-wide settings.\n- 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.\n- Keep UI building blocks on `docks/lit` + `docks/webawesome`; use `docks/core` for shell integration.\n\n## Anti-patterns\n\n- Bare filenames at the composite workspace root when a durable root prefix is required\n- Assuming `canvasHost` APIs exist on arbitrary LitElements outside a canvas mount\n- Re-implementing toast/dialog with `alert` when core helpers are available\n";
|
|
3
3
|
//#endregion
|
|
4
4
|
export { SKILL_default as default };
|
|
5
5
|
|