@cmssy/react 10.8.0 → 10.9.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/index.cjs +87 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +86 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -52,6 +52,9 @@ function unregisteredBlockError(type) {
|
|
|
52
52
|
message: `Block type "${type}" is not registered in this site's blocks array.`
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
+
function markBlockError(error) {
|
|
56
|
+
return { [BLOCK_ERROR_KEY]: error };
|
|
57
|
+
}
|
|
55
58
|
function readBlockError(value) {
|
|
56
59
|
if (typeof value !== "object" || value === null) return void 0;
|
|
57
60
|
const marked = value[BLOCK_ERROR_KEY];
|
|
@@ -301,6 +304,88 @@ async function CmssyServerPage({
|
|
|
301
304
|
})
|
|
302
305
|
) });
|
|
303
306
|
}
|
|
307
|
+
function collectBlockData(blocks, resolved, isPreview) {
|
|
308
|
+
const data = {};
|
|
309
|
+
const content = {};
|
|
310
|
+
blocks.forEach((block, index) => {
|
|
311
|
+
const entry = resolved[index];
|
|
312
|
+
if (!entry) return;
|
|
313
|
+
content[block.id] = entry.content;
|
|
314
|
+
if (entry.error && isPreview) {
|
|
315
|
+
data[block.id] = markBlockError(entry.error);
|
|
316
|
+
} else if (entry.data !== void 0) {
|
|
317
|
+
data[block.id] = entry.data;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return { data, content };
|
|
321
|
+
}
|
|
322
|
+
async function resolveEditorBlockData({
|
|
323
|
+
page,
|
|
324
|
+
blocks,
|
|
325
|
+
locale,
|
|
326
|
+
defaultLocale,
|
|
327
|
+
enabledLocales,
|
|
328
|
+
forms,
|
|
329
|
+
isPreview = false,
|
|
330
|
+
config,
|
|
331
|
+
appContext
|
|
332
|
+
}) {
|
|
333
|
+
if (!page) return { data: {}, content: {} };
|
|
334
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
335
|
+
const context = internal.buildBlockContext(
|
|
336
|
+
locale,
|
|
337
|
+
defaultLocale,
|
|
338
|
+
enabledLocales,
|
|
339
|
+
isPreview,
|
|
340
|
+
forms,
|
|
341
|
+
{ page, app: appContext }
|
|
342
|
+
);
|
|
343
|
+
const resolved = await resolveBlocks(
|
|
344
|
+
page.blocks,
|
|
345
|
+
loaderMap,
|
|
346
|
+
locale,
|
|
347
|
+
defaultLocale,
|
|
348
|
+
context,
|
|
349
|
+
enabledLocales,
|
|
350
|
+
{ schemas: blocksToSchemas(blocks), config }
|
|
351
|
+
);
|
|
352
|
+
return collectBlockData(page.blocks, resolved, isPreview);
|
|
353
|
+
}
|
|
354
|
+
async function resolveEditorLayoutBlockData({
|
|
355
|
+
groups,
|
|
356
|
+
blocks,
|
|
357
|
+
position,
|
|
358
|
+
locale,
|
|
359
|
+
defaultLocale,
|
|
360
|
+
enabledLocales,
|
|
361
|
+
forms,
|
|
362
|
+
isPreview = false,
|
|
363
|
+
config,
|
|
364
|
+
appContext
|
|
365
|
+
}) {
|
|
366
|
+
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
|
+
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
369
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
370
|
+
const context = internal.buildBlockContext(
|
|
371
|
+
locale,
|
|
372
|
+
defaultLocale,
|
|
373
|
+
enabledLocales,
|
|
374
|
+
isPreview,
|
|
375
|
+
forms,
|
|
376
|
+
{ app: appContext }
|
|
377
|
+
);
|
|
378
|
+
const resolved = await resolveBlocks(
|
|
379
|
+
layoutBlocks,
|
|
380
|
+
loaderMap,
|
|
381
|
+
locale,
|
|
382
|
+
defaultLocale,
|
|
383
|
+
context,
|
|
384
|
+
enabledLocales,
|
|
385
|
+
{ schemas: blocksToSchemas(blocks), config }
|
|
386
|
+
);
|
|
387
|
+
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
388
|
+
}
|
|
304
389
|
async function CmssyServerLayout({
|
|
305
390
|
groups,
|
|
306
391
|
blocks,
|
|
@@ -476,3 +561,5 @@ exports.CmssyServerPage = CmssyServerPage;
|
|
|
476
561
|
exports.UnknownBlock = UnknownBlock;
|
|
477
562
|
exports.buildBlockMap = buildBlockMap;
|
|
478
563
|
exports.defineBlock = defineBlock;
|
|
564
|
+
exports.resolveEditorBlockData = resolveEditorBlockData;
|
|
565
|
+
exports.resolveEditorLayoutBlockData = resolveEditorLayoutBlockData;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ 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
|
-
export { EditorBlockData, ResolveBlockDataOptions, ResolveLayoutBlockDataOptions } from './internal-server.cjs';
|
|
9
|
+
export { EditorBlockData, ResolveBlockDataOptions, ResolveLayoutBlockDataOptions, resolveEditorBlockData, resolveEditorLayoutBlockData } from './internal-server.cjs';
|
|
10
10
|
import 'react';
|
|
11
11
|
|
|
12
12
|
interface CmssyServerPageProps {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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
|
-
export { EditorBlockData, ResolveBlockDataOptions, ResolveLayoutBlockDataOptions } from './internal-server.js';
|
|
9
|
+
export { EditorBlockData, ResolveBlockDataOptions, ResolveLayoutBlockDataOptions, resolveEditorBlockData, resolveEditorLayoutBlockData } from './internal-server.js';
|
|
10
10
|
import 'react';
|
|
11
11
|
|
|
12
12
|
interface CmssyServerPageProps {
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,9 @@ function unregisteredBlockError(type) {
|
|
|
51
51
|
message: `Block type "${type}" is not registered in this site's blocks array.`
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
+
function markBlockError(error) {
|
|
55
|
+
return { [BLOCK_ERROR_KEY]: error };
|
|
56
|
+
}
|
|
54
57
|
function readBlockError(value) {
|
|
55
58
|
if (typeof value !== "object" || value === null) return void 0;
|
|
56
59
|
const marked = value[BLOCK_ERROR_KEY];
|
|
@@ -300,6 +303,88 @@ async function CmssyServerPage({
|
|
|
300
303
|
})
|
|
301
304
|
) });
|
|
302
305
|
}
|
|
306
|
+
function collectBlockData(blocks, resolved, isPreview) {
|
|
307
|
+
const data = {};
|
|
308
|
+
const content = {};
|
|
309
|
+
blocks.forEach((block, index) => {
|
|
310
|
+
const entry = resolved[index];
|
|
311
|
+
if (!entry) return;
|
|
312
|
+
content[block.id] = entry.content;
|
|
313
|
+
if (entry.error && isPreview) {
|
|
314
|
+
data[block.id] = markBlockError(entry.error);
|
|
315
|
+
} else if (entry.data !== void 0) {
|
|
316
|
+
data[block.id] = entry.data;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
return { data, content };
|
|
320
|
+
}
|
|
321
|
+
async function resolveEditorBlockData({
|
|
322
|
+
page,
|
|
323
|
+
blocks,
|
|
324
|
+
locale,
|
|
325
|
+
defaultLocale,
|
|
326
|
+
enabledLocales,
|
|
327
|
+
forms,
|
|
328
|
+
isPreview = false,
|
|
329
|
+
config,
|
|
330
|
+
appContext
|
|
331
|
+
}) {
|
|
332
|
+
if (!page) return { data: {}, content: {} };
|
|
333
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
334
|
+
const context = buildBlockContext(
|
|
335
|
+
locale,
|
|
336
|
+
defaultLocale,
|
|
337
|
+
enabledLocales,
|
|
338
|
+
isPreview,
|
|
339
|
+
forms,
|
|
340
|
+
{ page, app: appContext }
|
|
341
|
+
);
|
|
342
|
+
const resolved = await resolveBlocks(
|
|
343
|
+
page.blocks,
|
|
344
|
+
loaderMap,
|
|
345
|
+
locale,
|
|
346
|
+
defaultLocale,
|
|
347
|
+
context,
|
|
348
|
+
enabledLocales,
|
|
349
|
+
{ schemas: blocksToSchemas(blocks), config }
|
|
350
|
+
);
|
|
351
|
+
return collectBlockData(page.blocks, resolved, isPreview);
|
|
352
|
+
}
|
|
353
|
+
async function resolveEditorLayoutBlockData({
|
|
354
|
+
groups,
|
|
355
|
+
blocks,
|
|
356
|
+
position,
|
|
357
|
+
locale,
|
|
358
|
+
defaultLocale,
|
|
359
|
+
enabledLocales,
|
|
360
|
+
forms,
|
|
361
|
+
isPreview = false,
|
|
362
|
+
config,
|
|
363
|
+
appContext
|
|
364
|
+
}) {
|
|
365
|
+
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) : [];
|
|
367
|
+
if (layoutBlocks.length === 0) return { data: {}, content: {} };
|
|
368
|
+
const loaderMap = buildLoaderMap(blocks);
|
|
369
|
+
const context = buildBlockContext(
|
|
370
|
+
locale,
|
|
371
|
+
defaultLocale,
|
|
372
|
+
enabledLocales,
|
|
373
|
+
isPreview,
|
|
374
|
+
forms,
|
|
375
|
+
{ app: appContext }
|
|
376
|
+
);
|
|
377
|
+
const resolved = await resolveBlocks(
|
|
378
|
+
layoutBlocks,
|
|
379
|
+
loaderMap,
|
|
380
|
+
locale,
|
|
381
|
+
defaultLocale,
|
|
382
|
+
context,
|
|
383
|
+
enabledLocales,
|
|
384
|
+
{ schemas: blocksToSchemas(blocks), config }
|
|
385
|
+
);
|
|
386
|
+
return collectBlockData(layoutBlocks, resolved, isPreview);
|
|
387
|
+
}
|
|
303
388
|
async function CmssyServerLayout({
|
|
304
389
|
groups,
|
|
305
390
|
blocks,
|
|
@@ -429,4 +514,4 @@ function CmssyBlock({
|
|
|
429
514
|
);
|
|
430
515
|
}
|
|
431
516
|
|
|
432
|
-
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock };
|
|
517
|
+
export { CmssyBlock, CmssyServerLayout, CmssyServerPage, UnknownBlock, buildBlockMap, defineBlock, resolveEditorBlockData, resolveEditorLayoutBlockData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/react",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.9.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": "10.
|
|
75
|
+
"@cmssy/core": "10.9.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build": "tsup",
|