@johnoscott/isometric-engine 0.12.3 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EDITOR-GUIDE.md +10 -2
- package/README.md +1 -1
- package/assets/app.css +12 -0
- package/assets/marks.css +2 -0
- package/iso-editor.js +189 -188
- package/iso-render.js +82 -82
- package/iso-systems.js +79 -79
- package/js/iso-editor/commands.js +7 -0
- package/js/iso-editor/connections.js +24 -0
- package/js/iso-editor/make-way.js +62 -0
- package/js/iso-editor/model.js +17 -3
- package/js/iso-editor/ui/actions.js +22 -24
- package/js/iso-editor/ui/canvas.js +564 -223
- package/js/iso-editor/ui/mount.js +2 -1
- package/js/iso-editor/ui/palette-look.js +53 -0
- package/js/iso-editor/ui/props.js +2 -2
- package/js/iso-editor/ui/rename.js +114 -0
- package/js/iso-editor/ui/setup.js +4 -0
- package/js/iso-viewer/viewport.js +17 -5
- package/package.json +1 -1
- package/src/iso-editor/commands.ts +9 -0
- package/src/iso-editor/connections.ts +28 -0
- package/src/iso-editor/make-way.ts +89 -0
- package/src/iso-editor/model.ts +17 -3
- package/src/iso-editor/ui/actions.ts +20 -23
- package/src/iso-editor/ui/app.css +10 -0
- package/src/iso-editor/ui/canvas.ts +469 -180
- package/src/iso-editor/ui/marks.css +2 -0
- package/src/iso-editor/ui/mount.ts +4 -3
- package/src/iso-editor/ui/palette-look.ts +51 -0
- package/src/iso-editor/ui/props.ts +3 -3
- package/src/iso-editor/ui/rename.ts +105 -0
- package/src/iso-editor/ui/setup.ts +11 -0
- package/src/iso-viewer/viewport.ts +25 -5
- package/types/iso-editor/connections.d.ts +8 -0
- package/types/iso-editor/make-way.d.ts +40 -0
- package/types/iso-editor/model.d.ts +8 -2
- package/types/iso-editor/ui/actions.d.ts +5 -2
- package/types/iso-editor/ui/canvas.d.ts +42 -12
- package/types/iso-editor/ui/mount.d.ts +6 -2
- package/types/iso-editor/ui/palette-look.d.ts +5 -0
- package/types/iso-editor/ui/props.d.ts +1 -1
- package/types/iso-editor/ui/rename.d.ts +43 -0
- package/types/iso-editor/ui/setup.d.ts +7 -0
- package/types/iso-viewer/viewport.d.ts +13 -1
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
@layer views {
|
|
8
8
|
.iso-canvas { --iso-sel: var(--accent); --iso-sel-fill: color-mix(in srgb, var(--iso-sel) 12%, transparent);
|
|
9
9
|
--iso-sel-faint: color-mix(in srgb, var(--iso-sel) 6%, transparent); --iso-bad: var(--bad); --iso-warn: var(--warn); }
|
|
10
|
+
/* a drag moves things, it doesn't select the drawing's words */
|
|
11
|
+
.iso-canvas svg.scene { user-select: none; -webkit-user-select: none; }
|
|
10
12
|
.iso-canvas svg.scene [data-id] { cursor: pointer; }
|
|
11
13
|
.iso-canvas svg.scene.mode-pan { cursor: grab; }
|
|
12
14
|
.iso-canvas svg.scene.mode-select { cursor: crosshair; }
|
|
@@ -69,7 +69,7 @@ export interface ShellFeatures {
|
|
|
69
69
|
plan?: { planPanel(el: HTMLElement, o: { has(name: string): boolean; select(name: string): boolean }): { paint(extra: unknown, has: boolean): void } };
|
|
70
70
|
}
|
|
71
71
|
/** what the shell calls on a canvas */
|
|
72
|
-
export interface ShellCanvas { render(model: unknown, data: unknown): Promise<void>; setTheme(t: 'light' | 'dark'): void; fit(): void; focus(): void; dispose(): void }
|
|
72
|
+
export interface ShellCanvas { render(model: unknown, data: unknown): Promise<void>; setTheme(t: 'light' | 'dark'): void; fit(): void; /** (0.12.5) the next drawing is fitted, whatever the person did with the view before */ fitNext?(): void; focus(): void; dispose(): void }
|
|
73
73
|
/** what the domain gives the mounted editor */
|
|
74
74
|
export interface EditorSetup<R, X, A extends object> {
|
|
75
75
|
kit: MountKit<R, X>;
|
|
@@ -184,7 +184,8 @@ export interface EditorState<R = unknown, X = unknown> {
|
|
|
184
184
|
checks: number;
|
|
185
185
|
}
|
|
186
186
|
export interface Editor {
|
|
187
|
-
|
|
187
|
+
/** `fit` (0.12.5): it is another document, so its drawing is fitted once drawn (default: the view stays where it is) */
|
|
188
|
+
getText(): string; setText(text: string, o?: { fit?: boolean }): void; setReadOnly(ro: boolean): void; setTheme(t: Theme): void;
|
|
188
189
|
addFeatures(names: readonly string[]): Promise<void>; fit(): void; dispose(): void;
|
|
189
190
|
}
|
|
190
191
|
|
|
@@ -651,7 +652,7 @@ export function mountEditor<R, X, A extends object = object>(el: HTMLElement, op
|
|
|
651
652
|
return {
|
|
652
653
|
internal,
|
|
653
654
|
getText: () => doc.text,
|
|
654
|
-
setText(text: string) { hideBanner(); doc.load(text); doc.markClean(); paintTitle(); paintHistory(); },
|
|
655
|
+
setText(text: string, o: { fit?: boolean } = {}) { hideBanner(); if (o.fit && !disposed) canvas.fitNext?.(); doc.load(text); doc.markClean(); paintTitle(); paintHistory(); },
|
|
655
656
|
setReadOnly,
|
|
656
657
|
setTheme,
|
|
657
658
|
addFeatures,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The palette's entries as what they make (0.14.0): each thing drawn alone, small, in the drawing's own style. The canvas takes it as
|
|
2
|
+
// its kit's `looks`; a host that doesn't ask for it bundles none of it.
|
|
3
|
+
|
|
4
|
+
import { buildSvg } from '../../iso-core/svg-dom.ts';
|
|
5
|
+
import { boxSilhouette } from '../../iso-objects/geometry.ts';
|
|
6
|
+
import { applyStep } from '../splice.ts';
|
|
7
|
+
import type { Path } from '../path.ts';
|
|
8
|
+
import { h } from './icons.ts';
|
|
9
|
+
import type { CanvasDrawing, CanvasKit, CanvasUi, PaletteItem } from './canvas.ts';
|
|
10
|
+
|
|
11
|
+
type Kit<M, D extends CanvasDrawing> = Pick<CanvasKit<M, D>, 'kinds' | 'commands' | 'trial'>;
|
|
12
|
+
/** The kit's `looks`: the entries that show, one at a time, each once; an entry that can't be drawn alone keeps its icon. */
|
|
13
|
+
export const paletteLooks = <M, D extends CanvasDrawing>(K: Kit<M, D>): NonNullable<CanvasKit<M, D>['looks']> => (palette, data, ui: CanvasUi, theme) => {
|
|
14
|
+
palette.classList.add('looks');
|
|
15
|
+
let soon = 0;
|
|
16
|
+
return function draw() {
|
|
17
|
+
if (soon) return;
|
|
18
|
+
soon = window.setTimeout(() => {
|
|
19
|
+
soon = 0;
|
|
20
|
+
const b = [...palette.querySelectorAll<HTMLButtonElement>('.pal-item:not([data-look])')].find(q => !q.hidden && !q.closest('[hidden]')), d = data();
|
|
21
|
+
if (!b || !d) return;
|
|
22
|
+
const s = lookOf(K, ui.palette[Number(b.dataset.entry)], d, theme);
|
|
23
|
+
b.dataset.look = s ? 'object' : 'icon';
|
|
24
|
+
if (s) b.querySelector('.icon')?.replaceWith(h('span', { class: `${ui.rootClass} pal-look` }, s as unknown as HTMLElement));
|
|
25
|
+
draw();
|
|
26
|
+
}, 0);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** the thing an entry makes: the file with nothing in it but its plain values, and one of it; its own elements, without labels,
|
|
30
|
+
* framed by its outline. Undefined where that can't be drawn. */
|
|
31
|
+
function lookOf<M, D extends CanvasDrawing>(K: Kit<M, D>, item: PaletteItem, data: unknown, theme: string): SVGSVGElement | undefined {
|
|
32
|
+
const k = K.kinds.find(x => x.kind === item.kind);
|
|
33
|
+
if (!k) return undefined;
|
|
34
|
+
const name = K.commands.freshName('', item.name ?? k.singular), path = [...k.section, name] as Path;
|
|
35
|
+
const bare = Object.entries((data ?? {}) as Record<string, unknown>).filter(([, v]) => v === null || typeof v !== 'object').map(([n, v]) => `${JSON.stringify(n)}: ${JSON.stringify(v)}\n`).join('');
|
|
36
|
+
let d: D | undefined;
|
|
37
|
+
try { d = K.trial(K.commands.insertCmd(path.slice(0, -1), name, (item.value?.() ?? k.template()) as Record<string, unknown>).build(bare).steps.reduce((t, st) => applyStep(t, st), bare), theme); } catch { /* it needs more around it */ }
|
|
38
|
+
const id = d?.pinId.get(name), it = id ? d!.scene.layout.byId.get(id) : undefined;
|
|
39
|
+
if (!d || d.diags.length || !id || !it) return undefined;
|
|
40
|
+
const s = buildSvg(d.svg), all = [...s.querySelectorAll<SVGElement>('[data-id]')];
|
|
41
|
+
if (!all.some(e => e.getAttribute('data-id') === id)) return undefined;
|
|
42
|
+
for (const e of all) if (e.getAttribute('data-id') !== id) e.remove();
|
|
43
|
+
for (const e of s.querySelectorAll('text, title, desc, .g-labels, .g-floor')) e.remove();
|
|
44
|
+
const pts = boxSilhouette(it.box), xs = pts.map(q => q[0]), ys = pts.map(q => q[1]), m = 3;
|
|
45
|
+
s.setAttribute('viewBox', [Math.min(...xs) - m, Math.min(...ys) - m, Math.max(...xs) - Math.min(...xs) + 2 * m, Math.max(...ys) - Math.min(...ys) + 2 * m].map(v => v.toFixed(1)).join(' '));
|
|
46
|
+
for (const a of ['width', 'height', 'role', 'tabindex', 'aria-label']) s.removeAttribute(a);
|
|
47
|
+
for (const e of s.querySelectorAll('[tabindex]')) { e.removeAttribute('tabindex'); e.removeAttribute('role'); }
|
|
48
|
+
s.setAttribute('preserveAspectRatio', 'xMidYMid meet'); s.setAttribute('aria-hidden', 'true'); s.setAttribute('focusable', 'false');
|
|
49
|
+
s.classList.add('pal-scene');
|
|
50
|
+
return s;
|
|
51
|
+
}
|
|
@@ -38,7 +38,7 @@ export interface PropsUi {
|
|
|
38
38
|
/** what the panel is given of the domain */
|
|
39
39
|
export interface PropsKit {
|
|
40
40
|
commands: Pick<Commands, 'setCmd' | 'deleteCmd' | 'insertItemCmd' | 'referencesTo' | 'describe'>;
|
|
41
|
-
actions: Pick<Actions, 'deletePaths' | '
|
|
41
|
+
actions: Pick<Actions, 'deletePaths' | 'rename'>;
|
|
42
42
|
slotAt(ptr: string): RefSlot | undefined;
|
|
43
43
|
objectOf(ptr: string): ObjectRef | undefined;
|
|
44
44
|
kinds: ObjectKindInfo[];
|
|
@@ -67,7 +67,7 @@ export function propsPanel(body: HTMLElement, doc: EditorModel, opts: PropsOpts)
|
|
|
67
67
|
let focusInput = false;
|
|
68
68
|
const K = opts.kit, ui = K.ui;
|
|
69
69
|
const { setCmd, deleteCmd, insertItemCmd, referencesTo, describe } = K.commands;
|
|
70
|
-
const { deletePaths,
|
|
70
|
+
const { deletePaths, rename } = K.actions;
|
|
71
71
|
const kindOf = (k: string) => K.kinds.find(x => x.kind === k);
|
|
72
72
|
const singular = (k: string) => kindOf(k)?.singular ?? 'item';
|
|
73
73
|
|
|
@@ -101,7 +101,7 @@ export function propsPanel(body: HTMLElement, doc: EditorModel, opts: PropsOpts)
|
|
|
101
101
|
if (!r) { settings(p); return; }
|
|
102
102
|
const head = h('div', { class: 'sel-headrow' }, h('div', { class: 'sel-title' }, describe(target)));
|
|
103
103
|
const rn = h('button', { type: 'button', class: 'btn sm quiet icon-only', 'aria-label': `Rename ${describe(target)}`, title: 'Rename (F2)' }, icon('pencil'));
|
|
104
|
-
rn.addEventListener('click', () =>
|
|
104
|
+
rn.addEventListener('click', () => void rename(doc, target, 'props', opts.note, { over: true, place: () => (head.isConnected ? head.firstElementChild!.getBoundingClientRect() : undefined) }));
|
|
105
105
|
head.append(rn);
|
|
106
106
|
body.append(head);
|
|
107
107
|
if (toPointer(p) !== r.path) pendingFocus = toPointer(p);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// The inline name field (0.12.5): a small text field just above a thing (on the canvas it follows the thing through pan and
|
|
2
|
+
// zoom), the name selected, so typing replaces it. Nothing modal: no backdrop, and what is under it stays live. Enter commits, and so
|
|
3
|
+
// does a press anywhere else or the focus going elsewhere, when the name is a good one (a bad one is dropped, the name as
|
|
4
|
+
// it was); Esc dismisses. What is wrong with a name shows under the field, and Enter then does nothing.
|
|
5
|
+
|
|
6
|
+
import { h } from './icons.ts';
|
|
7
|
+
import { layer } from './layer.ts';
|
|
8
|
+
|
|
9
|
+
export interface RenameAt {
|
|
10
|
+
/** where the thing is on the page now (asked each frame while the field is open); undefined: not drawn */
|
|
11
|
+
place(): { left: number; top: number; width: number; height: number } | undefined;
|
|
12
|
+
/** over the thing's own words, from their left edge (a heading), not above it */
|
|
13
|
+
over?: boolean;
|
|
14
|
+
/** what the field stays inside, on the page (default: the window) */
|
|
15
|
+
bounds?(): { left: number; top: number; right: number; bottom: number };
|
|
16
|
+
/** where it is until the thing is drawn */
|
|
17
|
+
at?: { x: number; y: number };
|
|
18
|
+
/** a press in here saves the name once it is released (the press may be on the thing itself, or drag it: it goes by the
|
|
19
|
+
* name it has); anywhere else at once, before what was pressed acts (Save, Undo) */
|
|
20
|
+
late?: HTMLElement;
|
|
21
|
+
/** what such a press started (a drag of the thing) isn't over yet: the name waits for it */
|
|
22
|
+
busy?(): boolean;
|
|
23
|
+
/** what has the focus after Enter or Esc (default: what had it) */
|
|
24
|
+
back?: HTMLElement;
|
|
25
|
+
}
|
|
26
|
+
export interface RenameField {
|
|
27
|
+
label: string;
|
|
28
|
+
value: string;
|
|
29
|
+
/** what is wrong with a name ('' : nothing) */
|
|
30
|
+
wrong(v: string): string;
|
|
31
|
+
/** Enter on a good name that isn't the one there */
|
|
32
|
+
commit(v: string): void;
|
|
33
|
+
/** false: the thing is gone, and the field with it */
|
|
34
|
+
alive?(): boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let open: { close(): void } | undefined;
|
|
38
|
+
export const renameOpen = () => !!open;
|
|
39
|
+
|
|
40
|
+
/** Open the field; resolves with the name committed, or undefined when dismissed. */
|
|
41
|
+
export function renameField(f: RenameField, at: RenameAt): Promise<string | undefined> {
|
|
42
|
+
open?.close();
|
|
43
|
+
return new Promise(resolve => {
|
|
44
|
+
const back = at.back ?? (document.activeElement as HTMLElement | null);
|
|
45
|
+
const id = `rename-${Math.random().toString(36).slice(2, 8)}`;
|
|
46
|
+
const input = h('input', { type: 'text', class: 'rename-input', 'aria-label': f.label, 'aria-describedby': id, spellcheck: 'false', autocomplete: 'off', autocapitalize: 'off' });
|
|
47
|
+
const why = h('p', { class: 'rename-error', role: 'alert', id });
|
|
48
|
+
const box = h('div', { class: `rename-field${at.over ? ' over' : ''}` }, input, why);
|
|
49
|
+
input.value = f.value;
|
|
50
|
+
const fitWidth = () => { input.size = Math.max(8, Math.min(40, input.value.length + 1)); };
|
|
51
|
+
fitWidth();
|
|
52
|
+
layer().append(box);
|
|
53
|
+
let done = false, frame = 0, seen = at.at ? { left: at.at.x, top: at.at.y, width: 0, height: 0 } : undefined;
|
|
54
|
+
const put = () => {
|
|
55
|
+
const p = at.place();
|
|
56
|
+
if (p) seen = p;
|
|
57
|
+
const b = at.bounds?.() ?? { left: 0, top: 0, right: innerWidth, bottom: innerHeight }, r = input.getBoundingClientRect();
|
|
58
|
+
const t = seen ?? { left: (b.left + b.right) / 2, top: b.top + 48, width: 0, height: 0 };
|
|
59
|
+
const within = (v: number, lo: number, hi: number) => Math.max(lo, Math.min(v, Math.max(lo, hi)));
|
|
60
|
+
box.style.left = `${within(at.over ? t.left - 8 : t.left + t.width / 2 - r.width / 2, b.left + 4, b.right - r.width - 4)}px`;
|
|
61
|
+
box.style.top = `${within(at.over ? t.top + t.height / 2 - r.height / 2 : t.top - r.height - 8, b.top + 4, b.bottom - r.height - 4)}px`;
|
|
62
|
+
};
|
|
63
|
+
const follow = () => { if (done) return; if (f.alive && !f.alive()) { end(undefined, false); return; } put(); frame = requestAnimationFrame(follow); };
|
|
64
|
+
const check = () => {
|
|
65
|
+
const bad = f.wrong(input.value.trim());
|
|
66
|
+
why.textContent = bad;
|
|
67
|
+
input.setAttribute('aria-invalid', String(!!bad));
|
|
68
|
+
return bad;
|
|
69
|
+
};
|
|
70
|
+
/** the name to save: a good one that isn't the one there */
|
|
71
|
+
const good = () => { const v = input.value.trim(); return v !== f.value && !f.wrong(v) ? v : undefined; };
|
|
72
|
+
function end(v: string | undefined, focusBack: boolean, late = false) {
|
|
73
|
+
if (done) return;
|
|
74
|
+
done = true;
|
|
75
|
+
cancelAnimationFrame(frame);
|
|
76
|
+
removeEventListener('pointerdown', outside, true);
|
|
77
|
+
box.remove();
|
|
78
|
+
open = undefined;
|
|
79
|
+
if (focusBack && back?.isConnected) back.focus({ preventScroll: true });
|
|
80
|
+
const save = () => { if (v !== undefined && (!f.alive || f.alive())) f.commit(v); resolve(v); };
|
|
81
|
+
if (!late || v === undefined) { save(); return; }
|
|
82
|
+
const up = () => { removeEventListener('pointerup', up, true); removeEventListener('pointercancel', up, true); setTimeout(wait, 0); };
|
|
83
|
+
const wait = () => { if (at.busy?.()) setTimeout(wait, 20); else save(); };
|
|
84
|
+
addEventListener('pointerup', up, true); addEventListener('pointercancel', up, true);
|
|
85
|
+
}
|
|
86
|
+
const outside = (e: Event) => { if (!box.contains(e.target as Node)) end(good(), false, !!at.late?.contains(e.target as Node)); };
|
|
87
|
+
addEventListener('pointerdown', outside, true);
|
|
88
|
+
input.addEventListener('input', () => { fitWidth(); check(); });
|
|
89
|
+
input.addEventListener('keydown', e => {
|
|
90
|
+
// ⌘S saves the file, with the name
|
|
91
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 's') { end(good(), true); return; }
|
|
92
|
+
e.stopPropagation(); // the keys are the field's: ⌘Z, Delete and the arrows never reach the canvas
|
|
93
|
+
if (e.isComposing) return;
|
|
94
|
+
if (e.key === 'Escape') { e.preventDefault(); end(undefined, true); }
|
|
95
|
+
if (e.key === 'Enter') { e.preventDefault(); const v = input.value.trim(); if (!check()) end(v === f.value ? undefined : v, true); }
|
|
96
|
+
});
|
|
97
|
+
input.addEventListener('keyup', e => e.stopPropagation());
|
|
98
|
+
// the focus gone elsewhere in the page (not with the window: coming back, the field is as it was)
|
|
99
|
+
input.addEventListener('blur', () => setTimeout(() => { if (!done && document.hasFocus() && document.activeElement !== input && document.activeElement !== document.body) end(good(), false); }, 0));
|
|
100
|
+
open = { close: () => end(undefined, false) };
|
|
101
|
+
follow();
|
|
102
|
+
input.focus({ preventScroll: true });
|
|
103
|
+
input.select();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -7,6 +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 { paletteLooks } from './palette-look.ts';
|
|
10
11
|
import type { DomainAdapter, FileRole, ObjectRef } from '../adapter.ts';
|
|
11
12
|
import type { Path } from '../path.ts';
|
|
12
13
|
import { toPointer } from '../path.ts';
|
|
@@ -56,6 +57,13 @@ export interface DomainView<R, D extends CanvasDrawing> {
|
|
|
56
57
|
/** (0.12.0) the palette 'floating' over the canvas (the default) or 'docked': a pane of its own at the canvas's left,
|
|
57
58
|
* searchable by label and section, resizable and collapsible */
|
|
58
59
|
paletteLayout?: 'floating' | 'docked';
|
|
60
|
+
/** (0.12.5) what a double click on an object of the canvas does: shows it in the text (the default), or renames it */
|
|
61
|
+
doubleClick?: 'text' | 'rename';
|
|
62
|
+
/** (0.14.0) the palette's entries with their icon (the default), or with the thing itself, drawn small in the current theme */
|
|
63
|
+
paletteLook?: 'icon' | 'object';
|
|
64
|
+
/** (0.14.0) what is in a drag's way jiggles before it gives way, and glides: 'always' (the default), or 'respect': not where
|
|
65
|
+
* the viewer prefers reduced motion */
|
|
66
|
+
dragMotion?: 'always' | 'respect';
|
|
59
67
|
/** the canvas's 2D view (0.6.0): a 3D | 2D switch; its link kinds' styles (the host's canvas CSS adds flatCss) */
|
|
60
68
|
flat?: CanvasKit<R, D>['flat'];
|
|
61
69
|
/** a layer over the canvas, and a part beside the views (A: their calls) */
|
|
@@ -112,6 +120,8 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
|
|
|
112
120
|
? 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
121
|
: a.kinds.map(k => ({ kind: k.kind, icon: icon(k.kind), label: k.singular[0].toUpperCase() + k.singular.slice(1) })),
|
|
114
122
|
...(v.paletteLayout === undefined ? {} : { paletteLayout: v.paletteLayout }),
|
|
123
|
+
...(v.doubleClick === undefined ? {} : { doubleClick: v.doubleClick }),
|
|
124
|
+
...(v.dragMotion === undefined ? {} : { dragMotion: v.dragMotion }),
|
|
115
125
|
text: {
|
|
116
126
|
stage: 'The file, drawn: arrow keys and Tab move through what is drawn; + and − zoom, 0 fits', dragGroup: 'A drag on nothing',
|
|
117
127
|
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.',
|
|
@@ -125,6 +135,7 @@ export function setupFor<R, D extends CanvasDrawing>(a: DomainAdapter, v: Domain
|
|
|
125
135
|
...(a.dropInto ? { dropOnto: (t: ObjectRef, v: unknown, k: string, d: unknown) => a.dropInto!(t, v, k, d) } : {}),
|
|
126
136
|
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); },
|
|
127
137
|
};
|
|
138
|
+
if (v.paletteLook === 'object') canvas.looks = paletteLooks(canvas);
|
|
128
139
|
const kit: MountKit<R, undefined> = {
|
|
129
140
|
async check(text) {
|
|
130
141
|
const r = analyse(a, text, { fileName: v.fileName });
|
|
@@ -6,6 +6,24 @@
|
|
|
6
6
|
// Moved here from the editor canvas (R1 S4); the canvas owns the drawing, the overlay and the pointer.
|
|
7
7
|
|
|
8
8
|
export type View = { x: number; y: number; w: number; h: number };
|
|
9
|
+
/** (0.12.6) how far inside the stage what must be on it is, px */
|
|
10
|
+
const INSET = 6;
|
|
11
|
+
/** What a fit makes of a stage (px) and what it frames, `box` PAD px inside it, and what must be on it too, `also` INSET px inside:
|
|
12
|
+
* the zoom and the middle. Pure. */
|
|
13
|
+
export function fitted(s: { w: number; h: number }, box: View, also?: View): { k: number; cx: number; cy: number } {
|
|
14
|
+
const pad = 24;
|
|
15
|
+
// along one axis: the most zoom that `box`, and `also`, and the one's end and the other's together, allow
|
|
16
|
+
const most = (len: number, a0: number, a1: number, b0?: number, b1?: number) => Math.min((len - pad * 2) / (a1 - a0), ...(b0 === undefined || b1 === undefined ? [] : [[b1 - b0, INSET * 2], [b1 - a0, pad + INSET], [a1 - b0, pad + INSET]].map(([d, edges]) => (d > 0 ? (len - edges) / d : Infinity))));
|
|
17
|
+
const k = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, Math.min(most(s.w, box.x, box.x + box.w, also?.x, also && also.x + also.w), most(s.h, box.y, box.y + box.h, also?.y, also && also.y + also.h))));
|
|
18
|
+
// the middle of `box`, moved only as far as `also` needs
|
|
19
|
+
const middle = (len: number, a0: number, a1: number, b0?: number, b1?: number) => {
|
|
20
|
+
const c = (a0 + a1) / 2;
|
|
21
|
+
if (b0 === undefined || b1 === undefined) return c;
|
|
22
|
+
const lo = b1 - (len / 2 - INSET) / k, hi = b0 + (len / 2 - INSET) / k;
|
|
23
|
+
return lo > hi ? (lo + hi) / 2 : Math.max(lo, Math.min(hi, c));
|
|
24
|
+
};
|
|
25
|
+
return { k, cx: middle(s.w, box.x, box.x + box.w, also?.x, also && also.x + also.w), cy: middle(s.h, box.y, box.y + box.h, also?.y, also && also.y + also.h) };
|
|
26
|
+
}
|
|
9
27
|
export const MIN_ZOOM = 0.1, MAX_ZOOM = 8;
|
|
10
28
|
|
|
11
29
|
export interface ViewportOpts {
|
|
@@ -17,6 +35,8 @@ export interface ViewportOpts {
|
|
|
17
35
|
onRezoom(): void;
|
|
18
36
|
/** what a fit frames (the drawing's own things, the overlay's shown marks), if not the whole scene */
|
|
19
37
|
itemsBox(): View | undefined;
|
|
38
|
+
/** (0.12.6) what must be on the stage too when the things are fitted (the connectors), a few px from its edges */
|
|
39
|
+
alsoBox?(): View | undefined;
|
|
20
40
|
/** the overlay has marks that keep their size on screen (a fit repeats while they are showing) */
|
|
21
41
|
marksShowing(): boolean;
|
|
22
42
|
}
|
|
@@ -59,11 +79,11 @@ export function viewport(host: HTMLElement, o: ViewportOpts) {
|
|
|
59
79
|
view = { x: p.x - (px - r.left) / nk, y: p.y - (py - r.top) / nk, w: s.w / nk, h: s.h / nk };
|
|
60
80
|
applyView();
|
|
61
81
|
}
|
|
62
|
-
|
|
82
|
+
/** `also` (0.12.6): what must be on the stage too, INSET px from its edges, and nothing more: the zoom and the middle change only as
|
|
83
|
+
* much as that takes (not at all where it is inside already) */
|
|
84
|
+
function fit(box = full, also?: View) {
|
|
63
85
|
if (!box) return;
|
|
64
|
-
const s = size(),
|
|
65
|
-
const k = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, Math.min((s.w - pad * 2) / box.w, (s.h - pad * 2) / box.h)));
|
|
66
|
-
const cx = box.x + box.w / 2, cy = box.y + box.h / 2;
|
|
86
|
+
const s = size(), { k, cx, cy } = fitted(s, box, also);
|
|
67
87
|
const next = { x: cx - s.w / k / 2, y: cy - s.h / k / 2, w: s.w / k, h: s.h / k };
|
|
68
88
|
// v0.4.2: a fit that lands where the view already is (a refit after a resize that changed nothing it fits) leaves
|
|
69
89
|
// it alone: no new zoom by a rounding error, so nothing on the overlay is redrawn
|
|
@@ -82,7 +102,7 @@ export function viewport(host: HTMLElement, o: ViewportOpts) {
|
|
|
82
102
|
if (key === last) break;
|
|
83
103
|
last = key;
|
|
84
104
|
const m = Math.max(24, Math.min(b.w, b.h) * 0.06);
|
|
85
|
-
quietly(() => fit({ x: b.x - m, y: b.y - m, w: b.w + m * 2, h: b.h + m * 2 }));
|
|
105
|
+
quietly(() => fit({ x: b.x - m, y: b.y - m, w: b.w + m * 2, h: b.h + m * 2 }, o.alsoBox?.()));
|
|
86
106
|
// the marks are redrawn for a new zoom only past the same 2% the zoom itself uses (applyView's rezoom)
|
|
87
107
|
if (!o.marksShowing() || !paintedK || Math.abs(scale() / paintedK - 1) <= 0.02) break;
|
|
88
108
|
cancelAnimationFrame(rezoom); rezoom = 0;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** path → route id, in the file's order as the drawing maps it */
|
|
2
|
+
export declare function connectionsOf(pathOf: ReadonlyMap<string, string>, isRoute: (id: string) => boolean, objectOf: (ptr: string) => unknown): Map<string, string>;
|
|
3
|
+
/** the nearest point of a polyline path ("M x,y L x,y …", the numbers taken in pairs) to a point */
|
|
4
|
+
export declare function nearestOn(d: string, x: number, y: number): {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
dist: number;
|
|
8
|
+
} | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** a drop that overlaps waits this long on one cell before anything shows (ms) */
|
|
2
|
+
export declare const DWELL_HINT = 150;
|
|
3
|
+
/** and this long, from the same start, before the things in its way give way (ms) */
|
|
4
|
+
export declare const DWELL_GIVE = 700;
|
|
5
|
+
/** what gave way goes back this long after the dragged thing no longer needs the place (ms) */
|
|
6
|
+
export declare const BACK_AFTER = 250;
|
|
7
|
+
/** a thing's glide to its place, or back (ms) */
|
|
8
|
+
export declare const GLIDE = 180;
|
|
9
|
+
/** the jiggle: how far (screen px), and how often (a second) */
|
|
10
|
+
export declare const JIGGLE: {
|
|
11
|
+
px: number;
|
|
12
|
+
hz: number;
|
|
13
|
+
};
|
|
14
|
+
/** the most things that may step aside for one drop */
|
|
15
|
+
export declare const MAX_CHAIN = 3;
|
|
16
|
+
export interface Rect {
|
|
17
|
+
x0: number;
|
|
18
|
+
y0: number;
|
|
19
|
+
x1: number;
|
|
20
|
+
y1: number;
|
|
21
|
+
}
|
|
22
|
+
export interface Beside extends Rect {
|
|
23
|
+
id: string;
|
|
24
|
+
/** whether it may be pinned somewhere else */
|
|
25
|
+
movable: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface WayOptions {
|
|
28
|
+
/** where the dragged thing would be */
|
|
29
|
+
foot: Rect;
|
|
30
|
+
/** everything else in the container */
|
|
31
|
+
others: Beside[];
|
|
32
|
+
/** the way it was going: its last step, or from where it started */
|
|
33
|
+
going: [number, number];
|
|
34
|
+
/** what a thing that steps aside must stay in (the container, less its margin); none: anywhere */
|
|
35
|
+
bounds?: Rect;
|
|
36
|
+
max?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare const hits: (a: Rect, b: Rect) => boolean;
|
|
39
|
+
/** The steps (whole cells) of what would move, by id; undefined: nothing can make way. */
|
|
40
|
+
export declare function makeWay({ foot, others, going, bounds, max }: WayOptions): Map<string, [number, number]> | undefined;
|
|
@@ -9,6 +9,8 @@ export interface Command {
|
|
|
9
9
|
build(text: string): Splice;
|
|
10
10
|
/** the paths it touched (for the views to refresh and reveal) */
|
|
11
11
|
touched?: Path[];
|
|
12
|
+
/** (0.12.5) the label of the step it joined (apply's `joins`), given the step's own */
|
|
13
|
+
joined?(label: string): string;
|
|
12
14
|
/** where a path is after the change (a rename moves paths); null when it no longer exists */
|
|
13
15
|
remap?(p: Path): Path | null;
|
|
14
16
|
/** the selection afterwards (default: the old one, remapped) */
|
|
@@ -68,8 +70,10 @@ export declare class EditorModel {
|
|
|
68
70
|
/** A new file: the text, an empty history, clean. */
|
|
69
71
|
load(text: string, origin?: Origin): void;
|
|
70
72
|
private set;
|
|
71
|
-
/** Run a command: build it against the text, apply its steps, push it. Returns false if it changed nothing.
|
|
72
|
-
|
|
73
|
+
/** Run a command: build it against the text, apply its steps, push it. Returns false if it changed nothing. `joins`
|
|
74
|
+
* (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
|
|
75
|
+
* wasn't saved at it (the saved text must stay a step of its own to come back to). */
|
|
76
|
+
apply(cmd: Command, origin?: Origin, joins?: number): boolean;
|
|
73
77
|
/**
|
|
74
78
|
* Text the user typed (one change from the text pane: edits against the text before it). The view has already
|
|
75
79
|
* made the change; the model takes it, and coalesces typing into one command per word or pause.
|
|
@@ -84,6 +88,8 @@ export declare class EditorModel {
|
|
|
84
88
|
private push;
|
|
85
89
|
get canUndo(): boolean;
|
|
86
90
|
get canRedo(): boolean;
|
|
91
|
+
/** the last undo step's id (what `apply` may join) */
|
|
92
|
+
get undoId(): number;
|
|
87
93
|
get undoLabel(): string;
|
|
88
94
|
get redoLabel(): string;
|
|
89
95
|
undo(): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RenameAt } from './rename.js';
|
|
1
2
|
import type { EditorModel, Command } from '../model.js';
|
|
2
3
|
import type { Commands } from '../commands.js';
|
|
3
4
|
import type { ObjectKindInfo, ObjectRef } from '../adapter.js';
|
|
@@ -10,13 +11,15 @@ export interface ActionsKit {
|
|
|
10
11
|
nameRule: RegExp;
|
|
11
12
|
nameHint: string;
|
|
12
13
|
}
|
|
13
|
-
export declare function run(doc: EditorModel, c: Command, origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void): boolean;
|
|
14
|
+
export declare function run(doc: EditorModel, c: Command, origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void, joins?: number): boolean;
|
|
14
15
|
/** Several commands as one undo step. */
|
|
15
16
|
export declare function composite(label: string, cmds: Command[]): Command;
|
|
16
17
|
/** The shared actions, for one domain. */
|
|
17
18
|
export declare function actionsFor(kit: ActionsKit): {
|
|
18
19
|
deletePaths: (doc: EditorModel, paths: Path[], origin: 'canvas' | 'props' | 'menu', note?: (t: string, tone?: 'bad') => void) => Promise<boolean>;
|
|
19
|
-
|
|
20
|
+
rename: (doc: EditorModel, path: Path, origin: 'canvas' | 'props' | 'menu', note: ((t: string, tone?: 'bad') => void) | undefined, at: RenameAt & {
|
|
21
|
+
joins?: number;
|
|
22
|
+
}) => Promise<boolean>;
|
|
20
23
|
duplicate: (doc: EditorModel, path: Path, origin: 'canvas' | 'menu', note?: (t: string, tone?: 'bad') => void) => void;
|
|
21
24
|
connected: (doc: EditorModel, paths: Path[]) => Path[];
|
|
22
25
|
};
|
|
@@ -4,9 +4,10 @@ import { type Actions } from './actions.js';
|
|
|
4
4
|
import { type Move } from '../../iso-objects/geometry.js';
|
|
5
5
|
import { type KindCatalog } from '../../iso-objects/kinds.js';
|
|
6
6
|
import type { CompiledScene } from '../../iso-objects/compile.js';
|
|
7
|
-
import type { EditorModel } from '../model.js';
|
|
7
|
+
import type { EditorModel, Command } from '../model.js';
|
|
8
8
|
import type { Problem } from '../validate.js';
|
|
9
9
|
import { type Commands } from '../commands.js';
|
|
10
|
+
import { type Beside } from '../make-way.js';
|
|
10
11
|
import type { ObjectKindInfo, ObjectRef, ConnectPlan, GroupPlan } from '../adapter.js';
|
|
11
12
|
import { type Path } from '../path.js';
|
|
12
13
|
import { type View } from '../../iso-viewer/viewport.js';
|
|
@@ -90,6 +91,12 @@ export interface CanvasUi {
|
|
|
90
91
|
* its own at the canvas's left, with a search box filtering by label and section, resizable and collapsible; its
|
|
91
92
|
* width and whether it is collapsed are kept in the host's store as `canvas-palette-dock`) */
|
|
92
93
|
paletteLayout?: 'floating' | 'docked';
|
|
94
|
+
/** (0.12.5) what a double click on an object does: shows it in the text (the default), or renames it (0.14.1: what has no
|
|
95
|
+
* name, a connection, does nothing then) */
|
|
96
|
+
doubleClick?: 'text' | 'rename';
|
|
97
|
+
/** (0.14.0) whether what is in a drag's way jiggles before it gives way, and glides: 'always' (the default), or
|
|
98
|
+
* 'respect': not where the viewer prefers reduced motion (the outlines of where it would go still show) */
|
|
99
|
+
dragMotion?: 'always' | 'respect';
|
|
93
100
|
text: {
|
|
94
101
|
stage: string;
|
|
95
102
|
dragGroup: string;
|
|
@@ -132,6 +139,9 @@ export interface CanvasKit<M, D extends CanvasDrawing> {
|
|
|
132
139
|
} | undefined;
|
|
133
140
|
/** (0.10.0) the selection made into a new container (the adapter's group): Group, ⌘G, one undo step */
|
|
134
141
|
group?(members: ObjectRef[], data: unknown): GroupPlan | undefined;
|
|
142
|
+
/** (0.14.0) the palette's entries as what they make, drawn small (palette-look.ts): what draws those that show and aren't
|
|
143
|
+
* drawn yet. None: the entries' icons */
|
|
144
|
+
looks?(palette: HTMLElement, data: () => unknown, ui: CanvasUi, theme: string): () => void;
|
|
135
145
|
actions: Actions;
|
|
136
146
|
/** what an object's own menu offers, beyond rename, duplicate and delete */
|
|
137
147
|
objectItems(doc: EditorModel, path: Path, origin: 'canvas' | 'menu', note?: (t: string, tone?: 'bad') => void): MenuItem[];
|
|
@@ -180,6 +190,12 @@ export interface CanvasOpts<M, D extends CanvasDrawing, A extends object = objec
|
|
|
180
190
|
/** a layer over the drawing (none: the drawing and its marks only) */
|
|
181
191
|
layer?: (ctx: CanvasCtx<D>) => CanvasLayer<A>;
|
|
182
192
|
}
|
|
193
|
+
/** a new thing as a drag would make it: inside what (none: the canvas), by which command */
|
|
194
|
+
export interface FreshPlan {
|
|
195
|
+
into?: string;
|
|
196
|
+
label: string;
|
|
197
|
+
add: Command;
|
|
198
|
+
}
|
|
183
199
|
export declare function canvasView<M, D extends CanvasDrawing, A extends object = object>(host: HTMLElement, doc: EditorModel, opts: CanvasOpts<M, D, A>): {
|
|
184
200
|
addFromPalette: (sec: string, at?: {
|
|
185
201
|
x: number;
|
|
@@ -188,10 +204,6 @@ export declare function canvasView<M, D extends CanvasDrawing, A extends object
|
|
|
188
204
|
palette: HTMLDivElement;
|
|
189
205
|
groupSelection: () => void;
|
|
190
206
|
startPick: () => void;
|
|
191
|
-
objectsUnder: (at: {
|
|
192
|
-
x: number;
|
|
193
|
-
y: number;
|
|
194
|
-
}) => ObjectRef[];
|
|
195
207
|
readonly linking: {
|
|
196
208
|
from: ObjectRef;
|
|
197
209
|
x?: number;
|
|
@@ -203,7 +215,8 @@ export declare function canvasView<M, D extends CanvasDrawing, A extends object
|
|
|
203
215
|
setTheme: (_t: 'light' | 'dark') => void;
|
|
204
216
|
paintOverlay: () => void;
|
|
205
217
|
fit: () => void;
|
|
206
|
-
|
|
218
|
+
fitNext(): void;
|
|
219
|
+
fitAll: (box?: View | undefined, also?: View) => void;
|
|
207
220
|
actual: () => void;
|
|
208
221
|
zoomAt: (f: number, cx?: number, cy?: number) => void;
|
|
209
222
|
itemsBox: () => {
|
|
@@ -212,6 +225,12 @@ export declare function canvasView<M, D extends CanvasDrawing, A extends object
|
|
|
212
225
|
w: number;
|
|
213
226
|
h: number;
|
|
214
227
|
} | undefined;
|
|
228
|
+
routesBox: () => {
|
|
229
|
+
x: number;
|
|
230
|
+
y: number;
|
|
231
|
+
w: number;
|
|
232
|
+
h: number;
|
|
233
|
+
} | undefined;
|
|
215
234
|
readonly moved: boolean;
|
|
216
235
|
settled: () => Promise<void>;
|
|
217
236
|
readonly zoom: number;
|
|
@@ -257,6 +276,7 @@ export declare function canvasView<M, D extends CanvasDrawing, A extends object
|
|
|
257
276
|
z0?: number;
|
|
258
277
|
size?: [number, number];
|
|
259
278
|
parent?: {
|
|
279
|
+
id: string;
|
|
260
280
|
w: number;
|
|
261
281
|
d: number;
|
|
262
282
|
pad: number;
|
|
@@ -268,17 +288,27 @@ export declare function canvasView<M, D extends CanvasDrawing, A extends object
|
|
|
268
288
|
};
|
|
269
289
|
label: string;
|
|
270
290
|
};
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
y0: number;
|
|
274
|
-
x1: number;
|
|
275
|
-
y1: number;
|
|
276
|
-
}[];
|
|
291
|
+
/** (0.14.0) how far the view was moved to keep the container still on screen (a trial may lay it out elsewhere) */
|
|
292
|
+
shifted?: [number, number];
|
|
277
293
|
move?: Move;
|
|
278
294
|
invalid?: boolean;
|
|
279
295
|
step?: number;
|
|
280
296
|
origCd?: D;
|
|
281
297
|
gridShown?: boolean;
|
|
298
|
+
/** what stands beside it in its container, where it stood when the drag began */
|
|
299
|
+
beside?: Beside[];
|
|
300
|
+
/** (0.14.0) what gave way to it, by how many cells; what would, while the drop waits; the last cell it could drop on */
|
|
301
|
+
given?: Map<string, [number, number]>;
|
|
302
|
+
way?: Map<string, [number, number]>;
|
|
303
|
+
clearAt?: [number, number];
|
|
304
|
+
/** (0.14.0) a new thing, from the palette (origCd: the drawing without it): the drawing with it, and what it is made as */
|
|
305
|
+
fresh?: {
|
|
306
|
+
base: D;
|
|
307
|
+
name: string;
|
|
308
|
+
path: Path;
|
|
309
|
+
plan: FreshPlan;
|
|
310
|
+
text: string;
|
|
311
|
+
};
|
|
282
312
|
/** siblings that flow after the dragged item, pinned where they stand so the drag doesn't push them */
|
|
283
313
|
keep?: [string, [number, number]][];
|
|
284
314
|
sel0?: Path[];
|
|
@@ -85,7 +85,8 @@ export interface ShellFeatures {
|
|
|
85
85
|
export interface ShellCanvas {
|
|
86
86
|
render(model: unknown, data: unknown): Promise<void>;
|
|
87
87
|
setTheme(t: 'light' | 'dark'): void;
|
|
88
|
-
fit(): void;
|
|
88
|
+
fit(): void; /** (0.12.5) the next drawing is fitted, whatever the person did with the view before */
|
|
89
|
+
fitNext?(): void;
|
|
89
90
|
focus(): void;
|
|
90
91
|
dispose(): void;
|
|
91
92
|
}
|
|
@@ -131,8 +132,11 @@ export interface EditorState<R = unknown, X = unknown> {
|
|
|
131
132
|
checks: number;
|
|
132
133
|
}
|
|
133
134
|
export interface Editor {
|
|
135
|
+
/** `fit` (0.12.5): it is another document, so its drawing is fitted once drawn (default: the view stays where it is) */
|
|
134
136
|
getText(): string;
|
|
135
|
-
setText(text: string
|
|
137
|
+
setText(text: string, o?: {
|
|
138
|
+
fit?: boolean;
|
|
139
|
+
}): void;
|
|
136
140
|
setReadOnly(ro: boolean): void;
|
|
137
141
|
setTheme(t: Theme): void;
|
|
138
142
|
addFeatures(names: readonly string[]): Promise<void>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CanvasDrawing, CanvasKit } from './canvas.js';
|
|
2
|
+
type Kit<M, D extends CanvasDrawing> = Pick<CanvasKit<M, D>, 'kinds' | 'commands' | 'trial'>;
|
|
3
|
+
/** The kit's `looks`: the entries that show, one at a time, each once; an entry that can't be drawn alone keeps its icon. */
|
|
4
|
+
export declare const paletteLooks: <M, D extends CanvasDrawing>(K: Kit<M, D>) => NonNullable<CanvasKit<M, D>['looks']>;
|
|
5
|
+
export {};
|
|
@@ -34,7 +34,7 @@ export interface PropsUi {
|
|
|
34
34
|
/** what the panel is given of the domain */
|
|
35
35
|
export interface PropsKit {
|
|
36
36
|
commands: Pick<Commands, 'setCmd' | 'deleteCmd' | 'insertItemCmd' | 'referencesTo' | 'describe'>;
|
|
37
|
-
actions: Pick<Actions, 'deletePaths' | '
|
|
37
|
+
actions: Pick<Actions, 'deletePaths' | 'rename'>;
|
|
38
38
|
slotAt(ptr: string): RefSlot | undefined;
|
|
39
39
|
objectOf(ptr: string): ObjectRef | undefined;
|
|
40
40
|
kinds: ObjectKindInfo[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface RenameAt {
|
|
2
|
+
/** where the thing is on the page now (asked each frame while the field is open); undefined: not drawn */
|
|
3
|
+
place(): {
|
|
4
|
+
left: number;
|
|
5
|
+
top: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
} | undefined;
|
|
9
|
+
/** over the thing's own words, from their left edge (a heading), not above it */
|
|
10
|
+
over?: boolean;
|
|
11
|
+
/** what the field stays inside, on the page (default: the window) */
|
|
12
|
+
bounds?(): {
|
|
13
|
+
left: number;
|
|
14
|
+
top: number;
|
|
15
|
+
right: number;
|
|
16
|
+
bottom: number;
|
|
17
|
+
};
|
|
18
|
+
/** where it is until the thing is drawn */
|
|
19
|
+
at?: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
};
|
|
23
|
+
/** a press in here saves the name once it is released (the press may be on the thing itself, or drag it: it goes by the
|
|
24
|
+
* name it has); anywhere else at once, before what was pressed acts (Save, Undo) */
|
|
25
|
+
late?: HTMLElement;
|
|
26
|
+
/** what such a press started (a drag of the thing) isn't over yet: the name waits for it */
|
|
27
|
+
busy?(): boolean;
|
|
28
|
+
/** what has the focus after Enter or Esc (default: what had it) */
|
|
29
|
+
back?: HTMLElement;
|
|
30
|
+
}
|
|
31
|
+
export interface RenameField {
|
|
32
|
+
label: string;
|
|
33
|
+
value: string;
|
|
34
|
+
/** what is wrong with a name ('' : nothing) */
|
|
35
|
+
wrong(v: string): string;
|
|
36
|
+
/** Enter on a good name that isn't the one there */
|
|
37
|
+
commit(v: string): void;
|
|
38
|
+
/** false: the thing is gone, and the field with it */
|
|
39
|
+
alive?(): boolean;
|
|
40
|
+
}
|
|
41
|
+
export declare const renameOpen: () => boolean;
|
|
42
|
+
/** Open the field; resolves with the name committed, or undefined when dismissed. */
|
|
43
|
+
export declare function renameField(f: RenameField, at: RenameAt): Promise<string | undefined>;
|