@etoile-dev/react 0.2.3 → 1.0.1
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/README.md +344 -206
- package/dist/Searchbar.d.ts +315 -0
- package/dist/Searchbar.js +207 -0
- package/dist/context.d.ts +57 -0
- package/dist/context.js +32 -0
- package/dist/hooks/useEtoileSearch.d.ts +136 -0
- package/dist/hooks/useEtoileSearch.js +187 -0
- package/dist/index.d.ts +44 -19
- package/dist/index.js +37 -12
- package/dist/primitives/Content.d.ts +34 -0
- package/dist/primitives/Content.js +108 -0
- package/dist/primitives/Empty.d.ts +25 -0
- package/dist/primitives/Empty.js +25 -0
- package/dist/primitives/Error.d.ts +29 -0
- package/dist/primitives/Error.js +26 -0
- package/dist/primitives/Group.d.ts +30 -0
- package/dist/primitives/Group.js +22 -0
- package/dist/primitives/Icon.d.ts +21 -0
- package/dist/primitives/Icon.js +14 -0
- package/dist/primitives/Input.d.ts +32 -0
- package/dist/primitives/Input.js +70 -0
- package/dist/primitives/Item.d.ts +61 -0
- package/dist/primitives/Item.js +76 -0
- package/dist/primitives/Kbd.d.ts +20 -0
- package/dist/primitives/Kbd.js +13 -0
- package/dist/primitives/List.d.ts +35 -0
- package/dist/primitives/List.js +37 -0
- package/dist/primitives/Loading.d.ts +25 -0
- package/dist/primitives/Loading.js +26 -0
- package/dist/primitives/Modal.d.ts +39 -0
- package/dist/primitives/Modal.js +37 -0
- package/dist/primitives/ModalInput.d.ts +61 -0
- package/dist/primitives/ModalInput.js +33 -0
- package/dist/primitives/Overlay.d.ts +21 -0
- package/dist/primitives/Overlay.js +41 -0
- package/dist/primitives/Portal.d.ts +28 -0
- package/dist/primitives/Portal.js +30 -0
- package/dist/primitives/Root.d.ts +116 -0
- package/dist/primitives/Root.js +413 -0
- package/dist/primitives/Separator.d.ts +19 -0
- package/dist/primitives/Separator.js +18 -0
- package/dist/primitives/Thumbnail.d.ts +31 -0
- package/dist/primitives/Thumbnail.js +59 -0
- package/dist/primitives/Trigger.d.ts +28 -0
- package/dist/primitives/Trigger.js +35 -0
- package/dist/store.d.ts +38 -0
- package/dist/store.js +63 -0
- package/dist/styles.css +480 -133
- package/dist/types.d.ts +3 -31
- package/dist/utils/composeRefs.d.ts +12 -0
- package/dist/utils/composeRefs.js +27 -0
- package/dist/utils/slot.d.ts +22 -0
- package/dist/utils/slot.js +58 -0
- package/package.json +9 -5
- package/dist/Search.d.ts +0 -39
- package/dist/Search.js +0 -31
- package/dist/components/SearchIcon.d.ts +0 -22
- package/dist/components/SearchIcon.js +0 -17
- package/dist/components/SearchInput.d.ts +0 -30
- package/dist/components/SearchInput.js +0 -59
- package/dist/components/SearchKbd.d.ts +0 -30
- package/dist/components/SearchKbd.js +0 -24
- package/dist/components/SearchResult.d.ts +0 -31
- package/dist/components/SearchResult.js +0 -40
- package/dist/components/SearchResultThumbnail.d.ts +0 -38
- package/dist/components/SearchResultThumbnail.js +0 -38
- package/dist/components/SearchResults.d.ts +0 -39
- package/dist/components/SearchResults.js +0 -53
- package/dist/components/SearchRoot.d.ts +0 -44
- package/dist/components/SearchRoot.js +0 -132
- package/dist/context/SearchContext.d.ts +0 -55
- package/dist/context/SearchContext.js +0 -36
- package/dist/hooks/useSearch.d.ts +0 -56
- package/dist/hooks/useSearch.js +0 -116
package/dist/store.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SearchbarStore — external state container for the Searchbar primitives.
|
|
3
|
+
*
|
|
4
|
+
* Uses the subscribe/getSnapshot pattern compatible with useSyncExternalStore,
|
|
5
|
+
* so each component can subscribe to exactly the slice of state it needs and
|
|
6
|
+
* avoid re-rendering on unrelated updates (e.g. a keystroke should not force
|
|
7
|
+
* every item to re-render).
|
|
8
|
+
*/
|
|
9
|
+
function deriveFiltered(state) {
|
|
10
|
+
const base = state.sortedValues.filter((v) => {
|
|
11
|
+
const item = state.items.get(v);
|
|
12
|
+
return item && !item.disabled;
|
|
13
|
+
});
|
|
14
|
+
return { filteredValues: base, filteredSet: new Set(base) };
|
|
15
|
+
}
|
|
16
|
+
export function createSearchbarStore(initial = {}) {
|
|
17
|
+
let state = {
|
|
18
|
+
query: "",
|
|
19
|
+
open: false,
|
|
20
|
+
selectedValue: null,
|
|
21
|
+
isLoading: false,
|
|
22
|
+
error: null,
|
|
23
|
+
items: new Map(),
|
|
24
|
+
sortedValues: [],
|
|
25
|
+
filteredValues: [],
|
|
26
|
+
filteredSet: new Set(),
|
|
27
|
+
...initial,
|
|
28
|
+
};
|
|
29
|
+
// Compute initial derived state
|
|
30
|
+
const derived = deriveFiltered(state);
|
|
31
|
+
state = { ...state, ...derived };
|
|
32
|
+
const listeners = new Set();
|
|
33
|
+
const emit = () => listeners.forEach((fn) => fn());
|
|
34
|
+
const shallowEqual = (a, b) => a.query === b.query &&
|
|
35
|
+
a.open === b.open &&
|
|
36
|
+
a.selectedValue === b.selectedValue &&
|
|
37
|
+
a.isLoading === b.isLoading &&
|
|
38
|
+
a.error === b.error &&
|
|
39
|
+
a.items === b.items &&
|
|
40
|
+
a.sortedValues === b.sortedValues &&
|
|
41
|
+
a.filteredValues === b.filteredValues;
|
|
42
|
+
return {
|
|
43
|
+
getState: () => state,
|
|
44
|
+
setState: (updater) => {
|
|
45
|
+
const prev = state;
|
|
46
|
+
const next = updater(prev);
|
|
47
|
+
const needsRefilter = next.query !== prev.query ||
|
|
48
|
+
next.sortedValues !== prev.sortedValues ||
|
|
49
|
+
next.items !== prev.items;
|
|
50
|
+
const nextState = needsRefilter
|
|
51
|
+
? { ...next, ...deriveFiltered(next) }
|
|
52
|
+
: next;
|
|
53
|
+
if (shallowEqual(state, nextState))
|
|
54
|
+
return;
|
|
55
|
+
state = nextState;
|
|
56
|
+
emit();
|
|
57
|
+
},
|
|
58
|
+
subscribe: (fn) => {
|
|
59
|
+
listeners.add(fn);
|
|
60
|
+
return () => listeners.delete(fn);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|