@enonic/nextjs-adapter 2.0.0-B3 → 2.0.1
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/.eslint-childrc.js +17 -0
- package/.eslintrc.js +15 -0
- package/.github/dependabot.yml +20 -0
- package/.github/pull-merger.yml +1 -0
- package/.github/workflows/release.yml +39 -0
- package/LICENSE +201 -0
- package/RELEASE.md +75 -0
- package/package.json +8 -7
- package/server/.eslintrc.js +11 -0
- package/server/ClearableFileCache.ts +410 -0
- package/server/cache.ts +50 -0
- package/server/index.ts +74 -0
- package/server/tsconfig.json +23 -0
- package/setversion.js +8 -0
- package/src/.eslintrc.js +11 -0
- package/src/ComponentRegistry.ts +189 -0
- package/{UrlProcessor.js → src/UrlProcessor.ts} +54 -36
- package/{baseMappings.js → src/baseMappings.ts} +13 -3
- package/{guillotine/fetchContent.js → src/guillotine/fetchContent.ts} +496 -243
- package/src/guillotine/getMetaData.ts +246 -0
- package/{index.d.ts → src/index.ts} +1 -1
- package/src/tsconfig.json +20 -0
- package/{utils.js → src/utils.ts} +160 -70
- package/{views/BaseComponent.jsx → src/views/BaseComponent.tsx} +73 -39
- package/{views/BaseContent.jsx → src/views/BaseContent.tsx} +24 -17
- package/src/views/BaseLayout.tsx +45 -0
- package/{views/BaseMacro.jsx → src/views/BaseMacro.tsx} +45 -29
- package/src/views/BasePage.tsx +56 -0
- package/src/views/BasePart.tsx +50 -0
- package/{views/Empty.jsx → src/views/Empty.tsx} +2 -0
- package/src/views/Fragment.tsx +45 -0
- package/src/views/MainView.tsx +21 -0
- package/src/views/Region.tsx +89 -0
- package/{views/RichTextView.jsx → src/views/RichTextView.tsx} +31 -10
- package/{views/SingleComponent.jsx → src/views/SingleComponent.tsx} +8 -2
- package/src/views/StaticContent.tsx +40 -0
- package/src/views/Text.tsx +15 -0
- package/src/views/macros/DefaultMacro.tsx +9 -0
- package/src/views/macros/DisableMacro.tsx +8 -0
- package/ComponentRegistry.d.ts +0 -64
- package/ComponentRegistry.js +0 -121
- package/UrlProcessor.d.ts +0 -25
- package/baseMappings.d.ts +0 -1
- package/guillotine/fetchContent.d.ts +0 -48
- package/guillotine/getMetaData.d.ts +0 -94
- package/guillotine/getMetaData.js +0 -128
- package/index.js +0 -5
- package/query/Shortcut.d.ts +0 -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/utils.d.ts +0 -114
- package/views/BaseComponent.d.ts +0 -25
- package/views/BaseContent.d.ts +0 -4
- package/views/BaseLayout.d.ts +0 -17
- package/views/BaseLayout.jsx +0 -24
- package/views/BaseMacro.d.ts +0 -16
- package/views/BasePage.d.ts +0 -19
- package/views/BasePage.jsx +0 -34
- package/views/BasePart.d.ts +0 -19
- package/views/BasePart.jsx +0 -24
- package/views/Empty.d.ts +0 -3
- package/views/Fragment.d.ts +0 -10
- package/views/Fragment.jsx +0 -30
- package/views/MainView.d.ts +0 -4
- package/views/MainView.jsx +0 -14
- package/views/Region.d.ts +0 -20
- package/views/Region.jsx +0 -52
- package/views/RichTextView.d.ts +0 -16
- package/views/SingleComponent.d.ts +0 -5
- package/views/StaticContent.d.ts +0 -15
- package/views/StaticContent.jsx +0 -36
- package/views/Text.d.ts +0 -9
- package/views/Text.jsx +0 -4
- package/views/macros/DefaultMacro.d.ts +0 -4
- package/views/macros/DefaultMacro.jsx +0 -3
- package/views/macros/DisableMacro.d.ts +0 -3
- package/views/macros/DisableMacro.jsx +0 -2
- /package/{query/Shortcut.js → src/query/Shortcut.ts} +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {PORTAL_REGION_ATTRIBUTE, RENDER_MODE} from '../utils';
|
|
3
|
+
|
|
4
|
+
import BaseComponent from './BaseComponent';
|
|
5
|
+
import {MetaData, PageComponent, PageData} from '../guillotine/getMetaData';
|
|
6
|
+
|
|
7
|
+
export interface RegionProps {
|
|
8
|
+
name: string;
|
|
9
|
+
components?: PageComponent[];
|
|
10
|
+
className?: string;
|
|
11
|
+
common?: any; // Content is passed down for optional consumption in componentviews. TODO: Use a react contextprovider instead?
|
|
12
|
+
meta: MetaData;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RegionsProps {
|
|
16
|
+
page: PageData | null;
|
|
17
|
+
name?: string;
|
|
18
|
+
common?: any; // Content is passed down for optional consumption in componentviews. TODO: Use a react contextprovider instead?
|
|
19
|
+
meta: MetaData;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Single region */
|
|
23
|
+
export const RegionView = (props: RegionProps) => {
|
|
24
|
+
const {name, components, common, meta, className} = props;
|
|
25
|
+
const regionAttrs: { [key: string]: string } = {};
|
|
26
|
+
|
|
27
|
+
if (className) {
|
|
28
|
+
regionAttrs.className = className;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const children = (components || [])
|
|
32
|
+
.sort(sortPageComponentsByPath)
|
|
33
|
+
.map((component: PageComponent, i: number) => (
|
|
34
|
+
<BaseComponent key={`${regionAttrs.id}-${i}`} component={component} common={common} meta={meta}/>
|
|
35
|
+
));
|
|
36
|
+
|
|
37
|
+
if (meta.renderMode === RENDER_MODE.EDIT) {
|
|
38
|
+
regionAttrs.id = name + 'Region';
|
|
39
|
+
regionAttrs[PORTAL_REGION_ATTRIBUTE] = name;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return <div {...regionAttrs}>{children}</div>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/** Multiple regions, or only one if named in props.selected */
|
|
47
|
+
const RegionsView = (props: RegionsProps) => {
|
|
48
|
+
const {page, name, meta, common} = props;
|
|
49
|
+
const regions = page?.regions;
|
|
50
|
+
if (!regions || !Object.keys(regions)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Detect if any single region is selected for rendering and if so, handle that
|
|
55
|
+
if (name) {
|
|
56
|
+
const selectedRegion = regions[name];
|
|
57
|
+
if (!selectedRegion) {
|
|
58
|
+
console.warn(
|
|
59
|
+
`Region name '${name}' was selected but not found among regions (${JSON.stringify(Object.keys(regions))}). Skipping.`); // TODO: Throw error instead of this? Return null?
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return <RegionView {...selectedRegion} common={common} meta={meta}/>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
{
|
|
68
|
+
Object.keys(regions).map((name: string, i) => {
|
|
69
|
+
const region = regions[name];
|
|
70
|
+
return <RegionView key={i} {...region} common={common} meta={meta}/>;
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
</>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
function sortPageComponentsByPath(aComp: PageComponent, bComp: PageComponent): number {
|
|
78
|
+
// sort according to index in region, otherwise there will be a mismatch of views and data
|
|
79
|
+
// because after 10 components the order will be: /main/1, /main/11, /main/2, /main/3,...
|
|
80
|
+
|
|
81
|
+
let pathArr = aComp.path.split('/');
|
|
82
|
+
const aIndex = +(pathArr[pathArr.length - 1] || 0);
|
|
83
|
+
pathArr = bComp.path.split('/');
|
|
84
|
+
const bIndex = +(pathArr[pathArr.length - 1] || 0);
|
|
85
|
+
|
|
86
|
+
return aIndex - bIndex;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default RegionsView;
|
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
2
|
+
import {getUrl, UrlProcessor} from '../UrlProcessor';
|
|
3
|
+
import {MetaData, RichTextData} from '../guillotine/getMetaData';
|
|
4
|
+
import HTMLReactParser, {DOMNode} from 'html-react-parser';
|
|
5
|
+
import {ElementType} from 'domelementtype';
|
|
6
|
+
import {Element} from 'domhandler/lib';
|
|
5
7
|
import BaseMacro from './BaseMacro';
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
export type ReplacerResult = JSX.Element | object | void | undefined | null | false;
|
|
10
|
+
|
|
11
|
+
export type Replacer = (domNode: DOMNode, data: RichTextData, meta: MetaData, renderMacroInEditMode: boolean) => ReplacerResult;
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
data: RichTextData,
|
|
15
|
+
meta: MetaData,
|
|
16
|
+
className?: string,
|
|
17
|
+
tag?: string,
|
|
18
|
+
renderMacroInEditMode?: boolean,
|
|
19
|
+
customReplacer?: Replacer,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function createReplacer(allData: RichTextData, meta: MetaData, renderMacroInEditMode = true, customReplacer?: Replacer): (domNode: DOMNode) => ReplacerResult {
|
|
7
23
|
// eslint-disable-next-line react/display-name
|
|
8
|
-
return (domNode) => {
|
|
24
|
+
return (domNode: DOMNode): ReplacerResult => {
|
|
9
25
|
if (domNode.type !== ElementType.Tag) {
|
|
10
26
|
return domNode;
|
|
11
27
|
}
|
|
12
|
-
|
|
13
|
-
|
|
28
|
+
|
|
29
|
+
const el = domNode as Element;
|
|
30
|
+
let ref: string;
|
|
14
31
|
switch (el.tagName) {
|
|
15
32
|
case UrlProcessor.IMG_TAG:
|
|
16
33
|
ref = el.attribs[UrlProcessor.IMG_ATTR];
|
|
@@ -20,6 +37,7 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
20
37
|
if (src) {
|
|
21
38
|
el.attribs['src'] = getUrl(src, meta);
|
|
22
39
|
}
|
|
40
|
+
|
|
23
41
|
const srcset = el.attribs['srcset'];
|
|
24
42
|
if (srcset) {
|
|
25
43
|
el.attribs['srcset'] = UrlProcessor.processSrcSet(srcset, meta);
|
|
@@ -30,6 +48,7 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
30
48
|
case UrlProcessor.LINK_TAG:
|
|
31
49
|
ref = el.attribs[UrlProcessor.LINK_ATTR];
|
|
32
50
|
const href = el.attribs['href'];
|
|
51
|
+
|
|
33
52
|
if (ref && href) {
|
|
34
53
|
el.attribs['href'] = getUrl(href, meta);
|
|
35
54
|
}
|
|
@@ -53,10 +72,12 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
53
72
|
return el;
|
|
54
73
|
};
|
|
55
74
|
}
|
|
56
|
-
|
|
57
|
-
|
|
75
|
+
|
|
76
|
+
const RichTextView = ({className, tag, data, meta, renderMacroInEditMode, customReplacer}: Props) => {
|
|
77
|
+
const CustomTag = tag as keyof JSX.IntrinsicElements || 'section';
|
|
58
78
|
return <CustomTag className={className}>
|
|
59
|
-
{data.processedHtml ? HTMLReactParser(data.processedHtml, {
|
|
79
|
+
{data.processedHtml ? HTMLReactParser(data.processedHtml, {replace: createReplacer(data, meta, renderMacroInEditMode, customReplacer)}) : ''}
|
|
60
80
|
</CustomTag>;
|
|
61
81
|
};
|
|
82
|
+
|
|
62
83
|
export default RichTextView;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/** Render only one component as a result of a request from XP-side .../_/component/... during edit refresh. */
|
|
2
|
+
|
|
2
3
|
import BaseComponent from './BaseComponent';
|
|
3
4
|
import React from 'react';
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import {FetchContentResult} from '../guillotine/fetchContent';
|
|
6
|
+
|
|
7
|
+
const SingleComponent = ({meta, common}: FetchContentResult) => {
|
|
8
|
+
|
|
9
|
+
if (!meta?.requestedComponent) {
|
|
6
10
|
// TODO: Handle missing target region (Throw a 404, "component path not found"?)
|
|
7
11
|
return null;
|
|
8
12
|
}
|
|
13
|
+
|
|
9
14
|
return <BaseComponent component={meta.requestedComponent} common={common} meta={meta}/>;
|
|
10
15
|
};
|
|
16
|
+
|
|
11
17
|
export default SingleComponent;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {createElement, createRef, ReactNode, useEffect, useState} from 'react';
|
|
2
|
+
|
|
3
|
+
function useStaticContent(ref, isServer) {
|
|
4
|
+
if (isServer) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (ref?.current?.innerHTML === '') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface StaticContentProps extends Record<string, any> {
|
|
16
|
+
children?: ReactNode | ReactNode[];
|
|
17
|
+
element?: string;
|
|
18
|
+
condition: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function StaticContent({children, element = 'div', condition = true, ...props}: StaticContentProps) {
|
|
22
|
+
const isServer = typeof window === 'undefined';
|
|
23
|
+
const ref = createRef();
|
|
24
|
+
const isStatic = useStaticContent(ref, isServer);
|
|
25
|
+
|
|
26
|
+
// avoid re-render on the client
|
|
27
|
+
if (isStatic && condition) {
|
|
28
|
+
return createElement(element, {
|
|
29
|
+
...props,
|
|
30
|
+
ref,
|
|
31
|
+
suppressHydrationWarning: true,
|
|
32
|
+
dangerouslySetInnerHTML: {__html: ''},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// just render if:
|
|
37
|
+
// - condition is false
|
|
38
|
+
// - we're in the server or a spa navigation
|
|
39
|
+
return createElement(element, props, ...[].concat(children));
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {MetaData, TextData} from '../guillotine/getMetaData';
|
|
3
|
+
import RichTextView from './RichTextView';
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
meta: MetaData,
|
|
7
|
+
component: TextData,
|
|
8
|
+
path: string,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const DefaultTextView = ({component, meta, path}: Props) => (
|
|
12
|
+
<RichTextView data={component.value} meta={meta} renderMacroInEditMode={false}/>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export default DefaultTextView;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {MacroProps} from '../BaseMacro';
|
|
3
|
+
import HTMLReactParser from 'html-react-parser';
|
|
4
|
+
|
|
5
|
+
const DefaultMacro = ({name, config, meta}: MacroProps) => (
|
|
6
|
+
HTMLReactParser(config.body) as JSX.Element
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export default DefaultMacro;
|
package/ComponentRegistry.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
}
|
package/ComponentRegistry.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
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 = {};
|
package/UrlProcessor.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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;
|
package/baseMappings.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { MetaData, PageComponent } from './getMetaData';
|
|
2
|
-
import { ContentPathItem, Context, LocaleProjectConfig } from '../utils';
|
|
3
|
-
import { 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): GetStaticPropsResult<FetchContentResult>;
|
|
46
|
-
export declare function fetchContentPathsForAllLocales(path: string, query?: string, countPerLocale?: number): Promise<ContentPathItem[]>;
|
|
47
|
-
export declare function fetchContentPathsForLocale(path: string, config: LocaleProjectConfig, query?: string, count?: number): Promise<ContentPathItem[]>;
|
|
48
|
-
export {};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { RENDER_MODE, XP_COMPONENT_TYPE, XP_REQUEST_TYPE } from '../utils';
|
|
2
|
-
export declare const richTextQuery: (fieldName: string) => string;
|
|
3
|
-
export declare const pageFragmentQuery: () => string;
|
|
4
|
-
export declare function getMetaQuery(pageFragment?: string): string;
|
|
5
|
-
export interface PageComponent {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
type: XP_COMPONENT_TYPE;
|
|
8
|
-
path: string;
|
|
9
|
-
page?: PageData;
|
|
10
|
-
part?: PartData;
|
|
11
|
-
layout?: LayoutData;
|
|
12
|
-
fragment?: FragmentData;
|
|
13
|
-
text?: TextData;
|
|
14
|
-
image?: any;
|
|
15
|
-
regions?: RegionTree;
|
|
16
|
-
data?: any;
|
|
17
|
-
error?: any;
|
|
18
|
-
}
|
|
19
|
-
export interface TextData {
|
|
20
|
-
value: RichTextData;
|
|
21
|
-
}
|
|
22
|
-
export interface RichTextData {
|
|
23
|
-
processedHtml: string;
|
|
24
|
-
links: LinkData[];
|
|
25
|
-
macros: MacroData[];
|
|
26
|
-
images: ImageData[];
|
|
27
|
-
}
|
|
28
|
-
export interface LinkData {
|
|
29
|
-
ref: string;
|
|
30
|
-
media: {
|
|
31
|
-
content: {
|
|
32
|
-
id: string;
|
|
33
|
-
};
|
|
34
|
-
} | null;
|
|
35
|
-
}
|
|
36
|
-
export interface MacroData {
|
|
37
|
-
ref: string;
|
|
38
|
-
name: string;
|
|
39
|
-
descriptor: string;
|
|
40
|
-
config: {
|
|
41
|
-
[name: string]: MacroConfig;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export interface ImageData {
|
|
45
|
-
ref: string;
|
|
46
|
-
image: {
|
|
47
|
-
id: string;
|
|
48
|
-
} | null;
|
|
49
|
-
}
|
|
50
|
-
export interface MacroConfig {
|
|
51
|
-
[key: string]: any;
|
|
52
|
-
}
|
|
53
|
-
export interface RegionTree {
|
|
54
|
-
[key: string]: PageRegion;
|
|
55
|
-
}
|
|
56
|
-
export interface PageRegion {
|
|
57
|
-
name: string;
|
|
58
|
-
components: PageComponent[];
|
|
59
|
-
}
|
|
60
|
-
export interface PartData {
|
|
61
|
-
descriptor: string;
|
|
62
|
-
config: any;
|
|
63
|
-
[customKeysFromQuery: string]: any;
|
|
64
|
-
}
|
|
65
|
-
export interface LayoutData {
|
|
66
|
-
descriptor: string;
|
|
67
|
-
config?: any;
|
|
68
|
-
[customKeysFromQuery: string]: any;
|
|
69
|
-
}
|
|
70
|
-
export interface PageData {
|
|
71
|
-
descriptor: string;
|
|
72
|
-
config?: any;
|
|
73
|
-
template?: string | null;
|
|
74
|
-
regions?: RegionTree;
|
|
75
|
-
}
|
|
76
|
-
export interface FragmentData {
|
|
77
|
-
id: string;
|
|
78
|
-
fragment: {
|
|
79
|
-
components: PageComponent[];
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
export interface MetaData {
|
|
83
|
-
type: string;
|
|
84
|
-
path: string;
|
|
85
|
-
requestType: XP_REQUEST_TYPE;
|
|
86
|
-
renderMode: RENDER_MODE;
|
|
87
|
-
requestedComponent?: PageComponent;
|
|
88
|
-
canRender: boolean;
|
|
89
|
-
catchAll: boolean;
|
|
90
|
-
apiUrl: string;
|
|
91
|
-
baseUrl: string;
|
|
92
|
-
locale: string;
|
|
93
|
-
defaultLocale: string;
|
|
94
|
-
}
|