@veroxm/react-sdk 0.0.0-stage → 0.1.0
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 +5 -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,856 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { EDITOR_HEADER, PREVIEW_COOKIE, ROUTE_BASE } from './constants.js';
|
|
6
|
+
import { RICH_TEXT_STYLES, RichTextInput } from './rich-text.js';
|
|
7
|
+
import { MENU_STYLES, MenuInput } from './menu-input.js';
|
|
8
|
+
import { parseVideoUrl } from '../site/video.js';
|
|
9
|
+
import { parseMapLink } from '../site/map-math.js';
|
|
10
|
+
import { CHART_KINDS, chartTableText, parseChartTable } from '../site/chart.js';
|
|
11
|
+
import { canEditInline, startInlineEdit } from './inline.js';
|
|
12
|
+
const TEST_STATUS = {
|
|
13
|
+
draft: 'Test draft',
|
|
14
|
+
pending_approval: 'Test waiting for approval',
|
|
15
|
+
live: 'Test running',
|
|
16
|
+
paused: 'Test paused',
|
|
17
|
+
};
|
|
18
|
+
function setPreviewCookie(value) {
|
|
19
|
+
document.cookie = value
|
|
20
|
+
? `${PREVIEW_COOKIE}=${encodeURIComponent(value)}; Path=/; SameSite=Lax`
|
|
21
|
+
: `${PREVIEW_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
22
|
+
}
|
|
23
|
+
const OUTCOME_NOTICE = {
|
|
24
|
+
published: 'Published. Visitors see this now.',
|
|
25
|
+
submitted: 'Sent for approval. Nothing changes for visitors until it is approved.',
|
|
26
|
+
approved: 'Approved. It moves to the next step.',
|
|
27
|
+
rejected: 'Rejected. The author can change it and send it again.',
|
|
28
|
+
withdrawn: 'Request withdrawn. Your draft is unchanged.',
|
|
29
|
+
};
|
|
30
|
+
class EditorError extends Error {
|
|
31
|
+
constructor(status, problems) {
|
|
32
|
+
super(problems.join(' '));
|
|
33
|
+
this.status = status;
|
|
34
|
+
this.problems = problems;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const routeTransport = {
|
|
38
|
+
request: (path, init) => fetch(`${ROUTE_BASE}/${path}`, {
|
|
39
|
+
method: init.method,
|
|
40
|
+
credentials: 'same-origin',
|
|
41
|
+
cache: 'no-store',
|
|
42
|
+
headers: { [EDITOR_HEADER]: '1', ...(init.body !== undefined ? { 'Content-Type': 'application/json' } : {}) },
|
|
43
|
+
body: init.body !== undefined ? JSON.stringify(init.body) : undefined,
|
|
44
|
+
}),
|
|
45
|
+
exit: () => location.assign(`${ROUTE_BASE}/exit?path=${encodeURIComponent(location.pathname + location.search)}`),
|
|
46
|
+
};
|
|
47
|
+
let transport = routeTransport;
|
|
48
|
+
/** Replaces how the overlay reaches VeroXM (the script tag uses this). */
|
|
49
|
+
export function configureEditorTransport(next) {
|
|
50
|
+
transport = next;
|
|
51
|
+
}
|
|
52
|
+
async function call(path, init = {}) {
|
|
53
|
+
const res = await transport.request(path, { method: init.method ?? 'GET', body: init.body });
|
|
54
|
+
const body = (await res.json().catch(() => ({})));
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
const problems = body.errors ?? (body.error ? [body.error] : Array.isArray(body.message) ? body.message : [body.message ?? `Something went wrong (HTTP ${res.status}).`]);
|
|
57
|
+
throw new EditorError(res.status, problems);
|
|
58
|
+
}
|
|
59
|
+
return body;
|
|
60
|
+
}
|
|
61
|
+
const slotPath = (name, locale, suffix = '') => `slots/${encodeURIComponent(name)}${suffix}${locale ? `?locale=${encodeURIComponent(locale)}` : ''}`;
|
|
62
|
+
/** What the API stores: media as { id }, everything else as entered. */
|
|
63
|
+
function toPayload(fields, values) {
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const [name, def] of Object.entries(fields)) {
|
|
66
|
+
const v = values[name];
|
|
67
|
+
if (def.type === 'media')
|
|
68
|
+
out[name] = v && typeof v === 'object' ? { id: v.id } : null;
|
|
69
|
+
else if (def.type === 'slides' && Array.isArray(v))
|
|
70
|
+
out[name] = v.map((sl) => ({ ...sl, image: sl.image ? { id: sl.image.id } : null }));
|
|
71
|
+
else
|
|
72
|
+
out[name] = v;
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
// -------------------------------------------------------------- singleton
|
|
77
|
+
const owners = [];
|
|
78
|
+
const ownerListeners = new Set();
|
|
79
|
+
const notifyOwners = () => ownerListeners.forEach((l) => l());
|
|
80
|
+
function useIsOwner(id) {
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
owners.push(id);
|
|
83
|
+
notifyOwners();
|
|
84
|
+
return () => {
|
|
85
|
+
owners.splice(owners.indexOf(id), 1);
|
|
86
|
+
notifyOwners();
|
|
87
|
+
};
|
|
88
|
+
}, [id]);
|
|
89
|
+
return useSyncExternalStore((l) => {
|
|
90
|
+
ownerListeners.add(l);
|
|
91
|
+
return () => ownerListeners.delete(l);
|
|
92
|
+
}, () => owners[0] === id, () => false);
|
|
93
|
+
}
|
|
94
|
+
// -------------------------------------------------------------- page dom
|
|
95
|
+
function rectOf(el) {
|
|
96
|
+
if (!el)
|
|
97
|
+
return null;
|
|
98
|
+
let rect = null;
|
|
99
|
+
if (getComputedStyle(el).display === 'contents' && typeof document.createRange === 'function') {
|
|
100
|
+
const range = document.createRange();
|
|
101
|
+
range.selectNodeContents(el);
|
|
102
|
+
rect = typeof range.getBoundingClientRect === 'function' ? range.getBoundingClientRect() : null;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
rect = el.getBoundingClientRect();
|
|
106
|
+
}
|
|
107
|
+
return rect && (rect.width || rect.height) ? rect : null;
|
|
108
|
+
}
|
|
109
|
+
function findPageSlots() {
|
|
110
|
+
const seen = new Set();
|
|
111
|
+
const out = [];
|
|
112
|
+
document.querySelectorAll('[data-veroxm-slot]').forEach((el) => {
|
|
113
|
+
const name = el.getAttribute('data-veroxm-slot') ?? '';
|
|
114
|
+
const locale = el.getAttribute('data-veroxm-locale') ?? '';
|
|
115
|
+
const key = `${name}|${locale}`;
|
|
116
|
+
if (!name || seen.has(key))
|
|
117
|
+
return;
|
|
118
|
+
seen.add(key);
|
|
119
|
+
out.push({ name, locale, label: el.getAttribute('data-veroxm-label') || name, el });
|
|
120
|
+
});
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
/** The values a slot is rendering right now (including the site's fallbacks), from its marker. */
|
|
124
|
+
function readShown(name, locale) {
|
|
125
|
+
try {
|
|
126
|
+
return JSON.parse(slotElement(name, locale)?.getAttribute('data-veroxm-shown') ?? '{}');
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return {};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Tells VeroXM what each slot on the page shows from the site's own
|
|
134
|
+
* fallback, so its dashboard can show that text in empty fields. Once per
|
|
135
|
+
* slot and value per page load; display only, failures are ignored.
|
|
136
|
+
*/
|
|
137
|
+
const sentFallbacks = new Set();
|
|
138
|
+
/** Test helper: forgets which fallbacks were sent. */
|
|
139
|
+
export function resetSentFallbacksForTests() {
|
|
140
|
+
sentFallbacks.clear();
|
|
141
|
+
}
|
|
142
|
+
function sendFallbacks() {
|
|
143
|
+
for (const s of findPageSlots()) {
|
|
144
|
+
let values;
|
|
145
|
+
try {
|
|
146
|
+
values = JSON.parse(s.el.getAttribute('data-veroxm-fallback') ?? '{}');
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (!Object.keys(values).length)
|
|
152
|
+
continue;
|
|
153
|
+
const key = `${s.name}|${s.locale}|${JSON.stringify(values)}`;
|
|
154
|
+
if (sentFallbacks.has(key))
|
|
155
|
+
continue;
|
|
156
|
+
sentFallbacks.add(key);
|
|
157
|
+
call(slotPath(s.name, s.locale, '/shown'), { method: 'PUT', body: { values } }).catch(() => sentFallbacks.delete(key));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function slotElement(name, locale) {
|
|
161
|
+
return document.querySelector(`[data-veroxm-slot="${CSS.escape(name)}"][data-veroxm-locale="${CSS.escape(locale)}"]`);
|
|
162
|
+
}
|
|
163
|
+
/** Re-renders on scroll, resize and page changes (a refresh after saving) so outlines follow the page. */
|
|
164
|
+
function useLayoutTick(active, ignore) {
|
|
165
|
+
const [tick, setTick] = useState(0);
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (!active)
|
|
168
|
+
return;
|
|
169
|
+
let frame = 0;
|
|
170
|
+
const onChange = () => {
|
|
171
|
+
if (frame)
|
|
172
|
+
return;
|
|
173
|
+
frame = requestAnimationFrame(() => {
|
|
174
|
+
frame = 0;
|
|
175
|
+
setTick((t) => t + 1);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
window.addEventListener('scroll', onChange, { capture: true, passive: true });
|
|
179
|
+
window.addEventListener('resize', onChange);
|
|
180
|
+
// The overlay's own re-renders don't count, or this would never settle.
|
|
181
|
+
const observer = new MutationObserver((records) => {
|
|
182
|
+
if (records.some((r) => !ignore.current?.contains(r.target)))
|
|
183
|
+
onChange();
|
|
184
|
+
});
|
|
185
|
+
observer.observe(document.body, { childList: true, subtree: true, characterData: true, attributes: true });
|
|
186
|
+
return () => {
|
|
187
|
+
observer.disconnect();
|
|
188
|
+
window.removeEventListener('scroll', onChange, { capture: true });
|
|
189
|
+
window.removeEventListener('resize', onChange);
|
|
190
|
+
cancelAnimationFrame(frame);
|
|
191
|
+
};
|
|
192
|
+
}, [active, ignore]);
|
|
193
|
+
return tick;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The editor overlay. Each <VeroxmSlot> renders one while editing; only the
|
|
197
|
+
* first mounted actually draws, so a page gets exactly one.
|
|
198
|
+
*/
|
|
199
|
+
export function VeroxmEditorOverlay({ onChange, tools }) {
|
|
200
|
+
const id = useId();
|
|
201
|
+
const owner = useIsOwner(id);
|
|
202
|
+
const [mounted, setMounted] = useState(false);
|
|
203
|
+
const changeRef = useRef(onChange);
|
|
204
|
+
changeRef.current = onChange;
|
|
205
|
+
const stableChange = useCallback(() => changeRef.current(), []);
|
|
206
|
+
useEffect(() => setMounted(true), []);
|
|
207
|
+
if (!owner || !mounted)
|
|
208
|
+
return null;
|
|
209
|
+
return createPortal(_jsx(Overlay, { onChange: stableChange, tools: tools }), document.body);
|
|
210
|
+
}
|
|
211
|
+
function Overlay({ onChange, tools }) {
|
|
212
|
+
const rootRef = useRef(null);
|
|
213
|
+
const [session, setSession] = useState(null);
|
|
214
|
+
const [ended, setEnded] = useState(null);
|
|
215
|
+
const [editMode, setEditMode] = useState(true);
|
|
216
|
+
const [hover, setHover] = useState(null);
|
|
217
|
+
const [open, setOpen] = useState(null);
|
|
218
|
+
const [listOpen, setListOpen] = useState(false);
|
|
219
|
+
const listToggleRef = useRef(null);
|
|
220
|
+
const [highlightField, setHighlightField] = useState(null);
|
|
221
|
+
const [inlineHint, setInlineHint] = useState(null);
|
|
222
|
+
useLayoutTick(Boolean(hover || open || inlineHint), rootRef);
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
call('session')
|
|
225
|
+
.then(setSession)
|
|
226
|
+
.catch((err) => setEnded(err instanceof EditorError ? err.problems.join(' ') : 'VeroXM could not be reached.'));
|
|
227
|
+
}, []);
|
|
228
|
+
// Once the session is confirmed: the site's own text for each slot, for
|
|
229
|
+
// the dashboard. Again shortly after, for slots whose fallback arrives late.
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
if (!session)
|
|
232
|
+
return;
|
|
233
|
+
sendFallbacks();
|
|
234
|
+
const timers = [1500, 5000].map((ms) => setTimeout(sendFallbacks, ms));
|
|
235
|
+
return () => timers.forEach(clearTimeout);
|
|
236
|
+
}, [session]);
|
|
237
|
+
const onSessionError = useCallback((err) => {
|
|
238
|
+
if (err instanceof EditorError && (err.status === 401 || err.status === 403))
|
|
239
|
+
setEnded(err.problems.join(' '));
|
|
240
|
+
}, []);
|
|
241
|
+
// Hover outlines and click-to-edit, while edit mode is on.
|
|
242
|
+
useEffect(() => {
|
|
243
|
+
if (!editMode || ended) {
|
|
244
|
+
setHover(null);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const inOverlay = (t) => t instanceof Node && !!rootRef.current?.contains(t);
|
|
248
|
+
const onMove = (e) => {
|
|
249
|
+
if (inOverlay(e.target))
|
|
250
|
+
return setHover(null);
|
|
251
|
+
const el = e.target instanceof Element ? e.target.closest('[data-veroxm-slot]') : null;
|
|
252
|
+
setHover((prev) => (prev === el ? prev : el));
|
|
253
|
+
};
|
|
254
|
+
const onClick = (e) => {
|
|
255
|
+
if (inOverlay(e.target) || !(e.target instanceof Element))
|
|
256
|
+
return;
|
|
257
|
+
const el = e.target.closest('[data-veroxm-slot]');
|
|
258
|
+
if (!el)
|
|
259
|
+
return;
|
|
260
|
+
// Editing, not navigating: a slot's links and buttons don't fire.
|
|
261
|
+
e.preventDefault();
|
|
262
|
+
e.stopPropagation();
|
|
263
|
+
// A click inside text being typed into just moves the caret.
|
|
264
|
+
if (e.target.closest('[data-veroxm-inline]'))
|
|
265
|
+
return;
|
|
266
|
+
setListOpen(false);
|
|
267
|
+
const fieldEl = e.target.closest('[data-veroxm-field]');
|
|
268
|
+
const field = fieldEl?.getAttribute('data-veroxm-field') ?? undefined;
|
|
269
|
+
setOpen({
|
|
270
|
+
name: el.getAttribute('data-veroxm-slot') ?? '',
|
|
271
|
+
locale: el.getAttribute('data-veroxm-locale') ?? '',
|
|
272
|
+
focusField: field,
|
|
273
|
+
inline: field && canEditInline(fieldEl) ? { el: fieldEl, field, point: { x: e.clientX, y: e.clientY } } : undefined,
|
|
274
|
+
nonce: Date.now(),
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
const onLeave = () => setHover(null);
|
|
278
|
+
document.addEventListener('mousemove', onMove, { passive: true });
|
|
279
|
+
document.addEventListener('click', onClick, true);
|
|
280
|
+
document.documentElement.addEventListener('mouseleave', onLeave);
|
|
281
|
+
return () => {
|
|
282
|
+
document.removeEventListener('mousemove', onMove);
|
|
283
|
+
document.removeEventListener('click', onClick, true);
|
|
284
|
+
document.documentElement.removeEventListener('mouseleave', onLeave);
|
|
285
|
+
};
|
|
286
|
+
}, [editMode, ended]);
|
|
287
|
+
const openEl = open ? slotElement(open.name, open.locale) : null;
|
|
288
|
+
const hoverRect = hover && hover !== openEl ? rectOf(hover) : null;
|
|
289
|
+
const openRect = rectOf(openEl);
|
|
290
|
+
const fieldRect = openEl && highlightField ? rectOf(openEl.querySelector(`[data-veroxm-field="${CSS.escape(highlightField)}"]`)) : null;
|
|
291
|
+
return (_jsxs("div", { ref: rootRef, className: "vx-root", "data-veroxm-overlay": "", children: [_jsx("style", { children: STYLES + RICH_TEXT_STYLES + MENU_STYLES }), hoverRect && _jsx(Outline, { rect: hoverRect, label: hover?.getAttribute('data-veroxm-label') || hover?.getAttribute('data-veroxm-slot') || '' }), openRect && _jsx(Outline, { rect: openRect, active: true }), fieldRect && !inlineHint && _jsx(Outline, { rect: fieldRect, field: true }), inlineHint ? _jsx(InlineHintBar, { hint: inlineHint }) : null, open && session && !ended && (_jsx(SlotPanel, { slot: open, canPublish: session.canPublish, canManageTests: session.canManageTests ?? false, dashboardUrl: session.dashboardUrl ?? null, onClose: () => {
|
|
292
|
+
setOpen(null);
|
|
293
|
+
setHighlightField(null);
|
|
294
|
+
}, onFieldFocus: setHighlightField, onSessionError: onSessionError, onChange: onChange, onInline: setInlineHint }, `${open.name}|${open.locale}`)), listOpen && (_jsx(SlotList, { onPick: (s) => {
|
|
295
|
+
setListOpen(false);
|
|
296
|
+
s.el.firstElementChild?.scrollIntoView?.({ block: 'center', behavior: 'smooth' });
|
|
297
|
+
setOpen({ name: s.name, locale: s.locale });
|
|
298
|
+
}, onClose: () => {
|
|
299
|
+
setListOpen(false);
|
|
300
|
+
listToggleRef.current?.focus();
|
|
301
|
+
} })), _jsxs("div", { className: "vx-toolbar", role: "toolbar", "aria-label": "VeroXM editor", children: [_jsxs("span", { className: "vx-brand", children: [_jsx("span", { className: "vx-dot", "aria-hidden": "true" }), ended ? 'Editing ended' : 'Editing drafts', session?.projectName ? _jsxs("span", { className: "vx-muted", children: [" \u00B7 ", session.projectName] }) : null] }), ended ? (_jsx("span", { className: "vx-muted vx-ended", role: "alert", children: ended })) : (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "vx-btn", "aria-pressed": editMode, onClick: () => setEditMode((v) => !v), children: editMode ? 'Click to edit: on' : 'Click to edit: off' }), _jsx("button", { type: "button", ref: listToggleRef, className: "vx-btn", "data-vx-list-toggle": "", "aria-expanded": listOpen, onClick: () => setListOpen((v) => !v), children: "Slots on this page" }), tools] })), _jsx("button", { type: "button", className: "vx-btn", onClick: () => transport.exit(), children: "Exit" })] })] }));
|
|
302
|
+
}
|
|
303
|
+
function InlineHintBar({ hint }) {
|
|
304
|
+
const rect = rectOf(hint.el);
|
|
305
|
+
if (!rect)
|
|
306
|
+
return null;
|
|
307
|
+
const below = rect.bottom + 40 < window.innerHeight;
|
|
308
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "vx-outline vx-outline-inline", style: { top: rect.top - 4, left: rect.left - 4, width: rect.width + 8, height: rect.height + 8 }, "aria-hidden": "true" }), _jsxs("div", { className: "vx-inline-hint", style: { top: below ? rect.bottom + 8 : Math.max(8, rect.top - 36), left: Math.max(8, rect.left - 4) }, role: "status", "aria-live": "polite", children: [_jsx("strong", { children: hint.label }), hint.max !== undefined ? _jsxs("span", { children: [" \u00B7 ", hint.length, "/", hint.max] }) : null, _jsx("span", { className: "vx-inline-keys", children: " \u00B7 Enter to save \u00B7 Esc to cancel" })] })] }));
|
|
309
|
+
}
|
|
310
|
+
function Outline({ rect, label, active, field }) {
|
|
311
|
+
return (_jsx("div", { className: `vx-outline${active ? ' vx-outline-active' : ''}${field ? ' vx-outline-field' : ''}`, style: { top: rect.top - 3, left: rect.left - 3, width: rect.width + 6, height: rect.height + 6 }, "aria-hidden": "true", children: label ? _jsx("span", { className: "vx-tag", children: label }) : null }));
|
|
312
|
+
}
|
|
313
|
+
// -------------------------------------------------------------- slot list
|
|
314
|
+
function SlotList({ onPick, onClose }) {
|
|
315
|
+
const [slots] = useState(findPageSlots);
|
|
316
|
+
const firstRef = useRef(null);
|
|
317
|
+
useEffect(() => firstRef.current?.focus(), []);
|
|
318
|
+
return (_jsxs("div", { className: "vx-list", role: "dialog", "aria-label": "Slots on this page", onKeyDown: (e) => {
|
|
319
|
+
if (e.key !== 'Escape')
|
|
320
|
+
return;
|
|
321
|
+
e.stopPropagation();
|
|
322
|
+
onClose();
|
|
323
|
+
}, children: [_jsx("p", { className: "vx-list-title", children: "Slots on this page" }), slots.length === 0 ? (_jsx("p", { className: "vx-muted", children: "No slots are visible on this page." })) : (_jsx("ul", { children: slots.map((s, i) => (_jsx("li", { children: _jsxs("button", { type: "button", ref: i === 0 ? firstRef : undefined, onClick: () => onPick(s), children: [_jsx("span", { children: s.label }), s.label !== s.name ? _jsx("code", { children: s.name }) : null, s.locale ? _jsxs("span", { className: "vx-muted", children: [" \u00B7 ", s.locale] }) : null] }) }, `${s.name}|${s.locale}`))) }))] }));
|
|
324
|
+
}
|
|
325
|
+
const AUTOSAVE_MS = 800;
|
|
326
|
+
function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, onFieldFocus, onSessionError, onChange, onInline, }) {
|
|
327
|
+
const titleId = useId();
|
|
328
|
+
const panelRef = useRef(null);
|
|
329
|
+
const returnFocus = useRef(typeof document !== 'undefined' ? document.activeElement : null);
|
|
330
|
+
const [data, setData] = useState(null);
|
|
331
|
+
const [locale, setLocale] = useState(slot.locale);
|
|
332
|
+
const [values, setValues] = useState({});
|
|
333
|
+
const [loadError, setLoadError] = useState(null);
|
|
334
|
+
const [save, setSave] = useState({ kind: 'idle' });
|
|
335
|
+
const [busy, setBusy] = useState(null);
|
|
336
|
+
const [reviewComment, setReviewComment] = useState('');
|
|
337
|
+
const [confirmDiscard, setConfirmDiscard] = useState(false);
|
|
338
|
+
const [notice, setNotice] = useState(null);
|
|
339
|
+
const timer = useRef(null);
|
|
340
|
+
const inlineRef = useRef(null);
|
|
341
|
+
const valuesRef = useRef({});
|
|
342
|
+
const latest = useRef(null);
|
|
343
|
+
const apply = useCallback((next) => {
|
|
344
|
+
if (!next)
|
|
345
|
+
return;
|
|
346
|
+
setData(next);
|
|
347
|
+
setValues(next.values);
|
|
348
|
+
}, []);
|
|
349
|
+
// Which version the panel shows and edits: 0 = the slot itself, 1+ = an
|
|
350
|
+
// A/B test variant (previewed on the page through a cookie the site reads).
|
|
351
|
+
const [variant, setVariant] = useState(0);
|
|
352
|
+
const variantRef = useRef(0);
|
|
353
|
+
const baseValues = useRef({});
|
|
354
|
+
const load = useCallback(async (position) => {
|
|
355
|
+
const qs = new URLSearchParams({ names: slot.name });
|
|
356
|
+
if (slot.locale)
|
|
357
|
+
qs.set('locale', slot.locale);
|
|
358
|
+
if (position > 0)
|
|
359
|
+
qs.set('variant', String(position));
|
|
360
|
+
try {
|
|
361
|
+
const res = await call(`slots?${qs}`);
|
|
362
|
+
setLocale(res.locale);
|
|
363
|
+
const s = res.slots[slot.name];
|
|
364
|
+
if (!s)
|
|
365
|
+
setLoadError('VeroXM doesn’t know this slot yet. Reload the page so the site can report it, then try again.');
|
|
366
|
+
else {
|
|
367
|
+
if (position === 0)
|
|
368
|
+
baseValues.current = s.values;
|
|
369
|
+
apply(s);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
catch (err) {
|
|
373
|
+
onSessionError(err);
|
|
374
|
+
setLoadError(err instanceof EditorError ? err.problems.join(' ') : 'VeroXM could not be reached.');
|
|
375
|
+
}
|
|
376
|
+
}, [slot.name, slot.locale, apply, onSessionError]);
|
|
377
|
+
useEffect(() => {
|
|
378
|
+
void load(0);
|
|
379
|
+
}, [load]);
|
|
380
|
+
const selectVariant = async (position) => {
|
|
381
|
+
if (position === variantRef.current)
|
|
382
|
+
return;
|
|
383
|
+
await flushRef.current();
|
|
384
|
+
variantRef.current = position;
|
|
385
|
+
setVariant(position);
|
|
386
|
+
setPreviewCookie(position > 0 ? `${slot.name}:${position}` : null);
|
|
387
|
+
if (position > 0 && variantRef.current > 0)
|
|
388
|
+
await load(0); // fresh base to compare against
|
|
389
|
+
await load(position);
|
|
390
|
+
onChange();
|
|
391
|
+
};
|
|
392
|
+
// Leaving the panel stops previewing a variant on the page.
|
|
393
|
+
useEffect(() => () => {
|
|
394
|
+
if (variantRef.current > 0) {
|
|
395
|
+
setPreviewCookie(null);
|
|
396
|
+
onChange();
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
400
|
+
[]);
|
|
401
|
+
const flush = useCallback(async () => {
|
|
402
|
+
if (timer.current)
|
|
403
|
+
clearTimeout(timer.current);
|
|
404
|
+
timer.current = null;
|
|
405
|
+
const pending = latest.current;
|
|
406
|
+
if (!pending || !data)
|
|
407
|
+
return true;
|
|
408
|
+
latest.current = null;
|
|
409
|
+
setSave({ kind: 'saving' });
|
|
410
|
+
try {
|
|
411
|
+
if (variantRef.current > 0) {
|
|
412
|
+
// A test variant stores only the fields it changes from the slot.
|
|
413
|
+
const changes = Object.fromEntries(Object.entries(toPayload(data.fields, pending)).filter(([k, v]) => JSON.stringify(v) !== JSON.stringify(toPayload(data.fields, baseValues.current)[k])));
|
|
414
|
+
await call(`slots/${encodeURIComponent(slot.name)}/variants/${variantRef.current}`, { method: 'PUT', body: { values: changes } });
|
|
415
|
+
await load(variantRef.current);
|
|
416
|
+
setSave({ kind: 'saved', at: new Date() });
|
|
417
|
+
if (!inlineRef.current)
|
|
418
|
+
onChange();
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
const next = await call(slotPath(slot.name, locale), { method: 'PUT', body: { values: toPayload(data.fields, pending) } });
|
|
422
|
+
setData(next);
|
|
423
|
+
setSave({ kind: 'saved', at: new Date() });
|
|
424
|
+
// While typing on the page the page already shows the text; re-render when done.
|
|
425
|
+
if (!inlineRef.current)
|
|
426
|
+
onChange();
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
catch (err) {
|
|
430
|
+
onSessionError(err);
|
|
431
|
+
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['Could not save. Check your connection.'] });
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
}, [data, locale, slot.name, onChange, onSessionError, load]);
|
|
435
|
+
const flushRef = useRef(flush);
|
|
436
|
+
flushRef.current = flush;
|
|
437
|
+
useEffect(() => () => {
|
|
438
|
+
inlineRef.current?.end(true);
|
|
439
|
+
void flushRef.current();
|
|
440
|
+
}, []);
|
|
441
|
+
const change = (field, value) => {
|
|
442
|
+
setNotice(null);
|
|
443
|
+
setConfirmDiscard(false);
|
|
444
|
+
setValues((prev) => {
|
|
445
|
+
const next = { ...prev, [field]: value };
|
|
446
|
+
latest.current = next;
|
|
447
|
+
return next;
|
|
448
|
+
});
|
|
449
|
+
if (timer.current)
|
|
450
|
+
clearTimeout(timer.current);
|
|
451
|
+
timer.current = setTimeout(() => void flushRef.current(), AUTOSAVE_MS);
|
|
452
|
+
};
|
|
453
|
+
valuesRef.current = values;
|
|
454
|
+
const changeRef = useRef(change);
|
|
455
|
+
changeRef.current = change;
|
|
456
|
+
// Once the form is loaded: type into the clicked text on the page if it
|
|
457
|
+
// allows it, otherwise focus the clicked field (or the first) in the panel.
|
|
458
|
+
useEffect(() => {
|
|
459
|
+
if (!data)
|
|
460
|
+
return;
|
|
461
|
+
const target = slot.inline;
|
|
462
|
+
const def = target ? data.fields[target.field] : undefined;
|
|
463
|
+
if (target && def?.type === 'text' && target.el.isConnected && canEditInline(target.el)) {
|
|
464
|
+
inlineRef.current?.end(true);
|
|
465
|
+
const before = valuesRef.current[target.field];
|
|
466
|
+
let typed = false;
|
|
467
|
+
const label = def.label ?? target.field;
|
|
468
|
+
onFieldFocus(target.field);
|
|
469
|
+
onInline({ el: target.el, label, length: target.el.textContent?.length ?? 0, max: def.max });
|
|
470
|
+
inlineRef.current = startInlineEdit(target.el, {
|
|
471
|
+
label,
|
|
472
|
+
max: def.max,
|
|
473
|
+
point: target.point,
|
|
474
|
+
onInput: (text) => {
|
|
475
|
+
typed = true;
|
|
476
|
+
changeRef.current(target.field, text);
|
|
477
|
+
onInline({ el: target.el, label, length: text.length, max: def.max });
|
|
478
|
+
},
|
|
479
|
+
onEnd: ({ committed, text }) => {
|
|
480
|
+
inlineRef.current = null;
|
|
481
|
+
onInline(null);
|
|
482
|
+
if (!typed)
|
|
483
|
+
return;
|
|
484
|
+
changeRef.current(target.field, committed ? text : before);
|
|
485
|
+
void flushRef.current().then(() => onChange());
|
|
486
|
+
},
|
|
487
|
+
});
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
const panel = panelRef.current;
|
|
491
|
+
const focus = (slot.focusField && panel?.querySelector(`[data-field="${CSS.escape(slot.focusField)}"]`)) ||
|
|
492
|
+
panel?.querySelector('[data-field]') ||
|
|
493
|
+
panel?.querySelector('button');
|
|
494
|
+
focus?.focus();
|
|
495
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
496
|
+
}, [data !== null, slot.nonce]);
|
|
497
|
+
const close = () => {
|
|
498
|
+
inlineRef.current?.end(true);
|
|
499
|
+
void flush();
|
|
500
|
+
onFieldFocus(null);
|
|
501
|
+
onClose();
|
|
502
|
+
// Back to where editing started; if that's gone (the slot list closes when a slot is picked), the list button.
|
|
503
|
+
const back = returnFocus.current;
|
|
504
|
+
if (back instanceof HTMLElement && back.isConnected)
|
|
505
|
+
back.focus();
|
|
506
|
+
else
|
|
507
|
+
document.querySelector('[data-vx-list-toggle]')?.focus();
|
|
508
|
+
};
|
|
509
|
+
/** Publish (or send for approval), approve, reject or withdraw. */
|
|
510
|
+
const act = async (verb, body) => {
|
|
511
|
+
if (verb === 'publish' && !(await flush()))
|
|
512
|
+
return;
|
|
513
|
+
setBusy(verb);
|
|
514
|
+
try {
|
|
515
|
+
const res = await call(slotPath(slot.name, locale, `/${verb}`), {
|
|
516
|
+
method: 'POST',
|
|
517
|
+
...(body ? { body } : {}),
|
|
518
|
+
});
|
|
519
|
+
apply(res.slot);
|
|
520
|
+
setSave({ kind: 'idle' });
|
|
521
|
+
setNotice(OUTCOME_NOTICE[res.outcome] ?? null);
|
|
522
|
+
setReviewComment('');
|
|
523
|
+
if (res.outcome === 'published' || verb === 'publish')
|
|
524
|
+
onChange();
|
|
525
|
+
}
|
|
526
|
+
catch (err) {
|
|
527
|
+
onSessionError(err);
|
|
528
|
+
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['Something went wrong. Try again.'] });
|
|
529
|
+
}
|
|
530
|
+
finally {
|
|
531
|
+
setBusy(null);
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
const discard = async () => {
|
|
535
|
+
if (!confirmDiscard)
|
|
536
|
+
return setConfirmDiscard(true);
|
|
537
|
+
if (timer.current)
|
|
538
|
+
clearTimeout(timer.current);
|
|
539
|
+
latest.current = null;
|
|
540
|
+
setBusy('discard');
|
|
541
|
+
try {
|
|
542
|
+
apply(await call(slotPath(slot.name, locale, '/discard'), { method: 'POST' }));
|
|
543
|
+
setNotice('Changes discarded.');
|
|
544
|
+
setSave({ kind: 'idle' });
|
|
545
|
+
onChange();
|
|
546
|
+
}
|
|
547
|
+
catch (err) {
|
|
548
|
+
onSessionError(err);
|
|
549
|
+
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['Could not discard.'] });
|
|
550
|
+
}
|
|
551
|
+
finally {
|
|
552
|
+
setBusy(null);
|
|
553
|
+
setConfirmDiscard(false);
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
// The page's own fallback copy, so empty fields show what visitors see now.
|
|
557
|
+
const shown = readShown(slot.name, slot.locale);
|
|
558
|
+
const dirty = Boolean(data?.unpublishedChanges) || save.kind === 'saving' || latest.current !== null;
|
|
559
|
+
const title = data?.label || slot.name;
|
|
560
|
+
const approval = data?.approval ?? null;
|
|
561
|
+
return (_jsxs("div", { ref: panelRef, className: "vx-panel", role: "dialog", "aria-modal": "false", "aria-labelledby": titleId, onKeyDown: (e) => {
|
|
562
|
+
if (e.key === 'Escape') {
|
|
563
|
+
e.stopPropagation();
|
|
564
|
+
close();
|
|
565
|
+
}
|
|
566
|
+
}, children: [_jsxs("div", { className: "vx-panel-head", children: [_jsxs("div", { children: [_jsx("h2", { id: titleId, children: title }), _jsxs("p", { className: "vx-muted", children: [title !== slot.name ? _jsx("code", { children: slot.name }) : null, locale ? _jsxs("span", { children: [" \u00B7 ", locale] }) : null, data ? _jsxs("span", { children: [" \u00B7 ", data.version ? `v${data.version} live` : 'never published'] }) : null] })] }), _jsx("button", { type: "button", className: "vx-icon", "aria-label": "Close", onClick: close, children: "\u00D7" })] }), _jsxs("div", { className: "vx-panel-body", children: [loadError ? _jsx("p", { role: "alert", children: loadError }) : null, !data && !loadError ? _jsx("p", { className: "vx-muted", children: "Loading\u2026" }) : null, data?.test ? (_jsxs("div", { className: "vx-test", children: [_jsxs("p", { className: "vx-test-title", children: [TEST_STATUS[data.test.status] ?? 'Test', ": ", data.test.name] }), _jsx("div", { className: "vx-tabs", role: "tablist", "aria-label": "Version to show and edit", onKeyDown: (e) => {
|
|
567
|
+
// Arrow keys move between versions (one tab stop for the whole list).
|
|
568
|
+
const order = data.test.variants.map((v) => v.position);
|
|
569
|
+
const at = order.indexOf(variant);
|
|
570
|
+
const next = e.key === 'ArrowRight' || e.key === 'ArrowDown'
|
|
571
|
+
? order[(at + 1) % order.length]
|
|
572
|
+
: e.key === 'ArrowLeft' || e.key === 'ArrowUp'
|
|
573
|
+
? order[(at - 1 + order.length) % order.length]
|
|
574
|
+
: e.key === 'Home'
|
|
575
|
+
? order[0]
|
|
576
|
+
: e.key === 'End'
|
|
577
|
+
? order[order.length - 1]
|
|
578
|
+
: undefined;
|
|
579
|
+
if (next === undefined)
|
|
580
|
+
return;
|
|
581
|
+
e.preventDefault();
|
|
582
|
+
void selectVariant(next);
|
|
583
|
+
e.currentTarget.querySelector(`[data-position="${next}"]`)?.focus();
|
|
584
|
+
}, children: data.test.variants.map((v) => (_jsx("button", { type: "button", role: "tab", "data-position": v.position, "aria-selected": variant === v.position, tabIndex: variant === v.position ? 0 : -1, className: "vx-tab", onClick: () => void selectVariant(v.position), children: v.isControl ? 'Published' : v.label }, v.position))) }), variant > 0 ? (_jsx("p", { className: "vx-muted", children: data.test.editable && canManageTests
|
|
585
|
+
? 'The page shows this variant. Edits change only this variant; empty fields use the published version.'
|
|
586
|
+
: data.test.editable
|
|
587
|
+
? 'The page shows this variant. Editing variants needs permission to manage experiments.'
|
|
588
|
+
: 'The page shows this variant. Variants can’t change once the test has started.' })) : null] })) : null, data?.inherited && locale ? (_jsxs("p", { className: "vx-note", children: ["Nothing saved in ", locale, " yet; you\u2019re starting from the default language\u2019s published copy."] })) : null, data
|
|
589
|
+
? (variant > 0 && !(data.test?.editable && canManageTests) ? [] : Object.entries(data.fields)).map(([name, def]) => (_jsx(FieldInput, { name: name, def: def, value: values[name], shown: shown[name], onChange: (v) => change(name, v), onFocus: () => onFieldFocus(name) }, name)))
|
|
590
|
+
: null] }), _jsxs("div", { className: "vx-panel-foot", children: [_jsx("p", { className: "vx-status", role: "status", "aria-live": "polite", children: save.kind === 'saving'
|
|
591
|
+
? variant > 0
|
|
592
|
+
? 'Saving variant…'
|
|
593
|
+
: 'Saving draft…'
|
|
594
|
+
: save.kind === 'saved'
|
|
595
|
+
? variant > 0
|
|
596
|
+
? 'Variant saved'
|
|
597
|
+
: 'Draft saved'
|
|
598
|
+
: save.kind === 'error'
|
|
599
|
+
? ''
|
|
600
|
+
: latest.current !== null
|
|
601
|
+
? 'Editing… saves in a moment'
|
|
602
|
+
: notice ?? (data?.unpublishedChanges ? 'Unpublished changes' : data ? 'No unpublished changes' : '') }), save.kind === 'error' ? (_jsx("ul", { className: "vx-errors", role: "alert", children: save.problems.map((p) => (_jsx("li", { children: p }, p))) })) : null, variant > 0 && data?.test ? (_jsxs("div", { className: "vx-actions", children: [dashboardUrl ? (_jsx("a", { className: "vx-btn", href: `${dashboardUrl}${data.test.dashboardPath}`, target: "_blank", rel: "noopener noreferrer", children: "Test settings and results" })) : null, _jsx("button", { type: "button", className: "vx-btn", onClick: () => void selectVariant(0), children: "Back to published" })] })) : null, variant === 0 && approval?.pending ? (_jsxs("div", { className: "vx-review", role: "group", "aria-label": "Approval", children: [_jsxs("p", { className: "vx-review-title", children: ["Waiting for approval", approval.steps.length > 1 && approval.currentStep !== null
|
|
603
|
+
? ` · step ${approval.steps.findIndex((st) => st.stepOrder === approval.currentStep) + 1} of ${approval.steps.length}`
|
|
604
|
+
: ''] }), _jsxs("p", { className: "vx-muted", children: [approval.steps.find((st) => st.stepOrder === approval.currentStep)?.label, approval.submittedByName ? ` · sent by ${approval.submittedByName}` : ''] }), approval.changedSinceSubmission ? (_jsx("p", { className: "vx-muted", children: "Edits made since it was sent aren't part of the request." })) : null, approval.canAct ? (_jsxs(_Fragment, { children: [_jsx("label", { className: "vx-sublabel", htmlFor: `${titleId}-review`, children: "Comment (needed to reject)" }), _jsx("textarea", { id: `${titleId}-review`, className: "vx-review-comment", rows: 2, value: reviewComment, onChange: (e) => setReviewComment(e.target.value) }), _jsxs("div", { className: "vx-actions", children: [_jsx("button", { type: "button", className: "vx-btn vx-primary", disabled: busy !== null, onClick: () => act('approve', { comment: reviewComment }), children: busy === 'approve' ? 'Approving…' : approval.steps[approval.steps.length - 1]?.stepOrder === approval.currentStep ? 'Approve and publish' : 'Approve' }), _jsx("button", { type: "button", className: "vx-btn", disabled: busy !== null || !reviewComment.trim(), onClick: () => act('reject', { comment: reviewComment }), children: busy === 'reject' ? 'Rejecting…' : 'Reject' })] })] })) : approval.isSubmitter ? (_jsx("p", { className: "vx-muted", children: "Someone else on that step's role approves it." })) : null, approval.canWithdraw ? (_jsx("button", { type: "button", className: "vx-btn vx-review-withdraw", disabled: busy !== null, onClick: () => act('withdraw'), children: busy === 'withdraw' ? 'Withdrawing…' : 'Withdraw request' })) : null] })) : null, _jsxs("div", { className: "vx-actions", hidden: variant > 0, children: [canPublish ? (_jsx("button", { type: "button", className: "vx-btn vx-primary", disabled: !data || !dirty || busy !== null || approval?.pending, onClick: () => act('publish'), children: busy === 'publish' ? (approval?.required ? 'Sending…' : 'Publishing…') : approval?.required ? 'Send for approval' : 'Publish' })) : (_jsx("span", { className: "vx-muted", children: "Someone with publish permission can make this live." })), data?.unpublishedChanges && data.version > 0 ? (_jsx("button", { type: "button", className: "vx-btn", disabled: busy !== null, onClick: discard, children: busy === 'discard' ? 'Discarding…' : confirmDiscard ? 'Discard all changes?' : 'Discard changes' })) : null] })] })] }));
|
|
605
|
+
}
|
|
606
|
+
// ----------------------------------------------------------------- fields
|
|
607
|
+
function stripTags(html) {
|
|
608
|
+
return html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
609
|
+
}
|
|
610
|
+
function FieldInput({ name, def, value, shown, onChange, onFocus, }) {
|
|
611
|
+
const placeholder = typeof shown === 'string' && shown ? shown : undefined;
|
|
612
|
+
const id = useId();
|
|
613
|
+
const label = (_jsxs("label", { htmlFor: id, className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }));
|
|
614
|
+
const common = { id, 'data-field': name, onFocus, 'aria-required': def.required || undefined };
|
|
615
|
+
switch (def.type) {
|
|
616
|
+
case 'text': {
|
|
617
|
+
const text = typeof value === 'string' ? value : '';
|
|
618
|
+
return (_jsxs("div", { className: "vx-field", children: [label, _jsx("input", { ...common, type: "text", value: text, placeholder: placeholder, maxLength: def.max, onChange: (e) => onChange(e.target.value) }), def.max ? _jsxs("span", { className: "vx-count", children: [text.length, " / ", def.max] }) : null] }));
|
|
619
|
+
}
|
|
620
|
+
case 'richText': {
|
|
621
|
+
const html = typeof value === 'string' ? value : '';
|
|
622
|
+
return (_jsxs("div", { className: "vx-field", children: [_jsxs("span", { id: `${id}-label`, className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx(RichTextInput, { id: id, value: html, onChange: onChange, onFocus: onFocus, max: def.max, required: def.required, labelledBy: `${id}-label`, placeholder: placeholder ? stripTags(placeholder) : undefined, regionProps: { 'data-field': name } })] }));
|
|
623
|
+
}
|
|
624
|
+
case 'number':
|
|
625
|
+
return (_jsxs("div", { className: "vx-field", children: [label, _jsx("input", { ...common, type: "number", value: typeof value === 'number' ? value : '', onChange: (e) => onChange(e.target.value === '' ? null : Number(e.target.value)) })] }));
|
|
626
|
+
case 'boolean':
|
|
627
|
+
return (_jsxs("div", { className: "vx-field vx-check", children: [_jsx("input", { ...common, type: "checkbox", checked: typeof value === 'boolean' ? value : shown === true, onChange: (e) => onChange(e.target.checked) }), label] }));
|
|
628
|
+
case 'select':
|
|
629
|
+
return (_jsxs("div", { className: "vx-field", children: [label, _jsxs("select", { ...common, value: typeof value === 'string' ? value : typeof shown === 'string' ? shown : '', onChange: (e) => onChange(e.target.value || null), children: [!def.required ? _jsx("option", { value: "", children: "\u2014" }) : null, (def.options ?? []).map((o) => (_jsx("option", { value: o, children: o }, o)))] })] }));
|
|
630
|
+
case 'link': {
|
|
631
|
+
const link = (value && typeof value === 'object' ? value : { label: '', href: '' });
|
|
632
|
+
const set = (patch) => {
|
|
633
|
+
const next = { ...link, ...patch };
|
|
634
|
+
onChange(next.label || next.href ? next : null);
|
|
635
|
+
};
|
|
636
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx("label", { htmlFor: `${id}-label`, className: "vx-sublabel", children: "Text" }), _jsx("input", { id: `${id}-label`, "data-field": name, onFocus: onFocus, type: "text", value: link.label, onChange: (e) => set({ label: e.target.value }) }), _jsx("label", { htmlFor: `${id}-href`, className: "vx-sublabel", children: "Address" }), _jsx("input", { id: `${id}-href`, onFocus: onFocus, type: "text", inputMode: "url", placeholder: "https://\u2026 or /page", value: link.href, onChange: (e) => set({ href: e.target.value }) })] }));
|
|
637
|
+
}
|
|
638
|
+
case 'media':
|
|
639
|
+
return _jsx(MediaInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
640
|
+
case 'video':
|
|
641
|
+
return _jsx(VideoInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
642
|
+
case 'chart':
|
|
643
|
+
return _jsx(ChartInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
644
|
+
case 'map':
|
|
645
|
+
return _jsx(MapInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
646
|
+
case 'slides':
|
|
647
|
+
return _jsx(SlidesInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
648
|
+
case 'menu':
|
|
649
|
+
return _jsx(MenuInput, { name: name, label: def.label ?? name, required: def.required, depth: def.depth ?? 2, value: value, onChange: onChange, onFocus: onFocus });
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
function VideoInput({ name, def, value, onChange, onFocus }) {
|
|
653
|
+
const id = useId();
|
|
654
|
+
const video = (value && typeof value === 'object' ? value : { url: typeof value === 'string' ? value : '' });
|
|
655
|
+
const url = video.url ?? '';
|
|
656
|
+
const ref = url ? parseVideoUrl(url) : null;
|
|
657
|
+
const set = (patch) => {
|
|
658
|
+
const next = { url, ...(video.title ? { title: video.title } : {}), ...patch };
|
|
659
|
+
if (!next.title)
|
|
660
|
+
delete next.title;
|
|
661
|
+
onChange(next.url || next.title ? next : null);
|
|
662
|
+
};
|
|
663
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx("label", { htmlFor: `${id}-url`, className: "vx-sublabel", children: "YouTube or Vimeo link, or a video file" }), _jsx("input", { id: `${id}-url`, "data-field": name, onFocus: onFocus, type: "text", inputMode: "url", placeholder: "https://www.youtube.com/watch?v=\u2026", value: url, "aria-describedby": `${id}-status`, onChange: (e) => set({ url: e.target.value }) }), _jsx("span", { id: `${id}-status`, className: "vx-count", "aria-live": "polite", children: !url ? 'The page shows it as a player.' : ref ? `${ref.provider === 'youtube' ? 'YouTube' : ref.provider === 'vimeo' ? 'Vimeo' : 'Video file'}: recognised.` : 'Not a video link VeroXM can play.' }), _jsx("label", { htmlFor: `${id}-title`, className: "vx-sublabel", children: "Title" }), _jsx("input", { id: `${id}-title`, onFocus: onFocus, type: "text", maxLength: 120, value: video.title ?? '', onChange: (e) => set({ title: e.target.value }) })] }));
|
|
664
|
+
}
|
|
665
|
+
const KIND_NAMES = { bar: 'Columns', hbar: 'Bars', line: 'Line', area: 'Area', pie: 'Pie', donut: 'Donut', kpi: 'Key figure' };
|
|
666
|
+
function ChartInput({ name, def, value, onChange, onFocus }) {
|
|
667
|
+
const id = useId();
|
|
668
|
+
const chart = (value && typeof value === 'object' ? value : { kind: 'bar', labels: [], series: [], source: { type: 'manual' } });
|
|
669
|
+
const [text, setText] = useState(null);
|
|
670
|
+
const [error, setError] = useState(null);
|
|
671
|
+
const set = (patch) => onChange({ ...chart, ...patch });
|
|
672
|
+
const typed = chart.source.type === 'manual';
|
|
673
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), chart.sample ? _jsx("p", { className: "vx-note", children: "These are the template's sample numbers. Put in your own before publishing." }) : null, _jsx("label", { htmlFor: `${id}-kind`, className: "vx-sublabel", children: "Kind" }), _jsx("select", { id: `${id}-kind`, "data-field": name, onFocus: onFocus, value: chart.kind, onChange: (e) => set({ kind: e.target.value }), children: CHART_KINDS.map((k) => (_jsx("option", { value: k, children: KIND_NAMES[k] }, k))) }), _jsx("label", { htmlFor: `${id}-title`, className: "vx-sublabel", children: "Title" }), _jsx("input", { id: `${id}-title`, onFocus: onFocus, type: "text", maxLength: 120, value: chart.title ?? '', onChange: (e) => set({ title: e.target.value }) }), typed ? (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-data`, className: "vx-sublabel", children: "Numbers: paste from a spreadsheet, or type a row per label" }), _jsx("textarea", { id: `${id}-data`, onFocus: onFocus, rows: Math.min(12, chart.labels.length + 2), value: text ?? chartTableText(chart), "aria-describedby": `${id}-data-note`, onChange: (e) => {
|
|
674
|
+
setText(e.target.value);
|
|
675
|
+
const parsed = parseChartTable(e.target.value);
|
|
676
|
+
if ('error' in parsed)
|
|
677
|
+
setError(parsed.error);
|
|
678
|
+
else {
|
|
679
|
+
setError(null);
|
|
680
|
+
onChange({ ...chart, labels: parsed.labels, series: parsed.series, sample: undefined });
|
|
681
|
+
}
|
|
682
|
+
}, onBlur: () => !error && setText(null) }), _jsx("span", { id: `${id}-data-note`, className: error ? 'vx-errors' : 'vx-count', "aria-live": "polite", children: error ?? 'First row: Label, then a name for each series.' })] })) : (_jsxs("p", { className: "vx-muted", children: [chart.source.type === 'analytics' ? 'The numbers come from VeroXM analytics' : chart.source.type === 'content' ? `The numbers come from the “${chart.source.collection}” collection` : 'The numbers come from your API', " and fill in when the page loads. Change where they come from in the dashboard."] })), _jsxs("div", { className: "vx-menu-row", children: [_jsx("input", { "aria-label": "Before numbers, such as $", placeholder: "Before (SAR )", onFocus: onFocus, type: "text", maxLength: 8, value: chart.format?.prefix ?? '', onChange: (e) => set({ format: { ...chart.format, prefix: e.target.value || undefined } }) }), _jsx("input", { "aria-label": "After numbers, such as %", placeholder: "After ( SAR, %)", onFocus: onFocus, type: "text", maxLength: 12, value: chart.format?.suffix ?? '', onChange: (e) => set({ format: { ...chart.format, suffix: e.target.value || undefined } }) })] }), _jsx("label", { htmlFor: `${id}-caption`, className: "vx-sublabel", children: "Caption" }), _jsx("input", { id: `${id}-caption`, onFocus: onFocus, type: "text", maxLength: 300, value: chart.caption ?? '', onChange: (e) => set({ caption: e.target.value }) })] }));
|
|
683
|
+
}
|
|
684
|
+
function MapInput({ name, def, value, onChange, onFocus }) {
|
|
685
|
+
const id = useId();
|
|
686
|
+
const map = (value && typeof value === 'object' ? value : { places: [] });
|
|
687
|
+
const places = Array.isArray(map.places) ? map.places : [];
|
|
688
|
+
const max = def.max ?? 20;
|
|
689
|
+
const [search, setSearch] = useState(null);
|
|
690
|
+
const [pasted, setPasted] = useState({});
|
|
691
|
+
const set = (next) => onChange(next.length ? { places: next, ...(map.zoom ? { zoom: map.zoom } : {}) } : null);
|
|
692
|
+
const update = (i, patch) => set(places.map((p, j) => (j === i ? { ...p, ...patch } : p)));
|
|
693
|
+
const find = async (i, q) => {
|
|
694
|
+
setSearch({ at: i, q, results: null, error: null, busy: true });
|
|
695
|
+
try {
|
|
696
|
+
const r = await call(`geocode?q=${encodeURIComponent(q)}`);
|
|
697
|
+
setSearch({ at: i, q, results: r.results, error: r.results.length ? null : 'Nothing found. Try a fuller address, or paste a map link.', busy: false });
|
|
698
|
+
}
|
|
699
|
+
catch (err) {
|
|
700
|
+
setSearch({ at: i, q, results: null, error: err instanceof EditorError ? err.problems.join(' ') : 'Address search failed.', busy: false });
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsxs("span", { className: "vx-count", children: [places.length, " / ", max, " places"] }), places.map((place, i) => {
|
|
704
|
+
const title = place.name.trim() || `place ${i + 1}`;
|
|
705
|
+
const located = place.lat !== null && place.lng !== null && Number.isFinite(place.lat) && Number.isFinite(place.lng);
|
|
706
|
+
const q = search?.at === i ? search.q : (place.address ?? '');
|
|
707
|
+
return (_jsxs("div", { className: "vx-slide-card", children: [_jsx("label", { htmlFor: `${id}-${i}-name`, className: "vx-sublabel", children: "Name" }), _jsx("input", { id: `${id}-${i}-name`, "data-field": i === 0 ? name : undefined, onFocus: onFocus, type: "text", maxLength: 80, value: place.name, onChange: (e) => update(i, { name: e.target.value }) }), _jsx("label", { htmlFor: `${id}-${i}-address`, className: "vx-sublabel", children: "Address" }), _jsxs("div", { className: "vx-menu-row", children: [_jsx("input", { id: `${id}-${i}-address`, onFocus: onFocus, type: "text", maxLength: 200, value: place.address ?? '', onChange: (e) => update(i, { address: e.target.value }), onKeyDown: (e) => {
|
|
708
|
+
if (e.key === 'Enter') {
|
|
709
|
+
e.preventDefault();
|
|
710
|
+
void find(i, (place.address ?? '').trim());
|
|
711
|
+
}
|
|
712
|
+
} }), _jsx("button", { type: "button", className: "vx-btn", disabled: (place.address ?? '').trim().length < 3 || (search?.at === i && search.busy), onClick: () => void find(i, (place.address ?? '').trim()), children: search?.at === i && search.busy ? 'Finding…' : 'Find on map' })] }), search?.at === i && (search.results?.length || search.error) ? (_jsxs("div", { className: "vx-picker", role: "group", "aria-label": `Places matching ${q}`, children: [search.error ? _jsx("p", { className: "vx-errors", children: search.error }) : null, search.results?.map((r, k) => (_jsxs("button", { type: "button", className: "vx-result", onClick: () => {
|
|
713
|
+
update(i, { lat: r.lat, lng: r.lng, ...(place.name.trim() ? {} : { name: r.name }), address: place.address?.trim() ? place.address : r.address });
|
|
714
|
+
setSearch(null);
|
|
715
|
+
}, children: [_jsx("strong", { children: r.name }), " ", _jsx("span", { className: "vx-muted", children: r.address })] }, k))), _jsx("span", { className: "vx-count", children: "Search by OpenStreetMap Nominatim" })] })) : null, _jsx("label", { htmlFor: `${id}-${i}-pos`, className: "vx-sublabel", children: "Position: coordinates or a map link" }), _jsx("input", { id: `${id}-${i}-pos`, onFocus: onFocus, type: "text", placeholder: "24.7136, 46.6753", value: pasted[i] ?? (located ? `${place.lat}, ${place.lng}` : ''), "aria-describedby": `${id}-${i}-pos-note`, onChange: (e) => {
|
|
716
|
+
setPasted({ ...pasted, [i]: e.target.value });
|
|
717
|
+
const p = parseMapLink(e.target.value);
|
|
718
|
+
if (p)
|
|
719
|
+
update(i, { lat: p.lat, lng: p.lng });
|
|
720
|
+
else if (!e.target.value.trim())
|
|
721
|
+
update(i, { lat: null, lng: null });
|
|
722
|
+
}, onBlur: () => setPasted(({ [i]: _gone, ...rest }) => rest) }), _jsx("span", { id: `${id}-${i}-pos-note`, className: "vx-count", children: located ? 'On the map.' : 'Not placed yet: find the address, or paste coordinates or a link from a map site.' }), _jsx("div", { className: "vx-menu-tools", children: _jsx("button", { type: "button", className: "vx-mini", "aria-label": `Remove ${title}`, onClick: () => set(places.filter((_, j) => j !== i)), children: "Remove" }) })] }, i));
|
|
723
|
+
}), _jsx("div", { className: "vx-actions", children: _jsx("button", { type: "button", className: "vx-btn", "data-field": places.length ? undefined : name, onFocus: onFocus, disabled: places.length >= max, onClick: () => set([...places, { lat: null, lng: null, name: '' }]), children: "Add place" }) })] }));
|
|
724
|
+
}
|
|
725
|
+
function SlidesInput({ name, def, value, onChange, onFocus }) {
|
|
726
|
+
const id = useId();
|
|
727
|
+
const slides = Array.isArray(value) ? value : [];
|
|
728
|
+
const max = def.max ?? 10;
|
|
729
|
+
const set = (next) => onChange(next.length ? next : null);
|
|
730
|
+
const update = (i, patch) => set(slides.map((s, j) => (j === i ? { ...s, ...patch } : s)));
|
|
731
|
+
const move = (i, by) => {
|
|
732
|
+
const to = i + by;
|
|
733
|
+
if (to < 0 || to >= slides.length)
|
|
734
|
+
return;
|
|
735
|
+
const next = [...slides];
|
|
736
|
+
[next[i], next[to]] = [next[to], next[i]];
|
|
737
|
+
set(next);
|
|
738
|
+
};
|
|
739
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsxs("span", { className: "vx-count", children: [slides.length, " / ", max, " slides"] }), slides.map((slide, i) => {
|
|
740
|
+
const title = slide.title?.trim() || `slide ${i + 1}`;
|
|
741
|
+
return (_jsxs("div", { className: "vx-slide-card", children: [_jsx(MediaInput, { name: i === 0 ? name : `${name}-${i}`, def: { type: 'media', label: `Slide ${i + 1} image`, required: true }, value: slide.image, onChange: (v) => update(i, { image: v }), onFocus: onFocus }), _jsx("label", { htmlFor: `${id}-${i}-title`, className: "vx-sublabel", children: "Title" }), _jsx("input", { id: `${id}-${i}-title`, onFocus: onFocus, type: "text", maxLength: 120, value: slide.title ?? '', onChange: (e) => update(i, { title: e.target.value }) }), _jsx("label", { htmlFor: `${id}-${i}-text`, className: "vx-sublabel", children: "Text" }), _jsx("textarea", { id: `${id}-${i}-text`, onFocus: onFocus, rows: 2, maxLength: 300, value: slide.text ?? '', onChange: (e) => update(i, { text: e.target.value }) }), _jsxs("div", { className: "vx-menu-row", children: [_jsx("input", { "aria-label": `Button text of ${title}`, placeholder: "Button text", onFocus: onFocus, type: "text", value: slide.link?.label ?? '', onChange: (e) => update(i, { link: { label: e.target.value, href: slide.link?.href ?? '' } }) }), _jsx("input", { "aria-label": `Button link of ${title}`, placeholder: "/page or https://\u2026", inputMode: "url", onFocus: onFocus, type: "text", value: slide.link?.href ?? '', onChange: (e) => update(i, { link: { label: slide.link?.label ?? '', href: e.target.value } }) })] }), _jsxs("div", { className: "vx-menu-tools", children: [_jsx("button", { type: "button", className: "vx-mini", disabled: i === 0, "aria-label": `Move ${title} earlier`, onClick: () => move(i, -1), children: "\u2191" }), _jsx("button", { type: "button", className: "vx-mini", disabled: i === slides.length - 1, "aria-label": `Move ${title} later`, onClick: () => move(i, 1), children: "\u2193" }), _jsx("button", { type: "button", className: "vx-mini", "aria-label": `Remove ${title}`, onClick: () => set(slides.filter((_, j) => j !== i)), children: "Remove" })] })] }, i));
|
|
742
|
+
}), _jsx("div", { className: "vx-actions", children: _jsx("button", { type: "button", className: "vx-btn", "data-field": slides.length ? undefined : name, onFocus: onFocus, disabled: slides.length >= max, onClick: () => set([...slides, { image: null }]), children: "Add slide" }) })] }));
|
|
743
|
+
}
|
|
744
|
+
function MediaInput({ name, def, value, onChange, onFocus }) {
|
|
745
|
+
const [picking, setPicking] = useState(false);
|
|
746
|
+
const [search, setSearch] = useState('');
|
|
747
|
+
const [items, setItems] = useState(null);
|
|
748
|
+
const [error, setError] = useState(null);
|
|
749
|
+
const searchId = useId();
|
|
750
|
+
const labelId = useId();
|
|
751
|
+
useEffect(() => {
|
|
752
|
+
if (!picking)
|
|
753
|
+
return;
|
|
754
|
+
const t = setTimeout(() => {
|
|
755
|
+
call(`media${search ? `?search=${encodeURIComponent(search)}` : ''}`)
|
|
756
|
+
.then((r) => {
|
|
757
|
+
setItems(r.data);
|
|
758
|
+
setError(null);
|
|
759
|
+
})
|
|
760
|
+
.catch((err) => setError(err instanceof EditorError ? err.problems.join(' ') : 'Could not load images.'));
|
|
761
|
+
}, 250);
|
|
762
|
+
return () => clearTimeout(t);
|
|
763
|
+
}, [picking, search]);
|
|
764
|
+
return (_jsxs("div", { className: "vx-field", role: "group", "aria-labelledby": labelId, children: [_jsxs("span", { id: labelId, className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), value?.url ? _jsx("img", { className: "vx-preview", src: value.url, alt: value.alt ?? '' }) : _jsx("p", { className: "vx-muted", children: "No image chosen." }), _jsxs("div", { className: "vx-actions", children: [_jsx("button", { type: "button", className: "vx-btn", "data-field": name, onFocus: onFocus, "aria-expanded": picking, onClick: () => setPicking((p) => !p), children: picking ? 'Close library' : value ? 'Replace image' : 'Choose image' }), value && !def.required ? (_jsx("button", { type: "button", className: "vx-btn", onClick: () => onChange(null), children: "Remove" })) : null] }), picking ? (_jsxs("div", { className: "vx-picker", children: [_jsx("label", { htmlFor: searchId, className: "vx-sublabel", children: "Search the media library" }), _jsx("input", { id: searchId, type: "search", value: search, onChange: (e) => setSearch(e.target.value) }), error ? _jsx("p", { role: "alert", children: error }) : null, items && items.length === 0 ? _jsx("p", { className: "vx-muted", children: "No images found." }) : null, _jsx("div", { className: "vx-grid", children: (items ?? []).map((m) => (_jsxs("button", { type: "button", "aria-pressed": value?.id === m.id, onClick: () => {
|
|
765
|
+
onChange({ id: m.id, url: m.url, alt: m.alt });
|
|
766
|
+
setPicking(false);
|
|
767
|
+
}, children: [_jsx("img", { src: m.thumbUrl, alt: "" }), _jsx("span", { children: m.alt || m.name })] }, m.id))) })] })) : null] }));
|
|
768
|
+
}
|
|
769
|
+
// ----------------------------------------------------------------- styles
|
|
770
|
+
// Scoped by the vx- prefix and reset at .vx-root so the site's own CSS
|
|
771
|
+
// neither leaks in much nor gets touched.
|
|
772
|
+
const STYLES = `
|
|
773
|
+
.vx-root{all:initial;font:14px/1.45 system-ui,-apple-system,"Segoe UI",sans-serif;color:#18181b}
|
|
774
|
+
.vx-root *{box-sizing:border-box;font:inherit;color:inherit}
|
|
775
|
+
.vx-root code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}
|
|
776
|
+
.vx-outline{position:fixed;z-index:2147483000;pointer-events:none;border:2px dashed #6d28d9;border-radius:6px}
|
|
777
|
+
.vx-outline-active{border-style:solid;box-shadow:0 0 0 4px rgba(109,40,217,.15)}
|
|
778
|
+
.vx-outline-field{border:2px solid #f59e0b;border-radius:4px}
|
|
779
|
+
.vx-outline-inline{border:2px solid #6d28d9;border-radius:6px;box-shadow:0 0 0 4px rgba(109,40,217,.18)}
|
|
780
|
+
.vx-inline-hint{position:fixed;z-index:2147483002;background:#18181b;color:#fafafa;font-size:12px;padding:5px 9px;border-radius:7px;box-shadow:0 6px 20px rgba(0,0,0,.25);white-space:nowrap;pointer-events:none}
|
|
781
|
+
.vx-inline-keys{color:#a1a1aa}
|
|
782
|
+
[data-veroxm-inline]{outline:none;cursor:text;caret-color:auto}
|
|
783
|
+
.vx-tag{position:absolute;top:-24px;left:-2px;background:#6d28d9;color:#fff;font-size:12px;padding:2px 8px;border-radius:4px;white-space:nowrap}
|
|
784
|
+
.vx-toolbar{position:fixed;z-index:2147483002;left:50%;bottom:16px;transform:translateX(-50%);width:max-content;display:flex;flex-wrap:wrap;align-items:center;gap:8px;max-width:calc(100vw - 32px);background:#18181b;color:#fafafa;padding:8px 10px;border-radius:12px;box-shadow:0 8px 30px rgba(0,0,0,.3)}
|
|
785
|
+
.vx-toolbar .vx-muted{color:#a1a1aa}
|
|
786
|
+
.vx-brand{display:flex;align-items:center;gap:6px;font-weight:600;padding:0 4px}
|
|
787
|
+
.vx-dot{width:8px;height:8px;border-radius:50%;background:#a78bfa}
|
|
788
|
+
.vx-ended{max-width:28rem}
|
|
789
|
+
.vx-btn{appearance:none;cursor:pointer;display:inline-flex;align-items:center;min-height:32px;padding:4px 12px;border-radius:8px;border:1px solid #d4d4d8;background:#fff;color:#18181b;text-decoration:none}
|
|
790
|
+
.vx-toolbar .vx-btn{background:#27272a;border-color:#3f3f46;color:#fafafa}
|
|
791
|
+
.vx-toolbar .vx-btn[aria-pressed="true"]{background:#4c1d95;border-color:#6d28d9}
|
|
792
|
+
.vx-btn:disabled{opacity:.5;cursor:not-allowed}
|
|
793
|
+
.vx-primary{background:#6d28d9;border-color:#6d28d9;color:#fff}
|
|
794
|
+
.vx-root :focus-visible{outline:2px solid #f59e0b;outline-offset:2px}
|
|
795
|
+
.vx-panel{position:fixed;z-index:2147483001;top:12px;right:12px;bottom:76px;width:min(380px,calc(100vw - 24px));display:flex;flex-direction:column;background:#fff;border:1px solid #e4e4e7;border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.18)}
|
|
796
|
+
.vx-panel-head{display:flex;justify-content:space-between;gap:8px;padding:14px 16px;border-bottom:1px solid #f4f4f5}
|
|
797
|
+
.vx-panel-head h2{margin:0;font-size:16px;font-weight:650}
|
|
798
|
+
.vx-panel-head p{margin:2px 0 0}
|
|
799
|
+
.vx-panel-body{flex:1;overflow:auto;padding:12px 16px}
|
|
800
|
+
.vx-panel-foot{border-top:1px solid #f4f4f5;padding:10px 16px}
|
|
801
|
+
.vx-icon{appearance:none;border:0;background:transparent;font-size:22px;line-height:1;cursor:pointer;width:32px;height:32px;border-radius:8px}
|
|
802
|
+
.vx-icon:hover{background:#f4f4f5}
|
|
803
|
+
.vx-muted{color:#71717a;margin:0}
|
|
804
|
+
.vx-note{background:#faf5ff;border:1px solid #e9d5ff;border-radius:8px;padding:8px 10px;margin:0 0 12px}
|
|
805
|
+
.vx-field{display:flex;flex-direction:column;gap:4px;margin:0 0 14px;border:0;padding:0}
|
|
806
|
+
.vx-check{flex-direction:row;align-items:center;gap:8px}
|
|
807
|
+
.vx-label{font-weight:600;padding:0}
|
|
808
|
+
.vx-sublabel{font-size:12px;color:#52525b;margin-top:4px}
|
|
809
|
+
.vx-field input[type=text],.vx-field input[type=number],.vx-field input[type=search],.vx-field textarea,.vx-field select{width:100%;padding:7px 9px;border:1px solid #d4d4d8;border-radius:8px;background:#fff}
|
|
810
|
+
.vx-field input::placeholder,.vx-field textarea::placeholder{color:#a1a1aa;opacity:1}
|
|
811
|
+
.vx-field textarea{resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}
|
|
812
|
+
.vx-count{font-size:12px;color:#71717a}
|
|
813
|
+
.vx-preview{max-width:100%;max-height:160px;border-radius:8px;object-fit:contain;background:#f4f4f5;align-self:flex-start}
|
|
814
|
+
.vx-picker{border:1px solid #e4e4e7;border-radius:10px;padding:8px;margin-top:6px}
|
|
815
|
+
.vx-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;margin-top:8px;max-height:240px;overflow:auto}
|
|
816
|
+
.vx-grid button{appearance:none;cursor:pointer;border:2px solid transparent;border-radius:8px;padding:2px;background:#f4f4f5;display:flex;flex-direction:column;gap:2px;font-size:11px;text-align:left}
|
|
817
|
+
.vx-grid button[aria-pressed="true"]{border-color:#6d28d9}
|
|
818
|
+
.vx-grid img{width:100%;aspect-ratio:1;object-fit:cover;border-radius:6px}
|
|
819
|
+
.vx-grid span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
820
|
+
.vx-status{margin:0 0 8px;min-height:20px;color:#52525b}
|
|
821
|
+
.vx-errors{margin:0 0 8px;padding-left:18px;color:#b91c1c}
|
|
822
|
+
.vx-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
|
|
823
|
+
.vx-actions[hidden]{display:none}
|
|
824
|
+
.vx-test{border:1px solid #ddd6fe;background:#faf5ff;border-radius:10px;padding:8px 10px;margin:0 0 12px;display:flex;flex-direction:column;gap:6px}
|
|
825
|
+
.vx-test-title{margin:0;font-weight:600}
|
|
826
|
+
.vx-tabs{display:flex;flex-wrap:wrap;gap:4px}
|
|
827
|
+
.vx-tab{appearance:none;cursor:pointer;border:1px solid #d4d4d8;background:#fff;border-radius:999px;padding:3px 10px;font-size:12px}
|
|
828
|
+
.vx-tab[aria-selected="true"]{background:#6d28d9;border-color:#6d28d9;color:#fff}
|
|
829
|
+
.vx-review{border:1px solid #fde68a;background:#fffbeb;border-radius:10px;padding:8px 10px;margin:0 0 10px;display:flex;flex-direction:column;gap:4px}
|
|
830
|
+
.vx-review-title{margin:0;font-weight:600}
|
|
831
|
+
.vx-review-comment{width:100%;padding:6px 8px;border:1px solid #d4d4d8;border-radius:8px;background:#fff;resize:vertical}
|
|
832
|
+
.vx-review-withdraw{align-self:flex-start;margin-top:4px}
|
|
833
|
+
.vx-list{position:fixed;z-index:2147483002;left:50%;bottom:70px;transform:translateX(-50%);width:min(360px,calc(100vw - 24px));max-height:50vh;overflow:auto;background:#fff;border:1px solid #e4e4e7;border-radius:12px;box-shadow:0 12px 40px rgba(0,0,0,.18);padding:10px}
|
|
834
|
+
.vx-list-title{font-weight:650;margin:0 0 6px}
|
|
835
|
+
.vx-list ul{list-style:none;margin:0;padding:0}
|
|
836
|
+
.vx-list button{appearance:none;cursor:pointer;width:100%;text-align:left;border:0;background:transparent;padding:8px;border-radius:8px;display:flex;gap:6px;align-items:baseline;flex-wrap:wrap}
|
|
837
|
+
.vx-list button:hover{background:#f4f4f5}
|
|
838
|
+
@media (prefers-color-scheme: dark){
|
|
839
|
+
.vx-root{color:#fafafa}
|
|
840
|
+
.vx-panel,.vx-list{background:#18181b;border-color:#3f3f46}
|
|
841
|
+
.vx-panel-head,.vx-panel-foot{border-color:#27272a}
|
|
842
|
+
.vx-icon:hover,.vx-list button:hover,.vx-grid button,.vx-preview{background:#27272a}
|
|
843
|
+
.vx-muted,.vx-count,.vx-sublabel,.vx-status{color:#a1a1aa}
|
|
844
|
+
.vx-note{background:#2e1065;border-color:#4c1d95}
|
|
845
|
+
.vx-field input[type=text],.vx-field input[type=number],.vx-field input[type=search],.vx-field textarea,.vx-field select{background:#09090b;border-color:#3f3f46}
|
|
846
|
+
.vx-btn{background:#27272a;border-color:#3f3f46;color:#fafafa}
|
|
847
|
+
.vx-primary{background:#7c3aed;border-color:#7c3aed}
|
|
848
|
+
.vx-picker{border-color:#3f3f46}
|
|
849
|
+
.vx-errors{color:#fca5a5}
|
|
850
|
+
.vx-review{background:#2a2108;border-color:#78590f}
|
|
851
|
+
.vx-test{background:#1e1035;border-color:#4c1d95}
|
|
852
|
+
.vx-tab{background:#18181b;border-color:#3f3f46}
|
|
853
|
+
.vx-tab[aria-selected="true"]{background:#7c3aed;border-color:#7c3aed}
|
|
854
|
+
.vx-review-comment{background:#09090b;border-color:#3f3f46}
|
|
855
|
+
}
|
|
856
|
+
`;
|