@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
package/dist/build.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { aiProfileOf, checkAiProfile } from './headless/ai.js';
|
|
2
2
|
import { KIT_STRINGS } from './headless/strings.js';
|
|
3
3
|
import { APP_BLOCKS, acceptsAppBlocks } from './runtime/kit/contract/content.js';
|
|
4
|
+
import { editorOnlyReplacement } from './runtime/kit/contract/validate.js';
|
|
5
|
+
import { fontValueProblem, FAMILY_NAME } from './sdk/fonts.js';
|
|
4
6
|
export { aiProfileOf, checkAiProfile } from './headless/ai.js';
|
|
5
7
|
export { KIT_STRINGS, kitStrings } from './headless/strings.js';
|
|
6
8
|
/** RFC 8785 JSON canonicalization: `manifest.json` is its JCS bytes plus one trailing LF. */
|
|
@@ -67,10 +69,17 @@ export function fieldSpecOf(key, f) {
|
|
|
67
69
|
if (f.control === 'range' && f.unit)
|
|
68
70
|
out.unit = f.unit;
|
|
69
71
|
}
|
|
72
|
+
else if (f.control === 'list') {
|
|
73
|
+
// A resource list (registry `list`): each entry is a handle the platform resolves into snapshot.refs, one ref per
|
|
74
|
+
// entry (`${nodeId}.${key}.${index}`), like a single resource setting.
|
|
75
|
+
out.items = { type: f.items, ...(RESOLVED.has(f.items) ? { resolve: true } : {}) };
|
|
76
|
+
out.max = f.max;
|
|
77
|
+
}
|
|
70
78
|
if (RESOLVED.has(f.control))
|
|
71
79
|
out.resolve = true;
|
|
72
|
-
// "Not set" is an absent key: an empty default is no default.
|
|
73
|
-
|
|
80
|
+
// "Not set" is an absent key: an empty default (text or list) is no default.
|
|
81
|
+
const empty = f.default === '' || f.default === null || f.default === undefined || (Array.isArray(f.default) && f.default.length === 0);
|
|
82
|
+
if (!empty)
|
|
74
83
|
out.default = f.default;
|
|
75
84
|
return out;
|
|
76
85
|
}
|
|
@@ -146,8 +155,7 @@ export function buildManifest(input) {
|
|
|
146
155
|
const blocks = s.blocks ?? [];
|
|
147
156
|
// theme-abi §7.2: `'@app'` in the section's schema blocks accepts the blocks of installed apps (never on layout).
|
|
148
157
|
const appBlocks = acceptsAppBlocks(s.schema.blocks);
|
|
149
|
-
|
|
150
|
-
problems.push(`sections: "${s.id}" is a layout section and cannot accept app blocks ("${APP_BLOCKS}")`);
|
|
158
|
+
// a header or footer section may accept app blocks too (theme-abi §7.2 AppBlocks-1)
|
|
151
159
|
if (blocks.length || appBlocks)
|
|
152
160
|
c.children = [...blocks.map((b) => b.name), ...(appBlocks ? [APP_BLOCKS] : [])];
|
|
153
161
|
if (s.requiresContext?.length)
|
|
@@ -173,6 +181,14 @@ export function buildManifest(input) {
|
|
|
173
181
|
components[b.name] = { role: 'block', title: b.title ?? humanize(b.name), attributes: attributesOf(b), parents: [...parents], ...(b.description ? { description: b.description } : {}), ...(b.requiresContext?.length ? { requires: [...b.requiresContext] } : {}) };
|
|
174
182
|
}
|
|
175
183
|
}
|
|
184
|
+
// MCP limits item 7: an editor-only type written as a control is refused here with its declarable form named
|
|
185
|
+
// (the manifest schema would only say the type is not allowed)
|
|
186
|
+
for (const [cid, c] of Object.entries(components))
|
|
187
|
+
for (const [k, spec] of Object.entries(c.attributes)) {
|
|
188
|
+
const instead = editorOnlyReplacement(spec.type);
|
|
189
|
+
if (instead)
|
|
190
|
+
problems.push(`components.${cid}.attributes.${k}: "${String(spec.type)}" cannot be declared by a theme. ${instead}`);
|
|
191
|
+
}
|
|
176
192
|
// Defaults and preset values against their attributes.
|
|
177
193
|
for (const [cid, c] of Object.entries(components)) {
|
|
178
194
|
const attrs = c.attributes;
|
|
@@ -209,11 +225,70 @@ export function buildManifest(input) {
|
|
|
209
225
|
if (!groups.has(g))
|
|
210
226
|
groups.set(g, []);
|
|
211
227
|
const item = settingItem(key, spec);
|
|
228
|
+
const instead = editorOnlyReplacement(spec.type);
|
|
229
|
+
if (instead)
|
|
230
|
+
problems.push(`settingsSchema.${g}.${key}: "${String(spec.type)}" cannot be declared by a theme. ${instead}`);
|
|
212
231
|
if (item.default !== undefined)
|
|
213
232
|
check(`settingsSchema.${g}.${key}.default`, spec.type, item.default, item);
|
|
214
233
|
groups.get(g).push(item);
|
|
215
234
|
}
|
|
216
235
|
const settingsSchema = [...groups].map(([group, items]) => ({ group, items }));
|
|
236
|
+
// ── the editor's hints (`x-tanqory-editor`): what the ABI manifest does not carry ──────────────────────────────
|
|
237
|
+
// A font select (fontSetting / field.font) is a plain `select` to the ABI (registry 1-3); the editor draws it as its
|
|
238
|
+
// font picker from these hints (studio-api artifact-workspace.mjs merges them into what the editor reads).
|
|
239
|
+
const editor = { settings: {}, components: {} };
|
|
240
|
+
const declared = input.themeFontFamilies ? new Set(input.themeFontFamilies) : null;
|
|
241
|
+
const fontChecks = (where, values, groups, def) => {
|
|
242
|
+
const theme = new Set(values.filter((v) => groups[v] === 'Theme'));
|
|
243
|
+
for (const f of theme) {
|
|
244
|
+
if (!FAMILY_NAME.test(f))
|
|
245
|
+
problems.push(`${where}: theme font "${f}" is not a family name (letters, digits, spaces, hyphens)`);
|
|
246
|
+
else if (declared && !declared.has(f))
|
|
247
|
+
problems.push(`${where}: theme font "${f}" is not one of the theme's fonts (themeFontFamilies)`);
|
|
248
|
+
}
|
|
249
|
+
for (const v of values) {
|
|
250
|
+
const p = fontValueProblem(v, theme);
|
|
251
|
+
if (p)
|
|
252
|
+
problems.push(`${where}: ${p}`);
|
|
253
|
+
}
|
|
254
|
+
if (typeof def === 'string' && !values.includes(def))
|
|
255
|
+
problems.push(`${where}: the default "${def}" is not one of its fonts`);
|
|
256
|
+
};
|
|
257
|
+
for (const [key, spec] of Object.entries(input.settings ?? {})) {
|
|
258
|
+
if (spec.control !== 'font' && spec.control !== 'color_scheme' && !spec.weight_setting && !spec.options?.some((o) => o.group || o.scripts))
|
|
259
|
+
continue;
|
|
260
|
+
const hints = {};
|
|
261
|
+
if (spec.control)
|
|
262
|
+
hints.control = spec.control;
|
|
263
|
+
if (spec.weight_setting)
|
|
264
|
+
hints.weight_setting = spec.weight_setting;
|
|
265
|
+
const opts = (spec.options ?? []).filter((o) => o.group || o.scripts);
|
|
266
|
+
if (opts.length)
|
|
267
|
+
hints.options = Object.fromEntries(opts.map((o) => [o.value, { ...(o.group ? { group: o.group } : {}), ...(o.scripts ? { scripts: [...o.scripts] } : {}) }]));
|
|
268
|
+
editor.settings[key] = hints;
|
|
269
|
+
if (spec.control === 'font') {
|
|
270
|
+
if (spec.type !== 'select')
|
|
271
|
+
problems.push(`settingsSchema.${key}: a font setting is a select`);
|
|
272
|
+
fontChecks(`settingsSchema.${key}`, (spec.options ?? []).map((o) => o.value), Object.fromEntries((spec.options ?? []).map((o) => [o.value, o.group])), spec.default);
|
|
273
|
+
if (spec.weight_setting && !input.settings?.[spec.weight_setting])
|
|
274
|
+
problems.push(`settingsSchema.${key}: weight_setting "${spec.weight_setting}" is not a theme setting`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const hintsOf = (cid, fields) => {
|
|
278
|
+
for (const [k, f] of Object.entries(fields)) {
|
|
279
|
+
if (f.control !== 'select' || !f.editor || f.legacyHidden)
|
|
280
|
+
continue;
|
|
281
|
+
(editor.components[cid] ??= {})[k] = { ...f.editor };
|
|
282
|
+
fontChecks(`components.${cid}.attributes.${k}`, f.options, Object.fromEntries(Object.entries(f.editor.options).map(([v, o]) => [v, o.group])), f.default);
|
|
283
|
+
if (f.editor.weight_setting && !fields[f.editor.weight_setting])
|
|
284
|
+
problems.push(`components.${cid}.attributes.${k}: weight_setting "${f.editor.weight_setting}" is not a setting of "${cid}"`);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
for (const s of sections) {
|
|
288
|
+
hintsOf(s.id, s.schema.fields);
|
|
289
|
+
for (const b of s.blocks ?? [])
|
|
290
|
+
hintsOf(b.name, b.fields);
|
|
291
|
+
}
|
|
217
292
|
// ── routes, templates, regions ───────────────────────────────────────
|
|
218
293
|
const regions = input.regions ?? DEFAULT_REGIONS;
|
|
219
294
|
const templates = {};
|
|
@@ -244,6 +319,21 @@ export function buildManifest(input) {
|
|
|
244
319
|
continue;
|
|
245
320
|
forms[id] = { title: typeof f === 'object' ? f.title : humanize(id), fields: [...FORM_FIELDS[id]] };
|
|
246
321
|
}
|
|
322
|
+
// A `model` setting exists only in field-type registry 4 (B.4). Registries only add (B.3, B.4: "every registry-3 entry
|
|
323
|
+
// and value rule verbatim"), so a theme that declares a model setting and names no registry gets "4": the platform's
|
|
324
|
+
// build files (the custom and partner starters' scripts/build.mjs) pass none, and no theme could use field.model
|
|
325
|
+
// otherwise (MCP item 3, Dev 2026-11-20). A theme that names a lower registry keeps the refusal.
|
|
326
|
+
const modelFields = [];
|
|
327
|
+
for (const [cid, c] of Object.entries(components)) {
|
|
328
|
+
for (const [k, spec] of Object.entries((c.attributes) ?? {})) {
|
|
329
|
+
if (spec?.type === 'model')
|
|
330
|
+
modelFields.push(`components.${cid}.attributes.${k}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const fieldTypes = input.fieldTypes ?? (modelFields.length ? '4' : '2');
|
|
334
|
+
if (fieldTypes !== '4')
|
|
335
|
+
for (const at of modelFields)
|
|
336
|
+
problems.push(`${at}: field.model needs fieldTypes: '4' (tanqory-field-types@4, B.4)`);
|
|
247
337
|
const profile = input.aiProfile === false ? null : (input.aiProfile ?? aiProfileOf(sections));
|
|
248
338
|
if (profile)
|
|
249
339
|
problems.push(...checkAiProfile(profile, components));
|
|
@@ -251,7 +341,7 @@ export function buildManifest(input) {
|
|
|
251
341
|
abi: '2.0',
|
|
252
342
|
name: input.name,
|
|
253
343
|
version: input.version,
|
|
254
|
-
engines: { 'tanqory-abi': '^2.0', 'tanqory-field-types':
|
|
344
|
+
engines: { 'tanqory-abi': '^2.0', 'tanqory-field-types': fieldTypes },
|
|
255
345
|
capabilities,
|
|
256
346
|
client: { hydration: 'full' },
|
|
257
347
|
...(Object.keys(forms).length ? { forms } : {}),
|
|
@@ -263,6 +353,7 @@ export function buildManifest(input) {
|
|
|
263
353
|
components,
|
|
264
354
|
settingsSchema,
|
|
265
355
|
...(profile ? { 'x-tanqory-ai': profile } : {}),
|
|
356
|
+
...(Object.keys(editor.settings).length || Object.keys(editor.components).length ? { 'x-tanqory-editor': { v: 1, ...(Object.keys(editor.settings).length ? { settings: editor.settings } : {}), ...(Object.keys(editor.components).length ? { components: editor.components } : {}) } } : {}),
|
|
266
357
|
...(input.extensions ?? {}),
|
|
267
358
|
};
|
|
268
359
|
return { manifest, problems };
|
package/dist/chunks.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@tanqory/theme-kit/chunks` — what build-service's bundler routes every `import()` of a client-chunks theme
|
|
3
|
+
* through (theme-abi-v2.md §2.2.1). Theme code never imports this module itself: the platform bundler rewrites
|
|
4
|
+
* `import('./x')` into `__tqChunk("<key>", () => import('./x'))` (client) or `__tqChunkStatic("<key>", x)`
|
|
5
|
+
* (server, where `import()` stays banned), and adds the import of this module.
|
|
6
|
+
*
|
|
7
|
+
* 'split' the build's chunks: the boot's gate (`globalThis.__tqGate`, defined by the SRI-verified boot, not
|
|
8
|
+
* writable) preloads the chunk's whole closure with integrity, waits, then imports. With no gate the
|
|
9
|
+
* promise never settles: nothing loads unverified, and the section keeps its server HTML.
|
|
10
|
+
* 'single' the single-bundle fallback (esbuild inlined the import): load directly.
|
|
11
|
+
* anything else (a theme's own dev build, a unit test): load directly.
|
|
12
|
+
*/
|
|
13
|
+
/** A loading chunk, with the key the bundler gave it (the theme path of the imported module). */
|
|
14
|
+
export type ChunkPromise<T> = PromiseLike<T> & {
|
|
15
|
+
readonly key: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function __tqChunk<T>(key: string, load: () => Promise<T>): ChunkPromise<T>;
|
|
18
|
+
/**
|
|
19
|
+
* The server's form: the module is a static import, so the chunk is already "loaded". A thenable that calls back
|
|
20
|
+
* synchronously, so `React.lazy` renders it in the same `renderToString` pass (React reads the module as soon as
|
|
21
|
+
* `then` resolves it).
|
|
22
|
+
*/
|
|
23
|
+
export declare function __tqChunkStatic<T>(key: string, mod: T): ChunkPromise<T>;
|
package/dist/chunks.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@tanqory/theme-kit/chunks` — what build-service's bundler routes every `import()` of a client-chunks theme
|
|
3
|
+
* through (theme-abi-v2.md §2.2.1). Theme code never imports this module itself: the platform bundler rewrites
|
|
4
|
+
* `import('./x')` into `__tqChunk("<key>", () => import('./x'))` (client) or `__tqChunkStatic("<key>", x)`
|
|
5
|
+
* (server, where `import()` stays banned), and adds the import of this module.
|
|
6
|
+
*
|
|
7
|
+
* 'split' the build's chunks: the boot's gate (`globalThis.__tqGate`, defined by the SRI-verified boot, not
|
|
8
|
+
* writable) preloads the chunk's whole closure with integrity, waits, then imports. With no gate the
|
|
9
|
+
* promise never settles: nothing loads unverified, and the section keeps its server HTML.
|
|
10
|
+
* 'single' the single-bundle fallback (esbuild inlined the import): load directly.
|
|
11
|
+
* anything else (a theme's own dev build, a unit test): load directly.
|
|
12
|
+
*/
|
|
13
|
+
const mode = () => (typeof __TQ_CHUNK_MODE__ === 'string' ? __TQ_CHUNK_MODE__ : 'direct');
|
|
14
|
+
export function __tqChunk(key, load) {
|
|
15
|
+
let p;
|
|
16
|
+
if (mode() === 'split') {
|
|
17
|
+
const gate = globalThis.__tqGate;
|
|
18
|
+
p = typeof gate === 'function' ? gate(key, load) : new Promise(() => { });
|
|
19
|
+
}
|
|
20
|
+
else
|
|
21
|
+
p = load();
|
|
22
|
+
return Object.assign(p, { key });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The server's form: the module is a static import, so the chunk is already "loaded". A thenable that calls back
|
|
26
|
+
* synchronously, so `React.lazy` renders it in the same `renderToString` pass (React reads the module as soon as
|
|
27
|
+
* `then` resolves it).
|
|
28
|
+
*/
|
|
29
|
+
export function __tqChunkStatic(key, mod) {
|
|
30
|
+
const t = {
|
|
31
|
+
key,
|
|
32
|
+
status: 'fulfilled',
|
|
33
|
+
value: mod,
|
|
34
|
+
then(ok) {
|
|
35
|
+
if (ok)
|
|
36
|
+
ok(mod);
|
|
37
|
+
return t;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
return t;
|
|
41
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ThemeBundle } from './runtime/slots.js';
|
|
2
2
|
import type { ContentNode } from './runtime/kit/types.js';
|
|
3
|
+
import type { PageData } from './abi/page-data.js';
|
|
3
4
|
type Settings = Record<string, unknown>;
|
|
4
5
|
export interface HydrateOptions {
|
|
5
6
|
/** The theme bundle the server entry was built from (the same object `createRender` got). */
|
|
@@ -9,6 +10,12 @@ export interface HydrateOptions {
|
|
|
9
10
|
* hydrated tree is the one the server rendered. Default: unchanged.
|
|
10
11
|
*/
|
|
11
12
|
transformNodes?(nodes: ContentNode[], settings: Settings): ContentNode[];
|
|
13
|
+
/**
|
|
14
|
+
* The server entry's settings hooks (`RenderOptions.effectiveSettings` and `shopSettings`), run again on the editor
|
|
15
|
+
* canvas over the editor's live theme settings, so the preview matches what the server renders. Default: unchanged.
|
|
16
|
+
*/
|
|
17
|
+
effectiveSettings?(settings: Settings): Settings;
|
|
18
|
+
shopSettings?(settings: Settings, shop: PageData['shop']): Settings;
|
|
12
19
|
}
|
|
13
20
|
/**
|
|
14
21
|
* Hydrates the server-rendered page. Call it once, at module scope of the theme's browser entry.
|
package/dist/client.js
CHANGED
|
@@ -33,6 +33,8 @@ import { keepRefCode } from './abi/referrals.js';
|
|
|
33
33
|
import { createAbiRemote } from './abi/wire.js';
|
|
34
34
|
import { connectCanvas, createCanvasStore, createSettingsStore } from './abi/canvas-live.js';
|
|
35
35
|
import { locationOf, nodesOf, notFoundTree } from './abi/page.js';
|
|
36
|
+
import { preloadLazySections } from './headless/lazy-section.js';
|
|
37
|
+
import { ResolvedStateContext } from './runtime/render/resolved.js';
|
|
36
38
|
/**
|
|
37
39
|
* The editor canvas (a preview render): the section nodes live in a store the platform's editor
|
|
38
40
|
* bridge feeds, so a setting edit re-renders its section without a reload (abi/canvas-live.ts).
|
|
@@ -76,12 +78,24 @@ export function hydrate(options) {
|
|
|
76
78
|
let liveSettings = null;
|
|
77
79
|
if (preview) {
|
|
78
80
|
canvas = createCanvasStore(raw);
|
|
79
|
-
|
|
81
|
+
const effective = options.effectiveSettings ?? ((s) => s);
|
|
82
|
+
const withShop = options.shopSettings ?? ((s) => s);
|
|
83
|
+
liveSettings = createSettingsStore(settings, (s) => withShop(effective(s), state.data.shop));
|
|
80
84
|
connectCanvas(window, canvas, (type, detail) => new CustomEvent(type, { detail }), liveSettings);
|
|
81
85
|
}
|
|
82
86
|
// A `?ref=` visit keeps the friend's code for checkout even while the host has no referral ops.
|
|
83
87
|
if (!preview && !HOST_OFFERS_LOYALTY)
|
|
84
88
|
keepRefCode(window.location.search);
|
|
85
89
|
const page = (settings_) => (_jsx(ThemeProvider, { settings: settings_, locale: strings, children: _jsx(AbiCartProvider, { initial: state.data.cart, remote: remote, children: _jsx(AbiRewardsProvider, { remote: preview || !HOST_OFFERS_LOYALTY ? null : remote, children: _jsx(AbiShell, { location: location, locale: ui, contentLanguage: state.lang, settings: settings_, preview: preview, labels: state.labels, children: canvas ? _jsx(LiveSectionTree, { store: canvas, settings: settings_, transform: transform }) : _jsx(SectionTree, { tree: state.data.routeMissing ? notFoundTree(transform(raw, settings_)) : transform(raw, settings_) }) }) }) }) }));
|
|
86
|
-
|
|
90
|
+
const go = () => {
|
|
91
|
+
hydrateRoot(root, _jsx(PreviewModeProvider, { value: preview, children: _jsx(ResolvedStateContext.Provider, { value: state.resolved ?? null, children: _jsx(DataProvider, { value: data, children: liveSettings ? _jsx(WithLiveSettings, { store: liveSettings, children: page }) : page(settings) }) }) }));
|
|
92
|
+
};
|
|
93
|
+
// Client chunks (theme-abi-v2 §2.2.1): the page's lazy sections load first, so none suspends while React hydrates.
|
|
94
|
+
// A boundary still suspended at hydration would be client-rendered (its server HTML dropped) by the first update
|
|
95
|
+
// that reaches it. The boot already verified the page's chunks, so these resolve at once.
|
|
96
|
+
const pending = preloadLazySections(bundle.theme.sections, canvas ? raw : transform(raw, settings));
|
|
97
|
+
if (pending)
|
|
98
|
+
void pending.then(go);
|
|
99
|
+
else
|
|
100
|
+
go();
|
|
87
101
|
}
|
package/dist/headless/hooks.js
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
10
|
import { useThemeActions, useThemeContext } from '../sdk/runtime-context.js';
|
|
11
11
|
import { useStore } from '../runtime/data/StoreProvider.js';
|
|
12
|
-
|
|
12
|
+
// Straight from the defining modules, never the runtime/kit barrel: the barrel re-exports ssg.js, whose
|
|
13
|
+
// `react-dom/server` import is CommonJS, and esbuild (build-service's bundler) keeps it in a client bundle even with
|
|
14
|
+
// sideEffects false. Through the barrel the client carried ~70 kB of react-dom/server (BLD 2026-11-21, Nova 831bc27d).
|
|
15
|
+
import { useCart as useRuntimeCart } from '../runtime/kit/cart.js';
|
|
16
|
+
import { useData } from '../runtime/kit/data.js';
|
|
13
17
|
import * as map from '../runtime/data/to-ui.js';
|
|
14
18
|
import { filterRequests, metafieldBooleanLabelKey, queryOfState, stateFromQuery, withListingQuery } from '../runtime/render/listing-query.js';
|
|
15
19
|
import { localeHref } from '../runtime/render/section-actions.js';
|
package/dist/headless/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* the kit supplies the data, the behaviour and accessible, semantic primitives carrying the platform's
|
|
4
4
|
* `tq-storefront-hooks/1` attributes (`data-tq-action`, `data-tq-price`, `data-tq-variant-picker`, …).
|
|
5
5
|
*
|
|
6
|
-
* declare defineTheme · defineSection · defineBlock · field · ai.*
|
|
6
|
+
* declare defineTheme · defineSection · defineBlock · field · ai.* · AppBlock · APP_BLOCKS ('@app')
|
|
7
7
|
* data useShop · useMenu · useProduct · useCollection · useSearch · usePredictiveSearch · useCart ·
|
|
8
8
|
* useCustomer · useLocalization · useRecommendations · useConsent · usePage
|
|
9
9
|
* commerce ProductForm · VariantPicker · ProductPrice · ProductQuantity · AddToCart · CartToggle · CartDrawer ·
|
|
@@ -20,6 +20,10 @@ export { defineTheme, defineSection, defineBlock, type HeadlessThemeDefinition,
|
|
|
20
20
|
export { ai, aiProfileOf, checkAiProfile, type AiRole, type AiProfile } from './ai.js';
|
|
21
21
|
export { field, defineSchema, resolveSettings, type Field, type Fields, type Schema } from '../sdk/schema.js';
|
|
22
22
|
export { defineSettings, type SettingSpec } from '../sdk/theme.js';
|
|
23
|
+
export { AppBlock, isAppBlock, appBlockSettingsJson, type AppBlockProps } from '../sdk/app-block.js';
|
|
24
|
+
export { APP_BLOCKS } from '../runtime/kit/contract/content.js';
|
|
25
|
+
export { FONT_CATALOGUE, SYSTEM_FONTS, FONT_WEIGHTS, fontSetting, fontOptions, fontStack, isCatalogueFont, type CatalogueFont, type ThemeFont, type FontOption, type FontScript, type FontSettingInput } from '../sdk/fonts.js';
|
|
26
|
+
export { useFont } from '../sdk/font-hooks.js';
|
|
23
27
|
export { useSettings, useShop, useMenu, useProduct, useProductState, useCollection, useCollectionState, useSearch, usePredictiveSearch, useCart, useCustomer, useLocalization, useRecommendations, useConsent, usePageContent, useBlog, useArticle, usePolicy, initialVariant, optionStates, ProductContext, CollectionContext, COLLECTION_SORTS, SEARCH_SORT_IDS, type ProductState, type OptionValueState, type CollectionState, type CollectionSort, type SearchState, type PredictiveResults, type CartStateHeadless as CartState, type CustomerState, type LocalizationState, type CountryChoice, type LanguageChoice, type ConsentState, } from './hooks.js';
|
|
24
28
|
export { usePage, DETACHED_PAGE, type PageInfo } from './page.js';
|
|
25
29
|
export { ProductForm, VariantPicker, ProductPrice, ProductQuantity, AddToCart, useProductForm, type ProductFormState, type ProductFormProps, type VariantPickerProps, type ProductPriceProps, type ProductQuantityProps, type AddToCartProps } from './primitives/product.js';
|
|
@@ -27,6 +31,9 @@ export { CartToggle, CartDrawer, CartLine, CartLineQuantity, CartLineIncrement,
|
|
|
27
31
|
export { CollectionProvider, SortSelect, FacetFilters, Pagination, type CollectionProviderProps, type SortSelectProps, type FacetFiltersProps, type PaginationProps } from './primitives/collection.js';
|
|
28
32
|
export { SearchForm, LocalizationForm, NewsletterForm, ContactForm, ConsentBanner, AccountSlot, type SearchFormProps, type LocalizationFormProps, type PlatformFormProps, type PlatformFormState, type FormStatus, type ConsentBannerProps } from './primitives/storefront.js';
|
|
29
33
|
export { Seo, Image, SkipLink, resolveImageUrl, type SeoProps, type ImageProps } from './platform.js';
|
|
34
|
+
export { lazySection } from './lazy-section.js';
|
|
35
|
+
export { lazyComponent, preloadOnIdle, type LazyComponent, type LazyComponentOptions } from './lazy-component.js';
|
|
36
|
+
export { ModelViewer, ModelViewerBase, loadModelViewer, MODEL_VIEWER_SRC, MODEL_VIEWER_INTEGRITY, type ModelViewerProps, type ModelViewerBaseProps, type ModelViewerLabels, type ModelMedia } from './model.js';
|
|
30
37
|
export { useTranslate, translate, interpolate, KIT_STRINGS, kitStrings, type Translate, type TranslateVars, type Strings } from './i18n.js';
|
|
31
38
|
export { formatMoney, currencyDecimals, currencySymbol, type MoneyLike, type FormatMoneyOptions } from './money.js';
|
|
32
39
|
export { productJsonLd, homeJsonLd, articleJsonLd, collectionJsonLd, breadcrumbJsonLd, type JsonLd, type Crumb } from './structured-data.js';
|
package/dist/headless/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* the kit supplies the data, the behaviour and accessible, semantic primitives carrying the platform's
|
|
4
4
|
* `tq-storefront-hooks/1` attributes (`data-tq-action`, `data-tq-price`, `data-tq-variant-picker`, …).
|
|
5
5
|
*
|
|
6
|
-
* declare defineTheme · defineSection · defineBlock · field · ai.*
|
|
6
|
+
* declare defineTheme · defineSection · defineBlock · field · ai.* · AppBlock · APP_BLOCKS ('@app')
|
|
7
7
|
* data useShop · useMenu · useProduct · useCollection · useSearch · usePredictiveSearch · useCart ·
|
|
8
8
|
* useCustomer · useLocalization · useRecommendations · useConsent · usePage
|
|
9
9
|
* commerce ProductForm · VariantPicker · ProductPrice · ProductQuantity · AddToCart · CartToggle · CartDrawer ·
|
|
@@ -21,6 +21,13 @@ export { defineTheme, defineSection, defineBlock } from './theme.js';
|
|
|
21
21
|
export { ai, aiProfileOf, checkAiProfile } from './ai.js';
|
|
22
22
|
export { field, defineSchema, resolveSettings } from '../sdk/schema.js';
|
|
23
23
|
export { defineSettings } from '../sdk/theme.js';
|
|
24
|
+
// app blocks (theme-abi §7.2): a section lists '@app' (APP_BLOCKS) in its blocks and renders each block of an installed
|
|
25
|
+
// app with <AppBlock>; every theme does so on its product section and on a general section (AppBlocks-1)
|
|
26
|
+
export { AppBlock, isAppBlock, appBlockSettingsJson } from '../sdk/app-block.js';
|
|
27
|
+
export { APP_BLOCKS } from '../runtime/kit/contract/content.js';
|
|
28
|
+
// fonts (TS-7): the platform catalogue (same-origin /_tq/fonts), the theme's own assets/*.woff2, the device's faces
|
|
29
|
+
export { FONT_CATALOGUE, SYSTEM_FONTS, FONT_WEIGHTS, fontSetting, fontOptions, fontStack, isCatalogueFont } from '../sdk/fonts.js';
|
|
30
|
+
export { useFont } from '../sdk/font-hooks.js';
|
|
24
31
|
// data
|
|
25
32
|
export { useSettings, useShop, useMenu, useProduct, useProductState, useCollection, useCollectionState, useSearch, usePredictiveSearch, useCart, useCustomer, useLocalization, useRecommendations, useConsent, usePageContent, useBlog, useArticle, usePolicy, initialVariant, optionStates, ProductContext, CollectionContext, COLLECTION_SORTS, SEARCH_SORT_IDS, } from './hooks.js';
|
|
26
33
|
export { usePage, DETACHED_PAGE } from './page.js';
|
|
@@ -31,6 +38,9 @@ export { CollectionProvider, SortSelect, FacetFilters, Pagination } from './prim
|
|
|
31
38
|
export { SearchForm, LocalizationForm, NewsletterForm, ContactForm, ConsentBanner, AccountSlot } from './primitives/storefront.js';
|
|
32
39
|
// platform
|
|
33
40
|
export { Seo, Image, SkipLink, resolveImageUrl } from './platform.js';
|
|
41
|
+
export { lazySection } from './lazy-section.js';
|
|
42
|
+
export { lazyComponent, preloadOnIdle } from './lazy-component.js';
|
|
43
|
+
export { ModelViewer, ModelViewerBase, loadModelViewer, MODEL_VIEWER_SRC, MODEL_VIEWER_INTEGRITY } from './model.js';
|
|
34
44
|
export { useTranslate, translate, interpolate, KIT_STRINGS, kitStrings } from './i18n.js';
|
|
35
45
|
export { formatMoney, currencyDecimals, currencySymbol } from './money.js';
|
|
36
46
|
export { productJsonLd, homeJsonLd, articleJsonLd, collectionJsonLd, breadcrumbJsonLd } from './structured-data.js';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `lazyComponent(() => import('./CartDrawer'), 'CartDrawer', { active: (p) => p.open, enter: (p) => ({ ...p, open: false }) })`
|
|
3
|
+
* — a component that is not a section (a drawer, a modal, a menu: anything the shopper opens) whose code loads as its
|
|
4
|
+
* own client chunk after the page has hydrated, not before (theme-abi-v2.md §2.2.1, a theme with
|
|
5
|
+
* `manifest.client.chunks: "sections"`; in any other build `import()` is inlined or loads directly).
|
|
6
|
+
*
|
|
7
|
+
* Hydration stays byte-identical by construction:
|
|
8
|
+
* - On the server and while React hydrates, it renders `placeholder` (default: nothing), whatever its props say, and
|
|
9
|
+
* loads nothing. So the server HTML and the browser's first render are the same, with or without its chunk.
|
|
10
|
+
* (`useSyncExternalStore` with a server snapshot: React reads `false` on the server and during hydration, `true` on
|
|
11
|
+
* every render after it, and re-renders once hydration has committed.)
|
|
12
|
+
* - Its chunk key is never recorded for the page's `<head>` (ChunkSinkContext is lazySection's), so the boot does not
|
|
13
|
+
* fetch it before hydration: it costs nothing on first load.
|
|
14
|
+
*
|
|
15
|
+
* After hydration:
|
|
16
|
+
* - It loads the first time `active(props)` is true (default: at once, for a component that is only mounted on a user
|
|
17
|
+
* action), or earlier when `preload()` / `preloadOnIdle()` runs. A preload fetches the code only: the page's DOM
|
|
18
|
+
* stays the server's until the shopper opens something (conformance suite 5 compares the two after hydration).
|
|
19
|
+
* - An instance mounts the real component on its first activation, once the code is there: first with `enter(props)`
|
|
20
|
+
* (e.g. closed), then with its own props two frames later, so its opening transition runs. It stays mounted after
|
|
21
|
+
* (a close keeps its exit transition).
|
|
22
|
+
* - A chunk that fails its integrity check never settles (the platform gate): the instance keeps its placeholder. A
|
|
23
|
+
* load that rejects (a theme's own dev build offline) is forgotten, and the next activation tries again.
|
|
24
|
+
*
|
|
25
|
+
* A component that can be open on first paint (open in the server HTML, or from URL state the server reads) must not
|
|
26
|
+
* be lazy: the server cannot render its open state without its code, so it would open only after hydration. Keep it
|
|
27
|
+
* an ordinary import.
|
|
28
|
+
*/
|
|
29
|
+
import { type ReactNode } from 'react';
|
|
30
|
+
type Loaded = Record<string, unknown>;
|
|
31
|
+
export interface LazyComponentOptions<P> {
|
|
32
|
+
/** When the component is needed. Until this is true once (after hydration), only `placeholder` renders. Default: always. */
|
|
33
|
+
active?: (props: P) => boolean;
|
|
34
|
+
/** The props of its first frame when it was active before its code arrived (e.g. closed). Default: its props. */
|
|
35
|
+
enter?: (props: P) => P;
|
|
36
|
+
/**
|
|
37
|
+
* What renders on the server, while React hydrates and until the code has loaded. It must depend on props only (never
|
|
38
|
+
* browser state), so the server and the browser render the same. Default: nothing.
|
|
39
|
+
*/
|
|
40
|
+
placeholder?: (props: P) => ReactNode;
|
|
41
|
+
}
|
|
42
|
+
/** A lazyComponent: `preload()` starts loading (once) and resolves when the code has loaded. */
|
|
43
|
+
export interface LazyComponent<P> {
|
|
44
|
+
(props: P): JSX.Element | null;
|
|
45
|
+
preload(): PromiseLike<unknown>;
|
|
46
|
+
/** True once the code has loaded. */
|
|
47
|
+
loaded(): boolean;
|
|
48
|
+
}
|
|
49
|
+
export declare function lazyComponent<P extends object>(load: () => PromiseLike<Loaded>, exportName?: string, options?: LazyComponentOptions<P>): LazyComponent<P>;
|
|
50
|
+
/**
|
|
51
|
+
* Preloads `components` after the page has settled, or at the shopper's first hover, touch, focus or key press,
|
|
52
|
+
* whichever comes first, so a first open finds the code already loaded. Call it after hydration (in an effect).
|
|
53
|
+
* Never throws; returns a stop function.
|
|
54
|
+
*
|
|
55
|
+
* "Settled" keeps the preload out of the page's first load (theme-abi-v2 §2.2.1: what a page fetches before it goes
|
|
56
|
+
* quiet is its first load, and a runner counts it so): the window's `load` event has fired, then no resource request
|
|
57
|
+
* has ended for `quietMs` (default 2000 ms: a conformance runner calls a page quiet after 500 ms with no request, and
|
|
58
|
+
* under load its view of the page's requests lags, so 800 ms was seen landing inside its count once), then the browser is
|
|
59
|
+
* idle (requestIdleCallback with `timeout`, default 1000 ms; a timer of `fallbackMs`, default 0, without it). The quiet
|
|
60
|
+
* is read from resource timing (a PerformanceObserver, or `performance.getEntriesByType` without one), checked every
|
|
61
|
+
* `pollMs` (default 100 ms); once it fires, nothing of it stays scheduled. A first interaction preloads at once.
|
|
62
|
+
*/
|
|
63
|
+
export declare function preloadOnIdle(components: readonly {
|
|
64
|
+
preload(): PromiseLike<unknown>;
|
|
65
|
+
}[], o?: {
|
|
66
|
+
timeout?: number;
|
|
67
|
+
fallbackMs?: number;
|
|
68
|
+
quietMs?: number;
|
|
69
|
+
pollMs?: number;
|
|
70
|
+
win?: Window;
|
|
71
|
+
}): () => void;
|
|
72
|
+
export {};
|