@johnoscott/isometric-engine 0.9.0 → 0.12.3
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 +54 -6
- package/README.md +1 -1
- package/assets/app.css +38 -3
- package/assets/icons.svg +1 -1
- package/assets/marks.css +5 -1
- package/iso-editor.js +173 -173
- package/iso-render.js +97 -97
- package/iso-systems.js +104 -104
- package/js/iso-editor/doc.js +4 -0
- package/js/iso-editor/splice.js +3 -1
- package/js/iso-editor/ui/canvas.js +393 -18
- package/js/iso-editor/ui/plain-icons.js +2 -0
- package/js/iso-editor/ui/setup.js +7 -2
- package/js/iso-objects/board.js +6 -1
- package/js/iso-objects/scene.js +3 -2
- package/js/iso-viewer/index.js +4 -1
- package/package.json +101 -92
- package/src/iso-core/compile-schema.ts +3 -1
- package/src/iso-editor/adapter.ts +19 -0
- package/src/iso-editor/doc.ts +6 -0
- package/src/iso-editor/index.ts +2 -2
- package/src/iso-editor/splice.ts +8 -3
- package/src/iso-editor/ui/app.css +33 -2
- package/src/iso-editor/ui/canvas.ts +299 -23
- package/src/iso-editor/ui/marks.css +5 -1
- package/src/iso-editor/ui/plain-icons.ts +2 -0
- package/src/iso-editor/ui/setup.ts +16 -3
- package/src/iso-objects/board.ts +6 -2
- package/src/iso-objects/route.ts +1 -1
- package/src/iso-objects/scene.ts +4 -2
- package/src/iso-viewer/index.ts +2 -2
- package/src/iso-viewer/morph.ts +5 -2
- package/types/iso-core/compile-schema.d.ts +2 -2
- 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 +44 -8
- package/types/iso-editor/ui/monaco-entry.d.ts +2 -0
- package/types/iso-editor/ui/setup.d.ts +13 -0
- package/types/iso-objects/route.d.ts +1 -1
- package/types/iso-systems/validate.d.ts +4 -0
- package/types/iso-viewer/bundle.d.ts +1 -0
- package/types/iso-viewer/index.d.ts +2 -2
- package/types/iso-viewer/morph.d.ts +6 -3
|
@@ -22,7 +22,7 @@ import type { EditorModel, Command } from '../model.ts';
|
|
|
22
22
|
import type { Problem } from '../validate.ts';
|
|
23
23
|
import { applyStep } from '../splice.ts';
|
|
24
24
|
import { seqCmd, type Commands } from '../commands.ts';
|
|
25
|
-
import type { ObjectKindInfo, ObjectRef } from '../adapter.ts';
|
|
25
|
+
import type { ObjectKindInfo, ObjectRef, ConnectPlan, GroupPlan } from '../adapter.ts';
|
|
26
26
|
import { fromPointer, toPointer, type Path } from '../path.ts';
|
|
27
27
|
import { buildSvg } from '../../iso-core/svg-dom.ts';
|
|
28
28
|
import { viewport, type View } from '../../iso-viewer/viewport.ts';
|
|
@@ -74,13 +74,26 @@ export interface CanvasUi {
|
|
|
74
74
|
rootClass: string; panKeyClass: string;
|
|
75
75
|
/** the kinds the canvas's menu offers, in order */
|
|
76
76
|
newOrder: string[];
|
|
77
|
-
palette:
|
|
77
|
+
/** the palette's entries: a kind, and (0.10.0) a preset: what a new one starts as (default: the kind's template) and
|
|
78
|
+
* the base of its fresh name (default: the kind's singular) */
|
|
79
|
+
palette: PaletteItem[];
|
|
80
|
+
/** (0.12.0) where the palette is: 'floating' (the default: over the canvas, at its top left) or 'docked' (a pane of
|
|
81
|
+
* its own at the canvas's left, with a search box filtering by label and section, resizable and collapsible; its
|
|
82
|
+
* width and whether it is collapsed are kept in the host's store as `canvas-palette-dock`) */
|
|
83
|
+
paletteLayout?: 'floating' | 'docked';
|
|
78
84
|
text: {
|
|
79
85
|
stage: string; dragGroup: string; dragSelectTip: string; unreadable: string; palette: string;
|
|
80
86
|
/** the end of a pin drag's hint */
|
|
81
87
|
pinHint: string; renameWhy: string; duplicateWhy: string;
|
|
82
88
|
};
|
|
83
89
|
}
|
|
90
|
+
export interface PaletteItem {
|
|
91
|
+
kind: string; icon: IconName; label: string; value?(): unknown; name?: string;
|
|
92
|
+
/** (0.11.0) the header it is listed under: entries with one are grouped by it, in order of first use, each group under
|
|
93
|
+
* a header that collapses (all collapsed but the one last added from, remembered in the host's store as
|
|
94
|
+
* `canvas-palette`); entries without one are listed as before, where they are */
|
|
95
|
+
section?: string;
|
|
96
|
+
}
|
|
84
97
|
/** what the canvas is given of the domain (M: the domain's reading of the file; D: its drawing) */
|
|
85
98
|
export interface CanvasKit<M, D extends CanvasDrawing> {
|
|
86
99
|
draw(model: M, data: unknown, theme: string): D;
|
|
@@ -89,7 +102,14 @@ export interface CanvasKit<M, D extends CanvasDrawing> {
|
|
|
89
102
|
catalog: KindCatalog;
|
|
90
103
|
objectOf(ptr: string): ObjectRef | undefined;
|
|
91
104
|
kinds: ObjectKindInfo[];
|
|
92
|
-
commands: Pick<Commands, 'setCmd' | 'deleteCmd' | 'insertCmd' | 'pinsCmd' | 'withPinsMoved' | 'describe' | 'freshName'>;
|
|
105
|
+
commands: Pick<Commands, 'setCmd' | 'deleteCmd' | 'insertCmd' | 'insertItemCmd' | 'pinsCmd' | 'withPinsMoved' | 'describe' | 'freshName'>;
|
|
106
|
+
/** (0.10.0) a connection drawn from one object to another (the adapter's connect): the canvas offers the gesture (a
|
|
107
|
+
* handle on a selected object, and "Connect to…") only when it is given */
|
|
108
|
+
connect?(from: ObjectRef, to: ObjectRef, data: unknown): ConnectPlan | undefined;
|
|
109
|
+
/** (0.10.1) a palette drop onto an object (the adapter's dropInto): the new thing inside it, asked innermost first */
|
|
110
|
+
dropOnto?(target: ObjectRef, value: unknown, kind: string, data: unknown): { value: unknown; label?: string } | undefined;
|
|
111
|
+
/** (0.10.0) the selection made into a new container (the adapter's group): Group, ⌘G, one undo step */
|
|
112
|
+
group?(members: ObjectRef[], data: unknown): GroupPlan | undefined;
|
|
93
113
|
actions: Actions;
|
|
94
114
|
/** what an object's own menu offers, beyond rename, duplicate and delete */
|
|
95
115
|
objectItems(doc: EditorModel, path: Path, origin: 'canvas' | 'menu', note?: (t: string, tone?: 'bad') => void): MenuItem[];
|
|
@@ -130,11 +150,14 @@ const SVGNS = 'http://www.w3.org/2000/svg';
|
|
|
130
150
|
|
|
131
151
|
export function canvasView<M, D extends CanvasDrawing, A extends object = object>(host: HTMLElement, doc: EditorModel, opts: CanvasOpts<M, D, A>) {
|
|
132
152
|
const K = opts.kit, ui = K.ui, T = ui.text;
|
|
133
|
-
const { setCmd, deleteCmd, insertCmd, pinsCmd, withPinsMoved, freshName, describe } = K.commands;
|
|
153
|
+
const { setCmd, deleteCmd, insertCmd, insertItemCmd, pinsCmd, withPinsMoved, freshName, describe } = K.commands;
|
|
134
154
|
const { deletePaths, renameDialog, duplicate, connected } = K.actions;
|
|
135
155
|
const resourceOf = (ptr: string) => K.objectOf(ptr);
|
|
136
156
|
const kindOf = (k: string) => K.kinds.find(x => x.kind === k)!;
|
|
137
157
|
const PINS_KEY = K.pins.key;
|
|
158
|
+
/** (0.10.0) a connection being drawn: from what, the pointer (in the drawing's coordinates), what it is over; `pick`:
|
|
159
|
+
* started from the menu, so the next click ends it */
|
|
160
|
+
let linking: { from: ObjectRef; x?: number; y?: number; over?: string; pick?: boolean } | undefined;
|
|
138
161
|
host.classList.add('canvas');
|
|
139
162
|
// the stage holds the drawing, and takes the focus, the keys and the pointer
|
|
140
163
|
const stage = h('div', { class: `${ui.rootClass} canvas-stage`, tabindex: '0', role: 'application', 'aria-label': T.stage });
|
|
@@ -313,7 +336,11 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
313
336
|
const live = layer?.extent?.() ?? [];
|
|
314
337
|
return union([...ptrs.flatMap(p => elementsFor(p)).filter(e => e.getBBox().width || e.getBBox().height).map(boxOf), ...live]);
|
|
315
338
|
}
|
|
316
|
-
|
|
339
|
+
// (0.12.1) the view is the stage's: docked, the palette's pane shares the host, so the host is wider than what is
|
|
340
|
+
// drawn (the scale, the pointer's place, a resize); floating, the stage is the host's whole area
|
|
341
|
+
const docked = ui.paletteLayout === 'docked';
|
|
342
|
+
const viewEl = docked ? stage : host;
|
|
343
|
+
const V = viewport(viewEl, {
|
|
317
344
|
svg: () => svg,
|
|
318
345
|
onApply: k => {
|
|
319
346
|
svg!.classList.toggle('zoom-near', k >= 1); // a layer's detail shows from 100% up
|
|
@@ -438,6 +465,31 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
438
465
|
};
|
|
439
466
|
if (hoverId !== undefined && !doc.selection.some(p => toPointer(p) === hoverId)) draw(hoverId, 'hover');
|
|
440
467
|
for (const p of doc.selection) draw(toPointer(p), 'ring');
|
|
468
|
+
// (0.10.0) connecting: a handle on the one selected object, and while a connection is drawn, its line and its target
|
|
469
|
+
const one = connectable();
|
|
470
|
+
const from = linking?.from ?? one;
|
|
471
|
+
const fb = from ? boxFor(fromPointer(from.path)) : undefined;
|
|
472
|
+
if (fb && K.connect) {
|
|
473
|
+
const k = scale(), hx = fb.x + fb.w + 10 / k, hy = fb.y + fb.h / 2;
|
|
474
|
+
if (linking && linking.x !== undefined && linking.y !== undefined) {
|
|
475
|
+
if (linking.over) draw(linking.over, 'hover');
|
|
476
|
+
const l = d.createElementNS(SVGNS, 'line');
|
|
477
|
+
l.setAttribute('class', `connect-line${linking.over ? ' ok' : ''}`);
|
|
478
|
+
l.setAttribute('x1', String(hx)); l.setAttribute('y1', String(hy)); l.setAttribute('x2', String(linking.x)); l.setAttribute('y2', String(linking.y));
|
|
479
|
+
overlay.append(l);
|
|
480
|
+
}
|
|
481
|
+
if (!linking) {
|
|
482
|
+
const c = d.createElementNS(SVGNS, 'circle');
|
|
483
|
+
c.setAttribute('class', 'connect-handle');
|
|
484
|
+
c.setAttribute('cx', String(hx)); c.setAttribute('cy', String(hy)); c.setAttribute('r', String(7 / k));
|
|
485
|
+
// the one mark that takes the pointer (through the CSSOM: a host's marks CSS may say none for the overlay)
|
|
486
|
+
c.style.pointerEvents = 'all'; c.style.cursor = 'crosshair';
|
|
487
|
+
const t = d.createElementNS(SVGNS, 'title');
|
|
488
|
+
t.textContent = `Drag to what ${from!.name} connects to`;
|
|
489
|
+
c.append(t);
|
|
490
|
+
overlay.append(c);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
441
493
|
// a badge on each drawn resource with problems
|
|
442
494
|
const counts = new Map<string, { e: number; w: number }>();
|
|
443
495
|
for (const pr of opts.problems()) {
|
|
@@ -497,6 +549,12 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
497
549
|
stage.focus({ preventScroll: true });
|
|
498
550
|
if (layer?.down?.(e)) return;
|
|
499
551
|
const { x, y } = pageXY(e);
|
|
552
|
+
// (0.10.0) a press on the connect handle starts a connection; a click while one is picked ends it
|
|
553
|
+
if (e.button === 0 && linking?.pick) { e.preventDefault(); endConnect(pathAtEvent(e.target)); return; }
|
|
554
|
+
if (e.button === 0 && (e.target as Element | null)?.closest?.('.connect-handle')) {
|
|
555
|
+
const one = connectable();
|
|
556
|
+
if (one) { capture(e); e.preventDefault(); const p = toSvg(x, y); linking = { from: one, x: p.x, y: p.y }; paintOverlay(); return; }
|
|
557
|
+
}
|
|
500
558
|
if (e.button === 0 || e.button === 1) capture(e);
|
|
501
559
|
const pan = () => { drag = { kind: 'pan', x0: x, y0: y, v0: { ...V.view! } }; svg?.classList.add('panning'); e.preventDefault(); };
|
|
502
560
|
if (e.button === 1 || spaceKeyDown) { pan(); return; }
|
|
@@ -540,6 +598,13 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
540
598
|
}
|
|
541
599
|
function move(e: PointerEvent) {
|
|
542
600
|
const { x, y } = pageXY(e);
|
|
601
|
+
if (linking) {
|
|
602
|
+
const p = toSvg(x, y), under = pathAtEvent(document.elementFromPoint(x, y));
|
|
603
|
+
const r = under === undefined ? undefined : resourceOf(under);
|
|
604
|
+
linking = { ...linking, x: p.x, y: p.y, over: r && r.path !== linking.from.path ? r.path : undefined };
|
|
605
|
+
paintOverlay();
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
543
608
|
if (!drag) {
|
|
544
609
|
const p = pathAtEvent(e.target);
|
|
545
610
|
if (p !== hoverId) { hoverId = p; paintOverlay(); }
|
|
@@ -753,6 +818,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
753
818
|
}
|
|
754
819
|
|
|
755
820
|
function up(e: PointerEvent) {
|
|
821
|
+
if (linking && !linking.pick) { const { x, y } = pageXY(e); endConnect(pathAtEvent(document.elementFromPoint(x, y))); return; }
|
|
756
822
|
const d0 = drag;
|
|
757
823
|
drag = undefined;
|
|
758
824
|
svg?.classList.remove('panning');
|
|
@@ -840,6 +906,9 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
840
906
|
items.push({ label: 'Show in text', icon: 'code-xml', onSelect: () => opts.showInText(one) });
|
|
841
907
|
items.push({ label: 'Show in tree', icon: 'list-tree', onSelect: () => opts.showInTree(one) });
|
|
842
908
|
}
|
|
909
|
+
// (0.10.0) connect and group, where the domain says how
|
|
910
|
+
if (K.connect && one && isRes) items.push({ label: 'Connect to…', icon: 'link', desc: 'Then click what it connects to (Esc cancels)', disabled: ro, onSelect: () => startPick() });
|
|
911
|
+
if (K.group) items.push({ label: sel.length > 1 ? `Group ${sel.length} items` : 'Group', icon: 'box', keys: '⌘G', desc: 'Into a new container, as one step', disabled: ro || !members().length, why: 'Only objects are grouped', onSelect: groupSelection });
|
|
843
912
|
items.push({ label: 'Select parent', icon: 'arrow-up-right', keys: '⌘↑', onSelect: selectParent });
|
|
844
913
|
items.push({ label: 'Select connected', icon: 'link', desc: 'What refers to it, and what it refers to', onSelect: () => doc.select(connected(doc, sel), 'canvas') });
|
|
845
914
|
items.push({ label: 'Zoom to selection', keys: '⇧2', onSelect: zoomToSelection });
|
|
@@ -847,6 +916,66 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
847
916
|
items.push({ sep: true }, { label: sel.length > 1 ? `Delete ${sel.length} items` : 'Delete', icon: 'trash-2', keys: '⌫', danger: true, disabled: ro, onSelect: () => deletePaths(doc, sel, 'canvas', opts.note) });
|
|
848
917
|
return items;
|
|
849
918
|
}
|
|
919
|
+
// ---------- (0.10.0) connect and group, by the domain's plans ----------
|
|
920
|
+
/** the one selected object, if the domain connects and the file reads */
|
|
921
|
+
function connectable(): ObjectRef | undefined {
|
|
922
|
+
if (!K.connect || !doc.doc.ok || doc.selection.length !== 1) return undefined;
|
|
923
|
+
const ptr = toPointer(doc.selection[0]), r = resourceOf(ptr);
|
|
924
|
+
return r && r.path === ptr ? r : undefined;
|
|
925
|
+
}
|
|
926
|
+
function startPick() {
|
|
927
|
+
const from = connectable();
|
|
928
|
+
if (!from) return;
|
|
929
|
+
linking = { from, pick: true };
|
|
930
|
+
opts.note(`Click what ${from.name} connects to (Esc cancels)`);
|
|
931
|
+
paintOverlay();
|
|
932
|
+
}
|
|
933
|
+
/** end a connection on what is under the pointer: the domain's plan, written as one step */
|
|
934
|
+
function endConnect(ptr: string | undefined) {
|
|
935
|
+
const from = linking?.from;
|
|
936
|
+
linking = undefined;
|
|
937
|
+
paintOverlay();
|
|
938
|
+
if (!from || ptr === undefined) return;
|
|
939
|
+
const to = resourceOf(ptr);
|
|
940
|
+
if (!to || to.path === from.path) { opts.note('Not connected: drop it on another object', 'warn'); return; }
|
|
941
|
+
const data = doc.goodDoc.data;
|
|
942
|
+
const plan = K.connect?.(from, to, data);
|
|
943
|
+
if (!plan) { opts.note(`${from.name} and ${to.name} can't be connected`, 'warn'); return; }
|
|
944
|
+
const label = plan.label ?? `Connect ${from.name} to ${to.name}`;
|
|
945
|
+
let cmd: Command, path: Path;
|
|
946
|
+
if (plan.name !== undefined) {
|
|
947
|
+
const name = freshName(doc.text, plan.name);
|
|
948
|
+
cmd = insertCmd(plan.at, name, plan.value, { label });
|
|
949
|
+
path = [...plan.at, name];
|
|
950
|
+
} else {
|
|
951
|
+
const list = plan.at.reduce<unknown>((x, k) => (x && typeof x === 'object' ? (x as Record<string, unknown>)[k as string] : undefined), data);
|
|
952
|
+
path = [...plan.at, Array.isArray(list) ? list.length : 0];
|
|
953
|
+
cmd = insertItemCmd(plan.at, plan.value, undefined, label);
|
|
954
|
+
}
|
|
955
|
+
if (run(doc, { ...cmd, select: [path] }, 'canvas', opts.note)) doc.select([path], 'canvas');
|
|
956
|
+
}
|
|
957
|
+
/** the selection's objects (a key inside one counts as its object), once each */
|
|
958
|
+
function members(): ObjectRef[] {
|
|
959
|
+
const out = new Map<string, ObjectRef>();
|
|
960
|
+
for (const p of doc.selection) { const r = resourceOf(toPointer(p)); if (r) out.set(r.path, r); }
|
|
961
|
+
return [...out.values()];
|
|
962
|
+
}
|
|
963
|
+
/** the selection into a new container: the container, each member's change and its pin dropped (the layout places it
|
|
964
|
+
* in its new frame), as one command, one undo step */
|
|
965
|
+
function groupSelection() {
|
|
966
|
+
if (!K.group || !doc.doc.ok) return;
|
|
967
|
+
const ms = members();
|
|
968
|
+
if (!ms.length) { opts.note('Only objects are grouped', 'warn'); return; }
|
|
969
|
+
const plan = K.group(ms, doc.goodDoc.data);
|
|
970
|
+
if (!plan) { opts.note(ms.length > 1 ? `These ${ms.length} can't be grouped` : `${ms[0].name} can't be grouped`, 'warn'); return; }
|
|
971
|
+
const name = freshName(doc.text, plan.name);
|
|
972
|
+
const pins = K.pins.of(doc.goodDoc.data) ?? {};
|
|
973
|
+
const unpin = ms.filter(m => pins[m.name] !== undefined).map(m => withPinsMoved(deleteCmd([PINS_KEY, 'layout', m.name])));
|
|
974
|
+
const label = plan.label ?? `Group ${ms.length > 1 ? `${ms.length} items` : ms[0].name} into ${name}`;
|
|
975
|
+
const p = [...plan.at, name] as Path;
|
|
976
|
+
const cmd = seqCmd(label, [insertCmd(plan.at, name, plan.value, { label }), ...plan.members(name).map(m => setCmd(m.path, m.value)), ...unpin]);
|
|
977
|
+
if (run(doc, { ...cmd, select: [p] }, 'canvas', opts.note)) doc.select([p], 'canvas');
|
|
978
|
+
}
|
|
850
979
|
function addResource(s: string) {
|
|
851
980
|
const k = kindOf(s);
|
|
852
981
|
const name = freshName(doc.text, k.singular);
|
|
@@ -898,40 +1027,186 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
898
1027
|
}
|
|
899
1028
|
return undefined;
|
|
900
1029
|
}
|
|
1030
|
+
/** (0.10.1) the objects whose drawn floor a point is on, innermost first: in 2D the panels under it; in 3D every placed
|
|
1031
|
+
* thing whose floor holds the point, the deepest (then the smallest) first */
|
|
1032
|
+
function objectsUnder(at: { x: number; y: number }): ObjectRef[] {
|
|
1033
|
+
if (!cd) return [];
|
|
1034
|
+
const p = toSvg(at.x, at.y);
|
|
1035
|
+
const refOf = (id: string) => { const ptr = cd!.pathOf.get(id); const r = ptr === undefined ? undefined : resourceOf(ptr); return r && r.path === ptr ? r : undefined; };
|
|
1036
|
+
if (flat) return flat.panelsAt(p.x, p.y).map(refOf).filter((r): r is ObjectRef => !!r);
|
|
1037
|
+
const inside = (poly: [number, number][]) => { let c = false; for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) { const [xi, yi] = poly[i], [xj, yj] = poly[j]; if ((yi > p.y) !== (yj > p.y) && p.x < (xj - xi) * (p.y - yi) / (yj - yi) + xi) c = !c; } return c; };
|
|
1038
|
+
const depth = (i: { parent?: unknown }) => { let n = 0; for (let q = i.parent as { parent?: unknown } | undefined; q; q = q.parent as { parent?: unknown } | undefined) n++; return n; };
|
|
1039
|
+
// what is drawn under the point, topmost (innermost) first, as the eye sees it; then any whose floor holds the point
|
|
1040
|
+
const seen = new Map<string, ObjectRef>();
|
|
1041
|
+
for (const e of fdoc().elementsFromPoint(at.x, at.y)) {
|
|
1042
|
+
if (!svg?.contains(e)) continue;
|
|
1043
|
+
for (let el = e.closest('[data-id]'); el; el = el.parentElement?.closest('[data-id]') ?? null) {
|
|
1044
|
+
const r = refOf(el.getAttribute('data-id') ?? '');
|
|
1045
|
+
if (r && !seen.has(r.path)) seen.set(r.path, r);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
const hits: { r: ObjectRef; d: number; a: number }[] = [];
|
|
1049
|
+
for (const [, id] of cd.pinId) {
|
|
1050
|
+
const item = cd.scene.layout.byId.get(id), r = refOf(id);
|
|
1051
|
+
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) });
|
|
1052
|
+
}
|
|
1053
|
+
return [...seen.values(), ...hits.sort((x, y) => y.d - x.d || x.a - y.a).map(h => h.r)];
|
|
1054
|
+
}
|
|
901
1055
|
/** Add an object from the palette: dropped at a point, it is pinned there; dropped on a container the kit names, it
|
|
902
1056
|
* is made inside it; else the layout places it. One command (one undo step); then it is selected and named. */
|
|
903
|
-
function addFromPalette(sec: string, at?: { x: number; y: number }): Path | undefined {
|
|
1057
|
+
function addFromPalette(sec: string, at?: { x: number; y: number }, item?: PaletteItem): Path | undefined {
|
|
904
1058
|
if (!doc.doc.ok) { opts.note('Fix the YAML first', 'warn'); return undefined; }
|
|
905
1059
|
const k = kindOf(sec);
|
|
906
|
-
|
|
1060
|
+
// (0.10.0) a palette entry's preset: what it starts as, and the base of its name
|
|
1061
|
+
const preset = item?.value?.() as Record<string, unknown> | undefined;
|
|
1062
|
+
const what = item && preset !== undefined ? item.label.toLowerCase() : k.singular;
|
|
1063
|
+
const name = freshName(doc.text, item?.name ?? k.singular);
|
|
907
1064
|
const p = [...k.section, name] as Path;
|
|
908
|
-
let value = k.template() as Record<string, unknown>;
|
|
1065
|
+
let value = (preset ?? k.template()) as Record<string, unknown>;
|
|
909
1066
|
let into: string | undefined;
|
|
910
1067
|
const drop = at ? K.dropInto?.(sec) : undefined;
|
|
911
1068
|
if (at && drop) {
|
|
912
1069
|
const c = containerAt(drop.container, at);
|
|
913
|
-
|
|
1070
|
+
// dropped into a container: what puts it there, and the preset's own keys over it
|
|
1071
|
+
if (c) { into = c; value = { ...(drop.value(c) as Record<string, unknown>), ...(preset ?? {}) }; }
|
|
914
1072
|
}
|
|
915
|
-
|
|
1073
|
+
let intoLabel = into ? drop!.label(into) : '';
|
|
1074
|
+
// (0.10.1) the domain's rule: the innermost object under the drop that holds it
|
|
1075
|
+
if (at && !into && K.dropOnto) {
|
|
1076
|
+
for (const t of objectsUnder(at)) {
|
|
1077
|
+
const plan = K.dropOnto(t, value, sec, doc.goodDoc.data);
|
|
1078
|
+
if (plan) { into = t.name; value = plan.value as Record<string, unknown>; intoLabel = plan.label ? ` ${plan.label}` : ` in ${t.name}`; break; }
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
const label = `Add ${what} ${name}${intoLabel}`;
|
|
916
1082
|
const add = insertCmd(p.slice(0, -1), name, value, { label });
|
|
917
1083
|
const pin = at && !into && mode === '3d' ? placeAt(name, add, at) : undefined;
|
|
918
1084
|
const cmd = pin ? seqCmd(`${label} at [${pin.join(', ')}]`, [add, withPinsMoved(setCmd([PINS_KEY, 'layout', name], { at: pin }))]) : add;
|
|
919
1085
|
if (!run(doc, { ...cmd, select: [p] }, 'canvas', opts.note)) return undefined;
|
|
920
1086
|
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`);
|
|
921
1087
|
doc.select([p], 'canvas');
|
|
1088
|
+
// (0.10.1) the canvas has the focus while the name is asked, so the dialog gives it back there (⌘Z works at once)
|
|
1089
|
+
stage.focus({ preventScroll: true });
|
|
922
1090
|
renameDialog(doc, p, 'canvas', opts.note);
|
|
923
1091
|
return p;
|
|
924
1092
|
}
|
|
925
1093
|
const palette = h('div', { class: 'palette', role: 'toolbar', 'aria-label': T.palette, 'aria-orientation': 'vertical' });
|
|
926
|
-
|
|
927
|
-
|
|
1094
|
+
// (0.11.0) sections: a header (a button, aria-expanded) over its entries; open: the section last added from (the
|
|
1095
|
+
// first, before any); the reader opens and closes the others as they like. The host's store may be off: guarded.
|
|
1096
|
+
const sections = new Map<string, { head: HTMLButtonElement; body: HTMLElement }>();
|
|
1097
|
+
const PAL_KEY = 'canvas-palette';
|
|
1098
|
+
let lastSection: string | undefined;
|
|
1099
|
+
try { const v = JSON.parse(opts.store?.get(PAL_KEY) ?? '{}') as { last?: unknown }; if (typeof v.last === 'string') lastSection = v.last; } catch { /* none */ }
|
|
1100
|
+
const named = [...new Set(ui.palette.map(i => i.section).filter((x): x is string => x !== undefined))];
|
|
1101
|
+
const openAtStart = lastSection !== undefined && named.includes(lastSection) ? lastSection : named[0];
|
|
1102
|
+
const setOpen = (sec: string, open: boolean) => { const g = sections.get(sec); if (!g) return; g.head.setAttribute('aria-expanded', String(open)); g.body.hidden = !open; };
|
|
1103
|
+
function sectionBody(sec: string): HTMLElement {
|
|
1104
|
+
const have = sections.get(sec);
|
|
1105
|
+
if (have) return have.body;
|
|
1106
|
+
const id = `pal-sec-${sections.size}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1107
|
+
const head = h('button', { type: 'button', class: 'pal-head', 'aria-expanded': 'false', 'aria-controls': id, 'data-section-head': sec }, icon('chevron-right', 'pal-chev'), h('span', { class: 'pal-head-label' }, sec)) as HTMLButtonElement;
|
|
1108
|
+
const body = h('div', { class: 'pal-body', id, role: 'group', 'aria-label': sec, 'data-section-body': sec });
|
|
1109
|
+
head.addEventListener('click', () => setOpen(sec, head.getAttribute('aria-expanded') !== 'true'));
|
|
1110
|
+
palette.append(h('div', { class: 'pal-section', 'data-pal-section': sec }, head, body));
|
|
1111
|
+
sections.set(sec, { head, body });
|
|
1112
|
+
setOpen(sec, sec === openAtStart);
|
|
1113
|
+
return body;
|
|
1114
|
+
}
|
|
1115
|
+
// (0.12.0) docked: a pane of its own at the canvas's left (the stage beside it): a search box over the list, a
|
|
1116
|
+
// control that collapses it to a strip, and a grip that resizes it; its width and state in the host's store
|
|
1117
|
+
const DOCK_KEY = 'canvas-palette-dock';
|
|
1118
|
+
const dockPref: { w?: number; collapsed?: boolean } = {};
|
|
1119
|
+
try { const v = JSON.parse(opts.store?.get(DOCK_KEY) ?? '{}') as { w?: unknown; collapsed?: unknown }; if (typeof v.w === 'number' && Number.isFinite(v.w)) dockPref.w = v.w; if (v.collapsed === true) dockPref.collapsed = true; } catch { /* none */ }
|
|
1120
|
+
const saveDock = () => { try { opts.store?.set(DOCK_KEY, JSON.stringify(dockPref)); } catch { /* storage may be off */ } };
|
|
1121
|
+
const DOCK_MIN = 160, DOCK_MAX = 440;
|
|
1122
|
+
const palHome: HTMLElement = docked ? h('aside', { class: 'pal-dock', 'aria-label': 'Palette' }) : palette;
|
|
1123
|
+
const palGrip = h('div', { class: 'pal-grip', role: 'separator', 'aria-orientation': 'vertical', 'aria-label': 'Resize the palette', tabindex: '0' });
|
|
1124
|
+
const search = h('input', { type: 'search', class: 'pal-search', placeholder: 'Search', 'aria-label': 'Search the palette', autocomplete: 'off', spellcheck: 'false' }) as HTMLInputElement;
|
|
1125
|
+
const none = h('p', { class: 'pal-none', role: 'status', hidden: '' });
|
|
1126
|
+
const collapseBtn = h('button', { type: 'button', class: 'btn sm quiet icon-only pal-collapse', 'aria-expanded': 'true', 'aria-label': 'Collapse the palette', title: 'Collapse the palette' }, icon('chevron-left')) as HTMLButtonElement;
|
|
1127
|
+
const visibleItems = () => [...palette.querySelectorAll<HTMLButtonElement>('.pal-item')].filter(b => !b.hidden && !b.closest('[hidden]'));
|
|
1128
|
+
/** the search: every word in the entry's label or its section; sections with a match open while it is on, and the
|
|
1129
|
+
* reader's own open and closed come back when it is cleared */
|
|
1130
|
+
let before: Map<string, boolean> | undefined;
|
|
1131
|
+
function filter() {
|
|
1132
|
+
const words = search.value.toLowerCase().split(/\s+/).filter(Boolean);
|
|
1133
|
+
if (words.length && !before) before = new Map([...sections].map(([k, g]) => [k, g.head.getAttribute('aria-expanded') === 'true']));
|
|
1134
|
+
let shown = 0;
|
|
1135
|
+
for (const b of palette.querySelectorAll<HTMLButtonElement>('.pal-item')) {
|
|
1136
|
+
const item = ui.palette[Number(b.dataset.entry)];
|
|
1137
|
+
const hay = `${item.label} ${item.section ?? ''}`.toLowerCase();
|
|
1138
|
+
b.hidden = !words.every(w => hay.includes(w));
|
|
1139
|
+
if (!b.hidden) shown++;
|
|
1140
|
+
}
|
|
1141
|
+
for (const [sec, g] of sections) {
|
|
1142
|
+
const any = [...g.body.querySelectorAll<HTMLButtonElement>('.pal-item')].some(b => !b.hidden);
|
|
1143
|
+
(g.head.parentElement as HTMLElement).hidden = words.length > 0 && !any;
|
|
1144
|
+
if (words.length) setOpen(sec, any);
|
|
1145
|
+
}
|
|
1146
|
+
if (!words.length && before) { for (const [sec, open] of before) setOpen(sec, open); before = undefined; }
|
|
1147
|
+
none.hidden = shown > 0;
|
|
1148
|
+
none.textContent = shown ? '' : `Nothing matches "${search.value.trim()}"`;
|
|
1149
|
+
}
|
|
1150
|
+
const setDockW = (w: number, keep = true) => { const v = Math.round(Math.min(DOCK_MAX, Math.max(DOCK_MIN, w))); host.style.setProperty('--pal-w', `${v}px`); palGrip.setAttribute('aria-valuenow', String(v)); if (keep) { dockPref.w = v; saveDock(); } };
|
|
1151
|
+
const setCollapsed = (c: boolean, keep = true) => {
|
|
1152
|
+
host.classList.toggle('pal-collapsed', c);
|
|
1153
|
+
collapseBtn.setAttribute('aria-expanded', String(!c));
|
|
1154
|
+
const say = c ? 'Show the palette' : 'Collapse the palette';
|
|
1155
|
+
collapseBtn.setAttribute('aria-label', say); collapseBtn.title = say;
|
|
1156
|
+
collapseBtn.replaceChildren(icon(c ? 'chevron-right' : 'chevron-left'));
|
|
1157
|
+
if (keep) { if (c) dockPref.collapsed = true; else delete dockPref.collapsed; saveDock(); }
|
|
1158
|
+
};
|
|
1159
|
+
if (docked) {
|
|
1160
|
+
host.classList.add('pal-docked');
|
|
1161
|
+
palette.classList.add('pal-list');
|
|
1162
|
+
palHome.append(h('div', { class: 'pal-dock-head' }, collapseBtn, h('label', { class: 'pal-search-wrap' }, icon('search'), search)), palette, none);
|
|
1163
|
+
palGrip.setAttribute('aria-valuemin', String(DOCK_MIN)); palGrip.setAttribute('aria-valuemax', String(DOCK_MAX));
|
|
1164
|
+
setDockW(dockPref.w ?? 220, false);
|
|
1165
|
+
setCollapsed(!!dockPref.collapsed, false);
|
|
1166
|
+
collapseBtn.addEventListener('click', () => { setCollapsed(!host.classList.contains('pal-collapsed')); if (!host.classList.contains('pal-collapsed')) search.focus(); });
|
|
1167
|
+
search.addEventListener('input', filter);
|
|
1168
|
+
search.addEventListener('keydown', e => {
|
|
1169
|
+
if (e.key === 'Escape' && search.value) { e.preventDefault(); e.stopPropagation(); search.value = ''; filter(); }
|
|
1170
|
+
else if (e.key === 'ArrowDown') { const first = visibleItems()[0]; if (first) { e.preventDefault(); first.focus(); } }
|
|
1171
|
+
else if (e.key === 'Enter') { const first = visibleItems()[0]; if (first) { e.preventDefault(); first.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })); } }
|
|
1172
|
+
});
|
|
1173
|
+
// the list's arrow keys: up and down through what is shown (up from the first: back to the search)
|
|
1174
|
+
palette.addEventListener('keydown', e => {
|
|
1175
|
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
|
|
1176
|
+
const all = [...palette.querySelectorAll<HTMLButtonElement>('.pal-head, .pal-item')].filter(b => !b.hidden && !b.parentElement?.closest('[hidden]') && (b.classList.contains('pal-head') || !b.closest('.pal-body[hidden]')));
|
|
1177
|
+
const i = all.indexOf(document.activeElement as HTMLButtonElement);
|
|
1178
|
+
if (i < 0) return;
|
|
1179
|
+
e.preventDefault();
|
|
1180
|
+
if (e.key === 'ArrowUp' && i === 0) search.focus(); else all[Math.min(all.length - 1, Math.max(0, i + (e.key === 'ArrowDown' ? 1 : -1)))].focus();
|
|
1181
|
+
});
|
|
1182
|
+
palGrip.addEventListener('pointerdown', e => {
|
|
1183
|
+
if (e.button !== 0) return;
|
|
1184
|
+
try { palGrip.setPointerCapture(e.pointerId); } catch { /* synthetic */ }
|
|
1185
|
+
const x0 = e.clientX, w0 = palHome.getBoundingClientRect().width;
|
|
1186
|
+
const mv = (ev: PointerEvent) => setDockW(w0 + ev.clientX - x0, false);
|
|
1187
|
+
const up = (ev: PointerEvent) => { palGrip.removeEventListener('pointermove', mv); palGrip.removeEventListener('pointerup', up); setDockW(w0 + ev.clientX - x0); };
|
|
1188
|
+
palGrip.addEventListener('pointermove', mv); palGrip.addEventListener('pointerup', up);
|
|
1189
|
+
});
|
|
1190
|
+
palGrip.addEventListener('keydown', e => {
|
|
1191
|
+
const d = e.key === 'ArrowLeft' ? -16 : e.key === 'ArrowRight' ? 16 : 0;
|
|
1192
|
+
if (d) { e.preventDefault(); setDockW(palHome.getBoundingClientRect().width + d); }
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
const usedSection = (item: PaletteItem) => {
|
|
1196
|
+
if (item.section === undefined || item.section === lastSection) return;
|
|
1197
|
+
lastSection = item.section;
|
|
1198
|
+
try { opts.store?.set(PAL_KEY, JSON.stringify({ last: lastSection })); } catch { /* storage may be off */ }
|
|
1199
|
+
};
|
|
1200
|
+
ui.palette.forEach((item, idx) => {
|
|
1201
|
+
const { kind: sec, icon: ic, label } = item;
|
|
1202
|
+
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));
|
|
928
1203
|
b.addEventListener('pointerdown', e => {
|
|
929
1204
|
if (e.button !== 0) return;
|
|
930
1205
|
e.preventDefault();
|
|
931
1206
|
try { b.setPointerCapture(e.pointerId); } catch { /* a synthetic pointer: the events come to the button anyway */ }
|
|
932
1207
|
const x0 = e.clientX, y0 = e.clientY;
|
|
933
1208
|
let ghost: HTMLElement | undefined;
|
|
934
|
-
const over = (ev: PointerEvent) => { const r = stage.getBoundingClientRect(); return ev.clientX >= r.left && ev.clientX <= r.right && ev.clientY >= r.top && ev.clientY <= r.bottom && !
|
|
1209
|
+
const over = (ev: PointerEvent) => { const r = stage.getBoundingClientRect(); return ev.clientX >= r.left && ev.clientX <= r.right && ev.clientY >= r.top && ev.clientY <= r.bottom && !palHome.contains(document.elementFromPoint(ev.clientX, ev.clientY)); };
|
|
935
1210
|
const mv = (ev: PointerEvent) => {
|
|
936
1211
|
if (!ghost && Math.hypot(ev.clientX - x0, ev.clientY - y0) < 4) return;
|
|
937
1212
|
if (!ghost) { ghost = h('div', { class: 'pal-ghost', 'aria-hidden': 'true' }, icon(ic), label); host.append(ghost); }
|
|
@@ -944,18 +1219,18 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
944
1219
|
const dragged = !!ghost;
|
|
945
1220
|
ghost?.remove();
|
|
946
1221
|
if (!drop) return;
|
|
947
|
-
if (!dragged) addFromPalette(sec);
|
|
948
|
-
else if (over(ev)) addFromPalette(sec, { x: ev.clientX, y: ev.clientY });
|
|
1222
|
+
if (!dragged) { usedSection(item); addFromPalette(sec, undefined, item); }
|
|
1223
|
+
else if (over(ev)) { usedSection(item); addFromPalette(sec, { x: ev.clientX, y: ev.clientY }, item); }
|
|
949
1224
|
};
|
|
950
1225
|
const upH = (ev: PointerEvent) => done(ev, true), cancelH = (ev: PointerEvent) => done(ev, false);
|
|
951
1226
|
const esc = (ev: KeyboardEvent) => { if (ev.key === 'Escape') { ev.stopPropagation(); ev.preventDefault(); done(e, false); } };
|
|
952
1227
|
b.addEventListener('pointermove', mv); b.addEventListener('pointerup', upH); b.addEventListener('pointercancel', cancelH); addEventListener('keydown', esc, true);
|
|
953
1228
|
});
|
|
954
1229
|
// the keyboard: Enter or the space key adds (the layout places it)
|
|
955
|
-
b.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); addFromPalette(sec); } });
|
|
956
|
-
palette.append(b);
|
|
957
|
-
}
|
|
958
|
-
host.append(palette);
|
|
1230
|
+
b.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); usedSection(item); addFromPalette(sec, undefined, item); } });
|
|
1231
|
+
(item.section === undefined ? palette : sectionBody(item.section)).append(b);
|
|
1232
|
+
});
|
|
1233
|
+
if (docked) host.prepend(palHome, palGrip); else host.append(palette);
|
|
959
1234
|
|
|
960
1235
|
function resetLayout() {
|
|
961
1236
|
// wherever the pins are (x-editor, or the legacy key): removed, and their key too if it holds nothing else
|
|
@@ -992,7 +1267,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
992
1267
|
case '0': fitItems(); break;
|
|
993
1268
|
case '1': actual(); break;
|
|
994
1269
|
case '@': case '2': if (e.shiftKey || e.key === '@') zoomToSelection(); else return; break;
|
|
995
|
-
case 'Escape': if (pinDrag()) { endPin(false); break; } doc.select([], 'canvas'); break;
|
|
1270
|
+
case 'Escape': if (linking) { linking = undefined; paintOverlay(); opts.note('Not connected'); break; } if (pinDrag()) { endPin(false); break; } doc.select([], 'canvas'); break;
|
|
996
1271
|
case 'Delete': case 'Backspace': if (sel.length && !ro) deletePaths(doc, sel, 'canvas', opts.note); break;
|
|
997
1272
|
case 'F2': if (sel.length === 1 && !ro) renameDialog(doc, sel[0], 'canvas', opts.note); break;
|
|
998
1273
|
case 'ArrowUp': if (mod) { selectParent(); break; } return;
|
|
@@ -1008,11 +1283,12 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1008
1283
|
}
|
|
1009
1284
|
case 'ContextMenu': case 'F10':
|
|
1010
1285
|
if (e.key === 'F10' && !e.shiftKey) return;
|
|
1011
|
-
{ const b = unionBox(sel); const r =
|
|
1286
|
+
{ const b = unionBox(sel); const r = viewEl.getBoundingClientRect(); const k = scale(); openMenu(menuItems(sel.length ? toPointer(sel[0]) : undefined), b ? { x: r.left + (b.x + b.w - V.view!.x) * k, y: r.top + (b.y - V.view!.y) * k } : { x: r.left + 40, y: r.top + 40 }, 'Canvas'); }
|
|
1012
1287
|
break;
|
|
1013
1288
|
default:
|
|
1014
1289
|
if (mod && e.key.toLowerCase() === 'd' && sel.length === 1 && !ro) { duplicate(doc, sel[0], 'canvas', opts.note); break; }
|
|
1015
1290
|
if (mod && e.key.toLowerCase() === 'a') { doc.select(drawn.map(fromPointer), 'canvas'); break; }
|
|
1291
|
+
if (mod && e.key.toLowerCase() === 'g' && K.group && sel.length && !ro) { groupSelection(); break; }
|
|
1016
1292
|
return;
|
|
1017
1293
|
}
|
|
1018
1294
|
e.preventDefault();
|
|
@@ -1053,7 +1329,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1053
1329
|
});
|
|
1054
1330
|
|
|
1055
1331
|
const base = {
|
|
1056
|
-
addFromPalette, palette,
|
|
1332
|
+
addFromPalette, palette, groupSelection, startPick, objectsUnder, get linking() { return linking; },
|
|
1057
1333
|
render, setTheme, paintOverlay, fit: fitItems, fitAll: fit, actual, zoomAt, itemsBox, get moved() { return V.moved; }, settled, get zoom() { return V.zoom; },
|
|
1058
1334
|
dispose() { endMorph(); clearTimeout(relayout); V.dispose(); disposed = true; },
|
|
1059
1335
|
focus: () => stage.focus(),
|
|
@@ -1063,7 +1339,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1063
1339
|
/** the view (3D or 2D), and the 2D layout while it shows */
|
|
1064
1340
|
get mode() { return mode; }, setMode, get flat() { return flat?.layout; },
|
|
1065
1341
|
stage, key, scale: () => scale(), nav, paintNav, outlinesFor, footprints, get drag() { return pinDrag(); }, get lastMarquee() { return lastMarquee; },
|
|
1066
|
-
boxFor, pageXYOf: (p: Path) => { const b = boxFor(p); const r =
|
|
1342
|
+
boxFor, pageXYOf: (p: Path) => { const b = boxFor(p); const r = viewEl.getBoundingClientRect(); const k = scale(); return b && V.view ? { x: r.left + (b.x + b.w / 2 - V.view.x) * k, y: r.top + (b.y + b.h / 2 - V.view.y) * k } : undefined; },
|
|
1067
1343
|
};
|
|
1068
1344
|
// the layer's calls, as they are (its getters stay getters)
|
|
1069
1345
|
if (layer) Object.defineProperties(base, Object.getOwnPropertyDescriptors(layer.api));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* The canvas's own marks over the drawing (0.7.4), for the plain words (setup.ts: the root .iso-canvas, the pan key's
|
|
2
2
|
class .pan-key): selection, hover, marquee, the drag's grid, drop target and edges,
|
|
3
|
-
problem badges, and the canvas's cursors. On the skin's tokens: --iso-sel* default to --accent, --iso-bad and
|
|
3
|
+
problem badges, the connect handle and line (0.10.0), and the canvas's cursors. On the skin's tokens: --iso-sel* default to --accent, --iso-bad and
|
|
4
4
|
--iso-warn to --bad and --warn; a host may set any of them on .iso-canvas. The package's assets/app.css carries
|
|
5
5
|
this file after the layout, and it ships alone as assets/marks.css. (A domain with its own words styles its own.)
|
|
6
6
|
Without any of it the marks are still harmless: the overlay's own attributes give no fill and take no pointer. */
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
.iso-canvas .overlay .drop { fill: var(--iso-sel-fill); stroke: var(--iso-sel); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
|
|
28
28
|
.iso-canvas .overlay .drop.bad { fill: color-mix(in srgb, var(--iso-bad) 18%, transparent); stroke: var(--iso-bad); }
|
|
29
29
|
.iso-canvas .overlay .edge { fill: none; stroke: var(--iso-sel); stroke-width: 4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
|
|
30
|
+
.iso-canvas .overlay .connect-handle { fill: var(--surface, #fff); stroke: var(--iso-sel); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: all; cursor: crosshair; }
|
|
31
|
+
.iso-canvas .overlay .connect-handle:hover { fill: var(--iso-sel); }
|
|
32
|
+
.iso-canvas .overlay .connect-line { stroke: var(--iso-sel); stroke-width: 2; stroke-dasharray: 5 4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
|
|
33
|
+
.iso-canvas .overlay .connect-line.ok { stroke-dasharray: none; }
|
|
30
34
|
.iso-canvas .overlay .badge circle { fill: var(--iso-bad); stroke: none; }
|
|
31
35
|
.iso-canvas .overlay .badge.warn circle { fill: var(--iso-warn); }
|
|
32
36
|
.iso-canvas .overlay .badge text { fill: #fff; stroke: none; font-family: system-ui, sans-serif; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
|
|
@@ -52,6 +52,7 @@ export const PLAIN_ICON_SVG: Record<string, string> = {
|
|
|
52
52
|
'arrow-up-right': '<path d="M7 7h10v10" /> <path d="M7 17 17 7" />',
|
|
53
53
|
'box': '<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z" /> <path d="m3.3 7 8.7 5 8.7-5" /> <path d="M12 22V12" />',
|
|
54
54
|
'chevron-down': '<path d="m6 9 6 6 6-6" />',
|
|
55
|
+
'chevron-left': '<path d="m15 18-6-6 6-6" />',
|
|
55
56
|
'chevron-right': '<path d="m9 18 6-6-6-6" />',
|
|
56
57
|
'circle-dot': '<circle cx="12" cy="12" r="1" /> <circle cx="12" cy="12" r="10" />',
|
|
57
58
|
'circle-x': '<circle cx="12" cy="12" r="10" /> <path d="m15 9-6 6" /> <path d="m9 9 6 6" />',
|
|
@@ -67,6 +68,7 @@ export const PLAIN_ICON_SVG: Record<string, string> = {
|
|
|
67
68
|
'pencil': '<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" /> <path d="m15 5 4 4" />',
|
|
68
69
|
'plus': '<path d="M5 12h14" /> <path d="M12 5v14" />',
|
|
69
70
|
'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" />',
|
|
71
|
+
'search': '<path d="m21 21-4.34-4.34" /> <circle cx="11" cy="11" r="8" />',
|
|
70
72
|
'trash-2': '<path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />',
|
|
71
73
|
'triangle-alert': '<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" /> <path d="M12 9v4" /> <path d="M12 17h.01" />',
|
|
72
74
|
'x': '<path d="M18 6 6 18" /> <path d="m6 6 12 12" />',
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// The text pane is given, not imported: Monaco is a big dependency, and a host without it still gets the canvas, the
|
|
8
8
|
// tree and the panel.
|
|
9
9
|
|
|
10
|
-
import type { DomainAdapter, FileRole } from '../adapter.ts';
|
|
10
|
+
import type { DomainAdapter, FileRole, ObjectRef } from '../adapter.ts';
|
|
11
11
|
import type { Path } from '../path.ts';
|
|
12
12
|
import { toPointer } from '../path.ts';
|
|
13
13
|
import { outline } from '../outline.ts';
|
|
@@ -50,6 +50,12 @@ export interface DomainView<R, D extends CanvasDrawing> {
|
|
|
50
50
|
icons?: Record<string, string>;
|
|
51
51
|
words?: Partial<ShellWords>;
|
|
52
52
|
keymap?: KeyGroup[];
|
|
53
|
+
/** (0.10.0) the palette's entries: presets of a kind, each with its label, icon, what a new one starts as (a copy of
|
|
54
|
+
* `value`; default: the kind's template) and the base of its fresh name. None: one entry per kind, as before */
|
|
55
|
+
palette?: { kind: string; label: string; icon?: string; value?: unknown; name?: string; section?: string }[];
|
|
56
|
+
/** (0.12.0) the palette 'floating' over the canvas (the default) or 'docked': a pane of its own at the canvas's left,
|
|
57
|
+
* searchable by label and section, resizable and collapsible */
|
|
58
|
+
paletteLayout?: 'floating' | 'docked';
|
|
53
59
|
/** the canvas's 2D view (0.6.0): a 3D | 2D switch; its link kinds' styles (the host's canvas CSS adds flatCss) */
|
|
54
60
|
flat?: CanvasKit<R, D>['flat'];
|
|
55
61
|
/** a layer over the canvas, and a part beside the views (A: their calls) */
|
|
@@ -102,7 +108,10 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
|
|
|
102
108
|
};
|
|
103
109
|
const canvasUi: CanvasUi = {
|
|
104
110
|
rootClass: 'iso-canvas', panKeyClass: 'pan-key', newOrder: a.kinds.map(k => k.kind),
|
|
105
|
-
palette:
|
|
111
|
+
palette: v.palette
|
|
112
|
+
? v.palette.map(e => ({ kind: e.kind, label: e.label, icon: (e.icon ?? icon(e.kind)) as IconName, name: e.name, ...(e.section === undefined ? {} : { section: e.section }), ...(e.value === undefined ? {} : { value: () => structuredClone(e.value) }) }))
|
|
113
|
+
: a.kinds.map(k => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
|
|
114
|
+
...(v.paletteLayout === undefined ? {} : { paletteLayout: v.paletteLayout }),
|
|
106
115
|
text: {
|
|
107
116
|
stage: 'The file, drawn: arrow keys and Tab move through what is drawn; + and − zoom, 0 fits', dragGroup: 'A drag on nothing',
|
|
108
117
|
dragSelectTip: 'Drag draws a selection; hold the space key to pan', unreadable: 'The canvas draws a file that reads cleanly; fix the problems listed to see it.',
|
|
@@ -111,6 +120,9 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
|
|
|
111
120
|
};
|
|
112
121
|
const canvas: CanvasKit<R, D> = {
|
|
113
122
|
draw: v.draw, catalog: v.catalog, objectOf: a.objectOf, kinds: a.kinds, commands, actions, objectItems: () => [], pins, ui: canvasUi, flat: v.flat,
|
|
123
|
+
...(a.connect ? { connect: (f: ObjectRef, t: ObjectRef, d: unknown) => a.connect!(f, t, d) } : {}),
|
|
124
|
+
...(a.group ? { group: (m: ObjectRef[], d: unknown) => a.group!(m, d) } : {}),
|
|
125
|
+
...(a.dropInto ? { dropOnto: (t: ObjectRef, v: unknown, k: string, d: unknown) => a.dropInto!(t, v, k, d) } : {}),
|
|
114
126
|
trial: (text, theme) => { const r = read(text); return r.read === undefined || r.diags.some(d => d.severity === 'error') ? undefined : v.draw(r.read as R, (r.read as { data?: unknown }).data, theme); },
|
|
115
127
|
};
|
|
116
128
|
const kit: MountKit<R, undefined> = {
|
|
@@ -128,7 +140,8 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
|
|
|
128
140
|
return undefined;
|
|
129
141
|
},
|
|
130
142
|
extraLabel: () => ({ text: '', cls: '' }),
|
|
131
|
-
|
|
143
|
+
// (0.10.0) the plain keymap says ⌘G where the domain groups
|
|
144
|
+
keymap: v.keymap ?? (a.group ? PLAIN_KEYMAP.map(g => (g.where === 'The tree and the canvas' ? { ...g, keys: [...g.keys, ['⌘G', 'Group the selection'] as [string, string]] } : g)) : PLAIN_KEYMAP),
|
|
132
145
|
};
|
|
133
146
|
const features: ShellFeatures & Record<string, unknown> = {
|
|
134
147
|
canvas: { canvasView: (host: HTMLElement, doc: EditorModel, o: never) => canvasView<R, D, object>(host, doc, { ...(o as object), theme: v.theme, kit: canvas, layer: v.layer } as never) },
|
package/src/iso-objects/board.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// card above it, and its column one right of every card left of it, asked of the two things that part them (so each
|
|
6
6
|
// container's rows and columns are its own, and near-aligned boxes share them); a card in no region keeps its place
|
|
7
7
|
// across. Two cards in one cell get a column each. A region (or a node
|
|
8
|
-
// holding nodes) is a panel over the cells of what it holds; one holding nothing has no cell and isn't shown
|
|
8
|
+
// holding nodes) is a panel over the cells of what it holds; one holding nothing has no cell and isn't shown (in a
|
|
9
|
+
// drawing with no nodes at all, the innermost regions are the cards). Routes
|
|
9
10
|
// are links, their ends' sides dropped. What 2D leaves out: sizes (every card is the same size), heights, a route's
|
|
10
11
|
// sides and via points, a region's label style.
|
|
11
12
|
|
|
@@ -22,7 +23,9 @@ import { placeBoard, type Board, type BoardCard, type BoardLink, type BoardPanel
|
|
|
22
23
|
export function boardOf(scene: CompiledScene, visible: (id: string) => boolean = () => true): Required<Board> {
|
|
23
24
|
const items = scene.layout.items.filter(p => visible(p.id));
|
|
24
25
|
const cat = scene.layout.catalog;
|
|
25
|
-
|
|
26
|
+
// (0.12.2) a drawing of regions alone has no nodes to be cards: its innermost regions are (else 2D would be empty)
|
|
27
|
+
const bare = !scene.layout.items.some(p => p.type === 'node');
|
|
28
|
+
const isCard = (p: Placed) => (bare ? !p.children.some(c => visible(c.id)) : p.type === 'node' && !p.children.some(c => c.type === 'node' && visible(c.id)));
|
|
26
29
|
const cardsP = items.filter(isCard);
|
|
27
30
|
// rows and columns: a card is a row below every card above it, and a column right of every card left of it, asked of
|
|
28
31
|
// the two things that part them (the children of their nearest common container holding each: their regions, or the
|
|
@@ -68,6 +71,7 @@ export function boardOf(scene: CompiledScene, visible: (id: string) => boolean =
|
|
|
68
71
|
} else taken.set(String(c), p.id);
|
|
69
72
|
}
|
|
70
73
|
const cards: BoardCard[] = cardsP.map(p => {
|
|
74
|
+
if (p.region) { const r = p.region; return { id: p.id, label: r.label ?? p.id, sub: undefined, role: r.role ?? regionKind(cat, r.kind)?.role ?? 'grey', ghost: r.ghost || undefined, cell: cell.get(p.id)! }; }
|
|
71
75
|
const n = p.node!, a = nodeKindOr(cat, n.asset);
|
|
72
76
|
return { id: p.id, label: n.label ?? p.id, sub: n.sub, role: n.role ?? a.role, ghost: n.ghost || undefined, cell: cell.get(p.id)! };
|
|
73
77
|
});
|
package/src/iso-objects/route.ts
CHANGED
|
@@ -74,7 +74,7 @@ export interface RouteResult { routes: Routed[]; diags: Diag[] }
|
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* The search steps routing may take in one scene. The heaviest diagram in this repo takes about 57,000
|
|
77
|
-
* (the
|
|
77
|
+
* (the large drawing in corpus/messaging.yaml); a drawing with 40 more nodes took 11 million, and minutes. Past the budget,
|
|
78
78
|
* the routes left are drawn as plain elbows and the scene says so, so a large diagram draws in about a second.
|
|
79
79
|
*/
|
|
80
80
|
export const ROUTE_BUDGET = 500_000;
|