@cripty2001/utils 0.0.112 → 0.0.114
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/Searcher/index.d.ts +11 -0
- package/dist/Searcher/index.js +25 -0
- package/dist/react-ui/modal.d.ts +2 -2
- package/dist/react-ui/modal.js +2 -4
- package/dist/react-whispr.d.ts +9 -0
- package/dist/react-whispr.js +14 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Whispr } from "@cripty2001/whispr";
|
|
2
|
+
export type SearcherData<T> = {
|
|
3
|
+
queries: string[];
|
|
4
|
+
doc: T;
|
|
5
|
+
};
|
|
6
|
+
export declare class Searcher<T> {
|
|
7
|
+
private data;
|
|
8
|
+
constructor(data: SearcherData<T>[]);
|
|
9
|
+
search(query: string): SearcherData<T>[];
|
|
10
|
+
}
|
|
11
|
+
export declare function useSearcher_w<T>(data: SearcherData<T>[], query: Whispr<string>): Whispr<SearcherData<T>[]>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Searcher = void 0;
|
|
4
|
+
exports.useSearcher_w = useSearcher_w;
|
|
5
|
+
const whispr_1 = require("@cripty2001/whispr");
|
|
6
|
+
class Searcher {
|
|
7
|
+
data = [];
|
|
8
|
+
constructor(data) {
|
|
9
|
+
this.data = data;
|
|
10
|
+
}
|
|
11
|
+
search(query) {
|
|
12
|
+
return this.data.filter(item => item.queries.some(q => q.includes(query.toLowerCase())));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Searcher = Searcher;
|
|
16
|
+
function useSearcher_w(data, query) {
|
|
17
|
+
const searcher = new Searcher(data);
|
|
18
|
+
let unsubscribe = () => { };
|
|
19
|
+
const [toReturn, setToReturn] = whispr_1.Whispr.create([], () => unsubscribe());
|
|
20
|
+
unsubscribe = query.subscribe((q) => {
|
|
21
|
+
let result = searcher.search(q);
|
|
22
|
+
setToReturn(result);
|
|
23
|
+
}, true);
|
|
24
|
+
return toReturn;
|
|
25
|
+
}
|
package/dist/react-ui/modal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type ModalComponentProps = {
|
|
2
2
|
children: React.ReactNode;
|
|
3
|
-
open: boolean
|
|
4
|
-
setOpen: (open: boolean) => void
|
|
3
|
+
open: boolean;
|
|
4
|
+
setOpen: (open: boolean) => void;
|
|
5
5
|
};
|
|
6
6
|
export default function ModalComponent(props: ModalComponentProps): import("react/jsx-runtime").JSX.Element | null;
|
package/dist/react-ui/modal.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = ModalComponent;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
-
const react_whispr_1 = require("../react-whispr");
|
|
7
6
|
const slideUpKeyframes = `
|
|
8
7
|
@keyframes slide-up {
|
|
9
8
|
from {
|
|
@@ -28,8 +27,7 @@ let modalCount = 0;
|
|
|
28
27
|
function ModalComponent(props) {
|
|
29
28
|
const zIndex = (0, react_1.useRef)(1000 + modalCount++).current;
|
|
30
29
|
const id = (0, react_1.useRef)(`modal-${zIndex}`).current;
|
|
31
|
-
|
|
32
|
-
if (!open)
|
|
30
|
+
if (!props.open)
|
|
33
31
|
return null;
|
|
34
32
|
return ((0, jsx_runtime_1.jsx)("div", { id: id, style: {
|
|
35
33
|
position: 'fixed',
|
|
@@ -45,5 +43,5 @@ function ModalComponent(props) {
|
|
|
45
43
|
height: '100vh',
|
|
46
44
|
width: '100vw',
|
|
47
45
|
zIndex: zIndex
|
|
48
|
-
}, onClick: () => setOpen(false), children: (0, jsx_runtime_1.jsx)("div", { style: { maxWidth: '100%', animation: 'slide-up 0.3s ease-out' }, onClick: (e) => e.stopPropagation(), children: props.children }) }));
|
|
46
|
+
}, onClick: () => props.setOpen(false), children: (0, jsx_runtime_1.jsx)("div", { style: { maxWidth: '100%', animation: 'slide-up 0.3s ease-out' }, onClick: (e) => e.stopPropagation(), children: props.children }) }));
|
|
49
47
|
}
|
package/dist/react-whispr.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Whispr } from "@cripty2001/whispr";
|
|
2
2
|
import { Dispatcher } from "./Dispatcher";
|
|
3
|
+
import { SearcherData } from "./Searcher";
|
|
3
4
|
/**
|
|
4
5
|
* Convert a Whispr value into a reactive react value, usable in function components with the standard react reactive system.
|
|
5
6
|
* If the value is not a Whispr, it is returned as is, thus allowing for progressive migration and adoption
|
|
@@ -70,3 +71,11 @@ export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) =>
|
|
|
70
71
|
* @returns A callback (reactive, will change on refresh) that formats a given timestamp into a relative time string.
|
|
71
72
|
*/
|
|
72
73
|
export declare function useRelTime(refresh?: number): (ts: Date | number) => string;
|
|
74
|
+
/**
|
|
75
|
+
* React shorthand for the Searcher
|
|
76
|
+
* @param data The data to search on (static, the hook must be re-called if those data changes)
|
|
77
|
+
* @param q The query to search for (dynamic, can be updated to have the returned results updated)
|
|
78
|
+
* @return The filtered data
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
export declare function useSearcher<T>(data: SearcherData<T>[], q: string): SearcherData<T>[];
|
package/dist/react-whispr.js
CHANGED
|
@@ -8,11 +8,13 @@ exports.useDebounced = useDebounced;
|
|
|
8
8
|
exports.useSynced = useSynced;
|
|
9
9
|
exports.useAsync = useAsync;
|
|
10
10
|
exports.useRelTime = useRelTime;
|
|
11
|
+
exports.useSearcher = useSearcher;
|
|
11
12
|
const whispr_1 = require("@cripty2001/whispr");
|
|
12
13
|
const react_1 = require("react");
|
|
13
14
|
const lodash_1 = require("lodash");
|
|
14
15
|
const _1 = require(".");
|
|
15
16
|
const Dispatcher_1 = require("./Dispatcher");
|
|
17
|
+
const Searcher_1 = require("./Searcher");
|
|
16
18
|
/**
|
|
17
19
|
* Convert a Whispr value into a reactive react value, usable in function components with the standard react reactive system.
|
|
18
20
|
* If the value is not a Whispr, it is returned as is, thus allowing for progressive migration and adoption
|
|
@@ -173,3 +175,15 @@ function useRelTime(refresh = 1000) {
|
|
|
173
175
|
}, [currTs, rtf]);
|
|
174
176
|
return cb;
|
|
175
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* React shorthand for the Searcher
|
|
180
|
+
* @param data The data to search on (static, the hook must be re-called if those data changes)
|
|
181
|
+
* @param q The query to search for (dynamic, can be updated to have the returned results updated)
|
|
182
|
+
* @return The filtered data
|
|
183
|
+
*
|
|
184
|
+
*/
|
|
185
|
+
function useSearcher(data, q) {
|
|
186
|
+
const q_w = useWhispr(q);
|
|
187
|
+
const searcher = (0, Searcher_1.useSearcher_w)(data, q_w);
|
|
188
|
+
return useWhisprValue(searcher);
|
|
189
|
+
}
|
package/package.json
CHANGED