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.
- package/LICENSE +21 -0
- package/README.md +288 -2
- package/bin/verso.js +16 -0
- package/editor/door.js +139 -0
- package/editor/editor.js +1880 -0
- package/editor/elevate.css +2158 -0
- package/editor/ext-attrs.js +87 -0
- package/editor/ext-blocks.js +422 -0
- package/editor/ext-builder.js +819 -0
- package/editor/ext-channels.js +574 -0
- package/editor/ext-components.js +160 -0
- package/editor/ext-history.js +242 -0
- package/editor/ext-palette.js +307 -0
- package/editor/ext-people.js +345 -0
- package/editor/ext-repeaters.js +143 -0
- package/editor/ext-screens.js +94 -0
- package/editor/ext-site-settings.js +318 -0
- package/editor/ext-site-view.js +632 -0
- package/editor/ext-tokens.js +1166 -0
- package/editor/new-page.js +252 -0
- package/editor/rich.js +23 -0
- package/package.json +69 -4
- package/src/blocks.js +269 -0
- package/src/box.js +339 -0
- package/src/build.js +210 -0
- package/src/cli.js +161 -0
- package/src/color.js +137 -0
- package/src/components.js +223 -0
- package/src/elevate.js +74 -0
- package/src/errors.js +46 -0
- package/src/extensions/README.md +70 -0
- package/src/extensions/blocks.js +294 -0
- package/src/extensions/builder.js +734 -0
- package/src/extensions/channels.js +341 -0
- package/src/extensions/components.js +141 -0
- package/src/extensions/history.js +169 -0
- package/src/extensions/palette.js +31 -0
- package/src/extensions/people.js +113 -0
- package/src/extensions/site-settings.js +251 -0
- package/src/extensions/site-view.js +381 -0
- package/src/extensions/tags.js +15 -0
- package/src/extensions/tokens.js +587 -0
- package/src/fonts.js +139 -0
- package/src/git.js +419 -0
- package/src/html-edit.js +942 -0
- package/src/images.js +116 -0
- package/src/people.js +286 -0
- package/src/rich.js +124 -0
- package/src/scaffold.js +185 -0
- package/src/screens.js +65 -0
- package/src/server.js +693 -0
- package/src/site.js +618 -0
- package/src/template.js +915 -0
- package/src/video.js +29 -0
- package/starter/Dockerfile +20 -0
- package/starter/README.md +49 -0
- package/starter/blocks/call-to-action.html +6 -0
- package/starter/blocks/features.html +15 -0
- package/starter/blocks/hero.html +8 -0
- package/starter/blocks/image-and-text.html +8 -0
- package/starter/blocks/latest-posts.html +20 -0
- package/starter/blocks/post-index.html +30 -0
- package/starter/blocks/quote.html +9 -0
- package/starter/blocks/site-footer.html +8 -0
- package/starter/blocks/site-nav.html +8 -0
- package/starter/blocks/tag-list.html +10 -0
- package/starter/blocks/tagged-posts.html +19 -0
- package/starter/blocks/team.html +15 -0
- package/starter/blocks/text.html +4 -0
- package/starter/content/404/page.json +21 -0
- package/starter/content/about/page.json +65 -0
- package/starter/content/journal/designing-for-the-morning-shift/body.html +22 -0
- package/starter/content/journal/designing-for-the-morning-shift/checklist.jpg +0 -0
- package/starter/content/journal/designing-for-the-morning-shift/cover.jpg +0 -0
- package/starter/content/journal/designing-for-the-morning-shift/page.json +17 -0
- package/starter/content/journal/page.json +19 -0
- package/starter/content/journal/the-first-week/body.html +17 -0
- package/starter/content/journal/the-first-week/cover.jpg +0 -0
- package/starter/content/journal/the-first-week/page.json +17 -0
- package/starter/content/journal/the-first-week/wall-of-cards.jpg +0 -0
- package/starter/content/page.json +94 -0
- package/starter/content/site.json +88 -0
- package/starter/content/studio-table.jpg +0 -0
- package/starter/content/topics/page.json +27 -0
- package/starter/dockerignore +5 -0
- package/starter/elevate/config/design.ts +30 -0
- package/starter/elevate/config/elevate.ts +16 -0
- package/starter/elevate/config/syntax.ts +6 -0
- package/starter/elevate/design/site.ts +9 -0
- package/starter/elevate/design/tokens.json +20 -0
- package/starter/elevate/extend/fonts.css +1 -0
- package/starter/gitignore +6 -0
- package/starter/netlify.toml +5 -0
- package/starter/parts/.gitkeep +0 -0
- package/starter/public/favicon.svg +1 -0
- package/starter/templates/page.html +20 -0
- package/starter/templates/page.layout.json +23 -0
- package/starter/templates/post.html +65 -0
- package/starter/verso.defaults.json +33 -0
- package/starter-blank/blocks/site-footer.html +3 -0
- package/starter-blank/blocks/site-nav.html +8 -0
- package/starter-blank/blocks/text.html +4 -0
- package/starter-blank/content/404/page.json +18 -0
- package/starter-blank/content/page.json +18 -0
- package/starter-blank/content/site.json +36 -0
- package/starter-blank/elevate/design/tokens.json +10 -0
- package/starter-blank/templates/page.html +17 -0
- package/starter-blank/verso.defaults.json +26 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
// The site view, full screen: every page, two ways.
|
|
2
|
+
//
|
|
3
|
+
// Outline the pages as an indented list. Drag a row up or down to reorder
|
|
4
|
+
// it, or onto the middle of a row to put it inside that page.
|
|
5
|
+
// Keyboard: arrows move around, Alt+arrows move the page, Tab puts
|
|
6
|
+
// it inside the page above, Shift+Tab takes it out a level.
|
|
7
|
+
// Map the same tree drawn as a site map, top down, with previews.
|
|
8
|
+
// Drag a card beside another to reorder, onto it to put it inside.
|
|
9
|
+
//
|
|
10
|
+
// Either way, the page you pick shows on the right: its preview, title,
|
|
11
|
+
// address, type and whether it's live, with everything you can do to it.
|
|
12
|
+
// Moving a page moves its folder, so its address and the links to it follow.
|
|
13
|
+
|
|
14
|
+
let verso;
|
|
15
|
+
let tree = null;
|
|
16
|
+
let selected = null;
|
|
17
|
+
let view = 'outline';
|
|
18
|
+
let dragging = null;
|
|
19
|
+
let confirmDelete = null;
|
|
20
|
+
const collapsed = new Set();
|
|
21
|
+
// The map starts with the top level open: the shape of the site first.
|
|
22
|
+
const mapOpen = new Set(['/']);
|
|
23
|
+
let collapseDecided = false;
|
|
24
|
+
|
|
25
|
+
const SVG_TREE = '<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="3" width="6" height="5" rx="1.2" fill="none" stroke="currentColor" stroke-width="2"/><rect x="3" y="16" width="6" height="5" rx="1.2" fill="none" stroke="currentColor" stroke-width="2"/><rect x="15" y="16" width="6" height="5" rx="1.2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M12 8v4M6 16v-2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v2" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
|
|
26
|
+
const SVG_LIST = '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 6h16M8 12h12M8 18h12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';
|
|
27
|
+
const SVG_CARET = '<svg width="12" height="12" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 6 6 6-6 6" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
|
28
|
+
const SVG_HOME = '<svg width="15" height="15" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 11 12 4l8 7v8a1 1 0 0 1-1 1h-5v-6h-4v6H5a1 1 0 0 1-1-1z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>';
|
|
29
|
+
const SVG_PAGE = '<svg width="15" height="15" viewBox="0 0 24 24" aria-hidden="true"><path d="M7 3h7l5 5v12a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M14 3v5h5" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>';
|
|
30
|
+
const SVG_COPY = '<svg width="15" height="15" 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 8V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h3" fill="none" stroke="currentColor" stroke-width="2"/></svg>';
|
|
31
|
+
const SVG_OPEN = '<svg width="15" height="15" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
|
32
|
+
|
|
33
|
+
// The map's connecting lines: plain CSS, since they're drawn with ::before
|
|
34
|
+
// and ::after on each card's column.
|
|
35
|
+
const MAP_CSS = `
|
|
36
|
+
.vsv-tree{display:flex;justify-content:center;width:max-content;min-width:100%;box-sizing:border-box;padding:56px 40px 80px}
|
|
37
|
+
.vsv-node{display:flex;flex-direction:column;align-items:center;position:relative;padding:22px 10px 0}
|
|
38
|
+
.vsv-node::before,.vsv-node::after{content:'';position:absolute;top:0;right:50%;width:50%;height:22px;border-top:1.5px solid #D6D6D0}
|
|
39
|
+
.vsv-node::after{right:auto;left:50%;border-left:1.5px solid #D6D6D0}
|
|
40
|
+
.vsv-node:first-child::before,.vsv-node:last-child::after{border:0 none}
|
|
41
|
+
.vsv-node:last-child::before{border-right:1.5px solid #D6D6D0;border-radius:0 8px 0 0}
|
|
42
|
+
.vsv-node:first-child::after{border-radius:8px 0 0 0}
|
|
43
|
+
.vsv-node:only-child::before{display:none}
|
|
44
|
+
.vsv-node:only-child::after{border:0 none;border-left:1.5px solid #D6D6D0;border-radius:0}
|
|
45
|
+
.vsv-root{padding-top:0}.vsv-root::before,.vsv-root::after{display:none}
|
|
46
|
+
.vsv-kids{display:flex;position:relative;padding-top:22px}
|
|
47
|
+
.vsv-kids::before{content:'';position:absolute;top:0;left:50%;height:22px;border-left:1.5px solid #D6D6D0}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
export function init(v) {
|
|
51
|
+
verso = v;
|
|
52
|
+
const { ui, data } = verso;
|
|
53
|
+
verso.addBarButton({ id: 'site-view', title: 'Site view', svg: SVG_TREE, onClick: toggle });
|
|
54
|
+
verso.menuItems.push({ label: 'Site view', icon: SVG_TREE, run: open });
|
|
55
|
+
try { view = sessionStorage.getItem('verso-site-view-mode') === 'map' ? 'map' : 'outline'; } catch {}
|
|
56
|
+
|
|
57
|
+
// A Draft pill beside the page name, so it's never forgotten.
|
|
58
|
+
// Pressing it takes the page out of drafts.
|
|
59
|
+
if (data.draft) {
|
|
60
|
+
const pill = document.createElement('button');
|
|
61
|
+
pill.type = 'button';
|
|
62
|
+
pill.className = ui("row:y-center h:d6 pd-x:d2 bd:width-0 bd:round-pill bg-color:proof-soft text:proof-2 font:tiny:semibold format:no-wrap cursor:pointer @hover:[bg-color:proof_text:paper] transition:fast");
|
|
63
|
+
pill.textContent = 'Draft';
|
|
64
|
+
pill.title = 'Draft: this page isn\'t on the live site. Press to make it live.';
|
|
65
|
+
pill.setAttribute('aria-label', 'Draft. Make live');
|
|
66
|
+
pill.addEventListener('click', async () => {
|
|
67
|
+
try {
|
|
68
|
+
const out = await post('/__verso/draft', { url: data.url, draft: false });
|
|
69
|
+
if (!out.ok) throw new Error(out.message || 'That didn\'t work.');
|
|
70
|
+
try { sessionStorage.setItem('verso-site-view-toast', JSON.stringify({ message: `${data.label} is live. Publish to put it online.` })); } catch {}
|
|
71
|
+
location.reload();
|
|
72
|
+
} catch (err) {
|
|
73
|
+
verso.toast(err.message, 'error');
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
verso.root.getElementById('page')?.after(pill);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Keep the view open across a reload that following a moved page causes.
|
|
80
|
+
try {
|
|
81
|
+
if (sessionStorage.getItem('verso-site-view') === 'open') {
|
|
82
|
+
sessionStorage.removeItem('verso-site-view');
|
|
83
|
+
open();
|
|
84
|
+
}
|
|
85
|
+
const said = sessionStorage.getItem('verso-site-view-toast');
|
|
86
|
+
if (said) {
|
|
87
|
+
sessionStorage.removeItem('verso-site-view-toast');
|
|
88
|
+
const { message, kind } = JSON.parse(said);
|
|
89
|
+
verso.toast(message, kind);
|
|
90
|
+
}
|
|
91
|
+
} catch {}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const post = async (url, body) => {
|
|
95
|
+
try {
|
|
96
|
+
const res = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
97
|
+
return await res.json().catch(() => ({ ok: false, message: 'Verso didn\'t answer.' }));
|
|
98
|
+
} catch {
|
|
99
|
+
return { ok: false, message: 'Verso isn\'t running, so nothing changed.' };
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Said now, and again after a reload if one follows.
|
|
104
|
+
function say(message, kind = 'ok', reloading = false) {
|
|
105
|
+
verso.toast(message, kind);
|
|
106
|
+
if (!reloading) return;
|
|
107
|
+
try {
|
|
108
|
+
sessionStorage.setItem('verso-site-view-toast', JSON.stringify({ message, kind }));
|
|
109
|
+
sessionStorage.setItem('verso-site-view', 'open');
|
|
110
|
+
} catch {}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function panel() {
|
|
114
|
+
const { root, ui } = verso;
|
|
115
|
+
let el = root.getElementById('site-view-panel');
|
|
116
|
+
if (!el) {
|
|
117
|
+
el = document.createElement('section');
|
|
118
|
+
el.id = 'site-view-panel';
|
|
119
|
+
el.setAttribute('role', 'dialog');
|
|
120
|
+
el.setAttribute('aria-label', 'Site view');
|
|
121
|
+
el.className = ui("fixed top:0 left:0 w:full h:full col bg-color:paper text:ink font:ui:small z:6");
|
|
122
|
+
el.style.display = 'none';
|
|
123
|
+
el.addEventListener('keydown', onKey);
|
|
124
|
+
root.querySelector('.-verso')?.appendChild(el) || root.appendChild(el);
|
|
125
|
+
}
|
|
126
|
+
return el;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const isOpen = () => panel().style.display !== 'none';
|
|
130
|
+
function toggle() { if (isOpen()) close(); else open(); }
|
|
131
|
+
|
|
132
|
+
function close() {
|
|
133
|
+
panel().style.display = 'none';
|
|
134
|
+
document.documentElement.style.overflow = '';
|
|
135
|
+
verso.holdReload?.(false);
|
|
136
|
+
try { sessionStorage.removeItem('verso-site-view'); } catch {}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function open() {
|
|
140
|
+
verso.holdReload?.(true);
|
|
141
|
+
panel().style.display = 'flex';
|
|
142
|
+
document.documentElement.style.overflow = 'hidden';
|
|
143
|
+
await load();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function load(select) {
|
|
147
|
+
try {
|
|
148
|
+
const out = await (await fetch('/__verso/site-tree')).json();
|
|
149
|
+
if (!out.ok) throw new Error(out.message);
|
|
150
|
+
tree = out.tree;
|
|
151
|
+
} catch {
|
|
152
|
+
verso.toast('The site view couldn\'t load. Is Verso still running?', 'error');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Long lists start folded, so the shape of the site shows first.
|
|
156
|
+
if (!collapseDecided && tree) {
|
|
157
|
+
collapseDecided = true;
|
|
158
|
+
walk(tree, (n) => { if (n.children.length > 8 && n.url !== '/') collapsed.add(n.url); });
|
|
159
|
+
}
|
|
160
|
+
selected = byUrl(select) ? select : byUrl(selected) ? selected : byUrl(verso.data.url) ? verso.data.url : '/';
|
|
161
|
+
// The picked page's folders are open.
|
|
162
|
+
for (let up = parentOf(byUrl(selected)); up; up = parentOf(up)) { collapsed.delete(up.url); mapOpen.add(up.url); }
|
|
163
|
+
render();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ════ The tree ════
|
|
167
|
+
|
|
168
|
+
const walk = (n, fn, depth = 0, parent = null) => { fn(n, depth, parent); n.children.forEach((c) => walk(c, fn, depth + 1, n)); };
|
|
169
|
+
const byUrl = (url) => {
|
|
170
|
+
let found = null;
|
|
171
|
+
if (tree && url) walk(tree, (n) => { if (n.url === url) found = n; });
|
|
172
|
+
return found;
|
|
173
|
+
};
|
|
174
|
+
const parentOf = (node) => {
|
|
175
|
+
let found = null;
|
|
176
|
+
if (tree && node) walk(tree, (n, d, p) => { if (n === node) found = p; });
|
|
177
|
+
return found;
|
|
178
|
+
};
|
|
179
|
+
const count = (n) => n.children.reduce((s, c) => s + 1 + count(c), 0);
|
|
180
|
+
const pageCount = () => (tree ? 1 + count(tree) : 0);
|
|
181
|
+
// Rows as the outline shows them: open folders only.
|
|
182
|
+
function rows() {
|
|
183
|
+
const out = [];
|
|
184
|
+
const add = (n, depth) => {
|
|
185
|
+
out.push({ node: n, depth });
|
|
186
|
+
if (!collapsed.has(n.url)) n.children.forEach((c) => add(c, n.url === '/' ? depth : depth + 1));
|
|
187
|
+
};
|
|
188
|
+
if (tree) add(tree, 0);
|
|
189
|
+
// Home sits at the top level with its pages, not above them.
|
|
190
|
+
return out.map((r) => ({ ...r, depth: r.node.url === '/' ? 0 : r.depth }));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ════ Drawing ════
|
|
194
|
+
|
|
195
|
+
function render() {
|
|
196
|
+
const { ui, esc, icon } = verso;
|
|
197
|
+
const el = panel();
|
|
198
|
+
const keepList = el.querySelector('[data-scroll]')?.scrollTop || 0;
|
|
199
|
+
const keepMap = el.querySelector('[data-map]');
|
|
200
|
+
const mapAt = keepMap ? [keepMap.scrollLeft, keepMap.scrollTop] : null;
|
|
201
|
+
const seg = (id, label, svg) => `<button data-view="${id}" aria-pressed="${view === id}" class="${view === id ? ui("row:y-center gap:d2 h:d9 pd-x:d3 bd:round-pill bd:width-0 bg-color:paper text:ink font:small:semibold cursor:pointer shadow:float") : ui("row:y-center gap:d2 h:d9 pd-x:d3 bd:round-pill bd:width-0 bg-color:transparent text:ink-3 font:small:medium cursor:pointer @hover:[text:ink] transition:fast")}">${svg}${label}</button>`;
|
|
202
|
+
el.innerHTML = `
|
|
203
|
+
<header class="${ui("row:y-center gap:d4 pd-x:d5 pd-y:d3 bd-b:width-px:solid:line child:no-shrink")}">
|
|
204
|
+
<div class="${ui("row:y-center gap:d3")}">
|
|
205
|
+
<h2 class="${ui("font:small:semibold text:ink")}">Site view</h2>
|
|
206
|
+
<span class="${ui("font:small text:mist")}">${pageCount()} page${pageCount() === 1 ? '' : 's'}</span>
|
|
207
|
+
</div>
|
|
208
|
+
<div class="${ui("row gap:d0 pd:d0 bd:round-pill bg-color:paper-2")}" role="group" aria-label="Show the site as">${seg('outline', 'Outline', SVG_LIST)}${seg('map', 'Map', SVG_TREE)}</div>
|
|
209
|
+
<span class="${ui("child:grow")}"></span>
|
|
210
|
+
<button data-new class="${ui("row:y-center gap:d1 h:d10 pd-l:d3 pd-r:d4 bd:round-pill bd:width-0 bg-color:proof text:paper font:small:semibold cursor:pointer @hover:[bg-color:proof-2] @focus-visible:[outline:d0:solid:ink] transition:fast")}">${icon('plus')}New page</button>
|
|
211
|
+
<button data-close class="${ui("bg-color:transparent bd:width-0 cursor:pointer row:x-center:y-center w:d10 h:d10 bd:round-full text:ink @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}" aria-label="Close">${icon('close')}</button>
|
|
212
|
+
</header>
|
|
213
|
+
<div class="${ui("relative row child:grow overflow:hidden")}">
|
|
214
|
+
${view === 'outline' ? outline() : map()}
|
|
215
|
+
${details()}
|
|
216
|
+
</div>`;
|
|
217
|
+
el.querySelector('[data-close]').addEventListener('click', close);
|
|
218
|
+
el.querySelector('[data-new]').addEventListener('click', () => newPage(selected));
|
|
219
|
+
el.querySelectorAll('[data-view]').forEach((b) => b.addEventListener('click', () => {
|
|
220
|
+
view = b.dataset.view;
|
|
221
|
+
try { sessionStorage.setItem('verso-site-view-mode', view); } catch {}
|
|
222
|
+
render();
|
|
223
|
+
}));
|
|
224
|
+
const list = el.querySelector('[data-scroll]');
|
|
225
|
+
if (list) list.scrollTop = keepList;
|
|
226
|
+
const m = el.querySelector('[data-map]');
|
|
227
|
+
if (m && mapAt) [m.scrollLeft, m.scrollTop] = mapAt;
|
|
228
|
+
else if (m) centreMap(m);
|
|
229
|
+
wire();
|
|
230
|
+
fitFrames();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function outline() {
|
|
234
|
+
const { ui, esc } = verso;
|
|
235
|
+
const row = ({ node, depth }) => {
|
|
236
|
+
const on = node.url === selected;
|
|
237
|
+
const home = node.url === '/';
|
|
238
|
+
const kids = node.children.length;
|
|
239
|
+
const open = !collapsed.has(node.url);
|
|
240
|
+
return `
|
|
241
|
+
<div data-row="${esc(node.url)}" ${home ? '' : 'draggable="true"'} role="treeitem" aria-level="${depth + 1}" aria-selected="${on}" ${kids ? `aria-expanded="${open}"` : ''} tabindex="${on ? 0 : -1}"
|
|
242
|
+
class="${on ? ui("relative row:y-center gap:d2 h:d10 pd-r:d3 bd:round-d3 bg-color:proof-soft text:ink cursor:pointer child:no-shrink @focus-visible:[outline:d0:solid:proof]") : ui("relative row:y-center gap:d2 h:d10 pd-r:d3 bd:round-d3 bg-color:transparent text:ink cursor:pointer child:no-shrink @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}" style="padding-left:${8 + depth * 22}px">
|
|
243
|
+
${kids && !home ? `<button data-fold tabindex="-1" aria-label="${open ? 'Fold' : 'Unfold'} ${esc(node.label)}" class="${ui("row:x-center:y-center w:d7 h:d7 bd:round-d2 bd:width-0 bg-color:transparent text:ink-3 cursor:pointer child:no-shrink @hover:[bg-color:line] transition:fast")}" style="transform:rotate(${open ? 90 : 0}deg)">${SVG_CARET}</button>` : `<span class="${ui("w:d7 child:no-shrink")}"></span>`}
|
|
244
|
+
<span class="${ui("row:y-center text:ink-3 child:no-shrink")}">${home ? SVG_HOME : SVG_PAGE}</span>
|
|
245
|
+
<span class="${ui("child:grow min-w:0 overflow:hidden text-overflow:ellipsis format:no-wrap font:small:medium")}">${esc(node.label)}</span>
|
|
246
|
+
${node.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>` : ''}
|
|
247
|
+
${kids && !open ? `<span class="${ui("font:tiny text:mist child:no-shrink")}">${kids}</span>` : ''}
|
|
248
|
+
</div>`;
|
|
249
|
+
};
|
|
250
|
+
return `
|
|
251
|
+
<div class="${ui("col w:card bd-r:width-px:solid:line child:no-shrink")}">
|
|
252
|
+
<div data-scroll role="tree" aria-label="Pages" class="${ui("relative col gap:px pd:d3 child:grow overflow-y:auto")}">${rows().map(row).join('')}</div>
|
|
253
|
+
<p class="${ui("pd:d4 bd-t:width-px:solid:line font:tiny text:ink-3")}">Drag a page up or down to reorder it, or onto the middle of another to put it inside. With the keyboard: Alt and the arrows move it, Tab puts it inside the page above, Shift+Tab takes it out.</p>
|
|
254
|
+
</div>`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function map() {
|
|
258
|
+
const { ui, esc } = verso;
|
|
259
|
+
const card = (node) => {
|
|
260
|
+
const on = node.url === selected;
|
|
261
|
+
const kids = node.children.length;
|
|
262
|
+
const open = mapOpen.has(node.url);
|
|
263
|
+
return `
|
|
264
|
+
<div data-card="${esc(node.url)}" ${node.url === '/' ? '' : 'draggable="true"'} tabindex="0" role="button" aria-pressed="${on}" aria-label="${esc(node.label)}"
|
|
265
|
+
class="${on ? ui("relative col w:c11 bd:round-d4 bd:width-d0:solid:proof bg-color:paper cursor:pointer overflow:hidden shadow:float") : ui("relative col w:c11 bd:round-d4 bd:width-px:solid:line bg-color:paper cursor:pointer overflow:hidden @hover:[bd:ink-3] @focus-visible:[outline:d0:solid:proof] transition:fast")}">
|
|
266
|
+
<div data-frame class="${ui("relative w:full aspect:landscape overflow:hidden bg-color:paper-2 bd-b:width-px:solid:line")}">
|
|
267
|
+
<iframe src="/__verso/thumb?url=${encodeURIComponent(node.url)}" loading="lazy" tabindex="-1" aria-hidden="true" class="${ui("absolute top:0 left:0 bd:width-0 events:none")}" style="width:1280px;height:800px;transform-origin:0 0"></iframe>
|
|
268
|
+
</div>
|
|
269
|
+
<div class="${ui("col gap:d0 pd:d3")}">
|
|
270
|
+
<span class="${ui("row:y-center gap:d2")}"><span class="${ui("child:grow min-w:0 overflow:hidden text-overflow:ellipsis format:no-wrap font:small:semibold")}">${esc(node.label)}</span>${node.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>
|
|
271
|
+
<span class="${ui("font:tiny text:mist overflow:hidden text-overflow:ellipsis format:no-wrap")}">${esc(node.url)}</span>
|
|
272
|
+
</div>
|
|
273
|
+
</div>
|
|
274
|
+
${kids ? `<button data-map-fold="${esc(node.url)}" aria-expanded="${open}" class="${ui("relative row:y-center gap:d1 h:d7 pd-x:d3 bd:round-pill bd:width-px:solid:line bg-color:paper text:ink-3 font:tiny:semibold cursor:pointer z:1 @hover:[text:ink_bd:ink-3] @focus-visible:[outline:d0:solid:proof] transition:fast")}" style="margin-top:-12px">${open ? 'Fold' : `${kids} inside`}</button>` : ''}`;
|
|
275
|
+
};
|
|
276
|
+
const node = (n, root = false) => `
|
|
277
|
+
<div class="vsv-node${root ? ' vsv-root' : ''}">
|
|
278
|
+
${card(n)}
|
|
279
|
+
${n.children.length && mapOpen.has(n.url) ? `<div class="vsv-kids">${n.children.map((c) => node(c)).join('')}</div>` : ''}
|
|
280
|
+
</div>`;
|
|
281
|
+
return `
|
|
282
|
+
<style>${MAP_CSS}</style>
|
|
283
|
+
<div class="${ui("relative child:grow bg-color:paper-2")}">
|
|
284
|
+
<div data-map class="${ui("absolute top:0 left:0 w:full h:full overflow:auto")}">
|
|
285
|
+
<div class="vsv-tree">${tree ? node(tree, true) : ''}</div>
|
|
286
|
+
</div>
|
|
287
|
+
<p class="${ui("absolute top:d3 left:d4 pd:d1:d3 bd:round-pill bg-color:paper font:tiny text:ink-3 events:none")}">Drag a page beside another to reorder it, or onto it to put it inside.</p>
|
|
288
|
+
</div>`;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Everything about the picked page, and everything you can do to it.
|
|
292
|
+
function details() {
|
|
293
|
+
const { ui, esc, icon, data } = verso;
|
|
294
|
+
const node = byUrl(selected);
|
|
295
|
+
if (!node) return '';
|
|
296
|
+
const home = node.url === '/';
|
|
297
|
+
const parent = parentOf(node);
|
|
298
|
+
const slug = home ? '' : node.url.split('/').filter(Boolean).pop();
|
|
299
|
+
const prefix = home ? '' : parent ? (parent.url === '/' ? '/' : parent.url) : '/';
|
|
300
|
+
const inside = count(node);
|
|
301
|
+
const wide = view === 'outline';
|
|
302
|
+
const label = (t) => `<span class="${ui("font:tiny:medium text:ink-3")}">${t}</span>`;
|
|
303
|
+
const btn = (attrs, inner, danger = false) => `<button ${attrs} class="${danger ? ui("row:y-center gap:d2 h:d10 pd-x:d4 bd:round-pill bd:width-px:solid:line bg-color:paper text:proof-2 font:small:semibold cursor:pointer @hover:[bg-color:proof-soft] @focus-visible:[outline:d0:solid:proof] transition:fast") : ui("row:y-center gap:d2 h:d10 pd-x:d4 bd:round-pill bd:width-px:solid:line bg-color:paper text:ink font:small:semibold cursor:pointer @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}">${inner}</button>`;
|
|
304
|
+
// Every page this one could go inside, as the "Move inside" list.
|
|
305
|
+
const homes = [];
|
|
306
|
+
if (!home) walk(tree, (n, depth) => { if (n.url !== node.url && !n.url.startsWith(node.url)) homes.push({ url: n.url, label: n.url === '/' ? 'The top level' : `${' '.repeat(Math.max(0, depth - 1))}${n.label}`, here: parent && parent.url === n.url }); });
|
|
307
|
+
const confirm = confirmDelete && confirmDelete.url === node.url;
|
|
308
|
+
return `
|
|
309
|
+
<aside data-details aria-label="${esc(node.label)}" class="${wide ? ui("col gap:d6 child:grow pd:d8 overflow-y:auto") : ui("col gap:d5 w:sheet pd:d5 bd-l:width-px:solid:line bg-color:paper overflow-y:auto child:no-shrink")}" style="${wide ? 'max-width:64rem' : ''}">
|
|
310
|
+
<div class="${ui("row:y-center gap:d3")}">
|
|
311
|
+
<input data-title value="${esc(node.title || node.label)}" aria-label="Title" ${home ? 'readonly' : ''} class="${ui("child:grow min-w:0 h:d11 pd-x:d2 bd:round-d3 bd:width-px:solid:transparent bg-color:transparent font:h6:semibold text:ink @hover:[bd:line] @focus:[bd:proof_shadow:proof-focus_outline:none] transition:fast")}">
|
|
312
|
+
${home ? `<span class="${ui("pd-x:d3 h:d8 row:y-center bd:round-pill bg-color:paper-2 text:ink-3 font:tiny:semibold format:no-wrap child:no-shrink")}">Home page</span>` : node.draft
|
|
313
|
+
? `<span class="${ui("row:y-center h:d8 pd-x:d3 bd:round-pill bg-color:proof-soft text:proof-2 font:tiny:semibold format:no-wrap child:no-shrink")}" title="Not on the live site">Draft</span>`
|
|
314
|
+
: `<span class="${ui("row:y-center h:d8 pd-x:d3 bd:round-pill bg-color:paper-2 text:ok-2 font:tiny:semibold format:no-wrap child:no-shrink")}" title="On the live site">Live</span>`}
|
|
315
|
+
</div>
|
|
316
|
+
<a href="${esc(node.url)}" data-frame class="${ui("relative block w:full aspect:landscape overflow:hidden bd:round-d4 bd:width-px:solid:line bg-color:paper-2")}" title="Open ${esc(node.label)}">
|
|
317
|
+
<iframe src="/__verso/thumb?url=${encodeURIComponent(node.url)}" tabindex="-1" aria-hidden="true" class="${ui("absolute top:0 left:0 bd:width-0 events:none")}" style="width:1280px;height:800px;transform-origin:0 0"></iframe>
|
|
318
|
+
</a>
|
|
319
|
+
<div class="${wide ? ui("grid:cols-1-fr:gap-d5 /lg/ grid:cols-2-fr:gap-d6") : ui("col gap:d5")}">
|
|
320
|
+
<label class="${ui("col gap:d1")}">${label('Address')}
|
|
321
|
+
${home ? `<span class="${ui("h:d10 row:y-center font:small text:ink")}">/</span>` : `<span class="${ui("row:y-center h:d10 pd-l:d3 bd:round-d3 bd:width-px:solid:line bg-color:paper @focus-within:[bd:proof_shadow:proof-focus]")}"><span class="${ui("font:small text:mist format:no-wrap")}">${esc(prefix)}</span><input data-slug value="${esc(slug)}" spellcheck="false" aria-label="Address" class="${ui("child:grow min-w:0 h:full pd-r:d3 bd:width-0 bg-color:transparent font:small text:ink @focus:[outline:none]")}"></span>`}
|
|
322
|
+
</label>
|
|
323
|
+
<div class="${ui("col gap:d1")}">${label('Page type')}<span class="${ui("h:d10 row:y-center font:small text:ink")}">${esc(String(node.template || '').replace(/^./, (c) => c.toUpperCase()))}</span></div>
|
|
324
|
+
${home ? '' : `<label class="${ui("col gap:d1")}">${label('Inside')}
|
|
325
|
+
<select data-parent class="${ui("w:full h:d10 pd-x:d2 bd:round-d3 bd:width-px:solid:line bg-color:paper font:small text:ink cursor:pointer @focus:[bd:proof_shadow:proof-focus_outline:none]")}">${homes.map((h) => `<option value="${esc(h.url)}"${h.here ? ' selected' : ''}>${esc(h.label)}</option>`).join('')}</select>
|
|
326
|
+
</label>`}
|
|
327
|
+
<div class="${ui("col gap:d1")}">${label('Pages inside it')}<span class="${ui("h:d10 row:y-center font:small text:ink")}">${inside ? `${inside} page${inside === 1 ? '' : 's'}` : 'None yet'}</span></div>
|
|
328
|
+
</div>
|
|
329
|
+
<div class="${ui("row:y-center:wrap gap:d2")}">
|
|
330
|
+
${node.url === data.url ? '' : `<a href="${esc(node.url)}" class="${ui("row:y-center gap:d2 h:d10 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")}">Open page${SVG_OPEN}</a>`}
|
|
331
|
+
${btn('data-inside', `${icon('plus')}Page inside`)}
|
|
332
|
+
${home ? '' : btn('data-duplicate', `${SVG_COPY}Duplicate`)}
|
|
333
|
+
${home ? '' : node.draft ? btn('data-live', 'Make live') : btn('data-draft', 'Back to draft')}
|
|
334
|
+
<span class="${ui("child:grow")}"></span>
|
|
335
|
+
${home ? '' : btn('data-delete', `${icon('trash')}Delete`, true)}
|
|
336
|
+
</div>
|
|
337
|
+
${confirm ? `<div data-confirm class="${ui("row:y-center:wrap gap:d3 pd:d4 bd:round-d4 bg-color:proof-soft text:ink font:small")}">
|
|
338
|
+
<span class="${ui("child:grow")}">${confirmDelete.within ? `${esc(node.label)} has ${confirmDelete.within} page${confirmDelete.within === 1 ? '' : 's'} inside. Delete ${confirmDelete.within === 1 ? 'it' : 'them'} too?` : `Delete ${esc(node.label)}? A published page can be brought back from History.`}</span>
|
|
339
|
+
${btn('data-delete-yes', confirmDelete.within ? 'Delete them all' : 'Delete', true)}${btn('data-delete-no', 'Keep it')}
|
|
340
|
+
</div>` : ''}
|
|
341
|
+
</aside>`;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Previews are drawn 1280 wide and scaled into their frames.
|
|
345
|
+
function fitFrames() {
|
|
346
|
+
panel().querySelectorAll('[data-frame]').forEach((frame) => {
|
|
347
|
+
const iframe = frame.querySelector('iframe');
|
|
348
|
+
if (iframe && frame.clientWidth) iframe.style.transform = `scale(${frame.clientWidth / 1280})`;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
window.addEventListener('resize', () => { if (verso && isOpen()) fitFrames(); });
|
|
352
|
+
|
|
353
|
+
function centreMap(m) {
|
|
354
|
+
const card = m.querySelector(`[data-card="${CSS.escape(selected || '/')}"]`) || m.querySelector('[data-card]');
|
|
355
|
+
if (!card) return;
|
|
356
|
+
const r = card.getBoundingClientRect();
|
|
357
|
+
const box = m.getBoundingClientRect();
|
|
358
|
+
m.scrollLeft += r.left - box.left - (box.width - r.width) / 2;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// ════ Doing things ════
|
|
362
|
+
|
|
363
|
+
function pick(url, focus = false) {
|
|
364
|
+
if (!byUrl(url)) return;
|
|
365
|
+
selected = url;
|
|
366
|
+
confirmDelete = null;
|
|
367
|
+
render();
|
|
368
|
+
if (focus) panel().querySelector(`[data-row="${CSS.escape(url)}"], [data-card="${CSS.escape(url)}"]`)?.focus();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function newPage(parent) {
|
|
372
|
+
import('/__verso/new-page.js')
|
|
373
|
+
.then((m) => m.openNewPage({ root: verso.root, data: verso.data, ui: verso.ui, toast: verso.toast, icon: verso.icon, parent: parent || '/' }))
|
|
374
|
+
.catch(() => verso.toast('The new page form couldn\'t open. Is Verso still running?', 'error'));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async function move(from, toParent, index) {
|
|
378
|
+
const { data } = verso;
|
|
379
|
+
const out = await post('/__verso/move', { from, toParent, index });
|
|
380
|
+
if (!out.ok) { verso.toast(out.message, 'error'); return; }
|
|
381
|
+
const label = byUrl(from)?.label || 'the page';
|
|
382
|
+
const links = out.links ? ` ${out.links} link${out.links === 1 ? '' : 's'} updated.` : '';
|
|
383
|
+
const tpl = out.templates?.length ? ` ${out.templates.join(', ')} still ${out.templates.length === 1 ? 'links' : 'link'} to ${out.from}. Change it there.` : '';
|
|
384
|
+
verso.refreshStatus();
|
|
385
|
+
// If the page being edited moved, follow it.
|
|
386
|
+
if (out.from !== out.to && (data.url === out.from || data.url.startsWith(out.from))) {
|
|
387
|
+
say(`Moved ${label} to ${out.to}.${links}${tpl}`, 'ok', true);
|
|
388
|
+
location.href = out.to + data.url.slice(out.from.length);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
say(out.from === out.to ? `Moved ${label}.` : `Moved ${label} to ${out.to}.${links}${tpl}`);
|
|
392
|
+
await load(out.to);
|
|
393
|
+
panel().querySelector(`[data-row="${CSS.escape(out.to)}"], [data-card="${CSS.escape(out.to)}"]`)?.focus();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Where a drop lands: "before" and "after" a page are among its neighbours,
|
|
397
|
+
// "inside" goes last among its own pages.
|
|
398
|
+
function drop(from, target, where) {
|
|
399
|
+
if (!from || from === target.url || target.url.startsWith(from)) return;
|
|
400
|
+
if (where === 'inside' || target.url === '/') {
|
|
401
|
+
move(from, target.url, target.children.filter((c) => c.url !== from).length);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const parent = parentOf(target) || tree;
|
|
405
|
+
const rest = parent.children.filter((c) => c.url !== from);
|
|
406
|
+
move(from, parent.url, rest.findIndex((c) => c.url === target.url) + (where === 'after' ? 1 : 0));
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function marker(el, where, vertical) {
|
|
410
|
+
clearMarkers();
|
|
411
|
+
const m = document.createElement('div');
|
|
412
|
+
m.dataset.marker = '';
|
|
413
|
+
const red = '#FF4F2B';
|
|
414
|
+
if (where === 'inside') {
|
|
415
|
+
Object.assign(m.style, { position: 'absolute', inset: '0', borderRadius: '10px', boxShadow: `inset 0 0 0 2px ${red}`, background: 'rgba(255,79,43,.08)', pointerEvents: 'none' });
|
|
416
|
+
const tag = document.createElement('span');
|
|
417
|
+
tag.textContent = `Inside ${byUrl(el.dataset.row || el.dataset.card)?.label || ''}`;
|
|
418
|
+
Object.assign(tag.style, { position: 'absolute', right: '8px', top: '50%', transform: 'translateY(-50%)', background: red, color: '#fff', font: '600 11px/1 ui-sans-serif,system-ui,sans-serif', padding: '4px 7px', borderRadius: '999px' });
|
|
419
|
+
if (vertical) Object.assign(tag.style, { top: '8px', transform: 'none' });
|
|
420
|
+
m.appendChild(tag);
|
|
421
|
+
} else if (vertical) {
|
|
422
|
+
Object.assign(m.style, { position: 'absolute', top: '0', bottom: '0', width: '3px', borderRadius: '3px', background: red, pointerEvents: 'none', [where === 'before' ? 'left' : 'right']: '-9px' });
|
|
423
|
+
} else {
|
|
424
|
+
const indent = parseFloat(el.style.paddingLeft || '8') + 28;
|
|
425
|
+
Object.assign(m.style, { position: 'absolute', left: `${indent}px`, right: '6px', height: '3px', borderRadius: '3px', background: red, pointerEvents: 'none', [where === 'before' ? 'top' : 'bottom']: '-2px' });
|
|
426
|
+
}
|
|
427
|
+
el.appendChild(m);
|
|
428
|
+
}
|
|
429
|
+
const clearMarkers = () => panel().querySelectorAll('[data-marker]').forEach((m) => m.remove());
|
|
430
|
+
|
|
431
|
+
function wireDrag(el, url, vertical) {
|
|
432
|
+
const node = byUrl(url);
|
|
433
|
+
const zone = (e) => {
|
|
434
|
+
if (url === '/') return 'inside';
|
|
435
|
+
const r = el.getBoundingClientRect();
|
|
436
|
+
const f = vertical ? (e.clientX - r.left) / r.width : (e.clientY - r.top) / r.height;
|
|
437
|
+
return f < 0.3 ? 'before' : f > 0.7 ? 'after' : 'inside';
|
|
438
|
+
};
|
|
439
|
+
const allowed = () => dragging && dragging !== url && !url.startsWith(dragging);
|
|
440
|
+
el.addEventListener('dragstart', (e) => {
|
|
441
|
+
dragging = url;
|
|
442
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
443
|
+
e.dataTransfer.setData('text/plain', url);
|
|
444
|
+
requestAnimationFrame(() => { el.style.opacity = '0.45'; });
|
|
445
|
+
});
|
|
446
|
+
el.addEventListener('dragend', () => { el.style.opacity = ''; dragging = null; clearMarkers(); });
|
|
447
|
+
el.addEventListener('dragover', (e) => {
|
|
448
|
+
if (!allowed()) return;
|
|
449
|
+
e.preventDefault();
|
|
450
|
+
e.dataTransfer.dropEffect = 'move';
|
|
451
|
+
marker(el, zone(e), vertical);
|
|
452
|
+
});
|
|
453
|
+
el.addEventListener('dragleave', (e) => { if (!el.contains(e.relatedTarget)) clearMarkers(); });
|
|
454
|
+
el.addEventListener('drop', (e) => {
|
|
455
|
+
if (!allowed()) return;
|
|
456
|
+
e.preventDefault();
|
|
457
|
+
const where = zone(e);
|
|
458
|
+
const from = dragging;
|
|
459
|
+
clearMarkers();
|
|
460
|
+
drop(from, node, where);
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function wire() {
|
|
465
|
+
const el = panel();
|
|
466
|
+
el.querySelectorAll('[data-row]').forEach((row) => {
|
|
467
|
+
const url = row.dataset.row;
|
|
468
|
+
row.addEventListener('click', (e) => {
|
|
469
|
+
if (e.target.closest('[data-fold]')) return;
|
|
470
|
+
pick(url, true);
|
|
471
|
+
});
|
|
472
|
+
row.addEventListener('dblclick', () => { location.href = url; });
|
|
473
|
+
row.querySelector('[data-fold]')?.addEventListener('click', () => fold(url));
|
|
474
|
+
wireDrag(row, url, false);
|
|
475
|
+
});
|
|
476
|
+
el.querySelectorAll('[data-card]').forEach((card) => {
|
|
477
|
+
const url = card.dataset.card;
|
|
478
|
+
card.addEventListener('click', () => pick(url));
|
|
479
|
+
card.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); pick(url, true); } });
|
|
480
|
+
card.addEventListener('dblclick', () => { location.href = url; });
|
|
481
|
+
wireDrag(card, url, true);
|
|
482
|
+
});
|
|
483
|
+
el.querySelectorAll('[data-map-fold]').forEach((b) => b.addEventListener('click', () => {
|
|
484
|
+
const url = b.dataset.mapFold;
|
|
485
|
+
if (mapOpen.has(url)) mapOpen.delete(url); else mapOpen.add(url);
|
|
486
|
+
render();
|
|
487
|
+
}));
|
|
488
|
+
|
|
489
|
+
const node = byUrl(selected);
|
|
490
|
+
if (!node) return;
|
|
491
|
+
const q = (s) => el.querySelector(s);
|
|
492
|
+
const title = q('[data-title]');
|
|
493
|
+
const saveTitle = async () => {
|
|
494
|
+
const text = title.value.trim();
|
|
495
|
+
if (!text || text === (node.title || node.label) || node.url === '/') { title.value = node.title || node.label; return; }
|
|
496
|
+
const out = await post('/__verso/page/title', { url: node.url, title: text });
|
|
497
|
+
if (!out.ok) { verso.toast(out.message, 'error'); title.value = node.title || node.label; return; }
|
|
498
|
+
verso.refreshStatus();
|
|
499
|
+
say(`Retitled ${text}.`);
|
|
500
|
+
await load(node.url);
|
|
501
|
+
};
|
|
502
|
+
title?.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); title.blur(); } if (e.key === 'Escape') { e.stopPropagation(); title.value = node.title || node.label; title.blur(); } });
|
|
503
|
+
title?.addEventListener('blur', saveTitle);
|
|
504
|
+
|
|
505
|
+
const slug = q('[data-slug]');
|
|
506
|
+
const saveSlug = async () => {
|
|
507
|
+
const was = node.url.split('/').filter(Boolean).pop();
|
|
508
|
+
const name = slug.value.trim();
|
|
509
|
+
if (!name || name === was) { slug.value = was; return; }
|
|
510
|
+
const out = await post('/__verso/page/address', { url: node.url, name });
|
|
511
|
+
if (!out.ok) { verso.toast(out.message, 'error'); slug.value = was; return; }
|
|
512
|
+
verso.refreshStatus();
|
|
513
|
+
const links = out.links ? ` ${out.links} link${out.links === 1 ? '' : 's'} updated.` : '';
|
|
514
|
+
const { data } = verso;
|
|
515
|
+
if (out.from !== out.to && (data.url === out.from || data.url.startsWith(out.from))) {
|
|
516
|
+
say(`${node.label} is now at ${out.to}.${links}`, 'ok', true);
|
|
517
|
+
location.href = out.to + data.url.slice(out.from.length);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
say(`${node.label} is now at ${out.to}.${links}`);
|
|
521
|
+
await load(out.to);
|
|
522
|
+
};
|
|
523
|
+
slug?.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); slug.blur(); } if (e.key === 'Escape') { e.stopPropagation(); slug.value = node.url.split('/').filter(Boolean).pop(); slug.blur(); } });
|
|
524
|
+
slug?.addEventListener('blur', saveSlug);
|
|
525
|
+
|
|
526
|
+
q('[data-parent]')?.addEventListener('change', (e) => {
|
|
527
|
+
const to = byUrl(e.target.value);
|
|
528
|
+
if (to) move(node.url, to.url, to.children.filter((c) => c.url !== node.url).length);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
const setDraft = async (draft) => {
|
|
532
|
+
const out = await post('/__verso/draft', { url: node.url, draft });
|
|
533
|
+
if (!out.ok) { verso.toast(out.message || 'That couldn\'t be changed.', 'error'); return; }
|
|
534
|
+
say(draft ? `${node.label} is back to draft. It's not on the live site.` : `${node.label} is live. Publish to put it online.`);
|
|
535
|
+
verso.refreshStatus();
|
|
536
|
+
await load(node.url);
|
|
537
|
+
};
|
|
538
|
+
q('[data-draft]')?.addEventListener('click', () => setDraft(true));
|
|
539
|
+
q('[data-live]')?.addEventListener('click', () => setDraft(false));
|
|
540
|
+
q('[data-inside]')?.addEventListener('click', () => newPage(node.url));
|
|
541
|
+
q('[data-duplicate]')?.addEventListener('click', async () => {
|
|
542
|
+
const out = await post('/__verso/page/duplicate', { url: node.url });
|
|
543
|
+
if (!out.ok) { verso.toast(out.message, 'error'); return; }
|
|
544
|
+
say(`Made ${out.label}, as a draft beside the original.`);
|
|
545
|
+
verso.refreshStatus();
|
|
546
|
+
await load(out.url);
|
|
547
|
+
});
|
|
548
|
+
// Always asked first, and said plainly when pages inside go with it.
|
|
549
|
+
q('[data-delete]')?.addEventListener('click', () => {
|
|
550
|
+
confirmDelete = { url: node.url, within: count(node) };
|
|
551
|
+
render();
|
|
552
|
+
panel().querySelector('[data-delete-no]')?.focus();
|
|
553
|
+
});
|
|
554
|
+
q('[data-delete-yes]')?.addEventListener('click', async () => {
|
|
555
|
+
const out = await post('/__verso/page/delete', { url: node.url, inside: true });
|
|
556
|
+
if (!out.ok) { verso.toast(out.message, 'error'); return; }
|
|
557
|
+
afterDelete(out);
|
|
558
|
+
});
|
|
559
|
+
q('[data-delete-no]')?.addEventListener('click', () => { confirmDelete = null; render(); });
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
async function afterDelete(out) {
|
|
563
|
+
const { data } = verso;
|
|
564
|
+
confirmDelete = null;
|
|
565
|
+
verso.refreshStatus();
|
|
566
|
+
const others = out.linked?.length ? ` ${out.linked.slice(0, 3).join(', ')} still ${out.linked.length === 1 ? 'links' : 'link'} to it.` : '';
|
|
567
|
+
if (data.url === out.url || data.url.startsWith(out.url)) {
|
|
568
|
+
say(`Deleted ${out.label}.${others}`, 'ok', true);
|
|
569
|
+
location.href = out.parent || '/';
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
say(`Deleted ${out.label}.${others}`);
|
|
573
|
+
await load(out.parent || '/');
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function fold(url) {
|
|
577
|
+
if (collapsed.has(url)) collapsed.delete(url); else collapsed.add(url);
|
|
578
|
+
render();
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// ════ Keys ════
|
|
582
|
+
// Outline: arrows to move around and fold; Alt+arrows to move the page;
|
|
583
|
+
// Tab and Shift+Tab to put it inside the page above, or take it out.
|
|
584
|
+
function onKey(e) {
|
|
585
|
+
if (e.key === 'Escape') {
|
|
586
|
+
if (e.target.closest('input, select')) return;
|
|
587
|
+
if (confirmDelete) { confirmDelete = null; render(); return; }
|
|
588
|
+
close();
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
const row = e.target.closest?.('[data-row]');
|
|
592
|
+
if (!row) return;
|
|
593
|
+
const list = rows();
|
|
594
|
+
const i = list.findIndex((r) => r.node.url === row.dataset.row);
|
|
595
|
+
const { node } = list[i];
|
|
596
|
+
const parent = parentOf(node);
|
|
597
|
+
const siblings = parent ? parent.children : [];
|
|
598
|
+
const at = siblings.indexOf(node);
|
|
599
|
+
if (e.altKey && (e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
|
|
600
|
+
e.preventDefault();
|
|
601
|
+
const to = at + (e.key === 'ArrowUp' ? -1 : 1);
|
|
602
|
+
if (parent && node.url !== '/' && to >= 0 && to < siblings.length) move(node.url, parent.url, to);
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (e.key === 'Tab' && node.url !== '/') {
|
|
606
|
+
e.preventDefault();
|
|
607
|
+
if (e.shiftKey) {
|
|
608
|
+
const grand = parent && parentOf(parent);
|
|
609
|
+
if (grand) move(node.url, grand.url, grand.children.indexOf(parent) + 1);
|
|
610
|
+
} else if (at > 0) {
|
|
611
|
+
const above = siblings[at - 1];
|
|
612
|
+
collapsed.delete(above.url);
|
|
613
|
+
move(node.url, above.url, above.children.length);
|
|
614
|
+
}
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
618
|
+
e.preventDefault();
|
|
619
|
+
const next = list[i + (e.key === 'ArrowDown' ? 1 : -1)];
|
|
620
|
+
if (next) pick(next.node.url, true);
|
|
621
|
+
} else if (e.key === 'ArrowRight' && node.children.length && collapsed.has(node.url)) {
|
|
622
|
+
e.preventDefault();
|
|
623
|
+
fold(node.url);
|
|
624
|
+
panel().querySelector(`[data-row="${CSS.escape(node.url)}"]`)?.focus();
|
|
625
|
+
} else if (e.key === 'ArrowLeft') {
|
|
626
|
+
e.preventDefault();
|
|
627
|
+
if (node.children.length && !collapsed.has(node.url) && node.url !== '/') { fold(node.url); panel().querySelector(`[data-row="${CSS.escape(node.url)}"]`)?.focus(); } else if (parent && parent.url !== '/') pick(parent.url, true);
|
|
628
|
+
} else if (e.key === 'Enter') {
|
|
629
|
+
e.preventDefault();
|
|
630
|
+
location.href = node.url;
|
|
631
|
+
}
|
|
632
|
+
}
|