@elementor/editor-elements 4.0.0-543 → 4.0.0-545

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.js CHANGED
@@ -47,7 +47,6 @@ __export(index_exports, {
47
47
  getElementType: () => getElementType,
48
48
  getElements: () => getElements,
49
49
  getLinkInLinkRestriction: () => getLinkInLinkRestriction,
50
- getModel: () => getModel,
51
50
  getSelectedElements: () => getSelectedElements,
52
51
  getWidgetsCache: () => getWidgetsCache,
53
52
  isElementAnchored: () => isElementAnchored,
@@ -91,22 +90,7 @@ var selectElement = (elementId) => {
91
90
  }
92
91
  };
93
92
 
94
- // src/sync/get-model.ts
95
- function getModel(id, parentModel) {
96
- const extendedWindow = window;
97
- const container = extendedWindow.elementor?.getContainer?.(id) ?? null;
98
- if (container) {
99
- return { model: container.model };
100
- }
101
- if (parentModel) {
102
- const childModels = parentModel.get("elements") ?? [];
103
- const model = childModels.find((m) => m.get("id") === id);
104
- if (model) {
105
- return { model };
106
- }
107
- }
108
- return null;
109
- }
93
+ // src/sync/model-utils.ts
110
94
  function findChildRecursive(model, predicate) {
111
95
  const childModels = model.get("elements") ?? [];
112
96
  for (const childModel of childModels) {
@@ -304,11 +288,7 @@ function useSelectedElement() {
304
288
 
305
289
  // src/sync/create-element.ts
306
290
  var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
307
- function createElement({ containerId, model, options }) {
308
- const container = getContainer(containerId);
309
- if (!container) {
310
- throw new Error(`Container with ID "${containerId}" not found`);
311
- }
291
+ function createElement({ container, model, options }) {
312
292
  return (0, import_editor_v1_adapters7.__privateRunCommandSync)("document/elements/create", {
313
293
  container,
314
294
  model,
@@ -322,14 +302,7 @@ var import_i18n = require("@wordpress/i18n");
322
302
 
323
303
  // src/sync/delete-element.ts
324
304
  var import_editor_v1_adapters8 = require("@elementor/editor-v1-adapters");
325
- function deleteElement({
326
- elementId,
327
- options = {}
328
- }) {
329
- const container = getContainer(elementId);
330
- if (!container) {
331
- throw new Error(`Element with ID "${elementId}" not found`);
332
- }
305
+ function deleteElement({ container, options = {} }) {
333
306
  return (0, import_editor_v1_adapters8.__privateRunCommand)("document/elements/delete", {
334
307
  container,
335
308
  options
@@ -346,48 +319,54 @@ var createElements = ({
346
319
  {
347
320
  do: ({ elements: elementsParam }) => {
348
321
  const createdElements = [];
349
- elementsParam.forEach((createParams) => {
350
- const { options, ...elementParams } = createParams;
322
+ elementsParam.forEach(({ container, options, ...elementParams }) => {
323
+ const parentContainer = container.lookup?.() ?? container;
324
+ if (!parentContainer) {
325
+ throw new Error("Parent container not found");
326
+ }
351
327
  const element = createElement({
328
+ container: parentContainer,
352
329
  ...elementParams,
353
330
  options: { ...options, useHistory: false }
354
331
  });
355
- const elementId = element.id;
356
332
  createdElements.push({
357
- elementId,
333
+ container: element,
334
+ parentContainer,
358
335
  model: element.model?.toJSON() || {},
359
- createParams: {
360
- ...createParams
361
- }
336
+ options
362
337
  });
363
338
  });
364
339
  return { createdElements };
365
340
  },
366
341
  undo: (_, { createdElements }) => {
367
- [...createdElements].reverse().forEach(({ elementId }) => {
368
- deleteElement({
369
- elementId,
370
- options: { useHistory: false }
371
- });
342
+ [...createdElements].reverse().forEach(({ container }) => {
343
+ const freshContainer = container.lookup?.();
344
+ if (freshContainer) {
345
+ deleteElement({
346
+ container: freshContainer,
347
+ options: { useHistory: false }
348
+ });
349
+ }
372
350
  });
373
351
  },
374
352
  redo: (_, { createdElements }) => {
375
353
  const newElements = [];
376
- createdElements.forEach(({ createParams, model }) => {
354
+ createdElements.forEach(({ parentContainer, model, options }) => {
355
+ const freshParent = parentContainer.lookup?.();
356
+ if (!freshParent) {
357
+ return;
358
+ }
377
359
  const element = createElement({
378
- containerId: createParams.containerId,
360
+ container: freshParent,
379
361
  model,
380
- options: { ...createParams.options, useHistory: false }
362
+ options: { ...options, useHistory: false }
363
+ });
364
+ newElements.push({
365
+ container: element,
366
+ parentContainer: freshParent,
367
+ model: element.model.toJSON(),
368
+ options
381
369
  });
382
- const elementId = element.id;
383
- const container = getContainer(elementId);
384
- if (container) {
385
- newElements.push({
386
- elementId,
387
- model: container.model.toJSON(),
388
- createParams
389
- });
390
- }
391
370
  });
392
371
  return { createdElements: newElements };
393
372
  }
@@ -416,15 +395,11 @@ function dropElement({ containerId, model, options }) {
416
395
 
417
396
  // src/sync/duplicate-element.ts
418
397
  var import_editor_v1_adapters11 = require("@elementor/editor-v1-adapters");
419
- function duplicateElement({ elementId, options = {} }) {
420
- const elementToDuplicate = getContainer(elementId);
421
- if (!elementToDuplicate) {
422
- throw new Error(`Element with ID "${elementId}" not found`);
423
- }
424
- const currentIndex = elementToDuplicate.view?._index ?? 0;
398
+ function duplicateElement({ element, options = {} }) {
399
+ const currentIndex = element.view?._index ?? 0;
425
400
  const insertPosition = options.clone !== false ? currentIndex + 1 : void 0;
426
401
  return (0, import_editor_v1_adapters11.__privateRunCommandSync)("document/elements/duplicate", {
427
- container: elementToDuplicate,
402
+ container: element,
428
403
  options: { at: insertPosition, edit: false, ...options }
429
404
  });
430
405
  }
@@ -443,59 +418,56 @@ var duplicateElements = ({
443
418
  {
444
419
  do: ({ elementIds: elementIdsToDuplicate }) => {
445
420
  onDuplicateElements?.();
446
- const duplicatedElements = elementIdsToDuplicate.reduce((acc, elementId) => {
421
+ const duplicatedElements = [];
422
+ elementIdsToDuplicate.forEach((elementId) => {
447
423
  const originalContainer = getContainer(elementId);
448
- if (originalContainer?.parent) {
449
- const duplicatedElement = duplicateElement({
450
- elementId,
451
- options: { useHistory: false }
452
- });
453
- acc.push({
454
- id: duplicatedElement.id,
455
- model: duplicatedElement.model.toJSON(),
456
- originalElementId: elementId,
457
- modelToRestore: duplicatedElement.model.toJSON(),
458
- parentContainerId: duplicatedElement.parent?.id,
459
- at: duplicatedElement.view?._index
460
- });
424
+ if (!originalContainer?.parent) {
425
+ return;
461
426
  }
462
- return acc;
463
- }, []);
427
+ const duplicatedElement = duplicateElement({
428
+ element: originalContainer,
429
+ options: { useHistory: false }
430
+ });
431
+ if (!duplicatedElement.parent) {
432
+ return;
433
+ }
434
+ duplicatedElements.push({
435
+ container: duplicatedElement,
436
+ parentContainer: duplicatedElement.parent,
437
+ model: duplicatedElement.model.toJSON(),
438
+ at: duplicatedElement.view?._index
439
+ });
440
+ });
464
441
  return { duplicatedElements };
465
442
  },
466
443
  undo: (_, { duplicatedElements }) => {
467
444
  onRestoreElements?.();
468
- [...duplicatedElements].reverse().forEach(({ id }) => {
445
+ [...duplicatedElements].reverse().forEach(({ container }) => {
469
446
  deleteElement({
470
- elementId: id,
447
+ container,
471
448
  options: { useHistory: false }
472
449
  });
473
450
  });
474
451
  },
475
452
  redo: (_, { duplicatedElements: previousElements }) => {
476
453
  onDuplicateElements?.();
477
- const duplicatedElements = previousElements.reduce((acc, previousElement) => {
478
- if (previousElement.modelToRestore && previousElement.parentContainerId) {
454
+ const duplicatedElements = [];
455
+ previousElements.forEach(({ parentContainer, model, at }) => {
456
+ const freshParent = parentContainer.lookup?.();
457
+ if (freshParent) {
479
458
  const createdElement = createElement({
480
- containerId: previousElement.parentContainerId,
481
- model: previousElement.modelToRestore,
482
- options: {
483
- useHistory: false,
484
- clone: false,
485
- at: previousElement.at
486
- }
459
+ container: freshParent,
460
+ model,
461
+ options: { useHistory: false, clone: false, at }
487
462
  });
488
- acc.push({
489
- id: createdElement.id,
490
- model: createdElement.model.toJSON(),
491
- originalElementId: previousElement.originalElementId,
492
- modelToRestore: previousElement.modelToRestore,
493
- parentContainerId: previousElement.parentContainerId,
494
- at: previousElement.at
463
+ duplicatedElements.push({
464
+ container: createdElement,
465
+ parentContainer: freshParent,
466
+ model,
467
+ at
495
468
  });
496
469
  }
497
- return acc;
498
- }, []);
470
+ });
499
471
  return { duplicatedElements };
500
472
  }
501
473
  },
@@ -594,25 +566,23 @@ function getElements(root) {
594
566
  }
595
567
 
596
568
  // src/sync/move-element.ts
597
- function moveElement({ elementId, targetContainerId, options = {} }) {
598
- const container = getContainer(elementId);
599
- const target = getContainer(targetContainerId);
600
- if (!container) {
601
- throw new Error(`Element with ID "${elementId}" not found`);
569
+ function moveElement({ element, targetContainer, options = {} }) {
570
+ const resolvedElement = element.lookup?.();
571
+ const resolvedTarget = targetContainer.lookup?.();
572
+ if (!resolvedElement) {
573
+ throw new Error(`Element not found: ${element.id}`);
602
574
  }
603
- if (!target) {
604
- throw new Error(`Target container with ID "${targetContainerId}" not found`);
575
+ if (!resolvedTarget) {
576
+ throw new Error(`Target container not found: ${targetContainer.id}`);
605
577
  }
606
- const modelToRecreate = container.model.toJSON();
578
+ const modelToRecreate = resolvedElement.model.toJSON();
607
579
  deleteElement({
608
- elementId,
609
- // prevent inner history from being created
580
+ container: resolvedElement,
610
581
  options: { ...options, useHistory: false }
611
582
  });
612
583
  const newContainer = createElement({
613
- containerId: targetContainerId,
584
+ container: resolvedTarget,
614
585
  model: modelToRecreate,
615
- // prevent inner history from being created
616
586
  options: { edit: false, ...options, useHistory: false }
617
587
  });
618
588
  return newContainer;
@@ -633,39 +603,46 @@ var moveElements = ({
633
603
  do: ({ moves }) => {
634
604
  const movedElements = [];
635
605
  onMoveElements?.();
636
- moves.forEach((move) => {
637
- const { elementId } = move;
638
- const sourceContainer = getContainer(elementId);
639
- if (!sourceContainer) {
640
- throw new Error(`Element with ID "${elementId}" not found`);
606
+ moves.forEach(({ element, targetContainer, options }) => {
607
+ const sourceElement = element.lookup?.() ?? element;
608
+ const target = targetContainer.lookup?.() ?? targetContainer;
609
+ if (!sourceElement) {
610
+ throw new Error("Element not found");
611
+ }
612
+ if (!target) {
613
+ throw new Error("Target container not found");
614
+ }
615
+ if (!sourceElement.parent) {
616
+ throw new Error("Element has no parent container");
641
617
  }
642
- const originalContainerId = sourceContainer.parent?.id || "";
643
- const originalIndex = sourceContainer.parent?.children?.indexOf(sourceContainer) ?? -1;
644
- const originalPosition = {
645
- elementId,
646
- originalContainerId,
647
- originalIndex
648
- };
649
- const element = moveElement({
650
- ...move,
651
- options: { ...move.options, useHistory: false }
618
+ const originalContainer = sourceElement.parent;
619
+ const originalIndex = originalContainer.children?.indexOf(sourceElement) ?? -1;
620
+ const newElement = moveElement({
621
+ element: sourceElement,
622
+ targetContainer: target,
623
+ options: { ...options, useHistory: false }
652
624
  });
653
625
  movedElements.push({
654
- elementId,
655
- originalPosition,
656
- move,
657
- element
626
+ element: newElement,
627
+ originalContainer,
628
+ originalIndex,
629
+ targetContainer: target,
630
+ options
658
631
  });
659
632
  });
660
633
  return { movedElements };
661
634
  },
662
635
  undo: (_, { movedElements }) => {
663
636
  onRestoreElements?.();
664
- [...movedElements].reverse().forEach(({ originalPosition }) => {
665
- const { elementId, originalContainerId, originalIndex } = originalPosition;
637
+ [...movedElements].reverse().forEach(({ element, originalContainer, originalIndex }) => {
638
+ const freshElement = element.lookup?.();
639
+ const freshOriginalContainer = originalContainer.lookup?.();
640
+ if (!freshElement || !freshOriginalContainer) {
641
+ return;
642
+ }
666
643
  moveElement({
667
- elementId,
668
- targetContainerId: originalContainerId,
644
+ element: freshElement,
645
+ targetContainer: freshOriginalContainer,
669
646
  options: {
670
647
  useHistory: false,
671
648
  at: originalIndex >= 0 ? originalIndex : void 0
@@ -676,16 +653,24 @@ var moveElements = ({
676
653
  redo: (_, { movedElements }) => {
677
654
  const newMovedElements = [];
678
655
  onMoveElements?.();
679
- movedElements.forEach(({ move, originalPosition }) => {
680
- const element = moveElement({
681
- ...move,
682
- options: { ...move.options, useHistory: false }
656
+ movedElements.forEach(({ element, originalContainer, originalIndex, targetContainer, options }) => {
657
+ const freshElement = element.lookup?.();
658
+ const freshOriginalContainer = originalContainer.lookup?.();
659
+ const freshTarget = targetContainer.lookup?.();
660
+ if (!freshElement || !freshOriginalContainer || !freshTarget) {
661
+ return;
662
+ }
663
+ const newElement = moveElement({
664
+ element: freshElement,
665
+ targetContainer: freshTarget,
666
+ options: { ...options, useHistory: false }
683
667
  });
684
668
  newMovedElements.push({
685
- elementId: move.elementId,
686
- originalPosition,
687
- move,
688
- element
669
+ element: newElement,
670
+ originalContainer: freshOriginalContainer,
671
+ originalIndex,
672
+ targetContainer: freshTarget,
673
+ options
689
674
  });
690
675
  });
691
676
  return { movedElements: newMovedElements };
@@ -715,48 +700,58 @@ var removeElements = ({
715
700
  const removedElements = [];
716
701
  elementIdsParam.forEach((elementId) => {
717
702
  const container = getContainer(elementId);
718
- if (container) {
719
- const model = container.model.toJSON();
720
- const parent = container.parent;
721
- const at = container.view?._index ?? 0;
703
+ if (container?.parent) {
722
704
  removedElements.push({
723
- elementId,
724
- model,
725
- parent: parent ?? null,
726
- at
705
+ container,
706
+ parent: container.parent,
707
+ model: container.model.toJSON(),
708
+ at: container.view?._index ?? 0
727
709
  });
728
710
  }
729
711
  });
730
712
  onRemoveElements?.();
731
- elementIdsParam.forEach((elementId) => {
713
+ removedElements.forEach(({ container }) => {
732
714
  deleteElement({
733
- elementId,
715
+ container,
734
716
  options: { useHistory: false }
735
717
  });
736
718
  });
737
- return { elementIds: elementIdsParam, removedElements };
719
+ return { removedElements };
738
720
  },
739
721
  undo: (_, { removedElements }) => {
740
722
  onRestoreElements?.();
741
- [...removedElements].reverse().forEach(({ model, parent, at }) => {
742
- if (parent && model) {
723
+ [...removedElements].reverse().forEach(({ parent, model, at }) => {
724
+ const freshParent = parent.lookup?.();
725
+ if (freshParent) {
743
726
  createElement({
744
- containerId: parent.id,
727
+ container: freshParent,
745
728
  model,
746
729
  options: { useHistory: false, at }
747
730
  });
748
731
  }
749
732
  });
750
733
  },
751
- redo: (_, { elementIds: originalElementIds, removedElements }) => {
734
+ redo: (_, { removedElements }) => {
752
735
  onRemoveElements?.();
753
- originalElementIds.forEach((elementId) => {
736
+ const newRemovedElements = [];
737
+ removedElements.forEach(({ container, parent, model, at }) => {
738
+ const freshContainer = container.lookup?.();
739
+ const freshParent = parent.lookup?.();
740
+ if (!freshContainer || !freshParent) {
741
+ return;
742
+ }
754
743
  deleteElement({
755
- elementId,
744
+ container: freshContainer,
756
745
  options: { useHistory: false }
757
746
  });
747
+ newRemovedElements.push({
748
+ container: freshContainer,
749
+ parent: freshParent,
750
+ model,
751
+ at
752
+ });
758
753
  });
759
- return { elementIds: originalElementIds, removedElements };
754
+ return { removedElements: newRemovedElements };
760
755
  }
761
756
  },
762
757
  {
@@ -769,42 +764,42 @@ var removeElements = ({
769
764
 
770
765
  // src/sync/replace-element.ts
771
766
  var replaceElement = async ({ currentElement, newElement, withHistory = true }) => {
772
- const { containerId, index } = getNewElementContainer(currentElement, newElement);
767
+ const currentElementContainer = getContainer(currentElement.id);
768
+ if (!currentElementContainer) {
769
+ throw new ElementNotFoundError({ context: { elementId: currentElement.id } });
770
+ }
771
+ const { container, index } = getNewElementContainer(currentElementContainer, newElement);
773
772
  const newElementInstance = createElement({
774
- containerId,
773
+ container,
775
774
  model: newElement,
776
775
  options: { at: index, useHistory: withHistory }
777
776
  });
778
- await deleteElement({ elementId: currentElement.id, options: { useHistory: withHistory } });
777
+ await deleteElement({ container: currentElementContainer, options: { useHistory: withHistory } });
779
778
  return newElementInstance;
780
779
  };
781
- function getNewElementContainer(currentElement, newElement) {
782
- const currentElementContainer = getContainer(currentElement.id);
783
- if (!currentElementContainer) {
784
- throw new ElementNotFoundError({ context: { elementId: currentElement.id } });
785
- }
780
+ function getNewElementContainer(currentElementContainer, newElement) {
786
781
  const { parent } = currentElementContainer;
787
782
  if (!parent) {
788
- throw new ElementParentNotFoundError({ context: { elementId: currentElement.id } });
783
+ throw new ElementParentNotFoundError({ context: { elementId: currentElementContainer.id } });
789
784
  }
790
785
  const elementIndex = currentElementContainer.view?._index ?? 0;
791
786
  if (elementIndex === -1) {
792
- throw new ElementIndexNotFoundError({ context: { elementId: currentElement.id } });
787
+ throw new ElementIndexNotFoundError({ context: { elementId: currentElementContainer.id } });
793
788
  }
794
- let container = { containerId: parent.id, index: elementIndex };
789
+ let location = { container: parent, index: elementIndex };
795
790
  if (parent.id === "document" && newElement.elType === "widget") {
796
- container = createWrapperForWidget(parent.id, elementIndex);
791
+ location = createWrapperForWidget(parent, elementIndex);
797
792
  }
798
- return container;
793
+ return location;
799
794
  }
800
795
  var DEFAULT_CONTAINER_TYPE = "e-flexbox";
801
- function createWrapperForWidget(parentId, elementIndex) {
796
+ function createWrapperForWidget(parent, elementIndex) {
802
797
  const container = createElement({
803
- containerId: parentId,
798
+ container: parent,
804
799
  model: { elType: DEFAULT_CONTAINER_TYPE },
805
800
  options: { at: elementIndex, useHistory: false }
806
801
  });
807
- return { containerId: container.id, index: 0 };
802
+ return { container, index: 0 };
808
803
  }
809
804
 
810
805
  // src/sync/update-element-editor-settings.ts
@@ -819,16 +814,16 @@ var updateElementEditorSettings = ({
819
814
  }
820
815
  const editorSettings = element.model.get("editor_settings") ?? {};
821
816
  element.model.set("editor_settings", { ...editorSettings, ...settings });
822
- setDocumentModifiedStatus(true);
817
+ (0, import_editor_v1_adapters15.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true });
823
818
  };
824
- function setDocumentModifiedStatus(status) {
825
- (0, import_editor_v1_adapters15.__privateRunCommandSync)("document/save/set-is-modified", { status }, { internal: true });
826
- }
827
819
 
828
820
  // src/sync/update-element-settings.ts
829
821
  var import_editor_v1_adapters16 = require("@elementor/editor-v1-adapters");
830
822
  var updateElementSettings = ({ id, props, withHistory = true }) => {
831
823
  const container = getContainer(id);
824
+ if (!container) {
825
+ return;
826
+ }
832
827
  const args = {
833
828
  container,
834
829
  settings: { ...props }
@@ -1141,16 +1136,13 @@ var updateElementInteractions = ({
1141
1136
  }
1142
1137
  element.model.set("interactions", interactions);
1143
1138
  window.dispatchEvent(new CustomEvent("elementor/element/update_interactions"));
1144
- setDocumentModifiedStatus2(true);
1139
+ (0, import_editor_v1_adapters20.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true });
1145
1140
  };
1146
1141
  var playElementInteractions = (elementId, interactionId) => {
1147
1142
  window.top?.dispatchEvent(
1148
1143
  new CustomEvent("atomic/play_interactions", { detail: { elementId, interactionId } })
1149
1144
  );
1150
1145
  };
1151
- function setDocumentModifiedStatus2(status) {
1152
- (0, import_editor_v1_adapters20.__privateRunCommandSync)("document/save/set-is-modified", { status }, { internal: true });
1153
- }
1154
1146
  // Annotate the CommonJS export names for ESM import in node:
1155
1147
  0 && (module.exports = {
1156
1148
  ELEMENT_STYLE_CHANGE_EVENT,
@@ -1180,7 +1172,6 @@ function setDocumentModifiedStatus2(status) {
1180
1172
  getElementType,
1181
1173
  getElements,
1182
1174
  getLinkInLinkRestriction,
1183
- getModel,
1184
1175
  getSelectedElements,
1185
1176
  getWidgetsCache,
1186
1177
  isElementAnchored,