@merkle-open/magnolia-headless-frontend-nextjs 0.0.3 → 0.0.5
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/package.json
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import { EditableArea as MagnoliaEditableArea } from '@magnolia/react-editor';
|
|
1
|
+
import { EditableArea as MagnoliaEditableArea, RefService } from '@magnolia/react-editor';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
import EditableAreaProps from './EditableAreaProps.ts';
|
|
4
|
-
import { ContentRendererService, MgnlContent } from '@magnolia/frontend-helpers-base';
|
|
4
|
+
import { ContentRendererService, IMagnoliaContext, MgnlContent } from '@magnolia/frontend-helpers-base';
|
|
5
5
|
import { EditableComponent } from '../../components/__magnolia-editable-component/EditableComponent.tsx';
|
|
6
6
|
|
|
7
|
+
function shouldRender(hasChildren: boolean, renderEmpty?: boolean) {
|
|
8
|
+
if (renderEmpty) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const magnoliaContext = RefService.getMagnoliaContextRef<IMagnoliaContext>();
|
|
12
|
+
const isEditMode = magnoliaContext?.isMagnoliaEdit;
|
|
13
|
+
return isEditMode || hasChildren;
|
|
14
|
+
}
|
|
15
|
+
|
|
7
16
|
export function EditableArea(props: EditableAreaProps): ReactNode {
|
|
8
17
|
const { content, additionalContent, additionalComponentContent } = props;
|
|
9
18
|
const componentNodeMapping = content['@nodes'].map((nodeName: any) => [nodeName, merge(content[nodeName], additionalComponentContent)]);
|
|
@@ -13,9 +22,11 @@ export function EditableArea(props: EditableAreaProps): ReactNode {
|
|
|
13
22
|
const children = componentContents?.map((item, index) => <EditableComponent key={ContentRendererService.buildKey(item)} content={item} index={index} />);
|
|
14
23
|
|
|
15
24
|
return (
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
|
|
25
|
+
shouldRender(children.length > 0, props.renderEmpty) && (
|
|
26
|
+
<MagnoliaEditableArea {...props} content={mergedContent}>
|
|
27
|
+
{children}
|
|
28
|
+
</MagnoliaEditableArea>
|
|
29
|
+
)
|
|
19
30
|
);
|
|
20
31
|
}
|
|
21
32
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { ReactNode } from 'react';
|
|
4
|
-
import
|
|
3
|
+
import React, { ReactNode, Suspense } from 'react';
|
|
4
|
+
import ErrorElement from './ErrorElement.tsx';
|
|
5
5
|
|
|
6
6
|
interface ErrorState {
|
|
7
|
-
error: Error;
|
|
7
|
+
error: Error | null;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface ErrorProps {
|
|
@@ -26,8 +26,8 @@ export default class ErrorBoundary extends React.Component<ErrorProps, ErrorStat
|
|
|
26
26
|
|
|
27
27
|
render() {
|
|
28
28
|
if (this.state.error) {
|
|
29
|
-
return <
|
|
29
|
+
return <ErrorElement editMode={this.props.isEditMode} throwNotEditMode={this.props.throwNotEditMode} path={this.props.path} msg={this.state.error.message} />;
|
|
30
30
|
}
|
|
31
|
-
return this.props.children
|
|
31
|
+
return <Suspense fallback={null}>{this.props.children}</Suspense>;
|
|
32
32
|
}
|
|
33
33
|
}
|