@sitecore-jss/sitecore-jss-react 20.0.2 → 20.1.0-canary.2
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/.nyc_output/173f0211-344c-4eaa-8f79-f5b0e45279e6.json +1 -0
- package/.nyc_output/c4d084e7-2cd1-4afd-a6a5-2b617fc51ca7.json +1 -0
- package/.nyc_output/c8fa7776-951e-406a-acd7-a3a839ff9dd2.json +1 -0
- package/.nyc_output/processinfo/173f0211-344c-4eaa-8f79-f5b0e45279e6.json +1 -0
- package/.nyc_output/processinfo/c4d084e7-2cd1-4afd-a6a5-2b617fc51ca7.json +1 -0
- package/.nyc_output/processinfo/c8fa7776-951e-406a-acd7-a3a839ff9dd2.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/LICENSE.txt +202 -202
- package/README.md +8 -8
- package/coverage/coverage-summary.json +21 -0
- package/dist/cjs/components/Image.js +28 -16
- package/dist/cjs/components/Placeholder.js +1 -0
- package/dist/cjs/components/PlaceholderCommon.js +20 -2
- package/dist/cjs/enhancers/withComponentFactory.js +13 -3
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/utils.js +21 -1
- package/dist/esm/components/Image.js +27 -16
- package/dist/esm/components/Placeholder.js +1 -0
- package/dist/esm/components/PlaceholderCommon.js +20 -2
- package/dist/esm/enhancers/withComponentFactory.js +13 -3
- package/dist/esm/index.js +1 -1
- package/dist/esm/utils.js +19 -0
- package/package.json +3 -3
- package/tsconfig-esm.json +7 -7
- package/types/components/Image.d.ts +8 -0
- package/types/components/Placeholder.d.ts +4 -1
- package/types/components/PlaceholderCommon.d.ts +6 -5
- package/types/components/sharedTypes.d.ts +5 -1
- package/types/enhancers/withComponentFactory.d.ts +4 -1
- package/types/enhancers/withPlaceholder.d.ts +4 -1
- package/types/index.d.ts +1 -1
- package/types/utils.d.ts +8 -0
|
@@ -17,9 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.PlaceholderCommon = void 0;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const prop_types_1 = __importDefault(require("prop-types"));
|
|
20
|
-
const MissingComponent_1 = require("
|
|
20
|
+
const MissingComponent_1 = require("./MissingComponent");
|
|
21
21
|
const utils_1 = require("../utils");
|
|
22
22
|
const HiddenRendering_1 = require("./HiddenRendering");
|
|
23
|
+
/** [SXA] common marker by which we find container fo replacing **/
|
|
24
|
+
const PREFIX_PLACEHOLDER = 'container-{*}';
|
|
23
25
|
class PlaceholderCommon extends react_1.default.Component {
|
|
24
26
|
constructor(props) {
|
|
25
27
|
super(props);
|
|
@@ -31,6 +33,12 @@ class PlaceholderCommon extends react_1.default.Component {
|
|
|
31
33
|
}
|
|
32
34
|
static getPlaceholderDataFromRenderingData(rendering, name) {
|
|
33
35
|
let result;
|
|
36
|
+
/** [SXA] it needs for deleting dynamics placeholder when we set him number(props.name) of container.
|
|
37
|
+
from backend side we get common name of placeholder is called 'container-{*}' where '{*}' marker for replacing **/
|
|
38
|
+
if (rendering && rendering.placeholders && rendering.placeholders[PREFIX_PLACEHOLDER]) {
|
|
39
|
+
rendering.placeholders[name] = rendering.placeholders[PREFIX_PLACEHOLDER];
|
|
40
|
+
delete rendering.placeholders[PREFIX_PLACEHOLDER];
|
|
41
|
+
}
|
|
34
42
|
if (rendering && rendering.placeholders && Object.keys(rendering.placeholders).length > 0) {
|
|
35
43
|
result = rendering.placeholders[name];
|
|
36
44
|
}
|
|
@@ -52,6 +60,11 @@ class PlaceholderCommon extends react_1.default.Component {
|
|
|
52
60
|
componentDidCatch(error) {
|
|
53
61
|
this.setState({ error });
|
|
54
62
|
}
|
|
63
|
+
getSXAParams(rendering) {
|
|
64
|
+
return (rendering.params.FieldNames && {
|
|
65
|
+
styles: `${rendering.params.GridParameters || ''} ${rendering.params.Styles || ''}`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
55
68
|
getComponentsForRenderingData(placeholderData) {
|
|
56
69
|
const _a = this.props, { name, fields: placeholderFields, params: placeholderParams, missingComponentComponent, hiddenRenderingComponent } = _a, placeholderProps = __rest(_a, ["name", "fields", "params", "missingComponentComponent", "hiddenRenderingComponent"]);
|
|
57
70
|
return placeholderData
|
|
@@ -80,18 +93,23 @@ class PlaceholderCommon extends react_1.default.Component {
|
|
|
80
93
|
const finalProps = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, commonProps), placeholderProps), ((placeholderFields || componentRendering.fields) && {
|
|
81
94
|
fields: Object.assign(Object.assign({}, placeholderFields), componentRendering.fields),
|
|
82
95
|
})), ((placeholderParams || componentRendering.params) && {
|
|
83
|
-
params: Object.assign(Object.assign({}, placeholderParams), componentRendering.params),
|
|
96
|
+
params: Object.assign(Object.assign(Object.assign({}, placeholderParams), componentRendering.params), this.getSXAParams(componentRendering)),
|
|
84
97
|
})), { rendering: componentRendering });
|
|
85
98
|
return react_1.default.createElement(component, this.props.modifyComponentProps ? this.props.modifyComponentProps(finalProps) : finalProps);
|
|
86
99
|
})
|
|
87
100
|
.filter((element) => element); // remove nulls
|
|
88
101
|
}
|
|
89
102
|
getComponentForRendering(renderingDefinition) {
|
|
103
|
+
var _a;
|
|
90
104
|
const componentFactory = this.props.componentFactory;
|
|
91
105
|
if (!componentFactory || typeof componentFactory !== 'function') {
|
|
92
106
|
console.warn(`No componentFactory was available to service request for component ${renderingDefinition}`);
|
|
93
107
|
return null;
|
|
94
108
|
}
|
|
109
|
+
// Render SXA Rendering Variant
|
|
110
|
+
if ((_a = renderingDefinition.params) === null || _a === void 0 ? void 0 : _a.FieldNames) {
|
|
111
|
+
return componentFactory(renderingDefinition.componentName, renderingDefinition.params.FieldNames);
|
|
112
|
+
}
|
|
95
113
|
return componentFactory(renderingDefinition.componentName);
|
|
96
114
|
}
|
|
97
115
|
addRef(nodeRef) {
|
|
@@ -6,12 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.withComponentFactory = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const SitecoreContext_1 = require("../components/SitecoreContext");
|
|
9
|
+
const react_2 = require("react");
|
|
9
10
|
/**
|
|
10
11
|
* @param {React.ComponentClass<T> | React.SFC<T>} Component
|
|
11
12
|
*/
|
|
12
13
|
function withComponentFactory(Component) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @param {T} props - props to pass to the wrapped component
|
|
16
|
+
* @returns {JSX.Element} - the rendered component
|
|
17
|
+
*/
|
|
18
|
+
function WithComponentFactory(props) {
|
|
19
|
+
const context = react_2.useContext(SitecoreContext_1.ComponentFactoryReactContext);
|
|
20
|
+
return react_1.default.createElement(Component, Object.assign({}, props, { componentFactory: props.componentFactory || context }));
|
|
21
|
+
}
|
|
22
|
+
WithComponentFactory.displayName = `withComponentFactory(${Component.displayName ||
|
|
23
|
+
Component.name ||
|
|
24
|
+
'Anonymous'})`;
|
|
25
|
+
return WithComponentFactory;
|
|
16
26
|
}
|
|
17
27
|
exports.withComponentFactory = withComponentFactory;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withDatasourceCheck = exports.withPlaceholder = exports.withExperienceEditorChromes = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.LinkPropTypes = exports.Link = exports.DateField = exports.Text = exports.RichTextPropTypes = exports.RichText = exports.Image = exports.Placeholder = exports.mediaApi = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.resetEditorChromes = exports.isEditorActive = exports.resetExperienceEditorChromes = exports.isExperienceEditorActive = exports.constants = void 0;
|
|
3
|
+
exports.withDatasourceCheck = exports.withPlaceholder = exports.withExperienceEditorChromes = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.LinkPropTypes = exports.Link = exports.DateField = exports.Text = exports.RichTextPropTypes = exports.RichText = exports.getEEMarkup = exports.Image = exports.Placeholder = exports.mediaApi = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.resetEditorChromes = exports.isEditorActive = exports.resetExperienceEditorChromes = exports.isExperienceEditorActive = exports.constants = void 0;
|
|
4
4
|
var sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
5
5
|
Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return sitecore_jss_1.constants; } });
|
|
6
6
|
var utils_1 = require("@sitecore-jss/sitecore-jss/utils");
|
|
@@ -25,6 +25,7 @@ var Placeholder_1 = require("./components/Placeholder");
|
|
|
25
25
|
Object.defineProperty(exports, "Placeholder", { enumerable: true, get: function () { return Placeholder_1.Placeholder; } });
|
|
26
26
|
var Image_1 = require("./components/Image");
|
|
27
27
|
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return Image_1.Image; } });
|
|
28
|
+
Object.defineProperty(exports, "getEEMarkup", { enumerable: true, get: function () { return Image_1.getEEMarkup; } });
|
|
28
29
|
var RichText_1 = require("./components/RichText");
|
|
29
30
|
Object.defineProperty(exports, "RichText", { enumerable: true, get: function () { return RichText_1.RichText; } });
|
|
30
31
|
Object.defineProperty(exports, "RichTextPropTypes", { enumerable: true, get: function () { return RichText_1.RichTextPropTypes; } });
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertAttributesToReactProps = exports.convertStyleAttribute = exports.convertKebabCasetoCamelCase = void 0;
|
|
3
|
+
exports.addClassName = exports.convertAttributesToReactProps = exports.convertStyleAttribute = exports.convertKebabCasetoCamelCase = void 0;
|
|
4
4
|
const style_attr_1 = require("style-attr");
|
|
5
5
|
// https://stackoverflow.com/a/10426674/9324
|
|
6
6
|
const convertKebabCasetoCamelCase = (str) => str.replace(/^.|-./g, (letter, index) => index === 0 ? letter.toLowerCase() : letter.substr(1).toUpperCase());
|
|
@@ -48,3 +48,23 @@ const convertAttributesToReactProps = (attributes) => {
|
|
|
48
48
|
}, {});
|
|
49
49
|
};
|
|
50
50
|
exports.convertAttributesToReactProps = convertAttributesToReactProps;
|
|
51
|
+
/**
|
|
52
|
+
* "class" property will be transformed into or appended to "className" instead.
|
|
53
|
+
* @param {string} otherAttrs all other props included on the image component
|
|
54
|
+
* * @returns {void}
|
|
55
|
+
*/
|
|
56
|
+
const addClassName = (otherAttrs) => {
|
|
57
|
+
if (otherAttrs.class) {
|
|
58
|
+
// if any classes are defined properly already
|
|
59
|
+
if (otherAttrs.className) {
|
|
60
|
+
let className = otherAttrs.className;
|
|
61
|
+
className += ` ${otherAttrs.class}`;
|
|
62
|
+
otherAttrs.className = className;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
otherAttrs.className = otherAttrs.class;
|
|
66
|
+
}
|
|
67
|
+
delete otherAttrs.class;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.addClassName = addClassName;
|
|
@@ -13,7 +13,7 @@ import { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
14
|
import React from 'react';
|
|
15
15
|
import ReactDOMServer from 'react-dom/server';
|
|
16
|
-
import { convertAttributesToReactProps } from '../utils';
|
|
16
|
+
import { addClassName, convertAttributesToReactProps } from '../utils';
|
|
17
17
|
const getEditableWrapper = (editableMarkup, ...otherProps) => (
|
|
18
18
|
// create an inline wrapper and use dangerouslySetInnerHTML.
|
|
19
19
|
// if we try to parse the EE value, the parser will strip invalid or disallowed attributes from html elements - and EE uses several
|
|
@@ -23,6 +23,7 @@ const getImageAttrs = (_a, imageParams, mediaUrlPrefix) => {
|
|
|
23
23
|
if (!src) {
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
|
+
addClassName(otherAttrs);
|
|
26
27
|
const newAttrs = Object.assign({}, otherAttrs);
|
|
27
28
|
// update image URL for jss handler and image rendering params
|
|
28
29
|
const resolvedSrc = mediaApi.updateImageUrl(src, imageParams, mediaUrlPrefix);
|
|
@@ -34,6 +35,30 @@ const getImageAttrs = (_a, imageParams, mediaUrlPrefix) => {
|
|
|
34
35
|
newAttrs.src = resolvedSrc;
|
|
35
36
|
return newAttrs;
|
|
36
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* @param imageField {ImageField} provides the dynamicMedia which is used to render the image
|
|
40
|
+
* @param imageParams {ImageProp['imageParams']}} provides the image parameters that will be attached to the image URL
|
|
41
|
+
* @param mediaUrlPrefix {RegExp} the url prefix regex used in the mediaApi
|
|
42
|
+
* @param otherProps {ImageProps} all other props included on the image component
|
|
43
|
+
* @returns Experience Editor Markup
|
|
44
|
+
*/
|
|
45
|
+
export const getEEMarkup = (imageField, imageParams, mediaUrlPrefix, otherProps) => {
|
|
46
|
+
// we likely have an experience editor value, should be a string
|
|
47
|
+
const foundImg = mediaApi.findEditorImageTag(imageField.editable);
|
|
48
|
+
if (!foundImg) {
|
|
49
|
+
return getEditableWrapper(imageField.editable);
|
|
50
|
+
}
|
|
51
|
+
const foundImgProps = convertAttributesToReactProps(foundImg.attrs);
|
|
52
|
+
// Note: otherProps may override values from foundImgProps, e.g. `style`, `className` prop
|
|
53
|
+
// We do not attempt to merge.
|
|
54
|
+
const imgAttrs = getImageAttrs(Object.assign(Object.assign({}, foundImgProps), otherProps), imageParams, mediaUrlPrefix);
|
|
55
|
+
if (!imgAttrs) {
|
|
56
|
+
return getEditableWrapper(imageField.editable);
|
|
57
|
+
}
|
|
58
|
+
const imgHtml = ReactDOMServer.renderToStaticMarkup(React.createElement("img", Object.assign({}, imgAttrs)));
|
|
59
|
+
const editableMarkup = imageField.editable.replace(foundImg.imgTag, imgHtml);
|
|
60
|
+
return getEditableWrapper(editableMarkup);
|
|
61
|
+
};
|
|
37
62
|
export const Image = (_a) => {
|
|
38
63
|
var { media, editable, imageParams, field, mediaUrlPrefix } = _a, otherProps = __rest(_a, ["media", "editable", "imageParams", "field", "mediaUrlPrefix"]);
|
|
39
64
|
// allows the mistake of using 'field' prop instead of 'media' (consistent with other helpers)
|
|
@@ -46,22 +71,8 @@ export const Image = (_a) => {
|
|
|
46
71
|
return null;
|
|
47
72
|
}
|
|
48
73
|
const imageField = dynamicMedia;
|
|
49
|
-
// we likely have an experience editor value, should be a string
|
|
50
74
|
if (editable && imageField.editable) {
|
|
51
|
-
|
|
52
|
-
if (!foundImg) {
|
|
53
|
-
return getEditableWrapper(imageField.editable);
|
|
54
|
-
}
|
|
55
|
-
const foundImgProps = convertAttributesToReactProps(foundImg.attrs);
|
|
56
|
-
// Note: otherProps may override values from foundImgProps, e.g. `style`, `className` prop
|
|
57
|
-
// We do not attempt to merge.
|
|
58
|
-
const imgAttrs = getImageAttrs(Object.assign(Object.assign({}, foundImgProps), otherProps), imageParams, mediaUrlPrefix);
|
|
59
|
-
if (!imgAttrs) {
|
|
60
|
-
return getEditableWrapper(imageField.editable);
|
|
61
|
-
}
|
|
62
|
-
const imgHtml = ReactDOMServer.renderToStaticMarkup(React.createElement("img", Object.assign({}, imgAttrs)));
|
|
63
|
-
const editableMarkup = imageField.editable.replace(foundImg.imgTag, imgHtml);
|
|
64
|
-
return getEditableWrapper(editableMarkup);
|
|
75
|
+
return getEEMarkup(imageField, imageParams, mediaUrlPrefix, otherProps);
|
|
65
76
|
}
|
|
66
77
|
// some wise-guy/gal is passing in a 'raw' image object value
|
|
67
78
|
const img = dynamicMedia.src
|
|
@@ -11,9 +11,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
|
-
import { MissingComponent } from '
|
|
14
|
+
import { MissingComponent } from './MissingComponent';
|
|
15
15
|
import { convertAttributesToReactProps } from '../utils';
|
|
16
16
|
import { HiddenRendering, HIDDEN_RENDERING_NAME } from './HiddenRendering';
|
|
17
|
+
/** [SXA] common marker by which we find container fo replacing **/
|
|
18
|
+
const PREFIX_PLACEHOLDER = 'container-{*}';
|
|
17
19
|
export class PlaceholderCommon extends React.Component {
|
|
18
20
|
constructor(props) {
|
|
19
21
|
super(props);
|
|
@@ -25,6 +27,12 @@ export class PlaceholderCommon extends React.Component {
|
|
|
25
27
|
}
|
|
26
28
|
static getPlaceholderDataFromRenderingData(rendering, name) {
|
|
27
29
|
let result;
|
|
30
|
+
/** [SXA] it needs for deleting dynamics placeholder when we set him number(props.name) of container.
|
|
31
|
+
from backend side we get common name of placeholder is called 'container-{*}' where '{*}' marker for replacing **/
|
|
32
|
+
if (rendering && rendering.placeholders && rendering.placeholders[PREFIX_PLACEHOLDER]) {
|
|
33
|
+
rendering.placeholders[name] = rendering.placeholders[PREFIX_PLACEHOLDER];
|
|
34
|
+
delete rendering.placeholders[PREFIX_PLACEHOLDER];
|
|
35
|
+
}
|
|
28
36
|
if (rendering && rendering.placeholders && Object.keys(rendering.placeholders).length > 0) {
|
|
29
37
|
result = rendering.placeholders[name];
|
|
30
38
|
}
|
|
@@ -46,6 +54,11 @@ export class PlaceholderCommon extends React.Component {
|
|
|
46
54
|
componentDidCatch(error) {
|
|
47
55
|
this.setState({ error });
|
|
48
56
|
}
|
|
57
|
+
getSXAParams(rendering) {
|
|
58
|
+
return (rendering.params.FieldNames && {
|
|
59
|
+
styles: `${rendering.params.GridParameters || ''} ${rendering.params.Styles || ''}`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
49
62
|
getComponentsForRenderingData(placeholderData) {
|
|
50
63
|
const _a = this.props, { name, fields: placeholderFields, params: placeholderParams, missingComponentComponent, hiddenRenderingComponent } = _a, placeholderProps = __rest(_a, ["name", "fields", "params", "missingComponentComponent", "hiddenRenderingComponent"]);
|
|
51
64
|
return placeholderData
|
|
@@ -74,18 +87,23 @@ export class PlaceholderCommon extends React.Component {
|
|
|
74
87
|
const finalProps = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, commonProps), placeholderProps), ((placeholderFields || componentRendering.fields) && {
|
|
75
88
|
fields: Object.assign(Object.assign({}, placeholderFields), componentRendering.fields),
|
|
76
89
|
})), ((placeholderParams || componentRendering.params) && {
|
|
77
|
-
params: Object.assign(Object.assign({}, placeholderParams), componentRendering.params),
|
|
90
|
+
params: Object.assign(Object.assign(Object.assign({}, placeholderParams), componentRendering.params), this.getSXAParams(componentRendering)),
|
|
78
91
|
})), { rendering: componentRendering });
|
|
79
92
|
return React.createElement(component, this.props.modifyComponentProps ? this.props.modifyComponentProps(finalProps) : finalProps);
|
|
80
93
|
})
|
|
81
94
|
.filter((element) => element); // remove nulls
|
|
82
95
|
}
|
|
83
96
|
getComponentForRendering(renderingDefinition) {
|
|
97
|
+
var _a;
|
|
84
98
|
const componentFactory = this.props.componentFactory;
|
|
85
99
|
if (!componentFactory || typeof componentFactory !== 'function') {
|
|
86
100
|
console.warn(`No componentFactory was available to service request for component ${renderingDefinition}`);
|
|
87
101
|
return null;
|
|
88
102
|
}
|
|
103
|
+
// Render SXA Rendering Variant
|
|
104
|
+
if ((_a = renderingDefinition.params) === null || _a === void 0 ? void 0 : _a.FieldNames) {
|
|
105
|
+
return componentFactory(renderingDefinition.componentName, renderingDefinition.params.FieldNames);
|
|
106
|
+
}
|
|
89
107
|
return componentFactory(renderingDefinition.componentName);
|
|
90
108
|
}
|
|
91
109
|
addRef(nodeRef) {
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ComponentFactoryReactContext } from '../components/SitecoreContext';
|
|
3
|
+
import { useContext } from 'react';
|
|
3
4
|
/**
|
|
4
5
|
* @param {React.ComponentClass<T> | React.SFC<T>} Component
|
|
5
6
|
*/
|
|
6
7
|
export function withComponentFactory(Component) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
10
20
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { trackingApi, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
|
5
5
|
export { GraphQLDictionaryService, RestDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
6
6
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
7
7
|
export { Placeholder } from './components/Placeholder';
|
|
8
|
-
export { Image } from './components/Image';
|
|
8
|
+
export { Image, getEEMarkup } from './components/Image';
|
|
9
9
|
export { RichText, RichTextPropTypes } from './components/RichText';
|
|
10
10
|
export { Text } from './components/Text';
|
|
11
11
|
export { DateField } from './components/Date';
|
package/dist/esm/utils.js
CHANGED
|
@@ -42,3 +42,22 @@ export const convertAttributesToReactProps = (attributes) => {
|
|
|
42
42
|
return result;
|
|
43
43
|
}, {});
|
|
44
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* "class" property will be transformed into or appended to "className" instead.
|
|
47
|
+
* @param {string} otherAttrs all other props included on the image component
|
|
48
|
+
* * @returns {void}
|
|
49
|
+
*/
|
|
50
|
+
export const addClassName = (otherAttrs) => {
|
|
51
|
+
if (otherAttrs.class) {
|
|
52
|
+
// if any classes are defined properly already
|
|
53
|
+
if (otherAttrs.className) {
|
|
54
|
+
let className = otherAttrs.className;
|
|
55
|
+
className += ` ${otherAttrs.class}`;
|
|
56
|
+
otherAttrs.className = className;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
otherAttrs.className = otherAttrs.class;
|
|
60
|
+
}
|
|
61
|
+
delete otherAttrs.class;
|
|
62
|
+
}
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-react",
|
|
3
|
-
"version": "20.0.2",
|
|
3
|
+
"version": "20.1.0-canary.2",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -61,12 +61,12 @@
|
|
|
61
61
|
"react-dom": "^17.0.2"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@sitecore-jss/sitecore-jss": "^20.0.2",
|
|
64
|
+
"@sitecore-jss/sitecore-jss": "^20.1.0-canary.2",
|
|
65
65
|
"deep-equal": "^2.0.5",
|
|
66
66
|
"prop-types": "^15.7.2",
|
|
67
67
|
"style-attr": "^1.3.0"
|
|
68
68
|
},
|
|
69
69
|
"description": "",
|
|
70
70
|
"types": "types/index.d.ts",
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "fba4497292298d24067efc25dddc1a144ccd59df"
|
|
72
72
|
}
|
package/tsconfig-esm.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "es6",
|
|
5
|
-
"outDir": "dist/esm"
|
|
6
|
-
},
|
|
7
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "es6",
|
|
5
|
+
"outDir": "dist/esm"
|
|
6
|
+
},
|
|
7
|
+
}
|
|
@@ -55,4 +55,12 @@ export interface ImageProps {
|
|
|
55
55
|
*/
|
|
56
56
|
mediaUrlPrefix?: RegExp;
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* @param imageField {ImageField} provides the dynamicMedia which is used to render the image
|
|
60
|
+
* @param imageParams {ImageProp['imageParams']}} provides the image parameters that will be attached to the image URL
|
|
61
|
+
* @param mediaUrlPrefix {RegExp} the url prefix regex used in the mediaApi
|
|
62
|
+
* @param otherProps {ImageProps} all other props included on the image component
|
|
63
|
+
* @returns Experience Editor Markup
|
|
64
|
+
*/
|
|
65
|
+
export declare const getEEMarkup: (imageField: ImageField, imageParams?: ImageProps['imageParams'], mediaUrlPrefix?: RegExp, otherProps?: ImageProps) => JSX.Element;
|
|
58
66
|
export declare const Image: React.SFC<ImageProps>;
|
|
@@ -18,4 +18,7 @@ export interface PlaceholderComponentProps extends PlaceholderProps {
|
|
|
18
18
|
*/
|
|
19
19
|
renderEach?: (component: React.ReactNode, index: number) => React.ComponentClass<unknown> | React.SFC<unknown> | React.ReactNode;
|
|
20
20
|
}
|
|
21
|
-
export declare const Placeholder:
|
|
21
|
+
export declare const Placeholder: {
|
|
22
|
+
(props: PlaceholderComponentProps): JSX.Element;
|
|
23
|
+
displayName: string;
|
|
24
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { ComponentType } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { ComponentFactory } from '
|
|
3
|
+
import { ComponentFactory } from './sharedTypes';
|
|
4
4
|
import { ComponentRendering, RouteData, Field, Item, HtmlElementRendering } from '@sitecore-jss/sitecore-jss/layout';
|
|
5
5
|
declare type ErrorComponentProps = {
|
|
6
6
|
[prop: string]: unknown;
|
|
7
7
|
};
|
|
8
8
|
/** Provided for the component which represents rendering data */
|
|
9
|
-
declare type ComponentProps = {
|
|
9
|
+
export declare type ComponentProps = {
|
|
10
10
|
[key: string]: unknown;
|
|
11
11
|
rendering: ComponentRendering;
|
|
12
12
|
};
|
|
@@ -80,12 +80,13 @@ export declare class PlaceholderCommon<T extends PlaceholderProps> extends React
|
|
|
80
80
|
componentDidMount(): void;
|
|
81
81
|
componentDidUpdate(): void;
|
|
82
82
|
componentDidCatch(error: Error): void;
|
|
83
|
+
getSXAParams(rendering: ComponentRendering): {
|
|
84
|
+
styles: string;
|
|
85
|
+
};
|
|
83
86
|
getComponentsForRenderingData(placeholderData: (ComponentRendering | HtmlElementRendering)[]): React.ReactElement<{
|
|
84
87
|
[attr: string]: unknown;
|
|
85
88
|
}, string | React.JSXElementConstructor<any>>[];
|
|
86
|
-
getComponentForRendering(renderingDefinition:
|
|
87
|
-
componentName: string;
|
|
88
|
-
}): ComponentType | null;
|
|
89
|
+
getComponentForRendering(renderingDefinition: ComponentRendering): ComponentType | null;
|
|
89
90
|
addRef(nodeRef: Element): void;
|
|
90
91
|
createRawElement(elem: HtmlElementRendering, baseProps: {
|
|
91
92
|
key?: string;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
|
-
|
|
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 declare type ComponentFactory = (componentName: string, exportName?: string) => ComponentType | null;
|
|
@@ -6,4 +6,7 @@ export interface ComponentFactoryProps {
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {React.ComponentClass<T> | React.SFC<T>} Component
|
|
8
8
|
*/
|
|
9
|
-
export declare function withComponentFactory<T extends ComponentFactoryProps>(Component: React.ComponentClass<T> | React.SFC<T>):
|
|
9
|
+
export declare function withComponentFactory<T extends ComponentFactoryProps>(Component: React.ComponentClass<T> | React.SFC<T>): {
|
|
10
|
+
(props: T): JSX.Element;
|
|
11
|
+
displayName: string;
|
|
12
|
+
};
|
|
@@ -31,4 +31,7 @@ export declare type WithPlaceholderSpec = (string | PlaceholderToPropMapping) |
|
|
|
31
31
|
* @param {WithPlaceholderSpec} placeholders
|
|
32
32
|
* @param {WithPlaceholderOptions} [options]
|
|
33
33
|
*/
|
|
34
|
-
export declare function withPlaceholder(placeholders: WithPlaceholderSpec, options?: WithPlaceholderOptions): (WrappedComponent: React.ComponentClass<PlaceholderProps> | React.FunctionComponent<PlaceholderProps>) =>
|
|
34
|
+
export declare function withPlaceholder(placeholders: WithPlaceholderSpec, options?: WithPlaceholderOptions): (WrappedComponent: React.ComponentClass<PlaceholderProps> | React.FunctionComponent<PlaceholderProps>) => {
|
|
35
|
+
(props: PlaceholderProps): JSX.Element;
|
|
36
|
+
displayName: string;
|
|
37
|
+
};
|
package/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, RestDic
|
|
|
6
6
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
7
7
|
export { ComponentFactory } from './components/sharedTypes';
|
|
8
8
|
export { Placeholder, PlaceholderComponentProps } from './components/Placeholder';
|
|
9
|
-
export { Image, ImageField } from './components/Image';
|
|
9
|
+
export { Image, ImageProps, ImageField, getEEMarkup, ImageFieldValue } from './components/Image';
|
|
10
10
|
export { RichText, RichTextProps, RichTextPropTypes, RichTextField } from './components/RichText';
|
|
11
11
|
export { Text, TextField } from './components/Text';
|
|
12
12
|
export { DateField } from './components/Date';
|
package/types/utils.d.ts
CHANGED
|
@@ -15,3 +15,11 @@ export declare const convertAttributesToReactProps: (attributes: {
|
|
|
15
15
|
}) => [] | {
|
|
16
16
|
[attr: string]: unknown;
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* "class" property will be transformed into or appended to "className" instead.
|
|
20
|
+
* @param {string} otherAttrs all other props included on the image component
|
|
21
|
+
* * @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
export declare const addClassName: (otherAttrs: {
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}) => void;
|