@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,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
+ }
@@ -0,0 +1,276 @@
1
+ import type { Article, Blog, Cart, CartLine, Collection, Facet, Image, Localization, Menu, Money, Policy, Product, ProductVariant, Shop, SortOption } from '../sdk/types.js';
2
+ import { type AddToCartOptions, type CartLineRefusal } from '../sdk/runtime-context.js';
3
+ /** The theme's global settings: the manifest defaults with the store's saved values over them. */
4
+ export declare function useSettings(): Readonly<Record<string, unknown>>;
5
+ /** The store as the page shows it: name, logo, contact, social links, payment methods, policies, cookie banner. */
6
+ export declare function useShop(): Shop;
7
+ /** A store menu by handle (a `menu` setting's value), with `active` marking the current route; null when absent. */
8
+ export declare function useMenu(handle: string | null | undefined): Menu | null;
9
+ export interface OptionValueState {
10
+ value: string;
11
+ /** This value is part of the selected variant. */
12
+ selected: boolean;
13
+ /** Some variant with this value and the other selected values can be bought. */
14
+ available: boolean;
15
+ /** The variant this value selects, keeping the other selected values when one exists. */
16
+ variantId: string | null;
17
+ }
18
+ export interface ProductState {
19
+ product: Product | null;
20
+ /** The handle exists but the product is unpublished or deleted. */
21
+ unavailable: boolean;
22
+ /** The selected variant (from `?variant=` on the server, else the first available, else the first). */
23
+ variant: ProductVariant | null;
24
+ options: {
25
+ name: string;
26
+ values: OptionValueState[];
27
+ }[];
28
+ selectOption(name: string, value: string): void;
29
+ selectVariant(variantId: string): void;
30
+ price: Money | null;
31
+ compareAtPrice: Money | null;
32
+ onSale: boolean;
33
+ /** The selected variant can be bought. */
34
+ available: boolean;
35
+ /** Units the shopper can still buy, when the store shares inventory (`data:inventory`); null when unknown. */
36
+ quantityAvailable: number | null;
37
+ /** The selected variant's image, else the product's featured image. */
38
+ image: Image | null;
39
+ quantity: number;
40
+ setQuantity(quantity: number): void;
41
+ }
42
+ /** The variant to open on: `wanted` when it belongs to the product, else the first available, else the first. */
43
+ export declare function initialVariant(product: Product | null | undefined, wanted?: string | null): ProductVariant | null;
44
+ /** The option values of `product` around `selected`: each value's availability and the variant it selects. */
45
+ export declare function optionStates(product: Product | null | undefined, selected: ProductVariant | null): ProductState['options'];
46
+ /** The product state `<ProductForm>` shares with the primitives inside it. */
47
+ export declare const ProductContext: import("react").Context<ProductState | null>;
48
+ /**
49
+ * A product and its variant selection. Without an argument: the product of the enclosing `<ProductForm>`, else
50
+ * the route's product (product pages), opened on the `?variant=` the URL names. With a handle: that product (a
51
+ * `product` setting's value). A product object is used as given. Choosing a variant of the route's product keeps
52
+ * `?variant=` in the address bar, so the link shares.
53
+ */
54
+ export declare function useProduct(input?: string | Product | null): ProductState;
55
+ /** The state behind `useProduct` (`inactive`: another instance owns this product; no URL writes). */
56
+ export declare function useProductState(input: string | Product | null | undefined, inactive?: boolean): ProductState;
57
+ /** The collection sorts the data plane answers (`?sort=`), in the order a sort control offers them. */
58
+ export declare const COLLECTION_SORTS: readonly ["featured", "best-selling", "title-asc", "title-desc", "price-asc", "price-desc", "created-desc", "created-asc"];
59
+ export type CollectionSort = (typeof COLLECTION_SORTS)[number];
60
+ export interface CollectionState {
61
+ collection: Collection | null;
62
+ /** The handle exists but the collection is unpublished or deleted. */
63
+ unavailable: boolean;
64
+ /** The products shown now (sorted and filtered as selected). */
65
+ products: Product[];
66
+ /** Products matching the selection when known (the collection's count, unfiltered), else null. */
67
+ total: number | null;
68
+ status: 'ready' | 'loading' | 'error';
69
+ facets: Facet[];
70
+ /** Facet id → the selected value ids. */
71
+ selected: Readonly<Record<string, readonly string[]>>;
72
+ price: {
73
+ from?: number;
74
+ to?: number;
75
+ } | null;
76
+ filtered: boolean;
77
+ toggleFilter(facetId: string, valueId: string): void;
78
+ setPrice(from?: number, to?: number): void;
79
+ clearFilters(): void;
80
+ sort: CollectionSort;
81
+ sortOptions: SortOption[];
82
+ setSort(sort: string): void;
83
+ /** More products exist past the ones shown. */
84
+ hasMore: boolean;
85
+ loadMore(): void;
86
+ /** The page number of a `?page=N` request (1 otherwise) and the URL of any page, for no-JS paging. */
87
+ page: number;
88
+ pageHref(page: number): string;
89
+ }
90
+ /** The collection state `<CollectionProvider>` shares with the primitives inside it. */
91
+ export declare const CollectionContext: import("react").Context<CollectionState | null>;
92
+ /**
93
+ * A collection with its facets, sort and paging. Inside `<CollectionProvider>` (without an argument, or with its
94
+ * handle) every caller shares that provider's state, so a sort control, the filters and the grid agree.
95
+ * Otherwise, without an argument: the route's collection, whose selection
96
+ * lives in the URL (`?sort=`, `?filter.<facet>=`), so a sorted or filtered page shares and reloads. With a
97
+ * handle: that collection (a `collection` setting's value), selection kept in the component.
98
+ *
99
+ * The first render shows what the server rendered (the data plane applies `?sort=` and `?page=`). A change of
100
+ * selection asks the data plane again through the browser wire, sorted and filtered there.
101
+ */
102
+ export declare function useCollection(handle?: string | null): CollectionState;
103
+ /** The state behind `useCollection` (`inactive`: another instance owns this collection; no requests, no URL writes). */
104
+ export declare function useCollectionState(handle?: string | null, inactive?: boolean): CollectionState;
105
+ export declare const SEARCH_SORT_IDS: readonly ["relevance", "price-asc", "price-desc", "title-asc", "created-desc"];
106
+ export interface SearchState {
107
+ /** The query the page was loaded with (`/search?q=`), '' when none. */
108
+ query: string;
109
+ products: Product[];
110
+ articles: Article[];
111
+ pages: {
112
+ title: string;
113
+ url: string;
114
+ excerpt?: string;
115
+ }[];
116
+ /** All matches; null before a query. */
117
+ total: number | null;
118
+ sort: string;
119
+ sortOptions: SortOption[];
120
+ /** The results URL for a query (and sort). */
121
+ href(query: string, sort?: string): string;
122
+ }
123
+ /** The search page's results (`/search?q=…&sort=…`), rendered by the server. */
124
+ export declare function useSearch(): SearchState;
125
+ export interface PredictiveResults {
126
+ products: {
127
+ handle: string;
128
+ title: string;
129
+ url: string;
130
+ price: Money | null;
131
+ image: Image | null;
132
+ }[];
133
+ collections: {
134
+ handle: string;
135
+ title: string;
136
+ url: string;
137
+ }[];
138
+ queries: string[];
139
+ }
140
+ /**
141
+ * Suggestions while the shopper types (`catalog.predictive` over the browser wire; needs `data:search` in the
142
+ * manifest's browser capabilities). Debounced; an answer for an older query never shows under a newer one.
143
+ * On the server, and for an empty query, `results` is null.
144
+ */
145
+ export declare function usePredictiveSearch(query: string, options?: {
146
+ limit?: number;
147
+ debounceMs?: number;
148
+ }): {
149
+ results: PredictiveResults | null;
150
+ loading: boolean;
151
+ };
152
+ export interface CartStateHeadless {
153
+ cart: Cart | null;
154
+ lines: CartLine[];
155
+ itemCount: number;
156
+ subtotal: Money | null;
157
+ total: Money | null;
158
+ /** Where checkout goes (`Cart.checkoutUrl`). Checkout itself is the platform's. */
159
+ checkoutUrl: string;
160
+ /** The shopper's cart is known (an empty cart is known too). */
161
+ ready: boolean;
162
+ /** A request is in flight. */
163
+ loading: boolean;
164
+ /** Why the cart could not be loaded (a wire code), while `ready` is false. */
165
+ loadError: string | null;
166
+ /** The cart drawer is open. */
167
+ isOpen: boolean;
168
+ /** It was opened by an add, not by the shopper. */
169
+ justAdded: boolean;
170
+ open(): void;
171
+ close(): void;
172
+ /**
173
+ * Resolves true when the line is in the cart; never rejects. Opens the cart on success. `options.sellingPlanId` makes it a
174
+ * subscription line; `options.attributes` are the line's custom attributes (a gift card's recipient).
175
+ */
176
+ add(variantId: string, quantity?: number, options?: AddToCartOptions): Promise<boolean>;
177
+ setQuantity(lineId: string, quantity: number): Promise<void>;
178
+ remove(lineId: string): Promise<void>;
179
+ setNote(note: string): Promise<void>;
180
+ isBusy(lineId: string): boolean;
181
+ hasFailed(lineId: string): boolean;
182
+ /** Why the store refused the line's last change, when it said. */
183
+ refusal(lineId: string): CartLineRefusal | null;
184
+ }
185
+ /** The shopper's cart and every cart action (`/_tq/actions/cart.*`, versioned, conflicts retried by the runtime). */
186
+ export declare function useCart(): CartStateHeadless;
187
+ export interface CustomerState {
188
+ /** Whether the shopper has a customer session (never who); null when this page did not read it. */
189
+ signedIn: boolean | null;
190
+ /** The platform's account area for `<AccountSlot>` (customer route only), else null. */
191
+ accountUrl: string | null;
192
+ /** Where an account link goes. */
193
+ accountHref: string;
194
+ }
195
+ /**
196
+ * The shopper's account state. Customer data never reaches theme code: the account area is the platform's
197
+ * iframe (`<AccountSlot>`). `signedIn` is read only when the page asks for it (a `header` section, or
198
+ * `storefront.plan.account`), because the page then varies on it.
199
+ */
200
+ export declare function useCustomer(): CustomerState;
201
+ export interface CountryChoice {
202
+ code: string;
203
+ name: string;
204
+ currencyCode: string;
205
+ currencySymbol: string;
206
+ current: boolean;
207
+ }
208
+ export interface LanguageChoice {
209
+ code: string;
210
+ /** The language's own name (English, ไทย, 日本語). */
211
+ name: string;
212
+ current: boolean;
213
+ }
214
+ export interface LocalizationState {
215
+ localization: Localization | null;
216
+ country: CountryChoice | null;
217
+ language: LanguageChoice;
218
+ /** The store's countries (each with its market currency). Empty unless the page reads the shopper's country. */
219
+ countries: CountryChoice[];
220
+ /** The store's published languages. */
221
+ languages: LanguageChoice[];
222
+ /** Load this page for another country (prices follow its market) or language. */
223
+ changeCountry(code: string): void;
224
+ changeLanguage(code: string): void;
225
+ /** A link to this page in another country and/or language. */
226
+ href(next: {
227
+ country?: string;
228
+ language?: string;
229
+ }): string;
230
+ }
231
+ /**
232
+ * The shopper's market and language, and the switch between them (`?country=`, `?locale=`; the platform
233
+ * remembers both). The country list exists only on a page that reads the shopper's country: a `header`/`footer`
234
+ * section with `showLocale`, or `storefront.plan.localization`.
235
+ */
236
+ export declare function useLocalization(): LocalizationState;
237
+ /**
238
+ * Products recommended with the route's product (`catalog.recommendations`). In the server render when the page
239
+ * asks for them (a `product-recommendations` section, or `storefront.plan.recommendations`); otherwise loaded by
240
+ * the browser after the page shows, which needs `data:products.recommendations` in the browser capabilities.
241
+ */
242
+ export declare function useRecommendations(): {
243
+ products: Product[];
244
+ loading: boolean;
245
+ };
246
+ export interface ConsentState {
247
+ /** The platform says a banner is needed and the shopper has not answered (never on a preview render). */
248
+ required: boolean;
249
+ accept(): void;
250
+ reject(): void;
251
+ decide(choice: {
252
+ analytics: boolean;
253
+ marketing: boolean;
254
+ }): void;
255
+ /** Show the banner again so the shopper can change an earlier answer (a footer "Cookie settings" link). */
256
+ reopen(): void;
257
+ /** The merchant's privacy link, else the published privacy policy, else null. */
258
+ privacyUrl: string | null;
259
+ /** The merchant's own banner wording (Settings › Customer privacy), when typed. */
260
+ text: Partial<Record<'title' | 'body' | 'privacyLinkLabel' | 'acceptLabel' | 'declineLabel', string>>;
261
+ }
262
+ /** The cookie banner's state and the shopper's answer (`/_tq/actions/consent.set`). The platform owns consent. */
263
+ export declare function useConsent(): ConsentState;
264
+ /** The route's content page (`/pages/<handle>`): its title and HTML body; null elsewhere or when the store has none. */
265
+ export declare function usePageContent(): {
266
+ title: string;
267
+ html: string;
268
+ } | null;
269
+ /** A blog with its articles: the route's (`/blogs/<handle>`, and an article's blog), or the one a `blog` setting names. */
270
+ export declare function useBlog(handle?: string | null): Blog | null;
271
+ /** The route's article (`/blogs/<blog>/<handle>`) with its HTML body; null elsewhere. */
272
+ export declare function useArticle(): (Article & {
273
+ contentHtml?: string;
274
+ }) | null;
275
+ /** The route's store policy (`/policies/<handle>`); null elsewhere or when it is not published. */
276
+ export declare function usePolicy(): Policy | null;