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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -10
  3. package/dist/abi/canvas-live.d.ts +67 -0
  4. package/dist/abi/canvas-live.js +154 -0
  5. package/dist/abi/cart.d.ts +59 -0
  6. package/dist/abi/cart.js +387 -0
  7. package/dist/abi/convert.d.ts +344 -0
  8. package/dist/abi/convert.js +1278 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +209 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/labels.d.ts +3 -0
  14. package/dist/abi/labels.js +34 -0
  15. package/dist/abi/page-data.d.ts +256 -0
  16. package/dist/abi/page-data.js +678 -0
  17. package/dist/abi/page.d.ts +28 -0
  18. package/dist/abi/page.js +57 -0
  19. package/dist/abi/referrals.d.ts +23 -0
  20. package/dist/abi/referrals.js +89 -0
  21. package/dist/abi/rewards.d.ts +27 -0
  22. package/dist/abi/rewards.js +82 -0
  23. package/dist/abi/seo.d.ts +47 -0
  24. package/dist/abi/seo.js +68 -0
  25. package/dist/abi/shell.d.ts +23 -0
  26. package/dist/abi/shell.js +10 -0
  27. package/dist/abi/state-pack.d.ts +17 -0
  28. package/dist/abi/state-pack.js +43 -0
  29. package/dist/abi/wire.d.ts +38 -0
  30. package/dist/abi/wire.js +84 -0
  31. package/dist/build.d.ts +116 -0
  32. package/dist/build.js +310 -0
  33. package/dist/client.d.ts +19 -0
  34. package/dist/client.js +87 -0
  35. package/dist/contract.d.ts +6 -0
  36. package/dist/contract.js +6 -0
  37. package/dist/headless/ai.d.ts +132 -0
  38. package/dist/headless/ai.js +99 -0
  39. package/dist/headless/hooks.d.ts +276 -0
  40. package/dist/headless/hooks.js +540 -0
  41. package/dist/headless/i18n.d.ts +13 -0
  42. package/dist/headless/i18n.js +45 -0
  43. package/dist/headless/index.d.ts +37 -0
  44. package/dist/headless/index.js +38 -0
  45. package/dist/headless/money.d.ts +25 -0
  46. package/dist/headless/money.js +61 -0
  47. package/dist/headless/page.d.ts +43 -0
  48. package/dist/headless/page.js +53 -0
  49. package/dist/headless/platform.d.ts +55 -0
  50. package/dist/headless/platform.js +77 -0
  51. package/dist/headless/primitives/cart.d.ts +90 -0
  52. package/dist/headless/primitives/cart.js +153 -0
  53. package/dist/headless/primitives/collection.d.ts +68 -0
  54. package/dist/headless/primitives/collection.js +80 -0
  55. package/dist/headless/primitives/product.d.ts +101 -0
  56. package/dist/headless/primitives/product.js +117 -0
  57. package/dist/headless/primitives/storefront.d.ts +106 -0
  58. package/dist/headless/primitives/storefront.js +186 -0
  59. package/dist/headless/primitives/util.d.ts +19 -0
  60. package/dist/headless/primitives/util.js +42 -0
  61. package/dist/headless/strings.d.ts +9 -0
  62. package/dist/headless/strings.js +190 -0
  63. package/dist/headless/structured-data.d.ts +31 -0
  64. package/dist/headless/structured-data.js +57 -0
  65. package/dist/headless/theme.d.ts +99 -0
  66. package/dist/headless/theme.js +54 -0
  67. package/dist/index.d.ts +20 -0
  68. package/dist/index.js +18 -553
  69. package/dist/runtime/data/StoreProvider.d.ts +84 -0
  70. package/dist/runtime/data/StoreProvider.js +373 -0
  71. package/dist/runtime/data/handle.d.ts +14 -0
  72. package/dist/runtime/data/handle.js +16 -0
  73. package/dist/runtime/data/routes.d.ts +87 -0
  74. package/dist/runtime/data/routes.js +158 -0
  75. package/dist/runtime/data/to-ui.d.ts +281 -0
  76. package/dist/runtime/data/to-ui.js +977 -0
  77. package/dist/runtime/entries/register.d.ts +9 -0
  78. package/dist/runtime/entries/register.js +9 -0
  79. package/dist/runtime/entries/sections.d.ts +16 -0
  80. package/dist/runtime/entries/sections.js +19 -0
  81. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  82. package/dist/runtime/kit/SectionTree.js +100 -0
  83. package/dist/runtime/kit/analytics.d.ts +63 -0
  84. package/dist/runtime/kit/analytics.js +250 -0
  85. package/dist/runtime/kit/cart.d.ts +215 -0
  86. package/dist/runtime/kit/cart.js +545 -0
  87. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  88. package/dist/runtime/kit/composition.js +3 -0
  89. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  90. package/dist/runtime/kit/config.js +6 -0
  91. package/dist/runtime/kit/consent.d.ts +29 -0
  92. package/dist/runtime/kit/consent.js +159 -0
  93. package/dist/runtime/kit/contract/content.d.ts +199 -0
  94. package/dist/runtime/kit/contract/content.js +106 -0
  95. package/dist/runtime/kit/contract/field-types.d.ts +337 -0
  96. package/dist/runtime/kit/contract/field-types.js +206 -0
  97. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  98. package/dist/runtime/kit/contract/groups.js +402 -0
  99. package/dist/runtime/kit/contract/index.d.ts +33 -0
  100. package/dist/runtime/kit/contract/index.js +33 -0
  101. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  102. package/dist/runtime/kit/contract/transform.js +133 -0
  103. package/dist/runtime/kit/contract/validate.d.ts +75 -0
  104. package/dist/runtime/kit/contract/validate.js +480 -0
  105. package/dist/runtime/kit/data.d.ts +720 -0
  106. package/dist/runtime/kit/data.js +1117 -0
  107. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  108. package/dist/runtime/kit/defineSection.js +10 -0
  109. package/dist/{types → runtime/kit}/dynamic-source.d.ts +40 -18
  110. package/dist/runtime/kit/dynamic-source.js +294 -0
  111. package/dist/runtime/kit/index.d.ts +24 -0
  112. package/dist/runtime/kit/index.js +24 -0
  113. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  114. package/dist/runtime/kit/jsx-to-json.js +28 -0
  115. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  116. package/dist/runtime/kit/mount.js +124 -0
  117. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  118. package/dist/runtime/kit/registry.js +12 -0
  119. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  120. package/dist/runtime/kit/ssg.js +56 -0
  121. package/dist/runtime/kit/storefront.d.ts +639 -0
  122. package/dist/runtime/kit/storefront.js +723 -0
  123. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  124. package/dist/runtime/kit/theme-context.js +25 -0
  125. package/dist/runtime/kit/types.d.ts +147 -0
  126. package/dist/runtime/kit/types.js +1 -0
  127. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  128. package/dist/runtime/platform/TrackingPixels.js +63 -0
  129. package/dist/runtime/platform/environment.d.ts +68 -0
  130. package/dist/runtime/platform/environment.js +85 -0
  131. package/dist/runtime/platform/locale.d.ts +27 -0
  132. package/dist/runtime/platform/locale.js +42 -0
  133. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  134. package/dist/runtime/platform/route-analytics.js +72 -0
  135. package/dist/runtime/platform/safe-href.d.ts +25 -0
  136. package/dist/runtime/platform/safe-href.js +69 -0
  137. package/dist/runtime/platform/safe-values.d.ts +37 -0
  138. package/dist/runtime/platform/safe-values.js +140 -0
  139. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  140. package/dist/runtime/render/SectionRenderer.js +166 -0
  141. package/dist/runtime/render/listing-query.d.ts +52 -0
  142. package/dist/runtime/render/listing-query.js +122 -0
  143. package/dist/runtime/render/localized-copy.d.ts +86 -0
  144. package/dist/runtime/render/localized-copy.js +129 -0
  145. package/dist/runtime/render/product-listing.d.ts +11 -0
  146. package/dist/runtime/render/product-listing.js +243 -0
  147. package/dist/runtime/render/section-actions.d.ts +66 -0
  148. package/dist/runtime/render/section-actions.js +202 -0
  149. package/dist/runtime/render/starter.d.ts +11 -0
  150. package/dist/runtime/render/starter.js +81 -0
  151. package/dist/runtime/seo/head.d.ts +115 -0
  152. package/dist/runtime/seo/head.js +281 -0
  153. package/dist/runtime/seo/structured-data.d.ts +83 -0
  154. package/dist/runtime/seo/structured-data.js +252 -0
  155. package/dist/runtime/shell/PageShell.d.ts +18 -0
  156. package/dist/runtime/shell/PageShell.js +113 -0
  157. package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
  158. package/dist/runtime/shell/RuntimeBridge.js +93 -0
  159. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  160. package/dist/runtime/shell/overlay-state.js +59 -0
  161. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  162. package/dist/runtime/shell/preview-mode.js +11 -0
  163. package/dist/runtime/shell/spa-router.d.ts +14 -0
  164. package/dist/runtime/shell/spa-router.js +76 -0
  165. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  166. package/dist/runtime/shell/url-redirects.js +37 -0
  167. package/dist/runtime/slots.d.ts +74 -0
  168. package/dist/runtime/slots.js +16 -0
  169. package/dist/runtime.d.ts +34 -0
  170. package/dist/runtime.js +40 -0
  171. package/dist/sdk/app-block.d.ts +29 -0
  172. package/dist/sdk/app-block.js +22 -0
  173. package/dist/sdk/index.d.ts +26 -0
  174. package/dist/sdk/index.js +26 -0
  175. package/dist/sdk/referrals.d.ts +62 -0
  176. package/dist/sdk/referrals.js +20 -0
  177. package/dist/sdk/rewards.d.ts +85 -0
  178. package/dist/sdk/rewards.js +29 -0
  179. package/dist/sdk/runtime-context.d.ts +202 -0
  180. package/dist/sdk/runtime-context.js +73 -0
  181. package/dist/sdk/schema.d.ts +206 -0
  182. package/dist/sdk/schema.js +121 -0
  183. package/dist/sdk/server-render.d.ts +8 -0
  184. package/dist/sdk/server-render.js +12 -0
  185. package/dist/sdk/store-lookup.d.ts +27 -0
  186. package/dist/sdk/store-lookup.js +29 -0
  187. package/dist/sdk/store.d.ts +149 -0
  188. package/dist/sdk/store.js +5 -0
  189. package/dist/sdk/sx.d.ts +40 -0
  190. package/dist/sdk/sx.js +112 -0
  191. package/dist/sdk/theme.d.ts +191 -0
  192. package/dist/sdk/theme.js +10 -0
  193. package/dist/sdk/types.d.ts +757 -0
  194. package/dist/sdk/types.js +7 -0
  195. package/dist/server.d.ts +111 -0
  196. package/dist/server.js +533 -0
  197. package/docs/headless-api.md +220 -0
  198. package/package.json +76 -22
  199. package/dist/index.js.map +0 -1
  200. package/dist/ssg-BZ5FYTw7.js +0 -1802
  201. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  202. package/dist/ssg.js +0 -8
  203. package/dist/ssg.js.map +0 -1
  204. package/dist/types/cart.d.ts +0 -86
  205. package/dist/types/data.d.ts +0 -357
  206. package/dist/types/editor.d.ts +0 -5
  207. package/dist/types/index.d.ts +0 -20
  208. package/dist/types/preview-bridge.d.ts +0 -9
  209. package/dist/types/storefront.d.ts +0 -333
  210. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,206 @@
1
+ /**
2
+ * The settings schema DSL — the ONE place a Nova section or block declares its
3
+ * persisted settings in code. Everything else is derived from it:
4
+ *
5
+ * schema ──► TypeScript prop types (SettingsOf<typeof schema>)
6
+ * ──► the adapter (resolveSettings: defaults, legacy, coercion)
7
+ * ──► Storybook controls (stories/argTypes.ts)
8
+ * ──► contract drift validation (validate.ts, against generated/*.json)
9
+ *
10
+ * Option IDs here are the PERSISTED IDs (what a store's saved JSON holds), never
11
+ * display labels. Labels come from the approved contract at display time.
12
+ */
13
+ /** The editor control vocabulary used by the approved contracts. */
14
+ export type Control = 'select' | 'boolean' | 'text' | 'textarea' | 'richtext' | 'url' | 'range' | 'number' | 'color' | 'image' | 'video' | 'menu' | 'collection' | 'product' | 'page' | 'blog' | 'article';
15
+ /**
16
+ * How a persisted setting reaches the component:
17
+ * prop — passed through as the typed component prop of the same name
18
+ * adapter — resolved by the adapter layer into data (a menu handle becomes a
19
+ * Menu object, an image id an Image). The component takes the data.
20
+ */
21
+ export type Binding = 'prop' | 'adapter';
22
+ interface FieldBase<C extends Control, V, B extends Binding = 'prop'> {
23
+ readonly control: C;
24
+ readonly default: V;
25
+ readonly binding: B;
26
+ /** LEGACY-HIDDEN: saved values keep rendering; not a control for new stores. */
27
+ readonly legacyHidden?: boolean;
28
+ /** The semantic this setting controls — two visible fields must never share one. */
29
+ readonly semantic?: string;
30
+ /** Why a field that is not in the approved contract exists. Absent = it must be in the contract. */
31
+ readonly extension?: string;
32
+ /** The editor's label for the control (a theme's manifest build reads it; the key, humanised, when absent). */
33
+ readonly label?: string;
34
+ /** Helper text under the control. */
35
+ readonly info?: string;
36
+ /** Placeholder text in the control. */
37
+ readonly placeholder?: string;
38
+ /** The editor panel group the control is filed under. */
39
+ readonly group?: string;
40
+ /**
41
+ * Shown in the editor only while this holds: a Liquid-style condition over `section.settings.*`, `block.settings.*`
42
+ * and `settings.*` (the manifest's `visible_if`). A hidden setting keeps its value and still renders.
43
+ */
44
+ readonly visibleIf?: string;
45
+ }
46
+ export interface SelectField<O extends string = string> extends FieldBase<'select', O> {
47
+ readonly options: readonly O[];
48
+ /** The editor's label for each option id (the id itself when absent). */
49
+ readonly optionLabels?: Readonly<Partial<Record<O, string>>>;
50
+ /** Saved values that are no longer options → the option they render as. */
51
+ readonly legacy?: Readonly<Record<string, O>>;
52
+ }
53
+ export interface BooleanField extends FieldBase<'boolean', boolean> {
54
+ }
55
+ export interface TextField<C extends 'text' | 'textarea' | 'richtext' | 'url' | 'color' = 'text'> extends FieldBase<C, string> {
56
+ }
57
+ export interface RangeField extends FieldBase<'range' | 'number', number> {
58
+ readonly min: number;
59
+ readonly max: number;
60
+ readonly step: number;
61
+ /** Values the design snaps to (e.g. spacer 8·12·16·24…). */
62
+ readonly snap?: readonly number[];
63
+ /** The unit the editor shows beside a range ("px", "%"). */
64
+ readonly unit?: string;
65
+ }
66
+ export type ResourceControl = 'image' | 'video' | 'menu' | 'collection' | 'product' | 'page' | 'blog' | 'article';
67
+ export interface ResourceField<C extends ResourceControl = ResourceControl> extends FieldBase<C, string, 'adapter'> {
68
+ }
69
+ export type Field = SelectField | BooleanField | TextField<'text' | 'textarea' | 'richtext' | 'url' | 'color'> | RangeField | ResourceField;
70
+ type Opts = {
71
+ legacyHidden?: boolean;
72
+ semantic?: string;
73
+ extension?: string;
74
+ label?: string;
75
+ info?: string;
76
+ placeholder?: string;
77
+ group?: string;
78
+ visibleIf?: string;
79
+ };
80
+ declare function select<const O extends string>(options: readonly O[], def: NoInfer<O>): SelectField<O>;
81
+ declare function select<const O extends string, const X extends Opts & {
82
+ legacy?: Record<string, NoInfer<O>>;
83
+ optionLabels?: Readonly<Partial<Record<NoInfer<O>, string>>>;
84
+ }>(options: readonly O[], def: NoInfer<O>, opts: X): SelectField<O> & X;
85
+ declare function resource<const C extends ResourceControl>(control: C, def?: string): ResourceField<C>;
86
+ declare function resource<const C extends ResourceControl, const X extends Opts>(control: C, def: string, opts: X): ResourceField<C> & X;
87
+ export declare const field: {
88
+ select: typeof select;
89
+ boolean: {
90
+ (def?: boolean | undefined): BooleanField;
91
+ <const X extends Opts>(def: boolean, opts: X): BooleanField & X;
92
+ };
93
+ text: {
94
+ (def?: string | undefined): TextField<"text">;
95
+ <const X extends Opts>(def: string, opts: X): TextField<"text"> & X;
96
+ };
97
+ textarea: {
98
+ (def?: string | undefined): TextField<"textarea">;
99
+ <const X extends Opts>(def: string, opts: X): TextField<"textarea"> & X;
100
+ };
101
+ richtext: {
102
+ (def?: string | undefined): TextField<"richtext">;
103
+ <const X extends Opts>(def: string, opts: X): TextField<"richtext"> & X;
104
+ };
105
+ url: {
106
+ (def?: string | undefined): TextField<"url">;
107
+ <const X extends Opts>(def: string, opts: X): TextField<"url"> & X;
108
+ };
109
+ color: {
110
+ (def?: string | undefined): TextField<"color">;
111
+ <const X extends Opts>(def: string, opts: X): TextField<"color"> & X;
112
+ };
113
+ range(def: number, min: number, max: number, step: number, opts?: Opts & {
114
+ snap?: readonly number[];
115
+ unit?: string;
116
+ }): RangeField;
117
+ /** A number input (contract control "number") — same resolution as range. */
118
+ number(def: number, min: number, max: number, step: number, opts?: Opts): RangeField;
119
+ /** A data picker: the persisted value is a handle/id; the adapter resolves it. */
120
+ resource: typeof resource;
121
+ };
122
+ export type Fields = Readonly<Record<string, Field>>;
123
+ /** Where a schema came from: section or block, and which design family owns it. */
124
+ export interface SchemaMeta {
125
+ /** global = a theme setting group (Nova 13 popup), not placed on a page. */
126
+ readonly kind: 'section' | 'block' | 'global';
127
+ readonly name: string;
128
+ /** Design family, e.g. '12A'. The validator reads the contract from here. */
129
+ readonly family: string;
130
+ /**
131
+ * Blocks a section (or a nested block) accepts. The reserved entry `'@app'` (`APP_BLOCKS`) accepts the blocks of the
132
+ * apps installed on the store (theme-abi §7.2); render those with `<AppBlock>`. Never on a header or footer section.
133
+ */
134
+ readonly blocks?: readonly string[];
135
+ /** Blocks still accepted for saved stores but hidden from the picker. */
136
+ readonly legacyBlocks?: readonly string[];
137
+ /** Sections a block may be placed in (blocks only). */
138
+ readonly parents?: readonly string[];
139
+ /**
140
+ * Earlier persisted names of this block (blocks only). Saved content may still
141
+ * hold a node of that type: the section keeps accepting it (`legacyBlocks`),
142
+ * the theme renders it as this block, and the contract validator reads this
143
+ * block's contract under the old name. New content is written with `name`.
144
+ */
145
+ readonly legacyNames?: readonly string[];
146
+ /** How the editor names the block in "Add block" (blocks). */
147
+ readonly title?: string;
148
+ /** One line for the editor's picker. */
149
+ readonly description?: string;
150
+ readonly icon?: string;
151
+ /** Route context the block needs (`product`, `collection`, …): it is offered only where the page has it. */
152
+ readonly requiresContext?: readonly string[];
153
+ }
154
+ export interface Schema<F extends Fields = Fields> extends SchemaMeta {
155
+ readonly fields: F;
156
+ }
157
+ export declare function defineSchema<const F extends Fields>(meta: SchemaMeta, fields: F): Schema<F>;
158
+ type ValueOf<F> = F extends SelectField<infer O> ? O : F extends BooleanField ? boolean : F extends RangeField ? number : string;
159
+ /**
160
+ * The resolved settings of a schema: every visible field required (the adapter
161
+ * fills defaults), every LEGACY-HIDDEN field optional.
162
+ */
163
+ export type SettingsOf<S extends Schema> = {
164
+ -readonly [K in keyof S['fields'] as S['fields'][K] extends {
165
+ binding: 'adapter';
166
+ } ? never : S['fields'][K] extends {
167
+ legacyHidden: true;
168
+ } ? never : K]: ValueOf<S['fields'][K]>;
169
+ } & {
170
+ -readonly [K in keyof S['fields'] as S['fields'][K] extends {
171
+ binding: 'adapter';
172
+ } ? never : S['fields'][K] extends {
173
+ legacyHidden: true;
174
+ } ? K : never]?: ValueOf<S['fields'][K]>;
175
+ };
176
+ /** The raw adapter-bound (handle) values of a schema. */
177
+ export type HandlesOf<S extends Schema> = {
178
+ -readonly [K in keyof S['fields'] as S['fields'][K] extends {
179
+ binding: 'adapter';
180
+ } ? K : never]: string;
181
+ };
182
+ export interface SettingIssue {
183
+ readonly key: string;
184
+ readonly code: 'unknown-option' | 'legacy-value' | 'coerced' | 'unknown-setting' | 'out-of-range';
185
+ readonly value: unknown;
186
+ readonly resolved?: unknown;
187
+ }
188
+ export interface Resolved<S extends Schema> {
189
+ readonly settings: SettingsOf<S>;
190
+ readonly handles: HandlesOf<S>;
191
+ /** Everything the adapter had to correct — surfaced in dev and asserted in tests. */
192
+ readonly issues: readonly SettingIssue[];
193
+ }
194
+ /**
195
+ * The adapter core: saved JSON settings → typed, complete settings.
196
+ *
197
+ * - missing → the field default
198
+ * - a legacy option → the option it renders as (issue: legacy-value)
199
+ * - an unknown option → the default (issue: unknown-option), never a crash
200
+ * - "true"/"false"/"32" strings → boolean / number (issue: coerced)
201
+ * - LEGACY-HIDDEN fields keep their saved value (that is the point of them)
202
+ */
203
+ export declare function resolveSettings<S extends Schema>(schema: S, raw: Readonly<Record<string, unknown>> | undefined): Resolved<S>;
204
+ /** Defaults of a schema — what a brand-new section renders with. */
205
+ export declare function defaultsOf<S extends Schema>(schema: S): SettingsOf<S>;
206
+ export {};
@@ -0,0 +1,121 @@
1
+ /**
2
+ * The settings schema DSL — the ONE place a Nova section or block declares its
3
+ * persisted settings in code. Everything else is derived from it:
4
+ *
5
+ * schema ──► TypeScript prop types (SettingsOf<typeof schema>)
6
+ * ──► the adapter (resolveSettings: defaults, legacy, coercion)
7
+ * ──► Storybook controls (stories/argTypes.ts)
8
+ * ──► contract drift validation (validate.ts, against generated/*.json)
9
+ *
10
+ * Option IDs here are the PERSISTED IDs (what a store's saved JSON holds), never
11
+ * display labels. Labels come from the approved contract at display time.
12
+ */
13
+ function select(options, def, opts) {
14
+ return { control: 'select', options, default: def, binding: 'prop', ...opts };
15
+ }
16
+ function simple(control) {
17
+ function make(def, opts) {
18
+ return { control, default: def ?? (control === 'boolean' ? false : ''), binding: 'prop', ...opts };
19
+ }
20
+ return make;
21
+ }
22
+ function resource(control, def = '', opts) {
23
+ return { control, default: def, binding: 'adapter', ...opts };
24
+ }
25
+ export const field = {
26
+ select,
27
+ boolean: simple('boolean'),
28
+ text: simple('text'),
29
+ textarea: simple('textarea'),
30
+ richtext: simple('richtext'),
31
+ url: simple('url'),
32
+ color: simple('color'),
33
+ range(def, min, max, step, opts = {}) {
34
+ return { control: 'range', default: def, min, max, step, binding: 'prop', ...opts };
35
+ },
36
+ /** A number input (contract control "number") — same resolution as range. */
37
+ number(def, min, max, step, opts = {}) {
38
+ return { control: 'number', default: def, min, max, step, binding: 'prop', ...opts };
39
+ },
40
+ /** A data picker: the persisted value is a handle/id; the adapter resolves it. */
41
+ resource,
42
+ };
43
+ export function defineSchema(meta, fields) {
44
+ return { ...meta, fields };
45
+ }
46
+ function snapTo(value, snap) {
47
+ return snap.reduce((best, s) => (Math.abs(s - value) < Math.abs(best - value) ? s : best), snap[0]);
48
+ }
49
+ /**
50
+ * The adapter core: saved JSON settings → typed, complete settings.
51
+ *
52
+ * - missing → the field default
53
+ * - a legacy option → the option it renders as (issue: legacy-value)
54
+ * - an unknown option → the default (issue: unknown-option), never a crash
55
+ * - "true"/"false"/"32" strings → boolean / number (issue: coerced)
56
+ * - LEGACY-HIDDEN fields keep their saved value (that is the point of them)
57
+ */
58
+ export function resolveSettings(schema, raw) {
59
+ const input = raw ?? {};
60
+ const settings = {};
61
+ const handles = {};
62
+ const issues = [];
63
+ for (const [key, f] of Object.entries(schema.fields)) {
64
+ const has = Object.prototype.hasOwnProperty.call(input, key) && input[key] !== undefined && input[key] !== null;
65
+ let value = has ? input[key] : f.default;
66
+ if (f.control === 'select') {
67
+ const opts = f.options;
68
+ if (typeof value === 'number')
69
+ value = String(value);
70
+ if (!opts.includes(value)) {
71
+ const legacy = f.legacy?.[value];
72
+ if (legacy !== undefined) {
73
+ issues.push({ key, code: 'legacy-value', value, resolved: legacy });
74
+ value = legacy;
75
+ }
76
+ else {
77
+ if (has)
78
+ issues.push({ key, code: 'unknown-option', value, resolved: f.default });
79
+ value = f.default;
80
+ }
81
+ }
82
+ }
83
+ else if (f.control === 'boolean') {
84
+ if (typeof value === 'string') {
85
+ issues.push({ key, code: 'coerced', value, resolved: value === 'true' });
86
+ value = value === 'true';
87
+ }
88
+ else
89
+ value = Boolean(value);
90
+ }
91
+ else if (f.control === 'range' || f.control === 'number') {
92
+ let n = typeof value === 'number' ? value : Number(value);
93
+ if (typeof value === 'string')
94
+ issues.push({ key, code: 'coerced', value, resolved: n });
95
+ if (!Number.isFinite(n))
96
+ n = f.default;
97
+ const clamped = Math.min(f.max, Math.max(f.min, n));
98
+ if (clamped !== n)
99
+ issues.push({ key, code: 'out-of-range', value: n, resolved: clamped });
100
+ value = f.snap ? snapTo(clamped, f.snap) : clamped;
101
+ }
102
+ else {
103
+ value = typeof value === 'string' ? value : String(value ?? '');
104
+ }
105
+ if (f.legacyHidden && !has)
106
+ continue; // a legacy field that was never saved stays absent
107
+ if (f.binding === 'adapter')
108
+ handles[key] = value;
109
+ else
110
+ settings[key] = value;
111
+ }
112
+ for (const key of Object.keys(input)) {
113
+ if (!(key in schema.fields))
114
+ issues.push({ key, code: 'unknown-setting', value: input[key] });
115
+ }
116
+ return { settings: settings, handles: handles, issues };
117
+ }
118
+ /** Defaults of a schema — what a brand-new section renders with. */
119
+ export function defaultsOf(schema) {
120
+ return resolveSettings(schema, {}).settings;
121
+ }
@@ -0,0 +1,8 @@
1
+ /** Set by the platform's server `render()` around the page; never in the browser. */
2
+ export declare const ServerRenderProvider: import("react").Provider<boolean>;
3
+ /**
4
+ * True while the platform renders this page on the server; false in the browser — the hydrating first render
5
+ * included. For markup the platform adds to the delivered page after the server render (the gateway's form
6
+ * fields): the browser renders it so its tree matches the page it received, the server never does.
7
+ */
8
+ export declare function useServerRender(): boolean;
@@ -0,0 +1,12 @@
1
+ import { createContext, useContext } from 'react';
2
+ const ServerRenderContext = createContext(false);
3
+ /** Set by the platform's server `render()` around the page; never in the browser. */
4
+ export const ServerRenderProvider = ServerRenderContext.Provider;
5
+ /**
6
+ * True while the platform renders this page on the server; false in the browser — the hydrating first render
7
+ * included. For markup the platform adds to the delivered page after the server render (the gateway's form
8
+ * fields): the browser renders it so its tree matches the page it received, the server never does.
9
+ */
10
+ export function useServerRender() {
11
+ return useContext(ServerRenderContext) || typeof document === 'undefined';
12
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Reading the store context: a saved handle → the object the runtime already
3
+ * put in the context (an image, a menu, a collection …). WHERE the data comes
4
+ * from is the runtime's job; these only look it up, the same way for every
5
+ * theme, including the platform rule that an unpublished or deleted handle is
6
+ * "unavailable", not missing. Nothing here fetches.
7
+ */
8
+ import type { StoreContext } from './store.js';
9
+ import type { Collection, Image, Link, Menu, Video, Product } from './types.js';
10
+ /** An image handle → the image, or null. */
11
+ export declare const imageFor: (store: StoreContext, handle: string | undefined) => Image | null;
12
+ /** A video handle → the video, or null. */
13
+ export declare const videoFor: (store: StoreContext, handle: string | undefined) => Video | null;
14
+ /** A menu handle → the menu, or null. */
15
+ export declare const menuFor: (store: StoreContext, handle: string | undefined) => Menu | null;
16
+ /** A collection handle → the collection; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
17
+ export declare function collectionFor(store: StoreContext, handle: string | undefined, fallback?: Collection): {
18
+ collection: Collection | null;
19
+ unavailable: boolean;
20
+ };
21
+ /** A product handle → the product; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
22
+ export declare function productFor(store: StoreContext, handle: string | undefined, fallback?: Product): {
23
+ product: Product | null;
24
+ unavailable: boolean;
25
+ };
26
+ /** Comma-separated collection handles (a multi-picker fallback) → links; typos and unavailable handles drop out. */
27
+ export declare function collectionLinksFor(store: StoreContext, handles: string): Link[];
@@ -0,0 +1,29 @@
1
+ /** An image handle → the image, or null. */
2
+ export const imageFor = (store, handle) => (handle ? (store.images?.[handle] ?? null) : null);
3
+ /** A video handle → the video, or null. */
4
+ export const videoFor = (store, handle) => (handle ? (store.videos?.[handle] ?? null) : null);
5
+ /** A menu handle → the menu, or null. */
6
+ export const menuFor = (store, handle) => (handle ? (store.menus[handle] ?? null) : null);
7
+ /** A collection handle → the collection; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
8
+ export function collectionFor(store, handle, fallback) {
9
+ if (handle && store.unavailableCollections?.includes(handle))
10
+ return { collection: null, unavailable: true };
11
+ return { collection: (handle ? store.collections?.[handle] : undefined) ?? fallback ?? null, unavailable: false };
12
+ }
13
+ /** A product handle → the product; an unpublished / deleted handle is `unavailable`, blank uses the fallback. */
14
+ export function productFor(store, handle, fallback) {
15
+ if (handle && store.unavailableProducts?.includes(handle))
16
+ return { product: null, unavailable: true };
17
+ return { product: (handle ? store.products?.[handle] : undefined) ?? fallback ?? null, unavailable: false };
18
+ }
19
+ /** Comma-separated collection handles (a multi-picker fallback) → links; typos and unavailable handles drop out. */
20
+ export function collectionLinksFor(store, handles) {
21
+ return handles
22
+ .split(',')
23
+ .map((h) => h.trim())
24
+ .filter(Boolean)
25
+ .flatMap((h) => {
26
+ const c = store.collections?.[h];
27
+ return c && !store.unavailableCollections?.includes(h) ? [{ title: c.title, url: c.url }] : [];
28
+ });
29
+ }
@@ -0,0 +1,149 @@
1
+ /**
2
+ * The store context a section's data binding reads: the store's data, already
3
+ * shaped as the types in ./types. The theme runtime builds it; a theme never
4
+ * fetches.
5
+ */
6
+ import type { Article, Blog, Cart, CustomerAccount, Policy, ReviewsData, SearchResults, SortOption, StoreLocation, UgcPost, BreadcrumbItem, Collection, Product, CartSummary, Customer, Image, Localization, Menu, Shop, Video, GiftCardBalance } from './types.js';
7
+ export interface SavedBlock {
8
+ /** The block's id in the saved content (`b-testimonial-1`): the editor selects a block by it (blockAttrs). */
9
+ id?: string;
10
+ type: string;
11
+ settings?: Record<string, unknown>;
12
+ /** A block that holds blocks (nested theme blocks): its own, in order. */
13
+ blocks?: SavedBlock[];
14
+ }
15
+ /**
16
+ * The attributes that make one rendered block selectable on the editor's canvas: spread them on the block's root
17
+ * element (`<li {...blockAttrs(b)}>`). The canvas bridge (storefront-edge editor-bridge) finds a block by
18
+ * `data-tq-node` inside its section's node, outlines it with `data-tq-type` as its label and scrolls to it, and a click
19
+ * inside it selects the block instead of the whole section. No id (a block from older content, a preview seed) gives
20
+ * nothing, so the section is selected as before.
21
+ */
22
+ export interface BlockRef {
23
+ id?: string;
24
+ type: string;
25
+ }
26
+ export declare function blockAttrs(block: {
27
+ id?: string | null;
28
+ type?: string | null;
29
+ } | null | undefined): {
30
+ 'data-tq-node'?: string;
31
+ 'data-tq-type'?: string;
32
+ };
33
+ export interface SavedSection {
34
+ type: string;
35
+ settings?: Record<string, unknown>;
36
+ blocks?: SavedBlock[];
37
+ }
38
+ export interface StoreContext {
39
+ shop: Shop;
40
+ menus: Record<string, Menu>;
41
+ images?: Record<string, Image>;
42
+ videos?: Record<string, Video>;
43
+ cart?: CartSummary;
44
+ customer?: Customer;
45
+ localization?: Localization | null;
46
+ /** Route context. */
47
+ breadcrumbs?: BreadcrumbItem[];
48
+ /**
49
+ * The route's base template (`index`, `product`, `collection`, `cart`, `page`, `search`, …; a template suffix is not
50
+ * part of it). A section that behaves differently on one kind of page reads it here: a product row beside the cart
51
+ * leaves out what cannot be added. Absent where the section renders with no route (the editor's single-section preview).
52
+ */
53
+ template?: string;
54
+ /** The page's first section is a hero with media (transparentOnHero). */
55
+ firstSectionIsHeroWithMedia?: boolean;
56
+ consentEnabled?: boolean;
57
+ brandColor?: string;
58
+ /** Collections by handle (collection pickers). */
59
+ collections?: Record<string, Collection>;
60
+ /** The route's collection on collection templates (collection-banner default). */
61
+ currentCollection?: Collection;
62
+ /** Handles that exist but are unpublished or deleted. */
63
+ unavailableCollections?: readonly string[];
64
+ /** The store's IANA time zone (promo-banner endsAt). */
65
+ timeZone?: string;
66
+ /** The store / server clock. */
67
+ clock?: () => number;
68
+ /** The shopper has not answered the cookie banner yet (the phone sticky bar waits). */
69
+ consentAnswered?: boolean;
70
+ /** Products by handle (product pickers). */
71
+ products?: Record<string, Product>;
72
+ /** The route's product on product templates. */
73
+ currentProduct?: Product;
74
+ /** The variant the product URL names (`?variant=`), as given; the section checks it belongs to the product. */
75
+ currentVariantId?: string;
76
+ /** Handles that exist but are unpublished or deleted. */
77
+ unavailableProducts?: readonly string[];
78
+ /** Pages by handle (size guide page). */
79
+ pages?: Record<string, {
80
+ title: string;
81
+ html: string;
82
+ }>;
83
+ /** Recommendations for the current product, by intent (platform). */
84
+ recommendations?: Partial<Record<'related' | 'complementary', Product[]>>;
85
+ /** This shopper's viewed products — null until the platform supports history + consent. */
86
+ recentlyViewed?: Product[] | null;
87
+ /** The store's newest collections (collection-list without blocks). */
88
+ newestCollections?: Collection[];
89
+ /** The page being rendered (page-body). */
90
+ currentPage?: {
91
+ title: string;
92
+ html: string;
93
+ };
94
+ /** The article being rendered and its blog (article-body). */
95
+ currentArticle?: Article & {
96
+ contentHtml?: string;
97
+ };
98
+ currentBlog?: {
99
+ title: string;
100
+ url: string;
101
+ };
102
+ /** The tag a blog page is filtered to (`/blogs/<blog>/tagged/<tag>`). */
103
+ currentTag?: string;
104
+ /** Blogs by handle (blog-posts). */
105
+ blogs?: Record<string, Blog>;
106
+ /** The current product's reviews from a reviews source — null until the platform has one (12F DATA REQUIREMENT). */
107
+ reviews?: ReviewsData | null;
108
+ /** A connected social feed for ugc-gallery source = feed — null until the platform has one. */
109
+ ugcFeed?: UgcPost[] | null;
110
+ /** 12G · the full cart for the cart page (the header only needs the summary above). */
111
+ currentCart?: Cart | null;
112
+ /** The checkout app — the only place Checkout goes. */
113
+ checkoutUrl?: string;
114
+ /** Why a cart permalink the store could not open sent the shopper to the cart page (`unavailable`, `failed`), else null. */
115
+ cartLink?: string | null;
116
+ searchQuery?: string;
117
+ searchResults?: SearchResults | null;
118
+ searchSortOptions?: SortOption[];
119
+ /** The search page's current sort id (`?sort=`); 'relevance' when none. */
120
+ searchSort?: string;
121
+ /** The signed-in customer's account (accounts app); null when signed out. */
122
+ account?: CustomerAccount | null;
123
+ /**
124
+ * The Account BFF URL to frame on the customer route (`/account*`): render
125
+ * `<iframe data-tq-slot="account" src={accountUrl} sandbox="allow-scripts allow-forms allow-same-origin">`
126
+ * (Theme ABI v2 §4, the account slot). Sign-in, orders and addresses render inside that frame; customer data
127
+ * never reaches the theme. Absent on every other route and where the host has no account area.
128
+ */
129
+ accountUrl?: string;
130
+ /** Store policies by handle, and the route's policy on policy templates. */
131
+ policies?: Record<string, Policy>;
132
+ currentPolicy?: Policy | null;
133
+ locations?: StoreLocation[];
134
+ /** Platform form endpoints, when they exist (12G DATA REQUIREMENT). */
135
+ newsletterEndpoint?: string;
136
+ contactEndpoint?: string;
137
+ /** Where ANY declared native form of this page posts (the page's own path), when the platform takes form posts. */
138
+ formEndpoint?: string;
139
+ /** The route's captured segments (a manifest custom route `/gift-card/:id` ⇒ `{ id }`); `{}` on a built-in route. */
140
+ routeParams?: Readonly<Record<string, string>>;
141
+ /** The outcome of the platform form POST this page answers (ABI native forms). */
142
+ formResult?: {
143
+ formId: string;
144
+ status: 'ok' | 'invalid' | 'rate_limited' | 'unavailable' | 'expired';
145
+ email?: string;
146
+ discountCode?: string;
147
+ giftCard?: GiftCardBalance;
148
+ };
149
+ }
@@ -0,0 +1,5 @@
1
+ export function blockAttrs(block) {
2
+ if (!block || typeof block.id !== 'string' || !block.id)
3
+ return {};
4
+ return { 'data-tq-node': block.id, ...(typeof block.type === 'string' && block.type ? { 'data-tq-type': block.type } : {}) };
5
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Dynamic style values without `style=""` attributes.
3
+ *
4
+ * The platform's CSP carries `style-src-attr 'none'` and no 'unsafe-inline' (Theme ABI v2 §5), and
5
+ * conformance fails a page whose DOM holds a style attribute at all. So a value a component computes
6
+ * (a column count, a scrim, an aspect ratio, the theme settings' CSS variables) becomes a CLASS:
7
+ *
8
+ * <ul className={cx('nv-list', sx({ '--nv-cols': columns }))}>
9
+ *
10
+ * - The class name is a hash of the declarations: the server and the hydrating browser compute the
11
+ * same name from the same values, so hydration matches.
12
+ * - Server: the entry opens a sink for exactly one synchronous `renderToString` (`collectStyles`) and
13
+ * emits its rules as ONE hashed `<style>`. Nothing outlives the render — no module cache, so no
14
+ * value of one store can reach another store's page.
15
+ * - Browser: a rule the server block does not already hold is inserted through CSSOM (a constructed
16
+ * stylesheet), which CSP does not govern.
17
+ *
18
+ * A declaration whose value could leave its rule (`<`, `{`, `}`, `;`, `\`, a newline) is dropped,
19
+ * never escaped into place.
20
+ */
21
+ import type { CSSProperties } from 'react';
22
+ /** id of the server-emitted `<style>` that carries the page's rules. */
23
+ export declare const STYLE_RULES_ID = "tq-style-rules";
24
+ export interface StyleSink {
25
+ add(className: string, declarations: string): void;
26
+ }
27
+ /** Declarations text of a style object (`prop:value;…`), unsafe values dropped. */
28
+ export declare function declarations(style: CSSProperties | Record<string, unknown>): string;
29
+ /**
30
+ * Run `render` (a synchronous `renderToString`) with a fresh sink and return its output plus the
31
+ * rules it used. The sink exists only for that call.
32
+ */
33
+ export declare function collectStyles<T>(render: () => T): {
34
+ result: T;
35
+ css: string;
36
+ };
37
+ /** `sx(style)` → a class name carrying those declarations (undefined for an empty style). */
38
+ export declare function sx(style: CSSProperties | Record<string, unknown> | null | undefined | false): string | undefined;
39
+ /** Join class names, skipping empty ones. */
40
+ export declare function cx(...names: Array<string | false | null | undefined>): string | undefined;