@enonic/nextjs-adapter 2.0.0 → 3.0.0-B1
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/UrlProcessor.d.ts +3 -2
- package/UrlProcessor.js +25 -10
- package/guillotine/fetchContent.d.ts +6 -8
- package/guillotine/fetchContent.js +98 -92
- package/i18n/LocaleContext.d.ts +13 -0
- package/i18n/LocaleContext.jsx +42 -0
- package/i18n/i18n.d.ts +13 -0
- package/i18n/i18n.js +56 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +15 -12
- package/utils.d.ts +27 -30
- package/utils.js +75 -61
- package/views/BaseComponent.d.ts +1 -1
- package/views/BaseComponent.jsx +19 -5
- package/views/RichTextView.jsx +4 -1
- package/server/ClearableFileCache.d.ts +0 -31
- package/server/ClearableFileCache.js +0 -472
- package/server/cache.d.ts +0 -2
- package/server/cache.js +0 -129
- package/server/index.d.ts +0 -5
- package/server/index.js +0 -132
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enonic/nextjs-adapter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-B1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,26 +8,29 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"copy": "npx --yes cpy-cli package.json README.md dist",
|
|
11
|
-
"build": "tsc --build
|
|
12
|
-
"lint": "eslint --quiet
|
|
13
|
-
"lint:fix": "eslint --fix
|
|
11
|
+
"build": "tsc --build tsconfig.json",
|
|
12
|
+
"lint": "eslint --quiet src",
|
|
13
|
+
"lint:fix": "eslint --fix src"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"
|
|
16
|
+
"@formatjs/intl-localematcher": "^0.5.2",
|
|
17
|
+
"html-react-parser": "^5.0.11",
|
|
17
18
|
"lru-cache": "^10.0.1",
|
|
18
|
-
"
|
|
19
|
+
"negotiator": "^0.6.3",
|
|
20
|
+
"next": "^14.0.4",
|
|
19
21
|
"react": "18.2.0",
|
|
20
22
|
"react-dom": "18.2.0",
|
|
21
23
|
"unescape": "^1.0.1"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
24
26
|
"@enonic/eslint-config": "^1.1.0",
|
|
25
|
-
"@types/
|
|
26
|
-
"@types/
|
|
27
|
-
"@types/react
|
|
28
|
-
"@
|
|
29
|
-
"@typescript-eslint/
|
|
30
|
-
"eslint": "^
|
|
27
|
+
"@types/negotiator": "^0.6.3",
|
|
28
|
+
"@types/node": "^20.10.7",
|
|
29
|
+
"@types/react": "18.2.47",
|
|
30
|
+
"@types/react-dom": "18.2.18",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
32
|
+
"@typescript-eslint/parser": "^6.18.1",
|
|
33
|
+
"eslint": "^8.56.0",
|
|
31
34
|
"eslint-plugin-react": "^7.33.2",
|
|
32
35
|
"typescript": "^5.2.2"
|
|
33
36
|
}
|
package/utils.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
/** Import config values from .env, .env.development and .env.production */
|
|
4
|
-
import { GetServerSidePropsContext } from 'next';
|
|
5
3
|
import { ParsedUrlQuery } from 'node:querystring';
|
|
6
|
-
import {
|
|
4
|
+
import { ReadonlyHeaders } from 'next/dist/server/web/spec-extension/adapters/headers';
|
|
7
5
|
export declare const IS_DEV_MODE: boolean;
|
|
8
|
-
export declare const PURGE_CACHE_URL = "/_/enonic/cache/purge";
|
|
9
6
|
export declare enum ENV_VARS {
|
|
10
7
|
PROJECTS = "ENONIC_PROJECTS",
|
|
11
8
|
API = "ENONIC_API",
|
|
@@ -67,40 +64,40 @@ export interface PreviewParams {
|
|
|
67
64
|
headers: Record<string, string>;
|
|
68
65
|
params: Record<string, string>;
|
|
69
66
|
}
|
|
70
|
-
export type Context =
|
|
71
|
-
|
|
67
|
+
export type Context = {
|
|
68
|
+
headers?: ReadonlyHeaders | Headers;
|
|
69
|
+
locale?: string;
|
|
70
|
+
contentPath: string | string[];
|
|
71
|
+
};
|
|
72
|
+
export type ProjectLocaleConfig = {
|
|
73
|
+
default: boolean;
|
|
72
74
|
project: string;
|
|
73
75
|
site: string;
|
|
74
76
|
locale: string;
|
|
75
77
|
};
|
|
76
|
-
export type
|
|
77
|
-
|
|
78
|
-
[locale: string]: LocaleProjectConfig;
|
|
78
|
+
export type ProjectLocalesConfig = {
|
|
79
|
+
[locale: string]: ProjectLocaleConfig;
|
|
79
80
|
};
|
|
80
|
-
export interface MinimalContext {
|
|
81
|
-
req?: {
|
|
82
|
-
headers: IncomingHttpHeaders;
|
|
83
|
-
};
|
|
84
|
-
locale?: string;
|
|
85
|
-
defaultLocale?: string;
|
|
86
|
-
locales?: string[];
|
|
87
|
-
}
|
|
88
81
|
export interface ContentPathItem {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
locale?: string;
|
|
82
|
+
contentPath: string[];
|
|
83
|
+
locale: string;
|
|
93
84
|
}
|
|
94
|
-
export declare const getRenderMode: (context
|
|
95
|
-
export declare function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
export declare const getRenderMode: (context: Context) => RENDER_MODE;
|
|
86
|
+
export declare function getRequestLocaleInfo(context: Context): {
|
|
87
|
+
locale: string;
|
|
88
|
+
locales: string[];
|
|
89
|
+
defaultLocale: string;
|
|
90
|
+
};
|
|
91
|
+
export declare function getProjectLocaleConfig(context: Context): ProjectLocaleConfig;
|
|
92
|
+
export declare function getProjectLocales(): string[];
|
|
93
|
+
export declare function getProjectLocaleConfigById(projectId?: string, useDefault?: boolean): ProjectLocaleConfig;
|
|
94
|
+
export declare function getProjectLocaleConfigByLocale(locale?: string, useDefault?: boolean): ProjectLocaleConfig;
|
|
95
|
+
export declare function getProjectLocaleConfigs(): ProjectLocalesConfig;
|
|
99
96
|
export declare function fixDoubleSlashes(str: string): string;
|
|
100
|
-
export declare function getContentApiUrl(context
|
|
101
|
-
export declare function addJsessionHeaders(
|
|
102
|
-
export declare function addLocaleHeaders(
|
|
103
|
-
export declare const getXpBaseUrl: (context
|
|
97
|
+
export declare function getContentApiUrl(context: Context): string;
|
|
98
|
+
export declare function addJsessionHeaders(target: Object, context: Context): void;
|
|
99
|
+
export declare function addLocaleHeaders(target: Object, locale: string, locales: string[], defaultLocale: string): void;
|
|
100
|
+
export declare const getXpBaseUrl: (context: Context) => string;
|
|
104
101
|
export declare const commonChars: (s1?: string, s2?: string) => string;
|
|
105
102
|
export declare const sanitizeGraphqlName: (text: string) => string;
|
|
106
103
|
declare const adapterConstants: {
|
package/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import Negotiator from 'negotiator';
|
|
2
|
+
import { match as localeMatcher } from '@formatjs/intl-localematcher';
|
|
1
3
|
const mode = process.env.MODE || process.env.NEXT_PUBLIC_MODE;
|
|
2
4
|
export const IS_DEV_MODE = (mode === 'development');
|
|
3
|
-
export const PURGE_CACHE_URL = '/_/enonic/cache/purge';
|
|
4
5
|
export var ENV_VARS;
|
|
5
6
|
(function (ENV_VARS) {
|
|
6
7
|
ENV_VARS["PROJECTS"] = "ENONIC_PROJECTS";
|
|
@@ -17,7 +18,7 @@ export const APP_NAME = (process.env.ENONIC_APP_NAME || process.env.NEXT_PUBLIC_
|
|
|
17
18
|
export const APP_NAME_UNDERSCORED = (APP_NAME || '').replace(/\./g, '_');
|
|
18
19
|
/** Optional utility value - derived from APP_NAME, only with dashes instead of dots */
|
|
19
20
|
export const APP_NAME_DASHED = (APP_NAME || '').replace(/\./g, '-');
|
|
20
|
-
const PROJECT_CONFIG_REGEXP = new RegExp('^(
|
|
21
|
+
const PROJECT_CONFIG_REGEXP = new RegExp('^([\\w-]+):([^\\/\\s]+)(\\/[\\w-.]+)?$', 'i');
|
|
21
22
|
// //////////////////////////////////////////////////////////////////////// Hardcode-able constants
|
|
22
23
|
// URI parameter marking that a request is for a preview for CS. MUST MATCH THE VALUE OF 'FROM_XP_PARAM' on XP side.
|
|
23
24
|
export const XP_BASE_URL_HEADER = 'xpbaseurl';
|
|
@@ -87,56 +88,89 @@ export var XP_COMPONENT_TYPE;
|
|
|
87
88
|
})(XP_COMPONENT_TYPE || (XP_COMPONENT_TYPE = {}));
|
|
88
89
|
export const getRenderMode = (context) => {
|
|
89
90
|
var _a;
|
|
90
|
-
const value = (
|
|
91
|
+
const value = (_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(RENDER_MODE_HEADER);
|
|
91
92
|
const enumValue = RENDER_MODE[value === null || value === void 0 ? void 0 : value.toUpperCase()];
|
|
92
93
|
return enumValue || RENDER_MODE[process.env.RENDER_MODE] || RENDER_MODE.NEXT;
|
|
93
94
|
};
|
|
94
|
-
export function
|
|
95
|
-
|
|
95
|
+
export function getRequestLocaleInfo(context) {
|
|
96
|
+
var _a, _b, _c;
|
|
97
|
+
let locale;
|
|
98
|
+
const configs = getProjectLocaleConfigs();
|
|
99
|
+
const locales = Object.keys(configs);
|
|
100
|
+
const defaultLocale = locales.find((locale) => configs[locale].default);
|
|
101
|
+
const projectId = (_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(PROJECT_ID_HEADER);
|
|
102
|
+
if (projectId) {
|
|
103
|
+
locale = (_b = getProjectLocaleConfigById(projectId, false)) === null || _b === void 0 ? void 0 : _b.locale;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
locale = context.locale;
|
|
107
|
+
if (!locale) {
|
|
108
|
+
const acceptLang = ((_c = context.headers) === null || _c === void 0 ? void 0 : _c.get('accept-language')) || '';
|
|
109
|
+
const langs = new Negotiator({ headers: { 'accept-language': acceptLang } }).languages();
|
|
110
|
+
locale = localeMatcher(langs, locales, defaultLocale);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { locale, locales, defaultLocale };
|
|
96
114
|
}
|
|
97
|
-
export function
|
|
115
|
+
export function getProjectLocaleConfig(context) {
|
|
98
116
|
var _a;
|
|
99
|
-
const projectId = (
|
|
117
|
+
const projectId = (_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(PROJECT_ID_HEADER);
|
|
118
|
+
let config;
|
|
100
119
|
if (projectId) {
|
|
101
|
-
|
|
120
|
+
// first use project id header
|
|
121
|
+
config = getProjectLocaleConfigById(projectId, false);
|
|
102
122
|
}
|
|
103
|
-
const projectsConfig = getLocaleProjectConfigs();
|
|
104
|
-
const locale = (context === null || context === void 0 ? void 0 : context.locale) || (context === null || context === void 0 ? void 0 : context.defaultLocale);
|
|
105
|
-
let config = projectsConfig[locale];
|
|
106
123
|
if (!config) {
|
|
107
|
-
|
|
124
|
+
// next try to use locale from url
|
|
125
|
+
// it will fall back to default locale if not found
|
|
126
|
+
config = getProjectLocaleConfigByLocale(context.locale);
|
|
108
127
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
128
|
+
return config;
|
|
129
|
+
}
|
|
130
|
+
export function getProjectLocales() {
|
|
131
|
+
return Object.keys(getProjectLocaleConfigs());
|
|
132
|
+
}
|
|
133
|
+
export function getProjectLocaleConfigById(projectId, useDefault = true) {
|
|
134
|
+
const configs = getProjectLocaleConfigs();
|
|
135
|
+
let config;
|
|
136
|
+
if (projectId) {
|
|
137
|
+
config = Object.values(configs).find(p => {
|
|
138
|
+
var _a;
|
|
139
|
+
return ((_a = p === null || p === void 0 ? void 0 : p.project) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === projectId.toLowerCase();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (!config && useDefault) {
|
|
143
|
+
config = Object.values(configs).find(c => c.default);
|
|
112
144
|
}
|
|
113
145
|
return config;
|
|
114
146
|
}
|
|
115
|
-
export function
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
return
|
|
147
|
+
export function getProjectLocaleConfigByLocale(locale, useDefault = true) {
|
|
148
|
+
const configs = getProjectLocaleConfigs();
|
|
149
|
+
let config;
|
|
150
|
+
if (locale) {
|
|
151
|
+
config = configs[locale];
|
|
152
|
+
}
|
|
153
|
+
if (!config && useDefault) {
|
|
154
|
+
config = Object.values(configs).find(c => c.default);
|
|
155
|
+
}
|
|
156
|
+
return config;
|
|
125
157
|
}
|
|
126
|
-
export function
|
|
158
|
+
export function getProjectLocaleConfigs() {
|
|
127
159
|
const str = PROJECTS;
|
|
128
160
|
const envVarName = ENV_VARS.PROJECTS;
|
|
129
161
|
if (!(str === null || str === void 0 ? void 0 : str.length)) {
|
|
130
|
-
throw Error(`"${
|
|
162
|
+
throw new Error(`Did you forget to define "${ENV_VARS.PROJECTS}" environmental variable?
|
|
163
|
+
Format: <default-language>:<default-repository-name>/<default-site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
131
164
|
}
|
|
132
|
-
|
|
165
|
+
return str.split(',').reduce((config, prjStr, index) => {
|
|
133
166
|
const matches = PROJECT_CONFIG_REGEXP.exec(prjStr === null || prjStr === void 0 ? void 0 : prjStr.trim());
|
|
134
167
|
if (!(matches === null || matches === void 0 ? void 0 : matches.length)) {
|
|
135
168
|
return config;
|
|
136
169
|
}
|
|
137
|
-
const [full, lang
|
|
170
|
+
const [full, lang, project, site] = matches;
|
|
138
171
|
if (project && site) {
|
|
139
172
|
config[lang] = {
|
|
173
|
+
default: index === 0,
|
|
140
174
|
project,
|
|
141
175
|
site,
|
|
142
176
|
locale: lang,
|
|
@@ -144,56 +178,36 @@ export function getLocaleProjectConfigs() {
|
|
|
144
178
|
}
|
|
145
179
|
else {
|
|
146
180
|
throw Error(`Wrong configuration in "${envVarName}": ${prjStr}.
|
|
147
|
-
Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
181
|
+
Format: <default-language>:<default-repository-name>/<default-site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
148
182
|
}
|
|
149
183
|
return config;
|
|
150
|
-
}, {
|
|
151
|
-
default: {
|
|
152
|
-
project: '',
|
|
153
|
-
site: '',
|
|
154
|
-
locale: '',
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
if (!result.default.site || !result.default.project) {
|
|
158
|
-
throw Error(`"${envVarName}" environmental variable should contain default value.
|
|
159
|
-
Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
160
|
-
}
|
|
161
|
-
return result;
|
|
184
|
+
}, {});
|
|
162
185
|
}
|
|
163
186
|
export function fixDoubleSlashes(str) {
|
|
164
187
|
return str.replace(/(^|[^:/])\/{2,}/g, '$1/');
|
|
165
188
|
}
|
|
166
189
|
export function getContentApiUrl(context) {
|
|
167
|
-
const project =
|
|
190
|
+
const project = getProjectLocaleConfig(context).project;
|
|
168
191
|
const branch = getRenderMode(context) === RENDER_MODE.NEXT ? 'master' : 'draft';
|
|
169
192
|
return fixDoubleSlashes(`${API_URL}/${project}/${branch}`);
|
|
170
193
|
}
|
|
171
|
-
export function addJsessionHeaders(
|
|
194
|
+
export function addJsessionHeaders(target = {}, context) {
|
|
172
195
|
var _a;
|
|
173
|
-
const jsessionid = (_a = context
|
|
196
|
+
const jsessionid = (_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(JSESSIONID_HEADER);
|
|
174
197
|
if (jsessionid) {
|
|
175
|
-
|
|
198
|
+
target['Cookie'] = `${JSESSIONID_HEADER}=${jsessionid}`;
|
|
176
199
|
}
|
|
177
200
|
}
|
|
178
|
-
export function addLocaleHeaders(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
const locales = context === null || context === void 0 ? void 0 : context.locales;
|
|
184
|
-
if (locales) {
|
|
185
|
-
headers[LOCALES_HEADER] = JSON.stringify(locales);
|
|
186
|
-
}
|
|
187
|
-
const defaultLocale = context === null || context === void 0 ? void 0 : context.defaultLocale;
|
|
188
|
-
if (defaultLocale) {
|
|
189
|
-
headers[DEFAULT_LOCALE_HEADER] = defaultLocale;
|
|
190
|
-
}
|
|
201
|
+
export function addLocaleHeaders(target = {}, locale, locales, defaultLocale) {
|
|
202
|
+
target[LOCALE_HEADER] = locale;
|
|
203
|
+
target[LOCALES_HEADER] = JSON.stringify(locales);
|
|
204
|
+
target[DEFAULT_LOCALE_HEADER] = defaultLocale;
|
|
191
205
|
}
|
|
192
206
|
export const getXpBaseUrl = (context) => {
|
|
193
207
|
var _a;
|
|
194
|
-
const header = ((
|
|
208
|
+
const header = ((_a = context.headers) === null || _a === void 0 ? void 0 : _a.get(XP_BASE_URL_HEADER)) || '/';
|
|
195
209
|
// TODO: workaround for XP pattern controller mapping not picked up in edit mode
|
|
196
|
-
return
|
|
210
|
+
return header.replace(/\/edit\//, '/inline/');
|
|
197
211
|
};
|
|
198
212
|
export const commonChars = (s1, s2) => {
|
|
199
213
|
let result = '';
|
package/views/BaseComponent.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type BaseComponentProps = {
|
|
|
5
5
|
meta: MetaData;
|
|
6
6
|
common?: any;
|
|
7
7
|
};
|
|
8
|
-
declare const BaseComponent: ({ component, meta, common }: BaseComponentProps) => JSX.Element
|
|
8
|
+
declare const BaseComponent: ({ component, meta, common }: BaseComponentProps) => Promise<React.JSX.Element>;
|
|
9
9
|
export default BaseComponent;
|
|
10
10
|
export declare const MissingComponent: ({ descriptor, type }: {
|
|
11
11
|
descriptor?: string;
|
package/views/BaseComponent.jsx
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import React from 'react';
|
|
2
11
|
import { IS_DEV_MODE, PORTAL_COMPONENT_ATTRIBUTE, RENDER_MODE, XP_COMPONENT_TYPE } from '../utils';
|
|
3
12
|
import { ComponentRegistry } from '../ComponentRegistry';
|
|
4
13
|
import Empty from './Empty';
|
|
5
|
-
|
|
6
|
-
const BaseComponent = ({ component, meta, common }) => {
|
|
14
|
+
const BaseComponent = ({ component, meta, common }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
15
|
var _a;
|
|
8
16
|
const { type, error } = component;
|
|
9
17
|
const cmpData = component[type];
|
|
@@ -28,8 +36,8 @@ const BaseComponent = ({ component, meta, common }) => {
|
|
|
28
36
|
}
|
|
29
37
|
// need to display a placeholder if descriptor is empty as component is not initialized yet
|
|
30
38
|
if (descriptor && shouldShowPlaceholderView(meta)) {
|
|
31
|
-
const outputHTML =
|
|
32
|
-
if (!outputHTML || outputHTML.trim().length
|
|
39
|
+
const outputHTML = yield renderComponent(ComponentView);
|
|
40
|
+
if (!(outputHTML === null || outputHTML === void 0 ? void 0 : outputHTML.trim().length)) {
|
|
33
41
|
// render some placeholder in case of empty output
|
|
34
42
|
ComponentView = <PlaceholderComponent type={type} descriptor={descriptor}/>;
|
|
35
43
|
}
|
|
@@ -43,7 +51,7 @@ const BaseComponent = ({ component, meta, common }) => {
|
|
|
43
51
|
// do not make component wrappers in live mode
|
|
44
52
|
return ComponentView;
|
|
45
53
|
}
|
|
46
|
-
};
|
|
54
|
+
});
|
|
47
55
|
export default BaseComponent;
|
|
48
56
|
/*
|
|
49
57
|
* Used for displaying components with missing implementations on the page, while rendering whole page
|
|
@@ -57,6 +65,12 @@ export const MissingComponent = ({ descriptor, type }) => {
|
|
|
57
65
|
<p style={{ marginBottom: 0, color: 'grey' }}>{`Missing ${type} with descriptor: ${descriptor}`}</p>
|
|
58
66
|
</div>);
|
|
59
67
|
};
|
|
68
|
+
// Have to import it dynamically because of this issue:
|
|
69
|
+
// https://github.com/vercel/next.js/issues/43810
|
|
70
|
+
const renderComponent = (component) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
const ReactDOMServer = (yield import('react-dom/server')).default;
|
|
72
|
+
return ReactDOMServer.renderToStaticMarkup(component);
|
|
73
|
+
});
|
|
60
74
|
export function shouldShowMissingView(meta) {
|
|
61
75
|
return IS_DEV_MODE || meta.renderMode !== RENDER_MODE.NEXT;
|
|
62
76
|
}
|
package/views/RichTextView.jsx
CHANGED
|
@@ -3,9 +3,11 @@ import { getUrl, UrlProcessor } from '../UrlProcessor';
|
|
|
3
3
|
import HTMLReactParser from 'html-react-parser';
|
|
4
4
|
import { ElementType } from 'domelementtype';
|
|
5
5
|
import BaseMacro from './BaseMacro';
|
|
6
|
+
import Link from 'next/link';
|
|
6
7
|
export function createReplacer(allData, meta, renderMacroInEditMode = true, customReplacer) {
|
|
7
8
|
// eslint-disable-next-line react/display-name
|
|
8
9
|
return (domNode) => {
|
|
10
|
+
var _a;
|
|
9
11
|
if (domNode.type !== ElementType.Tag) {
|
|
10
12
|
return domNode;
|
|
11
13
|
}
|
|
@@ -31,7 +33,8 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
31
33
|
ref = el.attribs[UrlProcessor.LINK_ATTR];
|
|
32
34
|
const href = el.attribs['href'];
|
|
33
35
|
if (ref && href) {
|
|
34
|
-
el.
|
|
36
|
+
const textChild = (_a = el.children) === null || _a === void 0 ? void 0 : _a.find(c => c.type === ElementType.Text);
|
|
37
|
+
return <Link href={getUrl(href, meta)}>{textChild === null || textChild === void 0 ? void 0 : textChild.data}</Link>;
|
|
35
38
|
}
|
|
36
39
|
break;
|
|
37
40
|
case UrlProcessor.MACRO_TAG:
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { CacheHandler, CacheHandlerContext, CacheHandlerValue } from 'next/dist/server/lib/incremental-cache';
|
|
2
|
-
import { CacheFs } from 'next/dist/shared/lib/utils';
|
|
3
|
-
type FileSystemCacheContext = Omit<CacheHandlerContext, 'fs' | 'serverDistDir'> & {
|
|
4
|
-
fs: CacheFs;
|
|
5
|
-
serverDistDir: string;
|
|
6
|
-
};
|
|
7
|
-
export default class FileSystemCache implements CacheHandler {
|
|
8
|
-
private fs;
|
|
9
|
-
private flushToDisk?;
|
|
10
|
-
private serverDistDir;
|
|
11
|
-
private appDir;
|
|
12
|
-
private tagsManifestPath?;
|
|
13
|
-
private revalidatedTags;
|
|
14
|
-
constructor(ctx: FileSystemCacheContext);
|
|
15
|
-
clear(): void;
|
|
16
|
-
delete(path: string): boolean | undefined;
|
|
17
|
-
private loadTagsManifest;
|
|
18
|
-
setTags(key: string, tags: string[]): Promise<void>;
|
|
19
|
-
revalidateTag(tag: string): Promise<void>;
|
|
20
|
-
get(key: string, fetchCache?: boolean): Promise<CacheHandlerValue | null>;
|
|
21
|
-
set(key: string, data: CacheHandlerValue['value']): Promise<void>;
|
|
22
|
-
getFsPath({ pathname, appDir, fetchCache, }: {
|
|
23
|
-
pathname: string;
|
|
24
|
-
appDir?: boolean;
|
|
25
|
-
fetchCache?: boolean;
|
|
26
|
-
}): Promise<{
|
|
27
|
-
filePath: string;
|
|
28
|
-
isAppPath: boolean;
|
|
29
|
-
}>;
|
|
30
|
-
}
|
|
31
|
-
export {};
|