@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
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
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ThemeBundle } from './runtime/slots.js';
|
|
2
|
+
import type { ContentNode } from './runtime/kit/types.js';
|
|
3
|
+
import type { PageData } from './abi/page-data.js';
|
|
4
|
+
type Settings = Record<string, unknown>;
|
|
5
|
+
export interface HydrateOptions {
|
|
6
|
+
/** The theme bundle the server entry was built from (the same object `createRender` got). */
|
|
7
|
+
bundle: ThemeBundle;
|
|
8
|
+
/**
|
|
9
|
+
* The same node transform the server entry applies (`RenderOptions.transformNodes`), so the
|
|
10
|
+
* hydrated tree is the one the server rendered. Default: unchanged.
|
|
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;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Hydrates the server-rendered page. Call it once, at module scope of the theme's browser entry.
|
|
22
|
+
* Does nothing on a page without the server's state block.
|
|
23
|
+
*/
|
|
24
|
+
export declare function hydrate(options: HydrateOptions): void;
|
|
25
|
+
export type { ThemeBundle } from './runtime/slots.js';
|
|
26
|
+
export type { ContentNode } from './runtime/kit/types.js';
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* `@tanqory/theme-kit/client` — the Theme ABI v2 browser entry as a function: the one `isEntry`
|
|
4
|
+
* script of client/client-manifest.json calls `hydrate({ bundle })`.
|
|
5
|
+
*
|
|
6
|
+
* It hydrates exactly what `createRender` (./server) rendered: the page's content document and the
|
|
7
|
+
* data the server loaded are read back from the non-executable
|
|
8
|
+
* `<script type="application/json" id="tq-state">` block, so the first client render is built from
|
|
9
|
+
* the same bytes. Dynamic style values are class rules (sdk/sx.ts): the server block already holds
|
|
10
|
+
* the first render's, and a later one is inserted through CSSOM. After hydration the only requests
|
|
11
|
+
* are same-origin `/_tq/data/*` and `/_tq/actions/*` (abi/wire.ts).
|
|
12
|
+
*
|
|
13
|
+
* On the editor canvas (a preview render) the section nodes live in a store the platform's editor
|
|
14
|
+
* bridge feeds (`tq:canvas` events, announced with `tq:canvas-live`), so a setting edit re-renders
|
|
15
|
+
* its section without a reload (abi/canvas-live.ts). A theme does nothing to get this.
|
|
16
|
+
*/
|
|
17
|
+
import { unpackPageData } from './abi/state-pack.js';
|
|
18
|
+
import { useSyncExternalStore } from 'react';
|
|
19
|
+
import { hydrateRoot } from 'react-dom/client';
|
|
20
|
+
import { setThemeBundle } from './runtime/slots.js';
|
|
21
|
+
import { sectionModules } from './runtime/entries/sections.js';
|
|
22
|
+
import { registerSections } from './runtime/kit/registry.js';
|
|
23
|
+
import { SectionTree } from './runtime/kit/SectionTree.js';
|
|
24
|
+
import { DataProvider } from './runtime/kit/data.js';
|
|
25
|
+
import { ThemeProvider } from './runtime/kit/theme-context.js';
|
|
26
|
+
import { PreviewModeProvider } from './runtime/shell/preview-mode.js';
|
|
27
|
+
import { localeStrings } from './runtime/platform/locale.js';
|
|
28
|
+
import { AbiShell } from './abi/shell.js';
|
|
29
|
+
import { createDataApi } from './abi/data-api.js';
|
|
30
|
+
import { AbiCartProvider } from './abi/cart.js';
|
|
31
|
+
import { AbiRewardsProvider, HOST_OFFERS_LOYALTY } from './abi/rewards.js';
|
|
32
|
+
import { keepRefCode } from './abi/referrals.js';
|
|
33
|
+
import { createAbiRemote } from './abi/wire.js';
|
|
34
|
+
import { connectCanvas, createCanvasStore, createSettingsStore } from './abi/canvas-live.js';
|
|
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';
|
|
38
|
+
/**
|
|
39
|
+
* The editor canvas (a preview render): the section nodes live in a store the platform's editor
|
|
40
|
+
* bridge feeds, so a setting edit re-renders its section without a reload (abi/canvas-live.ts).
|
|
41
|
+
*/
|
|
42
|
+
function LiveSectionTree({ store, settings, transform }) {
|
|
43
|
+
const nodes = useSyncExternalStore(store.subscribe, store.get, store.get);
|
|
44
|
+
return _jsx(SectionTree, { tree: transform(nodes, settings) });
|
|
45
|
+
}
|
|
46
|
+
/** The theme provider + shell with the editor's live theme settings on the canvas; the server's settings otherwise. */
|
|
47
|
+
function WithLiveSettings({ store, children }) {
|
|
48
|
+
return _jsx(_Fragment, { children: children(useSyncExternalStore(store.subscribe, store.get, store.get)) });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Hydrates the server-rendered page. Call it once, at module scope of the theme's browser entry.
|
|
52
|
+
* Does nothing on a page without the server's state block.
|
|
53
|
+
*/
|
|
54
|
+
export function hydrate(options) {
|
|
55
|
+
const { bundle } = options;
|
|
56
|
+
const transform = options.transformNodes ?? ((n) => n);
|
|
57
|
+
setThemeBundle(bundle);
|
|
58
|
+
registerSections(Object.values(sectionModules()).map((m) => m.default));
|
|
59
|
+
const LOCALE_MAPS = Object.fromEntries(Object.entries(bundle.locales).map(([path, mod]) => [path.match(/\/([^/]+)\.json$/)?.[1] ?? 'en', mod.default]));
|
|
60
|
+
const el = document.getElementById('tq-state');
|
|
61
|
+
const root = document.getElementById('root');
|
|
62
|
+
if (!el || !root)
|
|
63
|
+
return;
|
|
64
|
+
const state = JSON.parse(el.textContent ?? '{}');
|
|
65
|
+
// the listing's products travel once (abi/state-pack.ts): put them back before anything reads the data
|
|
66
|
+
if (state.data)
|
|
67
|
+
unpackPageData(state.data);
|
|
68
|
+
const remote = createAbiRemote();
|
|
69
|
+
const data = createDataApi(state.data, remote);
|
|
70
|
+
const settings = state.settings ?? {};
|
|
71
|
+
const raw = nodesOf(state.page.regions);
|
|
72
|
+
const ui = state.ui ?? 'en';
|
|
73
|
+
const strings = localeStrings(ui, LOCALE_MAPS);
|
|
74
|
+
const location = locationOf(state.route.canonical, state.route.params ?? {}, state.listing ?? '');
|
|
75
|
+
const preview = state.preview === true;
|
|
76
|
+
// Preview only: never on a live storefront, whose page has no bridge to answer.
|
|
77
|
+
let canvas = null;
|
|
78
|
+
let liveSettings = null;
|
|
79
|
+
if (preview) {
|
|
80
|
+
canvas = createCanvasStore(raw);
|
|
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));
|
|
84
|
+
connectCanvas(window, canvas, (type, detail) => new CustomEvent(type, { detail }), liveSettings);
|
|
85
|
+
}
|
|
86
|
+
// A `?ref=` visit keeps the friend's code for checkout even while the host has no referral ops.
|
|
87
|
+
if (!preview && !HOST_OFFERS_LOYALTY)
|
|
88
|
+
keepRefCode(window.location.search);
|
|
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_) }) }) }) }) }));
|
|
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();
|
|
101
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@tanqory/theme-kit/contract` — the content contract the editor and the runtime share: page and
|
|
3
|
+
* section-group documents, roles, validation and the content-version transforms. Pure (no React,
|
|
4
|
+
* no DOM), so build scripts and the manifest generator can load it in Node.
|
|
5
|
+
*/
|
|
6
|
+
export * from './runtime/kit/contract/index.js';
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@tanqory/theme-kit/contract` — the content contract the editor and the runtime share: page and
|
|
3
|
+
* section-group documents, roles, validation and the content-version transforms. Pure (no React,
|
|
4
|
+
* no DOM), so build scripts and the manifest generator can load it in Node.
|
|
5
|
+
*/
|
|
6
|
+
export * from './runtime/kit/contract/index.js';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI compatibility: which of a theme's own sections and settings play the roles Tanqory AI fills (a hero, the
|
|
3
|
+
* header menu, the footer menus and brand, product grids, text blocks), so AI can compose any theme, not one
|
|
4
|
+
* vocabulary. Declared per section with the `ai.*` helpers; the build prints the profile into the manifest as
|
|
5
|
+
* `x-tanqory-ai` (draft v0).
|
|
6
|
+
*
|
|
7
|
+
* defineSection({ type: 'hero', …, ai: ai.hero({ heading: 'heading', image: 'image', button: 'buttonLabel', link: 'buttonLink' }) })
|
|
8
|
+
* defineSection({ type: 'header', …, ai: ai.headerMenu('menu') })
|
|
9
|
+
* defineSection({ type: 'footer', …, ai: [ai.footerMenu('menu', { block: 'footer-menu' }), ai.footerBrand({ block: 'footer-brand' })] })
|
|
10
|
+
*
|
|
11
|
+
* Pure: no React, no DOM (the build loads it in Node).
|
|
12
|
+
*/
|
|
13
|
+
export type AiRole = {
|
|
14
|
+
role: 'hero';
|
|
15
|
+
heading: string;
|
|
16
|
+
subheading?: string;
|
|
17
|
+
image?: string;
|
|
18
|
+
button?: string;
|
|
19
|
+
link?: string;
|
|
20
|
+
block?: string;
|
|
21
|
+
} | {
|
|
22
|
+
role: 'headerMenu';
|
|
23
|
+
setting: string;
|
|
24
|
+
block?: string;
|
|
25
|
+
} | {
|
|
26
|
+
role: 'footerMenu';
|
|
27
|
+
setting: string;
|
|
28
|
+
block?: string;
|
|
29
|
+
} | {
|
|
30
|
+
role: 'footerBrand';
|
|
31
|
+
block?: string;
|
|
32
|
+
} | {
|
|
33
|
+
role: 'productGrid';
|
|
34
|
+
setting: string;
|
|
35
|
+
heading?: string;
|
|
36
|
+
block?: string;
|
|
37
|
+
} | {
|
|
38
|
+
role: 'richText';
|
|
39
|
+
heading?: string;
|
|
40
|
+
body?: string;
|
|
41
|
+
block?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Role declarations for `defineSection({ ai })`. Every key names one of the section's (or its block's) settings. */
|
|
44
|
+
export declare const ai: {
|
|
45
|
+
/** A hero: `heading` (text), and optionally `subheading`, `image` (image), `button` (text) and `link` (url). */
|
|
46
|
+
hero: (keys: {
|
|
47
|
+
heading: string;
|
|
48
|
+
subheading?: string;
|
|
49
|
+
image?: string;
|
|
50
|
+
button?: string;
|
|
51
|
+
link?: string;
|
|
52
|
+
block?: string;
|
|
53
|
+
}) => AiRole;
|
|
54
|
+
/** The header's main menu: a `menu` setting. */
|
|
55
|
+
headerMenu: (setting: string, opts?: {
|
|
56
|
+
block?: string;
|
|
57
|
+
}) => AiRole;
|
|
58
|
+
/** A footer menu: a `menu` setting, usually on a block. */
|
|
59
|
+
footerMenu: (setting: string, opts?: {
|
|
60
|
+
block?: string;
|
|
61
|
+
}) => AiRole;
|
|
62
|
+
/** The footer's brand area (the section or one of its blocks). */
|
|
63
|
+
footerBrand: (opts?: {
|
|
64
|
+
block?: string;
|
|
65
|
+
}) => AiRole;
|
|
66
|
+
/** A product grid: a `collection` or `product` setting, and its heading. */
|
|
67
|
+
productGrid: (setting: string, opts?: {
|
|
68
|
+
heading?: string;
|
|
69
|
+
block?: string;
|
|
70
|
+
}) => AiRole;
|
|
71
|
+
/** A text section: its `heading` and `body` settings. */
|
|
72
|
+
richText: (keys: {
|
|
73
|
+
heading?: string;
|
|
74
|
+
body?: string;
|
|
75
|
+
block?: string;
|
|
76
|
+
}) => AiRole;
|
|
77
|
+
};
|
|
78
|
+
/** `manifest["x-tanqory-ai"]` (draft v0). */
|
|
79
|
+
export interface AiProfile {
|
|
80
|
+
version: 0;
|
|
81
|
+
roles: {
|
|
82
|
+
hero?: {
|
|
83
|
+
component: string;
|
|
84
|
+
block?: string;
|
|
85
|
+
heading: string;
|
|
86
|
+
subheading?: string;
|
|
87
|
+
image?: string;
|
|
88
|
+
button?: string;
|
|
89
|
+
link?: string;
|
|
90
|
+
}[];
|
|
91
|
+
headerMenu?: {
|
|
92
|
+
component: string;
|
|
93
|
+
block?: string;
|
|
94
|
+
setting: string;
|
|
95
|
+
};
|
|
96
|
+
footerMenus?: {
|
|
97
|
+
component: string;
|
|
98
|
+
block?: string;
|
|
99
|
+
setting: string;
|
|
100
|
+
}[];
|
|
101
|
+
footerBrand?: {
|
|
102
|
+
component: string;
|
|
103
|
+
block?: string;
|
|
104
|
+
};
|
|
105
|
+
productGrid?: {
|
|
106
|
+
component: string;
|
|
107
|
+
block?: string;
|
|
108
|
+
setting: string;
|
|
109
|
+
heading?: string;
|
|
110
|
+
}[];
|
|
111
|
+
richText?: {
|
|
112
|
+
component: string;
|
|
113
|
+
block?: string;
|
|
114
|
+
heading?: string;
|
|
115
|
+
body?: string;
|
|
116
|
+
}[];
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** The profile from each section's `ai` roles, or null when no section declares one. */
|
|
120
|
+
export declare function aiProfileOf(sections: readonly {
|
|
121
|
+
id: string;
|
|
122
|
+
ai?: AiRole | readonly AiRole[];
|
|
123
|
+
}[]): AiProfile | null;
|
|
124
|
+
/**
|
|
125
|
+
* Problems with a profile against the manifest's components: every component/block it names must exist, and
|
|
126
|
+
* every setting must exist with a matching type (`menu` for menus, `collection`/`product` for product grids).
|
|
127
|
+
*/
|
|
128
|
+
export declare function checkAiProfile(profile: AiProfile, components: Readonly<Record<string, {
|
|
129
|
+
attributes?: Readonly<Record<string, {
|
|
130
|
+
type?: string;
|
|
131
|
+
}>>;
|
|
132
|
+
}>>): string[];
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI compatibility: which of a theme's own sections and settings play the roles Tanqory AI fills (a hero, the
|
|
3
|
+
* header menu, the footer menus and brand, product grids, text blocks), so AI can compose any theme, not one
|
|
4
|
+
* vocabulary. Declared per section with the `ai.*` helpers; the build prints the profile into the manifest as
|
|
5
|
+
* `x-tanqory-ai` (draft v0).
|
|
6
|
+
*
|
|
7
|
+
* defineSection({ type: 'hero', …, ai: ai.hero({ heading: 'heading', image: 'image', button: 'buttonLabel', link: 'buttonLink' }) })
|
|
8
|
+
* defineSection({ type: 'header', …, ai: ai.headerMenu('menu') })
|
|
9
|
+
* defineSection({ type: 'footer', …, ai: [ai.footerMenu('menu', { block: 'footer-menu' }), ai.footerBrand({ block: 'footer-brand' })] })
|
|
10
|
+
*
|
|
11
|
+
* Pure: no React, no DOM (the build loads it in Node).
|
|
12
|
+
*/
|
|
13
|
+
/** Role declarations for `defineSection({ ai })`. Every key names one of the section's (or its block's) settings. */
|
|
14
|
+
export const ai = {
|
|
15
|
+
/** A hero: `heading` (text), and optionally `subheading`, `image` (image), `button` (text) and `link` (url). */
|
|
16
|
+
hero: (keys) => ({ role: 'hero', ...keys }),
|
|
17
|
+
/** The header's main menu: a `menu` setting. */
|
|
18
|
+
headerMenu: (setting, opts = {}) => ({ role: 'headerMenu', setting, ...opts }),
|
|
19
|
+
/** A footer menu: a `menu` setting, usually on a block. */
|
|
20
|
+
footerMenu: (setting, opts = {}) => ({ role: 'footerMenu', setting, ...opts }),
|
|
21
|
+
/** The footer's brand area (the section or one of its blocks). */
|
|
22
|
+
footerBrand: (opts = {}) => ({ role: 'footerBrand', ...opts }),
|
|
23
|
+
/** A product grid: a `collection` or `product` setting, and its heading. */
|
|
24
|
+
productGrid: (setting, opts = {}) => ({ role: 'productGrid', setting, ...opts }),
|
|
25
|
+
/** A text section: its `heading` and `body` settings. */
|
|
26
|
+
richText: (keys) => ({ role: 'richText', ...keys }),
|
|
27
|
+
};
|
|
28
|
+
/** The profile from each section's `ai` roles, or null when no section declares one. */
|
|
29
|
+
export function aiProfileOf(sections) {
|
|
30
|
+
const roles = {};
|
|
31
|
+
for (const s of sections) {
|
|
32
|
+
for (const r of s.ai ? (Array.isArray(s.ai) ? s.ai : [s.ai]) : []) {
|
|
33
|
+
const { role, ...rest } = r;
|
|
34
|
+
const entry = { component: s.id, ...rest };
|
|
35
|
+
switch (role) {
|
|
36
|
+
case 'hero':
|
|
37
|
+
(roles.hero ??= []).push(entry);
|
|
38
|
+
break;
|
|
39
|
+
case 'headerMenu':
|
|
40
|
+
roles.headerMenu ??= entry;
|
|
41
|
+
break;
|
|
42
|
+
case 'footerMenu':
|
|
43
|
+
(roles.footerMenus ??= []).push(entry);
|
|
44
|
+
break;
|
|
45
|
+
case 'footerBrand':
|
|
46
|
+
roles.footerBrand ??= entry;
|
|
47
|
+
break;
|
|
48
|
+
case 'productGrid':
|
|
49
|
+
(roles.productGrid ??= []).push(entry);
|
|
50
|
+
break;
|
|
51
|
+
case 'richText':
|
|
52
|
+
(roles.richText ??= []).push(entry);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return Object.keys(roles).length ? { version: 0, roles } : null;
|
|
58
|
+
}
|
|
59
|
+
/** Setting types each role key accepts (manifest field types). */
|
|
60
|
+
const ROLE_KEY_TYPES = {
|
|
61
|
+
heading: ['text', 'textarea', 'inline_richtext', 'richtext', 'heading'],
|
|
62
|
+
subheading: ['text', 'textarea', 'inline_richtext', 'richtext'],
|
|
63
|
+
body: ['richtext', 'textarea', 'text', 'inline_richtext'],
|
|
64
|
+
image: ['image'],
|
|
65
|
+
button: ['text'],
|
|
66
|
+
link: ['url', 'link'],
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Problems with a profile against the manifest's components: every component/block it names must exist, and
|
|
70
|
+
* every setting must exist with a matching type (`menu` for menus, `collection`/`product` for product grids).
|
|
71
|
+
*/
|
|
72
|
+
export function checkAiProfile(profile, components) {
|
|
73
|
+
const problems = [];
|
|
74
|
+
for (const [role, value] of Object.entries(profile.roles)) {
|
|
75
|
+
const list = (Array.isArray(value) ? value : [value]);
|
|
76
|
+
list.forEach((target, i) => {
|
|
77
|
+
const at = `x-tanqory-ai.roles.${role}${Array.isArray(value) ? `[${i}]` : ''}`;
|
|
78
|
+
if (!components[target.component])
|
|
79
|
+
return void problems.push(`${at}.component "${target.component}" is not a manifest component`);
|
|
80
|
+
if (target.block && !components[target.block])
|
|
81
|
+
return void problems.push(`${at}.block "${target.block}" is not a manifest component`);
|
|
82
|
+
const owner = target.block ?? target.component;
|
|
83
|
+
const attrs = components[owner]?.attributes ?? {};
|
|
84
|
+
for (const [key, name] of Object.entries(target)) {
|
|
85
|
+
if (key === 'component' || key === 'block')
|
|
86
|
+
continue;
|
|
87
|
+
const want = key === 'setting' ? (role === 'headerMenu' || role === 'footerMenus' ? ['menu'] : ['collection', 'product']) : ROLE_KEY_TYPES[key];
|
|
88
|
+
if (!want)
|
|
89
|
+
continue;
|
|
90
|
+
const a = attrs[name];
|
|
91
|
+
if (!a)
|
|
92
|
+
problems.push(`${at}.${key} "${name}" is not a setting of ${owner}`);
|
|
93
|
+
else if (!want.includes(String(a.type)))
|
|
94
|
+
problems.push(`${at}.${key} "${name}" has type ${a.type}; expected ${want.join('|')}`);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return problems;
|
|
99
|
+
}
|