deictic 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +136 -30
- package/README.md +4 -3
- package/dist/annotations/client.d.ts +1 -1
- package/dist/annotations/client.d.ts.map +1 -1
- package/dist/annotations/client.js +161 -176
- package/dist/annotations/client.js.map +1 -1
- package/dist/annotations/index.d.ts +2 -11
- package/dist/client/index.d.ts +7 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1007 -192
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/recommended/index.d.ts +2 -2
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +82 -153
- package/dist/recordings/client.js.map +1 -1
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/shared/annotations.js +3 -4
- package/dist/shared/annotations.js.map +1 -1
- package/dist/shared/board.js +1 -1
- package/dist/shared/client.js +45 -2
- package/dist/shared/client.js.map +1 -1
- package/dist/shared/component.js +62 -0
- package/dist/shared/component.js.map +1 -0
- package/dist/shared/dom.js +79 -0
- package/dist/shared/dom.js.map +1 -0
- package/dist/shared/drawer.js +217 -0
- package/dist/shared/drawer.js.map +1 -0
- package/dist/shared/index.d.ts +116 -7
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index2.d.ts +9 -19
- package/dist/shared/index2.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +103 -26
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/index9.d.ts +1 -1
- package/dist/shared/integration.d.ts +1 -1
- package/dist/shared/packages.js +1 -1
- package/dist/shared/recording.js +31 -3
- package/dist/shared/recording.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +44 -29
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +232 -62
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/vb.js +1 -1
- package/dist/shared/voice2.js +6 -4
- package/dist/shared/voice2.js.map +1 -1
- package/dist/shared/watch.js +14 -14
- package/dist/shared/watch.js.map +1 -1
- package/dist/tasks/client.d.ts +2 -2
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +1829 -741
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/voice/client.d.ts.map +1 -1
- package/dist/voice/client.js +154 -57
- package/dist/voice/client.js.map +1 -1
- package/package.json +1 -1
- package/skills/deictic/SKILL.md +22 -28
- package/src/cli/recording.ts +34 -3
- package/src/cli/task.ts +59 -30
- package/src/cli/voice.ts +9 -4
- package/src/cli/watch.ts +14 -13
- package/src/client/away.ts +3 -1
- package/src/client/component.ts +98 -0
- package/src/client/dom.ts +70 -0
- package/src/client/drawer.ts +258 -0
- package/src/client/index.ts +220 -128
- package/src/client/lightbox.ts +8 -8
- package/src/client/lighting.ts +279 -0
- package/src/client/style.ts +263 -44
- package/src/client/tools.ts +279 -0
- package/src/client/tooltip.ts +25 -5
- package/src/client/tray.ts +48 -0
- package/src/index.ts +113 -6
- package/src/plugins/annotations/client.ts +103 -129
- package/src/plugins/annotations/draw.ts +68 -72
- package/src/plugins/annotations/index.ts +12 -19
- package/src/plugins/recordings/client.ts +89 -167
- package/src/plugins/screenshots/client.ts +53 -2
- package/src/plugins/tasks/client.ts +219 -748
- package/src/plugins/tasks/composer.ts +797 -0
- package/src/plugins/tasks/drawer.ts +516 -0
- package/src/plugins/tasks/index.ts +360 -82
- package/src/plugins/tasks/pins.ts +275 -0
- package/src/plugins/tasks/store.ts +132 -0
- package/src/plugins/voice/client.ts +96 -5
- package/skills/deictic/references/recordings.md +0 -13
- package/skills/deictic/references/tasks.md +0 -22
- package/skills/deictic/references/watch.md +0 -17
package/src/client/index.ts
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `deictic/client`: the overlay the page loads in dev. Hold a shortcut's keys (Alt, deictic's own,
|
|
3
|
-
* by default) and point: the element under the pointer that the source marked
|
|
4
|
-
*
|
|
5
|
-
* the popup
|
|
6
|
-
* its shortcut was pressed.
|
|
3
|
+
* by default) and point: the page dims around the element under the pointer that the source marked
|
|
4
|
+
* (`tools/locate.ts`), which stays lit, with its tag, its place and how many elements share it (`lighting.ts`).
|
|
5
|
+
* Press the shortcut's button to open the popup beside it: a tab for each plugin with a panel, at the one used
|
|
6
|
+
* last, or at a plugin's own where its shortcut was pressed.
|
|
7
7
|
*
|
|
8
8
|
* Everything drawn sits in one shadow root, so neither the page's styles nor ours cross over. A
|
|
9
9
|
* panel's undo and redo are its tab's on its element: the latest change that plugin made there.
|
|
10
10
|
*/
|
|
11
|
-
import type { ClientContext, ClientPlugin, LightboxItem, PanelContext, Resumed, Standalone, Target } from '#src/index.ts';
|
|
11
|
+
import type { ClientContext, ClientPlugin, LightboxItem, PanelContext, Point, Resumed, Spot, Standalone, Target } from '#src/index.ts';
|
|
12
12
|
import { gestureOf, type Shortcut } from '#src/shortcut.ts';
|
|
13
13
|
|
|
14
14
|
import { dropAway, keepAway, keptAway } from './away.ts';
|
|
15
|
+
import { named, tell } from './component.ts';
|
|
16
|
+
import { ATTRIBUTE, div, nameOf, reduced, sameAs, targetOf } from './dom.ts';
|
|
17
|
+
import { drawerIn } from './drawer.ts';
|
|
15
18
|
import { openLightbox } from './lightbox.ts';
|
|
19
|
+
import { CLEAR, type Lighting, spotlight, spotOf } from './lighting.ts';
|
|
16
20
|
import { STYLE } from './style.ts';
|
|
21
|
+
import { toolPanel } from './tools.ts';
|
|
17
22
|
import { tooltips } from './tooltip.ts';
|
|
23
|
+
import { tray } from './tray.ts';
|
|
18
24
|
|
|
19
25
|
// For a plugin's page half that records the mic, or shows a clip: the waveforms the lightbox draws.
|
|
20
26
|
export { drawBars, liveWaveform, peaksOf, type Colors } from './waveform.ts';
|
|
27
|
+
export { targetOf } from './dom.ts';
|
|
21
28
|
|
|
22
29
|
export interface StartOptions {
|
|
23
30
|
/** The dev server's base URL, ending in `/`. */
|
|
@@ -41,7 +48,6 @@ interface Tab {
|
|
|
41
48
|
mount: Mount;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
const ATTRIBUTE = 'data-deictic';
|
|
45
51
|
/** An arrow pointing up and out: the link leaves the page for the editor. */
|
|
46
52
|
const OUT = icon('M7 17 17 7M8 7h9v9', 2.25);
|
|
47
53
|
// Drawn, as the arrows and the cross of a system's font differ in size and weight from one to the next.
|
|
@@ -54,15 +60,6 @@ const LAST = 'deictic:tab';
|
|
|
54
60
|
const SLOW = 200;
|
|
55
61
|
const STARTED = Symbol.for('deictic');
|
|
56
62
|
|
|
57
|
-
export function targetOf(el: Element): Target | undefined {
|
|
58
|
-
const at = el.getAttribute(ATTRIBUTE);
|
|
59
|
-
const match = at === null ? null : /^(.*):(\d+):(\d+)$/.exec(at);
|
|
60
|
-
if (match === null) return undefined;
|
|
61
|
-
return { loc: { file: match[1]!, line: Number(match[2]), column: Number(match[3]) }, tag: el.localName };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const sameAs = (el: Element) => [...document.querySelectorAll(`[${ATTRIBUTE}="${CSS.escape(el.getAttribute(ATTRIBUTE) ?? '')}"]`)];
|
|
65
|
-
|
|
66
63
|
/** The nearest marked element around `el`, out through shadow roots to their hosts. */
|
|
67
64
|
function markedAround(el: Element): Element | undefined {
|
|
68
65
|
for (let at: Element | undefined = el; at !== undefined;) {
|
|
@@ -74,13 +71,10 @@ function markedAround(el: Element): Element | undefined {
|
|
|
74
71
|
return undefined;
|
|
75
72
|
}
|
|
76
73
|
|
|
77
|
-
/** `div.panel > button.tab`: the element as a selector, the deepest classes only, for a person to tell it by. */
|
|
78
74
|
function icon(path: string, width = 2): string {
|
|
79
75
|
return `<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="${width}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${path}"/></svg>`;
|
|
80
76
|
}
|
|
81
77
|
|
|
82
|
-
const nameOf = (el: Element) => `${el.localName}${[...el.classList].map((c) => `.${c}`).join('')}`;
|
|
83
|
-
|
|
84
78
|
/** What the overlay keeps once started, for `popupIn` to show the popup with. */
|
|
85
79
|
interface Started {
|
|
86
80
|
base: string;
|
|
@@ -151,7 +145,6 @@ export function popupIn(container: Element, { tab: name, element }: { tab?: stri
|
|
|
151
145
|
remember,
|
|
152
146
|
element,
|
|
153
147
|
target,
|
|
154
|
-
pinned: true,
|
|
155
148
|
onClose: (shown, leaving) => {
|
|
156
149
|
panel = undefined;
|
|
157
150
|
// Closed by its own × or Esc: open again, as the page is there to show it. Leaving for `away` comes back by `reopen`.
|
|
@@ -197,13 +190,22 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
197
190
|
const root = host.attachShadow({ mode: 'open' });
|
|
198
191
|
const style = document.createElement('style');
|
|
199
192
|
style.textContent = STYLE;
|
|
200
|
-
|
|
201
|
-
const label = div('label');
|
|
202
|
-
box.append(label);
|
|
203
|
-
// What's under the pointer, outlined inside the marked element around it when they differ.
|
|
204
|
-
const inner = div('box inner');
|
|
205
|
-
root.append(style, box, inner);
|
|
193
|
+
root.append(style);
|
|
206
194
|
tooltips(root);
|
|
195
|
+
const lighting = spotlight(root);
|
|
196
|
+
const kept = tray();
|
|
197
|
+
// A tool has the page to pick a point on (`pick`): what's under the pointer is lit as while the keys are held.
|
|
198
|
+
let picking = false;
|
|
199
|
+
const tools = toolPanel(root, {
|
|
200
|
+
spotAt: (x, y) => spotAt(x, y),
|
|
201
|
+
aim: (on) => {
|
|
202
|
+
picking = on;
|
|
203
|
+
if (on) glance(true);
|
|
204
|
+
else if (held.length === 0) hide();
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
// Out from under the tool panel, where that's on the window's right.
|
|
208
|
+
const drawer = drawerIn(root, { crowded: () => tools.edge() === 'right' });
|
|
207
209
|
// What's typed in the popup is the popup's: the page hears a key from in here as one on the host, not in a field,
|
|
208
210
|
// so its own shortcuts (a "/" to search, a "j" to step) would run on a task's words. Ours listen while capturing.
|
|
209
211
|
for (const type of ['keydown', 'keypress', 'keyup'] as const) host.addEventListener(type, (e) => e.stopPropagation());
|
|
@@ -221,8 +223,16 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
221
223
|
options: optionsOf.get(name),
|
|
222
224
|
use: (other) => apis.get(other) as never,
|
|
223
225
|
request: (route, init) => send(`${base}__deictic/plugins/${name}/${route}`, init),
|
|
224
|
-
|
|
226
|
+
// Not from under something unsaved, which a press on the page wouldn't close either: its button shakes.
|
|
227
|
+
open: (plugin, element, at) => panel?.guard() !== true && openAt(plugin, element, at),
|
|
225
228
|
lightbox: (items, options) => openLightbox(root, items, options),
|
|
229
|
+
drawer,
|
|
230
|
+
light: (element) => {
|
|
231
|
+
lit = element?.isConnected === true ? element : undefined;
|
|
232
|
+
relight();
|
|
233
|
+
},
|
|
234
|
+
tools,
|
|
235
|
+
tray: kept,
|
|
226
236
|
});
|
|
227
237
|
for (const { plugin } of given) {
|
|
228
238
|
if (plugin.setup === undefined) continue;
|
|
@@ -261,11 +271,11 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
261
271
|
// What opens the popup, and at which tab: deictic's own shortcut at the one used last, each
|
|
262
272
|
// plugin's at its own.
|
|
263
273
|
const plugins = [
|
|
264
|
-
...(own === undefined || tabs.length === 0 ? [] : [{ shortcut: own, gesture: gestureOf(own), tab: last }]),
|
|
274
|
+
...(own === undefined || tabs.length === 0 ? [] : [{ shortcut: own, gesture: gestureOf(own), tab: last, named: false }]),
|
|
265
275
|
...given.flatMap(({ plugin, shortcut }) => {
|
|
266
276
|
if (shortcut === undefined) return [];
|
|
267
277
|
const tab = tabs.find((t) => t.plugin === plugin);
|
|
268
|
-
if (tab !== undefined) return [{ shortcut, gesture: gestureOf(shortcut), tab: () => tab }];
|
|
278
|
+
if (tab !== undefined) return [{ shortcut, gesture: gestureOf(shortcut), tab: () => tab, named: true }];
|
|
269
279
|
console.error(`deictic: ${plugin.name} has a shortcut, but its page half has no \`mount\` to draw a tab with`);
|
|
270
280
|
return [];
|
|
271
281
|
}),
|
|
@@ -273,7 +283,7 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
273
283
|
|
|
274
284
|
let pointer: { x: number; y: number } | undefined;
|
|
275
285
|
let frame = 0;
|
|
276
|
-
let panel:
|
|
286
|
+
let panel: ReturnType<typeof openPanel> | undefined;
|
|
277
287
|
|
|
278
288
|
/** The plugins whose keys are held: several, where they share keys and differ by button. */
|
|
279
289
|
const heldBy = (e: MouseEvent | KeyboardEvent) => plugins.filter((p) => p.gesture.held(e));
|
|
@@ -281,10 +291,11 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
281
291
|
const pressedBy = (e: MouseEvent) => plugins.find((p) => p.gesture.held(e) && e.button === p.gesture.button);
|
|
282
292
|
/**
|
|
283
293
|
* The marked element at a point, and what's under the pointer inside it where that differs: down through
|
|
284
|
-
* open shadow roots but the overlay's own, as a page showing the popup (`popupIn`) has it in one.
|
|
294
|
+
* open shadow roots but the overlay's own, as a page showing the popup (`popupIn`) has it in one. `through` the
|
|
295
|
+
* overlay, where it's the overlay that has the pointer: a tool's surface, while a point is picked.
|
|
285
296
|
*/
|
|
286
|
-
const hitAt = (x: number, y: number) => {
|
|
287
|
-
let under = document.elementFromPoint(x, y) ?? undefined;
|
|
297
|
+
const hitAt = (x: number, y: number, through = false) => {
|
|
298
|
+
let under = (through ? document.elementsFromPoint(x, y).find((el) => el !== host) : document.elementFromPoint(x, y)) ?? undefined;
|
|
288
299
|
while (under !== undefined && under !== host && under.shadowRoot !== null) {
|
|
289
300
|
const inside = under.shadowRoot.elementFromPoint(x, y);
|
|
290
301
|
if (inside === null || inside === under) break;
|
|
@@ -293,39 +304,90 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
293
304
|
const el = under === undefined || under === host ? undefined : markedAround(under);
|
|
294
305
|
return el === undefined ? undefined : { el, pointed: under === el ? undefined : under };
|
|
295
306
|
};
|
|
307
|
+
// The plugins whose keys are held now, as the last event said: what's pointed at is shown while there are any.
|
|
308
|
+
let held: typeof plugins = [];
|
|
309
|
+
// What plugins show on the page while it's pointed on (`pointing`), each with what takes it away.
|
|
310
|
+
let glanced: (() => void)[] | undefined;
|
|
311
|
+
const glance = (on: boolean) => {
|
|
312
|
+
if (on === (glanced !== undefined)) return;
|
|
313
|
+
for (const end of glanced ?? []) end();
|
|
314
|
+
glanced = !on
|
|
315
|
+
? undefined
|
|
316
|
+
: given.flatMap(({ plugin }) => {
|
|
317
|
+
try {
|
|
318
|
+
return plugin.pointing === undefined ? [] : [plugin.pointing(contextOf(plugin.name))];
|
|
319
|
+
} catch (e) {
|
|
320
|
+
console.error(`deictic: ${plugin.name} failed to show what it has on the page`, e);
|
|
321
|
+
return [];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
// An element a plugin lights from the overlay's own UI (`context.light`): lit while it says so, whatever the keys.
|
|
326
|
+
let lit: Element | undefined;
|
|
327
|
+
const relight = () => {
|
|
328
|
+
const target = lit === undefined ? undefined : targetOf(lit);
|
|
329
|
+
if (lit !== undefined && target !== undefined) return lighting.point({ el: lit, target, names: [], count: sameAs(lit).length });
|
|
330
|
+
if (held.length > 0 || picking) return show(false);
|
|
331
|
+
lighting.hide();
|
|
332
|
+
};
|
|
296
333
|
const hide = () => {
|
|
297
|
-
|
|
298
|
-
|
|
334
|
+
held = [];
|
|
335
|
+
tools.point(false);
|
|
336
|
+
drawer.point(false);
|
|
337
|
+
glance(false);
|
|
338
|
+
relight();
|
|
339
|
+
};
|
|
340
|
+
/** The marked element at a point of the window, or the nearest to it where none is under it, and the point in it. */
|
|
341
|
+
const spotAt = (x: number, y: number): Spot | undefined => {
|
|
342
|
+
const away = (el: Element) => {
|
|
343
|
+
const r = el.getBoundingClientRect();
|
|
344
|
+
return r.width === 0 || r.height === 0
|
|
345
|
+
? Infinity
|
|
346
|
+
: Math.hypot(Math.max(r.left - x, 0, x - r.right), Math.max(r.top - y, 0, y - r.bottom));
|
|
347
|
+
};
|
|
348
|
+
const nearest = () => {
|
|
349
|
+
let found: { el: Element; far: number } | undefined;
|
|
350
|
+
for (const el of document.querySelectorAll(`[${ATTRIBUTE}]`)) {
|
|
351
|
+
const far = away(el);
|
|
352
|
+
// The later of two as near is the inner one, or the one drawn over.
|
|
353
|
+
if (far !== Infinity && (found === undefined || far <= found.far)) found = { el, far };
|
|
354
|
+
}
|
|
355
|
+
return found?.el;
|
|
356
|
+
};
|
|
357
|
+
const element = hitAt(x, y, true)?.el ?? nearest();
|
|
358
|
+
if (element === undefined) return undefined;
|
|
359
|
+
const r = element.getBoundingClientRect();
|
|
360
|
+
return { element, at: { x: Math.round(x - r.left), y: Math.round(y - r.top) } };
|
|
299
361
|
};
|
|
300
|
-
const show = (
|
|
362
|
+
const show = (glide: boolean) => {
|
|
301
363
|
frame = 0;
|
|
302
|
-
|
|
364
|
+
// On something of ours that takes the pointer (a task's pin, the tool panel): the light stays where it was, as
|
|
365
|
+
// the pointer is on its way to a press there, not to another element.
|
|
366
|
+
if (pointer !== undefined && !picking && held.length > 0 && document.elementFromPoint(pointer.x, pointer.y) === host) {
|
|
367
|
+
if (lit !== undefined) relight();
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const hit = pointer === undefined || (held.length === 0 && !picking) ? undefined : hitAt(pointer.x, pointer.y, picking);
|
|
303
371
|
const el = hit?.el;
|
|
304
372
|
const target = el === undefined ? undefined : targetOf(el);
|
|
305
|
-
if (el === undefined || target === undefined) return hide();
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
place(inner, hit.pointed.getBoundingClientRect());
|
|
311
|
-
inner.classList.add('shown');
|
|
312
|
-
}
|
|
313
|
-
const count = sameAs(el).length;
|
|
314
|
-
// The button, where it isn't the left: what the keys alone don't tell apart.
|
|
315
|
-
const names = held.map(({ tab, shortcut }) => {
|
|
373
|
+
if (el === undefined || target === undefined) return lighting.hide();
|
|
374
|
+
// A plugin's own shortcut says its tab, and its button where it isn't the left, which the keys alone don't tell
|
|
375
|
+
// apart. deictic's own says nothing: it opens whichever tab was used last.
|
|
376
|
+
const names = held.flatMap(({ tab, shortcut, named }) => {
|
|
377
|
+
if (!named) return [];
|
|
316
378
|
const { plugin } = tab();
|
|
317
379
|
const name = plugin.label ?? plugin.name;
|
|
318
|
-
return shortcut.button === 'left' ? name : `${name} (${shortcut.button})
|
|
380
|
+
return [shortcut.button === 'left' ? name : `${name} (${shortcut.button})`];
|
|
319
381
|
});
|
|
320
|
-
|
|
321
|
-
label.textContent = `${names.join(' / ')} · <${target.tag}> ${target.loc.file}:${target.loc.line}${count > 1 ? ` · ×${count}` : ''}${within}`;
|
|
322
|
-
label.classList.toggle('below', el.getBoundingClientRect().top < 24);
|
|
323
|
-
box.classList.add('shown');
|
|
382
|
+
lighting.point({ el, ...(hit?.pointed === undefined ? {} : { pointed: hit.pointed }), target, names, count: sameAs(el).length }, glide);
|
|
324
383
|
};
|
|
325
384
|
const update = (e: MouseEvent | KeyboardEvent) => {
|
|
326
|
-
|
|
327
|
-
if (held.length === 0) return hide();
|
|
328
|
-
|
|
385
|
+
held = heldBy(e);
|
|
386
|
+
if (held.length === 0 && !picking) return hide();
|
|
387
|
+
tools.point(held.length > 0);
|
|
388
|
+
drawer.point(held.length > 0);
|
|
389
|
+
glance(true);
|
|
390
|
+
if (frame === 0) frame = requestAnimationFrame(() => show(true));
|
|
329
391
|
};
|
|
330
392
|
|
|
331
393
|
window.addEventListener(
|
|
@@ -339,6 +401,14 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
339
401
|
window.addEventListener('keydown', update, true);
|
|
340
402
|
window.addEventListener('keyup', update, true);
|
|
341
403
|
window.addEventListener('blur', hide);
|
|
404
|
+
// The page scrolled under the pointer: another element is under it now, or the same one elsewhere.
|
|
405
|
+
window.addEventListener(
|
|
406
|
+
'scroll',
|
|
407
|
+
() => {
|
|
408
|
+
if ((held.length > 0 || picking) && frame === 0) frame = requestAnimationFrame(() => show(false));
|
|
409
|
+
},
|
|
410
|
+
{ capture: true, passive: true },
|
|
411
|
+
);
|
|
342
412
|
let press = {};
|
|
343
413
|
let opened: object | undefined;
|
|
344
414
|
// Alt-click on a link would otherwise download it, and on a field focus it.
|
|
@@ -368,7 +438,7 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
368
438
|
if (panel?.unsaved() === true) return;
|
|
369
439
|
openTab(found.tab(), hit.el, target, undefined, hit.pointed);
|
|
370
440
|
};
|
|
371
|
-
const openTab = (tab: Tab, el: Element, target: Target, resumed?: Resumed, pointed?: Element) => {
|
|
441
|
+
const openTab = (tab: Tab, el: Element, target: Target, resumed?: Resumed, pointed?: Element, at?: Point) => {
|
|
372
442
|
hide();
|
|
373
443
|
panel?.close();
|
|
374
444
|
panel = openPanel({
|
|
@@ -381,14 +451,23 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
381
451
|
remember,
|
|
382
452
|
element: el,
|
|
383
453
|
...(pointed === undefined ? {} : { pointed }),
|
|
454
|
+
...(at === undefined ? {} : { at }),
|
|
384
455
|
target,
|
|
456
|
+
lighting,
|
|
385
457
|
onClose: () => (panel = undefined),
|
|
386
458
|
...(resumed === undefined ? {} : { resumed }),
|
|
387
459
|
reopen: (again, element, kept) => {
|
|
388
460
|
// Rendered again while away, or gone from the page, which moved on: the popup comes back all the same, on
|
|
389
461
|
// the element as it was left, since what it kept (a recording) is about it wherever the page is now.
|
|
390
462
|
const found = element.isConnected ? element : (sameAs(element)[0] ?? element);
|
|
391
|
-
openTab(
|
|
463
|
+
openTab(
|
|
464
|
+
again,
|
|
465
|
+
found,
|
|
466
|
+
targetOf(found) ?? target,
|
|
467
|
+
kept,
|
|
468
|
+
pointed?.isConnected === true && found === element ? pointed : undefined,
|
|
469
|
+
at,
|
|
470
|
+
);
|
|
392
471
|
},
|
|
393
472
|
});
|
|
394
473
|
};
|
|
@@ -404,19 +483,21 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
404
483
|
const { loc, tag } = away.target;
|
|
405
484
|
const absent = document.createElement(tag);
|
|
406
485
|
absent.setAttribute(ATTRIBUTE, `${loc.file}:${loc.line}:${loc.column}`);
|
|
407
|
-
|
|
486
|
+
const found = sameAs(absent).find((el) => el.localName === tag);
|
|
487
|
+
// The spot only where this page has the element: there's nowhere for it otherwise.
|
|
488
|
+
openTab(tab, found ?? absent, away.target, resumed, undefined, found === undefined ? undefined : away.at);
|
|
408
489
|
};
|
|
409
490
|
task.then(
|
|
410
491
|
(result) => back({ state: away.state, result }),
|
|
411
492
|
(e: unknown) => back({ state: away.state, problem: messageOf(e) }),
|
|
412
493
|
);
|
|
413
494
|
});
|
|
414
|
-
function openAt(name: string, given: Element): boolean {
|
|
495
|
+
function openAt(name: string, given: Element, at?: Point): boolean {
|
|
415
496
|
const tab = tabs.find((t) => t.plugin.name === name);
|
|
416
497
|
const el = given.isConnected ? given : (sameAs(given)[0] ?? undefined);
|
|
417
498
|
const target = el === undefined ? undefined : targetOf(el);
|
|
418
499
|
if (tab === undefined || el === undefined || target === undefined) return false;
|
|
419
|
-
openTab(tab, el, target);
|
|
500
|
+
openTab(tab, el, target, undefined, undefined, at);
|
|
420
501
|
return true;
|
|
421
502
|
}
|
|
422
503
|
for (const type of ['click', 'auxclick', 'contextmenu'] as const) window.addEventListener(type, pressed, true);
|
|
@@ -435,9 +516,14 @@ interface PanelOptions {
|
|
|
435
516
|
element: Element;
|
|
436
517
|
/** What was under the pointer inside `element`, where that differs. */
|
|
437
518
|
pointed?: Element;
|
|
519
|
+
/** The spot in `element` it's opened on, where it's one: what's lit, and what it's beside. */
|
|
520
|
+
at?: Point;
|
|
438
521
|
target: Target;
|
|
439
|
-
/**
|
|
440
|
-
|
|
522
|
+
/**
|
|
523
|
+
* Over the page, beside the element: what lights the element there. Without it the popup is shown where the
|
|
524
|
+
* page put it (`popupIn`): nothing on the page is lit, and Esc leaves it alone.
|
|
525
|
+
*/
|
|
526
|
+
lighting?: Lighting;
|
|
441
527
|
/** Called as it closes: the tab it showed, and whether it's leaving for a tab's `away`, to come back by `reopen`. */
|
|
442
528
|
onClose: (shown: Tab, leaving: boolean) => void;
|
|
443
529
|
/** What the first tab's mount gets, coming back from `away`. */
|
|
@@ -456,12 +542,19 @@ function openPanel({
|
|
|
456
542
|
remember,
|
|
457
543
|
element,
|
|
458
544
|
pointed,
|
|
545
|
+
at: spot,
|
|
459
546
|
target,
|
|
460
|
-
|
|
547
|
+
lighting,
|
|
461
548
|
onClose,
|
|
462
549
|
resumed: coming,
|
|
463
550
|
reopen,
|
|
464
|
-
}: PanelOptions): {
|
|
551
|
+
}: PanelOptions): {
|
|
552
|
+
close: () => void;
|
|
553
|
+
unsaved: () => boolean;
|
|
554
|
+
/** Whether it holds something unsaved, whose button it then shakes: what asks before opening another over it. */
|
|
555
|
+
guard: () => boolean;
|
|
556
|
+
} {
|
|
557
|
+
const pinned = lighting === undefined;
|
|
465
558
|
// Given to the first tab's first mount only: another tab, or a remount after an undo, starts afresh.
|
|
466
559
|
let resumed = coming;
|
|
467
560
|
const panel = div('panel');
|
|
@@ -473,8 +566,10 @@ function openPanel({
|
|
|
473
566
|
where.className = 'where';
|
|
474
567
|
const file = document.createElement('span');
|
|
475
568
|
file.textContent = `${target.loc.file}:${target.loc.line}`;
|
|
569
|
+
// What it is too, as the caption said it while pointing, which is gone once the popup is open.
|
|
570
|
+
const tag = Object.assign(document.createElement('span'), { className: 'tag', textContent: tell(named(element)) });
|
|
476
571
|
// An arrow out, as it leaves the page for the editor; its title is the overlay's tooltip (`tooltip.ts`).
|
|
477
|
-
where.append(file);
|
|
572
|
+
where.append(tag, file);
|
|
478
573
|
where.insertAdjacentHTML('beforeend', OUT);
|
|
479
574
|
where.title = 'Open in editor';
|
|
480
575
|
where.setAttribute('aria-label', `Open ${file.textContent} in the editor`);
|
|
@@ -497,10 +592,18 @@ function openPanel({
|
|
|
497
592
|
el.addEventListener('click', () => show(tab));
|
|
498
593
|
return { tab, el };
|
|
499
594
|
});
|
|
500
|
-
|
|
501
|
-
|
|
595
|
+
// What marks the shown tab, behind it, and slides to the next one shown.
|
|
596
|
+
const thumb = div('thumb');
|
|
597
|
+
const slide = (to: HTMLElement) => {
|
|
598
|
+
Object.assign(thumb.style, { left: `${to.offsetLeft}px`, width: `${to.offsetWidth}px` });
|
|
599
|
+
// Laid out where it is before it may move: the first place is no slide from the head's corner.
|
|
600
|
+
void thumb.offsetWidth;
|
|
601
|
+
thumb.classList.add('moves');
|
|
602
|
+
};
|
|
603
|
+
close.classList.add('end');
|
|
604
|
+
head.append(thumb, ...buttons.map((b) => b.el), close);
|
|
502
605
|
bar.append(where, undo, redo);
|
|
503
|
-
// Back from `away` on a page that doesn't have the element: said, as nothing on it is
|
|
606
|
+
// Back from `away` on a page that doesn't have the element: said, as nothing on it is lit.
|
|
504
607
|
if (!element.isConnected)
|
|
505
608
|
where.after(Object.assign(document.createElement('span'), { className: 'absent', textContent: 'not on this page' }));
|
|
506
609
|
const body = div('body');
|
|
@@ -509,8 +612,9 @@ function openPanel({
|
|
|
509
612
|
panel.append(head, bar, body, status);
|
|
510
613
|
root.append(panel);
|
|
511
614
|
if (pinned) panel.classList.add('pinned');
|
|
512
|
-
const release = pinned ? undefined : keepInView(panel, body, head, element);
|
|
513
|
-
|
|
615
|
+
const release = pinned ? undefined : keepInView(panel, body, head, element, spot);
|
|
616
|
+
// Its element, or the spot in it, lit for as long as it's open.
|
|
617
|
+
const unmark = lighting?.hold(element, panel, spot);
|
|
514
618
|
if (!pinned) window.dispatchEvent(new CustomEvent<PopupOpened>(POPUP_OPENED, { detail: { element, tab: first.plugin.name } }));
|
|
515
619
|
|
|
516
620
|
let cleanup: (() => void) | void;
|
|
@@ -638,7 +742,7 @@ function openPanel({
|
|
|
638
742
|
const tab = current;
|
|
639
743
|
done(true);
|
|
640
744
|
// For the tab's next page too, should this one go before the task is done. Not one a page pinned: that's the page's own.
|
|
641
|
-
if (!pinned) keepAway({ tab: tab.plugin.name, target, state });
|
|
745
|
+
if (!pinned) keepAway({ tab: tab.plugin.name, target, state, ...(spot === undefined ? {} : { at: spot }) });
|
|
642
746
|
const back = (resumed: Resumed) => {
|
|
643
747
|
if (!pinned) dropAway();
|
|
644
748
|
reopen(tab, element, resumed);
|
|
@@ -650,13 +754,14 @@ function openPanel({
|
|
|
650
754
|
},
|
|
651
755
|
element,
|
|
652
756
|
...(pointed === undefined ? {} : { pointed }),
|
|
757
|
+
...(spot === undefined ? {} : { at: spot }),
|
|
653
758
|
elements: sameAs(element),
|
|
654
759
|
target,
|
|
655
760
|
model,
|
|
656
|
-
apply: async (op) => {
|
|
761
|
+
apply: async (op, on = target) => {
|
|
657
762
|
say('Writing…');
|
|
658
763
|
try {
|
|
659
|
-
const result = await post<{ model: unknown }>('apply', { plugin: plugin.name, target, op });
|
|
764
|
+
const result = await post<{ model: unknown }>('apply', { plugin: plugin.name, target: on, op });
|
|
660
765
|
say('');
|
|
661
766
|
void steps();
|
|
662
767
|
return result.model;
|
|
@@ -673,75 +778,53 @@ function openPanel({
|
|
|
673
778
|
};
|
|
674
779
|
const show = (tab: Tab) => {
|
|
675
780
|
current = tab;
|
|
676
|
-
for (const b of buttons)
|
|
781
|
+
for (const b of buttons) {
|
|
782
|
+
b.el.setAttribute('aria-selected', String(b.tab === tab));
|
|
783
|
+
if (b.tab === tab) slide(b.el);
|
|
784
|
+
}
|
|
677
785
|
remember(tab);
|
|
678
786
|
void steps();
|
|
679
787
|
void load();
|
|
680
788
|
};
|
|
681
789
|
show(first);
|
|
682
|
-
|
|
790
|
+
const guard = () => {
|
|
791
|
+
if (holding !== undefined) shake(holding);
|
|
792
|
+
return holding !== undefined;
|
|
793
|
+
};
|
|
794
|
+
return { close: done, unsaved: () => holding !== undefined, guard };
|
|
683
795
|
}
|
|
684
796
|
|
|
685
797
|
/** Shakes a panel's button, in view: what a press outside does where closing would lose something. A blink where motion is reduced. */
|
|
686
798
|
function shake(el: HTMLElement): void {
|
|
687
799
|
el.scrollIntoView({ block: 'nearest' });
|
|
688
|
-
if (
|
|
800
|
+
if (reduced()) return void el.animate({ opacity: [1, 0.3, 1, 0.3, 1] }, 400);
|
|
689
801
|
el.animate({ translate: ['0', '-5px', '5px', '-4px', '4px', '-2px', '0'] }, { duration: 360, easing: 'ease-out' });
|
|
690
802
|
}
|
|
691
803
|
|
|
692
|
-
/** Puts an outline over `r`. */
|
|
693
|
-
function place(el: HTMLElement, r: DOMRect): void {
|
|
694
|
-
Object.assign(el.style, { left: `${r.left}px`, top: `${r.top}px`, width: `${r.width}px`, height: `${r.height}px` });
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
/** How far from the element the popup's outline is drawn, in pixels. */
|
|
698
|
-
const ROOM = 4;
|
|
699
|
-
|
|
700
|
-
/**
|
|
701
|
-
* Outlines the element the popup is open on, for as long as it is: which one it's about, where several look alike
|
|
702
|
-
* or the popup covers it. Dashed, with no fill and a little room around the element, so nothing of it is drawn on:
|
|
703
|
-
* a border, a ring or a colour tried on it shows as it is. Read each frame, as the element moves with the page's
|
|
704
|
-
* scrolling, its layout and what a panel previews on it. Answers what removes it.
|
|
705
|
-
*/
|
|
706
|
-
function outline(root: ShadowRoot, element: Element): () => void {
|
|
707
|
-
const box = div('box on');
|
|
708
|
-
root.append(box);
|
|
709
|
-
let frame = 0;
|
|
710
|
-
let was = '';
|
|
711
|
-
const follow = () => {
|
|
712
|
-
frame = requestAnimationFrame(follow);
|
|
713
|
-
const r = element.getBoundingClientRect();
|
|
714
|
-
const now = element.isConnected ? `${r.left},${r.top},${r.width},${r.height}` : '';
|
|
715
|
-
if (now === was) return;
|
|
716
|
-
was = now;
|
|
717
|
-
box.classList.toggle('shown', now !== '');
|
|
718
|
-
place(box, new DOMRect(r.left - ROOM, r.top - ROOM, r.width + 2 * ROOM, r.height + 2 * ROOM));
|
|
719
|
-
};
|
|
720
|
-
follow();
|
|
721
|
-
return () => {
|
|
722
|
-
cancelAnimationFrame(frame);
|
|
723
|
-
box.remove();
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
|
|
727
804
|
const MARGIN = 8;
|
|
728
805
|
// Under this much room on either side, the panel overlaps the element rather than shrink to a sliver beside it.
|
|
729
806
|
const LEAST = 160;
|
|
807
|
+
/** How far from the element the popup is, in pixels: room for the line between them. */
|
|
808
|
+
const APART = 32;
|
|
730
809
|
|
|
731
810
|
/** How far a press on the head moves, in pixels, before it's a drag: a click there leaves the popup following. */
|
|
732
811
|
const SLACK = 3;
|
|
733
812
|
|
|
734
813
|
/**
|
|
735
814
|
* Keeps a panel beside `element` and inside the viewport, as its tabs fill it, the window resizes and the element
|
|
736
|
-
* moves with the page:
|
|
737
|
-
*
|
|
738
|
-
*
|
|
815
|
+
* moves with the page: to its right, or its left, where there's the room, level with its top and as tall as the
|
|
816
|
+
* window lets it be; else below, or above where it fits better, its height capped to the room there, so the body
|
|
817
|
+
* scrolls rather than the panel leaving the window. Off the element either way (`APART`): it's what's lit, with
|
|
818
|
+
* room for the line between them. Dragged by `handle`, it stays where it's put, in the window, and follows the
|
|
819
|
+
* element no more. Fixed, so it never changes the page's own scrolling. Answers a release.
|
|
739
820
|
*/
|
|
740
|
-
function keepInView(panel: HTMLElement, body: HTMLElement, handle: HTMLElement, element: Element): () => void {
|
|
821
|
+
function keepInView(panel: HTMLElement, body: HTMLElement, handle: HTMLElement, element: Element, at?: Point): () => void {
|
|
741
822
|
let frame = 0;
|
|
742
823
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
824
|
+
// What it's beside: the element, or the spot in it.
|
|
825
|
+
const boxOf = () => (at === undefined ? element.getBoundingClientRect() : spotOf(element, at));
|
|
743
826
|
// Where the element was last seen: one gone from the page leaves the popup where it was.
|
|
744
|
-
let r =
|
|
827
|
+
let r = boxOf();
|
|
745
828
|
// An element that's not on the page (back from `away`, on another) has no place to be beside: as if dragged to the
|
|
746
829
|
// middle, toward the top.
|
|
747
830
|
let moved: { left: number; top: number } | undefined = element.isConnected
|
|
@@ -768,26 +851,41 @@ function keepInView(panel: HTMLElement, body: HTMLElement, handle: HTMLElement,
|
|
|
768
851
|
}
|
|
769
852
|
const top = Math.min(Math.max(r.top, 0), height);
|
|
770
853
|
const bottom = Math.min(Math.max(r.bottom, 0), height);
|
|
771
|
-
const
|
|
772
|
-
const
|
|
854
|
+
const gap = APART;
|
|
855
|
+
const right = width - MARGIN - panel.offsetWidth - (r.right + gap);
|
|
856
|
+
const left = r.left - gap - panel.offsetWidth - MARGIN;
|
|
857
|
+
if (right >= 0 || left >= 0) {
|
|
858
|
+
const room = Math.max(0, height - 2 * MARGIN);
|
|
859
|
+
Object.assign(panel.style, {
|
|
860
|
+
left: `${right >= 0 ? r.right + gap : r.left - gap - panel.offsetWidth}px`,
|
|
861
|
+
top: `${Math.max(MARGIN, Math.min(r.top - CLEAR, height - MARGIN - Math.min(wanted, room)))}px`,
|
|
862
|
+
maxHeight: `${room}px`,
|
|
863
|
+
// It grows out of the side the element is on, as it opens.
|
|
864
|
+
transformOrigin: right >= 0 ? '0 24px' : '100% 24px',
|
|
865
|
+
});
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
const below = height - bottom - gap - MARGIN;
|
|
869
|
+
const above = top - gap - MARGIN;
|
|
773
870
|
const cap = Math.max(0, Math.min(height * 0.6, height - 2 * MARGIN));
|
|
774
871
|
let at: number;
|
|
775
872
|
let room: number;
|
|
776
873
|
if (Math.max(below, above) < LEAST) {
|
|
777
874
|
room = height - 2 * MARGIN;
|
|
778
|
-
at = Math.min(Math.max(bottom +
|
|
875
|
+
at = Math.min(Math.max(bottom + gap, MARGIN), height - MARGIN - Math.min(wanted, room));
|
|
779
876
|
} else if (wanted <= below || below >= above) {
|
|
780
877
|
room = Math.min(below, cap);
|
|
781
|
-
at = bottom +
|
|
878
|
+
at = bottom + gap;
|
|
782
879
|
} else {
|
|
783
880
|
room = Math.min(above, cap);
|
|
784
|
-
at = top -
|
|
881
|
+
at = top - gap - Math.min(wanted, room);
|
|
785
882
|
}
|
|
786
883
|
Object.assign(panel.style, {
|
|
787
884
|
left: `${Math.max(MARGIN, Math.min(r.left, width - MARGIN - panel.offsetWidth))}px`,
|
|
788
885
|
top: `${at}px`,
|
|
789
886
|
bottom: '',
|
|
790
887
|
maxHeight: `${room}px`,
|
|
888
|
+
transformOrigin: at < top ? '24px 100%' : '24px 0',
|
|
791
889
|
});
|
|
792
890
|
};
|
|
793
891
|
// Not in the observers' callbacks, where a change of size is a "ResizeObserver loop" error on the page. The next
|
|
@@ -802,7 +900,7 @@ function keepInView(panel: HTMLElement, body: HTMLElement, handle: HTMLElement,
|
|
|
802
900
|
if (moved !== undefined) return;
|
|
803
901
|
watching = requestAnimationFrame(watch);
|
|
804
902
|
if (!element.isConnected) return;
|
|
805
|
-
const now =
|
|
903
|
+
const now = boxOf();
|
|
806
904
|
if (now.left === r.left && now.top === r.top && now.width === r.width && now.height === r.height) return;
|
|
807
905
|
r = now;
|
|
808
906
|
fit();
|
|
@@ -851,12 +949,6 @@ function keepInView(panel: HTMLElement, body: HTMLElement, handle: HTMLElement,
|
|
|
851
949
|
};
|
|
852
950
|
}
|
|
853
951
|
|
|
854
|
-
function div(className: string): HTMLDivElement {
|
|
855
|
-
const el = document.createElement('div');
|
|
856
|
-
el.className = className;
|
|
857
|
-
return el;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
952
|
/** A button that is a drawing: named for what it does, as its title, the tooltip, changes with what it would do. */
|
|
861
953
|
function iconButton(svg: string, name: string, title: string): HTMLButtonElement {
|
|
862
954
|
const el = button('', title);
|