@cmssy/react 13.0.1 → 14.1.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 +17 -9
- package/dist/client.d.cts +4 -2
- package/dist/client.d.ts +4 -2
- package/dist/client.js +17 -9
- package/dist/index.cjs +75 -15
- package/dist/index.d.cts +41 -8
- package/dist/index.d.ts +41 -8
- package/dist/index.js +75 -16
- package/dist/{registry-CwJ2cby4.d.cts → internal-server-CP0tEgpM.d.cts} +36 -2
- package/dist/{registry-CwJ2cby4.d.ts → internal-server-CP0tEgpM.d.ts} +36 -2
- package/dist/internal-server.cjs +10 -8
- package/dist/internal-server.d.cts +2 -37
- package/dist/internal-server.d.ts +2 -37
- package/dist/internal-server.js +10 -8
- package/package.json +3 -3
package/dist/client.cjs
CHANGED
|
@@ -13,17 +13,23 @@ function buildBlockMap(blocks) {
|
|
|
13
13
|
for (const block of blocks) map[block.type] = block.component;
|
|
14
14
|
return map;
|
|
15
15
|
}
|
|
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
|
+
}
|
|
16
23
|
function blocksToSchemas(blocks) {
|
|
17
24
|
const out = /* @__PURE__ */ Object.create(null);
|
|
18
|
-
for (const block of blocks)
|
|
19
|
-
const schema = {};
|
|
20
|
-
for (const [key, def] of Object.entries(block.props)) {
|
|
21
|
-
schema[key] = { ...def, label: def.label || key };
|
|
22
|
-
}
|
|
23
|
-
out[block.type] = schema;
|
|
24
|
-
}
|
|
25
|
+
for (const block of blocks) out[block.type] = propsToSchema(block.props);
|
|
25
26
|
return out;
|
|
26
27
|
}
|
|
28
|
+
function layoutRegionsToBridge(regions) {
|
|
29
|
+
return regions.map(
|
|
30
|
+
(region) => region.settings ? { ...region, settings: propsToSchema(region.settings) } : { ...region }
|
|
31
|
+
);
|
|
32
|
+
}
|
|
27
33
|
function blocksToMeta(blocks, defaults = {}) {
|
|
28
34
|
const out = /* @__PURE__ */ Object.create(null);
|
|
29
35
|
for (const block of blocks) {
|
|
@@ -316,7 +322,7 @@ function useEditBridge(page, config) {
|
|
|
316
322
|
schemas: config.schemas ?? /* @__PURE__ */ Object.create(null),
|
|
317
323
|
blockMeta: config.blockMeta ?? /* @__PURE__ */ Object.create(null),
|
|
318
324
|
capabilities: canDetectInvisibleBlocks() ? ["shortcuts", "invisible-blocks"] : ["shortcuts"],
|
|
319
|
-
...config.layoutRegions ? { layoutRegions:
|
|
325
|
+
...config.layoutRegions ? { layoutRegions: layoutRegionsToBridge(config.layoutRegions) } : {}
|
|
320
326
|
});
|
|
321
327
|
} catch (error) {
|
|
322
328
|
if (typeof console !== "undefined") {
|
|
@@ -1006,6 +1012,7 @@ function CmssyEditableLayout({
|
|
|
1006
1012
|
groups,
|
|
1007
1013
|
blocks,
|
|
1008
1014
|
position,
|
|
1015
|
+
page,
|
|
1009
1016
|
locale = "en",
|
|
1010
1017
|
defaultLocale = "en",
|
|
1011
1018
|
enabledLocales,
|
|
@@ -1026,9 +1033,10 @@ function CmssyEditableLayout({
|
|
|
1026
1033
|
const patches = useLayoutPatchBridge(position, edit);
|
|
1027
1034
|
const context = react.useMemo(
|
|
1028
1035
|
() => internal.buildBlockContext(locale, defaultLocale, enabledLocales, true, void 0, {
|
|
1036
|
+
page,
|
|
1029
1037
|
app: appContext
|
|
1030
1038
|
}),
|
|
1031
|
-
[locale, defaultLocale, enabledLocales, appContext]
|
|
1039
|
+
[locale, defaultLocale, enabledLocales, page, appContext]
|
|
1032
1040
|
);
|
|
1033
1041
|
if (layoutBlocks.length === 0) return null;
|
|
1034
1042
|
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 './
|
|
3
|
+
import { B as BlockDefinition, L as LayoutBlockPage } from './internal-server-CP0tEgpM.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 './
|
|
3
|
+
import { B as BlockDefinition, L as LayoutBlockPage } from './internal-server-CP0tEgpM.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
|
@@ -11,17 +11,23 @@ function buildBlockMap(blocks) {
|
|
|
11
11
|
for (const block of blocks) map[block.type] = block.component;
|
|
12
12
|
return map;
|
|
13
13
|
}
|
|
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
|
+
}
|
|
14
21
|
function blocksToSchemas(blocks) {
|
|
15
22
|
const out = /* @__PURE__ */ Object.create(null);
|
|
16
|
-
for (const block of blocks)
|
|
17
|
-
const schema = {};
|
|
18
|
-
for (const [key, def] of Object.entries(block.props)) {
|
|
19
|
-
schema[key] = { ...def, label: def.label || key };
|
|
20
|
-
}
|
|
21
|
-
out[block.type] = schema;
|
|
22
|
-
}
|
|
23
|
+
for (const block of blocks) out[block.type] = propsToSchema(block.props);
|
|
23
24
|
return out;
|
|
24
25
|
}
|
|
26
|
+
function layoutRegionsToBridge(regions) {
|
|
27
|
+
return regions.map(
|
|
28
|
+
(region) => region.settings ? { ...region, settings: propsToSchema(region.settings) } : { ...region }
|
|
29
|
+
);
|
|
30
|
+
}
|
|
25
31
|
function blocksToMeta(blocks, defaults = {}) {
|
|
26
32
|
const out = /* @__PURE__ */ Object.create(null);
|
|
27
33
|
for (const block of blocks) {
|
|
@@ -314,7 +320,7 @@ function useEditBridge(page, config) {
|
|
|
314
320
|
schemas: config.schemas ?? /* @__PURE__ */ Object.create(null),
|
|
315
321
|
blockMeta: config.blockMeta ?? /* @__PURE__ */ Object.create(null),
|
|
316
322
|
capabilities: canDetectInvisibleBlocks() ? ["shortcuts", "invisible-blocks"] : ["shortcuts"],
|
|
317
|
-
...config.layoutRegions ? { layoutRegions:
|
|
323
|
+
...config.layoutRegions ? { layoutRegions: layoutRegionsToBridge(config.layoutRegions) } : {}
|
|
318
324
|
});
|
|
319
325
|
} catch (error) {
|
|
320
326
|
if (typeof console !== "undefined") {
|
|
@@ -1004,6 +1010,7 @@ function CmssyEditableLayout({
|
|
|
1004
1010
|
groups,
|
|
1005
1011
|
blocks,
|
|
1006
1012
|
position,
|
|
1013
|
+
page,
|
|
1007
1014
|
locale = "en",
|
|
1008
1015
|
defaultLocale = "en",
|
|
1009
1016
|
enabledLocales,
|
|
@@ -1024,9 +1031,10 @@ function CmssyEditableLayout({
|
|
|
1024
1031
|
const patches = useLayoutPatchBridge(position, edit);
|
|
1025
1032
|
const context = useMemo(
|
|
1026
1033
|
() => buildBlockContext(locale, defaultLocale, enabledLocales, true, void 0, {
|
|
1034
|
+
page,
|
|
1027
1035
|
app: appContext
|
|
1028
1036
|
}),
|
|
1029
|
-
[locale, defaultLocale, enabledLocales, appContext]
|
|
1037
|
+
[locale, defaultLocale, enabledLocales, page, appContext]
|
|
1030
1038
|
);
|
|
1031
1039
|
if (layoutBlocks.length === 0) return null;
|
|
1032
1040
|
return /* @__PURE__ */ jsx(Fragment, { children: layoutBlocks.map((block) => /* @__PURE__ */ jsx(
|
package/dist/index.cjs
CHANGED
|
@@ -25,15 +25,16 @@ function buildLoaderMap(blocks) {
|
|
|
25
25
|
}
|
|
26
26
|
return map;
|
|
27
27
|
}
|
|
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
|
+
}
|
|
28
35
|
function blocksToSchemas(blocks) {
|
|
29
36
|
const out = /* @__PURE__ */ Object.create(null);
|
|
30
|
-
for (const block of blocks)
|
|
31
|
-
const schema = {};
|
|
32
|
-
for (const [key, def] of Object.entries(block.props)) {
|
|
33
|
-
schema[key] = { ...def, label: def.label || key };
|
|
34
|
-
}
|
|
35
|
-
out[block.type] = schema;
|
|
36
|
-
}
|
|
37
|
+
for (const block of blocks) out[block.type] = propsToSchema(block.props);
|
|
37
38
|
return out;
|
|
38
39
|
}
|
|
39
40
|
|
|
@@ -363,6 +364,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
363
364
|
groups,
|
|
364
365
|
blocks,
|
|
365
366
|
position,
|
|
367
|
+
page,
|
|
366
368
|
locale,
|
|
367
369
|
defaultLocale,
|
|
368
370
|
enabledLocales,
|
|
@@ -381,7 +383,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
381
383
|
enabledLocales,
|
|
382
384
|
isPreview,
|
|
383
385
|
forms,
|
|
384
|
-
{ app: appContext }
|
|
386
|
+
{ page, app: appContext }
|
|
385
387
|
);
|
|
386
388
|
const resolved = await resolveBlocks(
|
|
387
389
|
layoutBlocks,
|
|
@@ -394,12 +396,16 @@ async function resolveEditorLayoutBlockData({
|
|
|
394
396
|
);
|
|
395
397
|
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
396
398
|
}
|
|
399
|
+
function layoutSlotPage(slug) {
|
|
400
|
+
return { slug, path: slug.split("/").filter(Boolean) };
|
|
401
|
+
}
|
|
397
402
|
async function resolveCmssyLayoutSlot(config, options) {
|
|
398
403
|
const {
|
|
399
404
|
position,
|
|
400
405
|
blocks,
|
|
401
406
|
editMode,
|
|
402
|
-
|
|
407
|
+
preview = false,
|
|
408
|
+
page: explicitPage,
|
|
403
409
|
forms,
|
|
404
410
|
appContext,
|
|
405
411
|
path,
|
|
@@ -411,13 +417,15 @@ async function resolveCmssyLayoutSlot(config, options) {
|
|
|
411
417
|
const fromPath = path ? locale.splitLocaleFromPath(path, siteLocales) : { locale: siteLocales.defaultLocale, path: [] };
|
|
412
418
|
const locale$1 = explicitLocale ?? fromPath.locale;
|
|
413
419
|
const slugSegments = fromPath.path ?? [];
|
|
414
|
-
const
|
|
415
|
-
const groups = await internal.fetchLayouts(config,
|
|
416
|
-
previewSecret: editMode ? config.draftSecret : void 0,
|
|
420
|
+
const page = layoutSlotPage(explicitPage ?? "/" + slugSegments.join("/"));
|
|
421
|
+
const groups = await internal.fetchLayouts(config, page.slug, {
|
|
422
|
+
previewSecret: editMode || preview ? config.draftSecret : void 0,
|
|
417
423
|
...requestOptions
|
|
418
424
|
});
|
|
419
425
|
const base = {
|
|
420
426
|
groups,
|
|
427
|
+
settings: groups.find((g) => g.position === position)?.settings ?? null,
|
|
428
|
+
page,
|
|
421
429
|
locale: locale$1,
|
|
422
430
|
defaultLocale: siteLocales.defaultLocale,
|
|
423
431
|
enabledLocales: siteLocales.locales,
|
|
@@ -428,6 +436,7 @@ async function resolveCmssyLayoutSlot(config, options) {
|
|
|
428
436
|
groups,
|
|
429
437
|
blocks,
|
|
430
438
|
position,
|
|
439
|
+
page,
|
|
431
440
|
locale: locale$1,
|
|
432
441
|
defaultLocale: siteLocales.defaultLocale,
|
|
433
442
|
enabledLocales: siteLocales.locales,
|
|
@@ -447,12 +456,14 @@ async function CmssyServerLayout({
|
|
|
447
456
|
groups,
|
|
448
457
|
blocks,
|
|
449
458
|
position,
|
|
459
|
+
page,
|
|
450
460
|
locale: localeProp,
|
|
451
461
|
defaultLocale: defaultLocaleProp,
|
|
452
462
|
enabledLocales: enabledLocalesProp,
|
|
453
463
|
config,
|
|
454
464
|
appContext,
|
|
455
|
-
editMode
|
|
465
|
+
editMode,
|
|
466
|
+
preview = false
|
|
456
467
|
}) {
|
|
457
468
|
const { locale, defaultLocale, enabledLocales } = await resolveRenderLocale({
|
|
458
469
|
locale: localeProp,
|
|
@@ -469,9 +480,9 @@ async function CmssyServerLayout({
|
|
|
469
480
|
locale,
|
|
470
481
|
defaultLocale,
|
|
471
482
|
enabledLocales,
|
|
472
|
-
|
|
483
|
+
preview,
|
|
473
484
|
void 0,
|
|
474
|
-
{ app: appContext }
|
|
485
|
+
{ page, app: appContext }
|
|
475
486
|
);
|
|
476
487
|
const resolved = await resolveBlocks(
|
|
477
488
|
layoutBlocks,
|
|
@@ -493,6 +504,54 @@ async function CmssyServerLayout({
|
|
|
493
504
|
})
|
|
494
505
|
) });
|
|
495
506
|
}
|
|
507
|
+
async function resolveCmssyLayout(config, options) {
|
|
508
|
+
const { editable: Editable, ...slotOptions } = options;
|
|
509
|
+
if (slotOptions.editMode && !Editable) {
|
|
510
|
+
throw new Error(
|
|
511
|
+
"cmssy: resolveCmssyLayout needs an `editable` component in edit mode - the editor bridge lives on the client"
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
const resolved = await resolveCmssyLayoutSlot(
|
|
515
|
+
config,
|
|
516
|
+
slotOptions
|
|
517
|
+
);
|
|
518
|
+
const { groups, settings, page, locale, defaultLocale, enabledLocales } = resolved;
|
|
519
|
+
const shared = {
|
|
520
|
+
groups,
|
|
521
|
+
position: options.position,
|
|
522
|
+
page,
|
|
523
|
+
locale,
|
|
524
|
+
defaultLocale,
|
|
525
|
+
enabledLocales,
|
|
526
|
+
appContext: options.appContext
|
|
527
|
+
};
|
|
528
|
+
const element = slotOptions.editMode && Editable ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
529
|
+
Editable,
|
|
530
|
+
{
|
|
531
|
+
...shared,
|
|
532
|
+
edit: { editorOrigin: resolved.editorOrigin ?? "" },
|
|
533
|
+
data: resolved.data,
|
|
534
|
+
resolvedContent: resolved.resolvedContent
|
|
535
|
+
}
|
|
536
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
537
|
+
CmssyServerLayout,
|
|
538
|
+
{
|
|
539
|
+
...shared,
|
|
540
|
+
blocks: options.blocks,
|
|
541
|
+
config,
|
|
542
|
+
preview: slotOptions.preview
|
|
543
|
+
}
|
|
544
|
+
);
|
|
545
|
+
return {
|
|
546
|
+
groups,
|
|
547
|
+
settings,
|
|
548
|
+
page,
|
|
549
|
+
locale,
|
|
550
|
+
defaultLocale,
|
|
551
|
+
enabledLocales,
|
|
552
|
+
element
|
|
553
|
+
};
|
|
554
|
+
}
|
|
496
555
|
function CmssyBlock({
|
|
497
556
|
block,
|
|
498
557
|
locale,
|
|
@@ -634,6 +693,7 @@ exports.CmssyServerPage = CmssyServerPage;
|
|
|
634
693
|
exports.UnknownBlock = UnknownBlock;
|
|
635
694
|
exports.buildBlockMap = buildBlockMap;
|
|
636
695
|
exports.defineBlock = defineBlock;
|
|
696
|
+
exports.resolveCmssyLayout = resolveCmssyLayout;
|
|
637
697
|
exports.resolveCmssyLayoutSlot = resolveCmssyLayoutSlot;
|
|
638
698
|
exports.resolveEditorBlockData = resolveEditorBlockData;
|
|
639
699
|
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,
|
|
3
|
-
import { B as BlockDefinition, a as BlockMap } from './
|
|
4
|
-
export { b as BlockProps, c as
|
|
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-CP0tEgpM.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-CP0tEgpM.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
|
-
|
|
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,
|
|
3
|
-
import { B as BlockDefinition, a as BlockMap } from './
|
|
4
|
-
export { b as BlockProps, c as
|
|
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-CP0tEgpM.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-CP0tEgpM.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
|
-
|
|
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
|
@@ -25,15 +25,16 @@ function buildLoaderMap(blocks) {
|
|
|
25
25
|
}
|
|
26
26
|
return map;
|
|
27
27
|
}
|
|
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
|
+
}
|
|
28
35
|
function blocksToSchemas(blocks) {
|
|
29
36
|
const out = /* @__PURE__ */ Object.create(null);
|
|
30
|
-
for (const block of blocks)
|
|
31
|
-
const schema = {};
|
|
32
|
-
for (const [key, def] of Object.entries(block.props)) {
|
|
33
|
-
schema[key] = { ...def, label: def.label || key };
|
|
34
|
-
}
|
|
35
|
-
out[block.type] = schema;
|
|
36
|
-
}
|
|
37
|
+
for (const block of blocks) out[block.type] = propsToSchema(block.props);
|
|
37
38
|
return out;
|
|
38
39
|
}
|
|
39
40
|
|
|
@@ -363,6 +364,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
363
364
|
groups,
|
|
364
365
|
blocks,
|
|
365
366
|
position,
|
|
367
|
+
page,
|
|
366
368
|
locale,
|
|
367
369
|
defaultLocale,
|
|
368
370
|
enabledLocales,
|
|
@@ -381,7 +383,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
381
383
|
enabledLocales,
|
|
382
384
|
isPreview,
|
|
383
385
|
forms,
|
|
384
|
-
{ app: appContext }
|
|
386
|
+
{ page, app: appContext }
|
|
385
387
|
);
|
|
386
388
|
const resolved = await resolveBlocks(
|
|
387
389
|
layoutBlocks,
|
|
@@ -394,12 +396,16 @@ async function resolveEditorLayoutBlockData({
|
|
|
394
396
|
);
|
|
395
397
|
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
396
398
|
}
|
|
399
|
+
function layoutSlotPage(slug) {
|
|
400
|
+
return { slug, path: slug.split("/").filter(Boolean) };
|
|
401
|
+
}
|
|
397
402
|
async function resolveCmssyLayoutSlot(config, options) {
|
|
398
403
|
const {
|
|
399
404
|
position,
|
|
400
405
|
blocks,
|
|
401
406
|
editMode,
|
|
402
|
-
|
|
407
|
+
preview = false,
|
|
408
|
+
page: explicitPage,
|
|
403
409
|
forms,
|
|
404
410
|
appContext,
|
|
405
411
|
path,
|
|
@@ -411,13 +417,15 @@ async function resolveCmssyLayoutSlot(config, options) {
|
|
|
411
417
|
const fromPath = path ? splitLocaleFromPath(path, siteLocales) : { locale: siteLocales.defaultLocale, path: [] };
|
|
412
418
|
const locale = explicitLocale ?? fromPath.locale;
|
|
413
419
|
const slugSegments = fromPath.path ?? [];
|
|
414
|
-
const
|
|
415
|
-
const groups = await fetchLayouts(config,
|
|
416
|
-
previewSecret: editMode ? config.draftSecret : void 0,
|
|
420
|
+
const page = layoutSlotPage(explicitPage ?? "/" + slugSegments.join("/"));
|
|
421
|
+
const groups = await fetchLayouts(config, page.slug, {
|
|
422
|
+
previewSecret: editMode || preview ? config.draftSecret : void 0,
|
|
417
423
|
...requestOptions
|
|
418
424
|
});
|
|
419
425
|
const base = {
|
|
420
426
|
groups,
|
|
427
|
+
settings: groups.find((g) => g.position === position)?.settings ?? null,
|
|
428
|
+
page,
|
|
421
429
|
locale,
|
|
422
430
|
defaultLocale: siteLocales.defaultLocale,
|
|
423
431
|
enabledLocales: siteLocales.locales,
|
|
@@ -428,6 +436,7 @@ async function resolveCmssyLayoutSlot(config, options) {
|
|
|
428
436
|
groups,
|
|
429
437
|
blocks,
|
|
430
438
|
position,
|
|
439
|
+
page,
|
|
431
440
|
locale,
|
|
432
441
|
defaultLocale: siteLocales.defaultLocale,
|
|
433
442
|
enabledLocales: siteLocales.locales,
|
|
@@ -447,12 +456,14 @@ async function CmssyServerLayout({
|
|
|
447
456
|
groups,
|
|
448
457
|
blocks,
|
|
449
458
|
position,
|
|
459
|
+
page,
|
|
450
460
|
locale: localeProp,
|
|
451
461
|
defaultLocale: defaultLocaleProp,
|
|
452
462
|
enabledLocales: enabledLocalesProp,
|
|
453
463
|
config,
|
|
454
464
|
appContext,
|
|
455
|
-
editMode
|
|
465
|
+
editMode,
|
|
466
|
+
preview = false
|
|
456
467
|
}) {
|
|
457
468
|
const { locale, defaultLocale, enabledLocales } = await resolveRenderLocale({
|
|
458
469
|
locale: localeProp,
|
|
@@ -469,9 +480,9 @@ async function CmssyServerLayout({
|
|
|
469
480
|
locale,
|
|
470
481
|
defaultLocale,
|
|
471
482
|
enabledLocales,
|
|
472
|
-
|
|
483
|
+
preview,
|
|
473
484
|
void 0,
|
|
474
|
-
{ app: appContext }
|
|
485
|
+
{ page, app: appContext }
|
|
475
486
|
);
|
|
476
487
|
const resolved = await resolveBlocks(
|
|
477
488
|
layoutBlocks,
|
|
@@ -493,6 +504,54 @@ async function CmssyServerLayout({
|
|
|
493
504
|
})
|
|
494
505
|
) });
|
|
495
506
|
}
|
|
507
|
+
async function resolveCmssyLayout(config, options) {
|
|
508
|
+
const { editable: Editable, ...slotOptions } = options;
|
|
509
|
+
if (slotOptions.editMode && !Editable) {
|
|
510
|
+
throw new Error(
|
|
511
|
+
"cmssy: resolveCmssyLayout needs an `editable` component in edit mode - the editor bridge lives on the client"
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
const resolved = await resolveCmssyLayoutSlot(
|
|
515
|
+
config,
|
|
516
|
+
slotOptions
|
|
517
|
+
);
|
|
518
|
+
const { groups, settings, page, locale, defaultLocale, enabledLocales } = resolved;
|
|
519
|
+
const shared = {
|
|
520
|
+
groups,
|
|
521
|
+
position: options.position,
|
|
522
|
+
page,
|
|
523
|
+
locale,
|
|
524
|
+
defaultLocale,
|
|
525
|
+
enabledLocales,
|
|
526
|
+
appContext: options.appContext
|
|
527
|
+
};
|
|
528
|
+
const element = slotOptions.editMode && Editable ? /* @__PURE__ */ jsx(
|
|
529
|
+
Editable,
|
|
530
|
+
{
|
|
531
|
+
...shared,
|
|
532
|
+
edit: { editorOrigin: resolved.editorOrigin ?? "" },
|
|
533
|
+
data: resolved.data,
|
|
534
|
+
resolvedContent: resolved.resolvedContent
|
|
535
|
+
}
|
|
536
|
+
) : /* @__PURE__ */ jsx(
|
|
537
|
+
CmssyServerLayout,
|
|
538
|
+
{
|
|
539
|
+
...shared,
|
|
540
|
+
blocks: options.blocks,
|
|
541
|
+
config,
|
|
542
|
+
preview: slotOptions.preview
|
|
543
|
+
}
|
|
544
|
+
);
|
|
545
|
+
return {
|
|
546
|
+
groups,
|
|
547
|
+
settings,
|
|
548
|
+
page,
|
|
549
|
+
locale,
|
|
550
|
+
defaultLocale,
|
|
551
|
+
enabledLocales,
|
|
552
|
+
element
|
|
553
|
+
};
|
|
554
|
+
}
|
|
496
555
|
function CmssyBlock({
|
|
497
556
|
block,
|
|
498
557
|
locale,
|
|
@@ -572,4 +631,4 @@ function CmssyBlock({
|
|
|
572
631
|
);
|
|
573
632
|
}
|
|
574
633
|
|
|
575
|
-
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock, resolveCmssyLayoutSlot, resolveEditorBlockData, resolveEditorLayoutBlockData };
|
|
634
|
+
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock, resolveCmssyLayout, resolveCmssyLayoutSlot, resolveEditorBlockData, resolveEditorLayoutBlockData };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent, BlockSchema, 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>;
|
|
@@ -67,4 +67,38 @@ type BlockMap = Record<string, ComponentType<{
|
|
|
67
67
|
declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
|
|
68
68
|
declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
type LayoutBlockPage = NonNullable<BuildBlockContextExtra["page"]>;
|
|
71
|
+
interface EditorBlockData {
|
|
72
|
+
data: Record<string, unknown>;
|
|
73
|
+
content: Record<string, Record<string, unknown>>;
|
|
74
|
+
}
|
|
75
|
+
interface ResolveBlockDataOptions {
|
|
76
|
+
page: CmssyPageData | null;
|
|
77
|
+
blocks: BlockDefinition[];
|
|
78
|
+
locale: string;
|
|
79
|
+
defaultLocale: string;
|
|
80
|
+
enabledLocales?: string[];
|
|
81
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
82
|
+
isPreview?: boolean;
|
|
83
|
+
config?: CmssyClientConfig;
|
|
84
|
+
appContext?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
|
|
87
|
+
declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
|
|
88
|
+
interface ResolveLayoutBlockDataOptions {
|
|
89
|
+
groups: CmssyLayoutGroup[];
|
|
90
|
+
blocks: BlockDefinition[];
|
|
91
|
+
position: string;
|
|
92
|
+
page?: LayoutBlockPage;
|
|
93
|
+
locale: string;
|
|
94
|
+
defaultLocale: string;
|
|
95
|
+
enabledLocales?: string[];
|
|
96
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
97
|
+
isPreview?: boolean;
|
|
98
|
+
config?: CmssyClientConfig;
|
|
99
|
+
appContext?: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
declare function resolveEditorLayoutBlockData({ groups, blocks, position, page, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
|
|
102
|
+
declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
|
|
103
|
+
|
|
104
|
+
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, blocksToSchemas as g, resolveBlockData as h, resolveLayoutBlockData as i, resolveEditorBlockData as r };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent, BlockSchema, 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>;
|
|
@@ -67,4 +67,38 @@ type BlockMap = Record<string, ComponentType<{
|
|
|
67
67
|
declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
|
|
68
68
|
declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
type LayoutBlockPage = NonNullable<BuildBlockContextExtra["page"]>;
|
|
71
|
+
interface EditorBlockData {
|
|
72
|
+
data: Record<string, unknown>;
|
|
73
|
+
content: Record<string, Record<string, unknown>>;
|
|
74
|
+
}
|
|
75
|
+
interface ResolveBlockDataOptions {
|
|
76
|
+
page: CmssyPageData | null;
|
|
77
|
+
blocks: BlockDefinition[];
|
|
78
|
+
locale: string;
|
|
79
|
+
defaultLocale: string;
|
|
80
|
+
enabledLocales?: string[];
|
|
81
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
82
|
+
isPreview?: boolean;
|
|
83
|
+
config?: CmssyClientConfig;
|
|
84
|
+
appContext?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
|
|
87
|
+
declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
|
|
88
|
+
interface ResolveLayoutBlockDataOptions {
|
|
89
|
+
groups: CmssyLayoutGroup[];
|
|
90
|
+
blocks: BlockDefinition[];
|
|
91
|
+
position: string;
|
|
92
|
+
page?: LayoutBlockPage;
|
|
93
|
+
locale: string;
|
|
94
|
+
defaultLocale: string;
|
|
95
|
+
enabledLocales?: string[];
|
|
96
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
97
|
+
isPreview?: boolean;
|
|
98
|
+
config?: CmssyClientConfig;
|
|
99
|
+
appContext?: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
declare function resolveEditorLayoutBlockData({ groups, blocks, position, page, locale, defaultLocale, enabledLocales, forms, isPreview, config, appContext, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
|
|
102
|
+
declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
|
|
103
|
+
|
|
104
|
+
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, blocksToSchemas as g, resolveBlockData as h, resolveLayoutBlockData as i, resolveEditorBlockData as r };
|
package/dist/internal-server.cjs
CHANGED
|
@@ -12,15 +12,16 @@ function buildLoaderMap(blocks) {
|
|
|
12
12
|
}
|
|
13
13
|
return map;
|
|
14
14
|
}
|
|
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
|
+
}
|
|
15
22
|
function blocksToSchemas(blocks) {
|
|
16
23
|
const out = /* @__PURE__ */ Object.create(null);
|
|
17
|
-
for (const block of blocks)
|
|
18
|
-
const schema = {};
|
|
19
|
-
for (const [key, def] of Object.entries(block.props)) {
|
|
20
|
-
schema[key] = { ...def, label: def.label || key };
|
|
21
|
-
}
|
|
22
|
-
out[block.type] = schema;
|
|
23
|
-
}
|
|
24
|
+
for (const block of blocks) out[block.type] = propsToSchema(block.props);
|
|
24
25
|
return out;
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -136,6 +137,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
136
137
|
groups,
|
|
137
138
|
blocks,
|
|
138
139
|
position,
|
|
140
|
+
page,
|
|
139
141
|
locale,
|
|
140
142
|
defaultLocale,
|
|
141
143
|
enabledLocales,
|
|
@@ -154,7 +156,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
154
156
|
enabledLocales,
|
|
155
157
|
isPreview,
|
|
156
158
|
forms,
|
|
157
|
-
{ app: appContext }
|
|
159
|
+
{ page, app: appContext }
|
|
158
160
|
);
|
|
159
161
|
const resolved = await resolveBlocks(
|
|
160
162
|
layoutBlocks,
|
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
export { e as blocksToSchemas } from './registry-CwJ2cby4.cjs';
|
|
1
|
+
export { E as EditorBlockData, R as ResolveBlockDataOptions, c as ResolveLayoutBlockDataOptions, g as blocksToSchemas, h as resolveBlockData, r as resolveEditorBlockData, f as resolveEditorLayoutBlockData, i as resolveLayoutBlockData } from './internal-server-CP0tEgpM.cjs';
|
|
2
|
+
import '@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
|
-
|
|
2
|
-
import
|
|
3
|
-
export { e as blocksToSchemas } from './registry-CwJ2cby4.js';
|
|
1
|
+
export { E as EditorBlockData, R as ResolveBlockDataOptions, c as ResolveLayoutBlockDataOptions, g as blocksToSchemas, h as resolveBlockData, r as resolveEditorBlockData, f as resolveEditorLayoutBlockData, i as resolveLayoutBlockData } from './internal-server-CP0tEgpM.js';
|
|
2
|
+
import '@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 };
|
package/dist/internal-server.js
CHANGED
|
@@ -10,15 +10,16 @@ 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
|
+
}
|
|
13
20
|
function blocksToSchemas(blocks) {
|
|
14
21
|
const out = /* @__PURE__ */ Object.create(null);
|
|
15
|
-
for (const block of blocks)
|
|
16
|
-
const schema = {};
|
|
17
|
-
for (const [key, def] of Object.entries(block.props)) {
|
|
18
|
-
schema[key] = { ...def, label: def.label || key };
|
|
19
|
-
}
|
|
20
|
-
out[block.type] = schema;
|
|
21
|
-
}
|
|
22
|
+
for (const block of blocks) out[block.type] = propsToSchema(block.props);
|
|
22
23
|
return out;
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -134,6 +135,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
134
135
|
groups,
|
|
135
136
|
blocks,
|
|
136
137
|
position,
|
|
138
|
+
page,
|
|
137
139
|
locale,
|
|
138
140
|
defaultLocale,
|
|
139
141
|
enabledLocales,
|
|
@@ -152,7 +154,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
152
154
|
enabledLocales,
|
|
153
155
|
isPreview,
|
|
154
156
|
forms,
|
|
155
|
-
{ app: appContext }
|
|
157
|
+
{ page, app: appContext }
|
|
156
158
|
);
|
|
157
159
|
const resolved = await resolveBlocks(
|
|
158
160
|
layoutBlocks,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.1.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.
|
|
100
|
-
"@cmssy/core": "
|
|
99
|
+
"@cmssy/types": "0.39.0",
|
|
100
|
+
"@cmssy/core": "14.1.0"
|
|
101
101
|
},
|
|
102
102
|
"scripts": {
|
|
103
103
|
"build": "tsup",
|