@cmssy/react 2.1.0 → 2.3.0

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.
package/dist/client.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyAddress, g as CmssyCart, h as CmssyOrder, i as CmssyProduct } from './commerce-queries-BFnU2_SV.cjs';
3
- export { j as CmssyCartDiscount, k as CmssyCartItem, l as CmssyCartItemSnapshot, m as CmssyOrderItem, n as CmssyProductVariant } from './commerce-queries-BFnU2_SV.cjs';
2
+ import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyAddress, g as CmssyCart, h as CmssyOrder, i as CmssyProduct } from './commerce-queries-C-qnHDOq.cjs';
3
+ export { j as CmssyCartDiscount, k as CmssyCartItem, l as CmssyCartItemSnapshot, m as CmssyOrderItem, n as CmssyProductVariant } from './commerce-queries-C-qnHDOq.cjs';
4
4
  import { ReactNode } from 'react';
5
5
  import '@cmssy/types';
6
6
 
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyAddress, g as CmssyCart, h as CmssyOrder, i as CmssyProduct } from './commerce-queries-BFnU2_SV.js';
3
- export { j as CmssyCartDiscount, k as CmssyCartItem, l as CmssyCartItemSnapshot, m as CmssyOrderItem, n as CmssyProductVariant } from './commerce-queries-BFnU2_SV.js';
2
+ import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, d as CmssyLayoutGroup, e as CmssyLocaleContext, f as CmssyAddress, g as CmssyCart, h as CmssyOrder, i as CmssyProduct } from './commerce-queries-C-qnHDOq.js';
3
+ export { j as CmssyCartDiscount, k as CmssyCartItem, l as CmssyCartItemSnapshot, m as CmssyOrderItem, n as CmssyProductVariant } from './commerce-queries-C-qnHDOq.js';
4
4
  import { ReactNode } from 'react';
5
5
  import '@cmssy/types';
6
6
 
@@ -65,9 +65,14 @@ interface RawLayoutBlock {
65
65
  order: number;
66
66
  isActive: boolean;
67
67
  }
68
+ interface CmssyLayoutSettings {
69
+ desktopWidth: number | null;
70
+ mobileBehavior: string;
71
+ }
68
72
  interface CmssyLayoutGroup {
69
73
  position: string;
70
74
  blocks: RawLayoutBlock[];
75
+ settings?: CmssyLayoutSettings | null;
71
76
  }
72
77
  declare function normalizeSlug(path: string | string[] | undefined): string;
73
78
  declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
@@ -547,4 +552,4 @@ interface CmssyOrder {
547
552
  accessToken?: string | null;
548
553
  }
549
554
 
550
- export { PROTOCOL_VERSION as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyBranding as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssyFormField as G, type CmssyFormSettings as H, type CmssyFormSubmitResponse as I, type CmssyLocalizedValue as J, type CmssyModelDefinition as K, type CmssyModelRecord as L, type CmssyOrderDiscount as M, type CmssyOrderTaxSummaryLine as N, type CmssyPageMeta as O, type CmssyPageSummary as P, type CmssyPriceTier as Q, type RawBlock as R, type CmssyRecordList as S, type CmssyShippingMethod as T, type CmssyTaxSummaryLine as U, DEFAULT_CMSSY_API_URL as V, FORM_QUERY as W, type FetchLikeResponse as X, type FetchPageOptions as Y, MODEL_DEFINITIONS_QUERY as Z, MODEL_RECORDS_QUERY as _, type BlockMeta as a, type ParentReadyMessage as a0, type PatchMessage as a1, type RawLayoutBlock as a2, type ReadyMessage as a3, SITE_CONFIG_QUERY as a4, SUBMIT_FORM_MUTATION as a5, type SelectMessage as a6, type SubmitFormInput as a7, blocksToMeta as a8, blocksToSchemas as a9, buildBlockContext as aa, buildBlockMap as ab, defineBlock as ac, fetchLayouts as ad, fetchPage as ae, fetchPageById as af, fetchPageMeta as ag, fetchPages as ah, isProtocolCompatible as ai, normalizeSlug as aj, resolveApiUrl as ak, resolvePublicUrl as al, type BlockDefinition as b, type CmssyFormDefinition as c, type CmssyLayoutGroup as d, type CmssyLocaleContext as e, type CmssyAddress as f, type CmssyCart as g, type CmssyOrder as h, type CmssyProduct as i, type CmssyCartDiscount as j, type CmssyCartItem as k, type CmssyCartItemSnapshot as l, type CmssyOrderItem as m, type CmssyProductVariant as n, type CmssyBlockAuthContext as o, type CmssyBlockWorkspace as p, type FetchLike as q, type CmssyClientConfig as r, type CmssySiteConfig as s, type BlockMap as t, type CmssyBlockContext as u, type BlockRect as v, type BoundsMessage as w, type BuildBlockContextExtra as x, type ClickMessage as y, type CmssyBlockMember as z };
555
+ export { MODEL_RECORDS_QUERY as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyBranding as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssyFormField as G, type CmssyFormSettings as H, type CmssyFormSubmitResponse as I, type CmssyLayoutSettings as J, type CmssyLocalizedValue as K, type CmssyModelDefinition as L, type CmssyModelRecord as M, type CmssyOrderDiscount as N, type CmssyOrderTaxSummaryLine as O, type CmssyPageMeta as P, type CmssyPageSummary as Q, type RawBlock as R, type CmssyPriceTier as S, type CmssyRecordList as T, type CmssyShippingMethod as U, type CmssyTaxSummaryLine as V, DEFAULT_CMSSY_API_URL as W, FORM_QUERY as X, type FetchLikeResponse as Y, type FetchPageOptions as Z, MODEL_DEFINITIONS_QUERY as _, type BlockMeta as a, PROTOCOL_VERSION as a0, type ParentReadyMessage as a1, type PatchMessage as a2, type RawLayoutBlock as a3, type ReadyMessage as a4, SITE_CONFIG_QUERY as a5, SUBMIT_FORM_MUTATION as a6, type SelectMessage as a7, type SubmitFormInput as a8, blocksToMeta as a9, blocksToSchemas as aa, buildBlockContext as ab, buildBlockMap as ac, defineBlock as ad, fetchLayouts as ae, fetchPage as af, fetchPageById as ag, fetchPageMeta as ah, fetchPages as ai, isProtocolCompatible as aj, normalizeSlug as ak, resolveApiUrl as al, resolvePublicUrl as am, type BlockDefinition as b, type CmssyFormDefinition as c, type CmssyLayoutGroup as d, type CmssyLocaleContext as e, type CmssyAddress as f, type CmssyCart as g, type CmssyOrder as h, type CmssyProduct as i, type CmssyCartDiscount as j, type CmssyCartItem as k, type CmssyCartItemSnapshot as l, type CmssyOrderItem as m, type CmssyProductVariant as n, type CmssyBlockAuthContext as o, type CmssyBlockWorkspace as p, type FetchLike as q, type CmssyClientConfig as r, type CmssySiteConfig as s, type BlockMap as t, type CmssyBlockContext as u, type BlockRect as v, type BoundsMessage as w, type BuildBlockContextExtra as x, type ClickMessage as y, type CmssyBlockMember as z };
@@ -65,9 +65,14 @@ interface RawLayoutBlock {
65
65
  order: number;
66
66
  isActive: boolean;
67
67
  }
68
+ interface CmssyLayoutSettings {
69
+ desktopWidth: number | null;
70
+ mobileBehavior: string;
71
+ }
68
72
  interface CmssyLayoutGroup {
69
73
  position: string;
70
74
  blocks: RawLayoutBlock[];
75
+ settings?: CmssyLayoutSettings | null;
71
76
  }
72
77
  declare function normalizeSlug(path: string | string[] | undefined): string;
73
78
  declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
@@ -547,4 +552,4 @@ interface CmssyOrder {
547
552
  accessToken?: string | null;
548
553
  }
549
554
 
550
- export { PROTOCOL_VERSION as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyBranding as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssyFormField as G, type CmssyFormSettings as H, type CmssyFormSubmitResponse as I, type CmssyLocalizedValue as J, type CmssyModelDefinition as K, type CmssyModelRecord as L, type CmssyOrderDiscount as M, type CmssyOrderTaxSummaryLine as N, type CmssyPageMeta as O, type CmssyPageSummary as P, type CmssyPriceTier as Q, type RawBlock as R, type CmssyRecordList as S, type CmssyShippingMethod as T, type CmssyTaxSummaryLine as U, DEFAULT_CMSSY_API_URL as V, FORM_QUERY as W, type FetchLikeResponse as X, type FetchPageOptions as Y, MODEL_DEFINITIONS_QUERY as Z, MODEL_RECORDS_QUERY as _, type BlockMeta as a, type ParentReadyMessage as a0, type PatchMessage as a1, type RawLayoutBlock as a2, type ReadyMessage as a3, SITE_CONFIG_QUERY as a4, SUBMIT_FORM_MUTATION as a5, type SelectMessage as a6, type SubmitFormInput as a7, blocksToMeta as a8, blocksToSchemas as a9, buildBlockContext as aa, buildBlockMap as ab, defineBlock as ac, fetchLayouts as ad, fetchPage as ae, fetchPageById as af, fetchPageMeta as ag, fetchPages as ah, isProtocolCompatible as ai, normalizeSlug as aj, resolveApiUrl as ak, resolvePublicUrl as al, type BlockDefinition as b, type CmssyFormDefinition as c, type CmssyLayoutGroup as d, type CmssyLocaleContext as e, type CmssyAddress as f, type CmssyCart as g, type CmssyOrder as h, type CmssyProduct as i, type CmssyCartDiscount as j, type CmssyCartItem as k, type CmssyCartItemSnapshot as l, type CmssyOrderItem as m, type CmssyProductVariant as n, type CmssyBlockAuthContext as o, type CmssyBlockWorkspace as p, type FetchLike as q, type CmssyClientConfig as r, type CmssySiteConfig as s, type BlockMap as t, type CmssyBlockContext as u, type BlockRect as v, type BoundsMessage as w, type BuildBlockContextExtra as x, type ClickMessage as y, type CmssyBlockMember as z };
555
+ export { MODEL_RECORDS_QUERY as $, type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type CmssyBranding as D, type EditorToAppMessage as E, type FieldDefinition as F, type CmssyFormField as G, type CmssyFormSettings as H, type CmssyFormSubmitResponse as I, type CmssyLayoutSettings as J, type CmssyLocalizedValue as K, type CmssyModelDefinition as L, type CmssyModelRecord as M, type CmssyOrderDiscount as N, type CmssyOrderTaxSummaryLine as O, type CmssyPageMeta as P, type CmssyPageSummary as Q, type RawBlock as R, type CmssyPriceTier as S, type CmssyRecordList as T, type CmssyShippingMethod as U, type CmssyTaxSummaryLine as V, DEFAULT_CMSSY_API_URL as W, FORM_QUERY as X, type FetchLikeResponse as Y, type FetchPageOptions as Z, MODEL_DEFINITIONS_QUERY as _, type BlockMeta as a, PROTOCOL_VERSION as a0, type ParentReadyMessage as a1, type PatchMessage as a2, type RawLayoutBlock as a3, type ReadyMessage as a4, SITE_CONFIG_QUERY as a5, SUBMIT_FORM_MUTATION as a6, type SelectMessage as a7, type SubmitFormInput as a8, blocksToMeta as a9, blocksToSchemas as aa, buildBlockContext as ab, buildBlockMap as ac, defineBlock as ad, fetchLayouts as ae, fetchPage as af, fetchPageById as ag, fetchPageMeta as ah, fetchPages as ai, isProtocolCompatible as aj, normalizeSlug as ak, resolveApiUrl as al, resolvePublicUrl as am, type BlockDefinition as b, type CmssyFormDefinition as c, type CmssyLayoutGroup as d, type CmssyLocaleContext as e, type CmssyAddress as f, type CmssyCart as g, type CmssyOrder as h, type CmssyProduct as i, type CmssyCartDiscount as j, type CmssyCartItem as k, type CmssyCartItemSnapshot as l, type CmssyOrderItem as m, type CmssyProductVariant as n, type CmssyBlockAuthContext as o, type CmssyBlockWorkspace as p, type FetchLike as q, type CmssyClientConfig as r, type CmssySiteConfig as s, type BlockMap as t, type CmssyBlockContext as u, type BlockRect as v, type BoundsMessage as w, type BuildBlockContextExtra as x, type ClickMessage as y, type CmssyBlockMember as z };
package/dist/index.cjs CHANGED
@@ -78,6 +78,21 @@ function blocksToMeta(blocks, defaults = {}) {
78
78
  return out;
79
79
  }
80
80
 
81
+ // src/components/block-context.ts
82
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
83
+ return {
84
+ locale: {
85
+ current: locale,
86
+ default: defaultLocale,
87
+ enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
88
+ },
89
+ isPreview: isPreview ?? false,
90
+ forms,
91
+ ...extra?.auth ? { auth: extra.auth } : {},
92
+ ...extra?.workspace ? { workspace: extra.workspace } : {}
93
+ };
94
+ }
95
+
81
96
  // src/content/get-block-content.ts
82
97
  function isPlainObject(value) {
83
98
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -104,21 +119,6 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
104
119
  function asBucket(value) {
105
120
  return isPlainObject(value) ? value : {};
106
121
  }
107
-
108
- // src/components/block-context.ts
109
- function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
110
- return {
111
- locale: {
112
- current: locale,
113
- default: defaultLocale,
114
- enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
115
- },
116
- isPreview: isPreview ?? false,
117
- forms,
118
- ...extra?.auth ? { auth: extra.auth } : {},
119
- ...extra?.workspace ? { workspace: extra.workspace } : {}
120
- };
121
- }
122
122
  var WARN_CAP = 256;
123
123
  var warned = /* @__PURE__ */ new Set();
124
124
  function UnknownBlock({ type }) {
@@ -155,29 +155,11 @@ function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
155
155
  block.id
156
156
  );
157
157
  }
158
- async function CmssyServerPage({
159
- page,
160
- blocks,
161
- locale = "en",
162
- defaultLocale = "en",
163
- enabledLocales,
164
- forms,
165
- auth,
166
- workspace
167
- }) {
168
- if (!page) return null;
169
- const map = buildBlockMap(blocks);
170
- const loaderMap = buildLoaderMap(blocks);
171
- const context = buildBlockContext(
172
- locale,
173
- defaultLocale,
174
- enabledLocales,
175
- false,
176
- forms,
177
- { auth, workspace }
178
- );
179
- const resolved = await Promise.all(
180
- page.blocks.map(async (block) => {
158
+
159
+ // src/components/resolve-blocks.ts
160
+ async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales) {
161
+ return Promise.all(
162
+ blocks.map(async (block) => {
181
163
  const content = getBlockContentForLanguage(
182
164
  block.content,
183
165
  locale,
@@ -201,6 +183,36 @@ async function CmssyServerPage({
201
183
  return { content, data };
202
184
  })
203
185
  );
186
+ }
187
+ async function CmssyServerPage({
188
+ page,
189
+ blocks,
190
+ locale = "en",
191
+ defaultLocale = "en",
192
+ enabledLocales,
193
+ forms,
194
+ auth,
195
+ workspace
196
+ }) {
197
+ if (!page) return null;
198
+ const map = buildBlockMap(blocks);
199
+ const loaderMap = buildLoaderMap(blocks);
200
+ const context = buildBlockContext(
201
+ locale,
202
+ defaultLocale,
203
+ enabledLocales,
204
+ false,
205
+ forms,
206
+ { auth, workspace }
207
+ );
208
+ const resolved = await resolveBlocks(
209
+ page.blocks,
210
+ loaderMap,
211
+ locale,
212
+ defaultLocale,
213
+ context,
214
+ enabledLocales
215
+ );
204
216
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: page.blocks.map(
205
217
  (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
206
218
  context,
@@ -210,7 +222,7 @@ async function CmssyServerPage({
210
222
  })
211
223
  ) });
212
224
  }
213
- function CmssyServerLayout({
225
+ async function CmssyServerLayout({
214
226
  groups,
215
227
  blocks,
216
228
  position,
@@ -222,10 +234,21 @@ function CmssyServerLayout({
222
234
  const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
223
235
  if (layoutBlocks.length === 0) return null;
224
236
  const map = buildBlockMap(blocks);
237
+ const loaderMap = buildLoaderMap(blocks);
225
238
  const context = buildBlockContext(locale, defaultLocale, enabledLocales);
239
+ const resolved = await resolveBlocks(
240
+ layoutBlocks,
241
+ loaderMap,
242
+ locale,
243
+ defaultLocale,
244
+ context,
245
+ enabledLocales
246
+ );
226
247
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: layoutBlocks.map(
227
- (block) => renderResolvedBlock(block, map, locale, defaultLocale, {
248
+ (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
228
249
  context,
250
+ data: resolved[i]?.data,
251
+ resolvedContent: resolved[i]?.content,
229
252
  enabledLocales
230
253
  })
231
254
  ) });
@@ -395,6 +418,7 @@ var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!
395
418
  layouts(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug, previewSecret: $previewSecret) {
396
419
  position
397
420
  blocks { id type content style advanced order isActive }
421
+ settings { desktopWidth mobileBehavior }
398
422
  }
399
423
  }
400
424
  }
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, o as CmssyBlockAuthContext, p as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, q as FetchLike, r as CmssyClientConfig, s as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, t as BlockMap, u as CmssyBlockContext } from './commerce-queries-BFnU2_SV.cjs';
2
- export { a as BlockMeta, v as BlockRect, B as BlockSchema, w as BoundsMessage, x as BuildBlockContextExtra, y as ClickMessage, f as CmssyAddress, z as CmssyBlockMember, D as CmssyBranding, g as CmssyCart, j as CmssyCartDiscount, k as CmssyCartItem, l as CmssyCartItemSnapshot, G as CmssyFormField, H as CmssyFormSettings, I as CmssyFormSubmitResponse, J as CmssyLocalizedValue, K as CmssyModelDefinition, L as CmssyModelRecord, h as CmssyOrder, M as CmssyOrderDiscount, m as CmssyOrderItem, N as CmssyOrderTaxSummaryLine, O as CmssyPageMeta, P as CmssyPageSummary, Q as CmssyPriceTier, i as CmssyProduct, n as CmssyProductVariant, S as CmssyRecordList, T as CmssyShippingMethod, U as CmssyTaxSummaryLine, V as DEFAULT_CMSSY_API_URL, W as FORM_QUERY, X as FetchLikeResponse, Y as FetchPageOptions, Z as MODEL_DEFINITIONS_QUERY, _ as MODEL_RECORDS_QUERY, $ as PROTOCOL_VERSION, a0 as ParentReadyMessage, a1 as PatchMessage, a2 as RawLayoutBlock, a3 as ReadyMessage, a4 as SITE_CONFIG_QUERY, a5 as SUBMIT_FORM_MUTATION, a6 as SelectMessage, a7 as SubmitFormInput, a8 as blocksToMeta, a9 as blocksToSchemas, aa as buildBlockContext, ab as buildBlockMap, ac as defineBlock, ad as fetchLayouts, ae as fetchPage, af as fetchPageById, ag as fetchPageMeta, ah as fetchPages, ai as isProtocolCompatible, aj as normalizeSlug, ak as resolveApiUrl, al as resolvePublicUrl } from './commerce-queries-BFnU2_SV.cjs';
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, o as CmssyBlockAuthContext, p as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, q as FetchLike, r as CmssyClientConfig, s as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, t as BlockMap, u as CmssyBlockContext } from './commerce-queries-C-qnHDOq.cjs';
2
+ export { a as BlockMeta, v as BlockRect, B as BlockSchema, w as BoundsMessage, x as BuildBlockContextExtra, y as ClickMessage, f as CmssyAddress, z as CmssyBlockMember, D as CmssyBranding, g as CmssyCart, j as CmssyCartDiscount, k as CmssyCartItem, l as CmssyCartItemSnapshot, G as CmssyFormField, H as CmssyFormSettings, I as CmssyFormSubmitResponse, J as CmssyLayoutSettings, K as CmssyLocalizedValue, L as CmssyModelDefinition, M as CmssyModelRecord, h as CmssyOrder, N as CmssyOrderDiscount, m as CmssyOrderItem, O as CmssyOrderTaxSummaryLine, P as CmssyPageMeta, Q as CmssyPageSummary, S as CmssyPriceTier, i as CmssyProduct, n as CmssyProductVariant, T as CmssyRecordList, U as CmssyShippingMethod, V as CmssyTaxSummaryLine, W as DEFAULT_CMSSY_API_URL, X as FORM_QUERY, Y as FetchLikeResponse, Z as FetchPageOptions, _ as MODEL_DEFINITIONS_QUERY, $ as MODEL_RECORDS_QUERY, a0 as PROTOCOL_VERSION, a1 as ParentReadyMessage, a2 as PatchMessage, a3 as RawLayoutBlock, a4 as ReadyMessage, a5 as SITE_CONFIG_QUERY, a6 as SUBMIT_FORM_MUTATION, a7 as SelectMessage, a8 as SubmitFormInput, a9 as blocksToMeta, aa as blocksToSchemas, ab as buildBlockContext, ac as buildBlockMap, ad as defineBlock, ae as fetchLayouts, af as fetchPage, ag as fetchPageById, ah as fetchPageMeta, ai as fetchPages, aj as isProtocolCompatible, ak as normalizeSlug, al as resolveApiUrl, am as resolvePublicUrl } from './commerce-queries-C-qnHDOq.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  export { FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldType, evaluateFieldConditionGroup } from '@cmssy/types';
5
5
  import 'react';
@@ -61,7 +61,12 @@ interface CmssyServerLayoutProps {
61
61
  /** All languages enabled on the workspace; exposed to blocks via context.locale.enabled. */
62
62
  enabledLocales?: string[];
63
63
  }
64
- declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, }: CmssyServerLayoutProps): react_jsx_runtime.JSX.Element | null;
64
+ /**
65
+ * Async React Server Component. Like CmssyServerPage it runs each block's
66
+ * loader server-side before rendering, so a header block can list categories
67
+ * the same way a page block can. Must be rendered in a server component tree.
68
+ */
69
+ declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, }: CmssyServerLayoutProps): Promise<react_jsx_runtime.JSX.Element | null>;
65
70
 
66
71
  interface PostTarget {
67
72
  postMessage: (message: unknown, targetOrigin: string) => void;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, o as CmssyBlockAuthContext, p as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, q as FetchLike, r as CmssyClientConfig, s as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, t as BlockMap, u as CmssyBlockContext } from './commerce-queries-BFnU2_SV.js';
2
- export { a as BlockMeta, v as BlockRect, B as BlockSchema, w as BoundsMessage, x as BuildBlockContextExtra, y as ClickMessage, f as CmssyAddress, z as CmssyBlockMember, D as CmssyBranding, g as CmssyCart, j as CmssyCartDiscount, k as CmssyCartItem, l as CmssyCartItemSnapshot, G as CmssyFormField, H as CmssyFormSettings, I as CmssyFormSubmitResponse, J as CmssyLocalizedValue, K as CmssyModelDefinition, L as CmssyModelRecord, h as CmssyOrder, M as CmssyOrderDiscount, m as CmssyOrderItem, N as CmssyOrderTaxSummaryLine, O as CmssyPageMeta, P as CmssyPageSummary, Q as CmssyPriceTier, i as CmssyProduct, n as CmssyProductVariant, S as CmssyRecordList, T as CmssyShippingMethod, U as CmssyTaxSummaryLine, V as DEFAULT_CMSSY_API_URL, W as FORM_QUERY, X as FetchLikeResponse, Y as FetchPageOptions, Z as MODEL_DEFINITIONS_QUERY, _ as MODEL_RECORDS_QUERY, $ as PROTOCOL_VERSION, a0 as ParentReadyMessage, a1 as PatchMessage, a2 as RawLayoutBlock, a3 as ReadyMessage, a4 as SITE_CONFIG_QUERY, a5 as SUBMIT_FORM_MUTATION, a6 as SelectMessage, a7 as SubmitFormInput, a8 as blocksToMeta, a9 as blocksToSchemas, aa as buildBlockContext, ab as buildBlockMap, ac as defineBlock, ad as fetchLayouts, ae as fetchPage, af as fetchPageById, ag as fetchPageMeta, ah as fetchPages, ai as isProtocolCompatible, aj as normalizeSlug, ak as resolveApiUrl, al as resolvePublicUrl } from './commerce-queries-BFnU2_SV.js';
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyFormDefinition, o as CmssyBlockAuthContext, p as CmssyBlockWorkspace, d as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, q as FetchLike, r as CmssyClientConfig, s as CmssySiteConfig, R as RawBlock, e as CmssyLocaleContext, t as BlockMap, u as CmssyBlockContext } from './commerce-queries-C-qnHDOq.js';
2
+ export { a as BlockMeta, v as BlockRect, B as BlockSchema, w as BoundsMessage, x as BuildBlockContextExtra, y as ClickMessage, f as CmssyAddress, z as CmssyBlockMember, D as CmssyBranding, g as CmssyCart, j as CmssyCartDiscount, k as CmssyCartItem, l as CmssyCartItemSnapshot, G as CmssyFormField, H as CmssyFormSettings, I as CmssyFormSubmitResponse, J as CmssyLayoutSettings, K as CmssyLocalizedValue, L as CmssyModelDefinition, M as CmssyModelRecord, h as CmssyOrder, N as CmssyOrderDiscount, m as CmssyOrderItem, O as CmssyOrderTaxSummaryLine, P as CmssyPageMeta, Q as CmssyPageSummary, S as CmssyPriceTier, i as CmssyProduct, n as CmssyProductVariant, T as CmssyRecordList, U as CmssyShippingMethod, V as CmssyTaxSummaryLine, W as DEFAULT_CMSSY_API_URL, X as FORM_QUERY, Y as FetchLikeResponse, Z as FetchPageOptions, _ as MODEL_DEFINITIONS_QUERY, $ as MODEL_RECORDS_QUERY, a0 as PROTOCOL_VERSION, a1 as ParentReadyMessage, a2 as PatchMessage, a3 as RawLayoutBlock, a4 as ReadyMessage, a5 as SITE_CONFIG_QUERY, a6 as SUBMIT_FORM_MUTATION, a7 as SelectMessage, a8 as SubmitFormInput, a9 as blocksToMeta, aa as blocksToSchemas, ab as buildBlockContext, ac as buildBlockMap, ad as defineBlock, ae as fetchLayouts, af as fetchPage, ag as fetchPageById, ah as fetchPageMeta, ai as fetchPages, aj as isProtocolCompatible, ak as normalizeSlug, al as resolveApiUrl, am as resolvePublicUrl } from './commerce-queries-C-qnHDOq.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  export { FieldCondition, FieldConditionGroup, FieldConditionLogic, FieldType, evaluateFieldConditionGroup } from '@cmssy/types';
5
5
  import 'react';
@@ -61,7 +61,12 @@ interface CmssyServerLayoutProps {
61
61
  /** All languages enabled on the workspace; exposed to blocks via context.locale.enabled. */
62
62
  enabledLocales?: string[];
63
63
  }
64
- declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, }: CmssyServerLayoutProps): react_jsx_runtime.JSX.Element | null;
64
+ /**
65
+ * Async React Server Component. Like CmssyServerPage it runs each block's
66
+ * loader server-side before rendering, so a header block can list categories
67
+ * the same way a page block can. Must be rendered in a server component tree.
68
+ */
69
+ declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, }: CmssyServerLayoutProps): Promise<react_jsx_runtime.JSX.Element | null>;
65
70
 
66
71
  interface PostTarget {
67
72
  postMessage: (message: unknown, targetOrigin: string) => void;
package/dist/index.js CHANGED
@@ -76,6 +76,21 @@ function blocksToMeta(blocks, defaults = {}) {
76
76
  return out;
77
77
  }
78
78
 
79
+ // src/components/block-context.ts
80
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
81
+ return {
82
+ locale: {
83
+ current: locale,
84
+ default: defaultLocale,
85
+ enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
86
+ },
87
+ isPreview: isPreview ?? false,
88
+ forms,
89
+ ...extra?.auth ? { auth: extra.auth } : {},
90
+ ...extra?.workspace ? { workspace: extra.workspace } : {}
91
+ };
92
+ }
93
+
79
94
  // src/content/get-block-content.ts
80
95
  function isPlainObject(value) {
81
96
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -102,21 +117,6 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
102
117
  function asBucket(value) {
103
118
  return isPlainObject(value) ? value : {};
104
119
  }
105
-
106
- // src/components/block-context.ts
107
- function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview, forms, extra) {
108
- return {
109
- locale: {
110
- current: locale,
111
- default: defaultLocale,
112
- enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
113
- },
114
- isPreview: isPreview ?? false,
115
- forms,
116
- ...extra?.auth ? { auth: extra.auth } : {},
117
- ...extra?.workspace ? { workspace: extra.workspace } : {}
118
- };
119
- }
120
120
  var WARN_CAP = 256;
121
121
  var warned = /* @__PURE__ */ new Set();
122
122
  function UnknownBlock({ type }) {
@@ -153,29 +153,11 @@ function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
153
153
  block.id
154
154
  );
155
155
  }
156
- async function CmssyServerPage({
157
- page,
158
- blocks,
159
- locale = "en",
160
- defaultLocale = "en",
161
- enabledLocales,
162
- forms,
163
- auth,
164
- workspace
165
- }) {
166
- if (!page) return null;
167
- const map = buildBlockMap(blocks);
168
- const loaderMap = buildLoaderMap(blocks);
169
- const context = buildBlockContext(
170
- locale,
171
- defaultLocale,
172
- enabledLocales,
173
- false,
174
- forms,
175
- { auth, workspace }
176
- );
177
- const resolved = await Promise.all(
178
- page.blocks.map(async (block) => {
156
+
157
+ // src/components/resolve-blocks.ts
158
+ async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales) {
159
+ return Promise.all(
160
+ blocks.map(async (block) => {
179
161
  const content = getBlockContentForLanguage(
180
162
  block.content,
181
163
  locale,
@@ -199,6 +181,36 @@ async function CmssyServerPage({
199
181
  return { content, data };
200
182
  })
201
183
  );
184
+ }
185
+ async function CmssyServerPage({
186
+ page,
187
+ blocks,
188
+ locale = "en",
189
+ defaultLocale = "en",
190
+ enabledLocales,
191
+ forms,
192
+ auth,
193
+ workspace
194
+ }) {
195
+ if (!page) return null;
196
+ const map = buildBlockMap(blocks);
197
+ const loaderMap = buildLoaderMap(blocks);
198
+ const context = buildBlockContext(
199
+ locale,
200
+ defaultLocale,
201
+ enabledLocales,
202
+ false,
203
+ forms,
204
+ { auth, workspace }
205
+ );
206
+ const resolved = await resolveBlocks(
207
+ page.blocks,
208
+ loaderMap,
209
+ locale,
210
+ defaultLocale,
211
+ context,
212
+ enabledLocales
213
+ );
202
214
  return /* @__PURE__ */ jsx(Fragment, { children: page.blocks.map(
203
215
  (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
204
216
  context,
@@ -208,7 +220,7 @@ async function CmssyServerPage({
208
220
  })
209
221
  ) });
210
222
  }
211
- function CmssyServerLayout({
223
+ async function CmssyServerLayout({
212
224
  groups,
213
225
  blocks,
214
226
  position,
@@ -220,10 +232,21 @@ function CmssyServerLayout({
220
232
  const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
221
233
  if (layoutBlocks.length === 0) return null;
222
234
  const map = buildBlockMap(blocks);
235
+ const loaderMap = buildLoaderMap(blocks);
223
236
  const context = buildBlockContext(locale, defaultLocale, enabledLocales);
237
+ const resolved = await resolveBlocks(
238
+ layoutBlocks,
239
+ loaderMap,
240
+ locale,
241
+ defaultLocale,
242
+ context,
243
+ enabledLocales
244
+ );
224
245
  return /* @__PURE__ */ jsx(Fragment, { children: layoutBlocks.map(
225
- (block) => renderResolvedBlock(block, map, locale, defaultLocale, {
246
+ (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
226
247
  context,
248
+ data: resolved[i]?.data,
249
+ resolvedContent: resolved[i]?.content,
227
250
  enabledLocales
228
251
  })
229
252
  ) });
@@ -393,6 +416,7 @@ var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!
393
416
  layouts(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug, previewSecret: $previewSecret) {
394
417
  position
395
418
  blocks { id type content style advanced order isActive }
419
+ settings { desktopWidth mobileBehavior }
396
420
  }
397
421
  }
398
422
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",