easy-email-extensions 4.0.0 → 4.1.0
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 +78 -27
- package/lib/index2.js.map +1 -1
- package/package.json +2 -2
package/lib/index2.js
CHANGED
@@ -55,7 +55,7 @@ var __async = (__this, __arguments, generator) => {
|
|
55
55
|
};
|
56
56
|
import * as React from "react";
|
57
57
|
import React__default, { Children, isValidElement, cloneElement, createContext, useContext, Component, useMemo, memo, forwardRef, useEffect, useRef, useLayoutEffect, useState, createRef, useImperativeHandle, PureComponent, useCallback, useReducer, Fragment, createElement, Suspense } from "react";
|
58
|
-
import { IconFont, useEditorProps, Stack as Stack$6, getShadowRoot, TextStyle, useEditorContext, useBlock, useFocusIdx, useFocusBlockLayout,
|
58
|
+
import { IconFont, useEditorProps, Stack as Stack$6, getShadowRoot, DATA_CONTENT_EDITABLE_TYPE, ContentEditableType, TextStyle, useEditorContext, useBlock, useFocusIdx, useFocusBlockLayout, MergeTagBadge, FIXED_CONTAINER_ID, getPluginElement, RICH_TEXT_BAR_ID, CONTENT_EDITABLE_CLASS_NAME, getEditorRoot, DATA_CONTENT_EDITABLE_IDX, scrollBlockEleIntoView, useHoverIdx, useDataTransfer, useRefState, getBlockNodeByChildEle, getDirectionPosition, DATA_ATTRIBUTE_DROP_CONTAINER, BlockAvatarWrapper, isTextBlock, getBlockNodeByIdx, useLazyState, useActiveTab, ActiveTabKeys } from "easy-email-editor";
|
59
59
|
import { BasicType, ImageManager, EMAIL_BLOCK_CLASS_NAME, BlockManager, createBlockDataByType, AdvancedType, Operator, OperatorSymbol, isAdvancedBlock, getParentByIdx, getParentIdx, getIndexByIdx, getSiblingIdx, getNodeIdxFromClassName, getNodeIdxClassName, getPageIdx, getChildIdx, MjmlToJson, JsonToMjml, getNodeTypeFromClassName } from "easy-email-core";
|
60
60
|
import ReactDOM, { findDOMNode, render as render$1, unmountComponentAtNode, createPortal } from "react-dom";
|
61
61
|
import { useField, Field, useForm as useForm$1, Form as Form$3, version as version$2, useFormState } from "react-final-form";
|
@@ -40216,17 +40216,28 @@ function InlineText({ idx, onChange, children }) {
|
|
40216
40216
|
useEffect(() => {
|
40217
40217
|
const shadowRoot = getShadowRoot();
|
40218
40218
|
const onPaste = (e) => {
|
40219
|
-
var _a;
|
40219
|
+
var _a, _b;
|
40220
40220
|
if (!(e.target instanceof Element) || !e.target.getAttribute("contenteditable"))
|
40221
40221
|
return;
|
40222
40222
|
e.preventDefault();
|
40223
40223
|
const text = ((_a = e.clipboardData) == null ? void 0 : _a.getData("text/plain")) || "";
|
40224
40224
|
document.execCommand("insertHTML", false, text);
|
40225
|
-
|
40225
|
+
const contentEditableType = e.target.getAttribute(DATA_CONTENT_EDITABLE_TYPE);
|
40226
|
+
if (contentEditableType === ContentEditableType.RichText) {
|
40227
|
+
onChange(e.target.innerHTML || "");
|
40228
|
+
} else if (contentEditableType === ContentEditableType.Text) {
|
40229
|
+
onChange(((_b = e.target.textContent) == null ? void 0 : _b.trim()) || "");
|
40230
|
+
}
|
40226
40231
|
};
|
40227
40232
|
const onInput = (e) => {
|
40233
|
+
var _a;
|
40228
40234
|
if (e.target instanceof Element && e.target.getAttribute("contenteditable")) {
|
40229
|
-
|
40235
|
+
const contentEditableType = e.target.getAttribute(DATA_CONTENT_EDITABLE_TYPE);
|
40236
|
+
if (contentEditableType === ContentEditableType.RichText) {
|
40237
|
+
onChange(e.target.innerHTML || "");
|
40238
|
+
} else if (contentEditableType === ContentEditableType.Text) {
|
40239
|
+
onChange(((_a = e.target.textContent) == null ? void 0 : _a.trim()) || "");
|
40240
|
+
}
|
40230
40241
|
}
|
40231
40242
|
};
|
40232
40243
|
shadowRoot.addEventListener("paste", onPaste, true);
|
@@ -43633,17 +43644,13 @@ function Tools(props) {
|
|
43633
43644
|
const { mergeTags: mergeTags2, enabledMergeTagsBadge } = useEditorProps();
|
43634
43645
|
const { focusBlockNode } = useFocusBlockLayout();
|
43635
43646
|
const { selectionRange, restoreRange, setRangeByElement } = useSelectionRange();
|
43636
|
-
const execCommand = (cmd, val) => {
|
43637
|
-
|
43638
|
-
if (!container2) {
|
43639
|
-
console.error("No container");
|
43640
|
-
return;
|
43641
|
-
}
|
43647
|
+
const execCommand = useCallback((cmd, val) => {
|
43648
|
+
var _a;
|
43642
43649
|
if (!selectionRange) {
|
43643
43650
|
console.error("No selectionRange");
|
43644
43651
|
return;
|
43645
43652
|
}
|
43646
|
-
if (!(
|
43653
|
+
if (!(focusBlockNode == null ? void 0 : focusBlockNode.contains(selectionRange == null ? void 0 : selectionRange.commonAncestorContainer))) {
|
43647
43654
|
console.error("Not commonAncestorContainer");
|
43648
43655
|
return;
|
43649
43656
|
}
|
@@ -43679,19 +43686,15 @@ function Tools(props) {
|
|
43679
43686
|
} else {
|
43680
43687
|
document.execCommand(cmd, false, val);
|
43681
43688
|
}
|
43682
|
-
const html =
|
43689
|
+
const html = ((_a = getShadowRoot().activeElement) == null ? void 0 : _a.innerHTML) || "";
|
43683
43690
|
props.onChange(html);
|
43684
|
-
};
|
43691
|
+
}, [enabledMergeTagsBadge, focusBlockNode, props, restoreRange, selectionRange, setRangeByElement]);
|
43685
43692
|
const execCommandWithRange = useCallback((cmd, val) => {
|
43686
|
-
|
43687
|
-
if (!container2) {
|
43688
|
-
console.error("No container");
|
43689
|
-
return;
|
43690
|
-
}
|
43693
|
+
var _a;
|
43691
43694
|
document.execCommand(cmd, false, val);
|
43692
|
-
const html =
|
43695
|
+
const html = ((_a = getShadowRoot().activeElement) == null ? void 0 : _a.innerHTML) || "";
|
43693
43696
|
props.onChange(html);
|
43694
|
-
}, [
|
43697
|
+
}, [props.onChange]);
|
43695
43698
|
const getPopoverMountNode = () => document.getElementById(FIXED_CONTAINER_ID);
|
43696
43699
|
return /* @__PURE__ */ React__default.createElement("div", {
|
43697
43700
|
id: "Tools",
|
@@ -43822,6 +43825,7 @@ function RichTextToolBar(props) {
|
|
43822
43825
|
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, createPortal(/* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("style", {
|
43823
43826
|
dangerouslySetInnerHTML: { __html: styleText }
|
43824
43827
|
}), /* @__PURE__ */ React__default.createElement("div", {
|
43828
|
+
id: RICH_TEXT_BAR_ID,
|
43825
43829
|
style: {
|
43826
43830
|
transform: "translate(0,0)",
|
43827
43831
|
padding: "4px 8px",
|
@@ -43846,20 +43850,67 @@ function RichTextToolBar(props) {
|
|
43846
43850
|
}))), root2));
|
43847
43851
|
}
|
43848
43852
|
const RichTextField = (props) => {
|
43849
|
-
const
|
43850
|
-
const
|
43851
|
-
|
43853
|
+
const [contentEditableName, setContentEditableName] = useState("");
|
43854
|
+
const [contentEditableType, setContentEditableType] = useState(CONTENT_EDITABLE_CLASS_NAME);
|
43855
|
+
useEffect(() => {
|
43856
|
+
const onClick = (e) => {
|
43857
|
+
var _a;
|
43858
|
+
if ((_a = getEditorRoot()) == null ? void 0 : _a.contains(e.target)) {
|
43859
|
+
return;
|
43860
|
+
}
|
43861
|
+
const fixedContainer = document.getElementById(FIXED_CONTAINER_ID);
|
43862
|
+
if (fixedContainer == null ? void 0 : fixedContainer.contains(e.target)) {
|
43863
|
+
return;
|
43864
|
+
}
|
43865
|
+
setContentEditableName("");
|
43866
|
+
};
|
43867
|
+
window.addEventListener("click", onClick);
|
43868
|
+
return () => {
|
43869
|
+
window.removeEventListener("click", onClick);
|
43870
|
+
};
|
43871
|
+
}, []);
|
43872
|
+
useEffect(() => {
|
43873
|
+
const root2 = getShadowRoot();
|
43874
|
+
if (!root2)
|
43875
|
+
return;
|
43876
|
+
const onClick = (e) => {
|
43877
|
+
const target2 = e.target;
|
43878
|
+
const fixedContainer = document.getElementById(FIXED_CONTAINER_ID);
|
43879
|
+
const richTextBar = root2.getElementById(RICH_TEXT_BAR_ID);
|
43880
|
+
if ((fixedContainer == null ? void 0 : fixedContainer.contains(target2)) || (richTextBar == null ? void 0 : richTextBar.contains(target2))) {
|
43881
|
+
return;
|
43882
|
+
}
|
43883
|
+
const activeElement = getShadowRoot().activeElement;
|
43884
|
+
if (!activeElement) {
|
43885
|
+
setContentEditableName("");
|
43886
|
+
} else {
|
43887
|
+
const idxName = activeElement.getAttribute(DATA_CONTENT_EDITABLE_IDX);
|
43888
|
+
const type = activeElement.getAttribute(DATA_CONTENT_EDITABLE_TYPE);
|
43889
|
+
setContentEditableType(type);
|
43890
|
+
if (idxName) {
|
43891
|
+
setContentEditableName(idxName);
|
43892
|
+
} else {
|
43893
|
+
setContentEditableName("");
|
43894
|
+
}
|
43895
|
+
}
|
43896
|
+
};
|
43897
|
+
root2.addEventListener("click", onClick);
|
43898
|
+
return () => {
|
43899
|
+
root2.removeEventListener("click", onClick);
|
43900
|
+
};
|
43901
|
+
}, []);
|
43902
|
+
if (!contentEditableName)
|
43852
43903
|
return null;
|
43853
|
-
const name = `${focusIdx2}.data.value.content`;
|
43854
43904
|
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Field, {
|
43855
|
-
name,
|
43905
|
+
name: contentEditableName,
|
43856
43906
|
parse: (v) => v
|
43857
43907
|
}, ({ input }) => /* @__PURE__ */ React__default.createElement(FieldWrapper, __spreadProps(__spreadValues({}, props), {
|
43908
|
+
contentEditableType,
|
43858
43909
|
input
|
43859
43910
|
}))));
|
43860
43911
|
};
|
43861
43912
|
function FieldWrapper(props) {
|
43862
|
-
const _a = props, { input } = _a, rest = __objRest(_a, ["input"]);
|
43913
|
+
const _a = props, { input, contentEditableType } = _a, rest = __objRest(_a, ["input", "contentEditableType"]);
|
43863
43914
|
const { mergeTagGenerate, enabledMergeTagsBadge } = useEditorProps();
|
43864
43915
|
const debounceCallbackChange = useCallback(lodash.exports.debounce((val) => {
|
43865
43916
|
if (enabledMergeTagsBadge) {
|
@@ -43869,7 +43920,7 @@ function FieldWrapper(props) {
|
|
43869
43920
|
}
|
43870
43921
|
input.onBlur();
|
43871
43922
|
}, 200), [input]);
|
43872
|
-
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(RichTextToolBar, {
|
43923
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, contentEditableType === ContentEditableType.RichText && /* @__PURE__ */ React__default.createElement(RichTextToolBar, {
|
43873
43924
|
onChange: debounceCallbackChange
|
43874
43925
|
}), /* @__PURE__ */ React__default.createElement(InlineText, __spreadProps(__spreadValues({}, rest), {
|
43875
43926
|
onChange: debounceCallbackChange
|