@cmssy/react 0.1.1 → 0.1.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
@@ -415,6 +415,18 @@ function useDragAgent(config) {
415
415
  return { dropY };
416
416
  }
417
417
 
418
+ // src/components/block-context.ts
419
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview) {
420
+ return {
421
+ locale: {
422
+ current: locale,
423
+ default: defaultLocale,
424
+ enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
425
+ },
426
+ isPreview: isPreview ?? false
427
+ };
428
+ }
429
+
418
430
  // src/content/get-block-content.ts
419
431
  function isPlainObject(value) {
420
432
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -455,7 +467,8 @@ function CmssyBlock({
455
467
  blockMap,
456
468
  patchedContent,
457
469
  editable,
458
- layoutPosition
470
+ layoutPosition,
471
+ context
459
472
  }) {
460
473
  const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
461
474
  const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
@@ -468,7 +481,7 @@ function CmssyBlock({
468
481
  "data-layout-position": layoutPosition,
469
482
  draggable: editable || void 0,
470
483
  style: Component ? void 0 : { display: "none" },
471
- children: Component ? react.createElement(Component, { content }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
484
+ children: Component ? react.createElement(Component, { content, context }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
472
485
  }
473
486
  );
474
487
  }
@@ -477,6 +490,7 @@ function CmssyEditablePage({
477
490
  blocks,
478
491
  locale = "en",
479
492
  defaultLocale = "en",
493
+ enabledLocales,
480
494
  edit,
481
495
  category
482
496
  }) {
@@ -493,6 +507,7 @@ function CmssyEditablePage({
493
507
  blocks,
494
508
  locale,
495
509
  defaultLocale,
510
+ enabledLocales,
496
511
  edit,
497
512
  category
498
513
  }
@@ -503,10 +518,15 @@ function EditableBlocks({
503
518
  blocks,
504
519
  locale,
505
520
  defaultLocale,
521
+ enabledLocales,
506
522
  edit,
507
523
  category
508
524
  }) {
509
525
  const blockMap = react.useMemo(() => buildBlockMap(blocks), [blocks]);
526
+ const context = react.useMemo(
527
+ () => buildBlockContext(locale, defaultLocale, enabledLocales, true),
528
+ [locale, defaultLocale, enabledLocales]
529
+ );
510
530
  const bridgeConfig = react.useMemo(
511
531
  () => ({
512
532
  ...edit,
@@ -550,7 +570,8 @@ function EditableBlocks({
550
570
  defaultLocale,
551
571
  patchedContent: patches[block.id],
552
572
  blockMap,
553
- editable: true
573
+ editable: true,
574
+ context
554
575
  },
555
576
  block.id
556
577
  )),
@@ -638,6 +659,7 @@ function CmssyEditableLayout({
638
659
  position,
639
660
  locale = "en",
640
661
  defaultLocale = "en",
662
+ enabledLocales,
641
663
  edit
642
664
  }) {
643
665
  const blockMap = react.useMemo(() => buildBlockMap(blocks), [blocks]);
@@ -646,6 +668,10 @@ function CmssyEditableLayout({
646
668
  return group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
647
669
  }, [groups, position]);
648
670
  const patches = useLayoutPatchBridge(position, edit);
671
+ const context = react.useMemo(
672
+ () => buildBlockContext(locale, defaultLocale, enabledLocales, true),
673
+ [locale, defaultLocale, enabledLocales]
674
+ );
649
675
  if (layoutBlocks.length === 0) return null;
650
676
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: layoutBlocks.map((block) => /* @__PURE__ */ jsxRuntime.jsx(
651
677
  CmssyBlock,
@@ -655,7 +681,8 @@ function CmssyEditableLayout({
655
681
  defaultLocale,
656
682
  blockMap,
657
683
  patchedContent: patches[block.id],
658
- layoutPosition: position
684
+ layoutPosition: position,
685
+ context
659
686
  },
660
687
  block.id
661
688
  )) });
package/dist/client.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup } from './registry-BoxAyw4_.cjs';
2
+ import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup } from './registry-suRGkEQs.cjs';
3
3
  import 'react';
4
4
 
5
5
  interface EditBridgeConfig {
@@ -35,15 +35,17 @@ interface CmssyEditablePageProps {
35
35
  blocks: BlockDefinition[];
36
36
  locale?: string;
37
37
  defaultLocale?: string;
38
+ enabledLocales?: string[];
38
39
  edit: EditBridgeConfig;
39
40
  category?: string;
40
41
  }
41
- declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, edit, category, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
42
+ declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
42
43
 
43
44
  interface CmssyLazyEditorProps {
44
45
  page: CmssyPageData | null;
45
46
  locale?: string;
46
47
  defaultLocale?: string;
48
+ enabledLocales?: string[];
47
49
  edit: EditBridgeConfig;
48
50
  load: () => Promise<{
49
51
  blocks: BlockDefinition[];
@@ -58,15 +60,17 @@ interface CmssyEditableLayoutProps {
58
60
  position: string;
59
61
  locale?: string;
60
62
  defaultLocale?: string;
63
+ enabledLocales?: string[];
61
64
  edit: EditBridgeConfig;
62
65
  }
63
- declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, edit, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
66
+ declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, edit, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
64
67
 
65
68
  interface CmssyLazyLayoutProps {
66
69
  groups: CmssyLayoutGroup[];
67
70
  position: string;
68
71
  locale?: string;
69
72
  defaultLocale?: string;
73
+ enabledLocales?: string[];
70
74
  edit: EditBridgeConfig;
71
75
  load: () => Promise<{
72
76
  blocks: BlockDefinition[];
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup } from './registry-BoxAyw4_.js';
2
+ import { B as BlockSchema, a as BlockMeta, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup } from './registry-suRGkEQs.js';
3
3
  import 'react';
4
4
 
5
5
  interface EditBridgeConfig {
@@ -35,15 +35,17 @@ interface CmssyEditablePageProps {
35
35
  blocks: BlockDefinition[];
36
36
  locale?: string;
37
37
  defaultLocale?: string;
38
+ enabledLocales?: string[];
38
39
  edit: EditBridgeConfig;
39
40
  category?: string;
40
41
  }
41
- declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, edit, category, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
42
+ declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
42
43
 
43
44
  interface CmssyLazyEditorProps {
44
45
  page: CmssyPageData | null;
45
46
  locale?: string;
46
47
  defaultLocale?: string;
48
+ enabledLocales?: string[];
47
49
  edit: EditBridgeConfig;
48
50
  load: () => Promise<{
49
51
  blocks: BlockDefinition[];
@@ -58,15 +60,17 @@ interface CmssyEditableLayoutProps {
58
60
  position: string;
59
61
  locale?: string;
60
62
  defaultLocale?: string;
63
+ enabledLocales?: string[];
61
64
  edit: EditBridgeConfig;
62
65
  }
63
- declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, edit, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
66
+ declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, edit, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
64
67
 
65
68
  interface CmssyLazyLayoutProps {
66
69
  groups: CmssyLayoutGroup[];
67
70
  position: string;
68
71
  locale?: string;
69
72
  defaultLocale?: string;
73
+ enabledLocales?: string[];
70
74
  edit: EditBridgeConfig;
71
75
  load: () => Promise<{
72
76
  blocks: BlockDefinition[];
package/dist/client.js CHANGED
@@ -413,6 +413,18 @@ function useDragAgent(config) {
413
413
  return { dropY };
414
414
  }
415
415
 
416
+ // src/components/block-context.ts
417
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview) {
418
+ return {
419
+ locale: {
420
+ current: locale,
421
+ default: defaultLocale,
422
+ enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
423
+ },
424
+ isPreview: isPreview ?? false
425
+ };
426
+ }
427
+
416
428
  // src/content/get-block-content.ts
417
429
  function isPlainObject(value) {
418
430
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -453,7 +465,8 @@ function CmssyBlock({
453
465
  blockMap,
454
466
  patchedContent,
455
467
  editable,
456
- layoutPosition
468
+ layoutPosition,
469
+ context
457
470
  }) {
458
471
  const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
459
472
  const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
@@ -466,7 +479,7 @@ function CmssyBlock({
466
479
  "data-layout-position": layoutPosition,
467
480
  draggable: editable || void 0,
468
481
  style: Component ? void 0 : { display: "none" },
469
- children: Component ? createElement(Component, { content }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
482
+ children: Component ? createElement(Component, { content, context }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
470
483
  }
471
484
  );
472
485
  }
@@ -475,6 +488,7 @@ function CmssyEditablePage({
475
488
  blocks,
476
489
  locale = "en",
477
490
  defaultLocale = "en",
491
+ enabledLocales,
478
492
  edit,
479
493
  category
480
494
  }) {
@@ -491,6 +505,7 @@ function CmssyEditablePage({
491
505
  blocks,
492
506
  locale,
493
507
  defaultLocale,
508
+ enabledLocales,
494
509
  edit,
495
510
  category
496
511
  }
@@ -501,10 +516,15 @@ function EditableBlocks({
501
516
  blocks,
502
517
  locale,
503
518
  defaultLocale,
519
+ enabledLocales,
504
520
  edit,
505
521
  category
506
522
  }) {
507
523
  const blockMap = useMemo(() => buildBlockMap(blocks), [blocks]);
524
+ const context = useMemo(
525
+ () => buildBlockContext(locale, defaultLocale, enabledLocales, true),
526
+ [locale, defaultLocale, enabledLocales]
527
+ );
508
528
  const bridgeConfig = useMemo(
509
529
  () => ({
510
530
  ...edit,
@@ -548,7 +568,8 @@ function EditableBlocks({
548
568
  defaultLocale,
549
569
  patchedContent: patches[block.id],
550
570
  blockMap,
551
- editable: true
571
+ editable: true,
572
+ context
552
573
  },
553
574
  block.id
554
575
  )),
@@ -636,6 +657,7 @@ function CmssyEditableLayout({
636
657
  position,
637
658
  locale = "en",
638
659
  defaultLocale = "en",
660
+ enabledLocales,
639
661
  edit
640
662
  }) {
641
663
  const blockMap = useMemo(() => buildBlockMap(blocks), [blocks]);
@@ -644,6 +666,10 @@ function CmssyEditableLayout({
644
666
  return group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
645
667
  }, [groups, position]);
646
668
  const patches = useLayoutPatchBridge(position, edit);
669
+ const context = useMemo(
670
+ () => buildBlockContext(locale, defaultLocale, enabledLocales, true),
671
+ [locale, defaultLocale, enabledLocales]
672
+ );
647
673
  if (layoutBlocks.length === 0) return null;
648
674
  return /* @__PURE__ */ jsx(Fragment, { children: layoutBlocks.map((block) => /* @__PURE__ */ jsx(
649
675
  CmssyBlock,
@@ -653,7 +679,8 @@ function CmssyEditableLayout({
653
679
  defaultLocale,
654
680
  blockMap,
655
681
  patchedContent: patches[block.id],
656
- layoutPosition: position
682
+ layoutPosition: position,
683
+ context
657
684
  },
658
685
  block.id
659
686
  )) });
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var jsxRuntime = require('react/jsx-runtime');
4
3
  var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
5
 
6
6
  // src/fields.ts
7
7
  function control(type) {
@@ -60,6 +60,18 @@ function blocksToMeta(blocks, defaults = {}) {
60
60
  return out;
61
61
  }
62
62
 
63
+ // src/components/block-context.ts
64
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview) {
65
+ return {
66
+ locale: {
67
+ current: locale,
68
+ default: defaultLocale,
69
+ enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
70
+ },
71
+ isPreview: isPreview ?? false
72
+ };
73
+ }
74
+
63
75
  // src/content/get-block-content.ts
64
76
  function isPlainObject(value) {
65
77
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -93,8 +105,8 @@ function UnknownBlock({ type }) {
93
105
  }
94
106
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-cmssy-unknown-block": type });
95
107
  }
96
- function renderResolvedBlock(block, map, locale, defaultLocale) {
97
- const Component = map[block.type];
108
+ function renderResolvedBlock(block, map, locale, defaultLocale, context) {
109
+ const Component = Object.hasOwn(map, block.type) ? map[block.type] : void 0;
98
110
  const content = getBlockContentForLanguage(
99
111
  block.content,
100
112
  locale,
@@ -106,7 +118,7 @@ function renderResolvedBlock(block, map, locale, defaultLocale) {
106
118
  "data-block-id": block.id,
107
119
  "data-block-type": block.type,
108
120
  style: Component ? void 0 : { display: "none" },
109
- children: Component ? /* @__PURE__ */ jsxRuntime.jsx(Component, { content }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
121
+ children: Component ? react.createElement(Component, { content, context }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
110
122
  },
111
123
  block.id
112
124
  );
@@ -115,12 +127,14 @@ function CmssyServerPage({
115
127
  page,
116
128
  blocks,
117
129
  locale = "en",
118
- defaultLocale = "en"
130
+ defaultLocale = "en",
131
+ enabledLocales
119
132
  }) {
120
133
  if (!page) return null;
121
134
  const map = buildBlockMap(blocks);
135
+ const context = buildBlockContext(locale, defaultLocale, enabledLocales);
122
136
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: page.blocks.map(
123
- (block) => renderResolvedBlock(block, map, locale, defaultLocale)
137
+ (block) => renderResolvedBlock(block, map, locale, defaultLocale, context)
124
138
  ) });
125
139
  }
126
140
  function CmssyServerLayout({
@@ -128,14 +142,16 @@ function CmssyServerLayout({
128
142
  blocks,
129
143
  position,
130
144
  locale = "en",
131
- defaultLocale = "en"
145
+ defaultLocale = "en",
146
+ enabledLocales
132
147
  }) {
133
148
  const group = groups.find((g) => g.position === position);
134
149
  const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
135
150
  if (layoutBlocks.length === 0) return null;
136
151
  const map = buildBlockMap(blocks);
152
+ const context = buildBlockContext(locale, defaultLocale, enabledLocales);
137
153
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: layoutBlocks.map(
138
- (block) => renderResolvedBlock(block, map, locale, defaultLocale)
154
+ (block) => renderResolvedBlock(block, map, locale, defaultLocale, context)
139
155
  ) });
140
156
  }
141
157
 
@@ -484,7 +500,8 @@ function CmssyBlock({
484
500
  blockMap,
485
501
  patchedContent,
486
502
  editable,
487
- layoutPosition
503
+ layoutPosition,
504
+ context
488
505
  }) {
489
506
  const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
490
507
  const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
@@ -497,7 +514,7 @@ function CmssyBlock({
497
514
  "data-layout-position": layoutPosition,
498
515
  draggable: editable || void 0,
499
516
  style: Component ? void 0 : { display: "none" },
500
- children: Component ? react.createElement(Component, { content }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
517
+ children: Component ? react.createElement(Component, { content, context }) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
501
518
  }
502
519
  );
503
520
  }
@@ -514,6 +531,7 @@ exports.SUBMIT_FORM_MUTATION = SUBMIT_FORM_MUTATION;
514
531
  exports.UnknownBlock = UnknownBlock;
515
532
  exports.blocksToMeta = blocksToMeta;
516
533
  exports.blocksToSchemas = blocksToSchemas;
534
+ exports.buildBlockContext = buildBlockContext;
517
535
  exports.buildBlockMap = buildBlockMap;
518
536
  exports.createCmssyClient = createCmssyClient;
519
537
  exports.defineBlock = defineBlock;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, d as FetchLike, e as CmssyClientConfig, R as RawBlock, f as BlockMap } from './registry-BoxAyw4_.cjs';
2
- export { a as BlockMeta, g as BlockRect, B as BlockSchema, h as BoundsMessage, i as ClickMessage, j as FetchLikeResponse, k as FetchPageOptions, l as FieldType, P as PROTOCOL_VERSION, m as ParentReadyMessage, n as PatchMessage, o as RawLayoutBlock, p as ReadyMessage, S as SelectMessage, q as blocksToMeta, r as blocksToSchemas, s as buildBlockMap, t as defineBlock, u as fetchLayouts, v as fetchPage, w as isProtocolCompatible, x as normalizeSlug } from './registry-BoxAyw4_.cjs';
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, d as FetchLike, e as CmssyClientConfig, R as RawBlock, f as BlockMap, g as CmssyBlockContext } from './registry-suRGkEQs.cjs';
2
+ export { a as BlockMeta, h as BlockRect, B as BlockSchema, i as BoundsMessage, j as ClickMessage, k as CmssyLocaleContext, l as FetchLikeResponse, m as FetchPageOptions, n as FieldType, P as PROTOCOL_VERSION, o as ParentReadyMessage, p as PatchMessage, q as RawLayoutBlock, r as ReadyMessage, S as SelectMessage, s as blocksToMeta, t as blocksToSchemas, u as buildBlockContext, v as buildBlockMap, w as defineBlock, x as fetchLayouts, y as fetchPage, z as isProtocolCompatible, D as normalizeSlug } from './registry-suRGkEQs.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import 'react';
5
5
 
@@ -26,8 +26,10 @@ interface CmssyServerPageProps {
26
26
  blocks: BlockDefinition[];
27
27
  locale?: string;
28
28
  defaultLocale?: string;
29
+ /** All languages enabled on the workspace; exposed to blocks via context.locale.enabled. */
30
+ enabledLocales?: string[];
29
31
  }
30
- declare function CmssyServerPage({ page, blocks, locale, defaultLocale, }: CmssyServerPageProps): react_jsx_runtime.JSX.Element | null;
32
+ declare function CmssyServerPage({ page, blocks, locale, defaultLocale, enabledLocales, }: CmssyServerPageProps): react_jsx_runtime.JSX.Element | null;
31
33
 
32
34
  interface CmssyServerLayoutProps {
33
35
  groups: CmssyLayoutGroup[];
@@ -35,8 +37,10 @@ interface CmssyServerLayoutProps {
35
37
  position: string;
36
38
  locale?: string;
37
39
  defaultLocale?: string;
40
+ /** All languages enabled on the workspace; exposed to blocks via context.locale.enabled. */
41
+ enabledLocales?: string[];
38
42
  }
39
- declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, }: CmssyServerLayoutProps): react_jsx_runtime.JSX.Element | null;
43
+ declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, }: CmssyServerLayoutProps): react_jsx_runtime.JSX.Element | null;
40
44
 
41
45
  interface PostTarget {
42
46
  postMessage: (message: unknown, targetOrigin: string) => void;
@@ -155,12 +159,13 @@ interface CmssyBlockProps {
155
159
  patchedContent?: Record<string, unknown>;
156
160
  editable?: boolean;
157
161
  layoutPosition?: string;
162
+ context?: CmssyBlockContext;
158
163
  }
159
- declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
164
+ declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
160
165
 
161
166
  interface UnknownBlockProps {
162
167
  type: string;
163
168
  }
164
169
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
165
170
 
166
- export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, type CmssyFormDefinition, type CmssyFormField, type CmssyFormSettings, type CmssyFormSubmitResponse, CmssyLayoutGroup, type CmssyModelDefinition, type CmssyModelRecord, CmssyPageData, type CmssyRecordList, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type CmssySiteConfig, EditorToAppMessage, FORM_QUERY, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, type PostTarget, type QueryScopedOptions, RawBlock, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, type SubmitFormInput, UnknownBlock, type UnknownBlockProps, createCmssyClient, fields, getBlockContentForLanguage, graphqlRequest, normalizeOrigin, parseEditorMessage, postToEditor };
171
+ export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, CmssyBlockContext, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, type CmssyFormDefinition, type CmssyFormField, type CmssyFormSettings, type CmssyFormSubmitResponse, CmssyLayoutGroup, type CmssyModelDefinition, type CmssyModelRecord, CmssyPageData, type CmssyRecordList, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type CmssySiteConfig, EditorToAppMessage, FORM_QUERY, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, type PostTarget, type QueryScopedOptions, RawBlock, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, type SubmitFormInput, UnknownBlock, type UnknownBlockProps, createCmssyClient, fields, getBlockContentForLanguage, graphqlRequest, normalizeOrigin, parseEditorMessage, postToEditor };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, d as FetchLike, e as CmssyClientConfig, R as RawBlock, f as BlockMap } from './registry-BoxAyw4_.js';
2
- export { a as BlockMeta, g as BlockRect, B as BlockSchema, h as BoundsMessage, i as ClickMessage, j as FetchLikeResponse, k as FetchPageOptions, l as FieldType, P as PROTOCOL_VERSION, m as ParentReadyMessage, n as PatchMessage, o as RawLayoutBlock, p as ReadyMessage, S as SelectMessage, q as blocksToMeta, r as blocksToSchemas, s as buildBlockMap, t as defineBlock, u as fetchLayouts, v as fetchPage, w as isProtocolCompatible, x as normalizeSlug } from './registry-BoxAyw4_.js';
1
+ import { F as FieldDefinition, C as CmssyPageData, b as BlockDefinition, c as CmssyLayoutGroup, E as EditorToAppMessage, A as AppToEditorMessage, d as FetchLike, e as CmssyClientConfig, R as RawBlock, f as BlockMap, g as CmssyBlockContext } from './registry-suRGkEQs.js';
2
+ export { a as BlockMeta, h as BlockRect, B as BlockSchema, i as BoundsMessage, j as ClickMessage, k as CmssyLocaleContext, l as FetchLikeResponse, m as FetchPageOptions, n as FieldType, P as PROTOCOL_VERSION, o as ParentReadyMessage, p as PatchMessage, q as RawLayoutBlock, r as ReadyMessage, S as SelectMessage, s as blocksToMeta, t as blocksToSchemas, u as buildBlockContext, v as buildBlockMap, w as defineBlock, x as fetchLayouts, y as fetchPage, z as isProtocolCompatible, D as normalizeSlug } from './registry-suRGkEQs.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import 'react';
5
5
 
@@ -26,8 +26,10 @@ interface CmssyServerPageProps {
26
26
  blocks: BlockDefinition[];
27
27
  locale?: string;
28
28
  defaultLocale?: string;
29
+ /** All languages enabled on the workspace; exposed to blocks via context.locale.enabled. */
30
+ enabledLocales?: string[];
29
31
  }
30
- declare function CmssyServerPage({ page, blocks, locale, defaultLocale, }: CmssyServerPageProps): react_jsx_runtime.JSX.Element | null;
32
+ declare function CmssyServerPage({ page, blocks, locale, defaultLocale, enabledLocales, }: CmssyServerPageProps): react_jsx_runtime.JSX.Element | null;
31
33
 
32
34
  interface CmssyServerLayoutProps {
33
35
  groups: CmssyLayoutGroup[];
@@ -35,8 +37,10 @@ interface CmssyServerLayoutProps {
35
37
  position: string;
36
38
  locale?: string;
37
39
  defaultLocale?: string;
40
+ /** All languages enabled on the workspace; exposed to blocks via context.locale.enabled. */
41
+ enabledLocales?: string[];
38
42
  }
39
- declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, }: CmssyServerLayoutProps): react_jsx_runtime.JSX.Element | null;
43
+ declare function CmssyServerLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, }: CmssyServerLayoutProps): react_jsx_runtime.JSX.Element | null;
40
44
 
41
45
  interface PostTarget {
42
46
  postMessage: (message: unknown, targetOrigin: string) => void;
@@ -155,12 +159,13 @@ interface CmssyBlockProps {
155
159
  patchedContent?: Record<string, unknown>;
156
160
  editable?: boolean;
157
161
  layoutPosition?: string;
162
+ context?: CmssyBlockContext;
158
163
  }
159
- declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
164
+ declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
160
165
 
161
166
  interface UnknownBlockProps {
162
167
  type: string;
163
168
  }
164
169
  declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
165
170
 
166
- export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, type CmssyFormDefinition, type CmssyFormField, type CmssyFormSettings, type CmssyFormSubmitResponse, CmssyLayoutGroup, type CmssyModelDefinition, type CmssyModelRecord, CmssyPageData, type CmssyRecordList, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type CmssySiteConfig, EditorToAppMessage, FORM_QUERY, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, type PostTarget, type QueryScopedOptions, RawBlock, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, type SubmitFormInput, UnknownBlock, type UnknownBlockProps, createCmssyClient, fields, getBlockContentForLanguage, graphqlRequest, normalizeOrigin, parseEditorMessage, postToEditor };
171
+ export { AppToEditorMessage, BlockDefinition, BlockMap, CmssyBlock, CmssyBlockContext, type CmssyBlockProps, type CmssyClient, CmssyClientConfig, type CmssyFormDefinition, type CmssyFormField, type CmssyFormSettings, type CmssyFormSubmitResponse, CmssyLayoutGroup, type CmssyModelDefinition, type CmssyModelRecord, CmssyPageData, type CmssyRecordList, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type CmssySiteConfig, EditorToAppMessage, FORM_QUERY, FetchLike, type FieldControl, FieldDefinition, type GraphqlRequestOptions, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, type PostTarget, type QueryScopedOptions, RawBlock, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, type SubmitFormInput, UnknownBlock, type UnknownBlockProps, createCmssyClient, fields, getBlockContentForLanguage, graphqlRequest, normalizeOrigin, parseEditorMessage, postToEditor };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { jsx, Fragment } from 'react/jsx-runtime';
2
1
  import { createElement } from 'react';
2
+ import { jsx, Fragment } from 'react/jsx-runtime';
3
3
 
4
4
  // src/fields.ts
5
5
  function control(type) {
@@ -58,6 +58,18 @@ function blocksToMeta(blocks, defaults = {}) {
58
58
  return out;
59
59
  }
60
60
 
61
+ // src/components/block-context.ts
62
+ function buildBlockContext(locale, defaultLocale, enabledLocales, isPreview) {
63
+ return {
64
+ locale: {
65
+ current: locale,
66
+ default: defaultLocale,
67
+ enabled: enabledLocales && enabledLocales.length > 0 ? enabledLocales : Array.from(/* @__PURE__ */ new Set([defaultLocale, locale]))
68
+ },
69
+ isPreview: isPreview ?? false
70
+ };
71
+ }
72
+
61
73
  // src/content/get-block-content.ts
62
74
  function isPlainObject(value) {
63
75
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -91,8 +103,8 @@ function UnknownBlock({ type }) {
91
103
  }
92
104
  return /* @__PURE__ */ jsx("div", { "data-cmssy-unknown-block": type });
93
105
  }
94
- function renderResolvedBlock(block, map, locale, defaultLocale) {
95
- const Component = map[block.type];
106
+ function renderResolvedBlock(block, map, locale, defaultLocale, context) {
107
+ const Component = Object.hasOwn(map, block.type) ? map[block.type] : void 0;
96
108
  const content = getBlockContentForLanguage(
97
109
  block.content,
98
110
  locale,
@@ -104,7 +116,7 @@ function renderResolvedBlock(block, map, locale, defaultLocale) {
104
116
  "data-block-id": block.id,
105
117
  "data-block-type": block.type,
106
118
  style: Component ? void 0 : { display: "none" },
107
- children: Component ? /* @__PURE__ */ jsx(Component, { content }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
119
+ children: Component ? createElement(Component, { content, context }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
108
120
  },
109
121
  block.id
110
122
  );
@@ -113,12 +125,14 @@ function CmssyServerPage({
113
125
  page,
114
126
  blocks,
115
127
  locale = "en",
116
- defaultLocale = "en"
128
+ defaultLocale = "en",
129
+ enabledLocales
117
130
  }) {
118
131
  if (!page) return null;
119
132
  const map = buildBlockMap(blocks);
133
+ const context = buildBlockContext(locale, defaultLocale, enabledLocales);
120
134
  return /* @__PURE__ */ jsx(Fragment, { children: page.blocks.map(
121
- (block) => renderResolvedBlock(block, map, locale, defaultLocale)
135
+ (block) => renderResolvedBlock(block, map, locale, defaultLocale, context)
122
136
  ) });
123
137
  }
124
138
  function CmssyServerLayout({
@@ -126,14 +140,16 @@ function CmssyServerLayout({
126
140
  blocks,
127
141
  position,
128
142
  locale = "en",
129
- defaultLocale = "en"
143
+ defaultLocale = "en",
144
+ enabledLocales
130
145
  }) {
131
146
  const group = groups.find((g) => g.position === position);
132
147
  const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
133
148
  if (layoutBlocks.length === 0) return null;
134
149
  const map = buildBlockMap(blocks);
150
+ const context = buildBlockContext(locale, defaultLocale, enabledLocales);
135
151
  return /* @__PURE__ */ jsx(Fragment, { children: layoutBlocks.map(
136
- (block) => renderResolvedBlock(block, map, locale, defaultLocale)
152
+ (block) => renderResolvedBlock(block, map, locale, defaultLocale, context)
137
153
  ) });
138
154
  }
139
155
 
@@ -482,7 +498,8 @@ function CmssyBlock({
482
498
  blockMap,
483
499
  patchedContent,
484
500
  editable,
485
- layoutPosition
501
+ layoutPosition,
502
+ context
486
503
  }) {
487
504
  const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
488
505
  const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
@@ -495,9 +512,9 @@ function CmssyBlock({
495
512
  "data-layout-position": layoutPosition,
496
513
  draggable: editable || void 0,
497
514
  style: Component ? void 0 : { display: "none" },
498
- children: Component ? createElement(Component, { content }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
515
+ children: Component ? createElement(Component, { content, context }) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
499
516
  }
500
517
  );
501
518
  }
502
519
 
503
- export { CmssyBlock, CmssyServerLayout, CmssyServerPage, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, PROTOCOL_VERSION, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, UnknownBlock, blocksToMeta, blocksToSchemas, buildBlockMap, createCmssyClient, defineBlock, fetchLayouts, fetchPage, fields, getBlockContentForLanguage, graphqlRequest, isProtocolCompatible, normalizeOrigin, normalizeSlug, parseEditorMessage, postToEditor };
520
+ export { CmssyBlock, CmssyServerLayout, CmssyServerPage, FORM_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, PROTOCOL_VERSION, SITE_CONFIG_QUERY, SUBMIT_FORM_MUTATION, UnknownBlock, blocksToMeta, blocksToSchemas, buildBlockContext, buildBlockMap, createCmssyClient, defineBlock, fetchLayouts, fetchPage, fields, getBlockContentForLanguage, graphqlRequest, isProtocolCompatible, normalizeOrigin, normalizeSlug, parseEditorMessage, postToEditor };
@@ -44,6 +44,17 @@ declare function normalizeSlug(path: string | string[] | undefined): string;
44
44
  declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
45
45
  declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
46
46
 
47
+ interface CmssyLocaleContext {
48
+ current: string;
49
+ default: string;
50
+ enabled: string[];
51
+ }
52
+ interface CmssyBlockContext {
53
+ locale: CmssyLocaleContext;
54
+ isPreview: boolean;
55
+ }
56
+ declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean): CmssyBlockContext;
57
+
47
58
  declare const PROTOCOL_VERSION = 1;
48
59
  type FieldType = "singleLine" | "multiLine" | "richText" | "numeric" | "date" | "media" | "link" | "select" | "multiselect" | "boolean" | "color" | "repeater";
49
60
  interface FieldDefinition {
@@ -164,6 +175,7 @@ interface BlockDefinition {
164
175
  props: Record<string, FieldDefinition>;
165
176
  component: ComponentType<{
166
177
  content: Record<string, unknown>;
178
+ context?: CmssyBlockContext;
167
179
  }>;
168
180
  }
169
181
  declare function defineBlock<C extends Record<string, unknown>>(def: {
@@ -175,10 +187,12 @@ declare function defineBlock<C extends Record<string, unknown>>(def: {
175
187
  props: Record<string, FieldDefinition>;
176
188
  component: ComponentType<{
177
189
  content: C;
190
+ context?: CmssyBlockContext;
178
191
  }>;
179
192
  }): BlockDefinition;
180
193
  type BlockMap = Record<string, ComponentType<{
181
194
  content: Record<string, unknown>;
195
+ context?: CmssyBlockContext;
182
196
  }>>;
183
197
  declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
184
198
  declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
@@ -186,4 +200,4 @@ declare function blocksToMeta(blocks: BlockDefinition[], defaults?: {
186
200
  category?: string;
187
201
  }): Record<string, BlockMeta>;
188
202
 
189
- export { type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type EditorToAppMessage as E, type FieldDefinition as F, PROTOCOL_VERSION as P, type RawBlock as R, type SelectMessage as S, type BlockMeta as a, type BlockDefinition as b, type CmssyLayoutGroup as c, type FetchLike as d, type CmssyClientConfig as e, type BlockMap as f, type BlockRect as g, type BoundsMessage as h, type ClickMessage as i, type FetchLikeResponse as j, type FetchPageOptions as k, type FieldType as l, type ParentReadyMessage as m, type PatchMessage as n, type RawLayoutBlock as o, type ReadyMessage as p, blocksToMeta as q, blocksToSchemas as r, buildBlockMap as s, defineBlock as t, fetchLayouts as u, fetchPage as v, isProtocolCompatible as w, normalizeSlug as x };
203
+ export { type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, normalizeSlug as D, type EditorToAppMessage as E, type FieldDefinition as F, PROTOCOL_VERSION as P, type RawBlock as R, type SelectMessage as S, type BlockMeta as a, type BlockDefinition as b, type CmssyLayoutGroup as c, type FetchLike as d, type CmssyClientConfig as e, type BlockMap as f, type CmssyBlockContext as g, type BlockRect as h, type BoundsMessage as i, type ClickMessage as j, type CmssyLocaleContext as k, type FetchLikeResponse as l, type FetchPageOptions as m, type FieldType as n, type ParentReadyMessage as o, type PatchMessage as p, type RawLayoutBlock as q, type ReadyMessage as r, blocksToMeta as s, blocksToSchemas as t, buildBlockContext as u, buildBlockMap as v, defineBlock as w, fetchLayouts as x, fetchPage as y, isProtocolCompatible as z };
@@ -44,6 +44,17 @@ declare function normalizeSlug(path: string | string[] | undefined): string;
44
44
  declare function fetchPage(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyPageData | null>;
45
45
  declare function fetchLayouts(config: CmssyClientConfig, path: string | string[] | undefined, options?: FetchPageOptions): Promise<CmssyLayoutGroup[]>;
46
46
 
47
+ interface CmssyLocaleContext {
48
+ current: string;
49
+ default: string;
50
+ enabled: string[];
51
+ }
52
+ interface CmssyBlockContext {
53
+ locale: CmssyLocaleContext;
54
+ isPreview: boolean;
55
+ }
56
+ declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean): CmssyBlockContext;
57
+
47
58
  declare const PROTOCOL_VERSION = 1;
48
59
  type FieldType = "singleLine" | "multiLine" | "richText" | "numeric" | "date" | "media" | "link" | "select" | "multiselect" | "boolean" | "color" | "repeater";
49
60
  interface FieldDefinition {
@@ -164,6 +175,7 @@ interface BlockDefinition {
164
175
  props: Record<string, FieldDefinition>;
165
176
  component: ComponentType<{
166
177
  content: Record<string, unknown>;
178
+ context?: CmssyBlockContext;
167
179
  }>;
168
180
  }
169
181
  declare function defineBlock<C extends Record<string, unknown>>(def: {
@@ -175,10 +187,12 @@ declare function defineBlock<C extends Record<string, unknown>>(def: {
175
187
  props: Record<string, FieldDefinition>;
176
188
  component: ComponentType<{
177
189
  content: C;
190
+ context?: CmssyBlockContext;
178
191
  }>;
179
192
  }): BlockDefinition;
180
193
  type BlockMap = Record<string, ComponentType<{
181
194
  content: Record<string, unknown>;
195
+ context?: CmssyBlockContext;
182
196
  }>>;
183
197
  declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
184
198
  declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
@@ -186,4 +200,4 @@ declare function blocksToMeta(blocks: BlockDefinition[], defaults?: {
186
200
  category?: string;
187
201
  }): Record<string, BlockMeta>;
188
202
 
189
- export { type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, type EditorToAppMessage as E, type FieldDefinition as F, PROTOCOL_VERSION as P, type RawBlock as R, type SelectMessage as S, type BlockMeta as a, type BlockDefinition as b, type CmssyLayoutGroup as c, type FetchLike as d, type CmssyClientConfig as e, type BlockMap as f, type BlockRect as g, type BoundsMessage as h, type ClickMessage as i, type FetchLikeResponse as j, type FetchPageOptions as k, type FieldType as l, type ParentReadyMessage as m, type PatchMessage as n, type RawLayoutBlock as o, type ReadyMessage as p, blocksToMeta as q, blocksToSchemas as r, buildBlockMap as s, defineBlock as t, fetchLayouts as u, fetchPage as v, isProtocolCompatible as w, normalizeSlug as x };
203
+ export { type AppToEditorMessage as A, type BlockSchema as B, type CmssyPageData as C, normalizeSlug as D, type EditorToAppMessage as E, type FieldDefinition as F, PROTOCOL_VERSION as P, type RawBlock as R, type SelectMessage as S, type BlockMeta as a, type BlockDefinition as b, type CmssyLayoutGroup as c, type FetchLike as d, type CmssyClientConfig as e, type BlockMap as f, type CmssyBlockContext as g, type BlockRect as h, type BoundsMessage as i, type ClickMessage as j, type CmssyLocaleContext as k, type FetchLikeResponse as l, type FetchPageOptions as m, type FieldType as n, type ParentReadyMessage as o, type PatchMessage as p, type RawLayoutBlock as q, type ReadyMessage as r, blocksToMeta as s, blocksToSchemas as t, buildBlockContext as u, buildBlockMap as v, defineBlock as w, fetchLayouts as x, fetchPage as y, isProtocolCompatible as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",