@elementor/editor-elements 4.3.0-999 → 4.3.0-beta2

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
@@ -283,7 +283,7 @@ function toElementModel({ model }) {
283
283
  editorSettings: model.get("editor_settings") ?? {}
284
284
  };
285
285
  }
286
- function useElementChildren(elementId, childrenTypes) {
286
+ function useElementChildren(elementId, childrenTypes, { includeSelfAsParent = false } = {}) {
287
287
  return useListenTo(
288
288
  [
289
289
  v1ReadyEvent(),
@@ -299,7 +299,7 @@ function useElementChildren(elementId, childrenTypes) {
299
299
  return {};
300
300
  }
301
301
  const elementChildren = Object.entries(childrenTypes).reduce((acc, [parentType, childType]) => {
302
- const parent = findChildRecursive(model, (m) => m.get("elType") === parentType);
302
+ const parent = includeSelfAsParent && model.get("elType") === parentType ? { model } : findChildRecursive(model, (m) => m.get("elType") === parentType);
303
303
  if (!parent) {
304
304
  acc[childType] = [];
305
305
  return acc;
@@ -687,6 +687,26 @@ var duplicateElements = ({
687
687
  return undoableDuplicate({ elementIds });
688
688
  };
689
689
 
690
+ // src/sync/get-preview-element-dom.ts
691
+ function getPreviewElementDOM(id) {
692
+ try {
693
+ const fromContainer = getContainer(id)?.view?.el;
694
+ if (fromContainer) {
695
+ return fromContainer;
696
+ }
697
+ return queryPreviewDOMByElementId(id);
698
+ } catch {
699
+ return null;
700
+ }
701
+ }
702
+ function queryPreviewDOMByElementId(id) {
703
+ const previewDocument = window.elementor?.getPreviewContainer?.()?.view?.el?.ownerDocument;
704
+ if (!previewDocument) {
705
+ return null;
706
+ }
707
+ return previewDocument.querySelector(`[data-id="${id}"]`);
708
+ }
709
+
690
710
  // src/sync/get-current-document-container.ts
691
711
  function getCurrentDocumentContainer() {
692
712
  const extendedWindow = window;
@@ -1208,22 +1228,7 @@ function checkForInlineLink(elementId, resolvedValue) {
1208
1228
  return element.querySelector(ANCHOR_SELECTOR) !== null;
1209
1229
  }
1210
1230
  function getElementDOM(id) {
1211
- try {
1212
- const fromContainer = getContainer(id)?.view?.el;
1213
- if (fromContainer) {
1214
- return fromContainer;
1215
- }
1216
- return queryPreviewDOMByElementId(id);
1217
- } catch {
1218
- return null;
1219
- }
1220
- }
1221
- function queryPreviewDOMByElementId(id) {
1222
- const previewDocument = window.elementor?.getPreviewContainer?.()?.view?.el?.ownerDocument;
1223
- if (!previewDocument) {
1224
- return null;
1225
- }
1226
- return previewDocument.querySelector(`[data-id="${id}"]`);
1231
+ return getPreviewElementDOM(id);
1227
1232
  }
1228
1233
  function isElementorElement(element) {
1229
1234
  return element.hasAttribute("data-id");
@@ -1286,6 +1291,9 @@ function isStyleEmpty(style) {
1286
1291
  }
1287
1292
  function clearRemovedClasses(container, { oldIds, newIds }) {
1288
1293
  const removedIds = oldIds.filter((id) => !newIds.includes(id));
1294
+ if (!removedIds.length) {
1295
+ return;
1296
+ }
1289
1297
  const classesProps = structuredClone(getClassesProps(container));
1290
1298
  classesProps.forEach(([, prop]) => {
1291
1299
  prop.value = prop.value.filter((value) => !removedIds.includes(value));
@@ -1395,6 +1403,48 @@ function getElementInteractions(elementId) {
1395
1403
  return interactions;
1396
1404
  }
1397
1405
 
1406
+ // src/utils/get-default-style-tag-from-preview.ts
1407
+ var DEFAULT_STYLE_CLASS_PREFIX = "e-default-";
1408
+ function parseDefaultStyleTagFromClassList(classList) {
1409
+ for (const className of classList) {
1410
+ if (className.startsWith(DEFAULT_STYLE_CLASS_PREFIX)) {
1411
+ return className.slice(DEFAULT_STYLE_CLASS_PREFIX.length);
1412
+ }
1413
+ }
1414
+ return null;
1415
+ }
1416
+ function getDefaultStyleTagFromPreviewElement(elementId) {
1417
+ const renderRoot = getAtomicElementRenderRoot(elementId);
1418
+ if (!renderRoot) {
1419
+ return null;
1420
+ }
1421
+ return parseDefaultStyleTagFromClassList(renderRoot.classList);
1422
+ }
1423
+ function getAtomicElementRenderRoot(elementId) {
1424
+ const view = getContainerView(elementId);
1425
+ if (view?.getDomElement) {
1426
+ const domElement = view.getDomElement().get?.(0);
1427
+ if (domElement) {
1428
+ return domElement;
1429
+ }
1430
+ }
1431
+ const wrapper = view?.el ?? getPreviewElementDOM(elementId);
1432
+ if (!wrapper) {
1433
+ return null;
1434
+ }
1435
+ if (wrapper.hasAttribute("data-id")) {
1436
+ return wrapper;
1437
+ }
1438
+ const firstChild = wrapper.firstElementChild;
1439
+ if (firstChild instanceof HTMLElement) {
1440
+ return firstChild;
1441
+ }
1442
+ return wrapper;
1443
+ }
1444
+ function getContainerView(elementId) {
1445
+ return getContainer(elementId)?.view ?? null;
1446
+ }
1447
+
1398
1448
  // src/sync/update-element-interactions.ts
1399
1449
  import { __privateRunCommandSync as runCommandSync8 } from "@elementor/editor-v1-adapters";
1400
1450
  var updateElementInteractions = ({
@@ -1415,6 +1465,7 @@ var playElementInteractions = (elementId, interactionId) => {
1415
1465
  );
1416
1466
  };
1417
1467
  export {
1468
+ DEFAULT_STYLE_CLASS_PREFIX,
1418
1469
  ELEMENT_STYLE_CHANGE_EVENT,
1419
1470
  addModelToParent,
1420
1471
  bindSettingsReconcile,
@@ -1436,6 +1487,7 @@ export {
1436
1487
  getContainer,
1437
1488
  getCurrentDocumentContainer,
1438
1489
  getCurrentDocumentId,
1490
+ getDefaultStyleTagFromPreviewElement,
1439
1491
  getElementChildren as getElementChildrenWithFallback,
1440
1492
  getElementEditorSettings,
1441
1493
  getElementIcon,
@@ -1448,11 +1500,13 @@ export {
1448
1500
  getElementType,
1449
1501
  getElements,
1450
1502
  getLinkInLinkRestriction,
1503
+ getPreviewElementDOM,
1451
1504
  getSelectedElements,
1452
1505
  getWidgetsCache,
1453
1506
  isElementAnchored,
1454
1507
  moveElement,
1455
1508
  moveElements,
1509
+ parseDefaultStyleTagFromClassList,
1456
1510
  playElementInteractions,
1457
1511
  reconcileInitialChildren,
1458
1512
  removeElements,