@opencloudcms/schema 0.0.0-stage → 0.1.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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -2
  3. package/dist/__typecheck__/define-messages.d.ts +20 -0
  4. package/dist/__typecheck__/define-messages.js +16 -0
  5. package/dist/__typecheck__/define-messages.js.map +1 -0
  6. package/dist/actions.d.ts +86 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.js.map +1 -0
  9. package/dist/composed-block.d.ts +205 -0
  10. package/dist/composed-block.js +897 -0
  11. package/dist/composed-block.js.map +1 -0
  12. package/dist/config.d.ts +3 -0
  13. package/dist/config.js +57 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/define.d.ts +31 -0
  16. package/dist/define.js +113 -0
  17. package/dist/define.js.map +1 -0
  18. package/dist/form-controls.d.ts +18 -0
  19. package/dist/form-controls.js +52 -0
  20. package/dist/form-controls.js.map +1 -0
  21. package/dist/groups.d.ts +12 -0
  22. package/dist/groups.js +55 -0
  23. package/dist/groups.js.map +1 -0
  24. package/dist/i18n.d.ts +43 -0
  25. package/dist/i18n.js +93 -0
  26. package/dist/i18n.js.map +1 -0
  27. package/dist/icons.d.ts +3 -0
  28. package/dist/icons.js +28 -0
  29. package/dist/icons.js.map +1 -0
  30. package/dist/index.d.ts +20 -0
  31. package/dist/index.js +51 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/locales.d.ts +11 -0
  34. package/dist/locales.js +38 -0
  35. package/dist/locales.js.map +1 -0
  36. package/dist/pages.d.ts +78 -0
  37. package/dist/pages.js +139 -0
  38. package/dist/pages.js.map +1 -0
  39. package/dist/permissions.d.ts +7 -0
  40. package/dist/permissions.js +29 -0
  41. package/dist/permissions.js.map +1 -0
  42. package/dist/physical.d.ts +72 -0
  43. package/dist/physical.js +195 -0
  44. package/dist/physical.js.map +1 -0
  45. package/dist/search.d.ts +5 -0
  46. package/dist/search.js +15 -0
  47. package/dist/search.js.map +1 -0
  48. package/dist/slug.d.ts +65 -0
  49. package/dist/slug.js +238 -0
  50. package/dist/slug.js.map +1 -0
  51. package/dist/style.d.ts +71 -0
  52. package/dist/style.js +211 -0
  53. package/dist/style.js.map +1 -0
  54. package/dist/theme.d.ts +15 -0
  55. package/dist/theme.js +64 -0
  56. package/dist/theme.js.map +1 -0
  57. package/dist/types.d.ts +140 -0
  58. package/dist/types.js +9 -0
  59. package/dist/types.js.map +1 -0
  60. package/dist/validate.d.ts +11 -0
  61. package/dist/validate.js +191 -0
  62. package/dist/validate.js.map +1 -0
  63. package/dist/validator.d.ts +25 -0
  64. package/dist/validator.js +80 -0
  65. package/dist/validator.js.map +1 -0
  66. package/package.json +30 -3
@@ -0,0 +1,897 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIST_LAYOUT_SUFFIX = exports.COLLECTION_LIST_DEFAULT_LIMIT = exports.COLLECTION_LIST_MAX_LIMIT = exports.MAX_COLLECTION_LISTS = exports.COLLECTION_LIST_KEY_RE = exports.COMPOSED_GENERATED_FIELD_RE = exports.COMPOSED_RESERVED_PROPS = exports.RESERVED_BLOCK_PROPS = exports.BLOCK_FIELD_KEY_RE = exports.COMPOSED_FIELD_KINDS = exports.TOOLTIP_TEXT_MAX = exports.CLICKABLE_ELEMENTS = exports.INTERACTIVE_ELEMENTS = exports.INTERACTIVE_CONTAINERS = exports.ELEMENT_BINDABLE = exports.COMPOSED_ELEMENTS = exports.FORM_CONTROL_ELEMENTS = void 0;
4
+ exports.composedFieldNameIssue = composedFieldNameIssue;
5
+ exports.isClickable = isClickable;
6
+ exports.isReservedListKey = isReservedListKey;
7
+ exports.composedDetailLinks = composedDetailLinks;
8
+ exports.validateComposedSpec = validateComposedSpec;
9
+ exports.composedManifestEntry = composedManifestEntry;
10
+ exports.kebabName = kebabName;
11
+ exports.overlayDefaultName = overlayDefaultName;
12
+ exports.slotSignature = slotSignature;
13
+ exports.slotsChanged = slotsChanged;
14
+ exports.composedKind = composedKind;
15
+ exports.regionNames = regionNames;
16
+ exports.collectionListsOf = collectionListsOf;
17
+ exports.isBreakingChange = isBreakingChange;
18
+ exports.withAutoVersion = withAutoVersion;
19
+ // Pure spec types, validation and versioning for composed (builder-made) page blocks.
20
+ // Must not import from `node:*` (bundled for the browser and shared with Nest and the blocks package).
21
+ const actions_1 = require("./actions");
22
+ const form_controls_1 = require("./form-controls");
23
+ const groups_1 = require("./groups");
24
+ const icons_1 = require("./icons");
25
+ const style_1 = require("./style");
26
+ exports.FORM_CONTROL_ELEMENTS = ['Input', 'Textarea', 'Select', 'Combobox', 'Radio', 'Checkbox', 'Switch'];
27
+ exports.COMPOSED_ELEMENTS = [
28
+ 'Box', 'Stack', 'Columns', 'Grid', 'Card', 'Slot', 'Heading', 'Text',
29
+ 'Image', 'Button', 'Badge', 'Price', 'Date', 'Divider', 'Spacer', 'Region', 'PageContent', 'Overlay',
30
+ 'Dropdown', 'Tooltip', 'Accordion', 'AccordionItem', 'Tabs', 'TabPanel', 'Carousel', 'Icon',
31
+ 'CollectionList', 'Form', ...exports.FORM_CONTROL_ELEMENTS,
32
+ ];
33
+ /** Props of each element that may be bound to data (everything else takes design tokens only). */
34
+ exports.ELEMENT_BINDABLE = {
35
+ Stack: [], Columns: [], Grid: [], Slot: [], Divider: [], Spacer: [], Region: [], PageContent: [], Overlay: [],
36
+ Accordion: [], Tabs: [], Carousel: [], CollectionList: [], Form: [],
37
+ Box: ['href'],
38
+ Card: ['href'],
39
+ Heading: ['text'],
40
+ Text: ['text', 'html'],
41
+ Image: ['src', 'alt', 'href'],
42
+ Button: ['label', 'href'],
43
+ Badge: ['text'],
44
+ Price: ['value'],
45
+ Date: ['value'],
46
+ Dropdown: ['label', 'href'],
47
+ Tooltip: ['text'],
48
+ AccordionItem: ['title'],
49
+ TabPanel: ['label'],
50
+ Icon: ['label'],
51
+ Input: ['label', 'placeholder', 'help'],
52
+ Textarea: ['label', 'placeholder', 'help'],
53
+ Select: ['label', 'placeholder', 'help'],
54
+ Combobox: ['label', 'placeholder', 'help'],
55
+ Radio: ['label', 'help'],
56
+ Checkbox: ['label', 'help'],
57
+ Switch: ['label', 'help'],
58
+ };
59
+ /** Interactive containers: not the root of an overlay frame. */
60
+ exports.INTERACTIVE_CONTAINERS = ['Dropdown', 'Tooltip', 'Accordion', 'Tabs', 'Carousel'];
61
+ /** Elements that render interactive content (not allowed inside a clickable Box/Card, at any depth). */
62
+ exports.INTERACTIVE_ELEMENTS = ['Button', ...exports.INTERACTIVE_CONTAINERS, 'Slot', ...exports.FORM_CONTROL_ELEMENTS];
63
+ /** Elements that become a link or button with a bound `href` or a valid `action`. */
64
+ exports.CLICKABLE_ELEMENTS = ['Image', 'Box', 'Card'];
65
+ /** Max length of a Tooltip `text` bound to a constant. */
66
+ exports.TOOLTIP_TEXT_MAX = 200;
67
+ exports.COMPOSED_FIELD_KINDS = ['text', 'longText', 'richText', 'number', 'boolean', 'select', 'image', 'link'];
68
+ const ID_RE = /^blk_[a-z0-9]{6,}$/;
69
+ /** Block field names `defineBlocks` accepts. */
70
+ exports.BLOCK_FIELD_KEY_RE = /^[A-Za-z][A-Za-z0-9]*$/;
71
+ /** Prop names used by core or Puck on every block item (`defineBlocks` rejects them as field names). */
72
+ exports.RESERVED_BLOCK_PROPS = ['id', '_v', 'puck', 'editMode'];
73
+ /** Reserved props stamped on composed (and `usesLocale`) block items. */
74
+ exports.COMPOSED_RESERVED_PROPS = ['_locale', '_editor'];
75
+ /**
76
+ * Field names `defineComposedBlock` may generate (`entry`, `entries`, `layout`, `slot`, `slot2`, …). Manual fields
77
+ * never use them, whatever the binding and tree, so a later binding or Slot cannot clash with stored content.
78
+ */
79
+ exports.COMPOSED_GENERATED_FIELD_RE = /^(entry|entries|layout|slot\d*)$/;
80
+ // CollectionList keys (`list`, `list2`, … by default) are generated field names too, but only reserved against the
81
+ // keys a spec actually has: a clash is reported on the list's `props.key`, never on a manual field (older specs may
82
+ // have a manual field named `list`).
83
+ /** `key` of a `CollectionList` (its generated block field name). */
84
+ exports.COLLECTION_LIST_KEY_RE = /^[a-z][a-zA-Z0-9]{0,31}$/;
85
+ /** Max `CollectionList`s per block. */
86
+ exports.MAX_COLLECTION_LISTS = 4;
87
+ /** Max `limit` of a `CollectionList`. */
88
+ exports.COLLECTION_LIST_MAX_LIMIT = 50;
89
+ /** Default `limit` of a `CollectionList`. */
90
+ exports.COLLECTION_LIST_DEFAULT_LIMIT = 12;
91
+ /** Why `name` cannot be a manual field of a composed block (null when it can). */
92
+ function composedFieldNameIssue(name) {
93
+ if (!exports.BLOCK_FIELD_KEY_RE.test(name))
94
+ return 'field name must start with a letter and use letters and digits only';
95
+ if (exports.RESERVED_BLOCK_PROPS.includes(name) || exports.COMPOSED_RESERVED_PROPS.includes(name))
96
+ return `"${name}" is reserved`;
97
+ if (exports.COMPOSED_GENERATED_FIELD_RE.test(name))
98
+ return `"${name}" is reserved for a generated field`;
99
+ if (name in Object.prototype)
100
+ return `"${name}" is reserved`;
101
+ return null;
102
+ }
103
+ const DEFAULT_CHECKS = {
104
+ text: (d) => typeof d === 'string',
105
+ longText: (d) => typeof d === 'string',
106
+ richText: (d) => typeof d === 'string',
107
+ number: (d) => typeof d === 'number' && Number.isFinite(d),
108
+ boolean: (d) => typeof d === 'boolean',
109
+ select: null, // checked against the options
110
+ image: (d) => d === null || (!!d && typeof d === 'object' && !Array.isArray(d)),
111
+ link: (d) => d === null || (!!d && typeof d === 'object' && !Array.isArray(d)),
112
+ };
113
+ const DEFAULT_EXPECTED = {
114
+ text: 'a string', longText: 'a string', richText: 'a string', number: 'a number', boolean: 'a boolean',
115
+ select: 'one of the options', image: 'an object or null', link: 'an object or null',
116
+ };
117
+ const NAME_RE = /^[A-Z][A-Za-z0-9]{0,63}$/;
118
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
119
+ const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
120
+ const enumLeaf = (allowed, add) => (v, p) => {
121
+ if (typeof v !== 'string' || !allowed.includes(v))
122
+ add(p, `must be one of ${allowed.join(', ')}`);
123
+ };
124
+ /** Checks the layout props Columns, Stack and Image accept; other props stay unchecked. */
125
+ function checkLayoutProps(el, props, path, add) {
126
+ const at = (k) => [...path, k];
127
+ if (el === 'Columns') {
128
+ if (props.tracks !== undefined) {
129
+ (0, style_1.checkResponsive)(props.tracks, at('tracks'), (v, p) => {
130
+ if (!Array.isArray(v))
131
+ return add(p, 'tracks must be an array');
132
+ if (v.length < 1 || v.length > style_1.MAX_TRACKS)
133
+ add(p, `tracks must have 1 to ${style_1.MAX_TRACKS} entries`);
134
+ v.forEach((t, i) => { if (!(0, style_1.isTrack)(t))
135
+ add([...p, i], 'track must be <n>fr (1-12), auto or a length'); });
136
+ });
137
+ }
138
+ if (props.alignY !== undefined)
139
+ enumLeaf(['start', 'center', 'end', 'stretch'], add)(props.alignY, at('alignY'));
140
+ for (const k of ['gapX', 'gapY']) {
141
+ if (props[k] !== undefined && !(0, style_1.isLength)(props[k]))
142
+ add(at(k), 'must be a spacing token or a length like 12px');
143
+ }
144
+ }
145
+ else if (el === 'Stack') {
146
+ if (props.direction !== undefined)
147
+ (0, style_1.checkResponsive)(props.direction, at('direction'), enumLeaf(['vertical', 'horizontal'], add));
148
+ if (props.align !== undefined)
149
+ (0, style_1.checkResponsive)(props.align, at('align'), enumLeaf(['start', 'center', 'end', 'stretch'], add));
150
+ if (props.justify !== undefined)
151
+ enumLeaf(['start', 'center', 'end', 'between'], add)(props.justify, at('justify'));
152
+ if (props.wrap !== undefined && typeof props.wrap !== 'boolean')
153
+ add(at('wrap'), 'wrap must be a boolean');
154
+ }
155
+ else if (el === 'Overlay') {
156
+ if (props.variant !== undefined)
157
+ enumLeaf(['modal', 'drawer'], add)(props.variant, at('variant'));
158
+ if (props.side !== undefined) {
159
+ enumLeaf(['left', 'right', 'top', 'bottom'], add)(props.side, at('side'));
160
+ if (props.variant !== 'drawer')
161
+ add(at('side'), 'side is only allowed on a drawer');
162
+ }
163
+ if (props.size !== undefined)
164
+ enumLeaf(['sm', 'md', 'lg', 'xl', 'full'], add)(props.size, at('size'));
165
+ for (const k of ['closeOnBackdrop', 'showClose']) {
166
+ if (props[k] !== undefined && typeof props[k] !== 'boolean')
167
+ add(at(k), `${k} must be a boolean`);
168
+ }
169
+ if (props.labelledBy !== undefined && props.labelledBy !== 'first-heading')
170
+ add(at('labelledBy'), "labelledBy must be 'first-heading'");
171
+ }
172
+ else if (el === 'Image') {
173
+ if (props.fit !== undefined)
174
+ enumLeaf(['cover', 'contain'], add)(props.fit, at('fit'));
175
+ if (props.aspect !== undefined)
176
+ (0, style_1.checkResponsive)(props.aspect, at('aspect'), enumLeaf(['auto', 'square', 'video', '3/2', '4/3', 'wide'], add));
177
+ }
178
+ }
179
+ const oneOf = (allowed) => (v, p, add) => enumLeaf(allowed, add)(v, p);
180
+ const bool = (v, p, add) => { if (typeof v !== 'boolean')
181
+ add(p, 'must be a boolean'); };
182
+ const intIn = (min, max) => (v, p, add) => {
183
+ if (!Number.isInteger(v) || v < min || v > max)
184
+ add(p, `must be an integer between ${min} and ${max}`);
185
+ };
186
+ const responsive = (leaf) => (v, p, add) => (0, style_1.checkResponsive)(v, p, (x, q) => leaf(x, q, add));
187
+ const controlName = (v, p, add) => {
188
+ if (typeof v !== 'string' || !form_controls_1.FORM_CONTROL_NAME_RE.test(v))
189
+ add(p, 'name must match ^[A-Za-z][A-Za-z0-9_-]{0,63}$');
190
+ };
191
+ const iconName = (v, p, add) => { if (!(0, icons_1.isIconName)(v))
192
+ add(p, 'must be one of the icon names'); };
193
+ const plainText = (v, p, add) => { if (typeof v !== 'string')
194
+ add(p, 'must be a string'); };
195
+ const options = (v, p, add) => { for (const i of (0, form_controls_1.validateOptions)(v, p))
196
+ add(i.path, i.message); };
197
+ const autoplay = (v, p, add) => {
198
+ if (v !== 'off' && !(Number.isInteger(v) && v >= 3 && v <= 10))
199
+ add(p, "autoplay must be 'off' or 3 to 10 seconds");
200
+ };
201
+ const checkboxValue = (v, p, add) => {
202
+ if (typeof v !== 'string' || !v || v.length > form_controls_1.MAX_OPTION_VALUE)
203
+ add(p, `value must be a non-empty string of at most ${form_controls_1.MAX_OPTION_VALUE} characters`);
204
+ };
205
+ /** Checks a query `filter` (block binding and CollectionList). */
206
+ const filterCheck = (v, p, add) => {
207
+ if (!Array.isArray(v))
208
+ return add(p, 'filter must be an array');
209
+ v.forEach((f, i) => {
210
+ if (!isObj(f) || typeof f.field !== 'string' || !f.field)
211
+ add([...p, i, 'field'], 'filter field is required');
212
+ else if (!('value' in f))
213
+ add([...p, i, 'value'], 'filter value is required');
214
+ else if (!['string', 'number', 'boolean'].includes(typeof f.value) || (typeof f.value === 'number' && !Number.isFinite(f.value))) {
215
+ add([...p, i, 'value'], 'filter value must be a string, number or boolean');
216
+ }
217
+ });
218
+ };
219
+ const sortCheck = (v, p, add) => {
220
+ if (!isObj(v) || typeof v.field !== 'string' || !v.field)
221
+ add([...p, 'field'], 'sort field is required');
222
+ else if (v.field.includes(':'))
223
+ add([...p, 'field'], 'sort field must not contain ":"');
224
+ else if (v.direction !== 'asc' && v.direction !== 'desc')
225
+ add([...p, 'direction'], "direction must be 'asc' or 'desc'");
226
+ };
227
+ const layoutCheck = (v, p, add) => {
228
+ if (!isObj(v) || !['grid', 'list', 'carousel'].includes(v.kind))
229
+ return add([...p, 'kind'], "layout kind must be 'grid', 'list' or 'carousel'");
230
+ const min = v.kind === 'carousel' ? 1 : 2;
231
+ if (v.columns !== undefined && (!Number.isInteger(v.columns) || v.columns < min || v.columns > 6)) {
232
+ add([...p, 'columns'], `columns must be an integer between ${min} and 6`);
233
+ }
234
+ };
235
+ const urlPatternCheck = (v, p, add) => { if (typeof v !== 'string' || !v)
236
+ add(p, 'urlPattern must be a non-empty string'); };
237
+ const emptyTextCheck = (v, p, add) => {
238
+ if (!isObj(v) || typeof v['en-US'] !== 'string')
239
+ add([...p, 'en-US'], 'emptyText requires an en-US text');
240
+ };
241
+ const LIST_EDITOR_KEYS = ['filter', 'sort', 'limit', 'layout'];
242
+ const listEditorCheck = (v, p, add) => {
243
+ if (!isObj(v))
244
+ return add(p, 'editor must be an object');
245
+ for (const [k, x] of Object.entries(v)) {
246
+ if (!LIST_EDITOR_KEYS.includes(k))
247
+ add([...p, k], `editor has no option "${k}"`);
248
+ else if (x !== undefined && typeof x !== 'boolean')
249
+ add([...p, k], `${k} must be a boolean`);
250
+ }
251
+ };
252
+ const listKeyCheck = (v, p, add) => {
253
+ if (typeof v !== 'string' || !exports.COLLECTION_LIST_KEY_RE.test(v))
254
+ add(p, 'key must match ^[a-z][a-zA-Z0-9]{0,31}$');
255
+ };
256
+ const apiIdCheck = (v, p, add) => { if (typeof v !== 'string' || !v)
257
+ add(p, 'apiId is required'); };
258
+ /** Same list as `ButtonVariant` in `@opencloudcms/blocks`. */
259
+ const BUTTON_VARIANTS = ['default', 'secondary', 'outline', 'ghost', 'link'];
260
+ const CONTROL = { name: controlName, required: bool, disabled: bool };
261
+ const CHOICE = { ...CONTROL, options, defaultValue: plainText };
262
+ /**
263
+ * Props of the new elements (strict: any other prop is an issue, except `anchorId` and `action`, which are checked
264
+ * on every element).
265
+ */
266
+ const COMPONENT_PROPS = {
267
+ Dropdown: {
268
+ openOn: oneOf(['hover', 'click']), placement: oneOf(['bottom-start', 'bottom-end', 'bottom']),
269
+ display: responsive(oneOf(['popover', 'inline'])), triggerVariant: oneOf(BUTTON_VARIANTS), chevron: bool,
270
+ },
271
+ Tooltip: { side: oneOf(['top', 'bottom', 'left', 'right']) },
272
+ Accordion: { single: bool, defaultOpen: oneOf(['none', 'first']) },
273
+ AccordionItem: {},
274
+ Tabs: { variant: oneOf(['underline', 'pills']), align: oneOf(['start', 'center', 'stretch']) },
275
+ TabPanel: {},
276
+ Carousel: {
277
+ perView: responsive(intIn(1, 6)), gap: oneOf(style_1.STYLE_SPACING_TOKENS), arrows: bool, dots: bool, loop: bool, autoplay,
278
+ },
279
+ Icon: { name: iconName, size: oneOf(['sm', 'md', 'lg', 'xl']) },
280
+ CollectionList: {
281
+ key: listKeyCheck, apiId: apiIdCheck, filter: filterCheck, sort: sortCheck, limit: intIn(1, exports.COLLECTION_LIST_MAX_LIMIT),
282
+ layout: layoutCheck, emptyText: emptyTextCheck, urlPattern: urlPatternCheck, editor: listEditorCheck,
283
+ },
284
+ Form: { resetOnSuccess: bool },
285
+ Input: { ...CONTROL, type: oneOf(form_controls_1.INPUT_TYPES), autocomplete: oneOf(form_controls_1.AUTOCOMPLETE_TOKENS) },
286
+ Textarea: { ...CONTROL, rows: intIn(2, 12) },
287
+ Select: CHOICE,
288
+ Combobox: CHOICE,
289
+ Radio: { ...CHOICE, orientation: oneOf(['vertical', 'horizontal']) },
290
+ Checkbox: { ...CONTROL, value: checkboxValue, defaultChecked: bool },
291
+ Switch: { name: controlName, defaultChecked: bool, disabled: bool },
292
+ };
293
+ const REQUIRED_PROPS = {
294
+ Icon: ['name'], CollectionList: ['key', 'apiId'], Form: ['action'], Input: ['name'], Textarea: ['name'], Select: ['name', 'options'], Combobox: ['name', 'options'],
295
+ Radio: ['name', 'options'], Checkbox: ['name'], Switch: ['name'],
296
+ };
297
+ /** New props of existing elements (checked when present; other props stay unchecked). */
298
+ const EXTRA_PROPS = {
299
+ Button: { icon: iconName, iconPosition: oneOf(['start', 'end']), iconOnly: bool, submit: bool },
300
+ Box: { ariaLabel: plainText },
301
+ Card: { ariaLabel: plainText },
302
+ };
303
+ /** Elements that take no children. */
304
+ const LEAF_ELEMENTS = ['Icon', ...exports.FORM_CONTROL_ELEMENTS];
305
+ const CHILD_COUNTS = {
306
+ Accordion: [1, 30, 'items'], Tabs: [1, 12, 'panels'], Carousel: [1, 20, 'slides'], Tooltip: [1, 1, 'child'],
307
+ };
308
+ /** Elements whose `action` prop is a `ButtonAction`. */
309
+ const ACTION_ELEMENTS = ['Button', ...exports.CLICKABLE_ELEMENTS];
310
+ /** Checks the props of the new elements and the new props of Button, Box and Card. */
311
+ function checkComponentProps(el, props, path, add) {
312
+ const strict = COMPONENT_PROPS[el];
313
+ const checks = strict ?? EXTRA_PROPS[el];
314
+ if (!checks)
315
+ return;
316
+ for (const [k, v] of Object.entries(props)) {
317
+ if (v === undefined)
318
+ continue;
319
+ if (has(checks, k))
320
+ checks[k](v, [...path, k], add);
321
+ else if (strict && k !== 'anchorId' && k !== 'action')
322
+ add([...path, k], `${el} has no prop "${k}"`);
323
+ }
324
+ for (const k of REQUIRED_PROPS[el] ?? [])
325
+ if (props[k] === undefined)
326
+ add([...path, k], `${k} is required`);
327
+ if (has(props, 'defaultValue') && typeof props.defaultValue === 'string' && (0, form_controls_1.validateOptions)(props.options, []).length === 0
328
+ && !(0, form_controls_1.optionValues)(props.options).includes(props.defaultValue)) {
329
+ add([...path, 'defaultValue'], 'defaultValue must be one of the option values');
330
+ }
331
+ }
332
+ /** Image, Box or Card with a bound `href` or a valid `action` (renders as a link or button). */
333
+ function isClickable(node) {
334
+ if (!isObj(node) || !exports.CLICKABLE_ELEMENTS.includes(node.el))
335
+ return false;
336
+ if (isObj(node.bind) && node.bind.href !== undefined)
337
+ return true;
338
+ return isObj(node.props) && node.props.action !== undefined && (0, actions_1.validateButtonAction)(node.props.action, []).length === 0;
339
+ }
340
+ const childEl = (c) => (isObj(c) ? c.el : undefined);
341
+ const constText = (s) => (isObj(s) && s.from === 'const' && typeof s.value === 'string' ? s.value : undefined);
342
+ /** Key names a CollectionList may not take (besides manual field names and the other lists' keys). */
343
+ const RESERVED_LIST_KEY_RE = /^(entry|entries|layout|slot\d*|region)$/;
344
+ /**
345
+ * True when `key` is reserved for a CollectionList of a spec of `kind`: generated field names (`entry`, `entries`,
346
+ * `layout`, `slot…`, `region`), core block props, `Object.prototype` names, `name` in an overlay and `pageContent`
347
+ * in a layout. Manual field names and the other lists' keys are checked separately.
348
+ */
349
+ function isReservedListKey(key, kind = 'block') {
350
+ return RESERVED_LIST_KEY_RE.test(key) || exports.RESERVED_BLOCK_PROPS.includes(key) || key in Object.prototype
351
+ || (kind === 'overlay' && key === 'name') || (kind === 'layout' && key === 'pageContent');
352
+ }
353
+ /** Suffix of a CollectionList's generated editor layout field: `<key>__layout`. */
354
+ exports.LIST_LAYOUT_SUFFIX = '__layout';
355
+ /**
356
+ * apiIds whose detail path an `entryUrl` of the tree uses: inside a CollectionList without its own `urlPattern` the
357
+ * list's type; elsewhere the binding's type when the binding has no `urlPattern` (decisions 6, 9).
358
+ */
359
+ function composedDetailLinks(spec) {
360
+ const out = new Set();
361
+ const walk = (n, list) => {
362
+ const inList = n.el === 'CollectionList' ? n.props : list;
363
+ for (const s of Object.values(n.bind ?? {})) {
364
+ if (s.from !== 'entryUrl')
365
+ continue;
366
+ if (list) {
367
+ if (!list.urlPattern && list.apiId)
368
+ out.add(list.apiId);
369
+ }
370
+ else if (spec.binding && !spec.binding.urlPattern)
371
+ out.add(spec.binding.apiId);
372
+ }
373
+ for (const c of n.children ?? [])
374
+ walk(c, inList);
375
+ };
376
+ walk(spec.tree, undefined);
377
+ return [...out];
378
+ }
379
+ function validateComposedSpec(spec, opts = {}) {
380
+ const issues = [];
381
+ const add = (path, message) => issues.push({ path, message });
382
+ if (!isObj(spec))
383
+ return [{ path: [], message: 'Spec must be an object' }];
384
+ if (typeof spec.id !== 'string' || !ID_RE.test(spec.id))
385
+ add(['id'], 'id must match ^blk_[a-z0-9]{6,}$');
386
+ if (typeof spec.name !== 'string' || !NAME_RE.test(spec.name))
387
+ add(['name'], 'name must be PascalCase (^[A-Z][A-Za-z0-9]{0,63}$)');
388
+ if (!isObj(spec.label) || typeof spec.label['en-US'] !== 'string' || !spec.label['en-US'].trim()) {
389
+ add(['label', 'en-US'], 'label requires a non-empty en-US text');
390
+ }
391
+ else
392
+ for (const m of (0, groups_1.validateLocalizedText)(spec.label, 'label'))
393
+ add(['label'], m);
394
+ if (typeof spec.category !== 'string' || !spec.category.trim())
395
+ add(['category'], 'category is required');
396
+ if (spec.icon !== undefined && typeof spec.icon !== 'string')
397
+ add(['icon'], 'icon must be a string');
398
+ if (!Number.isInteger(spec.version) || spec.version < 1)
399
+ add(['version'], 'version must be an integer >= 1');
400
+ // binding
401
+ let binding;
402
+ if (spec.binding !== undefined) {
403
+ if (!isObj(spec.binding))
404
+ add(['binding'], 'binding must be an object');
405
+ else {
406
+ binding = spec.binding;
407
+ const b = binding;
408
+ if (typeof b.apiId !== 'string' || !b.apiId)
409
+ add(['binding', 'apiId'], 'apiId is required');
410
+ if (b.mode !== 'single' && b.mode !== 'collection')
411
+ add(['binding', 'mode'], "mode must be 'single' or 'collection'");
412
+ if (b.mode === 'single') {
413
+ for (const k of ['filter', 'sort', 'limit', 'layout'])
414
+ if (b[k] !== undefined)
415
+ add(['binding', k], `${k} is only allowed in collection mode`);
416
+ }
417
+ if (b.filter !== undefined)
418
+ filterCheck(b.filter, ['binding', 'filter'], add);
419
+ if (b.sort !== undefined)
420
+ sortCheck(b.sort, ['binding', 'sort'], add);
421
+ if (b.limit !== undefined && (!Number.isInteger(b.limit) || b.limit < 1 || b.limit > 100)) {
422
+ add(['binding', 'limit'], 'limit must be an integer between 1 and 100');
423
+ }
424
+ if (b.layout !== undefined)
425
+ layoutCheck(b.layout, ['binding', 'layout'], add);
426
+ if (b.urlPattern !== undefined)
427
+ urlPatternCheck(b.urlPattern, ['binding', 'urlPattern'], add);
428
+ if (b.options !== undefined) {
429
+ if (!isObj(b.options))
430
+ add(['binding', 'options'], 'options must be an object');
431
+ else {
432
+ const o = b.options;
433
+ for (const k of ['editorFilter', 'editorSort', 'editorLimit', 'editorLayout']) {
434
+ if (o[k] === undefined)
435
+ continue;
436
+ if (typeof o[k] !== 'boolean')
437
+ add(['binding', 'options', k], `${k} must be a boolean`);
438
+ else if (o[k] && b.mode !== 'collection')
439
+ add(['binding', 'options', k], `${k} is only allowed in collection mode`);
440
+ }
441
+ if (o.emptyText !== undefined)
442
+ emptyTextCheck(o.emptyText, ['binding', 'options', 'emptyText'], add);
443
+ }
444
+ }
445
+ }
446
+ }
447
+ // fields
448
+ const fieldNames = new Set();
449
+ if (!isObj(spec.fields))
450
+ add(['fields'], 'fields must be an object');
451
+ else {
452
+ for (const [name, f] of Object.entries(spec.fields)) {
453
+ fieldNames.add(name);
454
+ const nameIssue = composedFieldNameIssue(name);
455
+ if (nameIssue)
456
+ add(['fields', name], nameIssue);
457
+ if (!isObj(f) || !exports.COMPOSED_FIELD_KINDS.includes(f.kind)) {
458
+ add(['fields', name, 'kind'], `kind must be one of ${exports.COMPOSED_FIELD_KINDS.join(', ')}`);
459
+ continue;
460
+ }
461
+ if (f.label !== undefined && typeof f.label !== 'string') {
462
+ const m = (0, groups_1.validateLocalizedText)(f.label, 'label');
463
+ if (m.length)
464
+ add(['fields', name, 'label'], m.join('; '));
465
+ }
466
+ const kind = f.kind;
467
+ const check = DEFAULT_CHECKS[kind];
468
+ if (check && f.default !== undefined && !check(f.default))
469
+ add(['fields', name, 'default'], `default must be ${DEFAULT_EXPECTED[kind]}`);
470
+ if (f.kind === 'select') {
471
+ const o = f.options;
472
+ const ok = Array.isArray(o) && o.length > 0 && o.every((x) => typeof x === 'string' || typeof x === 'number') && new Set(o).size === o.length;
473
+ if (!ok)
474
+ add(['fields', name, 'options'], 'select requires a non-empty array of unique strings or numbers');
475
+ else if (f.default !== undefined && !o.includes(f.default))
476
+ add(['fields', name, 'default'], 'default must be one of the options');
477
+ }
478
+ else if (f.options !== undefined) {
479
+ add(['fields', name, 'options'], 'options are only allowed on select fields');
480
+ }
481
+ }
482
+ }
483
+ // layout and overlay blocks
484
+ const rootEl = isObj(spec.tree) ? spec.tree.el : undefined;
485
+ if (rootEl === 'Overlay' && spec.binding !== undefined)
486
+ add(['binding'], 'an overlay block cannot have a binding');
487
+ if (isObj(spec.fields)) {
488
+ const kind = composedKind(spec);
489
+ if (kind === 'overlay' && has(spec.fields, 'name'))
490
+ add(['fields', 'name'], '"name" is reserved for the overlay name field');
491
+ if (kind === 'layout' && has(spec.fields, 'pageContent'))
492
+ add(['fields', 'pageContent'], '"pageContent" is reserved for the page content slot');
493
+ }
494
+ // tree
495
+ const collection = binding?.mode === 'collection';
496
+ const hasBinding = binding !== undefined;
497
+ // Run actions: the current entry is the CollectionList item's, else the block binding's; missing required params are
498
+ // not a save error (they are reported where the action runs).
499
+ const actionCheck = (c) => {
500
+ const apiId = c.list ? c.list.apiId : binding?.apiId;
501
+ return { entry: { apiId: typeof apiId === 'string' && apiId ? apiId : null }, skipRequired: true };
502
+ };
503
+ const hasDetail = (apiId) => !opts.detailTypes || (typeof apiId === 'string' && opts.detailTypes.has(apiId));
504
+ const checkSource = (s, path, ctx) => {
505
+ if (!isObj(s))
506
+ return add(path, 'bind source must be an object');
507
+ switch (s.from) {
508
+ case 'entry':
509
+ if (typeof s.path !== 'string' || !s.path)
510
+ add([...path, 'path'], 'entry path is required');
511
+ if (!hasBinding && !ctx.list)
512
+ add(path, "'entry' requires a binding");
513
+ break;
514
+ case 'entryUrl':
515
+ if (ctx.list) {
516
+ if ((typeof ctx.list.urlPattern !== 'string' || !ctx.list.urlPattern) && !hasDetail(ctx.list.apiId)) {
517
+ add(path, "'entryUrl' requires the CollectionList urlPattern or a content type with a detail page");
518
+ }
519
+ }
520
+ else if (!hasBinding)
521
+ add(path, "'entryUrl' requires a binding");
522
+ else if ((typeof binding.urlPattern !== 'string' || !binding.urlPattern) && !hasDetail(binding.apiId)) {
523
+ add(path, "'entryUrl' requires binding.urlPattern or a content type with a detail page");
524
+ }
525
+ break;
526
+ case 'field':
527
+ if (typeof s.name !== 'string' || !fieldNames.has(s.name))
528
+ add([...path, 'name'], `unknown field "${String(s.name)}"`);
529
+ break;
530
+ case 'const':
531
+ if (!('value' in s))
532
+ add([...path, 'value'], 'const value is required');
533
+ break;
534
+ default:
535
+ add([...path, 'from'], "from must be 'entry', 'entryUrl', 'field' or 'const'");
536
+ }
537
+ };
538
+ const rootIsOverlay = isObj(spec.tree) && spec.tree.el === 'Overlay';
539
+ const regionNamesSeen = new Set();
540
+ let pageContents = 0;
541
+ let layoutNodes = 0;
542
+ let lists = 0;
543
+ const listKeys = new Set();
544
+ const specKind = isObj(spec.tree) ? composedKind(spec) : 'block';
545
+ const walk = (n, path, ctx) => {
546
+ if (!isObj(n))
547
+ return add(path, 'node must be an object');
548
+ const el = n.el;
549
+ const at = (m) => add([...path, 'el'], m);
550
+ let flaggedInClickable = false;
551
+ if (!exports.COMPOSED_ELEMENTS.includes(el)) {
552
+ at(`unknown element "${String(n.el)}"`);
553
+ }
554
+ else if (el === 'Slot' && (collection || ctx.list)) {
555
+ at('Slot is not allowed inside a collection item template');
556
+ }
557
+ else if (el === 'Carousel' && (collection || ctx.list)) {
558
+ at('Carousel is not allowed inside a collection item template');
559
+ }
560
+ else if (el === 'CollectionList' && ctx.list) {
561
+ at('a CollectionList cannot contain a CollectionList');
562
+ }
563
+ else if (el === 'CollectionList' && collection) {
564
+ at('a CollectionList is not allowed in a block with a collection binding');
565
+ }
566
+ else if (el === 'CollectionList' && ++lists > exports.MAX_COLLECTION_LISTS) {
567
+ at(`a block can have at most ${exports.MAX_COLLECTION_LISTS} CollectionLists`);
568
+ }
569
+ else if (el === 'AccordionItem' && ctx.parent !== 'Accordion') {
570
+ at('AccordionItem is only allowed directly inside an Accordion');
571
+ }
572
+ else if (el === 'TabPanel' && ctx.parent !== 'Tabs') {
573
+ at('TabPanel is only allowed directly inside Tabs');
574
+ }
575
+ else if (el === 'Form' && ctx.inForm) {
576
+ at('a Form cannot contain a Form');
577
+ }
578
+ else if (el === 'Dropdown' && ctx.inDropdown) {
579
+ at('a Dropdown cannot contain a Dropdown');
580
+ }
581
+ else if ((el === 'Region' || el === 'PageContent') && ctx.inDropdown) {
582
+ at(`${el} is not allowed inside a Dropdown`);
583
+ }
584
+ else if (exports.INTERACTIVE_CONTAINERS.includes(el) && ctx.parent === 'Overlay' && rootIsOverlay && path.length === 3) {
585
+ at(`${el} cannot be the root of an overlay frame (put it inside a Box or Stack)`);
586
+ }
587
+ if (ctx.inClickable && (exports.INTERACTIVE_ELEMENTS.includes(el) || el === 'Form' || isClickable(n))) {
588
+ flaggedInClickable = true;
589
+ add([...path, 'el'], `${String(el)} is not allowed inside a clickable Box or Card`);
590
+ }
591
+ if ((el === 'Region' || el === 'PageContent') && ctx.list) {
592
+ add([...path, 'el'], `${el} is not allowed inside a collection item template`);
593
+ }
594
+ else if (el === 'Region' || el === 'PageContent') {
595
+ layoutNodes++;
596
+ if (collection)
597
+ add([...path, 'el'], `${el} is not allowed in a block with a collection binding`);
598
+ if (rootIsOverlay)
599
+ add([...path, 'el'], `${el} is not allowed in an overlay block`);
600
+ if (Array.isArray(n.children) ? n.children.length > 0 : n.children !== undefined)
601
+ add([...path, 'children'], `${el} cannot have children`);
602
+ if (el === 'PageContent' && ++pageContents === 2)
603
+ add([...path, 'el'], 'only one PageContent is allowed');
604
+ if (el === 'Region' && (n.props === undefined || isObj(n.props))) {
605
+ const rp = isObj(n.props) ? n.props : {};
606
+ if (typeof rp.name !== 'string' || !actions_1.OVERLAY_NAME_RE.test(rp.name))
607
+ add([...path, 'props', 'name'], 'name must match ^[a-z][a-z0-9-]{0,31}$');
608
+ else if (regionNamesSeen.has(rp.name))
609
+ add([...path, 'props', 'name'], `duplicate region name "${rp.name}"`);
610
+ else
611
+ regionNamesSeen.add(rp.name);
612
+ if (rp.label !== undefined && typeof rp.label !== 'string') {
613
+ const m = isObj(rp.label) ? (0, groups_1.validateLocalizedText)(rp.label, 'label') : ['label must be a string or localized text'];
614
+ if (m.length)
615
+ add([...path, 'props', 'label'], m.join('; '));
616
+ }
617
+ if (rp.allow !== undefined && !(Array.isArray(rp.allow) && rp.allow.every((x) => typeof x === 'string' && x))) {
618
+ add([...path, 'props', 'allow'], 'allow must be an array of block names');
619
+ }
620
+ }
621
+ }
622
+ if (el === 'Overlay' && path.length > 1)
623
+ add([...path, 'el'], 'Overlay is only allowed as the root node');
624
+ if (n.props !== undefined && !isObj(n.props))
625
+ add([...path, 'props'], 'props must be an object');
626
+ else if (el === 'Slot' && isObj(n.props)) {
627
+ const { allow, max } = n.props;
628
+ if (allow !== undefined && !(Array.isArray(allow) && allow.every((x) => typeof x === 'string' && x))) {
629
+ add([...path, 'props', 'allow'], 'allow must be an array of block names');
630
+ }
631
+ if (max !== undefined && !(Number.isInteger(max) && max > 0))
632
+ add([...path, 'props', 'max'], 'max must be a positive integer');
633
+ }
634
+ for (const i of (0, style_1.validateNodeStyle)(n.style, [...path, 'style'], exports.COMPOSED_ELEMENTS.includes(el) ? el : undefined))
635
+ add(i.path, i.message);
636
+ if (isObj(n.props) || (n.props === undefined && REQUIRED_PROPS[el])) {
637
+ checkComponentProps(el, isObj(n.props) ? n.props : {}, [...path, 'props'], add);
638
+ }
639
+ if (isObj(n.props)) {
640
+ checkLayoutProps(el, n.props, [...path, 'props'], add);
641
+ const pp = [...path, 'props'];
642
+ if (n.props.anchorId !== undefined && (typeof n.props.anchorId !== 'string' || !actions_1.ANCHOR_ID_RE.test(n.props.anchorId))) {
643
+ add([...pp, 'anchorId'], 'anchorId must match ^[A-Za-z][\\w-]{0,63}$');
644
+ }
645
+ if (n.props.action !== undefined) {
646
+ if (el === 'Form') { /* checked below: run only */ }
647
+ else if (ACTION_ELEMENTS.includes(el))
648
+ for (const i of (0, actions_1.validateButtonAction)(n.props.action, [...pp, 'action'], opts.actions, actionCheck(ctx)))
649
+ add(i.path, i.message);
650
+ else
651
+ add([...pp, 'action'], 'action is only allowed on Button, Image, Box and Card');
652
+ }
653
+ if (el === 'Form' && n.props.action !== undefined) {
654
+ const fa = (0, actions_1.validateButtonAction)(n.props.action, [...pp, 'action'], opts.actions, actionCheck(ctx));
655
+ for (const i of fa)
656
+ add(i.path, i.message);
657
+ if (fa.length === 0 && n.props.action.type !== 'run')
658
+ add([...pp, 'action'], "a Form's action must be a run action");
659
+ }
660
+ if (el === 'Button' && n.props.submit === true) {
661
+ if (!ctx.inForm)
662
+ add([...pp, 'submit'], 'a submit Button is only allowed inside a Form');
663
+ if (n.props.action !== undefined)
664
+ add([...pp, 'action'], 'a submit Button cannot have an action (the Form runs it)');
665
+ if (isObj(n.bind) && n.bind.href !== undefined)
666
+ add([...path, 'bind', 'href'], 'a submit Button cannot have an href');
667
+ }
668
+ if (el === 'CollectionList' && typeof n.props.key === 'string' && exports.COLLECTION_LIST_KEY_RE.test(n.props.key)) {
669
+ const key = n.props.key;
670
+ const kp = [...pp, 'key'];
671
+ if (listKeys.has(key))
672
+ add(kp, `duplicate CollectionList key "${key}"`);
673
+ else if (fieldNames.has(key))
674
+ add(kp, `key collides with field "${key}"`);
675
+ else if (isReservedListKey(key, specKind)) {
676
+ add(kp, `"${key}" is reserved`);
677
+ }
678
+ listKeys.add(key);
679
+ }
680
+ if (el === 'Dropdown' && n.props.chevron === false && isObj(n.bind) && n.bind.href !== undefined) {
681
+ add([...pp, 'chevron'], 'a Dropdown with a link must keep its chevron (it opens the panel)');
682
+ }
683
+ }
684
+ if (isObj(n.bind)) {
685
+ if (el === 'Image' && isClickable(n) && constText(n.bind.alt)?.trim() === '') {
686
+ add([...path, 'bind', 'alt'], 'a clickable image needs a non-empty alt (it names the link)');
687
+ }
688
+ const tip = el === 'Tooltip' ? constText(n.bind.text) : undefined;
689
+ if (tip !== undefined && tip.length > exports.TOOLTIP_TEXT_MAX)
690
+ add([...path, 'bind', 'text'], `text must be at most ${exports.TOOLTIP_TEXT_MAX} characters`);
691
+ }
692
+ if (n.bind !== undefined) {
693
+ if (!isObj(n.bind))
694
+ add([...path, 'bind'], 'bind must be an object');
695
+ else
696
+ for (const [k, s] of Object.entries(n.bind)) {
697
+ if (exports.COMPOSED_ELEMENTS.includes(el) && !exports.ELEMENT_BINDABLE[el].includes(k)) {
698
+ add([...path, 'bind', k], `${String(el)} has no bindable prop "${k}"`);
699
+ }
700
+ checkSource(s, [...path, 'bind', k], ctx);
701
+ }
702
+ }
703
+ if (n.showIf !== undefined) {
704
+ const s = n.showIf;
705
+ const sp = [...path, 'showIf'];
706
+ if (!isObj(s))
707
+ add(sp, 'showIf must be an object');
708
+ else {
709
+ if (s.is !== 'present' && s.is !== 'absent')
710
+ add([...sp, 'is'], "is must be 'present' or 'absent'");
711
+ if (s.from === 'entry') {
712
+ if (!hasBinding && !ctx.list)
713
+ add(sp, "'entry' requires a binding");
714
+ if (typeof s.path !== 'string' || !s.path)
715
+ add([...sp, 'path'], 'path is required');
716
+ }
717
+ else if (s.from === 'field') {
718
+ if (typeof s.name !== 'string' || !fieldNames.has(s.name))
719
+ add([...sp, 'name'], `unknown field "${String(s.name)}"`);
720
+ }
721
+ else
722
+ add([...sp, 'from'], "from must be 'entry' or 'field'");
723
+ }
724
+ }
725
+ const kids = Array.isArray(n.children) ? n.children : [];
726
+ if (LEAF_ELEMENTS.includes(el) && kids.length > 0)
727
+ add([...path, 'children'], `${el} cannot have children`);
728
+ const count = CHILD_COUNTS[el];
729
+ if (count && (n.children === undefined || Array.isArray(n.children)) && (kids.length < count[0] || kids.length > count[1])) {
730
+ add([...path, 'children'], count[0] === count[1] ? `${el} must have exactly ${count[0]} ${count[2]}` : `${el} must have ${count[0]} to ${count[1]} ${count[2]}`);
731
+ }
732
+ kids.forEach((c, i) => {
733
+ const ce = childEl(c);
734
+ const cp = [...path, 'children', i, 'el'];
735
+ // A misplaced AccordionItem/TabPanel is reported by its own rule.
736
+ if (ce === 'AccordionItem' || ce === 'TabPanel')
737
+ return;
738
+ if (el === 'Accordion')
739
+ add(cp, 'an Accordion accepts only AccordionItem children');
740
+ else if (el === 'Tabs')
741
+ add(cp, 'Tabs accept only TabPanel children');
742
+ else if (el === 'Tooltip' && (ce === 'Tooltip' || ce === 'Dropdown' || exports.FORM_CONTROL_ELEMENTS.includes(ce))) {
743
+ add(cp, `a Tooltip cannot wrap a ${String(ce)}`);
744
+ }
745
+ });
746
+ if (n.children !== undefined) {
747
+ if (!Array.isArray(n.children))
748
+ add([...path, 'children'], 'children must be an array');
749
+ else {
750
+ const next = {
751
+ parent: el,
752
+ inDropdown: ctx.inDropdown || el === 'Dropdown',
753
+ inForm: ctx.inForm || el === 'Form',
754
+ inClickable: (ctx.inClickable && !flaggedInClickable) || ((el === 'Box' || el === 'Card') && isClickable(n)),
755
+ list: el === 'CollectionList' ? { apiId: isObj(n.props) ? n.props.apiId : undefined, urlPattern: isObj(n.props) ? n.props.urlPattern : undefined } : ctx.list,
756
+ };
757
+ n.children.forEach((c, i) => walk(c, [...path, 'children', i], next));
758
+ }
759
+ }
760
+ };
761
+ if (spec.tree === undefined)
762
+ add(['tree'], 'tree is required');
763
+ else
764
+ walk(spec.tree, ['tree'], { inDropdown: false, inClickable: false });
765
+ if (layoutNodes > 0 && pageContents === 0 && !rootIsOverlay && !collection)
766
+ add(['tree'], 'a layout block requires exactly one PageContent');
767
+ return issues;
768
+ }
769
+ function composedManifestEntry(spec) {
770
+ const richText = Object.entries(spec.fields ?? {}).filter(([, f]) => f.kind === 'richText').map(([n]) => n);
771
+ const kind = composedKind(spec);
772
+ return {
773
+ name: spec.name,
774
+ version: spec.version,
775
+ ...(richText.length ? { richText } : {}),
776
+ ...(kind !== 'block' ? { kind } : {}),
777
+ };
778
+ }
779
+ /** `ProductCard` → `product-card` (block folders and file names, default overlay names). */
780
+ function kebabName(name) {
781
+ return name
782
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
783
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
784
+ .toLowerCase();
785
+ }
786
+ /** Default `name` of an overlay block placement: the block name in kebab case, cut to the overlay name length. */
787
+ function overlayDefaultName(blockName) {
788
+ return kebabName(blockName).slice(0, 32).replace(/-+$/, '');
789
+ }
790
+ /**
791
+ * Identity of each `Slot` of `tree`, in tree order (the order `defineComposedBlock` names them `slot`, `slot2`, …):
792
+ * its position path (child indices) and its sorted `allow` list (`*` = any block).
793
+ */
794
+ function slotSignature(tree) {
795
+ const out = [];
796
+ const walk = (n, path) => {
797
+ if (!n || typeof n !== 'object')
798
+ return;
799
+ if (n.el === 'Slot') {
800
+ const allow = Array.isArray(n.props?.allow) ? [...n.props.allow].map(String).sort().join(',') : '*';
801
+ out.push(`${path.join('.')}|${allow}`);
802
+ }
803
+ (Array.isArray(n.children) ? n.children : []).forEach((c, i) => walk(c, [...path, i]));
804
+ };
805
+ walk(tree, []);
806
+ return out;
807
+ }
808
+ /**
809
+ * True when stored content of a slot would land in another slot or be dropped: fewer slots, or any existing slot
810
+ * moved or given another `allow`. A slot added after the existing ones is not breaking.
811
+ */
812
+ function slotsChanged(prev, next) {
813
+ const a = slotSignature(prev.tree);
814
+ const b = slotSignature(next.tree);
815
+ return b.length < a.length || a.some((s, i) => b[i] !== s);
816
+ }
817
+ const someNode = (n, f) => {
818
+ if (!isObj(n))
819
+ return false;
820
+ return f(n) || (Array.isArray(n.children) && n.children.some((c) => someNode(c, f)));
821
+ };
822
+ /** `overlay` when the tree root is an `Overlay`, `layout` when it holds a `Region` or `PageContent`, else `block`. */
823
+ function composedKind(spec) {
824
+ const tree = spec?.tree;
825
+ if (isObj(tree) && tree.el === 'Overlay')
826
+ return 'overlay';
827
+ return someNode(tree, (n) => n.el === 'Region' || n.el === 'PageContent') ? 'layout' : 'block';
828
+ }
829
+ /** Names of the valid, first-seen `Region`s of `spec`, in tree order. */
830
+ function regionNames(spec) {
831
+ const out = [];
832
+ const walk = (n) => {
833
+ if (!isObj(n))
834
+ return;
835
+ const name = isObj(n.props) ? n.props.name : undefined;
836
+ if (n.el === 'Region' && typeof name === 'string' && actions_1.OVERLAY_NAME_RE.test(name) && !out.includes(name))
837
+ out.push(name);
838
+ if (Array.isArray(n.children))
839
+ n.children.forEach(walk);
840
+ };
841
+ walk(spec?.tree);
842
+ return out;
843
+ }
844
+ /**
845
+ * The `CollectionList`s of `spec` with a valid, first-seen `key`, in tree order (each one's key is its generated
846
+ * `b.entries` block field).
847
+ */
848
+ function collectionListsOf(spec) {
849
+ const out = [];
850
+ const walk = (n) => {
851
+ if (!isObj(n))
852
+ return;
853
+ const key = isObj(n.props) ? n.props.key : undefined;
854
+ if (n.el === 'CollectionList' && typeof key === 'string' && exports.COLLECTION_LIST_KEY_RE.test(key) && !out.some((l) => l.key === key)) {
855
+ out.push({ key, node: n });
856
+ }
857
+ if (Array.isArray(n.children))
858
+ n.children.forEach(walk);
859
+ };
860
+ walk(spec?.tree);
861
+ return out;
862
+ }
863
+ function isBreakingChange(prev, next) {
864
+ if (slotsChanged(prev, next))
865
+ return true;
866
+ // Stored list content lives in a field named after the key: a removed key or another type drops it.
867
+ const nextLists = collectionListsOf(next);
868
+ for (const l of collectionListsOf(prev)) {
869
+ const n = nextLists.find((x) => x.key === l.key);
870
+ if (!n || n.node.props?.apiId !== l.node.props?.apiId)
871
+ return true;
872
+ }
873
+ if (composedKind(prev) !== composedKind(next))
874
+ return true;
875
+ if (regionNames(prev).join('\n') !== regionNames(next).join('\n'))
876
+ return true;
877
+ for (const [name, f] of Object.entries(prev.fields ?? {})) {
878
+ const n = next.fields?.[name];
879
+ if (!n || n.kind !== f.kind)
880
+ return true;
881
+ if (f.kind === 'select' && (f.options ?? []).some((o) => !(n.options ?? []).includes(o)))
882
+ return true;
883
+ }
884
+ const a = prev.binding;
885
+ const b = next.binding;
886
+ if (!a !== !b)
887
+ return true;
888
+ if (a && b && (a.apiId !== b.apiId || a.mode !== b.mode))
889
+ return true;
890
+ return false;
891
+ }
892
+ function withAutoVersion(prev, next) {
893
+ if (!prev)
894
+ return { ...next, version: 1 };
895
+ return { ...next, version: isBreakingChange(prev, next) ? prev.version + 1 : prev.version };
896
+ }
897
+ //# sourceMappingURL=composed-block.js.map