@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.17

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.
Files changed (210) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -10
  3. package/dist/abi/canvas-live.d.ts +67 -0
  4. package/dist/abi/canvas-live.js +154 -0
  5. package/dist/abi/cart.d.ts +59 -0
  6. package/dist/abi/cart.js +387 -0
  7. package/dist/abi/convert.d.ts +344 -0
  8. package/dist/abi/convert.js +1278 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +209 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/labels.d.ts +3 -0
  14. package/dist/abi/labels.js +34 -0
  15. package/dist/abi/page-data.d.ts +256 -0
  16. package/dist/abi/page-data.js +678 -0
  17. package/dist/abi/page.d.ts +28 -0
  18. package/dist/abi/page.js +57 -0
  19. package/dist/abi/referrals.d.ts +23 -0
  20. package/dist/abi/referrals.js +89 -0
  21. package/dist/abi/rewards.d.ts +27 -0
  22. package/dist/abi/rewards.js +82 -0
  23. package/dist/abi/seo.d.ts +47 -0
  24. package/dist/abi/seo.js +68 -0
  25. package/dist/abi/shell.d.ts +23 -0
  26. package/dist/abi/shell.js +10 -0
  27. package/dist/abi/state-pack.d.ts +17 -0
  28. package/dist/abi/state-pack.js +43 -0
  29. package/dist/abi/wire.d.ts +38 -0
  30. package/dist/abi/wire.js +84 -0
  31. package/dist/build.d.ts +116 -0
  32. package/dist/build.js +310 -0
  33. package/dist/client.d.ts +19 -0
  34. package/dist/client.js +87 -0
  35. package/dist/contract.d.ts +6 -0
  36. package/dist/contract.js +6 -0
  37. package/dist/headless/ai.d.ts +132 -0
  38. package/dist/headless/ai.js +99 -0
  39. package/dist/headless/hooks.d.ts +276 -0
  40. package/dist/headless/hooks.js +540 -0
  41. package/dist/headless/i18n.d.ts +13 -0
  42. package/dist/headless/i18n.js +45 -0
  43. package/dist/headless/index.d.ts +37 -0
  44. package/dist/headless/index.js +38 -0
  45. package/dist/headless/money.d.ts +25 -0
  46. package/dist/headless/money.js +61 -0
  47. package/dist/headless/page.d.ts +43 -0
  48. package/dist/headless/page.js +53 -0
  49. package/dist/headless/platform.d.ts +55 -0
  50. package/dist/headless/platform.js +77 -0
  51. package/dist/headless/primitives/cart.d.ts +90 -0
  52. package/dist/headless/primitives/cart.js +153 -0
  53. package/dist/headless/primitives/collection.d.ts +68 -0
  54. package/dist/headless/primitives/collection.js +80 -0
  55. package/dist/headless/primitives/product.d.ts +101 -0
  56. package/dist/headless/primitives/product.js +117 -0
  57. package/dist/headless/primitives/storefront.d.ts +106 -0
  58. package/dist/headless/primitives/storefront.js +186 -0
  59. package/dist/headless/primitives/util.d.ts +19 -0
  60. package/dist/headless/primitives/util.js +42 -0
  61. package/dist/headless/strings.d.ts +9 -0
  62. package/dist/headless/strings.js +190 -0
  63. package/dist/headless/structured-data.d.ts +31 -0
  64. package/dist/headless/structured-data.js +57 -0
  65. package/dist/headless/theme.d.ts +99 -0
  66. package/dist/headless/theme.js +54 -0
  67. package/dist/index.d.ts +20 -0
  68. package/dist/index.js +18 -553
  69. package/dist/runtime/data/StoreProvider.d.ts +84 -0
  70. package/dist/runtime/data/StoreProvider.js +373 -0
  71. package/dist/runtime/data/handle.d.ts +14 -0
  72. package/dist/runtime/data/handle.js +16 -0
  73. package/dist/runtime/data/routes.d.ts +87 -0
  74. package/dist/runtime/data/routes.js +158 -0
  75. package/dist/runtime/data/to-ui.d.ts +281 -0
  76. package/dist/runtime/data/to-ui.js +977 -0
  77. package/dist/runtime/entries/register.d.ts +9 -0
  78. package/dist/runtime/entries/register.js +9 -0
  79. package/dist/runtime/entries/sections.d.ts +16 -0
  80. package/dist/runtime/entries/sections.js +19 -0
  81. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  82. package/dist/runtime/kit/SectionTree.js +100 -0
  83. package/dist/runtime/kit/analytics.d.ts +63 -0
  84. package/dist/runtime/kit/analytics.js +250 -0
  85. package/dist/runtime/kit/cart.d.ts +215 -0
  86. package/dist/runtime/kit/cart.js +545 -0
  87. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  88. package/dist/runtime/kit/composition.js +3 -0
  89. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  90. package/dist/runtime/kit/config.js +6 -0
  91. package/dist/runtime/kit/consent.d.ts +29 -0
  92. package/dist/runtime/kit/consent.js +159 -0
  93. package/dist/runtime/kit/contract/content.d.ts +199 -0
  94. package/dist/runtime/kit/contract/content.js +106 -0
  95. package/dist/runtime/kit/contract/field-types.d.ts +337 -0
  96. package/dist/runtime/kit/contract/field-types.js +206 -0
  97. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  98. package/dist/runtime/kit/contract/groups.js +402 -0
  99. package/dist/runtime/kit/contract/index.d.ts +33 -0
  100. package/dist/runtime/kit/contract/index.js +33 -0
  101. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  102. package/dist/runtime/kit/contract/transform.js +133 -0
  103. package/dist/runtime/kit/contract/validate.d.ts +75 -0
  104. package/dist/runtime/kit/contract/validate.js +480 -0
  105. package/dist/runtime/kit/data.d.ts +720 -0
  106. package/dist/runtime/kit/data.js +1117 -0
  107. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  108. package/dist/runtime/kit/defineSection.js +10 -0
  109. package/dist/{types → runtime/kit}/dynamic-source.d.ts +40 -18
  110. package/dist/runtime/kit/dynamic-source.js +294 -0
  111. package/dist/runtime/kit/index.d.ts +24 -0
  112. package/dist/runtime/kit/index.js +24 -0
  113. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  114. package/dist/runtime/kit/jsx-to-json.js +28 -0
  115. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  116. package/dist/runtime/kit/mount.js +124 -0
  117. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  118. package/dist/runtime/kit/registry.js +12 -0
  119. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  120. package/dist/runtime/kit/ssg.js +56 -0
  121. package/dist/runtime/kit/storefront.d.ts +639 -0
  122. package/dist/runtime/kit/storefront.js +723 -0
  123. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  124. package/dist/runtime/kit/theme-context.js +25 -0
  125. package/dist/runtime/kit/types.d.ts +147 -0
  126. package/dist/runtime/kit/types.js +1 -0
  127. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  128. package/dist/runtime/platform/TrackingPixels.js +63 -0
  129. package/dist/runtime/platform/environment.d.ts +68 -0
  130. package/dist/runtime/platform/environment.js +85 -0
  131. package/dist/runtime/platform/locale.d.ts +27 -0
  132. package/dist/runtime/platform/locale.js +42 -0
  133. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  134. package/dist/runtime/platform/route-analytics.js +72 -0
  135. package/dist/runtime/platform/safe-href.d.ts +25 -0
  136. package/dist/runtime/platform/safe-href.js +69 -0
  137. package/dist/runtime/platform/safe-values.d.ts +37 -0
  138. package/dist/runtime/platform/safe-values.js +140 -0
  139. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  140. package/dist/runtime/render/SectionRenderer.js +166 -0
  141. package/dist/runtime/render/listing-query.d.ts +52 -0
  142. package/dist/runtime/render/listing-query.js +122 -0
  143. package/dist/runtime/render/localized-copy.d.ts +86 -0
  144. package/dist/runtime/render/localized-copy.js +129 -0
  145. package/dist/runtime/render/product-listing.d.ts +11 -0
  146. package/dist/runtime/render/product-listing.js +243 -0
  147. package/dist/runtime/render/section-actions.d.ts +66 -0
  148. package/dist/runtime/render/section-actions.js +202 -0
  149. package/dist/runtime/render/starter.d.ts +11 -0
  150. package/dist/runtime/render/starter.js +81 -0
  151. package/dist/runtime/seo/head.d.ts +115 -0
  152. package/dist/runtime/seo/head.js +281 -0
  153. package/dist/runtime/seo/structured-data.d.ts +83 -0
  154. package/dist/runtime/seo/structured-data.js +252 -0
  155. package/dist/runtime/shell/PageShell.d.ts +18 -0
  156. package/dist/runtime/shell/PageShell.js +113 -0
  157. package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
  158. package/dist/runtime/shell/RuntimeBridge.js +93 -0
  159. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  160. package/dist/runtime/shell/overlay-state.js +59 -0
  161. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  162. package/dist/runtime/shell/preview-mode.js +11 -0
  163. package/dist/runtime/shell/spa-router.d.ts +14 -0
  164. package/dist/runtime/shell/spa-router.js +76 -0
  165. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  166. package/dist/runtime/shell/url-redirects.js +37 -0
  167. package/dist/runtime/slots.d.ts +74 -0
  168. package/dist/runtime/slots.js +16 -0
  169. package/dist/runtime.d.ts +34 -0
  170. package/dist/runtime.js +40 -0
  171. package/dist/sdk/app-block.d.ts +29 -0
  172. package/dist/sdk/app-block.js +22 -0
  173. package/dist/sdk/index.d.ts +26 -0
  174. package/dist/sdk/index.js +26 -0
  175. package/dist/sdk/referrals.d.ts +62 -0
  176. package/dist/sdk/referrals.js +20 -0
  177. package/dist/sdk/rewards.d.ts +85 -0
  178. package/dist/sdk/rewards.js +29 -0
  179. package/dist/sdk/runtime-context.d.ts +202 -0
  180. package/dist/sdk/runtime-context.js +73 -0
  181. package/dist/sdk/schema.d.ts +206 -0
  182. package/dist/sdk/schema.js +121 -0
  183. package/dist/sdk/server-render.d.ts +8 -0
  184. package/dist/sdk/server-render.js +12 -0
  185. package/dist/sdk/store-lookup.d.ts +27 -0
  186. package/dist/sdk/store-lookup.js +29 -0
  187. package/dist/sdk/store.d.ts +149 -0
  188. package/dist/sdk/store.js +5 -0
  189. package/dist/sdk/sx.d.ts +40 -0
  190. package/dist/sdk/sx.js +112 -0
  191. package/dist/sdk/theme.d.ts +191 -0
  192. package/dist/sdk/theme.js +10 -0
  193. package/dist/sdk/types.d.ts +757 -0
  194. package/dist/sdk/types.js +7 -0
  195. package/dist/server.d.ts +111 -0
  196. package/dist/server.js +533 -0
  197. package/docs/headless-api.md +220 -0
  198. package/package.json +76 -22
  199. package/dist/index.js.map +0 -1
  200. package/dist/ssg-BZ5FYTw7.js +0 -1802
  201. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  202. package/dist/ssg.js +0 -8
  203. package/dist/ssg.js.map +0 -1
  204. package/dist/types/cart.d.ts +0 -86
  205. package/dist/types/data.d.ts +0 -357
  206. package/dist/types/editor.d.ts +0 -5
  207. package/dist/types/index.d.ts +0 -20
  208. package/dist/types/preview-bridge.d.ts +0 -9
  209. package/dist/types/storefront.d.ts +0 -333
  210. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,113 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The storefront shell: everything a page needs around the theme's sections.
4
+ *
5
+ * theme.Provider the theme's tokens, theme settings, strings (the theme's own component)
6
+ * StoreProvider route context + store data the sections' bindings read
7
+ * RuntimeBridge what the SDK hooks return (cart, overlays, actions, consent)
8
+ * theme.Layout the theme's page layout — sections and page-level overlays
9
+ *
10
+ * The section tree arrives as `children` (mount and the editor's preview bridge
11
+ * both render `<Shell><SectionTree/></Shell>`). With SPA navigation on, a soft
12
+ * navigation away from the landing URL renders the new template's tree instead.
13
+ */
14
+ import { useEffect, useMemo, useRef, useState } from 'react';
15
+ import { SectionTree, groupsFromGlob, resolvePageSections, useData, useSettings } from '../kit/index.js';
16
+ import { applyHead, computeHead } from '../seo/head.js';
17
+ import { emitRoute } from '../platform/route-analytics.js';
18
+ import { matchRoute, resolveAsyncVariant, resolvePageTemplate } from '../data/routes.js';
19
+ import { isEditorPreview } from '../platform/environment.js';
20
+ import { themeLocaleOf } from '../platform/locale.js';
21
+ import { OverlayProvider } from './overlay-state.js';
22
+ import { StoreProvider } from '../data/StoreProvider.js';
23
+ import { TrackingPixels } from '../platform/TrackingPixels.js';
24
+ import { useSoftRoute } from './spa-router.js';
25
+ import { useUrlRedirect } from './url-redirects.js';
26
+ import { RuntimeBridge } from './RuntimeBridge.js';
27
+ import { getEditorRuntime, getThemeBundle } from '../slots.js';
28
+ const same = (s) => s;
29
+ const noop = () => { };
30
+ /** The locales the theme ships strings for (locales/<code>.json). */
31
+ export function themeLocales() {
32
+ return Object.keys(getThemeBundle().locales).map((k) => k.match(/\/([^/]+)\.json$/)?.[1] ?? 'en');
33
+ }
34
+ export default function PageShell({ children }) {
35
+ const bundle = getThemeBundle();
36
+ const { theme } = bundle;
37
+ const editor = getEditorRuntime();
38
+ const preview = isEditorPreview();
39
+ const saved = useSettings();
40
+ // The editor runtime is fixed for the page's lifetime, so the hook called here never changes.
41
+ const useLiveSettings = editor?.useLiveSettings ?? same;
42
+ const usePreviewSelection = editor?.usePreviewSelection ?? noop;
43
+ const settings = useLiveSettings(saved, preview);
44
+ usePreviewSelection(preview);
45
+ const data = useData();
46
+ const locale = themeLocaleOf(settings.locale, themeLocales());
47
+ const { templates, groups } = useMemo(() => ({ templates: bundle.templates, groups: groupsFromGlob(bundle.groups) }), [bundle]);
48
+ const templateExists = (name) => Object.keys(templates).some((k) => k.endsWith(`/${name}.json`));
49
+ const lookupTemplate = (name) => {
50
+ for (const [key, mod] of Object.entries(templates))
51
+ if (key.endsWith(`/${name}.json`))
52
+ return resolvePageSections(mod.default, groups);
53
+ return null;
54
+ };
55
+ // Soft navigation is off in the editor: the preview bridge owns the tree
56
+ // there, and a click should select a section, not navigate away.
57
+ const enableSpa = !preview && settings.enableSpaNavigation !== false;
58
+ const location = useSoftRoute(enableSpa);
59
+ const pathname = location.split('?')[0] || '/';
60
+ // The landing route's template was resolved by the entry (including the
61
+ // merchant's templateSuffix); only a navigation AWAY from it is the shell's.
62
+ const entryPath = useRef(pathname);
63
+ const navigatedAway = enableSpa && pathname !== entryPath.current;
64
+ // A page, blog or article's template variant needs its record (not in the sync
65
+ // bootstrap): until it answers, the new page renders empty rather than as
66
+ // the base template it would then have to swap out.
67
+ const route = matchRoute(pathname);
68
+ const needsRecord = navigatedAway && (route.resource === 'blog' || route.resource === 'article' || route.resource === 'page');
69
+ const [asyncVariant, setAsyncVariant] = useState(null);
70
+ useEffect(() => {
71
+ if (!needsRecord)
72
+ return;
73
+ let live = true;
74
+ void resolveAsyncVariant(route, route.template, data, templateExists).then((template) => {
75
+ if (live)
76
+ setAsyncVariant({ path: pathname, template });
77
+ });
78
+ return () => {
79
+ live = false;
80
+ };
81
+ // eslint-disable-next-line react-hooks/exhaustive-deps
82
+ }, [needsRecord, pathname, data]);
83
+ const softTree = useMemo(() => {
84
+ if (!navigatedAway)
85
+ return null;
86
+ const template = needsRecord ? (asyncVariant?.path === pathname ? asyncVariant.template : null) : resolvePageTemplate(pathname, data, templateExists);
87
+ if (!template)
88
+ return [];
89
+ return lookupTemplate(template) ?? lookupTemplate('404') ?? [];
90
+ // eslint-disable-next-line react-hooks/exhaustive-deps
91
+ }, [navigatedAway, needsRecord, asyncVariant, pathname, data, templates, groups]);
92
+ useUrlRedirect(pathname);
93
+ // While the next page's template is still being resolved, keep the current
94
+ // page on screen — the header, footer and content stay put and are swapped in
95
+ // one step when the next tree is ready, instead of flashing an empty page.
96
+ const pending = navigatedAway && needsRecord && asyncVariant?.path !== pathname;
97
+ const shown = useRef({ location, tree: softTree });
98
+ if (!pending)
99
+ shown.current = { location, tree: softTree };
100
+ const view = shown.current;
101
+ const viewPath = view.location.split('?')[0] || '/';
102
+ const viewSearch = view.location.includes('?') ? `?${view.location.split('?')[1] ?? ''}` : '';
103
+ // The head and the page-view follow what is on screen, so a page's title is
104
+ // applied once its record has loaded, not before.
105
+ useEffect(() => {
106
+ if (!enableSpa || typeof window === 'undefined')
107
+ return;
108
+ applyHead(computeHead(viewPath, data, settings));
109
+ emitRoute({ pathname: viewPath, search: viewSearch }, data);
110
+ }, [enableSpa, viewPath, viewSearch, data, settings]);
111
+ const { Provider, Layout } = theme;
112
+ return (_jsx(Provider, { mode: preview ? 'editor' : 'storefront', locale: locale, settings: settings, children: _jsx(StoreProvider, { location: view.location, locale: locale, settings: settings, children: _jsxs(OverlayProvider, { children: [_jsx(RuntimeBridge, { mode: preview ? 'editor' : 'storefront', locale: locale, settings: settings, children: _jsx(Layout, { children: _jsx("div", { style: { display: 'contents' }, children: view.tree ? _jsx(SectionTree, { tree: view.tree }) : children }, view.tree ? viewPath : 'entry') }) }), _jsx(TrackingPixels, {})] }) }) }));
113
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * What `useThemeContext()` and `useThemeActions()` (theme SDK) return on a
3
+ * page: the platform's cart, overlay, consent and navigation, behind a stable
4
+ * API. One instance per page, so every section and overlay shares the same
5
+ * cart-line status.
6
+ */
7
+ import { type ReactNode } from 'react';
8
+ import { type ThemeMode } from '../../sdk/index.js';
9
+ export declare function RuntimeBridge({ mode, locale, settings, children }: {
10
+ mode: ThemeMode;
11
+ locale: string;
12
+ settings: Record<string, unknown>;
13
+ children: ReactNode;
14
+ }): JSX.Element;
@@ -0,0 +1,93 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * What `useThemeContext()` and `useThemeActions()` (theme SDK) return on a
4
+ * page: the platform's cart, overlay, consent and navigation, behind a stable
5
+ * API. One instance per page, so every section and overlay shares the same
6
+ * cart-line status.
7
+ */
8
+ import { useMemo, useState } from 'react';
9
+ import { ThemeRuntimeContext } from '../../sdk/index.js';
10
+ import { useData } from '../kit/data.js';
11
+ import { useCart } from '../kit/cart.js';
12
+ import { setConsent } from '../kit/consent.js';
13
+ import { useCartActions, navigate, searchHref, changeCountry, changeLocale } from '../render/section-actions.js';
14
+ import { useOverlays } from './overlay-state.js';
15
+ import { useStore } from '../data/StoreProvider.js';
16
+ import * as map from '../data/to-ui.js';
17
+ export function RuntimeBridge({ mode, locale, settings, children }) {
18
+ const cart = useCart();
19
+ const data = useData();
20
+ const store = useStore();
21
+ const overlays = useOverlays();
22
+ const cartActions = useCartActions();
23
+ // The shopper asked to change their cookie choice (footer link): show the banner again.
24
+ const [consentReopened, setConsentReopened] = useState(false);
25
+ const actions = useMemo(() => ({
26
+ cart: {
27
+ add: cartActions.addToCart,
28
+ // Cart-2: what stock let the last add put in the cart, when the platform cut it
29
+ lastAddStock: cartActions.lastAddStock,
30
+ // NEW-PROD-12: `add` carries `options.attributes` to the line (a theme checks this before a recipient form)
31
+ lineAttributes: true,
32
+ setQuantity: cartActions.setQuantity,
33
+ remove: cartActions.removeLine,
34
+ setNote: cartActions.setNote,
35
+ ...(cartActions.applyDiscountCode && cartActions.removeDiscountCode
36
+ ? { applyDiscountCode: cartActions.applyDiscountCode, removeDiscountCode: cartActions.removeDiscountCode }
37
+ : {}),
38
+ ...(cartActions.lastDiscountRefusal ? { lastDiscountRefusal: cartActions.lastDiscountRefusal } : {}),
39
+ ...(cartActions.lastDiscountReplaced ? { lastDiscountReplaced: cartActions.lastDiscountReplaced } : {}),
40
+ open: () => (settings.enableCartDrawer === false ? navigate('/cart') : overlays.show('cart')),
41
+ },
42
+ search: {
43
+ open: () => (settings.enableSearchModal === false ? navigate('/search') : overlays.show('search')),
44
+ go: (q) => navigate(searchHref(q)),
45
+ // The storefront search query (the predictive endpoint asks for fields
46
+ // the storefront does not serve and fails as a whole).
47
+ suggest: async (q) => {
48
+ if (!data.search)
49
+ return { products: [], collections: [], articles: [], total: 0 };
50
+ const r = await data.search(q, { first: 6, types: ['PRODUCT', 'PAGE', 'ARTICLE'] });
51
+ // Search results carry no blog handle, so an article cannot be linked.
52
+ return { products: map.toProducts(r.products), collections: [], articles: [], total: r.totalCount ?? r.products.length };
53
+ },
54
+ },
55
+ localization: { changeCountry, changeLocale },
56
+ consent: {
57
+ decide: (c) => {
58
+ setConsent({ analytics: c.analytics, marketing: c.marketing });
59
+ // Theme ABI v2: the platform records the choice (POST /_tq/actions/consent.set).
60
+ void data.consent?.set({ analytics: c.analytics, marketing: c.marketing, functional: true }).catch(() => { });
61
+ setConsentReopened(false);
62
+ },
63
+ open: () => setConsentReopened(true),
64
+ },
65
+ overlays: { close: overlays.close },
66
+ toasts: { show: (m, tone = 'info') => overlays.toast(m, tone === 'error' ? 'error' : 'default'), dismiss: overlays.dismiss },
67
+ navigate,
68
+ }), [cartActions, data, overlays, settings.enableCartDrawer, settings.enableSearchModal]);
69
+ // The banner's privacy link: the merchant's own link (Settings › Customer privacy), else the privacy
70
+ // policy while it is published — loaded on this page, or listed in `Shop.policyLinks`.
71
+ const shop = store?.ctx.shop;
72
+ const privacyUrl = shop?.consentBanner?.privacyLinkUrl ?? store?.ctx.policies?.['privacy-policy']?.url ?? shop?.policyLinks?.find((p) => p.handle === 'privacy-policy')?.url ?? null;
73
+ const context = useMemo(() => ({
74
+ mode,
75
+ locale,
76
+ settings,
77
+ cart: map.toCart(cart),
78
+ checkoutUrl: cart.checkoutUrl ?? '/checkout',
79
+ overlay: overlays.open,
80
+ justAddedToCart: overlays.justAdded,
81
+ busyLines: [...cartActions.busyLines],
82
+ failedLines: [...cartActions.failedLines],
83
+ refusedLines: Object.fromEntries(cartActions.refusedLines),
84
+ toasts: overlays.toasts.map((t) => ({ id: t.id, message: t.message, tone: t.tone === 'error' ? 'error' : 'info' })),
85
+ consentRequired: Boolean(store?.ctx.consentEnabled && (store.ctx.consentAnswered === false || consentReopened)),
86
+ privacyPolicyUrl: privacyUrl,
87
+ ...(shop ? { shop } : {}),
88
+ ...(store?.ctx.newsletterEndpoint ? { formEndpoint: store.ctx.newsletterEndpoint } : {}),
89
+ ...(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]);
91
+ const value = useMemo(() => ({ context, actions }), [context, actions]);
92
+ return _jsx(ThemeRuntimeContext.Provider, { value: value, children: children });
93
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Page-level overlay state: which surface is open (cart drawer, search modal,
3
+ * account menu) and the toast queue. Sections never own an overlay the page
4
+ * shares — the header asks for the cart, the product form asks for the cart
5
+ * after an add, and both reach the same drawer through this context.
6
+ */
7
+ import { type ReactNode, type RefObject } from 'react';
8
+ export type OverlayName = 'cart' | 'search' | 'account';
9
+ export interface Toast {
10
+ id: string;
11
+ message: string;
12
+ tone?: 'default' | 'error';
13
+ }
14
+ export interface OverlayApi {
15
+ open: OverlayName | null;
16
+ /** The element that opened the account menu (it anchors to it). */
17
+ anchor: RefObject<HTMLElement>;
18
+ show: (name: OverlayName, from?: HTMLElement | null) => void;
19
+ close: () => void;
20
+ /** The cart drawer was opened by an add, not by the shopper. */
21
+ justAdded: boolean;
22
+ toasts: readonly Toast[];
23
+ toast: (message: string, tone?: Toast['tone']) => void;
24
+ dismiss: (id: string) => void;
25
+ }
26
+ export declare function OverlayProvider({ children }: {
27
+ children: ReactNode;
28
+ }): JSX.Element;
29
+ /** Outside a provider (a section preview) every overlay request is a no-op. */
30
+ export declare function useOverlays(): OverlayApi;
31
+ export declare function useOpenCartAfterAdd(): () => void;
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Page-level overlay state: which surface is open (cart drawer, search modal,
4
+ * account menu) and the toast queue. Sections never own an overlay the page
5
+ * shares — the header asks for the cart, the product form asks for the cart
6
+ * after an add, and both reach the same drawer through this context.
7
+ */
8
+ import { createContext, useCallback, useContext, useMemo, useRef, useState } from 'react';
9
+ const OverlayContext = createContext(null);
10
+ let toastSeq = 0;
11
+ export function OverlayProvider({ children }) {
12
+ const [open, setOpen] = useState(null);
13
+ const [justAdded, setJustAdded] = useState(false);
14
+ const [toasts, setToasts] = useState([]);
15
+ const anchor = useRef(null);
16
+ const show = useCallback((name, from) => {
17
+ if (from !== undefined)
18
+ anchor.current = from;
19
+ setJustAdded(false);
20
+ setOpen(name);
21
+ }, []);
22
+ const close = useCallback(() => {
23
+ setOpen(null);
24
+ setJustAdded(false);
25
+ }, []);
26
+ const toast = useCallback((message, tone = 'default') => {
27
+ toastSeq += 1;
28
+ setToasts((ts) => [...ts, { id: `toast-${toastSeq}`, message, tone }]);
29
+ }, []);
30
+ const dismiss = useCallback((id) => setToasts((ts) => ts.filter((t) => t.id !== id)), []);
31
+ const value = useMemo(() => ({ open, anchor: anchor, show, close, justAdded, toasts, toast, dismiss }), [open, show, close, justAdded, toasts, toast, dismiss]);
32
+ return (_jsx(OverlayContext.Provider, { value: value, children: _jsx(JustAddedBridge, { set: setJustAdded, setOpen: setOpen, children: children }) }));
33
+ }
34
+ /** Lets `openCartAfterAdd` flip both flags in one place without widening the public API. */
35
+ const JustAddedContext = createContext(null);
36
+ function JustAddedBridge({ set, setOpen, children }) {
37
+ const openAfterAdd = useCallback(() => {
38
+ setOpen('cart');
39
+ set(true);
40
+ }, [set, setOpen]);
41
+ return _jsx(JustAddedContext.Provider, { value: openAfterAdd, children: children });
42
+ }
43
+ const NOOP = {
44
+ open: null,
45
+ anchor: { current: null },
46
+ show: () => { },
47
+ close: () => { },
48
+ justAdded: false,
49
+ toasts: [],
50
+ toast: () => { },
51
+ dismiss: () => { },
52
+ };
53
+ /** Outside a provider (a section preview) every overlay request is a no-op. */
54
+ export function useOverlays() {
55
+ return useContext(OverlayContext) ?? NOOP;
56
+ }
57
+ export function useOpenCartAfterAdd() {
58
+ return useContext(JustAddedContext) ?? (() => { });
59
+ }
@@ -0,0 +1,2 @@
1
+ export declare const PreviewModeProvider: import("react").Provider<boolean>;
2
+ export declare function usePreviewMode(): boolean;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Is this render a PREVIEW (the editor canvas or a preview channel)? Under Theme ABI v2 that is
3
+ * `ctx.mode === 'preview'`, decided by the platform and handed to the tree by the entries — never
4
+ * read from the URL, so the server render and the hydrating browser agree.
5
+ */
6
+ import { createContext, useContext } from 'react';
7
+ const PreviewModeContext = createContext(false);
8
+ export const PreviewModeProvider = PreviewModeContext.Provider;
9
+ export function usePreviewMode() {
10
+ return useContext(PreviewModeContext);
11
+ }
@@ -0,0 +1,14 @@
1
+ export declare function setServerLocation(location: string): void;
2
+ /**
3
+ * SPA router — intercepts internal `<a>` clicks, pushes the new URL and
4
+ * re-renders, so a navigation swaps templates without a page load.
5
+ *
6
+ * Returns pathname + SEARCH: tracking the pathname alone left `/search?q=shirt`
7
+ * on screen after navigating to `/search?q=hat`.
8
+ *
9
+ * Skips external origins, new-tab / download / modified clicks, links marked
10
+ * `data-full-page-nav="true"`, and `/checkout`, `/account`, `/orders` — those
11
+ * are served by separate apps the edge router forwards to, so they need a real
12
+ * HTTP navigation.
13
+ */
14
+ export declare function useSoftRoute(enabled: boolean): string;
@@ -0,0 +1,76 @@
1
+ import { useEffect, useState } from 'react';
2
+ /**
3
+ * The URL a server render is for. The SSR entry sets it before rendering (one
4
+ * synchronous render per request), so the server draws the same route the
5
+ * browser will hydrate — without it every page rendered as `/` on the server
6
+ * and hydration failed on every other URL.
7
+ */
8
+ let serverLocation = '/';
9
+ export function setServerLocation(location) {
10
+ serverLocation = location || '/';
11
+ }
12
+ /**
13
+ * SPA router — intercepts internal `<a>` clicks, pushes the new URL and
14
+ * re-renders, so a navigation swaps templates without a page load.
15
+ *
16
+ * Returns pathname + SEARCH: tracking the pathname alone left `/search?q=shirt`
17
+ * on screen after navigating to `/search?q=hat`.
18
+ *
19
+ * Skips external origins, new-tab / download / modified clicks, links marked
20
+ * `data-full-page-nav="true"`, and `/checkout`, `/account`, `/orders` — those
21
+ * are served by separate apps the edge router forwards to, so they need a real
22
+ * HTTP navigation.
23
+ */
24
+ export function useSoftRoute(enabled) {
25
+ const here = () => (typeof window !== 'undefined' ? window.location.pathname + window.location.search : serverLocation);
26
+ const [location, setLocation] = useState(here);
27
+ useEffect(() => {
28
+ if (!enabled || typeof window === 'undefined')
29
+ return;
30
+ const go = (next) => {
31
+ if (next !== window.location.pathname + window.location.search)
32
+ window.history.pushState({}, '', next);
33
+ setLocation(window.location.pathname + window.location.search);
34
+ if (!next.includes('#'))
35
+ window.scrollTo({ top: 0, behavior: 'auto' });
36
+ };
37
+ const onClick = (e) => {
38
+ if (e.defaultPrevented || e.button !== 0)
39
+ return;
40
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
41
+ return;
42
+ const a = e.target?.closest?.('a[href]');
43
+ if (!a)
44
+ return;
45
+ if (a.target && a.target !== '_self')
46
+ return;
47
+ if (a.hasAttribute('download'))
48
+ return;
49
+ if (a.dataset.fullPageNav === 'true')
50
+ return;
51
+ let url;
52
+ try {
53
+ url = new URL(a.href, window.location.origin);
54
+ }
55
+ catch {
56
+ return;
57
+ }
58
+ if (url.origin !== window.location.origin)
59
+ return;
60
+ if (url.pathname === window.location.pathname && url.hash)
61
+ return;
62
+ if (/^\/(checkout|account|orders)(\/|$)/.test(url.pathname))
63
+ return;
64
+ e.preventDefault();
65
+ go(url.pathname + url.search + url.hash);
66
+ };
67
+ const onPop = () => setLocation(window.location.pathname + window.location.search);
68
+ document.addEventListener('click', onClick);
69
+ window.addEventListener('popstate', onPop);
70
+ return () => {
71
+ document.removeEventListener('click', onClick);
72
+ window.removeEventListener('popstate', onPop);
73
+ };
74
+ }, [enabled]);
75
+ return location;
76
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The merchant's URL redirects (Settings → Navigation → URL redirects): when the
3
+ * current path matches one, go to its target. Client-side, after render, so a
4
+ * store with no redirects pays one small query and nothing else.
5
+ */
6
+ export declare function useUrlRedirect(pathname?: string): void;
@@ -0,0 +1,37 @@
1
+ import { useEffect } from 'react';
2
+ import { useData } from '../kit/data.js';
3
+ /**
4
+ * The merchant's URL redirects (Settings → Navigation → URL redirects): when the
5
+ * current path matches one, go to its target. Client-side, after render, so a
6
+ * store with no redirects pays one small query and nothing else.
7
+ */
8
+ export function useUrlRedirect(pathname) {
9
+ const { graphql } = useData();
10
+ useEffect(() => {
11
+ if (typeof window === 'undefined' || !graphql)
12
+ return;
13
+ const currentPath = pathname ?? window.location.pathname;
14
+ let cancelled = false;
15
+ // Server-side filter keeps the response small — only exact-path matches
16
+ // matter. The cap of 5 tolerates `query` substring false positives without
17
+ // paying for a full list.
18
+ void graphql(`query R($q: String) {
19
+ urlRedirects(first: 5, query: $q) {
20
+ nodes { path target }
21
+ }
22
+ }`, { q: currentPath })
23
+ .then((res) => {
24
+ if (cancelled)
25
+ return;
26
+ const match = res?.urlRedirects?.nodes.find((n) => n.path === currentPath);
27
+ if (match)
28
+ window.location.replace(match.target);
29
+ })
30
+ .catch(() => {
31
+ /* a failed redirect lookup should never break the page */
32
+ });
33
+ return () => {
34
+ cancelled = true;
35
+ };
36
+ }, [pathname, graphql]);
37
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * What the runtime is handed at boot, instead of importing it:
3
+ *
4
+ * the theme bundle — the theme's definition and content (from .tanqory/, generated by the compiler)
5
+ * the editor runtime — Studio canvas behaviour (@tanqory/theme-editor-runtime), only where it applies
6
+ *
7
+ * One page (or one server render) runs one theme, so a module-level slot is
8
+ * enough; the entry sets both before it renders anything.
9
+ */
10
+ import type { FC, ReactNode } from 'react';
11
+ import type { ThemeDefinition } from '../sdk/index.js';
12
+ import type { ContentNode } from './kit/types.js';
13
+ type GlobMap = Record<string, {
14
+ default: unknown;
15
+ }>;
16
+ export interface ThemeBundle {
17
+ theme: ThemeDefinition;
18
+ /** templates/*.json, groups/*.json, locales/*.json — keyed by their theme path. */
19
+ templates: GlobMap;
20
+ groups: GlobMap;
21
+ locales: GlobMap;
22
+ /** config/settings.json */
23
+ settings: Record<string, unknown>;
24
+ /** config/settings.schema.ts — the theme settings the editor offers. */
25
+ settingsSchema: Record<string, {
26
+ type: string;
27
+ options?: readonly {
28
+ value: string;
29
+ }[];
30
+ min?: number;
31
+ max?: number;
32
+ }>;
33
+ /** Custom sections (sections/*.tsx, `defineSection` from the old API) — registered after the theme's own. */
34
+ customSections: Record<string, {
35
+ default?: unknown;
36
+ }>;
37
+ /** The generated manifest the platform reads (served by the server entry). */
38
+ manifest: unknown;
39
+ }
40
+ export interface EditorRuntime {
41
+ /** This page is the editor canvas (preview plane): the bridge renders the tree. */
42
+ isPreviewPlane(location: {
43
+ hostname: string;
44
+ search: string;
45
+ }): boolean;
46
+ PreviewBridge: FC<{
47
+ pages: Record<string, ContentNode[]>;
48
+ initialPage: string;
49
+ Shell: FC<{
50
+ children: ReactNode;
51
+ }>;
52
+ allowedOrigins?: readonly string[];
53
+ }>;
54
+ Editor?: FC<{
55
+ pages: Record<string, ContentNode[]>;
56
+ initialPage: string;
57
+ }>;
58
+ /** Saved theme settings, plus the editor's unsaved live values on the canvas. */
59
+ useLiveSettings(saved: Record<string, unknown>, onCanvas: boolean): Record<string, unknown>;
60
+ /** The canvas's selection outline. */
61
+ usePreviewSelection(enabled: boolean): void;
62
+ /** The "Add section" preview endpoint (preview plane only); null = not that request. */
63
+ /** `page.data` is the store's live data when a store is attached; absent only offline (no store). */
64
+ sectionPreview?(request: Request, bundle: ThemeBundle, page: {
65
+ styles: string;
66
+ settings: Record<string, unknown>;
67
+ data?: import('./kit/index.js').DataApi;
68
+ }): Response | null;
69
+ }
70
+ export declare function setThemeBundle(b: ThemeBundle): void;
71
+ export declare function getThemeBundle(): ThemeBundle;
72
+ export declare function setEditorRuntime(e: EditorRuntime | null): void;
73
+ export declare function getEditorRuntime(): EditorRuntime | null;
74
+ export {};
@@ -0,0 +1,16 @@
1
+ let bundle = null;
2
+ let editor = null;
3
+ export function setThemeBundle(b) {
4
+ bundle = b;
5
+ }
6
+ export function getThemeBundle() {
7
+ if (!bundle)
8
+ throw new Error('[tanqory] no theme bundle: the entry must call setThemeBundle() before rendering');
9
+ return bundle;
10
+ }
11
+ export function setEditorRuntime(e) {
12
+ editor = e;
13
+ }
14
+ export function getEditorRuntime() {
15
+ return editor;
16
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * `@tanqory/theme-kit/runtime` — the low-level runtime pieces `createRender` and `hydrate` are built
3
+ * from. For a theme's own tests (render a section tree under the real providers) and for custom
4
+ * entries. A theme's components never import this; they use `@tanqory/theme-kit`.
5
+ *
6
+ * Alpha surface: these names may still move between pre-releases.
7
+ */
8
+ export { setThemeBundle, getThemeBundle, type ThemeBundle } from './runtime/slots.js';
9
+ export { sectionModules } from './runtime/entries/sections.js';
10
+ export { registerSections, getSection, allSections } from './runtime/kit/registry.js';
11
+ export { SectionTree } from './runtime/kit/SectionTree.js';
12
+ export type { ContentNode, SectionDef, AttrSpec, SectionProps } from './runtime/kit/types.js';
13
+ export { DataProvider, type DataApi } from './runtime/kit/data.js';
14
+ export { ThemeProvider } from './runtime/kit/theme-context.js';
15
+ export { PreviewModeProvider } from './runtime/shell/preview-mode.js';
16
+ export { localeStrings, themeLocaleOf } from './runtime/platform/locale.js';
17
+ export { AbiShell } from './abi/shell.js';
18
+ export { nodesOf, notFoundTree, locationOf } from './abi/page.js';
19
+ export { loadPageData, pageNeeds, pageParamsOf, variantOf, cartLinkOf, searchQueryOf, searchSortOf, listingQueryOfRequest, localizationOf, marketsOf, type PageData, type NativeFormResult, type NativeFormStatus, type LocaleMarket, } from './abi/page-data.js';
20
+ export { createDataApi, searchKey, searchOrder, SEARCH_SORTS } from './abi/data-api.js';
21
+ export * as convert from './abi/convert.js';
22
+ export { createAbiRemote, AbiWireError, parseRetryAfter, type AbiRemote, type WireEnvelope } from './abi/wire.js';
23
+ export { AbiCartProvider, refusalOf, wireCode, retryDelay } from './abi/cart.js';
24
+ export { AbiRewardsProvider, HOST_OFFERS_LOYALTY, rewardsStateOf } from './abi/rewards.js';
25
+ export { AbiReferralsProvider, keepRefCode, referralStateOf, friendOfferOf, REF_COOKIE, CLAIM_COOKIE } from './abi/referrals.js';
26
+ export { homeHead, heroImageOf, hreflangAlternates, type HomeHead, type HreflangAlternate } from './abi/seo.js';
27
+ export { canonicalize } from './abi/jcs.js';
28
+ export { CANVAS_EVENT, CANVAS_LIVE_EVENT, CANVAS_BRIDGE_EVENT, LIVE_TYPES, blocksOf, applyCanvasMessage, createCanvasStore, connectCanvas, type CanvasStore, } from './abi/canvas-live.js';
29
+ export { computeHead, headFrom, shopNameOf } from './runtime/seo/head.js';
30
+ export { jsonLdTag } from './runtime/seo/structured-data.js';
31
+ export { toLocalization, toShop, toCart, toProduct, consentBannerShows } from './runtime/data/to-ui.js';
32
+ export { localeHref } from './runtime/render/section-actions.js';
33
+ export { listingQueryOf, metafieldBooleanLabelKey, queryOfState, stateFromQuery, withListingQuery } from './runtime/render/listing-query.js';
34
+ export { copyPlanOf, localizeShippedCopy, shippedCopyOf, unknownCopyRefs } from './runtime/render/localized-copy.js';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * `@tanqory/theme-kit/runtime` — the low-level runtime pieces `createRender` and `hydrate` are built
3
+ * from. For a theme's own tests (render a section tree under the real providers) and for custom
4
+ * entries. A theme's components never import this; they use `@tanqory/theme-kit`.
5
+ *
6
+ * Alpha surface: these names may still move between pre-releases.
7
+ */
8
+ // the theme bundle slot + section registration
9
+ export { setThemeBundle, getThemeBundle } from './runtime/slots.js';
10
+ export { sectionModules } from './runtime/entries/sections.js';
11
+ export { registerSections, getSection, allSections } from './runtime/kit/registry.js';
12
+ export { SectionTree } from './runtime/kit/SectionTree.js';
13
+ // providers
14
+ export { DataProvider } from './runtime/kit/data.js';
15
+ export { ThemeProvider } from './runtime/kit/theme-context.js';
16
+ export { PreviewModeProvider } from './runtime/shell/preview-mode.js';
17
+ export { localeStrings, themeLocaleOf } from './runtime/platform/locale.js';
18
+ // the ABI v2 layer: page, data plan, data API, wire, cart, loyalty
19
+ export { AbiShell } from './abi/shell.js';
20
+ export { nodesOf, notFoundTree, locationOf } from './abi/page.js';
21
+ export { loadPageData, pageNeeds, pageParamsOf, variantOf, cartLinkOf, searchQueryOf, searchSortOf, listingQueryOfRequest, localizationOf, marketsOf, } from './abi/page-data.js';
22
+ export { createDataApi, searchKey, searchOrder, SEARCH_SORTS } from './abi/data-api.js';
23
+ export * as convert from './abi/convert.js';
24
+ export { createAbiRemote, AbiWireError, parseRetryAfter } from './abi/wire.js';
25
+ export { AbiCartProvider, refusalOf, wireCode, retryDelay } from './abi/cart.js';
26
+ export { AbiRewardsProvider, HOST_OFFERS_LOYALTY, rewardsStateOf } from './abi/rewards.js';
27
+ export { AbiReferralsProvider, keepRefCode, referralStateOf, friendOfferOf, REF_COOKIE, CLAIM_COOKIE } from './abi/referrals.js';
28
+ export { homeHead, heroImageOf, hreflangAlternates } from './abi/seo.js';
29
+ export { canonicalize } from './abi/jcs.js';
30
+ // live edit on the editor canvas
31
+ export { CANVAS_EVENT, CANVAS_LIVE_EVENT, CANVAS_BRIDGE_EVENT, LIVE_TYPES, blocksOf, applyCanvasMessage, createCanvasStore, connectCanvas, } from './abi/canvas-live.js';
32
+ // SEO
33
+ export { computeHead, headFrom, shopNameOf } from './runtime/seo/head.js';
34
+ export { jsonLdTag } from './runtime/seo/structured-data.js';
35
+ // store data → the shapes components read
36
+ export { toLocalization, toShop, toCart, toProduct, consentBannerShows } from './runtime/data/to-ui.js';
37
+ // render helpers
38
+ export { localeHref } from './runtime/render/section-actions.js';
39
+ export { listingQueryOf, metafieldBooleanLabelKey, queryOfState, stateFromQuery, withListingQuery } from './runtime/render/listing-query.js';
40
+ export { copyPlanOf, localizeShippedCopy, shippedCopyOf, unknownCopyRefs } from './runtime/render/localized-copy.js';