@snack-uikit/tree 0.11.1-preview-c3fee040.0 → 0.11.1-preview-210b4b95.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.
Files changed (101) hide show
  1. package/README.md +84 -95
  2. package/dist/cjs/helpers/__tests__/updateTreeNode.spec.js +200 -0
  3. package/dist/cjs/helpers/checkNestedNodesSelection.d.ts +7 -0
  4. package/dist/cjs/helpers/checkNestedNodesSelection.js +7 -0
  5. package/dist/cjs/helpers/collectEmptyNestedNodesInExpanded.d.ts +7 -0
  6. package/dist/cjs/helpers/collectEmptyNestedNodesInExpanded.js +7 -0
  7. package/dist/cjs/helpers/collectIds.d.ts +8 -1
  8. package/dist/cjs/helpers/collectIds.js +10 -4
  9. package/dist/cjs/helpers/extractTreeNodeTitle.d.ts +4 -0
  10. package/dist/cjs/helpers/extractTreeNodeTitle.js +4 -0
  11. package/dist/cjs/helpers/findAllChildNodeIds.d.ts +7 -0
  12. package/dist/cjs/helpers/findAllChildNodeIds.js +7 -0
  13. package/dist/cjs/helpers/findAllExpandedChildNodeIds.d.ts +6 -0
  14. package/dist/cjs/helpers/findAllExpandedChildNodeIds.js +6 -0
  15. package/dist/cjs/helpers/getSearchedTreeItems.d.ts +6 -0
  16. package/dist/cjs/helpers/getSearchedTreeItems.js +6 -0
  17. package/dist/cjs/helpers/getSearchedTreeNodeById.d.ts +8 -0
  18. package/dist/cjs/helpers/getSearchedTreeNodeById.js +8 -0
  19. package/dist/cjs/helpers/index.d.ts +5 -2
  20. package/dist/cjs/helpers/index.js +5 -2
  21. package/dist/cjs/helpers/lookupTreeForSelectedNodes.d.ts +7 -0
  22. package/dist/cjs/helpers/lookupTreeForSelectedNodes.js +7 -0
  23. package/dist/cjs/helpers/sortTreeItemsByTitle.d.ts +12 -1
  24. package/dist/cjs/helpers/sortTreeItemsByTitle.js +8 -4
  25. package/dist/cjs/helpers/traverse.d.ts +5 -5
  26. package/dist/cjs/helpers/traverse.js +8 -38
  27. package/dist/cjs/helpers/traverseWithTarget.d.ts +11 -0
  28. package/dist/cjs/helpers/traverseWithTarget.js +52 -0
  29. package/dist/cjs/helpers/updateTreeNode.d.ts +13 -0
  30. package/dist/cjs/helpers/updateTreeNode.js +36 -0
  31. package/dist/cjs/hooks/__tests__/useSearchableTree.spec.js +4 -2
  32. package/dist/cjs/hooks/__tests__/useTreeMultiSelection.spec.js +39 -18
  33. package/dist/cjs/hooks/useSearchableTree.d.ts +24 -0
  34. package/dist/cjs/hooks/useSearchableTree.js +20 -3
  35. package/dist/cjs/hooks/useTreeMultiSelection.d.ts +21 -0
  36. package/dist/cjs/hooks/useTreeMultiSelection.js +10 -0
  37. package/dist/esm/helpers/__tests__/updateTreeNode.spec.js +101 -0
  38. package/dist/esm/helpers/checkNestedNodesSelection.d.ts +7 -0
  39. package/dist/esm/helpers/checkNestedNodesSelection.js +7 -0
  40. package/dist/esm/helpers/collectEmptyNestedNodesInExpanded.d.ts +7 -0
  41. package/dist/esm/helpers/collectEmptyNestedNodesInExpanded.js +7 -0
  42. package/dist/esm/helpers/collectIds.d.ts +8 -1
  43. package/dist/esm/helpers/collectIds.js +9 -2
  44. package/dist/esm/helpers/extractTreeNodeTitle.d.ts +4 -0
  45. package/dist/esm/helpers/extractTreeNodeTitle.js +5 -1
  46. package/dist/esm/helpers/findAllChildNodeIds.d.ts +7 -0
  47. package/dist/esm/helpers/findAllChildNodeIds.js +7 -0
  48. package/dist/esm/helpers/findAllExpandedChildNodeIds.d.ts +6 -0
  49. package/dist/esm/helpers/findAllExpandedChildNodeIds.js +6 -0
  50. package/dist/esm/helpers/getSearchedTreeItems.d.ts +6 -0
  51. package/dist/esm/helpers/getSearchedTreeItems.js +6 -0
  52. package/dist/esm/helpers/getSearchedTreeNodeById.d.ts +8 -0
  53. package/dist/esm/helpers/getSearchedTreeNodeById.js +8 -0
  54. package/dist/esm/helpers/index.d.ts +5 -2
  55. package/dist/esm/helpers/index.js +5 -2
  56. package/dist/esm/helpers/lookupTreeForSelectedNodes.d.ts +7 -0
  57. package/dist/esm/helpers/lookupTreeForSelectedNodes.js +7 -0
  58. package/dist/esm/helpers/sortTreeItemsByTitle.d.ts +12 -1
  59. package/dist/esm/helpers/sortTreeItemsByTitle.js +8 -4
  60. package/dist/esm/helpers/traverse.d.ts +5 -5
  61. package/dist/esm/helpers/traverse.js +6 -24
  62. package/dist/esm/helpers/traverseWithTarget.d.ts +11 -0
  63. package/dist/esm/helpers/traverseWithTarget.js +29 -0
  64. package/dist/esm/helpers/updateTreeNode.d.ts +13 -0
  65. package/dist/esm/helpers/updateTreeNode.js +28 -0
  66. package/dist/esm/hooks/__tests__/useSearchableTree.spec.js +2 -2
  67. package/dist/esm/hooks/__tests__/useTreeMultiSelection.spec.js +16 -7
  68. package/dist/esm/hooks/useSearchableTree.d.ts +24 -0
  69. package/dist/esm/hooks/useSearchableTree.js +16 -4
  70. package/dist/esm/hooks/useTreeMultiSelection.d.ts +21 -0
  71. package/dist/esm/hooks/useTreeMultiSelection.js +10 -0
  72. package/package.json +2 -2
  73. package/src/helpers/__tests__/updateTreeNode.spec.ts +130 -0
  74. package/src/helpers/checkNestedNodesSelection.ts +7 -0
  75. package/src/helpers/collectEmptyNestedNodesInExpanded.ts +7 -0
  76. package/src/helpers/collectIds.ts +9 -2
  77. package/src/helpers/extractTreeNodeTitle.ts +5 -1
  78. package/src/helpers/findAllChildNodeIds.ts +7 -0
  79. package/src/helpers/findAllExpandedChildNodeIds.ts +6 -0
  80. package/src/helpers/getSearchedTreeItems.ts +6 -0
  81. package/src/helpers/getSearchedTreeNodeById.ts +8 -0
  82. package/src/helpers/index.ts +5 -2
  83. package/src/helpers/lookupTreeForSelectedNodes.ts +7 -0
  84. package/src/helpers/sortTreeItemsByTitle.ts +19 -4
  85. package/src/helpers/traverse.ts +6 -37
  86. package/src/helpers/traverseWithTarget.ts +44 -0
  87. package/src/helpers/updateTreeNode.ts +47 -0
  88. package/src/hooks/__tests__/useSearchableTree.spec.ts +5 -2
  89. package/src/hooks/__tests__/useTreeMultiSelection.spec.ts +24 -10
  90. package/src/hooks/useSearchableTree.ts +30 -4
  91. package/src/hooks/useTreeMultiSelection.ts +21 -0
  92. package/dist/cjs/helpers/__tests__/setChildrenOfTreeNode.spec.js +0 -102
  93. package/dist/cjs/helpers/setChildrenOfTreeNode.d.ts +0 -2
  94. package/dist/cjs/helpers/setChildrenOfTreeNode.js +0 -28
  95. package/dist/esm/helpers/__tests__/setChildrenOfTreeNode.spec.js +0 -50
  96. package/dist/esm/helpers/setChildrenOfTreeNode.d.ts +0 -2
  97. package/dist/esm/helpers/setChildrenOfTreeNode.js +0 -20
  98. package/src/helpers/__tests__/setChildrenOfTreeNode.spec.ts +0 -68
  99. package/src/helpers/setChildrenOfTreeNode.ts +0 -30
  100. /package/dist/cjs/helpers/__tests__/{setChildrenOfTreeNode.spec.d.ts → updateTreeNode.spec.d.ts} +0 -0
  101. /package/dist/esm/helpers/__tests__/{setChildrenOfTreeNode.spec.d.ts → updateTreeNode.spec.d.ts} +0 -0
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 |
@@ -120,115 +108,116 @@ function TreeAsyncLoadExample() {
120
108
  | selected | `string \| string[]` | - | Состояние для выбраных элементов: <br> - При <strong>selectionMode</strong>=`Multi` - принимает массив строк <br> - При <strong>selectionMode</strong>=`Single` - принимает строку |
121
109
  | onSelect | `((selectedKeys: string[], node: TreeNodeProps) => void) \| ((selectedKey: string, node: TreeNodeProps) => void)` | - | Колбэк при изменении выбраных элементов: <br> - При <strong>selectionMode</strong>=`Multi` - возвращает массив строк <br> - При <strong>selectionMode</strong>=`Single` - возвращает строку |
122
110
  | showToggle | `boolean` | - | |
111
+ ## checkNestedNodesSelection
112
+ Проверяет состояние выбора дочерних узлов:
113
+ выбраны ли все, выбраны ли некоторые.
114
+ ### Props
115
+ | name | type | default value | description |
116
+ |------|------|---------------|-------------|
117
+ ## collectEmptyNestedNodesInExpanded
118
+ Возвращает раскрытые узлы, у которых `nested` уже существует, но пока пустой.
119
+ Используется для определения узлов, требующих дополнительной подгрузки детей.
120
+ ### Props
121
+ | name | type | default value | description |
122
+ |------|------|---------------|-------------|
123
123
  ## collectIds
124
+ `collectIds`
125
+
126
+ Собирает id всех узлов дерева.
127
+ ## extractTreeNodeTitle
128
+ Возвращает строковый заголовок узла дерева.
129
+ Если title задан функцией, использует getTitle (если он доступен).
130
+ ### Props
131
+ | name | type | default value | description |
132
+ |------|------|---------------|-------------|
133
+ | title* | `((value: Pick<BaseTreeNode, "id" \| "disabled">) => ReactNode) \| ((string \| ((value: Pick<BaseTreeNode, "id" \| "disabled">) => ReactNode)) & (string \| ((value: Pick<...>) => ReactNode)))` | - | Имя элемента |
134
+ | id* | `string` | - | Идентификатор элемента |
135
+ | disabled | `boolean` | - | Является ли элемент деактивированным |
136
+ | onClick | `MouseEventHandler` | - | Обработчик клика по элементу |
137
+ | className | `string` | - | CSS-класс |
138
+ | href | `string` | - | Ссылка на элемент |
139
+ | icon | `ReactNode` | - | Иконка дочернего элемента |
140
+ | nested | `(ChildTreeNode \| ParentTreeNode)[]` | - | Вложенные элементы дерева |
141
+ | expandedIcon | `ReactNode` | - | Иконка элемента-родителя в открытом состоянии |
142
+ | collapsedIcon | `ReactNode` | - | Иконка элемента-родителя в закрытом состоянии |
143
+ | getTitle | `() => void` | - | |
144
+ ## findAllChildNodeIds
145
+ `findAllChildNodeIds`
146
+
147
+ Собирает id всех недеактивированных узлов в поддереве.
148
+ ## findAllExpandedChildNodeIds
149
+ Возвращает id узлов в поддереве, проходя только по раскрытым веткам.
124
150
  ### Props
125
151
  | name | type | default value | description |
126
152
  |------|------|---------------|-------------|
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 |
129
- | 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
- | 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
- | 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] ``` |
132
- | toReversed* | `() => TreeNodeProps[]` | - | Returns a copy of an array with its elements reversed. |
133
- | findLastIndex* | `(predicate: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => unknown, thisArg?: any) => number` | - | Returns the index of the last element in the array where predicate is true, and -1 otherwise. @param predicate findLastIndex calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
134
- | findLast* | `{ <S extends TreeNodeProps>(predicate: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => value is S, thisArg?: any): S; (predicate: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => unknown, thisArg?: any): TreeNodeProps; }` | - | Returns the value of the last element in the array where predicate is true, and undefined otherwise. @param predicate findLast calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLast immediately returns that element value. Otherwise, findLast returns undefined. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
135
- | at* | `(index: number) => TreeNodeProps` | - | Returns the item located at the specified index. @param index The zero-based index of the desired code unit. A negative index will count back from the last item. |
136
- | flat* | `<A, D extends number = 1>(this: A, depth?: D) => FlatArray<A, D>[]` | - | Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth. @param depth The maximum recursion depth |
137
- | flatMap* | `<U, This = undefined>(callback: (this: This, value: TreeNodeProps, index: number, array: TreeNodeProps[]) => U \| readonly U[], thisArg?: This) => U[]` | - | Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1. @param callback A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value. |
138
- | includes* | `(searchElement: TreeNodeProps, fromIndex?: number) => boolean` | - | Determines whether an array includes a certain element, returning true or false as appropriate. @param searchElement The element to search for. @param fromIndex The position in this array at which to begin searching for searchElement. |
139
- | values* | `() => ArrayIterator<TreeNodeProps>` | - | Returns an iterable of values in the array |
140
- | keys* | `() => ArrayIterator<number>` | - | Returns an iterable of keys in the array |
141
- | entries* | `() => ArrayIterator<[number, TreeNodeProps]>` | - | Returns an iterable of key, value pairs for every entry in the array |
142
- | copyWithin* | `(target: number, start: number, end?: number) => TreeNodeProps[]` | - | Returns the this object after copying a section of the array identified by start and end to the same array starting at position target @param target If target is negative, it is treated as length+target where length is the length of the array. @param start If start is negative, it is treated as length+start. If end is negative, it is treated as length+end. @param end If not specified, length of the this object is used as its default value. |
143
- | fill* | `(value: TreeNodeProps, start?: number, end?: number) => TreeNodeProps[]` | - | Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @param value value to fill array section with @param start index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array. @param end index to stop filling the array at. If end is negative, it is treated as length+end. |
144
- | findIndex* | `(predicate: (value: TreeNodeProps, index: number, obj: TreeNodeProps[]) => unknown, thisArg?: any) => number` | - | Returns the index of the first element in the array where predicate is true, and -1 otherwise. @param predicate find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
145
- | find* | `{ <S extends TreeNodeProps>(predicate: (value: TreeNodeProps, index: number, obj: TreeNodeProps[]) => value is S, thisArg?: any): S; (predicate: (value: TreeNodeProps, index: number, obj: TreeNodeProps[]) => unknown, thisArg?: any): TreeNodeProps; }` | - | Returns the value of the first element in the array where predicate is true, and undefined otherwise. @param predicate find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
146
- | reduceRight* | `{ (callbackfn: (previousValue: TreeNodeProps, currentValue: TreeNodeProps, currentIndex: number, array: TreeNodeProps[]) => TreeNodeProps): TreeNodeProps; (callbackfn: (previousValue: TreeNodeProps, currentValue: TreeNodeProps, currentIndex: number, array: TreeNodeProps[]) => TreeNodeProps, initialValue: TreeNodePro...` | - | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. |
147
- | reduce* | `{ (callbackfn: (previousValue: TreeNodeProps, currentValue: TreeNodeProps, currentIndex: number, array: TreeNodeProps[]) => TreeNodeProps): TreeNodeProps; (callbackfn: (previousValue: TreeNodeProps, currentValue: TreeNodeProps, currentIndex: number, array: TreeNodeProps[]) => TreeNodeProps, initialValue: TreeNodePro...` | - | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. |
148
- | filter* | `{ <S extends TreeNodeProps>(predicate: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => value is S, thisArg?: any): S[]; (predicate: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => unknown, thisArg?: any): TreeNodeProps[]; }` | - | Returns the elements of an array that meet the condition specified in a callback function. @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
149
- | map* | `<U>(callbackfn: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => U, thisArg?: any) => U[]` | - | Calls a defined callback function on each element of an array, and returns an array that contains the results. @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
150
- | forEach* | `(callbackfn: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => void, thisArg?: any) => void` | - | Performs the specified action for each element in an array. @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
151
- | some* | `(predicate: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => unknown, thisArg?: any) => boolean` | - | Determines whether the specified callback function returns true for any element of an array. @param predicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
152
- | every* | `{ <S extends TreeNodeProps>(predicate: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: TreeNodeProps, index: number, array: TreeNodeProps[]) => unknown, thisArg?: any): boolean; }` | - | Determines whether all the members of an array satisfy the specified test. @param predicate A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. @param predicate A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
153
- | lastIndexOf* | `(searchElement: TreeNodeProps, fromIndex?: number) => number` | - | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. @param searchElement The value to locate in the array. @param fromIndex The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array. |
154
- | indexOf* | `(searchElement: TreeNodeProps, fromIndex?: number) => number` | - | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. @param searchElement The value to locate in the array. @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. |
155
- | unshift* | `(...items: TreeNodeProps[]) => number` | - | Inserts new elements at the start of an array, and returns the new length of the array. @param items Elements to insert at the start of the array. |
156
- | splice* | `{ (start: number, deleteCount?: number): TreeNodeProps[]; (start: number, deleteCount: number, ...items: TreeNodeProps[]): TreeNodeProps[]; }` | - | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. Omitting this argument will remove all elements from the start paramater location to end of the array. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements. @returns An array containing the elements that were deleted. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements. @param items Elements to insert into the array in place of the deleted elements. @returns An array containing the elements that were deleted. |
157
- | sort* | `(compareFn?: (a: TreeNodeProps, b: TreeNodeProps) => number) => TreeNodeProps[]` | - | Sorts an array in place. This method mutates the array and returns a reference to the same array. @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].sort((a, b) => a - b) ``` |
158
- | slice* | `(start?: number, end?: number) => TreeNodeProps[]` | - | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. @param start The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0. @param end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array. |
159
- | shift* | `() => TreeNodeProps` | - | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
160
- | reverse* | `() => TreeNodeProps[]` | - | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. |
161
- | join* | `(separator?: string) => string` | - | Adds all the elements of an array into a string, separated by the specified separator string. @param separator A string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma. |
162
- | concat* | `{ (...items: ConcatArray<TreeNodeProps>[]): TreeNodeProps[]; (...items: (TreeNodeProps \| ConcatArray<TreeNodeProps>)[]): TreeNodeProps[]; }` | - | Combines two or more arrays. This method returns a new array without modifying any existing arrays. @param items Additional arrays and/or items to add to the end of the array. @param items Additional arrays and/or items to add to the end of the array. |
163
- | push* | `(...items: TreeNodeProps[]) => number` | - | Appends new elements to the end of an array, and returns the new length of the array. @param items New elements to add to the array. |
164
- | pop* | `() => TreeNodeProps` | - | Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
165
- | length* | `number` | - | Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
166
- | toString | `() => string` | function toString() { [native code] } | Returns a string representation of an array. |
167
- | 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. |
168
153
  ## getSearchedTreeItems
154
+ Фильтрует дерево по поисковой строке с сохранением иерархии подходящих узлов.
169
155
  ### Props
170
156
  | name | type | default value | description |
171
157
  |------|------|---------------|-------------|
172
158
  | tree* | `ExtendedTreeNodeProps[]` | - | |
173
159
  | searchOptions | `Partial<{ query: string; includeChildrenMatchedParent: boolean; }>` | - | |
174
160
  ## getSearchedTreeNodeById
161
+ Ищет узлы дерева по одному id или по массиву id.
175
162
  ### Props
176
163
  | name | type | default value | description |
177
164
  |------|------|---------------|-------------|
178
165
  | searchOptions* | `{ id: I; includeNested?: boolean; }` | - | |
179
166
  | tree* | `T[]` | - | |
180
167
  ## lookupTreeForSelectedNodes
168
+ Пересчитывает выбранные узлы для режима мультивыбора в дереве.
169
+ Учитывает потомков текущего узла и корректирует состояние предков.
181
170
  ### Props
182
171
  | name | type | default value | description |
183
172
  |------|------|---------------|-------------|
184
173
  | selectedNodes* | `string[]` | - | |
185
174
  | node* | `Pick<TreeNodeProps, "id" \| "disabled" \| "nested">` | - | |
186
175
  | parentNode | `ParentNode` | - | |
187
- ## sortTreeItemsByTitle
176
+ ## traverse
177
+ Обходит дерево в ширину (BFS) и вызывает callback для каждого узла.
178
+ ### Props
179
+ | name | type | default value | description |
180
+ |------|------|---------------|-------------|
181
+ ## traverseWithTarget
182
+ Обходит дерево в ширину (BFS), передавая каждому узлу список,
183
+ в который должен быть добавлен его трансформированный результат.
184
+ ### Props
185
+ | name | type | default value | description |
186
+ |------|------|---------------|-------------|
187
+ ## updateTreeNode
188
+ Возвращает копию дерева, где у узла с указанным id обновляются переданные поля.
189
+ ### Props
190
+ | name | type | default value | description |
191
+ |------|------|---------------|-------------|
192
+ ## useSearchableTree
193
+ Хук для работы с деревом, поддерживающим поиск и асинхронную подгрузку узлов.
194
+
195
+ Возможности:
196
+ - хранение актуального дерева и записи элементов (`treeItemsRecord`);
197
+ - управление раскрытыми узлами;
198
+ - дебаунс-поиск с отменой предыдущего запроса;
199
+ - дозагрузка дочерних узлов после поиска или раскрытия.
200
+ ### Props
201
+ | name | type | default value | description |
202
+ |------|------|---------------|-------------|
203
+ | mapNodeToRecordItem* | `(node: TTreeNode) => TRecordValue` | - | Сопоставление узла с элементом записи `treeItemsRecord` (по `node.id`). |
204
+ | onSearch* | `(params: SearchParams, signal?: AbortSignal) => Promise<SearchResult<TTreeNode>>` | - | Поиск по дереву. |
205
+ | onPreloadNodes* | `(nodes: string[], signal?: AbortSignal) => Promise<Record<string, TTreeNode[]>>` | - | Пакетная подгрузка детей по id родителей. |
206
+ | onPreloadNode* | `(node: TreeNodeProps) => Promise<TTreeNode[]>` | - | Подгрузка дочерних узлов для одного узла. |
207
+ | initTree* | `TTreeNode[]` | - | Начальное дерево узлов. |
208
+ ## useTreeMultiSelection
209
+ Хук мультивыбора для дерева.
210
+
211
+ Выполняет пересчет выбранных id после клика по узлу, поддерживает
212
+ controlled/uncontrolled режим (`selected` + `onChangeSelected`) и при необходимости
213
+ подгружает детей узла перед вычислением итогового выбора.
188
214
  ### Props
189
215
  | name | type | default value | description |
190
216
  |------|------|---------------|-------------|
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 |
193
- | 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
- | 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
- | 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] ``` |
196
- | toReversed* | `() => ExtendedTreeNodeProps[]` | - | Returns a copy of an array with its elements reversed. |
197
- | findLastIndex* | `(predicate: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => unknown, thisArg?: any) => number` | - | Returns the index of the last element in the array where predicate is true, and -1 otherwise. @param predicate findLastIndex calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
198
- | findLast* | `{ <S extends ExtendedTreeNodeProps>(predicate: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => value is S, thisArg?: any): S; (predicate: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => unknown, thisArg?: any): ExtendedTreeNodeProps; }` | - | Returns the value of the last element in the array where predicate is true, and undefined otherwise. @param predicate findLast calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLast immediately returns that element value. Otherwise, findLast returns undefined. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
199
- | at* | `(index: number) => ExtendedTreeNodeProps` | - | Returns the item located at the specified index. @param index The zero-based index of the desired code unit. A negative index will count back from the last item. |
200
- | flat* | `<A, D extends number = 1>(this: A, depth?: D) => FlatArray<A, D>[]` | - | Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth. @param depth The maximum recursion depth |
201
- | flatMap* | `<U, This = undefined>(callback: (this: This, value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => U \| readonly U[], thisArg?: This) => U[]` | - | Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1. @param callback A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value. |
202
- | includes* | `(searchElement: ExtendedTreeNodeProps, fromIndex?: number) => boolean` | - | Determines whether an array includes a certain element, returning true or false as appropriate. @param searchElement The element to search for. @param fromIndex The position in this array at which to begin searching for searchElement. |
203
- | values* | `() => ArrayIterator<ExtendedTreeNodeProps>` | - | Returns an iterable of values in the array |
204
- | keys* | `() => ArrayIterator<number>` | - | Returns an iterable of keys in the array |
205
- | entries* | `() => ArrayIterator<[number, ExtendedTreeNodeProps]>` | - | Returns an iterable of key, value pairs for every entry in the array |
206
- | copyWithin* | `(target: number, start: number, end?: number) => ExtendedTreeNodeProps[]` | - | Returns the this object after copying a section of the array identified by start and end to the same array starting at position target @param target If target is negative, it is treated as length+target where length is the length of the array. @param start If start is negative, it is treated as length+start. If end is negative, it is treated as length+end. @param end If not specified, length of the this object is used as its default value. |
207
- | fill* | `(value: ExtendedTreeNodeProps, start?: number, end?: number) => ExtendedTreeNodeProps[]` | - | Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @param value value to fill array section with @param start index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array. @param end index to stop filling the array at. If end is negative, it is treated as length+end. |
208
- | findIndex* | `(predicate: (value: ExtendedTreeNodeProps, index: number, obj: ExtendedTreeNodeProps[]) => unknown, thisArg?: any) => number` | - | Returns the index of the first element in the array where predicate is true, and -1 otherwise. @param predicate find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
209
- | find* | `{ <S extends ExtendedTreeNodeProps>(predicate: (value: ExtendedTreeNodeProps, index: number, obj: ExtendedTreeNodeProps[]) => value is S, thisArg?: any): S; (predicate: (value: ExtendedTreeNodeProps, index: number, obj: ExtendedTreeNodeProps[]) => unknown, thisArg?: any): ExtendedTreeNodeProps; }` | - | Returns the value of the first element in the array where predicate is true, and undefined otherwise. @param predicate find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
210
- | reduceRight* | `{ (callbackfn: (previousValue: ExtendedTreeNodeProps, currentValue: ExtendedTreeNodeProps, currentIndex: number, array: ExtendedTreeNodeProps[]) => ExtendedTreeNodeProps): ExtendedTreeNodeProps; (callbackfn: (previousValue: ExtendedTreeNodeProps, currentValue: ExtendedTreeNodeProps, currentIndex: number, array: Exte...` | - | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. |
211
- | reduce* | `{ (callbackfn: (previousValue: ExtendedTreeNodeProps, currentValue: ExtendedTreeNodeProps, currentIndex: number, array: ExtendedTreeNodeProps[]) => ExtendedTreeNodeProps): ExtendedTreeNodeProps; (callbackfn: (previousValue: ExtendedTreeNodeProps, currentValue: ExtendedTreeNodeProps, currentIndex: number, array: Exte...` | - | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. |
212
- | filter* | `{ <S extends ExtendedTreeNodeProps>(predicate: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => value is S, thisArg?: any): S[]; (predicate: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => unknown, thisArg?: any): ExtendedTreeNodeProps[]; }` | - | Returns the elements of an array that meet the condition specified in a callback function. @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
213
- | map* | `<U>(callbackfn: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => U, thisArg?: any) => U[]` | - | Calls a defined callback function on each element of an array, and returns an array that contains the results. @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
214
- | forEach* | `(callbackfn: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => void, thisArg?: any) => void` | - | Performs the specified action for each element in an array. @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
215
- | some* | `(predicate: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => unknown, thisArg?: any) => boolean` | - | Determines whether the specified callback function returns true for any element of an array. @param predicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
216
- | every* | `{ <S extends ExtendedTreeNodeProps>(predicate: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: ExtendedTreeNodeProps, index: number, array: ExtendedTreeNodeProps[]) => unknown, thisArg?: any): boolean; }` | - | Determines whether all the members of an array satisfy the specified test. @param predicate A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. @param predicate A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
217
- | lastIndexOf* | `(searchElement: ExtendedTreeNodeProps, fromIndex?: number) => number` | - | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. @param searchElement The value to locate in the array. @param fromIndex The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array. |
218
- | indexOf* | `(searchElement: ExtendedTreeNodeProps, fromIndex?: number) => number` | - | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. @param searchElement The value to locate in the array. @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. |
219
- | unshift* | `(...items: ExtendedTreeNodeProps[]) => number` | - | Inserts new elements at the start of an array, and returns the new length of the array. @param items Elements to insert at the start of the array. |
220
- | splice* | `{ (start: number, deleteCount?: number): ExtendedTreeNodeProps[]; (start: number, deleteCount: number, ...items: ExtendedTreeNodeProps[]): ExtendedTreeNodeProps[]; }` | - | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. Omitting this argument will remove all elements from the start paramater location to end of the array. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements. @returns An array containing the elements that were deleted. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements. @param items Elements to insert into the array in place of the deleted elements. @returns An array containing the elements that were deleted. |
221
- | sort* | `(compareFn?: (a: ExtendedTreeNodeProps, b: ExtendedTreeNodeProps) => number) => ExtendedTreeNodeProps[]` | - | Sorts an array in place. This method mutates the array and returns a reference to the same array. @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].sort((a, b) => a - b) ``` |
222
- | slice* | `(start?: number, end?: number) => ExtendedTreeNodeProps[]` | - | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. @param start The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0. @param end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array. |
223
- | shift* | `() => ExtendedTreeNodeProps` | - | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
224
- | reverse* | `() => ExtendedTreeNodeProps[]` | - | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. |
225
- | join* | `(separator?: string) => string` | - | Adds all the elements of an array into a string, separated by the specified separator string. @param separator A string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma. |
226
- | concat* | `{ (...items: ConcatArray<ExtendedTreeNodeProps>[]): ExtendedTreeNodeProps[]; (...items: (ExtendedTreeNodeProps \| ConcatArray<...>)[]): ExtendedTreeNodeProps[]; }` | - | Combines two or more arrays. This method returns a new array without modifying any existing arrays. @param items Additional arrays and/or items to add to the end of the array. @param items Additional arrays and/or items to add to the end of the array. |
227
- | push* | `(...items: ExtendedTreeNodeProps[]) => number` | - | Appends new elements to the end of an array, and returns the new length of the array. @param items New elements to add to the array. |
228
- | pop* | `() => ExtendedTreeNodeProps` | - | Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
229
- | length* | `number` | - | Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
230
- | toString | `() => string` | function toString() { [native code] } | Returns a string representation of an array. |
231
- | 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. |
217
+ | onSelect* | `SelectHandler` | - | Логика мультивыбора: по клику возвращает, какие id добавить и снять. |
218
+ | onDataLoad* | `PreloadNodeHandler<TTreeNode>` | - | Подгрузка дочерних узлов, если у узла есть `nested`, но массив пуст (ленивая загрузка перед выбором). |
219
+ | selected | `string[]` | - | Controlled: текущие выбранные id; без пропа внутреннее состояние хука. |
220
+ | onChangeSelected | `(newSelected: string[]) => void` | - | Вызывается при изменении набора выбранных id (controlled-сценарий). |
232
221
 
233
222
 
234
223
  [//]: DOCUMENTATION_SECTION_END
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ const vitest_1 = require("vitest");
7
+ const updateTreeNode_1 = require("../updateTreeNode");
8
+ const node = (id, nested) => Object.assign({
9
+ id,
10
+ title: id
11
+ }, nested !== undefined && {
12
+ nested
13
+ });
14
+ (0, vitest_1.describe)('updateTreeNode', () => {
15
+ (0, vitest_1.it)('replaces nested for root-level node', () => {
16
+ const tree = [node('a', [{
17
+ id: 'a1',
18
+ title: 'a1'
19
+ }]), node('b', [{
20
+ id: 'b1',
21
+ title: 'b1'
22
+ }])];
23
+ const children = [node('new1'), node('new2')];
24
+ const result = (0, updateTreeNode_1.updateTreeNode)(tree, 'b', {
25
+ nested: children
26
+ });
27
+ (0, vitest_1.expect)(result).toHaveLength(2);
28
+ (0, vitest_1.expect)(result[0]).toMatchObject({
29
+ id: 'a',
30
+ title: 'a',
31
+ nested: [{
32
+ id: 'a1',
33
+ title: 'a1'
34
+ }]
35
+ });
36
+ (0, vitest_1.expect)(result[1]).toMatchObject({
37
+ id: 'b',
38
+ title: 'b',
39
+ nested: [{
40
+ id: 'new1',
41
+ title: 'new1'
42
+ }, {
43
+ id: 'new2',
44
+ title: 'new2'
45
+ }]
46
+ });
47
+ });
48
+ (0, vitest_1.it)('replaces nested for deeply nested node', () => {
49
+ const childWithNested = {
50
+ id: 'child',
51
+ title: 'child',
52
+ nested: [{
53
+ id: 'grand',
54
+ title: 'grand'
55
+ }]
56
+ };
57
+ const tree = [node('root', [childWithNested])];
58
+ const children = [node('replacement')];
59
+ const result = (0, updateTreeNode_1.updateTreeNode)(tree, 'child', {
60
+ nested: children
61
+ });
62
+ const root = result[0];
63
+ (0, vitest_1.expect)(root).toMatchObject({
64
+ id: 'root',
65
+ title: 'root'
66
+ });
67
+ (0, vitest_1.expect)(root.nested).toHaveLength(1);
68
+ (0, vitest_1.expect)(root.nested[0]).toMatchObject({
69
+ id: 'child',
70
+ title: 'child',
71
+ nested: [{
72
+ id: 'replacement',
73
+ title: 'replacement'
74
+ }]
75
+ });
76
+ });
77
+ (0, vitest_1.it)('returns cloned tree when node is not found', () => {
78
+ const tree = [node('a'), node('b')];
79
+ const result = (0, updateTreeNode_1.updateTreeNode)(tree, 'missing', {
80
+ nested: [node('x')]
81
+ });
82
+ (0, vitest_1.expect)(result).toHaveLength(2);
83
+ (0, vitest_1.expect)(result[0]).toMatchObject({
84
+ id: 'a',
85
+ title: 'a'
86
+ });
87
+ (0, vitest_1.expect)(result[1]).toMatchObject({
88
+ id: 'b',
89
+ title: 'b'
90
+ });
91
+ (0, vitest_1.expect)(result).not.toBe(tree);
92
+ });
93
+ (0, vitest_1.it)('returns empty array for empty tree', () => {
94
+ const result = (0, updateTreeNode_1.updateTreeNode)([], 'any', {
95
+ nested: [node('x')]
96
+ });
97
+ (0, vitest_1.expect)(result).toEqual([]);
98
+ });
99
+ (0, vitest_1.it)('sets children for target node that had no nested (leaf)', () => {
100
+ const tree = [node('leaf'), node('other')];
101
+ const children = [node('new1')];
102
+ const result = (0, updateTreeNode_1.updateTreeNode)(tree, 'leaf', {
103
+ nested: children
104
+ });
105
+ (0, vitest_1.expect)(result[0]).toMatchObject({
106
+ id: 'leaf',
107
+ title: 'leaf',
108
+ nested: [{
109
+ id: 'new1',
110
+ title: 'new1'
111
+ }]
112
+ });
113
+ (0, vitest_1.expect)(result[1]).toMatchObject({
114
+ id: 'other',
115
+ title: 'other'
116
+ });
117
+ });
118
+ (0, vitest_1.it)('preserves order of root nodes when target is second', () => {
119
+ const tree = [node('first'), node('second', [{
120
+ id: 's1',
121
+ title: 's1'
122
+ }]), node('third')];
123
+ const children = [node('new1'), node('new2')];
124
+ const result = (0, updateTreeNode_1.updateTreeNode)(tree, 'second', {
125
+ nested: children
126
+ });
127
+ (0, vitest_1.expect)(result.map(n => n.id)).toEqual(['first', 'second', 'third']);
128
+ (0, vitest_1.expect)(result.map(n => n.title)).toEqual(['first', 'second', 'third']);
129
+ (0, vitest_1.expect)(result[1].nested).toHaveLength(2);
130
+ (0, vitest_1.expect)(result[1].nested.map(n => n.id)).toEqual(['new1', 'new2']);
131
+ (0, vitest_1.expect)(result[1].nested.map(n => n.title)).toEqual(['new1', 'new2']);
132
+ });
133
+ (0, vitest_1.it)('updates title without changing nested', () => {
134
+ const tree = [node('a', [{
135
+ id: 'c1',
136
+ title: 'c1'
137
+ }])];
138
+ const result = (0, updateTreeNode_1.updateTreeNode)(tree, 'a', {
139
+ title: 'Renamed root'
140
+ });
141
+ (0, vitest_1.expect)(result[0]).toMatchObject({
142
+ id: 'a',
143
+ title: 'Renamed root',
144
+ nested: [{
145
+ id: 'c1',
146
+ title: 'c1'
147
+ }]
148
+ });
149
+ });
150
+ (0, vitest_1.it)('updates disabled and className without nested in data', () => {
151
+ const tree = [Object.assign(Object.assign({}, node('x')), {
152
+ disabled: false
153
+ }), Object.assign(Object.assign({}, node('y', [{
154
+ id: 'y1',
155
+ title: 'y1'
156
+ }])), {
157
+ className: 'old'
158
+ })];
159
+ const result = (0, updateTreeNode_1.updateTreeNode)(tree, 'x', {
160
+ disabled: true,
161
+ className: 'leaf-updated'
162
+ });
163
+ (0, vitest_1.expect)(result[0]).toMatchObject({
164
+ id: 'x',
165
+ disabled: true,
166
+ className: 'leaf-updated'
167
+ });
168
+ (0, vitest_1.expect)(result[1]).toMatchObject({
169
+ id: 'y',
170
+ title: 'y',
171
+ className: 'old',
172
+ nested: [{
173
+ id: 'y1',
174
+ title: 'y1'
175
+ }]
176
+ });
177
+ });
178
+ (0, vitest_1.it)('applies title and nested together on target node', () => {
179
+ const tree = [node('root', [{
180
+ id: 'c1',
181
+ title: 'c1'
182
+ }])];
183
+ const newChildren = [node('n1'), node('n2')];
184
+ const result = (0, updateTreeNode_1.updateTreeNode)(tree, 'root', {
185
+ title: 'New title',
186
+ nested: newChildren
187
+ });
188
+ (0, vitest_1.expect)(result[0]).toMatchObject({
189
+ id: 'root',
190
+ title: 'New title',
191
+ nested: [{
192
+ id: 'n1',
193
+ title: 'n1'
194
+ }, {
195
+ id: 'n2',
196
+ title: 'n2'
197
+ }]
198
+ });
199
+ });
200
+ });
@@ -1,4 +1,11 @@
1
1
  import { TreeNodeId, TreeNodeProps } from '../types';
2
+ /**
3
+ * Проверяет состояние выбора дочерних узлов:
4
+ * выбраны ли все, выбраны ли некоторые.
5
+ *
6
+ * @param nodes Дочерние узлы для проверки.
7
+ * @param selectedKeys Текущий список выбранных id.
8
+ */
2
9
  export declare function checkNestedNodesSelection(nodes: TreeNodeProps[], selectedKeys: TreeNodeId[]): {
3
10
  someSelected: boolean;
4
11
  allSelected: boolean;
@@ -5,6 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.checkNestedNodesSelection = checkNestedNodesSelection;
7
7
  const findAllChildNodeIds_1 = require("./findAllChildNodeIds");
8
+ /**
9
+ * Проверяет состояние выбора дочерних узлов:
10
+ * выбраны ли все, выбраны ли некоторые.
11
+ *
12
+ * @param nodes Дочерние узлы для проверки.
13
+ * @param selectedKeys Текущий список выбранных id.
14
+ */
8
15
  function checkNestedNodesSelection(nodes, selectedKeys) {
9
16
  const allIds = (0, findAllChildNodeIds_1.findAllChildNodeIds)(nodes);
10
17
  const selected = allIds.filter(id => selectedKeys.includes(id));
@@ -1,2 +1,9 @@
1
1
  import { TreeNodeProps } from '../types';
2
+ /**
3
+ * Возвращает раскрытые узлы, у которых `nested` уже существует, но пока пустой.
4
+ * Используется для определения узлов, требующих дополнительной подгрузки детей.
5
+ *
6
+ * @param nodes Узлы дерева для проверки.
7
+ * @param expandedIds Множество id раскрытых узлов.
8
+ */
2
9
  export declare function collectEmptyNestedNodesInExpanded<TTreeNode extends TreeNodeProps>(nodes: TTreeNode[], expandedIds: Set<string>): TTreeNode[];
@@ -5,6 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.collectEmptyNestedNodesInExpanded = collectEmptyNestedNodesInExpanded;
7
7
  const traverse_1 = require("./traverse");
8
+ /**
9
+ * Возвращает раскрытые узлы, у которых `nested` уже существует, но пока пустой.
10
+ * Используется для определения узлов, требующих дополнительной подгрузки детей.
11
+ *
12
+ * @param nodes Узлы дерева для проверки.
13
+ * @param expandedIds Множество id раскрытых узлов.
14
+ */
8
15
  function collectEmptyNestedNodesInExpanded(nodes, expandedIds) {
9
16
  const result = [];
10
17
  (0, traverse_1.traverse)(nodes, node => {
@@ -1,2 +1,9 @@
1
1
  import { TreeNodeProps } from '../types';
2
- export declare const collectIds: (treeNodes: TreeNodeProps[]) => string[];
2
+ /**
3
+ * Собирает id всех узлов дерева.
4
+ *
5
+ * @param treeNodes Узлы дерева для обхода.
6
+ * @returns Массив id узлов в порядке обхода BFS.
7
+ * @function collectIds
8
+ */
9
+ export declare function collectIds(treeNodes: TreeNodeProps[]): string[];
@@ -3,11 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.collectIds = void 0;
6
+ exports.collectIds = collectIds;
7
7
  const traverse_1 = require("./traverse");
8
- const collectIds = treeNodes => {
8
+ /**
9
+ * Собирает id всех узлов дерева.
10
+ *
11
+ * @param treeNodes Узлы дерева для обхода.
12
+ * @returns Массив id узлов в порядке обхода BFS.
13
+ * @function collectIds
14
+ */
15
+ function collectIds(treeNodes) {
9
16
  const ids = [];
10
17
  (0, traverse_1.traverse)(treeNodes, node => ids.push(node.id));
11
18
  return ids;
12
- };
13
- exports.collectIds = collectIds;
19
+ }
@@ -1,2 +1,6 @@
1
1
  import { ExtendedTreeNodeProps } from '../types';
2
+ /**
3
+ * Возвращает строковый заголовок узла дерева.
4
+ * Если title задан функцией, использует getTitle (если он доступен).
5
+ */
2
6
  export declare const extractTreeNodeTitle: ({ title, getTitle }: ExtendedTreeNodeProps) => string;
@@ -4,6 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.extractTreeNodeTitle = void 0;
7
+ /**
8
+ * Возвращает строковый заголовок узла дерева.
9
+ * Если title задан функцией, использует getTitle (если он доступен).
10
+ */
7
11
  const extractTreeNodeTitle = _ref => {
8
12
  let {
9
13
  title,
@@ -1,2 +1,9 @@
1
1
  import { TreeNodeId, TreeNodeProps } from '../types';
2
+ /**
3
+ * Собирает id всех недеактивированных узлов в поддереве.
4
+ *
5
+ * @param nodes Стартовые узлы обхода.
6
+ * @returns Массив id всех доступных узлов.
7
+ * @function findAllChildNodeIds
8
+ */
2
9
  export declare function findAllChildNodeIds(nodes: TreeNodeProps[]): TreeNodeId[];
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.findAllChildNodeIds = findAllChildNodeIds;
7
+ /**
8
+ * Собирает id всех недеактивированных узлов в поддереве.
9
+ *
10
+ * @param nodes Стартовые узлы обхода.
11
+ * @returns Массив id всех доступных узлов.
12
+ * @function findAllChildNodeIds
13
+ */
7
14
  function findAllChildNodeIds(nodes) {
8
15
  var _a;
9
16
  const stack = [...nodes];
@@ -1,2 +1,8 @@
1
1
  import { TreeNodeId, TreeNodeProps } from '../types';
2
+ /**
3
+ * Возвращает id узлов в поддереве, проходя только по раскрытым веткам.
4
+ *
5
+ * @param nodes Стартовые узлы обхода.
6
+ * @param expandedNodes Список id раскрытых узлов.
7
+ */
2
8
  export declare function findAllExpandedChildNodeIds(nodes: TreeNodeProps[], expandedNodes: TreeNodeId[]): string[];
@@ -4,6 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.findAllExpandedChildNodeIds = findAllExpandedChildNodeIds;
7
+ /**
8
+ * Возвращает id узлов в поддереве, проходя только по раскрытым веткам.
9
+ *
10
+ * @param nodes Стартовые узлы обхода.
11
+ * @param expandedNodes Список id раскрытых узлов.
12
+ */
7
13
  function findAllExpandedChildNodeIds(nodes, expandedNodes) {
8
14
  var _a;
9
15
  const stack = [...nodes];