bom-pi 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/README.md +33 -2
  2. package/apps/README.md +7 -0
  3. package/apps/web/README.md +21 -0
  4. package/apps/web/pocket-adapter.mjs +323 -0
  5. package/apps/web/public/LICENSE.pocket +21 -0
  6. package/apps/web/public/activity-fold.js +28 -0
  7. package/apps/web/public/agent-now.js +37 -0
  8. package/apps/web/public/agent-tile.js +79 -0
  9. package/apps/web/public/app.js +975 -0
  10. package/apps/web/public/apple-touch-icon.png +0 -0
  11. package/apps/web/public/artifact-bridge.js +687 -0
  12. package/apps/web/public/avatar.js +87 -0
  13. package/apps/web/public/back.js +554 -0
  14. package/apps/web/public/box-keys.js +216 -0
  15. package/apps/web/public/browser-panel.js +1097 -0
  16. package/apps/web/public/browser.js +68 -0
  17. package/apps/web/public/calls.js +139 -0
  18. package/apps/web/public/chat.js +919 -0
  19. package/apps/web/public/clock.js +34 -0
  20. package/apps/web/public/commands.js +578 -0
  21. package/apps/web/public/composer.js +2068 -0
  22. package/apps/web/public/diff-parse.js +672 -0
  23. package/apps/web/public/diff.js +1646 -0
  24. package/apps/web/public/dock.js +299 -0
  25. package/apps/web/public/extension-ui.js +2734 -0
  26. package/apps/web/public/files-panel.js +775 -0
  27. package/apps/web/public/files.js +368 -0
  28. package/apps/web/public/fonts/FiraCode-VF.woff2 +0 -0
  29. package/apps/web/public/fonts/Geist.woff2 +0 -0
  30. package/apps/web/public/fonts/IBMPlexMono-Variable-Italic.woff2 +0 -0
  31. package/apps/web/public/fonts/IBMPlexMono-Variable.woff2 +0 -0
  32. package/apps/web/public/fonts/InterVariable-Italic.woff2 +0 -0
  33. package/apps/web/public/fonts/InterVariable.woff2 +0 -0
  34. package/apps/web/public/fonts/Iosevka-Bold.woff2 +0 -0
  35. package/apps/web/public/fonts/Iosevka-BoldItalic.woff2 +0 -0
  36. package/apps/web/public/fonts/Iosevka-Italic.woff2 +0 -0
  37. package/apps/web/public/fonts/Iosevka-Regular.woff2 +0 -0
  38. package/apps/web/public/fonts/Iosevka-SemiBold.woff2 +0 -0
  39. package/apps/web/public/fonts/Iosevka-SemiBoldItalic.woff2 +0 -0
  40. package/apps/web/public/fonts/JetBrainsMono-Italic.woff2 +0 -0
  41. package/apps/web/public/fonts/JetBrainsMono.woff2 +0 -0
  42. package/apps/web/public/fonts/NerdFontsSymbolsMono.woff2 +0 -0
  43. package/apps/web/public/fonts/SOURCES.md +69 -0
  44. package/apps/web/public/gestures.js +610 -0
  45. package/apps/web/public/highlight.js +480 -0
  46. package/apps/web/public/history.js +70 -0
  47. package/apps/web/public/home.js +169 -0
  48. package/apps/web/public/icon-192.png +0 -0
  49. package/apps/web/public/icon-512.png +0 -0
  50. package/apps/web/public/icon-maskable-512.png +0 -0
  51. package/apps/web/public/icon.svg +16 -0
  52. package/apps/web/public/index.html +71 -0
  53. package/apps/web/public/launcher.js +1293 -0
  54. package/apps/web/public/linked-sessions.js +55 -0
  55. package/apps/web/public/live.js +39 -0
  56. package/apps/web/public/manifest.webmanifest +32 -0
  57. package/apps/web/public/model-refresh.js +73 -0
  58. package/apps/web/public/notify.js +251 -0
  59. package/apps/web/public/peeks.js +920 -0
  60. package/apps/web/public/pip-attachments.js +182 -0
  61. package/apps/web/public/pip-window.js +141 -0
  62. package/apps/web/public/pip.js +1217 -0
  63. package/apps/web/public/quote-reply.js +109 -0
  64. package/apps/web/public/quote-text.js +31 -0
  65. package/apps/web/public/rich.js +403 -0
  66. package/apps/web/public/run-frame.js +106 -0
  67. package/apps/web/public/safe-mode.js +71 -0
  68. package/apps/web/public/seen.js +169 -0
  69. package/apps/web/public/session-tree.js +117 -0
  70. package/apps/web/public/sessions.js +2695 -0
  71. package/apps/web/public/share.js +126 -0
  72. package/apps/web/public/sheets/appearance.js +820 -0
  73. package/apps/web/public/sheets/branch.js +353 -0
  74. package/apps/web/public/sheets/extensions.js +818 -0
  75. package/apps/web/public/sheets/file.js +318 -0
  76. package/apps/web/public/sheets/find.js +250 -0
  77. package/apps/web/public/sheets/folder.js +680 -0
  78. package/apps/web/public/sheets/gallery.js +2340 -0
  79. package/apps/web/public/sheets/hooks.js +350 -0
  80. package/apps/web/public/sheets/memory.js +531 -0
  81. package/apps/web/public/sheets/menu.js +580 -0
  82. package/apps/web/public/sheets/message.js +220 -0
  83. package/apps/web/public/sheets/model.js +412 -0
  84. package/apps/web/public/sheets/people.js +414 -0
  85. package/apps/web/public/sheets/pi-sessions.js +264 -0
  86. package/apps/web/public/sheets/providers.js +525 -0
  87. package/apps/web/public/sheets/running.js +130 -0
  88. package/apps/web/public/sheets/schedules.js +71 -0
  89. package/apps/web/public/sheets/session.js +249 -0
  90. package/apps/web/public/sheets/shortcuts.js +101 -0
  91. package/apps/web/public/sheets/spend.js +150 -0
  92. package/apps/web/public/sheets/text.js +53 -0
  93. package/apps/web/public/sheets/viewers.js +363 -0
  94. package/apps/web/public/sheets/worktree.js +50 -0
  95. package/apps/web/public/sheets.js +410 -0
  96. package/apps/web/public/signin.js +57 -0
  97. package/apps/web/public/slots.js +208 -0
  98. package/apps/web/public/store.js +1760 -0
  99. package/apps/web/public/style.css +18625 -0
  100. package/apps/web/public/subagents-board.js +879 -0
  101. package/apps/web/public/subagents.js +273 -0
  102. package/apps/web/public/sw.js +169 -0
  103. package/apps/web/public/taps.js +26 -0
  104. package/apps/web/public/theme-surface.d.ts +4 -0
  105. package/apps/web/public/theme-surface.js +266 -0
  106. package/apps/web/public/theme.js +845 -0
  107. package/apps/web/public/themes/lantern/colors.toml +25 -0
  108. package/apps/web/public/themes/lantern/direction.css +60 -0
  109. package/apps/web/public/themes/lantern/frame.css +254 -0
  110. package/apps/web/public/themes/lantern/theme.css +10 -0
  111. package/apps/web/public/themes/lantern/theme.json +7 -0
  112. package/apps/web/public/themes/pocket/theme.css +189 -0
  113. package/apps/web/public/themes/pocket/theme.json +6 -0
  114. package/apps/web/public/themes.js +556 -0
  115. package/apps/web/public/transcript.js +3348 -0
  116. package/apps/web/public/trust.js +295 -0
  117. package/apps/web/public/turns.js +507 -0
  118. package/apps/web/public/ui.js +1910 -0
  119. package/apps/web/public/voice.js +345 -0
  120. package/apps/web/server.mjs +774 -0
  121. package/package.json +43 -4
  122. package/packages/cli/src/bom-pi.mjs +452 -0
  123. package/packages/cli/templates/blank.factory.json +7 -0
  124. package/packages/cli/templates/dev.factory.json +11 -0
  125. package/packages/cli/templates/docs.factory.json +12 -0
  126. package/packages/cli/templates/ops.factory.json +14 -0
  127. package/packages/cli/templates/triage.factory.json +10 -0
  128. package/packages/core/src/daemon.mjs +2047 -0
  129. package/packages/core/src/limit-gate.mjs +192 -0
  130. package/packages/core/src/rpc-client.mjs +66 -0
  131. package/systemd/README.md +11 -0
@@ -0,0 +1,2340 @@
1
+ // The extension gallery: drop-ins and themes other people wrote, from a reviewed index. Browse and search them, read
2
+ // one's code before it is installed, install it (a drop-in off; a theme into Appearance's list, not applied), ask Pi to
3
+ // review a drop-in, turn it on, update it with a diff, remove it; and share your own as a draft index entry. The
4
+ // owner's alone; the server side is src/server/gallery.ts.
5
+ //
6
+ // Everything the index says is untrusted: it shows as text only, and links go only to addresses the server built.
7
+ import { useContext, useEffect, useRef, useState } from "preact/hooks";
8
+ import { personColor } from "../avatar.js";
9
+ import { planAvailable } from "../commands.js";
10
+ import { browserModuleState } from "../extension-ui.js";
11
+ import { DiffBlock } from "../diff.js";
12
+ import { Highlighted } from "../rich.js";
13
+ import {
14
+ actions,
15
+ api,
16
+ attempt,
17
+ closeSheet,
18
+ navigate,
19
+ notify,
20
+ openSheet,
21
+ store,
22
+ uid,
23
+ } from "../store.js";
24
+ import { BASE_LOOK, chooseLook, prefs, setPrefs } from "../theme.js";
25
+ import { copyText, formatBytes, html, Icon, Loader, Sheet, SheetBack, timeAgo } from "../ui.js";
26
+
27
+ /** The owner's, while its module is on. */
28
+ export const galleryAvailable = () =>
29
+ store.state.me?.role === "owner" &&
30
+ store.state.server?.extensions?.includes("pocket-gallery") === true;
31
+
32
+ /** The gallery's routes: GET without a body, POST with one; `options.signal` stops it. */
33
+ export const galleryApi = (path, body, options) => api(`x/gallery/${path}`, body, options);
34
+
35
+ /**
36
+ * Read a route while a sheet shows, and stop when it closes: a download of an extension's files goes no further, and
37
+ * its answer reaches no sheet that is gone.
38
+ */
39
+ function useRoute(path, setData, setProblem) {
40
+ useEffect(() => {
41
+ const stop = new AbortController();
42
+
43
+ galleryApi(path, undefined, { signal: stop.signal }).then(
44
+ (result) => !stop.signal.aborted && setData(result),
45
+ (error) => !stop.signal.aborted && setProblem(error.message),
46
+ );
47
+
48
+ return () => stop.abort();
49
+ }, [path]);
50
+ }
51
+
52
+ const short = (commit) => (commit ?? "").slice(0, 7);
53
+ const plural = (count, word) =>
54
+ `${count} ${count === 1 ? word : word.endsWith("y") ? `${word.slice(0, -1)}ies` : `${word}s`}`;
55
+ const revocation = (entry, commit) => entry.revoked.find((each) => each.commit === commit)?.reason;
56
+
57
+ /** Who a browser module or a route is for, in words. */
58
+ export const ACCESS_WORDS = {
59
+ owner: "the owner",
60
+ steer: "people who can steer",
61
+ view: "everyone who sees every session",
62
+ };
63
+
64
+ /** What a module declares, by group, in the order the entry and the review list them. */
65
+ const GROUPS = [
66
+ ["extensions", "Extensions"],
67
+ ["tools", "Tools"],
68
+ ["readOnlyTools", "Read-only tools"],
69
+ ["hooks", "Hooks"],
70
+ ["sections", "Prompt sections"],
71
+ ["wraps", "Wraps"],
72
+ ["routes", "Routes"],
73
+ ["commands", "Slash commands"],
74
+ ];
75
+
76
+ /**
77
+ * One group of what a module declares, as names to show: a command with its slash, and who may run it. Older entries
78
+ * lack some groups.
79
+ */
80
+ const declared = (declares, key) =>
81
+ (declares[key] ?? []).map((each) => {
82
+ if (key !== "commands") {
83
+ return each;
84
+ }
85
+
86
+ const [scope, name] = each.split(" ");
87
+
88
+ return `/${name} (${scope === "global" ? "owner" : "who can steer"})`;
89
+ });
90
+
91
+ const RISK =
92
+ "It runs inside the server with your rights, in every session. Lancet Guard does not see what its code does.";
93
+ const THEME_RISK =
94
+ "A theme is CSS, fonts, and images. It runs no code, and it loads nothing from other sites. But it can hide or relabel what people see, approvals too: install only themes you trust.";
95
+
96
+ const isTheme = (item) => item?.kind === "theme";
97
+
98
+ /** A link out, to an address the server built (or a GitHub profile): never one the index wrote. */
99
+ const Out = ({ href, class: className = "", children }) =>
100
+ html`<a class=${className} href=${href} target="_blank" rel="noopener noreferrer">${children}</a>`;
101
+
102
+ /** The last index read, so an entry opened from the list shows at once while it is read again. */
103
+ let lastListing = null;
104
+
105
+ /** Preserve the hub tab through source/update sheets and their return to an entry. */
106
+ function openGallerySheet(type, name) {
107
+ const sheet = store.state.sheet;
108
+
109
+ openSheet({
110
+ type,
111
+ id: name,
112
+ tab: sheet?.tab,
113
+ origin: sheet?.origin ?? (sheet?.type === "gallery" ? "gallery" : "extensions"),
114
+ });
115
+ }
116
+
117
+ function useListing(shared) {
118
+ const [data, setData] = useState(lastListing);
119
+ const [problem, setProblem] = useState(null);
120
+ const [loading, setLoading] = useState(true);
121
+ const live = useRef(true);
122
+
123
+ const load = (refresh = false) => {
124
+ setLoading(true);
125
+
126
+ return galleryApi(`index${refresh ? "?refresh=1" : ""}`)
127
+ .then(
128
+ (result) => {
129
+ lastListing = result;
130
+
131
+ if (live.current) {
132
+ setData(result);
133
+ setProblem(null);
134
+ }
135
+ },
136
+ (error) => live.current && setProblem(error.message),
137
+ )
138
+ .finally(() => live.current && setLoading(false));
139
+ };
140
+
141
+ useEffect(() => {
142
+ live.current = true;
143
+
144
+ if (!shared) {
145
+ load();
146
+ }
147
+
148
+ return () => {
149
+ live.current = false;
150
+ };
151
+ }, []);
152
+
153
+ return shared ?? { data, problem, loading, load };
154
+ }
155
+
156
+ export function Tile({ name, title, icon = null, large = false }) {
157
+ const letter = (title ?? name ?? "?").trim().charAt(0).toUpperCase() || "?";
158
+
159
+ return html`<span
160
+ class=${`ext-tile ${large ? "large" : ""}`}
161
+ style=${`--tint:${personColor(name ?? title ?? "")}`}
162
+ aria-hidden="true"
163
+ >
164
+ ${icon ? html`<${Icon} name=${icon} size=${large ? 17 : 11} />` : letter}
165
+ </span>`;
166
+ }
167
+
168
+ const sentence = (items) =>
169
+ items.length > 1 ? `${items.slice(0, -1).join(", ")} and ${items.at(-1)}` : (items[0] ?? "");
170
+
171
+ const HOOK_WORDS = {
172
+ beforeTool: "tool calls, before they run",
173
+ afterTool: "tool results",
174
+ beforeRequest: "what goes to the model",
175
+ afterResponse: "the model's replies",
176
+ onYield: "the end of each turn",
177
+ };
178
+
179
+ let lastReach = null;
180
+
181
+ /** A server from before the reach route answers 404: the facts then wait for a restart. */
182
+ function useReach(data) {
183
+ const [reach, setReach] = useState(lastReach);
184
+ const [problem, setProblem] = useState(null);
185
+
186
+ useEffect(() => {
187
+ if (!data) {
188
+ return;
189
+ }
190
+
191
+ const stop = new AbortController();
192
+
193
+ galleryApi("reach", undefined, { signal: stop.signal }).then(
194
+ (result) => {
195
+ if (!stop.signal.aborted) {
196
+ lastReach = result.entries ?? {};
197
+ setReach(lastReach);
198
+ setProblem(null);
199
+ }
200
+ },
201
+ (error) =>
202
+ !stop.signal.aborted &&
203
+ setProblem(
204
+ error.status === 404 || error.status === 503
205
+ ? "What its code reaches shows after a server restart (menu → Restart server)."
206
+ : `Its code could not be read: ${error.message}`,
207
+ ),
208
+ );
209
+
210
+ return () => stop.abort();
211
+ }, [data?.fetchedAt, data?.address, data?.installed.length]);
212
+
213
+ return { reach, problem };
214
+ }
215
+
216
+ /** A scan counts only for the same commit and pinned files, and the version installed here. */
217
+ function foundFor(reach, entry, installed) {
218
+ const found = entry?.source ? reach?.[entry.name] : undefined;
219
+
220
+ if (
221
+ !found ||
222
+ found.error ||
223
+ found.commit !== entry.source.commit ||
224
+ found.pin !== entry.pin ||
225
+ (installed && installed.commit !== entry.source.commit)
226
+ ) {
227
+ return undefined;
228
+ }
229
+
230
+ return found;
231
+ }
232
+
233
+ function useModules(on, round) {
234
+ const [modules, setModules] = useState(null);
235
+
236
+ useEffect(() => {
237
+ if (!on) {
238
+ return;
239
+ }
240
+
241
+ let live = true;
242
+
243
+ api("extensions").then(
244
+ (result) => live && setModules(result.modules),
245
+ () => {},
246
+ );
247
+
248
+ return () => {
249
+ live = false;
250
+ };
251
+ }, [on, round]);
252
+
253
+ return modules;
254
+ }
255
+
256
+ function reachRows(declares, found) {
257
+ const scanned = found?.scanned;
258
+ const rows = [];
259
+
260
+ if (scanned) {
261
+ for (const [key, glyph, words] of [
262
+ ["network", "globe", (items) => `Talks to ${sentence(items)}`],
263
+ [
264
+ "keys",
265
+ "key",
266
+ (items) =>
267
+ `Uses ${sentence(items.map((item) => item.replace(/^(.+) key from Pi$/, "your $1 key, from Pi")))}`,
268
+ ],
269
+ ["programs", "terminal", (items) => `Runs ${sentence(items)}`],
270
+ ["files", "folder", (items) => `Uses ${sentence(items)}`],
271
+ ]) {
272
+ if (scanned[key]?.length > 0) {
273
+ rows.push({ key, glyph, text: words(scanned[key]), from: "In its code" });
274
+ }
275
+ }
276
+ }
277
+
278
+ if ((declares.hooks ?? []).length > 0) {
279
+ rows.push({
280
+ key: "sees",
281
+ glyph: "eye",
282
+ text: `Sees ${sentence(declares.hooks.map((hook) => HOOK_WORDS[hook] ?? hook))}`,
283
+ from: "Declared",
284
+ });
285
+ }
286
+
287
+ const changes = [
288
+ (declares.sections ?? []).length > 0 && "Adds to Pi's instructions",
289
+ ...(declares.wraps ?? []).map((wrap) => `Wraps the ${wrap.replace(/^tool /, "")} tool`),
290
+ ].filter(Boolean);
291
+
292
+ if (changes.length > 0) {
293
+ rows.push({ key: "changes", glyph: "chat", text: changes.join("; "), from: "Declared" });
294
+ }
295
+
296
+ return rows;
297
+ }
298
+
299
+ const RUN_TIME = /at run time/;
300
+
301
+ function rowFacts(entry, found) {
302
+ if (isTheme(entry) || !entry.declares) {
303
+ return [];
304
+ }
305
+
306
+ const d = entry.declares;
307
+ const s = found?.scanned;
308
+ const tools = new Set([...(d.tools ?? []), ...(d.readOnlyTools ?? [])]).size;
309
+
310
+ return [
311
+ s?.network.length > 0 && [
312
+ "globe",
313
+ s.network.length > 1
314
+ ? `${s.network.length} hosts`
315
+ : RUN_TIME.test(s.network[0])
316
+ ? "network"
317
+ : s.network[0],
318
+ ],
319
+ s?.keys.length > 0 && ["key", s.keys.length > 1 ? `${s.keys.length} keys` : "a key"],
320
+ s?.programs.length > 0 && [
321
+ "terminal",
322
+ RUN_TIME.test(s.programs.join()) ? "programs" : s.programs.join(", "),
323
+ ],
324
+ (d.hooks ?? []).length > 0 && ["eye", "sees turns"],
325
+ ((d.sections ?? []).length > 0 || (d.wraps ?? []).length > 0) && ["chat", "changes Pi"],
326
+ tools > 0 && ["sparkle", plural(tools, "tool")],
327
+ d.client !== null && ["tiles", "in the app"],
328
+ ]
329
+ .filter(Boolean)
330
+ .slice(0, 3);
331
+ }
332
+
333
+ function newReach(before, after) {
334
+ const added = (key) =>
335
+ declared(after, key).filter((each) => !declared(before, key).includes(each));
336
+ const tools = [...new Set([...added("tools"), ...added("readOnlyTools")])];
337
+
338
+ return [
339
+ added("hooks").length > 0 &&
340
+ `sees ${sentence(added("hooks").map((hook) => HOOK_WORDS[hook] ?? hook))}`,
341
+ added("sections").length > 0 && "adds to Pi's instructions",
342
+ ...added("wraps").map((wrap) => `wraps the ${wrap.replace(/^tool /, "")} tool`),
343
+ tools.length > 0 && plural(tools.length, "new tool"),
344
+ added("commands").length > 0 && plural(added("commands").length, "new command"),
345
+ (added("routes").length > 0 || (before.client === null && after.client !== null)) &&
346
+ "adds to the app",
347
+ before.access !== after.access && `now for ${ACCESS_WORDS[after.access] ?? after.access}`,
348
+ ].filter(Boolean);
349
+ }
350
+
351
+ function liveStatus(item, module, tab) {
352
+ if (item.revoked !== null && item.revoked !== undefined) {
353
+ return { kind: "bad", text: "Revoked" };
354
+ }
355
+
356
+ if (module?.error) {
357
+ return { kind: "bad", text: "Did not load" };
358
+ }
359
+
360
+ if (module && browserModuleState(module.file.replace(/\.ts$/, ""))?.status === "failed") {
361
+ return { kind: "warn", text: "Off in this tab" };
362
+ }
363
+
364
+ if (item.changed?.length > 0) {
365
+ return { kind: "warn", text: "Edited since install" };
366
+ }
367
+
368
+ if (item.enabled) {
369
+ return { kind: "on", text: "On" };
370
+ }
371
+
372
+ return { kind: "off", text: tab === "discover" ? "Installed" : "Off" };
373
+ }
374
+
375
+ const Status = ({ status }) =>
376
+ html`<span class=${`ext-state ${status.kind}`}>
377
+ <span class="ext-mark" aria-hidden="true"></span>${status.text}
378
+ </span>`;
379
+
380
+ function statusWhy(item, module) {
381
+ if (module?.error) {
382
+ return { kind: "bad", text: `Did not load: ${module.error}` };
383
+ }
384
+
385
+ const here = module && browserModuleState(module.file.replace(/\.ts$/, ""));
386
+
387
+ if (here?.status === "failed") {
388
+ return {
389
+ kind: "warn",
390
+ text: `In this browser: ${here.error}. Reloading the page tries again.`,
391
+ };
392
+ }
393
+
394
+ if (item?.revoked) {
395
+ return { kind: "bad", text: `The gallery revoked this version: ${item.revoked}` };
396
+ }
397
+
398
+ return null;
399
+ }
400
+
401
+ function EntryRow({ entry, found, module, tab, selected, onOpen, onChanged }) {
402
+ const [busy, setBusy] = useState(false);
403
+ const going = useRef(false);
404
+ const installed = entry.installed ?? (entry.listed === false ? entry : null);
405
+ const theme = isTheme(entry);
406
+ const update = tab === "updates" && installed?.update;
407
+ const added =
408
+ update && !theme && entry.declares && installed.declares
409
+ ? newReach(installed.declares, entry.declares)
410
+ : null;
411
+ const facts = rowFacts(entry, found);
412
+ const why = tab !== "discover" && installed && !theme ? statusWhy(installed, module) : null;
413
+
414
+ const install = () => {
415
+ if (going.current) {
416
+ return;
417
+ }
418
+
419
+ going.current = true;
420
+ setBusy(true);
421
+ attempt(() =>
422
+ galleryApi(`install/${encodeURIComponent(entry.name)}`, { pin: entry.pin }),
423
+ ).finally(() => {
424
+ going.current = false;
425
+ setBusy(false);
426
+ onChanged();
427
+ });
428
+ };
429
+
430
+ const end = !installed
431
+ ? html`<button class="button small ext-get" disabled=${busy} onClick=${install}>
432
+ ${busy ? "Installing…" : "Install"}
433
+ </button>`
434
+ : installed.update && tab !== "installed"
435
+ ? html`<button
436
+ class=${`button small ${added?.length > 0 ? "" : "primary"}`}
437
+ onClick=${() => openGallerySheet("gallery-update", entry.name)}
438
+ >
439
+ ${added?.length > 0 ? "Review" : "Update"}
440
+ </button>`
441
+ : theme
442
+ ? html`<span class="ext-state on"><${Icon} name="check" size=${13} stroke=${2.5} />Installed</span>`
443
+ : html`<${Status} status=${liveStatus(installed, module, tab)} />`;
444
+
445
+ return html`<div
446
+ class=${`ext-row ${selected ? "selected" : ""} ${installed && !theme && !installed.enabled ? "off" : ""}`}
447
+ >
448
+ <button class="ext-row-open" aria-current=${selected ? "true" : undefined} onClick=${onOpen}>
449
+ <span class="ext-row-line">
450
+ <${Tile} name=${entry.name} title=${entry.title} icon=${theme ? "palette" : null} />
451
+ <span class="ext-row-title">${entry.title}</span>
452
+ <span class="ext-row-by">
453
+ ${update ? `${installed.version} → ${installed.update.version}` : (entry.author?.name ?? entry.unlisted ?? "")}
454
+ </span>
455
+ </span>
456
+ ${entry.description && html`<span class="ext-row-desc">${entry.description}</span>`}
457
+ ${
458
+ why
459
+ ? html`<span class=${`ext-why ${why.kind}`}>${why.text}</span>`
460
+ : added !== null
461
+ ? html`<span class="ext-facts">
462
+ ${
463
+ added.length > 0
464
+ ? html`<span class="ext-fact new">
465
+ <${Icon} name="eye" size=${12} /><span>Declares more: ${added.join("; ")}</span>
466
+ </span>`
467
+ : html`<span class="ext-fact"><${Icon} name="check" size=${12} /><span>Declares nothing new</span></span>`
468
+ }
469
+ </span>`
470
+ : facts.length > 0 &&
471
+ html`<span class="ext-facts">
472
+ ${facts.map(
473
+ ([glyph, text]) => html`<span class="ext-fact" key=${glyph}>
474
+ <${Icon} name=${glyph} size=${12} /><span>${text}</span>
475
+ </span>`,
476
+ )}
477
+ </span>`
478
+ }
479
+ </button>
480
+ <div class="ext-row-end">${end}</div>
481
+ </div>`;
482
+ }
483
+
484
+ /** Only a color written as #rgb to #rrggbbaa reaches a style: a theme's palette is the index's text. */
485
+ const HEX = /^#[0-9a-f]{3,8}$/i;
486
+ const THEME_DOTS = ["red", "yellow", "green", "cyan", "blue", "magenta"];
487
+
488
+ function paletteStyle(colors) {
489
+ if (!colors) {
490
+ return "";
491
+ }
492
+
493
+ const pick = (...keys) => keys.map((key) => colors[key]).find((value) => HEX.test(value ?? ""));
494
+
495
+ return [
496
+ ["--t-bg", pick("background")],
497
+ ["--t-bg-dark", pick("dark_background", "background")],
498
+ ["--t-bg-darker", pick("darker_background", "background")],
499
+ ["--t-bg-light", pick("lighter_background", "background")],
500
+ ["--t-fg", pick("foreground")],
501
+ ["--t-accent", pick("accent")],
502
+ ...THEME_DOTS.map((color) => [`--t-${color}`, pick(color)]),
503
+ ]
504
+ .filter(([, value]) => value !== undefined)
505
+ .map(([key, value]) => `${key}:${value}`)
506
+ .join(";");
507
+ }
508
+
509
+ function paletteOf(entry, found) {
510
+ const listed = store.state.themeList?.find((each) => each.id === entry.name);
511
+
512
+ if (entry.installed && listed?.colors) {
513
+ return { colors: listed.colors, colorsLight: listed.colorsLight ?? null };
514
+ }
515
+
516
+ return found?.palette?.colors ? found.palette : null;
517
+ }
518
+
519
+ const modeWords = (palette) =>
520
+ !palette
521
+ ? "theme"
522
+ : palette.colorsLight
523
+ ? "dark and light"
524
+ : palette.colors.mode === "light"
525
+ ? "light"
526
+ : "dark";
527
+
528
+ const ThemeDesk = ({ colors, big = false }) =>
529
+ html`<span
530
+ class=${`ext-desk ${big ? "big" : ""} ${colors ? "" : "unknown"}`}
531
+ style=${paletteStyle(colors)}
532
+ aria-hidden="true"
533
+ >
534
+ <span class="ext-win side"><i></i><i></i><i></i></span>
535
+ <span class="ext-win main">
536
+ ${big ? html`<i></i><i></i><i class="bubble"></i><i></i>` : html`<i></i><i></i>`}
537
+ <i class="lit"></i>
538
+ </span>
539
+ </span>`;
540
+
541
+ function ThemeCard({ entry, palette, selected, state = null, onOpen }) {
542
+ return html`<button
543
+ class=${`ext-theme ${selected ? "selected" : ""}`}
544
+ aria-current=${selected ? "true" : undefined}
545
+ onClick=${onOpen}
546
+ >
547
+ <${ThemeDesk} colors=${palette?.colors ?? null} />
548
+ <span class="ext-theme-name">
549
+ <span>${entry.title ?? entry.name}</span>
550
+ ${state && html`<small><${Icon} name="check" size=${11} stroke=${2.5} />${state}</small>`}
551
+ </span>
552
+ <span class="ext-theme-meta">${modeWords(palette)} · ${entry.author?.name ?? entry.author ?? "yours"}</span>
553
+ <span class="ext-theme-dots" style=${paletteStyle(palette?.colors)} aria-hidden="true">
554
+ ${THEME_DOTS.map((color) => html`<i key=${color} style=${`background:var(--t-${color}, var(--hair-2))`}></i>`)}
555
+ </span>
556
+ </button>`;
557
+ }
558
+
559
+ const Section = ({ title, count, children }) =>
560
+ html`<section class="ext-section">
561
+ <h3 class="ext-section-title">${title} <span>${count}</span></h3>
562
+ ${children}
563
+ </section>`;
564
+
565
+ /** Where the index is read from, and changing it (empty is the default). */
566
+ function IndexAddress({ address, onChanged }) {
567
+ const [editing, setEditing] = useState(false);
568
+ const [value, setValue] = useState(address);
569
+ const [fallback, setFallback] = useState(null);
570
+ const [busy, setBusy] = useState(false);
571
+ const [problem, setProblem] = useState(null);
572
+
573
+ useEffect(() => {
574
+ if (editing && fallback === null) {
575
+ galleryApi("settings").then(
576
+ (result) => setFallback(result.default),
577
+ () => {},
578
+ );
579
+ }
580
+ }, [editing]);
581
+
582
+ const save = async (index) => {
583
+ setBusy(true);
584
+ setProblem(null);
585
+
586
+ try {
587
+ const result = await galleryApi("settings", { index });
588
+
589
+ setValue(result.index);
590
+ setEditing(false);
591
+ onChanged();
592
+ } catch (error) {
593
+ setProblem(error.message);
594
+ } finally {
595
+ setBusy(false);
596
+ }
597
+ };
598
+
599
+ if (!editing) {
600
+ return html`<div class="setting wrap">
601
+ <div class="grow small">
602
+ <div class="muted">Index</div>
603
+ <div class="mono gallery-address">${address}</div>
604
+ </div>
605
+ <button
606
+ class="button small"
607
+ onClick=${() => {
608
+ setValue(address);
609
+ setEditing(true);
610
+ }}
611
+ >
612
+ Change
613
+ </button>
614
+ </div>`;
615
+ }
616
+
617
+ return html`<form
618
+ class="field gallery-index-form"
619
+ onSubmit=${(event) => {
620
+ event.preventDefault();
621
+ save(value.trim());
622
+ }}
623
+ >
624
+ <label class="label" for="gallery-index">
625
+ Index: a GitHub repository (owner/name), or the https address of an index.json
626
+ </label>
627
+ <input
628
+ id="gallery-index"
629
+ class="mono"
630
+ value=${value}
631
+ autofocus
632
+ spellcheck=${false}
633
+ autocapitalize="off"
634
+ onInput=${(event) => setValue(event.currentTarget.value)}
635
+ />
636
+ ${problem && html`<div class="error-box small">${problem}</div>`}
637
+ <div class="sheet-actions gallery-wrap">
638
+ ${
639
+ fallback !== null &&
640
+ fallback !== address &&
641
+ html`<button type="button" class="button small ghost" disabled=${busy} onClick=${() => save("")}>
642
+ Use the default (${fallback})
643
+ </button>`
644
+ }
645
+ <button type="button" class="button small" onClick=${() => setEditing(false)}>Cancel</button>
646
+ <button class="button small primary" disabled=${busy}>Save</button>
647
+ </div>
648
+ </form>`;
649
+ }
650
+
651
+ const TABS = [
652
+ ["discover", "Discover"],
653
+ ["installed", "Installed"],
654
+ ["updates", "Updates"],
655
+ ];
656
+
657
+ const KINDS = [
658
+ ["all", "All", null],
659
+ ["extensions", "Extensions", null],
660
+ ["themes", "Themes", "palette"],
661
+ ];
662
+ const WANTS = [
663
+ ["tools", "Tools for Pi", "sparkle"],
664
+ ["app", "In the app", "tiles"],
665
+ ["changes", "Changes Pi", "chat"],
666
+ ];
667
+
668
+ function wanted(entry, want) {
669
+ const d = entry.declares;
670
+
671
+ if (want === null) {
672
+ return true;
673
+ }
674
+
675
+ if (isTheme(entry) || !d) {
676
+ return false;
677
+ }
678
+
679
+ if (want === "tools") {
680
+ return (d.tools ?? []).length + (d.readOnlyTools ?? []).length > 0;
681
+ }
682
+
683
+ if (want === "app") {
684
+ return d.client !== null || (d.routes ?? []).length > 0;
685
+ }
686
+
687
+ return (d.hooks ?? []).length + (d.sections ?? []).length + (d.wraps ?? []).length > 0;
688
+ }
689
+
690
+ /** One hub, whether opened from Extensions or Appearance's gallery link. */
691
+ export function GallerySheet({
692
+ selected = null,
693
+ tab = "discover",
694
+ origin = "extensions",
695
+ show = null,
696
+ Management,
697
+ }) {
698
+ const listing = useListing();
699
+ const { data, problem, loading, load } = listing;
700
+ const { reach, problem: reachProblem } = useReach(data);
701
+ // The sheet's own Back returns to the list on a phone; this one is for an entry opened on its own.
702
+ const sheetBack = useContext(SheetBack);
703
+ const modules = useModules(tab !== "discover" || selected !== null, data);
704
+ const [query, setQuery] = useState("");
705
+ const [kind, setKind] = useState("all");
706
+ const [want, setWant] = useState(null);
707
+ const needle = query.trim().toLowerCase();
708
+ const installed = data?.installed ?? [];
709
+ const updates = installed.filter((item) => item.update).length;
710
+ // Revoked offered versions stay hidden unless one is already installed here.
711
+ const offered = (data?.entries ?? []).filter(
712
+ (entry) => entry.installed !== null || revocation(entry, entry.source.commit) === undefined,
713
+ );
714
+ const entries =
715
+ tab === "discover"
716
+ ? offered
717
+ : [
718
+ ...offered.filter(
719
+ (entry) => entry.installed && (tab !== "updates" || entry.installed.update),
720
+ ),
721
+ ...installed.filter((item) => !item.listed && (tab !== "updates" || item.update)),
722
+ ];
723
+ const foundOf = (entry) =>
724
+ foundFor(reach, entry.listed === false ? null : entry, entry.installed ?? null);
725
+ const matches = entries.filter(
726
+ (entry) =>
727
+ (tab !== "discover" || kind === "all" || (kind === "themes") === isTheme(entry)) &&
728
+ (tab !== "discover" || wanted(entry, want)) &&
729
+ (needle === "" ||
730
+ [entry.name, entry.title, entry.description ?? "", ...(entry.tags ?? [])].some(
731
+ (text) => text.toLowerCase().includes(needle),
732
+ )),
733
+ );
734
+ const extensionMatches = matches.filter((entry) => !isTheme(entry));
735
+ const themeMatches = matches.filter(isTheme);
736
+ const ownThemes =
737
+ tab === "installed"
738
+ ? (store.state.themeList ?? []).filter(
739
+ (look) =>
740
+ !look.builtIn &&
741
+ !installed.some((item) => item.name === look.id) &&
742
+ (needle === "" ||
743
+ `${look.name} ${look.description ?? ""}`.toLowerCase().includes(needle)),
744
+ )
745
+ : [];
746
+ const detailName =
747
+ selected ??
748
+ extensionMatches[0]?.name ??
749
+ (tab === "discover" ? themeMatches[0]?.name : null);
750
+ const hidden = data?.hidden ?? { incompatible: 0, invalid: [] };
751
+ const select = (name) => openSheet({ type: "gallery-entry", id: name, tab, origin });
752
+ const moduleOf = (entry) =>
753
+ modules?.find((each) => each.file === (entry.installed ?? entry).file) ?? null;
754
+
755
+ const changeTab = (next) => {
756
+ setQuery("");
757
+ setKind("all");
758
+ setWant(null);
759
+ openSheet({ type: origin, tab: next });
760
+ };
761
+
762
+ const chip = (key, label, glyph, on, onClick) => html`<button
763
+ key=${key}
764
+ class=${`gallery-tag ${on ? "on" : ""}`}
765
+ aria-pressed=${on}
766
+ onClick=${onClick}
767
+ >
768
+ ${glyph && html`<${Icon} name=${glyph} size=${12} />`}${label}
769
+ </button>`;
770
+
771
+ const row = (entry) => html`<${EntryRow}
772
+ key=${entry.name}
773
+ entry=${entry}
774
+ found=${foundOf(entry)}
775
+ module=${moduleOf(entry)}
776
+ tab=${tab}
777
+ selected=${detailName === entry.name}
778
+ onOpen=${() => select(entry.name)}
779
+ onChanged=${load}
780
+ />`;
781
+
782
+ const card = (entry) => html`<${ThemeCard}
783
+ key=${entry.name}
784
+ entry=${entry}
785
+ palette=${paletteOf(entry, foundOf(entry))}
786
+ selected=${detailName === entry.name}
787
+ state=${tab === "discover" && entry.installed ? "Installed" : null}
788
+ onOpen=${() => select(entry.name)}
789
+ />`;
790
+
791
+ const tabs = html`<div class="ext-tabs" role="tablist" aria-label="Extensions">
792
+ ${TABS.map(
793
+ ([value, label]) => html`<button
794
+ key=${value}
795
+ class=${tab === value ? "on" : ""}
796
+ role="tab"
797
+ aria-selected=${tab === value}
798
+ onClick=${() => changeTab(value)}
799
+ >
800
+ ${label}
801
+ ${
802
+ value === "updates" &&
803
+ updates > 0 &&
804
+ html`<span class="ext-count" aria-label=${`${updates} available`}>${updates}</span>`
805
+ }
806
+ </button>`,
807
+ )}
808
+ </div>`;
809
+
810
+ const themesHere = [
811
+ ...themeMatches,
812
+ ...ownThemes.map((look) => ({ ...look, name: look.id, title: look.name, own: true })),
813
+ ];
814
+ const installedThemes =
815
+ themesHere.length > 0 &&
816
+ html`<${Section} title="Themes" count=${themesHere.length}>
817
+ <div class="ext-themes">
818
+ ${themesHere.map((entry) =>
819
+ entry.own
820
+ ? html`<${ThemeCard}
821
+ key=${entry.name}
822
+ entry=${entry}
823
+ palette=${entry.colors ? { colors: entry.colors, colorsLight: entry.colorsLight ?? null } : null}
824
+ state="Yours"
825
+ onOpen=${() => openSheet({ type: "appearance" })}
826
+ />`
827
+ : card(entry),
828
+ )}
829
+ </div>
830
+ <//>`;
831
+
832
+ return html`<${Sheet}
833
+ title="Extensions"
834
+ onClose=${closeSheet}
835
+ wide=${true}
836
+ className="extension-hub gallery"
837
+ actions=${tabs}
838
+ >
839
+ <div class=${`extension-hub-layout ${tab} ${selected ? "has-selection" : ""}`}>
840
+ <div class="extension-hub-list">
841
+ <div class="ext-toolbar">
842
+ <div class="extension-hub-toolbar">
843
+ <label class="ext-search">
844
+ <${Icon} name="search" size=${15} />
845
+ <input
846
+ type="search"
847
+ placeholder=${
848
+ tab === "installed"
849
+ ? "Search installed"
850
+ : tab === "updates"
851
+ ? "Search updates"
852
+ : `Search ${offered.length || ""} extensions and themes`.replace(
853
+ " ",
854
+ " ",
855
+ )
856
+ }
857
+ aria-label="Search extensions and themes"
858
+ value=${query}
859
+ onInput=${(event) => setQuery(event.currentTarget.value)}
860
+ />
861
+ </label>
862
+ ${
863
+ tab !== "installed" &&
864
+ html`<button
865
+ class="button small ext-icon-button"
866
+ aria-label="Refresh"
867
+ title="Read the index again"
868
+ disabled=${loading}
869
+ onClick=${() => load(true)}
870
+ >
871
+ <${Icon} name="reload" size=${15} />
872
+ </button>`
873
+ }
874
+ </div>
875
+ ${
876
+ tab === "discover" &&
877
+ data &&
878
+ html`<div class="gallery-tags ext-filters" role="group" aria-label="Filters">
879
+ ${KINDS.map(([value, label, glyph]) =>
880
+ chip(`kind-${value}`, label, glyph, kind === value, () =>
881
+ setKind(value),
882
+ ),
883
+ )}
884
+ <span class="ext-filters-gap"></span>
885
+ ${WANTS.map(([value, label, glyph]) =>
886
+ chip(value, label, glyph, want === value, () =>
887
+ setWant(want === value ? null : value),
888
+ ),
889
+ )}
890
+ </div>`
891
+ }
892
+ </div>
893
+ ${problem && html`<div class="error-box small">${problem}</div>`}
894
+ ${data?.error && html`<div class="error-box small">${data.error}</div>`}
895
+ ${!data && !problem && html`<${Loader} label="Reading the index" />`}
896
+ ${
897
+ tab === "discover" &&
898
+ extensionMatches.length > 0 &&
899
+ html`<${Section} title="Extensions" count=${extensionMatches.length}>
900
+ <div class="ext-list">${extensionMatches.map(row)}</div>
901
+ <//>`
902
+ }
903
+ ${
904
+ tab === "discover" &&
905
+ themeMatches.length > 0 &&
906
+ html`<${Section} title="Themes" count=${themeMatches.length}>
907
+ <div class="ext-themes">${themeMatches.map(card)}</div>
908
+ <//>`
909
+ }
910
+ ${
911
+ tab === "updates" &&
912
+ matches.length > 0 &&
913
+ html`<${Section} title="Updates" count=${matches.length}>
914
+ <div class="ext-list">${matches.map(row)}</div>
915
+ <//>`
916
+ }
917
+ ${
918
+ data &&
919
+ matches.length === 0 &&
920
+ tab !== "installed" &&
921
+ html`<div class="extension-hub-empty">
922
+ ${
923
+ tab === "updates" && !needle
924
+ ? html`<span class="ext-empty-mark"><${Icon} name="check" size=${20} /></span>
925
+ <span>Everything is up to date.</span>`
926
+ : needle || kind !== "all" || want
927
+ ? "Nothing matches. Try other words, or All."
928
+ : "The index has nothing for this Pi Pocket yet."
929
+ }
930
+ </div>`
931
+ }
932
+ ${
933
+ tab === "installed" &&
934
+ Management &&
935
+ html`<${Management}
936
+ galleryInstalled=${installed}
937
+ query=${query}
938
+ onChanged=${load}
939
+ hub=${true}
940
+ show=${show}
941
+ before=${extensionMatches.length > 0 && html`<div class="ext-list">${extensionMatches.map(row)}</div>`}
942
+ beforeCount=${extensionMatches.length}
943
+ between=${installedThemes}
944
+ />`
945
+ }
946
+ ${
947
+ tab === "discover" &&
948
+ data &&
949
+ html`<details class="gallery-technical ext-where">
950
+ <summary>Where these come from</summary>
951
+ <${IndexAddress} address=${data.address} onChanged=${() => load(true)} />
952
+ <p class="muted small">
953
+ ${data.fetchedAt ? `Read ${timeAgo(data.fetchedAt)}` : "Not read yet"}
954
+ </p>
955
+ ${
956
+ hidden.incompatible > 0 &&
957
+ html`<p class="muted small">
958
+ ${plural(hidden.incompatible, "entry")} need a newer Pi Pocket.
959
+ </p>`
960
+ }
961
+ ${
962
+ hidden.invalid.length > 0 &&
963
+ html`<ul class="gallery-problems small">
964
+ ${hidden.invalid.map(
965
+ (each, index) => html`<li key=${index}>
966
+ ${each.name ? `${each.name}: ` : ""}${each.problem}
967
+ </li>`,
968
+ )}
969
+ </ul>`
970
+ }
971
+ ${
972
+ data.repoUrl &&
973
+ html`<${Out} class="button small" href=${data.repoUrl}>
974
+ Submit yours <${Icon} name="external" size=${14} />
975
+ <//>`
976
+ }
977
+ </details>`
978
+ }
979
+ </div>
980
+ <div class="extension-hub-detail">
981
+ ${
982
+ detailName
983
+ ? html`${
984
+ !sheetBack &&
985
+ html`<button class="ext-back" onClick=${() => openSheet({ type: origin, tab })}>
986
+ <${Icon} name="back" size=${16} /> Back to ${TABS.find(([value]) => value === tab)[1]}
987
+ </button>`
988
+ }
989
+ <${GalleryEntrySheet}
990
+ key=${detailName}
991
+ name=${detailName}
992
+ listing=${listing}
993
+ reach=${reach}
994
+ reachProblem=${reachProblem}
995
+ module=${modules?.find((each) => each.file === `${detailName}.ts`) ?? null}
996
+ embedded=${true}
997
+ />`
998
+ : html`<div class="extension-hub-empty">Choose one to see what it does.</div>`
999
+ }
1000
+ </div>
1001
+ </div>
1002
+ <//>`;
1003
+ }
1004
+
1005
+ /** What a module declares, group by group: "nothing" for an empty one. */
1006
+ function Declares({ declares }) {
1007
+ return html`<dl class="pi-facts gallery-declares">
1008
+ ${GROUPS.map(
1009
+ ([key, label]) => html`<div key=${key}>
1010
+ <dt>${label}</dt>
1011
+ ${
1012
+ declared(declares, key).length > 0
1013
+ ? html`<dd class="mono">${declared(declares, key).join(", ")}</dd>`
1014
+ : html`<dd class="muted">nothing</dd>`
1015
+ }
1016
+ </div>`,
1017
+ )}
1018
+ <div>
1019
+ <dt>Browser module</dt>
1020
+ ${
1021
+ declares.client === null
1022
+ ? html`<dd class="muted">nothing</dd>`
1023
+ : html`<dd>for ${ACCESS_WORDS[declares.client] ?? declares.client}</dd>`
1024
+ }
1025
+ </div>
1026
+ <div>
1027
+ <dt>Widest access</dt>
1028
+ <dd>${ACCESS_WORDS[declares.access] ?? declares.access}</dd>
1029
+ </div>
1030
+ </dl>`;
1031
+ }
1032
+
1033
+ /**
1034
+ * Ask Pi to review an installed extension: a new session in the drop-in folder, in plan mode, with the review prompt.
1035
+ * Pi reads code that may hold instructions to it: without plan mode, which blocks its edits and commands that change
1036
+ * things, the review is not sent.
1037
+ */
1038
+ async function askForReview(name) {
1039
+ if (!planAvailable()) {
1040
+ throw new Error(
1041
+ "The review runs in plan mode, which is off: turn Plan mode on in Extensions first.",
1042
+ );
1043
+ }
1044
+
1045
+ const { cwd, prompt } = await galleryApi(`review/${encodeURIComponent(name)}`);
1046
+ const { id } = await actions.createSession(cwd);
1047
+
1048
+ try {
1049
+ await api(`c/${id}/plan`, { on: true });
1050
+ } catch (error) {
1051
+ navigate(id);
1052
+
1053
+ throw new Error(
1054
+ `Plan mode did not turn on (${error.message}), so the review was not sent.`,
1055
+ );
1056
+ }
1057
+
1058
+ await api(`c/${id}/submit`, { text: prompt, requestId: uid() });
1059
+ closeSheet();
1060
+ navigate(id);
1061
+ notify(
1062
+ "info",
1063
+ "Pi reviews it in plan mode: it reads the files, and plan mode keeps it from changing them.",
1064
+ );
1065
+ }
1066
+
1067
+ /** Turn an installed extension on (once the owner said they trust it, in its entry) or off. */
1068
+ async function setEnabled(installed, enabled) {
1069
+ // The server tells every tab who turned it on or off, this one too.
1070
+ await api(`extensions/${encodeURIComponent(installed.file)}`, { enabled });
1071
+
1072
+ return true;
1073
+ }
1074
+
1075
+ /** Embedded detail is content, not a second dialog inside the hub. */
1076
+ function EntryFrame({ embedded, title, children }) {
1077
+ return embedded
1078
+ ? html`<div class="gallery-entry-content">${children}</div>`
1079
+ : html`<${Sheet}
1080
+ title=${title}
1081
+ onClose=${closeSheet}
1082
+ wide=${true}
1083
+ className="gallery extension-detail-sheet"
1084
+ >
1085
+ ${children}
1086
+ <//>`;
1087
+ }
1088
+
1089
+ /** A newer version waits: one calm line, and the review that shows what it changes. */
1090
+ const UpdateCallout = ({ installed, name, busy }) =>
1091
+ installed?.update &&
1092
+ html`<div class="ext-callout">
1093
+ <span class="grow">Version ${installed.update.version} is ready. See what changes first.</span>
1094
+ <button
1095
+ class="button small primary"
1096
+ disabled=${busy}
1097
+ onClick=${() => openGallerySheet("gallery-update", name)}
1098
+ >
1099
+ Review update
1100
+ </button>
1101
+ </div>`;
1102
+
1103
+ /** Files that are not as installed: edited since, or gone. */
1104
+ const Changed = ({ installed }) =>
1105
+ installed?.changed.length > 0 &&
1106
+ html`<div class="gallery-warn small">
1107
+ Not as installed (edited since, or gone): <span class="mono">${installed.changed.join(", ")}</span>
1108
+ </div>`;
1109
+
1110
+ /** Removing it, kept apart at the end and quiet, with what it does. */
1111
+ const Remove = ({ label, text, busy, onClick }) =>
1112
+ html`<div class="ext-remove">
1113
+ <button class="button small ghost" disabled=${busy} onClick=${onClick}>${label}</button>
1114
+ <span class="muted small">${text}</span>
1115
+ </div>`;
1116
+
1117
+ /** The files the index pins, with their sizes. */
1118
+ const Files = ({ files }) =>
1119
+ files &&
1120
+ html`<div class="group">
1121
+ <div class="group-title">Files</div>
1122
+ <div class="sheet-list gallery-files">
1123
+ ${files.map(
1124
+ (file) => html`<div class="gallery-file" key=${file.name}>
1125
+ <span class="mono">${file.name}</span>
1126
+ <span class="muted small">${formatBytes(file.size)}</span>
1127
+ </div>`,
1128
+ )}
1129
+ </div>
1130
+ </div>`;
1131
+
1132
+ /** The facts both kinds of entry show: who made it, its version, where its files are, what it needs, and when. */
1133
+ function EntryFacts({ entry, installed, needs }) {
1134
+ const version = installed?.version ?? entry.version;
1135
+ const repo = installed?.repo ?? entry.source.repo;
1136
+ const commit = installed?.commit ?? entry.source.commit;
1137
+
1138
+ return html`<dl class="pi-facts">
1139
+ ${
1140
+ entry &&
1141
+ html`<div>
1142
+ <dt>Author</dt>
1143
+ <dd>
1144
+ ${entry.author.name}
1145
+ ${
1146
+ entry.author.github &&
1147
+ html` · <${Out} href=${`https://github.com/${entry.author.github}`}>@${entry.author.github}<//>`
1148
+ }
1149
+ </dd>
1150
+ </div>`
1151
+ }
1152
+ <div>
1153
+ <dt>Version</dt>
1154
+ <dd>
1155
+ ${version}${installed?.update ? html`<span class="warn"> · ${installed.update.version} available</span>` : ""}
1156
+ </dd>
1157
+ </div>
1158
+ <div>
1159
+ <dt>Source</dt>
1160
+ <dd class="mono">
1161
+ <${Out} href=${installed?.sourceUrl ?? entry.sourceUrl}>${repo} @ ${short(commit)}<//>
1162
+ </dd>
1163
+ </div>
1164
+ ${
1165
+ entry &&
1166
+ html`<div>
1167
+ <dt>Needs</dt>
1168
+ <dd>${needs}</dd>
1169
+ </div>`
1170
+ }
1171
+ ${
1172
+ installed &&
1173
+ html`<div>
1174
+ <dt>Installed</dt>
1175
+ <dd>
1176
+ ${timeAgo(installed.installedAt)}${installed.unlisted ? ` · ${installed.unlisted}` : ""}
1177
+ </dd>
1178
+ </div>`
1179
+ }
1180
+ </dl>`;
1181
+ }
1182
+
1183
+ function ReachSection({ declares, found, problem, edited = false }) {
1184
+ const rows = reachRows(declares, found);
1185
+ const missing = found?.scanned
1186
+ ? ["network", "keys", "programs", "files"].filter((key) => found.scanned[key].length === 0)
1187
+ : [];
1188
+
1189
+ return html`<section class="ext-block">
1190
+ <h4 class="ext-label">What it can reach</h4>
1191
+ ${
1192
+ edited &&
1193
+ html`<p class="ext-why warn">
1194
+ Its files were edited since it was installed: this is what the pinned version reaches, not what runs
1195
+ here. Read its source.
1196
+ </p>`
1197
+ }
1198
+ <ul class="ext-reach">
1199
+ ${rows.map(
1200
+ (row) => html`<li key=${row.key}>
1201
+ <${Icon} name=${row.glyph} size=${14} />
1202
+ <span class="ext-reach-text">${row.text}</span>
1203
+ <span class="ext-reach-from">${row.from}</span>
1204
+ </li>`,
1205
+ )}
1206
+ <li class="always">
1207
+ <${Icon} name="shield" size=${14} />
1208
+ <span class="ext-reach-text">${RISK}</span>
1209
+ <span class="ext-reach-from">Always</span>
1210
+ </li>
1211
+ </ul>
1212
+ ${
1213
+ missing.length > 0 &&
1214
+ html`<p class="ext-quiet">
1215
+ The scan found nothing for ${sentence(missing)}. It reads the code's text for addresses, keys, programs,
1216
+ and files, so the code can still reach more than it finds.
1217
+ </p>`
1218
+ }
1219
+ ${
1220
+ !found &&
1221
+ html`<p class="ext-quiet">
1222
+ ${problem ?? "Its code is not read yet for this version: what it reaches in its code shows here once it is."}
1223
+ </p>`
1224
+ }
1225
+ </section>`;
1226
+ }
1227
+
1228
+ function AddsSection({ declares: d }) {
1229
+ const readOnly = d.readOnlyTools ?? [];
1230
+ const tools = [...new Set([...(d.tools ?? []), ...readOnly])];
1231
+ const commands = (d.commands ?? []).map((each) => {
1232
+ const [scope, name] = each.split(" ");
1233
+
1234
+ return [`/${name}`, scope === "global" ? "owner" : "who can steer"];
1235
+ });
1236
+ const app = [
1237
+ d.client !== null && "pages and buttons",
1238
+ (d.routes ?? []).length > 0 && plural(d.routes.length, "server route"),
1239
+ ].filter(Boolean);
1240
+
1241
+ if (tools.length + commands.length + app.length === 0) {
1242
+ return html`<section class="ext-block">
1243
+ <h4 class="ext-label">What it adds</h4>
1244
+ <p class="ext-quiet">No tools, commands, or pages.</p>
1245
+ </section>`;
1246
+ }
1247
+
1248
+ return html`<section class="ext-block">
1249
+ <h4 class="ext-label">What it adds</h4>
1250
+ ${
1251
+ tools.length > 0 &&
1252
+ html`<div class="ext-codes">
1253
+ ${tools.map(
1254
+ (tool) => html`<code key=${tool}>
1255
+ ${tool}${readOnly.includes(tool) && html`<span>reads only</span>`}
1256
+ </code>`,
1257
+ )}
1258
+ </div>`
1259
+ }
1260
+ ${
1261
+ commands.length > 0 &&
1262
+ html`<div class="ext-codes">
1263
+ ${commands.map(([name, who]) => html`<code key=${name}>${name}<span>${who}</span></code>`)}
1264
+ </div>`
1265
+ }
1266
+ ${
1267
+ app.length > 0 &&
1268
+ html`<p class="ext-quiet">
1269
+ <${Icon} name="tiles" size=${13} />
1270
+ ${`${sentence(app).charAt(0).toUpperCase()}${sentence(app).slice(1)} in the app, for ${ACCESS_WORDS[d.access] ?? d.access}`}
1271
+ </p>`
1272
+ }
1273
+ </section>`;
1274
+ }
1275
+
1276
+ function TurnOnDialog({ title, declares, found, installed, busy, onCancel, onOff, onOn }) {
1277
+ const box = useRef(null);
1278
+ const rows = reachRows(declares, found);
1279
+ // While it installs or turns on, the question stays: closing it would hide code about to run.
1280
+ const cancel = () => !busy && onCancel();
1281
+
1282
+ useEffect(() => {
1283
+ const opener = document.activeElement;
1284
+
1285
+ box.current?.querySelector("[data-cancel]")?.focus();
1286
+
1287
+ return () => opener?.isConnected && opener.focus({ preventScroll: true });
1288
+ }, []);
1289
+
1290
+ const onKeyDown = (event) => {
1291
+ if (event.key === "Escape" && !event.isComposing && event.keyCode !== 229) {
1292
+ event.preventDefault();
1293
+ event.stopPropagation();
1294
+ cancel();
1295
+
1296
+ return;
1297
+ }
1298
+
1299
+ if (event.key === "Tab") {
1300
+ const stops = [...box.current.querySelectorAll("button:not(:disabled)")];
1301
+ const at = stops.indexOf(document.activeElement);
1302
+ const next = event.shiftKey
1303
+ ? at <= 0
1304
+ ? stops.at(-1)
1305
+ : stops[at - 1]
1306
+ : at === stops.length - 1
1307
+ ? stops[0]
1308
+ : stops[at + 1];
1309
+
1310
+ event.preventDefault();
1311
+ event.stopPropagation();
1312
+ next?.focus();
1313
+ }
1314
+ };
1315
+
1316
+ return html`<div
1317
+ class="ext-dialog-scrim"
1318
+ onMouseDown=${(event) => event.target === event.currentTarget && cancel()}
1319
+ >
1320
+ <div
1321
+ class="ext-dialog"
1322
+ role="dialog"
1323
+ aria-modal="true"
1324
+ aria-labelledby="ext-dialog-title"
1325
+ ref=${box}
1326
+ onKeyDown=${onKeyDown}
1327
+ >
1328
+ <h3 id="ext-dialog-title">${installed ? "Turn on" : "Install and turn on"} ${title}?</h3>
1329
+ <p>${RISK}</p>
1330
+ ${
1331
+ installed?.changed.length > 0 &&
1332
+ html`<p class="ext-why warn">
1333
+ Its files were edited since it was installed: this is what the pinned version reaches, not what
1334
+ runs here.
1335
+ </p>`
1336
+ }
1337
+ ${
1338
+ rows.length > 0
1339
+ ? html`<ul class="ext-reach compact">
1340
+ ${rows.map(
1341
+ (row) => html`<li key=${row.key}>
1342
+ <${Icon} name=${row.glyph} size=${14} />
1343
+ <span class="ext-reach-text">${row.text}</span>
1344
+ </li>`,
1345
+ )}
1346
+ </ul>
1347
+ <p class="ext-quiet">
1348
+ The scan reads text, so the code can still reach more.
1349
+ </p>`
1350
+ : found
1351
+ ? html`<p class="ext-quiet">
1352
+ The scan of its code found no address, key, program, or file, and it declares no hooks.
1353
+ The scan reads text, so the code can still reach more.
1354
+ </p>`
1355
+ : html`<p class="ext-quiet">Its code is not read yet: read it with View source first.</p>`
1356
+ }
1357
+ <div class="ext-dialog-actions">
1358
+ <button class="button small" data-cancel disabled=${busy} onClick=${cancel}>Cancel</button>
1359
+ ${
1360
+ !installed &&
1361
+ html`<button class="button small" disabled=${busy} onClick=${onOff}>
1362
+ Install turned off
1363
+ </button>`
1364
+ }
1365
+ <button class="button small primary" disabled=${busy} onClick=${onOn}>
1366
+ ${installed ? "Turn on" : "Install and turn on"}
1367
+ </button>
1368
+ </div>
1369
+ </div>
1370
+ </div>`;
1371
+ }
1372
+
1373
+ function EntryHead({ name, title, entry, installed, theme, size }) {
1374
+ const meta = [
1375
+ entry?.author?.name ?? (installed?.unlisted ? "not in the index" : null),
1376
+ `v${installed?.version ?? entry?.version}`,
1377
+ entry && plural(entry.files.length, "file"),
1378
+ size > 0 && formatBytes(size),
1379
+ theme && "theme",
1380
+ ].filter(Boolean);
1381
+
1382
+ return html`<header class="ext-detail-head">
1383
+ <${Tile} name=${name} title=${title} icon=${theme ? "palette" : null} large=${true} />
1384
+ <div class="ext-detail-name">
1385
+ <h3 class="pi-title">${title}</h3>
1386
+ <div class="ext-detail-by">${meta.join(" · ")}</div>
1387
+ </div>
1388
+ </header>`;
1389
+ }
1390
+
1391
+ export function GalleryEntrySheet({
1392
+ name,
1393
+ listing,
1394
+ reach = null,
1395
+ reachProblem = null,
1396
+ module = null,
1397
+ embedded = false,
1398
+ }) {
1399
+ const { data, problem, load } = useListing(listing);
1400
+ const [busy, setBusy] = useState(false);
1401
+ // Set at once, not at the next render: a second tap in the same moment must not run it twice.
1402
+ const going = useRef(false);
1403
+ const [asking, setAsking] = useState(false);
1404
+ const entry = data?.entries.find((each) => each.name === name) ?? null;
1405
+ const installed =
1406
+ entry?.installed ?? data?.installed.find((each) => each.name === name) ?? null;
1407
+
1408
+ const run = (work, reload = true) => {
1409
+ if (going.current) {
1410
+ return;
1411
+ }
1412
+
1413
+ going.current = true;
1414
+ setBusy(true);
1415
+ attempt(work).finally(() => {
1416
+ going.current = false;
1417
+ setBusy(false);
1418
+
1419
+ if (reload) {
1420
+ load();
1421
+ }
1422
+ });
1423
+ };
1424
+
1425
+ if (!entry && !installed) {
1426
+ return html`<${EntryFrame} title="Extension" embedded=${embedded}>
1427
+ ${problem && html`<div class="error-box small">${problem}</div>`}
1428
+ ${
1429
+ data === null
1430
+ ? !problem && html`<${Loader} label="Reading the index" />`
1431
+ : html`<p class="muted">The index does not list ${name}, and it is not installed.</p>`
1432
+ }
1433
+ <//>`;
1434
+ }
1435
+
1436
+ const found = foundFor(reach, entry, installed);
1437
+
1438
+ if (isTheme(entry ?? installed)) {
1439
+ return html`<${ThemeEntry}
1440
+ name=${name}
1441
+ entry=${entry}
1442
+ installed=${installed}
1443
+ palette=${paletteOf(entry ?? installed, found)}
1444
+ problem=${problem}
1445
+ busy=${busy}
1446
+ run=${run}
1447
+ embedded=${embedded}
1448
+ />`;
1449
+ }
1450
+
1451
+ const title = installed?.title ?? entry.title;
1452
+ const declares = installed?.declares ?? entry.declares;
1453
+ const files =
1454
+ entry && (!installed || entry.source.commit === installed.commit) ? entry.files : null;
1455
+ const offeredRevoked = !installed && entry ? revocation(entry, entry.source.commit) : undefined;
1456
+ const on = installed?.enabled && installed.revoked === null;
1457
+ const status = installed ? liveStatus(installed, module, "installed") : null;
1458
+ const why = installed ? statusWhy(installed, module) : null;
1459
+
1460
+ // Bound to the manifest the owner saw (`pin`): when the index changed since, the server refuses with 409, and the
1461
+ // entry is read again (run's reload) for the owner to look at once more.
1462
+ const install = (andOn) =>
1463
+ run(async () => {
1464
+ const result = await galleryApi(`install/${encodeURIComponent(name)}`, {
1465
+ pin: entry.pin,
1466
+ });
1467
+
1468
+ if (andOn) {
1469
+ await setEnabled(result, true);
1470
+ }
1471
+
1472
+ setAsking(false);
1473
+ });
1474
+
1475
+ const toggle = (enabled) =>
1476
+ run(async () => {
1477
+ await setEnabled(installed, enabled);
1478
+ setAsking(false);
1479
+ });
1480
+
1481
+ const uninstall = () => {
1482
+ if (
1483
+ confirm(
1484
+ `Remove ${title}?\n\n${installed.enabled ? "It is turned off first, then its" : "Its"} files are deleted from the extensions folder.`,
1485
+ )
1486
+ ) {
1487
+ run(() => galleryApi(`uninstall/${encodeURIComponent(name)}`, {}));
1488
+ }
1489
+ };
1490
+
1491
+ const source = html`<button
1492
+ class="button small"
1493
+ disabled=${busy}
1494
+ onClick=${() => openGallerySheet("gallery-source", name)}
1495
+ >
1496
+ View source
1497
+ </button>`;
1498
+ const askPi = html`<button class="button small" disabled=${busy} onClick=${() => run(() => askForReview(name), false)}>
1499
+ <${Icon} name="sparkle" size=${14} /> Ask Pi to review
1500
+ </button>`;
1501
+ const revoked = installed?.revoked ?? offeredRevoked;
1502
+
1503
+ return html`<${EntryFrame} title=${title} embedded=${embedded}>
1504
+ ${problem && html`<div class="error-box small">${problem}</div>`}
1505
+ ${
1506
+ revoked !== null &&
1507
+ revoked !== undefined &&
1508
+ html`<div class="error-box gallery-revoked" role="alert">
1509
+ <strong>The gallery revoked this version.</strong> Its reason: ${revoked}
1510
+ ${
1511
+ installed?.enabled &&
1512
+ html`<div class="sheet-actions">
1513
+ <button class="button small primary" disabled=${busy} onClick=${() => toggle(false)}>
1514
+ Turn it off
1515
+ </button>
1516
+ </div>`
1517
+ }
1518
+ </div>`
1519
+ }
1520
+ <${EntryHead} name=${name} title=${title} entry=${entry} installed=${installed} />
1521
+ ${entry?.description && html`<p class="gallery-description">${entry.description}</p>`}
1522
+ <${UpdateCallout} installed=${installed} name=${name} busy=${busy} />
1523
+ ${
1524
+ status &&
1525
+ html`<div class="ext-standing">
1526
+ <${Status} status=${status} />
1527
+ <span class="muted small">
1528
+ ${on ? "Runs in every session." : installed.revoked === null ? "Installed, turned off: nothing runs." : ""}
1529
+ </span>
1530
+ </div>`
1531
+ }
1532
+ ${why && html`<div class=${`ext-why ${why.kind} small`}>${why.text}</div>`}
1533
+ <div class="ext-actions">
1534
+ ${
1535
+ !installed
1536
+ ? html`<button
1537
+ class="button small primary"
1538
+ disabled=${busy || offeredRevoked !== undefined}
1539
+ onClick=${() => setAsking(true)}
1540
+ >
1541
+ Install and turn on
1542
+ </button>
1543
+ <button
1544
+ class="button small"
1545
+ disabled=${busy || offeredRevoked !== undefined}
1546
+ onClick=${() => install(false)}
1547
+ >
1548
+ Install turned off
1549
+ </button>
1550
+ ${source}`
1551
+ : on
1552
+ ? html`<button class="button small" disabled=${busy} onClick=${() => toggle(false)}>
1553
+ Turn off
1554
+ </button>
1555
+ <button
1556
+ class="button small"
1557
+ disabled=${busy}
1558
+ onClick=${() =>
1559
+ run(() =>
1560
+ api(
1561
+ `extensions/${encodeURIComponent(installed.file)}/reload`,
1562
+ {},
1563
+ ),
1564
+ )}
1565
+ >
1566
+ <${Icon} name="reload" size=${14} /> Reload
1567
+ </button>
1568
+ ${source} ${askPi}`
1569
+ : html`${
1570
+ installed.revoked === null &&
1571
+ html`<button class="button small primary" disabled=${busy} onClick=${() => setAsking(true)}>
1572
+ Turn on
1573
+ </button>`
1574
+ }
1575
+ ${source} ${askPi}`
1576
+ }
1577
+ </div>
1578
+ <${Changed} installed=${installed} />
1579
+ <${ReachSection}
1580
+ declares=${declares}
1581
+ found=${found}
1582
+ problem=${reachProblem}
1583
+ edited=${installed?.changed.length > 0}
1584
+ />
1585
+ <${AddsSection} declares=${declares} />
1586
+ ${
1587
+ entry?.tags.length > 0 &&
1588
+ html`<p class="ext-tags">${entry.tags.map((tag) => html`<span key=${tag}>#${tag}</span>`)}</p>`
1589
+ }
1590
+ <details class="gallery-technical">
1591
+ <summary>Technical details</summary>
1592
+ <${EntryFacts}
1593
+ entry=${entry}
1594
+ installed=${installed}
1595
+ needs=${entry && `Pi Pocket ${entry.minPocket} or newer · extension API ${entry.pocketApi}`}
1596
+ />
1597
+ <${Files} files=${files} />
1598
+ <div class="group">
1599
+ <div class="group-title">Everything it declares</div>
1600
+ <${Declares} declares=${declares} />
1601
+ </div>
1602
+ </details>
1603
+ ${
1604
+ installed &&
1605
+ html`<${Remove}
1606
+ label="Uninstall"
1607
+ text=${installed.enabled ? "Turns it off and deletes its files." : "Deletes its files."}
1608
+ busy=${busy}
1609
+ onClick=${uninstall}
1610
+ />`
1611
+ }
1612
+ ${
1613
+ asking &&
1614
+ html`<${TurnOnDialog}
1615
+ title=${title}
1616
+ declares=${declares}
1617
+ found=${found}
1618
+ installed=${installed}
1619
+ busy=${busy}
1620
+ onCancel=${() => setAsking(false)}
1621
+ onOff=${() => install(false)}
1622
+ onOn=${() => (installed ? toggle(true) : install(true))}
1623
+ />`
1624
+ }
1625
+ <//>`;
1626
+ }
1627
+
1628
+ function themeChanges(files, palette) {
1629
+ const names = (files ?? []).map((file) => file.name);
1630
+ const fonts = [
1631
+ ...new Set(
1632
+ names
1633
+ .filter((file) => /\.(woff2?|ttf|otf)$/i.test(file))
1634
+ .map((file) =>
1635
+ file
1636
+ .split("/")
1637
+ .pop()
1638
+ .replace(/\.(woff2?|ttf|otf)$/i, "")
1639
+ .replace(/[-_](Roman|Italic|Regular|Bold|Variable|VF).*$/i, "")
1640
+ .replace(/([a-z])([A-Z0-9])/g, "$1 $2"),
1641
+ ),
1642
+ ),
1643
+ ];
1644
+ const images = names.filter((file) => /\.(png|jpe?g|webp|avif|gif|svg)$/i.test(file));
1645
+
1646
+ return [
1647
+ ["swatch", palette ? `Colors, ${modeWords(palette)}` : "Its own colors"],
1648
+ names.some((file) => file.endsWith("layout.css")) && [
1649
+ "tiles",
1650
+ "A layout of its own: it moves and restyles parts of the app",
1651
+ ],
1652
+ fonts.length > 0 && [
1653
+ "file",
1654
+ `Its own ${fonts.length === 1 ? "font" : "fonts"}: ${sentence(fonts)}`,
1655
+ ],
1656
+ images.length > 0 && ["artifact", plural(images.length, "image")],
1657
+ ].filter(Boolean);
1658
+ }
1659
+
1660
+ const Swatches = ({ colors }) =>
1661
+ html`<div class="ext-swatches">
1662
+ ${["background", "foreground", "accent", ...THEME_DOTS]
1663
+ .filter((key) => HEX.test(colors[key] ?? ""))
1664
+ .map(
1665
+ (key) =>
1666
+ html`<i key=${key} style=${`background:${colors[key]}`} title=${`${key} ${colors[key]}`}></i>`,
1667
+ )}
1668
+ <span class="mono">
1669
+ ${[
1670
+ ["background", "background"],
1671
+ ["foreground", "text"],
1672
+ ["accent", "accent"],
1673
+ ]
1674
+ .filter(([key]) => HEX.test(colors[key] ?? ""))
1675
+ .map(([key, label]) => `${label} ${colors[key]}`)
1676
+ .join(" · ")}
1677
+ </span>
1678
+ </div>`;
1679
+
1680
+ function ThemeEntry({ name, entry, installed, palette, problem, busy, run, embedded }) {
1681
+ const title = installed?.title ?? entry.title;
1682
+ const files =
1683
+ entry && (!installed || entry.source.commit === installed.commit) ? entry.files : null;
1684
+ const offeredRevoked = !installed && entry ? revocation(entry, entry.source.commit) : undefined;
1685
+ const usable = store.state.themeList?.some((each) => each.id === name && each.usable);
1686
+ const inUse = (prefs().look ?? BASE_LOOK) === name;
1687
+ const size = (entry?.files ?? []).reduce((sum, file) => sum + file.size, 0);
1688
+
1689
+ const install = () =>
1690
+ run(() => galleryApi(`install/${encodeURIComponent(name)}`, { pin: entry.pin }));
1691
+
1692
+ const uninstall = () => {
1693
+ if (
1694
+ confirm(
1695
+ `Remove the theme ${title}?\n\nIts folder moves to themes/.removed/ in the data folder. Browsers that use it go back to Pocket.`,
1696
+ )
1697
+ ) {
1698
+ run(async () => {
1699
+ await galleryApi(`uninstall/${encodeURIComponent(name)}`, {});
1700
+
1701
+ if (prefs().look === name) {
1702
+ setPrefs({ look: BASE_LOOK });
1703
+ }
1704
+ });
1705
+ }
1706
+ };
1707
+
1708
+ return html`<${EntryFrame} title=${title} embedded=${embedded}>
1709
+ ${problem && html`<div class="error-box small">${problem}</div>`}
1710
+ ${
1711
+ (installed?.revoked ?? offeredRevoked) &&
1712
+ html`<div class="error-box gallery-revoked" role="alert">
1713
+ <strong>The gallery revoked this version.</strong> Its reason: ${installed?.revoked ?? offeredRevoked}
1714
+ </div>`
1715
+ }
1716
+ <${EntryHead}
1717
+ name=${name}
1718
+ title=${title}
1719
+ entry=${entry}
1720
+ installed=${installed}
1721
+ theme=${true}
1722
+ size=${size}
1723
+ />
1724
+ <div class=${`ext-preview ${palette?.colorsLight ? "pair" : ""}`}>
1725
+ <figure>
1726
+ <${ThemeDesk} colors=${palette?.colors ?? null} big=${true} />
1727
+ <figcaption>${palette ? (palette.colorsLight || palette.colors.mode !== "light" ? "Dark" : "Light") : "Its colors show once the gallery reads them"}</figcaption>
1728
+ </figure>
1729
+ ${
1730
+ palette?.colorsLight &&
1731
+ html`<figure>
1732
+ <${ThemeDesk} colors=${palette.colorsLight} big=${true} />
1733
+ <figcaption>Light</figcaption>
1734
+ </figure>`
1735
+ }
1736
+ </div>
1737
+ ${entry?.description && html`<p class="gallery-description">${entry.description}</p>`}
1738
+ <${UpdateCallout} installed=${installed} name=${name} busy=${busy} />
1739
+ <div class="ext-actions">
1740
+ ${
1741
+ !installed
1742
+ ? html`<button
1743
+ class="button small primary"
1744
+ disabled=${busy || offeredRevoked !== undefined}
1745
+ onClick=${install}
1746
+ >
1747
+ Install
1748
+ </button>`
1749
+ : html`<button
1750
+ class="button small primary"
1751
+ disabled=${!usable || inUse}
1752
+ onClick=${(event) => chooseLook(name, event)}
1753
+ >
1754
+ ${inUse ? "In use in this browser" : "Use it in this browser"}
1755
+ </button>
1756
+ <button class="button small" onClick=${() => openSheet({ type: "appearance" })}>
1757
+ Open Appearance
1758
+ </button>`
1759
+ }
1760
+ <button
1761
+ class="button small"
1762
+ disabled=${busy}
1763
+ onClick=${() => openGallerySheet("gallery-source", name)}
1764
+ >
1765
+ View source
1766
+ </button>
1767
+ </div>
1768
+ <p class="ext-quiet">
1769
+ ${installed ? "Each person picks a theme for their own browser: using it here changes nothing for anyone else." : "Installing adds it to Appearance. Nothing changes until someone picks it."}
1770
+ </p>
1771
+ ${
1772
+ installed?.problem &&
1773
+ html`<div class="gallery-warn small">Appearance does not offer it as it is: ${installed.problem}</div>`
1774
+ }
1775
+ <${Changed} installed=${installed} />
1776
+ <section class="ext-block">
1777
+ <h4 class="ext-label">What it changes</h4>
1778
+ <ul class="ext-reach">
1779
+ ${themeChanges(entry?.files, palette).map(
1780
+ ([glyph, text]) => html`<li key=${glyph}>
1781
+ <${Icon} name=${glyph} size=${14} />
1782
+ <span class="ext-reach-text">${text}</span>
1783
+ <span class="ext-reach-from">In its files</span>
1784
+ </li>`,
1785
+ )}
1786
+ <li class="always">
1787
+ <${Icon} name="shield" size=${14} />
1788
+ <span class="ext-reach-text">${THEME_RISK}</span>
1789
+ <span class="ext-reach-from">Always</span>
1790
+ </li>
1791
+ </ul>
1792
+ </section>
1793
+ ${
1794
+ palette &&
1795
+ html`<section class="ext-block">
1796
+ <h4 class="ext-label">Palette</h4>
1797
+ <${Swatches} colors=${palette.colors} />
1798
+ ${palette.colorsLight && html`<${Swatches} colors=${palette.colorsLight} />`}
1799
+ </section>`
1800
+ }
1801
+ ${
1802
+ entry?.tags.length > 0 &&
1803
+ html`<p class="ext-tags">${entry.tags.map((tag) => html`<span key=${tag}>#${tag}</span>`)}</p>`
1804
+ }
1805
+ <details class="gallery-technical">
1806
+ <summary>Technical details</summary>
1807
+ <${EntryFacts}
1808
+ entry=${entry}
1809
+ installed=${installed}
1810
+ needs=${entry && `Pi Pocket ${entry.minPocket} or newer · theme API ${entry.themeApi}`}
1811
+ />
1812
+ <${Files} files=${files} />
1813
+ </details>
1814
+ ${
1815
+ installed &&
1816
+ html`<${Remove}
1817
+ label="Remove"
1818
+ text="Moves it to themes/.removed/ in the data folder."
1819
+ busy=${busy}
1820
+ onClick=${uninstall}
1821
+ />`
1822
+ }
1823
+ <//>`;
1824
+ }
1825
+
1826
+ /** An extension's files, to read: as installed, or downloaded from the pinned commit before it is. */
1827
+ export function GallerySourceSheet({ name }) {
1828
+ const [data, setData] = useState(null);
1829
+ const [problem, setProblem] = useState(null);
1830
+
1831
+ useRoute(`source/${encodeURIComponent(name)}`, setData, setProblem);
1832
+
1833
+ return html`<${Sheet}
1834
+ title=${data ? `Source: ${data.title}` : "Source"}
1835
+ onClose=${closeSheet}
1836
+ wide=${true}
1837
+ className="gallery extension-detail-sheet"
1838
+ >
1839
+ ${problem && html`<div class="error-box small">${problem}</div>`}
1840
+ ${!data && !problem && html`<${Loader} label="Getting its files" />`}
1841
+ ${
1842
+ data &&
1843
+ html`<p class="muted small">
1844
+ ${data.from === "installed" ? "The files as they are in your extensions folder." : "Downloaded from the commit the index pins, and checked against its hashes. Nothing is installed."}
1845
+ </p>`
1846
+ }
1847
+ ${data?.files.map(
1848
+ (file) => html`<section class="gallery-source" key=${file.name}>
1849
+ <div class="gallery-source-head">
1850
+ <span class="mono gallery-source-name">${file.name}</span>
1851
+ <span class="muted small">${formatBytes(file.size)}</span>
1852
+ ${
1853
+ file.missing
1854
+ ? html`<span class="pi-tag gallery-bad">missing</span>`
1855
+ : file.pinned
1856
+ ? html`<span class="pi-tag gallery-on" title="Matches the hash the index pins">✓ pinned</span>`
1857
+ : html`<span class="pi-tag behind" title="Not the file the index pins">changed</span>`
1858
+ }
1859
+ ${file.binary && html`<span class="pi-tag gallery-plain">binary</span>`}
1860
+ </div>
1861
+ ${file.text !== null && html`<${Highlighted} class="gallery-code" text=${file.text} lang=${file.name} />`}
1862
+ </section>`,
1863
+ )}
1864
+ <//>`;
1865
+ }
1866
+
1867
+ /** What changed in each group of declarations: lines like "Hooks: + after_tool_call". */
1868
+ function declarationChanges(before, after) {
1869
+ const lines = [];
1870
+
1871
+ for (const [key, label] of GROUPS) {
1872
+ const added = declared(after, key).filter((each) => !declared(before, key).includes(each));
1873
+ const removed = declared(before, key).filter(
1874
+ (each) => !declared(after, key).includes(each),
1875
+ );
1876
+
1877
+ if (added.length > 0 || removed.length > 0) {
1878
+ lines.push({ label, added, removed });
1879
+ }
1880
+ }
1881
+
1882
+ const words = (client) => (client === null ? "none" : `for ${ACCESS_WORDS[client] ?? client}`);
1883
+
1884
+ if (before.client !== after.client) {
1885
+ lines.push({
1886
+ label: "Browser module",
1887
+ from: words(before.client),
1888
+ to: words(after.client),
1889
+ });
1890
+ }
1891
+
1892
+ if (before.access !== after.access) {
1893
+ lines.push({
1894
+ label: "Widest access",
1895
+ from: ACCESS_WORDS[before.access] ?? before.access,
1896
+ to: ACCESS_WORDS[after.access] ?? after.access,
1897
+ });
1898
+ }
1899
+
1900
+ return lines;
1901
+ }
1902
+
1903
+ /** An update the index offers: what changes, the diff, and applying it. */
1904
+ export function GalleryUpdateSheet({ name }) {
1905
+ const [data, setData] = useState(null);
1906
+ const [problem, setProblem] = useState(null);
1907
+ const [busy, setBusy] = useState(false);
1908
+ const going = useRef(false);
1909
+
1910
+ const path = `update/${encodeURIComponent(name)}`;
1911
+ // Read again after the index changed: the sheet shows the update it offers now.
1912
+ const [round, setRound] = useState(0);
1913
+
1914
+ useRoute(
1915
+ `${path}?round=${round}`,
1916
+ (result) => {
1917
+ setData(result);
1918
+ setProblem(null);
1919
+ },
1920
+ setProblem,
1921
+ );
1922
+
1923
+ const apply = () => {
1924
+ if (going.current) {
1925
+ return;
1926
+ }
1927
+
1928
+ if (
1929
+ data.enabled &&
1930
+ !confirm(
1931
+ `Apply the update to ${data.title}?\n\nIt is on, so the new code runs as soon as it is in place.`,
1932
+ )
1933
+ ) {
1934
+ return;
1935
+ }
1936
+
1937
+ going.current = true;
1938
+ setBusy(true);
1939
+ attempt(async () => {
1940
+ let result;
1941
+
1942
+ try {
1943
+ // Bound to the manifest shown here (`pin`), and to whether it was on, as the question above said.
1944
+ result = await galleryApi(path, { pin: data.to.pin, enabled: data.enabled });
1945
+ } catch (error) {
1946
+ // The index, or the switch, changed since this preview: show the update as it stands now instead.
1947
+ if (error.status === 409) {
1948
+ setData(null);
1949
+ setRound(round + 1);
1950
+ }
1951
+
1952
+ throw error;
1953
+ }
1954
+
1955
+ if (result.restart) {
1956
+ notify(
1957
+ "warning",
1958
+ `${data.title}'s helper files changed while it is on: restart the server (Menu → Restart server) to load them.`,
1959
+ );
1960
+ }
1961
+
1962
+ // A row can open review without an entry beneath it. Drop the completed review before
1963
+ // showing the entry, so Back never returns to an obsolete update preview.
1964
+ openSheet({
1965
+ type: store.state.sheet.origin ?? "extensions",
1966
+ tab: store.state.sheet.tab ?? "updates",
1967
+ });
1968
+ openGallerySheet("gallery-entry", name);
1969
+ }).finally(() => {
1970
+ going.current = false;
1971
+ setBusy(false);
1972
+ });
1973
+ };
1974
+
1975
+ if (data === null) {
1976
+ return html`<${Sheet}
1977
+ title="Update"
1978
+ onClose=${closeSheet}
1979
+ wide=${true}
1980
+ className="gallery extension-detail-sheet"
1981
+ >
1982
+ ${
1983
+ problem
1984
+ ? html`<div class="error-box small">${problem}</div>`
1985
+ : html`<${Loader} label="Getting the new version" />`
1986
+ }
1987
+ <//>`;
1988
+ }
1989
+
1990
+ const changes =
1991
+ data.declares === null ? [] : declarationChanges(data.declares.before, data.declares.after);
1992
+
1993
+ return html`<${Sheet}
1994
+ title=${`Update ${data.title}`}
1995
+ onClose=${closeSheet}
1996
+ wide=${true}
1997
+ className="gallery extension-detail-sheet"
1998
+ >
1999
+ <dl class="pi-facts">
2000
+ <div>
2001
+ <dt>From</dt>
2002
+ <dd class="mono">${data.from.version} · ${short(data.from.commit)}</dd>
2003
+ </div>
2004
+ <div>
2005
+ <dt>To</dt>
2006
+ <dd class="mono">
2007
+ ${data.to.version} · <${Out} href=${data.sourceUrl}>${short(data.to.commit)}<//>
2008
+ </dd>
2009
+ </div>
2010
+ </dl>
2011
+ ${
2012
+ data.from.repo !== data.to.repo &&
2013
+ html`<div class="gallery-warn small" role="alert">
2014
+ It now comes from another repository: <span class="mono">${data.from.repo}</span> → <span class="mono">${data.to.repo}</span>. Make sure you trust the new one.
2015
+ </div>`
2016
+ }
2017
+ ${
2018
+ data.edited.length > 0 &&
2019
+ html`<div class="gallery-warn small" role="alert">
2020
+ Yours here, edited since it was installed or never part of it: <span class="mono">${data.edited.join(", ")}</span>. The diff is against your files, and the update replaces them.
2021
+ </div>`
2022
+ }
2023
+ ${
2024
+ data.declares === null
2025
+ ? html`<p class="muted small">
2026
+ It is checked as every theme is before it is in place. The version you have now goes to themes/.removed/ in the data folder.
2027
+ </p>`
2028
+ : html`<div class="group">
2029
+ <div class="group-title">What it declares</div>
2030
+ ${
2031
+ changes.length === 0
2032
+ ? html`<p class="muted small">The same as before.</p>`
2033
+ : html`<dl class="pi-facts gallery-declares">
2034
+ ${changes.map(
2035
+ (change) => html`<div key=${change.label}>
2036
+ <dt>${change.label}</dt>
2037
+ <dd>
2038
+ ${change.added?.length > 0 && html`<div class="mono gallery-added">+ ${change.added.join(", ")}</div>`}
2039
+ ${change.removed?.length > 0 && html`<div class="mono gallery-removed">− ${change.removed.join(", ")}</div>`}
2040
+ ${change.from !== undefined && html`<div>${change.from} → ${change.to}</div>`}
2041
+ </dd>
2042
+ </div>`,
2043
+ )}
2044
+ </dl>`
2045
+ }
2046
+ </div>`
2047
+ }
2048
+ <div class="group">
2049
+ <div class="group-title">Files</div>
2050
+ <div class="sheet-list gallery-files">
2051
+ ${data.files.map(
2052
+ (file) => html`<div class="gallery-file" key=${file.name}>
2053
+ <span class="mono">${file.name}</span>
2054
+ <span class=${`small gallery-change ${file.change}`}>${file.change}</span>
2055
+ </div>`,
2056
+ )}
2057
+ </div>
2058
+ </div>
2059
+ ${data.diff && html`<${DiffBlock} text=${data.diff} />`}
2060
+ ${
2061
+ data.enabled &&
2062
+ html`<p class="gallery-warn small">It is on: the new code runs as soon as it is in place.</p>`
2063
+ }
2064
+ <div class="gallery-actions">
2065
+ <button class="button primary" disabled=${busy} onClick=${apply}>Apply update</button>
2066
+ </div>
2067
+ <//>`;
2068
+ }
2069
+
2070
+ /** The rules an index entry keeps for what only its author fills in (`gallery/entry.ts`, which the index checks with). */
2071
+ const OWNER = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/;
2072
+ const REPO_NAME = /^[A-Za-z0-9._-]{1,100}$/;
2073
+ const PART = /^[A-Za-z0-9_][A-Za-z0-9._-]{0,99}$/;
2074
+ const TAG = /^[a-z0-9][a-z0-9-]{0,23}$/;
2075
+ /** Past this, GitHub's page would refuse the link with the entry in it: the owner copies the entry instead. */
2076
+ const LINK_LIMIT = 6000;
2077
+
2078
+ /** Why what the owner typed for each of the author's fields would not pass the index's checks, by field. */
2079
+ function fieldProblems({ repo, commit, path, tags, github, name }) {
2080
+ const [owner, repository, ...rest] = repo.split("/");
2081
+ const parts = path === "" ? [] : path.split("/");
2082
+
2083
+ return {
2084
+ repo:
2085
+ repo === ""
2086
+ ? "Give the GitHub repository with its files."
2087
+ : rest.length > 0 ||
2088
+ !OWNER.test(owner ?? "") ||
2089
+ !REPO_NAME.test(repository ?? "") ||
2090
+ repository === "." ||
2091
+ repository === ".."
2092
+ ? "Write it as owner/name, such as tannermidd/pocket-clock."
2093
+ : null,
2094
+ commit:
2095
+ commit === ""
2096
+ ? "Give the commit with its files."
2097
+ : /^[0-9a-f]{40}$/.test(commit)
2098
+ ? null
2099
+ : "Write the full commit ID: 40 letters and digits, from a to f and 0 to 9.",
2100
+ path:
2101
+ parts.length > 4 || parts.some((part) => !PART.test(part))
2102
+ ? "Write a folder of the repository, such as extension, four deep at most."
2103
+ : null,
2104
+ tags:
2105
+ tags.length > 10 || tags.some((tag) => !TAG.test(tag))
2106
+ ? "Use up to 10 tags of lowercase letters, digits, and -."
2107
+ : null,
2108
+ github: github === "" || OWNER.test(github) ? null : "Write your GitHub name only.",
2109
+ name: name === "" || name.length > 60 ? "Give your name, 60 characters at most." : null,
2110
+ };
2111
+ }
2112
+
2113
+ /** One of the author's fields, with what is wrong with it once something is typed. */
2114
+ function Field({ id, label, hint, value, onInput, problem, placeholder, mono = true }) {
2115
+ return html`<div class="field gallery-field">
2116
+ <label class="label" for=${id}>${label}</label>
2117
+ <input
2118
+ id=${id}
2119
+ class=${mono ? "mono" : ""}
2120
+ value=${value}
2121
+ placeholder=${placeholder}
2122
+ spellcheck=${false}
2123
+ autocapitalize="off"
2124
+ autocomplete="off"
2125
+ aria-invalid=${problem !== null && value !== ""}
2126
+ onInput=${(event) => onInput(event.currentTarget.value)}
2127
+ />
2128
+ ${
2129
+ problem !== null && value !== ""
2130
+ ? html`<div class="small warn">${problem}</div>`
2131
+ : hint && html`<div class="muted small">${hint}</div>`
2132
+ }
2133
+ </div>`;
2134
+ }
2135
+
2136
+ /**
2137
+ * Share one of your own drop-ins, or with `theme`, one of your theme folders (`file` is its id): the checks, where its
2138
+ * files are on GitHub (only its author knows), its index entry made from both, and the pull request, which opens only
2139
+ * once the entry can pass the index's checks.
2140
+ */
2141
+ export function GalleryShareSheet({ file, theme = false }) {
2142
+ const [data, setData] = useState(null);
2143
+ const [problem, setProblem] = useState(null);
2144
+ const [form, setForm] = useState({
2145
+ repo: "",
2146
+ commit: "",
2147
+ path: "",
2148
+ tags: "",
2149
+ github: "",
2150
+ name: null,
2151
+ });
2152
+
2153
+ useRoute(`${theme ? "share-theme" : "share"}/${encodeURIComponent(file)}`, setData, setProblem);
2154
+ // A theme by its name, as Appearance shows it; a drop-in by its file.
2155
+ const shareName = theme
2156
+ ? (store.state.themeList?.find((each) => each.id === file)?.name ?? file)
2157
+ : file;
2158
+
2159
+ if (!data) {
2160
+ return html`<${Sheet} title=${`Share ${shareName}`} onClose=${closeSheet} wide=${true} className="gallery">
2161
+ ${problem ? html`<div class="error-box small">${problem}</div>` : html`<${Loader} label="Checking it" />`}
2162
+ <//>`;
2163
+ }
2164
+
2165
+ const set = (field) => (value) => setForm({ ...form, [field]: value });
2166
+ const typed = {
2167
+ repo: form.repo
2168
+ .trim()
2169
+ .replace(/^https:\/\/github\.com\//, "")
2170
+ .replace(/(\.git)?\/*$/, ""),
2171
+ commit: form.commit.trim().toLowerCase(),
2172
+ path: form.path.trim().replace(/^\/+|\/+$/g, ""),
2173
+ tags: form.tags
2174
+ .split(/[\s,]+/)
2175
+ .map((tag) => tag.trim().toLowerCase())
2176
+ .filter(Boolean),
2177
+ github: form.github.trim().replace(/^@/, ""),
2178
+ name: (form.name ?? data.entry.author.name).trim(),
2179
+ };
2180
+ const wrong = fieldProblems(typed);
2181
+ const entry = {
2182
+ ...data.entry,
2183
+ tags: typed.tags,
2184
+ author: { name: typed.name, ...(typed.github === "" ? {} : { github: typed.github }) },
2185
+ source: {
2186
+ repo: typed.repo,
2187
+ commit: typed.commit,
2188
+ ...(typed.path === "" ? {} : { path: typed.path }),
2189
+ },
2190
+ };
2191
+ const text = `${JSON.stringify(entry, null, 4)}\n`;
2192
+ // What keeps the pull request closed, first to last: the drop-in itself, then what is still to fill in.
2193
+ const blocked =
2194
+ data.problems.length > 0
2195
+ ? "Fix the problems above first."
2196
+ : !data.declaresKnown
2197
+ ? "Turn it on once, so what it declares is known, then look again."
2198
+ : (Object.values(wrong).find((each) => each !== null) ?? null);
2199
+ const filled = data.newEntryPage && `${data.newEntryPage}&value=${encodeURIComponent(text)}`;
2200
+ const link = filled && filled.length <= LINK_LIMIT ? filled : data.newEntryPage;
2201
+
2202
+ return html`<${Sheet} title=${`Share ${shareName}`} onClose=${closeSheet} wide=${true} className="gallery">
2203
+ <p class="muted small">
2204
+ To share it, add its entry to the gallery's index with a pull request. Pi Pocket makes no GitHub calls: you put its files on GitHub and open the pull request yourself.
2205
+ </p>
2206
+ ${
2207
+ data.problems.length > 0
2208
+ ? html`<div class="gallery-warn small" role="alert">
2209
+ <strong>Fix these first:</strong>
2210
+ <ul>
2211
+ ${data.problems.map((each, index) => html`<li key=${index}>${each}</li>`)}
2212
+ </ul>
2213
+ </div>`
2214
+ : html`<p class="ok small">
2215
+ <${Icon} name="check" size=${14} /> It stands on its own.
2216
+ </p>`
2217
+ }
2218
+ ${
2219
+ data.notes.length > 0 &&
2220
+ html`<ul class="muted small gallery-notes">
2221
+ ${data.notes.map((each, index) => html`<li key=${index}>${each}</li>`)}
2222
+ </ul>`
2223
+ }
2224
+ <div class="group">
2225
+ <div class="group-title">1. Put its files on GitHub</div>
2226
+ <p class="small">
2227
+ Make a public GitHub repository, and commit these files to it with the same names, at its top or in one folder:
2228
+ </p>
2229
+ <div class="sheet-list gallery-files">
2230
+ ${data.entry.files.map(
2231
+ (each) => html`<div class="gallery-file" key=${each.name}>
2232
+ <span class="mono">${each.name}</span>
2233
+ <span class="muted small">${formatBytes(each.size)}</span>
2234
+ </div>`,
2235
+ )}
2236
+ </div>
2237
+ </div>
2238
+ <div class="group">
2239
+ <div class="group-title">2. Say where they are</div>
2240
+ <div class="gallery-form">
2241
+ <${Field}
2242
+ id="share-repo"
2243
+ label="Repository"
2244
+ placeholder="owner/name"
2245
+ value=${form.repo}
2246
+ onInput=${set("repo")}
2247
+ problem=${wrong.repo}
2248
+ />
2249
+ <${Field}
2250
+ id="share-commit"
2251
+ label="Commit"
2252
+ hint="The full ID of the commit with these files (git rev-parse HEAD)."
2253
+ placeholder="40 letters and digits"
2254
+ value=${form.commit}
2255
+ onInput=${set("commit")}
2256
+ problem=${wrong.commit}
2257
+ />
2258
+ <${Field}
2259
+ id="share-path"
2260
+ label="Folder (optional)"
2261
+ hint="Only when the files are not at the top of the repository."
2262
+ placeholder=${theme ? "theme" : "extension"}
2263
+ value=${form.path}
2264
+ onInput=${set("path")}
2265
+ problem=${wrong.path}
2266
+ />
2267
+ <${Field}
2268
+ id="share-tags"
2269
+ label="Tags"
2270
+ hint=${`A few words people search for, such as ${theme ? "dark, calm" : "usage, time"}.`}
2271
+ placeholder=${theme ? "dark, minimal" : "usage, limits"}
2272
+ value=${form.tags}
2273
+ onInput=${set("tags")}
2274
+ problem=${wrong.tags}
2275
+ />
2276
+ <${Field}
2277
+ id="share-name"
2278
+ label="Your name"
2279
+ value=${form.name ?? data.entry.author.name}
2280
+ onInput=${set("name")}
2281
+ problem=${wrong.name}
2282
+ mono=${false}
2283
+ />
2284
+ <${Field}
2285
+ id="share-github"
2286
+ label="Your GitHub name (optional)"
2287
+ placeholder="octocat"
2288
+ value=${form.github}
2289
+ onInput=${set("github")}
2290
+ problem=${wrong.github}
2291
+ />
2292
+ </div>
2293
+ </div>
2294
+ <div class="group">
2295
+ <div class="gallery-entry-head">
2296
+ <div class="group-title">
2297
+ 3. Its entry, <span class="mono">entries/${data.name}.json</span>
2298
+ </div>
2299
+ <button
2300
+ class="button small"
2301
+ onClick=${() =>
2302
+ attempt(() => copyText(text).then(() => notify("info", "Entry copied.")))}
2303
+ >
2304
+ <${Icon} name="copy" size=${14} /> Copy
2305
+ </button>
2306
+ </div>
2307
+ <${Highlighted} class="gallery-code" text=${text} lang="json" />
2308
+ </div>
2309
+ <div class="gallery-actions">
2310
+ ${
2311
+ link &&
2312
+ (blocked === null
2313
+ ? html`<${Out} class="button primary" href=${link}>
2314
+ Open a pull request <${Icon} name="external" size=${14} />
2315
+ <//>`
2316
+ : html`<button class="button primary" disabled=${true}>Open a pull request</button>`)
2317
+ }
2318
+ ${
2319
+ data.contributingUrl &&
2320
+ html`<${Out} class="button" href=${data.contributingUrl}>
2321
+ How to submit <${Icon} name="external" size=${14} />
2322
+ <//>`
2323
+ }
2324
+ </div>
2325
+ ${blocked !== null && link && html`<p class="muted small">${blocked}</p>`}
2326
+ ${
2327
+ blocked === null &&
2328
+ link !== filled &&
2329
+ html`<p class="muted small">
2330
+ Its entry is too long for the link: copy it, and paste it on GitHub's page.
2331
+ </p>`
2332
+ }
2333
+ ${
2334
+ !data.repoUrl &&
2335
+ html`<p class="muted small">
2336
+ This index does not say where to submit: ask whoever keeps it.
2337
+ </p>`
2338
+ }
2339
+ <//>`;
2340
+ }