@cmssy/react 8.0.0 → 8.0.2

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.cjs CHANGED
@@ -441,7 +441,8 @@ function CmssyBlock({
441
441
  patchedAdvanced,
442
442
  editable,
443
443
  layoutPosition,
444
- context
444
+ context,
445
+ data
445
446
  }) {
446
447
  const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
447
448
  const base = core.getBlockContentForLanguage(block.content, locale, defaultLocale);
@@ -460,7 +461,8 @@ function CmssyBlock({
460
461
  content,
461
462
  style,
462
463
  advanced,
463
- context
464
+ context,
465
+ data
464
466
  }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
465
467
  }
466
468
  );
@@ -473,7 +475,8 @@ function CmssyEditablePage({
473
475
  enabledLocales,
474
476
  edit,
475
477
  category,
476
- forms
478
+ forms,
479
+ data
477
480
  }) {
478
481
  if (!Array.isArray(blocks)) {
479
482
  throw new Error(
@@ -491,7 +494,8 @@ function CmssyEditablePage({
491
494
  enabledLocales,
492
495
  edit,
493
496
  category,
494
- forms
497
+ forms,
498
+ data
495
499
  }
496
500
  );
497
501
  }
@@ -503,7 +507,8 @@ function EditableBlocks({
503
507
  enabledLocales,
504
508
  edit,
505
509
  category,
506
- forms
510
+ forms,
511
+ data
507
512
  }) {
508
513
  const blockMap = react.useMemo(() => buildBlockMap(blocks), [blocks]);
509
514
  const context = react.useMemo(
@@ -555,7 +560,8 @@ function EditableBlocks({
555
560
  patchedAdvanced: patchesAdvanced[block.id],
556
561
  blockMap,
557
562
  editable: true,
558
- context
563
+ context,
564
+ data: data?.[block.id]
559
565
  },
560
566
  block.id
561
567
  )),
package/dist/client.d.cts CHANGED
@@ -47,8 +47,9 @@ interface CmssyEditablePageProps {
47
47
  edit: EditBridgeConfig;
48
48
  category?: string;
49
49
  forms?: Record<string, CmssyFormDefinition>;
50
+ data?: Record<string, unknown>;
50
51
  }
51
- declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, forms, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
52
+ declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, forms, data, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
52
53
 
53
54
  interface CmssyLazyEditorProps {
54
55
  page: CmssyPageData | null;
@@ -57,6 +58,7 @@ interface CmssyLazyEditorProps {
57
58
  enabledLocales?: string[];
58
59
  edit: EditBridgeConfig;
59
60
  forms?: Record<string, CmssyFormDefinition>;
61
+ data?: Record<string, unknown>;
60
62
  load: () => Promise<{
61
63
  blocks: BlockDefinition[];
62
64
  category?: string;
package/dist/client.d.ts CHANGED
@@ -47,8 +47,9 @@ interface CmssyEditablePageProps {
47
47
  edit: EditBridgeConfig;
48
48
  category?: string;
49
49
  forms?: Record<string, CmssyFormDefinition>;
50
+ data?: Record<string, unknown>;
50
51
  }
51
- declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, forms, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
52
+ declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, forms, data, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
52
53
 
53
54
  interface CmssyLazyEditorProps {
54
55
  page: CmssyPageData | null;
@@ -57,6 +58,7 @@ interface CmssyLazyEditorProps {
57
58
  enabledLocales?: string[];
58
59
  edit: EditBridgeConfig;
59
60
  forms?: Record<string, CmssyFormDefinition>;
61
+ data?: Record<string, unknown>;
60
62
  load: () => Promise<{
61
63
  blocks: BlockDefinition[];
62
64
  category?: string;
package/dist/client.js CHANGED
@@ -440,7 +440,8 @@ function CmssyBlock({
440
440
  patchedAdvanced,
441
441
  editable,
442
442
  layoutPosition,
443
- context
443
+ context,
444
+ data
444
445
  }) {
445
446
  const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
446
447
  const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
@@ -459,7 +460,8 @@ function CmssyBlock({
459
460
  content,
460
461
  style,
461
462
  advanced,
462
- context
463
+ context,
464
+ data
463
465
  }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
464
466
  }
465
467
  );
@@ -472,7 +474,8 @@ function CmssyEditablePage({
472
474
  enabledLocales,
473
475
  edit,
474
476
  category,
475
- forms
477
+ forms,
478
+ data
476
479
  }) {
477
480
  if (!Array.isArray(blocks)) {
478
481
  throw new Error(
@@ -490,7 +493,8 @@ function CmssyEditablePage({
490
493
  enabledLocales,
491
494
  edit,
492
495
  category,
493
- forms
496
+ forms,
497
+ data
494
498
  }
495
499
  );
496
500
  }
@@ -502,7 +506,8 @@ function EditableBlocks({
502
506
  enabledLocales,
503
507
  edit,
504
508
  category,
505
- forms
509
+ forms,
510
+ data
506
511
  }) {
507
512
  const blockMap = useMemo(() => buildBlockMap(blocks), [blocks]);
508
513
  const context = useMemo(
@@ -554,7 +559,8 @@ function EditableBlocks({
554
559
  patchedAdvanced: patchesAdvanced[block.id],
555
560
  blockMap,
556
561
  editable: true,
557
- context
562
+ context,
563
+ data: data?.[block.id]
558
564
  },
559
565
  block.id
560
566
  )),
package/dist/index.cjs CHANGED
@@ -184,6 +184,39 @@ async function CmssyServerPage({
184
184
  })
185
185
  ) });
186
186
  }
187
+ async function resolveBlockData({
188
+ page,
189
+ blocks,
190
+ locale,
191
+ defaultLocale,
192
+ enabledLocales,
193
+ forms,
194
+ isPreview = false
195
+ }) {
196
+ if (!page) return {};
197
+ const loaderMap = buildLoaderMap(blocks);
198
+ const context = core.buildBlockContext(
199
+ locale,
200
+ defaultLocale,
201
+ enabledLocales,
202
+ isPreview,
203
+ forms
204
+ );
205
+ const resolved = await resolveBlocks(
206
+ page.blocks,
207
+ loaderMap,
208
+ locale,
209
+ defaultLocale,
210
+ context,
211
+ enabledLocales
212
+ );
213
+ const data = {};
214
+ page.blocks.forEach((block, index) => {
215
+ const value = resolved[index]?.data;
216
+ if (value !== void 0) data[block.id] = value;
217
+ });
218
+ return data;
219
+ }
187
220
  async function CmssyServerLayout({
188
221
  groups,
189
222
  blocks,
@@ -232,7 +265,8 @@ function CmssyBlock({
232
265
  patchedAdvanced,
233
266
  editable,
234
267
  layoutPosition,
235
- context
268
+ context,
269
+ data
236
270
  }) {
237
271
  const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
238
272
  const base = core.getBlockContentForLanguage(block.content, locale, defaultLocale);
@@ -251,7 +285,8 @@ function CmssyBlock({
251
285
  content,
252
286
  style,
253
287
  advanced,
254
- context
288
+ context,
289
+ data
255
290
  }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
256
291
  }
257
292
  );
@@ -405,3 +440,4 @@ exports.blocksToMeta = blocksToMeta;
405
440
  exports.blocksToSchemas = blocksToSchemas;
406
441
  exports.buildBlockMap = buildBlockMap;
407
442
  exports.defineBlock = defineBlock;
443
+ exports.resolveBlockData = resolveBlockData;
package/dist/index.d.cts CHANGED
@@ -32,6 +32,17 @@ interface CmssyServerPageProps {
32
32
  */
33
33
  declare function CmssyServerPage({ page, blocks, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, forms, auth, workspace, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
34
34
 
35
+ interface ResolveBlockDataOptions {
36
+ page: CmssyPageData | null;
37
+ blocks: BlockDefinition[];
38
+ locale: string;
39
+ defaultLocale: string;
40
+ enabledLocales?: string[];
41
+ forms?: Record<string, CmssyFormDefinition>;
42
+ isPreview?: boolean;
43
+ }
44
+ declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
45
+
35
46
  interface CmssyServerLayoutProps {
36
47
  groups: CmssyLayoutGroup[];
37
48
  blocks: BlockDefinition[];
@@ -65,12 +76,13 @@ interface CmssyBlockProps {
65
76
  editable?: boolean;
66
77
  layoutPosition?: string;
67
78
  context?: CmssyBlockContext;
79
+ data?: unknown;
68
80
  }
69
- declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
81
+ declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, layoutPosition, context, data, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
70
82
 
71
83
  interface UnknownBlockProps {
72
84
  type: string;
73
85
  }
74
86
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
75
87
 
76
- export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, UnknownBlock, type UnknownBlockProps };
88
+ export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type ResolveBlockDataOptions, UnknownBlock, type UnknownBlockProps, resolveBlockData };
package/dist/index.d.ts CHANGED
@@ -32,6 +32,17 @@ interface CmssyServerPageProps {
32
32
  */
33
33
  declare function CmssyServerPage({ page, blocks, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, forms, auth, workspace, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
34
34
 
35
+ interface ResolveBlockDataOptions {
36
+ page: CmssyPageData | null;
37
+ blocks: BlockDefinition[];
38
+ locale: string;
39
+ defaultLocale: string;
40
+ enabledLocales?: string[];
41
+ forms?: Record<string, CmssyFormDefinition>;
42
+ isPreview?: boolean;
43
+ }
44
+ declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
45
+
35
46
  interface CmssyServerLayoutProps {
36
47
  groups: CmssyLayoutGroup[];
37
48
  blocks: BlockDefinition[];
@@ -65,12 +76,13 @@ interface CmssyBlockProps {
65
76
  editable?: boolean;
66
77
  layoutPosition?: string;
67
78
  context?: CmssyBlockContext;
79
+ data?: unknown;
68
80
  }
69
- declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
81
+ declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, layoutPosition, context, data, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
70
82
 
71
83
  interface UnknownBlockProps {
72
84
  type: string;
73
85
  }
74
86
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
75
87
 
76
- export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, UnknownBlock, type UnknownBlockProps };
88
+ export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type ResolveBlockDataOptions, UnknownBlock, type UnknownBlockProps, resolveBlockData };
package/dist/index.js CHANGED
@@ -183,6 +183,39 @@ async function CmssyServerPage({
183
183
  })
184
184
  ) });
185
185
  }
186
+ async function resolveBlockData({
187
+ page,
188
+ blocks,
189
+ locale,
190
+ defaultLocale,
191
+ enabledLocales,
192
+ forms,
193
+ isPreview = false
194
+ }) {
195
+ if (!page) return {};
196
+ const loaderMap = buildLoaderMap(blocks);
197
+ const context = buildBlockContext(
198
+ locale,
199
+ defaultLocale,
200
+ enabledLocales,
201
+ isPreview,
202
+ forms
203
+ );
204
+ const resolved = await resolveBlocks(
205
+ page.blocks,
206
+ loaderMap,
207
+ locale,
208
+ defaultLocale,
209
+ context,
210
+ enabledLocales
211
+ );
212
+ const data = {};
213
+ page.blocks.forEach((block, index) => {
214
+ const value = resolved[index]?.data;
215
+ if (value !== void 0) data[block.id] = value;
216
+ });
217
+ return data;
218
+ }
186
219
  async function CmssyServerLayout({
187
220
  groups,
188
221
  blocks,
@@ -231,7 +264,8 @@ function CmssyBlock({
231
264
  patchedAdvanced,
232
265
  editable,
233
266
  layoutPosition,
234
- context
267
+ context,
268
+ data
235
269
  }) {
236
270
  const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
237
271
  const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
@@ -250,10 +284,11 @@ function CmssyBlock({
250
284
  content,
251
285
  style,
252
286
  advanced,
253
- context
287
+ context,
288
+ data
254
289
  }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
255
290
  }
256
291
  );
257
292
  }
258
293
 
259
- export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, blocksToMeta, blocksToSchemas, buildBlockMap, defineBlock };
294
+ export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, blocksToMeta, blocksToSchemas, buildBlockMap, defineBlock, resolveBlockData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@cmssy/types": "0.28.0",
60
- "@cmssy/core": "8.0.0"
60
+ "@cmssy/core": "8.0.2"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsup",