@sitecore-jss/sitecore-jss-react 21.0.0-canary.13 → 21.0.0-canary.130
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/File.js +0 -1
- package/dist/cjs/components/Image.js +28 -16
- package/dist/cjs/components/Link.js +34 -12
- package/dist/cjs/components/Placeholder.js +1 -0
- package/dist/cjs/components/PlaceholderCommon.js +9 -1
- package/dist/cjs/components/VisitorIdentification.js +3 -2
- package/dist/cjs/enhancers/withComponentFactory.js +14 -4
- package/dist/cjs/enhancers/withEditorChromes.js +1 -5
- package/dist/cjs/enhancers/withSitecoreContext.js +1 -1
- package/dist/cjs/index.js +3 -4
- package/dist/cjs/utils.js +21 -1
- package/dist/esm/components/File.js +0 -1
- package/dist/esm/components/Image.js +27 -16
- package/dist/esm/components/Link.js +15 -11
- package/dist/esm/components/Placeholder.js +1 -0
- package/dist/esm/components/PlaceholderCommon.js +9 -1
- package/dist/esm/components/VisitorIdentification.js +4 -3
- package/dist/esm/enhancers/withComponentFactory.js +14 -4
- package/dist/esm/enhancers/withEditorChromes.js +0 -4
- package/dist/esm/enhancers/withSitecoreContext.js +1 -1
- package/dist/esm/index.js +5 -5
- package/dist/esm/utils.js +19 -0
- package/package.json +21 -16
- package/types/components/Date.d.ts +2 -2
- package/types/components/File.d.ts +1 -1
- package/types/components/HiddenRendering.d.ts +0 -1
- package/types/components/Image.d.ts +9 -1
- package/types/components/Link.d.ts +2 -3
- package/types/components/Placeholder.d.ts +7 -4
- package/types/components/PlaceholderCommon.d.ts +3 -3
- package/types/components/RichText.d.ts +1 -1
- package/types/components/SitecoreContext.d.ts +1 -0
- package/types/components/VisitorIdentification.d.ts +2 -7
- package/types/enhancers/withComponentFactory.d.ts +5 -2
- package/types/enhancers/withEditorChromes.d.ts +1 -5
- package/types/enhancers/withPlaceholder.d.ts +4 -1
- package/types/enhancers/withSitecoreContext.d.ts +1 -1
- package/types/index.d.ts +5 -5
- package/types/utils.d.ts +8 -0
- package/.nyc_output/84263055-6f17-48fd-b090-fef90621d6dc.json +0 -1
- package/.nyc_output/94112157-a977-441b-b88d-8803367ea6e2.json +0 -1
- package/.nyc_output/a241a342-2ff7-4f26-80d5-9349ad56bdc2.json +0 -1
- package/.nyc_output/processinfo/84263055-6f17-48fd-b090-fef90621d6dc.json +0 -1
- package/.nyc_output/processinfo/94112157-a977-441b-b88d-8803367ea6e2.json +0 -1
- package/.nyc_output/processinfo/a241a342-2ff7-4f26-80d5-9349ad56bdc2.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/coverage/coverage-summary.json +0 -21
- package/global.d.ts +0 -17
- package/tsconfig-esm.json +0 -7
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Image = void 0;
|
|
17
|
+
exports.Image = exports.getEEMarkup = void 0;
|
|
18
18
|
const media_1 = require("@sitecore-jss/sitecore-jss/media");
|
|
19
19
|
const prop_types_1 = __importDefault(require("prop-types"));
|
|
20
20
|
const react_1 = __importDefault(require("react"));
|
|
@@ -29,6 +29,7 @@ const getImageAttrs = (_a, imageParams, mediaUrlPrefix) => {
|
|
|
29
29
|
if (!src) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
+
utils_1.addClassName(otherAttrs);
|
|
32
33
|
const newAttrs = Object.assign({}, otherAttrs);
|
|
33
34
|
// update image URL for jss handler and image rendering params
|
|
34
35
|
const resolvedSrc = media_1.mediaApi.updateImageUrl(src, imageParams, mediaUrlPrefix);
|
|
@@ -40,6 +41,31 @@ const getImageAttrs = (_a, imageParams, mediaUrlPrefix) => {
|
|
|
40
41
|
newAttrs.src = resolvedSrc;
|
|
41
42
|
return newAttrs;
|
|
42
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* @param {ImageField} imageField {ImageField} provides the dynamicMedia which is used to render the image
|
|
46
|
+
* @param {ImageProps['imageParams']} imageParams {ImageProp['imageParams']}} provides the image parameters that will be attached to the image URL
|
|
47
|
+
* @param {RegExp} mediaUrlPrefix {RegExp} the url prefix regex used in the mediaApi
|
|
48
|
+
* @param {ImageProps} otherProps {ImageProps} all other props included on the image component
|
|
49
|
+
* @returns Experience Editor Markup
|
|
50
|
+
*/
|
|
51
|
+
const getEEMarkup = (imageField, imageParams, mediaUrlPrefix, otherProps) => {
|
|
52
|
+
// we likely have an experience editor value, should be a string
|
|
53
|
+
const foundImg = media_1.mediaApi.findEditorImageTag(imageField.editable);
|
|
54
|
+
if (!foundImg) {
|
|
55
|
+
return getEditableWrapper(imageField.editable);
|
|
56
|
+
}
|
|
57
|
+
const foundImgProps = utils_1.convertAttributesToReactProps(foundImg.attrs);
|
|
58
|
+
// Note: otherProps may override values from foundImgProps, e.g. `style`, `className` prop
|
|
59
|
+
// We do not attempt to merge.
|
|
60
|
+
const imgAttrs = getImageAttrs(Object.assign(Object.assign({}, foundImgProps), otherProps), imageParams, mediaUrlPrefix);
|
|
61
|
+
if (!imgAttrs) {
|
|
62
|
+
return getEditableWrapper(imageField.editable);
|
|
63
|
+
}
|
|
64
|
+
const imgHtml = server_1.default.renderToStaticMarkup(react_1.default.createElement("img", Object.assign({}, imgAttrs)));
|
|
65
|
+
const editableMarkup = imageField.editable.replace(foundImg.imgTag, imgHtml);
|
|
66
|
+
return getEditableWrapper(editableMarkup);
|
|
67
|
+
};
|
|
68
|
+
exports.getEEMarkup = getEEMarkup;
|
|
43
69
|
const Image = (_a) => {
|
|
44
70
|
var { media, editable, imageParams, field, mediaUrlPrefix } = _a, otherProps = __rest(_a, ["media", "editable", "imageParams", "field", "mediaUrlPrefix"]);
|
|
45
71
|
// allows the mistake of using 'field' prop instead of 'media' (consistent with other helpers)
|
|
@@ -52,22 +78,8 @@ const Image = (_a) => {
|
|
|
52
78
|
return null;
|
|
53
79
|
}
|
|
54
80
|
const imageField = dynamicMedia;
|
|
55
|
-
// we likely have an experience editor value, should be a string
|
|
56
81
|
if (editable && imageField.editable) {
|
|
57
|
-
|
|
58
|
-
if (!foundImg) {
|
|
59
|
-
return getEditableWrapper(imageField.editable);
|
|
60
|
-
}
|
|
61
|
-
const foundImgProps = utils_1.convertAttributesToReactProps(foundImg.attrs);
|
|
62
|
-
// Note: otherProps may override values from foundImgProps, e.g. `style`, `className` prop
|
|
63
|
-
// We do not attempt to merge.
|
|
64
|
-
const imgAttrs = getImageAttrs(Object.assign(Object.assign({}, foundImgProps), otherProps), imageParams, mediaUrlPrefix);
|
|
65
|
-
if (!imgAttrs) {
|
|
66
|
-
return getEditableWrapper(imageField.editable);
|
|
67
|
-
}
|
|
68
|
-
const imgHtml = server_1.default.renderToStaticMarkup(react_1.default.createElement("img", Object.assign({}, imgAttrs)));
|
|
69
|
-
const editableMarkup = imageField.editable.replace(foundImg.imgTag, imgHtml);
|
|
70
|
-
return getEditableWrapper(editableMarkup);
|
|
82
|
+
return exports.getEEMarkup(imageField, imageParams, mediaUrlPrefix, otherProps);
|
|
71
83
|
}
|
|
72
84
|
// some wise-guy/gal is passing in a 'raw' image object value
|
|
73
85
|
const img = dynamicMedia.src
|
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
22
|
var t = {};
|
|
4
23
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -15,10 +34,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
34
|
};
|
|
16
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
36
|
exports.LinkPropTypes = exports.Link = void 0;
|
|
18
|
-
const react_1 =
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
19
38
|
const prop_types_1 = __importDefault(require("prop-types"));
|
|
20
|
-
const
|
|
21
|
-
|
|
39
|
+
const html_react_parser_1 = __importDefault(require("html-react-parser"));
|
|
40
|
+
exports.Link = react_1.forwardRef((_a, ref) => {
|
|
41
|
+
var { field, editable, showLinkTextWithChildrenPresent } = _a, otherProps = __rest(_a, ["field", "editable", "showLinkTextWithChildrenPresent"]);
|
|
42
|
+
const children = otherProps.children;
|
|
22
43
|
const dynamicField = field;
|
|
23
44
|
if (!field ||
|
|
24
45
|
(!dynamicField.editableFirstPart &&
|
|
@@ -34,10 +55,13 @@ const Link = (_a) => {
|
|
|
34
55
|
// However, we cannot combine arbitrary unparsed HTML (innerHTML) based components with actual vDOM components (the children)
|
|
35
56
|
// because the innerHTML is not parsed - it'd make a discontinuous vDOM. So, we'll go for the next best compromise of rendering the link field and children separately
|
|
36
57
|
// as siblings. Should be "good enough" for most cases - and write your own helper if it isn't. Or bring xEditor out of 2006.
|
|
37
|
-
const htmlProps = Object.assign(Object.assign({ className: 'sc-link-wrapper',
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
58
|
+
const htmlProps = Object.assign(Object.assign({ className: 'sc-link-wrapper' }, otherProps), { key: 'editable' });
|
|
59
|
+
const components = html_react_parser_1.default(markup, {
|
|
60
|
+
htmlparser2: {
|
|
61
|
+
lowerCaseTags: false,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
resultTags.push(react_1.default.createElement("span", Object.assign({}, htmlProps), components));
|
|
41
65
|
// don't render normal link tag when editing, if no children exist
|
|
42
66
|
// this preserves normal-ish behavior if not using a link body (no hacks required)
|
|
43
67
|
if (!children) {
|
|
@@ -62,14 +86,13 @@ const Link = (_a) => {
|
|
|
62
86
|
anchorAttrs.rel = 'noopener noreferrer';
|
|
63
87
|
}
|
|
64
88
|
const linkText = showLinkTextWithChildrenPresent || !children ? link.text || link.href : null;
|
|
65
|
-
resultTags.push(react_1.default.createElement('a', Object.assign(Object.assign(Object.assign({}, anchorAttrs), otherProps), { key: 'link' }), linkText, children));
|
|
89
|
+
resultTags.push(react_1.default.createElement('a', Object.assign(Object.assign(Object.assign({}, anchorAttrs), otherProps), { key: 'link', ref }), linkText, children));
|
|
66
90
|
return react_1.default.createElement(react_1.default.Fragment, null, resultTags);
|
|
67
|
-
};
|
|
68
|
-
exports.Link = Link;
|
|
91
|
+
});
|
|
69
92
|
exports.LinkPropTypes = {
|
|
70
93
|
field: prop_types_1.default.oneOfType([
|
|
71
94
|
prop_types_1.default.shape({
|
|
72
|
-
href: prop_types_1.default.string,
|
|
95
|
+
href: prop_types_1.default.oneOfType([prop_types_1.default.string.isRequired, prop_types_1.default.oneOf([null]).isRequired]),
|
|
73
96
|
}),
|
|
74
97
|
prop_types_1.default.shape({
|
|
75
98
|
value: prop_types_1.default.object,
|
|
@@ -78,7 +101,6 @@ exports.LinkPropTypes = {
|
|
|
78
101
|
}),
|
|
79
102
|
]).isRequired,
|
|
80
103
|
editable: prop_types_1.default.bool,
|
|
81
|
-
children: prop_types_1.default.node,
|
|
82
104
|
showLinkTextWithChildrenPresent: prop_types_1.default.bool,
|
|
83
105
|
};
|
|
84
106
|
exports.Link.propTypes = exports.LinkPropTypes;
|
|
@@ -21,6 +21,7 @@ class PlaceholderComponent extends PlaceholderCommon_1.PlaceholderCommon {
|
|
|
21
21
|
this.isEmpty = false;
|
|
22
22
|
}
|
|
23
23
|
componentDidMount() {
|
|
24
|
+
super.componentDidMount();
|
|
24
25
|
if (this.isEmpty && utils_1.HorizonEditor.isActive()) {
|
|
25
26
|
utils_1.HorizonEditor.resetChromes();
|
|
26
27
|
}
|
|
@@ -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
|
}
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VisitorIdentification = void 0;
|
|
4
4
|
const withSitecoreContext_1 = require("../enhancers/withSitecoreContext");
|
|
5
5
|
let emittedVI = false;
|
|
6
|
-
const VIComponent = (
|
|
6
|
+
const VIComponent = () => {
|
|
7
|
+
const { sitecoreContext } = withSitecoreContext_1.useSitecoreContext();
|
|
7
8
|
if (emittedVI ||
|
|
8
9
|
typeof document === 'undefined' ||
|
|
9
10
|
!sitecoreContext.visitorIdentificationTimestamp) {
|
|
@@ -24,4 +25,4 @@ const VIComponent = ({ sitecoreContext }) => {
|
|
|
24
25
|
return null;
|
|
25
26
|
};
|
|
26
27
|
VIComponent.displayName = 'VisitorIdentification';
|
|
27
|
-
exports.VisitorIdentification =
|
|
28
|
+
exports.VisitorIdentification = VIComponent;
|
|
@@ -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
|
-
* @param {React.ComponentClass<T> | React.
|
|
11
|
+
* @param {React.ComponentClass<T> | React.FC<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;
|
|
@@ -3,7 +3,7 @@ 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.withEditorChromes = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const __1 = require("..");
|
|
9
9
|
const withEditorChromes = (WrappedComponent) => {
|
|
@@ -22,7 +22,3 @@ const withEditorChromes = (WrappedComponent) => {
|
|
|
22
22
|
return Enhancer;
|
|
23
23
|
};
|
|
24
24
|
exports.withEditorChromes = withEditorChromes;
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated Will be removed in a future release. Please use withEditorChromes instead.
|
|
27
|
-
*/
|
|
28
|
-
exports.withExperienceEditorChromes = exports.withEditorChromes;
|
|
@@ -18,7 +18,7 @@ function withSitecoreContext(options) {
|
|
|
18
18
|
}
|
|
19
19
|
exports.withSitecoreContext = withSitecoreContext;
|
|
20
20
|
/**
|
|
21
|
-
* This hook grants acсess to the current
|
|
21
|
+
* This hook grants acсess to the current Sitecore page context
|
|
22
22
|
* by default JSS includes the following properties in this context:
|
|
23
23
|
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Experience Editor.
|
|
24
24
|
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withDatasourceCheck = exports.withPlaceholder = exports.
|
|
3
|
+
exports.withDatasourceCheck = exports.withPlaceholder = 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.enableDebug = 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
|
+
Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return sitecore_jss_1.enableDebug; } });
|
|
6
7
|
var utils_1 = require("@sitecore-jss/sitecore-jss/utils");
|
|
7
|
-
Object.defineProperty(exports, "isExperienceEditorActive", { enumerable: true, get: function () { return utils_1.isExperienceEditorActive; } });
|
|
8
|
-
Object.defineProperty(exports, "resetExperienceEditorChromes", { enumerable: true, get: function () { return utils_1.resetExperienceEditorChromes; } });
|
|
9
8
|
Object.defineProperty(exports, "isEditorActive", { enumerable: true, get: function () { return utils_1.isEditorActive; } });
|
|
10
9
|
Object.defineProperty(exports, "resetEditorChromes", { enumerable: true, get: function () { return utils_1.resetEditorChromes; } });
|
|
11
10
|
var layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
@@ -25,6 +24,7 @@ var Placeholder_1 = require("./components/Placeholder");
|
|
|
25
24
|
Object.defineProperty(exports, "Placeholder", { enumerable: true, get: function () { return Placeholder_1.Placeholder; } });
|
|
26
25
|
var Image_1 = require("./components/Image");
|
|
27
26
|
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return Image_1.Image; } });
|
|
27
|
+
Object.defineProperty(exports, "getEEMarkup", { enumerable: true, get: function () { return Image_1.getEEMarkup; } });
|
|
28
28
|
var RichText_1 = require("./components/RichText");
|
|
29
29
|
Object.defineProperty(exports, "RichText", { enumerable: true, get: function () { return RichText_1.RichText; } });
|
|
30
30
|
Object.defineProperty(exports, "RichTextPropTypes", { enumerable: true, get: function () { return RichText_1.RichTextPropTypes; } });
|
|
@@ -47,7 +47,6 @@ Object.defineProperty(exports, "withSitecoreContext", { enumerable: true, get: f
|
|
|
47
47
|
Object.defineProperty(exports, "useSitecoreContext", { enumerable: true, get: function () { return withSitecoreContext_1.useSitecoreContext; } });
|
|
48
48
|
var withEditorChromes_1 = require("./enhancers/withEditorChromes");
|
|
49
49
|
Object.defineProperty(exports, "withEditorChromes", { enumerable: true, get: function () { return withEditorChromes_1.withEditorChromes; } });
|
|
50
|
-
Object.defineProperty(exports, "withExperienceEditorChromes", { enumerable: true, get: function () { return withEditorChromes_1.withExperienceEditorChromes; } });
|
|
51
50
|
var withPlaceholder_1 = require("./enhancers/withPlaceholder");
|
|
52
51
|
Object.defineProperty(exports, "withPlaceholder", { enumerable: true, get: function () { return withPlaceholder_1.withPlaceholder; } });
|
|
53
52
|
var withDatasourceCheck_1 = require("./enhancers/withDatasourceCheck");
|
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 {ImageField} provides the dynamicMedia which is used to render the image
|
|
40
|
+
* @param {ImageProps['imageParams']} imageParams {ImageProp['imageParams']}} provides the image parameters that will be attached to the image URL
|
|
41
|
+
* @param {RegExp} mediaUrlPrefix {RegExp} the url prefix regex used in the mediaApi
|
|
42
|
+
* @param {ImageProps} 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
|
|
@@ -9,10 +9,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React from 'react';
|
|
12
|
+
import React, { forwardRef } from 'react';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
import parse from 'html-react-parser';
|
|
15
|
+
export const Link = forwardRef((_a, ref) => {
|
|
16
|
+
var { field, editable, showLinkTextWithChildrenPresent } = _a, otherProps = __rest(_a, ["field", "editable", "showLinkTextWithChildrenPresent"]);
|
|
17
|
+
const children = otherProps.children;
|
|
16
18
|
const dynamicField = field;
|
|
17
19
|
if (!field ||
|
|
18
20
|
(!dynamicField.editableFirstPart &&
|
|
@@ -28,10 +30,13 @@ export const Link = (_a) => {
|
|
|
28
30
|
// However, we cannot combine arbitrary unparsed HTML (innerHTML) based components with actual vDOM components (the children)
|
|
29
31
|
// because the innerHTML is not parsed - it'd make a discontinuous vDOM. So, we'll go for the next best compromise of rendering the link field and children separately
|
|
30
32
|
// as siblings. Should be "good enough" for most cases - and write your own helper if it isn't. Or bring xEditor out of 2006.
|
|
31
|
-
const htmlProps = Object.assign(Object.assign({ className: 'sc-link-wrapper',
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const htmlProps = Object.assign(Object.assign({ className: 'sc-link-wrapper' }, otherProps), { key: 'editable' });
|
|
34
|
+
const components = parse(markup, {
|
|
35
|
+
htmlparser2: {
|
|
36
|
+
lowerCaseTags: false,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
resultTags.push(React.createElement("span", Object.assign({}, htmlProps), components));
|
|
35
40
|
// don't render normal link tag when editing, if no children exist
|
|
36
41
|
// this preserves normal-ish behavior if not using a link body (no hacks required)
|
|
37
42
|
if (!children) {
|
|
@@ -56,13 +61,13 @@ export const Link = (_a) => {
|
|
|
56
61
|
anchorAttrs.rel = 'noopener noreferrer';
|
|
57
62
|
}
|
|
58
63
|
const linkText = showLinkTextWithChildrenPresent || !children ? link.text || link.href : null;
|
|
59
|
-
resultTags.push(React.createElement('a', Object.assign(Object.assign(Object.assign({}, anchorAttrs), otherProps), { key: 'link' }), linkText, children));
|
|
64
|
+
resultTags.push(React.createElement('a', Object.assign(Object.assign(Object.assign({}, anchorAttrs), otherProps), { key: 'link', ref }), linkText, children));
|
|
60
65
|
return React.createElement(React.Fragment, null, resultTags);
|
|
61
|
-
};
|
|
66
|
+
});
|
|
62
67
|
export const LinkPropTypes = {
|
|
63
68
|
field: PropTypes.oneOfType([
|
|
64
69
|
PropTypes.shape({
|
|
65
|
-
href: PropTypes.string,
|
|
70
|
+
href: PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.oneOf([null]).isRequired]),
|
|
66
71
|
}),
|
|
67
72
|
PropTypes.shape({
|
|
68
73
|
value: PropTypes.object,
|
|
@@ -71,7 +76,6 @@ export const LinkPropTypes = {
|
|
|
71
76
|
}),
|
|
72
77
|
]).isRequired,
|
|
73
78
|
editable: PropTypes.bool,
|
|
74
|
-
children: PropTypes.node,
|
|
75
79
|
showLinkTextWithChildrenPresent: PropTypes.bool,
|
|
76
80
|
};
|
|
77
81
|
Link.propTypes = LinkPropTypes;
|
|
@@ -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
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useSitecoreContext } from '../enhancers/withSitecoreContext';
|
|
2
2
|
let emittedVI = false;
|
|
3
|
-
const VIComponent = (
|
|
3
|
+
const VIComponent = () => {
|
|
4
|
+
const { sitecoreContext } = useSitecoreContext();
|
|
4
5
|
if (emittedVI ||
|
|
5
6
|
typeof document === 'undefined' ||
|
|
6
7
|
!sitecoreContext.visitorIdentificationTimestamp) {
|
|
@@ -21,4 +22,4 @@ const VIComponent = ({ sitecoreContext }) => {
|
|
|
21
22
|
return null;
|
|
22
23
|
};
|
|
23
24
|
VIComponent.displayName = 'VisitorIdentification';
|
|
24
|
-
export const VisitorIdentification =
|
|
25
|
+
export const VisitorIdentification = VIComponent;
|
|
@@ -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
|
-
* @param {React.ComponentClass<T> | React.
|
|
5
|
+
* @param {React.ComponentClass<T> | React.FC<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
|
}
|
|
@@ -11,7 +11,7 @@ export function withSitecoreContext(options) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* This hook grants acсess to the current
|
|
14
|
+
* This hook grants acсess to the current Sitecore page context
|
|
15
15
|
* by default JSS includes the following properties in this context:
|
|
16
16
|
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Experience Editor.
|
|
17
17
|
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { constants } from '@sitecore-jss/sitecore-jss';
|
|
2
|
-
export {
|
|
1
|
+
export { constants, enableDebug } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
export { isEditorActive, resetEditorChromes } from '@sitecore-jss/sitecore-jss/utils';
|
|
3
3
|
export { LayoutServicePageState, GraphQLLayoutService, RestLayoutService, getChildPlaceholder, getFieldValue, } 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 { 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';
|
|
@@ -13,7 +13,7 @@ export { Link, LinkPropTypes } from './components/Link';
|
|
|
13
13
|
export { File } from './components/File';
|
|
14
14
|
export { VisitorIdentification } from './components/VisitorIdentification';
|
|
15
15
|
export { SitecoreContext, SitecoreContextReactContext, } from './components/SitecoreContext';
|
|
16
|
-
export { withSitecoreContext, useSitecoreContext } from './enhancers/withSitecoreContext';
|
|
17
|
-
export { withEditorChromes
|
|
16
|
+
export { withSitecoreContext, useSitecoreContext, } from './enhancers/withSitecoreContext';
|
|
17
|
+
export { withEditorChromes } from './enhancers/withEditorChromes';
|
|
18
18
|
export { withPlaceholder } from './enhancers/withPlaceholder';
|
|
19
19
|
export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
|
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
|
+
};
|