@enonic/nextjs-adapter 0.10.0 → 0.11.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/ComponentRegistry.d.ts +10 -9
- package/ComponentRegistry.js +35 -35
- package/guillotine/fetchContent.d.ts +10 -10
- package/guillotine/fetchContent.js +31 -18
- package/package.json +8 -8
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
- package/views/BaseComponent.d.ts +1 -1
- package/views/RichTextView.d.ts +5 -4
- package/views/RichTextView.jsx +2 -2
- package/views/Text.d.ts +1 -1
package/ComponentRegistry.d.ts
CHANGED
|
@@ -14,17 +14,18 @@ export interface ComponentDefinition {
|
|
|
14
14
|
processor?: DataProcessor;
|
|
15
15
|
view?: React.FunctionComponent<any>;
|
|
16
16
|
}
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
17
|
+
export type DataProcessor = (data: any, context?: Context) => Promise<Record<string, any>>;
|
|
18
|
+
export type VariablesGetter = (path: string, context?: Context, config?: any) => VariablesGetterResult;
|
|
19
|
+
export type QueryGetter = (config?: any) => string;
|
|
20
|
+
export type VariablesGetterResult = {
|
|
20
21
|
[variables: string]: any;
|
|
21
22
|
path: string;
|
|
22
23
|
};
|
|
23
|
-
export
|
|
24
|
-
query: string;
|
|
24
|
+
export type SelectedQueryMaybeVariablesFunc = string | QueryGetter | {
|
|
25
|
+
query: string | QueryGetter;
|
|
25
26
|
variables: VariablesGetter;
|
|
26
27
|
} | [
|
|
27
|
-
string,
|
|
28
|
+
string | QueryGetter,
|
|
28
29
|
VariablesGetter
|
|
29
30
|
];
|
|
30
31
|
export declare const CATCH_ALL = "*";
|
|
@@ -36,6 +37,9 @@ export declare class ComponentRegistry {
|
|
|
36
37
|
private static layouts;
|
|
37
38
|
private static macros;
|
|
38
39
|
private static commonQuery;
|
|
40
|
+
private static getSelector;
|
|
41
|
+
private static getType;
|
|
42
|
+
private static addType;
|
|
39
43
|
static getByComponent(component: PageComponent): ComponentDefinition | undefined;
|
|
40
44
|
static setCommonQuery(query: SelectedQueryMaybeVariablesFunc): void;
|
|
41
45
|
static getCommonQuery(): SelectedQueryMaybeVariablesFunc;
|
|
@@ -55,7 +59,4 @@ export declare class ComponentRegistry {
|
|
|
55
59
|
static getLayout(name: string): ComponentDefinition | undefined;
|
|
56
60
|
static addComponent(name: string, obj: ComponentDefinition): void;
|
|
57
61
|
static getComponent(name: string): ComponentDefinition | undefined;
|
|
58
|
-
private static getSelector;
|
|
59
|
-
private static getType;
|
|
60
|
-
private static addType;
|
|
61
62
|
}
|
package/ComponentRegistry.js
CHANGED
|
@@ -11,6 +11,41 @@ function toSelectorName(type) {
|
|
|
11
11
|
}
|
|
12
12
|
export const CATCH_ALL = '*';
|
|
13
13
|
export class ComponentRegistry {
|
|
14
|
+
static getSelector(name) {
|
|
15
|
+
switch (name) {
|
|
16
|
+
case 'contentType':
|
|
17
|
+
return this.contentTypes;
|
|
18
|
+
case 'page':
|
|
19
|
+
return this.pages;
|
|
20
|
+
case 'component':
|
|
21
|
+
return this.components;
|
|
22
|
+
case 'layout':
|
|
23
|
+
return this.layouts;
|
|
24
|
+
case 'part':
|
|
25
|
+
return this.parts;
|
|
26
|
+
case 'macro':
|
|
27
|
+
return this.macros;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static getType(selectorName, typeName, useCatchAll = true) {
|
|
31
|
+
const selector = ComponentRegistry.getSelector(selectorName);
|
|
32
|
+
let type = selector[typeName];
|
|
33
|
+
if (type) {
|
|
34
|
+
type.catchAll = false;
|
|
35
|
+
}
|
|
36
|
+
else if (!type && useCatchAll) {
|
|
37
|
+
type = selector[CATCH_ALL];
|
|
38
|
+
if (type) {
|
|
39
|
+
type.catchAll = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return type;
|
|
43
|
+
}
|
|
44
|
+
static addType(selectorName, name, obj) {
|
|
45
|
+
const selector = ComponentRegistry.getSelector(selectorName);
|
|
46
|
+
const curr = selector[name];
|
|
47
|
+
selector[name] = curr ? Object.assign(curr, obj) : obj;
|
|
48
|
+
}
|
|
14
49
|
static getByComponent(component) {
|
|
15
50
|
const selName = toSelectorName(component.type);
|
|
16
51
|
const cmpData = component[component.type];
|
|
@@ -71,41 +106,6 @@ export class ComponentRegistry {
|
|
|
71
106
|
static getComponent(name) {
|
|
72
107
|
return ComponentRegistry.getType('component', name);
|
|
73
108
|
}
|
|
74
|
-
static getSelector(name) {
|
|
75
|
-
switch (name) {
|
|
76
|
-
case 'contentType':
|
|
77
|
-
return this.contentTypes;
|
|
78
|
-
case 'page':
|
|
79
|
-
return this.pages;
|
|
80
|
-
case 'component':
|
|
81
|
-
return this.components;
|
|
82
|
-
case 'layout':
|
|
83
|
-
return this.layouts;
|
|
84
|
-
case 'part':
|
|
85
|
-
return this.parts;
|
|
86
|
-
case 'macro':
|
|
87
|
-
return this.macros;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
static getType(selectorName, typeName, useCatchAll = true) {
|
|
91
|
-
const selector = ComponentRegistry.getSelector(selectorName);
|
|
92
|
-
let type = selector[typeName];
|
|
93
|
-
if (type) {
|
|
94
|
-
type.catchAll = false;
|
|
95
|
-
}
|
|
96
|
-
else if (!type && useCatchAll) {
|
|
97
|
-
type = selector[CATCH_ALL];
|
|
98
|
-
if (type) {
|
|
99
|
-
type.catchAll = true;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return type;
|
|
103
|
-
}
|
|
104
|
-
static addType(selectorName, name, obj) {
|
|
105
|
-
const selector = ComponentRegistry.getSelector(selectorName);
|
|
106
|
-
const curr = selector[name];
|
|
107
|
-
selector[name] = curr ? Object.assign(curr, obj) : obj;
|
|
108
|
-
}
|
|
109
109
|
}
|
|
110
110
|
ComponentRegistry.contentTypes = {};
|
|
111
111
|
ComponentRegistry.pages = {};
|
|
@@ -7,7 +7,7 @@ import { ParsedUrlQuery } from 'node:querystring';
|
|
|
7
7
|
import { type GetServerSidePropsContext } from 'next';
|
|
8
8
|
import { IncomingMessage } from 'http';
|
|
9
9
|
import { type NextApiRequestCookies } from 'next/dist/server/api-utils';
|
|
10
|
-
export
|
|
10
|
+
export type AdapterConstants = {
|
|
11
11
|
APP_NAME: string;
|
|
12
12
|
APP_NAME_DASHED: string;
|
|
13
13
|
SITE_KEY: string;
|
|
@@ -15,22 +15,22 @@ export declare type AdapterConstants = {
|
|
|
15
15
|
getRenderMode: (context?: Context) => RENDER_MODE;
|
|
16
16
|
getSingleComponentPath: (context?: Context) => string | undefined;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
type Result = {
|
|
19
19
|
error?: {
|
|
20
20
|
code: string;
|
|
21
21
|
message: string;
|
|
22
22
|
} | null;
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
type GuillotineResult = Result & {
|
|
25
25
|
[dataKey: string]: any;
|
|
26
26
|
};
|
|
27
|
-
export
|
|
27
|
+
export type FetchContentResult = Result & {
|
|
28
28
|
data: Record<string, any> | null;
|
|
29
29
|
common: Record<string, any> | null;
|
|
30
30
|
meta: MetaData;
|
|
31
31
|
page: PageComponent | null;
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
type FetcherConfig<T extends AdapterConstants> = T & {
|
|
34
34
|
componentRegistry: typeof ComponentRegistry;
|
|
35
35
|
};
|
|
36
36
|
export interface ServerSideParams extends ParsedUrlQuery {
|
|
@@ -41,7 +41,7 @@ export interface PreviewParams {
|
|
|
41
41
|
contentPath: string[];
|
|
42
42
|
headers: Record<string, string>;
|
|
43
43
|
}
|
|
44
|
-
export
|
|
44
|
+
export type Context = GetServerSidePropsContext<ServerSideParams, PreviewParams>;
|
|
45
45
|
export interface MinimalContext {
|
|
46
46
|
req: IncomingMessage & {
|
|
47
47
|
cookies: NextApiRequestCookies;
|
|
@@ -52,17 +52,17 @@ export interface MinimalContext {
|
|
|
52
52
|
* @param contentPath string or string array: pre-split or slash-delimited _path to a content available on the API
|
|
53
53
|
* @returns FetchContentResult object: {data?: T, error?: {code, message}}
|
|
54
54
|
*/
|
|
55
|
-
export
|
|
56
|
-
export
|
|
55
|
+
export type ContentFetcher = (contentPath: string | string[], context: Context) => Promise<FetchContentResult>;
|
|
56
|
+
export type ContentApiBaseBody = {
|
|
57
57
|
query?: string;
|
|
58
58
|
variables?: {
|
|
59
59
|
path?: string;
|
|
60
60
|
};
|
|
61
61
|
};
|
|
62
62
|
/** Generic fetch */
|
|
63
|
-
export declare const fetchFromApi: (apiUrl: string, body: {}, method?: string) => Promise<any>;
|
|
63
|
+
export declare const fetchFromApi: (apiUrl: string, body: ContentApiBaseBody, headers?: {}, method?: string) => Promise<any>;
|
|
64
64
|
/** Guillotine-specialized fetch, using the generic fetch above */
|
|
65
|
-
export declare const fetchGuillotine: (contentApiUrl: string, body: ContentApiBaseBody, xpContentPath: string) => Promise<GuillotineResult>;
|
|
65
|
+
export declare const fetchGuillotine: (contentApiUrl: string, body: ContentApiBaseBody, xpContentPath: string, headers?: {}) => Promise<GuillotineResult>;
|
|
66
66
|
/**
|
|
67
67
|
* Configures, builds and returns a general fetchContent function.
|
|
68
68
|
* @param adapterConstants Object containing attributes imported from enonic-connecion-config.js: constants and function concerned with connection to the XP backend. Easiest: caller imports enonic-connection-config and just passes that entire object here as adapterConstants.
|
|
@@ -7,15 +7,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { getMetaQuery, pageFragmentQuery
|
|
11
|
-
import adapterConstants, { APP_NAME, APP_NAME_DASHED, FRAGMENT_CONTENTTYPE_NAME, FRAGMENT_DEFAULT_REGION_NAME, getContentApiUrl, getXpBaseUrl, IS_DEV_MODE, PAGE_TEMPLATE_CONTENTTYPE_NAME, PAGE_TEMPLATE_FOLDER, RENDER_MODE, sanitizeGraphqlName, SITE_KEY, XP_COMPONENT_TYPE, XP_REQUEST_TYPE, } from '../utils';
|
|
10
|
+
import { getMetaQuery, pageFragmentQuery } from './getMetaData';
|
|
11
|
+
import adapterConstants, { APP_NAME, APP_NAME_DASHED, FRAGMENT_CONTENTTYPE_NAME, FRAGMENT_DEFAULT_REGION_NAME, getContentApiUrl, getXpBaseUrl, IS_DEV_MODE, JSESSIONID_HEADER, PAGE_TEMPLATE_CONTENTTYPE_NAME, PAGE_TEMPLATE_FOLDER, RENDER_MODE, sanitizeGraphqlName, SITE_KEY, XP_COMPONENT_TYPE, XP_REQUEST_TYPE, } from '../utils';
|
|
12
12
|
import { ComponentRegistry } from '../ComponentRegistry';
|
|
13
13
|
const NO_PROPS_PROCESSOR = (props) => __awaiter(void 0, void 0, void 0, function* () { var _a; return (_a = yield props) !== null && _a !== void 0 ? _a : {}; });
|
|
14
14
|
const ALIAS_PREFIX = 'request';
|
|
15
15
|
const GUILLOTINE_QUERY_REGEXP = /^\s*query\s*(?:\((.*)*\))?\s*{\s*guillotine\s*{((?:.|\s)+)}\s*}\s*$/;
|
|
16
16
|
const GRAPHQL_FRAGMENTS_REGEXP = /fragment\s+.+\s+on\s+.+\s*{[\s\w{}().,:"'`]+}/;
|
|
17
17
|
/** Generic fetch */
|
|
18
|
-
export const fetchFromApi = (apiUrl, body, method = 'POST') => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
export const fetchFromApi = (apiUrl, body, headers, method = 'POST') => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
const options = {
|
|
20
20
|
method,
|
|
21
21
|
headers: {
|
|
@@ -25,6 +25,9 @@ export const fetchFromApi = (apiUrl, body, method = 'POST') => __awaiter(void 0,
|
|
|
25
25
|
},
|
|
26
26
|
body: JSON.stringify(body),
|
|
27
27
|
};
|
|
28
|
+
if (headers) {
|
|
29
|
+
Object.assign(options.headers, headers);
|
|
30
|
+
}
|
|
28
31
|
let res;
|
|
29
32
|
try {
|
|
30
33
|
res = yield fetch(apiUrl, options);
|
|
@@ -61,7 +64,7 @@ export const fetchFromApi = (apiUrl, body, method = 'POST') => __awaiter(void 0,
|
|
|
61
64
|
return json;
|
|
62
65
|
});
|
|
63
66
|
/** Guillotine-specialized fetch, using the generic fetch above */
|
|
64
|
-
export const fetchGuillotine = (contentApiUrl, body, xpContentPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
export const fetchGuillotine = (contentApiUrl, body, xpContentPath, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
68
|
if (typeof body.query !== 'string' || !body.query.trim()) {
|
|
66
69
|
return {
|
|
67
70
|
error: {
|
|
@@ -70,7 +73,7 @@ export const fetchGuillotine = (contentApiUrl, body, xpContentPath) => __awaiter
|
|
|
70
73
|
},
|
|
71
74
|
};
|
|
72
75
|
}
|
|
73
|
-
const result = yield fetchFromApi(contentApiUrl, body)
|
|
76
|
+
const result = yield fetchFromApi(contentApiUrl, body, headers)
|
|
74
77
|
.then(json => {
|
|
75
78
|
let errors = (json || {}).errors;
|
|
76
79
|
if (errors) {
|
|
@@ -104,7 +107,7 @@ export const fetchGuillotine = (contentApiUrl, body, xpContentPath) => __awaiter
|
|
|
104
107
|
return result;
|
|
105
108
|
});
|
|
106
109
|
// /////////////////////////////////////////////////////////////////////////////// Specific fetch wrappers:
|
|
107
|
-
const fetchMetaData = (contentApiUrl, xpContentPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
const fetchMetaData = (contentApiUrl, xpContentPath, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
111
|
var _b;
|
|
109
112
|
const body = {
|
|
110
113
|
query: getMetaQuery(pageFragmentQuery()),
|
|
@@ -112,7 +115,7 @@ const fetchMetaData = (contentApiUrl, xpContentPath) => __awaiter(void 0, void 0
|
|
|
112
115
|
path: xpContentPath,
|
|
113
116
|
},
|
|
114
117
|
};
|
|
115
|
-
const metaResult = yield fetchGuillotine(contentApiUrl, body, xpContentPath);
|
|
118
|
+
const metaResult = yield fetchGuillotine(contentApiUrl, body, xpContentPath, headers);
|
|
116
119
|
if (metaResult.error) {
|
|
117
120
|
return metaResult;
|
|
118
121
|
}
|
|
@@ -122,12 +125,12 @@ const fetchMetaData = (contentApiUrl, xpContentPath) => __awaiter(void 0, void 0
|
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
127
|
});
|
|
125
|
-
const fetchContentData = (contentApiUrl, xpContentPath, query, variables) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
const fetchContentData = (contentApiUrl, xpContentPath, query, variables, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
129
|
const body = { query };
|
|
127
130
|
if (variables && Object.keys(variables).length > 0) {
|
|
128
131
|
body.variables = variables;
|
|
129
132
|
}
|
|
130
|
-
const contentResults = yield fetchGuillotine(contentApiUrl, body, xpContentPath);
|
|
133
|
+
const contentResults = yield fetchGuillotine(contentApiUrl, body, xpContentPath, headers);
|
|
131
134
|
if (contentResults.error) {
|
|
132
135
|
return contentResults;
|
|
133
136
|
}
|
|
@@ -406,7 +409,7 @@ function processComponentConfig(myAppName, myAppNameDashed, cmp) {
|
|
|
406
409
|
}
|
|
407
410
|
function getQueryAndVariables(type, path, selectedQuery, context, config) {
|
|
408
411
|
let query, getVariables;
|
|
409
|
-
if (typeof selectedQuery === 'string') {
|
|
412
|
+
if (typeof selectedQuery === 'string' || typeof selectedQuery === 'function') {
|
|
410
413
|
query = selectedQuery;
|
|
411
414
|
}
|
|
412
415
|
else if (Array.isArray(selectedQuery)) {
|
|
@@ -420,12 +423,15 @@ function getQueryAndVariables(type, path, selectedQuery, context, config) {
|
|
|
420
423
|
if (getVariables && typeof getVariables !== 'function') {
|
|
421
424
|
throw Error(`getVariables for content type ${type} should be a function, not: ${typeof getVariables}`);
|
|
422
425
|
}
|
|
423
|
-
if (query && typeof query !== 'string') {
|
|
424
|
-
throw Error(`Query for content type ${type} should be a string, not: ${typeof query}`);
|
|
426
|
+
if (query && typeof query !== 'string' && typeof query !== 'function') {
|
|
427
|
+
throw Error(`Query for content type ${type} should be a string or function, not: ${typeof query}`);
|
|
428
|
+
}
|
|
429
|
+
if (typeof query === 'function') {
|
|
430
|
+
query = query(config);
|
|
425
431
|
}
|
|
426
432
|
if (query) {
|
|
427
433
|
return {
|
|
428
|
-
query
|
|
434
|
+
query,
|
|
429
435
|
variables: getVariables ? getVariables(path, context, config) : { path },
|
|
430
436
|
};
|
|
431
437
|
}
|
|
@@ -502,7 +508,14 @@ function errorResponse(code = '500', message = 'Unknown error', requestType, ren
|
|
|
502
508
|
export const buildContentFetcher = (config) => {
|
|
503
509
|
const { APP_NAME, APP_NAME_DASHED, getXPRequestType, getRenderMode, getSingleComponentPath, componentRegistry, } = config;
|
|
504
510
|
return (contentPathOrArray, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
505
|
-
var _a, _b;
|
|
511
|
+
var _a, _b, _c;
|
|
512
|
+
let headers;
|
|
513
|
+
const jsessionid = (_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers[JSESSIONID_HEADER];
|
|
514
|
+
if (jsessionid) {
|
|
515
|
+
headers = {
|
|
516
|
+
'Cookie': `${JSESSIONID_HEADER}=${jsessionid}`,
|
|
517
|
+
};
|
|
518
|
+
}
|
|
506
519
|
const xpBaseUrl = getXpBaseUrl(context);
|
|
507
520
|
const contentApiUrl = getContentApiUrl(context);
|
|
508
521
|
const requestType = getXPRequestType(context);
|
|
@@ -515,7 +528,7 @@ export const buildContentFetcher = (config) => {
|
|
|
515
528
|
requestedComponentPath = getSingleComponentPath(context);
|
|
516
529
|
}
|
|
517
530
|
// ///////////// FIRST GUILLOTINE CALL FOR METADATA /////////////////
|
|
518
|
-
const metaResult = yield fetchMetaData(contentApiUrl, '${site}/' + siteRelativeContentPath);
|
|
531
|
+
const metaResult = yield fetchMetaData(contentApiUrl, '${site}/' + siteRelativeContentPath, headers);
|
|
519
532
|
// ///////////////////////////////////////////////////////////////////////
|
|
520
533
|
const { type, components, _path } = metaResult.meta || {};
|
|
521
534
|
contentPath = _path || '';
|
|
@@ -542,14 +555,14 @@ export const buildContentFetcher = (config) => {
|
|
|
542
555
|
if (pageCmp) {
|
|
543
556
|
processComponentConfig(APP_NAME, APP_NAME_DASHED, pageCmp);
|
|
544
557
|
}
|
|
545
|
-
const contentQueryAndVars = getQueryAndVariables(type, contentPath, contentTypeDef === null || contentTypeDef === void 0 ? void 0 : contentTypeDef.query, context, (
|
|
558
|
+
const contentQueryAndVars = getQueryAndVariables(type, contentPath, contentTypeDef === null || contentTypeDef === void 0 ? void 0 : contentTypeDef.query, context, (_b = pageCmp === null || pageCmp === void 0 ? void 0 : pageCmp.page) === null || _b === void 0 ? void 0 : _b.config);
|
|
546
559
|
if (contentQueryAndVars) {
|
|
547
560
|
allDescriptors.push({
|
|
548
561
|
type: contentTypeDef,
|
|
549
562
|
queryAndVariables: contentQueryAndVars,
|
|
550
563
|
});
|
|
551
564
|
}
|
|
552
|
-
const commonQueryAndVars = getQueryAndVariables(type, contentPath, componentRegistry.getCommonQuery(), context, (
|
|
565
|
+
const commonQueryAndVars = getQueryAndVariables(type, contentPath, componentRegistry.getCommonQuery(), context, (_c = pageCmp === null || pageCmp === void 0 ? void 0 : pageCmp.page) === null || _c === void 0 ? void 0 : _c.config);
|
|
553
566
|
if (commonQueryAndVars) {
|
|
554
567
|
allDescriptors.push({
|
|
555
568
|
type: contentTypeDef,
|
|
@@ -571,7 +584,7 @@ export const buildContentFetcher = (config) => {
|
|
|
571
584
|
return errorResponse('400', `Missing or empty query override for content type ${type}`, requestType, renderMode, contentApiUrl, xpBaseUrl, contentPath);
|
|
572
585
|
}
|
|
573
586
|
// /////////////// SECOND GUILLOTINE CALL FOR DATA //////////////////////
|
|
574
|
-
const contentResults = yield fetchContentData(contentApiUrl, contentPath, query, variables);
|
|
587
|
+
const contentResults = yield fetchContentData(contentApiUrl, contentPath, query, variables, headers);
|
|
575
588
|
// ///////////////////////////////////////////////////////////////////////////
|
|
576
589
|
// Apply processors to every component
|
|
577
590
|
const datas = yield applyProcessors(allDescriptors, contentResults, context);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enonic/nextjs-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"html-react-parser": "^3.0.4",
|
|
17
|
-
"next": "^13.0.
|
|
17
|
+
"next": "^13.0.4",
|
|
18
18
|
"react": "^18.2.0",
|
|
19
19
|
"react-dom": "^18.2.0",
|
|
20
20
|
"unescape": "^1.0.1"
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"@enonic/eslint-config": "^0.1.0",
|
|
24
24
|
"@types/node": "^18.11.9",
|
|
25
25
|
"@types/react": "^18.0.25",
|
|
26
|
-
"@types/react-dom": "^18.0.
|
|
27
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
28
|
-
"@typescript-eslint/parser": "^5.
|
|
29
|
-
"eslint": "^8.
|
|
30
|
-
"eslint-plugin-react": "^7.31.
|
|
31
|
-
"typescript": "^4.
|
|
26
|
+
"@types/react-dom": "^18.0.9",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
|
28
|
+
"@typescript-eslint/parser": "^5.44.0",
|
|
29
|
+
"eslint": "^8.28.0",
|
|
30
|
+
"eslint-plugin-react": "^7.31.11",
|
|
31
|
+
"typescript": "^4.9.3"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/utils.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare const FROM_XP_PARAM = "__fromxp__";
|
|
|
12
12
|
export declare const XP_BASE_URL_HEADER = "xpbaseurl";
|
|
13
13
|
export declare const COMPONENT_SUBPATH_HEADER = "xp-component-path";
|
|
14
14
|
export declare const RENDER_MODE_HEADER = "content-studio-mode";
|
|
15
|
+
export declare const JSESSIONID_HEADER = "jsessionid";
|
|
15
16
|
export declare const PORTAL_COMPONENT_ATTRIBUTE = "data-portal-component-type";
|
|
16
17
|
export declare const PORTAL_REGION_ATTRIBUTE = "data-portal-region";
|
|
17
18
|
export declare const FRAGMENT_CONTENTTYPE_NAME = "portal:fragment";
|
package/utils.js
CHANGED
|
@@ -16,6 +16,7 @@ export const FROM_XP_PARAM = '__fromxp__';
|
|
|
16
16
|
export const XP_BASE_URL_HEADER = 'xpbaseurl';
|
|
17
17
|
export const COMPONENT_SUBPATH_HEADER = 'xp-component-path';
|
|
18
18
|
export const RENDER_MODE_HEADER = 'content-studio-mode';
|
|
19
|
+
export const JSESSIONID_HEADER = 'jsessionid';
|
|
19
20
|
export const PORTAL_COMPONENT_ATTRIBUTE = 'data-portal-component-type';
|
|
20
21
|
export const PORTAL_REGION_ATTRIBUTE = 'data-portal-region';
|
|
21
22
|
export const FRAGMENT_CONTENTTYPE_NAME = 'portal:fragment';
|
package/views/BaseComponent.d.ts
CHANGED
package/views/RichTextView.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { MetaData, RichTextData } from '../guillotine/getMetaData';
|
|
3
3
|
import { DOMNode } from 'html-react-parser';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
|
|
4
|
+
export type ReplacerResult = JSX.Element | object | void | undefined | null | false;
|
|
5
|
+
export type Replacer = (domNode: DOMNode, data: RichTextData, meta: MetaData, renderMacroInEditMode: boolean) => ReplacerResult;
|
|
6
|
+
type Props = {
|
|
7
7
|
data: RichTextData;
|
|
8
8
|
meta: MetaData;
|
|
9
|
+
className?: string;
|
|
9
10
|
tag?: string;
|
|
10
11
|
renderMacroInEditMode?: boolean;
|
|
11
12
|
customReplacer?: Replacer;
|
|
12
13
|
};
|
|
13
14
|
export declare function createReplacer(allData: RichTextData, meta: MetaData, renderMacroInEditMode?: boolean, customReplacer?: Replacer): (domNode: DOMNode) => ReplacerResult;
|
|
14
|
-
declare const RichTextView: ({ tag, data, meta, renderMacroInEditMode, customReplacer }: Props) => JSX.Element;
|
|
15
|
+
declare const RichTextView: ({ className, tag, data, meta, renderMacroInEditMode, customReplacer }: Props) => JSX.Element;
|
|
15
16
|
export default RichTextView;
|
package/views/RichTextView.jsx
CHANGED
|
@@ -46,9 +46,9 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
46
46
|
return el;
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
const RichTextView = ({ tag, data, meta, renderMacroInEditMode, customReplacer }) => {
|
|
49
|
+
const RichTextView = ({ className, tag, data, meta, renderMacroInEditMode, customReplacer }) => {
|
|
50
50
|
const CustomTag = tag || 'section';
|
|
51
|
-
return <CustomTag>
|
|
51
|
+
return <CustomTag className={className}>
|
|
52
52
|
{data.processedHtml ? HTMLReactParser(data.processedHtml, { replace: createReplacer(data, meta, renderMacroInEditMode, customReplacer) }) : ''}
|
|
53
53
|
</CustomTag>;
|
|
54
54
|
};
|