@cmssy/react 14.0.0 → 14.2.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.cjs CHANGED
@@ -7,43 +7,11 @@ var internal = require('@cmssy/core/internal');
7
7
  var blockErrorBoundary = require('@cmssy/react/block-error-boundary');
8
8
  var jsxRuntime = require('react/jsx-runtime');
9
9
 
10
- // src/registry.ts
11
10
  function buildBlockMap(blocks) {
12
11
  const map = /* @__PURE__ */ Object.create(null);
13
12
  for (const block of blocks) map[block.type] = block.component;
14
13
  return map;
15
14
  }
16
- function propsToSchema(props) {
17
- const schema = {};
18
- for (const [key, def] of Object.entries(props)) {
19
- schema[key] = { ...def, label: def.label || key };
20
- }
21
- return schema;
22
- }
23
- function blocksToSchemas(blocks) {
24
- const out = /* @__PURE__ */ Object.create(null);
25
- for (const block of blocks) out[block.type] = propsToSchema(block.props);
26
- return out;
27
- }
28
- function layoutRegionsToBridge(regions) {
29
- return regions.map(
30
- (region) => region.settings ? { ...region, settings: propsToSchema(region.settings) } : { ...region }
31
- );
32
- }
33
- function blocksToMeta(blocks, defaults = {}) {
34
- const out = /* @__PURE__ */ Object.create(null);
35
- for (const block of blocks) {
36
- const category = block.category ?? defaults.category;
37
- out[block.type] = {
38
- label: block.label ?? block.type,
39
- ...category ? { category } : {},
40
- ...block.icon ? { icon: block.icon } : {},
41
- ...block.layoutPositions ? { layoutPositions: block.layoutPositions } : {},
42
- ...block.description ? { description: block.description } : {}
43
- };
44
- }
45
- return out;
46
- }
47
15
 
48
16
  // src/bridge/shortcut-keys.ts
49
17
  function isMacPlatform() {
@@ -322,7 +290,7 @@ function useEditBridge(page, config) {
322
290
  schemas: config.schemas ?? /* @__PURE__ */ Object.create(null),
323
291
  blockMeta: config.blockMeta ?? /* @__PURE__ */ Object.create(null),
324
292
  capabilities: canDetectInvisibleBlocks() ? ["shortcuts", "invisible-blocks"] : ["shortcuts"],
325
- ...config.layoutRegions ? { layoutRegions: layoutRegionsToBridge(config.layoutRegions) } : {}
293
+ ...config.layoutRegions ? { layoutRegions: core.layoutRegionsToBridge(config.layoutRegions) } : {}
326
294
  });
327
295
  } catch (error) {
328
296
  if (typeof console !== "undefined") {
@@ -879,8 +847,8 @@ function EditableBlocks({
879
847
  const bridgeConfig = react.useMemo(
880
848
  () => ({
881
849
  ...edit,
882
- schemas: edit.schemas ?? blocksToSchemas(blocks),
883
- blockMeta: edit.blockMeta ?? blocksToMeta(blocks, { category })
850
+ schemas: edit.schemas ?? core.blocksToSchemas(blocks),
851
+ blockMeta: edit.blockMeta ?? core.blocksToMeta(blocks, { category })
884
852
  }),
885
853
  [edit, blocks, category]
886
854
  );
@@ -1012,6 +980,7 @@ function CmssyEditableLayout({
1012
980
  groups,
1013
981
  blocks,
1014
982
  position,
983
+ page,
1015
984
  locale = "en",
1016
985
  defaultLocale = "en",
1017
986
  enabledLocales,
@@ -1022,7 +991,7 @@ function CmssyEditableLayout({
1022
991
  }) {
1023
992
  const blockMap = react.useMemo(() => buildBlockMap(blocks), [blocks]);
1024
993
  const schemas = react.useMemo(
1025
- () => edit.schemas ?? blocksToSchemas(blocks),
994
+ () => edit.schemas ?? core.blocksToSchemas(blocks),
1026
995
  [edit.schemas, blocks]
1027
996
  );
1028
997
  const layoutBlocks = react.useMemo(() => {
@@ -1032,9 +1001,10 @@ function CmssyEditableLayout({
1032
1001
  const patches = useLayoutPatchBridge(position, edit);
1033
1002
  const context = react.useMemo(
1034
1003
  () => internal.buildBlockContext(locale, defaultLocale, enabledLocales, true, void 0, {
1004
+ page,
1035
1005
  app: appContext
1036
1006
  }),
1037
- [locale, defaultLocale, enabledLocales, appContext]
1007
+ [locale, defaultLocale, enabledLocales, page, appContext]
1038
1008
  );
1039
1009
  if (layoutBlocks.length === 0) return null;
1040
1010
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: layoutBlocks.map((block) => /* @__PURE__ */ jsxRuntime.jsx(
package/dist/client.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { BlockSchema, BlockMeta, LayoutRegion, CmssyPageData, CmssyFormDefinition, CmssyLayoutGroup } from '@cmssy/core';
3
- import { B as BlockDefinition } from './registry-CwJ2cby4.cjs';
3
+ import { B as BlockDefinition, L as LayoutBlockPage } from './internal-server-Hogm3pjD.cjs';
4
4
  import 'react';
5
5
 
6
6
  interface EditBridgeConfig {
@@ -72,6 +72,7 @@ interface CmssyEditableLayoutProps {
72
72
  groups: CmssyLayoutGroup[];
73
73
  blocks: BlockDefinition[];
74
74
  position: string;
75
+ page?: LayoutBlockPage;
75
76
  locale?: string;
76
77
  defaultLocale?: string;
77
78
  enabledLocales?: string[];
@@ -80,11 +81,12 @@ interface CmssyEditableLayoutProps {
80
81
  resolvedContent?: Record<string, Record<string, unknown>>;
81
82
  appContext?: Record<string, unknown>;
82
83
  }
83
- declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, edit, data, resolvedContent, appContext, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
84
+ declare function CmssyEditableLayout({ groups, blocks, position, page, locale, defaultLocale, enabledLocales, edit, data, resolvedContent, appContext, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
84
85
 
85
86
  interface CmssyLazyLayoutProps {
86
87
  groups: CmssyLayoutGroup[];
87
88
  position: string;
89
+ page?: LayoutBlockPage;
88
90
  locale?: string;
89
91
  defaultLocale?: string;
90
92
  enabledLocales?: string[];
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { BlockSchema, BlockMeta, LayoutRegion, CmssyPageData, CmssyFormDefinition, CmssyLayoutGroup } from '@cmssy/core';
3
- import { B as BlockDefinition } from './registry-CwJ2cby4.js';
3
+ import { B as BlockDefinition, L as LayoutBlockPage } from './internal-server-Hogm3pjD.js';
4
4
  import 'react';
5
5
 
6
6
  interface EditBridgeConfig {
@@ -72,6 +72,7 @@ interface CmssyEditableLayoutProps {
72
72
  groups: CmssyLayoutGroup[];
73
73
  blocks: BlockDefinition[];
74
74
  position: string;
75
+ page?: LayoutBlockPage;
75
76
  locale?: string;
76
77
  defaultLocale?: string;
77
78
  enabledLocales?: string[];
@@ -80,11 +81,12 @@ interface CmssyEditableLayoutProps {
80
81
  resolvedContent?: Record<string, Record<string, unknown>>;
81
82
  appContext?: Record<string, unknown>;
82
83
  }
83
- declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, edit, data, resolvedContent, appContext, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
84
+ declare function CmssyEditableLayout({ groups, blocks, position, page, locale, defaultLocale, enabledLocales, edit, data, resolvedContent, appContext, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
84
85
 
85
86
  interface CmssyLazyLayoutProps {
86
87
  groups: CmssyLayoutGroup[];
87
88
  position: string;
89
+ page?: LayoutBlockPage;
88
90
  locale?: string;
89
91
  defaultLocale?: string;
90
92
  enabledLocales?: string[];
package/dist/client.js CHANGED
@@ -1,47 +1,15 @@
1
1
  "use client";
2
2
  import { useState, useRef, useEffect, useMemo, createElement } from 'react';
3
- import { postToEditor, PROTOCOL_VERSION, parseEditorMessage } from '@cmssy/core';
3
+ import { blocksToMeta, blocksToSchemas, postToEditor, layoutRegionsToBridge, PROTOCOL_VERSION, parseEditorMessage } from '@cmssy/core';
4
4
  import { resolveInitialTarget, buildBlockContext, getBlockContentForLanguage, normalizeBlockContent, asBucket } from '@cmssy/core/internal';
5
5
  import { BlockErrorBoundary } from '@cmssy/react/block-error-boundary';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
7
 
8
- // src/registry.ts
9
8
  function buildBlockMap(blocks) {
10
9
  const map = /* @__PURE__ */ Object.create(null);
11
10
  for (const block of blocks) map[block.type] = block.component;
12
11
  return map;
13
12
  }
14
- function propsToSchema(props) {
15
- const schema = {};
16
- for (const [key, def] of Object.entries(props)) {
17
- schema[key] = { ...def, label: def.label || key };
18
- }
19
- return schema;
20
- }
21
- function blocksToSchemas(blocks) {
22
- const out = /* @__PURE__ */ Object.create(null);
23
- for (const block of blocks) out[block.type] = propsToSchema(block.props);
24
- return out;
25
- }
26
- function layoutRegionsToBridge(regions) {
27
- return regions.map(
28
- (region) => region.settings ? { ...region, settings: propsToSchema(region.settings) } : { ...region }
29
- );
30
- }
31
- function blocksToMeta(blocks, defaults = {}) {
32
- const out = /* @__PURE__ */ Object.create(null);
33
- for (const block of blocks) {
34
- const category = block.category ?? defaults.category;
35
- out[block.type] = {
36
- label: block.label ?? block.type,
37
- ...category ? { category } : {},
38
- ...block.icon ? { icon: block.icon } : {},
39
- ...block.layoutPositions ? { layoutPositions: block.layoutPositions } : {},
40
- ...block.description ? { description: block.description } : {}
41
- };
42
- }
43
- return out;
44
- }
45
13
 
46
14
  // src/bridge/shortcut-keys.ts
47
15
  function isMacPlatform() {
@@ -1010,6 +978,7 @@ function CmssyEditableLayout({
1010
978
  groups,
1011
979
  blocks,
1012
980
  position,
981
+ page,
1013
982
  locale = "en",
1014
983
  defaultLocale = "en",
1015
984
  enabledLocales,
@@ -1030,9 +999,10 @@ function CmssyEditableLayout({
1030
999
  const patches = useLayoutPatchBridge(position, edit);
1031
1000
  const context = useMemo(
1032
1001
  () => buildBlockContext(locale, defaultLocale, enabledLocales, true, void 0, {
1002
+ page,
1033
1003
  app: appContext
1034
1004
  }),
1035
- [locale, defaultLocale, enabledLocales, appContext]
1005
+ [locale, defaultLocale, enabledLocales, page, appContext]
1036
1006
  );
1037
1007
  if (layoutBlocks.length === 0) return null;
1038
1008
  return /* @__PURE__ */ jsx(Fragment, { children: layoutBlocks.map((block) => /* @__PURE__ */ jsx(
package/dist/index.cjs CHANGED
@@ -8,8 +8,6 @@ var jsxRuntime = require('react/jsx-runtime');
8
8
  var locale = require('@cmssy/core/internal/locale');
9
9
 
10
10
  // src/index.ts
11
-
12
- // src/registry.ts
13
11
  function defineBlock(def) {
14
12
  return def;
15
13
  }
@@ -25,18 +23,6 @@ function buildLoaderMap(blocks) {
25
23
  }
26
24
  return map;
27
25
  }
28
- function propsToSchema(props) {
29
- const schema = {};
30
- for (const [key, def] of Object.entries(props)) {
31
- schema[key] = { ...def, label: def.label || key };
32
- }
33
- return schema;
34
- }
35
- function blocksToSchemas(blocks) {
36
- const out = /* @__PURE__ */ Object.create(null);
37
- for (const block of blocks) out[block.type] = propsToSchema(block.props);
38
- return out;
39
- }
40
26
 
41
27
  // src/components/block-error.ts
42
28
  var BLOCK_ERROR_KEY = "__cmssyBlockError";
@@ -300,7 +286,7 @@ async function CmssyServerPage({
300
286
  defaultLocale,
301
287
  context,
302
288
  enabledLocales,
303
- { schemas: blocksToSchemas(blocks), config, workspaceId: workspace?.id }
289
+ { schemas: core.blocksToSchemas(blocks), config, workspaceId: workspace?.id }
304
290
  );
305
291
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: page.blocks.map(
306
292
  (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
@@ -356,7 +342,7 @@ async function resolveEditorBlockData({
356
342
  defaultLocale,
357
343
  context,
358
344
  enabledLocales,
359
- { schemas: blocksToSchemas(blocks), config }
345
+ { schemas: core.blocksToSchemas(blocks), config }
360
346
  );
361
347
  return collectBlockData(page.blocks, resolved, isPreview);
362
348
  }
@@ -364,6 +350,7 @@ async function resolveEditorLayoutBlockData({
364
350
  groups,
365
351
  blocks,
366
352
  position,
353
+ page,
367
354
  locale,
368
355
  defaultLocale,
369
356
  enabledLocales,
@@ -382,7 +369,7 @@ async function resolveEditorLayoutBlockData({
382
369
  enabledLocales,
383
370
  isPreview,
384
371
  forms,
385
- { app: appContext }
372
+ { page, app: appContext }
386
373
  );
387
374
  const resolved = await resolveBlocks(
388
375
  layoutBlocks,
@@ -391,16 +378,20 @@ async function resolveEditorLayoutBlockData({
391
378
  defaultLocale,
392
379
  context,
393
380
  enabledLocales,
394
- { schemas: blocksToSchemas(blocks), config }
381
+ { schemas: core.blocksToSchemas(blocks), config }
395
382
  );
396
383
  return collectBlockData(layoutBlocks, resolved, isPreview);
397
384
  }
385
+ function layoutSlotPage(slug) {
386
+ return { slug, path: slug.split("/").filter(Boolean) };
387
+ }
398
388
  async function resolveCmssyLayoutSlot(config, options) {
399
389
  const {
400
390
  position,
401
391
  blocks,
402
392
  editMode,
403
- page,
393
+ preview = false,
394
+ page: explicitPage,
404
395
  forms,
405
396
  appContext,
406
397
  path,
@@ -412,13 +403,15 @@ async function resolveCmssyLayoutSlot(config, options) {
412
403
  const fromPath = path ? locale.splitLocaleFromPath(path, siteLocales) : { locale: siteLocales.defaultLocale, path: [] };
413
404
  const locale$1 = explicitLocale ?? fromPath.locale;
414
405
  const slugSegments = fromPath.path ?? [];
415
- const pageSlug = page ?? "/" + slugSegments.join("/");
416
- const groups = await internal.fetchLayouts(config, pageSlug, {
417
- previewSecret: editMode ? config.draftSecret : void 0,
406
+ const page = layoutSlotPage(explicitPage ?? "/" + slugSegments.join("/"));
407
+ const groups = await internal.fetchLayouts(config, page.slug, {
408
+ previewSecret: editMode || preview ? config.draftSecret : void 0,
418
409
  ...requestOptions
419
410
  });
420
411
  const base = {
421
412
  groups,
413
+ settings: groups.find((g) => g.position === position)?.settings ?? null,
414
+ page,
422
415
  locale: locale$1,
423
416
  defaultLocale: siteLocales.defaultLocale,
424
417
  enabledLocales: siteLocales.locales,
@@ -429,6 +422,7 @@ async function resolveCmssyLayoutSlot(config, options) {
429
422
  groups,
430
423
  blocks,
431
424
  position,
425
+ page,
432
426
  locale: locale$1,
433
427
  defaultLocale: siteLocales.defaultLocale,
434
428
  enabledLocales: siteLocales.locales,
@@ -448,12 +442,14 @@ async function CmssyServerLayout({
448
442
  groups,
449
443
  blocks,
450
444
  position,
445
+ page,
451
446
  locale: localeProp,
452
447
  defaultLocale: defaultLocaleProp,
453
448
  enabledLocales: enabledLocalesProp,
454
449
  config,
455
450
  appContext,
456
- editMode
451
+ editMode,
452
+ preview = false
457
453
  }) {
458
454
  const { locale, defaultLocale, enabledLocales } = await resolveRenderLocale({
459
455
  locale: localeProp,
@@ -470,9 +466,9 @@ async function CmssyServerLayout({
470
466
  locale,
471
467
  defaultLocale,
472
468
  enabledLocales,
473
- false,
469
+ preview,
474
470
  void 0,
475
- { app: appContext }
471
+ { page, app: appContext }
476
472
  );
477
473
  const resolved = await resolveBlocks(
478
474
  layoutBlocks,
@@ -481,7 +477,7 @@ async function CmssyServerLayout({
481
477
  defaultLocale,
482
478
  context,
483
479
  enabledLocales,
484
- { schemas: blocksToSchemas(blocks), config }
480
+ { schemas: core.blocksToSchemas(blocks), config }
485
481
  );
486
482
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: layoutBlocks.map(
487
483
  (block, i) => renderResolvedBlock(block, map, locale, defaultLocale, {
@@ -494,6 +490,54 @@ async function CmssyServerLayout({
494
490
  })
495
491
  ) });
496
492
  }
493
+ async function resolveCmssyLayout(config, options) {
494
+ const { editable: Editable, ...slotOptions } = options;
495
+ if (slotOptions.editMode && !Editable) {
496
+ throw new Error(
497
+ "cmssy: resolveCmssyLayout needs an `editable` component in edit mode - the editor bridge lives on the client"
498
+ );
499
+ }
500
+ const resolved = await resolveCmssyLayoutSlot(
501
+ config,
502
+ slotOptions
503
+ );
504
+ const { groups, settings, page, locale, defaultLocale, enabledLocales } = resolved;
505
+ const shared = {
506
+ groups,
507
+ position: options.position,
508
+ page,
509
+ locale,
510
+ defaultLocale,
511
+ enabledLocales,
512
+ appContext: options.appContext
513
+ };
514
+ const element = slotOptions.editMode && Editable ? /* @__PURE__ */ jsxRuntime.jsx(
515
+ Editable,
516
+ {
517
+ ...shared,
518
+ edit: { editorOrigin: resolved.editorOrigin ?? "" },
519
+ data: resolved.data,
520
+ resolvedContent: resolved.resolvedContent
521
+ }
522
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
523
+ CmssyServerLayout,
524
+ {
525
+ ...shared,
526
+ blocks: options.blocks,
527
+ config,
528
+ preview: slotOptions.preview
529
+ }
530
+ );
531
+ return {
532
+ groups,
533
+ settings,
534
+ page,
535
+ locale,
536
+ defaultLocale,
537
+ enabledLocales,
538
+ element
539
+ };
540
+ }
497
541
  function CmssyBlock({
498
542
  block,
499
543
  locale,
@@ -635,6 +679,7 @@ exports.CmssyServerPage = CmssyServerPage;
635
679
  exports.UnknownBlock = UnknownBlock;
636
680
  exports.buildBlockMap = buildBlockMap;
637
681
  exports.defineBlock = defineBlock;
682
+ exports.resolveCmssyLayout = resolveCmssyLayout;
638
683
  exports.resolveCmssyLayoutSlot = resolveCmssyLayoutSlot;
639
684
  exports.resolveEditorBlockData = resolveEditorBlockData;
640
685
  exports.resolveEditorLayoutBlockData = resolveEditorLayoutBlockData;
package/dist/index.d.cts CHANGED
@@ -1,13 +1,12 @@
1
- import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, RetryOption, CmssyConfig, RawBlock, CmssyBlockContext } from '@cmssy/core';
2
- export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayout, CmssyLayoutGroup, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRegion, CmssyRegionOf, CmssyRegionSettings, CmssyRequestError, CmssyRetryMode, CmssySiteConfig, CmssyTypedDocument, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, LayoutPosition, LayoutRegion, MediaLike, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryOption, RetryPolicy, SelectMessage, SubmitFormInput, TypedField, createCmssyClient, defineCmssyLayout, fields, graphqlRequest, isProtocolCompatible, mediaAlt, mediaUrl, mediaUrls, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
3
- import { B as BlockDefinition, a as BlockMap } from './registry-CwJ2cby4.cjs';
4
- export { b as BlockProps, c as buildBlockMap, d as defineBlock } from './registry-CwJ2cby4.cjs';
1
+ import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, CmssyBlockPage, RetryOption, CmssyConfig, CmssyRegionOf, CmssyRegionSettingsOf, RawBlock, CmssyBlockContext } from '@cmssy/core';
2
+ export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayout, CmssyLayoutGroup, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRegion, CmssyRegionOf, CmssyRegionSettings, CmssyRegionSettingsOf, CmssyRequestError, CmssyRetryMode, CmssySiteConfig, CmssyTypedDocument, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, LayoutPosition, LayoutRegion, MediaLike, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryOption, RetryPolicy, SelectMessage, SubmitFormInput, TypedField, createCmssyClient, defineCmssyLayout, fields, graphqlRequest, isProtocolCompatible, mediaAlt, mediaUrl, mediaUrls, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
3
+ import { B as BlockDefinition, L as LayoutBlockPage, a as BlockMap } from './internal-server-Hogm3pjD.cjs';
4
+ export { b as BlockProps, E as EditorBlockData, R as ResolveBlockDataOptions, c as ResolveLayoutBlockDataOptions, d as buildBlockMap, e as defineBlock, r as resolveEditorBlockData, f as resolveEditorLayoutBlockData } from './internal-server-Hogm3pjD.cjs';
5
5
  import { FieldDefinition } from '@cmssy/types';
6
6
  export { FieldCondition, FieldConditionGroup, FieldConditionLogic } from '@cmssy/types';
7
7
  export { buildBlockContext } from '@cmssy/core/internal';
8
8
  import * as react_jsx_runtime from 'react/jsx-runtime';
9
- export { EditorBlockData, ResolveBlockDataOptions, ResolveLayoutBlockDataOptions, resolveEditorBlockData, resolveEditorLayoutBlockData } from './internal-server.cjs';
10
- import 'react';
9
+ import { ReactElement, ComponentType } from 'react';
11
10
 
12
11
  interface CmssyServerPageProps {
13
12
  page: CmssyPageData | null;
@@ -28,6 +27,7 @@ interface ResolveCmssyLayoutSlotBase {
28
27
  position: string;
29
28
  blocks: BlockDefinition[];
30
29
  editMode: boolean;
30
+ preview?: boolean;
31
31
  page?: string;
32
32
  forms?: Record<string, CmssyFormDefinition>;
33
33
  appContext?: Record<string, unknown>;
@@ -43,6 +43,8 @@ type CmssyLayoutSlotLocaleSource = {
43
43
  type ResolveCmssyLayoutSlotOptions = ResolveCmssyLayoutSlotBase & CmssyLayoutSlotLocaleSource;
44
44
  interface CmssyLayoutSlotResolution {
45
45
  groups: CmssyLayoutGroup[];
46
+ settings: Record<string, unknown> | null;
47
+ page: CmssyBlockPage;
46
48
  locale: string;
47
49
  defaultLocale: string;
48
50
  enabledLocales: string[];
@@ -53,18 +55,49 @@ interface CmssyLayoutSlotResolution {
53
55
  }
54
56
  declare function resolveCmssyLayoutSlot(config: CmssyConfig, options: ResolveCmssyLayoutSlotOptions): Promise<CmssyLayoutSlotResolution>;
55
57
 
58
+ interface CmssyLayoutEditableProps {
59
+ groups: CmssyLayoutGroup[];
60
+ position: string;
61
+ page?: CmssyBlockPage;
62
+ locale: string;
63
+ defaultLocale: string;
64
+ enabledLocales: string[];
65
+ edit: {
66
+ editorOrigin: string | string[];
67
+ };
68
+ data?: Record<string, unknown>;
69
+ resolvedContent?: Record<string, Record<string, unknown>>;
70
+ appContext?: Record<string, unknown>;
71
+ }
72
+ type ResolveCmssyLayoutOptions<C extends CmssyConfig, P extends CmssyRegionOf<C>> = Omit<ResolveCmssyLayoutSlotOptions, "position" | keyof CmssyLayoutSlotLocaleSource> & CmssyLayoutSlotLocaleSource & {
73
+ position: P;
74
+ editable?: ComponentType<CmssyLayoutEditableProps>;
75
+ };
76
+ interface CmssyLayoutResolution<C extends CmssyConfig = CmssyConfig, P extends CmssyRegionOf<C> = CmssyRegionOf<C>> {
77
+ groups: CmssyLayoutGroup[];
78
+ settings: CmssyRegionSettingsOf<C, P> | null;
79
+ page: CmssyBlockPage;
80
+ locale: string;
81
+ defaultLocale: string;
82
+ enabledLocales: string[];
83
+ element: ReactElement<Record<string, unknown>>;
84
+ }
85
+ declare function resolveCmssyLayout<C extends CmssyConfig, P extends CmssyRegionOf<C>>(config: C, options: ResolveCmssyLayoutOptions<C, P>): Promise<CmssyLayoutResolution<C, P>>;
86
+
56
87
  interface CmssyServerLayoutProps {
57
88
  groups: CmssyLayoutGroup[];
58
89
  blocks: BlockDefinition[];
59
90
  position: string;
91
+ page?: LayoutBlockPage;
60
92
  locale?: string;
61
93
  defaultLocale?: string;
62
94
  enabledLocales?: string[];
63
95
  config?: CmssyClientConfig;
64
96
  appContext?: Record<string, unknown>;
65
97
  editMode?: boolean;
98
+ preview?: boolean;
66
99
  }
67
- declare function CmssyServerLayout({ groups, blocks, position, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, appContext, editMode, }: CmssyServerLayoutProps): Promise<react_jsx_runtime.JSX.Element | null>;
100
+ declare function CmssyServerLayout({ groups, blocks, position, page, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, appContext, editMode, preview, }: CmssyServerLayoutProps): Promise<react_jsx_runtime.JSX.Element | null>;
68
101
 
69
102
  interface CmssyBlockProps {
70
103
  block: RawBlock;
@@ -89,4 +122,4 @@ interface UnknownBlockProps {
89
122
  }
90
123
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
91
124
 
92
- export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyLayoutSlotLocaleSource, type CmssyLayoutSlotResolution, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type ResolveCmssyLayoutSlotOptions, UnknownBlock, type UnknownBlockProps, resolveCmssyLayoutSlot };
125
+ export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyLayoutEditableProps, type CmssyLayoutResolution, type CmssyLayoutSlotLocaleSource, type CmssyLayoutSlotResolution, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, LayoutBlockPage, type ResolveCmssyLayoutOptions, type ResolveCmssyLayoutSlotOptions, UnknownBlock, type UnknownBlockProps, resolveCmssyLayout, resolveCmssyLayoutSlot };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, RetryOption, CmssyConfig, RawBlock, CmssyBlockContext } from '@cmssy/core';
2
- export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayout, CmssyLayoutGroup, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRegion, CmssyRegionOf, CmssyRegionSettings, CmssyRequestError, CmssyRetryMode, CmssySiteConfig, CmssyTypedDocument, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, LayoutPosition, LayoutRegion, MediaLike, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryOption, RetryPolicy, SelectMessage, SubmitFormInput, TypedField, createCmssyClient, defineCmssyLayout, fields, graphqlRequest, isProtocolCompatible, mediaAlt, mediaUrl, mediaUrls, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
3
- import { B as BlockDefinition, a as BlockMap } from './registry-CwJ2cby4.js';
4
- export { b as BlockProps, c as buildBlockMap, d as defineBlock } from './registry-CwJ2cby4.js';
1
+ import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, CmssyBlockPage, RetryOption, CmssyConfig, CmssyRegionOf, CmssyRegionSettingsOf, RawBlock, CmssyBlockContext } from '@cmssy/core';
2
+ export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayout, CmssyLayoutGroup, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRegion, CmssyRegionOf, CmssyRegionSettings, CmssyRegionSettingsOf, CmssyRequestError, CmssyRetryMode, CmssySiteConfig, CmssyTypedDocument, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, LayoutPosition, LayoutRegion, MediaLike, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryOption, RetryPolicy, SelectMessage, SubmitFormInput, TypedField, createCmssyClient, defineCmssyLayout, fields, graphqlRequest, isProtocolCompatible, mediaAlt, mediaUrl, mediaUrls, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
3
+ import { B as BlockDefinition, L as LayoutBlockPage, a as BlockMap } from './internal-server-Hogm3pjD.js';
4
+ export { b as BlockProps, E as EditorBlockData, R as ResolveBlockDataOptions, c as ResolveLayoutBlockDataOptions, d as buildBlockMap, e as defineBlock, r as resolveEditorBlockData, f as resolveEditorLayoutBlockData } from './internal-server-Hogm3pjD.js';
5
5
  import { FieldDefinition } from '@cmssy/types';
6
6
  export { FieldCondition, FieldConditionGroup, FieldConditionLogic } from '@cmssy/types';
7
7
  export { buildBlockContext } from '@cmssy/core/internal';
8
8
  import * as react_jsx_runtime from 'react/jsx-runtime';
9
- export { EditorBlockData, ResolveBlockDataOptions, ResolveLayoutBlockDataOptions, resolveEditorBlockData, resolveEditorLayoutBlockData } from './internal-server.js';
10
- import 'react';
9
+ import { ReactElement, ComponentType } from 'react';
11
10
 
12
11
  interface CmssyServerPageProps {
13
12
  page: CmssyPageData | null;
@@ -28,6 +27,7 @@ interface ResolveCmssyLayoutSlotBase {
28
27
  position: string;
29
28
  blocks: BlockDefinition[];
30
29
  editMode: boolean;
30
+ preview?: boolean;
31
31
  page?: string;
32
32
  forms?: Record<string, CmssyFormDefinition>;
33
33
  appContext?: Record<string, unknown>;
@@ -43,6 +43,8 @@ type CmssyLayoutSlotLocaleSource = {
43
43
  type ResolveCmssyLayoutSlotOptions = ResolveCmssyLayoutSlotBase & CmssyLayoutSlotLocaleSource;
44
44
  interface CmssyLayoutSlotResolution {
45
45
  groups: CmssyLayoutGroup[];
46
+ settings: Record<string, unknown> | null;
47
+ page: CmssyBlockPage;
46
48
  locale: string;
47
49
  defaultLocale: string;
48
50
  enabledLocales: string[];
@@ -53,18 +55,49 @@ interface CmssyLayoutSlotResolution {
53
55
  }
54
56
  declare function resolveCmssyLayoutSlot(config: CmssyConfig, options: ResolveCmssyLayoutSlotOptions): Promise<CmssyLayoutSlotResolution>;
55
57
 
58
+ interface CmssyLayoutEditableProps {
59
+ groups: CmssyLayoutGroup[];
60
+ position: string;
61
+ page?: CmssyBlockPage;
62
+ locale: string;
63
+ defaultLocale: string;
64
+ enabledLocales: string[];
65
+ edit: {
66
+ editorOrigin: string | string[];
67
+ };
68
+ data?: Record<string, unknown>;
69
+ resolvedContent?: Record<string, Record<string, unknown>>;
70
+ appContext?: Record<string, unknown>;
71
+ }
72
+ type ResolveCmssyLayoutOptions<C extends CmssyConfig, P extends CmssyRegionOf<C>> = Omit<ResolveCmssyLayoutSlotOptions, "position" | keyof CmssyLayoutSlotLocaleSource> & CmssyLayoutSlotLocaleSource & {
73
+ position: P;
74
+ editable?: ComponentType<CmssyLayoutEditableProps>;
75
+ };
76
+ interface CmssyLayoutResolution<C extends CmssyConfig = CmssyConfig, P extends CmssyRegionOf<C> = CmssyRegionOf<C>> {
77
+ groups: CmssyLayoutGroup[];
78
+ settings: CmssyRegionSettingsOf<C, P> | null;
79
+ page: CmssyBlockPage;
80
+ locale: string;
81
+ defaultLocale: string;
82
+ enabledLocales: string[];
83
+ element: ReactElement<Record<string, unknown>>;
84
+ }
85
+ declare function resolveCmssyLayout<C extends CmssyConfig, P extends CmssyRegionOf<C>>(config: C, options: ResolveCmssyLayoutOptions<C, P>): Promise<CmssyLayoutResolution<C, P>>;
86
+
56
87
  interface CmssyServerLayoutProps {
57
88
  groups: CmssyLayoutGroup[];
58
89
  blocks: BlockDefinition[];
59
90
  position: string;
91
+ page?: LayoutBlockPage;
60
92
  locale?: string;
61
93
  defaultLocale?: string;
62
94
  enabledLocales?: string[];
63
95
  config?: CmssyClientConfig;
64
96
  appContext?: Record<string, unknown>;
65
97
  editMode?: boolean;
98
+ preview?: boolean;
66
99
  }
67
- declare function CmssyServerLayout({ groups, blocks, position, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, appContext, editMode, }: CmssyServerLayoutProps): Promise<react_jsx_runtime.JSX.Element | null>;
100
+ declare function CmssyServerLayout({ groups, blocks, position, page, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, appContext, editMode, preview, }: CmssyServerLayoutProps): Promise<react_jsx_runtime.JSX.Element | null>;
68
101
 
69
102
  interface CmssyBlockProps {
70
103
  block: RawBlock;
@@ -89,4 +122,4 @@ interface UnknownBlockProps {
89
122
  }
90
123
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
91
124
 
92
- export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyLayoutSlotLocaleSource, type CmssyLayoutSlotResolution, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type ResolveCmssyLayoutSlotOptions, UnknownBlock, type UnknownBlockProps, resolveCmssyLayoutSlot };
125
+ export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyLayoutEditableProps, type CmssyLayoutResolution, type CmssyLayoutSlotLocaleSource, type CmssyLayoutSlotResolution, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, LayoutBlockPage, type ResolveCmssyLayoutOptions, type ResolveCmssyLayoutSlotOptions, UnknownBlock, type UnknownBlockProps, resolveCmssyLayout, resolveCmssyLayoutSlot };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { resolveEditorOrigin } from '@cmssy/core';
1
+ import { blocksToSchemas, resolveEditorOrigin } from '@cmssy/core';
2
2
  export { CmssyRequestError, PROTOCOL_VERSION, createCmssyClient, defineCmssyLayout, fields, graphqlRequest, isProtocolCompatible, mediaAlt, mediaUrl, mediaUrls, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
3
3
  import { buildBlockContext, fetchLayouts, getBlockContentForLanguage, normalizeBlockContent, asBucket, resolveSiteLocales as resolveSiteLocales$1, resolveRelationContent } from '@cmssy/core/internal';
4
4
  export { buildBlockContext } from '@cmssy/core/internal';
@@ -8,8 +8,6 @@ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
8
8
  import { resolveSiteLocales, splitLocaleFromPath } from '@cmssy/core/internal/locale';
9
9
 
10
10
  // src/index.ts
11
-
12
- // src/registry.ts
13
11
  function defineBlock(def) {
14
12
  return def;
15
13
  }
@@ -25,18 +23,6 @@ function buildLoaderMap(blocks) {
25
23
  }
26
24
  return map;
27
25
  }
28
- function propsToSchema(props) {
29
- const schema = {};
30
- for (const [key, def] of Object.entries(props)) {
31
- schema[key] = { ...def, label: def.label || key };
32
- }
33
- return schema;
34
- }
35
- function blocksToSchemas(blocks) {
36
- const out = /* @__PURE__ */ Object.create(null);
37
- for (const block of blocks) out[block.type] = propsToSchema(block.props);
38
- return out;
39
- }
40
26
 
41
27
  // src/components/block-error.ts
42
28
  var BLOCK_ERROR_KEY = "__cmssyBlockError";
@@ -364,6 +350,7 @@ async function resolveEditorLayoutBlockData({
364
350
  groups,
365
351
  blocks,
366
352
  position,
353
+ page,
367
354
  locale,
368
355
  defaultLocale,
369
356
  enabledLocales,
@@ -382,7 +369,7 @@ async function resolveEditorLayoutBlockData({
382
369
  enabledLocales,
383
370
  isPreview,
384
371
  forms,
385
- { app: appContext }
372
+ { page, app: appContext }
386
373
  );
387
374
  const resolved = await resolveBlocks(
388
375
  layoutBlocks,
@@ -395,12 +382,16 @@ async function resolveEditorLayoutBlockData({
395
382
  );
396
383
  return collectBlockData(layoutBlocks, resolved, isPreview);
397
384
  }
385
+ function layoutSlotPage(slug) {
386
+ return { slug, path: slug.split("/").filter(Boolean) };
387
+ }
398
388
  async function resolveCmssyLayoutSlot(config, options) {
399
389
  const {
400
390
  position,
401
391
  blocks,
402
392
  editMode,
403
- page,
393
+ preview = false,
394
+ page: explicitPage,
404
395
  forms,
405
396
  appContext,
406
397
  path,
@@ -412,13 +403,15 @@ async function resolveCmssyLayoutSlot(config, options) {
412
403
  const fromPath = path ? splitLocaleFromPath(path, siteLocales) : { locale: siteLocales.defaultLocale, path: [] };
413
404
  const locale = explicitLocale ?? fromPath.locale;
414
405
  const slugSegments = fromPath.path ?? [];
415
- const pageSlug = page ?? "/" + slugSegments.join("/");
416
- const groups = await fetchLayouts(config, pageSlug, {
417
- previewSecret: editMode ? config.draftSecret : void 0,
406
+ const page = layoutSlotPage(explicitPage ?? "/" + slugSegments.join("/"));
407
+ const groups = await fetchLayouts(config, page.slug, {
408
+ previewSecret: editMode || preview ? config.draftSecret : void 0,
418
409
  ...requestOptions
419
410
  });
420
411
  const base = {
421
412
  groups,
413
+ settings: groups.find((g) => g.position === position)?.settings ?? null,
414
+ page,
422
415
  locale,
423
416
  defaultLocale: siteLocales.defaultLocale,
424
417
  enabledLocales: siteLocales.locales,
@@ -429,6 +422,7 @@ async function resolveCmssyLayoutSlot(config, options) {
429
422
  groups,
430
423
  blocks,
431
424
  position,
425
+ page,
432
426
  locale,
433
427
  defaultLocale: siteLocales.defaultLocale,
434
428
  enabledLocales: siteLocales.locales,
@@ -448,12 +442,14 @@ async function CmssyServerLayout({
448
442
  groups,
449
443
  blocks,
450
444
  position,
445
+ page,
451
446
  locale: localeProp,
452
447
  defaultLocale: defaultLocaleProp,
453
448
  enabledLocales: enabledLocalesProp,
454
449
  config,
455
450
  appContext,
456
- editMode
451
+ editMode,
452
+ preview = false
457
453
  }) {
458
454
  const { locale, defaultLocale, enabledLocales } = await resolveRenderLocale({
459
455
  locale: localeProp,
@@ -470,9 +466,9 @@ async function CmssyServerLayout({
470
466
  locale,
471
467
  defaultLocale,
472
468
  enabledLocales,
473
- false,
469
+ preview,
474
470
  void 0,
475
- { app: appContext }
471
+ { page, app: appContext }
476
472
  );
477
473
  const resolved = await resolveBlocks(
478
474
  layoutBlocks,
@@ -494,6 +490,54 @@ async function CmssyServerLayout({
494
490
  })
495
491
  ) });
496
492
  }
493
+ async function resolveCmssyLayout(config, options) {
494
+ const { editable: Editable, ...slotOptions } = options;
495
+ if (slotOptions.editMode && !Editable) {
496
+ throw new Error(
497
+ "cmssy: resolveCmssyLayout needs an `editable` component in edit mode - the editor bridge lives on the client"
498
+ );
499
+ }
500
+ const resolved = await resolveCmssyLayoutSlot(
501
+ config,
502
+ slotOptions
503
+ );
504
+ const { groups, settings, page, locale, defaultLocale, enabledLocales } = resolved;
505
+ const shared = {
506
+ groups,
507
+ position: options.position,
508
+ page,
509
+ locale,
510
+ defaultLocale,
511
+ enabledLocales,
512
+ appContext: options.appContext
513
+ };
514
+ const element = slotOptions.editMode && Editable ? /* @__PURE__ */ jsx(
515
+ Editable,
516
+ {
517
+ ...shared,
518
+ edit: { editorOrigin: resolved.editorOrigin ?? "" },
519
+ data: resolved.data,
520
+ resolvedContent: resolved.resolvedContent
521
+ }
522
+ ) : /* @__PURE__ */ jsx(
523
+ CmssyServerLayout,
524
+ {
525
+ ...shared,
526
+ blocks: options.blocks,
527
+ config,
528
+ preview: slotOptions.preview
529
+ }
530
+ );
531
+ return {
532
+ groups,
533
+ settings,
534
+ page,
535
+ locale,
536
+ defaultLocale,
537
+ enabledLocales,
538
+ element
539
+ };
540
+ }
497
541
  function CmssyBlock({
498
542
  block,
499
543
  locale,
@@ -573,4 +617,4 @@ function CmssyBlock({
573
617
  );
574
618
  }
575
619
 
576
- export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock, resolveCmssyLayoutSlot, resolveEditorBlockData, resolveEditorLayoutBlockData };
620
+ export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock, resolveCmssyLayout, resolveCmssyLayoutSlot, resolveEditorBlockData, resolveEditorLayoutBlockData };
@@ -1,5 +1,5 @@
1
+ import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent, BuildBlockContextExtra, CmssyPageData, CmssyFormDefinition, CmssyClientConfig, CmssyLayoutGroup } from '@cmssy/core';
1
2
  import { ComponentType } from 'react';
2
- import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent, BlockSchema } from '@cmssy/core';
3
3
 
4
4
  interface BlockProps<P extends BlockPropsSchema, D = unknown> {
5
5
  content: InferBlockContent<P>;
@@ -65,6 +65,39 @@ type BlockMap = Record<string, ComponentType<{
65
65
  data?: unknown;
66
66
  }>>;
67
67
  declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
68
- declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
69
68
 
70
- export { type BlockDefinition as B, type BlockMap as a, type BlockProps as b, buildBlockMap as c, defineBlock as d, blocksToSchemas as e };
69
+ type LayoutBlockPage = NonNullable<BuildBlockContextExtra["page"]>;
70
+ interface EditorBlockData {
71
+ data: Record<string, unknown>;
72
+ content: Record<string, Record<string, unknown>>;
73
+ }
74
+ interface ResolveBlockDataOptions {
75
+ page: CmssyPageData | null;
76
+ blocks: BlockDefinition[];
77
+ locale: string;
78
+ defaultLocale: string;
79
+ enabledLocales?: string[];
80
+ forms?: Record<string, CmssyFormDefinition>;
81
+ isPreview?: boolean;
82
+ config?: CmssyClientConfig;
83
+ appContext?: Record<string, unknown>;
84
+ }
85
+ declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
86
+ declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
87
+ interface ResolveLayoutBlockDataOptions {
88
+ groups: CmssyLayoutGroup[];
89
+ blocks: BlockDefinition[];
90
+ position: string;
91
+ page?: LayoutBlockPage;
92
+ locale: string;
93
+ defaultLocale: string;
94
+ enabledLocales?: string[];
95
+ forms?: Record<string, CmssyFormDefinition>;
96
+ isPreview?: boolean;
97
+ config?: CmssyClientConfig;
98
+ appContext?: Record<string, unknown>;
99
+ }
100
+ declare function resolveEditorLayoutBlockData({ groups, blocks, position, page, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
101
+ declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
102
+
103
+ export { type BlockDefinition as B, type EditorBlockData as E, type LayoutBlockPage as L, type ResolveBlockDataOptions as R, type BlockMap as a, type BlockProps as b, type ResolveLayoutBlockDataOptions as c, buildBlockMap as d, defineBlock as e, resolveEditorLayoutBlockData as f, resolveBlockData as g, resolveLayoutBlockData as h, resolveEditorBlockData as r };
@@ -1,5 +1,5 @@
1
+ import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent, BuildBlockContextExtra, CmssyPageData, CmssyFormDefinition, CmssyClientConfig, CmssyLayoutGroup } from '@cmssy/core';
1
2
  import { ComponentType } from 'react';
2
- import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent, BlockSchema } from '@cmssy/core';
3
3
 
4
4
  interface BlockProps<P extends BlockPropsSchema, D = unknown> {
5
5
  content: InferBlockContent<P>;
@@ -65,6 +65,39 @@ type BlockMap = Record<string, ComponentType<{
65
65
  data?: unknown;
66
66
  }>>;
67
67
  declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
68
- declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
69
68
 
70
- export { type BlockDefinition as B, type BlockMap as a, type BlockProps as b, buildBlockMap as c, defineBlock as d, blocksToSchemas as e };
69
+ type LayoutBlockPage = NonNullable<BuildBlockContextExtra["page"]>;
70
+ interface EditorBlockData {
71
+ data: Record<string, unknown>;
72
+ content: Record<string, Record<string, unknown>>;
73
+ }
74
+ interface ResolveBlockDataOptions {
75
+ page: CmssyPageData | null;
76
+ blocks: BlockDefinition[];
77
+ locale: string;
78
+ defaultLocale: string;
79
+ enabledLocales?: string[];
80
+ forms?: Record<string, CmssyFormDefinition>;
81
+ isPreview?: boolean;
82
+ config?: CmssyClientConfig;
83
+ appContext?: Record<string, unknown>;
84
+ }
85
+ declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
86
+ declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
87
+ interface ResolveLayoutBlockDataOptions {
88
+ groups: CmssyLayoutGroup[];
89
+ blocks: BlockDefinition[];
90
+ position: string;
91
+ page?: LayoutBlockPage;
92
+ locale: string;
93
+ defaultLocale: string;
94
+ enabledLocales?: string[];
95
+ forms?: Record<string, CmssyFormDefinition>;
96
+ isPreview?: boolean;
97
+ config?: CmssyClientConfig;
98
+ appContext?: Record<string, unknown>;
99
+ }
100
+ declare function resolveEditorLayoutBlockData({ groups, blocks, position, page, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
101
+ declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
102
+
103
+ export { type BlockDefinition as B, type EditorBlockData as E, type LayoutBlockPage as L, type ResolveBlockDataOptions as R, type BlockMap as a, type BlockProps as b, type ResolveLayoutBlockDataOptions as c, buildBlockMap as d, defineBlock as e, resolveEditorLayoutBlockData as f, resolveBlockData as g, resolveLayoutBlockData as h, resolveEditorBlockData as r };
@@ -1,10 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var internal = require('@cmssy/core/internal');
4
+ var core = require('@cmssy/core');
4
5
 
5
6
  // src/components/resolve-block-data.ts
6
-
7
- // src/registry.ts
8
7
  function buildLoaderMap(blocks) {
9
8
  const map = /* @__PURE__ */ Object.create(null);
10
9
  for (const block of blocks) {
@@ -12,18 +11,6 @@ function buildLoaderMap(blocks) {
12
11
  }
13
12
  return map;
14
13
  }
15
- function propsToSchema(props) {
16
- const schema = {};
17
- for (const [key, def] of Object.entries(props)) {
18
- schema[key] = { ...def, label: def.label || key };
19
- }
20
- return schema;
21
- }
22
- function blocksToSchemas(blocks) {
23
- const out = /* @__PURE__ */ Object.create(null);
24
- for (const block of blocks) out[block.type] = propsToSchema(block.props);
25
- return out;
26
- }
27
14
 
28
15
  // src/components/block-error.ts
29
16
  var BLOCK_ERROR_KEY = "__cmssyBlockError";
@@ -126,7 +113,7 @@ async function resolveEditorBlockData({
126
113
  defaultLocale,
127
114
  context,
128
115
  enabledLocales,
129
- { schemas: blocksToSchemas(blocks), config }
116
+ { schemas: core.blocksToSchemas(blocks), config }
130
117
  );
131
118
  return collectBlockData(page.blocks, resolved, isPreview);
132
119
  }
@@ -137,6 +124,7 @@ async function resolveEditorLayoutBlockData({
137
124
  groups,
138
125
  blocks,
139
126
  position,
127
+ page,
140
128
  locale,
141
129
  defaultLocale,
142
130
  enabledLocales,
@@ -155,7 +143,7 @@ async function resolveEditorLayoutBlockData({
155
143
  enabledLocales,
156
144
  isPreview,
157
145
  forms,
158
- { app: appContext }
146
+ { page, app: appContext }
159
147
  );
160
148
  const resolved = await resolveBlocks(
161
149
  layoutBlocks,
@@ -164,7 +152,7 @@ async function resolveEditorLayoutBlockData({
164
152
  defaultLocale,
165
153
  context,
166
154
  enabledLocales,
167
- { schemas: blocksToSchemas(blocks), config }
155
+ { schemas: core.blocksToSchemas(blocks), config }
168
156
  );
169
157
  return collectBlockData(layoutBlocks, resolved, isPreview);
170
158
  }
@@ -172,7 +160,10 @@ async function resolveLayoutBlockData(options) {
172
160
  return (await resolveEditorLayoutBlockData(options)).data;
173
161
  }
174
162
 
175
- exports.blocksToSchemas = blocksToSchemas;
163
+ Object.defineProperty(exports, "blocksToSchemas", {
164
+ enumerable: true,
165
+ get: function () { return core.blocksToSchemas; }
166
+ });
176
167
  exports.resolveBlockData = resolveBlockData;
177
168
  exports.resolveEditorBlockData = resolveEditorBlockData;
178
169
  exports.resolveEditorLayoutBlockData = resolveEditorLayoutBlockData;
@@ -1,38 +1,3 @@
1
- import { CmssyPageData, CmssyFormDefinition, CmssyClientConfig, CmssyLayoutGroup } from '@cmssy/core';
2
- import { B as BlockDefinition } from './registry-CwJ2cby4.cjs';
3
- export { e as blocksToSchemas } from './registry-CwJ2cby4.cjs';
1
+ export { E as EditorBlockData, R as ResolveBlockDataOptions, c as ResolveLayoutBlockDataOptions, g as resolveBlockData, r as resolveEditorBlockData, f as resolveEditorLayoutBlockData, h as resolveLayoutBlockData } from './internal-server-Hogm3pjD.cjs';
2
+ export { blocksToSchemas } from '@cmssy/core';
4
3
  import 'react';
5
-
6
- interface EditorBlockData {
7
- data: Record<string, unknown>;
8
- content: Record<string, Record<string, unknown>>;
9
- }
10
- interface ResolveBlockDataOptions {
11
- page: CmssyPageData | null;
12
- blocks: BlockDefinition[];
13
- locale: string;
14
- defaultLocale: string;
15
- enabledLocales?: string[];
16
- forms?: Record<string, CmssyFormDefinition>;
17
- isPreview?: boolean;
18
- config?: CmssyClientConfig;
19
- appContext?: Record<string, unknown>;
20
- }
21
- declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
22
- declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
23
- interface ResolveLayoutBlockDataOptions {
24
- groups: CmssyLayoutGroup[];
25
- blocks: BlockDefinition[];
26
- position: string;
27
- locale: string;
28
- defaultLocale: string;
29
- enabledLocales?: string[];
30
- forms?: Record<string, CmssyFormDefinition>;
31
- isPreview?: boolean;
32
- config?: CmssyClientConfig;
33
- appContext?: Record<string, unknown>;
34
- }
35
- declare function resolveEditorLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
36
- declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
37
-
38
- export { type EditorBlockData, type ResolveBlockDataOptions, type ResolveLayoutBlockDataOptions, resolveBlockData, resolveEditorBlockData, resolveEditorLayoutBlockData, resolveLayoutBlockData };
@@ -1,38 +1,3 @@
1
- import { CmssyPageData, CmssyFormDefinition, CmssyClientConfig, CmssyLayoutGroup } from '@cmssy/core';
2
- import { B as BlockDefinition } from './registry-CwJ2cby4.js';
3
- export { e as blocksToSchemas } from './registry-CwJ2cby4.js';
1
+ export { E as EditorBlockData, R as ResolveBlockDataOptions, c as ResolveLayoutBlockDataOptions, g as resolveBlockData, r as resolveEditorBlockData, f as resolveEditorLayoutBlockData, h as resolveLayoutBlockData } from './internal-server-Hogm3pjD.js';
2
+ export { blocksToSchemas } from '@cmssy/core';
4
3
  import 'react';
5
-
6
- interface EditorBlockData {
7
- data: Record<string, unknown>;
8
- content: Record<string, Record<string, unknown>>;
9
- }
10
- interface ResolveBlockDataOptions {
11
- page: CmssyPageData | null;
12
- blocks: BlockDefinition[];
13
- locale: string;
14
- defaultLocale: string;
15
- enabledLocales?: string[];
16
- forms?: Record<string, CmssyFormDefinition>;
17
- isPreview?: boolean;
18
- config?: CmssyClientConfig;
19
- appContext?: Record<string, unknown>;
20
- }
21
- declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
22
- declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
23
- interface ResolveLayoutBlockDataOptions {
24
- groups: CmssyLayoutGroup[];
25
- blocks: BlockDefinition[];
26
- position: string;
27
- locale: string;
28
- defaultLocale: string;
29
- enabledLocales?: string[];
30
- forms?: Record<string, CmssyFormDefinition>;
31
- isPreview?: boolean;
32
- config?: CmssyClientConfig;
33
- appContext?: Record<string, unknown>;
34
- }
35
- declare function resolveEditorLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
36
- declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
37
-
38
- export { type EditorBlockData, type ResolveBlockDataOptions, type ResolveLayoutBlockDataOptions, resolveBlockData, resolveEditorBlockData, resolveEditorLayoutBlockData, resolveLayoutBlockData };
@@ -1,8 +1,8 @@
1
1
  import { buildBlockContext, getBlockContentForLanguage, resolveRelationContent, normalizeBlockContent } from '@cmssy/core/internal';
2
+ import { blocksToSchemas } from '@cmssy/core';
3
+ export { blocksToSchemas } from '@cmssy/core';
2
4
 
3
5
  // src/components/resolve-block-data.ts
4
-
5
- // src/registry.ts
6
6
  function buildLoaderMap(blocks) {
7
7
  const map = /* @__PURE__ */ Object.create(null);
8
8
  for (const block of blocks) {
@@ -10,18 +10,6 @@ function buildLoaderMap(blocks) {
10
10
  }
11
11
  return map;
12
12
  }
13
- function propsToSchema(props) {
14
- const schema = {};
15
- for (const [key, def] of Object.entries(props)) {
16
- schema[key] = { ...def, label: def.label || key };
17
- }
18
- return schema;
19
- }
20
- function blocksToSchemas(blocks) {
21
- const out = /* @__PURE__ */ Object.create(null);
22
- for (const block of blocks) out[block.type] = propsToSchema(block.props);
23
- return out;
24
- }
25
13
 
26
14
  // src/components/block-error.ts
27
15
  var BLOCK_ERROR_KEY = "__cmssyBlockError";
@@ -135,6 +123,7 @@ async function resolveEditorLayoutBlockData({
135
123
  groups,
136
124
  blocks,
137
125
  position,
126
+ page,
138
127
  locale,
139
128
  defaultLocale,
140
129
  enabledLocales,
@@ -153,7 +142,7 @@ async function resolveEditorLayoutBlockData({
153
142
  enabledLocales,
154
143
  isPreview,
155
144
  forms,
156
- { app: appContext }
145
+ { page, app: appContext }
157
146
  );
158
147
  const resolved = await resolveBlocks(
159
148
  layoutBlocks,
@@ -170,4 +159,4 @@ async function resolveLayoutBlockData(options) {
170
159
  return (await resolveEditorLayoutBlockData(options)).data;
171
160
  }
172
161
 
173
- export { blocksToSchemas, resolveBlockData, resolveEditorBlockData, resolveEditorLayoutBlockData, resolveLayoutBlockData };
162
+ export { resolveBlockData, resolveEditorBlockData, resolveEditorLayoutBlockData, resolveLayoutBlockData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "14.0.0",
3
+ "version": "14.2.0",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -96,8 +96,8 @@
96
96
  "vitest": "^2.1.0"
97
97
  },
98
98
  "dependencies": {
99
- "@cmssy/types": "0.38.0",
100
- "@cmssy/core": "14.0.0"
99
+ "@cmssy/types": "0.39.0",
100
+ "@cmssy/core": "14.2.0"
101
101
  },
102
102
  "scripts": {
103
103
  "build": "tsup",