@fe-free/core 2.2.9 → 2.2.11

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,19 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 2.2.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @fe-free/tool@2.2.11
9
+
10
+ ## 2.2.10
11
+
12
+ ### Patch Changes
13
+
14
+ - feat: true
15
+ - @fe-free/tool@2.2.10
16
+
3
17
  ## 2.2.9
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "2.2.9",
3
+ "version": "2.2.11",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -41,7 +41,7 @@
41
41
  "remark-gfm": "^4.0.1",
42
42
  "vanilla-jsoneditor": "^0.23.1",
43
43
  "zustand": "^4.5.4",
44
- "@fe-free/tool": "2.2.9"
44
+ "@fe-free/tool": "2.2.11"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
@@ -3,7 +3,7 @@ import { useDebounce } from 'ahooks';
3
3
  import type { TreeProps as AntdTreeProps } from 'antd';
4
4
  import { Tree as AntdTree, Input } from 'antd';
5
5
  import type { DataNode } from 'antd/es/tree';
6
- import { useMemo, useState } from 'react';
6
+ import { useCallback, useMemo, useState } from 'react';
7
7
  import { flatToTreeData } from './helper';
8
8
 
9
9
  interface TreeProps<T extends DataNode> extends AntdTreeProps<T> {
@@ -101,8 +101,32 @@ function Tree<T extends DataNode>(props: TreeProps<T>) {
101
101
  treeData: filterTreeData,
102
102
  search: debouncedSearch,
103
103
  });
104
+ const newTreeData = highlightedTreeData;
104
105
 
105
- const node = <AntdTree {...rest} treeData={highlightedTreeData} />;
106
+ const handleSearch = useCallback((e) => {
107
+ setSearch(e.target.value);
108
+ }, []);
109
+
110
+ const searchExpandKeysProps = useMemo(() => {
111
+ if (!debouncedSearch) {
112
+ return {};
113
+ }
114
+
115
+ const keys: string[] = [];
116
+ function loop(arr) {
117
+ arr.forEach((item) => {
118
+ keys.push(item.key);
119
+ if (item.children) {
120
+ loop(item.children);
121
+ }
122
+ });
123
+ }
124
+ loop(newTreeData);
125
+
126
+ return { expandedKeys: keys };
127
+ }, [debouncedSearch, newTreeData]);
128
+
129
+ const node = <AntdTree {...searchExpandKeysProps} {...rest} treeData={newTreeData} />;
106
130
 
107
131
  if (!enableSearch) {
108
132
  return node;
@@ -114,11 +138,7 @@ function Tree<T extends DataNode>(props: TreeProps<T>) {
114
138
  start={
115
139
  enableSearch && (
116
140
  <div className="px-2 pb-2">
117
- <Input.Search
118
- placeholder="搜索"
119
- value={search}
120
- onChange={(e) => setSearch(e.target.value)}
121
- />
141
+ <Input.Search placeholder="搜索" value={search} onChange={handleSearch} />
122
142
  </div>
123
143
  )
124
144
  }