@itwin/presentation-hierarchies 2.0.0-alpha.12 → 2.0.0-alpha.14

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 (121) hide show
  1. package/CHANGELOG.md +301 -16
  2. package/README.md +2 -2
  3. package/lib/cjs/hierarchies/HierarchyNode.d.ts +13 -11
  4. package/lib/cjs/hierarchies/HierarchyNode.d.ts.map +1 -1
  5. package/lib/cjs/hierarchies/HierarchyNode.js +18 -0
  6. package/lib/cjs/hierarchies/HierarchyNode.js.map +1 -1
  7. package/lib/cjs/hierarchies/HierarchyNodeIdentifier.d.ts +2 -0
  8. package/lib/cjs/hierarchies/HierarchyNodeIdentifier.d.ts.map +1 -1
  9. package/lib/cjs/hierarchies/HierarchyNodeIdentifier.js +23 -6
  10. package/lib/cjs/hierarchies/HierarchyNodeIdentifier.js.map +1 -1
  11. package/lib/cjs/hierarchies/HierarchyNodeKey.d.ts +5 -4
  12. package/lib/cjs/hierarchies/HierarchyNodeKey.d.ts.map +1 -1
  13. package/lib/cjs/hierarchies/HierarchyNodeKey.js.map +1 -1
  14. package/lib/cjs/hierarchies/HierarchyProvider.d.ts +3 -3
  15. package/lib/cjs/hierarchies/HierarchyProvider.d.ts.map +1 -1
  16. package/lib/cjs/hierarchies/HierarchyProvider.js.map +1 -1
  17. package/lib/cjs/hierarchies/HierarchySearch.d.ts +206 -78
  18. package/lib/cjs/hierarchies/HierarchySearch.d.ts.map +1 -1
  19. package/lib/cjs/hierarchies/HierarchySearch.js +315 -113
  20. package/lib/cjs/hierarchies/HierarchySearch.js.map +1 -1
  21. package/lib/cjs/hierarchies/imodel/IModelHierarchyDefinition.d.ts +2 -2
  22. package/lib/cjs/hierarchies/imodel/IModelHierarchyDefinition.d.ts.map +1 -1
  23. package/lib/cjs/hierarchies/imodel/IModelHierarchyDefinition.js.map +1 -1
  24. package/lib/cjs/hierarchies/imodel/IModelHierarchyNode.d.ts +3 -3
  25. package/lib/cjs/hierarchies/imodel/IModelHierarchyNode.d.ts.map +1 -1
  26. package/lib/cjs/hierarchies/imodel/IModelHierarchyNode.js.map +1 -1
  27. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.d.ts +9 -4
  28. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.d.ts.map +1 -1
  29. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.js +25 -16
  30. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.js.map +1 -1
  31. package/lib/cjs/hierarchies/imodel/NodeSelectQueryFactory.d.ts +4 -4
  32. package/lib/cjs/hierarchies/imodel/NodeSelectQueryFactory.d.ts.map +1 -1
  33. package/lib/cjs/hierarchies/imodel/NodeSelectQueryFactory.js +12 -9
  34. package/lib/cjs/hierarchies/imodel/NodeSelectQueryFactory.js.map +1 -1
  35. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts +3 -3
  36. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts.map +1 -1
  37. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.js.map +1 -1
  38. package/lib/cjs/hierarchies/imodel/SearchHierarchyDefinition.d.ts +2 -2
  39. package/lib/cjs/hierarchies/imodel/SearchHierarchyDefinition.d.ts.map +1 -1
  40. package/lib/cjs/hierarchies/imodel/SearchHierarchyDefinition.js +31 -55
  41. package/lib/cjs/hierarchies/imodel/SearchHierarchyDefinition.js.map +1 -1
  42. package/lib/cjs/hierarchies/imodel/TreeNodesReader.d.ts +2 -2
  43. package/lib/cjs/hierarchies/imodel/TreeNodesReader.d.ts.map +1 -1
  44. package/lib/cjs/hierarchies/imodel/TreeNodesReader.js +1 -1
  45. package/lib/cjs/hierarchies/imodel/TreeNodesReader.js.map +1 -1
  46. package/lib/cjs/hierarchies/imodel/operators/grouping/BaseClassGrouping.js.map +1 -1
  47. package/lib/cjs/hierarchies/imodel/operators/grouping/ClassGrouping.d.ts.map +1 -1
  48. package/lib/cjs/hierarchies/imodel/operators/grouping/ClassGrouping.js +4 -1
  49. package/lib/cjs/hierarchies/imodel/operators/grouping/ClassGrouping.js.map +1 -1
  50. package/lib/cjs/hierarchies/imodel/operators/grouping/PropertiesGrouping.d.ts +1 -1
  51. package/lib/cjs/hierarchies/imodel/operators/grouping/PropertiesGrouping.d.ts.map +1 -1
  52. package/lib/cjs/hierarchies/imodel/operators/grouping/PropertiesGrouping.js.map +1 -1
  53. package/lib/cjs/hierarchies/internal/operators/ReduceToMergeMap.d.ts +2 -2
  54. package/lib/cjs/hierarchies/internal/operators/ReduceToMergeMap.d.ts.map +1 -1
  55. package/lib/cjs/hierarchies/internal/operators/ReduceToMergeMap.js.map +1 -1
  56. package/lib/cjs/hierarchies/internal/operators/Sorting.d.ts.map +1 -1
  57. package/lib/cjs/hierarchies/internal/operators/Sorting.js.map +1 -1
  58. package/lib/cjs/presentation-hierarchies.d.ts +1 -1
  59. package/lib/cjs/presentation-hierarchies.d.ts.map +1 -1
  60. package/lib/cjs/presentation-hierarchies.js +2 -1
  61. package/lib/cjs/presentation-hierarchies.js.map +1 -1
  62. package/lib/esm/hierarchies/HierarchyNode.d.ts +13 -11
  63. package/lib/esm/hierarchies/HierarchyNode.d.ts.map +1 -1
  64. package/lib/esm/hierarchies/HierarchyNode.js +18 -0
  65. package/lib/esm/hierarchies/HierarchyNode.js.map +1 -1
  66. package/lib/esm/hierarchies/HierarchyNodeIdentifier.d.ts +2 -0
  67. package/lib/esm/hierarchies/HierarchyNodeIdentifier.d.ts.map +1 -1
  68. package/lib/esm/hierarchies/HierarchyNodeIdentifier.js +23 -6
  69. package/lib/esm/hierarchies/HierarchyNodeIdentifier.js.map +1 -1
  70. package/lib/esm/hierarchies/HierarchyNodeKey.d.ts +5 -4
  71. package/lib/esm/hierarchies/HierarchyNodeKey.d.ts.map +1 -1
  72. package/lib/esm/hierarchies/HierarchyNodeKey.js.map +1 -1
  73. package/lib/esm/hierarchies/HierarchyProvider.d.ts +3 -3
  74. package/lib/esm/hierarchies/HierarchyProvider.d.ts.map +1 -1
  75. package/lib/esm/hierarchies/HierarchyProvider.js.map +1 -1
  76. package/lib/esm/hierarchies/HierarchySearch.d.ts +206 -78
  77. package/lib/esm/hierarchies/HierarchySearch.d.ts.map +1 -1
  78. package/lib/esm/hierarchies/HierarchySearch.js +314 -111
  79. package/lib/esm/hierarchies/HierarchySearch.js.map +1 -1
  80. package/lib/esm/hierarchies/imodel/IModelHierarchyDefinition.d.ts +2 -2
  81. package/lib/esm/hierarchies/imodel/IModelHierarchyDefinition.d.ts.map +1 -1
  82. package/lib/esm/hierarchies/imodel/IModelHierarchyDefinition.js.map +1 -1
  83. package/lib/esm/hierarchies/imodel/IModelHierarchyNode.d.ts +3 -3
  84. package/lib/esm/hierarchies/imodel/IModelHierarchyNode.d.ts.map +1 -1
  85. package/lib/esm/hierarchies/imodel/IModelHierarchyNode.js.map +1 -1
  86. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.d.ts +9 -4
  87. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.d.ts.map +1 -1
  88. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.js +26 -17
  89. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.js.map +1 -1
  90. package/lib/esm/hierarchies/imodel/NodeSelectQueryFactory.d.ts +4 -4
  91. package/lib/esm/hierarchies/imodel/NodeSelectQueryFactory.d.ts.map +1 -1
  92. package/lib/esm/hierarchies/imodel/NodeSelectQueryFactory.js +13 -10
  93. package/lib/esm/hierarchies/imodel/NodeSelectQueryFactory.js.map +1 -1
  94. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts +3 -3
  95. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts.map +1 -1
  96. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.js.map +1 -1
  97. package/lib/esm/hierarchies/imodel/SearchHierarchyDefinition.d.ts +2 -2
  98. package/lib/esm/hierarchies/imodel/SearchHierarchyDefinition.d.ts.map +1 -1
  99. package/lib/esm/hierarchies/imodel/SearchHierarchyDefinition.js +32 -56
  100. package/lib/esm/hierarchies/imodel/SearchHierarchyDefinition.js.map +1 -1
  101. package/lib/esm/hierarchies/imodel/TreeNodesReader.d.ts +2 -2
  102. package/lib/esm/hierarchies/imodel/TreeNodesReader.d.ts.map +1 -1
  103. package/lib/esm/hierarchies/imodel/TreeNodesReader.js +2 -2
  104. package/lib/esm/hierarchies/imodel/TreeNodesReader.js.map +1 -1
  105. package/lib/esm/hierarchies/imodel/operators/grouping/BaseClassGrouping.js.map +1 -1
  106. package/lib/esm/hierarchies/imodel/operators/grouping/ClassGrouping.d.ts.map +1 -1
  107. package/lib/esm/hierarchies/imodel/operators/grouping/ClassGrouping.js +4 -1
  108. package/lib/esm/hierarchies/imodel/operators/grouping/ClassGrouping.js.map +1 -1
  109. package/lib/esm/hierarchies/imodel/operators/grouping/PropertiesGrouping.d.ts +1 -1
  110. package/lib/esm/hierarchies/imodel/operators/grouping/PropertiesGrouping.d.ts.map +1 -1
  111. package/lib/esm/hierarchies/imodel/operators/grouping/PropertiesGrouping.js.map +1 -1
  112. package/lib/esm/hierarchies/internal/operators/ReduceToMergeMap.d.ts +2 -2
  113. package/lib/esm/hierarchies/internal/operators/ReduceToMergeMap.d.ts.map +1 -1
  114. package/lib/esm/hierarchies/internal/operators/ReduceToMergeMap.js.map +1 -1
  115. package/lib/esm/hierarchies/internal/operators/Sorting.d.ts.map +1 -1
  116. package/lib/esm/hierarchies/internal/operators/Sorting.js.map +1 -1
  117. package/lib/esm/presentation-hierarchies.d.ts +1 -1
  118. package/lib/esm/presentation-hierarchies.d.ts.map +1 -1
  119. package/lib/esm/presentation-hierarchies.js +1 -1
  120. package/lib/esm/presentation-hierarchies.js.map +1 -1
  121. package/package.json +10 -10
@@ -4,41 +4,13 @@
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.HierarchySearchPath = void 0;
7
+ exports.HierarchySearchTree = exports.HierarchySearchPath = void 0;
8
8
  exports.createHierarchySearchHelper = createHierarchySearchHelper;
9
- exports.shouldAutoExpandBasedOnReveal = shouldAutoExpandBasedOnReveal;
9
+ const rxjs_1 = require("rxjs");
10
+ const core_bentley_1 = require("@itwin/core-bentley");
10
11
  const HierarchyNodeIdentifier_js_1 = require("./HierarchyNodeIdentifier.js");
11
12
  const HierarchyNodeKey_js_1 = require("./HierarchyNodeKey.js");
12
- var HierarchySearchPathOptions;
13
- (function (HierarchySearchPathOptions) {
14
- function mergeRevealOptions(lhs, rhs) {
15
- if (rhs === true || lhs === true) {
16
- return true;
17
- }
18
- if (!rhs || !lhs) {
19
- return !!rhs ? rhs : lhs;
20
- }
21
- const lhsDepth = "depthInPath" in lhs ? lhs.depthInPath : lhs.depthInHierarchy;
22
- const rhsDepth = "depthInPath" in rhs ? rhs.depthInPath : rhs.depthInHierarchy;
23
- const isLhsDepthBasedOnPath = "depthInPath" in lhs;
24
- const isRhsDepthBasedOnPath = "depthInPath" in rhs;
25
- if (isLhsDepthBasedOnPath) {
26
- if (isRhsDepthBasedOnPath) {
27
- return lhsDepth > rhsDepth ? lhs : rhs;
28
- }
29
- return lhs;
30
- }
31
- if (isRhsDepthBasedOnPath) {
32
- return rhs;
33
- }
34
- return lhsDepth > rhsDepth ? lhs : rhs;
35
- }
36
- HierarchySearchPathOptions.mergeRevealOptions = mergeRevealOptions;
37
- function mergeAutoExpandOption(lhs, rhs) {
38
- return lhs || rhs ? true : undefined;
39
- }
40
- HierarchySearchPathOptions.mergeAutoExpandOption = mergeAutoExpandOption;
41
- })(HierarchySearchPathOptions || (HierarchySearchPathOptions = {}));
13
+ const ReleaseMainThread_js_1 = require("./internal/operators/ReleaseMainThread.js");
42
14
  /** @public */
43
15
  // eslint-disable-next-line @typescript-eslint/no-redeclare
44
16
  var HierarchySearchPath;
@@ -62,14 +34,14 @@ var HierarchySearchPath;
62
34
  * - else if only one of the inputs is an object, return it,
63
35
  * - else if both inputs are falsy, return `false` or `undefined`,
64
36
  * - else:
65
- * - if only one of the inputs has `depthInHierarchy` set, return the other one,
66
- * - else return the one with greater `depthInPath` or `depthInHierarchy`.
37
+ * - if only one of the inputs has `groupingLevel` set, return that one,
38
+ * - else compare by matching reveal type (`groupingLevel` or `depthInPath`) and return the deeper one.
67
39
  *
68
40
  * @public
69
41
  */
70
42
  function mergeOptions(lhs, rhs) {
71
- const reveal = HierarchySearchPathOptions.mergeRevealOptions(lhs?.reveal, rhs?.reveal);
72
- const autoExpand = HierarchySearchPathOptions.mergeAutoExpandOption(lhs?.autoExpand, rhs?.autoExpand);
43
+ const reveal = mergeRevealOptions(lhs?.reveal, rhs?.reveal);
44
+ const autoExpand = mergeAutoExpandOption(lhs?.autoExpand, rhs?.autoExpand);
73
45
  return reveal || autoExpand
74
46
  ? {
75
47
  ...(reveal !== undefined ? { reveal } : undefined),
@@ -78,7 +50,264 @@ var HierarchySearchPath;
78
50
  : undefined;
79
51
  }
80
52
  HierarchySearchPath.mergeOptions = mergeOptions;
53
+ function mergeRevealOptions(lhs, rhs) {
54
+ if (rhs === true || lhs === true) {
55
+ return true;
56
+ }
57
+ if (!rhs || !lhs) {
58
+ return !!rhs ? rhs : lhs;
59
+ }
60
+ if ("groupingLevel" in lhs) {
61
+ if ("groupingLevel" in rhs) {
62
+ return lhs.groupingLevel > rhs.groupingLevel ? lhs : rhs;
63
+ }
64
+ return lhs;
65
+ }
66
+ else if ("groupingLevel" in rhs) {
67
+ return rhs;
68
+ }
69
+ return lhs.depthInPath > rhs.depthInPath ? lhs : rhs;
70
+ }
71
+ function mergeAutoExpandOption(lhs, rhs) {
72
+ return lhs || rhs ? true : undefined;
73
+ }
81
74
  })(HierarchySearchPath || (exports.HierarchySearchPath = HierarchySearchPath = {}));
75
+ /** @public */
76
+ var HierarchySearchTree;
77
+ (function (HierarchySearchTree) {
78
+ /**
79
+ * Create a `HierarchySearchTree` builder utility that accepts hierarchy search paths or search trees one by one and builds
80
+ * a `HierarchySearchTree` structure based on them.
81
+ *
82
+ * Usage example:
83
+ *
84
+ * ```ts
85
+ * const builder = HierarchySearchTree.createBuilder();
86
+ * for (const path of searchPaths) {
87
+ * builder.accept({ path });
88
+ * }
89
+ * const searchTree = builder.getTree();
90
+ * ```
91
+ *
92
+ * @public
93
+ */
94
+ function createBuilder() {
95
+ var _a;
96
+ return new (class Impl {
97
+ #rootsDictionary = new core_bentley_1.Dictionary(HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.compare);
98
+ static #mapDictionaryToTree(dictionary, parentEntries, props) {
99
+ const list = [];
100
+ for (const { children, ...entry } of dictionary.values()) {
101
+ let processedEntry = entry;
102
+ if (props?.processEntry) {
103
+ processedEntry = props.processEntry({ treeEntry: entry, parentEntries });
104
+ }
105
+ if (!processedEntry) {
106
+ continue;
107
+ }
108
+ const { extras: _, ...entryWithoutExtras } = processedEntry;
109
+ parentEntries.push(processedEntry);
110
+ list.push({ ...entryWithoutExtras, ...(children ? { children: Impl.#mapDictionaryToTree(children, parentEntries, props) } : undefined) });
111
+ parentEntries.pop();
112
+ }
113
+ return list;
114
+ }
115
+ static #assignAutoExpandOptionsBasedOnReveal(treePath, revealOption) {
116
+ if (revealOption === true) {
117
+ Impl.#assignOptionsOnTreePath({
118
+ treePath,
119
+ targetEntryIndex: treePath.length - 1,
120
+ getEntryOptions: (index, targetEntryIndex) => {
121
+ if (index === targetEntryIndex) {
122
+ // auto-expand all grouping nodes of the revealed node
123
+ return { autoExpand: { groupingLevel: Number.MAX_SAFE_INTEGER } };
124
+ }
125
+ // auto-expand all parent nodes
126
+ return { autoExpand: true };
127
+ },
128
+ });
129
+ }
130
+ else if (revealOption && "groupingLevel" in revealOption) {
131
+ Impl.#assignOptionsOnTreePath({
132
+ treePath,
133
+ targetEntryIndex: treePath.length - 1,
134
+ getEntryOptions: (index, targetEntryIndex) => {
135
+ if (index === targetEntryIndex) {
136
+ // the last entry should have `autoExpand` with `groupingLevel` set to the value based on `reveal.groupingLevel`
137
+ return { autoExpand: { groupingLevel: Math.max(revealOption.groupingLevel - 1, 0) } };
138
+ }
139
+ // auto-expand all parent nodes
140
+ return { autoExpand: true };
141
+ },
142
+ });
143
+ }
144
+ else if (revealOption && "depthInPath" in revealOption) {
145
+ Impl.#assignOptionsOnTreePath({
146
+ treePath,
147
+ targetEntryIndex: Math.min(revealOption.depthInPath, treePath.length - 1),
148
+ getEntryOptions: (index, targetEntryIndex) => {
149
+ if (index === targetEntryIndex) {
150
+ // auto-expand all grouping nodes of the revealed node
151
+ return { autoExpand: { groupingLevel: Number.MAX_SAFE_INTEGER } };
152
+ }
153
+ // auto-expand all parent nodes
154
+ return { autoExpand: true };
155
+ },
156
+ });
157
+ }
158
+ }
159
+ static #assignOptionsOnTreePath({ treePath, targetEntryIndex, getEntryOptions, }) {
160
+ // set all parent entries to auto-expand
161
+ for (let i = 0; i <= targetEntryIndex; i++) {
162
+ const options = mergeOptions(treePath[i].options, getEntryOptions(i, targetEntryIndex));
163
+ if (options) {
164
+ treePath[i].options = options;
165
+ }
166
+ }
167
+ }
168
+ #acceptNode({ parentEntries, level, node, handler, }) {
169
+ let entry = level.get(node.identifier);
170
+ if (!entry) {
171
+ if (handler?.onNewEntry && !handler.onNewEntry({ parentEntries, inputEntry: node })) {
172
+ return undefined;
173
+ }
174
+ entry = {
175
+ identifier: node.identifier,
176
+ children: node.hasChildren ? new core_bentley_1.Dictionary(HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.compare) : undefined,
177
+ extras: {},
178
+ };
179
+ level.set(node.identifier, entry);
180
+ }
181
+ const isNodeSearchTarget = node.isTarget || !node.hasChildren;
182
+ if (isNodeSearchTarget && entry.children) {
183
+ entry.isTarget = true;
184
+ }
185
+ if (!entry.children && node.hasChildren) {
186
+ // Existing leaf nodes are implied targets. Preserve that status when adding children.
187
+ entry.isTarget = true;
188
+ entry.children = new core_bentley_1.Dictionary(HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.compare);
189
+ }
190
+ handler?.onEntryHandled?.({ parentEntries, treeEntry: entry, inputEntry: node });
191
+ return entry;
192
+ }
193
+ #acceptPath({ path, handler }) {
194
+ const normalized = HierarchySearchPath.normalize(path);
195
+ const treePath = [];
196
+ let currentLevel = this.#rootsDictionary;
197
+ for (let i = 0; i < normalized.path.length; i++) {
198
+ const identifier = normalized.path[i];
199
+ const acceptedNode = this.#acceptNode({
200
+ parentEntries: treePath,
201
+ node: { identifier, hasChildren: i < normalized.path.length - 1 },
202
+ level: currentLevel,
203
+ handler,
204
+ });
205
+ if (!acceptedNode) {
206
+ break;
207
+ }
208
+ treePath.push(acceptedNode);
209
+ if (!acceptedNode.children) {
210
+ break;
211
+ }
212
+ currentLevel = acceptedNode.children;
213
+ }
214
+ if (treePath.length === 0) {
215
+ return;
216
+ }
217
+ // handle auto-expand
218
+ const lastNode = treePath[treePath.length - 1];
219
+ if (normalized.options?.autoExpand) {
220
+ (lastNode.options ??= {}).autoExpand = true;
221
+ }
222
+ // handle auto-reveal
223
+ Impl.#assignAutoExpandOptionsBasedOnReveal(treePath, normalized.options?.reveal);
224
+ }
225
+ #acceptTree({ tree, handler }) {
226
+ const acceptTreeNode = (parentEntries, parentInputs, level, node) => {
227
+ const acceptedNode = this.#acceptNode({
228
+ parentEntries,
229
+ node: { ...node, hasChildren: node.children !== undefined },
230
+ level,
231
+ handler,
232
+ });
233
+ if (!acceptedNode) {
234
+ // It was decided to reject this node and its children, if any
235
+ return;
236
+ }
237
+ const treePath = [...parentEntries, acceptedNode];
238
+ const inputsPath = [...parentInputs, node];
239
+ if (!node.children || node.isTarget) {
240
+ // Found an effective search target - merge options from its path
241
+ Impl.#assignOptionsOnTreePath({
242
+ treePath,
243
+ targetEntryIndex: treePath.length - 1,
244
+ getEntryOptions: (index) => inputsPath[index].options,
245
+ });
246
+ }
247
+ const currentLevel = acceptedNode.children;
248
+ if (currentLevel) {
249
+ node.children?.forEach((child) => acceptTreeNode(treePath, inputsPath, currentLevel, child));
250
+ }
251
+ };
252
+ acceptTreeNode([], [], this.#rootsDictionary, tree);
253
+ }
254
+ accept(props) {
255
+ if ("path" in props) {
256
+ this.#acceptPath(props);
257
+ }
258
+ else {
259
+ this.#acceptTree(props);
260
+ }
261
+ return this;
262
+ }
263
+ getTree(props) {
264
+ return Impl.#mapDictionaryToTree(this.#rootsDictionary, [], props);
265
+ }
266
+ })();
267
+ }
268
+ HierarchySearchTree.createBuilder = createBuilder;
269
+ /**
270
+ * Builds a list of `HierarchySearchTree` nodes from an iterable of search paths. Shared
271
+ * path prefixes are merged so that each unique hierarchy node identifier appears only once
272
+ * per level. The resulting trees carry `isTarget`, `options`, and `children` attributes
273
+ * derived from the paths and their options (`autoExpand`, `reveal`).
274
+ *
275
+ * @public
276
+ */
277
+ async function createFromPathsList(paths) {
278
+ return (0, rxjs_1.firstValueFrom)((0, rxjs_1.from)(paths).pipe((0, ReleaseMainThread_js_1.releaseMainThreadOnItemsCount)(1000), (0, rxjs_1.reduce)((builder, path) => builder.accept({ path }), createBuilder()), (0, rxjs_1.map)((builder) => builder.getTree())));
279
+ }
280
+ HierarchySearchTree.createFromPathsList = createFromPathsList;
281
+ /**
282
+ * Merges two `HierarchySearchTree` option objects. For the `autoExpand` attribute,
283
+ * `true` takes precedence over `{ groupingLevel }`, and when both sides are
284
+ * `{ groupingLevel }` objects the larger value wins.
285
+ * @public
286
+ */
287
+ function mergeOptions(lhs, rhs) {
288
+ if (!lhs) {
289
+ return rhs;
290
+ }
291
+ if (!rhs) {
292
+ return lhs;
293
+ }
294
+ const autoExpand = mergeSearchTreeAutoExpandOption(lhs.autoExpand, rhs.autoExpand);
295
+ const options = {
296
+ ...(autoExpand ? { autoExpand } : undefined),
297
+ };
298
+ return Object.keys(options).length > 0 ? options : undefined;
299
+ }
300
+ HierarchySearchTree.mergeOptions = mergeOptions;
301
+ function mergeSearchTreeAutoExpandOption(lhs, rhs) {
302
+ if (!lhs) {
303
+ return rhs;
304
+ }
305
+ if (!rhs) {
306
+ return lhs;
307
+ }
308
+ return lhs === true || rhs === true ? true : { groupingLevel: Math.max(lhs.groupingLevel, rhs.groupingLevel) };
309
+ }
310
+ })(HierarchySearchTree || (exports.HierarchySearchTree = HierarchySearchTree = {}));
82
311
  function extractSearchPropsInternal(rootLevelSearchProps, parentNode) {
83
312
  if (!parentNode) {
84
313
  return rootLevelSearchProps ? { childrenTargetPaths: rootLevelSearchProps, hasSearchTargetAncestor: false } : undefined;
@@ -99,41 +328,37 @@ function createHierarchySearchHelper(rootLevelSearchProps, parentNode) {
99
328
  const searchProps = extractSearchPropsInternal(rootLevelSearchProps, parentNode);
100
329
  const hasSearch = !!searchProps;
101
330
  function saveSearchPropsFromPathsIntoReducer(extractionProps) {
102
- // Passes down matching normalized paths to the reducer.
103
- // It uses `nodeKey`, `pathMatcher` or `asyncPathMatcher` to check if `HierarchyNodeIdentifier` at the first position in search path matches the node
331
+ // Passes down matching hierarchy search trees to the reducer.
332
+ // It uses `nodeKey`, `pathMatcher` or `asyncPathMatcher` to check if `HierarchyNodeIdentifier` in the search tree item's identifier matches the node
104
333
  // and if it does, the path is passed down to the reducer.
105
- // This function returns a promise only if asyncPathMatcher returns a promise.
334
+ // This function returns a promise only if `asyncPathMatcher` returns a promise.
106
335
  if (!searchProps?.childrenTargetPaths) {
107
336
  return;
108
337
  }
109
- const matchedPathPromises = new Array();
110
- for (const childrenTargetPaths of searchProps.childrenTargetPaths) {
111
- const normalizedPath = HierarchySearchPath.normalize(childrenTargetPaths);
112
- /* c8 ignore next 3 */
113
- if (normalizedPath.path.length === 0) {
114
- continue;
115
- }
116
- if ("nodeKey" in extractionProps) {
117
- if ((HierarchyNodeKey_js_1.HierarchyNodeKey.isGeneric(extractionProps.nodeKey) && HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.equal(normalizedPath.path[0], extractionProps.nodeKey)) ||
118
- (HierarchyNodeKey_js_1.HierarchyNodeKey.isInstances(extractionProps.nodeKey) &&
119
- extractionProps.nodeKey.instanceKeys.some((ik) => HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.equal(normalizedPath.path[0], ik)))) {
120
- extractionProps.pathsReducer.accept(normalizedPath);
338
+ const matchedTreePromises = new Array();
339
+ for (const childrenSearchTree of searchProps.childrenTargetPaths) {
340
+ if ("asyncPathMatcher" in extractionProps) {
341
+ const matchesPossiblyPromise = extractionProps.asyncPathMatcher(childrenSearchTree.identifier);
342
+ if (matchesPossiblyPromise instanceof Promise) {
343
+ matchedTreePromises.push(matchesPossiblyPromise.then((matches) => (matches ? childrenSearchTree : undefined)));
344
+ }
345
+ else if (matchesPossiblyPromise) {
346
+ extractionProps.pathsReducer.accept(childrenSearchTree);
121
347
  }
122
- continue;
123
- }
124
- const matchesPossiblyPromise = "pathMatcher" in extractionProps ? extractionProps.pathMatcher(normalizedPath.path[0]) : extractionProps.asyncPathMatcher(normalizedPath.path[0]);
125
- if (matchesPossiblyPromise instanceof Promise) {
126
- matchedPathPromises.push(matchesPossiblyPromise.then((matches) => (matches ? normalizedPath : undefined)));
127
- continue;
128
348
  }
129
- if (matchesPossiblyPromise) {
130
- extractionProps.pathsReducer.accept(normalizedPath);
349
+ else {
350
+ const matches = "pathMatcher" in extractionProps
351
+ ? extractionProps.pathMatcher(childrenSearchTree.identifier)
352
+ : nodeKeyMatchesIdentifier(extractionProps.nodeKey, childrenSearchTree.identifier);
353
+ if (matches) {
354
+ extractionProps.pathsReducer.accept(childrenSearchTree);
355
+ }
131
356
  }
132
357
  }
133
- if (matchedPathPromises.length === 0) {
358
+ if (matchedTreePromises.length === 0) {
134
359
  return;
135
360
  }
136
- return Promise.all(matchedPathPromises).then((matchedPath) => matchedPath.forEach((normalizedPath) => normalizedPath && extractionProps.pathsReducer.accept(normalizedPath)));
361
+ return Promise.all(matchedTreePromises).then((matchedTrees) => matchedTrees.forEach((matchedTree) => matchedTree && extractionProps.pathsReducer.accept(matchedTree)));
137
362
  }
138
363
  function createChildNodeProps(props) {
139
364
  if (!hasSearch) {
@@ -141,15 +366,15 @@ function createHierarchySearchHelper(rootLevelSearchProps, parentNode) {
141
366
  }
142
367
  const reducer = new MatchingSearchPathsReducer(searchProps.hasSearchTargetAncestor);
143
368
  if ("asyncPathMatcher" in props) {
144
- const extractResult = saveSearchPropsFromPathsIntoReducer({ pathsReducer: reducer, asyncPathMatcher: props.asyncPathMatcher });
369
+ const extractResult = saveSearchPropsFromPathsIntoReducer({ pathsReducer: reducer, nodeKey: props.nodeKey, asyncPathMatcher: props.asyncPathMatcher });
145
370
  if (extractResult instanceof Promise) {
146
- return extractResult.then(() => reducer.getNodeProps(props.parentKeys));
371
+ return extractResult.then(() => reducer.aggregatedOptions);
147
372
  }
148
373
  }
149
374
  else {
150
- saveSearchPropsFromPathsIntoReducer({ ...props, pathsReducer: reducer });
375
+ saveSearchPropsFromPathsIntoReducer({ pathsReducer: reducer, ...props });
151
376
  }
152
- return reducer.getNodeProps(props.parentKeys);
377
+ return reducer.aggregatedOptions;
153
378
  }
154
379
  return {
155
380
  /** Returns a flag indicating if the hierarchy level is filtered. */
@@ -169,10 +394,7 @@ function createHierarchySearchHelper(rootLevelSearchProps, parentNode) {
169
394
  if (!searchProps?.childrenTargetPaths) {
170
395
  return undefined;
171
396
  }
172
- return searchProps.childrenTargetPaths
173
- .map(HierarchySearchPath.normalize)
174
- .filter(({ path }) => path.length > 0)
175
- .map(({ path }) => path[0]);
397
+ return searchProps.childrenTargetPaths.map(({ identifier }) => identifier);
176
398
  },
177
399
  /**
178
400
  * When a hierarchy node is created for a filtered hierarchy level, it needs some attributes (e.g. `search`
@@ -184,13 +406,16 @@ function createHierarchySearchHelper(rootLevelSearchProps, parentNode) {
184
406
  * `nodeKey` prop can be used to check the whole identifier.
185
407
  *
186
408
  * There are multiple overloads of `createChildNodeProps`: depending on props type it returns different values:
187
- * - `parentKeys` is defined and `pathMatcher` or `nodeKey` is provided - returns undefined **or** `search` and `autoExpand` prop from `HierarchyNode`;
188
- * - `parentKeys` is undefined - does not return `HierarchyNode.autoExpand` option;
189
- * - props have `asyncPathMatcher` - returns either Promise or the regular return value based on whether or not `asyncPathMatcher` returns a promise.
409
+ * - `asyncPathMatcher` is provided - returns either Promise or the regular return value based on whether or not `asyncPathMatcher` returns a `Promise`.
410
+ * - `pathMatcher` or only `nodeKey` is provided - returns undefined **or** `search` and `autoExpand` prop from `HierarchyNode`;
190
411
  */
191
412
  createChildNodeProps,
192
413
  };
193
414
  }
415
+ function nodeKeyMatchesIdentifier(nodeKey, identifier) {
416
+ return ((HierarchyNodeKey_js_1.HierarchyNodeKey.isGeneric(nodeKey) && HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.equal(identifier, nodeKey)) ||
417
+ (HierarchyNodeKey_js_1.HierarchyNodeKey.isInstances(nodeKey) && nodeKey.instanceKeys.some((ik) => HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.equal(identifier, ik))));
418
+ }
194
419
  /**
195
420
  * Extracts information from search paths and later returns `search` and `autoExpand` values from `HierarchyNode`.
196
421
  *
@@ -204,56 +429,33 @@ class MatchingSearchPathsReducer {
204
429
  _hasSearchTargetAncestor;
205
430
  _childrenTargetPaths = new Array();
206
431
  _isSearchTarget = false;
207
- _searchTargetOptions = undefined;
208
- _revealOption = false;
432
+ _options = undefined;
209
433
  constructor(_hasSearchTargetAncestor) {
210
434
  this._hasSearchTargetAncestor = _hasSearchTargetAncestor;
211
435
  }
212
- accept(normalizedPath) {
213
- const { path, options } = normalizedPath;
214
- if (path.length === 1) {
436
+ accept(tree) {
437
+ if (tree.isTarget || tree.children === undefined) {
215
438
  this._isSearchTarget = true;
216
- this._searchTargetOptions = HierarchySearchPath.mergeOptions(this._searchTargetOptions, options);
217
439
  }
218
- else if (path.length > 1) {
219
- this._childrenTargetPaths.push({ path: path.slice(1), options });
220
- this._revealOption = HierarchySearchPathOptions.mergeRevealOptions(options?.reveal, this._revealOption);
440
+ if (tree.children && tree.children.length > 0) {
441
+ this._childrenTargetPaths.push(...tree.children);
221
442
  }
443
+ this._options = HierarchySearchTree.mergeOptions(this._options, tree.options);
222
444
  }
223
- getNodeProps(parentKeys) {
445
+ get aggregatedOptions() {
446
+ const search = this._hasSearchTargetAncestor || this._isSearchTarget || this._childrenTargetPaths.length > 0 || this._options
447
+ ? {
448
+ ...(this._hasSearchTargetAncestor ? { hasSearchTargetAncestor: true } : undefined),
449
+ ...(this._isSearchTarget ? { isSearchTarget: true } : undefined),
450
+ ...(this._childrenTargetPaths.length > 0 ? { childrenTargetPaths: this._childrenTargetPaths } : undefined),
451
+ ...(this._options ? { options: this._options } : undefined),
452
+ }
453
+ : undefined;
454
+ const autoExpand = this._options?.autoExpand === true;
224
455
  return {
225
- ...(this._hasSearchTargetAncestor || this._isSearchTarget || this._childrenTargetPaths.length > 0
226
- ? {
227
- search: {
228
- ...(this._hasSearchTargetAncestor ? { hasSearchTargetAncestor: true } : undefined),
229
- ...(this._isSearchTarget ? { isSearchTarget: true, searchTargetOptions: this._searchTargetOptions } : undefined),
230
- ...(this._childrenTargetPaths.length > 0 ? { childrenTargetPaths: this._childrenTargetPaths } : undefined),
231
- },
232
- }
233
- : undefined),
234
- ...(parentKeys &&
235
- (shouldAutoExpandBasedOnReveal({
236
- reveal: this._revealOption,
237
- nodePositionInHierarchy: parentKeys.length,
238
- nodePositionInPath: parentKeys.filter((key) => !HierarchyNodeKey_js_1.HierarchyNodeKey.isGrouping(key)).length,
239
- }) ||
240
- !!this._searchTargetOptions?.autoExpand)
241
- ? { autoExpand: true }
242
- : undefined),
456
+ ...(search ? { search } : undefined),
457
+ ...(autoExpand ? { autoExpand } : undefined),
243
458
  };
244
459
  }
245
460
  }
246
- /** @internal */
247
- function shouldAutoExpandBasedOnReveal({ reveal, nodePositionInPath, nodePositionInHierarchy, }) {
248
- if (!reveal) {
249
- return false;
250
- }
251
- if (reveal === true) {
252
- return true;
253
- }
254
- if ("depthInHierarchy" in reveal) {
255
- return nodePositionInHierarchy < reveal.depthInHierarchy;
256
- }
257
- return nodePositionInPath < reveal.depthInPath;
258
- }
259
461
  //# sourceMappingURL=HierarchySearch.js.map