@enonic/nextjs-adapter 0.12.0 → 1.0.0-RC1
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 +4 -2
- package/ComponentRegistry.js +6 -0
- package/README.md +623 -8
- package/UrlProcessor.d.ts +2 -1
- package/UrlProcessor.js +26 -1
- package/guillotine/fetchContent.d.ts +2 -21
- package/guillotine/fetchContent.js +128 -58
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +16 -15
- package/server/ClearableFileCache.js +314 -0
- package/server/cache.js +129 -0
- package/server/index.js +114 -0
- package/utils.d.ts +3 -12
- package/utils.js +10 -23
- package/views/Region.jsx +1 -6
- package/views/RichTextView.jsx +11 -4
- package/views/StaticContent.d.ts +15 -0
- package/views/StaticContent.jsx +38 -0
package/views/Region.jsx
CHANGED
|
@@ -15,12 +15,7 @@ export const RegionView = (props) => {
|
|
|
15
15
|
regionAttrs.id = name + 'Region';
|
|
16
16
|
regionAttrs[PORTAL_REGION_ATTRIBUTE] = name;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
return <div {...regionAttrs}>{children}</div>;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return <>{children}</>;
|
|
23
|
-
}
|
|
18
|
+
return <div {...regionAttrs}>{children}</div>;
|
|
24
19
|
};
|
|
25
20
|
/** Multiple regions, or only one if named in props.selected */
|
|
26
21
|
const RegionsView = (props) => {
|
package/views/RichTextView.jsx
CHANGED
|
@@ -14,10 +14,17 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
14
14
|
switch (el.tagName) {
|
|
15
15
|
case UrlProcessor.IMG_TAG:
|
|
16
16
|
ref = el.attribs[UrlProcessor.IMG_ATTR];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (ref) {
|
|
18
|
+
if (UrlProcessor.isContentImage(ref, allData.images)) {
|
|
19
|
+
const src = el.attribs['src'];
|
|
20
|
+
if (src) {
|
|
21
|
+
el.attribs['src'] = getUrl(src, meta);
|
|
22
|
+
}
|
|
23
|
+
const srcset = el.attribs['srcset'];
|
|
24
|
+
if (srcset) {
|
|
25
|
+
el.attribs['srcset'] = UrlProcessor.processSrcSet(srcset, meta);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
29
|
break;
|
|
23
30
|
case UrlProcessor.LINK_TAG:
|
|
@@ -0,0 +1,15 @@
|
|
|
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").DOMElement<{
|
|
8
|
+
[x: string]: any;
|
|
9
|
+
}, Element> | import("react").ReactElement<{
|
|
10
|
+
ref: boolean | import("react").MutableRefObject<any>;
|
|
11
|
+
suppressHydrationWarning: boolean;
|
|
12
|
+
dangerouslySetInnerHTML: {
|
|
13
|
+
__html: string;
|
|
14
|
+
};
|
|
15
|
+
}, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -0,0 +1,38 @@
|
|
|
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, useEffect, useRef, useState } from 'react';
|
|
13
|
+
function useStaticContent() {
|
|
14
|
+
const ref = useRef(null);
|
|
15
|
+
const [render, setRender] = useState(typeof window === 'undefined');
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
var _a;
|
|
18
|
+
// check if the innerHTML is empty as client side navigation
|
|
19
|
+
// need to render the component without server-side backup
|
|
20
|
+
const isEmpty = ((_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.innerHTML) === '';
|
|
21
|
+
if (isEmpty) {
|
|
22
|
+
setRender(true);
|
|
23
|
+
}
|
|
24
|
+
}, []);
|
|
25
|
+
return [render, ref];
|
|
26
|
+
}
|
|
27
|
+
export default function StaticContent(_a) {
|
|
28
|
+
var { children, element = 'div', condition = true } = _a, props = __rest(_a, ["children", "element", "condition"]);
|
|
29
|
+
const [render, ref] = useStaticContent();
|
|
30
|
+
// just render if:
|
|
31
|
+
// - condition is false
|
|
32
|
+
// - we're in the server or a spa navigation
|
|
33
|
+
if (render || !condition) {
|
|
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: '' } }));
|
|
38
|
+
}
|