@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.
Files changed (81) hide show
  1. package/ComponentRegistry.d.ts +64 -0
  2. package/ComponentRegistry.js +121 -0
  3. package/UrlProcessor.d.ts +25 -0
  4. package/{src/UrlProcessor.ts → UrlProcessor.js} +35 -53
  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} +243 -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} +69 -148
  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/guillotine/getMetaData.ts +0 -246
  70. package/src/tsconfig.json +0 -20
  71. package/src/views/BaseLayout.tsx +0 -45
  72. package/src/views/BasePage.tsx +0 -56
  73. package/src/views/BasePart.tsx +0 -50
  74. package/src/views/Fragment.tsx +0 -45
  75. package/src/views/MainView.tsx +0 -21
  76. package/src/views/Region.tsx +0 -89
  77. package/src/views/StaticContent.tsx +0 -40
  78. package/src/views/Text.tsx +0 -15
  79. package/src/views/macros/DefaultMacro.tsx +0 -9
  80. package/src/views/macros/DisableMacro.tsx +0 -8
  81. /package/{src/query/Shortcut.ts → query/Shortcut.js} +0 -0
@@ -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