@johnoscott/isometric-engine 0.0.0-stage → 0.10.1
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/EDITOR-GUIDE.md +355 -0
- package/LICENSE +21 -0
- package/LICENSES/ajv.txt +22 -0
- package/LICENSES/lucide-static.txt +43 -0
- package/LICENSES/yaml.txt +13 -0
- package/README.md +62 -2
- package/assets/app.css +269 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +39 -0
- package/assets/skin.css +181 -0
- package/iso-editor.d.ts +4 -0
- package/iso-editor.js +550 -0
- package/iso-render.d.ts +3 -0
- package/iso-render.js +388 -0
- package/iso-systems.d.ts +4 -0
- package/iso-systems.js +389 -0
- package/js/iso-core/compile-schema.js +22 -0
- package/js/iso-core/depth.js +55 -0
- package/js/iso-core/errors.js +65 -0
- package/js/iso-core/glyphs.js +100 -0
- package/js/iso-core/index.js +55 -0
- package/js/iso-core/kernel.js +158 -0
- package/js/iso-core/metrics.json +1 -0
- package/js/iso-core/package.json +6 -0
- package/js/iso-core/parse.js +79 -0
- package/js/iso-core/schema-errors.js +170 -0
- package/js/iso-core/shims/crypto.js +125 -0
- package/js/iso-core/shims/path.js +49 -0
- package/js/iso-core/svg-dom.js +144 -0
- package/js/iso-core/theme.js +48 -0
- package/js/iso-core/vdom.js +48 -0
- package/js/iso-editor/adapter.js +0 -0
- package/js/iso-editor/clipboard.js +152 -0
- package/js/iso-editor/commands.js +173 -0
- package/js/iso-editor/complete.js +55 -0
- package/js/iso-editor/doc.js +182 -0
- package/js/iso-editor/index.js +105 -0
- package/js/iso-editor/model.js +210 -0
- package/js/iso-editor/outline.js +111 -0
- package/js/iso-editor/package.json +6 -0
- package/js/iso-editor/path.js +19 -0
- package/js/iso-editor/providers.js +96 -0
- package/js/iso-editor/schema-nav.js +117 -0
- package/js/iso-editor/splice.js +443 -0
- package/js/iso-editor/storage-keys.js +6 -0
- package/js/iso-editor/ui/actions.js +116 -0
- package/js/iso-editor/ui/canvas-layer.js +0 -0
- package/js/iso-editor/ui/canvas.js +1403 -0
- package/js/iso-editor/ui/clip.js +133 -0
- package/js/iso-editor/ui/dialog.js +26 -0
- package/js/iso-editor/ui/flat-canvas.js +54 -0
- package/js/iso-editor/ui/icons.js +15 -0
- package/js/iso-editor/ui/keys.js +26 -0
- package/js/iso-editor/ui/later.js +28 -0
- package/js/iso-editor/ui/layer.js +11 -0
- package/js/iso-editor/ui/menu.js +105 -0
- package/js/iso-editor/ui/monaco-entry.js +2 -0
- package/js/iso-editor/ui/mount-kit.js +0 -0
- package/js/iso-editor/ui/mount.js +767 -0
- package/js/iso-editor/ui/pane.js +0 -0
- package/js/iso-editor/ui/part.js +0 -0
- package/js/iso-editor/ui/plain-icons.js +34 -0
- package/js/iso-editor/ui/props.js +314 -0
- package/js/iso-editor/ui/scope-css.js +81 -0
- package/js/iso-editor/ui/setup.js +149 -0
- package/js/iso-editor/ui/text.js +323 -0
- package/js/iso-editor/ui/tree.js +728 -0
- package/js/iso-editor/validate.js +33 -0
- package/js/iso-editor/window/protocol.js +8 -0
- package/js/iso-objects/assemble.js +43 -0
- package/js/iso-objects/assets.js +88 -0
- package/js/iso-objects/board.js +162 -0
- package/js/iso-objects/compile.js +60 -0
- package/js/iso-objects/css.js +154 -0
- package/js/iso-objects/flat.js +696 -0
- package/js/iso-objects/focus.js +16 -0
- package/js/iso-objects/geometry.js +76 -0
- package/js/iso-objects/index.js +93 -0
- package/js/iso-objects/kinds.js +12 -0
- package/js/iso-objects/labels.js +325 -0
- package/js/iso-objects/package.json +6 -0
- package/js/iso-objects/place.js +347 -0
- package/js/iso-objects/route.js +461 -0
- package/js/iso-objects/scene.js +350 -0
- package/js/iso-objects/steps.js +246 -0
- package/js/iso-objects/types.js +0 -0
- package/js/iso-systems/catalog.js +42 -0
- package/js/iso-systems/compile.js +34 -0
- package/js/iso-systems/css.js +8 -0
- package/js/iso-systems/index.js +16 -0
- package/js/iso-systems/nodes.js +124 -0
- package/js/iso-systems/package.json +6 -0
- package/js/iso-systems/schema.json +311 -0
- package/js/iso-systems/validate.js +35 -0
- package/js/iso-viewer/bundle.js +20 -0
- package/js/iso-viewer/card-motion.js +228 -0
- package/js/iso-viewer/dom.js +14 -0
- package/js/iso-viewer/dual-view.js +212 -0
- package/js/iso-viewer/flat-view.js +124 -0
- package/js/iso-viewer/history.js +990 -0
- package/js/iso-viewer/index.js +98 -0
- package/js/iso-viewer/morph.js +192 -0
- package/js/iso-viewer/overlay.js +199 -0
- package/js/iso-viewer/package.json +6 -0
- package/js/iso-viewer/page.js +138 -0
- package/js/iso-viewer/player.js +409 -0
- package/js/iso-viewer/still.js +81 -0
- package/js/iso-viewer/timeline-contract.js +14 -0
- package/js/iso-viewer/timeline-engine.js +475 -0
- package/js/iso-viewer/timeline-export.js +36 -0
- package/js/iso-viewer/timeline-scale.js +116 -0
- package/js/iso-viewer/timeline-scope.js +58 -0
- package/js/iso-viewer/timeline-search.js +216 -0
- package/js/iso-viewer/timeline-time.js +55 -0
- package/js/iso-viewer/view-css.js +68 -0
- package/js/iso-viewer/viewport.js +177 -0
- package/package.json +511 -4
- package/src/iso-core/compile-schema.ts +23 -0
- package/src/iso-core/depth.ts +56 -0
- package/src/iso-core/errors.ts +73 -0
- package/src/iso-core/glyphs.ts +108 -0
- package/src/iso-core/index.ts +27 -0
- package/src/iso-core/kernel.ts +163 -0
- package/src/iso-core/metrics.json +1 -0
- package/src/iso-core/package.json +6 -0
- package/src/iso-core/parse.ts +91 -0
- package/src/iso-core/schema-errors.ts +163 -0
- package/src/iso-core/shims/crypto.ts +37 -0
- package/src/iso-core/shims/path.ts +24 -0
- package/src/iso-core/svg-dom.ts +103 -0
- package/src/iso-core/theme.ts +64 -0
- package/src/iso-core/vdom.ts +41 -0
- package/src/iso-editor/adapter.ts +147 -0
- package/src/iso-editor/clipboard.ts +163 -0
- package/src/iso-editor/commands.ts +191 -0
- package/src/iso-editor/complete.ts +73 -0
- package/src/iso-editor/doc.ts +207 -0
- package/src/iso-editor/index.ts +67 -0
- package/src/iso-editor/model.ts +234 -0
- package/src/iso-editor/outline.ts +126 -0
- package/src/iso-editor/package.json +6 -0
- package/src/iso-editor/path.ts +18 -0
- package/src/iso-editor/providers.ts +113 -0
- package/src/iso-editor/schema-nav.ts +129 -0
- package/src/iso-editor/splice.ts +477 -0
- package/src/iso-editor/storage-keys.ts +6 -0
- package/src/iso-editor/ui/actions.ts +119 -0
- package/src/iso-editor/ui/app.css +230 -0
- package/src/iso-editor/ui/canvas-layer.ts +56 -0
- package/src/iso-editor/ui/canvas.ts +1227 -0
- package/src/iso-editor/ui/clip.ts +97 -0
- package/src/iso-editor/ui/dialog.ts +25 -0
- package/src/iso-editor/ui/flat-canvas.ts +51 -0
- package/src/iso-editor/ui/icons.ts +21 -0
- package/src/iso-editor/ui/keys.ts +30 -0
- package/src/iso-editor/ui/later.ts +22 -0
- package/src/iso-editor/ui/layer.ts +7 -0
- package/src/iso-editor/ui/marks.css +39 -0
- package/src/iso-editor/ui/menu.ts +67 -0
- package/src/iso-editor/ui/monaco-entry.ts +6 -0
- package/src/iso-editor/ui/mount-kit.ts +35 -0
- package/src/iso-editor/ui/mount.ts +684 -0
- package/src/iso-editor/ui/pane.ts +45 -0
- package/src/iso-editor/ui/part.ts +45 -0
- package/src/iso-editor/ui/plain-icons.ts +83 -0
- package/src/iso-editor/ui/props.ts +347 -0
- package/src/iso-editor/ui/scope-css.ts +65 -0
- package/src/iso-editor/ui/setup.ts +153 -0
- package/src/iso-editor/ui/skin.css +181 -0
- package/src/iso-editor/ui/text.ts +262 -0
- package/src/iso-editor/ui/tree.ts +657 -0
- package/src/iso-editor/validate.ts +62 -0
- package/src/iso-editor/window/protocol.ts +33 -0
- package/src/iso-objects/assemble.ts +57 -0
- package/src/iso-objects/assets.ts +122 -0
- package/src/iso-objects/board.ts +169 -0
- package/src/iso-objects/compile.ts +76 -0
- package/src/iso-objects/css.ts +163 -0
- package/src/iso-objects/flat.ts +653 -0
- package/src/iso-objects/focus.ts +14 -0
- package/src/iso-objects/geometry.ts +86 -0
- package/src/iso-objects/index.ts +33 -0
- package/src/iso-objects/kinds.ts +56 -0
- package/src/iso-objects/labels.ts +310 -0
- package/src/iso-objects/package.json +6 -0
- package/src/iso-objects/place.ts +318 -0
- package/src/iso-objects/route.ts +444 -0
- package/src/iso-objects/scene.ts +376 -0
- package/src/iso-objects/steps.ts +234 -0
- package/src/iso-objects/types.ts +68 -0
- package/src/iso-systems/catalog.ts +31 -0
- package/src/iso-systems/compile.ts +39 -0
- package/src/iso-systems/css.ts +9 -0
- package/src/iso-systems/index.ts +12 -0
- package/src/iso-systems/nodes.ts +126 -0
- package/src/iso-systems/package.json +6 -0
- package/src/iso-systems/schema.json +311 -0
- package/src/iso-systems/validate.ts +34 -0
- package/src/iso-viewer/bundle.ts +15 -0
- package/src/iso-viewer/card-motion.ts +237 -0
- package/src/iso-viewer/dom.ts +13 -0
- package/src/iso-viewer/dual-view.ts +212 -0
- package/src/iso-viewer/flat-view.ts +127 -0
- package/src/iso-viewer/history.ts +781 -0
- package/src/iso-viewer/index.ts +40 -0
- package/src/iso-viewer/morph.ts +191 -0
- package/src/iso-viewer/overlay.ts +212 -0
- package/src/iso-viewer/package.json +6 -0
- package/src/iso-viewer/page.ts +150 -0
- package/src/iso-viewer/player.ts +321 -0
- package/src/iso-viewer/still.ts +74 -0
- package/src/iso-viewer/timeline-contract.ts +342 -0
- package/src/iso-viewer/timeline-engine.ts +420 -0
- package/src/iso-viewer/timeline-export.ts +31 -0
- package/src/iso-viewer/timeline-scale.ts +129 -0
- package/src/iso-viewer/timeline-scope.ts +56 -0
- package/src/iso-viewer/timeline-search.ts +198 -0
- package/src/iso-viewer/timeline-time.ts +54 -0
- package/src/iso-viewer/view-css.ts +59 -0
- package/src/iso-viewer/viewport.ts +142 -0
- package/types/iso-core/compile-schema.d.ts +11 -0
- package/types/iso-core/depth.d.ts +6 -0
- package/types/iso-core/errors.d.ts +24 -0
- package/types/iso-core/glyphs.d.ts +19 -0
- package/types/iso-core/index.d.ts +17 -0
- package/types/iso-core/kernel.d.ts +130 -0
- package/types/iso-core/metrics.json +1 -0
- package/types/iso-core/parse.d.ts +18 -0
- package/types/iso-core/schema-errors.d.ts +14 -0
- package/types/iso-core/shims/crypto.d.ts +9 -0
- package/types/iso-core/svg-dom.d.ts +15 -0
- package/types/iso-core/theme.d.ts +38 -0
- package/types/iso-core/vdom.d.ts +26 -0
- package/types/iso-editor/adapter.d.ts +178 -0
- package/types/iso-editor/clipboard.d.ts +23 -0
- package/types/iso-editor/commands.d.ts +32 -0
- package/types/iso-editor/complete.d.ts +25 -0
- package/types/iso-editor/doc.d.ts +50 -0
- package/types/iso-editor/index.d.ts +57 -0
- package/types/iso-editor/model.d.ts +96 -0
- package/types/iso-editor/outline.d.ts +28 -0
- package/types/iso-editor/path.d.ts +7 -0
- package/types/iso-editor/providers.d.ts +43 -0
- package/types/iso-editor/schema-nav.d.ts +34 -0
- package/types/iso-editor/splice.d.ts +53 -0
- package/types/iso-editor/storage-keys.d.ts +5 -0
- package/types/iso-editor/ui/actions.d.ts +23 -0
- package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
- package/types/iso-editor/ui/canvas.d.ts +307 -0
- package/types/iso-editor/ui/clip.d.ts +14 -0
- package/types/iso-editor/ui/dialog.d.ts +7 -0
- package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
- package/types/iso-editor/ui/icons.d.ts +5 -0
- package/types/iso-editor/ui/keys.d.ts +7 -0
- package/types/iso-editor/ui/later.d.ts +12 -0
- package/types/iso-editor/ui/layer.d.ts +2 -0
- package/types/iso-editor/ui/menu.d.ts +21 -0
- package/types/iso-editor/ui/mount-kit.d.ts +31 -0
- package/types/iso-editor/ui/mount.d.ts +146 -0
- package/types/iso-editor/ui/pane.d.ts +60 -0
- package/types/iso-editor/ui/part.d.ts +40 -0
- package/types/iso-editor/ui/plain-icons.d.ts +10 -0
- package/types/iso-editor/ui/props.d.ts +57 -0
- package/types/iso-editor/ui/scope-css.d.ts +5 -0
- package/types/iso-editor/ui/setup.d.ts +49 -0
- package/types/iso-editor/ui/text.d.ts +19 -0
- package/types/iso-editor/ui/tree.d.ts +100 -0
- package/types/iso-editor/validate.d.ts +36 -0
- package/types/iso-editor/window/protocol.d.ts +60 -0
- package/types/iso-objects/assemble.d.ts +35 -0
- package/types/iso-objects/assets.d.ts +49 -0
- package/types/iso-objects/board.d.ts +36 -0
- package/types/iso-objects/compile.d.ts +35 -0
- package/types/iso-objects/css.d.ts +16 -0
- package/types/iso-objects/flat.d.ts +130 -0
- package/types/iso-objects/focus.d.ts +1 -0
- package/types/iso-objects/geometry.d.ts +59 -0
- package/types/iso-objects/index.d.ts +26 -0
- package/types/iso-objects/kinds.d.ts +53 -0
- package/types/iso-objects/labels.d.ts +92 -0
- package/types/iso-objects/place.d.ts +25 -0
- package/types/iso-objects/route.d.ts +67 -0
- package/types/iso-objects/scene.d.ts +63 -0
- package/types/iso-objects/steps.d.ts +90 -0
- package/types/iso-objects/types.d.ts +140 -0
- package/types/iso-systems/catalog.d.ts +4 -0
- package/types/iso-systems/compile.d.ts +6 -0
- package/types/iso-systems/css.d.ts +3 -0
- package/types/iso-systems/index.d.ts +5 -0
- package/types/iso-systems/nodes.d.ts +3 -0
- package/types/iso-viewer/card-motion.d.ts +56 -0
- package/types/iso-viewer/dom.d.ts +1 -0
- package/types/iso-viewer/dual-view.d.ts +44 -0
- package/types/iso-viewer/flat-view.d.ts +25 -0
- package/types/iso-viewer/history.d.ts +91 -0
- package/types/iso-viewer/index.d.ts +31 -0
- package/types/iso-viewer/morph.d.ts +28 -0
- package/types/iso-viewer/overlay.d.ts +135 -0
- package/types/iso-viewer/page.d.ts +13 -0
- package/types/iso-viewer/still.d.ts +26 -0
- package/types/iso-viewer/timeline-contract.d.ts +345 -0
- package/types/iso-viewer/timeline-engine.d.ts +20 -0
- package/types/iso-viewer/timeline-export.d.ts +5 -0
- package/types/iso-viewer/timeline-scale.d.ts +44 -0
- package/types/iso-viewer/timeline-scope.d.ts +33 -0
- package/types/iso-viewer/timeline-search.d.ts +52 -0
- package/types/iso-viewer/timeline-time.d.ts +8 -0
- package/types/iso-viewer/view-css.d.ts +7 -0
- package/types/iso-viewer/viewport.d.ts +50 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// What the page asks of its text pane (Monaco: text.ts). A pane binds to the one EditorModel: typing goes to the model
|
|
2
|
+
// once, tagged with the pane; every other change (the tree, the canvas, undo) comes back from the model, and never
|
|
3
|
+
// returns to it. The interface outlived a second pane (CodeMirror 6, tried in E8: tag editor-codemirror-e8).
|
|
4
|
+
|
|
5
|
+
import type { Problem } from '../validate.ts';
|
|
6
|
+
import type { Path } from '../path.ts';
|
|
7
|
+
import type { EditorDoc } from '../doc.ts';
|
|
8
|
+
import type { Item } from '../complete.ts';
|
|
9
|
+
|
|
10
|
+
/** A text selection as offsets into the text, the form the model keeps for undo (any pane can put it back). */
|
|
11
|
+
export type TextSel = { anchor: number; head: number }[];
|
|
12
|
+
|
|
13
|
+
export interface TextPane {
|
|
14
|
+
id: 'monaco';
|
|
15
|
+
el: HTMLElement;
|
|
16
|
+
setProblems(ps: Problem[]): void;
|
|
17
|
+
/** the path at the caret, for the status bar */
|
|
18
|
+
pathAtCaret(): Path;
|
|
19
|
+
/** mark paths in the text (and move the caret to the first, unless this pane has the focus) */
|
|
20
|
+
showSelection(paths: Path[], move: boolean): void;
|
|
21
|
+
/** put the caret at a path, scroll to it, and focus the pane */
|
|
22
|
+
goTo(path: Path): void;
|
|
23
|
+
/** put the caret at an offset, scroll to it, and focus the pane */
|
|
24
|
+
goToOffset(offset: number): void;
|
|
25
|
+
/** the caret, 1-based, for the status bar */
|
|
26
|
+
caret(): { line: number; col: number } | undefined;
|
|
27
|
+
/** the caret moved (in this pane) */
|
|
28
|
+
onCaret(fn: () => void): void;
|
|
29
|
+
hasFocus(): boolean;
|
|
30
|
+
focus(): void;
|
|
31
|
+
setTheme(dark: boolean): void;
|
|
32
|
+
/** times the pane and the model disagreed and the pane was put right (should stay 0: the tests check) */
|
|
33
|
+
resyncs(): number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** what a pane asks of the domain, by offset into the text (the editor core's providers, given an adapter) */
|
|
37
|
+
export interface TextServices {
|
|
38
|
+
docFor(text: string): EditorDoc;
|
|
39
|
+
completionAt(d: EditorDoc, offset: number): { from: number; items: Item[] };
|
|
40
|
+
hoverAt(d: EditorDoc, offset: number): { from: number; to: number; parts: string[] } | null;
|
|
41
|
+
definitionAt(d: EditorDoc, offset: number): { from: number; to: number } | { open: string } | null;
|
|
42
|
+
rangeOfPath(d: EditorDoc, p: Path): [number, number] | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface PaneOpts { services: TextServices; onOpen?(file: string): void; onSave?(): void; onSaveAs?(): void }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// An editor part: what a domain adds to the mounted editor beside its views (a host's state drawn over them, a
|
|
2
|
+
// simulator, what waits for a person). It is given what the editor has (PartCtx), and gives what is true now about an
|
|
3
|
+
// object (the properties panel's Now), rows before the problems (and how many, and whether they open the list), a
|
|
4
|
+
// start once the editor is up, a dispose, and its own calls. The editor carries none of a part's code.
|
|
5
|
+
|
|
6
|
+
import type { EditorModel } from '../model.ts';
|
|
7
|
+
|
|
8
|
+
/** what the editor gives a part */
|
|
9
|
+
export interface PartCtx {
|
|
10
|
+
root: HTMLElement;
|
|
11
|
+
/** one of the shell's elements, by its id (without the prefix) */
|
|
12
|
+
byId<T extends HTMLElement = HTMLElement>(id: string): T;
|
|
13
|
+
doc: EditorModel;
|
|
14
|
+
store: { get(k: string): string | null; set(k: string, v: string | null): void };
|
|
15
|
+
note(t: string, tone?: 'info' | 'warn' | 'bad'): void;
|
|
16
|
+
/** the editor shows the file for this mount only (nothing it shows is kept) */
|
|
17
|
+
watch: boolean;
|
|
18
|
+
/** a listener, removed when the editor is disposed */
|
|
19
|
+
on(t: EventTarget, ev: string, fn: (e: never) => void): void;
|
|
20
|
+
disposed(): boolean;
|
|
21
|
+
paintProblems(): void;
|
|
22
|
+
paintProps(): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** what waits for a person: rows put before the file's problems */
|
|
26
|
+
export interface Attention {
|
|
27
|
+
/** how many (they count as problems seen) */
|
|
28
|
+
count: number;
|
|
29
|
+
/** how many open the list when they appear */
|
|
30
|
+
opens: number;
|
|
31
|
+
/** the list keeps still (neither opens nor closes for these) */
|
|
32
|
+
still: boolean;
|
|
33
|
+
rows: Node[];
|
|
34
|
+
/** their words in the list's label */
|
|
35
|
+
label: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** what a part gives the editor; A: its calls */
|
|
39
|
+
export interface EditorPart<A extends object> {
|
|
40
|
+
now?(ptr: string): unknown;
|
|
41
|
+
attention?(): Attention | undefined;
|
|
42
|
+
start?(): void;
|
|
43
|
+
dispose?(): void;
|
|
44
|
+
api: A;
|
|
45
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// GENERATED by scripts/plain-icons.ts from lucide-static v1.48.0 (the vendored copy the script names): do not edit.
|
|
2
|
+
// L3's own icons: one <symbol id="se-i-NAME"> for every name the editor's shell and views use (PLAIN_ICONS), so a
|
|
3
|
+
// host with no sprite of its own still has them. setupFor gives PLAIN_SPRITE as the setup's sprite by default.
|
|
4
|
+
//
|
|
5
|
+
// Lucide's licence (the symbols below are Lucide's):
|
|
6
|
+
// ISC License
|
|
7
|
+
//
|
|
8
|
+
// Copyright (c) 2026 Lucide Icons and Contributors
|
|
9
|
+
//
|
|
10
|
+
// Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
// purpose with or without fee is hereby granted, provided that the above
|
|
12
|
+
// copyright notice and this permission notice appear in all copies.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
15
|
+
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
17
|
+
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
18
|
+
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
19
|
+
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
20
|
+
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
+
//
|
|
22
|
+
// ---
|
|
23
|
+
//
|
|
24
|
+
// The following Lucide icons are derived from the Feather project:
|
|
25
|
+
//
|
|
26
|
+
// airplay, alert-circle, alert-octagon, alert-triangle, aperture, arrow-down-circle, arrow-down-left, arrow-down-right, arrow-down, arrow-left-circle, arrow-left, arrow-right-circle, arrow-right, arrow-up-circle, arrow-up-left, arrow-up-right, arrow-up, at-sign, calendar, cast, check, chevron-down, chevron-left, chevron-right, chevron-up, chevrons-down, chevrons-left, chevrons-right, chevrons-up, circle, clipboard, clock, code, columns, command, compass, corner-down-left, corner-down-right, corner-left-down, corner-left-up, corner-right-down, corner-right-up, corner-up-left, corner-up-right, crosshair, database, divide-circle, divide-square, dollar-sign, download, external-link, feather, frown, hash, headphones, help-circle, info, italic, key, layout, life-buoy, link-2, link, loader, lock, log-in, log-out, maximize, meh, minimize, minimize-2, minus-circle, minus-square, minus, monitor, moon, more-horizontal, more-vertical, move, music, navigation-2, navigation, octagon, pause-circle, percent, plus-circle, plus-square, plus, power, radio, rss, search, server, share, shopping-bag, sidebar, smartphone, smile, square, table-2, tablet, target, terminal, trash-2, trash, triangle, tv, type, upload, x-circle, x-octagon, x-square, x, zoom-in, zoom-out
|
|
27
|
+
//
|
|
28
|
+
// The MIT License (MIT) (for the icons listed above)
|
|
29
|
+
//
|
|
30
|
+
// Copyright (c) 2013-present Cole Bemis
|
|
31
|
+
//
|
|
32
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
33
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
34
|
+
// in the Software without restriction, including without limitation the rights
|
|
35
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
36
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
37
|
+
// furnished to do so, subject to the following conditions:
|
|
38
|
+
//
|
|
39
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
40
|
+
// copies or substantial portions of the Software.
|
|
41
|
+
//
|
|
42
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
|
+
// SOFTWARE.
|
|
49
|
+
|
|
50
|
+
/** each icon's SVG body, by name (Lucide, ISC) */
|
|
51
|
+
export const PLAIN_ICON_SVG: Record<string, string> = {
|
|
52
|
+
'arrow-up-right': '<path d="M7 7h10v10" /> <path d="M7 17 17 7" />',
|
|
53
|
+
'box': '<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z" /> <path d="m3.3 7 8.7 5 8.7-5" /> <path d="M12 22V12" />',
|
|
54
|
+
'chevron-down': '<path d="m6 9 6 6 6-6" />',
|
|
55
|
+
'chevron-right': '<path d="m9 18 6-6-6-6" />',
|
|
56
|
+
'circle-dot': '<circle cx="12" cy="12" r="1" /> <circle cx="12" cy="12" r="10" />',
|
|
57
|
+
'circle-x': '<circle cx="12" cy="12" r="10" /> <path d="m15 9-6 6" /> <path d="m9 9 6 6" />',
|
|
58
|
+
'clipboard': '<rect width="8" height="4" x="8" y="2" rx="1" ry="1" /> <path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" />',
|
|
59
|
+
'clipboard-paste': '<path d="M11 14h10" /> <path d="M16 4h2a2 2 0 0 1 2 2v1.344" /> <path d="m17 18 4-4-4-4" /> <path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113" /> <rect x="8" y="2" width="8" height="4" rx="1" />',
|
|
60
|
+
'code-xml': '<path d="m18 16 4-4-4-4" /> <path d="m6 8-4 4 4 4" /> <path d="m14.5 4-5 16" />',
|
|
61
|
+
'copy': '<rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />',
|
|
62
|
+
'layers': '<path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z" /> <path d="M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12" /> <path d="M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17" />',
|
|
63
|
+
'link': '<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" /> <path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" />',
|
|
64
|
+
'list': '<path d="M3 5h.01" /> <path d="M3 12h.01" /> <path d="M3 19h.01" /> <path d="M8 5h13" /> <path d="M8 12h13" /> <path d="M8 19h13" />',
|
|
65
|
+
'list-tree': '<path d="M8 5h13" /> <path d="M13 12h8" /> <path d="M13 19h8" /> <path d="M3 10a2 2 0 0 0 2 2h3" /> <path d="M3 5v12a2 2 0 0 0 2 2h3" />',
|
|
66
|
+
'panel-right': '<rect width="18" height="18" x="3" y="3" rx="2" /> <path d="M15 3v18" />',
|
|
67
|
+
'pencil': '<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" /> <path d="m15 5 4 4" />',
|
|
68
|
+
'plus': '<path d="M5 12h14" /> <path d="M12 5v14" />',
|
|
69
|
+
'rotate-ccw': '<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /> <path d="M3 3v5h5" />',
|
|
70
|
+
'trash-2': '<path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />',
|
|
71
|
+
'triangle-alert': '<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" /> <path d="M12 9v4" /> <path d="M12 17h.01" />',
|
|
72
|
+
'x': '<path d="M18 6 6 18" /> <path d="m6 6 12 12" />',
|
|
73
|
+
};
|
|
74
|
+
/** the names L3 uses */
|
|
75
|
+
export const PLAIN_ICONS: readonly string[] = Object.keys(PLAIN_ICON_SVG);
|
|
76
|
+
/** symbols of a sprite: one per icon, with the id icon() and the shell's markup use */
|
|
77
|
+
export const iconSymbols = (svgs: Record<string, string>): string =>
|
|
78
|
+
Object.entries(svgs).map(([n, body]) => `<symbol id="se-i-${n}" viewBox="0 0 24 24">${body}</symbol>`).join('');
|
|
79
|
+
/** a sprite of symbols, as the setup's sprite (mountEditor puts it in the editor's root) */
|
|
80
|
+
export const spriteOf = (symbols: string): string =>
|
|
81
|
+
`<svg xmlns="http://www.w3.org/2000/svg" class="sprite" aria-hidden="true" focusable="false">${symbols}</svg>`;
|
|
82
|
+
/** L3's sprite: every icon it uses */
|
|
83
|
+
export const PLAIN_SPRITE = spriteOf(iconSymbols(PLAIN_ICON_SVG));
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
// The properties panel: a form, generated from the schema, for what is selected. One object (or a key inside one):
|
|
2
|
+
// each key the schema allows there, written or not. Several objects of one kind: their common keys, where an edit
|
|
3
|
+
// applies to all of them as one command. Enums and references are pickers; lists of references are chips; a long text
|
|
4
|
+
// is a text area; anything more structured is edited as YAML. Keys an object inherits (the kit says which, and from
|
|
5
|
+
// where) show greyed with where they come from: "Override" writes them here, "Reset" removes this file's own value so
|
|
6
|
+
// the inherited one applies again.
|
|
7
|
+
|
|
8
|
+
import { later, isTyping } from './later.ts';
|
|
9
|
+
import { parse as parseYaml } from 'yaml';
|
|
10
|
+
import { h, icon } from './icons.ts';
|
|
11
|
+
import type { EditorModel, Command } from '../model.ts';
|
|
12
|
+
import type { SchemaNav, KeyInfo } from '../schema-nav.ts';
|
|
13
|
+
import type { Problem } from '../validate.ts';
|
|
14
|
+
import type { Commands } from '../commands.ts';
|
|
15
|
+
import type { ObjectKindInfo, ObjectRef, RefSlot } from '../adapter.ts';
|
|
16
|
+
import { composite, run, type Actions } from './actions.ts';
|
|
17
|
+
import { flowText } from '../splice.ts';
|
|
18
|
+
import { fromPointer, toPointer, type Path } from '../path.ts';
|
|
19
|
+
|
|
20
|
+
/** what the panel shows of the domain */
|
|
21
|
+
export interface PropsUi {
|
|
22
|
+
/** keys worth showing even when unset */
|
|
23
|
+
important(kind: string, value: Record<string, unknown>, external: boolean): string[];
|
|
24
|
+
/** an object that exists elsewhere (only its reference keys apply) */
|
|
25
|
+
isExternal(value: unknown): boolean;
|
|
26
|
+
/** a key one object inherits (its value, and where from), given the domain's reading; and every key it inherits */
|
|
27
|
+
inherited?(path: Path, key: string, read: unknown): { value: unknown; from?: string } | undefined;
|
|
28
|
+
inheritedKeys?(path: Path, read: unknown): string[];
|
|
29
|
+
/** where inherited values come from, when the reading doesn't say */
|
|
30
|
+
inheritedFrom: string;
|
|
31
|
+
/** what is true now about an object, as rows (undefined: not shown; empty: not known) */
|
|
32
|
+
facts?(now: unknown): { term: string; def: string; cls?: string }[] | undefined;
|
|
33
|
+
/** an x- key's words */
|
|
34
|
+
extensionDoc: string;
|
|
35
|
+
/** the root's title, and its words in a list */
|
|
36
|
+
rootTitle: string; rootItem: string;
|
|
37
|
+
}
|
|
38
|
+
/** what the panel is given of the domain */
|
|
39
|
+
export interface PropsKit {
|
|
40
|
+
commands: Pick<Commands, 'setCmd' | 'deleteCmd' | 'insertItemCmd' | 'referencesTo' | 'describe'>;
|
|
41
|
+
actions: Pick<Actions, 'deletePaths' | 'renameDialog'>;
|
|
42
|
+
slotAt(ptr: string): RefSlot | undefined;
|
|
43
|
+
objectOf(ptr: string): ObjectRef | undefined;
|
|
44
|
+
kinds: ObjectKindInfo[];
|
|
45
|
+
ui: PropsUi;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type Raw = Record<string, unknown>;
|
|
49
|
+
const getIn = (o: unknown, p: Path) => p.reduce<unknown>((x, k) => (x && typeof x === 'object' ? (x as Raw)[k as string] : undefined), o);
|
|
50
|
+
const isMap = (v: unknown): v is Raw => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
51
|
+
const MIXED = Symbol('mixed');
|
|
52
|
+
|
|
53
|
+
export interface PropsOpts {
|
|
54
|
+
kit: PropsKit;
|
|
55
|
+
nav(): SchemaNav;
|
|
56
|
+
problems(): Problem[];
|
|
57
|
+
/** the domain's reading of the file (the kit's inherited() reads it) */
|
|
58
|
+
read(): unknown;
|
|
59
|
+
note(t: string, tone?: 'info' | 'warn' | 'bad'): void;
|
|
60
|
+
showInText(p: Path): void;
|
|
61
|
+
/** while the host's state is shown, what is true now about an object (the kit's facts() reads it); undefined while not */
|
|
62
|
+
now?(ptr: string): unknown;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function propsPanel(body: HTMLElement, doc: EditorModel, opts: PropsOpts) {
|
|
66
|
+
let pendingFocus: string | undefined;
|
|
67
|
+
let focusInput = false;
|
|
68
|
+
const K = opts.kit, ui = K.ui;
|
|
69
|
+
const { setCmd, deleteCmd, insertItemCmd, referencesTo, describe } = K.commands;
|
|
70
|
+
const { deletePaths, renameDialog } = K.actions;
|
|
71
|
+
const kindOf = (k: string) => K.kinds.find(x => x.kind === k);
|
|
72
|
+
const singular = (k: string) => kindOf(k)?.singular ?? 'item';
|
|
73
|
+
|
|
74
|
+
const names = (s: string) => Object.keys((getIn(doc.goodDoc.data, kindOf(s)?.section ?? []) ?? {}) as Raw).filter(k => !k.startsWith('x-'));
|
|
75
|
+
const apply = (c: Command) => run(doc, c, 'props', opts.note);
|
|
76
|
+
|
|
77
|
+
function paint() {
|
|
78
|
+
// never repaint under a field being typed in; it repaints when the field is left
|
|
79
|
+
if (body.contains(document.activeElement) && (document.activeElement as HTMLElement).matches('input, textarea')) return;
|
|
80
|
+
body.replaceChildren();
|
|
81
|
+
const sel = doc.selection;
|
|
82
|
+
if (!sel.length) { body.append(h('p', { class: 'hint' }, 'Select something in the canvas, the tree or the text.')); return; }
|
|
83
|
+
const res = sel.map(p => K.objectOf(toPointer(p)));
|
|
84
|
+
// several: their common keys, if they are all resources of one kind
|
|
85
|
+
if (sel.length > 1) {
|
|
86
|
+
const kinds = new Set(res.map(r => r?.kind));
|
|
87
|
+
if (kinds.size === 1 && res.every(r => r && r.path === toPointer(fromPointer(r.path)))) {
|
|
88
|
+
const paths = [...new Set(res.map(r => r!.path))].map(fromPointer);
|
|
89
|
+
body.append(h('div', { class: 'sel-title' }, `${paths.length} ${singular(res[0]!.kind)}s`), h('div', { class: 'sel-path' }, paths.map(p => p[p.length - 1]).join(', ')));
|
|
90
|
+
form(paths, res[0]!.kind);
|
|
91
|
+
} else {
|
|
92
|
+
body.append(h('div', { class: 'sel-title' }, `${sel.length} items`), h('ul', { class: 'plain' }, ...sel.map(p => h('li', null, h('code', null, p.join('.') || ui.rootItem)))));
|
|
93
|
+
}
|
|
94
|
+
deleteButton();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const p = sel[0];
|
|
98
|
+
const r = res[0];
|
|
99
|
+
const target = r ? fromPointer(r.path) : p.length ? p : [];
|
|
100
|
+
// the root, a section, or a setting outside objects: its own keys
|
|
101
|
+
if (!r) { settings(p); return; }
|
|
102
|
+
const head = h('div', { class: 'sel-headrow' }, h('div', { class: 'sel-title' }, describe(target)));
|
|
103
|
+
const rn = h('button', { type: 'button', class: 'btn sm quiet icon-only', 'aria-label': `Rename ${describe(target)}`, title: 'Rename (F2)' }, icon('pencil'));
|
|
104
|
+
rn.addEventListener('click', () => renameDialog(doc, target, 'props', opts.note));
|
|
105
|
+
head.append(rn);
|
|
106
|
+
body.append(head);
|
|
107
|
+
if (toPointer(p) !== r.path) pendingFocus = toPointer(p);
|
|
108
|
+
form([target], r.kind);
|
|
109
|
+
uses(r.kind, r.name);
|
|
110
|
+
problemsFor(r.path);
|
|
111
|
+
deleteButton();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** the form for one or more objects of a kind */
|
|
115
|
+
function form(paths: Path[], section: string) {
|
|
116
|
+
const nav = opts.nav();
|
|
117
|
+
const data = doc.goodDoc.data;
|
|
118
|
+
const values = paths.map(p => (getIn(data, p) ?? {}) as Raw);
|
|
119
|
+
const present = values[0] && isMap(values[0]) ? values[0] : {};
|
|
120
|
+
const ext = values.some(v => ui.isExternal(v));
|
|
121
|
+
// the keys: the schema's for this kind (only what fits beside external:, or not), written ones first
|
|
122
|
+
const keys = nav.keys(paths[0], ext ? { external: true } : present);
|
|
123
|
+
// written keys in the file's order (of the first selected), then the rest in the schema's
|
|
124
|
+
const order = Object.keys(present);
|
|
125
|
+
const written = keys.filter(k => values.some(v => isMap(v) && k.name in v)).sort((a, b) => (order.indexOf(a.name) + 1 || 999) - (order.indexOf(b.name) + 1 || 999));
|
|
126
|
+
const read = opts.read();
|
|
127
|
+
// shown: what is written, what matters even when unset, and what it inherits; the rest is one click away
|
|
128
|
+
const shown = new Set([...written.map(k => k.name), ...ui.important(section, values[0] ?? {}, ext), ...(paths.length === 1 && read !== undefined && ui.inheritedKeys ? ui.inheritedKeys(paths[0], read) : [])]);
|
|
129
|
+
const rest = keys.filter(k => !written.includes(k) && shown.has(k.name));
|
|
130
|
+
const more = keys.filter(k => !shown.has(k.name));
|
|
131
|
+
const sec = h('div', { class: 'props' });
|
|
132
|
+
for (const k of [...written, ...rest]) sec.append(field(paths, section, k, values, read));
|
|
133
|
+
if (more.length && doc.doc.ok) {
|
|
134
|
+
const add = h('select', { class: 'padd', 'aria-label': 'Add a property' }, h('option', { value: '' }, '+ Add property'), ...more.map(k => h('option', { value: k.name, title: (k.doc ?? '').replace(/`/g, '') }, k.name)));
|
|
135
|
+
add.addEventListener('change', () => {
|
|
136
|
+
const name = add.value;
|
|
137
|
+
if (!name) return;
|
|
138
|
+
const v = nav.defaultFor([...paths[0], name]);
|
|
139
|
+
pendingFocus = toPointer([...paths[0], name]);
|
|
140
|
+
focusInput = true;
|
|
141
|
+
apply(paths.length === 1 ? setCmd([...paths[0], name], v, `Add ${describe([...paths[0], name])}`) : composite(`Add ${name} to ${paths.length} ${singular(section)}s`, paths.map(p => setCmd([...p, name], v))));
|
|
142
|
+
});
|
|
143
|
+
sec.append(add);
|
|
144
|
+
}
|
|
145
|
+
// keys written that the schema doesn't know (x-*, typos): shown, editable as YAML
|
|
146
|
+
const known = new Set(keys.map(k => k.name));
|
|
147
|
+
for (const name of new Set(values.flatMap(v => (isMap(v) ? Object.keys(v) : [])))) {
|
|
148
|
+
if (!known.has(name)) sec.append(field(paths, section, { name, shape: 'scalar', enumValues: [], examples: [], doc: name.startsWith('x-') ? ui.extensionDoc : 'Not a key the schema knows.' }, values, read));
|
|
149
|
+
}
|
|
150
|
+
body.append(sec);
|
|
151
|
+
if (pendingFocus) {
|
|
152
|
+
const f = sec.querySelector<HTMLElement>(`[data-path="${CSS.escape(pendingFocus)}"]`);
|
|
153
|
+
f?.classList.add('focus-row');
|
|
154
|
+
f?.scrollIntoView({ block: 'nearest' });
|
|
155
|
+
// the field takes the focus only after an add or an override here, never because something else selected it
|
|
156
|
+
if (focusInput) (f?.querySelector('input, select, textarea') as HTMLElement | null)?.focus({ preventScroll: true });
|
|
157
|
+
pendingFocus = undefined;
|
|
158
|
+
focusInput = false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function field(paths: Path[], section: string, k: KeyInfo, values: Raw[], read: unknown): HTMLElement {
|
|
163
|
+
const nav = opts.nav();
|
|
164
|
+
const own = values.map(v => (isMap(v) ? v[k.name] : undefined));
|
|
165
|
+
const same = own.every(x => JSON.stringify(x) === JSON.stringify(own[0]));
|
|
166
|
+
const value: unknown = same ? own[0] : MIXED;
|
|
167
|
+
const isWritten = own.some(x => x !== undefined);
|
|
168
|
+
// inherited (the kit says), with where it comes from
|
|
169
|
+
const inherited = section && paths.length === 1 && read !== undefined ? ui.inherited?.(paths[0], k.name, read) : undefined;
|
|
170
|
+
const ptrs = paths.map(p => toPointer([...p, k.name]));
|
|
171
|
+
const row = h('div', { class: `prow${isWritten ? '' : ' unset'}`, 'data-path': ptrs[0] });
|
|
172
|
+
const label = h('label', { class: 'plabel', title: k.doc?.replace(/`/g, '') ?? '' }, k.name);
|
|
173
|
+
const id = `pf-${Math.random().toString(36).slice(2, 8)}`;
|
|
174
|
+
label.setAttribute('for', id);
|
|
175
|
+
row.append(label);
|
|
176
|
+
const set = (v: unknown, lbl?: string) => apply(paths.length === 1 ? setCmd([...paths[0], k.name], v, lbl) : composite(lbl ?? `Set ${k.name} on ${paths.length} ${singular(section)}s`, paths.map(p => setCmd([...p, k.name], v))));
|
|
177
|
+
const unset = () => {
|
|
178
|
+
const ps = paths.filter((_, i) => own[i] !== undefined);
|
|
179
|
+
apply(ps.length === 1 ? { ...deleteCmd([...ps[0], k.name]), label: `Remove ${describe([...ps[0], k.name])}` } : composite(`Remove ${k.name} from ${ps.length} ${singular(section)}s`, ps.map(p => deleteCmd([...p, k.name]))));
|
|
180
|
+
};
|
|
181
|
+
const slot = K.slotAt(toPointer([...paths[0], k.name]));
|
|
182
|
+
const itemSlot = K.slotAt(toPointer([...paths[0], k.name, 0]));
|
|
183
|
+
const vals = nav.values([...paths[0], k.name]);
|
|
184
|
+
const types = nav.types([...paths[0], k.name]);
|
|
185
|
+
let control: HTMLElement;
|
|
186
|
+
const placeholder = value === MIXED ? '(mixed)' : '';
|
|
187
|
+
|
|
188
|
+
if (slot || vals.length) {
|
|
189
|
+
// a picker: the allowed values, or the declared names
|
|
190
|
+
const choices = [...new Set([...vals, ...(slot ? slot.targets.flatMap(s => names(s).map(n => (slot.write ? slot.write(n) : n))).concat(slot.extra ?? []) : [])])];
|
|
191
|
+
const sel = h('select', { id, class: 'pinput' });
|
|
192
|
+
sel.append(h('option', { value: '\u0000' }, placeholder || '—'));
|
|
193
|
+
for (const c of choices) sel.append(h('option', { value: c }, c));
|
|
194
|
+
if (value !== MIXED && value !== undefined && !choices.includes(String(value))) sel.append(h('option', { value: String(value) }, String(value)));
|
|
195
|
+
sel.value = value === MIXED || value === undefined ? '\u0000' : String(value);
|
|
196
|
+
sel.addEventListener('change', () => {
|
|
197
|
+
if (sel.value === '\u0000') { if (isWritten) unset(); return; }
|
|
198
|
+
set(vals.includes('true') && (sel.value === 'true' || sel.value === 'false') ? sel.value === 'true' : sel.value);
|
|
199
|
+
});
|
|
200
|
+
control = sel;
|
|
201
|
+
} else if (itemSlot && paths.length === 1) {
|
|
202
|
+
// a list of names: chips, and a picker to add one
|
|
203
|
+
const list = Array.isArray(value) ? (value as string[]) : [];
|
|
204
|
+
const wrap = h('div', { class: 'chips' });
|
|
205
|
+
list.forEach((v, i) => {
|
|
206
|
+
const x = h('button', { type: 'button', class: 'chip-x', 'aria-label': `Remove ${v}` }, '×');
|
|
207
|
+
x.addEventListener('click', () => apply({ ...deleteCmd([...paths[0], k.name, i]), label: `Remove ${v} from ${describe([...paths[0], k.name])}` }));
|
|
208
|
+
wrap.append(h('span', { class: 'chip' }, String(v), x));
|
|
209
|
+
});
|
|
210
|
+
const can = [...new Set(itemSlot.targets.flatMap(s => names(s)).concat(itemSlot.extra ?? []))].filter(n => !list.includes(n));
|
|
211
|
+
if (can.length) {
|
|
212
|
+
const add = h('select', { id, class: 'pinput chip-add', 'aria-label': `Add to ${k.name}` }, h('option', { value: '' }, '+ add'), ...can.map(n => h('option', { value: n }, n)));
|
|
213
|
+
add.addEventListener('change', () => { if (add.value) apply(insertItemCmd([...paths[0], k.name], add.value, undefined, `Add ${add.value} to ${describe([...paths[0], k.name])}`)); });
|
|
214
|
+
wrap.append(add);
|
|
215
|
+
}
|
|
216
|
+
control = wrap;
|
|
217
|
+
} else if (k.name === 'prompt' || (typeof value === 'string' && value.includes('\n'))) {
|
|
218
|
+
const ta = h('textarea', { id, class: 'pinput', rows: '5', spellcheck: 'false', placeholder });
|
|
219
|
+
ta.value = typeof value === 'string' ? value : '';
|
|
220
|
+
ta.addEventListener('change', () => { const v = ta.value; if (v === '' && isWritten) unset(); else if (v !== value) set(v.endsWith('\n') || !v.includes('\n') ? v : v + '\n'); });
|
|
221
|
+
control = ta;
|
|
222
|
+
} else if (k.shape === 'scalar' && (value === undefined || value === MIXED || typeof value !== 'object')) {
|
|
223
|
+
const inp = h('input', { id, class: 'pinput', type: types.has('integer') || types.has('number') ? 'number' : 'text', spellcheck: 'false', autocomplete: 'off', placeholder });
|
|
224
|
+
inp.value = value === undefined || value === MIXED ? '' : String(value);
|
|
225
|
+
inp.addEventListener('change', () => {
|
|
226
|
+
const raw = inp.value;
|
|
227
|
+
if (raw === '') { if (isWritten) unset(); return; }
|
|
228
|
+
const v = (types.has('integer') || types.has('number')) && /^-?\d+(\.\d+)?$/.test(raw) ? Number(raw) : raw;
|
|
229
|
+
if (v !== value) set(v);
|
|
230
|
+
});
|
|
231
|
+
inp.addEventListener('keydown', e => { if (e.key === 'Enter') inp.blur(); });
|
|
232
|
+
control = inp;
|
|
233
|
+
} else {
|
|
234
|
+
// a map or a list: as YAML, in flow style
|
|
235
|
+
const inp = h('input', { id, class: 'pinput mono', spellcheck: 'false', autocomplete: 'off', placeholder: placeholder || (k.shape === 'list' ? '[a, b]' : '{ key: value }') });
|
|
236
|
+
inp.value = value === undefined || value === MIXED ? '' : flowText(value);
|
|
237
|
+
inp.addEventListener('change', () => {
|
|
238
|
+
if (inp.value.trim() === '') { if (isWritten) unset(); return; }
|
|
239
|
+
let v: unknown;
|
|
240
|
+
try { v = parseYaml(inp.value); } catch (e) { inp.setAttribute('aria-invalid', 'true'); inp.title = `Not YAML: ${(e as Error).message}`; return; }
|
|
241
|
+
inp.removeAttribute('aria-invalid');
|
|
242
|
+
if (JSON.stringify(v) !== JSON.stringify(value)) set(v);
|
|
243
|
+
});
|
|
244
|
+
inp.addEventListener('keydown', e => { if (e.key === 'Enter') inp.blur(); });
|
|
245
|
+
control = inp;
|
|
246
|
+
}
|
|
247
|
+
// the full value as a tooltip (a field can be narrower than its value)
|
|
248
|
+
const full = value === undefined || value === MIXED ? '' : display(value);
|
|
249
|
+
if (full) control.title = full;
|
|
250
|
+
if (inherited && !isWritten) {
|
|
251
|
+
// inherited and not written here: the value in full, greyed, where it comes from, and Override on its own line
|
|
252
|
+
row.classList.add('inherited');
|
|
253
|
+
row.append(h('div', { class: 'pinherit', title: display(inherited.value) }, display(inherited.value)));
|
|
254
|
+
const line = h('div', { class: 'pfrom' }, `inherited from ${inherited.from ?? ui.inheritedFrom}`);
|
|
255
|
+
const o = h('button', { type: 'button', class: 'btn sm quiet poverride', title: `Write ${k.name}: ${display(inherited.value)} in this file, to change it here` }, 'Override');
|
|
256
|
+
o.addEventListener('click', () => { pendingFocus = ptrs[0]; focusInput = true; set(inherited!.value, `Override ${describe([...paths[0], k.name])}`); });
|
|
257
|
+
row.append(line, o);
|
|
258
|
+
const probs0 = opts.problems().filter(pr => ptrs.some(ptr => pr.path === ptr || pr.path.startsWith(ptr + '/')));
|
|
259
|
+
for (const pr of probs0) row.append(h('div', { class: `pprob ${pr.severity}` }, icon(pr.severity === 'error' ? 'circle-x' : 'triangle-alert'), pr.message));
|
|
260
|
+
return row;
|
|
261
|
+
}
|
|
262
|
+
row.append(control);
|
|
263
|
+
const acts = h('span', { class: 'pacts' });
|
|
264
|
+
if (inherited && isWritten) {
|
|
265
|
+
const o = h('button', { type: 'button', class: 'btn sm quiet', title: `Remove this file's value: ${display(inherited.value)} applies again` }, 'Reset');
|
|
266
|
+
o.addEventListener('click', unset);
|
|
267
|
+
acts.append(o);
|
|
268
|
+
} else if (isWritten && control.tagName !== 'SELECT') {
|
|
269
|
+
const o = h('button', { type: 'button', class: 'btn sm quiet icon-only', 'aria-label': `Remove ${k.name}`, title: `Remove ${k.name}` }, icon('x'));
|
|
270
|
+
o.addEventListener('click', unset);
|
|
271
|
+
acts.append(o);
|
|
272
|
+
}
|
|
273
|
+
row.append(acts);
|
|
274
|
+
if (inherited) row.append(h('div', { class: 'pfrom' }, `overrides ${display(inherited.value)} from ${inherited.from ?? ui.inheritedFrom}`));
|
|
275
|
+
const probs = opts.problems().filter(pr => ptrs.some(ptr => pr.path === ptr || pr.path.startsWith(ptr + '/')));
|
|
276
|
+
for (const pr of probs) row.append(h('div', { class: `pprob ${pr.severity}` }, icon(pr.severity === 'error' ? 'circle-x' : 'triangle-alert'), pr.message));
|
|
277
|
+
return row;
|
|
278
|
+
}
|
|
279
|
+
const display = (v: unknown) => (v === null || typeof v !== 'object' ? String(v) : flowText(v));
|
|
280
|
+
|
|
281
|
+
/** Now, read-only: what the host says is true about it (its state shown) */
|
|
282
|
+
function nowSection(ptr: string) {
|
|
283
|
+
const rows = opts.now && ui.facts ? ui.facts(opts.now(ptr)) : undefined;
|
|
284
|
+
if (!rows) return;
|
|
285
|
+
body.append(h('div', { class: 'sel-head' }, 'Now'));
|
|
286
|
+
if (!rows.length) { body.append(h('p', { class: 'hint now-unknown' }, 'Not known: the host has said nothing about it.')); return; }
|
|
287
|
+
const dl = h('dl', { class: 'now' });
|
|
288
|
+
for (const r of rows) dl.append(h('dt', null, r.term), h('dd', r.cls ? { class: r.cls } : null, r.def));
|
|
289
|
+
body.append(dl);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function uses(section: string, name: string) {
|
|
293
|
+
nowSection(toPointer([...(kindOf(section)?.section ?? []), name]));
|
|
294
|
+
const refs = referencesTo(doc.text, section, name);
|
|
295
|
+
body.append(h('div', { class: 'sel-head' }, refs.length ? `Used in ${refs.length} place${refs.length > 1 ? 's' : ''}` : 'Not referenced'));
|
|
296
|
+
if (!refs.length) return;
|
|
297
|
+
const ul = h('ul', { class: 'plain sel-refs' });
|
|
298
|
+
for (const r of refs) {
|
|
299
|
+
const b = h('button', { type: 'button', class: 'linkish' }, r.path.slice(1).replace(/\//g, '.'));
|
|
300
|
+
b.addEventListener('click', () => doc.select([fromPointer(r.path)], 'props'));
|
|
301
|
+
ul.append(h('li', null, b, h('span', { class: 'hint' }, ` ${r.slot.what}`)));
|
|
302
|
+
}
|
|
303
|
+
body.append(ul);
|
|
304
|
+
}
|
|
305
|
+
function problemsFor(ptr: string) {
|
|
306
|
+
const mine = opts.problems().filter(x => x.path === ptr && !x.file);
|
|
307
|
+
if (mine.length) body.append(h('div', { class: 'sel-head' }, 'Problems'), ...mine.map(x => h('div', { class: `sel-prob ${x.severity}` }, icon(x.severity === 'error' ? 'circle-x' : 'triangle-alert'), h('span', null, x.message))));
|
|
308
|
+
}
|
|
309
|
+
function deleteButton() {
|
|
310
|
+
if (!doc.doc.ok || !doc.selection.some(p => p.length)) return;
|
|
311
|
+
const b = h('button', { type: 'button', class: 'btn sm danger props-delete' }, icon('trash-2'), doc.selection.length > 1 ? `Delete ${doc.selection.length} items` : 'Delete');
|
|
312
|
+
b.addEventListener('click', () => deletePaths(doc, doc.selection, 'props', opts.note));
|
|
313
|
+
body.append(b);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** a setting of the file (or a section): its value, its words, and its own keys as a form */
|
|
317
|
+
function settings(p: Path) {
|
|
318
|
+
const nav = opts.nav();
|
|
319
|
+
body.append(h('div', { class: 'sel-title' }, p.length ? describe(p) : ui.rootTitle), h('code', { class: 'sel-path' }, p.join('.') || '(the whole file)'));
|
|
320
|
+
const words = nav.hover(p);
|
|
321
|
+
if (words && p.length) body.append(h('p', { class: 'sel-doc' }, words.split('\n\n')[0].replace(/`/g, '')));
|
|
322
|
+
const v = getIn(doc.goodDoc.data, p);
|
|
323
|
+
const isSection = K.kinds.some(k => toPointer(k.section) === toPointer(p));
|
|
324
|
+
if (isSection) {
|
|
325
|
+
const n = isMap(v) ? Object.keys(v).length : 0;
|
|
326
|
+
body.append(h('p', null, `${n} ${n === 1 ? 'entry' : 'entries'}. Add one from the tree's +, or the canvas's menu.`));
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
// the file's own settings, or a top-level map: its keys
|
|
330
|
+
const holder = !p.length ? [] : isMap(v) ? p : p.slice(0, -1);
|
|
331
|
+
const val = getIn(doc.goodDoc.data, holder);
|
|
332
|
+
if (!isMap(val) && holder.length) return;
|
|
333
|
+
const sectionTops = new Set(K.kinds.map(k => String(k.section[0])));
|
|
334
|
+
const keys = nav.keys(holder, (val ?? {}) as Raw).filter(k => !sectionTops.has(k.name) || holder.length);
|
|
335
|
+
const sec = h('div', { class: 'props' });
|
|
336
|
+
for (const k of keys) sec.append(field([holder], '', k, [(val ?? {}) as Raw], undefined));
|
|
337
|
+
body.append(sec);
|
|
338
|
+
if (p.length && toPointer(p) !== toPointer(holder)) { const f = sec.querySelector(`[data-path="${CSS.escape(toPointer(p))}"]`); f?.classList.add('focus-row'); f?.scrollIntoView({ block: 'nearest' }); }
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
body.addEventListener('focusout', () => setTimeout(() => { if (!body.contains(document.activeElement)) paint(); }, 0));
|
|
342
|
+
doc.onSelect(() => paint());
|
|
343
|
+
// typing: once it pauses; everything else at once
|
|
344
|
+
const paintLater = later(() => paint());
|
|
345
|
+
doc.on(c => { if (isTyping(c)) paintLater(); else paintLater.now(); });
|
|
346
|
+
return { paint, dispose: () => paintLater.cancel() };
|
|
347
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// The editor's stylesheet, scoped to its root element (the setup's root class), so it can live in a host's page: every rule sits
|
|
2
|
+
// under the root class; html, body and :root become the root itself; @layer, @media, @container and @supports keep their
|
|
3
|
+
// rules, scoped; @keyframes are renamed se-*. Nothing styles the host's page. Used at build time (pure; tested in Node).
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/** Split CSS into its top-level blocks: [prelude, body], or [statement, ''] for an at-rule without a block. */
|
|
7
|
+
function blocks(css: string): [string, string | null][] {
|
|
8
|
+
const out: [string, string | null][] = [];
|
|
9
|
+
const text = css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
10
|
+
let i = 0;
|
|
11
|
+
while (i < text.length) {
|
|
12
|
+
const open = text.indexOf('{', i), semi = text.indexOf(';', i);
|
|
13
|
+
if (open < 0 && semi < 0) break;
|
|
14
|
+
if (semi >= 0 && (open < 0 || semi < open)) { // a statement: @layer a, b; @import …;
|
|
15
|
+
const st = text.slice(i, semi).trim();
|
|
16
|
+
if (st) out.push([st, null]);
|
|
17
|
+
i = semi + 1;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
let depth = 1, j = open + 1;
|
|
21
|
+
while (j < text.length && depth) { if (text[j] === '{') depth++; else if (text[j] === '}') depth--; j++; }
|
|
22
|
+
out.push([text.slice(i, open).trim(), text.slice(open + 1, j - 1)]);
|
|
23
|
+
i = j;
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** a selector list split at its top-level commas */
|
|
29
|
+
function selectors(list: string): string[] {
|
|
30
|
+
const out: string[] = [];
|
|
31
|
+
let depth = 0, cut = 0;
|
|
32
|
+
for (let i = 0; i < list.length; i++) {
|
|
33
|
+
const c = list[i];
|
|
34
|
+
if (c === '(' || c === '[') depth++;
|
|
35
|
+
else if (c === ')' || c === ']') depth--;
|
|
36
|
+
else if (c === ',' && !depth) { out.push(list.slice(cut, i).trim()); cut = i + 1; }
|
|
37
|
+
}
|
|
38
|
+
out.push(list.slice(cut).trim());
|
|
39
|
+
return out.filter(Boolean);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** One selector under the root: html, body and :root (with any state they name) become the root itself; * is the
|
|
43
|
+
* root and everything in it. */
|
|
44
|
+
export function scopeOne(sel: string, root: string): string {
|
|
45
|
+
const r = `.${root}`;
|
|
46
|
+
const m = /^(?:html|body|:root)((?:\[[^\]]*\]|\.[\w-]+|:not\([^)]*\))*)(.*)$/.exec(sel);
|
|
47
|
+
if (m && /^(html|body|:root)(?![\w-])/.test(sel)) return `${r}${m[1]}${m[2].trim() ? ' ' + m[2].trim() : ''}`;
|
|
48
|
+
if (sel === '*') return `${r}, ${r} *`;
|
|
49
|
+
return `${r} ${sel}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Scope a stylesheet to the root class. */
|
|
53
|
+
export function scopeCss(css: string, root: string): string {
|
|
54
|
+
let out = '';
|
|
55
|
+
for (const [pre, body] of blocks(css)) {
|
|
56
|
+
if (body === null) { if (pre.startsWith('@layer') || pre.startsWith('@import')) out += `${pre};\n`; continue; }
|
|
57
|
+
if (pre.startsWith('@keyframes')) { out += `@keyframes se-${pre.slice('@keyframes'.length).trim()}{${body}}\n`; continue; }
|
|
58
|
+
if (/^@(layer|media|container|supports)\b/.test(pre)) { out += `${pre}{\n${scopeCss(body, root)}}\n`; continue; }
|
|
59
|
+
if (pre.startsWith('@font-face')) { out += `${pre}{${body}}\n`; continue; }
|
|
60
|
+
if (pre.startsWith('@')) throw new Error(`the editor's CSS has an at-rule it can't scope: ${pre}`);
|
|
61
|
+
const scoped = [...new Set(selectors(pre).flatMap(s => scopeOne(s, root).split(', ')))].join(',');
|
|
62
|
+
out += `${scoped}{${body.replace(/\banimation(-name)?:\s*([a-z][\w-]*)/g, (m0, n, k) => (k === 'none' ? m0 : `animation${n ?? ''}:se-${k}`))}}\n`;
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|