@sitecore-jss/sitecore-jss-react 23.0.0-canary.8 → 23.0.0
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/LICENSE.txt +202 -202
- package/README.md +10 -10
- 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 +8 -44
- 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 +9 -45
- 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 +5 -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
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { MissingComponent } from './MissingComponent';
|
|
3
|
-
import {
|
|
3
|
+
import { isDynamicPlaceholder, getDynamicPlaceholderPattern, } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
4
|
import { constants } from '@sitecore-jss/sitecore-jss';
|
|
5
5
|
import { convertAttributesToReactProps } from '../utils';
|
|
6
6
|
import { HiddenRendering } from './HiddenRendering';
|
|
7
|
-
import { FEaaSComponent, FEAAS_COMPONENT_RENDERING_NAME } from './FEaaSComponent';
|
|
8
|
-
import { FEaaSWrapper, FEAAS_WRAPPER_RENDERING_NAME } from './FEaaSWrapper';
|
|
9
|
-
import { BYOCComponent, BYOC_COMPONENT_RENDERING_NAME } from './BYOCComponent';
|
|
10
|
-
import { BYOCWrapper, BYOC_WRAPPER_RENDERING_NAME } from './BYOCWrapper';
|
|
11
|
-
import { PlaceholderMetadata } from './PlaceholderMetadata';
|
|
12
7
|
import ErrorBoundary from './ErrorBoundary';
|
|
13
8
|
export class PlaceholderCommon extends React.Component {
|
|
14
9
|
constructor(props) {
|
|
@@ -19,13 +14,12 @@ export class PlaceholderCommon extends React.Component {
|
|
|
19
14
|
this.updateKeyAttributes = this.updateKeyAttributes.bind(this);
|
|
20
15
|
this.createRawElement = this.createRawElement.bind(this);
|
|
21
16
|
}
|
|
22
|
-
static getPlaceholderDataFromRenderingData(rendering, name
|
|
17
|
+
static getPlaceholderDataFromRenderingData(rendering, name) {
|
|
23
18
|
let result;
|
|
24
|
-
|
|
19
|
+
const phName = name.slice();
|
|
25
20
|
/**
|
|
26
21
|
* Process (SXA) dynamic placeholders
|
|
27
22
|
* Find and replace the matching dynamic placeholder e.g 'nameOfContainer-{*}' with the requested e.g. 'nameOfContainer-1'.
|
|
28
|
-
* For Metadata EditMode, we need to keep the raw placeholder name in place.
|
|
29
23
|
*/
|
|
30
24
|
if (rendering === null || rendering === void 0 ? void 0 : rendering.placeholders) {
|
|
31
25
|
Object.keys(rendering.placeholders).forEach((placeholder) => {
|
|
@@ -33,13 +27,8 @@ export class PlaceholderCommon extends React.Component {
|
|
|
33
27
|
? getDynamicPlaceholderPattern(placeholder)
|
|
34
28
|
: null;
|
|
35
29
|
if (patternPlaceholder && patternPlaceholder.test(phName)) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
rendering.placeholders[phName] = rendering.placeholders[placeholder];
|
|
41
|
-
delete rendering.placeholders[placeholder];
|
|
42
|
-
}
|
|
30
|
+
rendering.placeholders[phName] = rendering.placeholders[placeholder];
|
|
31
|
+
delete rendering.placeholders[placeholder];
|
|
43
32
|
}
|
|
44
33
|
});
|
|
45
34
|
}
|
|
@@ -72,11 +61,10 @@ export class PlaceholderCommon extends React.Component {
|
|
|
72
61
|
});
|
|
73
62
|
}
|
|
74
63
|
getComponentsForRenderingData(placeholderData) {
|
|
75
|
-
var _a;
|
|
76
64
|
const { name, fields: placeholderFields, params: placeholderParams, missingComponentComponent, hiddenRenderingComponent, passThroughComponentProps, modifyComponentProps, } = this.props;
|
|
77
65
|
const transformedComponents = placeholderData
|
|
78
66
|
.map((rendering, index) => {
|
|
79
|
-
var _a
|
|
67
|
+
var _a;
|
|
80
68
|
const key = rendering.uid
|
|
81
69
|
? rendering.uid
|
|
82
70
|
: `component-${index}`;
|
|
@@ -100,21 +88,6 @@ export class PlaceholderCommon extends React.Component {
|
|
|
100
88
|
else {
|
|
101
89
|
component = this.getComponentForRendering(componentRendering);
|
|
102
90
|
}
|
|
103
|
-
// Fallback/defaults for Sitecore Component renderings (in case not defined in component factory)
|
|
104
|
-
if (!component) {
|
|
105
|
-
if (componentRendering.componentName === FEAAS_COMPONENT_RENDERING_NAME) {
|
|
106
|
-
component = FEaaSComponent;
|
|
107
|
-
}
|
|
108
|
-
else if (componentRendering.componentName === FEAAS_WRAPPER_RENDERING_NAME) {
|
|
109
|
-
component = FEaaSWrapper;
|
|
110
|
-
}
|
|
111
|
-
else if (componentRendering.componentName === BYOC_COMPONENT_RENDERING_NAME) {
|
|
112
|
-
component = BYOCComponent;
|
|
113
|
-
}
|
|
114
|
-
else if (componentRendering.componentName === BYOC_WRAPPER_RENDERING_NAME) {
|
|
115
|
-
component = BYOCWrapper;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
91
|
if (!component) {
|
|
119
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.`);
|
|
120
93
|
component = missingComponentComponent !== null && missingComponentComponent !== void 0 ? missingComponentComponent : MissingComponent;
|
|
@@ -133,26 +106,15 @@ export class PlaceholderCommon extends React.Component {
|
|
|
133
106
|
if (!isEmpty) {
|
|
134
107
|
// assign type based on passed element - type='text/sitecore' should be ignored when renderEach Placeholder prop function is being used
|
|
135
108
|
const type = rendered.props.type === 'text/sitecore' ? rendered.props.type : '';
|
|
136
|
-
// the registered BYOC components are imported using dynamic(), so we need to account for that when passing the isDynamic prop to ErrorBoundary
|
|
137
|
-
const isByocWrapper = componentRendering.componentName === BYOC_WRAPPER_RENDERING_NAME;
|
|
138
109
|
// all dynamic elements will have a separate render prop
|
|
139
110
|
const isDynamicComponent = !!((_a = component.render) === null || _a === void 0 ? void 0 : _a.preload);
|
|
140
111
|
// wrapping with error boundary could cause problems in case where parent component uses withPlaceholder HOC and tries to access its children props
|
|
141
112
|
// that's why we need to expose element's props here
|
|
142
|
-
rendered = (React.createElement(ErrorBoundary, Object.assign({ key: rendered.type + '-' + index, errorComponent: this.props.errorComponent, componentLoadingMessage: this.props.componentLoadingMessage, type: type, isDynamic: isDynamicComponent
|
|
143
|
-
}
|
|
144
|
-
// if editMode is equal to 'metadata' then emit shallow chromes for hydration in Pages
|
|
145
|
-
if (((_b = this.props.sitecoreContext) === null || _b === void 0 ? void 0 : _b.editMode) === EditMode.Metadata) {
|
|
146
|
-
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));
|
|
147
114
|
}
|
|
148
115
|
return rendered;
|
|
149
116
|
})
|
|
150
117
|
.filter((element) => element); // remove nulls
|
|
151
|
-
if (((_a = this.props.sitecoreContext) === null || _a === void 0 ? void 0 : _a.editMode) === EditMode.Metadata) {
|
|
152
|
-
return [
|
|
153
|
-
React.createElement(PlaceholderMetadata, { key: this.props.rendering.uid, placeholderName: name, rendering: this.props.rendering }, transformedComponents),
|
|
154
|
-
];
|
|
155
|
-
}
|
|
156
118
|
return transformedComponents;
|
|
157
119
|
}
|
|
158
120
|
getComponentForRendering(renderingDefinition) {
|
|
@@ -184,6 +146,8 @@ export class PlaceholderCommon extends React.Component {
|
|
|
184
146
|
if (!Array.isArray(attributes) && attributes && attributes.chrometype === 'placeholder') {
|
|
185
147
|
props.phkey = elem.attributes.key; // props that get rendered as dom attribute names need to be lowercase, otherwise React complains.
|
|
186
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;
|
|
187
151
|
}
|
|
188
152
|
return React.createElement(elem.name, props);
|
|
189
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
|
|
3
|
+
"version": "23.0.0",
|
|
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
|
|
61
|
+
"@sitecore-jss/sitecore-jss": "23.0.0",
|
|
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": "df3fb1582d7a53c14a3e3901d3561436f5110130",
|
|
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
|
*/
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/// <reference types="@types/react" />
|
|
2
1
|
import React, { RefAttributes } from 'react';
|
|
3
2
|
import { EditableFieldProps } from './sharedTypes';
|
|
4
|
-
import { FieldMetadata } from '@sitecore-jss/sitecore-jss/layout';
|
|
5
3
|
export interface LinkFieldValue {
|
|
6
4
|
[attributeName: string]: unknown;
|
|
7
5
|
href?: string;
|
|
@@ -19,13 +17,13 @@ export interface LinkField {
|
|
|
19
17
|
editableFirstPart?: string;
|
|
20
18
|
editableLastPart?: string;
|
|
21
19
|
}
|
|
22
|
-
export type LinkProps = EditableFieldProps
|
|
20
|
+
export type LinkProps = EditableFieldProps & React.AnchorHTMLAttributes<HTMLAnchorElement> & RefAttributes<HTMLAnchorElement> & {
|
|
23
21
|
/** The link field data. */
|
|
24
|
-
field:
|
|
22
|
+
field: LinkField | LinkFieldValue;
|
|
25
23
|
/**
|
|
26
24
|
* Displays a link text ('description' in Sitecore) even when children exist
|
|
27
25
|
* NOTE: when in Sitecore Experience Editor, this setting is ignored due to technical limitations, and the description is always rendered.
|
|
28
26
|
*/
|
|
29
27
|
showLinkTextWithChildrenPresent?: boolean;
|
|
30
28
|
};
|
|
31
|
-
export declare const Link: React.
|
|
29
|
+
export declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="@types/react" />
|
|
2
1
|
import React, { ComponentType } from 'react';
|
|
3
2
|
import { ComponentFactory } from './sharedTypes';
|
|
4
|
-
import { ComponentRendering, RouteData, Field, Item, HtmlElementRendering
|
|
3
|
+
import { ComponentRendering, RouteData, Field, Item, HtmlElementRendering } from '@sitecore-jss/sitecore-jss/layout';
|
|
5
4
|
import { SitecoreContextValue } from './SitecoreContext';
|
|
6
5
|
type ErrorComponentProps = {
|
|
7
6
|
[prop: string]: unknown;
|
|
@@ -87,7 +86,7 @@ export declare class PlaceholderCommon<T extends PlaceholderProps> extends React
|
|
|
87
86
|
error?: Error;
|
|
88
87
|
}>;
|
|
89
88
|
constructor(props: T);
|
|
90
|
-
static getPlaceholderDataFromRenderingData(rendering: ComponentRendering | RouteData, name: string
|
|
89
|
+
static getPlaceholderDataFromRenderingData(rendering: ComponentRendering | RouteData, name: string): (ComponentRendering<import("@sitecore-jss/sitecore-jss/layout").ComponentFields> | HtmlElementRendering)[];
|
|
91
90
|
componentDidMount(): void;
|
|
92
91
|
componentDidUpdate(): void;
|
|
93
92
|
componentDidCatch(error: Error): void;
|
|
@@ -96,7 +95,9 @@ export declare class PlaceholderCommon<T extends PlaceholderProps> extends React
|
|
|
96
95
|
} | {
|
|
97
96
|
styles: string;
|
|
98
97
|
};
|
|
99
|
-
getComponentsForRenderingData(placeholderData: (ComponentRendering | HtmlElementRendering)[]): React.
|
|
98
|
+
getComponentsForRenderingData(placeholderData: (ComponentRendering | HtmlElementRendering)[]): React.ReactElement<{
|
|
99
|
+
[attr: string]: unknown;
|
|
100
|
+
}, string | React.JSXElementConstructor<any>>[];
|
|
100
101
|
getComponentForRendering(renderingDefinition: ComponentRendering): ComponentType | null;
|
|
101
102
|
addRef(nodeRef: Element): void;
|
|
102
103
|
createRawElement(elem: HtmlElementRendering, baseProps: {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/// <reference types="@types/react" />
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { EditableFieldProps } from './sharedTypes';
|
|
4
|
-
|
|
5
|
-
export interface RichTextField extends FieldMetadata {
|
|
3
|
+
export interface RichTextField {
|
|
6
4
|
value?: string;
|
|
7
5
|
editable?: string;
|
|
8
6
|
}
|
|
9
|
-
export interface RichTextProps extends EditableFieldProps
|
|
7
|
+
export interface RichTextProps extends EditableFieldProps {
|
|
10
8
|
[htmlAttributes: string]: unknown;
|
|
11
9
|
/** The rich text field data. */
|
|
12
10
|
field?: RichTextField;
|
|
@@ -16,4 +14,4 @@ export interface RichTextProps extends EditableFieldProps<RichTextProps> {
|
|
|
16
14
|
*/
|
|
17
15
|
tag?: string;
|
|
18
16
|
}
|
|
19
|
-
export declare const RichText: React.
|
|
17
|
+
export declare const RichText: React.ForwardRefExoticComponent<Omit<RichTextProps, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
@@ -1,35 +1,14 @@
|
|
|
1
|
-
/// <reference types="@types/react" />
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { ComponentFactory } from './sharedTypes';
|
|
4
3
|
import { LayoutServiceContext, LayoutServiceData, RouteData } from '../index';
|
|
5
4
|
export interface SitecoreContextProps {
|
|
6
5
|
componentFactory: ComponentFactory;
|
|
7
6
|
layoutData?: LayoutServiceData;
|
|
8
|
-
/**
|
|
9
|
-
* API settings to connect to Sitecore.
|
|
10
|
-
*/
|
|
11
|
-
api?: {
|
|
12
|
-
/**
|
|
13
|
-
* Sitecore XM Cloud Edge endpoint credentials for Sitecore connection.
|
|
14
|
-
*/
|
|
15
|
-
edge?: {
|
|
16
|
-
/**
|
|
17
|
-
* A unified identifier used to connect and retrieve data from XM Cloud instance
|
|
18
|
-
*/
|
|
19
|
-
contextId: string;
|
|
20
|
-
/**
|
|
21
|
-
* XM Cloud endpoint that the app will communicate and retrieve data from
|
|
22
|
-
* @default https://edge-platform.sitecorecloud.io
|
|
23
|
-
*/
|
|
24
|
-
edgeUrl?: string;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
7
|
children: React.ReactNode;
|
|
28
8
|
}
|
|
29
9
|
export interface SitecoreContextState {
|
|
30
10
|
setContext: (value: SitecoreContextValue | LayoutServiceData) => void;
|
|
31
11
|
context: SitecoreContextValue;
|
|
32
|
-
api?: SitecoreContextProps['api'];
|
|
33
12
|
}
|
|
34
13
|
export declare const SitecoreContextReactContext: React.Context<SitecoreContextState>;
|
|
35
14
|
export declare const ComponentFactoryReactContext: React.Context<ComponentFactory>;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/// <reference types="@types/react" />
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { EditableFieldProps } from './sharedTypes';
|
|
4
|
-
|
|
5
|
-
export interface TextField extends FieldMetadata {
|
|
3
|
+
export interface TextField {
|
|
6
4
|
value?: string | number;
|
|
7
5
|
editable?: string;
|
|
8
6
|
}
|
|
9
|
-
export interface TextProps extends EditableFieldProps
|
|
7
|
+
export interface TextProps extends EditableFieldProps {
|
|
10
8
|
[htmlAttributes: string]: unknown;
|
|
11
9
|
/** The text field data. */
|
|
12
10
|
field?: TextField;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="@types/react" />
|
|
2
1
|
import { ComponentType } from 'react';
|
|
3
2
|
/**
|
|
4
3
|
* @param {string} componentName component to be imported from the component factory
|
|
@@ -16,17 +15,11 @@ export type JssComponentType = ComponentType & {
|
|
|
16
15
|
/**
|
|
17
16
|
* Shared editing field props
|
|
18
17
|
*/
|
|
19
|
-
export interface EditableFieldProps
|
|
18
|
+
export interface EditableFieldProps {
|
|
20
19
|
/**
|
|
21
20
|
* Can be used to explicitly disable inline editing.
|
|
22
21
|
* If true and `field.editable` has a value, then `field.editable` will be processed and rendered as component output. If false, `field.editable` value will be ignored and not rendered.
|
|
23
22
|
* @default true
|
|
24
23
|
*/
|
|
25
24
|
editable?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* -- Edit Mode Metadata --
|
|
28
|
-
*
|
|
29
|
-
* Custom element to render in Pages in Metadata edit mode if field value is empty
|
|
30
|
-
*/
|
|
31
|
-
emptyFieldEditingComponent?: React.ComponentClass<EmptyFieldEditingComponentProps> | React.FC<EmptyFieldEditingComponentProps>;
|
|
32
25
|
}
|