pi-pocket 0.25.0 → 0.26.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/AGENTS.md +2 -0
- package/README.md +5 -3
- package/docs/architecture.md +21 -0
- package/docs/design/design-mode.md +108 -0
- package/docs/design/notes-a.md +106 -0
- package/docs/design/notes-b.md +123 -0
- package/docs/design/notes-c.md +92 -0
- package/docs/design/notes-d.md +78 -0
- package/docs/design/release-notes-design.md +46 -0
- package/docs/extensions/browser-modules.md +2 -0
- package/docs/extensions/policies/api-stability.md +2 -0
- package/docs/extensions/reference/api-versions.md +1 -0
- package/docs/extensions/reference/host.md +1 -1
- package/docs/extensions/reference/limits.md +4 -0
- package/docs/extensions/reference/names.md +2 -2
- package/docs/extensions/reference/pocket.md +38 -0
- package/docs/features.md +19 -5
- package/docs/map.md +75 -54
- package/docs/release-notes.md +1 -1
- package/docs/self-editing.md +1 -1
- package/docs/systemd.md +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/src/launcher/main.ts +20 -9
- package/src/server/app.ts +113 -4
- package/src/server/background.ts +3 -3
- package/src/server/cache-keeper.ts +605 -0
- package/src/server/compaction.ts +68 -15
- package/src/server/design/bundle.ts +65 -0
- package/src/server/design/export.ts +118 -0
- package/src/server/design/files.ts +49 -0
- package/src/server/design/guide.ts +56 -0
- package/src/server/design/index.ts +232 -0
- package/src/server/design/pptx.ts +304 -0
- package/src/server/design/render.ts +593 -0
- package/src/server/design/system.ts +248 -0
- package/src/server/docs.ts +55 -0
- package/src/server/extensions/artifacts.ts +202 -18
- package/src/server/extensions/design/canvas.js +304 -0
- package/src/server/extensions/design/comments.js +15 -0
- package/src/server/extensions/design/data.js +263 -0
- package/src/server/extensions/design/devices.js +70 -0
- package/src/server/extensions/design/docks.js +647 -0
- package/src/server/extensions/design/edits.js +37 -0
- package/src/server/extensions/design/index.js +326 -0
- package/src/server/extensions/design/messages.js +92 -0
- package/src/server/extensions/design/parts.js +160 -0
- package/src/server/extensions/design/state.js +146 -0
- package/src/server/extensions/design/style.css +1332 -0
- package/src/server/extensions/design/tweaks.js +161 -0
- package/src/server/extensions/design/views.js +375 -0
- package/src/server/extensions/design/workspace.js +723 -0
- package/src/server/extensions/design.ts +620 -0
- package/src/server/extensions/plan.ts +11 -9
- package/src/server/extensions/prompt.ts +11 -3
- package/src/server/extensions/subagents.ts +7 -1
- package/src/server/extensions/updates/index.js +16 -6
- package/src/server/extensions/updates.ts +2 -2
- package/src/server/http/artifact-assets.ts +216 -0
- package/src/server/http/artifact-inspect.ts +1281 -0
- package/src/server/http/artifacts.ts +89 -14
- package/src/server/http/conversation-routes.ts +46 -1
- package/src/server/http.ts +12 -4
- package/src/server/main.ts +4 -0
- package/src/server/npm-install.ts +82 -0
- package/src/server/npm-update.ts +100 -0
- package/src/server/reload.ts +5 -0
- package/src/server/room.ts +2 -0
- package/src/server/spend.ts +73 -9
- package/src/server/update-state.ts +257 -8
- package/src/server/updates.ts +268 -33
- package/src/server/zip.ts +163 -0
- package/types/pocket.d.ts +32 -0
- package/web/activity-fold.js +28 -0
- package/web/artifact-bridge.js +506 -82
- package/web/extension-ui.js +21 -1
- package/web/pip.js +46 -9
- package/web/sessions.js +1 -1
- package/web/sheets/appearance.js +10 -0
- package/web/sheets/viewers.js +26 -1
- package/web/style.css +11 -0
- package/web/taps.js +26 -0
- package/web/theme.js +6 -0
- package/web/transcript.js +19 -10
- package/src/server/http/public.ts +0 -30
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
// The side panel of the workspace: versions, comments, text edits, and tweaks. On a wide panel it sits beside the canvas,
|
|
2
|
+
// on a narrow one under it.
|
|
3
|
+
import { openOf, pinNumber } from "./comments.js";
|
|
4
|
+
import { nameOf } from "./edits.js";
|
|
5
|
+
import { commentsMessage, editsMessage, tweaksMessage } from "./messages.js";
|
|
6
|
+
import { changed, coerce, show } from "./tweaks.js";
|
|
7
|
+
|
|
8
|
+
export function createDocks(env) {
|
|
9
|
+
const { pocket, store, data, parts } = env;
|
|
10
|
+
const { html, useEffect, useRef, useState, Switch } = pocket;
|
|
11
|
+
const { Ico, ago } = parts;
|
|
12
|
+
|
|
13
|
+
const versionTitle = (version, latest) =>
|
|
14
|
+
`${version.version === latest ? "Newest" : `Version ${version.version}`}${version.restoredFrom ? ` · from v${version.restoredFrom}` : ""}`;
|
|
15
|
+
const versionNote = (version) =>
|
|
16
|
+
`${ago(version.createdAt)} · ${(version.size / 1024).toFixed(1)} KB`;
|
|
17
|
+
const confirmText = (latest, from) =>
|
|
18
|
+
`Make version ${latest + 1} from version ${from}? Nothing is lost: every version stays.`;
|
|
19
|
+
|
|
20
|
+
function DockHead({ title, count, children }) {
|
|
21
|
+
return html`<header class="dsn-dock-head">
|
|
22
|
+
<h3>${title}${count > 0 && html` <span class="dsn-count">${count}</span>`}</h3>
|
|
23
|
+
<span class="grow"></span>
|
|
24
|
+
${children}
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
class="icon-button"
|
|
28
|
+
title="Close"
|
|
29
|
+
aria-label="Close"
|
|
30
|
+
onClick=${() => env.setDock(null)}
|
|
31
|
+
>
|
|
32
|
+
<${Ico} name="close" size=${16} />
|
|
33
|
+
</button>
|
|
34
|
+
</header>`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ─── Versions ────────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
function VersionsDock({ s, design, shown, canEdit }) {
|
|
40
|
+
const [asking, setAsking] = useState(null);
|
|
41
|
+
const [busy, setBusy] = useState(false);
|
|
42
|
+
const latest = design.versions.at(-1)?.version ?? 1;
|
|
43
|
+
const list = [...design.versions].reverse();
|
|
44
|
+
|
|
45
|
+
const goBack = async (version) => {
|
|
46
|
+
setBusy(true);
|
|
47
|
+
|
|
48
|
+
const made = await data.restore(design.id, version);
|
|
49
|
+
|
|
50
|
+
setBusy(false);
|
|
51
|
+
setAsking(null);
|
|
52
|
+
|
|
53
|
+
if (made !== null) {
|
|
54
|
+
env.showVersion(null);
|
|
55
|
+
pocket.notify("info", `Version ${made} is a copy of version ${version}.`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return html`<${DockHead} title="Versions" count=${design.versions.length}>
|
|
60
|
+
${
|
|
61
|
+
list.length > 1 &&
|
|
62
|
+
html`<button
|
|
63
|
+
type="button"
|
|
64
|
+
class="dsn-link"
|
|
65
|
+
onClick=${() => env.compare(shown === latest ? latest - 1 : shown, latest)}
|
|
66
|
+
>
|
|
67
|
+
<${Ico} name="compare" size=${14} /> Compare
|
|
68
|
+
</button>`
|
|
69
|
+
}
|
|
70
|
+
<//>
|
|
71
|
+
<div class="dsn-dock-body">
|
|
72
|
+
<ol class="dsn-versions">
|
|
73
|
+
${list.map(
|
|
74
|
+
(version) =>
|
|
75
|
+
html`<li
|
|
76
|
+
class=${`dsn-version ${version.version === shown ? "on" : ""}`}
|
|
77
|
+
key=${version.version}
|
|
78
|
+
>
|
|
79
|
+
<button
|
|
80
|
+
type="button"
|
|
81
|
+
class="dsn-version-main"
|
|
82
|
+
onClick=${() => env.showVersion(version.version === latest ? null : version.version)}
|
|
83
|
+
>
|
|
84
|
+
<span class="dsn-version-no mono">v${version.version}</span>
|
|
85
|
+
<span class="dsn-version-info">
|
|
86
|
+
<span>${versionTitle(version, latest)}</span>
|
|
87
|
+
<span class="muted small">${versionNote(version)}</span>
|
|
88
|
+
</span>
|
|
89
|
+
${version.version === shown && html`<${Ico} name="check" size=${15} />`}
|
|
90
|
+
</button>
|
|
91
|
+
<div class="dsn-version-actions">
|
|
92
|
+
${
|
|
93
|
+
version.version !== latest &&
|
|
94
|
+
html`<button
|
|
95
|
+
type="button"
|
|
96
|
+
class="dsn-link"
|
|
97
|
+
onClick=${() => env.compare(version.version, latest)}
|
|
98
|
+
>
|
|
99
|
+
Compare
|
|
100
|
+
</button>`
|
|
101
|
+
}
|
|
102
|
+
${
|
|
103
|
+
version.version !== latest &&
|
|
104
|
+
canEdit &&
|
|
105
|
+
asking !== version.version &&
|
|
106
|
+
html`<button
|
|
107
|
+
type="button"
|
|
108
|
+
class="dsn-link"
|
|
109
|
+
onClick=${() => setAsking(version.version)}
|
|
110
|
+
>
|
|
111
|
+
Go back to this one
|
|
112
|
+
</button>`
|
|
113
|
+
}
|
|
114
|
+
</div>
|
|
115
|
+
${
|
|
116
|
+
asking === version.version &&
|
|
117
|
+
html`<div
|
|
118
|
+
class="dsn-confirm"
|
|
119
|
+
ref=${(element) => element?.scrollIntoView({ block: "nearest" })}
|
|
120
|
+
>
|
|
121
|
+
<span>${confirmText(latest, version.version)}</span>
|
|
122
|
+
<span class="dsn-confirm-actions">
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
class="button small primary"
|
|
126
|
+
disabled=${busy}
|
|
127
|
+
onClick=${() => goBack(version.version)}
|
|
128
|
+
>
|
|
129
|
+
${busy ? "Making it…" : "Go back"}
|
|
130
|
+
</button>
|
|
131
|
+
<button
|
|
132
|
+
type="button"
|
|
133
|
+
class="button small"
|
|
134
|
+
disabled=${busy}
|
|
135
|
+
onClick=${() => setAsking(null)}
|
|
136
|
+
>
|
|
137
|
+
Cancel
|
|
138
|
+
</button>
|
|
139
|
+
</span>
|
|
140
|
+
</div>`
|
|
141
|
+
}
|
|
142
|
+
</li>`,
|
|
143
|
+
)}
|
|
144
|
+
</ol>
|
|
145
|
+
</div>`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ─── Comments ────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
function Composer({ design, draft, onDone }) {
|
|
151
|
+
const [text, setText] = useState("");
|
|
152
|
+
const [busy, setBusy] = useState(false);
|
|
153
|
+
const box = useRef(null);
|
|
154
|
+
|
|
155
|
+
useEffect(() => box.current?.focus({ preventScroll: true }), [draft]);
|
|
156
|
+
|
|
157
|
+
const submit = async () => {
|
|
158
|
+
if (text.trim() === "" || busy) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
setBusy(true);
|
|
163
|
+
|
|
164
|
+
const ok = await data.addComment(design.id, draft.version, draft.target, text.trim());
|
|
165
|
+
|
|
166
|
+
setBusy(false);
|
|
167
|
+
|
|
168
|
+
if (ok) {
|
|
169
|
+
setText("");
|
|
170
|
+
onDone();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
return html`<form
|
|
175
|
+
class="dsn-composer"
|
|
176
|
+
onSubmit=${(event) => {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
void submit();
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<div class="dsn-composer-target">
|
|
182
|
+
<${Ico} name="target" size=${14} />
|
|
183
|
+
<span>${nameOf(draft.target)}</span>
|
|
184
|
+
<span class="muted small mono">v${draft.version}</span>
|
|
185
|
+
</div>
|
|
186
|
+
<textarea
|
|
187
|
+
ref=${box}
|
|
188
|
+
rows="3"
|
|
189
|
+
placeholder="What should change here?"
|
|
190
|
+
maxlength="2000"
|
|
191
|
+
value=${text}
|
|
192
|
+
onInput=${(event) => setText(event.currentTarget.value)}
|
|
193
|
+
onKeyDown=${(event) => {
|
|
194
|
+
if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
void submit();
|
|
197
|
+
}
|
|
198
|
+
}}
|
|
199
|
+
></textarea>
|
|
200
|
+
<div class="dsn-composer-actions">
|
|
201
|
+
<button type="button" class="button small" onClick=${onDone}>Cancel</button>
|
|
202
|
+
<button
|
|
203
|
+
type="submit"
|
|
204
|
+
class="button small primary"
|
|
205
|
+
disabled=${busy || text.trim() === ""}
|
|
206
|
+
>
|
|
207
|
+
Add comment
|
|
208
|
+
</button>
|
|
209
|
+
</div>
|
|
210
|
+
</form>`;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function CommentsDock({ s, design, shown, canEdit, me }) {
|
|
214
|
+
const [showDone, setShowDone] = useState(false);
|
|
215
|
+
const sent = s.sent[design.id] ?? null;
|
|
216
|
+
const setSent = (ids) => store.set((now) => ({ sent: { ...now.sent, [design.id]: ids } }));
|
|
217
|
+
const notes = s.notes[design.id];
|
|
218
|
+
const comments = notes?.comments ?? [];
|
|
219
|
+
const open = openOf(comments);
|
|
220
|
+
const done = comments.filter((comment) => comment.resolved);
|
|
221
|
+
const draft = s.draft?.artifact === design.id ? s.draft : null;
|
|
222
|
+
|
|
223
|
+
const send = () => {
|
|
224
|
+
env.sendToBox(
|
|
225
|
+
commentsMessage({
|
|
226
|
+
title: design.title,
|
|
227
|
+
id: design.id,
|
|
228
|
+
version: shown,
|
|
229
|
+
comments: open,
|
|
230
|
+
}),
|
|
231
|
+
);
|
|
232
|
+
setSent(open.map((comment) => comment.id));
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const row = (comment) => {
|
|
236
|
+
const number = pinNumber(comments, comment, shown);
|
|
237
|
+
const mine = comment.by === me?.id || me?.role === "owner";
|
|
238
|
+
|
|
239
|
+
return html`<li
|
|
240
|
+
class=${`dsn-comment ${comment.resolved ? "done" : ""}`}
|
|
241
|
+
key=${comment.id}
|
|
242
|
+
>
|
|
243
|
+
<span class=${`dsn-pin ${number === 0 ? "off" : ""}`} aria-hidden="true"
|
|
244
|
+
>${number === 0 ? "·" : number}</span
|
|
245
|
+
>
|
|
246
|
+
<div class="dsn-comment-body">
|
|
247
|
+
<div class="dsn-comment-head">
|
|
248
|
+
<strong>${comment.byName || "Someone"}</strong>
|
|
249
|
+
<span class="muted small">${ago(comment.at)}</span>
|
|
250
|
+
${
|
|
251
|
+
comment.version !== shown &&
|
|
252
|
+
html`<button
|
|
253
|
+
type="button"
|
|
254
|
+
class="dsn-chip mono"
|
|
255
|
+
title=${`Show version ${comment.version}`}
|
|
256
|
+
onClick=${() => env.showVersion(comment.version === design.versions.at(-1)?.version ? null : comment.version)}
|
|
257
|
+
>
|
|
258
|
+
v${comment.version}
|
|
259
|
+
</button>`
|
|
260
|
+
}
|
|
261
|
+
</div>
|
|
262
|
+
<p>${comment.text}</p>
|
|
263
|
+
<div class="muted small dsn-comment-target">${nameOf(comment.target)}</div>
|
|
264
|
+
</div>
|
|
265
|
+
${
|
|
266
|
+
canEdit &&
|
|
267
|
+
html`<div class="dsn-comment-actions">
|
|
268
|
+
<button
|
|
269
|
+
type="button"
|
|
270
|
+
class="icon-button"
|
|
271
|
+
title=${comment.resolved ? "Open it again" : "Mark done"}
|
|
272
|
+
aria-label=${comment.resolved ? "Open it again" : "Mark done"}
|
|
273
|
+
onClick=${() => data.patchComment(design.id, comment.id, { resolved: !comment.resolved })}
|
|
274
|
+
>
|
|
275
|
+
<${Ico} name=${comment.resolved ? "undo" : "check"} size=${15} />
|
|
276
|
+
</button>
|
|
277
|
+
${
|
|
278
|
+
mine &&
|
|
279
|
+
html`<button
|
|
280
|
+
type="button"
|
|
281
|
+
class="icon-button"
|
|
282
|
+
title="Delete"
|
|
283
|
+
aria-label="Delete"
|
|
284
|
+
onClick=${() => data.removeComment(design.id, comment.id)}
|
|
285
|
+
>
|
|
286
|
+
<${Ico} name="trash" size=${15} />
|
|
287
|
+
</button>`
|
|
288
|
+
}
|
|
289
|
+
</div>`
|
|
290
|
+
}
|
|
291
|
+
</li>`;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
return html`<${DockHead} title="Comments" count=${open.length}>
|
|
295
|
+
${
|
|
296
|
+
canEdit &&
|
|
297
|
+
open.length > 0 &&
|
|
298
|
+
html`<button
|
|
299
|
+
type="button"
|
|
300
|
+
class="dsn-link"
|
|
301
|
+
onClick=${() =>
|
|
302
|
+
data.resolveMany(
|
|
303
|
+
design.id,
|
|
304
|
+
open.map((comment) => comment.id),
|
|
305
|
+
)}
|
|
306
|
+
>
|
|
307
|
+
All done
|
|
308
|
+
</button>`
|
|
309
|
+
}
|
|
310
|
+
<//>
|
|
311
|
+
<div class="dsn-dock-body">
|
|
312
|
+
${
|
|
313
|
+
!canEdit &&
|
|
314
|
+
html`<p class="muted small dsn-note">
|
|
315
|
+
You can read the comments here. Only people who can steer the session add
|
|
316
|
+
them.
|
|
317
|
+
</p>`
|
|
318
|
+
}
|
|
319
|
+
${
|
|
320
|
+
draft &&
|
|
321
|
+
canEdit &&
|
|
322
|
+
html`<${Composer}
|
|
323
|
+
key=${draft.target.selector}
|
|
324
|
+
design=${design}
|
|
325
|
+
draft=${draft}
|
|
326
|
+
onDone=${() => store.set({ draft: null })}
|
|
327
|
+
/>`
|
|
328
|
+
}
|
|
329
|
+
${
|
|
330
|
+
open.length === 0 &&
|
|
331
|
+
!draft &&
|
|
332
|
+
html`<p class="muted small dsn-empty">
|
|
333
|
+
${canEdit ? "No open comments. Turn on Comment, then tap an element." : "No open comments."}
|
|
334
|
+
</p>`
|
|
335
|
+
}
|
|
336
|
+
<ul class="dsn-comments">
|
|
337
|
+
${open.map(row)}
|
|
338
|
+
</ul>
|
|
339
|
+
${
|
|
340
|
+
done.length > 0 &&
|
|
341
|
+
html`<button
|
|
342
|
+
type="button"
|
|
343
|
+
class="dsn-link dsn-done-toggle"
|
|
344
|
+
onClick=${() => setShowDone(!showDone)}
|
|
345
|
+
>
|
|
346
|
+
${showDone ? "Hide" : "Show"} done (${done.length})
|
|
347
|
+
</button>`
|
|
348
|
+
}
|
|
349
|
+
${
|
|
350
|
+
showDone &&
|
|
351
|
+
html`<ul class="dsn-comments">
|
|
352
|
+
${done.map(row)}
|
|
353
|
+
</ul>`
|
|
354
|
+
}
|
|
355
|
+
</div>
|
|
356
|
+
${
|
|
357
|
+
canEdit &&
|
|
358
|
+
open.length > 0 &&
|
|
359
|
+
html`<footer class="dsn-dock-foot">
|
|
360
|
+
${
|
|
361
|
+
sent &&
|
|
362
|
+
html`<span class="muted small">
|
|
363
|
+
${"In your message box. After Pi makes the new version, "}
|
|
364
|
+
<button
|
|
365
|
+
type="button"
|
|
366
|
+
class="dsn-link"
|
|
367
|
+
onClick=${() => {
|
|
368
|
+
data.resolveMany(design.id, sent);
|
|
369
|
+
setSent(null);
|
|
370
|
+
}}
|
|
371
|
+
>
|
|
372
|
+
mark them done</button
|
|
373
|
+
>.
|
|
374
|
+
</span>`
|
|
375
|
+
}
|
|
376
|
+
<button type="button" class="button primary" onClick=${send}>
|
|
377
|
+
<${Ico} name="send" size=${15} /> Send ${open.length} to Pi
|
|
378
|
+
</button>
|
|
379
|
+
</footer>`
|
|
380
|
+
}`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// ─── Text edits ──────────────────────────────────────────────────────────
|
|
384
|
+
|
|
385
|
+
function EditsDock({ s, design, shown, canEdit }) {
|
|
386
|
+
const at = `${design.id}@${shown}`;
|
|
387
|
+
const edits = s.edits[at] ?? [];
|
|
388
|
+
|
|
389
|
+
const apply = () => {
|
|
390
|
+
env.sendToBox(
|
|
391
|
+
editsMessage({ title: design.title, id: design.id, version: shown, edits }),
|
|
392
|
+
);
|
|
393
|
+
// The message has them now: the list starts empty for the next ones.
|
|
394
|
+
store.set((now) => ({ edits: { ...now.edits, [at]: [] } }));
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const discard = () => {
|
|
398
|
+
store.set((now) => ({ edits: { ...now.edits, [at]: [] } }));
|
|
399
|
+
env.reloadFrame();
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
return html`<${DockHead} title="Text edits" count=${edits.length}>
|
|
403
|
+
${
|
|
404
|
+
edits.length > 0 &&
|
|
405
|
+
html`<button type="button" class="dsn-link" onClick=${discard}>Discard</button>`
|
|
406
|
+
}
|
|
407
|
+
<//>
|
|
408
|
+
<div class="dsn-dock-body">
|
|
409
|
+
${
|
|
410
|
+
edits.length === 0 &&
|
|
411
|
+
html`<p class="muted small dsn-empty">
|
|
412
|
+
${canEdit ? "Tap text on the canvas, change it, and tap away. Each change lands here." : "Nobody has edited text here."}
|
|
413
|
+
</p>`
|
|
414
|
+
}
|
|
415
|
+
<ul class="dsn-edits">
|
|
416
|
+
${edits.map(
|
|
417
|
+
(edit, index) =>
|
|
418
|
+
html`<li class="dsn-edit" key=${index}>
|
|
419
|
+
<div class="muted small">${nameOf(edit.target)}</div>
|
|
420
|
+
<div class="dsn-edit-before">${edit.before}</div>
|
|
421
|
+
<div class="dsn-edit-after">${edit.after}</div>
|
|
422
|
+
<button
|
|
423
|
+
type="button"
|
|
424
|
+
class="icon-button"
|
|
425
|
+
title="Leave this one out of the message"
|
|
426
|
+
aria-label="Leave this one out of the message"
|
|
427
|
+
onClick=${() =>
|
|
428
|
+
store.set((now) => ({
|
|
429
|
+
edits: {
|
|
430
|
+
...now.edits,
|
|
431
|
+
[at]: edits.filter((_, each) => each !== index),
|
|
432
|
+
},
|
|
433
|
+
}))}
|
|
434
|
+
>
|
|
435
|
+
<${Ico} name="close" size=${14} />
|
|
436
|
+
</button>
|
|
437
|
+
</li>`,
|
|
438
|
+
)}
|
|
439
|
+
</ul>
|
|
440
|
+
</div>
|
|
441
|
+
${
|
|
442
|
+
canEdit &&
|
|
443
|
+
edits.length > 0 &&
|
|
444
|
+
html`<footer class="dsn-dock-foot">
|
|
445
|
+
<button type="button" class="button primary" onClick=${apply}>
|
|
446
|
+
<${Ico} name="send" size=${15} /> Apply ${edits.length} with Pi
|
|
447
|
+
</button>
|
|
448
|
+
</footer>`
|
|
449
|
+
}`;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// ─── Tweaks ──────────────────────────────────────────────────────────────
|
|
453
|
+
|
|
454
|
+
function Knob({ knob, value, disabled, onChange }) {
|
|
455
|
+
const label = html`<label class="dsn-knob-label">
|
|
456
|
+
<span>${knob.label}</span>
|
|
457
|
+
<span class="mono small muted">${show(knob, value)}</span>
|
|
458
|
+
</label>`;
|
|
459
|
+
|
|
460
|
+
let control;
|
|
461
|
+
|
|
462
|
+
if (knob.type === "range") {
|
|
463
|
+
control = html`<input
|
|
464
|
+
type="range"
|
|
465
|
+
data-no-swipe
|
|
466
|
+
min=${knob.min}
|
|
467
|
+
max=${knob.max}
|
|
468
|
+
step=${knob.step}
|
|
469
|
+
value=${value}
|
|
470
|
+
disabled=${disabled}
|
|
471
|
+
aria-label=${knob.label}
|
|
472
|
+
onInput=${(event) => onChange(Number(event.currentTarget.value))}
|
|
473
|
+
/>`;
|
|
474
|
+
} else if (knob.type === "color") {
|
|
475
|
+
control = html`<span class="dsn-color">
|
|
476
|
+
<input
|
|
477
|
+
type="color"
|
|
478
|
+
value=${/^#[0-9a-f]{6}$/i.test(value) ? value : "#000000"}
|
|
479
|
+
disabled=${disabled}
|
|
480
|
+
aria-label=${knob.label}
|
|
481
|
+
onInput=${(event) => onChange(event.currentTarget.value)}
|
|
482
|
+
/>
|
|
483
|
+
<input
|
|
484
|
+
type="text"
|
|
485
|
+
class="mono"
|
|
486
|
+
value=${value}
|
|
487
|
+
disabled=${disabled}
|
|
488
|
+
spellcheck="false"
|
|
489
|
+
aria-label=${`${knob.label}, as text`}
|
|
490
|
+
onChange=${(event) => onChange(event.currentTarget.value)}
|
|
491
|
+
/>
|
|
492
|
+
</span>`;
|
|
493
|
+
} else if (knob.type === "select") {
|
|
494
|
+
control = html`<select
|
|
495
|
+
value=${value}
|
|
496
|
+
disabled=${disabled}
|
|
497
|
+
aria-label=${knob.label}
|
|
498
|
+
onChange=${(event) => onChange(event.currentTarget.value)}
|
|
499
|
+
>
|
|
500
|
+
${knob.options.map((option) => html`<option value=${option.value}>${option.label}</option>`)}
|
|
501
|
+
</select>`;
|
|
502
|
+
} else if (knob.type === "toggle") {
|
|
503
|
+
control = html`<${Switch}
|
|
504
|
+
on=${value === true}
|
|
505
|
+
label=${knob.label}
|
|
506
|
+
disabled=${disabled}
|
|
507
|
+
onChange=${() => onChange(!value)}
|
|
508
|
+
/>`;
|
|
509
|
+
} else {
|
|
510
|
+
control = html`<input
|
|
511
|
+
type="text"
|
|
512
|
+
value=${value}
|
|
513
|
+
disabled=${disabled}
|
|
514
|
+
aria-label=${knob.label}
|
|
515
|
+
onChange=${(event) => onChange(event.currentTarget.value)}
|
|
516
|
+
/>`;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return html`<div class="dsn-knob" data-type=${knob.type}>${label}${control}</div>`;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function TweaksDock({ s, design, shown, canEdit }) {
|
|
523
|
+
const knobs = s.knobs;
|
|
524
|
+
const values = s.tweaks[design.id] ?? {};
|
|
525
|
+
const moved = changed(knobs, values);
|
|
526
|
+
|
|
527
|
+
const keep = () =>
|
|
528
|
+
env.sendToBox(
|
|
529
|
+
tweaksMessage({
|
|
530
|
+
title: design.title,
|
|
531
|
+
id: design.id,
|
|
532
|
+
version: shown,
|
|
533
|
+
changes: moved.map((knob) => ({ knob, value: values[knob.name] })),
|
|
534
|
+
}),
|
|
535
|
+
);
|
|
536
|
+
|
|
537
|
+
return html`<${DockHead} title="Tweaks" count=${moved.length}>
|
|
538
|
+
${
|
|
539
|
+
moved.length > 0 &&
|
|
540
|
+
canEdit &&
|
|
541
|
+
html`<button
|
|
542
|
+
type="button"
|
|
543
|
+
class="dsn-link"
|
|
544
|
+
onClick=${() => env.resetTweaks(design.id)}
|
|
545
|
+
>
|
|
546
|
+
Reset
|
|
547
|
+
</button>`
|
|
548
|
+
}
|
|
549
|
+
<//>
|
|
550
|
+
<div class="dsn-dock-body" data-no-swipe>
|
|
551
|
+
${
|
|
552
|
+
knobs.length === 0 &&
|
|
553
|
+
html`<div class="dsn-empty">
|
|
554
|
+
<p class="muted small">
|
|
555
|
+
This design has no tweaks. Tweaks are knobs for colors, spacing, type,
|
|
556
|
+
and more that change the page live, without a new version.
|
|
557
|
+
</p>
|
|
558
|
+
${
|
|
559
|
+
canEdit &&
|
|
560
|
+
html`<button
|
|
561
|
+
type="button"
|
|
562
|
+
class="button small"
|
|
563
|
+
onClick=${() =>
|
|
564
|
+
env.sendToBox(
|
|
565
|
+
`Add tweaks to ${design.title} (artifact \`${design.id}\`): 3 to 8 knobs for the things I would want to adjust, such as the accent color, spacing, and type size, in the design's tweaks manifest.`,
|
|
566
|
+
)}
|
|
567
|
+
>
|
|
568
|
+
Ask Pi for tweaks
|
|
569
|
+
</button>`
|
|
570
|
+
}
|
|
571
|
+
</div>`
|
|
572
|
+
}
|
|
573
|
+
${
|
|
574
|
+
!canEdit &&
|
|
575
|
+
knobs.length > 0 &&
|
|
576
|
+
html`<p class="muted small dsn-note">
|
|
577
|
+
Tweaks are for people who can steer the session.
|
|
578
|
+
</p>`
|
|
579
|
+
}
|
|
580
|
+
${
|
|
581
|
+
knobs.length > 0 &&
|
|
582
|
+
html`<div class="dsn-knobs">
|
|
583
|
+
${knobs.map(
|
|
584
|
+
(knob) =>
|
|
585
|
+
html`<${Knob}
|
|
586
|
+
key=${knob.name}
|
|
587
|
+
knob=${knob}
|
|
588
|
+
value=${Object.hasOwn(values, knob.name) ? values[knob.name] : knob.value}
|
|
589
|
+
disabled=${!canEdit}
|
|
590
|
+
onChange=${(value) => {
|
|
591
|
+
const clean = coerce(knob, value);
|
|
592
|
+
|
|
593
|
+
if (clean !== undefined) {
|
|
594
|
+
env.setTweak(design.id, knob, clean);
|
|
595
|
+
}
|
|
596
|
+
}}
|
|
597
|
+
/>`,
|
|
598
|
+
)}
|
|
599
|
+
<p class="muted small dsn-note">
|
|
600
|
+
Only you see your tweaks. They stay with you for this design. “Keep
|
|
601
|
+
these” asks Pi to write them in.
|
|
602
|
+
</p>
|
|
603
|
+
</div>`
|
|
604
|
+
}
|
|
605
|
+
</div>
|
|
606
|
+
${
|
|
607
|
+
canEdit &&
|
|
608
|
+
moved.length > 0 &&
|
|
609
|
+
html`<footer class="dsn-dock-foot">
|
|
610
|
+
<button type="button" class="button primary" onClick=${keep}>
|
|
611
|
+
<${Ico} name="send" size=${15} /> Keep these ${moved.length}
|
|
612
|
+
</button>
|
|
613
|
+
</footer>`
|
|
614
|
+
}`;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const DOCKS = {
|
|
618
|
+
versions: "Versions",
|
|
619
|
+
comments: "Comments",
|
|
620
|
+
edits: "Text edits",
|
|
621
|
+
tweaks: "Tweaks",
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
/** The dock for `s.dock`, or nothing. */
|
|
625
|
+
function Dock({ s, design, shown, canEdit, me }) {
|
|
626
|
+
const props = { s, design, shown, canEdit, me };
|
|
627
|
+
const body =
|
|
628
|
+
s.dock === "versions"
|
|
629
|
+
? html`<${VersionsDock} ...${props} />`
|
|
630
|
+
: s.dock === "comments"
|
|
631
|
+
? html`<${CommentsDock} ...${props} />`
|
|
632
|
+
: s.dock === "edits"
|
|
633
|
+
? html`<${EditsDock} ...${props} />`
|
|
634
|
+
: s.dock === "tweaks"
|
|
635
|
+
? html`<${TweaksDock} ...${props} />`
|
|
636
|
+
: null;
|
|
637
|
+
|
|
638
|
+
return (
|
|
639
|
+
body &&
|
|
640
|
+
html`<aside class="dsn-dock" data-dock=${s.dock} aria-label=${DOCKS[s.dock]}>
|
|
641
|
+
${body}
|
|
642
|
+
</aside>`
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
return { Dock };
|
|
647
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The text edits a person makes on the canvas, gathered until they are sent to Pi as one message.
|
|
2
|
+
|
|
3
|
+
/** The key an edit goes by: the element it changed. */
|
|
4
|
+
const keyOf = (target) => `${target?.pid ?? ""}\n${target?.selector ?? ""}`;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Add one edit (`{ target, before, after }`) to the list. A second edit of the same element keeps the first `before` and
|
|
8
|
+
* takes the new `after`; an edit that ends where it began is dropped. Returns a new list.
|
|
9
|
+
*/
|
|
10
|
+
export function addEdit(list, edit) {
|
|
11
|
+
const key = keyOf(edit.target);
|
|
12
|
+
const at = list.findIndex((each) => keyOf(each.target) === key);
|
|
13
|
+
|
|
14
|
+
if (at === -1) {
|
|
15
|
+
return edit.before === edit.after ? list : [...list, { ...edit }];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const merged = { ...list[at], target: edit.target, after: edit.after };
|
|
19
|
+
|
|
20
|
+
if (merged.before === merged.after) {
|
|
21
|
+
return list.filter((_, index) => index !== at);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return list.map((each, index) => (index === at ? merged : each));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A short name for an element: `button “Get started”`, or its tag and selector when it has no words. */
|
|
28
|
+
export function nameOf(target) {
|
|
29
|
+
const words = String(target?.text ?? "")
|
|
30
|
+
.replace(/\s+/g, " ")
|
|
31
|
+
.trim();
|
|
32
|
+
const tag = target?.tag || "element";
|
|
33
|
+
|
|
34
|
+
return words === ""
|
|
35
|
+
? `${tag} ${target?.selector ?? ""}`.trim()
|
|
36
|
+
: `${tag} “${words.slice(0, 40)}${words.length > 40 ? "…" : ""}”`;
|
|
37
|
+
}
|