@ivanholiak/easy-email-extensions 4.16.29 → 4.16.30

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/lib/index2.js CHANGED
@@ -36009,19 +36009,36 @@ function InlineText({ idx, onChange, children }) {
36009
36009
  }
36010
36010
  }
36011
36011
  };
36012
+ const findEditableEl = (el) => {
36013
+ var _a2;
36014
+ if (!el)
36015
+ return null;
36016
+ if (el.isContentEditable)
36017
+ return el;
36018
+ return (_a2 = el.closest) == null ? void 0 : _a2.call(el, "[contenteditable]");
36019
+ };
36012
36020
  const onDrop = (e2) => {
36013
- var _a2, _b2, _c;
36021
+ var _a2, _b2, _c, _d, _e, _f;
36014
36022
  const target2 = e2.target;
36015
- if (!target2 || !target2.getAttribute("contenteditable"))
36023
+ const editableEl = findEditableEl(target2);
36024
+ if (!editableEl)
36016
36025
  return;
36017
36026
  const mergeTagText = ((_a2 = e2.dataTransfer) == null ? void 0 : _a2.getData("text/merge-tag")) || ((_b2 = e2.dataTransfer) == null ? void 0 : _b2.getData("text/plain"));
36018
- if (mergeTagText && (mergeTagText.startsWith("{{") || mergeTagText.includes("{{"))) {
36027
+ if (mergeTagText && mergeTagText.includes("{{")) {
36019
36028
  e2.preventDefault();
36020
36029
  e2.stopPropagation();
36021
- const contentEditableType = target2.getAttribute(DATA_CONTENT_EDITABLE_TYPE);
36030
+ const range = (_c = document.caretRangeFromPoint) == null ? void 0 : _c.call(document, e2.clientX, e2.clientY);
36031
+ if (range) {
36032
+ const sel = (_e = (_d = shadowRoot.getSelection) == null ? void 0 : _d.call(shadowRoot)) != null ? _e : window.getSelection();
36033
+ if (sel) {
36034
+ sel.removeAllRanges();
36035
+ sel.addRange(range);
36036
+ }
36037
+ }
36038
+ const contentEditableType = editableEl.getAttribute(DATA_CONTENT_EDITABLE_TYPE);
36022
36039
  let insertText = mergeTagText;
36023
36040
  if (enabledMergeTagsBadge && mergeTagGenerate) {
36024
- const match = mergeTagText.match(/{{([^}]+)}}/);
36041
+ const match = mergeTagText.match(/\{\{([^}]+)\}\}/);
36025
36042
  if (match && match[1]) {
36026
36043
  const mergeTagKey = match[1].trim();
36027
36044
  const generatedTag = mergeTagGenerate(mergeTagKey);
@@ -36032,20 +36049,19 @@ function InlineText({ idx, onChange, children }) {
36032
36049
  }
36033
36050
  document.execCommand("insertHTML", false, insertText);
36034
36051
  if (contentEditableType === ContentEditableType.RichText) {
36035
- onChange(target2.innerHTML || "");
36052
+ onChange(editableEl.innerHTML || "");
36036
36053
  } else if (contentEditableType === ContentEditableType.Text) {
36037
- onChange(((_c = target2.textContent) == null ? void 0 : _c.trim()) || "");
36054
+ onChange(((_f = editableEl.textContent) == null ? void 0 : _f.trim()) || "");
36038
36055
  }
36039
36056
  }
36040
36057
  };
36041
36058
  const onDragOver = (e2) => {
36042
36059
  var _a2;
36043
36060
  const target2 = e2.target;
36044
- if (target2 && target2.getAttribute("contenteditable")) {
36045
- if ((_a2 = e2.dataTransfer) == null ? void 0 : _a2.types.includes("text/merge-tag")) {
36046
- e2.preventDefault();
36047
- e2.dataTransfer.dropEffect = "copy";
36048
- }
36061
+ const editableEl = findEditableEl(target2);
36062
+ if (editableEl && ((_a2 = e2.dataTransfer) == null ? void 0 : _a2.types.includes("text/merge-tag"))) {
36063
+ e2.preventDefault();
36064
+ e2.dataTransfer.dropEffect = "copy";
36049
36065
  }
36050
36066
  };
36051
36067
  shadowRoot.addEventListener("paste", onPaste, true);