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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -10
  3. package/dist/abi/canvas-live.d.ts +67 -0
  4. package/dist/abi/canvas-live.js +154 -0
  5. package/dist/abi/cart.d.ts +59 -0
  6. package/dist/abi/cart.js +387 -0
  7. package/dist/abi/convert.d.ts +344 -0
  8. package/dist/abi/convert.js +1278 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +209 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/labels.d.ts +3 -0
  14. package/dist/abi/labels.js +34 -0
  15. package/dist/abi/page-data.d.ts +256 -0
  16. package/dist/abi/page-data.js +678 -0
  17. package/dist/abi/page.d.ts +28 -0
  18. package/dist/abi/page.js +57 -0
  19. package/dist/abi/referrals.d.ts +23 -0
  20. package/dist/abi/referrals.js +89 -0
  21. package/dist/abi/rewards.d.ts +27 -0
  22. package/dist/abi/rewards.js +82 -0
  23. package/dist/abi/seo.d.ts +47 -0
  24. package/dist/abi/seo.js +68 -0
  25. package/dist/abi/shell.d.ts +23 -0
  26. package/dist/abi/shell.js +10 -0
  27. package/dist/abi/state-pack.d.ts +17 -0
  28. package/dist/abi/state-pack.js +43 -0
  29. package/dist/abi/wire.d.ts +38 -0
  30. package/dist/abi/wire.js +84 -0
  31. package/dist/build.d.ts +116 -0
  32. package/dist/build.js +310 -0
  33. package/dist/client.d.ts +19 -0
  34. package/dist/client.js +87 -0
  35. package/dist/contract.d.ts +6 -0
  36. package/dist/contract.js +6 -0
  37. package/dist/headless/ai.d.ts +132 -0
  38. package/dist/headless/ai.js +99 -0
  39. package/dist/headless/hooks.d.ts +276 -0
  40. package/dist/headless/hooks.js +540 -0
  41. package/dist/headless/i18n.d.ts +13 -0
  42. package/dist/headless/i18n.js +45 -0
  43. package/dist/headless/index.d.ts +37 -0
  44. package/dist/headless/index.js +38 -0
  45. package/dist/headless/money.d.ts +25 -0
  46. package/dist/headless/money.js +61 -0
  47. package/dist/headless/page.d.ts +43 -0
  48. package/dist/headless/page.js +53 -0
  49. package/dist/headless/platform.d.ts +55 -0
  50. package/dist/headless/platform.js +77 -0
  51. package/dist/headless/primitives/cart.d.ts +90 -0
  52. package/dist/headless/primitives/cart.js +153 -0
  53. package/dist/headless/primitives/collection.d.ts +68 -0
  54. package/dist/headless/primitives/collection.js +80 -0
  55. package/dist/headless/primitives/product.d.ts +101 -0
  56. package/dist/headless/primitives/product.js +117 -0
  57. package/dist/headless/primitives/storefront.d.ts +106 -0
  58. package/dist/headless/primitives/storefront.js +186 -0
  59. package/dist/headless/primitives/util.d.ts +19 -0
  60. package/dist/headless/primitives/util.js +42 -0
  61. package/dist/headless/strings.d.ts +9 -0
  62. package/dist/headless/strings.js +190 -0
  63. package/dist/headless/structured-data.d.ts +31 -0
  64. package/dist/headless/structured-data.js +57 -0
  65. package/dist/headless/theme.d.ts +99 -0
  66. package/dist/headless/theme.js +54 -0
  67. package/dist/index.d.ts +20 -0
  68. package/dist/index.js +18 -553
  69. package/dist/runtime/data/StoreProvider.d.ts +84 -0
  70. package/dist/runtime/data/StoreProvider.js +373 -0
  71. package/dist/runtime/data/handle.d.ts +14 -0
  72. package/dist/runtime/data/handle.js +16 -0
  73. package/dist/runtime/data/routes.d.ts +87 -0
  74. package/dist/runtime/data/routes.js +158 -0
  75. package/dist/runtime/data/to-ui.d.ts +281 -0
  76. package/dist/runtime/data/to-ui.js +977 -0
  77. package/dist/runtime/entries/register.d.ts +9 -0
  78. package/dist/runtime/entries/register.js +9 -0
  79. package/dist/runtime/entries/sections.d.ts +16 -0
  80. package/dist/runtime/entries/sections.js +19 -0
  81. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  82. package/dist/runtime/kit/SectionTree.js +100 -0
  83. package/dist/runtime/kit/analytics.d.ts +63 -0
  84. package/dist/runtime/kit/analytics.js +250 -0
  85. package/dist/runtime/kit/cart.d.ts +215 -0
  86. package/dist/runtime/kit/cart.js +545 -0
  87. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  88. package/dist/runtime/kit/composition.js +3 -0
  89. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  90. package/dist/runtime/kit/config.js +6 -0
  91. package/dist/runtime/kit/consent.d.ts +29 -0
  92. package/dist/runtime/kit/consent.js +159 -0
  93. package/dist/runtime/kit/contract/content.d.ts +199 -0
  94. package/dist/runtime/kit/contract/content.js +106 -0
  95. package/dist/runtime/kit/contract/field-types.d.ts +337 -0
  96. package/dist/runtime/kit/contract/field-types.js +206 -0
  97. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  98. package/dist/runtime/kit/contract/groups.js +402 -0
  99. package/dist/runtime/kit/contract/index.d.ts +33 -0
  100. package/dist/runtime/kit/contract/index.js +33 -0
  101. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  102. package/dist/runtime/kit/contract/transform.js +133 -0
  103. package/dist/runtime/kit/contract/validate.d.ts +75 -0
  104. package/dist/runtime/kit/contract/validate.js +480 -0
  105. package/dist/runtime/kit/data.d.ts +720 -0
  106. package/dist/runtime/kit/data.js +1117 -0
  107. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  108. package/dist/runtime/kit/defineSection.js +10 -0
  109. package/dist/{types → runtime/kit}/dynamic-source.d.ts +40 -18
  110. package/dist/runtime/kit/dynamic-source.js +294 -0
  111. package/dist/runtime/kit/index.d.ts +24 -0
  112. package/dist/runtime/kit/index.js +24 -0
  113. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  114. package/dist/runtime/kit/jsx-to-json.js +28 -0
  115. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  116. package/dist/runtime/kit/mount.js +124 -0
  117. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  118. package/dist/runtime/kit/registry.js +12 -0
  119. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  120. package/dist/runtime/kit/ssg.js +56 -0
  121. package/dist/runtime/kit/storefront.d.ts +639 -0
  122. package/dist/runtime/kit/storefront.js +723 -0
  123. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  124. package/dist/runtime/kit/theme-context.js +25 -0
  125. package/dist/runtime/kit/types.d.ts +147 -0
  126. package/dist/runtime/kit/types.js +1 -0
  127. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  128. package/dist/runtime/platform/TrackingPixels.js +63 -0
  129. package/dist/runtime/platform/environment.d.ts +68 -0
  130. package/dist/runtime/platform/environment.js +85 -0
  131. package/dist/runtime/platform/locale.d.ts +27 -0
  132. package/dist/runtime/platform/locale.js +42 -0
  133. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  134. package/dist/runtime/platform/route-analytics.js +72 -0
  135. package/dist/runtime/platform/safe-href.d.ts +25 -0
  136. package/dist/runtime/platform/safe-href.js +69 -0
  137. package/dist/runtime/platform/safe-values.d.ts +37 -0
  138. package/dist/runtime/platform/safe-values.js +140 -0
  139. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  140. package/dist/runtime/render/SectionRenderer.js +166 -0
  141. package/dist/runtime/render/listing-query.d.ts +52 -0
  142. package/dist/runtime/render/listing-query.js +122 -0
  143. package/dist/runtime/render/localized-copy.d.ts +86 -0
  144. package/dist/runtime/render/localized-copy.js +129 -0
  145. package/dist/runtime/render/product-listing.d.ts +11 -0
  146. package/dist/runtime/render/product-listing.js +243 -0
  147. package/dist/runtime/render/section-actions.d.ts +66 -0
  148. package/dist/runtime/render/section-actions.js +202 -0
  149. package/dist/runtime/render/starter.d.ts +11 -0
  150. package/dist/runtime/render/starter.js +81 -0
  151. package/dist/runtime/seo/head.d.ts +115 -0
  152. package/dist/runtime/seo/head.js +281 -0
  153. package/dist/runtime/seo/structured-data.d.ts +83 -0
  154. package/dist/runtime/seo/structured-data.js +252 -0
  155. package/dist/runtime/shell/PageShell.d.ts +18 -0
  156. package/dist/runtime/shell/PageShell.js +113 -0
  157. package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
  158. package/dist/runtime/shell/RuntimeBridge.js +93 -0
  159. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  160. package/dist/runtime/shell/overlay-state.js +59 -0
  161. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  162. package/dist/runtime/shell/preview-mode.js +11 -0
  163. package/dist/runtime/shell/spa-router.d.ts +14 -0
  164. package/dist/runtime/shell/spa-router.js +76 -0
  165. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  166. package/dist/runtime/shell/url-redirects.js +37 -0
  167. package/dist/runtime/slots.d.ts +74 -0
  168. package/dist/runtime/slots.js +16 -0
  169. package/dist/runtime.d.ts +34 -0
  170. package/dist/runtime.js +40 -0
  171. package/dist/sdk/app-block.d.ts +29 -0
  172. package/dist/sdk/app-block.js +22 -0
  173. package/dist/sdk/index.d.ts +26 -0
  174. package/dist/sdk/index.js +26 -0
  175. package/dist/sdk/referrals.d.ts +62 -0
  176. package/dist/sdk/referrals.js +20 -0
  177. package/dist/sdk/rewards.d.ts +85 -0
  178. package/dist/sdk/rewards.js +29 -0
  179. package/dist/sdk/runtime-context.d.ts +202 -0
  180. package/dist/sdk/runtime-context.js +73 -0
  181. package/dist/sdk/schema.d.ts +206 -0
  182. package/dist/sdk/schema.js +121 -0
  183. package/dist/sdk/server-render.d.ts +8 -0
  184. package/dist/sdk/server-render.js +12 -0
  185. package/dist/sdk/store-lookup.d.ts +27 -0
  186. package/dist/sdk/store-lookup.js +29 -0
  187. package/dist/sdk/store.d.ts +149 -0
  188. package/dist/sdk/store.js +5 -0
  189. package/dist/sdk/sx.d.ts +40 -0
  190. package/dist/sdk/sx.js +112 -0
  191. package/dist/sdk/theme.d.ts +191 -0
  192. package/dist/sdk/theme.js +10 -0
  193. package/dist/sdk/types.d.ts +757 -0
  194. package/dist/sdk/types.js +7 -0
  195. package/dist/server.d.ts +111 -0
  196. package/dist/server.js +533 -0
  197. package/docs/headless-api.md +220 -0
  198. package/package.json +76 -22
  199. package/dist/index.js.map +0 -1
  200. package/dist/ssg-BZ5FYTw7.js +0 -1802
  201. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  202. package/dist/ssg.js +0 -8
  203. package/dist/ssg.js.map +0 -1
  204. package/dist/types/cart.d.ts +0 -86
  205. package/dist/types/data.d.ts +0 -357
  206. package/dist/types/editor.d.ts +0 -5
  207. package/dist/types/index.d.ts +0 -20
  208. package/dist/types/preview-bridge.d.ts +0 -9
  209. package/dist/types/storefront.d.ts +0 -333
  210. package/dist/types/types.d.ts +0 -44
@@ -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
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Dynamic sources — bind a section/block setting to a live metafield, resource
3
- * property, or metaobject field (Shopify "Insert dynamic source", the ⛁ icon).
3
+ * property, or metaobject field (the commerce standard "Insert dynamic source", the ⛁ icon).
4
4
  *
5
5
  * A setting value is normally a primitive. When the merchant connects a dynamic
6
6
  * source the editor stores a `{ '@source': '<path>' }` object instead, and the
@@ -8,22 +8,32 @@
8
8
  *
9
9
  * product.metafields.custom.subtitle → the page product's metafield
10
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)
11
13
  * shop.metafields.custom.announcement → the store's metafield (any page)
12
14
  * product.title / shop.name → a plain resource property
13
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)
14
17
  *
15
- * The path grammar mirrors Shopify so themes/docs are portable. Resolution is
18
+ * The path grammar follows the standard commerce object model.
16
19
  * synchronous against already-loaded resources — the provider is responsible
17
20
  * for loading the bound metafields (see `collectBoundIdentifiers`).
18
21
  */
19
22
  import { type ReactNode } from 'react';
20
- import type { Product, Collection } from './data';
21
- import type { Shop, Metaobject } from './storefront';
23
+ import type { Product, Collection, Page, MetaobjectPage } from './data.js';
24
+ import type { Shop, Metaobject, Article } from './storefront.js';
22
25
  /** A setting bound to a dynamic source instead of a literal value. */
23
26
  export interface BoundSource {
24
27
  '@source': string;
25
28
  }
26
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;
27
37
  export declare function isBoundSource(v: unknown): v is BoundSource;
28
38
  /** Resources a dynamic source can read from on the current page. */
29
39
  export interface ResourceContextValue {
@@ -36,8 +46,18 @@ export interface ResourceContextValue {
36
46
  collection?: (Collection & {
37
47
  metafields?: Record<string, string | null>;
38
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;
39
57
  /** Synchronous metaobject lookup (type, handle) → entry, from a warmed cache. */
40
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;
41
61
  }
42
62
  /**
43
63
  * Provide the current page's resources to dynamic sources. Wrap the page once
@@ -49,8 +69,20 @@ export declare function DynamicSourceProvider({ value, children, }: {
49
69
  children: ReactNode;
50
70
  }): JSX.Element;
51
71
  export declare function useResourceContext(): ResourceContextValue;
72
+ /** The resources a `@source` path may start with. */
73
+ export declare const BOUND_SOURCE_ROOTS: readonly ["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';
52
76
  /** Resolve a `@source` path against a resource context. Returns null if unbound. */
53
77
  export declare function resolveBoundSource(source: string, ctx: ResourceContextValue): string | null;
78
+ /**
79
+ * Resolve every bound value of one saved settings object against the page's resources, before the section's data
80
+ * binding sees it (O4: the kit does this for every section and block, so no section needs its own code). A plain
81
+ * value passes through. A bound value becomes the live text; one with no value on this resource becomes '' (the
82
+ * setting shows empty, as a merchant who connected an empty metafield expects — never the setting's default copy),
83
+ * except a number setting, which then falls back to its default. Returns the same object when nothing is bound.
84
+ */
85
+ export declare function resolveBoundSettings(settings: Record<string, unknown> | undefined, ctx: ResourceContextValue, controlOf?: (key: string) => string | undefined): Record<string, unknown> | undefined;
54
86
  /**
55
87
  * Resolve a possibly-bound setting value for the current page.
56
88
  * const heading = useBound(attributes.heading) // string | the literal | null
@@ -68,17 +100,7 @@ export declare function useBoundText(value: unknown, fallback?: string): string;
68
100
  export declare function collectBoundIdentifiers(nodes: Array<{
69
101
  settings?: Record<string, unknown>;
70
102
  blocks?: unknown[];
71
- }> | undefined): {
72
- product: Array<{
73
- namespace: string;
74
- key: string;
75
- }>;
76
- collection: Array<{
77
- namespace: string;
78
- key: string;
79
- }>;
80
- shop: Array<{
81
- namespace: string;
82
- key: string;
83
- }>;
84
- };
103
+ }> | undefined): Record<'product' | 'collection' | 'page' | 'article' | 'shop', Array<{
104
+ namespace: string;
105
+ key: string;
106
+ }>>;
@@ -0,0 +1,294 @@
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
+ export function isBoundTemplate(v) {
26
+ return typeof v === 'object' && v !== null && typeof v['@template'] === 'string';
27
+ }
28
+ const TEMPLATE_TOKEN = /\{\{\s*([^{}\s]+)\s*\}\}/g;
29
+ /** The template with every token replaced by its source's text on this page ('' where a source has none). */
30
+ export function resolveBoundTemplate(template, ctx) {
31
+ return template.replace(TEMPLATE_TOKEN, (_, path) => resolveBoundSource(path, ctx) ?? '');
32
+ }
33
+ export function isBoundSource(v) {
34
+ return (typeof v === 'object' &&
35
+ v !== null &&
36
+ typeof v['@source'] === 'string');
37
+ }
38
+ const ResourceContext = createContext({});
39
+ /**
40
+ * Provide the current page's resources to dynamic sources. Wrap the page once
41
+ * (the layout does this). `shop` falls back to the data source so shop-level
42
+ * bindings work on every page without extra wiring.
43
+ */
44
+ export function DynamicSourceProvider({ value, children, }) {
45
+ return _jsx(ResourceContext.Provider, { value: value, children: children });
46
+ }
47
+ export function useResourceContext() {
48
+ const data = useData();
49
+ const ctx = useContext(ResourceContext);
50
+ // Shop is always available from the data source; an explicit provider value
51
+ // (carrying loaded shop metafields) takes precedence.
52
+ return { shop: data.shop, ...ctx };
53
+ }
54
+ const METAOBJECT_RE = /^metaobject:([^:]+):([^.]+)\.(.+)$/;
55
+ /** The resources a `@source` path may start with. */
56
+ export const BOUND_SOURCE_ROOTS = ['product', 'collection', 'page', 'article', 'shop', 'metaobject'];
57
+ /** The `@source` grammar a saved setting may carry (the contract owns it; the validator refuses anything else). */
58
+ export { BOUND_SOURCE_PATTERN } from './contract/field-types.js';
59
+ /** Resolve a `@source` path against a resource context. Returns null if unbound. */
60
+ export function resolveBoundSource(source, ctx) {
61
+ const mo = source.match(METAOBJECT_RE);
62
+ if (mo) {
63
+ const [, type, handle, field] = mo;
64
+ const obj = ctx.metaobject?.(type, handle);
65
+ return obj?.values?.[field] ?? null;
66
+ }
67
+ const parts = source.split('.');
68
+ const root = parts[0];
69
+ // A metaobject page's own entry: `metaobject.<field>` is one of its fields; `metaobject.url` (when no field is so
70
+ // named) its page. A reference field holds `{url}` (a file) or `{handle}` (a resource): the value a setting takes.
71
+ if (root === 'metaobject')
72
+ return parts.length === 2 ? metaobjectField(ctx.metaobjectPage, parts[1]) : null;
73
+ const resource = root === 'product'
74
+ ? ctx.product
75
+ : root === 'collection'
76
+ ? ctx.collection
77
+ : root === 'page'
78
+ ? ctx.page
79
+ : root === 'article'
80
+ ? ctx.article
81
+ : root === 'shop'
82
+ ? ctx.shop
83
+ : null;
84
+ if (!resource)
85
+ return null;
86
+ if (parts[1] === 'metafields') {
87
+ const ns = parts[2];
88
+ const key = parts.slice(3).join('.');
89
+ if (!ns || !key)
90
+ return null;
91
+ return resource.metafields?.[`${ns}.${key}`] ?? null;
92
+ }
93
+ // A property the editor's picker names that the record spells otherwise (a link, an image, the content).
94
+ const derived = derivedProperty(root, resource, parts[1] ?? '');
95
+ if (derived !== undefined)
96
+ return derived;
97
+ // Plain resource property: product.title, shop.name, collection.title… (a scalar only — never "[object Object]")
98
+ const direct = resource[parts[1]];
99
+ return typeof direct === 'string' || typeof direct === 'number' || typeof direct === 'boolean' ? String(direct) : null;
100
+ }
101
+ /** One field of the page's metaobject entry as a setting's value (see resolveBoundSource). */
102
+ function metaobjectField(entry, key) {
103
+ if (!entry || !key)
104
+ return null;
105
+ const fields = entry.fields;
106
+ if (!Object.prototype.hasOwnProperty.call(fields, key))
107
+ return key === 'url' ? entry.url || null : key === 'handle' ? entry.handle : null;
108
+ const v = fields[key];
109
+ if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean')
110
+ return String(v);
111
+ if (Array.isArray(v)) {
112
+ 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);
113
+ return items.length ? items.join(',') : null;
114
+ }
115
+ if (v && typeof v === 'object') {
116
+ const handle = v.handle;
117
+ return urlOf(v) ?? (typeof handle === 'string' && handle ? handle : null);
118
+ }
119
+ return null;
120
+ }
121
+ const urlOf = (v) => {
122
+ if (!v || typeof v !== 'object')
123
+ return null;
124
+ const u = v.url ?? v.src;
125
+ return typeof u === 'string' && u ? u : null;
126
+ };
127
+ /**
128
+ * The record's own value for a property of the source picker (studio-api DYNAMIC_SOURCE_RESOURCES), or undefined
129
+ * when the name is a plain field of the record: `url` is the resource's storefront path, `featured_image` / `image`
130
+ * its image URL, `content` its body, `collections` a product's collection handles (comma-separated, the list
131
+ * pickers' value shape).
132
+ */
133
+ function derivedProperty(root, r, prop) {
134
+ const handle = typeof r.handle === 'string' ? r.handle : '';
135
+ switch (prop) {
136
+ case 'url':
137
+ if (!handle)
138
+ return null;
139
+ if (root === 'product')
140
+ return `/products/${handle}`;
141
+ if (root === 'collection')
142
+ return `/collections/${handle}`;
143
+ if (root === 'page')
144
+ return `/pages/${handle}`;
145
+ if (root === 'article')
146
+ return typeof r.blogHandle === 'string' ? `/blogs/${r.blogHandle}/${handle}` : null;
147
+ return undefined;
148
+ case 'featured_image':
149
+ return urlOf(r.featuredImage ?? r.image);
150
+ case 'image':
151
+ return root === 'shop' ? undefined : urlOf(r.image ?? r.featuredImage);
152
+ case 'content': {
153
+ const html = r.contentHtml ?? r.body ?? r.bodyHtml ?? r.content;
154
+ return typeof html === 'string' ? html : null;
155
+ }
156
+ case 'collections': {
157
+ const list = Array.isArray(r.collections) ? r.collections : [];
158
+ const handles = list.map((c) => (c && typeof c === 'object' ? c.handle : null)).filter((h) => typeof h === 'string' && !!h);
159
+ return handles.length ? handles.join(',') : null;
160
+ }
161
+ default:
162
+ return undefined;
163
+ }
164
+ }
165
+ /** Field controls whose bound value must be a value of their own kind (a handle, an https URL, a hex colour). */
166
+ const KIND_CONTROLS = new Set(['product', 'collection', 'page', 'article', 'blog', 'image', 'video', 'color']);
167
+ const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
168
+ /** Field controls whose bound value is a number (the resolved text is converted; non-numeric ⇒ the default). */
169
+ const NUMBER_CONTROLS = new Set(['number', 'range']);
170
+ /**
171
+ * Resolve every bound value of one saved settings object against the page's resources, before the section's data
172
+ * binding sees it (O4: the kit does this for every section and block, so no section needs its own code). A plain
173
+ * value passes through. A bound value becomes the live text; one with no value on this resource becomes '' (the
174
+ * setting shows empty, as a merchant who connected an empty metafield expects — never the setting's default copy),
175
+ * except a number setting, which then falls back to its default. Returns the same object when nothing is bound.
176
+ */
177
+ export function resolveBoundSettings(settings, ctx, controlOf) {
178
+ if (!settings)
179
+ return settings;
180
+ let out = null;
181
+ for (const [k, v] of Object.entries(settings)) {
182
+ if (isBoundTemplate(v)) {
183
+ out ??= { ...settings };
184
+ out[k] = resolveBoundTemplate(v['@template'], ctx);
185
+ continue;
186
+ }
187
+ if (!isBoundSource(v))
188
+ continue;
189
+ out ??= { ...settings };
190
+ const text = resolveBoundSource(v['@source'], ctx);
191
+ const control = controlOf?.(k) ?? '';
192
+ // A picker setting (product, collection, page, article, image, video) or a colour takes only a value of its own
193
+ // kind: a handle / URL / hex. Anything else (an unresolved reference id) falls back to the setting's default,
194
+ // never a broken value.
195
+ if (KIND_CONTROLS.has(control)) {
196
+ const t = (text ?? '').trim();
197
+ const ok = control === 'color' ? HEX.test(t) : t !== '' && !t.startsWith('gid://') && (control !== 'image' && control !== 'video' ? true : /^https:\/\//.test(t));
198
+ if (ok)
199
+ out[k] = t;
200
+ else
201
+ delete out[k];
202
+ continue;
203
+ }
204
+ if (NUMBER_CONTROLS.has(control)) {
205
+ const n = text === null || text.trim() === '' ? NaN : Number(text);
206
+ if (Number.isFinite(n))
207
+ out[k] = n;
208
+ else
209
+ delete out[k];
210
+ }
211
+ else {
212
+ out[k] = text ?? '';
213
+ }
214
+ }
215
+ return out ?? settings;
216
+ }
217
+ /**
218
+ * Resolve a possibly-bound setting value for the current page.
219
+ * const heading = useBound(attributes.heading) // string | the literal | null
220
+ * A plain value passes through unchanged; a `{ '@source' }` object resolves to
221
+ * the live value (or null when the source has no value on this resource).
222
+ */
223
+ export function useBound(value) {
224
+ const ctx = useResourceContext();
225
+ if (!isBoundSource(value))
226
+ return value;
227
+ return resolveBoundSource(value['@source'], ctx);
228
+ }
229
+ /** Convenience: resolve to a string (empty when null/unbound-empty). */
230
+ export function useBoundText(value, fallback = '') {
231
+ const resolved = useBound(value);
232
+ if (resolved == null)
233
+ return fallback;
234
+ return typeof resolved === 'string' ? resolved : String(resolved);
235
+ }
236
+ /**
237
+ * Walk a content tree's section/block settings and collect every bound metafield
238
+ * identifier, grouped by resource. The provider uses this to request exactly the
239
+ * metafields the page binds (the live product/collection query takes identifiers).
240
+ */
241
+ export function collectBoundIdentifiers(nodes) {
242
+ const out = {
243
+ product: [],
244
+ collection: [],
245
+ page: [],
246
+ article: [],
247
+ shop: [],
248
+ };
249
+ const seen = new Set();
250
+ const visitSettings = (settings) => {
251
+ if (!settings)
252
+ return;
253
+ const paths = [];
254
+ for (const v of Object.values(settings)) {
255
+ if (isBoundSource(v))
256
+ paths.push(v['@source']);
257
+ else if (isBoundTemplate(v))
258
+ for (const m of v['@template'].matchAll(TEMPLATE_TOKEN))
259
+ paths.push(m[1]);
260
+ }
261
+ for (const path of paths) {
262
+ const parts = path.split('.');
263
+ const root = parts[0];
264
+ if (parts[1] !== 'metafields')
265
+ continue;
266
+ const namespace = parts[2];
267
+ const key = parts.slice(3).join('.');
268
+ if (!namespace || !key || !(root in out))
269
+ continue;
270
+ const dedupe = `${root}:${namespace}.${key}`;
271
+ if (seen.has(dedupe))
272
+ continue;
273
+ seen.add(dedupe);
274
+ out[root].push({ namespace, key });
275
+ }
276
+ };
277
+ // Sections + blocks may store children as an array OR an object map (the
278
+ // editor's `{ id: node }` shape) — normalize both before iterating.
279
+ const toNodes = (v) => {
280
+ if (Array.isArray(v))
281
+ return v;
282
+ if (v && typeof v === 'object')
283
+ return Object.values(v);
284
+ return [];
285
+ };
286
+ const walk = (list) => {
287
+ for (const node of toNodes(list)) {
288
+ visitSettings(node.settings);
289
+ walk(node.blocks);
290
+ }
291
+ };
292
+ walk(nodes);
293
+ return out;
294
+ }
@@ -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