@sitecore-content-sdk/react 1.1.0-canary.9 → 1.1.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 +11 -11
- package/dist/cjs/components/Date.js +3 -1
- package/dist/cjs/components/DefaultEmptyFieldEditingComponents.js +4 -4
- package/dist/cjs/components/DesignLibrary.js +118 -92
- 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 +12 -7
- 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/DefaultEmptyFieldEditingComponents.js +4 -4
- package/dist/esm/components/DesignLibrary.js +118 -91
- 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 +12 -7
- package/dist/esm/enhancers/withFieldMetadata.js +0 -2
- package/dist/esm/enhancers/withPlaceholder.js +2 -1
- package/package.json +14 -5
- package/types/components/Date.d.ts +1 -1
- package/types/components/DefaultEmptyFieldEditingComponents.d.ts +8 -2
- package/types/components/DesignLibrary.d.ts +17 -14
- package/types/components/Image.d.ts +1 -1
- package/types/components/Link.d.ts +1 -1
- package/types/components/RichText.d.ts +1 -1
- package/types/components/Text.d.ts +1 -1
- package/types/components/sharedTypes/props.d.ts +2 -2
- package/types/enhancers/withEmptyFieldEditingComponent.d.ts +3 -3
|
@@ -32,8 +32,17 @@ 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
|
-
exports.DesignLibrary = exports.
|
|
45
|
+
exports.DesignLibrary = exports.__mockDependencies = void 0;
|
|
37
46
|
/* eslint-disable jsdoc/require-param */
|
|
38
47
|
/* eslint-disable prefer-const */
|
|
39
48
|
const react_1 = __importStar(require("react"));
|
|
@@ -42,53 +51,31 @@ const layout_1 = require("@sitecore-content-sdk/core/layout");
|
|
|
42
51
|
const editing_1 = require("@sitecore-content-sdk/core/editing");
|
|
43
52
|
const codegen = __importStar(require("@sitecore-content-sdk/core/codegen"));
|
|
44
53
|
const withSitecore_1 = require("../enhancers/withSitecore");
|
|
54
|
+
const PlaceholderMetadata_1 = require("./PlaceholderMetadata");
|
|
45
55
|
let { getDesignLibraryImportMapEvent, getDesignLibraryComponentPropsEvent, addComponentPreviewHandler, } = codegen;
|
|
46
56
|
const __mockDependencies = (mocks) => {
|
|
47
57
|
addComponentPreviewHandler = mocks.addComponentPreviewHandler;
|
|
48
58
|
};
|
|
49
59
|
exports.__mockDependencies = __mockDependencies;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
(0, react_1.useEffect)(() => {
|
|
70
|
-
// useEffect will fire when components are ready - and we inform the whole wide world of it too
|
|
71
|
-
if (!componentReady) {
|
|
72
|
-
componentReady = true;
|
|
73
|
-
window.top.postMessage((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.READY, rootComponent.uid), '*');
|
|
74
|
-
}
|
|
75
|
-
const unsubscribe = (0, editing_1.addComponentUpdateHandler)(persistedRoot, (updatedRoot) => {
|
|
76
|
-
setRootUpdate(Object.assign({}, updatedRoot));
|
|
77
|
-
setRenderKey((key) => key + 1);
|
|
78
|
-
});
|
|
79
|
-
// useEffect will cleanup event handler on re-render
|
|
80
|
-
return unsubscribe;
|
|
81
|
-
}, []);
|
|
82
|
-
(0, react_1.useEffect)(() => {
|
|
83
|
-
// Send a rendered event only as effect of a component update command
|
|
84
|
-
if (renderKey === 0) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
window.top.postMessage((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.RENDERED, rootComponent.uid), '*');
|
|
88
|
-
}, [renderKey, rootComponent.uid]);
|
|
89
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
90
|
-
react_1.default.createElement("main", null,
|
|
91
|
-
react_1.default.createElement("div", { id: layout_1.EDITING_COMPONENT_ID }, route && (react_1.default.createElement(Placeholder_1.Placeholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
|
|
60
|
+
const sendErrorEvent = (uid, error, type) => {
|
|
61
|
+
const errorEvent = codegen.getDesignLibraryComponentPreviewErrorEvent(uid, error, type);
|
|
62
|
+
console.error('Component Library: sending error event', errorEvent);
|
|
63
|
+
if (typeof window !== 'undefined') {
|
|
64
|
+
const target = window.parent && window.parent !== window ? window.parent : window;
|
|
65
|
+
target.postMessage(errorEvent, '*');
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const postToDL = (evt) => {
|
|
69
|
+
if (typeof window === 'undefined')
|
|
70
|
+
return;
|
|
71
|
+
const target = window.parent && window.parent !== window ? window.parent : window;
|
|
72
|
+
try {
|
|
73
|
+
console.log('Component Library: sending event', evt === null || evt === void 0 ? void 0 : evt.name, evt);
|
|
74
|
+
target.postMessage(evt, '*');
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error('Component Library: postMessage failed', err, evt);
|
|
78
|
+
}
|
|
92
79
|
};
|
|
93
80
|
class ErrorBoundary extends react_1.default.Component {
|
|
94
81
|
constructor() {
|
|
@@ -106,9 +93,7 @@ class ErrorBoundary extends react_1.default.Component {
|
|
|
106
93
|
}
|
|
107
94
|
}
|
|
108
95
|
componentDidCatch(error) {
|
|
109
|
-
|
|
110
|
-
console.debug('Component Library: sending error event', errorEvent);
|
|
111
|
-
window.top.postMessage(errorEvent, '*');
|
|
96
|
+
sendErrorEvent(this.props.uid, error, codegen.DesignLibraryPreviewError.Render);
|
|
112
97
|
}
|
|
113
98
|
render() {
|
|
114
99
|
if (this.state.hasError) {
|
|
@@ -118,58 +103,99 @@ class ErrorBoundary extends react_1.default.Component {
|
|
|
118
103
|
}
|
|
119
104
|
}
|
|
120
105
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
106
|
+
* Design Library component.
|
|
107
|
+
*
|
|
108
|
+
* Renders the **real** Sitecore component for `library` / `library-metadata` modes and,
|
|
109
|
+
* when generation is enabled (`page.mode.designLibrary.isVariantGeneration === true`),
|
|
110
|
+
* wires the **variant generation** handshake so the parent (DL Studio) can send
|
|
111
|
+
* generated code to preview and iterate on.
|
|
112
|
+
* @param {DesignLibraryProps} props
|
|
113
|
+
* @param {() => Promise<{ default: import('../codegen').ImportEntry[] }>} [props.loadImportMap] Optional async loader that resolves to the import-map used to resolve the generated component’s imports. Required when `isVariantGeneration` is true.
|
|
114
|
+
* @returns {JSX.Element} The preview surface, or `null` when not in Design Library mode.
|
|
123
115
|
*/
|
|
124
|
-
const
|
|
116
|
+
const DesignLibrary = ({ loadImportMap }) => {
|
|
117
|
+
var _a, _b;
|
|
125
118
|
const { page } = (0, withSitecore_1.useSitecore)();
|
|
126
|
-
const
|
|
127
|
-
const rendering = route === null || route === void 0 ? void 0 : route.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER][0];
|
|
119
|
+
const route = page.layout.sitecore.route;
|
|
120
|
+
const rendering = (_a = route === null || route === void 0 ? void 0 : route.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
|
|
121
|
+
const { isDesignLibrary } = page.mode;
|
|
122
|
+
const isVariantGeneration = (_b = page.mode.designLibrary) === null || _b === void 0 ? void 0 : _b.isVariantGeneration;
|
|
123
|
+
const [propsState, setPropsState] = (0, react_1.useState)({
|
|
124
|
+
fields: rendering === null || rendering === void 0 ? void 0 : rendering.fields,
|
|
125
|
+
params: rendering === null || rendering === void 0 ? void 0 : rendering.params,
|
|
126
|
+
});
|
|
128
127
|
const [renderKey, setRenderKey] = (0, react_1.useState)(0);
|
|
129
|
-
const [initError, setInitError] = (0, react_1.useState)(false);
|
|
130
128
|
const [Component, setComponent] = (0, react_1.useState)(null);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return react_1.default.createElement("div", null, "No component found in layout data. Please check your layout data.");
|
|
136
|
-
}
|
|
129
|
+
const isGeneratedComponentActive = !!Component;
|
|
130
|
+
if (!isDesignLibrary)
|
|
131
|
+
return null;
|
|
132
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
137
133
|
(0, react_1.useEffect)(() => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
134
|
+
postToDL((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.READY, rendering.uid));
|
|
135
|
+
if (!isVariantGeneration) {
|
|
136
|
+
requestAnimationFrame(() => {
|
|
137
|
+
setRenderKey((k) => (k === 0 ? k + 1 : k));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const unsubUpdate = (0, editing_1.addComponentUpdateHandler)(rendering, (updated) => {
|
|
141
|
+
setPropsState({ fields: updated.fields, params: updated.params });
|
|
142
|
+
setRenderKey((k) => k + 1);
|
|
143
|
+
});
|
|
144
|
+
// useEffect will cleanup event handler on re-render
|
|
145
|
+
return () => unsubUpdate && unsubUpdate();
|
|
146
|
+
}, [isVariantGeneration, rendering]);
|
|
147
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
148
|
+
(0, react_1.useEffect)(() => {
|
|
149
|
+
// Send a rendered event only as effect of a component update command
|
|
150
|
+
if (renderKey === 0)
|
|
151
|
+
return;
|
|
152
|
+
postToDL((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.RENDERED, rendering.uid));
|
|
153
|
+
}, [renderKey, rendering]);
|
|
154
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
155
|
+
(0, react_1.useEffect)(() => {
|
|
156
|
+
if (!isDesignLibrary || !isVariantGeneration)
|
|
157
|
+
return undefined;
|
|
158
|
+
let cancelled = false;
|
|
159
|
+
// since import map is loaded lazily, we only need to add preview event handler once the import map is loaded
|
|
160
|
+
// unsubscribe function for useEffect cleanup will also be returned once importMap promise has been resolved or rejected
|
|
161
|
+
let unsubscribe;
|
|
162
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
if (!loadImportMap) {
|
|
164
|
+
sendErrorEvent(rendering.uid, 'No loadImportMap provided', codegen.DesignLibraryPreviewError.RenderInit);
|
|
142
165
|
return;
|
|
143
166
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
let importMap;
|
|
168
|
+
try {
|
|
169
|
+
const mod = yield loadImportMap();
|
|
170
|
+
importMap = mod.default;
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
sendErrorEvent(rendering.uid, `Error loading import map: ${e}`, codegen.DesignLibraryPreviewError.RenderInit);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
// account for component being unmounted while resolving async import map
|
|
177
|
+
if (cancelled)
|
|
178
|
+
return;
|
|
179
|
+
unsubscribe = addComponentPreviewHandler(importMap, (error, Component) => {
|
|
180
|
+
// Error event is already sent in the addComponentPreviewHandler
|
|
181
|
+
if (error)
|
|
182
|
+
return;
|
|
183
|
+
setComponent(() => Component);
|
|
184
|
+
setRenderKey((k) => k + 1);
|
|
185
|
+
});
|
|
186
|
+
const importMapEvent = getDesignLibraryImportMapEvent(rendering.uid, importMap);
|
|
187
|
+
postToDL(importMapEvent);
|
|
188
|
+
const propsEvent = getDesignLibraryComponentPropsEvent(rendering.uid, propsState.fields, propsState.params);
|
|
189
|
+
postToDL(propsEvent);
|
|
190
|
+
}))();
|
|
191
|
+
// return function that calls unsubscribe - if the component was mounted correctly
|
|
192
|
+
return () => {
|
|
193
|
+
cancelled = true;
|
|
194
|
+
unsubscribe && unsubscribe();
|
|
195
|
+
};
|
|
196
|
+
}, [isVariantGeneration, rendering]);
|
|
197
|
+
return (react_1.default.createElement("main", null, isGeneratedComponentActive ? (react_1.default.createElement(ErrorBoundary, { uid: rendering.uid, renderKey: renderKey },
|
|
198
|
+
react_1.default.createElement(PlaceholderMetadata_1.PlaceholderMetadata, { rendering: rendering },
|
|
199
|
+
react_1.default.createElement(Component, { fields: propsState.fields, params: propsState.params, key: renderKey })))) : (react_1.default.createElement("div", { id: layout_1.EDITING_COMPONENT_ID }, route && (react_1.default.createElement(Placeholder_1.Placeholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
|
|
174
200
|
};
|
|
175
201
|
exports.DesignLibrary = DesignLibrary;
|
|
@@ -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
|
}
|
|
@@ -46,20 +46,25 @@ function withEmptyFieldEditingComponent(FieldComponent, options) {
|
|
|
46
46
|
var _a;
|
|
47
47
|
const { editable = true } = props;
|
|
48
48
|
if (((_a = props.field) === null || _a === void 0 ? void 0 : _a.metadata) && editable && (0, layout_1.isFieldValueEmpty)(props.field)) {
|
|
49
|
-
|
|
49
|
+
const Component = props.emptyFieldEditingComponent || options.defaultEmptyFieldEditingComponent;
|
|
50
|
+
let resolvedProps = props;
|
|
51
|
+
// If no custom empty field editing component is provided, we can omit unnecessary props
|
|
52
|
+
// to do not insert them to html
|
|
53
|
+
if (!props.emptyFieldEditingComponent) {
|
|
54
|
+
resolvedProps = Object.assign(Object.assign({}, props), { editable: undefined, field: undefined });
|
|
55
|
+
}
|
|
56
|
+
return react_1.default.createElement(Component, Object.assign({}, resolvedProps));
|
|
50
57
|
}
|
|
51
58
|
return null;
|
|
52
59
|
};
|
|
53
60
|
if (options.isForwardRef) {
|
|
54
|
-
// eslint-disable-next-line react/display-name
|
|
55
61
|
return (0, react_1.forwardRef)((props, ref) => {
|
|
56
|
-
const
|
|
57
|
-
return (
|
|
62
|
+
const emptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
63
|
+
return (emptyFieldEditingComponent || (react_1.default.createElement(FieldComponent, Object.assign({}, props, { ref: ref }))));
|
|
58
64
|
});
|
|
59
65
|
}
|
|
60
|
-
// eslint-disable-next-line react/display-name
|
|
61
66
|
return (props) => {
|
|
62
|
-
const
|
|
63
|
-
return
|
|
67
|
+
const emptyFieldEditingComponent = getEmptyFieldEditingComponent(props);
|
|
68
|
+
return emptyFieldEditingComponent || react_1.default.createElement(FieldComponent, Object.assign({}, props));
|
|
64
69
|
};
|
|
65
70
|
}
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export const DefaultEmptyFieldEditingComponentText = () => {
|
|
3
|
-
return React.createElement(
|
|
2
|
+
export const DefaultEmptyFieldEditingComponentText = (props) => {
|
|
3
|
+
return React.createElement(props.tag || 'span', props, '[No text in field]');
|
|
4
4
|
};
|
|
5
|
-
export const DefaultEmptyFieldEditingComponentImage = () => {
|
|
5
|
+
export const DefaultEmptyFieldEditingComponentImage = (props) => {
|
|
6
6
|
const inlineStyles = {
|
|
7
7
|
minWidth: '48px',
|
|
8
8
|
minHeight: '48px',
|
|
@@ -10,5 +10,5 @@ export const DefaultEmptyFieldEditingComponentImage = () => {
|
|
|
10
10
|
maxHeight: '400px',
|
|
11
11
|
cursor: 'pointer',
|
|
12
12
|
};
|
|
13
|
-
return (React.createElement("img", { alt: "", src: 'data:image/svg+xml,%3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240 240" style="enable-background:new 0 0 240 240;" xml:space="preserve"%3E%3Cstyle type="text/css"%3E .st0%7Bfill:none;%7D .st1%7Bfill:%23969696;%7D .st2%7Bfill:%23FFFFFF;%7D .st3%7Bfill:%23FFFFFF;stroke:%23FFFFFF;stroke-width:0.75;stroke-miterlimit:10;%7D%0A%3C/style%3E%3Cg%3E%3Crect class="st0" width="240" height="240"/%3E%3Cg%3E%3Cg%3E%3Crect x="20" y="20" class="st1" width="200" height="200"/%3E%3C/g%3E%3Cg%3E%3Ccircle class="st2" cx="174" cy="67" r="14"/%3E%3Cpath class="st2" d="M174,54c7.17,0,13,5.83,13,13s-5.83,13-13,13s-13-5.83-13-13S166.83,54,174,54 M174,52 c-8.28,0-15,6.72-15,15s6.72,15,15,15s15-6.72,15-15S182.28,52,174,52L174,52z"/%3E%3C/g%3E%3Cpolyline class="st3" points="29.5,179.25 81.32,122.25 95.41,137.75 137.23,91.75 209.5,179.75 "/%3E%3C/g%3E%3C/g%3E%3C/svg%3E', className:
|
|
13
|
+
return (React.createElement("img", Object.assign({}, props, { alt: "", src: 'data:image/svg+xml,%3Csvg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240 240" style="enable-background:new 0 0 240 240;" xml:space="preserve"%3E%3Cstyle type="text/css"%3E .st0%7Bfill:none;%7D .st1%7Bfill:%23969696;%7D .st2%7Bfill:%23FFFFFF;%7D .st3%7Bfill:%23FFFFFF;stroke:%23FFFFFF;stroke-width:0.75;stroke-miterlimit:10;%7D%0A%3C/style%3E%3Cg%3E%3Crect class="st0" width="240" height="240"/%3E%3Cg%3E%3Cg%3E%3Crect x="20" y="20" class="st1" width="200" height="200"/%3E%3C/g%3E%3Cg%3E%3Ccircle class="st2" cx="174" cy="67" r="14"/%3E%3Cpath class="st2" d="M174,54c7.17,0,13,5.83,13,13s-5.83,13-13,13s-13-5.83-13-13S166.83,54,174,54 M174,52 c-8.28,0-15,6.72-15,15s6.72,15,15,15s15-6.72,15-15S182.28,52,174,52L174,52z"/%3E%3C/g%3E%3Cpolyline class="st3" points="29.5,179.25 81.32,122.25 95.41,137.75 137.23,91.75 209.5,179.75 "/%3E%3C/g%3E%3C/g%3E%3C/svg%3E', className: `scEmptyImage ${props.className || ''}`, style: inlineStyles })));
|
|
14
14
|
};
|