@ikas/component-cli 1.4.0-beta.2 → 1.4.0-beta.200
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-to-page.d.ts +3 -0
- package/dist/commands/add-to-page.d.ts.map +1 -0
- package/dist/commands/add-to-page.js +41 -0
- package/dist/commands/add-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 +1235 -228
- 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 +398 -53
- 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/import.d.ts +3 -0
- package/dist/commands/import.d.ts.map +1 -0
- package/dist/commands/import.js +25 -0
- package/dist/commands/import.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-imported.d.ts +3 -0
- package/dist/commands/list-imported.d.ts.map +1 -0
- package/dist/commands/list-imported.js +25 -0
- package/dist/commands/list-imported.js.map +1 -0
- package/dist/commands/list-page-sections.d.ts +3 -0
- package/dist/commands/list-page-sections.d.ts.map +1 -0
- package/dist/commands/list-page-sections.js +31 -0
- package/dist/commands/list-page-sections.js.map +1 -0
- package/dist/commands/list-pages.d.ts +3 -0
- package/dist/commands/list-pages.d.ts.map +1 -0
- package/dist/commands/list-pages.js +21 -0
- package/dist/commands/list-pages.js.map +1 -0
- 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 +3 -0
- package/dist/commands/update-section-prop.d.ts.map +1 -0
- package/dist/commands/update-section-prop.js +76 -0
- package/dist/commands/update-section-prop.js.map +1 -0
- package/dist/commands/upload-image.d.ts +3 -0
- package/dist/commands/upload-image.d.ts.map +1 -0
- package/dist/commands/upload-image.js +38 -0
- package/dist/commands/upload-image.js.map +1 -0
- 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 +67 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +52 -1
- 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 +148 -3
- package/dist/utils/component-helpers.d.ts.map +1 -1
- package/dist/utils/component-helpers.js +376 -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 +29 -0
- package/dist/utils/editor-action-client.d.ts.map +1 -0
- package/dist/utils/editor-action-client.js +137 -0
- package/dist/utils/editor-action-client.js.map +1 -0
- 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 +134 -3
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js +279 -24
- 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 -9
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js +0 -9
- 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 -212
- package/dist/commands/proxy.js.map +0 -1
|
@@ -35,6 +35,52 @@ 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
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Validate that every entry in `input` is the id of a component currently in `components`.
|
|
74
|
+
* Returns the list of unknown entries (empty array means all valid).
|
|
75
|
+
*
|
|
76
|
+
* Component ids are opaque random strings — they cannot be derived from names. Callers
|
|
77
|
+
* (CLI commands, dev-server WS handlers) must reject writes that reference unknown ids
|
|
78
|
+
* and surface `validComponents` so the LLM/editor can correct itself.
|
|
79
|
+
*/
|
|
80
|
+
export function validateFilteredComponentIds(input, components) {
|
|
81
|
+
const known = new Set(components.map((c) => c.id));
|
|
82
|
+
return { unknown: input.filter((id) => !known.has(id)) };
|
|
83
|
+
}
|
|
38
84
|
export const PROP_TYPES = [
|
|
39
85
|
"TEXT",
|
|
40
86
|
"RICH_TEXT",
|
|
@@ -44,6 +90,8 @@ export const PROP_TYPES = [
|
|
|
44
90
|
"IMAGE",
|
|
45
91
|
"IMAGE_LIST",
|
|
46
92
|
"VIDEO",
|
|
93
|
+
"SVG",
|
|
94
|
+
"SVG_LIST",
|
|
47
95
|
"DATE",
|
|
48
96
|
"LINK",
|
|
49
97
|
"LIST_OF_LINK",
|
|
@@ -74,14 +122,16 @@ export const PROP_TYPE_TO_TS = {
|
|
|
74
122
|
IMAGE: "IkasImage | null",
|
|
75
123
|
IMAGE_LIST: "IkasImageList",
|
|
76
124
|
VIDEO: "IkasVideo | null",
|
|
125
|
+
SVG: "string",
|
|
126
|
+
SVG_LIST: "string[]",
|
|
77
127
|
DATE: "Date | string",
|
|
78
128
|
LINK: "IkasNavigationLink | null",
|
|
79
129
|
LIST_OF_LINK: "IkasNavigationLinkList",
|
|
80
130
|
COLOR: "string",
|
|
81
131
|
PRODUCT: "IkasProduct | null",
|
|
82
132
|
PRODUCT_LIST: "IkasProductList",
|
|
83
|
-
PRODUCT_ATTRIBUTE: "
|
|
84
|
-
PRODUCT_ATTRIBUTE_LIST: "
|
|
133
|
+
PRODUCT_ATTRIBUTE: "IkasProductAttributeDetail | null",
|
|
134
|
+
PRODUCT_ATTRIBUTE_LIST: "IkasProductAttributeList",
|
|
85
135
|
CATEGORY: "IkasCategory | null",
|
|
86
136
|
CATEGORY_LIST: "IkasCategoryList",
|
|
87
137
|
BRAND: "IkasBrand | null",
|
|
@@ -95,6 +145,21 @@ export const PROP_TYPE_TO_TS = {
|
|
|
95
145
|
COMPONENT: "any",
|
|
96
146
|
COMPONENT_LIST: "any",
|
|
97
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
|
+
}
|
|
98
163
|
export function toKebabCase(str) {
|
|
99
164
|
return str
|
|
100
165
|
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
@@ -133,14 +198,16 @@ function resolveTypeId(typeId) {
|
|
|
133
198
|
*/
|
|
134
199
|
function resolveCustomEnumTypeName(enumTypeId, editorTypes, customTypes) {
|
|
135
200
|
if (editorTypes) {
|
|
136
|
-
const editorType = editorTypes.find(t => t.id === enumTypeId);
|
|
137
|
-
if (editorType?.enumOptions &&
|
|
201
|
+
const editorType = editorTypes.find((t) => t.id === enumTypeId);
|
|
202
|
+
if (editorType?.enumOptions &&
|
|
203
|
+
Object.keys(editorType.enumOptions).length > 0) {
|
|
138
204
|
return toPascalCase(editorType.name);
|
|
139
205
|
}
|
|
140
206
|
}
|
|
141
207
|
if (customTypes) {
|
|
142
|
-
const customType = customTypes.find(t => t.id === enumTypeId);
|
|
143
|
-
if (customType?.enumOptions &&
|
|
208
|
+
const customType = customTypes.find((t) => t.id === enumTypeId);
|
|
209
|
+
if (customType?.enumOptions &&
|
|
210
|
+
Object.keys(customType.enumOptions).length > 0) {
|
|
144
211
|
return toPascalCase(customType.name);
|
|
145
212
|
}
|
|
146
213
|
}
|
|
@@ -160,7 +227,9 @@ export function generateTypesFile(componentName, props, type, editorTypes, custo
|
|
|
160
227
|
typeIdResolved.set(prop.name, resolved.isArray ? `${resolved.typeName}[]` : resolved.typeName);
|
|
161
228
|
}
|
|
162
229
|
}
|
|
163
|
-
else if (prop.type === "ENUM" &&
|
|
230
|
+
else if (prop.type === "ENUM" &&
|
|
231
|
+
prop.enumTypeId &&
|
|
232
|
+
prop.enumTypeId !== PATTERN_ELEMENT_ENUM_ID) {
|
|
164
233
|
const resolved = resolveTypeId(prop.enumTypeId);
|
|
165
234
|
if (resolved) {
|
|
166
235
|
// Built-in enum — import from @ikas/bp-storefront
|
|
@@ -177,6 +246,9 @@ export function generateTypesFile(componentName, props, type, editorTypes, custo
|
|
|
177
246
|
}
|
|
178
247
|
}
|
|
179
248
|
else {
|
|
249
|
+
// Non-ENUM props, plus the font-style (pattern-element) sentinel whose
|
|
250
|
+
// runtime value is a plain pattern-element id string → PROP_TYPE_TO_TS
|
|
251
|
+
// (PROP_TYPE_TO_TS["ENUM"] === "string"), no import emitted.
|
|
180
252
|
const tsType = PROP_TYPE_TO_TS[prop.type];
|
|
181
253
|
if (tsType?.includes("Ikas")) {
|
|
182
254
|
const matches = tsType.match(/Ikas\w+/g);
|
|
@@ -282,6 +354,96 @@ export function collectUsedCustomTypeIds(customTypes, components) {
|
|
|
282
354
|
}
|
|
283
355
|
return used;
|
|
284
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* Enum ids referenced by ENUM theme settings. Their union types must be emitted into
|
|
359
|
+
* `global-types.ts` even when no component prop uses the enum, so the setting's value-map
|
|
360
|
+
* entry (and `themeValue()`) can narrow to it.
|
|
361
|
+
*/
|
|
362
|
+
export function collectThemeSettingEnumIds(themeSettings) {
|
|
363
|
+
const ids = new Set();
|
|
364
|
+
for (const s of themeSettings || []) {
|
|
365
|
+
if (s.type === "ENUM" && s.enumTypeId)
|
|
366
|
+
ids.add(s.enumTypeId);
|
|
367
|
+
}
|
|
368
|
+
return ids;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Map a global-variable kind to a TS type. Primitives narrowed; complex kinds stay `any`. An
|
|
372
|
+
* ENUM setting narrows to the union type THIS file declares for its enum: `resolveEnumTypeName`
|
|
373
|
+
* only knows the enums emitted above the theme block, so the map can never name an undeclared
|
|
374
|
+
* identifier. An ENUM whose enum is not emitted here — a deleted type, or a built-in `@ikas/*`
|
|
375
|
+
* enum (which the editor does not accept for a theme global, and whose import from
|
|
376
|
+
* `@ikas/bp-storefront` this generator cannot verify) — degrades to `string`.
|
|
377
|
+
*/
|
|
378
|
+
function themeSettingTsType(setting, resolveEnumTypeName) {
|
|
379
|
+
switch (setting.type) {
|
|
380
|
+
case "NUMBER":
|
|
381
|
+
return "number";
|
|
382
|
+
case "BOOLEAN":
|
|
383
|
+
return "boolean";
|
|
384
|
+
case "TEXT":
|
|
385
|
+
case "RICH_TEXT":
|
|
386
|
+
case "COLOR":
|
|
387
|
+
return "string";
|
|
388
|
+
case "ENUM":
|
|
389
|
+
return ((setting.enumTypeId && resolveEnumTypeName(setting.enumTypeId)) ||
|
|
390
|
+
"string");
|
|
391
|
+
default:
|
|
392
|
+
return "any"; // IMAGE, BORDER, SHADOW — object shapes can drift from runtime
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Import line for the typed theme-globals wrapper. Must sit at the top of the generated
|
|
397
|
+
* file (after the header). Emitted only when there are theme globals.
|
|
398
|
+
*
|
|
399
|
+
* A module augmentation can't deliver key-safety here: the runtime `getThemeSettingValue`
|
|
400
|
+
* is declared `(name: string): any`, so an added narrower overload never wins resolution —
|
|
401
|
+
* unknown keys still match `string` and return `any`. A generated wrapper whose parameter
|
|
402
|
+
* is `ThemeSettingName` (no `string` overload) does reject unknown keys and narrow the value.
|
|
403
|
+
*/
|
|
404
|
+
const THEME_GLOBALS_IMPORT = `import { getThemeSettingValue as _getThemeSettingValueRaw } from "@ikas/bp-storefront";\n`;
|
|
405
|
+
/**
|
|
406
|
+
* Sentinel that marks a generated `global-types.ts` as containing the theme-globals block.
|
|
407
|
+
* This is the exported symbol authors import (stable public API), and it must stay a substring
|
|
408
|
+
* of what {@link generateThemeGlobalsBlock} emits — keep the two in sync if that output changes.
|
|
409
|
+
*/
|
|
410
|
+
const THEME_GLOBALS_MARKER = "export type ThemeSettingName";
|
|
411
|
+
/**
|
|
412
|
+
* Build the theme-globals block for `src/global-types.ts`: the key union, a value-type map,
|
|
413
|
+
* and a type-safe `themeValue` wrapper (authors import it from `./global-types`). The wrapper
|
|
414
|
+
* is deliberately named differently from the SDK's `getThemeSettingValue` so authors can't
|
|
415
|
+
* accidentally import the untyped SDK version and lose key-safety (no shadowing).
|
|
416
|
+
* Returns "" when there are no globals (an empty union would resolve to `never`). The import
|
|
417
|
+
* the wrapper needs is emitted separately via {@link THEME_GLOBALS_IMPORT}.
|
|
418
|
+
*/
|
|
419
|
+
function generateThemeGlobalsBlock(themeSettings, resolveEnumTypeName = () => null) {
|
|
420
|
+
if (!themeSettings || themeSettings.length === 0)
|
|
421
|
+
return "";
|
|
422
|
+
const sorted = [...themeSettings].sort((a, b) => a.name.localeCompare(b.name));
|
|
423
|
+
const unionLines = sorted
|
|
424
|
+
.map((s) => {
|
|
425
|
+
// Escape the JSDoc comment terminator to avoid prematurely closing the
|
|
426
|
+
// generated `/** ... */` block when a displayName contains `*/`.
|
|
427
|
+
const label = String(s.displayName).replace(/\*\//g, "*\\/");
|
|
428
|
+
return ` /** ${label} (${s.type}) */\n | ${JSON.stringify(s.name)}`;
|
|
429
|
+
})
|
|
430
|
+
.join("\n");
|
|
431
|
+
const mapLines = sorted
|
|
432
|
+
.map((s) => ` ${JSON.stringify(s.name)}: ${themeSettingTsType(s, resolveEnumTypeName)};`)
|
|
433
|
+
.join("\n");
|
|
434
|
+
return (`\n/** Stable keys of theme global variables defined in the editor's "Styles" panel. */\n` +
|
|
435
|
+
`export type ThemeSettingName =\n${unionLines};\n\n` +
|
|
436
|
+
`/** Narrowed value type per global key (primitives and ENUM unions; complex kinds are \`any\`). */\n` +
|
|
437
|
+
`type ThemeSettingValueMap = {\n${mapLines}\n};\n\n` +
|
|
438
|
+
`/**\n` +
|
|
439
|
+
` * Type-safe theme global accessor — only accepts keys declared in the editor's Styles panel.\n` +
|
|
440
|
+
` * Import this from \`./global-types\`, not \`getThemeSettingValue\` from \`@ikas/bp-storefront\`\n` +
|
|
441
|
+
` * (that one is untyped: it accepts any string and returns \`any\`).\n` +
|
|
442
|
+
` */\n` +
|
|
443
|
+
`export function themeValue<K extends ThemeSettingName>(name: K): ThemeSettingValueMap[K] {\n` +
|
|
444
|
+
` return _getThemeSettingValueRaw(name) as ThemeSettingValueMap[K];\n` +
|
|
445
|
+
`}\n`);
|
|
446
|
+
}
|
|
285
447
|
/**
|
|
286
448
|
* Generate the content for `src/global-types.ts`.
|
|
287
449
|
* Collects all custom enum types from editorTypes (preferred) or customTypes (fallback)
|
|
@@ -295,8 +457,11 @@ export function generateGlobalTypesFile(editorTypes, customTypes,
|
|
|
295
457
|
* Callers should compute this from `config.components[*].props[*].enumTypeId`
|
|
296
458
|
* so unused enums are excluded from `global-types.ts`.
|
|
297
459
|
*/
|
|
298
|
-
usedEnumIds) {
|
|
460
|
+
usedEnumIds, themeSettings) {
|
|
299
461
|
const header = `// Auto-generated global type definitions for ikas code components.\n// This file is regenerated automatically — do not edit manually.\n`;
|
|
462
|
+
// Enums an ENUM theme setting selects from are emitted regardless of `usedEnumIds`: the
|
|
463
|
+
// setting's value-map entry names them, so they must exist even if no prop uses them.
|
|
464
|
+
const forcedEnumIds = collectThemeSettingEnumIds(themeSettings);
|
|
300
465
|
// Collect all custom enum types with their options
|
|
301
466
|
// Use a Map keyed by type ID to deduplicate
|
|
302
467
|
const enumTypes = new Map();
|
|
@@ -304,10 +469,10 @@ usedEnumIds) {
|
|
|
304
469
|
if (editorTypes) {
|
|
305
470
|
for (const t of editorTypes) {
|
|
306
471
|
if (t.enumOptions && Object.keys(t.enumOptions).length > 0) {
|
|
307
|
-
// Skip built-in types
|
|
308
|
-
if (t.id
|
|
472
|
+
// Skip built-in types (@ikas/* and the pattern-element font-style sentinel)
|
|
473
|
+
if (isBuiltInEnumTypeId(t.id))
|
|
309
474
|
continue;
|
|
310
|
-
if (usedEnumIds && !usedEnumIds.has(t.id))
|
|
475
|
+
if (usedEnumIds && !usedEnumIds.has(t.id) && !forcedEnumIds.has(t.id))
|
|
311
476
|
continue;
|
|
312
477
|
enumTypes.set(t.id, {
|
|
313
478
|
name: toPascalCase(t.name),
|
|
@@ -323,9 +488,9 @@ usedEnumIds) {
|
|
|
323
488
|
const id = t.id;
|
|
324
489
|
if (enumTypes.has(id))
|
|
325
490
|
continue;
|
|
326
|
-
if (id
|
|
491
|
+
if (isBuiltInEnumTypeId(id))
|
|
327
492
|
continue;
|
|
328
|
-
if (usedEnumIds && !usedEnumIds.has(id))
|
|
493
|
+
if (usedEnumIds && !usedEnumIds.has(id) && !forcedEnumIds.has(id))
|
|
329
494
|
continue;
|
|
330
495
|
if (t.enumOptions && Object.keys(t.enumOptions).length > 0) {
|
|
331
496
|
enumTypes.set(id, {
|
|
@@ -336,17 +501,56 @@ usedEnumIds) {
|
|
|
336
501
|
}
|
|
337
502
|
}
|
|
338
503
|
}
|
|
504
|
+
// The theme block may only name enum types declared in THIS file (see themeSettingTsType).
|
|
505
|
+
const resolveEnumTypeName = (enumTypeId) => enumTypes.get(enumTypeId)?.name ?? null;
|
|
506
|
+
const themeBlock = generateThemeGlobalsBlock(themeSettings, resolveEnumTypeName);
|
|
507
|
+
// The wrapper's runtime import must sit at the top of the file (after the header).
|
|
508
|
+
const themeImport = themeBlock ? THEME_GLOBALS_IMPORT : "";
|
|
339
509
|
if (enumTypes.size === 0) {
|
|
340
|
-
|
|
510
|
+
if (!themeBlock) {
|
|
511
|
+
return `${header}// Custom enum types from the editor will appear here.\n\nexport {};\n`;
|
|
512
|
+
}
|
|
513
|
+
return `${header}${themeImport}${themeBlock}`;
|
|
341
514
|
}
|
|
342
515
|
// Sort by type name for stable output
|
|
343
516
|
const sorted = Array.from(enumTypes.values()).sort((a, b) => a.name.localeCompare(b.name));
|
|
344
|
-
let content = `${header}\n`;
|
|
517
|
+
let content = `${header}${themeImport}\n`;
|
|
345
518
|
for (const enumType of sorted) {
|
|
346
|
-
const unionType = enumType.options.map(v => `"${v}"`).join(" | ");
|
|
519
|
+
const unionType = enumType.options.map((v) => `"${v}"`).join(" | ");
|
|
347
520
|
content += `/** Enum type: ${enumType.id} */\nexport type ${enumType.name} = ${unionType};\n`;
|
|
348
521
|
}
|
|
349
|
-
return content
|
|
522
|
+
return `${content}${themeBlock}`;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Decide whether freshly generated `global-types.ts` content should overwrite
|
|
526
|
+
* the existing file on disk.
|
|
527
|
+
*
|
|
528
|
+
* Guards the dev-server startup race: before the editor connects, the theme
|
|
529
|
+
* settings cache is empty, so the generated content omits the theme-globals
|
|
530
|
+
* block (`themeValue`, `ThemeSettingName`). Writing it would clobber the rich
|
|
531
|
+
* file left from the previous session and break every component that imports
|
|
532
|
+
* those exports until the editor reconnects and re-syncs. While theme settings
|
|
533
|
+
* are not yet cached, preserve an existing theme-globals block instead of
|
|
534
|
+
* stubbing it out — the editor's `onSyncTypes` is the authoritative writer once
|
|
535
|
+
* connected.
|
|
536
|
+
*
|
|
537
|
+
* @param existing current file content, or null if the file is absent
|
|
538
|
+
* @param next freshly generated content
|
|
539
|
+
* @param hasThemeSettingsCached whether the editor has synced theme settings yet
|
|
540
|
+
*/
|
|
541
|
+
export function shouldWriteGlobalTypes(existing, next, hasThemeSettingsCached) {
|
|
542
|
+
// No file yet — always write so imports resolve.
|
|
543
|
+
if (existing === null)
|
|
544
|
+
return true;
|
|
545
|
+
// Identical content — skip to avoid file-watcher loops.
|
|
546
|
+
if (existing === next)
|
|
547
|
+
return false;
|
|
548
|
+
// Editor has synced theme settings — it's authoritative, write freely.
|
|
549
|
+
if (hasThemeSettingsCached)
|
|
550
|
+
return true;
|
|
551
|
+
// Not synced yet: write unless we'd drop an existing theme-globals block for a stub.
|
|
552
|
+
return (!existing.includes(THEME_GLOBALS_MARKER) ||
|
|
553
|
+
next.includes(THEME_GLOBALS_MARKER));
|
|
350
554
|
}
|
|
351
555
|
export function generateComponentFile(componentName, props, type) {
|
|
352
556
|
const propsDestructure = props.map((p) => p.name).join(", ");
|
|
@@ -376,6 +580,39 @@ export function updateBarrelExport(projectRoot, componentNames) {
|
|
|
376
580
|
.join("\n") + "\n";
|
|
377
581
|
fs.writeFileSync(indexPath, content);
|
|
378
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* A config visibility gate in wire form, or nothing at all — spread it.
|
|
585
|
+
*
|
|
586
|
+
* Config names the governing prop; the editor needs its id, and ids are minted here from position.
|
|
587
|
+
* A gate naming a prop this component does not have is dropped rather than passed on: the editor
|
|
588
|
+
* would show the control anyway, and a dangling id in the theme is worse than none.
|
|
589
|
+
*/
|
|
590
|
+
export function resolveCondition(gate, propIdByName) {
|
|
591
|
+
if (!gate?.requiredProp)
|
|
592
|
+
return {};
|
|
593
|
+
const requiredPropId = propIdByName.get(gate.requiredProp);
|
|
594
|
+
if (!requiredPropId)
|
|
595
|
+
return {};
|
|
596
|
+
// An ENUM gate carries its option and no boolean state; a BOOLEAN one the reverse. Emitting only
|
|
597
|
+
// the half that applies keeps a stale option from a re-typed governing prop out of the theme.
|
|
598
|
+
if (gate.requiredEnumOptionValue !== undefined) {
|
|
599
|
+
return {
|
|
600
|
+
requiredPropId,
|
|
601
|
+
requiredEnumOptionId: gate.requiredEnumOptionId,
|
|
602
|
+
requiredEnumOptionValue: gate.requiredEnumOptionValue,
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
return { requiredPropId, requiredPropValue: gate.requiredPropValue ?? true };
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Config prop name to the id this component's props are broadcast under.
|
|
609
|
+
*
|
|
610
|
+
* The formula is duplicated at each mapping site (dev broadcast, config rebuild, publish); this
|
|
611
|
+
* reads it back off whatever that site produced rather than restating it a fourth time.
|
|
612
|
+
*/
|
|
613
|
+
export function propIdsByName(props) {
|
|
614
|
+
return new Map(props.map((prop) => [prop.name, prop.id]));
|
|
615
|
+
}
|
|
379
616
|
/**
|
|
380
617
|
* Convert flat config-format prop groups into an IThemePropGroup[] hierarchy.
|
|
381
618
|
*
|
|
@@ -389,11 +626,14 @@ export function updateBarrelExport(projectRoot, componentNames) {
|
|
|
389
626
|
*/
|
|
390
627
|
export function buildPropGroupHierarchy(componentId, propGroups, props) {
|
|
391
628
|
const result = [];
|
|
629
|
+
// A group names its governing prop; the leaf wrappers below carry no gate of their own, because a
|
|
630
|
+
// prop's gate travels on the prop itself (see `resolveCondition` at each prop mapping site).
|
|
631
|
+
const propIdByName = propIdsByName(props);
|
|
392
632
|
for (const group of propGroups) {
|
|
393
633
|
const groupGlobalId = `${componentId}_pg_${group.id}`;
|
|
394
634
|
// Collect props assigned to this group
|
|
395
|
-
const groupProps = props.filter(p => p.groupId === group.id);
|
|
396
|
-
const propChildren = groupProps.map(p => ({
|
|
635
|
+
const groupProps = props.filter((p) => p.groupId === group.id);
|
|
636
|
+
const propChildren = groupProps.map((p) => ({
|
|
397
637
|
id: `${componentId}_pgp_${p.id}`,
|
|
398
638
|
propId: p.id,
|
|
399
639
|
}));
|
|
@@ -403,8 +643,8 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
|
|
|
403
643
|
for (const child of group.children) {
|
|
404
644
|
const childGlobalId = `${componentId}_pg_${child.id}`;
|
|
405
645
|
// Collect props assigned to this child group
|
|
406
|
-
const childProps = props.filter(p => p.groupId === child.id);
|
|
407
|
-
const childPropChildren = childProps.map(p => ({
|
|
646
|
+
const childProps = props.filter((p) => p.groupId === child.id);
|
|
647
|
+
const childPropChildren = childProps.map((p) => ({
|
|
408
648
|
id: `${componentId}_pgp_${p.id}`,
|
|
409
649
|
propId: p.id,
|
|
410
650
|
}));
|
|
@@ -412,7 +652,10 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
|
|
|
412
652
|
id: childGlobalId,
|
|
413
653
|
name: child.name,
|
|
414
654
|
...(child.description ? { description: child.description } : {}),
|
|
415
|
-
...(
|
|
655
|
+
...resolveCondition(child, propIdByName),
|
|
656
|
+
...(childPropChildren.length > 0
|
|
657
|
+
? { children: childPropChildren }
|
|
658
|
+
: {}),
|
|
416
659
|
});
|
|
417
660
|
}
|
|
418
661
|
}
|
|
@@ -421,19 +664,117 @@ export function buildPropGroupHierarchy(componentId, propGroups, props) {
|
|
|
421
664
|
id: groupGlobalId,
|
|
422
665
|
name: group.name,
|
|
423
666
|
...(group.description ? { description: group.description } : {}),
|
|
667
|
+
...resolveCondition(group, propIdByName),
|
|
424
668
|
...(allChildren.length > 0 ? { children: allChildren } : {}),
|
|
425
669
|
});
|
|
426
670
|
}
|
|
427
671
|
return result;
|
|
428
672
|
}
|
|
673
|
+
/** Every group id under `group`, itself included — the groups a prop assigned "inside" it can sit in. */
|
|
674
|
+
export function groupIdsUnder(group) {
|
|
675
|
+
return new Set([
|
|
676
|
+
group.id,
|
|
677
|
+
...(group.children || []).map((child) => child.id),
|
|
678
|
+
]);
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Validate a visibility condition — the `requiredProp` family on a prop or a prop group — against
|
|
682
|
+
* the component it lives on. Returns an error message, or null when it is sound (or absent).
|
|
683
|
+
*
|
|
684
|
+
* What is rejected, and why each one would otherwise strand a control with no way to reach it:
|
|
685
|
+
*
|
|
686
|
+
* - a name no prop on this component has, or a prop that is not BOOLEAN — nothing to read a
|
|
687
|
+
* true/false off, so the gate could never resolve;
|
|
688
|
+
* - a prop gating itself, or a chain of props that comes back around to it — every prop in the
|
|
689
|
+
* cycle stays hidden forever, including the toggles that would let someone out of it;
|
|
690
|
+
* - an ENUM gate with no option to wait for, or an option value hung on a BOOLEAN prop;
|
|
691
|
+
* - a group gated by a toggle that lives inside it — turning that toggle off takes the toggle away
|
|
692
|
+
* with the rest of the group.
|
|
693
|
+
*/
|
|
694
|
+
export function visibilityGateError(component, gate, where, opts = {}) {
|
|
695
|
+
const { requiredProp, requiredPropValue, requiredEnumOptionValue } = gate;
|
|
696
|
+
if (requiredProp === undefined || requiredProp === null) {
|
|
697
|
+
return requiredPropValue === undefined &&
|
|
698
|
+
requiredEnumOptionValue === undefined
|
|
699
|
+
? null
|
|
700
|
+
: `${where} declares a visibility state with no requiredProp to read it off. Name the prop that gates it, or drop both.`;
|
|
701
|
+
}
|
|
702
|
+
if (typeof requiredProp !== "string" || !requiredProp) {
|
|
703
|
+
return `requiredProp on ${where} must be the name of a BOOLEAN or ENUM prop on this component.`;
|
|
704
|
+
}
|
|
705
|
+
if (requiredPropValue !== undefined &&
|
|
706
|
+
typeof requiredPropValue !== "boolean") {
|
|
707
|
+
return `requiredPropValue on ${where} must be true or false (it defaults to true).`;
|
|
708
|
+
}
|
|
709
|
+
if (opts.selfPropName && requiredProp === opts.selfPropName) {
|
|
710
|
+
return `${where} cannot gate itself on "${requiredProp}".`;
|
|
711
|
+
}
|
|
712
|
+
const governing = component.props.find((prop) => prop.name === requiredProp);
|
|
713
|
+
if (!governing) {
|
|
714
|
+
const names = component.props.map((prop) => prop.name).join(", ");
|
|
715
|
+
return `requiredProp "${requiredProp}" on ${where} is not a prop of component "${component.name}". Available props: ${names || "(none)"}.`;
|
|
716
|
+
}
|
|
717
|
+
if (governing.type !== "BOOLEAN" && governing.type !== "ENUM") {
|
|
718
|
+
return `requiredProp "${requiredProp}" on ${where} is a ${governing.type} prop; only a BOOLEAN or ENUM prop can gate visibility.`;
|
|
719
|
+
}
|
|
720
|
+
// An ENUM gate is meaningless without the option it waits for: nothing would ever match it, so
|
|
721
|
+
// the node would never appear at all.
|
|
722
|
+
if (governing.type === "ENUM" &&
|
|
723
|
+
typeof requiredEnumOptionValue !== "string") {
|
|
724
|
+
return `requiredProp "${requiredProp}" on ${where} is an ENUM prop, so requiredEnumOptionValue must name the option value that shows it.`;
|
|
725
|
+
}
|
|
726
|
+
if (governing.type === "BOOLEAN" && requiredEnumOptionValue !== undefined) {
|
|
727
|
+
return `requiredEnumOptionValue on ${where} has no meaning against the BOOLEAN prop "${requiredProp}" — use requiredPropValue instead.`;
|
|
728
|
+
}
|
|
729
|
+
if (opts.group &&
|
|
730
|
+
governing.groupId &&
|
|
731
|
+
groupIdsUnder(opts.group).has(governing.groupId)) {
|
|
732
|
+
return `requiredProp "${requiredProp}" on ${where} sits inside that group — hiding the group would take that control with it, leaving nothing to bring it back.`;
|
|
733
|
+
}
|
|
734
|
+
// Walk the chain the governing prop hangs on. It cannot come back to this prop, and it cannot
|
|
735
|
+
// close on itself either — a cycle anywhere in it hides everything on it.
|
|
736
|
+
const byName = new Map(component.props.map((prop) => [prop.name, prop]));
|
|
737
|
+
const seen = new Set([requiredProp]);
|
|
738
|
+
let current = governing.requiredProp;
|
|
739
|
+
while (current) {
|
|
740
|
+
if (opts.selfPropName && current === opts.selfPropName) {
|
|
741
|
+
return `requiredProp "${requiredProp}" on ${where} depends on it in turn — the two would hide each other permanently.`;
|
|
742
|
+
}
|
|
743
|
+
if (seen.has(current)) {
|
|
744
|
+
return `requiredProp "${requiredProp}" on ${where} sits in a visibility cycle through "${current}" — everything on it would stay hidden.`;
|
|
745
|
+
}
|
|
746
|
+
seen.add(current);
|
|
747
|
+
current = byName.get(current)?.requiredProp;
|
|
748
|
+
}
|
|
749
|
+
return null;
|
|
750
|
+
}
|
|
429
751
|
/**
|
|
430
752
|
* Validate prop groups configuration for a component.
|
|
431
753
|
* Returns an array of error messages (empty = valid).
|
|
432
754
|
*/
|
|
433
755
|
export function validatePropGroups(component) {
|
|
434
756
|
const errors = [];
|
|
435
|
-
const propGroups = component.propGroups;
|
|
436
|
-
|
|
757
|
+
const propGroups = component.propGroups || [];
|
|
758
|
+
// A prop can name a visibility gate whether or not this component has groups at all, so gates are
|
|
759
|
+
// checked before the group walk bails out below.
|
|
760
|
+
for (const prop of component.props) {
|
|
761
|
+
const error = visibilityGateError(component, prop, `prop "${prop.name}"`, {
|
|
762
|
+
selfPropName: prop.name,
|
|
763
|
+
});
|
|
764
|
+
if (error)
|
|
765
|
+
errors.push(error);
|
|
766
|
+
}
|
|
767
|
+
for (const group of [
|
|
768
|
+
...propGroups,
|
|
769
|
+
...propGroups.flatMap((group) => group.children || []),
|
|
770
|
+
]) {
|
|
771
|
+
const error = visibilityGateError(component, group, `group "${group.id}"`, {
|
|
772
|
+
group,
|
|
773
|
+
});
|
|
774
|
+
if (error)
|
|
775
|
+
errors.push(error);
|
|
776
|
+
}
|
|
777
|
+
if (propGroups.length === 0)
|
|
437
778
|
return errors;
|
|
438
779
|
// Collect all group IDs and check uniqueness
|
|
439
780
|
const allIds = new Set();
|
|
@@ -512,7 +853,9 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
|
|
|
512
853
|
const found = findPropGroup(propGroups, propGroupId);
|
|
513
854
|
if (!found)
|
|
514
855
|
throw new Error(`Prop group "${propGroupId}" not found`);
|
|
515
|
-
if (parentGroupId &&
|
|
856
|
+
if (parentGroupId &&
|
|
857
|
+
found.group.children &&
|
|
858
|
+
found.group.children.length > 0) {
|
|
516
859
|
throw new Error(`Cannot nest "${propGroupId}": it already has child groups`);
|
|
517
860
|
}
|
|
518
861
|
if (parentGroupId) {
|
|
@@ -526,10 +869,10 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
|
|
|
526
869
|
}
|
|
527
870
|
let roots = propGroups;
|
|
528
871
|
if (found.parent) {
|
|
529
|
-
found.parent.children = (found.parent.children || []).filter(c => c.id !== propGroupId);
|
|
872
|
+
found.parent.children = (found.parent.children || []).filter((c) => c.id !== propGroupId);
|
|
530
873
|
}
|
|
531
874
|
else {
|
|
532
|
-
roots = roots.filter(g => g.id !== propGroupId);
|
|
875
|
+
roots = roots.filter((g) => g.id !== propGroupId);
|
|
533
876
|
}
|
|
534
877
|
if (parentGroupId) {
|
|
535
878
|
const target = findPropGroup(roots, parentGroupId);
|
|
@@ -537,13 +880,17 @@ export function movePropGroupInTree(propGroups, propGroupId, parentGroupId, inde
|
|
|
537
880
|
throw new Error(`Target parent group "${parentGroupId}" not found after removal`);
|
|
538
881
|
if (!target.group.children)
|
|
539
882
|
target.group.children = [];
|
|
540
|
-
const insertAt = typeof index === "number" &&
|
|
883
|
+
const insertAt = typeof index === "number" &&
|
|
884
|
+
index >= 0 &&
|
|
885
|
+
index <= target.group.children.length
|
|
541
886
|
? index
|
|
542
887
|
: target.group.children.length;
|
|
543
888
|
target.group.children.splice(insertAt, 0, found.group);
|
|
544
889
|
}
|
|
545
890
|
else {
|
|
546
|
-
const insertAt = typeof index === "number" && index >= 0 && index <= roots.length
|
|
891
|
+
const insertAt = typeof index === "number" && index >= 0 && index <= roots.length
|
|
892
|
+
? index
|
|
893
|
+
: roots.length;
|
|
547
894
|
roots.splice(insertAt, 0, found.group);
|
|
548
895
|
}
|
|
549
896
|
return roots;
|