@johnoscott/isometric-engine 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EDITOR-GUIDE.md +43 -5
- package/README.md +1 -1
- package/assets/app.css +7 -3
- package/assets/marks.css +5 -1
- package/iso-editor.js +176 -176
- package/js/iso-editor/splice.js +3 -1
- package/js/iso-editor/ui/canvas.js +210 -12
- package/js/iso-editor/ui/setup.js +6 -2
- package/package.json +10 -1
- package/src/iso-editor/adapter.ts +19 -0
- package/src/iso-editor/index.ts +2 -2
- package/src/iso-editor/splice.ts +8 -3
- package/src/iso-editor/ui/app.css +2 -2
- package/src/iso-editor/ui/canvas.ts +173 -17
- package/src/iso-editor/ui/marks.css +5 -1
- package/src/iso-editor/ui/setup.ts +12 -3
- package/src/iso-objects/route.ts +1 -1
- package/types/iso-editor/adapter.d.ts +33 -0
- package/types/iso-editor/index.d.ts +2 -2
- package/types/iso-editor/ui/canvas.d.ts +36 -8
- package/types/iso-editor/ui/setup.d.ts +9 -0
- package/types/iso-objects/route.d.ts +1 -1
package/js/iso-editor/splice.js
CHANGED
|
@@ -334,7 +334,9 @@ function insertItem(text, listPath, value, index, order) {
|
|
|
334
334
|
s.items.splice(at, 0, d.createNode(value));
|
|
335
335
|
}, true);
|
|
336
336
|
const indent = prefix.indexOf("-");
|
|
337
|
-
const
|
|
337
|
+
const near = items[Math.min(at, items.length - 1)];
|
|
338
|
+
const inline = isObj(value) && isMap(near) && near.flow;
|
|
339
|
+
const body = " ".repeat(indent) + "- " + (inline ? flowText(value) : isObj(value) && Object.keys(value).length ? reindent(yamlText(value), indent + 2).slice(indent + 2) : scalarText(value, { flow: false, indent: indent + 2 })) + "\n";
|
|
338
340
|
if (at < items.length) {
|
|
339
341
|
const s = lineStart(text, items[at].range[0]);
|
|
340
342
|
return { steps: [[{ start: s, end: s, text: body }]] };
|
|
@@ -12,11 +12,12 @@ import { viewport } from "../../iso-viewer/viewport.js";
|
|
|
12
12
|
const SVGNS = "http://www.w3.org/2000/svg";
|
|
13
13
|
function canvasView(host, doc, opts) {
|
|
14
14
|
const K = opts.kit, ui = K.ui, T = ui.text;
|
|
15
|
-
const { setCmd, deleteCmd, insertCmd, pinsCmd, withPinsMoved, freshName, describe } = K.commands;
|
|
15
|
+
const { setCmd, deleteCmd, insertCmd, insertItemCmd, pinsCmd, withPinsMoved, freshName, describe } = K.commands;
|
|
16
16
|
const { deletePaths, renameDialog, duplicate, connected } = K.actions;
|
|
17
17
|
const resourceOf = (ptr) => K.objectOf(ptr);
|
|
18
18
|
const kindOf = (k) => K.kinds.find((x) => x.kind === k);
|
|
19
19
|
const PINS_KEY = K.pins.key;
|
|
20
|
+
let linking;
|
|
20
21
|
host.classList.add("canvas");
|
|
21
22
|
const stage = h("div", { class: `${ui.rootClass} canvas-stage`, tabindex: "0", role: "application", "aria-label": T.stage });
|
|
22
23
|
const tools = h("div", { class: "canvas-tools", role: "toolbar", "aria-label": "Canvas" });
|
|
@@ -374,6 +375,35 @@ function canvasView(host, doc, opts) {
|
|
|
374
375
|
};
|
|
375
376
|
if (hoverId !== void 0 && !doc.selection.some((p) => toPointer(p) === hoverId)) draw2(hoverId, "hover");
|
|
376
377
|
for (const p of doc.selection) draw2(toPointer(p), "ring");
|
|
378
|
+
const one = connectable();
|
|
379
|
+
const from = linking?.from ?? one;
|
|
380
|
+
const fb = from ? boxFor(fromPointer(from.path)) : void 0;
|
|
381
|
+
if (fb && K.connect) {
|
|
382
|
+
const k = scale(), hx = fb.x + fb.w + 10 / k, hy = fb.y + fb.h / 2;
|
|
383
|
+
if (linking && linking.x !== void 0 && linking.y !== void 0) {
|
|
384
|
+
if (linking.over) draw2(linking.over, "hover");
|
|
385
|
+
const l = d.createElementNS(SVGNS, "line");
|
|
386
|
+
l.setAttribute("class", `connect-line${linking.over ? " ok" : ""}`);
|
|
387
|
+
l.setAttribute("x1", String(hx));
|
|
388
|
+
l.setAttribute("y1", String(hy));
|
|
389
|
+
l.setAttribute("x2", String(linking.x));
|
|
390
|
+
l.setAttribute("y2", String(linking.y));
|
|
391
|
+
overlay.append(l);
|
|
392
|
+
}
|
|
393
|
+
if (!linking) {
|
|
394
|
+
const c = d.createElementNS(SVGNS, "circle");
|
|
395
|
+
c.setAttribute("class", "connect-handle");
|
|
396
|
+
c.setAttribute("cx", String(hx));
|
|
397
|
+
c.setAttribute("cy", String(hy));
|
|
398
|
+
c.setAttribute("r", String(7 / k));
|
|
399
|
+
c.style.pointerEvents = "all";
|
|
400
|
+
c.style.cursor = "crosshair";
|
|
401
|
+
const t = d.createElementNS(SVGNS, "title");
|
|
402
|
+
t.textContent = `Drag to what ${from.name} connects to`;
|
|
403
|
+
c.append(t);
|
|
404
|
+
overlay.append(c);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
377
407
|
const counts = /* @__PURE__ */ new Map();
|
|
378
408
|
for (const pr of opts.problems()) {
|
|
379
409
|
if (pr.file) continue;
|
|
@@ -431,6 +461,22 @@ function canvasView(host, doc, opts) {
|
|
|
431
461
|
stage.focus({ preventScroll: true });
|
|
432
462
|
if (layer?.down?.(e)) return;
|
|
433
463
|
const { x, y } = pageXY(e);
|
|
464
|
+
if (e.button === 0 && linking?.pick) {
|
|
465
|
+
e.preventDefault();
|
|
466
|
+
endConnect(pathAtEvent(e.target));
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (e.button === 0 && e.target?.closest?.(".connect-handle")) {
|
|
470
|
+
const one = connectable();
|
|
471
|
+
if (one) {
|
|
472
|
+
capture(e);
|
|
473
|
+
e.preventDefault();
|
|
474
|
+
const p2 = toSvg(x, y);
|
|
475
|
+
linking = { from: one, x: p2.x, y: p2.y };
|
|
476
|
+
paintOverlay();
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
434
480
|
if (e.button === 0 || e.button === 1) capture(e);
|
|
435
481
|
const pan = () => {
|
|
436
482
|
drag = { kind: "pan", x0: x, y0: y, v0: { ...V.view } };
|
|
@@ -493,6 +539,13 @@ function canvasView(host, doc, opts) {
|
|
|
493
539
|
}
|
|
494
540
|
function move(e) {
|
|
495
541
|
const { x, y } = pageXY(e);
|
|
542
|
+
if (linking) {
|
|
543
|
+
const p = toSvg(x, y), under = pathAtEvent(document.elementFromPoint(x, y));
|
|
544
|
+
const r = under === void 0 ? void 0 : resourceOf(under);
|
|
545
|
+
linking = { ...linking, x: p.x, y: p.y, over: r && r.path !== linking.from.path ? r.path : void 0 };
|
|
546
|
+
paintOverlay();
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
496
549
|
if (!drag) {
|
|
497
550
|
const p = pathAtEvent(e.target);
|
|
498
551
|
if (p !== hoverId) {
|
|
@@ -740,6 +793,11 @@ function canvasView(host, doc, opts) {
|
|
|
740
793
|
}
|
|
741
794
|
}
|
|
742
795
|
function up(e) {
|
|
796
|
+
if (linking && !linking.pick) {
|
|
797
|
+
const { x: x2, y: y2 } = pageXY(e);
|
|
798
|
+
endConnect(pathAtEvent(document.elementFromPoint(x2, y2)));
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
743
801
|
const d0 = drag;
|
|
744
802
|
drag = void 0;
|
|
745
803
|
svg?.classList.remove("panning");
|
|
@@ -834,6 +892,8 @@ function canvasView(host, doc, opts) {
|
|
|
834
892
|
items.push({ label: "Show in text", icon: "code-xml", onSelect: () => opts.showInText(one) });
|
|
835
893
|
items.push({ label: "Show in tree", icon: "list-tree", onSelect: () => opts.showInTree(one) });
|
|
836
894
|
}
|
|
895
|
+
if (K.connect && one && isRes) items.push({ label: "Connect to\u2026", icon: "link", desc: "Then click what it connects to (Esc cancels)", disabled: ro, onSelect: () => startPick() });
|
|
896
|
+
if (K.group) items.push({ label: sel.length > 1 ? `Group ${sel.length} items` : "Group", icon: "box", keys: "\u2318G", desc: "Into a new container, as one step", disabled: ro || !members().length, why: "Only objects are grouped", onSelect: groupSelection });
|
|
837
897
|
items.push({ label: "Select parent", icon: "arrow-up-right", keys: "\u2318\u2191", onSelect: selectParent });
|
|
838
898
|
items.push({ label: "Select connected", icon: "link", desc: "What refers to it, and what it refers to", onSelect: () => doc.select(connected(doc, sel), "canvas") });
|
|
839
899
|
items.push({ label: "Zoom to selection", keys: "\u21E72", onSelect: zoomToSelection });
|
|
@@ -841,6 +901,75 @@ function canvasView(host, doc, opts) {
|
|
|
841
901
|
items.push({ sep: true }, { label: sel.length > 1 ? `Delete ${sel.length} items` : "Delete", icon: "trash-2", keys: "\u232B", danger: true, disabled: ro, onSelect: () => deletePaths(doc, sel, "canvas", opts.note) });
|
|
842
902
|
return items;
|
|
843
903
|
}
|
|
904
|
+
function connectable() {
|
|
905
|
+
if (!K.connect || !doc.doc.ok || doc.selection.length !== 1) return void 0;
|
|
906
|
+
const ptr = toPointer(doc.selection[0]), r = resourceOf(ptr);
|
|
907
|
+
return r && r.path === ptr ? r : void 0;
|
|
908
|
+
}
|
|
909
|
+
function startPick() {
|
|
910
|
+
const from = connectable();
|
|
911
|
+
if (!from) return;
|
|
912
|
+
linking = { from, pick: true };
|
|
913
|
+
opts.note(`Click what ${from.name} connects to (Esc cancels)`);
|
|
914
|
+
paintOverlay();
|
|
915
|
+
}
|
|
916
|
+
function endConnect(ptr) {
|
|
917
|
+
const from = linking?.from;
|
|
918
|
+
linking = void 0;
|
|
919
|
+
paintOverlay();
|
|
920
|
+
if (!from || ptr === void 0) return;
|
|
921
|
+
const to = resourceOf(ptr);
|
|
922
|
+
if (!to || to.path === from.path) {
|
|
923
|
+
opts.note("Not connected: drop it on another object", "warn");
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
const data = doc.goodDoc.data;
|
|
927
|
+
const plan = K.connect?.(from, to, data);
|
|
928
|
+
if (!plan) {
|
|
929
|
+
opts.note(`${from.name} and ${to.name} can't be connected`, "warn");
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const label = plan.label ?? `Connect ${from.name} to ${to.name}`;
|
|
933
|
+
let cmd, path;
|
|
934
|
+
if (plan.name !== void 0) {
|
|
935
|
+
const name = freshName(doc.text, plan.name);
|
|
936
|
+
cmd = insertCmd(plan.at, name, plan.value, { label });
|
|
937
|
+
path = [...plan.at, name];
|
|
938
|
+
} else {
|
|
939
|
+
const list = plan.at.reduce((x, k) => x && typeof x === "object" ? x[k] : void 0, data);
|
|
940
|
+
path = [...plan.at, Array.isArray(list) ? list.length : 0];
|
|
941
|
+
cmd = insertItemCmd(plan.at, plan.value, void 0, label);
|
|
942
|
+
}
|
|
943
|
+
if (run(doc, { ...cmd, select: [path] }, "canvas", opts.note)) doc.select([path], "canvas");
|
|
944
|
+
}
|
|
945
|
+
function members() {
|
|
946
|
+
const out = /* @__PURE__ */ new Map();
|
|
947
|
+
for (const p of doc.selection) {
|
|
948
|
+
const r = resourceOf(toPointer(p));
|
|
949
|
+
if (r) out.set(r.path, r);
|
|
950
|
+
}
|
|
951
|
+
return [...out.values()];
|
|
952
|
+
}
|
|
953
|
+
function groupSelection() {
|
|
954
|
+
if (!K.group || !doc.doc.ok) return;
|
|
955
|
+
const ms = members();
|
|
956
|
+
if (!ms.length) {
|
|
957
|
+
opts.note("Only objects are grouped", "warn");
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
const plan = K.group(ms, doc.goodDoc.data);
|
|
961
|
+
if (!plan) {
|
|
962
|
+
opts.note(ms.length > 1 ? `These ${ms.length} can't be grouped` : `${ms[0].name} can't be grouped`, "warn");
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
const name = freshName(doc.text, plan.name);
|
|
966
|
+
const pins = K.pins.of(doc.goodDoc.data) ?? {};
|
|
967
|
+
const unpin = ms.filter((m) => pins[m.name] !== void 0).map((m) => withPinsMoved(deleteCmd([PINS_KEY, "layout", m.name])));
|
|
968
|
+
const label = plan.label ?? `Group ${ms.length > 1 ? `${ms.length} items` : ms[0].name} into ${name}`;
|
|
969
|
+
const p = [...plan.at, name];
|
|
970
|
+
const cmd = seqCmd(label, [insertCmd(plan.at, name, plan.value, { label }), ...plan.members(name).map((m) => setCmd(m.path, m.value)), ...unpin]);
|
|
971
|
+
if (run(doc, { ...cmd, select: [p] }, "canvas", opts.note)) doc.select([p], "canvas");
|
|
972
|
+
}
|
|
844
973
|
function addResource(s) {
|
|
845
974
|
const k = kindOf(s);
|
|
846
975
|
const name = freshName(doc.text, k.singular);
|
|
@@ -902,37 +1031,90 @@ function canvasView(host, doc, opts) {
|
|
|
902
1031
|
}
|
|
903
1032
|
return void 0;
|
|
904
1033
|
}
|
|
905
|
-
function
|
|
1034
|
+
function objectsUnder(at) {
|
|
1035
|
+
if (!cd) return [];
|
|
1036
|
+
const p = toSvg(at.x, at.y);
|
|
1037
|
+
const refOf = (id) => {
|
|
1038
|
+
const ptr = cd.pathOf.get(id);
|
|
1039
|
+
const r = ptr === void 0 ? void 0 : resourceOf(ptr);
|
|
1040
|
+
return r && r.path === ptr ? r : void 0;
|
|
1041
|
+
};
|
|
1042
|
+
if (flat) return flat.panelsAt(p.x, p.y).map(refOf).filter((r) => !!r);
|
|
1043
|
+
const inside = (poly) => {
|
|
1044
|
+
let c = false;
|
|
1045
|
+
for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
|
|
1046
|
+
const [xi, yi] = poly[i], [xj, yj] = poly[j];
|
|
1047
|
+
if (yi > p.y !== yj > p.y && p.x < (xj - xi) * (p.y - yi) / (yj - yi) + xi) c = !c;
|
|
1048
|
+
}
|
|
1049
|
+
return c;
|
|
1050
|
+
};
|
|
1051
|
+
const depth = (i) => {
|
|
1052
|
+
let n = 0;
|
|
1053
|
+
for (let q = i.parent; q; q = q.parent) n++;
|
|
1054
|
+
return n;
|
|
1055
|
+
};
|
|
1056
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1057
|
+
for (const e of fdoc().elementsFromPoint(at.x, at.y)) {
|
|
1058
|
+
if (!svg?.contains(e)) continue;
|
|
1059
|
+
for (let el = e.closest("[data-id]"); el; el = el.parentElement?.closest("[data-id]") ?? null) {
|
|
1060
|
+
const r = refOf(el.getAttribute("data-id") ?? "");
|
|
1061
|
+
if (r && !seen.has(r.path)) seen.set(r.path, r);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
const hits = [];
|
|
1065
|
+
for (const [, id] of cd.pinId) {
|
|
1066
|
+
const item = cd.scene.layout.byId.get(id), r = refOf(id);
|
|
1067
|
+
if (item && r && !seen.has(r.path) && inside(floorOf(item.box))) hits.push({ r, d: depth(item), a: (item.box.x1 - item.box.x0) * (item.box.y1 - item.box.y0) });
|
|
1068
|
+
}
|
|
1069
|
+
return [...seen.values(), ...hits.sort((x, y) => y.d - x.d || x.a - y.a).map((h2) => h2.r)];
|
|
1070
|
+
}
|
|
1071
|
+
function addFromPalette(sec, at, item) {
|
|
906
1072
|
if (!doc.doc.ok) {
|
|
907
1073
|
opts.note("Fix the YAML first", "warn");
|
|
908
1074
|
return void 0;
|
|
909
1075
|
}
|
|
910
1076
|
const k = kindOf(sec);
|
|
911
|
-
const
|
|
1077
|
+
const preset = item?.value?.();
|
|
1078
|
+
const what = item && preset !== void 0 ? item.label.toLowerCase() : k.singular;
|
|
1079
|
+
const name = freshName(doc.text, item?.name ?? k.singular);
|
|
912
1080
|
const p = [...k.section, name];
|
|
913
|
-
let value = k.template();
|
|
1081
|
+
let value = preset ?? k.template();
|
|
914
1082
|
let into;
|
|
915
1083
|
const drop = at ? K.dropInto?.(sec) : void 0;
|
|
916
1084
|
if (at && drop) {
|
|
917
1085
|
const c = containerAt(drop.container, at);
|
|
918
1086
|
if (c) {
|
|
919
1087
|
into = c;
|
|
920
|
-
value = drop.value(c);
|
|
1088
|
+
value = { ...drop.value(c), ...preset ?? {} };
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
let intoLabel = into ? drop.label(into) : "";
|
|
1092
|
+
if (at && !into && K.dropOnto) {
|
|
1093
|
+
for (const t of objectsUnder(at)) {
|
|
1094
|
+
const plan = K.dropOnto(t, value, sec, doc.goodDoc.data);
|
|
1095
|
+
if (plan) {
|
|
1096
|
+
into = t.name;
|
|
1097
|
+
value = plan.value;
|
|
1098
|
+
intoLabel = plan.label ? ` ${plan.label}` : ` in ${t.name}`;
|
|
1099
|
+
break;
|
|
1100
|
+
}
|
|
921
1101
|
}
|
|
922
1102
|
}
|
|
923
|
-
const label = `Add ${
|
|
1103
|
+
const label = `Add ${what} ${name}${intoLabel}`;
|
|
924
1104
|
const add = insertCmd(p.slice(0, -1), name, value, { label });
|
|
925
1105
|
const pin = at && !into && mode === "3d" ? placeAt(name, add, at) : void 0;
|
|
926
1106
|
const cmd = pin ? seqCmd(`${label} at [${pin.join(", ")}]`, [add, withPinsMoved(setCmd([PINS_KEY, "layout", name], { at: pin }))]) : add;
|
|
927
1107
|
if (!run(doc, { ...cmd, select: [p] }, "canvas", opts.note)) return void 0;
|
|
928
1108
|
if (at && !into && !pin) opts.note(mode === "2d" ? `${k.singular} ${name} added; the layout placed it (in 3D a drop pins it where it lands)` : `${k.singular} ${name} added; that spot is taken, so the layout placed it`);
|
|
929
1109
|
doc.select([p], "canvas");
|
|
1110
|
+
stage.focus({ preventScroll: true });
|
|
930
1111
|
renameDialog(doc, p, "canvas", opts.note);
|
|
931
1112
|
return p;
|
|
932
1113
|
}
|
|
933
1114
|
const palette = h("div", { class: "palette", role: "toolbar", "aria-label": T.palette, "aria-orientation": "vertical" });
|
|
934
|
-
|
|
935
|
-
const
|
|
1115
|
+
ui.palette.forEach((item, idx) => {
|
|
1116
|
+
const { kind: sec, icon: ic, label } = item;
|
|
1117
|
+
const b = h("button", { type: "button", class: "pal-item", "data-section": sec, "data-entry": String(idx), title: `Add ${label.toLowerCase()} (click), or drag it where it goes` }, icon(ic), h("span", { class: "pal-label" }, label));
|
|
936
1118
|
b.addEventListener("pointerdown", (e) => {
|
|
937
1119
|
if (e.button !== 0) return;
|
|
938
1120
|
e.preventDefault();
|
|
@@ -965,8 +1147,8 @@ function canvasView(host, doc, opts) {
|
|
|
965
1147
|
const dragged = !!ghost;
|
|
966
1148
|
ghost?.remove();
|
|
967
1149
|
if (!drop) return;
|
|
968
|
-
if (!dragged) addFromPalette(sec);
|
|
969
|
-
else if (over(ev)) addFromPalette(sec, { x: ev.clientX, y: ev.clientY });
|
|
1150
|
+
if (!dragged) addFromPalette(sec, void 0, item);
|
|
1151
|
+
else if (over(ev)) addFromPalette(sec, { x: ev.clientX, y: ev.clientY }, item);
|
|
970
1152
|
};
|
|
971
1153
|
const upH = (ev) => done(ev, true), cancelH = (ev) => done(ev, false);
|
|
972
1154
|
const esc = (ev) => {
|
|
@@ -984,11 +1166,11 @@ function canvasView(host, doc, opts) {
|
|
|
984
1166
|
b.addEventListener("keydown", (e) => {
|
|
985
1167
|
if (e.key === "Enter" || e.key === " ") {
|
|
986
1168
|
e.preventDefault();
|
|
987
|
-
addFromPalette(sec);
|
|
1169
|
+
addFromPalette(sec, void 0, item);
|
|
988
1170
|
}
|
|
989
1171
|
});
|
|
990
1172
|
palette.append(b);
|
|
991
|
-
}
|
|
1173
|
+
});
|
|
992
1174
|
host.append(palette);
|
|
993
1175
|
function resetLayout() {
|
|
994
1176
|
const key2 = K.pins.keyOf(doc.goodDoc.data);
|
|
@@ -1045,6 +1227,12 @@ function canvasView(host, doc, opts) {
|
|
|
1045
1227
|
else return;
|
|
1046
1228
|
break;
|
|
1047
1229
|
case "Escape":
|
|
1230
|
+
if (linking) {
|
|
1231
|
+
linking = void 0;
|
|
1232
|
+
paintOverlay();
|
|
1233
|
+
opts.note("Not connected");
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1048
1236
|
if (pinDrag()) {
|
|
1049
1237
|
endPin(false);
|
|
1050
1238
|
break;
|
|
@@ -1095,6 +1283,10 @@ function canvasView(host, doc, opts) {
|
|
|
1095
1283
|
doc.select(drawn.map(fromPointer), "canvas");
|
|
1096
1284
|
break;
|
|
1097
1285
|
}
|
|
1286
|
+
if (mod && e.key.toLowerCase() === "g" && K.group && sel.length && !ro) {
|
|
1287
|
+
groupSelection();
|
|
1288
|
+
break;
|
|
1289
|
+
}
|
|
1098
1290
|
return;
|
|
1099
1291
|
}
|
|
1100
1292
|
e.preventDefault();
|
|
@@ -1139,6 +1331,12 @@ function canvasView(host, doc, opts) {
|
|
|
1139
1331
|
const base = {
|
|
1140
1332
|
addFromPalette,
|
|
1141
1333
|
palette,
|
|
1334
|
+
groupSelection,
|
|
1335
|
+
startPick,
|
|
1336
|
+
objectsUnder,
|
|
1337
|
+
get linking() {
|
|
1338
|
+
return linking;
|
|
1339
|
+
},
|
|
1142
1340
|
render,
|
|
1143
1341
|
setTheme,
|
|
1144
1342
|
paintOverlay,
|
|
@@ -76,7 +76,7 @@ function setupFor(a, v, textPane) {
|
|
|
76
76
|
rootClass: "iso-canvas",
|
|
77
77
|
panKeyClass: "pan-key",
|
|
78
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) })),
|
|
79
|
+
palette: v.palette ? v.palette.map((e) => ({ kind: e.kind, label: e.label, icon: e.icon ?? icon(e.kind), name: e.name, ...e.value === void 0 ? {} : { value: () => structuredClone(e.value) } })) : a.kinds.map((k) => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
|
|
80
80
|
text: {
|
|
81
81
|
stage: "The file, drawn: arrow keys and Tab move through what is drawn; + and \u2212 zoom, 0 fits",
|
|
82
82
|
dragGroup: "A drag on nothing",
|
|
@@ -99,6 +99,9 @@ function setupFor(a, v, textPane) {
|
|
|
99
99
|
pins,
|
|
100
100
|
ui: canvasUi,
|
|
101
101
|
flat: v.flat,
|
|
102
|
+
...a.connect ? { connect: (f, t, d) => a.connect(f, t, d) } : {},
|
|
103
|
+
...a.group ? { group: (m, d) => a.group(m, d) } : {},
|
|
104
|
+
...a.dropInto ? { dropOnto: (t, v2, k, d) => a.dropInto(t, v2, k, d) } : {},
|
|
102
105
|
trial: (text, theme) => {
|
|
103
106
|
const r = read(text);
|
|
104
107
|
return r.read === void 0 || r.diags.some((d) => d.severity === "error") ? void 0 : v.draw(r.read, r.read.data, theme);
|
|
@@ -119,7 +122,8 @@ function setupFor(a, v, textPane) {
|
|
|
119
122
|
return void 0;
|
|
120
123
|
},
|
|
121
124
|
extraLabel: () => ({ text: "", cls: "" }),
|
|
122
|
-
|
|
125
|
+
// (0.10.0) the plain keymap says ⌘G where the domain groups
|
|
126
|
+
keymap: v.keymap ?? (a.group ? PLAIN_KEYMAP.map((g) => g.where === "The tree and the canvas" ? { ...g, keys: [...g.keys, ["\u2318G", "Group the selection"]] } : g) : PLAIN_KEYMAP)
|
|
123
127
|
};
|
|
124
128
|
const features = {
|
|
125
129
|
canvas: { canvasView: (host, doc, o) => canvasView(host, doc, { ...o, theme: v.theme, kit: canvas, layer: v.layer }) },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnoscott/isometric-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "A generic isometric diagram engine: render (L0–L2) and editor (L0–L3), with a 2D view and a YAML diagram format.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
"./src/**",
|
|
9
9
|
"./js/**"
|
|
10
10
|
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/johnoscott/isometric-diagrams.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://johnoscott.github.io/isometric-diagrams/",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/johnoscott/isometric-diagrams/issues"
|
|
18
|
+
},
|
|
11
19
|
"publishConfig": {
|
|
12
20
|
"registry": "https://registry.npmjs.org/",
|
|
13
21
|
"access": "public"
|
|
@@ -397,6 +405,7 @@
|
|
|
397
405
|
"source": "./src/iso-editor/ui/layer.ts",
|
|
398
406
|
"default": "./js/iso-editor/ui/layer.js"
|
|
399
407
|
},
|
|
408
|
+
"./modules/iso-editor/ui/marks.css": "./src/iso-editor/ui/marks.css",
|
|
400
409
|
"./modules/iso-editor/ui/menu": {
|
|
401
410
|
"types": "./src/iso-editor/ui/menu.ts",
|
|
402
411
|
"source": "./src/iso-editor/ui/menu.ts",
|
|
@@ -53,6 +53,13 @@ export interface Ref {
|
|
|
53
53
|
/** a thing at a pointer: its kind, its name and its own pointer */
|
|
54
54
|
export interface ObjectRef { kind: string; name: string; path: string }
|
|
55
55
|
|
|
56
|
+
/** (0.10.0) what a connection drawn on the canvas writes: a value added to a list (`at`), or, with `name` (a base for a
|
|
57
|
+
* fresh one), to a map */
|
|
58
|
+
export interface ConnectPlan { at: Path; value: unknown; name?: string; label?: string }
|
|
59
|
+
/** (0.10.0) the selection made into a new container: where it goes (`at`, a map), the base of its fresh name, its
|
|
60
|
+
* value, and, given the name it got, what changes in each member (each a set) */
|
|
61
|
+
export interface GroupPlan { at: Path; name: string; value: unknown; members(name: string): { path: Path; value: unknown }[]; label?: string }
|
|
62
|
+
|
|
56
63
|
/** what the domain's reader says of a text */
|
|
57
64
|
export interface ReadOutcome {
|
|
58
65
|
diags: Diag[];
|
|
@@ -108,6 +115,18 @@ export interface DomainAdapter {
|
|
|
108
115
|
/** what a completion list says of an extra word in a slot */
|
|
109
116
|
extraDetail?(word: string, data: unknown): string | undefined;
|
|
110
117
|
|
|
118
|
+
/** (0.10.0) a connection drawn from one object to another: what to add, or undefined (these two don't connect). None:
|
|
119
|
+
* the canvas offers no connect gesture */
|
|
120
|
+
connect?(from: ObjectRef, to: ObjectRef, data: unknown): ConnectPlan | undefined;
|
|
121
|
+
/** (0.10.0) the selected objects grouped into a new container, as one step; undefined: these can't be. None: the
|
|
122
|
+
* canvas offers no Group */
|
|
123
|
+
group?(members: ObjectRef[], data: unknown): GroupPlan | undefined;
|
|
124
|
+
|
|
125
|
+
/** (0.10.1) a new object of `kind` (its value as the palette made it) dropped onto `target`: its value put inside the
|
|
126
|
+
* target, and the words for it ("in subnet app"), or undefined (the target doesn't hold it). The canvas asks what is
|
|
127
|
+
* under the drop, innermost first; none: a drop is pinned where it lands */
|
|
128
|
+
dropInto?(target: ObjectRef, value: unknown, kind: string, data: unknown): { value: unknown; label?: string } | undefined;
|
|
129
|
+
|
|
111
130
|
/** the top-level key order: where a new section goes */
|
|
112
131
|
topOrder: readonly string[];
|
|
113
132
|
/** the layout pins: the key they live under, a legacy key read too, and whether a file has only the legacy one */
|
package/src/iso-editor/index.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// The layer's public API. Importers name the module a name comes from (with code splitting, a barrel puts every file
|
|
8
8
|
// it reaches into each bundle that imports it); the Node tests may import this index.
|
|
9
9
|
|
|
10
|
-
export type { FileRole, ObjectKindInfo, RefSlot, Ref, ObjectRef, ReadOutcome, DomainAdapter } from './adapter.ts';
|
|
10
|
+
export type { FileRole, ObjectKindInfo, RefSlot, Ref, ObjectRef, ReadOutcome, DomainAdapter, ConnectPlan, GroupPlan } from './adapter.ts';
|
|
11
11
|
export { toPointer, fromPointer, parentOf, isPrefix, samePath } from './path.ts';
|
|
12
12
|
export type { Seg, Path } from './path.ts';
|
|
13
13
|
export { EditorDoc, completionContext } from './doc.ts';
|
|
@@ -52,7 +52,7 @@ export { propsPanel } from './ui/props.ts';
|
|
|
52
52
|
export type { PropsUi, PropsKit, PropsOpts } from './ui/props.ts';
|
|
53
53
|
export type { Box as CanvasBox, Outline, CanvasCtx, CanvasLayer } from './ui/canvas-layer.ts';
|
|
54
54
|
export { canvasView } from './ui/canvas.ts';
|
|
55
|
-
export type { CanvasDrawing, DropInto, CanvasUi, CanvasKit, CanvasOpts, FlatCanvas, FlatDrawn } from './ui/canvas.ts';
|
|
55
|
+
export type { CanvasDrawing, DropInto, CanvasUi, CanvasKit, CanvasOpts, FlatCanvas, FlatDrawn, PaletteItem } from './ui/canvas.ts';
|
|
56
56
|
// the canvas's 2D view (0.6.4): a host hands it to the canvas (DomainView.flat.load); the canvas never imports it
|
|
57
57
|
export { flatCanvas } from './ui/flat-canvas.ts';
|
|
58
58
|
export type { PartCtx, Attention, EditorPart } from './ui/part.ts';
|
package/src/iso-editor/splice.ts
CHANGED
|
@@ -364,9 +364,14 @@ export function insertItem(text: string, listPath: Path, value: unknown, index?:
|
|
|
364
364
|
const prefix = text.slice(dash, first.range![0]);
|
|
365
365
|
if (!/^\s*- $/.test(prefix)) return fallback(text, listPath, d => { const s = d.getIn(listPath) as YAMLSeq; s.items.splice(at, 0, d.createNode(value) as never); }, true);
|
|
366
366
|
const indent = prefix.indexOf('-');
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
367
|
+
// (0.10.0) a map among maps written inline ({ … }) is written inline too
|
|
368
|
+
const near = items[Math.min(at, items.length - 1)];
|
|
369
|
+
const inline = isObj(value) && isMap(near) && (near as { flow?: boolean }).flow;
|
|
370
|
+
const body = ' '.repeat(indent) + '- ' + (inline
|
|
371
|
+
? flowText(value)
|
|
372
|
+
: isObj(value) && Object.keys(value as object).length
|
|
373
|
+
? reindent(yamlText(value), indent + 2).slice(indent + 2)
|
|
374
|
+
: scalarText(value, { flow: false, indent: indent + 2 })) + '\n';
|
|
370
375
|
if (at < items.length) { const s = lineStart(text, items[at].range![0]); return { steps: [[{ start: s, end: s, text: body }]] }; }
|
|
371
376
|
const e = items[items.length - 1].range![1];
|
|
372
377
|
const end = nextLine(text, text[e - 1] === '\n' ? e - 1 : e);
|
|
@@ -217,8 +217,8 @@ body { position: relative; height: 100%; min-height: 0; font: var(--fw-regular)
|
|
|
217
217
|
}
|
|
218
218
|
/* E11: the palette, on the canvas: click to add, or drag onto the canvas */
|
|
219
219
|
@layer views {
|
|
220
|
-
.palette { position: absolute; left: var(--sp-3); top: var(--sp-3); display: flex; flex-direction: column; gap: 2px; padding: var(--sp-0); background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1, none); z-index: 2; }
|
|
221
|
-
.pal-item { display: flex; align-items: center; gap: var(--sp-2); height: var(--ctl-sm); padding: 0 var(--sp-2); border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2); font: inherit; font-size: var(--fs-sm); cursor: grab; text-align: left; touch-action: none; user-select: none; }
|
|
220
|
+
.palette { position: absolute; left: var(--sp-3); top: var(--sp-3); display: flex; flex-direction: column; gap: 2px; padding: var(--sp-0); max-height: calc(100% - 2 * var(--sp-3) - 56px); overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1, none); z-index: 2; }
|
|
221
|
+
.pal-item { display: flex; flex-shrink: 0; align-items: center; gap: var(--sp-2); height: var(--ctl-sm); padding: 0 var(--sp-2); border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-2); font: inherit; font-size: var(--fs-sm); cursor: grab; text-align: left; touch-action: none; user-select: none; }
|
|
222
222
|
.pal-item:hover { background: var(--state-hover); color: var(--ink); }
|
|
223
223
|
.pal-item:active { cursor: grabbing; }
|
|
224
224
|
.pal-item .icon { width: 14px; height: 14px; }
|