@cmssy/remix 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/index.cjs CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  var core = require('@cmssy/core');
4
4
  var internal = require('@cmssy/core/internal');
5
+ var react = require('@cmssy/react');
5
6
 
6
7
  // src/loader.ts
7
- function createCmssyLoader(config) {
8
+ function createCmssyLoader(config, options = {}) {
8
9
  return async function cmssyLoader({
9
10
  request
10
11
  }) {
@@ -30,23 +31,55 @@ function createCmssyLoader(config) {
30
31
  diagnostics: renderEditDiagnostics(diagnosed)
31
32
  };
32
33
  }
33
- const siteLocales = await internal.resolveSiteLocales(config);
34
34
  const segments = url.pathname.split("/").filter(Boolean);
35
- const fromPath = internal.splitLocaleFromPath(segments, siteLocales);
36
- const locale = request.headers.get(internal.CMSSY_LOCALE_HEADER) ?? fromPath.locale;
37
- const previewSecret = isEdit ? config.draftSecret : void 0;
38
- const [page, layouts] = await Promise.all([
39
- internal.fetchPage(config, fromPath.path, { previewSecret }),
40
- internal.fetchLayouts(config, fromPath.path, { previewSecret })
41
- ]);
35
+ const positions = options.positions ?? ["header", "footer"];
36
+ const blocks = options.blocks ?? [];
37
+ const headerLocale = request.headers.get(internal.CMSSY_LOCALE_HEADER) ?? void 0;
38
+ const slot = await react.resolveCmssyLayoutSlot(config, {
39
+ position: positions[0] ?? "header",
40
+ blocks,
41
+ editMode: isEdit,
42
+ path: segments,
43
+ locale: headerLocale,
44
+ appContext: options.appContext
45
+ });
46
+ const page = await internal.fetchPage(config, slot.path, {
47
+ previewSecret: isEdit ? config.draftSecret : void 0
48
+ });
49
+ let editorData;
50
+ if (isEdit && slot.data && slot.resolvedContent) {
51
+ editorData = {
52
+ [positions[0] ?? "header"]: {
53
+ data: slot.data,
54
+ resolvedContent: slot.resolvedContent
55
+ }
56
+ };
57
+ for (const position of positions.slice(1)) {
58
+ const extra = await react.resolveCmssyLayoutSlot(config, {
59
+ position,
60
+ blocks,
61
+ editMode: true,
62
+ path: segments,
63
+ locale: headerLocale,
64
+ appContext: options.appContext
65
+ });
66
+ if (extra.data && extra.resolvedContent) {
67
+ editorData[position] = {
68
+ data: extra.data,
69
+ resolvedContent: extra.resolvedContent
70
+ };
71
+ }
72
+ }
73
+ }
42
74
  return {
43
75
  page,
44
- layouts,
45
- locale,
46
- defaultLocale: siteLocales.defaultLocale,
47
- enabledLocales: siteLocales.locales,
76
+ layouts: slot.groups,
77
+ locale: slot.locale,
78
+ defaultLocale: slot.defaultLocale,
79
+ enabledLocales: slot.enabledLocales,
48
80
  isEdit,
49
- editorOrigin: config.editorOrigin ?? "*"
81
+ editorOrigin: config.editorOrigin ?? "*",
82
+ editorData
50
83
  };
51
84
  };
52
85
  }
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { CmssyPageData, CmssyLayoutGroup, CmssyConfig } from '@cmssy/core';
2
2
  export { CMSSY_LOCALE_HEADER, CmssyBlockContext, CmssyConfig, CmssyEnvConfig, CmssyLayoutGroup, CmssyPageData, createCmssyClient, defineCmssyConfig, isVerifiedEditUrl, localizeHref } from '@cmssy/core';
3
+ import { BlockDefinition } from '@cmssy/react';
3
4
 
4
5
  interface CmssyRouteData {
5
6
  page: CmssyPageData | null;
@@ -11,6 +12,27 @@ interface CmssyRouteData {
11
12
  isEdit: boolean;
12
13
  editorOrigin: string | string[];
13
14
  diagnostics?: string;
15
+ /**
16
+ * Edit mode only, and only when `blocks` was passed: what the canvas needs,
17
+ * **keyed by position**. The header and the footer hold different blocks and
18
+ * resolve to different data - handing the footer the header's is the quiet
19
+ * version of this bug.
20
+ */
21
+ editorData?: Record<string, CmssyLayoutEditorData>;
22
+ }
23
+ interface CmssyLayoutEditorData {
24
+ data: Record<string, unknown>;
25
+ resolvedContent: Record<string, Record<string, unknown>>;
26
+ }
27
+ interface CreateCmssyLoaderOptions {
28
+ /**
29
+ * The block registry. Required to resolve the editor's layout data; omit it
30
+ * and the layouts still render, but the editor cannot fill them.
31
+ */
32
+ blocks?: BlockDefinition[];
33
+ /** Which positions the editor renders. Defaults to the header and footer. */
34
+ positions?: string[];
35
+ appContext?: Record<string, unknown>;
14
36
  }
15
37
  /**
16
38
  * The page loader.
@@ -21,7 +43,7 @@ interface CmssyRouteData {
21
43
  * request, so the editor can be served from the page itself - verified the same
22
44
  * way, on the same protocol, with less machinery.
23
45
  */
24
- declare function createCmssyLoader(config: CmssyConfig): ({ request, }: {
46
+ declare function createCmssyLoader(config: CmssyConfig, options?: CreateCmssyLoaderOptions): ({ request, }: {
25
47
  request: Request;
26
48
  }) => Promise<CmssyRouteData>;
27
49
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { CmssyPageData, CmssyLayoutGroup, CmssyConfig } from '@cmssy/core';
2
2
  export { CMSSY_LOCALE_HEADER, CmssyBlockContext, CmssyConfig, CmssyEnvConfig, CmssyLayoutGroup, CmssyPageData, createCmssyClient, defineCmssyConfig, isVerifiedEditUrl, localizeHref } from '@cmssy/core';
3
+ import { BlockDefinition } from '@cmssy/react';
3
4
 
4
5
  interface CmssyRouteData {
5
6
  page: CmssyPageData | null;
@@ -11,6 +12,27 @@ interface CmssyRouteData {
11
12
  isEdit: boolean;
12
13
  editorOrigin: string | string[];
13
14
  diagnostics?: string;
15
+ /**
16
+ * Edit mode only, and only when `blocks` was passed: what the canvas needs,
17
+ * **keyed by position**. The header and the footer hold different blocks and
18
+ * resolve to different data - handing the footer the header's is the quiet
19
+ * version of this bug.
20
+ */
21
+ editorData?: Record<string, CmssyLayoutEditorData>;
22
+ }
23
+ interface CmssyLayoutEditorData {
24
+ data: Record<string, unknown>;
25
+ resolvedContent: Record<string, Record<string, unknown>>;
26
+ }
27
+ interface CreateCmssyLoaderOptions {
28
+ /**
29
+ * The block registry. Required to resolve the editor's layout data; omit it
30
+ * and the layouts still render, but the editor cannot fill them.
31
+ */
32
+ blocks?: BlockDefinition[];
33
+ /** Which positions the editor renders. Defaults to the header and footer. */
34
+ positions?: string[];
35
+ appContext?: Record<string, unknown>;
14
36
  }
15
37
  /**
16
38
  * The page loader.
@@ -21,7 +43,7 @@ interface CmssyRouteData {
21
43
  * request, so the editor can be served from the page itself - verified the same
22
44
  * way, on the same protocol, with less machinery.
23
45
  */
24
- declare function createCmssyLoader(config: CmssyConfig): ({ request, }: {
46
+ declare function createCmssyLoader(config: CmssyConfig, options?: CreateCmssyLoaderOptions): ({ request, }: {
25
47
  request: Request;
26
48
  }) => Promise<CmssyRouteData>;
27
49
  /**
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { isVerifiedEditUrl, CMSSY_EDIT_QUERY_PARAM, CMSSY_SECRET_QUERY_PARAM } from '@cmssy/core';
2
2
  export { CMSSY_LOCALE_HEADER, createCmssyClient, defineCmssyConfig, isVerifiedEditUrl, localizeHref } from '@cmssy/core';
3
- import { isDevelopment, resolveSiteLocales, splitLocaleFromPath, CMSSY_LOCALE_HEADER, fetchPage, fetchLayouts, cmssyCspHeaders } from '@cmssy/core/internal';
3
+ import { isDevelopment, resolveSiteLocales, CMSSY_LOCALE_HEADER, fetchPage, cmssyCspHeaders } from '@cmssy/core/internal';
4
+ import { resolveCmssyLayoutSlot } from '@cmssy/react';
4
5
 
5
6
  // src/loader.ts
6
- function createCmssyLoader(config) {
7
+ function createCmssyLoader(config, options = {}) {
7
8
  return async function cmssyLoader({
8
9
  request
9
10
  }) {
@@ -29,23 +30,55 @@ function createCmssyLoader(config) {
29
30
  diagnostics: renderEditDiagnostics(diagnosed)
30
31
  };
31
32
  }
32
- const siteLocales = await resolveSiteLocales(config);
33
33
  const segments = url.pathname.split("/").filter(Boolean);
34
- const fromPath = splitLocaleFromPath(segments, siteLocales);
35
- const locale = request.headers.get(CMSSY_LOCALE_HEADER) ?? fromPath.locale;
36
- const previewSecret = isEdit ? config.draftSecret : void 0;
37
- const [page, layouts] = await Promise.all([
38
- fetchPage(config, fromPath.path, { previewSecret }),
39
- fetchLayouts(config, fromPath.path, { previewSecret })
40
- ]);
34
+ const positions = options.positions ?? ["header", "footer"];
35
+ const blocks = options.blocks ?? [];
36
+ const headerLocale = request.headers.get(CMSSY_LOCALE_HEADER) ?? void 0;
37
+ const slot = await resolveCmssyLayoutSlot(config, {
38
+ position: positions[0] ?? "header",
39
+ blocks,
40
+ editMode: isEdit,
41
+ path: segments,
42
+ locale: headerLocale,
43
+ appContext: options.appContext
44
+ });
45
+ const page = await fetchPage(config, slot.path, {
46
+ previewSecret: isEdit ? config.draftSecret : void 0
47
+ });
48
+ let editorData;
49
+ if (isEdit && slot.data && slot.resolvedContent) {
50
+ editorData = {
51
+ [positions[0] ?? "header"]: {
52
+ data: slot.data,
53
+ resolvedContent: slot.resolvedContent
54
+ }
55
+ };
56
+ for (const position of positions.slice(1)) {
57
+ const extra = await resolveCmssyLayoutSlot(config, {
58
+ position,
59
+ blocks,
60
+ editMode: true,
61
+ path: segments,
62
+ locale: headerLocale,
63
+ appContext: options.appContext
64
+ });
65
+ if (extra.data && extra.resolvedContent) {
66
+ editorData[position] = {
67
+ data: extra.data,
68
+ resolvedContent: extra.resolvedContent
69
+ };
70
+ }
71
+ }
72
+ }
41
73
  return {
42
74
  page,
43
- layouts,
44
- locale,
45
- defaultLocale: siteLocales.defaultLocale,
46
- enabledLocales: siteLocales.locales,
75
+ layouts: slot.groups,
76
+ locale: slot.locale,
77
+ defaultLocale: slot.defaultLocale,
78
+ enabledLocales: slot.enabledLocales,
47
79
  isEdit,
48
- editorOrigin: config.editorOrigin ?? "*"
80
+ editorOrigin: config.editorOrigin ?? "*",
81
+ editorData
49
82
  };
50
83
  };
51
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/remix",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "description": "React Router 7 bindings for cmssy headless sites: page loader, framing CSP, sitemap and robots.",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -39,16 +39,18 @@
39
39
  "dist"
40
40
  ],
41
41
  "peerDependencies": {
42
- "react-router": ">=7"
42
+ "react-router": ">=7",
43
+ "@cmssy/react": "^11.1.0"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@types/node": "^20.0.0",
46
47
  "tsup": "^8.3.0",
47
48
  "typescript": "^5.6.0",
48
- "vitest": "^2.1.0"
49
+ "vitest": "^2.1.0",
50
+ "@cmssy/react": "11.1.0"
49
51
  },
50
52
  "dependencies": {
51
- "@cmssy/core": "11.0.0"
53
+ "@cmssy/core": "11.1.0"
52
54
  },
53
55
  "scripts": {
54
56
  "build": "tsup",