@ikas/component-cli 1.4.0-beta.20 → 1.4.0-beta.201
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-tools.d.ts +37 -0
- package/dist/build-tools.d.ts.map +1 -0
- package/dist/build-tools.js +36 -0
- package/dist/build-tools.js.map +1 -0
- package/dist/commands/add-sections-to-page.d.ts +3 -0
- package/dist/commands/add-sections-to-page.d.ts.map +1 -0
- package/dist/commands/add-sections-to-page.js +39 -0
- package/dist/commands/add-sections-to-page.js.map +1 -0
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +11 -2
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +5 -165
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/config.d.ts +35 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +1082 -147
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/create-design-tokens.d.ts +24 -0
- package/dist/commands/create-design-tokens.d.ts.map +1 -0
- package/dist/commands/create-design-tokens.js +327 -0
- package/dist/commands/create-design-tokens.js.map +1 -0
- package/dist/commands/create-global-variable.d.ts +3 -0
- package/dist/commands/create-global-variable.d.ts.map +1 -0
- package/dist/commands/create-global-variable.js +73 -0
- package/dist/commands/create-global-variable.js.map +1 -0
- package/dist/commands/create-page.d.ts +3 -0
- package/dist/commands/create-page.d.ts.map +1 -0
- package/dist/commands/create-page.js +31 -0
- package/dist/commands/create-page.js.map +1 -0
- package/dist/commands/delete-page.d.ts +3 -0
- package/dist/commands/delete-page.d.ts.map +1 -0
- package/dist/commands/delete-page.js +28 -0
- package/dist/commands/delete-page.js.map +1 -0
- package/dist/commands/delete-theme-globals.d.ts +4 -0
- package/dist/commands/delete-theme-globals.d.ts.map +1 -0
- package/dist/commands/delete-theme-globals.js +48 -0
- package/dist/commands/delete-theme-globals.js.map +1 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +170 -31
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/enable-builtin-pages.d.ts +3 -0
- package/dist/commands/enable-builtin-pages.d.ts.map +1 -0
- package/dist/commands/enable-builtin-pages.js +27 -0
- package/dist/commands/enable-builtin-pages.js.map +1 -0
- package/dist/commands/get-component-props.d.ts +3 -0
- package/dist/commands/get-component-props.d.ts.map +1 -0
- package/dist/commands/get-component-props.js +32 -0
- package/dist/commands/get-component-props.js.map +1 -0
- package/dist/commands/get-page-by-type.d.ts +3 -0
- package/dist/commands/get-page-by-type.d.ts.map +1 -0
- package/dist/commands/get-page-by-type.js +25 -0
- package/dist/commands/get-page-by-type.js.map +1 -0
- package/dist/commands/get-section-values.d.ts +3 -0
- package/dist/commands/get-section-values.d.ts.map +1 -0
- package/dist/commands/get-section-values.js +39 -0
- package/dist/commands/get-section-values.js.map +1 -0
- package/dist/commands/list-builtin-pages.d.ts +3 -0
- package/dist/commands/list-builtin-pages.d.ts.map +1 -0
- package/dist/commands/list-builtin-pages.js +28 -0
- package/dist/commands/list-builtin-pages.js.map +1 -0
- package/dist/commands/list-entities.d.ts +3 -0
- package/dist/commands/list-entities.d.ts.map +1 -0
- package/dist/commands/list-entities.js +32 -0
- package/dist/commands/list-entities.js.map +1 -0
- package/dist/commands/list-page-sections.d.ts.map +1 -1
- package/dist/commands/list-page-sections.js +8 -2
- package/dist/commands/list-page-sections.js.map +1 -1
- package/dist/commands/list-theme-globals.d.ts +3 -0
- package/dist/commands/list-theme-globals.d.ts.map +1 -0
- package/dist/commands/list-theme-globals.js +22 -0
- package/dist/commands/list-theme-globals.js.map +1 -0
- package/dist/commands/move-page-section.d.ts +3 -0
- package/dist/commands/move-page-section.d.ts.map +1 -0
- package/dist/commands/move-page-section.js +62 -0
- package/dist/commands/move-page-section.js.map +1 -0
- package/dist/commands/publish-theme.d.ts +3 -0
- package/dist/commands/publish-theme.d.ts.map +1 -0
- package/dist/commands/publish-theme.js +29 -0
- package/dist/commands/publish-theme.js.map +1 -0
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +54 -3
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/remove-page-section.d.ts +3 -0
- package/dist/commands/remove-page-section.d.ts.map +1 -0
- package/dist/commands/remove-page-section.js +40 -0
- package/dist/commands/remove-page-section.js.map +1 -0
- package/dist/commands/search-products.d.ts +3 -0
- package/dist/commands/search-products.d.ts.map +1 -0
- package/dist/commands/search-products.js +40 -0
- package/dist/commands/search-products.js.map +1 -0
- package/dist/commands/update-builtin-page-prop.d.ts +3 -0
- package/dist/commands/update-builtin-page-prop.d.ts.map +1 -0
- package/dist/commands/update-builtin-page-prop.js +49 -0
- package/dist/commands/update-builtin-page-prop.js.map +1 -0
- package/dist/commands/update-global-variable.d.ts +3 -0
- package/dist/commands/update-global-variable.d.ts.map +1 -0
- package/dist/commands/update-global-variable.js +70 -0
- package/dist/commands/update-global-variable.js.map +1 -0
- package/dist/commands/update-page-sections.d.ts +3 -0
- package/dist/commands/update-page-sections.d.ts.map +1 -0
- package/dist/commands/update-page-sections.js +39 -0
- package/dist/commands/update-page-sections.js.map +1 -0
- package/dist/commands/update-section-prop.d.ts.map +1 -1
- package/dist/commands/update-section-prop.js +25 -8
- package/dist/commands/update-section-prop.js.map +1 -1
- package/dist/commands/upload-image.d.ts.map +1 -1
- package/dist/commands/upload-image.js +5 -46
- package/dist/commands/upload-image.js.map +1 -1
- package/dist/commands/upload-images.d.ts +3 -0
- package/dist/commands/upload-images.d.ts.map +1 -0
- package/dist/commands/upload-images.js +48 -0
- package/dist/commands/upload-images.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/compile.d.ts +17 -2
- package/dist/utils/compile.d.ts.map +1 -1
- package/dist/utils/compile.js +750 -117
- package/dist/utils/compile.js.map +1 -1
- package/dist/utils/component-helpers.d.ts +145 -2
- package/dist/utils/component-helpers.d.ts.map +1 -1
- package/dist/utils/component-helpers.js +397 -29
- package/dist/utils/component-helpers.js.map +1 -1
- package/dist/utils/css-import-resolver.d.ts +4 -1
- package/dist/utils/css-import-resolver.d.ts.map +1 -1
- package/dist/utils/css-import-resolver.js +9 -1
- package/dist/utils/css-import-resolver.js.map +1 -1
- package/dist/utils/editor-action-client.d.ts +4 -3
- package/dist/utils/editor-action-client.d.ts.map +1 -1
- package/dist/utils/editor-action-client.js +55 -19
- package/dist/utils/editor-action-client.js.map +1 -1
- package/dist/utils/esm-transform.d.ts +30 -0
- package/dist/utils/esm-transform.d.ts.map +1 -1
- package/dist/utils/esm-transform.js +169 -2
- package/dist/utils/esm-transform.js.map +1 -1
- package/dist/utils/find-component-for-file.d.ts +12 -0
- package/dist/utils/find-component-for-file.d.ts.map +1 -0
- package/dist/utils/find-component-for-file.js +24 -0
- package/dist/utils/find-component-for-file.js.map +1 -0
- package/dist/utils/forbid-deep-imports.d.ts +3 -0
- package/dist/utils/forbid-deep-imports.d.ts.map +1 -0
- package/dist/utils/forbid-deep-imports.js +54 -0
- package/dist/utils/forbid-deep-imports.js.map +1 -0
- package/dist/utils/forbid-external-packages.d.ts +26 -0
- package/dist/utils/forbid-external-packages.d.ts.map +1 -0
- package/dist/utils/forbid-external-packages.js +99 -0
- package/dist/utils/forbid-external-packages.js.map +1 -0
- package/dist/utils/load-image.d.ts +16 -0
- package/dist/utils/load-image.d.ts.map +1 -0
- package/dist/utils/load-image.js +50 -0
- package/dist/utils/load-image.js.map +1 -0
- package/dist/utils/vendor-storefront.d.ts +13 -0
- package/dist/utils/vendor-storefront.d.ts.map +1 -0
- package/dist/utils/vendor-storefront.js +91 -0
- package/dist/utils/vendor-storefront.js.map +1 -0
- package/dist/utils/websocket-server.d.ts +88 -5
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js +241 -44
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +17 -2
- package/templates/add/section.css +11 -0
- package/dist/commands/create.d.ts +0 -4
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js +0 -228
- package/dist/commands/create.js.map +0 -1
- package/dist/commands/proxy.d.ts +0 -39
- package/dist/commands/proxy.d.ts.map +0 -1
- package/dist/commands/proxy.js +0 -210
- package/dist/commands/proxy.js.map +0 -1
|
@@ -35,6 +35,40 @@ 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
|
+
export function findInvalidComponentIds(components) {
|
|
70
|
+
return components.filter((c) => !COMPONENT_ID_PATTERN.test(c.id));
|
|
71
|
+
}
|
|
38
72
|
/**
|
|
39
73
|
* Validate that every entry in `input` is the id of a component currently in `components`.
|
|
40
74
|
* Returns the list of unknown entries (empty array means all valid).
|
|
@@ -96,8 +130,8 @@ export const PROP_TYPE_TO_TS = {
|
|
|
96
130
|
COLOR: "string",
|
|
97
131
|
PRODUCT: "IkasProduct | null",
|
|
98
132
|
PRODUCT_LIST: "IkasProductList",
|
|
99
|
-
PRODUCT_ATTRIBUTE: "
|
|
100
|
-
PRODUCT_ATTRIBUTE_LIST: "
|
|
133
|
+
PRODUCT_ATTRIBUTE: "IkasProductAttributeDetail | null",
|
|
134
|
+
PRODUCT_ATTRIBUTE_LIST: "IkasProductAttributeList",
|
|
101
135
|
CATEGORY: "IkasCategory | null",
|
|
102
136
|
CATEGORY_LIST: "IkasCategoryList",
|
|
103
137
|
BRAND: "IkasBrand | null",
|
|
@@ -111,6 +145,58 @@ export const PROP_TYPE_TO_TS = {
|
|
|
111
145
|
COMPONENT: "any",
|
|
112
146
|
COMPONENT_LIST: "any",
|
|
113
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* Pattern-element ("Font Style" / typography) enum sentinel. The editor builds
|
|
150
|
+
* this synthetic enum at theme time (createPatternElementEnum). Mirror of
|
|
151
|
+
* PATTERN_ELEMENT_ENUM_ID in @ikas/editor-models — kept local to avoid an
|
|
152
|
+
* editor-models dependency in the CLI.
|
|
153
|
+
*/
|
|
154
|
+
export const PATTERN_ELEMENT_ENUM_ID = "__patternElementEnum__";
|
|
155
|
+
/**
|
|
156
|
+
* Built-in enum type ids do not need to exist in config.customTypes: @ikas/*
|
|
157
|
+
* enums ship with the storefront models, and the pattern-element sentinel is
|
|
158
|
+
* resolved by the editor at theme time. Author-defined enums are NOT built-in.
|
|
159
|
+
*/
|
|
160
|
+
export function isBuiltInEnumTypeId(enumTypeId) {
|
|
161
|
+
return (enumTypeId.startsWith("@ikas/") || enumTypeId === PATTERN_ELEMENT_ENUM_ID);
|
|
162
|
+
}
|
|
163
|
+
const ENUM_OPTIONS_EXAMPLE = `'{"Small":"sm","Medium":"md"}' or '[{"name":"Small","value":"sm"}]'`;
|
|
164
|
+
/**
|
|
165
|
+
* The parsed `--options` of `config add-enum` / `config update-enum`, as the `{ "Label": "value" }`
|
|
166
|
+
* record an enum stores. The object form passes through unchanged. The array form
|
|
167
|
+
* `[{ "name": "Label", "value": "value" }]` (`label` is accepted for `name`) — which older project
|
|
168
|
+
* docs showed and agents still produce — is converted, with values stringified like every enum value.
|
|
169
|
+
*/
|
|
170
|
+
export function normalizeEnumOptionsInput(input) {
|
|
171
|
+
if (Array.isArray(input)) {
|
|
172
|
+
const options = {};
|
|
173
|
+
for (const item of input) {
|
|
174
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
175
|
+
return { error: `Each option in the array must be an object { "name", "value" }, e.g. ${ENUM_OPTIONS_EXAMPLE}.` };
|
|
176
|
+
}
|
|
177
|
+
const { name, label, value } = item;
|
|
178
|
+
const optionLabel = name ?? label;
|
|
179
|
+
if (typeof optionLabel !== "string" || !optionLabel.trim()) {
|
|
180
|
+
return { error: `Every option needs a non-empty string "name", e.g. ${ENUM_OPTIONS_EXAMPLE}.` };
|
|
181
|
+
}
|
|
182
|
+
if ((typeof value !== "string" && typeof value !== "number") || String(value).trim() === "") {
|
|
183
|
+
return { error: `Option "${optionLabel}" needs a non-empty string "value", e.g. ${ENUM_OPTIONS_EXAMPLE}.` };
|
|
184
|
+
}
|
|
185
|
+
if (Object.prototype.hasOwnProperty.call(options, optionLabel)) {
|
|
186
|
+
return { error: `Duplicate option name "${optionLabel}".` };
|
|
187
|
+
}
|
|
188
|
+
options[optionLabel] = String(value);
|
|
189
|
+
}
|
|
190
|
+
if (Object.keys(options).length === 0) {
|
|
191
|
+
return { error: `Options must not be empty, e.g. ${ENUM_OPTIONS_EXAMPLE}.` };
|
|
192
|
+
}
|
|
193
|
+
return { options };
|
|
194
|
+
}
|
|
195
|
+
if (input && typeof input === "object" && Object.keys(input).length > 0) {
|
|
196
|
+
return { options: input };
|
|
197
|
+
}
|
|
198
|
+
return { error: `Options must be a non-empty JSON object or array, e.g. ${ENUM_OPTIONS_EXAMPLE}.` };
|
|
199
|
+
}
|
|
114
200
|
export function toKebabCase(str) {
|
|
115
201
|
return str
|
|
116
202
|
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
@@ -149,14 +235,16 @@ function resolveTypeId(typeId) {
|
|
|
149
235
|
*/
|
|
150
236
|
function resolveCustomEnumTypeName(enumTypeId, editorTypes, customTypes) {
|
|
151
237
|
if (editorTypes) {
|
|
152
|
-
const editorType = editorTypes.find(t => t.id === enumTypeId);
|
|
153
|
-
if (editorType?.enumOptions &&
|
|
238
|
+
const editorType = editorTypes.find((t) => t.id === enumTypeId);
|
|
239
|
+
if (editorType?.enumOptions &&
|
|
240
|
+
Object.keys(editorType.enumOptions).length > 0) {
|
|
154
241
|
return toPascalCase(editorType.name);
|
|
155
242
|
}
|
|
156
243
|
}
|
|
157
244
|
if (customTypes) {
|
|
158
|
-
const customType = customTypes.find(t => t.id === enumTypeId);
|
|
159
|
-
if (customType?.enumOptions &&
|
|
245
|
+
const customType = customTypes.find((t) => t.id === enumTypeId);
|
|
246
|
+
if (customType?.enumOptions &&
|
|
247
|
+
Object.keys(customType.enumOptions).length > 0) {
|
|
160
248
|
return toPascalCase(customType.name);
|
|
161
249
|
}
|
|
162
250
|
}
|
|
@@ -176,7 +264,9 @@ export function generateTypesFile(componentName, props, type, editorTypes, custo
|
|
|
176
264
|
typeIdResolved.set(prop.name, resolved.isArray ? `${resolved.typeName}[]` : resolved.typeName);
|
|
177
265
|
}
|
|
178
266
|
}
|
|
179
|
-
else if (prop.type === "ENUM" &&
|
|
267
|
+
else if (prop.type === "ENUM" &&
|
|
268
|
+
prop.enumTypeId &&
|
|
269
|
+
prop.enumTypeId !== PATTERN_ELEMENT_ENUM_ID) {
|
|
180
270
|
const resolved = resolveTypeId(prop.enumTypeId);
|
|
181
271
|
if (resolved) {
|
|
182
272
|
// Built-in enum — import from @ikas/bp-storefront
|
|
@@ -193,6 +283,9 @@ export function generateTypesFile(componentName, props, type, editorTypes, custo
|
|
|
193
283
|
}
|
|
194
284
|
}
|
|
195
285
|
else {
|
|
286
|
+
// Non-ENUM props, plus the font-style (pattern-element) sentinel whose
|
|
287
|
+
// runtime value is a plain pattern-element id string → PROP_TYPE_TO_TS
|
|
288
|
+
// (PROP_TYPE_TO_TS["ENUM"] === "string"), no import emitted.
|
|
196
289
|
const tsType = PROP_TYPE_TO_TS[prop.type];
|
|
197
290
|
if (tsType?.includes("Ikas")) {
|
|
198
291
|
const matches = tsType.match(/Ikas\w+/g);
|
|
@@ -298,6 +391,96 @@ export function collectUsedCustomTypeIds(customTypes, components) {
|
|
|
298
391
|
}
|
|
299
392
|
return used;
|
|
300
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Enum ids referenced by ENUM theme settings. Their union types must be emitted into
|
|
396
|
+
* `global-types.ts` even when no component prop uses the enum, so the setting's value-map
|
|
397
|
+
* entry (and `themeValue()`) can narrow to it.
|
|
398
|
+
*/
|
|
399
|
+
export function collectThemeSettingEnumIds(themeSettings) {
|
|
400
|
+
const ids = new Set();
|
|
401
|
+
for (const s of themeSettings || []) {
|
|
402
|
+
if (s.type === "ENUM" && s.enumTypeId)
|
|
403
|
+
ids.add(s.enumTypeId);
|
|
404
|
+
}
|
|
405
|
+
return ids;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Map a global-variable kind to a TS type. Primitives narrowed; complex kinds stay `any`. An
|
|
409
|
+
* ENUM setting narrows to the union type THIS file declares for its enum: `resolveEnumTypeName`
|
|
410
|
+
* only knows the enums emitted above the theme block, so the map can never name an undeclared
|
|
411
|
+
* identifier. An ENUM whose enum is not emitted here — a deleted type, or a built-in `@ikas/*`
|
|
412
|
+
* enum (which the editor does not accept for a theme global, and whose import from
|
|
413
|
+
* `@ikas/bp-storefront` this generator cannot verify) — degrades to `string`.
|
|
414
|
+
*/
|
|
415
|
+
function themeSettingTsType(setting, resolveEnumTypeName) {
|
|
416
|
+
switch (setting.type) {
|
|
417
|
+
case "NUMBER":
|
|
418
|
+
return "number";
|
|
419
|
+
case "BOOLEAN":
|
|
420
|
+
return "boolean";
|
|
421
|
+
case "TEXT":
|
|
422
|
+
case "RICH_TEXT":
|
|
423
|
+
case "COLOR":
|
|
424
|
+
return "string";
|
|
425
|
+
case "ENUM":
|
|
426
|
+
return ((setting.enumTypeId && resolveEnumTypeName(setting.enumTypeId)) ||
|
|
427
|
+
"string");
|
|
428
|
+
default:
|
|
429
|
+
return "any"; // IMAGE, BORDER, SHADOW — object shapes can drift from runtime
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Import line for the typed theme-globals wrapper. Must sit at the top of the generated
|
|
434
|
+
* file (after the header). Emitted only when there are theme globals.
|
|
435
|
+
*
|
|
436
|
+
* A module augmentation can't deliver key-safety here: the runtime `getThemeSettingValue`
|
|
437
|
+
* is declared `(name: string): any`, so an added narrower overload never wins resolution —
|
|
438
|
+
* unknown keys still match `string` and return `any`. A generated wrapper whose parameter
|
|
439
|
+
* is `ThemeSettingName` (no `string` overload) does reject unknown keys and narrow the value.
|
|
440
|
+
*/
|
|
441
|
+
const THEME_GLOBALS_IMPORT = `import { getThemeSettingValue as _getThemeSettingValueRaw } from "@ikas/bp-storefront";\n`;
|
|
442
|
+
/**
|
|
443
|
+
* Sentinel that marks a generated `global-types.ts` as containing the theme-globals block.
|
|
444
|
+
* This is the exported symbol authors import (stable public API), and it must stay a substring
|
|
445
|
+
* of what {@link generateThemeGlobalsBlock} emits — keep the two in sync if that output changes.
|
|
446
|
+
*/
|
|
447
|
+
const THEME_GLOBALS_MARKER = "export type ThemeSettingName";
|
|
448
|
+
/**
|
|
449
|
+
* Build the theme-globals block for `src/global-types.ts`: the key union, a value-type map,
|
|
450
|
+
* and a type-safe `themeValue` wrapper (authors import it from `./global-types`). The wrapper
|
|
451
|
+
* is deliberately named differently from the SDK's `getThemeSettingValue` so authors can't
|
|
452
|
+
* accidentally import the untyped SDK version and lose key-safety (no shadowing).
|
|
453
|
+
* Returns "" when there are no globals (an empty union would resolve to `never`). The import
|
|
454
|
+
* the wrapper needs is emitted separately via {@link THEME_GLOBALS_IMPORT}.
|
|
455
|
+
*/
|
|
456
|
+
function generateThemeGlobalsBlock(themeSettings, resolveEnumTypeName = () => null) {
|
|
457
|
+
if (!themeSettings || themeSettings.length === 0)
|
|
458
|
+
return "";
|
|
459
|
+
const sorted = [...themeSettings].sort((a, b) => a.name.localeCompare(b.name));
|
|
460
|
+
const unionLines = sorted
|
|
461
|
+
.map((s) => {
|
|
462
|
+
// Escape the JSDoc comment terminator to avoid prematurely closing the
|
|
463
|
+
// generated `/** ... */` block when a displayName contains `*/`.
|
|
464
|
+
const label = String(s.displayName).replace(/\*\//g, "*\\/");
|
|
465
|
+
return ` /** ${label} (${s.type}) */\n | ${JSON.stringify(s.name)}`;
|
|
466
|
+
})
|
|
467
|
+
.join("\n");
|
|
468
|
+
const mapLines = sorted
|
|
469
|
+
.map((s) => ` ${JSON.stringify(s.name)}: ${themeSettingTsType(s, resolveEnumTypeName)};`)
|
|
470
|
+
.join("\n");
|
|
471
|
+
return (`\n/** Stable keys of theme global variables defined in the editor's "Styles" panel. */\n` +
|
|
472
|
+
`export type ThemeSettingName =\n${unionLines};\n\n` +
|
|
473
|
+
`/** Narrowed value type per global key (primitives and ENUM unions; complex kinds are \`any\`). */\n` +
|
|
474
|
+
`type ThemeSettingValueMap = {\n${mapLines}\n};\n\n` +
|
|
475
|
+
`/**\n` +
|
|
476
|
+
` * Type-safe theme global accessor — only accepts keys declared in the editor's Styles panel.\n` +
|
|
477
|
+
` * Import this from \`./global-types\`, not \`getThemeSettingValue\` from \`@ikas/bp-storefront\`\n` +
|
|
478
|
+
` * (that one is untyped: it accepts any string and returns \`any\`).\n` +
|
|
479
|
+
` */\n` +
|
|
480
|
+
`export function themeValue<K extends ThemeSettingName>(name: K): ThemeSettingValueMap[K] {\n` +
|
|
481
|
+
` return _getThemeSettingValueRaw(name) as ThemeSettingValueMap[K];\n` +
|
|
482
|
+
`}\n`);
|
|
483
|
+
}
|
|
301
484
|
/**
|
|
302
485
|
* Generate the content for `src/global-types.ts`.
|
|
303
486
|
* Collects all custom enum types from editorTypes (preferred) or customTypes (fallback)
|
|
@@ -311,8 +494,11 @@ export function generateGlobalTypesFile(editorTypes, customTypes,
|
|
|
311
494
|
* Callers should compute this from `config.components[*].props[*].enumTypeId`
|
|
312
495
|
* so unused enums are excluded from `global-types.ts`.
|
|
313
496
|
*/
|
|
314
|
-
usedEnumIds) {
|
|
497
|
+
usedEnumIds, themeSettings) {
|
|
315
498
|
const header = `// Auto-generated global type definitions for ikas code components.\n// This file is regenerated automatically — do not edit manually.\n`;
|
|
499
|
+
// Enums an ENUM theme setting selects from are emitted regardless of `usedEnumIds`: the
|
|
500
|
+
// setting's value-map entry names them, so they must exist even if no prop uses them.
|
|
501
|
+
const forcedEnumIds = collectThemeSettingEnumIds(themeSettings);
|
|
316
502
|
// Collect all custom enum types with their options
|
|
317
503
|
// Use a Map keyed by type ID to deduplicate
|
|
318
504
|
const enumTypes = new Map();
|
|
@@ -320,10 +506,10 @@ usedEnumIds) {
|
|
|
320
506
|
if (editorTypes) {
|
|
321
507
|
for (const t of editorTypes) {
|
|
322
508
|
if (t.enumOptions && Object.keys(t.enumOptions).length > 0) {
|
|
323
|
-
// Skip built-in types
|
|
324
|
-
if (t.id
|
|
509
|
+
// Skip built-in types (@ikas/* and the pattern-element font-style sentinel)
|
|
510
|
+
if (isBuiltInEnumTypeId(t.id))
|
|
325
511
|
continue;
|
|
326
|
-
if (usedEnumIds && !usedEnumIds.has(t.id))
|
|
512
|
+
if (usedEnumIds && !usedEnumIds.has(t.id) && !forcedEnumIds.has(t.id))
|
|
327
513
|
continue;
|
|
328
514
|
enumTypes.set(t.id, {
|
|
329
515
|
name: toPascalCase(t.name),
|
|
@@ -339,9 +525,9 @@ usedEnumIds) {
|
|
|
339
525
|
const id = t.id;
|
|
340
526
|
if (enumTypes.has(id))
|
|
341
527
|
continue;
|
|
342
|
-
if (id
|
|
528
|
+
if (isBuiltInEnumTypeId(id))
|
|
343
529
|
continue;
|
|
344
|
-
if (usedEnumIds && !usedEnumIds.has(id))
|
|
530
|
+
if (usedEnumIds && !usedEnumIds.has(id) && !forcedEnumIds.has(id))
|
|
345
531
|
continue;
|
|
346
532
|
if (t.enumOptions && Object.keys(t.enumOptions).length > 0) {
|
|
347
533
|
enumTypes.set(id, {
|
|
@@ -352,17 +538,56 @@ usedEnumIds) {
|
|
|
352
538
|
}
|
|
353
539
|
}
|
|
354
540
|
}
|
|
541
|
+
// The theme block may only name enum types declared in THIS file (see themeSettingTsType).
|
|
542
|
+
const resolveEnumTypeName = (enumTypeId) => enumTypes.get(enumTypeId)?.name ?? null;
|
|
543
|
+
const themeBlock = generateThemeGlobalsBlock(themeSettings, resolveEnumTypeName);
|
|
544
|
+
// The wrapper's runtime import must sit at the top of the file (after the header).
|
|
545
|
+
const themeImport = themeBlock ? THEME_GLOBALS_IMPORT : "";
|
|
355
546
|
if (enumTypes.size === 0) {
|
|
356
|
-
|
|
547
|
+
if (!themeBlock) {
|
|
548
|
+
return `${header}// Custom enum types from the editor will appear here.\n\nexport {};\n`;
|
|
549
|
+
}
|
|
550
|
+
return `${header}${themeImport}${themeBlock}`;
|
|
357
551
|
}
|
|
358
552
|
// Sort by type name for stable output
|
|
359
553
|
const sorted = Array.from(enumTypes.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
360
|
-
let content = `${header}\n`;
|
|
554
|
+
let content = `${header}${themeImport}\n`;
|
|
361
555
|
for (const enumType of sorted) {
|
|
362
|
-
const unionType = enumType.options.map(v => `"${v}"`).join(" | ");
|
|
556
|
+
const unionType = enumType.options.map((v) => `"${v}"`).join(" | ");
|
|
363
557
|
content += `/** Enum type: ${enumType.id} */\nexport type ${enumType.name} = ${unionType};\n`;
|
|
364
558
|
}
|
|
365
|
-
return content
|
|
559
|
+
return `${content}${themeBlock}`;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Decide whether freshly generated `global-types.ts` content should overwrite
|
|
563
|
+
* the existing file on disk.
|
|
564
|
+
*
|
|
565
|
+
* Guards the dev-server startup race: before the editor connects, the theme
|
|
566
|
+
* settings cache is empty, so the generated content omits the theme-globals
|
|
567
|
+
* block (`themeValue`, `ThemeSettingName`). Writing it would clobber the rich
|
|
568
|
+
* file left from the previous session and break every component that imports
|
|
569
|
+
* those exports until the editor reconnects and re-syncs. While theme settings
|
|
570
|
+
* are not yet cached, preserve an existing theme-globals block instead of
|
|
571
|
+
* stubbing it out — the editor's `onSyncTypes` is the authoritative writer once
|
|
572
|
+
* connected.
|
|
573
|
+
*
|
|
574
|
+
* @param existing current file content, or null if the file is absent
|
|
575
|
+
* @param next freshly generated content
|
|
576
|
+
* @param hasThemeSettingsCached whether the editor has synced theme settings yet
|
|
577
|
+
*/
|
|
578
|
+
export function shouldWriteGlobalTypes(existing, next, hasThemeSettingsCached) {
|
|
579
|
+
// No file yet — always write so imports resolve.
|
|
580
|
+
if (existing === null)
|
|
581
|
+
return true;
|
|
582
|
+
// Identical content — skip to avoid file-watcher loops.
|
|
583
|
+
if (existing === next)
|
|
584
|
+
return false;
|
|
585
|
+
// Editor has synced theme settings — it's authoritative, write freely.
|
|
586
|
+
if (hasThemeSettingsCached)
|
|
587
|
+
return true;
|
|
588
|
+
// Not synced yet: write unless we'd drop an existing theme-globals block for a stub.
|
|
589
|
+
return (!existing.includes(THEME_GLOBALS_MARKER) ||
|
|
590
|
+
next.includes(THEME_GLOBALS_MARKER));
|
|
366
591
|
}
|
|
367
592
|
export function generateComponentFile(componentName, props, type) {
|
|
368
593
|
const propsDestructure = props.map((p) => p.name).join(", ");
|
|
@@ -392,6 +617,39 @@ export function updateBarrelExport(projectRoot, componentNames) {
|
|
|
392
617
|
.join("\n") + "\n";
|
|
393
618
|
fs.writeFileSync(indexPath, content);
|
|
394
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* A config visibility gate in wire form, or nothing at all — spread it.
|
|
622
|
+
*
|
|
623
|
+
* Config names the governing prop; the editor needs its id, and ids are minted here from position.
|
|
624
|
+
* A gate naming a prop this component does not have is dropped rather than passed on: the editor
|
|
625
|
+
* would show the control anyway, and a dangling id in the theme is worse than none.
|
|
626
|
+
*/
|
|
627
|
+
export function resolveCondition(gate, propIdByName) {
|
|
628
|
+
if (!gate?.requiredProp)
|
|
629
|
+
return {};
|
|
630
|
+
const requiredPropId = propIdByName.get(gate.requiredProp);
|
|
631
|
+
if (!requiredPropId)
|
|
632
|
+
return {};
|
|
633
|
+
// An ENUM gate carries its option and no boolean state; a BOOLEAN one the reverse. Emitting only
|
|
634
|
+
// the half that applies keeps a stale option from a re-typed governing prop out of the theme.
|
|
635
|
+
if (gate.requiredEnumOptionValue !== undefined) {
|
|
636
|
+
return {
|
|
637
|
+
requiredPropId,
|
|
638
|
+
requiredEnumOptionId: gate.requiredEnumOptionId,
|
|
639
|
+
requiredEnumOptionValue: gate.requiredEnumOptionValue,
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
return { requiredPropId, requiredPropValue: gate.requiredPropValue ?? true };
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Config prop name to the id this component's props are broadcast under.
|
|
646
|
+
*
|
|
647
|
+
* The formula is duplicated at each mapping site (dev broadcast, config rebuild, publish); this
|
|
648
|
+
* reads it back off whatever that site produced rather than restating it a fourth time.
|
|
649
|
+
*/
|
|
650
|
+
export function propIdsByName(props) {
|
|
651
|
+
return new Map(props.map((prop) => [prop.name, prop.id]));
|
|
652
|
+
}
|
|
395
653
|
/**
|
|
396
654
|
* Convert flat config-format prop groups into an IThemePropGroup[] hierarchy.
|
|
397
655
|
*
|
|
@@ -405,11 +663,14 @@ export function updateBarrelExport(projectRoot, componentNames) {
|
|
|
405
663
|
*/
|
|
406
664
|
export function buildPropGroupHierarchy(componentId, propGroups, props) {
|
|
407
665
|
const result = [];
|
|
666
|
+
// A group names its governing prop; the leaf wrappers below carry no gate of their own, because a
|
|
667
|
+
// prop's gate travels on the prop itself (see `resolveCondition` at each prop mapping site).
|
|
668
|
+
const propIdByName = propIdsByName(props);
|
|
408
669
|
for (const group of propGroups) {
|
|
409
670
|
const groupGlobalId = `${componentId}_pg_${group.id}`;
|
|
410
671
|
// Collect props assigned to this group
|
|
411
|
-
const groupProps = props.filter(p => p.groupId === group.id);
|
|
412
|
-
const propChildren = groupProps.map(p => ({
|
|
672
|
+
const groupProps = props.filter((p) => p.groupId === group.id);
|
|
673
|
+
const propChildren = groupProps.map((p) => ({
|
|
413
674
|
id: `${componentId}_pgp_${p.id}`,
|
|
414
675
|
propId: p.id,
|
|
415
676
|
}));
|
|
@@ -419,8 +680,8 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
|
|
|
419
680
|
for (const child of group.children) {
|
|
420
681
|
const childGlobalId = `${componentId}_pg_${child.id}`;
|
|
421
682
|
// Collect props assigned to this child group
|
|
422
|
-
const childProps = props.filter(p => p.groupId === child.id);
|
|
423
|
-
const childPropChildren = childProps.map(p => ({
|
|
683
|
+
const childProps = props.filter((p) => p.groupId === child.id);
|
|
684
|
+
const childPropChildren = childProps.map((p) => ({
|
|
424
685
|
id: `${componentId}_pgp_${p.id}`,
|
|
425
686
|
propId: p.id,
|
|
426
687
|
}));
|
|
@@ -428,7 +689,10 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
|
|
|
428
689
|
id: childGlobalId,
|
|
429
690
|
name: child.name,
|
|
430
691
|
...(child.description ? { description: child.description } : {}),
|
|
431
|
-
...(
|
|
692
|
+
...resolveCondition(child, propIdByName),
|
|
693
|
+
...(childPropChildren.length > 0
|
|
694
|
+
? { children: childPropChildren }
|
|
695
|
+
: {}),
|
|
432
696
|
});
|
|
433
697
|
}
|
|
434
698
|
}
|
|
@@ -437,19 +701,117 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
|
|
|
437
701
|
id: groupGlobalId,
|
|
438
702
|
name: group.name,
|
|
439
703
|
...(group.description ? { description: group.description } : {}),
|
|
704
|
+
...resolveCondition(group, propIdByName),
|
|
440
705
|
...(allChildren.length > 0 ? { children: allChildren } : {}),
|
|
441
706
|
});
|
|
442
707
|
}
|
|
443
708
|
return result;
|
|
444
709
|
}
|
|
710
|
+
/** Every group id under `group`, itself included — the groups a prop assigned "inside" it can sit in. */
|
|
711
|
+
export function groupIdsUnder(group) {
|
|
712
|
+
return new Set([
|
|
713
|
+
group.id,
|
|
714
|
+
...(group.children || []).map((child) => child.id),
|
|
715
|
+
]);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Validate a visibility condition — the `requiredProp` family on a prop or a prop group — against
|
|
719
|
+
* the component it lives on. Returns an error message, or null when it is sound (or absent).
|
|
720
|
+
*
|
|
721
|
+
* What is rejected, and why each one would otherwise strand a control with no way to reach it:
|
|
722
|
+
*
|
|
723
|
+
* - a name no prop on this component has, or a prop that is not BOOLEAN — nothing to read a
|
|
724
|
+
* true/false off, so the gate could never resolve;
|
|
725
|
+
* - a prop gating itself, or a chain of props that comes back around to it — every prop in the
|
|
726
|
+
* cycle stays hidden forever, including the toggles that would let someone out of it;
|
|
727
|
+
* - an ENUM gate with no option to wait for, or an option value hung on a BOOLEAN prop;
|
|
728
|
+
* - a group gated by a toggle that lives inside it — turning that toggle off takes the toggle away
|
|
729
|
+
* with the rest of the group.
|
|
730
|
+
*/
|
|
731
|
+
export function visibilityGateError(component, gate, where, opts = {}) {
|
|
732
|
+
const { requiredProp, requiredPropValue, requiredEnumOptionValue } = gate;
|
|
733
|
+
if (requiredProp === undefined || requiredProp === null) {
|
|
734
|
+
return requiredPropValue === undefined &&
|
|
735
|
+
requiredEnumOptionValue === undefined
|
|
736
|
+
? null
|
|
737
|
+
: `${where} declares a visibility state with no requiredProp to read it off. Name the prop that gates it, or drop both.`;
|
|
738
|
+
}
|
|
739
|
+
if (typeof requiredProp !== "string" || !requiredProp) {
|
|
740
|
+
return `requiredProp on ${where} must be the name of a BOOLEAN or ENUM prop on this component.`;
|
|
741
|
+
}
|
|
742
|
+
if (requiredPropValue !== undefined &&
|
|
743
|
+
typeof requiredPropValue !== "boolean") {
|
|
744
|
+
return `requiredPropValue on ${where} must be true or false (it defaults to true).`;
|
|
745
|
+
}
|
|
746
|
+
if (opts.selfPropName && requiredProp === opts.selfPropName) {
|
|
747
|
+
return `${where} cannot gate itself on "${requiredProp}".`;
|
|
748
|
+
}
|
|
749
|
+
const governing = component.props.find((prop) => prop.name === requiredProp);
|
|
750
|
+
if (!governing) {
|
|
751
|
+
const names = component.props.map((prop) => prop.name).join(", ");
|
|
752
|
+
return `requiredProp "${requiredProp}" on ${where} is not a prop of component "${component.name}". Available props: ${names || "(none)"}.`;
|
|
753
|
+
}
|
|
754
|
+
if (governing.type !== "BOOLEAN" && governing.type !== "ENUM") {
|
|
755
|
+
return `requiredProp "${requiredProp}" on ${where} is a ${governing.type} prop; only a BOOLEAN or ENUM prop can gate visibility.`;
|
|
756
|
+
}
|
|
757
|
+
// An ENUM gate is meaningless without the option it waits for: nothing would ever match it, so
|
|
758
|
+
// the node would never appear at all.
|
|
759
|
+
if (governing.type === "ENUM" &&
|
|
760
|
+
typeof requiredEnumOptionValue !== "string") {
|
|
761
|
+
return `requiredProp "${requiredProp}" on ${where} is an ENUM prop, so requiredEnumOptionValue must name the option value that shows it.`;
|
|
762
|
+
}
|
|
763
|
+
if (governing.type === "BOOLEAN" && requiredEnumOptionValue !== undefined) {
|
|
764
|
+
return `requiredEnumOptionValue on ${where} has no meaning against the BOOLEAN prop "${requiredProp}" — use requiredPropValue instead.`;
|
|
765
|
+
}
|
|
766
|
+
if (opts.group &&
|
|
767
|
+
governing.groupId &&
|
|
768
|
+
groupIdsUnder(opts.group).has(governing.groupId)) {
|
|
769
|
+
return `requiredProp "${requiredProp}" on ${where} sits inside that group — hiding the group would take that control with it, leaving nothing to bring it back.`;
|
|
770
|
+
}
|
|
771
|
+
// Walk the chain the governing prop hangs on. It cannot come back to this prop, and it cannot
|
|
772
|
+
// close on itself either — a cycle anywhere in it hides everything on it.
|
|
773
|
+
const byName = new Map(component.props.map((prop) => [prop.name, prop]));
|
|
774
|
+
const seen = new Set([requiredProp]);
|
|
775
|
+
let current = governing.requiredProp;
|
|
776
|
+
while (current) {
|
|
777
|
+
if (opts.selfPropName && current === opts.selfPropName) {
|
|
778
|
+
return `requiredProp "${requiredProp}" on ${where} depends on it in turn — the two would hide each other permanently.`;
|
|
779
|
+
}
|
|
780
|
+
if (seen.has(current)) {
|
|
781
|
+
return `requiredProp "${requiredProp}" on ${where} sits in a visibility cycle through "${current}" — everything on it would stay hidden.`;
|
|
782
|
+
}
|
|
783
|
+
seen.add(current);
|
|
784
|
+
current = byName.get(current)?.requiredProp;
|
|
785
|
+
}
|
|
786
|
+
return null;
|
|
787
|
+
}
|
|
445
788
|
/**
|
|
446
789
|
* Validate prop groups configuration for a component.
|
|
447
790
|
* Returns an array of error messages (empty = valid).
|
|
448
791
|
*/
|
|
449
792
|
export function validatePropGroups(component) {
|
|
450
793
|
const errors = [];
|
|
451
|
-
const propGroups = component.propGroups;
|
|
452
|
-
|
|
794
|
+
const propGroups = component.propGroups || [];
|
|
795
|
+
// A prop can name a visibility gate whether or not this component has groups at all, so gates are
|
|
796
|
+
// checked before the group walk bails out below.
|
|
797
|
+
for (const prop of component.props) {
|
|
798
|
+
const error = visibilityGateError(component, prop, `prop "${prop.name}"`, {
|
|
799
|
+
selfPropName: prop.name,
|
|
800
|
+
});
|
|
801
|
+
if (error)
|
|
802
|
+
errors.push(error);
|
|
803
|
+
}
|
|
804
|
+
for (const group of [
|
|
805
|
+
...propGroups,
|
|
806
|
+
...propGroups.flatMap((group) => group.children || []),
|
|
807
|
+
]) {
|
|
808
|
+
const error = visibilityGateError(component, group, `group "${group.id}"`, {
|
|
809
|
+
group,
|
|
810
|
+
});
|
|
811
|
+
if (error)
|
|
812
|
+
errors.push(error);
|
|
813
|
+
}
|
|
814
|
+
if (propGroups.length === 0)
|
|
453
815
|
return errors;
|
|
454
816
|
// Collect all group IDs and check uniqueness
|
|
455
817
|
const allIds = new Set();
|
|
@@ -528,7 +890,9 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
|
|
|
528
890
|
const found = findPropGroup(propGroups, propGroupId);
|
|
529
891
|
if (!found)
|
|
530
892
|
throw new Error(`Prop group "${propGroupId}" not found`);
|
|
531
|
-
if (parentGroupId &&
|
|
893
|
+
if (parentGroupId &&
|
|
894
|
+
found.group.children &&
|
|
895
|
+
found.group.children.length > 0) {
|
|
532
896
|
throw new Error(`Cannot nest "${propGroupId}": it already has child groups`);
|
|
533
897
|
}
|
|
534
898
|
if (parentGroupId) {
|
|
@@ -542,10 +906,10 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
|
|
|
542
906
|
}
|
|
543
907
|
let roots = propGroups;
|
|
544
908
|
if (found.parent) {
|
|
545
|
-
found.parent.children = (found.parent.children || []).filter(c => c.id !== propGroupId);
|
|
909
|
+
found.parent.children = (found.parent.children || []).filter((c) => c.id !== propGroupId);
|
|
546
910
|
}
|
|
547
911
|
else {
|
|
548
|
-
roots = roots.filter(g => g.id !== propGroupId);
|
|
912
|
+
roots = roots.filter((g) => g.id !== propGroupId);
|
|
549
913
|
}
|
|
550
914
|
if (parentGroupId) {
|
|
551
915
|
const target = findPropGroup(roots, parentGroupId);
|
|
@@ -553,13 +917,17 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
|
|
|
553
917
|
throw new Error(`Target parent group "${parentGroupId}" not found after removal`);
|
|
554
918
|
if (!target.group.children)
|
|
555
919
|
target.group.children = [];
|
|
556
|
-
const insertAt = typeof index === "number" &&
|
|
920
|
+
const insertAt = typeof index === "number" &&
|
|
921
|
+
index >= 0 &&
|
|
922
|
+
index <= target.group.children.length
|
|
557
923
|
? index
|
|
558
924
|
: target.group.children.length;
|
|
559
925
|
target.group.children.splice(insertAt, 0, found.group);
|
|
560
926
|
}
|
|
561
927
|
else {
|
|
562
|
-
const insertAt = typeof index === "number" && index >= 0 && index <= roots.length
|
|
928
|
+
const insertAt = typeof index === "number" && index >= 0 && index <= roots.length
|
|
929
|
+
? index
|
|
930
|
+
: roots.length;
|
|
563
931
|
roots.splice(insertAt, 0, found.group);
|
|
564
932
|
}
|
|
565
933
|
return roots;
|