@fe-free/core 3.0.32 → 3.0.33

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 3.0.33
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: tree
8
+ - Updated dependencies
9
+ - @fe-free/tool@3.0.33
10
+ - @fe-free/icons@3.0.33
11
+
3
12
  ## 3.0.32
4
13
 
5
14
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "3.0.32",
3
+ "version": "3.0.33",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -46,8 +46,8 @@
46
46
  "antd": "^5.27.1",
47
47
  "dayjs": "~1.11.10",
48
48
  "react": "^19.2.0",
49
- "@fe-free/icons": "3.0.32",
50
- "@fe-free/tool": "3.0.32"
49
+ "@fe-free/icons": "3.0.33",
50
+ "@fe-free/tool": "3.0.33"
51
51
  },
52
52
  "scripts": {
53
53
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -198,7 +198,7 @@ function FileTree<D extends DataNode>(props: FileTreeProps<D>) {
198
198
  (nodeData) => {
199
199
  const hasMore = actions?.includes('update') || actions?.includes('delete');
200
200
  return (
201
- <div className="group flex items-center gap-2">
201
+ <div className="group flex items-center gap-1">
202
202
  {nodeData.children ? (
203
203
  <FileCard.FileIcon isDirectory className="text-base" />
204
204
  ) : (
package/src/tree/tree.tsx CHANGED
@@ -108,6 +108,32 @@ function useFilterTreeData({ treeData, search }) {
108
108
  }, [treeData, search]);
109
109
  }
110
110
 
111
+ function useTreeData({ treeData }) {
112
+ return useMemo(() => {
113
+ if (!treeData) {
114
+ return treeData;
115
+ }
116
+
117
+ function process(nodes) {
118
+ // 返回自己。 而非 [] undefined,因为要保留原数据格式。
119
+ if (!nodes || nodes.length === 0) {
120
+ return nodes;
121
+ }
122
+
123
+ return nodes.map((node) => {
124
+ return {
125
+ ...node,
126
+ // 如果没有显式设置 isLeaf,则 children 没传代表是叶子节点,否则还是个 dir
127
+ isLeaf: node.isLeaf ?? !node.children,
128
+ children: process(node.children),
129
+ };
130
+ });
131
+ }
132
+
133
+ return process(treeData);
134
+ }, [treeData]);
135
+ }
136
+
111
137
  function useIsAllLeaf(treeData?: DataNode[]) {
112
138
  return useMemo(() => {
113
139
  if (treeData) {
@@ -134,7 +160,7 @@ function Tree<T extends DataNode>(props: TreeProps<T>) {
134
160
  treeData: filterTreeData,
135
161
  search: debouncedSearch,
136
162
  });
137
- const newTreeData = highlightedTreeData;
163
+ const newTreeData = useTreeData({ treeData: highlightedTreeData });
138
164
 
139
165
  const handleSearch = useCallback((e) => {
140
166
  setSearch(e.target.value);