@johnoscott/isometric-engine 0.10.1 → 0.12.6

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.
Files changed (56) hide show
  1. package/EDITOR-GUIDE.md +12 -1
  2. package/README.md +1 -1
  3. package/assets/app.css +37 -0
  4. package/assets/icons.svg +1 -1
  5. package/iso-editor.js +182 -182
  6. package/iso-render.js +105 -105
  7. package/iso-systems.js +108 -108
  8. package/js/iso-editor/commands.js +7 -0
  9. package/js/iso-editor/connections.js +24 -0
  10. package/js/iso-editor/doc.js +4 -0
  11. package/js/iso-editor/model.js +17 -3
  12. package/js/iso-editor/ui/actions.js +22 -24
  13. package/js/iso-editor/ui/canvas.js +277 -20
  14. package/js/iso-editor/ui/mount.js +2 -1
  15. package/js/iso-editor/ui/plain-icons.js +2 -0
  16. package/js/iso-editor/ui/props.js +2 -2
  17. package/js/iso-editor/ui/rename.js +114 -0
  18. package/js/iso-editor/ui/setup.js +3 -1
  19. package/js/iso-objects/board.js +6 -1
  20. package/js/iso-objects/scene.js +3 -2
  21. package/js/iso-viewer/index.js +4 -1
  22. package/js/iso-viewer/viewport.js +17 -5
  23. package/package.json +92 -92
  24. package/src/iso-core/compile-schema.ts +3 -1
  25. package/src/iso-editor/commands.ts +9 -0
  26. package/src/iso-editor/connections.ts +28 -0
  27. package/src/iso-editor/doc.ts +6 -0
  28. package/src/iso-editor/model.ts +17 -3
  29. package/src/iso-editor/ui/actions.ts +20 -23
  30. package/src/iso-editor/ui/app.css +37 -0
  31. package/src/iso-editor/ui/canvas.ts +214 -25
  32. package/src/iso-editor/ui/mount.ts +4 -3
  33. package/src/iso-editor/ui/plain-icons.ts +2 -0
  34. package/src/iso-editor/ui/props.ts +3 -3
  35. package/src/iso-editor/ui/rename.ts +105 -0
  36. package/src/iso-editor/ui/setup.ts +9 -2
  37. package/src/iso-objects/board.ts +6 -2
  38. package/src/iso-objects/scene.ts +4 -2
  39. package/src/iso-viewer/index.ts +2 -2
  40. package/src/iso-viewer/morph.ts +5 -2
  41. package/src/iso-viewer/viewport.ts +25 -5
  42. package/types/iso-core/compile-schema.d.ts +2 -2
  43. package/types/iso-editor/connections.d.ts +8 -0
  44. package/types/iso-editor/model.d.ts +8 -2
  45. package/types/iso-editor/ui/actions.d.ts +5 -2
  46. package/types/iso-editor/ui/canvas.d.ts +18 -1
  47. package/types/iso-editor/ui/monaco-entry.d.ts +2 -0
  48. package/types/iso-editor/ui/mount.d.ts +6 -2
  49. package/types/iso-editor/ui/props.d.ts +1 -1
  50. package/types/iso-editor/ui/rename.d.ts +43 -0
  51. package/types/iso-editor/ui/setup.d.ts +6 -0
  52. package/types/iso-systems/validate.d.ts +4 -0
  53. package/types/iso-viewer/bundle.d.ts +1 -0
  54. package/types/iso-viewer/index.d.ts +2 -2
  55. package/types/iso-viewer/morph.d.ts +6 -3
  56. package/types/iso-viewer/viewport.d.ts +13 -1
@@ -172,6 +172,12 @@ function parentByIndent(d: EditorDoc, lineStart: number, indent: number, forList
172
172
  if (a.where === 'key') return a.path.slice(0, -1);
173
173
  if (line.slice(ind).startsWith('- ')) return a.path.slice(0, -1);
174
174
  }
175
+ // (0.12.2) "- key: …" holds its item's first key two columns in: a key typed below it at that column is its
176
+ // sibling, in the same item (a list of maps, written in block style)
177
+ if (!forList && /^- /.test(line.slice(ind)) && ind + 2 === indent) {
178
+ const a = d.at(s + ind + 2);
179
+ if (a.where === 'key') return a.path.slice(0, -1);
180
+ }
175
181
  if (ind < indent || (forList && ind <= indent && /:\s*$/.test(line))) {
176
182
  const m = /^(\s*)(- )?([^\s:#][^:#]*?)\s*:/.exec(line);
177
183
  if (m) {
@@ -16,6 +16,8 @@ export interface Command {
16
16
  build(text: string): Splice;
17
17
  /** the paths it touched (for the views to refresh and reveal) */
18
18
  touched?: Path[];
19
+ /** (0.12.5) the label of the step it joined (apply's `joins`), given the step's own */
20
+ joined?(label: string): string;
19
21
  /** where a path is after the change (a rename moves paths); null when it no longer exists */
20
22
  remap?(p: Path): Path | null;
21
23
  /** the selection afterwards (default: the old one, remapped) */
@@ -119,8 +121,10 @@ export class EditorModel {
119
121
 
120
122
  // ---------- doing ----------
121
123
 
122
- /** Run a command: build it against the text, apply its steps, push it. Returns false if it changed nothing. */
123
- apply(cmd: Command, origin: Origin = 'api'): boolean {
124
+ /** Run a command: build it against the text, apply its steps, push it. Returns false if it changed nothing. `joins`
125
+ * (0.12.5): the id of an undo step it is part of, when that is the last one, nothing was undone since and the file
126
+ * wasn't saved at it (the saved text must stay a step of its own to come back to). */
127
+ apply(cmd: Command, origin: Origin = 'api', joins?: number): boolean {
124
128
  this.seal();
125
129
  const splice = cmd.build(this._text);
126
130
  if (!splice.steps.some(s => s.length)) return false;
@@ -129,7 +133,15 @@ export class EditorModel {
129
133
  const remap = cmd.remap ?? ((p: Path) => p);
130
134
  this.selection = cmd.select ?? this.selection.map(remap).filter((p): p is Path => p !== null);
131
135
  if (splice.fallback) this.fallbacks++;
132
- this.push({ id: this.nextId++, label: cmd.label, origin, steps: splice.steps, inverse, before, after: { paths: this.selection, text: this.textSel }, time: this.now(), fallback: !!splice.fallback, open: false });
136
+ const top = this.undoStack[this.undoStack.length - 1];
137
+ if (top && joins !== undefined && top.id === joins && !this.redoStack.length && top.id !== this.cleanId) {
138
+ top.label = cmd.joined?.(top.label) ?? top.label;
139
+ top.steps.push(...splice.steps);
140
+ top.inverse.unshift(...inverse);
141
+ top.after = { paths: this.selection, text: this.textSel };
142
+ top.time = this.now();
143
+ top.fallback ||= !!splice.fallback;
144
+ } else this.push({ id: this.nextId++, label: cmd.label, origin, steps: splice.steps, inverse, before, after: { paths: this.selection, text: this.textSel }, time: this.now(), fallback: !!splice.fallback, open: false });
133
145
  this.emit({ kind: 'do', origin, label: cmd.label, steps: splice.steps, version: this._version, remap: cmd.remap });
134
146
  for (const fn of this.selListeners) fn({ paths: this.selection, origin });
135
147
  return true;
@@ -196,6 +208,8 @@ export class EditorModel {
196
208
 
197
209
  get canUndo() { return this.undoStack.length > 0; }
198
210
  get canRedo() { return this.redoStack.length > 0; }
211
+ /** the last undo step's id (what `apply` may join) */
212
+ get undoId() { return this.undoStack[this.undoStack.length - 1]?.id; }
199
213
  get undoLabel() { return this.undoStack[this.undoStack.length - 1]?.label; }
200
214
  get redoLabel() { return this.redoStack[this.redoStack.length - 1]?.label; }
201
215
 
@@ -1,10 +1,11 @@
1
1
  // Actions the canvas and the properties panel share (the tree has its own inline forms of the same commands): delete
2
- // with a references dialog, rename in a dialog, duplicate, select connected. What an object is and how it is named
2
+ // with a references dialog, rename in the inline field, duplicate, select connected. What an object is and how it is named
3
3
  // are the kit's (the domain's commands, objectOf, kinds and name rule); what each kind offers in its own menu is the
4
4
  // domain's too.
5
5
 
6
6
  import { h } from './icons.ts';
7
7
  import { ask } from './dialog.ts';
8
+ import { renameField, type RenameAt } from './rename.ts';
8
9
  import type { EditorModel, Command } from '../model.ts';
9
10
  import type { Commands } from '../commands.ts';
10
11
  import type { ObjectKindInfo, ObjectRef } from '../adapter.ts';
@@ -23,8 +24,8 @@ export interface ActionsKit {
23
24
  nameHint: string;
24
25
  }
25
26
 
26
- export function run(doc: EditorModel, c: Command, origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void): boolean {
27
- try { return doc.apply(c, origin); } catch (e) { note?.(String((e as Error).message), 'bad'); return false; }
27
+ export function run(doc: EditorModel, c: Command, origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void, joins?: number): boolean {
28
+ try { return doc.apply(c, origin, joins); } catch (e) { note?.(String((e as Error).message), 'bad'); return false; }
28
29
  }
29
30
 
30
31
  /** Several commands as one undo step. */
@@ -68,26 +69,22 @@ async function deletePaths(doc: EditorModel, paths: Path[], origin: 'canvas' | '
68
69
  return ok;
69
70
  }
70
71
 
71
- /** Rename in a dialog (the canvas has no inline field). */
72
- async function renameDialog(doc: EditorModel, path: Path, origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void): Promise<boolean> {
73
- const now = String(path[path.length - 1]);
74
- const input = h('input', { type: 'text', value: now, 'aria-label': 'New name', spellcheck: 'false', autocomplete: 'off', class: 'mono-input' });
75
- input.value = now;
76
- const why = h('p', { class: 'dlg-error', role: 'alert' });
72
+ /** Rename, in the inline field (rename.ts). `joins`: the undo step it becomes part of (an add's, so a drop and its name
73
+ * are one), when that is still the last one. */
74
+ async function rename(doc: EditorModel, path: Path, origin: 'canvas' | 'props' | 'menu', note: ((t: string, tone?: 'bad') => void) | undefined, at: RenameAt & { joins?: number }): Promise<boolean> {
75
+ const now = String(path[path.length - 1]), res = isRes(path);
76
+ let here: Path | null = path;
77
+ const off = doc.on(c => { if (here && c.remap) here = c.remap(here); });
77
78
  const used = () => kit.kinds.flatMap(k => Object.keys((getIn(doc.goodDoc.data, k.section) ?? {}) as Raw));
78
- const check = () => {
79
- const v = input.value.trim();
80
- const bad = !kit.nameRule.test(v) && isRes(path) ? kit.nameHint : v !== now && used().includes(v) ? `"${v}" is already used` : '';
81
- why.textContent = bad;
82
- return bad ? undefined : v;
83
- };
84
- input.addEventListener('input', check);
85
- const go = ask(`Rename ${describe(path)}`, [h('label', { class: 'field' }, h('span', null, 'Name'), input), why, isRes(path) ? h('p', { class: 'sub' }, 'Every reference to it is renamed too.') : ''], [{ label: 'Cancel', value: 'cancel' }, { label: 'Rename', value: 'ok', primary: true }]);
86
- setTimeout(() => { input.focus(); input.select(); }, 0);
87
- if (await go !== 'ok') return false;
88
- const v = check();
89
- if (!v || v === now) return false;
90
- return run(doc, isRes(path) ? renameCmd(path, v) : renameKeyCmd(path, v), origin, note);
79
+ let ok = false;
80
+ await renameField({
81
+ label: `Rename ${describe(path)}`, value: now,
82
+ wrong: v => (!v ? 'A name is needed' : v === now ? '' : res && !kit.nameRule.test(v) ? kit.nameHint : used().includes(v) ? `"${v}" is already used` : ''),
83
+ alive: () => !!here && getIn(doc.goodDoc.data, here) !== undefined,
84
+ commit: v => { if (here) ok = run(doc, { ...(res ? renameCmd(here, v) : renameKeyCmd(here, v)), joined: l => l.replace(` ${now}`, ` ${v}`) }, origin, note, at.joins); },
85
+ }, at);
86
+ off();
87
+ return ok;
91
88
  }
92
89
 
93
90
  const duplicate = (doc: EditorModel, path: Path, origin: 'canvas' | 'menu', note?: (t: string, tone?: 'bad') => void) => {
@@ -114,6 +111,6 @@ function connected(doc: EditorModel, paths: Path[]): Path[] {
114
111
  return [...out.values()];
115
112
  }
116
113
 
117
- return { deletePaths, renameDialog, duplicate, connected };
114
+ return { deletePaths, rename, duplicate, connected };
118
115
  }
119
116
  export type Actions = ReturnType<typeof actionsFor>;
@@ -54,6 +54,8 @@ body[data-view="text"] #se-canvas, body[data-view="text"] #se-work-grip { displa
54
54
  /* the stage (canvas.css styles the drawing in it); focused by a click, a quieter ring than the keyboard's */
55
55
  .canvas.has-focus .canvas-stage:not(:focus-visible) { outline: 2px solid color-mix(in srgb, var(--focus) 50%, transparent); outline-offset: -2px; }
56
56
  .canvas-tools { position: absolute; right: var(--sp-3); bottom: var(--sp-3); display: flex; gap: var(--sp-0); padding: var(--sp-0); background: var(--surface); border: var(--bw) solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1, none); }
57
+ /* a canvas too narrow for it: the toolbar wraps onto rows inside it, right-aligned (one row, as ever, when it fits) */
58
+ .canvas-tools { max-width: calc(100% - 2 * var(--sp-3)); flex-wrap: wrap; justify-content: flex-end; }
57
59
  .canvas-tools .segmented { margin-right: var(--sp-1); }
58
60
  .status .hint-mode { color: var(--ink-3); }
59
61
  body[data-view="text"] .status .hint-mode { display: none; }
@@ -93,6 +95,12 @@ body[data-view="text"] .status .hint-mode { display: none; }
93
95
  .chip-add { width: auto !important; min-width: 80px; }
94
96
  .props-delete { margin-top: var(--sp-4); align-self: flex-start; }
95
97
  .mono-input { font-family: var(--mono); }
98
+ .rename-field { position: fixed; z-index: var(--z-menu); }
99
+ .rename-field > .rename-input { display: block; width: auto; max-width: calc(100vw - 16px); height: 26px; min-height: 26px; padding: 0 var(--sp-2); font-family: var(--mono); font-size: var(--fs-mono); text-align: center; box-shadow: var(--shadow-3); }
100
+ .rename-field.over > .rename-input { text-align: left; }
101
+ .rename-field > .rename-input[aria-invalid="true"] { border-color: var(--bad); }
102
+ .rename-field > .rename-error { position: absolute; top: 100%; left: 50%; translate: -50% 4px; width: max-content; max-width: 280px; margin: 0; padding: var(--sp-1) var(--sp-2); background: var(--surface); border: var(--bw) solid var(--bad); border-radius: var(--r-md); color: var(--bad); font-size: var(--fs-sm); line-height: 1.35; box-shadow: var(--shadow-2); }
103
+ .rename-field > .rename-error:empty { display: none; }
96
104
  #se-grip { height: 6px; margin: -3px 0; cursor: row-resize; z-index: 2; position: relative; }
97
105
  #se-grip:hover, #se-grip:focus-visible { background: color-mix(in srgb, var(--accent) 30%, transparent); }
98
106
  #se-problems { height: var(--problems-h, 160px); flex: none; overflow: auto; border-top: var(--bw) solid var(--line); background: var(--bg); font-size: var(--fs-sm); }
@@ -222,7 +230,36 @@ body { position: relative; height: 100%; min-height: 0; font: var(--fw-regular)
222
230
  .pal-item:hover { background: var(--state-hover); color: var(--ink); }
223
231
  .pal-item:active { cursor: grabbing; }
224
232
  .pal-item .icon { width: 14px; height: 14px; }
233
+ .pal-section { display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }
234
+ .pal-head { display: flex; flex-shrink: 0; align-items: center; gap: var(--sp-1); height: var(--ctl-sm); padding: 0 var(--sp-2) 0 var(--sp-1); border: 0; border-radius: var(--r-sm); background: none; color: var(--ink-3); font: inherit; font-size: var(--fs-xs); font-weight: var(--fw-strong); letter-spacing: .02em; cursor: pointer; text-align: left; }
235
+ .pal-head:hover { background: var(--state-hover); color: var(--ink); }
236
+ .pal-head .pal-chev { width: 12px; height: 12px; transition: transform var(--dur-1, 0ms); }
237
+ .pal-head[aria-expanded="true"] .pal-chev { transform: rotate(90deg); }
238
+ .pal-body { display: flex; flex-direction: column; gap: 2px; }
239
+ .pal-body[hidden] { display: none; }
225
240
  body.read-only .palette { display: none; }
241
+ /* 0.12.0: the palette docked, a pane of its own at the canvas's left (search, sections, a grip, collapsible) */
242
+ .canvas.pal-docked { display: flex; --pal-cur: var(--pal-w, 220px); }
243
+ .canvas.pal-docked.pal-collapsed { --pal-cur: 36px; }
244
+ .canvas.pal-docked > .canvas-stage { flex: 1 1 auto; min-width: 0; position: relative; }
245
+ .canvas.pal-docked > .canvas-empty { left: var(--pal-cur, 220px); }
246
+ /* the toolbar stays on the stage, beside the pane */
247
+ .canvas.pal-docked > .canvas-tools { max-width: calc(100% - var(--pal-cur, 220px) - 2 * var(--sp-3)); }
248
+ .pal-dock { flex: 0 0 var(--pal-cur, 220px); width: var(--pal-cur, 220px); min-width: 0; display: flex; flex-direction: column; background: var(--surface); border-right: var(--bw) solid var(--line); overflow: hidden; z-index: 2; }
249
+ .pal-dock-head { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-1); border-bottom: var(--bw) solid var(--line); }
250
+ .pal-search-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-1); height: var(--ctl-sm); padding: 0 var(--sp-2); border: var(--bw) solid var(--line); border-radius: var(--r-sm); background: var(--bg); color: var(--ink-3); }
251
+ .pal-search-wrap:focus-within { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
252
+ .pal-search-wrap .icon { width: 14px; height: 14px; flex: none; }
253
+ .pal-search { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--ink); font: inherit; font-size: var(--fs-sm); }
254
+ .pal-dock .palette.pal-list { position: static; flex: 1 1 auto; max-height: none; min-height: 0; border: 0; border-radius: 0; box-shadow: none; background: none; padding: var(--sp-1); }
255
+ .pal-dock .pal-item[hidden], .pal-dock .pal-section[hidden] { display: none; }
256
+ .pal-none { margin: 0; padding: var(--sp-2) var(--sp-3); color: var(--ink-3); font-size: var(--fs-sm); }
257
+ .pal-none[hidden] { display: none; }
258
+ .canvas.pal-collapsed .pal-search-wrap, .canvas.pal-collapsed .palette.pal-list, .canvas.pal-collapsed .pal-none, .canvas.pal-collapsed .pal-grip { display: none; }
259
+ .canvas.pal-collapsed .pal-dock-head { border-bottom: 0; justify-content: center; }
260
+ .pal-grip { flex: none; width: 6px; margin: 0 -3px; cursor: col-resize; z-index: 3; position: relative; }
261
+ .pal-grip:hover, .pal-grip:focus-visible { background: color-mix(in srgb, var(--accent) 30%, transparent); outline: 0; }
262
+ body.read-only .pal-dock, body.read-only .pal-grip { display: none; }
226
263
  .pal-ghost { position: absolute; z-index: 5; pointer-events: none; display: flex; align-items: center; gap: var(--sp-1); padding: 2px var(--sp-2); border: var(--bw) solid var(--accent); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font-size: var(--fs-sm); box-shadow: var(--shadow-2, none); }
227
264
  .pal-ghost .icon { width: 14px; height: 14px; }
228
265
  .pal-ghost.bad { border-color: var(--bad); color: var(--bad); }
@@ -14,6 +14,7 @@
14
14
  import { h, icon, type IconName } from './icons.ts';
15
15
  import { openMenu, type MenuItem } from './menu.ts';
16
16
  import { run, type Actions } from './actions.ts';
17
+ import { connectionsOf, nearestOn } from '../connections.ts';
17
18
  import { screenToGrid, localAt, boxSilhouette, floorOf, snapMove, overlaps, paddingOf, type Move } from '../../iso-objects/geometry.ts';
18
19
  import { regionKind, type KindCatalog } from '../../iso-objects/kinds.ts';
19
20
  import type { CompiledScene } from '../../iso-objects/compile.ts';
@@ -77,13 +78,25 @@ export interface CanvasUi {
77
78
  /** 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
79
  * the base of its fresh name (default: the kind's singular) */
79
80
  palette: PaletteItem[];
81
+ /** (0.12.0) where the palette is: 'floating' (the default: over the canvas, at its top left) or 'docked' (a pane of
82
+ * its own at the canvas's left, with a search box filtering by label and section, resizable and collapsible; its
83
+ * width and whether it is collapsed are kept in the host's store as `canvas-palette-dock`) */
84
+ paletteLayout?: 'floating' | 'docked';
85
+ /** (0.12.5) what a double click on an object does: shows it in the text (the default), or renames it */
86
+ doubleClick?: 'text' | 'rename';
80
87
  text: {
81
88
  stage: string; dragGroup: string; dragSelectTip: string; unreadable: string; palette: string;
82
89
  /** the end of a pin drag's hint */
83
90
  pinHint: string; renameWhy: string; duplicateWhy: string;
84
91
  };
85
92
  }
86
- export interface PaletteItem { kind: string; icon: IconName; label: string; value?(): unknown; name?: string }
93
+ export interface PaletteItem {
94
+ kind: string; icon: IconName; label: string; value?(): unknown; name?: string;
95
+ /** (0.11.0) the header it is listed under: entries with one are grouped by it, in order of first use, each group under
96
+ * a header that collapses (all collapsed but the one last added from, remembered in the host's store as
97
+ * `canvas-palette`); entries without one are listed as before, where they are */
98
+ section?: string;
99
+ }
87
100
  /** what the canvas is given of the domain (M: the domain's reading of the file; D: its drawing) */
88
101
  export interface CanvasKit<M, D extends CanvasDrawing> {
89
102
  draw(model: M, data: unknown, theme: string): D;
@@ -141,7 +154,7 @@ const SVGNS = 'http://www.w3.org/2000/svg';
141
154
  export function canvasView<M, D extends CanvasDrawing, A extends object = object>(host: HTMLElement, doc: EditorModel, opts: CanvasOpts<M, D, A>) {
142
155
  const K = opts.kit, ui = K.ui, T = ui.text;
143
156
  const { setCmd, deleteCmd, insertCmd, insertItemCmd, pinsCmd, withPinsMoved, freshName, describe } = K.commands;
144
- const { deletePaths, renameDialog, duplicate, connected } = K.actions;
157
+ const { deletePaths, duplicate, connected } = K.actions;
145
158
  const resourceOf = (ptr: string) => K.objectOf(ptr);
146
159
  const kindOf = (k: string) => K.kinds.find(x => x.kind === k)!;
147
160
  const PINS_KEY = K.pins.key;
@@ -227,7 +240,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
227
240
  if (!s3) { showEmpty(T.unreadable); return; }
228
241
  const key = JSON.stringify(data);
229
242
  // nothing new to draw: repaint the marks, unless a drag is showing its grid (it repaints when it ends)
230
- if (key === lastKey && svg) { if (!pinDrag()) paintOverlay(); return; }
243
+ if (key === lastKey && svg) { if (!pinDrag()) paintOverlay(); if (toFit) { toFit = false; fitItems(); } return; }
231
244
  if (mode === '2d' && !flatImpl) {
232
245
  try { await loadFlat(); } catch (e) { mode = '3d'; paintNav(); opts.note(`The 2D view couldn't load: ${(e as Error).message}`, 'warn'); }
233
246
  }
@@ -240,6 +253,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
240
253
  await draw(next);
241
254
  if (cd!.pinNotes.length) opts.note(`Pins: ${cd!.pinNotes.join('; ')}`, 'warn');
242
255
  }
256
+ let toFit = false; // (0.12.5) the next drawing is another document's: fitted
243
257
  let lastS3: M | undefined, lastData: unknown, pendingAfterDrag = false;
244
258
  // ---------- the switch's morph (0.7.5): the 2D view's implementation runs it, over the stage ----------
245
259
  let morphFrom: { svg: SVGSVGElement; mode: '3d' | '2d' } | undefined;
@@ -298,7 +312,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
298
312
  svg = s;
299
313
  const [x, y, w, hh] = full;
300
314
  V.full = { x, y, w, h: hh };
301
- if (!V.view) { V.view = { ...V.full }; autoFit(); } else quietly(applyView);
315
+ if (toFit) { toFit = false; V.view = { ...V.full }; fitItems(); } else if (!V.view) { V.view = { ...V.full }; autoFit(); } else quietly(applyView);
302
316
  empty.hidden = true;
303
317
  layer?.drawn?.();
304
318
  if (pendingReveal && reveal(pendingReveal)) pendingReveal = undefined;
@@ -326,7 +340,17 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
326
340
  const live = layer?.extent?.() ?? [];
327
341
  return union([...ptrs.flatMap(p => elementsFor(p)).filter(e => e.getBBox().width || e.getBBox().height).map(boxOf), ...live]);
328
342
  }
329
- const V = viewport(host, {
343
+ /** (0.12.6) the connectors and their labels (not a step's marks on them, which a still doesn't show): Fit keeps them on the stage */
344
+ function routesBox() {
345
+ if (!cd || !svg) return undefined;
346
+ const els = Object.keys(cd.scene.rendered.paths).flatMap(id => [...svg!.querySelectorAll<SVGGraphicsElement>(`[data-id="${CSS.escape(id)}"], [data-hl="${CSS.escape(id)}"], [data-for="${CSS.escape(id)}"]`)]).filter(e => !e.closest('.pre, .overlay, .g-marks, .g-badges, .g-anim'));
347
+ return union(els.filter(e => e.getBBox().width || e.getBBox().height).map(boxOf));
348
+ }
349
+ // (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
350
+ // drawn (the scale, the pointer's place, a resize); floating, the stage is the host's whole area
351
+ const docked = ui.paletteLayout === 'docked';
352
+ const viewEl = docked ? stage : host;
353
+ const V = viewport(viewEl, {
330
354
  svg: () => svg,
331
355
  onApply: k => {
332
356
  svg!.classList.toggle('zoom-near', k >= 1); // a layer's detail shows from 100% up
@@ -336,6 +360,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
336
360
  },
337
361
  onRezoom: () => paintOverlay(),
338
362
  itemsBox: () => itemsBox(),
363
+ alsoBox: () => routesBox(),
339
364
  marksShowing: () => !!layer?.showing?.(),
340
365
  });
341
366
  const { size, scale, quietly, applyView, toSvg, zoomAt, fit, fitItems, autoFit, actual, settled } = V;
@@ -385,6 +410,37 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
385
410
  return undefined;
386
411
  };
387
412
 
413
+ // (0.12.4) connections: the routes that are entries of the file's own (src/iso-editor/connections.ts)
414
+ const isRouteId = (id: string) => !!cd && Object.hasOwn(cd.scene.rendered.paths, id);
415
+ const connections = () => (cd ? connectionsOf(cd.pathOf, isRouteId, K.objectOf) : new Map<string, string>());
416
+ /** how near a connection, in the page's pixels, is on it */
417
+ const NEAR = 6;
418
+ /** the drawn thing under a place on the page: a connection within NEAR of it, unless a node is there (a node's always the
419
+ * one meant; a region's floor, or nothing, gives way) or a node hides that part of the connection */
420
+ const pathAt = (target: EventTarget | null, px: number, py: number): string | undefined => {
421
+ const direct = pathAtEvent(target);
422
+ const isNode = (el: Element | null): boolean => {
423
+ const id = el?.closest?.('[data-id]')?.getAttribute('data-id');
424
+ if (!id || !cd || isRouteId(id)) return false;
425
+ if (flat) { const q = toSvg(px, py); return !flat.panelsAt(q.x, q.y).includes(id) && cd.scene.layout.byId.has(id); }
426
+ return cd.scene.layout.byId.get(id)?.type === 'node';
427
+ };
428
+ const el = target as Element | null;
429
+ if (!cd || !svg || !el?.closest || (el !== svg && !svg.contains(el) && el !== stage) || isNode(el)) return direct;
430
+ const conns = connections();
431
+ if (!conns.size || (direct !== undefined && conns.has(direct))) return direct;
432
+ const at = toSvg(px, py), k = scale(), r = viewEl.getBoundingClientRect();
433
+ let best: { ptr: string; dist: number } | undefined;
434
+ for (const ptr of conns.keys()) for (const sh of outlinesFor(ptr)) {
435
+ if (sh.kind !== 'route') continue;
436
+ const q = nearestOn(sh.d, at.x, at.y);
437
+ if (!q || q.dist * k > NEAR || (best && q.dist >= best.dist)) continue;
438
+ if (isNode(fdoc().elementFromPoint(r.left + (q.x - V.view!.x) * k, r.top + (q.y - V.view!.y) * k))) continue;
439
+ best = { ptr, dist: q.dist };
440
+ }
441
+ return best ? best.ptr : direct;
442
+ };
443
+
388
444
  // ---------- the overlay: selection rings, hover, problem badges ----------
389
445
  /**
390
446
  * A resource's drawn shapes, isometric: a node (or a slab, a VM, a platform) is the silhouette of its box (the hexagon
@@ -524,7 +580,13 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
524
580
  stage.addEventListener('pointercancel', up);
525
581
  stage.addEventListener('wheel', wheel, { passive: false });
526
582
  stage.addEventListener('contextmenu', context);
527
- stage.addEventListener('dblclick', e => { const p = pathAtEvent(e.target); if (p !== undefined) opts.showInText(fromPointer(p)); });
583
+ stage.addEventListener('dblclick', e => {
584
+ // (0.12.5) what is under the pointer: the presses were captured, so a real double click's target is the stage
585
+ const p = pathAt(e.target === stage ? fdoc().elementFromPoint(e.clientX, e.clientY) : e.target, e.clientX, e.clientY);
586
+ if (p === undefined) return;
587
+ if (ui.doubleClick === 'rename' && doc.doc.ok && resourceOf(p)?.path === p) rename(fromPointer(p));
588
+ else opts.showInText(fromPointer(p));
589
+ });
528
590
  };
529
591
  // in the page, a pointer's coordinates are already the page's
530
592
  const pageXY = (e: PointerEvent | MouseEvent) => ({ x: e.clientX, y: e.clientY });
@@ -545,7 +607,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
545
607
  const pan = () => { drag = { kind: 'pan', x0: x, y0: y, v0: { ...V.view! } }; svg?.classList.add('panning'); e.preventDefault(); };
546
608
  if (e.button === 1 || spaceKeyDown) { pan(); return; }
547
609
  if (e.button !== 0) return;
548
- const ptr = pathAtEvent(e.target);
610
+ const ptr = pathAt(e.target, x, y);
549
611
  if (ptr === undefined) {
550
612
  // nothing under the pointer: Pan mode pans (⇧ or ⌘ draws a selection instead); Select mode draws a selection (the space key pans)
551
613
  const mod = e.shiftKey || e.metaKey || e.ctrlKey;
@@ -592,7 +654,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
592
654
  return;
593
655
  }
594
656
  if (!drag) {
595
- const p = pathAtEvent(e.target);
657
+ const p = pathAt(e.target, x, y);
596
658
  if (p !== hoverId) { hoverId = p; paintOverlay(); }
597
659
  return;
598
660
  }
@@ -773,7 +835,14 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
773
835
  }
774
836
  }
775
837
  /** end a pin drag: the drop commits one command; an overlap, a cancel or no move puts the drawing back */
838
+ /** drops whose pin isn't written yet (the grid fading out first) */
839
+ let dropping = 0;
776
840
  async function endPin(commit: boolean) {
841
+ if (!pinDrag()) return;
842
+ dropping++;
843
+ try { await endDrop(commit); } finally { dropping--; }
844
+ }
845
+ async function endDrop(commit: boolean) {
777
846
  const g = pinDrag();
778
847
  if (!g) return;
779
848
  drag = undefined;
@@ -862,7 +931,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
862
931
  e.preventDefault();
863
932
  const { x, y } = pageXY(e);
864
933
  if (layer?.context?.(e, { x, y })) return;
865
- const ptr = pathAtEvent(e.target);
934
+ const ptr = pathAt(e.target, x, y);
866
935
  if (ptr !== undefined && !doc.selection.some(p => toPointer(p) === ptr)) doc.select([fromPointer(ptr)], 'canvas');
867
936
  openMenu(menuItems(ptr), { x, y }, 'Canvas');
868
937
  }
@@ -883,7 +952,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
883
952
  if (one) {
884
953
  items.push(...K.objectItems(doc, one, 'canvas', opts.note));
885
954
  if (items.length) items.push({ sep: true });
886
- items.push({ label: 'Rename…', icon: 'pencil', keys: 'F2', disabled: ro || !isRes, why: T.renameWhy, onSelect: () => renameDialog(doc, one, 'canvas', opts.note) });
955
+ items.push({ label: 'Rename…', icon: 'pencil', keys: 'F2', disabled: ro || !isRes, why: T.renameWhy, onSelect: () => rename(one) });
887
956
  items.push({ label: 'Duplicate', icon: 'copy', keys: '⌘D', disabled: ro || !isRes, why: T.duplicateWhy, onSelect: () => duplicate(doc, one, 'canvas', opts.note) });
888
957
  const name = isRes ? resourceOf(toPointer(one))!.name : '';
889
958
  const pinned = !!K.pins.of(doc.goodDoc.data)?.[name];
@@ -968,7 +1037,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
968
1037
  const p = [...k.section, name];
969
1038
  if (run(doc, insertCmd(p.slice(0, -1), name, k.template(), { label: `Add ${k.singular} ${name}` }), 'canvas', opts.note)) {
970
1039
  doc.select([p], 'canvas');
971
- renameDialog(doc, p, 'canvas', opts.note);
1040
+ rename(p, { joins: doc.undoId });
972
1041
  }
973
1042
  }
974
1043
  // ---------- E11: the palette: add a resource by a click, or by a drag onto the canvas ----------
@@ -1071,12 +1140,117 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1071
1140
  if (!run(doc, { ...cmd, select: [p] }, 'canvas', opts.note)) return undefined;
1072
1141
  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`);
1073
1142
  doc.select([p], 'canvas');
1074
- // (0.10.1) the canvas has the focus while the name is asked, so the dialog gives it back there (⌘Z works at once)
1075
- stage.focus({ preventScroll: true });
1076
- renameDialog(doc, p, 'canvas', opts.note);
1143
+ // (0.12.5) its name, in the inline field above it; the drop and the name are one undo step
1144
+ rename(p, { joins: doc.undoId, at });
1077
1145
  return p;
1078
1146
  }
1079
1147
  const palette = h('div', { class: 'palette', role: 'toolbar', 'aria-label': T.palette, 'aria-orientation': 'vertical' });
1148
+ // (0.11.0) sections: a header (a button, aria-expanded) over its entries; open: the section last added from (the
1149
+ // first, before any); the reader opens and closes the others as they like. The host's store may be off: guarded.
1150
+ const sections = new Map<string, { head: HTMLButtonElement; body: HTMLElement }>();
1151
+ const PAL_KEY = 'canvas-palette';
1152
+ let lastSection: string | undefined;
1153
+ try { const v = JSON.parse(opts.store?.get(PAL_KEY) ?? '{}') as { last?: unknown }; if (typeof v.last === 'string') lastSection = v.last; } catch { /* none */ }
1154
+ const named = [...new Set(ui.palette.map(i => i.section).filter((x): x is string => x !== undefined))];
1155
+ const openAtStart = lastSection !== undefined && named.includes(lastSection) ? lastSection : named[0];
1156
+ 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; };
1157
+ function sectionBody(sec: string): HTMLElement {
1158
+ const have = sections.get(sec);
1159
+ if (have) return have.body;
1160
+ const id = `pal-sec-${sections.size}-${Math.random().toString(36).slice(2, 8)}`;
1161
+ 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;
1162
+ const body = h('div', { class: 'pal-body', id, role: 'group', 'aria-label': sec, 'data-section-body': sec });
1163
+ head.addEventListener('click', () => setOpen(sec, head.getAttribute('aria-expanded') !== 'true'));
1164
+ palette.append(h('div', { class: 'pal-section', 'data-pal-section': sec }, head, body));
1165
+ sections.set(sec, { head, body });
1166
+ setOpen(sec, sec === openAtStart);
1167
+ return body;
1168
+ }
1169
+ // (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
1170
+ // control that collapses it to a strip, and a grip that resizes it; its width and state in the host's store
1171
+ const DOCK_KEY = 'canvas-palette-dock';
1172
+ const dockPref: { w?: number; collapsed?: boolean } = {};
1173
+ 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 */ }
1174
+ const saveDock = () => { try { opts.store?.set(DOCK_KEY, JSON.stringify(dockPref)); } catch { /* storage may be off */ } };
1175
+ const DOCK_MIN = 160, DOCK_MAX = 440;
1176
+ const palHome: HTMLElement = docked ? h('aside', { class: 'pal-dock', 'aria-label': 'Palette' }) : palette;
1177
+ const palGrip = h('div', { class: 'pal-grip', role: 'separator', 'aria-orientation': 'vertical', 'aria-label': 'Resize the palette', tabindex: '0' });
1178
+ const search = h('input', { type: 'search', class: 'pal-search', placeholder: 'Search', 'aria-label': 'Search the palette', autocomplete: 'off', spellcheck: 'false' }) as HTMLInputElement;
1179
+ const none = h('p', { class: 'pal-none', role: 'status', hidden: '' });
1180
+ 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;
1181
+ const visibleItems = () => [...palette.querySelectorAll<HTMLButtonElement>('.pal-item')].filter(b => !b.hidden && !b.closest('[hidden]'));
1182
+ /** the search: every word in the entry's label or its section; sections with a match open while it is on, and the
1183
+ * reader's own open and closed come back when it is cleared */
1184
+ let before: Map<string, boolean> | undefined;
1185
+ function filter() {
1186
+ const words = search.value.toLowerCase().split(/\s+/).filter(Boolean);
1187
+ if (words.length && !before) before = new Map([...sections].map(([k, g]) => [k, g.head.getAttribute('aria-expanded') === 'true']));
1188
+ let shown = 0;
1189
+ for (const b of palette.querySelectorAll<HTMLButtonElement>('.pal-item')) {
1190
+ const item = ui.palette[Number(b.dataset.entry)];
1191
+ const hay = `${item.label} ${item.section ?? ''}`.toLowerCase();
1192
+ b.hidden = !words.every(w => hay.includes(w));
1193
+ if (!b.hidden) shown++;
1194
+ }
1195
+ for (const [sec, g] of sections) {
1196
+ const any = [...g.body.querySelectorAll<HTMLButtonElement>('.pal-item')].some(b => !b.hidden);
1197
+ (g.head.parentElement as HTMLElement).hidden = words.length > 0 && !any;
1198
+ if (words.length) setOpen(sec, any);
1199
+ }
1200
+ if (!words.length && before) { for (const [sec, open] of before) setOpen(sec, open); before = undefined; }
1201
+ none.hidden = shown > 0;
1202
+ none.textContent = shown ? '' : `Nothing matches "${search.value.trim()}"`;
1203
+ }
1204
+ 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(); } };
1205
+ const setCollapsed = (c: boolean, keep = true) => {
1206
+ host.classList.toggle('pal-collapsed', c);
1207
+ collapseBtn.setAttribute('aria-expanded', String(!c));
1208
+ const say = c ? 'Show the palette' : 'Collapse the palette';
1209
+ collapseBtn.setAttribute('aria-label', say); collapseBtn.title = say;
1210
+ collapseBtn.replaceChildren(icon(c ? 'chevron-right' : 'chevron-left'));
1211
+ if (keep) { if (c) dockPref.collapsed = true; else delete dockPref.collapsed; saveDock(); }
1212
+ };
1213
+ if (docked) {
1214
+ host.classList.add('pal-docked');
1215
+ palette.classList.add('pal-list');
1216
+ palHome.append(h('div', { class: 'pal-dock-head' }, collapseBtn, h('label', { class: 'pal-search-wrap' }, icon('search'), search)), palette, none);
1217
+ palGrip.setAttribute('aria-valuemin', String(DOCK_MIN)); palGrip.setAttribute('aria-valuemax', String(DOCK_MAX));
1218
+ setDockW(dockPref.w ?? 220, false);
1219
+ setCollapsed(!!dockPref.collapsed, false);
1220
+ collapseBtn.addEventListener('click', () => { setCollapsed(!host.classList.contains('pal-collapsed')); if (!host.classList.contains('pal-collapsed')) search.focus(); });
1221
+ search.addEventListener('input', filter);
1222
+ search.addEventListener('keydown', e => {
1223
+ if (e.key === 'Escape' && search.value) { e.preventDefault(); e.stopPropagation(); search.value = ''; filter(); }
1224
+ else if (e.key === 'ArrowDown') { const first = visibleItems()[0]; if (first) { e.preventDefault(); first.focus(); } }
1225
+ else if (e.key === 'Enter') { const first = visibleItems()[0]; if (first) { e.preventDefault(); first.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })); } }
1226
+ });
1227
+ // the list's arrow keys: up and down through what is shown (up from the first: back to the search)
1228
+ palette.addEventListener('keydown', e => {
1229
+ if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
1230
+ 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]')));
1231
+ const i = all.indexOf(document.activeElement as HTMLButtonElement);
1232
+ if (i < 0) return;
1233
+ e.preventDefault();
1234
+ 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();
1235
+ });
1236
+ palGrip.addEventListener('pointerdown', e => {
1237
+ if (e.button !== 0) return;
1238
+ try { palGrip.setPointerCapture(e.pointerId); } catch { /* synthetic */ }
1239
+ const x0 = e.clientX, w0 = palHome.getBoundingClientRect().width;
1240
+ const mv = (ev: PointerEvent) => setDockW(w0 + ev.clientX - x0, false);
1241
+ const up = (ev: PointerEvent) => { palGrip.removeEventListener('pointermove', mv); palGrip.removeEventListener('pointerup', up); setDockW(w0 + ev.clientX - x0); };
1242
+ palGrip.addEventListener('pointermove', mv); palGrip.addEventListener('pointerup', up);
1243
+ });
1244
+ palGrip.addEventListener('keydown', e => {
1245
+ const d = e.key === 'ArrowLeft' ? -16 : e.key === 'ArrowRight' ? 16 : 0;
1246
+ if (d) { e.preventDefault(); setDockW(palHome.getBoundingClientRect().width + d); }
1247
+ });
1248
+ }
1249
+ const usedSection = (item: PaletteItem) => {
1250
+ if (item.section === undefined || item.section === lastSection) return;
1251
+ lastSection = item.section;
1252
+ try { opts.store?.set(PAL_KEY, JSON.stringify({ last: lastSection })); } catch { /* storage may be off */ }
1253
+ };
1080
1254
  ui.palette.forEach((item, idx) => {
1081
1255
  const { kind: sec, icon: ic, label } = item;
1082
1256
  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));
@@ -1086,7 +1260,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1086
1260
  try { b.setPointerCapture(e.pointerId); } catch { /* a synthetic pointer: the events come to the button anyway */ }
1087
1261
  const x0 = e.clientX, y0 = e.clientY;
1088
1262
  let ghost: HTMLElement | undefined;
1089
- 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 && !palette.contains(document.elementFromPoint(ev.clientX, ev.clientY)); };
1263
+ 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)); };
1090
1264
  const mv = (ev: PointerEvent) => {
1091
1265
  if (!ghost && Math.hypot(ev.clientX - x0, ev.clientY - y0) < 4) return;
1092
1266
  if (!ghost) { ghost = h('div', { class: 'pal-ghost', 'aria-hidden': 'true' }, icon(ic), label); host.append(ghost); }
@@ -1099,18 +1273,18 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1099
1273
  const dragged = !!ghost;
1100
1274
  ghost?.remove();
1101
1275
  if (!drop) return;
1102
- if (!dragged) addFromPalette(sec, undefined, item);
1103
- else if (over(ev)) addFromPalette(sec, { x: ev.clientX, y: ev.clientY }, item);
1276
+ if (!dragged) { usedSection(item); addFromPalette(sec, undefined, item); }
1277
+ else if (over(ev)) { usedSection(item); addFromPalette(sec, { x: ev.clientX, y: ev.clientY }, item); }
1104
1278
  };
1105
1279
  const upH = (ev: PointerEvent) => done(ev, true), cancelH = (ev: PointerEvent) => done(ev, false);
1106
1280
  const esc = (ev: KeyboardEvent) => { if (ev.key === 'Escape') { ev.stopPropagation(); ev.preventDefault(); done(e, false); } };
1107
1281
  b.addEventListener('pointermove', mv); b.addEventListener('pointerup', upH); b.addEventListener('pointercancel', cancelH); addEventListener('keydown', esc, true);
1108
1282
  });
1109
1283
  // the keyboard: Enter or the space key adds (the layout places it)
1110
- b.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); addFromPalette(sec, undefined, item); } });
1111
- palette.append(b);
1284
+ b.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); usedSection(item); addFromPalette(sec, undefined, item); } });
1285
+ (item.section === undefined ? palette : sectionBody(item.section)).append(b);
1112
1286
  });
1113
- host.append(palette);
1287
+ if (docked) host.prepend(palHome, palGrip); else host.append(palette);
1114
1288
 
1115
1289
  function resetLayout() {
1116
1290
  // wherever the pins are (x-editor, or the legacy key): removed, and their key too if it holds nothing else
@@ -1119,6 +1293,20 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1119
1293
  const only = x && Object.keys(x).length === 1;
1120
1294
  run(doc, { ...deleteCmd(only ? [key] : [key, 'layout']), label: 'Reset the layout' }, 'canvas', opts.note);
1121
1295
  }
1296
+ /** (0.12.5) name it, in the inline field above its drawing; Enter and Esc give the canvas the focus back (⌘Z works at once) */
1297
+ function rename(p: Path, o: { joins?: number; at?: { x: number; y: number } } = {}) {
1298
+ let path: Path | null = p;
1299
+ const off = doc.on(c => { if (path && c.remap) path = c.remap(path); });
1300
+ void K.actions.rename(doc, p, 'canvas', opts.note, {
1301
+ ...o, back: stage, late: stage, busy: () => !!drag || dropping > 0, bounds: () => stage.getBoundingClientRect(),
1302
+ place: () => {
1303
+ const b = path && V.view ? boxFor(path) : undefined;
1304
+ if (!b) return undefined;
1305
+ const r = viewEl.getBoundingClientRect(), k = scale();
1306
+ return { left: r.left + (b.x - V.view!.x) * k, top: r.top + (b.y - V.view!.y) * k, width: b.w * k, height: b.h * k };
1307
+ },
1308
+ }).finally(off);
1309
+ }
1122
1310
  function selectParent() {
1123
1311
  const up = new Map<string, Path>();
1124
1312
  for (const p of doc.selection) {
@@ -1149,10 +1337,11 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1149
1337
  case '@': case '2': if (e.shiftKey || e.key === '@') zoomToSelection(); else return; break;
1150
1338
  case 'Escape': if (linking) { linking = undefined; paintOverlay(); opts.note('Not connected'); break; } if (pinDrag()) { endPin(false); break; } doc.select([], 'canvas'); break;
1151
1339
  case 'Delete': case 'Backspace': if (sel.length && !ro) deletePaths(doc, sel, 'canvas', opts.note); break;
1152
- case 'F2': if (sel.length === 1 && !ro) renameDialog(doc, sel[0], 'canvas', opts.note); break;
1340
+ case 'F2': if (sel.length === 1 && !ro) rename(sel[0]); break;
1153
1341
  case 'ArrowUp': if (mod) { selectParent(); break; } return;
1154
1342
  case 'Tab': case 'ArrowRight': case 'ArrowLeft': case 'ArrowDown': {
1155
- // move through what is drawn, in the file's order
1343
+ // move through what is drawn, in the file's order: the objects, then (0.12.4) the connections
1344
+ drawn.push(...connections().keys());
1156
1345
  if (!drawn.length) return;
1157
1346
  const i = sel.length ? drawn.indexOf(toPointer(sel[0])) : -1;
1158
1347
  const back = e.key === 'ArrowLeft' || (e.key === 'Tab' && e.shiftKey);
@@ -1163,7 +1352,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1163
1352
  }
1164
1353
  case 'ContextMenu': case 'F10':
1165
1354
  if (e.key === 'F10' && !e.shiftKey) return;
1166
- { const b = unionBox(sel); const r = host.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'); }
1355
+ { 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'); }
1167
1356
  break;
1168
1357
  default:
1169
1358
  if (mod && e.key.toLowerCase() === 'd' && sel.length === 1 && !ro) { duplicate(doc, sel[0], 'canvas', opts.note); break; }
@@ -1210,7 +1399,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1210
1399
 
1211
1400
  const base = {
1212
1401
  addFromPalette, palette, groupSelection, startPick, objectsUnder, get linking() { return linking; },
1213
- render, setTheme, paintOverlay, fit: fitItems, fitAll: fit, actual, zoomAt, itemsBox, get moved() { return V.moved; }, settled, get zoom() { return V.zoom; },
1402
+ render, setTheme, paintOverlay, fit: fitItems, fitNext() { toFit = true; }, fitAll: fit, actual, zoomAt, itemsBox, routesBox, get moved() { return V.moved; }, settled, get zoom() { return V.zoom; },
1214
1403
  dispose() { endMorph(); clearTimeout(relayout); V.dispose(); disposed = true; },
1215
1404
  focus: () => stage.focus(),
1216
1405
  /** for the tests */
@@ -1219,7 +1408,7 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
1219
1408
  /** the view (3D or 2D), and the 2D layout while it shows */
1220
1409
  get mode() { return mode; }, setMode, get flat() { return flat?.layout; },
1221
1410
  stage, key, scale: () => scale(), nav, paintNav, outlinesFor, footprints, get drag() { return pinDrag(); }, get lastMarquee() { return lastMarquee; },
1222
- boxFor, pageXYOf: (p: Path) => { const b = boxFor(p); const r = host.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; },
1411
+ 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; },
1223
1412
  };
1224
1413
  // the layer's calls, as they are (its getters stay getters)
1225
1414
  if (layer) Object.defineProperties(base, Object.getOwnPropertyDescriptors(layer.api));