@sitecore-content-sdk/react 0.1.0-beta.34 → 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.
- package/dist/cjs/components/EditingScripts.js +20 -7
- package/dist/cjs/components/Placeholder.js +4 -4
- package/dist/cjs/components/PlaceholderCommon.js +16 -9
- package/dist/cjs/components/SitecoreContext.js +4 -4
- package/dist/cjs/components/sharedTypes/components.js +7 -0
- package/dist/cjs/components/sharedTypes/index.js +18 -0
- package/dist/cjs/enhancers/{withComponentFactory.js → withComponentMap.js} +7 -7
- package/dist/cjs/enhancers/withPlaceholder.js +3 -3
- package/dist/cjs/index.js +1 -3
- package/dist/esm/components/EditingScripts.js +21 -8
- package/dist/esm/components/Placeholder.js +4 -4
- package/dist/esm/components/PlaceholderCommon.js +16 -9
- package/dist/esm/components/SitecoreContext.js +3 -3
- package/dist/esm/components/sharedTypes/components.js +4 -0
- package/dist/esm/components/sharedTypes/index.js +2 -0
- package/dist/esm/enhancers/withComponentMap.js +20 -0
- package/dist/esm/enhancers/withPlaceholder.js +3 -3
- package/dist/esm/index.js +0 -1
- package/package.json +3 -3
- package/types/components/EditingScripts.d.ts +15 -2
- package/types/components/PlaceholderCommon.d.ts +5 -5
- package/types/components/SitecoreContext.d.ts +4 -4
- package/types/components/sharedTypes/components.d.ts +32 -0
- package/types/components/sharedTypes/index.d.ts +2 -0
- package/types/components/sharedTypes/props.d.ts +14 -0
- package/types/enhancers/withComponentMap.d.ts +12 -0
- package/types/index.d.ts +1 -2
- package/dist/cjs/ComponentBuilder.js +0 -25
- package/dist/esm/ComponentBuilder.js +0 -21
- package/dist/esm/enhancers/withComponentFactory.js +0 -20
- package/types/ComponentBuilder.d.ts +0 -27
- package/types/components/sharedTypes.d.ts +0 -28
- package/types/enhancers/withComponentFactory.d.ts +0 -12
- /package/dist/cjs/components/{sharedTypes.js → sharedTypes/props.js} +0 -0
- /package/dist/esm/components/{sharedTypes.js → sharedTypes/props.js} +0 -0
|
@@ -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 }))),
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Placeholder = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const PlaceholderCommon_1 = require("./PlaceholderCommon");
|
|
9
|
-
const
|
|
9
|
+
const withComponentMap_1 = require("../enhancers/withComponentMap");
|
|
10
10
|
const editing_1 = require("@sitecore-content-sdk/core/editing");
|
|
11
11
|
const withSitecoreContext_1 = require("../enhancers/withSitecoreContext");
|
|
12
12
|
class PlaceholderComponent extends PlaceholderCommon_1.PlaceholderCommon {
|
|
@@ -30,7 +30,7 @@ class PlaceholderComponent extends PlaceholderCommon_1.PlaceholderCommon {
|
|
|
30
30
|
render() {
|
|
31
31
|
var _a, _b;
|
|
32
32
|
const childProps = Object.assign({}, this.props);
|
|
33
|
-
delete childProps.
|
|
33
|
+
delete childProps.componentMap;
|
|
34
34
|
if (this.state.error) {
|
|
35
35
|
if (childProps.errorComponent) {
|
|
36
36
|
return react_1.default.createElement(childProps.errorComponent, { error: this.state.error });
|
|
@@ -68,5 +68,5 @@ class PlaceholderComponent extends PlaceholderCommon_1.PlaceholderCommon {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
PlaceholderComponent.propTypes = PlaceholderCommon_1.PlaceholderCommon.propTypes;
|
|
71
|
-
const
|
|
72
|
-
exports.Placeholder = (0, withSitecoreContext_1.withSitecoreContext)()(
|
|
71
|
+
const PlaceholderWithComponentMap = (0, withComponentMap_1.withComponentMap)(PlaceholderComponent);
|
|
72
|
+
exports.Placeholder = (0, withSitecoreContext_1.withSitecoreContext)()(PlaceholderWithComponentMap);
|
|
@@ -18,6 +18,7 @@ exports.PlaceholderCommon = void 0;
|
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const prop_types_1 = __importDefault(require("prop-types"));
|
|
20
20
|
const MissingComponent_1 = require("./MissingComponent");
|
|
21
|
+
const sharedTypes_1 = require("./sharedTypes");
|
|
21
22
|
const layout_1 = require("@sitecore-content-sdk/core/layout");
|
|
22
23
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
23
24
|
const HiddenRendering_1 = require("./HiddenRendering");
|
|
@@ -102,7 +103,7 @@ class PlaceholderCommon extends react_1.default.Component {
|
|
|
102
103
|
else {
|
|
103
104
|
component = this.getComponentForRendering(componentRendering);
|
|
104
105
|
}
|
|
105
|
-
// Fallback/defaults for Sitecore Component renderings (in case not defined in component
|
|
106
|
+
// Fallback/defaults for Sitecore Component renderings (in case not defined in component map)
|
|
106
107
|
if (!component) {
|
|
107
108
|
if (componentRendering.componentName === FEaaSComponent_1.FEAAS_COMPONENT_RENDERING_NAME) {
|
|
108
109
|
component = FEaaSComponent_1.FEaaSComponent;
|
|
@@ -118,7 +119,7 @@ class PlaceholderCommon extends react_1.default.Component {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
if (!component) {
|
|
121
|
-
console.error(`Placeholder ${name} contains unknown component ${componentRendering.componentName}. Ensure that a React component exists for it, and that it is registered in your
|
|
122
|
+
console.error(`Placeholder ${name} contains unknown component ${componentRendering.componentName}. Ensure that a React component exists for it, and that it is registered in your component-map file.`);
|
|
122
123
|
component = missingComponentComponent !== null && missingComponentComponent !== void 0 ? missingComponentComponent : MissingComponent_1.MissingComponent;
|
|
123
124
|
isEmpty = true;
|
|
124
125
|
}
|
|
@@ -151,16 +152,22 @@ class PlaceholderCommon extends react_1.default.Component {
|
|
|
151
152
|
}
|
|
152
153
|
getComponentForRendering(renderingDefinition) {
|
|
153
154
|
var _a;
|
|
154
|
-
const
|
|
155
|
-
if (!
|
|
156
|
-
console.warn(`No
|
|
155
|
+
const componentMap = this.props.componentMap;
|
|
156
|
+
if (!componentMap || componentMap.size === 0) {
|
|
157
|
+
console.warn(`No components were available in component map to service request for component ${renderingDefinition}`);
|
|
157
158
|
return null;
|
|
158
159
|
}
|
|
159
|
-
// Render SXA Rendering Variant
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
// Render SXA Rendering Variant if available
|
|
161
|
+
const exportName = (_a = renderingDefinition.params) === null || _a === void 0 ? void 0 : _a.FieldNames;
|
|
162
|
+
const component = componentMap.get(renderingDefinition.componentName);
|
|
163
|
+
if (!component)
|
|
164
|
+
return null;
|
|
165
|
+
if (exportName && exportName !== sharedTypes_1.DEFAULT_EXPORT_NAME) {
|
|
166
|
+
return component[exportName];
|
|
162
167
|
}
|
|
163
|
-
return
|
|
168
|
+
return (component.default ||
|
|
169
|
+
component.Default ||
|
|
170
|
+
component);
|
|
164
171
|
}
|
|
165
172
|
}
|
|
166
173
|
exports.PlaceholderCommon = PlaceholderCommon;
|
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SitecoreContext = exports.
|
|
6
|
+
exports.SitecoreContext = exports.ComponentMapReactContext = exports.SitecoreContextReactContext = void 0;
|
|
7
7
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
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
11
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
12
12
|
exports.SitecoreContextReactContext = react_1.default.createContext({});
|
|
13
|
-
exports.
|
|
13
|
+
exports.ComponentMapReactContext = react_1.default.createContext(new Map());
|
|
14
14
|
class SitecoreContext extends react_1.default.Component {
|
|
15
15
|
constructor(props) {
|
|
16
16
|
var _a, _b, _c, _d;
|
|
@@ -56,14 +56,14 @@ class SitecoreContext extends react_1.default.Component {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
render() {
|
|
59
|
-
return (react_1.default.createElement(exports.
|
|
59
|
+
return (react_1.default.createElement(exports.ComponentMapReactContext.Provider, { value: this.props.componentMap },
|
|
60
60
|
react_1.default.createElement(exports.SitecoreContextReactContext.Provider, { value: this.state }, this.props.children)));
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
exports.SitecoreContext = SitecoreContext;
|
|
64
64
|
SitecoreContext.propTypes = {
|
|
65
65
|
children: prop_types_1.default.any.isRequired,
|
|
66
|
-
|
|
66
|
+
componentMap: prop_types_1.default.instanceOf(Map),
|
|
67
67
|
layoutData: prop_types_1.default.shape({
|
|
68
68
|
sitecore: prop_types_1.default.shape({
|
|
69
69
|
context: prop_types_1.default.any,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./components"), exports);
|
|
18
|
+
__exportStar(require("./props"), exports);
|
|
@@ -3,24 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.withComponentMap = withComponentMap;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const SitecoreContext_1 = require("../components/SitecoreContext");
|
|
9
9
|
const react_2 = require("react");
|
|
10
10
|
/**
|
|
11
11
|
* @param {React.ComponentClass<T> | React.FC<T>} Component
|
|
12
12
|
*/
|
|
13
|
-
function
|
|
13
|
+
function withComponentMap(Component) {
|
|
14
14
|
/**
|
|
15
15
|
* @param {T} props - props to pass to the wrapped component
|
|
16
16
|
* @returns {JSX.Element} - the rendered component
|
|
17
17
|
*/
|
|
18
|
-
function
|
|
19
|
-
const context = (0, react_2.useContext)(SitecoreContext_1.
|
|
20
|
-
return react_1.default.createElement(Component, Object.assign({}, props, {
|
|
18
|
+
function WithComponentMap(props) {
|
|
19
|
+
const context = (0, react_2.useContext)(SitecoreContext_1.ComponentMapReactContext);
|
|
20
|
+
return react_1.default.createElement(Component, Object.assign({}, props, { componentMap: props.componentMap || context }));
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
WithComponentMap.displayName = `withComponentMap(${Component.displayName ||
|
|
23
23
|
Component.name ||
|
|
24
24
|
'Anonymous'})`;
|
|
25
|
-
return
|
|
25
|
+
return WithComponentMap;
|
|
26
26
|
}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.withPlaceholder = withPlaceholder;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const PlaceholderCommon_1 = require("../components/PlaceholderCommon");
|
|
9
|
-
const
|
|
9
|
+
const withComponentMap_1 = require("./withComponentMap");
|
|
10
10
|
const withSitecoreContext_1 = require("./withSitecoreContext");
|
|
11
11
|
/**
|
|
12
12
|
* @param {WithPlaceholderSpec} placeholders
|
|
@@ -20,7 +20,7 @@ function withPlaceholder(placeholders, options) {
|
|
|
20
20
|
}
|
|
21
21
|
render() {
|
|
22
22
|
let childProps = Object.assign({}, this.props);
|
|
23
|
-
delete childProps.
|
|
23
|
+
delete childProps.componentMap;
|
|
24
24
|
if (options && options.propsTransformer) {
|
|
25
25
|
childProps = options.propsTransformer(childProps);
|
|
26
26
|
}
|
|
@@ -58,6 +58,6 @@ function withPlaceholder(placeholders, options) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
WithPlaceholder.propTypes = PlaceholderCommon_1.PlaceholderCommon.propTypes;
|
|
61
|
-
return (0, withSitecoreContext_1.withSitecoreContext)()((0,
|
|
61
|
+
return (0, withSitecoreContext_1.withSitecoreContext)()((0, withComponentMap_1.withComponentMap)(WithPlaceholder));
|
|
62
62
|
};
|
|
63
63
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GraphQLSitePathService = exports.DefaultEmptyFieldEditingComponentImage = exports.DefaultEmptyFieldEditingComponentText = exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.
|
|
3
|
+
exports.GraphQLSitePathService = exports.DefaultEmptyFieldEditingComponentImage = exports.DefaultEmptyFieldEditingComponentText = exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = 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.Image = exports.Placeholder = exports.Form = exports.mediaApi = exports.GraphQLRequestClient = exports.DefaultRetryStrategy = exports.GraphQLDictionaryService = exports.EditMode = exports.getFieldValue = exports.getChildPlaceholder = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.getDesignLibraryStylesheetLinks = exports.getContentStylesheetLink = exports.resetEditorChromes = exports.isEditorActive = exports.NativeDataFetcher = exports.MemoryCacheClient = exports.ClientError = exports.enableDebug = exports.constants = void 0;
|
|
4
4
|
var core_1 = require("@sitecore-content-sdk/core");
|
|
5
5
|
Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return core_1.constants; } });
|
|
6
6
|
Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return core_1.enableDebug; } });
|
|
@@ -67,8 +67,6 @@ var withPlaceholder_1 = require("./enhancers/withPlaceholder");
|
|
|
67
67
|
Object.defineProperty(exports, "withPlaceholder", { enumerable: true, get: function () { return withPlaceholder_1.withPlaceholder; } });
|
|
68
68
|
var withDatasourceCheck_1 = require("./enhancers/withDatasourceCheck");
|
|
69
69
|
Object.defineProperty(exports, "withDatasourceCheck", { enumerable: true, get: function () { return withDatasourceCheck_1.withDatasourceCheck; } });
|
|
70
|
-
var ComponentBuilder_1 = require("./ComponentBuilder");
|
|
71
|
-
Object.defineProperty(exports, "ComponentBuilder", { enumerable: true, get: function () { return ComponentBuilder_1.ComponentBuilder; } });
|
|
72
70
|
var withFieldMetadata_1 = require("./enhancers/withFieldMetadata");
|
|
73
71
|
Object.defineProperty(exports, "withFieldMetadata", { enumerable: true, get: function () { return withFieldMetadata_1.withFieldMetadata; } });
|
|
74
72
|
var withEmptyFieldEditingComponent_1 = require("./enhancers/withEmptyFieldEditingComponent");
|
|
@@ -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 }))),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PlaceholderCommon } from './PlaceholderCommon';
|
|
3
|
-
import {
|
|
3
|
+
import { withComponentMap } from '../enhancers/withComponentMap';
|
|
4
4
|
import { PagesEditor } from '@sitecore-content-sdk/core/editing';
|
|
5
5
|
import { withSitecoreContext } from '../enhancers/withSitecoreContext';
|
|
6
6
|
class PlaceholderComponent extends PlaceholderCommon {
|
|
@@ -24,7 +24,7 @@ class PlaceholderComponent extends PlaceholderCommon {
|
|
|
24
24
|
render() {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
const childProps = Object.assign({}, this.props);
|
|
27
|
-
delete childProps.
|
|
27
|
+
delete childProps.componentMap;
|
|
28
28
|
if (this.state.error) {
|
|
29
29
|
if (childProps.errorComponent) {
|
|
30
30
|
return React.createElement(childProps.errorComponent, { error: this.state.error });
|
|
@@ -62,5 +62,5 @@ class PlaceholderComponent extends PlaceholderCommon {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
PlaceholderComponent.propTypes = PlaceholderCommon.propTypes;
|
|
65
|
-
const
|
|
66
|
-
export const Placeholder = withSitecoreContext()(
|
|
65
|
+
const PlaceholderWithComponentMap = withComponentMap(PlaceholderComponent);
|
|
66
|
+
export const Placeholder = withSitecoreContext()(PlaceholderWithComponentMap);
|
|
@@ -12,6 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
14
|
import { MissingComponent } from './MissingComponent';
|
|
15
|
+
import { DEFAULT_EXPORT_NAME } from './sharedTypes';
|
|
15
16
|
import { isDynamicPlaceholder, getDynamicPlaceholderPattern, } from '@sitecore-content-sdk/core/layout';
|
|
16
17
|
import { constants } from '@sitecore-content-sdk/core';
|
|
17
18
|
import { HiddenRendering } from './HiddenRendering';
|
|
@@ -96,7 +97,7 @@ export class PlaceholderCommon extends React.Component {
|
|
|
96
97
|
else {
|
|
97
98
|
component = this.getComponentForRendering(componentRendering);
|
|
98
99
|
}
|
|
99
|
-
// Fallback/defaults for Sitecore Component renderings (in case not defined in component
|
|
100
|
+
// Fallback/defaults for Sitecore Component renderings (in case not defined in component map)
|
|
100
101
|
if (!component) {
|
|
101
102
|
if (componentRendering.componentName === FEAAS_COMPONENT_RENDERING_NAME) {
|
|
102
103
|
component = FEaaSComponent;
|
|
@@ -112,7 +113,7 @@ export class PlaceholderCommon extends React.Component {
|
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
if (!component) {
|
|
115
|
-
console.error(`Placeholder ${name} contains unknown component ${componentRendering.componentName}. Ensure that a React component exists for it, and that it is registered in your
|
|
116
|
+
console.error(`Placeholder ${name} contains unknown component ${componentRendering.componentName}. Ensure that a React component exists for it, and that it is registered in your component-map file.`);
|
|
116
117
|
component = missingComponentComponent !== null && missingComponentComponent !== void 0 ? missingComponentComponent : MissingComponent;
|
|
117
118
|
isEmpty = true;
|
|
118
119
|
}
|
|
@@ -145,16 +146,22 @@ export class PlaceholderCommon extends React.Component {
|
|
|
145
146
|
}
|
|
146
147
|
getComponentForRendering(renderingDefinition) {
|
|
147
148
|
var _a;
|
|
148
|
-
const
|
|
149
|
-
if (!
|
|
150
|
-
console.warn(`No
|
|
149
|
+
const componentMap = this.props.componentMap;
|
|
150
|
+
if (!componentMap || componentMap.size === 0) {
|
|
151
|
+
console.warn(`No components were available in component map to service request for component ${renderingDefinition}`);
|
|
151
152
|
return null;
|
|
152
153
|
}
|
|
153
|
-
// Render SXA Rendering Variant
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
// Render SXA Rendering Variant if available
|
|
155
|
+
const exportName = (_a = renderingDefinition.params) === null || _a === void 0 ? void 0 : _a.FieldNames;
|
|
156
|
+
const component = componentMap.get(renderingDefinition.componentName);
|
|
157
|
+
if (!component)
|
|
158
|
+
return null;
|
|
159
|
+
if (exportName && exportName !== DEFAULT_EXPORT_NAME) {
|
|
160
|
+
return component[exportName];
|
|
156
161
|
}
|
|
157
|
-
return
|
|
162
|
+
return (component.default ||
|
|
163
|
+
component.Default ||
|
|
164
|
+
component);
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
167
|
PlaceholderCommon.propTypes = {
|
|
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
|
|
4
4
|
import fastDeepEqual from 'fast-deep-equal/es6/react';
|
|
5
5
|
import { constants } from '@sitecore-content-sdk/core';
|
|
6
6
|
export const SitecoreContextReactContext = React.createContext({});
|
|
7
|
-
export const
|
|
7
|
+
export const ComponentMapReactContext = React.createContext(new Map());
|
|
8
8
|
export class SitecoreContext extends React.Component {
|
|
9
9
|
constructor(props) {
|
|
10
10
|
var _a, _b, _c, _d;
|
|
@@ -50,13 +50,13 @@ export class SitecoreContext extends React.Component {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
render() {
|
|
53
|
-
return (React.createElement(
|
|
53
|
+
return (React.createElement(ComponentMapReactContext.Provider, { value: this.props.componentMap },
|
|
54
54
|
React.createElement(SitecoreContextReactContext.Provider, { value: this.state }, this.props.children)));
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
SitecoreContext.propTypes = {
|
|
58
58
|
children: PropTypes.any.isRequired,
|
|
59
|
-
|
|
59
|
+
componentMap: PropTypes.instanceOf(Map),
|
|
60
60
|
layoutData: PropTypes.shape({
|
|
61
61
|
sitecore: PropTypes.shape({
|
|
62
62
|
context: PropTypes.any,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentMapReactContext } from '../components/SitecoreContext';
|
|
3
|
+
import { useContext } from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* @param {React.ComponentClass<T> | React.FC<T>} Component
|
|
6
|
+
*/
|
|
7
|
+
export function withComponentMap(Component) {
|
|
8
|
+
/**
|
|
9
|
+
* @param {T} props - props to pass to the wrapped component
|
|
10
|
+
* @returns {JSX.Element} - the rendered component
|
|
11
|
+
*/
|
|
12
|
+
function WithComponentMap(props) {
|
|
13
|
+
const context = useContext(ComponentMapReactContext);
|
|
14
|
+
return React.createElement(Component, Object.assign({}, props, { componentMap: props.componentMap || context }));
|
|
15
|
+
}
|
|
16
|
+
WithComponentMap.displayName = `withComponentMap(${Component.displayName ||
|
|
17
|
+
Component.name ||
|
|
18
|
+
'Anonymous'})`;
|
|
19
|
+
return WithComponentMap;
|
|
20
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PlaceholderCommon } from '../components/PlaceholderCommon';
|
|
3
|
-
import {
|
|
3
|
+
import { withComponentMap } from './withComponentMap';
|
|
4
4
|
import { withSitecoreContext } from './withSitecoreContext';
|
|
5
5
|
/**
|
|
6
6
|
* @param {WithPlaceholderSpec} placeholders
|
|
@@ -14,7 +14,7 @@ export function withPlaceholder(placeholders, options) {
|
|
|
14
14
|
}
|
|
15
15
|
render() {
|
|
16
16
|
let childProps = Object.assign({}, this.props);
|
|
17
|
-
delete childProps.
|
|
17
|
+
delete childProps.componentMap;
|
|
18
18
|
if (options && options.propsTransformer) {
|
|
19
19
|
childProps = options.propsTransformer(childProps);
|
|
20
20
|
}
|
|
@@ -52,6 +52,6 @@ export function withPlaceholder(placeholders, options) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
WithPlaceholder.propTypes = PlaceholderCommon.propTypes;
|
|
55
|
-
return withSitecoreContext()(
|
|
55
|
+
return withSitecoreContext()(withComponentMap(WithPlaceholder));
|
|
56
56
|
};
|
|
57
57
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -22,7 +22,6 @@ export { withSitecoreContext, useSitecoreContext, } from './enhancers/withSiteco
|
|
|
22
22
|
export { withEditorChromes } from './enhancers/withEditorChromes';
|
|
23
23
|
export { withPlaceholder } from './enhancers/withPlaceholder';
|
|
24
24
|
export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
|
|
25
|
-
export { ComponentBuilder } from './ComponentBuilder';
|
|
26
25
|
export { withFieldMetadata } from './enhancers/withFieldMetadata';
|
|
27
26
|
export { withEmptyFieldEditingComponent } from './enhancers/withEmptyFieldEditingComponent';
|
|
28
27
|
export { EditingScripts } from './components/EditingScripts';
|
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ComponentType } from 'react';
|
|
2
2
|
import PropTypes, { Requireable } from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { ComponentMap } from './sharedTypes';
|
|
4
4
|
import { ComponentRendering, RouteData, Field, Item } from '@sitecore-content-sdk/core/layout';
|
|
5
5
|
import { SitecoreContextValue } from './SitecoreContext';
|
|
6
6
|
type ErrorComponentProps = {
|
|
@@ -18,10 +18,10 @@ export interface PlaceholderProps {
|
|
|
18
18
|
/** Rendering data to be used when rendering the placeholder. */
|
|
19
19
|
rendering: ComponentRendering | RouteData;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
* When rendered within a <SitecoreContext> component, defaults to the context
|
|
21
|
+
* Component Map will be used to map Sitecore component names to app implementation
|
|
22
|
+
* When rendered within a <SitecoreContext> component, defaults to the context componentMap.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
componentMap?: ComponentMap;
|
|
25
25
|
/**
|
|
26
26
|
* An object of field names/values that are aggregated and propagated through the component tree created by a placeholder.
|
|
27
27
|
* Any component or placeholder rendered by a placeholder will have access to this data via `props.fields`.
|
|
@@ -45,7 +45,7 @@ export interface PlaceholderProps {
|
|
|
45
45
|
modifyComponentProps?: (componentProps: ComponentProps) => ComponentProps;
|
|
46
46
|
/**
|
|
47
47
|
* A component that is rendered in place of any components that are in this placeholder,
|
|
48
|
-
* but do not have a definition in the
|
|
48
|
+
* but do not have a definition in the componentMap (i.e. don't have a React implementation)
|
|
49
49
|
*/
|
|
50
50
|
missingComponentComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
|
|
51
51
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { ComponentFactory } from './sharedTypes';
|
|
4
3
|
import { SitecoreConfig } from '@sitecore-content-sdk/core/config';
|
|
5
4
|
import { LayoutServiceContext, LayoutServiceData, RouteData } from '../index';
|
|
5
|
+
import { ComponentMap } from './sharedTypes';
|
|
6
6
|
export interface SitecoreContextProps {
|
|
7
7
|
api: SitecoreConfig['api'];
|
|
8
|
-
|
|
8
|
+
componentMap: ComponentMap;
|
|
9
9
|
layoutData?: LayoutServiceData;
|
|
10
10
|
children: React.ReactNode;
|
|
11
11
|
}
|
|
@@ -15,7 +15,7 @@ export interface SitecoreContextState {
|
|
|
15
15
|
api?: SitecoreContextProps['api'];
|
|
16
16
|
}
|
|
17
17
|
export declare const SitecoreContextReactContext: React.Context<SitecoreContextState>;
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const ComponentMapReactContext: React.Context<ComponentMap>;
|
|
19
19
|
export type SitecoreContextValue = LayoutServiceContext & {
|
|
20
20
|
itemId?: string;
|
|
21
21
|
route?: RouteData;
|
|
@@ -23,7 +23,7 @@ export type SitecoreContextValue = LayoutServiceContext & {
|
|
|
23
23
|
export declare class SitecoreContext extends React.Component<SitecoreContextProps, SitecoreContextState> {
|
|
24
24
|
static propTypes: {
|
|
25
25
|
children: PropTypes.Validator<any>;
|
|
26
|
-
|
|
26
|
+
componentMap: PropTypes.Requireable<Map<unknown, unknown>>;
|
|
27
27
|
layoutData: PropTypes.Requireable<PropTypes.InferProps<{
|
|
28
28
|
sitecore: PropTypes.Requireable<PropTypes.InferProps<{
|
|
29
29
|
context: PropTypes.Requireable<any>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* SXA uses custom default export name
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_EXPORT_NAME = "Default";
|
|
6
|
+
/**
|
|
7
|
+
* React component import with account for custom exports
|
|
8
|
+
*/
|
|
9
|
+
export type ReactJssComponent = ComponentType | ReactModule;
|
|
10
|
+
export type ReactModule = {
|
|
11
|
+
/**
|
|
12
|
+
* Custom exports
|
|
13
|
+
*/
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Default module export
|
|
17
|
+
*/
|
|
18
|
+
Default?: ComponentType;
|
|
19
|
+
/**
|
|
20
|
+
* Default non-standard export
|
|
21
|
+
*/
|
|
22
|
+
default?: ComponentType;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Component type returned from component builder / factory
|
|
26
|
+
*/
|
|
27
|
+
export type LazyComponentType = ComponentType & {
|
|
28
|
+
render?: {
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export type ComponentMap<TComponent extends ReactJssComponent = ReactJssComponent> = Map<string, TComponent>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared editing field props
|
|
3
|
+
*/
|
|
4
|
+
export interface EditableFieldProps {
|
|
5
|
+
/**
|
|
6
|
+
* Can be used to explicitly disable inline editing.
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
editable?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Custom element to render in Pages in edit mode if field value is empty
|
|
12
|
+
*/
|
|
13
|
+
emptyFieldEditingComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentMap } from '../components/sharedTypes';
|
|
3
|
+
export interface WithComponentMapProps {
|
|
4
|
+
componentMap?: ComponentMap;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @param {React.ComponentClass<T> | React.FC<T>} Component
|
|
8
|
+
*/
|
|
9
|
+
export declare function withComponentMap<T extends WithComponentMapProps>(Component: React.ComponentClass<T> | React.FC<T>): {
|
|
10
|
+
(props: T): JSX.Element;
|
|
11
|
+
displayName: string;
|
|
12
|
+
};
|
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 { ReactJssComponent, 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, RichTextPropTypes, RichTextField } from './components/RichText';
|
|
@@ -24,7 +24,6 @@ export { withSitecoreContext, useSitecoreContext, WithSitecoreContextOptions, Wi
|
|
|
24
24
|
export { withEditorChromes } from './enhancers/withEditorChromes';
|
|
25
25
|
export { withPlaceholder } from './enhancers/withPlaceholder';
|
|
26
26
|
export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
|
|
27
|
-
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
|
28
27
|
export { withFieldMetadata } from './enhancers/withFieldMetadata';
|
|
29
28
|
export { withEmptyFieldEditingComponent } from './enhancers/withEmptyFieldEditingComponent';
|
|
30
29
|
export { EditingScripts } from './components/EditingScripts';
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComponentBuilder = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* React implementation of component builder class for building components based on the configuration.
|
|
6
|
-
*/
|
|
7
|
-
class ComponentBuilder {
|
|
8
|
-
constructor(config) {
|
|
9
|
-
this.config = config;
|
|
10
|
-
this.components = new Map([...config.components]);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new instance of component factory
|
|
14
|
-
* @returns {ComponentFactory} Component factory implementation
|
|
15
|
-
*/
|
|
16
|
-
getComponentFactory() {
|
|
17
|
-
return (componentName) => {
|
|
18
|
-
const component = this.components.get(componentName);
|
|
19
|
-
if (!component)
|
|
20
|
-
return null;
|
|
21
|
-
return component;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.ComponentBuilder = ComponentBuilder;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React implementation of component builder class for building components based on the configuration.
|
|
3
|
-
*/
|
|
4
|
-
export class ComponentBuilder {
|
|
5
|
-
constructor(config) {
|
|
6
|
-
this.config = config;
|
|
7
|
-
this.components = new Map([...config.components]);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new instance of component factory
|
|
11
|
-
* @returns {ComponentFactory} Component factory implementation
|
|
12
|
-
*/
|
|
13
|
-
getComponentFactory() {
|
|
14
|
-
return (componentName) => {
|
|
15
|
-
const component = this.components.get(componentName);
|
|
16
|
-
if (!component)
|
|
17
|
-
return null;
|
|
18
|
-
return component;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ComponentFactoryReactContext } from '../components/SitecoreContext';
|
|
3
|
-
import { useContext } from 'react';
|
|
4
|
-
/**
|
|
5
|
-
* @param {React.ComponentClass<T> | React.FC<T>} Component
|
|
6
|
-
*/
|
|
7
|
-
export function withComponentFactory(Component) {
|
|
8
|
-
/**
|
|
9
|
-
* @param {T} props - props to pass to the wrapped component
|
|
10
|
-
* @returns {JSX.Element} - the rendered component
|
|
11
|
-
*/
|
|
12
|
-
function WithComponentFactory(props) {
|
|
13
|
-
const context = useContext(ComponentFactoryReactContext);
|
|
14
|
-
return React.createElement(Component, Object.assign({}, props, { componentFactory: props.componentFactory || context }));
|
|
15
|
-
}
|
|
16
|
-
WithComponentFactory.displayName = `withComponentFactory(${Component.displayName ||
|
|
17
|
-
Component.name ||
|
|
18
|
-
'Anonymous'})`;
|
|
19
|
-
return WithComponentFactory;
|
|
20
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
import { ComponentFactory } from './components/sharedTypes';
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for ComponentBuilder
|
|
5
|
-
*/
|
|
6
|
-
export type ComponentBuilderConfig<ComponentType> = {
|
|
7
|
-
/**
|
|
8
|
-
* List of components to be stored
|
|
9
|
-
*/
|
|
10
|
-
components: Map<string, ComponentType>;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* React implementation of component builder class for building components based on the configuration.
|
|
14
|
-
*/
|
|
15
|
-
export declare class ComponentBuilder {
|
|
16
|
-
protected config: ComponentBuilderConfig<ComponentType>;
|
|
17
|
-
/**
|
|
18
|
-
* List of components to be stored
|
|
19
|
-
*/
|
|
20
|
-
protected components: Map<string, ComponentType>;
|
|
21
|
-
constructor(config: ComponentBuilderConfig<ComponentType>);
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new instance of component factory
|
|
24
|
-
* @returns {ComponentFactory} Component factory implementation
|
|
25
|
-
*/
|
|
26
|
-
getComponentFactory(): ComponentFactory;
|
|
27
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* @param {string} componentName component to be imported from the component factory
|
|
4
|
-
* @param {string?} exportName component to be imported in case you export multiple components from the same file
|
|
5
|
-
*/
|
|
6
|
-
export type ComponentFactory = (componentName: string, exportName?: string) => JssComponentType | null;
|
|
7
|
-
/**
|
|
8
|
-
* Component type returned from component builder / factory
|
|
9
|
-
*/
|
|
10
|
-
export type JssComponentType = ComponentType & {
|
|
11
|
-
render?: {
|
|
12
|
-
[key: string]: unknown;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Shared editing field props
|
|
17
|
-
*/
|
|
18
|
-
export interface EditableFieldProps {
|
|
19
|
-
/**
|
|
20
|
-
* Can be used to explicitly disable inline editing.
|
|
21
|
-
* @default true
|
|
22
|
-
*/
|
|
23
|
-
editable?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Custom element to render in Pages in edit mode if field value is empty
|
|
26
|
-
*/
|
|
27
|
-
emptyFieldEditingComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
|
|
28
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ComponentFactory } from '../components/sharedTypes';
|
|
3
|
-
export interface ComponentFactoryProps {
|
|
4
|
-
componentFactory?: ComponentFactory;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* @param {React.ComponentClass<T> | React.FC<T>} Component
|
|
8
|
-
*/
|
|
9
|
-
export declare function withComponentFactory<T extends ComponentFactoryProps>(Component: React.ComponentClass<T> | React.FC<T>): {
|
|
10
|
-
(props: T): JSX.Element;
|
|
11
|
-
displayName: string;
|
|
12
|
-
};
|
|
File without changes
|
|
File without changes
|