deictic 0.6.0 → 0.8.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 +156 -31
- package/README.md +6 -4
- 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/bun.js +1 -1
- package/dist/client/index.d.ts +7 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1077 -236
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/next.js +1 -1
- package/dist/recommended/index.d.ts +2 -2
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +89 -154
- 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/endpoints.js +26 -6
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/index.d.ts +150 -9
- 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 +123 -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/integration.js +59 -5
- package/dist/shared/integration.js.map +1 -1
- package/dist/shared/package.js +23 -0
- package/dist/shared/package.js.map +1 -0
- package/dist/shared/packages.js +14 -23
- package/dist/shared/packages.js.map +1 -1
- package/dist/shared/playwright.js +11 -3
- package/dist/shared/playwright.js.map +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 +55 -31
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +279 -61
- 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 +15 -14
- package/dist/shared/watch.js.map +1 -1
- package/dist/tailwind/index.js +7 -2
- package/dist/tailwind/index.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 +1870 -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/dist/webpack.js +1 -1
- package/package.json +2 -1
- package/skills/deictic/SKILL.md +22 -28
- package/src/cli/recording.ts +34 -3
- package/src/cli/task.ts +78 -33
- package/src/cli/voice.ts +9 -4
- package/src/cli/watch.ts +16 -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 +290 -165
- 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 +148 -8
- 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 +96 -168
- package/src/plugins/screenshots/client.ts +53 -2
- package/src/plugins/screenshots/playwright.ts +8 -3
- package/src/plugins/tailwind/index.ts +3 -2
- package/src/plugins/tasks/client.ts +229 -748
- package/src/plugins/tasks/composer.ts +797 -0
- package/src/plugins/tasks/drawer.ts +516 -0
- package/src/plugins/tasks/index.ts +436 -80
- package/src/plugins/tasks/pins.ts +280 -0
- package/src/plugins/tasks/store.ts +132 -0
- package/src/plugins/tasks/which.ts +34 -0
- package/src/plugins/voice/client.ts +96 -5
- package/src/tools/endpoints.ts +31 -5
- package/src/tools/packages.ts +12 -4
- package/src/tools/plugins.ts +18 -4
- package/src/tools/problems.ts +60 -0
- package/skills/deictic/references/recordings.md +0 -13
- package/skills/deictic/references/tasks.md +0 -22
- package/skills/deictic/references/watch.md +0 -17
|
@@ -1,162 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
-
*
|
|
11
|
-
*
|
|
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 {
|
|
26
|
-
import {
|
|
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
|
-
|
|
29
|
-
import
|
|
30
|
-
import type {
|
|
31
|
-
import
|
|
32
|
-
import
|
|
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';
|
|
22
|
+
import { whichOf } from './which.ts';
|
|
35
23
|
|
|
36
24
|
const STYLE = `
|
|
37
|
-
|
|
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; }
|
|
25
|
+
.compose { flex: none; }
|
|
76
26
|
.row { display: flex; gap: 6px; margin-top: 8px; justify-content: space-between; align-items: center; }
|
|
77
|
-
/* Cut short
|
|
27
|
+
/* Cut short: a channel's name and its watchers' may be long. */
|
|
78
28
|
.hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--deictic-muted); font-size: 12px; }
|
|
79
29
|
/* A dot as a task's state is: a ring while no one watches, green while someone does. */
|
|
80
30
|
.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
31
|
.watch.on::before { border-color: #4ade80; background: #4ade80; }
|
|
82
32
|
.hint a { color: inherit; }
|
|
83
33
|
.hint a:hover { color: var(--deictic-fg); }
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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;
|
|
34
|
+
${COMPOSER_STYLE}`;
|
|
35
|
+
|
|
36
|
+
const TOOL_STYLE = `
|
|
37
|
+
.task-tool button { position: relative; }
|
|
38
|
+
.task-tool .count {
|
|
39
|
+
position: absolute;
|
|
40
|
+
top: -5px;
|
|
41
|
+
right: -5px;
|
|
42
|
+
box-sizing: border-box;
|
|
43
|
+
min-width: 15px;
|
|
44
|
+
height: 15px;
|
|
45
|
+
padding: 0 4px;
|
|
46
|
+
border-radius: 8px;
|
|
47
|
+
font: 700 10px/15px system-ui, sans-serif;
|
|
48
|
+
color: var(--deictic-on-accent);
|
|
49
|
+
background: var(--deictic-accent);
|
|
133
50
|
}
|
|
51
|
+
.task-tool button[aria-pressed='true'] .count { color: var(--deictic-fg); background: #09090b; }
|
|
52
|
+
`;
|
|
53
|
+
/** A note with a plus: a task to add. */
|
|
54
|
+
const TASK = '<path d="M4 5h16v11H9l-5 4zM12 8v5M9.5 10.5h5"/>';
|
|
134
55
|
|
|
135
|
-
/** What the panel keeps while it's away recording: what's typed
|
|
56
|
+
/** What the panel keeps while it's away recording: what's typed and asked for. What's attached is the tray's. */
|
|
136
57
|
interface Kept {
|
|
137
58
|
text: string;
|
|
138
|
-
|
|
59
|
+
/** Whether a shot was asked for, or asked not to be, where either was. */
|
|
60
|
+
shot?: boolean;
|
|
139
61
|
html: boolean;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
facts: Facts;
|
|
62
|
+
/** The page as the panel left, and its elements as that page had them: for a task added where the page has moved on. */
|
|
63
|
+
page: string;
|
|
64
|
+
viewport: Op['viewport'];
|
|
65
|
+
about: { target: Target; own: boolean; seen: Seen }[];
|
|
145
66
|
}
|
|
146
67
|
|
|
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
68
|
/**
|
|
161
69
|
* `#shadow-root > div.panel > div.head > button.tab:nth-of-type(2)`: where `inner` is inside `outer`, through
|
|
162
70
|
* shadow roots, by tag, classes and, among siblings alike, place, for whoever finds it in the code.
|
|
@@ -192,39 +100,6 @@ const parentOf = (el: Element): Element | undefined => {
|
|
|
192
100
|
/** 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
101
|
const CHAIN = 3;
|
|
194
102
|
|
|
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
103
|
/**
|
|
229
104
|
* The source `el` rendered through, after its own place, nearest first: a shared component's own line is the same
|
|
230
105
|
* wherever it's used, and the change is most often in what uses it, or in what uses that.
|
|
@@ -270,51 +145,13 @@ function chainOf(el: Element, file: string): NonNullable<Op['chain']> {
|
|
|
270
145
|
/** What's sent of the element's HTML at most, in characters: the server attaches it as a file. */
|
|
271
146
|
const HTML = 100_000;
|
|
272
147
|
|
|
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
148
|
/** The event the page hears of each added task by, on `window`: its `detail` is a `TaskAdded`. */
|
|
311
149
|
export const TASK_ADDED = 'deictic:task';
|
|
312
150
|
|
|
313
151
|
/** 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 {
|
|
152
|
+
function announce(model: Model, op: Op, target: Target, shots: string[]): void {
|
|
315
153
|
const task = model.tasks.at(-1);
|
|
316
154
|
if (task === undefined) return;
|
|
317
|
-
const marks = (op.annotations?.count ?? 0) + (op.screenshots ?? []).reduce((n, shot) => n + (shot.marks?.count ?? 0), 0);
|
|
318
155
|
const detail: TaskAdded = {
|
|
319
156
|
id: task.id,
|
|
320
157
|
title: task.title,
|
|
@@ -326,583 +163,227 @@ function announce(model: Model, op: Op, target: Target): void {
|
|
|
326
163
|
screenshots: op.screenshots?.length ?? 0,
|
|
327
164
|
recordings: op.recordings?.length ?? 0,
|
|
328
165
|
voice: op.voice?.length ?? 0,
|
|
329
|
-
marks,
|
|
166
|
+
marks: (op.annotations?.count ?? 0) + (op.screenshots ?? []).reduce((n, shot) => n + (shot.marks?.count ?? 0), 0),
|
|
330
167
|
},
|
|
168
|
+
screenshots: shots,
|
|
331
169
|
};
|
|
332
170
|
window.dispatchEvent(new CustomEvent(TASK_ADDED, { detail }));
|
|
333
171
|
}
|
|
334
172
|
|
|
335
|
-
export default defineClientPlugin<Model,
|
|
173
|
+
export default defineClientPlugin<Model, Op>({
|
|
336
174
|
name: 'tasks',
|
|
337
175
|
label: 'Task',
|
|
338
|
-
//
|
|
176
|
+
// Its tool in the tool panel, after the others': what takes what they made. Picked, the next press on the page
|
|
177
|
+
// opens the tab on that spot.
|
|
178
|
+
setup: (context) => {
|
|
179
|
+
const { tools, tray } = context;
|
|
180
|
+
// The tasks there already, in the drawer.
|
|
181
|
+
drawerOf(context);
|
|
182
|
+
const group = element('div', { className: 'tool-group task-tool' });
|
|
183
|
+
let picking = false;
|
|
184
|
+
const button = toolButton(TASK, 'Task', 'T', () => {
|
|
185
|
+
if (picking) return;
|
|
186
|
+
picking = true;
|
|
187
|
+
button.setAttribute('aria-pressed', 'true');
|
|
188
|
+
void tools.pick().then((spot) => {
|
|
189
|
+
picking = false;
|
|
190
|
+
button.setAttribute('aria-pressed', 'false');
|
|
191
|
+
if (spot !== undefined) context.open('tasks', spot.element, spot.at);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
button.setAttribute('aria-pressed', 'false');
|
|
195
|
+
// How much is in the tray, for the task to take.
|
|
196
|
+
const count = element('span', { className: 'count' });
|
|
197
|
+
const counted = () => {
|
|
198
|
+
const held = tray.list().length;
|
|
199
|
+
count.textContent = String(held);
|
|
200
|
+
count.hidden = held === 0;
|
|
201
|
+
};
|
|
202
|
+
tray.subscribe(counted);
|
|
203
|
+
counted();
|
|
204
|
+
button.append(count);
|
|
205
|
+
group.append(element('style', { textContent: TOOL_STYLE }), button);
|
|
206
|
+
// After the other tools that capture the page, as it takes what they made.
|
|
207
|
+
tools.add(group, { section: 'capture', last: true });
|
|
208
|
+
},
|
|
209
|
+
// What the page before this left the tab for: a recording, where it carries on here.
|
|
339
210
|
resume: ({ use }) => use('recordings')?.going(),
|
|
211
|
+
// The page's tasks, where they are, while it's pointed on.
|
|
212
|
+
pointing: (context) => pinsIn(context).glance(),
|
|
340
213
|
mount: (panel, context) => {
|
|
341
214
|
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
215
|
const hint = element('span', { className: 'hint' });
|
|
346
216
|
const row = element('div', { className: 'row' });
|
|
347
|
-
row.append(hint
|
|
348
|
-
// The
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
const
|
|
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);
|
|
217
|
+
row.append(hint);
|
|
218
|
+
// The page's tasks, pinned where they are, while the tab is open too: not for a popup a page shows in place,
|
|
219
|
+
// which is in a root of its own.
|
|
220
|
+
const over = panel.getRootNode() === context.root;
|
|
221
|
+
const unpin = over ? pinsIn(context).glance() : undefined;
|
|
359
222
|
|
|
360
223
|
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
224
|
const recorder = context.use('recordings');
|
|
365
|
-
const
|
|
366
|
-
// The server half's `html` option, which takes the
|
|
225
|
+
const back = context.resumed;
|
|
226
|
+
// The server half's `html` option, which takes the button away; a page half with no options (a `standalone` server's) has it.
|
|
367
227
|
const sendsHtml = (context.options as { html?: boolean } | undefined)?.html !== false;
|
|
368
|
-
|
|
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);
|
|
228
|
+
const own = (): About[] => [{ target: context.target, own: true, el: context.element }];
|
|
397
229
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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();
|
|
230
|
+
/**
|
|
231
|
+
* What the page says of an element: read now, while the page has it, and as the panel left it where the page
|
|
232
|
+
* has moved on without it (a recording that went on to another), which is the page the task is about.
|
|
233
|
+
*/
|
|
234
|
+
const seenOf = (a: About): Seen | undefined => {
|
|
235
|
+
const el = onPage(a);
|
|
236
|
+
if (el === undefined) return a.seen;
|
|
237
|
+
const chain = chainOf(el, a.target.loc.file);
|
|
238
|
+
const { pointed, at } = context;
|
|
239
|
+
const masked = shots?.masked(el) ?? el;
|
|
240
|
+
const alike = sameAs(el);
|
|
241
|
+
return {
|
|
242
|
+
// What was pointed at, and the spot, are the popup's own element's.
|
|
243
|
+
...(a.own && at !== undefined ? { point: at } : {}),
|
|
244
|
+
...(a.own && pointed !== undefined ? { pointed: { path: pathTo(pointed, el), html: pointed.outerHTML.slice(0, 4000) } } : {}),
|
|
245
|
+
count: alike.length,
|
|
246
|
+
...(alike.length > 1 ? { which: whichOf(el, alike, masked) } : {}),
|
|
247
|
+
...(chain.length === 0 ? {} : { chain }),
|
|
248
|
+
html: masked.outerHTML.slice(0, HTML),
|
|
249
|
+
};
|
|
505
250
|
};
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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();
|
|
251
|
+
/** The page the task is about: this one, or the one the panel left where none of its elements is on this one. */
|
|
252
|
+
const wherever = (about: About[]): Pick<Kept, 'page' | 'viewport'> => {
|
|
253
|
+
if (back !== undefined && about.length > 0 && !about.some((a) => onPage(a) !== undefined)) {
|
|
254
|
+
const { page, viewport } = back.state as Kept;
|
|
255
|
+
return { page, viewport };
|
|
536
256
|
}
|
|
257
|
+
return { page: location.href, viewport: { width: innerWidth, height: innerHeight } };
|
|
537
258
|
};
|
|
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
259
|
|
|
550
|
-
//
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
problem.textContent = '';
|
|
557
|
-
speak.disabled = true;
|
|
558
|
-
try {
|
|
559
|
-
take = await voice.start();
|
|
560
|
-
} catch (e) {
|
|
561
|
-
problem.textContent = messageOf(e);
|
|
260
|
+
// Record: the popup goes, the page is recorded, and it comes back with what's typed and the recording attached.
|
|
261
|
+
const leave = async () => {
|
|
262
|
+
if (recorder === undefined) return;
|
|
263
|
+
composer.problem.textContent = '';
|
|
264
|
+
if (recorder.recording()) {
|
|
265
|
+
composer.problem.textContent = "A recording is going already: stop it in the tool panel, and it's attached here";
|
|
562
266
|
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
267
|
}
|
|
268
|
+
// A take going on is kept first, as a chip, to come back to with the rest.
|
|
269
|
+
await composer.stopTake();
|
|
270
|
+
const { text, shot, html, about } = composer.draft();
|
|
271
|
+
const kept: Kept = {
|
|
272
|
+
text,
|
|
273
|
+
...(shot === undefined ? {} : { shot }),
|
|
274
|
+
html,
|
|
275
|
+
...wherever(about),
|
|
276
|
+
about: about.flatMap(({ target, own: mine, ...a }) => {
|
|
277
|
+
const seen = seenOf({ target, own: mine, ...a });
|
|
278
|
+
return seen === undefined ? [] : [{ target, own: mine, seen }];
|
|
279
|
+
}),
|
|
280
|
+
};
|
|
281
|
+
context.away(kept, () => recorder.record());
|
|
597
282
|
};
|
|
598
|
-
speak.addEventListener('click', () => void (take === undefined ? speakOn() : speakOff()));
|
|
599
283
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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();
|
|
284
|
+
const composer = composerIn(context, {
|
|
285
|
+
placeholder: 'What should change here?',
|
|
286
|
+
sendLabel: 'Add task',
|
|
287
|
+
about: own,
|
|
288
|
+
html: sendsHtml,
|
|
289
|
+
...(context.at === undefined ? {} : { at: context.at }),
|
|
290
|
+
shoot: true,
|
|
291
|
+
// Back from a recording on a page without the element: nothing of it to shoot or draw on here.
|
|
292
|
+
here: context.element.isConnected,
|
|
293
|
+
over,
|
|
294
|
+
record: () => void leave(),
|
|
295
|
+
changed: () => mark(),
|
|
296
|
+
submit: async (gathered) => {
|
|
297
|
+
const { text, about, html: withHtml, screenshots } = gathered;
|
|
298
|
+
// The first element is the task's place; the rest are named beside it; with none, it's the page's.
|
|
299
|
+
const [first, ...rest] = about;
|
|
300
|
+
const { html, ...said } = (first === undefined ? undefined : seenOf(first)) ?? { html: undefined, count: 0 };
|
|
301
|
+
const htmlOf = (of: string | undefined) => (sendsHtml && withHtml && of !== undefined ? { html: of } : {});
|
|
302
|
+
const op: Op = {
|
|
303
|
+
text,
|
|
304
|
+
...wherever(about),
|
|
305
|
+
...said,
|
|
306
|
+
...(first === undefined ? { detached: true } : {}),
|
|
307
|
+
...htmlOf(html),
|
|
308
|
+
...(rest.length === 0 ? {} : { also: rest.map((a) => ({ at: atOf(a.target), tag: a.target.tag, ...htmlOf(seenOf(a)?.html) })) }),
|
|
309
|
+
...attachedOf(gathered),
|
|
310
|
+
};
|
|
311
|
+
// Sent on its first element, which may not be the popup's.
|
|
312
|
+
const on = first?.target ?? context.target;
|
|
313
|
+
let model: Model;
|
|
314
|
+
try {
|
|
315
|
+
model = await context.apply(op, on);
|
|
316
|
+
} catch {
|
|
317
|
+
// The panel's status says why; what was typed and attached stays, to send again.
|
|
318
|
+
return false;
|
|
650
319
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
320
|
+
// In the drawer and on its pin at once: the tab lists none.
|
|
321
|
+
storeOf(context).load(true);
|
|
322
|
+
announce(
|
|
323
|
+
model,
|
|
324
|
+
op,
|
|
325
|
+
on,
|
|
326
|
+
(screenshots ?? []).map((shot) => shot.url),
|
|
327
|
+
);
|
|
328
|
+
const added = model.tasks.at(-1);
|
|
329
|
+
composer.note.textContent =
|
|
330
|
+
first === undefined
|
|
331
|
+
? 'Added, about the page: it is in the drawer'
|
|
332
|
+
: `Added${added === undefined ? '' : ` #${added.id}`}: it is in the drawer`;
|
|
333
|
+
if (added?.dropped !== undefined) {
|
|
334
|
+
// Open, to say so: the task went without something that was attached.
|
|
335
|
+
composer.problem.textContent = `Sent without ${added.dropped}: it wasn't kept any more`;
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
// Its pin and the drawer have it now. Once the composer has emptied (the tray, the page's marks), which it does as this answers.
|
|
339
|
+
setTimeout(context.close);
|
|
340
|
+
return true;
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
panel.append(style, composer.el);
|
|
344
|
+
composer.el.append(row);
|
|
345
|
+
|
|
346
|
+
/** 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. */
|
|
347
|
+
const mark = () => context.unsaved(composer.pending() ? composer.send : undefined);
|
|
348
|
+
/** 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. */
|
|
349
|
+
const render = ({ channel, link, watching }: Model) => {
|
|
665
350
|
const name =
|
|
666
351
|
link === undefined
|
|
667
352
|
? element('span')
|
|
668
353
|
: element('a', { href: link, target: '_blank', rel: 'noreferrer', title: 'Open the channel on the board' });
|
|
669
354
|
name.textContent = `#${channel}`;
|
|
670
355
|
hint.replaceChildren('to ', name);
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
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
|
-
/**
|
|
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.
|
|
776
|
-
*/
|
|
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);
|
|
781
|
-
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,
|
|
788
|
-
...(chain.length === 0 ? {} : { chain }),
|
|
789
|
-
html: (shots?.masked(el) ?? el).outerHTML.slice(0, HTML),
|
|
790
|
-
};
|
|
791
|
-
};
|
|
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 }];
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
|
|
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();
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
add.textContent = 'Add task';
|
|
841
|
-
try {
|
|
842
|
-
const { html, ...said } = facts();
|
|
843
|
-
const op: Op = {
|
|
844
|
-
text: text.value,
|
|
845
|
-
...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),
|
|
860
|
-
};
|
|
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();
|
|
356
|
+
if (watching === undefined) return;
|
|
357
|
+
const names = new Intl.ListFormat('en', { type: 'conjunction' }).format(watching);
|
|
358
|
+
const on = watching.length > 0;
|
|
359
|
+
const who = element('span', {
|
|
360
|
+
className: on ? 'watch on' : 'watch',
|
|
361
|
+
textContent: on ? `${names} watching` : 'no agent watching',
|
|
362
|
+
title: on
|
|
363
|
+
? `${names} ${watching.length === 1 ? 'is' : 'are'} watching #${channel}, and take${watching.length === 1 ? 's' : ''} each task as it's added`
|
|
364
|
+
: `A task waits on the board until an agent watches #${channel}: ask yours to watch deictic's tasks`,
|
|
365
|
+
});
|
|
366
|
+
hint.append(' · ', who);
|
|
873
367
|
};
|
|
874
368
|
|
|
875
|
-
// Back from recording: what was
|
|
369
|
+
// Back from recording: what was typed and asked for, and why there's no recording, where there's none.
|
|
876
370
|
if (back !== undefined) {
|
|
877
371
|
const kept = back.state as Kept;
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
372
|
+
// Each element where this page has it, and as the page that had it said it where not.
|
|
373
|
+
const about = kept.about.map(({ target, own: mine, seen }) => {
|
|
374
|
+
const el = mine ? context.element : (document.querySelector(`[data-deictic="${CSS.escape(atOf(target))}"]`) ?? undefined);
|
|
375
|
+
return { target, own: mine, seen, ...(el === undefined ? {} : { el }) };
|
|
376
|
+
});
|
|
377
|
+
const draft: Draft = { text: kept.text, html: kept.html, about, ...(kept.shot === undefined ? {} : { shot: kept.shot }) };
|
|
378
|
+
composer.restore(draft);
|
|
379
|
+
if (back.problem !== undefined) composer.problem.textContent = back.problem;
|
|
885
380
|
}
|
|
886
381
|
|
|
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
382
|
render(context.model);
|
|
899
|
-
|
|
383
|
+
composer.focus();
|
|
900
384
|
return () => {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
clearInterval(ticking);
|
|
904
|
-
stopWave?.();
|
|
905
|
-
for (const c of chips) URL.revokeObjectURL(c.url);
|
|
385
|
+
unpin?.();
|
|
386
|
+
composer.destroy();
|
|
906
387
|
};
|
|
907
388
|
},
|
|
908
389
|
});
|