@elementor/editor-components 4.3.0-1033 → 4.3.0-1035

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
@@ -2612,6 +2612,66 @@ function formatComponentElementsId(elements, path) {
2612
2612
  });
2613
2613
  }
2614
2614
 
2615
+ // src/utils/reconcile-component-instance-elements.ts
2616
+ import {
2617
+ getWidgetsCache as getWidgetsCache2,
2618
+ reconcileInitialChildren
2619
+ } from "@elementor/editor-elements";
2620
+ import { hashString as hashString2 } from "@elementor/utils";
2621
+ var ELEMENT_ID_LENGTH2 = 7;
2622
+ function overridesRecordToMapping(overrides) {
2623
+ const mapping = {};
2624
+ for (const [key, value] of Object.entries(overrides)) {
2625
+ mapping[key] = { value };
2626
+ }
2627
+ return mapping;
2628
+ }
2629
+ function getElementConfig(element) {
2630
+ const type = element.elType === "widget" ? element.widgetType : element.elType;
2631
+ if (!type) {
2632
+ return void 0;
2633
+ }
2634
+ return getWidgetsCache2()?.[type];
2635
+ }
2636
+ function deriveIds(element, seed) {
2637
+ const id = hashString2(seed, ELEMENT_ID_LENGTH2);
2638
+ return {
2639
+ ...element,
2640
+ id,
2641
+ elements: (element.elements ?? []).map((child, index) => deriveIds(child, `${id}_${index}`))
2642
+ };
2643
+ }
2644
+ function reconcileElementTree(element, overridesMapping) {
2645
+ const elementConfig = getElementConfig(element);
2646
+ const withOverrides = applyOverridesToSettings(element.settings ?? {}, overridesMapping);
2647
+ const effectiveSettings = unwrapOverridableSettings(withOverrides);
2648
+ const originalChildren = element.elements ?? [];
2649
+ const originalChildIds = new Set(originalChildren.map((child) => child.id));
2650
+ const attributes = {
2651
+ elements: [...originalChildren],
2652
+ settings: effectiveSettings
2653
+ };
2654
+ if (elementConfig?.children_dependencies?.length) {
2655
+ reconcileInitialChildren({
2656
+ elementId: element.id,
2657
+ elementConfig,
2658
+ attributes
2659
+ });
2660
+ }
2661
+ const reconciledChildren = (attributes.elements ?? []).map(
2662
+ (child) => originalChildIds.has(child.id) ? child : deriveIds(child, `${element.id}_${child.elType}`)
2663
+ ).map((child) => reconcileElementTree(child, overridesMapping));
2664
+ return {
2665
+ ...element,
2666
+ settings: effectiveSettings,
2667
+ elements: reconciledChildren
2668
+ };
2669
+ }
2670
+ function reconcileComponentInstanceElements(elements, overrides = {}) {
2671
+ const overridesMapping = overridesRecordToMapping(overrides);
2672
+ return elements.map((element) => reconcileElementTree(element, overridesMapping));
2673
+ }
2674
+
2615
2675
  // src/utils/switch-to-component.ts
2616
2676
  import { invalidateDocumentData, switchToDocument } from "@elementor/editor-documents";
2617
2677
  import { getCurrentDocumentContainer, selectElement as selectElement2 } from "@elementor/editor-elements";
@@ -2788,7 +2848,11 @@ function createComponentView(options) {
2788
2848
  };
2789
2849
  const instanceId = this.model.get("id");
2790
2850
  const elements = componentInstance.elements ?? [];
2791
- const formattedElements = formatComponentElementsId(elements, [instanceId]);
2851
+ const reconciledElements = reconcileComponentInstanceElements(
2852
+ elements,
2853
+ componentInstance.overrides ?? {}
2854
+ );
2855
+ const formattedElements = formatComponentElementsId(reconciledElements, [instanceId]);
2792
2856
  this.collection = legacyWindow.elementor.createBackboneElementsCollection(formattedElements);
2793
2857
  this.collection.models.forEach(setInactiveRecursively);
2794
2858
  settings.component_instance = "<template data-children-placeholder></template>";