@sitecore-content-sdk/react 1.1.0-canary.8 → 1.2.0-canary.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/dist/cjs/components/Date.js +3 -1
- package/dist/cjs/components/DesignLibrary.js +61 -22
- package/dist/cjs/components/EditingScripts.js +8 -2
- package/dist/cjs/components/FEaaSComponent.js +1 -2
- package/dist/cjs/components/File.js +1 -3
- package/dist/cjs/components/Image.js +1 -0
- package/dist/cjs/components/Link.js +4 -3
- package/dist/cjs/components/RichText.js +8 -4
- package/dist/cjs/components/Text.js +1 -1
- package/dist/cjs/enhancers/withComponentMap.js +1 -3
- package/dist/cjs/enhancers/withEmptyFieldEditingComponent.js +0 -2
- package/dist/cjs/enhancers/withFieldMetadata.js +0 -2
- package/dist/cjs/enhancers/withPlaceholder.js +2 -1
- package/dist/esm/components/Date.js +3 -1
- package/dist/esm/components/DesignLibrary.js +61 -22
- package/dist/esm/components/EditingScripts.js +8 -2
- package/dist/esm/components/FEaaSComponent.js +1 -2
- package/dist/esm/components/File.js +1 -3
- package/dist/esm/components/Image.js +1 -0
- package/dist/esm/components/Link.js +4 -3
- package/dist/esm/components/RichText.js +8 -4
- package/dist/esm/components/Text.js +1 -1
- package/dist/esm/enhancers/withComponentMap.js +1 -3
- package/dist/esm/enhancers/withEmptyFieldEditingComponent.js +0 -2
- package/dist/esm/enhancers/withFieldMetadata.js +0 -2
- package/dist/esm/enhancers/withPlaceholder.js +2 -1
- package/package.json +14 -5
- package/types/components/DesignLibrary.d.ts +7 -4
|
@@ -20,7 +20,9 @@ const withFieldMetadata_1 = require("../enhancers/withFieldMetadata");
|
|
|
20
20
|
const withEmptyFieldEditingComponent_1 = require("../enhancers/withEmptyFieldEditingComponent");
|
|
21
21
|
const DefaultEmptyFieldEditingComponents_1 = require("./DefaultEmptyFieldEditingComponents");
|
|
22
22
|
const layout_1 = require("@sitecore-content-sdk/core/layout");
|
|
23
|
-
exports.DateField = (0, withFieldMetadata_1.withFieldMetadata)((0, withEmptyFieldEditingComponent_1.withEmptyFieldEditingComponent)(
|
|
23
|
+
exports.DateField = (0, withFieldMetadata_1.withFieldMetadata)((0, withEmptyFieldEditingComponent_1.withEmptyFieldEditingComponent)(
|
|
24
|
+
// eslint-disable-next-line no-unused-vars
|
|
25
|
+
(_a) => {
|
|
24
26
|
var { field, tag, editable = true, render } = _a, otherProps = __rest(_a, ["field", "tag", "editable", "render"]);
|
|
25
27
|
if ((0, layout_1.isFieldValueEmpty)(field)) {
|
|
26
28
|
return null;
|
|
@@ -32,6 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
35
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
45
|
exports.DesignLibrary = exports.VariantGeneration = exports.__mockDependencies = void 0;
|
|
37
46
|
/* eslint-disable jsdoc/require-param */
|
|
@@ -61,10 +70,7 @@ const Preview = () => {
|
|
|
61
70
|
// useEffect may execute multiple times on single render (i.e. in dev) - but we only want to fire ready event once
|
|
62
71
|
let componentReady = false;
|
|
63
72
|
// have an up-to-date layout state between re-renders (SSR re-render excluded)
|
|
64
|
-
const persistedRoot = (0, react_1.useMemo)(() => (Object.assign(Object.assign({}, (rootComponent || {})), rootUpdate)), [
|
|
65
|
-
rootComponent,
|
|
66
|
-
rootUpdate,
|
|
67
|
-
]);
|
|
73
|
+
const persistedRoot = (0, react_1.useMemo)(() => (Object.assign(Object.assign({}, (rootComponent || {})), rootUpdate)), [rootComponent, rootUpdate]);
|
|
68
74
|
route.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER][0] = persistedRoot;
|
|
69
75
|
(0, react_1.useEffect)(() => {
|
|
70
76
|
// useEffect will fire when components are ready - and we inform the whole wide world of it too
|
|
@@ -127,31 +133,64 @@ const VariantGeneration = (props) => {
|
|
|
127
133
|
const rendering = route === null || route === void 0 ? void 0 : route.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER][0];
|
|
128
134
|
const [renderKey, setRenderKey] = (0, react_1.useState)(0);
|
|
129
135
|
const [initError, setInitError] = (0, react_1.useState)(false);
|
|
136
|
+
const [importMapError, setImportMapError] = (0, react_1.useState)(false);
|
|
130
137
|
const [Component, setComponent] = (0, react_1.useState)(null);
|
|
131
|
-
if (!props.importMap) {
|
|
132
|
-
return react_1.default.createElement("div", null, "No import map found. Please check your import map.");
|
|
133
|
-
}
|
|
134
138
|
if (!rendering) {
|
|
135
139
|
return react_1.default.createElement("div", null, "No component found in layout data. Please check your layout data.");
|
|
136
140
|
}
|
|
141
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
137
142
|
(0, react_1.useEffect)(() => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
let cancelled = false;
|
|
144
|
+
// since import map is loaded lazily, we only need to add preview event handler once the import map is loaded
|
|
145
|
+
// unsubscribe function for useEffect cleanup will also be returned once importMap promise has been resolved or rejected
|
|
146
|
+
let unsubscribe = undefined;
|
|
147
|
+
const init = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
|
+
let importMap = undefined;
|
|
149
|
+
if (!props.loadImportMap) {
|
|
150
|
+
console.error('No loadImportMap prop provided. Please provide a dynamic import map function for DesignLibrary.');
|
|
151
|
+
setImportMapError(true);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const importMapImport = yield props.loadImportMap();
|
|
156
|
+
importMap = importMapImport.default;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error('Error loading import map:', error);
|
|
160
|
+
setImportMapError(true);
|
|
142
161
|
return;
|
|
143
162
|
}
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
// account for component being unmounted while resolving async import map
|
|
164
|
+
if (cancelled)
|
|
165
|
+
return;
|
|
166
|
+
unsubscribe = addComponentPreviewHandler(importMap, (error, Component) => {
|
|
167
|
+
setRenderKey((key) => key + 1);
|
|
168
|
+
if (error) {
|
|
169
|
+
setInitError(true);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
setInitError(false);
|
|
173
|
+
setComponent(() => Component);
|
|
174
|
+
});
|
|
175
|
+
const importMapEvent = getDesignLibraryImportMapEvent(rendering.uid, importMap);
|
|
176
|
+
console.debug('Component Library: sending event', importMapEvent);
|
|
177
|
+
window.parent.postMessage(importMapEvent, '*');
|
|
178
|
+
const componentPropsEvent = getDesignLibraryComponentPropsEvent(rendering.uid, rendering.fields, rendering.params);
|
|
179
|
+
console.debug('Component Library: sending event', componentPropsEvent);
|
|
180
|
+
window.top.postMessage(componentPropsEvent, '*');
|
|
146
181
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
182
|
+
init();
|
|
183
|
+
// return function that calls unsubsubribe - if the component was mounted correctly
|
|
184
|
+
return () => {
|
|
185
|
+
cancelled = true;
|
|
186
|
+
if (unsubscribe) {
|
|
187
|
+
unsubscribe();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
154
190
|
}, []);
|
|
191
|
+
if (importMapError) {
|
|
192
|
+
return (react_1.default.createElement("div", null, "No dynamic import map loaded. Please check a dynamic import map function is passed into Design Library"));
|
|
193
|
+
}
|
|
155
194
|
if (initError) {
|
|
156
195
|
return react_1.default.createElement("div", { key: renderKey }, "Error during component initialization");
|
|
157
196
|
}
|
|
@@ -159,7 +198,7 @@ const VariantGeneration = (props) => {
|
|
|
159
198
|
react_1.default.createElement(Component, { fields: rendering.fields, params: rendering.params, key: renderKey }))) : (react_1.default.createElement("div", null, "Loading preview..."))));
|
|
160
199
|
};
|
|
161
200
|
exports.VariantGeneration = VariantGeneration;
|
|
162
|
-
const DesignLibrary = ({
|
|
201
|
+
const DesignLibrary = ({ loadImportMap }) => {
|
|
163
202
|
var _a;
|
|
164
203
|
const { page } = (0, withSitecore_1.useSitecore)();
|
|
165
204
|
const { isDesignLibrary } = page.mode;
|
|
@@ -168,7 +207,7 @@ const DesignLibrary = ({ importMap }) => {
|
|
|
168
207
|
return null;
|
|
169
208
|
}
|
|
170
209
|
if (isVariantGeneration) {
|
|
171
|
-
return react_1.default.createElement(exports.VariantGeneration, {
|
|
210
|
+
return react_1.default.createElement(exports.VariantGeneration, { loadImportMap: loadImportMap });
|
|
172
211
|
}
|
|
173
212
|
return react_1.default.createElement(Preview, null);
|
|
174
213
|
};
|
|
@@ -23,8 +23,14 @@ const EditingScripts = () => {
|
|
|
23
23
|
}
|
|
24
24
|
// In case of Design Library - render only the script for Design Library
|
|
25
25
|
if (mode.isDesignLibrary) {
|
|
26
|
-
// Add cache buster to the script URL
|
|
27
|
-
const
|
|
26
|
+
// Add cache buster to the script URL (format hh-dd-mm-yyyy, UTC)
|
|
27
|
+
const now = new Date();
|
|
28
|
+
const hour = String(now.getUTCHours()).padStart(2, '0');
|
|
29
|
+
const day = String(now.getUTCDate()).padStart(2, '0');
|
|
30
|
+
const month = String(now.getUTCMonth() + 1).padStart(2, '0');
|
|
31
|
+
const year = String(now.getUTCFullYear());
|
|
32
|
+
const cacheTimestamp = `${hour}-${day}-${month}-${year}`;
|
|
33
|
+
const scriptUrl = `${(0, editing_2.getDesignLibraryScriptLink)((_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl)}?cb=${cacheTimestamp}`;
|
|
28
34
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
29
35
|
react_1.default.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
30
36
|
}
|
|
@@ -119,8 +119,7 @@ function fetchComponentTemplate(src, params, revisionFallback) {
|
|
|
119
119
|
return template;
|
|
120
120
|
}
|
|
121
121
|
catch (error) {
|
|
122
|
-
console.error(`Fetch FEAAS component from ${src} failed. Ensure the component revision "${params.ComponentRevision ||
|
|
123
|
-
revisionFallback}" is present`);
|
|
122
|
+
console.error(`Fetch FEAAS component from ${src} failed. Ensure the component revision "${params.ComponentRevision || revisionFallback}" is present`);
|
|
124
123
|
throw error;
|
|
125
124
|
}
|
|
126
125
|
});
|
|
@@ -24,9 +24,7 @@ const File = (_a) => {
|
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
26
|
// handle link directly on field for forgetful devs
|
|
27
|
-
const file = (dynamicField.src
|
|
28
|
-
? field
|
|
29
|
-
: dynamicField.value);
|
|
27
|
+
const file = (dynamicField.src ? field : dynamicField.value);
|
|
30
28
|
if (!file) {
|
|
31
29
|
return null;
|
|
32
30
|
}
|
|
@@ -15,6 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.Image = void 0;
|
|
18
|
+
/* eslint-disable no-unused-vars */
|
|
18
19
|
const media_1 = require("@sitecore-content-sdk/core/media");
|
|
19
20
|
const react_1 = __importDefault(require("react"));
|
|
20
21
|
const utils_1 = require("../utils");
|
|
@@ -45,14 +45,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
45
45
|
};
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
47
|
exports.Link = void 0;
|
|
48
|
+
/* eslint-disable no-unused-expressions, @typescript-eslint/no-unused-expressions */
|
|
48
49
|
const react_1 = __importStar(require("react"));
|
|
49
50
|
const layout_1 = require("@sitecore-content-sdk/core/layout");
|
|
50
51
|
const withFieldMetadata_1 = require("../enhancers/withFieldMetadata");
|
|
51
52
|
const withEmptyFieldEditingComponent_1 = require("../enhancers/withEmptyFieldEditingComponent");
|
|
52
53
|
const DefaultEmptyFieldEditingComponents_1 = require("./DefaultEmptyFieldEditingComponents");
|
|
53
|
-
exports.Link = (0, withFieldMetadata_1.withFieldMetadata)((0, withEmptyFieldEditingComponent_1.withEmptyFieldEditingComponent)(
|
|
54
|
-
// eslint-disable-next-line
|
|
55
|
-
(
|
|
54
|
+
exports.Link = (0, withFieldMetadata_1.withFieldMetadata)((0, withEmptyFieldEditingComponent_1.withEmptyFieldEditingComponent)((0, react_1.forwardRef)(
|
|
55
|
+
// eslint-disable-next-line no-unused-vars
|
|
56
|
+
(_a, ref) => {
|
|
56
57
|
var { field, editable = true, showLinkTextWithChildrenPresent } = _a, otherProps = __rest(_a, ["field", "editable", "showLinkTextWithChildrenPresent"]);
|
|
57
58
|
const children = otherProps.children;
|
|
58
59
|
const dynamicField = field;
|
|
@@ -50,10 +50,14 @@ const withFieldMetadata_1 = require("../enhancers/withFieldMetadata");
|
|
|
50
50
|
const withEmptyFieldEditingComponent_1 = require("../enhancers/withEmptyFieldEditingComponent");
|
|
51
51
|
const DefaultEmptyFieldEditingComponents_1 = require("./DefaultEmptyFieldEditingComponents");
|
|
52
52
|
const layout_1 = require("@sitecore-content-sdk/core/layout");
|
|
53
|
-
exports.RichText = (0, withFieldMetadata_1.withFieldMetadata)((0, withEmptyFieldEditingComponent_1.withEmptyFieldEditingComponent)(
|
|
54
|
-
// eslint-disable-next-line
|
|
55
|
-
|
|
56
|
-
var
|
|
53
|
+
exports.RichText = (0, withFieldMetadata_1.withFieldMetadata)((0, withEmptyFieldEditingComponent_1.withEmptyFieldEditingComponent)((0, react_1.forwardRef)((
|
|
54
|
+
// eslint-disable-next-line no-unused-vars
|
|
55
|
+
_a, ref) => {
|
|
56
|
+
var
|
|
57
|
+
// eslint-disable-next-line no-unused-vars
|
|
58
|
+
{ field, tag = 'div', editable = true } = _a, otherProps = __rest(_a,
|
|
59
|
+
// eslint-disable-next-line no-unused-vars
|
|
60
|
+
["field", "tag", "editable"]);
|
|
57
61
|
if ((0, layout_1.isFieldValueEmpty)(field)) {
|
|
58
62
|
return null;
|
|
59
63
|
}
|
|
@@ -27,7 +27,7 @@ exports.Text = (0, withFieldMetadata_1.withFieldMetadata)((0, withEmptyFieldEdit
|
|
|
27
27
|
}
|
|
28
28
|
// can't use editable value if we want to output unencoded
|
|
29
29
|
if (!encode) {
|
|
30
|
-
// eslint-disable-next-line no-param-reassign
|
|
30
|
+
// eslint-disable-next-line no-param-reassign, no-unused-vars
|
|
31
31
|
editable = false;
|
|
32
32
|
}
|
|
33
33
|
let output = field.value === undefined ? '' : field.value;
|
|
@@ -19,8 +19,6 @@ function withComponentMap(Component) {
|
|
|
19
19
|
const context = (0, react_2.useContext)(SitecoreProvider_1.ComponentMapReactContext);
|
|
20
20
|
return react_1.default.createElement(Component, Object.assign({}, props, { componentMap: props.componentMap || context }));
|
|
21
21
|
}
|
|
22
|
-
WithComponentMap.displayName = `withComponentMap(${Component.displayName ||
|
|
23
|
-
Component.name ||
|
|
24
|
-
'Anonymous'})`;
|
|
22
|
+
WithComponentMap.displayName = `withComponentMap(${Component.displayName || Component.name || 'Anonymous'})`;
|
|
25
23
|
return WithComponentMap;
|
|
26
24
|
}
|
|
@@ -51,13 +51,11 @@ function withEmptyFieldEditingComponent(FieldComponent, options) {
|
|
|
51
51
|
return null;
|
|
52
52
|
};
|
|
53
53
|
if (options.isForwardRef) {
|
|
54
|
-
// eslint-disable-next-line react/display-name
|
|
55
54
|
return (0, react_1.forwardRef)((props, ref) => {
|
|
56
55
|
const EmptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
57
56
|
return (react_1.default.createElement(react_1.default.Fragment, null, (EmptyFieldEditingComponent && react_1.default.createElement(EmptyFieldEditingComponent, null)) || (react_1.default.createElement(FieldComponent, Object.assign({}, props, { ref: ref })))));
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
|
-
// eslint-disable-next-line react/display-name
|
|
61
59
|
return (props) => {
|
|
62
60
|
const EmptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
63
61
|
return (react_1.default.createElement(react_1.default.Fragment, null, (EmptyFieldEditingComponent && react_1.default.createElement(EmptyFieldEditingComponent, null)) || (react_1.default.createElement(FieldComponent, Object.assign({}, props)))));
|
|
@@ -43,7 +43,6 @@ const FieldMetadata_1 = require("../components/FieldMetadata");
|
|
|
43
43
|
*/
|
|
44
44
|
function withFieldMetadata(FieldComponent, isForwardRef = false) {
|
|
45
45
|
if (isForwardRef) {
|
|
46
|
-
// eslint-disable-next-line react/display-name
|
|
47
46
|
return (0, react_1.forwardRef)((props, ref) => {
|
|
48
47
|
var _a;
|
|
49
48
|
const { editable = true } = props;
|
|
@@ -55,7 +54,6 @@ function withFieldMetadata(FieldComponent, isForwardRef = false) {
|
|
|
55
54
|
react_1.default.createElement(FieldComponent, Object.assign({}, props, { ref: ref }))));
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
|
-
// eslint-disable-next-line react/display-name
|
|
59
57
|
return (props) => {
|
|
60
58
|
var _a;
|
|
61
59
|
const { editable = true } = props;
|
|
@@ -50,7 +50,8 @@ function withPlaceholder(placeholders, options) {
|
|
|
50
50
|
else {
|
|
51
51
|
placeholderData = PlaceholderCommon_1.PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, placeholder, childProps.page.mode.isEditing);
|
|
52
52
|
if (placeholderData) {
|
|
53
|
-
childProps[placeholder] =
|
|
53
|
+
childProps[placeholder] =
|
|
54
|
+
this.getComponentsForRenderingData(placeholderData);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
});
|
|
@@ -14,7 +14,9 @@ import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
|
14
14
|
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
15
15
|
import { DefaultEmptyFieldEditingComponentText } from './DefaultEmptyFieldEditingComponents';
|
|
16
16
|
import { isFieldValueEmpty } from '@sitecore-content-sdk/core/layout';
|
|
17
|
-
export const DateField = withFieldMetadata(withEmptyFieldEditingComponent(
|
|
17
|
+
export const DateField = withFieldMetadata(withEmptyFieldEditingComponent(
|
|
18
|
+
// eslint-disable-next-line no-unused-vars
|
|
19
|
+
(_a) => {
|
|
18
20
|
var { field, tag, editable = true, render } = _a, otherProps = __rest(_a, ["field", "tag", "editable", "render"]);
|
|
19
21
|
if (isFieldValueEmpty(field)) {
|
|
20
22
|
return null;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
/* eslint-disable jsdoc/require-param */
|
|
2
11
|
/* eslint-disable prefer-const */
|
|
3
12
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
@@ -24,10 +33,7 @@ const Preview = () => {
|
|
|
24
33
|
// useEffect may execute multiple times on single render (i.e. in dev) - but we only want to fire ready event once
|
|
25
34
|
let componentReady = false;
|
|
26
35
|
// have an up-to-date layout state between re-renders (SSR re-render excluded)
|
|
27
|
-
const persistedRoot = useMemo(() => (Object.assign(Object.assign({}, (rootComponent || {})), rootUpdate)), [
|
|
28
|
-
rootComponent,
|
|
29
|
-
rootUpdate,
|
|
30
|
-
]);
|
|
36
|
+
const persistedRoot = useMemo(() => (Object.assign(Object.assign({}, (rootComponent || {})), rootUpdate)), [rootComponent, rootUpdate]);
|
|
31
37
|
route.placeholders[EDITING_COMPONENT_PLACEHOLDER][0] = persistedRoot;
|
|
32
38
|
useEffect(() => {
|
|
33
39
|
// useEffect will fire when components are ready - and we inform the whole wide world of it too
|
|
@@ -90,38 +96,71 @@ export const VariantGeneration = (props) => {
|
|
|
90
96
|
const rendering = route === null || route === void 0 ? void 0 : route.placeholders[EDITING_COMPONENT_PLACEHOLDER][0];
|
|
91
97
|
const [renderKey, setRenderKey] = useState(0);
|
|
92
98
|
const [initError, setInitError] = useState(false);
|
|
99
|
+
const [importMapError, setImportMapError] = useState(false);
|
|
93
100
|
const [Component, setComponent] = useState(null);
|
|
94
|
-
if (!props.importMap) {
|
|
95
|
-
return React.createElement("div", null, "No import map found. Please check your import map.");
|
|
96
|
-
}
|
|
97
101
|
if (!rendering) {
|
|
98
102
|
return React.createElement("div", null, "No component found in layout data. Please check your layout data.");
|
|
99
103
|
}
|
|
104
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
100
105
|
useEffect(() => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
let cancelled = false;
|
|
107
|
+
// since import map is loaded lazily, we only need to add preview event handler once the import map is loaded
|
|
108
|
+
// unsubscribe function for useEffect cleanup will also be returned once importMap promise has been resolved or rejected
|
|
109
|
+
let unsubscribe = undefined;
|
|
110
|
+
const init = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
let importMap = undefined;
|
|
112
|
+
if (!props.loadImportMap) {
|
|
113
|
+
console.error('No loadImportMap prop provided. Please provide a dynamic import map function for DesignLibrary.');
|
|
114
|
+
setImportMapError(true);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
const importMapImport = yield props.loadImportMap();
|
|
119
|
+
importMap = importMapImport.default;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error('Error loading import map:', error);
|
|
123
|
+
setImportMapError(true);
|
|
105
124
|
return;
|
|
106
125
|
}
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
// account for component being unmounted while resolving async import map
|
|
127
|
+
if (cancelled)
|
|
128
|
+
return;
|
|
129
|
+
unsubscribe = addComponentPreviewHandler(importMap, (error, Component) => {
|
|
130
|
+
setRenderKey((key) => key + 1);
|
|
131
|
+
if (error) {
|
|
132
|
+
setInitError(true);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
setInitError(false);
|
|
136
|
+
setComponent(() => Component);
|
|
137
|
+
});
|
|
138
|
+
const importMapEvent = getDesignLibraryImportMapEvent(rendering.uid, importMap);
|
|
139
|
+
console.debug('Component Library: sending event', importMapEvent);
|
|
140
|
+
window.parent.postMessage(importMapEvent, '*');
|
|
141
|
+
const componentPropsEvent = getDesignLibraryComponentPropsEvent(rendering.uid, rendering.fields, rendering.params);
|
|
142
|
+
console.debug('Component Library: sending event', componentPropsEvent);
|
|
143
|
+
window.top.postMessage(componentPropsEvent, '*');
|
|
109
144
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
145
|
+
init();
|
|
146
|
+
// return function that calls unsubsubribe - if the component was mounted correctly
|
|
147
|
+
return () => {
|
|
148
|
+
cancelled = true;
|
|
149
|
+
if (unsubscribe) {
|
|
150
|
+
unsubscribe();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
117
153
|
}, []);
|
|
154
|
+
if (importMapError) {
|
|
155
|
+
return (React.createElement("div", null, "No dynamic import map loaded. Please check a dynamic import map function is passed into Design Library"));
|
|
156
|
+
}
|
|
118
157
|
if (initError) {
|
|
119
158
|
return React.createElement("div", { key: renderKey }, "Error during component initialization");
|
|
120
159
|
}
|
|
121
160
|
return (React.createElement("main", null, Component ? (React.createElement(ErrorBoundary, { uid: rendering.uid, renderKey: renderKey },
|
|
122
161
|
React.createElement(Component, { fields: rendering.fields, params: rendering.params, key: renderKey }))) : (React.createElement("div", null, "Loading preview..."))));
|
|
123
162
|
};
|
|
124
|
-
export const DesignLibrary = ({
|
|
163
|
+
export const DesignLibrary = ({ loadImportMap }) => {
|
|
125
164
|
var _a;
|
|
126
165
|
const { page } = useSitecore();
|
|
127
166
|
const { isDesignLibrary } = page.mode;
|
|
@@ -130,7 +169,7 @@ export const DesignLibrary = ({ importMap }) => {
|
|
|
130
169
|
return null;
|
|
131
170
|
}
|
|
132
171
|
if (isVariantGeneration) {
|
|
133
|
-
return React.createElement(VariantGeneration, {
|
|
172
|
+
return React.createElement(VariantGeneration, { loadImportMap: loadImportMap });
|
|
134
173
|
}
|
|
135
174
|
return React.createElement(Preview, null);
|
|
136
175
|
};
|
|
@@ -17,8 +17,14 @@ export const EditingScripts = () => {
|
|
|
17
17
|
}
|
|
18
18
|
// In case of Design Library - render only the script for Design Library
|
|
19
19
|
if (mode.isDesignLibrary) {
|
|
20
|
-
// Add cache buster to the script URL
|
|
21
|
-
const
|
|
20
|
+
// Add cache buster to the script URL (format hh-dd-mm-yyyy, UTC)
|
|
21
|
+
const now = new Date();
|
|
22
|
+
const hour = String(now.getUTCHours()).padStart(2, '0');
|
|
23
|
+
const day = String(now.getUTCDate()).padStart(2, '0');
|
|
24
|
+
const month = String(now.getUTCMonth() + 1).padStart(2, '0');
|
|
25
|
+
const year = String(now.getUTCFullYear());
|
|
26
|
+
const cacheTimestamp = `${hour}-${day}-${month}-${year}`;
|
|
27
|
+
const scriptUrl = `${getDesignLibraryScriptLink((_a = api === null || api === void 0 ? void 0 : api.edge) === null || _a === void 0 ? void 0 : _a.edgeUrl)}?cb=${cacheTimestamp}`;
|
|
22
28
|
return (React.createElement(React.Fragment, null,
|
|
23
29
|
React.createElement("script", { src: scriptUrl, suppressHydrationWarning: true })));
|
|
24
30
|
}
|
|
@@ -78,8 +78,7 @@ function fetchComponentTemplate(src, params, revisionFallback) {
|
|
|
78
78
|
return template;
|
|
79
79
|
}
|
|
80
80
|
catch (error) {
|
|
81
|
-
console.error(`Fetch FEAAS component from ${src} failed. Ensure the component revision "${params.ComponentRevision ||
|
|
82
|
-
revisionFallback}" is present`);
|
|
81
|
+
console.error(`Fetch FEAAS component from ${src} failed. Ensure the component revision "${params.ComponentRevision || revisionFallback}" is present`);
|
|
83
82
|
throw error;
|
|
84
83
|
}
|
|
85
84
|
});
|
|
@@ -18,9 +18,7 @@ export const File = (_a) => {
|
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
// handle link directly on field for forgetful devs
|
|
21
|
-
const file = (dynamicField.src
|
|
22
|
-
? field
|
|
23
|
-
: dynamicField.value);
|
|
21
|
+
const file = (dynamicField.src ? field : dynamicField.value);
|
|
24
22
|
if (!file) {
|
|
25
23
|
return null;
|
|
26
24
|
}
|
|
@@ -9,14 +9,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
+
/* eslint-disable no-unused-expressions, @typescript-eslint/no-unused-expressions */
|
|
12
13
|
import React, { forwardRef } from 'react';
|
|
13
14
|
import { isFieldValueEmpty } from '@sitecore-content-sdk/core/layout';
|
|
14
15
|
import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
15
16
|
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
16
17
|
import { DefaultEmptyFieldEditingComponentText } from './DefaultEmptyFieldEditingComponents';
|
|
17
|
-
export const Link = withFieldMetadata(withEmptyFieldEditingComponent(
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
|
|
18
|
+
export const Link = withFieldMetadata(withEmptyFieldEditingComponent(forwardRef(
|
|
19
|
+
// eslint-disable-next-line no-unused-vars
|
|
20
|
+
(_a, ref) => {
|
|
20
21
|
var { field, editable = true, showLinkTextWithChildrenPresent } = _a, otherProps = __rest(_a, ["field", "editable", "showLinkTextWithChildrenPresent"]);
|
|
21
22
|
const children = otherProps.children;
|
|
22
23
|
const dynamicField = field;
|
|
@@ -14,10 +14,14 @@ import { withFieldMetadata } from '../enhancers/withFieldMetadata';
|
|
|
14
14
|
import { withEmptyFieldEditingComponent } from '../enhancers/withEmptyFieldEditingComponent';
|
|
15
15
|
import { DefaultEmptyFieldEditingComponentText } from './DefaultEmptyFieldEditingComponents';
|
|
16
16
|
import { isFieldValueEmpty } from '@sitecore-content-sdk/core/layout';
|
|
17
|
-
export const RichText = withFieldMetadata(withEmptyFieldEditingComponent(
|
|
18
|
-
// eslint-disable-next-line
|
|
19
|
-
|
|
20
|
-
var
|
|
17
|
+
export const RichText = withFieldMetadata(withEmptyFieldEditingComponent(forwardRef((
|
|
18
|
+
// eslint-disable-next-line no-unused-vars
|
|
19
|
+
_a, ref) => {
|
|
20
|
+
var
|
|
21
|
+
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
{ field, tag = 'div', editable = true } = _a, otherProps = __rest(_a,
|
|
23
|
+
// eslint-disable-next-line no-unused-vars
|
|
24
|
+
["field", "tag", "editable"]);
|
|
21
25
|
if (isFieldValueEmpty(field)) {
|
|
22
26
|
return null;
|
|
23
27
|
}
|
|
@@ -21,7 +21,7 @@ export const Text = withFieldMetadata(withEmptyFieldEditingComponent((_a) => {
|
|
|
21
21
|
}
|
|
22
22
|
// can't use editable value if we want to output unencoded
|
|
23
23
|
if (!encode) {
|
|
24
|
-
// eslint-disable-next-line no-param-reassign
|
|
24
|
+
// eslint-disable-next-line no-param-reassign, no-unused-vars
|
|
25
25
|
editable = false;
|
|
26
26
|
}
|
|
27
27
|
let output = field.value === undefined ? '' : field.value;
|
|
@@ -13,8 +13,6 @@ export function withComponentMap(Component) {
|
|
|
13
13
|
const context = useContext(ComponentMapReactContext);
|
|
14
14
|
return React.createElement(Component, Object.assign({}, props, { componentMap: props.componentMap || context }));
|
|
15
15
|
}
|
|
16
|
-
WithComponentMap.displayName = `withComponentMap(${Component.displayName ||
|
|
17
|
-
Component.name ||
|
|
18
|
-
'Anonymous'})`;
|
|
16
|
+
WithComponentMap.displayName = `withComponentMap(${Component.displayName || Component.name || 'Anonymous'})`;
|
|
19
17
|
return WithComponentMap;
|
|
20
18
|
}
|
|
@@ -15,13 +15,11 @@ export function withEmptyFieldEditingComponent(FieldComponent, options) {
|
|
|
15
15
|
return null;
|
|
16
16
|
};
|
|
17
17
|
if (options.isForwardRef) {
|
|
18
|
-
// eslint-disable-next-line react/display-name
|
|
19
18
|
return forwardRef((props, ref) => {
|
|
20
19
|
const EmptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
21
20
|
return (React.createElement(React.Fragment, null, (EmptyFieldEditingComponent && React.createElement(EmptyFieldEditingComponent, null)) || (React.createElement(FieldComponent, Object.assign({}, props, { ref: ref })))));
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
|
-
// eslint-disable-next-line react/display-name
|
|
25
23
|
return (props) => {
|
|
26
24
|
const EmptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
27
25
|
return (React.createElement(React.Fragment, null, (EmptyFieldEditingComponent && React.createElement(EmptyFieldEditingComponent, null)) || (React.createElement(FieldComponent, Object.assign({}, props)))));
|
|
@@ -7,7 +7,6 @@ import { FieldMetadata } from '../components/FieldMetadata';
|
|
|
7
7
|
*/
|
|
8
8
|
export function withFieldMetadata(FieldComponent, isForwardRef = false) {
|
|
9
9
|
if (isForwardRef) {
|
|
10
|
-
// eslint-disable-next-line react/display-name
|
|
11
10
|
return forwardRef((props, ref) => {
|
|
12
11
|
var _a;
|
|
13
12
|
const { editable = true } = props;
|
|
@@ -19,7 +18,6 @@ export function withFieldMetadata(FieldComponent, isForwardRef = false) {
|
|
|
19
18
|
React.createElement(FieldComponent, Object.assign({}, props, { ref: ref }))));
|
|
20
19
|
});
|
|
21
20
|
}
|
|
22
|
-
// eslint-disable-next-line react/display-name
|
|
23
21
|
return (props) => {
|
|
24
22
|
var _a;
|
|
25
23
|
const { editable = true } = props;
|
|
@@ -44,7 +44,8 @@ export function withPlaceholder(placeholders, options) {
|
|
|
44
44
|
else {
|
|
45
45
|
placeholderData = PlaceholderCommon.getPlaceholderDataFromRenderingData(renderingData, placeholder, childProps.page.mode.isEditing);
|
|
46
46
|
if (placeholderData) {
|
|
47
|
-
childProps[placeholder] =
|
|
47
|
+
childProps[placeholder] =
|
|
48
|
+
this.getComponentsForRenderingData(placeholderData);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-canary.1",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@sitecore-feaas/clientside": "^0.6.0",
|
|
34
|
+
"@stylistic/eslint-plugin": "^5.2.2",
|
|
34
35
|
"@testing-library/dom": "^10.4.0",
|
|
35
36
|
"@testing-library/react": "^16.3.0",
|
|
36
37
|
"@types/chai": "^5.2.2",
|
|
@@ -41,14 +42,22 @@
|
|
|
41
42
|
"@types/react-dom": "^19.1.3",
|
|
42
43
|
"@types/sinon": "^17.0.4",
|
|
43
44
|
"@types/sinon-chai": "^4.0.0",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "8.39.0",
|
|
46
|
+
"@typescript-eslint/parser": "8.39.0",
|
|
44
47
|
"chai": "^4.3.7",
|
|
45
48
|
"chai-string": "^1.6.0",
|
|
46
49
|
"del-cli": "^6.0.0",
|
|
47
|
-
"eslint": "^
|
|
48
|
-
"eslint-
|
|
50
|
+
"eslint": "^9.32.0",
|
|
51
|
+
"eslint-config-prettier": "^10.1.8",
|
|
52
|
+
"eslint-plugin-import": "2.32.0",
|
|
53
|
+
"eslint-plugin-jsdoc": "52.0.3",
|
|
54
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
55
|
+
"eslint-plugin-react": "7.37.5",
|
|
56
|
+
"eslint-plugin-react-hooks": "5.2.0",
|
|
49
57
|
"jsdom": "^26.1.0",
|
|
50
58
|
"mocha": "^11.2.2",
|
|
51
59
|
"nyc": "^17.1.0",
|
|
60
|
+
"prettier": "^2.8.0",
|
|
52
61
|
"react": "^19.1.0",
|
|
53
62
|
"react-dom": "^19.1.0",
|
|
54
63
|
"sinon": "^20.0.0",
|
|
@@ -63,12 +72,12 @@
|
|
|
63
72
|
"react-dom": "^19.1.0"
|
|
64
73
|
},
|
|
65
74
|
"dependencies": {
|
|
66
|
-
"@sitecore-content-sdk/core": "1.
|
|
75
|
+
"@sitecore-content-sdk/core": "1.2.0-canary.1",
|
|
67
76
|
"fast-deep-equal": "^3.1.3"
|
|
68
77
|
},
|
|
69
78
|
"description": "",
|
|
70
79
|
"types": "types/index.d.ts",
|
|
71
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "565f6fc2a2cb57ddcaf3dddb6e0a416a996eeb80",
|
|
72
81
|
"files": [
|
|
73
82
|
"dist",
|
|
74
83
|
"types"
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { JSX } from 'react';
|
|
2
2
|
import * as codegen from '@sitecore-content-sdk/core/codegen';
|
|
3
3
|
export declare const __mockDependencies: (mocks: any) => void;
|
|
4
|
+
export type ImportMapImport = {
|
|
5
|
+
default: codegen.ImportEntry[];
|
|
6
|
+
};
|
|
4
7
|
type VariantGenerationProps = {
|
|
5
8
|
/**
|
|
6
9
|
* The import map to be used in variant generation mode.
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
loadImportMap?: () => Promise<ImportMapImport>;
|
|
9
12
|
};
|
|
10
13
|
/**
|
|
11
14
|
* This component is used to render the component in variant generation mode.
|
|
@@ -14,10 +17,10 @@ type VariantGenerationProps = {
|
|
|
14
17
|
export declare const VariantGeneration: (props: VariantGenerationProps) => JSX.Element;
|
|
15
18
|
type DesignLibraryProps = {
|
|
16
19
|
/**
|
|
17
|
-
* The import map to be used in variant generation mode.
|
|
20
|
+
* The dynamic import for import map to be used in variant generation mode.
|
|
18
21
|
* Currently it's optional but it will be required in the next major version.
|
|
19
22
|
*/
|
|
20
|
-
|
|
23
|
+
loadImportMap?: () => Promise<ImportMapImport>;
|
|
21
24
|
};
|
|
22
|
-
export declare const DesignLibrary: ({
|
|
25
|
+
export declare const DesignLibrary: ({ loadImportMap }: DesignLibraryProps) => JSX.Element;
|
|
23
26
|
export {};
|