@enonic/nextjs-adapter 1.0.1 → 2.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/ComponentRegistry.d.ts +1 -1
- package/ComponentRegistry.js +1 -2
- package/UrlProcessor.d.ts +5 -3
- package/UrlProcessor.js +38 -25
- package/baseMappings.js +4 -0
- package/guillotine/fetchContent.d.ts +10 -25
- package/guillotine/fetchContent.js +122 -32
- package/guillotine/getMetaData.d.ts +3 -0
- package/package.json +14 -14
- package/query/Shortcut.d.ts +1 -0
- package/query/Shortcut.js +14 -0
- package/server/ClearableFileCache.d.ts +4 -0
- package/server/ClearableFileCache.js +156 -52
- package/server/cache.js +6 -6
- package/server/index.js +63 -51
- package/utils.d.ts +61 -4
- package/utils.js +123 -26
- package/views/BaseComponent.d.ts +4 -4
- package/views/BaseContent.d.ts +2 -2
- package/views/BaseLayout.d.ts +2 -2
- package/views/BaseMacro.d.ts +2 -2
- package/views/BasePage.d.ts +2 -2
- package/views/BasePart.d.ts +2 -2
- package/views/Empty.d.ts +2 -2
- package/views/Fragment.d.ts +2 -2
- package/views/Fragment.jsx +12 -7
- package/views/MainView.d.ts +2 -2
- package/views/Region.d.ts +3 -3
- package/views/RichTextView.d.ts +2 -2
- package/views/SingleComponent.d.ts +2 -2
- package/views/StaticContent.d.ts +5 -5
- package/views/StaticContent.jsx +18 -20
- package/views/Text.d.ts +2 -2
package/utils.js
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
const mode = process.env.MODE || process.env.NEXT_PUBLIC_MODE;
|
|
2
2
|
export const IS_DEV_MODE = (mode === 'development');
|
|
3
|
+
export var ENV_VARS;
|
|
4
|
+
(function (ENV_VARS) {
|
|
5
|
+
ENV_VARS["PROJECTS"] = "ENONIC_PROJECTS";
|
|
6
|
+
ENV_VARS["API"] = "ENONIC_API";
|
|
7
|
+
ENV_VARS["API_TOKEN"] = "ENONIC_API_TOKEN";
|
|
8
|
+
})(ENV_VARS || (ENV_VARS = {}));
|
|
3
9
|
/** URL to the guillotine API */
|
|
4
|
-
const
|
|
5
|
-
|
|
10
|
+
const API_URL = (process.env.ENONIC_API || process.env.NEXT_PUBLIC_ENONIC_API);
|
|
11
|
+
/** Locales and Enonic XP projects correspondence list */
|
|
12
|
+
const PROJECTS = (process.env.ENONIC_PROJECTS || process.env.NEXT_PUBLIC_ENONIC_PROJECTS);
|
|
6
13
|
/** Optional utility value - defining in one place the name of the target app (the app that defines the content types, the app name is therefore part of the content type strings used both in typeselector and in query introspections) */
|
|
7
|
-
export const APP_NAME = (process.env.
|
|
14
|
+
export const APP_NAME = (process.env.ENONIC_APP_NAME || process.env.NEXT_PUBLIC_ENONIC_APP_NAME);
|
|
8
15
|
/** Optional utility value - derived from APP_NAME, only with underscores instead of dots */
|
|
9
16
|
export const APP_NAME_UNDERSCORED = (APP_NAME || '').replace(/\./g, '_');
|
|
10
17
|
/** Optional utility value - derived from APP_NAME, only with dashes instead of dots */
|
|
11
18
|
export const APP_NAME_DASHED = (APP_NAME || '').replace(/\./g, '-');
|
|
12
|
-
|
|
19
|
+
const PROJECT_CONFIG_REGEXP = new RegExp('^(?:([\\w-]+):)?([^\\/\\s]+)(\\/[\\w-.]+)?$', 'i');
|
|
13
20
|
// //////////////////////////////////////////////////////////////////////// Hardcode-able constants
|
|
14
21
|
// URI parameter marking that a request is for a preview for CS. MUST MATCH THE VALUE OF 'FROM_XP_PARAM' on XP side.
|
|
15
22
|
export const XP_BASE_URL_HEADER = 'xpbaseurl';
|
|
16
23
|
export const RENDER_MODE_HEADER = 'content-studio-mode';
|
|
24
|
+
export const PROJECT_ID_HEADER = 'content-studio-project';
|
|
17
25
|
export const JSESSIONID_HEADER = 'jsessionid';
|
|
18
26
|
export const PORTAL_COMPONENT_ATTRIBUTE = 'data-portal-component-type';
|
|
19
27
|
export const PORTAL_REGION_ATTRIBUTE = 'data-portal-region';
|
|
@@ -22,6 +30,26 @@ export const FRAGMENT_DEFAULT_REGION_NAME = 'fragment';
|
|
|
22
30
|
export const PAGE_TEMPLATE_CONTENTTYPE_NAME = 'portal:page-template';
|
|
23
31
|
export const PAGE_TEMPLATE_FOLDER = 'portal:template-folder';
|
|
24
32
|
export const SITE_CONTENTTYPE_NAME = 'portal:site';
|
|
33
|
+
export const LOCALE_HEADER = 'locale';
|
|
34
|
+
export const LOCALES_HEADER = 'locales';
|
|
35
|
+
export const DEFAULT_LOCALE_HEADER = 'default-locale';
|
|
36
|
+
/** excluded contents:
|
|
37
|
+
* - folder
|
|
38
|
+
* - shortcuts (redirect can't be used in prerender)
|
|
39
|
+
* - media
|
|
40
|
+
* - paths with '/_' in them
|
|
41
|
+
*/
|
|
42
|
+
export const GET_STATIC_PATHS_QUERY = `query ($count: Int = 100){
|
|
43
|
+
guillotine {
|
|
44
|
+
query(query: "type != 'base:folder' AND type != 'base:shortcut' AND type NOT LIKE 'media:*' AND _path NOT LIKE '*/_*'", first: $count) {
|
|
45
|
+
_name
|
|
46
|
+
_path
|
|
47
|
+
site {
|
|
48
|
+
_name
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}`;
|
|
25
53
|
// ------------------------------- Exports and auxillary functions derived from values above ------------------------------------
|
|
26
54
|
export var XP_REQUEST_TYPE;
|
|
27
55
|
(function (XP_REQUEST_TYPE) {
|
|
@@ -53,39 +81,109 @@ export const getRenderMode = (context) => {
|
|
|
53
81
|
const enumValue = RENDER_MODE[value === null || value === void 0 ? void 0 : value.toUpperCase()];
|
|
54
82
|
return enumValue || RENDER_MODE[process.env.RENDER_MODE] || RENDER_MODE.NEXT;
|
|
55
83
|
};
|
|
84
|
+
export function normalizeLocale(locale) {
|
|
85
|
+
return locale !== 'default' ? locale : undefined;
|
|
86
|
+
}
|
|
87
|
+
export function getLocaleProjectConfig(context) {
|
|
88
|
+
var _a;
|
|
89
|
+
const projectId = (((_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers) || {})[PROJECT_ID_HEADER];
|
|
90
|
+
if (projectId) {
|
|
91
|
+
return getLocaleProjectConfigById(projectId);
|
|
92
|
+
}
|
|
93
|
+
const projectsConfig = getLocaleProjectConfigs();
|
|
94
|
+
const locale = (context === null || context === void 0 ? void 0 : context.locale) || (context === null || context === void 0 ? void 0 : context.defaultLocale);
|
|
95
|
+
let config = projectsConfig[locale];
|
|
96
|
+
if (!config) {
|
|
97
|
+
config = projectsConfig.default;
|
|
98
|
+
}
|
|
99
|
+
if (!config) {
|
|
100
|
+
throw new Error(`No config for locale "${locale}" found in "${ENV_VARS.PROJECTS}" environmental variable.
|
|
101
|
+
Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
102
|
+
}
|
|
103
|
+
return config;
|
|
104
|
+
}
|
|
105
|
+
export function getLocaleProjectConfigById(projectId, useDefault = true) {
|
|
106
|
+
const projects = getLocaleProjectConfigs();
|
|
107
|
+
if (!projectId) {
|
|
108
|
+
return useDefault ? projects.default : undefined;
|
|
109
|
+
}
|
|
110
|
+
const match = Object.values(projects).find(p => {
|
|
111
|
+
var _a;
|
|
112
|
+
return ((_a = p === null || p === void 0 ? void 0 : p.project) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === projectId.toLowerCase();
|
|
113
|
+
});
|
|
114
|
+
return match || (useDefault ? projects.default : undefined);
|
|
115
|
+
}
|
|
116
|
+
export function getLocaleProjectConfigs() {
|
|
117
|
+
const str = PROJECTS;
|
|
118
|
+
const envVarName = ENV_VARS.PROJECTS;
|
|
119
|
+
if (!(str === null || str === void 0 ? void 0 : str.length)) {
|
|
120
|
+
throw Error(`"${envVarName}" environmental variable is required.`);
|
|
121
|
+
}
|
|
122
|
+
const result = str.split(',').reduce((config, prjStr) => {
|
|
123
|
+
const matches = PROJECT_CONFIG_REGEXP.exec(prjStr === null || prjStr === void 0 ? void 0 : prjStr.trim());
|
|
124
|
+
if (!(matches === null || matches === void 0 ? void 0 : matches.length)) {
|
|
125
|
+
return config;
|
|
126
|
+
}
|
|
127
|
+
const [full, lang = 'default', project, site] = matches;
|
|
128
|
+
if (project && site) {
|
|
129
|
+
config[lang] = {
|
|
130
|
+
project,
|
|
131
|
+
site,
|
|
132
|
+
locale: lang,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
throw Error(`Wrong configuration in "${envVarName}": ${prjStr}.
|
|
137
|
+
Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
138
|
+
}
|
|
139
|
+
return config;
|
|
140
|
+
}, {
|
|
141
|
+
default: {
|
|
142
|
+
project: '',
|
|
143
|
+
site: '',
|
|
144
|
+
locale: '',
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
if (!result.default.site || !result.default.project) {
|
|
148
|
+
throw Error(`"${envVarName}" environmental variable should contain default value.
|
|
149
|
+
Format: <default-repository-name>/<site-path>,<language>:<repository-name>/<site-path>,...`);
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
export function fixDoubleSlashes(str) {
|
|
154
|
+
return str.replace(/(^|[^:/])\/{2,}/g, '$1/');
|
|
155
|
+
}
|
|
56
156
|
export function getContentApiUrl(context) {
|
|
57
|
-
const
|
|
58
|
-
|
|
157
|
+
const project = getLocaleProjectConfig(context).project;
|
|
158
|
+
const branch = getRenderMode(context) === RENDER_MODE.NEXT ? 'master' : 'draft';
|
|
159
|
+
return fixDoubleSlashes(`${API_URL}/${project}/${branch}`);
|
|
59
160
|
}
|
|
60
|
-
export function
|
|
161
|
+
export function addJsessionHeaders(headers = {}, context) {
|
|
61
162
|
var _a;
|
|
62
|
-
const headers = {};
|
|
63
163
|
const jsessionid = (_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers[JSESSIONID_HEADER];
|
|
64
164
|
if (jsessionid) {
|
|
65
165
|
headers['Cookie'] = `${JSESSIONID_HEADER}=${jsessionid}`;
|
|
66
166
|
}
|
|
67
|
-
return headers;
|
|
68
167
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
168
|
+
export function addLocaleHeaders(headers = {}, context) {
|
|
169
|
+
const locale = context === null || context === void 0 ? void 0 : context.locale;
|
|
170
|
+
if (locale) {
|
|
171
|
+
headers[LOCALE_HEADER] = locale;
|
|
172
|
+
}
|
|
173
|
+
const locales = context === null || context === void 0 ? void 0 : context.locales;
|
|
174
|
+
if (locales) {
|
|
175
|
+
headers[LOCALES_HEADER] = JSON.stringify(locales);
|
|
176
|
+
}
|
|
177
|
+
const defaultLocale = context === null || context === void 0 ? void 0 : context.defaultLocale;
|
|
178
|
+
if (defaultLocale) {
|
|
179
|
+
headers[DEFAULT_LOCALE_HEADER] = defaultLocale;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
77
182
|
export const getXpBaseUrl = (context) => {
|
|
78
183
|
var _a;
|
|
79
|
-
const mode = getRenderMode(context);
|
|
80
|
-
const existingUrl = xpBaseUrlMap[mode];
|
|
81
|
-
if (existingUrl) {
|
|
82
|
-
return existingUrl;
|
|
83
|
-
}
|
|
84
184
|
const header = ((((_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers) || {})[XP_BASE_URL_HEADER] || '');
|
|
85
185
|
// TODO: workaround for XP pattern controller mapping not picked up in edit mode
|
|
86
|
-
|
|
87
|
-
xpBaseUrlMap[mode] = resultingUrl;
|
|
88
|
-
return resultingUrl;
|
|
186
|
+
return (header || '/').replace(/\/edit\//, '/inline/');
|
|
89
187
|
};
|
|
90
188
|
export const commonChars = (s1, s2) => {
|
|
91
189
|
let result = '';
|
|
@@ -120,7 +218,6 @@ const adapterConstants = {
|
|
|
120
218
|
APP_NAME,
|
|
121
219
|
APP_NAME_UNDERSCORED,
|
|
122
220
|
APP_NAME_DASHED,
|
|
123
|
-
SITE_KEY,
|
|
124
221
|
PORTAL_COMPONENT_ATTRIBUTE,
|
|
125
222
|
PORTAL_REGION_ATTRIBUTE,
|
|
126
223
|
};
|
package/views/BaseComponent.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { MetaData, PageComponent } from '../guillotine/getMetaData';
|
|
3
3
|
export type BaseComponentProps = {
|
|
4
4
|
component: PageComponent;
|
|
@@ -10,16 +10,16 @@ export default BaseComponent;
|
|
|
10
10
|
export declare const MissingComponent: ({ descriptor, type }: {
|
|
11
11
|
descriptor?: string;
|
|
12
12
|
type: string;
|
|
13
|
-
}) => JSX.Element;
|
|
13
|
+
}) => React.JSX.Element;
|
|
14
14
|
export declare function shouldShowMissingView(meta: MetaData): boolean;
|
|
15
15
|
export declare const ErrorComponent: ({ type, descriptor, reason }: {
|
|
16
16
|
type?: string;
|
|
17
17
|
descriptor?: string;
|
|
18
18
|
reason: string;
|
|
19
|
-
}) => JSX.Element;
|
|
19
|
+
}) => React.JSX.Element;
|
|
20
20
|
export declare function shouldShowErrorView(meta: MetaData): boolean;
|
|
21
21
|
export declare const PlaceholderComponent: ({ type, descriptor }: {
|
|
22
22
|
type?: string;
|
|
23
23
|
descriptor?: string;
|
|
24
|
-
}) => JSX.Element;
|
|
24
|
+
}) => React.JSX.Element;
|
|
25
25
|
export declare function shouldShowPlaceholderView(meta: MetaData): boolean;
|
package/views/BaseContent.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FetchContentResult } from '../guillotine/fetchContent';
|
|
3
|
-
declare const BaseContent: (props: FetchContentResult) => JSX.Element;
|
|
3
|
+
declare const BaseContent: (props: FetchContentResult) => React.JSX.Element;
|
|
4
4
|
export default BaseContent;
|
package/views/BaseLayout.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { LayoutData, MetaData, RegionTree } from '../guillotine/getMetaData';
|
|
3
3
|
export interface LayoutProps {
|
|
4
4
|
layout: LayoutData;
|
|
@@ -13,5 +13,5 @@ interface BaseLayoutProps {
|
|
|
13
13
|
common?: any;
|
|
14
14
|
meta: MetaData;
|
|
15
15
|
}
|
|
16
|
-
declare const BaseLayout: (props: BaseLayoutProps) => JSX.Element;
|
|
16
|
+
declare const BaseLayout: (props: BaseLayoutProps) => React.JSX.Element;
|
|
17
17
|
export default BaseLayout;
|
package/views/BaseMacro.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { MacroConfig, MacroData, MetaData } from '../guillotine/getMetaData';
|
|
3
3
|
export declare const MACRO_DISABLE = "system:disable";
|
|
4
4
|
export declare const MACRO_EMBED = "system:embed";
|
|
@@ -12,5 +12,5 @@ export interface MacroProps {
|
|
|
12
12
|
config: MacroConfig;
|
|
13
13
|
meta: MetaData;
|
|
14
14
|
}
|
|
15
|
-
declare const BaseMacro: (props: BaseMacroProps) => JSX.Element;
|
|
15
|
+
declare const BaseMacro: (props: BaseMacroProps) => React.JSX.Element;
|
|
16
16
|
export default BaseMacro;
|
package/views/BasePage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { MetaData, PageData } from '../guillotine/getMetaData';
|
|
3
3
|
export interface PageProps {
|
|
4
4
|
page: PageData;
|
|
@@ -15,5 +15,5 @@ export interface BasePageProps {
|
|
|
15
15
|
error?: string;
|
|
16
16
|
meta: MetaData;
|
|
17
17
|
}
|
|
18
|
-
declare const BasePage: (props: BasePageProps) => JSX.Element;
|
|
18
|
+
declare const BasePage: (props: BasePageProps) => React.JSX.Element;
|
|
19
19
|
export default BasePage;
|
package/views/BasePart.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { MetaData, PartData } from '../guillotine/getMetaData';
|
|
3
3
|
export interface PartProps {
|
|
4
4
|
part: PartData;
|
|
@@ -15,5 +15,5 @@ interface BasePartProps {
|
|
|
15
15
|
error?: string;
|
|
16
16
|
meta: MetaData;
|
|
17
17
|
}
|
|
18
|
-
declare const BasePart: (props: BasePartProps) => JSX.Element;
|
|
18
|
+
declare const BasePart: (props: BasePartProps) => React.JSX.Element;
|
|
19
19
|
export default BasePart;
|
package/views/Empty.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare const Empty: () => JSX.Element;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare const Empty: () => React.JSX.Element;
|
|
3
3
|
export default Empty;
|
package/views/Fragment.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FragmentData, MetaData, PageData } from '../guillotine/getMetaData';
|
|
3
3
|
interface FragmentProps {
|
|
4
4
|
page?: PageData;
|
|
@@ -6,5 +6,5 @@ interface FragmentProps {
|
|
|
6
6
|
common?: any;
|
|
7
7
|
meta: MetaData;
|
|
8
8
|
}
|
|
9
|
-
declare const FragmentView: (props: FragmentProps) => JSX.Element;
|
|
9
|
+
declare const FragmentView: (props: FragmentProps) => React.JSX.Element;
|
|
10
10
|
export default FragmentView;
|
package/views/Fragment.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import BaseComponent from './BaseComponent';
|
|
3
|
-
import { FRAGMENT_DEFAULT_REGION_NAME } from '../utils';
|
|
2
|
+
import BaseComponent, { MissingComponent, shouldShowMissingView } from './BaseComponent';
|
|
3
|
+
import { FRAGMENT_DEFAULT_REGION_NAME, XP_COMPONENT_TYPE } from '../utils';
|
|
4
4
|
const FragmentView = (props) => {
|
|
5
5
|
var _a;
|
|
6
6
|
const { component, page } = props;
|
|
@@ -13,13 +13,18 @@ const FragmentView = (props) => {
|
|
|
13
13
|
comps.push(...regionComps);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
else if (component) {
|
|
16
|
+
else if (component === null || component === void 0 ? void 0 : component.fragment) {
|
|
17
17
|
// rendering a part of a page
|
|
18
18
|
comps.push(...component.fragment.components);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
if (!comps.length && shouldShowMissingView(props.meta)) {
|
|
21
|
+
return <MissingComponent type={XP_COMPONENT_TYPE.FRAGMENT} descriptor={(page === null || page === void 0 ? void 0 : page.descriptor) || (component === null || component === void 0 ? void 0 : component.id)}/>;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const { common, meta } = props;
|
|
25
|
+
return (<>
|
|
26
|
+
{comps.map((comp, i) => (<BaseComponent key={i} component={comp} common={common} meta={meta}/>))}
|
|
27
|
+
</>);
|
|
28
|
+
}
|
|
24
29
|
};
|
|
25
30
|
export default FragmentView;
|
package/views/MainView.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FetchContentResult } from '../guillotine/fetchContent';
|
|
3
|
-
declare const _MainView: (props: FetchContentResult) => JSX.Element;
|
|
3
|
+
declare const _MainView: (props: FetchContentResult) => React.JSX.Element;
|
|
4
4
|
export default _MainView;
|
package/views/Region.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { MetaData, PageComponent, PageData } from '../guillotine/getMetaData';
|
|
3
3
|
export interface RegionProps {
|
|
4
4
|
name: string;
|
|
@@ -14,7 +14,7 @@ export interface RegionsProps {
|
|
|
14
14
|
meta: MetaData;
|
|
15
15
|
}
|
|
16
16
|
/** Single region */
|
|
17
|
-
export declare const RegionView: (props: RegionProps) => JSX.Element;
|
|
17
|
+
export declare const RegionView: (props: RegionProps) => React.JSX.Element;
|
|
18
18
|
/** Multiple regions, or only one if named in props.selected */
|
|
19
|
-
declare const RegionsView: (props: RegionsProps) => JSX.Element;
|
|
19
|
+
declare const RegionsView: (props: RegionsProps) => React.JSX.Element;
|
|
20
20
|
export default RegionsView;
|
package/views/RichTextView.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { MetaData, RichTextData } from '../guillotine/getMetaData';
|
|
3
3
|
import { DOMNode } from 'html-react-parser';
|
|
4
4
|
export type ReplacerResult = JSX.Element | object | void | undefined | null | false;
|
|
@@ -12,5 +12,5 @@ type Props = {
|
|
|
12
12
|
customReplacer?: Replacer;
|
|
13
13
|
};
|
|
14
14
|
export declare function createReplacer(allData: RichTextData, meta: MetaData, renderMacroInEditMode?: boolean, customReplacer?: Replacer): (domNode: DOMNode) => ReplacerResult;
|
|
15
|
-
declare const RichTextView: ({ className, tag, data, meta, renderMacroInEditMode, customReplacer }: Props) => JSX.Element;
|
|
15
|
+
declare const RichTextView: ({ className, tag, data, meta, renderMacroInEditMode, customReplacer }: Props) => React.JSX.Element;
|
|
16
16
|
export default RichTextView;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Render only one component as a result of a request from XP-side .../_/component/... during edit refresh. */
|
|
2
|
-
|
|
2
|
+
import React from 'react';
|
|
3
3
|
import { FetchContentResult } from '../guillotine/fetchContent';
|
|
4
|
-
declare const SingleComponent: ({ meta, common }: FetchContentResult) => JSX.Element;
|
|
4
|
+
declare const SingleComponent: ({ meta, common }: FetchContentResult) => React.JSX.Element;
|
|
5
5
|
export default SingleComponent;
|
package/views/StaticContent.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ export interface StaticContentProps extends Record<string, any> {
|
|
|
4
4
|
element?: string;
|
|
5
5
|
condition: boolean;
|
|
6
6
|
}
|
|
7
|
-
export default function StaticContent({ children, element, condition, ...props }: StaticContentProps): import("react").
|
|
8
|
-
|
|
9
|
-
}, Element> | import("react").ReactElement<{
|
|
10
|
-
ref: boolean | import("react").MutableRefObject<any>;
|
|
7
|
+
export default function StaticContent({ children, element, condition, ...props }: StaticContentProps): import("react").ReactElement<{
|
|
8
|
+
ref: import("react").RefObject<unknown>;
|
|
11
9
|
suppressHydrationWarning: boolean;
|
|
12
10
|
dangerouslySetInnerHTML: {
|
|
13
11
|
__html: string;
|
|
14
12
|
};
|
|
15
|
-
}, string | import("react").JSXElementConstructor<any
|
|
13
|
+
}, string | import("react").JSXElementConstructor<any>> | import("react").DOMElement<{
|
|
14
|
+
[x: string]: any;
|
|
15
|
+
}, Element>;
|
package/views/StaticContent.jsx
CHANGED
|
@@ -9,30 +9,28 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { createElement,
|
|
13
|
-
function useStaticContent() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
setRender(true);
|
|
23
|
-
}
|
|
24
|
-
}, []);
|
|
25
|
-
return [render, ref];
|
|
12
|
+
import { createElement, createRef } from 'react';
|
|
13
|
+
function useStaticContent(ref, isServer) {
|
|
14
|
+
var _a;
|
|
15
|
+
if (isServer) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (((_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.innerHTML) === '') {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
26
22
|
}
|
|
27
23
|
export default function StaticContent(_a) {
|
|
28
24
|
var { children, element = 'div', condition = true } = _a, props = __rest(_a, ["children", "element", "condition"]);
|
|
29
|
-
const
|
|
25
|
+
const isServer = typeof window === 'undefined';
|
|
26
|
+
const ref = createRef();
|
|
27
|
+
const isStatic = useStaticContent(ref, isServer);
|
|
28
|
+
// avoid re-render on the client
|
|
29
|
+
if (isStatic && condition) {
|
|
30
|
+
return createElement(element, Object.assign(Object.assign({}, props), { ref, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: '' } }));
|
|
31
|
+
}
|
|
30
32
|
// just render if:
|
|
31
33
|
// - condition is false
|
|
32
34
|
// - we're in the server or a spa navigation
|
|
33
|
-
|
|
34
|
-
return createElement(element, props, ...[].concat(children));
|
|
35
|
-
}
|
|
36
|
-
// avoid re-render on the client
|
|
37
|
-
return createElement(element, Object.assign(Object.assign({}, props), { ref, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: '' } }));
|
|
35
|
+
return createElement(element, props, ...[].concat(children));
|
|
38
36
|
}
|
package/views/Text.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { MetaData, TextData } from '../guillotine/getMetaData';
|
|
3
3
|
type Props = {
|
|
4
4
|
meta: MetaData;
|
|
5
5
|
component: TextData;
|
|
6
6
|
path: string;
|
|
7
7
|
};
|
|
8
|
-
declare const DefaultTextView: ({ component, meta, path }: Props) => JSX.Element;
|
|
8
|
+
declare const DefaultTextView: ({ component, meta, path }: Props) => React.JSX.Element;
|
|
9
9
|
export default DefaultTextView;
|