@itwin/presentation-hierarchies-react 2.0.0-alpha.20 → 2.0.0-alpha.21

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 (61) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +85 -0
  3. package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
  4. package/lib/esm/presentation-hierarchies-react/Renderers.js +6 -0
  5. package/lib/esm/presentation-hierarchies-react/Renderers.js.map +1 -0
  6. package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +14 -25
  7. package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
  8. package/lib/esm/presentation-hierarchies-react/TreeNode.js +1 -7
  9. package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +1 -1
  10. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +2 -2
  11. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
  12. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +0 -7
  13. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
  14. package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +28 -68
  15. package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
  16. package/lib/esm/presentation-hierarchies-react/UseTree.js +42 -36
  17. package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
  18. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +2 -2
  19. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +1 -1
  20. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +31 -16
  21. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
  22. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +24 -6
  23. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +1 -1
  24. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +28 -32
  25. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
  26. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +6 -29
  27. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +1 -1
  28. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +31 -27
  29. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
  30. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +2 -2
  31. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
  32. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +2 -3
  33. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
  34. package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts +3 -3
  35. package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts.map +1 -1
  36. package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js.map +1 -1
  37. package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +5 -6
  38. package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -1
  39. package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +5 -9
  40. package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -1
  41. package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +6 -6
  42. package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -1
  43. package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +3 -3
  44. package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -1
  45. package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +7 -7
  46. package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -1
  47. package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +13 -13
  48. package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -1
  49. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +3 -6
  50. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -1
  51. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +14 -5
  52. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -1
  53. package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +5 -11
  54. package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -1
  55. package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +11 -26
  56. package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
  57. package/lib/esm/presentation-hierarchies-react.d.ts +6 -4
  58. package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
  59. package/lib/esm/presentation-hierarchies-react.js +3 -3
  60. package/lib/esm/presentation-hierarchies-react.js.map +1 -1
  61. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @itwin/presentation-hierarchies-react
2
2
 
3
+ ## 2.0.0-alpha.21
4
+
5
+ ### Major Changes
6
+
7
+ - [#961](https://github.com/iTwin/presentation/pull/961): **Breaking changes** to tree state hooks `useTree`, `useUnifiedSelectionTree`, `useIModelTree`, `useIModelUnifiedSelectionTree`:
8
+
9
+ - All tree rendering props have been moved under `treeRendererProps`. The value can be passed to `<StrataKitTreeRenderer />` component.
10
+ - In case an error occurs while loading the root hierarchy level, instead of `treeRendererProps`, the `rootErrorRendererProps` are set, which can be passed to `<StrataKitRootErrorRenderer />` component to render the error state.
11
+ - The `isLoading` attribute has been renamed to `isReloading`.
12
+ - Errors are no longer defined as children of `PresentationHierarchyNode` and instead are now included as `error` attribute for more fluent API.
13
+
14
+ When rendering tree state, the recommended order of checks is:
15
+
16
+ 1. If `rootErrorRendererProps` is defined, there was an error - render error state.
17
+ 2. If `treeRendererProps` is not defined, the component is doing the initial load - render loading state.
18
+ 3. If `treeRendererProps` is defined, the hierarchy is loaded - render the tree component.
19
+
20
+ The `isReloading` attribute may also be set at the same time, indicating that the hierarchy is being reloaded in the background. Consumers may want to render an overlay in this case, or not render the tree at all.
21
+
22
+ Example:
23
+
24
+ ```ts
25
+ function MyComponent () {
26
+ const useTreeResult = useIModelUnifiedSelectionTree({...});
27
+
28
+ // handle possible root errors with our provided component or your own custom implementation
29
+ if (treeProps.rootErrorRendererProps) {
30
+ return <StrataKitRootErrorRenderer {...useTreeResult.rootErrorRendererProps} />;
31
+ }
32
+
33
+ // handle loading state
34
+ if (!treeProps.treeRendererProps) {
35
+ return <MyLoadingComponent />;
36
+ }
37
+
38
+ // handle loaded hierarchy
39
+ return <StrataKitTreeRenderer {...useTreeResult.treeProps} />;
40
+ }
41
+ ```
42
+
3
43
  ## 2.0.0-alpha.20
4
44
 
5
45
  ### Major Changes
@@ -0,0 +1,85 @@
1
+ import { GenericInstanceFilter, HierarchyNode } from "@itwin/presentation-hierarchies";
2
+ import { InstanceKey } from "@itwin/presentation-shared";
3
+ import { ErrorInfo, PresentationHierarchyNode } from "./TreeNode.js";
4
+ import { SelectionChangeType } from "./UseSelectionHandler.js";
5
+ /**
6
+ * Type definition used to render tree rendering UI component.
7
+ * @alpha
8
+ */
9
+ export type TreeRendererProps = {
10
+ /**
11
+ * Array containing root tree nodes.
12
+ */
13
+ rootNodes: PresentationHierarchyNode[];
14
+ /**
15
+ * A function that should be called to either expand or collapse the given node.
16
+ */
17
+ expandNode: (nodeId: string, isExpanded: boolean) => void;
18
+ /**
19
+ * A function that should be called to select nodes in the tree.
20
+ * @param nodeIds Ids of the nodes that are selected.
21
+ * @param changeType Type of change that occurred for the selection.
22
+ */
23
+ selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;
24
+ /** Determines whether a given node is selected. */
25
+ isNodeSelected: (nodeId: string) => boolean;
26
+ } & CommonRendererProps;
27
+ /**
28
+ * Type definition used to render root error handling UI component.
29
+ * @alpha
30
+ */
31
+ export type RootErrorRendererProps = {
32
+ /** Object containing root error information */
33
+ error: ErrorInfo;
34
+ } & CommonRendererProps;
35
+ /**
36
+ * @alpha
37
+ */
38
+ interface CommonRendererProps {
39
+ /**
40
+ * A function that should be called to reload the tree.
41
+ */
42
+ reloadTree: (options?: ReloadTreeOptions) => void;
43
+ /** Returns hierarchy level details for a given node ID. */
44
+ getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;
45
+ }
46
+ /**
47
+ * Options for doing either full or a sub tree reload.
48
+ * @public
49
+ */
50
+ interface ReloadTreeOptions {
51
+ /** Specifies parent node under which sub tree should be reloaded. */
52
+ parentNodeId: string | undefined;
53
+ /**
54
+ * Specifies how current tree state should be handled:
55
+ * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).
56
+ * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.
57
+ * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.
58
+ *
59
+ * Defaults to `"keep"`.
60
+ */
61
+ state?: "keep" | "discard" | "reset";
62
+ }
63
+ /**
64
+ * A data structure that contains information about a single hierarchy level.
65
+ * @public
66
+ */
67
+ export interface HierarchyLevelDetails {
68
+ /** The parent node whose hierarchy level's information is contained in this data structure */
69
+ hierarchyNode: HierarchyNode | undefined;
70
+ /** A function to get instance keys of the hierarchy level. */
71
+ getInstanceKeysIterator: (props?: {
72
+ instanceFilter?: GenericInstanceFilter;
73
+ hierarchyLevelSizeLimit?: number | "unbounded";
74
+ }) => AsyncIterableIterator<InstanceKey>;
75
+ /** Get the limit of how many nodes can be loaded in this hierarchy level. */
76
+ sizeLimit?: number | "unbounded";
77
+ /** Set the limit of how many nodes can be loaded in this hierarchy level. */
78
+ setSizeLimit: (value: undefined | number | "unbounded") => void;
79
+ /** Get the active instance filter applied to this hierarchy level. */
80
+ instanceFilter?: GenericInstanceFilter;
81
+ /** Set the instance filter to apply to this hierarchy level */
82
+ setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;
83
+ }
84
+ export {};
85
+ //# sourceMappingURL=Renderers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Renderers.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/Renderers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,SAAS,EAAE,yBAAyB,EAAE,CAAC;IACvC;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1D;;;;OAIG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC/E,mDAAmD;IACnD,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CAC7C,GAAG,mBAAmB,CAAC;AAExB;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,+CAA+C;IAC/C,KAAK,EAAE,SAAS,CAAC;CAClB,GAAG,mBAAmB,CAAC;AAExB;;GAEG;AACH,UAAU,mBAAmB;IAC3B;;OAEG;IACH,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAClD,2DAA2D;IAC3D,wBAAwB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,qBAAqB,GAAG,SAAS,CAAC;CAC7F;AAED;;;GAGG;AACH,UAAU,iBAAiB;IACzB,qEAAqE;IACrE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,8FAA8F;IAC9F,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,8DAA8D;IAC9D,uBAAuB,EAAE,CAAC,KAAK,CAAC,EAAE;QAChC,cAAc,CAAC,EAAE,qBAAqB,CAAC;QACvC,uBAAuB,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;KAChD,KAAK,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAEzC,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACjC,6EAA6E;IAC7E,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,WAAW,KAAK,IAAI,CAAC;IAEhE,sEAAsE;IACtE,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,+DAA+D;IAC/D,iBAAiB,EAAE,CAAC,MAAM,EAAE,qBAAqB,GAAG,SAAS,KAAK,IAAI,CAAC;CACxE"}
@@ -0,0 +1,6 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ export {};
6
+ //# sourceMappingURL=Renderers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Renderers.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/Renderers.ts"],"names":[],"mappings":"AAAA;;;gGAGgG","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 { GenericInstanceFilter, HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey } from \"@itwin/presentation-shared\";\nimport { ErrorInfo, PresentationHierarchyNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\n\n/**\n * Type definition used to render tree rendering UI component.\n * @alpha\n */\nexport type TreeRendererProps = {\n /**\n * Array containing root tree nodes.\n */\n rootNodes: PresentationHierarchyNode[];\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} & CommonRendererProps;\n\n/**\n * Type definition used to render root error handling UI component.\n * @alpha\n */\nexport type RootErrorRendererProps = {\n /** Object containing root error information */\n error: ErrorInfo;\n} & CommonRendererProps;\n\n/**\n * @alpha\n */\ninterface CommonRendererProps {\n /**\n * A function that should be called to reload the tree.\n */\n reloadTree: (options?: ReloadTreeOptions) => void;\n /** Returns hierarchy level details for a given node ID. */\n getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;\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/**\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"]}
@@ -1,71 +1,60 @@
1
1
  import { HierarchyNode } from "@itwin/presentation-hierarchies";
2
2
  /**
3
- * A type that defines an actual expandable node in a UI tree component, built with `useTree` hook.
3
+ * A type that defines an node in a UI tree component, built with `useTree` hook.
4
4
  * @public
5
5
  */
6
6
  export interface PresentationHierarchyNode {
7
7
  id: string;
8
8
  label: string;
9
- children: true | Array<PresentationTreeNode>;
9
+ children: true | Array<PresentationHierarchyNode>;
10
10
  isExpanded: boolean;
11
11
  isLoading: boolean;
12
12
  isFilterable: boolean;
13
13
  isFiltered: boolean;
14
14
  /** UI-agnostic source of this node object. */
15
15
  nodeData: HierarchyNode;
16
+ /** Contains error encountered from expanding the node */
17
+ error?: ErrorInfo;
16
18
  }
17
19
  /**
18
- * A type of `PresentationInfoNode` that is returned as the single child of a filtered parent node,
20
+ * A type of `ErrorInfo` that is returned,
19
21
  * when none of the child nodes match the filter.
20
22
  *
21
23
  * @public
22
24
  */
23
- export interface PresentationNoFilterMatchesInfoNode {
25
+ export interface NoFilterMatchesErrorInfo {
24
26
  id: string;
25
- parentNodeId: string | undefined;
26
27
  type: "NoFilterMatches";
27
28
  }
28
29
  /**
29
- * A type of `PresentationInfoNode` that is returned as the single child of a parent node, when the
30
+ * A type of `ErrorInfo` that is returned, when the
30
31
  * number of child nodes exceeds the limit set on the tree nodes loader. The limit is also included
31
- * on this node as `resultSetSizeLimit` attribute.
32
+ * on this error as `resultSetSizeLimit` attribute.
32
33
  *
33
34
  * @public
34
35
  */
35
- export interface PresentationResultSetTooLargeInfoNode {
36
+ export interface ResultSetTooLargeErrorInfo {
36
37
  id: string;
37
- parentNodeId: string | undefined;
38
38
  type: "ResultSetTooLarge";
39
39
  resultSetSizeLimit: number;
40
40
  }
41
41
  /**
42
- * A type of `PresentationInfoNode` that contains a user-friendly message to be displayed in the UI.
43
- * Generally, this is the only child of a parent node, created in cases like an error loading children. The
42
+ * A type of `ErrorInfo` that contains a user-friendly message to be displayed in the UI.
43
+ * Created in cases like an error loading children. The
44
44
  * renderer may offer users to re-load the children or the whole component in such cases.
45
45
  *
46
46
  * @public
47
47
  */
48
- export interface PresentationGenericInfoNode {
48
+ export interface GenericErrorInfo {
49
49
  id: string;
50
- parentNodeId: string | undefined;
51
50
  type: "Unknown";
52
51
  message: string;
53
52
  }
54
53
  /**
55
- * A type that defines a non-expandable, non-selectable informational node in a UI tree component, built
54
+ * A collection of types that defines an error state for `PresentationHierarchyNode` node in a UI tree component, built
56
55
  * with `useTree` hook.
57
56
  *
58
57
  * @public
59
58
  */
60
- export type PresentationInfoNode = PresentationGenericInfoNode | PresentationResultSetTooLargeInfoNode | PresentationNoFilterMatchesInfoNode;
61
- /**
62
- * A type that defines a node in a UI tree component, built with `useTree` hook.
63
- * @public
64
- */
65
- export type PresentationTreeNode = PresentationHierarchyNode | PresentationInfoNode;
66
- /**
67
- * An utility function to check if a node is a `PresentationHierarchyNode`.
68
- * @public
69
- */
70
- export declare function isPresentationHierarchyNode(node: PresentationTreeNode): node is PresentationHierarchyNode;
59
+ export type ErrorInfo = GenericErrorInfo | ResultSetTooLargeErrorInfo | NoFilterMatchesErrorInfo;
71
60
  //# sourceMappingURL=TreeNode.d.ts.map
@@ -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;CACzB;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;;;;;;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
+ {"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,yBAAyB,CAAC,CAAC;IAClD,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,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,mBAAmB,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,wBAAwB,CAAC"}
@@ -2,11 +2,5 @@
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
- /**
6
- * An utility function to check if a node is a `PresentationHierarchyNode`.
7
- * @public
8
- */
9
- export function isPresentationHierarchyNode(node) {
10
- return "children" in node;
11
- }
5
+ export {};
12
6
  //# sourceMappingURL=TreeNode.js.map
@@ -1 +1 @@
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"]}
1
+ {"version":3,"file":"TreeNode.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG","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 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<PresentationHierarchyNode>;\n isExpanded: boolean;\n isLoading: boolean;\n isFilterable: boolean;\n isFiltered: boolean;\n /** UI-agnostic source of this node object. */\n nodeData: HierarchyNode;\n /** Contains error encountered from expanding the node */\n error?: ErrorInfo;\n}\n\n/**\n * A type of `ErrorInfo` that is returned,\n * when none of the child nodes match the filter.\n *\n * @public\n */\nexport interface NoFilterMatchesErrorInfo {\n id: string;\n type: \"NoFilterMatches\";\n}\n\n/**\n * A type of `ErrorInfo` that is returned, when the\n * number of child nodes exceeds the limit set on the tree nodes loader. The limit is also included\n * on this error as `resultSetSizeLimit` attribute.\n *\n * @public\n */\nexport interface ResultSetTooLargeErrorInfo {\n id: string;\n type: \"ResultSetTooLarge\";\n resultSetSizeLimit: number;\n}\n\n/**\n * A type of `ErrorInfo` that contains a user-friendly message to be displayed in the UI.\n * 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 GenericErrorInfo {\n id: string;\n type: \"Unknown\";\n message: string;\n}\n\n/**\n * A collection of types that defines an error state for `PresentationHierarchyNode` node in a UI tree component, built\n * with `useTree` hook.\n *\n * @public\n */\nexport type ErrorInfo = GenericErrorInfo | ResultSetTooLargeErrorInfo | NoFilterMatchesErrorInfo;\n"]}
@@ -1,5 +1,5 @@
1
+ import { TreeRendererProps } from "./Renderers.js";
1
2
  import { PresentationHierarchyNode } from "./TreeNode.js";
2
- import { useTree } from "./UseTree.js";
3
3
  /**
4
4
  * A union of different supported selection modes in a tree component:
5
5
  * - `none` - no selection is allowed,
@@ -23,7 +23,7 @@ export type SelectionChangeType = "add" | "replace" | "remove";
23
23
  * Props for `useSelectionHandler` hook.
24
24
  * @public
25
25
  */
26
- type UseSelectionHandlerProps = Pick<ReturnType<typeof useTree>, "rootNodes" | "selectNodes"> & {
26
+ type UseSelectionHandlerProps = Pick<TreeRendererProps, "selectNodes" | "rootNodes"> & {
27
27
  /** Selection mode that the component is working in. */
28
28
  selectionMode: SelectionMode;
29
29
  };
@@ -1 +1 @@
1
- {"version":3,"file":"UseSelectionHandler.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"names":[],"mappings":"AAMA,OAAO,EAA+B,yBAAyB,EAAwB,MAAM,eAAe,CAAC;AAC7G,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;AAExE;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,C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AC1E,WAAW,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC;IAC9H,iFAAiF;IACjF,aAAa,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACxH;AAOD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,yBAAyB,CA8D9F"}
@@ -3,7 +3,6 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { useCallback, useEffect, useRef } from "react";
6
- import { isPresentationHierarchyNode } from "./TreeNode.js";
7
6
  /**
8
7
  * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.
9
8
  * @public
@@ -16,9 +15,6 @@ export function useSelectionHandler(props) {
16
15
  nodeIdToIndexMap: new Map(),
17
16
  });
18
17
  useEffect(() => {
19
- if (!rootNodes) {
20
- return;
21
- }
22
18
  state.current = computeFlatNodeList(rootNodes);
23
19
  }, [rootNodes]);
24
20
  const getNodeRange = (firstId, secondId) => {
@@ -82,9 +78,6 @@ function computeFlatNodeList(rootNodes) {
82
78
  const nodeIdToIndexMap = new Map();
83
79
  const flattenNodeRecursively = (nodes) => {
84
80
  nodes.forEach((node) => {
85
- if (!isPresentationHierarchyNode(node)) {
86
- return;
87
- }
88
81
  nodeIdToIndexMap.set(node.id, flatNodeList.length);
89
82
  flatNodeList.push(node.id);
90
83
  if (node.isExpanded && typeof node.children !== "boolean") {
@@ -1 +1 @@
1
- {"version":3,"file":"UseSelectionHandler.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,W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AC;IACD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC7C,CAAC;AAED,SAAS,mBAAmB,CAAC,SAAsC;IACjE,MAAM,YAAY,GAAkB,EAAE,CAAC;IACvC,MAAM,gBAAgB,GAAwB,IAAI,GAAG,EAAE,CAAC;IAExD,MAAM,sBAAsB,GAAG,CAAC,KAAkC,EAAE,EAAE;QACpE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvC,OAAO;YACT,CAAC;YACD,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;YACnD,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC3B,IAAI,IAAI,CAAC,UAAU,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC1D,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAClC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAC5C,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 } from \"react\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode, PresentationTreeNode } from \"./TreeNode.js\";\nimport { useTree } from \"./UseTree.js\";\n\n/**\n * A union of different supported selection modes in a tree component:\n * - `none` - no selection is allowed,\n * - `single` - only one node can be selected at a time,\n * - `extended` - multiple nodes can be selected using shift and ctrl keys,\n * - `multiple` - multiple nodes can be selected without using shift or ctrl keys.\n *\n * @public\n */\nexport type SelectionMode = \"none\" | \"single\" | \"extended\" | \"multiple\";\n\n/**\n * Type of selection change.\n * - `add` - a node was added to the selection,\n * - `replace` - a selected node was replaced with a different one,\n * - `remove` - a node was removed from the selection.\n *\n * @public\n */\nexport type SelectionChangeType = \"add\" | \"replace\" | \"remove\";\n\n/**\n * Props for `useSelectionHandler` hook.\n * @public\n */\ntype UseSelectionHandlerProps = Pick<ReturnType<typeof useTree>, \"rootNodes\" | \"selectNodes\"> & {\n /** Selection mode that the component is working in. */\n selectionMode: SelectionMode;\n};\n\n/**\n * Result of `useSelectionHandler` hook.\n * @public\n */\ninterface UseSelectionHandlerResult {\n /** Should be called by node renderer when a node component is clicked. */\n onNodeClick: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Should be called by node renderer when a keyboard event happens on a node. */\n onNodeKeyDown: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n}\n\ninterface FlatTreeState {\n flatNodeList: Array<string>;\n nodeIdToIndexMap: Map<string, number>;\n}\n\n/**\n * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.\n * @public\n */\nexport function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult {\n const { rootNodes, selectionMode, selectNodes } = props;\n const previousSelectionRef = useRef<string | undefined>(undefined);\n const state = useRef<FlatTreeState>({\n flatNodeList: [],\n nodeIdToIndexMap: new Map(),\n });\n\n useEffect(() => {\n if (!rootNodes) {\n return;\n }\n state.current = computeFlatNodeList(rootNodes);\n }, [rootNodes]);\n\n const getNodeRange = (firstId?: string, secondId?: string) => {\n const getIndex = (nodeId?: string) => {\n return nodeId ? state.current.nodeIdToIndexMap.get(nodeId) : 0;\n };\n const firstIndex = getIndex(firstId);\n const secondIndex = getIndex(secondId);\n if (firstIndex === undefined || secondIndex === undefined) {\n return [];\n }\n\n const startingIndex = Math.min(firstIndex, secondIndex);\n const endIndex = Math.max(firstIndex, secondIndex);\n return state.current.flatNodeList.slice(startingIndex, endIndex + 1);\n };\n\n const onNodeSelect = useCallback(\n (nodeId: string, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean) => {\n const selection = getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown);\n if (selection.type === \"disabled\") {\n return;\n }\n\n const nodes = selection.select === \"range\" ? getNodeRange(previousSelectionRef.current, nodeId) : [nodeId];\n if (!nodes.length) {\n return;\n }\n\n selection.select !== \"range\" && (previousSelectionRef.current = nodeId);\n selectNodes(nodes, selection.type);\n },\n [selectionMode, selectNodes],\n );\n\n const onNodeClick = useCallback(\n (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => {\n return onNodeSelect(node.id, isSelected, event.shiftKey, event.ctrlKey);\n },\n [onNodeSelect],\n );\n\n const onNodeKeyDown = useCallback(\n (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => {\n if (event.key === \" \" || event.key === \"Spacebar\" || event.key === \"Enter\") {\n return onNodeSelect(node.id, isSelected, event.shiftKey, event.ctrlKey);\n }\n },\n [onNodeSelect],\n );\n\n return { onNodeClick, onNodeKeyDown };\n}\n\ninterface SelectionAction {\n select: \"node\" | \"range\";\n type: SelectionChangeType | \"disabled\";\n}\n\nfunction getSelectionAction(selectionMode: SelectionMode, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n switch (selectionMode) {\n case \"none\":\n return { select: \"node\", type: \"disabled\" };\n case \"single\":\n return { select: \"node\", type: isSelected ? \"replace\" : \"remove\" };\n case \"multiple\":\n return { select: \"node\", type: isSelected ? \"add\" : \"remove\" };\n case \"extended\":\n return getExtendedSelectionAction(isSelected, shiftDown, ctrlDown);\n }\n}\n\nfunction getExtendedSelectionAction(isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n if (shiftDown) {\n return { select: \"range\", type: \"replace\" };\n }\n if (ctrlDown) {\n return { select: \"node\", type: isSelected ? \"add\" : \"remove\" };\n }\n return { select: \"node\", type: \"replace\" };\n}\n\nfunction computeFlatNodeList(rootNodes: Array<PresentationTreeNode>): FlatTreeState {\n const flatNodeList: Array<string> = [];\n const nodeIdToIndexMap: Map<string, number> = new Map();\n\n const flattenNodeRecursively = (nodes: Array<PresentationTreeNode>) => {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n nodeIdToIndexMap.set(node.id, flatNodeList.length);\n flatNodeList.push(node.id);\n if (node.isExpanded && typeof node.children !== \"boolean\") {\n flattenNodeRecursively(node.children);\n }\n });\n };\n\n flattenNodeRecursively(rootNodes);\n return { flatNodeList, nodeIdToIndexMap };\n}\n"]}
1
+ {"version":3,"file":"UseSelectionHandler.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAkDvD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IACxD,MAAM,oBAAoB,GAAG,MAAM,CAAqB,SAAS,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,MAAM,CAAgB;QAClC,YAAY,EAAE,EAAE;QAChB,gBAAgB,EAAE,IAAI,GAAG,EAAE;KAC5B,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,OAAO,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,MAAM,YAAY,GAAG,CAAC,OAAgB,EAAE,QAAiB,EAAE,EAAE;QAC3D,MAAM,QAAQ,GAAG,CAAC,MAAe,EAAE,EAAE;YACnC,OAAO,MAAM,CAAC,CAAC,CAAC,KA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ourcesContent":["/*---------------------------------------------------------------------------------------------\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 } from \"react\";\nimport { TreeRendererProps } from \"./Renderers.js\";\nimport { PresentationHierarchyNode } from \"./TreeNode.js\";\n\n/**\n * A union of different supported selection modes in a tree component:\n * - `none` - no selection is allowed,\n * - `single` - only one node can be selected at a time,\n * - `extended` - multiple nodes can be selected using shift and ctrl keys,\n * - `multiple` - multiple nodes can be selected without using shift or ctrl keys.\n *\n * @public\n */\nexport type SelectionMode = \"none\" | \"single\" | \"extended\" | \"multiple\";\n\n/**\n * Type of selection change.\n * - `add` - a node was added to the selection,\n * - `replace` - a selected node was replaced with a different one,\n * - `remove` - a node was removed from the selection.\n *\n * @public\n */\nexport type SelectionChangeType = \"add\" | \"replace\" | \"remove\";\n\n/**\n * Props for `useSelectionHandler` hook.\n * @public\n */\ntype UseSelectionHandlerProps = Pick<TreeRendererProps, \"selectNodes\" | \"rootNodes\"> & {\n /** Selection mode that the component is working in. */\n selectionMode: SelectionMode;\n};\n\n/**\n * Result of `useSelectionHandler` hook.\n * @public\n */\ninterface UseSelectionHandlerResult {\n /** Should be called by node renderer when a node component is clicked. */\n onNodeClick: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Should be called by node renderer when a keyboard event happens on a node. */\n onNodeKeyDown: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n}\n\ninterface FlatTreeState {\n flatNodeList: Array<string>;\n nodeIdToIndexMap: Map<string, number>;\n}\n\n/**\n * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.\n * @public\n */\nexport function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult {\n const { rootNodes, selectionMode, selectNodes } = props;\n const previousSelectionRef = useRef<string | undefined>(undefined);\n const state = useRef<FlatTreeState>({\n flatNodeList: [],\n nodeIdToIndexMap: new Map(),\n });\n\n useEffect(() => {\n state.current = computeFlatNodeList(rootNodes);\n }, [rootNodes]);\n\n const getNodeRange = (firstId?: string, secondId?: string) => {\n const getIndex = (nodeId?: string) => {\n return nodeId ? state.current.nodeIdToIndexMap.get(nodeId) : 0;\n };\n const firstIndex = getIndex(firstId);\n const secondIndex = getIndex(secondId);\n if (firstIndex === undefined || secondIndex === undefined) {\n return [];\n }\n\n const startingIndex = Math.min(firstIndex, secondIndex);\n const endIndex = Math.max(firstIndex, secondIndex);\n return state.current.flatNodeList.slice(startingIndex, endIndex + 1);\n };\n\n const onNodeSelect = useCallback(\n (nodeId: string, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean) => {\n const selection = getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown);\n if (selection.type === \"disabled\") {\n return;\n }\n\n const nodes = selection.select === \"range\" ? getNodeRange(previousSelectionRef.current, nodeId) : [nodeId];\n if (!nodes.length) {\n return;\n }\n\n selection.select !== \"range\" && (previousSelectionRef.current = nodeId);\n selectNodes(nodes, selection.type);\n },\n [selectionMode, selectNodes],\n );\n\n const onNodeClick = useCallback(\n (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => {\n return onNodeSelect(node.id, isSelected, event.shiftKey, event.ctrlKey);\n },\n [onNodeSelect],\n );\n\n const onNodeKeyDown = useCallback(\n (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => {\n if (event.key === \" \" || event.key === \"Spacebar\" || event.key === \"Enter\") {\n return onNodeSelect(node.id, isSelected, event.shiftKey, event.ctrlKey);\n }\n },\n [onNodeSelect],\n );\n\n return { onNodeClick, onNodeKeyDown };\n}\n\ninterface SelectionAction {\n select: \"node\" | \"range\";\n type: SelectionChangeType | \"disabled\";\n}\n\nfunction getSelectionAction(selectionMode: SelectionMode, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n switch (selectionMode) {\n case \"none\":\n return { select: \"node\", type: \"disabled\" };\n case \"single\":\n return { select: \"node\", type: isSelected ? \"replace\" : \"remove\" };\n case \"multiple\":\n return { select: \"node\", type: isSelected ? \"add\" : \"remove\" };\n case \"extended\":\n return getExtendedSelectionAction(isSelected, shiftDown, ctrlDown);\n }\n}\n\nfunction getExtendedSelectionAction(isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n if (shiftDown) {\n return { select: \"range\", type: \"replace\" };\n }\n if (ctrlDown) {\n return { select: \"node\", type: isSelected ? \"add\" : \"remove\" };\n }\n return { select: \"node\", type: \"replace\" };\n}\n\nfunction computeFlatNodeList(rootNodes: Array<PresentationHierarchyNode>): FlatTreeState {\n const flatNodeList: Array<string> = [];\n const nodeIdToIndexMap: Map<string, number> = new Map();\n\n const flattenNodeRecursively = (nodes: Array<PresentationHierarchyNode>) => {\n nodes.forEach((node) => {\n nodeIdToIndexMap.set(node.id, flatNodeList.length);\n flatNodeList.push(node.id);\n if (node.isExpanded && typeof node.children !== \"boolean\") {\n flattenNodeRecursively(node.children);\n }\n });\n };\n\n flattenNodeRecursively(rootNodes);\n return { flatNodeList, nodeIdToIndexMap };\n}\n"]}
@@ -1,29 +1,8 @@
1
- import { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from "@itwin/presentation-hierarchies";
2
- import { InstanceKey, IPrimitiveValueFormatter } from "@itwin/presentation-shared";
1
+ import { GenericInstanceFilter, HierarchyFilteringPath, HierarchyProvider } from "@itwin/presentation-hierarchies";
2
+ import { IPrimitiveValueFormatter } from "@itwin/presentation-shared";
3
3
  import { UseUnifiedTreeSelectionProps } from "./internal/UseUnifiedSelection.js";
4
- import { PresentationHierarchyNode, PresentationTreeNode } from "./TreeNode.js";
5
- import { SelectionChangeType } from "./UseSelectionHandler.js";
6
- /**
7
- * A data structure that contains information about a single hierarchy level.
8
- * @public
9
- */
10
- export interface HierarchyLevelDetails {
11
- /** The parent node whose hierarchy level's information is contained in this data structure */
12
- hierarchyNode: HierarchyNode | undefined;
13
- /** A function to get instance keys of the hierarchy level. */
14
- getInstanceKeysIterator: (props?: {
15
- instanceFilter?: GenericInstanceFilter;
16
- hierarchyLevelSizeLimit?: number | "unbounded";
17
- }) => AsyncIterableIterator<InstanceKey>;
18
- /** Get the limit of how many nodes can be loaded in this hierarchy level. */
19
- sizeLimit?: number | "unbounded";
20
- /** Set the limit of how many nodes can be loaded in this hierarchy level. */
21
- setSizeLimit: (value: undefined | number | "unbounded") => void;
22
- /** Get the active instance filter applied to this hierarchy level. */
23
- instanceFilter?: GenericInstanceFilter;
24
- /** Set the instance filter to apply to this hierarchy level */
25
- setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;
26
- }
4
+ import { RootErrorRendererProps, TreeRendererProps } from "./Renderers.js";
5
+ import { PresentationHierarchyNode } from "./TreeNode.js";
27
6
  /**
28
7
  * A React hook that creates state for a tree component.
29
8
  *
@@ -77,56 +56,37 @@ export interface UseTreeProps {
77
56
  error: unknown;
78
57
  }) => void;
79
58
  }
80
- /**
81
- * Options for doing either full or a sub tree reload.
82
- * @public
83
- */
84
- interface ReloadTreeOptions {
85
- /** Specifies parent node under which sub tree should be reloaded. */
86
- parentNodeId: string | undefined;
87
- /**
88
- * Specifies how current tree state should be handled:
89
- * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).
90
- * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.
91
- * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.
92
- *
93
- * Defaults to `"keep"`.
94
- */
95
- state?: "keep" | "discard" | "reset";
96
- }
97
59
  /** @public */
98
- export interface UseTreeResult {
99
- /**
100
- * Array containing root tree nodes. It is `undefined` on initial render until any nodes are loaded.
101
- */
102
- rootNodes: PresentationTreeNode[] | undefined;
60
+ export type UseTreeResult = {
103
61
  /**
104
- * Specifies whether tree is loading or not. It is set to `true` when initial tree load is in progress
62
+ * Specifies whether tree is reloading or not. It is set to `false` when initial tree load is in progress to check if
105
63
  * or tree is reloading.
106
64
  */
107
- isLoading: boolean;
108
- /**
109
- * A function that should be called to reload the tree.
110
- */
111
- reloadTree: (options?: ReloadTreeOptions) => void;
112
- /**
113
- * A function that should be called to either expand or collapse the given node.
114
- */
115
- expandNode: (nodeId: string, isExpanded: boolean) => void;
116
- /**
117
- * A function that should be called to select nodes in the tree.
118
- * @param nodeIds Ids of the nodes that are selected.
119
- * @param changeType Type of change that occurred for the selection.
120
- */
121
- selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;
122
- /** Determines whether a given node is selected. */
123
- isNodeSelected: (nodeId: string) => boolean;
65
+ isReloading: boolean;
124
66
  /** Get a tree node by id */
125
67
  getNode: (nodeId: string) => PresentationHierarchyNode | undefined;
126
- /** Returns hierarchy level details for a given node ID. */
127
- getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;
128
68
  /** Sets a formatter for the primitive values that are displayed in the hierarchy. */
129
69
  setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;
130
- }
70
+ } & RendererProps;
71
+ /**.
72
+ * @alpha
73
+ */
74
+ type RendererProps = {
75
+ /**
76
+ * An object containing information used to render root error handling UI.
77
+ * Use in combination with `RootErrorRenderer` or your custom implementation.
78
+ * Defined when root nodes fail to load.
79
+ */
80
+ rootErrorRendererProps: RootErrorRendererProps;
81
+ } | {
82
+ /** Is undefined when rootNodes where sucessfully loaded or are in initial loading process */
83
+ rootErrorRendererProps: undefined;
84
+ /**
85
+ * An object containing information used to render tree.
86
+ * Use with `TreeRenderer` or your custom implementation.
87
+ * Is undefined on initial loading process.
88
+ */
89
+ treeRendererProps?: TreeRendererProps;
90
+ };
131
91
  export {};
132
92
  //# sourceMappingURL=UseTree.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UseTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAA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