@firecms/core 3.0.0-canary.95 → 3.0.0-canary.97

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/dist/index.es.js CHANGED
@@ -13,7 +13,7 @@ import useMeasure from "react-use-measure";
13
13
  import { useDropzone } from "react-dropzone";
14
14
  import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd";
15
15
  import Resizer from "react-image-file-resizer";
16
- import * as JsSearch from "js-search";
16
+ import Fuse from "fuse.js";
17
17
  import { FixedSizeList } from "react-window";
18
18
  import * as yup from "yup";
19
19
  import MarkdownIt from "markdown-it";
@@ -2652,15 +2652,20 @@ const iconSynonyms = {
2652
2652
  zoom_out: "find glass look magnifier magnifying minus negative scale search see size smaller",
2653
2653
  zoom_out_map: "arrows destination location maps move place stop"
2654
2654
  };
2655
- const iconsSearch = new JsSearch.Search("key");
2656
- iconsSearch.addIndex("synonyms");
2657
- iconsSearch.addDocuments(iconKeys.map((importName) => {
2655
+ console.log("iconKeys", iconKeys);
2656
+ const map = iconKeys.map((importName) => {
2657
+ const iconSynonym = importName in iconSynonyms ? iconSynonyms[importName] : "";
2658
2658
  return {
2659
2659
  key: importName,
2660
- // @ts-ignore
2661
- synonyms: iconSynonyms[importName] ?? []
2660
+ synonyms: iconSynonym
2662
2661
  };
2663
- }));
2662
+ });
2663
+ const iconsSearch = new Fuse(map, {
2664
+ isCaseSensitive: false,
2665
+ shouldSort: true,
2666
+ distance: 0,
2667
+ keys: ["key", "synonyms"]
2668
+ });
2664
2669
  function hashString(str) {
2665
2670
  let hash2 = 0;
2666
2671
  let i;
@@ -11417,11 +11422,6 @@ function useRestoreScroll() {
11417
11422
  direction
11418
11423
  };
11419
11424
  }
11420
- const search = new JsSearch.Search("url");
11421
- search.addIndex("name");
11422
- search.addIndex("description");
11423
- search.addIndex("group");
11424
- search.addIndex("path");
11425
11425
  function DefaultHomePage({
11426
11426
  additionalActions,
11427
11427
  additionalChildrenStart,
@@ -11430,6 +11430,7 @@ function DefaultHomePage({
11430
11430
  const context = useFireCMSContext();
11431
11431
  const customizationController = useCustomizationController();
11432
11432
  const navigationController = useNavigationController();
11433
+ const fuse = useRef(null);
11433
11434
  if (!navigationController.topLevelNavigation)
11434
11435
  throw Error("Navigation not ready in FireCMSHomePage");
11435
11436
  const {
@@ -11444,15 +11445,25 @@ function DefaultHomePage({
11444
11445
  const [filteredUrls, setFilteredUrls] = useState(null);
11445
11446
  const filteredNavigationEntries = filteredUrls ? navigationEntries.filter((entry) => filteredUrls.includes(entry.url)) : navigationEntries;
11446
11447
  useEffect(() => {
11447
- search.addDocuments(navigationEntries);
11448
+ fuse.current = new Fuse(navigationEntries, {
11449
+ keys: [
11450
+ "name",
11451
+ "description",
11452
+ "group",
11453
+ "path"
11454
+ ]
11455
+ });
11448
11456
  }, [navigationEntries]);
11449
11457
  const updateSearchResults = useCallback(
11450
11458
  (value) => {
11451
11459
  if (!value || value === "") {
11452
11460
  setFilteredUrls(null);
11453
11461
  } else {
11454
- const searchResult = search.search(value);
11455
- setFilteredUrls(searchResult.map((e) => e.url));
11462
+ const searchResult = fuse.current?.search(value);
11463
+ console.log("Search result", searchResult);
11464
+ if (searchResult) {
11465
+ setFilteredUrls(searchResult.map((e) => e.item.url));
11466
+ }
11456
11467
  }
11457
11468
  },
11458
11469
  []
@@ -13587,7 +13598,9 @@ function SearchIconsView({
13587
13598
  setKeys(null);
13588
13599
  } else {
13589
13600
  const searchResult = iconsSearch.search(value);
13590
- setKeys(searchResult.map((e) => e.key));
13601
+ const limit = 50;
13602
+ const limited = searchResult.slice(0, limit);
13603
+ setKeys(limited.map((e) => e.item.key));
13591
13604
  }
13592
13605
  }, UPDATE_SEARCH_INDEX_WAIT_MS),
13593
13606
  []
@@ -13599,6 +13612,7 @@ function SearchIconsView({
13599
13612
  };
13600
13613
  }, [query, updateSearchResults]);
13601
13614
  const icons = keys === null ? coolIconKeys : keys;
13615
+ console.log("Icons", icons);
13602
13616
  return /* @__PURE__ */ jsxs(Fragment, { children: [
13603
13617
  /* @__PURE__ */ jsx(
13604
13618
  SearchBar,