easy-email-extensions 4.0.0 → 4.1.2

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.
@@ -1,6 +1,6 @@
1
1
  export declare function useFontFamily(): {
2
2
  fontList: {
3
3
  value: string;
4
- label: string;
4
+ label: JSX.Element;
5
5
  }[];
6
6
  };
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, getEditNode, MergeTagBadge, FIXED_CONTAINER_ID, getPluginElement, isTextBlock, scrollBlockEleIntoView, useHoverIdx, useDataTransfer, useRefState, getBlockNodeByChildEle, getDirectionPosition, DATA_ATTRIBUTE_DROP_CONTAINER, BlockAvatarWrapper, getBlockNodeByIdx, useLazyState, getEditorRoot, useActiveTab, ActiveTabKeys } from "easy-email-editor";
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";
@@ -39793,6 +39793,21 @@ ImageManager.add(defaultImagesMap$1);
39793
39793
  function getImg$1(name) {
39794
39794
  return ImageManager.get(name);
39795
39795
  }
39796
+ const helperText = "_helperText_1m9nq_1";
39797
+ const labelHidden = "_label-hidden_1m9nq_9";
39798
+ const editTab = "_editTab_1m9nq_20";
39799
+ const inputWithUnit = "_inputWithUnit_1m9nq_27";
39800
+ const inputWithUnitSelectOption = "_inputWithUnitSelectOption_1m9nq_35";
39801
+ const colorPicker = "_colorPicker_1m9nq_40";
39802
+ var styles$3 = {
39803
+ helperText,
39804
+ "label-hidden": "_label-hidden_1m9nq_9",
39805
+ labelHidden,
39806
+ editTab,
39807
+ inputWithUnit,
39808
+ inputWithUnitSelectOption,
39809
+ colorPicker
39810
+ };
39796
39811
  function ColorPicker(props) {
39797
39812
  const { colors: presetColors, addCurrentColor } = useContext(PresetColorsContext);
39798
39813
  const [color, setColor] = useState("");
@@ -39819,12 +39834,14 @@ function ColorPicker(props) {
39819
39834
  title: props.label,
39820
39835
  trigger: "click"
39821
39836
  }, props), {
39822
- content: /* @__PURE__ */ React__default.createElement(SketchPicker, {
39837
+ content: /* @__PURE__ */ React__default.createElement("div", {
39838
+ className: styles$3.colorPicker
39839
+ }, /* @__PURE__ */ React__default.createElement(SketchPicker, {
39823
39840
  presetColors,
39824
39841
  color,
39825
39842
  disableAlpha: true,
39826
39843
  onChangeComplete
39827
- })
39844
+ }))
39828
39845
  }), children || /* @__PURE__ */ React__default.createElement("div", {
39829
39846
  style: {
39830
39847
  display: "inline-block",
@@ -39888,19 +39905,6 @@ function RadioGroup(props) {
39888
39905
  value: item2.value
39889
39906
  }, item2.label))));
39890
39907
  }
39891
- const helperText = "_helperText_k05ys_1";
39892
- const labelHidden = "_label-hidden_k05ys_9";
39893
- const editTab = "_editTab_k05ys_20";
39894
- const inputWithUnit = "_inputWithUnit_k05ys_27";
39895
- const inputWithUnitSelectOption = "_inputWithUnitSelectOption_k05ys_35";
39896
- var styles$3 = {
39897
- helperText,
39898
- "label-hidden": "_label-hidden_k05ys_9",
39899
- labelHidden,
39900
- editTab,
39901
- inputWithUnit,
39902
- inputWithUnitSelectOption
39903
- };
39904
39908
  let primaryId = 0;
39905
39909
  const parse = (v) => v;
39906
39910
  function enhancer(Component2, changeAdapter) {
@@ -40216,17 +40220,28 @@ function InlineText({ idx, onChange, children }) {
40216
40220
  useEffect(() => {
40217
40221
  const shadowRoot = getShadowRoot();
40218
40222
  const onPaste = (e) => {
40219
- var _a;
40223
+ var _a, _b;
40220
40224
  if (!(e.target instanceof Element) || !e.target.getAttribute("contenteditable"))
40221
40225
  return;
40222
40226
  e.preventDefault();
40223
40227
  const text = ((_a = e.clipboardData) == null ? void 0 : _a.getData("text/plain")) || "";
40224
40228
  document.execCommand("insertHTML", false, text);
40225
- onChange(e.target.innerHTML || "");
40229
+ const contentEditableType = e.target.getAttribute(DATA_CONTENT_EDITABLE_TYPE);
40230
+ if (contentEditableType === ContentEditableType.RichText) {
40231
+ onChange(e.target.innerHTML || "");
40232
+ } else if (contentEditableType === ContentEditableType.Text) {
40233
+ onChange(((_b = e.target.textContent) == null ? void 0 : _b.trim()) || "");
40234
+ }
40226
40235
  };
40227
40236
  const onInput = (e) => {
40237
+ var _a;
40228
40238
  if (e.target instanceof Element && e.target.getAttribute("contenteditable")) {
40229
- onChange(e.target.innerHTML || "");
40239
+ const contentEditableType = e.target.getAttribute(DATA_CONTENT_EDITABLE_TYPE);
40240
+ if (contentEditableType === ContentEditableType.RichText) {
40241
+ onChange(e.target.innerHTML || "");
40242
+ } else if (contentEditableType === ContentEditableType.Text) {
40243
+ onChange(((_a = e.target.textContent) == null ? void 0 : _a.trim()) || "");
40244
+ }
40230
40245
  }
40231
40246
  };
40232
40247
  shadowRoot.addEventListener("paste", onPaste, true);
@@ -40385,7 +40400,9 @@ function useFontFamily() {
40385
40400
  const options2 = addFonts.map((item2) => ({ value: item2.name, label: item2.name }));
40386
40401
  fonts.unshift(...options2);
40387
40402
  }
40388
- return fonts;
40403
+ return fonts.map((item2) => ({ value: item2.value, label: /* @__PURE__ */ React__default.createElement("span", {
40404
+ style: { fontFamily: item2.value }
40405
+ }, item2.label) }));
40389
40406
  }, [addFonts, defaultFontList]);
40390
40407
  return {
40391
40408
  fontList: fontList2
@@ -43633,17 +43650,13 @@ function Tools(props) {
43633
43650
  const { mergeTags: mergeTags2, enabledMergeTagsBadge } = useEditorProps();
43634
43651
  const { focusBlockNode } = useFocusBlockLayout();
43635
43652
  const { selectionRange, restoreRange, setRangeByElement } = useSelectionRange();
43636
- const execCommand = (cmd, val) => {
43637
- const container2 = getEditNode(focusBlockNode);
43638
- if (!container2) {
43639
- console.error("No container");
43640
- return;
43641
- }
43653
+ const execCommand = useCallback((cmd, val) => {
43654
+ var _a;
43642
43655
  if (!selectionRange) {
43643
43656
  console.error("No selectionRange");
43644
43657
  return;
43645
43658
  }
43646
- if (!(container2 == null ? void 0 : container2.contains(selectionRange == null ? void 0 : selectionRange.commonAncestorContainer)) && container2 !== (selectionRange == null ? void 0 : selectionRange.commonAncestorContainer)) {
43659
+ if (!(focusBlockNode == null ? void 0 : focusBlockNode.contains(selectionRange == null ? void 0 : selectionRange.commonAncestorContainer))) {
43647
43660
  console.error("Not commonAncestorContainer");
43648
43661
  return;
43649
43662
  }
@@ -43679,19 +43692,15 @@ function Tools(props) {
43679
43692
  } else {
43680
43693
  document.execCommand(cmd, false, val);
43681
43694
  }
43682
- const html = container2.innerHTML;
43695
+ const html = ((_a = getShadowRoot().activeElement) == null ? void 0 : _a.innerHTML) || "";
43683
43696
  props.onChange(html);
43684
- };
43697
+ }, [enabledMergeTagsBadge, focusBlockNode, props, restoreRange, selectionRange, setRangeByElement]);
43685
43698
  const execCommandWithRange = useCallback((cmd, val) => {
43686
- const container2 = getEditNode(focusBlockNode);
43687
- if (!container2) {
43688
- console.error("No container");
43689
- return;
43690
- }
43699
+ var _a;
43691
43700
  document.execCommand(cmd, false, val);
43692
- const html = container2.innerHTML;
43701
+ const html = ((_a = getShadowRoot().activeElement) == null ? void 0 : _a.innerHTML) || "";
43693
43702
  props.onChange(html);
43694
- }, [focusBlockNode, props]);
43703
+ }, [props.onChange]);
43695
43704
  const getPopoverMountNode = () => document.getElementById(FIXED_CONTAINER_ID);
43696
43705
  return /* @__PURE__ */ React__default.createElement("div", {
43697
43706
  id: "Tools",
@@ -43822,6 +43831,7 @@ function RichTextToolBar(props) {
43822
43831
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, createPortal(/* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("style", {
43823
43832
  dangerouslySetInnerHTML: { __html: styleText }
43824
43833
  }), /* @__PURE__ */ React__default.createElement("div", {
43834
+ id: RICH_TEXT_BAR_ID,
43825
43835
  style: {
43826
43836
  transform: "translate(0,0)",
43827
43837
  padding: "4px 8px",
@@ -43846,20 +43856,67 @@ function RichTextToolBar(props) {
43846
43856
  }))), root2));
43847
43857
  }
43848
43858
  const RichTextField = (props) => {
43849
- const { focusBlock: focusBlock2 } = useBlock();
43850
- const { focusIdx: focusIdx2 } = useFocusIdx();
43851
- if (!isTextBlock(focusBlock2 == null ? void 0 : focusBlock2.type))
43859
+ const [contentEditableName, setContentEditableName] = useState("");
43860
+ const [contentEditableType, setContentEditableType] = useState(CONTENT_EDITABLE_CLASS_NAME);
43861
+ useEffect(() => {
43862
+ const onClick = (e) => {
43863
+ var _a;
43864
+ if ((_a = getEditorRoot()) == null ? void 0 : _a.contains(e.target)) {
43865
+ return;
43866
+ }
43867
+ const fixedContainer = document.getElementById(FIXED_CONTAINER_ID);
43868
+ if (fixedContainer == null ? void 0 : fixedContainer.contains(e.target)) {
43869
+ return;
43870
+ }
43871
+ setContentEditableName("");
43872
+ };
43873
+ window.addEventListener("click", onClick);
43874
+ return () => {
43875
+ window.removeEventListener("click", onClick);
43876
+ };
43877
+ }, []);
43878
+ useEffect(() => {
43879
+ const root2 = getShadowRoot();
43880
+ if (!root2)
43881
+ return;
43882
+ const onClick = (e) => {
43883
+ const target2 = e.target;
43884
+ const fixedContainer = document.getElementById(FIXED_CONTAINER_ID);
43885
+ const richTextBar = root2.getElementById(RICH_TEXT_BAR_ID);
43886
+ if ((fixedContainer == null ? void 0 : fixedContainer.contains(target2)) || (richTextBar == null ? void 0 : richTextBar.contains(target2))) {
43887
+ return;
43888
+ }
43889
+ const activeElement = getShadowRoot().activeElement;
43890
+ if (!activeElement) {
43891
+ setContentEditableName("");
43892
+ } else {
43893
+ const idxName = activeElement.getAttribute(DATA_CONTENT_EDITABLE_IDX);
43894
+ const type = activeElement.getAttribute(DATA_CONTENT_EDITABLE_TYPE);
43895
+ setContentEditableType(type);
43896
+ if (idxName) {
43897
+ setContentEditableName(idxName);
43898
+ } else {
43899
+ setContentEditableName("");
43900
+ }
43901
+ }
43902
+ };
43903
+ root2.addEventListener("click", onClick);
43904
+ return () => {
43905
+ root2.removeEventListener("click", onClick);
43906
+ };
43907
+ }, []);
43908
+ if (!contentEditableName)
43852
43909
  return null;
43853
- const name = `${focusIdx2}.data.value.content`;
43854
43910
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Field, {
43855
- name,
43911
+ name: contentEditableName,
43856
43912
  parse: (v) => v
43857
43913
  }, ({ input }) => /* @__PURE__ */ React__default.createElement(FieldWrapper, __spreadProps(__spreadValues({}, props), {
43914
+ contentEditableType,
43858
43915
  input
43859
43916
  }))));
43860
43917
  };
43861
43918
  function FieldWrapper(props) {
43862
- const _a = props, { input } = _a, rest = __objRest(_a, ["input"]);
43919
+ const _a = props, { input, contentEditableType } = _a, rest = __objRest(_a, ["input", "contentEditableType"]);
43863
43920
  const { mergeTagGenerate, enabledMergeTagsBadge } = useEditorProps();
43864
43921
  const debounceCallbackChange = useCallback(lodash.exports.debounce((val) => {
43865
43922
  if (enabledMergeTagsBadge) {
@@ -43869,7 +43926,7 @@ function FieldWrapper(props) {
43869
43926
  }
43870
43927
  input.onBlur();
43871
43928
  }, 200), [input]);
43872
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(RichTextToolBar, {
43929
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, contentEditableType === ContentEditableType.RichText && /* @__PURE__ */ React__default.createElement(RichTextToolBar, {
43873
43930
  onChange: debounceCallbackChange
43874
43931
  }), /* @__PURE__ */ React__default.createElement(InlineText, __spreadProps(__spreadValues({}, rest), {
43875
43932
  onChange: debounceCallbackChange