@enonic/nextjs-adapter 1.0.2 → 2.0.0-B2
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/ComponentRegistry.d.ts +1 -1
- package/ComponentRegistry.js +1 -2
- package/UrlProcessor.d.ts +4 -3
- package/UrlProcessor.js +35 -26
- package/baseMappings.js +4 -0
- package/guillotine/fetchContent.d.ts +10 -25
- package/guillotine/fetchContent.js +122 -32
- package/guillotine/getMetaData.d.ts +3 -0
- package/package.json +14 -14
- package/query/Shortcut.d.ts +1 -0
- package/query/Shortcut.js +14 -0
- package/server/index.js +63 -51
- package/utils.d.ts +61 -4
- package/utils.js +123 -26
- package/views/BaseComponent.d.ts +4 -4
- package/views/BaseContent.d.ts +2 -2
- package/views/BaseLayout.d.ts +2 -2
- package/views/BaseMacro.d.ts +2 -2
- package/views/BasePage.d.ts +2 -2
- package/views/BasePart.d.ts +2 -2
- package/views/Empty.d.ts +2 -2
- package/views/Fragment.d.ts +2 -2
- package/views/Fragment.jsx +12 -7
- package/views/MainView.d.ts +2 -2
- package/views/Region.d.ts +3 -3
- package/views/RichTextView.d.ts +2 -2
- package/views/SingleComponent.d.ts +2 -2
- package/views/StaticContent.d.ts +5 -5
- package/views/StaticContent.jsx +18 -20
- package/views/Text.d.ts +2 -2
package/views/StaticContent.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ export interface StaticContentProps extends Record<string, any> {
|
|
|
4
4
|
element?: string;
|
|
5
5
|
condition: boolean;
|
|
6
6
|
}
|
|
7
|
-
export default function StaticContent({ children, element, condition, ...props }: StaticContentProps): import("react").
|
|
8
|
-
|
|
9
|
-
}, Element> | import("react").ReactElement<{
|
|
10
|
-
ref: boolean | import("react").MutableRefObject<any>;
|
|
7
|
+
export default function StaticContent({ children, element, condition, ...props }: StaticContentProps): import("react").ReactElement<{
|
|
8
|
+
ref: import("react").RefObject<unknown>;
|
|
11
9
|
suppressHydrationWarning: boolean;
|
|
12
10
|
dangerouslySetInnerHTML: {
|
|
13
11
|
__html: string;
|
|
14
12
|
};
|
|
15
|
-
}, string | import("react").JSXElementConstructor<any
|
|
13
|
+
}, string | import("react").JSXElementConstructor<any>> | import("react").DOMElement<{
|
|
14
|
+
[x: string]: any;
|
|
15
|
+
}, Element>;
|
package/views/StaticContent.jsx
CHANGED
|
@@ -9,30 +9,28 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { createElement,
|
|
13
|
-
function useStaticContent() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
setRender(true);
|
|
23
|
-
}
|
|
24
|
-
}, []);
|
|
25
|
-
return [render, ref];
|
|
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;
|
|
26
22
|
}
|
|
27
23
|
export default function StaticContent(_a) {
|
|
28
24
|
var { children, element = 'div', condition = true } = _a, props = __rest(_a, ["children", "element", "condition"]);
|
|
29
|
-
const
|
|
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
|
+
}
|
|
30
32
|
// just render if:
|
|
31
33
|
// - condition is false
|
|
32
34
|
// - we're in the server or a spa navigation
|
|
33
|
-
|
|
34
|
-
return createElement(element, props, ...[].concat(children));
|
|
35
|
-
}
|
|
36
|
-
// avoid re-render on the client
|
|
37
|
-
return createElement(element, Object.assign(Object.assign({}, props), { ref, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: '' } }));
|
|
35
|
+
return createElement(element, props, ...[].concat(children));
|
|
38
36
|
}
|
package/views/Text.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { MetaData, TextData } from '../guillotine/getMetaData';
|
|
3
3
|
type Props = {
|
|
4
4
|
meta: MetaData;
|
|
5
5
|
component: TextData;
|
|
6
6
|
path: string;
|
|
7
7
|
};
|
|
8
|
-
declare const DefaultTextView: ({ component, meta, path }: Props) => JSX.Element;
|
|
8
|
+
declare const DefaultTextView: ({ component, meta, path }: Props) => React.JSX.Element;
|
|
9
9
|
export default DefaultTextView;
|