@elementor/editor-components 3.35.0-402 → 3.35.0-403

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
@@ -362,15 +362,44 @@ var import_store5 = require("@elementor/store");
362
362
 
363
363
  // src/utils/switch-to-component.ts
364
364
  var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
365
- function switchToComponent(componentId, componentInstanceId) {
365
+ function switchToComponent(componentId, componentInstanceId, element) {
366
+ const selector = getSelector(element, componentInstanceId);
366
367
  (0, import_editor_v1_adapters2.__privateRunCommand)("editor/documents/switch", {
367
368
  id: componentId,
368
- selector: componentInstanceId ? `[data-id="${componentInstanceId}"]` : void 0,
369
+ selector,
369
370
  mode: "autosave",
370
371
  setAsInitial: false,
371
372
  shouldScroll: false
372
373
  });
373
374
  }
375
+ function getSelector(element, componentInstanceId) {
376
+ if (element) {
377
+ return buildUniqueSelector(element);
378
+ }
379
+ if (componentInstanceId) {
380
+ return `[data-id="${componentInstanceId}"]`;
381
+ }
382
+ return void 0;
383
+ }
384
+ function buildUniqueSelector(element) {
385
+ const selectors = [];
386
+ let current = element.closest("[data-id]");
387
+ while (current) {
388
+ const dataId = current.dataset.id;
389
+ const isComponentInstance2 = current.hasAttribute("data-elementor-id");
390
+ if (isComponentInstance2) {
391
+ selectors.unshift(`[data-id="${dataId}"]`);
392
+ }
393
+ current = current.parentElement?.closest("[data-id]") ?? null;
394
+ }
395
+ if (selectors.length === 0) {
396
+ const closestElement = element.closest("[data-id]");
397
+ if (closestElement?.dataset?.id) {
398
+ return `[data-id="${closestElement.dataset.id}"]`;
399
+ }
400
+ }
401
+ return selectors.join(" ");
402
+ }
374
403
 
375
404
  // src/hooks/use-navigate-back.ts
376
405
  function useNavigateBack() {
@@ -1790,7 +1819,7 @@ function createComponentView(options) {
1790
1819
  if (!isAllowedToSwitchDocument) {
1791
1820
  options.showLockedByModal?.(lockedBy || "");
1792
1821
  } else {
1793
- switchToComponent(this.getComponentId(), this.model.get("id"));
1822
+ switchToComponent(this.getComponentId(), this.model.get("id"), this.el);
1794
1823
  }
1795
1824
  }
1796
1825
  editComponent({ trigger, location, secondaryLocation }) {