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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -10
  3. package/dist/abi/canvas-live.d.ts +72 -0
  4. package/dist/abi/canvas-live.js +159 -0
  5. package/dist/abi/cart.d.ts +60 -0
  6. package/dist/abi/cart.js +396 -0
  7. package/dist/abi/convert.d.ts +360 -0
  8. package/dist/abi/convert.js +1330 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +213 -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 +264 -0
  16. package/dist/abi/page-data.js +746 -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 +46 -0
  30. package/dist/abi/wire.js +114 -0
  31. package/dist/build.d.ts +121 -0
  32. package/dist/build.js +401 -0
  33. package/dist/chunks.d.ts +23 -0
  34. package/dist/chunks.js +41 -0
  35. package/dist/client.d.ts +26 -0
  36. package/dist/client.js +101 -0
  37. package/dist/contract.d.ts +6 -0
  38. package/dist/contract.js +6 -0
  39. package/dist/headless/ai.d.ts +132 -0
  40. package/dist/headless/ai.js +99 -0
  41. package/dist/headless/hooks.d.ts +276 -0
  42. package/dist/headless/hooks.js +544 -0
  43. package/dist/headless/i18n.d.ts +13 -0
  44. package/dist/headless/i18n.js +45 -0
  45. package/dist/headless/index.d.ts +44 -0
  46. package/dist/headless/index.js +48 -0
  47. package/dist/headless/lazy-component.d.ts +72 -0
  48. package/dist/headless/lazy-component.js +225 -0
  49. package/dist/headless/lazy-section.d.ts +38 -0
  50. package/dist/headless/lazy-section.js +97 -0
  51. package/dist/headless/model.d.ts +73 -0
  52. package/dist/headless/model.js +115 -0
  53. package/dist/headless/money.d.ts +17 -0
  54. package/dist/headless/money.js +63 -0
  55. package/dist/headless/page.d.ts +45 -0
  56. package/dist/headless/page.js +53 -0
  57. package/dist/headless/platform.d.ts +55 -0
  58. package/dist/headless/platform.js +77 -0
  59. package/dist/headless/primitives/cart.d.ts +90 -0
  60. package/dist/headless/primitives/cart.js +153 -0
  61. package/dist/headless/primitives/collection.d.ts +68 -0
  62. package/dist/headless/primitives/collection.js +80 -0
  63. package/dist/headless/primitives/product.d.ts +101 -0
  64. package/dist/headless/primitives/product.js +117 -0
  65. package/dist/headless/primitives/storefront.d.ts +106 -0
  66. package/dist/headless/primitives/storefront.js +187 -0
  67. package/dist/headless/primitives/util.d.ts +19 -0
  68. package/dist/headless/primitives/util.js +42 -0
  69. package/dist/headless/strings.d.ts +9 -0
  70. package/dist/headless/strings.js +198 -0
  71. package/dist/headless/structured-data.d.ts +31 -0
  72. package/dist/headless/structured-data.js +57 -0
  73. package/dist/headless/tanqory-money.generated.d.ts +493 -0
  74. package/dist/headless/tanqory-money.generated.js +507 -0
  75. package/dist/headless/theme.d.ts +109 -0
  76. package/dist/headless/theme.js +62 -0
  77. package/dist/index.d.ts +21 -0
  78. package/dist/index.js +21 -553
  79. package/dist/runtime/data/StoreProvider.d.ts +84 -0
  80. package/dist/runtime/data/StoreProvider.js +380 -0
  81. package/dist/runtime/data/handle.d.ts +14 -0
  82. package/dist/runtime/data/handle.js +16 -0
  83. package/dist/runtime/data/routes.d.ts +87 -0
  84. package/dist/runtime/data/routes.js +158 -0
  85. package/dist/runtime/data/to-ui.d.ts +286 -0
  86. package/dist/runtime/data/to-ui.js +1009 -0
  87. package/dist/runtime/entries/register.d.ts +9 -0
  88. package/dist/runtime/entries/register.js +9 -0
  89. package/dist/runtime/entries/sections.d.ts +16 -0
  90. package/dist/runtime/entries/sections.js +19 -0
  91. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  92. package/dist/runtime/kit/SectionTree.js +100 -0
  93. package/dist/runtime/kit/analytics.d.ts +63 -0
  94. package/dist/runtime/kit/analytics.js +250 -0
  95. package/dist/runtime/kit/cart.d.ts +222 -0
  96. package/dist/runtime/kit/cart.js +545 -0
  97. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  98. package/dist/runtime/kit/composition.js +3 -0
  99. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  100. package/dist/runtime/kit/config.js +6 -0
  101. package/dist/runtime/kit/consent.d.ts +29 -0
  102. package/dist/runtime/kit/consent.js +159 -0
  103. package/dist/runtime/kit/contract/content.d.ts +213 -0
  104. package/dist/runtime/kit/contract/content.js +119 -0
  105. package/dist/runtime/kit/contract/field-types.d.ts +360 -0
  106. package/dist/runtime/kit/contract/field-types.js +216 -0
  107. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  108. package/dist/runtime/kit/contract/groups.js +402 -0
  109. package/dist/runtime/kit/contract/index.d.ts +33 -0
  110. package/dist/runtime/kit/contract/index.js +33 -0
  111. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  112. package/dist/runtime/kit/contract/transform.js +133 -0
  113. package/dist/runtime/kit/contract/validate.d.ts +77 -0
  114. package/dist/runtime/kit/contract/validate.js +520 -0
  115. package/dist/runtime/kit/data.d.ts +732 -0
  116. package/dist/runtime/kit/data.js +1131 -0
  117. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  118. package/dist/runtime/kit/defineSection.js +10 -0
  119. package/dist/runtime/kit/dynamic-source.d.ts +118 -0
  120. package/dist/runtime/kit/dynamic-source.js +311 -0
  121. package/dist/runtime/kit/index.d.ts +24 -0
  122. package/dist/runtime/kit/index.js +24 -0
  123. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  124. package/dist/runtime/kit/jsx-to-json.js +28 -0
  125. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  126. package/dist/runtime/kit/mount.js +124 -0
  127. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  128. package/dist/runtime/kit/registry.js +12 -0
  129. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  130. package/dist/runtime/kit/ssg.js +56 -0
  131. package/dist/runtime/kit/storefront.d.ts +652 -0
  132. package/dist/runtime/kit/storefront.js +723 -0
  133. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  134. package/dist/runtime/kit/theme-context.js +25 -0
  135. package/dist/runtime/kit/types.d.ts +155 -0
  136. package/dist/runtime/kit/types.js +1 -0
  137. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  138. package/dist/runtime/platform/TrackingPixels.js +63 -0
  139. package/dist/runtime/platform/environment.d.ts +68 -0
  140. package/dist/runtime/platform/environment.js +85 -0
  141. package/dist/runtime/platform/locale.d.ts +27 -0
  142. package/dist/runtime/platform/locale.js +42 -0
  143. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  144. package/dist/runtime/platform/route-analytics.js +72 -0
  145. package/dist/runtime/platform/safe-href.d.ts +25 -0
  146. package/dist/runtime/platform/safe-href.js +69 -0
  147. package/dist/runtime/platform/safe-values.d.ts +37 -0
  148. package/dist/runtime/platform/safe-values.js +140 -0
  149. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  150. package/dist/runtime/render/SectionRenderer.js +199 -0
  151. package/dist/runtime/render/listing-query.d.ts +52 -0
  152. package/dist/runtime/render/listing-query.js +122 -0
  153. package/dist/runtime/render/localized-copy.d.ts +86 -0
  154. package/dist/runtime/render/localized-copy.js +129 -0
  155. package/dist/runtime/render/product-listing.d.ts +11 -0
  156. package/dist/runtime/render/product-listing.js +243 -0
  157. package/dist/runtime/render/resolved.d.ts +47 -0
  158. package/dist/runtime/render/resolved.js +80 -0
  159. package/dist/runtime/render/section-actions.d.ts +67 -0
  160. package/dist/runtime/render/section-actions.js +205 -0
  161. package/dist/runtime/render/starter.d.ts +11 -0
  162. package/dist/runtime/render/starter.js +96 -0
  163. package/dist/runtime/seo/head.d.ts +115 -0
  164. package/dist/runtime/seo/head.js +281 -0
  165. package/dist/runtime/seo/structured-data.d.ts +83 -0
  166. package/dist/runtime/seo/structured-data.js +252 -0
  167. package/dist/runtime/shell/PageShell.d.ts +18 -0
  168. package/dist/runtime/shell/PageShell.js +118 -0
  169. package/dist/runtime/shell/RuntimeBridge.d.ts +18 -0
  170. package/dist/runtime/shell/RuntimeBridge.js +124 -0
  171. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  172. package/dist/runtime/shell/overlay-state.js +59 -0
  173. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  174. package/dist/runtime/shell/preview-mode.js +11 -0
  175. package/dist/runtime/shell/spa-router.d.ts +14 -0
  176. package/dist/runtime/shell/spa-router.js +76 -0
  177. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  178. package/dist/runtime/shell/url-redirects.js +37 -0
  179. package/dist/runtime/slots.d.ts +74 -0
  180. package/dist/runtime/slots.js +16 -0
  181. package/dist/runtime.d.ts +34 -0
  182. package/dist/runtime.js +40 -0
  183. package/dist/sdk/app-block.d.ts +29 -0
  184. package/dist/sdk/app-block.js +22 -0
  185. package/dist/sdk/font-hooks.d.ts +7 -0
  186. package/dist/sdk/font-hooks.js +21 -0
  187. package/dist/sdk/fonts.d.ts +144 -0
  188. package/dist/sdk/fonts.js +241 -0
  189. package/dist/sdk/index.d.ts +32 -0
  190. package/dist/sdk/index.js +36 -0
  191. package/dist/sdk/motion-hooks.d.ts +23 -0
  192. package/dist/sdk/motion-hooks.js +46 -0
  193. package/dist/sdk/motion.d.ts +78 -0
  194. package/dist/sdk/motion.js +292 -0
  195. package/dist/sdk/referrals.d.ts +62 -0
  196. package/dist/sdk/referrals.js +20 -0
  197. package/dist/sdk/rewards.d.ts +85 -0
  198. package/dist/sdk/rewards.js +29 -0
  199. package/dist/sdk/runtime-context.d.ts +230 -0
  200. package/dist/sdk/runtime-context.js +73 -0
  201. package/dist/sdk/schema.d.ts +249 -0
  202. package/dist/sdk/schema.js +168 -0
  203. package/dist/sdk/server-render.d.ts +8 -0
  204. package/dist/sdk/server-render.js +12 -0
  205. package/dist/sdk/store-lookup.d.ts +32 -0
  206. package/dist/sdk/store-lookup.js +48 -0
  207. package/dist/sdk/store.d.ts +164 -0
  208. package/dist/sdk/store.js +5 -0
  209. package/dist/sdk/sx.d.ts +45 -0
  210. package/dist/sdk/sx.js +117 -0
  211. package/dist/sdk/theme.d.ts +212 -0
  212. package/dist/sdk/theme.js +27 -0
  213. package/dist/sdk/types.d.ts +789 -0
  214. package/dist/sdk/types.js +7 -0
  215. package/dist/server.d.ts +112 -0
  216. package/dist/server.js +589 -0
  217. package/dist/vite-chunks.d.ts +10 -0
  218. package/dist/vite-chunks.js +44 -0
  219. package/docs/headless-api.md +250 -0
  220. package/package.json +72 -26
  221. package/dist/index.js.map +0 -1
  222. package/dist/ssg-BZ5FYTw7.js +0 -1802
  223. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  224. package/dist/ssg.js +0 -8
  225. package/dist/ssg.js.map +0 -1
  226. package/dist/types/cart.d.ts +0 -86
  227. package/dist/types/data.d.ts +0 -357
  228. package/dist/types/dynamic-source.d.ts +0 -84
  229. package/dist/types/editor.d.ts +0 -5
  230. package/dist/types/index.d.ts +0 -20
  231. package/dist/types/preview-bridge.d.ts +0 -9
  232. package/dist/types/storefront.d.ts +0 -333
  233. package/dist/types/types.d.ts +0 -44
@@ -1,4 +1,4 @@
1
- import type { SectionDef } from './types';
1
+ import type { SectionDef } from './types.js';
2
2
  /**
3
3
  * Declare a section (a top-level, editor-placeable unit). Attaches `blockName`
4
4
  * to the component so a JSX composition (`<Hero/>`) can be walked back into the
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Declare a section (a top-level, editor-placeable unit). Attaches `blockName`
3
+ * to the component so a JSX composition (`<Hero/>`) can be walked back into the
4
+ * content tree (see jsx-to-json.ts).
5
+ */
6
+ export function defineSection(def) {
7
+ ;
8
+ def.component.blockName = def.name;
9
+ return def;
10
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Dynamic sources — bind a section/block setting to a live metafield, resource
3
+ * property, or metaobject field (the commerce standard "Insert dynamic source", the ⛁ icon).
4
+ *
5
+ * A setting value is normally a primitive. When the merchant connects a dynamic
6
+ * source the editor stores a `{ '@source': '<path>' }` object instead, and the
7
+ * theme resolves it at render against the CURRENT page resource:
8
+ *
9
+ * product.metafields.custom.subtitle → the page product's metafield
10
+ * collection.metafields.custom.tagline → the page collection's metafield
11
+ * page.metafields.custom.banner → the page's metafield (page templates)
12
+ * article.metafields.custom.byline → the article's metafield (article templates)
13
+ * shop.metafields.custom.announcement → the store's metafield (any page)
14
+ * product.title / shop.name → a plain resource property
15
+ * metaobject:size:medium.label → a metaobject field (type:handle.key)
16
+ * metaobject.title → a field of the page's own entry (metaobject page templates)
17
+ *
18
+ * The path grammar follows the standard commerce object model.
19
+ * synchronous against already-loaded resources — the provider is responsible
20
+ * for loading the bound metafields (see `collectBoundIdentifiers`).
21
+ */
22
+ import { type ReactNode } from 'react';
23
+ import type { Product, Collection, Page, MetaobjectPage } from './data.js';
24
+ import type { Shop, Metaobject, Article } from './storefront.js';
25
+ /** A setting bound to a dynamic source instead of a literal value. */
26
+ export interface BoundSource {
27
+ '@source': string;
28
+ }
29
+ export type Bound<T> = T | BoundSource;
30
+ /** Text with several sources in it: `{ '@template': 'By {{ product.vendor }}' }` (contract `isBoundTemplateValue`). */
31
+ export interface BoundTemplate {
32
+ '@template': string;
33
+ }
34
+ export declare function isBoundTemplate(v: unknown): v is BoundTemplate;
35
+ /** The template with every token replaced by its source's text on this page ('' where a source has none). */
36
+ export declare function resolveBoundTemplate(template: string, ctx: ResourceContextValue): string;
37
+ export declare function isBoundSource(v: unknown): v is BoundSource;
38
+ /** Resources a dynamic source can read from on the current page. */
39
+ export interface ResourceContextValue {
40
+ shop?: (Shop & {
41
+ metafields?: Record<string, string | null>;
42
+ }) | null;
43
+ product?: (Product & {
44
+ metafields?: Record<string, string | null>;
45
+ }) | null;
46
+ collection?: (Collection & {
47
+ metafields?: Record<string, string | null>;
48
+ }) | null;
49
+ /** The route's page on page templates (storefront-query rev 2.45, O4). */
50
+ page?: (Page & {
51
+ metafields?: Record<string, string | null>;
52
+ }) | null;
53
+ /** The route's article on article templates (storefront-query rev 2.45, O4). */
54
+ article?: (Article & {
55
+ metafields?: Record<string, string | null>;
56
+ }) | null;
57
+ /** Synchronous metaobject lookup (type, handle) → entry, from a warmed cache. */
58
+ metaobject?: (type: string, handle: string) => Metaobject | null;
59
+ /** The route's entry on a metaobject page template (`/pages/<definition>/<entry>`): what `metaobject.<field>` reads. */
60
+ metaobjectPage?: MetaobjectPage | null;
61
+ }
62
+ /**
63
+ * Provide the current page's resources to dynamic sources. Wrap the page once
64
+ * (the layout does this). `shop` falls back to the data source so shop-level
65
+ * bindings work on every page without extra wiring.
66
+ */
67
+ export declare function DynamicSourceProvider({ value, children, }: {
68
+ value: ResourceContextValue;
69
+ children: ReactNode;
70
+ }): JSX.Element;
71
+ export declare function useResourceContext(): ResourceContextValue;
72
+ /**
73
+ * Text that names dynamic sources as plain text (`Goes well with {{ product.title }}`): a default the editor has not
74
+ * connected yet, a starter template, a section preview. Read with each source of this page ('' where it has none),
75
+ * exactly as the connected `{ '@template' }` value reads; never the literal braces. Text whose tokens are not all source
76
+ * paths (the contract's `isBoundTemplateValue`), or that names none, is returned as it is.
77
+ */
78
+ export declare function sourceText(text: string, ctx: ResourceContextValue): string;
79
+ /**
80
+ * `sourceText` against the page's resources, for a section component. Reads the resource context the page provides
81
+ * (StoreProvider: the route's resource and the shop), and works without one (a section rendered on its own).
82
+ */
83
+ export declare function useSourceText(text: string): string;
84
+ /** The resources a `@source` path may start with. */
85
+ export declare const BOUND_SOURCE_ROOTS: readonly ["product", "collection", "page", "article", "shop", "metaobject"];
86
+ /** The `@source` grammar a saved setting may carry (the contract owns it; the validator refuses anything else). */
87
+ export { BOUND_SOURCE_PATTERN } from './contract/field-types.js';
88
+ /** Resolve a `@source` path against a resource context. Returns null if unbound. */
89
+ export declare function resolveBoundSource(source: string, ctx: ResourceContextValue): string | null;
90
+ /**
91
+ * Resolve every bound value of one saved settings object against the page's resources, before the section's data
92
+ * binding sees it (O4: the kit does this for every section and block, so no section needs its own code). A plain
93
+ * value passes through. A bound value becomes the live text; one with no value on this resource becomes '' (the
94
+ * setting shows empty, as a merchant who connected an empty metafield expects — never the setting's default copy),
95
+ * except a number setting, which then falls back to its default. Returns the same object when nothing is bound.
96
+ */
97
+ export declare function resolveBoundSettings(settings: Record<string, unknown> | undefined, ctx: ResourceContextValue, controlOf?: (key: string) => string | undefined): Record<string, unknown> | undefined;
98
+ /**
99
+ * Resolve a possibly-bound setting value for the current page.
100
+ * const heading = useBound(attributes.heading) // string | the literal | null
101
+ * A plain value passes through unchanged; a `{ '@source' }` object resolves to
102
+ * the live value (or null when the source has no value on this resource).
103
+ */
104
+ export declare function useBound(value: unknown): unknown;
105
+ /** Convenience: resolve to a string (empty when null/unbound-empty). */
106
+ export declare function useBoundText(value: unknown, fallback?: string): string;
107
+ /**
108
+ * Walk a content tree's section/block settings and collect every bound metafield
109
+ * identifier, grouped by resource. The provider uses this to request exactly the
110
+ * metafields the page binds (the live product/collection query takes identifiers).
111
+ */
112
+ export declare function collectBoundIdentifiers(nodes: Array<{
113
+ settings?: Record<string, unknown>;
114
+ blocks?: unknown[];
115
+ }> | undefined): Record<'product' | 'collection' | 'page' | 'article' | 'shop', Array<{
116
+ namespace: string;
117
+ key: string;
118
+ }>>;
@@ -0,0 +1,311 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Dynamic sources — bind a section/block setting to a live metafield, resource
4
+ * property, or metaobject field (the commerce standard "Insert dynamic source", the ⛁ icon).
5
+ *
6
+ * A setting value is normally a primitive. When the merchant connects a dynamic
7
+ * source the editor stores a `{ '@source': '<path>' }` object instead, and the
8
+ * theme resolves it at render against the CURRENT page resource:
9
+ *
10
+ * product.metafields.custom.subtitle → the page product's metafield
11
+ * collection.metafields.custom.tagline → the page collection's metafield
12
+ * page.metafields.custom.banner → the page's metafield (page templates)
13
+ * article.metafields.custom.byline → the article's metafield (article templates)
14
+ * shop.metafields.custom.announcement → the store's metafield (any page)
15
+ * product.title / shop.name → a plain resource property
16
+ * metaobject:size:medium.label → a metaobject field (type:handle.key)
17
+ * metaobject.title → a field of the page's own entry (metaobject page templates)
18
+ *
19
+ * The path grammar follows the standard commerce object model.
20
+ * synchronous against already-loaded resources — the provider is responsible
21
+ * for loading the bound metafields (see `collectBoundIdentifiers`).
22
+ */
23
+ import { createContext, useContext } from 'react';
24
+ import { useData } from './data.js';
25
+ import { isBoundTemplateValue } from './contract/field-types.js';
26
+ export function isBoundTemplate(v) {
27
+ return typeof v === 'object' && v !== null && typeof v['@template'] === 'string';
28
+ }
29
+ const TEMPLATE_TOKEN = /\{\{\s*([^{}\s]+)\s*\}\}/g;
30
+ /** The template with every token replaced by its source's text on this page ('' where a source has none). */
31
+ export function resolveBoundTemplate(template, ctx) {
32
+ return template.replace(TEMPLATE_TOKEN, (_, path) => resolveBoundSource(path, ctx) ?? '');
33
+ }
34
+ export function isBoundSource(v) {
35
+ return (typeof v === 'object' &&
36
+ v !== null &&
37
+ typeof v['@source'] === 'string');
38
+ }
39
+ const ResourceContext = createContext({});
40
+ /**
41
+ * Provide the current page's resources to dynamic sources. Wrap the page once
42
+ * (the layout does this). `shop` falls back to the data source so shop-level
43
+ * bindings work on every page without extra wiring.
44
+ */
45
+ export function DynamicSourceProvider({ value, children, }) {
46
+ return _jsx(ResourceContext.Provider, { value: value, children: children });
47
+ }
48
+ export function useResourceContext() {
49
+ const data = useData();
50
+ const ctx = useContext(ResourceContext);
51
+ // Shop is always available from the data source; an explicit provider value
52
+ // (carrying loaded shop metafields) takes precedence.
53
+ return { shop: data.shop, ...ctx };
54
+ }
55
+ const METAOBJECT_RE = /^metaobject:([^:]+):([^.]+)\.(.+)$/;
56
+ /**
57
+ * Text that names dynamic sources as plain text (`Goes well with {{ product.title }}`): a default the editor has not
58
+ * connected yet, a starter template, a section preview. Read with each source of this page ('' where it has none),
59
+ * exactly as the connected `{ '@template' }` value reads; never the literal braces. Text whose tokens are not all source
60
+ * paths (the contract's `isBoundTemplateValue`), or that names none, is returned as it is.
61
+ */
62
+ export function sourceText(text, ctx) {
63
+ return typeof text === 'string' && text.includes('{{') && isBoundTemplateValue({ '@template': text }) ? resolveBoundTemplate(text, ctx) : text;
64
+ }
65
+ /**
66
+ * `sourceText` against the page's resources, for a section component. Reads the resource context the page provides
67
+ * (StoreProvider: the route's resource and the shop), and works without one (a section rendered on its own).
68
+ */
69
+ export function useSourceText(text) {
70
+ return sourceText(text, useContext(ResourceContext));
71
+ }
72
+ /** The resources a `@source` path may start with. */
73
+ export const BOUND_SOURCE_ROOTS = ['product', 'collection', 'page', 'article', 'shop', 'metaobject'];
74
+ /** The `@source` grammar a saved setting may carry (the contract owns it; the validator refuses anything else). */
75
+ export { BOUND_SOURCE_PATTERN } from './contract/field-types.js';
76
+ /** Resolve a `@source` path against a resource context. Returns null if unbound. */
77
+ export function resolveBoundSource(source, ctx) {
78
+ const mo = source.match(METAOBJECT_RE);
79
+ if (mo) {
80
+ const [, type, handle, field] = mo;
81
+ const obj = ctx.metaobject?.(type, handle);
82
+ return obj?.values?.[field] ?? null;
83
+ }
84
+ const parts = source.split('.');
85
+ const root = parts[0];
86
+ // A metaobject page's own entry: `metaobject.<field>` is one of its fields; `metaobject.url` (when no field is so
87
+ // named) its page. A reference field holds `{url}` (a file) or `{handle}` (a resource): the value a setting takes.
88
+ if (root === 'metaobject')
89
+ return parts.length === 2 ? metaobjectField(ctx.metaobjectPage, parts[1]) : null;
90
+ const resource = root === 'product'
91
+ ? ctx.product
92
+ : root === 'collection'
93
+ ? ctx.collection
94
+ : root === 'page'
95
+ ? ctx.page
96
+ : root === 'article'
97
+ ? ctx.article
98
+ : root === 'shop'
99
+ ? ctx.shop
100
+ : null;
101
+ if (!resource)
102
+ return null;
103
+ if (parts[1] === 'metafields') {
104
+ const ns = parts[2];
105
+ const key = parts.slice(3).join('.');
106
+ if (!ns || !key)
107
+ return null;
108
+ return resource.metafields?.[`${ns}.${key}`] ?? null;
109
+ }
110
+ // A property the editor's picker names that the record spells otherwise (a link, an image, the content).
111
+ const derived = derivedProperty(root, resource, parts[1] ?? '');
112
+ if (derived !== undefined)
113
+ return derived;
114
+ // Plain resource property: product.title, shop.name, collection.title… (a scalar only — never "[object Object]")
115
+ const direct = resource[parts[1]];
116
+ return typeof direct === 'string' || typeof direct === 'number' || typeof direct === 'boolean' ? String(direct) : null;
117
+ }
118
+ /** One field of the page's metaobject entry as a setting's value (see resolveBoundSource). */
119
+ function metaobjectField(entry, key) {
120
+ if (!entry || !key)
121
+ return null;
122
+ const fields = entry.fields;
123
+ if (!Object.prototype.hasOwnProperty.call(fields, key))
124
+ return key === 'url' ? entry.url || null : key === 'handle' ? entry.handle : null;
125
+ const v = fields[key];
126
+ if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean')
127
+ return String(v);
128
+ if (Array.isArray(v)) {
129
+ const items = v.map((x) => (x && typeof x === 'object' ? (urlOf(x) ?? (typeof x.handle === 'string' ? x.handle : null)) : typeof x === 'string' ? x : null)).filter((x) => !!x);
130
+ return items.length ? items.join(',') : null;
131
+ }
132
+ if (v && typeof v === 'object') {
133
+ const handle = v.handle;
134
+ return urlOf(v) ?? (typeof handle === 'string' && handle ? handle : null);
135
+ }
136
+ return null;
137
+ }
138
+ const urlOf = (v) => {
139
+ if (!v || typeof v !== 'object')
140
+ return null;
141
+ const u = v.url ?? v.src;
142
+ return typeof u === 'string' && u ? u : null;
143
+ };
144
+ /**
145
+ * The record's own value for a property of the source picker (studio-api DYNAMIC_SOURCE_RESOURCES), or undefined
146
+ * when the name is a plain field of the record: `url` is the resource's storefront path, `featured_image` / `image`
147
+ * its image URL, `content` its body, `collections` a product's collection handles (comma-separated, the list
148
+ * pickers' value shape).
149
+ */
150
+ function derivedProperty(root, r, prop) {
151
+ const handle = typeof r.handle === 'string' ? r.handle : '';
152
+ switch (prop) {
153
+ case 'url':
154
+ if (!handle)
155
+ return null;
156
+ if (root === 'product')
157
+ return `/products/${handle}`;
158
+ if (root === 'collection')
159
+ return `/collections/${handle}`;
160
+ if (root === 'page')
161
+ return `/pages/${handle}`;
162
+ if (root === 'article')
163
+ return typeof r.blogHandle === 'string' ? `/blogs/${r.blogHandle}/${handle}` : null;
164
+ return undefined;
165
+ case 'featured_image':
166
+ return urlOf(r.featuredImage ?? r.image);
167
+ case 'image':
168
+ return root === 'shop' ? undefined : urlOf(r.image ?? r.featuredImage);
169
+ case 'content': {
170
+ const html = r.contentHtml ?? r.body ?? r.bodyHtml ?? r.content;
171
+ return typeof html === 'string' ? html : null;
172
+ }
173
+ case 'collections': {
174
+ const list = Array.isArray(r.collections) ? r.collections : [];
175
+ const handles = list.map((c) => (c && typeof c === 'object' ? c.handle : null)).filter((h) => typeof h === 'string' && !!h);
176
+ return handles.length ? handles.join(',') : null;
177
+ }
178
+ default:
179
+ return undefined;
180
+ }
181
+ }
182
+ /** Field controls whose bound value must be a value of their own kind (a handle, an https URL, a hex colour). */
183
+ const KIND_CONTROLS = new Set(['product', 'collection', 'page', 'article', 'blog', 'image', 'video', 'color']);
184
+ const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
185
+ /** Field controls whose bound value is a number (the resolved text is converted; non-numeric ⇒ the default). */
186
+ const NUMBER_CONTROLS = new Set(['number', 'range']);
187
+ /**
188
+ * Resolve every bound value of one saved settings object against the page's resources, before the section's data
189
+ * binding sees it (O4: the kit does this for every section and block, so no section needs its own code). A plain
190
+ * value passes through. A bound value becomes the live text; one with no value on this resource becomes '' (the
191
+ * setting shows empty, as a merchant who connected an empty metafield expects — never the setting's default copy),
192
+ * except a number setting, which then falls back to its default. Returns the same object when nothing is bound.
193
+ */
194
+ export function resolveBoundSettings(settings, ctx, controlOf) {
195
+ if (!settings)
196
+ return settings;
197
+ let out = null;
198
+ for (const [k, v] of Object.entries(settings)) {
199
+ if (isBoundTemplate(v)) {
200
+ out ??= { ...settings };
201
+ out[k] = resolveBoundTemplate(v['@template'], ctx);
202
+ continue;
203
+ }
204
+ if (!isBoundSource(v))
205
+ continue;
206
+ out ??= { ...settings };
207
+ const text = resolveBoundSource(v['@source'], ctx);
208
+ const control = controlOf?.(k) ?? '';
209
+ // A picker setting (product, collection, page, article, image, video) or a colour takes only a value of its own
210
+ // kind: a handle / URL / hex. Anything else (an unresolved reference id) falls back to the setting's default,
211
+ // never a broken value.
212
+ if (KIND_CONTROLS.has(control)) {
213
+ const t = (text ?? '').trim();
214
+ const ok = control === 'color' ? HEX.test(t) : t !== '' && !t.startsWith('gid://') && (control !== 'image' && control !== 'video' ? true : /^https:\/\//.test(t));
215
+ if (ok)
216
+ out[k] = t;
217
+ else
218
+ delete out[k];
219
+ continue;
220
+ }
221
+ if (NUMBER_CONTROLS.has(control)) {
222
+ const n = text === null || text.trim() === '' ? NaN : Number(text);
223
+ if (Number.isFinite(n))
224
+ out[k] = n;
225
+ else
226
+ delete out[k];
227
+ }
228
+ else {
229
+ out[k] = text ?? '';
230
+ }
231
+ }
232
+ return out ?? settings;
233
+ }
234
+ /**
235
+ * Resolve a possibly-bound setting value for the current page.
236
+ * const heading = useBound(attributes.heading) // string | the literal | null
237
+ * A plain value passes through unchanged; a `{ '@source' }` object resolves to
238
+ * the live value (or null when the source has no value on this resource).
239
+ */
240
+ export function useBound(value) {
241
+ const ctx = useResourceContext();
242
+ if (!isBoundSource(value))
243
+ return value;
244
+ return resolveBoundSource(value['@source'], ctx);
245
+ }
246
+ /** Convenience: resolve to a string (empty when null/unbound-empty). */
247
+ export function useBoundText(value, fallback = '') {
248
+ const resolved = useBound(value);
249
+ if (resolved == null)
250
+ return fallback;
251
+ return typeof resolved === 'string' ? resolved : String(resolved);
252
+ }
253
+ /**
254
+ * Walk a content tree's section/block settings and collect every bound metafield
255
+ * identifier, grouped by resource. The provider uses this to request exactly the
256
+ * metafields the page binds (the live product/collection query takes identifiers).
257
+ */
258
+ export function collectBoundIdentifiers(nodes) {
259
+ const out = {
260
+ product: [],
261
+ collection: [],
262
+ page: [],
263
+ article: [],
264
+ shop: [],
265
+ };
266
+ const seen = new Set();
267
+ const visitSettings = (settings) => {
268
+ if (!settings)
269
+ return;
270
+ const paths = [];
271
+ for (const v of Object.values(settings)) {
272
+ if (isBoundSource(v))
273
+ paths.push(v['@source']);
274
+ else if (isBoundTemplate(v))
275
+ for (const m of v['@template'].matchAll(TEMPLATE_TOKEN))
276
+ paths.push(m[1]);
277
+ }
278
+ for (const path of paths) {
279
+ const parts = path.split('.');
280
+ const root = parts[0];
281
+ if (parts[1] !== 'metafields')
282
+ continue;
283
+ const namespace = parts[2];
284
+ const key = parts.slice(3).join('.');
285
+ if (!namespace || !key || !(root in out))
286
+ continue;
287
+ const dedupe = `${root}:${namespace}.${key}`;
288
+ if (seen.has(dedupe))
289
+ continue;
290
+ seen.add(dedupe);
291
+ out[root].push({ namespace, key });
292
+ }
293
+ };
294
+ // Sections + blocks may store children as an array OR an object map (the
295
+ // editor's `{ id: node }` shape) — normalize both before iterating.
296
+ const toNodes = (v) => {
297
+ if (Array.isArray(v))
298
+ return v;
299
+ if (v && typeof v === 'object')
300
+ return Object.values(v);
301
+ return [];
302
+ };
303
+ const walk = (list) => {
304
+ for (const node of toNodes(list)) {
305
+ visitSettings(node.settings);
306
+ walk(node.blocks);
307
+ }
308
+ };
309
+ walk(nodes);
310
+ return out;
311
+ }
@@ -0,0 +1,24 @@
1
+ export { defineSection } from './defineSection.js';
2
+ export { createAnalytics, getAnalytics, subscribe, type Analytics, type AnalyticsOptions, type StorefrontEventType, type StorefrontEvent, } from './analytics.js';
3
+ export { getConsent, setConsent, hasConsent, hasDecided, setBannerRequired, isBannerRequired, setConsentMode, holdConsentClosed, isConsentArmed, onConsentModeChange, getConsentMode, consentModeFromShop, onConsentChange, type Consent, type ConsentMode, } from './consent.js';
4
+ export { defineTheme, defineSettings, type ThemeConfig, type SettingsSchema } from './config.js';
5
+ export { ThemeProvider, useSettings, useT } from './theme-context.js';
6
+ export { mount, groupsFromGlob, resolvePageSections, type MountOptions } from './mount.js';
7
+ export { renderStorefrontHTML, renderSectionPreviewHTML } from './ssg.js';
8
+ export { SectionTree, usePageTree } from './SectionTree.js';
9
+ export { registerSections, getSection, allSections } from './registry.js';
10
+ export { DataProvider, useData, createMockData, createLiveData, createLiveDataFromSnapshot, formatMoney, formatMoneyWithCurrency, formatMoneyWithoutCurrency, formatMoneyWithoutTrailingZeros, imageUrl, formatDate, formatWeight, } from './data.js';
11
+ export { CartProvider, useCart } from './cart.js';
12
+ export { DynamicSourceProvider, useResourceContext, useBound, useBoundText, isBoundSource, isBoundTemplate, resolveBoundSource, resolveBoundTemplate, resolveBoundSettings, collectBoundIdentifiers, BOUND_SOURCE_PATTERN, BOUND_SOURCE_ROOTS, } from './dynamic-source.js';
13
+ export type { Bound, BoundSource, ResourceContextValue } from './dynamic-source.js';
14
+ export type { CartApi, CartLine, CartState, AddToCartInput, AppliedDiscountCode, AppliedGiftCard, } from './cart.js';
15
+ export type { LiveDataOptions, Localization, LocalizedCountry, LocalizedMarket, LocalizedCurrency, ProductOption, ProductVariant, ImageRef, QuantityRule, UnitPriceMeasurement, StoreAvailability, SellingPlan, SellingPlanOption, SellingPlanGroup, Measurement, Rating, FocalPoint, ImagePresentation, ModelSource, VideoSource, GenericFile, Recommendations, } from './data.js';
16
+ export { toRecommendations } from './data.js';
17
+ export { jsxToJSON } from './jsx-to-json.js';
18
+ export { tag, type Tag } from './composition.js';
19
+ export type { Money, Product, Collection, DataApi } from './data.js';
20
+ export type { SectionDef, SectionProps, ContentNode, PageDoc, AttrSpec, SectionPreset, SectionGroupDoc } from './types.js';
21
+ export { customerTokenStore } from './storefront.js';
22
+ export type { StorefrontExtensions, Menu, MenuItem, MenuItemType, Blog, Article, ArticleComment, ArticleComments, SearchResults, CollectionProductsPage, PredictiveSearchResults, PageInfo, Filter, Metaobject, MetaobjectField, Shop, ShopPolicy, Image as StorefrontImage, Seo, CustomerApi, Customer, CustomerAddress, CustomerAddressInput, CustomerPaymentMethod, Order, OrderTransaction, OrderGiftCard, StoreCreditAccount, OrderLineItem, AuthResult, MutationResult, } from './storefront.js';
23
+ export { CONTRACT_VERSION, KIT_COMPATIBILITY, FIELD_TYPES, FIELD_TYPE_ALIASES, EDITOR_ONLY_TYPES, UNIVERSAL_CONSTRAINTS, canonicalFieldType, fieldType, TEMPLATE_AREAS, CONTEXT_KINDS, CURRENT_CONTENT_VERSION, NODE_ID_PATTERN, NODE_NAME_MAX_LENGTH, isValidNodeName, mintNodeId, roleOf, templateContext, SECTION_ROLES, GROUP_SLOTS, GROUP_NAME_PATTERN, resolvePage, resolvePageFrom, splitPage, groupImpact, extractGroups, slotSignature, inlineSlotOf, isSectionGroupDoc, validatePage, validateGroup, toEditorShape, toRuntimeShape, ensureNodeIds, validateDocument, validateSectionContract, formatIssues, } from './contract/index.js';
24
+ export type { FieldTypeDef, FieldTypeId, FieldTypeAlias, AnyFieldType, ControlKind, ValueKind, ContractNode, ContractPageDoc, SectionContract, SectionPresetContract, AttrContract, TemplateArea, ContextKind, SectionRole, PlacementContract, GroupSlot, GroupBinding, GroupedPageDoc, GroupMap, NodeSource, SlotResolution, ResolvedPage, SplitResult, SplitOptions, ExtractOptions, ExtractReport, ExtractResult, ValidationIssue, ValidationResult, ValidationCode, SectionCatalog, ValidateOptions, Severity, EditorNode, EditorDoc, TransformReport, } from './contract/index.js';
@@ -0,0 +1,24 @@
1
+ // @tanqory/theme-kit — public API. Themes import only from here.
2
+ export { defineSection } from './defineSection.js';
3
+ export { createAnalytics, getAnalytics, subscribe, } from './analytics.js';
4
+ export { getConsent, setConsent, hasConsent, hasDecided, setBannerRequired, isBannerRequired, setConsentMode, holdConsentClosed, isConsentArmed, onConsentModeChange, getConsentMode, consentModeFromShop, onConsentChange, } from './consent.js';
5
+ export { defineTheme, defineSettings } from './config.js';
6
+ export { ThemeProvider, useSettings, useT } from './theme-context.js';
7
+ export { mount, groupsFromGlob, resolvePageSections } from './mount.js';
8
+ export { renderStorefrontHTML, renderSectionPreviewHTML } from './ssg.js';
9
+ export { SectionTree, usePageTree } from './SectionTree.js';
10
+ export { registerSections, getSection, allSections } from './registry.js';
11
+ export { DataProvider, useData, createMockData, createLiveData, createLiveDataFromSnapshot, formatMoney, formatMoneyWithCurrency, formatMoneyWithoutCurrency, formatMoneyWithoutTrailingZeros, imageUrl, formatDate, formatWeight, } from './data.js';
12
+ export { CartProvider, useCart } from './cart.js';
13
+ export { DynamicSourceProvider, useResourceContext, useBound, useBoundText, isBoundSource, isBoundTemplate, resolveBoundSource, resolveBoundTemplate, resolveBoundSettings, collectBoundIdentifiers, BOUND_SOURCE_PATTERN, BOUND_SOURCE_ROOTS, } from './dynamic-source.js';
14
+ export { toRecommendations } from './data.js';
15
+ export { jsxToJSON } from './jsx-to-json.js';
16
+ export { tag } from './composition.js';
17
+ // commerce-standard storefront extensions (live data layer): navigation menus,
18
+ // blog/articles, search, recommendations, metaobjects, shop/policies, and the
19
+ // full customer account flow. See storefront.ts.
20
+ export { customerTokenStore } from './storefront.js';
21
+ // Tanqory Theme Contract v1 — the shared agreement between theme, CMS, Editor
22
+ // and AI. Also built as its own dependency-free entry (`@tanqory/theme-kit/contract`)
23
+ // so studio-api can vendor it without an npm install.
24
+ export { CONTRACT_VERSION, KIT_COMPATIBILITY, FIELD_TYPES, FIELD_TYPE_ALIASES, EDITOR_ONLY_TYPES, UNIVERSAL_CONSTRAINTS, canonicalFieldType, fieldType, TEMPLATE_AREAS, CONTEXT_KINDS, CURRENT_CONTENT_VERSION, NODE_ID_PATTERN, NODE_NAME_MAX_LENGTH, isValidNodeName, mintNodeId, roleOf, templateContext, SECTION_ROLES, GROUP_SLOTS, GROUP_NAME_PATTERN, resolvePage, resolvePageFrom, splitPage, groupImpact, extractGroups, slotSignature, inlineSlotOf, isSectionGroupDoc, validatePage, validateGroup, toEditorShape, toRuntimeShape, ensureNodeIds, validateDocument, validateSectionContract, formatIssues, } from './contract/index.js';
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- import type { ContentNode } from './types';
2
+ import type { ContentNode } from './types.js';
3
3
  /**
4
4
  * Compile a *static* JSX composition into the canonical JSON block tree.
5
5
  *
@@ -0,0 +1,28 @@
1
+ import { Children, isValidElement } from 'react';
2
+ /**
3
+ * Compile a *static* JSX composition into the canonical JSON block tree.
4
+ *
5
+ * <Hero settings={{…}}><Button settings={{…}} /></Hero>
6
+ * → [{ type:'hero', settings:{…}, blocks:[{ type:'button', settings:{…} }] }]
7
+ *
8
+ * Only nesting + literal `settings` are read — there is no place for logic, which
9
+ * is exactly what keeps a page round-trippable by the editor. (Logic lives in
10
+ * the block components, never in a page composition.)
11
+ */
12
+ export function jsxToJSON(node) {
13
+ return Children.toArray(node).flatMap((el) => {
14
+ if (!isValidElement(el))
15
+ return [];
16
+ const name = el.type?.blockName;
17
+ if (!name)
18
+ return [];
19
+ const props = el.props;
20
+ const out = { type: name };
21
+ if (props.settings)
22
+ out.settings = props.settings;
23
+ const blocks = jsxToJSON(props.children);
24
+ if (blocks.length)
25
+ out.blocks = blocks;
26
+ return [out];
27
+ });
28
+ }
@@ -1,12 +1,20 @@
1
- import { type DataApi } from './data';
1
+ import { type DataApi } from './data.js';
2
+ import type { PageDoc, ContentNode } from './types.js';
3
+ import { type GroupMap } from './contract/groups.js';
2
4
  type GlobMap = Record<string, unknown>;
3
5
  export interface MountOptions {
4
- /** import.meta.glob('./sections/*.tsx', { eager: true }) — run in the THEME. */
6
+ /** import.meta.glob('../../../../themes/nova/app/platform/tanqory/sections/*.tsx', { eager: true }) — run in the THEME. */
5
7
  sections: GlobMap;
6
- /** import.meta.glob('./templates/*.json', { eager: true }). */
8
+ /** import.meta.glob('../../../../themes/nova/app/platform/tanqory/templates/*.json', { eager: true }). */
7
9
  pages: GlobMap;
8
- /** import.meta.glob('./layouts/*.tsx', { eager: true }) — optional. */
10
+ /** import.meta.glob('../../../../themes/nova/app/platform/tanqory/layouts/*.tsx', { eager: true }) — optional. */
9
11
  shell?: GlobMap;
12
+ /**
13
+ * import.meta.glob('../../../../themes/nova/app/platform/tanqory/groups/*.json', { eager: true }) — the shared
14
+ * header/footer groups a template may bind. Optional: a theme with no
15
+ * `groups/` renders its templates' inline header/footer exactly as before.
16
+ */
17
+ groups?: GlobMap;
10
18
  /** Data source the theme provides (createMockData(...) or a live client). */
11
19
  data: DataApi;
12
20
  /** Global settings values (config/settings.json). */
@@ -32,7 +40,20 @@ export interface MountOptions {
32
40
  * hydrating against mismatched markup throws React #418/#425.
33
41
  */
34
42
  forceClientRender?: boolean;
43
+ /**
44
+ * Exact studio origins allowed to drive the preview bridge (and the only
45
+ * targets it posts to). Defaults to the platform's studio hosts; a loopback
46
+ * page also accepts any loopback origin so the laptop loop works on any port.
47
+ */
48
+ previewOrigins?: readonly string[];
35
49
  }
50
+ /** `groups/<name>.json` glob → name-keyed map for `resolvePage`. */
51
+ export declare function groupsFromGlob(map?: GlobMap): GroupMap;
52
+ /**
53
+ * The section list a template renders — header group, body, footer group —
54
+ * through the ONE resolver the editor and the AI tools also use.
55
+ */
56
+ export declare function resolvePageSections(doc: PageDoc | undefined, groups: GroupMap): ContentNode[];
36
57
  /**
37
58
  * Boot a theme. The theme's entry passes its globbed sections/templates/layouts
38
59
  * (so Vite resolves them relative to the theme) plus a data source. Everything