@sitecore-content-sdk/react 0.3.0-canary.2 → 0.3.0-canary.21

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.
@@ -12,12 +12,11 @@ const editing_2 = require("@sitecore-content-sdk/core/editing");
12
12
  /**
13
13
  * Renders client scripts and data for editing/preview mode for Pages.
14
14
  * Renders script required for the Design Library (when RenderingType is `component`).
15
- * @param {EditingScriptsProps} props - The props for the EditingScripts component.
16
- * @param {string} props.sitecoreEdgeUrl - Sitecore Edge Platform URL.
17
15
  * @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
18
16
  */
19
- const EditingScripts = (props) => {
20
- const { pageContext: { pageState, clientData, clientScripts, renderingType }, } = (0, withSitecore_1.useSitecore)();
17
+ const EditingScripts = () => {
18
+ var _a;
19
+ const { pageContext: { pageState, clientData, clientScripts, renderingType }, api, } = (0, withSitecore_1.useSitecore)();
21
20
  // Don't render anything if not in editing/preview mode and rendering type is not component
22
21
  if (renderingType !== layout_1.RenderingType.Component &&
23
22
  (pageState === layout_1.LayoutServicePageState.Normal ||
@@ -28,7 +27,7 @@ const EditingScripts = (props) => {
28
27
  // In case of RenderingType.Component - render only the script for Design Libnrary
29
28
  if (renderingType === layout_1.RenderingType.Component) {
30
29
  // Add cache buster to the script URL
31
- const scriptUrl = `${(0, editing_2.getDesignLibraryScriptLink)(props.sitecoreEdgeUrl)}?cb=${Date.now()}`;
30
+ const scriptUrl = `${(0, editing_2.getDesignLibraryScriptLink)((_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl)}?cb=${Date.now()}`;
32
31
  return (react_1.default.createElement(react_1.default.Fragment, null,
33
32
  react_1.default.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
34
33
  }
@@ -85,8 +85,8 @@ class ErrorBoundary extends react_1.default.Component {
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));
@@ -74,8 +74,9 @@ class PlaceholderCommon extends react_1.default.Component {
74
74
  getSXAParams(rendering) {
75
75
  if (!rendering.params)
76
76
  return {};
77
- return (rendering.params.FieldNames && {
78
- styles: `${rendering.params.GridParameters || ''} ${rendering.params.Styles || ''}`,
77
+ const { GridParameters, Styles } = rendering.params;
78
+ return ((GridParameters || Styles) && {
79
+ styles: `${GridParameters || ''} ${Styles || ''}`,
79
80
  });
80
81
  }
81
82
  getComponentsForRenderingData(placeholderData) {
@@ -131,9 +132,13 @@ class PlaceholderCommon extends react_1.default.Component {
131
132
  if (!isEmpty) {
132
133
  // assign type based on passed element - type='text/sitecore' should be ignored when renderEach Placeholder prop function is being used
133
134
  const type = rendered.props.type === 'text/sitecore' ? rendered.props.type : '';
135
+ const disableSuspense = this.props.disableSuspense || false;
134
136
  // wrapping with error boundary could cause problems in case where parent component uses withPlaceholder HOC and tries to access its children props
135
137
  // that's why we need to expose element's props here
136
- rendered = (react_1.default.createElement(ErrorBoundary_1.default, Object.assign({ key: rendered.type + '-' + index, errorComponent: this.props.errorComponent, componentLoadingMessage: this.props.componentLoadingMessage, type: type, isDynamic: ((_a = component.render) === null || _a === void 0 ? void 0 : _a.preload) ? true : false }, rendered.props), rendered));
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));
137
142
  }
138
143
  // if in edit mode then emit shallow chromes for hydration in Pages
139
144
  if ((_b = this.props.pageContext) === null || _b === void 0 ? void 0 : _b.pageEditing) {
@@ -6,12 +6,11 @@ import { getDesignLibraryScriptLink } from '@sitecore-content-sdk/core/editing';
6
6
  /**
7
7
  * Renders client scripts and data for editing/preview mode for Pages.
8
8
  * Renders script required for the Design Library (when RenderingType is `component`).
9
- * @param {EditingScriptsProps} props - The props for the EditingScripts component.
10
- * @param {string} props.sitecoreEdgeUrl - Sitecore Edge Platform URL.
11
9
  * @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
12
10
  */
13
- export const EditingScripts = (props) => {
14
- const { pageContext: { pageState, clientData, clientScripts, renderingType }, } = useSitecore();
11
+ export const EditingScripts = () => {
12
+ var _a;
13
+ const { pageContext: { pageState, clientData, clientScripts, renderingType }, api, } = useSitecore();
15
14
  // Don't render anything if not in editing/preview mode and rendering type is not component
16
15
  if (renderingType !== RenderingType.Component &&
17
16
  (pageState === LayoutServicePageState.Normal ||
@@ -22,7 +21,7 @@ export const EditingScripts = (props) => {
22
21
  // In case of RenderingType.Component - render only the script for Design Libnrary
23
22
  if (renderingType === RenderingType.Component) {
24
23
  // Add cache buster to the script URL
25
- const scriptUrl = `${getDesignLibraryScriptLink(props.sitecoreEdgeUrl)}?cb=${Date.now()}`;
24
+ const scriptUrl = `${getDesignLibraryScriptLink((_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl)}?cb=${Date.now()}`;
26
25
  return (React.createElement(React.Fragment, null,
27
26
  React.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
28
27
  }
@@ -50,8 +50,8 @@ class ErrorBoundary extends React.Component {
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));
@@ -68,8 +68,9 @@ export class PlaceholderCommon extends React.Component {
68
68
  getSXAParams(rendering) {
69
69
  if (!rendering.params)
70
70
  return {};
71
- return (rendering.params.FieldNames && {
72
- styles: `${rendering.params.GridParameters || ''} ${rendering.params.Styles || ''}`,
71
+ const { GridParameters, Styles } = rendering.params;
72
+ return ((GridParameters || Styles) && {
73
+ styles: `${GridParameters || ''} ${Styles || ''}`,
73
74
  });
74
75
  }
75
76
  getComponentsForRenderingData(placeholderData) {
@@ -125,9 +126,13 @@ export class PlaceholderCommon extends React.Component {
125
126
  if (!isEmpty) {
126
127
  // assign type based on passed element - type='text/sitecore' should be ignored when renderEach Placeholder prop function is being used
127
128
  const type = rendered.props.type === 'text/sitecore' ? rendered.props.type : '';
129
+ const disableSuspense = this.props.disableSuspense || false;
128
130
  // wrapping with error boundary could cause problems in case where parent component uses withPlaceholder HOC and tries to access its children props
129
131
  // that's why we need to expose element's props here
130
- rendered = (React.createElement(ErrorBoundary, Object.assign({ key: rendered.type + '-' + index, errorComponent: this.props.errorComponent, componentLoadingMessage: this.props.componentLoadingMessage, type: type, isDynamic: ((_a = component.render) === null || _a === void 0 ? void 0 : _a.preload) ? true : false }, rendered.props), rendered));
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));
131
136
  }
132
137
  // if in edit mode then emit shallow chromes for hydration in Pages
133
138
  if ((_b = this.props.pageContext) === null || _b === void 0 ? void 0 : _b.pageEditing) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/react",
3
- "version": "0.3.0-canary.2",
3
+ "version": "0.3.0-canary.21",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -63,12 +63,12 @@
63
63
  "react-dom": "^19.1.0"
64
64
  },
65
65
  "dependencies": {
66
- "@sitecore-content-sdk/core": "0.3.0-canary.2",
66
+ "@sitecore-content-sdk/core": "0.3.0-canary.21",
67
67
  "fast-deep-equal": "^3.1.3"
68
68
  },
69
69
  "description": "",
70
70
  "types": "types/index.d.ts",
71
- "gitHead": "8243c78fad6aa9456ac8cb726ac0a90c72589506",
71
+ "gitHead": "c793864ef8bbfec2c08aaf4959a169a7519401ce",
72
72
  "files": [
73
73
  "dist",
74
74
  "types"
@@ -1,18 +1,7 @@
1
1
  import { JSX } from 'react';
2
- /**
3
- * Props for the EditingScripts component.
4
- */
5
- export type EditingScriptsProps = {
6
- /**
7
- * Sitecore Edge Platform URL.
8
- */
9
- sitecoreEdgeUrl?: string;
10
- };
11
2
  /**
12
3
  * Renders client scripts and data for editing/preview mode for Pages.
13
4
  * Renders script required for the Design Library (when RenderingType is `component`).
14
- * @param {EditingScriptsProps} props - The props for the EditingScripts component.
15
- * @param {string} props.sitecoreEdgeUrl - Sitecore Edge Platform URL.
16
5
  * @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
17
6
  */
18
- export declare const EditingScripts: (props: EditingScriptsProps) => JSX.Element;
7
+ export declare const EditingScripts: () => JSX.Element;
@@ -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<{