@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.
@@ -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.9.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",