@cmssy/next 10.0.0 → 10.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/README.md +9 -10
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/server.cjs +2 -13
- package/dist/server.d.cts +2 -12
- package/dist/server.d.ts +2 -12
- package/dist/server.js +4 -14
- package/package.json +3 -8
- package/dist/client.cjs +0 -21
- package/dist/client.d.cts +0 -18
- package/dist/client.d.ts +0 -18
- package/dist/client.js +0 -15
package/README.md
CHANGED
|
@@ -61,18 +61,19 @@ Helpers to frame the page inside the cmssy editor only in edit mode.
|
|
|
61
61
|
|
|
62
62
|
The active locale lives in the URL path prefix (`/en/about`; the default locale
|
|
63
63
|
stays bare). `createCmssyPage` resolves it and exposes it via `CmssyLocaleProvider`.
|
|
64
|
-
For the locale to survive navigation, internal links must carry the prefix -
|
|
65
|
-
`
|
|
64
|
+
For the locale to survive navigation, internal links must carry the prefix -
|
|
65
|
+
prefix hrefs yourself with `localizeHref` and pass the result to `next/link`:
|
|
66
66
|
|
|
67
67
|
```tsx
|
|
68
68
|
// any block component
|
|
69
|
-
import
|
|
69
|
+
import Link from "next/link";
|
|
70
|
+
import { localizeHref } from "@cmssy/next";
|
|
70
71
|
|
|
71
|
-
<
|
|
72
|
+
<Link href={localizeHref("/about", locale)}>About</Link>; // → /en/about while EN is active
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
Add middleware so the root layout (which can't read the path) resolves the right
|
|
75
|
-
locale
|
|
76
|
+
locale from the path prefix. On Next.js 16 the file is `proxy.ts` (the renamed
|
|
76
77
|
middleware convention); on Next.js 15 use `middleware.ts` with the same body.
|
|
77
78
|
|
|
78
79
|
```ts
|
|
@@ -87,16 +88,14 @@ export const config = { matcher: ["/((?!_next/|api/|.*\\..*).*)"] };
|
|
|
87
88
|
On Next.js 15, name the file `middleware.ts` and rename the export to
|
|
88
89
|
`middleware` (`export const middleware = createCmssyLocaleMiddleware(cmssy)`).
|
|
89
90
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
`localizeHtmlLinks(html, locale)`.
|
|
91
|
+
`localizeHref(href, locale)` and the `CMSSY_LOCALE_HEADER` constant are
|
|
92
|
+
re-exported from `@cmssy/next` (and `@cmssy/core`).
|
|
93
93
|
|
|
94
94
|
## Exports
|
|
95
95
|
|
|
96
96
|
`createCmssyPage`, `createDraftRoute`, `cmssyCspHeaders` / `applyCmssyCsp`,
|
|
97
97
|
`isCmssyEditRequest` / `isCmssyEditMode`, `createCmssyLocaleMiddleware` /
|
|
98
|
-
`resolveLocaleFromPathname`, the `CmssyConfig` type
|
|
99
|
-
`@cmssy/next/client`: `CmssyLink`, `CmssyLocaleProvider`, `useCmssyLocale`.
|
|
98
|
+
`resolveLocaleFromPathname`, and the `CmssyConfig` type.
|
|
100
99
|
|
|
101
100
|
## License
|
|
102
101
|
|
package/dist/index.cjs
CHANGED
|
@@ -12,6 +12,10 @@ Object.defineProperty(exports, "CMSSY_EDIT_QUERY_PARAM", {
|
|
|
12
12
|
enumerable: true,
|
|
13
13
|
get: function () { return core.CMSSY_EDIT_QUERY_PARAM; }
|
|
14
14
|
});
|
|
15
|
+
Object.defineProperty(exports, "CMSSY_LOCALE_HEADER", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return core.CMSSY_LOCALE_HEADER; }
|
|
18
|
+
});
|
|
15
19
|
Object.defineProperty(exports, "CMSSY_SECRET_QUERY_PARAM", {
|
|
16
20
|
enumerable: true,
|
|
17
21
|
get: function () { return core.CMSSY_SECRET_QUERY_PARAM; }
|
|
@@ -24,6 +28,10 @@ Object.defineProperty(exports, "defineCmssyConfig", {
|
|
|
24
28
|
enumerable: true,
|
|
25
29
|
get: function () { return core.defineCmssyConfig; }
|
|
26
30
|
});
|
|
31
|
+
Object.defineProperty(exports, "localizeHref", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return core.localizeHref; }
|
|
34
|
+
});
|
|
27
35
|
Object.defineProperty(exports, "resolveEditorOrigin", {
|
|
28
36
|
enumerable: true,
|
|
29
37
|
get: function () { return core.resolveEditorOrigin; }
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_SECRET_QUERY_PARAM, CmssyConfig, CmssyEnvConfig, CmssyPageData, CmssyPageMeta, CmssyPageSummary, DEFAULT_CMSSY_EDITOR_ORIGINS, defineCmssyConfig, resolveEditorOrigin } from '@cmssy/core';
|
|
1
|
+
export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_LOCALE_HEADER, CMSSY_SECRET_QUERY_PARAM, CmssyConfig, CmssyEnvConfig, CmssyPageData, CmssyPageMeta, CmssyPageSummary, DEFAULT_CMSSY_EDITOR_ORIGINS, defineCmssyConfig, localizeHref, resolveEditorOrigin } from '@cmssy/core';
|
|
2
2
|
export { C as CmssyEditorProps, a as CreateCmssyPageOptions } from './index-C4vUxDkk.cjs';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_SECRET_QUERY_PARAM, CmssyConfig, CmssyEnvConfig, CmssyPageData, CmssyPageMeta, CmssyPageSummary, DEFAULT_CMSSY_EDITOR_ORIGINS, defineCmssyConfig, resolveEditorOrigin } from '@cmssy/core';
|
|
1
|
+
export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_LOCALE_HEADER, CMSSY_SECRET_QUERY_PARAM, CmssyConfig, CmssyEnvConfig, CmssyPageData, CmssyPageMeta, CmssyPageSummary, DEFAULT_CMSSY_EDITOR_ORIGINS, defineCmssyConfig, localizeHref, resolveEditorOrigin } from '@cmssy/core';
|
|
2
2
|
export { C as CmssyEditorProps, a as CreateCmssyPageOptions } from './index-C4vUxDkk.js';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_SECRET_QUERY_PARAM, DEFAULT_CMSSY_EDITOR_ORIGINS, defineCmssyConfig, resolveEditorOrigin } from '@cmssy/core';
|
|
1
|
+
export { CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM, CMSSY_LOCALE_HEADER, CMSSY_SECRET_QUERY_PARAM, DEFAULT_CMSSY_EDITOR_ORIGINS, defineCmssyConfig, localizeHref, resolveEditorOrigin } from '@cmssy/core';
|
package/dist/server.cjs
CHANGED
|
@@ -5,6 +5,7 @@ var headers = require('next/headers');
|
|
|
5
5
|
var navigation = require('next/navigation');
|
|
6
6
|
var react = require('@cmssy/react');
|
|
7
7
|
var internal$1 = require('@cmssy/react/internal');
|
|
8
|
+
var internalServer = require('@cmssy/react/internal-server');
|
|
8
9
|
var internal = require('@cmssy/core/internal');
|
|
9
10
|
var core = require('@cmssy/core');
|
|
10
11
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -101,7 +102,7 @@ function buildCmssyPageRenderer(config, blocks, options, editRoute) {
|
|
|
101
102
|
};
|
|
102
103
|
if (editorActive && Editor) {
|
|
103
104
|
const bridgeOrigin = resolveBridgeOrigin(config.editorOrigin);
|
|
104
|
-
const editorData = await
|
|
105
|
+
const editorData = await internalServer.resolveEditorBlockData({
|
|
105
106
|
page,
|
|
106
107
|
blocks,
|
|
107
108
|
locale,
|
|
@@ -240,17 +241,6 @@ function createDraftRoute(config) {
|
|
|
240
241
|
navigation.redirect(location);
|
|
241
242
|
};
|
|
242
243
|
}
|
|
243
|
-
async function getCmssyLocale(config, options) {
|
|
244
|
-
if (options?.path !== void 0) {
|
|
245
|
-
return internal.localeForPath(config, options.path);
|
|
246
|
-
}
|
|
247
|
-
const { headers: headers3 } = await import('next/headers');
|
|
248
|
-
const headerList = await headers3();
|
|
249
|
-
const fromHeader = headerList.get(internal.CMSSY_LOCALE_HEADER);
|
|
250
|
-
if (fromHeader) return fromHeader;
|
|
251
|
-
const { defaultLocale } = await internal.resolveSiteLocales(config);
|
|
252
|
-
return defaultLocale;
|
|
253
|
-
}
|
|
254
244
|
async function isCmssyEditMode() {
|
|
255
245
|
const h = await headers.headers();
|
|
256
246
|
return h.get(core.CMSSY_EDIT_HEADER) === "1";
|
|
@@ -259,5 +249,4 @@ async function isCmssyEditMode() {
|
|
|
259
249
|
exports.createCmssyEditPage = createCmssyEditPage;
|
|
260
250
|
exports.createCmssyPage = createCmssyPage;
|
|
261
251
|
exports.createDraftRoute = createDraftRoute;
|
|
262
|
-
exports.getCmssyLocale = getCmssyLocale;
|
|
263
252
|
exports.isCmssyEditMode = isCmssyEditMode;
|
package/dist/server.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { C as CmssyEditorProps, a as CreateCmssyPageOptions, c as createCmssyEditPage, b as createCmssyPage } from './index-C4vUxDkk.cjs';
|
|
2
|
-
import { CmssyConfig
|
|
2
|
+
import { CmssyConfig } from '@cmssy/core';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '@cmssy/react';
|
|
@@ -10,16 +10,6 @@ type CmssyDraftRouteConfig = Pick<CmssyConfig, "draftSecret"> & {
|
|
|
10
10
|
};
|
|
11
11
|
declare function createDraftRoute(config: CmssyDraftRouteConfig): (request: Request) => Promise<Response>;
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* Resolve the active locale. Pass `options.path` (route params) wherever
|
|
15
|
-
* possible - that path is static-safe. The no-argument form falls back to the
|
|
16
|
-
* `x-cmssy-locale` request header, which reads `headers()` and forces the
|
|
17
|
-
* calling route into dynamic rendering.
|
|
18
|
-
*/
|
|
19
|
-
declare function getCmssyLocale(config: CmssyClientConfig, options?: {
|
|
20
|
-
path?: string | string[];
|
|
21
|
-
}): Promise<string>;
|
|
22
|
-
|
|
23
13
|
declare function isCmssyEditMode(): Promise<boolean>;
|
|
24
14
|
|
|
25
|
-
export { type CmssyDraftRouteConfig, createDraftRoute,
|
|
15
|
+
export { type CmssyDraftRouteConfig, createDraftRoute, isCmssyEditMode };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { C as CmssyEditorProps, a as CreateCmssyPageOptions, c as createCmssyEditPage, b as createCmssyPage } from './index-C4vUxDkk.js';
|
|
2
|
-
import { CmssyConfig
|
|
2
|
+
import { CmssyConfig } from '@cmssy/core';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
|
5
5
|
import '@cmssy/react';
|
|
@@ -10,16 +10,6 @@ type CmssyDraftRouteConfig = Pick<CmssyConfig, "draftSecret"> & {
|
|
|
10
10
|
};
|
|
11
11
|
declare function createDraftRoute(config: CmssyDraftRouteConfig): (request: Request) => Promise<Response>;
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* Resolve the active locale. Pass `options.path` (route params) wherever
|
|
15
|
-
* possible - that path is static-safe. The no-argument form falls back to the
|
|
16
|
-
* `x-cmssy-locale` request header, which reads `headers()` and forces the
|
|
17
|
-
* calling route into dynamic rendering.
|
|
18
|
-
*/
|
|
19
|
-
declare function getCmssyLocale(config: CmssyClientConfig, options?: {
|
|
20
|
-
path?: string | string[];
|
|
21
|
-
}): Promise<string>;
|
|
22
|
-
|
|
23
13
|
declare function isCmssyEditMode(): Promise<boolean>;
|
|
24
14
|
|
|
25
|
-
export { type CmssyDraftRouteConfig, createDraftRoute,
|
|
15
|
+
export { type CmssyDraftRouteConfig, createDraftRoute, isCmssyEditMode };
|
package/dist/server.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
2
|
import { draftMode, headers } from 'next/headers';
|
|
3
3
|
import { notFound, redirect } from 'next/navigation';
|
|
4
|
-
import { createCmssyClient,
|
|
4
|
+
import { createCmssyClient, CmssyServerPage } from '@cmssy/react';
|
|
5
5
|
import { CmssyLocaleProvider } from '@cmssy/react/internal';
|
|
6
|
-
import {
|
|
6
|
+
import { resolveEditorBlockData } from '@cmssy/react/internal-server';
|
|
7
|
+
import { isDevelopment, resolveSiteLocales, splitLocaleFromPath, fetchPage, resolveForms, toCspOrigin, cmssySecretsMatch } from '@cmssy/core/internal';
|
|
7
8
|
import { CMSSY_SECRET_QUERY_PARAM, resolveEditorOrigin, CMSSY_EDIT_HEADER, CMSSY_EDIT_QUERY_PARAM } from '@cmssy/core';
|
|
8
9
|
import { jsx } from 'react/jsx-runtime';
|
|
9
10
|
|
|
@@ -238,20 +239,9 @@ function createDraftRoute(config) {
|
|
|
238
239
|
redirect(location);
|
|
239
240
|
};
|
|
240
241
|
}
|
|
241
|
-
async function getCmssyLocale(config, options) {
|
|
242
|
-
if (options?.path !== void 0) {
|
|
243
|
-
return localeForPath(config, options.path);
|
|
244
|
-
}
|
|
245
|
-
const { headers: headers3 } = await import('next/headers');
|
|
246
|
-
const headerList = await headers3();
|
|
247
|
-
const fromHeader = headerList.get(CMSSY_LOCALE_HEADER);
|
|
248
|
-
if (fromHeader) return fromHeader;
|
|
249
|
-
const { defaultLocale } = await resolveSiteLocales(config);
|
|
250
|
-
return defaultLocale;
|
|
251
|
-
}
|
|
252
242
|
async function isCmssyEditMode() {
|
|
253
243
|
const h = await headers();
|
|
254
244
|
return h.get(CMSSY_EDIT_HEADER) === "1";
|
|
255
245
|
}
|
|
256
246
|
|
|
257
|
-
export { createCmssyEditPage, createCmssyPage, createDraftRoute,
|
|
247
|
+
export { createCmssyEditPage, createCmssyPage, createDraftRoute, isCmssyEditMode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/next",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -38,11 +38,6 @@
|
|
|
38
38
|
"import": "./dist/middleware.js",
|
|
39
39
|
"require": "./dist/middleware.cjs"
|
|
40
40
|
},
|
|
41
|
-
"./client": {
|
|
42
|
-
"types": "./dist/client.d.ts",
|
|
43
|
-
"import": "./dist/client.js",
|
|
44
|
-
"require": "./dist/client.cjs"
|
|
45
|
-
},
|
|
46
41
|
"./testing": {
|
|
47
42
|
"types": "./dist/testing.d.ts",
|
|
48
43
|
"import": "./dist/testing.js",
|
|
@@ -70,12 +65,12 @@
|
|
|
70
65
|
"tsup": "^8.3.0",
|
|
71
66
|
"typescript": "^5.6.0",
|
|
72
67
|
"vitest": "^2.1.0",
|
|
73
|
-
"@cmssy/react": "10.
|
|
68
|
+
"@cmssy/react": "10.1.0"
|
|
74
69
|
},
|
|
75
70
|
"dependencies": {
|
|
76
71
|
"@cmssy/types": "0.29.0",
|
|
77
72
|
"server-only": "^0.0.1",
|
|
78
|
-
"@cmssy/core": "10.
|
|
73
|
+
"@cmssy/core": "10.1.0"
|
|
79
74
|
},
|
|
80
75
|
"scripts": {
|
|
81
76
|
"build": "tsup",
|
package/dist/client.cjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var Link = require('next/link');
|
|
5
|
-
var internal$1 = require('@cmssy/core/internal');
|
|
6
|
-
var internal = require('@cmssy/react/internal');
|
|
7
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
-
|
|
9
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
|
|
11
|
-
var Link__default = /*#__PURE__*/_interopDefault(Link);
|
|
12
|
-
|
|
13
|
-
// src/cmssy-link.tsx
|
|
14
|
-
function CmssyLink({ href, locale, ...rest }) {
|
|
15
|
-
const fromContext = internal.useCmssyLocale();
|
|
16
|
-
const active = locale ?? fromContext;
|
|
17
|
-
const resolved = active ? internal$1.localizeHref(href, active) : href;
|
|
18
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Link__default.default, { href: resolved, ...rest });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
exports.CmssyLink = CmssyLink;
|
package/dist/client.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import Link from 'next/link';
|
|
3
|
-
import { ComponentProps } from 'react';
|
|
4
|
-
import { CmssyLocaleContext } from '@cmssy/react';
|
|
5
|
-
|
|
6
|
-
interface CmssyLinkProps extends Omit<ComponentProps<typeof Link>, "href" | "locale"> {
|
|
7
|
-
href: string;
|
|
8
|
-
/** Override the active locale (defaults to the nearest CmssyLocaleProvider). */
|
|
9
|
-
locale?: CmssyLocaleContext;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* `next/link` that prefixes internal hrefs with the active locale, so navigation
|
|
13
|
-
* preserves the language. Reads the locale from the nearest
|
|
14
|
-
* `CmssyLocaleProvider`; falls back to the raw href when none is mounted.
|
|
15
|
-
*/
|
|
16
|
-
declare function CmssyLink({ href, locale, ...rest }: CmssyLinkProps): react_jsx_runtime.JSX.Element;
|
|
17
|
-
|
|
18
|
-
export { CmssyLink, type CmssyLinkProps };
|
package/dist/client.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import Link from 'next/link';
|
|
3
|
-
import { ComponentProps } from 'react';
|
|
4
|
-
import { CmssyLocaleContext } from '@cmssy/react';
|
|
5
|
-
|
|
6
|
-
interface CmssyLinkProps extends Omit<ComponentProps<typeof Link>, "href" | "locale"> {
|
|
7
|
-
href: string;
|
|
8
|
-
/** Override the active locale (defaults to the nearest CmssyLocaleProvider). */
|
|
9
|
-
locale?: CmssyLocaleContext;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* `next/link` that prefixes internal hrefs with the active locale, so navigation
|
|
13
|
-
* preserves the language. Reads the locale from the nearest
|
|
14
|
-
* `CmssyLocaleProvider`; falls back to the raw href when none is mounted.
|
|
15
|
-
*/
|
|
16
|
-
declare function CmssyLink({ href, locale, ...rest }: CmssyLinkProps): react_jsx_runtime.JSX.Element;
|
|
17
|
-
|
|
18
|
-
export { CmssyLink, type CmssyLinkProps };
|
package/dist/client.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import Link from 'next/link';
|
|
3
|
-
import { localizeHref } from '@cmssy/core/internal';
|
|
4
|
-
import { useCmssyLocale } from '@cmssy/react/internal';
|
|
5
|
-
import { jsx } from 'react/jsx-runtime';
|
|
6
|
-
|
|
7
|
-
// src/cmssy-link.tsx
|
|
8
|
-
function CmssyLink({ href, locale, ...rest }) {
|
|
9
|
-
const fromContext = useCmssyLocale();
|
|
10
|
-
const active = locale ?? fromContext;
|
|
11
|
-
const resolved = active ? localizeHref(href, active) : href;
|
|
12
|
-
return /* @__PURE__ */ jsx(Link, { href: resolved, ...rest });
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { CmssyLink };
|