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

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 (204) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -10
  3. package/dist/abi/canvas-live.d.ts +49 -0
  4. package/dist/abi/canvas-live.js +88 -0
  5. package/dist/abi/cart.d.ts +48 -0
  6. package/dist/abi/cart.js +321 -0
  7. package/dist/abi/convert.d.ts +192 -0
  8. package/dist/abi/convert.js +670 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +198 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/page-data.d.ts +209 -0
  14. package/dist/abi/page-data.js +583 -0
  15. package/dist/abi/page.d.ts +23 -0
  16. package/dist/abi/page.js +46 -0
  17. package/dist/abi/referrals.d.ts +23 -0
  18. package/dist/abi/referrals.js +89 -0
  19. package/dist/abi/rewards.d.ts +27 -0
  20. package/dist/abi/rewards.js +82 -0
  21. package/dist/abi/seo.d.ts +47 -0
  22. package/dist/abi/seo.js +68 -0
  23. package/dist/abi/shell.d.ts +22 -0
  24. package/dist/abi/shell.js +10 -0
  25. package/dist/abi/wire.d.ts +38 -0
  26. package/dist/abi/wire.js +84 -0
  27. package/dist/build.d.ts +113 -0
  28. package/dist/build.js +294 -0
  29. package/dist/client.d.ts +19 -0
  30. package/dist/client.js +76 -0
  31. package/dist/contract.d.ts +6 -0
  32. package/dist/contract.js +6 -0
  33. package/dist/headless/ai.d.ts +132 -0
  34. package/dist/headless/ai.js +99 -0
  35. package/dist/headless/hooks.d.ts +273 -0
  36. package/dist/headless/hooks.js +533 -0
  37. package/dist/headless/i18n.d.ts +13 -0
  38. package/dist/headless/i18n.js +45 -0
  39. package/dist/headless/index.d.ts +36 -0
  40. package/dist/headless/index.js +38 -0
  41. package/dist/headless/money.d.ts +25 -0
  42. package/dist/headless/money.js +61 -0
  43. package/dist/headless/page.d.ts +43 -0
  44. package/dist/headless/page.js +53 -0
  45. package/dist/headless/platform.d.ts +55 -0
  46. package/dist/headless/platform.js +77 -0
  47. package/dist/headless/primitives/cart.d.ts +90 -0
  48. package/dist/headless/primitives/cart.js +153 -0
  49. package/dist/headless/primitives/collection.d.ts +68 -0
  50. package/dist/headless/primitives/collection.js +80 -0
  51. package/dist/headless/primitives/product.d.ts +101 -0
  52. package/dist/headless/primitives/product.js +117 -0
  53. package/dist/headless/primitives/storefront.d.ts +106 -0
  54. package/dist/headless/primitives/storefront.js +186 -0
  55. package/dist/headless/primitives/util.d.ts +19 -0
  56. package/dist/headless/primitives/util.js +42 -0
  57. package/dist/headless/strings.d.ts +9 -0
  58. package/dist/headless/strings.js +186 -0
  59. package/dist/headless/structured-data.d.ts +31 -0
  60. package/dist/headless/structured-data.js +57 -0
  61. package/dist/headless/theme.d.ts +99 -0
  62. package/dist/headless/theme.js +54 -0
  63. package/dist/index.d.ts +20 -0
  64. package/dist/index.js +18 -553
  65. package/dist/runtime/data/StoreProvider.d.ts +56 -0
  66. package/dist/runtime/data/StoreProvider.js +308 -0
  67. package/dist/runtime/data/handle.d.ts +14 -0
  68. package/dist/runtime/data/handle.js +16 -0
  69. package/dist/runtime/data/routes.d.ts +87 -0
  70. package/dist/runtime/data/routes.js +154 -0
  71. package/dist/runtime/data/to-ui.d.ts +258 -0
  72. package/dist/runtime/data/to-ui.js +820 -0
  73. package/dist/runtime/entries/register.d.ts +9 -0
  74. package/dist/runtime/entries/register.js +9 -0
  75. package/dist/runtime/entries/sections.d.ts +16 -0
  76. package/dist/runtime/entries/sections.js +19 -0
  77. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  78. package/dist/runtime/kit/SectionTree.js +100 -0
  79. package/dist/runtime/kit/analytics.d.ts +63 -0
  80. package/dist/runtime/kit/analytics.js +233 -0
  81. package/dist/runtime/kit/cart.d.ts +186 -0
  82. package/dist/runtime/kit/cart.js +545 -0
  83. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  84. package/dist/runtime/kit/composition.js +3 -0
  85. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  86. package/dist/runtime/kit/config.js +6 -0
  87. package/dist/runtime/kit/consent.d.ts +29 -0
  88. package/dist/runtime/kit/consent.js +159 -0
  89. package/dist/runtime/kit/contract/content.d.ts +164 -0
  90. package/dist/runtime/kit/contract/content.js +83 -0
  91. package/dist/runtime/kit/contract/field-types.d.ts +290 -0
  92. package/dist/runtime/kit/contract/field-types.js +129 -0
  93. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  94. package/dist/runtime/kit/contract/groups.js +402 -0
  95. package/dist/runtime/kit/contract/index.d.ts +33 -0
  96. package/dist/runtime/kit/contract/index.js +33 -0
  97. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  98. package/dist/runtime/kit/contract/transform.js +133 -0
  99. package/dist/runtime/kit/contract/validate.d.ts +67 -0
  100. package/dist/runtime/kit/contract/validate.js +388 -0
  101. package/dist/runtime/kit/data.d.ts +636 -0
  102. package/dist/runtime/kit/data.js +1117 -0
  103. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  104. package/dist/runtime/kit/defineSection.js +10 -0
  105. package/dist/{types → runtime/kit}/dynamic-source.d.ts +4 -4
  106. package/dist/runtime/kit/dynamic-source.js +143 -0
  107. package/dist/runtime/kit/index.d.ts +24 -0
  108. package/dist/runtime/kit/index.js +24 -0
  109. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  110. package/dist/runtime/kit/jsx-to-json.js +28 -0
  111. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  112. package/dist/runtime/kit/mount.js +124 -0
  113. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  114. package/dist/runtime/kit/registry.js +12 -0
  115. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  116. package/dist/runtime/kit/ssg.js +56 -0
  117. package/dist/runtime/kit/storefront.d.ts +566 -0
  118. package/dist/runtime/kit/storefront.js +723 -0
  119. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  120. package/dist/runtime/kit/theme-context.js +25 -0
  121. package/dist/runtime/kit/types.d.ts +142 -0
  122. package/dist/runtime/kit/types.js +1 -0
  123. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  124. package/dist/runtime/platform/TrackingPixels.js +63 -0
  125. package/dist/runtime/platform/environment.d.ts +68 -0
  126. package/dist/runtime/platform/environment.js +85 -0
  127. package/dist/runtime/platform/locale.d.ts +27 -0
  128. package/dist/runtime/platform/locale.js +42 -0
  129. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  130. package/dist/runtime/platform/route-analytics.js +72 -0
  131. package/dist/runtime/platform/safe-href.d.ts +25 -0
  132. package/dist/runtime/platform/safe-href.js +69 -0
  133. package/dist/runtime/platform/safe-values.d.ts +37 -0
  134. package/dist/runtime/platform/safe-values.js +140 -0
  135. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  136. package/dist/runtime/render/SectionRenderer.js +111 -0
  137. package/dist/runtime/render/listing-query.d.ts +47 -0
  138. package/dist/runtime/render/listing-query.js +114 -0
  139. package/dist/runtime/render/localized-copy.d.ts +86 -0
  140. package/dist/runtime/render/localized-copy.js +129 -0
  141. package/dist/runtime/render/product-listing.d.ts +11 -0
  142. package/dist/runtime/render/product-listing.js +240 -0
  143. package/dist/runtime/render/section-actions.d.ts +48 -0
  144. package/dist/runtime/render/section-actions.js +170 -0
  145. package/dist/runtime/render/starter.d.ts +11 -0
  146. package/dist/runtime/render/starter.js +81 -0
  147. package/dist/runtime/seo/head.d.ts +87 -0
  148. package/dist/runtime/seo/head.js +224 -0
  149. package/dist/runtime/seo/structured-data.d.ts +22 -0
  150. package/dist/runtime/seo/structured-data.js +115 -0
  151. package/dist/runtime/shell/PageShell.d.ts +18 -0
  152. package/dist/runtime/shell/PageShell.js +113 -0
  153. package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
  154. package/dist/runtime/shell/RuntimeBridge.js +85 -0
  155. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  156. package/dist/runtime/shell/overlay-state.js +59 -0
  157. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  158. package/dist/runtime/shell/preview-mode.js +11 -0
  159. package/dist/runtime/shell/spa-router.d.ts +14 -0
  160. package/dist/runtime/shell/spa-router.js +76 -0
  161. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  162. package/dist/runtime/shell/url-redirects.js +37 -0
  163. package/dist/runtime/slots.d.ts +74 -0
  164. package/dist/runtime/slots.js +16 -0
  165. package/dist/runtime.d.ts +34 -0
  166. package/dist/runtime.js +40 -0
  167. package/dist/sdk/index.d.ts +24 -0
  168. package/dist/sdk/index.js +24 -0
  169. package/dist/sdk/referrals.d.ts +62 -0
  170. package/dist/sdk/referrals.js +20 -0
  171. package/dist/sdk/rewards.d.ts +85 -0
  172. package/dist/sdk/rewards.js +29 -0
  173. package/dist/sdk/runtime-context.d.ts +135 -0
  174. package/dist/sdk/runtime-context.js +73 -0
  175. package/dist/sdk/schema.d.ts +197 -0
  176. package/dist/sdk/schema.js +121 -0
  177. package/dist/sdk/server-render.d.ts +8 -0
  178. package/dist/sdk/server-render.js +12 -0
  179. package/dist/sdk/store-lookup.d.ts +27 -0
  180. package/dist/sdk/store-lookup.js +29 -0
  181. package/dist/sdk/store.d.ts +115 -0
  182. package/dist/sdk/store.js +1 -0
  183. package/dist/sdk/sx.d.ts +40 -0
  184. package/dist/sdk/sx.js +112 -0
  185. package/dist/sdk/theme.d.ts +152 -0
  186. package/dist/sdk/theme.js +10 -0
  187. package/dist/sdk/types.d.ts +470 -0
  188. package/dist/sdk/types.js +7 -0
  189. package/dist/server.d.ts +65 -0
  190. package/dist/server.js +370 -0
  191. package/docs/headless-api.md +220 -0
  192. package/package.json +77 -23
  193. package/dist/index.js.map +0 -1
  194. package/dist/ssg-BZ5FYTw7.js +0 -1802
  195. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  196. package/dist/ssg.js +0 -8
  197. package/dist/ssg.js.map +0 -1
  198. package/dist/types/cart.d.ts +0 -86
  199. package/dist/types/data.d.ts +0 -357
  200. package/dist/types/editor.d.ts +0 -5
  201. package/dist/types/index.d.ts +0 -20
  202. package/dist/types/preview-bridge.d.ts +0 -9
  203. package/dist/types/storefront.d.ts +0 -333
  204. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Collection primitives. Wrap a collection page in `<CollectionProvider>` so the sort control, the filters, the
3
+ * product grid and the paging share one `useCollection()` state.
4
+ *
5
+ * <CollectionProvider> the route's collection (or `handle`)
6
+ * <SortSelect /> <form><select name="sort" data-tq-sort>
7
+ * <FacetFilters /> <div data-tq-filter>: fieldset/legend + a checkbox per value, price from/to
8
+ * {grid from useCollection().products}
9
+ * <Pagination /> <nav data-tq-pagination>: "Load more" (a ?page=N link without JavaScript)
10
+ * </CollectionProvider>
11
+ */
12
+ import { type ReactNode } from 'react';
13
+ import type { SortOption } from '../../sdk/types.js';
14
+ import { type CollectionState } from '../hooks.js';
15
+ import { type RenderChildren } from './util.js';
16
+ export interface CollectionProviderProps {
17
+ /** A collection handle (a `collection` setting); the route's collection when absent. */
18
+ handle?: string | null;
19
+ children?: RenderChildren<CollectionState>;
20
+ }
21
+ /** One collection state for everything inside it (`useCollection()` there returns it). */
22
+ export declare function CollectionProvider({ handle, children }: CollectionProviderProps): JSX.Element;
23
+ export interface SortSelectProps {
24
+ className?: string;
25
+ /** On the `<label>`; omit to keep the label for screen readers only. */
26
+ labelClassName?: string;
27
+ label?: 'visible' | 'hidden';
28
+ /** Another sort state (the search page's); the enclosing collection's by default. */
29
+ state?: {
30
+ sort: string;
31
+ sortOptions: readonly SortOption[];
32
+ setSort(id: string): void;
33
+ };
34
+ }
35
+ /**
36
+ * The sort `<select name="sort" data-tq-sort>` in a GET form. With JavaScript a choice re-sorts in place
37
+ * (and keeps `?sort=` in the URL); without it, submitting the form loads the sorted page.
38
+ */
39
+ export declare function SortSelect({ className, labelClassName, label, state }: SortSelectProps): JSX.Element | null;
40
+ export interface FacetFiltersProps {
41
+ className?: string;
42
+ /** On each facet's `<fieldset>`. */
43
+ facetClassName?: string;
44
+ legendClassName?: string;
45
+ /** On each value's `<label>` (it carries `data-active`). */
46
+ valueClassName?: string;
47
+ /** On the "Clear filters" button. */
48
+ clearClassName?: string;
49
+ /** Show each value's product count (default true). */
50
+ counts?: boolean;
51
+ /** Full control: the facets and the actions. */
52
+ children?: (state: Pick<CollectionState, 'facets' | 'toggleFilter' | 'setPrice' | 'clearFilters' | 'filtered' | 'price'>) => ReactNode;
53
+ }
54
+ /** The collection's facets (`data-tq-filter`): a checkbox per value, a from/to pair for price, and "Clear filters". */
55
+ export declare function FacetFilters({ className, facetClassName, legendClassName, valueClassName, clearClassName, counts, children }: FacetFiltersProps): JSX.Element | null;
56
+ export interface PaginationProps {
57
+ className?: string;
58
+ /** On the "Load more" / next control. */
59
+ nextClassName?: string;
60
+ /** On the "Previous page" link of a `?page=N` page. */
61
+ previousClassName?: string;
62
+ children?: (state: Pick<CollectionState, 'hasMore' | 'loadMore' | 'page' | 'pageHref' | 'status'>) => ReactNode;
63
+ }
64
+ /**
65
+ * Paging for the collection (`<nav data-tq-pagination>`): a "Load more" link that appends the next products in
66
+ * place, and is a real `?page=N` link (`rel="next"`) for a browser without JavaScript.
67
+ */
68
+ export declare function Pagination({ className, nextClassName, previousClassName, children }: PaginationProps): JSX.Element | null;
@@ -0,0 +1,80 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Collection primitives. Wrap a collection page in `<CollectionProvider>` so the sort control, the filters, the
4
+ * product grid and the paging share one `useCollection()` state.
5
+ *
6
+ * <CollectionProvider> the route's collection (or `handle`)
7
+ * <SortSelect /> <form><select name="sort" data-tq-sort>
8
+ * <FacetFilters /> <div data-tq-filter>: fieldset/legend + a checkbox per value, price from/to
9
+ * {grid from useCollection().products}
10
+ * <Pagination /> <nav data-tq-pagination>: "Load more" (a ?page=N link without JavaScript)
11
+ * </CollectionProvider>
12
+ */
13
+ import { useId, useState } from 'react';
14
+ import { CollectionContext, useCollection, useCollectionState } from '../hooks.js';
15
+ import { useTranslate } from '../i18n.js';
16
+ import { cn, renderChildren, visuallyHidden } from './util.js';
17
+ /** One collection state for everything inside it (`useCollection()` there returns it). */
18
+ export function CollectionProvider({ handle, children }) {
19
+ const state = useCollectionState(handle);
20
+ return _jsx(CollectionContext.Provider, { value: state, children: renderChildren(children, state, () => null) });
21
+ }
22
+ /**
23
+ * The sort `<select name="sort" data-tq-sort>` in a GET form. With JavaScript a choice re-sorts in place
24
+ * (and keeps `?sort=` in the URL); without it, submitting the form loads the sorted page.
25
+ */
26
+ export function SortSelect({ className, labelClassName, label = 'visible', state }) {
27
+ const collection = useCollection();
28
+ const t = useTranslate();
29
+ const id = useId();
30
+ const s = state ?? collection;
31
+ if (!s.sortOptions.length)
32
+ return null;
33
+ return (_jsxs("form", { method: "get", className: className, onSubmit: (e) => e.preventDefault(), children: [_jsx("label", { htmlFor: id, className: label === 'visible' ? labelClassName : cn(visuallyHidden(), labelClassName), children: t('collection.sort') }), _jsx("select", { id: id, name: "sort", "data-tq-sort": "", value: s.sort, onChange: (e) => s.setSort(e.target.value), children: s.sortOptions.map((o) => (_jsx("option", { value: o.id, children: o.label }, o.id))) })] }));
34
+ }
35
+ /** The collection's facets (`data-tq-filter`): a checkbox per value, a from/to pair for price, and "Clear filters". */
36
+ export function FacetFilters({ className, facetClassName, legendClassName, valueClassName, clearClassName, counts = true, children }) {
37
+ const c = useCollection();
38
+ const t = useTranslate();
39
+ if (children)
40
+ return _jsx("div", { className: className, "data-tq-filter": "", children: children(c) });
41
+ if (!c.facets.length)
42
+ return null;
43
+ return (_jsxs("div", { className: className, "data-tq-filter": "", children: [c.facets.map((f) => f.type === 'price' ? (_jsx(PriceFacet, { facet: f, state: c, className: facetClassName, legendClassName: legendClassName }, f.id)) : (_jsxs("fieldset", { className: facetClassName, children: [_jsx("legend", { className: legendClassName, children: f.label }), (f.values ?? []).map((v) => (_jsxs("label", { className: valueClassName, "data-active": v.active ? 'true' : 'false', children: [_jsx("input", { type: "checkbox", name: f.id, value: v.id, checked: v.active, onChange: () => c.toggleFilter(f.id, v.id) }), _jsx("span", { children: v.label }), counts ? _jsxs("span", { children: [" (", v.count, ")"] }) : null] }, v.id)))] }, f.id))), c.filtered ? (_jsx("button", { type: "button", className: clearClassName, onClick: c.clearFilters, children: t('collection.clearFilters') })) : null] }));
44
+ }
45
+ function PriceFacet({ facet, state, className, legendClassName }) {
46
+ const t = useTranslate();
47
+ const id = useId();
48
+ const range = facet.range;
49
+ const [from, setFrom] = useState(range?.from != null ? String(range.from) : '');
50
+ const [to, setTo] = useState(range?.to != null ? String(range.to) : '');
51
+ if (!range)
52
+ return null;
53
+ const num = (v) => (v.trim() === '' || !Number.isFinite(Number(v)) ? undefined : Number(v));
54
+ const commit = () => state.setPrice(num(from), num(to));
55
+ return (_jsxs("fieldset", { className: className, children: [_jsx("legend", { className: legendClassName, children: facet.label }), _jsx("label", { htmlFor: `${id}-from`, children: t('collection.priceFrom') }), _jsx("input", { id: `${id}-from`, type: "number", inputMode: "decimal", min: range.min, max: range.max, placeholder: String(range.min), value: from, onChange: (e) => setFrom(e.target.value), onBlur: commit, onKeyDown: (e) => { if (e.key === 'Enter') {
56
+ e.preventDefault();
57
+ commit();
58
+ } } }), _jsx("label", { htmlFor: `${id}-to`, children: t('collection.priceTo') }), _jsx("input", { id: `${id}-to`, type: "number", inputMode: "decimal", min: range.min, max: range.max, placeholder: String(range.max), value: to, onChange: (e) => setTo(e.target.value), onBlur: commit, onKeyDown: (e) => { if (e.key === 'Enter') {
59
+ e.preventDefault();
60
+ commit();
61
+ } } }), _jsx("span", { className: visuallyHidden(), children: range.currencyCode })] }));
62
+ }
63
+ /**
64
+ * Paging for the collection (`<nav data-tq-pagination>`): a "Load more" link that appends the next products in
65
+ * place, and is a real `?page=N` link (`rel="next"`) for a browser without JavaScript.
66
+ */
67
+ export function Pagination({ className, nextClassName, previousClassName, children }) {
68
+ const c = useCollection();
69
+ const t = useTranslate();
70
+ if (children)
71
+ return _jsx("nav", { className: className, "data-tq-pagination": "", "aria-label": t('collection.pagination'), children: children(c) });
72
+ if (!c.hasMore && c.page <= 1)
73
+ return null;
74
+ return (_jsxs("nav", { className: className, "data-tq-pagination": "", "aria-label": t('collection.pagination'), children: [c.page > 1 ? (_jsx("a", { className: previousClassName, href: c.pageHref(c.page - 1), rel: "prev", children: t('collection.previous') })) : null, c.hasMore ? (_jsx("a", { className: nextClassName, href: c.pageHref(c.page + 1), rel: "next", "aria-busy": c.status === 'loading' || undefined, onClick: (e) => {
75
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0)
76
+ return;
77
+ e.preventDefault();
78
+ c.loadMore();
79
+ }, children: c.status === 'loading' ? t('collection.loading') : t('collection.loadMore') })) : null] }));
80
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Product primitives: a form that adds the selected variant, its option picker, the price, the quantity and the
3
+ * add button. Semantic HTML, no styling; every element takes `className`, and `children` may be a function of the
4
+ * product state for full control of the markup.
5
+ *
6
+ * <ProductForm> <form data-tq-product-form> (shares one useProduct() state)
7
+ * <VariantPicker /> <div data-tq-variant-picker> fieldset/legend + radio per value
8
+ * <ProductPrice /> <span data-tq-price>
9
+ * <ProductQuantity /> <input type="number">
10
+ * <AddToCart /> <button type="submit" data-tq-action="cart:add">, disabled when sold out
11
+ * </ProductForm>
12
+ */
13
+ import { type ButtonHTMLAttributes, type ReactNode } from 'react';
14
+ import type { Product } from '../../sdk/types.js';
15
+ import { type OptionValueState, type ProductState } from '../hooks.js';
16
+ import { type RenderChildren } from './util.js';
17
+ /** What `<ProductForm>` shares: the product state, plus whether an add is in flight. */
18
+ export interface ProductFormState extends ProductState {
19
+ adding: boolean;
20
+ /** Add the selected variant (the form's submit does this). Resolves true when it is in the cart. */
21
+ addToCart(): Promise<boolean>;
22
+ }
23
+ /** The enclosing `<ProductForm>`'s state, or null outside one. */
24
+ export declare function useProductForm(): ProductFormState | null;
25
+ export interface ProductFormProps {
26
+ /** A product, or a product handle; the route's product when absent. */
27
+ product?: Product | string | null;
28
+ className?: string;
29
+ /** Runs after the selected variant was added. */
30
+ onAdded?(state: ProductFormState): void;
31
+ children?: RenderChildren<ProductFormState>;
32
+ }
33
+ /**
34
+ * A `<form>` around a product's purchase controls. Submitting it adds the selected variant and quantity
35
+ * (`cart.create` / `cart.addLines`), which opens the cart. A sold-out variant is never sent.
36
+ */
37
+ export declare function ProductForm({ product, className, onAdded, children }: ProductFormProps): JSX.Element;
38
+ export interface VariantPickerProps {
39
+ className?: string;
40
+ /** On each option's `<fieldset>`. */
41
+ optionClassName?: string;
42
+ /** On each value's `<label>` (it carries `data-selected` and `data-available`). */
43
+ valueClassName?: string;
44
+ /** On each option's `<legend>`. */
45
+ legendClassName?: string;
46
+ /** What a value's label shows (a swatch, the value plus a note); the value text by default. */
47
+ renderValue?(value: OptionValueState, option: {
48
+ name: string;
49
+ }): ReactNode;
50
+ /** Full control: the options and the selection function. */
51
+ children?: (state: {
52
+ options: ProductState['options'];
53
+ selectOption: ProductState['selectOption'];
54
+ }) => ReactNode;
55
+ }
56
+ /**
57
+ * The option values of the product as radio groups (one `<fieldset>` per option, a `<label>`led radio per value).
58
+ * Choosing a value selects the matching variant; the price, image and add button follow. A product with a
59
+ * single default variant renders nothing.
60
+ */
61
+ export declare function VariantPicker({ className, optionClassName, valueClassName, legendClassName, renderValue, children }: VariantPickerProps): JSX.Element | null;
62
+ export interface ProductPriceProps {
63
+ className?: string;
64
+ /** On the struck-through regular price of a sale. */
65
+ compareClassName?: string;
66
+ /** A product state to read instead of the enclosing form's. */
67
+ state?: Pick<ProductState, 'price' | 'compareAtPrice' | 'onSale'>;
68
+ children?: (state: {
69
+ price: string;
70
+ compareAtPrice: string | null;
71
+ onSale: boolean;
72
+ }) => ReactNode;
73
+ }
74
+ /** The selected variant's price (`data-tq-price`), and the regular price struck through on a sale. */
75
+ export declare function ProductPrice({ className, compareClassName, state, children }: ProductPriceProps): JSX.Element | null;
76
+ export interface ProductQuantityProps {
77
+ className?: string;
78
+ /** On the visible label; omit `label` to keep it for screen readers only. */
79
+ labelClassName?: string;
80
+ label?: 'visible' | 'hidden';
81
+ max?: number;
82
+ }
83
+ /** The quantity to add (a number input, at least 1). */
84
+ export declare function ProductQuantity({ className, labelClassName, label, max }: ProductQuantityProps): JSX.Element | null;
85
+ export interface AddToCartProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'type'> {
86
+ /** Outside a `<ProductForm>`: the variant this button adds. */
87
+ variantId?: string;
88
+ /** Outside a `<ProductForm>`: whether that variant can be bought (default true). */
89
+ available?: boolean;
90
+ quantity?: number;
91
+ children?: (state: {
92
+ available: boolean;
93
+ adding: boolean;
94
+ label: string;
95
+ }) => ReactNode;
96
+ }
97
+ /**
98
+ * The add-to-cart `<button>` (`data-tq-action="cart:add"`). In a `<ProductForm>` it submits the form; it is
99
+ * disabled, and says "Sold out", when the selected variant cannot be bought.
100
+ */
101
+ export declare function AddToCart({ variantId, available: availableProp, quantity, children, className, disabled, ...rest }: AddToCartProps): JSX.Element;
@@ -0,0 +1,117 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * Product primitives: a form that adds the selected variant, its option picker, the price, the quantity and the
4
+ * add button. Semantic HTML, no styling; every element takes `className`, and `children` may be a function of the
5
+ * product state for full control of the markup.
6
+ *
7
+ * <ProductForm> <form data-tq-product-form> (shares one useProduct() state)
8
+ * <VariantPicker /> <div data-tq-variant-picker> fieldset/legend + radio per value
9
+ * <ProductPrice /> <span data-tq-price>
10
+ * <ProductQuantity /> <input type="number">
11
+ * <AddToCart /> <button type="submit" data-tq-action="cart:add">, disabled when sold out
12
+ * </ProductForm>
13
+ */
14
+ import { useCallback, useContext, useId, useState } from 'react';
15
+ import { ProductContext, useCart, useProductState } from '../hooks.js';
16
+ import { useTranslate } from '../i18n.js';
17
+ import { formatMoney } from '../money.js';
18
+ import { cn, renderChildren, visuallyHidden } from './util.js';
19
+ const FormContext = ProductContext;
20
+ /** The enclosing `<ProductForm>`'s state, or null outside one. */
21
+ export function useProductForm() {
22
+ return useContext(FormContext);
23
+ }
24
+ /**
25
+ * A `<form>` around a product's purchase controls. Submitting it adds the selected variant and quantity
26
+ * (`cart.create` / `cart.addLines`), which opens the cart. A sold-out variant is never sent.
27
+ */
28
+ export function ProductForm({ product, className, onAdded, children }) {
29
+ const state = useProductState(product);
30
+ const cart = useCart();
31
+ const [adding, setAdding] = useState(false);
32
+ const addToCart = useCallback(async () => {
33
+ if (!state.variant || !state.available || adding)
34
+ return false;
35
+ setAdding(true);
36
+ try {
37
+ return await cart.add(state.variant.id, state.quantity);
38
+ }
39
+ finally {
40
+ setAdding(false);
41
+ }
42
+ }, [state.variant, state.available, state.quantity, adding, cart]);
43
+ const value = { ...state, adding, addToCart };
44
+ const submit = async (e) => {
45
+ e.preventDefault();
46
+ if (await addToCart())
47
+ onAdded?.(value);
48
+ };
49
+ return (_jsx(FormContext.Provider, { value: value, children: _jsx("form", { className: className, "data-tq-product-form": "", onSubmit: submit, noValidate: true, children: renderChildren(children, value, () => null) }) }));
50
+ }
51
+ /**
52
+ * The option values of the product as radio groups (one `<fieldset>` per option, a `<label>`led radio per value).
53
+ * Choosing a value selects the matching variant; the price, image and add button follow. A product with a
54
+ * single default variant renders nothing.
55
+ */
56
+ export function VariantPicker({ className, optionClassName, valueClassName, legendClassName, renderValue, children }) {
57
+ const form = useProductForm();
58
+ const id = useId();
59
+ if (!form?.product)
60
+ return null;
61
+ const { options, selectOption } = form;
62
+ if (children)
63
+ return _jsx("div", { className: className, "data-tq-variant-picker": "", children: children({ options, selectOption }) });
64
+ if (form.product.variants.length <= 1 && options.every((o) => o.values.length <= 1))
65
+ return null;
66
+ return (_jsx("div", { className: className, "data-tq-variant-picker": "", children: options.map((o, i) => (_jsxs("fieldset", { className: optionClassName, children: [_jsx("legend", { className: legendClassName, children: o.name }), o.values.map((v) => (_jsxs("label", { className: valueClassName, "data-selected": v.selected ? 'true' : 'false', "data-available": v.available ? 'true' : 'false', children: [_jsx("input", { type: "radio", name: `${id}-option-${i}`, value: v.value, checked: v.selected, onChange: () => selectOption(o.name, v.value) }), _jsx("span", { children: renderValue ? renderValue(v, o) : v.value })] }, v.value)))] }, o.name))) }));
67
+ }
68
+ /** The selected variant's price (`data-tq-price`), and the regular price struck through on a sale. */
69
+ export function ProductPrice({ className, compareClassName, state, children }) {
70
+ const form = useProductForm();
71
+ const t = useTranslate();
72
+ const s = state ?? form;
73
+ if (!s?.price)
74
+ return null;
75
+ const price = formatMoney(s.price);
76
+ const compare = s.onSale && s.compareAtPrice ? formatMoney(s.compareAtPrice) : null;
77
+ if (children)
78
+ return _jsx("span", { className: className, "data-tq-price": "", children: children({ price, compareAtPrice: compare, onSale: s.onSale }) });
79
+ return (_jsxs("span", { className: className, "data-tq-price": "", children: [compare ? (_jsxs(_Fragment, { children: [_jsx("span", { className: visuallyHidden(), children: t('product.regularPrice') }), _jsx("s", { className: compareClassName, children: compare }), " ", _jsx("span", { className: visuallyHidden(), children: t('product.salePrice') })] })) : null, _jsx("span", { children: price })] }));
80
+ }
81
+ /** The quantity to add (a number input, at least 1). */
82
+ export function ProductQuantity({ className, labelClassName, label = 'hidden', max }) {
83
+ const form = useProductForm();
84
+ const t = useTranslate();
85
+ const id = useId();
86
+ if (!form)
87
+ return null;
88
+ const cap = max ?? form.quantityAvailable ?? undefined;
89
+ return (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: id, className: label === 'visible' ? labelClassName : cn(visuallyHidden(), labelClassName), children: t('product.quantity') }), _jsx("input", { id: id, className: className, type: "number", inputMode: "numeric", min: 1, ...(cap ? { max: cap } : {}), value: form.quantity, onChange: (e) => form.setQuantity(Number(e.target.value)) })] }));
90
+ }
91
+ /**
92
+ * The add-to-cart `<button>` (`data-tq-action="cart:add"`). In a `<ProductForm>` it submits the form; it is
93
+ * disabled, and says "Sold out", when the selected variant cannot be bought.
94
+ */
95
+ export function AddToCart({ variantId, available: availableProp, quantity = 1, children, className, disabled, ...rest }) {
96
+ const form = useProductForm();
97
+ const cart = useCart();
98
+ const t = useTranslate();
99
+ const [busy, setBusy] = useState(false);
100
+ const available = form ? form.available && Boolean(form.variant) : availableProp !== false && Boolean(variantId);
101
+ const adding = form ? form.adding : busy;
102
+ const label = adding ? t('product.adding') : available ? t('product.addToCart') : t('product.soldOut');
103
+ const onClick = form
104
+ ? undefined
105
+ : async () => {
106
+ if (!variantId || !available || busy)
107
+ return;
108
+ setBusy(true);
109
+ try {
110
+ await cart.add(variantId, quantity);
111
+ }
112
+ finally {
113
+ setBusy(false);
114
+ }
115
+ };
116
+ return (_jsx("button", { ...rest, type: form ? 'submit' : 'button', className: className, "data-tq-action": "cart:add", disabled: disabled || !available || adding, "aria-busy": adding || undefined, onClick: onClick, children: children ? children({ available, adding, label }) : label }));
117
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Search, localization, platform forms, consent and the account slot.
3
+ *
4
+ * <SearchForm /> <form role="search" action="/search"> + <input type="search" name="q" data-tq-search>,
5
+ * with predictive suggestions while typing (browser `data:search`)
6
+ * <LocalizationForm /> <form data-tq-localization>: <select name="country"> + <select name="locale">
7
+ * <NewsletterForm /> <form data-tq-form="newsletter" method="post"> (manifest `forms.newsletter`)
8
+ * <ContactForm /> <form data-tq-form="contact" method="post"> (manifest `forms.contact`)
9
+ * <ConsentBanner /> the cookie banner (data-tq-consent-banner), only when the platform asks for one;
10
+ * never on a preview render (the editor canvas)
11
+ * <AccountSlot /> <iframe data-tq-slot="account">: the platform's account area (customer route)
12
+ */
13
+ import { type ReactNode } from 'react';
14
+ import { type ConsentState, type LocalizationState, type PredictiveResults } from '../hooks.js';
15
+ import { type RenderChildren } from './util.js';
16
+ export interface SearchFormProps {
17
+ className?: string;
18
+ inputClassName?: string;
19
+ /** On the submit button; `submit={false}` renders none (Enter submits). */
20
+ buttonClassName?: string;
21
+ submit?: boolean;
22
+ /** On the suggestions container. */
23
+ resultsClassName?: string;
24
+ /** Suggestions while typing (default true). Needs `data:search` in the manifest's browser capabilities. */
25
+ predictive?: boolean;
26
+ limit?: number;
27
+ /** How the suggestions render (links to products by default). */
28
+ renderResults?(results: PredictiveResults, query: string): ReactNode;
29
+ }
30
+ /** The store search (`GET /search?q=`), with predictive suggestions announced politely as the shopper types. */
31
+ export declare function SearchForm({ className, inputClassName, buttonClassName, submit, resultsClassName, predictive, limit, renderResults }: SearchFormProps): JSX.Element;
32
+ export interface LocalizationFormProps {
33
+ className?: string;
34
+ /** On each `<label>` text (visible by default). */
35
+ labelClassName?: string;
36
+ label?: 'visible' | 'hidden';
37
+ selectClassName?: string;
38
+ /** Which selects to show (default both; each renders only with two or more choices). */
39
+ show?: {
40
+ country?: boolean;
41
+ language?: boolean;
42
+ };
43
+ /** How a country option reads; "Japan (JPY ¥)" by default. */
44
+ countryLabel?(c: LocalizationState['countries'][number]): string;
45
+ children?: (state: LocalizationState) => ReactNode;
46
+ }
47
+ /**
48
+ * Market and language selectors (`data-tq-localization`): a GET form with `<select name="country">` and
49
+ * `<select name="locale">`. A choice loads the page for that country (its market's currency, with that currency's
50
+ * decimals) or language. The country list needs the page to read the shopper's country
51
+ * (`storefront.plan.localization`).
52
+ */
53
+ export declare function LocalizationForm({ className, labelClassName, label, selectClassName, show, countryLabel, children }: LocalizationFormProps): JSX.Element | null;
54
+ export type FormStatus = 'idle' | 'ok' | 'invalid' | 'rate_limited' | 'unavailable' | 'expired';
55
+ export interface PlatformFormState {
56
+ /** The outcome of this form's POST, when this page answers one. */
57
+ status: FormStatus;
58
+ /** The address typed before a failed post (kept so the shopper need not type it again). */
59
+ email: string;
60
+ /** The message for `status` in the page's language ('' when idle or ok). */
61
+ message: string;
62
+ /** A field the browser check refused before posting (`email`), else null. */
63
+ invalidField: string | null;
64
+ }
65
+ export interface PlatformFormProps {
66
+ className?: string;
67
+ inputClassName?: string;
68
+ buttonClassName?: string;
69
+ /** On the visible field labels. */
70
+ labelClassName?: string;
71
+ /** On the status / error message. */
72
+ messageClassName?: string;
73
+ /** The fields and button, as the theme writes them (the form, gateway fields and honeypot stay the kit's). */
74
+ children?: RenderChildren<PlatformFormState>;
75
+ /** What shows in place of the form after a successful post. */
76
+ done?: ReactNode;
77
+ }
78
+ /**
79
+ * Newsletter sign-up, posted natively to the platform (`<form data-tq-form="newsletter" method="post">`): the
80
+ * store's subscriber list. Declare `forms.newsletter` (fields `email`, `website`) in the manifest. Renders nothing
81
+ * on a host without the platform form endpoint.
82
+ */
83
+ export declare function NewsletterForm({ className, inputClassName, buttonClassName, labelClassName, messageClassName, children, done }: PlatformFormProps): JSX.Element | null;
84
+ /**
85
+ * Contact form, posted natively to the platform (`<form data-tq-form="contact" method="post">`): the message
86
+ * reaches the merchant. Declare `forms.contact` (fields `name`, `email`, `phone`, `message`, `website`).
87
+ */
88
+ export declare function ContactForm({ className, inputClassName, buttonClassName, labelClassName, messageClassName, children, done }: PlatformFormProps): JSX.Element | null;
89
+ export interface ConsentBannerProps {
90
+ className?: string;
91
+ buttonClassName?: string;
92
+ /** On the accept button (after `buttonClassName`). */
93
+ acceptClassName?: string;
94
+ children?: (state: ConsentState) => ReactNode;
95
+ }
96
+ /**
97
+ * The cookie banner (`data-tq-consent-banner`), shown only while the platform says one is needed and the shopper
98
+ * has not answered; never on a preview render. The merchant's own wording (Settings › Customer privacy) wins.
99
+ * Rendered inside `<div data-tq-client-slot="consent">` (empty in the server HTML).
100
+ */
101
+ export declare function ConsentBanner({ className, buttonClassName, acceptClassName, children }: ConsentBannerProps): JSX.Element;
102
+ /** The platform's account area (sign-in, orders, addresses) on the customer route: `<iframe data-tq-slot="account">`. */
103
+ export declare function AccountSlot({ className, title }: {
104
+ className?: string;
105
+ title?: string;
106
+ }): JSX.Element | null;