@sitecore-jss/sitecore-jss-react 22.5.0-beta.1 → 22.5.0-beta.10
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/dist/cjs/components/{ComponentLibraryLayout.js → DesignLibrary.js} +10 -7
- package/dist/cjs/components/EditingScripts.js +17 -5
- package/dist/cjs/components/SitecoreContext.js +7 -0
- package/dist/cjs/enhancers/withDatasourceCheck.js +4 -1
- package/dist/cjs/enhancers/withSitecoreContext.js +2 -1
- package/dist/cjs/index.js +4 -4
- package/dist/esm/components/{ComponentLibraryLayout.js → DesignLibrary.js} +10 -7
- package/dist/esm/components/EditingScripts.js +18 -6
- package/dist/esm/components/SitecoreContext.js +7 -0
- package/dist/esm/enhancers/withDatasourceCheck.js +4 -1
- package/dist/esm/enhancers/withSitecoreContext.js +3 -2
- package/dist/esm/index.js +2 -2
- package/package.json +3 -3
- package/types/components/DesignLibrary.d.ts +2 -0
- package/types/components/EditingScripts.d.ts +4 -2
- package/types/components/SitecoreContext.d.ts +20 -0
- package/types/enhancers/withSitecoreContext.d.ts +3 -5
- package/types/index.d.ts +2 -2
- package/types/components/ComponentLibraryLayout.d.ts +0 -2
|
@@ -23,14 +23,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.DesignLibrary = void 0;
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
28
|
const Placeholder_1 = require("./Placeholder");
|
|
29
29
|
const layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
30
30
|
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
31
|
-
|
|
32
|
-
const
|
|
31
|
+
9;
|
|
32
|
+
const DesignLibrary = (layoutData) => {
|
|
33
33
|
const { route } = layoutData.sitecore;
|
|
34
|
+
const isDesignLibrary = layoutData.sitecore.context.renderingType === layout_1.RenderingType.Component;
|
|
35
|
+
if (!isDesignLibrary) {
|
|
36
|
+
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
37
|
+
}
|
|
34
38
|
const [renderKey, setRenderKey] = (0, react_1.useState)(0);
|
|
35
39
|
const [rootUpdate, setRootUpdate] = (0, react_1.useState)(null);
|
|
36
40
|
const rootComponent = route === null || route === void 0 ? void 0 : route.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER][0];
|
|
@@ -46,7 +50,7 @@ const ComponentLibraryLayout = (layoutData) => {
|
|
|
46
50
|
// useEffect will fire when components are ready - and we inform the whole wide world of it too
|
|
47
51
|
if (!componentReady) {
|
|
48
52
|
componentReady = true;
|
|
49
|
-
window.top.postMessage((0, editing_1.
|
|
53
|
+
window.top.postMessage((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.READY, rootComponent.uid), '*');
|
|
50
54
|
}
|
|
51
55
|
const unsubscribe = (0, editing_1.addComponentUpdateHandler)(persistedRoot, (updatedRoot) => {
|
|
52
56
|
setRootUpdate(Object.assign({}, updatedRoot));
|
|
@@ -60,11 +64,10 @@ const ComponentLibraryLayout = (layoutData) => {
|
|
|
60
64
|
if (renderKey === 0) {
|
|
61
65
|
return;
|
|
62
66
|
}
|
|
63
|
-
window.top.postMessage((0, editing_1.
|
|
67
|
+
window.top.postMessage((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.RENDERED, rootComponent.uid), '*');
|
|
64
68
|
}, [renderKey, rootComponent.uid]);
|
|
65
69
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
66
|
-
react_1.default.createElement(EditingScripts_1.EditingScripts, null),
|
|
67
70
|
react_1.default.createElement("main", null,
|
|
68
71
|
react_1.default.createElement("div", { id: layout_1.EDITING_COMPONENT_ID }, route && (react_1.default.createElement(Placeholder_1.Placeholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
|
|
69
72
|
};
|
|
70
|
-
exports.
|
|
73
|
+
exports.DesignLibrary = DesignLibrary;
|
|
@@ -8,16 +8,28 @@ 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
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
14
17
|
*/
|
|
15
18
|
const EditingScripts = () => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if
|
|
19
|
+
var _a;
|
|
20
|
+
const { sitecoreContext: { pageState, editMode, clientData, clientScripts, renderingType }, api, } = (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 || pageState === layout_1.LayoutServicePageState.Preview)) {
|
|
19
24
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
20
25
|
}
|
|
26
|
+
// In case of RenderingType.Component - render only the script for Design Libnrary
|
|
27
|
+
if (renderingType === layout_1.RenderingType.Component) {
|
|
28
|
+
// Add cache buster to the script URL
|
|
29
|
+
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()}`;
|
|
30
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
31
|
+
react_1.default.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
32
|
+
}
|
|
21
33
|
if (editMode === layout_1.EditMode.Metadata) {
|
|
22
34
|
const jssClientData = Object.assign(Object.assign({}, clientData), (0, editing_1.getJssPagesClientData)());
|
|
23
35
|
return (react_1.default.createElement(react_1.default.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
@@ -8,10 +8,12 @@ exports.SitecoreContext = exports.ComponentFactoryReactContext = exports.Sitecor
|
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
9
|
const prop_types_1 = __importDefault(require("prop-types"));
|
|
10
10
|
const react_2 = __importDefault(require("fast-deep-equal/es6/react"));
|
|
11
|
+
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
11
12
|
exports.SitecoreContextReactContext = react_1.default.createContext({});
|
|
12
13
|
exports.ComponentFactoryReactContext = react_1.default.createContext({});
|
|
13
14
|
class SitecoreContext extends react_1.default.Component {
|
|
14
15
|
constructor(props) {
|
|
16
|
+
var _a, _b, _c, _d;
|
|
15
17
|
super(props);
|
|
16
18
|
/**
|
|
17
19
|
* Update context state. Value can be @type {LayoutServiceData} which will be automatically transformed
|
|
@@ -26,9 +28,14 @@ class SitecoreContext extends react_1.default.Component {
|
|
|
26
28
|
});
|
|
27
29
|
};
|
|
28
30
|
const context = this.constructContext(props.layoutData);
|
|
31
|
+
let api = props.api;
|
|
32
|
+
if (((_b = (_a = props.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId) && !((_d = (_c = props.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl)) {
|
|
33
|
+
api = Object.assign(Object.assign({}, props.api), { edge: Object.assign(Object.assign({}, props.api.edge), { edgeUrl: sitecore_jss_1.constants.SITECORE_EDGE_URL_DEFAULT }) });
|
|
34
|
+
}
|
|
29
35
|
this.state = {
|
|
30
36
|
context,
|
|
31
37
|
setContext: this.setContext,
|
|
38
|
+
api,
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
41
|
constructContext(layoutData) {
|
|
@@ -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
|
}
|
|
@@ -12,7 +12,7 @@ const SitecoreContext_1 = require("../components/SitecoreContext");
|
|
|
12
12
|
function withSitecoreContext(options) {
|
|
13
13
|
return function withSitecoreContextHoc(Component) {
|
|
14
14
|
return function WithSitecoreContext(props) {
|
|
15
|
-
return (react_1.default.createElement(SitecoreContext_1.SitecoreContextReactContext.Consumer, null, (context) => (react_1.default.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, updateSitecoreContext: options && options.updatable && context.setContext })))));
|
|
15
|
+
return (react_1.default.createElement(SitecoreContext_1.SitecoreContextReactContext.Consumer, null, (context) => (react_1.default.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, api: context.api, updateSitecoreContext: options && options.updatable && context.setContext })))));
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
}
|
|
@@ -42,6 +42,7 @@ function useSitecoreContext(options) {
|
|
|
42
42
|
const reactContext = react_1.default.useContext(SitecoreContext_1.SitecoreContextReactContext);
|
|
43
43
|
const updatable = options === null || options === void 0 ? void 0 : options.updatable;
|
|
44
44
|
return {
|
|
45
|
+
api: reactContext.api,
|
|
45
46
|
sitecoreContext: reactContext.context,
|
|
46
47
|
updateSitecoreContext: updatable ? reactContext.setContext : undefined,
|
|
47
48
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComponentBuilder = exports.EditFrame = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.LinkPropTypes = exports.Link = exports.BYOCWrapper = exports.fetchBYOCComponentServerProps = exports.BYOCComponent = exports.
|
|
3
|
+
exports.ComponentBuilder = exports.EditFrame = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.LinkPropTypes = exports.Link = exports.BYOCWrapper = exports.fetchBYOCComponentServerProps = exports.BYOCComponent = exports.DesignLibrary = exports.FEaaSWrapper = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.DateField = exports.Text = exports.RichTextPropTypes = exports.RichText = exports.getEEMarkup = exports.Image = exports.Placeholder = exports.mediaApi = exports.GraphQLRequestClient = exports.DefaultRetryStrategy = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.EditMode = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.getDesignLibraryStylesheetLinks = exports.getContentStylesheetLink = exports.DefaultEditFrameButtons = exports.DefaultEditFrameButton = exports.resetEditorChromes = exports.isEditorActive = exports.NativeDataFetcher = exports.MemoryCacheClient = exports.ClientError = exports.enableDebug = exports.constants = void 0;
|
|
4
4
|
exports.DefaultEmptyFieldEditingComponentImage = exports.DefaultEmptyFieldEditingComponentText = exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = void 0;
|
|
5
5
|
var sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
6
6
|
Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return sitecore_jss_1.constants; } });
|
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "DefaultEditFrameButton", { enumerable: true, get
|
|
|
15
15
|
Object.defineProperty(exports, "DefaultEditFrameButtons", { enumerable: true, get: function () { return editing_1.DefaultEditFrameButtons; } });
|
|
16
16
|
var layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
17
17
|
Object.defineProperty(exports, "getContentStylesheetLink", { enumerable: true, get: function () { return layout_1.getContentStylesheetLink; } });
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "getDesignLibraryStylesheetLinks", { enumerable: true, get: function () { return layout_1.getDesignLibraryStylesheetLinks; } });
|
|
19
19
|
Object.defineProperty(exports, "LayoutServicePageState", { enumerable: true, get: function () { return layout_1.LayoutServicePageState; } });
|
|
20
20
|
Object.defineProperty(exports, "GraphQLLayoutService", { enumerable: true, get: function () { return layout_1.GraphQLLayoutService; } });
|
|
21
21
|
Object.defineProperty(exports, "RestLayoutService", { enumerable: true, get: function () { return layout_1.RestLayoutService; } });
|
|
@@ -49,8 +49,8 @@ Object.defineProperty(exports, "FEaaSComponent", { enumerable: true, get: functi
|
|
|
49
49
|
Object.defineProperty(exports, "fetchFEaaSComponentServerProps", { enumerable: true, get: function () { return FEaaSComponent_1.fetchFEaaSComponentServerProps; } });
|
|
50
50
|
var FEaaSWrapper_1 = require("./components/FEaaSWrapper");
|
|
51
51
|
Object.defineProperty(exports, "FEaaSWrapper", { enumerable: true, get: function () { return FEaaSWrapper_1.FEaaSWrapper; } });
|
|
52
|
-
var
|
|
53
|
-
Object.defineProperty(exports, "
|
|
52
|
+
var DesignLibrary_1 = require("./components/DesignLibrary");
|
|
53
|
+
Object.defineProperty(exports, "DesignLibrary", { enumerable: true, get: function () { return DesignLibrary_1.DesignLibrary; } });
|
|
54
54
|
var BYOCComponent_1 = require("./components/BYOCComponent");
|
|
55
55
|
Object.defineProperty(exports, "BYOCComponent", { enumerable: true, get: function () { return BYOCComponent_1.BYOCComponent; } });
|
|
56
56
|
Object.defineProperty(exports, "fetchBYOCComponentServerProps", { enumerable: true, get: function () { return BYOCComponent_1.fetchBYOCComponentServerProps; } });
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { Placeholder } from './Placeholder';
|
|
3
|
-
import { EDITING_COMPONENT_ID, EDITING_COMPONENT_PLACEHOLDER, } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export const
|
|
3
|
+
import { EDITING_COMPONENT_ID, EDITING_COMPONENT_PLACEHOLDER, RenderingType, } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
|
+
import { DesignLibraryStatus, getDesignLibraryStatusEvent, addComponentUpdateHandler, } from '@sitecore-jss/sitecore-jss/editing';
|
|
5
|
+
9;
|
|
6
|
+
export const DesignLibrary = (layoutData) => {
|
|
7
7
|
const { route } = layoutData.sitecore;
|
|
8
|
+
const isDesignLibrary = layoutData.sitecore.context.renderingType === RenderingType.Component;
|
|
9
|
+
if (!isDesignLibrary) {
|
|
10
|
+
return React.createElement(React.Fragment, null);
|
|
11
|
+
}
|
|
8
12
|
const [renderKey, setRenderKey] = useState(0);
|
|
9
13
|
const [rootUpdate, setRootUpdate] = useState(null);
|
|
10
14
|
const rootComponent = route === null || route === void 0 ? void 0 : route.placeholders[EDITING_COMPONENT_PLACEHOLDER][0];
|
|
@@ -20,7 +24,7 @@ export const ComponentLibraryLayout = (layoutData) => {
|
|
|
20
24
|
// useEffect will fire when components are ready - and we inform the whole wide world of it too
|
|
21
25
|
if (!componentReady) {
|
|
22
26
|
componentReady = true;
|
|
23
|
-
window.top.postMessage(
|
|
27
|
+
window.top.postMessage(getDesignLibraryStatusEvent(DesignLibraryStatus.READY, rootComponent.uid), '*');
|
|
24
28
|
}
|
|
25
29
|
const unsubscribe = addComponentUpdateHandler(persistedRoot, (updatedRoot) => {
|
|
26
30
|
setRootUpdate(Object.assign({}, updatedRoot));
|
|
@@ -34,10 +38,9 @@ export const ComponentLibraryLayout = (layoutData) => {
|
|
|
34
38
|
if (renderKey === 0) {
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
|
-
window.top.postMessage(
|
|
41
|
+
window.top.postMessage(getDesignLibraryStatusEvent(DesignLibraryStatus.RENDERED, rootComponent.uid), '*');
|
|
38
42
|
}, [renderKey, rootComponent.uid]);
|
|
39
43
|
return (React.createElement(React.Fragment, null,
|
|
40
|
-
React.createElement(EditingScripts, null),
|
|
41
44
|
React.createElement("main", null,
|
|
42
45
|
React.createElement("div", { id: EDITING_COMPONENT_ID }, route && (React.createElement(Placeholder, { name: EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
|
|
43
46
|
};
|
|
@@ -1,17 +1,29 @@
|
|
|
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
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
8
11
|
*/
|
|
9
12
|
export const EditingScripts = () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if
|
|
13
|
+
var _a;
|
|
14
|
+
const { sitecoreContext: { pageState, editMode, clientData, clientScripts, renderingType }, api, } = 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 || pageState === LayoutServicePageState.Preview)) {
|
|
13
18
|
return React.createElement(React.Fragment, null);
|
|
14
19
|
}
|
|
20
|
+
// In case of RenderingType.Component - render only the script for Design Libnrary
|
|
21
|
+
if (renderingType === RenderingType.Component) {
|
|
22
|
+
// Add cache buster to the script URL
|
|
23
|
+
const scriptUrl = `${getDesignLibraryScriptLink((_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl)}?cb=${Date.now()}`;
|
|
24
|
+
return (React.createElement(React.Fragment, null,
|
|
25
|
+
React.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
26
|
+
}
|
|
15
27
|
if (editMode === EditMode.Metadata) {
|
|
16
28
|
const jssClientData = Object.assign(Object.assign({}, clientData), getJssPagesClientData());
|
|
17
29
|
return (React.createElement(React.Fragment, null, clientScripts === null || clientScripts === void 0 ? void 0 :
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import fastDeepEqual from 'fast-deep-equal/es6/react';
|
|
5
|
+
import { constants } from '@sitecore-jss/sitecore-jss';
|
|
5
6
|
export const SitecoreContextReactContext = React.createContext({});
|
|
6
7
|
export const ComponentFactoryReactContext = React.createContext({});
|
|
7
8
|
export class SitecoreContext extends React.Component {
|
|
8
9
|
constructor(props) {
|
|
10
|
+
var _a, _b, _c, _d;
|
|
9
11
|
super(props);
|
|
10
12
|
/**
|
|
11
13
|
* Update context state. Value can be @type {LayoutServiceData} which will be automatically transformed
|
|
@@ -20,9 +22,14 @@ export class SitecoreContext extends React.Component {
|
|
|
20
22
|
});
|
|
21
23
|
};
|
|
22
24
|
const context = this.constructContext(props.layoutData);
|
|
25
|
+
let api = props.api;
|
|
26
|
+
if (((_b = (_a = props.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId) && !((_d = (_c = props.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl)) {
|
|
27
|
+
api = Object.assign(Object.assign({}, props.api), { edge: Object.assign(Object.assign({}, props.api.edge), { edgeUrl: constants.SITECORE_EDGE_URL_DEFAULT }) });
|
|
28
|
+
}
|
|
23
29
|
this.state = {
|
|
24
30
|
context,
|
|
25
31
|
setContext: this.setContext,
|
|
32
|
+
api,
|
|
26
33
|
};
|
|
27
34
|
}
|
|
28
35
|
constructContext(layoutData) {
|
|
@@ -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
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SitecoreContextReactContext } from '../components/SitecoreContext';
|
|
2
|
+
import { SitecoreContextReactContext, } from '../components/SitecoreContext';
|
|
3
3
|
/**
|
|
4
4
|
* @param {WithSitecoreContextOptions} [options]
|
|
5
5
|
*/
|
|
6
6
|
export function withSitecoreContext(options) {
|
|
7
7
|
return function withSitecoreContextHoc(Component) {
|
|
8
8
|
return function WithSitecoreContext(props) {
|
|
9
|
-
return (React.createElement(SitecoreContextReactContext.Consumer, null, (context) => (React.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, updateSitecoreContext: options && options.updatable && context.setContext })))));
|
|
9
|
+
return (React.createElement(SitecoreContextReactContext.Consumer, null, (context) => (React.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, api: context.api, updateSitecoreContext: options && options.updatable && context.setContext })))));
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
}
|
|
@@ -35,6 +35,7 @@ export function useSitecoreContext(options) {
|
|
|
35
35
|
const reactContext = React.useContext(SitecoreContextReactContext);
|
|
36
36
|
const updatable = options === null || options === void 0 ? void 0 : options.updatable;
|
|
37
37
|
return {
|
|
38
|
+
api: reactContext.api,
|
|
38
39
|
sitecoreContext: reactContext.context,
|
|
39
40
|
updateSitecoreContext: updatable ? reactContext.setContext : undefined,
|
|
40
41
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { constants, enableDebug, ClientError, MemoryCacheClient, NativeDataFetcher, } from '@sitecore-jss/sitecore-jss';
|
|
2
2
|
export { isEditorActive, resetEditorChromes, DefaultEditFrameButton, DefaultEditFrameButtons, } from '@sitecore-jss/sitecore-jss/editing';
|
|
3
|
-
export { getContentStylesheetLink,
|
|
3
|
+
export { getContentStylesheetLink, getDesignLibraryStylesheetLinks, LayoutServicePageState, GraphQLLayoutService, RestLayoutService, getChildPlaceholder, getFieldValue, EditMode, } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
4
|
export { trackingApi, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
5
5
|
export { GraphQLDictionaryService, RestDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
6
6
|
export { DefaultRetryStrategy, GraphQLRequestClient, } from '@sitecore-jss/sitecore-jss/graphql';
|
|
@@ -12,7 +12,7 @@ export { Text } from './components/Text';
|
|
|
12
12
|
export { DateField } from './components/Date';
|
|
13
13
|
export { FEaaSComponent, fetchFEaaSComponentServerProps, } from './components/FEaaSComponent';
|
|
14
14
|
export { FEaaSWrapper } from './components/FEaaSWrapper';
|
|
15
|
-
export {
|
|
15
|
+
export { DesignLibrary } from './components/DesignLibrary';
|
|
16
16
|
export { BYOCComponent, fetchBYOCComponentServerProps, } from './components/BYOCComponent';
|
|
17
17
|
export { BYOCWrapper } from './components/BYOCWrapper';
|
|
18
18
|
export { Link, LinkPropTypes } from './components/Link';
|
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.10",
|
|
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": "
|
|
64
|
+
"@sitecore-jss/sitecore-jss": "22.5.0-beta.10",
|
|
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": "5219803dfd700b1e2967c02e1b17db07f6f31b45",
|
|
72
72
|
"files": [
|
|
73
73
|
"dist",
|
|
74
74
|
"types"
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Renders client scripts and data for editing/preview mode
|
|
3
|
-
*
|
|
2
|
+
* - Renders client scripts and data for editing/preview mode for Pages
|
|
3
|
+
* - Renders script required for the Design Library (when RenderingType is `component`).
|
|
4
|
+
* This script is only rendered when EditMode is Metadata or RenderingType is `component`, otherwise it renders nothing.
|
|
5
|
+
* @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
|
|
4
6
|
*/
|
|
5
7
|
export declare const EditingScripts: () => JSX.Element;
|
|
@@ -6,11 +6,31 @@ import { LayoutServiceContext, LayoutServiceData, RouteData } from '../index';
|
|
|
6
6
|
export interface SitecoreContextProps {
|
|
7
7
|
componentFactory: ComponentFactory;
|
|
8
8
|
layoutData?: LayoutServiceData;
|
|
9
|
+
/**
|
|
10
|
+
* API settings to connect to Sitecore.
|
|
11
|
+
*/
|
|
12
|
+
api?: {
|
|
13
|
+
/**
|
|
14
|
+
* Sitecore XM Cloud Edge endpoint credentials for Sitecore connection.
|
|
15
|
+
*/
|
|
16
|
+
edge?: {
|
|
17
|
+
/**
|
|
18
|
+
* A unified identifier used to connect and retrieve data from XM Cloud instance
|
|
19
|
+
*/
|
|
20
|
+
contextId: string;
|
|
21
|
+
/**
|
|
22
|
+
* XM Cloud endpoint that the app will communicate and retrieve data from
|
|
23
|
+
* @default https://edge-platform.sitecorecloud.io
|
|
24
|
+
*/
|
|
25
|
+
edgeUrl?: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
9
28
|
children: React.ReactNode;
|
|
10
29
|
}
|
|
11
30
|
export interface SitecoreContextState {
|
|
12
31
|
setContext: (value: SitecoreContextValue | LayoutServiceData) => void;
|
|
13
32
|
context: SitecoreContextValue;
|
|
33
|
+
api?: SitecoreContextProps['api'];
|
|
14
34
|
}
|
|
15
35
|
export declare const SitecoreContextReactContext: React.Context<SitecoreContextState>;
|
|
16
36
|
export declare const ComponentFactoryReactContext: React.Context<ComponentFactory>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="@types/react" />
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { EnhancedOmit } from '@sitecore-jss/sitecore-jss/utils';
|
|
4
|
-
import { SitecoreContextValue } from '../components/SitecoreContext';
|
|
4
|
+
import { SitecoreContextState, SitecoreContextValue } from '../components/SitecoreContext';
|
|
5
5
|
export interface WithSitecoreContextOptions {
|
|
6
6
|
updatable?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export interface WithSitecoreContextProps {
|
|
9
9
|
sitecoreContext: SitecoreContextValue;
|
|
10
|
+
api?: SitecoreContextState['api'];
|
|
10
11
|
updateSitecoreContext?: ((value: SitecoreContextValue) => void) | false;
|
|
11
12
|
}
|
|
12
13
|
export type WithSitecoreContextHocProps<ComponentProps> = EnhancedOmit<ComponentProps, keyof WithSitecoreContextProps>;
|
|
@@ -35,7 +36,4 @@ export declare function withSitecoreContext(options?: WithSitecoreContextOptions
|
|
|
35
36
|
* }
|
|
36
37
|
* @returns {object} { sitecoreContext, updateSitecoreContext }
|
|
37
38
|
*/
|
|
38
|
-
export declare function useSitecoreContext(options?: WithSitecoreContextOptions):
|
|
39
|
-
sitecoreContext: SitecoreContextValue;
|
|
40
|
-
updateSitecoreContext: (value: import("@sitecore-jss/sitecore-jss/layout").LayoutServiceData | SitecoreContextValue) => void;
|
|
41
|
-
};
|
|
39
|
+
export declare function useSitecoreContext(options?: WithSitecoreContextOptions): WithSitecoreContextProps;
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { constants, enableDebug, ClientError, CacheClient, CacheOptions, MemoryCacheClient, HttpDataFetcher, NativeDataFetcher, NativeDataFetcherError, NativeDataFetcherResponse, NativeDataFetcherConfig, } from '@sitecore-jss/sitecore-jss';
|
|
2
2
|
export { EnhancedOmit } from '@sitecore-jss/sitecore-jss/utils';
|
|
3
3
|
export { isEditorActive, resetEditorChromes, DefaultEditFrameButton, DefaultEditFrameButtons, EditFrameDataSource, FieldEditButton, WebEditButton, EditButtonTypes, } from '@sitecore-jss/sitecore-jss/editing';
|
|
4
|
-
export { getContentStylesheetLink,
|
|
4
|
+
export { getContentStylesheetLink, getDesignLibraryStylesheetLinks, LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, RestLayoutService, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, EditMode, } from '@sitecore-jss/sitecore-jss/layout';
|
|
5
5
|
export { trackingApi, TrackingRequestOptions, CampaignInstance, GoalInstance, OutcomeInstance, EventInstance, PageViewInstance, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
6
6
|
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, RestDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
7
7
|
export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClientFactoryConfig, GraphQLRequestClient, } from '@sitecore-jss/sitecore-jss/graphql';
|
|
@@ -14,7 +14,7 @@ export { Text, TextField } from './components/Text';
|
|
|
14
14
|
export { DateField, DateFieldProps } from './components/Date';
|
|
15
15
|
export { FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, } from './components/FEaaSComponent';
|
|
16
16
|
export { FEaaSWrapper } from './components/FEaaSWrapper';
|
|
17
|
-
export {
|
|
17
|
+
export { DesignLibrary } from './components/DesignLibrary';
|
|
18
18
|
export { BYOCComponent, BYOCComponentParams, BYOCComponentProps, fetchBYOCComponentServerProps, } from './components/BYOCComponent';
|
|
19
19
|
export { BYOCWrapper } from './components/BYOCWrapper';
|
|
20
20
|
export { Link, LinkField, LinkFieldValue, LinkProps, LinkPropTypes } from './components/Link';
|