easy-email-extensions 3.0.12 → 3.0.13

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.
@@ -4,4 +4,4 @@ export interface InlineTextProps {
4
4
  children?: React.ReactNode;
5
5
  onChange: (content: string) => void;
6
6
  }
7
- export declare function InlineText({ idx, onChange, children }: InlineTextProps): JSX.Element | null;
7
+ export declare function InlineText({ idx, onChange, children }: InlineTextProps): JSX.Element;
@@ -1,3 +1,2 @@
1
- import { EnhancerProps } from '../enhancer';
2
1
  import { InlineTextProps } from '../InlineTextField';
3
- export declare const RichTextField: (props: Omit<InlineTextProps, 'onChange' | 'mutators'> & EnhancerProps<string>) => JSX.Element | null;
2
+ export declare const RichTextField: (props: Omit<InlineTextProps, 'onChange' | 'mutators'>) => JSX.Element | null;
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, { useCallback, useState, useRef, useEffect, useMemo, Children, isValidElement, cloneElement, createContext, useContext, Component, memo, forwardRef, useLayoutEffect, createRef, useImperativeHandle, PureComponent, useReducer, createElement, Suspense } from "react";
58
- import { IconFont, Stack as Stack$6, TextStyle, getBlockNodeByIdx, useBlock, getEditNode, getShadowRoot, FIXED_CONTAINER_ID, getEditContent, getEditorRoot, useEditorProps, useEditorContext, useFocusIdx, scrollBlockEleIntoView, useHoverIdx, DATA_ATTRIBUTE_DROP_CONTAINER, BlockAvatarWrapper, useActiveTab, ActiveTabKeys } from "easy-email-editor";
58
+ import { IconFont, Stack as Stack$6, TextStyle, getBlockNodeByIdx, useBlock, getEditNode, getEditContent, useEditorProps, getShadowRoot, FIXED_CONTAINER_ID, useEditorContext, useFocusIdx, scrollBlockEleIntoView, useHoverIdx, DATA_ATTRIBUTE_DROP_CONTAINER, BlockAvatarWrapper, getEditorRoot, useActiveTab, ActiveTabKeys } from "easy-email-editor";
59
59
  import { BasicType, ImageManager, getIndexByIdx, getSiblingIdx, BlockManager, getPageIdx, getChildIdx, createBlockDataByType, getParentByIdx, getValueByIdx, MjmlToJson, JsonToMjml, getParentIdx, getNodeTypeFromClassName } from "easy-email-core";
60
60
  import { ReactSortable } from "react-sortablejs";
61
61
  import { useField, Field, useForm as useForm$1, Form as Form$3, version as version$2, useFormState } from "react-final-form";
@@ -38655,7 +38655,6 @@ function InlineText({ idx, onChange, children }) {
38655
38655
  const {
38656
38656
  mutators: { setFieldTouched }
38657
38657
  } = useForm$1();
38658
- const [isFocus, setIsFocus] = useState(false);
38659
38658
  const [textContainer, setTextContainer] = useState(null);
38660
38659
  useField(idx);
38661
38660
  const { focusBlock: focusBlock2 } = useBlock();
@@ -38668,79 +38667,32 @@ function InlineText({ idx, onChange, children }) {
38668
38667
  promiseObj.cancel();
38669
38668
  };
38670
38669
  }, [idx, focusBlock2]);
38671
- const onTextChange = useCallback((text) => {
38672
- if ((focusBlock2 == null ? void 0 : focusBlock2.data.value.content) !== text) {
38673
- onChange(text);
38674
- }
38675
- }, [focusBlock2 == null ? void 0 : focusBlock2.data.value.content, onChange]);
38676
38670
  useEffect(() => {
38677
38671
  if (!textContainer)
38678
38672
  return;
38679
38673
  const container2 = getEditNode(textContainer);
38680
38674
  if (container2) {
38681
38675
  container2.focus();
38682
- let focusTarget = null;
38683
- const root2 = getShadowRoot();
38684
- const onClick = (ev) => {
38685
- ev.stopPropagation();
38686
- focusTarget = ev.target;
38687
- const fixedContainer = document.getElementById(FIXED_CONTAINER_ID);
38688
- if (textContainer == null ? void 0 : textContainer.contains(focusTarget))
38689
- return;
38690
- if (fixedContainer && fixedContainer.contains(focusTarget))
38691
- return;
38692
- if (fixedContainer == null ? void 0 : fixedContainer.contains(document.activeElement))
38693
- return;
38694
- onTextChange(getEditContent(textContainer));
38695
- };
38696
38676
  const onPaste = (e) => {
38697
38677
  var _a;
38698
38678
  e.preventDefault();
38699
38679
  const text = ((_a = e.clipboardData) == null ? void 0 : _a.getData("text/plain")) || "";
38700
38680
  document.execCommand("insertHTML", false, text);
38701
- };
38702
- const stopDrag = (e) => {
38703
- e.preventDefault();
38704
- e.stopPropagation();
38681
+ setFieldTouched(idx, true);
38682
+ onChange(getEditContent(textContainer));
38705
38683
  };
38706
38684
  const onInput = () => {
38707
38685
  setFieldTouched(idx, true);
38686
+ onChange(getEditContent(textContainer));
38708
38687
  };
38709
38688
  container2.addEventListener("paste", onPaste, true);
38710
- container2.addEventListener("dragstart", stopDrag);
38711
38689
  container2.addEventListener("input", onInput);
38712
- document.addEventListener("mousedown", onClick);
38713
- root2.addEventListener("mousedown", onClick);
38714
38690
  return () => {
38715
38691
  container2.removeEventListener("paste", onPaste, true);
38716
- container2.removeEventListener("dragstart", stopDrag);
38717
38692
  container2.removeEventListener("input", onInput);
38718
- document.removeEventListener("mousedown", onClick);
38719
- root2.removeEventListener("mousedown", onClick);
38720
38693
  };
38721
38694
  }
38722
- }, [idx, onTextChange, setFieldTouched, textContainer]);
38723
- useEffect(() => {
38724
- const onFocus3 = (ev) => {
38725
- ev.stopPropagation();
38726
- if (document.activeElement === getEditorRoot()) {
38727
- setIsFocus(true);
38728
- } else {
38729
- setIsFocus(false);
38730
- }
38731
- };
38732
- const root2 = getShadowRoot();
38733
- root2.addEventListener("click", onFocus3);
38734
- root2.addEventListener("focusin", onFocus3);
38735
- window.addEventListener("focusin", onFocus3);
38736
- return () => {
38737
- root2.addEventListener("click", onFocus3);
38738
- root2.removeEventListener("focusin", onFocus3);
38739
- window.removeEventListener("focusin", onFocus3);
38740
- };
38741
- }, []);
38742
- if (!isFocus)
38743
- return null;
38695
+ }, [idx, onChange, setFieldTouched, textContainer]);
38744
38696
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, children);
38745
38697
  }
38746
38698
  function AutoComplete(props) {
@@ -39304,20 +39256,28 @@ function RichTextToolBar() {
39304
39256
  }
39305
39257
  }))), blockNode));
39306
39258
  }
39307
- const TEXT_BAR_LOCATION_KEY = "TEXT_BAR_LOCATION_KEY";
39308
- const RichTextFieldItem = (props) => {
39309
- useLocalStorage$1(TEXT_BAR_LOCATION_KEY, { left: 0, top: 0 });
39310
- return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(RichTextToolBar, null), /* @__PURE__ */ React__default.createElement(InlineTextField, __spreadValues({}, props)));
39311
- };
39312
39259
  const RichTextField = (props) => {
39313
39260
  const { focusBlock: focusBlock2 } = useBlock();
39314
39261
  const { focusIdx: focusIdx2 } = useFocusIdx();
39315
39262
  if ((focusBlock2 == null ? void 0 : focusBlock2.type) !== BasicType.TEXT)
39316
39263
  return null;
39317
- return /* @__PURE__ */ React__default.createElement(RichTextFieldItem, __spreadValues({
39318
- key: focusIdx2
39319
- }, props));
39264
+ const name = `${focusIdx2}.data.value.content`;
39265
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(RichTextToolBar, null), /* @__PURE__ */ React__default.createElement(Field, {
39266
+ name,
39267
+ parse: (v) => v
39268
+ }, ({ input }) => /* @__PURE__ */ React__default.createElement(FieldWrapper, __spreadProps(__spreadValues({}, props), {
39269
+ input
39270
+ }))));
39320
39271
  };
39272
+ function FieldWrapper(props) {
39273
+ const _a = props, { input } = _a, rest = __objRest(_a, ["input"]);
39274
+ const debounceCallbackChange = useCallback(lodash.exports.debounce((val) => {
39275
+ input.onChange(val);
39276
+ }, 500), [input]);
39277
+ return /* @__PURE__ */ React__default.createElement(InlineText, __spreadProps(__spreadValues({}, rest), {
39278
+ onChange: debounceCallbackChange
39279
+ }));
39280
+ }
39321
39281
  const TextField = enhancer(Input, (value) => value);
39322
39282
  const SearchField = enhancer(Input$5.Search, (val) => val);
39323
39283
  const TextAreaField = enhancer(Input$5.TextArea, (val) => val);
@@ -41748,10 +41708,7 @@ function AttributePanel() {
41748
41708
  }, "No matching components")), /* @__PURE__ */ React__default.createElement("div", {
41749
41709
  style: { position: "absolute" }
41750
41710
  }, /* @__PURE__ */ React__default.createElement(RichTextField, {
41751
- idx: focusIdx2,
41752
- name: `${focusIdx2}.data.value.content`,
41753
- label: "",
41754
- labelHidden: true
41711
+ idx: focusIdx2
41755
41712
  })), shadowRoot && ReactDOM.createPortal(/* @__PURE__ */ React__default.createElement("style", null, `
41756
41713
  .email-block [contentEditable="true"],
41757
41714
  .email-block [contentEditable="true"] * {