@veroxm/react-sdk 1.9.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.
@@ -1,6 +1,6 @@
1
1
  'use client';
2
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';
3
+ import { createContext, useCallback, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
5
  import { EDITOR_HEADER, PREVIEW_COOKIE, ROUTE_BASE } from './constants.js';
6
6
  import { RICH_TEXT_STYLES, RichTextInput } from './rich-text.js';
@@ -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 { readFallback, 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: 'Published. Visitors see this now.',
29
- submitted: 'Sent for approval. Nothing changes for visitors until it is approved.',
30
- approved: 'Approved. It moves to the next step.',
31
- rejected: 'Rejected. The author can change it and send it again.',
32
- withdrawn: 'Request withdrawn. Your draft is unchanged.',
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 ?? `Something went wrong (HTTP ${res.status}).`]);
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;
@@ -91,6 +88,53 @@ function toPayload(fields, values) {
91
88
  }
92
89
  return out;
93
90
  }
91
+ /** What the panel says after starting a slot from the page: which fields came from where. */
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));
95
+ if (!s.inherited)
96
+ return ui.t('seed.filled', { fields });
97
+ const rest = Object.keys(s.fields).filter((f) => !seeded.includes(f) && !isEmptyValue(s.values[f]));
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;
135
+ }
136
+ /** What the open panel may do beyond editing (read deep inside the form, by the image fields). */
137
+ const PanelCaps = createContext({ canUploadMedia: false });
94
138
  // -------------------------------------------------------------- singleton
95
139
  const owners = [];
96
140
  const ownerListeners = new Set();
@@ -134,7 +178,16 @@ function findPageSlots() {
134
178
  if (!name || seen.has(key))
135
179
  return;
136
180
  seen.add(key);
137
- out.push({ name, locale, label: el.getAttribute('data-veroxm-label') || name, el });
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 });
138
191
  });
139
192
  return out;
140
193
  }
@@ -250,6 +303,16 @@ function Overlay({ onChange, tools }) {
250
303
  const [highlightField, setHighlightField] = useState(null);
251
304
  const [inlineHint, setInlineHint] = useState(null);
252
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
+ };
253
316
  useEffect(() => {
254
317
  openFromOutside = (name, locale) => {
255
318
  setListOpen(false);
@@ -261,8 +324,16 @@ function Overlay({ onChange, tools }) {
261
324
  }, []);
262
325
  useEffect(() => {
263
326
  call('session')
264
- .then(setSession)
265
- .catch((err) => setEnded(err instanceof EditorError ? err.problems.join(' ') : 'VeroXM could not be reached.'));
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')));
266
337
  }, []);
267
338
  // Once the session is confirmed: the site's own text for each slot, for
268
339
  // the dashboard. Again shortly after, for slots whose fallback arrives late.
@@ -327,42 +398,59 @@ function Overlay({ onChange, tools }) {
327
398
  const hoverRect = hover && hover !== openEl ? rectOf(hover) : null;
328
399
  const openRect = rectOf(openEl);
329
400
  const fieldRect = openEl && highlightField ? rectOf(openEl.querySelector(`[data-veroxm-field="${CSS.escape(highlightField)}"]`)) : null;
330
- 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: () => {
331
- setOpen(null);
332
- setHighlightField(null);
333
- }, onFieldFocus: setHighlightField, onSessionError: onSessionError, onChange: onChange, onInline: setInlineHint }, `${open.name}|${open.locale}`)), listOpen && (_jsx(SlotList, { onPick: (s) => {
334
- setListOpen(false);
335
- s.el.firstElementChild?.scrollIntoView?.({ block: 'center', behavior: 'smooth' });
336
- setOpen({ name: s.name, locale: s.locale });
337
- }, onClose: () => {
338
- setListOpen(false);
339
- listToggleRef.current?.focus();
340
- } })), _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" })] })] }));
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') || '';
341
423
  }
342
424
  function InlineHintBar({ hint }) {
425
+ const ui = useUi();
343
426
  const rect = rectOf(hint.el);
344
427
  if (!rect)
345
428
  return null;
346
429
  const below = rect.bottom + 40 < window.innerHeight;
347
- 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" })] })] }));
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')] })] })] }));
348
431
  }
349
432
  function Outline({ rect, label, active, field }) {
350
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 }));
351
434
  }
352
435
  // -------------------------------------------------------------- slot list
353
436
  function SlotList({ onPick, onClose }) {
437
+ const ui = useUi();
354
438
  const [slots] = useState(findPageSlots);
355
439
  const firstRef = useRef(null);
356
440
  useEffect(() => firstRef.current?.focus(), []);
357
- return (_jsxs("div", { className: "vx-list", role: "dialog", "aria-label": "Slots on this page", onKeyDown: (e) => {
441
+ return (_jsxs("div", { className: "vx-list", role: "dialog", "aria-label": ui.t('bar.slots'), onKeyDown: (e) => {
358
442
  if (e.key !== 'Escape')
359
443
  return;
360
444
  e.stopPropagation();
361
445
  onClose();
362
- }, 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}`))) }))] }));
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
+ }) }))] }));
363
450
  }
364
451
  const AUTOSAVE_MS = 800;
365
- function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, onFieldFocus, onSessionError, onChange, onInline, }) {
452
+ function SlotPanel({ slot, canPublish, canManageTests, canUploadMedia = false, dashboardUrl, onClose, onFieldFocus, onSessionError, onChange, onInline, }) {
453
+ const ui = useUi();
366
454
  const titleId = useId();
367
455
  const panelRef = useRef(null);
368
456
  const returnFocus = useRef(typeof document !== 'undefined' ? document.activeElement : null);
@@ -378,9 +466,13 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
378
466
  const timer = useRef(null);
379
467
  const inlineRef = useRef(null);
380
468
  const valuesRef = useRef({});
469
+ const shownRef = useRef({});
381
470
  const latest = useRef(null);
382
471
  // Seeding from the page's fallback happens once per opening, for a slot never published.
383
472
  const seededOnce = useRef(false);
473
+ // Fields changed in this panel (typed, filled from the page). A save sends these from the form and every other
474
+ // field exactly as stored, so a field nobody touched is never written as an empty value.
475
+ const touched = useRef(new Set());
384
476
  const apply = useCallback((next) => {
385
477
  if (!next)
386
478
  return;
@@ -403,7 +495,7 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
403
495
  setLocale(res.locale);
404
496
  const s = res.slots[slot.name];
405
497
  if (!s)
406
- setLoadError('VeroXM doesn’t know this slot yet. Reload the page so the site can report it, then try again.');
498
+ setLoadError(currentUi.t('error.unknownSlot'));
407
499
  else {
408
500
  if (position === 0)
409
501
  baseValues.current = s.values;
@@ -411,20 +503,26 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
411
503
  // Never published: start from what the page shows now (its fallback), so the first save stores the real
412
504
  // content instead of empty fields. Not for a test variant (it stores only differences), and never over a
413
505
  // field with stored content.
506
+ // A language with nothing saved yet comes back with the default language's copy: the page's own copy for
507
+ // this language wins wherever it has one, the default language fills the rest.
414
508
  if (position === 0 && !s.version && !seededOnce.current) {
415
509
  seededOnce.current = true;
416
- const { values: seededValues, seeded } = seedFromFallback(s.fields, s.values, readFallback(slotElement(slot.name, slot.locale)));
510
+ const { values: seededValues, seeded } = seedFromFallback(s.fields, s.values, readFallback(slotElement(slot.name, slot.locale)), {
511
+ replace: s.inherited,
512
+ });
417
513
  if (seeded.length) {
514
+ for (const f of seeded)
515
+ touched.current.add(f);
418
516
  setValues(seededValues);
419
517
  latest.current = seededValues;
420
- setNotice('Filled from the page’s current content. Change what you need, then publish.');
518
+ setNotice(seedNotice(currentUi, s, seeded, res.locale));
421
519
  }
422
520
  }
423
521
  }
424
522
  }
425
523
  catch (err) {
426
524
  onSessionError(err);
427
- setLoadError(err instanceof EditorError ? err.problems.join(' ') : 'VeroXM could not be reached.');
525
+ setLoadError(err instanceof EditorError ? err.problems.join(' ') : currentUi.t('error.unreachable'));
428
526
  }
429
527
  }, [slot.name, slot.locale, apply, onSessionError]);
430
528
  useEffect(() => {
@@ -471,7 +569,10 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
471
569
  onChange();
472
570
  return true;
473
571
  }
474
- const next = await call(slotPath(slot.name, locale), { method: 'PUT', body: { values: toPayload(data.fields, pending) } });
572
+ // Changed fields from the form; every other field exactly as stored (left out when nothing is stored).
573
+ const stored = data.values;
574
+ const merged = Object.fromEntries(Object.keys(data.fields).map((k) => [k, touched.current.has(k) ? pending[k] : stored[k]]));
575
+ const next = await call(slotPath(slot.name, locale), { method: 'PUT', body: { values: toPayload(data.fields, merged) } });
475
576
  setData(next);
476
577
  setSave({ kind: 'saved', at: new Date() });
477
578
  // While typing on the page the page already shows the text; re-render when done.
@@ -481,7 +582,7 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
481
582
  }
482
583
  catch (err) {
483
584
  onSessionError(err);
484
- setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['Could not save. Check your connection.'] });
585
+ setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : [currentUi.t('error.save')] });
485
586
  return false;
486
587
  }
487
588
  }, [data, locale, slot.name, onChange, onSessionError, load]);
@@ -494,6 +595,7 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
494
595
  const change = (field, value) => {
495
596
  setNotice(null);
496
597
  setConfirmDiscard(false);
598
+ touched.current.add(field);
497
599
  setValues((prev) => {
498
600
  const next = { ...prev, [field]: value };
499
601
  latest.current = next;
@@ -516,14 +618,19 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
516
618
  if (target && def?.type === 'text' && target.el.isConnected && canEditInline(target.el)) {
517
619
  inlineRef.current?.end(true);
518
620
  const before = valuesRef.current[target.field];
621
+ const wasTouched = touched.current.has(target.field);
622
+ // Nothing stored: start from the text the page shows (its fallback), not an empty box.
623
+ const startText = isEmptyValue(before) && typeof shownRef.current[target.field] === 'string' ? shownRef.current[target.field] : undefined;
519
624
  let typed = false;
520
- const label = def.label ?? target.field;
625
+ const label = fieldLabel(currentUi, def, target.field);
521
626
  onFieldFocus(target.field);
522
627
  onInline({ el: target.el, label, length: target.el.textContent?.length ?? 0, max: def.max });
523
628
  inlineRef.current = startInlineEdit(target.el, {
524
629
  label,
630
+ ariaLabel: currentUi.t('inline.aria', { label }),
525
631
  max: def.max,
526
632
  point: target.point,
633
+ initialText: startText,
527
634
  onInput: (text) => {
528
635
  typed = true;
529
636
  changeRef.current(target.field, text);
@@ -534,7 +641,16 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
534
641
  onInline(null);
535
642
  if (!typed)
536
643
  return;
537
- changeRef.current(target.field, committed ? text : before);
644
+ if (!committed) {
645
+ // Cancelled: back to what was there, and the field counts as untouched again if it was.
646
+ setValues((prev) => ({ ...prev, [target.field]: before }));
647
+ if (latest.current)
648
+ latest.current = { ...latest.current, [target.field]: before };
649
+ if (!wasTouched)
650
+ touched.current.delete(target.field);
651
+ return;
652
+ }
653
+ changeRef.current(target.field, text);
538
654
  void flushRef.current().then(() => onChange());
539
655
  },
540
656
  });
@@ -571,14 +687,15 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
571
687
  });
572
688
  apply(res.slot);
573
689
  setSave({ kind: 'idle' });
574
- setNotice(OUTCOME_NOTICE[res.outcome] ?? null);
690
+ const outcome = OUTCOME_NOTICE[res.outcome];
691
+ setNotice(outcome ? ui.t(outcome) : null);
575
692
  setReviewComment('');
576
693
  if (res.outcome === 'published' || verb === 'publish')
577
694
  onChange();
578
695
  }
579
696
  catch (err) {
580
697
  onSessionError(err);
581
- setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['Something went wrong. Try again.'] });
698
+ setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : [ui.t('error.generic')] });
582
699
  }
583
700
  finally {
584
701
  setBusy(null);
@@ -593,13 +710,13 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
593
710
  setBusy('discard');
594
711
  try {
595
712
  apply(await call(slotPath(slot.name, locale, '/discard'), { method: 'POST' }));
596
- setNotice('Changes discarded.');
713
+ setNotice(ui.t('notice.discarded'));
597
714
  setSave({ kind: 'idle' });
598
715
  onChange();
599
716
  }
600
717
  catch (err) {
601
718
  onSessionError(err);
602
- setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : ['Could not discard.'] });
719
+ setSave({ kind: 'error', problems: err instanceof EditorError ? err.problems : [ui.t('error.discard')] });
603
720
  }
604
721
  finally {
605
722
  setBusy(null);
@@ -608,88 +725,115 @@ function SlotPanel({ slot, canPublish, canManageTests, dashboardUrl, onClose, on
608
725
  };
609
726
  // The page's own fallback copy, so empty fields show what visitors see now.
610
727
  const shown = readShown(slot.name, slot.locale);
728
+ shownRef.current = shown;
729
+ const fallback = readFallback(slotElement(slot.name, slot.locale));
730
+ // "Fill empty fields from the page": only when asked, never by itself on a published slot (a list emptied on
731
+ // purpose stays empty). Nothing is saved until the next edit, publish or close.
732
+ const fillable = data && variant === 0 ? seedFromFallback(data.fields, values, fallback).seeded : [];
733
+ const fillFromPage = () => {
734
+ if (!data)
735
+ return;
736
+ const { values: next, seeded } = seedFromFallback(data.fields, values, fallback);
737
+ if (!seeded.length)
738
+ return;
739
+ for (const f of seeded)
740
+ touched.current.add(f);
741
+ setValues(next);
742
+ latest.current = next;
743
+ setConfirmDiscard(false);
744
+ setNotice(ui.t('fill.done', { fields: ui.list(seeded.map((f) => fieldLabel(ui, data.fields[f], f))) }));
745
+ };
611
746
  const dirty = Boolean(data?.unpublishedChanges) || save.kind === 'saving' || latest.current !== null;
612
- const title = data?.label || slot.name;
747
+ const title = pickLabel(ui.lang, data?.label, data?.labels) || slot.name;
613
748
  const approval = data?.approval ?? null;
614
- return (_jsxs("div", { ref: panelRef, className: "vx-panel", role: "dialog", "aria-modal": "false", "aria-labelledby": titleId, onKeyDown: (e) => {
615
- if (e.key === 'Escape') {
616
- e.stopPropagation();
617
- close();
618
- }
619
- }, 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) => {
620
- // Arrow keys move between versions (one tab stop for the whole list).
621
- const order = data.test.variants.map((v) => v.position);
622
- const at = order.indexOf(variant);
623
- const next = e.key === 'ArrowRight' || e.key === 'ArrowDown'
624
- ? order[(at + 1) % order.length]
625
- : e.key === 'ArrowLeft' || e.key === 'ArrowUp'
626
- ? order[(at - 1 + order.length) % order.length]
627
- : e.key === 'Home'
628
- ? order[0]
629
- : e.key === 'End'
630
- ? order[order.length - 1]
631
- : undefined;
632
- if (next === undefined)
633
- return;
634
- e.preventDefault();
635
- void selectVariant(next);
636
- e.currentTarget.querySelector(`[data-position="${next}"]`)?.focus();
637
- }, 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
638
- ? 'The page shows this variant. Edits change only this variant; empty fields use the published version.'
639
- : data.test.editable
640
- ? 'The page shows this variant. Editing variants needs permission to manage experiments.'
641
- : '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
642
- ? (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)))
643
- : null] }), _jsxs("div", { className: "vx-panel-foot", children: [_jsx("p", { className: "vx-status", role: "status", "aria-live": "polite", children: save.kind === 'saving'
644
- ? variant > 0
645
- ? 'Saving variant…'
646
- : 'Saving draft…'
647
- : save.kind === 'saved'
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) => {
750
+ if (e.key === 'Escape') {
751
+ e.stopPropagation();
752
+ close();
753
+ }
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.
756
+ const order = data.test.variants.map((v) => v.position);
757
+ const at = order.indexOf(variant);
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'
761
+ ? order[(at + 1) % order.length]
762
+ : e.key === back || e.key === 'ArrowUp'
763
+ ? order[(at - 1 + order.length) % order.length]
764
+ : e.key === 'Home'
765
+ ? order[0]
766
+ : e.key === 'End'
767
+ ? order[order.length - 1]
768
+ : undefined;
769
+ if (next === undefined)
770
+ return;
771
+ e.preventDefault();
772
+ void selectVariant(next);
773
+ e.currentTarget.querySelector(`[data-position="${next}"]`)?.focus();
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
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)))
776
+ : null] }), _jsxs("div", { className: "vx-panel-foot", children: [_jsx("p", { className: "vx-status", role: "status", "aria-live": "polite", children: save.kind === 'saving'
648
777
  ? variant > 0
649
- ? 'Variant saved'
650
- : 'Draft saved'
651
- : save.kind === 'error'
652
- ? ''
653
- : latest.current !== null
654
- ? (notice ?? 'Editing… saves in a moment')
655
- : 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
656
- ? ` · step ${approval.steps.findIndex((st) => st.stepOrder === approval.currentStep) + 1} of ${approval.steps.length}`
657
- : ''] }), _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] })] })] }));
778
+ ? ui.t('status.savingVariant')
779
+ : ui.t('status.savingDraft')
780
+ : save.kind === 'saved'
781
+ ? variant > 0
782
+ ? ui.t('status.variantSaved')
783
+ : ui.t('status.draftSaved')
784
+ : save.kind === 'error'
785
+ ? ''
786
+ : latest.current !== null
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] })] })] }) }));
658
801
  }
659
802
  // ----------------------------------------------------------------- fields
660
803
  function stripTags(html) {
661
804
  return html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
662
805
  }
663
- function FieldInput({ name, def, value, shown, onChange, onFocus, }) {
806
+ function FieldInput({ name, def, value, shown, fallback, onChange, onFocus, }) {
807
+ const ui = useUi();
664
808
  const placeholder = typeof shown === 'string' && shown ? shown : undefined;
665
809
  const id = useId();
666
- const label = (_jsxs("label", { htmlFor: id, className: "vx-label", children: [def.label ?? name, def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }));
810
+ const label = (_jsxs("label", { htmlFor: id, className: "vx-label", children: [fieldLabel(ui, def, name), def.required ? _jsx("span", { "aria-hidden": "true", children: " *" }) : null] }));
667
811
  const common = { id, 'data-field': name, onFocus, 'aria-required': def.required || undefined };
668
812
  switch (def.type) {
669
813
  case 'text': {
670
814
  const text = typeof value === 'string' ? value : '';
671
- 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] }));
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] }));
672
816
  }
673
817
  case 'richText': {
674
818
  const html = typeof value === 'string' ? value : '';
675
- 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 } })] }));
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 } })] }));
676
820
  }
677
821
  case 'number':
678
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)) })] }));
679
823
  case 'boolean':
680
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] }));
681
825
  case 'select':
682
- 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)))] })] }));
683
827
  case 'link': {
684
828
  const link = (value && typeof value === 'object' ? value : { label: '', href: '' });
685
829
  const set = (patch) => {
686
830
  const next = { ...link, ...patch };
687
831
  onChange(next.label || next.href ? next : null);
688
832
  };
689
- 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 }) })] }));
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 }) })] }));
690
834
  }
691
835
  case 'media':
692
- return _jsx(MediaInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
836
+ return _jsx(MediaInput, { name: name, def: def, value: value, fallback: fallback, onChange: onChange, onFocus: onFocus });
693
837
  case 'video':
694
838
  return _jsx(VideoInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
695
839
  case 'chart':
@@ -697,20 +841,21 @@ function FieldInput({ name, def, value, shown, onChange, onFocus, }) {
697
841
  case 'map':
698
842
  return _jsx(MapInput, { name: name, def: def, value: value, onChange: onChange, onFocus: onFocus });
699
843
  case 'slides':
700
- 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 });
701
845
  case 'menu':
702
- return _jsx(MenuInput, { name: name, label: def.label ?? name, required: def.required, depth: def.depth ?? 2, icons: def.icons, value: value, onChange: onChange, onFocus: onFocus });
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 });
703
847
  case 'list':
704
- 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 });
705
849
  case 'component':
706
- 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 });
707
851
  }
708
852
  }
709
853
  /**
710
854
  * A component field: choose one of the components the developer registered for this place, then fill in that
711
855
  * component's own fields. Switching components keeps what was typed into fields both have (same name and type).
712
856
  */
713
- function ComponentInput({ name, def, value, onChange, onFocus }) {
857
+ function ComponentInput({ name, def, value, fallback, onChange, onFocus }) {
858
+ const ui = useUi();
714
859
  const id = useId();
715
860
  const components = def.components ?? {};
716
861
  const current = asComponentValue(value);
@@ -729,11 +874,12 @@ function ComponentInput({ name, def, value, onChange, onFocus }) {
729
874
  }
730
875
  onChange({ component: next, version: target.version, values: carried });
731
876
  };
732
- 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, className: "vx-sublabel", children: "Component" }), _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 ? 'Choose a component' : 'None (the site’s default)' }), Object.entries(components).map(([n, c]) => (_jsx("option", { value: n, children: c.label ?? n }, n)))] }), chosen && schema
733
- ? 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}`)))
734
879
  : null] }));
735
880
  }
736
881
  function VideoInput({ name, def, value, onChange, onFocus }) {
882
+ const ui = useUi();
737
883
  const id = useId();
738
884
  const video = (value && typeof value === 'object' ? value : { url: typeof value === 'string' ? value : '' });
739
885
  const url = video.url ?? '';
@@ -744,17 +890,30 @@ function VideoInput({ name, def, value, onChange, onFocus }) {
744
890
  delete next.title;
745
891
  onChange(next.url || next.title ? next : null);
746
892
  };
747
- 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 }) })] }));
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 }) })] }));
748
898
  }
749
- const KIND_NAMES = { bar: 'Columns', hbar: 'Bars', line: 'Line', area: 'Area', pie: 'Pie', donut: 'Donut', kpi: 'Key figure' };
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
+ };
750
908
  function ChartInput({ name, def, value, onChange, onFocus }) {
909
+ const ui = useUi();
751
910
  const id = useId();
752
911
  const chart = (value && typeof value === 'object' ? value : { kind: 'bar', labels: [], series: [], source: { type: 'manual' } });
753
912
  const [text, setText] = useState(null);
754
913
  const [error, setError] = useState(null);
755
914
  const set = (patch) => onChange({ ...chart, ...patch });
756
915
  const typed = chart.source.type === 'manual';
757
- 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) => {
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) => {
758
917
  setText(e.target.value);
759
918
  const parsed = parseChartTable(e.target.value);
760
919
  if ('error' in parsed)
@@ -763,9 +922,14 @@ function ChartInput({ name, def, value, onChange, onFocus }) {
763
922
  setError(null);
764
923
  onChange({ ...chart, labels: parsed.labels, series: parsed.series, sample: undefined });
765
924
  }
766
- }, 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 }) })] }));
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 }) })] }));
767
930
  }
768
931
  function MapInput({ name, def, value, onChange, onFocus }) {
932
+ const ui = useUi();
769
933
  const id = useId();
770
934
  const map = (value && typeof value === 'object' ? value : { places: [] });
771
935
  const places = Array.isArray(map.places) ? map.places : [];
@@ -778,35 +942,36 @@ function MapInput({ name, def, value, onChange, onFocus }) {
778
942
  setSearch({ at: i, q, results: null, error: null, busy: true });
779
943
  try {
780
944
  const r = await call(`geocode?q=${encodeURIComponent(q)}`);
781
- 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 });
945
+ setSearch({ at: i, q, results: r.results, error: r.results.length ? null : ui.t('map.nothingFound'), busy: false });
782
946
  }
783
947
  catch (err) {
784
- setSearch({ at: i, q, results: null, error: err instanceof EditorError ? err.problems.join(' ') : 'Address search failed.', busy: false });
948
+ setSearch({ at: i, q, results: null, error: err instanceof EditorError ? err.problems.join(' ') : ui.t('map.searchFailed'), busy: false });
785
949
  }
786
950
  };
787
- 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) => {
788
- const title = place.name.trim() || `place ${i + 1}`;
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 });
789
953
  const located = place.lat !== null && place.lng !== null && Number.isFinite(place.lat) && Number.isFinite(place.lng);
790
954
  const q = search?.at === i ? search.q : (place.address ?? '');
791
- 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) => {
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) => {
792
956
  if (e.key === 'Enter') {
793
957
  e.preventDefault();
794
958
  void find(i, (place.address ?? '').trim());
795
959
  }
796
- } }), _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: () => {
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: () => {
797
961
  update(i, { lat: r.lat, lng: r.lng, ...(place.name.trim() ? {} : { name: r.name }), address: place.address?.trim() ? place.address : r.address });
798
962
  setSearch(null);
799
- }, 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) => {
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) => {
800
964
  setPasted({ ...pasted, [i]: e.target.value });
801
965
  const p = parseMapLink(e.target.value);
802
966
  if (p)
803
967
  update(i, { lat: p.lat, lng: p.lng });
804
968
  else if (!e.target.value.trim())
805
969
  update(i, { lat: null, lng: null });
806
- }, 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));
807
- }), _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" }) })] }));
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') }) })] }));
808
972
  }
809
- function SlidesInput({ name, def, value, onChange, onFocus }) {
973
+ function SlidesInput({ name, def, value, fallback, onChange, onFocus }) {
974
+ const ui = useUi();
810
975
  const id = useId();
811
976
  const slides = Array.isArray(value) ? value : [];
812
977
  const max = def.max ?? 10;
@@ -820,27 +985,44 @@ function SlidesInput({ name, def, value, onChange, onFocus }) {
820
985
  [next[i], next[to]] = [next[to], next[i]];
821
986
  set(next);
822
987
  };
823
- 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) => {
824
- const title = slide.title?.trim() || `slide ${i + 1}`;
825
- 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));
826
- }), _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" }) })] }));
827
- }
828
- /** A short name for a list item: its first text field's value, or "Item 3". */
829
- function itemTitle(fields, item, i) {
830
- for (const [f, d] of Object.entries(fields)) {
831
- const v = item[f];
832
- if (d.type === 'text' && typeof v === 'string' && v.trim())
833
- return v.trim().slice(0, 40);
834
- if (d.type === 'link' && v && typeof v === 'object' && typeof v.label === 'string' && v.label.trim())
835
- return v.label.trim().slice(0, 40);
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') }) })] }));
992
+ }
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);
836
999
  }
837
- return `Item ${i + 1}`;
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;
1017
+ }
1018
+ return ui.t('list.itemN', { n: i + 1 });
838
1019
  }
839
1020
  /**
840
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
841
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.
842
1023
  */
843
- function ListInput({ name, def, value, onChange, onFocus }) {
1024
+ function ListInput({ name, def, value, fallback, onChange, onFocus }) {
1025
+ const ui = useUi();
844
1026
  const id = useId();
845
1027
  const items = Array.isArray(value) ? value : [];
846
1028
  const fields = def.fields ?? {};
@@ -857,19 +1039,46 @@ function ListInput({ name, def, value, onChange, onFocus }) {
857
1039
  set(next);
858
1040
  setOpenItem((o) => (o === i ? to : o === to ? i : o));
859
1041
  };
860
- 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: [items.length, " / ", max, " items"] }), items.map((item, i) => {
861
- 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);
862
1044
  const isOpen = openItem === i;
863
- 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": `Move ${title} earlier`, onClick: () => move(i, -1), children: "\u2191" }), _jsx("button", { type: "button", className: "vx-mini", disabled: i === items.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: () => {
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: () => {
864
1046
  set(items.filter((_, j) => j !== i));
865
1047
  setOpenItem(null);
866
- }, children: "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, onChange: (v) => update(i, { [f]: v }), onFocus: onFocus }, f))), def.schedule ? (_jsxs("div", { className: "vx-menu-row", children: [_jsxs("label", { className: "vx-sublabel", children: ["Shows from", _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: ["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));
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));
867
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: () => {
868
1050
  set([...items, {}]);
869
1051
  setOpenItem(items.length);
870
- }, children: "Add item" }) })] }));
1052
+ }, children: ui.t('list.add') }) })] }));
871
1053
  }
872
- function MediaInput({ name, def, value, onChange, onFocus }) {
1054
+ function MediaInput({ name, def, value, fallback, onChange, onFocus, }) {
1055
+ const ui = useUi();
1056
+ const { canUploadMedia } = useContext(PanelCaps);
1057
+ const [importing, setImporting] = useState(false);
1058
+ const [importError, setImportError] = useState(null);
1059
+ // The page shows an image from the site's own files (no media library id): show it, and offer to import it.
1060
+ const fromCode = !value?.url ? fallbackImage(fallback) : null;
1061
+ const importable = fromCode && typeof location !== 'undefined' ? sameSiteImage(fromCode.url, location.href) : null;
1062
+ const importIntoMedia = async () => {
1063
+ if (!importable || !fromCode)
1064
+ return;
1065
+ setImporting(true);
1066
+ setImportError(null);
1067
+ try {
1068
+ const res = await fetch(importable.href, { credentials: 'same-origin' });
1069
+ const blob = res.ok ? await res.blob() : null;
1070
+ if (!blob || !blob.type.startsWith('image/'))
1071
+ throw new EditorError(res.status, [ui.t('media.notImage')]);
1072
+ const m = await call('media', { method: 'POST', body: { fileName: importable.pathname, data: await toBase64(blob), alt: fromCode.alt } });
1073
+ onChange({ id: m.id, url: m.url, alt: m.alt });
1074
+ }
1075
+ catch (err) {
1076
+ setImportError(err instanceof EditorError ? err.problems.join(' ') : ui.t('media.importFailed'));
1077
+ }
1078
+ finally {
1079
+ setImporting(false);
1080
+ }
1081
+ };
873
1082
  const [picking, setPicking] = useState(false);
874
1083
  const [search, setSearch] = useState('');
875
1084
  const [items, setItems] = useState(null);
@@ -885,21 +1094,31 @@ function MediaInput({ name, def, value, onChange, onFocus }) {
885
1094
  setItems(r.data);
886
1095
  setError(null);
887
1096
  })
888
- .catch((err) => setError(err instanceof EditorError ? err.problems.join(' ') : 'Could not load images.'));
1097
+ .catch((err) => setError(err instanceof EditorError ? err.problems.join(' ') : currentUi.t('media.loadFailed')));
889
1098
  }, 250);
890
1099
  return () => clearTimeout(t);
891
1100
  }, [picking, search]);
892
- 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: () => {
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: () => {
893
1102
  onChange({ id: m.id, url: m.url, alt: m.alt });
894
1103
  setPicking(false);
895
1104
  }, children: [_jsx("img", { src: m.thumbUrl, alt: "" }), _jsx("span", { children: m.alt || m.name })] }, m.id))) })] })) : null] }));
896
1105
  }
1106
+ /** A file's bytes as base64 (no data: prefix). */
1107
+ async function toBase64(blob) {
1108
+ const bytes = new Uint8Array(await blob.arrayBuffer());
1109
+ let bin = '';
1110
+ for (let i = 0; i < bytes.length; i += 0x8000)
1111
+ bin += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
1112
+ return btoa(bin);
1113
+ }
897
1114
  // ----------------------------------------------------------------- styles
898
1115
  // Scoped by the vx- prefix and reset at .vx-root so the site's own CSS
899
1116
  // neither leaks in much nor gets touched.
900
1117
  const STYLES = `
901
1118
  .vx-root{all:initial;font:14px/1.45 system-ui,-apple-system,"Segoe UI",sans-serif;color:#18181b}
902
1119
  .vx-root *{box-sizing:border-box;font:inherit;color:inherit}
1120
+ .vx-root .vx-fill{margin:0 0 12px;padding:8px 10px;border:1px dashed #d4d4d8;border-radius:6px}
1121
+ .vx-root .vx-fill p{margin:0 0 6px}
903
1122
  .vx-root code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}
904
1123
  .vx-outline{position:fixed;z-index:2147483000;pointer-events:none;border:2px dashed #6d28d9;border-radius:6px}
905
1124
  .vx-outline-active{border-style:solid;box-shadow:0 0 0 4px rgba(109,40,217,.15)}
@@ -908,7 +1127,7 @@ const STYLES = `
908
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}
909
1128
  .vx-inline-keys{color:#a1a1aa}
910
1129
  [data-veroxm-inline]{outline:none;cursor:text;caret-color:auto}
911
- .vx-tag{position:absolute;top:-24px;left:-2px;background:#6d28d9;color:#fff;font-size:12px;padding:2px 8px;border-radius:4px;white-space:nowrap}
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}
912
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)}
913
1132
  .vx-toolbar .vx-muted{color:#a1a1aa}
914
1133
  .vx-brand{display:flex;align-items:center;gap:6px;font-weight:600;padding:0 4px}
@@ -917,10 +1136,11 @@ const STYLES = `
917
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}
918
1137
  .vx-toolbar .vx-btn{background:#27272a;border-color:#3f3f46;color:#fafafa}
919
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}
920
1140
  .vx-btn:disabled{opacity:.5;cursor:not-allowed}
921
1141
  .vx-primary{background:#6d28d9;border-color:#6d28d9;color:#fff}
922
1142
  .vx-root :focus-visible{outline:2px solid #f59e0b;outline-offset:2px}
923
- .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)}
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)}
924
1144
  .vx-panel-head{display:flex;justify-content:space-between;gap:8px;padding:14px 16px;border-bottom:1px solid #f4f4f5}
925
1145
  .vx-panel-head h2{margin:0;font-size:16px;font-weight:650}
926
1146
  .vx-panel-head p{margin:2px 0 0}
@@ -938,15 +1158,16 @@ const STYLES = `
938
1158
  .vx-field input::placeholder,.vx-field textarea::placeholder{color:#a1a1aa;opacity:1}
939
1159
  .vx-field textarea{resize:vertical;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}
940
1160
  .vx-count{font-size:12px;color:#71717a}
1161
+ .vx-root bdi{unicode-bidi:isolate}
941
1162
  .vx-preview{max-width:100%;max-height:160px;border-radius:8px;object-fit:contain;background:#f4f4f5;align-self:flex-start}
942
1163
  .vx-picker{border:1px solid #e4e4e7;border-radius:10px;padding:8px;margin-top:6px}
943
1164
  .vx-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;margin-top:8px;max-height:240px;overflow:auto}
944
- .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}
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}
945
1166
  .vx-grid button[aria-pressed="true"]{border-color:#6d28d9}
946
1167
  .vx-grid img{width:100%;aspect-ratio:1;object-fit:cover;border-radius:6px}
947
1168
  .vx-grid span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
948
1169
  .vx-status{margin:0 0 8px;min-height:20px;color:#52525b}
949
- .vx-errors{margin:0 0 8px;padding-left:18px;color:#b91c1c}
1170
+ .vx-errors{margin:0 0 8px;padding-inline-start:18px;color:#b91c1c}
950
1171
  .vx-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
951
1172
  .vx-actions[hidden]{display:none}
952
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}
@@ -961,7 +1182,7 @@ const STYLES = `
961
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}
962
1183
  .vx-list-title{font-weight:650;margin:0 0 6px}
963
1184
  .vx-list ul{list-style:none;margin:0;padding:0}
964
- .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}
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}
965
1186
  .vx-list button:hover{background:#f4f4f5}
966
1187
  @media (prefers-color-scheme: dark){
967
1188
  .vx-root{color:#fafafa}