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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @itwin/presentation-hierarchies
2
2
 
3
+ ## 2.0.0-alpha.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1042](https://github.com/iTwin/presentation/pull/1042): Version bump
8
+ - Updated dependencies:
9
+ - @itwin/presentation-shared@2.0.0-alpha.2
10
+
11
+ ## 2.0.0-alpha.3
12
+
13
+ ### Patch Changes
14
+
15
+ - [#1031](https://github.com/iTwin/presentation/pull/1031): Version bump
16
+
3
17
  ## 2.0.0-alpha.2
4
18
 
5
19
  ### Patch Changes
@@ -38,6 +52,55 @@
38
52
  - Updated dependencies:
39
53
  - @itwin/presentation-shared@2.0.0-alpha.0
40
54
 
55
+ ## 1.7.2
56
+
57
+ ### Patch Changes
58
+
59
+ - [#1039](https://github.com/iTwin/presentation/pull/1039): Bump iTwin.js core dependencies to `^5.1.1`.
60
+ - Updated dependencies:
61
+ - @itwin/presentation-shared@1.2.3
62
+
63
+ ## 1.7.1
64
+
65
+ ### Patch Changes
66
+
67
+ - [#1024](https://github.com/iTwin/presentation/pull/1024): Update `depthInPath` documentation. Clarified that it does not set auto-expand for node that is at `depthInPath` position.
68
+
69
+ ## 1.7.0
70
+
71
+ ### Minor Changes
72
+
73
+ - 8f7d200926b93e862276e1f978f6c891691e0dae: Refactored specifying the depth / level to which filtering path should be auto-expanded.
74
+
75
+ - Deprecated `FilteringPathAutoExpandOption` and `FilterTargetGroupingNodeInfo`.
76
+ - Added `FilteringPathAutoExpandDepthInPath` and `FilteringPathAutoExpandDepthInHierarchy` which should be used instead.
77
+
78
+ Migration:
79
+
80
+ ```ts
81
+ const pathExpandedToInstanceInPath: HierarchyFilteringPath = {
82
+ path: [instanceKey1, instanceKey2, instanceKey3],
83
+ options: {
84
+ // deprecated:
85
+ autoExpand: { depth: 1 },
86
+ // do this instead:
87
+ autoExpand: { depthInPath: 1 },
88
+ },
89
+ };
90
+
91
+ const pathExpandedToGroupingNode: HierarchyFilteringPath = {
92
+ path: [instanceKey1, instanceKey2, instanceKey3],
93
+ options: {
94
+ // deprecated:
95
+ autoExpand: { depth: 1, key: groupingNodeKey },
96
+ // also deprecated:
97
+ autoExpand: { depth: 1, includeGroupingNodes: true },
98
+ // do this instead:
99
+ autoExpand: { depthInHierarchy: 1 },
100
+ },
101
+ };
102
+ ```
103
+
41
104
  ## 1.6.1
42
105
 
43
106
  ### Patch Changes
@@ -49,9 +112,11 @@
49
112
  ### Minor Changes
50
113
 
51
114
  - 69a2db67917f84e99d532e8e9aabbc02ec262d91: `HierarchyFilteringPathOptions.autoExpand` is now of type:
115
+
52
116
  ```ts
53
117
  autoExpand?: { depth: number } | boolean;
54
118
  ```
119
+
55
120
  When `depth` is set, only nodes up to specified `depth` in `HierarchyFilteringPath` will have `autoExpand` option set.
56
121
 
57
122
  ## 1.5.1
@@ -2,19 +2,24 @@ import { HierarchyNode, NonGroupingHierarchyNode } from "./HierarchyNode.js";
2
2
  import { HierarchyNodeIdentifier, HierarchyNodeIdentifiersPath } from "./HierarchyNodeIdentifier.js";
3
3
  import { GenericNodeKey, InstancesNodeKey } from "./HierarchyNodeKey.js";
4
4
  /** @public */
5
- export interface FilteringPathAutoExpandOption {
5
+ export interface FilteringPathAutoExpandDepthInPath {
6
6
  /**
7
- * Depth up to which nodes in the hierarchy should be expanded.
7
+ * Depth that tells which nodes in the filtering path should be expanded.
8
8
  *
9
- * If `includeGroupingNodes` is set to true, then depth should take into account the number of grouping nodes in hierarchy.
9
+ * Use when you want to expand up to specific instance node and don't care about grouping nodes.
10
+ *
11
+ * **NOTE**: All nodes that are up to `depthInPath` will be expanded. Node at the `depthInPath` position won't be expanded.
10
12
  */
11
- depth: number;
13
+ depthInPath: number;
14
+ }
15
+ /** @public */
16
+ export interface FilteringPathAutoExpandDepthInHierarchy {
12
17
  /**
13
- * Whether or not `depth` includes grouping nodes.
18
+ * Depth that tells which nodes in the hierarchy should be expanded.
14
19
  *
15
- * Use when you want to autoExpand only some of the grouping nodes.
20
+ * This should take into account the number of grouping nodes in hierarchy.
16
21
  *
17
- * **Use case example:**
22
+ * * **Use case example:**
18
23
  *
19
24
  * You want to `autoExpand` only `Node1` and `GroupingNode1` in the following hierarchy:
20
25
  * - Node1
@@ -22,9 +27,13 @@ export interface FilteringPathAutoExpandOption {
22
27
  * - GroupingNode2
23
28
  * - Element1
24
29
  * - Element2
25
- * Then you provide `autoExpand: { depth: 2, includeGroupingNodes: true }`
30
+ * Then you provide `autoExpand: { depthInHierarchy: 2 }`
31
+ *
32
+ * To get the correct depth use `HierarchyNode.parentKeys.length`.
33
+ *
34
+ * **NOTE**: All nodes that are up to and including `depthInHierarchy` will be expanded.
26
35
  */
27
- includeGroupingNodes?: boolean;
36
+ depthInHierarchy: number;
28
37
  }
29
38
  /** @public */
30
39
  export interface HierarchyFilteringPathOptions {
@@ -32,9 +41,10 @@ export interface HierarchyFilteringPathOptions {
32
41
  * This option specifies the way `autoExpand` flag should be assigned to nodes in the filtered hierarchy.
33
42
  * - If it's `false` or `undefined`, nodes have no 'autoExpand' flag.
34
43
  * - If it's `true`, then all nodes up to the filter target will have `autoExpand` flag.
35
- * - If it's an instance of `FilteringPathAutoExpandOption`, then all nodes up to and including `depth` will have `autoExpand` flag.
44
+ * - If it's an instance of `FilteringPathAutoExpandDepthInPath`, then all nodes up to `depthInPath` will have `autoExpand` flag.
45
+ * - If it's an instance of `FilteringPathAutoExpandDepthInHierarchy`, then all nodes up to and including `depthInHierarchy` will have `autoExpand` flag.
36
46
  */
37
- autoExpand?: boolean | FilteringPathAutoExpandOption;
47
+ autoExpand?: boolean | FilteringPathAutoExpandDepthInHierarchy | FilteringPathAutoExpandDepthInPath;
38
48
  }
39
49
  /**
40
50
  * A path of hierarchy node identifiers for filtering the hierarchy with additional options.
@@ -62,8 +72,8 @@ export declare namespace HierarchyFilteringPath {
62
72
  * - else if only one of the inputs is an object, return it,
63
73
  * - else if both inputs are falsy, return `false` or `undefined`,
64
74
  * - 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`.
75
+ * - if only one of the inputs has `includeGroupingNodes` set to `true` or `key` defined or `depthInHierarchy` set, return the other one,
76
+ * - else return the one with greater `depth`, `depthInPath` or `depthInHierarchy`.
67
77
  *
68
78
  * @public
69
79
  */
@@ -85,7 +95,7 @@ export declare function extractFilteringProps(rootLevelFilteringProps: Hierarchy
85
95
  *
86
96
  * @public
87
97
  */
88
- export declare function createHierarchyFilteringHelper(rootLevelFilteringProps: HierarchyFilteringPath[] | undefined, parentNode: Pick<NonGroupingHierarchyNode, "filtering"> | undefined): {
98
+ export declare function createHierarchyFilteringHelper(rootLevelFilteringProps: HierarchyFilteringPath[] | undefined, parentNode: Pick<NonGroupingHierarchyNode, "filtering" | "parentKeys"> | undefined): {
89
99
  /**
90
100
  * Returns a flag indicating if the hierarchy level is filtered.
91
101
  */
@@ -115,19 +125,12 @@ export declare function createHierarchyFilteringHelper(rootLevelFilteringProps:
115
125
  nodeKey: InstancesNodeKey | GenericNodeKey;
116
126
  } | {
117
127
  pathMatcher: (identifier: HierarchyNodeIdentifier) => boolean;
118
- }) => NodeProps | undefined;
128
+ }) => Pick<HierarchyNode, "autoExpand" | "filtering"> | undefined;
119
129
  /**
120
130
  * Similar to `createChildNodeProps`, but takes an async `pathMatcher` prop.
121
131
  */
122
132
  createChildNodePropsAsync: (props: {
123
133
  pathMatcher: (identifier: HierarchyNodeIdentifier) => boolean | Promise<boolean>;
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
- };
134
+ }) => Promise<Pick<HierarchyNode, "autoExpand" | "filtering"> | undefined> | Pick<HierarchyNode, "autoExpand" | "filtering"> | undefined;
132
135
  };
133
136
  //# 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,EAAoB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE3F,cAAc;AACd,MAAM,WAAW,6BAA6B;IAC5C;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;;;OAcG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,cAAc;AACd,MAAM,WAAW,6BAA6B;IAC5C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,6BAA6B,CAAC;CACtD;AA2BD;;;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;;;;;;;;;;;;;;;OAeG;IACH,SAAgB,YAAY,CAC1B,GAAG,EAAE,6BAA6B,GAAG,SAAS,EAC9C,GAAG,EAAE,6BAA6B,GAAG,SAAS,GAC7C,6BAA6B,GAAG,SAAS,CAQ3C;CACF;AAED;;;;;GAKG;AAEH,wBAAgB,qBAAqB,CACnC,uBAAuB,EAAE,sBAAsB,E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GAAG,SAAS;IAKhF;;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,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG,SAAS;IAoB9D;;OAEG;uCACgC;QACjC,WAAW,EAAE,CAAC,UAAU,EAAE,uBAAuB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAClF,KAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,WAAW,CAAC,GAAG,SAAS;EAgCzI"}
@@ -18,16 +18,20 @@ var HierarchyFilteringPathOptions;
18
18
  if (!rhs || !lhs) {
19
19
  return !!rhs ? rhs : lhs;
20
20
  }
21
- if (!lhs.includeGroupingNodes) {
22
- if (!rhs.includeGroupingNodes) {
23
- return lhs.depth > rhs.depth ? lhs : rhs;
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;
24
28
  }
25
29
  return lhs;
26
30
  }
27
- if (!rhs.includeGroupingNodes) {
31
+ if (isRhsDepthBasedOnPath) {
28
32
  return rhs;
29
33
  }
30
- return lhs.depth > rhs.depth ? lhs : rhs;
34
+ return lhsDepth > rhsDepth ? lhs : rhs;
31
35
  }
32
36
  HierarchyFilteringPathOptions.mergeAutoExpandOptions = mergeAutoExpandOptions;
33
37
  })(HierarchyFilteringPathOptions || (HierarchyFilteringPathOptions = {}));
@@ -57,8 +61,8 @@ var HierarchyFilteringPath;
57
61
  * - else if only one of the inputs is an object, return it,
58
62
  * - else if both inputs are falsy, return `false` or `undefined`,
59
63
  * - 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`.
64
+ * - if only one of the inputs has `includeGroupingNodes` set to `true` or `key` defined or `depthInHierarchy` set, return the other one,
65
+ * - else return the one with greater `depth`, `depthInPath` or `depthInHierarchy`.
62
66
  *
63
67
  * @public
64
68
  */
@@ -153,7 +157,7 @@ function createHierarchyFilteringHelper(rootLevelFilteringProps, parentNode) {
153
157
  reducer.accept(normalizedPath);
154
158
  }
155
159
  });
156
- return reducer.getNodeProps();
160
+ return reducer.getNodeProps(parentNode);
157
161
  },
158
162
  /**
159
163
  * Similar to `createChildNodeProps`, but takes an async `pathMatcher` prop.
@@ -181,11 +185,11 @@ function createHierarchyFilteringHelper(rootLevelFilteringProps, parentNode) {
181
185
  reducer.accept(normalizedPath);
182
186
  }
183
187
  if (matchedPathPromises.length === 0) {
184
- return reducer.getNodeProps();
188
+ return reducer.getNodeProps(parentNode);
185
189
  }
186
190
  return Promise.all(matchedPathPromises)
187
191
  .then((matchedPath) => matchedPath.forEach((normalizedPath) => normalizedPath && reducer.accept(normalizedPath)))
188
- .then(() => reducer.getNodeProps());
192
+ .then(() => reducer.getNodeProps(parentNode));
189
193
  },
190
194
  };
191
195
  }
@@ -194,21 +198,40 @@ class MatchingFilteringPathsReducer {
194
198
  _filteredChildrenIdentifierPaths = new Array();
195
199
  _isFilterTarget = false;
196
200
  _filterTargetOptions = undefined;
197
- _needsAutoExpand = false;
201
+ _autoExpandOption = false;
198
202
  constructor(_hasFilterTargetAncestor) {
199
203
  this._hasFilterTargetAncestor = _hasFilterTargetAncestor;
200
204
  }
201
- accept({ path, options }) {
205
+ accept(normalizedPath) {
206
+ const { path, options } = normalizedPath;
202
207
  if (path.length === 1) {
203
208
  this._isFilterTarget = true;
204
209
  this._filterTargetOptions = HierarchyFilteringPath.mergeOptions(this._filterTargetOptions, options);
205
210
  }
206
211
  else if (path.length > 1) {
207
212
  this._filteredChildrenIdentifierPaths.push({ path: path.slice(1), options });
208
- this._needsAutoExpand = HierarchyFilteringPathOptions.mergeAutoExpandOptions(options?.autoExpand, this._needsAutoExpand);
213
+ this._autoExpandOption = HierarchyFilteringPathOptions.mergeAutoExpandOptions(options?.autoExpand, this._autoExpandOption);
209
214
  }
210
215
  }
211
- getNodeProps() {
216
+ getNeedsAutoExpand(parentNode) {
217
+ if (this._autoExpandOption === true) {
218
+ return true;
219
+ }
220
+ if (typeof this._autoExpandOption === "object") {
221
+ const parentLength = !parentNode
222
+ ? 0
223
+ : "depthInHierarchy" in this._autoExpandOption
224
+ ? 1 + parentNode.parentKeys.length
225
+ : 1 + parentNode.parentKeys.filter((key) => !HierarchyNodeKey_js_1.HierarchyNodeKey.isGrouping(key)).length;
226
+ const depth = "depthInHierarchy" in this._autoExpandOption
227
+ ? this._autoExpandOption.depthInHierarchy
228
+ : // With `depthInPath` option we don't want to expand node that is at the `depthInPath` position
229
+ this._autoExpandOption.depthInPath - 1;
230
+ return parentLength < depth;
231
+ }
232
+ return false;
233
+ }
234
+ getNodeProps(parentNode) {
212
235
  return {
213
236
  ...(this._hasFilterTargetAncestor || this._isFilterTarget || this._filteredChildrenIdentifierPaths.length > 0
214
237
  ? {
@@ -216,16 +239,10 @@ class MatchingFilteringPathsReducer {
216
239
  ...(this._hasFilterTargetAncestor ? { hasFilterTargetAncestor: true } : undefined),
217
240
  ...(this._isFilterTarget ? { isFilterTarget: true, filterTargetOptions: this._filterTargetOptions } : undefined),
218
241
  ...(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),
225
242
  },
226
243
  }
227
244
  : undefined),
228
- ...(this._needsAutoExpand ? { autoExpand: !!this._needsAutoExpand } : undefined),
245
+ ...(this.getNeedsAutoExpand(parentNode) ? { autoExpand: true } : undefined),
229
246
  };
230
247
  }
231
248
  }
@@ -1 +1 @@
1
- {"version":3,"file":"HierarchyFiltering.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyFiltering.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AA4HhG,sDAUC;AA6BD,wEA4GC;AA5QD,6EAAqG;AACrG,+DAA2F;AAuC3F,IAAU,6BAA6B,CAuBtC;AAvBD,WAAU,6BAA6B;IACrC,SAAgB,sBAAsB,CACpC,GAAgD,EAChD,GAAgD;QAEhD,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACjB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;YAC9B,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;gBAC9B,OAAO,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YAC3C,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;YAC9B,OAAO,GAAG,CAAC;QACb,CAAC;QACD,OAAO,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC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AAS,CAAC;wBAC9I,GAAG,CAAC,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI;4BACzD,CAAC,CAAC;gCACE,eAAe,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK;gCAC5C,oBAAoB,EAAE,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK;6BAChF;4BACH,CAAC,CAAC,SAAS,CAAC;qBACf;iBACF;gBACH,CAAC,CAAC,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
+ {"version":3,"file":"HierarchyFiltering.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyFiltering.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AA4IhG,sDAUC;AA6BD,wEA4GC;AA5RD,6EAAqG;AACrG,+DAA2F;AAkD3F,IAAU,6BAA6B,CA4BtC;AA5BD,WAAU,6BAA6B;IACrC,SAAgB,sBAAsB,CACpC,GAAgD,EAChD,GAAgD;QAEhD,IAAI,GAAG,KAAK,IA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AC,IAAI,CAAC,wBAAwB,IAAI,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,gCAAgC,CAAC,MAAM,GAAG,CAAC;gBAC3G,CAAC,CAAC;oBACE,SAAS,EAAE;wBACT,GAAG,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,uBAAuB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;wBAClF,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,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;SAC5E,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 FilteringPathAutoExpandDepthInPath {\n /**\n * Depth that tells which nodes in the filtering path should be expanded.\n *\n * Use when you want to expand up to specific instance node and don't care about grouping nodes.\n *\n * **NOTE**: All nodes that are up to `depthInPath` will be expanded. Node at the `depthInPath` position won't be expanded.\n */\n depthInPath: number;\n}\n\n/** @public */\nexport interface FilteringPathAutoExpandDepthInHierarchy {\n /**\n * Depth that tells which nodes in the hierarchy should be expanded.\n *\n * This should take into account the number of grouping nodes in hierarchy.\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: { depthInHierarchy: 2 }`\n *\n * To get the correct depth use `HierarchyNode.parentKeys.length`.\n *\n * **NOTE**: All nodes that are up to and including `depthInHierarchy` will be expanded.\n */\n depthInHierarchy: 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 `FilteringPathAutoExpandDepthInPath`, then all nodes up to `depthInPath` will have `autoExpand` flag.\n * - If it's an instance of `FilteringPathAutoExpandDepthInHierarchy`, then all nodes up to and including `depthInHierarchy` will have `autoExpand` flag.\n */\n autoExpand?: boolean | FilteringPathAutoExpandDepthInHierarchy | FilteringPathAutoExpandDepthInPath;\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 const lhsDepth = \"depthInPath\" in lhs ? lhs.depthInPath : lhs.depthInHierarchy;\n const rhsDepth = \"depthInPath\" in rhs ? rhs.depthInPath : rhs.depthInHierarchy;\n const isLhsDepthBasedOnPath = \"depthInPath\" in lhs;\n const isRhsDepthBasedOnPath = \"depthInPath\" in rhs;\n\n if (isLhsDepthBasedOnPath) {\n if (isRhsDepthBasedOnPath) {\n return lhsDepth > rhsDepth ? lhs : rhs;\n }\n return lhs;\n }\n if (isRhsDepthBasedOnPath) {\n return rhs;\n }\n return lhsDepth > rhsDepth ? 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 or `depthInHierarchy` set, return the other one,\n * - else return the one with greater `depth`, `depthInPath` or `depthInHierarchy`.\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\" | \"parentKeys\"> | 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, \"autoExpand\" | \"filtering\"> | 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(parentNode);\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<Pick<HierarchyNode, \"autoExpand\" | \"filtering\"> | undefined> | Pick<HierarchyNode, \"autoExpand\" | \"filtering\"> | 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(parentNode);\n }\n return Promise.all(matchedPathPromises)\n .then((matchedPath) => matchedPath.forEach((normalizedPath) => normalizedPath && reducer.accept(normalizedPath)))\n .then(() => reducer.getNodeProps(parentNode));\n },\n };\n}\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 _autoExpandOption: HierarchyFilteringPathOptions[\"autoExpand\"] = false;\n\n public constructor(private _hasFilterTargetAncestor: boolean) {}\n\n public accept(normalizedPath: NormalizedFilteringPath): void {\n const { path, options } = normalizedPath;\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._autoExpandOption = HierarchyFilteringPathOptions.mergeAutoExpandOptions(options?.autoExpand, this._autoExpandOption);\n }\n }\n\n private getNeedsAutoExpand(parentNode: Pick<NonGroupingHierarchyNode, \"parentKeys\"> | undefined): boolean {\n if (this._autoExpandOption === true) {\n return true;\n }\n if (typeof this._autoExpandOption === \"object\") {\n const parentLength = !parentNode\n ? 0\n : \"depthInHierarchy\" in this._autoExpandOption\n ? 1 + parentNode.parentKeys.length\n : 1 + parentNode.parentKeys.filter((key) => !HierarchyNodeKey.isGrouping(key)).length;\n const depth =\n \"depthInHierarchy\" in this._autoExpandOption\n ? this._autoExpandOption.depthInHierarchy\n : // With `depthInPath` option we don't want to expand node that is at the `depthInPath` position\n this._autoExpandOption.depthInPath - 1;\n\n return parentLength < depth;\n }\n return false;\n }\n\n public getNodeProps(parentNode: Pick<NonGroupingHierarchyNode, \"parentKeys\"> | undefined): Pick<HierarchyNode, \"autoExpand\" | \"filtering\"> {\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.getNeedsAutoExpand(parentNode) ? { autoExpand: true } : undefined),\n };\n }\n}\n"]}
@@ -19,7 +19,6 @@ export declare class FilteringHierarchyDefinition implements RxjsHierarchyDefini
19
19
  private _nodesParser;
20
20
  constructor(props: FilteringHierarchyDefinitionProps);
21
21
  get preProcessNode(): RxjsNodePreProcessor;
22
- private shouldExpandGroupingNode;
23
22
  get postProcessNode(): RxjsNodePostProcessor;
24
23
  get parseNode(): RxjsNodeParser;
25
24
  defineHierarchyLevel(props: DefineHierarchyLevelProps): Observable<HierarchyLevelDefinition>;
@@ -1 +1 @@
1
- {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sour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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,EAAiC,MAAM,0BAA0B,CAAC;AAGjI,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,EAAE,yBAAyB,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,MAAM,EAAE,uBAAuB,CAAC;IAChC,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;IAC9C,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B;AAED,gBAAgB;AAChB,qBAAa,4BAA6B,YAAW,uBAAuB;IAC1E,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,oBAAoB,CAA2B;IACvD,OAAO,CAAC,YAAY,CAAiB;gBAElB,KAAK,EAAE,iCAAiC;IAO3D,IAAW,cAAc,IAAI,oBAAoB,CAYhD;IAED,IAAW,eAAe,IAAI,qBAAqB,CAYlD;IAED,IAAW,SAAS,IAAI,cAAc,CA2CrC;IAEM,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,UAAU,CAAC,wBAAwB,CAAC;CAoGpG;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"}
@@ -39,49 +39,11 @@ class FilteringHierarchyDefinition {
39
39
  }));
40
40
  };
41
41
  }
42
- shouldExpandGroupingNode(node) {
43
- for (const child of node.children) {
44
- /* c8 ignore next 3 */
45
- if (!child.filtering) {
46
- continue;
47
- }
48
- if (child.filtering.isFilterTarget) {
49
- const childAutoExpand = child.filtering.filterTargetOptions?.autoExpand;
50
- // If child is a filter target and is has no `autoExpand` flag, then it's always to be expanded.
51
- if (childAutoExpand === true) {
52
- return true;
53
- }
54
- // If it's not an object and not `true`, then it's falsy - continue looking
55
- if (typeof childAutoExpand !== "object") {
56
- continue;
57
- }
58
- // If grouping node's child has `autoExpandUntil` flag,
59
- // auto-expand the grouping node only if it's depth is lower than that of the grouping node in associated with the target.
60
- const nodeDepth = childAutoExpand.includeGroupingNodes
61
- ? node.parentKeys.length
62
- : node.parentKeys.filter((key) => !HierarchyNodeKey_js_1.HierarchyNodeKey.isGrouping(key)).length;
63
- const filterTargetDepth = childAutoExpand.depth;
64
- if (nodeDepth < filterTargetDepth) {
65
- return true;
66
- }
67
- }
68
- if (!child.filtering.filteredChildrenIdentifierPaths) {
69
- /* c8 ignore next */
70
- continue;
71
- }
72
- for (const path of child.filtering.filteredChildrenIdentifierPaths) {
73
- if ("path" in path && path.options?.autoExpand) {
74
- return true;
75
- }
76
- }
77
- }
78
- return false;
79
- }
80
42
  get postProcessNode() {
81
43
  return (node) => {
82
44
  return (this._source.postProcessNode ? this._source.postProcessNode(node) : (0, rxjs_1.of)(node)).pipe((0, rxjs_1.map)((processedNode) => {
83
45
  // instance nodes get the auto-expand flag in `parseNode`, but grouping ones need to be handled during post-processing
84
- if (IModelHierarchyNode_js_1.ProcessedHierarchyNode.isGroupingNode(node) && this.shouldExpandGroupingNode(node)) {
46
+ if (IModelHierarchyNode_js_1.ProcessedHierarchyNode.isGroupingNode(node) && shouldExpandGroupingNode(node)) {
85
47
  Object.assign(processedNode, { autoExpand: true });
86
48
  }
87
49
  return processedNode;
@@ -118,13 +80,7 @@ class FilteringHierarchyDefinition {
118
80
  });
119
81
  return (nodeExtraPropsPossiblyPromise instanceof Promise ? (0, rxjs_1.from)(nodeExtraPropsPossiblyPromise) : (0, rxjs_1.of)(nodeExtraPropsPossiblyPromise)).pipe((0, rxjs_1.map)((nodeExtraProps) => {
120
82
  if (nodeExtraProps?.autoExpand) {
121
- const parentLength = !parentNode
122
- ? 0
123
- : nodeExtraProps.filtering?.includeGroupingNodes
124
- ? 1 + parentNode.parentKeys.length
125
- : 1 + parentNode.parentKeys.filter((key) => !HierarchyNodeKey_js_1.HierarchyNodeKey.isGrouping(key)).length;
126
- parsedNode.autoExpand =
127
- nodeExtraProps.filtering?.autoExpandDepth !== undefined && parentLength >= nodeExtraProps.filtering.autoExpandDepth ? undefined : true;
83
+ parsedNode.autoExpand = true;
128
84
  }
129
85
  if (nodeExtraProps?.filtering) {
130
86
  parsedNode.filtering = nodeExtraProps.filtering;
@@ -280,4 +236,39 @@ function applyECInstanceIdsSelector(def) {
280
236
  },
281
237
  };
282
238
  }
239
+ function shouldExpandGroupingNode(node) {
240
+ const numberOfNonGroupingParentNodes = node.parentKeys.filter((key) => !HierarchyNodeKey_js_1.HierarchyNodeKey.isGrouping(key)).length;
241
+ for (const child of node.children) {
242
+ /* c8 ignore next 3 */
243
+ if (!child.filtering) {
244
+ continue;
245
+ }
246
+ if (child.filtering.isFilterTarget &&
247
+ getAutoExpandAsTrueFalse(child.filtering.filterTargetOptions?.autoExpand, numberOfNonGroupingParentNodes, node.parentKeys.length)) {
248
+ return true;
249
+ }
250
+ if (!child.filtering.filteredChildrenIdentifierPaths) {
251
+ /* c8 ignore next */
252
+ continue;
253
+ }
254
+ for (const path of child.filtering.filteredChildrenIdentifierPaths) {
255
+ if ("path" in path && getAutoExpandAsTrueFalse(path.options?.autoExpand, numberOfNonGroupingParentNodes, node.parentKeys.length)) {
256
+ return true;
257
+ }
258
+ }
259
+ }
260
+ return false;
261
+ }
262
+ function getAutoExpandAsTrueFalse(autoExpand, numberOfNonGroupingParentNodes, numberOfParentNodes) {
263
+ if (!autoExpand) {
264
+ return false;
265
+ }
266
+ if (autoExpand === true) {
267
+ return true;
268
+ }
269
+ // auto-expand should be set to true only if parentKeys length is smaller than depth.
270
+ const nodeDepth = "depthInHierarchy" in autoExpand ? numberOfParentNodes : numberOfNonGroupingParentNodes;
271
+ const filterTargetDepth = "depthInPath" in autoExpand ? autoExpand.depthInPath : autoExpand.depthInHierarchy;
272
+ return nodeDepth < filterTargetDepth;
273
+ }
283
274
  //# sourceMappingURL=FilteringHierarchyDefinition.js.map