@itwin/presentation-hierarchies-react 2.0.0-alpha.14 → 2.0.0-alpha.15

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 (51) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +0 -4
  3. package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
  4. package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +1 -1
  5. package/lib/esm/presentation-hierarchies-react/UseTree.js +0 -1
  6. package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
  7. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +1 -5
  8. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
  9. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +0 -11
  10. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
  11. package/lib/esm/presentation-hierarchies-react/itwinui/FilterAction.d.ts +18 -0
  12. package/lib/esm/presentation-hierarchies-react/itwinui/FilterAction.d.ts.map +1 -0
  13. package/lib/esm/presentation-hierarchies-react/itwinui/FilterAction.js +32 -0
  14. package/lib/esm/presentation-hierarchies-react/itwinui/FilterAction.js.map +1 -0
  15. package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts +36 -7
  16. package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +1 -1
  17. package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +18 -6
  18. package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +1 -1
  19. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +15 -0
  20. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +1 -1
  21. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js +3 -0
  22. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +1 -1
  23. package/lib/esm/presentation-hierarchies-react/itwinui/RootErrorRenderer.d.ts +16 -0
  24. package/lib/esm/presentation-hierarchies-react/itwinui/RootErrorRenderer.d.ts.map +1 -0
  25. package/lib/esm/presentation-hierarchies-react/itwinui/RootErrorRenderer.js +41 -0
  26. package/lib/esm/presentation-hierarchies-react/itwinui/RootErrorRenderer.js.map +1 -0
  27. package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +29 -9
  28. package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +1 -1
  29. package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +52 -33
  30. package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +1 -1
  31. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +10 -9
  32. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
  33. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +18 -28
  34. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
  35. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +9 -4
  36. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +1 -1
  37. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +43 -20
  38. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +1 -1
  39. package/lib/esm/presentation-hierarchies-react.d.ts +3 -3
  40. package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
  41. package/lib/esm/presentation-hierarchies-react.js +3 -3
  42. package/lib/esm/presentation-hierarchies-react.js.map +1 -1
  43. package/package.json +6 -6
  44. package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts +0 -15
  45. package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts.map +0 -1
  46. package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js +0 -22
  47. package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js.map +0 -1
  48. package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts +0 -31
  49. package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +0 -1
  50. package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +0 -40
  51. package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,116 @@
1
1
  # @itwin/presentation-hierarchies-react
2
2
 
3
+ ## 2.0.0-alpha.15
4
+
5
+ ### Major Changes
6
+
7
+ - [#942](https://github.com/iTwin/presentation/pull/942): Unified selection API cleanup.
8
+
9
+ - Remove deprecated `UnifiedSelectionProvider`.
10
+ - Make `selectionStorage` prop required for unified selection - enabled tree state hooks (`useUnifiedSelectionTree` and `useIModelUnifiedSelectionTree`).
11
+
12
+ Previously, the `selectionStorage` prop was optional, and if not provided, the hooks used unified selection React context (provided by `UnifiedSelectionProvider`) as fallback. Finally, if the context was not provided either, the hooks acted as regular non-unified selection hooks.
13
+
14
+ This didn't make much sense, as the hooks were designed to work with unified selection, as their name suggests. So it makes sense to require the selection storage to be provided to them, and at that point the context becomes redundant.
15
+
16
+ - [#936](https://github.com/iTwin/presentation/pull/936): Replaced `actions` property on `TreeNodeRenderer` with `getActions` to match how decorations are handled. Removed `useFilterAction` hook and replaced it with `FilterAction` component.
17
+
18
+ Before:
19
+
20
+ ```tsx
21
+ import { TreeNodeRenderer, useFilterAction } from "@itwin/presentation-hierarchies-react";
22
+
23
+ const filterAction = useFilterAction({ onFilter, getHierarchyLevelDetails });
24
+ return (
25
+ <TreeNodeRenderer
26
+ actions={useMemo(
27
+ () => [
28
+ filterAction,
29
+ (node) => ({
30
+ label: "Custom Action",
31
+ actions: () => log(node.label),
32
+ icon: customIconHref,
33
+ }),
34
+ ],
35
+ [filterAction],
36
+ )}
37
+ />
38
+ );
39
+ ```
40
+
41
+ After:
42
+
43
+ ```tsx
44
+ import { Icon, Tree } from "@itwin/itwinui-react";
45
+ import { FilterAction, TreeNodeRenderer } from "@itwin/presentation-hierarchies-react";
46
+
47
+ return (
48
+ <TreeNodeRenderer
49
+ getActions={useCallback(
50
+ (node) => [
51
+ <FilterAction key="filter" node={node} onFilter={onFilter} getHierarchyLevelDetails={getHierarchyLevelDetails} />,
52
+ <Tree.ItemAction key="customAction" label="Custom action" onClick={() => log(node.label)} icon={<Icon href={customIconHref} />} />,
53
+ ],
54
+ [onFilter, getHierarchyLevelDetails],
55
+ )}
56
+ />
57
+ );
58
+ ```
59
+
60
+ ### Minor Changes
61
+
62
+ - [#930](https://github.com/iTwin/presentation/pull/930): Exposed `TreeErrorRenderer`, which takes `renderError` property to render custom error messages.
63
+ `TreeRenderer` now takes `errorRenderer` to render a custom error display component.
64
+
65
+ Custom error display component example:
66
+
67
+ ```ts
68
+ <TreeRenderer
69
+ {...treeProps}
70
+ errorRenderer={(errorsRendererProps) => (
71
+ <MyErrorRenderer {...errorsRendererProps} />
72
+ )}
73
+ />
74
+ ```
75
+
76
+ Custom error message example:
77
+
78
+ ```ts
79
+ <TreeRenderer
80
+ {...treeProps}
81
+ errorRenderer={(errorsRendererProps) => (
82
+ <TreeErrorRenderer
83
+ {...errorsRendererProps}
84
+ renderError={(errorProps) => {
85
+ return <unstable_ErrorRegion.Item message={...} />;
86
+ }}
87
+ />
88
+ )}
89
+ />
90
+ ```
91
+
92
+ - [#937](https://github.com/iTwin/presentation/pull/937): `TreeRenderer` now takes `rootErrorRenderer` to render a custom root error display component.
93
+
94
+ Custom error display component example:
95
+
96
+ ```ts
97
+ <TreeRenderer
98
+ {...treeProps}
99
+ rootErrorRenderer={(rootErrorRendererProps) => (
100
+ <MyRootErrorRenderer {...rootErrorRendererProps} />
101
+ )}
102
+ />
103
+ ```
104
+
105
+ - [#930](https://github.com/iTwin/presentation/pull/930): Changed flat tree building functions to hooks:
106
+
107
+ - `flattenNodes` => `useFlatTreeNodeList`.
108
+ - `getErrors` => `useErrorList`.
109
+
110
+ ### Patch Changes
111
+
112
+ - [#930](https://github.com/iTwin/presentation/pull/930): Fix `ResultSetTooLarge` error suggesting filtering when parent node is not filterable.
113
+
3
114
  ## 2.0.0-alpha.14
4
115
 
5
116
  ### Patch Changes
@@ -13,10 +13,6 @@ export interface PresentationHierarchyNode {
13
13
  isFiltered: boolean;
14
14
  /** UI-agnostic source of this node object. */
15
15
  nodeData: HierarchyNode;
16
- /** Additional data that may be assigned to this node. */
17
- extendedData?: {
18
- [key: string]: any;
19
- };
20
16
  }
21
17
  /**
22
18
  * A type of `PresentationInfoNode` that is returned as the single child of a filtered parent node,
@@ -1 +1 @@
1
- {"version":3,"file":"TreeNode.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC7C,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,8CAA8C;IAC9C,QAAQ,EAAE,aAAa,CAAC;IACxB,yDAAyD;IACzD,YAAY,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CACvC;AAED;;;;;GAKG;AACH,MAAM,WAAW,mCAAmC;IAClD,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED;;;;;;GAM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iB,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qCAAqC;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,2BAA2B,GAAG,qCAAqC,GAAG,mCAAmC,CAAC;AAE7I;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,yBAAyB,GAAG,oBAAoB,CAAC;AAEpF;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI,IAAI,yBAAyB,CAEzG"}
@@ -1 +1 @@
1
- {"version":3,"file":"TreeNode.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AA4EhG;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,IAA0B;IACpE,OAAO,UAAU,IAAI,IAAI,CAAC;AAC5B,CAAC","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 } from \"@itwin/presentation-hierarchies\";\n\n/**\n * A type that defines an actual expandable node in a UI tree component, built with `useTree` hook.\n * @public\n */\nexport interface PresentationHierarchyNode {\n id: string;\n label: string;\n children: true | Array<PresentationTreeNode>;\n isExpanded: boolean;\n isLoading: boolean;\n isFilterable: boolean;\n isFiltered: boolean;\n /** UI-agnostic source of this node object. */\n nodeData: HierarchyNode;\n /** Additional data that may be assigned to this node. */\n extendedData?: { [key: string]: any };\n}\n\n/**\n * A type of `PresentationInfoNode` that is returned as the single child of a filtered parent node,\n * when none of the child nodes match the filter.\n *\n * @public\n */\nexport interface PresentationNoFilterMatchesInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"NoFilterMatches\";\n}\n\n/**\n * A type of `PresentationInfoNode` that is returned as the single child of a parent node, when the\n * number of child nodes exceeds the limit set on the tree nodes loader. The limit is also included\n * on this node as `resultSetSizeLimit` attribute.\n *\n * @public\n */\nexport interface PresentationResultSetTooLargeInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"ResultSetTooLarge\";\n resultSetSizeLimit: number;\n}\n\n/**\n * A type of `PresentationInfoNode` that contains a user-friendly message to be displayed in the UI.\n * Generally, this is the only child of a parent node, created in cases like an error loading children. The\n * renderer may offer users to re-load the children or the whole component in such cases.\n *\n * @public\n */\nexport interface PresentationGenericInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"Unknown\";\n message: string;\n}\n\n/**\n * A type that defines a non-expandable, non-selectable informational node in a UI tree component, built\n * with `useTree` hook.\n *\n * @public\n */\nexport type PresentationInfoNode = PresentationGenericInfoNode | PresentationResultSetTooLargeInfoNode | PresentationNoFilterMatchesInfoNode;\n\n/**\n * A type that defines a node in a UI tree component, built with `useTree` hook.\n * @public\n */\nexport type PresentationTreeNode = PresentationHierarchyNode | PresentationInfoNode;\n\n/**\n * An utility function to check if a node is a `PresentationHierarchyNode`.\n * @public\n */\nexport function isPresentationHierarchyNode(node: PresentationTreeNode): node is PresentationHierarchyNode {\n return \"children\" in node;\n}\n"]}
1
+ {"version":3,"file":"TreeNode.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AA0EhG;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,IAA0B;IACpE,OAAO,UAAU,IAAI,IAAI,CAAC;AAC5B,CAAC","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 } from \"@itwin/presentation-hierarchies\";\n\n/**\n * A type that defines an actual expandable node in a UI tree component, built with `useTree` hook.\n * @public\n */\nexport interface PresentationHierarchyNode {\n id: string;\n label: string;\n children: true | Array<PresentationTreeNode>;\n isExpanded: boolean;\n isLoading: boolean;\n isFilterable: boolean;\n isFiltered: boolean;\n /** UI-agnostic source of this node object. */\n nodeData: HierarchyNode;\n}\n\n/**\n * A type of `PresentationInfoNode` that is returned as the single child of a filtered parent node,\n * when none of the child nodes match the filter.\n *\n * @public\n */\nexport interface PresentationNoFilterMatchesInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"NoFilterMatches\";\n}\n\n/**\n * A type of `PresentationInfoNode` that is returned as the single child of a parent node, when the\n * number of child nodes exceeds the limit set on the tree nodes loader. The limit is also included\n * on this node as `resultSetSizeLimit` attribute.\n *\n * @public\n */\nexport interface PresentationResultSetTooLargeInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"ResultSetTooLarge\";\n resultSetSizeLimit: number;\n}\n\n/**\n * A type of `PresentationInfoNode` that contains a user-friendly message to be displayed in the UI.\n * Generally, this is the only child of a parent node, created in cases like an error loading children. The\n * renderer may offer users to re-load the children or the whole component in such cases.\n *\n * @public\n */\nexport interface PresentationGenericInfoNode {\n id: string;\n parentNodeId: string | undefined;\n type: \"Unknown\";\n message: string;\n}\n\n/**\n * A type that defines a non-expandable, non-selectable informational node in a UI tree component, built\n * with `useTree` hook.\n *\n * @public\n */\nexport type PresentationInfoNode = PresentationGenericInfoNode | PresentationResultSetTooLargeInfoNode | PresentationNoFilterMatchesInfoNode;\n\n/**\n * A type that defines a node in a UI tree component, built with `useTree` hook.\n * @public\n */\nexport type PresentationTreeNode = PresentationHierarchyNode | PresentationInfoNode;\n\n/**\n * An utility function to check if a node is a `PresentationHierarchyNode`.\n * @public\n */\nexport function isPresentationHierarchyNode(node: PresentationTreeNode): node is PresentationHierarchyNode {\n return \"children\" in node;\n}\n"]}
@@ -230,7 +230,6 @@ function toPresentationHierarchyNodeBase(node) {
230
230
  isExpanded: !!node.isExpanded,
231
231
  isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,
232
232
  isFiltered: !!node.instanceFilter,
233
- extendedData: node.nodeData.extendedData,
234
233
  };
235
234
  }
236
235
  //# sourceMappingURL=UseTree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"UseTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAiD,aAAa,EAAqB,MAAM,iCAAiC,CAAC;AAElI,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,SAAS,EAA4D,MAAM,yBAAyB,CAAC;AAC7J,OAAO,EAAE,uBAAuB,EAAgC,MAAM,mCAAmC,CAAC;AAC1G,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA2BvC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CAAC,KAAmB;IACzC,MAAM,EAAE,gBAAgB,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAChE,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,uBAAuB,CAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,KAAK,EAA+C;IAC7H,MAAM,EA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AAC,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACxD,CAAC;YACD,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,+BAA+B,CAAC,IAA4B;IACnE,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS;QAC3B,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU;QAC7B,YAAY,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,iBAAiB,IAAI,IAAI,CAAC,QAAQ;QAChH,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc;QACjC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY;KACzC,CAAC;AACJ,CAAC","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 { useCallback, useEffect, useRef, useState } from \"react\";\nimport { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { isTreeModelHierarchyNode, isTreeModelInfoNode, TreeModel, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection, UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { PresentationHierarchyNode, PresentationTreeNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\nimport { useLatest } from \"./Utils.js\";\n\n/**\n * A data structure that contains information about a single hierarchy level.\n * @public\n */\nexport interface HierarchyLevelDetails {\n /** The parent node whose hierarchy level's information is contained in this data structure */\n hierarchyNode: HierarchyNode | undefined;\n\n /** A function to get instance keys of the hierarchy level. */\n getInstanceKeysIterator: (props?: {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n }) => AsyncIterableIterator<InstanceKey>;\n\n /** Get the limit of how many nodes can be loaded in this hierarchy level. */\n sizeLimit?: number | \"unbounded\";\n /** Set the limit of how many nodes can be loaded in this hierarchy level. */\n setSizeLimit: (value: undefined | number | \"unbounded\") => void;\n\n /** Get the active instance filter applied to this hierarchy level. */\n instanceFilter?: GenericInstanceFilter;\n /** Set the instance filter to apply to this hierarchy level */\n setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;\n}\n\n/**\n * A React hook that creates state for a tree component.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({ sourceName, selectionStorage, ...props }: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n return {\n ...rest,\n ...useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode }),\n };\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: () => Promise<HierarchyFilteringPath[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n}\n\n/**\n * Options for doing either full or a sub tree reload.\n * @public\n */\ninterface ReloadTreeOptions {\n /** Specifies parent node under which sub tree should be reloaded. */\n parentNodeId: string | undefined;\n\n /**\n * Specifies how current tree state should be handled:\n * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).\n * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.\n * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.\n *\n * Defaults to `\"keep\"`.\n */\n state?: \"keep\" | \"discard\" | \"reset\";\n}\n\n/** @public */\nexport interface UseTreeResult {\n /**\n * Array containing root tree nodes. It is `undefined` on initial render until any nodes are loaded.\n */\n rootNodes: PresentationTreeNode[] | undefined;\n /**\n * Specifies whether tree is loading or not. It is set to `true` when initial tree load is in progress\n * or tree is reloading.\n */\n isLoading: boolean;\n /**\n * A function that should be called to reload the tree.\n */\n reloadTree: (options?: ReloadTreeOptions) => void;\n /**\n * A function that should be called to either expand or collapse the given node.\n */\n expandNode: (nodeId: string, isExpanded: boolean) => void;\n /**\n * A function that should be called to select nodes in the tree.\n * @param nodeIds Ids of the nodes that are selected.\n * @param changeType Type of change that occurred for the selection.\n */\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n /** Determines whether a given node is selected. */\n isNodeSelected: (nodeId: string) => boolean;\n /** Get a tree node by id */\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n /** Returns hierarchy level details for a given node ID. */\n getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;\n /** Sets a formatter for the primitive values that are displayed in the hierarchy. */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n}\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<PresentationTreeNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getFilteredPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes = model.parentChildMap.get(undefined) !== undefined ? generateTreeStructure(undefined, model) : undefined;\n setState({\n model,\n rootNodes,\n });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs?.filterChange?.newFilter !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isFiltering, setIsFiltering] = useState(false);\n useEffect(() => {\n let disposed = false;\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getFilteredPaths) {\n hierarchyProvider.setHierarchyFilter(undefined);\n // reload tree in case hierarchy provider does not use hierarchy filter to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsFiltering(false);\n return;\n }\n\n setIsFiltering(true);\n let paths: HierarchyFilteringPath[] | undefined;\n try {\n paths = await getFilteredPaths();\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchyFilter(paths ? { paths } : undefined);\n setIsFiltering(false);\n }\n }\n })();\n return () => {\n disposed = true;\n };\n }, [hierarchyProvider, getFilteredPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): PresentationHierarchyNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return undefined;\n }\n return createPresentationHierarchyNode(node, state.model);\n },\n [actions, state.model],\n );\n\n const expandNode = useCallback<UseTreeResult[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<UseTreeResult[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<UseTreeResult[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<UseTreeResult[\"isNodeSelected\"]>((nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId), [state]);\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<UseTreeResult[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node || isTreeModelInfoNode(node)) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n return {\n rootNodes: state.rootNodes,\n isLoading: !!state.model.rootNode.isLoading || isFiltering,\n expandNode,\n reloadTree,\n selectNodes,\n isNodeSelected,\n getTreeModelNode,\n getNode,\n getHierarchyLevelDetails,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(parentNodeId: string | undefined, model: TreeModel): Array<PresentationTreeNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelNode => !!node)\n .map<PresentationTreeNode>((node) => {\n if (isTreeModelHierarchyNode(node)) {\n return createPresentationHierarchyNode(node, model);\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n resultSetSizeLimit: node.resultSetSizeLimit,\n };\n }\n\n if (node.type === \"NoFilterMatches\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n };\n }\n\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n message: node.message,\n };\n });\n}\n\nfunction createPresentationHierarchyNode(modelNode: TreeModelHierarchyNode, model: TreeModel): PresentationHierarchyNode {\n let children: Array<PresentationTreeNode> | undefined;\n return {\n ...toPresentationHierarchyNodeBase(modelNode),\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n\nfunction toPresentationHierarchyNodeBase(node: TreeModelHierarchyNode): Omit<PresentationHierarchyNode, \"children\"> {\n return {\n id: node.id,\n label: node.label,\n nodeData: node.nodeData,\n isLoading: !!node.isLoading,\n isExpanded: !!node.isExpanded,\n isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,\n isFiltered: !!node.instanceFilter,\n extendedData: node.nodeData.extendedData,\n };\n}\n"]}
1
+ {"version":3,"file":"UseTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAiD,aAAa,EAAqB,MAAM,iCAAiC,CAAC;AAElI,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,SAAS,EAA4D,MAAM,yBAAyB,CAAC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EAAE,IAAI,CAAC,EAAE;gBACX,YAAY;gBACZ,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;QACJ,CAAC;QAED,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,YAAY;YACZ,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,+BAA+B,CAAC,SAAiC,EAAE,KAAgB;IAC1F,IAAI,QAAiD,CAAC;IACtD,OAAO;QACL,GAAG,+BAA+B,CAAC,SAAS,CAAC;QAC7C,IAAI,QAAQ;YACV,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,QAAQ,GAAG,qBAAqB,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACxD,CAAC;YACD,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,+BAA+B,CAAC,IAA4B;IACnE,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS;QAC3B,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU;QAC7B,YAAY,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,iBAAiB,IAAI,IAAI,CAAC,QAAQ;QAChH,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc;KAClC,CAAC;AACJ,CAAC","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 { useCallback, useEffect, useRef, useState } from \"react\";\nimport { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { isTreeModelHierarchyNode, isTreeModelInfoNode, TreeModel, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection, UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { PresentationHierarchyNode, PresentationTreeNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\nimport { useLatest } from \"./Utils.js\";\n\n/**\n * A data structure that contains information about a single hierarchy level.\n * @public\n */\nexport interface HierarchyLevelDetails {\n /** The parent node whose hierarchy level's information is contained in this data structure */\n hierarchyNode: HierarchyNode | undefined;\n\n /** A function to get instance keys of the hierarchy level. */\n getInstanceKeysIterator: (props?: {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n }) => AsyncIterableIterator<InstanceKey>;\n\n /** Get the limit of how many nodes can be loaded in this hierarchy level. */\n sizeLimit?: number | \"unbounded\";\n /** Set the limit of how many nodes can be loaded in this hierarchy level. */\n setSizeLimit: (value: undefined | number | \"unbounded\") => void;\n\n /** Get the active instance filter applied to this hierarchy level. */\n instanceFilter?: GenericInstanceFilter;\n /** Set the instance filter to apply to this hierarchy level */\n setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;\n}\n\n/**\n * A React hook that creates state for a tree component.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({ sourceName, selectionStorage, ...props }: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n return {\n ...rest,\n ...useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode }),\n };\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: () => Promise<HierarchyFilteringPath[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n}\n\n/**\n * Options for doing either full or a sub tree reload.\n * @public\n */\ninterface ReloadTreeOptions {\n /** Specifies parent node under which sub tree should be reloaded. */\n parentNodeId: string | undefined;\n\n /**\n * Specifies how current tree state should be handled:\n * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).\n * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.\n * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.\n *\n * Defaults to `\"keep\"`.\n */\n state?: \"keep\" | \"discard\" | \"reset\";\n}\n\n/** @public */\nexport interface UseTreeResult {\n /**\n * Array containing root tree nodes. It is `undefined` on initial render until any nodes are loaded.\n */\n rootNodes: PresentationTreeNode[] | undefined;\n /**\n * Specifies whether tree is loading or not. It is set to `true` when initial tree load is in progress\n * or tree is reloading.\n */\n isLoading: boolean;\n /**\n * A function that should be called to reload the tree.\n */\n reloadTree: (options?: ReloadTreeOptions) => void;\n /**\n * A function that should be called to either expand or collapse the given node.\n */\n expandNode: (nodeId: string, isExpanded: boolean) => void;\n /**\n * A function that should be called to select nodes in the tree.\n * @param nodeIds Ids of the nodes that are selected.\n * @param changeType Type of change that occurred for the selection.\n */\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n /** Determines whether a given node is selected. */\n isNodeSelected: (nodeId: string) => boolean;\n /** Get a tree node by id */\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n /** Returns hierarchy level details for a given node ID. */\n getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;\n /** Sets a formatter for the primitive values that are displayed in the hierarchy. */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n}\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<PresentationTreeNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getFilteredPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes = model.parentChildMap.get(undefined) !== undefined ? generateTreeStructure(undefined, model) : undefined;\n setState({\n model,\n rootNodes,\n });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs?.filterChange?.newFilter !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isFiltering, setIsFiltering] = useState(false);\n useEffect(() => {\n let disposed = false;\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getFilteredPaths) {\n hierarchyProvider.setHierarchyFilter(undefined);\n // reload tree in case hierarchy provider does not use hierarchy filter to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsFiltering(false);\n return;\n }\n\n setIsFiltering(true);\n let paths: HierarchyFilteringPath[] | undefined;\n try {\n paths = await getFilteredPaths();\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchyFilter(paths ? { paths } : undefined);\n setIsFiltering(false);\n }\n }\n })();\n return () => {\n disposed = true;\n };\n }, [hierarchyProvider, getFilteredPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): PresentationHierarchyNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return undefined;\n }\n return createPresentationHierarchyNode(node, state.model);\n },\n [actions, state.model],\n );\n\n const expandNode = useCallback<UseTreeResult[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<UseTreeResult[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<UseTreeResult[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<UseTreeResult[\"isNodeSelected\"]>((nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId), [state]);\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<UseTreeResult[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node || isTreeModelInfoNode(node)) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n return {\n rootNodes: state.rootNodes,\n isLoading: !!state.model.rootNode.isLoading || isFiltering,\n expandNode,\n reloadTree,\n selectNodes,\n isNodeSelected,\n getTreeModelNode,\n getNode,\n getHierarchyLevelDetails,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(parentNodeId: string | undefined, model: TreeModel): Array<PresentationTreeNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelNode => !!node)\n .map<PresentationTreeNode>((node) => {\n if (isTreeModelHierarchyNode(node)) {\n return createPresentationHierarchyNode(node, model);\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n resultSetSizeLimit: node.resultSetSizeLimit,\n };\n }\n\n if (node.type === \"NoFilterMatches\") {\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n };\n }\n\n return {\n id: node.id,\n parentNodeId,\n type: node.type,\n message: node.message,\n };\n });\n}\n\nfunction createPresentationHierarchyNode(modelNode: TreeModelHierarchyNode, model: TreeModel): PresentationHierarchyNode {\n let children: Array<PresentationTreeNode> | undefined;\n return {\n ...toPresentationHierarchyNodeBase(modelNode),\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n\nfunction toPresentationHierarchyNodeBase(node: TreeModelHierarchyNode): Omit<PresentationHierarchyNode, \"children\"> {\n return {\n id: node.id,\n label: node.label,\n nodeData: node.nodeData,\n isLoading: !!node.isLoading,\n isExpanded: !!node.isExpanded,\n isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,\n isFiltered: !!node.instanceFilter,\n };\n}\n"]}
@@ -14,12 +14,8 @@ export interface UseUnifiedTreeSelectionProps {
14
14
  sourceName: string;
15
15
  /**
16
16
  * Unified selection storage to use for listening, getting and changing active selection.
17
- *
18
- * When not specified, the deprecated unified selection React context is used to access the
19
- * selection storage (see `UnifiedSelectionProvider`). This prop will be made required in the
20
- * next major release, where the deprecated context will also be removed.
21
17
  */
22
- selectionStorage?: SelectionStorage;
18
+ selectionStorage: SelectionStorage;
23
19
  }
24
20
  /** @internal */
25
21
  export declare function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, }: UseUnifiedTreeSelectionProps & {
@@ -1 +1 @@
1
- {"version":3,"file":"UseUnifiedSelection.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AASA,OAAO,EAA2B,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAErF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAoD,aAAa,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEpH,gBAAgB;AAChB,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAChF;AAED,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED,gBAAgB;AAChB,wBAAgB,uBAAuB,CAAC,EACtC,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACjB,EAAE,4BAA4B,GAAG;IAAE,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,aAAa,GAAG,iBAAiB,GAAG,SAAS,CAAA;CAAE,GAAG,oBAAoB,CA6B/I"}
1
+ {"version":3,"file":"UseUnifiedSelection.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AASA,OAAO,EAA2B,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAoD,aAAa,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEpH,gBAAgB;AAChB,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAChF;AAED,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED,gBAAgB;AAChB,wBAAgB,uBAAuB,CAAC,EACtC,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACjB,EAAE,4BAA4B,GAAG;IAAE,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,aAAa,GAAG,iBAAiB,GAAG,SAAS,CAAA;CAAE,GAAG,oBAAoB,CAiB/I"}
@@ -6,7 +6,6 @@ import { useEffect, useState } from "react";
6
6
  import { assert } from "@itwin/core-bentley";
7
7
  import { HierarchyNode } from "@itwin/presentation-hierarchies";
8
8
  import { Selectables } from "@itwin/unified-selection";
9
- import { useUnifiedSelectionStorage } from "../UnifiedSelectionContext.js";
10
9
  import { isTreeModelHierarchyNode } from "./TreeModel.js";
11
10
  /** @internal */
12
11
  export function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, }) {
@@ -14,17 +13,7 @@ export function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeM
14
13
  isNodeSelected: /* c8 ignore next */ () => false,
15
14
  selectNodes: /* c8 ignore next */ () => { },
16
15
  }));
17
- const deprecatedSelectionStorage = useUnifiedSelectionStorage();
18
- selectionStorage ??= deprecatedSelectionStorage;
19
16
  useEffect(() => {
20
- if (!selectionStorage) {
21
- // TODO: make selectionStorage prop required
22
- setOptions({
23
- isNodeSelected: () => false,
24
- selectNodes: () => { },
25
- });
26
- return;
27
- }
28
17
  setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));
29
18
  return selectionStorage.selectionChangeEvent.addListener((args) => {
30
19
  if (args.level > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"UseUnifiedSelection.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAoB,MAAM,iCAAiC,CAAC;AAElF,OAAO,EAAc,WAAW,EAAoB,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,wBAAwB,EAA4D,MAAM,gBAAgB,CAAC;AAyBpH,gBAAgB;AAChB,MAAM,UAAU,uBAAuB,CAAC,EACtC,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACuG;IACvH,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB,GAAG,EAAE,CAAC,CAAC;QAClE,cAAc,EAAE,oBAAoB,CAAC,GAAG,EAAE,CAAC,KAAK;QAChD,WAAW,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAE,CAAC;KAC3C,CAAC,CAAC,CAAC;IAEJ,MAAM,0BAA0B,GAAG,0BAA0B,EAAE,CAAC;I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CAAC;AAED,SAAS,uBAAuB,CAAC,YAA8C;IAC7E,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,iBAAiB,EAAE,GAAG,EAAE,EAAE;QACzB,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC;QACtC,IAAI,eAAe,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACnD,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,EAAE,CAAC;YACrB,iBAAiB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;QACjD,CAAC;QACD,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EACD,EAA4C,CAC7C,CAAC;AACJ,CAAC","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 { useEffect, useState } from \"react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { HierarchyNode, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey } from \"@itwin/presentation-shared\";\nimport { Selectable, Selectables, SelectionStorage } from \"@itwin/unified-selection\";\nimport { useUnifiedSelectionStorage } from \"../UnifiedSelectionContext.js\";\nimport { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport { isTreeModelHierarchyNode, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @public */\nexport interface UseUnifiedTreeSelectionProps {\n /**\n * Identifier to distinguish this source of changes to the unified selection from another ones in the application.\n */\n sourceName: string;\n\n /**\n * Unified selection storage to use for listening, getting and changing active selection.\n *\n * When not specified, the deprecated unified selection React context is used to access the\n * selection storage (see `UnifiedSelectionProvider`). This prop will be made required in the\n * next major release, where the deprecated context will also be removed.\n */\n selectionStorage?: SelectionStorage;\n}\n\n/** @internal */\nexport function useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n}: UseUnifiedTreeSelectionProps & { getTreeModelNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined }): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* c8 ignore next */ () => false,\n selectNodes: /* c8 ignore next */ () => {},\n }));\n\n const deprecatedSelectionStorage = useUnifiedSelectionStorage();\n selectionStorage ??= deprecatedSelectionStorage;\n\n useEffect(() => {\n if (!selectionStorage) {\n // TODO: make selectionStorage prop required\n setOptions({\n isNodeSelected: () => false,\n selectNodes: () => {},\n });\n return;\n }\n\n setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (args.level > 0) {\n return;\n }\n setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));\n });\n }, [selectionStorage, getTreeModelNode, sourceName]);\n\n return options;\n}\n\nfunction createOptions(\n source: string,\n storage: SelectionStorage,\n getNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined,\n): TreeSelectionOptions {\n return {\n isNodeSelected: (nodeId: string) => {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return false;\n }\n return Object.entries(groupNodeSelectablesByIModelKey(node)).some(([imodelKey, nodeSelectables]) => {\n const storageSelectables = storage.getSelection({ imodelKey, level: 0 });\n return Selectables.hasAny(storageSelectables, nodeSelectables);\n });\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n const imodelSelectables: { [imodelKey: string]: Selectable[] } = {};\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return;\n }\n Object.entries(groupNodeSelectablesByIModelKey(node)).forEach(([imodelKey, nodeSelectables]) => {\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n nodeSelectables.forEach((selectable) => selectablesList.push(selectable));\n });\n }\n Object.entries(imodelSelectables).forEach(([imodelKey, selectables]) => {\n const actionProps = { imodelKey, source, selectables, level: 0 };\n switch (changeType) {\n case \"add\":\n storage.addToSelection(actionProps);\n return;\n case \"remove\":\n storage.removeFromSelection(actionProps);\n return;\n case \"replace\":\n storage.replaceSelection(actionProps);\n return;\n }\n });\n },\n };\n}\n\nfunction groupNodeSelectablesByIModelKey(modelNode: TreeModelHierarchyNode): { [imodelKey: string]: Selectable[] } {\n const hierarchyNode = modelNode.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);\n }\n if (HierarchyNode.isGroupingNode(hierarchyNode)) {\n return Object.entries(groupIModelInstanceKeys(hierarchyNode.groupedInstanceKeys)).reduce(\n (imodelSelectables, [imodelKey, instanceKeys]) => ({\n ...imodelSelectables,\n [imodelKey]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {\n for (const key of instanceKeys) {\n yield key;\n }\n },\n },\n ],\n }),\n {} as { [imodelKey: string]: Selectable[] },\n );\n }\n assert(HierarchyNode.isGeneric(hierarchyNode));\n return {\n // note: generic nodes aren't associated with an imodel\n [\"\"]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {},\n },\n ],\n };\n}\n\nfunction groupIModelInstanceKeys(instanceKeys: InstancesNodeKey[\"instanceKeys\"]) {\n return instanceKeys.reduce(\n (imodelSelectables, key) => {\n const imodelKey = key.imodelKey ?? \"\";\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n selectablesList.push(key);\n return imodelSelectables;\n },\n {} as { [imodelKey: string]: InstanceKey[] },\n );\n}\n"]}
1
+ {"version":3,"file":"UseUnifiedSelection.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAoB,MAAM,iCAAiC,CAAC;AAElF,OAAO,EAAc,WAAW,EAAoB,MAAM,0BAA0B,CAAC;AAErF,OAAO,EAAE,wBAAwB,EAA4D,MAAM,gBAAgB,CAAC;AAqBpH,gBAAgB;AAChB,MAAM,UAAU,uBAAuB,CAAC,EACtC,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACuG;IACvH,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB,GAAG,EAAE,CAAC,CAAC;QAClE,cAAc,EAAE,oBAAoB,CAAC,GAAG,EAAE,CAAC,KAAK;QAChD,WAAW,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAE,CAAC;KAC3C,CAAC,CAAC,CAAC;IAEJ,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC;QAC1E,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE;YAChE,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;gBACnB,OAAO;YACT,CAAC;YACD,UAAU,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAAC;IAErD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CACp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AC,EAAE;oBACxB,IAAI,EAAE,aAAa;oBACnB,KAAK,CAAC,CAAC,gBAAgB;wBACrB,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;4BAC/B,MAAM,GAAG,CAAC;wBACZ,CAAC;oBACH,CAAC;iBACF;aACF;SACF,CAAC,EACF,EAA2C,CAC5C,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;IAC/C,OAAO;QACL,uDAAuD;QACvD,CAAC,EAAE,CAAC,EAAE;YACJ;gBACE,UAAU,EAAE,SAAS,CAAC,EAAE;gBACxB,IAAI,EAAE,aAAa;gBACnB,KAAK,CAAC,CAAC,gBAAgB,KAAI,CAAC;aAC7B;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,YAA8C;IAC7E,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,iBAAiB,EAAE,GAAG,EAAE,EAAE;QACzB,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC;QACtC,IAAI,eAAe,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACnD,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,EAAE,CAAC;YACrB,iBAAiB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;QACjD,CAAC;QACD,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EACD,EAA4C,CAC7C,CAAC;AACJ,CAAC","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 { useEffect, useState } from \"react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { HierarchyNode, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey } from \"@itwin/presentation-shared\";\nimport { Selectable, Selectables, SelectionStorage } from \"@itwin/unified-selection\";\nimport { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport { isTreeModelHierarchyNode, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @public */\nexport interface UseUnifiedTreeSelectionProps {\n /**\n * Identifier to distinguish this source of changes to the unified selection from another ones in the application.\n */\n sourceName: string;\n\n /**\n * Unified selection storage to use for listening, getting and changing active selection.\n */\n selectionStorage: SelectionStorage;\n}\n\n/** @internal */\nexport function useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n}: UseUnifiedTreeSelectionProps & { getTreeModelNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined }): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* c8 ignore next */ () => false,\n selectNodes: /* c8 ignore next */ () => {},\n }));\n\n useEffect(() => {\n setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (args.level > 0) {\n return;\n }\n setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));\n });\n }, [selectionStorage, getTreeModelNode, sourceName]);\n\n return options;\n}\n\nfunction createOptions(\n source: string,\n storage: SelectionStorage,\n getNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined,\n): TreeSelectionOptions {\n return {\n isNodeSelected: (nodeId: string) => {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return false;\n }\n return Object.entries(groupNodeSelectablesByIModelKey(node)).some(([imodelKey, nodeSelectables]) => {\n const storageSelectables = storage.getSelection({ imodelKey, level: 0 });\n return Selectables.hasAny(storageSelectables, nodeSelectables);\n });\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n const imodelSelectables: { [imodelKey: string]: Selectable[] } = {};\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return;\n }\n Object.entries(groupNodeSelectablesByIModelKey(node)).forEach(([imodelKey, nodeSelectables]) => {\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n nodeSelectables.forEach((selectable) => selectablesList.push(selectable));\n });\n }\n Object.entries(imodelSelectables).forEach(([imodelKey, selectables]) => {\n const actionProps = { imodelKey, source, selectables, level: 0 };\n switch (changeType) {\n case \"add\":\n storage.addToSelection(actionProps);\n return;\n case \"remove\":\n storage.removeFromSelection(actionProps);\n return;\n case \"replace\":\n storage.replaceSelection(actionProps);\n return;\n }\n });\n },\n };\n}\n\nfunction groupNodeSelectablesByIModelKey(modelNode: TreeModelHierarchyNode): { [imodelKey: string]: Selectable[] } {\n const hierarchyNode = modelNode.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);\n }\n if (HierarchyNode.isGroupingNode(hierarchyNode)) {\n return Object.entries(groupIModelInstanceKeys(hierarchyNode.groupedInstanceKeys)).reduce(\n (imodelSelectables, [imodelKey, instanceKeys]) => ({\n ...imodelSelectables,\n [imodelKey]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {\n for (const key of instanceKeys) {\n yield key;\n }\n },\n },\n ],\n }),\n {} as { [imodelKey: string]: Selectable[] },\n );\n }\n assert(HierarchyNode.isGeneric(hierarchyNode));\n return {\n // note: generic nodes aren't associated with an imodel\n [\"\"]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {},\n },\n ],\n };\n}\n\nfunction groupIModelInstanceKeys(instanceKeys: InstancesNodeKey[\"instanceKeys\"]) {\n return instanceKeys.reduce(\n (imodelSelectables, key) => {\n const imodelKey = key.imodelKey ?? \"\";\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n selectablesList.push(key);\n return imodelSelectables;\n },\n {} as { [imodelKey: string]: InstanceKey[] },\n );\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { PresentationHierarchyNode } from "../TreeNode.js";
2
+ import { HierarchyLevelDetails, useTree } from "../UseTree.js";
3
+ /** @alpha */
4
+ export type FilterActionProps = {
5
+ /** Action to perform when the filter button is clicked for this node. */
6
+ onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
7
+ } & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">>;
8
+ /**
9
+ * React component that renders a filter action for a tree item.
10
+ * @alpha
11
+ */
12
+ export declare const FilterAction: import("react").NamedExoticComponent<{
13
+ /** Action to perform when the filter button is clicked for this node. */
14
+ onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
15
+ } & Partial<Pick<import("../UseTree.js").UseTreeResult, "getHierarchyLevelDetails">> & {
16
+ node: PresentationHierarchyNode;
17
+ }>;
18
+ //# sourceMappingURL=FilterAction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilterAction.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FilterAction.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK/D,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACnE,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,YAAY;IARvB,yEAAyE;eAC9D,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI;;UAO8D,yBAAyB;EA2BxJ,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ import { memo, useCallback } from "react";
7
+ import { Tree } from "@itwin/itwinui-react/bricks";
8
+ import { useLocalizationContext } from "./LocalizationContext.js";
9
+ const filterSvg = new URL("@itwin/itwinui-icons/filter.svg", import.meta.url).href;
10
+ /**
11
+ * React component that renders a filter action for a tree item.
12
+ * @alpha
13
+ */
14
+ export const FilterAction = memo(function FilterAction({ node, onFilter, getHierarchyLevelDetails }) {
15
+ const { localizedStrings } = useLocalizationContext();
16
+ const { filterHierarchyLevel, filterHierarchyLevelActiveDescription } = localizedStrings;
17
+ const shouldShow = () => {
18
+ if (!onFilter || !node.isFilterable) {
19
+ return false;
20
+ }
21
+ if (node.isFiltered) {
22
+ return true;
23
+ }
24
+ return undefined;
25
+ };
26
+ const handleClick = useCallback(() => {
27
+ const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
28
+ hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);
29
+ }, [node, getHierarchyLevelDetails, onFilter]);
30
+ return (_jsx(Tree.ItemAction, { label: filterHierarchyLevel, onClick: handleClick, icon: filterSvg, visible: shouldShow(), dot: node.isFiltered ? filterHierarchyLevelActiveDescription : undefined }));
31
+ });
32
+ //# sourceMappingURL=FilterAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilterAction.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FilterAction.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,IAAI,EAAE,WAAW,EA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AAC,SAAS,GACxE,CACH,CAAC;AACJ,CAAC,CAAC,CAAC","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 { memo, useCallback } from \"react\";\nimport { Tree } from \"@itwin/itwinui-react/bricks\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\nconst filterSvg = new URL(\"@itwin/itwinui-icons/filter.svg\", import.meta.url).href;\n\n/** @alpha */\nexport type FilterActionProps = {\n /** Action to perform when the filter button is clicked for this node. */\n onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n} & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/**\n * React component that renders a filter action for a tree item.\n * @alpha\n */\nexport const FilterAction = memo(function FilterAction({ node, onFilter, getHierarchyLevelDetails }: FilterActionProps & { node: PresentationHierarchyNode }) {\n const { localizedStrings } = useLocalizationContext();\n const { filterHierarchyLevel, filterHierarchyLevelActiveDescription } = localizedStrings;\n const shouldShow = () => {\n if (!onFilter || !node.isFilterable) {\n return false;\n }\n if (node.isFiltered) {\n return true;\n }\n return undefined;\n };\n\n const handleClick = useCallback(() => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);\n }, [node, getHierarchyLevelDetails, onFilter]);\n\n return (\n <Tree.ItemAction\n label={filterHierarchyLevel}\n onClick={handleClick}\n icon={filterSvg}\n visible={shouldShow()}\n dot={node.isFiltered ? filterHierarchyLevelActiveDescription : undefined}\n />\n );\n});\n"]}
@@ -1,28 +1,57 @@
1
1
  import { PresentationHierarchyNode, PresentationInfoNode, PresentationTreeNode } from "../TreeNode.js";
2
- /** @alpha */
2
+ /**
3
+ * Placeholder node that is added to hierarchy as a child for a parent node while its child nodes are loading.
4
+ *
5
+ * @alpha
6
+ * */
3
7
  interface PlaceholderNode {
4
8
  id: string;
5
9
  level: number;
6
10
  placeholder: true;
7
11
  }
8
- /** @alpha */
12
+ /**
13
+ * An extended `PresentationHierarchyNode` node with properties needed for a flat tree structure.
14
+ *
15
+ * @alpha
16
+ */
9
17
  export type FlatNode = {
10
18
  level: number;
11
19
  levelSize: number;
12
20
  posInLevel: number;
13
21
  } & PresentationHierarchyNode;
14
- /** @alpha */
22
+ /**
23
+ * A node used to build an error message.
24
+ * Returned by `useErrorList`.
25
+ *
26
+ * @alpha
27
+ * */
15
28
  export interface ErrorNode {
16
29
  error: PresentationInfoNode;
17
30
  parent?: PresentationHierarchyNode;
18
31
  expandTo: (expandNode: (nodeId: string) => void) => void;
19
32
  }
20
- /** @alpha */
33
+ /**
34
+ * A node describing single tree item position and its content inside tree.
35
+ * Returned by `useFlatTreeNodeList` hook.
36
+ *
37
+ * @alpha
38
+ */
21
39
  export type FlatTreeNode = FlatNode | PlaceholderNode;
22
40
  /** @alpha */
23
41
  export declare function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode;
24
- /** @alpha */
25
- export declare function flattenNodes(rootNodes: PresentationTreeNode[]): FlatTreeNode[];
26
- export declare function getErrors(rootNodes: PresentationTreeNode[]): ErrorNode[];
42
+ /**
43
+ * Used to get a list of `FlatTreeNode` objects for the given list of `PresentationTreeNode` objects that represent
44
+ * a hierarchical structure. The resulting nodes can be used to render the hierarchy in a flat manner, e.g. using a
45
+ * virtualized list.
46
+ *
47
+ * @alpha
48
+ */
49
+ export declare function useFlatTreeNodeList(rootNodes: PresentationTreeNode[]): FlatTreeNode[];
50
+ /**
51
+ * Finds and returns all error nodes in a given hierarchy in the form of `PresentationTreeNode[]`.
52
+ *
53
+ * @alpha
54
+ */
55
+ export declare function useErrorList(rootNodes: PresentationTreeNode[]): ErrorNode[];
27
56
  export {};
28
57
  //# sourceMappingURL=FlatTreeNode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FlatTreeNode.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAKA,OAAO,EAA+B,yBAAyB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEpI,aAAa;AACb,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,aAAa;AACb,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,yBAAyB,CAAC;AAE9B,aAAa;AACb,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,oBAAoB,CAAC;IAC5B,MAAM,CAAC,EAAE,yBAAyB,CAAC;IACnC,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CAC1D;AAED,aAAa;AACb,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEtD,aAAa;AACb,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,IAAI,eAAe,CAE7E;AAED,aAAa;AACb,wBAAgB,YAAY,CAAC,SAAS,EAAE,oBAAoB,EAAE,kBAE7D;AAuBD,wBAAgB,SAAS,CAAC,SAAS,EAAE,oBAAoB,EAAE,GAAG,SAAS,EAAE,CAUxE"}
1
+ {"version":3,"file":"FlatTreeNode.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAMA,OAAO,EAA+B,yBAAyB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEpI;;;;KAIK;AACL,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,IAAI,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,yBAAyB,CAAC;AAE9B;;;;;KAKK;AACL,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,oBAAoB,CAAC;IAC5B,MAAM,CAAC,EAAE,yBAAyB,CAAC;IACnC,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CAC1D;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEtD,aAAa;AACb,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,IAAI,eAAe,CAE7E;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,oBAAoB,EAAE,kBAEpE;AAuBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,oBAAoB,EAAE,GAAG,SAAS,EAAE,CAc3E"}
@@ -2,14 +2,21 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
+ import { useMemo } from "react";
5
6
  import { isPresentationHierarchyNode } from "../TreeNode.js";
6
7
  /** @alpha */
7
8
  export function isPlaceholderNode(node) {
8
9
  return "placeholder" in node;
9
10
  }
10
- /** @alpha */
11
- export function flattenNodes(rootNodes) {
12
- return getFlatNodes(rootNodes, 1);
11
+ /**
12
+ * Used to get a list of `FlatTreeNode` objects for the given list of `PresentationTreeNode` objects that represent
13
+ * a hierarchical structure. The resulting nodes can be used to render the hierarchy in a flat manner, e.g. using a
14
+ * virtualized list.
15
+ *
16
+ * @alpha
17
+ */
18
+ export function useFlatTreeNodeList(rootNodes) {
19
+ return useMemo(() => getFlatNodes(rootNodes, 1), [rootNodes]);
13
20
  }
14
21
  function getFlatNodes(nodes, level) {
15
22
  const flatNodes = [];
@@ -30,8 +37,13 @@ function getFlatNodes(nodes, level) {
30
37
  });
31
38
  return flatNodes;
32
39
  }
33
- export function getErrors(rootNodes) {
34
- return rootNodes.flatMap((rootNode) => {
40
+ /**
41
+ * Finds and returns all error nodes in a given hierarchy in the form of `PresentationTreeNode[]`.
42
+ *
43
+ * @alpha
44
+ */
45
+ export function useErrorList(rootNodes) {
46
+ return useMemo(() => rootNodes.flatMap((rootNode) => {
35
47
  if (!isPresentationHierarchyNode(rootNode)) {
36
48
  return [{ parent: undefined, error: rootNode, expandTo: (expandNode) => expandTo(expandNode, []) }];
37
49
  }
@@ -39,7 +51,7 @@ export function getErrors(rootNodes) {
39
51
  return [];
40
52
  }
41
53
  return getErrorNodes(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);
42
- });
54
+ }), [rootNodes]);
43
55
  }
44
56
  function getErrorNodes(parent, path) {
45
57
  const errorList = [];
@@ -1 +1 @@
1
- {"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,2BAA2B,EAAyE,MAAM,gBAAgB,CAAC;AA0BpI,aAAa;AACb,MAAM,UAAU,iBAAiB,CAAC,IAAkB;IAClD,OAAO,aAAa,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED,aAAa;AACb,MAAM,UAAU,YAAY,CAAC,SAAiC;IAC5D,OAAO,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,YAAY,CAAC,KAA6B,EAAE,KAAa;IAChE,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,KAAK,CAAC,OA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CAAC;AAC/C,CAAC","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 { isPresentationHierarchyNode, PresentationHierarchyNode, PresentationInfoNode, PresentationTreeNode } from \"../TreeNode.js\";\n\n/** @alpha */\ninterface PlaceholderNode {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/** @alpha */\nexport type FlatNode = {\n level: number;\n levelSize: number;\n posInLevel: number;\n} & PresentationHierarchyNode;\n\n/** @alpha */\nexport interface ErrorNode {\n error: PresentationInfoNode;\n parent?: PresentationHierarchyNode;\n expandTo: (expandNode: (nodeId: string) => void) => void;\n}\n\n/** @alpha */\nexport type FlatTreeNode = FlatNode | PlaceholderNode;\n\n/** @alpha */\nexport function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode {\n return \"placeholder\" in node;\n}\n\n/** @alpha */\nexport function flattenNodes(rootNodes: PresentationTreeNode[]) {\n return getFlatNodes(rootNodes, 1);\n}\n\nfunction getFlatNodes(nodes: PresentationTreeNode[], level: number) {\n const flatNodes: FlatTreeNode[] = [];\n nodes.forEach((node, index) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n flatNodes.push({ ...node, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!node.isExpanded) {\n return;\n }\n if (node.children !== true) {\n const childNodes = getFlatNodes(node.children, level + 1);\n flatNodes.push(...childNodes);\n return;\n }\n\n flatNodes.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } satisfies PlaceholderNode);\n });\n return flatNodes;\n}\n\nexport function getErrors(rootNodes: PresentationTreeNode[]): ErrorNode[] {\n return rootNodes.flatMap((rootNode) => {\n if (!isPresentationHierarchyNode(rootNode)) {\n return [{ parent: undefined, error: rootNode, expandTo: (expandNode) => expandTo(expandNode, []) }];\n }\n if (rootNode.children === true) {\n return [];\n }\n return getErrorNodes(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);\n });\n}\n\nfunction getErrorNodes(parent: PresentationHierarchyNode, path: string[]) {\n const errorList: ErrorNode[] = [];\n\n if (parent.children === true) {\n return [];\n }\n\n const pathToChild = [...path, ...(!parent.isExpanded ? [parent.id] : [])];\n parent.children.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n errorList.push({ parent, error: node, expandTo: (expandNode) => expandTo(expandNode, path) });\n return;\n }\n\n if (node.children !== true) {\n const childErrorList = getErrorNodes(node, pathToChild);\n errorList.push(...childErrorList);\n return;\n }\n });\n return errorList;\n}\n\nfunction expandTo(expandNode: (nodeId: string) => void, path: string[]) {\n path.forEach((nodeId) => expandNode(nodeId));\n}\n"]}
1
+ {"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,2BAA2B,EAAyE,MAAM,gBAAgB,CAAC;AA4CpI,aAAa;AACb,MAAM,UAAU,iBAAiB,CAAC,IAAkB;IAClD,OAAO,aAAa,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiC;IACnE,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,YAAY,CAAC,KAA6B,EAAE,KAAa;IAChE,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,OAAO;QACT,CAAC;QACD,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,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CAAC;IAC5E,CAAC,CAAC,EACJ,CAAC,SAAS,CAAC,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,MAAiC,EAAE,IAAc;IACtE,MAAM,SAAS,GAAgB,EAAE,CAAC;IAElC,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1E,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC/B,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9F,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;YACxD,SAAS,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;YAClC,OAAO;QACT,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,UAAoC,EAAE,IAAc;IACpE,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC","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 { useMemo } from \"react\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode, PresentationInfoNode, PresentationTreeNode } from \"../TreeNode.js\";\n\n/**\n * Placeholder node that is added to hierarchy as a child for a parent node while its child nodes are loading.\n *\n * @alpha\n * */\ninterface PlaceholderNode {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/**\n * An extended `PresentationHierarchyNode` node with properties needed for a flat tree structure.\n *\n * @alpha\n */\nexport type FlatNode = {\n level: number;\n levelSize: number;\n posInLevel: number;\n} & PresentationHierarchyNode;\n\n/**\n * A node used to build an error message.\n * Returned by `useErrorList`.\n *\n * @alpha\n * */\nexport interface ErrorNode {\n error: PresentationInfoNode;\n parent?: PresentationHierarchyNode;\n expandTo: (expandNode: (nodeId: string) => void) => void;\n}\n\n/**\n * A node describing single tree item position and its content inside tree.\n * Returned by `useFlatTreeNodeList` hook.\n *\n * @alpha\n */\nexport type FlatTreeNode = FlatNode | PlaceholderNode;\n\n/** @alpha */\nexport function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode {\n return \"placeholder\" in node;\n}\n\n/**\n * Used to get a list of `FlatTreeNode` objects for the given list of `PresentationTreeNode` objects that represent\n * a hierarchical structure. The resulting nodes can be used to render the hierarchy in a flat manner, e.g. using a\n * virtualized list.\n *\n * @alpha\n */\nexport function useFlatTreeNodeList(rootNodes: PresentationTreeNode[]) {\n return useMemo(() => getFlatNodes(rootNodes, 1), [rootNodes]);\n}\n\nfunction getFlatNodes(nodes: PresentationTreeNode[], level: number) {\n const flatNodes: FlatTreeNode[] = [];\n nodes.forEach((node, index) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n flatNodes.push({ ...node, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!node.isExpanded) {\n return;\n }\n if (node.children !== true) {\n const childNodes = getFlatNodes(node.children, level + 1);\n flatNodes.push(...childNodes);\n return;\n }\n\n flatNodes.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } satisfies PlaceholderNode);\n });\n return flatNodes;\n}\n\n/**\n * Finds and returns all error nodes in a given hierarchy in the form of `PresentationTreeNode[]`.\n *\n * @alpha\n */\nexport function useErrorList(rootNodes: PresentationTreeNode[]): ErrorNode[] {\n return useMemo(\n () =>\n rootNodes.flatMap((rootNode) => {\n if (!isPresentationHierarchyNode(rootNode)) {\n return [{ parent: undefined, error: rootNode, expandTo: (expandNode) => expandTo(expandNode, []) }];\n }\n if (rootNode.children === true) {\n return [];\n }\n return getErrorNodes(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);\n }),\n [rootNodes],\n );\n}\n\nfunction getErrorNodes(parent: PresentationHierarchyNode, path: string[]) {\n const errorList: ErrorNode[] = [];\n\n if (parent.children === true) {\n return [];\n }\n\n const pathToChild = [...path, ...(!parent.isExpanded ? [parent.id] : [])];\n parent.children.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n errorList.push({ parent, error: node, expandTo: (expandNode) => expandTo(expandNode, path) });\n return;\n }\n\n if (node.children !== true) {\n const childErrorList = getErrorNodes(node, pathToChild);\n errorList.push(...childErrorList);\n return;\n }\n });\n return errorList;\n}\n\nfunction expandTo(expandNode: (nodeId: string) => void, path: string[]) {\n path.forEach((nodeId) => expandNode(nodeId));\n}\n"]}