@cmssy/next 0.1.6 → 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 +41 -5
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +39 -7
- package/package.json +3 -3
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,8 +75,23 @@ 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
|
-
|
|
80
|
-
|
|
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) {
|
|
@@ -103,7 +117,7 @@ function createCmssyPage(config, blocks, options) {
|
|
|
103
117
|
page,
|
|
104
118
|
locale,
|
|
105
119
|
defaultLocale,
|
|
106
|
-
enabledLocales
|
|
120
|
+
enabledLocales,
|
|
107
121
|
edit: { editorOrigin: bridgeOrigin },
|
|
108
122
|
forms
|
|
109
123
|
}
|
|
@@ -116,7 +130,7 @@ function createCmssyPage(config, blocks, options) {
|
|
|
116
130
|
blocks,
|
|
117
131
|
locale,
|
|
118
132
|
defaultLocale,
|
|
119
|
-
enabledLocales
|
|
133
|
+
enabledLocales,
|
|
120
134
|
forms
|
|
121
135
|
}
|
|
122
136
|
);
|
|
@@ -194,11 +208,33 @@ async function isCmssyEditMode() {
|
|
|
194
208
|
const h = await headers.headers();
|
|
195
209
|
return h.get(CMSSY_EDIT_HEADER) === "1";
|
|
196
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
|
+
}
|
|
197
229
|
|
|
198
230
|
exports.CMSSY_EDIT_HEADER = CMSSY_EDIT_HEADER;
|
|
231
|
+
exports.CMSSY_LOCALE_HEADER = CMSSY_LOCALE_HEADER;
|
|
199
232
|
exports.applyCmssyCsp = applyCmssyCsp;
|
|
200
233
|
exports.cmssyCspHeaders = cmssyCspHeaders;
|
|
201
234
|
exports.createCmssyPage = createCmssyPage;
|
|
202
235
|
exports.createDraftRoute = createDraftRoute;
|
|
236
|
+
exports.getCmssyLocale = getCmssyLocale;
|
|
203
237
|
exports.isCmssyEditMode = isCmssyEditMode;
|
|
204
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, CmssyFormDefinition, 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 {
|
|
@@ -67,4 +67,12 @@ interface EditRequestLike {
|
|
|
67
67
|
declare function isCmssyEditRequest(request: EditRequestLike): boolean;
|
|
68
68
|
declare function isCmssyEditMode(): Promise<boolean>;
|
|
69
69
|
|
|
70
|
-
|
|
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, CmssyFormDefinition, 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 {
|
|
@@ -67,4 +67,12 @@ interface EditRequestLike {
|
|
|
67
67
|
declare function isCmssyEditRequest(request: EditRequestLike): boolean;
|
|
68
68
|
declare function isCmssyEditMode(): Promise<boolean>;
|
|
69
69
|
|
|
70
|
-
|
|
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, resolveForms, 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,8 +73,23 @@ 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
|
-
|
|
78
|
-
|
|
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) {
|
|
@@ -101,7 +115,7 @@ function createCmssyPage(config, blocks, options) {
|
|
|
101
115
|
page,
|
|
102
116
|
locale,
|
|
103
117
|
defaultLocale,
|
|
104
|
-
enabledLocales
|
|
118
|
+
enabledLocales,
|
|
105
119
|
edit: { editorOrigin: bridgeOrigin },
|
|
106
120
|
forms
|
|
107
121
|
}
|
|
@@ -114,7 +128,7 @@ function createCmssyPage(config, blocks, options) {
|
|
|
114
128
|
blocks,
|
|
115
129
|
locale,
|
|
116
130
|
defaultLocale,
|
|
117
|
-
enabledLocales
|
|
131
|
+
enabledLocales,
|
|
118
132
|
forms
|
|
119
133
|
}
|
|
120
134
|
);
|
|
@@ -192,5 +206,23 @@ async function isCmssyEditMode() {
|
|
|
192
206
|
const h = await headers();
|
|
193
207
|
return h.get(CMSSY_EDIT_HEADER) === "1";
|
|
194
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
|
+
}
|
|
195
227
|
|
|
196
|
-
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.
|
|
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.
|
|
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.
|
|
52
|
+
"@cmssy/react": "0.1.7"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsup",
|