@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.11.0
4
+
5
+ - The on-page editor in Arabic. Every word of the editor (the editing bar, the panel, buttons, messages, errors, empty
6
+ states and screen-reader labels) comes from one table, `src/editor/i18n.ts`, in English and Arabic, with
7
+ placeholders and Arabic's six plural forms (`Intl.PluralRules`). The dashboard's slot editor reads the same table.
8
+ - The interface language is the editor's saved choice (a switch in the bar: English / العربية, kept in VeroXM for
9
+ the user, with a `localStorage` copy), else the page's language (the slot's `data-veroxm-locale`, then
10
+ `<html lang>`), else English. It never changes the content language being edited. In Arabic the bar and the panel
11
+ have `dir="rtl"` and `lang="ar"`, and the layout mirrors (the panel, its close button, arrows, the order of move
12
+ buttons).
13
+ - Digits: Latin (0123) by default in the Arabic interface, or Arabic-Indic (٠١٢٣), chosen in the bar
14
+ (`Intl.NumberFormat`).
15
+ - Labels per language: `label` on `<VeroxmSlot>`, every `field.*()`, `field.list()` and `defineComponent()` takes a
16
+ string or `{ en, ar, … }` (`Label`, `LabelMap`, exported from `@veroxm/react-sdk/next` and the package root). The
17
+ panel shows the interface language's label, else English, else the first given. A plain string works as before.
18
+ - `field.select(values, { options: { motor: { en: 'Motor', ar: 'المركبات' } } })`: display labels per option; the
19
+ stored values don't change.
20
+ - `field.list(fields, { titleField: 'label' })`: the field a collapsed item shows. Without it, the first required
21
+ text field, then the first text field.
22
+ - Right to left: counters are one message (`4 من 6 عناصر`, `25 / 80` kept left to right), slot keys, versions and
23
+ other mixed-direction text are isolated (`<bdi>`), and text inputs use `dir="auto"`.
24
+ - **Import into Media** also for images inside list items (an award's logo), slides and components: each item finds
25
+ the page's own item by a matching text field (so reordering keeps the right image), else by position.
26
+ - The route handler relays `PUT preferences` (the editor's interface language and digits). Label maps, option labels
27
+ and the language preference need a VeroXM server with this release's API.
28
+
29
+ ## 1.10.0
30
+
31
+ - A language with nothing saved yet (VeroXM answers the default language's published copy) starts from the page's own
32
+ fallback for that language wherever it has one; the default language fills only the rest, and the panel names the
33
+ source of each field.
34
+ - "Fill empty fields from the page": a button in the panel when a field is empty and the page's fallback has content
35
+ for it, for published slots too. It runs only when clicked (a list emptied on purpose stays empty), and nothing is
36
+ saved until the next edit, publish or close.
37
+ - Saving sends the changed fields from the form and every other field exactly as stored, so a field nobody touched is
38
+ never saved as empty.
39
+ - Media fields show an image the page takes from the site's own files ("Shown from the site's code"), with
40
+ **Import into Media** for users who can manage media: the editor reads the image from the site and adds it to the
41
+ media library, then the field holds its `{ id }`. A fallback image with `id: 0` is not treated as a library item.
42
+ The route handler relays `POST media` (needs a VeroXM server with the editor's media import).
43
+ - Typing on the page into a field with nothing stored starts from the text the page shows; Enter (or leaving) with
44
+ nothing changed is a cancel.
45
+
3
46
  ## 1.9.0
4
47
 
5
48
  - The on-page editor starts a slot that was never published from what the page shows: its empty fields (empty text,
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- import { field, type SlotFallback, type SlotFieldDefs, type SlotInfo, type SlotValues } from './slots-core.js';
2
+ import { field, type Label, type SlotFallback, type SlotFieldDefs, type SlotInfo, type SlotValues } from './slots-core.js';
3
3
  export { field };
4
4
  export type { SlotFieldDefs, SlotValues, SlotInfo };
5
5
  /** True while this browser is in an "Edit on page" session. */
@@ -11,7 +11,7 @@ export declare function configureClientSlots(options: {
11
11
  export interface ClientSlotOptions<F extends SlotFieldDefs> {
12
12
  fields: F;
13
13
  fallback?: SlotFallback<F>;
14
- label?: string;
14
+ label?: Label;
15
15
  locale?: string;
16
16
  }
17
17
  export interface ClientSlotState<F extends SlotFieldDefs> {
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
4
- import { fallbackValues, field, mergeSlotValues } from './slots-core.js';
4
+ import { fallbackValues, field, labelAttributes, mergeSlotValues } from './slots-core.js';
5
5
  import { EDITING_FLAG_COOKIE, PREVIEW_COOKIE, ROUTE_BASE } from './editor/constants.js';
6
6
  import { VeroxmEditorOverlay, resetSentFallbacksForTests } from './editor/overlay.js';
7
7
  import { useSlotImpression } from './tracking.js';
@@ -160,7 +160,7 @@ export function VeroxmSlot({ name, children, ...options }) {
160
160
  useSlotImpression(editing || loading ? null : name, slot.test);
161
161
  if (!editing)
162
162
  return children(values, slot);
163
- return (_jsxs(_Fragment, { children: [_jsx("div", { "data-veroxm-slot": name, "data-veroxm-label": options.label ?? '', "data-veroxm-locale": options.locale ?? '', "data-veroxm-shown": JSON.stringify(values), "data-veroxm-fallback": JSON.stringify(fallbackValues(options.fields, options.fallback)), style: { display: 'contents' }, children: children(values, slot) }), _jsx(VeroxmEditorOverlay, { onChange: bump })] }));
163
+ return (_jsxs(_Fragment, { children: [_jsx("div", { "data-veroxm-slot": name, ...labelAttributes(options.label), "data-veroxm-locale": options.locale ?? '', "data-veroxm-shown": JSON.stringify(values), "data-veroxm-fallback": JSON.stringify(fallbackValues(options.fields, options.fallback)), style: { display: 'contents' }, children: children(values, slot) }), _jsx(VeroxmEditorOverlay, { onChange: bump })] }));
164
164
  }
165
165
  /** Test helper. */
166
166
  export function resetClientSlotsForTests() {
@@ -218,6 +218,10 @@ export function createEditorHandler(hooks = {}) {
218
218
  if (method === 'PUT' && action === 'slots' && name && verb === 'variants' && /^\d{1,2}$/.test(rest[0] ?? '') && rest.length === 1) {
219
219
  return relay(request, `slots/${encodeURIComponent(name)}/variants/${rest[0]}`, 'PUT');
220
220
  }
221
+ if (method === 'POST' && action === 'media' && !name)
222
+ return relay(request, 'media', 'POST');
223
+ if (method === 'PUT' && action === 'preferences' && !name)
224
+ return relay(request, 'preferences', 'PUT');
221
225
  if (method === 'POST' && action === 'slots' && name && POST_VERBS.has(verb) && !rest.length) {
222
226
  return relay(request, `slots/${encodeURIComponent(name)}/${verb}`, 'POST');
223
227
  }
@@ -0,0 +1,255 @@
1
+ export type EditorLang = 'en' | 'ar';
2
+ export type EditorDigits = 'latn' | 'arab';
3
+ export declare const EDITOR_LANGS: readonly EditorLang[];
4
+ /** How each interface language names itself (the switch in the editing bar). */
5
+ export declare const LANG_NAMES: Record<EditorLang, string>;
6
+ type PluralForms = {
7
+ by?: string;
8
+ zero?: string;
9
+ one?: string;
10
+ two?: string;
11
+ few?: string;
12
+ many?: string;
13
+ other: string;
14
+ };
15
+ type Message = string | PluralForms;
16
+ declare const en: {
17
+ 'bar.aria': string;
18
+ 'bar.editing': string;
19
+ 'bar.ended': string;
20
+ 'bar.clickOn': string;
21
+ 'bar.clickOff': string;
22
+ 'bar.slots': string;
23
+ 'bar.exit': string;
24
+ 'bar.language': string;
25
+ 'bar.digits': string;
26
+ 'bar.digitsLatn': string;
27
+ 'bar.digitsArab': string;
28
+ 'list.empty': string;
29
+ 'inline.keys': string;
30
+ 'inline.aria': string;
31
+ 'error.unreachable': string;
32
+ 'error.http': string;
33
+ 'error.save': string;
34
+ 'error.generic': string;
35
+ 'error.discard': string;
36
+ 'error.unknownSlot': string;
37
+ 'panel.close': string;
38
+ 'panel.live': string;
39
+ 'panel.neverPublished': string;
40
+ 'panel.loading': string;
41
+ 'panel.inherited': string;
42
+ 'seed.filled': string;
43
+ 'seed.inheritedSplit': string;
44
+ 'seed.inheritedAll': string;
45
+ 'fill.offer': string;
46
+ 'fill.button': string;
47
+ 'fill.done': string;
48
+ 'list.separator': string;
49
+ 'status.savingVariant': string;
50
+ 'status.savingDraft': string;
51
+ 'status.variantSaved': string;
52
+ 'status.draftSaved': string;
53
+ 'status.editing': string;
54
+ 'status.unpublished': string;
55
+ 'status.clean': string;
56
+ 'notice.discarded': string;
57
+ 'outcome.published': string;
58
+ 'outcome.submitted': string;
59
+ 'outcome.approved': string;
60
+ 'outcome.rejected': string;
61
+ 'outcome.withdrawn': string;
62
+ 'publish.button': string;
63
+ 'publish.busy': string;
64
+ 'publish.send': string;
65
+ 'publish.sending': string;
66
+ 'publish.noPermission': string;
67
+ 'discard.button': string;
68
+ 'discard.confirm': string;
69
+ 'discard.busy': string;
70
+ 'approval.aria': string;
71
+ 'approval.waiting': string;
72
+ 'approval.step': string;
73
+ 'approval.sentBy': string;
74
+ 'approval.changed': string;
75
+ 'approval.comment': string;
76
+ 'approval.approve': string;
77
+ 'approval.approvePublish': string;
78
+ 'approval.approving': string;
79
+ 'approval.reject': string;
80
+ 'approval.rejecting': string;
81
+ 'approval.other': string;
82
+ 'approval.withdraw': string;
83
+ 'approval.withdrawing': string;
84
+ 'test.draft': string;
85
+ 'test.pending_approval': string;
86
+ 'test.live': string;
87
+ 'test.paused': string;
88
+ 'test.generic': string;
89
+ 'test.versions': string;
90
+ 'test.published': string;
91
+ 'test.editable': string;
92
+ 'test.noPermission': string;
93
+ 'test.locked': string;
94
+ 'test.settings': string;
95
+ 'test.back': string;
96
+ 'text.count': string;
97
+ 'common.remove': string;
98
+ 'common.removeItem': string;
99
+ 'common.moveEarlier': string;
100
+ 'common.moveLater': string;
101
+ 'common.title': string;
102
+ 'common.text': string;
103
+ 'common.address': string;
104
+ 'common.name': string;
105
+ 'common.pagePlaceholder': string;
106
+ 'common.pagePlaceholderShort': string;
107
+ 'link.text': string;
108
+ 'link.address': string;
109
+ 'component.label': string;
110
+ 'component.choose': string;
111
+ 'component.none': string;
112
+ 'video.url': string;
113
+ 'video.empty': string;
114
+ 'video.recognised': string;
115
+ 'video.file': string;
116
+ 'video.bad': string;
117
+ 'chart.kind': string;
118
+ 'chart.kind.bar': string;
119
+ 'chart.kind.hbar': string;
120
+ 'chart.kind.line': string;
121
+ 'chart.kind.area': string;
122
+ 'chart.kind.pie': string;
123
+ 'chart.kind.donut': string;
124
+ 'chart.kind.kpi': string;
125
+ 'chart.sample': string;
126
+ 'chart.numbers': string;
127
+ 'chart.firstRow': string;
128
+ 'chart.fromAnalytics': string;
129
+ 'chart.fromContent': string;
130
+ 'chart.fromApi': string;
131
+ 'chart.prefix': string;
132
+ 'chart.prefixPlaceholder': string;
133
+ 'chart.suffix': string;
134
+ 'chart.suffixPlaceholder': string;
135
+ 'chart.caption': string;
136
+ 'map.count': {
137
+ by: string;
138
+ one: string;
139
+ other: string;
140
+ };
141
+ 'map.placeN': string;
142
+ 'map.find': string;
143
+ 'map.finding': string;
144
+ 'map.matches': string;
145
+ 'map.attribution': string;
146
+ 'map.position': string;
147
+ 'map.placed': string;
148
+ 'map.notPlaced': string;
149
+ 'map.nothingFound': string;
150
+ 'map.searchFailed': string;
151
+ 'map.add': string;
152
+ 'slides.count': {
153
+ by: string;
154
+ one: string;
155
+ other: string;
156
+ };
157
+ 'slides.slideN': string;
158
+ 'slides.image': string;
159
+ 'slides.buttonText': string;
160
+ 'slides.buttonTextOf': string;
161
+ 'slides.buttonLinkOf': string;
162
+ 'slides.add': string;
163
+ 'list.count': {
164
+ by: string;
165
+ one: string;
166
+ other: string;
167
+ };
168
+ 'list.itemN': string;
169
+ 'list.showsFrom': string;
170
+ 'list.until': string;
171
+ 'list.add': string;
172
+ 'media.fromCode': string;
173
+ 'media.fromCodeImport': string;
174
+ 'media.import': string;
175
+ 'media.importing': string;
176
+ 'media.notImage': string;
177
+ 'media.importFailed': string;
178
+ 'media.none': string;
179
+ 'media.choose': string;
180
+ 'media.replace': string;
181
+ 'media.closeLibrary': string;
182
+ 'media.search': string;
183
+ 'media.noneFound': string;
184
+ 'media.loadFailed': string;
185
+ 'menu.itemN': string;
186
+ 'menu.label': string;
187
+ 'menu.labelOf': string;
188
+ 'menu.linkOptional': string;
189
+ 'menu.linkOf': string;
190
+ 'menu.iconOf': string;
191
+ 'menu.noIcon': string;
192
+ 'menu.badge': string;
193
+ 'menu.badgeOf': string;
194
+ 'menu.description': string;
195
+ 'menu.descriptionOf': string;
196
+ 'menu.newTab': string;
197
+ 'menu.up': string;
198
+ 'menu.down': string;
199
+ 'menu.outdent': string;
200
+ 'menu.indent': string;
201
+ 'menu.addSub': string;
202
+ 'menu.sub': string;
203
+ 'menu.removeWithSubs': string;
204
+ 'menu.oneLevel': string;
205
+ 'menu.levels': string;
206
+ 'menu.empty': string;
207
+ 'rte.toolbar': string;
208
+ 'rte.bold': string;
209
+ 'rte.italic': string;
210
+ 'rte.heading': string;
211
+ 'rte.subheading': string;
212
+ 'rte.bullets': string;
213
+ 'rte.bulletsShort': string;
214
+ 'rte.numbered': string;
215
+ 'rte.numberedShort': string;
216
+ 'rte.link': string;
217
+ 'rte.linkShort': string;
218
+ 'rte.clear': string;
219
+ 'rte.clearShort': string;
220
+ 'rte.linkAddress': string;
221
+ 'rte.apply': string;
222
+ 'rte.badLink': string;
223
+ 'rte.count': string;
224
+ };
225
+ export type EditorMessageKey = keyof typeof en;
226
+ export declare const EDITOR_MESSAGES: Record<EditorLang, Partial<Record<EditorMessageKey, Message>>>;
227
+ export type MessageVars = Record<string, string | number | null | undefined>;
228
+ export interface EditorTranslator {
229
+ lang: EditorLang;
230
+ dir: 'ltr' | 'rtl';
231
+ digits: EditorDigits;
232
+ /** A message with its {placeholders} filled; numbers in the interface's digits. */
233
+ t(key: EditorMessageKey, vars?: MessageVars): string;
234
+ /** A number in the interface's digits. */
235
+ num(n: number): string;
236
+ /** Names joined the way the language lists them ("Tabs, Question" / "التبويبات، السؤال"). */
237
+ list(items: readonly string[]): string;
238
+ }
239
+ export declare function createTranslator(lang: EditorLang, options?: {
240
+ digits?: EditorDigits;
241
+ }): EditorTranslator;
242
+ /** 'ar', 'ar-SA', 'AR' -> 'ar'; anything the editor isn't written in -> null. */
243
+ export declare function editorLang(value: string | null | undefined): EditorLang | null;
244
+ /** A label the site gives a slot, a field or an option: one text, or one per language. */
245
+ export type LabelMap = {
246
+ en?: string;
247
+ [locale: string]: string | undefined;
248
+ };
249
+ export type Label = string | LabelMap;
250
+ /**
251
+ * The label to show in `lang`: that language's, else English, else the first one given. A plain string is the
252
+ * same in every language. `labels` (what VeroXM stored from the site) wins over `label` (its one-text form).
253
+ */
254
+ export declare function pickLabel(lang: string, label: Label | null | undefined, labels?: LabelMap | null): string | undefined;
255
+ export {};