@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,152 @@
|
|
|
1
|
+
import { parseDocument } from "yaml";
|
|
2
|
+
import { pairText, insertRawPair, insertKey, setValue, renameKey, deleteAt, applyStep } from "./splice.js";
|
|
3
|
+
import { toPointer, fromPointer, isPrefix } from "./path.js";
|
|
4
|
+
import { commandsFor, chain } from "./commands.js";
|
|
5
|
+
const isMap = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
6
|
+
function clipboardFor(a) {
|
|
7
|
+
const { deleteCmd, describe, setCmd } = commandsFor(a);
|
|
8
|
+
const order = a.topOrder;
|
|
9
|
+
const sectionPtrs = a.kinds.map((k) => toPointer(k.section));
|
|
10
|
+
const kindOfSection = new Map(a.kinds.map((k) => [toPointer(k.section), k]));
|
|
11
|
+
const groupPtrs = a.entryGroups.map((g) => toPointer(g));
|
|
12
|
+
function holderOf(p) {
|
|
13
|
+
const r = a.objectOf(toPointer(p));
|
|
14
|
+
if (r && r.path === toPointer(p)) return a.kinds.find((k) => k.kind === r.kind).section;
|
|
15
|
+
const g = a.entryGroups.find((g2) => p.length === g2.length + 1 && isPrefix(g2, p));
|
|
16
|
+
if (g) return g;
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
function copyText(text, paths) {
|
|
20
|
+
const top = paths.filter((p) => p.length && !paths.some((o) => o !== p && o.length < p.length && isPrefix(o, p)));
|
|
21
|
+
if (!top.length) return void 0;
|
|
22
|
+
const whole = top.filter((p) => holderOf(p));
|
|
23
|
+
if (whole.length === top.length) {
|
|
24
|
+
const groups = /* @__PURE__ */ new Map();
|
|
25
|
+
for (const p of whole) {
|
|
26
|
+
const k = toPointer(holderOf(p));
|
|
27
|
+
groups.set(k, [...groups.get(k) ?? [], p]);
|
|
28
|
+
}
|
|
29
|
+
const out = [];
|
|
30
|
+
const holders = [...sectionPtrs, ...groupPtrs];
|
|
31
|
+
for (const g of [...groups.keys()].sort((x, y) => holders.indexOf(x) - holders.indexOf(y))) {
|
|
32
|
+
const h = fromPointer(g);
|
|
33
|
+
const pairs = groups.get(g).map((p) => pairText(text, p)).filter((x) => !!x);
|
|
34
|
+
const indent = " ".repeat(h.length);
|
|
35
|
+
out.push(h.map((k, i) => `${" ".repeat(i)}${k}:`).join("\n") + "\n" + pairs.map((t) => t.replace(/\n$/, "").split("\n").map((l) => l ? indent + l : l).join("\n")).join("\n") + "\n");
|
|
36
|
+
}
|
|
37
|
+
const n = whole.length;
|
|
38
|
+
return { text: out.join(""), what: n === 1 ? describe(whole[0]) : `${n} items` };
|
|
39
|
+
}
|
|
40
|
+
const lines = top.map((p) => typeof p[p.length - 1] === "string" ? pairText(text, p) : void 0).filter((x) => !!x);
|
|
41
|
+
if (!lines.length) return void 0;
|
|
42
|
+
return { text: lines.join(""), what: top.length === 1 ? describe(top[0]) : `${top.length} keys` };
|
|
43
|
+
}
|
|
44
|
+
function pasteCmd(text, clip, selection = []) {
|
|
45
|
+
const parsed = parseDocument(clip);
|
|
46
|
+
if (parsed.errors.length) return { what: "nothing", error: `the clipboard isn't YAML: ${parsed.errors[0].message.split("\n")[0]}` };
|
|
47
|
+
const data = parsed.toJS();
|
|
48
|
+
if (!isMap(data) || !Object.keys(data).length) return { what: "nothing", error: "the clipboard holds no YAML map" };
|
|
49
|
+
const tops = /* @__PURE__ */ new Set([...a.kinds.map((k) => String(k.section[0])), ...a.entryGroups.map((g) => String(g[0]))]);
|
|
50
|
+
const resourcesPaste = Object.keys(data).every((k) => tops.has(k));
|
|
51
|
+
if (resourcesPaste) return pasteResources(text, clip, data);
|
|
52
|
+
const targets = [...new Map(selection.map((p) => a.objectOf(toPointer(p))).filter((r) => !!r).map((r) => [r.path, fromPointer(r.path)])).values()];
|
|
53
|
+
if (!targets.length) return { what: "nothing", error: `select a ${a.noun} to paste these keys onto` };
|
|
54
|
+
const keys = Object.entries(data);
|
|
55
|
+
const label = `Paste ${keys.map(([k]) => k).join(", ")} onto ${targets.length === 1 ? describe(targets[0]) : `${targets.length} items`}`;
|
|
56
|
+
return {
|
|
57
|
+
what: label,
|
|
58
|
+
cmd: {
|
|
59
|
+
label,
|
|
60
|
+
touched: targets,
|
|
61
|
+
build: (t) => chain(t, targets.flatMap((p) => keys.map(([k, v]) => (x) => setCmd([...p, k], v).build(x))))
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function pasteResources(text, clip, data) {
|
|
66
|
+
const target = parseDocument(text).toJS();
|
|
67
|
+
const taken = /* @__PURE__ */ new Set();
|
|
68
|
+
for (const k of a.kinds) {
|
|
69
|
+
const m = getIn(target, k.section);
|
|
70
|
+
if (isMap(m)) for (const n2 of Object.keys(m)) taken.add(n2);
|
|
71
|
+
}
|
|
72
|
+
const pools = new Map(a.entryGroups.map((g) => {
|
|
73
|
+
const m = getIn(target, g);
|
|
74
|
+
return [toPointer(g), new Set(Object.keys(isMap(m) ? m : {}))];
|
|
75
|
+
}));
|
|
76
|
+
const items = [];
|
|
77
|
+
for (const p of [...sectionPtrs, ...groupPtrs]) {
|
|
78
|
+
const m = getIn(data, fromPointer(p));
|
|
79
|
+
if (!isMap(m)) continue;
|
|
80
|
+
for (const name of Object.keys(m)) {
|
|
81
|
+
const pool = pools.get(p) ?? taken;
|
|
82
|
+
let to = name;
|
|
83
|
+
if (pool.has(to)) {
|
|
84
|
+
const stem = name.replace(/-\d+$/, "");
|
|
85
|
+
let i = 2;
|
|
86
|
+
while (pool.has(`${stem}-${i}`)) i++;
|
|
87
|
+
to = `${stem}-${i}`;
|
|
88
|
+
}
|
|
89
|
+
pool.add(to);
|
|
90
|
+
items.push({ holder: fromPointer(p), name, to });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!items.length) return { what: "nothing", error: "nothing to paste" };
|
|
94
|
+
const renamed = new Map(items.filter((i) => !pools.has(toPointer(i.holder)) && i.name !== i.to).map((i) => [i.name, i.to]));
|
|
95
|
+
let frag = clip;
|
|
96
|
+
const step = (s) => {
|
|
97
|
+
for (const st of s.steps) frag = applyStep(frag, st);
|
|
98
|
+
};
|
|
99
|
+
const sectionOf = (kind) => a.kinds.find((k) => k.kind === kind)?.section ?? [];
|
|
100
|
+
for (const r of a.refs(data)) {
|
|
101
|
+
if (r.slot.key) continue;
|
|
102
|
+
const to = r.name !== void 0 ? renamed.get(r.name) : void 0;
|
|
103
|
+
if (!to || !r.slot.targets.some((s) => isMap(getIn(data, sectionOf(s))) && r.name in getIn(data, sectionOf(s)))) continue;
|
|
104
|
+
step(setValue(frag, fromPointer(r.path), r.slot.rename ? r.slot.rename(r.value, to) : to));
|
|
105
|
+
}
|
|
106
|
+
const dropped = [];
|
|
107
|
+
let dropWhy = "";
|
|
108
|
+
for (const i of items) {
|
|
109
|
+
const k = kindOfSection.get(toPointer(i.holder));
|
|
110
|
+
const drop = k && a.pasteDrops?.(target, { kind: k.kind, path: [...i.holder, i.name], value: getIn(data, [...i.holder, i.name]) });
|
|
111
|
+
if (drop) {
|
|
112
|
+
step(deleteAt(frag, drop.path));
|
|
113
|
+
dropped.push(i.to);
|
|
114
|
+
dropWhy = drop.why;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const i of items) if (i.name !== i.to) step(renameKey(frag, [...i.holder, i.name], i.to));
|
|
118
|
+
const fragDoc = parseDocument(frag).toJS();
|
|
119
|
+
const n = items.length;
|
|
120
|
+
const label = n === 1 ? `Paste ${kindOfSection.get(toPointer(items[0].holder))?.singular ?? a.kinds[0]?.singular ?? "entry"} ${items[0].to}` : `Paste ${n} items`;
|
|
121
|
+
return {
|
|
122
|
+
what: label + (dropped.length ? ` (${dropped.join(", ")}: ${dropWhy})` : ""),
|
|
123
|
+
names: new Map(items.map((i) => [i.name, i.to])),
|
|
124
|
+
cmd: {
|
|
125
|
+
label: pools.has(toPointer(items[0].holder)) && n === 1 ? `Paste ${items[0].holder.join(".")} entry ${items[0].to}` : label,
|
|
126
|
+
select: items.map((i) => [...i.holder, i.to]),
|
|
127
|
+
build: (t) => chain(t, items.map((i) => (x) => {
|
|
128
|
+
const holder = i.holder;
|
|
129
|
+
const exists = isMap(getIn(parseDocument(x).toJS(), holder));
|
|
130
|
+
if (!exists) return insertKey(x, holder.slice(0, -1), String(holder[holder.length - 1]), { [i.to]: getIn(fragDoc, [...holder, i.to]) }, { order });
|
|
131
|
+
const raw = pairText(frag, [...holder, i.to]);
|
|
132
|
+
return raw ? insertRawPair(x, holder, i.to, raw, order) : insertKey(x, holder, i.to, getIn(fragDoc, [...holder, i.to]), { order });
|
|
133
|
+
}))
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function cutCmd(text, paths) {
|
|
138
|
+
const c = copyText(text, paths);
|
|
139
|
+
if (!c) return void 0;
|
|
140
|
+
const top = paths.filter((p) => p.length && !paths.some((o) => o !== p && o.length < p.length && isPrefix(o, p)));
|
|
141
|
+
const order2 = [...top].sort((a2, b) => typeof a2.at(-1) === "number" && typeof b.at(-1) === "number" ? b.at(-1) - a2.at(-1) : 0);
|
|
142
|
+
return {
|
|
143
|
+
text: c.text,
|
|
144
|
+
cmd: { label: `Cut ${c.what}`, remap: (p) => top.some((t) => isPrefix(t, p)) ? null : p, build: (t) => chain(t, order2.map((p) => (x) => deleteCmd(p).build(x))) }
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return { copyText, pasteCmd, cutCmd };
|
|
148
|
+
}
|
|
149
|
+
const getIn = (o, p) => p.reduce((x, k) => x && typeof x === "object" ? x[k] : void 0, o);
|
|
150
|
+
export {
|
|
151
|
+
clipboardFor
|
|
152
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { parseDocument } from "yaml";
|
|
2
|
+
import { setValue, insertKey, deleteAt, insertItem, renameKey, moveKey, applyStep, scalarText } from "./splice.js";
|
|
3
|
+
import { EditorDoc } from "./doc.js";
|
|
4
|
+
import { isPrefix, toPointer } from "./path.js";
|
|
5
|
+
const dataOf = (t) => parseDocument(t, { uniqueKeys: false }).toJS();
|
|
6
|
+
function chain(text, parts) {
|
|
7
|
+
const steps = [];
|
|
8
|
+
let t = text;
|
|
9
|
+
let fallback = false;
|
|
10
|
+
for (const f of parts) {
|
|
11
|
+
const s = f(t);
|
|
12
|
+
for (const st of s.steps) {
|
|
13
|
+
steps.push(st);
|
|
14
|
+
t = applyStep(t, st);
|
|
15
|
+
}
|
|
16
|
+
fallback ||= !!s.fallback;
|
|
17
|
+
}
|
|
18
|
+
return { steps, fallback };
|
|
19
|
+
}
|
|
20
|
+
function seqCmd(label, cmds) {
|
|
21
|
+
return { label, touched: cmds.flatMap((c) => c.touched ?? []), select: cmds.find((c) => c.select)?.select, build: (t) => chain(t, cmds.map((c) => (u) => c.build(u))) };
|
|
22
|
+
}
|
|
23
|
+
const hasKey = (t, p) => {
|
|
24
|
+
const d = dataOf(t);
|
|
25
|
+
const parent = p.slice(0, -1).reduce((x, k) => x?.[k], d);
|
|
26
|
+
return !!parent && typeof parent === "object" && String(p[p.length - 1]) in parent;
|
|
27
|
+
};
|
|
28
|
+
const parsePath = (ptr) => ptr.split("/").slice(1).map((s) => {
|
|
29
|
+
const u = s.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
30
|
+
return /^\d+$/.test(u) ? Number(u) : u;
|
|
31
|
+
});
|
|
32
|
+
function commandsFor(a) {
|
|
33
|
+
const describe = (p) => a.describe(p);
|
|
34
|
+
const order = a.topOrder;
|
|
35
|
+
const allNames = (data) => {
|
|
36
|
+
const all = /* @__PURE__ */ new Set();
|
|
37
|
+
for (const k of a.kinds) {
|
|
38
|
+
const m = k.section.reduce((x, s) => x?.[s], data);
|
|
39
|
+
if (m && typeof m === "object") for (const n of Object.keys(m)) all.add(n);
|
|
40
|
+
}
|
|
41
|
+
return all;
|
|
42
|
+
};
|
|
43
|
+
function setCmd(path, value, label = `Set ${describe(path)}`) {
|
|
44
|
+
return {
|
|
45
|
+
label,
|
|
46
|
+
touched: [path],
|
|
47
|
+
build: (t) => {
|
|
48
|
+
const d = new EditorDoc(t);
|
|
49
|
+
if (d.rangeOf(path) || d.nodeAt(path) !== void 0 || hasKey(t, path)) return setValue(t, path, value);
|
|
50
|
+
return insertKey(t, path.slice(0, -1), String(path[path.length - 1]), value, { order });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function pinsCmd(pins, label) {
|
|
55
|
+
const paths = pins.map(([n]) => [a.pins.key, "layout", n]);
|
|
56
|
+
return withPinsMoved({ label, touched: paths, build: (t) => chain(t, pins.map(([, at], i) => (u) => setCmd(paths[i], { at }).build(u))) });
|
|
57
|
+
}
|
|
58
|
+
function withPinsMoved(cmd) {
|
|
59
|
+
return { ...cmd, build: (t) => a.pins.legacyOnly(dataOf(t)) ? chain(t, [(u) => renameKey(u, [a.pins.legacyKey], a.pins.key), (u) => cmd.build(u)]) : cmd.build(t) };
|
|
60
|
+
}
|
|
61
|
+
function insertCmd(mapPath, key, value, opts = {}) {
|
|
62
|
+
return { label: opts.label ?? `Add ${describe([...mapPath, key])}`, touched: [[...mapPath, key]], select: [[...mapPath, key]], build: (t) => insertKey(t, mapPath, key, value, { ...opts, order }) };
|
|
63
|
+
}
|
|
64
|
+
function insertItemCmd(listPath, value, index, label = `Add to ${describe(listPath)}`) {
|
|
65
|
+
return { label, touched: [listPath], build: (t) => insertItem(t, listPath, value, index, order) };
|
|
66
|
+
}
|
|
67
|
+
function moveCmd(path, before) {
|
|
68
|
+
return { label: `Move ${describe(path)}`, touched: [path], build: (t) => moveKey(t, path, before, order) };
|
|
69
|
+
}
|
|
70
|
+
function referencesTo(text, kind, name) {
|
|
71
|
+
return a.refs(dataOf(text)).filter((r) => (r.slot.key ? r.value === name : r.name === name) && r.slot.targets.includes(kind));
|
|
72
|
+
}
|
|
73
|
+
function deleteCmd(path, opts = {}) {
|
|
74
|
+
const res = a.objectOf(toPointer(path));
|
|
75
|
+
const whole = res && res.path === toPointer(path);
|
|
76
|
+
return {
|
|
77
|
+
label: `Delete ${describe(path)}`,
|
|
78
|
+
touched: [path],
|
|
79
|
+
remap: (p) => isPrefix(path, p) ? null : p,
|
|
80
|
+
build: (t) => {
|
|
81
|
+
if (!whole || !opts.withRefs) return deleteAt(t, path);
|
|
82
|
+
const refs = referencesTo(t, res.kind, res.name);
|
|
83
|
+
const taken = refs.map((r) => {
|
|
84
|
+
const p = parsePath(r.path);
|
|
85
|
+
return typeof p.at(-1) === "number" ? p : a.refDeletePath(p);
|
|
86
|
+
});
|
|
87
|
+
const once = [...new Map(taken.map((p) => [toPointer(p), p])).values()];
|
|
88
|
+
const items = once.filter((p) => typeof p.at(-1) === "number").sort((a2, b) => b.at(-1) - a2.at(-1));
|
|
89
|
+
const keys = once.filter((p) => typeof p.at(-1) !== "number");
|
|
90
|
+
const all = [...items, ...keys, path];
|
|
91
|
+
const kept = all.filter((p, i) => !all.some((q, j) => j !== i && q.length < p.length && isPrefix(q, p)));
|
|
92
|
+
return chain(t, kept.map((p) => (x) => deleteAt(x, p)));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function renameCmd(path, to) {
|
|
97
|
+
const res = a.objectOf(toPointer(path));
|
|
98
|
+
const from = String(path[path.length - 1]);
|
|
99
|
+
const base = path.slice(0, -1);
|
|
100
|
+
return {
|
|
101
|
+
label: `Rename ${describe(path)} to ${to}`,
|
|
102
|
+
touched: [[...base, to]],
|
|
103
|
+
remap: (p) => isPrefix(path, p) ? [...base, to, ...p.slice(path.length)] : p,
|
|
104
|
+
build: (t) => {
|
|
105
|
+
const key = renameKey(t, path, to);
|
|
106
|
+
if (!res || res.path !== toPointer(path)) return key;
|
|
107
|
+
const d = new EditorDoc(t);
|
|
108
|
+
const edits = [...key.steps[0]];
|
|
109
|
+
for (const r of referencesTo(t, res.kind, from)) {
|
|
110
|
+
const p = parsePath(r.path);
|
|
111
|
+
const v = a.renameRef(r, to);
|
|
112
|
+
if (v === void 0) continue;
|
|
113
|
+
const range = d.rangeOf(p, r.slot.key ? "key" : "value");
|
|
114
|
+
if (!range) continue;
|
|
115
|
+
const now = t.slice(range[0], range[1]);
|
|
116
|
+
const quote = now[0] === '"' || now[0] === "'" ? now[0] : void 0;
|
|
117
|
+
edits.push({ start: range[0], end: range[1], text: quote === '"' ? JSON.stringify(v) : quote === "'" ? `'${v}'` : scalarText(v, { flow: true, indent: 0 }) });
|
|
118
|
+
}
|
|
119
|
+
return { steps: [edits] };
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function duplicateCmd(path) {
|
|
124
|
+
const name = String(path[path.length - 1]);
|
|
125
|
+
const base = path.slice(0, -1);
|
|
126
|
+
let made = "";
|
|
127
|
+
return {
|
|
128
|
+
label: `Duplicate ${describe(path)}`,
|
|
129
|
+
get select() {
|
|
130
|
+
return made ? [[...base, made]] : void 0;
|
|
131
|
+
},
|
|
132
|
+
build: (t) => {
|
|
133
|
+
const data = dataOf(t);
|
|
134
|
+
const all = allNames(data);
|
|
135
|
+
const stem = name.replace(/-\d+$/, "");
|
|
136
|
+
let n = 2;
|
|
137
|
+
while (all.has(`${stem}-${n}`)) n++;
|
|
138
|
+
made = `${stem}-${n}`;
|
|
139
|
+
const kind = a.objectOf(toPointer(path))?.kind ?? "";
|
|
140
|
+
const value = a.copyValue(kind, path.reduce((x, k) => x?.[k], data));
|
|
141
|
+
return insertKey(t, base, made, value, { after: name, order });
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function renameKeyCmd(path, to) {
|
|
146
|
+
const base = path.slice(0, -1);
|
|
147
|
+
return { label: `Rename ${describe(path)} to ${to}`, touched: [[...base, to]], remap: (p) => isPrefix(path, p) ? [...base, to, ...p.slice(path.length)] : p, build: (t) => renameKey(t, path, to) };
|
|
148
|
+
}
|
|
149
|
+
function moveItemCmd(listPath, from, to) {
|
|
150
|
+
return {
|
|
151
|
+
label: `Move ${describe([...listPath, from])}`,
|
|
152
|
+
touched: [listPath],
|
|
153
|
+
remap: (p) => isPrefix(listPath, p) && p.length > listPath.length && p[listPath.length] === from ? [...listPath, to, ...p.slice(listPath.length + 1)] : p,
|
|
154
|
+
build: (t) => {
|
|
155
|
+
if (from === to) return { steps: [] };
|
|
156
|
+
const value = [...listPath, from].reduce((x, k) => x?.[k], dataOf(t));
|
|
157
|
+
return chain(t, [(x) => deleteAt(x, [...listPath, from]), (x) => insertItem(x, listPath, value, to, order)]);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function freshName(text, stem) {
|
|
162
|
+
const all = allNames(dataOf(text));
|
|
163
|
+
let n = 1;
|
|
164
|
+
while (all.has(`${stem}-${n}`)) n++;
|
|
165
|
+
return `${stem}-${n}`;
|
|
166
|
+
}
|
|
167
|
+
return { describe, setCmd, pinsCmd, withPinsMoved, insertCmd, insertItemCmd, moveCmd, referencesTo, deleteCmd, renameCmd, duplicateCmd, renameKeyCmd, moveItemCmd, freshName };
|
|
168
|
+
}
|
|
169
|
+
export {
|
|
170
|
+
chain,
|
|
171
|
+
commandsFor,
|
|
172
|
+
seqCmd
|
|
173
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { completionContext } from "./doc.js";
|
|
2
|
+
import { toPointer } from "./path.js";
|
|
3
|
+
const data = (d) => {
|
|
4
|
+
const v = d.data;
|
|
5
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
6
|
+
};
|
|
7
|
+
const get = (o, path) => path.reduce((x, k) => x && typeof x === "object" ? x[k] : void 0, o);
|
|
8
|
+
function namesIn(d, k) {
|
|
9
|
+
const m = get(data(d), k.section);
|
|
10
|
+
return m && typeof m === "object" && !Array.isArray(m) ? Object.keys(m).filter((k2) => !k2.startsWith("x-")) : [];
|
|
11
|
+
}
|
|
12
|
+
function complete(d, offset, nav, a) {
|
|
13
|
+
const c = completionContext(d, offset);
|
|
14
|
+
const items = [];
|
|
15
|
+
const root = data(d);
|
|
16
|
+
if (c.kind === "key") {
|
|
17
|
+
const here = get(root, c.path);
|
|
18
|
+
const present = here && typeof here === "object" && !Array.isArray(here) ? here : {};
|
|
19
|
+
if (nav.isNameMap(c.path)) {
|
|
20
|
+
const ptr = toPointer(c.path);
|
|
21
|
+
for (const [k, s] of Object.entries(a.snippets)) if (k.split("#")[0] === ptr) items.push({ label: s.label, insert: s.body, kind: "snippet", snippet: true, doc: s.doc, preferred: true });
|
|
22
|
+
} else {
|
|
23
|
+
const indent = " ".repeat(Math.max(0, c.start - (d.text.lastIndexOf("\n", c.start - 1) + 1)));
|
|
24
|
+
for (const k of nav.keys(c.path, present)) {
|
|
25
|
+
if (k.name in present) continue;
|
|
26
|
+
const after = c.flow || k.shape === "scalar" ? ": " : k.shape === "list" ? ":\n" + indent + " - " : ":\n" + indent + " ";
|
|
27
|
+
const insert = k.enumValues.length > 1 && k.shape === "scalar" ? `${k.name}: \${1|${k.enumValues.join(",")}|}` : k.name + after;
|
|
28
|
+
items.push({ label: k.name, insert, snippet: insert.includes("${"), kind: "key", doc: k.doc, detail: k.enumValues.length ? k.enumValues.join(" | ") : k.shape === "map" ? "map" : k.shape === "list" ? "list" : void 0 });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
const valuePath = c.kind === "item" ? [...c.path, 0] : c.path;
|
|
33
|
+
const ptr = toPointer(valuePath);
|
|
34
|
+
const slot = a.slotAt(ptr);
|
|
35
|
+
if (slot) {
|
|
36
|
+
for (const s of slot.targets) {
|
|
37
|
+
const k = a.kinds.find((x) => x.kind === s);
|
|
38
|
+
if (k) for (const n of namesIn(d, k)) {
|
|
39
|
+
items.push({ label: slot.write ? slot.write(n) : n, insert: slot.write ? slot.write(n) : n, kind: "ref", detail: `${k.singular} \xB7 declared`, preferred: true });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
for (const e of slot.extra ?? []) items.push({ label: e, insert: /[{*]/.test(e) ? JSON.stringify(e) : e, kind: "value", detail: a.extraDetail?.(e, root) });
|
|
43
|
+
}
|
|
44
|
+
for (const v of nav.values(valuePath)) if (!items.some((i) => i.label === v)) items.push({ label: v, insert: v, kind: "value" });
|
|
45
|
+
if (!items.length) {
|
|
46
|
+
const k = nav.keys(c.path.slice(0, -1)).find((x) => x.name === String(c.path[c.path.length - 1]));
|
|
47
|
+
for (const e of k?.examples ?? []) if (typeof e === "string") items.push({ label: e, insert: e, kind: "value", detail: "example" });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { items, start: c.start, path: c.path, context: c.kind };
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
complete,
|
|
54
|
+
namesIn
|
|
55
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { parseDocument, isMap, isSeq, isPair, isScalar, isCollection, LineCounter } from "yaml";
|
|
2
|
+
class EditorDoc {
|
|
3
|
+
text;
|
|
4
|
+
doc;
|
|
5
|
+
lines;
|
|
6
|
+
constructor(text) {
|
|
7
|
+
this.text = text;
|
|
8
|
+
this.lines = new LineCounter();
|
|
9
|
+
this.doc = parseDocument(text, { keepSourceTokens: true, lineCounter: this.lines, prettyErrors: false, uniqueKeys: false });
|
|
10
|
+
}
|
|
11
|
+
get ok() {
|
|
12
|
+
return this.doc.errors.length === 0;
|
|
13
|
+
}
|
|
14
|
+
get data() {
|
|
15
|
+
try {
|
|
16
|
+
return this.doc.toJS();
|
|
17
|
+
} catch {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** 1-based line and column of an offset */
|
|
22
|
+
pos(offset) {
|
|
23
|
+
return this.lines.linePos(offset);
|
|
24
|
+
}
|
|
25
|
+
/** offset of a 1-based line and column */
|
|
26
|
+
offset(line, col) {
|
|
27
|
+
return (this.lines.lineStarts[line - 1] ?? this.text.length) + col - 1;
|
|
28
|
+
}
|
|
29
|
+
/** The source range of the node (or its key, or the whole pair) at a path. */
|
|
30
|
+
rangeOf(path, part = "value") {
|
|
31
|
+
let node = this.doc.contents;
|
|
32
|
+
let pair;
|
|
33
|
+
for (const seg of path) {
|
|
34
|
+
pair = void 0;
|
|
35
|
+
if (isMap(node)) {
|
|
36
|
+
const p = node.items.find((x) => isPair(x) && isScalar(x.key) && String(x.key.value) === String(seg));
|
|
37
|
+
if (!p) return void 0;
|
|
38
|
+
pair = p;
|
|
39
|
+
node = p.value;
|
|
40
|
+
} else if (isSeq(node) && typeof seg === "number") node = node.items[seg];
|
|
41
|
+
else return void 0;
|
|
42
|
+
}
|
|
43
|
+
if (part === "key" && pair && isScalar(pair.key) && pair.key.range) return [pair.key.range[0], pair.key.range[1]];
|
|
44
|
+
const v = node?.range;
|
|
45
|
+
if (part === "pair" && pair && isScalar(pair.key) && pair.key.range) return [pair.key.range[0], v ? v[1] : pair.key.range[1]];
|
|
46
|
+
if (v) return [v[0], v[1]];
|
|
47
|
+
if (pair && isScalar(pair.key) && pair.key.range) return [pair.key.range[0], pair.key.range[1]];
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
/** What is at a caret: the innermost key, value or collection whose source contains the offset. */
|
|
51
|
+
at(offset) {
|
|
52
|
+
const walk = (node, path) => {
|
|
53
|
+
if (isMap(node)) {
|
|
54
|
+
for (const p of node.items) {
|
|
55
|
+
const k = p.key;
|
|
56
|
+
if (k?.range && offset >= k.range[0] && offset <= k.range[1]) return { path: [...path, keyOf(p)], where: "key", node: k };
|
|
57
|
+
const v = p.value;
|
|
58
|
+
if (v?.range && offset >= v.range[0] && (isScalar(v) ? offset <= v.range[1] : offset < v.range[1])) {
|
|
59
|
+
return walk(v, [...path, keyOf(p)]) ?? { path: [...path, keyOf(p)], where: "value", node: v };
|
|
60
|
+
}
|
|
61
|
+
if (k?.range && (!v || !v.range || isScalar(v) && v.value === null) && offset > k.range[1] && !this.text.slice(k.range[1], offset).includes("\n")) {
|
|
62
|
+
return { path: [...path, keyOf(p)], where: "value", node: v ?? void 0 };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return node.range && offset >= node.range[0] && offset <= node.range[1] ? { path, where: "inside", node } : void 0;
|
|
66
|
+
}
|
|
67
|
+
if (isSeq(node)) {
|
|
68
|
+
for (const [i, it] of node.items.entries()) {
|
|
69
|
+
const r = it?.range;
|
|
70
|
+
if (r && offset >= r[0] && (isScalar(it) ? offset <= r[1] : offset < r[1])) return walk(it, [...path, i]) ?? { path: [...path, i], where: "value", node: it };
|
|
71
|
+
}
|
|
72
|
+
return node.range && offset >= node.range[0] && offset <= node.range[1] ? { path, where: "inside", node } : void 0;
|
|
73
|
+
}
|
|
74
|
+
if (isScalar(node) && node.range && offset >= node.range[0] && offset <= node.range[1]) return { path, where: "value", node };
|
|
75
|
+
return void 0;
|
|
76
|
+
};
|
|
77
|
+
return walk(this.doc.contents, []) ?? { path: [], where: "inside" };
|
|
78
|
+
}
|
|
79
|
+
/** The node at a path. */
|
|
80
|
+
nodeAt(path) {
|
|
81
|
+
let node = this.doc.contents;
|
|
82
|
+
for (const seg of path) {
|
|
83
|
+
if (isMap(node)) node = node.items.find((x) => isScalar(x.key) && String(x.key.value) === String(seg))?.value;
|
|
84
|
+
else if (isSeq(node) && typeof seg === "number") node = node.items[seg];
|
|
85
|
+
else return void 0;
|
|
86
|
+
}
|
|
87
|
+
return node ?? void 0;
|
|
88
|
+
}
|
|
89
|
+
/** Every path in the document, with its range: for tests (rangeOf ∘ at is the identity) and the tree (E3). */
|
|
90
|
+
paths() {
|
|
91
|
+
const out = [];
|
|
92
|
+
const walk = (node, path) => {
|
|
93
|
+
const r = node?.range;
|
|
94
|
+
if (r && path.length) out.push({ path, range: [r[0], r[1]] });
|
|
95
|
+
if (isMap(node)) for (const p of node.items) walk(p.value, [...path, keyOf(p)]);
|
|
96
|
+
else if (isSeq(node)) node.items.forEach((x, i) => walk(x, [...path, i]));
|
|
97
|
+
};
|
|
98
|
+
walk(this.doc.contents, []);
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function keyOf(p) {
|
|
103
|
+
return isScalar(p.key) ? String(p.key.value) : String(p.key);
|
|
104
|
+
}
|
|
105
|
+
function completionContext(d, offset) {
|
|
106
|
+
const text = d.text;
|
|
107
|
+
const lineStart = text.lastIndexOf("\n", offset - 1) + 1;
|
|
108
|
+
const before = text.slice(lineStart, offset);
|
|
109
|
+
const word = /[A-Za-z0-9_.:\/{}*~$-]*$/.exec(before)[0].replace(/^[{[,]/, "");
|
|
110
|
+
const start = offset - word.length;
|
|
111
|
+
const flowNode = enclosingFlow(d, start);
|
|
112
|
+
if (flowNode) {
|
|
113
|
+
const inner = text.slice(flowNode.range[0], start);
|
|
114
|
+
const m = /([A-Za-z0-9_-]+)\s*:\s*$/.exec(inner.slice(Math.max(inner.lastIndexOf(","), inner.lastIndexOf("{")) + 1));
|
|
115
|
+
if (flowNode.kind === "map" && m) return { path: [...flowNode.path, m[1]], kind: "value", prefix: word, start, flow: true };
|
|
116
|
+
return { path: flowNode.path, kind: flowNode.kind === "map" ? "key" : "item", prefix: word, start, flow: true };
|
|
117
|
+
}
|
|
118
|
+
const kv = /^(\s*)(?:- )?([^\s:#][^:#]*?)\s*:\s+$/.exec(before.slice(0, before.length - word.length));
|
|
119
|
+
if (kv) {
|
|
120
|
+
const keyOffset = lineStart + before.indexOf(kv[2], kv[1].length);
|
|
121
|
+
const a = d.at(keyOffset);
|
|
122
|
+
if (a.where === "key") return { path: a.path, kind: "value", prefix: word, start, flow: false };
|
|
123
|
+
return { path: [...parentByIndent(d, lineStart, kv[1].length), kv[2]], kind: "value", prefix: word, start, flow: false };
|
|
124
|
+
}
|
|
125
|
+
const item = /^(\s*)- $/.exec(before.slice(0, before.length - word.length));
|
|
126
|
+
if (item) {
|
|
127
|
+
const owner = parentByIndent(d, lineStart, item[1].length, true);
|
|
128
|
+
return { path: owner, kind: "item", prefix: word, start, flow: false };
|
|
129
|
+
}
|
|
130
|
+
const indent = /^\s*/.exec(before)[0].length;
|
|
131
|
+
return { path: parentByIndent(d, lineStart, indent), kind: "key", prefix: word, start, flow: false };
|
|
132
|
+
}
|
|
133
|
+
function parentByIndent(d, lineStart, indent, forList = false) {
|
|
134
|
+
const text = d.text;
|
|
135
|
+
let end = lineStart - 1;
|
|
136
|
+
while (end > 0) {
|
|
137
|
+
const s = text.lastIndexOf("\n", end - 1) + 1;
|
|
138
|
+
const line = text.slice(s, end);
|
|
139
|
+
end = s - 1;
|
|
140
|
+
if (!line.trim() || /^\s*#/.test(line)) continue;
|
|
141
|
+
const ind = /^\s*/.exec(line)[0].length;
|
|
142
|
+
if (ind === indent && !forList) {
|
|
143
|
+
const keyAt = s + ind + (line.slice(ind).startsWith("- ") ? 2 : 0);
|
|
144
|
+
const a = d.at(keyAt);
|
|
145
|
+
if (a.where === "key") return a.path.slice(0, -1);
|
|
146
|
+
if (line.slice(ind).startsWith("- ")) return a.path.slice(0, -1);
|
|
147
|
+
}
|
|
148
|
+
if (ind < indent || forList && ind <= indent && /:\s*$/.test(line)) {
|
|
149
|
+
const m = /^(\s*)(- )?([^\s:#][^:#]*?)\s*:/.exec(line);
|
|
150
|
+
if (m) {
|
|
151
|
+
const a = d.at(s + m[1].length + (m[2] ? 2 : 0));
|
|
152
|
+
if (a.where === "key") return a.path;
|
|
153
|
+
}
|
|
154
|
+
if (/^\s*- /.test(line)) {
|
|
155
|
+
const a = d.at(s + ind + 2);
|
|
156
|
+
let i = a.path.length - 1;
|
|
157
|
+
while (i >= 0 && typeof a.path[i] !== "number") i--;
|
|
158
|
+
return i >= 0 ? a.path.slice(0, i + 1) : a.path;
|
|
159
|
+
}
|
|
160
|
+
if (ind < indent) return [];
|
|
161
|
+
}
|
|
162
|
+
if (ind === 0 && indent === 0) return [];
|
|
163
|
+
}
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
function enclosingFlow(d, offset) {
|
|
167
|
+
let best;
|
|
168
|
+
const walk = (node, path) => {
|
|
169
|
+
if (!isCollection(node)) return;
|
|
170
|
+
const r = node.range;
|
|
171
|
+
const flow = node.flow;
|
|
172
|
+
if (flow && r && offset > r[0] && offset < r[1]) best = { path, kind: isMap(node) ? "map" : "list", range: [r[0], r[1]] };
|
|
173
|
+
if (isMap(node)) for (const p of node.items) walk(p.value, [...path, keyOf(p)]);
|
|
174
|
+
else if (isSeq(node)) node.items.forEach((x, i) => walk(x, [...path, i]));
|
|
175
|
+
};
|
|
176
|
+
walk(d.doc.contents, []);
|
|
177
|
+
return best;
|
|
178
|
+
}
|
|
179
|
+
export {
|
|
180
|
+
EditorDoc,
|
|
181
|
+
completionContext
|
|
182
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { toPointer, fromPointer, parentOf, isPrefix, samePath } from "./path.js";
|
|
2
|
+
import { EditorDoc, completionContext } from "./doc.js";
|
|
3
|
+
import { HISTORY_DEPTH, EditorModel } from "./model.js";
|
|
4
|
+
import { SpliceError, applyStep, invertStep, scalarText, flowText, setValue, insertKey, deleteAt, insertItem, renameKey, moveKey, insertRawPair, pairText } from "./splice.js";
|
|
5
|
+
import { SchemaNav } from "./schema-nav.js";
|
|
6
|
+
import { PREF, VIEWS } from "./storage-keys.js";
|
|
7
|
+
import { chain, seqCmd, commandsFor } from "./commands.js";
|
|
8
|
+
import { clipboardFor } from "./clipboard.js";
|
|
9
|
+
import { namesIn, complete } from "./complete.js";
|
|
10
|
+
import { outline, flatten } from "./outline.js";
|
|
11
|
+
import { analyse, place } from "./validate.js";
|
|
12
|
+
import { docFor, providersFor, rangeOfPath, problemRange, cmSnippet, mdRuns } from "./providers.js";
|
|
13
|
+
import { setLayer, layer } from "./ui/layer.js";
|
|
14
|
+
import { icon } from "./ui/icons.js";
|
|
15
|
+
import { ask } from "./ui/dialog.js";
|
|
16
|
+
import { menuOpen, openMenu, closeMenu } from "./ui/menu.js";
|
|
17
|
+
import { TYPING_PAUSE_MS, isTyping, later } from "./ui/later.js";
|
|
18
|
+
import { keymapWith, keySheet } from "./ui/keys.js";
|
|
19
|
+
import { clipboard } from "./ui/clip.js";
|
|
20
|
+
import { treeView } from "./ui/tree.js";
|
|
21
|
+
import { run, composite, actionsFor } from "./ui/actions.js";
|
|
22
|
+
import { propsPanel } from "./ui/props.js";
|
|
23
|
+
import { canvasView } from "./ui/canvas.js";
|
|
24
|
+
import { flatCanvas } from "./ui/flat-canvas.js";
|
|
25
|
+
import { mountEditor } from "./ui/mount.js";
|
|
26
|
+
import { PROTOCOL, isMessage } from "./window/protocol.js";
|
|
27
|
+
import { setupFor, PLAIN_WORDS, PLAIN_KEYMAP } from "./ui/setup.js";
|
|
28
|
+
import { scopeCss, scopeOne } from "./ui/scope-css.js";
|
|
29
|
+
import { PLAIN_ICON_SVG, PLAIN_ICONS, PLAIN_SPRITE, iconSymbols, spriteOf } from "./ui/plain-icons.js";
|
|
30
|
+
export {
|
|
31
|
+
EditorDoc,
|
|
32
|
+
EditorModel,
|
|
33
|
+
HISTORY_DEPTH,
|
|
34
|
+
PLAIN_ICONS,
|
|
35
|
+
PLAIN_ICON_SVG,
|
|
36
|
+
PLAIN_KEYMAP,
|
|
37
|
+
PLAIN_SPRITE,
|
|
38
|
+
PLAIN_WORDS,
|
|
39
|
+
PREF,
|
|
40
|
+
PROTOCOL,
|
|
41
|
+
SchemaNav,
|
|
42
|
+
SpliceError,
|
|
43
|
+
TYPING_PAUSE_MS,
|
|
44
|
+
VIEWS,
|
|
45
|
+
actionsFor,
|
|
46
|
+
analyse,
|
|
47
|
+
applyStep,
|
|
48
|
+
ask,
|
|
49
|
+
canvasView,
|
|
50
|
+
chain,
|
|
51
|
+
clipboard,
|
|
52
|
+
clipboardFor,
|
|
53
|
+
closeMenu,
|
|
54
|
+
cmSnippet,
|
|
55
|
+
commandsFor,
|
|
56
|
+
complete,
|
|
57
|
+
completionContext,
|
|
58
|
+
composite,
|
|
59
|
+
deleteAt,
|
|
60
|
+
docFor,
|
|
61
|
+
flatCanvas,
|
|
62
|
+
flatten,
|
|
63
|
+
flowText,
|
|
64
|
+
fromPointer,
|
|
65
|
+
icon,
|
|
66
|
+
iconSymbols,
|
|
67
|
+
insertItem,
|
|
68
|
+
insertKey,
|
|
69
|
+
insertRawPair,
|
|
70
|
+
invertStep,
|
|
71
|
+
isMessage,
|
|
72
|
+
isPrefix,
|
|
73
|
+
isTyping,
|
|
74
|
+
keySheet,
|
|
75
|
+
keymapWith,
|
|
76
|
+
later,
|
|
77
|
+
layer,
|
|
78
|
+
mdRuns,
|
|
79
|
+
menuOpen,
|
|
80
|
+
mountEditor,
|
|
81
|
+
moveKey,
|
|
82
|
+
namesIn,
|
|
83
|
+
openMenu,
|
|
84
|
+
outline,
|
|
85
|
+
pairText,
|
|
86
|
+
parentOf,
|
|
87
|
+
place,
|
|
88
|
+
problemRange,
|
|
89
|
+
propsPanel,
|
|
90
|
+
providersFor,
|
|
91
|
+
rangeOfPath,
|
|
92
|
+
renameKey,
|
|
93
|
+
run,
|
|
94
|
+
samePath,
|
|
95
|
+
scalarText,
|
|
96
|
+
scopeCss,
|
|
97
|
+
scopeOne,
|
|
98
|
+
seqCmd,
|
|
99
|
+
setLayer,
|
|
100
|
+
setValue,
|
|
101
|
+
setupFor,
|
|
102
|
+
spriteOf,
|
|
103
|
+
toPointer,
|
|
104
|
+
treeView
|
|
105
|
+
};
|