@designcrowd/library.brand-page 6.0.11 → 6.0.13
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-DopPc6g2.js → CreatedOnBrandCrowd-de-de-CBjFFeBP.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-en-us-CSHmaAWm.js → CreatedOnBrandCrowd-en-us-NuNXF81K.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-es-es-C4vM0p2e.js → CreatedOnBrandCrowd-es-es-BJG8nfug.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-fr-ArpBbnxm.js → CreatedOnBrandCrowd-fr-ca-uX-nL53e.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-fr-ca-ArpBbnxm.js → CreatedOnBrandCrowd-fr-fr-uX-nL53e.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-pt-CGAQLXiX.js → CreatedOnBrandCrowd-pt-br-DTrgFGQV.js} +1 -1
- package/lib/src/{CreatedOnBrandCrowd-pt-br-CGAQLXiX.js → CreatedOnBrandCrowd-pt-pt-DTrgFGQV.js} +1 -1
- package/lib/src/{CreatedOnDcom-de-de-3WVSgB6t.js → CreatedOnDcom-de-de-DSfpxioT.js} +1 -1
- package/lib/src/{CreatedOnDcom-en-us-Dx-RHXrH.js → CreatedOnDcom-en-us-C7G4gKem.js} +1 -1
- package/lib/src/{CreatedOnDcom-es-es-CfnEYFMA.js → CreatedOnDcom-es-es-DVckCaji.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-ca-BSHZTiUO.js → CreatedOnDcom-fr-ca-C5GDrm_C.js} +1 -1
- package/lib/src/{CreatedOnDcom-fr-fr-DtHssrQb.js → CreatedOnDcom-fr-fr-v5eMm-j2.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-br-CdX1aRI8.js → CreatedOnDcom-pt-br-Dq3-fPUc.js} +1 -1
- package/lib/src/{CreatedOnDcom-pt-pt-jy044FNL.js → CreatedOnDcom-pt-pt-DFsncYax.js} +1 -1
- package/lib/src/brand-page/components/image-gallery/ImageGallery.stories.js +3 -0
- package/lib/src/brand-page/components/image-gallery/masonry/MasonryGallery.mixin.d.ts +1 -1
- package/lib/src/brand-page/components/images-section/ImagesSection.stories.js +2 -1
- package/lib/src/brand-page/components/social-links/SocialLinks.stories.js +3 -0
- package/lib/src/brand-page/components/testimonial-section/__fixtures__/data.js +3 -0
- package/lib/src/brand-page/components/text/Text.stories.js +2 -0
- package/lib/src/brand-page/models/index.d.ts +13 -0
- package/lib/src/brand-page/models/index.js +4 -0
- package/lib/src/brand-page/utils/migration/migration-01.js +2 -0
- package/lib/src/brand-page/utils/migration/migration-18.d.ts +14 -0
- package/lib/src/brand-page/utils/migration/migration-18.js +17 -0
- package/lib/src/brand-page/utils/migration.util.js +6 -0
- package/lib/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.stories.js +1 -0
- package/lib/src/brand-page-maker/components/brand-page-maker/__fixtures__/brand-page-examples.js +1 -0
- package/lib/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.js +5 -0
- package/lib/src/brand-page-maker/constants/config-settings-constant.js +4 -0
- package/lib/src/brand-page-maker/models/content-settings.js +4 -0
- package/lib/src/brand-page-maker/stores/ai-checkpoint/ai-checkpoint-store.d.ts +18 -0
- package/lib/src/index.mjs +84 -83
- package/lib/src/{lib-Bx7xK4dn.js → lib-BG-pyXi9.js} +19585 -19807
- package/lib/src/metadata-builder/ai-metadata-executor.js +24 -1
- package/lib/src/metadata-builder/builders/footer-builder.js +32 -41
- package/lib/src/metadata-builder/builders/item-id-utils.d.ts +54 -0
- package/lib/src/metadata-builder/builders/item-id-utils.js +96 -0
- package/lib/src/metadata-builder/builders/move-page-builder.d.ts +32 -0
- package/lib/src/metadata-builder/builders/move-page-builder.js +137 -0
- package/lib/src/metadata-builder/builders/nav-utils.d.ts +26 -0
- package/lib/src/metadata-builder/builders/nav-utils.js +95 -0
- package/lib/src/metadata-builder/builders/section-builders/image-gallery-builder.js +57 -68
- package/lib/src/metadata-builder/builders/section-builders/images-section-builder.js +58 -93
- package/lib/src/metadata-builder/builders/section-builders/move-section-builder.d.ts +13 -1
- package/lib/src/metadata-builder/builders/section-builders/move-section-builder.js +40 -30
- package/lib/src/metadata-builder/builders/section-builders/shapes-section-builder.js +66 -99
- package/lib/src/metadata-builder/builders/section-builders/social-links-builder.js +57 -17
- package/lib/src/metadata-builder/builders/section-builders/testimonial-section-builder.js +51 -85
- package/lib/src/metadata-builder/builders/section-builders/text-section-builder.js +50 -74
- package/lib/src/metadata-builder/builders/section-field-maps.js +17 -0
- package/lib/src/metadata-builder/builders/set-page-visibility-builder.d.ts +23 -0
- package/lib/src/metadata-builder/builders/set-page-visibility-builder.js +83 -0
- package/lib/src/metadata-builder/metadata-executor.js +4 -0
- package/lib/src/metadata-builder/models.d.ts +2 -0
- package/lib/src/metadata-builder/models.js +2 -0
- package/lib/src/metadata-builder/parsers/ai-toolcall-parser.d.ts +31 -7
- package/lib/src/metadata-builder/parsers/ai-toolcall-parser.js +2 -0
- package/lib/src/metadata-builder/parsers/section-tool-arguments.d.ts +84 -48
- package/lib/src/shared/content-settings/components/links-field/LinksField.mixin.js +2 -0
- package/lib/src/shared/page-settings/components/page-settings/PageSettings.mixin.d.ts +2 -0
- package/lib/src/shared/page-settings/components/page-settings-section-styles/PageSettingsSectionStyles.mixin.d.ts +2 -0
- package/lib/src/tracker.d.ts +2 -0
- package/lib/src/tracker.js +12 -0
- package/lib/src/tracker.mjs +12 -0
- package/lib/src/useEventTracker-DmQ6AkNn.js +356 -0
- package/lib/src/utils/minify-brand-page-metadata.d.ts +2 -0
- package/lib/src/utils/minify-brand-page-metadata.js +8 -1
- package/package.json +16 -1
- package/src/brand-page/components/image-gallery/ImageGallery.stories.ts +3 -0
- package/src/brand-page/components/image-gallery/ImageGallery.test.ts +1 -0
- package/src/brand-page/components/image-gallery/masonry/MasonryGallery.mixin.ts +2 -1
- package/src/brand-page/components/images-section/ImagesSection.stories.ts +2 -1
- package/src/brand-page/components/social-links/SocialLinks.stories.ts +3 -0
- package/src/brand-page/components/social-links/SocialLinks.vue.test.ts +5 -0
- package/src/brand-page/components/testimonial-section/__fixtures__/data.ts +3 -0
- package/src/brand-page/components/text/Text.stories.ts +2 -0
- package/src/brand-page/models/index.ts +17 -0
- package/src/brand-page/utils/__snapshots__/migration.util.test.ts.snap +23 -3
- package/src/brand-page/utils/__snapshots__/migration2.util.test.ts.snap +6 -0
- package/src/brand-page/utils/__snapshots__/model.util.test.ts.snap +12 -0
- package/src/brand-page/utils/migration/migration-01.ts +2 -0
- package/src/brand-page/utils/migration/migration-18.test.ts +131 -0
- package/src/brand-page/utils/migration/migration-18.ts +22 -0
- package/src/brand-page/utils/migration.util.ts +7 -0
- package/src/brand-page/utils/personalisation.util.test.ts +4 -0
- package/src/brand-page-maker/components/brand-page-maker/BrandPageMaker.stories.ts +1 -0
- package/src/brand-page-maker/components/brand-page-maker/__fixtures__/brand-page-examples.ts +1 -0
- package/src/brand-page-maker/composables/ai-chat/useAiWebsiteBuilderChat.ts +6 -0
- package/src/brand-page-maker/constants/config-settings-constant.ts +4 -0
- package/src/brand-page-maker/models/content-settings.ts +4 -0
- package/src/metadata-builder/ai-metadata-executor.ts +31 -1
- package/src/metadata-builder/builders/footer-builder.test.ts +335 -28
- package/src/metadata-builder/builders/footer-builder.ts +40 -57
- package/src/metadata-builder/builders/item-id-utils.test.ts +184 -0
- package/src/metadata-builder/builders/item-id-utils.ts +117 -0
- package/src/metadata-builder/builders/move-page-builder.ts +227 -0
- package/src/metadata-builder/builders/nav-utils.ts +141 -0
- package/src/metadata-builder/builders/section-builders/image-gallery-builder.ts +62 -88
- package/src/metadata-builder/builders/section-builders/images-section-builder.ts +66 -129
- package/src/metadata-builder/builders/section-builders/move-section-builder.ts +58 -35
- package/src/metadata-builder/builders/section-builders/shapes-section-builder.ts +105 -160
- package/src/metadata-builder/builders/section-builders/social-links-builder.ts +65 -20
- package/src/metadata-builder/builders/section-builders/testimonial-section-builder.ts +83 -146
- package/src/metadata-builder/builders/section-builders/text-section-builder.ts +71 -122
- package/src/metadata-builder/builders/section-field-maps.ts +18 -0
- package/src/metadata-builder/builders/set-page-visibility-builder.ts +122 -0
- package/src/metadata-builder/metadata-executor.ts +4 -0
- package/src/metadata-builder/models.ts +2 -0
- package/src/metadata-builder/parsers/ai-toolcall-parser.ts +32 -7
- package/src/metadata-builder/parsers/section-tool-arguments.ts +84 -48
- package/src/shared/content-settings/components/links-field/LinksField.mixin.ts +2 -0
- package/src/tracker.ts +28 -0
- package/src/utils/minify-brand-page-metadata.ts +14 -2
- package/lib/src/metadata-builder/builders/reorder-pages-builder.d.ts +0 -13
- package/lib/src/metadata-builder/builders/reorder-pages-builder.js +0 -49
- package/src/metadata-builder/builders/reorder-pages-builder.ts +0 -80
|
@@ -45,7 +45,7 @@ export const executeToolCallsAsync = async (metadata, toolcalls, options) => {
|
|
|
45
45
|
type: BUILDER_TYPES.MOVE_SECTION,
|
|
46
46
|
payload: {
|
|
47
47
|
contentId: arg.content_id,
|
|
48
|
-
|
|
48
|
+
moveBeforeContentId: arg.move_before_content_id,
|
|
49
49
|
targetPageId: arg.target_page_id,
|
|
50
50
|
},
|
|
51
51
|
};
|
|
@@ -82,6 +82,29 @@ export const executeToolCallsAsync = async (metadata, toolcalls, options) => {
|
|
|
82
82
|
},
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
+
case AI_ASSISTANT_TOOL_NAMES.MOVE_PAGE: {
|
|
86
|
+
const arg = toolcall.arguments;
|
|
87
|
+
return {
|
|
88
|
+
id: toolcall.toolId,
|
|
89
|
+
type: BUILDER_TYPES.MOVE_PAGE,
|
|
90
|
+
payload: {
|
|
91
|
+
pageId: arg.page_id,
|
|
92
|
+
parentPageId: arg.parent_page_id,
|
|
93
|
+
moveBeforePageId: arg.move_before_page_id,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
case AI_ASSISTANT_TOOL_NAMES.SET_PAGE_VISIBILITY: {
|
|
98
|
+
const arg = toolcall.arguments;
|
|
99
|
+
return {
|
|
100
|
+
id: toolcall.toolId,
|
|
101
|
+
type: BUILDER_TYPES.SET_PAGE_VISIBILITY,
|
|
102
|
+
payload: {
|
|
103
|
+
pageId: arg.page_id,
|
|
104
|
+
isHidden: arg.is_hidden,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
85
108
|
case AI_ASSISTANT_TOOL_NAMES.UPDATE_FOOTER: {
|
|
86
109
|
const arg = toolcall.arguments;
|
|
87
110
|
return {
|
|
@@ -2,6 +2,7 @@ import {} from '../../brand-page/models';
|
|
|
2
2
|
import { BaseMetadataBuilder, } from '../models';
|
|
3
3
|
import { FOOTER_CHECKS } from './section-rules/footer.rules';
|
|
4
4
|
import { applyDetachedStyleOverride, normalizeStyleValue, } from './section-field-utils';
|
|
5
|
+
import { generateItemId, removeItemsByIds, repositionItemByAnchor, } from './item-id-utils';
|
|
5
6
|
const normaliseSocialUrl = (url) => {
|
|
6
7
|
for (const prefix of ['mailto:', 'tel:']) {
|
|
7
8
|
if (url.startsWith(prefix))
|
|
@@ -10,6 +11,7 @@ const normaliseSocialUrl = (url) => {
|
|
|
10
11
|
return url;
|
|
11
12
|
};
|
|
12
13
|
const makeSocialLink = (icon, url) => ({
|
|
14
|
+
id: generateItemId(),
|
|
13
15
|
imageUrl: icon || '',
|
|
14
16
|
url: normaliseSocialUrl(url || ''),
|
|
15
17
|
imageTitle: '',
|
|
@@ -18,8 +20,7 @@ const makeSocialLink = (icon, url) => ({
|
|
|
18
20
|
imageLink: '',
|
|
19
21
|
});
|
|
20
22
|
const hasSocialLinkMutation = (args) => args._replace_social_links === true ||
|
|
21
|
-
(args.
|
|
22
|
-
(args._reorder_social_links?.length ?? 0) > 0 ||
|
|
23
|
+
(args._remove_social_link_ids?.length ?? 0) > 0 ||
|
|
23
24
|
(args.social_links?.length ?? 0) > 0;
|
|
24
25
|
/**
|
|
25
26
|
* Social links are a GLOBAL footer concern — one logical list that both
|
|
@@ -41,47 +42,37 @@ const computeSocialLinks = (current, args) => {
|
|
|
41
42
|
if (args._replace_social_links) {
|
|
42
43
|
return (args.social_links ?? []).map((l) => makeSocialLink(l.social_link_icon, l.url));
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
//
|
|
45
|
+
// Work on fresh copies so `current` (which may be shared across viewports)
|
|
46
|
+
// is never mutated. Backfill ids on the copies so legacy links become
|
|
47
|
+
// referenceable by the id-based contract (BP-5603).
|
|
48
|
+
let links = (current ?? []).map((l) => ({
|
|
49
|
+
...l,
|
|
50
|
+
id: l.id || generateItemId(),
|
|
51
|
+
}));
|
|
52
|
+
// Remove by id — order-independent, no index shifting.
|
|
53
|
+
links = removeItemsByIds(links, args._remove_social_link_ids);
|
|
54
|
+
// Update existing links (item_id present) or insert new ones (no item_id);
|
|
55
|
+
// position/move via move_before_item_id ("__end__" or a missing anchor => end).
|
|
47
56
|
for (const link of args.social_links ?? []) {
|
|
48
|
-
if (link.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const sorted = [...args._remove_social_link_indices].sort((a, b) => b - a);
|
|
64
|
-
for (const idx of sorted) {
|
|
65
|
-
if (idx >= 0 && idx < links.length)
|
|
66
|
-
links.splice(idx, 1);
|
|
57
|
+
if (link.item_id) {
|
|
58
|
+
const index = links.findIndex((l) => l.id === link.item_id);
|
|
59
|
+
// Unknown id — skip rather than guess at a position.
|
|
60
|
+
if (index === -1)
|
|
61
|
+
continue;
|
|
62
|
+
links[index] = {
|
|
63
|
+
...links[index],
|
|
64
|
+
...(link.social_link_icon !== undefined
|
|
65
|
+
? { imageUrl: link.social_link_icon }
|
|
66
|
+
: {}),
|
|
67
|
+
...(link.url !== undefined
|
|
68
|
+
? { url: normaliseSocialUrl(link.url) }
|
|
69
|
+
: {}),
|
|
70
|
+
};
|
|
71
|
+
repositionItemByAnchor(links, links[index], link.move_before_item_id);
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const sortedInserts = [...insertLinks].sort((a, b) => b.insert_at - a.insert_at);
|
|
72
|
-
for (const link of sortedInserts) {
|
|
73
|
-
const pos = Math.max(0, Math.min(link.insert_at, links.length));
|
|
74
|
-
links.splice(pos, 0, makeSocialLink(link.social_link_icon, link.url));
|
|
75
|
-
}
|
|
76
|
-
// Reorder (requires ALL indices — partial reorder is not supported).
|
|
77
|
-
if (args._reorder_social_links?.length) {
|
|
78
|
-
const newOrder = args._reorder_social_links;
|
|
79
|
-
const unique = new Set(newOrder);
|
|
80
|
-
if (unique.size === newOrder.length &&
|
|
81
|
-
newOrder.every((idx) => idx >= 0 && idx < links.length)) {
|
|
82
|
-
const reordered = newOrder.map((idx) => links[idx]);
|
|
83
|
-
if (reordered.length === links.length)
|
|
84
|
-
return reordered;
|
|
73
|
+
else {
|
|
74
|
+
const newLink = makeSocialLink(link.social_link_icon, link.url);
|
|
75
|
+
repositionItemByAnchor(links, newLink, link.move_before_item_id);
|
|
85
76
|
}
|
|
86
77
|
}
|
|
87
78
|
return links;
|
|
@@ -0,0 +1,54 @@
|
|
|
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;
|
|
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;
|
|
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;
|
|
54
|
+
}>(items: T[], item: T, moveBeforeItemId: string | undefined) => void;
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BrandPageModel } from '../../brand-page/models';
|
|
2
|
+
import { BaseMetadataBuilder, type BuilderResult, type MetadataBuilderRequest } from '../models';
|
|
3
|
+
import type { Logger } from '../logger';
|
|
4
|
+
export interface MovePagePayload {
|
|
5
|
+
/** The page to move (resolved from page_id). */
|
|
6
|
+
pageId: string;
|
|
7
|
+
/**
|
|
8
|
+
* Destination parent: a page_id to nest under, or null/undefined for top-level.
|
|
9
|
+
* Analogous to move_section's target_page_id.
|
|
10
|
+
*/
|
|
11
|
+
parentPageId?: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Position anchor at the destination level: the page_id of the sibling to
|
|
14
|
+
* insert before, or "__end__" to append. Omitted/null → append at end.
|
|
15
|
+
* Analogous to move_section's move_before_content_id.
|
|
16
|
+
*/
|
|
17
|
+
moveBeforePageId?: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare class MovePageBuilder extends BaseMetadataBuilder<MovePagePayload> {
|
|
20
|
+
constructor(request: MetadataBuilderRequest<MovePagePayload>, logger?: Logger);
|
|
21
|
+
validateAsync(): Promise<{
|
|
22
|
+
errors: string[];
|
|
23
|
+
}>;
|
|
24
|
+
buildAsync(model: BrandPageModel): Promise<BuilderResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the insertion index within destinationOrders.
|
|
27
|
+
*
|
|
28
|
+
* moveBeforePageId anchors by pageId of a sibling at that level.
|
|
29
|
+
* "__end__" or omitted/null → append. Unknown anchor → append.
|
|
30
|
+
*/
|
|
31
|
+
private resolveIndex;
|
|
32
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { getPageSlugFromPageTitle } from '../../brand-page-maker/utils/slug.util';
|
|
2
|
+
import { BaseMetadataBuilder, } from '../models';
|
|
3
|
+
import { detachOrder, findOrderAnywhere, findParentRouteId, getSiblingSlugsAtDepth, syncPagesWithNavOrders, } from './nav-utils';
|
|
4
|
+
export class MovePageBuilder extends BaseMetadataBuilder {
|
|
5
|
+
constructor(request, logger) {
|
|
6
|
+
super(request, logger);
|
|
7
|
+
}
|
|
8
|
+
async validateAsync() {
|
|
9
|
+
const errors = [];
|
|
10
|
+
const payload = this.request.payload;
|
|
11
|
+
if (!payload?.pageId) {
|
|
12
|
+
errors.push('pageId is required for move_page');
|
|
13
|
+
}
|
|
14
|
+
return { errors };
|
|
15
|
+
}
|
|
16
|
+
async buildAsync(model) {
|
|
17
|
+
this.log('Build called');
|
|
18
|
+
const validation = await this.validateAsync();
|
|
19
|
+
if (validation.errors.length) {
|
|
20
|
+
return { request: this.request, model, errors: validation.errors };
|
|
21
|
+
}
|
|
22
|
+
const { pageId, parentPageId, moveBeforePageId } = this.request.payload;
|
|
23
|
+
// Build lookup: pageId → NavRoute.
|
|
24
|
+
const routeByPageId = new Map(model.nav.routes.map((r) => [r.pageId, r]));
|
|
25
|
+
// --- Find the target route ---
|
|
26
|
+
const targetRoute = routeByPageId.get(pageId);
|
|
27
|
+
if (!targetRoute) {
|
|
28
|
+
return {
|
|
29
|
+
request: this.request,
|
|
30
|
+
model,
|
|
31
|
+
errors: [`Page with ID "${pageId}" not found`],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const targetRouteId = targetRoute.id;
|
|
35
|
+
// Find the NavOrder for the target (must exist in the tree).
|
|
36
|
+
const targetOrder = findOrderAnywhere(model.nav.orders, targetRouteId);
|
|
37
|
+
if (!targetOrder) {
|
|
38
|
+
return {
|
|
39
|
+
request: this.request,
|
|
40
|
+
model,
|
|
41
|
+
errors: [`NavOrder for page "${pageId}" not found in nav.orders`],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// --- GUARD: parent cannot equal target ---
|
|
45
|
+
if (parentPageId && parentPageId === pageId) {
|
|
46
|
+
return {
|
|
47
|
+
request: this.request,
|
|
48
|
+
model,
|
|
49
|
+
errors: [`A page cannot be nested under itself`],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// --- GUARD: home page (orders[0]) cannot be nested ---
|
|
53
|
+
const homeRouteId = model.nav.orders[0]?.routeId;
|
|
54
|
+
if (parentPageId && homeRouteId === targetRouteId) {
|
|
55
|
+
return {
|
|
56
|
+
request: this.request,
|
|
57
|
+
model,
|
|
58
|
+
errors: [`Home page "${pageId}" cannot be nested under another page`],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// --- Resolve destination level ---
|
|
62
|
+
let destinationOrders;
|
|
63
|
+
if (parentPageId) {
|
|
64
|
+
const parentRoute = routeByPageId.get(parentPageId);
|
|
65
|
+
if (!parentRoute) {
|
|
66
|
+
return {
|
|
67
|
+
request: this.request,
|
|
68
|
+
model,
|
|
69
|
+
errors: [`Parent page with ID "${parentPageId}" not found`],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// GUARD: parent must be a root-level page (depth-1 cap).
|
|
73
|
+
const isParentAtRoot = model.nav.orders.some((o) => o.routeId === parentRoute.id);
|
|
74
|
+
if (!isParentAtRoot) {
|
|
75
|
+
return {
|
|
76
|
+
request: this.request,
|
|
77
|
+
model,
|
|
78
|
+
errors: [
|
|
79
|
+
`Parent page "${parentPageId}" is itself a subpage — nesting beyond depth 1 is not supported`,
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const parentOrder = findOrderAnywhere(model.nav.orders, parentRoute.id);
|
|
84
|
+
// GUARD: target page must not have its own subRoutes when being nested.
|
|
85
|
+
if (targetOrder.subRoutes.length > 0) {
|
|
86
|
+
return {
|
|
87
|
+
request: this.request,
|
|
88
|
+
model,
|
|
89
|
+
errors: [
|
|
90
|
+
`Page "${pageId}" has subpages and cannot itself be nested under another page`,
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
destinationOrders = parentOrder.subRoutes;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Moving to top level (un-nest or reorder at root).
|
|
98
|
+
destinationOrders = model.nav.orders;
|
|
99
|
+
}
|
|
100
|
+
// Record the old parent before any mutation for slug recompute.
|
|
101
|
+
const oldParentRouteId = findParentRouteId(model.nav.orders, targetRouteId);
|
|
102
|
+
// Detach the target from its current position.
|
|
103
|
+
detachOrder(model.nav.orders, targetRouteId);
|
|
104
|
+
// --- Resolve insertion index ---
|
|
105
|
+
const insertIndex = this.resolveIndex(destinationOrders, moveBeforePageId, routeByPageId);
|
|
106
|
+
destinationOrders.splice(insertIndex, 0, targetOrder);
|
|
107
|
+
// --- Slug recompute only when parent changed ---
|
|
108
|
+
const newParentRouteId = findParentRouteId(model.nav.orders, targetRouteId) ?? undefined;
|
|
109
|
+
// After detach+re-insert, undefined means root.
|
|
110
|
+
const effectiveOldParent = oldParentRouteId ?? undefined;
|
|
111
|
+
if (newParentRouteId !== effectiveOldParent) {
|
|
112
|
+
const siblingSlugs = getSiblingSlugsAtDepth(model, newParentRouteId, targetRouteId);
|
|
113
|
+
targetRoute.pageSlug = getPageSlugFromPageTitle(targetRoute.displayName, siblingSlugs);
|
|
114
|
+
}
|
|
115
|
+
syncPagesWithNavOrders(model);
|
|
116
|
+
this.log({
|
|
117
|
+
message: `Moved page "${pageId}" — parent: ${parentPageId ?? 'root'}, before: ${moveBeforePageId ?? 'end'}`,
|
|
118
|
+
});
|
|
119
|
+
return { request: this.request, model };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Resolve the insertion index within destinationOrders.
|
|
123
|
+
*
|
|
124
|
+
* moveBeforePageId anchors by pageId of a sibling at that level.
|
|
125
|
+
* "__end__" or omitted/null → append. Unknown anchor → append.
|
|
126
|
+
*/
|
|
127
|
+
resolveIndex(destinationOrders, moveBeforePageId, routeByPageId) {
|
|
128
|
+
if (!moveBeforePageId || moveBeforePageId === '__end__') {
|
|
129
|
+
return destinationOrders.length;
|
|
130
|
+
}
|
|
131
|
+
const anchorRoute = routeByPageId.get(moveBeforePageId);
|
|
132
|
+
if (!anchorRoute)
|
|
133
|
+
return destinationOrders.length;
|
|
134
|
+
const idx = destinationOrders.findIndex((o) => o.routeId === anchorRoute.id);
|
|
135
|
+
return idx !== -1 ? idx : destinationOrders.length;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BrandPageModel, NavOrder } from '../../brand-page/models';
|
|
2
|
+
/**
|
|
3
|
+
* Resync model.pages[] to match the DFS walk of model.nav.orders.
|
|
4
|
+
* Pages not referenced in nav are appended at the end (defensive).
|
|
5
|
+
* Mutates and returns model.pages in place.
|
|
6
|
+
*/
|
|
7
|
+
export declare const syncPagesWithNavOrders: (model: BrandPageModel) => BrandPageModel["pages"];
|
|
8
|
+
/**
|
|
9
|
+
* Find a NavOrder by routeId anywhere in the tree (root + subRoutes, recursive).
|
|
10
|
+
*/
|
|
11
|
+
export declare const findOrderAnywhere: (orders: NavOrder[], routeId: string) => NavOrder | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Find the routeId of the parent that contains the target as a direct child in subRoutes.
|
|
14
|
+
* Returns undefined when the target is a root order.
|
|
15
|
+
*/
|
|
16
|
+
export declare const findParentRouteId: (orders: NavOrder[], targetRouteId: string, _parentId?: string) => string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Splice the NavOrder with routeId from wherever it lives (root or any subRoutes), in place.
|
|
19
|
+
*/
|
|
20
|
+
export declare const detachOrder: (orders: NavOrder[], routeId: string) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Return the slugs of all routes that are direct children at the same depth as parentRouteId.
|
|
23
|
+
* - parentRouteId === undefined → root orders.
|
|
24
|
+
* - excludeRouteId is omitted from the result (pass the route being renamed/moved).
|
|
25
|
+
*/
|
|
26
|
+
export declare const getSiblingSlugsAtDepth: (model: BrandPageModel, parentRouteId: string | undefined, excludeRouteId: string) => string[];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DFS walk of nav.orders (recurse subRoutes), returning every routeId in visit order.
|
|
3
|
+
*/
|
|
4
|
+
const dfsRouteIds = (orders) => {
|
|
5
|
+
const ids = [];
|
|
6
|
+
for (const order of orders) {
|
|
7
|
+
ids.push(order.routeId);
|
|
8
|
+
ids.push(...dfsRouteIds(order.subRoutes));
|
|
9
|
+
}
|
|
10
|
+
return ids;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Resync model.pages[] to match the DFS walk of model.nav.orders.
|
|
14
|
+
* Pages not referenced in nav are appended at the end (defensive).
|
|
15
|
+
* Mutates and returns model.pages in place.
|
|
16
|
+
*/
|
|
17
|
+
export const syncPagesWithNavOrders = (model) => {
|
|
18
|
+
const routeIds = dfsRouteIds(model.nav.orders);
|
|
19
|
+
// Build a map from pageId to its nav position so we can sort pages by encounter order.
|
|
20
|
+
const routeById = new Map(model.nav.routes.map((r) => [r.id, r]));
|
|
21
|
+
// Map from pageId → DFS index (using route→pageId lookup).
|
|
22
|
+
const routeIdToDfsIndex = new Map(routeIds.map((rid, i) => [rid, i]));
|
|
23
|
+
// Convert nav routeId order to pageId order.
|
|
24
|
+
const pageIdOrder = new Map();
|
|
25
|
+
for (const [routeId, idx] of routeIdToDfsIndex) {
|
|
26
|
+
const route = routeById.get(routeId);
|
|
27
|
+
if (route) {
|
|
28
|
+
pageIdOrder.set(route.pageId, idx);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const navMax = routeIds.length;
|
|
32
|
+
model.pages = [...model.pages].sort((a, b) => {
|
|
33
|
+
const ia = pageIdOrder.has(a.id) ? pageIdOrder.get(a.id) : navMax;
|
|
34
|
+
const ib = pageIdOrder.has(b.id) ? pageIdOrder.get(b.id) : navMax;
|
|
35
|
+
return ia - ib;
|
|
36
|
+
});
|
|
37
|
+
return model.pages;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Find a NavOrder by routeId anywhere in the tree (root + subRoutes, recursive).
|
|
41
|
+
*/
|
|
42
|
+
export const findOrderAnywhere = (orders, routeId) => {
|
|
43
|
+
for (const order of orders) {
|
|
44
|
+
if (order.routeId === routeId)
|
|
45
|
+
return order;
|
|
46
|
+
const found = findOrderAnywhere(order.subRoutes, routeId);
|
|
47
|
+
if (found)
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Find the routeId of the parent that contains the target as a direct child in subRoutes.
|
|
54
|
+
* Returns undefined when the target is a root order.
|
|
55
|
+
*/
|
|
56
|
+
export const findParentRouteId = (orders, targetRouteId, _parentId) => {
|
|
57
|
+
for (const order of orders) {
|
|
58
|
+
if (order.subRoutes.some((sr) => sr.routeId === targetRouteId)) {
|
|
59
|
+
return order.routeId;
|
|
60
|
+
}
|
|
61
|
+
const found = findParentRouteId(order.subRoutes, targetRouteId, order.routeId);
|
|
62
|
+
if (found !== undefined)
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Splice the NavOrder with routeId from wherever it lives (root or any subRoutes), in place.
|
|
69
|
+
*/
|
|
70
|
+
export const detachOrder = (orders, routeId) => {
|
|
71
|
+
const idx = orders.findIndex((o) => o.routeId === routeId);
|
|
72
|
+
if (idx !== -1) {
|
|
73
|
+
orders.splice(idx, 1);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
for (const order of orders) {
|
|
77
|
+
detachOrder(order.subRoutes, routeId);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Return the slugs of all routes that are direct children at the same depth as parentRouteId.
|
|
82
|
+
* - parentRouteId === undefined → root orders.
|
|
83
|
+
* - excludeRouteId is omitted from the result (pass the route being renamed/moved).
|
|
84
|
+
*/
|
|
85
|
+
export const getSiblingSlugsAtDepth = (model, parentRouteId, excludeRouteId) => {
|
|
86
|
+
const siblingOrders = parentRouteId === undefined
|
|
87
|
+
? model.nav.orders
|
|
88
|
+
: (findOrderAnywhere(model.nav.orders, parentRouteId)?.subRoutes ?? []);
|
|
89
|
+
const siblingRouteIds = new Set(siblingOrders
|
|
90
|
+
.filter((o) => o.routeId !== excludeRouteId)
|
|
91
|
+
.map((o) => o.routeId));
|
|
92
|
+
return model.nav.routes
|
|
93
|
+
.filter((r) => siblingRouteIds.has(r.id))
|
|
94
|
+
.map((r) => r.pageSlug);
|
|
95
|
+
};
|