@cmssy/react 8.0.1 → 8.0.3
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 +16 -8
- package/dist/client.d.cts +6 -2
- package/dist/client.d.ts +6 -2
- package/dist/client.js +16 -8
- package/dist/index.cjs +75 -2
- package/dist/index.d.cts +25 -2
- package/dist/index.d.ts +25 -2
- package/dist/index.js +74 -3
- package/package.json +2 -2
package/dist/client.cjs
CHANGED
|
@@ -441,7 +441,8 @@ function CmssyBlock({
|
|
|
441
441
|
patchedAdvanced,
|
|
442
442
|
editable,
|
|
443
443
|
layoutPosition,
|
|
444
|
-
context
|
|
444
|
+
context,
|
|
445
|
+
data
|
|
445
446
|
}) {
|
|
446
447
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
447
448
|
const base = core.getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
@@ -460,7 +461,8 @@ function CmssyBlock({
|
|
|
460
461
|
content,
|
|
461
462
|
style,
|
|
462
463
|
advanced,
|
|
463
|
-
context
|
|
464
|
+
context,
|
|
465
|
+
data
|
|
464
466
|
}) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
465
467
|
}
|
|
466
468
|
);
|
|
@@ -473,7 +475,8 @@ function CmssyEditablePage({
|
|
|
473
475
|
enabledLocales,
|
|
474
476
|
edit,
|
|
475
477
|
category,
|
|
476
|
-
forms
|
|
478
|
+
forms,
|
|
479
|
+
data
|
|
477
480
|
}) {
|
|
478
481
|
if (!Array.isArray(blocks)) {
|
|
479
482
|
throw new Error(
|
|
@@ -491,7 +494,8 @@ function CmssyEditablePage({
|
|
|
491
494
|
enabledLocales,
|
|
492
495
|
edit,
|
|
493
496
|
category,
|
|
494
|
-
forms
|
|
497
|
+
forms,
|
|
498
|
+
data
|
|
495
499
|
}
|
|
496
500
|
);
|
|
497
501
|
}
|
|
@@ -503,7 +507,8 @@ function EditableBlocks({
|
|
|
503
507
|
enabledLocales,
|
|
504
508
|
edit,
|
|
505
509
|
category,
|
|
506
|
-
forms
|
|
510
|
+
forms,
|
|
511
|
+
data
|
|
507
512
|
}) {
|
|
508
513
|
const blockMap = react.useMemo(() => buildBlockMap(blocks), [blocks]);
|
|
509
514
|
const context = react.useMemo(
|
|
@@ -555,7 +560,8 @@ function EditableBlocks({
|
|
|
555
560
|
patchedAdvanced: patchesAdvanced[block.id],
|
|
556
561
|
blockMap,
|
|
557
562
|
editable: true,
|
|
558
|
-
context
|
|
563
|
+
context,
|
|
564
|
+
data: data?.[block.id]
|
|
559
565
|
},
|
|
560
566
|
block.id
|
|
561
567
|
)),
|
|
@@ -646,7 +652,8 @@ function CmssyEditableLayout({
|
|
|
646
652
|
locale = "en",
|
|
647
653
|
defaultLocale = "en",
|
|
648
654
|
enabledLocales,
|
|
649
|
-
edit
|
|
655
|
+
edit,
|
|
656
|
+
data
|
|
650
657
|
}) {
|
|
651
658
|
const blockMap = react.useMemo(() => buildBlockMap(blocks), [blocks]);
|
|
652
659
|
const layoutBlocks = react.useMemo(() => {
|
|
@@ -668,7 +675,8 @@ function CmssyEditableLayout({
|
|
|
668
675
|
blockMap,
|
|
669
676
|
patchedContent: patches[block.id],
|
|
670
677
|
layoutPosition: position,
|
|
671
|
-
context
|
|
678
|
+
context,
|
|
679
|
+
data: data?.[block.id]
|
|
672
680
|
},
|
|
673
681
|
block.id
|
|
674
682
|
)) });
|
package/dist/client.d.cts
CHANGED
|
@@ -47,8 +47,9 @@ interface CmssyEditablePageProps {
|
|
|
47
47
|
edit: EditBridgeConfig;
|
|
48
48
|
category?: string;
|
|
49
49
|
forms?: Record<string, CmssyFormDefinition>;
|
|
50
|
+
data?: Record<string, unknown>;
|
|
50
51
|
}
|
|
51
|
-
declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, forms, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
|
|
52
|
+
declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, forms, data, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
|
|
52
53
|
|
|
53
54
|
interface CmssyLazyEditorProps {
|
|
54
55
|
page: CmssyPageData | null;
|
|
@@ -57,6 +58,7 @@ interface CmssyLazyEditorProps {
|
|
|
57
58
|
enabledLocales?: string[];
|
|
58
59
|
edit: EditBridgeConfig;
|
|
59
60
|
forms?: Record<string, CmssyFormDefinition>;
|
|
61
|
+
data?: Record<string, unknown>;
|
|
60
62
|
load: () => Promise<{
|
|
61
63
|
blocks: BlockDefinition[];
|
|
62
64
|
category?: string;
|
|
@@ -72,8 +74,9 @@ interface CmssyEditableLayoutProps {
|
|
|
72
74
|
defaultLocale?: string;
|
|
73
75
|
enabledLocales?: string[];
|
|
74
76
|
edit: EditBridgeConfig;
|
|
77
|
+
data?: Record<string, unknown>;
|
|
75
78
|
}
|
|
76
|
-
declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, edit, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
|
|
79
|
+
declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, edit, data, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
|
|
77
80
|
|
|
78
81
|
interface CmssyLazyLayoutProps {
|
|
79
82
|
groups: CmssyLayoutGroup[];
|
|
@@ -82,6 +85,7 @@ interface CmssyLazyLayoutProps {
|
|
|
82
85
|
defaultLocale?: string;
|
|
83
86
|
enabledLocales?: string[];
|
|
84
87
|
edit: EditBridgeConfig;
|
|
88
|
+
data?: Record<string, unknown>;
|
|
85
89
|
load: () => Promise<{
|
|
86
90
|
blocks: BlockDefinition[];
|
|
87
91
|
}>;
|
package/dist/client.d.ts
CHANGED
|
@@ -47,8 +47,9 @@ interface CmssyEditablePageProps {
|
|
|
47
47
|
edit: EditBridgeConfig;
|
|
48
48
|
category?: string;
|
|
49
49
|
forms?: Record<string, CmssyFormDefinition>;
|
|
50
|
+
data?: Record<string, unknown>;
|
|
50
51
|
}
|
|
51
|
-
declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, forms, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
|
|
52
|
+
declare function CmssyEditablePage({ page, blocks, locale, defaultLocale, enabledLocales, edit, category, forms, data, }: CmssyEditablePageProps): react_jsx_runtime.JSX.Element | null;
|
|
52
53
|
|
|
53
54
|
interface CmssyLazyEditorProps {
|
|
54
55
|
page: CmssyPageData | null;
|
|
@@ -57,6 +58,7 @@ interface CmssyLazyEditorProps {
|
|
|
57
58
|
enabledLocales?: string[];
|
|
58
59
|
edit: EditBridgeConfig;
|
|
59
60
|
forms?: Record<string, CmssyFormDefinition>;
|
|
61
|
+
data?: Record<string, unknown>;
|
|
60
62
|
load: () => Promise<{
|
|
61
63
|
blocks: BlockDefinition[];
|
|
62
64
|
category?: string;
|
|
@@ -72,8 +74,9 @@ interface CmssyEditableLayoutProps {
|
|
|
72
74
|
defaultLocale?: string;
|
|
73
75
|
enabledLocales?: string[];
|
|
74
76
|
edit: EditBridgeConfig;
|
|
77
|
+
data?: Record<string, unknown>;
|
|
75
78
|
}
|
|
76
|
-
declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, edit, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
|
|
79
|
+
declare function CmssyEditableLayout({ groups, blocks, position, locale, defaultLocale, enabledLocales, edit, data, }: CmssyEditableLayoutProps): react_jsx_runtime.JSX.Element | null;
|
|
77
80
|
|
|
78
81
|
interface CmssyLazyLayoutProps {
|
|
79
82
|
groups: CmssyLayoutGroup[];
|
|
@@ -82,6 +85,7 @@ interface CmssyLazyLayoutProps {
|
|
|
82
85
|
defaultLocale?: string;
|
|
83
86
|
enabledLocales?: string[];
|
|
84
87
|
edit: EditBridgeConfig;
|
|
88
|
+
data?: Record<string, unknown>;
|
|
85
89
|
load: () => Promise<{
|
|
86
90
|
blocks: BlockDefinition[];
|
|
87
91
|
}>;
|
package/dist/client.js
CHANGED
|
@@ -440,7 +440,8 @@ function CmssyBlock({
|
|
|
440
440
|
patchedAdvanced,
|
|
441
441
|
editable,
|
|
442
442
|
layoutPosition,
|
|
443
|
-
context
|
|
443
|
+
context,
|
|
444
|
+
data
|
|
444
445
|
}) {
|
|
445
446
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
446
447
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
@@ -459,7 +460,8 @@ function CmssyBlock({
|
|
|
459
460
|
content,
|
|
460
461
|
style,
|
|
461
462
|
advanced,
|
|
462
|
-
context
|
|
463
|
+
context,
|
|
464
|
+
data
|
|
463
465
|
}) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
464
466
|
}
|
|
465
467
|
);
|
|
@@ -472,7 +474,8 @@ function CmssyEditablePage({
|
|
|
472
474
|
enabledLocales,
|
|
473
475
|
edit,
|
|
474
476
|
category,
|
|
475
|
-
forms
|
|
477
|
+
forms,
|
|
478
|
+
data
|
|
476
479
|
}) {
|
|
477
480
|
if (!Array.isArray(blocks)) {
|
|
478
481
|
throw new Error(
|
|
@@ -490,7 +493,8 @@ function CmssyEditablePage({
|
|
|
490
493
|
enabledLocales,
|
|
491
494
|
edit,
|
|
492
495
|
category,
|
|
493
|
-
forms
|
|
496
|
+
forms,
|
|
497
|
+
data
|
|
494
498
|
}
|
|
495
499
|
);
|
|
496
500
|
}
|
|
@@ -502,7 +506,8 @@ function EditableBlocks({
|
|
|
502
506
|
enabledLocales,
|
|
503
507
|
edit,
|
|
504
508
|
category,
|
|
505
|
-
forms
|
|
509
|
+
forms,
|
|
510
|
+
data
|
|
506
511
|
}) {
|
|
507
512
|
const blockMap = useMemo(() => buildBlockMap(blocks), [blocks]);
|
|
508
513
|
const context = useMemo(
|
|
@@ -554,7 +559,8 @@ function EditableBlocks({
|
|
|
554
559
|
patchedAdvanced: patchesAdvanced[block.id],
|
|
555
560
|
blockMap,
|
|
556
561
|
editable: true,
|
|
557
|
-
context
|
|
562
|
+
context,
|
|
563
|
+
data: data?.[block.id]
|
|
558
564
|
},
|
|
559
565
|
block.id
|
|
560
566
|
)),
|
|
@@ -645,7 +651,8 @@ function CmssyEditableLayout({
|
|
|
645
651
|
locale = "en",
|
|
646
652
|
defaultLocale = "en",
|
|
647
653
|
enabledLocales,
|
|
648
|
-
edit
|
|
654
|
+
edit,
|
|
655
|
+
data
|
|
649
656
|
}) {
|
|
650
657
|
const blockMap = useMemo(() => buildBlockMap(blocks), [blocks]);
|
|
651
658
|
const layoutBlocks = useMemo(() => {
|
|
@@ -667,7 +674,8 @@ function CmssyEditableLayout({
|
|
|
667
674
|
blockMap,
|
|
668
675
|
patchedContent: patches[block.id],
|
|
669
676
|
layoutPosition: position,
|
|
670
|
-
context
|
|
677
|
+
context,
|
|
678
|
+
data: data?.[block.id]
|
|
671
679
|
},
|
|
672
680
|
block.id
|
|
673
681
|
)) });
|
package/dist/index.cjs
CHANGED
|
@@ -184,6 +184,75 @@ async function CmssyServerPage({
|
|
|
184
184
|
})
|
|
185
185
|
) });
|
|
186
186
|
}
|
|
187
|
+
async function resolveBlockData({
|
|
188
|
+
page,
|
|
189
|
+
blocks,
|
|
190
|
+
locale,
|
|
191
|
+
defaultLocale,
|
|
192
|
+
enabledLocales,
|
|
193
|
+
forms,
|
|
194
|
+
isPreview = false
|
|
195
|
+
}) {
|
|
196
|
+
if (!page) return {};
|
|
197
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
198
|
+
const context = core.buildBlockContext(
|
|
199
|
+
locale,
|
|
200
|
+
defaultLocale,
|
|
201
|
+
enabledLocales,
|
|
202
|
+
isPreview,
|
|
203
|
+
forms
|
|
204
|
+
);
|
|
205
|
+
const resolved = await resolveBlocks(
|
|
206
|
+
page.blocks,
|
|
207
|
+
loaderMap,
|
|
208
|
+
locale,
|
|
209
|
+
defaultLocale,
|
|
210
|
+
context,
|
|
211
|
+
enabledLocales
|
|
212
|
+
);
|
|
213
|
+
const data = {};
|
|
214
|
+
page.blocks.forEach((block, index) => {
|
|
215
|
+
const value = resolved[index]?.data;
|
|
216
|
+
if (value !== void 0) data[block.id] = value;
|
|
217
|
+
});
|
|
218
|
+
return data;
|
|
219
|
+
}
|
|
220
|
+
async function resolveLayoutBlockData({
|
|
221
|
+
groups,
|
|
222
|
+
blocks,
|
|
223
|
+
position,
|
|
224
|
+
locale,
|
|
225
|
+
defaultLocale,
|
|
226
|
+
enabledLocales,
|
|
227
|
+
forms,
|
|
228
|
+
isPreview = false
|
|
229
|
+
}) {
|
|
230
|
+
const group = groups.find((g) => g.position === position);
|
|
231
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
232
|
+
if (layoutBlocks.length === 0) return {};
|
|
233
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
234
|
+
const context = core.buildBlockContext(
|
|
235
|
+
locale,
|
|
236
|
+
defaultLocale,
|
|
237
|
+
enabledLocales,
|
|
238
|
+
isPreview,
|
|
239
|
+
forms
|
|
240
|
+
);
|
|
241
|
+
const resolved = await resolveBlocks(
|
|
242
|
+
layoutBlocks,
|
|
243
|
+
loaderMap,
|
|
244
|
+
locale,
|
|
245
|
+
defaultLocale,
|
|
246
|
+
context,
|
|
247
|
+
enabledLocales
|
|
248
|
+
);
|
|
249
|
+
const data = {};
|
|
250
|
+
layoutBlocks.forEach((block, index) => {
|
|
251
|
+
const value = resolved[index]?.data;
|
|
252
|
+
if (value !== void 0) data[block.id] = value;
|
|
253
|
+
});
|
|
254
|
+
return data;
|
|
255
|
+
}
|
|
187
256
|
async function CmssyServerLayout({
|
|
188
257
|
groups,
|
|
189
258
|
blocks,
|
|
@@ -232,7 +301,8 @@ function CmssyBlock({
|
|
|
232
301
|
patchedAdvanced,
|
|
233
302
|
editable,
|
|
234
303
|
layoutPosition,
|
|
235
|
-
context
|
|
304
|
+
context,
|
|
305
|
+
data
|
|
236
306
|
}) {
|
|
237
307
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
238
308
|
const base = core.getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
@@ -251,7 +321,8 @@ function CmssyBlock({
|
|
|
251
321
|
content,
|
|
252
322
|
style,
|
|
253
323
|
advanced,
|
|
254
|
-
context
|
|
324
|
+
context,
|
|
325
|
+
data
|
|
255
326
|
}) : /* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type })
|
|
256
327
|
}
|
|
257
328
|
);
|
|
@@ -405,3 +476,5 @@ exports.blocksToMeta = blocksToMeta;
|
|
|
405
476
|
exports.blocksToSchemas = blocksToSchemas;
|
|
406
477
|
exports.buildBlockMap = buildBlockMap;
|
|
407
478
|
exports.defineBlock = defineBlock;
|
|
479
|
+
exports.resolveBlockData = resolveBlockData;
|
|
480
|
+
exports.resolveLayoutBlockData = resolveLayoutBlockData;
|
package/dist/index.d.cts
CHANGED
|
@@ -32,6 +32,28 @@ interface CmssyServerPageProps {
|
|
|
32
32
|
*/
|
|
33
33
|
declare function CmssyServerPage({ page, blocks, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, forms, auth, workspace, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
|
|
34
34
|
|
|
35
|
+
interface ResolveBlockDataOptions {
|
|
36
|
+
page: CmssyPageData | null;
|
|
37
|
+
blocks: BlockDefinition[];
|
|
38
|
+
locale: string;
|
|
39
|
+
defaultLocale: string;
|
|
40
|
+
enabledLocales?: string[];
|
|
41
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
42
|
+
isPreview?: boolean;
|
|
43
|
+
}
|
|
44
|
+
declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
|
|
45
|
+
interface ResolveLayoutBlockDataOptions {
|
|
46
|
+
groups: CmssyLayoutGroup[];
|
|
47
|
+
blocks: BlockDefinition[];
|
|
48
|
+
position: string;
|
|
49
|
+
locale: string;
|
|
50
|
+
defaultLocale: string;
|
|
51
|
+
enabledLocales?: string[];
|
|
52
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
53
|
+
isPreview?: boolean;
|
|
54
|
+
}
|
|
55
|
+
declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
|
|
56
|
+
|
|
35
57
|
interface CmssyServerLayoutProps {
|
|
36
58
|
groups: CmssyLayoutGroup[];
|
|
37
59
|
blocks: BlockDefinition[];
|
|
@@ -65,12 +87,13 @@ interface CmssyBlockProps {
|
|
|
65
87
|
editable?: boolean;
|
|
66
88
|
layoutPosition?: string;
|
|
67
89
|
context?: CmssyBlockContext;
|
|
90
|
+
data?: unknown;
|
|
68
91
|
}
|
|
69
|
-
declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
|
|
92
|
+
declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, layoutPosition, context, data, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
|
|
70
93
|
|
|
71
94
|
interface UnknownBlockProps {
|
|
72
95
|
type: string;
|
|
73
96
|
}
|
|
74
97
|
declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
|
|
75
98
|
|
|
76
|
-
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, UnknownBlock, type UnknownBlockProps };
|
|
99
|
+
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type ResolveBlockDataOptions, type ResolveLayoutBlockDataOptions, UnknownBlock, type UnknownBlockProps, resolveBlockData, resolveLayoutBlockData };
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,28 @@ interface CmssyServerPageProps {
|
|
|
32
32
|
*/
|
|
33
33
|
declare function CmssyServerPage({ page, blocks, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, forms, auth, workspace, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
|
|
34
34
|
|
|
35
|
+
interface ResolveBlockDataOptions {
|
|
36
|
+
page: CmssyPageData | null;
|
|
37
|
+
blocks: BlockDefinition[];
|
|
38
|
+
locale: string;
|
|
39
|
+
defaultLocale: string;
|
|
40
|
+
enabledLocales?: string[];
|
|
41
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
42
|
+
isPreview?: boolean;
|
|
43
|
+
}
|
|
44
|
+
declare function resolveBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
|
|
45
|
+
interface ResolveLayoutBlockDataOptions {
|
|
46
|
+
groups: CmssyLayoutGroup[];
|
|
47
|
+
blocks: BlockDefinition[];
|
|
48
|
+
position: string;
|
|
49
|
+
locale: string;
|
|
50
|
+
defaultLocale: string;
|
|
51
|
+
enabledLocales?: string[];
|
|
52
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
53
|
+
isPreview?: boolean;
|
|
54
|
+
}
|
|
55
|
+
declare function resolveLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, }: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
|
|
56
|
+
|
|
35
57
|
interface CmssyServerLayoutProps {
|
|
36
58
|
groups: CmssyLayoutGroup[];
|
|
37
59
|
blocks: BlockDefinition[];
|
|
@@ -65,12 +87,13 @@ interface CmssyBlockProps {
|
|
|
65
87
|
editable?: boolean;
|
|
66
88
|
layoutPosition?: string;
|
|
67
89
|
context?: CmssyBlockContext;
|
|
90
|
+
data?: unknown;
|
|
68
91
|
}
|
|
69
|
-
declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, layoutPosition, context, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
|
|
92
|
+
declare function CmssyBlock({ block, locale, defaultLocale, blockMap, patchedContent, patchedStyle, patchedAdvanced, editable, layoutPosition, context, data, }: CmssyBlockProps): react_jsx_runtime.JSX.Element;
|
|
70
93
|
|
|
71
94
|
interface UnknownBlockProps {
|
|
72
95
|
type: string;
|
|
73
96
|
}
|
|
74
97
|
declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
|
|
75
98
|
|
|
76
|
-
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, UnknownBlock, type UnknownBlockProps };
|
|
99
|
+
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type ResolveBlockDataOptions, type ResolveLayoutBlockDataOptions, UnknownBlock, type UnknownBlockProps, resolveBlockData, resolveLayoutBlockData };
|
package/dist/index.js
CHANGED
|
@@ -183,6 +183,75 @@ async function CmssyServerPage({
|
|
|
183
183
|
})
|
|
184
184
|
) });
|
|
185
185
|
}
|
|
186
|
+
async function resolveBlockData({
|
|
187
|
+
page,
|
|
188
|
+
blocks,
|
|
189
|
+
locale,
|
|
190
|
+
defaultLocale,
|
|
191
|
+
enabledLocales,
|
|
192
|
+
forms,
|
|
193
|
+
isPreview = false
|
|
194
|
+
}) {
|
|
195
|
+
if (!page) return {};
|
|
196
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
197
|
+
const context = buildBlockContext(
|
|
198
|
+
locale,
|
|
199
|
+
defaultLocale,
|
|
200
|
+
enabledLocales,
|
|
201
|
+
isPreview,
|
|
202
|
+
forms
|
|
203
|
+
);
|
|
204
|
+
const resolved = await resolveBlocks(
|
|
205
|
+
page.blocks,
|
|
206
|
+
loaderMap,
|
|
207
|
+
locale,
|
|
208
|
+
defaultLocale,
|
|
209
|
+
context,
|
|
210
|
+
enabledLocales
|
|
211
|
+
);
|
|
212
|
+
const data = {};
|
|
213
|
+
page.blocks.forEach((block, index) => {
|
|
214
|
+
const value = resolved[index]?.data;
|
|
215
|
+
if (value !== void 0) data[block.id] = value;
|
|
216
|
+
});
|
|
217
|
+
return data;
|
|
218
|
+
}
|
|
219
|
+
async function resolveLayoutBlockData({
|
|
220
|
+
groups,
|
|
221
|
+
blocks,
|
|
222
|
+
position,
|
|
223
|
+
locale,
|
|
224
|
+
defaultLocale,
|
|
225
|
+
enabledLocales,
|
|
226
|
+
forms,
|
|
227
|
+
isPreview = false
|
|
228
|
+
}) {
|
|
229
|
+
const group = groups.find((g) => g.position === position);
|
|
230
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
231
|
+
if (layoutBlocks.length === 0) return {};
|
|
232
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
233
|
+
const context = buildBlockContext(
|
|
234
|
+
locale,
|
|
235
|
+
defaultLocale,
|
|
236
|
+
enabledLocales,
|
|
237
|
+
isPreview,
|
|
238
|
+
forms
|
|
239
|
+
);
|
|
240
|
+
const resolved = await resolveBlocks(
|
|
241
|
+
layoutBlocks,
|
|
242
|
+
loaderMap,
|
|
243
|
+
locale,
|
|
244
|
+
defaultLocale,
|
|
245
|
+
context,
|
|
246
|
+
enabledLocales
|
|
247
|
+
);
|
|
248
|
+
const data = {};
|
|
249
|
+
layoutBlocks.forEach((block, index) => {
|
|
250
|
+
const value = resolved[index]?.data;
|
|
251
|
+
if (value !== void 0) data[block.id] = value;
|
|
252
|
+
});
|
|
253
|
+
return data;
|
|
254
|
+
}
|
|
186
255
|
async function CmssyServerLayout({
|
|
187
256
|
groups,
|
|
188
257
|
blocks,
|
|
@@ -231,7 +300,8 @@ function CmssyBlock({
|
|
|
231
300
|
patchedAdvanced,
|
|
232
301
|
editable,
|
|
233
302
|
layoutPosition,
|
|
234
|
-
context
|
|
303
|
+
context,
|
|
304
|
+
data
|
|
235
305
|
}) {
|
|
236
306
|
const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
|
|
237
307
|
const base = getBlockContentForLanguage(block.content, locale, defaultLocale);
|
|
@@ -250,10 +320,11 @@ function CmssyBlock({
|
|
|
250
320
|
content,
|
|
251
321
|
style,
|
|
252
322
|
advanced,
|
|
253
|
-
context
|
|
323
|
+
context,
|
|
324
|
+
data
|
|
254
325
|
}) : /* @__PURE__ */ jsx(UnknownBlock, { type: block.type })
|
|
255
326
|
}
|
|
256
327
|
);
|
|
257
328
|
}
|
|
258
329
|
|
|
259
|
-
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, blocksToMeta, blocksToSchemas, buildBlockMap, defineBlock };
|
|
330
|
+
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, blocksToMeta, blocksToSchemas, buildBlockMap, defineBlock, resolveBlockData, resolveLayoutBlockData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/react",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.3",
|
|
4
4
|
"description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@cmssy/types": "0.28.0",
|
|
60
|
-
"@cmssy/core": "8.0.
|
|
60
|
+
"@cmssy/core": "8.0.3"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "tsup",
|