@sitecore-jss/sitecore-jss-react 23.0.0-canary.2 → 23.0.0-canary.21
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/Date.js +3 -5
- package/dist/cjs/components/ErrorBoundary.js +18 -2
- package/dist/cjs/components/Image.js +5 -10
- package/dist/cjs/components/Link.js +5 -8
- package/dist/cjs/components/Placeholder.js +3 -10
- package/dist/cjs/components/PlaceholderCommon.js +15 -58
- package/dist/cjs/components/RichText.js +10 -11
- package/dist/cjs/components/SitecoreContext.js +0 -8
- package/dist/cjs/components/Text.js +3 -6
- package/dist/cjs/enhancers/withDatasourceCheck.js +1 -4
- package/dist/cjs/enhancers/withPlaceholder.js +2 -2
- package/dist/cjs/enhancers/withSitecoreContext.js +1 -2
- package/dist/cjs/index.js +1 -28
- package/dist/cjs/utils.js +1 -16
- package/dist/esm/components/Date.js +2 -5
- package/dist/esm/components/ErrorBoundary.js +18 -2
- package/dist/esm/components/Image.js +4 -10
- package/dist/esm/components/Link.js +5 -8
- package/dist/esm/components/Placeholder.js +3 -10
- package/dist/esm/components/PlaceholderCommon.js +16 -59
- package/dist/esm/components/RichText.js +11 -12
- package/dist/esm/components/SitecoreContext.js +0 -8
- package/dist/esm/components/Text.js +2 -6
- package/dist/esm/enhancers/withDatasourceCheck.js +1 -4
- package/dist/esm/enhancers/withPlaceholder.js +2 -2
- package/dist/esm/enhancers/withSitecoreContext.js +2 -3
- package/dist/esm/index.js +1 -11
- package/dist/esm/utils.js +0 -14
- package/package.json +3 -6
- package/types/ComponentBuilder.d.ts +0 -1
- package/types/components/Date.d.ts +2 -4
- package/types/components/EditFrame.d.ts +0 -1
- package/types/components/ErrorBoundary.d.ts +0 -1
- package/types/components/File.d.ts +0 -1
- package/types/components/HiddenRendering.d.ts +0 -1
- package/types/components/Image.d.ts +2 -4
- package/types/components/Link.d.ts +3 -5
- package/types/components/MissingComponent.d.ts +0 -1
- package/types/components/Placeholder.d.ts +0 -1
- package/types/components/PlaceholderCommon.d.ts +12 -4
- package/types/components/RichText.d.ts +3 -5
- package/types/components/SitecoreContext.d.ts +0 -21
- package/types/components/Text.d.ts +2 -4
- package/types/components/VisitorIdentification.d.ts +0 -1
- package/types/components/sharedTypes.d.ts +1 -8
- package/types/enhancers/withComponentFactory.d.ts +0 -1
- package/types/enhancers/withDatasourceCheck.d.ts +0 -1
- package/types/enhancers/withEditorChromes.d.ts +0 -1
- package/types/enhancers/withPlaceholder.d.ts +0 -1
- package/types/enhancers/withSitecoreContext.d.ts +1 -3
- package/types/index.d.ts +1 -11
- package/types/utils.d.ts +0 -9
- package/dist/cjs/components/BYOCComponent.js +0 -122
- package/dist/cjs/components/BYOCWrapper.js +0 -18
- package/dist/cjs/components/DefaultEmptyFieldEditingComponents.js +0 -22
- package/dist/cjs/components/DesignLibrary.js +0 -72
- package/dist/cjs/components/EditingScripts.js +0 -47
- package/dist/cjs/components/FEaaSComponent.js +0 -151
- package/dist/cjs/components/FEaaSWrapper.js +0 -18
- package/dist/cjs/components/FieldMetadata.js +0 -29
- package/dist/cjs/components/Form.js +0 -80
- package/dist/cjs/components/PlaceholderMetadata.js +0 -63
- package/dist/cjs/enhancers/withEmptyFieldEditingComponent.js +0 -63
- package/dist/cjs/enhancers/withFieldMetadata.js +0 -60
- package/dist/esm/components/BYOCComponent.js +0 -91
- package/dist/esm/components/BYOCWrapper.js +0 -11
- package/dist/esm/components/DefaultEmptyFieldEditingComponents.js +0 -14
- package/dist/esm/components/DesignLibrary.js +0 -45
- package/dist/esm/components/EditingScripts.js +0 -40
- package/dist/esm/components/FEaaSComponent.js +0 -119
- package/dist/esm/components/FEaaSWrapper.js +0 -11
- package/dist/esm/components/FieldMetadata.js +0 -22
- package/dist/esm/components/Form.js +0 -52
- package/dist/esm/components/PlaceholderMetadata.js +0 -56
- package/dist/esm/enhancers/withEmptyFieldEditingComponent.js +0 -36
- package/dist/esm/enhancers/withFieldMetadata.js +0 -33
- package/types/components/BYOCComponent.d.ts +0 -91
- package/types/components/BYOCWrapper.d.ts +0 -4
- package/types/components/DefaultEmptyFieldEditingComponents.d.ts +0 -10
- package/types/components/DesignLibrary.d.ts +0 -3
- package/types/components/EditingScripts.d.ts +0 -8
- package/types/components/FEaaSComponent.d.ts +0 -72
- package/types/components/FEaaSWrapper.d.ts +0 -4
- package/types/components/FieldMetadata.d.ts +0 -18
- package/types/components/Form.d.ts +0 -30
- package/types/components/PlaceholderMetadata.d.ts +0 -29
- package/types/enhancers/withEmptyFieldEditingComponent.d.ts +0 -28
- package/types/enhancers/withFieldMetadata.d.ts +0 -17
|
@@ -27,6 +27,11 @@ class ErrorBoundary extends React.Component {
|
|
|
27
27
|
((_a = this.props.sitecoreContext) === null || _a === void 0 ? void 0 : _a.pageState) === LayoutServicePageState.Edit ||
|
|
28
28
|
((_b = this.props.sitecoreContext) === null || _b === void 0 ? void 0 : _b.pageState) === LayoutServicePageState.Preview);
|
|
29
29
|
}
|
|
30
|
+
isPageEditing() {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
return (!!((_a = this.props.sitecoreContext) === null || _a === void 0 ? void 0 : _a.pageEditing) ||
|
|
33
|
+
((_b = this.props.sitecoreContext) === null || _b === void 0 ? void 0 : _b.pageState) === LayoutServicePageState.Edit);
|
|
34
|
+
}
|
|
30
35
|
render() {
|
|
31
36
|
var _a, _b;
|
|
32
37
|
if (this.state.error) {
|
|
@@ -51,10 +56,21 @@ class ErrorBoundary extends React.Component {
|
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
// do not apply suspense when suspense is disabled or when on already dynamic components
|
|
59
|
+
let content;
|
|
54
60
|
if (((_b = this.props.disableSuspense) !== null && _b !== void 0 ? _b : true) || this.props.isDynamic) {
|
|
55
|
-
|
|
61
|
+
content = this.props.children;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
content = (React.createElement(Suspense, { fallback: React.createElement("h4", null, this.props.componentLoadingMessage || this.defaultLoadingMessage) }, this.props.children));
|
|
65
|
+
}
|
|
66
|
+
// Experience Editor tags the outermost DOM node of each rendering (sc-part-of,
|
|
67
|
+
// scEnabledChrome) after SSR. Own that node in the SDK during editing so hydration
|
|
68
|
+
// mismatches can be suppressed without requiring suppressHydrationWarning on every
|
|
69
|
+
// app component. `display: contents` keeps SXA/Bootstrap column layout intact.
|
|
70
|
+
if (this.isPageEditing()) {
|
|
71
|
+
return (React.createElement("div", { suppressHydrationWarning: true, style: { display: 'contents' } }, content));
|
|
56
72
|
}
|
|
57
|
-
return
|
|
73
|
+
return content;
|
|
58
74
|
}
|
|
59
75
|
}
|
|
60
76
|
export default withSitecoreContext()(ErrorBoundary);
|
|
@@ -13,14 +13,12 @@ import { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
|
13
13
|
import React from 'react';
|
|
14
14
|
import { addClassName, convertAttributesToReactProps } from '../utils';
|
|
15
15
|
import { getAttributesString } from '../utils';
|
|
16
|
-
import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
17
|
-
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
18
|
-
import { DefaultEmptyFieldEditingComponentImage } from './DefaultEmptyFieldEditingComponents';
|
|
19
16
|
import { isFieldValueEmpty } from '@sitecore-jss/sitecore-jss/layout';
|
|
20
17
|
const getEditableWrapper = (editableMarkup, ...otherProps) => (
|
|
21
18
|
// create an inline wrapper and use dangerouslySetInnerHTML.
|
|
22
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
|
-
|
|
20
|
+
// Experience Editor rewrites this chrome markup client-side after SSR.
|
|
21
|
+
React.createElement("span", Object.assign({ className: "sc-image-wrapper", suppressHydrationWarning: true }, otherProps, { dangerouslySetInnerHTML: { __html: editableMarkup } })));
|
|
24
22
|
const getImageAttrs = (_a, imageParams, mediaUrlPrefix) => {
|
|
25
23
|
var { src, srcSet } = _a, otherAttrs = __rest(_a, ["src", "srcSet"]);
|
|
26
24
|
if (!src) {
|
|
@@ -62,7 +60,7 @@ export const getEEMarkup = (imageField, imageParams, mediaUrlPrefix, otherProps)
|
|
|
62
60
|
const editableMarkup = imageField.editable.replace(foundImg.imgTag, imgHtml);
|
|
63
61
|
return getEditableWrapper(editableMarkup);
|
|
64
62
|
};
|
|
65
|
-
export const Image =
|
|
63
|
+
export const Image = (_a) => {
|
|
66
64
|
var { editable = true, imageParams, field, mediaUrlPrefix } = _a, otherProps = __rest(_a, ["editable", "imageParams", "field", "mediaUrlPrefix"]);
|
|
67
65
|
const dynamicMedia = field;
|
|
68
66
|
if (!field || (!dynamicMedia.editable && isFieldValueEmpty(dynamicMedia))) {
|
|
@@ -79,14 +77,10 @@ export const Image = withFieldMetadata(withEmptyFieldEditingComponent((_a) => {
|
|
|
79
77
|
if (!img) {
|
|
80
78
|
return null;
|
|
81
79
|
}
|
|
82
|
-
// prevent metadata from being passed to the img tag
|
|
83
|
-
if (img.metadata) {
|
|
84
|
-
delete img.metadata;
|
|
85
|
-
}
|
|
86
80
|
const attrs = getImageAttrs(Object.assign(Object.assign({}, img), otherProps), imageParams, mediaUrlPrefix);
|
|
87
81
|
if (attrs) {
|
|
88
82
|
return React.createElement("img", Object.assign({}, attrs));
|
|
89
83
|
}
|
|
90
84
|
return null; // we can't handle the truth
|
|
91
|
-
}
|
|
85
|
+
};
|
|
92
86
|
Image.displayName = 'Image';
|
|
@@ -10,13 +10,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import React, { forwardRef } from 'react';
|
|
13
|
-
import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
14
|
-
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
15
|
-
import { DefaultEmptyFieldEditingComponentText } from './DefaultEmptyFieldEditingComponents';
|
|
16
13
|
import { isFieldValueEmpty } from '@sitecore-jss/sitecore-jss/layout';
|
|
17
|
-
export const Link =
|
|
18
|
-
// eslint-disable-next-line react/display-name
|
|
19
|
-
forwardRef((_a, ref) => {
|
|
14
|
+
export const Link = forwardRef((_a, ref) => {
|
|
20
15
|
var { field, editable = true, showLinkTextWithChildrenPresent } = _a, otherProps = __rest(_a, ["field", "editable", "showLinkTextWithChildrenPresent"]);
|
|
21
16
|
const children = otherProps.children;
|
|
22
17
|
const dynamicField = field;
|
|
@@ -31,7 +26,9 @@ forwardRef((_a, ref) => {
|
|
|
31
26
|
// However, we cannot combine arbitrary unparsed HTML (innerHTML) based components with actual vDOM components (the children)
|
|
32
27
|
// 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
|
|
33
28
|
// as siblings. Should be "good enough" for most cases - and write your own helper if it isn't. Or bring xEditor out of 2006.
|
|
34
|
-
const htmlProps = Object.assign(Object.assign({ className: 'sc-link-wrapper',
|
|
29
|
+
const htmlProps = Object.assign(Object.assign({ className: 'sc-link-wrapper',
|
|
30
|
+
// Experience Editor rewrites this chrome markup client-side after SSR.
|
|
31
|
+
suppressHydrationWarning: true, dangerouslySetInnerHTML: {
|
|
35
32
|
__html: markup,
|
|
36
33
|
} }, otherProps), { key: 'editable' });
|
|
37
34
|
// Exclude children, since 'dangerouslySetInnerHTML' and 'children' can't be set together
|
|
@@ -66,5 +63,5 @@ forwardRef((_a, ref) => {
|
|
|
66
63
|
const linkText = showLinkTextWithChildrenPresent || !children ? link.text || link.href : null;
|
|
67
64
|
resultTags.push(React.createElement('a', Object.assign(Object.assign(Object.assign({}, anchorAttrs), otherProps), { key: 'link', ref }), linkText, children));
|
|
68
65
|
return React.createElement(React.Fragment, null, resultTags);
|
|
69
|
-
})
|
|
66
|
+
});
|
|
70
67
|
Link.displayName = 'Link';
|
|
@@ -1,7 +1,6 @@
|
|
|
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/editing';
|
|
5
4
|
import { withSitecoreContext } from '../enhancers/withSitecoreContext';
|
|
6
5
|
/**
|
|
7
6
|
* @param {HtmlElementRendering | ComponentRendering} rendering
|
|
@@ -15,12 +14,6 @@ class PlaceholderComponent extends PlaceholderCommon {
|
|
|
15
14
|
super(props);
|
|
16
15
|
this.isEmpty = false;
|
|
17
16
|
}
|
|
18
|
-
componentDidMount() {
|
|
19
|
-
super.componentDidMount();
|
|
20
|
-
if (this.isEmpty && HorizonEditor.isActive()) {
|
|
21
|
-
HorizonEditor.resetChromes();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
17
|
/**
|
|
25
18
|
* In case we need to render an empty placeholder, some part of the markup will be inserted by the EE,
|
|
26
19
|
* so we need to separate the empty placeholder's markup and allow React reconciliation to be executed correctly
|
|
@@ -29,10 +22,10 @@ class PlaceholderComponent extends PlaceholderCommon {
|
|
|
29
22
|
* @returns react node
|
|
30
23
|
*/
|
|
31
24
|
renderEmptyPlaceholder(node) {
|
|
32
|
-
|
|
25
|
+
// Experience Editor may mutate empty-placeholder chrome between SSR and hydration.
|
|
26
|
+
return (React.createElement("div", { className: "sc-jss-empty-placeholder", suppressHydrationWarning: true }, node));
|
|
33
27
|
}
|
|
34
28
|
render() {
|
|
35
|
-
var _a;
|
|
36
29
|
const childProps = Object.assign({}, this.props);
|
|
37
30
|
delete childProps.componentFactory;
|
|
38
31
|
if (this.state.error) {
|
|
@@ -45,7 +38,7 @@ class PlaceholderComponent extends PlaceholderCommon {
|
|
|
45
38
|
"."));
|
|
46
39
|
}
|
|
47
40
|
const renderingData = childProps.rendering;
|
|
48
|
-
const placeholderData = PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, this.props.name
|
|
41
|
+
const placeholderData = PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, this.props.name);
|
|
49
42
|
this.isEmpty = placeholderData.every((rendering) => isRawRendering(rendering));
|
|
50
43
|
const components = this.getComponentsForRenderingData(placeholderData);
|
|
51
44
|
if (this.props.renderEmpty && this.isEmpty) {
|
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import React from 'react';
|
|
13
2
|
import { MissingComponent } from './MissingComponent';
|
|
14
|
-
import {
|
|
3
|
+
import { isDynamicPlaceholder, getDynamicPlaceholderPattern, } from '@sitecore-jss/sitecore-jss/layout';
|
|
15
4
|
import { constants } from '@sitecore-jss/sitecore-jss';
|
|
16
5
|
import { convertAttributesToReactProps } from '../utils';
|
|
17
6
|
import { HiddenRendering } from './HiddenRendering';
|
|
18
|
-
import { FEaaSComponent, FEAAS_COMPONENT_RENDERING_NAME } from './FEaaSComponent';
|
|
19
|
-
import { FEaaSWrapper, FEAAS_WRAPPER_RENDERING_NAME } from './FEaaSWrapper';
|
|
20
|
-
import { BYOCComponent, BYOC_COMPONENT_RENDERING_NAME } from './BYOCComponent';
|
|
21
|
-
import { BYOCWrapper, BYOC_WRAPPER_RENDERING_NAME } from './BYOCWrapper';
|
|
22
|
-
import { PlaceholderMetadata } from './PlaceholderMetadata';
|
|
23
7
|
import ErrorBoundary from './ErrorBoundary';
|
|
24
8
|
export class PlaceholderCommon extends React.Component {
|
|
25
9
|
constructor(props) {
|
|
@@ -30,13 +14,12 @@ export class PlaceholderCommon extends React.Component {
|
|
|
30
14
|
this.updateKeyAttributes = this.updateKeyAttributes.bind(this);
|
|
31
15
|
this.createRawElement = this.createRawElement.bind(this);
|
|
32
16
|
}
|
|
33
|
-
static getPlaceholderDataFromRenderingData(rendering, name
|
|
17
|
+
static getPlaceholderDataFromRenderingData(rendering, name) {
|
|
34
18
|
let result;
|
|
35
|
-
|
|
19
|
+
const phName = name.slice();
|
|
36
20
|
/**
|
|
37
21
|
* Process (SXA) dynamic placeholders
|
|
38
22
|
* Find and replace the matching dynamic placeholder e.g 'nameOfContainer-{*}' with the requested e.g. 'nameOfContainer-1'.
|
|
39
|
-
* For Metadata EditMode, we need to keep the raw placeholder name in place.
|
|
40
23
|
*/
|
|
41
24
|
if (rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) {
|
|
42
25
|
Object.keys(rendering.placeholders).forEach((placeholder) => {
|
|
@@ -44,13 +27,8 @@ export class PlaceholderCommon extends React.Component {
|
|
|
44
27
|
? getDynamicPlaceholderPattern(placeholder)
|
|
45
28
|
: null;
|
|
46
29
|
if (patternPlaceholder && patternPlaceholder.test(phName)) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
rendering.placeholders[phName] = rendering.placeholders[placeholder];
|
|
52
|
-
delete rendering.placeholders[placeholder];
|
|
53
|
-
}
|
|
30
|
+
rendering.placeholders[phName] = rendering.placeholders[placeholder];
|
|
31
|
+
delete rendering.placeholders[placeholder];
|
|
54
32
|
}
|
|
55
33
|
});
|
|
56
34
|
}
|
|
@@ -83,11 +61,10 @@ export class PlaceholderCommon extends React.Component {
|
|
|
83
61
|
});
|
|
84
62
|
}
|
|
85
63
|
getComponentsForRenderingData(placeholderData) {
|
|
86
|
-
|
|
87
|
-
const _b = this.props, { name, fields: placeholderFields, params: placeholderParams, missingComponentComponent, hiddenRenderingComponent } = _b, placeholderProps = __rest(_b, ["name", "fields", "params", "missingComponentComponent", "hiddenRenderingComponent"]);
|
|
64
|
+
const { name, fields: placeholderFields, params: placeholderParams, missingComponentComponent, hiddenRenderingComponent, passThroughComponentProps, modifyComponentProps, } = this.props;
|
|
88
65
|
const transformedComponents = placeholderData
|
|
89
66
|
.map((rendering, index) => {
|
|
90
|
-
var _a
|
|
67
|
+
var _a;
|
|
91
68
|
const key = rendering.uid
|
|
92
69
|
? rendering.uid
|
|
93
70
|
: `component-${index}`;
|
|
@@ -111,55 +88,33 @@ export class PlaceholderCommon extends React.Component {
|
|
|
111
88
|
else {
|
|
112
89
|
component = this.getComponentForRendering(componentRendering);
|
|
113
90
|
}
|
|
114
|
-
// Fallback/defaults for Sitecore Component renderings (in case not defined in component factory)
|
|
115
|
-
if (!component) {
|
|
116
|
-
if (componentRendering.componentName === FEAAS_COMPONENT_RENDERING_NAME) {
|
|
117
|
-
component = FEaaSComponent;
|
|
118
|
-
}
|
|
119
|
-
else if (componentRendering.componentName === FEAAS_WRAPPER_RENDERING_NAME) {
|
|
120
|
-
component = FEaaSWrapper;
|
|
121
|
-
}
|
|
122
|
-
else if (componentRendering.componentName === BYOC_COMPONENT_RENDERING_NAME) {
|
|
123
|
-
component = BYOCComponent;
|
|
124
|
-
}
|
|
125
|
-
else if (componentRendering.componentName === BYOC_WRAPPER_RENDERING_NAME) {
|
|
126
|
-
component = BYOCWrapper;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
91
|
if (!component) {
|
|
130
92
|
console.error(`Placeholder ${name} contains unknown component ${componentRendering.componentName}. Ensure that a React component exists for it, and that it is registered in your componentFactory.js.`);
|
|
131
93
|
component = missingComponentComponent !== null && missingComponentComponent !== void 0 ? missingComponentComponent : MissingComponent;
|
|
132
94
|
isEmpty = true;
|
|
133
95
|
}
|
|
134
|
-
|
|
96
|
+
// Only pass rendering data props to child components.
|
|
97
|
+
// Internal Placeholder/SitecoreContext props are excluded.
|
|
98
|
+
const childProps = Object.assign(Object.assign(Object.assign(Object.assign({}, commonProps), ((placeholderFields || componentRendering.fields) && {
|
|
135
99
|
fields: Object.assign(Object.assign({}, placeholderFields), componentRendering.fields),
|
|
136
100
|
})), ((placeholderParams || componentRendering.params) && {
|
|
137
101
|
params: Object.assign(Object.assign(Object.assign({}, placeholderParams), componentRendering.params), this.getSXAParams(componentRendering)),
|
|
138
102
|
})), { rendering: componentRendering });
|
|
139
|
-
|
|
103
|
+
const modifiedProps = modifyComponentProps ? modifyComponentProps(childProps) : childProps;
|
|
104
|
+
const finalProps = Object.assign(Object.assign({}, modifiedProps), passThroughComponentProps);
|
|
105
|
+
let rendered = React.createElement(component, finalProps);
|
|
140
106
|
if (!isEmpty) {
|
|
141
107
|
// assign type based on passed element - type='text/sitecore' should be ignored when renderEach Placeholder prop function is being used
|
|
142
108
|
const type = rendered.props.type === 'text/sitecore' ? rendered.props.type : '';
|
|
143
|
-
// the registered BYOC components are imported using dynamic(), so we need to account for that when passing the isDynamic prop to ErrorBoundary
|
|
144
|
-
const isByocWrapper = componentRendering.componentName === BYOC_WRAPPER_RENDERING_NAME;
|
|
145
109
|
// all dynamic elements will have a separate render prop
|
|
146
110
|
const isDynamicComponent = !!((_a = component.render) === null || _a === void 0 ? void 0 : _a.preload);
|
|
147
111
|
// wrapping with error boundary could cause problems in case where parent component uses withPlaceholder HOC and tries to access its children props
|
|
148
112
|
// that's why we need to expose element's props here
|
|
149
|
-
rendered = (React.createElement(ErrorBoundary, Object.assign({ key: rendered.type + '-' + index, errorComponent: this.props.errorComponent, componentLoadingMessage: this.props.componentLoadingMessage, type: type, isDynamic: isDynamicComponent
|
|
150
|
-
}
|
|
151
|
-
// if editMode is equal to 'metadata' then emit shallow chromes for hydration in Pages
|
|
152
|
-
if (((_b = this.props.sitecoreContext) === null || _b === void 0 ? void 0 : _b.editMode) === EditMode.Metadata) {
|
|
153
|
-
return (React.createElement(PlaceholderMetadata, { key: key, rendering: rendering }, rendered));
|
|
113
|
+
rendered = (React.createElement(ErrorBoundary, Object.assign({ key: rendered.type + '-' + index, errorComponent: this.props.errorComponent, componentLoadingMessage: this.props.componentLoadingMessage, type: type, isDynamic: isDynamicComponent, disableSuspense: this.props.disableSuspense }, rendered.props), rendered));
|
|
154
114
|
}
|
|
155
115
|
return rendered;
|
|
156
116
|
})
|
|
157
117
|
.filter((element) => element); // remove nulls
|
|
158
|
-
if (((_a = this.props.sitecoreContext) === null || _a === void 0 ? void 0 : _a.editMode) === EditMode.Metadata) {
|
|
159
|
-
return [
|
|
160
|
-
React.createElement(PlaceholderMetadata, { key: this.props.rendering.uid, placeholderName: name, rendering: this.props.rendering }, transformedComponents),
|
|
161
|
-
];
|
|
162
|
-
}
|
|
163
118
|
return transformedComponents;
|
|
164
119
|
}
|
|
165
120
|
getComponentForRendering(renderingDefinition) {
|
|
@@ -191,6 +146,8 @@ export class PlaceholderCommon extends React.Component {
|
|
|
191
146
|
if (!Array.isArray(attributes) && attributes && attributes.chrometype === 'placeholder') {
|
|
192
147
|
props.phkey = elem.attributes.key; // props that get rendered as dom attribute names need to be lowercase, otherwise React complains.
|
|
193
148
|
props.ref = this.addRef; // only need ref for placeholder containers, trying to add it to other components (e.g. stateless components) may result in a warning.
|
|
149
|
+
// EE may mutate chrome
|
|
150
|
+
props.suppressHydrationWarning = true;
|
|
194
151
|
}
|
|
195
152
|
return React.createElement(elem.name, props);
|
|
196
153
|
}
|
|
@@ -9,21 +9,20 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React, { forwardRef } from 'react';
|
|
13
|
-
import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
14
|
-
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
15
|
-
import { DefaultEmptyFieldEditingComponentText } from './DefaultEmptyFieldEditingComponents';
|
|
12
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
16
13
|
import { isFieldValueEmpty } from '@sitecore-jss/sitecore-jss/layout';
|
|
17
|
-
export const RichText =
|
|
18
|
-
// eslint-disable-next-line react/display-name
|
|
19
|
-
forwardRef((_a, ref) => {
|
|
14
|
+
export const RichText = forwardRef((_a, ref) => {
|
|
20
15
|
var { field, tag = 'div', editable = true } = _a, otherProps = __rest(_a, ["field", "tag", "editable"]);
|
|
21
|
-
|
|
16
|
+
const html = field && (field.editable && editable ? field.editable : field.value);
|
|
17
|
+
// Keep the object reference stable across re-renders when the html is unchanged,
|
|
18
|
+
// since React DOM compares dangerouslySetInnerHTML by reference and re-sets
|
|
19
|
+
// innerHTML (recreating all child DOM nodes) whenever it changes.
|
|
20
|
+
const dangerouslySetInnerHTML = useMemo(() => (html !== undefined && html !== '' ? { __html: html } : undefined), [html]);
|
|
21
|
+
if (!field || (!field.editable && isFieldValueEmpty(field)) || !dangerouslySetInnerHTML) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
|
-
const htmlProps = Object.assign({ dangerouslySetInnerHTML
|
|
25
|
-
|
|
26
|
-
}, ref }, otherProps);
|
|
24
|
+
const htmlProps = Object.assign(Object.assign({ dangerouslySetInnerHTML,
|
|
25
|
+
ref }, (field.editable && editable ? { suppressHydrationWarning: true } : {})), otherProps);
|
|
27
26
|
return React.createElement(tag || 'div', htmlProps);
|
|
28
|
-
})
|
|
27
|
+
});
|
|
29
28
|
RichText.displayName = 'RichText';
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import fastDeepEqual from 'fast-deep-equal/es6/react';
|
|
4
|
-
import { constants } from '@sitecore-jss/sitecore-jss';
|
|
5
3
|
export const SitecoreContextReactContext = React.createContext({});
|
|
6
4
|
export const ComponentFactoryReactContext = React.createContext({});
|
|
7
5
|
export class SitecoreContext extends React.Component {
|
|
8
6
|
constructor(props) {
|
|
9
|
-
var _a, _b, _c, _d;
|
|
10
7
|
super(props);
|
|
11
8
|
/**
|
|
12
9
|
* Update context state. Value can be @type {LayoutServiceData} which will be automatically transformed
|
|
@@ -21,14 +18,9 @@ export class SitecoreContext extends React.Component {
|
|
|
21
18
|
});
|
|
22
19
|
};
|
|
23
20
|
const context = this.constructContext(props.layoutData);
|
|
24
|
-
let api = props.api;
|
|
25
|
-
if (((_b = (_a = props.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId) && !((_d = (_c = props.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl)) {
|
|
26
|
-
api = Object.assign(Object.assign({}, props.api), { edge: Object.assign(Object.assign({}, props.api.edge), { edgeUrl: constants.SITECORE_EDGE_URL_DEFAULT }) });
|
|
27
|
-
}
|
|
28
21
|
this.state = {
|
|
29
22
|
context,
|
|
30
23
|
setContext: this.setContext,
|
|
31
|
-
api,
|
|
32
24
|
};
|
|
33
25
|
}
|
|
34
26
|
constructContext(layoutData) {
|
|
@@ -10,18 +10,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import React from 'react';
|
|
13
|
-
import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
14
|
-
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
15
|
-
import { DefaultEmptyFieldEditingComponentText } from './DefaultEmptyFieldEditingComponents';
|
|
16
13
|
import { isFieldValueEmpty } from '@sitecore-jss/sitecore-jss/layout';
|
|
17
|
-
export const Text =
|
|
14
|
+
export const Text = (_a) => {
|
|
18
15
|
var { field, tag, editable = true, encode = true } = _a, otherProps = __rest(_a, ["field", "tag", "editable", "encode"]);
|
|
19
16
|
if (!field || (!field.editable && isFieldValueEmpty(field))) {
|
|
20
17
|
return null;
|
|
21
18
|
}
|
|
22
19
|
// can't use editable value if we want to output unencoded
|
|
23
20
|
if (!encode) {
|
|
24
|
-
// eslint-disable-next-line no-param-reassign
|
|
25
21
|
editable = false;
|
|
26
22
|
}
|
|
27
23
|
const isEditable = field.editable && editable;
|
|
@@ -62,5 +58,5 @@ export const Text = withFieldMetadata(withEmptyFieldEditingComponent((_a) => {
|
|
|
62
58
|
else {
|
|
63
59
|
return React.createElement(React.Fragment, null, children);
|
|
64
60
|
}
|
|
65
|
-
}
|
|
61
|
+
};
|
|
66
62
|
Text.displayName = 'Text';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { RenderingType } from '@sitecore-jss/sitecore-jss/layout';
|
|
3
2
|
import { useSitecoreContext } from './withSitecoreContext';
|
|
4
3
|
export const DefaultEditingError = () => (React.createElement("div", { className: "sc-jss-editing-error", role: "alert" }, "Datasource is required. Please choose a content item for this component."));
|
|
5
4
|
/**
|
|
@@ -15,9 +14,7 @@ export function withDatasourceCheck(options) {
|
|
|
15
14
|
var _a, _b;
|
|
16
15
|
const { sitecoreContext } = useSitecoreContext();
|
|
17
16
|
const EditingError = (_a = options === null || options === void 0 ? void 0 : options.editingErrorComponent) !== null && _a !== void 0 ? _a : DefaultEditingError;
|
|
18
|
-
|
|
19
|
-
const isDesignLibrary = (sitecoreContext === null || sitecoreContext === void 0 ? void 0 : sitecoreContext.renderingType) === RenderingType.Component;
|
|
20
|
-
return isDesignLibrary || ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (React.createElement(Component, Object.assign({}, props))) : sitecoreContext.pageEditing ? (React.createElement(EditingError, null)) : null;
|
|
17
|
+
return ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (React.createElement(Component, Object.assign({}, props))) : sitecoreContext.pageEditing ? (React.createElement(EditingError, null)) : null;
|
|
21
18
|
};
|
|
22
19
|
};
|
|
23
20
|
}
|
|
@@ -36,13 +36,13 @@ export function withPlaceholder(placeholders, options) {
|
|
|
36
36
|
definitelyArrayPlacholders.forEach((placeholder) => {
|
|
37
37
|
let placeholderData;
|
|
38
38
|
if (typeof placeholder !== 'string' && placeholder.placeholder && placeholder.prop) {
|
|
39
|
-
placeholderData = PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, placeholder.placeholder
|
|
39
|
+
placeholderData = PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, placeholder.placeholder);
|
|
40
40
|
if (placeholderData) {
|
|
41
41
|
childProps[placeholder.prop] = this.getComponentsForRenderingData(placeholderData);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
placeholderData = PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, placeholder
|
|
45
|
+
placeholderData = PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, placeholder);
|
|
46
46
|
if (placeholderData) {
|
|
47
47
|
childProps[placeholder] = this.getComponentsForRenderingData(placeholderData);
|
|
48
48
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SitecoreContextReactContext
|
|
2
|
+
import { SitecoreContextReactContext } from '../components/SitecoreContext';
|
|
3
3
|
/**
|
|
4
4
|
* @param {WithSitecoreContextOptions} [options]
|
|
5
5
|
*/
|
|
6
6
|
export function withSitecoreContext(options) {
|
|
7
7
|
return function withSitecoreContextHoc(Component) {
|
|
8
8
|
return function WithSitecoreContext(props) {
|
|
9
|
-
return (React.createElement(SitecoreContextReactContext.Consumer, null, (context) => (React.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context,
|
|
9
|
+
return (React.createElement(SitecoreContextReactContext.Consumer, null, (context) => (React.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, updateSitecoreContext: options && options.updatable && context.setContext })))));
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
}
|
|
@@ -35,7 +35,6 @@ export function useSitecoreContext(options) {
|
|
|
35
35
|
const reactContext = React.useContext(SitecoreContextReactContext);
|
|
36
36
|
const updatable = options === null || options === void 0 ? void 0 : options.updatable;
|
|
37
37
|
return {
|
|
38
|
-
api: reactContext.api,
|
|
39
38
|
sitecoreContext: reactContext.context,
|
|
40
39
|
updateSitecoreContext: updatable ? reactContext.setContext : undefined,
|
|
41
40
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
export { constants, enableDebug, ClientError, MemoryCacheClient, NativeDataFetcher, } from '@sitecore-jss/sitecore-jss';
|
|
2
2
|
export { isEditorActive, resetEditorChromes, DefaultEditFrameButton, DefaultEditFrameButtons, } from '@sitecore-jss/sitecore-jss/editing';
|
|
3
|
-
export {
|
|
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 { DefaultRetryStrategy, GraphQLRequestClient, } from '@sitecore-jss/sitecore-jss/graphql';
|
|
7
7
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
8
8
|
export { Placeholder } from './components/Placeholder';
|
|
9
|
-
export { Form } from './components/Form';
|
|
10
9
|
export { Image, getEEMarkup, } from './components/Image';
|
|
11
10
|
export { RichText } from './components/RichText';
|
|
12
11
|
export { Text } from './components/Text';
|
|
13
12
|
export { DateField } from './components/Date';
|
|
14
|
-
export { FEaaSComponent, fetchFEaaSComponentServerProps, } from './components/FEaaSComponent';
|
|
15
|
-
export { FEaaSWrapper } from './components/FEaaSWrapper';
|
|
16
|
-
export { DesignLibrary } from './components/DesignLibrary';
|
|
17
|
-
export { BYOCComponent, fetchBYOCComponentServerProps, } from './components/BYOCComponent';
|
|
18
|
-
export { BYOCWrapper } from './components/BYOCWrapper';
|
|
19
13
|
export { Link } from './components/Link';
|
|
20
14
|
export { File } from './components/File';
|
|
21
15
|
export { VisitorIdentification } from './components/VisitorIdentification';
|
|
@@ -26,7 +20,3 @@ export { withPlaceholder } from './enhancers/withPlaceholder';
|
|
|
26
20
|
export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
|
|
27
21
|
export { EditFrame } from './components/EditFrame';
|
|
28
22
|
export { ComponentBuilder } from './ComponentBuilder';
|
|
29
|
-
export { withFieldMetadata } from './enhancers/withFieldMetadata';
|
|
30
|
-
export { withEmptyFieldEditingComponent } from './enhancers/withEmptyFieldEditingComponent';
|
|
31
|
-
export { EditingScripts } from './components/EditingScripts';
|
|
32
|
-
export { DefaultEmptyFieldEditingComponentText, DefaultEmptyFieldEditingComponentImage, } from './components/DefaultEmptyFieldEditingComponents';
|
package/dist/esm/utils.js
CHANGED
|
@@ -9,7 +9,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { getFieldValue } from '@sitecore-jss/sitecore-jss/layout';
|
|
13
12
|
import { parse as styleParse } from 'style-attr';
|
|
14
13
|
// https://stackoverflow.com/a/10426674/9324
|
|
15
14
|
export const convertKebabCasetoCamelCase = (str) => str.replace(/^.|-./g, (letter, index) => index === 0 ? letter.toLowerCase() : letter.substr(1).toUpperCase());
|
|
@@ -94,16 +93,3 @@ export const getAttributesString = (attributes) => {
|
|
|
94
93
|
}
|
|
95
94
|
return attributesEntries.join(' ');
|
|
96
95
|
};
|
|
97
|
-
/**
|
|
98
|
-
* Used in FEAAS and BYOC implementations to convert datasource item field values into component props
|
|
99
|
-
* @param {ComponentFields} fields field collection from Sitecore
|
|
100
|
-
* @returns JSON object that can be used as props
|
|
101
|
-
*/
|
|
102
|
-
export const getDataFromFields = (fields) => {
|
|
103
|
-
let data = {};
|
|
104
|
-
data = Object.entries(fields).reduce((acc, [key]) => {
|
|
105
|
-
acc[key] = getFieldValue(fields, key);
|
|
106
|
-
return acc;
|
|
107
|
-
}, data);
|
|
108
|
-
return data;
|
|
109
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-react",
|
|
3
|
-
"version": "23.0.0-canary.
|
|
3
|
+
"version": "23.0.0-canary.21",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"url": "https://github.com/sitecore/jss/issues"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@sitecore-feaas/clientside": "^0.6.2",
|
|
30
29
|
"@testing-library/dom": "^10.4.1",
|
|
31
30
|
"@testing-library/react": "^16.3.0",
|
|
32
31
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -55,19 +54,17 @@
|
|
|
55
54
|
"typescript": "~4.9.3"
|
|
56
55
|
},
|
|
57
56
|
"peerDependencies": {
|
|
58
|
-
"@sitecore-cloudsdk/events": "^0.5.2",
|
|
59
|
-
"@sitecore-feaas/clientside": "^0.6.2",
|
|
60
57
|
"react": "^19.1.0",
|
|
61
58
|
"react-dom": "^19.1.0"
|
|
62
59
|
},
|
|
63
60
|
"dependencies": {
|
|
64
|
-
"@sitecore-jss/sitecore-jss": "23.0.0-canary.
|
|
61
|
+
"@sitecore-jss/sitecore-jss": "23.0.0-canary.21",
|
|
65
62
|
"fast-deep-equal": "^3.1.3",
|
|
66
63
|
"style-attr": "^1.3.0"
|
|
67
64
|
},
|
|
68
65
|
"description": "",
|
|
69
66
|
"types": "types/index.d.ts",
|
|
70
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "9f17c1ef59f6b506117d0956e9df69f32b14f4b9",
|
|
71
68
|
"files": [
|
|
72
69
|
"dist",
|
|
73
70
|
"types"
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
/// <reference types="@types/react" />
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { EditableFieldProps } from './sharedTypes';
|
|
4
|
-
|
|
5
|
-
export interface DateFieldProps extends EditableFieldProps<DateFieldProps> {
|
|
3
|
+
export interface DateFieldProps extends EditableFieldProps {
|
|
6
4
|
/** The date field data. */
|
|
7
5
|
[htmlAttributes: string]: unknown;
|
|
8
|
-
field:
|
|
6
|
+
field: {
|
|
9
7
|
value?: string;
|
|
10
8
|
editable?: string;
|
|
11
9
|
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/// <reference types="@types/react" />
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { EditableFieldProps } from './sharedTypes';
|
|
4
|
-
import { FieldMetadata } from '@sitecore-jss/sitecore-jss/layout';
|
|
5
3
|
export interface ImageFieldValue {
|
|
6
4
|
[attributeName: string]: unknown;
|
|
7
5
|
src?: string;
|
|
@@ -27,10 +25,10 @@ export interface ImageSizeParameters {
|
|
|
27
25
|
/** Image scale. Defaults to 1.0 */
|
|
28
26
|
sc?: number;
|
|
29
27
|
}
|
|
30
|
-
export interface ImageProps extends EditableFieldProps
|
|
28
|
+
export interface ImageProps extends EditableFieldProps {
|
|
31
29
|
[attributeName: string]: unknown;
|
|
32
30
|
/** Image field data (consistent with other field types) */
|
|
33
|
-
field?:
|
|
31
|
+
field?: ImageField | ImageFieldValue;
|
|
34
32
|
/**
|
|
35
33
|
* Parameters that will be attached to Sitecore media URLs
|
|
36
34
|
*/
|