@sitecore-feaas/clientside 0.1.18 → 0.1.20
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/build/basic.js +5 -1
- package/build/basic.js.map +1 -1
- package/build/cloud.js +45 -4
- package/build/cloud.js.map +1 -1
- package/build/components/FEAASBase.js +60 -21
- package/build/components/FEAASBase.js.map +1 -1
- package/build/components/FEAASComponent.js +35 -1
- package/build/components/FEAASComponent.js.map +1 -1
- package/build/components/FEAASElement.js +14 -0
- package/build/components/FEAASElement.js.map +1 -0
- package/build/components/FEAASLoader.js +13 -1
- package/build/components/FEAASLoader.js.map +1 -1
- package/build/components/FEAASStylesheet.js.map +1 -1
- package/build/dom.js +6 -0
- package/build/dom.js.map +1 -1
- package/build/fetch.js +48 -45
- package/build/fetch.js.map +1 -1
- package/build/ui/FEAASContext.js +12 -13
- package/build/ui/FEAASContext.js.map +1 -1
- package/build/ui/FEAASEditor.js +448 -76
- package/build/ui/FEAASEditor.js.map +1 -1
- package/build/ui/FEAASPicker.js +9 -59
- package/build/ui/FEAASPicker.js.map +1 -1
- package/dist/browser/basic.esm.js +5 -5
- package/dist/browser/basic.esm.js.map +1 -1
- package/dist/browser/basic.js +5 -5
- package/dist/browser/basic.js.map +1 -1
- package/dist/browser/index.esm.js +5 -10
- package/dist/browser/index.esm.js.map +1 -1
- package/dist/browser/index.js +5 -10
- package/dist/browser/index.js.map +1 -1
- package/dist/node/basic.esm.js +3 -3
- package/dist/node/basic.esm.js.map +1 -1
- package/dist/node/basic.js +3 -3
- package/dist/node/basic.js.map +1 -1
- package/dist/node/index.esm.js +3 -8
- package/dist/node/index.esm.js.map +1 -1
- package/dist/node/index.js +3 -8
- package/dist/node/index.js.map +1 -1
- package/examples/index.html +8 -49
- package/package.json +2 -7
- package/src/basic.ts +8 -1
- package/src/cloud.ts +49 -11
- package/src/components/FEAASBase.tsx +73 -20
- package/src/components/{FEAASComponent.ts → FEAASComponent.tsx} +37 -1
- package/src/components/FEAASElement.tsx +21 -0
- package/src/components/{FEAASLoader.ts → FEAASLoader.tsx} +14 -1
- package/src/components/{FEAASStylesheet.ts → FEAASStylesheet.tsx} +1 -1
- package/src/dom.ts +5 -0
- package/src/fetch.ts +82 -51
- package/src/ui/FEAASContext.tsx +13 -14
- package/src/ui/FEAASEditor.tsx +598 -144
- package/src/ui/FEAASPicker.tsx +18 -65
- package/test/components.ts +19 -0
- package/types/basic.d.ts +3 -0
- package/types/basic.d.ts.map +1 -1
- package/types/cloud.d.ts +8 -1
- package/types/cloud.d.ts.map +1 -1
- package/types/components/FEAASBase.d.ts +18 -4
- package/types/components/FEAASBase.d.ts.map +1 -1
- package/types/components/FEAASComponent.d.ts +7 -0
- package/types/components/FEAASComponent.d.ts.map +1 -1
- package/types/components/FEAASElement.d.ts +12 -0
- package/types/components/FEAASElement.d.ts.map +1 -0
- package/types/components/FEAASLoader.d.ts +6 -0
- package/types/components/FEAASLoader.d.ts.map +1 -1
- package/types/components/FEAASStylesheet.d.ts +1 -1
- package/types/components/FEAASStylesheet.d.ts.map +1 -1
- package/types/dom.d.ts.map +1 -1
- package/types/fetch.d.ts +42 -1
- package/types/fetch.d.ts.map +1 -1
- package/types/tsbuildinfo +1 -1
- package/types/tsbuildinfo_ui +1 -1
- package/types/ui/FEAASContext.d.ts +4 -4
- package/types/ui/FEAASContext.d.ts.map +1 -1
- package/types/ui/FEAASEditor.d.ts +71 -5
- package/types/ui/FEAASEditor.d.ts.map +1 -1
- package/types/ui/FEAASPicker.d.ts +15 -34
- package/types/ui/FEAASPicker.d.ts.map +1 -1
- package/types/components/FEAASContext.d.ts +0 -43
- package/types/components/FEAASEditor.d.ts +0 -136
- package/types/components/FEAASPicker.d.ts +0 -65
- package/types/components/index.d.ts +0 -7
- package/types/index.d.ts +0 -7
package/build/ui/FEAASEditor.js
CHANGED
|
@@ -36,13 +36,17 @@ export function FEAASEditorProps(element = this) {
|
|
|
36
36
|
return {
|
|
37
37
|
context: HTMLElement,
|
|
38
38
|
frontend: element === null || element === void 0 ? void 0 : element.getContextAttribute('frontend'),
|
|
39
|
-
src: (_a = element === null || element === void 0 ? void 0 : element.getAttribute('src')) !== null && _a !== void 0 ? _a : '/
|
|
39
|
+
src: (_a = element === null || element === void 0 ? void 0 : element.getAttribute('src')) !== null && _a !== void 0 ? _a : '/editor.js',
|
|
40
40
|
library: element === null || element === void 0 ? void 0 : element.getAttribute('library'),
|
|
41
41
|
component: element === null || element === void 0 ? void 0 : element.getAttribute('component'),
|
|
42
42
|
version: element === null || element === void 0 ? void 0 : element.getAttribute('version'),
|
|
43
|
+
instance: element === null || element === void 0 ? void 0 : element.getAttribute('instance'),
|
|
44
|
+
forked: element === null || element === void 0 ? void 0 : element.getAttribute('forked'),
|
|
43
45
|
revision: (element === null || element === void 0 ? void 0 : element.getAttribute('revision')) || 'saved',
|
|
44
46
|
hidden: (element === null || element === void 0 ? void 0 : element.getAttribute('hidden')) != null,
|
|
45
|
-
for: element === null || element === void 0 ? void 0 : element.getAttribute('for')
|
|
47
|
+
for: element === null || element === void 0 ? void 0 : element.getAttribute('for'),
|
|
48
|
+
state: (element === null || element === void 0 ? void 0 : element.getAttribute('state')) || 'idle',
|
|
49
|
+
changed: (element === null || element === void 0 ? void 0 : element.getAttribute('changed')) != null
|
|
46
50
|
};
|
|
47
51
|
}
|
|
48
52
|
export class FEAASEditor extends FEAASBase {
|
|
@@ -51,13 +55,19 @@ export class FEAASEditor extends FEAASBase {
|
|
|
51
55
|
this.framePoint = { top: 0, left: 0 };
|
|
52
56
|
this.wrapperRect = { top: 0, left: 0, width: 0, height: 0 };
|
|
53
57
|
this.bodyRect = { top: 0, left: 0, width: 0, height: 0 };
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
this.setTarget = (element, props = {
|
|
59
|
+
component: element.getAttribute('component'),
|
|
60
|
+
version: element.getAttribute('version'),
|
|
61
|
+
revision: element.getAttribute('revision'),
|
|
62
|
+
instance: element.getAttribute('instance')
|
|
63
|
+
}) => {
|
|
64
|
+
if (!this.closing && (!this.target || element == null)) {
|
|
65
|
+
this.set(props);
|
|
66
|
+
this.target = element;
|
|
67
|
+
return true;
|
|
60
68
|
}
|
|
69
|
+
};
|
|
70
|
+
this.onChromeMeasureElement = (element, rect = element.getBoundingClientRect()) => {
|
|
61
71
|
if (element.ownerDocument == document) {
|
|
62
72
|
return {
|
|
63
73
|
left: rect.left - this.bodyRect.left,
|
|
@@ -76,105 +86,467 @@ export class FEAASEditor extends FEAASBase {
|
|
|
76
86
|
this.onBeforeMeasure = (refs) => {
|
|
77
87
|
if (refs.memoized.focusable)
|
|
78
88
|
this.framePoint = getFramePosition(refs.memoized.focusable);
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
if (this.chrome) {
|
|
90
|
+
this.wrapperRect = this.chrome.positionable.getBoundingClientRect();
|
|
91
|
+
this.bodyRect = this.chrome.positionable.ownerDocument.body.parentElement.getBoundingClientRect();
|
|
92
|
+
}
|
|
81
93
|
};
|
|
82
94
|
this.onMeasure = () => { };
|
|
83
95
|
this.onPosition = ({ focusable, root }) => {
|
|
84
|
-
|
|
85
|
-
|
|
96
|
+
if (!this.chrome || this.props.hidden)
|
|
97
|
+
return;
|
|
86
98
|
if (focusable) {
|
|
87
99
|
const topbarHeight = 64;
|
|
88
100
|
const padding = 16;
|
|
89
|
-
chrome.style.width = focusable.width + padding * 2 + 'px';
|
|
90
|
-
chrome.style.height = focusable.height + padding * 1 + topbarHeight + 'px';
|
|
91
|
-
chrome.style.left = focusable.left - padding + 'px';
|
|
92
|
-
chrome.style.top = focusable.top - topbarHeight + 'px';
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
this.chrome.wrapper.style.width = focusable.width + padding * 2 + 'px';
|
|
102
|
+
this.chrome.wrapper.style.height = focusable.height + padding * 1 + topbarHeight + 'px';
|
|
103
|
+
this.chrome.wrapper.style.left = focusable.left - padding + 'px';
|
|
104
|
+
this.chrome.wrapper.style.top = focusable.top - topbarHeight + 'px';
|
|
105
|
+
this.chrome.wrapper.style.opacity = '1';
|
|
106
|
+
this.chrome.absolute = this.querySelector('.ui.overlays');
|
|
107
|
+
if (this.chrome.absolute) {
|
|
108
|
+
this.chrome.absolute.style.left = root.left + 'px';
|
|
109
|
+
this.chrome.absolute.style.top = root.top + 'px';
|
|
96
110
|
}
|
|
97
111
|
}
|
|
98
112
|
else {
|
|
99
|
-
chrome.style.
|
|
100
|
-
chrome.style.
|
|
113
|
+
this.chrome.wrapper.style.opacity = '0';
|
|
114
|
+
this.chrome.wrapper.style.left = '-1000px';
|
|
115
|
+
this.chrome.wrapper.style.top = '-1000px';
|
|
101
116
|
// wrapper.style.left = '-1000px'
|
|
102
117
|
// wrapper.style.top = '-1000px'
|
|
103
118
|
}
|
|
119
|
+
// this.setPlaceholder()
|
|
120
|
+
};
|
|
121
|
+
this.onWindowMessage = (event) => {
|
|
122
|
+
var _a;
|
|
123
|
+
switch ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) {
|
|
124
|
+
case 'feaasEdit':
|
|
125
|
+
const placeholder = this.getPlaceholder();
|
|
126
|
+
if (this.setTarget(placeholder.editable, event.data)) {
|
|
127
|
+
this.loader = placeholder.loader;
|
|
128
|
+
document.body.appendChild(placeholder.clipper);
|
|
129
|
+
this.editedUID = event.data.id;
|
|
130
|
+
this.setPlaceholder();
|
|
131
|
+
this.open();
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
case 'feaasMeasurements':
|
|
135
|
+
this.measurements = event.data.measurements;
|
|
136
|
+
if (!this.props.hidden)
|
|
137
|
+
this.setPlaceholder();
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
this.onContentChange = () => {
|
|
142
|
+
this.setAttribute('changed', 'changed');
|
|
143
|
+
requestAnimationFrame(() => {
|
|
144
|
+
this.setIframeComponentContent();
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
this.onClose = () => {
|
|
148
|
+
var _a;
|
|
149
|
+
this.setAttribute('hidden', 'hidden');
|
|
150
|
+
if (this.placeholder) {
|
|
151
|
+
this.placeholder.positionable.style.opacity = '0';
|
|
152
|
+
this.placeholder.positionable.style.pointerEvents = 'none';
|
|
153
|
+
}
|
|
154
|
+
if (this.chrome) {
|
|
155
|
+
this.chrome.wrapper.style.opacity = '0';
|
|
156
|
+
}
|
|
157
|
+
// FIXME: Workaround for CKEditor not removing event listeners properly
|
|
158
|
+
// Reported: https://github.com/ckeditor/ckeditor5/issues/13141
|
|
159
|
+
// Have to recreate the whole component
|
|
160
|
+
if ((_a = this.target) === null || _a === void 0 ? void 0 : _a.parentNode) {
|
|
161
|
+
this.target.outerHTML = this.target.outerHTML;
|
|
162
|
+
}
|
|
163
|
+
this.setTarget(null, {
|
|
164
|
+
component: null,
|
|
165
|
+
version: null,
|
|
166
|
+
instance: null,
|
|
167
|
+
revision: null
|
|
168
|
+
});
|
|
169
|
+
this.setEditorContext({
|
|
170
|
+
isFocused: false
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
this.onVersionStateChange = (versionContext, setVersionContext) => {
|
|
174
|
+
this.versionContext = versionContext;
|
|
175
|
+
this.setVersionContext = setVersionContext;
|
|
176
|
+
};
|
|
177
|
+
this.onEditorStateChange = (editorContext, setEditorContext) => {
|
|
178
|
+
this.editorContext = editorContext;
|
|
179
|
+
this.setEditorContext = setEditorContext;
|
|
180
|
+
// On editor loaded
|
|
181
|
+
if (editorContext.editor && this.props.state == 'loading' && !this.props.hidden) {
|
|
182
|
+
this.setAttribute('state', 'ready');
|
|
183
|
+
this.ownerDocument.fonts.ready.then(() => setTimeout(() => {
|
|
184
|
+
this.setReadyState();
|
|
185
|
+
this.setIframeComponentContent();
|
|
186
|
+
}, 100));
|
|
187
|
+
}
|
|
104
188
|
};
|
|
105
189
|
}
|
|
106
190
|
getProps() {
|
|
107
191
|
return FEAASEditorProps(this);
|
|
108
192
|
}
|
|
193
|
+
getReactRootElement() {
|
|
194
|
+
if (!this.reactRootElement) {
|
|
195
|
+
this.reactRootElement = document.createElement('div');
|
|
196
|
+
this.getRoot().appendChild(this.reactRootElement);
|
|
197
|
+
}
|
|
198
|
+
return this.reactRootElement;
|
|
199
|
+
}
|
|
200
|
+
showLoader() {
|
|
201
|
+
if (!this.loader) {
|
|
202
|
+
this.loader = document.createElement('feaas-loader');
|
|
203
|
+
this.loader.setAttribute('opacity', '0.6');
|
|
204
|
+
this.loader.style.zIndex = '1000';
|
|
205
|
+
this.target.appendChild(this.loader);
|
|
206
|
+
if (this.target.tagName == 'FEAAS-COMPONENT') {
|
|
207
|
+
this.target.style.position = 'relative';
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
hideLoader() {
|
|
212
|
+
if (this.loader) {
|
|
213
|
+
this.loader.setAttribute('hidden', 'hidden');
|
|
214
|
+
if (this.target.tagName == 'FEAAS-COMPONENT') {
|
|
215
|
+
this.target.style.position = 'relative';
|
|
216
|
+
this.target.style.position = '';
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
109
220
|
load() {
|
|
110
221
|
return import(/* @vite-ignore */ /* webpackIgnore: true */ this.formatURL(this.props.src, this.props.frontend));
|
|
111
222
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
223
|
+
connectedCallback() {
|
|
224
|
+
super.connectedCallback();
|
|
225
|
+
window.addEventListener('message', this.onWindowMessage);
|
|
226
|
+
}
|
|
227
|
+
disconnectedCallback() {
|
|
228
|
+
super.disconnectedCallback();
|
|
229
|
+
window.removeEventListener('message', this.onWindowMessage);
|
|
230
|
+
}
|
|
231
|
+
setIframe(iframe) {
|
|
232
|
+
this.iframe = iframe;
|
|
233
|
+
}
|
|
234
|
+
setIframeComponentContent() {
|
|
235
|
+
if (this.placeholder && this.iframe && this.placeholder.editable.innerHTML)
|
|
236
|
+
this.iframe.contentWindow.postMessage({
|
|
237
|
+
type: 'feaasUpdate',
|
|
238
|
+
id: this.editedUID,
|
|
239
|
+
content: this.placeholder.editable.innerHTML
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
setPlaceholder() {
|
|
243
|
+
const x = this.iframe.clientWidth;
|
|
244
|
+
const y = this.iframe.clientHeight;
|
|
245
|
+
const rect = this.iframe.getBoundingClientRect();
|
|
246
|
+
const placeholder = this.getPlaceholder();
|
|
247
|
+
const body = document.body.getBoundingClientRect();
|
|
248
|
+
const measurement = this.measurements[this.editedUID];
|
|
249
|
+
if (!measurement)
|
|
250
|
+
return;
|
|
251
|
+
Object.assign(placeholder.clipper.style, {
|
|
252
|
+
position: 'absolute',
|
|
253
|
+
top: rect.top + this.iframe.clientTop - body.top + 'px',
|
|
254
|
+
left: rect.left + this.iframe.clientLeft - body.left + 'px',
|
|
255
|
+
width: x + 'px',
|
|
256
|
+
height: y + 'px',
|
|
257
|
+
pointerEvents: 'none',
|
|
258
|
+
zIndex: 1,
|
|
259
|
+
overflow: 'hidden'
|
|
260
|
+
});
|
|
261
|
+
Object.assign(placeholder.positionable.style, {
|
|
262
|
+
position: 'absolute',
|
|
263
|
+
top: measurement.top + 'px',
|
|
264
|
+
left: measurement.left + 'px',
|
|
265
|
+
width: measurement.width + 'px',
|
|
266
|
+
zIndex: 2,
|
|
267
|
+
transition: 'opacity 0.4s',
|
|
268
|
+
//height: measurement.height + 'px',
|
|
269
|
+
pointerEvents: this.props.hidden ? 'none' : 'all'
|
|
270
|
+
//outline: '3px solid orange'
|
|
271
|
+
});
|
|
272
|
+
Object.assign(placeholder.loader.style, {
|
|
273
|
+
position: 'absolute',
|
|
274
|
+
top: measurement.top + 'px',
|
|
275
|
+
left: measurement.left + 'px',
|
|
276
|
+
width: measurement.width + 'px',
|
|
277
|
+
height: measurement.height + 'px',
|
|
278
|
+
filter: 'opacity(0.6)',
|
|
279
|
+
zIndex: 3,
|
|
280
|
+
pointerEvents: 'none'
|
|
281
|
+
//outline: '3px solid orange'
|
|
282
|
+
});
|
|
283
|
+
document.dispatchEvent(new Event('feaasRefresh', { bubbles: true }));
|
|
284
|
+
}
|
|
285
|
+
getPlaceholder() {
|
|
286
|
+
if (this.placeholder)
|
|
287
|
+
return this.placeholder;
|
|
288
|
+
this.placeholder = {
|
|
289
|
+
clipper: document.createElement('div'),
|
|
290
|
+
positionable: document.createElement('div'),
|
|
291
|
+
editable: Object.assign(document.createElement('div'), { className: '-feaas' }),
|
|
292
|
+
loader: document.createElement('feaas-loader')
|
|
293
|
+
};
|
|
294
|
+
this.placeholder.clipper.appendChild(this.placeholder.positionable);
|
|
295
|
+
this.placeholder.positionable.appendChild(this.placeholder.editable);
|
|
296
|
+
this.placeholder.clipper.appendChild(this.placeholder.loader);
|
|
297
|
+
return this.placeholder;
|
|
298
|
+
}
|
|
299
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
300
|
+
if (oldValue === newValue)
|
|
301
|
+
return;
|
|
302
|
+
if (name == 'hidden') {
|
|
303
|
+
this.style.setProperty('display', 'block', 'important');
|
|
304
|
+
this.style.setProperty('transition', 'opacity 0.3s', 'important');
|
|
305
|
+
if (newValue) {
|
|
306
|
+
this.style.setProperty('opacity', '0', 'important');
|
|
307
|
+
this.style.pointerEvents = 'none';
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
this.style.setProperty('opacity', '1', 'important');
|
|
311
|
+
this.style.pointerEvents = 'all';
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
315
|
+
}
|
|
316
|
+
open() {
|
|
317
|
+
clearTimeout(this.closing);
|
|
318
|
+
this.removeAttribute('hidden');
|
|
319
|
+
this.removeAttribute('changed');
|
|
320
|
+
this.setLoadingState();
|
|
321
|
+
}
|
|
322
|
+
shouldFork(version) {
|
|
323
|
+
return version.forkOriginId == null && this.props.instance != null;
|
|
324
|
+
}
|
|
325
|
+
cleanup() {
|
|
326
|
+
var _a;
|
|
327
|
+
if (this.placeholder) {
|
|
328
|
+
(_a = this.placeholder.clipper) === null || _a === void 0 ? void 0 : _a.remove();
|
|
329
|
+
this.placeholder = null;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
close() {
|
|
333
|
+
console.log('Editor is not ready');
|
|
334
|
+
}
|
|
335
|
+
unfork() {
|
|
336
|
+
console.log('Editor is not ready');
|
|
337
|
+
}
|
|
338
|
+
discard() {
|
|
339
|
+
console.log('Editor is not ready');
|
|
340
|
+
}
|
|
341
|
+
save() {
|
|
342
|
+
console.log('Editor is not ready');
|
|
343
|
+
}
|
|
344
|
+
setVersionContext(props) {
|
|
345
|
+
console.log('Editor is not ready');
|
|
346
|
+
}
|
|
347
|
+
setEditorContext(props) {
|
|
348
|
+
console.log('Editor is not ready');
|
|
349
|
+
}
|
|
350
|
+
setLoadingState() {
|
|
351
|
+
this.showLoader();
|
|
352
|
+
this.setAttribute('state', 'loading');
|
|
353
|
+
}
|
|
354
|
+
setReadyState() {
|
|
355
|
+
this.hideLoader();
|
|
356
|
+
this.setEditorContext({
|
|
357
|
+
activeVersionId: this.component.versions[0].id
|
|
358
|
+
});
|
|
359
|
+
this.setAttribute('state', 'ready');
|
|
360
|
+
}
|
|
361
|
+
renderReact({ children, component: componentId, version: versionId, instance: instanceId }, { Editor, VersionStatusList, VersionStatusButton, Version, VersionMenu, EditorUIUndo, EditorUIMode, React: { useEffect, useMemo, useState, useContext }, Chakra: { HStack, Box, Button, MenuItem }, Chrome, ReactDOM, useSDK, useSlots, useModelObserver, ConfirmationContext, VersionContext }) {
|
|
127
362
|
if (!this.payload)
|
|
128
363
|
return;
|
|
364
|
+
const { React } = this.payload;
|
|
129
365
|
const { sdk } = useSDK();
|
|
130
366
|
const [component, setComponent] = useState();
|
|
367
|
+
const { setConfirm } = useContext(ConfirmationContext);
|
|
368
|
+
const usedId = instanceId || versionId;
|
|
131
369
|
const library = sdk.library;
|
|
370
|
+
if (component)
|
|
371
|
+
this.component = component;
|
|
132
372
|
useEffect(() => {
|
|
133
|
-
|
|
134
|
-
|
|
373
|
+
if (this.props.hidden)
|
|
374
|
+
return;
|
|
375
|
+
const comp = library.components.getItem(componentId).clone();
|
|
376
|
+
comp.versions
|
|
377
|
+
.search({ ids: [versionId, instanceId].filter(Boolean), componentIds: [componentId] })
|
|
378
|
+
.then((versions) => {
|
|
379
|
+
comp.versions.setItems(versions);
|
|
380
|
+
const fork = comp.findVersion(instanceId, ['staged', 'published']);
|
|
381
|
+
const original = comp.findVersion(versionId, ['staged', 'published']);
|
|
382
|
+
if (fork) {
|
|
383
|
+
if (fork.deletedAt) {
|
|
384
|
+
// Get unforked version up to date
|
|
385
|
+
fork.getDraft().changeAndNotify(original.toProperties()).restore(); //.publish()
|
|
386
|
+
console.error('FEAAS Editor: Restoring fork');
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
console.error('FEAAS Editor: Pre-forked');
|
|
390
|
+
this.setAttribute('forked', fork.id);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
this.removeAttribute('forked');
|
|
395
|
+
if (this.shouldFork(original)) {
|
|
396
|
+
console.error('FEAAS Editor: Forking');
|
|
397
|
+
const newForkId = original.fork(instanceId).id;
|
|
398
|
+
this.setAttribute('instance', newForkId);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
console.error('FEAAS Editor: Regular');
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
setComponent(comp);
|
|
405
|
+
});
|
|
406
|
+
return () => {
|
|
407
|
+
this.closing = setTimeout(() => {
|
|
408
|
+
this.closing = null;
|
|
409
|
+
this.cleanup();
|
|
410
|
+
setComponent(null);
|
|
411
|
+
}, 400);
|
|
412
|
+
};
|
|
413
|
+
}, [versionId, this.props.hidden]);
|
|
414
|
+
const versions = useModelObserver(component === null || component === void 0 ? void 0 : component.versions, []).filter((v) => v.id == usedId);
|
|
415
|
+
const version = versions[0];
|
|
416
|
+
if (version && !this.props.hidden)
|
|
417
|
+
this.version = version;
|
|
135
418
|
useEffect(() => {
|
|
136
|
-
|
|
419
|
+
this.unfork = () => {
|
|
420
|
+
setConfirm({
|
|
421
|
+
title: 'Reverting component customizations',
|
|
422
|
+
button: 'Discard',
|
|
423
|
+
body: 'Are you sure to reset component to its original state? All changes will be lost.',
|
|
424
|
+
action: () => {
|
|
425
|
+
const original = component.findVersion(versionId, ['staged', 'published']);
|
|
426
|
+
component.findVersion(instanceId).unstage().unpublish().changeAndNotify(original.toProperties());
|
|
427
|
+
component.saveVersions(false);
|
|
428
|
+
this.setVersionContext({
|
|
429
|
+
needsWrite: true
|
|
430
|
+
});
|
|
431
|
+
this.removeAttribute('forked');
|
|
432
|
+
requestAnimationFrame(this.onClose);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
this.discard = () => {
|
|
437
|
+
if (this.props.changed) {
|
|
438
|
+
component.findVersion(usedId).revert();
|
|
439
|
+
component.saveVersions(false);
|
|
440
|
+
this.setVersionContext({
|
|
441
|
+
needsWrite: true
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
this.close = () => {
|
|
446
|
+
setConfirm({
|
|
447
|
+
title: 'Component has unsaved changes',
|
|
448
|
+
button: 'Discard',
|
|
449
|
+
body: 'Are you sure to close editor and discard changes?',
|
|
450
|
+
bypass: !this.props.changed,
|
|
451
|
+
action: () => {
|
|
452
|
+
this.discard();
|
|
453
|
+
requestAnimationFrame(this.onClose);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
this.save = () => {
|
|
458
|
+
setConfirm({
|
|
459
|
+
bypass: !!this.props.forked,
|
|
460
|
+
title: 'Customizing component',
|
|
461
|
+
button: 'Save',
|
|
462
|
+
body: 'Changes to the component will only be visible on that page. Changes to component done in Component Builder will not be reflected here. It will be possible to revert the customization.',
|
|
463
|
+
action: () => {
|
|
464
|
+
component
|
|
465
|
+
.findVersion(usedId)
|
|
466
|
+
.commitData({
|
|
467
|
+
view: this.editorContext.editor.getData({ rootName: usedId }),
|
|
468
|
+
model: ''
|
|
469
|
+
})
|
|
470
|
+
.stage()
|
|
471
|
+
.publish();
|
|
472
|
+
this.removeAttribute('changed');
|
|
473
|
+
this.setAttribute('forked', usedId);
|
|
474
|
+
component.saveVersions(false);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
return () => {
|
|
479
|
+
delete this.unfork;
|
|
480
|
+
delete this.discard;
|
|
481
|
+
delete this.save;
|
|
482
|
+
delete this.editorContext;
|
|
483
|
+
delete this.versionContext;
|
|
484
|
+
delete this.setEditorContext;
|
|
485
|
+
delete this.setVersionContext;
|
|
486
|
+
};
|
|
137
487
|
}, [component]);
|
|
138
|
-
const target = useMemo(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
React.createElement(Box, {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
React.createElement(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
488
|
+
const target = useMemo(() => {
|
|
489
|
+
return this.target;
|
|
490
|
+
}, [component]);
|
|
491
|
+
return useMemo(() => component &&
|
|
492
|
+
useSlots(children, ({ picker, children }) => (React.createElement(Box, { ref: (el) => {
|
|
493
|
+
this.chrome = el
|
|
494
|
+
? {
|
|
495
|
+
positionable: el,
|
|
496
|
+
wrapper: el.querySelector('.editor-chrome'),
|
|
497
|
+
absolute: this.querySelector('.ui.overlays')
|
|
498
|
+
}
|
|
499
|
+
: null;
|
|
500
|
+
} },
|
|
501
|
+
React.createElement(Box, { className: 'editor-wrapper', position: 'absolute', left: 0, top: 0 },
|
|
502
|
+
React.createElement(Editor, { datasources: sdk.datasources, sdk: sdk, library: sdk.library, component: component, versions: versions, context: {
|
|
503
|
+
isAutosaveEnabled: false,
|
|
504
|
+
onChromeMeasure: this.onMeasure,
|
|
505
|
+
onChromeBeforeMeasure: this.onBeforeMeasure,
|
|
506
|
+
onChromeMeasureElement: this.onChromeMeasureElement,
|
|
507
|
+
onChromePosition: this.onPosition,
|
|
508
|
+
onContentChange: this.onContentChange
|
|
509
|
+
} }, {
|
|
510
|
+
exports: this.onEditorStateChange,
|
|
511
|
+
after: children,
|
|
512
|
+
chrome: ({ editor }) => editor && React.createElement(Chrome, null),
|
|
513
|
+
children: ({ isArchivedDisplayed, editor, status }) => (React.createElement(Box, { position: 'absolute', left: 0, top: 0, className: 'editor-chrome', p: 4, boxShadow: '2xl', pointerEvents: 'none', opacity: 0, transition: 'opacity 0.3s' },
|
|
514
|
+
React.createElement(Box, { left: 0, width: '4', top: 0, bottom: 0, backdropFilter: 'blur(2px)', background: 'rgb(244 244 244 / 80%)', position: 'absolute' }),
|
|
515
|
+
React.createElement(Box, { right: 0, width: '4', top: 0, bottom: 0, backdropFilter: 'blur(2px)', background: 'rgb(244 244 244 / 80%)', position: 'absolute' }),
|
|
516
|
+
React.createElement(Box, { top: 0, height: '16', left: 0, right: 0, backdropFilter: 'blur(2px)', background: 'rgb(244 244 244 / 80%)', position: 'absolute' }),
|
|
517
|
+
React.createElement(Box, { bottom: 0, height: '4', left: 0, right: 0, backdropFilter: 'blur(2px)', background: 'rgb(244 244 244 / 80%)', position: 'absolute' }),
|
|
518
|
+
version && (React.createElement(Version, { version: version, node: target, ignoreBreakpoints: true, deps: [this.props.forked, this.props.changed] }, {
|
|
519
|
+
exports: this.onVersionStateChange,
|
|
520
|
+
left: (React.createElement(HStack, { justifyContent: 'space-between' },
|
|
521
|
+
React.createElement(EditorUIUndo, { size: 'sm', editor: status == 'ready' ? editor : null }),
|
|
522
|
+
React.createElement(EditorUIMode, { size: 'sm' }))),
|
|
523
|
+
middle: (versionContext, setVersionContext) => [
|
|
524
|
+
false && (React.createElement(VersionContext.Provider, { value: [
|
|
525
|
+
{
|
|
526
|
+
...versionContext,
|
|
527
|
+
version: component.findVersion(versionId)
|
|
528
|
+
},
|
|
529
|
+
setVersionContext
|
|
530
|
+
] },
|
|
531
|
+
React.createElement(VersionStatusList, null)))
|
|
532
|
+
],
|
|
533
|
+
right: (React.createElement(React.Fragment, null,
|
|
534
|
+
React.createElement(Button, { variant: 'secondary', size: 'sm', onClick: this.close }, "Close"),
|
|
535
|
+
React.createElement(Button, { variant: 'primary', size: 'sm', onClick: this.save, isDisabled: !this.props.changed }, !this.props.changed
|
|
536
|
+
? 'Up to date'
|
|
537
|
+
: this.props.forked
|
|
538
|
+
? 'Save'
|
|
539
|
+
: 'Save customization'),
|
|
540
|
+
React.createElement(VersionMenu, { isDisabled: !this.props.forked && !this.props.changed },
|
|
541
|
+
React.createElement(MenuItem, { onClick: this.unfork, isDisabled: !this.props.forked }, "Unfork"),
|
|
542
|
+
React.createElement(MenuItem, { onClick: this.discard, isDisabled: !this.props.changed }, "Discard"))))
|
|
543
|
+
}))))
|
|
544
|
+
}))))), [version, this.props.forked, this.props.changed]);
|
|
174
545
|
}
|
|
175
546
|
isReadyToLoad() {
|
|
176
|
-
return this.props.component != null && this.props.version != null;
|
|
547
|
+
return this.props.component != null && this.props.version != null && !this.props.hidden;
|
|
177
548
|
}
|
|
178
549
|
}
|
|
550
|
+
FEAASEditor.observedAttributes = ['library', 'component', 'version', 'revision', 'hidden', 'state', 'changed', 'forked'];
|
|
179
551
|
FEAASEditor.register('feaas-editor');
|
|
180
552
|
//# sourceMappingURL=FEAASEditor.js.map
|