@sitecore-jss/sitecore-jss-react 22.5.0-beta.5 → 22.5.0-beta.7
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,16 +8,29 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
9
9
|
const withSitecoreContext_1 = require("../enhancers/withSitecoreContext");
|
|
10
10
|
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
11
|
+
const editing_2 = require("@sitecore-jss/sitecore-jss/editing");
|
|
11
12
|
/**
|
|
12
|
-
* Renders client scripts and data for editing/preview mode
|
|
13
|
-
*
|
|
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
|
+
* This script is only rendered when EditMode is Metadata or RenderingType is `component`, otherwise it renders nothing.
|
|
16
|
+
* @param {EditingScriptsProps} props - The props for the EditingScripts component.
|
|
17
|
+
* @param {string} props.sitecoreEdgeUrl - Sitecore Edge Platform URL.
|
|
18
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
14
19
|
*/
|
|
15
|
-
const EditingScripts = () => {
|
|
16
|
-
const { sitecoreContext: { pageState, editMode, clientData, clientScripts }, } = (0, withSitecoreContext_1.useSitecoreContext)();
|
|
17
|
-
// Don't render anything if not in editing/preview mode
|
|
18
|
-
if (
|
|
20
|
+
const EditingScripts = (props) => {
|
|
21
|
+
const { sitecoreContext: { pageState, editMode, clientData, clientScripts, renderingType }, } = (0, withSitecoreContext_1.useSitecoreContext)();
|
|
22
|
+
// Don't render anything if not in editing/preview mode and rendering type is not component
|
|
23
|
+
if (renderingType !== layout_1.RenderingType.Component &&
|
|
24
|
+
(pageState === layout_1.LayoutServicePageState.Normal || pageState === layout_1.LayoutServicePageState.Preview)) {
|
|
19
25
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
20
26
|
}
|
|
27
|
+
// In case of RenderingType.Component - render only the script for Design Libnrary
|
|
28
|
+
if (renderingType === layout_1.RenderingType.Component) {
|
|
29
|
+
// Add cache buster to the script URL
|
|
30
|
+
const scriptUrl = `${(0, editing_2.getDesignLibraryScriptLink)(props.sitecoreEdgeUrl)}?cb=${Date.now()}`;
|
|
31
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
32
|
+
react_1.default.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
33
|
+
}
|
|
21
34
|
if (editMode === layout_1.EditMode.Metadata) {
|
|
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 :
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.withDatasourceCheck = exports.DefaultEditingError = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
8
9
|
const withSitecoreContext_1 = require("./withSitecoreContext");
|
|
9
10
|
const DefaultEditingError = () => (react_1.default.createElement("div", { className: "sc-jss-editing-error", role: "alert" }, "Datasource is required. Please choose a content item for this component."));
|
|
10
11
|
exports.DefaultEditingError = DefaultEditingError;
|
|
@@ -21,7 +22,9 @@ function withDatasourceCheck(options) {
|
|
|
21
22
|
var _a, _b;
|
|
22
23
|
const { sitecoreContext } = (0, withSitecoreContext_1.useSitecoreContext)();
|
|
23
24
|
const EditingError = (_a = options === null || options === void 0 ? void 0 : options.editingErrorComponent) !== null && _a !== void 0 ? _a : exports.DefaultEditingError;
|
|
24
|
-
|
|
25
|
+
// If the component is rendered in DesignLibrary, we don't need to check for datasource
|
|
26
|
+
const isDesignLibrary = (sitecoreContext === null || sitecoreContext === void 0 ? void 0 : sitecoreContext.renderingType) === layout_1.RenderingType.Component;
|
|
27
|
+
return isDesignLibrary || ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (react_1.default.createElement(Component, Object.assign({}, props))) : sitecoreContext.pageEditing ? (react_1.default.createElement(EditingError, null)) : null;
|
|
25
28
|
};
|
|
26
29
|
};
|
|
27
30
|
}
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { EditMode, LayoutServicePageState } from '@sitecore-jss/sitecore-jss/layout';
|
|
2
|
+
import { EditMode, LayoutServicePageState, RenderingType } from '@sitecore-jss/sitecore-jss/layout';
|
|
3
3
|
import { useSitecoreContext } from '../enhancers/withSitecoreContext';
|
|
4
4
|
import { getJssPagesClientData } from '@sitecore-jss/sitecore-jss/editing';
|
|
5
|
+
import { getDesignLibraryScriptLink } from '@sitecore-jss/sitecore-jss/editing';
|
|
5
6
|
/**
|
|
6
|
-
* Renders client scripts and data for editing/preview mode
|
|
7
|
-
*
|
|
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
|
+
* This script is only rendered when EditMode is Metadata or RenderingType is `component`, otherwise it renders nothing.
|
|
10
|
+
* @param {EditingScriptsProps} props - The props for the EditingScripts component.
|
|
11
|
+
* @param {string} props.sitecoreEdgeUrl - Sitecore Edge Platform URL.
|
|
12
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
8
13
|
*/
|
|
9
|
-
export const EditingScripts = () => {
|
|
10
|
-
const { sitecoreContext: { pageState, editMode, clientData, clientScripts }, } = useSitecoreContext();
|
|
11
|
-
// Don't render anything if not in editing/preview mode
|
|
12
|
-
if (
|
|
14
|
+
export const EditingScripts = (props) => {
|
|
15
|
+
const { sitecoreContext: { pageState, editMode, clientData, clientScripts, renderingType }, } = useSitecoreContext();
|
|
16
|
+
// Don't render anything if not in editing/preview mode and rendering type is not component
|
|
17
|
+
if (renderingType !== RenderingType.Component &&
|
|
18
|
+
(pageState === LayoutServicePageState.Normal || pageState === LayoutServicePageState.Preview)) {
|
|
13
19
|
return React.createElement(React.Fragment, null);
|
|
14
20
|
}
|
|
21
|
+
// In case of RenderingType.Component - render only the script for Design Libnrary
|
|
22
|
+
if (renderingType === RenderingType.Component) {
|
|
23
|
+
// Add cache buster to the script URL
|
|
24
|
+
const scriptUrl = `${getDesignLibraryScriptLink(props.sitecoreEdgeUrl)}?cb=${Date.now()}`;
|
|
25
|
+
return (React.createElement(React.Fragment, null,
|
|
26
|
+
React.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
27
|
+
}
|
|
15
28
|
if (editMode === EditMode.Metadata) {
|
|
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 :
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { RenderingType } from '@sitecore-jss/sitecore-jss/layout';
|
|
2
3
|
import { useSitecoreContext } from './withSitecoreContext';
|
|
3
4
|
export const DefaultEditingError = () => (React.createElement("div", { className: "sc-jss-editing-error", role: "alert" }, "Datasource is required. Please choose a content item for this component."));
|
|
4
5
|
/**
|
|
@@ -14,7 +15,9 @@ export function withDatasourceCheck(options) {
|
|
|
14
15
|
var _a, _b;
|
|
15
16
|
const { sitecoreContext } = useSitecoreContext();
|
|
16
17
|
const EditingError = (_a = options === null || options === void 0 ? void 0 : options.editingErrorComponent) !== null && _a !== void 0 ? _a : DefaultEditingError;
|
|
17
|
-
|
|
18
|
+
// If the component is rendered in DesignLibrary, we don't need to check for datasource
|
|
19
|
+
const isDesignLibrary = (sitecoreContext === null || sitecoreContext === void 0 ? void 0 : sitecoreContext.renderingType) === RenderingType.Component;
|
|
20
|
+
return isDesignLibrary || ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (React.createElement(Component, Object.assign({}, props))) : sitecoreContext.pageEditing ? (React.createElement(EditingError, null)) : null;
|
|
18
21
|
};
|
|
19
22
|
};
|
|
20
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-react",
|
|
3
|
-
"version": "22.5.0-beta.
|
|
3
|
+
"version": "22.5.0-beta.7",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -61,14 +61,14 @@
|
|
|
61
61
|
"react-dom": "^18.2.0"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@sitecore-jss/sitecore-jss": "22.5.0-beta.
|
|
64
|
+
"@sitecore-jss/sitecore-jss": "22.5.0-beta.7",
|
|
65
65
|
"fast-deep-equal": "^3.1.3",
|
|
66
66
|
"prop-types": "^15.8.1",
|
|
67
67
|
"style-attr": "^1.3.0"
|
|
68
68
|
},
|
|
69
69
|
"description": "",
|
|
70
70
|
"types": "types/index.d.ts",
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "9d505ba46b5dbd08852c69509a61c6e720daa12b",
|
|
72
72
|
"files": [
|
|
73
73
|
"dist",
|
|
74
74
|
"types"
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* This script is only rendered when EditMode is Metadata, otherwise it renders nothing.
|
|
2
|
+
* Props for the EditingScripts component.
|
|
4
3
|
*/
|
|
5
|
-
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
|
+
* This script is only rendered when EditMode is Metadata or RenderingType is `component`, otherwise it renders nothing.
|
|
14
|
+
* @param {EditingScriptsProps} props - The props for the EditingScripts component.
|
|
15
|
+
* @param {string} props.sitecoreEdgeUrl - Sitecore Edge Platform URL.
|
|
16
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
17
|
+
*/
|
|
18
|
+
export declare const EditingScripts: (props: EditingScriptsProps) => JSX.Element;
|