@cmssy/react 9.5.0 → 9.6.1

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
@@ -522,6 +522,7 @@ function CmssyBlock({
522
522
  patchedContent,
523
523
  patchedStyle,
524
524
  patchedAdvanced,
525
+ schema,
525
526
  editable,
526
527
  editMode,
527
528
  layoutPosition,
@@ -569,6 +570,7 @@ function CmssyBlock({
569
570
  }
570
571
  const base = core.getBlockContentForLanguage(block.content, locale, defaultLocale);
571
572
  const content = patchedContent ? { ...base, ...patchedContent } : base;
573
+ if (schema) core.normalizeRelationContent(content, schema);
572
574
  const style = patchedStyle ? { ...core.asBucket(block.style), ...patchedStyle } : core.asBucket(block.style);
573
575
  const advanced = patchedAdvanced ? { ...core.asBucket(block.advanced), ...patchedAdvanced } : core.asBucket(block.advanced);
574
576
  return wrap(
@@ -680,6 +682,7 @@ function EditableBlocks({
680
682
  patchedContent: patches[block.id],
681
683
  patchedStyle: patchesStyle[block.id],
682
684
  patchedAdvanced: patchesAdvanced[block.id],
685
+ schema: bridgeConfig.schemas?.[block.type],
683
686
  blockMap,
684
687
  editable: true,
685
688
  context,
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { createContext, useState, useRef, useEffect, useMemo, useContext, useCallback, createElement } from 'react';
3
- import { fields, resolveInitialTarget, buildBlockContext, postToEditor, PROTOCOL_VERSION, parseEditorMessage, getBlockContentForLanguage, asBucket, toMinorUnits, formatPrice } from '@cmssy/core';
3
+ import { fields, resolveInitialTarget, buildBlockContext, postToEditor, PROTOCOL_VERSION, parseEditorMessage, getBlockContentForLanguage, normalizeRelationContent, asBucket, toMinorUnits, formatPrice } from '@cmssy/core';
4
4
  export { formatPrice, fractionDigits, fromMinorUnits, toMinorUnits } from '@cmssy/core';
5
5
  import { BlockErrorBoundary } from '@cmssy/react/block-error-boundary';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -521,6 +521,7 @@ function CmssyBlock({
521
521
  patchedContent,
522
522
  patchedStyle,
523
523
  patchedAdvanced,
524
+ schema,
524
525
  editable,
525
526
  editMode,
526
527
  layoutPosition,
@@ -568,6 +569,7 @@ function CmssyBlock({
568
569
  }
569
570
  const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
570
571
  const content = patchedContent ? { ...base, ...patchedContent } : base;
572
+ if (schema) normalizeRelationContent(content, schema);
571
573
  const style = patchedStyle ? { ...asBucket(block.style), ...patchedStyle } : asBucket(block.style);
572
574
  const advanced = patchedAdvanced ? { ...asBucket(block.advanced), ...patchedAdvanced } : asBucket(block.advanced);
573
575
  return wrap(
@@ -679,6 +681,7 @@ function EditableBlocks({
679
681
  patchedContent: patches[block.id],
680
682
  patchedStyle: patchesStyle[block.id],
681
683
  patchedAdvanced: patchesAdvanced[block.id],
684
+ schema: bridgeConfig.schemas?.[block.type],
682
685
  blockMap,
683
686
  editable: true,
684
687
  context,
package/dist/index.cjs CHANGED
@@ -199,15 +199,27 @@ function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
199
199
  )
200
200
  );
201
201
  }
202
- async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales) {
202
+ async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales, options) {
203
+ const contents = blocks.map(
204
+ (block) => core.getBlockContentForLanguage(
205
+ block.content,
206
+ locale,
207
+ defaultLocale,
208
+ enabledLocales?.length ? enabledLocales : void 0
209
+ )
210
+ );
211
+ if (options?.config && options.schemas) {
212
+ await core.resolveRelationContent(
213
+ options.config,
214
+ blocks.map((block, i) => ({ type: block.type, content: contents[i] })),
215
+ options.schemas,
216
+ locale,
217
+ options.workspaceId ? { workspaceId: options.workspaceId } : {}
218
+ );
219
+ }
203
220
  return Promise.all(
204
- blocks.map(async (block) => {
205
- const content = core.getBlockContentForLanguage(
206
- block.content,
207
- locale,
208
- defaultLocale,
209
- enabledLocales?.length ? enabledLocales : void 0
210
- );
221
+ blocks.map(async (block, i) => {
222
+ const content = contents[i];
211
223
  const loader = loaderMap[block.type];
212
224
  let data;
213
225
  let error;
@@ -291,7 +303,8 @@ async function CmssyServerPage({
291
303
  locale,
292
304
  defaultLocale,
293
305
  context,
294
- enabledLocales
306
+ enabledLocales,
307
+ { schemas: blocksToSchemas(blocks), config, workspaceId: workspace?.id }
295
308
  );
296
309
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: page.blocks.map(
297
310
  (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
@@ -324,7 +337,8 @@ async function resolveBlockData({
324
337
  defaultLocale,
325
338
  enabledLocales,
326
339
  forms,
327
- isPreview = false
340
+ isPreview = false,
341
+ config
328
342
  }) {
329
343
  if (!page) return {};
330
344
  const loaderMap = buildLoaderMap(blocks);
@@ -341,7 +355,8 @@ async function resolveBlockData({
341
355
  locale,
342
356
  defaultLocale,
343
357
  context,
344
- enabledLocales
358
+ enabledLocales,
359
+ { schemas: blocksToSchemas(blocks), config }
345
360
  );
346
361
  return collectBlockData(page.blocks, resolved, isPreview);
347
362
  }
@@ -353,7 +368,8 @@ async function resolveLayoutBlockData({
353
368
  defaultLocale,
354
369
  enabledLocales,
355
370
  forms,
356
- isPreview = false
371
+ isPreview = false,
372
+ config
357
373
  }) {
358
374
  const group = groups.find((g) => g.position === position);
359
375
  const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
@@ -372,7 +388,8 @@ async function resolveLayoutBlockData({
372
388
  locale,
373
389
  defaultLocale,
374
390
  context,
375
- enabledLocales
391
+ enabledLocales,
392
+ { schemas: blocksToSchemas(blocks), config }
376
393
  );
377
394
  return collectBlockData(layoutBlocks, resolved, isPreview);
378
395
  }
@@ -404,7 +421,8 @@ async function CmssyServerLayout({
404
421
  locale,
405
422
  defaultLocale,
406
423
  context,
407
- enabledLocales
424
+ enabledLocales,
425
+ { schemas: blocksToSchemas(blocks), config }
408
426
  );
409
427
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: layoutBlocks.map(
410
428
  (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
@@ -425,6 +443,7 @@ function CmssyBlock({
425
443
  patchedContent,
426
444
  patchedStyle,
427
445
  patchedAdvanced,
446
+ schema,
428
447
  editable,
429
448
  editMode,
430
449
  layoutPosition,
@@ -472,6 +491,7 @@ function CmssyBlock({
472
491
  }
473
492
  const base = core.getBlockContentForLanguage(block.content, locale, defaultLocale);
474
493
  const content = patchedContent ? { ...base, ...patchedContent } : base;
494
+ if (schema) core.normalizeRelationContent(content, schema);
475
495
  const style = patchedStyle ? { ...core.asBucket(block.style), ...patchedStyle } : core.asBucket(block.style);
476
496
  const advanced = patchedAdvanced ? { ...core.asBucket(block.advanced), ...patchedAdvanced } : core.asBucket(block.advanced);
477
497
  return wrap(
package/dist/index.d.cts CHANGED
@@ -3,6 +3,7 @@ export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema
3
3
  import { B as BlockDefinition, a as BlockMap } from './registry-Bfq4Pq18.cjs';
4
4
  export { b as BlockProps, c as blocksToMeta, d as blocksToSchemas, e as buildBlockMap, f as defineBlock } from './registry-Bfq4Pq18.cjs';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
+ import { FieldDefinition } from '@cmssy/types';
6
7
  export { FieldCondition, FieldConditionGroup, FieldConditionLogic, evaluateFieldConditionGroup } from '@cmssy/types';
7
8
  import 'react';
8
9
 
@@ -41,8 +42,10 @@ interface ResolveBlockDataOptions {
41
42
  enabledLocales?: string[];
42
43
  forms?: Record<string, CmssyFormDefinition>;
43
44
  isPreview?: boolean;
45
+ /** Workspace the relation records are read from. No config, no resolution. */
46
+ config?: CmssyClientConfig;
44
47
  }
45
- declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
48
+ declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
46
49
  interface ResolveLayoutBlockDataOptions {
47
50
  groups: CmssyLayoutGroup[];
48
51
  blocks: BlockDefinition[];
@@ -52,8 +55,10 @@ interface ResolveLayoutBlockDataOptions {
52
55
  enabledLocales?: string[];
53
56
  forms?: Record<string, CmssyFormDefinition>;
54
57
  isPreview?: boolean;
58
+ /** Workspace the relation records are read from. No config, no resolution. */
59
+ config?: CmssyClientConfig;
55
60
  }
56
- declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
61
+ declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
57
62
 
58
63
  interface CmssyServerLayoutProps {
59
64
  groups: CmssyLayoutGroup[];
@@ -86,13 +91,15 @@ interface CmssyBlockProps {
86
91
  patchedContent?: Record<string, unknown>;
87
92
  patchedStyle?: Record<string, unknown>;
88
93
  patchedAdvanced?: Record<string, unknown>;
94
+ /** The block's field schema; lets the client render coerce raw relation values. */
95
+ schema?: Record<string, FieldDefinition>;
89
96
  editable?: boolean;
90
97
  editMode?: boolean;
91
98
  layoutPosition?: string;
92
99
  context?: CmssyBlockContext;
93
100
  data?: unknown;
94
101
  }
95
- declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, editMode, layoutPosition, context, data, }: CmssyBlockProps): react_jsx_runtime.JSX.Element | null;
102
+ declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, schema, editable, editMode, layoutPosition, context, data, }: CmssyBlockProps): react_jsx_runtime.JSX.Element | null;
96
103
 
97
104
  interface UnknownBlockProps {
98
105
  type: string;
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema
3
3
  import { B as BlockDefinition, a as BlockMap } from './registry-Bfq4Pq18.js';
4
4
  export { b as BlockProps, c as blocksToMeta, d as blocksToSchemas, e as buildBlockMap, f as defineBlock } from './registry-Bfq4Pq18.js';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
+ import { FieldDefinition } from '@cmssy/types';
6
7
  export { FieldCondition, FieldConditionGroup, FieldConditionLogic, evaluateFieldConditionGroup } from '@cmssy/types';
7
8
  import 'react';
8
9
 
@@ -41,8 +42,10 @@ interface ResolveBlockDataOptions {
41
42
  enabledLocales?: string[];
42
43
  forms?: Record<string, CmssyFormDefinition>;
43
44
  isPreview?: boolean;
45
+ /** Workspace the relation records are read from. No config, no resolution. */
46
+ config?: CmssyClientConfig;
44
47
  }
45
- declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
48
+ declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
46
49
  interface ResolveLayoutBlockDataOptions {
47
50
  groups: CmssyLayoutGroup[];
48
51
  blocks: BlockDefinition[];
@@ -52,8 +55,10 @@ interface ResolveLayoutBlockDataOptions {
52
55
  enabledLocales?: string[];
53
56
  forms?: Record<string, CmssyFormDefinition>;
54
57
  isPreview?: boolean;
58
+ /** Workspace the relation records are read from. No config, no resolution. */
59
+ config?: CmssyClientConfig;
55
60
  }
56
- declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
61
+ declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
57
62
 
58
63
  interface CmssyServerLayoutProps {
59
64
  groups: CmssyLayoutGroup[];
@@ -86,13 +91,15 @@ interface CmssyBlockProps {
86
91
  patchedContent?: Record<string, unknown>;
87
92
  patchedStyle?: Record<string, unknown>;
88
93
  patchedAdvanced?: Record<string, unknown>;
94
+ /** The block's field schema; lets the client render coerce raw relation values. */
95
+ schema?: Record<string, FieldDefinition>;
89
96
  editable?: boolean;
90
97
  editMode?: boolean;
91
98
  layoutPosition?: string;
92
99
  context?: CmssyBlockContext;
93
100
  data?: unknown;
94
101
  }
95
- declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, editMode, layoutPosition, context, data, }: CmssyBlockProps): react_jsx_runtime.JSX.Element | null;
102
+ declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, schema, editable, editMode, layoutPosition, context, data, }: CmssyBlockProps): react_jsx_runtime.JSX.Element | null;
96
103
 
97
104
  interface UnknownBlockProps {
98
105
  type: string;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { buildBlockContext, getBlockContentForLanguage, asBucket, resolveSiteLocales } from '@cmssy/core';
1
+ import { buildBlockContext, getBlockContentForLanguage, normalizeRelationContent, asBucket, resolveSiteLocales, resolveRelationContent } from '@cmssy/core';
2
2
  export { CmssyRequestError, DEFAULT_CMSSY_API_URL, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, PROTOCOL_VERSION, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, buildBlockContext, buildLocaleSwitchHref, collectFormIds, createCmssyClient, fetchLayouts, fetchPage, fetchPageById, fetchPageMeta, fetchPages, fetchSiteConfig, fields, getBlockContentForLanguage, graphqlRequest, isProtocolCompatible, localizeHref, localizeHtmlLinks, normalizeOrigin, normalizeSlug, parseEditorMessage, postToEditor, resolveApiUrl, resolveForms, resolvePublicUrl, resolveSiteLocales, resolveWorkspaceId, splitLocaleFromPath } from '@cmssy/core';
3
3
  import { createElement } from 'react';
4
4
  import { BlockErrorBoundary } from '@cmssy/react/block-error-boundary';
@@ -198,15 +198,27 @@ function renderResolvedBlock(block, map, locale, defaultLocale, options = {}) {
198
198
  )
199
199
  );
200
200
  }
201
- async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales) {
201
+ async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales, options) {
202
+ const contents = blocks.map(
203
+ (block) => getBlockContentForLanguage(
204
+ block.content,
205
+ locale,
206
+ defaultLocale,
207
+ enabledLocales?.length ? enabledLocales : void 0
208
+ )
209
+ );
210
+ if (options?.config && options.schemas) {
211
+ await resolveRelationContent(
212
+ options.config,
213
+ blocks.map((block, i) => ({ type: block.type, content: contents[i] })),
214
+ options.schemas,
215
+ locale,
216
+ options.workspaceId ? { workspaceId: options.workspaceId } : {}
217
+ );
218
+ }
202
219
  return Promise.all(
203
- blocks.map(async (block) => {
204
- const content = getBlockContentForLanguage(
205
- block.content,
206
- locale,
207
- defaultLocale,
208
- enabledLocales?.length ? enabledLocales : void 0
209
- );
220
+ blocks.map(async (block, i) => {
221
+ const content = contents[i];
210
222
  const loader = loaderMap[block.type];
211
223
  let data;
212
224
  let error;
@@ -290,7 +302,8 @@ async function CmssyServerPage({
290
302
  locale,
291
303
  defaultLocale,
292
304
  context,
293
- enabledLocales
305
+ enabledLocales,
306
+ { schemas: blocksToSchemas(blocks), config, workspaceId: workspace?.id }
294
307
  );
295
308
  return /* @__PURE__ */ jsx(Fragment, { children: page.blocks.map(
296
309
  (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
@@ -323,7 +336,8 @@ async function resolveBlockData({
323
336
  defaultLocale,
324
337
  enabledLocales,
325
338
  forms,
326
- isPreview = false
339
+ isPreview = false,
340
+ config
327
341
  }) {
328
342
  if (!page) return {};
329
343
  const loaderMap = buildLoaderMap(blocks);
@@ -340,7 +354,8 @@ async function resolveBlockData({
340
354
  locale,
341
355
  defaultLocale,
342
356
  context,
343
- enabledLocales
357
+ enabledLocales,
358
+ { schemas: blocksToSchemas(blocks), config }
344
359
  );
345
360
  return collectBlockData(page.blocks, resolved, isPreview);
346
361
  }
@@ -352,7 +367,8 @@ async function resolveLayoutBlockData({
352
367
  defaultLocale,
353
368
  enabledLocales,
354
369
  forms,
355
- isPreview = false
370
+ isPreview = false,
371
+ config
356
372
  }) {
357
373
  const group = groups.find((g) => g.position === position);
358
374
  const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
@@ -371,7 +387,8 @@ async function resolveLayoutBlockData({
371
387
  locale,
372
388
  defaultLocale,
373
389
  context,
374
- enabledLocales
390
+ enabledLocales,
391
+ { schemas: blocksToSchemas(blocks), config }
375
392
  );
376
393
  return collectBlockData(layoutBlocks, resolved, isPreview);
377
394
  }
@@ -403,7 +420,8 @@ async function CmssyServerLayout({
403
420
  locale,
404
421
  defaultLocale,
405
422
  context,
406
- enabledLocales
423
+ enabledLocales,
424
+ { schemas: blocksToSchemas(blocks), config }
407
425
  );
408
426
  return /* @__PURE__ */ jsx(Fragment, { children: layoutBlocks.map(
409
427
  (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
@@ -424,6 +442,7 @@ function CmssyBlock({
424
442
  patchedContent,
425
443
  patchedStyle,
426
444
  patchedAdvanced,
445
+ schema,
427
446
  editable,
428
447
  editMode,
429
448
  layoutPosition,
@@ -471,6 +490,7 @@ function CmssyBlock({
471
490
  }
472
491
  const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
473
492
  const content = patchedContent ? { ...base, ...patchedContent } : base;
493
+ if (schema) normalizeRelationContent(content, schema);
474
494
  const style = patchedStyle ? { ...asBucket(block.style), ...patchedStyle } : asBucket(block.style);
475
495
  const advanced = patchedAdvanced ? { ...asBucket(block.advanced), ...patchedAdvanced } : asBucket(block.advanced);
476
496
  return wrap(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "9.5.0",
3
+ "version": "9.6.1",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -61,8 +61,8 @@
61
61
  "vitest": "^2.1.0"
62
62
  },
63
63
  "dependencies": {
64
- "@cmssy/types": "0.28.0",
65
- "@cmssy/core": "9.5.0"
64
+ "@cmssy/types": "0.29.0",
65
+ "@cmssy/core": "9.6.1"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsup",