@ivanholiak/easy-email-extensions 4.16.23 → 4.16.24

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,4 +1,5 @@
1
1
  import React from 'react';
2
+ import './FontFamily.scss';
2
3
  export declare function FontFamily({ name }: {
3
4
  name?: string;
4
5
  }): React.JSX.Element;
package/lib/index2.js CHANGED
@@ -38394,7 +38394,7 @@ function useFontFamily() {
38394
38394
  };
38395
38395
  }
38396
38396
  var styleText$2 = ".easy-email-extensions-Tools-Popover .ee-popover-content{padding:0}.easy-email-extensions-Tools-Popover .ee-popover-content-inner *::-webkit-scrollbar{-webkit-appearance:none;width:5px}.easy-email-extensions-Tools-Popover .ee-popover-content-inner *::-webkit-scrollbar-thumb{border-radius:5px;background-color:#00000080;box-shadow:0 0 1px #ffffff80;-webkit-box-shadow:0 0 1px rgba(255,255,255,.5)}\n";
38397
- function FontFamily$1(props) {
38397
+ function FontFamily$2(props) {
38398
38398
  const { fontList: fontList2 } = useFontFamily();
38399
38399
  const { execCommand } = props;
38400
38400
  const [visible, setVisible] = React__default.useState(false);
@@ -38696,11 +38696,13 @@ function EyeIcon() {
38696
38696
  onClick: onToggleVisible
38697
38697
  });
38698
38698
  }
38699
+ var FontFamily$1 = "";
38699
38700
  function FontFamily({ name: name2 }) {
38700
38701
  const { focusIdx: focusIdx2 } = useFocusIdx();
38701
38702
  const { fontList: defaultFontList } = useEditorProps();
38702
38703
  const { pageData: pageData2 } = useEditorContext();
38703
38704
  const [searchValue, setSearchValue] = useState("");
38705
+ const loadedRef = useRef(/* @__PURE__ */ new Set());
38704
38706
  const addFonts = pageData2.data.value.fonts;
38705
38707
  const allOptions = useMemo(() => {
38706
38708
  const options2 = [];
@@ -38729,21 +38731,38 @@ function FontFamily({ name: name2 }) {
38729
38731
  }
38730
38732
  return options2;
38731
38733
  }, [addFonts, defaultFontList]);
38732
- useEffect(() => {
38734
+ const filteredOptions = useMemo(() => {
38735
+ if (!searchValue)
38736
+ return allOptions;
38733
38737
  const search = searchValue.toLowerCase();
38734
- const visible = search ? allOptions.filter((opt2) => opt2.value.toLowerCase().includes(search)) : allOptions;
38735
- const fontsToLoad = visible.slice(0, 15).map((opt2) => opt2.value).filter((f2) => GOOGLE_FONTS.includes(f2));
38736
- if (fontsToLoad.length > 0) {
38737
- loadGoogleFontsPreview(fontsToLoad);
38738
- }
38738
+ return allOptions.filter((opt2) => opt2.value.toLowerCase().includes(search));
38739
38739
  }, [searchValue, allOptions]);
38740
+ const loadFontsBatch = useCallback((fonts) => {
38741
+ const toLoad = fonts.map((f2) => f2.value).filter((f2) => GOOGLE_FONTS.includes(f2) && !loadedRef.current.has(f2));
38742
+ if (toLoad.length > 0) {
38743
+ toLoad.forEach((f2) => loadedRef.current.add(f2));
38744
+ loadGoogleFontsPreview(toLoad);
38745
+ }
38746
+ }, []);
38747
+ useEffect(() => {
38748
+ loadFontsBatch(filteredOptions.slice(0, 20));
38749
+ }, [filteredOptions, loadFontsBatch]);
38740
38750
  const handleSearch = useCallback((val) => {
38741
38751
  setSearchValue(val);
38742
38752
  }, []);
38753
+ const handlePopupScroll = useCallback((e2) => {
38754
+ const target2 = e2.target;
38755
+ const scrollRatio = (target2.scrollTop + target2.clientHeight) / target2.scrollHeight;
38756
+ if (scrollRatio > 0.7) {
38757
+ const approxIndex = Math.floor(target2.scrollTop / target2.scrollHeight * filteredOptions.length);
38758
+ loadFontsBatch(filteredOptions.slice(approxIndex, approxIndex + 20));
38759
+ }
38760
+ }, [filteredOptions, loadFontsBatch]);
38743
38761
  const fieldName = name2 || `${focusIdx2}.attributes.font-family`;
38744
38762
  return /* @__PURE__ */ React__default.createElement(Field, {
38745
38763
  name: fieldName
38746
38764
  }, ({ input: { onChange, onBlur: onBlur3, value } }) => /* @__PURE__ */ React__default.createElement(Form.Item, {
38765
+ className: "easy-email-font-family-field",
38747
38766
  label: t("Font family"),
38748
38767
  labelCol: { span: 24, style: { paddingRight: 0 } },
38749
38768
  wrapperCol: { span: 24 },
@@ -38761,12 +38780,20 @@ function FontFamily({ name: name2 }) {
38761
38780
  onBlur3();
38762
38781
  setSearchValue("");
38763
38782
  },
38783
+ onVisibleChange: (visible) => {
38784
+ if (visible) {
38785
+ loadFontsBatch(filteredOptions.slice(0, 20));
38786
+ }
38787
+ },
38764
38788
  filterOption: (inputValue, option) => {
38765
38789
  var _a2;
38766
38790
  const optValue = (((_a2 = option.props) == null ? void 0 : _a2.value) || "").toLowerCase();
38767
38791
  return optValue.includes(inputValue.toLowerCase());
38768
38792
  },
38769
- virtualListProps: { height: 256 },
38793
+ virtualListProps: {
38794
+ height: 256,
38795
+ onScroll: handlePopupScroll
38796
+ },
38770
38797
  style: { width: "100%" },
38771
38798
  dropdownMenuClassName: "easy-email-overlay",
38772
38799
  allowClear: true
@@ -55046,7 +55073,7 @@ function Tools(props) {
55046
55073
  ];
55047
55074
  case AvailableTools.FontFamily:
55048
55075
  return [
55049
- /* @__PURE__ */ React__default.createElement(FontFamily$1, {
55076
+ /* @__PURE__ */ React__default.createElement(FontFamily$2, {
55050
55077
  key: tool,
55051
55078
  execCommand,
55052
55079
  getPopupContainer: getPopoverMountNode