@designcrowd/library.brand-page 5.19.1-id-based-items-2 → 5.19.1
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/lib/src/{CreatedOnBrandCrowd-de-de-Ruu5Az32.js → CreatedOnBrandCrowd-de-de-BmeMc9oz.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-en-us-DGUJtvld.js → CreatedOnBrandCrowd-en-us-CQNdm_6P.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-es-es-Dg-1uOfV.js → CreatedOnBrandCrowd-es-es-BrmHWeAM.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-fr-CRKraZl8.js → CreatedOnBrandCrowd-fr-ca-CaIyjTXl.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-ca-CRKraZl8.js → CreatedOnBrandCrowd-fr-fr-CaIyjTXl.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-pt-bZ9VlEAu.js → CreatedOnBrandCrowd-pt-br-BClE0Nd9.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-br-bZ9VlEAu.js → CreatedOnBrandCrowd-pt-pt-BClE0Nd9.js} +1 -1
- package/lib/src/{CreatedOnDcom-de-de-CJYfwZx8.js → CreatedOnDcom-de-de-CkrdlPqK.js} +1 -1
- package/lib/src/{CreatedOnDcom-en-us-rzA1lVxH.js → CreatedOnDcom-en-us-D33J9qky.js} +1 -1
- package/lib/src/{CreatedOnDcom-es-es-CNwGPjik.js → CreatedOnDcom-es-es-BsmInngw.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-ca-DKw7OGIz.js → CreatedOnDcom-fr-ca-DOXlsRea.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-fr-WzOEaAZG.js → CreatedOnDcom-fr-fr-SfFYLtyn.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-br-DkualVhm.js → CreatedOnDcom-pt-br-DcWeuZUy.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-pt-w4Nnsdzq.js → CreatedOnDcom-pt-pt-DZsZZ4iX.js} +1 -1
- package/lib/src/brand-page/components/image-gallery/masonry/MasonryGallery.mixin.d.ts +1 -1
- package/lib/src/brand-page/models/index.d.ts +0 -12
- package/lib/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.js +0 -5
- package/lib/src/brand-page-maker/stores/ai-checkpoint/ai-checkpoint-store.d.ts +0 -18
- package/lib/src/index.mjs +1 -1
- package/lib/src/{lib-Dy7MYyqz.js → lib-C5vGkjfs.js} +17577 -17407
- package/lib/src/metadata-builder/builders/footer-builder.js +44 -34
- package/lib/src/metadata-builder/builders/section-builders/image-gallery-builder.js +68 -57
- package/lib/src/metadata-builder/builders/section-builders/images-section-builder.js +93 -58
- package/lib/src/metadata-builder/builders/section-builders/shapes-section-builder.js +99 -66
- package/lib/src/metadata-builder/builders/section-builders/social-links-builder.js +17 -57
- package/lib/src/metadata-builder/builders/section-builders/testimonial-section-builder.js +85 -51
- package/lib/src/metadata-builder/builders/section-builders/text-section-builder.js +74 -49
- package/lib/src/metadata-builder/parsers/ai-toolcall-parser.d.ts +4 -13
- package/lib/src/metadata-builder/parsers/section-tool-arguments.d.ts +48 -66
- package/lib/src/shared/page-settings/components/page-settings/PageSettings.mixin.d.ts +0 -2
- package/lib/src/shared/page-settings/components/page-settings-section-styles/PageSettingsSectionStyles.mixin.d.ts +0 -2
- package/lib/src/utils/minify-brand-page-metadata.d.ts +0 -2
- package/lib/src/utils/minify-brand-page-metadata.js +1 -8
- package/package.json +1 -1
- package/src/brand-page/components/image-gallery/masonry/MasonryGallery.mixin.ts +1 -2
- package/src/brand-page/models/index.ts +0 -12
- package/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.ts +0 -6
- package/src/metadata-builder/builders/footer-builder.test.ts +0 -298
- package/src/metadata-builder/builders/footer-builder.ts +65 -56
- package/src/metadata-builder/builders/section-builders/image-gallery-builder.ts +88 -62
- package/src/metadata-builder/builders/section-builders/images-section-builder.ts +129 -66
- package/src/metadata-builder/builders/section-builders/shapes-section-builder.ts +160 -105
- package/src/metadata-builder/builders/section-builders/social-links-builder.ts +20 -65
- package/src/metadata-builder/builders/section-builders/testimonial-section-builder.ts +146 -83
- package/src/metadata-builder/builders/section-builders/text-section-builder.ts +122 -70
- package/src/metadata-builder/parsers/ai-toolcall-parser.ts +4 -13
- package/src/metadata-builder/parsers/section-tool-arguments.ts +48 -66
- package/src/utils/minify-brand-page-metadata.ts +2 -14
- package/lib/src/metadata-builder/builders/item-id-utils.d.ts +0 -54
- package/lib/src/metadata-builder/builders/item-id-utils.js +0 -96
- package/src/metadata-builder/builders/item-id-utils.test.ts +0 -184
- package/src/metadata-builder/builders/item-id-utils.ts +0 -117
|
@@ -142,15 +142,10 @@ export interface ProfileSectionArguments {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
export interface TextSectionItem {
|
|
145
|
-
/**
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
|
|
149
|
-
* move for existing ones). Use "__end__" for the end of the list. Omit to
|
|
150
|
-
* leave an existing item in place / append a new item. Mirrors the
|
|
151
|
-
* section-level move_before_content_id.
|
|
152
|
-
*/
|
|
153
|
-
move_before_item_id?: string;
|
|
145
|
+
/** 0-based index of existing item to update in-place */
|
|
146
|
+
item_index?: number;
|
|
147
|
+
/** 0-based position to insert a new item at */
|
|
148
|
+
insert_at?: number;
|
|
154
149
|
text?: RichTextField;
|
|
155
150
|
text_style?: TextStyleArguments;
|
|
156
151
|
}
|
|
@@ -164,8 +159,10 @@ export interface TextSectionArguments {
|
|
|
164
159
|
/** Multiple text items (BrandSite) */
|
|
165
160
|
items?: TextSectionItem[];
|
|
166
161
|
_replace_items?: boolean;
|
|
167
|
-
/**
|
|
168
|
-
|
|
162
|
+
/** 0-based indices of items to remove */
|
|
163
|
+
_remove_item_indices?: number[];
|
|
164
|
+
/** New order as array of current 0-based indices */
|
|
165
|
+
_reorder_items?: number[];
|
|
169
166
|
background_color?: string | null;
|
|
170
167
|
}
|
|
171
168
|
|
|
@@ -175,15 +172,10 @@ export interface ImageSectionArguments {
|
|
|
175
172
|
}
|
|
176
173
|
|
|
177
174
|
export interface ImageGalleryItem {
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
|
|
182
|
-
* move for existing ones). Use "__end__" for the end of the list. Omit to
|
|
183
|
-
* leave an existing item in place / append a new item. Mirrors the
|
|
184
|
-
* section-level move_before_content_id.
|
|
185
|
-
*/
|
|
186
|
-
move_before_item_id?: string;
|
|
175
|
+
/** 0-based index of existing item to update in-place */
|
|
176
|
+
item_index?: number;
|
|
177
|
+
/** 0-based position to insert a new item at */
|
|
178
|
+
insert_at?: number;
|
|
187
179
|
image_url?: string;
|
|
188
180
|
caption?: string;
|
|
189
181
|
}
|
|
@@ -193,8 +185,10 @@ export interface ImageGallerySectionArguments {
|
|
|
193
185
|
gallery_type?: 'grid' | 'carousel' | 'masonry';
|
|
194
186
|
is_full_width?: boolean;
|
|
195
187
|
_replace_items?: boolean;
|
|
196
|
-
/**
|
|
197
|
-
|
|
188
|
+
/** 0-based indices of items to remove */
|
|
189
|
+
_remove_item_indices?: number[];
|
|
190
|
+
/** New order as array of current 0-based indices */
|
|
191
|
+
_reorder_items?: number[];
|
|
198
192
|
}
|
|
199
193
|
|
|
200
194
|
export interface GeneralLinkSectionArguments {
|
|
@@ -262,15 +256,10 @@ export interface TiktokSectionArguments {
|
|
|
262
256
|
}
|
|
263
257
|
|
|
264
258
|
export interface SocialLink {
|
|
265
|
-
/**
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
|
|
269
|
-
* move for existing ones). Use "__end__" for the end of the list. Omit to
|
|
270
|
-
* leave an existing item in place / append a new item. Mirrors the
|
|
271
|
-
* section-level move_before_content_id.
|
|
272
|
-
*/
|
|
273
|
-
move_before_item_id?: string;
|
|
259
|
+
/** 0-based index of existing item to update in-place */
|
|
260
|
+
item_index?: number;
|
|
261
|
+
/** 0-based position to insert a new item at */
|
|
262
|
+
insert_at?: number;
|
|
274
263
|
platform?:
|
|
275
264
|
| 'facebook'
|
|
276
265
|
| 'x'
|
|
@@ -291,8 +280,10 @@ export interface SocialLinksSectionArguments {
|
|
|
291
280
|
/** Style for the icon container background (used when icon_style is 'square' or 'circle'). */
|
|
292
281
|
icon_background_style?: TextStyleArguments;
|
|
293
282
|
_replace_items?: boolean;
|
|
294
|
-
/**
|
|
295
|
-
|
|
283
|
+
/** 0-based indices of items to remove */
|
|
284
|
+
_remove_item_indices?: number[];
|
|
285
|
+
/** New order as array of current 0-based indices */
|
|
286
|
+
_reorder_items?: number[];
|
|
296
287
|
}
|
|
297
288
|
|
|
298
289
|
export interface MailingListSectionArguments {
|
|
@@ -380,15 +371,10 @@ export interface AboutSectionArguments {
|
|
|
380
371
|
}
|
|
381
372
|
|
|
382
373
|
export interface ImagesSectionItem {
|
|
383
|
-
/**
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
|
|
387
|
-
* move for existing ones). Use "__end__" for the end of the list. Omit to
|
|
388
|
-
* leave an existing item in place / append a new item. Mirrors the
|
|
389
|
-
* section-level move_before_content_id.
|
|
390
|
-
*/
|
|
391
|
-
move_before_item_id?: string;
|
|
374
|
+
/** 0-based index of existing item to update in-place */
|
|
375
|
+
item_index?: number;
|
|
376
|
+
/** 0-based position to insert a new item at */
|
|
377
|
+
insert_at?: number;
|
|
392
378
|
image_url?: string;
|
|
393
379
|
heading?: string;
|
|
394
380
|
text?: string;
|
|
@@ -407,8 +393,10 @@ export interface ImagesSectionArguments {
|
|
|
407
393
|
| 'center-card-aligned-image'
|
|
408
394
|
| 'alternate-image';
|
|
409
395
|
_replace_items?: boolean;
|
|
410
|
-
/**
|
|
411
|
-
|
|
396
|
+
/** 0-based indices of items to remove */
|
|
397
|
+
_remove_item_indices?: number[];
|
|
398
|
+
/** New order as array of current 0-based indices */
|
|
399
|
+
_reorder_items?: number[];
|
|
412
400
|
title_style?: TextStyleArguments;
|
|
413
401
|
description_style?: TextStyleArguments;
|
|
414
402
|
heading_style?: TextStyleArguments;
|
|
@@ -421,15 +409,10 @@ export interface ImagesSectionArguments {
|
|
|
421
409
|
}
|
|
422
410
|
|
|
423
411
|
export interface TestimonialItem {
|
|
424
|
-
/**
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
|
|
428
|
-
* move for existing ones). Use "__end__" for the end of the list. Omit to
|
|
429
|
-
* leave an existing item in place / append a new item. Mirrors the
|
|
430
|
-
* section-level move_before_content_id.
|
|
431
|
-
*/
|
|
432
|
-
move_before_item_id?: string;
|
|
412
|
+
/** 0-based index of existing item to update in-place */
|
|
413
|
+
item_index?: number;
|
|
414
|
+
/** 0-based position to insert a new item at */
|
|
415
|
+
insert_at?: number;
|
|
433
416
|
testimonial?: string;
|
|
434
417
|
name?: string;
|
|
435
418
|
position?: string;
|
|
@@ -443,8 +426,10 @@ export interface TestimonialSectionArguments {
|
|
|
443
426
|
items?: TestimonialItem[];
|
|
444
427
|
display_style?: 'centered' | 'big-image' | 'columns';
|
|
445
428
|
_replace_items?: boolean;
|
|
446
|
-
/**
|
|
447
|
-
|
|
429
|
+
/** 0-based indices of items to remove */
|
|
430
|
+
_remove_item_indices?: number[];
|
|
431
|
+
/** New order as array of current 0-based indices */
|
|
432
|
+
_reorder_items?: number[];
|
|
448
433
|
title_style?: TextStyleArguments;
|
|
449
434
|
testimonial_style?: TextStyleArguments;
|
|
450
435
|
name_style?: TextStyleArguments;
|
|
@@ -454,15 +439,10 @@ export interface TestimonialSectionArguments {
|
|
|
454
439
|
}
|
|
455
440
|
|
|
456
441
|
export interface ShapesSectionItem {
|
|
457
|
-
/**
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
|
|
461
|
-
* move for existing ones). Use "__end__" for the end of the list. Omit to
|
|
462
|
-
* leave an existing item in place / append a new item. Mirrors the
|
|
463
|
-
* section-level move_before_content_id.
|
|
464
|
-
*/
|
|
465
|
-
move_before_item_id?: string;
|
|
442
|
+
/** 0-based index of existing item to update in-place */
|
|
443
|
+
item_index?: number;
|
|
444
|
+
/** 0-based position to insert a new item at */
|
|
445
|
+
insert_at?: number;
|
|
466
446
|
icon_image_url?: string;
|
|
467
447
|
shape_url?: string;
|
|
468
448
|
color_theme?: string;
|
|
@@ -482,8 +462,10 @@ export interface ShapesSectionArguments {
|
|
|
482
462
|
| 'center-card-aligned-image'
|
|
483
463
|
| 'alternate-image';
|
|
484
464
|
_replace_items?: boolean;
|
|
485
|
-
/**
|
|
486
|
-
|
|
465
|
+
/** 0-based indices of items to remove */
|
|
466
|
+
_remove_item_indices?: number[];
|
|
467
|
+
/** New order as array of current 0-based indices */
|
|
468
|
+
_reorder_items?: number[];
|
|
487
469
|
title_style?: TextStyleArguments;
|
|
488
470
|
description_style?: TextStyleArguments;
|
|
489
471
|
heading_style?: TextStyleArguments;
|
|
@@ -15,12 +15,7 @@ import { useExternalRichTextEditor } from '../brand-page-maker/composables/rich-
|
|
|
15
15
|
import type { Editor, JSONContent } from '@tiptap/vue-3';
|
|
16
16
|
import { type AssetEntry, resolveLogoData } from './build-asset-manifest';
|
|
17
17
|
|
|
18
|
-
type MinifiedFooterSocialLink = {
|
|
19
|
-
position: number;
|
|
20
|
-
id?: string;
|
|
21
|
-
imageUrl: string;
|
|
22
|
-
url: string;
|
|
23
|
-
};
|
|
18
|
+
type MinifiedFooterSocialLink = { imageUrl: string; url: string };
|
|
24
19
|
|
|
25
20
|
type MinifiedFooter = {
|
|
26
21
|
displayStyle?: string;
|
|
@@ -297,7 +292,6 @@ const minifyContent = (
|
|
|
297
292
|
...(Array.isArray(c.items) && {
|
|
298
293
|
items: c.items.map((item: any, index: number) => ({
|
|
299
294
|
position: index + 1,
|
|
300
|
-
...(item.id && { id: item.id }),
|
|
301
295
|
...st('name', item.name, editor),
|
|
302
296
|
...st('jobTitle', item.position, editor),
|
|
303
297
|
...st('testimonials', item.testimonials, editor),
|
|
@@ -326,7 +320,6 @@ const minifyContent = (
|
|
|
326
320
|
...(Array.isArray(c.items) && {
|
|
327
321
|
items: c.items.map((item: any, index: number) => ({
|
|
328
322
|
position: index + 1,
|
|
329
|
-
...(item.id && { id: item.id }),
|
|
330
323
|
...includeImageWithKey(item.imageUrl),
|
|
331
324
|
...st('title', item.title, editor),
|
|
332
325
|
...st('paragraph', item.paragraph, editor),
|
|
@@ -357,7 +350,6 @@ const minifyContent = (
|
|
|
357
350
|
...(Array.isArray(c.textItems) && {
|
|
358
351
|
textItems: c.textItems.map((item: any, index: number) => ({
|
|
359
352
|
position: index + 1,
|
|
360
|
-
...(item.id && { id: item.id }),
|
|
361
353
|
...st('text', item.text, editor),
|
|
362
354
|
...(includeStyle(item.textStyle) && { textStyle: item.textStyle }),
|
|
363
355
|
})),
|
|
@@ -447,7 +439,6 @@ const minifyContent = (
|
|
|
447
439
|
...(Array.isArray(c.links) && {
|
|
448
440
|
links: c.links.map((link: any, index: number) => ({
|
|
449
441
|
position: index + 1,
|
|
450
|
-
...(link.id && { id: link.id }),
|
|
451
442
|
...(includeString(link.url) && { url: link.url }),
|
|
452
443
|
...includeImageWithKey(link.imageUrl),
|
|
453
444
|
})),
|
|
@@ -491,7 +482,6 @@ const minifyContent = (
|
|
|
491
482
|
...(Array.isArray(c.images) && {
|
|
492
483
|
images: c.images.map((img: any, index: number) => ({
|
|
493
484
|
position: index + 1,
|
|
494
|
-
...(img.id && { id: img.id }),
|
|
495
485
|
...includeImageWithKey(img.imageUrl),
|
|
496
486
|
...st('imageTitle', img.imageTitle, editor),
|
|
497
487
|
})),
|
|
@@ -541,9 +531,7 @@ const minifyFooter = (
|
|
|
541
531
|
logoImageWidth: footer.logoImageWidth || undefined,
|
|
542
532
|
...(logoAssetKey && { logoAssetKey }),
|
|
543
533
|
socialLinks: footer.socialLinks?.length
|
|
544
|
-
? footer.socialLinks.map((l
|
|
545
|
-
position: index + 1,
|
|
546
|
-
...(l.id && { id: l.id }),
|
|
534
|
+
? footer.socialLinks.map((l) => ({
|
|
547
535
|
imageUrl: l.imageUrl || '',
|
|
548
536
|
url: l.url || '',
|
|
549
537
|
}))
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { BrandPageModel } from '../../brand-page/models';
|
|
2
|
-
/**
|
|
3
|
-
* Sentinel anchor meaning "the end of the list", mirroring the section-level
|
|
4
|
-
* `move_before_content_id: "__end__"` convention used in base-section-builder.
|
|
5
|
-
*/
|
|
6
|
-
export declare const END_ITEM_ANCHOR = "__end__";
|
|
7
|
-
/** Generate a stable item id. Mirrors section-level `uuid.v4()` id generation. */
|
|
8
|
-
export declare const generateItemId: () => string;
|
|
9
|
-
/**
|
|
10
|
-
* Walk an entire BrandPageModel and backfill a stable uuid `id` onto every
|
|
11
|
-
* nested array item that lacks one (gallery images, images/shapes/testimonial
|
|
12
|
-
* items, text items, social links, and footer social links).
|
|
13
|
-
*
|
|
14
|
-
* BP-5603: this must run BEFORE the model is minified for the AI, so the same
|
|
15
|
-
* id the AI is shown (and copies into `item_id`) is the one the executor later
|
|
16
|
-
* matches. The maker holds a single live model instance for both the minify
|
|
17
|
-
* and the apply step, so mutating it here makes the ids round-trip; they then
|
|
18
|
-
* persist on the next save. Idempotent — existing ids are preserved.
|
|
19
|
-
*/
|
|
20
|
-
export declare const ensureBrandPageItemIds: (model: BrandPageModel) => void;
|
|
21
|
-
/**
|
|
22
|
-
* Backfill ids onto any items missing one. Per BP-5603 this runs in the
|
|
23
|
-
* metadata builder when a section is processed, so the persisted metadata
|
|
24
|
-
* returned to the client gains stable ids that subsequent AI tool calls can
|
|
25
|
-
* reference. Mutates in place.
|
|
26
|
-
*/
|
|
27
|
-
export declare const ensureItemIds: <T extends {
|
|
28
|
-
id?: string | undefined;
|
|
29
|
-
}>(items: T[] | undefined) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Remove items whose id appears in `ids`. Order-independent (no descending
|
|
32
|
-
* index sort needed) — the whole point of the id-based migration. Items
|
|
33
|
-
* without an id are never removed by id.
|
|
34
|
-
*/
|
|
35
|
-
export declare const removeItemsByIds: <T extends {
|
|
36
|
-
id?: string | undefined;
|
|
37
|
-
}>(items: T[] | undefined, ids: string[] | undefined) => T[];
|
|
38
|
-
/**
|
|
39
|
-
* Position `item` within `items` relative to an anchor id — the item-level
|
|
40
|
-
* mirror of base-section-builder's `moveContent`:
|
|
41
|
-
*
|
|
42
|
-
* - `moveBeforeItemId === undefined` → leave an existing item where it is;
|
|
43
|
-
* append a new (not-yet-present) item to the end.
|
|
44
|
-
* - `moveBeforeItemId === "__end__"` → move/insert at the very end.
|
|
45
|
-
* - anchor id found → insert immediately before it.
|
|
46
|
-
* - anchor id not found → fall through to the end (same
|
|
47
|
-
* forgiving behaviour as `moveContent`).
|
|
48
|
-
*
|
|
49
|
-
* Mutates `items` in place. `item` may be an existing element of `items`
|
|
50
|
-
* (a move) or a brand-new object (an insert).
|
|
51
|
-
*/
|
|
52
|
-
export declare const repositionItemByAnchor: <T extends {
|
|
53
|
-
id?: string | undefined;
|
|
54
|
-
}>(items: T[], item: T, moveBeforeItemId: string | undefined) => void;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
-
/**
|
|
3
|
-
* Sentinel anchor meaning "the end of the list", mirroring the section-level
|
|
4
|
-
* `move_before_content_id: "__end__"` convention used in base-section-builder.
|
|
5
|
-
*/
|
|
6
|
-
export const END_ITEM_ANCHOR = '__end__';
|
|
7
|
-
/** Generate a stable item id. Mirrors section-level `uuid.v4()` id generation. */
|
|
8
|
-
export const generateItemId = () => uuidv4();
|
|
9
|
-
/**
|
|
10
|
-
* Walk an entire BrandPageModel and backfill a stable uuid `id` onto every
|
|
11
|
-
* nested array item that lacks one (gallery images, images/shapes/testimonial
|
|
12
|
-
* items, text items, social links, and footer social links).
|
|
13
|
-
*
|
|
14
|
-
* BP-5603: this must run BEFORE the model is minified for the AI, so the same
|
|
15
|
-
* id the AI is shown (and copies into `item_id`) is the one the executor later
|
|
16
|
-
* matches. The maker holds a single live model instance for both the minify
|
|
17
|
-
* and the apply step, so mutating it here makes the ids round-trip; they then
|
|
18
|
-
* persist on the next save. Idempotent — existing ids are preserved.
|
|
19
|
-
*/
|
|
20
|
-
export const ensureBrandPageItemIds = (model) => {
|
|
21
|
-
const ensureContentItemIds = (content) => {
|
|
22
|
-
// Every array field that the minifier surfaces as a list of items.
|
|
23
|
-
for (const field of ['images', 'items', 'textItems', 'links']) {
|
|
24
|
-
const arr = content[field];
|
|
25
|
-
if (Array.isArray(arr))
|
|
26
|
-
ensureItemIds(arr);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
for (const page of model.pages ?? []) {
|
|
30
|
-
for (const content of page.contents ?? []) {
|
|
31
|
-
ensureContentItemIds(content);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
ensureItemIds(model.pageFooterDesktop?.socialLinks);
|
|
35
|
-
ensureItemIds(model.pageFooterMobile?.socialLinks);
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Backfill ids onto any items missing one. Per BP-5603 this runs in the
|
|
39
|
-
* metadata builder when a section is processed, so the persisted metadata
|
|
40
|
-
* returned to the client gains stable ids that subsequent AI tool calls can
|
|
41
|
-
* reference. Mutates in place.
|
|
42
|
-
*/
|
|
43
|
-
export const ensureItemIds = (items) => {
|
|
44
|
-
if (!items)
|
|
45
|
-
return;
|
|
46
|
-
for (const item of items) {
|
|
47
|
-
if (!item.id)
|
|
48
|
-
item.id = generateItemId();
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Remove items whose id appears in `ids`. Order-independent (no descending
|
|
53
|
-
* index sort needed) — the whole point of the id-based migration. Items
|
|
54
|
-
* without an id are never removed by id.
|
|
55
|
-
*/
|
|
56
|
-
export const removeItemsByIds = (items, ids) => {
|
|
57
|
-
if (!items?.length)
|
|
58
|
-
return items ?? [];
|
|
59
|
-
if (!ids?.length)
|
|
60
|
-
return items;
|
|
61
|
-
const toRemove = new Set(ids);
|
|
62
|
-
return items.filter((item) => !item.id || !toRemove.has(item.id));
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Position `item` within `items` relative to an anchor id — the item-level
|
|
66
|
-
* mirror of base-section-builder's `moveContent`:
|
|
67
|
-
*
|
|
68
|
-
* - `moveBeforeItemId === undefined` → leave an existing item where it is;
|
|
69
|
-
* append a new (not-yet-present) item to the end.
|
|
70
|
-
* - `moveBeforeItemId === "__end__"` → move/insert at the very end.
|
|
71
|
-
* - anchor id found → insert immediately before it.
|
|
72
|
-
* - anchor id not found → fall through to the end (same
|
|
73
|
-
* forgiving behaviour as `moveContent`).
|
|
74
|
-
*
|
|
75
|
-
* Mutates `items` in place. `item` may be an existing element of `items`
|
|
76
|
-
* (a move) or a brand-new object (an insert).
|
|
77
|
-
*/
|
|
78
|
-
export const repositionItemByAnchor = (items, item, moveBeforeItemId) => {
|
|
79
|
-
const currentIndex = items.indexOf(item);
|
|
80
|
-
if (moveBeforeItemId === undefined) {
|
|
81
|
-
if (currentIndex === -1)
|
|
82
|
-
items.push(item);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (currentIndex !== -1)
|
|
86
|
-
items.splice(currentIndex, 1);
|
|
87
|
-
const anchorIndex = moveBeforeItemId === END_ITEM_ANCHOR
|
|
88
|
-
? -1
|
|
89
|
-
: items.findIndex((i) => i.id === moveBeforeItemId);
|
|
90
|
-
if (anchorIndex !== -1) {
|
|
91
|
-
items.splice(anchorIndex, 0, item);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
items.push(item);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
END_ITEM_ANCHOR,
|
|
4
|
-
ensureBrandPageItemIds,
|
|
5
|
-
ensureItemIds,
|
|
6
|
-
generateItemId,
|
|
7
|
-
removeItemsByIds,
|
|
8
|
-
repositionItemByAnchor,
|
|
9
|
-
} from './item-id-utils';
|
|
10
|
-
import type { BrandPageModel } from '../../brand-page/models';
|
|
11
|
-
|
|
12
|
-
type Item = { id?: string; label: string };
|
|
13
|
-
|
|
14
|
-
const UUID_RE =
|
|
15
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
16
|
-
|
|
17
|
-
const items = (...labels: string[]): Item[] =>
|
|
18
|
-
labels.map((label) => ({ id: label, label }));
|
|
19
|
-
|
|
20
|
-
const labels = (list: Item[]): string[] => list.map((i) => i.label);
|
|
21
|
-
|
|
22
|
-
describe('generateItemId', () => {
|
|
23
|
-
it('returns unique uuid-shaped ids', () => {
|
|
24
|
-
const a = generateItemId();
|
|
25
|
-
const b = generateItemId();
|
|
26
|
-
|
|
27
|
-
expect(a).not.toBe(b);
|
|
28
|
-
expect(a).toMatch(
|
|
29
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('ensureItemIds', () => {
|
|
35
|
-
it('backfills only the items missing an id, preserving existing ones', () => {
|
|
36
|
-
const list: Item[] = [
|
|
37
|
-
{ id: 'keep', label: 'a' },
|
|
38
|
-
{ label: 'b' },
|
|
39
|
-
{ id: '', label: 'c' },
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
ensureItemIds(list);
|
|
43
|
-
|
|
44
|
-
expect(list[0].id).toBe('keep');
|
|
45
|
-
expect(list[1].id).toBeTruthy();
|
|
46
|
-
expect(list[2].id).toBeTruthy();
|
|
47
|
-
expect(new Set(list.map((i) => i.id)).size).toBe(3);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('is a no-op for undefined', () => {
|
|
51
|
-
expect(() => ensureItemIds(undefined)).not.toThrow();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('removeItemsByIds', () => {
|
|
56
|
-
it('removes by id regardless of order (no index shifting)', () => {
|
|
57
|
-
const result = removeItemsByIds(items('a', 'b', 'c', 'd'), ['c', 'a']);
|
|
58
|
-
|
|
59
|
-
expect(labels(result)).toEqual(['b', 'd']);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('returns the list unchanged when no ids given', () => {
|
|
63
|
-
const list = items('a', 'b');
|
|
64
|
-
|
|
65
|
-
expect(removeItemsByIds(list, undefined)).toBe(list);
|
|
66
|
-
expect(removeItemsByIds(list, [])).toBe(list);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('returns [] for undefined items', () => {
|
|
70
|
-
expect(removeItemsByIds(undefined, ['x'])).toEqual([]);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('repositionItemByAnchor', () => {
|
|
75
|
-
it('appends a new item when no anchor is given', () => {
|
|
76
|
-
const list = items('a', 'b');
|
|
77
|
-
|
|
78
|
-
repositionItemByAnchor(list, { id: 'new', label: 'new' }, undefined);
|
|
79
|
-
|
|
80
|
-
expect(labels(list)).toEqual(['a', 'b', 'new']);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('leaves an existing item in place when no anchor is given', () => {
|
|
84
|
-
const list = items('a', 'b', 'c');
|
|
85
|
-
|
|
86
|
-
repositionItemByAnchor(list, list[1], undefined);
|
|
87
|
-
|
|
88
|
-
expect(labels(list)).toEqual(['a', 'b', 'c']);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('inserts a new item before the anchor id', () => {
|
|
92
|
-
const list = items('a', 'b', 'c');
|
|
93
|
-
|
|
94
|
-
repositionItemByAnchor(list, { id: 'new', label: 'new' }, 'b');
|
|
95
|
-
|
|
96
|
-
expect(labels(list)).toEqual(['a', 'new', 'b', 'c']);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('moves an existing item before the anchor id', () => {
|
|
100
|
-
const list = items('a', 'b', 'c', 'd');
|
|
101
|
-
|
|
102
|
-
// move 'd' before 'b'
|
|
103
|
-
repositionItemByAnchor(list, list[3], 'b');
|
|
104
|
-
|
|
105
|
-
expect(labels(list)).toEqual(['a', 'd', 'b', 'c']);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('moves an existing item to the end with the __end__ sentinel', () => {
|
|
109
|
-
const list = items('a', 'b', 'c');
|
|
110
|
-
|
|
111
|
-
repositionItemByAnchor(list, list[0], END_ITEM_ANCHOR);
|
|
112
|
-
|
|
113
|
-
expect(labels(list)).toEqual(['b', 'c', 'a']);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('falls through to the end when the anchor id is not found', () => {
|
|
117
|
-
const list = items('a', 'b');
|
|
118
|
-
|
|
119
|
-
repositionItemByAnchor(list, { id: 'new', label: 'new' }, 'missing');
|
|
120
|
-
|
|
121
|
-
expect(labels(list)).toEqual(['a', 'b', 'new']);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('ensureBrandPageItemIds', () => {
|
|
126
|
-
const makeModel = (): BrandPageModel =>
|
|
127
|
-
({
|
|
128
|
-
pages: [
|
|
129
|
-
{
|
|
130
|
-
contents: [
|
|
131
|
-
{
|
|
132
|
-
type: 'image-gallery',
|
|
133
|
-
images: [{ imageUrl: 'a' }, { imageUrl: 'b' }],
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
type: 'testimonial-section',
|
|
137
|
-
items: [{ id: 'keep-me', name: 'X' }, { name: 'Y' }],
|
|
138
|
-
},
|
|
139
|
-
{ type: 'text', textItems: [{ text: 'hi' }] },
|
|
140
|
-
{ type: 'social-links', links: [{ url: 'u' }] },
|
|
141
|
-
{ type: 'divider-section' }, // no item arrays — must not throw
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
pageFooterDesktop: { socialLinks: [{ url: 'f' }] },
|
|
146
|
-
pageFooterMobile: { socialLinks: [{ url: 'm' }] },
|
|
147
|
-
}) as unknown as BrandPageModel;
|
|
148
|
-
|
|
149
|
-
it('stamps a uuid id onto every id-less nested item across sections + footer', () => {
|
|
150
|
-
const model = makeModel();
|
|
151
|
-
|
|
152
|
-
ensureBrandPageItemIds(model);
|
|
153
|
-
|
|
154
|
-
const c = model.pages[0].contents as any[];
|
|
155
|
-
|
|
156
|
-
expect(c[0].images[0].id).toMatch(UUID_RE);
|
|
157
|
-
expect(c[0].images[1].id).toMatch(UUID_RE);
|
|
158
|
-
expect(c[1].items[1].id).toMatch(UUID_RE);
|
|
159
|
-
expect(c[2].textItems[0].id).toMatch(UUID_RE);
|
|
160
|
-
expect(c[3].links[0].id).toMatch(UUID_RE);
|
|
161
|
-
expect((model.pageFooterDesktop as any).socialLinks[0].id).toMatch(UUID_RE);
|
|
162
|
-
expect((model.pageFooterMobile as any).socialLinks[0].id).toMatch(UUID_RE);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('preserves existing ids (idempotent)', () => {
|
|
166
|
-
const model = makeModel();
|
|
167
|
-
|
|
168
|
-
ensureBrandPageItemIds(model);
|
|
169
|
-
const first = (model.pages[0].contents as any[])[1].items[0].id;
|
|
170
|
-
|
|
171
|
-
ensureBrandPageItemIds(model);
|
|
172
|
-
const second = (model.pages[0].contents as any[])[1].items[0].id;
|
|
173
|
-
|
|
174
|
-
expect(first).toBe('keep-me');
|
|
175
|
-
expect(second).toBe('keep-me');
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('does not throw on an empty / partial model', () => {
|
|
179
|
-
expect(() => ensureBrandPageItemIds({} as BrandPageModel)).not.toThrow();
|
|
180
|
-
expect(() =>
|
|
181
|
-
ensureBrandPageItemIds({ pages: [] } as unknown as BrandPageModel),
|
|
182
|
-
).not.toThrow();
|
|
183
|
-
});
|
|
184
|
-
});
|