@cmssy/react 11.0.0 → 11.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 +1 -1
- package/dist/client.js +1 -1
- package/dist/index.cjs +50 -2
- package/dist/index.d.cts +79 -2
- package/dist/index.d.ts +79 -2
- package/dist/index.js +53 -5
- package/dist/internal-server.cjs +1 -1
- package/dist/internal-server.js +1 -1
- package/package.json +2 -2
package/dist/client.cjs
CHANGED
|
@@ -817,7 +817,7 @@ function CmssyEditableLayout({
|
|
|
817
817
|
);
|
|
818
818
|
const layoutBlocks = react.useMemo(() => {
|
|
819
819
|
const group = groups.find((g) => g.position === position);
|
|
820
|
-
return group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
820
|
+
return group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
|
|
821
821
|
}, [groups, position]);
|
|
822
822
|
const patches = useLayoutPatchBridge(position, edit);
|
|
823
823
|
const context = react.useMemo(
|
package/dist/client.js
CHANGED
|
@@ -815,7 +815,7 @@ function CmssyEditableLayout({
|
|
|
815
815
|
);
|
|
816
816
|
const layoutBlocks = useMemo(() => {
|
|
817
817
|
const group = groups.find((g) => g.position === position);
|
|
818
|
-
return group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
818
|
+
return group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
|
|
819
819
|
}, [groups, position]);
|
|
820
820
|
const patches = useLayoutPatchBridge(position, edit);
|
|
821
821
|
const context = useMemo(
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var internal = require('@cmssy/core/internal');
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var blockErrorBoundary = require('@cmssy/react/block-error-boundary');
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var locale = require('@cmssy/core/internal/locale');
|
|
8
9
|
|
|
9
10
|
// src/index.ts
|
|
10
11
|
|
|
@@ -364,7 +365,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
364
365
|
appContext
|
|
365
366
|
}) {
|
|
366
367
|
const group = groups.find((g) => g.position === position);
|
|
367
|
-
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
368
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
|
|
368
369
|
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
369
370
|
const loaderMap = buildLoaderMap(blocks);
|
|
370
371
|
const context = internal.buildBlockContext(
|
|
@@ -386,6 +387,52 @@ async function resolveEditorLayoutBlockData({
|
|
|
386
387
|
);
|
|
387
388
|
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
388
389
|
}
|
|
390
|
+
async function resolveCmssyLayoutSlot(config, options) {
|
|
391
|
+
const {
|
|
392
|
+
position,
|
|
393
|
+
blocks,
|
|
394
|
+
editMode,
|
|
395
|
+
page,
|
|
396
|
+
forms,
|
|
397
|
+
appContext,
|
|
398
|
+
path,
|
|
399
|
+
locale: explicitLocale
|
|
400
|
+
} = options;
|
|
401
|
+
const siteLocales = await locale.resolveSiteLocales(config);
|
|
402
|
+
const fromPath = path ? locale.splitLocaleFromPath(path, siteLocales) : { locale: siteLocales.defaultLocale, path: [] };
|
|
403
|
+
const locale$1 = explicitLocale ?? fromPath.locale;
|
|
404
|
+
const slugSegments = fromPath.path ?? [];
|
|
405
|
+
const pageSlug = page ?? "/" + slugSegments.join("/");
|
|
406
|
+
const groups = await internal.fetchLayouts(config, pageSlug, {
|
|
407
|
+
previewSecret: editMode ? config.draftSecret : void 0
|
|
408
|
+
});
|
|
409
|
+
const base = {
|
|
410
|
+
groups,
|
|
411
|
+
locale: locale$1,
|
|
412
|
+
defaultLocale: siteLocales.defaultLocale,
|
|
413
|
+
enabledLocales: siteLocales.locales,
|
|
414
|
+
path: slugSegments
|
|
415
|
+
};
|
|
416
|
+
if (!editMode) return base;
|
|
417
|
+
const editorData = await resolveEditorLayoutBlockData({
|
|
418
|
+
groups,
|
|
419
|
+
blocks,
|
|
420
|
+
position,
|
|
421
|
+
locale: locale$1,
|
|
422
|
+
defaultLocale: siteLocales.defaultLocale,
|
|
423
|
+
enabledLocales: siteLocales.locales,
|
|
424
|
+
forms,
|
|
425
|
+
isPreview: true,
|
|
426
|
+
config,
|
|
427
|
+
appContext
|
|
428
|
+
});
|
|
429
|
+
return {
|
|
430
|
+
...base,
|
|
431
|
+
data: editorData.data,
|
|
432
|
+
resolvedContent: editorData.content,
|
|
433
|
+
editorOrigin: core.resolveEditorOrigin(config.editorOrigin)
|
|
434
|
+
};
|
|
435
|
+
}
|
|
389
436
|
async function CmssyServerLayout({
|
|
390
437
|
groups,
|
|
391
438
|
blocks,
|
|
@@ -404,7 +451,7 @@ async function CmssyServerLayout({
|
|
|
404
451
|
config
|
|
405
452
|
});
|
|
406
453
|
const group = groups.find((g) => g.position === position);
|
|
407
|
-
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
454
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
|
|
408
455
|
if (layoutBlocks.length === 0) return null;
|
|
409
456
|
const map = buildBlockMap(blocks);
|
|
410
457
|
const loaderMap = buildLoaderMap(blocks);
|
|
@@ -565,5 +612,6 @@ exports.CmssyServerPage = CmssyServerPage;
|
|
|
565
612
|
exports.UnknownBlock = UnknownBlock;
|
|
566
613
|
exports.buildBlockMap = buildBlockMap;
|
|
567
614
|
exports.defineBlock = defineBlock;
|
|
615
|
+
exports.resolveCmssyLayoutSlot = resolveCmssyLayoutSlot;
|
|
568
616
|
exports.resolveEditorBlockData = resolveEditorBlockData;
|
|
569
617
|
exports.resolveEditorLayoutBlockData = resolveEditorLayoutBlockData;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, RawBlock, CmssyBlockContext } from '@cmssy/core';
|
|
1
|
+
import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, CmssyConfig, RawBlock, CmssyBlockContext } from '@cmssy/core';
|
|
2
2
|
export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRequestError, CmssySiteConfig, CmssyTypedDocument, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, LayoutPosition, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryPolicy, SelectMessage, SubmitFormInput, TypedField, createCmssyClient, fields, graphqlRequest, isProtocolCompatible, layoutPositionValues, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
|
|
3
3
|
import { B as BlockDefinition, a as BlockMap } from './registry-zeNh3t6y.cjs';
|
|
4
4
|
export { b as BlockProps, c as buildBlockMap, d as defineBlock } from './registry-zeNh3t6y.cjs';
|
|
@@ -42,6 +42,83 @@ interface CmssyServerPageProps {
|
|
|
42
42
|
*/
|
|
43
43
|
declare function CmssyServerPage({ page, blocks, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, forms, auth, workspace, appContext, editMode, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
|
|
44
44
|
|
|
45
|
+
interface ResolveCmssyLayoutSlotBase {
|
|
46
|
+
position: string;
|
|
47
|
+
blocks: BlockDefinition[];
|
|
48
|
+
/**
|
|
49
|
+
* Whether to resolve for the edit bridge. A parameter, never a lookup: every
|
|
50
|
+
* way of asking the request is a dynamic API on Next, and one read makes the
|
|
51
|
+
* route uncacheable. Each adapter knows the answer already - from its own
|
|
52
|
+
* request object, or from the route segment.
|
|
53
|
+
*/
|
|
54
|
+
editMode: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whose layouts to render. Defaults to the routed page, which is what a page
|
|
57
|
+
* with its own header needs; pass `"/"` for the site-wide chrome.
|
|
58
|
+
*/
|
|
59
|
+
page?: string;
|
|
60
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
61
|
+
appContext?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Where the language comes from - one of two, never neither.
|
|
65
|
+
*
|
|
66
|
+
* `path` is the routed segments: the language prefix in them IS the language,
|
|
67
|
+
* and it is also where the page slug comes from. `locale` overrides the
|
|
68
|
+
* language without touching the slug, which is what an always-dynamic adapter
|
|
69
|
+
* wants when the proxy already resolved it into a header.
|
|
70
|
+
*
|
|
71
|
+
* What this deliberately does NOT do is read that header itself. On a cacheable
|
|
72
|
+
* route it is not there to read, and a fallback would render the wrong language
|
|
73
|
+
* while looking like it worked.
|
|
74
|
+
*/
|
|
75
|
+
type CmssyLayoutSlotLocaleSource = {
|
|
76
|
+
path: string[];
|
|
77
|
+
locale?: string;
|
|
78
|
+
} | {
|
|
79
|
+
locale: string;
|
|
80
|
+
path?: undefined;
|
|
81
|
+
};
|
|
82
|
+
type ResolveCmssyLayoutSlotOptions = ResolveCmssyLayoutSlotBase & CmssyLayoutSlotLocaleSource;
|
|
83
|
+
interface CmssyLayoutSlotResolution {
|
|
84
|
+
groups: CmssyLayoutGroup[];
|
|
85
|
+
locale: string;
|
|
86
|
+
defaultLocale: string;
|
|
87
|
+
enabledLocales: string[];
|
|
88
|
+
/**
|
|
89
|
+
* The routed segments with the language prefix removed - the page slug. It is
|
|
90
|
+
* returned because every caller needs it next, and resolving it twice is how
|
|
91
|
+
* the three adapters drifted apart in the first place.
|
|
92
|
+
*/
|
|
93
|
+
path: string[];
|
|
94
|
+
/** Edit mode only: the loader data and the server-resolved content. */
|
|
95
|
+
data?: Record<string, unknown>;
|
|
96
|
+
resolvedContent?: Record<string, Record<string, unknown>>;
|
|
97
|
+
/**
|
|
98
|
+
* Edit mode only, and unchanged: `string | string[]`. The bridge handles a
|
|
99
|
+
* list natively and the default is two origins - collapsing it to the first
|
|
100
|
+
* silently breaks an editor served from the second.
|
|
101
|
+
*/
|
|
102
|
+
editorOrigin?: string | string[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Everything a layout slot needs, for any framework.
|
|
106
|
+
*
|
|
107
|
+
* Three things have to be right here, and each was got wrong at least once by
|
|
108
|
+
* an app that wrote this by hand:
|
|
109
|
+
*
|
|
110
|
+
* 1. in edit mode the layouts are fetched **with the preview secret** -
|
|
111
|
+
* otherwise you edit the draft header and the editor shows the published
|
|
112
|
+
* one;
|
|
113
|
+
* 2. the language comes from the routed path, not from a request header;
|
|
114
|
+
* 3. the editor gets `resolvedContent` as well as `data` - the canvas renders
|
|
115
|
+
* stored content, where a relation field is raw ids.
|
|
116
|
+
*
|
|
117
|
+
* Rendering stays with the caller: three frameworks, three rendering models.
|
|
118
|
+
* This is the half that is the same in all of them.
|
|
119
|
+
*/
|
|
120
|
+
declare function resolveCmssyLayoutSlot(config: CmssyConfig, options: ResolveCmssyLayoutSlotOptions): Promise<CmssyLayoutSlotResolution>;
|
|
121
|
+
|
|
45
122
|
interface CmssyServerLayoutProps {
|
|
46
123
|
groups: CmssyLayoutGroup[];
|
|
47
124
|
blocks: BlockDefinition[];
|
|
@@ -96,4 +173,4 @@ interface UnknownBlockProps {
|
|
|
96
173
|
}
|
|
97
174
|
declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
|
|
98
175
|
|
|
99
|
-
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, UnknownBlock, type UnknownBlockProps };
|
|
176
|
+
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyLayoutSlotLocaleSource, type CmssyLayoutSlotResolution, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type ResolveCmssyLayoutSlotOptions, UnknownBlock, type UnknownBlockProps, resolveCmssyLayoutSlot };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, RawBlock, CmssyBlockContext } from '@cmssy/core';
|
|
1
|
+
import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, CmssyConfig, RawBlock, CmssyBlockContext } from '@cmssy/core';
|
|
2
2
|
export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockPage, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRequestError, CmssySiteConfig, CmssyTypedDocument, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, LayoutPosition, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryPolicy, SelectMessage, SubmitFormInput, TypedField, createCmssyClient, fields, graphqlRequest, isProtocolCompatible, layoutPositionValues, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
|
|
3
3
|
import { B as BlockDefinition, a as BlockMap } from './registry-zeNh3t6y.js';
|
|
4
4
|
export { b as BlockProps, c as buildBlockMap, d as defineBlock } from './registry-zeNh3t6y.js';
|
|
@@ -42,6 +42,83 @@ interface CmssyServerPageProps {
|
|
|
42
42
|
*/
|
|
43
43
|
declare function CmssyServerPage({ page, blocks, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, forms, auth, workspace, appContext, editMode, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
|
|
44
44
|
|
|
45
|
+
interface ResolveCmssyLayoutSlotBase {
|
|
46
|
+
position: string;
|
|
47
|
+
blocks: BlockDefinition[];
|
|
48
|
+
/**
|
|
49
|
+
* Whether to resolve for the edit bridge. A parameter, never a lookup: every
|
|
50
|
+
* way of asking the request is a dynamic API on Next, and one read makes the
|
|
51
|
+
* route uncacheable. Each adapter knows the answer already - from its own
|
|
52
|
+
* request object, or from the route segment.
|
|
53
|
+
*/
|
|
54
|
+
editMode: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whose layouts to render. Defaults to the routed page, which is what a page
|
|
57
|
+
* with its own header needs; pass `"/"` for the site-wide chrome.
|
|
58
|
+
*/
|
|
59
|
+
page?: string;
|
|
60
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
61
|
+
appContext?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Where the language comes from - one of two, never neither.
|
|
65
|
+
*
|
|
66
|
+
* `path` is the routed segments: the language prefix in them IS the language,
|
|
67
|
+
* and it is also where the page slug comes from. `locale` overrides the
|
|
68
|
+
* language without touching the slug, which is what an always-dynamic adapter
|
|
69
|
+
* wants when the proxy already resolved it into a header.
|
|
70
|
+
*
|
|
71
|
+
* What this deliberately does NOT do is read that header itself. On a cacheable
|
|
72
|
+
* route it is not there to read, and a fallback would render the wrong language
|
|
73
|
+
* while looking like it worked.
|
|
74
|
+
*/
|
|
75
|
+
type CmssyLayoutSlotLocaleSource = {
|
|
76
|
+
path: string[];
|
|
77
|
+
locale?: string;
|
|
78
|
+
} | {
|
|
79
|
+
locale: string;
|
|
80
|
+
path?: undefined;
|
|
81
|
+
};
|
|
82
|
+
type ResolveCmssyLayoutSlotOptions = ResolveCmssyLayoutSlotBase & CmssyLayoutSlotLocaleSource;
|
|
83
|
+
interface CmssyLayoutSlotResolution {
|
|
84
|
+
groups: CmssyLayoutGroup[];
|
|
85
|
+
locale: string;
|
|
86
|
+
defaultLocale: string;
|
|
87
|
+
enabledLocales: string[];
|
|
88
|
+
/**
|
|
89
|
+
* The routed segments with the language prefix removed - the page slug. It is
|
|
90
|
+
* returned because every caller needs it next, and resolving it twice is how
|
|
91
|
+
* the three adapters drifted apart in the first place.
|
|
92
|
+
*/
|
|
93
|
+
path: string[];
|
|
94
|
+
/** Edit mode only: the loader data and the server-resolved content. */
|
|
95
|
+
data?: Record<string, unknown>;
|
|
96
|
+
resolvedContent?: Record<string, Record<string, unknown>>;
|
|
97
|
+
/**
|
|
98
|
+
* Edit mode only, and unchanged: `string | string[]`. The bridge handles a
|
|
99
|
+
* list natively and the default is two origins - collapsing it to the first
|
|
100
|
+
* silently breaks an editor served from the second.
|
|
101
|
+
*/
|
|
102
|
+
editorOrigin?: string | string[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Everything a layout slot needs, for any framework.
|
|
106
|
+
*
|
|
107
|
+
* Three things have to be right here, and each was got wrong at least once by
|
|
108
|
+
* an app that wrote this by hand:
|
|
109
|
+
*
|
|
110
|
+
* 1. in edit mode the layouts are fetched **with the preview secret** -
|
|
111
|
+
* otherwise you edit the draft header and the editor shows the published
|
|
112
|
+
* one;
|
|
113
|
+
* 2. the language comes from the routed path, not from a request header;
|
|
114
|
+
* 3. the editor gets `resolvedContent` as well as `data` - the canvas renders
|
|
115
|
+
* stored content, where a relation field is raw ids.
|
|
116
|
+
*
|
|
117
|
+
* Rendering stays with the caller: three frameworks, three rendering models.
|
|
118
|
+
* This is the half that is the same in all of them.
|
|
119
|
+
*/
|
|
120
|
+
declare function resolveCmssyLayoutSlot(config: CmssyConfig, options: ResolveCmssyLayoutSlotOptions): Promise<CmssyLayoutSlotResolution>;
|
|
121
|
+
|
|
45
122
|
interface CmssyServerLayoutProps {
|
|
46
123
|
groups: CmssyLayoutGroup[];
|
|
47
124
|
blocks: BlockDefinition[];
|
|
@@ -96,4 +173,4 @@ interface UnknownBlockProps {
|
|
|
96
173
|
}
|
|
97
174
|
declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
|
|
98
175
|
|
|
99
|
-
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, UnknownBlock, type UnknownBlockProps };
|
|
176
|
+
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, type CmssyLayoutSlotLocaleSource, type CmssyLayoutSlotResolution, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, type ResolveCmssyLayoutSlotOptions, UnknownBlock, type UnknownBlockProps, resolveCmssyLayoutSlot };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { resolveEditorOrigin } from '@cmssy/core';
|
|
1
2
|
export { CmssyRequestError, PROTOCOL_VERSION, createCmssyClient, fields, graphqlRequest, isProtocolCompatible, layoutPositionValues, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
|
|
2
|
-
import { buildBlockContext, getBlockContentForLanguage, normalizeRelationContent, asBucket, resolveSiteLocales, resolveRelationContent } from '@cmssy/core/internal';
|
|
3
|
+
import { buildBlockContext, fetchLayouts, getBlockContentForLanguage, normalizeRelationContent, asBucket, resolveSiteLocales as resolveSiteLocales$1, resolveRelationContent } from '@cmssy/core/internal';
|
|
3
4
|
export { buildBlockContext } from '@cmssy/core/internal';
|
|
4
5
|
import { createElement } from 'react';
|
|
5
6
|
import { BlockErrorBoundary } from '@cmssy/react/block-error-boundary';
|
|
6
7
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
8
|
+
import { resolveSiteLocales, splitLocaleFromPath } from '@cmssy/core/internal/locale';
|
|
7
9
|
|
|
8
10
|
// src/index.ts
|
|
9
11
|
|
|
@@ -234,7 +236,7 @@ async function resolveRenderLocale({
|
|
|
234
236
|
}) {
|
|
235
237
|
if (locale && defaultLocale) return { locale, defaultLocale, enabledLocales };
|
|
236
238
|
if (config) {
|
|
237
|
-
const site = await resolveSiteLocales(config);
|
|
239
|
+
const site = await resolveSiteLocales$1(config);
|
|
238
240
|
return {
|
|
239
241
|
locale: locale ?? defaultLocale ?? site.defaultLocale,
|
|
240
242
|
defaultLocale: defaultLocale ?? site.defaultLocale,
|
|
@@ -363,7 +365,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
363
365
|
appContext
|
|
364
366
|
}) {
|
|
365
367
|
const group = groups.find((g) => g.position === position);
|
|
366
|
-
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
368
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
|
|
367
369
|
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
368
370
|
const loaderMap = buildLoaderMap(blocks);
|
|
369
371
|
const context = buildBlockContext(
|
|
@@ -385,6 +387,52 @@ async function resolveEditorLayoutBlockData({
|
|
|
385
387
|
);
|
|
386
388
|
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
387
389
|
}
|
|
390
|
+
async function resolveCmssyLayoutSlot(config, options) {
|
|
391
|
+
const {
|
|
392
|
+
position,
|
|
393
|
+
blocks,
|
|
394
|
+
editMode,
|
|
395
|
+
page,
|
|
396
|
+
forms,
|
|
397
|
+
appContext,
|
|
398
|
+
path,
|
|
399
|
+
locale: explicitLocale
|
|
400
|
+
} = options;
|
|
401
|
+
const siteLocales = await resolveSiteLocales(config);
|
|
402
|
+
const fromPath = path ? splitLocaleFromPath(path, siteLocales) : { locale: siteLocales.defaultLocale, path: [] };
|
|
403
|
+
const locale = explicitLocale ?? fromPath.locale;
|
|
404
|
+
const slugSegments = fromPath.path ?? [];
|
|
405
|
+
const pageSlug = page ?? "/" + slugSegments.join("/");
|
|
406
|
+
const groups = await fetchLayouts(config, pageSlug, {
|
|
407
|
+
previewSecret: editMode ? config.draftSecret : void 0
|
|
408
|
+
});
|
|
409
|
+
const base = {
|
|
410
|
+
groups,
|
|
411
|
+
locale,
|
|
412
|
+
defaultLocale: siteLocales.defaultLocale,
|
|
413
|
+
enabledLocales: siteLocales.locales,
|
|
414
|
+
path: slugSegments
|
|
415
|
+
};
|
|
416
|
+
if (!editMode) return base;
|
|
417
|
+
const editorData = await resolveEditorLayoutBlockData({
|
|
418
|
+
groups,
|
|
419
|
+
blocks,
|
|
420
|
+
position,
|
|
421
|
+
locale,
|
|
422
|
+
defaultLocale: siteLocales.defaultLocale,
|
|
423
|
+
enabledLocales: siteLocales.locales,
|
|
424
|
+
forms,
|
|
425
|
+
isPreview: true,
|
|
426
|
+
config,
|
|
427
|
+
appContext
|
|
428
|
+
});
|
|
429
|
+
return {
|
|
430
|
+
...base,
|
|
431
|
+
data: editorData.data,
|
|
432
|
+
resolvedContent: editorData.content,
|
|
433
|
+
editorOrigin: resolveEditorOrigin(config.editorOrigin)
|
|
434
|
+
};
|
|
435
|
+
}
|
|
388
436
|
async function CmssyServerLayout({
|
|
389
437
|
groups,
|
|
390
438
|
blocks,
|
|
@@ -403,7 +451,7 @@ async function CmssyServerLayout({
|
|
|
403
451
|
config
|
|
404
452
|
});
|
|
405
453
|
const group = groups.find((g) => g.position === position);
|
|
406
|
-
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
454
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
|
|
407
455
|
if (layoutBlocks.length === 0) return null;
|
|
408
456
|
const map = buildBlockMap(blocks);
|
|
409
457
|
const loaderMap = buildLoaderMap(blocks);
|
|
@@ -514,4 +562,4 @@ function CmssyBlock({
|
|
|
514
562
|
);
|
|
515
563
|
}
|
|
516
564
|
|
|
517
|
-
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock, resolveEditorBlockData, resolveEditorLayoutBlockData };
|
|
565
|
+
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock, resolveCmssyLayoutSlot, resolveEditorBlockData, resolveEditorLayoutBlockData };
|
package/dist/internal-server.cjs
CHANGED
|
@@ -138,7 +138,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
138
138
|
appContext
|
|
139
139
|
}) {
|
|
140
140
|
const group = groups.find((g) => g.position === position);
|
|
141
|
-
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
141
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
|
|
142
142
|
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
143
143
|
const loaderMap = buildLoaderMap(blocks);
|
|
144
144
|
const context = internal.buildBlockContext(
|
package/dist/internal-server.js
CHANGED
|
@@ -136,7 +136,7 @@ async function resolveEditorLayoutBlockData({
|
|
|
136
136
|
appContext
|
|
137
137
|
}) {
|
|
138
138
|
const group = groups.find((g) => g.position === position);
|
|
139
|
-
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
139
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
|
|
140
140
|
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
141
141
|
const loaderMap = buildLoaderMap(blocks);
|
|
142
142
|
const context = buildBlockContext(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/react",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@cmssy/types": "0.32.0",
|
|
75
|
-
"@cmssy/core": "11.
|
|
75
|
+
"@cmssy/core": "11.1.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsup",
|