@cripty2001/utils 0.0.118 → 0.0.120

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.
@@ -7,5 +7,6 @@ export declare class Searcher<T> {
7
7
  private data;
8
8
  constructor(data: SearcherData<T>[]);
9
9
  search(query: string): SearcherData<T>[];
10
+ updateData(data: SearcherData<T>[]): void;
10
11
  }
11
- export declare function useSearcher_w<T>(data: SearcherData<T>[], query: Whispr<string>): Whispr<SearcherData<T>[]>;
12
+ export declare function useSearcher_w<T>(data: Whispr<SearcherData<T>[]>, query: Whispr<string>): Whispr<SearcherData<T>[]>;
@@ -13,15 +13,25 @@ class Searcher {
13
13
  return this.data;
14
14
  return this.data.filter(item => item.queries.some(q => q.includes(query.toLowerCase())));
15
15
  }
16
+ updateData(data) {
17
+ this.data = data;
18
+ }
16
19
  }
17
20
  exports.Searcher = Searcher;
18
21
  function useSearcher_w(data, query) {
19
- const searcher = new Searcher(data);
20
- let unsubscribe = () => { };
21
- const [toReturn, setToReturn] = whispr_1.Whispr.create([], () => unsubscribe());
22
- unsubscribe = query.subscribe((q) => {
22
+ const searcher = new Searcher(data.value);
23
+ let unsubscribe_q = () => { };
24
+ let unsubscribe_d = () => { };
25
+ const [toReturn, setToReturn] = whispr_1.Whispr.create([], () => {
26
+ unsubscribe_q();
27
+ unsubscribe_d();
28
+ });
29
+ unsubscribe_q = query.subscribe((q) => {
23
30
  let result = searcher.search(q);
24
31
  setToReturn(result);
25
32
  }, true);
33
+ unsubscribe_d = data.subscribe((d) => {
34
+ searcher.updateData(d);
35
+ }, true);
26
36
  return toReturn;
27
37
  }
@@ -12,8 +12,10 @@ export type FormComponentPropsInput = {
12
12
  });
13
13
  export type FormComponentProps<T extends Record<string, string>> = {
14
14
  inputs: FormComponentPropsInput[];
15
- onSubmit?: (values: T) => void;
16
- submitLabel: string;
15
+ submit?: {
16
+ label: string;
17
+ callback: (values: T) => void | Promise<void>;
18
+ };
17
19
  value: T;
18
20
  setValue: React.Dispatch<React.SetStateAction<T>>;
19
21
  variant: TypeofRecord<InputComponentPropsVariants> & {
@@ -32,6 +32,6 @@ function FormComponent(props) {
32
32
  default:
33
33
  return (0, jsx_runtime_1.jsx)("div", { style: { color: '#ef4444', backgroundColor: 'white' }, children: "Unknown input type" });
34
34
  }
35
- })()), props.onSubmit &&
36
- (0, jsx_runtime_1.jsx)(button_1.default, { className: variants.default.button, title: props.submitLabel, onClick: () => props.onSubmit?.(props.value) })] }));
35
+ })()), props.submit &&
36
+ (0, jsx_runtime_1.jsx)(button_1.default, { className: variants.default.button, title: props.submit.label, onClick: () => props.submit?.callback(props.value) })] }));
37
37
  }
@@ -73,8 +73,8 @@ export declare function useAsync<I, O>(f: (input: I, setProgress: (p: number) =>
73
73
  export declare function useRelTime(refresh?: number): (ts: Date | number) => string;
74
74
  /**
75
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)
76
+ * @param data The data to search on
77
+ * @param q The query to search for
78
78
  * @return The filtered data
79
79
  *
80
80
  */
@@ -177,13 +177,14 @@ function useRelTime(refresh = 1000) {
177
177
  }
178
178
  /**
179
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)
180
+ * @param data The data to search on
181
+ * @param q The query to search for
182
182
  * @return The filtered data
183
183
  *
184
184
  */
185
185
  function useSearcher(data, q) {
186
186
  const q_w = useWhispr(q);
187
- const searcher = (0, Searcher_1.useSearcher_w)(data, q_w);
187
+ const data_w = useWhispr(data);
188
+ const searcher = (0, Searcher_1.useSearcher_w)(data_w, q_w);
188
189
  return useWhisprValue(searcher);
189
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.118",
3
+ "version": "0.0.120",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {