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.
- package/LICENSE +21 -0
- package/README.md +168 -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 +1195 -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,87 @@
|
|
|
1
|
+
// Fields that live in an attribute, like a link's address in
|
|
2
|
+
// <a href="{{ address:text }}">{{ label:text }}</a>. They can't be typed on
|
|
3
|
+
// the page, so when you're on such an element (click it, or edit the text
|
|
4
|
+
// inside it) a small card under it offers them. A link's address suggests
|
|
5
|
+
// the site's pages as you type.
|
|
6
|
+
|
|
7
|
+
const LINK = '<svg width="14" height="14" viewBox="0 0 24 24" aria-hidden="true"><path d="M10 14a4 4 0 0 0 5.66 0l3-3a4 4 0 0 0-5.66-5.66l-1 1M14 10a4 4 0 0 0-5.66 0l-3 3a4 4 0 0 0 5.66 5.66l1-1" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>';
|
|
8
|
+
const NAMES = { href: 'Links to', title: 'Tooltip', alt: 'Description', 'aria-label': 'Label for screen readers', id: 'Anchor name', target: 'Opens in' };
|
|
9
|
+
|
|
10
|
+
export function init(verso) {
|
|
11
|
+
const { root, data, ui, esc, values } = verso;
|
|
12
|
+
const attrsOf = (el) => [...el.attributes].filter((a) => a.name.startsWith('data-verso-attr-')).map((a) => ({ attr: a.name.slice(16), key: a.value }));
|
|
13
|
+
if (!document.querySelector('[data-verso-attr-href],[data-verso-attr-title],[data-verso-attr-alt],[data-verso-attr-aria-label],[data-verso-attr-id],[data-verso-attr-target]') && ![...document.querySelectorAll('*')].some((el) => attrsOf(el).length)) return;
|
|
14
|
+
const holder = (target) => {
|
|
15
|
+
for (let el = target; el && el !== document.body; el = el.parentElement) {
|
|
16
|
+
if (attrsOf(el).length) return el;
|
|
17
|
+
if (el.hasAttribute?.('data-verso-block')) return null;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
const labelOf = (key, attr) => {
|
|
22
|
+
const f = (data.fields || []).find((x) => x.name === key);
|
|
23
|
+
return NAMES[attr] || f?.label || attr;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const card = document.createElement('div');
|
|
27
|
+
card.className = ui("fixed col gap:d3 w:full max-w:s3 pd:d4 bg-color:ink text:paper bd:round-d4 shadow:float z:4 font:ui:small");
|
|
28
|
+
card.style.display = 'none';
|
|
29
|
+
card.setAttribute('role', 'dialog');
|
|
30
|
+
card.setAttribute('aria-label', 'Settings for this element');
|
|
31
|
+
root.appendChild(card);
|
|
32
|
+
// One list of the site's pages, shared with the rich text link box.
|
|
33
|
+
if (!root.getElementById('verso-attr-pages')) {
|
|
34
|
+
const list = document.createElement('datalist');
|
|
35
|
+
list.id = 'verso-attr-pages';
|
|
36
|
+
list.innerHTML = (data.pages || []).map((p) => `<option value="${esc(p.url)}">${esc(p.label || p.url)}</option>`).join('');
|
|
37
|
+
root.appendChild(list);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let current = null;
|
|
41
|
+
const place = () => {
|
|
42
|
+
if (!current) return;
|
|
43
|
+
const r = current.getBoundingClientRect();
|
|
44
|
+
if (r.bottom < 0 || r.top > innerHeight) { card.style.display = 'none'; return; }
|
|
45
|
+
card.style.display = 'flex';
|
|
46
|
+
const w = card.offsetWidth;
|
|
47
|
+
const h = card.offsetHeight;
|
|
48
|
+
card.style.left = `${Math.max(8, Math.min(innerWidth - w - 8, r.left))}px`;
|
|
49
|
+
const below = r.bottom + 8;
|
|
50
|
+
card.style.top = `${below + h > innerHeight - 90 ? Math.max(8, r.top - h - 8) : below}px`;
|
|
51
|
+
};
|
|
52
|
+
const close = () => { current = null; card.style.display = 'none'; };
|
|
53
|
+
const open = (el) => {
|
|
54
|
+
if (current === el) return place();
|
|
55
|
+
current = el;
|
|
56
|
+
card.innerHTML = attrsOf(el).map(({ attr, key }, i) => `
|
|
57
|
+
<label class="${ui("col gap:d1")}">
|
|
58
|
+
<span class="${ui("row:y-center gap:d1 text:mist font:ui:tiny:semibold")}">${attr === 'href' ? LINK : ''}${esc(labelOf(key, attr))}</span>
|
|
59
|
+
<input data-key="${esc(key)}" data-attr="${esc(attr)}" ${attr === 'href' ? 'list="verso-attr-pages" placeholder="A page, like /about/, or https://…"' : ''} value="${esc(String(values[key] ?? el.getAttribute(attr) ?? ''))}" autocomplete="off" spellcheck="false" class="${ui("w:full h:d10 pd-x:d3 bd:width-px:solid:ink-2 bd:round-d3 bg-color:ink-2 text:paper font:ui:small @focus:[bd:proof] transition:fast")}" ${i === 0 ? 'data-first' : ''}>
|
|
60
|
+
</label>`).join('');
|
|
61
|
+
card.querySelectorAll('input').forEach((input) => {
|
|
62
|
+
input.addEventListener('input', () => {
|
|
63
|
+
const { key, attr } = input.dataset;
|
|
64
|
+
values[key] = input.value;
|
|
65
|
+
document.querySelectorAll(`[data-verso-attr-${CSS.escape(attr)}="${CSS.escape(key)}"]`).forEach((x) => x.setAttribute(attr, input.value));
|
|
66
|
+
verso.queue({ fields: { [key]: input.value.trim() } });
|
|
67
|
+
});
|
|
68
|
+
input.addEventListener('keydown', (e) => { if (e.key === 'Escape' || e.key === 'Enter') { e.preventDefault(); close(); } });
|
|
69
|
+
});
|
|
70
|
+
place();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Clicking on the page: open the card for the element, or close it.
|
|
74
|
+
document.addEventListener('click', (e) => {
|
|
75
|
+
if (e.composedPath().includes(card)) return;
|
|
76
|
+
const el = holder(e.target);
|
|
77
|
+
if (el) {
|
|
78
|
+
// A link with fields in it edits its text; it doesn't take you away.
|
|
79
|
+
if (el.tagName === 'A' || e.target.closest?.('a')) e.preventDefault();
|
|
80
|
+
open(el);
|
|
81
|
+
} else close();
|
|
82
|
+
}, true);
|
|
83
|
+
document.addEventListener('focusin', (e) => { const el = holder(e.target); if (el) open(el); });
|
|
84
|
+
addEventListener('keydown', (e) => { if (e.key === 'Escape') close(); });
|
|
85
|
+
addEventListener('scroll', place, { passive: true });
|
|
86
|
+
addEventListener('resize', place);
|
|
87
|
+
}
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// Blocks in the editor: the library of live-rendered blocks, dragging them
|
|
2
|
+
// onto the page (only spots that take a block light up), and moving,
|
|
3
|
+
// copying and removing blocks already there.
|
|
4
|
+
|
|
5
|
+
const SVG = {
|
|
6
|
+
blocks: '<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><rect x="4" y="4" width="7" height="7" rx="1.5" fill="none" stroke="currentColor" stroke-width="2"/><rect x="13" y="4" width="7" height="7" rx="1.5" fill="none" stroke="currentColor" stroke-width="2"/><rect x="4" y="13" width="16" height="7" rx="1.5" fill="none" stroke="currentColor" stroke-width="2"/></svg>',
|
|
7
|
+
grip: '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><g fill="currentColor"><circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/></g></svg>',
|
|
8
|
+
up: '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 14 6-6 6 6" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
9
|
+
down: '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 10 6 6 6-6" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
10
|
+
copy: '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><rect x="8" y="8" width="11" height="11" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M5 15V6a1 1 0 0 1 1-1h9" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
|
|
11
|
+
trash: '<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>',
|
|
12
|
+
close: '<svg width="18" height="18" viewBox="0 0 24 24" aria-hidden="true"><path d="m7 7 10 10M17 7 7 17" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
|
|
13
|
+
component: '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 20 7.5v9L12 21l-8-4.5v-9z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M4 7.5 12 12l8-4.5M12 12v9" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
|
|
14
|
+
cube: '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3 20 7.5v9L12 21l-8-4.5v-9zM4 7.5 12 12l8-4.5M12 12v9" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
|
|
15
|
+
more: '<svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true"><g fill="currentColor"><circle cx="6" cy="12" r="1.8"/><circle cx="12" cy="12" r="1.8"/><circle cx="18" cy="12" r="1.8"/></g></svg>',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function init(verso) {
|
|
19
|
+
const { root, data, ui, esc, toast } = verso;
|
|
20
|
+
const types = data.blockTypes || [];
|
|
21
|
+
const components = data.components || [];
|
|
22
|
+
if (!types.length || !document.querySelector('[data-verso-slot]')) return;
|
|
23
|
+
// Component instances whose structure is being edited ("for all pages").
|
|
24
|
+
const editing = new Set(JSON.parse(sessionStorage.getItem('verso-structure') || '[]'));
|
|
25
|
+
const remember = () => { try { sessionStorage.setItem('verso-structure', JSON.stringify([...editing])); } catch {} };
|
|
26
|
+
|
|
27
|
+
// ════ Layers in the shadow root ════
|
|
28
|
+
const layer = document.createElement('div');
|
|
29
|
+
layer.className = ui("font:ui:small text:ink");
|
|
30
|
+
layer.innerHTML = `
|
|
31
|
+
<div id="blk-marks" class="${ui("fixed top:0 left:0 w:full h:full events:none z:2")}"></div>
|
|
32
|
+
<div id="blk-handle" class="${ui("fixed row:y-center gap:d0 pd:d0 bg-color:ink text:paper bd:round-d3 shadow:float z:3")}" style="display:none"></div>
|
|
33
|
+
<aside id="blk-library" class="${ui("fixed top:d3 left:d3 bottom:d3 w:sheet col bg-color:paper bd:round-d5 shadow:float bd:width-px:solid:line z:4 overflow-y:auto")}" style="display:none" aria-label="Blocks"></aside>`;
|
|
34
|
+
root.appendChild(layer);
|
|
35
|
+
const $ = (id) => root.getElementById(id);
|
|
36
|
+
const marks = $('blk-marks');
|
|
37
|
+
const handle = $('blk-handle');
|
|
38
|
+
const library = $('blk-library');
|
|
39
|
+
|
|
40
|
+
const post = async (action, body, before) => {
|
|
41
|
+
await verso.flush();
|
|
42
|
+
const res = await fetch(`/__verso/blocks/${action}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: data.url, ...body }) });
|
|
43
|
+
const out = await res.json().catch(() => ({}));
|
|
44
|
+
if (!out.ok) {
|
|
45
|
+
toast(out.message || 'That didn\'t work. Reload the page and try again.', 'error');
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
if (out.component && action !== 'restore') sessionStorage.setItem('verso-components-note', `Changed the ${out.component} component. Every page that uses it shows the change.`);
|
|
50
|
+
before?.(out);
|
|
51
|
+
} catch { /* storage is a convenience */ }
|
|
52
|
+
verso.reload();
|
|
53
|
+
return out;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// ════ Undo for removing a block ════
|
|
57
|
+
// The removed block is kept for a little while after the page reloads, with
|
|
58
|
+
// an Undo button, and Cmd/Ctrl+Z puts it back while nothing else has focus.
|
|
59
|
+
let undo = null;
|
|
60
|
+
try {
|
|
61
|
+
const kept = JSON.parse(sessionStorage.getItem('verso-undo-remove') || 'null');
|
|
62
|
+
if (kept && kept.url === data.url && Date.now() - kept.at < 60000) undo = kept;
|
|
63
|
+
else sessionStorage.removeItem('verso-undo-remove');
|
|
64
|
+
} catch { /* nothing kept */ }
|
|
65
|
+
const undoBar = document.createElement('div');
|
|
66
|
+
undoBar.className = ui("fixed bottom:c2 left:half translate:(-50%_0) row:y-center gap:d3 pd:d2 pd-l:d4 bg-color:ink text:paper bd:round-pill shadow:float z:5 font:ui:small");
|
|
67
|
+
undoBar.style.display = 'none';
|
|
68
|
+
root.appendChild(undoBar);
|
|
69
|
+
const putBack = () => {
|
|
70
|
+
if (!undo) return;
|
|
71
|
+
const { restore } = undo;
|
|
72
|
+
undo = null;
|
|
73
|
+
try { sessionStorage.removeItem('verso-undo-remove'); } catch {}
|
|
74
|
+
undoBar.style.display = 'none';
|
|
75
|
+
post('restore', restore);
|
|
76
|
+
};
|
|
77
|
+
if (undo) {
|
|
78
|
+
undoBar.innerHTML = `<span class="${ui("font:small")}">Removed ${esc(undo.label)}.</span><button data-undo class="${ui("bd:width-0 cursor:pointer h:d8 pd-x:d4 bd:round-pill bg-color:paper text:ink font:small:semibold @hover:[bg-color:proof-soft] transition:fast")}">Undo</button>`;
|
|
79
|
+
undoBar.querySelector('[data-undo]').addEventListener('click', putBack);
|
|
80
|
+
undoBar.style.display = 'flex';
|
|
81
|
+
setTimeout(() => { undoBar.style.display = 'none'; }, 10000);
|
|
82
|
+
}
|
|
83
|
+
addEventListener('keydown', (e) => {
|
|
84
|
+
if (!undo || !(e.metaKey || e.ctrlKey) || e.shiftKey || e.key.toLowerCase() !== 'z') return;
|
|
85
|
+
const active = document.activeElement;
|
|
86
|
+
if (active && (active.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(active.tagName))) return;
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
e.stopImmediatePropagation();
|
|
89
|
+
putBack();
|
|
90
|
+
}, true);
|
|
91
|
+
|
|
92
|
+
// ════ The library ════
|
|
93
|
+
// Items of a {{ list }} are added with the list's own Add button, so the
|
|
94
|
+
// library only shows real blocks, and only when there are some.
|
|
95
|
+
const libraryTypes = types.filter((t) => !t.repeater);
|
|
96
|
+
if (libraryTypes.length || components.length) {
|
|
97
|
+
verso.addBarButton({ id: 'open-blocks', title: 'Blocks', svg: SVG.blocks, onClick: () => (library.style.display === 'none' ? openLibrary() : closeLibrary()) });
|
|
98
|
+
try {
|
|
99
|
+
const again = sessionStorage.getItem('verso-reopen-blocks');
|
|
100
|
+
if (again != null) {
|
|
101
|
+
sessionStorage.removeItem('verso-reopen-blocks');
|
|
102
|
+
setTimeout(() => { openLibrary(); library.scrollTop = Number(again) || 0; }, 0);
|
|
103
|
+
}
|
|
104
|
+
} catch { /* storage is a convenience */ }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function openLibrary() {
|
|
108
|
+
library.innerHTML = `
|
|
109
|
+
<header class="${ui("row:y-center:x-between pd-x:d5 pd-t:d5 pd-b:d3 sticky top:0 bg-color:paper z:1")}">
|
|
110
|
+
<div class="${ui("col gap:d0")}">
|
|
111
|
+
<h2 class="${ui("font:h6:semibold text:ink")}">Blocks</h2>
|
|
112
|
+
<p class="${ui("font:tiny text:mist")}">Drag one onto the page, or press Add.</p>
|
|
113
|
+
</div>
|
|
114
|
+
<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 @hover:[bg-color:paper-2] @focus-visible:[outline:d0:solid:proof] transition:fast")}" aria-label="Close blocks">${SVG.close}</button>
|
|
115
|
+
</header>
|
|
116
|
+
<ul class="${ui("col gap:d5 pd-x:d5 pd-b:c3 list-style-type:none")}">
|
|
117
|
+
${libraryTypes.map((t) => `
|
|
118
|
+
<li draggable="true" data-block="${esc(t.name)}" class="${ui("col gap:d2 cursor:grab")}">
|
|
119
|
+
<div data-frame class="${ui("relative w:full aspect:landscape overflow:hidden bd:round-d3 bd:width-px:solid:line bg-color:paper-2 transition:fast @hover:[shadow:proof-ring]")}">
|
|
120
|
+
<iframe src="/__verso/block-preview/${encodeURIComponent(t.name)}/" loading="lazy" tabindex="-1" title="${esc(t.label)}" style="position:absolute;top:0;left:0;width:1280px;height:800px;border:0;transform-origin:0 0;pointer-events:none"></iframe>
|
|
121
|
+
</div>
|
|
122
|
+
<div class="${ui("row:y-center:x-between")}">
|
|
123
|
+
<span class="${ui("font:small:medium text:ink")}">${esc(t.label)}</span>
|
|
124
|
+
<button data-add="${esc(t.name)}" aria-label="Add ${esc(t.label)}" class="${ui("bg-color:transparent bd:width-0 cursor:pointer h:d8 pd-x:d3 bd:round-pill font:tiny:semibold text:proof-2 @hover:[bg-color:proof-soft] transition:fast")}">Add</button>
|
|
125
|
+
</div>
|
|
126
|
+
</li>`).join('')}
|
|
127
|
+
</ul>
|
|
128
|
+
${components.length ? `
|
|
129
|
+
<h3 class="${ui("pd-x:d5 pd-b:d3 font:small:medium text:mist")}">Components</h3>
|
|
130
|
+
<ul class="${ui("col gap:d5 pd-x:d5 pd-b:c3 list-style-type:none")}">
|
|
131
|
+
${components.map((c) => `
|
|
132
|
+
<li draggable="true" data-component="${esc(c.name)}" class="${ui("col gap:d2 cursor:grab")}">
|
|
133
|
+
<div data-frame class="${ui("relative w:full aspect:landscape overflow:hidden bd:round-d3 bd:width-px:solid:line bg-color:paper-2 transition:fast @hover:[shadow:proof-ring]")}">
|
|
134
|
+
<iframe src="/__verso/component-preview/${encodeURIComponent(c.name)}/" loading="lazy" tabindex="-1" title="${esc(c.label)}" style="position:absolute;top:0;left:0;width:1280px;height:800px;border:0;transform-origin:0 0;pointer-events:none"></iframe>
|
|
135
|
+
</div>
|
|
136
|
+
<div class="${ui("row:y-center:x-between")}">
|
|
137
|
+
<span class="${ui("row:y-center gap:d1 font:small:medium text:ink")}">${SVG.component}<span>${esc(c.label)}</span><span class="${ui("font:tiny text:mist")}">${c.pages} page${c.pages === 1 ? '' : 's'}</span></span>
|
|
138
|
+
<button data-add-component="${esc(c.name)}" aria-label="Add ${esc(c.label)}" class="${ui("bg-color:transparent bd:width-0 cursor:pointer h:d8 pd-x:d3 bd:round-pill font:tiny:semibold text:proof-2 @hover:[bg-color:proof-soft] transition:fast")}">Add</button>
|
|
139
|
+
</div>
|
|
140
|
+
</li>`).join('')}
|
|
141
|
+
</ul>` : ''}`;
|
|
142
|
+
// Each preview is scaled to show the whole block, centred in its frame.
|
|
143
|
+
const fit = () => library.querySelectorAll('[data-frame]').forEach((f) => {
|
|
144
|
+
const frame = f.querySelector('iframe');
|
|
145
|
+
let height = 800;
|
|
146
|
+
try { height = Math.max(200, frame.contentDocument?.body?.scrollHeight || 800); } catch { /* not loaded yet */ }
|
|
147
|
+
const scale = Math.min(f.clientWidth / 1280, f.clientHeight / height);
|
|
148
|
+
frame.style.height = `${height}px`;
|
|
149
|
+
frame.style.transform = `translate(${(f.clientWidth - 1280 * scale) / 2}px, ${(f.clientHeight - height * scale) / 2}px) scale(${scale})`;
|
|
150
|
+
});
|
|
151
|
+
library.querySelectorAll('iframe').forEach((frame) => frame.addEventListener('load', () => setTimeout(fit, 50)));
|
|
152
|
+
new ResizeObserver(fit).observe(library);
|
|
153
|
+
fit();
|
|
154
|
+
library.querySelector('[data-close]').addEventListener('click', closeLibrary);
|
|
155
|
+
// Adding by click: the page's own spots come first, then the slots
|
|
156
|
+
// inside its blocks, and the site's shared header and footer only when
|
|
157
|
+
// nothing else takes the block (it would show on every page).
|
|
158
|
+
const bestSlot = (drag) => {
|
|
159
|
+
const all = slotsFor(drag);
|
|
160
|
+
const shared = (sl) => sl.dataset.versoSlot.startsWith(':site.') || !!sl.parentElement?.closest('[data-verso-slot^=":site."]');
|
|
161
|
+
const own = all.filter((sl) => !shared(sl));
|
|
162
|
+
const top = own.filter((sl) => sl.dataset.versoSlot.startsWith(':'));
|
|
163
|
+
return top[0] || own[0] || all[0];
|
|
164
|
+
};
|
|
165
|
+
// Where in that spot: after the block you're looking at (the last one
|
|
166
|
+
// whose top is above the middle of the screen), not always at the end.
|
|
167
|
+
const placeIn = (slot) => {
|
|
168
|
+
const kids = [...slot.querySelectorAll('[data-verso-block]')].filter((el) => el.parentElement?.closest('[data-verso-slot]') === slot);
|
|
169
|
+
const mid = window.innerHeight / 2;
|
|
170
|
+
let index = 0;
|
|
171
|
+
kids.forEach((el, i) => { if (el.getBoundingClientRect().top < mid) index = i + 1; });
|
|
172
|
+
return index;
|
|
173
|
+
};
|
|
174
|
+
library.querySelectorAll('[data-add]').forEach((b) => b.addEventListener('click', () => {
|
|
175
|
+
const name = b.dataset.add;
|
|
176
|
+
const slot = bestSlot({ kind: 'new', block: name });
|
|
177
|
+
if (!slot) return toast(`There's no spot on this page that takes a ${b.closest('li').querySelector('span').textContent} block.`, 'error');
|
|
178
|
+
// The page is drawn again with the new block; the library stays open,
|
|
179
|
+
// where it was, so several blocks can be added in a row.
|
|
180
|
+
post('insert', { slot: slot.dataset.versoSlot, block: name, index: placeIn(slot) }, () => sessionStorage.setItem('verso-reopen-blocks', String(library.scrollTop)));
|
|
181
|
+
}));
|
|
182
|
+
library.querySelectorAll('[data-block]').forEach((li) => {
|
|
183
|
+
li.addEventListener('dragstart', (e) => startDrag(e, { kind: 'new', block: li.dataset.block }));
|
|
184
|
+
li.addEventListener('dragend', endDrag);
|
|
185
|
+
});
|
|
186
|
+
library.querySelectorAll('[data-add-component]').forEach((b) => b.addEventListener('click', () => {
|
|
187
|
+
const c = components.find((x) => x.name === b.dataset.addComponent);
|
|
188
|
+
const slot = bestSlot({ kind: 'new', component: c.name, blocks: c.blocks });
|
|
189
|
+
if (!slot) return toast(`There's no spot on this page that takes the ${c.label} component.`, 'error');
|
|
190
|
+
post('insert', { slot: slot.dataset.versoSlot, component: c.name, index: placeIn(slot) }, () => sessionStorage.setItem('verso-reopen-blocks', String(library.scrollTop)));
|
|
191
|
+
}));
|
|
192
|
+
library.querySelectorAll('[data-component]').forEach((li) => {
|
|
193
|
+
const c = components.find((x) => x.name === li.dataset.component);
|
|
194
|
+
li.addEventListener('dragstart', (e) => startDrag(e, { kind: 'new', component: c.name, blocks: c.blocks }));
|
|
195
|
+
li.addEventListener('dragend', endDrag);
|
|
196
|
+
});
|
|
197
|
+
library.style.display = 'flex';
|
|
198
|
+
}
|
|
199
|
+
function closeLibrary() { library.style.display = 'none'; }
|
|
200
|
+
|
|
201
|
+
// ════ Dragging ════
|
|
202
|
+
let dragging = null;
|
|
203
|
+
let target = null; // { slot, index, line }
|
|
204
|
+
|
|
205
|
+
const allows = (slot, name) => {
|
|
206
|
+
const list = (slot.dataset.versoAllows || '*').split(' ');
|
|
207
|
+
return list.includes('*') || list.includes(name);
|
|
208
|
+
};
|
|
209
|
+
// Slots on the page that take this block, leaving out ones inside the block being moved.
|
|
210
|
+
const slotsFor = (drag) => [...document.querySelectorAll('[data-verso-slot]')].filter((slot) => {
|
|
211
|
+
if (drag.blocks) {
|
|
212
|
+
if (!drag.blocks.every((b) => allows(slot, b))) return false;
|
|
213
|
+
if (slot.closest('[data-verso-component]')) return false;
|
|
214
|
+
} else if (!allows(slot, drag.block)) return false;
|
|
215
|
+
// Inside a component, blocks only move when its structure is being edited.
|
|
216
|
+
const comp = slot.closest('[data-verso-component]');
|
|
217
|
+
if (comp && !editing.has(comp.dataset.versoComponent)) return false;
|
|
218
|
+
if (drag.kind === 'move') {
|
|
219
|
+
const own = document.querySelector(`[data-verso-block="${CSS.escape(drag.id)}"]`);
|
|
220
|
+
if (own && own.contains(slot)) return false;
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
});
|
|
224
|
+
const childBlocks = (slot) => [...slot.children].filter((c) => c.hasAttribute('data-verso-block'));
|
|
225
|
+
|
|
226
|
+
function startDrag(e, drag) {
|
|
227
|
+
dragging = { ...drag, slots: slotsFor(drag) };
|
|
228
|
+
e.dataTransfer.setData('application/x-verso-block', JSON.stringify(drag));
|
|
229
|
+
e.dataTransfer.effectAllowed = drag.kind === 'new' ? 'copy' : 'move';
|
|
230
|
+
if (drag.kind === 'new') setTimeout(closeLibrary, 0);
|
|
231
|
+
if (!dragging.slots.length) toast('There\'s no spot on this page that takes that block.', 'error');
|
|
232
|
+
setTimeout(() => { handle.style.display = 'none'; hovered = null; draw(); }, 0);
|
|
233
|
+
}
|
|
234
|
+
function endDrag() {
|
|
235
|
+
dragging = null;
|
|
236
|
+
target = null;
|
|
237
|
+
draw();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
document.addEventListener('dragover', (e) => {
|
|
241
|
+
if (!dragging) return;
|
|
242
|
+
let slot = e.target.closest?.('[data-verso-slot]');
|
|
243
|
+
while (slot && !dragging.slots.includes(slot)) slot = slot.parentElement?.closest('[data-verso-slot]');
|
|
244
|
+
if (!slot) {
|
|
245
|
+
if (target) { target = null; draw(); }
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
e.preventDefault();
|
|
249
|
+
e.stopPropagation();
|
|
250
|
+
e.dataTransfer.dropEffect = dragging.kind === 'new' ? 'copy' : 'move';
|
|
251
|
+
const kids = childBlocks(slot);
|
|
252
|
+
let index = kids.findIndex((k) => {
|
|
253
|
+
const r = k.getBoundingClientRect();
|
|
254
|
+
return e.clientY < r.top + r.height / 2;
|
|
255
|
+
});
|
|
256
|
+
if (index === -1) index = kids.length;
|
|
257
|
+
if (!target || target.slot !== slot || target.index !== index) {
|
|
258
|
+
target = { slot, index };
|
|
259
|
+
draw();
|
|
260
|
+
}
|
|
261
|
+
}, true);
|
|
262
|
+
|
|
263
|
+
document.addEventListener('drop', (e) => {
|
|
264
|
+
if (!dragging) return;
|
|
265
|
+
e.preventDefault();
|
|
266
|
+
e.stopPropagation();
|
|
267
|
+
const drag = dragging;
|
|
268
|
+
const at = target;
|
|
269
|
+
endDrag();
|
|
270
|
+
if (!at) return;
|
|
271
|
+
const slot = at.slot.dataset.versoSlot;
|
|
272
|
+
if (drag.kind === 'new' && drag.component) post('insert', { slot, index: at.index, component: drag.component });
|
|
273
|
+
else if (drag.kind === 'new') post('insert', { slot, index: at.index, block: drag.block });
|
|
274
|
+
else post('move', { id: drag.id, slot, index: at.index });
|
|
275
|
+
}, true);
|
|
276
|
+
document.addEventListener('dragend', endDrag, true);
|
|
277
|
+
|
|
278
|
+
// ════ Marks: drop zones and the insertion line ════
|
|
279
|
+
function draw() {
|
|
280
|
+
const parts = [];
|
|
281
|
+
if (dragging) {
|
|
282
|
+
dragging.slots.forEach((slot) => {
|
|
283
|
+
const r = slot.getBoundingClientRect();
|
|
284
|
+
const on = target && target.slot === slot;
|
|
285
|
+
parts.push(`<div class="${on ? ui("absolute bd:width-d0:dashed:proof bd:round-d2 bg-color:proof-soft opacity:0.35") : ui("absolute bd:width-px:dashed:proof bd:round-d2")}" style="left:${r.left - 6}px;top:${r.top - 6}px;width:${r.width + 12}px;height:${Math.max(r.height, 24) + 12}px"></div>`);
|
|
286
|
+
});
|
|
287
|
+
if (target) {
|
|
288
|
+
const r = target.slot.getBoundingClientRect();
|
|
289
|
+
const kids = childBlocks(target.slot);
|
|
290
|
+
let y;
|
|
291
|
+
if (!kids.length) y = r.top + 2;
|
|
292
|
+
else if (target.index < kids.length) y = kids[target.index].getBoundingClientRect().top - 2;
|
|
293
|
+
else y = kids[kids.length - 1].getBoundingClientRect().bottom + 2;
|
|
294
|
+
parts.push(`<div class="${ui("absolute h:d1 bd:round-pill bg-color:proof shadow:proof-ring")}" style="left:${r.left}px;top:${y - 3}px;width:${r.width}px"></div>`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (hovered && !dragging) {
|
|
298
|
+
const r = hovered.getBoundingClientRect();
|
|
299
|
+
parts.push(`<div class="${ui("absolute bd:width-px:dashed:mist bd:round-d2")}" style="left:${r.left - 4}px;top:${r.top - 4}px;width:${r.width + 8}px;height:${r.height + 8}px"></div>`);
|
|
300
|
+
}
|
|
301
|
+
marks.innerHTML = parts.join('');
|
|
302
|
+
}
|
|
303
|
+
addEventListener('scroll', () => { draw(); placeHandle(); }, { passive: true, capture: true });
|
|
304
|
+
addEventListener('resize', () => { draw(); placeHandle(); });
|
|
305
|
+
|
|
306
|
+
// ════ The handle on each block: drag, up, down, copy, remove ════
|
|
307
|
+
let hovered = null;
|
|
308
|
+
let confirmDelete = false;
|
|
309
|
+
const btn = ui("bg-color:transparent bd:width-0 cursor:pointer row:x-center:y-center w:d8 h:d8 bd:round-d2 text:paper @hover:[bg-color:ink-2] @focus-visible:[outline:d0:solid:proof] transition:fast");
|
|
310
|
+
|
|
311
|
+
// What a handle acts on: a plain block, a whole component instance, or (while
|
|
312
|
+
// its structure is being edited) one block inside a component.
|
|
313
|
+
let acting = null; // { id, kind: 'block' | 'component' | 'part', label, blockName }
|
|
314
|
+
const menuItem = ui("bg-color:transparent bd:width-0 cursor:pointer row:y-center gap:d2 pd:d2 bd:round-d2 text:paper font:small text:left @hover:[bg-color:ink-2]");
|
|
315
|
+
function showHandle(found) {
|
|
316
|
+
let block = found;
|
|
317
|
+
const comp = found.closest('[data-verso-component]');
|
|
318
|
+
if (comp && !editing.has(comp.dataset.versoComponent)) {
|
|
319
|
+
// The whole instance: its first top-level element carries the handle.
|
|
320
|
+
block = document.querySelector(`[data-verso-component="${CSS.escape(comp.dataset.versoComponent)}"][data-verso-component-top]`) || comp;
|
|
321
|
+
}
|
|
322
|
+
if (hovered === block && acting) return;
|
|
323
|
+
hovered = block;
|
|
324
|
+
confirmDelete = false;
|
|
325
|
+
const kids = childBlocks(block.parentElement);
|
|
326
|
+
const i = kids.indexOf(block);
|
|
327
|
+
const blockLabel = types.find((t) => t.name === block.dataset.versoBlockName)?.label || block.dataset.versoBlockName;
|
|
328
|
+
const inComp = block.closest('[data-verso-component]');
|
|
329
|
+
if (inComp && !editing.has(inComp.dataset.versoComponent)) {
|
|
330
|
+
acting = { id: inComp.dataset.versoComponent, kind: 'component', label: inComp.dataset.versoComponentName, blockName: block.dataset.versoBlockName };
|
|
331
|
+
} else if (inComp) {
|
|
332
|
+
acting = { id: block.dataset.versoBlock, kind: 'part', label: `${inComp.dataset.versoComponentName} › ${blockLabel}`, blockName: block.dataset.versoBlockName, instance: inComp.dataset.versoComponent };
|
|
333
|
+
} else {
|
|
334
|
+
acting = { id: block.dataset.versoBlock, kind: 'block', label: blockLabel, blockName: block.dataset.versoBlockName };
|
|
335
|
+
}
|
|
336
|
+
const tag = acting.kind === 'component'
|
|
337
|
+
? `<span class="${ui("row:y-center gap:d1 h:d8 pd-x:d2 bd:round-d2 bg-color:proof text:paper font:tiny:semibold")}">${SVG.component}${esc(acting.label)}</span>`
|
|
338
|
+
: acting.kind === 'part'
|
|
339
|
+
? `<span class="${ui("row:y-center gap:d1 h:d8 pd-x:d2 bd:round-d2 bg-color:proof-soft text:proof-2 font:tiny:semibold")}" title="Changes every page that uses this component">${SVG.component}${esc(acting.label)}, all pages</span>`
|
|
340
|
+
: '';
|
|
341
|
+
const grip = acting.kind === 'component'
|
|
342
|
+
? `<span draggable="true" data-grip class="${ui("row:y-center h:d8 pd-x:d1 bd:round-d2 cursor:grab text:paper @hover:[bg-color:ink-2]")}" title="Drag to move">${SVG.grip}</span>`
|
|
343
|
+
: `<span draggable="true" data-grip class="${ui("row:y-center gap:d1 h:d8 pd-x:d2 bd:round-d2 cursor:grab font:tiny:semibold text:paper @hover:[bg-color:ink-2]")}" title="Drag to move">${SVG.grip}${acting.kind === 'block' ? esc(blockLabel) : ''}</span>`;
|
|
344
|
+
const repeater = !!types.find((t) => t.name === acting.blockName)?.repeater;
|
|
345
|
+
// Opens Build a block on this block's design (it changes every use).
|
|
346
|
+
const canChange = acting.kind !== 'component' && !!acting.blockName && !!verso.builder?.open;
|
|
347
|
+
handle.innerHTML = `
|
|
348
|
+
${grip}${tag}
|
|
349
|
+
<button data-act="up" class="${btn}" title="Move up" aria-label="Move up" ${i <= 0 ? 'disabled style="opacity:.35"' : ''}>${SVG.up}</button>
|
|
350
|
+
<button data-act="down" class="${btn}" title="Move down" aria-label="Move down" ${i >= kids.length - 1 ? 'disabled style="opacity:.35"' : ''}>${SVG.down}</button>
|
|
351
|
+
<button data-act="duplicate" class="${btn}" title="Duplicate" aria-label="Duplicate">${SVG.copy}</button>
|
|
352
|
+
<button data-act="remove" class="${btn}" title="Remove (you can undo)" aria-label="Remove">${SVG.trash}</button>
|
|
353
|
+
${acting.kind === 'block' && !repeater ? `<button data-act="save-component" class="${btn}" title="Save as a component" aria-label="Save as a component">${SVG.component}</button>` : ''}
|
|
354
|
+
${canChange || !repeater ? `<button data-act="more" class="${btn}" title="More" aria-label="More" aria-haspopup="menu">${SVG.more}</button>` : ''}
|
|
355
|
+
<div data-more class="${ui("absolute top:full right:0 mg-t:d1 col w:menu pd:d1 bg-color:ink bd:round-d3 shadow:float")}" style="display:none" role="menu">
|
|
356
|
+
${canChange ? `<button data-act="change-block" class="${menuItem}" role="menuitem">${SVG.cube}Change this block</button>` : ''}
|
|
357
|
+
${acting.kind === 'block' && !repeater ? `<button data-act="save-component" class="${menuItem}" role="menuitem">${SVG.component}Save as a component…</button>` : ''}
|
|
358
|
+
${acting.kind === 'component' ? `
|
|
359
|
+
<button data-act="structure" class="${menuItem}" role="menuitem">Edit structure for all pages</button>
|
|
360
|
+
<button data-act="lock" class="${menuItem}" role="menuitem">Lock fields…</button>
|
|
361
|
+
<button data-act="detach" class="${menuItem}" role="menuitem">Detach from component</button>` : ''}
|
|
362
|
+
${acting.kind === 'part' ? `<button data-act="done-structure" class="${menuItem}" role="menuitem">Done editing structure</button>` : ''}
|
|
363
|
+
</div>`;
|
|
364
|
+
handle.style.display = 'flex';
|
|
365
|
+
placeHandle();
|
|
366
|
+
draw();
|
|
367
|
+
}
|
|
368
|
+
function hideHandle() {
|
|
369
|
+
hovered = null;
|
|
370
|
+
acting = null;
|
|
371
|
+
handle.style.display = 'none';
|
|
372
|
+
draw();
|
|
373
|
+
}
|
|
374
|
+
function placeHandle() {
|
|
375
|
+
if (!hovered) return;
|
|
376
|
+
const r = hovered.getBoundingClientRect();
|
|
377
|
+
const w = handle.offsetWidth;
|
|
378
|
+
handle.style.left = `${Math.max(8, Math.min(r.right - w - 8, innerWidth - w - 8))}px`;
|
|
379
|
+
handle.style.top = `${Math.max(8, Math.min(r.top + 8, r.bottom - 48))}px`;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
document.addEventListener('mousemove', (e) => {
|
|
383
|
+
if (dragging || handle.querySelector('[data-more]')?.style.display === 'flex') return;
|
|
384
|
+
const block = e.target.closest?.('[data-verso-block]');
|
|
385
|
+
if (block) showHandle(block);
|
|
386
|
+
}, { passive: true });
|
|
387
|
+
document.addEventListener('mouseleave', () => { if (!dragging) hideHandle(); });
|
|
388
|
+
|
|
389
|
+
handle.addEventListener('click', (e) => {
|
|
390
|
+
const b = e.target.closest('[data-act]');
|
|
391
|
+
if (!b || !hovered || b.disabled || !acting) return;
|
|
392
|
+
const { id } = acting;
|
|
393
|
+
const act = b.dataset.act;
|
|
394
|
+
const more = handle.querySelector('[data-more]');
|
|
395
|
+
if (act === 'more') { more.style.display = more.style.display === 'flex' ? 'none' : 'flex'; return; }
|
|
396
|
+
more.style.display = 'none';
|
|
397
|
+
if (act === 'save-component') return verso.components?.saveAs(id, acting.label);
|
|
398
|
+
if (act === 'change-block') { const name = acting.blockName; hideHandle(); return verso.builder?.open(name); }
|
|
399
|
+
if (act === 'lock') return verso.components?.lockPanel(id);
|
|
400
|
+
if (act === 'detach') return verso.components?.detach(id);
|
|
401
|
+
if (act === 'structure') { editing.add(id); remember(); const what = acting.label; hideHandle(); toast(`Editing the ${what} component's structure. Moves, copies and removals inside it change every page that uses it.`, 'ok'); return; }
|
|
402
|
+
if (act === 'done-structure') { editing.delete(acting.instance); remember(); hideHandle(); return; }
|
|
403
|
+
if (act === 'up' || act === 'down') post('step', { id, by: act === 'up' ? -1 : 1 });
|
|
404
|
+
else if (act === 'duplicate') post('duplicate', { id });
|
|
405
|
+
else if (act === 'remove') {
|
|
406
|
+
// One click removes it; the Undo bar (and Cmd/Ctrl+Z) puts it back.
|
|
407
|
+
const label = acting.label;
|
|
408
|
+
post('remove', { id }, (out) => {
|
|
409
|
+
if (out.restore) sessionStorage.setItem('verso-undo-remove', JSON.stringify({ url: data.url, at: Date.now(), label: out.component ? `${out.removed} from ${out.component}` : (out.removed || label), restore: out.restore }));
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
handle.addEventListener('dragstart', (e) => {
|
|
414
|
+
const grip = e.target.closest?.('[data-grip]');
|
|
415
|
+
if (!grip || !hovered) return;
|
|
416
|
+
if (acting?.kind === 'component') {
|
|
417
|
+
const c = components.find((x) => x.label === acting.label);
|
|
418
|
+
startDrag(e, { kind: 'move', id: acting.id, block: acting.blockName, blocks: c ? c.blocks : [acting.blockName] });
|
|
419
|
+
} else startDrag(e, { kind: 'move', id: acting.id, block: acting.blockName });
|
|
420
|
+
});
|
|
421
|
+
handle.addEventListener('dragend', endDrag);
|
|
422
|
+
}
|