@ikas/component-cli 1.4.0-beta.22 → 1.4.0-beta.221

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 (204) hide show
  1. package/dist/build-tools.d.ts +37 -0
  2. package/dist/build-tools.d.ts.map +1 -0
  3. package/dist/build-tools.js +36 -0
  4. package/dist/build-tools.js.map +1 -0
  5. package/dist/commands/add-sections-to-page.d.ts +3 -0
  6. package/dist/commands/add-sections-to-page.d.ts.map +1 -0
  7. package/dist/commands/add-sections-to-page.js +39 -0
  8. package/dist/commands/add-sections-to-page.js.map +1 -0
  9. package/dist/commands/add.d.ts.map +1 -1
  10. package/dist/commands/add.js +11 -2
  11. package/dist/commands/add.js.map +1 -1
  12. package/dist/commands/build.d.ts.map +1 -1
  13. package/dist/commands/build.js +15 -167
  14. package/dist/commands/build.js.map +1 -1
  15. package/dist/commands/config-texts.d.ts +38 -0
  16. package/dist/commands/config-texts.d.ts.map +1 -0
  17. package/dist/commands/config-texts.js +186 -0
  18. package/dist/commands/config-texts.js.map +1 -0
  19. package/dist/commands/config.d.ts +45 -0
  20. package/dist/commands/config.d.ts.map +1 -1
  21. package/dist/commands/config.js +1148 -154
  22. package/dist/commands/config.js.map +1 -1
  23. package/dist/commands/create-design-tokens.d.ts +24 -0
  24. package/dist/commands/create-design-tokens.d.ts.map +1 -0
  25. package/dist/commands/create-design-tokens.js +388 -0
  26. package/dist/commands/create-design-tokens.js.map +1 -0
  27. package/dist/commands/create-global-variable.d.ts +3 -0
  28. package/dist/commands/create-global-variable.d.ts.map +1 -0
  29. package/dist/commands/create-global-variable.js +73 -0
  30. package/dist/commands/create-global-variable.js.map +1 -0
  31. package/dist/commands/create-page.d.ts +3 -0
  32. package/dist/commands/create-page.d.ts.map +1 -0
  33. package/dist/commands/create-page.js +31 -0
  34. package/dist/commands/create-page.js.map +1 -0
  35. package/dist/commands/delete-page.d.ts +3 -0
  36. package/dist/commands/delete-page.d.ts.map +1 -0
  37. package/dist/commands/delete-page.js +28 -0
  38. package/dist/commands/delete-page.js.map +1 -0
  39. package/dist/commands/delete-theme-globals.d.ts +4 -0
  40. package/dist/commands/delete-theme-globals.d.ts.map +1 -0
  41. package/dist/commands/delete-theme-globals.js +50 -0
  42. package/dist/commands/delete-theme-globals.js.map +1 -0
  43. package/dist/commands/dev.d.ts.map +1 -1
  44. package/dist/commands/dev.js +308 -39
  45. package/dist/commands/dev.js.map +1 -1
  46. package/dist/commands/enable-builtin-pages.d.ts +3 -0
  47. package/dist/commands/enable-builtin-pages.d.ts.map +1 -0
  48. package/dist/commands/enable-builtin-pages.js +28 -0
  49. package/dist/commands/enable-builtin-pages.js.map +1 -0
  50. package/dist/commands/get-component-props.d.ts +3 -0
  51. package/dist/commands/get-component-props.d.ts.map +1 -0
  52. package/dist/commands/get-component-props.js +32 -0
  53. package/dist/commands/get-component-props.js.map +1 -0
  54. package/dist/commands/get-page-by-type.d.ts +3 -0
  55. package/dist/commands/get-page-by-type.d.ts.map +1 -0
  56. package/dist/commands/get-page-by-type.js +25 -0
  57. package/dist/commands/get-page-by-type.js.map +1 -0
  58. package/dist/commands/get-section-values.d.ts +3 -0
  59. package/dist/commands/get-section-values.d.ts.map +1 -0
  60. package/dist/commands/get-section-values.js +39 -0
  61. package/dist/commands/get-section-values.js.map +1 -0
  62. package/dist/commands/list-builtin-pages.d.ts +3 -0
  63. package/dist/commands/list-builtin-pages.d.ts.map +1 -0
  64. package/dist/commands/list-builtin-pages.js +28 -0
  65. package/dist/commands/list-builtin-pages.js.map +1 -0
  66. package/dist/commands/list-entities.d.ts +3 -0
  67. package/dist/commands/list-entities.d.ts.map +1 -0
  68. package/dist/commands/list-entities.js +32 -0
  69. package/dist/commands/list-entities.js.map +1 -0
  70. package/dist/commands/list-page-sections.d.ts.map +1 -1
  71. package/dist/commands/list-page-sections.js +8 -2
  72. package/dist/commands/list-page-sections.js.map +1 -1
  73. package/dist/commands/list-theme-globals.d.ts +3 -0
  74. package/dist/commands/list-theme-globals.d.ts.map +1 -0
  75. package/dist/commands/list-theme-globals.js +22 -0
  76. package/dist/commands/list-theme-globals.js.map +1 -0
  77. package/dist/commands/list-translations.d.ts +3 -0
  78. package/dist/commands/list-translations.d.ts.map +1 -0
  79. package/dist/commands/list-translations.js +33 -0
  80. package/dist/commands/list-translations.js.map +1 -0
  81. package/dist/commands/move-page-section.d.ts +3 -0
  82. package/dist/commands/move-page-section.d.ts.map +1 -0
  83. package/dist/commands/move-page-section.js +62 -0
  84. package/dist/commands/move-page-section.js.map +1 -0
  85. package/dist/commands/publish-theme.d.ts +3 -0
  86. package/dist/commands/publish-theme.d.ts.map +1 -0
  87. package/dist/commands/publish-theme.js +29 -0
  88. package/dist/commands/publish-theme.js.map +1 -0
  89. package/dist/commands/publish.d.ts.map +1 -1
  90. package/dist/commands/publish.js +65 -3
  91. package/dist/commands/publish.js.map +1 -1
  92. package/dist/commands/remove-page-section.d.ts +3 -0
  93. package/dist/commands/remove-page-section.d.ts.map +1 -0
  94. package/dist/commands/remove-page-section.js +40 -0
  95. package/dist/commands/remove-page-section.js.map +1 -0
  96. package/dist/commands/search-products.d.ts +3 -0
  97. package/dist/commands/search-products.d.ts.map +1 -0
  98. package/dist/commands/search-products.js +40 -0
  99. package/dist/commands/search-products.js.map +1 -0
  100. package/dist/commands/translation-languages.d.ts +3 -0
  101. package/dist/commands/translation-languages.d.ts.map +1 -0
  102. package/dist/commands/translation-languages.js +43 -0
  103. package/dist/commands/translation-languages.js.map +1 -0
  104. package/dist/commands/update-builtin-page-prop.d.ts +3 -0
  105. package/dist/commands/update-builtin-page-prop.d.ts.map +1 -0
  106. package/dist/commands/update-builtin-page-prop.js +49 -0
  107. package/dist/commands/update-builtin-page-prop.js.map +1 -0
  108. package/dist/commands/update-global-variable.d.ts +3 -0
  109. package/dist/commands/update-global-variable.d.ts.map +1 -0
  110. package/dist/commands/update-global-variable.js +70 -0
  111. package/dist/commands/update-global-variable.js.map +1 -0
  112. package/dist/commands/update-page-sections.d.ts +3 -0
  113. package/dist/commands/update-page-sections.d.ts.map +1 -0
  114. package/dist/commands/update-page-sections.js +39 -0
  115. package/dist/commands/update-page-sections.js.map +1 -0
  116. package/dist/commands/update-section-prop.d.ts.map +1 -1
  117. package/dist/commands/update-section-prop.js +25 -8
  118. package/dist/commands/update-section-prop.js.map +1 -1
  119. package/dist/commands/update-translations.d.ts +3 -0
  120. package/dist/commands/update-translations.d.ts.map +1 -0
  121. package/dist/commands/update-translations.js +37 -0
  122. package/dist/commands/update-translations.js.map +1 -0
  123. package/dist/commands/upload-image.d.ts.map +1 -1
  124. package/dist/commands/upload-image.js +5 -46
  125. package/dist/commands/upload-image.js.map +1 -1
  126. package/dist/commands/upload-images.d.ts +3 -0
  127. package/dist/commands/upload-images.d.ts.map +1 -0
  128. package/dist/commands/upload-images.js +48 -0
  129. package/dist/commands/upload-images.js.map +1 -0
  130. package/dist/index.d.ts.map +1 -1
  131. package/dist/index.js +60 -1
  132. package/dist/index.js.map +1 -1
  133. package/dist/types.d.ts +77 -0
  134. package/dist/types.d.ts.map +1 -1
  135. package/dist/utils/archive-project.d.ts +50 -0
  136. package/dist/utils/archive-project.d.ts.map +1 -0
  137. package/dist/utils/archive-project.js +178 -0
  138. package/dist/utils/archive-project.js.map +1 -0
  139. package/dist/utils/compile.d.ts +17 -2
  140. package/dist/utils/compile.d.ts.map +1 -1
  141. package/dist/utils/compile.js +759 -117
  142. package/dist/utils/compile.js.map +1 -1
  143. package/dist/utils/component-helpers.d.ts +222 -4
  144. package/dist/utils/component-helpers.d.ts.map +1 -1
  145. package/dist/utils/component-helpers.js +558 -37
  146. package/dist/utils/component-helpers.js.map +1 -1
  147. package/dist/utils/css-import-resolver.d.ts +4 -1
  148. package/dist/utils/css-import-resolver.d.ts.map +1 -1
  149. package/dist/utils/css-import-resolver.js +9 -1
  150. package/dist/utils/css-import-resolver.js.map +1 -1
  151. package/dist/utils/dev-server-auth.d.ts +19 -0
  152. package/dist/utils/dev-server-auth.d.ts.map +1 -0
  153. package/dist/utils/dev-server-auth.js +60 -0
  154. package/dist/utils/dev-server-auth.js.map +1 -0
  155. package/dist/utils/editor-action-client.d.ts +4 -3
  156. package/dist/utils/editor-action-client.d.ts.map +1 -1
  157. package/dist/utils/editor-action-client.js +56 -19
  158. package/dist/utils/editor-action-client.js.map +1 -1
  159. package/dist/utils/esm-transform.d.ts +30 -0
  160. package/dist/utils/esm-transform.d.ts.map +1 -1
  161. package/dist/utils/esm-transform.js +169 -2
  162. package/dist/utils/esm-transform.js.map +1 -1
  163. package/dist/utils/find-component-for-file.d.ts +12 -0
  164. package/dist/utils/find-component-for-file.d.ts.map +1 -0
  165. package/dist/utils/find-component-for-file.js +24 -0
  166. package/dist/utils/find-component-for-file.js.map +1 -0
  167. package/dist/utils/forbid-deep-imports.d.ts +3 -0
  168. package/dist/utils/forbid-deep-imports.d.ts.map +1 -0
  169. package/dist/utils/forbid-deep-imports.js +54 -0
  170. package/dist/utils/forbid-deep-imports.js.map +1 -0
  171. package/dist/utils/forbid-external-packages.d.ts +26 -0
  172. package/dist/utils/forbid-external-packages.d.ts.map +1 -0
  173. package/dist/utils/forbid-external-packages.js +99 -0
  174. package/dist/utils/forbid-external-packages.js.map +1 -0
  175. package/dist/utils/i18n.d.ts +81 -0
  176. package/dist/utils/i18n.d.ts.map +1 -0
  177. package/dist/utils/i18n.js +268 -0
  178. package/dist/utils/i18n.js.map +1 -0
  179. package/dist/utils/load-image.d.ts +16 -0
  180. package/dist/utils/load-image.d.ts.map +1 -0
  181. package/dist/utils/load-image.js +50 -0
  182. package/dist/utils/load-image.js.map +1 -0
  183. package/dist/utils/storefront-t.d.ts +17 -0
  184. package/dist/utils/storefront-t.d.ts.map +1 -0
  185. package/dist/utils/storefront-t.js +187 -0
  186. package/dist/utils/storefront-t.js.map +1 -0
  187. package/dist/utils/vendor-storefront.d.ts +13 -0
  188. package/dist/utils/vendor-storefront.d.ts.map +1 -0
  189. package/dist/utils/vendor-storefront.js +91 -0
  190. package/dist/utils/vendor-storefront.js.map +1 -0
  191. package/dist/utils/websocket-server.d.ts +161 -7
  192. package/dist/utils/websocket-server.d.ts.map +1 -1
  193. package/dist/utils/websocket-server.js +324 -45
  194. package/dist/utils/websocket-server.js.map +1 -1
  195. package/package.json +19 -2
  196. package/templates/add/section.css +11 -0
  197. package/dist/commands/create.d.ts +0 -4
  198. package/dist/commands/create.d.ts.map +0 -1
  199. package/dist/commands/create.js +0 -228
  200. package/dist/commands/create.js.map +0 -1
  201. package/dist/commands/proxy.d.ts +0 -39
  202. package/dist/commands/proxy.d.ts.map +0 -1
  203. package/dist/commands/proxy.js +0 -210
  204. package/dist/commands/proxy.js.map +0 -1
@@ -35,6 +35,95 @@ export function generateUniqueId() {
35
35
  export function generateComponentId(projectId) {
36
36
  return `${projectId}-${generateUniqueId()}`;
37
37
  }
38
+ /**
39
+ * The editor's publish-id machinery (rewrite-asset-ids.ts, MIN_ROOT_ID_LENGTH = 6)
40
+ * treats a leading run of >=6 alphanumeric characters before a `-`/`_` separator as
41
+ * a strippable project prefix, and republish stability (insert-vs-version matching
42
+ * by source suffix) depends on every projectId satisfying that shape. A projectId
43
+ * that is shorter, or that contains a separator/non-alphanumeric character, shifts
44
+ * the prefix/suffix boundary and silently re-opens the duplicate-element bug.
45
+ * `generateProjectId()` always satisfies this; the check exists because
46
+ * ikas.config.json is hand-editable and parsed without a schema.
47
+ */
48
+ export const PROJECT_ID_PATTERN = /^[A-Za-z0-9]{6,}$/;
49
+ export function isValidProjectId(projectId) {
50
+ return PROJECT_ID_PATTERN.test(projectId);
51
+ }
52
+ /**
53
+ * A component id is publishable when the editor's prefix-strip machinery parses it
54
+ * unambiguously: either a legacy atomic id (alphanumeric only, no separators) or a
55
+ * `<projectId>-<suffix>` form whose PREFIX meets the same >=6 floor as PROJECT_ID_PATTERN.
56
+ * The prefix must stay >=6 alphanumeric with NO separator (the editor strips exactly one
57
+ * leading `>=MIN_ROOT_ID_LENGTH` run before the first `-`/`_`); a short/separator-bearing
58
+ * prefix shifts that boundary and re-opens the duplicate-element bug.
59
+ *
60
+ * The SUFFIX, however, may be multi-segment (`<projectId>-hero-slider`,
61
+ * `<projectId>-product-detail-add-to-cart`): older CLI configs used human-readable
62
+ * suffixes, and those ids are already placed on published themes so they cannot be
63
+ * renamed. The editor's `normalizeSourceElementId` canonicalizes every suffix separator
64
+ * to `_`, so a hyphenated local suffix and its underscore-sterilized published form
65
+ * normalize to the same republish-invariant key — multi-segment suffixes match stably.
66
+ * Each segment must still be a non-empty alphanumeric run (no trailing/doubled separators).
67
+ */
68
+ export const COMPONENT_ID_PATTERN = /^(?:[A-Za-z0-9]+|[A-Za-z0-9]{6,}(?:[-_][A-Za-z0-9]+)+)$/;
69
+ /**
70
+ * Ids from the pre-projectId CLI (`<kebab-name>-<Date.now()>`) predate the prefix
71
+ * contract and are already placed on themes, so the prefix check below skips them.
72
+ */
73
+ const LEGACY_TIMESTAMP_ID_PATTERN = /-\d{13}$/;
74
+ /**
75
+ * Besides the shape check, a separator-bearing id must carry THIS project's prefix.
76
+ * An id with another prefix was copied from somewhere else — typically the published
77
+ * id the editor reports for a component installed from a design asset. Syncing it
78
+ * creates a second copy of the published component in the partner theme and corrupts
79
+ * the asset's local→published id map on the next publish.
80
+ */
81
+ export function findInvalidComponentIds(components, projectId) {
82
+ return components.flatMap((c) => {
83
+ if (!COMPONENT_ID_PATTERN.test(c.id)) {
84
+ return [{ id: c.id, name: c.name, reason: "malformed id" }];
85
+ }
86
+ const prefix = c.id.split(/[-_]/)[0];
87
+ const hasSeparator = prefix !== c.id;
88
+ if (projectId &&
89
+ hasSeparator &&
90
+ prefix !== projectId &&
91
+ !LEGACY_TIMESTAMP_ID_PATTERN.test(c.id)) {
92
+ return [
93
+ {
94
+ id: c.id,
95
+ name: c.name,
96
+ reason: `does not start with this project's id "${projectId}"`,
97
+ },
98
+ ];
99
+ }
100
+ return [];
101
+ });
102
+ }
103
+ /**
104
+ * Identity edits a running dev server must not take from a config reload: a changed
105
+ * projectId, or a component that kept its entry file but came back under another id.
106
+ * The editor reads an id that disappears mid-session as "component deleted" and removes
107
+ * the imported component, its wrapper section and its page placements from the theme.
108
+ * A component whose entry is gone from the config is a real removal and is not reported.
109
+ */
110
+ export function findIdentityChanges(previous, reloaded) {
111
+ const changes = [];
112
+ if (previous.projectId && reloaded.projectId !== previous.projectId) {
113
+ changes.push(`projectId "${previous.projectId}" -> "${reloaded.projectId}"`);
114
+ }
115
+ const previousIdByEntry = new Map((previous.components ?? []).map((c) => [c.entry, c.id]));
116
+ for (const c of reloaded.components ?? []) {
117
+ const previousId = previousIdByEntry.get(c.entry);
118
+ if (previousId && previousId !== c.id) {
119
+ changes.push(`${c.name}: "${previousId}" -> "${c.id}"`);
120
+ }
121
+ }
122
+ return changes;
123
+ }
124
+ /** Shared hint printed under an invalid-component-id error. */
125
+ export const COMPONENT_ID_HINT = "Component ids are generated by the CLI — restore the original values. Never hand-edit them, " +
126
+ "never copy an id shown by the editor into ikas.config.json, and do not change projectId to match.";
38
127
  /**
39
128
  * Validate that every entry in `input` is the id of a component currently in `components`.
40
129
  * Returns the list of unknown entries (empty array means all valid).
@@ -96,8 +185,8 @@ export const PROP_TYPE_TO_TS = {
96
185
  COLOR: "string",
97
186
  PRODUCT: "IkasProduct | null",
98
187
  PRODUCT_LIST: "IkasProductList",
99
- PRODUCT_ATTRIBUTE: "IkasProductAttributeValue | null",
100
- PRODUCT_ATTRIBUTE_LIST: "IkasProductAttributeValue[]",
188
+ PRODUCT_ATTRIBUTE: "IkasProductAttributeDetail | null",
189
+ PRODUCT_ATTRIBUTE_LIST: "IkasProductAttributeList",
101
190
  CATEGORY: "IkasCategory | null",
102
191
  CATEGORY_LIST: "IkasCategoryList",
103
192
  BRAND: "IkasBrand | null",
@@ -111,6 +200,69 @@ export const PROP_TYPE_TO_TS = {
111
200
  COMPONENT: "any",
112
201
  COMPONENT_LIST: "any",
113
202
  };
203
+ /**
204
+ * Pattern-element ("Font Style" / typography) enum sentinel. The editor builds
205
+ * this synthetic enum at theme time (createPatternElementEnum). Mirror of
206
+ * PATTERN_ELEMENT_ENUM_ID in @ikas/editor-models — kept local to avoid an
207
+ * editor-models dependency in the CLI.
208
+ */
209
+ export const PATTERN_ELEMENT_ENUM_ID = "__patternElementEnum__";
210
+ /**
211
+ * Built-in enum type ids do not need to exist in config.customTypes: @ikas/*
212
+ * enums ship with the storefront models, and the pattern-element sentinel is
213
+ * resolved by the editor at theme time. Author-defined enums are NOT built-in.
214
+ */
215
+ export function isBuiltInEnumTypeId(enumTypeId) {
216
+ return (enumTypeId.startsWith("@ikas/") || enumTypeId === PATTERN_ELEMENT_ENUM_ID);
217
+ }
218
+ const ENUM_OPTIONS_EXAMPLE = `'{"Small":"sm","Medium":"md"}' or '[{"name":"Small","value":"sm"}]'`;
219
+ /**
220
+ * The parsed `--options` of `config add-enum` / `config update-enum`, as the `{ "Label": "value" }`
221
+ * record an enum stores. The object form passes through unchanged. The array form
222
+ * `[{ "name": "Label", "value": "value" }]` (`label` is accepted for `name`) — which older project
223
+ * docs showed and agents still produce — is converted, with values stringified like every enum value.
224
+ */
225
+ export function normalizeEnumOptionsInput(input) {
226
+ if (Array.isArray(input)) {
227
+ const options = {};
228
+ for (const item of input) {
229
+ if (!item || typeof item !== "object" || Array.isArray(item)) {
230
+ return {
231
+ error: `Each option in the array must be an object { "name", "value" }, e.g. ${ENUM_OPTIONS_EXAMPLE}.`,
232
+ };
233
+ }
234
+ const { name, label, value } = item;
235
+ const optionLabel = name ?? label;
236
+ if (typeof optionLabel !== "string" || !optionLabel.trim()) {
237
+ return {
238
+ error: `Every option needs a non-empty string "name", e.g. ${ENUM_OPTIONS_EXAMPLE}.`,
239
+ };
240
+ }
241
+ if ((typeof value !== "string" && typeof value !== "number") ||
242
+ String(value).trim() === "") {
243
+ return {
244
+ error: `Option "${optionLabel}" needs a non-empty string "value", e.g. ${ENUM_OPTIONS_EXAMPLE}.`,
245
+ };
246
+ }
247
+ if (Object.prototype.hasOwnProperty.call(options, optionLabel)) {
248
+ return { error: `Duplicate option name "${optionLabel}".` };
249
+ }
250
+ options[optionLabel] = String(value);
251
+ }
252
+ if (Object.keys(options).length === 0) {
253
+ return {
254
+ error: `Options must not be empty, e.g. ${ENUM_OPTIONS_EXAMPLE}.`,
255
+ };
256
+ }
257
+ return { options };
258
+ }
259
+ if (input && typeof input === "object" && Object.keys(input).length > 0) {
260
+ return { options: input };
261
+ }
262
+ return {
263
+ error: `Options must be a non-empty JSON object or array, e.g. ${ENUM_OPTIONS_EXAMPLE}.`,
264
+ };
265
+ }
114
266
  export function toKebabCase(str) {
115
267
  return str
116
268
  .replace(/([a-z])([A-Z])/g, "$1-$2")
@@ -149,14 +301,16 @@ function resolveTypeId(typeId) {
149
301
  */
150
302
  function resolveCustomEnumTypeName(enumTypeId, editorTypes, customTypes) {
151
303
  if (editorTypes) {
152
- const editorType = editorTypes.find(t => t.id === enumTypeId);
153
- if (editorType?.enumOptions && Object.keys(editorType.enumOptions).length > 0) {
304
+ const editorType = editorTypes.find((t) => t.id === enumTypeId);
305
+ if (editorType?.enumOptions &&
306
+ Object.keys(editorType.enumOptions).length > 0) {
154
307
  return toPascalCase(editorType.name);
155
308
  }
156
309
  }
157
310
  if (customTypes) {
158
- const customType = customTypes.find(t => t.id === enumTypeId);
159
- if (customType?.enumOptions && Object.keys(customType.enumOptions).length > 0) {
311
+ const customType = customTypes.find((t) => t.id === enumTypeId);
312
+ if (customType?.enumOptions &&
313
+ Object.keys(customType.enumOptions).length > 0) {
160
314
  return toPascalCase(customType.name);
161
315
  }
162
316
  }
@@ -176,7 +330,9 @@ export function generateTypesFile(componentName, props, type, editorTypes, custo
176
330
  typeIdResolved.set(prop.name, resolved.isArray ? `${resolved.typeName}[]` : resolved.typeName);
177
331
  }
178
332
  }
179
- else if (prop.type === "ENUM" && prop.enumTypeId) {
333
+ else if (prop.type === "ENUM" &&
334
+ prop.enumTypeId &&
335
+ prop.enumTypeId !== PATTERN_ELEMENT_ENUM_ID) {
180
336
  const resolved = resolveTypeId(prop.enumTypeId);
181
337
  if (resolved) {
182
338
  // Built-in enum — import from @ikas/bp-storefront
@@ -193,6 +349,9 @@ export function generateTypesFile(componentName, props, type, editorTypes, custo
193
349
  }
194
350
  }
195
351
  else {
352
+ // Non-ENUM props, plus the font-style (pattern-element) sentinel whose
353
+ // runtime value is a plain pattern-element id string → PROP_TYPE_TO_TS
354
+ // (PROP_TYPE_TO_TS["ENUM"] === "string"), no import emitted.
196
355
  const tsType = PROP_TYPE_TO_TS[prop.type];
197
356
  if (tsType?.includes("Ikas")) {
198
357
  const matches = tsType.match(/Ikas\w+/g);
@@ -298,6 +457,96 @@ export function collectUsedCustomTypeIds(customTypes, components) {
298
457
  }
299
458
  return used;
300
459
  }
460
+ /**
461
+ * Enum ids referenced by ENUM theme settings. Their union types must be emitted into
462
+ * `global-types.ts` even when no component prop uses the enum, so the setting's value-map
463
+ * entry (and `themeValue()`) can narrow to it.
464
+ */
465
+ export function collectThemeSettingEnumIds(themeSettings) {
466
+ const ids = new Set();
467
+ for (const s of themeSettings || []) {
468
+ if (s.type === "ENUM" && s.enumTypeId)
469
+ ids.add(s.enumTypeId);
470
+ }
471
+ return ids;
472
+ }
473
+ /**
474
+ * Map a global-variable kind to a TS type. Primitives narrowed; complex kinds stay `any`. An
475
+ * ENUM setting narrows to the union type THIS file declares for its enum: `resolveEnumTypeName`
476
+ * only knows the enums emitted above the theme block, so the map can never name an undeclared
477
+ * identifier. An ENUM whose enum is not emitted here — a deleted type, or a built-in `@ikas/*`
478
+ * enum (which the editor does not accept for a theme global, and whose import from
479
+ * `@ikas/bp-storefront` this generator cannot verify) — degrades to `string`.
480
+ */
481
+ function themeSettingTsType(setting, resolveEnumTypeName) {
482
+ switch (setting.type) {
483
+ case "NUMBER":
484
+ return "number";
485
+ case "BOOLEAN":
486
+ return "boolean";
487
+ case "TEXT":
488
+ case "RICH_TEXT":
489
+ case "COLOR":
490
+ return "string";
491
+ case "ENUM":
492
+ return ((setting.enumTypeId && resolveEnumTypeName(setting.enumTypeId)) ||
493
+ "string");
494
+ default:
495
+ return "any"; // IMAGE, BORDER, SHADOW — object shapes can drift from runtime
496
+ }
497
+ }
498
+ /**
499
+ * Import line for the typed theme-globals wrapper. Must sit at the top of the generated
500
+ * file (after the header). Emitted only when there are theme globals.
501
+ *
502
+ * A module augmentation can't deliver key-safety here: the runtime `getThemeSettingValue`
503
+ * is declared `(name: string): any`, so an added narrower overload never wins resolution —
504
+ * unknown keys still match `string` and return `any`. A generated wrapper whose parameter
505
+ * is `ThemeSettingName` (no `string` overload) does reject unknown keys and narrow the value.
506
+ */
507
+ const THEME_GLOBALS_IMPORT = `import { getThemeSettingValue as _getThemeSettingValueRaw } from "@ikas/bp-storefront";\n`;
508
+ /**
509
+ * Sentinel that marks a generated `global-types.ts` as containing the theme-globals block.
510
+ * This is the exported symbol authors import (stable public API), and it must stay a substring
511
+ * of what {@link generateThemeGlobalsBlock} emits — keep the two in sync if that output changes.
512
+ */
513
+ const THEME_GLOBALS_MARKER = "export type ThemeSettingName";
514
+ /**
515
+ * Build the theme-globals block for `src/global-types.ts`: the key union, a value-type map,
516
+ * and a type-safe `themeValue` wrapper (authors import it from `./global-types`). The wrapper
517
+ * is deliberately named differently from the SDK's `getThemeSettingValue` so authors can't
518
+ * accidentally import the untyped SDK version and lose key-safety (no shadowing).
519
+ * Returns "" when there are no globals (an empty union would resolve to `never`). The import
520
+ * the wrapper needs is emitted separately via {@link THEME_GLOBALS_IMPORT}.
521
+ */
522
+ function generateThemeGlobalsBlock(themeSettings, resolveEnumTypeName = () => null) {
523
+ if (!themeSettings || themeSettings.length === 0)
524
+ return "";
525
+ const sorted = [...themeSettings].sort((a, b) => a.name.localeCompare(b.name));
526
+ const unionLines = sorted
527
+ .map((s) => {
528
+ // Escape the JSDoc comment terminator to avoid prematurely closing the
529
+ // generated `/** ... */` block when a displayName contains `*/`.
530
+ const label = String(s.displayName).replace(/\*\//g, "*\\/");
531
+ return ` /** ${label} (${s.type}) */\n | ${JSON.stringify(s.name)}`;
532
+ })
533
+ .join("\n");
534
+ const mapLines = sorted
535
+ .map((s) => ` ${JSON.stringify(s.name)}: ${themeSettingTsType(s, resolveEnumTypeName)};`)
536
+ .join("\n");
537
+ return (`\n/** Stable keys of theme global variables defined in the editor's "Styles" panel. */\n` +
538
+ `export type ThemeSettingName =\n${unionLines};\n\n` +
539
+ `/** Narrowed value type per global key (primitives and ENUM unions; complex kinds are \`any\`). */\n` +
540
+ `type ThemeSettingValueMap = {\n${mapLines}\n};\n\n` +
541
+ `/**\n` +
542
+ ` * Type-safe theme global accessor — only accepts keys declared in the editor's Styles panel.\n` +
543
+ ` * Import this from \`./global-types\`, not \`getThemeSettingValue\` from \`@ikas/bp-storefront\`\n` +
544
+ ` * (that one is untyped: it accepts any string and returns \`any\`).\n` +
545
+ ` */\n` +
546
+ `export function themeValue<K extends ThemeSettingName>(name: K): ThemeSettingValueMap[K] {\n` +
547
+ ` return _getThemeSettingValueRaw(name) as ThemeSettingValueMap[K];\n` +
548
+ `}\n`);
549
+ }
301
550
  /**
302
551
  * Generate the content for `src/global-types.ts`.
303
552
  * Collects all custom enum types from editorTypes (preferred) or customTypes (fallback)
@@ -311,8 +560,11 @@ export function generateGlobalTypesFile(editorTypes, customTypes,
311
560
  * Callers should compute this from `config.components[*].props[*].enumTypeId`
312
561
  * so unused enums are excluded from `global-types.ts`.
313
562
  */
314
- usedEnumIds) {
563
+ usedEnumIds, themeSettings) {
315
564
  const header = `// Auto-generated global type definitions for ikas code components.\n// This file is regenerated automatically — do not edit manually.\n`;
565
+ // Enums an ENUM theme setting selects from are emitted regardless of `usedEnumIds`: the
566
+ // setting's value-map entry names them, so they must exist even if no prop uses them.
567
+ const forcedEnumIds = collectThemeSettingEnumIds(themeSettings);
316
568
  // Collect all custom enum types with their options
317
569
  // Use a Map keyed by type ID to deduplicate
318
570
  const enumTypes = new Map();
@@ -320,10 +572,10 @@ usedEnumIds) {
320
572
  if (editorTypes) {
321
573
  for (const t of editorTypes) {
322
574
  if (t.enumOptions && Object.keys(t.enumOptions).length > 0) {
323
- // Skip built-in types
324
- if (t.id.startsWith("@ikas/"))
575
+ // Skip built-in types (@ikas/* and the pattern-element font-style sentinel)
576
+ if (isBuiltInEnumTypeId(t.id))
325
577
  continue;
326
- if (usedEnumIds && !usedEnumIds.has(t.id))
578
+ if (usedEnumIds && !usedEnumIds.has(t.id) && !forcedEnumIds.has(t.id))
327
579
  continue;
328
580
  enumTypes.set(t.id, {
329
581
  name: toPascalCase(t.name),
@@ -339,9 +591,9 @@ usedEnumIds) {
339
591
  const id = t.id;
340
592
  if (enumTypes.has(id))
341
593
  continue;
342
- if (id.startsWith("@ikas/"))
594
+ if (isBuiltInEnumTypeId(id))
343
595
  continue;
344
- if (usedEnumIds && !usedEnumIds.has(id))
596
+ if (usedEnumIds && !usedEnumIds.has(id) && !forcedEnumIds.has(id))
345
597
  continue;
346
598
  if (t.enumOptions && Object.keys(t.enumOptions).length > 0) {
347
599
  enumTypes.set(id, {
@@ -352,17 +604,56 @@ usedEnumIds) {
352
604
  }
353
605
  }
354
606
  }
607
+ // The theme block may only name enum types declared in THIS file (see themeSettingTsType).
608
+ const resolveEnumTypeName = (enumTypeId) => enumTypes.get(enumTypeId)?.name ?? null;
609
+ const themeBlock = generateThemeGlobalsBlock(themeSettings, resolveEnumTypeName);
610
+ // The wrapper's runtime import must sit at the top of the file (after the header).
611
+ const themeImport = themeBlock ? THEME_GLOBALS_IMPORT : "";
355
612
  if (enumTypes.size === 0) {
356
- return `${header}// Custom enum types from the editor will appear here.\n\nexport {};\n`;
613
+ if (!themeBlock) {
614
+ return `${header}// Custom enum types from the editor will appear here.\n\nexport {};\n`;
615
+ }
616
+ return `${header}${themeImport}${themeBlock}`;
357
617
  }
358
618
  // Sort by type name for stable output
359
619
  const sorted = Array.from(enumTypes.values()).sort((a, b) => a.name.localeCompare(b.name));
360
- let content = `${header}\n`;
620
+ let content = `${header}${themeImport}\n`;
361
621
  for (const enumType of sorted) {
362
- const unionType = enumType.options.map(v => `"${v}"`).join(" | ");
622
+ const unionType = enumType.options.map((v) => `"${v}"`).join(" | ");
363
623
  content += `/** Enum type: ${enumType.id} */\nexport type ${enumType.name} = ${unionType};\n`;
364
624
  }
365
- return content;
625
+ return `${content}${themeBlock}`;
626
+ }
627
+ /**
628
+ * Decide whether freshly generated `global-types.ts` content should overwrite
629
+ * the existing file on disk.
630
+ *
631
+ * Guards the dev-server startup race: before the editor connects, the theme
632
+ * settings cache is empty, so the generated content omits the theme-globals
633
+ * block (`themeValue`, `ThemeSettingName`). Writing it would clobber the rich
634
+ * file left from the previous session and break every component that imports
635
+ * those exports until the editor reconnects and re-syncs. While theme settings
636
+ * are not yet cached, preserve an existing theme-globals block instead of
637
+ * stubbing it out — the editor's `onSyncTypes` is the authoritative writer once
638
+ * connected.
639
+ *
640
+ * @param existing current file content, or null if the file is absent
641
+ * @param next freshly generated content
642
+ * @param hasThemeSettingsCached whether the editor has synced theme settings yet
643
+ */
644
+ export function shouldWriteGlobalTypes(existing, next, hasThemeSettingsCached) {
645
+ // No file yet — always write so imports resolve.
646
+ if (existing === null)
647
+ return true;
648
+ // Identical content — skip to avoid file-watcher loops.
649
+ if (existing === next)
650
+ return false;
651
+ // Editor has synced theme settings — it's authoritative, write freely.
652
+ if (hasThemeSettingsCached)
653
+ return true;
654
+ // Not synced yet: write unless we'd drop an existing theme-globals block for a stub.
655
+ return (!existing.includes(THEME_GLOBALS_MARKER) ||
656
+ next.includes(THEME_GLOBALS_MARKER));
366
657
  }
367
658
  export function generateComponentFile(componentName, props, type) {
368
659
  const propsDestructure = props.map((p) => p.name).join(", ");
@@ -380,18 +671,136 @@ export function generateStylesFile(componentName, type) {
380
671
  return readTemplate(templateName, { KEBAB_NAME: kebabName });
381
672
  }
382
673
  /**
383
- * Update the barrel export file (src/components/index.ts) to include all components
674
+ * Update the barrel export file (src/components/index.ts) to include all components. Each is exported by its
675
+ * entry's folder, which is named after the function it exports when created; its name may change later.
384
676
  */
385
- export function updateBarrelExport(projectRoot, componentNames) {
677
+ export function updateBarrelExport(projectRoot, components) {
386
678
  const indexPath = path.resolve(projectRoot, "src/components/index.ts");
387
- const content = componentNames
388
- .map((name) => {
389
- const pascal = toPascalCase(name);
390
- return `export { ${pascal} } from "./${pascal}/index";`;
679
+ const content = components
680
+ .map((c) => {
681
+ const folder = path.basename(path.dirname(c.entry));
682
+ return `export { ${folder} } from "./${folder}/index";`;
391
683
  })
392
684
  .join("\n") + "\n";
393
685
  fs.writeFileSync(indexPath, content);
394
686
  }
687
+ /**
688
+ * A config visibility gate in wire form, or nothing at all — spread it.
689
+ *
690
+ * Config names the governing prop; the editor needs its id, and ids are minted here from position.
691
+ * A gate naming a prop this component does not have is dropped rather than passed on: the editor
692
+ * would show the control anyway, and a dangling id in the theme is worse than none.
693
+ */
694
+ export function resolveCondition(gate, propIdByName) {
695
+ if (!gate?.requiredProp)
696
+ return {};
697
+ const requiredPropId = propIdByName.get(gate.requiredProp);
698
+ if (!requiredPropId)
699
+ return {};
700
+ // An ENUM gate carries its option and no boolean state; a BOOLEAN one the reverse. Emitting only
701
+ // the half that applies keeps a stale option from a re-typed governing prop out of the theme.
702
+ if (gate.requiredEnumOptionValue !== undefined) {
703
+ return {
704
+ requiredPropId,
705
+ requiredEnumOptionId: gate.requiredEnumOptionId,
706
+ requiredEnumOptionValue: gate.requiredEnumOptionValue,
707
+ };
708
+ }
709
+ return { requiredPropId, requiredPropValue: gate.requiredPropValue ?? true };
710
+ }
711
+ /**
712
+ * Config prop name to the id this component's props are broadcast under.
713
+ *
714
+ * The formula is duplicated at each mapping site (dev broadcast, config rebuild, publish); this
715
+ * reads it back off whatever that site produced rather than restating it a fourth time.
716
+ */
717
+ export function propIdsByName(props) {
718
+ return new Map(props.map((prop) => [prop.name, prop.id]));
719
+ }
720
+ /**
721
+ * Sets a field, or removes it when emptied (a blank text, a map without entries, so the key leaves
722
+ * the config); a required field keeps its old value instead.
723
+ */
724
+ function setField(target, field, value, required = false) {
725
+ const fields = target;
726
+ const empty = !value || (typeof value === "object" && Object.keys(value).length === 0);
727
+ if (!empty)
728
+ fields[field] = value;
729
+ else if (!required)
730
+ delete fields[field];
731
+ }
732
+ /**
733
+ * Writes the technical texts the editor saved back onto a config component: the base fields and the
734
+ * editor-language `translations`. A store language's `propValues` on the component stay as they are,
735
+ * unless the editor sent its store content too (a component's, not a section's).
736
+ */
737
+ export function applyTechnicalTexts(component, texts) {
738
+ setField(component, "name", texts.name, true);
739
+ const locales = new Set([
740
+ ...Object.keys(component.translations || {}),
741
+ ...Object.keys(texts.translations),
742
+ ...Object.keys(texts.propValues || {}),
743
+ ]);
744
+ const translations = {};
745
+ locales.forEach((locale) => {
746
+ const { name: _name, propValues: configValues, ...rest } = component.translations?.[locale] || {};
747
+ const name = texts.translations[locale]?.name;
748
+ const propValues = texts.propValues
749
+ ? texts.propValues[locale]
750
+ : configValues;
751
+ const record = {
752
+ ...(name ? { name } : {}),
753
+ ...rest,
754
+ ...(propValues && Object.keys(propValues).length ? { propValues } : {}),
755
+ };
756
+ if (Object.keys(record).length > 0)
757
+ translations[locale] = record;
758
+ });
759
+ setField(component, "translations", translations);
760
+ const defaults = texts.defaults;
761
+ if (defaults)
762
+ component.props.forEach((prop) => {
763
+ if (!(prop.name in defaults))
764
+ return;
765
+ const value = defaults[prop.name];
766
+ if (value === null || value === undefined)
767
+ delete prop.defaultValue;
768
+ else
769
+ prop.defaultValue = value;
770
+ });
771
+ component.props.forEach((prop) => {
772
+ const text = texts.props[prop.name];
773
+ if (!text)
774
+ return;
775
+ setField(prop, "displayName", text.displayName, true);
776
+ setField(prop, "description", text.description);
777
+ setField(prop, "translations", text.translations);
778
+ });
779
+ // The editor knows a group by its global id; prop wrappers carry no texts of their own
780
+ (component.propGroups || [])
781
+ .flatMap((group) => [group, ...(group.children || [])])
782
+ .forEach((group) => {
783
+ const text = texts.propGroups[propGroupGlobalId(component.id, group.id)];
784
+ if (!text)
785
+ return;
786
+ setField(group, "name", text.name, true);
787
+ setField(group, "description", text.description);
788
+ setField(group, "translations", text.translations);
789
+ });
790
+ }
791
+ /**
792
+ * A config translation map (`{ en: { displayName: "Heading" } }`) as the editor's record list
793
+ * (`[{ locale: "en", displayName: "Heading" }]`); nothing for an empty or missing map, so the
794
+ * wire payload carries the key only when there is something to carry. Spread the result.
795
+ */
796
+ export function translationRecords(translations) {
797
+ const records = Object.entries(translations || {})
798
+ .filter(([, fields]) => fields && Object.keys(fields).length > 0)
799
+ .map(([locale, fields]) => ({ locale, ...fields }));
800
+ return records.length > 0 ? { translations: records } : {};
801
+ }
802
+ /** The editor's id of a config prop group: the component's id prefixed, so it is unique across components. */
803
+ export const propGroupGlobalId = (componentId, groupId) => `${componentId}_pg_${groupId}`;
395
804
  /**
396
805
  * Convert flat config-format prop groups into an IThemePropGroup[] hierarchy.
397
806
  *
@@ -405,11 +814,14 @@ export function updateBarrelExport(projectRoot, componentNames) {
405
814
  */
406
815
  export function buildPropGroupHierarchy(componentId, propGroups, props) {
407
816
  const result = [];
817
+ // A group names its governing prop; the leaf wrappers below carry no gate of their own, because a
818
+ // prop's gate travels on the prop itself (see `resolveCondition` at each prop mapping site).
819
+ const propIdByName = propIdsByName(props);
408
820
  for (const group of propGroups) {
409
- const groupGlobalId = `${componentId}_pg_${group.id}`;
821
+ const groupGlobalId = propGroupGlobalId(componentId, group.id);
410
822
  // Collect props assigned to this group
411
- const groupProps = props.filter(p => p.groupId === group.id);
412
- const propChildren = groupProps.map(p => ({
823
+ const groupProps = props.filter((p) => p.groupId === group.id);
824
+ const propChildren = groupProps.map((p) => ({
413
825
  id: `${componentId}_pgp_${p.id}`,
414
826
  propId: p.id,
415
827
  }));
@@ -417,10 +829,10 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
417
829
  let nestedChildren = [];
418
830
  if (group.children) {
419
831
  for (const child of group.children) {
420
- const childGlobalId = `${componentId}_pg_${child.id}`;
832
+ const childGlobalId = propGroupGlobalId(componentId, child.id);
421
833
  // Collect props assigned to this child group
422
- const childProps = props.filter(p => p.groupId === child.id);
423
- const childPropChildren = childProps.map(p => ({
834
+ const childProps = props.filter((p) => p.groupId === child.id);
835
+ const childPropChildren = childProps.map((p) => ({
424
836
  id: `${componentId}_pgp_${p.id}`,
425
837
  propId: p.id,
426
838
  }));
@@ -428,7 +840,11 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
428
840
  id: childGlobalId,
429
841
  name: child.name,
430
842
  ...(child.description ? { description: child.description } : {}),
431
- ...(childPropChildren.length > 0 ? { children: childPropChildren } : {}),
843
+ ...translationRecords(child.translations),
844
+ ...resolveCondition(child, propIdByName),
845
+ ...(childPropChildren.length > 0
846
+ ? { children: childPropChildren }
847
+ : {}),
432
848
  });
433
849
  }
434
850
  }
@@ -437,19 +853,118 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
437
853
  id: groupGlobalId,
438
854
  name: group.name,
439
855
  ...(group.description ? { description: group.description } : {}),
856
+ ...translationRecords(group.translations),
857
+ ...resolveCondition(group, propIdByName),
440
858
  ...(allChildren.length > 0 ? { children: allChildren } : {}),
441
859
  });
442
860
  }
443
861
  return result;
444
862
  }
863
+ /** Every group id under `group`, itself included — the groups a prop assigned "inside" it can sit in. */
864
+ export function groupIdsUnder(group) {
865
+ return new Set([
866
+ group.id,
867
+ ...(group.children || []).map((child) => child.id),
868
+ ]);
869
+ }
870
+ /**
871
+ * Validate a visibility condition — the `requiredProp` family on a prop or a prop group — against
872
+ * the component it lives on. Returns an error message, or null when it is sound (or absent).
873
+ *
874
+ * What is rejected, and why each one would otherwise strand a control with no way to reach it:
875
+ *
876
+ * - a name no prop on this component has, or a prop that is not BOOLEAN — nothing to read a
877
+ * true/false off, so the gate could never resolve;
878
+ * - a prop gating itself, or a chain of props that comes back around to it — every prop in the
879
+ * cycle stays hidden forever, including the toggles that would let someone out of it;
880
+ * - an ENUM gate with no option to wait for, or an option value hung on a BOOLEAN prop;
881
+ * - a group gated by a toggle that lives inside it — turning that toggle off takes the toggle away
882
+ * with the rest of the group.
883
+ */
884
+ export function visibilityGateError(component, gate, where, opts = {}) {
885
+ const { requiredProp, requiredPropValue, requiredEnumOptionValue } = gate;
886
+ if (requiredProp === undefined || requiredProp === null) {
887
+ return requiredPropValue === undefined &&
888
+ requiredEnumOptionValue === undefined
889
+ ? null
890
+ : `${where} declares a visibility state with no requiredProp to read it off. Name the prop that gates it, or drop both.`;
891
+ }
892
+ if (typeof requiredProp !== "string" || !requiredProp) {
893
+ return `requiredProp on ${where} must be the name of a BOOLEAN or ENUM prop on this component.`;
894
+ }
895
+ if (requiredPropValue !== undefined &&
896
+ typeof requiredPropValue !== "boolean") {
897
+ return `requiredPropValue on ${where} must be true or false (it defaults to true).`;
898
+ }
899
+ if (opts.selfPropName && requiredProp === opts.selfPropName) {
900
+ return `${where} cannot gate itself on "${requiredProp}".`;
901
+ }
902
+ const governing = component.props.find((prop) => prop.name === requiredProp);
903
+ if (!governing) {
904
+ const names = component.props.map((prop) => prop.name).join(", ");
905
+ return `requiredProp "${requiredProp}" on ${where} is not a prop of component "${component.name}". Available props: ${names || "(none)"}.`;
906
+ }
907
+ if (governing.type !== "BOOLEAN" && governing.type !== "ENUM") {
908
+ return `requiredProp "${requiredProp}" on ${where} is a ${governing.type} prop; only a BOOLEAN or ENUM prop can gate visibility.`;
909
+ }
910
+ // An ENUM gate is meaningless without the option it waits for: nothing would ever match it, so
911
+ // the node would never appear at all.
912
+ if (governing.type === "ENUM" &&
913
+ typeof requiredEnumOptionValue !== "string") {
914
+ return `requiredProp "${requiredProp}" on ${where} is an ENUM prop, so requiredEnumOptionValue must name the option value that shows it.`;
915
+ }
916
+ if (governing.type === "BOOLEAN" && requiredEnumOptionValue !== undefined) {
917
+ return `requiredEnumOptionValue on ${where} has no meaning against the BOOLEAN prop "${requiredProp}" — use requiredPropValue instead.`;
918
+ }
919
+ if (opts.group &&
920
+ governing.groupId &&
921
+ groupIdsUnder(opts.group).has(governing.groupId)) {
922
+ return `requiredProp "${requiredProp}" on ${where} sits inside that group — hiding the group would take that control with it, leaving nothing to bring it back.`;
923
+ }
924
+ // Walk the chain the governing prop hangs on. It cannot come back to this prop, and it cannot
925
+ // close on itself either — a cycle anywhere in it hides everything on it.
926
+ const byName = new Map(component.props.map((prop) => [prop.name, prop]));
927
+ const seen = new Set([requiredProp]);
928
+ let current = governing.requiredProp;
929
+ while (current) {
930
+ if (opts.selfPropName && current === opts.selfPropName) {
931
+ return `requiredProp "${requiredProp}" on ${where} depends on it in turn — the two would hide each other permanently.`;
932
+ }
933
+ if (seen.has(current)) {
934
+ return `requiredProp "${requiredProp}" on ${where} sits in a visibility cycle through "${current}" — everything on it would stay hidden.`;
935
+ }
936
+ seen.add(current);
937
+ current = byName.get(current)?.requiredProp;
938
+ }
939
+ return null;
940
+ }
445
941
  /**
446
942
  * Validate prop groups configuration for a component.
447
943
  * Returns an array of error messages (empty = valid).
448
944
  */
449
945
  export function validatePropGroups(component) {
450
946
  const errors = [];
451
- const propGroups = component.propGroups;
452
- if (!propGroups || propGroups.length === 0)
947
+ const propGroups = component.propGroups || [];
948
+ // A prop can name a visibility gate whether or not this component has groups at all, so gates are
949
+ // checked before the group walk bails out below.
950
+ for (const prop of component.props) {
951
+ const error = visibilityGateError(component, prop, `prop "${prop.name}"`, {
952
+ selfPropName: prop.name,
953
+ });
954
+ if (error)
955
+ errors.push(error);
956
+ }
957
+ for (const group of [
958
+ ...propGroups,
959
+ ...propGroups.flatMap((group) => group.children || []),
960
+ ]) {
961
+ const error = visibilityGateError(component, group, `group "${group.id}"`, {
962
+ group,
963
+ });
964
+ if (error)
965
+ errors.push(error);
966
+ }
967
+ if (propGroups.length === 0)
453
968
  return errors;
454
969
  // Collect all group IDs and check uniqueness
455
970
  const allIds = new Set();
@@ -528,7 +1043,9 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
528
1043
  const found = findPropGroup(propGroups, propGroupId);
529
1044
  if (!found)
530
1045
  throw new Error(`Prop group "${propGroupId}" not found`);
531
- if (parentGroupId && found.group.children && found.group.children.length > 0) {
1046
+ if (parentGroupId &&
1047
+ found.group.children &&
1048
+ found.group.children.length > 0) {
532
1049
  throw new Error(`Cannot nest "${propGroupId}": it already has child groups`);
533
1050
  }
534
1051
  if (parentGroupId) {
@@ -542,10 +1059,10 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
542
1059
  }
543
1060
  let roots = propGroups;
544
1061
  if (found.parent) {
545
- found.parent.children = (found.parent.children || []).filter(c => c.id !== propGroupId);
1062
+ found.parent.children = (found.parent.children || []).filter((c) => c.id !== propGroupId);
546
1063
  }
547
1064
  else {
548
- roots = roots.filter(g => g.id !== propGroupId);
1065
+ roots = roots.filter((g) => g.id !== propGroupId);
549
1066
  }
550
1067
  if (parentGroupId) {
551
1068
  const target = findPropGroup(roots, parentGroupId);
@@ -553,13 +1070,17 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
553
1070
  throw new Error(`Target parent group "${parentGroupId}" not found after removal`);
554
1071
  if (!target.group.children)
555
1072
  target.group.children = [];
556
- const insertAt = typeof index === "number" && index >= 0 && index <= target.group.children.length
1073
+ const insertAt = typeof index === "number" &&
1074
+ index >= 0 &&
1075
+ index <= target.group.children.length
557
1076
  ? index
558
1077
  : target.group.children.length;
559
1078
  target.group.children.splice(insertAt, 0, found.group);
560
1079
  }
561
1080
  else {
562
- const insertAt = typeof index === "number" && index >= 0 && index <= roots.length ? index : roots.length;
1081
+ const insertAt = typeof index === "number" && index >= 0 && index <= roots.length
1082
+ ? index
1083
+ : roots.length;
563
1084
  roots.splice(insertAt, 0, found.group);
564
1085
  }
565
1086
  return roots;