@snack-uikit/tree 0.11.1-preview-c3fee040.0 → 0.11.1-preview-02fd9f01.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/README.md CHANGED
@@ -90,18 +90,6 @@ function TreeAsyncLoadExample() {
90
90
 
91
91
  [//]: DOCUMENTATION_SECTION_START
92
92
  [//]: THIS_SECTION_IS_AUTOGENERATED_PLEASE_DONT_EDIT_IT
93
- ## getSearchedTreeItems
94
- ### Props
95
- | name | type | default value | description |
96
- |------|------|---------------|-------------|
97
- | tree* | `ExtendedTreeNodeProps[]` | - | |
98
- | searchOptions | `Partial<{ query: string; includeChildrenMatchedParent: boolean; }>` | - | |
99
- ## getSearchedTreeNodeById
100
- ### Props
101
- | name | type | default value | description |
102
- |------|------|---------------|-------------|
103
- | searchOptions* | `{ id: I; includeNested?: boolean; }` | - | |
104
- | tree* | `T[]` | - | |
105
93
  ## Tree
106
94
  ### Props
107
95
  | name | type | default value | description |
@@ -124,8 +112,8 @@ function TreeAsyncLoadExample() {
124
112
  ### Props
125
113
  | name | type | default value | description |
126
114
  |------|------|---------------|-------------|
127
- | __@unscopables@986* | `{ [x: number]: boolean; length?: boolean; toString?: boolean; toLocaleString?: boolean; pop?: boolean; push?: boolean; concat?: boolean; join?: boolean; reverse?: boolean; shift?: boolean; slice?: boolean; sort?: boolean; ... 29 more ...; readonly [Symbol.unscopables]?: boolean; }` | - | Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement. |
128
- | __@iterator@984* | `() => ArrayIterator<TreeNodeProps>` | - | Iterator |
115
+ | __@unscopables@987* | `{ [x: number]: boolean; length?: boolean; toString?: boolean; toLocaleString?: boolean; pop?: boolean; push?: boolean; concat?: boolean; join?: boolean; reverse?: boolean; shift?: boolean; slice?: boolean; sort?: boolean; ... 29 more ...; readonly [Symbol.unscopables]?: boolean; }` | - | Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement. |
116
+ | __@iterator@985* | `() => ArrayIterator<TreeNodeProps>` | - | Iterator |
129
117
  | with* | `(index: number, value: TreeNodeProps) => TreeNodeProps[]` | - | Copies an array, then overwrites the value at the provided index with the given value. If the index is negative, then it replaces from the end of the array. @param index The index of the value to overwrite. If the index is negative, then it replaces from the end of the array. @param value The value to write into the copied array. @returns The copied array with the updated value. |
130
118
  | toSpliced* | `{ (start: number, deleteCount: number, ...items: TreeNodeProps[]): TreeNodeProps[]; (start: number, deleteCount?: number): TreeNodeProps[]; }` | - | Copies an array and removes elements and, if necessary, inserts new elements in their place. Returns the copied array. Copies an array and removes elements while returning the remaining elements. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @param items Elements to insert into the copied array in place of the deleted elements. @returns The copied array. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @returns A copy of the original array with the remaining elements. |
131
119
  | toSorted* | `(compareFn?: (a: TreeNodeProps, b: TreeNodeProps) => number) => TreeNodeProps[]` | - | Returns a copy of an array with its elements sorted. @param compareFn Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order. ```ts [11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22] ``` |
@@ -188,8 +176,8 @@ function TreeAsyncLoadExample() {
188
176
  ### Props
189
177
  | name | type | default value | description |
190
178
  |------|------|---------------|-------------|
191
- | __@unscopables@986* | `{ [x: number]: boolean; length?: boolean; toString?: boolean; toLocaleString?: boolean; pop?: boolean; push?: boolean; concat?: boolean; join?: boolean; reverse?: boolean; shift?: boolean; slice?: boolean; sort?: boolean; ... 29 more ...; readonly [Symbol.unscopables]?: boolean; }` | - | Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement. |
192
- | __@iterator@984* | `() => ArrayIterator<ExtendedTreeNodeProps>` | - | Iterator |
179
+ | __@unscopables@987* | `{ [x: number]: boolean; length?: boolean; toString?: boolean; toLocaleString?: boolean; pop?: boolean; push?: boolean; concat?: boolean; join?: boolean; reverse?: boolean; shift?: boolean; slice?: boolean; sort?: boolean; ... 29 more ...; readonly [Symbol.unscopables]?: boolean; }` | - | Is an object whose properties have the value 'true' when they will be absent when used in a 'with' statement. |
180
+ | __@iterator@985* | `() => ArrayIterator<ExtendedTreeNodeProps>` | - | Iterator |
193
181
  | with* | `(index: number, value: ExtendedTreeNodeProps) => ExtendedTreeNodeProps[]` | - | Copies an array, then overwrites the value at the provided index with the given value. If the index is negative, then it replaces from the end of the array. @param index The index of the value to overwrite. If the index is negative, then it replaces from the end of the array. @param value The value to write into the copied array. @returns The copied array with the updated value. |
194
182
  | toSpliced* | `{ (start: number, deleteCount: number, ...items: ExtendedTreeNodeProps[]): ExtendedTreeNodeProps[]; (start: number, deleteCount?: number): ExtendedTreeNodeProps[]; }` | - | Copies an array and removes elements and, if necessary, inserts new elements in their place. Returns the copied array. Copies an array and removes elements while returning the remaining elements. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @param items Elements to insert into the copied array in place of the deleted elements. @returns The copied array. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @returns A copy of the original array with the remaining elements. |
195
183
  | toSorted* | `(compareFn?: (a: ExtendedTreeNodeProps, b: ExtendedTreeNodeProps) => number) => ExtendedTreeNodeProps[]` | - | Returns a copy of an array with its elements sorted. @param compareFn Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, UTF-16 code unit order. ```ts [11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22] ``` |
@@ -229,6 +217,13 @@ function TreeAsyncLoadExample() {
229
217
  | length* | `number` | - | Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
230
218
  | toString | `() => string` | function toString() { [native code] } | Returns a string representation of an array. |
231
219
  | toLocaleString | `{ (): string; (locales: string \| string[], options?: NumberFormatOptions & DateTimeFormatOptions): string; }` | function toLocaleString() { [native code] } | Returns a string representation of an array. The elements are converted to string using their toLocaleString methods. |
220
+ ## traverseWithTarget
221
+ BFS с указанием целевого списка для каждого узла.
222
+ Очередь хранит (node, depth, targetList). Callback добавляет узел в targetList
223
+ и возвращает массив для детей (или undefined, чтобы не обходить детей).
224
+ ### Props
225
+ | name | type | default value | description |
226
+ |------|------|---------------|-------------|
232
227
 
233
228
 
234
229
  [//]: DOCUMENTATION_SECTION_END
@@ -175,7 +175,8 @@ const mapNodeToRecordItem = node => ({
175
175
  });
176
176
  yield (0, react_1.waitFor)(() => {
177
177
  (0, vitest_1.expect)(onSearch).toHaveBeenCalledWith({
178
- search: 'query'
178
+ search: 'query',
179
+ expandedNodes: ['expandable-root']
179
180
  }, vitest_1.expect.any(AbortSignal));
180
181
  (0, vitest_1.expect)(onPreloadNodes).toHaveBeenCalledWith(['expandable-root', 'external-root'], vitest_1.expect.any(AbortSignal));
181
182
  });
@@ -213,7 +214,8 @@ const mapNodeToRecordItem = node => ({
213
214
  });
214
215
  yield (0, react_1.waitFor)(() => {
215
216
  (0, vitest_1.expect)(onSearch).toHaveBeenCalledWith({
216
- search: 'query'
217
+ search: 'query',
218
+ expandedNodes: []
217
219
  }, vitest_1.expect.any(AbortSignal));
218
220
  (0, vitest_1.expect)(result.current.tree.current).toEqual([createParent('root-node', [createLeaf('child-node')])]);
219
221
  });
@@ -5,6 +5,7 @@ export type SearchResult<TTreeNode extends TreeNodeProps> = {
5
5
  };
6
6
  export type SearchParams = {
7
7
  search: string;
8
+ expandedNodes: string[];
8
9
  };
9
10
  type UseSearchableTreeParams<TRecordValue, TTreeNode extends TreeNodeProps> = {
10
11
  initTree: TTreeNode[];
@@ -84,7 +84,8 @@ function useSearchableTree(_ref) {
84
84
  const abortController = new AbortController();
85
85
  searchAbortControllerRef.current = abortController;
86
86
  const searchPromise = (0, cancelable_promise_1.cancelable)(onSearch({
87
- search: searchQuery
87
+ search: searchQuery,
88
+ expandedNodes: expandedNodes.current
88
89
  }, abortController.signal));
89
90
  searchPromiseRef.current = searchPromise;
90
91
  try {
@@ -122,7 +122,7 @@ describe('useSearchableTree', () => {
122
122
  result.current.search.onChange('query');
123
123
  });
124
124
  yield waitFor(() => {
125
- expect(onSearch).toHaveBeenCalledWith({ search: 'query' }, expect.any(AbortSignal));
125
+ expect(onSearch).toHaveBeenCalledWith({ search: 'query', expandedNodes: ['expandable-root'] }, expect.any(AbortSignal));
126
126
  expect(onPreloadNodes).toHaveBeenCalledWith(['expandable-root', 'external-root'], expect.any(AbortSignal));
127
127
  });
128
128
  expect(result.current.tree.current).toEqual([
@@ -153,7 +153,7 @@ describe('useSearchableTree', () => {
153
153
  result.current.search.onChange('query');
154
154
  });
155
155
  yield waitFor(() => {
156
- expect(onSearch).toHaveBeenCalledWith({ search: 'query' }, expect.any(AbortSignal));
156
+ expect(onSearch).toHaveBeenCalledWith({ search: 'query', expandedNodes: [] }, expect.any(AbortSignal));
157
157
  expect(result.current.tree.current).toEqual([createParent('root-node', [createLeaf('child-node')])]);
158
158
  });
159
159
  expect(result.current.expandedNodes.current).toEqual([]);
@@ -5,6 +5,7 @@ export type SearchResult<TTreeNode extends TreeNodeProps> = {
5
5
  };
6
6
  export type SearchParams = {
7
7
  search: string;
8
+ expandedNodes: string[];
8
9
  };
9
10
  type UseSearchableTreeParams<TRecordValue, TTreeNode extends TreeNodeProps> = {
10
11
  initTree: TTreeNode[];
@@ -48,7 +48,7 @@ export function useSearchableTree({ initTree, onPreloadNode, onPreloadNodes, onS
48
48
  setLoading(true);
49
49
  const abortController = new AbortController();
50
50
  searchAbortControllerRef.current = abortController;
51
- const searchPromise = cancelable(onSearch({ search: searchQuery }, abortController.signal));
51
+ const searchPromise = cancelable(onSearch({ search: searchQuery, expandedNodes: expandedNodes.current }, abortController.signal));
52
52
  searchPromiseRef.current = searchPromise;
53
53
  try {
54
54
  const { tree: searchedTree, needPreloadNodes } = yield searchPromise;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Tree",
7
- "version": "0.11.1-preview-c3fee040.0",
7
+ "version": "0.11.1-preview-02fd9f01.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -66,5 +66,5 @@
66
66
  "react-transition-state": "2.1.1",
67
67
  "uncontrollable": "8.0.4"
68
68
  },
69
- "gitHead": "4aa46f03f56e45a92f8d7cbf49d91bcc7ae130cb"
69
+ "gitHead": "21fc47703dee986985b9c28cc94b94983ebfd4ef"
70
70
  }
@@ -152,7 +152,10 @@ describe('useSearchableTree', () => {
152
152
  });
153
153
 
154
154
  await waitFor(() => {
155
- expect(onSearch).toHaveBeenCalledWith({ search: 'query' }, expect.any(AbortSignal));
155
+ expect(onSearch).toHaveBeenCalledWith(
156
+ { search: 'query', expandedNodes: ['expandable-root'] },
157
+ expect.any(AbortSignal),
158
+ );
156
159
  expect(onPreloadNodes).toHaveBeenCalledWith(['expandable-root', 'external-root'], expect.any(AbortSignal));
157
160
  });
158
161
  expect(result.current.tree.current).toEqual([
@@ -187,7 +190,7 @@ describe('useSearchableTree', () => {
187
190
  });
188
191
 
189
192
  await waitFor(() => {
190
- expect(onSearch).toHaveBeenCalledWith({ search: 'query' }, expect.any(AbortSignal));
193
+ expect(onSearch).toHaveBeenCalledWith({ search: 'query', expandedNodes: [] }, expect.any(AbortSignal));
191
194
  expect(result.current.tree.current).toEqual([createParent('root-node', [createLeaf('child-node')])]);
192
195
  });
193
196
 
@@ -12,6 +12,7 @@ export type SearchResult<TTreeNode extends TreeNodeProps> = {
12
12
 
13
13
  export type SearchParams = {
14
14
  search: string;
15
+ expandedNodes: string[];
15
16
  };
16
17
 
17
18
  type UseSearchableTreeParams<TRecordValue, TTreeNode extends TreeNodeProps> = {
@@ -87,7 +88,9 @@ export function useSearchableTree<TRecordValue, TTreeNode extends TreeNodeProps>
87
88
  const abortController = new AbortController();
88
89
  searchAbortControllerRef.current = abortController;
89
90
 
90
- const searchPromise = cancelable(onSearch({ search: searchQuery }, abortController.signal));
91
+ const searchPromise = cancelable(
92
+ onSearch({ search: searchQuery, expandedNodes: expandedNodes.current }, abortController.signal),
93
+ );
91
94
  searchPromiseRef.current = searchPromise;
92
95
 
93
96
  try {