@sitecore-content-sdk/react 0.3.0-canary.9 → 0.3.0
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/README.md +1 -1
- package/dist/cjs/components/EditingScripts.js +2 -2
- package/dist/cjs/components/ErrorBoundary.js +4 -4
- package/dist/cjs/components/FEaaSComponent.js +2 -2
- package/dist/cjs/components/Form.js +2 -2
- package/dist/cjs/components/HiddenRendering.js +8 -3
- package/dist/cjs/components/Image.js +1 -1
- package/dist/cjs/components/MissingComponent.js +1 -1
- package/dist/cjs/components/Placeholder.js +1 -1
- package/dist/cjs/components/PlaceholderCommon.js +5 -1
- package/dist/cjs/enhancers/withPlaceholder.js +1 -1
- package/dist/cjs/enhancers/withSitecore.js +1 -1
- package/dist/esm/components/EditingScripts.js +3 -3
- package/dist/esm/components/ErrorBoundary.js +4 -4
- package/dist/esm/components/FEaaSComponent.js +2 -2
- package/dist/esm/components/Form.js +2 -2
- package/dist/esm/components/HiddenRendering.js +8 -3
- package/dist/esm/components/Image.js +1 -1
- package/dist/esm/components/MissingComponent.js +1 -1
- package/dist/esm/components/Placeholder.js +1 -1
- package/dist/esm/components/PlaceholderCommon.js +5 -1
- package/dist/esm/enhancers/withPlaceholder.js +1 -1
- package/dist/esm/enhancers/withSitecore.js +1 -1
- package/package.json +5 -5
- package/types/components/ErrorBoundary.d.ts +1 -0
- package/types/components/PlaceholderCommon.d.ts +5 -0
- package/types/components/sharedTypes/components.d.ts +2 -2
- package/types/enhancers/withPlaceholder.d.ts +1 -1
- package/types/enhancers/withSitecore.d.ts +1 -1
- package/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,6 @@ This module is provided as a part of Sitecore Content SDK. It contains React com
|
|
|
6
6
|
@TODO: Update link with appropriate page when avaiable
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
|
-
[Documentation](https://doc.sitecore.com/xmc/en/developers/
|
|
9
|
+
[Documentation](https://doc.sitecore.com/xmc/en/developers/content-sdk/creating-a-content-sdk-app.html)
|
|
10
10
|
|
|
11
11
|
[API reference documentation](/ref-docs/react/)
|
|
@@ -31,9 +31,9 @@ const EditingScripts = () => {
|
|
|
31
31
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
32
32
|
react_1.default.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
33
33
|
}
|
|
34
|
-
const
|
|
34
|
+
const contentSdkClientData = Object.assign(Object.assign({}, clientData), (0, editing_1.getContentSdkPagesClientData)());
|
|
35
35
|
return (react_1.default.createElement(react_1.default.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
36
36
|
clientScripts.map((src, index) => (react_1.default.createElement("script", { src: src, key: index }))),
|
|
37
|
-
Object.keys(
|
|
37
|
+
Object.keys(contentSdkClientData).map((id) => (react_1.default.createElement("script", { key: id, id: id, type: "application/json", dangerouslySetInnerHTML: { __html: JSON.stringify(contentSdkClientData[id]) } })))));
|
|
38
38
|
};
|
|
39
39
|
exports.EditingScripts = EditingScripts;
|
|
@@ -71,7 +71,7 @@ class ErrorBoundary extends react_1.default.Component {
|
|
|
71
71
|
else {
|
|
72
72
|
if (this.showErrorDetails()) {
|
|
73
73
|
return (react_1.default.createElement("div", null,
|
|
74
|
-
react_1.default.createElement("div", { className: "sc-
|
|
74
|
+
react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" },
|
|
75
75
|
"A rendering error occurred in component",
|
|
76
76
|
' ',
|
|
77
77
|
react_1.default.createElement("em", null, (_a = this.props.rendering) === null || _a === void 0 ? void 0 : _a.componentName),
|
|
@@ -81,12 +81,12 @@ class ErrorBoundary extends react_1.default.Component {
|
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
83
|
return (react_1.default.createElement("div", null,
|
|
84
|
-
react_1.default.createElement("div", { className: "sc-
|
|
84
|
+
react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" }, this.defaultErrorMessage)));
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
// do not apply suspense on already dynamic components
|
|
89
|
-
if (this.props.isDynamic) {
|
|
88
|
+
// do not apply suspense when suspense is disabled or when on already dynamic components
|
|
89
|
+
if (this.props.disableSuspense || this.props.isDynamic) {
|
|
90
90
|
return this.props.children;
|
|
91
91
|
}
|
|
92
92
|
return (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement("h4", null, this.props.componentLoadingMessage || this.defaultLoadingMessage) }, this.props.children));
|
|
@@ -71,9 +71,9 @@ const FEaaSComponent = (props) => {
|
|
|
71
71
|
// combine fetchedData from server with datasource data (if present)
|
|
72
72
|
const data = Object.assign(Object.assign({}, props.fetchedData), { _: (0, utils_1.getDataFromFields)((_b = props.fields) !== null && _b !== void 0 ? _b : {}) });
|
|
73
73
|
// FEaaS control would still be hydrated by client
|
|
74
|
-
// we pass all the props as a workaround to avoid hydration error, until we convert all
|
|
74
|
+
// we pass all the props as a workaround to avoid hydration error, until we convert all Content SDK components to server side
|
|
75
75
|
// this also allows component to fall back to full client-side rendering when template or src is empty
|
|
76
|
-
// FEAAS should not fetch anything, since
|
|
76
|
+
// FEAAS should not fetch anything, since Content SDK does the fetching - so we pass empty array into fetch param
|
|
77
77
|
return (react_1.default.createElement(FEAAS.Component, { data: data, template: props.template, cdn: (_c = props.params) === null || _c === void 0 ? void 0 : _c.ComponentHostName, library: (_d = props.params) === null || _d === void 0 ? void 0 : _d.LibraryId, version: (_e = props.params) === null || _e === void 0 ? void 0 : _e.ComponentVersion, component: (_f = props.params) === null || _f === void 0 ? void 0 : _f.ComponentId, instance: (_g = props.params) === null || _g === void 0 ? void 0 : _g.ComponentInstanceId, revision: computedRevision, fetch: [] }));
|
|
78
78
|
};
|
|
79
79
|
exports.FEaaSComponent = FEaaSComponent;
|
|
@@ -63,7 +63,7 @@ const Form = ({ params, rendering }) => {
|
|
|
63
63
|
.then(setContent)
|
|
64
64
|
.catch(() => {
|
|
65
65
|
if (isEditing) {
|
|
66
|
-
console.error(`Failed to load form with id ${params.FormId}. Check debug logs for
|
|
66
|
+
console.error(`Failed to load form with id ${params.FormId}. Check debug logs for content-sdk:form for more details.`);
|
|
67
67
|
}
|
|
68
68
|
setError(true);
|
|
69
69
|
});
|
|
@@ -78,7 +78,7 @@ const Form = ({ params, rendering }) => {
|
|
|
78
78
|
}, [content]);
|
|
79
79
|
if (isEditing) {
|
|
80
80
|
if (error) {
|
|
81
|
-
return (react_1.default.createElement("div", { className: "sc-
|
|
81
|
+
return (react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" }, "There was a problem loading this section"));
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
return (react_1.default.createElement("div", { ref: formRef, dangerouslySetInnerHTML: { __html: content }, className: (_a = params.styles) === null || _a === void 0 ? void 0 : _a.trimEnd(), id: id ? id : undefined }));
|
|
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.HiddenRendering = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const
|
|
9
|
-
backgroundImage: 'linear-gradient(45deg, #ffffff 25%, #dcdcdc 25%, #dcdcdc 50%, #ffffff 50%, #ffffff 75%, #dcdcdc 75%, #dcdcdc 100%)',
|
|
8
|
+
const baseStyles = {
|
|
10
9
|
backgroundSize: '3px 3px',
|
|
11
10
|
display: 'flex',
|
|
12
11
|
justifyContent: 'center',
|
|
@@ -14,5 +13,11 @@ const styles = {
|
|
|
14
13
|
padding: '30px',
|
|
15
14
|
color: '#aaa',
|
|
16
15
|
};
|
|
17
|
-
const
|
|
16
|
+
const backgroundImageStyle = {
|
|
17
|
+
backgroundImage: 'linear-gradient(45deg, #ffffff 25%, #dcdcdc 25%, #dcdcdc 50%, #ffffff 50%, #ffffff 75%, #dcdcdc 75%, #dcdcdc 100%)',
|
|
18
|
+
};
|
|
19
|
+
const HiddenRendering = () => {
|
|
20
|
+
const styles = process.env.NODE_ENV === 'test' ? baseStyles : Object.assign(Object.assign({}, baseStyles), backgroundImageStyle);
|
|
21
|
+
return react_1.default.createElement("div", { style: styles }, "The component is hidden");
|
|
22
|
+
};
|
|
18
23
|
exports.HiddenRendering = HiddenRendering;
|
|
@@ -29,7 +29,7 @@ const getImageAttrs = (_a, imageParams, mediaUrlPrefix) => {
|
|
|
29
29
|
}
|
|
30
30
|
(0, utils_1.addClassName)(otherAttrs);
|
|
31
31
|
const newAttrs = Object.assign({}, otherAttrs);
|
|
32
|
-
// update image URL for
|
|
32
|
+
// update image URL for content sdk handler and image rendering params
|
|
33
33
|
const resolvedSrc = media_1.mediaApi.updateImageUrl(src, imageParams, mediaUrlPrefix);
|
|
34
34
|
if (srcSet) {
|
|
35
35
|
// replace with HTML-formatted srcset, including updated image URLs
|
|
@@ -13,7 +13,7 @@ const MissingComponent = (props) => {
|
|
|
13
13
|
!props.errorOverride &&
|
|
14
14
|
console.log(`Component props for unimplemented '${componentName}' component`, props);
|
|
15
15
|
const errorMessage = props.errorOverride ||
|
|
16
|
-
'
|
|
16
|
+
'Content SDK component is missing React implementation. See the developer console for more information.';
|
|
17
17
|
return (react_1.default.createElement("div", { style: {
|
|
18
18
|
background: 'darkorange',
|
|
19
19
|
outline: '5px solid orange',
|
|
@@ -35,7 +35,7 @@ class PlaceholderComponent extends PlaceholderCommon_1.PlaceholderCommon {
|
|
|
35
35
|
if (childProps.errorComponent) {
|
|
36
36
|
return react_1.default.createElement(childProps.errorComponent, { error: this.state.error });
|
|
37
37
|
}
|
|
38
|
-
return (react_1.default.createElement("div", { className: "sc-
|
|
38
|
+
return (react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" },
|
|
39
39
|
"A rendering error occurred: ",
|
|
40
40
|
this.state.error.message,
|
|
41
41
|
"."));
|
|
@@ -132,9 +132,13 @@ class PlaceholderCommon extends react_1.default.Component {
|
|
|
132
132
|
if (!isEmpty) {
|
|
133
133
|
// assign type based on passed element - type='text/sitecore' should be ignored when renderEach Placeholder prop function is being used
|
|
134
134
|
const type = rendered.props.type === 'text/sitecore' ? rendered.props.type : '';
|
|
135
|
+
const disableSuspense = this.props.disableSuspense || false;
|
|
135
136
|
// wrapping with error boundary could cause problems in case where parent component uses withPlaceholder HOC and tries to access its children props
|
|
136
137
|
// that's why we need to expose element's props here
|
|
137
|
-
|
|
138
|
+
const isByocWrapper = componentRendering.componentName === BYOCWrapper_1.BYOC_WRAPPER_RENDERING_NAME;
|
|
139
|
+
// all dynamic elements will have a separate render prop
|
|
140
|
+
const isDynamicComponent = !!((_a = component.render) === null || _a === void 0 ? void 0 : _a.preload);
|
|
141
|
+
rendered = (react_1.default.createElement(ErrorBoundary_1.default, Object.assign({ "data-testid": "error-boundary", key: rendered.type + '-' + index, errorComponent: this.props.errorComponent, componentLoadingMessage: this.props.componentLoadingMessage, type: type, isDynamic: isDynamicComponent || isByocWrapper, disableSuspense: disableSuspense }, rendered.props), rendered));
|
|
138
142
|
}
|
|
139
143
|
// if in edit mode then emit shallow chromes for hydration in Pages
|
|
140
144
|
if ((_b = this.props.pageContext) === null || _b === void 0 ? void 0 : _b.pageEditing) {
|
|
@@ -28,7 +28,7 @@ function withPlaceholder(placeholders, options) {
|
|
|
28
28
|
if (childProps.errorComponent) {
|
|
29
29
|
return react_1.default.createElement(childProps.errorComponent, { error: this.state.error });
|
|
30
30
|
}
|
|
31
|
-
return (react_1.default.createElement("div", { className: "sc-
|
|
31
|
+
return (react_1.default.createElement("div", { className: "sc-content-sdk-placeholder-error" },
|
|
32
32
|
"A rendering error occurred: ",
|
|
33
33
|
this.state.error.message,
|
|
34
34
|
"."));
|
|
@@ -19,7 +19,7 @@ function withSitecore(options) {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* This hook grants acсess to the current Sitecore page context and api.
|
|
22
|
-
* by default
|
|
22
|
+
* by default Content SDK includes the following properties in this context:
|
|
23
23
|
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Sitecore Editor.
|
|
24
24
|
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
|
25
25
|
* - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { LayoutServicePageState, RenderingType } from '@sitecore-content-sdk/core/layout';
|
|
3
3
|
import { useSitecore } from '../enhancers/withSitecore';
|
|
4
|
-
import {
|
|
4
|
+
import { getContentSdkPagesClientData } from '@sitecore-content-sdk/core/editing';
|
|
5
5
|
import { getDesignLibraryScriptLink } from '@sitecore-content-sdk/core/editing';
|
|
6
6
|
/**
|
|
7
7
|
* Renders client scripts and data for editing/preview mode for Pages.
|
|
@@ -25,8 +25,8 @@ export const EditingScripts = () => {
|
|
|
25
25
|
return (React.createElement(React.Fragment, null,
|
|
26
26
|
React.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const contentSdkClientData = Object.assign(Object.assign({}, clientData), getContentSdkPagesClientData());
|
|
29
29
|
return (React.createElement(React.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
30
30
|
clientScripts.map((src, index) => (React.createElement("script", { src: src, key: index }))),
|
|
31
|
-
Object.keys(
|
|
31
|
+
Object.keys(contentSdkClientData).map((id) => (React.createElement("script", { key: id, id: id, type: "application/json", dangerouslySetInnerHTML: { __html: JSON.stringify(contentSdkClientData[id]) } })))));
|
|
32
32
|
};
|
|
@@ -36,7 +36,7 @@ class ErrorBoundary extends React.Component {
|
|
|
36
36
|
else {
|
|
37
37
|
if (this.showErrorDetails()) {
|
|
38
38
|
return (React.createElement("div", null,
|
|
39
|
-
React.createElement("div", { className: "sc-
|
|
39
|
+
React.createElement("div", { className: "sc-content-sdk-placeholder-error" },
|
|
40
40
|
"A rendering error occurred in component",
|
|
41
41
|
' ',
|
|
42
42
|
React.createElement("em", null, (_a = this.props.rendering) === null || _a === void 0 ? void 0 : _a.componentName),
|
|
@@ -46,12 +46,12 @@ class ErrorBoundary extends React.Component {
|
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
48
|
return (React.createElement("div", null,
|
|
49
|
-
React.createElement("div", { className: "sc-
|
|
49
|
+
React.createElement("div", { className: "sc-content-sdk-placeholder-error" }, this.defaultErrorMessage)));
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
// do not apply suspense on already dynamic components
|
|
54
|
-
if (this.props.isDynamic) {
|
|
53
|
+
// do not apply suspense when suspense is disabled or when on already dynamic components
|
|
54
|
+
if (this.props.disableSuspense || this.props.isDynamic) {
|
|
55
55
|
return this.props.children;
|
|
56
56
|
}
|
|
57
57
|
return (React.createElement(Suspense, { fallback: React.createElement("h4", null, this.props.componentLoadingMessage || this.defaultLoadingMessage) }, this.props.children));
|
|
@@ -31,9 +31,9 @@ export const FEaaSComponent = (props) => {
|
|
|
31
31
|
// combine fetchedData from server with datasource data (if present)
|
|
32
32
|
const data = Object.assign(Object.assign({}, props.fetchedData), { _: getDataFromFields((_b = props.fields) !== null && _b !== void 0 ? _b : {}) });
|
|
33
33
|
// FEaaS control would still be hydrated by client
|
|
34
|
-
// we pass all the props as a workaround to avoid hydration error, until we convert all
|
|
34
|
+
// we pass all the props as a workaround to avoid hydration error, until we convert all Content SDK components to server side
|
|
35
35
|
// this also allows component to fall back to full client-side rendering when template or src is empty
|
|
36
|
-
// FEAAS should not fetch anything, since
|
|
36
|
+
// FEAAS should not fetch anything, since Content SDK does the fetching - so we pass empty array into fetch param
|
|
37
37
|
return (React.createElement(FEAAS.Component, { data: data, template: props.template, cdn: (_c = props.params) === null || _c === void 0 ? void 0 : _c.ComponentHostName, library: (_d = props.params) === null || _d === void 0 ? void 0 : _d.LibraryId, version: (_e = props.params) === null || _e === void 0 ? void 0 : _e.ComponentVersion, component: (_f = props.params) === null || _f === void 0 ? void 0 : _f.ComponentId, instance: (_g = props.params) === null || _g === void 0 ? void 0 : _g.ComponentInstanceId, revision: computedRevision, fetch: [] }));
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
@@ -26,7 +26,7 @@ export const Form = ({ params, rendering }) => {
|
|
|
26
26
|
.then(setContent)
|
|
27
27
|
.catch(() => {
|
|
28
28
|
if (isEditing) {
|
|
29
|
-
console.error(`Failed to load form with id ${params.FormId}. Check debug logs for
|
|
29
|
+
console.error(`Failed to load form with id ${params.FormId}. Check debug logs for content-sdk:form for more details.`);
|
|
30
30
|
}
|
|
31
31
|
setError(true);
|
|
32
32
|
});
|
|
@@ -41,7 +41,7 @@ export const Form = ({ params, rendering }) => {
|
|
|
41
41
|
}, [content]);
|
|
42
42
|
if (isEditing) {
|
|
43
43
|
if (error) {
|
|
44
|
-
return (React.createElement("div", { className: "sc-
|
|
44
|
+
return (React.createElement("div", { className: "sc-content-sdk-placeholder-error" }, "There was a problem loading this section"));
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
return (React.createElement("div", { ref: formRef, dangerouslySetInnerHTML: { __html: content }, className: (_a = params.styles) === null || _a === void 0 ? void 0 : _a.trimEnd(), id: id ? id : undefined }));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
const
|
|
3
|
-
backgroundImage: 'linear-gradient(45deg, #ffffff 25%, #dcdcdc 25%, #dcdcdc 50%, #ffffff 50%, #ffffff 75%, #dcdcdc 75%, #dcdcdc 100%)',
|
|
2
|
+
const baseStyles = {
|
|
4
3
|
backgroundSize: '3px 3px',
|
|
5
4
|
display: 'flex',
|
|
6
5
|
justifyContent: 'center',
|
|
@@ -8,4 +7,10 @@ const styles = {
|
|
|
8
7
|
padding: '30px',
|
|
9
8
|
color: '#aaa',
|
|
10
9
|
};
|
|
11
|
-
|
|
10
|
+
const backgroundImageStyle = {
|
|
11
|
+
backgroundImage: 'linear-gradient(45deg, #ffffff 25%, #dcdcdc 25%, #dcdcdc 50%, #ffffff 50%, #ffffff 75%, #dcdcdc 75%, #dcdcdc 100%)',
|
|
12
|
+
};
|
|
13
|
+
export const HiddenRendering = () => {
|
|
14
|
+
const styles = process.env.NODE_ENV === 'test' ? baseStyles : Object.assign(Object.assign({}, baseStyles), backgroundImageStyle);
|
|
15
|
+
return React.createElement("div", { style: styles }, "The component is hidden");
|
|
16
|
+
};
|
|
@@ -23,7 +23,7 @@ const getImageAttrs = (_a, imageParams, mediaUrlPrefix) => {
|
|
|
23
23
|
}
|
|
24
24
|
addClassName(otherAttrs);
|
|
25
25
|
const newAttrs = Object.assign({}, otherAttrs);
|
|
26
|
-
// update image URL for
|
|
26
|
+
// update image URL for content sdk handler and image rendering params
|
|
27
27
|
const resolvedSrc = mediaApi.updateImageUrl(src, imageParams, mediaUrlPrefix);
|
|
28
28
|
if (srcSet) {
|
|
29
29
|
// replace with HTML-formatted srcset, including updated image URLs
|
|
@@ -7,7 +7,7 @@ export const MissingComponent = (props) => {
|
|
|
7
7
|
!props.errorOverride &&
|
|
8
8
|
console.log(`Component props for unimplemented '${componentName}' component`, props);
|
|
9
9
|
const errorMessage = props.errorOverride ||
|
|
10
|
-
'
|
|
10
|
+
'Content SDK component is missing React implementation. See the developer console for more information.';
|
|
11
11
|
return (React.createElement("div", { style: {
|
|
12
12
|
background: 'darkorange',
|
|
13
13
|
outline: '5px solid orange',
|
|
@@ -29,7 +29,7 @@ class PlaceholderComponent extends PlaceholderCommon {
|
|
|
29
29
|
if (childProps.errorComponent) {
|
|
30
30
|
return React.createElement(childProps.errorComponent, { error: this.state.error });
|
|
31
31
|
}
|
|
32
|
-
return (React.createElement("div", { className: "sc-
|
|
32
|
+
return (React.createElement("div", { className: "sc-content-sdk-placeholder-error" },
|
|
33
33
|
"A rendering error occurred: ",
|
|
34
34
|
this.state.error.message,
|
|
35
35
|
"."));
|
|
@@ -126,9 +126,13 @@ export class PlaceholderCommon extends React.Component {
|
|
|
126
126
|
if (!isEmpty) {
|
|
127
127
|
// assign type based on passed element - type='text/sitecore' should be ignored when renderEach Placeholder prop function is being used
|
|
128
128
|
const type = rendered.props.type === 'text/sitecore' ? rendered.props.type : '';
|
|
129
|
+
const disableSuspense = this.props.disableSuspense || false;
|
|
129
130
|
// wrapping with error boundary could cause problems in case where parent component uses withPlaceholder HOC and tries to access its children props
|
|
130
131
|
// that's why we need to expose element's props here
|
|
131
|
-
|
|
132
|
+
const isByocWrapper = componentRendering.componentName === BYOC_WRAPPER_RENDERING_NAME;
|
|
133
|
+
// all dynamic elements will have a separate render prop
|
|
134
|
+
const isDynamicComponent = !!((_a = component.render) === null || _a === void 0 ? void 0 : _a.preload);
|
|
135
|
+
rendered = (React.createElement(ErrorBoundary, Object.assign({ "data-testid": "error-boundary", key: rendered.type + '-' + index, errorComponent: this.props.errorComponent, componentLoadingMessage: this.props.componentLoadingMessage, type: type, isDynamic: isDynamicComponent || isByocWrapper, disableSuspense: disableSuspense }, rendered.props), rendered));
|
|
132
136
|
}
|
|
133
137
|
// if in edit mode then emit shallow chromes for hydration in Pages
|
|
134
138
|
if ((_b = this.props.pageContext) === null || _b === void 0 ? void 0 : _b.pageEditing) {
|
|
@@ -22,7 +22,7 @@ export function withPlaceholder(placeholders, options) {
|
|
|
22
22
|
if (childProps.errorComponent) {
|
|
23
23
|
return React.createElement(childProps.errorComponent, { error: this.state.error });
|
|
24
24
|
}
|
|
25
|
-
return (React.createElement("div", { className: "sc-
|
|
25
|
+
return (React.createElement("div", { className: "sc-content-sdk-placeholder-error" },
|
|
26
26
|
"A rendering error occurred: ",
|
|
27
27
|
this.state.error.message,
|
|
28
28
|
"."));
|
|
@@ -12,7 +12,7 @@ export function withSitecore(options) {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* This hook grants acсess to the current Sitecore page context and api.
|
|
15
|
-
* by default
|
|
15
|
+
* by default Content SDK includes the following properties in this context:
|
|
16
16
|
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Sitecore Editor.
|
|
17
17
|
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
|
18
18
|
* - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/react",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"url": "https://github.com/sitecore/content-sdk/issues"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@sitecore-feaas/clientside": "^0.
|
|
33
|
+
"@sitecore-feaas/clientside": "^0.6.0",
|
|
34
34
|
"@testing-library/dom": "^10.4.0",
|
|
35
35
|
"@testing-library/react": "^16.3.0",
|
|
36
36
|
"@types/chai": "^5.2.2",
|
|
@@ -58,17 +58,17 @@
|
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@sitecore-cloudsdk/events": "^0.5.1",
|
|
61
|
-
"@sitecore-feaas/clientside": "^0.
|
|
61
|
+
"@sitecore-feaas/clientside": "^0.6.0",
|
|
62
62
|
"react": "^19.1.0",
|
|
63
63
|
"react-dom": "^19.1.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@sitecore-content-sdk/core": "0.3.0
|
|
66
|
+
"@sitecore-content-sdk/core": "0.3.0",
|
|
67
67
|
"fast-deep-equal": "^3.1.3"
|
|
68
68
|
},
|
|
69
69
|
"description": "",
|
|
70
70
|
"types": "types/index.d.ts",
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "b85e73a9c4da1fe7b135cc6d629617121cce0ad5",
|
|
72
72
|
"files": [
|
|
73
73
|
"dist",
|
|
74
74
|
"types"
|
|
@@ -12,6 +12,7 @@ export type ErrorBoundaryProps = {
|
|
|
12
12
|
errorComponent?: React.ComponentClass<ErrorComponentProps> | React.FC<ErrorComponentProps>;
|
|
13
13
|
rendering?: ComponentRendering;
|
|
14
14
|
componentLoadingMessage?: string;
|
|
15
|
+
disableSuspense?: boolean;
|
|
15
16
|
};
|
|
16
17
|
declare const _default: (props: import("@sitecore-content-sdk/core/utils").EnhancedOmit<ErrorBoundaryProps, keyof import("../enhancers/withSitecore").WithSitecoreProps>) => React.JSX.Element;
|
|
17
18
|
export default _default;
|
|
@@ -65,6 +65,11 @@ export interface PlaceholderProps {
|
|
|
65
65
|
* The message that gets displayed while component is loading
|
|
66
66
|
*/
|
|
67
67
|
componentLoadingMessage?: string;
|
|
68
|
+
/**
|
|
69
|
+
* If true, disables Suspense in ErrorBoundary for the placeholder.
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
72
|
+
disableSuspense?: boolean;
|
|
68
73
|
}
|
|
69
74
|
export declare class PlaceholderCommon<T extends PlaceholderProps> extends React.Component<T> {
|
|
70
75
|
state: Readonly<{
|
|
@@ -6,7 +6,7 @@ export declare const DEFAULT_EXPORT_NAME = "Default";
|
|
|
6
6
|
/**
|
|
7
7
|
* React component import with account for custom exports
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type ReactContentSdkComponent = ComponentType | ReactModule;
|
|
10
10
|
export type ReactModule = {
|
|
11
11
|
/**
|
|
12
12
|
* Custom exports
|
|
@@ -29,4 +29,4 @@ export type LazyComponentType = ComponentType & {
|
|
|
29
29
|
[key: string]: unknown;
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
|
-
export type ComponentMap<TComponent extends
|
|
32
|
+
export type ComponentMap<TComponent extends ReactContentSdkComponent = ReactContentSdkComponent> = Map<string, TComponent>;
|
|
@@ -4,7 +4,7 @@ import { PlaceholderProps } from '../components/PlaceholderCommon';
|
|
|
4
4
|
export interface WithPlaceholderOptions {
|
|
5
5
|
/**
|
|
6
6
|
* Function to map incoming placeholder props into rendering data to use for the placeholder data.
|
|
7
|
-
* Normally in a
|
|
7
|
+
* Normally in a Content SDK component, props.rendering is passed the component data, and that is the default.
|
|
8
8
|
* However, if your component data is in a different prop, like say 'route' in a sample app,
|
|
9
9
|
* this lets you map that.
|
|
10
10
|
*/
|
|
@@ -30,7 +30,7 @@ export type WithSitecoreHocProps<ComponentProps> = EnhancedOmit<ComponentProps,
|
|
|
30
30
|
export declare function withSitecore(options?: WithSitecoreOptions): <ComponentProps extends WithSitecoreProps>(Component: React.ComponentType<ComponentProps>) => (props: WithSitecoreHocProps<ComponentProps>) => React.JSX.Element;
|
|
31
31
|
/**
|
|
32
32
|
* This hook grants acсess to the current Sitecore page context and api.
|
|
33
|
-
* by default
|
|
33
|
+
* by default Content SDK includes the following properties in this context:
|
|
34
34
|
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Sitecore Editor.
|
|
35
35
|
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
|
36
36
|
* - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
|
package/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, } from
|
|
|
6
6
|
export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClientFactoryConfig, GraphQLRequestClient, } from '@sitecore-content-sdk/core/client';
|
|
7
7
|
export { mediaApi } from '@sitecore-content-sdk/core/media';
|
|
8
8
|
export { Form } from './components/Form';
|
|
9
|
-
export {
|
|
9
|
+
export { ReactContentSdkComponent, ComponentMap, ReactModule } from './components/sharedTypes';
|
|
10
10
|
export { Placeholder, PlaceholderComponentProps } from './components/Placeholder';
|
|
11
11
|
export { Image, ImageProps, ImageField, ImageFieldValue, ImageSizeParameters, } from './components/Image';
|
|
12
12
|
export { RichText, RichTextProps, RichTextField } from './components/RichText';
|