@itwin/presentation-hierarchies-react 0.5.3 → 0.7.0

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 (73) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +164 -79
  3. package/lib/cjs/presentation-hierarchies-react/TreeNode.js +1 -2
  4. package/lib/cjs/presentation-hierarchies-react/TreeNode.js.map +1 -1
  5. package/lib/cjs/presentation-hierarchies-react/UnifiedSelectionContext.js +2 -3
  6. package/lib/cjs/presentation-hierarchies-react/UnifiedSelectionContext.js.map +1 -1
  7. package/lib/cjs/presentation-hierarchies-react/UseSelectionHandler.d.ts +8 -2
  8. package/lib/cjs/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
  9. package/lib/cjs/presentation-hierarchies-react/UseSelectionHandler.js +1 -2
  10. package/lib/cjs/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
  11. package/lib/cjs/presentation-hierarchies-react/UseTree.d.ts +48 -8
  12. package/lib/cjs/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
  13. package/lib/cjs/presentation-hierarchies-react/UseTree.js +5 -5
  14. package/lib/cjs/presentation-hierarchies-react/UseTree.js.map +1 -1
  15. package/lib/cjs/presentation-hierarchies-react/internal/TreeActions.d.ts +5 -0
  16. package/lib/cjs/presentation-hierarchies-react/internal/TreeActions.d.ts.map +1 -1
  17. package/lib/cjs/presentation-hierarchies-react/internal/TreeActions.js +22 -4
  18. package/lib/cjs/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
  19. package/lib/cjs/presentation-hierarchies-react/internal/TreeLoader.d.ts +4 -0
  20. package/lib/cjs/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +1 -1
  21. package/lib/cjs/presentation-hierarchies-react/internal/TreeLoader.js +7 -1
  22. package/lib/cjs/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
  23. package/lib/cjs/presentation-hierarchies-react/internal/TreeModel.js +3 -3
  24. package/lib/cjs/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
  25. package/lib/cjs/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +8 -3
  26. package/lib/cjs/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
  27. package/lib/cjs/presentation-hierarchies-react/internal/UseUnifiedSelection.js +2 -3
  28. package/lib/cjs/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
  29. package/lib/cjs/presentation-hierarchies-react/internal/Utils.js +3 -3
  30. package/lib/cjs/presentation-hierarchies-react/internal/Utils.js.map +1 -1
  31. package/lib/cjs/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +13 -3
  32. package/lib/cjs/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +1 -1
  33. package/lib/cjs/presentation-hierarchies-react/itwinui/LocalizationContext.js +6 -4
  34. package/lib/cjs/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +1 -1
  35. package/lib/cjs/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +9 -0
  36. package/lib/cjs/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
  37. package/lib/cjs/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +15 -17
  38. package/lib/cjs/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
  39. package/lib/cjs/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +4 -3
  40. package/lib/cjs/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +1 -1
  41. package/lib/cjs/presentation-hierarchies-react/itwinui/TreeRenderer.js +2 -3
  42. package/lib/cjs/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +1 -1
  43. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +8 -2
  44. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
  45. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
  46. package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +48 -8
  47. package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
  48. package/lib/esm/presentation-hierarchies-react/UseTree.js +3 -2
  49. package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
  50. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +5 -0
  51. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +1 -1
  52. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +22 -4
  53. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
  54. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +4 -0
  55. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +1 -1
  56. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +7 -1
  57. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
  58. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +8 -3
  59. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
  60. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +1 -1
  61. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
  62. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +13 -3
  63. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +1 -1
  64. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js +4 -1
  65. package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +1 -1
  66. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +9 -0
  67. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
  68. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +14 -15
  69. package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
  70. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +4 -3
  71. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +1 -1
  72. package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +1 -1
  73. package/package.json +24 -22
@@ -27,10 +27,14 @@ export interface ITreeLoader {
27
27
  export declare class TreeLoader implements ITreeLoader {
28
28
  private _hierarchyProvider;
29
29
  private _onHierarchyLimitExceeded;
30
+ private _onHierarchyLoadError;
30
31
  constructor(_hierarchyProvider: HierarchyProvider, _onHierarchyLimitExceeded: (props: {
31
32
  parentId?: string;
32
33
  filter?: GenericInstanceFilter;
33
34
  limit?: number | "unbounded";
35
+ }) => void, _onHierarchyLoadError: (props: {
36
+ parentId?: string;
37
+ type: "timeout" | "unknown";
34
38
  }) => void);
35
39
  private loadChildren;
36
40
  loadNodes({ shouldLoadChildren, ...options }: LoadNodesOptions): Observable<LoadedTreePart>;
@@ -1 +1 @@
1
- {"version":3,"file":"TreeLoader.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2C,UAAU,EAAe,MAAM,MAAM,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAiB,iBAAiB,EAA0B,MAAM,iCAAiC,CAAC;AAClI,OAAO,EAA4B,sBAAsB,EAAqB,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGpI,gBAAgB;AAChB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,WAAW,EAAE,aAAa,EAAE,CAAC;CAC9B;AAED,gBAAgB;AAChB,MAAM,WAAW,qBAAqB;IACpC,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,uBAAuB,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;CAChD;AAED,gBAAgB;AAChB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,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{ createNodeId } from "./Utils";
9
9
  export class TreeLoader {
10
10
  _hierarchyProvider;
11
11
  _onHierarchyLimitExceeded;
12
- constructor(_hierarchyProvider, _onHierarchyLimitExceeded) {
12
+ _onHierarchyLoadError;
13
+ constructor(_hierarchyProvider, _onHierarchyLimitExceeded, _onHierarchyLoadError) {
13
14
  this._hierarchyProvider = _hierarchyProvider;
14
15
  this._onHierarchyLimitExceeded = _onHierarchyLimitExceeded;
16
+ this._onHierarchyLoadError = _onHierarchyLoadError;
15
17
  }
16
18
  loadChildren({ parent, getHierarchyLevelOptions, buildNode, ignoreCache }) {
17
19
  const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);
@@ -31,6 +33,7 @@ export class TreeLoader {
31
33
  this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: hierarchyLevelSizeLimit });
32
34
  return of([{ ...nodeProps, type: "ResultSetTooLarge", resultSetSizeLimit: err.limit }]);
33
35
  }
36
+ this._onHierarchyLoadError({ parentId: parent.id, type: isTimeoutError(err) ? "timeout" : "unknown" });
34
37
  return of([{ ...nodeProps, type: "Unknown", message: "Failed to create hierarchy level" }]);
35
38
  }), map((childNodes) => ({
36
39
  parentId: parent.id,
@@ -70,4 +73,7 @@ function isRowsLimitError(error) {
70
73
  const asRowsError = error;
71
74
  return asRowsError.limit !== undefined && asRowsError.message.includes("Query rows limit of");
72
75
  }
76
+ function isTimeoutError(error) {
77
+ return error.message.includes("query too long to execute or server is too busy");
78
+ }
73
79
  //# sourceMappingURL=TreeLoader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TreeLoader.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAc,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAExF,OAAO,EAAE,wBA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B;YACxC,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC;YACtB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAuC;IAC9D,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAY;IACpC,MAAM,WAAW,GAAG,KAA+B,CAAC;IACpD,OAAO,WAAW,CAAC,KAAK,KAAK,SAAS,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAChG,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 { catchError, expand, from, map, mergeMap, Observable, of, toArray } from \"rxjs\";\nimport { GenericInstanceFilter, HierarchyNode, HierarchyProvider, RowsLimitExceededError } from \"@itwin/presentation-hierarchies\";\nimport { isTreeModelHierarchyNode, TreeModelHierarchyNode, TreeModelInfoNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel\";\nimport { createNodeId } from \"./Utils\";\n\n/** @internal */\nexport interface LoadedTreePart {\n parentId: string | undefined;\n loadedNodes: TreeModelNode[];\n}\n\n/** @internal */\nexport interface HierarchyLevelOptions {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n}\n\n/** @internal */\nexport interface LoadNodesOptions {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n getHierarchyLevelOptions: (node: TreeModelRootNode | TreeModelHierarchyNode) => HierarchyLevelOptions;\n shouldLoadChildren: (node: TreeModelHierarchyNode) => boolean;\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n ignoreCache?: boolean;\n}\n\n/** @internal */\nexport interface ITreeLoader {\n loadNodes(options: LoadNodesOptions): Observable<LoadedTreePart>;\n}\n\n/** @internal */\nexport class TreeLoader implements ITreeLoader {\n constructor(\n private _hierarchyProvider: HierarchyProvider,\n private _onHierarchyLimitExceeded: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void,\n ) {}\n\n private loadChildren({ parent, getHierarchyLevelOptions, buildNode, ignoreCache }: Omit<LoadNodesOptions, \"shouldLoadChildren\">) {\n const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);\n const infoNodeIdBase = `${parent.id ?? \"<root>\"}`;\n const treeModelNodesFactory = createTreeModelNodesFactory(buildNode);\n return from(\n this._hierarchyProvider.getNodes({\n parentNode: parent.nodeData,\n hierarchyLevelSizeLimit,\n instanceFilter,\n ignoreCache,\n }),\n ).pipe(\n toArray(),\n catchError((err) => {\n const nodeProps = {\n id: `${infoNodeIdBase}-${err.message}`,\n parentId: parent.id,\n };\n if (isRowsLimitError(err)) {\n this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: hierarchyLevelSizeLimit });\n return of([{ ...nodeProps, type: \"ResultSetTooLarge\" as const, resultSetSizeLimit: err.limit }]);\n }\n return of([{ ...nodeProps, type: \"Unknown\" as const, message: \"Failed to create hierarchy level\" }]);\n }),\n map(\n (childNodes): LoadedTreePart => ({\n parentId: parent.id,\n loadedNodes:\n instanceFilter && childNodes.length === 0\n ? [\n {\n id: `${infoNodeIdBase}-no-filter-matches`,\n parentId: parent.id,\n type: \"NoFilterMatches\" as const,\n },\n ]\n : childNodes.map(treeModelNodesFactory),\n }),\n ),\n );\n }\n\n public loadNodes({ shouldLoadChildren, ...options }: LoadNodesOptions) {\n return this.loadChildren(options).pipe(\n expand((loadedPart) =>\n from(loadedPart.loadedNodes.filter((node): node is TreeModelHierarchyNode => isTreeModelHierarchyNode(node) && shouldLoadChildren(node))).pipe(\n mergeMap((node) => this.loadChildren({ ...options, parent: node })),\n ),\n ),\n );\n }\n}\n\nfunction createTreeModelNodesFactory(\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode,\n): (node: TreeModelInfoNode | HierarchyNode) => TreeModelNode {\n return (node: TreeModelInfoNode | HierarchyNode) => {\n if (!isHierarchyNode(node)) {\n return node;\n }\n\n const modelNode: TreeModelHierarchyNode = {\n id: createNodeId(node),\n children: node.children,\n label: node.label,\n nodeData: node,\n };\n return buildNode ? buildNode(modelNode) : modelNode;\n };\n}\n\nfunction isHierarchyNode(node: TreeModelInfoNode | HierarchyNode): node is HierarchyNode {\n return \"key\" in node && node.key !== undefined;\n}\n\nfunction isRowsLimitError(error: Error): error is RowsLimitExceededError {\n const asRowsError = error as RowsLimitExceededError;\n return asRowsError.limit !== undefined && asRowsError.message.includes(\"Query rows limit of\");\n}\n"]}
1
+ {"version":3,"file":"TreeLoader.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAc,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAA+E,MAAM,aAAa,CAAC;AACpI,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA4BvC,gBAAgB;AAChB,MAAM,OAAO,UAAU;IAEX;IACA;IACA;IAHV,YACU,kBAAqC,EACrC,yBAA+H,EAC/H,qBAA0F;QAF1F,uBAAkB,GAAlB,kBAAkB,CAAmB;QACrC,8BAAyB,GAAzB,yBAAyB,CAAsG;QAC/H,0BAAqB,GAArB,qBAAqB,CAAqE;IACjG,CAAC;IAEI,YAAY,CAAC,EAAE,MAA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IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAuC;IAC9D,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAY;IACpC,MAAM,WAAW,GAAG,KAA+B,CAAC;IACpD,OAAO,WAAW,CAAC,KAAK,KAAK,SAAS,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAChG,CAAC;AAED,SAAS,cAAc,CAAC,KAAY;IAClC,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,iDAAiD,CAAC,CAAC;AACnF,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 { catchError, expand, from, map, mergeMap, Observable, of, toArray } from \"rxjs\";\nimport { GenericInstanceFilter, HierarchyNode, HierarchyProvider, RowsLimitExceededError } from \"@itwin/presentation-hierarchies\";\nimport { isTreeModelHierarchyNode, TreeModelHierarchyNode, TreeModelInfoNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel\";\nimport { createNodeId } from \"./Utils\";\n\n/** @internal */\nexport interface LoadedTreePart {\n parentId: string | undefined;\n loadedNodes: TreeModelNode[];\n}\n\n/** @internal */\nexport interface HierarchyLevelOptions {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n}\n\n/** @internal */\nexport interface LoadNodesOptions {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n getHierarchyLevelOptions: (node: TreeModelRootNode | TreeModelHierarchyNode) => HierarchyLevelOptions;\n shouldLoadChildren: (node: TreeModelHierarchyNode) => boolean;\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n ignoreCache?: boolean;\n}\n\n/** @internal */\nexport interface ITreeLoader {\n loadNodes(options: LoadNodesOptions): Observable<LoadedTreePart>;\n}\n\n/** @internal */\nexport class TreeLoader implements ITreeLoader {\n constructor(\n private _hierarchyProvider: HierarchyProvider,\n private _onHierarchyLimitExceeded: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void,\n private _onHierarchyLoadError: (props: { parentId?: string; type: \"timeout\" | \"unknown\" }) => void,\n ) {}\n\n private loadChildren({ parent, getHierarchyLevelOptions, buildNode, ignoreCache }: Omit<LoadNodesOptions, \"shouldLoadChildren\">) {\n const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);\n const infoNodeIdBase = `${parent.id ?? \"<root>\"}`;\n const treeModelNodesFactory = createTreeModelNodesFactory(buildNode);\n return from(\n this._hierarchyProvider.getNodes({\n parentNode: parent.nodeData,\n hierarchyLevelSizeLimit,\n instanceFilter,\n ignoreCache,\n }),\n ).pipe(\n toArray(),\n catchError((err) => {\n const nodeProps = {\n id: `${infoNodeIdBase}-${err.message}`,\n parentId: parent.id,\n };\n if (isRowsLimitError(err)) {\n this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: hierarchyLevelSizeLimit });\n return of([{ ...nodeProps, type: \"ResultSetTooLarge\" as const, resultSetSizeLimit: err.limit }]);\n }\n this._onHierarchyLoadError({ parentId: parent.id, type: isTimeoutError(err) ? \"timeout\" : \"unknown\" });\n return of([{ ...nodeProps, type: \"Unknown\" as const, message: \"Failed to create hierarchy level\" }]);\n }),\n map(\n (childNodes): LoadedTreePart => ({\n parentId: parent.id,\n loadedNodes:\n instanceFilter && childNodes.length === 0\n ? [\n {\n id: `${infoNodeIdBase}-no-filter-matches`,\n parentId: parent.id,\n type: \"NoFilterMatches\" as const,\n },\n ]\n : childNodes.map(treeModelNodesFactory),\n }),\n ),\n );\n }\n\n public loadNodes({ shouldLoadChildren, ...options }: LoadNodesOptions) {\n return this.loadChildren(options).pipe(\n expand((loadedPart) =>\n from(loadedPart.loadedNodes.filter((node): node is TreeModelHierarchyNode => isTreeModelHierarchyNode(node) && shouldLoadChildren(node))).pipe(\n mergeMap((node) => this.loadChildren({ ...options, parent: node })),\n ),\n ),\n );\n }\n}\n\nfunction createTreeModelNodesFactory(\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode,\n): (node: TreeModelInfoNode | HierarchyNode) => TreeModelNode {\n return (node: TreeModelInfoNode | HierarchyNode) => {\n if (!isHierarchyNode(node)) {\n return node;\n }\n\n const modelNode: TreeModelHierarchyNode = {\n id: createNodeId(node),\n children: node.children,\n label: node.label,\n nodeData: node,\n };\n return buildNode ? buildNode(modelNode) : modelNode;\n };\n}\n\nfunction isHierarchyNode(node: TreeModelInfoNode | HierarchyNode): node is HierarchyNode {\n return \"key\" in node && node.key !== undefined;\n}\n\nfunction isRowsLimitError(error: Error): error is RowsLimitExceededError {\n const asRowsError = error as RowsLimitExceededError;\n return asRowsError.limit !== undefined && asRowsError.message.includes(\"Query rows limit of\");\n}\n\nfunction isTimeoutError(error: Error) {\n return error.message.includes(\"query too long to execute or server is too busy\");\n}\n"]}
@@ -5,12 +5,17 @@ export interface TreeSelectionOptions {
5
5
  isNodeSelected: (nodeId: string) => boolean;
6
6
  selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;
7
7
  }
8
- /** @internal */
8
+ /** @beta */
9
9
  export interface UseUnifiedTreeSelectionProps {
10
+ /** Key of the iModel. */
10
11
  imodelKey: string;
12
+ /**
13
+ * Identifier to distinguish this source of changes to the unified selection from another ones in the application.
14
+ */
11
15
  sourceName: string;
12
- getNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined;
13
16
  }
14
17
  /** @internal */
15
- export declare function useUnifiedTreeSelection({ imodelKey, sourceName, getNode }: UseUnifiedTreeSelectionProps): TreeSelectionOptions;
18
+ export declare function useUnifiedTreeSelection({ imodelKey, sourceName, getNode, }: UseUnifiedTreeSelectionProps & {
19
+ getNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined;
20
+ }): TreeSelectionOptions;
16
21
  //# sourceMappingURL=UseUnifiedSelection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UseUnifiedSelection.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAA4B,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEzF,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,gBAAgB;AAChB,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,aAAa,GAAG,iBAAiB,GAAG,SAAS,CAAC;CAC5E;AAED,gBAAgB;AAChB,wBAAgB,uBAAuB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,4BAA4B,GAAG,oBAAoB,CA2B9H"}
1
+ {"version":3,"file":"UseUnifiedSelection.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAA4B,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEzF,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,YAAY;AACZ,MAAM,WAAW,4BAA4B;IAC3C,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,gBAAgB;AAChB,wBAAgB,uBAAuB,CAAC,EACtC,SAAS,EACT,UAAU,EACV,OAAO,GACR,EAAE,4BAA4B,GAAG;IAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,aAAa,GAAG,iBAAiB,GAAG,SAAS,CAAA;CAAE,GAAG,oBAAoB,CA2BtI"}
@@ -8,7 +8,7 @@ import { Selectables } from "@itwin/unified-selection";
8
8
  import { useUnifiedSelectionContext } from "../UnifiedSelectionContext";
9
9
  import { isTreeModelHierarchyNode } from "./TreeModel";
10
10
  /** @internal */
11
- export function useUnifiedTreeSelection({ imodelKey, sourceName, getNode }) {
11
+ export function useUnifiedTreeSelection({ imodelKey, sourceName, getNode, }) {
12
12
  const [options, setOptions] = useState(() => ({
13
13
  isNodeSelected: /* istanbul ignore next */ () => false,
14
14
  selectNodes: /* istanbul ignore next */ () => { },
@@ -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,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAc,WAAW,EAAoB,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC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KAAK,KAAK;oBACR,OAAO,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;oBACpC,OAAO;gBACT,KAAK,QAAQ;oBACX,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;oBACzC,OAAO;gBACT,KAAK,SAAS;oBACZ,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;oBACtC,OAAO;YACX,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc,EAAE,IAAmB;IAC5D,IAAI,aAAa,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC;IAC/B,CAAC;IAED,OAAO;QACL;YACE,UAAU,EAAE,MAAM;YAClB,KAAK,CAAC,CAAC,gBAAgB;gBACrB,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxC,OAAO;gBACT,CAAC;gBAED,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;oBAC3C,MAAM,GAAG,CAAC;gBACZ,CAAC;YACH,CAAC;YACD,IAAI,EAAE,IAAI;SACX;KACF,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 { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { Selectable, Selectables, SelectionStorage } from \"@itwin/unified-selection\";\nimport { useUnifiedSelectionContext } from \"../UnifiedSelectionContext\";\nimport { SelectionChangeType } from \"../UseSelectionHandler\";\nimport { isTreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @internal */\nexport interface UseUnifiedTreeSelectionProps {\n imodelKey: string;\n sourceName: string;\n getNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined;\n}\n\n/** @internal */\nexport function useUnifiedTreeSelection({ imodelKey, sourceName, getNode }: UseUnifiedTreeSelectionProps): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* istanbul ignore next */ () => false,\n selectNodes: /* istanbul ignore next */ () => {},\n }));\n\n const selectionStorage = useUnifiedSelectionContext();\n useEffect(() => {\n if (!selectionStorage) {\n setOptions({\n isNodeSelected: () => false,\n selectNodes: () => {},\n });\n return;\n }\n\n setOptions(createOptions(imodelKey, sourceName, selectionStorage, getNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (imodelKey !== args.imodelKey || args.level > 0) {\n return;\n }\n\n setOptions(createOptions(imodelKey, sourceName, selectionStorage, getNode));\n });\n }, [selectionStorage, getNode, imodelKey, sourceName]);\n\n return options;\n}\n\nfunction createOptions(\n key: string,\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\n const selectables = storage.getSelection({ imodelKey: key, level: 0 });\n\n const hierarchyNode = node.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return Selectables.hasAny(selectables, hierarchyNode.key.instanceKeys);\n }\n\n return Selectables.has(selectables, { identifier: node.id });\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n let selectables: Selectable[] = [];\n\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return;\n }\n selectables = [...selectables, ...createSelectables(node.id, node.nodeData)];\n }\n\n const actionProps = { imodelKey: key, source, selectables, level: 0 };\n\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\nfunction createSelectables(nodeId: string, node: HierarchyNode): Selectable[] {\n if (HierarchyNode.isInstancesNode(node)) {\n return node.key.instanceKeys;\n }\n\n return [\n {\n identifier: nodeId,\n async *loadInstanceKeys() {\n if (!HierarchyNode.isGroupingNode(node)) {\n return;\n }\n\n for (const key of node.groupedInstanceKeys) {\n yield key;\n }\n },\n data: node,\n },\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,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAc,WAAW,EAAoB,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,EAAE,wBAAwB,EAAoC,MAAM,aAAa,CAAC;AAkBzF,gBAAgB;AAChB,MAAM,UAAU,uBAAuB,CAAC,EACtC,SAAS,EACT,UAAU,EACV,OAAO,GACuG;IAC9G,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB,GAAG,EAAE,CAAC,CAAC;QAClE,cAAc,EAAE,0BAA0B,CAAC,GAAG,EAAE,CAAC,KAAK;QACtD,WAAW,EAAE,0BAA0B,CAAC,GAAG,EAAE,GAAE,CAAC;KACjD,CAAC,CAAC,CAAC;IAEJ,MAAM,gBAAgB,GAAG,0BAA0B,EAAE,CAAC;IACtD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,UAAU,CAAC;gBACT,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,CAAC,gBAAgB;gBACrB,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxC,OAAO;gBACT,CAAC;gBAED,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;oBAC3C,MAAM,GAAG,CAAC;gBACZ,CAAC;YACH,CAAC;YACD,IAAI,EAAE,IAAI;SACX;KACF,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 { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { Selectable, Selectables, SelectionStorage } from \"@itwin/unified-selection\";\nimport { useUnifiedSelectionContext } from \"../UnifiedSelectionContext\";\nimport { SelectionChangeType } from \"../UseSelectionHandler\";\nimport { isTreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @beta */\nexport interface UseUnifiedTreeSelectionProps {\n /** Key of the iModel. */\n imodelKey: string;\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/** @internal */\nexport function useUnifiedTreeSelection({\n imodelKey,\n sourceName,\n getNode,\n}: UseUnifiedTreeSelectionProps & { getNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined }): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* istanbul ignore next */ () => false,\n selectNodes: /* istanbul ignore next */ () => {},\n }));\n\n const selectionStorage = useUnifiedSelectionContext();\n useEffect(() => {\n if (!selectionStorage) {\n setOptions({\n isNodeSelected: () => false,\n selectNodes: () => {},\n });\n return;\n }\n\n setOptions(createOptions(imodelKey, sourceName, selectionStorage, getNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (imodelKey !== args.imodelKey || args.level > 0) {\n return;\n }\n\n setOptions(createOptions(imodelKey, sourceName, selectionStorage, getNode));\n });\n }, [selectionStorage, getNode, imodelKey, sourceName]);\n\n return options;\n}\n\nfunction createOptions(\n key: string,\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\n const selectables = storage.getSelection({ imodelKey: key, level: 0 });\n\n const hierarchyNode = node.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return Selectables.hasAny(selectables, hierarchyNode.key.instanceKeys);\n }\n\n return Selectables.has(selectables, { identifier: node.id });\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n let selectables: Selectable[] = [];\n\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return;\n }\n selectables = [...selectables, ...createSelectables(node.id, node.nodeData)];\n }\n\n const actionProps = { imodelKey: key, source, selectables, level: 0 };\n\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\nfunction createSelectables(nodeId: string, node: HierarchyNode): Selectable[] {\n if (HierarchyNode.isInstancesNode(node)) {\n return node.key.instanceKeys;\n }\n\n return [\n {\n identifier: nodeId,\n async *loadInstanceKeys() {\n if (!HierarchyNode.isGroupingNode(node)) {\n return;\n }\n\n for (const key of node.groupedInstanceKeys) {\n yield key;\n }\n },\n data: node,\n },\n ];\n}\n"]}
@@ -1,5 +1,8 @@
1
1
  import { PropsWithChildren } from "react";
2
- /** @internal */
2
+ /**
3
+ * Localized strings used in the components.
4
+ * @beta
5
+ */
3
6
  export interface LocalizedStrings {
4
7
  /**
5
8
  * Message displayed when nodes are loading.
@@ -51,11 +54,18 @@ export interface LocalizedStrings {
51
54
  export interface LocalizationContext {
52
55
  localizedStrings: LocalizedStrings;
53
56
  }
54
- /** @beta */
57
+ /**
58
+ * Properties for `LocalizationContextProvider`.
59
+ * @beta
60
+ */
55
61
  interface LocalizationContextProviderProps {
62
+ /** Localized strings used in the components. */
56
63
  localizedStrings?: Partial<LocalizedStrings>;
57
64
  }
58
- /** @beta */
65
+ /**
66
+ * Context provider for localized strings used in the components.
67
+ * @beta
68
+ */
59
69
  export declare function LocalizationContextProvider({ localizedStrings, children }: PropsWithChildren<LocalizationContextProviderProps>): import("react/jsx-runtime").JSX.Element;
60
70
  /** @internal */
61
71
  export declare function useLocalizationContext(): LocalizationContext;
@@ -1 +1 @@
1
- {"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F,gBAAgB;AAChB,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,gCAAgC,EAAE,MAAM,CAAC;IACzC;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAC5C;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAgBD,YAAY;AACZ,UAAU,gCAAgC;IACxC,gBAAgB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9C;AAED,YAAY;AACZ,wBAAgB,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC,gCAAgC,CAAC,2CAQ9H;AAED,gBAAgB;AAChB,wBAAgB,sBAAsB,wBAErC"}
1
+ {"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,gCAAgC,EAAE,MAAM,CAAC;IACzC;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAC5C;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAgBD;;;GAGG;AACH,UAAU,gCAAgC;IACxC,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9C;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC,gCAAgC,CAAC,2CAQ9H;AAED,gBAAgB;AAChB,wBAAgB,sBAAsB,wBAErC"}
@@ -16,7 +16,10 @@ const defaultLocalizedStrings = {
16
16
  retry: "Retry",
17
17
  };
18
18
  const localizationContext = createContext({ localizedStrings: defaultLocalizedStrings });
19
- /** @beta */
19
+ /**
20
+ * Context provider for localized strings used in the components.
21
+ * @beta
22
+ */
20
23
  export function LocalizationContextProvider({ localizedStrings, children }) {
21
24
  const [state, setState] = useState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });
22
25
  useEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAwD1F,MAAM,uBAAuB,GAAqB;IAChD,OAAO,EAAE,YAAY;IACrB,oBAAoB,EAAE,cAAc;IACpC,yBAAyB,EAAE,qBAAqB;IAChD,kBAAkB,EAAE,qCAAqC;IACzD,mBAAmB,EAAE,uDAAuD;IAC5E,gCAAgC,EAAE,0GAA0G;IAC5I,sBAAsB,EAAE,oEAAoE;IAC5F,mCAAmC,EAAE,wEAAwE;IAC7G,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAO9G,YAAY;AACZ,MAAM,UAAU,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAuD;IAC7H,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAE9G,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IACtF,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,sBAAsB;IACpC,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,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 { createContext, PropsWithChildren, useContext, useEffect, useState } from \"react\";\n\n/** @internal */\nexport interface LocalizedStrings {\n /**\n * Message displayed when nodes are loading.\n * Default value: `Loading...`.\n */\n loading: string;\n /**\n * Title for apply hierarchy filter button.\n * Default value: `Apply filter`.\n */\n filterHierarchyLevel: string;\n /**\n * Title for clear hierarchy filter button.\n * Default value: `Clear active filter`.\n */\n clearHierarchyLevelFilter: string;\n /**\n * Message displayed when no nodes matching filter are found.\n * Default value: `No child nodes match current filter`.\n */\n noFilteredChildren: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `There are more items than allowed limit of {{limit}}.`.\n */\n resultLimitExceeded: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit and hierarchy filtering is enabled.\n * Default value: `Please provide <link>additional filtering</link> - there are more items than allowed limit of {{limit}}.`.\n */\n resultLimitExceededWithFiltering: string;\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `<link>Increase the hierarchy level size limit to {{limit}}.</link>`.\n */\n increaseHierarchyLimit: string;\n /**\n * Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.\n * Default value: `Or, <link>increase the hierarchy level size limit to {{limit}}.</link>`.\n */\n increaseHierarchyLimitWithFiltering: string;\n /**\n * Label for retry action.\n * Default value: `Retry`.\n */\n retry: string;\n}\n\n/** @internal */\nexport interface LocalizationContext {\n localizedStrings: LocalizedStrings;\n}\n\nconst defaultLocalizedStrings: LocalizedStrings = {\n loading: \"Loading...\",\n filterHierarchyLevel: \"Apply filter\",\n clearHierarchyLevelFilter: \"Clear active filter\",\n noFilteredChildren: \"No child nodes match current filter\",\n resultLimitExceeded: \"There are more items than allowed limit of {{limit}}.\",\n resultLimitExceededWithFiltering: \"Please provide <link>additional filtering</link> - there are more items than allowed limit of {{limit}}.\",\n increaseHierarchyLimit: \"<link>Increase the hierarchy level size limit to {{limit}}.</link>\",\n increaseHierarchyLimitWithFiltering: \"Or, <link>increase the hierarchy level size limit to {{limit}}.</link>\",\n retry: \"Retry\",\n};\n\nconst localizationContext = createContext<LocalizationContext>({ localizedStrings: defaultLocalizedStrings });\n\n/** @beta */\ninterface LocalizationContextProviderProps {\n localizedStrings?: Partial<LocalizedStrings>;\n}\n\n/** @beta */\nexport function LocalizationContextProvider({ localizedStrings, children }: PropsWithChildren<LocalizationContextProviderProps>) {\n const [state, setState] = useState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n\n useEffect(() => {\n setState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n }, [localizedStrings]);\n\n return <localizationContext.Provider value={state}>{children}</localizationContext.Provider>;\n}\n\n/** @internal */\nexport function useLocalizationContext() {\n return useContext(localizationContext);\n}\n"]}
1
+ {"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA2D1F,MAAM,uBAAuB,GAAqB;IAChD,OAAO,EAAE,YAAY;IACrB,oBAAoB,EAAE,cAAc;IACpC,yBAAyB,EAAE,qBAAqB;IAChD,kBAAkB,EAAE,qCAAqC;IACzD,mBAAmB,EAAE,uDAAuD;IAC5E,gCAAgC,EAAE,0GAA0G;IAC5I,sBAAsB,EAAE,oEAAoE;IAC5F,mCAAmC,EAAE,wEAAwE;IAC7G,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAW9G;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAuD;IAC7H,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAE9G,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IACtF,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,sBAAsB;IACpC,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,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 { createContext, PropsWithChildren, useContext, useEffect, useState } from \"react\";\n\n/**\n * Localized strings used in the components.\n * @beta\n */\nexport interface LocalizedStrings {\n /**\n * Message displayed when nodes are loading.\n * Default value: `Loading...`.\n */\n loading: string;\n /**\n * Title for apply hierarchy filter button.\n * Default value: `Apply filter`.\n */\n filterHierarchyLevel: string;\n /**\n * Title for clear hierarchy filter button.\n * Default value: `Clear active filter`.\n */\n clearHierarchyLevelFilter: string;\n /**\n * Message displayed when no nodes matching filter are found.\n * Default value: `No child nodes match current filter`.\n */\n noFilteredChildren: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `There are more items than allowed limit of {{limit}}.`.\n */\n resultLimitExceeded: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit and hierarchy filtering is enabled.\n * Default value: `Please provide <link>additional filtering</link> - there are more items than allowed limit of {{limit}}.`.\n */\n resultLimitExceededWithFiltering: string;\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `<link>Increase the hierarchy level size limit to {{limit}}.</link>`.\n */\n increaseHierarchyLimit: string;\n /**\n * Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.\n * Default value: `Or, <link>increase the hierarchy level size limit to {{limit}}.</link>`.\n */\n increaseHierarchyLimitWithFiltering: string;\n /**\n * Label for retry action.\n * Default value: `Retry`.\n */\n retry: string;\n}\n\n/** @internal */\nexport interface LocalizationContext {\n localizedStrings: LocalizedStrings;\n}\n\nconst defaultLocalizedStrings: LocalizedStrings = {\n loading: \"Loading...\",\n filterHierarchyLevel: \"Apply filter\",\n clearHierarchyLevelFilter: \"Clear active filter\",\n noFilteredChildren: \"No child nodes match current filter\",\n resultLimitExceeded: \"There are more items than allowed limit of {{limit}}.\",\n resultLimitExceededWithFiltering: \"Please provide <link>additional filtering</link> - there are more items than allowed limit of {{limit}}.\",\n increaseHierarchyLimit: \"<link>Increase the hierarchy level size limit to {{limit}}.</link>\",\n increaseHierarchyLimitWithFiltering: \"Or, <link>increase the hierarchy level size limit to {{limit}}.</link>\",\n retry: \"Retry\",\n};\n\nconst localizationContext = createContext<LocalizationContext>({ localizedStrings: defaultLocalizedStrings });\n\n/**\n * Properties for `LocalizationContextProvider`.\n * @beta\n */\ninterface LocalizationContextProviderProps {\n /** Localized strings used in the components. */\n localizedStrings?: Partial<LocalizedStrings>;\n}\n\n/**\n * Context provider for localized strings used in the components.\n * @beta\n */\nexport function LocalizationContextProvider({ localizedStrings, children }: PropsWithChildren<LocalizationContextProviderProps>) {\n const [state, setState] = useState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n\n useEffect(() => {\n setState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n }, [localizedStrings]);\n\n return <localizationContext.Provider value={state}>{children}</localizationContext.Provider>;\n}\n\n/** @internal */\nexport function useLocalizationContext() {\n return useContext(localizationContext);\n}\n"]}
@@ -8,17 +8,26 @@ import { RenderedTreeNode } from "./TreeRenderer";
8
8
  type TreeNodeProps = ComponentPropsWithoutRef<typeof TreeNode>;
9
9
  /** @beta */
10
10
  interface TreeNodeRendererOwnProps {
11
+ /** Node that is rendered. */
11
12
  node: RenderedTreeNode;
13
+ /** Action to perform when the filter button is clicked for this node. */
12
14
  onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
15
+ /** Returns an icon for a given node. */
13
16
  getIcon?: (node: PresentationHierarchyNode) => ReactElement | undefined;
17
+ /** Returns a label for a given node. */
14
18
  getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;
19
+ /** Returns sublabel for a given node. */
15
20
  getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;
21
+ /** Action to perform when the node is clicked. */
16
22
  onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
23
+ /** Action to perform when a key is pressed when the node is hovered on. */
17
24
  onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;
25
+ /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */
18
26
  reloadTree?: (options: {
19
27
  parentNodeId: string | undefined;
20
28
  state: "reset";
21
29
  }) => void;
30
+ /** CSS class name for the action buttons. */
22
31
  actionButtonsClassName?: string;
23
32
  }
24
33
  /** @beta */
@@ -1 +1 @@
1
- {"version":3,"file":"TreeNodeRenderer.d.ts","s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AAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACrF,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,YAAY;AACZ,KAAK,qBAAqB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,YAAY,CAAC,GACzE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,GACrE,IAAI,CAAC,aAAa,EAAE,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,MAAM,CAAC,GACnE,wBAAwB,CAAC;AAE3B;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,aAAa,EACjB,EAAE,qBAAqB,2CAqGvB"}
1
+ {"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAU,MAAM,OAAO,CAAC;AAEvE,OAAO,EAA+D,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE7G,OAAO,EAA+B,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,YAAY;AACZ,KAAK,aAAa,GAAG,wBAAwB,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE/D,YAAY;AACZ,UAAU,wBAAwB;IAChC,6BAA6B;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,yEAAyE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,CAAC,EAC/B,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,aAAa,EACjB,EAAE,qBAAqB,2CAmGvB"}
@@ -21,28 +21,27 @@ import { useLocalizationContext } from "./LocalizationContext";
21
21
  export function TreeNodeRenderer({ node, expandNode, getIcon, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isSelected, isDisabled, actionButtonsClassName, getHierarchyLevelDetails, reloadTree, ...treeNodeProps }) {
22
22
  const { localizedStrings } = useLocalizationContext();
23
23
  const applyFilterButtonRef = useRef(null);
24
+ const nodeRef = useRef(null);
24
25
  if ("type" in node && node.type === "ChildrenPlaceholder") {
25
26
  return _jsx(PlaceholderNode, { ...treeNodeProps });
26
27
  }
27
28
  if (isPresentationHierarchyNode(node)) {
28
- return (
29
- // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
30
- _jsx("div", { onClick: (event) => !isDisabled && onNodeClick?.(node, !isSelected, event), onKeyDown: (event) => {
29
+ return (_jsx(TreeNode, { ...treeNodeProps, ref: nodeRef, isSelected: isSelected, isDisabled: isDisabled, className: cx(treeNodeProps.className, "stateless-tree-node", { filtered: node.isFiltered }), onClick: (event) => !isDisabled && onNodeClick?.(node, !isSelected, event), onKeyDown: (event) => {
31
30
  // Ignore if it is called on the element inside, e.g. checkbox or expander
32
- if (!isDisabled && event.target instanceof HTMLElement && event.target.classList.contains("stateless-tree-node")) {
31
+ if (!isDisabled && event.target === nodeRef.current) {
33
32
  onNodeKeyDown?.(node, !isSelected, event);
34
33
  }
35
- }, children: _jsx(TreeNode, { ...treeNodeProps, isSelected: isSelected, isDisabled: isDisabled, className: cx(treeNodeProps.className, "stateless-tree-node", { filtered: node.isFiltered }), onExpanded: (_, isExpanded) => {
36
- expandNode(node.id, isExpanded);
37
- }, icon: getIcon ? getIcon(node) : undefined, label: getLabel ? getLabel(node) : node.label, sublabel: getSublabel ? getSublabel(node) : undefined, children: _jsxs(ButtonGroup, { className: cx("action-buttons", actionButtonsClassName), children: [getHierarchyLevelDetails && node.isFiltered ? (_jsx(IconButton, { className: "filtering-action-button", styleType: "borderless", size: "small", title: localizedStrings.clearHierarchyLevelFilter, onClick: (e) => {
38
- e.stopPropagation();
39
- getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);
40
- applyFilterButtonRef.current?.focus();
41
- }, children: _jsx(SvgRemove, {}) })) : null, onFilterClick && node.isFilterable ? (_jsx(IconButton, { ref: applyFilterButtonRef, className: "filtering-action-button", styleType: "borderless", size: "small", title: localizedStrings.filterHierarchyLevel, onClick: (e) => {
42
- e.stopPropagation();
43
- const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
44
- hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);
45
- }, children: node.isFiltered ? _jsx(SvgFilter, {}) : _jsx(SvgFilterHollow, {}) })) : null] }) }) }));
34
+ }, onExpanded: (_, isExpanded) => {
35
+ expandNode(node.id, isExpanded);
36
+ }, icon: getIcon ? getIcon(node) : undefined, label: getLabel ? getLabel(node) : node.label, sublabel: getSublabel ? getSublabel(node) : undefined, children: _jsxs(ButtonGroup, { className: cx("action-buttons", actionButtonsClassName), children: [getHierarchyLevelDetails && node.isFiltered ? (_jsx(IconButton, { className: "filtering-action-button", styleType: "borderless", size: "small", title: localizedStrings.clearHierarchyLevelFilter, onClick: (e) => {
37
+ e.stopPropagation();
38
+ getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);
39
+ applyFilterButtonRef.current?.focus();
40
+ }, children: _jsx(SvgRemove, {}) })) : null, onFilterClick && node.isFilterable ? (_jsx(IconButton, { ref: applyFilterButtonRef, className: "filtering-action-button", styleType: "borderless", size: "small", title: localizedStrings.filterHierarchyLevel, onClick: (e) => {
41
+ e.stopPropagation();
42
+ const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
43
+ hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);
44
+ }, children: node.isFiltered ? _jsx(SvgFilter, {}) : _jsx(SvgFilterHollow, {}) })) : null] }) }));
46
45
  }
47
46
  if (node.type === "ResultSetTooLarge") {
48
47
  return (_jsx(ResultSetTooLargeNode, { ...treeNodeProps, limit: node.resultSetSizeLimit, onOverrideLimit: getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined, onFilterClick: onFilterClick
@@ -1 +1 @@
1
- {"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAA0C,MAAM,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAA6B,MAAM,aAAa,CAAC;AAErF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAyB/D;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,aAAa,EACM;IACtB,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;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,mBAAmB,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE1C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO;YACL,KAAK,EAAE,gBAAgB;YACvB,OAAO,EAAE,CACP,KAAC,IAAI,IAAC,aAAa,EAAC,KAAK,EAAC,GAAG,EAAC,KAAK,YACjC,KAAC,IAAI,cAAE,gBAAgB,GAAQ,GAC1B,CACR;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IACpC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEjE,OAAO;QACL,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC;QACpD,OAAO,EAAE,CACP,MAAC,IAAI,IAAC,aAAa,EAAC,KAAK,EAAC,GAAG,EAAC,KAAK,aAChC,UAAU,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,UAAU,GAAQ,CAAC,CAAC,CAAC,IAAI,EAC9C,KAAC,MAAM,IACL,SAAS,QACT,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;wBACb,CAAC,CAAC,eAAe,EAAE,CAAC;wBACpB,OAAO,EAAE,EAAE,CAAC;oBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,SAAS,GAAQ,CAAC,CAAC,CAAC,IAAI,IACvC,CACR;KACF,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 \"./TreeNodeRenderer.css\";\nimport cx from \"classnames\";\nimport { ComponentPropsWithoutRef, ReactElement, useRef } from \"react\";\nimport { SvgFilter, SvgFilterHollow, SvgRemove } from \"@itwin/itwinui-icons-react\";\nimport { Anchor, ButtonGroup, Flex, IconButton, ProgressRadial, Text, TreeNode } from \"@itwin/itwinui-react\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree\";\nimport { useLocalizationContext } from \"./LocalizationContext\";\nimport { RenderedTreeNode } from \"./TreeRenderer\";\n\n/** @beta */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof TreeNode>;\n\n/** @beta */\ninterface TreeNodeRendererOwnProps {\n node: RenderedTreeNode;\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n getIcon?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n actionButtonsClassName?: string;\n}\n\n/** @beta */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"label\" | \"onExpanded\" | \"onSelected\" | \"icon\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @beta\n */\nexport function TreeNodeRenderer({\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isSelected,\n isDisabled,\n actionButtonsClassName,\n getHierarchyLevelDetails,\n reloadTree,\n ...treeNodeProps\n}: TreeNodeRendererProps) {\n const { localizedStrings } = useLocalizationContext();\n const applyFilterButtonRef = useRef<HTMLButtonElement>(null);\n\n if (\"type\" in node && node.type === \"ChildrenPlaceholder\") {\n return <PlaceholderNode {...treeNodeProps} />;\n }\n\n if (isPresentationHierarchyNode(node)) {\n return (\n // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions\n <div\n onClick={(event) => !isDisabled && onNodeClick?.(node, !isSelected, event)}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!isDisabled && event.target instanceof HTMLElement && event.target.classList.contains(\"stateless-tree-node\")) {\n onNodeKeyDown?.(node, !isSelected, event);\n }\n }}\n >\n <TreeNode\n {...treeNodeProps}\n isSelected={isSelected}\n isDisabled={isDisabled}\n className={cx(treeNodeProps.className, \"stateless-tree-node\", { filtered: node.isFiltered })}\n onExpanded={(_, isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n icon={getIcon ? getIcon(node) : undefined}\n label={getLabel ? getLabel(node) : node.label}\n sublabel={getSublabel ? getSublabel(node) : undefined}\n >\n <ButtonGroup className={cx(\"action-buttons\", actionButtonsClassName)}>\n {getHierarchyLevelDetails && node.isFiltered ? (\n <IconButton\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n title={localizedStrings.clearHierarchyLevelFilter}\n onClick={(e) => {\n e.stopPropagation();\n getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);\n applyFilterButtonRef.current?.focus();\n }}\n >\n <SvgRemove />\n </IconButton>\n ) : null}\n {onFilterClick && node.isFilterable ? (\n <IconButton\n ref={applyFilterButtonRef}\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n title={localizedStrings.filterHierarchyLevel}\n onClick={(e) => {\n e.stopPropagation();\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }}\n >\n {node.isFiltered ? <SvgFilter /> : <SvgFilterHollow />}\n </IconButton>\n ) : null}\n </ButtonGroup>\n </TreeNode>\n </div>\n );\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n return (\n <ResultSetTooLargeNode\n {...treeNodeProps}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick\n ? () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return <TreeNode {...treeNodeProps} label={localizedStrings.noFilteredChildren} isDisabled={true} onExpanded={/* istanbul ignore next */ () => {}} />;\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <TreeNode\n {...treeNodeProps}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n isDisabled={true}\n onExpanded={/* istanbul ignore next */ () => {}}\n />\n );\n}\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Flex flexDirection=\"row\" gap=\"xs\" title={message} alignItems=\"start\">\n <Text>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </Flex>\n );\n}\n\nfunction PlaceholderNode(props: Omit<TreeNodeProps, \"onExpanded\" | \"label\">) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <TreeNode\n {...props}\n label={localizedStrings.loading}\n icon={<ProgressRadial size=\"x-small\" indeterminate title={localizedStrings.loading} />}\n onExpanded={/* istanbul ignore next */ () => {}}\n ></TreeNode>\n );\n}\n\nfunction ResultSetTooLargeNode({\n onFilterClick,\n onOverrideLimit,\n limit,\n ...props\n}: Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps) {\n return (\n <TreeNode\n {...props}\n className=\"stateless-tree-node\"\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n onExpanded={/* istanbul ignore next */ () => {}}\n />\n );\n}\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <Flex flexDirection=\"column\" gap=\"3xs\" title={title} alignItems=\"start\">\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </Flex>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <Flex flexDirection=\"row\" gap=\"3xs\">\n <Text>{messageWithLimit}</Text>\n </Flex>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <Flex flexDirection=\"row\" gap=\"3xs\">\n {textBefore ? <Text>{textBefore}</Text> : null}\n <Anchor\n underline\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? <Text>{textAfter}</Text> : null}\n </Flex>\n ),\n };\n}\n"]}
1
+ {"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAA0C,MAAM,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAA6B,MAAM,aAAa,CAAC;AAErF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAkC/D;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,UAAU,EACV,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,aAAa,EACM;IACtB,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,MAAM,oBAAoB,GAAG,MAAM,CAA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K,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE1C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO;YACL,KAAK,EAAE,gBAAgB;YACvB,OAAO,EAAE,CACP,KAAC,IAAI,IAAC,aAAa,EAAC,KAAK,EAAC,GAAG,EAAC,KAAK,YACjC,KAAC,IAAI,cAAE,gBAAgB,GAAQ,GAC1B,CACR;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IACpC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEjE,OAAO;QACL,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC;QACpD,OAAO,EAAE,CACP,MAAC,IAAI,IAAC,aAAa,EAAC,KAAK,EAAC,GAAG,EAAC,KAAK,aAChC,UAAU,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,UAAU,GAAQ,CAAC,CAAC,CAAC,IAAI,EAC9C,KAAC,MAAM,IACL,SAAS,QACT,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;wBACb,CAAC,CAAC,eAAe,EAAE,CAAC;wBACpB,OAAO,EAAE,EAAE,CAAC;oBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,SAAS,GAAQ,CAAC,CAAC,CAAC,IAAI,IACvC,CACR;KACF,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 \"./TreeNodeRenderer.css\";\nimport cx from \"classnames\";\nimport { ComponentPropsWithoutRef, ReactElement, useRef } from \"react\";\nimport { SvgFilter, SvgFilterHollow, SvgRemove } from \"@itwin/itwinui-icons-react\";\nimport { Anchor, ButtonGroup, Flex, IconButton, ProgressRadial, Text, TreeNode } from \"@itwin/itwinui-react\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree\";\nimport { useLocalizationContext } from \"./LocalizationContext\";\nimport { RenderedTreeNode } from \"./TreeRenderer\";\n\n/** @beta */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof TreeNode>;\n\n/** @beta */\ninterface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: RenderedTreeNode;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Returns an icon for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** CSS class name for the action buttons. */\n actionButtonsClassName?: string;\n}\n\n/** @beta */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"label\" | \"onExpanded\" | \"onSelected\" | \"icon\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @beta\n */\nexport function TreeNodeRenderer({\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isSelected,\n isDisabled,\n actionButtonsClassName,\n getHierarchyLevelDetails,\n reloadTree,\n ...treeNodeProps\n}: TreeNodeRendererProps) {\n const { localizedStrings } = useLocalizationContext();\n const applyFilterButtonRef = useRef<HTMLButtonElement>(null);\n const nodeRef = useRef<HTMLLIElement>(null);\n\n if (\"type\" in node && node.type === \"ChildrenPlaceholder\") {\n return <PlaceholderNode {...treeNodeProps} />;\n }\n\n if (isPresentationHierarchyNode(node)) {\n return (\n <TreeNode\n {...treeNodeProps}\n ref={nodeRef}\n isSelected={isSelected}\n isDisabled={isDisabled}\n className={cx(treeNodeProps.className, \"stateless-tree-node\", { filtered: node.isFiltered })}\n onClick={(event) => !isDisabled && onNodeClick?.(node, !isSelected, event)}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!isDisabled && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !isSelected, event);\n }\n }}\n onExpanded={(_, isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n icon={getIcon ? getIcon(node) : undefined}\n label={getLabel ? getLabel(node) : node.label}\n sublabel={getSublabel ? getSublabel(node) : undefined}\n >\n <ButtonGroup className={cx(\"action-buttons\", actionButtonsClassName)}>\n {getHierarchyLevelDetails && node.isFiltered ? (\n <IconButton\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n title={localizedStrings.clearHierarchyLevelFilter}\n onClick={(e) => {\n e.stopPropagation();\n getHierarchyLevelDetails(node.id)?.setInstanceFilter(undefined);\n applyFilterButtonRef.current?.focus();\n }}\n >\n <SvgRemove />\n </IconButton>\n ) : null}\n {onFilterClick && node.isFilterable ? (\n <IconButton\n ref={applyFilterButtonRef}\n className=\"filtering-action-button\"\n styleType=\"borderless\"\n size=\"small\"\n title={localizedStrings.filterHierarchyLevel}\n onClick={(e) => {\n e.stopPropagation();\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }}\n >\n {node.isFiltered ? <SvgFilter /> : <SvgFilterHollow />}\n </IconButton>\n ) : null}\n </ButtonGroup>\n </TreeNode>\n );\n }\n\n if (node.type === \"ResultSetTooLarge\") {\n return (\n <ResultSetTooLargeNode\n {...treeNodeProps}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick\n ? () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return <TreeNode {...treeNodeProps} label={localizedStrings.noFilteredChildren} isDisabled={true} onExpanded={/* istanbul ignore next */ () => {}} />;\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <TreeNode\n {...treeNodeProps}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n isDisabled={true}\n onExpanded={/* istanbul ignore next */ () => {}}\n />\n );\n}\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Flex flexDirection=\"row\" gap=\"xs\" title={message} alignItems=\"start\">\n <Text>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </Flex>\n );\n}\n\nfunction PlaceholderNode(props: Omit<TreeNodeProps, \"onExpanded\" | \"label\">) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <TreeNode\n {...props}\n label={localizedStrings.loading}\n icon={<ProgressRadial size=\"x-small\" indeterminate title={localizedStrings.loading} />}\n onExpanded={/* istanbul ignore next */ () => {}}\n ></TreeNode>\n );\n}\n\nfunction ResultSetTooLargeNode({\n onFilterClick,\n onOverrideLimit,\n limit,\n ...props\n}: Omit<TreeNodeProps, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps) {\n return (\n <TreeNode\n {...props}\n className=\"stateless-tree-node\"\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n onExpanded={/* istanbul ignore next */ () => {}}\n />\n );\n}\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <Flex flexDirection=\"column\" gap=\"3xs\" title={title} alignItems=\"start\">\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </Flex>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <Flex flexDirection=\"row\" gap=\"3xs\">\n <Text>{messageWithLimit}</Text>\n </Flex>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <Flex flexDirection=\"row\" gap=\"3xs\">\n {textBefore ? <Text>{textBefore}</Text> : null}\n <Anchor\n underline\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? <Text>{textAfter}</Text> : null}\n </Flex>\n ),\n };\n}\n"]}
@@ -3,7 +3,7 @@ import { NodeData, Tree } from "@itwin/itwinui-react";
3
3
  import { PresentationTreeNode } from "../TreeNode";
4
4
  import { SelectionMode } from "../UseSelectionHandler";
5
5
  import { useTree } from "../UseTree";
6
- import { LocalizedStrings } from "./LocalizationContext";
6
+ import { LocalizationContextProvider } from "./LocalizationContext";
7
7
  import { TreeNodeRenderer } from "./TreeNodeRenderer";
8
8
  /** @beta */
9
9
  type TreeProps = ComponentPropsWithoutRef<typeof Tree<RenderedTreeNode>>;
@@ -11,12 +11,13 @@ type TreeProps = ComponentPropsWithoutRef<typeof Tree<RenderedTreeNode>>;
11
11
  type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof TreeNodeRenderer>;
12
12
  /** @beta */
13
13
  interface TreeRendererOwnProps {
14
+ /** Root nodes of the tree. */
14
15
  rootNodes: PresentationTreeNode[];
16
+ /** Active selection mode used by the tree. Defaults to `"single"`. */
15
17
  selectionMode?: SelectionMode;
16
- localizedStrings?: Partial<LocalizedStrings>;
17
18
  }
18
19
  /** @beta */
19
- type TreeRendererProps = Pick<ReturnType<typeof useTree>, "rootNodes" | "expandNode"> & Partial<Pick<ReturnType<typeof useTree>, "selectNodes" | "isNodeSelected" | "getHierarchyLevelDetails" | "reloadTree">> & Pick<TreeNodeRendererProps, "onFilterClick" | "getIcon" | "getLabel" | "getSublabel"> & TreeRendererOwnProps & Omit<TreeProps, "data" | "nodeRenderer" | "getNode" | "enableVirtualization">;
20
+ type TreeRendererProps = Pick<ReturnType<typeof useTree>, "rootNodes" | "expandNode"> & Partial<Pick<ReturnType<typeof useTree>, "selectNodes" | "isNodeSelected" | "getHierarchyLevelDetails" | "reloadTree">> & Pick<TreeNodeRendererProps, "onFilterClick" | "getIcon" | "getLabel" | "getSublabel"> & TreeRendererOwnProps & Omit<TreeProps, "data" | "nodeRenderer" | "getNode" | "enableVirtualization"> & ComponentPropsWithoutRef<typeof LocalizationContextProvider>;
20
21
  /**
21
22
  * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes
22
23
  * are rendered using `TreeNodeRenderer` component from this package.
@@ -1 +1 @@
1
- {"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAe,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,aAAa,EAAuB,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAA+B,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,YAAY;AACZ,KAAK,SAAS,GAAG,wBAAwB,CAAC,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAEzE,YAAY;AACZ,KAAK,qBAAqB,GAAG,wBAAwB,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE/E,YAAY;AACZ,UAAU,oBAAoB;IAC5B,SAAS,EAAE,oBAAoB,EAAE,CAAC;IAClC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,gBAAgB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9C;AAED,YAAY;AACZ,KAAK,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC,GACnF,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,aAAa,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,YAAY,CAAC,CAAC,GACvH,IAAI,CAAC,qBAAqB,EAAE,eAAe,GAAG,SAAS,GAAG,UAAU,GAAG,aAAa,CAAC,GACrF,oBAAoB,GACpB,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,GAAG,sBAAsB,CAAC,CAAC;AAEhF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,aAAa,EACb,OAAO,EACP,QAAQ,EACR,WAAW,EACX,wBAAwB,EACxB,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,GAAG,SAAS,EACb,EAAE,iBAAiB,2CAiCnB;AAOD;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GACxB,oBAAoB,GACpB;IACE,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,qBAAqB,CAAC;CAC7B,CAAC;AAEN;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CA6B1I"}
1
+ {"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,w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AAa,EACb,OAAO,EACP,QAAQ,EACR,WAAW,EACX,wBAAwB,EACxB,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,GAAG,SAAS,EACb,EAAE,iBAAiB,2CAiCnB;AAOD;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GACxB,oBAAoB,GACpB;IACE,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,qBAAqB,CAAC;CAC7B,CAAC;AAEN;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,gBAAgB,EAAE,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CA6B1I"}
@@ -1 +1 @@
1
- {"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAA4B,WAAW,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAY,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,2BAA2B,EAAoB,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAsBtD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,aAAa,EACb,OAAO,EACP,QAAQ,EACR,WAAW,EACX,wBAAwB,EACxB,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,GAAG,SAAS,EACM;IAClB,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,mBAAmB,CAAC;QACzD,SAAS;QACT,WAAW,EAAE,WAAW,IAAI,eAAe;QAC3C,aAAa,EAAE,aAAa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UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,IAAI;SACjB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,EAAE;QACf,IAAI;QACJ,WAAW,EAAE,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QAC/D,QAAQ;QACN,uEAAuE;QACvE,IAAI,CAAC,QAAQ,KAAK,IAAI;YACpB,CAAC,CAAC;gBACE;oBACE,EAAE,EAAE,WAAW,IAAI,CAAC,EAAE,EAAE;oBACxB,YAAY,EAAE,IAAI,CAAC,EAAE;oBACrB,IAAI,EAAE,qBAAqB;iBAC5B;aACF;YACH,CAAC,CAAC,IAAI,CAAC,QAAQ;QACnB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,UAAU,EAAE,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;KACpC,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 { ComponentPropsWithoutRef, useCallback } from \"react\";\nimport { NodeData, Tree } from \"@itwin/itwinui-react\";\nimport { PresentationTreeNode } from \"../TreeNode\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler\";\nimport { useTree } from \"../UseTree\";\nimport { LocalizationContextProvider, LocalizedStrings } from \"./LocalizationContext\";\nimport { TreeNodeRenderer } from \"./TreeNodeRenderer\";\n\n/** @beta */\ntype TreeProps = ComponentPropsWithoutRef<typeof Tree<RenderedTreeNode>>;\n\n/** @beta */\ntype TreeNodeRendererProps = ComponentPropsWithoutRef<typeof TreeNodeRenderer>;\n\n/** @beta */\ninterface TreeRendererOwnProps {\n rootNodes: PresentationTreeNode[];\n selectionMode?: SelectionMode;\n localizedStrings?: Partial<LocalizedStrings>;\n}\n\n/** @beta */\ntype TreeRendererProps = Pick<ReturnType<typeof useTree>, \"rootNodes\" | \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"selectNodes\" | \"isNodeSelected\" | \"getHierarchyLevelDetails\" | \"reloadTree\">> &\n Pick<TreeNodeRendererProps, \"onFilterClick\" | \"getIcon\" | \"getLabel\" | \"getSublabel\"> &\n TreeRendererOwnProps &\n Omit<TreeProps, \"data\" | \"nodeRenderer\" | \"getNode\" | \"enableVirtualization\">;\n\n/**\n * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes\n * are rendered using `TreeNodeRenderer` component from this package.\n *\n * @see https://itwinui.bentley.com/docs/tree\n * @beta\n */\nexport function TreeRenderer({\n rootNodes,\n expandNode,\n selectNodes,\n isNodeSelected,\n onFilterClick,\n getIcon,\n getLabel,\n getSublabel,\n getHierarchyLevelDetails,\n reloadTree,\n selectionMode,\n localizedStrings,\n ...treeProps\n}: TreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const nodeRenderer = useCallback<TreeProps[\"nodeRenderer\"]>(\n (nodeProps) => {\n return (\n <TreeNodeRenderer\n {...nodeProps}\n expandNode={expandNode}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n onFilterClick={onFilterClick}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n getIcon={getIcon}\n getLabel={getLabel}\n getSublabel={getSublabel}\n reloadTree={reloadTree}\n />\n );\n },\n [expandNode, getHierarchyLevelDetails, onFilterClick, onNodeClick, onNodeKeyDown, getIcon, getLabel, getSublabel, reloadTree],\n );\n\n const getNode = useCallback<TreeProps[\"getNode\"]>((node) => createRenderedTreeNodeData(node, isNodeSelected ?? noopIsNodeSelected), [isNodeSelected]);\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n <Tree<RenderedTreeNode> {...treeProps} data={rootNodes} nodeRenderer={nodeRenderer} getNode={getNode} enableVirtualization={true} />\n </LocalizationContextProvider>\n );\n}\n\nfunction noopSelectNodes() {}\nfunction noopIsNodeSelected() {\n return false;\n}\n\n/**\n * A data structure for a tree node that is rendered using the `TreeRenderer` component.\n *\n * In addition to the `PresentationTreeNode` union, this type may have one additional variation - an informational\n * type of node with `ChildrenPlaceholder` type. This type of node is returned as the single child node of a parent\n * while its children are being loaded. This allows the node renderer to show a placeholder under the parent during\n * the process.\n *\n * @beta\n */\nexport type RenderedTreeNode =\n | PresentationTreeNode\n | {\n id: string;\n parentNodeId: string | undefined;\n type: \"ChildrenPlaceholder\";\n };\n\n/**\n * An utility function that creates an `@itwin/itwinui-react` `NodeData` object for the `Tree` component from a\n * `RenderedTreeNode` object.\n *\n * Usage example:\n * ```tsx\n * function MyComponent({ rootNodes, nodeRenderer }: MyComponentProps) {\n * const getNode = useCallback<TreeProps[\"getNode\"]>((node) => createRenderedTreeNodeData(node, () => false), []);\n * return <Tree<RenderedTreeNode> data={rootNodes} getNode={getNode} nodeRenderer={nodeRenderer} />;\n * }\n * ```\n *\n * @beta\n */\nexport function createRenderedTreeNodeData(node: RenderedTreeNode, isNodeSelected: (nodeId: string) => boolean): NodeData<RenderedTreeNode> {\n if (\"type\" in node) {\n return {\n nodeId: node.id,\n node,\n hasSubNodes: false,\n isExpanded: false,\n isSelected: false,\n isDisabled: true,\n };\n }\n return {\n nodeId: node.id,\n node,\n hasSubNodes: node.children === true || node.children.length > 0,\n subNodes:\n // returns placeholder node to show as child while children is loading.\n node.children === true\n ? [\n {\n id: `Loading-${node.id}`,\n parentNodeId: node.id,\n type: \"ChildrenPlaceholder\",\n },\n ]\n : node.children,\n isExpanded: node.isExpanded,\n isSelected: isNodeSelected(node.id),\n };\n}\n"]}
1
+ {"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAA4B,W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,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAEtJ,OAAO,CACL,KAAC,2BAA2B,IAAC,gBAAgB,EAAE,gBAAgB,YAC7D,KAAC,IAAI,OAAuB,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,IAAI,GAAI,GACxG,CAC/B,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,KAAI,CAAC;AAC7B,SAAS,kBAAkB;IACzB,OAAO,KAAK,CAAC;AACf,CAAC;AAoBD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAsB,EAAE,cAA2C;IAC5G,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACnB,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,IAAI;YACJ,WAAW,EAAE,KAAK;YAClB,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,IAAI;SACjB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,EAAE;QACf,IAAI;QACJ,WAAW,EAAE,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QAC/D,QAAQ;QACN,uEAAuE;QACvE,IAAI,CAAC,QAAQ,KAAK,IAAI;YACpB,CAAC,CAAC;gBACE;oBACE,EAAE,EAAE,WAAW,IAAI,CAAC,EAAE,EAAE;oBACxB,YAAY,EAAE,IAAI,CAAC,EAAE;oBACrB,IAAI,EAAE,qBAAqB;iBAC5B;aACF;YACH,CAAC,CAAC,IAAI,CAAC,QAAQ;QACnB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,UAAU,EAAE,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;KACpC,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 { ComponentPropsWithoutRef, useCallback } from \"react\";\nimport { NodeData, Tree } from \"@itwin/itwinui-react\";\nimport { PresentationTreeNode } from \"../TreeNode\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler\";\nimport { useTree } from \"../UseTree\";\nimport { LocalizationContextProvider } from \"./LocalizationContext\";\nimport { TreeNodeRenderer } from \"./TreeNodeRenderer\";\n\n/** @beta */\ntype TreeProps = ComponentPropsWithoutRef<typeof Tree<RenderedTreeNode>>;\n\n/** @beta */\ntype TreeNodeRendererProps = ComponentPropsWithoutRef<typeof TreeNodeRenderer>;\n\n/** @beta */\ninterface TreeRendererOwnProps {\n /** Root nodes of the tree. */\n rootNodes: PresentationTreeNode[];\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n}\n\n/** @beta */\ntype TreeRendererProps = Pick<ReturnType<typeof useTree>, \"rootNodes\" | \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"selectNodes\" | \"isNodeSelected\" | \"getHierarchyLevelDetails\" | \"reloadTree\">> &\n Pick<TreeNodeRendererProps, \"onFilterClick\" | \"getIcon\" | \"getLabel\" | \"getSublabel\"> &\n TreeRendererOwnProps &\n Omit<TreeProps, \"data\" | \"nodeRenderer\" | \"getNode\" | \"enableVirtualization\"> &\n ComponentPropsWithoutRef<typeof LocalizationContextProvider>;\n\n/**\n * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes\n * are rendered using `TreeNodeRenderer` component from this package.\n *\n * @see https://itwinui.bentley.com/docs/tree\n * @beta\n */\nexport function TreeRenderer({\n rootNodes,\n expandNode,\n selectNodes,\n isNodeSelected,\n onFilterClick,\n getIcon,\n getLabel,\n getSublabel,\n getHierarchyLevelDetails,\n reloadTree,\n selectionMode,\n localizedStrings,\n ...treeProps\n}: TreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const nodeRenderer = useCallback<TreeProps[\"nodeRenderer\"]>(\n (nodeProps) => {\n return (\n <TreeNodeRenderer\n {...nodeProps}\n expandNode={expandNode}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n onFilterClick={onFilterClick}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n getIcon={getIcon}\n getLabel={getLabel}\n getSublabel={getSublabel}\n reloadTree={reloadTree}\n />\n );\n },\n [expandNode, getHierarchyLevelDetails, onFilterClick, onNodeClick, onNodeKeyDown, getIcon, getLabel, getSublabel, reloadTree],\n );\n\n const getNode = useCallback<TreeProps[\"getNode\"]>((node) => createRenderedTreeNodeData(node, isNodeSelected ?? noopIsNodeSelected), [isNodeSelected]);\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n <Tree<RenderedTreeNode> {...treeProps} data={rootNodes} nodeRenderer={nodeRenderer} getNode={getNode} enableVirtualization={true} />\n </LocalizationContextProvider>\n );\n}\n\nfunction noopSelectNodes() {}\nfunction noopIsNodeSelected() {\n return false;\n}\n\n/**\n * A data structure for a tree node that is rendered using the `TreeRenderer` component.\n *\n * In addition to the `PresentationTreeNode` union, this type may have one additional variation - an informational\n * type of node with `ChildrenPlaceholder` type. This type of node is returned as the single child node of a parent\n * while its children are being loaded. This allows the node renderer to show a placeholder under the parent during\n * the process.\n *\n * @beta\n */\nexport type RenderedTreeNode =\n | PresentationTreeNode\n | {\n id: string;\n parentNodeId: string | undefined;\n type: \"ChildrenPlaceholder\";\n };\n\n/**\n * An utility function that creates an `@itwin/itwinui-react` `NodeData` object for the `Tree` component from a\n * `RenderedTreeNode` object.\n *\n * Usage example:\n * ```tsx\n * function MyComponent({ rootNodes, nodeRenderer }: MyComponentProps) {\n * const getNode = useCallback<TreeProps[\"getNode\"]>((node) => createRenderedTreeNodeData(node, () => false), []);\n * return <Tree<RenderedTreeNode> data={rootNodes} getNode={getNode} nodeRenderer={nodeRenderer} />;\n * }\n * ```\n *\n * @beta\n */\nexport function createRenderedTreeNodeData(node: RenderedTreeNode, isNodeSelected: (nodeId: string) => boolean): NodeData<RenderedTreeNode> {\n if (\"type\" in node) {\n return {\n nodeId: node.id,\n node,\n hasSubNodes: false,\n isExpanded: false,\n isSelected: false,\n isDisabled: true,\n };\n }\n return {\n nodeId: node.id,\n node,\n hasSubNodes: node.children === true || node.children.length > 0,\n subNodes:\n // returns placeholder node to show as child while children is loading.\n node.children === true\n ? [\n {\n id: `Loading-${node.id}`,\n parentNodeId: node.id,\n type: \"ChildrenPlaceholder\",\n },\n ]\n : node.children,\n isExpanded: node.isExpanded,\n isSelected: isNodeSelected(node.id),\n };\n}\n"]}