deictic 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +150 -37
- package/README.md +4 -3
- package/dist/annotations/client.d.ts +1 -1
- package/dist/annotations/client.d.ts.map +1 -1
- package/dist/annotations/client.js +161 -176
- package/dist/annotations/client.js.map +1 -1
- package/dist/annotations/index.d.ts +2 -11
- package/dist/client/index.d.ts +7 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1007 -192
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/recommended/index.d.ts +2 -2
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +82 -153
- package/dist/recordings/client.js.map +1 -1
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/shared/annotations.js +3 -4
- package/dist/shared/annotations.js.map +1 -1
- package/dist/shared/board.js +1 -1
- package/dist/shared/client.js +45 -2
- package/dist/shared/client.js.map +1 -1
- package/dist/shared/component.js +62 -0
- package/dist/shared/component.js.map +1 -0
- package/dist/shared/dom.js +79 -0
- package/dist/shared/dom.js.map +1 -0
- package/dist/shared/drawer.js +217 -0
- package/dist/shared/drawer.js.map +1 -0
- package/dist/shared/endpoints.js +34 -8
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/find.js +2 -1
- package/dist/shared/find.js.map +1 -1
- package/dist/shared/index.d.ts +124 -11
- 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 +105 -26
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/index9.d.ts +1 -1
- package/dist/shared/init.js +12 -10
- package/dist/shared/init.js.map +1 -1
- package/dist/shared/integration.d.ts +1 -1
- package/dist/shared/packages.js +1 -1
- package/dist/shared/recording.js +31 -3
- package/dist/shared/recording.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +72 -21
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +330 -166
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/vb.js +1 -1
- package/dist/shared/voice2.js +6 -4
- package/dist/shared/voice2.js.map +1 -1
- package/dist/shared/watch.js +14 -14
- package/dist/shared/watch.js.map +1 -1
- package/dist/tailwind/index.js +6 -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 +1829 -742
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/voice/client.d.ts.map +1 -1
- package/dist/voice/client.js +154 -57
- package/dist/voice/client.js.map +1 -1
- package/package.json +1 -1
- package/skills/deictic/SKILL.md +22 -28
- package/src/cli/find.ts +3 -1
- package/src/cli/init.ts +13 -11
- package/src/cli/recording.ts +34 -3
- package/src/cli/task.ts +94 -23
- package/src/cli/voice.ts +9 -4
- package/src/cli/watch.ts +14 -13
- package/src/client/away.ts +3 -1
- package/src/client/component.ts +98 -0
- package/src/client/dom.ts +70 -0
- package/src/client/drawer.ts +258 -0
- package/src/client/index.ts +220 -128
- package/src/client/lightbox.ts +8 -8
- package/src/client/lighting.ts +279 -0
- package/src/client/style.ts +263 -44
- package/src/client/tools.ts +279 -0
- package/src/client/tooltip.ts +25 -5
- package/src/client/tray.ts +48 -0
- package/src/index.ts +121 -10
- package/src/plugins/annotations/client.ts +103 -129
- package/src/plugins/annotations/draw.ts +68 -72
- package/src/plugins/annotations/index.ts +12 -19
- package/src/plugins/recordings/client.ts +89 -167
- package/src/plugins/screenshots/client.ts +53 -2
- package/src/plugins/tailwind/index.ts +6 -2
- package/src/plugins/tasks/client.ts +219 -749
- package/src/plugins/tasks/composer.ts +797 -0
- package/src/plugins/tasks/drawer.ts +516 -0
- package/src/plugins/tasks/index.ts +459 -192
- package/src/plugins/tasks/pins.ts +275 -0
- package/src/plugins/tasks/store.ts +132 -0
- package/src/plugins/voice/client.ts +96 -5
- package/src/tools/endpoints.ts +18 -7
- package/src/tools/source.ts +25 -5
- package/skills/deictic/references/recordings.md +0 -13
- package/skills/deictic/references/tasks.md +0 -21
- package/skills/deictic/references/watch.md +0 -17
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tasks' section of the drawer: the channel's tasks still to do, each with its state, and the latest finished
|
|
3
|
+
* folded under them, those put away (archived) left out. One with something unread (a reply since it was last opened
|
|
4
|
+
* here, or an end no one looked at) says so, and a row the pointer is on lights its element on the page. A task opens
|
|
5
|
+
* in the drawer: its words, to change while no one has it, what it has attached, its thread, read as it's opened and
|
|
6
|
+
* again every few seconds, a composer to answer in (as the Task tab's, with what a reply can attach), and Delete,
|
|
7
|
+
* which cancels it on the board.
|
|
8
|
+
*/
|
|
9
|
+
import { named, tell } from '#src/client/component.ts';
|
|
10
|
+
import { ATTRIBUTE, place } from '#src/client/dom.ts';
|
|
11
|
+
import type { ClientContext, LightboxItem } from '#src/index.ts';
|
|
12
|
+
|
|
13
|
+
import { attachedOf, type Composer, COMPOSER_STYLE, composerIn, element, messageOf, PLAY } from './composer.ts';
|
|
14
|
+
import type { Answer, Attached, Listed, Thread } from './index.ts';
|
|
15
|
+
import { OVER, storeOf } from './store.ts';
|
|
16
|
+
|
|
17
|
+
const STYLE = `
|
|
18
|
+
.tasks-drawer h3 .unread { padding: 0 6px; border-radius: 8px; font-weight: 700; letter-spacing: 0; color: var(--deictic-on-accent); background: var(--deictic-accent); }
|
|
19
|
+
.tasks-drawer h3 a { margin-left: auto; font-weight: 400; letter-spacing: 0; text-transform: none; color: inherit; }
|
|
20
|
+
.tasks-drawer h3 a:hover { color: var(--deictic-fg); }
|
|
21
|
+
.task-row { display: grid; grid-template: 'state title mark' auto 'state meta mark' auto / auto minmax(0, 1fr) auto; gap: 1px 8px; align-items: center;
|
|
22
|
+
width: 100%; padding: 6px 8px; border: 1px solid rgb(255 255 255 / 0.08); border-radius: 8px; text-align: left; font-size: 12px; background: rgb(255 255 255 / 0.04); }
|
|
23
|
+
.task-row:hover { border-color: rgb(255 255 255 / 0.16); background: rgb(255 255 255 / 0.06); }
|
|
24
|
+
.task-row .title { grid-area: title; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
25
|
+
.task-row .meta { grid-area: meta; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--deictic-muted); }
|
|
26
|
+
.task-row.unread .title { font-weight: 600; }
|
|
27
|
+
/* What's unread is a dot of the overlay's own green, where a read one has nothing. */
|
|
28
|
+
.task-row .mark { grid-area: mark; width: 7px; height: 7px; border-radius: 50%; }
|
|
29
|
+
.task-row.unread .mark { background: var(--deictic-accent); box-shadow: 0 0 8px var(--deictic-accent); }
|
|
30
|
+
/* The state is a dot, as a board's is: a ring while no one has it, filled once someone does or it's finished. */
|
|
31
|
+
.task-state { grid-area: state; flex: none; box-sizing: border-box; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--deictic-muted); }
|
|
32
|
+
.task-state.waiting { border-style: dotted; }
|
|
33
|
+
.task-state.claimed { border-color: #60a5fa; background: #60a5fa; }
|
|
34
|
+
.task-state.blocked { border-color: #fbbf24; background: #fbbf24; }
|
|
35
|
+
.task-state.completed { border-color: #4ade80; background: #4ade80; }
|
|
36
|
+
.task-state.failed { border-color: var(--deictic-problem); background: var(--deictic-problem); }
|
|
37
|
+
.tasks-drawer details { margin-top: 6px; }
|
|
38
|
+
.tasks-drawer summary { cursor: pointer; font-size: 12px; color: var(--deictic-muted); }
|
|
39
|
+
.tasks-drawer summary:hover { color: var(--deictic-fg); }
|
|
40
|
+
.tasks-drawer details .drawer-rows { margin-top: 6px; }
|
|
41
|
+
.tasks-drawer .put-away { justify-self: end; }
|
|
42
|
+
.tasks-drawer .act, .task-view .act { padding: 1px 6px; border: 0; font-size: 12px; color: var(--deictic-muted); }
|
|
43
|
+
.tasks-drawer .act:hover, .task-view .act:hover { color: var(--deictic-fg); }
|
|
44
|
+
.task-view { display: flex; flex-direction: column; gap: 8px; min-height: 0; font-size: 12px; }
|
|
45
|
+
.task-view .stands { display: flex; align-items: center; gap: 6px; color: var(--deictic-muted); }
|
|
46
|
+
.task-view .stands .says { flex: 1; }
|
|
47
|
+
.task-view .stands a { color: inherit; }
|
|
48
|
+
.task-view .stands a:hover { color: var(--deictic-fg); }
|
|
49
|
+
.task-view .act.sure { color: var(--deictic-problem); }
|
|
50
|
+
.task-view .where { align-self: start; max-width: 100%; padding: 0; border: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 11px ui-monospace, monospace; color: var(--deictic-accent); }
|
|
51
|
+
.task-view .where span { color: var(--deictic-muted); }
|
|
52
|
+
.task-view .words { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; }
|
|
53
|
+
.task-view .said { padding: 4px 8px; border-left: 2px solid var(--deictic-line); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--deictic-muted); }
|
|
54
|
+
.task-view .editing textarea { display: block; box-sizing: border-box; width: 100%; min-height: 56px; resize: vertical; font: 13px/1.45 system-ui, sans-serif; }
|
|
55
|
+
.task-view .buttons { display: flex; justify-content: end; gap: 6px; margin-top: 6px; }
|
|
56
|
+
/* What a task or a reply has attached: a chip each, which opens all of them in the lightbox. */
|
|
57
|
+
.task-files { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
58
|
+
.task-files:empty { display: none; }
|
|
59
|
+
/* One height, and a thumbnail one size, as the composer's chips: nothing moves as the pictures load. */
|
|
60
|
+
.task-files button { box-sizing: border-box; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; height: 26px; padding: 0 6px 0 2px; border: 1px solid var(--deictic-line); border-radius: 6px; font-size: 11px; }
|
|
61
|
+
.task-files button span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
62
|
+
.task-files img { flex: none; display: block; width: 30px; height: 20px; object-fit: cover; border-radius: 4px; background: var(--deictic-line); }
|
|
63
|
+
.task-files .play { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 4px; background: var(--deictic-line); }
|
|
64
|
+
.task-files .play svg { width: 10px; height: 10px; }
|
|
65
|
+
.task-thread { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 0; padding: 8px 0 0; border-top: 1px solid rgb(255 255 255 / 0.08); list-style: none; }
|
|
66
|
+
.task-thread:empty { display: none; }
|
|
67
|
+
.task-thread li { display: grid; gap: 4px; padding: 6px 8px; border: 1px solid rgb(255 255 255 / 0.08); border-radius: 8px; background: rgb(255 255 255 / 0.04); }
|
|
68
|
+
.task-thread li.new { border-color: color-mix(in srgb, var(--deictic-accent) 55%, transparent); }
|
|
69
|
+
.task-thread .by { display: flex; gap: 6px; align-items: baseline; font-size: 11px; color: var(--deictic-muted); }
|
|
70
|
+
.task-thread .by b { font-weight: 600; color: var(--deictic-fg); }
|
|
71
|
+
.task-thread .by i { margin-left: auto; font-style: normal; }
|
|
72
|
+
.task-thread .text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
|
|
73
|
+
.task-view .problem { color: var(--deictic-problem); }
|
|
74
|
+
.task-view .problem:empty { display: none; }
|
|
75
|
+
/* On the page, around an element a task is about: the open task's, and each one attached in the Task tab. */
|
|
76
|
+
.task-about { position: fixed; z-index: 2147483646; box-sizing: border-box; pointer-events: none; border: 1.5px dashed var(--deictic-accent); border-radius: 6px; }
|
|
77
|
+
.task-about[hidden] { display: none; }
|
|
78
|
+
${COMPOSER_STYLE}`;
|
|
79
|
+
|
|
80
|
+
/** How often an open task's thread is read again, in ms: an agent answers while it's looked at. */
|
|
81
|
+
const AGAIN = 5000;
|
|
82
|
+
/** How long Delete waits to be pressed again, in ms, before it's only Delete once more. */
|
|
83
|
+
const SURE = 3000;
|
|
84
|
+
/** Where what's typed in a reply is kept while its task isn't open: for the tab, over page loads. */
|
|
85
|
+
const DRAFTS = 'deictic:tasks:drafts';
|
|
86
|
+
const FILE =
|
|
87
|
+
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M6 3h8l4 4v14H6zM14 3v4h4"/></svg>';
|
|
88
|
+
|
|
89
|
+
/** `now`, `5m`, `2h`, `3d`: how long ago, as short as a thread's margin. */
|
|
90
|
+
function ago(at: string): string {
|
|
91
|
+
const minutes = Math.round((Date.now() - Date.parse(at)) / 60_000);
|
|
92
|
+
if (!(minutes >= 1)) return 'now';
|
|
93
|
+
if (minutes < 60) return `${minutes}m`;
|
|
94
|
+
return minutes < 60 * 24 ? `${Math.round(minutes / 60)}h` : `${Math.round(minutes / (60 * 24))}d`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** What's typed in each task's reply, by its ID. */
|
|
98
|
+
function drafts(): Record<string, string> {
|
|
99
|
+
try {
|
|
100
|
+
const kept: unknown = JSON.parse(sessionStorage.getItem(DRAFTS) ?? '{}');
|
|
101
|
+
return typeof kept === 'object' && kept !== null ? (kept as Record<string, string>) : {};
|
|
102
|
+
} catch {
|
|
103
|
+
// Storage can be off: nothing's kept, then.
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function keepDraft(id: string, text: string): void {
|
|
109
|
+
const { [id]: _, ...rest } = drafts();
|
|
110
|
+
try {
|
|
111
|
+
sessionStorage.setItem(DRAFTS, JSON.stringify(text.trim() === '' ? rest : { ...rest, [id]: text }));
|
|
112
|
+
} catch {
|
|
113
|
+
// Not kept past the page, then.
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** A board's file as a person names it: what it is, not what deictic called it. */
|
|
118
|
+
function nameOf(file: Attached, i: number, all: Attached[]): string {
|
|
119
|
+
const alike = all.filter((other) => kindOf(other) === kindOf(file));
|
|
120
|
+
const n = alike.length === 1 ? '' : ` ${alike.indexOf(file) + 1}`;
|
|
121
|
+
const kind = kindOf(file);
|
|
122
|
+
if (kind === 'image') return `Screenshot${n}`;
|
|
123
|
+
if (kind === 'recording') return `Recording${n}`;
|
|
124
|
+
if (kind === 'audio') return `Voice note${n}`;
|
|
125
|
+
if (/^element(\.\d+)?\.html$/.test(file.name)) return `HTML${n}`;
|
|
126
|
+
return file.name || `File ${i + 1}`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const kindOf = ({ type, name }: Attached) =>
|
|
130
|
+
type.startsWith('image/') ? 'image' : name.startsWith('recording-') ? 'recording' : type.startsWith('audio/') ? 'audio' : 'file';
|
|
131
|
+
|
|
132
|
+
export interface TasksDrawer {
|
|
133
|
+
/** Opens a task in the drawer, or several to pick from: a pin's. */
|
|
134
|
+
open: (tasks: Listed[]) => void;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const made = new WeakMap<ShadowRoot, TasksDrawer>();
|
|
138
|
+
|
|
139
|
+
/** The tasks' section in the drawer of the overlay `context` is of: added the first time it's asked for. */
|
|
140
|
+
export function drawerOf(context: ClientContext): TasksDrawer {
|
|
141
|
+
const known = made.get(context.root);
|
|
142
|
+
if (known !== undefined) return known;
|
|
143
|
+
|
|
144
|
+
const store = storeOf(context);
|
|
145
|
+
const section = element('section', { className: 'tasks-drawer', hidden: true });
|
|
146
|
+
const heading = element('h3');
|
|
147
|
+
const rows = element('div', { className: 'drawer-rows' });
|
|
148
|
+
const finished = element('details');
|
|
149
|
+
const finishedCount = element('summary');
|
|
150
|
+
const finishedRows = element('div', { className: 'drawer-rows' });
|
|
151
|
+
const putAway = element('button', {
|
|
152
|
+
type: 'button',
|
|
153
|
+
className: 'act put-away',
|
|
154
|
+
textContent: 'Archive all',
|
|
155
|
+
title: 'Put the finished tasks away: one comes back when something happens to it',
|
|
156
|
+
});
|
|
157
|
+
putAway.addEventListener('click', () => store.archive(store.tasks().filter((task) => OVER.has(task.state))));
|
|
158
|
+
finishedRows.append(putAway);
|
|
159
|
+
finished.append(finishedCount, finishedRows);
|
|
160
|
+
section.append(element('style', { textContent: STYLE }), heading, rows, finished);
|
|
161
|
+
|
|
162
|
+
const elementOf = (task: Listed) =>
|
|
163
|
+
task.place === undefined ? null : document.querySelector(`[${ATTRIBUTE}="${CSS.escape(task.place)}"]`);
|
|
164
|
+
/** What a task is about, as the caption says an element: by its component where the page has it, else its tag. */
|
|
165
|
+
const about = (task: Listed) => {
|
|
166
|
+
if (task.place === undefined) return 'the page';
|
|
167
|
+
const el = elementOf(task);
|
|
168
|
+
if (el !== null) return tell(named(el));
|
|
169
|
+
// Not on this page: its tag as the task saw it, and the page it was on where that's another.
|
|
170
|
+
const on = task.page === undefined || task.page === location.pathname ? '' : ` on ${task.page}`;
|
|
171
|
+
return `${task.tag === undefined ? 'an element' : `<${task.tag}>`}${on}`;
|
|
172
|
+
};
|
|
173
|
+
/** Lights a task's element on the page while the pointer is on what stands for it here. */
|
|
174
|
+
const lights = (on: HTMLElement, task: () => Listed) => {
|
|
175
|
+
on.addEventListener('pointerenter', () => context.light(elementOf(task()) ?? undefined));
|
|
176
|
+
on.addEventListener('pointerleave', () => context.light());
|
|
177
|
+
};
|
|
178
|
+
const rowOf = (task: Listed) => {
|
|
179
|
+
const row = element('button', { type: 'button', className: `task-row${store.unread(task) ? ' unread' : ''}` });
|
|
180
|
+
const says = task.by === undefined ? task.state : `${task.state} by ${task.by}`;
|
|
181
|
+
const replies = task.replies === 0 ? '' : ` · ${task.replies} ${task.replies === 1 ? 'reply' : 'replies'}`;
|
|
182
|
+
row.append(
|
|
183
|
+
element('span', { className: `task-state ${task.state}`, ariaHidden: 'true' }),
|
|
184
|
+
element('span', { className: 'title', textContent: task.title }),
|
|
185
|
+
element('span', { className: 'meta', textContent: `${says} · ${about(task)}${replies}` }),
|
|
186
|
+
element('span', { className: 'mark', ...(store.unread(task) ? { title: 'Unread' } : {}) }),
|
|
187
|
+
);
|
|
188
|
+
lights(row, () => task);
|
|
189
|
+
row.addEventListener('click', () => {
|
|
190
|
+
context.light();
|
|
191
|
+
view(task);
|
|
192
|
+
});
|
|
193
|
+
return row;
|
|
194
|
+
};
|
|
195
|
+
const draw = () => {
|
|
196
|
+
const tasks = store.tasks().filter((task) => !store.archived(task));
|
|
197
|
+
const live = tasks.filter((task) => !OVER.has(task.state));
|
|
198
|
+
const ended = tasks.filter((task) => OVER.has(task.state));
|
|
199
|
+
section.hidden = tasks.length === 0;
|
|
200
|
+
const unread = tasks.filter(store.unread).length;
|
|
201
|
+
// For the drawer folded away: what's still to do, and what's unread.
|
|
202
|
+
section.dataset.count = String(live.length);
|
|
203
|
+
section.dataset.unread = String(unread);
|
|
204
|
+
const channel = store.channel();
|
|
205
|
+
heading.replaceChildren(
|
|
206
|
+
'Tasks',
|
|
207
|
+
...(unread === 0 ? [] : [element('span', { className: 'unread', textContent: String(unread), title: `${unread} unread` })]),
|
|
208
|
+
...(channel?.link === undefined
|
|
209
|
+
? []
|
|
210
|
+
: [
|
|
211
|
+
element('a', {
|
|
212
|
+
href: channel.link,
|
|
213
|
+
target: '_blank',
|
|
214
|
+
rel: 'noreferrer',
|
|
215
|
+
textContent: `#${channel.name}`,
|
|
216
|
+
title: 'Open the channel on the board',
|
|
217
|
+
}),
|
|
218
|
+
]),
|
|
219
|
+
);
|
|
220
|
+
rows.replaceChildren(...live.map(rowOf));
|
|
221
|
+
finished.hidden = ended.length === 0;
|
|
222
|
+
const news = ended.filter(store.unread).length;
|
|
223
|
+
finishedCount.textContent = `${ended.length} finished${news === 0 ? '' : `, ${news} unread`}`;
|
|
224
|
+
finishedRows.replaceChildren(...ended.map(rowOf), putAway);
|
|
225
|
+
};
|
|
226
|
+
store.subscribe(draw);
|
|
227
|
+
context.drawer.add(section, { first: true });
|
|
228
|
+
|
|
229
|
+
const ask = async <T>(route: string, body?: unknown): Promise<T> => {
|
|
230
|
+
const res = await context.request(
|
|
231
|
+
route,
|
|
232
|
+
body === undefined ? undefined : { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) },
|
|
233
|
+
);
|
|
234
|
+
const answer = (await res.json()) as T & { problem?: string };
|
|
235
|
+
if (!res.ok) throw new Error(answer.problem ?? `the dev server answered ${res.status}`);
|
|
236
|
+
return answer;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/** A message's files as chips, each opening them all in the lightbox at itself. */
|
|
240
|
+
const filesOf = (task: string, files: Attached[]): HTMLElement => {
|
|
241
|
+
const list = element('div', { className: 'task-files' });
|
|
242
|
+
const urlOf = (file: Attached) =>
|
|
243
|
+
file.url ?? `${context.base}__deictic/plugins/tasks/file/${encodeURIComponent(task)}/${encodeURIComponent(file.id)}`;
|
|
244
|
+
// What the lightbox shows of each: a picture, a sound, a recording's replay, or a file as text.
|
|
245
|
+
const items: LightboxItem[] = files.map((file, i) => {
|
|
246
|
+
const title = nameOf(file, i, files);
|
|
247
|
+
const kind = kindOf(file);
|
|
248
|
+
if (kind === 'image') return { kind: 'image', url: urlOf(file), title };
|
|
249
|
+
if (kind === 'audio') return { kind: 'audio', url: urlOf(file), title };
|
|
250
|
+
const replay = kind === 'recording' ? file.replay : undefined;
|
|
251
|
+
const url = replay === undefined ? urlOf(file) : `${replay}${replay.includes('?') ? '&' : '?'}embed`;
|
|
252
|
+
const open = replay ?? urlOf(file);
|
|
253
|
+
return {
|
|
254
|
+
kind: 'page',
|
|
255
|
+
url,
|
|
256
|
+
title,
|
|
257
|
+
actions: [{ label: 'New tab', title: 'Open it in a tab of its own', run: () => void window.open(open, '_blank', 'noopener') }],
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
list.append(
|
|
261
|
+
...files.map((file, i) => {
|
|
262
|
+
const name = nameOf(file, i, files);
|
|
263
|
+
// `Open screenshot 2`, but `Open HTML`.
|
|
264
|
+
const said = /^[A-Z]{2}/.test(name) ? name : `${name[0]!.toLowerCase()}${name.slice(1)}`;
|
|
265
|
+
const chip = element('button', { type: 'button', title: `Open ${said}` });
|
|
266
|
+
const kind = kindOf(file);
|
|
267
|
+
const icon =
|
|
268
|
+
kind === 'image'
|
|
269
|
+
? element('img', { src: urlOf(file), alt: '', loading: 'lazy' })
|
|
270
|
+
: element('span', { className: 'play', innerHTML: kind === 'file' ? FILE : PLAY });
|
|
271
|
+
chip.append(icon, element('span', { textContent: name }));
|
|
272
|
+
chip.addEventListener('click', () => context.lightbox(items, { at: i, from: chip }));
|
|
273
|
+
return chip;
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
return list;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/** A task, open in the drawer: its words, what's attached, its thread, and what changes them. */
|
|
280
|
+
function view(first: Listed): void {
|
|
281
|
+
let task = first;
|
|
282
|
+
let editing = false;
|
|
283
|
+
// The reply that was its newest when it was last read: those after it are new, this once.
|
|
284
|
+
const readTo = store.read(first);
|
|
285
|
+
const fresh = store.unread(first);
|
|
286
|
+
// What was answered from here: never new to who wrote it.
|
|
287
|
+
const mine = new Set<string>();
|
|
288
|
+
const recorder = context.use('recordings');
|
|
289
|
+
|
|
290
|
+
const el = element('div', { className: 'task-view' });
|
|
291
|
+
const stands = element('div', { className: 'stands' });
|
|
292
|
+
const where = element('button', { type: 'button', className: 'where' });
|
|
293
|
+
const words = element('div');
|
|
294
|
+
const files = element('div');
|
|
295
|
+
const said = element('div', { className: 'said' });
|
|
296
|
+
const thread = element('ol', { className: 'task-thread' });
|
|
297
|
+
const problem = element('div', { className: 'problem' });
|
|
298
|
+
// The task's element, lit on the page while the pointer is on its name, as its row's is.
|
|
299
|
+
lights(where, () => task);
|
|
300
|
+
|
|
301
|
+
const composer: Composer = composerIn(context, {
|
|
302
|
+
placeholder: 'Reply…',
|
|
303
|
+
sendLabel: 'Reply',
|
|
304
|
+
over: true,
|
|
305
|
+
// What's typed is kept, the drawer closes, and the page is recorded: stopped, the recording is in the tray,
|
|
306
|
+
// and the task opened again has it and the words.
|
|
307
|
+
record: () => {
|
|
308
|
+
if (recorder === undefined) return;
|
|
309
|
+
if (recorder.recording()) {
|
|
310
|
+
composer.problem.textContent = "A recording is going already: stop it in the tool panel, and it's attached here";
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
close();
|
|
314
|
+
void recorder.record();
|
|
315
|
+
},
|
|
316
|
+
submit: async (gathered) => {
|
|
317
|
+
const answer: Answer = { text: gathered.text, ...attachedOf(gathered) };
|
|
318
|
+
const after = await ask<Thread>(`reply/${encodeURIComponent(task.id)}`, answer);
|
|
319
|
+
const last = after.replies.at(-1);
|
|
320
|
+
if (last !== undefined) mine.add(last.id);
|
|
321
|
+
shown(after);
|
|
322
|
+
keepDraft(task.id, '');
|
|
323
|
+
store.load(true);
|
|
324
|
+
return true;
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
composer.restore({ text: drafts()[first.id] ?? '' });
|
|
328
|
+
el.append(stands, where, words, files, said, thread, composer.el, problem);
|
|
329
|
+
|
|
330
|
+
// The element it's about, outlined on the page while it's open, and shown by a press on its name.
|
|
331
|
+
const outline = element('div', { className: 'task-about', hidden: true });
|
|
332
|
+
context.root.append(outline);
|
|
333
|
+
let following = requestAnimationFrame(function follow() {
|
|
334
|
+
following = requestAnimationFrame(follow);
|
|
335
|
+
const it = elementOf(task);
|
|
336
|
+
outline.hidden = it === null;
|
|
337
|
+
if (it !== null) place(outline, it.getBoundingClientRect());
|
|
338
|
+
});
|
|
339
|
+
where.addEventListener('click', () => elementOf(task)?.scrollIntoView({ block: 'center', behavior: 'smooth' }));
|
|
340
|
+
|
|
341
|
+
const failed = (e: unknown) => (problem.textContent = messageOf(e));
|
|
342
|
+
let removing: ReturnType<typeof setTimeout> | undefined;
|
|
343
|
+
const drawTask = () => {
|
|
344
|
+
const state = element('span', { className: `task-state ${task.state}`, ariaHidden: 'true' });
|
|
345
|
+
const says = element('span', { className: 'says', textContent: task.by === undefined ? task.state : `${task.state} by ${task.by}` });
|
|
346
|
+
const to =
|
|
347
|
+
task.link === undefined
|
|
348
|
+
? []
|
|
349
|
+
: [
|
|
350
|
+
element('a', {
|
|
351
|
+
href: task.link,
|
|
352
|
+
target: '_blank',
|
|
353
|
+
rel: 'noreferrer',
|
|
354
|
+
textContent: 'on the board',
|
|
355
|
+
title: 'Open the task on the board',
|
|
356
|
+
}),
|
|
357
|
+
];
|
|
358
|
+
const edit = element('button', { type: 'button', className: 'act', textContent: 'Edit', title: 'Change its words' });
|
|
359
|
+
edit.addEventListener('click', () => {
|
|
360
|
+
editing = true;
|
|
361
|
+
drawWords();
|
|
362
|
+
});
|
|
363
|
+
// Twice, as nothing brings a task back: a board never reopens one it canceled.
|
|
364
|
+
const remove = element('button', { type: 'button', className: 'act', textContent: 'Delete', title: 'Cancel it on the board' });
|
|
365
|
+
remove.addEventListener('click', () => {
|
|
366
|
+
if (!remove.classList.contains('sure')) {
|
|
367
|
+
remove.classList.add('sure');
|
|
368
|
+
remove.textContent = 'Delete?';
|
|
369
|
+
removing = setTimeout(() => {
|
|
370
|
+
remove.classList.remove('sure');
|
|
371
|
+
remove.textContent = 'Delete';
|
|
372
|
+
}, SURE);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
remove.disabled = true;
|
|
376
|
+
ask(`remove/${encodeURIComponent(task.id)}`, {}).then(() => {
|
|
377
|
+
store.load(true);
|
|
378
|
+
close();
|
|
379
|
+
}, failed);
|
|
380
|
+
});
|
|
381
|
+
// A finished one is put away from here, as the list puts them all away.
|
|
382
|
+
const archive = element('button', {
|
|
383
|
+
type: 'button',
|
|
384
|
+
className: 'act',
|
|
385
|
+
textContent: 'Archive',
|
|
386
|
+
title: 'Put it away: it comes back when something happens to it',
|
|
387
|
+
});
|
|
388
|
+
archive.addEventListener('click', () => {
|
|
389
|
+
store.archive([task]);
|
|
390
|
+
close();
|
|
391
|
+
});
|
|
392
|
+
// Edit and Delete only for one no one has claimed, as on the board.
|
|
393
|
+
stands.replaceChildren(state, says, ...to, ...(task.open ? [edit, remove] : []), ...(OVER.has(task.state) ? [archive] : []));
|
|
394
|
+
const at = task.place?.replace(/:\d+$/, '');
|
|
395
|
+
where.replaceChildren(about(task), ...(at === undefined ? [] : [element('span', { textContent: ` ${at}` })]));
|
|
396
|
+
where.disabled = elementOf(task) === null;
|
|
397
|
+
where.title = task.place === undefined ? 'No element was attached' : where.disabled ? 'Not on this page now' : 'Show it on the page';
|
|
398
|
+
said.hidden = task.said === undefined;
|
|
399
|
+
said.textContent = task.said ?? '';
|
|
400
|
+
};
|
|
401
|
+
const drawWords = () => {
|
|
402
|
+
if (!editing) {
|
|
403
|
+
words.className = 'words';
|
|
404
|
+
words.replaceChildren(task.text);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const text = element('textarea', { value: task.text });
|
|
408
|
+
const save = element('button', { type: 'button', className: 'primary', textContent: 'Save' });
|
|
409
|
+
const leave = element('button', { type: 'button', textContent: 'Cancel' });
|
|
410
|
+
const buttons = element('div', { className: 'buttons' });
|
|
411
|
+
buttons.append(leave, save);
|
|
412
|
+
const done = () => {
|
|
413
|
+
editing = false;
|
|
414
|
+
drawWords();
|
|
415
|
+
};
|
|
416
|
+
const keep = () => {
|
|
417
|
+
if (text.value.trim() === '') return;
|
|
418
|
+
if (text.value.trim() === task.text) return done();
|
|
419
|
+
save.disabled = true;
|
|
420
|
+
ask<Thread>(`edit/${encodeURIComponent(task.id)}`, { text: text.value }).then(
|
|
421
|
+
(answer) => {
|
|
422
|
+
editing = false;
|
|
423
|
+
shown(answer);
|
|
424
|
+
store.load(true);
|
|
425
|
+
},
|
|
426
|
+
(e: unknown) => {
|
|
427
|
+
save.disabled = false;
|
|
428
|
+
failed(e);
|
|
429
|
+
},
|
|
430
|
+
);
|
|
431
|
+
};
|
|
432
|
+
text.addEventListener('keydown', (e) => {
|
|
433
|
+
if (e.key === 'Escape') {
|
|
434
|
+
// The words' alone: the task stays open.
|
|
435
|
+
e.stopPropagation();
|
|
436
|
+
done();
|
|
437
|
+
}
|
|
438
|
+
// Enter saves, as the composer sends; Shift+Enter is a new line.
|
|
439
|
+
if (e.key !== 'Enter' || e.shiftKey || e.isComposing) return;
|
|
440
|
+
e.preventDefault();
|
|
441
|
+
keep();
|
|
442
|
+
});
|
|
443
|
+
save.addEventListener('click', keep);
|
|
444
|
+
leave.addEventListener('click', done);
|
|
445
|
+
words.className = 'editing';
|
|
446
|
+
words.replaceChildren(text, buttons);
|
|
447
|
+
text.focus();
|
|
448
|
+
};
|
|
449
|
+
// What the thread was drawn from, so reading it again redraws only what changed: pictures don't blink.
|
|
450
|
+
let drawn = '';
|
|
451
|
+
/** The task and its thread as just read: drawn, and read by whoever is looking. */
|
|
452
|
+
const shown = (answer: Thread) => {
|
|
453
|
+
task = answer.task;
|
|
454
|
+
problem.textContent = '';
|
|
455
|
+
drawTask();
|
|
456
|
+
if (!editing) drawWords();
|
|
457
|
+
const now = JSON.stringify([answer.files.map((f) => f.id), answer.replies.map((r) => [r.id, r.text, r.files.length]), [...mine]]);
|
|
458
|
+
if (now !== drawn) {
|
|
459
|
+
drawn = now;
|
|
460
|
+
files.replaceChildren(filesOf(task.id, answer.files));
|
|
461
|
+
const from = readTo === undefined ? -1 : answer.replies.findIndex((r) => r.id === readTo);
|
|
462
|
+
// At its end only if it has grown: reading up the thread isn't pulled back down.
|
|
463
|
+
const grew = answer.replies.length !== thread.childElementCount;
|
|
464
|
+
thread.replaceChildren(
|
|
465
|
+
...answer.replies.map((r, i) => {
|
|
466
|
+
const item = element('li', { className: fresh && i > from && !mine.has(r.id) ? 'new' : '' });
|
|
467
|
+
const by = element('div', { className: 'by' });
|
|
468
|
+
by.append(
|
|
469
|
+
element('b', { textContent: r.by }),
|
|
470
|
+
...(r.kind === 'person' ? [] : ['agent']),
|
|
471
|
+
element('i', { textContent: ago(r.at), title: new Date(r.at).toLocaleString() }),
|
|
472
|
+
);
|
|
473
|
+
item.append(by, element('div', { className: 'text', textContent: r.text }), filesOf(task.id, r.files));
|
|
474
|
+
return item;
|
|
475
|
+
}),
|
|
476
|
+
);
|
|
477
|
+
if (grew) thread.lastElementChild?.scrollIntoView({ block: 'nearest' });
|
|
478
|
+
}
|
|
479
|
+
store.seen(task);
|
|
480
|
+
};
|
|
481
|
+
const load = () => ask<Thread>(`thread/${encodeURIComponent(task.id)}`).then(shown, failed);
|
|
482
|
+
|
|
483
|
+
drawTask();
|
|
484
|
+
drawWords();
|
|
485
|
+
void load();
|
|
486
|
+
const again = setInterval(() => void load(), AGAIN);
|
|
487
|
+
const close = context.drawer.show(el, {
|
|
488
|
+
title: `#${task.id}`,
|
|
489
|
+
closed: () => {
|
|
490
|
+
keepDraft(task.id, composer.draft().text);
|
|
491
|
+
composer.destroy();
|
|
492
|
+
context.light();
|
|
493
|
+
clearInterval(again);
|
|
494
|
+
clearTimeout(removing);
|
|
495
|
+
cancelAnimationFrame(following);
|
|
496
|
+
outline.remove();
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** Several tasks of one place, to pick from. */
|
|
502
|
+
const pick = (tasks: Listed[]) => {
|
|
503
|
+
const el = element('div', { className: 'drawer-rows' });
|
|
504
|
+
el.append(...tasks.map(rowOf));
|
|
505
|
+
context.drawer.show(el, { title: `${tasks.length} tasks on ${about(tasks[0]!)}`, closed: () => context.light() });
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
const drawer: TasksDrawer = {
|
|
509
|
+
open: (tasks) => {
|
|
510
|
+
if (tasks.length === 1) view(tasks[0]!);
|
|
511
|
+
else if (tasks.length > 1) pick(tasks);
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
made.set(context.root, drawer);
|
|
515
|
+
return drawer;
|
|
516
|
+
}
|