@elementor/editor-elements 4.4.0 → 4.4.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/index.mjs CHANGED
@@ -530,7 +530,8 @@ function deleteElement({ container, options = {} }) {
530
530
  var createElements = ({
531
531
  elements,
532
532
  title,
533
- subtitle = __("Item added", "elementor")
533
+ subtitle = __("Item added", "elementor"),
534
+ origin
534
535
  }) => {
535
536
  const undoableCreate = undoable(
536
537
  {
@@ -544,7 +545,7 @@ var createElements = ({
544
545
  const element = createElement({
545
546
  container: parentContainer,
546
547
  ...elementParams,
547
- options: { ...options, useHistory: false }
548
+ options: { ...options, useHistory: false, origin }
548
549
  });
549
550
  createdElements.push({
550
551
  container: element,
@@ -563,7 +564,7 @@ var createElements = ({
563
564
  if (freshContainer) {
564
565
  deleteElement({
565
566
  container: freshContainer,
566
- options: { useHistory: false }
567
+ options: { useHistory: false, origin }
567
568
  });
568
569
  return;
569
570
  }
@@ -578,7 +579,7 @@ var createElements = ({
578
579
  const element = createElement({
579
580
  container: freshParent,
580
581
  model,
581
- options: { ...options, useHistory: false }
582
+ options: { ...options, useHistory: false, origin }
582
583
  });
583
584
  newElements.push({
584
585
  container: element,
@@ -644,7 +645,8 @@ var duplicateElements = ({
644
645
  title,
645
646
  subtitle = __2("Item duplicated", "elementor"),
646
647
  onDuplicateElements,
647
- onRestoreElements
648
+ onRestoreElements,
649
+ origin
648
650
  }) => {
649
651
  const undoableDuplicate = undoable2(
650
652
  {
@@ -658,7 +660,7 @@ var duplicateElements = ({
658
660
  }
659
661
  const duplicatedElement = duplicateElement({
660
662
  element: originalContainer,
661
- options: { useHistory: false }
663
+ options: { useHistory: false, origin }
662
664
  });
663
665
  if (!duplicatedElement.parent) {
664
666
  return;
@@ -681,7 +683,7 @@ var duplicateElements = ({
681
683
  if (freshContainer) {
682
684
  deleteElement({
683
685
  container: freshContainer,
684
- options: { useHistory: false }
686
+ options: { useHistory: false, origin }
685
687
  });
686
688
  return;
687
689
  }
@@ -697,7 +699,7 @@ var duplicateElements = ({
697
699
  const createdElement = createElement({
698
700
  container: freshParent,
699
701
  model,
700
- options: { useHistory: false, clone: false, at }
702
+ options: { useHistory: false, clone: false, at, origin }
701
703
  });
702
704
  duplicatedElements.push({
703
705
  container: createdElement,
@@ -888,6 +890,74 @@ var getElementStyles = (elementID) => {
888
890
  return container?.model.get("styles") || null;
889
891
  };
890
892
 
893
+ // src/sync/get-element-widget-markers.ts
894
+ import { z } from "@elementor/schema";
895
+ var WIDGET_ID_PATTERN = /^[a-z0-9-]+\/[a-z0-9-]+$/;
896
+ var PART_PATTERN = /^[a-z][a-z0-9_]*$/;
897
+ var MIN_VERSION = 1;
898
+ var WIDGET_MARKER_KEYS = {
899
+ widget: "widget",
900
+ part: "part",
901
+ slot: "slot"
902
+ };
903
+ var widgetMarkerSchema = z.object({
904
+ id: z.string().regex(WIDGET_ID_PATTERN),
905
+ version: z.number().int().min(MIN_VERSION),
906
+ values: z.record(z.unknown()).optional()
907
+ });
908
+ var partSchema = z.string().regex(PART_PATTERN);
909
+ function getContainerWidgetMarker(container) {
910
+ const result = widgetMarkerSchema.safeParse(container?.model.get(WIDGET_MARKER_KEYS.widget));
911
+ if (!result.success) {
912
+ return null;
913
+ }
914
+ return { ...result.data, values: result.data.values ?? {} };
915
+ }
916
+ function getContainerPart(container) {
917
+ const result = partSchema.safeParse(container?.model.get(WIDGET_MARKER_KEYS.part));
918
+ return result.success ? result.data : null;
919
+ }
920
+ function isContainerSlot(container) {
921
+ return true === container?.model.get(WIDGET_MARKER_KEYS.slot) && null !== getContainerPart(container);
922
+ }
923
+
924
+ // src/sync/regenerate-local-style-ids.ts
925
+ import { classesPropTypeUtil } from "@elementor/editor-props";
926
+ function regenerateLocalStyleIds(element) {
927
+ const originalStyles = element.styles;
928
+ if (!originalStyles || Object.keys(originalStyles).length === 0) {
929
+ return { styles: void 0, settings: void 0 };
930
+ }
931
+ const newStyles = {};
932
+ const styleIdMapping = {};
933
+ for (const [originalStyleId, style] of Object.entries(originalStyles)) {
934
+ const newStyleId = generateLocalStyleId(element.id);
935
+ newStyles[newStyleId] = { ...style, id: newStyleId };
936
+ styleIdMapping[originalStyleId] = newStyleId;
937
+ }
938
+ const settings = element.settings;
939
+ if (!settings || Object.keys(settings).length === 0) {
940
+ return { styles: newStyles, settings: void 0 };
941
+ }
942
+ const updatedSettings = { ...settings };
943
+ for (const [propKey, propValue] of Object.entries(updatedSettings)) {
944
+ if (isClassesProp(propValue) && propValue.value.length > 0) {
945
+ const updatedClasses = propValue.value.map((classId) => styleIdMapping[classId] ?? classId);
946
+ updatedSettings[propKey] = classesPropTypeUtil.create(updatedClasses);
947
+ }
948
+ }
949
+ return {
950
+ styles: newStyles,
951
+ settings: updatedSettings
952
+ };
953
+ }
954
+ function isClassesProp(prop) {
955
+ return classesPropTypeUtil.isValid(prop);
956
+ }
957
+ function generateLocalStyleId(elementId) {
958
+ return `e-${elementId}-${generateElementId()}`;
959
+ }
960
+
891
961
  // src/sync/get-all-descendants.ts
892
962
  function getAllDescendants(container) {
893
963
  const children = (container.children ?? []).flatMap((child) => getAllDescendants(child));
@@ -963,7 +1033,8 @@ var moveElements = ({
963
1033
  title,
964
1034
  subtitle = __3("Elements moved", "elementor"),
965
1035
  onMoveElements,
966
- onRestoreElements
1036
+ onRestoreElements,
1037
+ origin
967
1038
  }) => {
968
1039
  const undoableMove = undoable3(
969
1040
  {
@@ -987,7 +1058,7 @@ var moveElements = ({
987
1058
  const newElement = moveElement({
988
1059
  element: sourceElement,
989
1060
  targetContainer: target,
990
- options: { ...options, useHistory: false }
1061
+ options: { ...options, useHistory: false, origin }
991
1062
  });
992
1063
  movedElements.push({
993
1064
  element: newElement,
@@ -1015,7 +1086,8 @@ var moveElements = ({
1015
1086
  targetContainer: freshOriginalContainer,
1016
1087
  options: {
1017
1088
  useHistory: false,
1018
- at: originalIndex >= 0 ? originalIndex : void 0
1089
+ at: originalIndex >= 0 ? originalIndex : void 0,
1090
+ origin
1019
1091
  }
1020
1092
  });
1021
1093
  });
@@ -1043,7 +1115,7 @@ var moveElements = ({
1043
1115
  const newElement = moveElement({
1044
1116
  element: freshElement,
1045
1117
  targetContainer: freshTarget,
1046
- options: { ...options, useHistory: false }
1118
+ options: { ...options, useHistory: false, origin }
1047
1119
  });
1048
1120
  newMovedElements.push({
1049
1121
  element: newElement,
@@ -1076,7 +1148,8 @@ var removeElements = ({
1076
1148
  title,
1077
1149
  subtitle = __4("Item removed", "elementor"),
1078
1150
  onRemoveElements,
1079
- onRestoreElements
1151
+ onRestoreElements,
1152
+ origin
1080
1153
  }) => {
1081
1154
  const undoableRemove = undoable4(
1082
1155
  {
@@ -1099,7 +1172,7 @@ var removeElements = ({
1099
1172
  removedElements.forEach(({ container }) => {
1100
1173
  deleteElement({
1101
1174
  container,
1102
- options: { useHistory: false }
1175
+ options: { useHistory: false, origin }
1103
1176
  });
1104
1177
  });
1105
1178
  return { removedElements };
@@ -1112,7 +1185,7 @@ var removeElements = ({
1112
1185
  createElement({
1113
1186
  container: freshParent,
1114
1187
  model,
1115
- options: { useHistory: false, at }
1188
+ options: { useHistory: false, at, origin }
1116
1189
  });
1117
1190
  return;
1118
1191
  }
@@ -1128,7 +1201,7 @@ var removeElements = ({
1128
1201
  if (freshContainer && freshParent) {
1129
1202
  deleteElement({
1130
1203
  container: freshContainer,
1131
- options: { useHistory: false }
1204
+ options: { useHistory: false, origin }
1132
1205
  });
1133
1206
  newRemovedElements.push({
1134
1207
  container: freshContainer,
@@ -1346,13 +1419,13 @@ var styleRerenderEvents = [
1346
1419
  ];
1347
1420
 
1348
1421
  // src/styles/create-element-style.ts
1349
- import { classesPropTypeUtil as classesPropTypeUtil2 } from "@elementor/editor-props";
1422
+ import { classesPropTypeUtil as classesPropTypeUtil3 } from "@elementor/editor-props";
1350
1423
  import {
1351
1424
  generateId
1352
1425
  } from "@elementor/editor-styles";
1353
1426
 
1354
1427
  // src/styles/mutate-element-styles.ts
1355
- import { classesPropTypeUtil } from "@elementor/editor-props";
1428
+ import { classesPropTypeUtil as classesPropTypeUtil2 } from "@elementor/editor-props";
1356
1429
  import { __privateRunCommandSync as runCommandSync7 } from "@elementor/editor-v1-adapters";
1357
1430
  function mutateElementStyles(elementId, mutator) {
1358
1431
  const container = getContainer(elementId);
@@ -1407,7 +1480,7 @@ function clearRemovedClasses(container, { oldIds, newIds }) {
1407
1480
  function getClassesProps(container) {
1408
1481
  return Object.entries(container.settings.toJSON()).filter((prop) => {
1409
1482
  const [, value] = prop;
1410
- return classesPropTypeUtil.isValid(value);
1483
+ return classesPropTypeUtil2.isValid(value);
1411
1484
  });
1412
1485
  }
1413
1486
  function notifyChanges() {
@@ -1446,7 +1519,7 @@ function createElementStyle({
1446
1519
  }
1447
1520
  function addStyleToClassesProp(elementId, classesProp, styleId) {
1448
1521
  const base = getElementSetting(elementId, classesProp);
1449
- const classesPropValue = classesPropTypeUtil2.create(
1522
+ const classesPropValue = classesPropTypeUtil3.create(
1450
1523
  (prev) => {
1451
1524
  return [...prev ?? [], styleId];
1452
1525
  },
@@ -1567,6 +1640,7 @@ var playElementInteractions = (elementId, interactionId) => {
1567
1640
  export {
1568
1641
  DEFAULT_STYLE_CLASS_PREFIX,
1569
1642
  ELEMENT_STYLE_CHANGE_EVENT,
1643
+ WIDGET_MARKER_KEYS,
1570
1644
  addModelToParent,
1571
1645
  bindSettingsReconcile,
1572
1646
  cloneElementTree,
@@ -1587,6 +1661,8 @@ export {
1587
1661
  getAnchoredAncestorId,
1588
1662
  getAnchoredDescendantId,
1589
1663
  getContainer,
1664
+ getContainerPart,
1665
+ getContainerWidgetMarker,
1590
1666
  getCurrentDocumentContainer,
1591
1667
  getCurrentDocumentId,
1592
1668
  getDefaultStyleTagFromPreviewElement,
@@ -1607,12 +1683,14 @@ export {
1607
1683
  getPreviewElementDOM,
1608
1684
  getSelectedElements,
1609
1685
  getWidgetsCache,
1686
+ isContainerSlot,
1610
1687
  isElementAnchored,
1611
1688
  moveElement,
1612
1689
  moveElements,
1613
1690
  parseDefaultStyleTagFromClassList,
1614
1691
  playElementInteractions,
1615
1692
  reconcileInitialChildren,
1693
+ regenerateLocalStyleIds,
1616
1694
  removeElements,
1617
1695
  removeModelFromParent,
1618
1696
  replaceElement,