@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.
@@ -1 +1,5 @@
1
- export declare const iconsSearch: any;
1
+ import Fuse from "fuse.js";
2
+ export declare const iconsSearch: Fuse<{
3
+ key: string;
4
+ synonyms: any;
5
+ }>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@firecms/core",
3
3
  "type": "module",
4
- "version": "3.0.0-canary.95",
4
+ "version": "3.0.0-canary.97",
5
5
  "description": "Awesome Firebase/Firestore-based headless open-source CMS",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/firecmsco"
@@ -46,14 +46,14 @@
46
46
  "./package.json": "./package.json"
47
47
  },
48
48
  "dependencies": {
49
- "@firecms/formex": "^3.0.0-canary.95",
50
- "@firecms/ui": "^3.0.0-canary.95",
49
+ "@firecms/formex": "^3.0.0-canary.97",
50
+ "@firecms/ui": "^3.0.0-canary.97",
51
51
  "@hello-pangea/dnd": "^16.6.0",
52
52
  "@radix-ui/react-portal": "^1.1.1",
53
53
  "clsx": "^2.1.1",
54
54
  "date-fns": "^3.6.0",
55
+ "fuse.js": "^7.0.0",
55
56
  "history": "^5.3.0",
56
- "js-search": "^2.0.1",
57
57
  "markdown-it": "^14.1.0",
58
58
  "notistack": "^3.0.1",
59
59
  "object-hash": "^3.0.0",
@@ -68,8 +68,8 @@
68
68
  },
69
69
  "peerDependencies": {
70
70
  "firebase": "^10.5.2",
71
- "react": "^18.3.1",
72
- "react-dom": "^18.3.1",
71
+ "react": ">=18.3.1",
72
+ "react-dom": ">=18.3.1",
73
73
  "react-router": "^6.25.1",
74
74
  "react-router-dom": "^6.25.1"
75
75
  },
@@ -100,7 +100,7 @@
100
100
  "dist",
101
101
  "src"
102
102
  ],
103
- "gitHead": "9445f94041b8654b1cf88310f6fda2a4f3e9be3f",
103
+ "gitHead": "da52ff032616af10d60ee976daf80f18d5ac879b",
104
104
  "publishConfig": {
105
105
  "access": "public"
106
106
  },
@@ -1,25 +1,23 @@
1
- import React, { useCallback, useEffect, useState } from "react";
1
+ import React, { useCallback, useEffect, useRef, useState } from "react";
2
2
 
3
3
  import { useCustomizationController, useFireCMSContext, useNavigationController } from "../../hooks";
4
- import { CMSAnalyticsEvent, PluginGenericProps, PluginHomePageAdditionalCardsProps } from "../../types";
4
+ import {
5
+ CMSAnalyticsEvent,
6
+ PluginGenericProps,
7
+ PluginHomePageAdditionalCardsProps,
8
+ TopNavigationEntry
9
+ } from "../../types";
5
10
 
6
11
  import { toArray } from "../../util/arrays";
7
12
  import { NavigationGroup } from "./NavigationGroup";
8
13
  import { NavigationCardBinding } from "./NavigationCardBinding";
9
14
 
10
- // @ts-ignore
11
- import * as JsSearch from "js-search";
15
+ import Fuse from "fuse.js"
12
16
 
13
17
  import { Container, SearchBar } from "@firecms/ui";
14
18
  import { FavouritesView } from "./FavouritesView";
15
19
  import { useRestoreScroll } from "../../internal/useRestoreScroll";
16
20
 
17
- const search = new JsSearch.Search("url");
18
- search.addIndex("name");
19
- search.addIndex("description");
20
- search.addIndex("group");
21
- search.addIndex("path");
22
-
23
21
  /**
24
22
  * Default entry view for the CMS. This component renders navigation cards
25
23
  * for each collection defined in the navigation.
@@ -49,6 +47,8 @@ export function DefaultHomePage({
49
47
  const customizationController = useCustomizationController();
50
48
  const navigationController = useNavigationController();
51
49
 
50
+ const fuse = useRef<Fuse<TopNavigationEntry> | null>(null);
51
+
52
52
  if (!navigationController.topLevelNavigation)
53
53
  throw Error("Navigation not ready in FireCMSHomePage");
54
54
 
@@ -70,7 +70,13 @@ export function DefaultHomePage({
70
70
  : navigationEntries;
71
71
 
72
72
  useEffect(() => {
73
- search.addDocuments(navigationEntries);
73
+ fuse.current = new Fuse(navigationEntries, {
74
+ keys: ["name",
75
+ "description",
76
+ "group",
77
+ "path"
78
+ ]
79
+ });
74
80
  }, [navigationEntries]);
75
81
 
76
82
  const updateSearchResults = useCallback(
@@ -78,8 +84,11 @@ export function DefaultHomePage({
78
84
  if (!value || value === "") {
79
85
  setFilteredUrls(null);
80
86
  } else {
81
- const searchResult = search.search(value);
82
- setFilteredUrls(searchResult.map((e: any) => e.url));
87
+ const searchResult = fuse.current?.search(value);
88
+ console.log("Search result", searchResult);
89
+ if (searchResult) {
90
+ setFilteredUrls(searchResult.map((e) => e.item.url));
91
+ }
83
92
  }
84
93
  }, []);
85
94
 
@@ -31,7 +31,9 @@ export function SearchIconsView({
31
31
  setKeys(null);
32
32
  } else {
33
33
  const searchResult = iconsSearch.search(value);
34
- setKeys(searchResult.map((e: any) => e.key));
34
+ const limit = 50;
35
+ const limited = searchResult.slice(0, limit);
36
+ setKeys(limited.map((e) => e.item.key));
35
37
  }
36
38
  }, UPDATE_SEARCH_INDEX_WAIT_MS), []
37
39
  );
@@ -44,6 +46,7 @@ export function SearchIconsView({
44
46
  }, [query, updateSearchResults]);
45
47
 
46
48
  const icons = keys === null ? coolIconKeys : keys;
49
+ console.log("Icons", icons);
47
50
 
48
51
  return (
49
52
  <>
@@ -1,17 +1,23 @@
1
1
  import { iconSynonyms } from "./icon_synonyms";
2
2
  import { iconKeys } from "@firecms/ui";
3
+ import Fuse from "fuse.js";
3
4
 
4
- // @ts-ignore
5
- import * as JsSearch from "js-search";
6
5
 
7
- export const iconsSearch = new JsSearch.Search("key");
8
- iconsSearch.addIndex("synonyms");
9
-
10
- iconsSearch.addDocuments(iconKeys
6
+ console.log("iconKeys", iconKeys);
7
+ const map = iconKeys
11
8
  .map((importName) => {
9
+ // @ts-ignore
10
+ const iconSynonym = importName in iconSynonyms ? iconSynonyms[importName] : "";
12
11
  return {
13
12
  key: importName,
14
- // @ts-ignore
15
- synonyms: iconSynonyms[importName] ?? [],
13
+ synonyms: iconSynonym,
16
14
  }
17
- }));
15
+ });
16
+ export const iconsSearch = new Fuse(map, {
17
+ isCaseSensitive: false,
18
+ shouldSort: true,
19
+ distance: 0,
20
+ keys: ["key", "synonyms"]
21
+ })
22
+
23
+