@enonic/nextjs-adapter 2.0.1 → 2.0.3

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/ComponentRegistry.d.ts +64 -0
  2. package/ComponentRegistry.js +121 -0
  3. package/UrlProcessor.d.ts +25 -0
  4. package/UrlProcessor.js +127 -0
  5. package/baseMappings.d.ts +1 -0
  6. package/{src/baseMappings.ts → baseMappings.js} +3 -13
  7. package/guillotine/fetchContent.d.ts +49 -0
  8. package/{src/guillotine/fetchContent.ts → guillotine/fetchContent.js} +244 -493
  9. package/guillotine/getMetaData.d.ts +94 -0
  10. package/guillotine/getMetaData.js +128 -0
  11. package/{src/index.ts → index.d.ts} +1 -1
  12. package/index.js +5 -0
  13. package/package.json +2 -2
  14. package/query/Shortcut.d.ts +1 -0
  15. package/server/ClearableFileCache.d.ts +31 -0
  16. package/server/ClearableFileCache.js +472 -0
  17. package/server/cache.d.ts +2 -0
  18. package/server/cache.js +129 -0
  19. package/server/index.d.ts +5 -0
  20. package/server/index.js +132 -0
  21. package/utils.d.ts +114 -0
  22. package/{src/utils.ts → utils.js} +81 -154
  23. package/views/BaseComponent.d.ts +25 -0
  24. package/{src/views/BaseComponent.tsx → views/BaseComponent.jsx} +39 -73
  25. package/views/BaseContent.d.ts +4 -0
  26. package/{src/views/BaseContent.tsx → views/BaseContent.jsx} +17 -24
  27. package/views/BaseLayout.d.ts +17 -0
  28. package/views/BaseLayout.jsx +24 -0
  29. package/views/BaseMacro.d.ts +16 -0
  30. package/{src/views/BaseMacro.tsx → views/BaseMacro.jsx} +29 -45
  31. package/views/BasePage.d.ts +19 -0
  32. package/views/BasePage.jsx +34 -0
  33. package/views/BasePart.d.ts +19 -0
  34. package/views/BasePart.jsx +24 -0
  35. package/views/Empty.d.ts +3 -0
  36. package/{src/views/Empty.tsx → views/Empty.jsx} +0 -2
  37. package/views/Fragment.d.ts +10 -0
  38. package/views/Fragment.jsx +30 -0
  39. package/views/MainView.d.ts +4 -0
  40. package/views/MainView.jsx +14 -0
  41. package/views/Region.d.ts +20 -0
  42. package/views/Region.jsx +52 -0
  43. package/views/RichTextView.d.ts +16 -0
  44. package/{src/views/RichTextView.tsx → views/RichTextView.jsx} +10 -31
  45. package/views/SingleComponent.d.ts +5 -0
  46. package/{src/views/SingleComponent.tsx → views/SingleComponent.jsx} +2 -8
  47. package/views/StaticContent.d.ts +15 -0
  48. package/views/StaticContent.jsx +36 -0
  49. package/views/Text.d.ts +9 -0
  50. package/views/Text.jsx +4 -0
  51. package/views/macros/DefaultMacro.d.ts +4 -0
  52. package/views/macros/DefaultMacro.jsx +3 -0
  53. package/views/macros/DisableMacro.d.ts +3 -0
  54. package/views/macros/DisableMacro.jsx +2 -0
  55. package/.eslint-childrc.js +0 -17
  56. package/.eslintrc.js +0 -15
  57. package/.github/dependabot.yml +0 -20
  58. package/.github/pull-merger.yml +0 -1
  59. package/.github/workflows/release.yml +0 -39
  60. package/LICENSE +0 -201
  61. package/RELEASE.md +0 -75
  62. package/server/.eslintrc.js +0 -11
  63. package/server/ClearableFileCache.ts +0 -410
  64. package/server/cache.ts +0 -50
  65. package/server/index.ts +0 -74
  66. package/server/tsconfig.json +0 -23
  67. package/src/.eslintrc.js +0 -11
  68. package/src/ComponentRegistry.ts +0 -189
  69. package/src/UrlProcessor.ts +0 -115
  70. package/src/guillotine/getMetaData.ts +0 -246
  71. package/src/tsconfig.json +0 -20
  72. package/src/views/BaseLayout.tsx +0 -45
  73. package/src/views/BasePage.tsx +0 -56
  74. package/src/views/BasePart.tsx +0 -50
  75. package/src/views/Fragment.tsx +0 -45
  76. package/src/views/MainView.tsx +0 -21
  77. package/src/views/Region.tsx +0 -89
  78. package/src/views/StaticContent.tsx +0 -40
  79. package/src/views/Text.tsx +0 -15
  80. package/src/views/macros/DefaultMacro.tsx +0 -9
  81. package/src/views/macros/DisableMacro.tsx +0 -8
  82. /package/{src/query/Shortcut.ts → query/Shortcut.js} +0 -0
@@ -1,50 +0,0 @@
1
- import React from 'react';
2
- import {MetaData, PartData} from '../guillotine/getMetaData';
3
- import {ComponentRegistry} from '../ComponentRegistry';
4
- import {XP_COMPONENT_TYPE} from '../utils';
5
- import {MissingComponent, shouldShowMissingView} from './BaseComponent';
6
-
7
-
8
- export interface PartProps {
9
- part: PartData;
10
- path: string;
11
- data?: any;
12
- common?: any; // Content is passed down to componentviews. TODO: Use a react contextprovider instead?
13
- meta: MetaData;
14
- }
15
-
16
- interface BasePartProps {
17
- component?: PartData;
18
- path: string;
19
- common?: any;
20
- data?: any;
21
- error?: string;
22
- meta: MetaData;
23
- }
24
-
25
- const BasePart = (props: BasePartProps) => {
26
- const {component, data, common, meta, path} = props;
27
-
28
- let partSelection;
29
- if (component) {
30
- partSelection = ComponentRegistry.getPart(component.descriptor);
31
- }
32
- const SelectedPartView = partSelection?.view;
33
- if (SelectedPartView) {
34
- return <SelectedPartView part={component}
35
- path={path}
36
- data={data}
37
- common={common}
38
- meta={meta}/>;
39
- } else if (component?.descriptor) {
40
- // empty descriptor usually means uninitialized part
41
- console.warn(`BasePart: can not render part '${component.descriptor}': no next view or catch-all defined`);
42
- if (shouldShowMissingView(meta)) {
43
- return <MissingComponent type={XP_COMPONENT_TYPE.PART} descriptor={component.descriptor}/>;
44
- }
45
- }
46
- return null;
47
- };
48
-
49
- export default BasePart;
50
-
@@ -1,45 +0,0 @@
1
- import React from 'react';
2
- import BaseComponent, {MissingComponent, shouldShowMissingView} from './BaseComponent';
3
- import {FragmentData, MetaData, PageComponent, PageData} from '../guillotine/getMetaData';
4
- import {FRAGMENT_DEFAULT_REGION_NAME, XP_COMPONENT_TYPE} from '../utils';
5
-
6
- interface FragmentProps {
7
- page?: PageData;
8
- component?: FragmentData;
9
- common?: any;
10
- meta: MetaData;
11
- }
12
-
13
- const FragmentView = (props: FragmentProps) => {
14
- const {component, page} = props;
15
- const comps: PageComponent[] = [];
16
- if (page) {
17
- // rendering whole page
18
- const regions = page.regions || {};
19
- const regionComps = regions[FRAGMENT_DEFAULT_REGION_NAME]?.components;
20
- if (regionComps) {
21
- comps.push(...regionComps);
22
- }
23
- } else if (component?.fragment) {
24
- // rendering a part of a page
25
- comps.push(...component.fragment.components);
26
- }
27
-
28
- if (!comps.length && shouldShowMissingView(props.meta)) {
29
- return <MissingComponent type={XP_COMPONENT_TYPE.FRAGMENT} descriptor={page?.descriptor || component?.id}/>;
30
- } else {
31
- const {common, meta} = props;
32
-
33
- return (
34
- <>
35
- {
36
- comps.map((comp: PageComponent, i: number) => (
37
- <BaseComponent key={i} component={comp} common={common} meta={meta}/>
38
- ))
39
- }
40
- </>
41
- );
42
- }
43
- };
44
-
45
- export default FragmentView;
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
-
3
- import {FetchContentResult} from '../guillotine/fetchContent';
4
- import SingleComponent from './SingleComponent';
5
- import BaseContent from './BaseContent';
6
- import {XP_REQUEST_TYPE} from '../utils';
7
-
8
-
9
- const _MainView = (props: FetchContentResult) => {
10
- const {meta} = props;
11
-
12
- // Single-component render:
13
- if (meta?.requestType === XP_REQUEST_TYPE.COMPONENT) {
14
- return <SingleComponent {...props} />;
15
- }
16
-
17
- // meta.requestType="type", and hence content-type based, is standard view for now.
18
- return <BaseContent {...props} />;
19
- };
20
-
21
- export default _MainView;
@@ -1,89 +0,0 @@
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,40 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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;
@@ -1,9 +0,0 @@
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;
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import {MacroProps} from '../BaseMacro';
3
-
4
- const DisableMacro = ({name, config, meta}: MacroProps) => (
5
- config.body
6
- );
7
-
8
- export default DisableMacro;
File without changes