@headless-tree/react 1.0.1 → 1.2.0
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/CHANGELOG.md +14 -0
- package/lib/cjs/use-tree.js +10 -5
- package/lib/esm/use-tree.js +11 -6
- package/package.json +7 -1
- package/readme.md +2 -2
- package/src/use-tree.tsx +20 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @headless-tree/react
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 647a072: Fixed incorrect package.json exports configurations to proper ESM and CJS exports (#104)
|
|
8
|
+
- 349d36e: change package.json["module"] to commonjs to fix inconsistent package definitiuons (#104)
|
|
9
|
+
- e2faf37: Fixed an issue async data loaders that resolve data before the tree is mounted can cause the tree to not render at all
|
|
10
|
+
|
|
11
|
+
Note: When using the `createTree()` API directly instead of going through the React `useTree` API, an additional call
|
|
12
|
+
to `tree.rebuildItems()` afterwards will be necessary. This change is marked as minor release regardless, since `createTree` is
|
|
13
|
+
currently not a publically documented feature.
|
|
14
|
+
|
|
15
|
+
## 1.1.0
|
|
16
|
+
|
|
3
17
|
## 1.0.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/lib/cjs/use-tree.js
CHANGED
|
@@ -6,11 +6,16 @@ const core_1 = require("@headless-tree/core");
|
|
|
6
6
|
const useTree = (config) => {
|
|
7
7
|
const [tree] = (0, react_1.useState)(() => ({ current: (0, core_1.createTree)(config) }));
|
|
8
8
|
const [state, setState] = (0, react_1.useState)(() => tree.current.getState());
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} })))
|
|
9
|
+
(0, react_1.useEffect)(() => {
|
|
10
|
+
tree.current.rebuildTree();
|
|
11
|
+
}, [tree]); // runs only once after mount
|
|
12
|
+
(0, react_1.useInsertionEffect)(() => {
|
|
13
|
+
tree.current.setConfig((prev) => (Object.assign(Object.assign(Object.assign({}, prev), config), { state: Object.assign(Object.assign({}, state), config.state), setState: (state) => {
|
|
14
|
+
var _a;
|
|
15
|
+
setState(state);
|
|
16
|
+
(_a = config.setState) === null || _a === void 0 ? void 0 : _a.call(config, state);
|
|
17
|
+
} })));
|
|
18
|
+
});
|
|
14
19
|
return tree.current;
|
|
15
20
|
};
|
|
16
21
|
exports.useTree = useTree;
|
package/lib/esm/use-tree.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useInsertionEffect, useState } from "react";
|
|
2
2
|
import { createTree } from "@headless-tree/core";
|
|
3
3
|
export const useTree = (config) => {
|
|
4
4
|
const [tree] = useState(() => ({ current: createTree(config) }));
|
|
5
5
|
const [state, setState] = useState(() => tree.current.getState());
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} })))
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
tree.current.rebuildTree();
|
|
8
|
+
}, [tree]); // runs only once after mount
|
|
9
|
+
useInsertionEffect(() => {
|
|
10
|
+
tree.current.setConfig((prev) => (Object.assign(Object.assign(Object.assign({}, prev), config), { state: Object.assign(Object.assign({}, state), config.state), setState: (state) => {
|
|
11
|
+
var _a;
|
|
12
|
+
setState(state);
|
|
13
|
+
(_a = config.setState) === null || _a === void 0 ? void 0 : _a.call(config, state);
|
|
14
|
+
} })));
|
|
15
|
+
});
|
|
11
16
|
return tree.current;
|
|
12
17
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-tree/react",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "lib/cjs/index.js",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/esm/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
"types": "./lib/esm/index.d.ts",
|
|
9
|
+
"import": "./lib/esm/index.js",
|
|
10
|
+
"default": "./lib/cjs/index.js"
|
|
11
|
+
},
|
|
7
12
|
"sideEffects": false,
|
|
8
13
|
"scripts": {
|
|
9
14
|
"build:cjs": "tsc -m commonjs --outDir lib/cjs",
|
|
@@ -16,6 +21,7 @@
|
|
|
16
21
|
"directory": "packages/react"
|
|
17
22
|
},
|
|
18
23
|
"author": "Lukas Bach <npm@lukasbach.com>",
|
|
24
|
+
"funding": "https://github.com/sponsors/lukasbach",
|
|
19
25
|
"license": "MIT",
|
|
20
26
|
"devDependencies": {
|
|
21
27
|
"@babel/preset-env": "^7.24.0",
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
[](https://headless-tree.lukasbach.com/)
|
|
4
4
|
[](https://discord.gg/KuZ6EezzVw)
|
|
@@ -139,7 +139,7 @@ Then, render your tree based on the tree instance returned from the hook:
|
|
|
139
139
|
style={{ paddingLeft: `${item.getItemMeta().level * 20}px` }}
|
|
140
140
|
>
|
|
141
141
|
<div
|
|
142
|
-
className={
|
|
142
|
+
className={cn("treeitem", {
|
|
143
143
|
focused: item.isFocused(),
|
|
144
144
|
expanded: item.isExpanded(),
|
|
145
145
|
selected: item.isSelected(),
|
package/src/use-tree.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useEffect, useInsertionEffect, useState } from "react";
|
|
2
2
|
import { TreeConfig, TreeState, createTree } from "@headless-tree/core";
|
|
3
3
|
|
|
4
4
|
export const useTree = <T,>(config: TreeConfig<T>) => {
|
|
@@ -7,19 +7,25 @@ export const useTree = <T,>(config: TreeConfig<T>) => {
|
|
|
7
7
|
tree.current.getState(),
|
|
8
8
|
);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
...
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
tree.current.rebuildTree();
|
|
12
|
+
}, [tree]); // runs only once after mount
|
|
13
|
+
|
|
14
|
+
useInsertionEffect(() => {
|
|
15
|
+
tree.current.setConfig((prev) => ({
|
|
16
|
+
...prev,
|
|
17
|
+
...config,
|
|
18
|
+
state: {
|
|
19
|
+
// ...prev.state,
|
|
20
|
+
...state,
|
|
21
|
+
...config.state,
|
|
22
|
+
},
|
|
23
|
+
setState: (state) => {
|
|
24
|
+
setState(state);
|
|
25
|
+
config.setState?.(state);
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
23
29
|
|
|
24
30
|
return tree.current;
|
|
25
31
|
};
|