verso-cms 0.0.0-stage → 0.1.3

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 +168 -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 +1195 -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,574 @@
1
+ // Channels: the posts in each channel the site declares in verso.json, newest
2
+ // first. Search them, show only drafts or only live ones, open one to edit it,
3
+ // or start a new one by typing its title. Duplicate, draft and delete are on
4
+ // every row.
5
+
6
+ let verso;
7
+ let state = { channels: [], problems: [] };
8
+ let current = null; // the channel's key
9
+ let filter = 'all'; // all | draft | live
10
+ let query = '';
11
+ let composing = false;
12
+ let confirming = null; // the url of the post waiting for "Delete?"
13
+ let returnFocus = null;
14
+ let setup = null; // { edit: false } to make a channel, { edit: true, key } to change one
15
+ let forgetting = false;
16
+
17
+ const SVG_CHANNELS = '<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><rect x="4" y="4" width="16" height="4.5" rx="1.2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M4 13h16M4 18h11" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';
18
+ const SVG_PLUS = '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/></svg>';
19
+ const SVG_SEARCH = '<svg width="16" height="16" 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>';
20
+ const SVG_COPY = '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><rect x="8" y="8" width="12" height="12" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
21
+ const SVG_HIDE = '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12s3.5-6 9-6 9 6 9 6-3.5 6-9 6-9-6-9-6Z" fill="none" stroke="currentColor" stroke-width="2"/><path d="M4 4l16 16" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';
22
+ const SVG_SHOW = '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12s3.5-6 9-6 9 6 9 6-3.5 6-9 6-9-6-9-6Z" fill="none" stroke="currentColor" stroke-width="2"/><circle cx="12" cy="12" r="2.6" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
23
+ const SVG_BIN = '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 7h14M10 7V5h4v2M7 7l1 12h8l1-12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
24
+
25
+ const KEY = 'verso-channel';
26
+
27
+ export function init(v) {
28
+ verso = v;
29
+ const { data } = verso;
30
+ const channels = data.channels || [];
31
+ // Always there, so the first channel can be made here too.
32
+ verso.addBarButton({ id: 'channels', title: 'Channels', svg: SVG_CHANNELS, onClick: toggle });
33
+ // The palette only: one pair per channel, so the page menu stays short.
34
+ verso.paletteItems = verso.paletteItems || [];
35
+ verso.paletteItems.push({ label: 'Make a channel', run: () => open(null, { setupNew: true }) });
36
+ channels.forEach((c) => {
37
+ verso.paletteItems.push({ label: `New ${c.item} in ${c.label}`, run: () => open(c.key, { compose: true }) });
38
+ verso.paletteItems.push({ label: `Open a ${c.item} in ${c.label}…`, run: () => open(c.key) });
39
+ });
40
+ document.addEventListener('keydown', onEscape);
41
+ }
42
+
43
+ // ════ The panel ════
44
+
45
+ function panel() {
46
+ const { root, ui } = verso;
47
+ let el = root.getElementById('channels-panel');
48
+ if (!el) {
49
+ el = document.createElement('section');
50
+ el.id = 'channels-panel';
51
+ el.setAttribute('role', 'dialog');
52
+ el.setAttribute('aria-label', 'Channels');
53
+ el.className = ui("fixed top:d3 bottom:c3 left:half translate:(-50%_0) w:toolbar col bg-color:paper bd:round-d5 shadow:float bd:width-px:solid:line z:4 font:ui:small text:ink overflow:hidden");
54
+ el.style.display = 'none';
55
+ root.querySelector('.-verso')?.appendChild(el) || root.appendChild(el);
56
+ }
57
+ return el;
58
+ }
59
+
60
+ const isOpen = () => panel().style.display !== 'none';
61
+ function toggle() { if (isOpen()) close(); else open(); }
62
+
63
+ function close() {
64
+ panel().style.display = 'none';
65
+ composing = false;
66
+ confirming = null;
67
+ setup = null;
68
+ forgetting = false;
69
+ returnFocus?.focus?.();
70
+ }
71
+
72
+ async function open(key, { compose = false, setupNew = false } = {}) {
73
+ returnFocus = verso.root.activeElement || document.activeElement;
74
+ const el = panel();
75
+ el.style.display = 'flex';
76
+ let remembered = null;
77
+ try { remembered = sessionStorage.getItem(KEY); } catch {}
78
+ current = key || current || verso.data.channel || remembered;
79
+ composing = compose;
80
+ confirming = null;
81
+ forgetting = false;
82
+ setup = setupNew ? { edit: false } : null;
83
+ await load();
84
+ if (!state.channels.length && !state.problems.length) setup = { edit: false };
85
+ render();
86
+ focusFirst();
87
+ }
88
+
89
+ function focusFirst() {
90
+ const el = panel();
91
+ (setup ? el.querySelector('[data-setup-label]') : composing ? el.querySelector('[data-title]') : el.querySelector('[data-search]'))?.focus();
92
+ }
93
+
94
+ async function load() {
95
+ try {
96
+ const out = await (await fetch('/__verso/channels')).json();
97
+ if (!out.ok) throw new Error(out.message);
98
+ state = out;
99
+ } catch {
100
+ verso.toast('The channels couldn\'t load. Is Verso still running?', 'error');
101
+ return;
102
+ }
103
+ if (!state.channels.some((c) => c.key === current)) current = state.channels[0]?.key || null;
104
+ try { if (current) sessionStorage.setItem(KEY, current); } catch {}
105
+ render();
106
+ }
107
+
108
+ const channel = () => state.channels.find((c) => c.key === current);
109
+
110
+ function formatDate(iso) {
111
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso || '');
112
+ if (!m) return '';
113
+ const d = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));
114
+ try {
115
+ return d.toLocaleDateString(verso.data.locale || undefined, { year: 'numeric', month: 'short', day: 'numeric' });
116
+ } catch {
117
+ return iso;
118
+ }
119
+ }
120
+
121
+ function visible(c) {
122
+ const q = query.trim().toLowerCase();
123
+ return c.entries.filter((e) => {
124
+ if (filter === 'draft' && !e.draft) return false;
125
+ if (filter === 'live' && e.draft) return false;
126
+ if (!q) return true;
127
+ return [e.label, e.title, e.url, e.description].some((t) => (t || '').toLowerCase().includes(q));
128
+ });
129
+ }
130
+
131
+ function render() {
132
+ const { ui, esc, icon } = verso;
133
+ const el = panel();
134
+ const c = channel();
135
+ const drafts = c ? c.entries.filter((e) => e.draft).length : 0;
136
+ const shown = c ? visible(c) : [];
137
+
138
+ el.innerHTML = `
139
+ <header class="${ui("row:y-center:x-between gap:d4 pd:d5 pd-b:d4 child:no-shrink")}">
140
+ <div class="${ui("col gap:d0 min-w:0")}">
141
+ <h2 class="${ui("font:h6:semibold text:ink")}">Channels</h2>
142
+ <p class="${ui("font:tiny text:mist")}">Posts in each channel, newest first. Open one to edit it on the page.</p>
143
+ </div>
144
+ <button data-make aria-expanded="${!!(setup && !setup.edit)}" class="${ui("row:y-center gap:d1 h:d9 pd-l:d2 pd-r:d3 bd:width-px:solid:line bd:round-pill bg-color:paper text:ink font:tiny:semibold cursor:pointer child:no-shrink @hover:[bd:mist] @focus-visible:[outline:d0:solid:proof] transition:fast")}">${SVG_PLUS}<span>Make a channel</span></button>
145
+ <button data-close class="${ui("bg-color:transparent bd:width-0 cursor:pointer row:x-center:y-center w:d9 h:d9 bd:round-full text:ink child:no-shrink @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}" aria-label="Close channels">${icon('close')}</button>
146
+ </header>
147
+
148
+ ${state.problems.length ? `<div class="${ui("col gap:d2 mg-x:d5 mg-b:d3")}">${state.problems.map((p) => `<p class="${ui("pd:d3:d4 bd:round-d3 bg-color:proof-soft font:small:normal text:proof-2")}">${esc(p)}</p>`).join('')}</div>` : ''}
149
+
150
+ ${state.channels.length > 1 ? `
151
+ <div role="tablist" aria-label="Channel" class="${ui("row gap:d1 pd-x:d5 pd-b:d3 overflow-x:auto child:no-shrink")}">
152
+ ${state.channels.map((ch) => `
153
+ <button role="tab" data-channel="${esc(ch.key)}" aria-selected="${ch.key === current}" class="${ch.key === current ? ui("row:y-center gap:d2 h:d9 pd-x:d4 bd:round-pill bd:width-0 bg-color:ink text:paper font:small:semibold cursor:pointer child:no-shrink @focus-visible:[outline:d0:solid:proof] transition:fast") : ui("row:y-center gap:d2 h:d9 pd-x:d4 bd:round-pill bd:width-0 bg-color:paper-2 text:ink font:small:medium cursor:pointer child:no-shrink @hover:[bg-color:line] @focus-visible:[outline:d0:solid:proof] transition:fast")}">
154
+ ${esc(ch.label)}<span class="${ui("font:tiny opacity:0.6")}">${ch.entries.length}</span>
155
+ </button>`).join('')}
156
+ </div>` : ''}
157
+
158
+ ${setup ? setupForm(c) : c ? `
159
+ <div class="${ui("row:y-center:x-between:wrap gap:d2 pd-x:d5 pd-b:d3 font:tiny text:mist child:no-shrink")}">
160
+ <span>${state.hasAddress ? `Feed at <span class="${ui("font:mono:tiny text:ink-3")}">${esc(c.url)}feed.xml</span>` : `A feed is made at <span class="${ui("font:mono:tiny text:ink-3")}">${esc(c.url)}feed.xml</span> once the site has an address in Site settings.`}</span>
161
+ ${forgetting ? `
162
+ <span class="${ui("row:y-center gap:d2")}">
163
+ <span class="${ui("font:tiny:medium text:proof-2")}">Stop listing ${esc(c.label)}? Its pages stay.</span>
164
+ <button data-forget-keep class="${ui("bg-color:transparent bd:width-0 cursor:pointer h:d8 pd-x:d3 bd:round-pill font:tiny:semibold text:ink @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}">Keep</button>
165
+ <button data-forget-confirm class="${ui("bd:width-0 cursor:pointer h:d8 pd-x:d3 bd:round-pill bg-color:proof text:paper font:tiny:semibold @hover:[bg-color:proof-2] @focus-visible:[outline:d0:solid:ink] transition:fast")}">Stop listing</button>
166
+ </span>` : `
167
+ <span class="${ui("row:y-center gap:d1")}">
168
+ <button data-edit-channel class="${ui("bg-color:transparent bd:width-0 cursor:pointer h:d8 pd-x:d3 bd:round-pill font:tiny:semibold text:ink-3 @hover:[bg-color:paper-2_text:ink] @focus-visible:[outline:d0:solid:proof] transition:fast")}">Change</button>
169
+ <button data-forget class="${ui("bg-color:transparent bd:width-0 cursor:pointer h:d8 pd-x:d3 bd:round-pill font:tiny:semibold text:ink-3 @hover:[bg-color:proof-soft_text:proof-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}">Stop listing</button>
170
+ </span>`}
171
+ </div>
172
+ <div class="${ui("col gap:d3 pd-x:d5 pd-b:d4 bd-b:width-px:solid:line child:no-shrink")}">
173
+ <div class="${ui("row:y-center gap:d2")}">
174
+ <label class="${ui("relative row:y-center child:grow min-w:0")}">
175
+ <span class="${ui("absolute left:d3 row:y-center text:mist events:none")}">${SVG_SEARCH}</span>
176
+ <input data-search type="search" value="${esc(query)}" placeholder="Search ${esc(c.label.toLowerCase())}" aria-label="Search ${esc(c.label)}" autocomplete="off" class="${ui("w:full h:d10 pd-l:d9 pd-r:d3 bd:round-pill bd:width-px:solid:line bg-color:paper font:ui:small text:ink @focus:[bd:proof_shadow:proof-focus_outline:none] transition:fast")}">
177
+ </label>
178
+ <button data-new class="${ui("row:y-center gap:d2 h:d10 pd-l:d3 pd-r:d4 bd:width-0 bd:round-pill bg-color:proof text:paper font:small:semibold cursor:pointer child:no-shrink @hover:[bg-color:proof-2] @focus-visible:[outline:d0:solid:ink] transition:fast")}" aria-expanded="${composing}">${SVG_PLUS}<span>New ${esc(c.item)}</span></button>
179
+ </div>
180
+ <div role="group" aria-label="Show" class="${ui("row:y-center gap:d1 font:tiny")}">
181
+ ${[['all', `All ${c.entries.length}`], ['draft', `Drafts ${drafts}`], ['live', `Live ${c.entries.length - drafts}`]].map(([value, text]) => `
182
+ <button data-filter="${value}" aria-pressed="${filter === value}" class="${filter === value ? ui("h:d8 pd-x:d3 bd:round-pill bd:width-px:solid:ink bg-color:paper text:ink font:tiny:semibold cursor:pointer @focus-visible:[outline:d0:solid:proof] transition:fast") : ui("h:d8 pd-x:d3 bd:round-pill bd:width-px:solid:line bg-color:paper text:ink-3 font:tiny:medium cursor:pointer @hover:[bd:mist_text:ink] @focus-visible:[outline:d0:solid:proof] transition:fast")}">${text}</button>`).join('')}
183
+ </div>
184
+ </div>
185
+
186
+ ${composing ? `
187
+ <form data-compose class="${ui("col gap:d3 mg-x:d5 mg-t:d4 pd:d4 bd:round-d4 bd:width-px:solid:proof bg-color:paper shadow:proof-ring child:no-shrink")}">
188
+ <label class="${ui("col gap:d2")}">
189
+ <span class="${ui("font:small:semibold text:ink")}">Title of the new ${esc(c.item)}</span>
190
+ <input data-title required maxlength="300" autocomplete="off" placeholder="What's it called?" class="${ui("w:full h:d11 pd-x:d3 bd:round-d3 bd:width-px:solid:line bg-color:paper font:ui:base text:ink @focus:[bd:proof_shadow:proof-focus_outline:none] transition:fast")}">
191
+ </label>
192
+ <p data-where class="${ui("font:tiny text:mist")}">It starts as a draft dated today, at <span class="${ui("font:mono:tiny text:ink-3")}">${esc(c.url)}…</span></p>
193
+ <p data-error role="alert" class="${ui("pd:d3:d4 bd:round-d3 bg-color:proof-soft font:small:normal text:proof-2")}" style="display:none"></p>
194
+ <div class="${ui("row:y-center:x-end gap:d2")}">
195
+ <button type="button" data-cancel class="${ui("bg-color:transparent bd:width-0 cursor:pointer h:d10 pd-x:d4 bd:round-pill font:small:semibold text:ink @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}">Cancel</button>
196
+ <button type="submit" data-create disabled class="${ui("bd:width-0 cursor:pointer h:d10 pd-x:d5 bd:round-pill bg-color:proof text:paper font:small:semibold @hover:[bg-color:proof-2] @focus-visible:[outline:d0:solid:ink] @disabled:[opacity:0.4_cursor:default] transition:fast")}">Create draft</button>
197
+ </div>
198
+ </form>` : ''}
199
+
200
+ <div class="${ui("col gap:d2 pd:d5 min-h:0 overflow-y:auto child:grow")}">
201
+ ${shown.length ? shown.map((e) => row(c, e)).join('') : empty(c)}
202
+ </div>` : `
203
+ <div class="${ui("col gap:d2 pd:d5")}"><p class="${ui("text:mist")}">${state.problems.length ? 'Fix the problem above, or stop listing that channel, and it will appear here.' : 'This site has no channels yet. Make one with Make a channel.'}</p></div>`}`;
204
+
205
+ wire(el, c);
206
+ }
207
+
208
+ // Make a channel, or change one: its folder, its name, what one item is
209
+ // called, and the page type new items use.
210
+ function setupForm(c) {
211
+ const { ui, esc } = verso;
212
+ const edit = setup.edit ? state.channels.find((ch) => ch.key === setup.key) : null;
213
+ const listed = new Set(state.channels.map((ch) => ch.key));
214
+ const folders = (state.folders || []).filter((f) => !listed.has(f));
215
+ const templates = state.templates || [];
216
+ const select = ui("w:full h:d11 pd-x:d3 bd:round-d3 bd:width-px:solid:line bg-color:paper font:ui:small text:ink cursor:pointer @focus:[bd:proof_shadow:proof-focus_outline:none] transition:fast");
217
+ const input = ui("w:full h:d11 pd-x:d3 bd:round-d3 bd:width-px:solid:line bg-color:paper font:ui:small text:ink @focus:[bd:proof_shadow:proof-focus_outline:none] transition:fast");
218
+ const label = (text) => `<span class="${ui("font:small:medium text:ink")}">${text}</span>`;
219
+ const note = (name) => `<span data-note="${name}" role="alert" class="${ui("font:tiny:medium text:proof-2")}" style="display:none"></span>`;
220
+ const options = (list, chosen) => list.map((t) => `<option value="${esc(t.name)}" ${t.name === chosen ? 'selected' : ''}>${esc(t.label)}</option>`).join('');
221
+ const base = templates.find((t) => /post|article|entry|note/.test(t.name)) || templates[0];
222
+ return `
223
+ <form data-setup novalidate class="${ui("col gap:d4 mg-x:d5 mg-y:d3 pd:d5 bd:round-d4 bd:width-px:solid:proof bg-color:paper shadow:proof-ring overflow-y:auto")}">
224
+ <div class="${ui("col gap:d1")}">
225
+ <h3 class="${ui("font:small:semibold text:ink")}">${edit ? `Change ${esc(edit.label)}` : 'Make a channel'}</h3>
226
+ <p class="${ui("font:tiny text:mist")}">A channel is a folder that grows, like a journal, case studies or events. It gets this list, a New button, and a feed.</p>
227
+ </div>
228
+ ${edit ? `<p class="${ui("font:small text:ink-3")}">Folder <span class="${ui("font:mono:small text:ink")}">${esc(edit.url)}</span></p>` : `
229
+ <label class="${ui("col gap:d2")}">
230
+ ${label('Folder')}
231
+ <select data-setup-folder class="${select}">
232
+ ${folders.map((f) => `<option value="${esc(f)}">/${esc(f)}/</option>`).join('')}
233
+ <option value="" ${folders.length ? '' : 'selected'}>A new folder…</option>
234
+ </select>
235
+ </label>
236
+ <div data-new-folder class="${ui("col gap:d3 pd:d4 bd:round-d3 bg-color:paper-2")}" ${folders.length ? 'style="display:none"' : ''}>
237
+ <label class="${ui("col gap:d2")}">
238
+ ${label('New folder name')}
239
+ <input data-setup-newfolder autocomplete="off" maxlength="80" placeholder="case-studies" class="${input}">
240
+ <span data-setup-address class="${ui("font:tiny text:mist")}">Its address will be /…/</span>
241
+ ${note('folder')}
242
+ </label>
243
+ <label class="${ui("col gap:d2")}">
244
+ ${label('Page type for the folder\'s own page, the one that lists everything')}
245
+ <select data-setup-index class="${select}">${options(templates, templates.find((t) => /journal|list|index|home|page/.test(t.name))?.name)}</select>
246
+ </label>
247
+ </div>`}
248
+ <div class="${ui("col gap:d4 /sm/ grid:cols-2-fr:gap-d3")}">
249
+ <label class="${ui("col gap:d2")}">
250
+ ${label('Name')}
251
+ <input data-setup-label maxlength="80" autocomplete="off" value="${esc(edit?.label || '')}" placeholder="Case studies" class="${input}">
252
+ ${note('label')}
253
+ </label>
254
+ <label class="${ui("col gap:d2")}">
255
+ ${label('One item is called')}
256
+ <input data-setup-item maxlength="40" autocomplete="off" value="${esc(edit?.item || '')}" placeholder="case study" class="${input}">
257
+ </label>
258
+ </div>
259
+ <label class="${ui("col gap:d2")}">
260
+ ${label('Each new item is a page of the type')}
261
+ <select data-setup-template class="${select}">
262
+ ${edit ? options(templates, edit.template) : `${options(templates, '')}<option value="" data-new-type selected>A new type, like ${esc(base?.label || 'Post')}</option>`}
263
+ </select>
264
+ <span data-type-hint class="${ui("font:tiny text:mist")}"></span>
265
+ </label>
266
+ <p data-setup-error role="alert" class="${ui("pd:d3:d4 bd:round-d3 bg-color:proof-soft font:small:normal text:proof-2")}" style="display:none"></p>
267
+ <div class="${ui("row:y-center:x-end gap:d2")}">
268
+ ${state.channels.length ? `<button type="button" data-setup-cancel class="${ui("bg-color:transparent bd:width-0 cursor:pointer h:d10 pd-x:d4 bd:round-pill font:small:semibold text:ink @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}">Cancel</button>` : ''}
269
+ <button type="submit" data-setup-save class="${ui("bd:width-0 cursor:pointer h:d10 pd-x:d5 bd:round-pill bg-color:proof text:paper font:small:semibold @hover:[bg-color:proof-2] @focus-visible:[outline:d0:solid:ink] @disabled:[opacity:0.4_cursor:default] transition:fast")}">${edit ? 'Save' : 'Make channel'}</button>
270
+ </div>
271
+ </form>`;
272
+ }
273
+
274
+ function wireSetup(el) {
275
+ const form = el.querySelector('[data-setup]');
276
+ if (!form) return;
277
+ const folder = form.querySelector('[data-setup-folder]');
278
+ const newBox = form.querySelector('[data-new-folder]');
279
+ const newName = form.querySelector('[data-setup-newfolder]');
280
+ const address = form.querySelector('[data-setup-address]');
281
+ const labelInput = form.querySelector('[data-setup-label]');
282
+ const itemInput = form.querySelector('[data-setup-item]');
283
+ const typeSelect = form.querySelector('[data-setup-template]');
284
+ const typeHint = form.querySelector('[data-type-hint]');
285
+ const error = form.querySelector('[data-setup-error]');
286
+ const templates = state.templates || [];
287
+ const base = templates.find((t) => /post|article|entry|note/.test(t.name)) || templates[0];
288
+ const slug = (s) => s.normalize('NFKD').replace(/[̀-ͯ]/g, '').toLowerCase().replace(/&/g, ' and ').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 80);
289
+ // "case-studies" → "Case studies", the name a person would give it.
290
+ const nameFor = (f) => { const w = String(f || '').split('/').pop().replace(/[-_]+/g, ' ').trim(); return w ? w.charAt(0).toUpperCase() + w.slice(1) : ''; };
291
+ // "Case studies" → "case study": a guess at what one item is called.
292
+ const singular = (n) => { const w = n.trim().toLowerCase(); return /ies$/.test(w) ? w.replace(/ies$/, 'y') : /(ss|us)$/.test(w) ? w : w.replace(/s$/, ''); };
293
+ const titleOf = (w) => (w ? w.charAt(0).toUpperCase() + w.slice(1) : '');
294
+ let labelTouched = !!labelInput.value;
295
+ let itemTouched = !!itemInput.value;
296
+ const say = (name, text) => {
297
+ const n = form.querySelector(`[data-note="${name}"]`);
298
+ if (!n) return;
299
+ n.textContent = text || '';
300
+ n.style.display = text ? '' : 'none';
301
+ };
302
+ const typeName = () => titleOf(itemInput.value.trim() || singular(labelInput.value) || 'item');
303
+ const syncType = () => {
304
+ if (!typeHint) return;
305
+ const opt = typeSelect.selectedOptions[0];
306
+ if (opt && opt.hasAttribute('data-new-type')) {
307
+ opt.textContent = `A new type: ${typeName()}`;
308
+ typeHint.textContent = `Verso makes the page type ${typeName()} for you, as a copy of ${base?.label || 'Post'}. Change its layout later from any ${typeName().toLowerCase()}.`;
309
+ } else typeHint.textContent = '';
310
+ };
311
+ const sync = () => {
312
+ const source = folder?.value || newName?.value || '';
313
+ if (!labelTouched && !setup.edit) { labelInput.value = nameFor(source); if (labelInput.value) say('label', ''); }
314
+ if (!itemTouched && !setup.edit) itemInput.value = singular(labelInput.value);
315
+ if (address) address.textContent = `Its address will be /${slug(newName.value || labelInput.value) || '…'}/`;
316
+ syncType();
317
+ };
318
+ folder?.addEventListener('change', () => { newBox.style.display = folder.value ? 'none' : ''; error.style.display = 'none'; sync(); });
319
+ newName?.addEventListener('input', () => { say('folder', ''); sync(); });
320
+ labelInput.addEventListener('input', () => { labelTouched = !!labelInput.value; say('label', ''); error.style.display = 'none'; sync(); });
321
+ itemInput.addEventListener('input', () => { itemTouched = !!itemInput.value; syncType(); });
322
+ typeSelect.addEventListener('change', syncType);
323
+ sync();
324
+ form.querySelector('[data-setup-cancel]')?.addEventListener('click', () => { setup = null; render(); });
325
+ form.addEventListener('submit', async (e) => {
326
+ e.preventDefault();
327
+ // Say what's missing beside the field, in words.
328
+ const making = !setup.edit && !folder?.value;
329
+ let missing = false;
330
+ if (making && !slug(newName?.value || labelInput.value)) { say('folder', 'Name the new folder, like case-studies.'); missing = true; }
331
+ if (!labelInput.value.trim()) { say('label', 'Give the channel a name, like Case studies.'); missing = true; }
332
+ if (missing) { [...form.querySelectorAll('[data-note]')].find((n) => n.style.display !== 'none')?.closest('label')?.querySelector('input')?.focus(); return; }
333
+ const save = form.querySelector('[data-setup-save]');
334
+ save.disabled = true;
335
+ let template = typeSelect.value;
336
+ // A new page type for the items, made in the same step.
337
+ if (!setup.edit && typeSelect.selectedOptions[0]?.hasAttribute('data-new-type')) {
338
+ const made = await send('/__verso/page-types/new', { name: typeName(), from: base?.name });
339
+ if (made.ok) template = made.name;
340
+ else if (/already a page type/.test(made.message || '')) template = slug(typeName());
341
+ else { save.disabled = false; error.textContent = made.message || 'The page type couldn\'t be made.'; error.style.display = ''; return; }
342
+ }
343
+ const body = setup.edit
344
+ ? { edit: true, folder: setup.key }
345
+ : { folder: folder?.value || newName?.value || labelInput.value, indexTemplate: form.querySelector('[data-setup-index]')?.value };
346
+ const out = await send('/__verso/channels/setup', { ...body, label: labelInput.value, item: itemInput.value, template });
347
+ save.disabled = false;
348
+ if (!out.ok) {
349
+ error.textContent = out.message || 'The channel couldn\'t be saved.';
350
+ error.style.display = '';
351
+ return;
352
+ }
353
+ const word = itemInput.value.trim() || 'entry';
354
+ verso.toast(setup.edit ? 'Channel saved.' : `${labelInput.value.trim()} is a channel now. Start the first ${word} with New ${word}.`, 'ok');
355
+ current = out.key;
356
+ setup = null;
357
+ verso.refreshStatus();
358
+ await load();
359
+ focusFirst();
360
+ });
361
+ }
362
+
363
+ function empty(c) {
364
+ const { ui, esc } = verso;
365
+ const text = query.trim()
366
+ ? `No ${esc(c.item)} in ${esc(c.label)} matches “${esc(query.trim())}”.`
367
+ : filter === 'draft' ? `There are no drafts in ${esc(c.label)}.`
368
+ : filter === 'live' ? `Nothing in ${esc(c.label)} is live yet. Take a draft out of drafts with its eye button, then publish.`
369
+ : `${esc(c.label)} is empty. Start the first ${esc(c.item)} with New ${esc(c.item)}.`;
370
+ return `<p class="${ui("pd:d6 text:mist text:center")}">${text}</p>`;
371
+ }
372
+
373
+ function row(c, e) {
374
+ const { ui, esc, data } = verso;
375
+ const here = e.url === data.url;
376
+ const date = formatDate(e.date);
377
+ const btn = ui("bg-color:transparent bd:width-0 cursor:pointer row:x-center:y-center w:d10 h:d10 bd:round-d3 text:ink-3 @hover:[bg-color:paper-2_text:ink] @focus-visible:[outline:d0:solid:proof] transition:fast");
378
+ const actions = confirming === e.url ? `
379
+ <div class="${ui("row:y-center:x-end gap:d2 w:full child:no-shrink /sm/ w:auto")}">
380
+ <span class="${ui("font:small:medium text:proof-2")}">Delete this ${esc(c.item)}?</span>
381
+ <button data-keep class="${ui("bg-color:transparent bd:width-0 cursor:pointer h:d9 pd-x:d3 bd:round-pill font:small:semibold text:ink @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}">Keep</button>
382
+ <button data-confirm class="${ui("bd:width-0 cursor:pointer h:d9 pd-x:d4 bd:round-pill bg-color:proof text:paper font:small:semibold @hover:[bg-color:proof-2] @focus-visible:[outline:d0:solid:ink] transition:fast")}">Delete</button>
383
+ </div>` : `
384
+ <div class="${ui("row:y-center:x-end gap:d1 w:full child:no-shrink /sm/ w:auto")}">
385
+ <button data-duplicate class="${btn}" aria-label="Duplicate ${esc(e.label)}" title="Duplicate">${SVG_COPY}</button>
386
+ <button data-draft="${e.draft ? 'false' : 'true'}" class="${btn}" aria-label="${e.draft ? `Take ${esc(e.label)} out of drafts` : `Make ${esc(e.label)} a draft`}" title="${e.draft ? 'Take out of drafts' : 'Make a draft (unpublish)'}">${e.draft ? SVG_SHOW : SVG_HIDE}</button>
387
+ <button data-delete class="${btn}" aria-label="Delete ${esc(e.label)}" title="Delete">${SVG_BIN}</button>
388
+ </div>`;
389
+ return `
390
+ <div data-entry="${esc(e.url)}" class="${here ? ui("row:y-center:wrap gap:d1 pd:d3 pd-l:d4 bd:round-d4 bd:width-px:solid:proof bg-color:paper transition:fast /sm/ row:y-center:no-wrap gap:d3") : ui("row:y-center:wrap gap:d1 pd:d3 pd-l:d4 bd:round-d4 bd:width-px:solid:line bg-color:paper @hover:[bd:mist] transition:fast /sm/ row:y-center:no-wrap gap:d3")}">
391
+ <a href="${esc(e.url)}" class="${ui("col gap:d1 min-w:0 child:grow text:ink @focus-visible:[outline:d0:solid:proof]")}">
392
+ <span class="${ui("row:y-center gap:d2 min-w:0")}">
393
+ <span class="${ui("font:small:semibold overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(e.label)}</span>
394
+ ${e.draft ? `<span class="${ui("pd-x:d2 bd:round-pill bg-color:proof-soft text:proof-2 font:tiny:semibold child:no-shrink")}">Draft</span>` : `<span class="${ui("pd-x:d2 bd:round-pill bg-color:paper-2 text:ink-3 font:tiny:medium child:no-shrink")}">Live</span>`}
395
+ ${here ? `<span class="${ui("font:tiny text:proof-2 child:no-shrink")}">You're here</span>` : ''}
396
+ </span>
397
+ <span class="${ui("row:y-center gap:d3 min-w:0 font:tiny text:mist")}">
398
+ ${date ? `<span class="${ui("child:no-shrink")}">${esc(date)}</span>` : ''}
399
+ <span class="${ui("font:mono:tiny overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(e.url)}</span>
400
+ </span>
401
+ </a>
402
+ ${actions}
403
+ </div>`;
404
+ }
405
+
406
+ // ════ Actions ════
407
+
408
+ const send = async (path, body) => {
409
+ try {
410
+ const res = await fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
411
+ return await res.json();
412
+ } catch {
413
+ return { ok: false, message: 'Verso isn\'t running, so nothing changed. Start it again with "npm run dev".' };
414
+ }
415
+ };
416
+
417
+ function wire(el, c) {
418
+ el.querySelector('[data-close]')?.addEventListener('click', close);
419
+ el.querySelector('[data-make]')?.addEventListener('click', () => {
420
+ setup = setup && !setup.edit ? null : { edit: false };
421
+ composing = false;
422
+ render();
423
+ focusFirst();
424
+ });
425
+ wireSetup(el);
426
+ el.querySelector('[data-edit-channel]')?.addEventListener('click', () => { setup = { edit: true, key: current }; render(); focusFirst(); });
427
+ el.querySelector('[data-forget]')?.addEventListener('click', () => { forgetting = true; render(); panel().querySelector('[data-forget-keep]')?.focus(); });
428
+ el.querySelector('[data-forget-keep]')?.addEventListener('click', () => { forgetting = false; render(); });
429
+ el.querySelector('[data-forget-confirm]')?.addEventListener('click', async () => {
430
+ const out = await send('/__verso/channels/forget', { key: current });
431
+ forgetting = false;
432
+ if (!out.ok) { render(); return verso.toast(out.message, 'error'); }
433
+ verso.toast(`${out.label} isn't listed as a channel any more. Its pages are where they were.`, 'ok');
434
+ verso.refreshStatus();
435
+ current = null;
436
+ await load();
437
+ });
438
+ el.querySelectorAll('[data-channel]').forEach((b) => b.addEventListener('click', () => {
439
+ current = b.dataset.channel;
440
+ try { sessionStorage.setItem(KEY, current); } catch {}
441
+ query = '';
442
+ confirming = null;
443
+ render();
444
+ el.querySelector(`[data-channel="${CSS.escape(current)}"]`)?.focus();
445
+ }));
446
+ // Arrow keys move between channel tabs.
447
+ el.querySelector('[role="tablist"]')?.addEventListener('keydown', (e) => {
448
+ if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return;
449
+ const keys = state.channels.map((ch) => ch.key);
450
+ const i = keys.indexOf(current) + (e.key === 'ArrowRight' ? 1 : -1);
451
+ if (i < 0 || i >= keys.length) return;
452
+ el.querySelector(`[data-channel="${CSS.escape(keys[i])}"]`)?.click();
453
+ });
454
+ if (!c) return;
455
+
456
+ const search = el.querySelector('[data-search]');
457
+ search?.addEventListener('input', () => {
458
+ query = search.value;
459
+ const at = search.selectionStart;
460
+ render();
461
+ const again = panel().querySelector('[data-search]');
462
+ again.focus();
463
+ again.setSelectionRange(at, at);
464
+ });
465
+ el.querySelectorAll('[data-filter]').forEach((b) => b.addEventListener('click', () => {
466
+ filter = b.dataset.filter;
467
+ render();
468
+ panel().querySelector(`[data-filter="${filter}"]`)?.focus();
469
+ }));
470
+ el.querySelector('[data-new]')?.addEventListener('click', () => {
471
+ composing = !composing;
472
+ render();
473
+ focusFirst();
474
+ });
475
+
476
+ const form = el.querySelector('[data-compose]');
477
+ if (form) {
478
+ const title = form.querySelector('[data-title]');
479
+ const create = form.querySelector('[data-create]');
480
+ const where = form.querySelector('[data-where] span');
481
+ const error = form.querySelector('[data-error]');
482
+ const slug = (s) => s.normalize('NFKD').replace(/[̀-ͯ]/g, '').toLowerCase().replace(/&/g, ' and ').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 80);
483
+ title.addEventListener('input', () => {
484
+ const s = slug(title.value);
485
+ create.disabled = !s;
486
+ where.textContent = `${c.url}${s ? `${s}/` : '…'}`;
487
+ error.style.display = 'none';
488
+ });
489
+ form.querySelector('[data-cancel]').addEventListener('click', () => { composing = false; render(); panel().querySelector('[data-new]')?.focus(); });
490
+ form.addEventListener('submit', async (e) => {
491
+ e.preventDefault();
492
+ if (create.disabled) return;
493
+ create.disabled = true;
494
+ create.textContent = 'Creating…';
495
+ const out = await send('/__verso/channels/new', { channel: c.key, title: title.value });
496
+ if (out.ok && out.url) {
497
+ location.href = out.url;
498
+ return;
499
+ }
500
+ error.textContent = out.message || `Verso couldn't create the ${c.item}.`;
501
+ error.style.display = '';
502
+ create.disabled = false;
503
+ create.textContent = 'Create draft';
504
+ });
505
+ }
506
+
507
+ el.querySelectorAll('[data-entry]').forEach((rowEl) => {
508
+ const url = rowEl.dataset.entry;
509
+ const entry = c.entries.find((x) => x.url === url);
510
+ rowEl.querySelector('[data-duplicate]')?.addEventListener('click', async () => {
511
+ const out = await send('/__verso/channels/duplicate', { url });
512
+ if (!out.ok) return verso.toast(out.message, 'error');
513
+ verso.toast(`Made a copy of ${entry.label}, as a draft.`, 'ok');
514
+ verso.refreshStatus();
515
+ await load();
516
+ });
517
+ rowEl.querySelector('[data-draft]')?.addEventListener('click', async (e) => {
518
+ const draft = e.currentTarget.dataset.draft === 'true';
519
+ const out = await send('/__verso/draft', { url, draft });
520
+ if (!out.ok) return verso.toast(out.message || 'That couldn\'t be changed.', 'error');
521
+ verso.toast(draft ? `${entry.label} is a draft now. Publish to take it off the live site.` : `${entry.label} will be on the live site when you publish.`, 'ok');
522
+ verso.refreshStatus();
523
+ await load();
524
+ panel().querySelector(`[data-entry="${CSS.escape(url)}"] [data-draft]`)?.focus();
525
+ });
526
+ rowEl.querySelector('[data-delete]')?.addEventListener('click', () => {
527
+ confirming = url;
528
+ render();
529
+ panel().querySelector('[data-keep]')?.focus();
530
+ });
531
+ rowEl.querySelector('[data-keep]')?.addEventListener('click', () => {
532
+ confirming = null;
533
+ render();
534
+ panel().querySelector(`[data-entry="${CSS.escape(url)}"] [data-delete]`)?.focus();
535
+ });
536
+ rowEl.querySelector('[data-confirm]')?.addEventListener('click', async () => {
537
+ const out = await send('/__verso/channels/delete', { url });
538
+ confirming = null;
539
+ if (!out.ok) {
540
+ render();
541
+ return verso.toast(out.message, 'error');
542
+ }
543
+ verso.toast(`Deleted ${out.label}. If it was published before, it's still in History.`, 'ok');
544
+ verso.refreshStatus();
545
+ // If this page was the one deleted, go to the channel instead.
546
+ if (verso.data.url === url) {
547
+ location.href = c.url;
548
+ return;
549
+ }
550
+ await load();
551
+ });
552
+ });
553
+ }
554
+
555
+ // Escape steps back: the delete question, then the new-post form, then the panel.
556
+ function onEscape(e) {
557
+ if (e.key !== 'Escape' || !verso || !isOpen()) return;
558
+ if (setup && state.channels.length) {
559
+ setup = null;
560
+ render();
561
+ } else if (forgetting) {
562
+ forgetting = false;
563
+ render();
564
+ } else if (confirming) {
565
+ confirming = null;
566
+ render();
567
+ } else if (composing) {
568
+ composing = false;
569
+ render();
570
+ panel().querySelector('[data-new]')?.focus();
571
+ } else {
572
+ close();
573
+ }
574
+ }