@veroxm/react-sdk 0.0.0-stage → 0.1.1
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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +295 -2
- package/dist/cache.d.ts +69 -0
- package/dist/cache.js +89 -0
- package/dist/client-slots.d.ts +35 -0
- package/dist/client-slots.js +169 -0
- package/dist/client.d.ts +65 -0
- package/dist/client.js +87 -0
- package/dist/editor/constants.d.ts +12 -0
- package/dist/editor/constants.js +12 -0
- package/dist/editor/handler.d.ts +16 -0
- package/dist/editor/handler.js +175 -0
- package/dist/editor/inline.d.ts +25 -0
- package/dist/editor/inline.js +149 -0
- package/dist/editor/menu-input.d.ts +26 -0
- package/dist/editor/menu-input.js +110 -0
- package/dist/editor/overlay.d.ts +31 -0
- package/dist/editor/overlay.js +856 -0
- package/dist/editor/rich-text.d.ts +21 -0
- package/dist/editor/rich-text.js +232 -0
- package/dist/editor/server.d.ts +9 -0
- package/dist/editor/server.js +43 -0
- package/dist/errors.d.ts +20 -0
- package/dist/errors.js +26 -0
- package/dist/hooks/use-cached-query.d.ts +21 -0
- package/dist/hooks/use-cached-query.js +59 -0
- package/dist/hooks/use-collection.d.ts +10 -0
- package/dist/hooks/use-collection.js +14 -0
- package/dist/hooks/use-entries.d.ts +18 -0
- package/dist/hooks/use-entries.js +25 -0
- package/dist/hooks/use-entry.d.ts +21 -0
- package/dist/hooks/use-entry.js +22 -0
- package/dist/hooks/use-media.d.ts +9 -0
- package/dist/hooks/use-media.js +13 -0
- package/dist/hydration-boundary.d.ts +35 -0
- package/dist/hydration-boundary.js +38 -0
- package/dist/image.d.ts +34 -0
- package/dist/image.js +39 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +32 -0
- package/dist/next/cache-components.d.ts +15 -0
- package/dist/next/cache-components.js +25 -0
- package/dist/next/cached.d.ts +9 -0
- package/dist/next/cached.js +20 -0
- package/dist/next/edge-slot.d.ts +21 -0
- package/dist/next/edge-slot.js +29 -0
- package/dist/next/editor.d.ts +7 -0
- package/dist/next/editor.js +13 -0
- package/dist/next/index.d.ts +17 -0
- package/dist/next/index.js +21 -0
- package/dist/next/llms.d.ts +2 -0
- package/dist/next/llms.js +44 -0
- package/dist/next/route.d.ts +12 -0
- package/dist/next/route.js +16 -0
- package/dist/next/slot.d.ts +21 -0
- package/dist/next/slot.js +160 -0
- package/dist/node.d.ts +43 -0
- package/dist/node.js +67 -0
- package/dist/preview.d.ts +35 -0
- package/dist/preview.js +46 -0
- package/dist/provider.d.ts +29 -0
- package/dist/provider.js +37 -0
- package/dist/query-keys.d.ts +19 -0
- package/dist/query-keys.js +49 -0
- package/dist/site/chart-view.d.ts +14 -0
- package/dist/site/chart-view.js +44 -0
- package/dist/site/chart.d.ts +127 -0
- package/dist/site/chart.js +639 -0
- package/dist/site/map-embed.d.ts +32 -0
- package/dist/site/map-embed.js +139 -0
- package/dist/site/map-math.d.ts +27 -0
- package/dist/site/map-math.js +89 -0
- package/dist/site/nav-menu.d.ts +19 -0
- package/dist/site/nav-menu.js +76 -0
- package/dist/site/site-parts.d.ts +87 -0
- package/dist/site/site-parts.js +46 -0
- package/dist/site/slider.d.ts +17 -0
- package/dist/site/slider.js +78 -0
- package/dist/site/styles.d.ts +3 -0
- package/dist/site/styles.js +155 -0
- package/dist/site/video-embed.d.ts +15 -0
- package/dist/site/video-embed.js +27 -0
- package/dist/site/video.d.ts +18 -0
- package/dist/site/video.js +73 -0
- package/dist/slots-core.d.ts +397 -0
- package/dist/slots-core.js +367 -0
- package/dist/slots.d.ts +13 -0
- package/dist/slots.js +30 -0
- package/dist/ssr.d.ts +20 -0
- package/dist/ssr.js +35 -0
- package/dist/structured-data.d.ts +13 -0
- package/dist/structured-data.js +36 -0
- package/dist/tracking.d.ts +142 -0
- package/dist/tracking.js +152 -0
- package/dist/types.d.ts +106 -0
- package/dist/types.js +6 -0
- package/package.json +95 -4
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Typing straight into the page for plain-text slot fields (field.text()).
|
|
2
|
+
//
|
|
3
|
+
// The element the site marked with {...slot.edit("title")} becomes
|
|
4
|
+
// editable in place. Rules that keep this safe on any React site:
|
|
5
|
+
//
|
|
6
|
+
// - Only an element whose whole content is one text node: if the field
|
|
7
|
+
// shares the element with other text or markup (another field, an icon),
|
|
8
|
+
// editing its textContent could swallow them, so the side panel is used
|
|
9
|
+
// instead. Put slot.edit() on an element that holds just that text.
|
|
10
|
+
// - React owns that text node. However the browser edits it, the element
|
|
11
|
+
// ends up holding that same node again, with the new text, before React
|
|
12
|
+
// re-renders -- so React's next update finds the node it expects.
|
|
13
|
+
// - One line, plain text: Enter saves, Escape restores the original,
|
|
14
|
+
// leaving the element (blur) saves. A field's max length is enforced as
|
|
15
|
+
// you type.
|
|
16
|
+
/** Whether an element can be edited in place: a single text node, nothing nested, not inside a button. */
|
|
17
|
+
export function canEditInline(el) {
|
|
18
|
+
if (!el || !(el instanceof HTMLElement))
|
|
19
|
+
return false;
|
|
20
|
+
if (el.childNodes.length !== 1 || el.firstChild?.nodeType !== Node.TEXT_NODE)
|
|
21
|
+
return false;
|
|
22
|
+
if (el.closest('button, select, textarea, input, [contenteditable="true"], [contenteditable="plaintext-only"]'))
|
|
23
|
+
return false;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
function plainText(el) {
|
|
27
|
+
return (el.textContent ?? '').replace(/[\r\n]+/g, ' ');
|
|
28
|
+
}
|
|
29
|
+
export function startInlineEdit(el, opts) {
|
|
30
|
+
const node = el.firstChild;
|
|
31
|
+
const original = node.nodeValue ?? '';
|
|
32
|
+
let finished = false;
|
|
33
|
+
const prev = {
|
|
34
|
+
contenteditable: el.getAttribute('contenteditable'),
|
|
35
|
+
role: el.getAttribute('role'),
|
|
36
|
+
ariaLabel: el.getAttribute('aria-label'),
|
|
37
|
+
spellcheck: el.getAttribute('spellcheck'),
|
|
38
|
+
};
|
|
39
|
+
el.setAttribute('contenteditable', 'plaintext-only');
|
|
40
|
+
// Older browsers without plaintext-only: rich mode, with paste and input cleaned up below.
|
|
41
|
+
const plainOnly = el.contentEditable === 'plaintext-only';
|
|
42
|
+
if (!plainOnly)
|
|
43
|
+
el.setAttribute('contenteditable', 'true');
|
|
44
|
+
el.setAttribute('role', 'textbox');
|
|
45
|
+
el.setAttribute('aria-label', `${opts.label} (editing – Enter to save, Escape to cancel)`);
|
|
46
|
+
el.setAttribute('spellcheck', 'true');
|
|
47
|
+
el.setAttribute('data-veroxm-inline', '');
|
|
48
|
+
el.focus({ preventScroll: true });
|
|
49
|
+
placeCaret(el, opts.point);
|
|
50
|
+
const onBeforeInput = (e) => {
|
|
51
|
+
if (e.inputType === 'insertParagraph' || e.inputType === 'insertLineBreak') {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (opts.max === undefined || !e.inputType.startsWith('insert'))
|
|
56
|
+
return;
|
|
57
|
+
const incoming = (e.data ?? e.dataTransfer?.getData('text/plain') ?? '').replace(/[\r\n]+/g, ' ');
|
|
58
|
+
const sel = document.getSelection();
|
|
59
|
+
const selected = sel && el.contains(sel.anchorNode) ? sel.toString().length : 0;
|
|
60
|
+
if (plainText(el).length - selected + incoming.length > opts.max)
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
};
|
|
63
|
+
const onInput = () => opts.onInput(clamp(plainText(el)));
|
|
64
|
+
const onKeyDown = (e) => {
|
|
65
|
+
if (e.key === 'Enter') {
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
finish(true);
|
|
68
|
+
}
|
|
69
|
+
else if (e.key === 'Escape') {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
finish(false);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const onBlur = () => finish(true);
|
|
76
|
+
const onPaste = (e) => {
|
|
77
|
+
if (plainOnly)
|
|
78
|
+
return;
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
const text = (e.clipboardData?.getData('text/plain') ?? '').replace(/[\r\n]+/g, ' ');
|
|
81
|
+
document.execCommand?.('insertText', false, text);
|
|
82
|
+
};
|
|
83
|
+
el.addEventListener('beforeinput', onBeforeInput);
|
|
84
|
+
el.addEventListener('input', onInput);
|
|
85
|
+
el.addEventListener('keydown', onKeyDown);
|
|
86
|
+
el.addEventListener('blur', onBlur);
|
|
87
|
+
el.addEventListener('paste', onPaste);
|
|
88
|
+
function clamp(text) {
|
|
89
|
+
return opts.max !== undefined ? text.slice(0, opts.max) : text;
|
|
90
|
+
}
|
|
91
|
+
function finish(commit) {
|
|
92
|
+
if (finished)
|
|
93
|
+
return;
|
|
94
|
+
finished = true;
|
|
95
|
+
el.removeEventListener('beforeinput', onBeforeInput);
|
|
96
|
+
el.removeEventListener('input', onInput);
|
|
97
|
+
el.removeEventListener('keydown', onKeyDown);
|
|
98
|
+
el.removeEventListener('blur', onBlur);
|
|
99
|
+
el.removeEventListener('paste', onPaste);
|
|
100
|
+
const text = commit ? clamp(plainText(el)) : original;
|
|
101
|
+
// Hand React back exactly the node it rendered, holding the final text.
|
|
102
|
+
node.nodeValue = text;
|
|
103
|
+
el.replaceChildren(node);
|
|
104
|
+
restore('contenteditable', prev.contenteditable);
|
|
105
|
+
restore('role', prev.role);
|
|
106
|
+
restore('aria-label', prev.ariaLabel);
|
|
107
|
+
restore('spellcheck', prev.spellcheck);
|
|
108
|
+
el.removeAttribute('data-veroxm-inline');
|
|
109
|
+
if (document.activeElement === el)
|
|
110
|
+
el.blur();
|
|
111
|
+
opts.onEnd({ committed: commit, text });
|
|
112
|
+
}
|
|
113
|
+
function restore(name, value) {
|
|
114
|
+
if (value === null)
|
|
115
|
+
el.removeAttribute(name);
|
|
116
|
+
else
|
|
117
|
+
el.setAttribute(name, value);
|
|
118
|
+
}
|
|
119
|
+
return { end: finish };
|
|
120
|
+
}
|
|
121
|
+
function placeCaret(el, point) {
|
|
122
|
+
const sel = document.getSelection();
|
|
123
|
+
if (!sel)
|
|
124
|
+
return;
|
|
125
|
+
let range = null;
|
|
126
|
+
const doc = document;
|
|
127
|
+
if (point) {
|
|
128
|
+
if (doc.caretPositionFromPoint) {
|
|
129
|
+
const pos = doc.caretPositionFromPoint(point.x, point.y);
|
|
130
|
+
if (pos && el.contains(pos.offsetNode)) {
|
|
131
|
+
range = document.createRange();
|
|
132
|
+
range.setStart(pos.offsetNode, pos.offset);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (doc.caretRangeFromPoint) {
|
|
136
|
+
const r = doc.caretRangeFromPoint(point.x, point.y);
|
|
137
|
+
if (r && el.contains(r.startContainer))
|
|
138
|
+
range = r;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!range) {
|
|
142
|
+
range = document.createRange();
|
|
143
|
+
range.selectNodeContents(el);
|
|
144
|
+
range.collapse(false);
|
|
145
|
+
}
|
|
146
|
+
range.collapse(true);
|
|
147
|
+
sel.removeAllRanges();
|
|
148
|
+
sel.addRange(range);
|
|
149
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SlotMenuItem } from '../slots-core.js';
|
|
2
|
+
export declare const MAX_MENU_ITEMS = 100;
|
|
3
|
+
type Path = number[];
|
|
4
|
+
export declare function countItems(items: SlotMenuItem[]): number;
|
|
5
|
+
/** The tree operations, pure (exported for tests). */
|
|
6
|
+
export declare const menuOps: {
|
|
7
|
+
add: (items: SlotMenuItem[], parent: Path) => SlotMenuItem[];
|
|
8
|
+
update: (items: SlotMenuItem[], path: Path, change: Partial<SlotMenuItem>) => SlotMenuItem[];
|
|
9
|
+
remove: (items: SlotMenuItem[], path: Path) => SlotMenuItem[];
|
|
10
|
+
move: (items: SlotMenuItem[], path: Path, by: -1 | 1) => SlotMenuItem[];
|
|
11
|
+
/** Becomes the last sub-item of the item above. */
|
|
12
|
+
indent: (items: SlotMenuItem[], path: Path) => SlotMenuItem[];
|
|
13
|
+
/** Becomes the next item after its parent, one level up. */
|
|
14
|
+
outdent: (items: SlotMenuItem[], path: Path) => SlotMenuItem[];
|
|
15
|
+
};
|
|
16
|
+
export declare function MenuInput({ name, label, required, depth, value, onChange, onFocus, }: {
|
|
17
|
+
name: string;
|
|
18
|
+
label: string;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
depth: number;
|
|
21
|
+
value: unknown;
|
|
22
|
+
onChange(v: SlotMenuItem[] | null): void;
|
|
23
|
+
onFocus(): void;
|
|
24
|
+
}): import("react").JSX.Element;
|
|
25
|
+
export declare const MENU_STYLES = "\n.vx-menu-list{list-style:none;margin:4px 0 0;padding:0;display:flex;flex-direction:column;gap:6px}\n.vx-menu-sub{margin-left:10px;padding-left:10px;border-left:2px solid #e4e4e7}\n.vx-menu-item{display:flex;flex-direction:column;gap:4px}\n.vx-menu-row{display:grid;grid-template-columns:1fr 1fr;gap:4px}\n.vx-menu-row input{width:100%;padding:6px 8px;border:1px solid #d4d4d8;border-radius:8px;background:#fff;min-width:0}\n.vx-menu-tools{display:flex;flex-wrap:wrap;gap:4px;align-items:center}\n.vx-menu-tab{display:flex;align-items:center;gap:4px;font-size:12px;color:#52525b;margin-right:auto}\n.vx-slide-card{border:1px solid #e4e4e7;border-radius:10px;padding:8px;display:flex;flex-direction:column;gap:4px;margin:4px 0 6px}\n.vx-slide-card .vx-field{margin:0}\n.vx-result{appearance:none;display:block;width:100%;text-align:left;border:0;background:transparent;padding:6px;border-radius:6px;cursor:pointer;font-size:13px}\n.vx-result:hover{background:#f4f4f5}\n.vx-mini{appearance:none;cursor:pointer;border:1px solid #e4e4e7;background:#fff;border-radius:6px;min-width:26px;height:24px;padding:0 6px;font-size:12px}\n.vx-mini:disabled{opacity:.4;cursor:not-allowed}\n@media (prefers-color-scheme: dark){\n.vx-menu-sub,.vx-slide-card{border-color:#3f3f46}\n.vx-menu-row input{background:#09090b;border-color:#3f3f46}\n.vx-menu-tab{color:#a1a1aa}\n.vx-mini{background:#27272a;border-color:#3f3f46}\n}\n";
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
// A menu field in the on-page editor: the same tree as the dashboard's,
|
|
4
|
+
// compact enough for the side panel. Each item has a label, a link and
|
|
5
|
+
// "new tab"; items move up and down, in under the item above, and out a
|
|
6
|
+
// level. An item with sub-items may have no link: it just opens them.
|
|
7
|
+
export const MAX_MENU_ITEMS = 100;
|
|
8
|
+
export function countItems(items) {
|
|
9
|
+
return items.reduce((n, i) => n + 1 + countItems(i.children ?? []), 0);
|
|
10
|
+
}
|
|
11
|
+
function depthOf(item) {
|
|
12
|
+
return 1 + Math.max(0, ...(item.children ?? []).map(depthOf));
|
|
13
|
+
}
|
|
14
|
+
/** A copy of the tree with the list under `parent` changed. */
|
|
15
|
+
function withList(items, parent, change) {
|
|
16
|
+
if (!parent.length)
|
|
17
|
+
return change(items);
|
|
18
|
+
const [i, ...rest] = parent;
|
|
19
|
+
return items.map((item, j) => {
|
|
20
|
+
if (j !== i)
|
|
21
|
+
return item;
|
|
22
|
+
const children = withList(item.children ?? [], rest, change);
|
|
23
|
+
// An item whose last sub-item left has no sub-menu any more.
|
|
24
|
+
if (children.length)
|
|
25
|
+
return { ...item, children };
|
|
26
|
+
const { children: _gone, ...rest2 } = item;
|
|
27
|
+
return rest2;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function at(items, path) {
|
|
31
|
+
let list = items;
|
|
32
|
+
let item;
|
|
33
|
+
for (const i of path) {
|
|
34
|
+
item = list[i];
|
|
35
|
+
list = item?.children ?? [];
|
|
36
|
+
}
|
|
37
|
+
return item;
|
|
38
|
+
}
|
|
39
|
+
const last = (path) => path[path.length - 1];
|
|
40
|
+
/** The tree operations, pure (exported for tests). */
|
|
41
|
+
export const menuOps = {
|
|
42
|
+
add: (items, parent) => (countItems(items) >= MAX_MENU_ITEMS ? items : withList(items, parent, (l) => [...l, { label: '', href: '' }])),
|
|
43
|
+
update: (items, path, change) => withList(items, path.slice(0, -1), (l) => l.map((item, j) => (j === last(path) ? { ...item, ...change } : item))),
|
|
44
|
+
remove: (items, path) => withList(items, path.slice(0, -1), (l) => l.filter((_, j) => j !== last(path))),
|
|
45
|
+
move: (items, path, by) => withList(items, path.slice(0, -1), (l) => {
|
|
46
|
+
const i = last(path);
|
|
47
|
+
const to = i + by;
|
|
48
|
+
if (to < 0 || to >= l.length)
|
|
49
|
+
return l;
|
|
50
|
+
const next = [...l];
|
|
51
|
+
[next[i], next[to]] = [next[to], next[i]];
|
|
52
|
+
return next;
|
|
53
|
+
}),
|
|
54
|
+
/** Becomes the last sub-item of the item above. */
|
|
55
|
+
indent: (items, path) => {
|
|
56
|
+
const i = last(path);
|
|
57
|
+
if (i === 0)
|
|
58
|
+
return items;
|
|
59
|
+
const parent = path.slice(0, -1);
|
|
60
|
+
const item = at(items, path);
|
|
61
|
+
const removed = withList(items, parent, (l) => l.filter((_, j) => j !== i));
|
|
62
|
+
return withList(removed, [...parent, i - 1], (l) => [...l, item]);
|
|
63
|
+
},
|
|
64
|
+
/** Becomes the next item after its parent, one level up. */
|
|
65
|
+
outdent: (items, path) => {
|
|
66
|
+
if (path.length < 2)
|
|
67
|
+
return items;
|
|
68
|
+
const parent = path.slice(0, -1);
|
|
69
|
+
const grand = parent.slice(0, -1);
|
|
70
|
+
const p = last(parent);
|
|
71
|
+
const item = at(items, path);
|
|
72
|
+
const removed = withList(items, parent, (l) => l.filter((_, j) => j !== last(path)));
|
|
73
|
+
return withList(removed, grand, (l) => [...l.slice(0, p + 1), item, ...l.slice(p + 1)]);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
export function MenuInput({ name, label, required, depth, value, onChange, onFocus, }) {
|
|
77
|
+
const id = useId();
|
|
78
|
+
const items = Array.isArray(value) ? value : [];
|
|
79
|
+
const total = countItems(items);
|
|
80
|
+
const set = (next) => onChange(next.length ? next : null);
|
|
81
|
+
const rows = (list, parent) => list.map((item, i) => {
|
|
82
|
+
const path = [...parent, i];
|
|
83
|
+
const level = path.length;
|
|
84
|
+
const title = item.label.trim() || `item ${i + 1}`;
|
|
85
|
+
const canIndent = i > 0 && level + depthOf(item) <= depth;
|
|
86
|
+
return (_jsxs("li", { className: "vx-menu-item", children: [_jsxs("div", { className: "vx-menu-row", children: [_jsx("input", { type: "text", "data-field": level === 1 && i === 0 ? name : undefined, onFocus: onFocus, value: item.label, maxLength: 80, placeholder: "Label", "aria-label": `Label of ${title}`, onChange: (e) => set(menuOps.update(items, path, { label: e.target.value })) }), _jsx("input", { type: "text", inputMode: "url", onFocus: onFocus, value: item.href, placeholder: item.children?.length ? 'Link (optional)' : '/page or https://…', "aria-label": `Link of ${title}`, onChange: (e) => set(menuOps.update(items, path, { href: e.target.value })) })] }), _jsxs("div", { className: "vx-menu-tools", children: [_jsxs("label", { className: "vx-menu-tab", children: [_jsx("input", { type: "checkbox", checked: !!item.newTab, onChange: (e) => set(menuOps.update(items, path, { newTab: e.target.checked || undefined })) }), "New tab"] }), _jsx("button", { type: "button", className: "vx-mini", disabled: i === 0, "aria-label": `Move ${title} up`, onClick: () => set(menuOps.move(items, path, -1)), children: "\u2191" }), _jsx("button", { type: "button", className: "vx-mini", disabled: i === list.length - 1, "aria-label": `Move ${title} down`, onClick: () => set(menuOps.move(items, path, 1)), children: "\u2193" }), depth > 1 ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "vx-mini", disabled: level === 1, "aria-label": `Move ${title} out a level`, onClick: () => set(menuOps.outdent(items, path)), children: "\u2190" }), _jsx("button", { type: "button", className: "vx-mini", disabled: !canIndent, "aria-label": `Move ${title} under the item above`, onClick: () => set(menuOps.indent(items, path)), children: "\u2192" })] })) : null, level < depth ? (_jsx("button", { type: "button", className: "vx-mini", disabled: total >= MAX_MENU_ITEMS, "aria-label": `Add a sub-item under ${title}`, onClick: () => set(menuOps.add(items, path)), children: "+ Sub" })) : null, _jsx("button", { type: "button", className: "vx-mini", "aria-label": `Remove ${title}${item.children?.length ? ' and its sub-items' : ''}`, onClick: () => set(menuOps.remove(items, path)), children: "Remove" })] }), item.children?.length ? _jsx("ul", { className: "vx-menu-list vx-menu-sub", children: rows(item.children, path) }) : null] }, path.join('-')));
|
|
87
|
+
});
|
|
88
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", "aria-describedby": `${id}-count`, children: [_jsxs("legend", { className: "vx-label", children: [label, required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsxs("span", { id: `${id}-count`, className: "vx-count", children: [total, " / ", MAX_MENU_ITEMS, " items \u00B7 ", depth === 1 ? 'one level' : `up to ${depth} levels`] }), items.length ? _jsx("ul", { className: "vx-menu-list", children: rows(items, []) }) : _jsx("p", { className: "vx-muted", children: "No items yet: the site shows its own menu." }), _jsx("div", { className: "vx-actions", children: _jsx("button", { type: "button", className: "vx-btn", "data-field": items.length ? undefined : name, onFocus: onFocus, disabled: total >= MAX_MENU_ITEMS, onClick: () => set(menuOps.add(items, [])), children: "Add item" }) })] }));
|
|
89
|
+
}
|
|
90
|
+
export const MENU_STYLES = `
|
|
91
|
+
.vx-menu-list{list-style:none;margin:4px 0 0;padding:0;display:flex;flex-direction:column;gap:6px}
|
|
92
|
+
.vx-menu-sub{margin-left:10px;padding-left:10px;border-left:2px solid #e4e4e7}
|
|
93
|
+
.vx-menu-item{display:flex;flex-direction:column;gap:4px}
|
|
94
|
+
.vx-menu-row{display:grid;grid-template-columns:1fr 1fr;gap:4px}
|
|
95
|
+
.vx-menu-row input{width:100%;padding:6px 8px;border:1px solid #d4d4d8;border-radius:8px;background:#fff;min-width:0}
|
|
96
|
+
.vx-menu-tools{display:flex;flex-wrap:wrap;gap:4px;align-items:center}
|
|
97
|
+
.vx-menu-tab{display:flex;align-items:center;gap:4px;font-size:12px;color:#52525b;margin-right:auto}
|
|
98
|
+
.vx-slide-card{border:1px solid #e4e4e7;border-radius:10px;padding:8px;display:flex;flex-direction:column;gap:4px;margin:4px 0 6px}
|
|
99
|
+
.vx-slide-card .vx-field{margin:0}
|
|
100
|
+
.vx-result{appearance:none;display:block;width:100%;text-align:left;border:0;background:transparent;padding:6px;border-radius:6px;cursor:pointer;font-size:13px}
|
|
101
|
+
.vx-result:hover{background:#f4f4f5}
|
|
102
|
+
.vx-mini{appearance:none;cursor:pointer;border:1px solid #e4e4e7;background:#fff;border-radius:6px;min-width:26px;height:24px;padding:0 6px;font-size:12px}
|
|
103
|
+
.vx-mini:disabled{opacity:.4;cursor:not-allowed}
|
|
104
|
+
@media (prefers-color-scheme: dark){
|
|
105
|
+
.vx-menu-sub,.vx-slide-card{border-color:#3f3f46}
|
|
106
|
+
.vx-menu-row input{background:#09090b;border-color:#3f3f46}
|
|
107
|
+
.vx-menu-tab{color:#a1a1aa}
|
|
108
|
+
.vx-mini{background:#27272a;border-color:#3f3f46}
|
|
109
|
+
}
|
|
110
|
+
`;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* How the overlay reaches VeroXM. By default through this site's own
|
|
4
|
+
* /api/veroxm route (which holds the editor token in an httpOnly cookie);
|
|
5
|
+
* the script tag, on sites with no server of their own, calls VeroXM's
|
|
6
|
+
* editor API directly with the token instead.
|
|
7
|
+
*/
|
|
8
|
+
export interface EditorTransport {
|
|
9
|
+
/** `path` is relative to the editor API, e.g. "slots?names=a" or "slots/a/publish". */
|
|
10
|
+
request(path: string, init: {
|
|
11
|
+
method: string;
|
|
12
|
+
body?: unknown;
|
|
13
|
+
}): Promise<Response>;
|
|
14
|
+
/** Leave editing. */
|
|
15
|
+
exit(): void;
|
|
16
|
+
}
|
|
17
|
+
/** Replaces how the overlay reaches VeroXM (the script tag uses this). */
|
|
18
|
+
export declare function configureEditorTransport(next: EditorTransport): void;
|
|
19
|
+
/** Test helper: forgets which fallbacks were sent. */
|
|
20
|
+
export declare function resetSentFallbacksForTests(): void;
|
|
21
|
+
export interface EditorOverlayProps {
|
|
22
|
+
/** Called after a draft is saved, published or discarded, so the page can re-render with it. */
|
|
23
|
+
onChange(): void;
|
|
24
|
+
/** Extra toolbar controls (the script tag's "Add a slot"). */
|
|
25
|
+
tools?: ReactNode;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The editor overlay. Each <VeroxmSlot> renders one while editing; only the
|
|
29
|
+
* first mounted actually draws, so a page gets exactly one.
|
|
30
|
+
*/
|
|
31
|
+
export declare function VeroxmEditorOverlay({ onChange, tools }: EditorOverlayProps): ReactNode;
|