@sitecore-content-sdk/react 0.1.0-beta.35 → 0.1.0-beta.36
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.
|
@@ -8,17 +8,30 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const layout_1 = require("@sitecore-content-sdk/core/layout");
|
|
9
9
|
const withSitecoreContext_1 = require("../enhancers/withSitecoreContext");
|
|
10
10
|
const editing_1 = require("@sitecore-content-sdk/core/editing");
|
|
11
|
+
const editing_2 = require("@sitecore-content-sdk/core/editing");
|
|
11
12
|
/**
|
|
12
|
-
* Renders client scripts and data for editing/preview mode
|
|
13
|
+
* Renders client scripts and data for editing/preview mode for Pages.
|
|
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
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
13
18
|
*/
|
|
14
|
-
const EditingScripts = () => {
|
|
15
|
-
const { sitecoreContext: { pageState, clientData, clientScripts }, } = (0, withSitecoreContext_1.useSitecoreContext)();
|
|
16
|
-
// Don't render anything if not in editing/preview mode
|
|
17
|
-
if (
|
|
18
|
-
pageState === layout_1.LayoutServicePageState.
|
|
19
|
-
|
|
19
|
+
const EditingScripts = (props) => {
|
|
20
|
+
const { sitecoreContext: { pageState, clientData, clientScripts, renderingType }, } = (0, withSitecoreContext_1.useSitecoreContext)();
|
|
21
|
+
// Don't render anything if not in editing/preview mode and rendering type is not component
|
|
22
|
+
if (renderingType !== layout_1.RenderingType.Component &&
|
|
23
|
+
(pageState === layout_1.LayoutServicePageState.Normal ||
|
|
24
|
+
pageState === layout_1.LayoutServicePageState.Preview ||
|
|
25
|
+
!pageState)) {
|
|
20
26
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
21
27
|
}
|
|
28
|
+
// In case of RenderingType.Component - render only the script for Design Libnrary
|
|
29
|
+
if (renderingType === layout_1.RenderingType.Component) {
|
|
30
|
+
// Add cache buster to the script URL
|
|
31
|
+
const scriptUrl = `${(0, editing_2.getDesignLibraryScriptLink)(props.sitecoreEdgeUrl)}?cb=${Date.now()}`;
|
|
32
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
33
|
+
react_1.default.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
34
|
+
}
|
|
22
35
|
const jssClientData = Object.assign(Object.assign({}, clientData), (0, editing_1.getJssPagesClientData)());
|
|
23
36
|
return (react_1.default.createElement(react_1.default.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
24
37
|
clientScripts.map((src, index) => (react_1.default.createElement("script", { src: src, key: index }))),
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { LayoutServicePageState } from '@sitecore-content-sdk/core/layout';
|
|
2
|
+
import { LayoutServicePageState, RenderingType } from '@sitecore-content-sdk/core/layout';
|
|
3
3
|
import { useSitecoreContext } from '../enhancers/withSitecoreContext';
|
|
4
4
|
import { getJssPagesClientData } from '@sitecore-content-sdk/core/editing';
|
|
5
|
+
import { getDesignLibraryScriptLink } from '@sitecore-content-sdk/core/editing';
|
|
5
6
|
/**
|
|
6
|
-
* Renders client scripts and data for editing/preview mode
|
|
7
|
+
* Renders client scripts and data for editing/preview mode for Pages.
|
|
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
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
7
12
|
*/
|
|
8
|
-
export const EditingScripts = () => {
|
|
9
|
-
const { sitecoreContext: { pageState, clientData, clientScripts }, } = useSitecoreContext();
|
|
10
|
-
// Don't render anything if not in editing/preview mode
|
|
11
|
-
if (
|
|
12
|
-
pageState === LayoutServicePageState.
|
|
13
|
-
|
|
13
|
+
export const EditingScripts = (props) => {
|
|
14
|
+
const { sitecoreContext: { pageState, clientData, clientScripts, renderingType }, } = useSitecoreContext();
|
|
15
|
+
// Don't render anything if not in editing/preview mode and rendering type is not component
|
|
16
|
+
if (renderingType !== RenderingType.Component &&
|
|
17
|
+
(pageState === LayoutServicePageState.Normal ||
|
|
18
|
+
pageState === LayoutServicePageState.Preview ||
|
|
19
|
+
!pageState)) {
|
|
14
20
|
return React.createElement(React.Fragment, null);
|
|
15
21
|
}
|
|
22
|
+
// In case of RenderingType.Component - render only the script for Design Libnrary
|
|
23
|
+
if (renderingType === RenderingType.Component) {
|
|
24
|
+
// Add cache buster to the script URL
|
|
25
|
+
const scriptUrl = `${getDesignLibraryScriptLink(props.sitecoreEdgeUrl)}?cb=${Date.now()}`;
|
|
26
|
+
return (React.createElement(React.Fragment, null,
|
|
27
|
+
React.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
28
|
+
}
|
|
16
29
|
const jssClientData = Object.assign(Object.assign({}, clientData), getJssPagesClientData());
|
|
17
30
|
return (React.createElement(React.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
18
31
|
clientScripts.map((src, index) => (React.createElement("script", { src: src, key: index }))),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/react",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.36",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
"react-dom": "^18.2.0"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@sitecore-content-sdk/core": "0.1.0-beta.
|
|
70
|
+
"@sitecore-content-sdk/core": "0.1.0-beta.36",
|
|
71
71
|
"fast-deep-equal": "^3.1.3",
|
|
72
72
|
"prop-types": "^15.8.1"
|
|
73
73
|
},
|
|
74
74
|
"description": "",
|
|
75
75
|
"types": "types/index.d.ts",
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "1a28b6590a0f8ef4d9e897f057f47abb01976998",
|
|
77
77
|
"files": [
|
|
78
78
|
"dist",
|
|
79
79
|
"types"
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Props for the EditingScripts component.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type EditingScriptsProps = {
|
|
5
|
+
/**
|
|
6
|
+
* Sitecore Edge Platform URL.
|
|
7
|
+
*/
|
|
8
|
+
sitecoreEdgeUrl?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Renders client scripts and data for editing/preview mode for Pages.
|
|
12
|
+
* Renders script required for the Design Library (when RenderingType is `component`).
|
|
13
|
+
* @param {EditingScriptsProps} props - The props for the EditingScripts component.
|
|
14
|
+
* @param {string} props.sitecoreEdgeUrl - Sitecore Edge Platform URL.
|
|
15
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
16
|
+
*/
|
|
17
|
+
export declare const EditingScripts: (props: EditingScriptsProps) => JSX.Element;
|