@ivanholiak/easy-email-extensions 4.16.12 → 4.16.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.
package/lib/index2.js CHANGED
@@ -38333,27 +38333,29 @@ const GOOGLE_FONTS = [
38333
38333
  "Zen Kaku Gothic New",
38334
38334
  "Zilla Slab"
38335
38335
  ];
38336
- const loadedFonts = /* @__PURE__ */ new Set();
38336
+ const loadedFullFonts = /* @__PURE__ */ new Set();
38337
+ const loadedPreviewFonts = /* @__PURE__ */ new Set();
38337
38338
  function loadGoogleFont(fontFamily) {
38338
- if (loadedFonts.has(fontFamily))
38339
+ if (loadedFullFonts.has(fontFamily))
38339
38340
  return;
38340
- loadedFonts.add(fontFamily);
38341
+ loadedFullFonts.add(fontFamily);
38341
38342
  const link2 = document.createElement("link");
38342
38343
  link2.rel = "stylesheet";
38343
38344
  link2.href = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(fontFamily)}:wght@400;700&display=swap`;
38344
38345
  document.head.appendChild(link2);
38345
38346
  }
38346
38347
  function loadGoogleFontsPreview(fontFamilies) {
38347
- const unloaded = fontFamilies.filter((f2) => !loadedFonts.has(f2));
38348
+ const unloaded = fontFamilies.filter((f2) => !loadedPreviewFonts.has(f2) && !loadedFullFonts.has(f2));
38348
38349
  if (unloaded.length === 0)
38349
38350
  return;
38350
38351
  for (const font of unloaded) {
38351
- loadedFonts.add(font);
38352
+ loadedPreviewFonts.add(font);
38352
38353
  }
38354
+ const uniqueChars = [...new Set(unloaded.join(""))].join("");
38353
38355
  const families = unloaded.map((f2) => `family=${encodeURIComponent(f2)}`).join("&");
38354
38356
  const link2 = document.createElement("link");
38355
38357
  link2.rel = "stylesheet";
38356
- link2.href = `https://fonts.googleapis.com/css2?${families}&display=swap`;
38358
+ link2.href = `https://fonts.googleapis.com/css2?${families}&text=${encodeURIComponent(uniqueChars)}&display=swap`;
38357
38359
  document.head.appendChild(link2);
38358
38360
  }
38359
38361
  function useFontFamily() {
@@ -38701,6 +38703,7 @@ function FontFamily({ name: name2 }) {
38701
38703
  const { fontList: defaultFontList } = useEditorProps();
38702
38704
  const { pageData: pageData2 } = useEditorContext();
38703
38705
  const [searchValue, setSearchValue] = useState("");
38706
+ const allFontsLoadedRef = useRef(false);
38704
38707
  const addFonts = pageData2.data.value.fonts;
38705
38708
  const allOptions = useMemo(() => {
38706
38709
  const options2 = [];
@@ -38729,14 +38732,21 @@ function FontFamily({ name: name2 }) {
38729
38732
  }
38730
38733
  return options2;
38731
38734
  }, [addFonts, defaultFontList]);
38732
- useEffect(() => {
38733
- 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);
38735
+ const handleDropdownVisibleChange = useCallback((visible) => {
38736
+ if (visible && !allFontsLoadedRef.current) {
38737
+ allFontsLoadedRef.current = true;
38738
+ const batchSize = 40;
38739
+ for (let i2 = 0; i2 < GOOGLE_FONTS.length; i2 += batchSize) {
38740
+ const batch = GOOGLE_FONTS.slice(i2, i2 + batchSize);
38741
+ const delay = Math.floor(i2 / batchSize) * 100;
38742
+ if (delay === 0) {
38743
+ loadGoogleFontsPreview(batch);
38744
+ } else {
38745
+ setTimeout(() => loadGoogleFontsPreview(batch), delay);
38746
+ }
38747
+ }
38738
38748
  }
38739
- }, [searchValue, allOptions]);
38749
+ }, []);
38740
38750
  const handleSearch = useCallback((val) => {
38741
38751
  setSearchValue(val);
38742
38752
  }, []);
@@ -38752,9 +38762,11 @@ function FontFamily({ name: name2 }) {
38752
38762
  }, /* @__PURE__ */ React__default.createElement(Select$2, {
38753
38763
  showSearch: true,
38754
38764
  allowCreate: true,
38765
+ className: "easy-email-font-family",
38755
38766
  value: value || void 0,
38756
38767
  placeholder: t("Font family"),
38757
38768
  onSearch: handleSearch,
38769
+ onVisibleChange: handleDropdownVisibleChange,
38758
38770
  onChange: (val) => {
38759
38771
  loadGoogleFont(val);
38760
38772
  onChange(val);