@johnoscott/isometric-engine 0.0.0-stage → 0.9.0
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 +317 -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 +265 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +35 -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 +441 -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 +1205 -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 +145 -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 +502 -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 +128 -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 +472 -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 +1071 -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 +35 -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 +144 -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 +145 -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 +279 -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 +40 -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,767 @@
|
|
|
1
|
+
import { problemRange } from "../providers.js";
|
|
2
|
+
import { later, isTyping } from "./later.js";
|
|
3
|
+
import { treeView } from "./tree.js";
|
|
4
|
+
import { keySheet, keymapWith } from "./keys.js";
|
|
5
|
+
import { closeMenu } from "./menu.js";
|
|
6
|
+
import { setLayer } from "./layer.js";
|
|
7
|
+
import { fromPointer, toPointer } from "../path.js";
|
|
8
|
+
import { h } from "./icons.js";
|
|
9
|
+
import { EditorModel } from "../model.js";
|
|
10
|
+
import { PREF } from "../storage-keys.js";
|
|
11
|
+
const shellHtml = (W) => `
|
|
12
|
+
<header class="titlebar">
|
|
13
|
+
<button id="se-tree" class="btn sm quiet icon-only" type="button" aria-expanded="false" aria-controls="se-side" aria-label="Show the outline" title="The outline"><svg class="icon" aria-hidden="true"><use href="#se-i-list-tree"></use></svg></button>
|
|
14
|
+
<span class="brand" data-se="brand" hidden>${W.brand}</span>
|
|
15
|
+
<span data-se="title-start" class="title-start"></span>
|
|
16
|
+
<span class="pill ro" id="se-ro" hidden>Read-only</span>
|
|
17
|
+
<button id="se-save" class="btn sm primary" type="button" disabled title="Save (\u2318S)">Save</button>
|
|
18
|
+
<div class="btn-group" role="group" aria-label="History">
|
|
19
|
+
<button id="se-undo" class="btn sm" type="button" disabled title="Nothing to undo"><svg class="icon" aria-hidden="true"><use href="#se-i-rotate-ccw"></use></svg>Undo</button>
|
|
20
|
+
<button id="se-redo" class="btn sm" type="button" disabled title="Nothing to redo"><svg class="icon flip" aria-hidden="true"><use href="#se-i-rotate-ccw"></use></svg>Redo</button>
|
|
21
|
+
</div>
|
|
22
|
+
<span class="spacer"></span>
|
|
23
|
+
<div id="se-views" class="segmented" role="group" aria-label="Show">
|
|
24
|
+
<button class="seg" type="button" data-v="canvas">Canvas</button>
|
|
25
|
+
<button class="seg" type="button" data-v="both">Both</button>
|
|
26
|
+
<button class="seg" type="button" data-v="text">Text</button>
|
|
27
|
+
</div>
|
|
28
|
+
<div id="se-theme" class="segmented" role="group" aria-label="Theme" hidden>
|
|
29
|
+
<button class="seg" type="button" data-v="system">System</button>
|
|
30
|
+
<button class="seg" type="button" data-v="light">Light</button>
|
|
31
|
+
<button class="seg" type="button" data-v="dark">Dark</button>
|
|
32
|
+
</div>
|
|
33
|
+
<button id="se-density" class="btn sm quiet" type="button" aria-pressed="false" title="Compact density" hidden>Compact</button>
|
|
34
|
+
<button id="se-keys" class="btn sm quiet" type="button" title="Keyboard (?)" aria-haspopup="dialog">Keys</button>
|
|
35
|
+
<button id="se-panel" class="btn sm quiet icon-only" type="button" aria-pressed="true" aria-label="Show the properties panel" title="The properties panel"><svg class="icon" aria-hidden="true"><use href="#se-i-panel-right"></use></svg></button>
|
|
36
|
+
</header>
|
|
37
|
+
<div class="body">
|
|
38
|
+
<div id="se-scrim" class="scrim" hidden></div>
|
|
39
|
+
<nav class="side" id="se-side" aria-label="${W.sideLabel}">
|
|
40
|
+
<div class="side-tabs segmented" role="tablist" aria-label="Sidebar" hidden>
|
|
41
|
+
<button class="seg" type="button" role="tab" id="se-tab-outline" aria-controls="se-outline" aria-selected="true"><svg class="icon" aria-hidden="true"><use href="#se-i-list-tree"></use></svg>Outline</button>
|
|
42
|
+
</div>
|
|
43
|
+
<div id="se-outline" role="tabpanel" aria-labelledby="se-tab-outline"></div>
|
|
44
|
+
</nav>
|
|
45
|
+
<div id="se-side-grip" class="vgrip" role="separator" aria-orientation="vertical" aria-label="Resize the sidebar" tabindex="0"></div>
|
|
46
|
+
<main class="center">
|
|
47
|
+
<div id="se-filebar" class="callout warn banner filebar" role="alert" hidden><svg class="icon" aria-hidden="true"><use href="#se-i-triangle-alert"></use></svg><div class="c-body"></div><div class="c-acts"></div></div>
|
|
48
|
+
<div class="work">
|
|
49
|
+
<div id="se-canvas" aria-label="${W.canvasLabel}"></div>
|
|
50
|
+
<div id="se-work-grip" class="vgrip" role="separator" aria-orientation="vertical" aria-label="Resize the canvas and the text" tabindex="0"></div>
|
|
51
|
+
<div id="se-code" aria-label="The file, as text"></div>
|
|
52
|
+
</div>
|
|
53
|
+
${W.slots} <div id="se-grip" role="separator" aria-orientation="horizontal" aria-label="Resize the problems list" tabindex="0"></div>
|
|
54
|
+
<section id="se-problems" aria-label="${W.problemsLabel}">
|
|
55
|
+
<div id="se-problems-head" class="problems-head">
|
|
56
|
+
<button id="se-problems-toggle" type="button" class="problems-toggle" aria-expanded="false" aria-controls="se-problems-list"><svg class="icon" aria-hidden="true"><use href="#se-i-chevron-right"></use></svg><span id="se-problems-label">No problems</span></button>
|
|
57
|
+
<span class="spacer"></span>
|
|
58
|
+
<span id="se-plan-label" class="plan-label"></span>
|
|
59
|
+
<div class="segmented bottom-tabs" role="tablist" aria-label="${W.bottomTabsLabel}">
|
|
60
|
+
<button class="seg" type="button" role="tab" id="se-tab-problems" aria-selected="true" aria-controls="se-problems-list">Problems</button>
|
|
61
|
+
<button class="seg" type="button" role="tab" id="se-tab-plan" aria-selected="false" aria-controls="se-plan">${W.extraTab}</button>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
<div id="se-problems-list" role="tabpanel" aria-labelledby="se-tab-problems"></div>
|
|
65
|
+
<div id="se-plan" class="plan" role="tabpanel" aria-labelledby="se-tab-plan" hidden></div>
|
|
66
|
+
</section>
|
|
67
|
+
<div id="se-note" class="callout compact" role="status" hidden><span class="c-body"></span></div>
|
|
68
|
+
</main>
|
|
69
|
+
<div id="se-right-grip" class="vgrip" role="separator" aria-orientation="vertical" aria-label="Resize the selection panel" tabindex="0"></div>
|
|
70
|
+
<aside id="se-right" class="right" aria-label="Properties">
|
|
71
|
+
<div class="side-head">Properties</div>
|
|
72
|
+
<div id="se-sel-body" class="sel-body"></div>
|
|
73
|
+
</aside>
|
|
74
|
+
</div>
|
|
75
|
+
<footer class="status">
|
|
76
|
+
<span id="se-st-problems" class="ok">0 \u2715 0 \u26A0</span>
|
|
77
|
+
<span id="se-st-path" class="path"></span>
|
|
78
|
+
<span class="spacer"></span>
|
|
79
|
+
<span id="se-st-sel"></span>
|
|
80
|
+
<span id="se-st-hint" class="hint-mode" title="The canvas's navigation: change it in the canvas's toolbar"></span>
|
|
81
|
+
<span id="se-st-zoom" title="The canvas's zoom"></span>
|
|
82
|
+
<span id="se-st-pos"></span>
|
|
83
|
+
<span id="se-st-kind"></span>
|
|
84
|
+
<span id="se-announce" class="sr-only" aria-live="polite"></span>
|
|
85
|
+
</footer>`;
|
|
86
|
+
function mountEditor(el, opts, S) {
|
|
87
|
+
const F = S.features;
|
|
88
|
+
const K = S.kit, W = S.words, load = S.load;
|
|
89
|
+
const watch = !!opts.watch;
|
|
90
|
+
const hooks = opts.host ?? {};
|
|
91
|
+
const store = {
|
|
92
|
+
get: (k) => {
|
|
93
|
+
try {
|
|
94
|
+
return opts.storage?.get(k) ?? null;
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
set: (k, v) => {
|
|
100
|
+
try {
|
|
101
|
+
opts.storage?.set(k, v);
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const root = h("div", { class: W.rootClass, "data-view": "both" });
|
|
107
|
+
const sprite = document.createElement("template");
|
|
108
|
+
sprite.innerHTML = S.sprite ?? "";
|
|
109
|
+
const shell = document.createElement("template");
|
|
110
|
+
shell.innerHTML = shellHtml(W);
|
|
111
|
+
root.append(sprite.content, shell.content);
|
|
112
|
+
el.append(root);
|
|
113
|
+
setLayer(root);
|
|
114
|
+
const $ = (id) => root.querySelector(`#se-${id}`);
|
|
115
|
+
const cleanups = [];
|
|
116
|
+
const on = (t, ev, fn, o) => {
|
|
117
|
+
t.addEventListener(ev, fn, o);
|
|
118
|
+
cleanups.push(() => t.removeEventListener(ev, fn, o));
|
|
119
|
+
};
|
|
120
|
+
on(root, "focusin", () => setLayer(root));
|
|
121
|
+
on(root, "pointerdown", () => setLayer(root));
|
|
122
|
+
const state = {
|
|
123
|
+
problems: [],
|
|
124
|
+
lifetimes: /* @__PURE__ */ new Map(),
|
|
125
|
+
read: void 0,
|
|
126
|
+
plan: void 0,
|
|
127
|
+
view: watch ? "canvas" : store.get(PREF.view) ?? "both",
|
|
128
|
+
theme: opts.theme ?? (hooks.themeControls ? store.get("theme") ?? "system" : "system"),
|
|
129
|
+
density: hooks.themeControls ? store.get("density") ?? "comfortable" : "comfortable",
|
|
130
|
+
readOnly: !!opts.readOnly || !F.edit,
|
|
131
|
+
problemsOpen: false,
|
|
132
|
+
problemsSeen: 0,
|
|
133
|
+
checks: 0
|
|
134
|
+
};
|
|
135
|
+
if (hooks.brand) root.querySelector('[data-se="brand"]').hidden = false;
|
|
136
|
+
for (const x of hooks.titleStart ?? []) root.querySelector('[data-se="title-start"]').append(x);
|
|
137
|
+
$("save").hidden = !opts.onSave;
|
|
138
|
+
$("theme").hidden = $("density").hidden = !hooks.themeControls;
|
|
139
|
+
const doc = new EditorModel();
|
|
140
|
+
for (const m of ["apply", "undo", "redo"]) {
|
|
141
|
+
const f = doc[m].bind(doc);
|
|
142
|
+
doc[m] = (...a) => {
|
|
143
|
+
if (state.readOnly) {
|
|
144
|
+
note("This file is read-only here", "warn");
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return f(...a);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const makePane = () => F.text ? F.text.textPane($("code"), doc, { onOpen: (rel) => hooks.onOpen?.(rel), onSave: () => {
|
|
151
|
+
void save();
|
|
152
|
+
}, onSaveAs: () => hooks.onSaveAs?.() }) : noText();
|
|
153
|
+
let pane = makePane();
|
|
154
|
+
const isTextTarget = (t) => !!t?.closest?.(".monaco-editor, #se-code");
|
|
155
|
+
const clip = F.edit ? F.edit.clipboard(doc, (t, tone) => note(t, tone)) : { items: () => [], attach: () => () => void 0 };
|
|
156
|
+
const tree = treeView($("outline"), doc, {
|
|
157
|
+
kit: S.tree,
|
|
158
|
+
clipItems: () => clip.items(),
|
|
159
|
+
nav: () => K.nav(doc.text),
|
|
160
|
+
problems: () => state.problems,
|
|
161
|
+
role: () => K.role(doc.text),
|
|
162
|
+
lifetimes: () => state.lifetimes,
|
|
163
|
+
showInText: (path) => showInText(path),
|
|
164
|
+
note: (t, tone) => note(t, tone)
|
|
165
|
+
});
|
|
166
|
+
const props = !F.edit ? { paint: () => void 0, dispose: () => void 0 } : F.edit.propsPanel($("sel-body"), doc, {
|
|
167
|
+
nav: () => K.nav(doc.text),
|
|
168
|
+
problems: () => state.problems,
|
|
169
|
+
read: () => state.read,
|
|
170
|
+
note: (t, tone) => note(t, tone),
|
|
171
|
+
showInText: (p) => showInText(p),
|
|
172
|
+
now: (ptr) => part?.now?.(ptr)
|
|
173
|
+
});
|
|
174
|
+
const paintSelection = () => {
|
|
175
|
+
$("st-sel").textContent = doc.selection.length > 1 ? `${doc.selection.length} selected` : "";
|
|
176
|
+
props.paint();
|
|
177
|
+
};
|
|
178
|
+
doc.onSelect(paintSelection);
|
|
179
|
+
const canvas = !F.canvas ? noCanvas(S.noCanvas) : F.canvas.canvasView($("canvas"), doc, {
|
|
180
|
+
problems: () => state.problems,
|
|
181
|
+
note: (t, tone) => note(t, tone),
|
|
182
|
+
showInText: (p) => showInText(p),
|
|
183
|
+
showInTree: (p) => {
|
|
184
|
+
$("tab-outline").click();
|
|
185
|
+
doc.select([p], "menu");
|
|
186
|
+
tree.focus();
|
|
187
|
+
},
|
|
188
|
+
onZoom: (pct) => {
|
|
189
|
+
$("st-zoom").textContent = `${pct}%`;
|
|
190
|
+
},
|
|
191
|
+
onHint: (t) => {
|
|
192
|
+
$("st-hint").textContent = t;
|
|
193
|
+
},
|
|
194
|
+
clipItems: () => clip.items(),
|
|
195
|
+
store,
|
|
196
|
+
...S.canvasOpts?.(() => part.api)
|
|
197
|
+
});
|
|
198
|
+
cleanups.push(clip.attach(root, (t) => !!t?.closest?.("#se-outline, .canvas, #se-sel-body")));
|
|
199
|
+
function showInText(path) {
|
|
200
|
+
if (state.view === "canvas") setView("both", true);
|
|
201
|
+
pane.goTo(path);
|
|
202
|
+
}
|
|
203
|
+
const tabs = root.querySelector(".side-tabs");
|
|
204
|
+
for (const t of hooks.sideTabs ?? []) {
|
|
205
|
+
const b = h("button", { class: "seg", type: "button", role: "tab", id: `se-tab-${t.id}`, "aria-controls": t.panel.id, "aria-selected": "false" });
|
|
206
|
+
const ic = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
207
|
+
ic.setAttribute("class", "icon");
|
|
208
|
+
ic.setAttribute("aria-hidden", "true");
|
|
209
|
+
const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
210
|
+
use.setAttribute("href", `#se-i-${t.icon}`);
|
|
211
|
+
ic.append(use);
|
|
212
|
+
b.append(ic, t.label);
|
|
213
|
+
tabs.append(b);
|
|
214
|
+
t.panel.setAttribute("role", "tabpanel");
|
|
215
|
+
t.panel.setAttribute("aria-labelledby", b.id);
|
|
216
|
+
t.panel.hidden = true;
|
|
217
|
+
root.querySelector("nav.side").append(t.panel);
|
|
218
|
+
}
|
|
219
|
+
tabs.hidden = !(hooks.sideTabs ?? []).length;
|
|
220
|
+
for (const b of tabs.querySelectorAll('[role="tab"]')) {
|
|
221
|
+
on(b, "click", () => {
|
|
222
|
+
for (const x of tabs.querySelectorAll('[role="tab"]')) {
|
|
223
|
+
const isOn = x === b;
|
|
224
|
+
x.setAttribute("aria-selected", String(isOn));
|
|
225
|
+
x.classList.toggle("active", isOn);
|
|
226
|
+
root.querySelector(`#${x.getAttribute("aria-controls")}`).hidden = !isOn;
|
|
227
|
+
}
|
|
228
|
+
store.set("tab", b.id);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if (store.get("tab") && store.get("tab") !== "se-tab-outline" && root.querySelector(`#${store.get("tab")}`)) root.querySelector(`#${store.get("tab")}`).click();
|
|
232
|
+
else $("tab-outline").classList.add("active");
|
|
233
|
+
let wanted = state.view;
|
|
234
|
+
function setView(v, chosen = false) {
|
|
235
|
+
if (chosen) {
|
|
236
|
+
wanted = v;
|
|
237
|
+
if (!watch) store.set(PREF.view, v);
|
|
238
|
+
}
|
|
239
|
+
if (!F.text) v = "canvas";
|
|
240
|
+
else if (!F.canvas) v = "text";
|
|
241
|
+
state.view = v;
|
|
242
|
+
root.dataset.view = v;
|
|
243
|
+
for (const b of root.querySelectorAll("#se-views .seg")) b.setAttribute("aria-pressed", String(b.dataset.v === v));
|
|
244
|
+
pane.editor.layout();
|
|
245
|
+
}
|
|
246
|
+
for (const b of root.querySelectorAll("#se-views .seg")) on(b, "click", () => setView(b.dataset.v, true));
|
|
247
|
+
const setTree = (open) => {
|
|
248
|
+
root.classList.toggle("side-open", open);
|
|
249
|
+
$("tree").setAttribute("aria-expanded", String(open));
|
|
250
|
+
$("tree").setAttribute("aria-label", open ? "Hide the outline" : "Show the outline");
|
|
251
|
+
$("scrim").hidden = !open;
|
|
252
|
+
};
|
|
253
|
+
on($("tree"), "click", () => setTree(!root.classList.contains("side-open")));
|
|
254
|
+
on($("scrim"), "click", () => setTree(false));
|
|
255
|
+
on(root, "keydown", (e) => {
|
|
256
|
+
if (e.key === "Escape" && root.classList.contains("side-open") && !e.target.closest?.("dialog, .menu")) {
|
|
257
|
+
setTree(false);
|
|
258
|
+
$("tree").focus();
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
{
|
|
262
|
+
const ro = new ResizeObserver(() => {
|
|
263
|
+
if (root.classList.contains("side-open") && root.clientWidth > 760) setTree(false);
|
|
264
|
+
});
|
|
265
|
+
ro.observe(root);
|
|
266
|
+
cleanups.push(() => ro.disconnect());
|
|
267
|
+
}
|
|
268
|
+
function grip(id, varName, side, min, max) {
|
|
269
|
+
const g = $(id);
|
|
270
|
+
const saved = store.get(varName);
|
|
271
|
+
if (saved) root.style.setProperty(varName, `${saved}px`);
|
|
272
|
+
const size = () => parseFloat(getComputedStyle(root).getPropertyValue(varName)) || (side === "left" ? 260 : 280);
|
|
273
|
+
const set = (w) => {
|
|
274
|
+
const v = Math.round(Math.min(max, Math.max(min, w)));
|
|
275
|
+
root.style.setProperty(varName, `${v}px`);
|
|
276
|
+
store.set(varName, String(v));
|
|
277
|
+
};
|
|
278
|
+
on(g, "pointerdown", (e) => {
|
|
279
|
+
g.setPointerCapture(e.pointerId);
|
|
280
|
+
const x0 = e.clientX, w0 = size();
|
|
281
|
+
const mv = (ev) => set(side === "left" ? w0 + ev.clientX - x0 : w0 - (ev.clientX - x0));
|
|
282
|
+
const up = () => {
|
|
283
|
+
g.removeEventListener("pointermove", mv);
|
|
284
|
+
g.removeEventListener("pointerup", up);
|
|
285
|
+
};
|
|
286
|
+
g.addEventListener("pointermove", mv);
|
|
287
|
+
g.addEventListener("pointerup", up);
|
|
288
|
+
});
|
|
289
|
+
on(g, "keydown", (e) => {
|
|
290
|
+
const d = e.key === "ArrowLeft" ? -16 : e.key === "ArrowRight" ? 16 : 0;
|
|
291
|
+
if (d) {
|
|
292
|
+
set(size() + (side === "left" ? d : -d));
|
|
293
|
+
e.preventDefault();
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
grip("side-grip", "--side-w", "left", 180, 520);
|
|
298
|
+
grip("right-grip", "--right-w", "right", 200, 520);
|
|
299
|
+
grip("work-grip", "--canvas-w", "left", 240, 1600);
|
|
300
|
+
const setPanel = (isOn) => {
|
|
301
|
+
root.classList.toggle("no-right", !isOn);
|
|
302
|
+
$("panel").setAttribute("aria-pressed", String(isOn));
|
|
303
|
+
store.set("panel", isOn ? "1" : "0");
|
|
304
|
+
};
|
|
305
|
+
setPanel(store.get("panel") !== "0");
|
|
306
|
+
on($("panel"), "click", () => setPanel(root.classList.contains("no-right")));
|
|
307
|
+
const media = matchMedia("(prefers-color-scheme: dark)");
|
|
308
|
+
const isDark = () => state.theme === "dark" || state.theme === "system" && media.matches;
|
|
309
|
+
function applyTheme() {
|
|
310
|
+
root.style.colorScheme = state.theme === "system" ? "light dark" : state.theme;
|
|
311
|
+
if (state.theme === "system") delete root.dataset.theme;
|
|
312
|
+
else root.dataset.theme = state.theme;
|
|
313
|
+
if (state.density === "compact") root.dataset.density = "compact";
|
|
314
|
+
else delete root.dataset.density;
|
|
315
|
+
pane.setTheme(isDark());
|
|
316
|
+
canvas.setTheme(isDark() ? "dark" : "light");
|
|
317
|
+
for (const b of root.querySelectorAll("#se-theme .seg")) b.setAttribute("aria-pressed", String(b.dataset.v === state.theme));
|
|
318
|
+
$("density").setAttribute("aria-pressed", String(state.density === "compact"));
|
|
319
|
+
}
|
|
320
|
+
on(media, "change", () => {
|
|
321
|
+
if (state.theme === "system") applyTheme();
|
|
322
|
+
});
|
|
323
|
+
const setTheme = (t) => {
|
|
324
|
+
state.theme = t;
|
|
325
|
+
if (hooks.themeControls) store.set("theme", t);
|
|
326
|
+
applyTheme();
|
|
327
|
+
};
|
|
328
|
+
const setDensity = (d) => {
|
|
329
|
+
state.density = d;
|
|
330
|
+
store.set("density", d);
|
|
331
|
+
applyTheme();
|
|
332
|
+
};
|
|
333
|
+
for (const b of root.querySelectorAll("#se-theme .seg")) on(b, "click", () => setTheme(b.dataset.v));
|
|
334
|
+
on($("density"), "click", () => setDensity(state.density === "compact" ? "comfortable" : "compact"));
|
|
335
|
+
let noteTimer = 0;
|
|
336
|
+
function note(text, tone = "info") {
|
|
337
|
+
const n = $("note");
|
|
338
|
+
n.className = `callout compact ${tone === "info" ? "" : tone}`;
|
|
339
|
+
n.querySelector(".c-body").textContent = text;
|
|
340
|
+
n.hidden = false;
|
|
341
|
+
clearTimeout(noteTimer);
|
|
342
|
+
noteTimer = window.setTimeout(() => {
|
|
343
|
+
n.hidden = true;
|
|
344
|
+
}, 6e3);
|
|
345
|
+
}
|
|
346
|
+
function showBanner(body, actions) {
|
|
347
|
+
const bar = $("filebar");
|
|
348
|
+
bar.querySelector(".c-body").replaceChildren(...body);
|
|
349
|
+
const acts = bar.querySelector(".c-acts");
|
|
350
|
+
acts.replaceChildren(...actions.map((a) => {
|
|
351
|
+
const b = h("button", { type: "button", class: `btn sm${a.primary ? " primary" : ""}` }, a.label);
|
|
352
|
+
b.addEventListener("click", a.run);
|
|
353
|
+
return b;
|
|
354
|
+
}));
|
|
355
|
+
bar.hidden = false;
|
|
356
|
+
}
|
|
357
|
+
const hideBanner = () => {
|
|
358
|
+
$("filebar").hidden = true;
|
|
359
|
+
};
|
|
360
|
+
const dirty = () => doc.dirty;
|
|
361
|
+
let wasDirty = false;
|
|
362
|
+
function paintTitle() {
|
|
363
|
+
$("save").disabled = !dirty() || state.readOnly;
|
|
364
|
+
if (dirty() !== wasDirty) {
|
|
365
|
+
wasDirty = dirty();
|
|
366
|
+
opts.onDirtyChange?.(wasDirty);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
async function save() {
|
|
370
|
+
if (!opts.onSave || state.readOnly) return false;
|
|
371
|
+
if (!dirty()) return true;
|
|
372
|
+
const text = doc.text;
|
|
373
|
+
doc.seal();
|
|
374
|
+
let r;
|
|
375
|
+
try {
|
|
376
|
+
r = await opts.onSave(text);
|
|
377
|
+
} catch (e) {
|
|
378
|
+
note(`Not saved: ${e.message ?? e}`, "bad");
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
if ("conflict" in r) {
|
|
382
|
+
if (hooks.onConflict) {
|
|
383
|
+
hooks.onConflict();
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
showBanner(
|
|
387
|
+
[h("span", { class: "c-title" }, "Changed elsewhere."), h("span", null, " This file changed outside the editor since it was loaded, so it wasn't saved.")],
|
|
388
|
+
[{ label: "Dismiss", run: hideBanner }]
|
|
389
|
+
);
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
if (doc.text === text) doc.markClean();
|
|
393
|
+
hideBanner();
|
|
394
|
+
paintTitle();
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
on($("save"), "click", () => {
|
|
398
|
+
void save();
|
|
399
|
+
});
|
|
400
|
+
const keymap = hooks.keymap ? keymapWith(K.keymap, hooks.keymap) : K.keymap;
|
|
401
|
+
const sheet = () => keySheet(keymap);
|
|
402
|
+
on($("keys"), "click", () => sheet());
|
|
403
|
+
on(root, "keydown", (e) => {
|
|
404
|
+
const t = e.target;
|
|
405
|
+
if (e.key === "?" && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
406
|
+
if (t.closest?.("input, textarea, select, .monaco-editor, #se-code, [contenteditable], dialog")) return;
|
|
407
|
+
e.preventDefault();
|
|
408
|
+
sheet();
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (hooks.keys?.(e)) return;
|
|
412
|
+
if (!(e.metaKey || e.ctrlKey) || e.altKey || isTextTarget(e.target)) return;
|
|
413
|
+
const k = e.key.toLowerCase();
|
|
414
|
+
if (k === "s" && !e.shiftKey) {
|
|
415
|
+
e.preventDefault();
|
|
416
|
+
void save();
|
|
417
|
+
} else if (k === "z" && !e.shiftKey) {
|
|
418
|
+
doc.undo();
|
|
419
|
+
e.preventDefault();
|
|
420
|
+
} else if (k === "z" && e.shiftKey || k === "y") {
|
|
421
|
+
doc.redo();
|
|
422
|
+
e.preventDefault();
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
const resourcePath = (name) => K.objectPath(name, state.read);
|
|
426
|
+
const makePlan = () => !F.plan ? { paint: () => void 0 } : F.plan.planPanel($("plan"), {
|
|
427
|
+
has: (name) => !!resourcePath(name),
|
|
428
|
+
select: (name) => {
|
|
429
|
+
const p = resourcePath(name);
|
|
430
|
+
if (!p) return false;
|
|
431
|
+
doc.select([fromPointer(p)], "menu");
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
let planUI = makePlan();
|
|
436
|
+
let bottomTab = store.get("bottom-tab") ?? "problems";
|
|
437
|
+
function setBottomTab(t) {
|
|
438
|
+
bottomTab = t;
|
|
439
|
+
store.set("bottom-tab", t);
|
|
440
|
+
for (const b of root.querySelectorAll('.bottom-tabs [role="tab"]')) {
|
|
441
|
+
const isOn = b.id === `se-tab-${t}`;
|
|
442
|
+
b.setAttribute("aria-selected", String(isOn));
|
|
443
|
+
b.classList.toggle("active", isOn);
|
|
444
|
+
}
|
|
445
|
+
$("problems-list").hidden = t !== "problems";
|
|
446
|
+
$("plan").hidden = t !== "plan";
|
|
447
|
+
$("problems-toggle").setAttribute("aria-controls", t === "plan" ? "se-plan" : "se-problems-list");
|
|
448
|
+
}
|
|
449
|
+
for (const b of root.querySelectorAll('.bottom-tabs [role="tab"]')) on(b, "click", () => {
|
|
450
|
+
setBottomTab(b.id === "se-tab-plan" ? "plan" : "problems");
|
|
451
|
+
setProblemsOpen(true, false);
|
|
452
|
+
});
|
|
453
|
+
function paintPlan() {
|
|
454
|
+
planUI.paint(state.plan, S.hasExtra);
|
|
455
|
+
const L = K.extraLabel(state.plan);
|
|
456
|
+
$("plan-label").textContent = L.text;
|
|
457
|
+
$("plan-label").className = `plan-label ${L.cls}`;
|
|
458
|
+
}
|
|
459
|
+
let timer = 0;
|
|
460
|
+
let disposed = false;
|
|
461
|
+
async function check() {
|
|
462
|
+
clearTimeout(timer);
|
|
463
|
+
const text = doc.text, version = doc.version;
|
|
464
|
+
const r = await K.check(text, state.plan, note);
|
|
465
|
+
if (disposed || doc.version !== version) return;
|
|
466
|
+
state.plan = r.extra;
|
|
467
|
+
state.problems = r.problems;
|
|
468
|
+
state.read = r.read;
|
|
469
|
+
state.lifetimes = r.tags;
|
|
470
|
+
state.checks++;
|
|
471
|
+
pane.setProblems(state.problems.filter((p) => !p.file));
|
|
472
|
+
paintProblems();
|
|
473
|
+
paintPlan();
|
|
474
|
+
tree.paint();
|
|
475
|
+
paintSelection();
|
|
476
|
+
void canvas.render(r.model, r.data);
|
|
477
|
+
}
|
|
478
|
+
cleanups.push(doc.on(() => {
|
|
479
|
+
paintTitle();
|
|
480
|
+
paintHistory();
|
|
481
|
+
clearTimeout(timer);
|
|
482
|
+
timer = window.setTimeout(() => {
|
|
483
|
+
void check();
|
|
484
|
+
}, 150);
|
|
485
|
+
}));
|
|
486
|
+
function paintHistory() {
|
|
487
|
+
const u = $("undo"), r = $("redo");
|
|
488
|
+
u.disabled = !doc.canUndo || state.readOnly;
|
|
489
|
+
r.disabled = !doc.canRedo || state.readOnly;
|
|
490
|
+
u.title = doc.canUndo ? `Undo ${doc.undoLabel} (\u2318Z)` : "Nothing to undo";
|
|
491
|
+
r.title = doc.canRedo ? `Redo ${doc.redoLabel} (\u21E7\u2318Z)` : "Nothing to redo";
|
|
492
|
+
u.setAttribute("aria-label", u.title);
|
|
493
|
+
r.setAttribute("aria-label", r.title);
|
|
494
|
+
}
|
|
495
|
+
on($("undo"), "click", () => {
|
|
496
|
+
doc.undo();
|
|
497
|
+
pane.focus();
|
|
498
|
+
});
|
|
499
|
+
on($("redo"), "click", () => {
|
|
500
|
+
doc.redo();
|
|
501
|
+
pane.focus();
|
|
502
|
+
});
|
|
503
|
+
function setProblemsOpen(open, byHand) {
|
|
504
|
+
if (byHand && !state.problems.length && !part?.attention?.()?.count && bottomTab === "problems") open = false;
|
|
505
|
+
state.problemsOpen = open;
|
|
506
|
+
$("problems").classList.toggle("collapsed", !open);
|
|
507
|
+
$("problems-toggle").setAttribute("aria-expanded", String(open));
|
|
508
|
+
pane.editor.layout();
|
|
509
|
+
}
|
|
510
|
+
on($("problems-toggle"), "click", () => setProblemsOpen(!state.problemsOpen, true));
|
|
511
|
+
let part;
|
|
512
|
+
function paintProblems() {
|
|
513
|
+
const list = $("problems-list");
|
|
514
|
+
list.replaceChildren();
|
|
515
|
+
const errs = state.problems.filter((p) => p.severity === "error").length;
|
|
516
|
+
const warns = state.problems.length - errs;
|
|
517
|
+
$("problems-label").textContent = state.problems.length ? `Problems \xB7 ${errs} error${errs === 1 ? "" : "s"}, ${warns} warning${warns === 1 ? "" : "s"}` : "No problems";
|
|
518
|
+
const had = state.problemsSeen;
|
|
519
|
+
const A = part?.attention?.();
|
|
520
|
+
state.problemsSeen = state.problems.length + (A?.count ?? 0);
|
|
521
|
+
const attn = A?.opens ?? 0;
|
|
522
|
+
if (A?.still && !state.problems.length) setProblemsOpen(state.problemsOpen, false);
|
|
523
|
+
else if (!state.problems.length && !attn && bottomTab === "problems") setProblemsOpen(false, false);
|
|
524
|
+
else if ((state.problems.length || attn) && !had) setProblemsOpen(true, false);
|
|
525
|
+
else setProblemsOpen(state.problemsOpen, false);
|
|
526
|
+
$("st-problems").textContent = `${errs} \u2715 ${warns} \u26A0`;
|
|
527
|
+
$("st-problems").className = errs ? "bad" : warns ? "warn" : "ok";
|
|
528
|
+
if (A?.rows.length) {
|
|
529
|
+
list.append(...A.rows);
|
|
530
|
+
if (state.problems.length) list.append(h("div", { class: "prob-head" }, "In the file"));
|
|
531
|
+
}
|
|
532
|
+
$("problems-label").textContent = (state.problems.length ? $("problems-label").textContent : A?.count ? "" : "No problems") + (A?.count ? `${state.problems.length ? " \xB7 " : ""}${A.label}` : "");
|
|
533
|
+
for (const p of state.problems) {
|
|
534
|
+
const b = h(
|
|
535
|
+
"button",
|
|
536
|
+
{ type: "button", class: `prob ${p.severity}${p.file ? " other-file" : ""}` },
|
|
537
|
+
h("span", { class: "where" }, p.file ? `${p.file} \xB7 line ${p.startLine}` : `${p.startLine}:${p.startCol}`),
|
|
538
|
+
h("span", { class: "msg" }, p.message),
|
|
539
|
+
p.hint ? h("span", { class: "hint" }, p.hint) : null
|
|
540
|
+
);
|
|
541
|
+
if (p.file) b.title = `In ${p.file}, line ${p.startLine}: not in this file`;
|
|
542
|
+
else b.addEventListener("click", () => pane.goToOffset(problemRange(doc.text, p)[0]));
|
|
543
|
+
list.append(b);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
let caretFrame = 0;
|
|
547
|
+
const paintCaret = () => {
|
|
548
|
+
if (caretFrame) return;
|
|
549
|
+
caretFrame = requestAnimationFrame(() => {
|
|
550
|
+
caretFrame = 0;
|
|
551
|
+
const p = pane.caret();
|
|
552
|
+
$("st-pos").textContent = p ? `Ln ${p.line}, Col ${p.col}` : "";
|
|
553
|
+
});
|
|
554
|
+
};
|
|
555
|
+
const paintPathLater = later(() => paintPath());
|
|
556
|
+
function paintPath() {
|
|
557
|
+
const path = pane.pathAtCaret();
|
|
558
|
+
$("st-path").textContent = path.length ? path.join(" \u203A ") : "";
|
|
559
|
+
$("st-path").title = toPointer(path);
|
|
560
|
+
$("st-kind").textContent = K.kindLabel(doc.text);
|
|
561
|
+
}
|
|
562
|
+
const wireCaret = () => pane.onCaret(() => {
|
|
563
|
+
paintCaret();
|
|
564
|
+
paintPathLater();
|
|
565
|
+
});
|
|
566
|
+
wireCaret();
|
|
567
|
+
cleanups.push(doc.on((c) => {
|
|
568
|
+
paintCaret();
|
|
569
|
+
if (isTyping(c)) paintPathLater();
|
|
570
|
+
else paintPathLater.now();
|
|
571
|
+
}));
|
|
572
|
+
{
|
|
573
|
+
const g = $("grip");
|
|
574
|
+
const move = (dy) => {
|
|
575
|
+
const hh = Math.min(Math.max($("problems").getBoundingClientRect().height - dy, 48), innerHeight * 0.6);
|
|
576
|
+
root.style.setProperty("--problems-h", `${hh}px`);
|
|
577
|
+
store.set("problems-h", String(Math.round(hh)));
|
|
578
|
+
};
|
|
579
|
+
const saved = store.get("problems-h");
|
|
580
|
+
if (saved) root.style.setProperty("--problems-h", `${saved}px`);
|
|
581
|
+
on(g, "pointerdown", (e) => {
|
|
582
|
+
g.setPointerCapture(e.pointerId);
|
|
583
|
+
let y = e.clientY;
|
|
584
|
+
const mv = (ev) => {
|
|
585
|
+
move(ev.clientY - y);
|
|
586
|
+
y = ev.clientY;
|
|
587
|
+
};
|
|
588
|
+
const up = () => {
|
|
589
|
+
g.removeEventListener("pointermove", mv);
|
|
590
|
+
g.removeEventListener("pointerup", up);
|
|
591
|
+
};
|
|
592
|
+
g.addEventListener("pointermove", mv);
|
|
593
|
+
g.addEventListener("pointerup", up);
|
|
594
|
+
});
|
|
595
|
+
on(g, "keydown", (e) => {
|
|
596
|
+
if (e.key === "ArrowUp") {
|
|
597
|
+
move(-16);
|
|
598
|
+
e.preventDefault();
|
|
599
|
+
}
|
|
600
|
+
if (e.key === "ArrowDown") {
|
|
601
|
+
move(16);
|
|
602
|
+
e.preventDefault();
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
part = S.part?.({
|
|
607
|
+
root,
|
|
608
|
+
byId: $,
|
|
609
|
+
doc,
|
|
610
|
+
store,
|
|
611
|
+
note,
|
|
612
|
+
watch,
|
|
613
|
+
on: (t, ev, fn) => on(t, ev, fn),
|
|
614
|
+
disposed: () => disposed,
|
|
615
|
+
paintProblems: () => paintProblems(),
|
|
616
|
+
paintProps: () => props.paint()
|
|
617
|
+
}, { canvas: () => canvas, objectPath: resourcePath });
|
|
618
|
+
function setReadOnly(ro) {
|
|
619
|
+
ro = ro || !F.edit;
|
|
620
|
+
state.readOnly = ro;
|
|
621
|
+
root.classList.toggle("read-only", ro);
|
|
622
|
+
$("ro").hidden = !ro;
|
|
623
|
+
pane.setReadOnly(ro);
|
|
624
|
+
paintTitle();
|
|
625
|
+
paintHistory();
|
|
626
|
+
}
|
|
627
|
+
function paintFeatures() {
|
|
628
|
+
$("views").hidden = !(F.text && F.canvas);
|
|
629
|
+
$("right").hidden = $("right-grip").hidden = !F.edit;
|
|
630
|
+
$("tab-plan").hidden = !F.plan;
|
|
631
|
+
root.dataset.features = Object.keys(F).sort().join(" ");
|
|
632
|
+
}
|
|
633
|
+
if (!F.plan && bottomTab === "plan") bottomTab = "problems";
|
|
634
|
+
setBottomTab(bottomTab);
|
|
635
|
+
paintFeatures();
|
|
636
|
+
setView(state.view);
|
|
637
|
+
applyTheme();
|
|
638
|
+
setReadOnly(state.readOnly);
|
|
639
|
+
doc.load(opts.text ?? "");
|
|
640
|
+
part?.start?.();
|
|
641
|
+
paintTitle();
|
|
642
|
+
paintHistory();
|
|
643
|
+
const LATE = S.late;
|
|
644
|
+
let adding = Promise.resolve();
|
|
645
|
+
async function addFeatures(names) {
|
|
646
|
+
const bad = names.filter((n) => !S.names.includes(n));
|
|
647
|
+
if (bad.length) throw new Error(`unknown feature ${bad.join(", ")}: the features are ${S.names.join(", ")}`);
|
|
648
|
+
const run = adding.then(async () => {
|
|
649
|
+
if (disposed) throw new Error("the editor was disposed");
|
|
650
|
+
const want = [...new Set(names)].filter((n) => !F[n]);
|
|
651
|
+
if (!want.length) return;
|
|
652
|
+
const late = want.filter((n) => !LATE.includes(n));
|
|
653
|
+
if (late.length) throw new Error(`${late.join(", ")} can't be added to a mounted editor (only ${LATE.join(" and ")} can): mount with ${late.length > 1 ? "them" : "it"}`);
|
|
654
|
+
if (!load) throw new Error(`this build has no loader for ${want.join(", ")}: mount with ${want.length > 1 ? "them" : "it"}`);
|
|
655
|
+
const got = await load(want);
|
|
656
|
+
if (disposed) throw new Error("the editor was disposed");
|
|
657
|
+
const sel = doc.selection.slice();
|
|
658
|
+
for (const f of got) F[f.name] = f;
|
|
659
|
+
if (want.includes("text")) {
|
|
660
|
+
pane.dispose();
|
|
661
|
+
pane = makePane();
|
|
662
|
+
wireCaret();
|
|
663
|
+
pane.setReadOnly(state.readOnly);
|
|
664
|
+
pane.setProblems(state.problems.filter((p) => !p.file));
|
|
665
|
+
applyTheme();
|
|
666
|
+
if (sel.length) doc.select(sel, "menu");
|
|
667
|
+
}
|
|
668
|
+
if (want.includes("plan")) {
|
|
669
|
+
planUI = makePlan();
|
|
670
|
+
paintPlan();
|
|
671
|
+
}
|
|
672
|
+
paintFeatures();
|
|
673
|
+
setView(wanted);
|
|
674
|
+
paintPath();
|
|
675
|
+
});
|
|
676
|
+
adding = run.catch(() => void 0);
|
|
677
|
+
return run;
|
|
678
|
+
}
|
|
679
|
+
const internal = {
|
|
680
|
+
root,
|
|
681
|
+
doc,
|
|
682
|
+
get pane() {
|
|
683
|
+
return pane;
|
|
684
|
+
},
|
|
685
|
+
tree,
|
|
686
|
+
canvas,
|
|
687
|
+
props,
|
|
688
|
+
clip,
|
|
689
|
+
state,
|
|
690
|
+
check,
|
|
691
|
+
save,
|
|
692
|
+
note,
|
|
693
|
+
setView,
|
|
694
|
+
showBanner,
|
|
695
|
+
hideBanner,
|
|
696
|
+
keySheet: sheet,
|
|
697
|
+
setTheme,
|
|
698
|
+
setDensity,
|
|
699
|
+
setBottomTab,
|
|
700
|
+
markers: () => {
|
|
701
|
+
const M = pane.monaco;
|
|
702
|
+
return M.editor.getModelMarkers({ resource: pane.model.uri }).map((m) => ({ severity: m.severity, message: m.message, line: m.startLineNumber, col: m.startColumn, endCol: m.endColumn }));
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
if (S.internal) Object.defineProperties(internal, Object.getOwnPropertyDescriptors(S.internal));
|
|
706
|
+
if (part) Object.defineProperties(internal, Object.getOwnPropertyDescriptors(part.api));
|
|
707
|
+
return {
|
|
708
|
+
internal,
|
|
709
|
+
getText: () => doc.text,
|
|
710
|
+
setText(text) {
|
|
711
|
+
hideBanner();
|
|
712
|
+
doc.load(text);
|
|
713
|
+
doc.markClean();
|
|
714
|
+
paintTitle();
|
|
715
|
+
paintHistory();
|
|
716
|
+
},
|
|
717
|
+
setReadOnly,
|
|
718
|
+
setTheme,
|
|
719
|
+
addFeatures,
|
|
720
|
+
fit() {
|
|
721
|
+
if (!disposed) canvas.fit();
|
|
722
|
+
},
|
|
723
|
+
dispose() {
|
|
724
|
+
if (disposed) return;
|
|
725
|
+
disposed = true;
|
|
726
|
+
clearTimeout(timer);
|
|
727
|
+
clearTimeout(noteTimer);
|
|
728
|
+
part?.dispose?.();
|
|
729
|
+
cancelAnimationFrame(caretFrame);
|
|
730
|
+
paintPathLater.cancel();
|
|
731
|
+
closeMenu();
|
|
732
|
+
for (const c of cleanups.splice(0)) c();
|
|
733
|
+
tree.dispose();
|
|
734
|
+
props.dispose();
|
|
735
|
+
canvas.dispose();
|
|
736
|
+
pane.dispose();
|
|
737
|
+
root.remove();
|
|
738
|
+
setLayer(null);
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function noText() {
|
|
743
|
+
const none = () => void 0;
|
|
744
|
+
return {
|
|
745
|
+
setTheme: none,
|
|
746
|
+
setReadOnly: none,
|
|
747
|
+
setProblems: none,
|
|
748
|
+
goTo: none,
|
|
749
|
+
goToOffset: none,
|
|
750
|
+
focus: none,
|
|
751
|
+
dispose: none,
|
|
752
|
+
onCaret: none,
|
|
753
|
+
caret: () => void 0,
|
|
754
|
+
pathAtCaret: () => [],
|
|
755
|
+
editor: { layout: none, focus: none },
|
|
756
|
+
model: void 0,
|
|
757
|
+
monaco: void 0,
|
|
758
|
+
resyncs: () => 0
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
function noCanvas(more = {}) {
|
|
762
|
+
const fixed = { palette: void 0, doc: void 0, stage: void 0, ...more };
|
|
763
|
+
return new Proxy({}, { get: (_t, k) => k in fixed ? fixed[k] : () => void 0 });
|
|
764
|
+
}
|
|
765
|
+
export {
|
|
766
|
+
mountEditor
|
|
767
|
+
};
|