verso-cms 0.0.0-stage → 0.1.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +288 -2
  3. package/bin/verso.js +16 -0
  4. package/editor/door.js +139 -0
  5. package/editor/editor.js +1880 -0
  6. package/editor/elevate.css +2158 -0
  7. package/editor/ext-attrs.js +87 -0
  8. package/editor/ext-blocks.js +422 -0
  9. package/editor/ext-builder.js +819 -0
  10. package/editor/ext-channels.js +574 -0
  11. package/editor/ext-components.js +160 -0
  12. package/editor/ext-history.js +242 -0
  13. package/editor/ext-palette.js +307 -0
  14. package/editor/ext-people.js +345 -0
  15. package/editor/ext-repeaters.js +143 -0
  16. package/editor/ext-screens.js +94 -0
  17. package/editor/ext-site-settings.js +318 -0
  18. package/editor/ext-site-view.js +632 -0
  19. package/editor/ext-tokens.js +1166 -0
  20. package/editor/new-page.js +252 -0
  21. package/editor/rich.js +23 -0
  22. package/package.json +69 -4
  23. package/src/blocks.js +269 -0
  24. package/src/box.js +339 -0
  25. package/src/build.js +210 -0
  26. package/src/cli.js +161 -0
  27. package/src/color.js +137 -0
  28. package/src/components.js +223 -0
  29. package/src/elevate.js +74 -0
  30. package/src/errors.js +46 -0
  31. package/src/extensions/README.md +70 -0
  32. package/src/extensions/blocks.js +294 -0
  33. package/src/extensions/builder.js +734 -0
  34. package/src/extensions/channels.js +341 -0
  35. package/src/extensions/components.js +141 -0
  36. package/src/extensions/history.js +169 -0
  37. package/src/extensions/palette.js +31 -0
  38. package/src/extensions/people.js +113 -0
  39. package/src/extensions/site-settings.js +251 -0
  40. package/src/extensions/site-view.js +381 -0
  41. package/src/extensions/tags.js +15 -0
  42. package/src/extensions/tokens.js +587 -0
  43. package/src/fonts.js +139 -0
  44. package/src/git.js +419 -0
  45. package/src/html-edit.js +942 -0
  46. package/src/images.js +116 -0
  47. package/src/people.js +286 -0
  48. package/src/rich.js +124 -0
  49. package/src/scaffold.js +185 -0
  50. package/src/screens.js +65 -0
  51. package/src/server.js +693 -0
  52. package/src/site.js +618 -0
  53. package/src/template.js +915 -0
  54. package/src/video.js +29 -0
  55. package/starter/Dockerfile +20 -0
  56. package/starter/README.md +49 -0
  57. package/starter/blocks/call-to-action.html +6 -0
  58. package/starter/blocks/features.html +15 -0
  59. package/starter/blocks/hero.html +8 -0
  60. package/starter/blocks/image-and-text.html +8 -0
  61. package/starter/blocks/latest-posts.html +20 -0
  62. package/starter/blocks/post-index.html +30 -0
  63. package/starter/blocks/quote.html +9 -0
  64. package/starter/blocks/site-footer.html +8 -0
  65. package/starter/blocks/site-nav.html +8 -0
  66. package/starter/blocks/tag-list.html +10 -0
  67. package/starter/blocks/tagged-posts.html +19 -0
  68. package/starter/blocks/team.html +15 -0
  69. package/starter/blocks/text.html +4 -0
  70. package/starter/content/404/page.json +21 -0
  71. package/starter/content/about/page.json +65 -0
  72. package/starter/content/journal/designing-for-the-morning-shift/body.html +22 -0
  73. package/starter/content/journal/designing-for-the-morning-shift/checklist.jpg +0 -0
  74. package/starter/content/journal/designing-for-the-morning-shift/cover.jpg +0 -0
  75. package/starter/content/journal/designing-for-the-morning-shift/page.json +17 -0
  76. package/starter/content/journal/page.json +19 -0
  77. package/starter/content/journal/the-first-week/body.html +17 -0
  78. package/starter/content/journal/the-first-week/cover.jpg +0 -0
  79. package/starter/content/journal/the-first-week/page.json +17 -0
  80. package/starter/content/journal/the-first-week/wall-of-cards.jpg +0 -0
  81. package/starter/content/page.json +94 -0
  82. package/starter/content/site.json +88 -0
  83. package/starter/content/studio-table.jpg +0 -0
  84. package/starter/content/topics/page.json +27 -0
  85. package/starter/dockerignore +5 -0
  86. package/starter/elevate/config/design.ts +30 -0
  87. package/starter/elevate/config/elevate.ts +16 -0
  88. package/starter/elevate/config/syntax.ts +6 -0
  89. package/starter/elevate/design/site.ts +9 -0
  90. package/starter/elevate/design/tokens.json +20 -0
  91. package/starter/elevate/extend/fonts.css +1 -0
  92. package/starter/gitignore +6 -0
  93. package/starter/netlify.toml +5 -0
  94. package/starter/parts/.gitkeep +0 -0
  95. package/starter/public/favicon.svg +1 -0
  96. package/starter/templates/page.html +20 -0
  97. package/starter/templates/page.layout.json +23 -0
  98. package/starter/templates/post.html +65 -0
  99. package/starter/verso.defaults.json +33 -0
  100. package/starter-blank/blocks/site-footer.html +3 -0
  101. package/starter-blank/blocks/site-nav.html +8 -0
  102. package/starter-blank/blocks/text.html +4 -0
  103. package/starter-blank/content/404/page.json +18 -0
  104. package/starter-blank/content/page.json +18 -0
  105. package/starter-blank/content/site.json +36 -0
  106. package/starter-blank/elevate/design/tokens.json +10 -0
  107. package/starter-blank/templates/page.html +17 -0
  108. package/starter-blank/verso.defaults.json +26 -0
@@ -0,0 +1,307 @@
1
+ // The command palette: Cmd/Ctrl+K (or "/") reaches any page, field, block or
2
+ // action from the keyboard. Results filter as you type; recent choices come
3
+ // first.
4
+
5
+ let verso;
6
+ let index = { pages: [], blocks: [], components: [] };
7
+ let items = [];
8
+ let shown = [];
9
+ let active = 0;
10
+ let returnFocus = null;
11
+
12
+ const RECENT_KEY = 'verso-palette-recent';
13
+ const recent = () => {
14
+ try { return JSON.parse(localStorage.getItem(RECENT_KEY) || '[]'); } catch { return []; }
15
+ };
16
+ const remember = (id) => {
17
+ try { localStorage.setItem(RECENT_KEY, JSON.stringify([id, ...recent().filter((r) => r !== id)].slice(0, 8))); } catch {}
18
+ };
19
+
20
+ const SEARCH = '<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><circle cx="11" cy="11" r="6.5" fill="none" stroke="currentColor" stroke-width="2"/><path d="m16 16 4 4" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';
21
+ const isMac = /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
22
+ const KEY = isMac ? '⌘K' : 'Ctrl K';
23
+
24
+ export function init(v) {
25
+ verso = v;
26
+ verso.menuItems.push({ label: 'Find a page or action', hint: KEY, icon: SEARCH, run: open });
27
+ document.addEventListener('keydown', onKey, true);
28
+ }
29
+
30
+ function editableFocused() {
31
+ let el = document.activeElement;
32
+ while (el && el.shadowRoot && el.shadowRoot.activeElement) el = el.shadowRoot.activeElement;
33
+ if (!el) return false;
34
+ return el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName);
35
+ }
36
+
37
+ function onKey(e) {
38
+ const k = e.key.toLowerCase();
39
+ if ((e.metaKey || e.ctrlKey) && k === 'k') {
40
+ e.preventDefault();
41
+ e.stopPropagation();
42
+ if (isOpen()) close(); else open();
43
+ return;
44
+ }
45
+ if (e.key === '/' && !e.metaKey && !e.ctrlKey && !e.altKey && !isOpen() && !editableFocused()) {
46
+ e.preventDefault();
47
+ open();
48
+ }
49
+ }
50
+
51
+ // ════ What can be chosen ════
52
+
53
+ function build() {
54
+ const { data, root } = verso;
55
+ const click = (id) => () => root.getElementById(id)?.click();
56
+ const list = [];
57
+ index.pages.forEach((p) => list.push({
58
+ id: `page:${p.url}`, group: 'Pages', label: p.label, detail: p.url, badge: p.draft ? 'Draft' : '',
59
+ current: p.url === data.url,
60
+ run: () => { location.href = p.url; },
61
+ }));
62
+ (data.fields || []).filter((f) => f.onPage).forEach((f) => {
63
+ const el = fieldElement(f.name);
64
+ if (!el) return;
65
+ const kind = f.type === 'rich' ? 'Rich text' : f.type === 'image' ? 'Image' : 'Text';
66
+ const block = el.closest('[data-verso-block-name]')?.dataset.versoBlockName;
67
+ const blockLabel = block && (index.blocks.find((b) => b.name === block)?.label || block.replace(/[-_]+/g, ' ').replace(/^./, (c) => c.toUpperCase()));
68
+ list.push({
69
+ id: `field:${data.url}:${f.name}`, group: 'On this page', label: f.label,
70
+ detail: blockLabel ? `${kind} in ${blockLabel}` : kind,
71
+ run: () => editField(f.name),
72
+ });
73
+ });
74
+ const actions = [
75
+ { label: 'Publish', run: click('publish') },
76
+ { label: 'Page settings', run: click('open-settings') },
77
+ { label: 'Undo', run: click('undo') },
78
+ { label: 'Redo', run: click('redo') },
79
+ { label: 'New page', run: () => { root.getElementById('page')?.click(); setTimeout(() => root.getElementById('new-page')?.click(), 0); } },
80
+ // Every tool from the page menu and the bar, once each.
81
+ ...verso.menuItems.filter((m, i, all) => m.run !== open && all.findIndex((o) => o.label === m.label) === i).map((m) => ({ label: m.label, run: m.run })),
82
+ // Actions an extension offers in the palette only, not the page menu.
83
+ ...(verso.paletteItems || []).map((m) => ({ label: m.label, run: m.run })),
84
+ ];
85
+ if (root.getElementById('open-blocks') && !actions.some((a) => a.label === 'Blocks')) actions.push({ label: 'Blocks', run: click('open-blocks') });
86
+ actions.filter((a, i) => actions.findIndex((o) => o.label === a.label) === i).forEach((a) => list.push({ id: `action:${a.label}`, group: 'Actions', label: a.label, detail: '', run: a.run }));
87
+ [...index.blocks.map((b) => ({ ...b, kind: 'Block' })), ...index.components.map((c) => ({ ...c, kind: 'Component' }))].forEach((b) => list.push({
88
+ id: `block:${b.kind}:${b.name}`, group: 'Blocks', label: b.label, detail: b.kind,
89
+ run: () => {
90
+ const open = root.getElementById('open-blocks');
91
+ if (open) open.click();
92
+ else verso.toast('This page has no place for blocks.', 'error');
93
+ },
94
+ }));
95
+ return list;
96
+ }
97
+
98
+ function fieldElement(name) {
99
+ const esc = window.CSS?.escape || ((s) => s);
100
+ return document.querySelector(`[data-verso-field="${esc(name)}"], [data-verso-rich="${esc(name)}"], [data-verso-image="${esc(name)}"]`);
101
+ }
102
+
103
+ function editField(name) {
104
+ const el = fieldElement(name);
105
+ if (!el) return verso.toast('That field isn\'t visible on this page. Look in Page settings.', 'error');
106
+ el.scrollIntoView({ block: 'center', behavior: 'smooth' });
107
+ const r = el.getBoundingClientRect();
108
+ const opts = { bubbles: true, cancelable: true, composed: true, button: 0, clientX: r.left + 4, clientY: r.top + r.height / 2 };
109
+ el.dispatchEvent(new MouseEvent('mousedown', opts));
110
+ el.dispatchEvent(new MouseEvent('mouseup', opts));
111
+ el.dispatchEvent(new MouseEvent('click', opts));
112
+ if (el.isContentEditable || el.querySelector('[contenteditable="true"]')) {
113
+ (el.isContentEditable ? el : el.querySelector('[contenteditable="true"]')).focus();
114
+ const sel = getSelection();
115
+ const range = document.createRange();
116
+ range.selectNodeContents(el);
117
+ range.collapse(false);
118
+ sel.removeAllRanges();
119
+ sel.addRange(range);
120
+ }
121
+ }
122
+
123
+ // ════ Matching ════
124
+ // Letters in order, anywhere: "jrn" finds "Journal". Starts of words and
125
+ // letters next to each other score higher.
126
+
127
+ function match(query, text) {
128
+ if (!query) return { score: 0, hits: [] };
129
+ const q = query.toLowerCase();
130
+ const t = text.toLowerCase();
131
+ const hits = [];
132
+ let score = 0;
133
+ let from = 0;
134
+ let last = -2;
135
+ for (const ch of q) {
136
+ if (ch === ' ') continue;
137
+ const at = t.indexOf(ch, from);
138
+ if (at === -1) return null;
139
+ hits.push(at);
140
+ score += 1;
141
+ if (at === last + 1) score += 3;
142
+ if (at === 0 || /[\s/\-_.(]/.test(t[at - 1])) score += 4;
143
+ last = at;
144
+ from = at + 1;
145
+ }
146
+ if (t.startsWith(q)) score += 10;
147
+ score -= (t.length - q.length) * 0.02;
148
+ return { score, hits };
149
+ }
150
+
151
+ const highlight = (text, hits) => {
152
+ const { esc } = verso;
153
+ if (!hits.length) return esc(text);
154
+ const set = new Set(hits);
155
+ return [...text].map((ch, i) => (set.has(i) ? `<mark class="${verso.ui("bg-color:transparent text:proof-2 font:semibold")}">${esc(ch)}</mark>` : esc(ch))).join('');
156
+ };
157
+
158
+ function filter(query) {
159
+ const rec = recent();
160
+ const q = query.trim();
161
+ const scored = [];
162
+ items.forEach((item) => {
163
+ // Fields on this page come up when you type, not in the opening list.
164
+ if (!q && item.group === 'On this page') return;
165
+ const m = match(q, item.label) || (q && item.detail ? match(q, item.detail) : null);
166
+ if (q && !m) return;
167
+ const onLabel = q ? match(q, item.label) : null;
168
+ const r = rec.indexOf(item.id);
169
+ scored.push({ item, score: (m ? m.score : 0) + (r === -1 ? 0 : 20 - r), hits: onLabel ? onLabel.hits : [], recent: r !== -1, rank: r });
170
+ });
171
+ if (!q) {
172
+ // No query: recent choices first, then everything in group order.
173
+ const order = ['Pages', 'Actions', 'Blocks', 'On this page'];
174
+ scored.sort((a, b) => (b.recent - a.recent) || (a.recent && b.recent ? a.rank - b.rank : 0) || order.indexOf(a.item.group) - order.indexOf(b.item.group) || (b.score - a.score));
175
+ } else {
176
+ // Groups stay together, led by the group with the best match.
177
+ const best = {};
178
+ scored.forEach((x) => { best[x.item.group] = Math.max(best[x.item.group] ?? -Infinity, x.score); });
179
+ scored.sort((a, b) => (best[b.item.group] - best[a.item.group]) || (a.item.group < b.item.group ? -1 : a.item.group > b.item.group ? 1 : 0) || (b.score - a.score));
180
+ }
181
+ return scored.slice(0, 60);
182
+ }
183
+
184
+ // ════ Interface ════
185
+
186
+ function panel() {
187
+ const { root, ui } = verso;
188
+ let el = root.getElementById('palette');
189
+ if (el) return el;
190
+ el = document.createElement('div');
191
+ el.id = 'palette';
192
+ el.className = ui("fixed top:0 left:0 w:full h:full z:6 font:ui:small text:ink");
193
+ el.style.display = 'none';
194
+ el.innerHTML = `
195
+ <div data-backdrop class="${ui("absolute top:0 left:0 w:full h:full bg-color:ink opacity:0.35")}"></div>
196
+ <div role="dialog" aria-modal="true" aria-label="Find a page or action" class="${ui("absolute top:c6 left:half translate:(-50%_0) w:toast col bg-color:paper bd:round-d5 shadow:float bd:width-px:solid:line overflow:hidden")}">
197
+ <label class="${ui("row:y-center gap:d3 pd-x:d4 h:d13 bd-b:width-px:solid:line text:mist")}">
198
+ ${SEARCH}
199
+ <input data-q type="text" autocomplete="off" spellcheck="false" placeholder="Go to a page, edit a field, run an action…" aria-label="Search" aria-controls="palette-list"
200
+ class="${ui("w:full h:full bg-color:transparent bd:width-0 font:ui:base text:ink @focus:[outline:none]")}">
201
+ <kbd class="${ui("pd:d0:d2 bd:round-d2 bd:width-px:solid:line font:ui:tiny text:mist format:no-wrap")}">Esc</kbd>
202
+ </label>
203
+ <ul id="palette-list" role="listbox" data-list class="${ui("col max-h:half-screen overflow-y:auto pd:d2")}"></ul>
204
+ <div class="${ui("row:y-center:x-between gap:d3 pd:d2:d4 bd-t:width-px:solid:line bg-color:paper-2 font:ui:tiny text:mist")}">
205
+ <span>↑ ↓ to move, Enter to choose</span><span>${KEY} anywhere</span>
206
+ </div>
207
+ </div>`;
208
+ (root.querySelector('.-verso') || root).appendChild(el);
209
+ const input = el.querySelector('[data-q]');
210
+ input.addEventListener('input', () => render(input.value));
211
+ input.addEventListener('keydown', (e) => {
212
+ if (e.key === 'ArrowDown') { e.preventDefault(); move(1); }
213
+ else if (e.key === 'ArrowUp') { e.preventDefault(); move(-1); }
214
+ else if (e.key === 'Enter') { e.preventDefault(); choose(active); }
215
+ else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); close(); }
216
+ else if (e.key === 'Tab') { e.preventDefault(); move(e.shiftKey ? -1 : 1); }
217
+ });
218
+ el.querySelector('[data-backdrop]').addEventListener('mousedown', close);
219
+ return el;
220
+ }
221
+
222
+ function render(query) {
223
+ const { ui, esc } = verso;
224
+ shown = filter(query);
225
+ active = 0;
226
+ const list = panel().querySelector('[data-list]');
227
+ if (!shown.length) {
228
+ list.innerHTML = `<li class="${ui("pd:d6:d4 text:mist text:center")}">Nothing matches “${esc(query)}”.</li>`;
229
+ return;
230
+ }
231
+ let group = null;
232
+ list.innerHTML = shown.map((s, i) => {
233
+ const heading = s.item.group !== group && !(!query.trim() && s.recent && i > 0 && shown[i - 1].recent);
234
+ const label = !query.trim() && s.recent ? 'Recent' : s.item.group;
235
+ const head = heading && label !== group ? `<li role="presentation" class="${ui("pd:d3:d3:d1 font:ui:small:medium text:mist")}">${esc(label)}</li>` : '';
236
+ group = heading ? label : group;
237
+ return `${head}<li role="option" id="palette-${i}" data-i="${i}" aria-selected="${i === 0}"
238
+ class="${i === 0 ? ui("row:y-center:x-between gap:d3 pd:d2:d3 bd:round-d3 bg-color:paper-2 cursor:pointer") : ui("row:y-center:x-between gap:d3 pd:d2:d3 bd:round-d3 cursor:pointer @hover:[bg-color:paper-2]")}">
239
+ <span class="${ui("col min-w:0")}">
240
+ <span class="${ui("font:medium text:ink overflow:hidden text-overflow:ellipsis format:no-wrap")}">${highlight(s.item.label, s.hits)}${s.item.current ? ` <span class="${ui("font:tiny text:mist")}">You're here</span>` : ''}</span>
241
+ ${s.item.detail ? `<span class="${ui("font:tiny text:mist overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(s.item.detail)}</span>` : ''}
242
+ </span>
243
+ ${s.item.badge ? `<span class="${ui("pd:d0:d2 bd:round-pill bg-color:proof-soft text:proof-2 font:tiny:semibold child:no-shrink")}">${esc(s.item.badge)}</span>` : ''}
244
+ </li>`;
245
+ }).join('');
246
+ list.querySelectorAll('[data-i]').forEach((li) => {
247
+ li.addEventListener('mousemove', () => setActive(Number(li.dataset.i)));
248
+ li.addEventListener('mousedown', (e) => { e.preventDefault(); choose(Number(li.dataset.i)); });
249
+ });
250
+ panel().querySelector('[data-q]').setAttribute('aria-activedescendant', 'palette-0');
251
+ }
252
+
253
+ function setActive(i) {
254
+ const { ui } = verso;
255
+ if (i === active) return;
256
+ const list = panel().querySelector('[data-list]');
257
+ const prev = list.querySelector(`[data-i="${active}"]`);
258
+ const next = list.querySelector(`[data-i="${i}"]`);
259
+ if (prev) { prev.className = ui("row:y-center:x-between gap:d3 pd:d2:d3 bd:round-d3 cursor:pointer @hover:[bg-color:paper-2]"); prev.setAttribute('aria-selected', 'false'); }
260
+ if (next) {
261
+ next.className = ui("row:y-center:x-between gap:d3 pd:d2:d3 bd:round-d3 bg-color:paper-2 cursor:pointer");
262
+ next.setAttribute('aria-selected', 'true');
263
+ next.scrollIntoView({ block: 'nearest' });
264
+ }
265
+ active = i;
266
+ panel().querySelector('[data-q]').setAttribute('aria-activedescendant', `palette-${i}`);
267
+ }
268
+
269
+ const move = (step) => shown.length && setActive((active + step + shown.length) % shown.length);
270
+
271
+ function choose(i) {
272
+ const s = shown[i];
273
+ if (!s) return;
274
+ remember(s.item.id);
275
+ close({ restore: false });
276
+ setTimeout(() => s.item.run(), 0);
277
+ }
278
+
279
+ const isOpen = () => !!verso?.root.getElementById('palette') && panel().style.display !== 'none';
280
+
281
+ async function open() {
282
+ returnFocus = document.activeElement;
283
+ const el = panel();
284
+ el.style.display = 'block';
285
+ const input = el.querySelector('[data-q]');
286
+ input.value = '';
287
+ items = build();
288
+ render('');
289
+ input.focus();
290
+ try {
291
+ index = await (await fetch('/__verso/palette')).json();
292
+ items = build();
293
+ render(input.value);
294
+ } catch {
295
+ // The page list from this page's data still works.
296
+ if (!index.pages.length) {
297
+ index.pages = (verso.data.pages || []).map((p) => ({ ...p, draft: false }));
298
+ items = build();
299
+ render(input.value);
300
+ }
301
+ }
302
+ }
303
+
304
+ function close({ restore = true } = {}) {
305
+ panel().style.display = 'none';
306
+ if (restore && returnFocus && document.contains(returnFocus)) returnFocus.focus?.();
307
+ }
@@ -0,0 +1,345 @@
1
+ // People, on a served site (verso serve): your account in the bar, who else
2
+ // is on this page, and for owners, who can edit the site.
3
+
4
+ const SVG = 'width="18" height="18" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';
5
+ const PEOPLE = `<svg ${SVG}><circle cx="9" cy="8" r="3.5"/><path d="M2.5 19.5c.6-3.4 3.2-5.5 6.5-5.5s5.9 2.1 6.5 5.5"/><path d="M16 4.8a3.5 3.5 0 0 1 0 6.4M18.5 14.6c1.7.8 2.8 2.5 3.1 4.9"/></svg>`;
6
+ const KEY = `<svg ${SVG}><circle cx="8" cy="15" r="4.5"/><path d="m11.2 11.8 8.3-8.3M16 7l3 3M13.5 9.5l2 2"/></svg>`;
7
+ const EXIT = `<svg ${SVG}><path d="M9.5 4.5h-3a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h3M15 8l4 4-4 4M19 12H9.5"/></svg>`;
8
+
9
+ const DAY = 24 * 60 * 60 * 1000;
10
+ const when = (iso) => {
11
+ if (!iso) return 'Hasn\'t signed in yet';
12
+ const days = Math.floor((Date.now() - Date.parse(iso)) / DAY);
13
+ if (days < 1) return 'Here today';
14
+ if (days < 2) return 'Here yesterday';
15
+ return `Last here ${new Date(iso).toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: days > 300 ? 'numeric' : undefined })}`;
16
+ };
17
+
18
+ export function init(verso) {
19
+ const { root, data, ui, toast, icon, esc, show, hide } = verso;
20
+ const me = data.me;
21
+ if (!me || window.parent !== window) return;
22
+ const owner = me.role === 'owner';
23
+ const bar = root.getElementById('bar');
24
+ const ITEM = ui("bg-color:transparent bd:width-0 cursor:pointer row:y-center gap:d2 pd:d3 bd:round-d3 text:paper font:medium @hover:[bg-color:ink-2] @focus-visible:[outline:d0:solid:proof] transition:fast");
25
+ const post = async (path, body) => {
26
+ const res = await fetch(`/__verso/people${path}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) });
27
+ return res.json().catch(() => ({ ok: false, message: 'Verso couldn\'t be reached. Try again.' }));
28
+ };
29
+
30
+ // ════ In the bar: who else is on this page, and you ════
31
+ const others = document.createElement('span');
32
+ others.className = ui("row:y-center gap:d0 pd-l:d1");
33
+ others.setAttribute('role', 'group');
34
+ others.setAttribute('aria-label', 'Also on this page');
35
+ others.hidden = true;
36
+ const account = document.createElement('button');
37
+ account.id = 'account';
38
+ account.className = ui("row:x-center:y-center w:d10 h:d10 bd:round-full bd:width-0 bg-color:ink-3 text:paper font:tiny:bold cursor:pointer child:no-shrink @hover:[bg-color:mist_text:ink] @focus-visible:[outline:d0:solid:proof] transition:fast");
39
+ account.textContent = me.initials;
40
+ account.dataset.tip = 'You and this site';
41
+ account.setAttribute('aria-label', `${me.name}: your account`);
42
+ account.setAttribute('aria-haspopup', 'menu');
43
+ account.setAttribute('aria-expanded', 'false');
44
+ bar.append(others, account);
45
+
46
+ const menu = document.createElement('div');
47
+ menu.className = ui("fixed bottom:c2 left:half translate:(-50%_0) w:menu col pd:d2 bg-color:ink bd:round-d5 shadow:float z:5");
48
+ menu.style.display = 'none';
49
+ menu.setAttribute('role', 'menu');
50
+ bar.parentNode.append(menu);
51
+ const closeMenu = () => { hide(menu); account.setAttribute('aria-expanded', 'false'); };
52
+ let elsewhere = [];
53
+ account.addEventListener('click', () => {
54
+ if (menu.style.display !== 'none') return closeMenu();
55
+ ['menu', 'publish-tip', 'changes'].forEach((id) => { const el = root.getElementById(id); if (el) hide(el); });
56
+ menu.innerHTML = `
57
+ <div class="${ui("row:y-center gap:d3 pd:d3")}">
58
+ <span class="${ui("row:x-center:y-center w:d11 h:d11 bd:round-full bg-color:ink-3 text:paper font:small:bold child:no-shrink")}" aria-hidden="true">${esc(me.initials)}</span>
59
+ <span class="${ui("col gap:d0 min-w:0")}">
60
+ <span class="${ui("font:medium text:paper overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(me.name)}</span>
61
+ <span class="${ui("font:tiny text:mist overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(me.email)} · ${owner ? 'Owner' : 'Editor'}</span>
62
+ </span>
63
+ </div>
64
+ ${elsewhere.length ? `<p class="${ui("pd-x:d3 pd-b:d2 font:tiny text:mist")}">Also editing now: ${elsewhere.map((o) => `${esc(o.name)}${o.same ? '' : ` (${esc(o.label || o.url)})`}`).join(', ')}</p>` : ''}
65
+ <span class="${ui("h:px mg-y:d1 bg-color:ink-3")}"></span>
66
+ ${owner ? `<button data-go="people" role="menuitem" class="${ITEM}">${PEOPLE}<span>People</span></button>` : ''}
67
+ <button data-go="password" role="menuitem" class="${ITEM}">${KEY}<span>Change password</span></button>
68
+ <button data-go="out" role="menuitem" class="${ITEM}">${EXIT}<span>Sign out</span></button>`;
69
+ show(menu);
70
+ account.setAttribute('aria-expanded', 'true');
71
+ menu.querySelector('button')?.focus();
72
+ });
73
+ menu.addEventListener('click', (e) => {
74
+ const go = e.target.closest('[data-go]')?.dataset.go;
75
+ if (!go) return;
76
+ closeMenu();
77
+ if (go === 'people') openPeople();
78
+ if (go === 'password') openPassword();
79
+ if (go === 'out') signOut();
80
+ });
81
+ menu.addEventListener('keydown', (e) => { if (e.key === 'Escape') { closeMenu(); account.focus(); } });
82
+ document.addEventListener('pointerdown', (e) => { if (menu.style.display !== 'none' && !e.composedPath().includes(menu) && !e.composedPath().includes(account)) closeMenu(); }, true);
83
+
84
+ // Signing out is a plain form, so it works the same as the sign-in page.
85
+ function signOut() {
86
+ const form = document.createElement('form');
87
+ form.method = 'post';
88
+ form.action = '/edit/out';
89
+ document.body.append(form);
90
+ form.submit();
91
+ }
92
+
93
+ // ════ Who else is here ════
94
+ // Every so often this tab says where it is and hears who else is about.
95
+ const FACE = ui("row:x-center:y-center w:d8 h:d8 bd:round-full bg-color:ok text:paper font:tiny:bold bd:width-d0:solid:ink child:no-shrink cursor:default");
96
+ async function hello(gone = false) {
97
+ try {
98
+ const res = await fetch('/__verso/people/here', { method: 'POST', keepalive: gone, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(gone ? { gone: true } : { url: location.pathname, label: data.label || '' }) });
99
+ if (gone || !res.ok) return;
100
+ const out = await res.json();
101
+ elsewhere = out.others || [];
102
+ const same = elsewhere.filter((o) => o.same);
103
+ others.hidden = !same.length;
104
+ others.innerHTML = same.slice(0, 3).map((o) => `<span class="${FACE}" data-tip="${esc(o.name)} is on this page too" aria-label="${esc(o.name)} is on this page too">${esc(o.initials)}</span>`).join('')
105
+ + (same.length > 3 ? `<span class="${FACE}" data-tip="${esc(same.slice(3).map((o) => o.name).join(', '))}">+${same.length - 3}</span>` : '');
106
+ } catch { /* offline for a moment: try again next time */ }
107
+ }
108
+ hello();
109
+ setInterval(() => { if (document.visibilityState === 'visible') hello(); }, 15000);
110
+ document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'visible') hello(); });
111
+ addEventListener('pagehide', () => hello(true));
112
+
113
+ // ════ Dialogs ════
114
+ const LABEL = ui("font:small:medium text:ink");
115
+ const INPUT = ui("w:full h:d11 pd-x:d3 bd:round-d3 bd:width-px:solid:line bg-color:paper font:small text:ink @focus:[bd:proof_shadow:proof-focus_outline:none] transition:fast");
116
+ const PRIMARY = ui("row:x-center:y-center gap:d2 h:d11 pd-x:d5 bd:width-0 bd:round-pill bg-color:proof text:paper font:small:semibold cursor:pointer format:no-wrap @hover:[bg-color:proof-2] @disabled:[bg-color:line_text:mist_cursor:default] @focus-visible:[outline:d0:solid:ink] transition:fast");
117
+ const QUIET = ui("row:x-center:y-center gap:d2 h:d11 pd-x:d5 bd:width-px:solid:line bd:round-pill bg-color:paper text:ink font:small:semibold cursor:pointer format:no-wrap @hover:[bd:ink-3] @focus-visible:[outline:d0:solid:proof] transition:fast");
118
+ const TEXT_BUTTON = ui("bg-color:transparent bd:width-0 pd:d2:d1 bd:round-d2 font:tiny:medium text:ink-3 cursor:pointer format:no-wrap @hover:[bg-color:paper-2_text:ink] @focus-visible:[outline:d0:solid:proof] transition:fast");
119
+ const DANGER_BUTTON = ui("bg-color:transparent bd:width-0 pd:d2:d1 bd:round-d2 font:tiny:medium text:proof-2 cursor:pointer format:no-wrap @hover:[bg-color:proof-soft] @focus-visible:[outline:d0:solid:proof] transition:fast");
120
+ const AVATAR = ui("row:x-center:y-center w:d10 h:d10 bd:round-full bg-color:paper-2 text:ink font:tiny:bold child:no-shrink");
121
+ const AVATAR_WAITING = ui("row:x-center:y-center w:d10 h:d10 bd:round-full bd:width-px:dashed:mist text:ink-3 font:tiny:bold child:no-shrink");
122
+
123
+ let dialog = null;
124
+ function closeDialog() {
125
+ dialog?.remove();
126
+ dialog = null;
127
+ account.focus();
128
+ }
129
+ function openDialog({ title, sub, width = 'narrow' }) {
130
+ dialog?.remove();
131
+ dialog = document.createElement('div');
132
+ dialog.className = ui("font:ui:small text:ink");
133
+ dialog.innerHTML = `
134
+ <div data-close class="${ui("fixed top:0 left:0 w:full h:full bg-color:ink opacity:0.55 z:6")}"></div>
135
+ <div role="dialog" aria-modal="true" aria-labelledby="people-title" class="${ui("fixed top:0 left:0 w:full h:full col:x-center:y-center pd:d3 z:7 events:none /md/ pd:d8")}">
136
+ <div class="${width === 'wide' ? ui("col w:full max-w:s4 max-h:full bg-color:paper bd:round-d5 shadow:float overflow-y:auto events:auto") : ui("col w:full max-w:s1 max-h:full bg-color:paper bd:round-d5 shadow:float overflow-y:auto events:auto")}">
137
+ <header class="${ui("row:y-start:x-between gap:d4 pd-x:d5 pd-t:d5 pd-b:d2")}">
138
+ <div class="${ui("col gap:d0")}">
139
+ <h2 id="people-title" class="${ui("font:h6:semibold text:ink")}">${esc(title)}</h2>
140
+ ${sub ? `<p class="${ui("font:small text:ink-3")}">${esc(sub)}</p>` : ''}
141
+ </div>
142
+ <button data-close aria-label="Close" class="${ui("row:x-center:y-center w:d9 h:d9 bd:width-0 bd:round-full bg-color:transparent text:ink-3 cursor:pointer child:no-shrink @hover:[bg-color:paper-2_text:ink] @focus-visible:[outline:d0:solid:proof] transition:fast")}">${icon('close')}</button>
143
+ </header>
144
+ <div data-body class="${ui("col")}"></div>
145
+ </div>
146
+ </div>`;
147
+ dialog.addEventListener('click', (e) => { if (e.target.closest('[data-close]')) closeDialog(); });
148
+ dialog.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.stopPropagation(); closeDialog(); } });
149
+ root.append(dialog);
150
+ return dialog.querySelector('[data-body]');
151
+ }
152
+ const problem = (message) => (message ? `<p role="alert" class="${ui("pd:d3:d2 bd:round-d3 bg-color:proof-soft font:small:medium text:proof-2")}">${esc(message)}</p>` : '');
153
+
154
+ // ════ Change password ════
155
+ function openPassword(error = '') {
156
+ const body = openDialog({ title: 'Change password', sub: 'Your other browsers will be signed out.' });
157
+ body.innerHTML = `
158
+ <form class="${ui("col gap:d4 pd:d5 pd-t:d3")}">
159
+ ${problem(error)}
160
+ <label class="${ui("col gap:d1")}"><span class="${LABEL}">Current password</span><input name="current" type="password" autocomplete="current-password" required class="${INPUT}"></label>
161
+ <label class="${ui("col gap:d1")}"><span class="${LABEL}">New password</span><input name="next" type="password" autocomplete="new-password" minlength="8" required class="${INPUT}"><span class="${ui("font:tiny text:ink-3")}">At least 8 characters. A few words together works well.</span></label>
162
+ <div class="${ui("row:x-end gap:d2 pd-t:d1")}"><button type="button" data-close class="${QUIET}">Cancel</button><button class="${PRIMARY}">Change password</button></div>
163
+ </form>`;
164
+ const form = body.querySelector('form');
165
+ form.current.focus();
166
+ form.addEventListener('submit', async (e) => {
167
+ e.preventDefault();
168
+ const out = await post('/password', { current: form.current.value, next: form.next.value });
169
+ if (!out.ok) return openPassword(out.message);
170
+ closeDialog();
171
+ toast('Password changed.', 'ok');
172
+ });
173
+ }
174
+
175
+ // ════ People ════
176
+ let state = null; // what the server says: people, waiting, roles, box
177
+ let made = null; // a link just made, to hand over
178
+ let asking = null; // the person being removed, while it's confirmed
179
+ let draft = { name: '', email: '', role: 'editor' };
180
+ let formError = '';
181
+
182
+ async function openPeople() {
183
+ made = null; asking = null; formError = '';
184
+ const body = openDialog({ title: 'People', sub: `Who can edit ${data.siteName || 'this site'}`, width: 'wide' });
185
+ body.innerHTML = `<p class="${ui("pd:d5 text:ink-3")}">Loading…</p>`;
186
+ await load();
187
+ }
188
+ async function load() {
189
+ const res = await fetch('/__verso/people');
190
+ state = await res.json().catch(() => null);
191
+ draw();
192
+ }
193
+
194
+ const person = (p) => {
195
+ const mine = p.id === state.me;
196
+ const confirming = asking === p.id;
197
+ const status = p.here && !mine ? `<span class="${ui("font:tiny:medium text:ok-2")}">On ${esc(p.here)} now</span>` : `<span class="${ui("font:tiny text:mist")}">${mine ? 'Signed in here' : when(p.seen)}</span>`;
198
+ return `
199
+ <li class="${ui("col gap:d1 pd-y:d3 bd-b:width-px:solid:line")}">
200
+ <div class="${ui("row:y-center gap:d3")}">
201
+ <span class="${AVATAR}" aria-hidden="true">${esc(p.initials)}</span>
202
+ <span class="${ui("col gap:d0 min-w:0 child:grow")}">
203
+ <span class="${ui("font:small:semibold text:ink overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(p.name)}${mine ? ` <span class="${ui("font:normal text:ink-3")}">(you)</span>` : ''}</span>
204
+ <span class="${ui("font:tiny text:ink-3 overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(p.email)}</span>
205
+ ${status}
206
+ </span>
207
+ ${mine
208
+ ? `<span class="${ui("font:small text:ink-3 child:no-shrink")}">${esc(state.roles[p.role].label)}</span>`
209
+ : `<select data-role="${esc(p.id)}" aria-label="${esc(p.name)}'s role" class="${ui("h:d9 pd-x:d2 bd:round-d3 bd:width-px:solid:line bg-color:paper font:small text:ink cursor:pointer child:no-shrink @focus:[bd:proof_shadow:proof-focus_outline:none]")}">${Object.entries(state.roles).map(([key, r]) => `<option value="${key}"${p.role === key ? ' selected' : ''}>${esc(r.label)}</option>`).join('')}</select>`}
210
+ </div>
211
+ ${mine ? '' : `<div class="${ui("row:y-center:x-end gap:d1")}">${confirming
212
+ ? `<span class="${ui("font:tiny:medium text:ink")}">Remove ${esc(p.name.split(' ')[0])}?</span><button data-remove="${esc(p.id)}" class="${DANGER_BUTTON}">Remove</button><button data-keep class="${TEXT_BUTTON}">Keep</button>`
213
+ : `<button data-link="${esc(p.id)}" class="${TEXT_BUTTON}">New sign-in link</button><button data-ask="${esc(p.id)}" class="${TEXT_BUTTON}">Remove</button>`}</div>`}
214
+ </li>`;
215
+ };
216
+ const waiting = (w) => `
217
+ <li class="${ui("row:y-center gap:d3 pd-y:d3 bd-b:width-px:solid:line")}">
218
+ <span class="${AVATAR_WAITING}" aria-hidden="true">${esc(w.initials)}</span>
219
+ <span class="${ui("col gap:d0 min-w:0 child:grow")}">
220
+ <span class="${ui("font:small:semibold text:ink overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(w.name)}</span>
221
+ <span class="${ui("font:tiny text:ink-3")}">Invited as ${w.role === 'owner' ? 'an owner' : 'an editor'}. Their link lasts ${w.days} more day${w.days === 1 ? '' : 's'}.</span>
222
+ </span>
223
+ <span class="${ui("row:y-center gap:d1 child:no-shrink")}"><button data-again="${esc(w.id)}" class="${TEXT_BUTTON}">New link</button><button data-cancel="${esc(w.id)}" class="${TEXT_BUTTON}">Cancel</button></span>
224
+ </li>`;
225
+
226
+ // A link just made: the one thing to do with it is send it to them.
227
+ const handover = () => {
228
+ const first = esc(made.name.split(' ')[0]);
229
+ const mail = `mailto:${encodeURIComponent(made.email)}?subject=${encodeURIComponent(made.reset ? `A new sign-in link for ${data.siteName}` : `You can edit ${data.siteName}`)}&body=${encodeURIComponent(`${made.reset ? 'Open this link to choose a new password' : `Open this link to choose a password and start editing ${data.siteName}`}:\n\n${made.link}\n\nIt works once and lasts 7 days.`)}`;
230
+ return `
231
+ <section class="${ui("col gap:d3 pd:d5 bg-color:paper-2 bd-t:width-px:solid:line")}" aria-live="polite">
232
+ <div class="${ui("col gap:d0")}">
233
+ <h3 class="${ui("font:small:semibold text:ink")}">${made.reset ? `A new sign-in link for ${first}` : `${first}'s invite is ready`}</h3>
234
+ <p class="${ui("font:small text:ink-3")}">Send ${first} this link. It works once and lasts 7 days. Verso doesn't send email itself.</p>
235
+ </div>
236
+ <input data-made readonly value="${esc(made.link)}" aria-label="The link" class="${ui("w:full h:d11 pd-x:d3 bd:round-d3 bd:width-px:solid:line bg-color:paper font:mono:tiny text:ink @focus:[bd:proof_shadow:proof-focus_outline:none]")}">
237
+ <div class="${ui("row:wrap gap:d2")}">
238
+ <button data-copy class="${PRIMARY}">Copy link</button>
239
+ <a href="${mail}" class="${QUIET}">Email it</a>
240
+ <button data-done class="${QUIET}">Done</button>
241
+ </div>
242
+ </section>`;
243
+ };
244
+ const inviteForm = () => `
245
+ <form data-invite class="${ui("col gap:d3 pd:d5 bg-color:paper-2 bd-t:width-px:solid:line")}">
246
+ <h3 class="${ui("font:small:semibold text:ink")}">Invite someone</h3>
247
+ ${problem(formError)}
248
+ <div class="${ui("grid:cols-1-fr gap:d3 /md/ grid:cols-2-fr")}">
249
+ <label class="${ui("col gap:d1")}"><span class="${LABEL}">Name</span><input name="name" autocomplete="off" required value="${esc(draft.name)}" class="${INPUT}"></label>
250
+ <label class="${ui("col gap:d1")}"><span class="${LABEL}">Email</span><input name="email" type="email" autocomplete="off" required value="${esc(draft.email)}" class="${INPUT}"></label>
251
+ </div>
252
+ <fieldset class="${ui("grid:cols-1-fr gap:d2 bd:width-0 pd:0 mg:0 /md/ grid:cols-2-fr")}">
253
+ <legend class="${ui("visually-hidden")}">What they can do</legend>
254
+ ${Object.entries(state.roles).reverse().map(([key, r]) => `
255
+ <label class="${draft.role === key ? ui("row gap:d2 pd:d3 bd:round-d3 bd:width-px:solid:proof bg-color:paper cursor:pointer") : ui("row gap:d2 pd:d3 bd:round-d3 bd:width-px:solid:line bg-color:paper cursor:pointer @hover:[bd:mist]")}">
256
+ <input type="radio" name="role" value="${key}"${draft.role === key ? ' checked' : ''} class="${ui("w:d4 h:d4 mg-t:d0 child:no-shrink cursor:pointer")}">
257
+ <span class="${ui("col gap:d0")}"><span class="${ui("font:small:semibold text:ink")}">${esc(r.label)}</span><span class="${ui("font:tiny text:ink-3")}">${esc(r.can)}</span></span>
258
+ </label>`).join('')}
259
+ </fieldset>
260
+ <div class="${ui("row:x-end")}"><button class="${PRIMARY}">Make invite link</button></div>
261
+ </form>`;
262
+ const boxNote = () => {
263
+ const b = state.box;
264
+ const since = new Date(b.since).toLocaleDateString(undefined, { day: 'numeric', month: 'long', year: 'numeric' });
265
+ return `<p class="${ui("pd:d5:d3 font:tiny text:ink-3:snug bd-t:width-px:solid:line")}">This site has been running since ${since}${b.starts > 1 ? `, and has kept its files through ${b.starts - 1} restart${b.starts === 2 ? '' : 's'}` : ''}. ${b.remote ? `Every publish is also copied to ${esc(b.remote.replace(/^https?:\/\//, '').replace(/\.git$/, ''))}.` : 'There\'s no second copy: add a git remote in the site\'s folder and every publish is copied there.'}</p>`;
266
+ };
267
+
268
+ function draw() {
269
+ const body = dialog?.querySelector('[data-body]');
270
+ if (!body) return;
271
+ if (!state?.ok) { body.innerHTML = `<div class="${ui("pd:d5")}">${problem(state?.message || 'The list couldn\'t be loaded. Close this and try again.')}</div>`; return; }
272
+ body.innerHTML = `
273
+ <ul class="${ui("col pd-x:d5 list-style-type:none")}">${state.people.map(person).join('')}${state.waiting.map(waiting).join('')}</ul>
274
+ ${made ? handover() : inviteForm()}
275
+ ${boxNote()}`;
276
+ if (made) body.querySelector('[data-made]').select();
277
+ }
278
+
279
+ root.addEventListener('change', async (e) => {
280
+ if (!dialog?.contains(e.target)) return;
281
+ const role = e.target.closest('[data-role]');
282
+ if (role) {
283
+ const out = await post('/role', { id: role.dataset.role, role: role.value });
284
+ if (!out.ok) toast(out.message, 'error'); else toast(`${out.person.name} is now ${out.person.role === 'owner' ? 'an owner' : 'an editor'}.`, 'ok');
285
+ return load();
286
+ }
287
+ const form = e.target.closest('[data-invite]');
288
+ if (form) {
289
+ draft = { name: form.name.value, email: form.email.value, role: form.role.value };
290
+ if (e.target.name === 'role') draw();
291
+ }
292
+ });
293
+ root.addEventListener('submit', async (e) => {
294
+ const form = e.target.closest('[data-invite]');
295
+ if (!form || !dialog?.contains(form)) return;
296
+ e.preventDefault();
297
+ draft = { name: form.name.value, email: form.email.value, role: form.role.value };
298
+ const out = await post('/invite', draft);
299
+ if (!out.ok) { formError = out.message; return draw(); }
300
+ formError = '';
301
+ made = out;
302
+ draft = { name: '', email: '', role: 'editor' };
303
+ await load();
304
+ });
305
+ root.addEventListener('click', async (e) => {
306
+ if (!dialog?.contains(e.target)) return;
307
+ const t = e.target.closest('button');
308
+ if (!t) return;
309
+ if (t.dataset.copy !== undefined) {
310
+ try { await navigator.clipboard.writeText(made.link); t.textContent = 'Copied'; } catch { dialog.querySelector('[data-made]').select(); toast('Press Ctrl+C or ⌘C to copy the link.', 'ok'); }
311
+ return;
312
+ }
313
+ if (t.dataset.done !== undefined) { made = null; return draw(); }
314
+ if (t.dataset.keep !== undefined) { asking = null; return draw(); }
315
+ if (t.dataset.ask) { asking = t.dataset.ask; return draw(); }
316
+ if (t.dataset.remove) {
317
+ const out = await post('/remove', { id: t.dataset.remove });
318
+ asking = null;
319
+ if (!out.ok) toast(out.message, 'error'); else toast(`${out.name} can no longer edit this site.`, 'ok');
320
+ return load();
321
+ }
322
+ if (t.dataset.link) {
323
+ const out = await post('/link', { id: t.dataset.link });
324
+ if (!out.ok) return toast(out.message, 'error');
325
+ made = { ...out, reset: true };
326
+ return draw();
327
+ }
328
+ if (t.dataset.again) {
329
+ const w = state.waiting.find((x) => x.id === t.dataset.again);
330
+ const out = await post('/invite', { name: w.name, email: w.email, role: w.role });
331
+ if (!out.ok) return toast(out.message, 'error');
332
+ made = out;
333
+ return load();
334
+ }
335
+ if (t.dataset.cancel) {
336
+ await post('/cancel', { id: t.dataset.cancel });
337
+ return load();
338
+ }
339
+ });
340
+
341
+ if (owner) {
342
+ verso.paletteItems = verso.paletteItems || [];
343
+ verso.paletteItems.push({ label: 'People: who can edit this site', run: openPeople });
344
+ }
345
+ }