@enonic/nextjs-adapter 2.0.1 → 2.0.2
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 +64 -0
- package/ComponentRegistry.js +121 -0
- package/UrlProcessor.d.ts +25 -0
- package/{src/UrlProcessor.ts → UrlProcessor.js} +35 -53
- package/baseMappings.d.ts +1 -0
- package/{src/baseMappings.ts → baseMappings.js} +3 -13
- package/guillotine/fetchContent.d.ts +49 -0
- package/{src/guillotine/fetchContent.ts → guillotine/fetchContent.js} +243 -493
- package/guillotine/getMetaData.d.ts +94 -0
- package/guillotine/getMetaData.js +128 -0
- package/{src/index.ts → index.d.ts} +1 -1
- package/index.js +5 -0
- package/package.json +2 -2
- package/query/Shortcut.d.ts +1 -0
- package/server/ClearableFileCache.d.ts +31 -0
- package/server/ClearableFileCache.js +472 -0
- package/server/cache.d.ts +2 -0
- package/server/cache.js +129 -0
- package/server/index.d.ts +5 -0
- package/server/index.js +132 -0
- package/utils.d.ts +114 -0
- package/{src/utils.ts → utils.js} +69 -148
- package/views/BaseComponent.d.ts +25 -0
- package/{src/views/BaseComponent.tsx → views/BaseComponent.jsx} +39 -73
- package/views/BaseContent.d.ts +4 -0
- package/{src/views/BaseContent.tsx → views/BaseContent.jsx} +17 -24
- package/views/BaseLayout.d.ts +17 -0
- package/views/BaseLayout.jsx +24 -0
- package/views/BaseMacro.d.ts +16 -0
- package/{src/views/BaseMacro.tsx → views/BaseMacro.jsx} +29 -45
- package/views/BasePage.d.ts +19 -0
- package/views/BasePage.jsx +34 -0
- package/views/BasePart.d.ts +19 -0
- package/views/BasePart.jsx +24 -0
- package/views/Empty.d.ts +3 -0
- package/{src/views/Empty.tsx → views/Empty.jsx} +0 -2
- package/views/Fragment.d.ts +10 -0
- package/views/Fragment.jsx +30 -0
- package/views/MainView.d.ts +4 -0
- package/views/MainView.jsx +14 -0
- package/views/Region.d.ts +20 -0
- package/views/Region.jsx +52 -0
- package/views/RichTextView.d.ts +16 -0
- package/{src/views/RichTextView.tsx → views/RichTextView.jsx} +10 -31
- package/views/SingleComponent.d.ts +5 -0
- package/{src/views/SingleComponent.tsx → views/SingleComponent.jsx} +2 -8
- package/views/StaticContent.d.ts +15 -0
- package/views/StaticContent.jsx +36 -0
- package/views/Text.d.ts +9 -0
- package/views/Text.jsx +4 -0
- package/views/macros/DefaultMacro.d.ts +4 -0
- package/views/macros/DefaultMacro.jsx +3 -0
- package/views/macros/DisableMacro.d.ts +3 -0
- package/views/macros/DisableMacro.jsx +2 -0
- package/.eslint-childrc.js +0 -17
- package/.eslintrc.js +0 -15
- package/.github/dependabot.yml +0 -20
- package/.github/pull-merger.yml +0 -1
- package/.github/workflows/release.yml +0 -39
- package/LICENSE +0 -201
- package/RELEASE.md +0 -75
- package/server/.eslintrc.js +0 -11
- package/server/ClearableFileCache.ts +0 -410
- package/server/cache.ts +0 -50
- package/server/index.ts +0 -74
- package/server/tsconfig.json +0 -23
- package/src/.eslintrc.js +0 -11
- package/src/ComponentRegistry.ts +0 -189
- package/src/guillotine/getMetaData.ts +0 -246
- package/src/tsconfig.json +0 -20
- package/src/views/BaseLayout.tsx +0 -45
- package/src/views/BasePage.tsx +0 -56
- package/src/views/BasePart.tsx +0 -50
- package/src/views/Fragment.tsx +0 -45
- package/src/views/MainView.tsx +0 -21
- package/src/views/Region.tsx +0 -89
- package/src/views/StaticContent.tsx +0 -40
- package/src/views/Text.tsx +0 -15
- package/src/views/macros/DefaultMacro.tsx +0 -9
- package/src/views/macros/DisableMacro.tsx +0 -8
- /package/{src/query/Shortcut.ts → query/Shortcut.js} +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PageComponent } from './guillotine/getMetaData';
|
|
3
|
+
import { Context } from './utils';
|
|
4
|
+
/**
|
|
5
|
+
* Object that configures the handling of a particular content type. All attributes are optional (see examples below), and missing values will fall back to default behavior:
|
|
6
|
+
* - 'query' (used in fetchContent.ts) Guillotine query for fetching content data, may also have a function that supplies guillotine variables. So, 'query' can EITHER be only a query string, OR also add a get-guillotine-variables function. In the latter case, 'query' can be an object with 'query' and 'variables' attributes, or an array where the query string is first and the get-variables function is second. Either way, the get-variables function takes two arguments: path (content path, mandatory) and context (next.js-supplied Context from getServerSideProps etc. Optional, and requires that fetchContent is called with the context, of course).
|
|
7
|
+
* - 'props' (used in fetchContent.ts) is a function for processing props after fetching them
|
|
8
|
+
* - 'view' (used in BasePage.tsx) is a React component: top-level content-type-specific rendering with the props first fetched from guillotine (and then optionally preprocessed with the function in 'props').
|
|
9
|
+
*/
|
|
10
|
+
export interface ComponentDefinition {
|
|
11
|
+
catchAll?: boolean;
|
|
12
|
+
query?: SelectedQueryMaybeVariablesFunc;
|
|
13
|
+
configQuery?: string;
|
|
14
|
+
processor?: DataProcessor;
|
|
15
|
+
view?: React.FunctionComponent<any>;
|
|
16
|
+
}
|
|
17
|
+
export type DataProcessor = (data: any, context?: Context, config?: any) => Promise<Record<string, any>>;
|
|
18
|
+
export type VariablesGetter = (path: string, context?: Context, config?: any) => VariablesGetterResult;
|
|
19
|
+
export type QueryGetter = (path: string, context?: Context, config?: any) => string;
|
|
20
|
+
export type VariablesGetterResult = {
|
|
21
|
+
[variables: string]: any;
|
|
22
|
+
path: string;
|
|
23
|
+
};
|
|
24
|
+
export type SelectedQueryMaybeVariablesFunc = string | QueryGetter | {
|
|
25
|
+
query: string | QueryGetter;
|
|
26
|
+
variables: VariablesGetter;
|
|
27
|
+
} | [
|
|
28
|
+
string | QueryGetter,
|
|
29
|
+
VariablesGetter
|
|
30
|
+
];
|
|
31
|
+
export declare const CATCH_ALL = "*";
|
|
32
|
+
export declare class ComponentRegistry {
|
|
33
|
+
private static contentTypes;
|
|
34
|
+
private static pages;
|
|
35
|
+
private static components;
|
|
36
|
+
private static parts;
|
|
37
|
+
private static layouts;
|
|
38
|
+
private static macros;
|
|
39
|
+
private static commonQuery;
|
|
40
|
+
private static getSelector;
|
|
41
|
+
private static getType;
|
|
42
|
+
private static addType;
|
|
43
|
+
static getByComponent(component: PageComponent): ComponentDefinition | undefined;
|
|
44
|
+
static setCommonQuery(query: SelectedQueryMaybeVariablesFunc): void;
|
|
45
|
+
static getCommonQuery(): SelectedQueryMaybeVariablesFunc;
|
|
46
|
+
static addMacro(name: string, obj: ComponentDefinition): void;
|
|
47
|
+
static getMacro(name: string): ComponentDefinition | undefined;
|
|
48
|
+
static getMacros(): [string, ComponentDefinition][];
|
|
49
|
+
static getParts(): [string, ComponentDefinition][];
|
|
50
|
+
static getLayouts(): [string, ComponentDefinition][];
|
|
51
|
+
static getPages(): [string, ComponentDefinition][];
|
|
52
|
+
static getContentTypes(): [string, ComponentDefinition][];
|
|
53
|
+
static getComponents(): [string, ComponentDefinition][];
|
|
54
|
+
static addContentType(name: string, obj: ComponentDefinition): void;
|
|
55
|
+
static getContentType(name: string): ComponentDefinition | undefined;
|
|
56
|
+
static addPage(name: string, obj: ComponentDefinition): void;
|
|
57
|
+
static getPage(name: string): ComponentDefinition | undefined;
|
|
58
|
+
static addPart(name: string, obj: ComponentDefinition): void;
|
|
59
|
+
static getPart(name: string): ComponentDefinition | undefined;
|
|
60
|
+
static addLayout(name: string, obj: ComponentDefinition): void;
|
|
61
|
+
static getLayout(name: string): ComponentDefinition | undefined;
|
|
62
|
+
static addComponent(name: string, obj: ComponentDefinition): void;
|
|
63
|
+
static getComponent(name: string): ComponentDefinition | undefined;
|
|
64
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { XP_COMPONENT_TYPE } from './utils';
|
|
2
|
+
function toSelectorName(type) {
|
|
3
|
+
switch (type) {
|
|
4
|
+
case XP_COMPONENT_TYPE.PAGE:
|
|
5
|
+
return 'page';
|
|
6
|
+
case XP_COMPONENT_TYPE.LAYOUT:
|
|
7
|
+
return 'layout';
|
|
8
|
+
case XP_COMPONENT_TYPE.PART:
|
|
9
|
+
return 'part';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const CATCH_ALL = '*';
|
|
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
|
+
}
|
|
49
|
+
static getByComponent(component) {
|
|
50
|
+
const selName = toSelectorName(component.type);
|
|
51
|
+
const cmpData = component[component.type];
|
|
52
|
+
const desc = cmpData && 'descriptor' in cmpData ? cmpData.descriptor : component.path;
|
|
53
|
+
return selName && desc ? this.getType(selName, desc) : undefined;
|
|
54
|
+
}
|
|
55
|
+
static setCommonQuery(query) {
|
|
56
|
+
this.commonQuery = query;
|
|
57
|
+
}
|
|
58
|
+
static getCommonQuery() {
|
|
59
|
+
return this.commonQuery;
|
|
60
|
+
}
|
|
61
|
+
static addMacro(name, obj) {
|
|
62
|
+
return ComponentRegistry.addType('macro', name, obj);
|
|
63
|
+
}
|
|
64
|
+
static getMacro(name) {
|
|
65
|
+
return ComponentRegistry.getType('macro', name);
|
|
66
|
+
}
|
|
67
|
+
static getMacros() {
|
|
68
|
+
return Object.entries(this.macros);
|
|
69
|
+
}
|
|
70
|
+
static getParts() {
|
|
71
|
+
return Object.entries(this.parts);
|
|
72
|
+
}
|
|
73
|
+
static getLayouts() {
|
|
74
|
+
return Object.entries(this.layouts);
|
|
75
|
+
}
|
|
76
|
+
static getPages() {
|
|
77
|
+
return Object.entries(this.pages);
|
|
78
|
+
}
|
|
79
|
+
static getContentTypes() {
|
|
80
|
+
return Object.entries(this.contentTypes);
|
|
81
|
+
}
|
|
82
|
+
static getComponents() {
|
|
83
|
+
return Object.entries(this.components);
|
|
84
|
+
}
|
|
85
|
+
static addContentType(name, obj) {
|
|
86
|
+
return ComponentRegistry.addType('contentType', name, obj);
|
|
87
|
+
}
|
|
88
|
+
static getContentType(name) {
|
|
89
|
+
return ComponentRegistry.getType('contentType', name);
|
|
90
|
+
}
|
|
91
|
+
static addPage(name, obj) {
|
|
92
|
+
return ComponentRegistry.addType('page', name, obj);
|
|
93
|
+
}
|
|
94
|
+
static getPage(name) {
|
|
95
|
+
return ComponentRegistry.getType('page', name);
|
|
96
|
+
}
|
|
97
|
+
static addPart(name, obj) {
|
|
98
|
+
return ComponentRegistry.addType('part', name, obj);
|
|
99
|
+
}
|
|
100
|
+
static getPart(name) {
|
|
101
|
+
return ComponentRegistry.getType('part', name);
|
|
102
|
+
}
|
|
103
|
+
static addLayout(name, obj) {
|
|
104
|
+
return ComponentRegistry.addType('layout', name, obj);
|
|
105
|
+
}
|
|
106
|
+
static getLayout(name) {
|
|
107
|
+
return ComponentRegistry.getType('layout', name);
|
|
108
|
+
}
|
|
109
|
+
static addComponent(name, obj) {
|
|
110
|
+
return ComponentRegistry.addType('component', name, obj);
|
|
111
|
+
}
|
|
112
|
+
static getComponent(name) {
|
|
113
|
+
return ComponentRegistry.getType('component', name);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
ComponentRegistry.contentTypes = {};
|
|
117
|
+
ComponentRegistry.pages = {};
|
|
118
|
+
ComponentRegistry.components = {};
|
|
119
|
+
ComponentRegistry.parts = {};
|
|
120
|
+
ComponentRegistry.layouts = {};
|
|
121
|
+
ComponentRegistry.macros = {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ImageData, LinkData, MetaData } from './guillotine/getMetaData';
|
|
2
|
+
export declare class UrlProcessor {
|
|
3
|
+
static IMG_TAG: string;
|
|
4
|
+
static LINK_TAG: string;
|
|
5
|
+
static MACRO_TAG: string;
|
|
6
|
+
static IMG_ATTR: string;
|
|
7
|
+
static LINK_ATTR: string;
|
|
8
|
+
static MACRO_ATTR: string;
|
|
9
|
+
private static IMG_ATMT_REGEXP;
|
|
10
|
+
private static endSlashPattern;
|
|
11
|
+
private static startSlashPattern;
|
|
12
|
+
private static localhostPattern;
|
|
13
|
+
private static siteKey;
|
|
14
|
+
static process(url: string, meta: MetaData, serverSide?: boolean): string;
|
|
15
|
+
static setSiteKey(key: string): void;
|
|
16
|
+
static isMediaLink(ref: string, linkData: LinkData[]): boolean;
|
|
17
|
+
static isContentImage(ref: string, linkData: ImageData[]): boolean;
|
|
18
|
+
static processSrcSet(srcset: string, meta: MetaData): string;
|
|
19
|
+
private static stripApiUrl;
|
|
20
|
+
private static isAttachmentUrl;
|
|
21
|
+
private static startsWithHash;
|
|
22
|
+
private static isRelative;
|
|
23
|
+
private static getApiUrl;
|
|
24
|
+
}
|
|
25
|
+
export declare const getUrl: (url: string, meta: MetaData, serverSide?: boolean) => string;
|
|
@@ -1,25 +1,7 @@
|
|
|
1
|
-
import {commonChars, fixDoubleSlashes, getLocaleProjectConfigs, RENDER_MODE} from './utils';
|
|
2
|
-
import {
|
|
3
|
-
import {addBasePath} from 'next/dist/client/add-base-path';
|
|
4
|
-
|
|
1
|
+
import { commonChars, fixDoubleSlashes, getLocaleProjectConfigs, RENDER_MODE } from './utils';
|
|
2
|
+
import { addBasePath } from 'next/dist/client/add-base-path';
|
|
5
3
|
export class UrlProcessor {
|
|
6
|
-
|
|
7
|
-
public static IMG_TAG = 'img';
|
|
8
|
-
public static LINK_TAG = 'a';
|
|
9
|
-
public static MACRO_TAG = 'editor-macro';
|
|
10
|
-
|
|
11
|
-
public static IMG_ATTR = 'data-image-ref';
|
|
12
|
-
public static LINK_ATTR = 'data-link-ref';
|
|
13
|
-
public static MACRO_ATTR = 'data-macro-ref';
|
|
14
|
-
|
|
15
|
-
private static IMG_ATMT_REGEXP = /_\/image\/|_\/attachment\//;
|
|
16
|
-
private static endSlashPattern = /\/+$/;
|
|
17
|
-
private static startSlashPattern = /^\/+/;
|
|
18
|
-
private static localhostPattern = /localhost/;
|
|
19
|
-
|
|
20
|
-
private static siteKey: string;
|
|
21
|
-
|
|
22
|
-
public static process(url: string, meta: MetaData, serverSide = false): string {
|
|
4
|
+
static process(url, meta, serverSide = false) {
|
|
23
5
|
if (this.startsWithHash(url) || !meta || (this.isAttachmentUrl(url)) && meta.renderMode === RENDER_MODE.NEXT) {
|
|
24
6
|
// do not process if:
|
|
25
7
|
// - url starts with #
|
|
@@ -27,11 +9,10 @@ export class UrlProcessor {
|
|
|
27
9
|
// - attachment urls in NEXT mode
|
|
28
10
|
return url;
|
|
29
11
|
}
|
|
30
|
-
|
|
31
|
-
let result: string;
|
|
12
|
+
let result;
|
|
32
13
|
const apiUrl = this.getApiUrl(meta);
|
|
33
14
|
const strippedUrl = this.stripApiUrl(url, apiUrl);
|
|
34
|
-
const baseUrl = meta
|
|
15
|
+
const baseUrl = (meta === null || meta === void 0 ? void 0 : meta.baseUrl) && (meta === null || meta === void 0 ? void 0 : meta.baseUrl) !== '/' ? meta.baseUrl : '';
|
|
35
16
|
if (meta.renderMode === RENDER_MODE.NEXT) {
|
|
36
17
|
// only add basePath and locale in next mode
|
|
37
18
|
result = `/${strippedUrl}`;
|
|
@@ -43,26 +24,24 @@ export class UrlProcessor {
|
|
|
43
24
|
// no need for baseurl and basepath on server
|
|
44
25
|
result = addBasePath(`${baseUrl}${result}`);
|
|
45
26
|
}
|
|
46
|
-
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
47
29
|
result = `${baseUrl}/${strippedUrl}`;
|
|
48
30
|
}
|
|
49
|
-
|
|
50
31
|
return fixDoubleSlashes(result);
|
|
51
32
|
}
|
|
52
|
-
|
|
53
|
-
public static setSiteKey(key: string): void {
|
|
33
|
+
static setSiteKey(key) {
|
|
54
34
|
this.siteKey = key;
|
|
55
35
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return linkData.find(data => data.ref === ref)
|
|
36
|
+
static isMediaLink(ref, linkData) {
|
|
37
|
+
var _a;
|
|
38
|
+
return ((_a = linkData.find(data => data.ref === ref)) === null || _a === void 0 ? void 0 : _a.media) !== null;
|
|
59
39
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return linkData.find(data => data.ref === ref)
|
|
40
|
+
static isContentImage(ref, linkData) {
|
|
41
|
+
var _a;
|
|
42
|
+
return ((_a = linkData.find(data => data.ref === ref)) === null || _a === void 0 ? void 0 : _a.image) !== null;
|
|
63
43
|
}
|
|
64
|
-
|
|
65
|
-
public static processSrcSet(srcset: string, meta: MetaData): string {
|
|
44
|
+
static processSrcSet(srcset, meta) {
|
|
66
45
|
return srcset.split(/, */g).map(src => {
|
|
67
46
|
const srcParts = src.trim().split(' ');
|
|
68
47
|
switch (srcParts.length) {
|
|
@@ -76,8 +55,7 @@ export class UrlProcessor {
|
|
|
76
55
|
}
|
|
77
56
|
}).join(', ');
|
|
78
57
|
}
|
|
79
|
-
|
|
80
|
-
private static stripApiUrl(url: string, apiUrl: string): string {
|
|
58
|
+
static stripApiUrl(url, apiUrl) {
|
|
81
59
|
// normalise localhost-127.0.0.1 if present in urls
|
|
82
60
|
const normalUrl = url.replace(this.localhostPattern, '127.0.0.1');
|
|
83
61
|
const normalApiUrl = apiUrl.replace(this.localhostPattern, '127.0.0.1');
|
|
@@ -85,31 +63,35 @@ export class UrlProcessor {
|
|
|
85
63
|
const remaining = common.length > 0 ? normalUrl.substring(common.length) : normalUrl;
|
|
86
64
|
return (remaining.length > 0 && remaining.charAt(0) === '/') ? remaining.substring(1) : remaining;
|
|
87
65
|
}
|
|
88
|
-
|
|
89
|
-
private static isAttachmentUrl(url: string): boolean {
|
|
66
|
+
static isAttachmentUrl(url) {
|
|
90
67
|
return this.IMG_ATMT_REGEXP.test(url);
|
|
91
68
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return url?.charAt(0) == '#';
|
|
69
|
+
static startsWithHash(url) {
|
|
70
|
+
return (url === null || url === void 0 ? void 0 : url.charAt(0)) == '#';
|
|
95
71
|
}
|
|
96
|
-
|
|
97
|
-
private static isRelative(url: string): boolean {
|
|
72
|
+
static isRelative(url) {
|
|
98
73
|
return !/^(?:ht|f)tps?:\/\/[^ :\r\n\t]+/.test(url);
|
|
99
74
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
let combinedUrl = meta.apiUrl
|
|
103
|
-
if (this.siteKey
|
|
75
|
+
static getApiUrl(meta) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
let combinedUrl = ((_a = meta.apiUrl) === null || _a === void 0 ? void 0 : _a.replace(this.endSlashPattern, '')) || '';
|
|
78
|
+
if ((_b = this.siteKey) === null || _b === void 0 ? void 0 : _b.length) {
|
|
104
79
|
combinedUrl += '/' + this.siteKey.replace(this.startSlashPattern, '');
|
|
105
80
|
}
|
|
106
81
|
return combinedUrl;
|
|
107
82
|
}
|
|
108
83
|
}
|
|
109
|
-
|
|
84
|
+
UrlProcessor.IMG_TAG = 'img';
|
|
85
|
+
UrlProcessor.LINK_TAG = 'a';
|
|
86
|
+
UrlProcessor.MACRO_TAG = 'editor-macro';
|
|
87
|
+
UrlProcessor.IMG_ATTR = 'data-image-ref';
|
|
88
|
+
UrlProcessor.LINK_ATTR = 'data-link-ref';
|
|
89
|
+
UrlProcessor.MACRO_ATTR = 'data-macro-ref';
|
|
90
|
+
UrlProcessor.IMG_ATMT_REGEXP = /_\/image\/|_\/attachment\//;
|
|
91
|
+
UrlProcessor.endSlashPattern = /\/+$/;
|
|
92
|
+
UrlProcessor.startSlashPattern = /^\/+/;
|
|
93
|
+
UrlProcessor.localhostPattern = /localhost/;
|
|
110
94
|
// Actual site is going to be set in fetchContent method, but set a default fallback here too
|
|
111
95
|
const defaultConfig = getLocaleProjectConfigs().default;
|
|
112
96
|
UrlProcessor.setSiteKey(defaultConfig.site);
|
|
113
|
-
|
|
114
|
-
export const getUrl: (url: string, meta: MetaData, serverSide?: boolean) => string = UrlProcessor.process.bind(UrlProcessor);
|
|
115
|
-
|
|
97
|
+
export const getUrl = UrlProcessor.process.bind(UrlProcessor);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {ComponentRegistry} from './ComponentRegistry';
|
|
2
|
-
import {FRAGMENT_CONTENTTYPE_NAME, XP_COMPONENT_TYPE} from './utils';
|
|
1
|
+
import { ComponentRegistry } from './ComponentRegistry';
|
|
2
|
+
import { FRAGMENT_CONTENTTYPE_NAME, XP_COMPONENT_TYPE } from './utils';
|
|
3
3
|
import FragmentView from './views/Fragment';
|
|
4
4
|
import BasePage from './views/BasePage';
|
|
5
5
|
import BasePart from './views/BasePart';
|
|
@@ -7,40 +7,30 @@ import BaseLayout from './views/BaseLayout';
|
|
|
7
7
|
import TextView from './views/Text';
|
|
8
8
|
import DefaultMacro from './views/macros/DefaultMacro';
|
|
9
9
|
import DisableMacro from './views/macros/DisableMacro';
|
|
10
|
-
import {getShortcutQuery} from './query/Shortcut';
|
|
11
|
-
|
|
10
|
+
import { getShortcutQuery } from './query/Shortcut';
|
|
12
11
|
// Base Content Types
|
|
13
|
-
|
|
14
12
|
ComponentRegistry.addContentType(FRAGMENT_CONTENTTYPE_NAME, {
|
|
15
13
|
view: FragmentView,
|
|
16
14
|
});
|
|
17
|
-
|
|
18
15
|
ComponentRegistry.addContentType('base:shortcut', {
|
|
19
16
|
query: getShortcutQuery,
|
|
20
17
|
});
|
|
21
|
-
|
|
22
18
|
// Base Components
|
|
23
|
-
|
|
24
19
|
ComponentRegistry.addComponent(XP_COMPONENT_TYPE.PAGE, {
|
|
25
20
|
view: BasePage,
|
|
26
21
|
});
|
|
27
|
-
|
|
28
22
|
ComponentRegistry.addComponent(XP_COMPONENT_TYPE.PART, {
|
|
29
23
|
view: BasePart,
|
|
30
24
|
});
|
|
31
|
-
|
|
32
25
|
ComponentRegistry.addComponent(XP_COMPONENT_TYPE.LAYOUT, {
|
|
33
26
|
view: BaseLayout,
|
|
34
27
|
});
|
|
35
|
-
|
|
36
28
|
ComponentRegistry.addComponent(XP_COMPONENT_TYPE.FRAGMENT, {
|
|
37
29
|
view: FragmentView,
|
|
38
30
|
});
|
|
39
|
-
|
|
40
31
|
ComponentRegistry.addComponent(XP_COMPONENT_TYPE.TEXT, {
|
|
41
32
|
view: TextView,
|
|
42
33
|
});
|
|
43
|
-
|
|
44
34
|
// Macro mappings
|
|
45
35
|
ComponentRegistry.addMacro('system:embed', {
|
|
46
36
|
view: DefaultMacro,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MetaData, PageComponent } from './getMetaData';
|
|
2
|
+
import { ContentPathItem, Context, LocaleProjectConfig } from '../utils';
|
|
3
|
+
import { GetServerSidePropsResult, GetStaticPropsResult } from 'next';
|
|
4
|
+
type Result = {
|
|
5
|
+
error?: {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
} | null;
|
|
9
|
+
};
|
|
10
|
+
export type GuillotineResult = Result & {
|
|
11
|
+
[dataKey: string]: any;
|
|
12
|
+
};
|
|
13
|
+
export type FetchContentResult = Result & {
|
|
14
|
+
data: Record<string, any> | null;
|
|
15
|
+
common: Record<string, any> | null;
|
|
16
|
+
meta: MetaData;
|
|
17
|
+
page: PageComponent | null;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Sends one query to the guillotine API and asks for content type, then uses the type to select a second query and variables, which is sent to the API and fetches content data.
|
|
21
|
+
* @param contentPath string or string array: pre-split or slash-delimited _path to a content available on the API
|
|
22
|
+
* @returns FetchContentResult object: {data?: T, error?: {code, message}}
|
|
23
|
+
*/
|
|
24
|
+
export type ContentFetcher = (contentPath: string | string[], context?: Context) => Promise<FetchContentResult>;
|
|
25
|
+
export type ContentApiBaseBody = {
|
|
26
|
+
query?: string;
|
|
27
|
+
variables?: {
|
|
28
|
+
path?: string;
|
|
29
|
+
[key: string]: string | number | undefined;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/** Generic fetch */
|
|
33
|
+
export declare const fetchFromApi: (apiUrl: string, body: ContentApiBaseBody, projectConfig: LocaleProjectConfig, headers?: {}, method?: string) => Promise<any>;
|
|
34
|
+
/** Guillotine-specialized fetch, using the generic fetch above */
|
|
35
|
+
export declare const fetchGuillotine: (contentApiUrl: string, body: ContentApiBaseBody, projectConfig: LocaleProjectConfig, headers?: {}) => Promise<GuillotineResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Default fetchContent function, built with params from imports.
|
|
38
|
+
* It runs custom content-type-specific guillotine calls against an XP guillotine endpoint, returns content data, error and some meta data
|
|
39
|
+
* Sends one query to the guillotine API and asks for content type, then uses the type to select a second query and variables, which is sent to the API and fetches content data.
|
|
40
|
+
* @param contentPath string or string array: local (site-relative) path to a content available on the API (by XP _path - obtainable by running contentPath through getXpPath). Pre-split into string array, or already a slash-delimited string.
|
|
41
|
+
* @param context object from Next, contains .query info
|
|
42
|
+
* @returns FetchContentResult object: {data?: T, error?: {code, message}}
|
|
43
|
+
*/
|
|
44
|
+
export declare const fetchContent: ContentFetcher;
|
|
45
|
+
export declare function createResponse(props: FetchContentResult, context?: Context, isStatic?: true): GetStaticPropsResult<FetchContentResult>;
|
|
46
|
+
export declare function createResponse(props: FetchContentResult, context?: Context, isStatic?: false): GetServerSidePropsResult<FetchContentResult>;
|
|
47
|
+
export declare function fetchContentPathsForAllLocales(path: string, query?: string, countPerLocale?: number): Promise<ContentPathItem[]>;
|
|
48
|
+
export declare function fetchContentPathsForLocale(path: string, config: LocaleProjectConfig, query?: string, count?: number): Promise<ContentPathItem[]>;
|
|
49
|
+
export {};
|