@enonic/nextjs-adapter 2.0.0 → 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.
Files changed (82) hide show
  1. package/.eslint-childrc.js +17 -0
  2. package/.eslintrc.js +15 -0
  3. package/.github/dependabot.yml +20 -0
  4. package/.github/pull-merger.yml +1 -0
  5. package/.github/workflows/release.yml +39 -0
  6. package/LICENSE +201 -0
  7. package/RELEASE.md +75 -0
  8. package/package.json +3 -2
  9. package/server/.eslintrc.js +11 -0
  10. package/server/ClearableFileCache.ts +410 -0
  11. package/server/cache.ts +50 -0
  12. package/server/index.ts +74 -0
  13. package/server/tsconfig.json +23 -0
  14. package/setversion.js +8 -0
  15. package/src/.eslintrc.js +11 -0
  16. package/src/ComponentRegistry.ts +189 -0
  17. package/{UrlProcessor.js → src/UrlProcessor.ts} +54 -36
  18. package/{baseMappings.js → src/baseMappings.ts} +13 -3
  19. package/{guillotine/fetchContent.js → src/guillotine/fetchContent.ts} +493 -243
  20. package/src/guillotine/getMetaData.ts +246 -0
  21. package/{index.d.ts → src/index.ts} +1 -1
  22. package/src/tsconfig.json +20 -0
  23. package/{utils.js → src/utils.ts} +158 -68
  24. package/{views/BaseComponent.jsx → src/views/BaseComponent.tsx} +73 -39
  25. package/{views/BaseContent.jsx → src/views/BaseContent.tsx} +24 -17
  26. package/src/views/BaseLayout.tsx +45 -0
  27. package/{views/BaseMacro.jsx → src/views/BaseMacro.tsx} +45 -29
  28. package/src/views/BasePage.tsx +56 -0
  29. package/src/views/BasePart.tsx +50 -0
  30. package/{views/Empty.jsx → src/views/Empty.tsx} +2 -0
  31. package/src/views/Fragment.tsx +45 -0
  32. package/src/views/MainView.tsx +21 -0
  33. package/src/views/Region.tsx +89 -0
  34. package/{views/RichTextView.jsx → src/views/RichTextView.tsx} +31 -10
  35. package/{views/SingleComponent.jsx → src/views/SingleComponent.tsx} +8 -2
  36. package/src/views/StaticContent.tsx +40 -0
  37. package/src/views/Text.tsx +15 -0
  38. package/src/views/macros/DefaultMacro.tsx +9 -0
  39. package/src/views/macros/DisableMacro.tsx +8 -0
  40. package/ComponentRegistry.d.ts +0 -64
  41. package/ComponentRegistry.js +0 -121
  42. package/UrlProcessor.d.ts +0 -25
  43. package/baseMappings.d.ts +0 -1
  44. package/guillotine/fetchContent.d.ts +0 -49
  45. package/guillotine/getMetaData.d.ts +0 -94
  46. package/guillotine/getMetaData.js +0 -128
  47. package/index.js +0 -5
  48. package/query/Shortcut.d.ts +0 -1
  49. package/server/ClearableFileCache.d.ts +0 -31
  50. package/server/ClearableFileCache.js +0 -472
  51. package/server/cache.d.ts +0 -2
  52. package/server/cache.js +0 -129
  53. package/server/index.d.ts +0 -5
  54. package/server/index.js +0 -132
  55. package/utils.d.ts +0 -114
  56. package/views/BaseComponent.d.ts +0 -25
  57. package/views/BaseContent.d.ts +0 -4
  58. package/views/BaseLayout.d.ts +0 -17
  59. package/views/BaseLayout.jsx +0 -24
  60. package/views/BaseMacro.d.ts +0 -16
  61. package/views/BasePage.d.ts +0 -19
  62. package/views/BasePage.jsx +0 -34
  63. package/views/BasePart.d.ts +0 -19
  64. package/views/BasePart.jsx +0 -24
  65. package/views/Empty.d.ts +0 -3
  66. package/views/Fragment.d.ts +0 -10
  67. package/views/Fragment.jsx +0 -30
  68. package/views/MainView.d.ts +0 -4
  69. package/views/MainView.jsx +0 -14
  70. package/views/Region.d.ts +0 -20
  71. package/views/Region.jsx +0 -52
  72. package/views/RichTextView.d.ts +0 -16
  73. package/views/SingleComponent.d.ts +0 -5
  74. package/views/StaticContent.d.ts +0 -15
  75. package/views/StaticContent.jsx +0 -36
  76. package/views/Text.d.ts +0 -9
  77. package/views/Text.jsx +0 -4
  78. package/views/macros/DefaultMacro.d.ts +0 -4
  79. package/views/macros/DefaultMacro.jsx +0 -3
  80. package/views/macros/DisableMacro.d.ts +0 -3
  81. package/views/macros/DisableMacro.jsx +0 -2
  82. /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;
@@ -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;
@@ -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>;
@@ -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
@@ -1,4 +0,0 @@
1
- import React from 'react';
2
- import RichTextView from './RichTextView';
3
- const DefaultTextView = ({ component, meta, path }) => (<RichTextView data={component.value} meta={meta} renderMacroInEditMode={false}/>);
4
- export default DefaultTextView;
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- import { MacroProps } from '../BaseMacro';
3
- declare const DefaultMacro: ({ name, config, meta }: MacroProps) => JSX.Element;
4
- export default DefaultMacro;
@@ -1,3 +0,0 @@
1
- import HTMLReactParser from 'html-react-parser';
2
- const DefaultMacro = ({ name, config, meta }) => HTMLReactParser(config.body);
3
- export default DefaultMacro;
@@ -1,3 +0,0 @@
1
- import { MacroProps } from '../BaseMacro';
2
- declare const DisableMacro: ({ name, config, meta }: MacroProps) => any;
3
- export default DisableMacro;
@@ -1,2 +0,0 @@
1
- const DisableMacro = ({ name, config, meta }) => (config.body);
2
- export default DisableMacro;
File without changes