@veroxm/react-sdk 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,5 +17,5 @@ interface Props {
17
17
  /** The editor. Styling hooks: .vx-rte, .vx-rte-toolbar, .vx-rte-area (override with your own classes via className). */
18
18
  export declare function RichTextInput({ id, value, onChange, onFocus, max, required, labelledBy, placeholder, regionProps, className }: Props): import("react").JSX.Element;
19
19
  /** Styles for the editor, using the overlay's vx- tokens. */
20
- export declare const RICH_TEXT_STYLES = "\n.vx-rte{display:flex;flex-direction:column;gap:4px}\n.vx-rte-toolbar{display:flex;flex-wrap:wrap;gap:2px;border:1px solid #d4d4d8;border-bottom:0;border-radius:8px 8px 0 0;padding:3px;background:#fafafa}\n.vx-rte-btn{appearance:none;border:0;background:transparent;border-radius:6px;padding:3px 7px;font-size:12px;cursor:pointer;min-width:28px;min-height:26px}\n.vx-rte-btn:hover{background:#e4e4e7}\n.vx-rte-btn[aria-pressed=\"true\"]{background:#ede9fe;color:#5b21b6}\n.vx-rte-area{min-height:120px;max-height:320px;overflow:auto;border:1px solid #d4d4d8;border-radius:0 0 8px 8px;padding:8px 10px;background:#fff;line-height:1.5;margin-top:-4px}\n.vx-rte-area:empty::before{content:attr(data-placeholder);color:#a1a1aa}\n.vx-rte-area p,.vx-rte-area ul,.vx-rte-area ol,.vx-rte-area blockquote{margin:0 0 8px}\n.vx-rte-area ul,.vx-rte-area ol{padding-left:22px}\n.vx-rte-area h2{font-size:18px;font-weight:700;margin:4px 0 8px}\n.vx-rte-area h3{font-size:15px;font-weight:700;margin:4px 0 6px}\n.vx-rte-area a{color:#6d28d9;text-decoration:underline}\n.vx-rte-link{border:1px solid #e4e4e7;border-radius:8px;padding:6px 8px}\n.vx-rte-link-row{display:flex;gap:6px}\n.vx-rte-link-row input{flex:1;padding:6px 8px;border:1px solid #d4d4d8;border-radius:8px}\n.vx-rte-error{color:#b91c1c;margin:4px 0 0;font-size:12px}\n.vx-count-over{color:#b91c1c}\n@media (prefers-color-scheme: dark){\n.vx-rte-toolbar{background:#18181b;border-color:#3f3f46}\n.vx-rte-btn:hover{background:#27272a}\n.vx-rte-btn[aria-pressed=\"true\"]{background:#2e1065;color:#ddd6fe}\n.vx-rte-area{background:#09090b;border-color:#3f3f46}\n.vx-rte-area a{color:#c4b5fd}\n.vx-rte-link{border-color:#3f3f46}\n.vx-rte-link-row input{background:#09090b;border-color:#3f3f46}\n.vx-rte-error,.vx-count-over{color:#fca5a5}\n}\n";
20
+ export declare const RICH_TEXT_STYLES = "\n.vx-rte{display:flex;flex-direction:column;gap:4px}\n.vx-rte-toolbar{display:flex;flex-wrap:wrap;gap:2px;border:1px solid #d4d4d8;border-bottom:0;border-radius:8px 8px 0 0;padding:3px;background:#fafafa}\n.vx-rte-btn{appearance:none;border:0;background:transparent;border-radius:6px;padding:3px 7px;font-size:12px;cursor:pointer;min-width:28px;min-height:26px}\n.vx-rte-btn:hover{background:#e4e4e7}\n.vx-rte-btn[aria-pressed=\"true\"]{background:#ede9fe;color:#5b21b6}\n.vx-rte-area{min-height:120px;max-height:320px;overflow:auto;border:1px solid #d4d4d8;border-radius:0 0 8px 8px;padding:8px 10px;background:#fff;line-height:1.5;margin-top:-4px}\n.vx-rte-area:empty::before{content:attr(data-placeholder);color:#a1a1aa}\n.vx-rte-area p,.vx-rte-area ul,.vx-rte-area ol,.vx-rte-area blockquote{margin:0 0 8px}\n.vx-rte-area ul,.vx-rte-area ol{padding-inline-start:22px}\n.vx-rte-area h2{font-size:18px;font-weight:700;margin:4px 0 8px}\n.vx-rte-area h3{font-size:15px;font-weight:700;margin:4px 0 6px}\n.vx-rte-area a{color:#6d28d9;text-decoration:underline}\n.vx-rte-link{border:1px solid #e4e4e7;border-radius:8px;padding:6px 8px}\n.vx-rte-link-row{display:flex;gap:6px}\n.vx-rte-link-row input{flex:1;padding:6px 8px;border:1px solid #d4d4d8;border-radius:8px}\n.vx-rte-error{color:#b91c1c;margin:4px 0 0;font-size:12px}\n.vx-count-over{color:#b91c1c}\n@media (prefers-color-scheme: dark){\n.vx-rte-toolbar{background:#18181b;border-color:#3f3f46}\n.vx-rte-btn:hover{background:#27272a}\n.vx-rte-btn[aria-pressed=\"true\"]{background:#2e1065;color:#ddd6fe}\n.vx-rte-area{background:#09090b;border-color:#3f3f46}\n.vx-rte-area a{color:#c4b5fd}\n.vx-rte-link{border-color:#3f3f46}\n.vx-rte-link-row input{background:#09090b;border-color:#3f3f46}\n.vx-rte-error,.vx-count-over{color:#fca5a5}\n}\n";
21
21
  export {};
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { useUi } from './ui-context.js';
4
5
  // A small rich text editor for slot fields declared with field.richText():
5
6
  // paragraphs, H2/H3, bold, italic, links and lists -- exactly what VeroXM
6
7
  // keeps when it saves (apps/api/src/slots/slot-fields.ts sanitizeRichText),
@@ -77,6 +78,7 @@ function normaliseBlocks(root) {
77
78
  }
78
79
  /** The editor. Styling hooks: .vx-rte, .vx-rte-toolbar, .vx-rte-area (override with your own classes via className). */
79
80
  export function RichTextInput({ id, value, onChange, onFocus, max, required, labelledBy, placeholder, regionProps, className }) {
81
+ const ui = useUi();
80
82
  const areaRef = useRef(null);
81
83
  const emitted = useRef(null);
82
84
  const savedRange = useRef(null);
@@ -145,7 +147,7 @@ export function RichTextInput({ id, value, onChange, onFocus, max, required, lab
145
147
  const applyLink = () => {
146
148
  const url = href.trim();
147
149
  if (url && !safeHref(url))
148
- return setLinkError('Use https://, http://, mailto:, tel:, / or #');
150
+ return setLinkError(ui.t('rte.badLink'));
149
151
  const sel = document.getSelection();
150
152
  areaRef.current?.focus();
151
153
  if (savedRange.current && sel) {
@@ -183,10 +185,10 @@ export function RichTextInput({ id, value, onChange, onFocus, max, required, lab
183
185
  // Keep the selection in the text while clicking the toolbar.
184
186
  onMouseDown: (e) => e.preventDefault(), onClick: onClick, children: text }, key));
185
187
  const over = max !== undefined && length > max;
186
- return (_jsxs("div", { className: `vx-rte${className ? ` ${className}` : ''}`, children: [_jsxs("div", { className: "vx-rte-toolbar", role: "toolbar", "aria-label": "Formatting", "aria-controls": id, children: [button('b', 'Bold (Ctrl+B)', _jsx("strong", { children: "B" }), () => run('bold'), active.bold), button('i', 'Italic (Ctrl+I)', _jsx("em", { children: "I" }), () => run('italic'), active.italic), button('h2', 'Heading', 'H2', () => toggleBlock('h2'), active.h2), button('h3', 'Subheading', 'H3', () => toggleBlock('h3'), active.h3), button('ul', 'Bulleted list', '• List', () => run('insertUnorderedList'), active.insertUnorderedList), button('ol', 'Numbered list', '1. List', () => run('insertOrderedList'), active.insertOrderedList), button('a', 'Link (Ctrl+K)', 'Link', startLink), button('x', 'Clear formatting', 'Clear', () => {
188
+ return (_jsxs("div", { className: `vx-rte${className ? ` ${className}` : ''}`, children: [_jsxs("div", { className: "vx-rte-toolbar", role: "toolbar", "aria-label": ui.t('rte.toolbar'), "aria-controls": id, children: [button('b', ui.t('rte.bold'), _jsx("strong", { children: "B" }), () => run('bold'), active.bold), button('i', ui.t('rte.italic'), _jsx("em", { children: "I" }), () => run('italic'), active.italic), button('h2', ui.t('rte.heading'), 'H2', () => toggleBlock('h2'), active.h2), button('h3', ui.t('rte.subheading'), 'H3', () => toggleBlock('h3'), active.h3), button('ul', ui.t('rte.bullets'), ui.t('rte.bulletsShort'), () => run('insertUnorderedList'), active.insertUnorderedList), button('ol', ui.t('rte.numbered'), ui.t('rte.numberedShort'), () => run('insertOrderedList'), active.insertOrderedList), button('a', ui.t('rte.link'), ui.t('rte.linkShort'), startLink), button('x', ui.t('rte.clear'), ui.t('rte.clearShort'), () => {
187
189
  run('removeFormat');
188
190
  run('formatBlock', 'p');
189
- })] }), linking ? (_jsxs("div", { className: "vx-rte-link", children: [_jsx("label", { htmlFor: `${id}-href`, className: "vx-sublabel", children: "Link address (leave empty to remove)" }), _jsxs("div", { className: "vx-rte-link-row", children: [_jsx("input", { id: `${id}-href`, type: "text", inputMode: "url", autoFocus: true, value: href, placeholder: "https://\u2026 or /page", onChange: (e) => setHref(e.target.value), onKeyDown: (e) => {
191
+ })] }), linking ? (_jsxs("div", { className: "vx-rte-link", children: [_jsx("label", { htmlFor: `${id}-href`, className: "vx-sublabel", children: ui.t('rte.linkAddress') }), _jsxs("div", { className: "vx-rte-link-row", children: [_jsx("input", { id: `${id}-href`, type: "text", dir: "ltr", inputMode: "url", autoFocus: true, value: href, placeholder: ui.t('common.pagePlaceholder'), onChange: (e) => setHref(e.target.value), onKeyDown: (e) => {
190
192
  if (e.key === 'Enter') {
191
193
  e.preventDefault();
192
194
  applyLink();
@@ -195,10 +197,10 @@ export function RichTextInput({ id, value, onChange, onFocus, max, required, lab
195
197
  e.stopPropagation();
196
198
  setLinking(false);
197
199
  }
198
- } }), _jsx("button", { type: "button", className: "vx-btn", onClick: applyLink, children: "Apply" })] }), linkError ? _jsx("p", { className: "vx-rte-error", role: "alert", children: linkError }) : null] })) : null, _jsx("div", { ...regionProps, id: id, ref: areaRef, className: "vx-rte-area", contentEditable: true, suppressContentEditableWarning: true, role: "textbox", "aria-multiline": "true", "aria-labelledby": labelledBy, "aria-required": required || undefined, "aria-invalid": over || undefined, "data-placeholder": placeholder, onInput: emit, onBlur: emit, onFocus: () => {
200
+ } }), _jsx("button", { type: "button", className: "vx-btn", onClick: applyLink, children: ui.t('rte.apply') })] }), linkError ? _jsx("p", { className: "vx-rte-error", role: "alert", children: linkError }) : null] })) : null, _jsx("div", { ...regionProps, id: id, ref: areaRef, className: "vx-rte-area", contentEditable: true, suppressContentEditableWarning: true, dir: "auto", role: "textbox", "aria-multiline": "true", "aria-labelledby": labelledBy, "aria-required": required || undefined, "aria-invalid": over || undefined, "data-placeholder": placeholder, onInput: emit, onBlur: emit, onFocus: () => {
199
201
  document.execCommand?.('defaultParagraphSeparator', false, 'p');
200
202
  onFocus?.();
201
- }, onPaste: onPaste, onKeyDown: onKeyDown, onKeyUp: refreshState, onMouseUp: refreshState }), max !== undefined ? (_jsxs("span", { className: `vx-count${over ? ' vx-count-over' : ''}`, children: [length, " / ", max, " characters, including formatting"] })) : null] }));
203
+ }, onPaste: onPaste, onKeyDown: onKeyDown, onKeyUp: refreshState, onMouseUp: refreshState }), max !== undefined ? (_jsx("span", { className: `vx-count${over ? ' vx-count-over' : ''}`, children: ui.t('rte.count', { n: length, max }) })) : null] }));
202
204
  }
203
205
  /** Styles for the editor, using the overlay's vx- tokens. */
204
206
  export const RICH_TEXT_STYLES = `
@@ -210,7 +212,7 @@ export const RICH_TEXT_STYLES = `
210
212
  .vx-rte-area{min-height:120px;max-height:320px;overflow:auto;border:1px solid #d4d4d8;border-radius:0 0 8px 8px;padding:8px 10px;background:#fff;line-height:1.5;margin-top:-4px}
211
213
  .vx-rte-area:empty::before{content:attr(data-placeholder);color:#a1a1aa}
212
214
  .vx-rte-area p,.vx-rte-area ul,.vx-rte-area ol,.vx-rte-area blockquote{margin:0 0 8px}
213
- .vx-rte-area ul,.vx-rte-area ol{padding-left:22px}
215
+ .vx-rte-area ul,.vx-rte-area ol{padding-inline-start:22px}
214
216
  .vx-rte-area h2{font-size:18px;font-weight:700;margin:4px 0 8px}
215
217
  .vx-rte-area h3{font-size:15px;font-weight:700;margin:4px 0 6px}
216
218
  .vx-rte-area a{color:#6d28d9;text-decoration:underline}
@@ -26,6 +26,12 @@ export declare function fallbackImage(v: unknown): {
26
26
  url: string;
27
27
  alt: string;
28
28
  } | null;
29
+ /**
30
+ * The page's fallback item a list item stands for, so a field inside it (an award's logo) can show and import the
31
+ * page's own image: the fallback item with the same text in one of the item's text fields (items keep their
32
+ * names when reordered), else the one at the same position. Null when the page has no list there.
33
+ */
34
+ export declare function fallbackItem(fields: Record<string, SeedFieldDef>, item: Record<string, unknown>, index: number, fallbackList: unknown): Record<string, unknown> | null;
29
35
  /** Whether an image address is on this site (so the editor may read it and import it), resolved against `base`. */
30
36
  export declare function sameSiteImage(url: string, base: string): URL | null;
31
37
  /** The slot's fallback as the page rendered it (data-veroxm-fallback), or null. Never the shown values: those may be a test variant's. */
@@ -75,6 +75,24 @@ export function fallbackImage(v) {
75
75
  const url = [v.url, v.src, v.webpUrl].find((u) => typeof u === 'string' && u.trim() !== '');
76
76
  return url ? { url, alt: typeof v.alt === 'string' ? v.alt : '' } : null;
77
77
  }
78
+ /**
79
+ * The page's fallback item a list item stands for, so a field inside it (an award's logo) can show and import the
80
+ * page's own image: the fallback item with the same text in one of the item's text fields (items keep their
81
+ * names when reordered), else the one at the same position. Null when the page has no list there.
82
+ */
83
+ export function fallbackItem(fields, item, index, fallbackList) {
84
+ if (!Array.isArray(fallbackList))
85
+ return null;
86
+ const items = fallbackList.filter(isObject);
87
+ const texts = Object.entries(fields).filter(([f, d]) => d.type === 'text' && typeof item[f] === 'string' && item[f].trim());
88
+ for (const [f] of texts) {
89
+ const match = items.find((fb) => typeof fb[f] === 'string' && fb[f].trim() === item[f].trim());
90
+ if (match)
91
+ return match;
92
+ }
93
+ const atIndex = fallbackList[index];
94
+ return isObject(atIndex) ? atIndex : null;
95
+ }
78
96
  /** Whether an image address is on this site (so the editor may read it and import it), resolved against `base`. */
79
97
  export function sameSiteImage(url, base) {
80
98
  try {
@@ -0,0 +1,4 @@
1
+ import { type EditorTranslator } from './i18n.js';
2
+ /** The editor's interface language, for every part of the overlay (the bar, the panel and its fields). */
3
+ export declare const Ui: import("react").Context<EditorTranslator>;
4
+ export declare const useUi: () => EditorTranslator;
@@ -0,0 +1,6 @@
1
+ 'use client';
2
+ import { createContext, useContext } from 'react';
3
+ import { createTranslator } from './i18n.js';
4
+ /** The editor's interface language, for every part of the overlay (the bar, the panel and its fields). */
5
+ export const Ui = createContext(createTranslator('en'));
6
+ export const useUi = () => useContext(Ui);
package/dist/index.d.ts CHANGED
@@ -55,6 +55,6 @@ export { VeroxmRegion, renderComponent, regionSlotProps } from './components.js'
55
55
  export { VeroxmComponentBoundary } from './component-boundary.js';
56
56
  export type { RegisteredComponent, ComponentSchema, SlotComponentValue } from './slots.js';
57
57
  export type { VeroxmRegionProps, RegionFallback, RenderComponentOptions } from './components.js';
58
- export type { VeroxmSlotProps, SlotFieldDef, SlotFieldDefs, SlotValues, SlotInfo, SlotTest, SlotMedia, SlotLink, SlotMenuItem, SlotFallback, ListItemFieldDef, NestedListItemFieldDef, SlotVideo, SlotSlide, SlotMap, SlotPlace, SlotChart, SlotState, SlotsConfig, LoadSlotOptions, SlotPerson, } from './slots.js';
58
+ export type { VeroxmSlotProps, SlotFieldDef, Label, LabelMap, SlotFieldDefs, SlotValues, SlotInfo, SlotTest, SlotMedia, SlotLink, SlotMenuItem, SlotFallback, ListItemFieldDef, NestedListItemFieldDef, SlotVideo, SlotSlide, SlotMap, SlotPlace, SlotChart, SlotState, SlotsConfig, LoadSlotOptions, SlotPerson, } from './slots.js';
59
59
  export { loadStructuredData, jsonLdScript } from './structured-data.js';
60
60
  export type { StructuredDataOptions } from './structured-data.js';
@@ -1,8 +1,8 @@
1
- import { type PublishedSlot, type SlotFieldDefs } from '../slots-core.js';
1
+ import { type Label, type PublishedSlot, type SlotFieldDefs } from '../slots-core.js';
2
2
  export declare function cachedPublishedSlot(name: string, locale: string | undefined, def?: SlotDefinition): Promise<PublishedSlot | null>;
3
3
  export interface SlotDefinition {
4
4
  fields: SlotFieldDefs;
5
- label?: string;
5
+ label?: Label;
6
6
  path?: string;
7
7
  /** What the site shows from its fallback, for VeroXM's dashboard. */
8
8
  shown?: Record<string, unknown>;
@@ -10,7 +10,7 @@ export type { RegisteredComponent, ComponentSchema, SlotComponentValue } from '.
10
10
  export type { VeroxmRegionProps, RegionFallback, RenderComponentOptions } from '../components.js';
11
11
  export { VeroxmEditor } from './editor.js';
12
12
  export { field, configureSlots, loadSlot, mergeSlotValues } from '../slots-core.js';
13
- export type { VeroxmSlotProps, SlotFieldDef, SlotFieldDefs, SlotValues, SlotInfo, SlotTest, SlotMedia, SlotLink, SlotMenuItem, SlotFallback, ListItemFieldDef, NestedListItemFieldDef, SlotVideo, SlotSlide, SlotMap, SlotPlace, SlotChart, SlotsConfig, LoadSlotOptions, SlotPerson } from '../slots-core.js';
13
+ export type { VeroxmSlotProps, SlotFieldDef, SlotFieldDefs, SlotValues, SlotInfo, SlotTest, SlotMedia, SlotLink, SlotMenuItem, SlotFallback, ListItemFieldDef, NestedListItemFieldDef, SlotVideo, SlotSlide, SlotMap, SlotPlace, SlotChart, SlotsConfig, LoadSlotOptions, SlotPerson, Label, LabelMap } from '../slots-core.js';
14
14
  export { NavMenu } from '../site/nav-menu.js';
15
15
  export { SiteHeader, SiteFooter, headerFields, footerFields } from '../site/site-parts.js';
16
16
  export { VeroxmSiteStyles } from '../site/styles.js';
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- import { loadPublishedSlot, type SlotFieldDefs, type VeroxmSlotProps } from '../slots-core.js';
2
+ import { loadPublishedSlot, type Label, type SlotFieldDefs, type VeroxmSlotProps } from '../slots-core.js';
3
3
  /**
4
4
  * <VeroxmSlot> for Next.js App Router. Outside draft mode it shows the
5
5
  * published content (cached) -- or, when the slot is under a live A/B test
@@ -11,7 +11,7 @@ export declare function VeroxmSlot<F extends SlotFieldDefs>(props: VeroxmSlotPro
11
11
  /** Reads a slot's published content; `def` is passed when the loader also reports the definition. */
12
12
  type Loader = (name: string, locale: string | undefined, def?: {
13
13
  fields: SlotFieldDefs;
14
- label?: string;
14
+ label?: Label;
15
15
  path?: string;
16
16
  shown?: Record<string, unknown>;
17
17
  }) => Promise<Loaded>;
package/dist/next/slot.js CHANGED
@@ -2,7 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  import { cookies, draftMode } from 'next/headers';
3
3
  import { after } from 'next/server';
4
4
  import { Suspense } from 'react';
5
- import { fallbackValues, loadPublishedSlot, loadSlotFor, loadSlotForVisitor, mergeSlotValues, reportSlot, resolveSlotsConfig, } from '../slots-core.js';
5
+ import { fallbackValues, labelAttributes, loadPublishedSlot, loadSlotFor, loadSlotForVisitor, mergeSlotValues, reportSlot, resolveSlotsConfig, } from '../slots-core.js';
6
6
  import { PREVIEW_COOKIE, VISITOR_COOKIE } from '../editor/constants.js';
7
7
  import { EDITOR_COOKIE, editorApi } from '../editor/server.js';
8
8
  import { VeroxmEditor } from './editor.js';
@@ -47,7 +47,7 @@ export async function slotWith(props, load, cached) {
47
47
  };
48
48
  // A draft of a slot never published: an empty list there means "not set yet" (the page keeps its own list).
49
49
  const values = mergeSlotValues(fields, fallback, draft?.values ?? null, { neverPublished: !draft?.version });
50
- return (_jsxs(_Fragment, { children: [_jsx("div", { "data-veroxm-slot": name, "data-veroxm-label": label ?? '', "data-veroxm-locale": locale ?? '', "data-veroxm-shown": JSON.stringify(values), "data-veroxm-fallback": JSON.stringify(site), style: { display: 'contents' }, children: children(values, slot) }), _jsx(VeroxmEditor, {})] }));
50
+ return (_jsxs(_Fragment, { children: [_jsx("div", { "data-veroxm-slot": name, ...labelAttributes(label), "data-veroxm-locale": locale ?? '', "data-veroxm-shown": JSON.stringify(values), "data-veroxm-fallback": JSON.stringify(site), style: { display: 'contents' }, children: children(values, slot) }), _jsx(VeroxmEditor, {})] }));
51
51
  }
52
52
  const cacheComponents = Boolean(process.env.__NEXT_CACHE_COMPONENTS);
53
53
  function render({ name, children, fields, fallback }, data) {
package/dist/node.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type SlotFieldDefs, type SlotsConfig } from './slots-core.js';
1
+ import { type Label, type SlotFieldDefs, type SlotsConfig } from './slots-core.js';
2
2
  interface NodeRequest extends AsyncIterable<Uint8Array | string> {
3
3
  method?: string;
4
4
  url?: string;
@@ -20,7 +20,7 @@ export interface VeroxmMiddlewareOptions extends SlotsConfig {
20
20
  export interface SlotDefinition {
21
21
  name: string;
22
22
  fields: SlotFieldDefs;
23
- label?: string;
23
+ label?: Label;
24
24
  /** Page path where it appears, shown in VeroXM and used by "Edit on page". */
25
25
  path?: string;
26
26
  /** The content the site shows before anything is published, so VeroXM's dashboard can show it in empty fields. */
@@ -7,25 +7,25 @@ import { type SlotLink, type SlotMedia, type SlotMenuItem } from '../slots-core.
7
7
  */
8
8
  export declare const headerFields: {
9
9
  logo: {
10
- label?: string;
10
+ label?: import("../slots-core.js").Label;
11
11
  required?: boolean;
12
12
  type: "media";
13
13
  };
14
14
  logoText: {
15
- label?: string;
15
+ label?: import("../slots-core.js").Label;
16
16
  required?: boolean;
17
17
  max?: number;
18
18
  type: "text";
19
19
  };
20
20
  menu: {
21
- label?: string;
21
+ label?: import("../slots-core.js").Label;
22
22
  required?: boolean;
23
23
  depth?: 1 | 2 | 3;
24
24
  icons?: readonly string[] | undefined;
25
25
  type: "menu";
26
26
  };
27
27
  cta: {
28
- label?: string;
28
+ label?: import("../slots-core.js").Label;
29
29
  required?: boolean;
30
30
  type: "link";
31
31
  };
@@ -33,27 +33,27 @@ export declare const headerFields: {
33
33
  /** What marketers edit in a site footer. Each top-level item of `columns` is a column heading, its sub-items the links under it. */
34
34
  export declare const footerFields: {
35
35
  columns: {
36
- label?: string;
36
+ label?: import("../slots-core.js").Label;
37
37
  required?: boolean;
38
38
  depth?: 1 | 2 | 3;
39
39
  icons?: readonly string[] | undefined;
40
40
  type: "menu";
41
41
  };
42
42
  text: {
43
- label?: string;
43
+ label?: import("../slots-core.js").Label;
44
44
  required?: boolean;
45
45
  max?: number;
46
46
  type: "richText";
47
47
  };
48
48
  social: {
49
- label?: string;
49
+ label?: import("../slots-core.js").Label;
50
50
  required?: boolean;
51
51
  depth?: 1 | 2 | 3;
52
52
  icons?: readonly string[] | undefined;
53
53
  type: "menu";
54
54
  };
55
55
  legal: {
56
- label?: string;
56
+ label?: import("../slots-core.js").Label;
57
57
  required?: boolean;
58
58
  max?: number;
59
59
  type: "text";
@@ -1,7 +1,10 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { ChartValue } from './site/chart.js';
3
+ import type { Label, LabelMap } from './editor/i18n.js';
4
+ export type { Label, LabelMap };
3
5
  interface BaseField {
4
- label?: string;
6
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
7
+ label?: Label;
5
8
  required?: boolean;
6
9
  }
7
10
  export type SlotFieldDef = (BaseField & {
@@ -21,6 +24,7 @@ export type SlotFieldDef = (BaseField & {
21
24
  }) | (BaseField & {
22
25
  type: 'select';
23
26
  options: readonly string[];
27
+ optionLabels?: Readonly<Record<string, Label>>;
24
28
  }) | (BaseField & {
25
29
  type: 'menu';
26
30
  depth?: 1 | 2 | 3;
@@ -43,6 +47,7 @@ export type SlotFieldDef = (BaseField & {
43
47
  fields: Record<string, ListItemFieldDef>;
44
48
  max?: number;
45
49
  schedule?: boolean;
50
+ titleField?: string;
46
51
  });
47
52
  export type SlotFieldDefs = Record<string, SlotFieldDef>;
48
53
  /** The field types of a list inside a list item (a card's ticked points): plain values only. */
@@ -57,10 +62,11 @@ export type ListItemFieldDef = Extract<SlotFieldDef, {
57
62
  fields: Record<string, NestedListItemFieldDef>;
58
63
  max?: number;
59
64
  schedule?: boolean;
65
+ titleField?: string;
60
66
  });
61
67
  /** What VeroXM is told about a registered component: its fields, and the version of that field list. */
62
68
  export interface ComponentSchema<F extends SlotFieldDefs = SlotFieldDefs> {
63
- label?: string;
69
+ label?: Label;
64
70
  /** Raise it when the fields change in a way values saved for the old fields don't fit. */
65
71
  version: number;
66
72
  fields: F;
@@ -99,7 +105,7 @@ type ComponentsOf<L extends readonly RegisteredComponent[]> = {
99
105
  * ```
100
106
  */
101
107
  export declare function defineComponent<const N extends string, F extends SlotFieldDefs>(name: N, def: {
102
- label?: string;
108
+ label?: Label;
103
109
  version?: number;
104
110
  fields: F;
105
111
  render: (props: {
@@ -111,7 +117,8 @@ export declare const field: {
111
117
  text: (o?: BaseField & {
112
118
  max?: number;
113
119
  }) => {
114
- label?: string;
120
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
121
+ label?: Label;
115
122
  required?: boolean;
116
123
  max?: number;
117
124
  type: "text";
@@ -119,33 +126,47 @@ export declare const field: {
119
126
  richText: (o?: BaseField & {
120
127
  max?: number;
121
128
  }) => {
122
- label?: string;
129
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
130
+ label?: Label;
123
131
  required?: boolean;
124
132
  max?: number;
125
133
  type: "richText";
126
134
  };
127
135
  media: (o?: BaseField) => {
128
- label?: string;
136
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
137
+ label?: Label;
129
138
  required?: boolean;
130
139
  type: "media";
131
140
  };
132
141
  link: (o?: BaseField) => {
133
- label?: string;
142
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
143
+ label?: Label;
134
144
  required?: boolean;
135
145
  type: "link";
136
146
  };
137
147
  number: (o?: BaseField) => {
138
- label?: string;
148
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
149
+ label?: Label;
139
150
  required?: boolean;
140
151
  type: "number";
141
152
  };
142
153
  boolean: (o?: BaseField) => {
143
- label?: string;
154
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
155
+ label?: Label;
144
156
  required?: boolean;
145
157
  type: "boolean";
146
158
  };
147
- select: <const T extends readonly [string, ...string[]]>(options: T, o?: BaseField) => {
148
- label?: string;
159
+ /**
160
+ * A choice from `options` (the values stored). `options` in the second argument gives each value a display label,
161
+ * one text or one per language; the stored values don't change:
162
+ * `field.select(['motor', 'health'], { label: 'Product line', options: { motor: { en: 'Motor', ar: 'المركبات' } } })`.
163
+ */
164
+ select: <const T extends readonly [string, ...string[]]>(options: T, o?: BaseField & {
165
+ options?: Partial<Record<T[number], Label>>;
166
+ }) => {
167
+ optionLabels?: Readonly<Record<string, Label>> | undefined;
168
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
169
+ label?: Label;
149
170
  required?: boolean;
150
171
  type: "select";
151
172
  options: T;
@@ -158,7 +179,8 @@ export declare const field: {
158
179
  depth?: 1 | 2 | 3;
159
180
  icons?: I;
160
181
  }) => {
161
- label?: string;
182
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
183
+ label?: Label;
162
184
  required?: boolean;
163
185
  depth?: 1 | 2 | 3;
164
186
  icons?: I;
@@ -169,6 +191,8 @@ export declare const field: {
169
191
  * has the `fields` you give (text, rich text, image, link, number, yes/no, choice, and one list of plain values, such
170
192
  * as a card's ticked points). `max` 1 to 50 items (default 20).
171
193
  * With `schedule`, each item may have a first and a last day it shows on (a ticker, a "New" badge that expires).
194
+ * `titleField` names the item field a collapsed item shows in the editor (default: the first required text field,
195
+ * then the first text field).
172
196
  *
173
197
  * ```tsx
174
198
  * cards: field.list({ title: field.text({ max: 40, required: true }), badge: field.text({ max: 24 }), link: field.link() }, { max: 12 })
@@ -177,17 +201,21 @@ export declare const field: {
177
201
  list: <const IF extends Record<string, ListItemFieldDef>>(fields: IF, o?: BaseField & {
178
202
  max?: number;
179
203
  schedule?: boolean;
204
+ titleField?: keyof IF & string;
180
205
  }) => {
181
- label?: string;
206
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
207
+ label?: Label;
182
208
  required?: boolean;
183
209
  max?: number;
184
210
  schedule?: boolean;
211
+ titleField?: keyof IF & string;
185
212
  type: "list";
186
213
  fields: IF;
187
214
  };
188
215
  /** A YouTube or Vimeo link, or a video file, that the site shows as a player. */
189
216
  video: (o?: BaseField) => {
190
- label?: string;
217
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
218
+ label?: Label;
191
219
  required?: boolean;
192
220
  type: "video";
193
221
  };
@@ -195,7 +223,8 @@ export declare const field: {
195
223
  slides: (o?: BaseField & {
196
224
  max?: number;
197
225
  }) => {
198
- label?: string;
226
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
227
+ label?: Label;
199
228
  required?: boolean;
200
229
  max?: number;
201
230
  type: "slides";
@@ -204,14 +233,16 @@ export declare const field: {
204
233
  map: (o?: BaseField & {
205
234
  max?: number;
206
235
  }) => {
207
- label?: string;
236
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
237
+ label?: Label;
208
238
  required?: boolean;
209
239
  max?: number;
210
240
  type: "map";
211
241
  };
212
242
  /** A chart: numbers typed in, read from your own systems (Connected APIs), or from VeroXM's analytics. */
213
243
  chart: (o?: BaseField) => {
214
- label?: string;
244
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
245
+ label?: Label;
215
246
  required?: boolean;
216
247
  type: "chart";
217
248
  };
@@ -220,7 +251,8 @@ export declare const field: {
220
251
  * A component's fields can't be components or charts. Render the value with renderComponent.
221
252
  */
222
253
  component: <const L extends readonly RegisteredComponent[]>(components: L, o?: BaseField) => {
223
- label?: string;
254
+ /** What editors see: one text, or one per language ({ en: 'Tabs', ar: 'التبويبات' }). */
255
+ label?: Label;
224
256
  required?: boolean;
225
257
  type: "component";
226
258
  components: ComponentsOf<L>;
@@ -460,13 +492,13 @@ export interface ShownValues {
460
492
  * because work left on a timer may never run while a page is prerendered.
461
493
  */
462
494
  export type ReportScheduler = (send: () => Promise<void>) => void;
463
- export declare function reportSlot(name: string, fields: SlotFieldDefs, label?: string, path?: string, schedule?: ReportScheduler, shown?: ShownValues): void;
495
+ export declare function reportSlot(name: string, fields: SlotFieldDefs, label?: Label, path?: string, schedule?: ReportScheduler, shown?: ShownValues): void;
464
496
  /**
465
497
  * Reports one slot right away and waits for the answer (once per process,
466
498
  * like reportSlot). For code that must finish its requests inside the
467
499
  * render, such as a Next.js 'use cache' function.
468
500
  */
469
- export declare function reportSlotNow(name: string, fields: SlotFieldDefs, label?: string, path?: string, shown?: ShownValues): Promise<void>;
501
+ export declare function reportSlotNow(name: string, fields: SlotFieldDefs, label?: Label, path?: string, shown?: ShownValues): Promise<void>;
470
502
  /**
471
503
  * The values a slot shows from its `fallback` alone (fields the fallback
472
504
  * leaves empty are left out): what the site shows before anything is
@@ -488,7 +520,8 @@ export declare function slotInfo(name: string, published: PublishedSlot | null):
488
520
  export interface LoadSlotOptions<F extends SlotFieldDefs> {
489
521
  fields: F;
490
522
  fallback?: SlotFallback<F>;
491
- label?: string;
523
+ /** The slot's name in the editor and the dashboard: one text, or one per language. */
524
+ label?: Label;
492
525
  locale?: string;
493
526
  /** Page path, shown in the dashboard as where the slot was last seen. */
494
527
  path?: string;
@@ -537,4 +570,8 @@ export interface VeroxmSlotProps<F extends SlotFieldDefs> extends LoadSlotOption
537
570
  export declare function VeroxmSlot<F extends SlotFieldDefs>({ name, children, ...options }: VeroxmSlotProps<F>): Promise<ReactNode>;
538
571
  /** Test helper: forgets configuration, queued requests and reported definitions. */
539
572
  export declare function resetSlotsForTests(): void;
540
- export {};
573
+ /** A slot's label as the page marks it for the editor: data-veroxm-label (one text) and, for a per-language label, data-veroxm-labels. */
574
+ export declare function labelAttributes(label: Label | undefined): {
575
+ 'data-veroxm-label': string;
576
+ 'data-veroxm-labels'?: string;
577
+ };
@@ -22,7 +22,15 @@ export const field = {
22
22
  link: (o = {}) => ({ type: 'link', ...o }),
23
23
  number: (o = {}) => ({ type: 'number', ...o }),
24
24
  boolean: (o = {}) => ({ type: 'boolean', ...o }),
25
- select: (options, o = {}) => ({ type: 'select', options, ...o }),
25
+ /**
26
+ * A choice from `options` (the values stored). `options` in the second argument gives each value a display label,
27
+ * one text or one per language; the stored values don't change:
28
+ * `field.select(['motor', 'health'], { label: 'Product line', options: { motor: { en: 'Motor', ar: 'المركبات' } } })`.
29
+ */
30
+ select: (options, o = {}) => {
31
+ const { options: optionLabels, ...rest } = o;
32
+ return { type: 'select', options, ...rest, ...(optionLabels ? { optionLabels: optionLabels } : {}) };
33
+ },
26
34
  /**
27
35
  * A navigation menu marketers edit: links, with sub-menus up to `depth` levels (default 2, at most 3). Each item may
28
36
  * have a badge ("New") and a description; with `icons`, an icon chosen from those names (your site draws them).
@@ -33,12 +41,18 @@ export const field = {
33
41
  * has the `fields` you give (text, rich text, image, link, number, yes/no, choice, and one list of plain values, such
34
42
  * as a card's ticked points). `max` 1 to 50 items (default 20).
35
43
  * With `schedule`, each item may have a first and a last day it shows on (a ticker, a "New" badge that expires).
44
+ * `titleField` names the item field a collapsed item shows in the editor (default: the first required text field,
45
+ * then the first text field).
36
46
  *
37
47
  * ```tsx
38
48
  * cards: field.list({ title: field.text({ max: 40, required: true }), badge: field.text({ max: 24 }), link: field.link() }, { max: 12 })
39
49
  * ```
40
50
  */
41
- list: (fields, o = {}) => ({ type: 'list', fields, ...o }),
51
+ list: (fields, o = {}) => ({
52
+ type: 'list',
53
+ fields,
54
+ ...o,
55
+ }),
42
56
  /** A YouTube or Vimeo link, or a video file, that the site shows as a player. */
43
57
  video: (o = {}) => ({ type: 'video', ...o }),
44
58
  /** Slides for a slider: each an image with optional title, text and link. `max` 1 to 20 (default 10). */
@@ -214,7 +228,7 @@ export async function reportSlotNow(name, fields, label, path, shown) {
214
228
  reported.add(key);
215
229
  await sendReports([queued(key, name, fields, label, path, shown)]);
216
230
  }
217
- const reportKey = (name, fields, label, shown) => `${name}|${stable(fields)}|${label ?? ''}|${shown ? `${shown.locale ?? ''}:${stable(shown.values)}` : ''}`;
231
+ const reportKey = (name, fields, label, shown) => `${name}|${stable(fields)}|${stable(label ?? '')}|${shown ? `${shown.locale ?? ''}:${stable(shown.values)}` : ''}`;
218
232
  function queued(key, name, fields, label, path, shown) {
219
233
  const hasShown = shown && Object.keys(shown.values).length > 0;
220
234
  return { key, name, label, fields, path, ...(hasShown ? { shown: shown.values, ...(shown.locale ? { locale: shown.locale } : {}) } : {}) };
@@ -461,3 +475,10 @@ function withoutTrailingSlashes(url) {
461
475
  end--;
462
476
  return url.slice(0, end);
463
477
  }
478
+ /** A slot's label as the page marks it for the editor: data-veroxm-label (one text) and, for a per-language label, data-veroxm-labels. */
479
+ export function labelAttributes(label) {
480
+ if (!label || typeof label === 'string')
481
+ return { 'data-veroxm-label': label ?? '' };
482
+ const one = label.en ?? Object.values(label).find((v) => typeof v === 'string' && v !== '') ?? '';
483
+ return { 'data-veroxm-label': one, 'data-veroxm-labels': JSON.stringify(label) };
484
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veroxm/react-sdk",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "React and Next.js SDK for VeroXM: content hooks, visual slots with A/B tests, the on-page editor, forms and product journeys, llms.txt and structured data.",
5
5
  "keywords": [
6
6
  "veroxm",