@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
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const PLAIN_ICON_SVG = {
|
|
2
|
+
"arrow-up-right": '<path d="M7 7h10v10" /> <path d="M7 17 17 7" />',
|
|
3
|
+
"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" />',
|
|
4
|
+
"chevron-down": '<path d="m6 9 6 6 6-6" />',
|
|
5
|
+
"chevron-right": '<path d="m9 18 6-6-6-6" />',
|
|
6
|
+
"circle-dot": '<circle cx="12" cy="12" r="1" /> <circle cx="12" cy="12" r="10" />',
|
|
7
|
+
"circle-x": '<circle cx="12" cy="12" r="10" /> <path d="m15 9-6 6" /> <path d="m9 9 6 6" />',
|
|
8
|
+
"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" />',
|
|
9
|
+
"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" />',
|
|
10
|
+
"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" />',
|
|
11
|
+
"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" />',
|
|
12
|
+
"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" />',
|
|
13
|
+
"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" />',
|
|
14
|
+
"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" />',
|
|
15
|
+
"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" />',
|
|
16
|
+
"panel-right": '<rect width="18" height="18" x="3" y="3" rx="2" /> <path d="M15 3v18" />',
|
|
17
|
+
"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" />',
|
|
18
|
+
"plus": '<path d="M5 12h14" /> <path d="M12 5v14" />',
|
|
19
|
+
"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" />',
|
|
20
|
+
"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" />',
|
|
21
|
+
"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" />',
|
|
22
|
+
"x": '<path d="M18 6 6 18" /> <path d="m6 6 12 12" />'
|
|
23
|
+
};
|
|
24
|
+
const PLAIN_ICONS = Object.keys(PLAIN_ICON_SVG);
|
|
25
|
+
const iconSymbols = (svgs) => Object.entries(svgs).map(([n, body]) => `<symbol id="se-i-${n}" viewBox="0 0 24 24">${body}</symbol>`).join("");
|
|
26
|
+
const spriteOf = (symbols) => `<svg xmlns="http://www.w3.org/2000/svg" class="sprite" aria-hidden="true" focusable="false">${symbols}</svg>`;
|
|
27
|
+
const PLAIN_SPRITE = spriteOf(iconSymbols(PLAIN_ICON_SVG));
|
|
28
|
+
export {
|
|
29
|
+
PLAIN_ICONS,
|
|
30
|
+
PLAIN_ICON_SVG,
|
|
31
|
+
PLAIN_SPRITE,
|
|
32
|
+
iconSymbols,
|
|
33
|
+
spriteOf
|
|
34
|
+
};
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { later, isTyping } from "./later.js";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { h, icon } from "./icons.js";
|
|
4
|
+
import { composite, run } from "./actions.js";
|
|
5
|
+
import { flowText } from "../splice.js";
|
|
6
|
+
import { fromPointer, toPointer } from "../path.js";
|
|
7
|
+
const getIn = (o, p) => p.reduce((x, k) => x && typeof x === "object" ? x[k] : void 0, o);
|
|
8
|
+
const isMap = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
9
|
+
const MIXED = /* @__PURE__ */ Symbol("mixed");
|
|
10
|
+
function propsPanel(body, doc, opts) {
|
|
11
|
+
let pendingFocus;
|
|
12
|
+
let focusInput = false;
|
|
13
|
+
const K = opts.kit, ui = K.ui;
|
|
14
|
+
const { setCmd, deleteCmd, insertItemCmd, referencesTo, describe } = K.commands;
|
|
15
|
+
const { deletePaths, renameDialog } = K.actions;
|
|
16
|
+
const kindOf = (k) => K.kinds.find((x) => x.kind === k);
|
|
17
|
+
const singular = (k) => kindOf(k)?.singular ?? "item";
|
|
18
|
+
const names = (s) => Object.keys(getIn(doc.goodDoc.data, kindOf(s)?.section ?? []) ?? {}).filter((k) => !k.startsWith("x-"));
|
|
19
|
+
const apply = (c) => run(doc, c, "props", opts.note);
|
|
20
|
+
function paint() {
|
|
21
|
+
if (body.contains(document.activeElement) && document.activeElement.matches("input, textarea")) return;
|
|
22
|
+
body.replaceChildren();
|
|
23
|
+
const sel = doc.selection;
|
|
24
|
+
if (!sel.length) {
|
|
25
|
+
body.append(h("p", { class: "hint" }, "Select something in the canvas, the tree or the text."));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const res = sel.map((p2) => K.objectOf(toPointer(p2)));
|
|
29
|
+
if (sel.length > 1) {
|
|
30
|
+
const kinds = new Set(res.map((r2) => r2?.kind));
|
|
31
|
+
if (kinds.size === 1 && res.every((r2) => r2 && r2.path === toPointer(fromPointer(r2.path)))) {
|
|
32
|
+
const paths = [...new Set(res.map((r2) => r2.path))].map(fromPointer);
|
|
33
|
+
body.append(h("div", { class: "sel-title" }, `${paths.length} ${singular(res[0].kind)}s`), h("div", { class: "sel-path" }, paths.map((p2) => p2[p2.length - 1]).join(", ")));
|
|
34
|
+
form(paths, res[0].kind);
|
|
35
|
+
} else {
|
|
36
|
+
body.append(h("div", { class: "sel-title" }, `${sel.length} items`), h("ul", { class: "plain" }, ...sel.map((p2) => h("li", null, h("code", null, p2.join(".") || ui.rootItem)))));
|
|
37
|
+
}
|
|
38
|
+
deleteButton();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const p = sel[0];
|
|
42
|
+
const r = res[0];
|
|
43
|
+
const target = r ? fromPointer(r.path) : p.length ? p : [];
|
|
44
|
+
if (!r) {
|
|
45
|
+
settings(p);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const head = h("div", { class: "sel-headrow" }, h("div", { class: "sel-title" }, describe(target)));
|
|
49
|
+
const rn = h("button", { type: "button", class: "btn sm quiet icon-only", "aria-label": `Rename ${describe(target)}`, title: "Rename (F2)" }, icon("pencil"));
|
|
50
|
+
rn.addEventListener("click", () => renameDialog(doc, target, "props", opts.note));
|
|
51
|
+
head.append(rn);
|
|
52
|
+
body.append(head);
|
|
53
|
+
if (toPointer(p) !== r.path) pendingFocus = toPointer(p);
|
|
54
|
+
form([target], r.kind);
|
|
55
|
+
uses(r.kind, r.name);
|
|
56
|
+
problemsFor(r.path);
|
|
57
|
+
deleteButton();
|
|
58
|
+
}
|
|
59
|
+
function form(paths, section) {
|
|
60
|
+
const nav = opts.nav();
|
|
61
|
+
const data = doc.goodDoc.data;
|
|
62
|
+
const values = paths.map((p) => getIn(data, p) ?? {});
|
|
63
|
+
const present = values[0] && isMap(values[0]) ? values[0] : {};
|
|
64
|
+
const ext = values.some((v) => ui.isExternal(v));
|
|
65
|
+
const keys = nav.keys(paths[0], ext ? { external: true } : present);
|
|
66
|
+
const order = Object.keys(present);
|
|
67
|
+
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));
|
|
68
|
+
const read = opts.read();
|
|
69
|
+
const shown = /* @__PURE__ */ new Set([...written.map((k) => k.name), ...ui.important(section, values[0] ?? {}, ext), ...paths.length === 1 && read !== void 0 && ui.inheritedKeys ? ui.inheritedKeys(paths[0], read) : []]);
|
|
70
|
+
const rest = keys.filter((k) => !written.includes(k) && shown.has(k.name));
|
|
71
|
+
const more = keys.filter((k) => !shown.has(k.name));
|
|
72
|
+
const sec = h("div", { class: "props" });
|
|
73
|
+
for (const k of [...written, ...rest]) sec.append(field(paths, section, k, values, read));
|
|
74
|
+
if (more.length && doc.doc.ok) {
|
|
75
|
+
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)));
|
|
76
|
+
add.addEventListener("change", () => {
|
|
77
|
+
const name = add.value;
|
|
78
|
+
if (!name) return;
|
|
79
|
+
const v = nav.defaultFor([...paths[0], name]);
|
|
80
|
+
pendingFocus = toPointer([...paths[0], name]);
|
|
81
|
+
focusInput = true;
|
|
82
|
+
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))));
|
|
83
|
+
});
|
|
84
|
+
sec.append(add);
|
|
85
|
+
}
|
|
86
|
+
const known = new Set(keys.map((k) => k.name));
|
|
87
|
+
for (const name of new Set(values.flatMap((v) => isMap(v) ? Object.keys(v) : []))) {
|
|
88
|
+
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));
|
|
89
|
+
}
|
|
90
|
+
body.append(sec);
|
|
91
|
+
if (pendingFocus) {
|
|
92
|
+
const f = sec.querySelector(`[data-path="${CSS.escape(pendingFocus)}"]`);
|
|
93
|
+
f?.classList.add("focus-row");
|
|
94
|
+
f?.scrollIntoView({ block: "nearest" });
|
|
95
|
+
if (focusInput) f?.querySelector("input, select, textarea")?.focus({ preventScroll: true });
|
|
96
|
+
pendingFocus = void 0;
|
|
97
|
+
focusInput = false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function field(paths, section, k, values, read) {
|
|
101
|
+
const nav = opts.nav();
|
|
102
|
+
const own = values.map((v) => isMap(v) ? v[k.name] : void 0);
|
|
103
|
+
const same = own.every((x) => JSON.stringify(x) === JSON.stringify(own[0]));
|
|
104
|
+
const value = same ? own[0] : MIXED;
|
|
105
|
+
const isWritten = own.some((x) => x !== void 0);
|
|
106
|
+
const inherited = section && paths.length === 1 && read !== void 0 ? ui.inherited?.(paths[0], k.name, read) : void 0;
|
|
107
|
+
const ptrs = paths.map((p) => toPointer([...p, k.name]));
|
|
108
|
+
const row = h("div", { class: `prow${isWritten ? "" : " unset"}`, "data-path": ptrs[0] });
|
|
109
|
+
const label = h("label", { class: "plabel", title: k.doc?.replace(/`/g, "") ?? "" }, k.name);
|
|
110
|
+
const id = `pf-${Math.random().toString(36).slice(2, 8)}`;
|
|
111
|
+
label.setAttribute("for", id);
|
|
112
|
+
row.append(label);
|
|
113
|
+
const set = (v, lbl) => 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))));
|
|
114
|
+
const unset = () => {
|
|
115
|
+
const ps = paths.filter((_, i) => own[i] !== void 0);
|
|
116
|
+
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]))));
|
|
117
|
+
};
|
|
118
|
+
const slot = K.slotAt(toPointer([...paths[0], k.name]));
|
|
119
|
+
const itemSlot = K.slotAt(toPointer([...paths[0], k.name, 0]));
|
|
120
|
+
const vals = nav.values([...paths[0], k.name]);
|
|
121
|
+
const types = nav.types([...paths[0], k.name]);
|
|
122
|
+
let control;
|
|
123
|
+
const placeholder = value === MIXED ? "(mixed)" : "";
|
|
124
|
+
if (slot || vals.length) {
|
|
125
|
+
const choices = [.../* @__PURE__ */ new Set([...vals, ...slot ? slot.targets.flatMap((s) => names(s).map((n) => slot.write ? slot.write(n) : n)).concat(slot.extra ?? []) : []])];
|
|
126
|
+
const sel = h("select", { id, class: "pinput" });
|
|
127
|
+
sel.append(h("option", { value: "\0" }, placeholder || "\u2014"));
|
|
128
|
+
for (const c of choices) sel.append(h("option", { value: c }, c));
|
|
129
|
+
if (value !== MIXED && value !== void 0 && !choices.includes(String(value))) sel.append(h("option", { value: String(value) }, String(value)));
|
|
130
|
+
sel.value = value === MIXED || value === void 0 ? "\0" : String(value);
|
|
131
|
+
sel.addEventListener("change", () => {
|
|
132
|
+
if (sel.value === "\0") {
|
|
133
|
+
if (isWritten) unset();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
set(vals.includes("true") && (sel.value === "true" || sel.value === "false") ? sel.value === "true" : sel.value);
|
|
137
|
+
});
|
|
138
|
+
control = sel;
|
|
139
|
+
} else if (itemSlot && paths.length === 1) {
|
|
140
|
+
const list = Array.isArray(value) ? value : [];
|
|
141
|
+
const wrap = h("div", { class: "chips" });
|
|
142
|
+
list.forEach((v, i) => {
|
|
143
|
+
const x = h("button", { type: "button", class: "chip-x", "aria-label": `Remove ${v}` }, "\xD7");
|
|
144
|
+
x.addEventListener("click", () => apply({ ...deleteCmd([...paths[0], k.name, i]), label: `Remove ${v} from ${describe([...paths[0], k.name])}` }));
|
|
145
|
+
wrap.append(h("span", { class: "chip" }, String(v), x));
|
|
146
|
+
});
|
|
147
|
+
const can = [...new Set(itemSlot.targets.flatMap((s) => names(s)).concat(itemSlot.extra ?? []))].filter((n) => !list.includes(n));
|
|
148
|
+
if (can.length) {
|
|
149
|
+
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)));
|
|
150
|
+
add.addEventListener("change", () => {
|
|
151
|
+
if (add.value) apply(insertItemCmd([...paths[0], k.name], add.value, void 0, `Add ${add.value} to ${describe([...paths[0], k.name])}`));
|
|
152
|
+
});
|
|
153
|
+
wrap.append(add);
|
|
154
|
+
}
|
|
155
|
+
control = wrap;
|
|
156
|
+
} else if (k.name === "prompt" || typeof value === "string" && value.includes("\n")) {
|
|
157
|
+
const ta = h("textarea", { id, class: "pinput", rows: "5", spellcheck: "false", placeholder });
|
|
158
|
+
ta.value = typeof value === "string" ? value : "";
|
|
159
|
+
ta.addEventListener("change", () => {
|
|
160
|
+
const v = ta.value;
|
|
161
|
+
if (v === "" && isWritten) unset();
|
|
162
|
+
else if (v !== value) set(v.endsWith("\n") || !v.includes("\n") ? v : v + "\n");
|
|
163
|
+
});
|
|
164
|
+
control = ta;
|
|
165
|
+
} else if (k.shape === "scalar" && (value === void 0 || value === MIXED || typeof value !== "object")) {
|
|
166
|
+
const inp = h("input", { id, class: "pinput", type: types.has("integer") || types.has("number") ? "number" : "text", spellcheck: "false", autocomplete: "off", placeholder });
|
|
167
|
+
inp.value = value === void 0 || value === MIXED ? "" : String(value);
|
|
168
|
+
inp.addEventListener("change", () => {
|
|
169
|
+
const raw = inp.value;
|
|
170
|
+
if (raw === "") {
|
|
171
|
+
if (isWritten) unset();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const v = (types.has("integer") || types.has("number")) && /^-?\d+(\.\d+)?$/.test(raw) ? Number(raw) : raw;
|
|
175
|
+
if (v !== value) set(v);
|
|
176
|
+
});
|
|
177
|
+
inp.addEventListener("keydown", (e) => {
|
|
178
|
+
if (e.key === "Enter") inp.blur();
|
|
179
|
+
});
|
|
180
|
+
control = inp;
|
|
181
|
+
} else {
|
|
182
|
+
const inp = h("input", { id, class: "pinput mono", spellcheck: "false", autocomplete: "off", placeholder: placeholder || (k.shape === "list" ? "[a, b]" : "{ key: value }") });
|
|
183
|
+
inp.value = value === void 0 || value === MIXED ? "" : flowText(value);
|
|
184
|
+
inp.addEventListener("change", () => {
|
|
185
|
+
if (inp.value.trim() === "") {
|
|
186
|
+
if (isWritten) unset();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
let v;
|
|
190
|
+
try {
|
|
191
|
+
v = parseYaml(inp.value);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
inp.setAttribute("aria-invalid", "true");
|
|
194
|
+
inp.title = `Not YAML: ${e.message}`;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
inp.removeAttribute("aria-invalid");
|
|
198
|
+
if (JSON.stringify(v) !== JSON.stringify(value)) set(v);
|
|
199
|
+
});
|
|
200
|
+
inp.addEventListener("keydown", (e) => {
|
|
201
|
+
if (e.key === "Enter") inp.blur();
|
|
202
|
+
});
|
|
203
|
+
control = inp;
|
|
204
|
+
}
|
|
205
|
+
const full = value === void 0 || value === MIXED ? "" : display(value);
|
|
206
|
+
if (full) control.title = full;
|
|
207
|
+
if (inherited && !isWritten) {
|
|
208
|
+
row.classList.add("inherited");
|
|
209
|
+
row.append(h("div", { class: "pinherit", title: display(inherited.value) }, display(inherited.value)));
|
|
210
|
+
const line = h("div", { class: "pfrom" }, `inherited from ${inherited.from ?? ui.inheritedFrom}`);
|
|
211
|
+
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");
|
|
212
|
+
o.addEventListener("click", () => {
|
|
213
|
+
pendingFocus = ptrs[0];
|
|
214
|
+
focusInput = true;
|
|
215
|
+
set(inherited.value, `Override ${describe([...paths[0], k.name])}`);
|
|
216
|
+
});
|
|
217
|
+
row.append(line, o);
|
|
218
|
+
const probs0 = opts.problems().filter((pr) => ptrs.some((ptr) => pr.path === ptr || pr.path.startsWith(ptr + "/")));
|
|
219
|
+
for (const pr of probs0) row.append(h("div", { class: `pprob ${pr.severity}` }, icon(pr.severity === "error" ? "circle-x" : "triangle-alert"), pr.message));
|
|
220
|
+
return row;
|
|
221
|
+
}
|
|
222
|
+
row.append(control);
|
|
223
|
+
const acts = h("span", { class: "pacts" });
|
|
224
|
+
if (inherited && isWritten) {
|
|
225
|
+
const o = h("button", { type: "button", class: "btn sm quiet", title: `Remove this file's value: ${display(inherited.value)} applies again` }, "Reset");
|
|
226
|
+
o.addEventListener("click", unset);
|
|
227
|
+
acts.append(o);
|
|
228
|
+
} else if (isWritten && control.tagName !== "SELECT") {
|
|
229
|
+
const o = h("button", { type: "button", class: "btn sm quiet icon-only", "aria-label": `Remove ${k.name}`, title: `Remove ${k.name}` }, icon("x"));
|
|
230
|
+
o.addEventListener("click", unset);
|
|
231
|
+
acts.append(o);
|
|
232
|
+
}
|
|
233
|
+
row.append(acts);
|
|
234
|
+
if (inherited) row.append(h("div", { class: "pfrom" }, `overrides ${display(inherited.value)} from ${inherited.from ?? ui.inheritedFrom}`));
|
|
235
|
+
const probs = opts.problems().filter((pr) => ptrs.some((ptr) => pr.path === ptr || pr.path.startsWith(ptr + "/")));
|
|
236
|
+
for (const pr of probs) row.append(h("div", { class: `pprob ${pr.severity}` }, icon(pr.severity === "error" ? "circle-x" : "triangle-alert"), pr.message));
|
|
237
|
+
return row;
|
|
238
|
+
}
|
|
239
|
+
const display = (v) => v === null || typeof v !== "object" ? String(v) : flowText(v);
|
|
240
|
+
function nowSection(ptr) {
|
|
241
|
+
const rows = opts.now && ui.facts ? ui.facts(opts.now(ptr)) : void 0;
|
|
242
|
+
if (!rows) return;
|
|
243
|
+
body.append(h("div", { class: "sel-head" }, "Now"));
|
|
244
|
+
if (!rows.length) {
|
|
245
|
+
body.append(h("p", { class: "hint now-unknown" }, "Not known: the host has said nothing about it."));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const dl = h("dl", { class: "now" });
|
|
249
|
+
for (const r of rows) dl.append(h("dt", null, r.term), h("dd", r.cls ? { class: r.cls } : null, r.def));
|
|
250
|
+
body.append(dl);
|
|
251
|
+
}
|
|
252
|
+
function uses(section, name) {
|
|
253
|
+
nowSection(toPointer([...kindOf(section)?.section ?? [], name]));
|
|
254
|
+
const refs = referencesTo(doc.text, section, name);
|
|
255
|
+
body.append(h("div", { class: "sel-head" }, refs.length ? `Used in ${refs.length} place${refs.length > 1 ? "s" : ""}` : "Not referenced"));
|
|
256
|
+
if (!refs.length) return;
|
|
257
|
+
const ul = h("ul", { class: "plain sel-refs" });
|
|
258
|
+
for (const r of refs) {
|
|
259
|
+
const b = h("button", { type: "button", class: "linkish" }, r.path.slice(1).replace(/\//g, "."));
|
|
260
|
+
b.addEventListener("click", () => doc.select([fromPointer(r.path)], "props"));
|
|
261
|
+
ul.append(h("li", null, b, h("span", { class: "hint" }, ` ${r.slot.what}`)));
|
|
262
|
+
}
|
|
263
|
+
body.append(ul);
|
|
264
|
+
}
|
|
265
|
+
function problemsFor(ptr) {
|
|
266
|
+
const mine = opts.problems().filter((x) => x.path === ptr && !x.file);
|
|
267
|
+
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))));
|
|
268
|
+
}
|
|
269
|
+
function deleteButton() {
|
|
270
|
+
if (!doc.doc.ok || !doc.selection.some((p) => p.length)) return;
|
|
271
|
+
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");
|
|
272
|
+
b.addEventListener("click", () => deletePaths(doc, doc.selection, "props", opts.note));
|
|
273
|
+
body.append(b);
|
|
274
|
+
}
|
|
275
|
+
function settings(p) {
|
|
276
|
+
const nav = opts.nav();
|
|
277
|
+
body.append(h("div", { class: "sel-title" }, p.length ? describe(p) : ui.rootTitle), h("code", { class: "sel-path" }, p.join(".") || "(the whole file)"));
|
|
278
|
+
const words = nav.hover(p);
|
|
279
|
+
if (words && p.length) body.append(h("p", { class: "sel-doc" }, words.split("\n\n")[0].replace(/`/g, "")));
|
|
280
|
+
const v = getIn(doc.goodDoc.data, p);
|
|
281
|
+
const isSection = K.kinds.some((k) => toPointer(k.section) === toPointer(p));
|
|
282
|
+
if (isSection) {
|
|
283
|
+
const n = isMap(v) ? Object.keys(v).length : 0;
|
|
284
|
+
body.append(h("p", null, `${n} ${n === 1 ? "entry" : "entries"}. Add one from the tree's +, or the canvas's menu.`));
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const holder = !p.length ? [] : isMap(v) ? p : p.slice(0, -1);
|
|
288
|
+
const val = getIn(doc.goodDoc.data, holder);
|
|
289
|
+
if (!isMap(val) && holder.length) return;
|
|
290
|
+
const sectionTops = new Set(K.kinds.map((k) => String(k.section[0])));
|
|
291
|
+
const keys = nav.keys(holder, val ?? {}).filter((k) => !sectionTops.has(k.name) || holder.length);
|
|
292
|
+
const sec = h("div", { class: "props" });
|
|
293
|
+
for (const k of keys) sec.append(field([holder], "", k, [val ?? {}], void 0));
|
|
294
|
+
body.append(sec);
|
|
295
|
+
if (p.length && toPointer(p) !== toPointer(holder)) {
|
|
296
|
+
const f = sec.querySelector(`[data-path="${CSS.escape(toPointer(p))}"]`);
|
|
297
|
+
f?.classList.add("focus-row");
|
|
298
|
+
f?.scrollIntoView({ block: "nearest" });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
body.addEventListener("focusout", () => setTimeout(() => {
|
|
302
|
+
if (!body.contains(document.activeElement)) paint();
|
|
303
|
+
}, 0));
|
|
304
|
+
doc.onSelect(() => paint());
|
|
305
|
+
const paintLater = later(() => paint());
|
|
306
|
+
doc.on((c) => {
|
|
307
|
+
if (isTyping(c)) paintLater();
|
|
308
|
+
else paintLater.now();
|
|
309
|
+
});
|
|
310
|
+
return { paint, dispose: () => paintLater.cancel() };
|
|
311
|
+
}
|
|
312
|
+
export {
|
|
313
|
+
propsPanel
|
|
314
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function blocks(css) {
|
|
2
|
+
const out = [];
|
|
3
|
+
const text = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
4
|
+
let i = 0;
|
|
5
|
+
while (i < text.length) {
|
|
6
|
+
const open = text.indexOf("{", i), semi = text.indexOf(";", i);
|
|
7
|
+
if (open < 0 && semi < 0) break;
|
|
8
|
+
if (semi >= 0 && (open < 0 || semi < open)) {
|
|
9
|
+
const st = text.slice(i, semi).trim();
|
|
10
|
+
if (st) out.push([st, null]);
|
|
11
|
+
i = semi + 1;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
let depth = 1, j = open + 1;
|
|
15
|
+
while (j < text.length && depth) {
|
|
16
|
+
if (text[j] === "{") depth++;
|
|
17
|
+
else if (text[j] === "}") depth--;
|
|
18
|
+
j++;
|
|
19
|
+
}
|
|
20
|
+
out.push([text.slice(i, open).trim(), text.slice(open + 1, j - 1)]);
|
|
21
|
+
i = j;
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
function selectors(list) {
|
|
26
|
+
const out = [];
|
|
27
|
+
let depth = 0, cut = 0;
|
|
28
|
+
for (let i = 0; i < list.length; i++) {
|
|
29
|
+
const c = list[i];
|
|
30
|
+
if (c === "(" || c === "[") depth++;
|
|
31
|
+
else if (c === ")" || c === "]") depth--;
|
|
32
|
+
else if (c === "," && !depth) {
|
|
33
|
+
out.push(list.slice(cut, i).trim());
|
|
34
|
+
cut = i + 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
out.push(list.slice(cut).trim());
|
|
38
|
+
return out.filter(Boolean);
|
|
39
|
+
}
|
|
40
|
+
function scopeOne(sel, root) {
|
|
41
|
+
const r = `.${root}`;
|
|
42
|
+
const m = /^(?:html|body|:root)((?:\[[^\]]*\]|\.[\w-]+|:not\([^)]*\))*)(.*)$/.exec(sel);
|
|
43
|
+
if (m && /^(html|body|:root)(?![\w-])/.test(sel)) return `${r}${m[1]}${m[2].trim() ? " " + m[2].trim() : ""}`;
|
|
44
|
+
if (sel === "*") return `${r}, ${r} *`;
|
|
45
|
+
return `${r} ${sel}`;
|
|
46
|
+
}
|
|
47
|
+
function scopeCss(css, root) {
|
|
48
|
+
let out = "";
|
|
49
|
+
for (const [pre, body] of blocks(css)) {
|
|
50
|
+
if (body === null) {
|
|
51
|
+
if (pre.startsWith("@layer") || pre.startsWith("@import")) out += `${pre};
|
|
52
|
+
`;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (pre.startsWith("@keyframes")) {
|
|
56
|
+
out += `@keyframes se-${pre.slice("@keyframes".length).trim()}{${body}}
|
|
57
|
+
`;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (/^@(layer|media|container|supports)\b/.test(pre)) {
|
|
61
|
+
out += `${pre}{
|
|
62
|
+
${scopeCss(body, root)}}
|
|
63
|
+
`;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (pre.startsWith("@font-face")) {
|
|
67
|
+
out += `${pre}{${body}}
|
|
68
|
+
`;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (pre.startsWith("@")) throw new Error(`the editor's CSS has an at-rule it can't scope: ${pre}`);
|
|
72
|
+
const scoped = [...new Set(selectors(pre).flatMap((s) => scopeOne(s, root).split(", ")))].join(",");
|
|
73
|
+
out += `${scoped}{${body.replace(/\banimation(-name)?:\s*([a-z][\w-]*)/g, (m0, n, k) => k === "none" ? m0 : `animation${n ?? ""}:se-${k}`)}}
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
scopeCss,
|
|
80
|
+
scopeOne
|
|
81
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { toPointer } from "../path.js";
|
|
2
|
+
import { outline } from "../outline.js";
|
|
3
|
+
import { commandsFor } from "../commands.js";
|
|
4
|
+
import { clipboardFor } from "../clipboard.js";
|
|
5
|
+
import { providersFor, docFor, rangeOfPath } from "../providers.js";
|
|
6
|
+
import { analyse } from "../validate.js";
|
|
7
|
+
import { actionsFor } from "./actions.js";
|
|
8
|
+
import { clipboard } from "./clip.js";
|
|
9
|
+
import { propsPanel } from "./props.js";
|
|
10
|
+
import { canvasView } from "./canvas.js";
|
|
11
|
+
import { PLAIN_ICON_SVG, iconSymbols, spriteOf } from "./plain-icons.js";
|
|
12
|
+
const NAME = /^[a-z][a-z0-9-]*$/;
|
|
13
|
+
const PLAIN_WORDS = {
|
|
14
|
+
rootClass: "iso-editor",
|
|
15
|
+
brand: "iso <b>editor</b>",
|
|
16
|
+
sideLabel: "The file",
|
|
17
|
+
canvasLabel: "The file, drawn",
|
|
18
|
+
problemsLabel: "Problems",
|
|
19
|
+
bottomTabsLabel: "Problems",
|
|
20
|
+
extraTab: "Check",
|
|
21
|
+
slots: ""
|
|
22
|
+
};
|
|
23
|
+
const PLAIN_KEYMAP = [
|
|
24
|
+
{ where: "Anywhere in the editor", keys: [["\u2318S", "Save"], ["\u2318Z", "Undo"], ["\u21E7\u2318Z or \u2318Y", "Redo"], ["?", "This sheet"], ["Esc", "Close a menu or dialog"]] },
|
|
25
|
+
{ where: "The tree and the canvas", keys: [["F2", "Rename"], ["\u232B", "Delete"], ["\u2318D", "Duplicate"], ["\u2318\u2191", "Select the parent"]] },
|
|
26
|
+
{ where: "The canvas", keys: [["+ \u2212", "Zoom"], ["0", "Fit"], ["1", "100%"], ["\u21E72", "Zoom to the selection"]] }
|
|
27
|
+
];
|
|
28
|
+
function setupFor(a, v, textPane) {
|
|
29
|
+
const commands = commandsFor(a);
|
|
30
|
+
const nameRule = v.nameRule ?? NAME, nameHint = v.nameHint ?? "a lower-case letter, then lower-case letters, digits and -";
|
|
31
|
+
const icon = v.icon ?? (() => "box");
|
|
32
|
+
const actions = actionsFor({ commands, objectOf: a.objectOf, kinds: a.kinds, nameRule, nameHint });
|
|
33
|
+
const P = providersFor(a);
|
|
34
|
+
const services = { docFor, completionAt: P.completionAt, hoverAt: P.hoverAt, definitionAt: P.definitionAt, rangeOfPath };
|
|
35
|
+
const getIn = (o, p) => p.reduce((x, k) => x && typeof x === "object" ? x[k] : void 0, o);
|
|
36
|
+
const layoutUnder = (data, key) => getIn(data, [key, "layout"]);
|
|
37
|
+
const pins = {
|
|
38
|
+
key: a.pins.key,
|
|
39
|
+
legacyKey: a.pins.legacyKey,
|
|
40
|
+
legacyOnly: a.pins.legacyOnly,
|
|
41
|
+
of: (data) => layoutUnder(data, a.pins.key) ?? (a.pins.legacyKey ? layoutUnder(data, a.pins.legacyKey) : void 0),
|
|
42
|
+
keyOf: (data) => a.pins.legacyOnly(data) && a.pins.legacyKey ? a.pins.legacyKey : a.pins.key
|
|
43
|
+
};
|
|
44
|
+
const read = (text, fileName = v.fileName) => a.read(text, { fileName, role: a.role(text) });
|
|
45
|
+
const tree = {
|
|
46
|
+
outline: (d, role, tags) => outline(d, a, role, tags),
|
|
47
|
+
commands,
|
|
48
|
+
slotAt: a.slotAt,
|
|
49
|
+
kinds: a.kinds,
|
|
50
|
+
entryGroups: a.entryGroups,
|
|
51
|
+
nameRule,
|
|
52
|
+
ui: {
|
|
53
|
+
label: "The file, as a tree",
|
|
54
|
+
rootIcon: "layers",
|
|
55
|
+
kindIcon: icon,
|
|
56
|
+
keyIcon: () => void 0,
|
|
57
|
+
entryIcon: () => "list-tree",
|
|
58
|
+
newItems: (k) => {
|
|
59
|
+
const x = a.kinds.find((y) => y.kind === k);
|
|
60
|
+
return [{ label: `New ${x.singular}`, icon: icon(k) }];
|
|
61
|
+
},
|
|
62
|
+
tagPill: (tag) => ({ title: tag }),
|
|
63
|
+
nameHint,
|
|
64
|
+
text: { root: "File", rootAdd: "the file", renameWhy: "Groups and the file itself have fixed names", deleteWhy: "The file itself stays", duplicateNote: "Duplicate works on objects", duplicateWhy: "Only objects can be duplicated" }
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const props = {
|
|
68
|
+
commands,
|
|
69
|
+
actions,
|
|
70
|
+
slotAt: a.slotAt,
|
|
71
|
+
objectOf: a.objectOf,
|
|
72
|
+
kinds: a.kinds,
|
|
73
|
+
ui: { important: () => [], isExternal: () => false, inheritedFrom: "the base file", extensionDoc: "An extension: ignored by the reader.", rootTitle: "The file", rootItem: "(the file)" }
|
|
74
|
+
};
|
|
75
|
+
const canvasUi = {
|
|
76
|
+
rootClass: "iso-canvas",
|
|
77
|
+
panKeyClass: "pan-key",
|
|
78
|
+
newOrder: a.kinds.map((k) => k.kind),
|
|
79
|
+
palette: a.kinds.map((k) => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
|
|
80
|
+
text: {
|
|
81
|
+
stage: "The file, drawn: arrow keys and Tab move through what is drawn; + and \u2212 zoom, 0 fits",
|
|
82
|
+
dragGroup: "A drag on nothing",
|
|
83
|
+
dragSelectTip: "Drag draws a selection; hold the space key to pan",
|
|
84
|
+
unreadable: "The canvas draws a file that reads cleanly; fix the problems listed to see it.",
|
|
85
|
+
palette: "Add to the file: click, or drag onto the canvas",
|
|
86
|
+
pinHint: "",
|
|
87
|
+
renameWhy: "Only objects are renamed here",
|
|
88
|
+
duplicateWhy: "Only objects are duplicated"
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const canvas = {
|
|
92
|
+
draw: v.draw,
|
|
93
|
+
catalog: v.catalog,
|
|
94
|
+
objectOf: a.objectOf,
|
|
95
|
+
kinds: a.kinds,
|
|
96
|
+
commands,
|
|
97
|
+
actions,
|
|
98
|
+
objectItems: () => [],
|
|
99
|
+
pins,
|
|
100
|
+
ui: canvasUi,
|
|
101
|
+
flat: v.flat,
|
|
102
|
+
trial: (text, theme) => {
|
|
103
|
+
const r = read(text);
|
|
104
|
+
return r.read === void 0 || r.diags.some((d) => d.severity === "error") ? void 0 : v.draw(r.read, r.read.data, theme);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const kit = {
|
|
108
|
+
async check(text) {
|
|
109
|
+
const r = analyse(a, text, { fileName: v.fileName });
|
|
110
|
+
const ok = !r.problems.some((p) => p.severity === "error") && r.read !== void 0;
|
|
111
|
+
return { problems: r.problems, read: r.read, tags: r.tags, model: ok ? r.read : void 0, data: r.read?.data, extra: void 0 };
|
|
112
|
+
},
|
|
113
|
+
role: (text) => a.role(text),
|
|
114
|
+
kindLabel: () => a.id,
|
|
115
|
+
nav: P.navFor,
|
|
116
|
+
objectPath(name, r) {
|
|
117
|
+
const data = r?.data;
|
|
118
|
+
for (const k of a.kinds) if (getIn(data, [...k.section, name]) !== void 0) return toPointer([...k.section, name]);
|
|
119
|
+
return void 0;
|
|
120
|
+
},
|
|
121
|
+
extraLabel: () => ({ text: "", cls: "" }),
|
|
122
|
+
keymap: v.keymap ?? PLAIN_KEYMAP
|
|
123
|
+
};
|
|
124
|
+
const features = {
|
|
125
|
+
canvas: { canvasView: (host, doc, o) => canvasView(host, doc, { ...o, theme: v.theme, kit: canvas, layer: v.layer }) },
|
|
126
|
+
edit: { propsPanel: (body, doc, o) => propsPanel(body, doc, { ...o, kit: props }), clipboard: (doc, note) => clipboard(doc, note, clipboardFor(a)) },
|
|
127
|
+
...textPane ? { text: { textPane: (el, doc, o) => textPane(el, doc, { ...o, services }) } } : {}
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
kit,
|
|
131
|
+
tree,
|
|
132
|
+
words: { ...PLAIN_WORDS, ...v.words },
|
|
133
|
+
features,
|
|
134
|
+
names: ["text", "canvas", "edit"],
|
|
135
|
+
late: ["text"],
|
|
136
|
+
hasExtra: false,
|
|
137
|
+
part: v.part ? (ctx) => v.part(ctx) : void 0,
|
|
138
|
+
sprite: spriteOf(iconSymbols({ ...PLAIN_ICON_SVG, ...v.icons }))
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
PLAIN_KEYMAP,
|
|
143
|
+
PLAIN_WORDS,
|
|
144
|
+
setupFor
|
|
145
|
+
};
|