@veroxm/react-sdk 1.10.0 → 1.11.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 +26 -0
- package/dist/client-slots.d.ts +2 -2
- package/dist/client-slots.js +2 -2
- package/dist/editor/handler.js +2 -0
- package/dist/editor/i18n.d.ts +255 -0
- package/dist/editor/i18n.js +491 -0
- package/dist/editor/inline.d.ts +2 -0
- package/dist/editor/inline.js +1 -1
- package/dist/editor/menu-input.d.ts +1 -1
- package/dist/editor/menu-input.js +8 -6
- package/dist/editor/overlay.d.ts +35 -0
- package/dist/editor/overlay.js +247 -121
- package/dist/editor/rich-text.d.ts +1 -1
- package/dist/editor/rich-text.js +8 -6
- package/dist/editor/seed.d.ts +6 -0
- package/dist/editor/seed.js +18 -0
- package/dist/editor/ui-context.d.ts +4 -0
- package/dist/editor/ui-context.js +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/next/cached.d.ts +2 -2
- package/dist/next/index.d.ts +1 -1
- package/dist/next/slot.d.ts +2 -2
- package/dist/next/slot.js +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/site/site-parts.d.ts +8 -8
- package/dist/slots-core.d.ts +59 -22
- package/dist/slots-core.js +24 -3
- package/package.json +1 -1
package/dist/editor/overlay.js
CHANGED
|
@@ -9,27 +9,24 @@ import { parseVideoUrl } from '../site/video.js';
|
|
|
9
9
|
import { parseMapLink } from '../site/map-math.js';
|
|
10
10
|
import { CHART_KINDS, chartTableText, parseChartTable } from '../site/chart.js';
|
|
11
11
|
import { canEditInline, startInlineEdit } from './inline.js';
|
|
12
|
-
import { fallbackImage, isEmptyValue, readFallback, sameSiteImage, seedFromFallback } from './seed.js';
|
|
12
|
+
import { fallbackImage, fallbackItem, isEmptyValue, readFallback, sameSiteImage, seedFromFallback } from './seed.js';
|
|
13
|
+
import { Ui, useUi } from './ui-context.js';
|
|
14
|
+
import { EDITOR_LANGS, LANG_NAMES, createTranslator, editorLang, pickLabel } from './i18n.js';
|
|
13
15
|
function asComponentValue(v) {
|
|
14
16
|
return v && typeof v === 'object' && !Array.isArray(v) && typeof v.component === 'string' ? v : null;
|
|
15
17
|
}
|
|
16
|
-
const TEST_STATUS = {
|
|
17
|
-
draft: 'Test draft',
|
|
18
|
-
pending_approval: 'Test waiting for approval',
|
|
19
|
-
live: 'Test running',
|
|
20
|
-
paused: 'Test paused',
|
|
21
|
-
};
|
|
18
|
+
const TEST_STATUS = { draft: 'test.draft', pending_approval: 'test.pending_approval', live: 'test.live', paused: 'test.paused' };
|
|
22
19
|
function setPreviewCookie(value) {
|
|
23
20
|
document.cookie = value
|
|
24
21
|
? `${PREVIEW_COOKIE}=${encodeURIComponent(value)}; Path=/; SameSite=Lax`
|
|
25
22
|
: `${PREVIEW_COOKIE}=; Path=/; Max-Age=0; SameSite=Lax`;
|
|
26
23
|
}
|
|
27
24
|
const OUTCOME_NOTICE = {
|
|
28
|
-
published: '
|
|
29
|
-
submitted: '
|
|
30
|
-
approved: '
|
|
31
|
-
rejected: '
|
|
32
|
-
withdrawn: '
|
|
25
|
+
published: 'outcome.published',
|
|
26
|
+
submitted: 'outcome.submitted',
|
|
27
|
+
approved: 'outcome.approved',
|
|
28
|
+
rejected: 'outcome.rejected',
|
|
29
|
+
withdrawn: 'outcome.withdrawn',
|
|
33
30
|
};
|
|
34
31
|
class EditorError extends Error {
|
|
35
32
|
constructor(status, problems) {
|
|
@@ -57,7 +54,7 @@ async function call(path, init = {}) {
|
|
|
57
54
|
const res = await transport.request(path, { method: init.method ?? 'GET', body: init.body });
|
|
58
55
|
const body = (await res.json().catch(() => ({})));
|
|
59
56
|
if (!res.ok) {
|
|
60
|
-
const problems = body.errors ?? (body.error ? [body.error] : Array.isArray(body.message) ? body.message : [body.message ??
|
|
57
|
+
const problems = body.errors ?? (body.error ? [body.error] : Array.isArray(body.message) ? body.message : [body.message ?? currentUi.t('error.http', { status: String(res.status) })]);
|
|
61
58
|
throw new EditorError(res.status, problems);
|
|
62
59
|
}
|
|
63
60
|
return body;
|
|
@@ -92,16 +89,49 @@ function toPayload(fields, values) {
|
|
|
92
89
|
return out;
|
|
93
90
|
}
|
|
94
91
|
/** What the panel says after starting a slot from the page: which fields came from where. */
|
|
95
|
-
function seedNotice(s, seeded, locale) {
|
|
96
|
-
const label = (f) => s.fields[f]
|
|
97
|
-
const
|
|
92
|
+
function seedNotice(ui, s, seeded, locale) {
|
|
93
|
+
const label = (f) => fieldLabel(ui, s.fields[f], f);
|
|
94
|
+
const fields = ui.list(seeded.map(label));
|
|
98
95
|
if (!s.inherited)
|
|
99
|
-
return
|
|
96
|
+
return ui.t('seed.filled', { fields });
|
|
100
97
|
const rest = Object.keys(s.fields).filter((f) => !seeded.includes(f) && !isEmptyValue(s.values[f]));
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
return rest.length ? ui.t('seed.inheritedSplit', { locale, fields, rest: ui.list(rest.map(label)) }) : ui.t('seed.inheritedAll', { locale, fields });
|
|
99
|
+
}
|
|
100
|
+
// ------------------------------------------------------------- interface language
|
|
101
|
+
// The editor's own words follow the interface language: the editor's saved choice, else the page's language, else
|
|
102
|
+
// English. It never changes the content language being edited.
|
|
103
|
+
/** The interface language, for code outside React (request errors). */
|
|
104
|
+
let currentUi = createTranslator('en');
|
|
105
|
+
const PREFS_KEY = 'veroxm-editor-ui';
|
|
106
|
+
function readStoredPrefs() {
|
|
107
|
+
try {
|
|
108
|
+
const raw = JSON.parse(localStorage.getItem(PREFS_KEY) ?? 'null');
|
|
109
|
+
return raw && typeof raw === 'object' ? { language: editorLang(raw.language) ?? undefined, digits: raw.digits === 'arab' || raw.digits === 'latn' ? raw.digits : undefined } : {};
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function storePrefs(prefs) {
|
|
116
|
+
try {
|
|
117
|
+
localStorage.setItem(PREFS_KEY, JSON.stringify(prefs));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// Private windows and blocked storage: the choice still lasts for this page.
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** The page's language: its slots' locale (data-veroxm-locale), then <html lang>. */
|
|
124
|
+
function pageLanguage() {
|
|
125
|
+
for (const el of Array.from(document.querySelectorAll('[data-veroxm-slot][data-veroxm-locale]'))) {
|
|
126
|
+
const lang = editorLang(el.getAttribute('data-veroxm-locale'));
|
|
127
|
+
if (lang)
|
|
128
|
+
return lang;
|
|
129
|
+
}
|
|
130
|
+
return editorLang(document.documentElement.getAttribute('lang'));
|
|
131
|
+
}
|
|
132
|
+
/** A field's label in the interface language (the site's per-language labels, else its one label), else its name. */
|
|
133
|
+
function fieldLabel(ui, def, name) {
|
|
134
|
+
return pickLabel(ui.lang, def?.label, def?.labels) ?? name;
|
|
105
135
|
}
|
|
106
136
|
/** What the open panel may do beyond editing (read deep inside the form, by the image fields). */
|
|
107
137
|
const PanelCaps = createContext({ canUploadMedia: false });
|
|
@@ -148,7 +178,16 @@ function findPageSlots() {
|
|
|
148
178
|
if (!name || seen.has(key))
|
|
149
179
|
return;
|
|
150
180
|
seen.add(key);
|
|
151
|
-
|
|
181
|
+
let labels = null;
|
|
182
|
+
try {
|
|
183
|
+
const raw = JSON.parse(el.getAttribute('data-veroxm-labels') ?? 'null');
|
|
184
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw))
|
|
185
|
+
labels = raw;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
labels = null;
|
|
189
|
+
}
|
|
190
|
+
out.push({ name, locale, label: el.getAttribute('data-veroxm-label') || name, labels, el });
|
|
152
191
|
});
|
|
153
192
|
return out;
|
|
154
193
|
}
|
|
@@ -264,6 +303,16 @@ function Overlay({ onChange, tools }) {
|
|
|
264
303
|
const [highlightField, setHighlightField] = useState(null);
|
|
265
304
|
const [inlineHint, setInlineHint] = useState(null);
|
|
266
305
|
useLayoutTick(Boolean(hover || open || inlineHint), rootRef);
|
|
306
|
+
// Interface language: the editor's choice (VeroXM's copy wins over this browser's), else the page's, else English.
|
|
307
|
+
const [prefs, setPrefs] = useState(readStoredPrefs);
|
|
308
|
+
const [pageLang] = useState(pageLanguage);
|
|
309
|
+
const ui = createTranslator(prefs.language ?? pageLang ?? 'en', { digits: prefs.digits ?? 'latn' });
|
|
310
|
+
currentUi = ui;
|
|
311
|
+
const savePrefs = (next) => {
|
|
312
|
+
setPrefs(next);
|
|
313
|
+
storePrefs(next);
|
|
314
|
+
call('preferences', { method: 'PUT', body: { language: next.language ?? null, digits: next.digits ?? null } }).catch(() => undefined);
|
|
315
|
+
};
|
|
267
316
|
useEffect(() => {
|
|
268
317
|
openFromOutside = (name, locale) => {
|
|
269
318
|
setListOpen(false);
|
|
@@ -275,8 +324,16 @@ function Overlay({ onChange, tools }) {
|
|
|
275
324
|
}, []);
|
|
276
325
|
useEffect(() => {
|
|
277
326
|
call('session')
|
|
278
|
-
.then(
|
|
279
|
-
|
|
327
|
+
.then((s) => {
|
|
328
|
+
setSession(s);
|
|
329
|
+
const saved = s.editorPrefs;
|
|
330
|
+
if (saved?.language || saved?.digits) {
|
|
331
|
+
const next = { language: editorLang(saved.language) ?? undefined, digits: saved.digits ?? undefined };
|
|
332
|
+
setPrefs((prev) => ({ language: next.language ?? prev.language, digits: next.digits ?? prev.digits }));
|
|
333
|
+
storePrefs(next);
|
|
334
|
+
}
|
|
335
|
+
})
|
|
336
|
+
.catch((err) => setEnded(err instanceof EditorError ? err.problems.join(' ') : currentUi.t('error.unreachable')));
|
|
280
337
|
}, []);
|
|
281
338
|
// Once the session is confirmed: the site's own text for each slot, for
|
|
282
339
|
// the dashboard. Again shortly after, for slots whose fallback arrives late.
|
|
@@ -341,42 +398,59 @@ function Overlay({ onChange, tools }) {
|
|
|
341
398
|
const hoverRect = hover && hover !== openEl ? rectOf(hover) : null;
|
|
342
399
|
const openRect = rectOf(openEl);
|
|
343
400
|
const fieldRect = openEl && highlightField ? rectOf(openEl.querySelector(`[data-veroxm-field="${CSS.escape(highlightField)}"]`)) : null;
|
|
344
|
-
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
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
401
|
+
return (_jsx(Ui.Provider, { value: ui, children: _jsxs("div", { ref: rootRef, className: "vx-root", "data-veroxm-overlay": "", dir: ui.dir, lang: ui.lang, children: [_jsx("style", { children: STYLES + RICH_TEXT_STYLES + MENU_STYLES }), hoverRect && _jsx(Outline, { rect: hoverRect, label: hover ? elementLabel(ui, hover) : '' }), 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, canUploadMedia: session.canUploadMedia ?? false, dashboardUrl: session.dashboardUrl ?? null, onClose: () => {
|
|
402
|
+
setOpen(null);
|
|
403
|
+
setHighlightField(null);
|
|
404
|
+
}, onFieldFocus: setHighlightField, onSessionError: onSessionError, onChange: onChange, onInline: setInlineHint }, `${open.name}|${open.locale}`)), listOpen && (_jsx(SlotList, { onPick: (s) => {
|
|
405
|
+
setListOpen(false);
|
|
406
|
+
s.el.firstElementChild?.scrollIntoView?.({ block: 'center', behavior: 'smooth' });
|
|
407
|
+
setOpen({ name: s.name, locale: s.locale });
|
|
408
|
+
}, onClose: () => {
|
|
409
|
+
setListOpen(false);
|
|
410
|
+
listToggleRef.current?.focus();
|
|
411
|
+
} })), _jsxs("div", { className: "vx-toolbar", role: "toolbar", "aria-label": ui.t('bar.aria'), dir: ui.dir, lang: ui.lang, children: [_jsxs("span", { className: "vx-brand", children: [_jsx("span", { className: "vx-dot", "aria-hidden": "true" }), ended ? ui.t('bar.ended') : ui.t('bar.editing'), session?.projectName ? (_jsxs("span", { className: "vx-muted", children: [' · ', _jsx("bdi", { children: 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 ? ui.t('bar.clickOn') : ui.t('bar.clickOff') }), _jsx("button", { type: "button", ref: listToggleRef, className: "vx-btn", "data-vx-list-toggle": "", "aria-expanded": listOpen, onClick: () => setListOpen((v) => !v), children: ui.t('bar.slots') }), tools] })), _jsx("select", { className: "vx-lang", "aria-label": ui.t('bar.language'), value: ui.lang, onChange: (e) => savePrefs({ ...prefs, language: editorLang(e.target.value) ?? 'en' }), children: EDITOR_LANGS.map((l) => (_jsx("option", { value: l, lang: l, children: LANG_NAMES[l] }, l))) }), ui.lang === 'ar' ? (_jsxs("select", { className: "vx-lang", "aria-label": ui.t('bar.digits'), value: ui.digits, onChange: (e) => savePrefs({ ...prefs, digits: e.target.value === 'arab' ? 'arab' : 'latn' }), children: [_jsx("option", { value: "latn", children: ui.t('bar.digitsLatn') }), _jsx("option", { value: "arab", children: ui.t('bar.digitsArab') })] })) : null, _jsx("button", { type: "button", className: "vx-btn", onClick: () => transport.exit(), children: ui.t('bar.exit') })] })] }) }));
|
|
412
|
+
}
|
|
413
|
+
/** A slot's name on the page, in the interface language (data-veroxm-labels), else its one label, else its name. */
|
|
414
|
+
function elementLabel(ui, el) {
|
|
415
|
+
let labels = null;
|
|
416
|
+
try {
|
|
417
|
+
labels = JSON.parse(el.getAttribute('data-veroxm-labels') ?? 'null');
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
labels = null;
|
|
421
|
+
}
|
|
422
|
+
return pickLabel(ui.lang, el.getAttribute('data-veroxm-label'), labels) || el.getAttribute('data-veroxm-slot') || '';
|
|
355
423
|
}
|
|
356
424
|
function InlineHintBar({ hint }) {
|
|
425
|
+
const ui = useUi();
|
|
357
426
|
const rect = rectOf(hint.el);
|
|
358
427
|
if (!rect)
|
|
359
428
|
return null;
|
|
360
429
|
const below = rect.bottom + 40 < window.innerHeight;
|
|
361
|
-
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: ["
|
|
430
|
+
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: [' · ', _jsx("bdi", { dir: "ltr", children: ui.t('text.count', { n: hint.length, max: hint.max }) })] })) : null, _jsxs("span", { className: "vx-inline-keys", children: [" \u00B7 ", ui.t('inline.keys')] })] })] }));
|
|
362
431
|
}
|
|
363
432
|
function Outline({ rect, label, active, field }) {
|
|
364
433
|
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 }));
|
|
365
434
|
}
|
|
366
435
|
// -------------------------------------------------------------- slot list
|
|
367
436
|
function SlotList({ onPick, onClose }) {
|
|
437
|
+
const ui = useUi();
|
|
368
438
|
const [slots] = useState(findPageSlots);
|
|
369
439
|
const firstRef = useRef(null);
|
|
370
440
|
useEffect(() => firstRef.current?.focus(), []);
|
|
371
|
-
return (_jsxs("div", { className: "vx-list", role: "dialog", "aria-label":
|
|
441
|
+
return (_jsxs("div", { className: "vx-list", role: "dialog", "aria-label": ui.t('bar.slots'), onKeyDown: (e) => {
|
|
372
442
|
if (e.key !== 'Escape')
|
|
373
443
|
return;
|
|
374
444
|
e.stopPropagation();
|
|
375
445
|
onClose();
|
|
376
|
-
}, children: [_jsx("p", { className: "vx-list-title", children:
|
|
446
|
+
}, children: [_jsx("p", { className: "vx-list-title", children: ui.t('bar.slots') }), slots.length === 0 ? (_jsx("p", { className: "vx-muted", children: ui.t('list.empty') })) : (_jsx("ul", { children: slots.map((s, i) => {
|
|
447
|
+
const label = pickLabel(ui.lang, s.label, s.labels) || s.name;
|
|
448
|
+
return (_jsx("li", { children: _jsxs("button", { type: "button", ref: i === 0 ? firstRef : undefined, onClick: () => onPick(s), children: [_jsx("span", { children: label }), label !== s.name ? (_jsx("code", { children: _jsx("bdi", { children: s.name }) })) : null, s.locale ? (_jsxs("span", { className: "vx-muted", children: [' · ', _jsx("bdi", { children: s.locale })] })) : null] }) }, `${s.name}|${s.locale}`));
|
|
449
|
+
}) }))] }));
|
|
377
450
|
}
|
|
378
451
|
const AUTOSAVE_MS = 800;
|
|
379
452
|
function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, dashboardUrl, onClose, onFieldFocus, onSessionError, onChange, onInline, }) {
|
|
453
|
+
const ui = useUi();
|
|
380
454
|
const titleId = useId();
|
|
381
455
|
const panelRef = useRef(null);
|
|
382
456
|
const returnFocus = useRef(typeof document !== 'undefined' ? document.activeElement : null);
|
|
@@ -421,7 +495,7 @@ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, d
|
|
|
421
495
|
setLocale(res.locale);
|
|
422
496
|
const s = res.slots[slot.name];
|
|
423
497
|
if (!s)
|
|
424
|
-
setLoadError('
|
|
498
|
+
setLoadError(currentUi.t('error.unknownSlot'));
|
|
425
499
|
else {
|
|
426
500
|
if (position === 0)
|
|
427
501
|
baseValues.current = s.values;
|
|
@@ -441,14 +515,14 @@ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, d
|
|
|
441
515
|
touched.current.add(f);
|
|
442
516
|
setValues(seededValues);
|
|
443
517
|
latest.current = seededValues;
|
|
444
|
-
setNotice(seedNotice(s, seeded, res.locale));
|
|
518
|
+
setNotice(seedNotice(currentUi, s, seeded, res.locale));
|
|
445
519
|
}
|
|
446
520
|
}
|
|
447
521
|
}
|
|
448
522
|
}
|
|
449
523
|
catch (err) {
|
|
450
524
|
onSessionError(err);
|
|
451
|
-
setLoadError(err instanceof EditorError ? err.problems.join(' ') : '
|
|
525
|
+
setLoadError(err instanceof EditorError ? err.problems.join(' ') : currentUi.t('error.unreachable'));
|
|
452
526
|
}
|
|
453
527
|
}, [slot.name, slot.locale, apply, onSessionError]);
|
|
454
528
|
useEffect(() => {
|
|
@@ -508,7 +582,7 @@ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, d
|
|
|
508
582
|
}
|
|
509
583
|
catch (err) {
|
|
510
584
|
onSessionError(err);
|
|
511
|
-
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['
|
|
585
|
+
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : [currentUi.t('error.save')] });
|
|
512
586
|
return false;
|
|
513
587
|
}
|
|
514
588
|
}, [data, locale, slot.name, onChange, onSessionError, load]);
|
|
@@ -548,11 +622,12 @@ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, d
|
|
|
548
622
|
// Nothing stored: start from the text the page shows (its fallback), not an empty box.
|
|
549
623
|
const startText = isEmptyValue(before) && typeof shownRef.current[target.field] === 'string' ? shownRef.current[target.field] : undefined;
|
|
550
624
|
let typed = false;
|
|
551
|
-
const label = def
|
|
625
|
+
const label = fieldLabel(currentUi, def, target.field);
|
|
552
626
|
onFieldFocus(target.field);
|
|
553
627
|
onInline({ el: target.el, label, length: target.el.textContent?.length ?? 0, max: def.max });
|
|
554
628
|
inlineRef.current = startInlineEdit(target.el, {
|
|
555
629
|
label,
|
|
630
|
+
ariaLabel: currentUi.t('inline.aria', { label }),
|
|
556
631
|
max: def.max,
|
|
557
632
|
point: target.point,
|
|
558
633
|
initialText: startText,
|
|
@@ -612,14 +687,15 @@ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, d
|
|
|
612
687
|
});
|
|
613
688
|
apply(res.slot);
|
|
614
689
|
setSave({ kind: 'idle' });
|
|
615
|
-
|
|
690
|
+
const outcome = OUTCOME_NOTICE[res.outcome];
|
|
691
|
+
setNotice(outcome ? ui.t(outcome) : null);
|
|
616
692
|
setReviewComment('');
|
|
617
693
|
if (res.outcome === 'published' || verb === 'publish')
|
|
618
694
|
onChange();
|
|
619
695
|
}
|
|
620
696
|
catch (err) {
|
|
621
697
|
onSessionError(err);
|
|
622
|
-
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['
|
|
698
|
+
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : [ui.t('error.generic')] });
|
|
623
699
|
}
|
|
624
700
|
finally {
|
|
625
701
|
setBusy(null);
|
|
@@ -634,13 +710,13 @@ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, d
|
|
|
634
710
|
setBusy('discard');
|
|
635
711
|
try {
|
|
636
712
|
apply(await call(slotPath(slot.name, locale, '/discard'), { method: 'POST' }));
|
|
637
|
-
setNotice('
|
|
713
|
+
setNotice(ui.t('notice.discarded'));
|
|
638
714
|
setSave({ kind: 'idle' });
|
|
639
715
|
onChange();
|
|
640
716
|
}
|
|
641
717
|
catch (err) {
|
|
642
718
|
onSessionError(err);
|
|
643
|
-
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['
|
|
719
|
+
setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : [ui.t('error.discard')] });
|
|
644
720
|
}
|
|
645
721
|
finally {
|
|
646
722
|
setBusy(null);
|
|
@@ -665,23 +741,25 @@ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, d
|
|
|
665
741
|
setValues(next);
|
|
666
742
|
latest.current = next;
|
|
667
743
|
setConfirmDiscard(false);
|
|
668
|
-
setNotice(
|
|
744
|
+
setNotice(ui.t('fill.done', { fields: ui.list(seeded.map((f) => fieldLabel(ui, data.fields[f], f))) }));
|
|
669
745
|
};
|
|
670
746
|
const dirty = Boolean(data?.unpublishedChanges) || save.kind === 'saving' || latest.current !== null;
|
|
671
|
-
const title = data?.label || slot.name;
|
|
747
|
+
const title = pickLabel(ui.lang, data?.label, data?.labels) || slot.name;
|
|
672
748
|
const approval = data?.approval ?? null;
|
|
673
|
-
return (_jsx(PanelCaps.Provider, { value: { canUploadMedia }, children: _jsxs("div", { ref: panelRef, className: "vx-panel", role: "dialog", "aria-modal": "false", "aria-labelledby": titleId, onKeyDown: (e) => {
|
|
749
|
+
return (_jsx(PanelCaps.Provider, { value: { canUploadMedia }, children: _jsxs("div", { ref: panelRef, className: "vx-panel", dir: ui.dir, lang: ui.lang, role: "dialog", "aria-modal": "false", "aria-labelledby": titleId, onKeyDown: (e) => {
|
|
674
750
|
if (e.key === 'Escape') {
|
|
675
751
|
e.stopPropagation();
|
|
676
752
|
close();
|
|
677
753
|
}
|
|
678
|
-
}, 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: [
|
|
679
|
-
// Arrow keys move between versions (one tab stop for the whole list).
|
|
754
|
+
}, children: [_jsxs("div", { className: "vx-panel-head", children: [_jsxs("div", { children: [_jsx("h2", { id: titleId, children: title }), _jsxs("p", { className: "vx-muted vx-slot-key", children: [title !== slot.name ? (_jsx("code", { children: _jsx("bdi", { children: slot.name }) })) : null, locale ? (_jsxs("span", { children: [' · ', _jsx("bdi", { children: locale })] })) : null, data ? (_jsxs("span", { children: [' · ', _jsx("bdi", { children: data.version ? ui.t('panel.live', { version: data.version }) : ui.t('panel.neverPublished') })] })) : null] })] }), _jsx("button", { type: "button", className: "vx-icon", "aria-label": ui.t('panel.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: ui.t('panel.loading') }) : null, data?.test ? (_jsxs("div", { className: "vx-test", children: [_jsxs("p", { className: "vx-test-title", children: [ui.t(TEST_STATUS[data.test.status] ?? 'test.generic'), ": ", _jsx("bdi", { children: data.test.name })] }), _jsx("div", { className: "vx-tabs", role: "tablist", "aria-label": ui.t('test.versions'), onKeyDown: (e) => {
|
|
755
|
+
// Arrow keys move between versions (one tab stop for the whole list); right to left, the arrows swap.
|
|
680
756
|
const order = data.test.variants.map((v) => v.position);
|
|
681
757
|
const at = order.indexOf(variant);
|
|
682
|
-
const
|
|
758
|
+
const forward = ui.dir === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
|
|
759
|
+
const back = ui.dir === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
|
|
760
|
+
const next = e.key === forward || e.key === 'ArrowDown'
|
|
683
761
|
? order[(at + 1) % order.length]
|
|
684
|
-
: e.key ===
|
|
762
|
+
: e.key === back || e.key === 'ArrowUp'
|
|
685
763
|
? order[(at - 1 + order.length) % order.length]
|
|
686
764
|
: e.key === 'Home'
|
|
687
765
|
? order[0]
|
|
@@ -693,59 +771,66 @@ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, d
|
|
|
693
771
|
e.preventDefault();
|
|
694
772
|
void selectVariant(next);
|
|
695
773
|
e.currentTarget.querySelector(`[data-position="${next}"]`)?.focus();
|
|
696
|
-
}, 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 ? '
|
|
697
|
-
? 'The page shows this variant. Edits change only this variant; empty fields use the published version.'
|
|
698
|
-
: data.test.editable
|
|
699
|
-
? 'The page shows this variant. Editing variants needs permission to manage experiments.'
|
|
700
|
-
: 'The page shows this variant. Variants can’t change once the test has started.' })) : null] })) : null, data?.inherited && locale && !touched.current.size ? (_jsxs("p", { className: "vx-note", children: ["Nothing saved in ", locale, " yet; you\u2019re starting from the default language\u2019s published copy."] })) : null, fillable.length ? (_jsxs("div", { className: "vx-fill", children: [_jsxs("p", { className: "vx-muted", children: ["Empty here, but the page shows content for: ", fillable.map((f) => data?.fields[f]?.label ?? f).join(', '), "."] }), _jsx("button", { type: "button", className: "vx-btn", onClick: fillFromPage, children: "Fill empty fields from the page" })] })) : null, data
|
|
774
|
+
}, 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 ? ui.t('test.published') : _jsx("bdi", { children: v.label }) }, v.position))) }), variant > 0 ? (_jsx("p", { className: "vx-muted", children: data.test.editable && canManageTests ? ui.t('test.editable') : data.test.editable ? ui.t('test.noPermission') : ui.t('test.locked') })) : null] })) : null, data?.inherited && locale && !touched.current.size ? (_jsx("p", { className: "vx-note", children: ui.t('panel.inherited', { locale }) })) : null, fillable.length ? (_jsxs("div", { className: "vx-fill", children: [_jsx("p", { className: "vx-muted", children: ui.t('fill.offer', { fields: ui.list(fillable.map((f) => fieldLabel(ui, data?.fields[f], f))) }) }), _jsx("button", { type: "button", className: "vx-btn", onClick: fillFromPage, children: ui.t('fill.button') })] })) : null, data
|
|
701
775
|
? (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], fallback: fallback?.[name], onChange: (v) => change(name, v), onFocus: () => onFieldFocus(name) }, name)))
|
|
702
776
|
: null] }), _jsxs("div", { className: "vx-panel-foot", children: [_jsx("p", { className: "vx-status", role: "status", "aria-live": "polite", children: save.kind === 'saving'
|
|
703
777
|
? variant > 0
|
|
704
|
-
? '
|
|
705
|
-
: '
|
|
778
|
+
? ui.t('status.savingVariant')
|
|
779
|
+
: ui.t('status.savingDraft')
|
|
706
780
|
: save.kind === 'saved'
|
|
707
781
|
? variant > 0
|
|
708
|
-
? '
|
|
709
|
-
: '
|
|
782
|
+
? ui.t('status.variantSaved')
|
|
783
|
+
: ui.t('status.draftSaved')
|
|
710
784
|
: save.kind === 'error'
|
|
711
785
|
? ''
|
|
712
786
|
: latest.current !== null
|
|
713
|
-
? (notice ?? '
|
|
714
|
-
: notice ?? (data?.unpublishedChanges ? '
|
|
715
|
-
? ` · step
|
|
716
|
-
: ''] }), _jsxs("p", { className: "vx-muted", children: [approval.steps.find((st) => st.stepOrder === approval.currentStep)?.label, approval.submittedByName ? ` ·
|
|
787
|
+
? (notice ?? ui.t('status.editing'))
|
|
788
|
+
: notice ?? (data?.unpublishedChanges ? ui.t('status.unpublished') : data ? ui.t('status.clean') : '') }), 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: ui.t('test.settings') })) : null, _jsx("button", { type: "button", className: "vx-btn", onClick: () => void selectVariant(0), children: ui.t('test.back') })] })) : null, variant === 0 && approval?.pending ? (_jsxs("div", { className: "vx-review", role: "group", "aria-label": ui.t('approval.aria'), children: [_jsxs("p", { className: "vx-review-title", children: [ui.t('approval.waiting'), approval.steps.length > 1 && approval.currentStep !== null
|
|
789
|
+
? ` · ${ui.t('approval.step', { n: approval.steps.findIndex((st) => st.stepOrder === approval.currentStep) + 1, total: approval.steps.length })}`
|
|
790
|
+
: ''] }), _jsxs("p", { className: "vx-muted", children: [approval.steps.find((st) => st.stepOrder === approval.currentStep)?.label, approval.submittedByName ? ` · ${ui.t('approval.sentBy', { name: approval.submittedByName })}` : ''] }), approval.changedSinceSubmission ? _jsx("p", { className: "vx-muted", children: ui.t('approval.changed') }) : null, approval.canAct ? (_jsxs(_Fragment, { children: [_jsx("label", { className: "vx-sublabel", htmlFor: `${titleId}-review`, children: ui.t('approval.comment') }), _jsx("textarea", { dir: "auto", 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'
|
|
791
|
+
? ui.t('approval.approving')
|
|
792
|
+
: approval.steps[approval.steps.length - 1]?.stepOrder === approval.currentStep
|
|
793
|
+
? ui.t('approval.approvePublish')
|
|
794
|
+
: ui.t('approval.approve') }), _jsx("button", { type: "button", className: "vx-btn", disabled: busy !== null || !reviewComment.trim(), onClick: () => act('reject', { comment: reviewComment }), children: busy === 'reject' ? ui.t('approval.rejecting') : ui.t('approval.reject') })] })] })) : approval.isSubmitter ? (_jsx("p", { className: "vx-muted", children: ui.t('approval.other') })) : null, approval.canWithdraw ? (_jsx("button", { type: "button", className: "vx-btn vx-review-withdraw", disabled: busy !== null, onClick: () => act('withdraw'), children: busy === 'withdraw' ? ui.t('approval.withdrawing') : ui.t('approval.withdraw') })) : 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'
|
|
795
|
+
? approval?.required
|
|
796
|
+
? ui.t('publish.sending')
|
|
797
|
+
: ui.t('publish.busy')
|
|
798
|
+
: approval?.required
|
|
799
|
+
? ui.t('publish.send')
|
|
800
|
+
: ui.t('publish.button') })) : (_jsx("span", { className: "vx-muted", children: ui.t('publish.noPermission') })), data?.unpublishedChanges && data.version > 0 ? (_jsx("button", { type: "button", className: "vx-btn", disabled: busy !== null, onClick: discard, children: busy === 'discard' ? ui.t('discard.busy') : confirmDiscard ? ui.t('discard.confirm') : ui.t('discard.button') })) : null] })] })] }) }));
|
|
717
801
|
}
|
|
718
802
|
// ----------------------------------------------------------------- fields
|
|
719
803
|
function stripTags(html) {
|
|
720
804
|
return html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
721
805
|
}
|
|
722
806
|
function FieldInput({ name, def, value, shown, fallback, onChange, onFocus, }) {
|
|
807
|
+
const ui = useUi();
|
|
723
808
|
const placeholder = typeof shown === 'string' && shown ? shown : undefined;
|
|
724
809
|
const id = useId();
|
|
725
|
-
const label = (_jsxs("label", { htmlFor: id, className: "vx-label", children: [def
|
|
810
|
+
const label = (_jsxs("label", { htmlFor: id, className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }));
|
|
726
811
|
const common = { id, 'data-field': name, onFocus, 'aria-required': def.required || undefined };
|
|
727
812
|
switch (def.type) {
|
|
728
813
|
case 'text': {
|
|
729
814
|
const text = typeof value === 'string' ? value : '';
|
|
730
|
-
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 ?
|
|
815
|
+
return (_jsxs("div", { className: "vx-field", children: [label, _jsx("input", { ...common, type: "text", dir: "auto", value: text, placeholder: placeholder, maxLength: def.max, onChange: (e) => onChange(e.target.value) }), def.max ? (_jsx("span", { className: "vx-count", children: _jsx("bdi", { dir: "ltr", children: ui.t('text.count', { n: text.length, max: def.max }) }) })) : null] }));
|
|
731
816
|
}
|
|
732
817
|
case 'richText': {
|
|
733
818
|
const html = typeof value === 'string' ? value : '';
|
|
734
|
-
return (_jsxs("div", { className: "vx-field", children: [_jsxs("span", { id: `${id}-label`, className: "vx-label", children: [def
|
|
819
|
+
return (_jsxs("div", { className: "vx-field", children: [_jsxs("span", { id: `${id}-label`, className: "vx-label", children: [fieldLabel(ui, def, 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 } })] }));
|
|
735
820
|
}
|
|
736
821
|
case 'number':
|
|
737
822
|
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)) })] }));
|
|
738
823
|
case 'boolean':
|
|
739
824
|
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] }));
|
|
740
825
|
case 'select':
|
|
741
|
-
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)))] })] }));
|
|
826
|
+
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: pickLabel(ui.lang, undefined, def.optionLabels?.[o]) ?? o }, o)))] })] }));
|
|
742
827
|
case 'link': {
|
|
743
828
|
const link = (value && typeof value === 'object' ? value : { label: '', href: '' });
|
|
744
829
|
const set = (patch) => {
|
|
745
830
|
const next = { ...link, ...patch };
|
|
746
831
|
onChange(next.label || next.href ? next : null);
|
|
747
832
|
};
|
|
748
|
-
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def
|
|
833
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx("label", { htmlFor: `${id}-label`, className: "vx-sublabel", children: ui.t('link.text') }), _jsx("input", { id: `${id}-label`, "data-field": name, onFocus: onFocus, type: "text", dir: "auto", value: link.label, onChange: (e) => set({ label: e.target.value }) }), _jsx("label", { htmlFor: `${id}-href`, className: "vx-sublabel", children: ui.t('link.address') }), _jsx("input", { id: `${id}-href`, onFocus: onFocus, type: "text", dir: "auto", inputMode: "url", placeholder: ui.t('common.pagePlaceholder'), value: link.href, onChange: (e) => set({ href: e.target.value }) })] }));
|
|
749
834
|
}
|
|
750
835
|
case 'media':
|
|
751
836
|
return _jsx(MediaInput, { name: name, def: def, value: value, fallback: fallback, onChange: onChange, onFocus: onFocus });
|
|
@@ -756,20 +841,21 @@ function FieldInput({ name, def, value, shown, fallback, onChange, onFocus, }) {
|
|
|
756
841
|
case 'map':
|
|
757
842
|
return _jsx(MapInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
758
843
|
case 'slides':
|
|
759
|
-
return _jsx(SlidesInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
844
|
+
return _jsx(SlidesInput, { name: name, def: def, value: value, fallback: fallback, onChange: onChange, onFocus: onFocus });
|
|
760
845
|
case 'menu':
|
|
761
|
-
return _jsx(MenuInput, { name: name, label: def
|
|
846
|
+
return _jsx(MenuInput, { name: name, label: fieldLabel(ui, def, name), required: def.required, depth: def.depth ?? 2, icons: def.icons, value: value, onChange: onChange, onFocus: onFocus });
|
|
762
847
|
case 'list':
|
|
763
|
-
return _jsx(ListInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
848
|
+
return _jsx(ListInput, { name: name, def: def, value: value, fallback: fallback, onChange: onChange, onFocus: onFocus });
|
|
764
849
|
case 'component':
|
|
765
|
-
return _jsx(ComponentInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
|
|
850
|
+
return _jsx(ComponentInput, { name: name, def: def, value: value, fallback: fallback, onChange: onChange, onFocus: onFocus });
|
|
766
851
|
}
|
|
767
852
|
}
|
|
768
853
|
/**
|
|
769
854
|
* A component field: choose one of the components the developer registered for this place, then fill in that
|
|
770
855
|
* component's own fields. Switching components keeps what was typed into fields both have (same name and type).
|
|
771
856
|
*/
|
|
772
|
-
function ComponentInput({ name, def, value, onChange, onFocus }) {
|
|
857
|
+
function ComponentInput({ name, def, value, fallback, onChange, onFocus }) {
|
|
858
|
+
const ui = useUi();
|
|
773
859
|
const id = useId();
|
|
774
860
|
const components = def.components ?? {};
|
|
775
861
|
const current = asComponentValue(value);
|
|
@@ -788,11 +874,12 @@ function ComponentInput({ name, def, value, onChange, onFocus }) {
|
|
|
788
874
|
}
|
|
789
875
|
onChange({ component: next, version: target.version, values: carried });
|
|
790
876
|
};
|
|
791
|
-
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def
|
|
792
|
-
? Object.entries(schema.fields).map(([f, d]) => (_jsx(FieldInput, { name: `${name}.${f}`, def: d, value: chosen.values?.[f], onChange: (v) => onChange({ ...chosen, version: schema.version, values: { ...(chosen.values ?? {}), [f]: v } }), onFocus: onFocus }, `${chosen.component}.${f}`)))
|
|
877
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx("label", { htmlFor: id, className: "vx-sublabel", children: ui.t('component.label') }), _jsxs("select", { id: id, "data-field": name, onFocus: onFocus, value: chosen?.component ?? '', onChange: (e) => pick(e.target.value), children: [_jsx("option", { value: "", children: def.required ? ui.t('component.choose') : ui.t('component.none') }), Object.entries(components).map(([n, c]) => (_jsx("option", { value: n, children: pickLabel(ui.lang, c.label, c.labels) ?? n }, n)))] }), chosen && schema
|
|
878
|
+
? Object.entries(schema.fields).map(([f, d]) => (_jsx(FieldInput, { name: `${name}.${f}`, def: d, value: chosen.values?.[f], fallback: asComponentValue(fallback)?.component === chosen.component ? asComponentValue(fallback)?.values?.[f] : undefined, onChange: (v) => onChange({ ...chosen, version: schema.version, values: { ...(chosen.values ?? {}), [f]: v } }), onFocus: onFocus }, `${chosen.component}.${f}`)))
|
|
793
879
|
: null] }));
|
|
794
880
|
}
|
|
795
881
|
function VideoInput({ name, def, value, onChange, onFocus }) {
|
|
882
|
+
const ui = useUi();
|
|
796
883
|
const id = useId();
|
|
797
884
|
const video = (value && typeof value === 'object' ? value : { url: typeof value === 'string' ? value : '' });
|
|
798
885
|
const url = video.url ?? '';
|
|
@@ -803,17 +890,30 @@ function VideoInput({ name, def, value, onChange, onFocus }) {
|
|
|
803
890
|
delete next.title;
|
|
804
891
|
onChange(next.url || next.title ? next : null);
|
|
805
892
|
};
|
|
806
|
-
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def
|
|
893
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx("label", { htmlFor: `${id}-url`, className: "vx-sublabel", children: ui.t('video.url') }), _jsx("input", { id: `${id}-url`, "data-field": name, onFocus: onFocus, type: "text", dir: "auto", 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
|
|
894
|
+
? ui.t('video.empty')
|
|
895
|
+
: ref
|
|
896
|
+
? ui.t('video.recognised', { provider: ref.provider === 'youtube' ? 'YouTube' : ref.provider === 'vimeo' ? 'Vimeo' : ui.t('video.file') })
|
|
897
|
+
: ui.t('video.bad') }), _jsx("label", { htmlFor: `${id}-title`, className: "vx-sublabel", children: ui.t('common.title') }), _jsx("input", { id: `${id}-title`, onFocus: onFocus, type: "text", dir: "auto", maxLength: 120, value: video.title ?? '', onChange: (e) => set({ title: e.target.value }) })] }));
|
|
807
898
|
}
|
|
808
|
-
const KIND_NAMES = {
|
|
899
|
+
const KIND_NAMES = {
|
|
900
|
+
bar: 'chart.kind.bar',
|
|
901
|
+
hbar: 'chart.kind.hbar',
|
|
902
|
+
line: 'chart.kind.line',
|
|
903
|
+
area: 'chart.kind.area',
|
|
904
|
+
pie: 'chart.kind.pie',
|
|
905
|
+
donut: 'chart.kind.donut',
|
|
906
|
+
kpi: 'chart.kind.kpi',
|
|
907
|
+
};
|
|
809
908
|
function ChartInput({ name, def, value, onChange, onFocus }) {
|
|
909
|
+
const ui = useUi();
|
|
810
910
|
const id = useId();
|
|
811
911
|
const chart = (value && typeof value === 'object' ? value : { kind: 'bar', labels: [], series: [], source: { type: 'manual' } });
|
|
812
912
|
const [text, setText] = useState(null);
|
|
813
913
|
const [error, setError] = useState(null);
|
|
814
914
|
const set = (patch) => onChange({ ...chart, ...patch });
|
|
815
915
|
const typed = chart.source.type === 'manual';
|
|
816
|
-
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def
|
|
916
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), chart.sample ? _jsx("p", { className: "vx-note", children: ui.t('chart.sample') }) : null, _jsx("label", { htmlFor: `${id}-kind`, className: "vx-sublabel", children: ui.t('chart.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: ui.t(KIND_NAMES[k]) }, k))) }), _jsx("label", { htmlFor: `${id}-title`, className: "vx-sublabel", children: ui.t('common.title') }), _jsx("input", { id: `${id}-title`, onFocus: onFocus, type: "text", dir: "auto", 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: ui.t('chart.numbers') }), _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) => {
|
|
817
917
|
setText(e.target.value);
|
|
818
918
|
const parsed = parseChartTable(e.target.value);
|
|
819
919
|
if ('error' in parsed)
|
|
@@ -822,9 +922,14 @@ function ChartInput({ name, def, value, onChange, onFocus }) {
|
|
|
822
922
|
setError(null);
|
|
823
923
|
onChange({ ...chart, labels: parsed.labels, series: parsed.series, sample: undefined });
|
|
824
924
|
}
|
|
825
|
-
}, onBlur: () => !error && setText(null) }), _jsx("span", { id: `${id}-data-note`, className: error ? 'vx-errors' : 'vx-count', "aria-live": "polite", children: error ?? '
|
|
925
|
+
}, onBlur: () => !error && setText(null) }), _jsx("span", { id: `${id}-data-note`, className: error ? 'vx-errors' : 'vx-count', "aria-live": "polite", children: error ?? ui.t('chart.firstRow') })] })) : (_jsx("p", { className: "vx-muted", children: chart.source.type === 'analytics'
|
|
926
|
+
? ui.t('chart.fromAnalytics')
|
|
927
|
+
: chart.source.type === 'content'
|
|
928
|
+
? ui.t('chart.fromContent', { collection: chart.source.collection })
|
|
929
|
+
: ui.t('chart.fromApi') })), _jsxs("div", { className: "vx-menu-row", children: [_jsx("input", { "aria-label": ui.t('chart.prefix'), placeholder: ui.t('chart.prefixPlaceholder'), onFocus: onFocus, type: "text", dir: "auto", maxLength: 8, value: chart.format?.prefix ?? '', onChange: (e) => set({ format: { ...chart.format, prefix: e.target.value || undefined } }) }), _jsx("input", { "aria-label": ui.t('chart.suffix'), placeholder: ui.t('chart.suffixPlaceholder'), onFocus: onFocus, type: "text", dir: "auto", 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: ui.t('chart.caption') }), _jsx("input", { id: `${id}-caption`, onFocus: onFocus, type: "text", dir: "auto", maxLength: 300, value: chart.caption ?? '', onChange: (e) => set({ caption: e.target.value }) })] }));
|
|
826
930
|
}
|
|
827
931
|
function MapInput({ name, def, value, onChange, onFocus }) {
|
|
932
|
+
const ui = useUi();
|
|
828
933
|
const id = useId();
|
|
829
934
|
const map = (value && typeof value === 'object' ? value : { places: [] });
|
|
830
935
|
const places = Array.isArray(map.places) ? map.places : [];
|
|
@@ -837,35 +942,36 @@ function MapInput({ name, def, value, onChange, onFocus }) {
|
|
|
837
942
|
setSearch({ at: i, q, results: null, error: null, busy: true });
|
|
838
943
|
try {
|
|
839
944
|
const r = await call(`geocode?q=${encodeURIComponent(q)}`);
|
|
840
|
-
setSearch({ at: i, q, results: r.results, error: r.results.length ? null : '
|
|
945
|
+
setSearch({ at: i, q, results: r.results, error: r.results.length ? null : ui.t('map.nothingFound'), busy: false });
|
|
841
946
|
}
|
|
842
947
|
catch (err) {
|
|
843
|
-
setSearch({ at: i, q, results: null, error: err instanceof EditorError ? err.problems.join(' ') : '
|
|
948
|
+
setSearch({ at: i, q, results: null, error: err instanceof EditorError ? err.problems.join(' ') : ui.t('map.searchFailed'), busy: false });
|
|
844
949
|
}
|
|
845
950
|
};
|
|
846
|
-
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def
|
|
847
|
-
const title = place.name.trim() ||
|
|
951
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx("span", { className: "vx-count", children: ui.t('map.count', { n: places.length, max }) }), places.map((place, i) => {
|
|
952
|
+
const title = place.name.trim() || ui.t('map.placeN', { n: i + 1 });
|
|
848
953
|
const located = place.lat !== null && place.lng !== null && Number.isFinite(place.lat) && Number.isFinite(place.lng);
|
|
849
954
|
const q = search?.at === i ? search.q : (place.address ?? '');
|
|
850
|
-
return (_jsxs("div", { className: "vx-slide-card", children: [_jsx("label", { htmlFor: `${id}-${i}-name`, className: "vx-sublabel", children:
|
|
955
|
+
return (_jsxs("div", { className: "vx-slide-card", children: [_jsx("label", { htmlFor: `${id}-${i}-name`, className: "vx-sublabel", children: ui.t('common.name') }), _jsx("input", { id: `${id}-${i}-name`, "data-field": i === 0 ? name : undefined, onFocus: onFocus, type: "text", dir: "auto", maxLength: 80, value: place.name, onChange: (e) => update(i, { name: e.target.value }) }), _jsx("label", { htmlFor: `${id}-${i}-address`, className: "vx-sublabel", children: ui.t('common.address') }), _jsxs("div", { className: "vx-menu-row", children: [_jsx("input", { id: `${id}-${i}-address`, onFocus: onFocus, type: "text", dir: "auto", maxLength: 200, value: place.address ?? '', onChange: (e) => update(i, { address: e.target.value }), onKeyDown: (e) => {
|
|
851
956
|
if (e.key === 'Enter') {
|
|
852
957
|
e.preventDefault();
|
|
853
958
|
void find(i, (place.address ?? '').trim());
|
|
854
959
|
}
|
|
855
|
-
} }), _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 ? '
|
|
960
|
+
} }), _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 ? ui.t('map.finding') : ui.t('map.find') })] }), search?.at === i && (search.results?.length || search.error) ? (_jsxs("div", { className: "vx-picker", role: "group", "aria-label": ui.t('map.matches', { 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: () => {
|
|
856
961
|
update(i, { lat: r.lat, lng: r.lng, ...(place.name.trim() ? {} : { name: r.name }), address: place.address?.trim() ? place.address : r.address });
|
|
857
962
|
setSearch(null);
|
|
858
|
-
}, children: [_jsx("strong", { children: r.name }), " ", _jsx("span", { className: "vx-muted", children: r.address })] }, k))), _jsx("span", { className: "vx-count", children:
|
|
963
|
+
}, children: [_jsx("strong", { children: r.name }), " ", _jsx("span", { className: "vx-muted", children: r.address })] }, k))), _jsx("span", { className: "vx-count", children: ui.t('map.attribution') })] })) : null, _jsx("label", { htmlFor: `${id}-${i}-pos`, className: "vx-sublabel", children: ui.t('map.position') }), _jsx("input", { id: `${id}-${i}-pos`, onFocus: onFocus, type: "text", placeholder: "24.7136, 46.6753", dir: "ltr", value: pasted[i] ?? (located ? `${place.lat}, ${place.lng}` : ''), "aria-describedby": `${id}-${i}-pos-note`, onChange: (e) => {
|
|
859
964
|
setPasted({ ...pasted, [i]: e.target.value });
|
|
860
965
|
const p = parseMapLink(e.target.value);
|
|
861
966
|
if (p)
|
|
862
967
|
update(i, { lat: p.lat, lng: p.lng });
|
|
863
968
|
else if (!e.target.value.trim())
|
|
864
969
|
update(i, { lat: null, lng: null });
|
|
865
|
-
}, onBlur: () => setPasted(({ [i]: _gone, ...rest }) => rest) }), _jsx("span", { id: `${id}-${i}-pos-note`, className: "vx-count", children: located ? '
|
|
866
|
-
}), _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:
|
|
970
|
+
}, onBlur: () => setPasted(({ [i]: _gone, ...rest }) => rest) }), _jsx("span", { id: `${id}-${i}-pos-note`, className: "vx-count", children: located ? ui.t('map.placed') : ui.t('map.notPlaced') }), _jsx("div", { className: "vx-menu-tools", children: _jsx("button", { type: "button", className: "vx-mini", "aria-label": ui.t('common.removeItem', { title }), onClick: () => set(places.filter((_, j) => j !== i)), children: ui.t('common.remove') }) })] }, i));
|
|
971
|
+
}), _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: ui.t('map.add') }) })] }));
|
|
867
972
|
}
|
|
868
|
-
function SlidesInput({ name, def, value, onChange, onFocus }) {
|
|
973
|
+
function SlidesInput({ name, def, value, fallback, onChange, onFocus }) {
|
|
974
|
+
const ui = useUi();
|
|
869
975
|
const id = useId();
|
|
870
976
|
const slides = Array.isArray(value) ? value : [];
|
|
871
977
|
const max = def.max ?? 10;
|
|
@@ -879,27 +985,44 @@ function SlidesInput({ name, def, value, onChange, onFocus }) {
|
|
|
879
985
|
[next[i], next[to]] = [next[to], next[i]];
|
|
880
986
|
set(next);
|
|
881
987
|
};
|
|
882
|
-
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def
|
|
883
|
-
const title = slide.title?.trim() ||
|
|
884
|
-
return (_jsxs("div", { className: "vx-slide-card", children: [_jsx(MediaInput, { name: i === 0 ? name : `${name}-${i}`, def: { type: 'media', label:
|
|
885
|
-
}), _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:
|
|
988
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx("span", { className: "vx-count", children: ui.t('slides.count', { n: slides.length, max }) }), slides.map((slide, i) => {
|
|
989
|
+
const title = slide.title?.trim() || ui.t('slides.slideN', { n: i + 1 });
|
|
990
|
+
return (_jsxs("div", { className: "vx-slide-card", children: [_jsx(MediaInput, { name: i === 0 ? name : `${name}-${i}`, def: { type: 'media', label: ui.t('slides.image', { n: i + 1 }), required: true }, value: slide.image, fallback: Array.isArray(fallback) ? fallback[i]?.image : undefined, onChange: (v) => update(i, { image: v }), onFocus: onFocus }), _jsx("label", { htmlFor: `${id}-${i}-title`, className: "vx-sublabel", children: ui.t('common.title') }), _jsx("input", { id: `${id}-${i}-title`, onFocus: onFocus, type: "text", dir: "auto", maxLength: 120, value: slide.title ?? '', onChange: (e) => update(i, { title: e.target.value }) }), _jsx("label", { htmlFor: `${id}-${i}-text`, className: "vx-sublabel", children: ui.t('common.text') }), _jsx("textarea", { dir: "auto", 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": ui.t('slides.buttonTextOf', { title }), placeholder: ui.t('slides.buttonText'), onFocus: onFocus, type: "text", dir: "auto", value: slide.link?.label ?? '', onChange: (e) => update(i, { link: { label: e.target.value, href: slide.link?.href ?? '' } }) }), _jsx("input", { "aria-label": ui.t('slides.buttonLinkOf', { title }), placeholder: ui.t('common.pagePlaceholderShort'), inputMode: "url", onFocus: onFocus, type: "text", dir: "auto", 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": ui.t('common.moveEarlier', { title }), onClick: () => move(i, -1), children: "\u2191" }), _jsx("button", { type: "button", className: "vx-mini", disabled: i === slides.length - 1, "aria-label": ui.t('common.moveLater', { title }), onClick: () => move(i, 1), children: "\u2193" }), _jsx("button", { type: "button", className: "vx-mini", "aria-label": ui.t('common.removeItem', { title }), onClick: () => set(slides.filter((_, j) => j !== i)), children: ui.t('common.remove') })] })] }, i));
|
|
991
|
+
}), _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: ui.t('slides.add') }) })] }));
|
|
886
992
|
}
|
|
887
|
-
/**
|
|
888
|
-
function
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
993
|
+
/** The text a list item shows for a field: a text field's value, or a link's text. */
|
|
994
|
+
function itemText(def, v) {
|
|
995
|
+
if (def?.type === 'text' && typeof v === 'string' && v.trim())
|
|
996
|
+
return v.trim().slice(0, 40);
|
|
997
|
+
if (def?.type === 'link' && v && typeof v === 'object' && typeof v.label === 'string' && v.label.trim()) {
|
|
998
|
+
return v.label.trim().slice(0, 40);
|
|
999
|
+
}
|
|
1000
|
+
return null;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* A short name for a collapsed list item: the list's titleField, else its first required text field, else its first
|
|
1004
|
+
* text field (a link's text counts), else "Item 3".
|
|
1005
|
+
*/
|
|
1006
|
+
export function itemTitle(fields, item, i, titleField, ui = currentUi) {
|
|
1007
|
+
const entries = Object.entries(fields);
|
|
1008
|
+
const order = [
|
|
1009
|
+
...(titleField && fields[titleField] ? [titleField] : []),
|
|
1010
|
+
...entries.filter(([, d]) => d.type === 'text' && d.required).map(([f]) => f),
|
|
1011
|
+
...entries.map(([f]) => f),
|
|
1012
|
+
];
|
|
1013
|
+
for (const f of order) {
|
|
1014
|
+
const text = itemText(fields[f], item[f]);
|
|
1015
|
+
if (text)
|
|
1016
|
+
return text;
|
|
895
1017
|
}
|
|
896
|
-
return
|
|
1018
|
+
return ui.t('list.itemN', { n: i + 1 });
|
|
897
1019
|
}
|
|
898
1020
|
/**
|
|
899
1021
|
* A list field: items to add, remove and reorder, each with the list's own fields (the same inputs as a slot's), and
|
|
900
1022
|
* with schedule, the first and last day it shows on. Items open one at a time, so a long list stays short on screen.
|
|
901
1023
|
*/
|
|
902
|
-
function ListInput({ name, def, value, onChange, onFocus }) {
|
|
1024
|
+
function ListInput({ name, def, value, fallback, onChange, onFocus }) {
|
|
1025
|
+
const ui = useUi();
|
|
903
1026
|
const id = useId();
|
|
904
1027
|
const items = Array.isArray(value) ? value : [];
|
|
905
1028
|
const fields = def.fields ?? {};
|
|
@@ -916,19 +1039,20 @@ function ListInput({ name, def, value, onChange, onFocus }) {
|
|
|
916
1039
|
set(next);
|
|
917
1040
|
setOpenItem((o) => (o === i ? to : o === to ? i : o));
|
|
918
1041
|
};
|
|
919
|
-
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [def
|
|
920
|
-
const title = itemTitle(fields, item, i);
|
|
1042
|
+
return (_jsxs("fieldset", { className: "vx-field vx-fieldset", children: [_jsxs("legend", { className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), _jsx("span", { className: "vx-count", children: ui.t('list.count', { n: items.length, max }) }), items.map((item, i) => {
|
|
1043
|
+
const title = itemTitle(fields, item, i, def.titleField, ui);
|
|
921
1044
|
const isOpen = openItem === i;
|
|
922
|
-
return (_jsxs("div", { className: "vx-slide-card", children: [_jsxs("div", { className: "vx-menu-tools", children: [_jsxs("button", { type: "button", className: "vx-mini vx-item-toggle", "aria-expanded": isOpen, "aria-controls": `${id}-${i}`, onClick: () => setOpenItem(isOpen ? null : i), children: [isOpen ? '▾' : '▸', " ", title] }), _jsx("button", { type: "button", className: "vx-mini", disabled: i === 0, "aria-label":
|
|
1045
|
+
return (_jsxs("div", { className: "vx-slide-card", children: [_jsxs("div", { className: "vx-menu-tools", children: [_jsxs("button", { type: "button", className: "vx-mini vx-item-toggle", "aria-expanded": isOpen, "aria-controls": `${id}-${i}`, onClick: () => setOpenItem(isOpen ? null : i), children: [isOpen ? '▾' : ui.dir === 'rtl' ? '◂' : '▸', " ", _jsx("bdi", { children: title })] }), _jsx("button", { type: "button", className: "vx-mini", disabled: i === 0, "aria-label": ui.t('common.moveEarlier', { title }), onClick: () => move(i, -1), children: "\u2191" }), _jsx("button", { type: "button", className: "vx-mini", disabled: i === items.length - 1, "aria-label": ui.t('common.moveLater', { title }), onClick: () => move(i, 1), children: "\u2193" }), _jsx("button", { type: "button", className: "vx-mini", "aria-label": ui.t('common.removeItem', { title }), onClick: () => {
|
|
923
1046
|
set(items.filter((_, j) => j !== i));
|
|
924
1047
|
setOpenItem(null);
|
|
925
|
-
}, children:
|
|
1048
|
+
}, children: ui.t('common.remove') })] }), isOpen ? (_jsxs("div", { id: `${id}-${i}`, children: [Object.entries(fields).map(([f, d]) => (_jsx(FieldInput, { name: `${name}-${i}-${f}`, def: d, value: item[f] ?? null, fallback: fallbackItem(fields, item, i, fallback)?.[f], onChange: (v) => update(i, { [f]: v }), onFocus: onFocus }, f))), def.schedule ? (_jsxs("div", { className: "vx-menu-row", children: [_jsxs("label", { className: "vx-sublabel", children: [ui.t('list.showsFrom'), _jsx("input", { type: "date", onFocus: onFocus, value: typeof item._from === 'string' ? item._from : '', onChange: (e) => update(i, { _from: e.target.value || undefined }) })] }), _jsxs("label", { className: "vx-sublabel", children: [ui.t('list.until'), _jsx("input", { type: "date", onFocus: onFocus, value: typeof item._until === 'string' ? item._until : '', onChange: (e) => update(i, { _until: e.target.value || undefined }) })] })] })) : null] })) : null] }, i));
|
|
926
1049
|
}), _jsx("div", { className: "vx-actions", children: _jsx("button", { type: "button", className: "vx-btn", "data-field": items.length ? undefined : name, onFocus: onFocus, disabled: items.length >= max, onClick: () => {
|
|
927
1050
|
set([...items, {}]);
|
|
928
1051
|
setOpenItem(items.length);
|
|
929
|
-
}, children:
|
|
1052
|
+
}, children: ui.t('list.add') }) })] }));
|
|
930
1053
|
}
|
|
931
1054
|
function MediaInput({ name, def, value, fallback, onChange, onFocus, }) {
|
|
1055
|
+
const ui = useUi();
|
|
932
1056
|
const { canUploadMedia } = useContext(PanelCaps);
|
|
933
1057
|
const [importing, setImporting] = useState(false);
|
|
934
1058
|
const [importError, setImportError] = useState(null);
|
|
@@ -944,12 +1068,12 @@ function MediaInput({ name, def, value, fallback, onChange, onFocus, }) {
|
|
|
944
1068
|
const res = await fetch(importable.href, { credentials: 'same-origin' });
|
|
945
1069
|
const blob = res.ok ? await res.blob() : null;
|
|
946
1070
|
if (!blob || !blob.type.startsWith('image/'))
|
|
947
|
-
throw new EditorError(res.status, ['
|
|
1071
|
+
throw new EditorError(res.status, [ui.t('media.notImage')]);
|
|
948
1072
|
const m = await call('media', { method: 'POST', body: { fileName: importable.pathname, data: await toBase64(blob), alt: fromCode.alt } });
|
|
949
1073
|
onChange({ id: m.id, url: m.url, alt: m.alt });
|
|
950
1074
|
}
|
|
951
1075
|
catch (err) {
|
|
952
|
-
setImportError(err instanceof EditorError ? err.problems.join(' ') : '
|
|
1076
|
+
setImportError(err instanceof EditorError ? err.problems.join(' ') : ui.t('media.importFailed'));
|
|
953
1077
|
}
|
|
954
1078
|
finally {
|
|
955
1079
|
setImporting(false);
|
|
@@ -970,11 +1094,11 @@ function MediaInput({ name, def, value, fallback, onChange, onFocus, }) {
|
|
|
970
1094
|
setItems(r.data);
|
|
971
1095
|
setError(null);
|
|
972
1096
|
})
|
|
973
|
-
.catch((err) => setError(err instanceof EditorError ? err.problems.join(' ') : '
|
|
1097
|
+
.catch((err) => setError(err instanceof EditorError ? err.problems.join(' ') : currentUi.t('media.loadFailed')));
|
|
974
1098
|
}, 250);
|
|
975
1099
|
return () => clearTimeout(t);
|
|
976
1100
|
}, [picking, search]);
|
|
977
|
-
return (_jsxs("div", { className: "vx-field", role: "group", "aria-labelledby": labelId, children: [_jsxs("span", { id: labelId, className: "vx-label", children: [def
|
|
1101
|
+
return (_jsxs("div", { className: "vx-field", role: "group", "aria-labelledby": labelId, children: [_jsxs("span", { id: labelId, className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }), value?.url ? (_jsx("img", { className: "vx-preview", src: value.url, alt: value.alt ?? '' })) : fromCode ? (_jsxs(_Fragment, { children: [_jsx("img", { className: "vx-preview", src: fromCode.url, alt: fromCode.alt }), _jsx("p", { className: "vx-muted", children: canUploadMedia && importable ? ui.t('media.fromCodeImport') : ui.t('media.fromCode') }), canUploadMedia && importable ? (_jsx("div", { className: "vx-actions", children: _jsx("button", { type: "button", className: "vx-btn", disabled: importing, onClick: () => void importIntoMedia(), children: importing ? ui.t('media.importing') : ui.t('media.import') }) })) : null, importError ? _jsx("p", { role: "alert", children: importError }) : null] })) : (_jsx("p", { className: "vx-muted", children: ui.t('media.none') })), _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 ? ui.t('media.closeLibrary') : value ? ui.t('media.replace') : ui.t('media.choose') }), value && !def.required ? (_jsx("button", { type: "button", className: "vx-btn", onClick: () => onChange(null), children: ui.t('common.remove') })) : null] }), picking ? (_jsxs("div", { className: "vx-picker", children: [_jsx("label", { htmlFor: searchId, className: "vx-sublabel", children: ui.t('media.search') }), _jsx("input", { id: searchId, type: "search", dir: "auto", 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: ui.t('media.noneFound') }) : null, _jsx("div", { className: "vx-grid", children: (items ?? []).map((m) => (_jsxs("button", { type: "button", "aria-pressed": value?.id === m.id, onClick: () => {
|
|
978
1102
|
onChange({ id: m.id, url: m.url, alt: m.alt });
|
|
979
1103
|
setPicking(false);
|
|
980
1104
|
}, children: [_jsx("img", { src: m.thumbUrl, alt: "" }), _jsx("span", { children: m.alt || m.name })] }, m.id))) })] })) : null] }));
|
|
@@ -1003,7 +1127,7 @@ const STYLES = `
|
|
|
1003
1127
|
.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}
|
|
1004
1128
|
.vx-inline-keys{color:#a1a1aa}
|
|
1005
1129
|
[data-veroxm-inline]{outline:none;cursor:text;caret-color:auto}
|
|
1006
|
-
.vx-tag{position:absolute;top:-24px;
|
|
1130
|
+
.vx-tag{position:absolute;top:-24px;inset-inline-start:-2px;background:#6d28d9;color:#fff;font-size:12px;padding:2px 8px;border-radius:4px;white-space:nowrap}
|
|
1007
1131
|
.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)}
|
|
1008
1132
|
.vx-toolbar .vx-muted{color:#a1a1aa}
|
|
1009
1133
|
.vx-brand{display:flex;align-items:center;gap:6px;font-weight:600;padding:0 4px}
|
|
@@ -1012,10 +1136,11 @@ const STYLES = `
|
|
|
1012
1136
|
.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}
|
|
1013
1137
|
.vx-toolbar .vx-btn{background:#27272a;border-color:#3f3f46;color:#fafafa}
|
|
1014
1138
|
.vx-toolbar .vx-btn[aria-pressed="true"]{background:#4c1d95;border-color:#6d28d9}
|
|
1139
|
+
.vx-lang{appearance:auto;min-height:32px;padding:4px 8px;border-radius:8px;border:1px solid #3f3f46;background:#27272a;color:#fafafa;cursor:pointer}
|
|
1015
1140
|
.vx-btn:disabled{opacity:.5;cursor:not-allowed}
|
|
1016
1141
|
.vx-primary{background:#6d28d9;border-color:#6d28d9;color:#fff}
|
|
1017
1142
|
.vx-root :focus-visible{outline:2px solid #f59e0b;outline-offset:2px}
|
|
1018
|
-
.vx-panel{position:fixed;z-index:2147483001;top:12px;
|
|
1143
|
+
.vx-panel{position:fixed;z-index:2147483001;top:12px;inset-inline-end: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)}
|
|
1019
1144
|
.vx-panel-head{display:flex;justify-content:space-between;gap:8px;padding:14px 16px;border-bottom:1px solid #f4f4f5}
|
|
1020
1145
|
.vx-panel-head h2{margin:0;font-size:16px;font-weight:650}
|
|
1021
1146
|
.vx-panel-head p{margin:2px 0 0}
|
|
@@ -1033,15 +1158,16 @@ const STYLES = `
|
|
|
1033
1158
|
.vx-field input::placeholder,.vx-field textarea::placeholder{color:#a1a1aa;opacity:1}
|
|
1034
1159
|
.vx-field textarea{resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}
|
|
1035
1160
|
.vx-count{font-size:12px;color:#71717a}
|
|
1161
|
+
.vx-root bdi{unicode-bidi:isolate}
|
|
1036
1162
|
.vx-preview{max-width:100%;max-height:160px;border-radius:8px;object-fit:contain;background:#f4f4f5;align-self:flex-start}
|
|
1037
1163
|
.vx-picker{border:1px solid #e4e4e7;border-radius:10px;padding:8px;margin-top:6px}
|
|
1038
1164
|
.vx-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;margin-top:8px;max-height:240px;overflow:auto}
|
|
1039
|
-
.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:
|
|
1165
|
+
.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:start}
|
|
1040
1166
|
.vx-grid button[aria-pressed="true"]{border-color:#6d28d9}
|
|
1041
1167
|
.vx-grid img{width:100%;aspect-ratio:1;object-fit:cover;border-radius:6px}
|
|
1042
1168
|
.vx-grid span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1043
1169
|
.vx-status{margin:0 0 8px;min-height:20px;color:#52525b}
|
|
1044
|
-
.vx-errors{margin:0 0 8px;padding-
|
|
1170
|
+
.vx-errors{margin:0 0 8px;padding-inline-start:18px;color:#b91c1c}
|
|
1045
1171
|
.vx-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
|
|
1046
1172
|
.vx-actions[hidden]{display:none}
|
|
1047
1173
|
.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}
|
|
@@ -1056,7 +1182,7 @@ const STYLES = `
|
|
|
1056
1182
|
.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}
|
|
1057
1183
|
.vx-list-title{font-weight:650;margin:0 0 6px}
|
|
1058
1184
|
.vx-list ul{list-style:none;margin:0;padding:0}
|
|
1059
|
-
.vx-list button{appearance:none;cursor:pointer;width:100%;text-align:
|
|
1185
|
+
.vx-list button{appearance:none;cursor:pointer;width:100%;text-align:start;border:0;background:transparent;padding:8px;border-radius:8px;display:flex;gap:6px;align-items:baseline;flex-wrap:wrap}
|
|
1060
1186
|
.vx-list button:hover{background:#f4f4f5}
|
|
1061
1187
|
@media (prefers-color-scheme: dark){
|
|
1062
1188
|
.vx-root{color:#fafafa}
|