@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.19
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/LICENSE +21 -0
- package/README.md +128 -10
- package/dist/abi/canvas-live.d.ts +72 -0
- package/dist/abi/canvas-live.js +159 -0
- package/dist/abi/cart.d.ts +60 -0
- package/dist/abi/cart.js +396 -0
- package/dist/abi/convert.d.ts +360 -0
- package/dist/abi/convert.js +1330 -0
- package/dist/abi/data-api.d.ts +15 -0
- package/dist/abi/data-api.js +213 -0
- package/dist/abi/jcs.d.ts +6 -0
- package/dist/abi/jcs.js +28 -0
- package/dist/abi/labels.d.ts +3 -0
- package/dist/abi/labels.js +34 -0
- package/dist/abi/page-data.d.ts +264 -0
- package/dist/abi/page-data.js +746 -0
- package/dist/abi/page.d.ts +28 -0
- package/dist/abi/page.js +57 -0
- package/dist/abi/referrals.d.ts +23 -0
- package/dist/abi/referrals.js +89 -0
- package/dist/abi/rewards.d.ts +27 -0
- package/dist/abi/rewards.js +82 -0
- package/dist/abi/seo.d.ts +47 -0
- package/dist/abi/seo.js +68 -0
- package/dist/abi/shell.d.ts +23 -0
- package/dist/abi/shell.js +10 -0
- package/dist/abi/state-pack.d.ts +17 -0
- package/dist/abi/state-pack.js +43 -0
- package/dist/abi/wire.d.ts +46 -0
- package/dist/abi/wire.js +114 -0
- package/dist/build.d.ts +121 -0
- package/dist/build.js +401 -0
- package/dist/chunks.d.ts +23 -0
- package/dist/chunks.js +41 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.js +101 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +6 -0
- package/dist/headless/ai.d.ts +132 -0
- package/dist/headless/ai.js +99 -0
- package/dist/headless/hooks.d.ts +276 -0
- package/dist/headless/hooks.js +544 -0
- package/dist/headless/i18n.d.ts +13 -0
- package/dist/headless/i18n.js +45 -0
- package/dist/headless/index.d.ts +44 -0
- package/dist/headless/index.js +48 -0
- package/dist/headless/lazy-component.d.ts +72 -0
- package/dist/headless/lazy-component.js +225 -0
- package/dist/headless/lazy-section.d.ts +38 -0
- package/dist/headless/lazy-section.js +97 -0
- package/dist/headless/model.d.ts +73 -0
- package/dist/headless/model.js +115 -0
- package/dist/headless/money.d.ts +17 -0
- package/dist/headless/money.js +63 -0
- package/dist/headless/page.d.ts +45 -0
- package/dist/headless/page.js +53 -0
- package/dist/headless/platform.d.ts +55 -0
- package/dist/headless/platform.js +77 -0
- package/dist/headless/primitives/cart.d.ts +90 -0
- package/dist/headless/primitives/cart.js +153 -0
- package/dist/headless/primitives/collection.d.ts +68 -0
- package/dist/headless/primitives/collection.js +80 -0
- package/dist/headless/primitives/product.d.ts +101 -0
- package/dist/headless/primitives/product.js +117 -0
- package/dist/headless/primitives/storefront.d.ts +106 -0
- package/dist/headless/primitives/storefront.js +187 -0
- package/dist/headless/primitives/util.d.ts +19 -0
- package/dist/headless/primitives/util.js +42 -0
- package/dist/headless/strings.d.ts +9 -0
- package/dist/headless/strings.js +198 -0
- package/dist/headless/structured-data.d.ts +31 -0
- package/dist/headless/structured-data.js +57 -0
- package/dist/headless/tanqory-money.generated.d.ts +493 -0
- package/dist/headless/tanqory-money.generated.js +507 -0
- package/dist/headless/theme.d.ts +109 -0
- package/dist/headless/theme.js +62 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -553
- package/dist/runtime/data/StoreProvider.d.ts +84 -0
- package/dist/runtime/data/StoreProvider.js +380 -0
- package/dist/runtime/data/handle.d.ts +14 -0
- package/dist/runtime/data/handle.js +16 -0
- package/dist/runtime/data/routes.d.ts +87 -0
- package/dist/runtime/data/routes.js +158 -0
- package/dist/runtime/data/to-ui.d.ts +286 -0
- package/dist/runtime/data/to-ui.js +1009 -0
- package/dist/runtime/entries/register.d.ts +9 -0
- package/dist/runtime/entries/register.js +9 -0
- package/dist/runtime/entries/sections.d.ts +16 -0
- package/dist/runtime/entries/sections.js +19 -0
- package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
- package/dist/runtime/kit/SectionTree.js +100 -0
- package/dist/runtime/kit/analytics.d.ts +63 -0
- package/dist/runtime/kit/analytics.js +250 -0
- package/dist/runtime/kit/cart.d.ts +222 -0
- package/dist/runtime/kit/cart.js +545 -0
- package/dist/{types → runtime/kit}/composition.d.ts +1 -1
- package/dist/runtime/kit/composition.js +3 -0
- package/dist/{types → runtime/kit}/config.d.ts +2 -2
- package/dist/runtime/kit/config.js +6 -0
- package/dist/runtime/kit/consent.d.ts +29 -0
- package/dist/runtime/kit/consent.js +159 -0
- package/dist/runtime/kit/contract/content.d.ts +213 -0
- package/dist/runtime/kit/contract/content.js +119 -0
- package/dist/runtime/kit/contract/field-types.d.ts +360 -0
- package/dist/runtime/kit/contract/field-types.js +216 -0
- package/dist/runtime/kit/contract/groups.d.ts +230 -0
- package/dist/runtime/kit/contract/groups.js +402 -0
- package/dist/runtime/kit/contract/index.d.ts +33 -0
- package/dist/runtime/kit/contract/index.js +33 -0
- package/dist/runtime/kit/contract/transform.d.ts +82 -0
- package/dist/runtime/kit/contract/transform.js +133 -0
- package/dist/runtime/kit/contract/validate.d.ts +77 -0
- package/dist/runtime/kit/contract/validate.js +520 -0
- package/dist/runtime/kit/data.d.ts +732 -0
- package/dist/runtime/kit/data.js +1131 -0
- package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
- package/dist/runtime/kit/defineSection.js +10 -0
- package/dist/runtime/kit/dynamic-source.d.ts +118 -0
- package/dist/runtime/kit/dynamic-source.js +311 -0
- package/dist/runtime/kit/index.d.ts +24 -0
- package/dist/runtime/kit/index.js +24 -0
- package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
- package/dist/runtime/kit/jsx-to-json.js +28 -0
- package/dist/{types → runtime/kit}/mount.d.ts +25 -4
- package/dist/runtime/kit/mount.js +124 -0
- package/dist/{types → runtime/kit}/registry.d.ts +1 -1
- package/dist/runtime/kit/registry.js +12 -0
- package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
- package/dist/runtime/kit/ssg.js +56 -0
- package/dist/runtime/kit/storefront.d.ts +652 -0
- package/dist/runtime/kit/storefront.js +723 -0
- package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
- package/dist/runtime/kit/theme-context.js +25 -0
- package/dist/runtime/kit/types.d.ts +155 -0
- package/dist/runtime/kit/types.js +1 -0
- package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
- package/dist/runtime/platform/TrackingPixels.js +63 -0
- package/dist/runtime/platform/environment.d.ts +68 -0
- package/dist/runtime/platform/environment.js +85 -0
- package/dist/runtime/platform/locale.d.ts +27 -0
- package/dist/runtime/platform/locale.js +42 -0
- package/dist/runtime/platform/route-analytics.d.ts +15 -0
- package/dist/runtime/platform/route-analytics.js +72 -0
- package/dist/runtime/platform/safe-href.d.ts +25 -0
- package/dist/runtime/platform/safe-href.js +69 -0
- package/dist/runtime/platform/safe-values.d.ts +37 -0
- package/dist/runtime/platform/safe-values.js +140 -0
- package/dist/runtime/render/SectionRenderer.d.ts +4 -0
- package/dist/runtime/render/SectionRenderer.js +199 -0
- package/dist/runtime/render/listing-query.d.ts +52 -0
- package/dist/runtime/render/listing-query.js +122 -0
- package/dist/runtime/render/localized-copy.d.ts +86 -0
- package/dist/runtime/render/localized-copy.js +129 -0
- package/dist/runtime/render/product-listing.d.ts +11 -0
- package/dist/runtime/render/product-listing.js +243 -0
- package/dist/runtime/render/resolved.d.ts +47 -0
- package/dist/runtime/render/resolved.js +80 -0
- package/dist/runtime/render/section-actions.d.ts +67 -0
- package/dist/runtime/render/section-actions.js +205 -0
- package/dist/runtime/render/starter.d.ts +11 -0
- package/dist/runtime/render/starter.js +96 -0
- package/dist/runtime/seo/head.d.ts +115 -0
- package/dist/runtime/seo/head.js +281 -0
- package/dist/runtime/seo/structured-data.d.ts +83 -0
- package/dist/runtime/seo/structured-data.js +252 -0
- package/dist/runtime/shell/PageShell.d.ts +18 -0
- package/dist/runtime/shell/PageShell.js +118 -0
- package/dist/runtime/shell/RuntimeBridge.d.ts +18 -0
- package/dist/runtime/shell/RuntimeBridge.js +124 -0
- package/dist/runtime/shell/overlay-state.d.ts +31 -0
- package/dist/runtime/shell/overlay-state.js +59 -0
- package/dist/runtime/shell/preview-mode.d.ts +2 -0
- package/dist/runtime/shell/preview-mode.js +11 -0
- package/dist/runtime/shell/spa-router.d.ts +14 -0
- package/dist/runtime/shell/spa-router.js +76 -0
- package/dist/runtime/shell/url-redirects.d.ts +6 -0
- package/dist/runtime/shell/url-redirects.js +37 -0
- package/dist/runtime/slots.d.ts +74 -0
- package/dist/runtime/slots.js +16 -0
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.js +40 -0
- package/dist/sdk/app-block.d.ts +29 -0
- package/dist/sdk/app-block.js +22 -0
- package/dist/sdk/font-hooks.d.ts +7 -0
- package/dist/sdk/font-hooks.js +21 -0
- package/dist/sdk/fonts.d.ts +144 -0
- package/dist/sdk/fonts.js +241 -0
- package/dist/sdk/index.d.ts +32 -0
- package/dist/sdk/index.js +36 -0
- package/dist/sdk/motion-hooks.d.ts +23 -0
- package/dist/sdk/motion-hooks.js +46 -0
- package/dist/sdk/motion.d.ts +78 -0
- package/dist/sdk/motion.js +292 -0
- package/dist/sdk/referrals.d.ts +62 -0
- package/dist/sdk/referrals.js +20 -0
- package/dist/sdk/rewards.d.ts +85 -0
- package/dist/sdk/rewards.js +29 -0
- package/dist/sdk/runtime-context.d.ts +230 -0
- package/dist/sdk/runtime-context.js +73 -0
- package/dist/sdk/schema.d.ts +249 -0
- package/dist/sdk/schema.js +168 -0
- package/dist/sdk/server-render.d.ts +8 -0
- package/dist/sdk/server-render.js +12 -0
- package/dist/sdk/store-lookup.d.ts +32 -0
- package/dist/sdk/store-lookup.js +48 -0
- package/dist/sdk/store.d.ts +164 -0
- package/dist/sdk/store.js +5 -0
- package/dist/sdk/sx.d.ts +45 -0
- package/dist/sdk/sx.js +117 -0
- package/dist/sdk/theme.d.ts +212 -0
- package/dist/sdk/theme.js +27 -0
- package/dist/sdk/types.d.ts +789 -0
- package/dist/sdk/types.js +7 -0
- package/dist/server.d.ts +112 -0
- package/dist/server.js +589 -0
- package/dist/vite-chunks.d.ts +10 -0
- package/dist/vite-chunks.js +44 -0
- package/docs/headless-api.md +250 -0
- package/package.json +72 -26
- package/dist/index.js.map +0 -1
- package/dist/ssg-BZ5FYTw7.js +0 -1802
- package/dist/ssg-BZ5FYTw7.js.map +0 -1
- package/dist/ssg.js +0 -8
- package/dist/ssg.js.map +0 -1
- package/dist/types/cart.d.ts +0 -86
- package/dist/types/data.d.ts +0 -357
- package/dist/types/dynamic-source.d.ts +0 -84
- package/dist/types/editor.d.ts +0 -5
- package/dist/types/index.d.ts +0 -20
- package/dist/types/preview-bridge.d.ts +0 -9
- package/dist/types/storefront.d.ts +0 -333
- package/dist/types/types.d.ts +0 -44
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Section groups — the shared header/footer contract.
|
|
3
|
+
*
|
|
4
|
+
* The problem this solves: every template carried its own copy of the header
|
|
5
|
+
* and footer (17 of Nova's 18 templates, and all 12 marketplace forks). Editing
|
|
6
|
+
* the header on the home page changed the home page only; the other sixteen
|
|
7
|
+
* copies drifted silently, and there was no way to say "this page is different
|
|
8
|
+
* on purpose" versus "nobody updated this copy".
|
|
9
|
+
*
|
|
10
|
+
* The model, in Tanqory's JSON-tree vocabulary:
|
|
11
|
+
*
|
|
12
|
+
* groups/<name>.json ONE source of truth per shared slot:
|
|
13
|
+
* { "type": "header", "sections": [ …ContractNode ] }
|
|
14
|
+
*
|
|
15
|
+
* templates/<slug>.json references the group instead of copying it:
|
|
16
|
+
* { "groups": { "header": "header", "footer": "footer" },
|
|
17
|
+
* "sections": [ …template-area sections only ] }
|
|
18
|
+
*
|
|
19
|
+
* or overrides it for THIS page, explicitly:
|
|
20
|
+
* { "groups": { "header": { "override": [ …nodes ] } } }
|
|
21
|
+
*
|
|
22
|
+
* `resolvePage` is the ONLY function that turns a template + its groups into
|
|
23
|
+
* the flat section list the runtime renders. The storefront, the SSG, the
|
|
24
|
+
* editor preview bridge, studio-api and the AI tools all call it, so "what
|
|
25
|
+
* does this page render" cannot be answered two different ways.
|
|
26
|
+
*
|
|
27
|
+
* Backward compatibility is total: a template with no `groups` key and inline
|
|
28
|
+
* header/footer sections (every template that exists today) resolves exactly
|
|
29
|
+
* as it did — those inline sections are treated as an implicit per-page
|
|
30
|
+
* override. Nothing has to migrate to keep working; migrating is what makes the
|
|
31
|
+
* header SHARED.
|
|
32
|
+
*/
|
|
33
|
+
import { type ContractNode, type ContractPageDoc } from './content.js';
|
|
34
|
+
/** The slots a group can fill. `template` is the page body and is never shared. */
|
|
35
|
+
export type GroupSlot = 'header' | 'footer';
|
|
36
|
+
export declare const GROUP_SLOTS: readonly GroupSlot[];
|
|
37
|
+
/** A shared section group as stored at `groups/<name>.json`. */
|
|
38
|
+
export interface SectionGroupDoc {
|
|
39
|
+
/** Which slot this group fills. */
|
|
40
|
+
type: GroupSlot;
|
|
41
|
+
/** Human label for the editor; defaults to the file name. */
|
|
42
|
+
name?: string;
|
|
43
|
+
sections: ContractNode[];
|
|
44
|
+
contentVersion?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* How a template binds a slot.
|
|
48
|
+
* - a string → shorthand for `{ ref: <name> }`
|
|
49
|
+
* - `{ ref }` → the shared group at `groups/<ref>.json`
|
|
50
|
+
* - `{ override: [...] }`→ a page-specific composition; the shared group is
|
|
51
|
+
* NOT rendered on this page
|
|
52
|
+
*/
|
|
53
|
+
export type GroupBinding = string | {
|
|
54
|
+
ref: string;
|
|
55
|
+
} | {
|
|
56
|
+
override: ContractNode[];
|
|
57
|
+
};
|
|
58
|
+
/** A template that knows about groups. Superset of `ContractPageDoc`. */
|
|
59
|
+
export interface GroupedPageDoc extends ContractPageDoc {
|
|
60
|
+
groups?: Partial<Record<GroupSlot, GroupBinding>>;
|
|
61
|
+
}
|
|
62
|
+
/** Where a resolved node came from — what the editor shows and what a save must respect. */
|
|
63
|
+
export type NodeSource = {
|
|
64
|
+
kind: 'group';
|
|
65
|
+
slot: GroupSlot;
|
|
66
|
+
group: string;
|
|
67
|
+
} | {
|
|
68
|
+
kind: 'override';
|
|
69
|
+
slot: GroupSlot;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'inline';
|
|
72
|
+
slot: GroupSlot;
|
|
73
|
+
} | {
|
|
74
|
+
kind: 'template';
|
|
75
|
+
};
|
|
76
|
+
export interface SlotResolution {
|
|
77
|
+
/** `ref` = shared group · `override` = explicit per-page · `inline` = legacy
|
|
78
|
+
* inline sections (implicit per-page) · `none` = the slot is empty. */
|
|
79
|
+
mode: 'ref' | 'override' | 'inline' | 'none';
|
|
80
|
+
group?: string;
|
|
81
|
+
sections: ContractNode[];
|
|
82
|
+
}
|
|
83
|
+
export interface ResolvedPage {
|
|
84
|
+
/** The flat list the runtime renders: header → template → footer. */
|
|
85
|
+
sections: ContractNode[];
|
|
86
|
+
/** nodeId → provenance. Every top-level node has an entry. */
|
|
87
|
+
provenance: Record<string, NodeSource>;
|
|
88
|
+
slots: Record<GroupSlot, SlotResolution>;
|
|
89
|
+
/** Groups that were referenced but not supplied — rendered as empty, reported here. */
|
|
90
|
+
missingGroups: string[];
|
|
91
|
+
}
|
|
92
|
+
export type GroupMap = Record<string, SectionGroupDoc>;
|
|
93
|
+
/** The slot a legacy inline node belongs to, from `area` first, then its type. */
|
|
94
|
+
export declare function inlineSlotOf(node: ContractNode): GroupSlot | 'template';
|
|
95
|
+
/**
|
|
96
|
+
* Resolve a template into the section list the runtime renders.
|
|
97
|
+
*
|
|
98
|
+
* Pure and deterministic: the same template + groups always produce the same
|
|
99
|
+
* list, so the storefront, the SSG, the preview and the editor agree by
|
|
100
|
+
* construction rather than by discipline.
|
|
101
|
+
*/
|
|
102
|
+
export declare function resolvePage(template: GroupedPageDoc, groups?: GroupMap): ResolvedPage;
|
|
103
|
+
export interface SplitResult {
|
|
104
|
+
template: GroupedPageDoc;
|
|
105
|
+
/** Only the groups whose sections were part of this page and may have changed. */
|
|
106
|
+
groups: Partial<Record<GroupSlot, {
|
|
107
|
+
name: string;
|
|
108
|
+
doc: SectionGroupDoc;
|
|
109
|
+
}>>;
|
|
110
|
+
}
|
|
111
|
+
export interface SplitOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Per slot, how the saved template should bind. Omitted slots keep the mode
|
|
114
|
+
* they were resolved with. `ref` needs a group name (the one to write to);
|
|
115
|
+
* `override` freezes the current nodes into the template; `none` drops the
|
|
116
|
+
* slot from this page.
|
|
117
|
+
*/
|
|
118
|
+
slots?: Partial<Record<GroupSlot, {
|
|
119
|
+
mode: 'ref';
|
|
120
|
+
group: string;
|
|
121
|
+
} | {
|
|
122
|
+
mode: 'override';
|
|
123
|
+
} | {
|
|
124
|
+
mode: 'none';
|
|
125
|
+
}>>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The inverse of `resolvePage`: take an edited flat list plus the provenance
|
|
129
|
+
* it was resolved with, and produce what to write to the template and to each
|
|
130
|
+
* group file.
|
|
131
|
+
*
|
|
132
|
+
* Rules that make this safe for a shared group:
|
|
133
|
+
* - A node whose provenance says `group` goes back to that group — and ONLY
|
|
134
|
+
* if the slot is still bound to that group. Nothing about a template save
|
|
135
|
+
* can silently rewrite a group the page no longer references.
|
|
136
|
+
* - A node with no provenance (newly inserted) lands where its `area` says.
|
|
137
|
+
* Inserted into a `ref`-bound slot, it becomes part of the shared group —
|
|
138
|
+
* that is the merchant editing "the header", which is shared by design and
|
|
139
|
+
* is reported as such by `groupImpact`.
|
|
140
|
+
* - Body nodes carry no `area` on disk unless they already had one, so a
|
|
141
|
+
* template that never used `area` on body nodes stays byte-identical.
|
|
142
|
+
*/
|
|
143
|
+
export declare function splitPage(sections: ContractNode[], previous: ResolvedPage, opts?: SplitOptions): SplitResult;
|
|
144
|
+
/**
|
|
145
|
+
* Attach the source template to a resolution so `splitPage` can preserve any
|
|
146
|
+
* top-level keys it does not model (`contentVersion`, future additions).
|
|
147
|
+
*/
|
|
148
|
+
export declare function resolvePageFrom(template: GroupedPageDoc, groups?: GroupMap): ResolvedPage & {
|
|
149
|
+
template: GroupedPageDoc;
|
|
150
|
+
};
|
|
151
|
+
/** Which templates render a given group — the blast radius of editing it. */
|
|
152
|
+
export declare function groupImpact(groupName: string, templates: Record<string, GroupedPageDoc>): string[];
|
|
153
|
+
export interface ExtractOptions {
|
|
154
|
+
/**
|
|
155
|
+
* Attribute defaults per section type, so two copies that differ only by an
|
|
156
|
+
* explicitly-written default (`{}` vs `{ sticky: 'always' }` when `always`
|
|
157
|
+
* IS the default) compare equal. Without this, the design-converted home
|
|
158
|
+
* page would look "different" from seventeen pages that merely omit defaults.
|
|
159
|
+
*/
|
|
160
|
+
defaults?: Record<string, Record<string, unknown>>;
|
|
161
|
+
/** Group file names to write. */
|
|
162
|
+
names?: Partial<Record<GroupSlot, string>>;
|
|
163
|
+
}
|
|
164
|
+
export interface ExtractReport {
|
|
165
|
+
slot: GroupSlot;
|
|
166
|
+
group: string;
|
|
167
|
+
/** The signature that won and the templates that carried it. */
|
|
168
|
+
canonical: {
|
|
169
|
+
signature: string;
|
|
170
|
+
templates: string[];
|
|
171
|
+
};
|
|
172
|
+
/** Templates whose copy differs — kept as explicit overrides, never merged. */
|
|
173
|
+
overrides: Array<{
|
|
174
|
+
template: string;
|
|
175
|
+
signature: string;
|
|
176
|
+
differences: string[];
|
|
177
|
+
}>;
|
|
178
|
+
/** Templates that carried no section in this slot. */
|
|
179
|
+
empty: string[];
|
|
180
|
+
/** Templates that already bind this slot (a re-run) — untouched. */
|
|
181
|
+
alreadyBound: string[];
|
|
182
|
+
/**
|
|
183
|
+
* Ids that change for a template that binds the group: its own copy carried
|
|
184
|
+
* the same content under different ids, and a shared group has one set of
|
|
185
|
+
* ids. Reported so nothing about a merchant's ids changes silently; an
|
|
186
|
+
* override keeps every id verbatim.
|
|
187
|
+
*/
|
|
188
|
+
idRemaps: Array<{
|
|
189
|
+
template: string;
|
|
190
|
+
from: string;
|
|
191
|
+
to: string;
|
|
192
|
+
}>;
|
|
193
|
+
}
|
|
194
|
+
export interface ExtractResult {
|
|
195
|
+
groups: Partial<Record<GroupSlot, {
|
|
196
|
+
name: string;
|
|
197
|
+
doc: SectionGroupDoc;
|
|
198
|
+
}>>;
|
|
199
|
+
templates: Record<string, GroupedPageDoc>;
|
|
200
|
+
report: ExtractReport[];
|
|
201
|
+
/** True when nothing needed to change — the second run of a migration. */
|
|
202
|
+
noop: boolean;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Canonical comparison form for a slot's nodes: type + settings-with-defaults
|
|
206
|
+
* + blocks, with ids REMOVED. Ids are identity, not content; two pages whose
|
|
207
|
+
* headers differ only in id are the same header.
|
|
208
|
+
*/
|
|
209
|
+
export declare function slotSignature(nodes: ContractNode[], defaults?: ExtractOptions['defaults']): string;
|
|
210
|
+
/**
|
|
211
|
+
* Turn per-template inline header/footer copies into shared groups.
|
|
212
|
+
*
|
|
213
|
+
* Deterministic and idempotent:
|
|
214
|
+
* - The canonical composition for a slot is the one the MOST templates carry
|
|
215
|
+
* (ties broken by the alphabetically-first template that carries it).
|
|
216
|
+
* - A template whose copy matches canonical (after defaults) binds the group.
|
|
217
|
+
* - A template whose copy differs keeps its own nodes as an explicit
|
|
218
|
+
* `override` — the difference is REPORTED, never merged away.
|
|
219
|
+
* - A template with nothing in the slot binds nothing for it.
|
|
220
|
+
* - A template that already binds the slot is left alone, so running the
|
|
221
|
+
* migration twice changes nothing (`noop: true`).
|
|
222
|
+
*
|
|
223
|
+
* Ids, settings, blocks and order are carried verbatim into the group and into
|
|
224
|
+
* every override; nothing is re-minted.
|
|
225
|
+
*/
|
|
226
|
+
export declare function extractGroups(templates: Record<string, GroupedPageDoc>, opts?: ExtractOptions): ExtractResult;
|
|
227
|
+
/** Validate a group document's own shape (the content validator checks its nodes). */
|
|
228
|
+
export declare function isSectionGroupDoc(v: unknown): v is SectionGroupDoc;
|
|
229
|
+
/** Group file names must be safe path segments. */
|
|
230
|
+
export declare const GROUP_NAME_PATTERN: RegExp;
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Section groups — the shared header/footer contract.
|
|
3
|
+
*
|
|
4
|
+
* The problem this solves: every template carried its own copy of the header
|
|
5
|
+
* and footer (17 of Nova's 18 templates, and all 12 marketplace forks). Editing
|
|
6
|
+
* the header on the home page changed the home page only; the other sixteen
|
|
7
|
+
* copies drifted silently, and there was no way to say "this page is different
|
|
8
|
+
* on purpose" versus "nobody updated this copy".
|
|
9
|
+
*
|
|
10
|
+
* The model, in Tanqory's JSON-tree vocabulary:
|
|
11
|
+
*
|
|
12
|
+
* groups/<name>.json ONE source of truth per shared slot:
|
|
13
|
+
* { "type": "header", "sections": [ …ContractNode ] }
|
|
14
|
+
*
|
|
15
|
+
* templates/<slug>.json references the group instead of copying it:
|
|
16
|
+
* { "groups": { "header": "header", "footer": "footer" },
|
|
17
|
+
* "sections": [ …template-area sections only ] }
|
|
18
|
+
*
|
|
19
|
+
* or overrides it for THIS page, explicitly:
|
|
20
|
+
* { "groups": { "header": { "override": [ …nodes ] } } }
|
|
21
|
+
*
|
|
22
|
+
* `resolvePage` is the ONLY function that turns a template + its groups into
|
|
23
|
+
* the flat section list the runtime renders. The storefront, the SSG, the
|
|
24
|
+
* editor preview bridge, studio-api and the AI tools all call it, so "what
|
|
25
|
+
* does this page render" cannot be answered two different ways.
|
|
26
|
+
*
|
|
27
|
+
* Backward compatibility is total: a template with no `groups` key and inline
|
|
28
|
+
* header/footer sections (every template that exists today) resolves exactly
|
|
29
|
+
* as it did — those inline sections are treated as an implicit per-page
|
|
30
|
+
* override. Nothing has to migrate to keep working; migrating is what makes the
|
|
31
|
+
* header SHARED.
|
|
32
|
+
*/
|
|
33
|
+
import { NODE_ID_PATTERN } from './content.js';
|
|
34
|
+
export const GROUP_SLOTS = ['header', 'footer'];
|
|
35
|
+
const bindingOf = (b) => {
|
|
36
|
+
if (b === undefined || b === null)
|
|
37
|
+
return null;
|
|
38
|
+
if (typeof b === 'string')
|
|
39
|
+
return { ref: b };
|
|
40
|
+
if (typeof b === 'object') {
|
|
41
|
+
if ('override' in b && Array.isArray(b.override))
|
|
42
|
+
return { override: b.override };
|
|
43
|
+
if ('ref' in b && typeof b.ref === 'string')
|
|
44
|
+
return { ref: b.ref };
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
/** The slot a legacy inline node belongs to, from `area` first, then its type. */
|
|
49
|
+
export function inlineSlotOf(node) {
|
|
50
|
+
const area = node?.area;
|
|
51
|
+
if (area === 'header' || area === 'footer')
|
|
52
|
+
return area;
|
|
53
|
+
if (area === 'template')
|
|
54
|
+
return 'template';
|
|
55
|
+
if (node?.type === 'header')
|
|
56
|
+
return 'header';
|
|
57
|
+
if (node?.type === 'footer')
|
|
58
|
+
return 'footer';
|
|
59
|
+
return 'template';
|
|
60
|
+
}
|
|
61
|
+
const withArea = (node, area) => node.area === area ? node : { ...node, area };
|
|
62
|
+
/**
|
|
63
|
+
* Resolve a template into the section list the runtime renders.
|
|
64
|
+
*
|
|
65
|
+
* Pure and deterministic: the same template + groups always produce the same
|
|
66
|
+
* list, so the storefront, the SSG, the preview and the editor agree by
|
|
67
|
+
* construction rather than by discipline.
|
|
68
|
+
*/
|
|
69
|
+
export function resolvePage(template, groups = {}) {
|
|
70
|
+
const provenance = {};
|
|
71
|
+
const missingGroups = [];
|
|
72
|
+
const all = Array.isArray(template?.sections) ? template.sections : [];
|
|
73
|
+
// Legacy inline nodes are bucketed by slot once; a template that binds a slot
|
|
74
|
+
// explicitly ignores any inline node for that slot (the binding wins).
|
|
75
|
+
const inline = { header: [], template: [], footer: [] };
|
|
76
|
+
for (const node of all)
|
|
77
|
+
inline[inlineSlotOf(node)].push(node);
|
|
78
|
+
const slots = {};
|
|
79
|
+
for (const slot of GROUP_SLOTS) {
|
|
80
|
+
const b = bindingOf(template?.groups?.[slot]);
|
|
81
|
+
if (b?.ref !== undefined) {
|
|
82
|
+
const g = groups[b.ref];
|
|
83
|
+
if (!g) {
|
|
84
|
+
missingGroups.push(b.ref);
|
|
85
|
+
slots[slot] = { mode: 'ref', group: b.ref, sections: [] };
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const sections = (Array.isArray(g.sections) ? g.sections : []).map((n) => withArea(n, slot));
|
|
89
|
+
for (const n of sections)
|
|
90
|
+
if (n.id)
|
|
91
|
+
provenance[n.id] = { kind: 'group', slot, group: b.ref };
|
|
92
|
+
slots[slot] = { mode: 'ref', group: b.ref, sections };
|
|
93
|
+
}
|
|
94
|
+
else if (b?.override !== undefined) {
|
|
95
|
+
const sections = b.override.map((n) => withArea(n, slot));
|
|
96
|
+
for (const n of sections)
|
|
97
|
+
if (n.id)
|
|
98
|
+
provenance[n.id] = { kind: 'override', slot };
|
|
99
|
+
slots[slot] = { mode: 'override', sections };
|
|
100
|
+
}
|
|
101
|
+
else if (inline[slot].length) {
|
|
102
|
+
const sections = inline[slot].map((n) => withArea(n, slot));
|
|
103
|
+
for (const n of sections)
|
|
104
|
+
if (n.id)
|
|
105
|
+
provenance[n.id] = { kind: 'inline', slot };
|
|
106
|
+
slots[slot] = { mode: 'inline', sections };
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
slots[slot] = { mode: 'none', sections: [] };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const body = inline.template;
|
|
113
|
+
for (const n of body)
|
|
114
|
+
if (n.id)
|
|
115
|
+
provenance[n.id] = { kind: 'template' };
|
|
116
|
+
return {
|
|
117
|
+
sections: [...slots.header.sections, ...body, ...slots.footer.sections],
|
|
118
|
+
provenance,
|
|
119
|
+
slots,
|
|
120
|
+
missingGroups,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The inverse of `resolvePage`: take an edited flat list plus the provenance
|
|
125
|
+
* it was resolved with, and produce what to write to the template and to each
|
|
126
|
+
* group file.
|
|
127
|
+
*
|
|
128
|
+
* Rules that make this safe for a shared group:
|
|
129
|
+
* - A node whose provenance says `group` goes back to that group — and ONLY
|
|
130
|
+
* if the slot is still bound to that group. Nothing about a template save
|
|
131
|
+
* can silently rewrite a group the page no longer references.
|
|
132
|
+
* - A node with no provenance (newly inserted) lands where its `area` says.
|
|
133
|
+
* Inserted into a `ref`-bound slot, it becomes part of the shared group —
|
|
134
|
+
* that is the merchant editing "the header", which is shared by design and
|
|
135
|
+
* is reported as such by `groupImpact`.
|
|
136
|
+
* - Body nodes carry no `area` on disk unless they already had one, so a
|
|
137
|
+
* template that never used `area` on body nodes stays byte-identical.
|
|
138
|
+
*/
|
|
139
|
+
export function splitPage(sections, previous, opts = {}) {
|
|
140
|
+
const buckets = { header: [], template: [], footer: [] };
|
|
141
|
+
for (const node of sections) {
|
|
142
|
+
const prov = node.id ? previous.provenance[node.id] : undefined;
|
|
143
|
+
const slot = prov
|
|
144
|
+
? prov.kind === 'template'
|
|
145
|
+
? 'template'
|
|
146
|
+
: prov.slot
|
|
147
|
+
: inlineSlotOf(node);
|
|
148
|
+
buckets[slot].push(node);
|
|
149
|
+
}
|
|
150
|
+
const source = previousTemplateShape(previous);
|
|
151
|
+
const groupsOut = {};
|
|
152
|
+
const groupsBinding = {};
|
|
153
|
+
// Legacy inline nodes stay inline, in slot order, so an unmigrated template
|
|
154
|
+
// saves back exactly as it was read.
|
|
155
|
+
const inline = { header: [], footer: [] };
|
|
156
|
+
for (const slot of GROUP_SLOTS) {
|
|
157
|
+
const prev = previous.slots[slot];
|
|
158
|
+
const want = opts.slots?.[slot];
|
|
159
|
+
const mode = want?.mode ?? (prev.mode === 'none' ? (buckets[slot].length ? 'inline' : 'none') : prev.mode);
|
|
160
|
+
const nodes = buckets[slot].map((n) => withArea(n, slot));
|
|
161
|
+
if (mode === 'ref') {
|
|
162
|
+
const name = want && want.mode === 'ref' ? want.group : prev.group;
|
|
163
|
+
if (!name)
|
|
164
|
+
throw new Error(`splitPage: slot "${slot}" is bound to a group but no group name is known`);
|
|
165
|
+
groupsBinding[slot] = name;
|
|
166
|
+
// Group nodes are stored without `area` — the slot is the group's `type`.
|
|
167
|
+
groupsOut[slot] = {
|
|
168
|
+
name,
|
|
169
|
+
doc: { type: slot, sections: nodes.map(stripArea) },
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
else if (mode === 'override') {
|
|
173
|
+
groupsBinding[slot] = { override: nodes };
|
|
174
|
+
}
|
|
175
|
+
else if (mode === 'inline') {
|
|
176
|
+
// Raw nodes, not `withArea` — a legacy template must save back byte-identical.
|
|
177
|
+
inline[slot] = buckets[slot];
|
|
178
|
+
}
|
|
179
|
+
// 'none' → nothing written for this slot.
|
|
180
|
+
}
|
|
181
|
+
// Rebuild in the SOURCE template's key order, so a save that changes nothing
|
|
182
|
+
// is byte-identical to what was read — that is what makes the revision check
|
|
183
|
+
// and the "nothing to write" short-circuit honest.
|
|
184
|
+
const next = {};
|
|
185
|
+
const merged = [...inline.header, ...buckets.template, ...inline.footer];
|
|
186
|
+
const hasGroups = Object.keys(groupsBinding).length > 0;
|
|
187
|
+
for (const [k, v] of Object.entries(source)) {
|
|
188
|
+
if (k === 'sections')
|
|
189
|
+
next.sections = merged;
|
|
190
|
+
else if (k === 'groups') {
|
|
191
|
+
if (hasGroups)
|
|
192
|
+
next.groups = groupsBinding;
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
next[k] = v;
|
|
196
|
+
}
|
|
197
|
+
if (!('sections' in next))
|
|
198
|
+
next.sections = merged;
|
|
199
|
+
if (hasGroups && !('groups' in next))
|
|
200
|
+
next.groups = groupsBinding;
|
|
201
|
+
const template = next;
|
|
202
|
+
return { template, groups: groupsOut };
|
|
203
|
+
}
|
|
204
|
+
/** `resolvePage` does not keep the template; carry the keys a split must preserve. */
|
|
205
|
+
function previousTemplateShape(previous) {
|
|
206
|
+
const extra = previous.template;
|
|
207
|
+
return extra ? { ...extra } : { sections: [] };
|
|
208
|
+
}
|
|
209
|
+
function stripArea(node) {
|
|
210
|
+
if (node.area === undefined)
|
|
211
|
+
return node;
|
|
212
|
+
const { area: _a, ...rest } = node;
|
|
213
|
+
return rest;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Attach the source template to a resolution so `splitPage` can preserve any
|
|
217
|
+
* top-level keys it does not model (`contentVersion`, future additions).
|
|
218
|
+
*/
|
|
219
|
+
export function resolvePageFrom(template, groups = {}) {
|
|
220
|
+
return { ...resolvePage(template, groups), template };
|
|
221
|
+
}
|
|
222
|
+
/** Which templates render a given group — the blast radius of editing it. */
|
|
223
|
+
export function groupImpact(groupName, templates) {
|
|
224
|
+
const out = [];
|
|
225
|
+
for (const [slug, doc] of Object.entries(templates)) {
|
|
226
|
+
for (const slot of GROUP_SLOTS) {
|
|
227
|
+
const b = bindingOf(doc?.groups?.[slot]);
|
|
228
|
+
if (b?.ref === groupName) {
|
|
229
|
+
out.push(slug);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return out.sort();
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Canonical comparison form for a slot's nodes: type + settings-with-defaults
|
|
238
|
+
* + blocks, with ids REMOVED. Ids are identity, not content; two pages whose
|
|
239
|
+
* headers differ only in id are the same header.
|
|
240
|
+
*/
|
|
241
|
+
export function slotSignature(nodes, defaults = {}) {
|
|
242
|
+
const norm = (n) => ({
|
|
243
|
+
type: n.type,
|
|
244
|
+
settings: sortKeys({ ...(defaults[n.type] ?? {}), ...(n.settings ?? {}) }),
|
|
245
|
+
blocks: (n.blocks ?? []).map(norm),
|
|
246
|
+
});
|
|
247
|
+
return JSON.stringify(nodes.map(norm));
|
|
248
|
+
}
|
|
249
|
+
function sortKeys(o) {
|
|
250
|
+
return Object.fromEntries(Object.keys(o).sort().map((k) => [k, o[k]]));
|
|
251
|
+
}
|
|
252
|
+
/** Human-readable diff between two signatures, for the migration report. */
|
|
253
|
+
function describeDifference(a, b, defaults = {}) {
|
|
254
|
+
const out = [];
|
|
255
|
+
const ta = a.map((n) => n.type).join(' + ') || '(empty)';
|
|
256
|
+
const tb = b.map((n) => n.type).join(' + ') || '(empty)';
|
|
257
|
+
if (ta !== tb)
|
|
258
|
+
out.push(`sections: ${tb} vs canonical ${ta}`);
|
|
259
|
+
const len = Math.min(a.length, b.length);
|
|
260
|
+
for (let i = 0; i < len; i++) {
|
|
261
|
+
if (a[i].type !== b[i].type)
|
|
262
|
+
continue;
|
|
263
|
+
const sa = { ...(defaults[a[i].type] ?? {}), ...(a[i].settings ?? {}) };
|
|
264
|
+
const sb = { ...(defaults[b[i].type] ?? {}), ...(b[i].settings ?? {}) };
|
|
265
|
+
for (const k of new Set([...Object.keys(sa), ...Object.keys(sb)])) {
|
|
266
|
+
if (JSON.stringify(sa[k]) !== JSON.stringify(sb[k])) {
|
|
267
|
+
out.push(`${a[i].type}.${k}: ${JSON.stringify(sb[k])} vs canonical ${JSON.stringify(sa[k])}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const ba = (a[i].blocks ?? []).map((x) => x.type).join(',');
|
|
271
|
+
const bb = (b[i].blocks ?? []).map((x) => x.type).join(',');
|
|
272
|
+
if (ba !== bb)
|
|
273
|
+
out.push(`${a[i].type}.blocks: [${bb}] vs canonical [${ba}]`);
|
|
274
|
+
else {
|
|
275
|
+
const blocksA = a[i].blocks ?? [];
|
|
276
|
+
const blocksB = b[i].blocks ?? [];
|
|
277
|
+
for (let j = 0; j < blocksA.length; j++) {
|
|
278
|
+
const x = { ...(defaults[blocksA[j].type] ?? {}), ...(blocksA[j].settings ?? {}) };
|
|
279
|
+
const y = { ...(defaults[blocksB[j].type] ?? {}), ...(blocksB[j].settings ?? {}) };
|
|
280
|
+
for (const k of new Set([...Object.keys(x), ...Object.keys(y)])) {
|
|
281
|
+
if (JSON.stringify(x[k]) !== JSON.stringify(y[k])) {
|
|
282
|
+
out.push(`${a[i].type}.blocks[${j}] (${blocksA[j].type}).${k}: ${JSON.stringify(y[k])} vs canonical ${JSON.stringify(x[k])}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return out;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Turn per-template inline header/footer copies into shared groups.
|
|
292
|
+
*
|
|
293
|
+
* Deterministic and idempotent:
|
|
294
|
+
* - The canonical composition for a slot is the one the MOST templates carry
|
|
295
|
+
* (ties broken by the alphabetically-first template that carries it).
|
|
296
|
+
* - A template whose copy matches canonical (after defaults) binds the group.
|
|
297
|
+
* - A template whose copy differs keeps its own nodes as an explicit
|
|
298
|
+
* `override` — the difference is REPORTED, never merged away.
|
|
299
|
+
* - A template with nothing in the slot binds nothing for it.
|
|
300
|
+
* - A template that already binds the slot is left alone, so running the
|
|
301
|
+
* migration twice changes nothing (`noop: true`).
|
|
302
|
+
*
|
|
303
|
+
* Ids, settings, blocks and order are carried verbatim into the group and into
|
|
304
|
+
* every override; nothing is re-minted.
|
|
305
|
+
*/
|
|
306
|
+
export function extractGroups(templates, opts = {}) {
|
|
307
|
+
const defaults = opts.defaults ?? {};
|
|
308
|
+
const out = {};
|
|
309
|
+
for (const [slug, doc] of Object.entries(templates))
|
|
310
|
+
out[slug] = doc;
|
|
311
|
+
const groups = {};
|
|
312
|
+
const report = [];
|
|
313
|
+
let changed = false;
|
|
314
|
+
for (const slot of GROUP_SLOTS) {
|
|
315
|
+
const name = opts.names?.[slot] ?? slot;
|
|
316
|
+
const bySig = new Map();
|
|
317
|
+
const nodesBySlug = new Map();
|
|
318
|
+
const alreadyBound = [];
|
|
319
|
+
const empty = [];
|
|
320
|
+
for (const slug of Object.keys(templates).sort()) {
|
|
321
|
+
const doc = templates[slug];
|
|
322
|
+
if (bindingOf(doc.groups?.[slot])) {
|
|
323
|
+
alreadyBound.push(slug);
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const nodes = (Array.isArray(doc.sections) ? doc.sections : []).filter((n) => inlineSlotOf(n) === slot);
|
|
327
|
+
if (!nodes.length) {
|
|
328
|
+
empty.push(slug);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
nodesBySlug.set(slug, nodes);
|
|
332
|
+
const sig = slotSignature(nodes, defaults);
|
|
333
|
+
bySig.set(sig, [...(bySig.get(sig) ?? []), slug]);
|
|
334
|
+
}
|
|
335
|
+
if (!nodesBySlug.size) {
|
|
336
|
+
// Nothing inline anywhere: either already migrated (noop) or no such slot.
|
|
337
|
+
if (alreadyBound.length) {
|
|
338
|
+
report.push({
|
|
339
|
+
slot, group: name,
|
|
340
|
+
canonical: { signature: '', templates: [] },
|
|
341
|
+
overrides: [], empty, alreadyBound, idRemaps: [],
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
// Majority wins; ties → the signature whose first template sorts first.
|
|
347
|
+
const ranked = [...bySig.entries()].sort((a, b) => b[1].length - a[1].length || a[1][0].localeCompare(b[1][0]));
|
|
348
|
+
const [canonicalSig, canonicalSlugs] = ranked[0];
|
|
349
|
+
const canonicalNodes = nodesBySlug.get(canonicalSlugs[0]);
|
|
350
|
+
groups[slot] = {
|
|
351
|
+
name,
|
|
352
|
+
doc: { type: slot, sections: canonicalNodes.map(stripArea) },
|
|
353
|
+
};
|
|
354
|
+
const overrides = [];
|
|
355
|
+
const idRemaps = [];
|
|
356
|
+
for (const [slug, nodes] of nodesBySlug) {
|
|
357
|
+
const sig = slotSignature(nodes, defaults);
|
|
358
|
+
const doc = out[slug];
|
|
359
|
+
const rest = (doc.sections ?? []).filter((n) => inlineSlotOf(n) !== slot);
|
|
360
|
+
const binding = sig === canonicalSig ? name : { override: nodes.map((n) => withArea(n, slot)) };
|
|
361
|
+
if (sig !== canonicalSig) {
|
|
362
|
+
overrides.push({ template: slug, signature: sig, differences: describeDifference(canonicalNodes, nodes, defaults) });
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
// Same content, possibly different ids: the group keeps the canonical
|
|
366
|
+
// template's ids. Say which ids this template loses.
|
|
367
|
+
const pairs = (a, b) => {
|
|
368
|
+
a.forEach((x, i) => {
|
|
369
|
+
const y = b[i];
|
|
370
|
+
if (!y)
|
|
371
|
+
return;
|
|
372
|
+
if (x.id && y.id && x.id !== y.id)
|
|
373
|
+
idRemaps.push({ template: slug, from: y.id, to: x.id });
|
|
374
|
+
pairs(x.blocks ?? [], y.blocks ?? []);
|
|
375
|
+
});
|
|
376
|
+
};
|
|
377
|
+
pairs(canonicalNodes, nodes);
|
|
378
|
+
}
|
|
379
|
+
out[slug] = {
|
|
380
|
+
...doc,
|
|
381
|
+
groups: { ...(doc.groups ?? {}), [slot]: binding },
|
|
382
|
+
sections: rest,
|
|
383
|
+
};
|
|
384
|
+
changed = true;
|
|
385
|
+
}
|
|
386
|
+
report.push({
|
|
387
|
+
slot, group: name,
|
|
388
|
+
canonical: { signature: canonicalSig, templates: canonicalSlugs },
|
|
389
|
+
overrides, empty, alreadyBound, idRemaps,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
return { groups, templates: out, report, noop: !changed };
|
|
393
|
+
}
|
|
394
|
+
/** Validate a group document's own shape (the content validator checks its nodes). */
|
|
395
|
+
export function isSectionGroupDoc(v) {
|
|
396
|
+
if (!v || typeof v !== 'object')
|
|
397
|
+
return false;
|
|
398
|
+
const g = v;
|
|
399
|
+
return GROUP_SLOTS.includes(g.type) && Array.isArray(g.sections);
|
|
400
|
+
}
|
|
401
|
+
/** Group file names must be safe path segments. */
|
|
402
|
+
export const GROUP_NAME_PATTERN = NODE_ID_PATTERN;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tanqory Theme Contract v1 — the shared agreement between the theme (kit),
|
|
3
|
+
* the CMS (studio-api + code-store), the Editor (studio-app), the storefront
|
|
4
|
+
* runtime, and any AI authoring against them.
|
|
5
|
+
*
|
|
6
|
+
* Owner: `@tanqory/theme-kit`. It already owns `AttrSpec` / `SectionDef` /
|
|
7
|
+
* `ContentNode` / `PageDoc`, so the contract derives from the code rather than
|
|
8
|
+
* restating it — and `tsc` proves the derivation.
|
|
9
|
+
*
|
|
10
|
+
* This entry is dependency-free (no React), so it builds to a single portable
|
|
11
|
+
* `dist/contract.js` that studio-api can vendor without breaking its
|
|
12
|
+
* zero-npm-dependency image.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CONTRACT_VERSION = "1.0.0";
|
|
15
|
+
/**
|
|
16
|
+
* Which theme-kit releases this contract describes.
|
|
17
|
+
*
|
|
18
|
+
* Nothing on the platform declared runtime compatibility before, so a theme
|
|
19
|
+
* built against one kit and rendered by another failed at runtime with no
|
|
20
|
+
* signal. A consumer compares its installed kit version against this range and
|
|
21
|
+
* says so up front.
|
|
22
|
+
*/
|
|
23
|
+
export declare const KIT_COMPATIBILITY: {
|
|
24
|
+
/** Lowest kit release whose runtime honours everything in this contract. */
|
|
25
|
+
readonly min: "0.1.3";
|
|
26
|
+
/** Highest kit release verified against it. */
|
|
27
|
+
readonly maxVerified: "0.2.0";
|
|
28
|
+
};
|
|
29
|
+
export * from './field-types.js';
|
|
30
|
+
export * from './content.js';
|
|
31
|
+
export * from './groups.js';
|
|
32
|
+
export * from './transform.js';
|
|
33
|
+
export * from './validate.js';
|