@elementor/editor-elements 4.1.0-725 → 4.1.0-727
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/index.d.mts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +157 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/sync/create-elements.ts +35 -13
- package/src/sync/duplicate-elements.ts +36 -7
- package/src/sync/move-elements.ts +61 -37
- package/src/sync/remove-elements.ts +34 -12
- package/src/sync/resolve-element.ts +50 -0
- package/src/sync/types.ts +27 -0
package/dist/index.mjs
CHANGED
|
@@ -242,6 +242,37 @@ function deleteElement({ container, options = {} }) {
|
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
// src/sync/resolve-element.ts
|
|
246
|
+
function isConnected(container) {
|
|
247
|
+
if (!container) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
if (!container.view?.el) {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
return container.view.el.isConnected;
|
|
254
|
+
}
|
|
255
|
+
function resolveContainer(container, id) {
|
|
256
|
+
const looked = container.lookup?.();
|
|
257
|
+
if (isConnected(looked)) {
|
|
258
|
+
return looked;
|
|
259
|
+
}
|
|
260
|
+
const byId = getContainer(id);
|
|
261
|
+
if (isConnected(byId)) {
|
|
262
|
+
return byId;
|
|
263
|
+
}
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
function getDocumentUtils() {
|
|
267
|
+
return window.$e?.components?.get?.("document")?.utils;
|
|
268
|
+
}
|
|
269
|
+
function addModelToParent(parentId, childData, options) {
|
|
270
|
+
return getDocumentUtils()?.addModelToParent?.(parentId, childData, options) ?? false;
|
|
271
|
+
}
|
|
272
|
+
function removeModelFromParent(parentId, childId) {
|
|
273
|
+
return getDocumentUtils()?.removeModelFromParent?.(parentId, childId) ?? false;
|
|
274
|
+
}
|
|
275
|
+
|
|
245
276
|
// src/sync/create-elements.ts
|
|
246
277
|
var createElements = ({
|
|
247
278
|
elements,
|
|
@@ -266,39 +297,54 @@ var createElements = ({
|
|
|
266
297
|
container: element,
|
|
267
298
|
parentContainer,
|
|
268
299
|
model: element.model?.toJSON() || {},
|
|
269
|
-
options
|
|
300
|
+
options,
|
|
301
|
+
containerId: element.id,
|
|
302
|
+
parentContainerId: parentContainer.id
|
|
270
303
|
});
|
|
271
304
|
});
|
|
272
305
|
return { createdElements };
|
|
273
306
|
},
|
|
274
307
|
undo: (_, { createdElements }) => {
|
|
275
|
-
[...createdElements].reverse().forEach(({ container }) => {
|
|
276
|
-
const freshContainer = container
|
|
308
|
+
[...createdElements].reverse().forEach(({ container, containerId, parentContainerId }) => {
|
|
309
|
+
const freshContainer = resolveContainer(container, containerId);
|
|
277
310
|
if (freshContainer) {
|
|
278
311
|
deleteElement({
|
|
279
312
|
container: freshContainer,
|
|
280
313
|
options: { useHistory: false }
|
|
281
314
|
});
|
|
315
|
+
return;
|
|
282
316
|
}
|
|
317
|
+
removeModelFromParent(parentContainerId, containerId);
|
|
283
318
|
});
|
|
284
319
|
},
|
|
285
320
|
redo: (_, { createdElements }) => {
|
|
286
321
|
const newElements = [];
|
|
287
|
-
createdElements.forEach(({ parentContainer, model, options }) => {
|
|
288
|
-
const freshParent = parentContainer
|
|
289
|
-
if (
|
|
322
|
+
createdElements.forEach(({ parentContainer, parentContainerId, model, options }) => {
|
|
323
|
+
const freshParent = resolveContainer(parentContainer, parentContainerId);
|
|
324
|
+
if (freshParent) {
|
|
325
|
+
const element = createElement({
|
|
326
|
+
container: freshParent,
|
|
327
|
+
model,
|
|
328
|
+
options: { ...options, useHistory: false }
|
|
329
|
+
});
|
|
330
|
+
newElements.push({
|
|
331
|
+
container: element,
|
|
332
|
+
parentContainer: freshParent,
|
|
333
|
+
model: element.model.toJSON(),
|
|
334
|
+
options,
|
|
335
|
+
containerId: element.id,
|
|
336
|
+
parentContainerId: freshParent.id
|
|
337
|
+
});
|
|
290
338
|
return;
|
|
291
339
|
}
|
|
292
|
-
|
|
293
|
-
container: freshParent,
|
|
294
|
-
model,
|
|
295
|
-
options: { ...options, useHistory: false }
|
|
296
|
-
});
|
|
340
|
+
addModelToParent(parentContainerId, model);
|
|
297
341
|
newElements.push({
|
|
298
|
-
container:
|
|
299
|
-
parentContainer
|
|
300
|
-
model
|
|
301
|
-
options
|
|
342
|
+
container: parentContainer,
|
|
343
|
+
parentContainer,
|
|
344
|
+
model,
|
|
345
|
+
options,
|
|
346
|
+
containerId: model.id ?? "",
|
|
347
|
+
parentContainerId
|
|
302
348
|
});
|
|
303
349
|
});
|
|
304
350
|
return { createdElements: newElements };
|
|
@@ -368,25 +414,32 @@ var duplicateElements = ({
|
|
|
368
414
|
container: duplicatedElement,
|
|
369
415
|
parentContainer: duplicatedElement.parent,
|
|
370
416
|
model: duplicatedElement.model.toJSON(),
|
|
371
|
-
at: duplicatedElement.view?._index
|
|
417
|
+
at: duplicatedElement.view?._index,
|
|
418
|
+
containerId: duplicatedElement.id,
|
|
419
|
+
parentContainerId: duplicatedElement.parent.id
|
|
372
420
|
});
|
|
373
421
|
});
|
|
374
422
|
return { duplicatedElements };
|
|
375
423
|
},
|
|
376
424
|
undo: (_, { duplicatedElements }) => {
|
|
377
425
|
onRestoreElements?.();
|
|
378
|
-
[...duplicatedElements].reverse().forEach(({ container }) => {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
426
|
+
[...duplicatedElements].reverse().forEach(({ container, containerId, parentContainerId }) => {
|
|
427
|
+
const freshContainer = resolveContainer(container, containerId);
|
|
428
|
+
if (freshContainer) {
|
|
429
|
+
deleteElement({
|
|
430
|
+
container: freshContainer,
|
|
431
|
+
options: { useHistory: false }
|
|
432
|
+
});
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
removeModelFromParent(parentContainerId, containerId);
|
|
383
436
|
});
|
|
384
437
|
},
|
|
385
438
|
redo: (_, { duplicatedElements: previousElements }) => {
|
|
386
439
|
onDuplicateElements?.();
|
|
387
440
|
const duplicatedElements = [];
|
|
388
|
-
previousElements.forEach(({ parentContainer, model, at }) => {
|
|
389
|
-
const freshParent = parentContainer
|
|
441
|
+
previousElements.forEach(({ parentContainer, parentContainerId, model, at }) => {
|
|
442
|
+
const freshParent = resolveContainer(parentContainer, parentContainerId);
|
|
390
443
|
if (freshParent) {
|
|
391
444
|
const createdElement = createElement({
|
|
392
445
|
container: freshParent,
|
|
@@ -397,9 +450,21 @@ var duplicateElements = ({
|
|
|
397
450
|
container: createdElement,
|
|
398
451
|
parentContainer: freshParent,
|
|
399
452
|
model,
|
|
400
|
-
at
|
|
453
|
+
at,
|
|
454
|
+
containerId: createdElement.id,
|
|
455
|
+
parentContainerId: freshParent.id
|
|
401
456
|
});
|
|
457
|
+
return;
|
|
402
458
|
}
|
|
459
|
+
addModelToParent(parentContainerId, model, { at });
|
|
460
|
+
duplicatedElements.push({
|
|
461
|
+
container: parentContainer,
|
|
462
|
+
parentContainer,
|
|
463
|
+
model,
|
|
464
|
+
at,
|
|
465
|
+
containerId: model.id ?? "",
|
|
466
|
+
parentContainerId
|
|
467
|
+
});
|
|
403
468
|
});
|
|
404
469
|
return { duplicatedElements };
|
|
405
470
|
}
|
|
@@ -560,16 +625,19 @@ var moveElements = ({
|
|
|
560
625
|
originalContainer,
|
|
561
626
|
originalIndex,
|
|
562
627
|
targetContainer: target,
|
|
563
|
-
options
|
|
628
|
+
options,
|
|
629
|
+
elementId: newElement.id,
|
|
630
|
+
originalContainerId: originalContainer.id,
|
|
631
|
+
targetContainerId: target.id
|
|
564
632
|
});
|
|
565
633
|
});
|
|
566
634
|
return { movedElements };
|
|
567
635
|
},
|
|
568
636
|
undo: (_, { movedElements }) => {
|
|
569
637
|
onRestoreElements?.();
|
|
570
|
-
[...movedElements].reverse().forEach(({ element, originalContainer, originalIndex }) => {
|
|
571
|
-
const freshElement = element
|
|
572
|
-
const freshOriginalContainer = originalContainer
|
|
638
|
+
[...movedElements].reverse().forEach(({ element, elementId, originalContainer, originalContainerId, originalIndex }) => {
|
|
639
|
+
const freshElement = resolveContainer(element, elementId);
|
|
640
|
+
const freshOriginalContainer = resolveContainer(originalContainer, originalContainerId);
|
|
573
641
|
if (!freshElement || !freshOriginalContainer) {
|
|
574
642
|
return;
|
|
575
643
|
}
|
|
@@ -586,26 +654,40 @@ var moveElements = ({
|
|
|
586
654
|
redo: (_, { movedElements }) => {
|
|
587
655
|
const newMovedElements = [];
|
|
588
656
|
onMoveElements?.();
|
|
589
|
-
movedElements.forEach(
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
const newElement = moveElement({
|
|
597
|
-
element: freshElement,
|
|
598
|
-
targetContainer: freshTarget,
|
|
599
|
-
options: { ...options, useHistory: false }
|
|
600
|
-
});
|
|
601
|
-
newMovedElements.push({
|
|
602
|
-
element: newElement,
|
|
603
|
-
originalContainer: freshOriginalContainer,
|
|
657
|
+
movedElements.forEach(
|
|
658
|
+
({
|
|
659
|
+
element,
|
|
660
|
+
elementId,
|
|
661
|
+
originalContainer,
|
|
662
|
+
originalContainerId,
|
|
604
663
|
originalIndex,
|
|
605
|
-
targetContainer
|
|
664
|
+
targetContainer,
|
|
665
|
+
targetContainerId,
|
|
606
666
|
options
|
|
607
|
-
})
|
|
608
|
-
|
|
667
|
+
}) => {
|
|
668
|
+
const freshElement = resolveContainer(element, elementId);
|
|
669
|
+
const freshOriginalContainer = resolveContainer(originalContainer, originalContainerId);
|
|
670
|
+
const freshTarget = resolveContainer(targetContainer, targetContainerId);
|
|
671
|
+
if (!freshElement || !freshOriginalContainer || !freshTarget) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
const newElement = moveElement({
|
|
675
|
+
element: freshElement,
|
|
676
|
+
targetContainer: freshTarget,
|
|
677
|
+
options: { ...options, useHistory: false }
|
|
678
|
+
});
|
|
679
|
+
newMovedElements.push({
|
|
680
|
+
element: newElement,
|
|
681
|
+
originalContainer: freshOriginalContainer,
|
|
682
|
+
originalIndex,
|
|
683
|
+
targetContainer: freshTarget,
|
|
684
|
+
options,
|
|
685
|
+
elementId: newElement.id,
|
|
686
|
+
originalContainerId: freshOriginalContainer.id,
|
|
687
|
+
targetContainerId: freshTarget.id
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
);
|
|
609
691
|
return { movedElements: newMovedElements };
|
|
610
692
|
}
|
|
611
693
|
},
|
|
@@ -638,7 +720,9 @@ var removeElements = ({
|
|
|
638
720
|
container,
|
|
639
721
|
parent: container.parent,
|
|
640
722
|
model: container.model.toJSON(),
|
|
641
|
-
at: container.view?._index ?? 0
|
|
723
|
+
at: container.view?._index ?? 0,
|
|
724
|
+
containerId: container.id,
|
|
725
|
+
parentId: container.parent.id
|
|
642
726
|
});
|
|
643
727
|
}
|
|
644
728
|
});
|
|
@@ -653,35 +737,48 @@ var removeElements = ({
|
|
|
653
737
|
},
|
|
654
738
|
undo: (_, { removedElements }) => {
|
|
655
739
|
onRestoreElements?.();
|
|
656
|
-
[...removedElements].reverse().forEach(({ parent, model, at }) => {
|
|
657
|
-
const freshParent = parent
|
|
740
|
+
[...removedElements].reverse().forEach(({ parent, parentId, model, at }) => {
|
|
741
|
+
const freshParent = resolveContainer(parent, parentId);
|
|
658
742
|
if (freshParent) {
|
|
659
743
|
createElement({
|
|
660
744
|
container: freshParent,
|
|
661
745
|
model,
|
|
662
746
|
options: { useHistory: false, at }
|
|
663
747
|
});
|
|
748
|
+
return;
|
|
664
749
|
}
|
|
750
|
+
addModelToParent(parentId, model, { at });
|
|
665
751
|
});
|
|
666
752
|
},
|
|
667
753
|
redo: (_, { removedElements }) => {
|
|
668
754
|
onRemoveElements?.();
|
|
669
755
|
const newRemovedElements = [];
|
|
670
|
-
removedElements.forEach(({ container, parent, model, at }) => {
|
|
671
|
-
const freshContainer = container
|
|
672
|
-
const freshParent = parent
|
|
673
|
-
if (
|
|
756
|
+
removedElements.forEach(({ container, parent, model, at, containerId, parentId }) => {
|
|
757
|
+
const freshContainer = resolveContainer(container, containerId);
|
|
758
|
+
const freshParent = resolveContainer(parent, parentId);
|
|
759
|
+
if (freshContainer && freshParent) {
|
|
760
|
+
deleteElement({
|
|
761
|
+
container: freshContainer,
|
|
762
|
+
options: { useHistory: false }
|
|
763
|
+
});
|
|
764
|
+
newRemovedElements.push({
|
|
765
|
+
container: freshContainer,
|
|
766
|
+
parent: freshParent,
|
|
767
|
+
model,
|
|
768
|
+
at,
|
|
769
|
+
containerId,
|
|
770
|
+
parentId
|
|
771
|
+
});
|
|
674
772
|
return;
|
|
675
773
|
}
|
|
676
|
-
|
|
677
|
-
container: freshContainer,
|
|
678
|
-
options: { useHistory: false }
|
|
679
|
-
});
|
|
774
|
+
removeModelFromParent(parentId, containerId);
|
|
680
775
|
newRemovedElements.push({
|
|
681
|
-
container
|
|
682
|
-
parent
|
|
776
|
+
container,
|
|
777
|
+
parent,
|
|
683
778
|
model,
|
|
684
|
-
at
|
|
779
|
+
at,
|
|
780
|
+
containerId,
|
|
781
|
+
parentId
|
|
685
782
|
});
|
|
686
783
|
});
|
|
687
784
|
return { removedElements: newRemovedElements };
|