@elementor/editor-components 4.2.0-915 → 4.2.0-917

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
@@ -1061,9 +1061,14 @@ import { DetachIcon } from "@elementor/icons";
1061
1061
  import { __ as __10 } from "@wordpress/i18n";
1062
1062
 
1063
1063
  // src/utils/detach-component-instance/detach-component-instance.ts
1064
- import { getContainer, replaceElement } from "@elementor/editor-elements";
1064
+ import { doAfterRender } from "@elementor/editor-canvas";
1065
+ import {
1066
+ getContainer,
1067
+ replaceElement,
1068
+ selectElement
1069
+ } from "@elementor/editor-elements";
1065
1070
  import { undoable } from "@elementor/editor-v1-adapters";
1066
- import { __dispatch as dispatch2, __getState as getState3 } from "@elementor/store";
1071
+ import { __getState as getState3 } from "@elementor/store";
1067
1072
  import { __ as __9 } from "@wordpress/i18n";
1068
1073
 
1069
1074
  // src/prop-types/component-instance-overrides-prop-type.ts
@@ -1259,7 +1264,7 @@ function resolvePropValue(propValue, overrideMap, options) {
1259
1264
  return resolveOverridableOverride(matchingOverride, originValue);
1260
1265
  }
1261
1266
  const matchingOverrideValue = componentInstanceOverridePropTypeUtil.extract(matchingOverride)?.override_value;
1262
- return matchingOverrideValue;
1267
+ return matchingOverrideValue ?? originValue;
1263
1268
  }
1264
1269
  function resolveOverridableOverride(matchingOverride, originValue) {
1265
1270
  if (!originValue || !componentInstanceOverridePropTypeUtil.isValid(originValue)) {
@@ -1322,6 +1327,9 @@ function getOverridableOverride(propValue) {
1322
1327
  }
1323
1328
 
1324
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";
1325
1333
  async function detachComponentInstance({
1326
1334
  instanceId,
1327
1335
  componentId,
@@ -1347,14 +1355,22 @@ async function detachComponentInstance({
1347
1355
  rootElement,
1348
1356
  overrides
1349
1357
  );
1350
- const editedComponentOnDetach = selectCurrentComponentId(getState3());
1351
- const overridablePropsBeforeDetach = editedComponentOnDetach ? selectOverridableProps(getState3(), editedComponentOnDetach) ?? null : null;
1352
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
+ );
1353
1368
  const detachedElement = replaceElement({
1354
1369
  currentElementId: instanceId,
1355
1370
  newElement: detachedInstanceElementData,
1356
1371
  withHistory: false
1357
1372
  });
1373
+ selectElement(detachedElement.id);
1358
1374
  const componentUid = selectComponent(getState3(), componentId)?.uid;
1359
1375
  trackComponentEvent({
1360
1376
  action: "detached",
@@ -1368,47 +1384,48 @@ async function detachComponentInstance({
1368
1384
  return {
1369
1385
  detachedElement,
1370
1386
  detachedInstanceElementData,
1371
- editedComponentOnDetach,
1372
- overridablePropsBeforeDetach,
1373
- originalInstanceModel
1387
+ originalInstanceModel,
1388
+ actionId
1374
1389
  };
1375
1390
  },
1376
- undo: (_, {
1377
- detachedElement,
1378
- originalInstanceModel,
1379
- overridablePropsBeforeDetach,
1380
- editedComponentOnDetach
1381
- }) => {
1391
+ undo: (_, { detachedElement, originalInstanceModel, actionId }) => {
1382
1392
  const restoredInstance = replaceElement({
1383
1393
  currentElementId: detachedElement.id,
1384
1394
  newElement: originalInstanceModel,
1385
1395
  withHistory: false
1386
1396
  });
1387
- const currentComponentId = selectCurrentComponentId(getState3());
1388
- if (currentComponentId && currentComponentId === editedComponentOnDetach && overridablePropsBeforeDetach) {
1389
- dispatch2(
1390
- slice.actions.setOverridableProps({
1391
- componentId: currentComponentId,
1392
- overridableProps: overridablePropsBeforeDetach
1393
- })
1394
- );
1395
- }
1397
+ window.dispatchEvent(
1398
+ new CustomEvent(DETACH_UNDO_EVENT, {
1399
+ detail: {
1400
+ restoredInstanceId: restoredInstance.id,
1401
+ detachActionId: actionId
1402
+ }
1403
+ })
1404
+ );
1405
+ doAfterRender([restoredInstance.id], () => {
1406
+ selectElement(restoredInstance.id);
1407
+ });
1396
1408
  return restoredInstance;
1397
1409
  },
1398
1410
  redo: (_, doReturn, restoredInstance) => {
1399
- const { detachedInstanceElementData } = doReturn;
1400
- const editedComponentOnDetach = selectCurrentComponentId(getState3());
1401
- const overridablePropsBeforeDetach = editedComponentOnDetach ? selectOverridableProps(getState3(), editedComponentOnDetach) ?? null : null;
1411
+ const { detachedInstanceElementData, actionId } = doReturn;
1402
1412
  const detachedElement = replaceElement({
1403
1413
  currentElementId: restoredInstance.id,
1404
1414
  newElement: detachedInstanceElementData,
1405
1415
  withHistory: false
1406
1416
  });
1417
+ window.dispatchEvent(
1418
+ new CustomEvent(DETACH_REDO_EVENT, {
1419
+ detail: {
1420
+ detachedInstanceId: detachedElement.id,
1421
+ detachActionId: actionId
1422
+ }
1423
+ })
1424
+ );
1425
+ selectElement(detachedElement.id);
1407
1426
  return {
1408
1427
  ...doReturn,
1409
- detachedElement,
1410
- editedComponentOnDetach,
1411
- overridablePropsBeforeDetach
1428
+ detachedElement
1412
1429
  };
1413
1430
  }
1414
1431
  },
@@ -1645,40 +1662,40 @@ function getOverrideValue(overrideProp) {
1645
1662
  }
1646
1663
 
1647
1664
  // src/store/dispatchers.ts
1648
- import { __dispatch as dispatch3, __getStore as getStore } from "@elementor/store";
1665
+ import { __dispatch as dispatch2, __getStore as getStore } from "@elementor/store";
1649
1666
  function safeDispatch() {
1650
1667
  return getStore()?.dispatch;
1651
1668
  }
1652
1669
  var componentsActions = {
1653
1670
  add(components) {
1654
- dispatch3(slice.actions.add(components));
1671
+ dispatch2(slice.actions.add(components));
1655
1672
  },
1656
1673
  load(components) {
1657
- dispatch3(slice.actions.load(components));
1674
+ dispatch2(slice.actions.load(components));
1658
1675
  },
1659
1676
  addUnpublished(component) {
1660
- dispatch3(slice.actions.addUnpublished(component));
1677
+ dispatch2(slice.actions.addUnpublished(component));
1661
1678
  },
1662
1679
  removeUnpublished(uids) {
1663
- dispatch3(slice.actions.removeUnpublished(uids));
1680
+ dispatch2(slice.actions.removeUnpublished(uids));
1664
1681
  },
1665
1682
  resetUnpublished() {
1666
- dispatch3(slice.actions.resetUnpublished());
1683
+ dispatch2(slice.actions.resetUnpublished());
1667
1684
  },
1668
1685
  removeStyles(id) {
1669
- dispatch3(slice.actions.removeStyles({ id }));
1686
+ dispatch2(slice.actions.removeStyles({ id }));
1670
1687
  },
1671
1688
  addStyles(styles) {
1672
- dispatch3(slice.actions.addStyles(styles));
1689
+ dispatch2(slice.actions.addStyles(styles));
1673
1690
  },
1674
1691
  addCreatedThisSession(uid) {
1675
- dispatch3(slice.actions.addCreatedThisSession(uid));
1692
+ dispatch2(slice.actions.addCreatedThisSession(uid));
1676
1693
  },
1677
1694
  removeCreatedThisSession(uid) {
1678
- dispatch3(slice.actions.removeCreatedThisSession(uid));
1695
+ dispatch2(slice.actions.removeCreatedThisSession(uid));
1679
1696
  },
1680
1697
  archive(componentId) {
1681
- dispatch3(slice.actions.archive(componentId));
1698
+ dispatch2(slice.actions.archive(componentId));
1682
1699
  },
1683
1700
  setCurrentComponentId(id) {
1684
1701
  safeDispatch()?.(slice.actions.setCurrentComponentId(id));
@@ -1687,19 +1704,19 @@ var componentsActions = {
1687
1704
  safeDispatch()?.(slice.actions.setPath(path));
1688
1705
  },
1689
1706
  setOverridableProps(componentId, overridableProps) {
1690
- dispatch3(slice.actions.setOverridableProps({ componentId, overridableProps }));
1707
+ dispatch2(slice.actions.setOverridableProps({ componentId, overridableProps }));
1691
1708
  },
1692
1709
  rename(componentUid, name) {
1693
- dispatch3(slice.actions.rename({ componentUid, name }));
1710
+ dispatch2(slice.actions.rename({ componentUid, name }));
1694
1711
  },
1695
1712
  cleanUpdatedComponentNames() {
1696
- dispatch3(slice.actions.cleanUpdatedComponentNames());
1713
+ dispatch2(slice.actions.cleanUpdatedComponentNames());
1697
1714
  },
1698
1715
  updateComponentSanitizedAttribute(componentId, attribute) {
1699
- dispatch3(slice.actions.updateComponentSanitizedAttribute({ componentId, attribute }));
1716
+ dispatch2(slice.actions.updateComponentSanitizedAttribute({ componentId, attribute }));
1700
1717
  },
1701
1718
  resetSanitizedComponents() {
1702
- dispatch3(slice.actions.resetSanitizedComponents());
1719
+ dispatch2(slice.actions.resetSanitizedComponents());
1703
1720
  }
1704
1721
  };
1705
1722
 
@@ -2544,19 +2561,19 @@ async function getDocumentsMap(ids, cache) {
2544
2561
  }
2545
2562
 
2546
2563
  // src/store/actions/load-components-overridable-props.ts
2547
- import { __dispatch as dispatch4, __getState as getState6 } from "@elementor/store";
2564
+ import { __dispatch as dispatch3, __getState as getState6 } from "@elementor/store";
2548
2565
  async function loadComponentsOverridableProps(componentIds) {
2549
2566
  const unloadedIds = componentIds.filter((id) => !selectIsOverridablePropsLoaded(getState6(), id));
2550
2567
  if (!unloadedIds.length) {
2551
2568
  return;
2552
2569
  }
2553
2570
  const { data } = await apiClient.getOverridableProps(unloadedIds);
2554
- dispatch4(slice.actions.loadOverridableProps(data));
2571
+ dispatch3(slice.actions.loadOverridableProps(data));
2555
2572
  }
2556
2573
 
2557
2574
  // src/store/actions/load-components-styles.ts
2558
2575
  import { addDocumentClasses } from "@elementor/editor-global-classes";
2559
- import { __dispatch as dispatch5, __getState as getState7 } from "@elementor/store";
2576
+ import { __dispatch as dispatch4, __getState as getState7 } from "@elementor/store";
2560
2577
  function loadComponentsStyles(documents) {
2561
2578
  if (!documents.size) {
2562
2579
  return;
@@ -2575,7 +2592,7 @@ function addStyles(documents) {
2575
2592
  return [id, extractStylesFromDocument(document2)];
2576
2593
  })
2577
2594
  );
2578
- dispatch5(slice.actions.addStyles(styles));
2595
+ dispatch4(slice.actions.addStyles(styles));
2579
2596
  }
2580
2597
  function extractStylesFromDocument(document2) {
2581
2598
  if (!document2.elements?.length) {
@@ -2647,7 +2664,7 @@ function formatComponentElementsId(elements, path) {
2647
2664
 
2648
2665
  // src/utils/switch-to-component.ts
2649
2666
  import { invalidateDocumentData, switchToDocument } from "@elementor/editor-documents";
2650
- import { getCurrentDocumentContainer, selectElement } from "@elementor/editor-elements";
2667
+ import { getCurrentDocumentContainer, selectElement as selectElement2 } from "@elementor/editor-elements";
2651
2668
  import { __privateRunCommand as runCommand } from "@elementor/editor-v1-adapters";
2652
2669
  async function switchToComponent(componentId, componentInstanceId, element) {
2653
2670
  const selector = getSelector(element, componentInstanceId);
@@ -2661,7 +2678,7 @@ async function switchToComponent(componentId, componentInstanceId, element) {
2661
2678
  const currentDocumentContainer = getCurrentDocumentContainer();
2662
2679
  const topLevelElement = currentDocumentContainer?.children?.[0];
2663
2680
  if (topLevelElement) {
2664
- selectElement(topLevelElement.id);
2681
+ selectElement2(topLevelElement.id);
2665
2682
  expandNavigator();
2666
2683
  }
2667
2684
  }
@@ -3030,10 +3047,10 @@ function createComponentModel() {
3030
3047
 
3031
3048
  // src/populate-store.ts
3032
3049
  import { useEffect as useEffect2 } from "react";
3033
- import { __dispatch as dispatch6 } from "@elementor/store";
3050
+ import { __dispatch as dispatch5 } from "@elementor/store";
3034
3051
  function PopulateStore() {
3035
3052
  useEffect2(() => {
3036
- dispatch6(loadComponents());
3053
+ dispatch5(loadComponents());
3037
3054
  }, []);
3038
3055
  return null;
3039
3056
  }
@@ -3166,10 +3183,10 @@ function blockCircularPaste(args) {
3166
3183
  }
3167
3184
 
3168
3185
  // src/store/actions/remove-component-styles.ts
3169
- import { __dispatch as dispatch7 } from "@elementor/store";
3186
+ import { __dispatch as dispatch6 } from "@elementor/store";
3170
3187
  function removeComponentStyles(id) {
3171
3188
  apiClient.invalidateComponentConfigCache(id);
3172
- dispatch7(slice.actions.removeStyles({ id }));
3189
+ dispatch6(slice.actions.removeStyles({ id }));
3173
3190
  }
3174
3191
 
3175
3192
  // src/store/components-styles-provider.ts