@cmssy/react 10.0.0 → 10.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 +2 -2
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +2 -2
- package/dist/index.cjs +5 -117
- package/dist/index.d.cts +7 -37
- package/dist/index.d.ts +7 -37
- package/dist/index.js +4 -106
- package/dist/internal-server.cjs +166 -0
- package/dist/internal-server.d.cts +37 -0
- package/dist/internal-server.d.ts +37 -0
- package/dist/internal-server.js +161 -0
- package/dist/{registry-Bfq4Pq18.d.cts → registry-zeNh3t6y.d.cts} +2 -6
- package/dist/{registry-Bfq4Pq18.d.ts → registry-zeNh3t6y.d.ts} +2 -6
- package/package.json +7 -2
package/dist/client.cjs
CHANGED
|
@@ -657,7 +657,7 @@ function EditableBlocks({
|
|
|
657
657
|
}) {
|
|
658
658
|
const blockMap = react.useMemo(() => buildBlockMap(blocks), [blocks]);
|
|
659
659
|
const context = react.useMemo(
|
|
660
|
-
() =>
|
|
660
|
+
() => internal.buildBlockContext(locale, defaultLocale, enabledLocales, true, forms),
|
|
661
661
|
[locale, defaultLocale, enabledLocales, forms]
|
|
662
662
|
);
|
|
663
663
|
const bridgeConfig = react.useMemo(
|
|
@@ -814,7 +814,7 @@ function CmssyEditableLayout({
|
|
|
814
814
|
}, [groups, position]);
|
|
815
815
|
const patches = useLayoutPatchBridge(position, edit);
|
|
816
816
|
const context = react.useMemo(
|
|
817
|
-
() =>
|
|
817
|
+
() => internal.buildBlockContext(locale, defaultLocale, enabledLocales, true),
|
|
818
818
|
[locale, defaultLocale, enabledLocales]
|
|
819
819
|
);
|
|
820
820
|
if (layoutBlocks.length === 0) return null;
|
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, CmssyPageData, CmssyFormDefinition, CmssyLayoutGroup } from '@cmssy/core';
|
|
3
|
-
import { B as BlockDefinition } from './registry-
|
|
3
|
+
import { B as BlockDefinition } from './registry-zeNh3t6y.cjs';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
interface EditBridgeConfig {
|
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, CmssyPageData, CmssyFormDefinition, CmssyLayoutGroup } from '@cmssy/core';
|
|
3
|
-
import { B as BlockDefinition } from './registry-
|
|
3
|
+
import { B as BlockDefinition } from './registry-zeNh3t6y.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
interface EditBridgeConfig {
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useState, useRef, useEffect, useMemo, createElement } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { resolveInitialTarget, getBlockContentForLanguage, normalizeRelationContent, asBucket } from '@cmssy/core/internal';
|
|
3
|
+
import { postToEditor, PROTOCOL_VERSION, parseEditorMessage } from '@cmssy/core';
|
|
4
|
+
import { resolveInitialTarget, buildBlockContext, getBlockContentForLanguage, normalizeRelationContent, asBucket } from '@cmssy/core/internal';
|
|
5
5
|
import { BlockErrorBoundary } from '@cmssy/react/block-error-boundary';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@cmssy/core');
|
|
4
|
-
var types = require('@cmssy/types');
|
|
5
|
-
var react = require('react');
|
|
6
4
|
var internal = require('@cmssy/core/internal');
|
|
5
|
+
var react = require('react');
|
|
7
6
|
var blockErrorBoundary = require('@cmssy/react/block-error-boundary');
|
|
8
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
8
|
|
|
@@ -36,20 +35,6 @@ function blocksToSchemas(blocks) {
|
|
|
36
35
|
}
|
|
37
36
|
return out;
|
|
38
37
|
}
|
|
39
|
-
function blocksToMeta(blocks, defaults = {}) {
|
|
40
|
-
const out = /* @__PURE__ */ Object.create(null);
|
|
41
|
-
for (const block of blocks) {
|
|
42
|
-
const category = block.category ?? defaults.category;
|
|
43
|
-
out[block.type] = {
|
|
44
|
-
label: block.label ?? block.type,
|
|
45
|
-
...category ? { category } : {},
|
|
46
|
-
...block.icon ? { icon: block.icon } : {},
|
|
47
|
-
...block.layoutPositions ? { layoutPositions: block.layoutPositions } : {},
|
|
48
|
-
...block.description ? { description: block.description } : {}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
38
|
|
|
54
39
|
// src/components/block-error.ts
|
|
55
40
|
var BLOCK_ERROR_KEY = "__cmssyBlockError";
|
|
@@ -67,9 +52,6 @@ function unregisteredBlockError(type) {
|
|
|
67
52
|
message: `Block type "${type}" is not registered in this site's blocks array.`
|
|
68
53
|
};
|
|
69
54
|
}
|
|
70
|
-
function markBlockError(error) {
|
|
71
|
-
return { [BLOCK_ERROR_KEY]: error };
|
|
72
|
-
}
|
|
73
55
|
function readBlockError(value) {
|
|
74
56
|
if (typeof value !== "object" || value === null) return void 0;
|
|
75
57
|
const marked = value[BLOCK_ERROR_KEY];
|
|
@@ -290,7 +272,7 @@ async function CmssyServerPage({
|
|
|
290
272
|
});
|
|
291
273
|
const map = buildBlockMap(blocks);
|
|
292
274
|
const loaderMap = buildLoaderMap(blocks);
|
|
293
|
-
const context =
|
|
275
|
+
const context = internal.buildBlockContext(
|
|
294
276
|
locale,
|
|
295
277
|
defaultLocale,
|
|
296
278
|
enabledLocales,
|
|
@@ -318,90 +300,6 @@ async function CmssyServerPage({
|
|
|
318
300
|
})
|
|
319
301
|
) });
|
|
320
302
|
}
|
|
321
|
-
function collectBlockData(blocks, resolved, isPreview) {
|
|
322
|
-
const data = {};
|
|
323
|
-
const content = {};
|
|
324
|
-
blocks.forEach((block, index) => {
|
|
325
|
-
const entry = resolved[index];
|
|
326
|
-
if (!entry) return;
|
|
327
|
-
content[block.id] = entry.content;
|
|
328
|
-
if (entry.error && isPreview) {
|
|
329
|
-
data[block.id] = markBlockError(entry.error);
|
|
330
|
-
} else if (entry.data !== void 0) {
|
|
331
|
-
data[block.id] = entry.data;
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
return { data, content };
|
|
335
|
-
}
|
|
336
|
-
async function resolveEditorBlockData({
|
|
337
|
-
page,
|
|
338
|
-
blocks,
|
|
339
|
-
locale,
|
|
340
|
-
defaultLocale,
|
|
341
|
-
enabledLocales,
|
|
342
|
-
forms,
|
|
343
|
-
isPreview = false,
|
|
344
|
-
config
|
|
345
|
-
}) {
|
|
346
|
-
if (!page) return { data: {}, content: {} };
|
|
347
|
-
const loaderMap = buildLoaderMap(blocks);
|
|
348
|
-
const context = core.buildBlockContext(
|
|
349
|
-
locale,
|
|
350
|
-
defaultLocale,
|
|
351
|
-
enabledLocales,
|
|
352
|
-
isPreview,
|
|
353
|
-
forms
|
|
354
|
-
);
|
|
355
|
-
const resolved = await resolveBlocks(
|
|
356
|
-
page.blocks,
|
|
357
|
-
loaderMap,
|
|
358
|
-
locale,
|
|
359
|
-
defaultLocale,
|
|
360
|
-
context,
|
|
361
|
-
enabledLocales,
|
|
362
|
-
{ schemas: blocksToSchemas(blocks), config }
|
|
363
|
-
);
|
|
364
|
-
return collectBlockData(page.blocks, resolved, isPreview);
|
|
365
|
-
}
|
|
366
|
-
async function resolveBlockData(options) {
|
|
367
|
-
return (await resolveEditorBlockData(options)).data;
|
|
368
|
-
}
|
|
369
|
-
async function resolveEditorLayoutBlockData({
|
|
370
|
-
groups,
|
|
371
|
-
blocks,
|
|
372
|
-
position,
|
|
373
|
-
locale,
|
|
374
|
-
defaultLocale,
|
|
375
|
-
enabledLocales,
|
|
376
|
-
forms,
|
|
377
|
-
isPreview = false,
|
|
378
|
-
config
|
|
379
|
-
}) {
|
|
380
|
-
const group = groups.find((g) => g.position === position);
|
|
381
|
-
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
382
|
-
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
383
|
-
const loaderMap = buildLoaderMap(blocks);
|
|
384
|
-
const context = core.buildBlockContext(
|
|
385
|
-
locale,
|
|
386
|
-
defaultLocale,
|
|
387
|
-
enabledLocales,
|
|
388
|
-
isPreview,
|
|
389
|
-
forms
|
|
390
|
-
);
|
|
391
|
-
const resolved = await resolveBlocks(
|
|
392
|
-
layoutBlocks,
|
|
393
|
-
loaderMap,
|
|
394
|
-
locale,
|
|
395
|
-
defaultLocale,
|
|
396
|
-
context,
|
|
397
|
-
enabledLocales,
|
|
398
|
-
{ schemas: blocksToSchemas(blocks), config }
|
|
399
|
-
);
|
|
400
|
-
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
401
|
-
}
|
|
402
|
-
async function resolveLayoutBlockData(options) {
|
|
403
|
-
return (await resolveEditorLayoutBlockData(options)).data;
|
|
404
|
-
}
|
|
405
303
|
async function CmssyServerLayout({
|
|
406
304
|
groups,
|
|
407
305
|
blocks,
|
|
@@ -423,7 +321,7 @@ async function CmssyServerLayout({
|
|
|
423
321
|
if (layoutBlocks.length === 0) return null;
|
|
424
322
|
const map = buildBlockMap(blocks);
|
|
425
323
|
const loaderMap = buildLoaderMap(blocks);
|
|
426
|
-
const context =
|
|
324
|
+
const context = internal.buildBlockContext(locale, defaultLocale, enabledLocales);
|
|
427
325
|
const resolved = await resolveBlocks(
|
|
428
326
|
layoutBlocks,
|
|
429
327
|
loaderMap,
|
|
@@ -531,10 +429,6 @@ Object.defineProperty(exports, "PROTOCOL_VERSION", {
|
|
|
531
429
|
enumerable: true,
|
|
532
430
|
get: function () { return core.PROTOCOL_VERSION; }
|
|
533
431
|
});
|
|
534
|
-
Object.defineProperty(exports, "buildBlockContext", {
|
|
535
|
-
enumerable: true,
|
|
536
|
-
get: function () { return core.buildBlockContext; }
|
|
537
|
-
});
|
|
538
432
|
Object.defineProperty(exports, "createCmssyClient", {
|
|
539
433
|
enumerable: true,
|
|
540
434
|
get: function () { return core.createCmssyClient; }
|
|
@@ -563,19 +457,13 @@ Object.defineProperty(exports, "postToEditor", {
|
|
|
563
457
|
enumerable: true,
|
|
564
458
|
get: function () { return core.postToEditor; }
|
|
565
459
|
});
|
|
566
|
-
Object.defineProperty(exports, "
|
|
460
|
+
Object.defineProperty(exports, "buildBlockContext", {
|
|
567
461
|
enumerable: true,
|
|
568
|
-
get: function () { return
|
|
462
|
+
get: function () { return internal.buildBlockContext; }
|
|
569
463
|
});
|
|
570
464
|
exports.CmssyBlock = CmssyBlock;
|
|
571
465
|
exports.CmssyServerLayout = CmssyServerLayout;
|
|
572
466
|
exports.CmssyServerPage = CmssyServerPage;
|
|
573
467
|
exports.UnknownBlock = UnknownBlock;
|
|
574
|
-
exports.blocksToMeta = blocksToMeta;
|
|
575
|
-
exports.blocksToSchemas = blocksToSchemas;
|
|
576
468
|
exports.buildBlockMap = buildBlockMap;
|
|
577
469
|
exports.defineBlock = defineBlock;
|
|
578
|
-
exports.resolveBlockData = resolveBlockData;
|
|
579
|
-
exports.resolveEditorBlockData = resolveEditorBlockData;
|
|
580
|
-
exports.resolveEditorLayoutBlockData = resolveEditorLayoutBlockData;
|
|
581
|
-
exports.resolveLayoutBlockData = resolveLayoutBlockData;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, RawBlock, CmssyBlockContext } from '@cmssy/core';
|
|
2
|
-
export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRequestError, CmssySiteConfig, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryPolicy, SelectMessage, SubmitFormInput, TypedField,
|
|
3
|
-
import { B as BlockDefinition, a as BlockMap } from './registry-
|
|
4
|
-
export { b as BlockProps, c as
|
|
2
|
+
export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRequestError, CmssySiteConfig, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryPolicy, SelectMessage, SubmitFormInput, TypedField, createCmssyClient, fields, graphqlRequest, isProtocolCompatible, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
|
|
3
|
+
import { B as BlockDefinition, a as BlockMap } from './registry-zeNh3t6y.cjs';
|
|
4
|
+
export { b as BlockProps, c as buildBlockMap, d as defineBlock } from './registry-zeNh3t6y.cjs';
|
|
5
5
|
import { FieldDefinition } from '@cmssy/types';
|
|
6
|
-
export { FieldCondition, FieldConditionGroup, FieldConditionLogic
|
|
6
|
+
export { FieldCondition, FieldConditionGroup, FieldConditionLogic } from '@cmssy/types';
|
|
7
|
+
export { buildBlockContext } from '@cmssy/core/internal';
|
|
7
8
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
9
|
+
export { EditorBlockData, ResolveBlockDataOptions, ResolveLayoutBlockDataOptions } from './internal-server.cjs';
|
|
8
10
|
import 'react';
|
|
9
11
|
|
|
10
12
|
interface CmssyServerPageProps {
|
|
@@ -34,38 +36,6 @@ interface CmssyServerPageProps {
|
|
|
34
36
|
*/
|
|
35
37
|
declare function CmssyServerPage({ page, blocks, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, forms, auth, workspace, editMode, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
|
|
36
38
|
|
|
37
|
-
interface EditorBlockData {
|
|
38
|
-
data: Record<string, unknown>;
|
|
39
|
-
content: Record<string, Record<string, unknown>>;
|
|
40
|
-
}
|
|
41
|
-
interface ResolveBlockDataOptions {
|
|
42
|
-
page: CmssyPageData | null;
|
|
43
|
-
blocks: BlockDefinition[];
|
|
44
|
-
locale: string;
|
|
45
|
-
defaultLocale: string;
|
|
46
|
-
enabledLocales?: string[];
|
|
47
|
-
forms?: Record<string, CmssyFormDefinition>;
|
|
48
|
-
isPreview?: boolean;
|
|
49
|
-
/** Workspace the relation records are read from. No config, no resolution. */
|
|
50
|
-
config?: CmssyClientConfig;
|
|
51
|
-
}
|
|
52
|
-
declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
|
|
53
|
-
declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
|
|
54
|
-
interface ResolveLayoutBlockDataOptions {
|
|
55
|
-
groups: CmssyLayoutGroup[];
|
|
56
|
-
blocks: BlockDefinition[];
|
|
57
|
-
position: string;
|
|
58
|
-
locale: string;
|
|
59
|
-
defaultLocale: string;
|
|
60
|
-
enabledLocales?: string[];
|
|
61
|
-
forms?: Record<string, CmssyFormDefinition>;
|
|
62
|
-
isPreview?: boolean;
|
|
63
|
-
/** Workspace the relation records are read from. No config, no resolution. */
|
|
64
|
-
config?: CmssyClientConfig;
|
|
65
|
-
}
|
|
66
|
-
declare function resolveEditorLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
|
|
67
|
-
declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
|
|
68
|
-
|
|
69
39
|
interface CmssyServerLayoutProps {
|
|
70
40
|
groups: CmssyLayoutGroup[];
|
|
71
41
|
blocks: BlockDefinition[];
|
|
@@ -114,4 +84,4 @@ interface UnknownBlockProps {
|
|
|
114
84
|
}
|
|
115
85
|
declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
|
|
116
86
|
|
|
117
|
-
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps,
|
|
87
|
+
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, UnknownBlock, type UnknownBlockProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CmssyPageData, CmssyClientConfig, CmssyFormDefinition, CmssyBlockAuthContext, CmssyBlockWorkspace, CmssyLayoutGroup, RawBlock, CmssyBlockContext } from '@cmssy/core';
|
|
2
|
-
export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRequestError, CmssySiteConfig, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryPolicy, SelectMessage, SubmitFormInput, TypedField,
|
|
3
|
-
import { B as BlockDefinition, a as BlockMap } from './registry-
|
|
4
|
-
export { b as BlockProps, c as
|
|
2
|
+
export { AppToEditorMessage, BlockMeta, BlockPropsSchema, BlockRect, BlockSchema, BoundsMessage, BuildBlockContextExtra, ClickMessage, CmssyBlockAuthContext, CmssyBlockContext, CmssyBlockMember, CmssyBlockWorkspace, CmssyBranding, CmssyClient, CmssyClientConfig, CmssyFormDefinition, CmssyFormField, CmssyFormSettings, CmssyFormSubmitResponse, CmssyLayoutGroup, CmssyLayoutSettings, CmssyLocaleContext, CmssyLocalizedValue, CmssyModelDefinition, CmssyModelRecord, CmssyPageData, CmssyPageMeta, CmssyPageSummary, CmssyRecordList, CmssyRequestError, CmssySiteConfig, EditorToAppMessage, FetchLike, FetchLikeResponse, FetchPageOptions, FieldControl, FieldDefinition, FieldType, GraphqlRequestOptions, InferBlockContent, PROTOCOL_VERSION, ParentReadyMessage, PatchMessage, PostTarget, QueryScopedOptions, RawBlock, RawLayoutBlock, ReadyMessage, RetryPolicy, SelectMessage, SubmitFormInput, TypedField, createCmssyClient, fields, graphqlRequest, isProtocolCompatible, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
|
|
3
|
+
import { B as BlockDefinition, a as BlockMap } from './registry-zeNh3t6y.js';
|
|
4
|
+
export { b as BlockProps, c as buildBlockMap, d as defineBlock } from './registry-zeNh3t6y.js';
|
|
5
5
|
import { FieldDefinition } from '@cmssy/types';
|
|
6
|
-
export { FieldCondition, FieldConditionGroup, FieldConditionLogic
|
|
6
|
+
export { FieldCondition, FieldConditionGroup, FieldConditionLogic } from '@cmssy/types';
|
|
7
|
+
export { buildBlockContext } from '@cmssy/core/internal';
|
|
7
8
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
9
|
+
export { EditorBlockData, ResolveBlockDataOptions, ResolveLayoutBlockDataOptions } from './internal-server.js';
|
|
8
10
|
import 'react';
|
|
9
11
|
|
|
10
12
|
interface CmssyServerPageProps {
|
|
@@ -34,38 +36,6 @@ interface CmssyServerPageProps {
|
|
|
34
36
|
*/
|
|
35
37
|
declare function CmssyServerPage({ page, blocks, locale: localeProp, defaultLocale: defaultLocaleProp, enabledLocales: enabledLocalesProp, config, forms, auth, workspace, editMode, }: CmssyServerPageProps): Promise<react_jsx_runtime.JSX.Element | null>;
|
|
36
38
|
|
|
37
|
-
interface EditorBlockData {
|
|
38
|
-
data: Record<string, unknown>;
|
|
39
|
-
content: Record<string, Record<string, unknown>>;
|
|
40
|
-
}
|
|
41
|
-
interface ResolveBlockDataOptions {
|
|
42
|
-
page: CmssyPageData | null;
|
|
43
|
-
blocks: BlockDefinition[];
|
|
44
|
-
locale: string;
|
|
45
|
-
defaultLocale: string;
|
|
46
|
-
enabledLocales?: string[];
|
|
47
|
-
forms?: Record<string, CmssyFormDefinition>;
|
|
48
|
-
isPreview?: boolean;
|
|
49
|
-
/** Workspace the relation records are read from. No config, no resolution. */
|
|
50
|
-
config?: CmssyClientConfig;
|
|
51
|
-
}
|
|
52
|
-
declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
|
|
53
|
-
declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
|
|
54
|
-
interface ResolveLayoutBlockDataOptions {
|
|
55
|
-
groups: CmssyLayoutGroup[];
|
|
56
|
-
blocks: BlockDefinition[];
|
|
57
|
-
position: string;
|
|
58
|
-
locale: string;
|
|
59
|
-
defaultLocale: string;
|
|
60
|
-
enabledLocales?: string[];
|
|
61
|
-
forms?: Record<string, CmssyFormDefinition>;
|
|
62
|
-
isPreview?: boolean;
|
|
63
|
-
/** Workspace the relation records are read from. No config, no resolution. */
|
|
64
|
-
config?: CmssyClientConfig;
|
|
65
|
-
}
|
|
66
|
-
declare function resolveEditorLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
|
|
67
|
-
declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
|
|
68
|
-
|
|
69
39
|
interface CmssyServerLayoutProps {
|
|
70
40
|
groups: CmssyLayoutGroup[];
|
|
71
41
|
blocks: BlockDefinition[];
|
|
@@ -114,4 +84,4 @@ interface UnknownBlockProps {
|
|
|
114
84
|
}
|
|
115
85
|
declare function UnknownBlock({ type }: UnknownBlockProps): react_jsx_runtime.JSX.Element;
|
|
116
86
|
|
|
117
|
-
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps,
|
|
87
|
+
export { BlockDefinition, BlockMap, CmssyBlock, type CmssyBlockProps, CmssyServerLayout, type CmssyServerLayoutProps, CmssyServerPage, type CmssyServerPageProps, UnknownBlock, type UnknownBlockProps };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
export { CmssyRequestError, PROTOCOL_VERSION, createCmssyClient, fields, graphqlRequest, isProtocolCompatible, normalizeOrigin, parseEditorMessage, postToEditor } from '@cmssy/core';
|
|
2
|
+
import { buildBlockContext, getBlockContentForLanguage, normalizeRelationContent, asBucket, resolveSiteLocales, resolveRelationContent } from '@cmssy/core/internal';
|
|
3
|
+
export { buildBlockContext } from '@cmssy/core/internal';
|
|
4
4
|
import { createElement } from 'react';
|
|
5
|
-
import { getBlockContentForLanguage, normalizeRelationContent, asBucket, resolveSiteLocales, resolveRelationContent } from '@cmssy/core/internal';
|
|
6
5
|
import { BlockErrorBoundary } from '@cmssy/react/block-error-boundary';
|
|
7
6
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
8
7
|
|
|
@@ -35,20 +34,6 @@ function blocksToSchemas(blocks) {
|
|
|
35
34
|
}
|
|
36
35
|
return out;
|
|
37
36
|
}
|
|
38
|
-
function blocksToMeta(blocks, defaults = {}) {
|
|
39
|
-
const out = /* @__PURE__ */ Object.create(null);
|
|
40
|
-
for (const block of blocks) {
|
|
41
|
-
const category = block.category ?? defaults.category;
|
|
42
|
-
out[block.type] = {
|
|
43
|
-
label: block.label ?? block.type,
|
|
44
|
-
...category ? { category } : {},
|
|
45
|
-
...block.icon ? { icon: block.icon } : {},
|
|
46
|
-
...block.layoutPositions ? { layoutPositions: block.layoutPositions } : {},
|
|
47
|
-
...block.description ? { description: block.description } : {}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return out;
|
|
51
|
-
}
|
|
52
37
|
|
|
53
38
|
// src/components/block-error.ts
|
|
54
39
|
var BLOCK_ERROR_KEY = "__cmssyBlockError";
|
|
@@ -66,9 +51,6 @@ function unregisteredBlockError(type) {
|
|
|
66
51
|
message: `Block type "${type}" is not registered in this site's blocks array.`
|
|
67
52
|
};
|
|
68
53
|
}
|
|
69
|
-
function markBlockError(error) {
|
|
70
|
-
return { [BLOCK_ERROR_KEY]: error };
|
|
71
|
-
}
|
|
72
54
|
function readBlockError(value) {
|
|
73
55
|
if (typeof value !== "object" || value === null) return void 0;
|
|
74
56
|
const marked = value[BLOCK_ERROR_KEY];
|
|
@@ -317,90 +299,6 @@ async function CmssyServerPage({
|
|
|
317
299
|
})
|
|
318
300
|
) });
|
|
319
301
|
}
|
|
320
|
-
function collectBlockData(blocks, resolved, isPreview) {
|
|
321
|
-
const data = {};
|
|
322
|
-
const content = {};
|
|
323
|
-
blocks.forEach((block, index) => {
|
|
324
|
-
const entry = resolved[index];
|
|
325
|
-
if (!entry) return;
|
|
326
|
-
content[block.id] = entry.content;
|
|
327
|
-
if (entry.error && isPreview) {
|
|
328
|
-
data[block.id] = markBlockError(entry.error);
|
|
329
|
-
} else if (entry.data !== void 0) {
|
|
330
|
-
data[block.id] = entry.data;
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
return { data, content };
|
|
334
|
-
}
|
|
335
|
-
async function resolveEditorBlockData({
|
|
336
|
-
page,
|
|
337
|
-
blocks,
|
|
338
|
-
locale,
|
|
339
|
-
defaultLocale,
|
|
340
|
-
enabledLocales,
|
|
341
|
-
forms,
|
|
342
|
-
isPreview = false,
|
|
343
|
-
config
|
|
344
|
-
}) {
|
|
345
|
-
if (!page) return { data: {}, content: {} };
|
|
346
|
-
const loaderMap = buildLoaderMap(blocks);
|
|
347
|
-
const context = buildBlockContext(
|
|
348
|
-
locale,
|
|
349
|
-
defaultLocale,
|
|
350
|
-
enabledLocales,
|
|
351
|
-
isPreview,
|
|
352
|
-
forms
|
|
353
|
-
);
|
|
354
|
-
const resolved = await resolveBlocks(
|
|
355
|
-
page.blocks,
|
|
356
|
-
loaderMap,
|
|
357
|
-
locale,
|
|
358
|
-
defaultLocale,
|
|
359
|
-
context,
|
|
360
|
-
enabledLocales,
|
|
361
|
-
{ schemas: blocksToSchemas(blocks), config }
|
|
362
|
-
);
|
|
363
|
-
return collectBlockData(page.blocks, resolved, isPreview);
|
|
364
|
-
}
|
|
365
|
-
async function resolveBlockData(options) {
|
|
366
|
-
return (await resolveEditorBlockData(options)).data;
|
|
367
|
-
}
|
|
368
|
-
async function resolveEditorLayoutBlockData({
|
|
369
|
-
groups,
|
|
370
|
-
blocks,
|
|
371
|
-
position,
|
|
372
|
-
locale,
|
|
373
|
-
defaultLocale,
|
|
374
|
-
enabledLocales,
|
|
375
|
-
forms,
|
|
376
|
-
isPreview = false,
|
|
377
|
-
config
|
|
378
|
-
}) {
|
|
379
|
-
const group = groups.find((g) => g.position === position);
|
|
380
|
-
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
381
|
-
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
382
|
-
const loaderMap = buildLoaderMap(blocks);
|
|
383
|
-
const context = buildBlockContext(
|
|
384
|
-
locale,
|
|
385
|
-
defaultLocale,
|
|
386
|
-
enabledLocales,
|
|
387
|
-
isPreview,
|
|
388
|
-
forms
|
|
389
|
-
);
|
|
390
|
-
const resolved = await resolveBlocks(
|
|
391
|
-
layoutBlocks,
|
|
392
|
-
loaderMap,
|
|
393
|
-
locale,
|
|
394
|
-
defaultLocale,
|
|
395
|
-
context,
|
|
396
|
-
enabledLocales,
|
|
397
|
-
{ schemas: blocksToSchemas(blocks), config }
|
|
398
|
-
);
|
|
399
|
-
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
400
|
-
}
|
|
401
|
-
async function resolveLayoutBlockData(options) {
|
|
402
|
-
return (await resolveEditorLayoutBlockData(options)).data;
|
|
403
|
-
}
|
|
404
302
|
async function CmssyServerLayout({
|
|
405
303
|
groups,
|
|
406
304
|
blocks,
|
|
@@ -522,4 +420,4 @@ function CmssyBlock({
|
|
|
522
420
|
);
|
|
523
421
|
}
|
|
524
422
|
|
|
525
|
-
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock,
|
|
423
|
+
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var internal = require('@cmssy/core/internal');
|
|
4
|
+
|
|
5
|
+
// src/components/resolve-block-data.ts
|
|
6
|
+
|
|
7
|
+
// src/registry.ts
|
|
8
|
+
function buildLoaderMap(blocks) {
|
|
9
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
10
|
+
for (const block of blocks) {
|
|
11
|
+
if (block.loader) map[block.type] = block.loader;
|
|
12
|
+
}
|
|
13
|
+
return map;
|
|
14
|
+
}
|
|
15
|
+
function blocksToSchemas(blocks) {
|
|
16
|
+
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
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/components/block-error.ts
|
|
28
|
+
var BLOCK_ERROR_KEY = "__cmssyBlockError";
|
|
29
|
+
function blockErrorMessage(err) {
|
|
30
|
+
return err instanceof Error ? err.message : String(err);
|
|
31
|
+
}
|
|
32
|
+
function markBlockError(error) {
|
|
33
|
+
return { [BLOCK_ERROR_KEY]: error };
|
|
34
|
+
}
|
|
35
|
+
async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales, options) {
|
|
36
|
+
const contents = blocks.map(
|
|
37
|
+
(block) => internal.getBlockContentForLanguage(
|
|
38
|
+
block.content,
|
|
39
|
+
locale,
|
|
40
|
+
defaultLocale,
|
|
41
|
+
enabledLocales?.length ? enabledLocales : void 0
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
if (options?.config && options.schemas) {
|
|
45
|
+
await internal.resolveRelationContent(
|
|
46
|
+
options.config,
|
|
47
|
+
blocks.map((block, i) => ({ type: block.type, content: contents[i] })),
|
|
48
|
+
options.schemas,
|
|
49
|
+
locale,
|
|
50
|
+
options.workspaceId ? { workspaceId: options.workspaceId } : {}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return Promise.all(
|
|
54
|
+
blocks.map(async (block, i) => {
|
|
55
|
+
const content = contents[i];
|
|
56
|
+
const loader = loaderMap[block.type];
|
|
57
|
+
let data;
|
|
58
|
+
let error;
|
|
59
|
+
if (loader) {
|
|
60
|
+
try {
|
|
61
|
+
data = await loader({ content, context });
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if (typeof console !== "undefined") {
|
|
64
|
+
console.error(
|
|
65
|
+
`[cmssy] loader for block "${block.type}" (${block.id}) failed`,
|
|
66
|
+
err
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
error = { message: blockErrorMessage(err), source: "loader" };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { content, data, error };
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/components/resolve-block-data.ts
|
|
78
|
+
function collectBlockData(blocks, resolved, isPreview) {
|
|
79
|
+
const data = {};
|
|
80
|
+
const content = {};
|
|
81
|
+
blocks.forEach((block, index) => {
|
|
82
|
+
const entry = resolved[index];
|
|
83
|
+
if (!entry) return;
|
|
84
|
+
content[block.id] = entry.content;
|
|
85
|
+
if (entry.error && isPreview) {
|
|
86
|
+
data[block.id] = markBlockError(entry.error);
|
|
87
|
+
} else if (entry.data !== void 0) {
|
|
88
|
+
data[block.id] = entry.data;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return { data, content };
|
|
92
|
+
}
|
|
93
|
+
async function resolveEditorBlockData({
|
|
94
|
+
page,
|
|
95
|
+
blocks,
|
|
96
|
+
locale,
|
|
97
|
+
defaultLocale,
|
|
98
|
+
enabledLocales,
|
|
99
|
+
forms,
|
|
100
|
+
isPreview = false,
|
|
101
|
+
config
|
|
102
|
+
}) {
|
|
103
|
+
if (!page) return { data: {}, content: {} };
|
|
104
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
105
|
+
const context = internal.buildBlockContext(
|
|
106
|
+
locale,
|
|
107
|
+
defaultLocale,
|
|
108
|
+
enabledLocales,
|
|
109
|
+
isPreview,
|
|
110
|
+
forms
|
|
111
|
+
);
|
|
112
|
+
const resolved = await resolveBlocks(
|
|
113
|
+
page.blocks,
|
|
114
|
+
loaderMap,
|
|
115
|
+
locale,
|
|
116
|
+
defaultLocale,
|
|
117
|
+
context,
|
|
118
|
+
enabledLocales,
|
|
119
|
+
{ schemas: blocksToSchemas(blocks), config }
|
|
120
|
+
);
|
|
121
|
+
return collectBlockData(page.blocks, resolved, isPreview);
|
|
122
|
+
}
|
|
123
|
+
async function resolveBlockData(options) {
|
|
124
|
+
return (await resolveEditorBlockData(options)).data;
|
|
125
|
+
}
|
|
126
|
+
async function resolveEditorLayoutBlockData({
|
|
127
|
+
groups,
|
|
128
|
+
blocks,
|
|
129
|
+
position,
|
|
130
|
+
locale,
|
|
131
|
+
defaultLocale,
|
|
132
|
+
enabledLocales,
|
|
133
|
+
forms,
|
|
134
|
+
isPreview = false,
|
|
135
|
+
config
|
|
136
|
+
}) {
|
|
137
|
+
const group = groups.find((g) => g.position === position);
|
|
138
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
139
|
+
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
140
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
141
|
+
const context = internal.buildBlockContext(
|
|
142
|
+
locale,
|
|
143
|
+
defaultLocale,
|
|
144
|
+
enabledLocales,
|
|
145
|
+
isPreview,
|
|
146
|
+
forms
|
|
147
|
+
);
|
|
148
|
+
const resolved = await resolveBlocks(
|
|
149
|
+
layoutBlocks,
|
|
150
|
+
loaderMap,
|
|
151
|
+
locale,
|
|
152
|
+
defaultLocale,
|
|
153
|
+
context,
|
|
154
|
+
enabledLocales,
|
|
155
|
+
{ schemas: blocksToSchemas(blocks), config }
|
|
156
|
+
);
|
|
157
|
+
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
158
|
+
}
|
|
159
|
+
async function resolveLayoutBlockData(options) {
|
|
160
|
+
return (await resolveEditorLayoutBlockData(options)).data;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
exports.resolveBlockData = resolveBlockData;
|
|
164
|
+
exports.resolveEditorBlockData = resolveEditorBlockData;
|
|
165
|
+
exports.resolveEditorLayoutBlockData = resolveEditorLayoutBlockData;
|
|
166
|
+
exports.resolveLayoutBlockData = resolveLayoutBlockData;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CmssyPageData, CmssyFormDefinition, CmssyClientConfig, CmssyLayoutGroup } from '@cmssy/core';
|
|
2
|
+
import { B as BlockDefinition } from './registry-zeNh3t6y.cjs';
|
|
3
|
+
import 'react';
|
|
4
|
+
|
|
5
|
+
interface EditorBlockData {
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
content: Record<string, Record<string, unknown>>;
|
|
8
|
+
}
|
|
9
|
+
interface ResolveBlockDataOptions {
|
|
10
|
+
page: CmssyPageData | null;
|
|
11
|
+
blocks: BlockDefinition[];
|
|
12
|
+
locale: string;
|
|
13
|
+
defaultLocale: string;
|
|
14
|
+
enabledLocales?: string[];
|
|
15
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
16
|
+
isPreview?: boolean;
|
|
17
|
+
/** Workspace the relation records are read from. No config, no resolution. */
|
|
18
|
+
config?: CmssyClientConfig;
|
|
19
|
+
}
|
|
20
|
+
declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
|
|
21
|
+
declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
|
|
22
|
+
interface ResolveLayoutBlockDataOptions {
|
|
23
|
+
groups: CmssyLayoutGroup[];
|
|
24
|
+
blocks: BlockDefinition[];
|
|
25
|
+
position: string;
|
|
26
|
+
locale: string;
|
|
27
|
+
defaultLocale: string;
|
|
28
|
+
enabledLocales?: string[];
|
|
29
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
30
|
+
isPreview?: boolean;
|
|
31
|
+
/** Workspace the relation records are read from. No config, no resolution. */
|
|
32
|
+
config?: CmssyClientConfig;
|
|
33
|
+
}
|
|
34
|
+
declare function resolveEditorLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
|
|
35
|
+
declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
|
|
36
|
+
|
|
37
|
+
export { type EditorBlockData, type ResolveBlockDataOptions, type ResolveLayoutBlockDataOptions, resolveBlockData, resolveEditorBlockData, resolveEditorLayoutBlockData, resolveLayoutBlockData };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CmssyPageData, CmssyFormDefinition, CmssyClientConfig, CmssyLayoutGroup } from '@cmssy/core';
|
|
2
|
+
import { B as BlockDefinition } from './registry-zeNh3t6y.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
|
|
5
|
+
interface EditorBlockData {
|
|
6
|
+
data: Record<string, unknown>;
|
|
7
|
+
content: Record<string, Record<string, unknown>>;
|
|
8
|
+
}
|
|
9
|
+
interface ResolveBlockDataOptions {
|
|
10
|
+
page: CmssyPageData | null;
|
|
11
|
+
blocks: BlockDefinition[];
|
|
12
|
+
locale: string;
|
|
13
|
+
defaultLocale: string;
|
|
14
|
+
enabledLocales?: string[];
|
|
15
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
16
|
+
isPreview?: boolean;
|
|
17
|
+
/** Workspace the relation records are read from. No config, no resolution. */
|
|
18
|
+
config?: CmssyClientConfig;
|
|
19
|
+
}
|
|
20
|
+
declare function resolveEditorBlockData({ page, blocks, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveBlockDataOptions): Promise<EditorBlockData>;
|
|
21
|
+
declare function resolveBlockData(options: ResolveBlockDataOptions): Promise<Record<string, unknown>>;
|
|
22
|
+
interface ResolveLayoutBlockDataOptions {
|
|
23
|
+
groups: CmssyLayoutGroup[];
|
|
24
|
+
blocks: BlockDefinition[];
|
|
25
|
+
position: string;
|
|
26
|
+
locale: string;
|
|
27
|
+
defaultLocale: string;
|
|
28
|
+
enabledLocales?: string[];
|
|
29
|
+
forms?: Record<string, CmssyFormDefinition>;
|
|
30
|
+
isPreview?: boolean;
|
|
31
|
+
/** Workspace the relation records are read from. No config, no resolution. */
|
|
32
|
+
config?: CmssyClientConfig;
|
|
33
|
+
}
|
|
34
|
+
declare function resolveEditorLayoutBlockData({ groups, blocks, position, locale, defaultLocale, enabledLocales, forms, isPreview, config, }: ResolveLayoutBlockDataOptions): Promise<EditorBlockData>;
|
|
35
|
+
declare function resolveLayoutBlockData(options: ResolveLayoutBlockDataOptions): Promise<Record<string, unknown>>;
|
|
36
|
+
|
|
37
|
+
export { type EditorBlockData, type ResolveBlockDataOptions, type ResolveLayoutBlockDataOptions, resolveBlockData, resolveEditorBlockData, resolveEditorLayoutBlockData, resolveLayoutBlockData };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { buildBlockContext, getBlockContentForLanguage, resolveRelationContent } from '@cmssy/core/internal';
|
|
2
|
+
|
|
3
|
+
// src/components/resolve-block-data.ts
|
|
4
|
+
|
|
5
|
+
// src/registry.ts
|
|
6
|
+
function buildLoaderMap(blocks) {
|
|
7
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
8
|
+
for (const block of blocks) {
|
|
9
|
+
if (block.loader) map[block.type] = block.loader;
|
|
10
|
+
}
|
|
11
|
+
return map;
|
|
12
|
+
}
|
|
13
|
+
function blocksToSchemas(blocks) {
|
|
14
|
+
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
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/components/block-error.ts
|
|
26
|
+
var BLOCK_ERROR_KEY = "__cmssyBlockError";
|
|
27
|
+
function blockErrorMessage(err) {
|
|
28
|
+
return err instanceof Error ? err.message : String(err);
|
|
29
|
+
}
|
|
30
|
+
function markBlockError(error) {
|
|
31
|
+
return { [BLOCK_ERROR_KEY]: error };
|
|
32
|
+
}
|
|
33
|
+
async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales, options) {
|
|
34
|
+
const contents = blocks.map(
|
|
35
|
+
(block) => getBlockContentForLanguage(
|
|
36
|
+
block.content,
|
|
37
|
+
locale,
|
|
38
|
+
defaultLocale,
|
|
39
|
+
enabledLocales?.length ? enabledLocales : void 0
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
if (options?.config && options.schemas) {
|
|
43
|
+
await resolveRelationContent(
|
|
44
|
+
options.config,
|
|
45
|
+
blocks.map((block, i) => ({ type: block.type, content: contents[i] })),
|
|
46
|
+
options.schemas,
|
|
47
|
+
locale,
|
|
48
|
+
options.workspaceId ? { workspaceId: options.workspaceId } : {}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return Promise.all(
|
|
52
|
+
blocks.map(async (block, i) => {
|
|
53
|
+
const content = contents[i];
|
|
54
|
+
const loader = loaderMap[block.type];
|
|
55
|
+
let data;
|
|
56
|
+
let error;
|
|
57
|
+
if (loader) {
|
|
58
|
+
try {
|
|
59
|
+
data = await loader({ content, context });
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (typeof console !== "undefined") {
|
|
62
|
+
console.error(
|
|
63
|
+
`[cmssy] loader for block "${block.type}" (${block.id}) failed`,
|
|
64
|
+
err
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
error = { message: blockErrorMessage(err), source: "loader" };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { content, data, error };
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/components/resolve-block-data.ts
|
|
76
|
+
function collectBlockData(blocks, resolved, isPreview) {
|
|
77
|
+
const data = {};
|
|
78
|
+
const content = {};
|
|
79
|
+
blocks.forEach((block, index) => {
|
|
80
|
+
const entry = resolved[index];
|
|
81
|
+
if (!entry) return;
|
|
82
|
+
content[block.id] = entry.content;
|
|
83
|
+
if (entry.error && isPreview) {
|
|
84
|
+
data[block.id] = markBlockError(entry.error);
|
|
85
|
+
} else if (entry.data !== void 0) {
|
|
86
|
+
data[block.id] = entry.data;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return { data, content };
|
|
90
|
+
}
|
|
91
|
+
async function resolveEditorBlockData({
|
|
92
|
+
page,
|
|
93
|
+
blocks,
|
|
94
|
+
locale,
|
|
95
|
+
defaultLocale,
|
|
96
|
+
enabledLocales,
|
|
97
|
+
forms,
|
|
98
|
+
isPreview = false,
|
|
99
|
+
config
|
|
100
|
+
}) {
|
|
101
|
+
if (!page) return { data: {}, content: {} };
|
|
102
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
103
|
+
const context = buildBlockContext(
|
|
104
|
+
locale,
|
|
105
|
+
defaultLocale,
|
|
106
|
+
enabledLocales,
|
|
107
|
+
isPreview,
|
|
108
|
+
forms
|
|
109
|
+
);
|
|
110
|
+
const resolved = await resolveBlocks(
|
|
111
|
+
page.blocks,
|
|
112
|
+
loaderMap,
|
|
113
|
+
locale,
|
|
114
|
+
defaultLocale,
|
|
115
|
+
context,
|
|
116
|
+
enabledLocales,
|
|
117
|
+
{ schemas: blocksToSchemas(blocks), config }
|
|
118
|
+
);
|
|
119
|
+
return collectBlockData(page.blocks, resolved, isPreview);
|
|
120
|
+
}
|
|
121
|
+
async function resolveBlockData(options) {
|
|
122
|
+
return (await resolveEditorBlockData(options)).data;
|
|
123
|
+
}
|
|
124
|
+
async function resolveEditorLayoutBlockData({
|
|
125
|
+
groups,
|
|
126
|
+
blocks,
|
|
127
|
+
position,
|
|
128
|
+
locale,
|
|
129
|
+
defaultLocale,
|
|
130
|
+
enabledLocales,
|
|
131
|
+
forms,
|
|
132
|
+
isPreview = false,
|
|
133
|
+
config
|
|
134
|
+
}) {
|
|
135
|
+
const group = groups.find((g) => g.position === position);
|
|
136
|
+
const layoutBlocks = group ? group.blocks.filter((b) => b.isActive).slice().sort((a, b) => a.order - b.order) : [];
|
|
137
|
+
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
138
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
139
|
+
const context = buildBlockContext(
|
|
140
|
+
locale,
|
|
141
|
+
defaultLocale,
|
|
142
|
+
enabledLocales,
|
|
143
|
+
isPreview,
|
|
144
|
+
forms
|
|
145
|
+
);
|
|
146
|
+
const resolved = await resolveBlocks(
|
|
147
|
+
layoutBlocks,
|
|
148
|
+
loaderMap,
|
|
149
|
+
locale,
|
|
150
|
+
defaultLocale,
|
|
151
|
+
context,
|
|
152
|
+
enabledLocales,
|
|
153
|
+
{ schemas: blocksToSchemas(blocks), config }
|
|
154
|
+
);
|
|
155
|
+
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
156
|
+
}
|
|
157
|
+
async function resolveLayoutBlockData(options) {
|
|
158
|
+
return (await resolveEditorLayoutBlockData(options)).data;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { resolveBlockData, resolveEditorBlockData, resolveEditorLayoutBlockData, resolveLayoutBlockData };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
|
-
import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent
|
|
2
|
+
import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent } from '@cmssy/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The props a block component receives, derived from the fields it declares:
|
|
@@ -99,9 +99,5 @@ type BlockMap = Record<string, ComponentType<{
|
|
|
99
99
|
data?: unknown;
|
|
100
100
|
}>>;
|
|
101
101
|
declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
|
|
102
|
-
declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
|
|
103
|
-
declare function blocksToMeta(blocks: BlockDefinition[], defaults?: {
|
|
104
|
-
category?: string;
|
|
105
|
-
}): Record<string, BlockMeta>;
|
|
106
102
|
|
|
107
|
-
export { type BlockDefinition as B, type BlockMap as a, type BlockProps as b,
|
|
103
|
+
export { type BlockDefinition as B, type BlockMap as a, type BlockProps as b, buildBlockMap as c, defineBlock as d };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
|
-
import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent
|
|
2
|
+
import { FieldDefinition, CmssyBlockContext, BlockPropsSchema, InferBlockContent } from '@cmssy/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The props a block component receives, derived from the fields it declares:
|
|
@@ -99,9 +99,5 @@ type BlockMap = Record<string, ComponentType<{
|
|
|
99
99
|
data?: unknown;
|
|
100
100
|
}>>;
|
|
101
101
|
declare function buildBlockMap(blocks: BlockDefinition[]): BlockMap;
|
|
102
|
-
declare function blocksToSchemas(blocks: BlockDefinition[]): Record<string, BlockSchema>;
|
|
103
|
-
declare function blocksToMeta(blocks: BlockDefinition[], defaults?: {
|
|
104
|
-
category?: string;
|
|
105
|
-
}): Record<string, BlockMeta>;
|
|
106
102
|
|
|
107
|
-
export { type BlockDefinition as B, type BlockMap as a, type BlockProps as b,
|
|
103
|
+
export { type BlockDefinition as B, type BlockMap as a, type BlockProps as b, buildBlockMap as c, defineBlock as d };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/react",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"import": "./dist/internal.js",
|
|
39
39
|
"require": "./dist/internal.cjs"
|
|
40
40
|
},
|
|
41
|
+
"./internal-server": {
|
|
42
|
+
"types": "./dist/internal-server.d.ts",
|
|
43
|
+
"import": "./dist/internal-server.js",
|
|
44
|
+
"require": "./dist/internal-server.cjs"
|
|
45
|
+
},
|
|
41
46
|
"./block-error-boundary": {
|
|
42
47
|
"types": "./dist/block-error-boundary.d.ts",
|
|
43
48
|
"import": "./dist/block-error-boundary.js",
|
|
@@ -67,7 +72,7 @@
|
|
|
67
72
|
},
|
|
68
73
|
"dependencies": {
|
|
69
74
|
"@cmssy/types": "0.29.0",
|
|
70
|
-
"@cmssy/core": "10.
|
|
75
|
+
"@cmssy/core": "10.1.0"
|
|
71
76
|
},
|
|
72
77
|
"scripts": {
|
|
73
78
|
"build": "tsup",
|