@cmssy/next 0.1.5 → 0.1.7

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
@@ -67,7 +67,6 @@ function createCmssyPage(config, blocks, options) {
67
67
  apiUrl: config.apiUrl,
68
68
  workspaceSlug: config.workspaceSlug
69
69
  };
70
- const defaultLocale = config.defaultLocale ?? "en";
71
70
  return async function CmssyCatchAllPage({
72
71
  params,
73
72
  searchParams
@@ -76,19 +75,41 @@ function createCmssyPage(config, blocks, options) {
76
75
  const { isEnabled } = await headers.draftMode();
77
76
  const query = searchParams ? await searchParams : {};
78
77
  const editMode = isEnabled || hasEditFlag(query[EDIT_QUERY_PARAM]);
79
- const locale = config.resolveLocale ? await config.resolveLocale() : defaultLocale;
80
- const page = await react.fetchPage(clientConfig, path, {
78
+ let locale;
79
+ let pagePath = path;
80
+ let defaultLocale;
81
+ let enabledLocales = config.enabledLocales;
82
+ if (config.resolveLocale) {
83
+ defaultLocale = config.defaultLocale ?? "en";
84
+ locale = await config.resolveLocale();
85
+ } else {
86
+ const siteLocales = await react.resolveSiteLocales(clientConfig);
87
+ defaultLocale = config.defaultLocale ?? siteLocales.defaultLocale;
88
+ const locales = config.enabledLocales ?? siteLocales.locales;
89
+ enabledLocales = locales;
90
+ const split = react.splitLocaleFromPath(path, { defaultLocale, locales });
91
+ locale = split.locale;
92
+ pagePath = split.path;
93
+ }
94
+ const page = await react.fetchPage(clientConfig, pagePath, {
81
95
  previewSecret: editMode ? config.draftSecret : void 0
82
96
  });
83
97
  if (!page) {
84
98
  navigation.notFound();
85
99
  }
86
- if (editMode) {
87
- if (!Editor) {
88
- throw new Error(
89
- 'cmssy: edit mode requires options.editor \u2014 pass a "use client" editor that imports your blocks and renders <CmssyEditablePage blocks={blocks} \u2026 />'
90
- );
91
- }
100
+ if (editMode && !Editor) {
101
+ throw new Error(
102
+ 'cmssy: edit mode requires options.editor \u2014 pass a "use client" editor that imports your blocks and renders <CmssyEditablePage blocks={blocks} \u2026 />'
103
+ );
104
+ }
105
+ const resolvedForms = await react.resolveForms(
106
+ clientConfig,
107
+ page.blocks,
108
+ locale,
109
+ defaultLocale
110
+ );
111
+ const forms = Object.keys(resolvedForms).length > 0 ? resolvedForms : void 0;
112
+ if (editMode && Editor) {
92
113
  const bridgeOrigin = resolveBridgeOrigin(config.editorOrigin);
93
114
  return /* @__PURE__ */ jsxRuntime.jsx(
94
115
  Editor,
@@ -96,8 +117,9 @@ function createCmssyPage(config, blocks, options) {
96
117
  page,
97
118
  locale,
98
119
  defaultLocale,
99
- enabledLocales: config.enabledLocales,
100
- edit: { editorOrigin: bridgeOrigin }
120
+ enabledLocales,
121
+ edit: { editorOrigin: bridgeOrigin },
122
+ forms
101
123
  }
102
124
  );
103
125
  }
@@ -108,7 +130,8 @@ function createCmssyPage(config, blocks, options) {
108
130
  blocks,
109
131
  locale,
110
132
  defaultLocale,
111
- enabledLocales: config.enabledLocales
133
+ enabledLocales,
134
+ forms
112
135
  }
113
136
  );
114
137
  };
@@ -185,11 +208,33 @@ async function isCmssyEditMode() {
185
208
  const h = await headers.headers();
186
209
  return h.get(CMSSY_EDIT_HEADER) === "1";
187
210
  }
211
+ var CMSSY_LOCALE_HEADER = "x-cmssy-locale";
212
+ async function localeForPathname(config, pathname) {
213
+ const siteLocales = await react.resolveSiteLocales(config);
214
+ const segments = pathname.split("/").filter(Boolean);
215
+ return react.splitLocaleFromPath(segments, siteLocales).locale;
216
+ }
217
+ async function splitCmssyLocale(config, path) {
218
+ const siteLocales = await react.resolveSiteLocales(config);
219
+ return react.splitLocaleFromPath(path, siteLocales);
220
+ }
221
+ async function getCmssyLocale(config) {
222
+ const { headers: headers2 } = await import('next/headers');
223
+ const headerList = await headers2();
224
+ const fromHeader = headerList.get(CMSSY_LOCALE_HEADER);
225
+ if (fromHeader) return fromHeader;
226
+ const { defaultLocale } = await react.resolveSiteLocales(config);
227
+ return defaultLocale;
228
+ }
188
229
 
189
230
  exports.CMSSY_EDIT_HEADER = CMSSY_EDIT_HEADER;
231
+ exports.CMSSY_LOCALE_HEADER = CMSSY_LOCALE_HEADER;
190
232
  exports.applyCmssyCsp = applyCmssyCsp;
191
233
  exports.cmssyCspHeaders = cmssyCspHeaders;
192
234
  exports.createCmssyPage = createCmssyPage;
193
235
  exports.createDraftRoute = createDraftRoute;
236
+ exports.getCmssyLocale = getCmssyLocale;
194
237
  exports.isCmssyEditMode = isCmssyEditMode;
195
238
  exports.isCmssyEditRequest = isCmssyEditRequest;
239
+ exports.localeForPathname = localeForPathname;
240
+ exports.splitCmssyLocale = splitCmssyLocale;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ComponentType } from 'react';
3
- import { CmssyPageData, BlockDefinition } from '@cmssy/react';
3
+ import { CmssyPageData, CmssyFormDefinition, BlockDefinition, CmssyClientConfig } from '@cmssy/react';
4
4
  import { EditBridgeConfig } from '@cmssy/react/client';
5
5
 
6
6
  interface CmssyNextConfig {
@@ -20,6 +20,7 @@ interface CmssyEditorProps {
20
20
  defaultLocale: string;
21
21
  enabledLocales?: string[];
22
22
  edit: EditBridgeConfig;
23
+ forms?: Record<string, CmssyFormDefinition>;
23
24
  }
24
25
  interface CreateCmssyPageOptions {
25
26
  editor?: ComponentType<CmssyEditorProps>;
@@ -66,4 +67,12 @@ interface EditRequestLike {
66
67
  declare function isCmssyEditRequest(request: EditRequestLike): boolean;
67
68
  declare function isCmssyEditMode(): Promise<boolean>;
68
69
 
69
- export { CMSSY_EDIT_HEADER, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CreateCmssyPageOptions, applyCmssyCsp, cmssyCspHeaders, createCmssyPage, createDraftRoute, isCmssyEditMode, isCmssyEditRequest };
70
+ declare const CMSSY_LOCALE_HEADER = "x-cmssy-locale";
71
+ declare function localeForPathname(config: CmssyClientConfig, pathname: string): Promise<string>;
72
+ declare function splitCmssyLocale(config: CmssyClientConfig, path: string[] | undefined): Promise<{
73
+ locale: string;
74
+ path: string[] | undefined;
75
+ }>;
76
+ declare function getCmssyLocale(config: CmssyClientConfig): Promise<string>;
77
+
78
+ export { CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CreateCmssyPageOptions, applyCmssyCsp, cmssyCspHeaders, createCmssyPage, createDraftRoute, getCmssyLocale, isCmssyEditMode, isCmssyEditRequest, localeForPathname, splitCmssyLocale };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ComponentType } from 'react';
3
- import { CmssyPageData, BlockDefinition } from '@cmssy/react';
3
+ import { CmssyPageData, CmssyFormDefinition, BlockDefinition, CmssyClientConfig } from '@cmssy/react';
4
4
  import { EditBridgeConfig } from '@cmssy/react/client';
5
5
 
6
6
  interface CmssyNextConfig {
@@ -20,6 +20,7 @@ interface CmssyEditorProps {
20
20
  defaultLocale: string;
21
21
  enabledLocales?: string[];
22
22
  edit: EditBridgeConfig;
23
+ forms?: Record<string, CmssyFormDefinition>;
23
24
  }
24
25
  interface CreateCmssyPageOptions {
25
26
  editor?: ComponentType<CmssyEditorProps>;
@@ -66,4 +67,12 @@ interface EditRequestLike {
66
67
  declare function isCmssyEditRequest(request: EditRequestLike): boolean;
67
68
  declare function isCmssyEditMode(): Promise<boolean>;
68
69
 
69
- export { CMSSY_EDIT_HEADER, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CreateCmssyPageOptions, applyCmssyCsp, cmssyCspHeaders, createCmssyPage, createDraftRoute, isCmssyEditMode, isCmssyEditRequest };
70
+ declare const CMSSY_LOCALE_HEADER = "x-cmssy-locale";
71
+ declare function localeForPathname(config: CmssyClientConfig, pathname: string): Promise<string>;
72
+ declare function splitCmssyLocale(config: CmssyClientConfig, path: string[] | undefined): Promise<{
73
+ locale: string;
74
+ path: string[] | undefined;
75
+ }>;
76
+ declare function getCmssyLocale(config: CmssyClientConfig): Promise<string>;
77
+
78
+ export { CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CreateCmssyPageOptions, applyCmssyCsp, cmssyCspHeaders, createCmssyPage, createDraftRoute, getCmssyLocale, isCmssyEditMode, isCmssyEditRequest, localeForPathname, splitCmssyLocale };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { draftMode, headers } from 'next/headers';
2
2
  import { notFound, redirect } from 'next/navigation';
3
- import { fetchPage, CmssyServerPage } from '@cmssy/react';
3
+ import { resolveSiteLocales, splitLocaleFromPath, fetchPage, resolveForms, CmssyServerPage } from '@cmssy/react';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
  import { createHash, timingSafeEqual } from 'crypto';
6
6
 
@@ -65,7 +65,6 @@ function createCmssyPage(config, blocks, options) {
65
65
  apiUrl: config.apiUrl,
66
66
  workspaceSlug: config.workspaceSlug
67
67
  };
68
- const defaultLocale = config.defaultLocale ?? "en";
69
68
  return async function CmssyCatchAllPage({
70
69
  params,
71
70
  searchParams
@@ -74,19 +73,41 @@ function createCmssyPage(config, blocks, options) {
74
73
  const { isEnabled } = await draftMode();
75
74
  const query = searchParams ? await searchParams : {};
76
75
  const editMode = isEnabled || hasEditFlag(query[EDIT_QUERY_PARAM]);
77
- const locale = config.resolveLocale ? await config.resolveLocale() : defaultLocale;
78
- const page = await fetchPage(clientConfig, path, {
76
+ let locale;
77
+ let pagePath = path;
78
+ let defaultLocale;
79
+ let enabledLocales = config.enabledLocales;
80
+ if (config.resolveLocale) {
81
+ defaultLocale = config.defaultLocale ?? "en";
82
+ locale = await config.resolveLocale();
83
+ } else {
84
+ const siteLocales = await resolveSiteLocales(clientConfig);
85
+ defaultLocale = config.defaultLocale ?? siteLocales.defaultLocale;
86
+ const locales = config.enabledLocales ?? siteLocales.locales;
87
+ enabledLocales = locales;
88
+ const split = splitLocaleFromPath(path, { defaultLocale, locales });
89
+ locale = split.locale;
90
+ pagePath = split.path;
91
+ }
92
+ const page = await fetchPage(clientConfig, pagePath, {
79
93
  previewSecret: editMode ? config.draftSecret : void 0
80
94
  });
81
95
  if (!page) {
82
96
  notFound();
83
97
  }
84
- if (editMode) {
85
- if (!Editor) {
86
- throw new Error(
87
- 'cmssy: edit mode requires options.editor \u2014 pass a "use client" editor that imports your blocks and renders <CmssyEditablePage blocks={blocks} \u2026 />'
88
- );
89
- }
98
+ if (editMode && !Editor) {
99
+ throw new Error(
100
+ 'cmssy: edit mode requires options.editor \u2014 pass a "use client" editor that imports your blocks and renders <CmssyEditablePage blocks={blocks} \u2026 />'
101
+ );
102
+ }
103
+ const resolvedForms = await resolveForms(
104
+ clientConfig,
105
+ page.blocks,
106
+ locale,
107
+ defaultLocale
108
+ );
109
+ const forms = Object.keys(resolvedForms).length > 0 ? resolvedForms : void 0;
110
+ if (editMode && Editor) {
90
111
  const bridgeOrigin = resolveBridgeOrigin(config.editorOrigin);
91
112
  return /* @__PURE__ */ jsx(
92
113
  Editor,
@@ -94,8 +115,9 @@ function createCmssyPage(config, blocks, options) {
94
115
  page,
95
116
  locale,
96
117
  defaultLocale,
97
- enabledLocales: config.enabledLocales,
98
- edit: { editorOrigin: bridgeOrigin }
118
+ enabledLocales,
119
+ edit: { editorOrigin: bridgeOrigin },
120
+ forms
99
121
  }
100
122
  );
101
123
  }
@@ -106,7 +128,8 @@ function createCmssyPage(config, blocks, options) {
106
128
  blocks,
107
129
  locale,
108
130
  defaultLocale,
109
- enabledLocales: config.enabledLocales
131
+ enabledLocales,
132
+ forms
110
133
  }
111
134
  );
112
135
  };
@@ -183,5 +206,23 @@ async function isCmssyEditMode() {
183
206
  const h = await headers();
184
207
  return h.get(CMSSY_EDIT_HEADER) === "1";
185
208
  }
209
+ var CMSSY_LOCALE_HEADER = "x-cmssy-locale";
210
+ async function localeForPathname(config, pathname) {
211
+ const siteLocales = await resolveSiteLocales(config);
212
+ const segments = pathname.split("/").filter(Boolean);
213
+ return splitLocaleFromPath(segments, siteLocales).locale;
214
+ }
215
+ async function splitCmssyLocale(config, path) {
216
+ const siteLocales = await resolveSiteLocales(config);
217
+ return splitLocaleFromPath(path, siteLocales);
218
+ }
219
+ async function getCmssyLocale(config) {
220
+ const { headers: headers2 } = await import('next/headers');
221
+ const headerList = await headers2();
222
+ const fromHeader = headerList.get(CMSSY_LOCALE_HEADER);
223
+ if (fromHeader) return fromHeader;
224
+ const { defaultLocale } = await resolveSiteLocales(config);
225
+ return defaultLocale;
226
+ }
186
227
 
187
- export { CMSSY_EDIT_HEADER, applyCmssyCsp, cmssyCspHeaders, createCmssyPage, createDraftRoute, isCmssyEditMode, isCmssyEditRequest };
228
+ export { CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, applyCmssyCsp, cmssyCspHeaders, createCmssyPage, createDraftRoute, getCmssyLocale, isCmssyEditMode, isCmssyEditRequest, localeForPathname, splitCmssyLocale };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/next",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -36,7 +36,7 @@
36
36
  "dist"
37
37
  ],
38
38
  "peerDependencies": {
39
- "@cmssy/react": "^0.1.5",
39
+ "@cmssy/react": "^0.1.7",
40
40
  "next": ">=15",
41
41
  "react": "^18.2.0 || ^19.0.0",
42
42
  "react-dom": "^18.2.0 || ^19.0.0"
@@ -49,7 +49,7 @@
49
49
  "tsup": "^8.3.0",
50
50
  "typescript": "^5.6.0",
51
51
  "vitest": "^2.1.0",
52
- "@cmssy/react": "0.1.5"
52
+ "@cmssy/react": "0.1.7"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsup",