@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
package/views/Region.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { MetaData, PageComponent, PageData } from '../guillotine/getMetaData';
|
|
3
|
-
export interface RegionProps {
|
|
4
|
-
name: string;
|
|
5
|
-
components?: PageComponent[];
|
|
6
|
-
className?: string;
|
|
7
|
-
common?: any;
|
|
8
|
-
meta: MetaData;
|
|
9
|
-
}
|
|
10
|
-
export interface RegionsProps {
|
|
11
|
-
page: PageData | null;
|
|
12
|
-
name?: string;
|
|
13
|
-
common?: any;
|
|
14
|
-
meta: MetaData;
|
|
15
|
-
}
|
|
16
|
-
/** Single region */
|
|
17
|
-
export declare const RegionView: (props: RegionProps) => React.JSX.Element;
|
|
18
|
-
/** Multiple regions, or only one if named in props.selected */
|
|
19
|
-
declare const RegionsView: (props: RegionsProps) => React.JSX.Element;
|
|
20
|
-
export default RegionsView;
|
package/views/Region.jsx
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { PORTAL_REGION_ATTRIBUTE, RENDER_MODE } from '../utils';
|
|
3
|
-
import BaseComponent from './BaseComponent';
|
|
4
|
-
/** Single region */
|
|
5
|
-
export const RegionView = (props) => {
|
|
6
|
-
const { name, components, common, meta, className } = props;
|
|
7
|
-
const regionAttrs = {};
|
|
8
|
-
if (className) {
|
|
9
|
-
regionAttrs.className = className;
|
|
10
|
-
}
|
|
11
|
-
const children = (components || [])
|
|
12
|
-
.sort(sortPageComponentsByPath)
|
|
13
|
-
.map((component, i) => (<BaseComponent key={`${regionAttrs.id}-${i}`} component={component} common={common} meta={meta}/>));
|
|
14
|
-
if (meta.renderMode === RENDER_MODE.EDIT) {
|
|
15
|
-
regionAttrs.id = name + 'Region';
|
|
16
|
-
regionAttrs[PORTAL_REGION_ATTRIBUTE] = name;
|
|
17
|
-
}
|
|
18
|
-
return <div {...regionAttrs}>{children}</div>;
|
|
19
|
-
};
|
|
20
|
-
/** Multiple regions, or only one if named in props.selected */
|
|
21
|
-
const RegionsView = (props) => {
|
|
22
|
-
const { page, name, meta, common } = props;
|
|
23
|
-
const regions = page === null || page === void 0 ? void 0 : page.regions;
|
|
24
|
-
if (!regions || !Object.keys(regions)) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
// Detect if any single region is selected for rendering and if so, handle that
|
|
28
|
-
if (name) {
|
|
29
|
-
const selectedRegion = regions[name];
|
|
30
|
-
if (!selectedRegion) {
|
|
31
|
-
console.warn(`Region name '${name}' was selected but not found among regions (${JSON.stringify(Object.keys(regions))}). Skipping.`); // TODO: Throw error instead of this? Return null?
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
return <RegionView {...selectedRegion} common={common} meta={meta}/>;
|
|
35
|
-
}
|
|
36
|
-
return (<>
|
|
37
|
-
{Object.keys(regions).map((name, i) => {
|
|
38
|
-
const region = regions[name];
|
|
39
|
-
return <RegionView key={i} {...region} common={common} meta={meta}/>;
|
|
40
|
-
})}
|
|
41
|
-
</>);
|
|
42
|
-
};
|
|
43
|
-
function sortPageComponentsByPath(aComp, bComp) {
|
|
44
|
-
// sort according to index in region, otherwise there will be a mismatch of views and data
|
|
45
|
-
// because after 10 components the order will be: /main/1, /main/11, /main/2, /main/3,...
|
|
46
|
-
let pathArr = aComp.path.split('/');
|
|
47
|
-
const aIndex = +(pathArr[pathArr.length - 1] || 0);
|
|
48
|
-
pathArr = bComp.path.split('/');
|
|
49
|
-
const bIndex = +(pathArr[pathArr.length - 1] || 0);
|
|
50
|
-
return aIndex - bIndex;
|
|
51
|
-
}
|
|
52
|
-
export default RegionsView;
|
package/views/RichTextView.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { MetaData, RichTextData } from '../guillotine/getMetaData';
|
|
3
|
-
import { DOMNode } from 'html-react-parser';
|
|
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
|
-
data: RichTextData;
|
|
8
|
-
meta: MetaData;
|
|
9
|
-
className?: string;
|
|
10
|
-
tag?: string;
|
|
11
|
-
renderMacroInEditMode?: boolean;
|
|
12
|
-
customReplacer?: Replacer;
|
|
13
|
-
};
|
|
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) => React.JSX.Element;
|
|
16
|
-
export default RichTextView;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/** Render only one component as a result of a request from XP-side .../_/component/... during edit refresh. */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { FetchContentResult } from '../guillotine/fetchContent';
|
|
4
|
-
declare const SingleComponent: ({ meta, common }: FetchContentResult) => React.JSX.Element;
|
|
5
|
-
export default SingleComponent;
|
package/views/StaticContent.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
export interface StaticContentProps extends Record<string, any> {
|
|
3
|
-
children?: ReactNode | ReactNode[];
|
|
4
|
-
element?: string;
|
|
5
|
-
condition: boolean;
|
|
6
|
-
}
|
|
7
|
-
export default function StaticContent({ children, element, condition, ...props }: StaticContentProps): import("react").ReactElement<{
|
|
8
|
-
ref: import("react").RefObject<unknown>;
|
|
9
|
-
suppressHydrationWarning: boolean;
|
|
10
|
-
dangerouslySetInnerHTML: {
|
|
11
|
-
__html: string;
|
|
12
|
-
};
|
|
13
|
-
}, string | import("react").JSXElementConstructor<any>> | import("react").DOMElement<{
|
|
14
|
-
[x: string]: any;
|
|
15
|
-
}, Element>;
|
package/views/StaticContent.jsx
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
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;
|
|
22
|
-
}
|
|
23
|
-
export default function StaticContent(_a) {
|
|
24
|
-
var { children, element = 'div', condition = true } = _a, props = __rest(_a, ["children", "element", "condition"]);
|
|
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
|
-
}
|
|
32
|
-
// just render if:
|
|
33
|
-
// - condition is false
|
|
34
|
-
// - we're in the server or a spa navigation
|
|
35
|
-
return createElement(element, props, ...[].concat(children));
|
|
36
|
-
}
|
package/views/Text.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { MetaData, TextData } from '../guillotine/getMetaData';
|
|
3
|
-
type Props = {
|
|
4
|
-
meta: MetaData;
|
|
5
|
-
component: TextData;
|
|
6
|
-
path: string;
|
|
7
|
-
};
|
|
8
|
-
declare const DefaultTextView: ({ component, meta, path }: Props) => React.JSX.Element;
|
|
9
|
-
export default DefaultTextView;
|
package/views/Text.jsx
DELETED
|
File without changes
|