@weser/hooks 1.0.0 → 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/dist/useList.d.ts +1 -1
- package/dist/useList.js +2 -2
- package/dist/useTree.d.ts +12 -12
- package/dist/useTree.js +12 -12
- package/package.json +2 -2
package/dist/useList.d.ts
CHANGED
package/dist/useList.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
-
export default function useList(
|
|
3
|
-
const [list, setList] = useState(
|
|
2
|
+
export default function useList(initialList = []) {
|
|
3
|
+
const [list, setList] = useState(initialList);
|
|
4
4
|
function set(list) {
|
|
5
5
|
setList(list);
|
|
6
6
|
}
|
package/dist/useTree.d.ts
CHANGED
|
@@ -4,16 +4,16 @@ export default function useTree<T extends BaseNode<T>>(initialTree: T): {
|
|
|
4
4
|
tree: T;
|
|
5
5
|
setTree: import("react").Dispatch<import("react").SetStateAction<T>>;
|
|
6
6
|
traverse: (callback: (node: T) => void) => void;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
create: (node: T extends any ? Omit<T, "id"> : never) => T;
|
|
8
|
+
get: (id: string, rootNode?: T) => T | null;
|
|
9
|
+
clone: (id: string) => T | null;
|
|
10
|
+
getParent: (id: string) => T | null;
|
|
11
|
+
find: (condition: (node: T) => boolean) => T | null;
|
|
12
|
+
findAll: (condition: (node: T) => boolean) => T[];
|
|
13
|
+
update: (id: string, newNode: Partial<BaseNodeInput<T>>) => void;
|
|
14
|
+
replace: (id: string, newNode: T) => void;
|
|
15
|
+
remove: (id: string) => void;
|
|
16
|
+
add: (id: string, newNode: T) => void;
|
|
17
|
+
insert: (id: string, index: number, newNode: T) => void;
|
|
18
|
+
move: (id: string, parentId: string, index?: number) => void;
|
|
19
19
|
};
|
package/dist/useTree.js
CHANGED
|
@@ -7,18 +7,18 @@ export default function useTree(initialTree) {
|
|
|
7
7
|
setTree,
|
|
8
8
|
// helpers
|
|
9
9
|
traverse: (callback) => utils.traverse(tree, callback),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
create: (utils.createNode),
|
|
11
|
+
get: (id, rootNode = tree) => utils.getNode(rootNode, id),
|
|
12
|
+
clone: (id) => utils.cloneNode(tree, id),
|
|
13
|
+
getParent: (id) => utils.getParentNode(tree, id),
|
|
14
|
+
find: (condition) => utils.findNode(tree, condition),
|
|
15
|
+
findAll: (condition) => utils.findAllNode(tree, condition),
|
|
16
16
|
// actions
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
update: (id, newNode) => setTree((tree) => utils.updateNode(tree, id, newNode)),
|
|
18
|
+
replace: (id, newNode) => setTree((tree) => utils.replaceNode(tree, id, newNode)),
|
|
19
|
+
remove: (id) => setTree((tree) => utils.removeNode(tree, id)),
|
|
20
|
+
add: (id, newNode) => setTree((tree) => utils.addNode(tree, id, newNode)),
|
|
21
|
+
insert: (id, index, newNode) => setTree((tree) => utils.insertNode(tree, id, index, newNode)),
|
|
22
|
+
move: (id, parentId, index) => setTree((tree) => utils.moveNode(tree, id, parentId, index)),
|
|
23
23
|
};
|
|
24
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weser/hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "React hooks for building apps",
|
|
5
5
|
"author": "Robin Weser <robin@weser.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"rimraf": "^3.0.2",
|
|
56
56
|
"typescript": "^5.4.5"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "e985ef20f1fb441a5fbdc4e5beb54ddea728f95f"
|
|
59
59
|
}
|