@cmssy/react 9.4.0 → 9.6.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/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, {
package/dist/index.d.cts CHANGED
@@ -41,8 +41,10 @@ interface ResolveBlockDataOptions {
41
41
  enabledLocales?: string[];
42
42
  forms?: Record<string, CmssyFormDefinition>;
43
43
  isPreview?: boolean;
44
+ /** Workspace the relation records are read from. No config, no resolution. */
45
+ config?: CmssyClientConfig;
44
46
  }
45
- declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
47
+ declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
46
48
  interface ResolveLayoutBlockDataOptions {
47
49
  groups: CmssyLayoutGroup[];
48
50
  blocks: BlockDefinition[];
@@ -52,8 +54,10 @@ interface ResolveLayoutBlockDataOptions {
52
54
  enabledLocales?: string[];
53
55
  forms?: Record<string, CmssyFormDefinition>;
54
56
  isPreview?: boolean;
57
+ /** Workspace the relation records are read from. No config, no resolution. */
58
+ config?: CmssyClientConfig;
55
59
  }
56
- declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
60
+ declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
57
61
 
58
62
  interface CmssyServerLayoutProps {
59
63
  groups: CmssyLayoutGroup[];
package/dist/index.d.ts CHANGED
@@ -41,8 +41,10 @@ interface ResolveBlockDataOptions {
41
41
  enabledLocales?: string[];
42
42
  forms?: Record<string, CmssyFormDefinition>;
43
43
  isPreview?: boolean;
44
+ /** Workspace the relation records are read from. No config, no resolution. */
45
+ config?: CmssyClientConfig;
44
46
  }
45
- declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
47
+ declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
46
48
  interface ResolveLayoutBlockDataOptions {
47
49
  groups: CmssyLayoutGroup[];
48
50
  blocks: BlockDefinition[];
@@ -52,8 +54,10 @@ interface ResolveLayoutBlockDataOptions {
52
54
  enabledLocales?: string[];
53
55
  forms?: Record<string, CmssyFormDefinition>;
54
56
  isPreview?: boolean;
57
+ /** Workspace the relation records are read from. No config, no resolution. */
58
+ config?: CmssyClientConfig;
55
59
  }
56
- declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
60
+ declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
57
61
 
58
62
  interface CmssyServerLayoutProps {
59
63
  groups: CmssyLayoutGroup[];
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { buildBlockContext, getBlockContentForLanguage, asBucket, resolveSiteLocales } from '@cmssy/core';
1
+ import { buildBlockContext, getBlockContentForLanguage, 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, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "9.4.0",
3
+ "version": "9.6.0",
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.4.0"
64
+ "@cmssy/types": "0.29.0",
65
+ "@cmssy/core": "9.6.0"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsup",