@itwin/presentation-hierarchies 2.0.0-alpha.0 → 2.0.0-alpha.2

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 (40) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/lib/cjs/hierarchies/HierarchyFiltering.d.ts +37 -14
  3. package/lib/cjs/hierarchies/HierarchyFiltering.d.ts.map +1 -1
  4. package/lib/cjs/hierarchies/HierarchyFiltering.js +46 -24
  5. package/lib/cjs/hierarchies/HierarchyFiltering.js.map +1 -1
  6. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.d.ts +10 -8
  7. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.d.ts.map +1 -1
  8. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.js +73 -60
  9. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.js.map +1 -1
  10. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.d.ts.map +1 -1
  11. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.js +31 -38
  12. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.js.map +1 -1
  13. package/lib/cjs/hierarchies/imodel/TreeNodesReader.d.ts +2 -2
  14. package/lib/cjs/hierarchies/imodel/TreeNodesReader.d.ts.map +1 -1
  15. package/lib/cjs/hierarchies/imodel/TreeNodesReader.js +2 -5
  16. package/lib/cjs/hierarchies/imodel/TreeNodesReader.js.map +1 -1
  17. package/lib/cjs/hierarchies/internal/RxjsHierarchyDefinition.d.ts +64 -0
  18. package/lib/cjs/hierarchies/internal/RxjsHierarchyDefinition.d.ts.map +1 -0
  19. package/lib/cjs/hierarchies/internal/RxjsHierarchyDefinition.js +25 -0
  20. package/lib/cjs/hierarchies/internal/RxjsHierarchyDefinition.js.map +1 -0
  21. package/lib/esm/hierarchies/HierarchyFiltering.d.ts +37 -14
  22. package/lib/esm/hierarchies/HierarchyFiltering.d.ts.map +1 -1
  23. package/lib/esm/hierarchies/HierarchyFiltering.js +46 -24
  24. package/lib/esm/hierarchies/HierarchyFiltering.js.map +1 -1
  25. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.d.ts +10 -8
  26. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.d.ts.map +1 -1
  27. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.js +74 -61
  28. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.js.map +1 -1
  29. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.d.ts.map +1 -1
  30. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.js +32 -39
  31. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.js.map +1 -1
  32. package/lib/esm/hierarchies/imodel/TreeNodesReader.d.ts +2 -2
  33. package/lib/esm/hierarchies/imodel/TreeNodesReader.d.ts.map +1 -1
  34. package/lib/esm/hierarchies/imodel/TreeNodesReader.js +2 -5
  35. package/lib/esm/hierarchies/imodel/TreeNodesReader.js.map +1 -1
  36. package/lib/esm/hierarchies/internal/RxjsHierarchyDefinition.d.ts +64 -0
  37. package/lib/esm/hierarchies/internal/RxjsHierarchyDefinition.d.ts.map +1 -0
  38. package/lib/esm/hierarchies/internal/RxjsHierarchyDefinition.js +22 -0
  39. package/lib/esm/hierarchies/internal/RxjsHierarchyDefinition.js.map +1 -0
  40. package/package.json +8 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @itwin/presentation-hierarchies
2
2
 
3
+ ## 2.0.0-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1005](https://github.com/iTwin/presentation/pull/1005): Removed deprecated `FilterTargetGroupingNodeInfo` interface.
8
+
9
+ ## 2.0.0-alpha.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#985](https://github.com/iTwin/presentation/pull/985): Add support for `itwinjs-core@5`
14
+ - Updated dependencies:
15
+ - @itwin/presentation-shared@2.0.0-alpha.1
16
+
3
17
  ## 2.0.0-alpha.0
4
18
 
5
19
  ### Major Changes
@@ -24,6 +38,73 @@
24
38
  - Updated dependencies:
25
39
  - @itwin/presentation-shared@2.0.0-alpha.0
26
40
 
41
+ ## 1.6.1
42
+
43
+ ### Patch Changes
44
+
45
+ - [#1010](https://github.com/iTwin/presentation/pull/1010): Fixed `HierarchyFilteringPathOptions.autoExpand` depth option not working properly with grouping nodes. Added `includeGroupingNodes` attribute to `FilteringPathAutoExpandOption`, which allows auto-expanding only desired gouping nodes, when set together with `depth` value.
46
+
47
+ ## 1.6.0
48
+
49
+ ### Minor Changes
50
+
51
+ - 69a2db67917f84e99d532e8e9aabbc02ec262d91: `HierarchyFilteringPathOptions.autoExpand` is now of type:
52
+ ```ts
53
+ autoExpand?: { depth: number } | boolean;
54
+ ```
55
+ When `depth` is set, only nodes up to specified `depth` in `HierarchyFilteringPath` will have `autoExpand` option set.
56
+
57
+ ## 1.5.1
58
+
59
+ ### Patch Changes
60
+
61
+ - [#982](https://github.com/iTwin/presentation/pull/982): Update itwinjs-core dependencies to v5.0.0
62
+ - Updated dependencies:
63
+ - @itwin/presentation-shared@1.2.2
64
+
65
+ ## 1.5.0
66
+
67
+ ### Minor Changes
68
+
69
+ - [#962](https://github.com/iTwin/presentation/pull/962): `createChildNodePropsAsync` function, returned by `createHierarchyFilteringHelper`, may now return either a Promise, or the value synchronously. Either way, the result may be awaited, but for cases when the `createChildNodePropsAsync` function is called many times, not having to await on it provides performance improvement.
70
+
71
+ **Before:**
72
+
73
+ ```ts
74
+ const childNodeProps = await createHierarchyFilteringHelper(undefined, undefined).createChildNodePropsAsync({
75
+ pathMatcher: (identifier): boolean | Promise<boolean> => {
76
+ return false;
77
+ },
78
+ });
79
+ ```
80
+
81
+ **After:**
82
+
83
+ - **Option A:** check if it's a Promise before awaiting:
84
+
85
+ Use this when you want to get slightly better performance by avoiding unnecessary `await`.
86
+
87
+ ```ts
88
+ const childNodePropsPossiblyPromise = createHierarchyFilteringHelper(undefined, undefined).createChildNodePropsAsync({
89
+ pathMatcher: (identifier): boolean | Promise<boolean> => {
90
+ return false;
91
+ },
92
+ });
93
+ const childNodeProps = childNodePropsPossiblyPromise instanceOf Promise ? await childNodePropsPossiblyPromise : childNodePropsPossiblyPromise;
94
+ ```
95
+
96
+ - **Option B:** always await
97
+
98
+ Use this if pathMatcher always returns a Promise or you prefer a simpler pattern.
99
+
100
+ ```ts
101
+ const childNodeProps = await createHierarchyFilteringHelper(undefined, undefined).createChildNodePropsAsync({
102
+ pathMatcher: async (identifier): Promise<boolean> => {
103
+ return false;
104
+ },
105
+ });
106
+ ```
107
+
27
108
  ## 1.4.2
28
109
 
29
110
  ### Patch Changes
@@ -1,15 +1,30 @@
1
1
  import { HierarchyNode, NonGroupingHierarchyNode } from "./HierarchyNode.js";
2
2
  import { HierarchyNodeIdentifier, HierarchyNodeIdentifiersPath } from "./HierarchyNodeIdentifier.js";
3
- import { GenericNodeKey, GroupingNodeKey, InstancesNodeKey } from "./HierarchyNodeKey.js";
3
+ import { GenericNodeKey, InstancesNodeKey } from "./HierarchyNodeKey.js";
4
4
  /** @public */
5
- export interface FilterTargetGroupingNodeInfo {
6
- /** Key of the grouping node. */
7
- key: GroupingNodeKey;
5
+ export interface FilteringPathAutoExpandOption {
8
6
  /**
9
- * Depth of the grouping node in the hierarchy.
10
- * Generally, it can be retrieved from `parentKeys.length`.
7
+ * Depth up to which nodes in the hierarchy should be expanded.
8
+ *
9
+ * If `includeGroupingNodes` is set to true, then depth should take into account the number of grouping nodes in hierarchy.
11
10
  */
12
11
  depth: number;
12
+ /**
13
+ * Whether or not `depth` includes grouping nodes.
14
+ *
15
+ * Use when you want to autoExpand only some of the grouping nodes.
16
+ *
17
+ * **Use case example:**
18
+ *
19
+ * You want to `autoExpand` only `Node1` and `GroupingNode1` in the following hierarchy:
20
+ * - Node1
21
+ * - GroupingNode1
22
+ * - GroupingNode2
23
+ * - Element1
24
+ * - Element2
25
+ * Then you provide `autoExpand: { depth: 2, includeGroupingNodes: true }`
26
+ */
27
+ includeGroupingNodes?: boolean;
13
28
  }
14
29
  /** @public */
15
30
  export interface HierarchyFilteringPathOptions {
@@ -17,10 +32,9 @@ export interface HierarchyFilteringPathOptions {
17
32
  * This option specifies the way `autoExpand` flag should be assigned to nodes in the filtered hierarchy.
18
33
  * - If it's `false` or `undefined`, nodes have no 'autoExpand' flag.
19
34
  * - If it's `true`, then all nodes up to the filter target will have `autoExpand` flag.
20
- * - If it's an instance of `FilterTargetGroupingNodeInfo`, then all nodes up to the grouping node that matches this property,
21
- * will have `autoExpand` flag.
35
+ * - If it's an instance of `FilteringPathAutoExpandOption`, then all nodes up to and including `depth` will have `autoExpand` flag.
22
36
  */
23
- autoExpand?: boolean | FilterTargetGroupingNodeInfo;
37
+ autoExpand?: boolean | FilteringPathAutoExpandOption;
24
38
  }
25
39
  /**
26
40
  * A path of hierarchy node identifiers for filtering the hierarchy with additional options.
@@ -45,9 +59,11 @@ export declare namespace HierarchyFilteringPath {
45
59
  *
46
60
  * For the `autoExpand` attribute, the merge chooses to auto-expand as deep as the deepest input:
47
61
  * - if any one of the inputs is `true`, return `true`,
48
- * - else if both inputs are objects, return the one with the greater `depth` attribute.
49
- * - else if one input is an object, return it.
50
- * - else, return `false` or `undefined`.
62
+ * - else if only one of the inputs is an object, return it,
63
+ * - else if both inputs are falsy, return `false` or `undefined`,
64
+ * - else:
65
+ * - if only one of the inputs has `includeGroupingNodes` set to `true` or `key` defined, return the one that has only `depth` set,
66
+ * - else return the one with greater `depth`.
51
67
  *
52
68
  * @public
53
69
  */
@@ -99,12 +115,19 @@ export declare function createHierarchyFilteringHelper(rootLevelFilteringProps:
99
115
  nodeKey: InstancesNodeKey | GenericNodeKey;
100
116
  } | {
101
117
  pathMatcher: (identifier: HierarchyNodeIdentifier) => boolean;
102
- }) => Pick<HierarchyNode, "filtering" | "autoExpand"> | undefined;
118
+ }) => NodeProps | undefined;
103
119
  /**
104
120
  * Similar to `createChildNodeProps`, but takes an async `pathMatcher` prop.
105
121
  */
106
122
  createChildNodePropsAsync: (props: {
107
123
  pathMatcher: (identifier: HierarchyNodeIdentifier) => boolean | Promise<boolean>;
108
- }) => Promise<Pick<HierarchyNode, "filtering" | "autoExpand"> | undefined>;
124
+ }) => Promise<NodeProps | undefined> | NodeProps | undefined;
125
+ };
126
+ /** @public */
127
+ export type NodeProps = Pick<HierarchyNode, "autoExpand" | "filtering"> & {
128
+ filtering?: {
129
+ autoExpandDepth?: number;
130
+ includeGroupingNodes?: boolean;
131
+ };
109
132
  };
110
133
  //# sourceMappingURL=HierarchyFiltering.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"HierarchyFiltering.d.ts","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyFiltering.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,eAAe,EAAoB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE5G,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C,gCAAgC;IAChC,GAAG,EAAE,eAAe,CAAC;IAErB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,cAAc;AACd,MAAM,WAAW,6BAA6B;IAC5C;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,4BAA4B,CAAC;CACrD;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,4BAA4B,GAAG;IAAE,IAAI,EAAE,4BAA4B,CAAC;IAAC,OAAO,CAAC,EAAE,6BAA6B,CAAA;CAAE,CAAC;AACpJ,cAAc;AAEd,yBAAiB,sBAAsB,CAAC;IACtC;;;OAGG;IACH,SAAgB,SAAS,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,EAAE,4BAA4B,CAAC,CAKvH;IAED;;;;;;;;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;IAKjE;;OAEG;;IAGH;;;;;OAKG;;IAGH;;;OAGG;;IAWH;;;;;;;;OAQG;kCAGG;QACE,OAAO,EAAE,gBAAgB,GAAG,cAAc,CAAC;KAC5C,GACD;QACE,WAAW,EAAE,CAAC,UAAU,EAAE,uBAAuB,KAAK,OAAO,CAAC;KAC/D,KACJ,SAAS,GAAG,SAAS;IAoBxB;;OAEG;uCACgC;QACjC,WAAW,EAAE,CAAC,UAAU,EAAE,uBAAuB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAClF,KAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS;EAgC7D;AAED,cAAc;AACd,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,oBAAoB,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAC"}
@@ -9,6 +9,28 @@ exports.extractFilteringProps = extractFilteringProps;
9
9
  exports.createHierarchyFilteringHelper = createHierarchyFilteringHelper;
10
10
  const HierarchyNodeIdentifier_js_1 = require("./HierarchyNodeIdentifier.js");
11
11
  const HierarchyNodeKey_js_1 = require("./HierarchyNodeKey.js");
12
+ var HierarchyFilteringPathOptions;
13
+ (function (HierarchyFilteringPathOptions) {
14
+ function mergeAutoExpandOptions(lhs, rhs) {
15
+ if (rhs === true || lhs === true) {
16
+ return true;
17
+ }
18
+ if (!rhs || !lhs) {
19
+ return !!rhs ? rhs : lhs;
20
+ }
21
+ if (!lhs.includeGroupingNodes) {
22
+ if (!rhs.includeGroupingNodes) {
23
+ return lhs.depth > rhs.depth ? lhs : rhs;
24
+ }
25
+ return lhs;
26
+ }
27
+ if (!rhs.includeGroupingNodes) {
28
+ return rhs;
29
+ }
30
+ return lhs.depth > rhs.depth ? lhs : rhs;
31
+ }
32
+ HierarchyFilteringPathOptions.mergeAutoExpandOptions = mergeAutoExpandOptions;
33
+ })(HierarchyFilteringPathOptions || (HierarchyFilteringPathOptions = {}));
12
34
  /** @public */
13
35
  // eslint-disable-next-line @typescript-eslint/no-redeclare
14
36
  var HierarchyFilteringPath;
@@ -32,9 +54,11 @@ var HierarchyFilteringPath;
32
54
  *
33
55
  * For the `autoExpand` attribute, the merge chooses to auto-expand as deep as the deepest input:
34
56
  * - if any one of the inputs is `true`, return `true`,
35
- * - else if both inputs are objects, return the one with the greater `depth` attribute.
36
- * - else if one input is an object, return it.
37
- * - else, return `false` or `undefined`.
57
+ * - else if only one of the inputs is an object, return it,
58
+ * - else if both inputs are falsy, return `false` or `undefined`,
59
+ * - else:
60
+ * - if only one of the inputs has `includeGroupingNodes` set to `true` or `key` defined, return the one that has only `depth` set,
61
+ * - else return the one with greater `depth`.
38
62
  *
39
63
  * @public
40
64
  */
@@ -43,18 +67,7 @@ var HierarchyFilteringPath;
43
67
  return lhs ?? rhs;
44
68
  }
45
69
  return {
46
- autoExpand: (() => {
47
- if (rhs.autoExpand === true || lhs.autoExpand === true) {
48
- return true;
49
- }
50
- if (typeof lhs.autoExpand === "object") {
51
- if (typeof rhs.autoExpand === "object" && rhs.autoExpand.depth > lhs.autoExpand.depth) {
52
- return rhs.autoExpand;
53
- }
54
- return lhs.autoExpand;
55
- }
56
- return rhs.autoExpand;
57
- })(),
70
+ autoExpand: HierarchyFilteringPathOptions.mergeAutoExpandOptions(lhs.autoExpand, rhs.autoExpand),
58
71
  };
59
72
  }
60
73
  HierarchyFilteringPath.mergeOptions = mergeOptions;
@@ -145,11 +158,12 @@ function createHierarchyFilteringHelper(rootLevelFilteringProps, parentNode) {
145
158
  /**
146
159
  * Similar to `createChildNodeProps`, but takes an async `pathMatcher` prop.
147
160
  */
148
- createChildNodePropsAsync: async (props) => {
161
+ createChildNodePropsAsync: (props) => {
149
162
  if (!hasFilter) {
150
163
  return undefined;
151
164
  }
152
165
  const reducer = new MatchingFilteringPathsReducer(filteringProps?.hasFilterTargetAncestor);
166
+ const matchedPathPromises = new Array();
153
167
  for (const filteredChildrenNodeIdentifierPath of filteringProps.filteredNodePaths) {
154
168
  const normalizedPath = HierarchyFilteringPath.normalize(filteredChildrenNodeIdentifierPath);
155
169
  /* c8 ignore next 3 */
@@ -158,16 +172,20 @@ function createHierarchyFilteringHelper(rootLevelFilteringProps, parentNode) {
158
172
  }
159
173
  const matchesPossiblyPromise = props.pathMatcher(normalizedPath.path[0]);
160
174
  if (matchesPossiblyPromise instanceof Promise) {
161
- if (!(await matchesPossiblyPromise)) {
162
- continue;
163
- }
175
+ matchedPathPromises.push(matchesPossiblyPromise.then((matches) => (matches ? normalizedPath : undefined)));
176
+ continue;
164
177
  }
165
178
  if (!matchesPossiblyPromise) {
166
179
  continue;
167
180
  }
168
181
  reducer.accept(normalizedPath);
169
182
  }
170
- return reducer.getNodeProps();
183
+ if (matchedPathPromises.length === 0) {
184
+ return reducer.getNodeProps();
185
+ }
186
+ return Promise.all(matchedPathPromises)
187
+ .then((matchedPath) => matchedPath.forEach((normalizedPath) => normalizedPath && reducer.accept(normalizedPath)))
188
+ .then(() => reducer.getNodeProps());
171
189
  },
172
190
  };
173
191
  }
@@ -187,9 +205,7 @@ class MatchingFilteringPathsReducer {
187
205
  }
188
206
  else if (path.length > 1) {
189
207
  this._filteredChildrenIdentifierPaths.push({ path: path.slice(1), options });
190
- if (options?.autoExpand) {
191
- this._needsAutoExpand = true;
192
- }
208
+ this._needsAutoExpand = HierarchyFilteringPathOptions.mergeAutoExpandOptions(options?.autoExpand, this._needsAutoExpand);
193
209
  }
194
210
  }
195
211
  getNodeProps() {
@@ -200,10 +216,16 @@ class MatchingFilteringPathsReducer {
200
216
  ...(this._hasFilterTargetAncestor ? { hasFilterTargetAncestor: true } : undefined),
201
217
  ...(this._isFilterTarget ? { isFilterTarget: true, filterTargetOptions: this._filterTargetOptions } : undefined),
202
218
  ...(this._filteredChildrenIdentifierPaths.length > 0 ? { filteredChildrenIdentifierPaths: this._filteredChildrenIdentifierPaths } : undefined),
219
+ ...(this._needsAutoExpand && this._needsAutoExpand !== true
220
+ ? {
221
+ autoExpandDepth: this._needsAutoExpand.depth,
222
+ includeGroupingNodes: this._needsAutoExpand.includeGroupingNodes ? true : false,
223
+ }
224
+ : undefined),
203
225
  },
204
226
  }
205
227
  : undefined),
206
- ...(this._needsAutoExpand ? { autoExpand: true } : undefined),
228
+ ...(this._needsAutoExpand ? { autoExpand: !!this._needsAutoExpand } : undefined),
207
229
  };
208
230
  }
209
231
  }
@@ -1 +1 @@
1
- {"version":3,"file":"HierarchyFiltering.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyFiltering.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AA+FhG,sDAUC;AA6BD,wEAuGC;AA1OD,6EAAqG;AACrG,+DAA4G;AA+B5G,cAAc;AACd,2DAA2D;AAC3D,IAAiB,sBAAsB,CAiDtC;AAjDD,WAAiB,sBAAsB;IACrC;;;OAGG;IACH,SAAgB,SAAS,CAAC,MAA8B;QACtD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC1B,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IALe,gCAAS,YAKxB,CAAA;IAED;;;;;;;;;;;;;OAaG;IACH,SAAgB,YAAY,CAC1B,GAA8C,EAC9C,GAA8C;QAE9C,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACjB,OAAO,GAAG,IAAI,GAAG,CAAC;QACpB,CAAC;QAED,OAAO;YACL,UAAU,EAAE,CAAC,GAAgD,EAAE;gBAC7D,IAAI,GAAG,CAAC,UAAU,KAAK,IAAI,IAAI,GAAG,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;oBACvD,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,IAAI,OAAO,GAAG,CAAC,UAAU,KAA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F,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;wBAChH,GAAG,CAAC,IAAI,CAAC,gCAAgC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,+BAA+B,EAAE,IAAI,CAAC,gCAAgC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;qBAC/I;iBACF;gBACH,CAAC,CAAC,SAAS,CAAC;YACd,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;SAC9D,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { HierarchyNode, NonGroupingHierarchyNode } from \"./HierarchyNode.js\";\nimport { HierarchyNodeIdentifier, HierarchyNodeIdentifiersPath } from \"./HierarchyNodeIdentifier.js\";\nimport { GenericNodeKey, GroupingNodeKey, HierarchyNodeKey, InstancesNodeKey } from \"./HierarchyNodeKey.js\";\n\n/** @public */\nexport interface FilterTargetGroupingNodeInfo {\n /** Key of the grouping node. */\n key: GroupingNodeKey;\n\n /**\n * Depth of the grouping node in the hierarchy.\n * Generally, it can be retrieved from `parentKeys.length`.\n */\n depth: number;\n}\n\n/** @public */\nexport interface HierarchyFilteringPathOptions {\n /**\n * This option specifies the way `autoExpand` flag should be assigned to nodes in the filtered hierarchy.\n * - If it's `false` or `undefined`, nodes have no 'autoExpand' flag.\n * - If it's `true`, then all nodes up to the filter target will have `autoExpand` flag.\n * - If it's an instance of `FilterTargetGroupingNodeInfo`, then all nodes up to the grouping node that matches this property,\n * will have `autoExpand` flag.\n */\n autoExpand?: boolean | FilterTargetGroupingNodeInfo;\n}\n\n/**\n * A path of hierarchy node identifiers for filtering the hierarchy with additional options.\n * @public\n */\nexport type HierarchyFilteringPath = HierarchyNodeIdentifiersPath | { path: HierarchyNodeIdentifiersPath; options?: HierarchyFilteringPathOptions };\n/** @public */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport namespace HierarchyFilteringPath {\n /**\n * Normalizes the hierarchy filtering path to the object form.\n * @public\n */\n export function normalize(source: HierarchyFilteringPath): Exclude<HierarchyFilteringPath, HierarchyNodeIdentifiersPath> {\n if (Array.isArray(source)) {\n return { path: source };\n }\n return source;\n }\n\n /**\n * Merges two given `HierarchyFilteringPathOptions` objects.\n * - if both inputs are `undefined`, `undefined` is returned,\n * - else if one of the inputs is `undefined`, the other one is returned.\n * - else, merge each option individually.\n *\n * For the `autoExpand` attribute, the merge chooses to auto-expand as deep as the deepest input:\n * - if any one of the inputs is `true`, return `true`,\n * - else if both inputs are objects, return the one with the greater `depth` attribute.\n * - else if one input is an object, return it.\n * - else, return `false` or `undefined`.\n *\n * @public\n */\n export function mergeOptions(\n lhs: HierarchyFilteringPathOptions | undefined,\n rhs: HierarchyFilteringPathOptions | undefined,\n ): HierarchyFilteringPathOptions | undefined {\n if (!lhs || !rhs) {\n return lhs ?? rhs;\n }\n\n return {\n autoExpand: ((): HierarchyFilteringPathOptions[\"autoExpand\"] => {\n if (rhs.autoExpand === true || lhs.autoExpand === true) {\n return true;\n }\n if (typeof lhs.autoExpand === \"object\") {\n if (typeof rhs.autoExpand === \"object\" && rhs.autoExpand.depth > lhs.autoExpand.depth) {\n return rhs.autoExpand;\n }\n return lhs.autoExpand;\n }\n return rhs.autoExpand;\n })(),\n };\n }\n}\n\n/**\n * An utility that extracts filtering properties from given root level filtering props or\n * the parent node. Returns `undefined` if filtering props are not present.\n * @public\n * @deprecated in 1.3. Use `createHierarchyFilteringHelper` instead.\n */\n/* c8 ignore start */\nexport function extractFilteringProps(\n rootLevelFilteringProps: HierarchyFilteringPath[],\n parentNode: Pick<NonGroupingHierarchyNode, \"filtering\"> | undefined,\n):\n | {\n filteredNodePaths: HierarchyFilteringPath[];\n hasFilterTargetAncestor: boolean;\n }\n | undefined {\n return extractFilteringPropsInternal(rootLevelFilteringProps, parentNode);\n}\n/* c8 ignore end */\n\nfunction extractFilteringPropsInternal(\n rootLevelFilteringProps: HierarchyFilteringPath[] | undefined,\n parentNode: Pick<NonGroupingHierarchyNode, \"filtering\"> | undefined,\n):\n | {\n filteredNodePaths: HierarchyFilteringPath[];\n hasFilterTargetAncestor: boolean;\n }\n | undefined {\n if (!parentNode) {\n return rootLevelFilteringProps ? { filteredNodePaths: rootLevelFilteringProps, hasFilterTargetAncestor: false } : undefined;\n }\n return parentNode.filtering?.filteredChildrenIdentifierPaths\n ? {\n filteredNodePaths: parentNode.filtering.filteredChildrenIdentifierPaths,\n hasFilterTargetAncestor: !!parentNode.filtering.hasFilterTargetAncestor || !!parentNode.filtering.isFilterTarget,\n }\n : undefined;\n}\n\n/**\n * Creates a set of utilities for making it easier to filter the given hierarchy\n * level.\n *\n * @public\n */\nexport function createHierarchyFilteringHelper(\n rootLevelFilteringProps: HierarchyFilteringPath[] | undefined,\n parentNode: Pick<NonGroupingHierarchyNode, \"filtering\"> | undefined,\n) {\n const filteringProps = extractFilteringPropsInternal(rootLevelFilteringProps, parentNode);\n const hasFilter = !!filteringProps;\n return {\n /**\n * Returns a flag indicating if the hierarchy level is filtered.\n */\n hasFilter,\n\n /**\n * Returns a flag indicating whether this hierarchy level has an ancestor node\n * that is a filter target. That generally means that this and all downstream hierarchy\n * levels should be displayed without filter being applied to them, even if filter paths\n * say otherwise.\n */\n hasFilterTargetAncestor: filteringProps?.hasFilterTargetAncestor ?? false,\n\n /**\n * Returns a list of hierarchy node identifiers that apply specifically for this\n * hierarchy level. Returns `undefined` if filtering is not applied to this level.\n */\n getChildNodeFilteringIdentifiers: () => {\n if (!hasFilter) {\n return undefined;\n }\n return filteringProps.filteredNodePaths\n .map(HierarchyFilteringPath.normalize)\n .filter(({ path }) => path.length > 0)\n .map(({ path }) => path[0]);\n },\n\n /**\n * When a hierarchy node is created for a filtered hierarchy level, it needs some attributes (e.g. `filtering`\n * and `autoExpand`) to be set based on the filter paths and filtering options. This function calculates\n * these props for a child node based on its key or path matcher.\n *\n * When using `pathMatcher` prop, callers have more flexibility to decide whether the given `HierarchyNodeIdentifier` applies\n * to their node. For example, only some parts of the identifier can be checked for improved performance. Otherwise, the\n * `nodeKey` prop can be used to check the whole identifier.\n */\n createChildNodeProps: (\n props:\n | {\n nodeKey: InstancesNodeKey | GenericNodeKey;\n }\n | {\n pathMatcher: (identifier: HierarchyNodeIdentifier) => boolean;\n },\n ): Pick<HierarchyNode, \"filtering\" | \"autoExpand\"> | undefined => {\n if (!hasFilter) {\n return undefined;\n }\n const reducer = new MatchingFilteringPathsReducer(filteringProps?.hasFilterTargetAncestor);\n filteringProps.filteredNodePaths.forEach((filteredPath) => {\n const normalizedPath = HierarchyFilteringPath.normalize(filteredPath);\n if (\n \"nodeKey\" in props &&\n ((HierarchyNodeKey.isGeneric(props.nodeKey) && HierarchyNodeIdentifier.equal(normalizedPath.path[0], props.nodeKey)) ||\n (HierarchyNodeKey.isInstances(props.nodeKey) && props.nodeKey.instanceKeys.some((ik) => HierarchyNodeIdentifier.equal(normalizedPath.path[0], ik))))\n ) {\n reducer.accept(normalizedPath);\n } else if (\"pathMatcher\" in props && props.pathMatcher(normalizedPath.path[0])) {\n reducer.accept(normalizedPath);\n }\n });\n return reducer.getNodeProps();\n },\n\n /**\n * Similar to `createChildNodeProps`, but takes an async `pathMatcher` prop.\n */\n createChildNodePropsAsync: async (props: {\n pathMatcher: (identifier: HierarchyNodeIdentifier) => boolean | Promise<boolean>;\n }): Promise<Pick<HierarchyNode, \"filtering\" | \"autoExpand\"> | undefined> => {\n if (!hasFilter) {\n return undefined;\n }\n const reducer = new MatchingFilteringPathsReducer(filteringProps?.hasFilterTargetAncestor);\n for (const filteredChildrenNodeIdentifierPath of filteringProps.filteredNodePaths) {\n const normalizedPath = HierarchyFilteringPath.normalize(filteredChildrenNodeIdentifierPath);\n /* c8 ignore next 3 */\n if (normalizedPath.path.length === 0) {\n continue;\n }\n\n const matchesPossiblyPromise = props.pathMatcher(normalizedPath.path[0]);\n if (matchesPossiblyPromise instanceof Promise) {\n if (!(await matchesPossiblyPromise)) {\n continue;\n }\n }\n if (!matchesPossiblyPromise) {\n continue;\n }\n\n reducer.accept(normalizedPath);\n }\n return reducer.getNodeProps();\n },\n };\n}\n\ntype NormalizedFilteringPath = ReturnType<(typeof HierarchyFilteringPath)[\"normalize\"]>;\nclass MatchingFilteringPathsReducer {\n private _filteredChildrenIdentifierPaths = new Array<NormalizedFilteringPath>();\n private _isFilterTarget = false;\n private _filterTargetOptions = undefined as HierarchyFilteringPathOptions | undefined;\n private _needsAutoExpand = false;\n\n public constructor(private _hasFilterTargetAncestor: boolean) {}\n\n public accept({ path, options }: NormalizedFilteringPath) {\n if (path.length === 1) {\n this._isFilterTarget = true;\n this._filterTargetOptions = HierarchyFilteringPath.mergeOptions(this._filterTargetOptions, options);\n } else if (path.length > 1) {\n this._filteredChildrenIdentifierPaths.push({ path: path.slice(1), options });\n if (options?.autoExpand) {\n this._needsAutoExpand = true;\n }\n }\n }\n public getNodeProps(): Pick<HierarchyNode, \"filtering\" | \"autoExpand\"> {\n return {\n ...(this._hasFilterTargetAncestor || this._isFilterTarget || this._filteredChildrenIdentifierPaths.length > 0\n ? {\n filtering: {\n ...(this._hasFilterTargetAncestor ? { hasFilterTargetAncestor: true } : undefined),\n ...(this._isFilterTarget ? { isFilterTarget: true, filterTargetOptions: this._filterTargetOptions } : undefined),\n ...(this._filteredChildrenIdentifierPaths.length > 0 ? { filteredChildrenIdentifierPaths: this._filteredChildrenIdentifierPaths } : undefined),\n },\n }\n : undefined),\n ...(this._needsAutoExpand ? { autoExpand: true } : undefined),\n };\n }\n}\n"]}
1
+ {"version":3,"file":"HierarchyFiltering.js","sourceRo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C,SAAS,CAAC;YACd,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;SACjF,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { HierarchyNode, NonGroupingHierarchyNode } from \"./HierarchyNode.js\";\nimport { HierarchyNodeIdentifier, HierarchyNodeIdentifiersPath } from \"./HierarchyNodeIdentifier.js\";\nimport { GenericNodeKey, HierarchyNodeKey, InstancesNodeKey } from \"./HierarchyNodeKey.js\";\n\n/** @public */\nexport interface FilteringPathAutoExpandOption {\n /**\n * Depth up to which nodes in the hierarchy should be expanded.\n *\n * If `includeGroupingNodes` is set to true, then depth should take into account the number of grouping nodes in hierarchy.\n */\n depth: number;\n /**\n * Whether or not `depth` includes grouping nodes.\n *\n * Use when you want to autoExpand only some of the grouping nodes.\n *\n * **Use case example:**\n *\n * You want to `autoExpand` only `Node1` and `GroupingNode1` in the following hierarchy:\n * - Node1\n * - GroupingNode1\n * - GroupingNode2\n * - Element1\n * - Element2\n * Then you provide `autoExpand: { depth: 2, includeGroupingNodes: true }`\n */\n includeGroupingNodes?: boolean;\n}\n\n/** @public */\nexport interface HierarchyFilteringPathOptions {\n /**\n * This option specifies the way `autoExpand` flag should be assigned to nodes in the filtered hierarchy.\n * - If it's `false` or `undefined`, nodes have no 'autoExpand' flag.\n * - If it's `true`, then all nodes up to the filter target will have `autoExpand` flag.\n * - If it's an instance of `FilteringPathAutoExpandOption`, then all nodes up to and including `depth` will have `autoExpand` flag.\n */\n autoExpand?: boolean | FilteringPathAutoExpandOption;\n}\n\nnamespace HierarchyFilteringPathOptions {\n export function mergeAutoExpandOptions(\n lhs: HierarchyFilteringPathOptions[\"autoExpand\"],\n rhs: HierarchyFilteringPathOptions[\"autoExpand\"],\n ): HierarchyFilteringPathOptions[\"autoExpand\"] {\n if (rhs === true || lhs === true) {\n return true;\n }\n if (!rhs || !lhs) {\n return !!rhs ? rhs : lhs;\n }\n\n if (!lhs.includeGroupingNodes) {\n if (!rhs.includeGroupingNodes) {\n return lhs.depth > rhs.depth ? lhs : rhs;\n }\n return lhs;\n }\n if (!rhs.includeGroupingNodes) {\n return rhs;\n }\n return lhs.depth > rhs.depth ? lhs : rhs;\n }\n}\n\n/**\n * A path of hierarchy node identifiers for filtering the hierarchy with additional options.\n * @public\n */\nexport type HierarchyFilteringPath = HierarchyNodeIdentifiersPath | { path: HierarchyNodeIdentifiersPath; options?: HierarchyFilteringPathOptions };\n/** @public */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport namespace HierarchyFilteringPath {\n /**\n * Normalizes the hierarchy filtering path to the object form.\n * @public\n */\n export function normalize(source: HierarchyFilteringPath): Exclude<HierarchyFilteringPath, HierarchyNodeIdentifiersPath> {\n if (Array.isArray(source)) {\n return { path: source };\n }\n return source;\n }\n\n /**\n * Merges two given `HierarchyFilteringPathOptions` objects.\n * - if both inputs are `undefined`, `undefined` is returned,\n * - else if one of the inputs is `undefined`, the other one is returned.\n * - else, merge each option individually.\n *\n * For the `autoExpand` attribute, the merge chooses to auto-expand as deep as the deepest input:\n * - if any one of the inputs is `true`, return `true`,\n * - else if only one of the inputs is an object, return it,\n * - else if both inputs are falsy, return `false` or `undefined`,\n * - else:\n * - if only one of the inputs has `includeGroupingNodes` set to `true` or `key` defined, return the one that has only `depth` set,\n * - else return the one with greater `depth`.\n *\n * @public\n */\n export function mergeOptions(\n lhs: HierarchyFilteringPathOptions | undefined,\n rhs: HierarchyFilteringPathOptions | undefined,\n ): HierarchyFilteringPathOptions | undefined {\n if (!lhs || !rhs) {\n return lhs ?? rhs;\n }\n\n return {\n autoExpand: HierarchyFilteringPathOptions.mergeAutoExpandOptions(lhs.autoExpand, rhs.autoExpand),\n };\n }\n}\n\n/**\n * An utility that extracts filtering properties from given root level filtering props or\n * the parent node. Returns `undefined` if filtering props are not present.\n * @public\n * @deprecated in 1.3. Use `createHierarchyFilteringHelper` instead.\n */\n/* c8 ignore start */\nexport function extractFilteringProps(\n rootLevelFilteringProps: HierarchyFilteringPath[],\n parentNode: Pick<NonGroupingHierarchyNode, \"filtering\"> | undefined,\n):\n | {\n filteredNodePaths: HierarchyFilteringPath[];\n hasFilterTargetAncestor: boolean;\n }\n | undefined {\n return extractFilteringPropsInternal(rootLevelFilteringProps, parentNode);\n}\n/* c8 ignore end */\n\nfunction extractFilteringPropsInternal(\n rootLevelFilteringProps: HierarchyFilteringPath[] | undefined,\n parentNode: Pick<NonGroupingHierarchyNode, \"filtering\"> | undefined,\n):\n | {\n filteredNodePaths: HierarchyFilteringPath[];\n hasFilterTargetAncestor: boolean;\n }\n | undefined {\n if (!parentNode) {\n return rootLevelFilteringProps ? { filteredNodePaths: rootLevelFilteringProps, hasFilterTargetAncestor: false } : undefined;\n }\n return parentNode.filtering?.filteredChildrenIdentifierPaths\n ? {\n filteredNodePaths: parentNode.filtering.filteredChildrenIdentifierPaths,\n hasFilterTargetAncestor: !!parentNode.filtering.hasFilterTargetAncestor || !!parentNode.filtering.isFilterTarget,\n }\n : undefined;\n}\n\n/**\n * Creates a set of utilities for making it easier to filter the given hierarchy\n * level.\n *\n * @public\n */\nexport function createHierarchyFilteringHelper(\n rootLevelFilteringProps: HierarchyFilteringPath[] | undefined,\n parentNode: Pick<NonGroupingHierarchyNode, \"filtering\"> | undefined,\n) {\n const filteringProps = extractFilteringPropsInternal(rootLevelFilteringProps, parentNode);\n const hasFilter = !!filteringProps;\n return {\n /**\n * Returns a flag indicating if the hierarchy level is filtered.\n */\n hasFilter,\n\n /**\n * Returns a flag indicating whether this hierarchy level has an ancestor node\n * that is a filter target. That generally means that this and all downstream hierarchy\n * levels should be displayed without filter being applied to them, even if filter paths\n * say otherwise.\n */\n hasFilterTargetAncestor: filteringProps?.hasFilterTargetAncestor ?? false,\n\n /**\n * Returns a list of hierarchy node identifiers that apply specifically for this\n * hierarchy level. Returns `undefined` if filtering is not applied to this level.\n */\n getChildNodeFilteringIdentifiers: () => {\n if (!hasFilter) {\n return undefined;\n }\n return filteringProps.filteredNodePaths\n .map(HierarchyFilteringPath.normalize)\n .filter(({ path }) => path.length > 0)\n .map(({ path }) => path[0]);\n },\n\n /**\n * When a hierarchy node is created for a filtered hierarchy level, it needs some attributes (e.g. `filtering`\n * and `autoExpand`) to be set based on the filter paths and filtering options. This function calculates\n * these props for a child node based on its key or path matcher.\n *\n * When using `pathMatcher` prop, callers have more flexibility to decide whether the given `HierarchyNodeIdentifier` applies\n * to their node. For example, only some parts of the identifier can be checked for improved performance. Otherwise, the\n * `nodeKey` prop can be used to check the whole identifier.\n */\n createChildNodeProps: (\n props:\n | {\n nodeKey: InstancesNodeKey | GenericNodeKey;\n }\n | {\n pathMatcher: (identifier: HierarchyNodeIdentifier) => boolean;\n },\n ): NodeProps | undefined => {\n if (!hasFilter) {\n return undefined;\n }\n const reducer = new MatchingFilteringPathsReducer(filteringProps?.hasFilterTargetAncestor);\n filteringProps.filteredNodePaths.forEach((filteredPath) => {\n const normalizedPath = HierarchyFilteringPath.normalize(filteredPath);\n if (\n \"nodeKey\" in props &&\n ((HierarchyNodeKey.isGeneric(props.nodeKey) && HierarchyNodeIdentifier.equal(normalizedPath.path[0], props.nodeKey)) ||\n (HierarchyNodeKey.isInstances(props.nodeKey) && props.nodeKey.instanceKeys.some((ik) => HierarchyNodeIdentifier.equal(normalizedPath.path[0], ik))))\n ) {\n reducer.accept(normalizedPath);\n } else if (\"pathMatcher\" in props && props.pathMatcher(normalizedPath.path[0])) {\n reducer.accept(normalizedPath);\n }\n });\n return reducer.getNodeProps();\n },\n\n /**\n * Similar to `createChildNodeProps`, but takes an async `pathMatcher` prop.\n */\n createChildNodePropsAsync: (props: {\n pathMatcher: (identifier: HierarchyNodeIdentifier) => boolean | Promise<boolean>;\n }): Promise<NodeProps | undefined> | NodeProps | undefined => {\n if (!hasFilter) {\n return undefined;\n }\n const reducer = new MatchingFilteringPathsReducer(filteringProps?.hasFilterTargetAncestor);\n const matchedPathPromises = new Array<Promise<NormalizedFilteringPath | undefined>>();\n for (const filteredChildrenNodeIdentifierPath of filteringProps.filteredNodePaths) {\n const normalizedPath = HierarchyFilteringPath.normalize(filteredChildrenNodeIdentifierPath);\n /* c8 ignore next 3 */\n if (normalizedPath.path.length === 0) {\n continue;\n }\n\n const matchesPossiblyPromise = props.pathMatcher(normalizedPath.path[0]);\n if (matchesPossiblyPromise instanceof Promise) {\n matchedPathPromises.push(matchesPossiblyPromise.then((matches) => (matches ? normalizedPath : undefined)));\n continue;\n }\n if (!matchesPossiblyPromise) {\n continue;\n }\n\n reducer.accept(normalizedPath);\n }\n if (matchedPathPromises.length === 0) {\n return reducer.getNodeProps();\n }\n return Promise.all(matchedPathPromises)\n .then((matchedPath) => matchedPath.forEach((normalizedPath) => normalizedPath && reducer.accept(normalizedPath)))\n .then(() => reducer.getNodeProps());\n },\n };\n}\n\n/** @public */\nexport type NodeProps = Pick<HierarchyNode, \"autoExpand\" | \"filtering\"> & { filtering?: { autoExpandDepth?: number; includeGroupingNodes?: boolean } };\n\ntype NormalizedFilteringPath = ReturnType<(typeof HierarchyFilteringPath)[\"normalize\"]>;\n\nclass MatchingFilteringPathsReducer {\n private _filteredChildrenIdentifierPaths = new Array<NormalizedFilteringPath>();\n private _isFilterTarget = false;\n private _filterTargetOptions = undefined as HierarchyFilteringPathOptions | undefined;\n private _needsAutoExpand: HierarchyFilteringPathOptions[\"autoExpand\"] = false;\n\n public constructor(private _hasFilterTargetAncestor: boolean) {}\n\n public accept({ path, options }: NormalizedFilteringPath) {\n if (path.length === 1) {\n this._isFilterTarget = true;\n this._filterTargetOptions = HierarchyFilteringPath.mergeOptions(this._filterTargetOptions, options);\n } else if (path.length > 1) {\n this._filteredChildrenIdentifierPaths.push({ path: path.slice(1), options });\n this._needsAutoExpand = HierarchyFilteringPathOptions.mergeAutoExpandOptions(options?.autoExpand, this._needsAutoExpand);\n }\n }\n public getNodeProps(): NodeProps {\n return {\n ...(this._hasFilterTargetAncestor || this._isFilterTarget || this._filteredChildrenIdentifierPaths.length > 0\n ? {\n filtering: {\n ...(this._hasFilterTargetAncestor ? { hasFilterTargetAncestor: true } : undefined),\n ...(this._isFilterTarget ? { isFilterTarget: true, filterTargetOptions: this._filterTargetOptions } : undefined),\n ...(this._filteredChildrenIdentifierPaths.length > 0 ? { filteredChildrenIdentifierPaths: this._filteredChildrenIdentifierPaths } : undefined),\n ...(this._needsAutoExpand && this._needsAutoExpand !== true\n ? {\n autoExpandDepth: this._needsAutoExpand.depth,\n includeGroupingNodes: this._needsAutoExpand.includeGroupingNodes ? true : false,\n }\n : undefined),\n },\n }\n : undefined),\n ...(this._needsAutoExpand ? { autoExpand: !!this._needsAutoExpand } : undefined),\n };\n }\n}\n"]}
@@ -1,26 +1,28 @@
1
+ import { Observable } from "rxjs";
1
2
  import { ECClassHierarchyInspector, InstanceKey } from "@itwin/presentation-shared";
2
3
  import { HierarchyFilteringPath } from "../HierarchyFiltering.js";
3
- import { DefineHierarchyLevelProps, HierarchyDefinition, HierarchyLevelDefinition, InstanceNodesQueryDefinition, NodeParser, NodePostProcessor, NodePreProcessor } from "./IModelHierarchyDefinition.js";
4
+ import { DefineHierarchyLevelProps, HierarchyLevelDefinition, InstanceNodesQueryDefinition } from "../imodel/IModelHierarchyDefinition.js";
5
+ import { RxjsHierarchyDefinition, RxjsNodeParser, RxjsNodePostProcessor, RxjsNodePreProcessor } from "../internal/RxjsHierarchyDefinition.js";
4
6
  interface FilteringHierarchyDefinitionProps {
5
7
  imodelAccess: ECClassHierarchyInspector & {
6
8
  imodelKey: string;
7
9
  };
8
- source: HierarchyDefinition;
10
+ source: RxjsHierarchyDefinition;
9
11
  nodeIdentifierPaths: HierarchyFilteringPath[];
10
- nodesParser?: NodeParser;
12
+ nodesParser?: RxjsNodeParser;
11
13
  }
12
14
  /** @internal */
13
- export declare class FilteringHierarchyDefinition implements HierarchyDefinition {
15
+ export declare class FilteringHierarchyDefinition implements RxjsHierarchyDefinition {
14
16
  private _imodelAccess;
15
17
  private _source;
16
18
  private _nodeIdentifierPaths;
17
19
  private _nodesParser;
18
20
  constructor(props: FilteringHierarchyDefinitionProps);
19
- get preProcessNode(): NodePreProcessor;
21
+ get preProcessNode(): RxjsNodePreProcessor;
20
22
  private shouldExpandGroupingNode;
21
- get postProcessNode(): NodePostProcessor;
22
- get parseNode(): NodeParser;
23
- defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition>;
23
+ get postProcessNode(): RxjsNodePostProcessor;
24
+ get parseNode(): RxjsNodeParser;
25
+ defineHierarchyLevel(props: DefineHierarchyLevelProps): Observable<HierarchyLevelDefinition>;
24
26
  }
25
27
  /** @internal */
26
28
  export declare const ECSQL_COLUMN_NAME_FilterECInstanceId = "FilterECInstanceId";
@@ -1 +1 @@
1
- {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAkC,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAIlG,OAAO,EACL,yBAAyB,EAEzB,mBAAmB,EAEnB,wBAAwB,EAExB,4BAA4B,EAC5B,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAKxC,UAAU,iCAAiC;IACzC,YAAY,EAAE,yBAAyB,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,MAAM,EAAE,mBAAmB,CAAC;IAC5B,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;IAC9C,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED,gBAAgB;AAChB,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,oBAAoB,CAA2B;IACvD,OAAO,CAAC,YAAY,CAAa;gBAEd,KAAK,EAAE,iCAAiC;IAO3D,IAAW,cAAc,IAAI,gBAAgB,CAS5C;IAED,OAAO,CAAC,wBAAwB;IA2ChC,IAAW,eAAe,IAAI,iBAAiB,CAS9C;IAED,IAAW,SAAS,IAAI,UAAU,CAuCjC;IAEY,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAsGvG;AAED,gBAAgB;AAEhB,eAAO,MAAM,oCAAoC,uBAAuB,CAAC;AAEzE,gBAAgB;AAEhB,eAAO,MAAM,iCAAiC,oBAAoB,CAAC;AAenE,gBAAgB;AAChB,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,WAAW,EAAE,GAAG,4BAA4B,CAgC7I;AAED,gBAAgB;AAChB,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,4BAA4B,GAAG,4BAA4B,CAc1G"}
1
+ {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuD,UAAU,EAAe,MAAM,MAAM,CAAC;AAEpG,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAkC,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlG,OAAO,EACL,yBAAyB,EAEzB,wBAAwB,EAExB,4BAA4B,EAC7B,MAAM,wCAAwC,CAAC;AAKhD,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAE9I,UAAU,iCAAiC;IACzC,YAAY,EAA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