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

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 (202) 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 +256 -0
  7. package/dist/abi/convert.d.ts +126 -0
  8. package/dist/abi/convert.js +493 -0
  9. package/dist/abi/data-api.d.ts +11 -0
  10. package/dist/abi/data-api.js +178 -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 +198 -0
  14. package/dist/abi/page-data.js +577 -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 +237 -0
  72. package/dist/runtime/data/to-ui.js +759 -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 +167 -0
  82. package/dist/runtime/kit/cart.js +544 -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/{types → runtime/kit}/data.d.ts +276 -7
  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/{types → runtime/kit}/storefront.d.ts +206 -7
  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 +44 -0
  144. package/dist/runtime/render/section-actions.js +169 -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 +82 -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 +120 -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 +395 -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/editor.d.ts +0 -5
  200. package/dist/types/index.d.ts +0 -20
  201. package/dist/types/preview-bridge.d.ts +0 -9
  202. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,186 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * Search, localization, platform forms, consent and the account slot.
4
+ *
5
+ * <SearchForm /> <form role="search" action="/search"> + <input type="search" name="q" data-tq-search>,
6
+ * with predictive suggestions while typing (browser `data:search`)
7
+ * <LocalizationForm /> <form data-tq-localization>: <select name="country"> + <select name="locale">
8
+ * <NewsletterForm /> <form data-tq-form="newsletter" method="post"> (manifest `forms.newsletter`)
9
+ * <ContactForm /> <form data-tq-form="contact" method="post"> (manifest `forms.contact`)
10
+ * <ConsentBanner /> the cookie banner (data-tq-consent-banner), only when the platform asks for one;
11
+ * never on a preview render (the editor canvas)
12
+ * <AccountSlot /> <iframe data-tq-slot="account">: the platform's account area (customer route)
13
+ */
14
+ import { useId, useState } from 'react';
15
+ import { useData } from '../../runtime/kit/index.js';
16
+ import { useServerRender } from '../../sdk/server-render.js';
17
+ import { useConsent, useCustomer, useLocalization, usePredictiveSearch, useSearch } from '../hooks.js';
18
+ import { useTranslate } from '../i18n.js';
19
+ import { usePage } from '../page.js';
20
+ import { formatMoney } from '../money.js';
21
+ import { cn, renderChildren, visuallyHidden } from './util.js';
22
+ /** The store search (`GET /search?q=`), with predictive suggestions announced politely as the shopper types. */
23
+ export function SearchForm({ className, inputClassName, buttonClassName, submit = true, resultsClassName, predictive = true, limit = 6, renderResults }) {
24
+ const t = useTranslate();
25
+ const search = useSearch();
26
+ const id = useId();
27
+ const [query, setQuery] = useState(search.query);
28
+ const [dirty, setDirty] = useState(false);
29
+ const { results } = usePredictiveSearch(predictive && dirty ? query : '', { limit });
30
+ const shown = results && (results.products.length > 0 || results.collections.length > 0) ? results : null;
31
+ return (_jsxs("form", { role: "search", action: "/search", method: "get", className: className, children: [_jsx("label", { htmlFor: id, className: visuallyHidden(), children: t('search.search') }), _jsx("input", { id: id, className: inputClassName, type: "search", name: "q", "data-tq-search": "", autoComplete: "off", placeholder: t('search.placeholder'), value: query, onChange: (e) => {
32
+ setQuery(e.target.value);
33
+ setDirty(true);
34
+ }, "aria-describedby": `${id}-results` }), submit ? (_jsx("button", { type: "submit", className: buttonClassName, children: t('search.submit') })) : null, _jsx("div", { id: `${id}-results`, className: resultsClassName, "aria-live": "polite", children: shown ? (renderResults ? (renderResults(shown, query)) : (_jsxs(_Fragment, { children: [_jsx("p", { className: visuallyHidden(), children: t('search.suggestions') }), _jsx("ul", { children: shown.products.map((p) => (_jsx("li", { children: _jsxs("a", { href: p.url, children: [_jsx("span", { children: p.title }), p.price ? _jsxs("span", { children: [" ", formatMoney(p.price)] }) : null] }) }, p.handle))) })] }))) : null })] }));
35
+ }
36
+ /**
37
+ * Market and language selectors (`data-tq-localization`): a GET form with `<select name="country">` and
38
+ * `<select name="locale">`. A choice loads the page for that country (its market's currency, with that currency's
39
+ * decimals) or language. The country list needs the page to read the shopper's country
40
+ * (`storefront.plan.localization`).
41
+ */
42
+ export function LocalizationForm({ className, labelClassName, label = 'visible', selectClassName, show, countryLabel, children }) {
43
+ const l = useLocalization();
44
+ const t = useTranslate();
45
+ const page = usePage();
46
+ const id = useId();
47
+ let action = '/';
48
+ try {
49
+ action = new URL(page.canonical).pathname;
50
+ }
51
+ catch {
52
+ action = '/';
53
+ }
54
+ const showCountry = show?.country !== false && l.countries.length > 1;
55
+ const showLanguage = show?.language !== false && l.languages.length > 1;
56
+ if (children)
57
+ return _jsx("form", { method: "get", action: action, className: className, "data-tq-localization": "", children: children(l) });
58
+ if (!showCountry && !showLanguage)
59
+ return null;
60
+ const labelCls = label === 'visible' ? labelClassName : cn(visuallyHidden(), labelClassName);
61
+ const nameOf = countryLabel ?? ((c) => `${c.name} (${c.currencyCode}${c.currencySymbol && c.currencySymbol !== c.currencyCode ? ` ${c.currencySymbol}` : ''})`);
62
+ return (_jsxs("form", { method: "get", action: action, className: className, "data-tq-localization": "", onSubmit: (e) => e.preventDefault(), children: [showCountry ? (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-country`, className: labelCls, children: t('localization.country') }), _jsxs("select", { id: `${id}-country`, name: "country", className: selectClassName, value: l.country?.code ?? '', onChange: (e) => l.changeCountry(e.target.value), children: [l.country ? null : _jsx("option", { value: "", children: "\u2014" }), l.countries.map((c) => (_jsx("option", { value: c.code, children: nameOf(c) }, c.code)))] })] })) : null, showLanguage ? (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-language`, className: labelCls, children: t('localization.language') }), _jsx("select", { id: `${id}-language`, name: "locale", className: selectClassName, value: l.language.code, onChange: (e) => l.changeLanguage(e.target.value), children: l.languages.map((x) => (_jsx("option", { value: x.code, lang: x.code, children: x.name }, x.code))) })] })) : null] }));
63
+ }
64
+ // ── platform forms ─────────────────────────────────────────────────────────
65
+ const FORM_FIELD = '_tq_form';
66
+ const CSRF_FIELD = '_tq_csrf';
67
+ const hiddenValue = (el, name) => (el && el.tagName === 'INPUT' && el.getAttribute('name') === name ? (el.getAttribute('value') ?? '') : null);
68
+ /** The fields the gateway put at the start of `<form data-tq-form="<id>">` in the delivered page, or null. */
69
+ function injectedInto(formId) {
70
+ if (typeof document === 'undefined')
71
+ return null;
72
+ for (const form of Array.from(document.querySelectorAll(`form[data-tq-form="${formId}"]`))) {
73
+ const first = form.firstElementChild;
74
+ if (hiddenValue(first, FORM_FIELD) !== null)
75
+ return { csrf: hiddenValue(first.nextElementSibling, CSRF_FIELD) ?? '' };
76
+ }
77
+ return null;
78
+ }
79
+ /**
80
+ * The platform gateway injects `_tq_form` and (with the shopper's token) `_tq_csrf` as the FIRST children of a
81
+ * `<form data-tq-form>` after its cache; the server never renders them. The browser mirrors what the delivered
82
+ * page holds on its hydrating render, so the tree matches the injected markup and a re-render keeps the fields.
83
+ */
84
+ function GatewayFields({ formId }) {
85
+ const server = useServerRender();
86
+ const [present] = useState(() => (server ? null : injectedInto(formId)));
87
+ if (server || !present)
88
+ return null;
89
+ return (_jsxs(_Fragment, { children: [_jsx("input", { type: "hidden", name: FORM_FIELD, value: formId }), present.csrf ? _jsx("input", { type: "hidden", name: CSRF_FIELD, value: present.csrf }) : null] }));
90
+ }
91
+ /** A form the gateway never saw (rendered after hydration) gets the two fields from `<meta name="tq-csrf">` before it posts. */
92
+ function ensureGatewayFields(form, formId) {
93
+ if (form.querySelector(`input[name="${FORM_FIELD}"]`))
94
+ return;
95
+ const token = document.querySelector('meta[name="tq-csrf"]')?.getAttribute('content') ?? '';
96
+ const add = (name, value) => {
97
+ const input = document.createElement('input');
98
+ input.type = 'hidden';
99
+ input.name = name;
100
+ input.value = value;
101
+ form.prepend(input);
102
+ };
103
+ if (/^[A-Za-z0-9_-]+$/.test(token))
104
+ add(CSRF_FIELD, token);
105
+ add(FORM_FIELD, formId);
106
+ }
107
+ /** The bot trap the platform form endpoints read (`website`): off screen, out of the tab order, hidden from assistive technology. */
108
+ function Honeypot() {
109
+ const t = useTranslate();
110
+ return (_jsx("div", { className: visuallyHidden(), "aria-hidden": "true", children: _jsxs("label", { children: [t('form.website'), _jsx("input", { type: "text", name: "website", tabIndex: -1, autoComplete: "off", defaultValue: "" })] }) }));
111
+ }
112
+ function usePlatformForm(formId) {
113
+ const data = useData();
114
+ const t = useTranslate();
115
+ const r = data.formResult && (data.formResult.formId === formId || data.formResult.formId === '*') ? data.formResult : null;
116
+ const [invalidField, setInvalid] = useState(null);
117
+ const status = r ? r.status : 'idle';
118
+ const message = invalidField === 'email' || status === 'invalid' ? t('form.invalidEmail') : status === 'rate_limited' ? t('form.rateLimited') : status === 'unavailable' ? t('form.unavailable') : status === 'expired' ? t('form.expired') : '';
119
+ return { endpoint: data.formEndpoint ?? null, state: { status, email: r?.email ?? '', message, invalidField }, setInvalid };
120
+ }
121
+ const EMAIL = /^[^\s@<>"]+@[^\s@<>"]+\.[^\s@<>"]+$/;
122
+ function submitFor(formId, setInvalid) {
123
+ return (e) => {
124
+ const form = e.currentTarget;
125
+ const email = String(new FormData(form).get('email') ?? '');
126
+ if (form.querySelector('input[name="email"]') && !EMAIL.test(email.trim())) {
127
+ e.preventDefault();
128
+ setInvalid('email');
129
+ return;
130
+ }
131
+ setInvalid(null);
132
+ ensureGatewayFields(form, formId);
133
+ };
134
+ }
135
+ /**
136
+ * Newsletter sign-up, posted natively to the platform (`<form data-tq-form="newsletter" method="post">`): the
137
+ * store's subscriber list. Declare `forms.newsletter` (fields `email`, `website`) in the manifest. Renders nothing
138
+ * on a host without the platform form endpoint.
139
+ */
140
+ export function NewsletterForm({ className, inputClassName, buttonClassName, labelClassName, messageClassName, children, done }) {
141
+ const { endpoint, state, setInvalid } = usePlatformForm('newsletter');
142
+ const t = useTranslate();
143
+ const id = useId();
144
+ if (!endpoint)
145
+ return null;
146
+ if (state.status === 'ok')
147
+ return _jsx("p", { className: messageClassName, role: "status", children: done ?? t('newsletter.done') });
148
+ return (_jsxs("form", { method: "post", action: endpoint, className: className, "data-tq-form": "newsletter", noValidate: true, onSubmit: submitFor('newsletter', setInvalid), children: [_jsx(GatewayFields, { formId: "newsletter" }), _jsx(Honeypot, {}), renderChildren(children, state, () => (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-email`, className: labelClassName ?? visuallyHidden(), children: t('form.email') }), _jsx("input", { id: `${id}-email`, className: inputClassName, type: "email", name: "email", autoComplete: "email", required: true, defaultValue: state.email, "aria-invalid": state.invalidField === 'email' || state.status === 'invalid' || undefined, "aria-describedby": state.message ? `${id}-msg` : undefined }), _jsx("button", { type: "submit", className: buttonClassName, children: t('newsletter.subscribe') })] }))), state.message ? (_jsx("p", { id: `${id}-msg`, className: messageClassName, role: "alert", children: state.message })) : null] }));
149
+ }
150
+ /**
151
+ * Contact form, posted natively to the platform (`<form data-tq-form="contact" method="post">`): the message
152
+ * reaches the merchant. Declare `forms.contact` (fields `name`, `email`, `phone`, `message`, `website`).
153
+ */
154
+ export function ContactForm({ className, inputClassName, buttonClassName, labelClassName, messageClassName, children, done }) {
155
+ const { endpoint, state, setInvalid } = usePlatformForm('contact');
156
+ const t = useTranslate();
157
+ const id = useId();
158
+ if (!endpoint)
159
+ return null;
160
+ if (state.status === 'ok')
161
+ return _jsx("p", { className: messageClassName, role: "status", children: done ?? t('contact.done') });
162
+ const field = (name, key, input) => (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: `${id}-${name}`, className: labelClassName, children: t(key) }), input] }));
163
+ return (_jsxs("form", { method: "post", action: endpoint, className: className, "data-tq-form": "contact", noValidate: true, onSubmit: submitFor('contact', setInvalid), children: [_jsx(GatewayFields, { formId: "contact" }), _jsx(Honeypot, {}), renderChildren(children, state, () => (_jsxs(_Fragment, { children: [field('name', 'contact.name', _jsx("input", { id: `${id}-name`, className: inputClassName, type: "text", name: "name", autoComplete: "name" })), field('email', 'form.email', _jsx("input", { id: `${id}-email`, className: inputClassName, type: "email", name: "email", autoComplete: "email", required: true, defaultValue: state.email, "aria-invalid": state.invalidField === 'email' || state.status === 'invalid' || undefined })), field('phone', 'contact.phone', _jsx("input", { id: `${id}-phone`, className: inputClassName, type: "tel", name: "phone", autoComplete: "tel" })), field('message', 'contact.message', _jsx("textarea", { id: `${id}-message`, className: inputClassName, name: "message", rows: 5 })), _jsx("button", { type: "submit", className: buttonClassName, children: t('contact.send') })] }))), state.message ? (_jsx("p", { className: messageClassName, role: "alert", children: state.message })) : null] }));
164
+ }
165
+ /**
166
+ * The cookie banner (`data-tq-consent-banner`), shown only while the platform says one is needed and the shopper
167
+ * has not answered; never on a preview render. The merchant's own wording (Settings › Customer privacy) wins.
168
+ * Rendered inside `<div data-tq-client-slot="consent">` (empty in the server HTML).
169
+ */
170
+ export function ConsentBanner({ className, buttonClassName, acceptClassName, children }) {
171
+ const c = useConsent();
172
+ const t = useTranslate();
173
+ const title = c.text.title ?? t('consent.title');
174
+ // The banner is browser-only (the platform answers consent after hydration): it lives in an empty client
175
+ // slot the server renders, so hydration parity holds (theme-abi §10.5, Hyd-2).
176
+ return _jsx("div", { "data-tq-client-slot": "consent", children: c.required ? (_jsx("section", { className: className, "data-tq-consent-banner": "", "aria-label": title, children: children ? (children(c)) : (_jsxs(_Fragment, { children: [_jsxs("p", { children: [_jsx("strong", { children: title }), " ", c.text.body ?? t('consent.body'), ' ', c.privacyUrl ? _jsx("a", { href: c.privacyUrl, children: c.text.privacyLinkLabel ?? t('consent.privacy') }) : null] }), _jsx("button", { type: "button", className: buttonClassName, onClick: c.reject, children: c.text.declineLabel ?? t('consent.reject') }), _jsx("button", { type: "button", className: cn(buttonClassName, acceptClassName), onClick: c.accept, children: c.text.acceptLabel ?? t('consent.accept') })] })) })) : null });
177
+ }
178
+ // ── account ────────────────────────────────────────────────────────────────
179
+ /** The platform's account area (sign-in, orders, addresses) on the customer route: `<iframe data-tq-slot="account">`. */
180
+ export function AccountSlot({ className, title }) {
181
+ const { accountUrl } = useCustomer();
182
+ const t = useTranslate();
183
+ if (!accountUrl)
184
+ return null;
185
+ return _jsx("iframe", { className: className, "data-tq-slot": "account", src: accountUrl, sandbox: "allow-scripts allow-forms allow-same-origin", title: title ?? t('account.title') });
186
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Shared plumbing for the headless primitives: render-prop children, the one visually-hidden class the kit
3
+ * needs (a label that must exist for assistive technology but not on screen), and focus management.
4
+ *
5
+ * The kit ships no CSS. The only rule it adds is `visuallyHidden()`, as an `sx()` class (the platform CSP has
6
+ * `style-src-attr 'none'`, so no `style=""` attribute is ever rendered).
7
+ */
8
+ import type { ReactNode } from 'react';
9
+ /** Children as nodes, or a function of the primitive's state. */
10
+ export type RenderChildren<S> = ReactNode | ((state: S) => ReactNode);
11
+ export declare function renderChildren<S>(children: RenderChildren<S> | undefined, state: S, fallback: () => ReactNode): ReactNode;
12
+ /** Join class names, skipping empty ones. */
13
+ export declare function cn(...names: Array<string | false | null | undefined>): string | undefined;
14
+ /** A class that hides an element on screen and keeps it for screen readers. */
15
+ export declare function visuallyHidden(): string | undefined;
16
+ /** The focusable elements inside `root`, in DOM order. */
17
+ export declare function focusables(root: Element): HTMLElement[];
18
+ /** Keep Tab / Shift+Tab inside `root` (a modal dialog). */
19
+ export declare function trapTab(e: KeyboardEvent, root: Element): void;
@@ -0,0 +1,42 @@
1
+ import { sx } from '../../sdk/sx.js';
2
+ export function renderChildren(children, state, fallback) {
3
+ if (typeof children === 'function')
4
+ return children(state);
5
+ return children ?? fallback();
6
+ }
7
+ /** Join class names, skipping empty ones. */
8
+ export function cn(...names) {
9
+ const s = names.filter(Boolean).join(' ');
10
+ return s || undefined;
11
+ }
12
+ /** A class that hides an element on screen and keeps it for screen readers. */
13
+ export function visuallyHidden() {
14
+ return sx({ position: 'absolute', width: 1, height: 1, padding: 0, margin: -1, overflow: 'hidden', clip: 'rect(0 0 0 0)', whiteSpace: 'nowrap', border: 0 });
15
+ }
16
+ const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
17
+ /** The focusable elements inside `root`, in DOM order. */
18
+ export function focusables(root) {
19
+ return Array.from(root.querySelectorAll(FOCUSABLE)).filter((e) => !e.hasAttribute('inert') && !e.closest('[inert]'));
20
+ }
21
+ /** Keep Tab / Shift+Tab inside `root` (a modal dialog). */
22
+ export function trapTab(e, root) {
23
+ if (e.key !== 'Tab')
24
+ return;
25
+ const list = focusables(root);
26
+ if (!list.length) {
27
+ e.preventDefault();
28
+ root.focus();
29
+ return;
30
+ }
31
+ const first = list[0];
32
+ const last = list[list.length - 1];
33
+ const active = root.ownerDocument.activeElement;
34
+ if (e.shiftKey && (active === first || !root.contains(active))) {
35
+ e.preventDefault();
36
+ last.focus();
37
+ }
38
+ else if (!e.shiftKey && (active === last || !root.contains(active))) {
39
+ e.preventDefault();
40
+ first.focus();
41
+ }
42
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The words the kit's headless primitives render, per language (pure data: the build reads it in Node too).
3
+ * Keys end in the names the storefront check recognises (`addToCart`, `soldOut`, `checkout`, `remove`, …).
4
+ */
5
+ export type Strings = Readonly<Record<string, string>>;
6
+ /** Every key exists in every language. */
7
+ export declare const KIT_STRINGS: Readonly<Record<'en' | 'th', Strings>>;
8
+ /** The kit's words for `language` (its base language), English when the kit has none for it. */
9
+ export declare function kitStrings(language: string): Strings;
@@ -0,0 +1,186 @@
1
+ /** Every key exists in every language. */
2
+ export const KIT_STRINGS = {
3
+ en: {
4
+ 'a11y.skipToContent': 'Skip to content',
5
+ 'a11y.close': 'Close',
6
+ 'menu.menu': 'Menu',
7
+ 'menu.closeMenu': 'Close menu',
8
+ 'product.addToCart': 'Add to cart',
9
+ 'product.soldOut': 'Sold out',
10
+ 'product.unavailable': 'Unavailable',
11
+ 'product.adding': 'Adding…',
12
+ 'product.quantity': 'Quantity',
13
+ 'product.salePrice': 'Sale price',
14
+ 'product.regularPrice': 'Regular price',
15
+ 'product.inStock': 'In stock',
16
+ 'product.lowStock': 'Only {count} left',
17
+ 'product.addFailed': 'This item could not be added to your cart.',
18
+ 'cart.openCart': 'Cart',
19
+ 'cart.cartCount': 'Cart ({count})',
20
+ 'cart.title': 'Your cart',
21
+ 'cart.empty': 'Your cart is empty.',
22
+ 'cart.checkout': 'Check out',
23
+ 'cart.remove': 'Remove',
24
+ 'cart.increase': 'Increase quantity',
25
+ 'cart.decrease': 'Decrease quantity',
26
+ 'cart.quantity': 'Quantity',
27
+ 'cart.subtotal': 'Subtotal',
28
+ 'cart.total': 'Total',
29
+ 'cart.close': 'Close cart',
30
+ 'cart.loading': 'Loading your cart…',
31
+ 'cart.loadError': "We couldn't load your cart. Retrying…",
32
+ 'cart.lineFailed': 'This change could not be saved.',
33
+ 'cart.limitReached': 'You can buy up to {max} of this item.',
34
+ 'collection.sort': 'Sort',
35
+ 'collection.filter': 'Filter',
36
+ 'collection.clearFilters': 'Clear filters',
37
+ 'collection.loadMore': 'Load more',
38
+ 'collection.loading': 'Loading…',
39
+ 'collection.productCount': '{count} products',
40
+ 'collection.empty': 'No products match these filters.',
41
+ 'collection.priceFrom': 'From',
42
+ 'collection.priceTo': 'To',
43
+ 'collection.loadError': "We couldn't load more products.",
44
+ 'collection.pagination': 'Pagination',
45
+ 'collection.previous': 'Previous page',
46
+ 'sort.featured': 'Featured',
47
+ 'sort.best-selling': 'Best selling',
48
+ 'sort.title-asc': 'Name, A–Z',
49
+ 'sort.title-desc': 'Name, Z–A',
50
+ 'sort.price-asc': 'Price, low to high',
51
+ 'sort.price-desc': 'Price, high to low',
52
+ 'sort.created-desc': 'Newest',
53
+ 'sort.created-asc': 'Oldest',
54
+ 'sort.relevance': 'Relevance',
55
+ 'filter.available': 'Availability',
56
+ 'filter.available.true': 'In stock',
57
+ 'filter.available.false': 'Out of stock',
58
+ 'filter.vendor': 'Brand',
59
+ 'filter.productType': 'Product type',
60
+ 'filter.price': 'Price',
61
+ 'search.search': 'Search',
62
+ 'search.placeholder': 'Search the store',
63
+ 'search.submit': 'Search',
64
+ 'search.results': '{count} results for “{query}”',
65
+ 'search.none': 'No results for “{query}”.',
66
+ 'search.suggestions': 'Suggestions',
67
+ 'search.products': 'Products',
68
+ 'localization.country': 'Country/region',
69
+ 'localization.language': 'Language',
70
+ 'localization.update': 'Update',
71
+ 'consent.title': 'Cookies',
72
+ 'consent.body': 'We use cookies to run this store and, with your permission, to measure and improve it.',
73
+ 'consent.accept': 'Accept',
74
+ 'consent.reject': 'Decline',
75
+ 'consent.privacy': 'Privacy policy',
76
+ 'form.email': 'Email',
77
+ 'form.website': 'Website',
78
+ 'form.invalidEmail': 'Enter a valid email address.',
79
+ 'form.rateLimited': 'Too many attempts. Please try again in a minute.',
80
+ 'form.unavailable': "This form isn't available right now. Please try again later.",
81
+ 'form.expired': 'This page expired. Please submit the form again.',
82
+ 'newsletter.subscribe': 'Subscribe',
83
+ 'newsletter.done': "Thanks — you're on the list.",
84
+ 'contact.name': 'Name',
85
+ 'contact.phone': 'Phone',
86
+ 'contact.message': 'Message',
87
+ 'contact.send': 'Send message',
88
+ 'contact.done': "Thanks — we'll get back to you soon.",
89
+ 'account.title': 'Account',
90
+ 'breadcrumbs.home': 'Home',
91
+ },
92
+ th: {
93
+ 'a11y.skipToContent': 'ข้ามไปยังเนื้อหา',
94
+ 'a11y.close': 'ปิด',
95
+ 'menu.menu': 'เมนู',
96
+ 'menu.closeMenu': 'ปิดเมนู',
97
+ 'product.addToCart': 'เพิ่มลงตะกร้า',
98
+ 'product.soldOut': 'สินค้าหมด',
99
+ 'product.unavailable': 'ไม่มีจำหน่าย',
100
+ 'product.adding': 'กำลังเพิ่ม…',
101
+ 'product.quantity': 'จำนวน',
102
+ 'product.salePrice': 'ราคาลด',
103
+ 'product.regularPrice': 'ราคาปกติ',
104
+ 'product.inStock': 'มีสินค้า',
105
+ 'product.lowStock': 'เหลือเพียง {count} ชิ้น',
106
+ 'product.addFailed': 'ไม่สามารถเพิ่มสินค้านี้ลงตะกร้าได้',
107
+ 'cart.openCart': 'ตะกร้า',
108
+ 'cart.cartCount': 'ตะกร้า ({count})',
109
+ 'cart.title': 'ตะกร้าของคุณ',
110
+ 'cart.empty': 'ตะกร้าของคุณว่างอยู่',
111
+ 'cart.checkout': 'ชำระเงิน',
112
+ 'cart.remove': 'นำออก',
113
+ 'cart.increase': 'เพิ่มจำนวน',
114
+ 'cart.decrease': 'ลดจำนวน',
115
+ 'cart.quantity': 'จำนวน',
116
+ 'cart.subtotal': 'ยอดรวมย่อย',
117
+ 'cart.total': 'ยอดรวม',
118
+ 'cart.close': 'ปิดตะกร้า',
119
+ 'cart.loading': 'กำลังโหลดตะกร้า…',
120
+ 'cart.loadError': 'โหลดตะกร้าไม่สำเร็จ กำลังลองใหม่…',
121
+ 'cart.lineFailed': 'บันทึกการเปลี่ยนแปลงนี้ไม่สำเร็จ',
122
+ 'cart.limitReached': 'ซื้อสินค้านี้ได้สูงสุด {max} ชิ้น',
123
+ 'collection.sort': 'เรียงตาม',
124
+ 'collection.filter': 'ตัวกรอง',
125
+ 'collection.clearFilters': 'ล้างตัวกรอง',
126
+ 'collection.loadMore': 'โหลดเพิ่ม',
127
+ 'collection.loading': 'กำลังโหลด…',
128
+ 'collection.productCount': 'สินค้า {count} รายการ',
129
+ 'collection.empty': 'ไม่มีสินค้าที่ตรงกับตัวกรองนี้',
130
+ 'collection.priceFrom': 'ตั้งแต่',
131
+ 'collection.priceTo': 'ถึง',
132
+ 'collection.loadError': 'โหลดสินค้าเพิ่มไม่สำเร็จ',
133
+ 'collection.pagination': 'การแบ่งหน้า',
134
+ 'collection.previous': 'หน้าก่อนหน้า',
135
+ 'sort.featured': 'แนะนำ',
136
+ 'sort.best-selling': 'ขายดี',
137
+ 'sort.title-asc': 'ชื่อ ก–ฮ',
138
+ 'sort.title-desc': 'ชื่อ ฮ–ก',
139
+ 'sort.price-asc': 'ราคา ต่ำไปสูง',
140
+ 'sort.price-desc': 'ราคา สูงไปต่ำ',
141
+ 'sort.created-desc': 'ใหม่ล่าสุด',
142
+ 'sort.created-asc': 'เก่าที่สุด',
143
+ 'sort.relevance': 'ความเกี่ยวข้อง',
144
+ 'filter.available': 'สถานะสินค้า',
145
+ 'filter.available.true': 'มีสินค้า',
146
+ 'filter.available.false': 'สินค้าหมด',
147
+ 'filter.vendor': 'แบรนด์',
148
+ 'filter.productType': 'ประเภทสินค้า',
149
+ 'filter.price': 'ราคา',
150
+ 'search.search': 'ค้นหา',
151
+ 'search.placeholder': 'ค้นหาในร้าน',
152
+ 'search.submit': 'ค้นหา',
153
+ 'search.results': 'พบ {count} รายการสำหรับ “{query}”',
154
+ 'search.none': 'ไม่พบผลลัพธ์สำหรับ “{query}”',
155
+ 'search.suggestions': 'คำแนะนำ',
156
+ 'search.products': 'สินค้า',
157
+ 'localization.country': 'ประเทศ/ภูมิภาค',
158
+ 'localization.language': 'ภาษา',
159
+ 'localization.update': 'อัปเดต',
160
+ 'consent.title': 'คุกกี้',
161
+ 'consent.body': 'เราใช้คุกกี้เพื่อให้ร้านค้าทำงาน และเพื่อวัดผลและปรับปรุงร้านเมื่อคุณอนุญาต',
162
+ 'consent.accept': 'ยอมรับ',
163
+ 'consent.reject': 'ปฏิเสธ',
164
+ 'consent.privacy': 'นโยบายความเป็นส่วนตัว',
165
+ 'form.email': 'อีเมล',
166
+ 'form.website': 'เว็บไซต์',
167
+ 'form.invalidEmail': 'กรุณากรอกอีเมลให้ถูกต้อง',
168
+ 'form.rateLimited': 'ลองหลายครั้งเกินไป กรุณาลองใหม่ในอีกสักครู่',
169
+ 'form.unavailable': 'แบบฟอร์มนี้ใช้งานไม่ได้ในขณะนี้ กรุณาลองใหม่ภายหลัง',
170
+ 'form.expired': 'หน้านี้หมดอายุแล้ว กรุณาส่งแบบฟอร์มอีกครั้ง',
171
+ 'newsletter.subscribe': 'สมัครรับข่าวสาร',
172
+ 'newsletter.done': 'ขอบคุณ คุณได้สมัครรับข่าวสารแล้ว',
173
+ 'contact.name': 'ชื่อ',
174
+ 'contact.phone': 'โทรศัพท์',
175
+ 'contact.message': 'ข้อความ',
176
+ 'contact.send': 'ส่งข้อความ',
177
+ 'contact.done': 'ขอบคุณ เราจะติดต่อกลับโดยเร็ว',
178
+ 'account.title': 'บัญชี',
179
+ 'breadcrumbs.home': 'หน้าแรก',
180
+ },
181
+ };
182
+ /** The kit's words for `language` (its base language), English when the kit has none for it. */
183
+ export function kitStrings(language) {
184
+ const base = language.split('-')[0].toLowerCase();
185
+ return KIT_STRINGS[base] ?? KIT_STRINGS.en;
186
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * schema.org structured data beside the Product JSON-LD the server render already prints on a product page
3
+ * (runtime/seo/structured-data.ts): a BreadcrumbList for detail pages and a CollectionPage with its ItemList for a
4
+ * collection. Pure (no DOM, no React): the server render builds them from the page's data.
5
+ *
6
+ * Only what the store's data says is claimed; anything unknown is left out rather than invented.
7
+ */
8
+ import type { JsonLd } from '../runtime/seo/structured-data.js';
9
+ export type { JsonLd };
10
+ export { productJsonLd, serializeJsonLd, jsonLdTag } from '../runtime/seo/structured-data.js';
11
+ /** `path` against `origin`, only when the result is an absolute http(s) URL on that origin. */
12
+ export declare function absoluteOn(origin: string, path: string): string;
13
+ /** One crumb: a name and, except for the current page, a URL. */
14
+ export interface Crumb {
15
+ name: string;
16
+ url?: string;
17
+ }
18
+ /** A BreadcrumbList from Home → … → the current page, or null with fewer than two named crumbs. */
19
+ export declare function breadcrumbJsonLd(crumbs: readonly Crumb[]): JsonLd | null;
20
+ /** A CollectionPage whose main entity lists the collection's products (first page, at most 24), or null without a title. */
21
+ export declare function collectionJsonLd(collection: {
22
+ title?: string | null;
23
+ description?: string | null;
24
+ products?: readonly {
25
+ handle: string;
26
+ title?: string;
27
+ }[];
28
+ } | null | undefined, ctx: {
29
+ url: string;
30
+ origin: string;
31
+ }): JsonLd | null;
@@ -0,0 +1,57 @@
1
+ export { productJsonLd, serializeJsonLd, jsonLdTag } from '../runtime/seo/structured-data.js';
2
+ const SCHEMA = 'https://schema.org';
3
+ const MAX_ITEMS = 24;
4
+ const text = (v) => (typeof v === 'string' ? v.trim() : '');
5
+ /** `path` against `origin`, only when the result is an absolute http(s) URL on that origin. */
6
+ export function absoluteOn(origin, path) {
7
+ try {
8
+ const u = new URL(path, origin);
9
+ return /^https?:$/.test(u.protocol) && u.origin === new URL(origin).origin ? u.toString() : '';
10
+ }
11
+ catch {
12
+ return '';
13
+ }
14
+ }
15
+ /** A BreadcrumbList from Home → … → the current page, or null with fewer than two named crumbs. */
16
+ export function breadcrumbJsonLd(crumbs) {
17
+ const named = crumbs.filter((c) => text(c.name));
18
+ if (named.length < 2)
19
+ return null;
20
+ return {
21
+ '@context': SCHEMA,
22
+ '@type': 'BreadcrumbList',
23
+ itemListElement: named.map((c, i) => ({
24
+ '@type': 'ListItem',
25
+ position: i + 1,
26
+ name: text(c.name),
27
+ ...(c.url ? { item: c.url } : {}),
28
+ })),
29
+ };
30
+ }
31
+ /** A CollectionPage whose main entity lists the collection's products (first page, at most 24), or null without a title. */
32
+ export function collectionJsonLd(collection, ctx) {
33
+ const name = text(collection?.title);
34
+ if (!collection || !name)
35
+ return null;
36
+ const description = text(collection.description);
37
+ const items = (collection.products ?? [])
38
+ .slice(0, MAX_ITEMS)
39
+ .map((p) => ({ url: absoluteOn(ctx.origin, `/products/${encodeURIComponent(p.handle)}`), name: text(p.title) }))
40
+ .filter((p) => p.url);
41
+ return {
42
+ '@context': SCHEMA,
43
+ '@type': 'CollectionPage',
44
+ name,
45
+ url: ctx.url,
46
+ ...(description ? { description } : {}),
47
+ ...(items.length
48
+ ? {
49
+ mainEntity: {
50
+ '@type': 'ItemList',
51
+ numberOfItems: items.length,
52
+ itemListElement: items.map((p, i) => ({ '@type': 'ListItem', position: i + 1, url: p.url, ...(p.name ? { name: p.name } : {}) })),
53
+ },
54
+ }
55
+ : {}),
56
+ };
57
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Declaring a headless theme: its sections and blocks with their settings schema, and the theme itself.
3
+ *
4
+ * const hero = defineSection({
5
+ * type: 'hero', title: 'Hero', settings: { heading: field.text('After dark', { label: 'Heading' }) },
6
+ * presets: [{ name: 'Hero' }],
7
+ * ai: ai.hero({ heading: 'heading' }),
8
+ * component: ({ settings }) => <section><h1>{settings.heading}</h1></section>,
9
+ * })
10
+ * export default defineTheme({ name: 'Aurora', sections: [header, hero, footer], Layout })
11
+ *
12
+ * A section component receives `{ settings, blocks }`: every setting resolved against its schema (defaults filled,
13
+ * legacy values mapped, types coerced; a resource setting is its handle, for `useMenu` / `useCollection` /
14
+ * `useProduct` / `<Image>`), and its blocks in order, each with its own resolved settings. The section renderer
15
+ * wraps each section in its `data-tq-node` element, and the canvas applies live edits to these props.
16
+ */
17
+ import type { ComponentType, ReactNode } from 'react';
18
+ import { type Fields, type HandlesOf, type Schema, type SettingsOf } from '../sdk/schema.js';
19
+ import type { SectionZone, ThemeDefinition, ThemeSection } from '../sdk/theme.js';
20
+ import type { AiRole } from './ai.js';
21
+ /** A section's or block's settings as its component receives them. */
22
+ export type SettingsFor<F extends Fields> = SettingsOf<Schema<F>> & HandlesOf<Schema<F>>;
23
+ /** One block of a section, in the merchant's order. */
24
+ export interface BlockInstance {
25
+ type: string;
26
+ settings: Record<string, unknown>;
27
+ }
28
+ export interface SectionComponentProps<F extends Fields = Fields> {
29
+ settings: SettingsFor<F>;
30
+ blocks: BlockInstance[];
31
+ }
32
+ /** A block definition (`defineBlock`): a settings schema that nests in sections. */
33
+ export type BlockSchema<F extends Fields = Fields> = Schema<F> & {
34
+ readonly ai?: AiRole | readonly AiRole[];
35
+ };
36
+ /** Declare a block: its persisted type, its settings, and the sections it may be placed in. */
37
+ export declare function defineBlock<const F extends Fields>(def: {
38
+ type: string;
39
+ title: string;
40
+ description?: string;
41
+ settings: F;
42
+ parents?: readonly string[];
43
+ requires?: readonly string[];
44
+ }): BlockSchema<F>;
45
+ export interface SectionPresetDef {
46
+ name: string;
47
+ settings?: Record<string, unknown>;
48
+ blocks?: {
49
+ type: string;
50
+ settings?: Record<string, unknown>;
51
+ }[];
52
+ }
53
+ export interface SectionDefinition<F extends Fields> {
54
+ /** The persisted section type: never changes once stores have saved it. */
55
+ type: string;
56
+ title: string;
57
+ /** One line for the editor's "Add section" picker. */
58
+ description?: string;
59
+ /** The picker group. */
60
+ category?: string;
61
+ /** Where the page places it: the header zone, the page body (default), the footer zone. */
62
+ zone?: SectionZone;
63
+ settings: F;
64
+ /** The blocks this section accepts. */
65
+ blocks?: readonly BlockSchema[];
66
+ /** "Add section" starting points; `presets[0]` is what the editor previews. */
67
+ presets?: readonly SectionPresetDef[];
68
+ /** Route kinds the section needs (`product`, `collection`, `cart`, …): offered only on those templates. */
69
+ requires?: readonly string[];
70
+ /** The roles it plays for Tanqory AI (`ai.hero`, `ai.headerMenu`, …). */
71
+ ai?: AiRole | readonly AiRole[];
72
+ component: ComponentType<SectionComponentProps<F>>;
73
+ }
74
+ /** A section as the runtime and the build read it. */
75
+ export type HeadlessSection<F extends Fields = Fields> = ThemeSection<SectionComponentProps<F>> & {
76
+ readonly ai?: AiRole | readonly AiRole[];
77
+ readonly headless: true;
78
+ };
79
+ /** Declare a section of a headless theme. */
80
+ export declare function defineSection<const F extends Fields>(def: SectionDefinition<F>): HeadlessSection<F>;
81
+ export interface HeadlessThemeDefinition {
82
+ name: string;
83
+ /** Every section, in the editor picker's order. A section of type `not-found` renders the 404 body. */
84
+ sections: readonly HeadlessSection<any>[];
85
+ /** The page layout around the sections (the runtime renders header zone → `<main id="main">` → footer zone inside it); a place for `<CartDrawer>` and `<ConsentBanner>`. */
86
+ Layout?: ComponentType<{
87
+ children: ReactNode;
88
+ }>;
89
+ /** Wraps every page and the editor's single-section preview. */
90
+ Provider?: ThemeDefinition['Provider'];
91
+ /** Words for the breadcrumb trail; the kit's strings by default. */
92
+ labels?: ThemeDefinition['labels'];
93
+ /** External stylesheets every page loads (web fonts). */
94
+ stylesheets?: readonly string[];
95
+ /** English words the theme ships in defaults and presets, rendered in the page's language (`copy.*` locale keys). */
96
+ shippedCopy?: ThemeDefinition['shippedCopy'];
97
+ }
98
+ /** Declare a headless theme. */
99
+ export declare function defineTheme(def: HeadlessThemeDefinition): ThemeDefinition;