@tanqory/theme-kit 2.0.0-alpha.17 → 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/README.md +4 -1
- package/dist/abi/canvas-live.d.ts +7 -2
- package/dist/abi/canvas-live.js +8 -3
- package/dist/abi/cart.d.ts +5 -4
- package/dist/abi/cart.js +14 -5
- package/dist/abi/convert.d.ts +18 -2
- package/dist/abi/convert.js +56 -4
- package/dist/abi/data-api.js +4 -0
- package/dist/abi/page-data.d.ts +11 -3
- package/dist/abi/page-data.js +71 -3
- package/dist/abi/wire.d.ts +8 -0
- package/dist/abi/wire.js +32 -2
- package/dist/build.d.ts +7 -2
- package/dist/build.js +96 -5
- package/dist/chunks.d.ts +23 -0
- package/dist/chunks.js +41 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +16 -2
- package/dist/headless/hooks.js +5 -1
- package/dist/headless/index.d.ts +8 -1
- package/dist/headless/index.js +11 -1
- 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 +1 -9
- package/dist/headless/money.js +24 -22
- package/dist/headless/page.d.ts +2 -0
- package/dist/headless/primitives/storefront.js +2 -1
- package/dist/headless/strings.js +8 -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 +13 -3
- package/dist/headless/theme.js +12 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/runtime/data/StoreProvider.js +10 -3
- package/dist/runtime/data/to-ui.d.ts +12 -7
- package/dist/runtime/data/to-ui.js +48 -16
- package/dist/runtime/kit/cart.d.ts +10 -3
- package/dist/runtime/kit/contract/content.d.ts +14 -0
- package/dist/runtime/kit/contract/content.js +13 -0
- package/dist/runtime/kit/contract/field-types.d.ts +26 -3
- package/dist/runtime/kit/contract/field-types.js +11 -1
- package/dist/runtime/kit/contract/validate.d.ts +2 -0
- package/dist/runtime/kit/contract/validate.js +49 -9
- package/dist/runtime/kit/data.d.ts +12 -0
- package/dist/runtime/kit/data.js +36 -22
- package/dist/runtime/kit/dynamic-source.d.ts +12 -0
- package/dist/runtime/kit/dynamic-source.js +17 -0
- package/dist/runtime/kit/storefront.d.ts +14 -1
- package/dist/runtime/kit/types.d.ts +8 -0
- package/dist/runtime/render/SectionRenderer.js +44 -11
- 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 +2 -1
- package/dist/runtime/render/section-actions.js +4 -1
- package/dist/runtime/render/starter.js +19 -4
- package/dist/runtime/seo/head.d.ts +1 -1
- package/dist/runtime/shell/PageShell.js +6 -1
- package/dist/runtime/shell/RuntimeBridge.d.ts +4 -0
- package/dist/runtime/shell/RuntimeBridge.js +37 -6
- package/dist/runtime/slots.d.ts +1 -1
- 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 +7 -1
- package/dist/sdk/index.js +11 -1
- 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/runtime-context.d.ts +32 -4
- package/dist/sdk/schema.d.ts +47 -4
- package/dist/sdk/schema.js +47 -0
- package/dist/sdk/store-lookup.d.ts +5 -0
- package/dist/sdk/store-lookup.js +19 -0
- package/dist/sdk/store.d.ts +15 -0
- package/dist/sdk/sx.d.ts +5 -0
- package/dist/sdk/sx.js +7 -2
- package/dist/sdk/theme.d.ts +21 -0
- package/dist/sdk/theme.js +17 -0
- package/dist/sdk/types.d.ts +36 -4
- package/dist/server.d.ts +5 -4
- package/dist/server.js +76 -20
- package/dist/vite-chunks.d.ts +10 -0
- package/dist/vite-chunks.js +44 -0
- package/docs/headless-api.md +33 -3
- package/package.json +10 -18
|
@@ -22,6 +22,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
22
22
|
*/
|
|
23
23
|
import { createContext, useContext } from 'react';
|
|
24
24
|
import { useData } from './data.js';
|
|
25
|
+
import { isBoundTemplateValue } from './contract/field-types.js';
|
|
25
26
|
export function isBoundTemplate(v) {
|
|
26
27
|
return typeof v === 'object' && v !== null && typeof v['@template'] === 'string';
|
|
27
28
|
}
|
|
@@ -52,6 +53,22 @@ export function useResourceContext() {
|
|
|
52
53
|
return { shop: data.shop, ...ctx };
|
|
53
54
|
}
|
|
54
55
|
const METAOBJECT_RE = /^metaobject:([^:]+):([^.]+)\.(.+)$/;
|
|
56
|
+
/**
|
|
57
|
+
* Text that names dynamic sources as plain text (`Goes well with {{ product.title }}`): a default the editor has not
|
|
58
|
+
* connected yet, a starter template, a section preview. Read with each source of this page ('' where it has none),
|
|
59
|
+
* exactly as the connected `{ '@template' }` value reads; never the literal braces. Text whose tokens are not all source
|
|
60
|
+
* paths (the contract's `isBoundTemplateValue`), or that names none, is returned as it is.
|
|
61
|
+
*/
|
|
62
|
+
export function sourceText(text, ctx) {
|
|
63
|
+
return typeof text === 'string' && text.includes('{{') && isBoundTemplateValue({ '@template': text }) ? resolveBoundTemplate(text, ctx) : text;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* `sourceText` against the page's resources, for a section component. Reads the resource context the page provides
|
|
67
|
+
* (StoreProvider: the route's resource and the shop), and works without one (a section rendered on its own).
|
|
68
|
+
*/
|
|
69
|
+
export function useSourceText(text) {
|
|
70
|
+
return sourceText(text, useContext(ResourceContext));
|
|
71
|
+
}
|
|
55
72
|
/** The resources a `@source` path may start with. */
|
|
56
73
|
export const BOUND_SOURCE_ROOTS = ['product', 'collection', 'page', 'article', 'shop', 'metaobject'];
|
|
57
74
|
/** The `@source` grammar a saved setting may carry (the contract owns it; the validator refuses anything else). */
|
|
@@ -348,13 +348,26 @@ export interface ShopAddress {
|
|
|
348
348
|
}
|
|
349
349
|
/** rev 2.52 (O3): a location's expected pickup time, as the merchant chose it. */
|
|
350
350
|
export type PickupReadyIn = '4h' | '24h' | '1-2d' | '2-4d' | '5d+';
|
|
351
|
-
/**
|
|
351
|
+
/** rev 2.73 (board 35 #117): one weekly opening period of a location, 24-hour local `HH:MM`. */
|
|
352
|
+
export interface OpeningPeriod {
|
|
353
|
+
day: 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY' | 'SUNDAY';
|
|
354
|
+
opens: string;
|
|
355
|
+
/** Earlier than `opens`: closes after midnight. */
|
|
356
|
+
closes: string;
|
|
357
|
+
}
|
|
358
|
+
/** One store location (rev 2.34 `ShopLocation`; rev 2.52 `pickupReadyIn`; rev 2.73 `pickup`, `storefront`, `openingHours`). */
|
|
352
359
|
export interface ShopLocation {
|
|
353
360
|
id: string;
|
|
354
361
|
name: string;
|
|
355
362
|
address: ShopAddress;
|
|
356
363
|
phone?: string;
|
|
357
364
|
pickupReadyIn?: PickupReadyIn;
|
|
365
|
+
/** rev 2.73: offers local pickup; absent ⇒ the rev 2.34 reading (yes). */
|
|
366
|
+
pickup?: boolean;
|
|
367
|
+
/** rev 2.73: Physical storefront on (a store locator lists it); absent ⇒ the rev 2.34 reading (yes). */
|
|
368
|
+
storefront?: boolean;
|
|
369
|
+
/** rev 2.73: weekly hours, Monday first; a day not listed is closed; absent ⇒ not set. */
|
|
370
|
+
openingHours?: OpeningPeriod[];
|
|
358
371
|
}
|
|
359
372
|
/**
|
|
360
373
|
* A merchant pop-up (Marketing › Pop-ups) the store runs now (storefront-query rev 2.37 `Shop.popups`, theme-abi
|
|
@@ -47,6 +47,14 @@ export interface AttrSpec {
|
|
|
47
47
|
value: string;
|
|
48
48
|
label: string;
|
|
49
49
|
}[];
|
|
50
|
+
/**
|
|
51
|
+
* For type 'list' — the element: `{ type: 'product' }` (a hand-picked list; `resolve: true` has the platform resolve
|
|
52
|
+
* each entry into the page's snapshot) or `{ type: 'color' }`.
|
|
53
|
+
*/
|
|
54
|
+
items?: {
|
|
55
|
+
type: string;
|
|
56
|
+
resolve?: boolean;
|
|
57
|
+
};
|
|
50
58
|
}
|
|
51
59
|
/** Props every section component receives. `attributes` are resolved (defaults applied). */
|
|
52
60
|
export interface SectionProps {
|
|
@@ -19,13 +19,25 @@ import { ShowStarterContext, starterSet, withoutStarter } from './starter.js';
|
|
|
19
19
|
import { copyPlanOf, localizeShippedCopy, shippedCopyOf } from './localized-copy.js';
|
|
20
20
|
import { useLocaleStrings } from '../kit/theme-context.js';
|
|
21
21
|
import { resolveBoundSettings, useResourceContext } from '../kit/dynamic-source.js';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
import { BLOCK_INDEX, blockDefOf, isClientOnly, resolveNode, ResolvedSinkContext, ResolvedStateContext, withBlockIndex } from './resolved.js';
|
|
23
|
+
import { useServerRender } from '../../sdk/server-render.js';
|
|
24
|
+
/**
|
|
25
|
+
* A saved block, its own blocks kept (nested theme blocks: a block that holds blocks). Its position as saved
|
|
26
|
+
* (BLOCK_INDEX) rides along, not enumerable (no spread or equality of saved blocks sees it), so `resolvedBlockKey`
|
|
27
|
+
* finds an id-less block's resolution under the key the server filed it under.
|
|
28
|
+
*/
|
|
29
|
+
const toSavedBlock = (b) => {
|
|
30
|
+
const out = {
|
|
31
|
+
...(typeof b.id === 'string' && b.id ? { id: b.id } : {}),
|
|
32
|
+
type: b.type,
|
|
33
|
+
settings: b.settings,
|
|
34
|
+
...(b.blocks?.length ? { blocks: b.blocks.map(toSavedBlock) } : {}),
|
|
35
|
+
};
|
|
36
|
+
const at = b[BLOCK_INDEX];
|
|
37
|
+
if (typeof at === 'number')
|
|
38
|
+
Object.defineProperty(out, BLOCK_INDEX, { value: at, enumerable: false });
|
|
39
|
+
return out;
|
|
40
|
+
};
|
|
29
41
|
const toSaved = (node) => ({
|
|
30
42
|
type: node.type,
|
|
31
43
|
settings: node.settings,
|
|
@@ -59,7 +71,8 @@ function withBoundValues(node, pageSources, theme, sourceFor) {
|
|
|
59
71
|
let blocksChanged = false;
|
|
60
72
|
// Nested blocks are bound too, at every depth (a block's own blocks are found among the section's block schemas).
|
|
61
73
|
const bindBlock = (b, above) => {
|
|
62
|
-
|
|
74
|
+
// the block's definition by the same rule resolveNode uses (an old block name finds the block it now is)
|
|
75
|
+
const def = blockDefOf(section?.blocks, b.type);
|
|
63
76
|
const blockFields = fieldsOf(def);
|
|
64
77
|
const own = closestSources(blockFields, b.settings, above, sourceFor);
|
|
65
78
|
const resolved = resolveBoundSettings(b.settings, own, (k) => blockFields[k]?.control);
|
|
@@ -92,7 +105,9 @@ export function SectionRenderer({ node }) {
|
|
|
92
105
|
const theme = getThemeBundle().theme;
|
|
93
106
|
// O4: a setting bound to a dynamic source reads this page's resource (StoreProvider mounts the route's resources).
|
|
94
107
|
const sources = useResourceContext();
|
|
95
|
-
|
|
108
|
+
// Every block carries its position as saved before anything drops one (the key of an id-less block's resolution).
|
|
109
|
+
const tagged = node ? withBlockIndex(node) : node;
|
|
110
|
+
const bound = tagged ? withBoundValues(tagged, sources, theme, store?.sourceFor) : tagged;
|
|
96
111
|
// On the live storefront, starter instructions never reach a shopper (the editor shows them).
|
|
97
112
|
const unpruned = bound && context.mode !== 'editor' && !showStarter ? withoutStarter(bound, starterSet(theme.starterText), defaultsFor(theme), copyFieldsFor(theme)) : bound;
|
|
98
113
|
// Then the theme's own shipped words in the page's language (after the starter check, which matches the English).
|
|
@@ -100,8 +115,25 @@ export function SectionRenderer({ node }) {
|
|
|
100
115
|
const shown = useMemo(() => (unpruned ? localizeShippedCopy(unpruned, shippedCopyOf(theme.shippedCopy?.english, theme.shippedCopy?.prefix ?? ''), strings, copyPlanOf(theme)) : unpruned), [unpruned, theme, strings]);
|
|
101
116
|
const section = shown ? theme.sections.find((s) => s.id === shown.type) : undefined;
|
|
102
117
|
const firstBody = tree?.find(isBody) ?? null;
|
|
118
|
+
// §2.2.2: the node's resolved settings. The server resolves with the schemas and records it for the page state; the
|
|
119
|
+
// browser takes the state's copy (a client-only definition has no schema to resolve with).
|
|
120
|
+
const server = useServerRender();
|
|
121
|
+
const sink = useContext(ResolvedSinkContext);
|
|
122
|
+
const stateResolved = useContext(ResolvedStateContext);
|
|
123
|
+
const clientOnly = isClientOnly(section);
|
|
124
|
+
const resolved = useMemo(() => {
|
|
125
|
+
if (!section || !shown)
|
|
126
|
+
return null;
|
|
127
|
+
// a full definition resolves itself (the editor's live edits change settings the state never saw); only a
|
|
128
|
+
// client-only definition, which has no schema, takes the state's copy
|
|
129
|
+
if (!clientOnly)
|
|
130
|
+
return resolveNode(section, shown);
|
|
131
|
+
return !server && typeof shown.id === 'string' ? (stateResolved?.[shown.id] ?? null) : null;
|
|
132
|
+
}, [section, shown, server, stateResolved, clientOnly]);
|
|
133
|
+
if (server && sink && resolved && typeof shown?.id === 'string')
|
|
134
|
+
sink.set(shown.id, resolved);
|
|
103
135
|
let props = null;
|
|
104
|
-
if (section && shown) {
|
|
136
|
+
if (section && shown && resolved) {
|
|
105
137
|
const saved = toSaved(shown);
|
|
106
138
|
props = section.data
|
|
107
139
|
? section.data(saved, store?.ctx ?? BARE, {
|
|
@@ -111,8 +143,9 @@ export function SectionRenderer({ node }) {
|
|
|
111
143
|
firstBodySection: firstBody ? toSaved(firstBody) : null,
|
|
112
144
|
isFirstBodySection: Boolean(firstBody && firstBody.id === shown.id && firstBody.type === shown.type),
|
|
113
145
|
},
|
|
146
|
+
resolved,
|
|
114
147
|
})
|
|
115
|
-
:
|
|
148
|
+
: { ...resolved.settings };
|
|
116
149
|
}
|
|
117
150
|
const listing = useListing(section?.listing && props ? props : null);
|
|
118
151
|
if (!section || !props)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Schema } from '../../sdk/schema.js';
|
|
2
|
+
import type { ContentNode } from '../kit/types.js';
|
|
3
|
+
/** A node's settings as `resolveSettings` returned them, and its blocks' by block id (or `#<index>`). */
|
|
4
|
+
export interface ResolvedNode {
|
|
5
|
+
readonly settings: Readonly<Record<string, unknown>>;
|
|
6
|
+
readonly handles: Readonly<Record<string, string | string[]>>;
|
|
7
|
+
readonly blocks: Readonly<Record<string, ResolvedNode>>;
|
|
8
|
+
}
|
|
9
|
+
/** The schema a `defineClientSection` carries in place of a real one: no fields, recognised by identity. */
|
|
10
|
+
export declare const CLIENT_ONLY_SCHEMA: Schema;
|
|
11
|
+
export declare const isClientOnly: (section: {
|
|
12
|
+
schema?: unknown;
|
|
13
|
+
} | undefined) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* A block's position in its parent's list as the page saved it, before anything drops blocks (starter pruning): the
|
|
16
|
+
* kit tags every block with it (`withBlockIndex`) before binding, pruning and the shipped copy, and keeps it on the
|
|
17
|
+
* saved block a `data()` receives. A block with no id is filed under `#<that position>`, so the server, which renders
|
|
18
|
+
* the pruned list, and the browser, whose shopper bundle receives the list as saved (it cannot prune without the
|
|
19
|
+
* schemas), use the same key for the same block. (Its index in the pruned list would differ from the browser's as soon
|
|
20
|
+
* as a block before it was dropped.)
|
|
21
|
+
*/
|
|
22
|
+
export declare const BLOCK_INDEX: unique symbol;
|
|
23
|
+
/** The key a block's resolution is filed under: its id, else `#<its position as saved>` (`i` when the block is untagged). */
|
|
24
|
+
export declare function blockKey(b: {
|
|
25
|
+
id?: unknown;
|
|
26
|
+
}, i: number): string;
|
|
27
|
+
/**
|
|
28
|
+
* The node with each block (at every depth) tagged with its position as saved (BLOCK_INDEX, an enumerable symbol: the
|
|
29
|
+
* object spreads that bind, prune and localize keep it; JSON never sees it). Cached per node, so an unchanged node
|
|
30
|
+
* stays the same object.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withBlockIndex(node: ContentNode): ContentNode;
|
|
33
|
+
/**
|
|
34
|
+
* The block definition a saved block renders with: the first of the section's block schemas named like it, or that
|
|
35
|
+
* lists its type among its earlier names (`legacyNames`): the rule the kit's renderers use (headless/theme.tsx), so a
|
|
36
|
+
* block saved under an old name is resolved as the block it now is.
|
|
37
|
+
*/
|
|
38
|
+
export declare function blockDefOf(blocks: readonly unknown[] | undefined, type: string): unknown;
|
|
39
|
+
/** Resolve a node with its definition's schema and block schemas (server; and the preview profile in the browser). */
|
|
40
|
+
export declare function resolveNode(def: {
|
|
41
|
+
schema: unknown;
|
|
42
|
+
blocks?: readonly unknown[];
|
|
43
|
+
}, node: ContentNode): ResolvedNode;
|
|
44
|
+
/** Server: where SectionRenderer records each rendered node's resolution (server.tsx puts it in the state). */
|
|
45
|
+
export declare const ResolvedSinkContext: import("react").Context<Map<string, ResolvedNode> | null>;
|
|
46
|
+
/** Browser: the state's resolutions, by node id. */
|
|
47
|
+
export declare const ResolvedStateContext: import("react").Context<Readonly<Record<string, ResolvedNode>> | null>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-resolved settings (theme-abi-v2.md §2.2.2, board 36 card B): the shopper bundle needs no section schema.
|
|
3
|
+
*
|
|
4
|
+
* The server resolves every node it renders (`resolveSettings` with the section's schema and its block schemas, after
|
|
5
|
+
* dynamic-source binding, starter pruning and the shipped copy) and puts the result in the page's hydration state, per
|
|
6
|
+
* node id. In the browser, `SectionRenderer` hands that result to the section's `data()` as `resolved`, so a section
|
|
7
|
+
* defined for the shopper bundle (`defineClientSection`: no schema, presets or block metadata) renders the same thing.
|
|
8
|
+
*
|
|
9
|
+
* Only nodes the server rendered are in the state (the host already stripped disabled nodes); everything a rendered
|
|
10
|
+
* section's settings hold is readable in page source, so a visible section's settings are public (§2.2.2 MUST 3).
|
|
11
|
+
*/
|
|
12
|
+
import { createContext } from 'react';
|
|
13
|
+
import { resolveSettings } from '../../sdk/schema.js';
|
|
14
|
+
/** The schema a `defineClientSection` carries in place of a real one: no fields, recognised by identity. */
|
|
15
|
+
export const CLIENT_ONLY_SCHEMA = Object.freeze({ kind: 'section', name: '@tanqory/client-only', family: 'client-only', fields: Object.freeze({}) });
|
|
16
|
+
export const isClientOnly = (section) => !!section && section.schema === CLIENT_ONLY_SCHEMA;
|
|
17
|
+
/**
|
|
18
|
+
* A block's position in its parent's list as the page saved it, before anything drops blocks (starter pruning): the
|
|
19
|
+
* kit tags every block with it (`withBlockIndex`) before binding, pruning and the shipped copy, and keeps it on the
|
|
20
|
+
* saved block a `data()` receives. A block with no id is filed under `#<that position>`, so the server, which renders
|
|
21
|
+
* the pruned list, and the browser, whose shopper bundle receives the list as saved (it cannot prune without the
|
|
22
|
+
* schemas), use the same key for the same block. (Its index in the pruned list would differ from the browser's as soon
|
|
23
|
+
* as a block before it was dropped.)
|
|
24
|
+
*/
|
|
25
|
+
export const BLOCK_INDEX = Symbol.for('tanqory.theme-kit.blockIndex');
|
|
26
|
+
/** The key a block's resolution is filed under: its id, else `#<its position as saved>` (`i` when the block is untagged). */
|
|
27
|
+
export function blockKey(b, i) {
|
|
28
|
+
if (typeof b.id === 'string' && b.id)
|
|
29
|
+
return b.id;
|
|
30
|
+
const at = b[BLOCK_INDEX];
|
|
31
|
+
return `#${typeof at === 'number' ? at : i}`;
|
|
32
|
+
}
|
|
33
|
+
const indexed = new WeakMap();
|
|
34
|
+
/**
|
|
35
|
+
* The node with each block (at every depth) tagged with its position as saved (BLOCK_INDEX, an enumerable symbol: the
|
|
36
|
+
* object spreads that bind, prune and localize keep it; JSON never sees it). Cached per node, so an unchanged node
|
|
37
|
+
* stays the same object.
|
|
38
|
+
*/
|
|
39
|
+
export function withBlockIndex(node) {
|
|
40
|
+
if (!node.blocks?.length)
|
|
41
|
+
return node;
|
|
42
|
+
const hit = indexed.get(node);
|
|
43
|
+
if (hit)
|
|
44
|
+
return hit;
|
|
45
|
+
const tag = (list) => list.map((b, i) => ({ ...b, [BLOCK_INDEX]: i, ...(b.blocks?.length ? { blocks: tag(b.blocks) } : {}) }));
|
|
46
|
+
const out = { ...node, blocks: tag(node.blocks) };
|
|
47
|
+
indexed.set(node, out);
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The block definition a saved block renders with: the first of the section's block schemas named like it, or that
|
|
52
|
+
* lists its type among its earlier names (`legacyNames`): the rule the kit's renderers use (headless/theme.tsx), so a
|
|
53
|
+
* block saved under an old name is resolved as the block it now is.
|
|
54
|
+
*/
|
|
55
|
+
export function blockDefOf(blocks, type) {
|
|
56
|
+
return blocks?.find((x) => x.name === type || !!x.legacyNames?.includes(type));
|
|
57
|
+
}
|
|
58
|
+
/** Resolve a node with its definition's schema and block schemas (server; and the preview profile in the browser). */
|
|
59
|
+
export function resolveNode(def, node) {
|
|
60
|
+
const r = resolveSettings(def.schema, node.settings);
|
|
61
|
+
const blocks = {};
|
|
62
|
+
const walk = (list, into) => {
|
|
63
|
+
;
|
|
64
|
+
(list ?? []).forEach((b, i) => {
|
|
65
|
+
const bdef = blockDefOf(def.blocks, b.type);
|
|
66
|
+
if (!bdef)
|
|
67
|
+
return;
|
|
68
|
+
const br = resolveSettings(bdef, b.settings);
|
|
69
|
+
const kids = {};
|
|
70
|
+
walk(b.blocks, kids);
|
|
71
|
+
into[blockKey(b, i)] = { settings: br.settings, handles: br.handles, blocks: kids };
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
walk(node.blocks, blocks);
|
|
75
|
+
return { settings: r.settings, handles: r.handles, blocks };
|
|
76
|
+
}
|
|
77
|
+
/** Server: where SectionRenderer records each rendered node's resolution (server.tsx puts it in the state). */
|
|
78
|
+
export const ResolvedSinkContext = createContext(null);
|
|
79
|
+
/** Browser: the state's resolutions, by node id. */
|
|
80
|
+
export const ResolvedStateContext = createContext(null);
|
|
@@ -2,7 +2,8 @@ import type { CartAddStock, CartRefusal } from '../kit/cart.js';
|
|
|
2
2
|
import type { AddToCartOptions, DiscountCodeRefusal, DiscountCodeResult } from '../../sdk/runtime-context.js';
|
|
3
3
|
/**
|
|
4
4
|
* The shopper-facing words for a refusal, in the page's language (locales/*.json): the merchant's
|
|
5
|
-
* limit when it is known, else that the most has been reached.
|
|
5
|
+
* limit when it is known, else that the most has been reached. A company location's quantity rule (Cart-3)
|
|
6
|
+
* carries no number, so the kit says the quantity is not allowed there; a theme that shows the rule names it.
|
|
6
7
|
*/
|
|
7
8
|
export declare function refusalMessage(t: (key: string, fallback?: string) => string, refusal: CartRefusal): string;
|
|
8
9
|
/**
|
|
@@ -16,9 +16,12 @@ class RefusedWrite extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* The shopper-facing words for a refusal, in the page's language (locales/*.json): the merchant's
|
|
19
|
-
* limit when it is known, else that the most has been reached.
|
|
19
|
+
* limit when it is known, else that the most has been reached. A company location's quantity rule (Cart-3)
|
|
20
|
+
* carries no number, so the kit says the quantity is not allowed there; a theme that shows the rule names it.
|
|
20
21
|
*/
|
|
21
22
|
export function refusalMessage(t, refusal) {
|
|
23
|
+
if (refusal.code === 'quantity_rule')
|
|
24
|
+
return t('cartQuantityRuleRefused', 'This quantity is not allowed for your company location.');
|
|
22
25
|
return refusal.maxQuantity
|
|
23
26
|
? t('cartLimitReached', 'You can buy up to {max} of this item.').replace('{max}', String(refusal.maxQuantity))
|
|
24
27
|
: t('cartLimitReachedAny', "You've reached the maximum quantity for this item.");
|
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
* empty, a section whose copy is nothing but starter text is not rendered, and
|
|
7
7
|
* a block holding one is left out (a testimonial nobody wrote, a "Milestone 1").
|
|
8
8
|
* A section the merchant wrote copy into stays — an untouched subtext must not
|
|
9
|
-
* take the merchant's own heading down with it
|
|
10
|
-
*
|
|
9
|
+
* take the merchant's own heading down with it, and so does a section holding
|
|
10
|
+
* an app block (theme-abi §7.2): the merchant placed it, so it renders with the
|
|
11
|
+
* section's starter fields emptied. The editor renders nodes as they are, so the
|
|
12
|
+
* merchant still sees every field to fill.
|
|
11
13
|
*/
|
|
12
14
|
import { createContext } from 'react';
|
|
15
|
+
import { isAppBlockType } from '../kit/contract/content.js';
|
|
13
16
|
/** True where starter text is the point — the editor's "Add section" preview shows a section as its preset reads. */
|
|
14
17
|
export const ShowStarterContext = createContext(false);
|
|
15
18
|
const plain = (v) => v.replace(/<[^>]*>/g, '').trim();
|
|
@@ -53,15 +56,27 @@ function sectionWithoutStarter(node, starter, defaultsOf, copyFieldsOf) {
|
|
|
53
56
|
}
|
|
54
57
|
return authored ? { ...node.settings, ...cleared } : null;
|
|
55
58
|
}
|
|
59
|
+
/** Does any block at any depth of `blocks` place an app's block? */
|
|
60
|
+
const holdsAppBlock = (blocks) => !!blocks?.some((b) => isAppBlockType(b.type) || holdsAppBlock(b.blocks));
|
|
61
|
+
/** A section's settings with every starter value emptied (saved or default), whoever wrote the rest. */
|
|
62
|
+
function starterEmptied(node, starter, defaultsOf) {
|
|
63
|
+
const cleared = {};
|
|
64
|
+
for (const [k, v] of Object.entries({ ...defaultsOf?.(node.type), ...node.settings }))
|
|
65
|
+
if (typeof v === 'string' && starter.has(v.trim()))
|
|
66
|
+
cleared[k] = '';
|
|
67
|
+
return { ...node.settings, ...cleared };
|
|
68
|
+
}
|
|
56
69
|
/** The node a shopper sees, or null when the section is still starter content. */
|
|
57
70
|
export function withoutStarter(node, starter, defaultsOf, copyFieldsOf) {
|
|
58
71
|
if (starter.size === 0)
|
|
59
72
|
return node;
|
|
60
73
|
if (holdsStarter(node.type, node.settings, starter, defaultsOf)) {
|
|
61
74
|
const settings = sectionWithoutStarter(node, starter, defaultsOf, copyFieldsOf);
|
|
62
|
-
|
|
75
|
+
// AppBlocks-1: an app block the merchant placed keeps its section up (a reviews app in the starter "Our story"
|
|
76
|
+
// rich text rendered nothing on a live store, 2026-11-23); the section's own starter copy is still emptied
|
|
77
|
+
if (!settings && !holdsAppBlock(pruneBlocks(node.blocks, starter, defaultsOf)))
|
|
63
78
|
return null;
|
|
64
|
-
node = { ...node, settings };
|
|
79
|
+
node = { ...node, settings: settings ?? starterEmptied(node, starter, defaultsOf) };
|
|
65
80
|
}
|
|
66
81
|
if (!node.blocks?.length)
|
|
67
82
|
return node;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* "<resource title> — <shop>" → the shop name. Description: SEO description →
|
|
13
13
|
* page bodySummary → shop description (home only).
|
|
14
14
|
*/
|
|
15
|
-
import type { DataApi } from '../kit/
|
|
15
|
+
import type { DataApi } from '../kit/data.js';
|
|
16
16
|
import type { MetaobjectPage } from '../kit/data.js';
|
|
17
17
|
import { type JsonLd } from './structured-data.js';
|
|
18
18
|
/**
|
|
@@ -12,7 +12,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
* navigation away from the landing URL renders the new template's tree instead.
|
|
13
13
|
*/
|
|
14
14
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
15
|
-
|
|
15
|
+
// The defining modules, never the runtime/kit barrel: it re-exports ssg.tsx and so react-dom/server, which esbuild keeps
|
|
16
|
+
// in a client bundle (build-service then refuses the build). test/headless/no-runtime-barrel.test.ts walks the client graph.
|
|
17
|
+
import { SectionTree } from '../kit/SectionTree.js';
|
|
18
|
+
import { groupsFromGlob, resolvePageSections } from '../kit/mount.js';
|
|
19
|
+
import { useData } from '../kit/data.js';
|
|
20
|
+
import { useSettings } from '../kit/theme-context.js';
|
|
16
21
|
import { applyHead, computeHead } from '../seo/head.js';
|
|
17
22
|
import { emitRoute } from '../platform/route-analytics.js';
|
|
18
23
|
import { matchRoute, resolveAsyncVariant, resolvePageTemplate } from '../data/routes.js';
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type ReactNode } from 'react';
|
|
8
8
|
import { type ThemeMode } from '../../sdk/index.js';
|
|
9
|
+
/** The link that opens the shopper's privacy choices (the platform's opt-out page body links it). */
|
|
10
|
+
export declare const PRIVACY_CHOICES_LINK = "a[href=\"#privacy-choices\"]";
|
|
11
|
+
/** The platform's data sharing opt-out page (store-api storefront-projection OPT_OUT_HANDLE). */
|
|
12
|
+
export declare const PRIVACY_CHOICES_PAGE = "/pages/data-sharing-opt-out";
|
|
9
13
|
export declare function RuntimeBridge({ mode, locale, settings, children }: {
|
|
10
14
|
mode: ThemeMode;
|
|
11
15
|
locale: string;
|
|
@@ -5,7 +5,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
* API. One instance per page, so every section and overlay shares the same
|
|
6
6
|
* cart-line status.
|
|
7
7
|
*/
|
|
8
|
-
import { useMemo, useState } from 'react';
|
|
8
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
9
9
|
import { ThemeRuntimeContext } from '../../sdk/index.js';
|
|
10
10
|
import { useData } from '../kit/data.js';
|
|
11
11
|
import { useCart } from '../kit/cart.js';
|
|
@@ -14,14 +14,34 @@ import { useCartActions, navigate, searchHref, changeCountry, changeLocale } fro
|
|
|
14
14
|
import { useOverlays } from './overlay-state.js';
|
|
15
15
|
import { useStore } from '../data/StoreProvider.js';
|
|
16
16
|
import * as map from '../data/to-ui.js';
|
|
17
|
+
/** The link that opens the shopper's privacy choices (the platform's opt-out page body links it). */
|
|
18
|
+
export const PRIVACY_CHOICES_LINK = 'a[href="#privacy-choices"]';
|
|
19
|
+
/** The platform's data sharing opt-out page (store-api storefront-projection OPT_OUT_HANDLE). */
|
|
20
|
+
export const PRIVACY_CHOICES_PAGE = '/pages/data-sharing-opt-out';
|
|
17
21
|
export function RuntimeBridge({ mode, locale, settings, children }) {
|
|
18
22
|
const cart = useCart();
|
|
19
23
|
const data = useData();
|
|
20
24
|
const store = useStore();
|
|
21
25
|
const overlays = useOverlays();
|
|
22
26
|
const cartActions = useCartActions();
|
|
23
|
-
// The shopper asked to change their cookie choice (footer link): show
|
|
27
|
+
// The shopper asked to change their cookie choice (footer link, a `#privacy-choices` link): show their choices again,
|
|
28
|
+
// as the preferences dialog itself (board 35 #42, 2026-11-24: it showed the banner, one more click away).
|
|
24
29
|
const [consentReopened, setConsentReopened] = useState(false);
|
|
30
|
+
// The choice made on this page (the preferences dialog starts from it when reopened).
|
|
31
|
+
const [lastChoice, setLastChoice] = useState(null);
|
|
32
|
+
// Board 35 #42: a link to `#privacy-choices` (the platform's data sharing opt-out page) opens the shopper's privacy
|
|
33
|
+
// choices on any page, wherever the shopper is.
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const onClick = (e) => {
|
|
36
|
+
const target = e.target;
|
|
37
|
+
if (!target || typeof target.closest !== 'function' || !target.closest(PRIVACY_CHOICES_LINK))
|
|
38
|
+
return;
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
setConsentReopened(true);
|
|
41
|
+
};
|
|
42
|
+
document.addEventListener('click', onClick);
|
|
43
|
+
return () => document.removeEventListener('click', onClick);
|
|
44
|
+
}, []);
|
|
25
45
|
const actions = useMemo(() => ({
|
|
26
46
|
cart: {
|
|
27
47
|
add: cartActions.addToCart,
|
|
@@ -56,11 +76,16 @@ export function RuntimeBridge({ mode, locale, settings, children }) {
|
|
|
56
76
|
consent: {
|
|
57
77
|
decide: (c) => {
|
|
58
78
|
setConsent({ analytics: c.analytics, marketing: c.marketing });
|
|
59
|
-
// Theme ABI v2: the platform records the choice (POST /_tq/actions/consent.set).
|
|
60
|
-
|
|
79
|
+
// Theme ABI v2: the platform records the choice (POST /_tq/actions/consent.set). `functional` is the
|
|
80
|
+
// preferences purpose as the shopper set it: off when they rejected non-essential (board 35 #42, 2026-11-24:
|
|
81
|
+
// it was always saved on).
|
|
82
|
+
const preferences = c.preferences === true;
|
|
83
|
+
void data.consent?.set({ analytics: c.analytics, marketing: c.marketing, functional: preferences }).catch(() => { });
|
|
84
|
+
setLastChoice({ analytics: c.analytics, marketing: c.marketing, preferences });
|
|
61
85
|
setConsentReopened(false);
|
|
62
86
|
},
|
|
63
87
|
open: () => setConsentReopened(true),
|
|
88
|
+
close: () => setConsentReopened(false),
|
|
64
89
|
},
|
|
65
90
|
overlays: { close: overlays.close },
|
|
66
91
|
toasts: { show: (m, tone = 'info') => overlays.toast(m, tone === 'error' ? 'error' : 'default'), dismiss: overlays.dismiss },
|
|
@@ -75,6 +100,7 @@ export function RuntimeBridge({ mode, locale, settings, children }) {
|
|
|
75
100
|
locale,
|
|
76
101
|
settings,
|
|
77
102
|
cart: map.toCart(cart),
|
|
103
|
+
cartStatus: cart.ready ? 'ready' : cart.loadError && !cart.loadRetrying ? 'failed' : 'loading',
|
|
78
104
|
checkoutUrl: cart.checkoutUrl ?? '/checkout',
|
|
79
105
|
overlay: overlays.open,
|
|
80
106
|
justAddedToCart: overlays.justAdded,
|
|
@@ -82,12 +108,17 @@ export function RuntimeBridge({ mode, locale, settings, children }) {
|
|
|
82
108
|
failedLines: [...cartActions.failedLines],
|
|
83
109
|
refusedLines: Object.fromEntries(cartActions.refusedLines),
|
|
84
110
|
toasts: overlays.toasts.map((t) => ({ id: t.id, message: t.message, tone: t.tone === 'error' ? 'error' : 'info' })),
|
|
85
|
-
|
|
111
|
+
// Reopened by the shopper: shown wherever they are (a choice can be changed outside a region that requires the banner).
|
|
112
|
+
consentRequired: Boolean((store?.ctx.consentEnabled && store.ctx.consentAnswered === false) || consentReopened),
|
|
113
|
+
...(consentReopened ? { consentManage: true } : {}),
|
|
114
|
+
...((lastChoice ?? store?.ctx.consentChoice) ? { consentChoice: (lastChoice ?? store?.ctx.consentChoice) } : {}),
|
|
115
|
+
// The platform's data sharing opt-out page, where a sale-of-data opt-out applies to the shopper (board 35 #42).
|
|
116
|
+
...(store?.ctx.consentOptOut ? { privacyChoicesUrl: PRIVACY_CHOICES_PAGE } : {}),
|
|
86
117
|
privacyPolicyUrl: privacyUrl,
|
|
87
118
|
...(shop ? { shop } : {}),
|
|
88
119
|
...(store?.ctx.newsletterEndpoint ? { formEndpoint: store.ctx.newsletterEndpoint } : {}),
|
|
89
120
|
...(store?.ctx.formResult ? { formResult: store.ctx.formResult } : {}),
|
|
90
|
-
}), [mode, locale, settings, cart, overlays.open, overlays.justAdded, overlays.toasts, cartActions.busyLines, cartActions.failedLines, cartActions.refusedLines, store?.ctx.consentEnabled, store?.ctx.consentAnswered, consentReopened, privacyUrl, shop, store?.ctx.newsletterEndpoint, store?.ctx.formResult]);
|
|
121
|
+
}), [mode, locale, settings, cart, overlays.open, overlays.justAdded, overlays.toasts, cartActions.busyLines, cartActions.failedLines, cartActions.refusedLines, store?.ctx.consentEnabled, store?.ctx.consentAnswered, store?.ctx.consentChoice, store?.ctx.consentOptOut, consentReopened, lastChoice, privacyUrl, shop, store?.ctx.newsletterEndpoint, store?.ctx.formResult]);
|
|
91
122
|
const value = useMemo(() => ({ context, actions }), [context, actions]);
|
|
92
123
|
return _jsx(ThemeRuntimeContext.Provider, { value: value, children: children });
|
|
93
124
|
}
|
package/dist/runtime/slots.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export interface EditorRuntime {
|
|
|
64
64
|
sectionPreview?(request: Request, bundle: ThemeBundle, page: {
|
|
65
65
|
styles: string;
|
|
66
66
|
settings: Record<string, unknown>;
|
|
67
|
-
data?: import('./kit/
|
|
67
|
+
data?: import('./kit/data.js').DataApi;
|
|
68
68
|
}): Response | null;
|
|
69
69
|
}
|
|
70
70
|
export declare function setThemeBundle(b: ThemeBundle): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ThemeFont } from './fonts.js';
|
|
2
|
+
/**
|
|
3
|
+
* A font setting's value as a CSS `font-family` stack, and the font loads: a catalogue family is imported by the server
|
|
4
|
+
* render (or fetched by the browser when the merchant picks it on the canvas); a theme font is the theme's own
|
|
5
|
+
* `@font-face`; a system face loads nothing. Undefined when the value is '' or not a font this theme offers.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFont(value: unknown, themeFonts?: readonly ThemeFont[]): string | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useFont (fonts.ts): a font setting's value as a CSS `font-family` stack, and the font loads.
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { registerFontFamily } from './sx.js';
|
|
6
|
+
import { fontStack, isCatalogueFont, loadCatalogueFont } from './fonts.js';
|
|
7
|
+
/**
|
|
8
|
+
* A font setting's value as a CSS `font-family` stack, and the font loads: a catalogue family is imported by the server
|
|
9
|
+
* render (or fetched by the browser when the merchant picks it on the canvas); a theme font is the theme's own
|
|
10
|
+
* `@font-face`; a system face loads nothing. Undefined when the value is '' or not a font this theme offers.
|
|
11
|
+
*/
|
|
12
|
+
export function useFont(value, themeFonts = []) {
|
|
13
|
+
const family = isCatalogueFont(value) ? value : null;
|
|
14
|
+
if (family)
|
|
15
|
+
registerFontFamily(family);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (family)
|
|
18
|
+
void loadCatalogueFont(family);
|
|
19
|
+
}, [family]);
|
|
20
|
+
return fontStack(value, themeFonts);
|
|
21
|
+
}
|