@cmssy/react 16.9.1 → 16.11.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/spa.cjs ADDED
@@ -0,0 +1,665 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var react = require('react');
5
+ var internal = require('@cmssy/core/internal');
6
+ var core = require('@cmssy/core');
7
+ var locale = require('@cmssy/core/internal/locale');
8
+ var blockErrorBoundary = require('@cmssy/react/block-error-boundary');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+
11
+ function buildBlockMap(blocks) {
12
+ const map = /* @__PURE__ */ Object.create(null);
13
+ for (const block of blocks) map[block.type] = block.component;
14
+ return map;
15
+ }
16
+ function buildLoaderMap(blocks) {
17
+ const map = /* @__PURE__ */ Object.create(null);
18
+ for (const block of blocks) {
19
+ if (block.loader) map[block.type] = block.loader;
20
+ }
21
+ return map;
22
+ }
23
+
24
+ // src/components/block-error.ts
25
+ var BLOCK_ERROR_KEY = "__cmssyBlockError";
26
+ var SOURCES = [
27
+ "loader",
28
+ "render",
29
+ "unregistered"
30
+ ];
31
+ function blockErrorMessage(err) {
32
+ return err instanceof Error ? err.message : String(err);
33
+ }
34
+ function unregisteredBlockError(type) {
35
+ return {
36
+ source: "unregistered",
37
+ message: `Block type "${type}" is not registered in this site's blocks array.`
38
+ };
39
+ }
40
+ function markBlockError(error) {
41
+ return { [BLOCK_ERROR_KEY]: error };
42
+ }
43
+ function readBlockError(value) {
44
+ if (typeof value !== "object" || value === null) return void 0;
45
+ const marked = value[BLOCK_ERROR_KEY];
46
+ if (typeof marked !== "object" || marked === null) return void 0;
47
+ const { message, source } = marked;
48
+ if (typeof message !== "string") return void 0;
49
+ if (!SOURCES.includes(source)) return void 0;
50
+ return { message, source };
51
+ }
52
+ async function resolveFoldedBlocks(blocks, contents, loaderMap, locale, context, options) {
53
+ const schemas = options?.schemas;
54
+ if (schemas) {
55
+ if (options?.config) {
56
+ await internal.resolveRelationContent(
57
+ options.config,
58
+ blocks.map((block, i) => ({ type: block.type, content: contents[i] })),
59
+ schemas,
60
+ locale,
61
+ options.workspaceId ? { workspaceId: options.workspaceId } : {}
62
+ );
63
+ }
64
+ blocks.forEach((block, i) => {
65
+ const schema = schemas[block.type];
66
+ if (schema) internal.normalizeBlockContent(contents[i], schema);
67
+ });
68
+ }
69
+ return Promise.all(
70
+ blocks.map(async (block, i) => {
71
+ const content = contents[i];
72
+ const loader = loaderMap[block.type];
73
+ let data;
74
+ let error;
75
+ if (loader) {
76
+ try {
77
+ data = await loader({ content, context });
78
+ } catch (err) {
79
+ if (typeof console !== "undefined") {
80
+ console.error(
81
+ `[cmssy] loader for block "${block.type}" (${block.id}) failed`,
82
+ err
83
+ );
84
+ }
85
+ error = { message: blockErrorMessage(err), source: "loader" };
86
+ }
87
+ }
88
+ return { content, data, error };
89
+ })
90
+ );
91
+ }
92
+ async function resolveBlocks(blocks, loaderMap, locale, defaultLocale, context, enabledLocales, options) {
93
+ const contents = blocks.map(
94
+ (block) => internal.getBlockContentForLanguage(
95
+ block.content,
96
+ locale,
97
+ defaultLocale,
98
+ enabledLocales?.length ? enabledLocales : void 0
99
+ )
100
+ );
101
+ return resolveFoldedBlocks(
102
+ blocks,
103
+ contents,
104
+ loaderMap,
105
+ locale,
106
+ context,
107
+ options
108
+ );
109
+ }
110
+
111
+ // src/components/resolve-block-data.ts
112
+ function collectBlockData(blocks, resolved, isPreview) {
113
+ const data = {};
114
+ const content = {};
115
+ blocks.forEach((block, index) => {
116
+ const entry = resolved[index];
117
+ if (!entry) return;
118
+ content[block.id] = entry.content;
119
+ if (entry.error && isPreview) {
120
+ data[block.id] = markBlockError(entry.error);
121
+ } else if (entry.data !== void 0) {
122
+ data[block.id] = entry.data;
123
+ }
124
+ });
125
+ return { data, content };
126
+ }
127
+ async function resolveEditorBlockData({
128
+ page,
129
+ blocks,
130
+ locale,
131
+ defaultLocale,
132
+ enabledLocales,
133
+ forms,
134
+ isPreview = false,
135
+ config,
136
+ appContext
137
+ }) {
138
+ if (!page) return { data: {}, content: {} };
139
+ const loaderMap = buildLoaderMap(blocks);
140
+ const context = internal.buildBlockContext(
141
+ locale,
142
+ defaultLocale,
143
+ enabledLocales,
144
+ isPreview,
145
+ forms,
146
+ { page, app: appContext }
147
+ );
148
+ const resolved = await resolveBlocks(
149
+ page.blocks,
150
+ loaderMap,
151
+ locale,
152
+ defaultLocale,
153
+ context,
154
+ enabledLocales,
155
+ { schemas: core.blocksToSchemas(blocks), config }
156
+ );
157
+ return collectBlockData(page.blocks, resolved, isPreview);
158
+ }
159
+ async function resolveEditorLayoutBlockData({
160
+ groups,
161
+ blocks,
162
+ region,
163
+ page,
164
+ locale,
165
+ defaultLocale,
166
+ enabledLocales,
167
+ forms,
168
+ isPreview = false,
169
+ config,
170
+ appContext
171
+ }) {
172
+ const group = groups.find((g) => g.region === region);
173
+ const layoutBlocks = group ? group.blocks.filter((b) => b.isActive !== false).slice().sort((a, b) => a.order - b.order) : [];
174
+ if (layoutBlocks.length === 0) return { data: {}, content: {} };
175
+ const loaderMap = buildLoaderMap(blocks);
176
+ const context = internal.buildBlockContext(
177
+ locale,
178
+ defaultLocale,
179
+ enabledLocales,
180
+ isPreview,
181
+ forms,
182
+ { page, app: appContext }
183
+ );
184
+ const resolved = await resolveBlocks(
185
+ layoutBlocks,
186
+ loaderMap,
187
+ locale,
188
+ defaultLocale,
189
+ context,
190
+ enabledLocales,
191
+ { schemas: core.blocksToSchemas(blocks), config }
192
+ );
193
+ return collectBlockData(layoutBlocks, resolved, isPreview);
194
+ }
195
+ function layoutSlotPage(slug) {
196
+ return { slug, path: slug.split("/").filter(Boolean) };
197
+ }
198
+ async function resolveCmssyLayoutSlot(config, options) {
199
+ const {
200
+ region,
201
+ blocks,
202
+ editMode,
203
+ preview = false,
204
+ page: explicitPage,
205
+ forms,
206
+ appContext,
207
+ path,
208
+ locale: explicitLocale,
209
+ retry,
210
+ fetch: fetchImpl
211
+ } = options;
212
+ const requestOptions = {
213
+ retry: retry ?? "build",
214
+ ...fetchImpl ? { fetch: fetchImpl } : {}
215
+ };
216
+ const siteLocales = await locale.resolveSiteLocales(config, requestOptions);
217
+ const fromPath = path ? locale.splitLocaleFromPath(path, siteLocales) : { locale: siteLocales.defaultLocale, path: [] };
218
+ const locale$1 = explicitLocale ?? fromPath.locale;
219
+ const slugSegments = fromPath.path ?? [];
220
+ const page = layoutSlotPage(explicitPage ?? "/" + slugSegments.join("/"));
221
+ const groups = await internal.fetchLayouts(config, page.slug, {
222
+ previewSecret: editMode || preview ? config.draftSecret : void 0,
223
+ ...requestOptions
224
+ });
225
+ const base = {
226
+ groups,
227
+ settings: groups.find((g) => g.region === region)?.settings ?? null,
228
+ page,
229
+ locale: locale$1,
230
+ defaultLocale: siteLocales.defaultLocale,
231
+ enabledLocales: siteLocales.locales,
232
+ path: slugSegments
233
+ };
234
+ if (!editMode) return base;
235
+ const editorData = await resolveEditorLayoutBlockData({
236
+ groups,
237
+ blocks,
238
+ region,
239
+ page,
240
+ locale: locale$1,
241
+ defaultLocale: siteLocales.defaultLocale,
242
+ enabledLocales: siteLocales.locales,
243
+ forms,
244
+ isPreview: true,
245
+ config,
246
+ appContext
247
+ });
248
+ return {
249
+ ...base,
250
+ data: editorData.data,
251
+ resolvedContent: editorData.content,
252
+ editorOrigin: core.resolveEditorOrigin(config.editorOrigin)
253
+ };
254
+ }
255
+
256
+ // src/components/load-cmssy-route.ts
257
+ function defineCmssyRouteConfig(config) {
258
+ const org = config.org?.trim() ?? "";
259
+ const workspaceSlug = config.workspaceSlug?.trim() ?? "";
260
+ const missing = [
261
+ ...org ? [] : ["org"],
262
+ ...workspaceSlug ? [] : ["workspaceSlug"]
263
+ ];
264
+ if (missing.length > 0) {
265
+ throw new Error(
266
+ `cmssy: defineCmssyRouteConfig is missing ${missing.join(" and ")}. Both name a public workspace, so a browser build can carry them - read them from import.meta.env if they differ per environment.`
267
+ );
268
+ }
269
+ if (typeof window !== "undefined") {
270
+ const carried = [
271
+ ...config.draftSecret === void 0 ? [] : ["draftSecret"],
272
+ ...config.devToken === void 0 ? [] : ["devToken"]
273
+ ];
274
+ if (carried.length > 0) {
275
+ throw new Error(
276
+ `cmssy: ${carried.join(" and ")} reached the browser. Anyone loading the page can read a value in the bundle: a draft secret opens every unpublished draft in the workspace, and a devToken is an API credential that writes to it. Keep both on a server build (@cmssy/next, @cmssy/astro or Vite SSR) and leave them out of a client-side config.`
277
+ );
278
+ }
279
+ }
280
+ return { ...config, org, workspaceSlug };
281
+ }
282
+ async function loadCmssyRoute(config, options) {
283
+ const {
284
+ blocks,
285
+ path,
286
+ locale,
287
+ forms,
288
+ appContext,
289
+ previewSecret,
290
+ isPreview = false,
291
+ retry,
292
+ fetch: fetchImpl
293
+ } = options;
294
+ const regions = options.regions ?? internal.layoutRegionIds(config.layout);
295
+ const firstRegion = regions[0] ?? "header";
296
+ const slot = await resolveCmssyLayoutSlot(config, {
297
+ region: firstRegion,
298
+ blocks,
299
+ editMode: false,
300
+ preview: isPreview,
301
+ forms,
302
+ appContext,
303
+ retry,
304
+ ...fetchImpl ? { fetch: fetchImpl } : {},
305
+ path: path ?? [],
306
+ ...locale === void 0 ? {} : { locale }
307
+ });
308
+ const secret = previewSecret ?? (isPreview ? config.draftSecret : void 0);
309
+ const page = await internal.fetchPage(config, slot.path, {
310
+ ...secret ? { previewSecret: secret } : {},
311
+ ...retry === void 0 ? {} : { retry },
312
+ ...fetchImpl ? { fetch: fetchImpl } : {}
313
+ });
314
+ const shared = {
315
+ blocks,
316
+ locale: slot.locale,
317
+ defaultLocale: slot.defaultLocale,
318
+ enabledLocales: slot.enabledLocales,
319
+ forms,
320
+ isPreview,
321
+ config,
322
+ appContext
323
+ };
324
+ const [pageBlocks, ...layoutBlocks] = await Promise.all([
325
+ resolveEditorBlockData({ ...shared, page }),
326
+ ...regions.map(
327
+ (region) => resolveEditorLayoutBlockData({
328
+ ...shared,
329
+ groups: slot.groups,
330
+ page: slot.page,
331
+ region
332
+ })
333
+ )
334
+ ]);
335
+ return {
336
+ page,
337
+ layouts: slot.groups,
338
+ pageContext: slot.page,
339
+ locale: slot.locale,
340
+ defaultLocale: slot.defaultLocale,
341
+ enabledLocales: slot.enabledLocales,
342
+ path: slot.path,
343
+ blockData: pageBlocks.data,
344
+ blockContent: pageBlocks.content,
345
+ layoutData: Object.fromEntries(
346
+ regions.map((region, index) => [region, layoutBlocks[index]])
347
+ ),
348
+ regions
349
+ };
350
+ }
351
+ var SOURCE_LABELS = {
352
+ loader: "loader failed",
353
+ render: "render failed",
354
+ unregistered: "type not registered"
355
+ };
356
+ var cardStyle = {
357
+ boxSizing: "border-box",
358
+ margin: "8px 0",
359
+ padding: "12px 16px",
360
+ border: "1px dashed #ef4444",
361
+ borderRadius: "8px",
362
+ background: "rgba(239, 68, 68, 0.08)",
363
+ color: "#ef4444",
364
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace",
365
+ fontSize: "13px",
366
+ lineHeight: 1.5,
367
+ textAlign: "left"
368
+ };
369
+ var headingStyle = {
370
+ fontWeight: 700,
371
+ marginBottom: "4px"
372
+ };
373
+ var metaStyle = {
374
+ opacity: 0.8,
375
+ marginBottom: "4px"
376
+ };
377
+ var messageStyle = {
378
+ whiteSpace: "pre-wrap",
379
+ overflowWrap: "anywhere"
380
+ };
381
+ function BlockErrorCard({
382
+ blockType,
383
+ blockId,
384
+ error
385
+ }) {
386
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "alert", "data-cmssy-block-error": error.source, style: cardStyle, children: [
387
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: headingStyle, children: [
388
+ 'Block "',
389
+ blockType,
390
+ '" - ',
391
+ SOURCE_LABELS[error.source]
392
+ ] }),
393
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: metaStyle, children: [
394
+ "id: ",
395
+ blockId
396
+ ] }),
397
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: messageStyle, children: error.message })
398
+ ] });
399
+ }
400
+ function foldBlockContent(block, locale, defaultLocale, patchedContent, resolvedContent) {
401
+ const base = resolvedContent ? { ...resolvedContent } : internal.getBlockContentForLanguage(block.content, locale, defaultLocale);
402
+ return patchedContent ? { ...base, ...patchedContent } : base;
403
+ }
404
+ var WARN_CAP = 256;
405
+ var warned = /* @__PURE__ */ new Set();
406
+ function UnknownBlock({ type }) {
407
+ if (typeof window !== "undefined" && !warned.has(type)) {
408
+ if (warned.size >= WARN_CAP) warned.clear();
409
+ warned.add(type);
410
+ console.error(`[cmssy] no component registered for block type "${type}"`);
411
+ }
412
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-cmssy-unknown-block": type });
413
+ }
414
+ function CmssyBlock({
415
+ block,
416
+ locale,
417
+ defaultLocale,
418
+ blockMap,
419
+ patchedContent,
420
+ patchedStyle,
421
+ patchedAdvanced,
422
+ resolvedContent,
423
+ schema,
424
+ editable,
425
+ editMode,
426
+ layoutRegion,
427
+ context,
428
+ data
429
+ }) {
430
+ const inEditMode = editMode ?? editable ?? false;
431
+ const Component = Object.hasOwn(blockMap, block.type) ? blockMap[block.type] : void 0;
432
+ const blockError = readBlockError(data);
433
+ const wrap = (children, hidden = false) => /* @__PURE__ */ jsxRuntime.jsx(
434
+ "div",
435
+ {
436
+ "data-block-id": block.id,
437
+ "data-block-type": block.type,
438
+ "data-layout-region": layoutRegion,
439
+ draggable: editable || void 0,
440
+ style: hidden ? { display: "none" } : void 0,
441
+ children
442
+ }
443
+ );
444
+ if (!Component) {
445
+ return inEditMode ? wrap(
446
+ /* @__PURE__ */ jsxRuntime.jsx(
447
+ BlockErrorCard,
448
+ {
449
+ blockType: block.type,
450
+ blockId: block.id,
451
+ error: unregisteredBlockError(block.type)
452
+ }
453
+ )
454
+ ) : wrap(/* @__PURE__ */ jsxRuntime.jsx(UnknownBlock, { type: block.type }), true);
455
+ }
456
+ if (blockError) {
457
+ if (!inEditMode) return null;
458
+ return wrap(
459
+ /* @__PURE__ */ jsxRuntime.jsx(
460
+ BlockErrorCard,
461
+ {
462
+ blockType: block.type,
463
+ blockId: block.id,
464
+ error: blockError
465
+ }
466
+ )
467
+ );
468
+ }
469
+ const content = foldBlockContent(
470
+ block,
471
+ locale,
472
+ defaultLocale,
473
+ patchedContent,
474
+ resolvedContent
475
+ );
476
+ if (schema) internal.normalizeBlockContent(content, schema, resolvedContent);
477
+ const style = patchedStyle ? { ...internal.asBucket(block.style), ...patchedStyle } : internal.asBucket(block.style);
478
+ const advanced = patchedAdvanced ? { ...internal.asBucket(block.advanced), ...patchedAdvanced } : internal.asBucket(block.advanced);
479
+ return wrap(
480
+ /* @__PURE__ */ jsxRuntime.jsx(
481
+ blockErrorBoundary.BlockErrorBoundary,
482
+ {
483
+ blockType: block.type,
484
+ blockId: block.id,
485
+ editMode: inEditMode,
486
+ children: react.createElement(Component, {
487
+ content,
488
+ style,
489
+ advanced,
490
+ context,
491
+ data
492
+ })
493
+ }
494
+ )
495
+ );
496
+ }
497
+ function CmssyBlocks({
498
+ page,
499
+ blocks,
500
+ locale,
501
+ defaultLocale,
502
+ enabledLocales,
503
+ blockData,
504
+ blockContent,
505
+ pageContext,
506
+ forms,
507
+ auth,
508
+ workspace,
509
+ appContext,
510
+ isPreview = false,
511
+ editMode = false
512
+ }) {
513
+ if (!page) return null;
514
+ const blockMap = buildBlockMap(blocks);
515
+ const context = internal.buildBlockContext(
516
+ locale,
517
+ defaultLocale,
518
+ enabledLocales,
519
+ isPreview,
520
+ forms,
521
+ { page: pageContext, auth, workspace, app: appContext }
522
+ );
523
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: (page.blocks ?? []).map((block) => /* @__PURE__ */ jsxRuntime.jsx(
524
+ CmssyBlock,
525
+ {
526
+ block,
527
+ blockMap,
528
+ locale,
529
+ defaultLocale,
530
+ context,
531
+ editMode,
532
+ resolvedContent: blockContent?.[block.id],
533
+ data: blockData?.[block.id]
534
+ },
535
+ block.id
536
+ )) });
537
+ }
538
+ function CmssyLayoutRegion({
539
+ groups,
540
+ region,
541
+ blocks,
542
+ locale,
543
+ defaultLocale,
544
+ enabledLocales,
545
+ page,
546
+ blockData,
547
+ blockContent,
548
+ forms,
549
+ appContext,
550
+ isPreview = false,
551
+ editMode = false
552
+ }) {
553
+ const group = groups.find((candidate) => candidate.region === region);
554
+ const regionBlocks = group ? group.blocks.filter((block) => block.isActive !== false).slice().sort((a, b) => (a.order ?? 0) - (b.order ?? 0)) : [];
555
+ if (regionBlocks.length === 0) return null;
556
+ const blockMap = buildBlockMap(blocks);
557
+ const context = internal.buildBlockContext(
558
+ locale,
559
+ defaultLocale,
560
+ enabledLocales,
561
+ isPreview,
562
+ forms,
563
+ { page, app: appContext }
564
+ );
565
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: regionBlocks.map((block) => /* @__PURE__ */ jsxRuntime.jsx(
566
+ CmssyBlock,
567
+ {
568
+ block,
569
+ blockMap,
570
+ locale,
571
+ defaultLocale,
572
+ context,
573
+ layoutRegion: region,
574
+ editMode,
575
+ resolvedContent: blockContent?.[block.id],
576
+ data: blockData?.[block.id]
577
+ },
578
+ block.id
579
+ )) });
580
+ }
581
+ function toSegments(path) {
582
+ if (Array.isArray(path)) return path;
583
+ const value = path ?? (typeof window === "undefined" ? "/" : window.location.pathname);
584
+ return value.split("/").filter(Boolean);
585
+ }
586
+ function useCmssyRoute(config, options) {
587
+ const segments = react.useMemo(() => toSegments(options.path), [options.path]);
588
+ const [state, setState] = react.useState({ data: null, error: null, loading: true });
589
+ const [attempt, setAttempt] = react.useState(0);
590
+ const latest = react.useRef(0);
591
+ const optionsRef = react.useRef(options);
592
+ optionsRef.current = options;
593
+ react.useEffect(() => {
594
+ const request = ++latest.current;
595
+ setState((current) => ({ ...current, error: null, loading: true }));
596
+ loadCmssyRoute(config, { ...optionsRef.current, path: segments }).then((data) => {
597
+ if (request !== latest.current) return;
598
+ setState({ data, error: null, loading: false });
599
+ }).catch((cause) => {
600
+ if (request !== latest.current) return;
601
+ setState({
602
+ data: null,
603
+ error: cause instanceof Error ? cause : new Error(String(cause)),
604
+ loading: false
605
+ });
606
+ });
607
+ }, [
608
+ config,
609
+ segments.join("/"),
610
+ options.locale,
611
+ options.previewSecret,
612
+ options.isPreview,
613
+ options.regions?.join(","),
614
+ attempt
615
+ ]);
616
+ const reload = react.useCallback(() => setAttempt((value) => value + 1), []);
617
+ return { ...state, reload };
618
+ }
619
+ function CmssyRoute({
620
+ config,
621
+ children,
622
+ fallback = null,
623
+ notFound = null,
624
+ renderError,
625
+ ...options
626
+ }) {
627
+ const { data, error, loading } = useCmssyRoute(config, options);
628
+ if (error) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderError ? renderError(error) : null });
629
+ if (!data) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: loading ? fallback : null });
630
+ const shared = {
631
+ blocks: options.blocks,
632
+ locale: data.locale,
633
+ defaultLocale: data.defaultLocale,
634
+ enabledLocales: data.enabledLocales,
635
+ forms: options.forms,
636
+ appContext: options.appContext,
637
+ isPreview: options.isPreview ?? false
638
+ };
639
+ const Blocks = () => data.page ? /* @__PURE__ */ jsxRuntime.jsx(
640
+ CmssyBlocks,
641
+ {
642
+ ...shared,
643
+ page: data.page,
644
+ pageContext: data.pageContext,
645
+ blockData: data.blockData,
646
+ blockContent: data.blockContent
647
+ }
648
+ ) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: notFound });
649
+ const Region = ({ id }) => /* @__PURE__ */ jsxRuntime.jsx(
650
+ CmssyLayoutRegion,
651
+ {
652
+ ...shared,
653
+ groups: data.layouts,
654
+ region: id,
655
+ page: data.pageContext,
656
+ blockData: data.layoutData[id]?.data,
657
+ blockContent: data.layoutData[id]?.content
658
+ }
659
+ );
660
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children({ data, Blocks, Region }) });
661
+ }
662
+
663
+ exports.CmssyRoute = CmssyRoute;
664
+ exports.defineCmssyRouteConfig = defineCmssyRouteConfig;
665
+ exports.useCmssyRoute = useCmssyRoute;
package/dist/spa.d.cts ADDED
@@ -0,0 +1,34 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { L as LoadCmssyRouteOptions, C as CmssyRouteConfig, a as CmssyRouteData } from './load-cmssy-route-DsAVTbis.cjs';
4
+ export { d as defineCmssyRouteConfig } from './load-cmssy-route-DsAVTbis.cjs';
5
+ import '@cmssy/core';
6
+ import './resolve-block-data-Bkracpae.cjs';
7
+
8
+ interface UseCmssyRouteOptions extends Omit<LoadCmssyRouteOptions, "path"> {
9
+ path?: string | string[];
10
+ }
11
+ interface CmssyRouteState {
12
+ data: CmssyRouteData | null;
13
+ error: Error | null;
14
+ loading: boolean;
15
+ reload: () => void;
16
+ }
17
+ declare function useCmssyRoute(config: CmssyRouteConfig, options: UseCmssyRouteOptions): CmssyRouteState;
18
+ interface CmssyRouteRenderProps {
19
+ data: CmssyRouteData;
20
+ Blocks: () => ReactNode;
21
+ Region: (props: {
22
+ id: string;
23
+ }) => ReactNode;
24
+ }
25
+ interface CmssyRouteProps extends UseCmssyRouteOptions {
26
+ config: CmssyRouteConfig;
27
+ children: (props: CmssyRouteRenderProps) => ReactNode;
28
+ fallback?: ReactNode;
29
+ notFound?: ReactNode;
30
+ renderError?: (error: Error) => ReactNode;
31
+ }
32
+ declare function CmssyRoute({ config, children, fallback, notFound, renderError, ...options }: CmssyRouteProps): react_jsx_runtime.JSX.Element;
33
+
34
+ export { CmssyRoute, CmssyRouteConfig, CmssyRouteData, type CmssyRouteProps, type CmssyRouteRenderProps, type CmssyRouteState, type UseCmssyRouteOptions, useCmssyRoute };