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.
Files changed (90) hide show
  1. package/API.md +136 -30
  2. package/README.md +4 -3
  3. package/dist/annotations/client.d.ts +1 -1
  4. package/dist/annotations/client.d.ts.map +1 -1
  5. package/dist/annotations/client.js +161 -176
  6. package/dist/annotations/client.js.map +1 -1
  7. package/dist/annotations/index.d.ts +2 -11
  8. package/dist/client/index.d.ts +7 -6
  9. package/dist/client/index.d.ts.map +1 -1
  10. package/dist/client/index.js +1007 -192
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/index.d.ts +2 -2
  13. package/dist/recommended/index.d.ts +2 -2
  14. package/dist/recordings/client.d.ts.map +1 -1
  15. package/dist/recordings/client.js +82 -153
  16. package/dist/recordings/client.js.map +1 -1
  17. package/dist/screenshots/client.d.ts.map +1 -1
  18. package/dist/shared/annotations.js +3 -4
  19. package/dist/shared/annotations.js.map +1 -1
  20. package/dist/shared/board.js +1 -1
  21. package/dist/shared/client.js +45 -2
  22. package/dist/shared/client.js.map +1 -1
  23. package/dist/shared/component.js +62 -0
  24. package/dist/shared/component.js.map +1 -0
  25. package/dist/shared/dom.js +79 -0
  26. package/dist/shared/dom.js.map +1 -0
  27. package/dist/shared/drawer.js +217 -0
  28. package/dist/shared/drawer.js.map +1 -0
  29. package/dist/shared/index.d.ts +116 -7
  30. package/dist/shared/index.d.ts.map +1 -1
  31. package/dist/shared/index2.d.ts +9 -19
  32. package/dist/shared/index2.d.ts.map +1 -1
  33. package/dist/shared/index7.d.ts +103 -26
  34. package/dist/shared/index7.d.ts.map +1 -1
  35. package/dist/shared/index9.d.ts +1 -1
  36. package/dist/shared/integration.d.ts +1 -1
  37. package/dist/shared/packages.js +1 -1
  38. package/dist/shared/recording.js +31 -3
  39. package/dist/shared/recording.js.map +1 -1
  40. package/dist/shared/src.js.map +1 -1
  41. package/dist/shared/task.js +44 -29
  42. package/dist/shared/task.js.map +1 -1
  43. package/dist/shared/tasks.js +232 -62
  44. package/dist/shared/tasks.js.map +1 -1
  45. package/dist/shared/vb.js +1 -1
  46. package/dist/shared/voice2.js +6 -4
  47. package/dist/shared/voice2.js.map +1 -1
  48. package/dist/shared/watch.js +14 -14
  49. package/dist/shared/watch.js.map +1 -1
  50. package/dist/tasks/client.d.ts +2 -2
  51. package/dist/tasks/client.d.ts.map +1 -1
  52. package/dist/tasks/client.js +1829 -741
  53. package/dist/tasks/client.js.map +1 -1
  54. package/dist/tasks/index.d.ts +2 -2
  55. package/dist/voice/client.d.ts.map +1 -1
  56. package/dist/voice/client.js +154 -57
  57. package/dist/voice/client.js.map +1 -1
  58. package/package.json +1 -1
  59. package/skills/deictic/SKILL.md +22 -28
  60. package/src/cli/recording.ts +34 -3
  61. package/src/cli/task.ts +59 -30
  62. package/src/cli/voice.ts +9 -4
  63. package/src/cli/watch.ts +14 -13
  64. package/src/client/away.ts +3 -1
  65. package/src/client/component.ts +98 -0
  66. package/src/client/dom.ts +70 -0
  67. package/src/client/drawer.ts +258 -0
  68. package/src/client/index.ts +220 -128
  69. package/src/client/lightbox.ts +8 -8
  70. package/src/client/lighting.ts +279 -0
  71. package/src/client/style.ts +263 -44
  72. package/src/client/tools.ts +279 -0
  73. package/src/client/tooltip.ts +25 -5
  74. package/src/client/tray.ts +48 -0
  75. package/src/index.ts +113 -6
  76. package/src/plugins/annotations/client.ts +103 -129
  77. package/src/plugins/annotations/draw.ts +68 -72
  78. package/src/plugins/annotations/index.ts +12 -19
  79. package/src/plugins/recordings/client.ts +89 -167
  80. package/src/plugins/screenshots/client.ts +53 -2
  81. package/src/plugins/tasks/client.ts +219 -748
  82. package/src/plugins/tasks/composer.ts +797 -0
  83. package/src/plugins/tasks/drawer.ts +516 -0
  84. package/src/plugins/tasks/index.ts +360 -82
  85. package/src/plugins/tasks/pins.ts +275 -0
  86. package/src/plugins/tasks/store.ts +132 -0
  87. package/src/plugins/voice/client.ts +96 -5
  88. package/skills/deictic/references/recordings.md +0 -13
  89. package/skills/deictic/references/tasks.md +0 -22
  90. package/skills/deictic/references/watch.md +0 -17
@@ -1,162 +1,69 @@
1
1
  /**
2
- * The tasks panel: the tasks already about this element and their state, and a field to add one. Each
3
- * task's ID opens it on the board, where the board has a page; one no one has claimed yet can be edited
4
- * in place (its words) or deleted (canceled on the board), both changes the popup's undo takes back.
5
- * Beside the channel it says who watches it (`Model.watching`), or that no agent does.
6
- * Ctrl+Enter or Add sends it with the page's URL, the viewport and the element as it rendered, which
7
- * the source can't tell: the chain of source it rendered through, its HTML (a file attached), and where the
8
- * annotations plugin is loaded, what's marked on the page.
2
+ * The Task tab: a composer to add a task about the element with (`composer.ts`). The tasks there already are the
3
+ * drawer's to list and open (`drawer.ts`), and the pins' to show on the page. Beside the channel it says who watches
4
+ * it (`Model.watching`), or that no agent does.
5
+ * Enter or the arrow sends it with the page's URL, the viewport and the element as it rendered, which the source
6
+ * can't tell: the chain of source it rendered through, its HTML (a file attached), and where the annotations plugin
7
+ * is loaded, what's marked on the page. Record leaves the popup (`away`) to record the page, and comes back with
8
+ * what was typed when it's stopped, wherever the page is by then.
9
9
  *
10
- * Where the screenshots plugin is loaded, a shot of the page goes with it, unless that's unticked, the element
11
- * outlined in it as the task goes: nothing else says which of two rows alike was meant (a shot drawn on is
12
- * left as it was drawn). With
13
- * the annotations plugin too, Annotate takes the shot now and opens it to draw on: saved, it's a chip
14
- * under the field, which opens it again to change the marks, and Add another takes one more. Any chip
15
- * (a recording's too) takes the box's place; removing the last brings it back unticked, so a task goes
16
- * without a shot unless asked again.
17
- *
18
- * The element's HTML as it rendered goes with it too, as a file, unless its box is unticked (or the server
19
- * half's `html` option is off, and then there's no box).
20
- *
21
- * Where the recordings plugin is loaded, Record leaves the popup (`away`) to record the page, keeping
22
- * what's typed and attached, and comes back with the recording as a chip too, which plays it back.
23
- * Where the voice plugin is, Voice records the mic here in the panel: stopped, it's a chip that plays it.
10
+ * Its tool in the panel adds a task about a spot: picked, the next press on the page opens this tab on that point,
11
+ * in the marked element under it or the nearest to it.
24
12
  */
25
- import { liveWaveform } from '#src/client/waveform.ts';
26
- import { defineClientPlugin, type LightboxItem, type Target } from '#src/index.ts';
13
+ import { componentOf, fiberOf, ownerOf } from '#src/client/component.ts';
14
+ import { sameAs, toolButton } from '#src/client/dom.ts';
15
+ import { defineClientPlugin, type Target } from '#src/index.ts';
27
16
 
28
- // For `use()`'s types: the plugins may not be loaded, and nothing of them runs here.
29
- import type { Annotation, Annotations, Picture } from '#src/plugins/annotations/index.ts';
30
- import type { Recording } from '#src/plugins/recordings/index.ts';
31
- import type { Shot } from '#src/plugins/screenshots/index.ts';
32
- import type { Clip, Take } from '#src/plugins/voice/index.ts';
33
-
34
- import type { Change, Marks, Model, Op, Task, TaskAdded } from './index.ts';
17
+ import { type About, atOf, attachedOf, COMPOSER_STYLE, composerIn, type Draft, element, onPage, type Seen } from './composer.ts';
18
+ import { drawerOf } from './drawer.ts';
19
+ import type { Model, Op, TaskAdded } from './index.ts';
20
+ import { pinsIn } from './pins.ts';
21
+ import { storeOf } from './store.ts';
35
22
 
36
23
  const STYLE = `
37
- /* The column is no wider than the panel: an \`auto\` one grows to a long title, which then never truncates. */
38
- .tasks { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
39
- /* Five rows, and the rest scrolled to: the field stays where it is however many there are. */
40
- .tasks { max-height: 112px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--deictic-line) transparent; }
41
- /* A task's words being changed need the room. */
42
- .tasks:has(.editing) { max-height: none; }
43
- .tasks li { position: relative; display: flex; gap: 6px; align-items: baseline; }
44
- .tasks .title { flex: 1; min-width: 0; padding: 0; border: 0; border-radius: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
45
- /* Clicked, a task reads whole, as it was typed. */
46
- .tasks li.whole .title { white-space: pre-wrap; overflow-wrap: anywhere; }
47
- /* The state is a dot, named by its tooltip: a ring while no one has it, filled once someone does or it's over. */
48
- .tasks .state { flex: none; align-self: center; box-sizing: border-box; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--deictic-muted); }
49
- /* Room for Edit and Delete, which would lie over the first line's end. */
50
- .tasks li.whole:has(.acts) .title { padding-right: 40px; }
51
- .tasks li.whole .state { align-self: baseline; }
52
- .tasks .state.waiting { border-style: dotted; }
53
- .tasks .state.claimed { border-color: #60a5fa; background: #60a5fa; }
54
- .tasks .state.blocked { border-color: #fbbf24; background: #fbbf24; }
55
- .tasks .state.completed { border-color: #4ade80; background: #4ade80; }
56
- .tasks .state.failed { border-color: var(--deictic-problem); background: var(--deictic-problem); }
57
- .tasks a { color: inherit; text-decoration: none; }
58
- .tasks a:hover { text-decoration: underline; }
59
- /* Over the row's end, and only while the row is pointed at or focused in: the title keeps the width. */
60
- .tasks .acts { position: absolute; inset: 0 0 auto auto; min-height: 18px; display: none; align-items: center; padding-left: 14px; background: linear-gradient(to right, transparent, var(--deictic-bg) 12px); }
61
- .tasks li:hover .acts, .tasks li:focus-within .acts { display: flex; }
62
- .tasks .act { display: inline-flex; padding: 2px; border: 0; color: var(--deictic-muted); }
63
- .tasks .act:hover { color: var(--deictic-fg); }
64
- .tasks .act svg { width: 12px; height: 12px; }
65
- .tasks .place { flex: none; padding: 0; border: 0; font: 11px ui-monospace, monospace; color: var(--deictic-muted); }
66
- .tasks button.place:hover { color: var(--deictic-fg); text-decoration: underline; }
67
- .more { margin: 0 0 8px; }
68
- .more[hidden] { display: none; }
69
- .more summary { cursor: pointer; font-size: 12px; color: var(--deictic-muted); }
70
- .more summary:hover { color: var(--deictic-fg); }
71
- .more .tasks { margin: 4px 0 0; }
72
- .tasks li.editing { display: grid; }
73
- .tasks li.editing .row { margin-top: 0; }
74
- .tasks li.editing .actions { display: flex; gap: 6px; }
75
- textarea { min-height: 64px; resize: vertical; font: 13px/1.4 system-ui, sans-serif; }
24
+ .compose { flex: none; }
76
25
  .row { display: flex; gap: 6px; margin-top: 8px; justify-content: space-between; align-items: center; }
77
- /* Cut short before it pushes Add out: a channel's name and its watchers' may be long. */
26
+ /* Cut short: a channel's name and its watchers' may be long. */
78
27
  .hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--deictic-muted); font-size: 12px; }
79
28
  /* A dot as a task's state is: a ring while no one watches, green while someone does. */
80
29
  .watch::before { content: ''; display: inline-block; box-sizing: border-box; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; border: 1.5px solid var(--deictic-muted); }
81
30
  .watch.on::before { border-color: #4ade80; background: #4ade80; }
82
31
  .hint a { color: inherit; }
83
32
  .hint a:hover { color: var(--deictic-fg); }
84
- .shot { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--deictic-muted); }
85
- .shot label { display: flex; gap: 6px; align-items: center; }
86
- .shot input { width: auto; margin: 0; }
87
- .shot .actions { display: flex; gap: 6px; margin-left: auto; }
88
- .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; font-size: 12px; }
89
- .chip { display: inline-flex; align-items: center; border: 1px solid var(--deictic-line); border-radius: 6px; }
90
- .chip button { border: 0; }
91
- .chip .open { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 2px; }
92
- .chip img { display: block; height: 28px; border-radius: 4px; }
93
- .chip .play { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 4px; background: var(--deictic-line); }
94
- .chip .play svg { width: 12px; height: 12px; }
95
- .chip .remove { padding: 0 6px; color: var(--deictic-muted); }
96
- .chip .remove:hover { color: var(--deictic-fg); }
97
- .voice-on { display: inline-flex; align-items: center; gap: 4px; color: #fff; background: #ef4444; border-color: #ef4444; font-variant-numeric: tabular-nums; }
98
- .voice-on .wave { width: 36px; height: 14px; }
99
- .shot-problem { margin-top: 4px; font-size: 12px; color: var(--deictic-problem); }
100
- .shot-problem:empty { display: none; }
101
- .shot[hidden], .chips[hidden], label[hidden] { display: none; }
102
- `;
103
-
104
- const ICON = (path: string) =>
105
- `<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="${path}"/></svg>`;
106
- const EDIT = ICON('M4 20h4L19 9l-4-4L4 16z');
107
- const DELETE = ICON('M4 7h16M10 7V4h4v3M6 7l1 13h10l1-13');
108
- /** The states of a task that's over, as a board names them: nothing more happens to it. */
109
- const OVER = new Set(['completed', 'failed']);
110
- const PLAY = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 4v16l13-8z" fill="currentColor"/></svg>';
111
-
112
- /** Marks as a task tells of them: how many, and what the notes say. */
113
- function marksOf(list: readonly Annotation[]): Marks {
114
- return { count: list.length, notes: list.flatMap(({ shape }) => (shape.kind === 'note' ? [shape.text] : [])) };
115
- }
116
-
117
- /** The page's annotations for the op, where there are any. */
118
- function annotationsOf(marks: Annotations | undefined): Pick<Op, 'annotations'> {
119
- const list = marks?.list() ?? [];
120
- return list.length === 0 ? {} : { annotations: marksOf(list) };
121
- }
122
-
123
- /** An annotated shot: the shot as taken, the marks drawn on it, and the PNG of both. */
124
- interface Drawn {
125
- shot: Shot;
126
- marks: Annotation[];
127
- png: Blob;
128
- }
129
-
130
- /** A drawn shot as the panel shows it, with a URL for its thumbnail, revoked with it. */
131
- interface Chip extends Drawn {
132
- url: string;
33
+ ${COMPOSER_STYLE}`;
34
+
35
+ const TOOL_STYLE = `
36
+ .task-tool button { position: relative; }
37
+ .task-tool .count {
38
+ position: absolute;
39
+ top: -5px;
40
+ right: -5px;
41
+ box-sizing: border-box;
42
+ min-width: 15px;
43
+ height: 15px;
44
+ padding: 0 4px;
45
+ border-radius: 8px;
46
+ font: 700 10px/15px system-ui, sans-serif;
47
+ color: var(--deictic-on-accent);
48
+ background: var(--deictic-accent);
133
49
  }
50
+ .task-tool button[aria-pressed='true'] .count { color: var(--deictic-fg); background: #09090b; }
51
+ `;
52
+ /** A note with a plus: a task to add. */
53
+ const TASK = '<path d="M4 5h16v11H9l-5 4zM12 8v5M9.5 10.5h5"/>';
134
54
 
135
- /** What the panel keeps while it's away recording: what's typed, ticked and attached. */
55
+ /** What the panel keeps while it's away recording: what's typed and asked for. What's attached is the tray's. */
136
56
  interface Kept {
137
57
  text: string;
138
- attach: boolean;
58
+ /** Whether a shot was asked for, or asked not to be, where either was. */
59
+ shot?: boolean;
139
60
  html: boolean;
140
- drawn: Drawn[];
141
- recordings: Recording[];
142
- voices: Clip[];
143
- /** What the page said of the element as the panel left, for a task added where the page no longer has it. */
144
- facts: Facts;
61
+ /** The page as the panel left, and its elements as that page had them: for a task added where the page has moved on. */
62
+ page: string;
63
+ viewport: Op['viewport'];
64
+ about: { target: Target; own: boolean; seen: Seen }[];
145
65
  }
146
66
 
147
- /** What a task says that only the page with the element on it knows. */
148
- type Facts = Pick<Op, 'page' | 'viewport' | 'pointed' | 'count' | 'chain'> & {
149
- /** The element's HTML, as it would be attached. */
150
- html: string;
151
- };
152
-
153
- const clock = (ms: number) => {
154
- const s = Math.round(ms / 1000);
155
- return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
156
- };
157
-
158
- const messageOf = (e: unknown) => (e instanceof Error ? e.message : String(e));
159
-
160
67
  /**
161
68
  * `#shadow-root > div.panel > div.head > button.tab:nth-of-type(2)`: where `inner` is inside `outer`, through
162
69
  * shadow roots, by tag, classes and, among siblings alike, place, for whoever finds it in the code.
@@ -192,39 +99,6 @@ const parentOf = (el: Element): Element | undefined => {
192
99
  /** How many places a chain names after the element's own: who uses it, and who uses that. Further out is the app's shell. */
193
100
  const CHAIN = 3;
194
101
 
195
- /**
196
- * What React keeps, in development, of who wrote an element: a fiber (its `type` the component), or for a server
197
- * component its `name`. Each has the one that wrote it in turn.
198
- */
199
- interface Owner {
200
- name?: unknown;
201
- type?: unknown;
202
- alternate?: Owner | null;
203
- owner?: Owner | null;
204
- _debugOwner?: Owner | null;
205
- }
206
-
207
- /** React's fiber of an element it rendered, which it keeps on the element under a key of its own. */
208
- const fiberOf = (el: Element): Owner | undefined => {
209
- const key = Object.keys(el).find((k) => k.startsWith('__reactFiber$'));
210
- return key === undefined ? undefined : (el as unknown as Record<string, Owner>)[key];
211
- };
212
-
213
- const ownerOf = (of: Owner | undefined): Owner | undefined => of?._debugOwner ?? of?.owner ?? undefined;
214
-
215
- /** A component's name, through `memo` and `forwardRef`, or nothing for one written without. */
216
- function componentOf(owner: Owner): string | undefined {
217
- if (typeof owner.name === 'string') return owner.name === '' ? undefined : owner.name;
218
- let type = owner.type as { displayName?: unknown; name?: unknown; render?: unknown; type?: unknown } | null | undefined;
219
- for (let depth = 0; depth < 4 && type !== null && type !== undefined; depth++) {
220
- // A function's own name, where it has no `displayName`; a `memo` or `forwardRef` object has neither.
221
- const name = type.displayName ?? type.name;
222
- if (typeof name === 'string' && name !== '') return name;
223
- type = (type.render ?? type.type) as typeof type;
224
- }
225
- return undefined;
226
- }
227
-
228
102
  /**
229
103
  * The source `el` rendered through, after its own place, nearest first: a shared component's own line is the same
230
104
  * wherever it's used, and the change is most often in what uses it, or in what uses that.
@@ -270,51 +144,13 @@ function chainOf(el: Element, file: string): NonNullable<Op['chain']> {
270
144
  /** What's sent of the element's HTML at most, in characters: the server attaches it as a file. */
271
145
  const HTML = 100_000;
272
146
 
273
- /** The overlay's own green, as its outline of the element while the popup is open. */
274
- const OUTLINE = '#12b358';
275
- /** CSS pixels between the element and its outline, so the dashes are on nothing of the element's. */
276
- const ROOM = 3;
277
-
278
- /**
279
- * A shot's PNG with the element outlined in it: dashes around its box, with nothing between them, as the overlay
280
- * draws it. The shot may have more pixels than its size in CSS ones, which the box is in.
281
- */
282
- async function outlined(png: Blob | string, { box, size }: Pick<Shot, 'box' | 'size'>): Promise<Blob> {
283
- const url = typeof png === 'string' ? png : URL.createObjectURL(png);
284
- try {
285
- const image = new Image();
286
- image.src = url;
287
- await image.decode();
288
- const canvas = element('canvas', { width: image.naturalWidth, height: image.naturalHeight });
289
- const ctx = canvas.getContext('2d');
290
- if (ctx === null) throw new Error("tasks: this browser won't draw to a canvas");
291
- ctx.drawImage(image, 0, 0);
292
- const k = image.naturalWidth / size.width;
293
- const rect = [(box.x - ROOM) * k, (box.y - ROOM) * k, (box.width + 2 * ROOM) * k, (box.height + 2 * ROOM) * k] as const;
294
- ctx.lineWidth = 2 * k;
295
- ctx.strokeStyle = OUTLINE;
296
- ctx.setLineDash([6 * k, 4 * k]);
297
- ctx.strokeRect(...rect);
298
- return await new Promise<Blob>((done, fail) =>
299
- canvas.toBlob((blob) => (blob === null ? fail(new Error('tasks: the screenshot drew nothing')) : done(blob)), 'image/png'),
300
- );
301
- } finally {
302
- if (typeof png !== 'string') URL.revokeObjectURL(url);
303
- }
304
- }
305
-
306
- function element<K extends keyof HTMLElementTagNameMap>(tag: K, props: Partial<HTMLElementTagNameMap[K]> = {}): HTMLElementTagNameMap[K] {
307
- return Object.assign(document.createElement(tag), props);
308
- }
309
-
310
147
  /** The event the page hears of each added task by, on `window`: its `detail` is a `TaskAdded`. */
311
148
  export const TASK_ADDED = 'deictic:task';
312
149
 
313
150
  /** Tells the page of a task just added: the newest of the element's tasks, as the board answered them. */
314
- function announce(model: Model, op: Op, target: Target): void {
151
+ function announce(model: Model, op: Op, target: Target, shots: string[]): void {
315
152
  const task = model.tasks.at(-1);
316
153
  if (task === undefined) return;
317
- const marks = (op.annotations?.count ?? 0) + (op.screenshots ?? []).reduce((n, shot) => n + (shot.marks?.count ?? 0), 0);
318
154
  const detail: TaskAdded = {
319
155
  id: task.id,
320
156
  title: task.title,
@@ -326,583 +162,218 @@ function announce(model: Model, op: Op, target: Target): void {
326
162
  screenshots: op.screenshots?.length ?? 0,
327
163
  recordings: op.recordings?.length ?? 0,
328
164
  voice: op.voice?.length ?? 0,
329
- marks,
165
+ marks: (op.annotations?.count ?? 0) + (op.screenshots ?? []).reduce((n, shot) => n + (shot.marks?.count ?? 0), 0),
330
166
  },
167
+ screenshots: shots,
331
168
  };
332
169
  window.dispatchEvent(new CustomEvent(TASK_ADDED, { detail }));
333
170
  }
334
171
 
335
- export default defineClientPlugin<Model, Change>({
172
+ export default defineClientPlugin<Model, Op>({
336
173
  name: 'tasks',
337
174
  label: 'Task',
338
- // All the panel leaves for is a recording, which a page load doesn't end.
175
+ // Its tool in the tool panel, after the others': what takes what they made. Picked, the next press on the page
176
+ // opens the tab on that spot.
177
+ setup: (context) => {
178
+ const { tools, tray } = context;
179
+ // The tasks there already, in the drawer.
180
+ drawerOf(context);
181
+ const group = element('div', { className: 'tool-group task-tool' });
182
+ let picking = false;
183
+ const button = toolButton(TASK, 'Task', 'T', () => {
184
+ if (picking) return;
185
+ picking = true;
186
+ button.setAttribute('aria-pressed', 'true');
187
+ void tools.pick().then((spot) => {
188
+ picking = false;
189
+ button.setAttribute('aria-pressed', 'false');
190
+ if (spot !== undefined) context.open('tasks', spot.element, spot.at);
191
+ });
192
+ });
193
+ button.setAttribute('aria-pressed', 'false');
194
+ // How much is in the tray, for the task to take.
195
+ const count = element('span', { className: 'count' });
196
+ const counted = () => {
197
+ const held = tray.list().length;
198
+ count.textContent = String(held);
199
+ count.hidden = held === 0;
200
+ };
201
+ tray.subscribe(counted);
202
+ counted();
203
+ button.append(count);
204
+ group.append(element('style', { textContent: TOOL_STYLE }), button);
205
+ // After the other tools that capture the page, as it takes what they made.
206
+ tools.add(group, { section: 'capture', last: true });
207
+ },
208
+ // What the page before this left the tab for: a recording, where it carries on here.
339
209
  resume: ({ use }) => use('recordings')?.going(),
210
+ // The page's tasks, where they are, while it's pointed on.
211
+ pointing: (context) => pinsIn(context).glance(),
340
212
  mount: (panel, context) => {
341
213
  const style = element('style', { textContent: STYLE });
342
- const list = element('ul', { className: 'tasks' });
343
- const text = element('textarea', { placeholder: 'What should change here?' });
344
- const add = element('button', { type: 'button', className: 'primary', textContent: 'Add task' });
345
214
  const hint = element('span', { className: 'hint' });
346
215
  const row = element('div', { className: 'row' });
347
- row.append(hint, add);
348
- // The file's other tasks, folded away: the panel is about this element. It stays as it's left while the panel is up.
349
- const fold = element('details', { className: 'more' });
350
- const count = element('summary');
351
- const others = element('ul', { className: 'tasks' });
352
- fold.append(count, others);
353
- // The element's tasks that are over, folded away too: what's still to do is what's read first.
354
- const closed = element('details', { className: 'more' });
355
- const closedCount = element('summary');
356
- const ended = element('ul', { className: 'tasks' });
357
- closed.append(closedCount, ended);
358
- panel.append(style, list, closed, fold, text);
216
+ row.append(hint);
217
+ // The page's tasks, pinned where they are, while the tab is open too: not for a popup a page shows in place,
218
+ // which is in a root of its own.
219
+ const over = panel.getRootNode() === context.root;
220
+ const unpin = over ? pinsIn(context).glance() : undefined;
359
221
 
360
222
  const shots = context.use('screenshots');
361
- // Back from a recording that went on to a page without the element: there's nothing here to take a shot of.
362
- const here = context.element.isConnected;
363
- const notes = context.use('annotations');
364
223
  const recorder = context.use('recordings');
365
- const voice = context.use('voice');
366
- // The server half's `html` option, which takes the box away; a page half with no options (a `standalone` server's) has it.
224
+ const back = context.resumed;
225
+ // The server half's `html` option, which takes the button away; a page half with no options (a `standalone` server's) has it.
367
226
  const sendsHtml = (context.options as { html?: boolean } | undefined)?.html !== false;
368
- // Closes an open editor with the panel.
369
- const aborts = new AbortController();
370
-
371
- const attach = element('input', { type: 'checkbox', checked: true });
372
- const toggle = element('label', { hidden: shots === undefined || !here });
373
- toggle.append(attach, 'Attach a screenshot');
374
- const annotate = element('button', { type: 'button', textContent: 'Annotate', title: 'Take the screenshot now and draw on it' });
375
- const record = element('button', {
376
- type: 'button',
377
- textContent: 'Record',
378
- title: 'Record the page, with a toolbar to draw on it, then come back here',
379
- });
380
- const speak = element('button', { type: 'button', textContent: 'Voice', title: 'Record your voice, here' });
381
- const actions = element('span', { className: 'actions' });
382
- actions.append(...(shots !== undefined && notes !== undefined && here ? [annotate] : []));
383
- const shot = element('div', { className: 'shot' });
384
- shot.append(toggle, actions);
385
- const chipsEl = element('div', { className: 'chips' });
386
- const another = element('button', { type: 'button', textContent: 'Add another', title: 'Take another screenshot and draw on it' });
387
- const problem = element('div', { className: 'shot-problem' });
388
- if (shots !== undefined || recorder !== undefined || voice !== undefined) panel.append(shot, chipsEl, problem);
389
- // Its own line: the screenshot's gives way to the chips, and this is asked whatever else is attached.
390
- const withHtml = element('input', { type: 'checkbox', checked: true });
391
- const htmlToggle = element('label', { title: 'The element as the page has it now, as a file: element.html' });
392
- htmlToggle.append(withHtml, 'Attach HTML snapshot');
393
- const htmlRow = element('div', { className: 'shot' });
394
- htmlRow.append(htmlToggle);
395
- if (sendsHtml) panel.append(htmlRow);
396
- panel.append(row);
227
+ const own = (): About[] => [{ target: context.target, own: true, el: context.element }];
397
228
 
398
- let chips: Chip[] = [];
399
- let recordings: Recording[] = [];
400
- let voices: Clip[] = [];
401
- let busy = false;
402
- const attachedCount = () => chips.length + recordings.length + voices.length;
403
- // A task goes with words, or with something attached that says it; not while one is going.
404
- let sending = false;
405
- const able = () => (add.disabled = sending || (text.value.trim() === '' && attachedCount() === 0));
406
- // Record and Voice, where their plugins are: beside Annotate, or after the chips while the box is away.
407
- const more = () => [...(recorder !== undefined ? [record] : []), ...(voice !== undefined ? [speak] : [])];
408
- const chip = (content: (string | Node)[], title: string, at: number, remove: string, drop: () => void) => {
409
- const opener = element('button', { type: 'button', className: 'open', title });
410
- opener.append(...content);
411
- // Every attachment in one lightbox, opened at this one, growing out of its chip.
412
- opener.addEventListener('click', () => context.lightbox(viewed(), { at, from: el }));
413
- const remover = element('button', { type: 'button', className: 'remove', textContent: '×', title: remove });
414
- remover.addEventListener('click', drop);
415
- const el = element('span', { className: 'chip' });
416
- el.append(opener, remover);
417
- return el;
418
- };
419
- const shotName = (i: number) => `Screenshot ${i + 1}`;
420
- const recordingName = (i: number) => (recordings.length === 1 ? 'Recording' : `Recording ${i + 1}`);
421
- const voiceName = (i: number) => (voices.length === 1 ? 'Voice' : `Voice ${i + 1}`);
422
- /** What's attached, as the lightbox shows it, in the chips' order. */
423
- const viewed = (): LightboxItem[] => [
424
- ...chips.map((c, i) => ({
425
- kind: 'image' as const,
426
- url: c.url,
427
- title: shotName(i),
428
- actions: [{ label: 'Change marks', title: 'Draw on it again', run: () => void draw(c) }],
429
- })),
430
- ...recordings.map((r, i) => ({
431
- kind: 'page' as const,
432
- // The replay filling the frame, without a header of its own: the lightbox names it.
433
- url: `${r.url}${r.url.includes('?') ? '&' : '?'}embed`,
434
- title: `${recordingName(i)} · ${clock(r.duration)}`,
435
- actions: [
436
- { label: 'New tab', title: 'Play it back in a tab of its own', run: () => void window.open(r.url, '_blank', 'noopener') },
437
- ],
438
- })),
439
- ...voices.map((v, i) => ({ kind: 'audio' as const, url: v.url, title: `${voiceName(i)} · ${clock(v.duration)}` })),
440
- ];
441
- const showChips = () => {
442
- // The box stands for a shot taken as the task goes, so it's away while anything else is attached.
443
- const attached = attachedCount() > 0;
444
- shot.hidden = attached;
445
- chipsEl.hidden = !attached;
446
- if (!busy) another.textContent = chips.length > 0 ? 'Add another' : 'Annotate';
447
- if (!attached) actions.append(...more());
448
- chipsEl.replaceChildren(
449
- ...chips.map((c, i) => {
450
- const thumb = element('img', { src: c.url, alt: '' });
451
- return chip([thumb, shotName(i)], `Open ${shotName(i).toLowerCase()}`, i, `Remove ${shotName(i).toLowerCase()}`, () =>
452
- dropShot(c),
453
- );
454
- }),
455
- ...recordings.map((r, i) => {
456
- const play = element('span', { className: 'play', innerHTML: PLAY });
457
- return chip(
458
- [play, `${recordingName(i)} ${clock(r.duration)}${r.voice === undefined ? '' : ' · voice'}`],
459
- `Play ${recordingName(i).toLowerCase()} back`,
460
- chips.length + i,
461
- `Remove ${recordingName(i).toLowerCase()}`,
462
- () => {
463
- recordings = recordings.filter((x) => x !== r);
464
- dropped();
465
- },
466
- );
467
- }),
468
- ...voices.map((v, i) => {
469
- const play = element('span', { className: 'play', innerHTML: PLAY });
470
- return chip(
471
- [play, `${voiceName(i)} ${clock(v.duration)}`],
472
- `Play ${voiceName(i).toLowerCase()}`,
473
- chips.length + recordings.length + i,
474
- `Remove ${voiceName(i).toLowerCase()}`,
475
- () => {
476
- voices = voices.filter((x) => x !== v);
477
- dropped();
478
- },
479
- );
480
- }),
481
- ...(attached && shots !== undefined && notes !== undefined && here ? [another] : []),
482
- ...(attached ? more() : []),
483
- );
484
- able();
485
- mark();
486
- };
487
- const dropShot = (c: Chip) => {
488
- URL.revokeObjectURL(c.url);
489
- chips = chips.filter((x) => x !== c);
490
- dropped();
491
- };
492
- // Back to the box, unticked, once the last is gone: what was attached is, so nothing is until it's asked for again.
493
- const dropped = () => {
494
- if (attachedCount() === 0) attach.checked = false;
495
- showChips();
496
- };
497
- const toChip = (drawn: Drawn): Chip => ({ ...drawn, url: URL.createObjectURL(drawn.png) });
498
- const reset = () => {
499
- for (const c of chips) URL.revokeObjectURL(c.url);
500
- chips = [];
501
- recordings = [];
502
- voices = [];
503
- attach.checked = true;
504
- showChips();
505
- };
506
-
507
- /** Takes a shot and opens it to draw on, or opens a chip's again: saved, it's a chip. */
508
- const draw = async (old?: Chip) => {
509
- if (shots === undefined || notes === undefined || busy) return;
510
- busy = true;
511
- const was = { annotate: annotate.textContent, another: another.textContent };
512
- annotate.textContent = another.textContent = old === undefined ? 'Capturing…' : was.another;
513
- problem.textContent = '';
514
- try {
515
- const taken = old?.shot ?? (await shots.capture(context.element));
516
- annotate.textContent = was.annotate;
517
- another.textContent = was.another;
518
- const picture: Picture = { url: taken.url, ...taken.size };
519
- const marks = await notes.edit(picture, old?.marks ?? [], { signal: aborts.signal });
520
- if (marks === undefined) return;
521
- const next = toChip({ shot: taken, marks, png: await notes.flatten(picture, marks) });
522
- if (old === undefined) {
523
- chips = [...chips, next];
524
- } else {
525
- URL.revokeObjectURL(old.url);
526
- chips = chips.map((c) => (c === old ? next : c));
527
- }
528
- showChips();
529
- } catch (e) {
530
- problem.textContent = messageOf(e);
531
- } finally {
532
- annotate.textContent = was.annotate;
533
- another.textContent = was.another;
534
- busy = false;
535
- showChips();
536
- }
537
- };
538
- annotate.addEventListener('click', () => void draw());
539
- another.addEventListener('click', () => void draw());
540
- record.addEventListener('click', () => {
541
- if (recorder === undefined || busy) return;
542
- // A take going on is kept first, as a chip, to come back to with the rest.
543
- void speakOff().then(() => {
544
- const drawn = chips.map(({ url: _, ...d }) => d);
545
- const kept: Kept = { text: text.value, attach: attach.checked, html: withHtml.checked, drawn, recordings, voices, facts: facts() };
546
- context.away(kept, () => recorder.record());
547
- });
548
- });
549
-
550
- // The mic, here: Voice starts a take, the same button (now its time) stops it, and it's a chip.
551
- let take: Take | undefined;
552
- let ticking: ReturnType<typeof setInterval> | undefined;
553
- let stopWave: (() => void) | undefined;
554
- const speakOn = async () => {
555
- if (voice === undefined) return;
556
- problem.textContent = '';
557
- speak.disabled = true;
558
- try {
559
- take = await voice.start();
560
- } catch (e) {
561
- problem.textContent = messageOf(e);
562
- return;
563
- } finally {
564
- speak.disabled = false;
565
- }
566
- const started = take.started;
567
- // The time, the mic's live waveform, so it's plain it hears, and what a click does.
568
- const time = element('span', { className: 'time' });
569
- const wave = element('canvas', { className: 'wave' });
570
- speak.replaceChildren('● ', time, wave, 'Stop');
571
- stopWave = liveWaveform(wave, take.stream, { played: '#fff', rest: 'rgb(255 255 255 / 0.4)' });
572
- const tick = () => (time.textContent = clock(Date.now() - started));
573
- speak.classList.add('voice-on');
574
- speak.title = 'Stop, and attach it';
575
- tick();
576
- ticking = setInterval(tick, 250);
577
- mark();
578
- };
579
- const speakOff = async () => {
580
- const ending = take;
581
- if (ending === undefined) return;
582
- take = undefined;
583
- clearInterval(ticking);
584
- stopWave?.();
585
- stopWave = undefined;
586
- speak.classList.remove('voice-on');
587
- speak.textContent = 'Saving…';
588
- try {
589
- voices = [...voices, await ending.stop()];
590
- } catch (e) {
591
- problem.textContent = messageOf(e);
592
- } finally {
593
- speak.textContent = 'Voice';
594
- speak.title = 'Record your voice, here';
595
- showChips();
596
- }
597
- };
598
- speak.addEventListener('click', () => void (take === undefined ? speakOn() : speakOff()));
599
-
600
- // The task whose words are open to change, by ID, and the tasks as last read.
601
- let editing: string | undefined;
602
- // The tasks shown whole, by ID: kept over a change, which draws the list again.
603
- const whole = new Set<string>();
604
- // The Save of a listed task whose words were changed and not kept yet.
605
- let edited: HTMLElement | undefined;
606
- /** Tells the popup what leaving now would lose: a listed task's changed words, or a new one's, typed, attached or being spoken. */
607
- const mark = () => context.unsaved(edited ?? (text.value.trim() !== '' || attachedCount() > 0 || take !== undefined ? add : undefined));
608
- let shown = context.model;
609
- /** Asks for a change to a listed task and shows the tasks as they are after; the panel's status says why not. */
610
- const change = async (op: Change) => {
611
- try {
612
- editing = undefined;
613
- render(await context.apply(op));
614
- } catch {
615
- render(shown);
616
- }
617
- };
618
- /** A task's words in a field of their own: Save or Ctrl+Enter keeps them, Cancel or Esc leaves them. */
619
- const editor = (t: Task) => {
620
- // Marked a modal while it's open, so Esc is its and not the popup's.
621
- const item = element('li', { className: 'editing' });
622
- item.dataset['deicticModal'] = '';
623
- const field = element('textarea', { value: t.text });
624
- const save = element('button', { type: 'button', className: 'primary', textContent: 'Save' });
625
- const leave = element('button', { type: 'button', textContent: 'Cancel' });
626
- const buttons = element('div', { className: 'row' });
627
- const right = element('span', { className: 'actions' });
628
- right.append(leave, save);
629
- buttons.append(element('code', { textContent: `#${t.id}` }), right);
630
- item.append(field, buttons);
631
- const done = () => {
632
- editing = undefined;
633
- render(shown);
634
- };
635
- const keep = () => {
636
- if (field.value.trim() === '') return;
637
- if (field.value.trim() === t.text) return done();
638
- save.disabled = true;
639
- void change({ edit: t.id, text: field.value });
640
- };
641
- field.addEventListener('input', () => {
642
- save.disabled = field.value.trim() === '';
643
- edited = field.value.trim() === t.text ? undefined : save;
644
- mark();
645
- });
646
- field.addEventListener('keydown', (e) => {
647
- if (e.key === 'Escape') {
648
- e.stopPropagation();
649
- done();
650
- }
651
- if (e.key !== 'Enter' || !(e.ctrlKey || e.metaKey)) return;
652
- e.preventDefault();
653
- keep();
654
- });
655
- save.addEventListener('click', keep);
656
- leave.addEventListener('click', done);
657
- queueMicrotask(() => field.focus());
658
- return item;
659
- };
660
- const render = (model: Model) => {
661
- shown = model;
662
- // A task being changed is drawn again with its words as they were.
663
- edited = undefined;
664
- const { channel, link, tasks, elsewhere, watching } = model;
665
- const name =
666
- link === undefined
667
- ? element('span')
668
- : element('a', { href: link, target: '_blank', rel: 'noreferrer', title: 'Open the channel on the board' });
669
- name.textContent = `#${channel}`;
670
- hint.replaceChildren('to ', name);
671
- // Whether a task added now is taken up: who watches the channel, or that no one does, where that's known.
672
- if (watching !== undefined) {
673
- const names = new Intl.ListFormat('en', { type: 'conjunction' }).format(watching);
674
- const on = watching.length > 0;
675
- const who = element('span', {
676
- className: on ? 'watch on' : 'watch',
677
- textContent: on ? `${names} watching` : 'no agent watching',
678
- title: on
679
- ? `${names} ${watching.length === 1 ? 'is' : 'are'} watching #${channel}, and take${watching.length === 1 ? 's' : ''} each task as it's added`
680
- : `A task waits on the board until an agent watches #${channel}: ask yours to watch deictic's tasks`,
681
- });
682
- hint.append(' · ', who);
683
- }
684
- /** A task's row: its state, its ID, a link where it has a page, its title, and where it's from when that's said. */
685
- const rowOf = (t: Task, from?: HTMLElement) => {
686
- const item = element('li');
687
- const state = element('span', { className: `state ${t.state}`, title: t.by === undefined ? t.state : `${t.state} by ${t.by}` });
688
- state.role = 'img';
689
- const id = element('code', { textContent: `#${t.id}` });
690
- const title = element('button', { type: 'button', className: 'title' });
691
- // In place, not by drawing the list again: that would take a task's words being changed with it.
692
- const show = () => {
693
- const all = whole.has(t.id);
694
- item.classList.toggle('whole', all);
695
- title.textContent = all ? t.text : t.title;
696
- title.title = all ? 'Show its first line only' : 'Show all of it';
697
- title.ariaExpanded = String(all);
698
- };
699
- title.addEventListener('click', () => {
700
- if (!whole.delete(t.id)) whole.add(t.id);
701
- show();
702
- });
703
- show();
704
- const to =
705
- t.link === undefined
706
- ? id
707
- : element('a', { href: t.link, target: '_blank', rel: 'noreferrer', title: 'Open the task on the board' });
708
- if (to !== id) to.append(id);
709
- item.append(state, to, title, ...(from === undefined ? [] : [from]));
710
- return item;
711
- };
712
- const { file } = context.target.loc;
713
- fold.hidden = elsewhere.length === 0;
714
- count.textContent = `${elsewhere.length} elsewhere in ${file.split('/').at(-1)}`;
715
- others.replaceChildren(
716
- ...elsewhere.map((t) => {
717
- if (t.at === undefined) return rowOf(t);
718
- const { line, column, tag } = t.at;
719
- const name = `<${tag}> :${line}`;
720
- // Only an element the page shows now has a popup to open: its place is from the task, which may be old.
721
- const there = document.querySelector(`[data-deictic="${CSS.escape(`${file}:${line}:${column}`)}"]`);
722
- if (there === null)
723
- return rowOf(t, element('span', { className: 'place', textContent: name, title: `Line ${line}, not on this page now` }));
724
-
725
- const go = element('button', { type: 'button', className: 'place', textContent: name, title: `Open the tasks of line ${line}` });
726
- go.addEventListener('click', () => void context.open('tasks', there));
727
- return rowOf(t, go);
728
- }),
729
- );
730
- const over = tasks.filter((t) => OVER.has(t.state));
731
- closed.hidden = over.length === 0;
732
- closedCount.textContent = `${over.length} closed`;
733
- ended.replaceChildren(...over.map((t) => rowOf(t)));
734
- const live = tasks.filter((t) => !OVER.has(t.state));
735
- // The latest is the last, which a list longer than its room would keep out of sight: as it opens, and after one is added.
736
- const grew = live.length > list.childElementCount;
737
- list.replaceChildren(
738
- ...live.map((t) => {
739
- if (t.id === editing && t.open) return editor(t);
740
- const item = rowOf(
741
- t,
742
- t.at === undefined
743
- ? undefined
744
- : element('span', {
745
- className: 'place',
746
- textContent: `was :${t.at.line}`,
747
- title: `Added when this was on line ${t.at.line}: it has moved since`,
748
- }),
749
- );
750
- if (!t.open) return item;
751
- const edit = element('button', { type: 'button', className: 'act', innerHTML: EDIT, title: 'Edit the task' });
752
- edit.addEventListener('click', () => {
753
- editing = t.id;
754
- render(shown);
755
- });
756
- const remove = element('button', { type: 'button', className: 'act', innerHTML: DELETE, title: 'Delete the task' });
757
- remove.addEventListener('click', () => {
758
- remove.disabled = true;
759
- void change({ remove: t.id });
760
- });
761
- const acts = element('span', { className: 'acts' });
762
- acts.append(edit, remove);
763
- item.append(acts);
764
- return item;
765
- }),
766
- );
767
- if (grew) list.scrollTop = list.scrollHeight;
768
- able();
769
- mark();
770
- };
771
-
772
- const back = context.resumed;
773
229
  /**
774
- * What the page says of the element: read now, while the page has it, and as the panel left it where the
775
- * page has moved on without it (a recording that went on to another), which is the page the task is about.
230
+ * What the page says of an element: read now, while the page has it, and as the panel left it where the page
231
+ * has moved on without it (a recording that went on to another), which is the page the task is about.
776
232
  */
777
- const facts = (): Facts => {
778
- const { element: el, elements } = context;
779
- if (!here && back !== undefined) return (back.state as Kept).facts;
780
- const chain = chainOf(el, context.target.loc.file);
233
+ const seenOf = (a: About): Seen | undefined => {
234
+ const el = onPage(a);
235
+ if (el === undefined) return a.seen;
236
+ const chain = chainOf(el, a.target.loc.file);
237
+ const { pointed, at } = context;
781
238
  return {
782
- page: location.href,
783
- viewport: { width: innerWidth, height: innerHeight },
784
- ...(context.pointed === undefined
785
- ? {}
786
- : { pointed: { path: pathTo(context.pointed, el), html: context.pointed.outerHTML.slice(0, 4000) } }),
787
- count: elements.length,
239
+ // What was pointed at, and the spot, are the popup's own element's.
240
+ ...(a.own && at !== undefined ? { point: at } : {}),
241
+ ...(a.own && pointed !== undefined ? { pointed: { path: pathTo(pointed, el), html: pointed.outerHTML.slice(0, 4000) } } : {}),
242
+ count: sameAs(el).length,
788
243
  ...(chain.length === 0 ? {} : { chain }),
789
244
  html: (shots?.masked(el) ?? el).outerHTML.slice(0, HTML),
790
245
  };
791
246
  };
792
-
793
- /**
794
- * The shots to attach: each chip's PNG, kept as a shot, as the person drew it, or a shot taken now where the
795
- * box is ticked. Only that one has the element outlined in it (or is as it was taken, where that can't be
796
- * drawn): nothing else in it says what it's about, while a shot someone annotated says what they marked.
797
- */
798
- const screenshotsOf = async (): Promise<Op['screenshots']> => {
799
- if (shots === undefined) return undefined;
800
- if (chips.length > 0) {
801
- add.textContent = 'Uploading…';
802
- return Promise.all(
803
- chips.map(async ({ shot: taken, marks, png }) => ({
804
- id: (await shots.upload(png, taken)).id,
805
- box: taken.box,
806
- ...(marks.length === 0 ? {} : { marks: marksOf(marks) }),
807
- })),
808
- );
809
- }
810
- // With a recording attached the box is away, so no shot is asked for.
811
- if (!attach.checked || recordings.length > 0 || !here) return undefined;
812
- add.textContent = 'Capturing…';
813
- const taken = await shots.capture(context.element);
814
- try {
815
- return [{ id: (await shots.upload(await outlined(taken.url, taken), taken)).id, box: taken.box, outlined: true }];
816
- } catch {
817
- return [{ id: taken.id, box: taken.box }];
247
+ /** The page the task is about: this one, or the one the panel left where none of its elements is on this one. */
248
+ const wherever = (about: About[]): Pick<Kept, 'page' | 'viewport'> => {
249
+ if (back !== undefined && about.length > 0 && !about.some((a) => onPage(a) !== undefined)) {
250
+ const { page, viewport } = back.state as Kept;
251
+ return { page, viewport };
818
252
  }
253
+ return { page: location.href, viewport: { width: innerWidth, height: innerHeight } };
819
254
  };
820
255
 
821
- const send = async () => {
822
- if (busy || sending) return;
823
- // A take still going is kept first: it may be all there is to send.
824
- await speakOff();
825
- if (able()) return;
826
- sending = true;
827
- able();
828
- problem.textContent = '';
829
- let screenshots: Op['screenshots'];
830
- try {
831
- screenshots = await screenshotsOf();
832
- } catch (e) {
833
- // Said under the shots, which stay as they are: untick the box, or remove the chips, to send without.
834
- problem.textContent = messageOf(e);
835
- add.textContent = 'Add task';
836
- sending = false;
837
- able();
256
+ // Record: the popup goes, the page is recorded, and it comes back with what's typed and the recording attached.
257
+ const leave = async () => {
258
+ if (recorder === undefined) return;
259
+ composer.problem.textContent = '';
260
+ if (recorder.recording()) {
261
+ composer.problem.textContent = "A recording is going already: stop it in the tool panel, and it's attached here";
838
262
  return;
839
263
  }
840
- add.textContent = 'Add task';
841
- try {
842
- const { html, ...said } = facts();
264
+ // A take going on is kept first, as a chip, to come back to with the rest.
265
+ await composer.stopTake();
266
+ const { text, shot, html, about } = composer.draft();
267
+ const kept: Kept = {
268
+ text,
269
+ ...(shot === undefined ? {} : { shot }),
270
+ html,
271
+ ...wherever(about),
272
+ about: about.flatMap(({ target, own: mine, ...a }) => {
273
+ const seen = seenOf({ target, own: mine, ...a });
274
+ return seen === undefined ? [] : [{ target, own: mine, seen }];
275
+ }),
276
+ };
277
+ context.away(kept, () => recorder.record());
278
+ };
279
+
280
+ const composer = composerIn(context, {
281
+ placeholder: 'What should change here?',
282
+ sendLabel: 'Add task',
283
+ about: own,
284
+ html: sendsHtml,
285
+ ...(context.at === undefined ? {} : { at: context.at }),
286
+ shoot: true,
287
+ // Back from a recording on a page without the element: nothing of it to shoot or draw on here.
288
+ here: context.element.isConnected,
289
+ over,
290
+ record: () => void leave(),
291
+ changed: () => mark(),
292
+ submit: async (gathered) => {
293
+ const { text, about, html: withHtml, screenshots } = gathered;
294
+ // The first element is the task's place; the rest are named beside it; with none, it's the page's.
295
+ const [first, ...rest] = about;
296
+ const { html, ...said } = (first === undefined ? undefined : seenOf(first)) ?? { html: undefined, count: 0 };
297
+ const htmlOf = (of: string | undefined) => (sendsHtml && withHtml && of !== undefined ? { html: of } : {});
843
298
  const op: Op = {
844
- text: text.value,
299
+ text,
300
+ ...wherever(about),
845
301
  ...said,
846
- ...(sendsHtml && withHtml.checked ? { html } : {}),
847
- ...(screenshots === undefined ? {} : { screenshots }),
848
- ...(recordings.length === 0
849
- ? {}
850
- : {
851
- recordings: recordings.map(({ id, duration, url, voice: clips }) => ({
852
- id,
853
- duration,
854
- replay: new URL(url, location.href).href,
855
- ...(clips === undefined ? {} : { voice: clips.map((c) => c.id) }),
856
- })),
857
- }),
858
- ...(voices.length === 0 ? {} : { voice: voices.map(({ id, duration }) => ({ id, duration })) }),
859
- ...annotationsOf(notes),
302
+ ...(first === undefined ? { detached: true } : {}),
303
+ ...htmlOf(html),
304
+ ...(rest.length === 0 ? {} : { also: rest.map((a) => ({ at: atOf(a.target), tag: a.target.tag, ...htmlOf(seenOf(a)?.html) })) }),
305
+ ...attachedOf(gathered),
860
306
  };
861
- const model = await context.apply(op);
862
- render(model);
863
- announce(model, op, context.target);
864
- text.value = '';
865
- reset();
866
- const dropped = model.tasks.at(-1)?.dropped;
867
- if (dropped !== undefined) problem.textContent = `Sent without ${dropped}: it wasn't kept any more`;
868
- } catch {
869
- // The panel's status says why; what was typed and drawn stays, to send again.
870
- }
871
- sending = false;
872
- able();
307
+ // Sent on its first element, which may not be the popup's.
308
+ const on = first?.target ?? context.target;
309
+ let model: Model;
310
+ try {
311
+ model = await context.apply(op, on);
312
+ } catch {
313
+ // The panel's status says why; what was typed and attached stays, to send again.
314
+ return false;
315
+ }
316
+ // In the drawer and on its pin at once: the tab lists none.
317
+ storeOf(context).load(true);
318
+ announce(
319
+ model,
320
+ op,
321
+ on,
322
+ (screenshots ?? []).map((shot) => shot.url),
323
+ );
324
+ const added = model.tasks.at(-1);
325
+ composer.note.textContent =
326
+ first === undefined
327
+ ? 'Added, about the page: it is in the drawer'
328
+ : `Added${added === undefined ? '' : ` #${added.id}`}: it is in the drawer`;
329
+ if (added?.dropped !== undefined) composer.problem.textContent = `Sent without ${added.dropped}: it wasn't kept any more`;
330
+ return true;
331
+ },
332
+ });
333
+ panel.append(style, composer.el);
334
+ composer.el.append(row);
335
+
336
+ /** Tells the popup what leaving now would lose: the words of a new task, or a take. What's attached is the tray's, and stays. */
337
+ const mark = () => context.unsaved(composer.pending() ? composer.send : undefined);
338
+ /** Where a task goes, and whether it's taken up: the channel, and who watches it, or that no one does, where that's known. */
339
+ const render = ({ channel, link, watching }: Model) => {
340
+ const name =
341
+ link === undefined
342
+ ? element('span')
343
+ : element('a', { href: link, target: '_blank', rel: 'noreferrer', title: 'Open the channel on the board' });
344
+ name.textContent = `#${channel}`;
345
+ hint.replaceChildren('to ', name);
346
+ if (watching === undefined) return;
347
+ const names = new Intl.ListFormat('en', { type: 'conjunction' }).format(watching);
348
+ const on = watching.length > 0;
349
+ const who = element('span', {
350
+ className: on ? 'watch on' : 'watch',
351
+ textContent: on ? `${names} watching` : 'no agent watching',
352
+ title: on
353
+ ? `${names} ${watching.length === 1 ? 'is' : 'are'} watching #${channel}, and take${watching.length === 1 ? 's' : ''} each task as it's added`
354
+ : `A task waits on the board until an agent watches #${channel}: ask yours to watch deictic's tasks`,
355
+ });
356
+ hint.append(' · ', who);
873
357
  };
874
358
 
875
- // Back from recording: what was kept, and the recording, or why there's none.
359
+ // Back from recording: what was typed and asked for, and why there's no recording, where there's none.
876
360
  if (back !== undefined) {
877
361
  const kept = back.state as Kept;
878
- text.value = kept.text;
879
- attach.checked = kept.attach;
880
- withHtml.checked = kept.html;
881
- chips = kept.drawn.map(toChip);
882
- recordings = [...kept.recordings, ...(back.result === undefined ? [] : [back.result as Recording])];
883
- voices = kept.voices;
884
- if (back.problem !== undefined) problem.textContent = back.problem;
362
+ // Each element where this page has it, and as the page that had it said it where not.
363
+ const about = kept.about.map(({ target, own: mine, seen }) => {
364
+ const el = mine ? context.element : (document.querySelector(`[data-deictic="${CSS.escape(atOf(target))}"]`) ?? undefined);
365
+ return { target, own: mine, seen, ...(el === undefined ? {} : { el }) };
366
+ });
367
+ const draft: Draft = { text: kept.text, html: kept.html, about, ...(kept.shot === undefined ? {} : { shot: kept.shot }) };
368
+ composer.restore(draft);
369
+ if (back.problem !== undefined) composer.problem.textContent = back.problem;
885
370
  }
886
371
 
887
- text.addEventListener('input', () => {
888
- able();
889
- mark();
890
- });
891
- text.addEventListener('keydown', (e) => {
892
- if (e.key !== 'Enter' || !(e.ctrlKey || e.metaKey)) return;
893
- e.preventDefault();
894
- void send();
895
- });
896
- add.addEventListener('click', () => void send());
897
- showChips();
898
372
  render(context.model);
899
- text.focus();
373
+ composer.focus();
900
374
  return () => {
901
- aborts.abort();
902
- take?.cancel();
903
- clearInterval(ticking);
904
- stopWave?.();
905
- for (const c of chips) URL.revokeObjectURL(c.url);
375
+ unpin?.();
376
+ composer.destroy();
906
377
  };
907
378
  },
908
379
  });