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,143 @@
1
+ // Repeaters: {{ list:team }} … {{ /list }} in a template. Each item is a small
2
+ // block the page owns; this adds the obvious way to make one. An empty list's
3
+ // placeholder becomes an Add button, and a full list shows "Add to Team"
4
+ // under its last item while the pointer or focus is in it. New items are
5
+ // added at the end, and the page scrolls to them once it reloads.
6
+
7
+ const PLUS = '<svg width="14" height="14" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/></svg>';
8
+ const JUST_ADDED = 'verso-repeater-added';
9
+
10
+ export function init(verso) {
11
+ const { root, data, ui, esc, toast } = verso;
12
+ const slots = [...document.querySelectorAll('[data-verso-repeater]')];
13
+ if (!slots.length) return;
14
+
15
+ const add = async (slot) => {
16
+ const block = (slot.dataset.versoAllows || '').split(' ')[0];
17
+ await verso.flush();
18
+ const res = await fetch('/__verso/blocks/insert', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: data.url, slot: slot.dataset.versoSlot, block }) });
19
+ const out = await res.json().catch(() => ({}));
20
+ if (!out.ok) return toast(out.message || 'That item couldn\'t be added. Reload the page and try again.', 'error');
21
+ try { sessionStorage.setItem(JUST_ADDED, JSON.stringify({ url: data.url, id: out.id })); } catch { /* a convenience */ }
22
+ verso.reload();
23
+ };
24
+
25
+ // An empty list: its placeholder is a button. Clicks and keys are caught
26
+ // on the document, before anything else in the editor sees them, so the
27
+ // placeholder works wherever it ends up (inside a block, under a field's
28
+ // label, after the page changes around it).
29
+ const emptyOf = (el) => el?.closest?.('[data-verso-slot-empty]');
30
+ const slotOf = (el) => emptyOf(el)?.closest('[data-verso-repeater]');
31
+ const label = (slot) => slot.dataset.versoRepeater || 'the list';
32
+ const prepare = () => slots.forEach((slot) => {
33
+ const empty = slot.querySelector('[data-verso-slot-empty]');
34
+ if (!empty || empty.dataset.versoReady) return;
35
+ empty.dataset.versoReady = '1';
36
+ empty.setAttribute('role', 'button');
37
+ empty.setAttribute('tabindex', '0');
38
+ empty.setAttribute('aria-label', `Add the first item to ${label(slot)}`);
39
+ empty.style.cursor = 'pointer';
40
+ empty.style.position = empty.style.position || 'relative';
41
+ empty.style.touchAction = 'manipulation';
42
+ });
43
+ prepare();
44
+ let adding = false;
45
+ const addOnce = (slot) => {
46
+ if (adding || !slot) return;
47
+ adding = true;
48
+ add(slot).finally(() => { adding = false; });
49
+ };
50
+ // On the window, so this runs before the editor's own document listeners.
51
+ addEventListener('mousedown', (e) => { if (slotOf(e.target)) e.stopPropagation(); }, true);
52
+ addEventListener('click', (e) => {
53
+ const slot = slotOf(e.target);
54
+ if (!slot) return;
55
+ e.preventDefault();
56
+ e.stopPropagation();
57
+ addOnce(slot);
58
+ }, true);
59
+ addEventListener('keydown', (e) => {
60
+ const slot = slotOf(e.target);
61
+ if (!slot || (e.key !== 'Enter' && e.key !== ' ')) return;
62
+ e.preventDefault();
63
+ e.stopPropagation();
64
+ addOnce(slot);
65
+ }, true);
66
+
67
+ // A list with items: one floating button, under whichever list is in use.
68
+ const button = document.createElement('button');
69
+ button.type = 'button';
70
+ button.className = ui("fixed row:y-center gap:d1 h:d8 pd-x:d3 bd:width-0 bd:round-pill bg-color:proof text:paper font:ui:small:semibold shadow:float cursor:pointer z:3 @hover:[bg-color:proof-2] @focus-visible:[outline:d0:solid:ink] transition:fast");
71
+ button.style.display = 'none';
72
+ root.appendChild(button);
73
+ let current = null;
74
+ // An empty list gets the button on its placeholder too: the button sits in
75
+ // the editor's own layer, above anything else the editor draws, so it can
76
+ // always be clicked.
77
+ const place = () => {
78
+ if (!current) return;
79
+ const empty = current.querySelector('[data-verso-slot-empty]');
80
+ const r = (empty || current).getBoundingClientRect();
81
+ if (r.bottom < 0 || r.top > innerHeight) { button.style.display = 'none'; return; }
82
+ button.style.display = 'flex';
83
+ const w = button.offsetWidth;
84
+ const h = button.offsetHeight;
85
+ button.style.left = `${Math.max(8, Math.min(innerWidth - w - 8, r.left + r.width / 2 - w / 2))}px`;
86
+ button.style.top = empty
87
+ ? `${Math.max(8, Math.min(innerHeight - 110, r.top + r.height / 2 - h / 2))}px`
88
+ : `${Math.min(innerHeight - 110, r.bottom + 8)}px`;
89
+ };
90
+ const showFor = (slot) => {
91
+ const isEmpty = !!slot.querySelector('[data-verso-slot-empty]');
92
+ if (current !== slot || button.dataset.empty !== String(isEmpty)) {
93
+ current = slot;
94
+ button.dataset.empty = String(isEmpty);
95
+ button.innerHTML = `${PLUS}<span>${isEmpty ? `Add the first one to ${esc(label(slot))}` : `Add to ${esc(label(slot))}`}</span>`;
96
+ button.setAttribute('aria-label', isEmpty ? `Add the first item to ${label(slot)}` : `Add an item to ${label(slot)}`);
97
+ }
98
+ place();
99
+ };
100
+ const hideSoon = () => setTimeout(() => {
101
+ if (!current || touch) return;
102
+ const overSlot = current.matches(':hover') || current.contains(document.activeElement);
103
+ if (!overSlot && !button.matches(':hover') && root.activeElement !== button) { current = null; button.style.display = 'none'; }
104
+ }, 250);
105
+ slots.forEach((slot) => {
106
+ slot.addEventListener('mouseenter', () => showFor(slot));
107
+ slot.addEventListener('focusin', () => showFor(slot));
108
+ slot.addEventListener('mouseleave', hideSoon);
109
+ slot.addEventListener('focusout', hideSoon);
110
+ });
111
+ button.addEventListener('mouseleave', hideSoon);
112
+ button.addEventListener('blur', hideSoon);
113
+ button.addEventListener('click', () => addOnce(current));
114
+ // Without hover (phones and tablets), the button comes up when you tap a
115
+ // list, and goes when you tap somewhere else.
116
+ const touch = matchMedia('(hover: none)').matches;
117
+ if (touch) {
118
+ document.addEventListener('pointerdown', (e) => {
119
+ if (e.composedPath().includes(button)) return;
120
+ const slot = slots.find((sl) => sl.contains(e.target));
121
+ if (slot) showFor(slot);
122
+ else { current = null; button.style.display = 'none'; }
123
+ }, true);
124
+ }
125
+ const onScreen = () => place();
126
+ addEventListener('scroll', onScreen, { passive: true });
127
+ addEventListener('resize', onScreen);
128
+ onScreen();
129
+
130
+ // After adding: bring the new item into view and outline it for a moment.
131
+ try {
132
+ const kept = JSON.parse(sessionStorage.getItem(JUST_ADDED) || 'null');
133
+ sessionStorage.removeItem(JUST_ADDED);
134
+ if (kept && kept.url === data.url && kept.id) {
135
+ const el = document.querySelector(`[data-verso-block="${CSS.escape(kept.id)}"]`);
136
+ if (el) {
137
+ el.scrollIntoView({ block: 'center' });
138
+ const first = el.querySelector('[data-verso-field],[data-verso-rich]');
139
+ if (first) verso.flash?.(first);
140
+ }
141
+ }
142
+ } catch { /* nothing kept */ }
143
+ }
@@ -0,0 +1,94 @@
1
+ // Screen sizes: the whole page at a phone's width, a tablet's, or any of the
2
+ // site's screen sizes, still editable. The page is shown in a frame of itself
3
+ // (?verso-frame), where the editor works as usual without its bar; when the
4
+ // frame saved something, the page underneath reloads on closing.
5
+
6
+ const DEVICES = '<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"><rect x="2.5" y="4.5" width="13" height="10" rx="1.5"/><path d="M6 18.5h6" stroke-linecap="round"/><rect x="16.5" y="8.5" width="5" height="11" rx="1.2"/></svg>';
7
+
8
+ // A phone is narrower than any screen size: the starting point.
9
+ const PHONE = 390;
10
+
11
+ export function init(verso) {
12
+ const { root, ui, toast, icon, esc } = verso;
13
+ if (window.parent !== window) return; // not inside its own preview
14
+
15
+ const layer = document.createElement('div');
16
+ layer.className = ui("fixed top:0 left:0 w:full h:full col bg-color:ink z:6 font:ui:small text:paper");
17
+ layer.style.display = 'none';
18
+ layer.setAttribute('role', 'dialog');
19
+ layer.setAttribute('aria-label', 'Screen sizes');
20
+ root.appendChild(layer);
21
+
22
+ let sizes = [];
23
+ let width = PHONE;
24
+ let saved = false;
25
+
26
+ const q = (sel) => layer.querySelector(sel);
27
+
28
+ function render() {
29
+ const options = [{ name: '', label: 'Phone', px: PHONE }, ...sizes];
30
+ layer.innerHTML = `
31
+ <header class="${ui("row:y-center:x-between:wrap gap:d2 pd:d3 child:no-shrink")}">
32
+ <div class="${ui("row:y-center gap:d0 pd:d0 bd:round-pill bg-color:ink-2 max-w:full overflow-x:auto")}" role="radiogroup" aria-label="Screen size">
33
+ ${options.map((o) => `<button role="radio" data-width="${o.px}" aria-checked="${o.px === width}" title="${esc(o.label)}, ${o.px}px wide" class="${o.px === width ? ui("h:d9 pd-x:d3 bd:round-pill bd:width-0 bg-color:paper text:ink font:ui:tiny:semibold cursor:pointer format:no-wrap child:no-shrink") : ui("h:d9 pd-x:d3 bd:round-pill bd:width-0 bg-color:transparent text:mist font:ui:tiny:semibold cursor:pointer format:no-wrap child:no-shrink @hover:[text:paper]")}">${esc(o.label)}</button>`).join('')}
34
+ </div>
35
+ <div class="${ui("row:y-center gap:d3")}">
36
+ <span data-note class="${ui("font:ui:tiny text:mist")}" aria-live="polite"></span>
37
+ <button data-close class="${ui("row:y-center gap:d1 h:d9 pd-x:d4 bd:round-pill bd:width-0 bg-color:paper text:ink font:ui:small:semibold cursor:pointer @hover:[bg-color:proof-soft]")}">${icon('close')}Done</button>
38
+ </div>
39
+ </header>
40
+ <div data-stage class="${ui("relative child:grow min-h:0 overflow:hidden")}">
41
+ <iframe data-frame title="This page at another screen size" class="${ui("absolute top:0 bg-color:paper bd:round-d3")}"></iframe>
42
+ </div>`;
43
+ q('[data-close]').addEventListener('click', close);
44
+ layer.querySelectorAll('[data-width]').forEach((b) => b.addEventListener('click', () => { width = Number(b.dataset.width); render(); }));
45
+ const frame = q('[data-frame]');
46
+ frame.src = `${location.pathname}?verso-frame=1`;
47
+ fit();
48
+ }
49
+
50
+ // The frame is the real width; when the window is narrower, it's scaled.
51
+ function fit() {
52
+ const stage = q('[data-stage]');
53
+ const frame = q('[data-frame]');
54
+ if (!stage || !frame) return;
55
+ const w = stage.clientWidth - 24;
56
+ const h = stage.clientHeight;
57
+ const scale = Math.min(1, w / width);
58
+ Object.assign(frame.style, {
59
+ width: `${width}px`,
60
+ height: `${h / scale}px`,
61
+ left: `${(stage.clientWidth - width * scale) / 2}px`,
62
+ transform: scale < 1 ? `scale(${scale})` : '',
63
+ transformOrigin: 'top left',
64
+ });
65
+ const s = sizes.filter((x) => x.px <= width).pop();
66
+ q('[data-note]').textContent = `${width}px wide${scale < 1 ? `, shown at ${Math.round(scale * 100)}%` : ''}. ${s ? `Uses the ${s.label.toLowerCase()} layout.` : 'Uses the smallest layout.'} You can edit here too.`;
67
+ }
68
+
69
+ async function open() {
70
+ const out = await fetch('/__verso/tokens/screens').then((r) => r.json()).catch(() => null);
71
+ sizes = (out?.screens || []).filter((x) => x.px > PHONE);
72
+ saved = false;
73
+ layer.style.display = 'flex';
74
+ render();
75
+ }
76
+
77
+ async function close() {
78
+ layer.style.display = 'none';
79
+ layer.innerHTML = '';
80
+ if (saved) {
81
+ toast('Showing your changes…', 'ok');
82
+ await verso.flush?.();
83
+ location.reload();
84
+ }
85
+ }
86
+
87
+ window.addEventListener('message', (e) => {
88
+ if (e.origin === location.origin && e.data?.verso === 'saved') saved = true;
89
+ });
90
+ window.addEventListener('resize', () => { if (layer.style.display !== 'none') fit(); });
91
+ layer.addEventListener('keydown', (e) => { if (e.key === 'Escape') close(); });
92
+
93
+ verso.addBarButton({ id: 'open-screens', title: 'Screen sizes', svg: DEVICES, onClick: () => open() });
94
+ }
@@ -0,0 +1,318 @@
1
+ // Site settings: the site's name, address, sub-folder, language and search
2
+ // index, plus its page types. Every change is written to verso.json or
3
+ // templates/ for you; nothing here needs a code editor.
4
+
5
+ let verso;
6
+ let state = null; // { settings }
7
+ let returnFocus = null;
8
+ let composing = false; // the New page type form
9
+
10
+ const SVG_SITE = '<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="8.5" fill="none" stroke="currentColor" stroke-width="2"/><path d="M3.5 12h17M12 3.5c2.6 2.6 3.6 5.4 3.6 8.5s-1 5.9-3.6 8.5M12 3.5C9.4 6.1 8.4 8.9 8.4 12s1 5.9 3.6 8.5" fill="none" stroke="currentColor" stroke-width="1.8"/></svg>';
11
+
12
+ const LOCALES = [
13
+ ['en-US', 'English (United States)'], ['en-GB', 'English (United Kingdom)'], ['en-AU', 'English (Australia)'], ['en-CA', 'English (Canada)'],
14
+ ['fr-FR', 'French'], ['de-DE', 'German'], ['es-ES', 'Spanish'], ['es-MX', 'Spanish (Mexico)'], ['it-IT', 'Italian'],
15
+ ['pt-BR', 'Portuguese (Brazil)'], ['nl-NL', 'Dutch'], ['sv-SE', 'Swedish'], ['ja-JP', 'Japanese'], ['zh-CN', 'Chinese (Simplified)'],
16
+ ];
17
+
18
+ export function init(v) {
19
+ verso = v;
20
+ const { data } = verso;
21
+ verso.addBarButton({ id: 'site-settings', title: 'Site settings', svg: SVG_SITE, onClick: toggle });
22
+ verso.paletteItems = verso.paletteItems || [];
23
+ verso.paletteItems.push({ label: 'Site settings', run: () => open() });
24
+ verso.paletteItems.push({ label: 'New page type', run: () => open({ compose: true }) });
25
+
26
+ // Page settings: this page's type, and whether new pages of that type
27
+ // start like this one. (Kept out of the page menu, where it sat one line
28
+ // from "New page" and was easy to choose by mistake.)
29
+ if (data.template) verso.settingsSections.push({ html: typeSection, bind: bindTypeSection });
30
+ document.addEventListener('keydown', (e) => {
31
+ if (e.key !== 'Escape' || !isOpen()) return;
32
+ if (composing) { composing = false; render(); } else close();
33
+ });
34
+ }
35
+
36
+ const send = async (path, body) => {
37
+ try {
38
+ const res = await fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
39
+ return await res.json();
40
+ } catch {
41
+ return { ok: false, message: 'Verso isn\'t running, so nothing changed. Start it again with "npm run dev".' };
42
+ }
43
+ };
44
+
45
+ // "new pages", "new project pages", "new landing pages": never "Page pages".
46
+ const typeLabel = () => (verso.data.templates || []).find((t) => t.name === verso.data.template)?.label || verso.data.template;
47
+ export function newPagesOf(label) {
48
+ const l = String(label || '').trim().toLowerCase();
49
+ if (!l || l === 'page') return 'new pages';
50
+ if (l.endsWith(' page') || l.endsWith('page')) return `new ${l}s`;
51
+ return `new ${l} pages`;
52
+ }
53
+
54
+ let confirming = false;
55
+
56
+ function typeSection() {
57
+ const { ui, esc } = verso;
58
+ const label = typeLabel();
59
+ const pages = newPagesOf(label);
60
+ const has = !!verso.data.hasStarter;
61
+ const primary = ui("bd:width-0 cursor:pointer w:fit-content h:d9 pd-x:d4 bd:round-pill bg-color:ink text:paper font:small:semibold @hover:[bg-color:ink-2] @focus-visible:[outline:d0:solid:proof] transition:fast");
62
+ const quiet = ui("bg-color:transparent bd:width-px:solid:line cursor:pointer w:fit-content h:d9 pd-x:d4 bd:round-pill text:ink font:small:medium @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast");
63
+ return `
64
+ <section class="${ui("col gap:d3")}" data-type-section>
65
+ <h3 class="${ui("font:small:medium text:mist")}">Page type</h3>
66
+ <p class="${ui("font:small text:ink")}">This page's type is <strong>${esc(label)}</strong>.</p>
67
+ <p class="${ui("font:tiny text:ink-3")}">${has ? `${esc(pages[0].toUpperCase() + pages.slice(1))} start with a saved layout.` : `${esc(pages[0].toUpperCase() + pages.slice(1))} start empty.`}</p>
68
+ ${confirming ? `
69
+ <div class="${ui("col gap:d3 pd:d4 bd:round-d4 bg-color:proof-soft")}" role="group" aria-label="Replace the saved layout">
70
+ <p class="${ui("font:small text:ink")}">Replace the saved layout for ${esc(pages)} with this page's?</p>
71
+ <div class="${ui("row:wrap gap:d2")}">
72
+ <button data-starter-replace class="${primary}">Replace it</button>
73
+ <button data-starter-cancel class="${quiet}">Keep the old one</button>
74
+ </div>
75
+ </div>` : `
76
+ <div class="${ui("row:wrap gap:d2")}">
77
+ <button data-starter-save class="${primary}">${has ? `Start ${esc(pages)} like this one instead` : `Start ${esc(pages)} like this one`}</button>
78
+ ${has ? `<button data-starter-clear class="${quiet}">Start them empty</button>` : ''}
79
+ </div>`}
80
+ <p class="${ui("font:tiny text:mist")}">The layout is this page's blocks, without its words. It never changes pages that already exist.</p>
81
+ </section>`;
82
+ }
83
+
84
+ function bindTypeSection(panel) {
85
+ const q = (sel) => panel.querySelector(sel);
86
+ q('[data-starter-save]')?.addEventListener('click', () => {
87
+ if (verso.data.hasStarter) { confirming = true; verso.openSettings(); return; }
88
+ setStarter(false);
89
+ });
90
+ q('[data-starter-replace]')?.addEventListener('click', () => { confirming = false; setStarter(false); });
91
+ q('[data-starter-cancel]')?.addEventListener('click', () => { confirming = false; verso.openSettings(); });
92
+ q('[data-starter-clear]')?.addEventListener('click', () => setStarter(true));
93
+ if (confirming) setTimeout(() => verso.root.querySelector('[data-starter-replace]')?.focus(), 0);
94
+ }
95
+
96
+ const starterState = (has) => {
97
+ verso.data.hasStarter = has;
98
+ verso.data.starters = has ? [...new Set([...(verso.data.starters || []), verso.data.template])] : (verso.data.starters || []).filter((n) => n !== verso.data.template);
99
+ };
100
+
101
+ async function setStarter(clear) {
102
+ const had = !!verso.data.hasStarter;
103
+ const out = await send('/__verso/page-types/starter', { url: verso.data.url, clear });
104
+ if (!out.ok) return verso.toast(out.message || 'That couldn\'t be changed.', 'error');
105
+ starterState(!clear);
106
+ verso.openSettings();
107
+ // Undo puts back exactly what was there before: the old layout, or none.
108
+ verso.toast(out.message, 'ok', {
109
+ label: 'Undo',
110
+ run: async () => {
111
+ const back = await send('/__verso/page-types/starter', { url: verso.data.url, restore: out.previous ?? null });
112
+ if (!back.ok) return verso.toast(back.message || 'That couldn\'t be undone.', 'error');
113
+ starterState(had);
114
+ verso.openSettings();
115
+ verso.toast(back.message, 'ok');
116
+ },
117
+ });
118
+ }
119
+
120
+ // ════ The panel ════
121
+
122
+ function panel() {
123
+ const { root, ui } = verso;
124
+ let el = root.getElementById('site-settings-panel');
125
+ if (!el) {
126
+ el = document.createElement('section');
127
+ el.id = 'site-settings-panel';
128
+ el.setAttribute('role', 'dialog');
129
+ el.setAttribute('aria-label', 'Site settings');
130
+ 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");
131
+ el.style.display = 'none';
132
+ root.querySelector('.-verso')?.appendChild(el) || root.appendChild(el);
133
+ }
134
+ return el;
135
+ }
136
+
137
+ const isOpen = () => panel().style.display !== 'none';
138
+ function toggle() { if (isOpen()) close(); else open(); }
139
+ function close() {
140
+ panel().style.display = 'none';
141
+ composing = false;
142
+ returnFocus?.focus?.();
143
+ }
144
+
145
+ async function open({ compose = false } = {}) {
146
+ returnFocus = verso.root.activeElement || document.activeElement;
147
+ panel().style.display = 'flex';
148
+ composing = compose;
149
+ try {
150
+ const out = await (await fetch('/__verso/site-settings')).json();
151
+ if (!out.ok) throw new Error(out.message);
152
+ state = out;
153
+ } catch {
154
+ verso.toast('The site settings couldn\'t load. Is Verso still running?', 'error');
155
+ return;
156
+ }
157
+ render();
158
+ (composing ? panel().querySelector('[data-type-name]') : panel().querySelector('[data-set="name"]'))?.focus();
159
+ }
160
+
161
+ function render() {
162
+ const { ui, esc, icon, data } = verso;
163
+ const s = state.settings;
164
+ const templates = data.templates || [];
165
+ const starters = new Set(data.starters || []);
166
+ const el = panel();
167
+ const field = (key, label, help, attrs = '') => `
168
+ <label class="${ui("col gap:d2")}">
169
+ <span class="${ui("font:small:medium text:ink")}">${label}</span>
170
+ <input data-set="${key}" value="${esc(s[key] || '')}" autocomplete="off" ${attrs} class="${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")}">
171
+ <span class="${ui("font:tiny text:mist")}">${help}</span>
172
+ </label>`;
173
+ el.innerHTML = `
174
+ <header class="${ui("row:y-center:x-between gap:d4 pd:d5 pd-b:d4 bd-b:width-px:solid:line child:no-shrink")}">
175
+ <div class="${ui("col gap:d0 min-w:0")}">
176
+ <h2 class="${ui("font:h6:semibold text:ink")}">Site settings</h2>
177
+ <p class="${ui("font:tiny text:mist")}">For the whole site. Saved when you press Save.</p>
178
+ </div>
179
+ <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 site settings">${icon('close')}</button>
180
+ </header>
181
+ <div class="${ui("col gap:d8 pd:d5 min-h:0 overflow-y:auto child:grow")}">
182
+ <form data-settings class="${ui("col gap:d5")}">
183
+ ${field('name', 'Site name', 'Shown in page titles, and in feeds.', 'required maxlength="120"')}
184
+ ${field('url', 'Address', 'Where the site lives, like https://example.com. With it, Verso makes a sitemap and a feed for each channel.', 'inputmode="url" placeholder="https://example.com"')}
185
+ ${field('base', 'Sub-folder', 'Only if the site lives in a folder of that address, like /blog. Leave it empty otherwise.', 'placeholder="/blog"')}
186
+ <label class="${ui("col gap:d2")}">
187
+ <span class="${ui("font:small:medium text:ink")}">Language</span>
188
+ <select data-set="locale" class="${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")}">
189
+ ${(LOCALES.some(([c]) => c === s.locale) ? LOCALES : [[s.locale, s.locale], ...LOCALES]).map(([code, name]) => `<option value="${esc(code)}" ${code === s.locale ? 'selected' : ''}>${esc(name)}</option>`).join('')}
190
+ </select>
191
+ <span class="${ui("font:tiny text:mist")}">Used for dates, like ${esc(new Date(2026, 10, 17).toLocaleDateString(s.locale || 'en-US', { year: 'numeric', month: 'long', day: 'numeric' }))}.</span>
192
+ </label>
193
+ <label class="${ui("row:y-start gap:d3 pd:d4 bd:round-d4 bd:width-px:solid:line cursor:pointer @hover:[bd:mist] transition:fast")}">
194
+ <input type="checkbox" data-set="index" ${s.index ? 'checked' : ''} class="${ui("w:d5 h:d5 mg-t:d0 cursor:pointer child:no-shrink")}">
195
+ <span class="${ui("col gap:d1")}">
196
+ <span class="${ui("font:small:semibold text:ink")}">Make a search index</span>
197
+ <span class="${ui("font:tiny text:mist")}">Writes pages.json with every page's words, for a search box on the site.</span>
198
+ </span>
199
+ </label>
200
+ <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>
201
+ <div class="${ui("row:y-center:x-end gap:d2")}">
202
+ <button type="submit" data-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")}">Save</button>
203
+ </div>
204
+ </form>
205
+
206
+ <section class="${ui("col gap:d3 pd-t:d6 bd-t:width-px:solid:line")}">
207
+ <div class="${ui("row:y-center:x-between gap:d3")}">
208
+ <div class="${ui("col gap:d0 min-w:0")}">
209
+ <h3 class="${ui("font:small:semibold text:ink")}">Page types</h3>
210
+ <p class="${ui("font:tiny text:mist")}">Every page has a type, which sets its design. To give a type a starting layout, open a page of that type and use Page settings.</p>
211
+ </div>
212
+ <button data-new-type aria-expanded="${composing}" class="${ui("row:y-center gap:d2 h:d10 pd-l:d3 pd-r:d4 bd:width-0 bd:round-pill bg-color:ink text:paper font:small:semibold cursor:pointer child:no-shrink @hover:[bg-color:ink-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}">${icon('plus')}<span>New page type</span></button>
213
+ </div>
214
+ ${composing ? `
215
+ <form data-type-form class="${ui("col gap:d3 pd:d4 bd:round-d4 bd:width-px:solid:proof bg-color:paper shadow:proof-ring")}">
216
+ <div class="${ui("col gap:d3 /sm/ grid:cols-2-fr:gap-d3")}">
217
+ <label class="${ui("col gap:d2")}">
218
+ <span class="${ui("font:small:medium text:ink")}">Name</span>
219
+ <input data-type-name required maxlength="60" autocomplete="off" placeholder="Case study" class="${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")}">
220
+ </label>
221
+ <label class="${ui("col gap:d2")}">
222
+ <span class="${ui("font:small:medium text:ink")}">Start from</span>
223
+ <select data-type-from class="${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")}">
224
+ ${templates.map((t) => `<option value="${esc(t.name)}" ${t.name === data.template ? 'selected' : ''}>${esc(t.label)}</option>`).join('')}
225
+ </select>
226
+ </label>
227
+ </div>
228
+ <p class="${ui("font:tiny text:mist")}">The new type starts as a copy of that design, with its starting layout if it has one.</p>
229
+ <p data-type-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>
230
+ <div class="${ui("row:y-center:x-end gap:d2")}">
231
+ <button type="button" data-type-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>
232
+ <button type="submit" data-type-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")}">Make page type</button>
233
+ </div>
234
+ </form>` : ''}
235
+ <ul class="${ui("col gap:d1")}">
236
+ ${templates.map((t) => `
237
+ <li class="${ui("row:y-center:x-between gap:d3 h:d11 pd-x:d4 bd:round-d3 bg-color:paper-2")}">
238
+ <span class="${ui("font:small:medium text:ink")}">${esc(t.label)}${t.name === data.template ? ` <span class="${ui("font:tiny text:proof-2")}">this page</span>` : ''}</span>
239
+ <span class="${ui("font:tiny text:mist")}">${starters.has(t.name) ? 'Has a starting layout' : 'Starts empty'}</span>
240
+ </li>`).join('')}
241
+ </ul>
242
+ </section>
243
+ </div>`;
244
+ wire(el);
245
+ }
246
+
247
+ function wire(el) {
248
+ const { data } = verso;
249
+ el.querySelector('[data-close]').addEventListener('click', close);
250
+
251
+ const form = el.querySelector('[data-settings]');
252
+ const error = form.querySelector('[data-error]');
253
+ const save = form.querySelector('[data-save]');
254
+ form.querySelectorAll('[data-set]').forEach((input) => input.addEventListener('input', () => { error.style.display = 'none'; }));
255
+ form.addEventListener('submit', async (e) => {
256
+ e.preventDefault();
257
+ const get = (k) => form.querySelector(`[data-set="${k}"]`);
258
+ save.disabled = true;
259
+ save.textContent = 'Saving…';
260
+ const out = await send('/__verso/site-settings', {
261
+ name: get('name').value, url: get('url').value, base: get('base').value, locale: get('locale').value, index: get('index').checked,
262
+ });
263
+ save.disabled = false;
264
+ save.textContent = 'Save';
265
+ if (!out.ok) {
266
+ error.textContent = out.message || 'The settings couldn\'t be saved.';
267
+ error.style.display = '';
268
+ return;
269
+ }
270
+ state = out;
271
+ data.siteName = out.settings.name;
272
+ data.locale = out.settings.locale;
273
+ const renamed = out.renamed;
274
+ if (renamed) {
275
+ verso.toast(`Site settings saved. The header still says ${renamed.from}. Also change it in the header?`, 'ok', {
276
+ label: 'Change it',
277
+ run: async () => {
278
+ const done = await send('/__verso/site-settings/rename-shared', { from: renamed.from, to: renamed.to });
279
+ if (!done.ok) { verso.toast(done.message || 'The header couldn\'t be changed.', 'error'); return; }
280
+ location.reload();
281
+ },
282
+ });
283
+ } else verso.toast('Site settings saved. They go live when you publish.', 'ok');
284
+ verso.refreshStatus();
285
+ render();
286
+ });
287
+
288
+ el.querySelector('[data-new-type]').addEventListener('click', () => {
289
+ composing = !composing;
290
+ render();
291
+ panel().querySelector('[data-type-name]')?.focus();
292
+ });
293
+ const typeForm = el.querySelector('[data-type-form]');
294
+ if (!typeForm) return;
295
+ const name = typeForm.querySelector('[data-type-name]');
296
+ const create = typeForm.querySelector('[data-type-create]');
297
+ const typeError = typeForm.querySelector('[data-type-error]');
298
+ name.addEventListener('input', () => { create.disabled = !/[a-z0-9]/i.test(name.value); typeError.style.display = 'none'; });
299
+ typeForm.querySelector('[data-type-cancel]').addEventListener('click', () => { composing = false; render(); panel().querySelector('[data-new-type]')?.focus(); });
300
+ typeForm.addEventListener('submit', async (e) => {
301
+ e.preventDefault();
302
+ if (create.disabled) return;
303
+ create.disabled = true;
304
+ const out = await send('/__verso/page-types/new', { name: name.value, from: typeForm.querySelector('[data-type-from]').value });
305
+ if (!out.ok) {
306
+ typeError.textContent = out.message;
307
+ typeError.style.display = '';
308
+ create.disabled = false;
309
+ return;
310
+ }
311
+ // The new type is ready for New page right away.
312
+ data.templates = [...(data.templates || []), { name: out.name, label: out.label }].sort((a, b) => a.name.localeCompare(b.name));
313
+ if (out.starter) data.starters = [...(data.starters || []), out.name];
314
+ composing = false;
315
+ verso.toast(`Made the page type ${out.label}. Choose it under New page.`, 'ok');
316
+ render();
317
+ });
318
+ }