@sitecore-jss/sitecore-jss-react 21.0.0-canary.99 → 21.0.1

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/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  This module is provided as a part of Sitecore JavaScript Rendering SDK (JSS). It contains React components and integration for JSS.
4
4
 
5
- <!---
6
- @TODO: Update to version 20.0.0 docs before release
7
- -->
8
- [Documentation](https://doc.sitecore.com/xp/en/developers/hd/190/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-react.html)
9
5
 
10
- [API reference documentation](/ref-docs/sitecore-jss-react/).
6
+ [Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/201/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-react.html)
7
+
8
+ [API reference documentation](/ref-docs/sitecore-jss-react/)
@@ -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 = __importDefault(require("react"));
37
+ const react_1 = __importStar(require("react"));
19
38
  const prop_types_1 = __importDefault(require("prop-types"));
20
- const Link = (_a) => {
21
- var { field, editable, children, showLinkTextWithChildrenPresent } = _a, otherProps = __rest(_a, ["field", "editable", "children", "showLinkTextWithChildrenPresent"]);
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', dangerouslySetInnerHTML: {
38
- __html: markup,
39
- } }, otherProps), { key: 'editable' });
40
- resultTags.push(react_1.default.createElement("span", Object.assign({}, htmlProps)));
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,
@@ -50,8 +50,36 @@ class PlaceholderComponent extends PlaceholderCommon_1.PlaceholderCommon {
50
50
  }
51
51
  const renderingData = childProps.rendering;
52
52
  const placeholderData = PlaceholderCommon_1.PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, this.props.name);
53
- const components = this.getComponentsForRenderingData(placeholderData);
54
53
  this.isEmpty = placeholderData.every((rendering) => isRawRendering(rendering));
54
+ // This is a workaround to insert Experience Editor-specific markup on the page for empty placeholders.
55
+ // It makes sure the markup is inserted by react and thus avoiding hydration errors when in editing mode
56
+ if (this.isEmpty && utils_1.ExperienceEditor.isActive()) {
57
+ const codePos = placeholderData.findIndex((component) => component.name === 'code' &&
58
+ component.attributes.kind === 'open');
59
+ const plhId = placeholderData[codePos].attributes.id;
60
+ const emptyPlaceholderMarkup = [
61
+ {
62
+ name: 'span',
63
+ contents: null,
64
+ attributes: {
65
+ type: 'text/sitecore',
66
+ 'sc-part-of': 'placeholder rendering',
67
+ style: 'display: none;',
68
+ },
69
+ },
70
+ {
71
+ name: 'div',
72
+ contents: null,
73
+ attributes: {
74
+ class: 'scEnabledChrome scEmptyPlaceholder',
75
+ 'sc-part-of': 'placeholder',
76
+ 'sc-placeholder-id': plhId,
77
+ },
78
+ },
79
+ ];
80
+ placeholderData.splice(codePos + 1, 0, ...emptyPlaceholderMarkup);
81
+ }
82
+ const components = this.getComponentsForRenderingData(placeholderData);
55
83
  if (this.props.renderEmpty && this.isEmpty) {
56
84
  const rendered = this.props.renderEmpty(components);
57
85
  return components.length ? this.renderEmptyPlaceholder(rendered) : rendered;
@@ -3,7 +3,7 @@ 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 = (props) => {
7
7
  const { sitecoreContext } = withSitecoreContext_1.useSitecoreContext();
8
8
  if (emittedVI ||
9
9
  typeof document === 'undefined' ||
@@ -16,6 +16,7 @@ const VIComponent = () => {
16
16
  const script = document.createElement('script');
17
17
  script.src = '/layouts/system/VisitorIdentification.js';
18
18
  script.type = 'text/javascript';
19
+ script.defer = props.defer;
19
20
  const meta = document.createElement('meta');
20
21
  meta.name = 'VIcurrentDateTime';
21
22
  meta.content = sitecoreContext.visitorIdentificationTimestamp.toString();
@@ -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.FC<T>} Component
11
12
  */
12
13
  function withComponentFactory(Component) {
13
- return function WithComponentFactory(props) {
14
- return (react_1.default.createElement(SitecoreContext_1.ComponentFactoryReactContext.Consumer, null, (context) => react_1.default.createElement(Component, Object.assign({}, props, { componentFactory: props.componentFactory || context }))));
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.withExperienceEditorChromes = exports.withEditorChromes = void 0;
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;
@@ -1,10 +1,26 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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;
4
20
  };
5
21
  Object.defineProperty(exports, "__esModule", { value: true });
6
22
  exports.useSitecoreContext = exports.withSitecoreContext = void 0;
7
- const react_1 = __importDefault(require("react"));
23
+ const react_1 = __importStar(require("react"));
8
24
  const SitecoreContext_1 = require("../components/SitecoreContext");
9
25
  /**
10
26
  * @param {WithSitecoreContextOptions} [options]
@@ -12,7 +28,8 @@ const SitecoreContext_1 = require("../components/SitecoreContext");
12
28
  function withSitecoreContext(options) {
13
29
  return function withSitecoreContextHoc(Component) {
14
30
  return function WithSitecoreContext(props) {
15
- return (react_1.default.createElement(SitecoreContext_1.SitecoreContextReactContext.Consumer, null, (context) => (react_1.default.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, updateSitecoreContext: options && options.updatable && context.setContext })))));
31
+ const context = react_1.useContext(SitecoreContext_1.SitecoreContextReactContext);
32
+ return (react_1.default.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, updateSitecoreContext: options && options.updatable && context.setContext })));
16
33
  };
17
34
  };
18
35
  }
package/dist/cjs/index.js CHANGED
@@ -1,12 +1,10 @@
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.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.enableDebug = exports.constants = void 0;
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
6
  Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return sitecore_jss_1.enableDebug; } });
7
7
  var utils_1 = require("@sitecore-jss/sitecore-jss/utils");
8
- Object.defineProperty(exports, "isExperienceEditorActive", { enumerable: true, get: function () { return utils_1.isExperienceEditorActive; } });
9
- Object.defineProperty(exports, "resetExperienceEditorChromes", { enumerable: true, get: function () { return utils_1.resetExperienceEditorChromes; } });
10
8
  Object.defineProperty(exports, "isEditorActive", { enumerable: true, get: function () { return utils_1.isEditorActive; } });
11
9
  Object.defineProperty(exports, "resetEditorChromes", { enumerable: true, get: function () { return utils_1.resetEditorChromes; } });
12
10
  var layout_1 = require("@sitecore-jss/sitecore-jss/layout");
@@ -49,7 +47,6 @@ Object.defineProperty(exports, "withSitecoreContext", { enumerable: true, get: f
49
47
  Object.defineProperty(exports, "useSitecoreContext", { enumerable: true, get: function () { return withSitecoreContext_1.useSitecoreContext; } });
50
48
  var withEditorChromes_1 = require("./enhancers/withEditorChromes");
51
49
  Object.defineProperty(exports, "withEditorChromes", { enumerable: true, get: function () { return withEditorChromes_1.withEditorChromes; } });
52
- Object.defineProperty(exports, "withExperienceEditorChromes", { enumerable: true, get: function () { return withEditorChromes_1.withExperienceEditorChromes; } });
53
50
  var withPlaceholder_1 = require("./enhancers/withPlaceholder");
54
51
  Object.defineProperty(exports, "withPlaceholder", { enumerable: true, get: function () { return withPlaceholder_1.withPlaceholder; } });
55
52
  var withDatasourceCheck_1 = require("./enhancers/withDatasourceCheck");
@@ -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
- export const Link = (_a) => {
15
- var { field, editable, children, showLinkTextWithChildrenPresent } = _a, otherProps = __rest(_a, ["field", "editable", "children", "showLinkTextWithChildrenPresent"]);
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', dangerouslySetInnerHTML: {
32
- __html: markup,
33
- } }, otherProps), { key: 'editable' });
34
- resultTags.push(React.createElement("span", Object.assign({}, htmlProps)));
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,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { PlaceholderCommon } from './PlaceholderCommon';
3
3
  import { withComponentFactory } from '../enhancers/withComponentFactory';
4
- import { HorizonEditor } from '@sitecore-jss/sitecore-jss/utils';
4
+ import { HorizonEditor, ExperienceEditor } from '@sitecore-jss/sitecore-jss/utils';
5
5
  /**
6
6
  * @param {HtmlElementRendering | ComponentRendering} rendering
7
7
  */
@@ -44,8 +44,36 @@ class PlaceholderComponent extends PlaceholderCommon {
44
44
  }
45
45
  const renderingData = childProps.rendering;
46
46
  const placeholderData = PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, this.props.name);
47
- const components = this.getComponentsForRenderingData(placeholderData);
48
47
  this.isEmpty = placeholderData.every((rendering) => isRawRendering(rendering));
48
+ // This is a workaround to insert Experience Editor-specific markup on the page for empty placeholders.
49
+ // It makes sure the markup is inserted by react and thus avoiding hydration errors when in editing mode
50
+ if (this.isEmpty && ExperienceEditor.isActive()) {
51
+ const codePos = placeholderData.findIndex((component) => component.name === 'code' &&
52
+ component.attributes.kind === 'open');
53
+ const plhId = placeholderData[codePos].attributes.id;
54
+ const emptyPlaceholderMarkup = [
55
+ {
56
+ name: 'span',
57
+ contents: null,
58
+ attributes: {
59
+ type: 'text/sitecore',
60
+ 'sc-part-of': 'placeholder rendering',
61
+ style: 'display: none;',
62
+ },
63
+ },
64
+ {
65
+ name: 'div',
66
+ contents: null,
67
+ attributes: {
68
+ class: 'scEnabledChrome scEmptyPlaceholder',
69
+ 'sc-part-of': 'placeholder',
70
+ 'sc-placeholder-id': plhId,
71
+ },
72
+ },
73
+ ];
74
+ placeholderData.splice(codePos + 1, 0, ...emptyPlaceholderMarkup);
75
+ }
76
+ const components = this.getComponentsForRenderingData(placeholderData);
49
77
  if (this.props.renderEmpty && this.isEmpty) {
50
78
  const rendered = this.props.renderEmpty(components);
51
79
  return components.length ? this.renderEmptyPlaceholder(rendered) : rendered;
@@ -1,6 +1,6 @@
1
1
  import { useSitecoreContext } from '../enhancers/withSitecoreContext';
2
2
  let emittedVI = false;
3
- const VIComponent = () => {
3
+ const VIComponent = (props) => {
4
4
  const { sitecoreContext } = useSitecoreContext();
5
5
  if (emittedVI ||
6
6
  typeof document === 'undefined' ||
@@ -13,6 +13,7 @@ const VIComponent = () => {
13
13
  const script = document.createElement('script');
14
14
  script.src = '/layouts/system/VisitorIdentification.js';
15
15
  script.type = 'text/javascript';
16
+ script.defer = props.defer;
16
17
  const meta = document.createElement('meta');
17
18
  meta.name = 'VIcurrentDateTime';
18
19
  meta.content = sitecoreContext.visitorIdentificationTimestamp.toString();
@@ -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.FC<T>} Component
5
6
  */
6
7
  export function withComponentFactory(Component) {
7
- return function WithComponentFactory(props) {
8
- return (React.createElement(ComponentFactoryReactContext.Consumer, null, (context) => React.createElement(Component, Object.assign({}, props, { componentFactory: props.componentFactory || context }))));
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
  }
@@ -15,7 +15,3 @@ export const withEditorChromes = (WrappedComponent) => {
15
15
  }
16
16
  return Enhancer;
17
17
  };
18
- /**
19
- * @deprecated Will be removed in a future release. Please use withEditorChromes instead.
20
- */
21
- export const withExperienceEditorChromes = withEditorChromes;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { useContext } from 'react';
2
2
  import { SitecoreContextReactContext } from '../components/SitecoreContext';
3
3
  /**
4
4
  * @param {WithSitecoreContextOptions} [options]
@@ -6,7 +6,8 @@ import { SitecoreContextReactContext } from '../components/SitecoreContext';
6
6
  export function withSitecoreContext(options) {
7
7
  return function withSitecoreContextHoc(Component) {
8
8
  return function WithSitecoreContext(props) {
9
- return (React.createElement(SitecoreContextReactContext.Consumer, null, (context) => (React.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, updateSitecoreContext: options && options.updatable && context.setContext })))));
9
+ const context = useContext(SitecoreContextReactContext);
10
+ return (React.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, updateSitecoreContext: options && options.updatable && context.setContext })));
10
11
  };
11
12
  };
12
13
  }
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { constants, enableDebug } from '@sitecore-jss/sitecore-jss';
2
- export { isExperienceEditorActive, resetExperienceEditorChromes, isEditorActive, resetEditorChromes, } from '@sitecore-jss/sitecore-jss/utils';
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';
@@ -14,6 +14,6 @@ export { File } from './components/File';
14
14
  export { VisitorIdentification } from './components/VisitorIdentification';
15
15
  export { SitecoreContext, SitecoreContextReactContext, } from './components/SitecoreContext';
16
16
  export { withSitecoreContext, useSitecoreContext, } from './enhancers/withSitecoreContext';
17
- export { withEditorChromes, withExperienceEditorChromes } from './enhancers/withEditorChromes';
17
+ export { withEditorChromes } from './enhancers/withEditorChromes';
18
18
  export { withPlaceholder } from './enhancers/withPlaceholder';
19
19
  export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-react",
3
- "version": "21.0.0-canary.99",
3
+ "version": "21.0.1",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -30,7 +30,7 @@
30
30
  "@types/chai": "^4.2.2",
31
31
  "@types/chai-string": "^1.4.2",
32
32
  "@types/deep-equal": "^1.0.1",
33
- "@types/enzyme": "^3.10.3",
33
+ "@types/enzyme": "^3.10.12",
34
34
  "@types/mocha": "^9.0.0",
35
35
  "@types/node": "17.0.40",
36
36
  "@types/prop-types": "^15.7.4",
@@ -42,7 +42,7 @@
42
42
  "chai": "^4.2.0",
43
43
  "chai-string": "^1.5.0",
44
44
  "cheerio": "1.0.0-rc.10",
45
- "del-cli": "^3.0.1",
45
+ "del-cli": "^5.0.0",
46
46
  "enzyme": "^3.11.0",
47
47
  "eslint": "^7.15.0",
48
48
  "eslint-plugin-react": "^7.21.5",
@@ -61,14 +61,15 @@
61
61
  "react-dom": "^18.1.0"
62
62
  },
63
63
  "dependencies": {
64
- "@sitecore-jss/sitecore-jss": "^21.0.0-canary.99",
64
+ "@sitecore-jss/sitecore-jss": "^21.0.1",
65
65
  "deep-equal": "^2.0.5",
66
+ "html-react-parser": "^3.0.0",
66
67
  "prop-types": "^15.7.2",
67
68
  "style-attr": "^1.3.0"
68
69
  },
69
70
  "description": "",
70
71
  "types": "types/index.d.ts",
71
- "gitHead": "079d830383d3d46b8b37eaf13c2a0aae1be52104",
72
+ "gitHead": "a8ce6e1211ed8fea0d59786527f67348423932b5",
72
73
  "files": [
73
74
  "dist",
74
75
  "types"
@@ -30,10 +30,10 @@ export declare type LinkProps = React.DetailedHTMLProps<React.AnchorHTMLAttribut
30
30
  */
31
31
  showLinkTextWithChildrenPresent?: boolean;
32
32
  };
33
- export declare const Link: React.FC<LinkProps>;
33
+ export declare const Link: React.ForwardRefExoticComponent<Pick<LinkProps, "key" | "editable" | "field" | "showLinkTextWithChildrenPresent" | keyof React.AnchorHTMLAttributes<HTMLAnchorElement>> & React.RefAttributes<HTMLAnchorElement>>;
34
34
  export declare const LinkPropTypes: {
35
35
  field: PropTypes.Validator<PropTypes.InferProps<{
36
- href: PropTypes.Requireable<string>;
36
+ href: PropTypes.Requireable<any>;
37
37
  }> | PropTypes.InferProps<{
38
38
  value: PropTypes.Requireable<object>;
39
39
  editableFirstPart: PropTypes.Requireable<string>;
@@ -18,4 +18,7 @@ export interface PlaceholderComponentProps extends PlaceholderProps {
18
18
  */
19
19
  renderEach?: (component: React.ReactNode, index: number) => React.ReactNode;
20
20
  }
21
- export declare const Placeholder: (props: PlaceholderComponentProps) => JSX.Element;
21
+ export declare const Placeholder: {
22
+ (props: PlaceholderComponentProps): JSX.Element;
23
+ displayName: string;
24
+ };
@@ -1,2 +1,6 @@
1
1
  import React from 'react';
2
- export declare const VisitorIdentification: React.FC<{}>;
2
+ interface VisitorIdentificationProps {
3
+ defer?: boolean;
4
+ }
5
+ export declare const VisitorIdentification: React.FC<VisitorIdentificationProps>;
6
+ export {};
@@ -6,4 +6,7 @@ export interface ComponentFactoryProps {
6
6
  /**
7
7
  * @param {React.ComponentClass<T> | React.FC<T>} Component
8
8
  */
9
- export declare function withComponentFactory<T extends ComponentFactoryProps>(Component: React.ComponentClass<T> | React.FC<T>): (props: T) => JSX.Element;
9
+ export declare function withComponentFactory<T extends ComponentFactoryProps>(Component: React.ComponentClass<T> | React.FC<T>): {
10
+ (props: T): JSX.Element;
11
+ displayName: string;
12
+ };
@@ -1,6 +1,2 @@
1
1
  import React from 'react';
2
2
  export declare const withEditorChromes: (WrappedComponent: React.ComponentClass<unknown> | React.FC<unknown>) => React.ComponentClass<{}, any>;
3
- /**
4
- * @deprecated Will be removed in a future release. Please use withEditorChromes instead.
5
- */
6
- export declare const withExperienceEditorChromes: (WrappedComponent: React.ComponentClass<unknown> | React.FC<unknown>) => React.ComponentClass<{}, any>;
@@ -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>) => (props: PlaceholderProps) => JSX.Element;
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
@@ -1,5 +1,5 @@
1
1
  export { constants, enableDebug } from '@sitecore-jss/sitecore-jss';
2
- export { isExperienceEditorActive, resetExperienceEditorChromes, isEditorActive, resetEditorChromes, } from '@sitecore-jss/sitecore-jss/utils';
2
+ export { isEditorActive, resetEditorChromes } from '@sitecore-jss/sitecore-jss/utils';
3
3
  export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, RestLayoutService, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, } from '@sitecore-jss/sitecore-jss/layout';
4
4
  export { trackingApi, TrackingRequestOptions, CampaignInstance, GoalInstance, OutcomeInstance, EventInstance, PageViewInstance, } from '@sitecore-jss/sitecore-jss/tracking';
5
5
  export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, RestDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
@@ -15,6 +15,6 @@ export { File, FileField } from './components/File';
15
15
  export { VisitorIdentification } from './components/VisitorIdentification';
16
16
  export { SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, } from './components/SitecoreContext';
17
17
  export { withSitecoreContext, useSitecoreContext, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, WithSitecoreContextHocProps, } from './enhancers/withSitecoreContext';
18
- export { withEditorChromes, withExperienceEditorChromes } from './enhancers/withEditorChromes';
18
+ export { withEditorChromes } from './enhancers/withEditorChromes';
19
19
  export { withPlaceholder } from './enhancers/withPlaceholder';
20
20
  export { withDatasourceCheck } from './enhancers/withDatasourceCheck';