@elementor/editor-components 4.2.0-916 → 4.2.0-918

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
@@ -1068,7 +1068,7 @@ import {
1068
1068
  selectElement
1069
1069
  } from "@elementor/editor-elements";
1070
1070
  import { undoable } from "@elementor/editor-v1-adapters";
1071
- import { __dispatch as dispatch2, __getState as getState3 } from "@elementor/store";
1071
+ import { __getState as getState3 } from "@elementor/store";
1072
1072
  import { __ as __9 } from "@wordpress/i18n";
1073
1073
 
1074
1074
  // src/prop-types/component-instance-overrides-prop-type.ts
@@ -1327,6 +1327,9 @@ function getOverridableOverride(propValue) {
1327
1327
  }
1328
1328
 
1329
1329
  // src/utils/detach-component-instance/detach-component-instance.ts
1330
+ var DETACH_EVENT = "elementor/components/detach-instance";
1331
+ var DETACH_UNDO_EVENT = "elementor/components/undo-detach-instance";
1332
+ var DETACH_REDO_EVENT = "elementor/components/redo-detach-instance";
1330
1333
  async function detachComponentInstance({
1331
1334
  instanceId,
1332
1335
  componentId,
@@ -1352,9 +1355,16 @@ async function detachComponentInstance({
1352
1355
  rootElement,
1353
1356
  overrides
1354
1357
  );
1355
- const editedComponentOnDetach = selectCurrentComponentId(getState3());
1356
- const overridablePropsBeforeDetach = editedComponentOnDetach ? selectOverridableProps(getState3(), editedComponentOnDetach) ?? null : null;
1357
1358
  const originalInstanceModel = instanceContainer.model.toJSON();
1359
+ const actionId = (/* @__PURE__ */ new Date()).getTime();
1360
+ window.dispatchEvent(
1361
+ new CustomEvent(DETACH_EVENT, {
1362
+ detail: {
1363
+ detachedInstanceId: instanceId,
1364
+ detachActionId: actionId
1365
+ }
1366
+ })
1367
+ );
1358
1368
  const detachedElement = replaceElement({
1359
1369
  currentElementId: instanceId,
1360
1370
  newElement: detachedInstanceElementData,
@@ -1374,51 +1384,48 @@ async function detachComponentInstance({
1374
1384
  return {
1375
1385
  detachedElement,
1376
1386
  detachedInstanceElementData,
1377
- editedComponentOnDetach,
1378
- overridablePropsBeforeDetach,
1379
- originalInstanceModel
1387
+ originalInstanceModel,
1388
+ actionId
1380
1389
  };
1381
1390
  },
1382
- undo: (_, {
1383
- detachedElement,
1384
- originalInstanceModel,
1385
- overridablePropsBeforeDetach,
1386
- editedComponentOnDetach
1387
- }) => {
1391
+ undo: (_, { detachedElement, originalInstanceModel, actionId }) => {
1388
1392
  const restoredInstance = replaceElement({
1389
1393
  currentElementId: detachedElement.id,
1390
1394
  newElement: originalInstanceModel,
1391
1395
  withHistory: false
1392
1396
  });
1393
- const currentComponentId = selectCurrentComponentId(getState3());
1394
- if (currentComponentId && currentComponentId === editedComponentOnDetach && overridablePropsBeforeDetach) {
1395
- dispatch2(
1396
- slice.actions.setOverridableProps({
1397
- componentId: currentComponentId,
1398
- overridableProps: overridablePropsBeforeDetach
1399
- })
1400
- );
1401
- }
1397
+ window.dispatchEvent(
1398
+ new CustomEvent(DETACH_UNDO_EVENT, {
1399
+ detail: {
1400
+ restoredInstanceId: restoredInstance.id,
1401
+ detachActionId: actionId
1402
+ }
1403
+ })
1404
+ );
1402
1405
  doAfterRender([restoredInstance.id], () => {
1403
1406
  selectElement(restoredInstance.id);
1404
1407
  });
1405
1408
  return restoredInstance;
1406
1409
  },
1407
1410
  redo: (_, doReturn, restoredInstance) => {
1408
- const { detachedInstanceElementData } = doReturn;
1409
- const editedComponentOnDetach = selectCurrentComponentId(getState3());
1410
- const overridablePropsBeforeDetach = editedComponentOnDetach ? selectOverridableProps(getState3(), editedComponentOnDetach) ?? null : null;
1411
+ const { detachedInstanceElementData, actionId } = doReturn;
1411
1412
  const detachedElement = replaceElement({
1412
1413
  currentElementId: restoredInstance.id,
1413
1414
  newElement: detachedInstanceElementData,
1414
1415
  withHistory: false
1415
1416
  });
1417
+ window.dispatchEvent(
1418
+ new CustomEvent(DETACH_REDO_EVENT, {
1419
+ detail: {
1420
+ detachedInstanceId: detachedElement.id,
1421
+ detachActionId: actionId
1422
+ }
1423
+ })
1424
+ );
1416
1425
  selectElement(detachedElement.id);
1417
1426
  return {
1418
1427
  ...doReturn,
1419
- detachedElement,
1420
- editedComponentOnDetach,
1421
- overridablePropsBeforeDetach
1428
+ detachedElement
1422
1429
  };
1423
1430
  }
1424
1431
  },
@@ -1655,40 +1662,40 @@ function getOverrideValue(overrideProp) {
1655
1662
  }
1656
1663
 
1657
1664
  // src/store/dispatchers.ts
1658
- import { __dispatch as dispatch3, __getStore as getStore } from "@elementor/store";
1665
+ import { __dispatch as dispatch2, __getStore as getStore } from "@elementor/store";
1659
1666
  function safeDispatch() {
1660
1667
  return getStore()?.dispatch;
1661
1668
  }
1662
1669
  var componentsActions = {
1663
1670
  add(components) {
1664
- dispatch3(slice.actions.add(components));
1671
+ dispatch2(slice.actions.add(components));
1665
1672
  },
1666
1673
  load(components) {
1667
- dispatch3(slice.actions.load(components));
1674
+ dispatch2(slice.actions.load(components));
1668
1675
  },
1669
1676
  addUnpublished(component) {
1670
- dispatch3(slice.actions.addUnpublished(component));
1677
+ dispatch2(slice.actions.addUnpublished(component));
1671
1678
  },
1672
1679
  removeUnpublished(uids) {
1673
- dispatch3(slice.actions.removeUnpublished(uids));
1680
+ dispatch2(slice.actions.removeUnpublished(uids));
1674
1681
  },
1675
1682
  resetUnpublished() {
1676
- dispatch3(slice.actions.resetUnpublished());
1683
+ dispatch2(slice.actions.resetUnpublished());
1677
1684
  },
1678
1685
  removeStyles(id) {
1679
- dispatch3(slice.actions.removeStyles({ id }));
1686
+ dispatch2(slice.actions.removeStyles({ id }));
1680
1687
  },
1681
1688
  addStyles(styles) {
1682
- dispatch3(slice.actions.addStyles(styles));
1689
+ dispatch2(slice.actions.addStyles(styles));
1683
1690
  },
1684
1691
  addCreatedThisSession(uid) {
1685
- dispatch3(slice.actions.addCreatedThisSession(uid));
1692
+ dispatch2(slice.actions.addCreatedThisSession(uid));
1686
1693
  },
1687
1694
  removeCreatedThisSession(uid) {
1688
- dispatch3(slice.actions.removeCreatedThisSession(uid));
1695
+ dispatch2(slice.actions.removeCreatedThisSession(uid));
1689
1696
  },
1690
1697
  archive(componentId) {
1691
- dispatch3(slice.actions.archive(componentId));
1698
+ dispatch2(slice.actions.archive(componentId));
1692
1699
  },
1693
1700
  setCurrentComponentId(id) {
1694
1701
  safeDispatch()?.(slice.actions.setCurrentComponentId(id));
@@ -1697,19 +1704,19 @@ var componentsActions = {
1697
1704
  safeDispatch()?.(slice.actions.setPath(path));
1698
1705
  },
1699
1706
  setOverridableProps(componentId, overridableProps) {
1700
- dispatch3(slice.actions.setOverridableProps({ componentId, overridableProps }));
1707
+ dispatch2(slice.actions.setOverridableProps({ componentId, overridableProps }));
1701
1708
  },
1702
1709
  rename(componentUid, name) {
1703
- dispatch3(slice.actions.rename({ componentUid, name }));
1710
+ dispatch2(slice.actions.rename({ componentUid, name }));
1704
1711
  },
1705
1712
  cleanUpdatedComponentNames() {
1706
- dispatch3(slice.actions.cleanUpdatedComponentNames());
1713
+ dispatch2(slice.actions.cleanUpdatedComponentNames());
1707
1714
  },
1708
1715
  updateComponentSanitizedAttribute(componentId, attribute) {
1709
- dispatch3(slice.actions.updateComponentSanitizedAttribute({ componentId, attribute }));
1716
+ dispatch2(slice.actions.updateComponentSanitizedAttribute({ componentId, attribute }));
1710
1717
  },
1711
1718
  resetSanitizedComponents() {
1712
- dispatch3(slice.actions.resetSanitizedComponents());
1719
+ dispatch2(slice.actions.resetSanitizedComponents());
1713
1720
  }
1714
1721
  };
1715
1722
 
@@ -2554,19 +2561,19 @@ async function getDocumentsMap(ids, cache) {
2554
2561
  }
2555
2562
 
2556
2563
  // src/store/actions/load-components-overridable-props.ts
2557
- import { __dispatch as dispatch4, __getState as getState6 } from "@elementor/store";
2564
+ import { __dispatch as dispatch3, __getState as getState6 } from "@elementor/store";
2558
2565
  async function loadComponentsOverridableProps(componentIds) {
2559
2566
  const unloadedIds = componentIds.filter((id) => !selectIsOverridablePropsLoaded(getState6(), id));
2560
2567
  if (!unloadedIds.length) {
2561
2568
  return;
2562
2569
  }
2563
2570
  const { data } = await apiClient.getOverridableProps(unloadedIds);
2564
- dispatch4(slice.actions.loadOverridableProps(data));
2571
+ dispatch3(slice.actions.loadOverridableProps(data));
2565
2572
  }
2566
2573
 
2567
2574
  // src/store/actions/load-components-styles.ts
2568
2575
  import { addDocumentClasses } from "@elementor/editor-global-classes";
2569
- import { __dispatch as dispatch5, __getState as getState7 } from "@elementor/store";
2576
+ import { __dispatch as dispatch4, __getState as getState7 } from "@elementor/store";
2570
2577
  function loadComponentsStyles(documents) {
2571
2578
  if (!documents.size) {
2572
2579
  return;
@@ -2585,7 +2592,7 @@ function addStyles(documents) {
2585
2592
  return [id, extractStylesFromDocument(document2)];
2586
2593
  })
2587
2594
  );
2588
- dispatch5(slice.actions.addStyles(styles));
2595
+ dispatch4(slice.actions.addStyles(styles));
2589
2596
  }
2590
2597
  function extractStylesFromDocument(document2) {
2591
2598
  if (!document2.elements?.length) {
@@ -3040,10 +3047,10 @@ function createComponentModel() {
3040
3047
 
3041
3048
  // src/populate-store.ts
3042
3049
  import { useEffect as useEffect2 } from "react";
3043
- import { __dispatch as dispatch6 } from "@elementor/store";
3050
+ import { __dispatch as dispatch5 } from "@elementor/store";
3044
3051
  function PopulateStore() {
3045
3052
  useEffect2(() => {
3046
- dispatch6(loadComponents());
3053
+ dispatch5(loadComponents());
3047
3054
  }, []);
3048
3055
  return null;
3049
3056
  }
@@ -3176,10 +3183,10 @@ function blockCircularPaste(args) {
3176
3183
  }
3177
3184
 
3178
3185
  // src/store/actions/remove-component-styles.ts
3179
- import { __dispatch as dispatch7 } from "@elementor/store";
3186
+ import { __dispatch as dispatch6 } from "@elementor/store";
3180
3187
  function removeComponentStyles(id) {
3181
3188
  apiClient.invalidateComponentConfigCache(id);
3182
- dispatch7(slice.actions.removeStyles({ id }));
3189
+ dispatch6(slice.actions.removeStyles({ id }));
3183
3190
  }
3184
3191
 
3185
3192
  // src/store/components-styles-provider.ts