@itwin/presentation-hierarchies-react 2.0.0-alpha.54 → 2.0.0-alpha.56

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 (128) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +23 -61
  3. package/lib/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
  4. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/TreeNode.d.ts +2 -0
  5. package/lib/presentation-hierarchies-react/TreeNode.d.ts.map +1 -0
  6. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseIModelTree.d.ts +1 -1
  7. package/lib/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -0
  8. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseIModelTree.js +43 -48
  9. package/lib/presentation-hierarchies-react/UseIModelTree.js.map +1 -0
  10. package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -0
  11. package/lib/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
  12. package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -0
  13. package/lib/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -0
  14. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseTree.d.ts +8 -3
  15. package/lib/presentation-hierarchies-react/UseTree.d.ts.map +1 -0
  16. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseTree.js +21 -21
  17. package/lib/presentation-hierarchies-react/UseTree.js.map +1 -0
  18. package/lib/presentation-hierarchies-react/Utils.js.map +1 -0
  19. package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -0
  20. package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts +9 -0
  21. package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts.map +1 -0
  22. package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js +12 -0
  23. package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js.map +1 -0
  24. package/lib/presentation-hierarchies-react/internal/TreeActions.js.map +1 -0
  25. package/lib/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -0
  26. package/lib/presentation-hierarchies-react/internal/TreeModel.js.map +1 -0
  27. package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -0
  28. package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -0
  29. package/lib/presentation-hierarchies-react/internal/Utils.js.map +1 -0
  30. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/ErrorItemRenderer.d.ts +3 -3
  31. package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
  32. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/ErrorItemRenderer.js +158 -128
  33. package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
  34. package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
  35. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/FlatTreeNode.js +7 -4
  36. package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
  37. package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +24 -0
  38. package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
  39. package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js +41 -0
  40. package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
  41. package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -0
  42. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/RootErrorRenderer.js +64 -46
  43. package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -0
  44. package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -0
  45. package/lib/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -0
  46. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeErrorRenderer.d.ts +3 -3
  47. package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
  48. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeErrorRenderer.js +19 -20
  49. package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
  50. package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -0
  51. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeFilterAction.js +43 -30
  52. package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -0
  53. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -0
  54. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeRenameAction.js +37 -31
  55. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -0
  56. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
  57. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeRenderer.js +227 -192
  58. package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
  59. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeRenderer.d.ts +3 -6
  60. package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
  61. package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeRenderer.js +39 -45
  62. package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
  63. package/lib/{esm/presentation-hierarchies-react.d.ts → presentation-hierarchies-react.d.ts} +3 -2
  64. package/lib/{esm/presentation-hierarchies-react.js → presentation-hierarchies-react.js} +3 -2
  65. package/lib/public/locales/en/PresentationHierarchies_1.0.json +26 -0
  66. package/package.json +19 -15
  67. package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +0 -1
  68. package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +0 -1
  69. package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +0 -1
  70. package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +0 -1
  71. package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +0 -1
  72. package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +0 -1
  73. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +0 -1
  74. package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +0 -1
  75. package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +0 -1
  76. package/lib/esm/presentation-hierarchies-react/UseTree.js.map +0 -1
  77. package/lib/esm/presentation-hierarchies-react/Utils.js.map +0 -1
  78. package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js.map +0 -1
  79. package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +0 -1
  80. package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +0 -1
  81. package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +0 -1
  82. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +0 -1
  83. package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +0 -1
  84. package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +0 -1
  85. package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +0 -1
  86. package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +0 -1
  87. package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +0 -1
  88. package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +0 -1
  89. package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +0 -138
  90. package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +0 -1
  91. package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js +0 -67
  92. package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +0 -1
  93. package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +0 -1
  94. package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +0 -1
  95. package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +0 -1
  96. package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js.map +0 -1
  97. package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +0 -1
  98. package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +0 -1
  99. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +0 -1
  100. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +0 -1
  101. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +0 -1
  102. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +0 -1
  103. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +0 -1
  104. package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +0 -1
  105. package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +0 -1
  106. package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +0 -1
  107. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/Renderers.d.ts +0 -0
  108. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseNodeHighlighting.d.ts +0 -0
  109. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseNodeHighlighting.js +0 -0
  110. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseSelectionHandler.d.ts +0 -0
  111. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseSelectionHandler.js +0 -0
  112. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/Utils.js +0 -0
  113. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/internal/DisposePolyfill.js +0 -0
  114. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/internal/TreeActions.js +0 -0
  115. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/internal/TreeLoader.js +0 -0
  116. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/internal/TreeModel.d.ts +0 -0
  117. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/internal/TreeModel.js +0 -0
  118. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/internal/UseUnifiedSelection.d.ts +0 -0
  119. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/internal/UseUnifiedSelection.js +0 -0
  120. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/internal/Utils.js +0 -0
  121. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/FlatTreeNode.d.ts +0 -0
  122. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/RootErrorRenderer.d.ts +0 -0
  123. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeAction.d.ts +0 -0
  124. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeAction.js +0 -0
  125. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeFilterAction.d.ts +0 -0
  126. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeRenameAction.d.ts +0 -0
  127. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeRenderer.css +0 -0
  128. /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeRenderer.d.ts +0 -0
@@ -0,0 +1,9 @@
1
+ //#region src/presentation-hierarchies-react/internal/LocalizedStrings.d.ts
2
+ /**
3
+ * Namespaces used for localization of presentation hierarchies components.
4
+ * @alpha
5
+ */
6
+ declare const LOCALIZATION_NAMESPACES: string[];
7
+ //#endregion
8
+ export { LOCALIZATION_NAMESPACES };
9
+ //# sourceMappingURL=LocalizedStrings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalizedStrings.d.ts","names":[],"sources":["../../../src/presentation-hierarchies-react/internal/LocalizedStrings.ts"],"mappings":";;;;;cA+Ka,uBAAA"}
@@ -0,0 +1,12 @@
1
+ //#region src/presentation-hierarchies-react/internal/LocalizedStrings.ts
2
+ /** @internal */
3
+ const LOCALIZATION_NAMESPACE = "PresentationHierarchies_1.0";
4
+ /**
5
+ * Namespaces used for localization of presentation hierarchies components.
6
+ * @alpha
7
+ */
8
+ const LOCALIZATION_NAMESPACES = [LOCALIZATION_NAMESPACE];
9
+
10
+ //#endregion
11
+ export { LOCALIZATION_NAMESPACE, LOCALIZATION_NAMESPACES };
12
+ //# sourceMappingURL=LocalizedStrings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalizedStrings.js","names":["LOCALIZED_STRINGS","loading","filterHierarchyLevel","filterHierarchyLevelActiveDescription","clearHierarchyLevelFilter","noFilteredChildren","noFilteredChildrenChangeFilter","failedToCreateHierarchy","failedToCreateRootHierarchy","resultLimitExceeded","rootResultLimitExceeded","issuesForTree","issuesFound","noIssuesFound","increaseHierarchyLimit","increaseHierarchyLimitToUnlimited","increaseHierarchyLimitWithFiltering","retry","rename","more","confirm","cancel","newLabel","other","unspecified","AddPrefix","TPrefix","TPath","ObjectKeys","Acc","TObject","K","LocalizationKey","LOCALIZATION_NAMESPACE","LOCALIZATION_NAMESPACES"],"sources":["../../../src/presentation-hierarchies-react/internal/LocalizedStrings.ts"],"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\n/**\n * Localized strings used in the components.\n *\n * The version suffix in `LOCALIZATION_NAMESPACE` should be bumped when making changes to this object:\n * - minor bump when new strings are added or exists string values are changed,\n * - major bump when a string is removed.\n *\n * @internal\n */\nexport const LOCALIZED_STRINGS = {\n /**\n * Message displayed when nodes are loading.\n * Default value: `Loading...`.\n */\n loading: \"Loading...\",\n /**\n * Title for apply hierarchy filter button.\n * Default value: `Apply filter`.\n */\n filterHierarchyLevel: \"Apply filter\",\n /**\n * Accessible description for applied hierarchy filter button.\n * Default value: `Filter is applied`.\n */\n filterHierarchyLevelActiveDescription: \"Filter is applied\",\n /**\n * Title for clear hierarchy filter button.\n * Default value: `Clear active filter`.\n */\n clearHierarchyLevelFilter: \"Clear active filter\",\n /**\n * Message displayed when no nodes matching filter are found.\n * Default value: `No matches for current filter for {{node}}.`.\n */\n noFilteredChildren: \"No matches for current filter for {{node}}.\",\n /**\n * Label for change filter action.\n * Default value: `Change filter`.\n */\n noFilteredChildrenChangeFilter: \"Change filter\",\n /**\n * Message displayed when hierarchy creation for a node failed.\n * Default value: `Failed to create hierarchy for {{node}}.`.\n */\n failedToCreateHierarchy: \"Failed to create hierarchy for {{node}}.\",\n /**\n * Message displayed when hierarchy creation for a node failed.\n * Default value: `Failed to load tree.`.\n */\n failedToCreateRootHierarchy: \"Failed to load tree.\",\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.`.\n */\n resultLimitExceeded: \"The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.\",\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `The root item hierarchy contains {{limit}}+ items. Try increasing the limit.`.\n */\n rootResultLimitExceeded: \"The root item hierarchy contains {{limit}}+ items. Try increasing the limit.\",\n /**\n * Name for the error region landmark.\n * Default value: `Issues for {{tree_label}}.`.\n */\n issuesForTree: \"Issues for {{tree_label}}.\",\n /**\n * Label displayed on the error region, when errors are detected.\n * Default value: `{{number_of_issues}} issue(s) found.`.\n */\n issuesFound: \"{{number_of_issues}} issue(s) found.\",\n /**\n * Label displayed on the error region, when no issues are found.\n * Default value: `No issues found.`.\n */\n noIssuesFound: \"No issues found.\",\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `Increase limit to {{limit}}`.\n */\n increaseHierarchyLimit: \"Increase limit to {{limit}}\",\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `Remove limit`.\n */\n increaseHierarchyLimitToUnlimited: \"Remove limit\",\n /**\n * Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.\n * Default value: `Add Filter`.\n */\n increaseHierarchyLimitWithFiltering: \"Add Filter\",\n /**\n * Label for retry action.\n * Default value: `Retry`.\n */\n retry: \"Retry\",\n /**\n * Label for rename action.\n * Default value: `Rename`.\n */\n rename: \"Rename\",\n /**\n * Label for more actions button.\n * Default value: `More`.\n */\n more: \"More\",\n /**\n * Label for confirm button.\n * Default value: `Confirm`.\n */\n confirm: \"Confirm\",\n /**\n * Label for cancel button.\n * Default value: `Cancel`.\n */\n cancel: \"Cancel\",\n /**\n * Label for tree node rename input.\n * Default value: `New label`.\n */\n newLabel: \"New label\",\n /**\n * A string for \"Other\". Used for label of a range property grouping node that\n * groups values which don't fit into any other range.\n */\n other: \"Other\",\n /**\n * A string for \"Unspecified\". Used for labels of property grouping nodes\n * that group by an empty value.\n */\n unspecified: \"Unspecified\",\n};\n\ntype AddPrefix<TPrefix extends string, TPath extends string> = [TPrefix] extends [never] ? `${TPath}` : `${TPrefix}.${TPath}`;\n\n/**\n * Utility type that extracts all possible keys from a nested object as dot-separated strings\n *\n * Example:\n *\n * ```ts\n * type Example = {\n * a: {\n * b: string;\n * c: number;\n * };\n * d: boolean;\n * }\n * // ExampleKeys will be \"a.b\" | \"a.c\" | \"d\"\n * type ExampleKeys = ObjectKeys<Example>\n * ```\n */\ntype ObjectKeys<TObject extends object, Acc extends string = never> =\n | Acc\n | {\n [K in keyof TObject & string]: TObject[K] extends object ? ObjectKeys<TObject[K], AddPrefix<Acc, K>> : AddPrefix<Acc, K>;\n }[keyof TObject & string];\n\n/**\n * Type representing all possible localization keys\n * @internal\n */\nexport type LocalizationKey = ObjectKeys<typeof LOCALIZED_STRINGS>;\n\n/** @internal */\nexport const LOCALIZATION_NAMESPACE = \"PresentationHierarchies_1.0\";\n\n/**\n * Namespaces used for localization of presentation hierarchies components.\n * @alpha\n */\nexport const LOCALIZATION_NAMESPACES = [LOCALIZATION_NAMESPACE];\n"],"mappings":";;AAyKA,MAAaiC,yBAAyB;;;;;AAMtC,MAAaC,0BAA0B,CAACD,uBAAuB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeActions.js","names":["enableMapSet","produce","buffer","debounceTime","EMPTY","groupBy","map","mergeMap","reduce","Subject","switchMap","takeUntil","tap","HierarchyNode","TreeLoader","TreeModel","createNodeId","sameNodes","Draft","Observable","GenericInstanceFilter","HierarchyProvider","ErrorInfo","SelectionChangeType","HierarchyLevelOptions","ITreeLoader","LoadedTreePart","LoadNodesOptions","TreeModelHierarchyNode","TreeModelRootNode","LoadDebouncedNodesOptions","loadOptions","onComplete","timeTracker","TimeTracker","initialRootNode","parentId","discardState","TreeActions","_loader","_nodeIdFactory","node","Pick","_currentModel","_reset","_nodeLoader","constructor","_onModelChanged","model","_onLoad","actionType","duration","_onHierarchyLimitExceeded","props","filter","limit","_onHierarchyLoadError","type","error","nodeIdFactory","seed","NoopTreeLoader","idToNode","Map","parentChildMap","rootNode","id","undefined","nodeData","createNodeLoader","subject","pipe","item","group","groupArr","returnIndex","length","forEach","member","index","Symbol","dispose","loadNodes","collectTreePartsUntil","next","newModel","parentNode","get","handleLoadedHierarchy","finish","complete","onLoadingComplete","subscribe","updateTreeModel","updater","loadedHierarchy","addHierarchyPart","setIsLoading","getLoadAction","size","loadSubTree","options","loadAction","parent","time","Promise","resolve","ignoreCache","getHierarchyLevelOptions","createHierarchyLevelOptions","getNonGroupedParentId","shouldLoadChildren","autoExpand","reloadSubTree","oldModel","currModel","expandedNodes","collectNodes","isExpanded","collapsedNodes","instanceFilter","hierarchyLevelSizeLimit","filteredNodeId","findIndex","expandedNode","collapsedNode","buildNode","addAttributes","getNode","reset","setHierarchyProvider","provider","Number","MAX_SAFE_INTEGER","nodeId","selectNodes","nodeIds","Array","changeType","expandNode","childrenAction","ReturnType","setHierarchyLimit","loadChildren","setInstanceFilter","reloadTree","parentNodeId","state","removeSubTree","untilNotifier","source","treeModel","loadedPart","addTreePartToModel","addNodesToModel","addErrorToModel","set","loadedNodes","oldNode","hierarchyLimit","isSelected","pred","currentChildren","flatMap","child","currNode","isGroupingNode","nonGroupingAncestor","modelNode","_start","_stopped","_onFinish","Date","now","elapsedTime"],"sources":["../../../src/presentation-hierarchies-react/internal/TreeActions.ts"],"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 \"./DisposePolyfill.js\";\n\nimport { enableMapSet, produce } from \"immer\";\nimport { buffer, debounceTime, EMPTY, groupBy, map, mergeMap, reduce, Subject, switchMap, takeUntil, tap } from \"rxjs\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { TreeLoader } from \"./TreeLoader.js\";\nimport { TreeModel } from \"./TreeModel.js\";\nimport { createNodeId, sameNodes } from \"./Utils.js\";\n\nimport type { Draft } from \"immer\";\nimport type { Observable } from \"rxjs\";\nimport type { GenericInstanceFilter, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport type { ErrorInfo } from \"../TreeNode.js\";\nimport type { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport type { HierarchyLevelOptions, ITreeLoader, LoadedTreePart, LoadNodesOptions } from \"./TreeLoader.js\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\nenableMapSet();\n\ninterface LoadDebouncedNodesOptions {\n loadOptions: LoadNodesOptions;\n onComplete: () => void;\n timeTracker?: TimeTracker;\n initialRootNode?: TreeModelRootNode;\n parentId?: string;\n discardState?: boolean;\n}\n\n/** @internal */\nexport class TreeActions {\n private _loader: ITreeLoader;\n private _nodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string;\n private _currentModel: TreeModel;\n private _reset = new Subject<void>();\n private _nodeLoader: Subject<LoadDebouncedNodesOptions>;\n\n constructor(\n private _onModelChanged: (model: TreeModel) => void,\n private _onLoad: (actionType: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void,\n private _onHierarchyLimitExceeded: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void,\n private _onHierarchyLoadError: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void,\n nodeIdFactory?: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string,\n seed?: TreeModel,\n ) {\n this._loader = new NoopTreeLoader();\n this._nodeIdFactory = nodeIdFactory ?? createNodeId;\n this._currentModel = seed ?? /* c8 ignore next */ {\n idToNode: new Map(),\n parentChildMap: new Map(),\n rootNode: { id: undefined, nodeData: undefined },\n };\n\n this._nodeLoader = this.createNodeLoader();\n }\n\n private createNodeLoader() {\n const subject = new Subject<LoadDebouncedNodesOptions>();\n subject\n .pipe(\n groupBy((item) => item.parentId),\n mergeMap((group) =>\n group.pipe(\n buffer(group.pipe(debounceTime(0))),\n map((groupArr) => {\n let returnIndex = groupArr.length - 1;\n\n groupArr.forEach((member, index) => {\n if (member.discardState) {\n returnIndex = index;\n }\n });\n\n groupArr.forEach((member, index) => {\n if (index === returnIndex) {\n return;\n }\n member.timeTracker?.[Symbol.dispose];\n member.onComplete();\n });\n return groupArr[returnIndex];\n }),\n switchMap((props) =>\n this._loader.loadNodes(props.loadOptions).pipe(\n collectTreePartsUntil(this._reset, props.initialRootNode),\n tap({\n next: (newModel: TreeModel) => {\n const parentNode = props.parentId ? newModel.idToNode.get(props.parentId) : newModel.rootNode;\n this.handleLoadedHierarchy(props.parentId, newModel);\n // only report load duration if children were loaded\n if (!(parentNode && parentNode.error)) {\n props.timeTracker?.finish();\n }\n },\n complete: () => {\n this.onLoadingComplete(props.parentId);\n props.timeTracker?.[Symbol.dispose]();\n props.onComplete();\n },\n }),\n ),\n ),\n ),\n ),\n )\n .subscribe();\n\n return subject;\n }\n\n private updateTreeModel(updater: (model: Draft<TreeModel>) => void) {\n const newModel = produce(this._currentModel, updater);\n if (this._currentModel === newModel) {\n return;\n }\n\n this._currentModel = newModel;\n this._onModelChanged(this._currentModel);\n }\n\n private handleLoadedHierarchy(parentId: string | undefined, loadedHierarchy: TreeModel) {\n this.updateTreeModel((model) => {\n TreeModel.addHierarchyPart(model, parentId, loadedHierarchy);\n });\n }\n\n private onLoadingComplete(parentId: string | undefined) {\n this.updateTreeModel((model) => {\n TreeModel.setIsLoading(model, parentId, false);\n });\n }\n\n private getLoadAction(parentId: string | undefined) {\n return this._currentModel.idToNode.size === 0 ? \"initial-load\" : parentId === undefined ? \"reload\" : \"hierarchy-level-load\";\n }\n\n private loadSubTree(options: LoadNodesOptions, initialRootNode?: TreeModelRootNode, discardState?: boolean) {\n const loadAction = this.getLoadAction(options.parent.id);\n const timeTracker = new TimeTracker((time) => this._onLoad(loadAction, time));\n\n return {\n complete: new Promise<void>((resolve) => {\n this._nodeLoader.next({ loadOptions: options, onComplete: resolve, timeTracker, parentId: options.parent.id, initialRootNode, discardState });\n }),\n };\n }\n\n private loadNodes(parentId: string, ignoreCache?: boolean) {\n const parentNode = this._currentModel.idToNode.get(parentId);\n /* c8 ignore next 3 */\n if (!parentNode) {\n return { complete: Promise.resolve() };\n }\n return this.loadSubTree({\n parent: parentNode,\n getHierarchyLevelOptions: (node) => createHierarchyLevelOptions(this._currentModel, getNonGroupedParentId(node, this._nodeIdFactory)),\n shouldLoadChildren: (node) => !!node.nodeData.autoExpand,\n ignoreCache,\n });\n }\n\n private reloadSubTree(parentId: string | undefined, oldModel: TreeModel, options?: { discardState?: boolean; ignoreCache?: boolean }) {\n const currModel = this._currentModel;\n const expandedNodes = !!options?.discardState ? [] : collectNodes(parentId, oldModel, (node) => node.isExpanded === true);\n const collapsedNodes = !!options?.discardState ? [] : collectNodes(parentId, oldModel, (node) => node.isExpanded === false);\n const getHierarchyLevelOptions = (node: TreeModelRootNode | TreeModelHierarchyNode) => {\n if (!!options?.discardState) {\n return { instanceFilter: undefined, hierarchyLevelSizeLimit: undefined };\n }\n const filteredNodeId = getNonGroupedParentId(node, this._nodeIdFactory);\n return createHierarchyLevelOptions(filteredNodeId === parentId ? currModel : oldModel, filteredNodeId);\n };\n const shouldLoadChildren = (node: TreeModelHierarchyNode) => {\n if (expandedNodes.findIndex((expandedNode) => sameNodes(expandedNode.nodeData, node.nodeData)) !== -1) {\n return true;\n }\n if (collapsedNodes.findIndex((collapsedNode) => sameNodes(collapsedNode.nodeData, node.nodeData)) !== -1) {\n return false;\n }\n return !!node.nodeData.autoExpand;\n };\n const buildNode = (node: TreeModelHierarchyNode) => (!!options?.discardState || node.id === parentId ? node : addAttributes(node, oldModel));\n\n const rootNode = parentId !== undefined ? this.getNode(parentId) : currModel.rootNode;\n /* c8 ignore next 3 */\n if (!rootNode) {\n return { complete: Promise.resolve() };\n }\n\n if (parentId === undefined) {\n // cancel all ongoing requests\n this._reset.next();\n }\n\n return this.loadSubTree(\n { parent: rootNode, getHierarchyLevelOptions, shouldLoadChildren, buildNode, ignoreCache: options?.ignoreCache },\n !!options?.discardState ? undefined : { ...currModel.rootNode },\n options?.discardState,\n );\n }\n\n public reset() {\n this._reset.next();\n }\n\n public setHierarchyProvider(provider?: HierarchyProvider) {\n this._loader = provider\n ? new TreeLoader(\n provider,\n this._onHierarchyLimitExceeded,\n ({ parentId, type, error }) => {\n if (type === \"timeout\") {\n const loadAction = this.getLoadAction(parentId);\n this._onLoad(loadAction, Number.MAX_SAFE_INTEGER);\n }\n this._onHierarchyLoadError({ parentId, type, error });\n },\n this._nodeIdFactory,\n )\n : /* c8 ignore next */ new NoopTreeLoader();\n }\n\n public getNode(nodeId: string | undefined): TreeModelHierarchyNode | TreeModelRootNode | undefined {\n return TreeModel.getNode(this._currentModel, nodeId);\n }\n\n public selectNodes(nodeIds: Array<string>, changeType: SelectionChangeType) {\n this.updateTreeModel((model) => {\n TreeModel.selectNodes(model, nodeIds, changeType);\n });\n }\n\n public expandNode(nodeId: string, isExpanded: boolean) {\n let childrenAction = \"none\" as ReturnType<typeof TreeModel.expandNode>;\n this.updateTreeModel((model) => {\n childrenAction = TreeModel.expandNode(model, nodeId, isExpanded);\n });\n\n if (childrenAction === \"none\") {\n return { complete: Promise.resolve() };\n }\n\n return this.loadNodes(nodeId, childrenAction === \"reloadChildren\");\n }\n\n public setHierarchyLimit(nodeId: string | undefined, limit?: number | \"unbounded\") {\n const oldModel = this._currentModel;\n let loadChildren = false as boolean;\n this.updateTreeModel((model) => {\n loadChildren = TreeModel.setHierarchyLimit(model, nodeId, limit);\n });\n\n if (!loadChildren) {\n return { complete: Promise.resolve() };\n }\n\n return this.reloadSubTree(nodeId, oldModel);\n }\n\n public setInstanceFilter(nodeId: string | undefined, filter?: GenericInstanceFilter) {\n const oldModel = this._currentModel;\n let loadChildren = false as boolean;\n this.updateTreeModel((model) => {\n loadChildren = TreeModel.setInstanceFilter(model, nodeId, filter);\n });\n\n if (!loadChildren) {\n return { complete: Promise.resolve() };\n }\n\n return this.reloadSubTree(nodeId, oldModel);\n }\n\n public reloadTree(options?: { parentNodeId?: string; state?: \"keep\" | \"discard\" | \"reset\" }) {\n const oldModel = this._currentModel;\n this.updateTreeModel((model) => {\n TreeModel.setIsLoading(model, options?.parentNodeId, true);\n if (options?.state === \"reset\") {\n TreeModel.removeSubTree(model, options.parentNodeId);\n }\n });\n\n const discardState = options?.state === \"discard\" || options?.state === \"reset\";\n const ignoreCache = options?.state === \"reset\";\n return this.reloadSubTree(options?.parentNodeId, oldModel, { discardState, ignoreCache });\n }\n}\n\nfunction collectTreePartsUntil(untilNotifier: Observable<void>, rootNode?: TreeModelRootNode) {\n return (source: Observable<LoadedTreePart>) =>\n source.pipe(\n reduce<LoadedTreePart, TreeModel>(\n (treeModel, loadedPart) => {\n addTreePartToModel(treeModel, loadedPart);\n return treeModel;\n },\n {\n idToNode: new Map(),\n parentChildMap: new Map(),\n rootNode: rootNode ?? { id: undefined, nodeData: undefined },\n },\n ),\n takeUntil(untilNotifier),\n );\n}\n\nfunction addTreePartToModel(treeModel: TreeModel, loadedPart: LoadedTreePart) {\n if (\"loadedNodes\" in loadedPart) {\n addNodesToModel(treeModel, loadedPart);\n } else {\n addErrorToModel(treeModel, loadedPart);\n }\n}\n\nfunction addErrorToModel(model: TreeModel, loadedPart: { parent: TreeModelHierarchyNode | TreeModelRootNode; error: ErrorInfo }) {\n if (loadedPart.parent.id === undefined) {\n model.rootNode.error = loadedPart.error;\n } else {\n model.idToNode.set(loadedPart.parent.id, { ...loadedPart.parent, error: loadedPart.error });\n }\n}\n\nfunction addNodesToModel(model: TreeModel, loadedPart: { parent: TreeModelHierarchyNode | TreeModelRootNode; loadedNodes: TreeModelHierarchyNode[] }) {\n model.parentChildMap.set(\n loadedPart.parent.id,\n loadedPart.loadedNodes.map((node) => node.id),\n );\n for (const node of loadedPart.loadedNodes) {\n model.idToNode.set(node.id, node);\n }\n const parentNode = loadedPart.parent.id ? model.idToNode.get(loadedPart.parent.id) : undefined;\n if (parentNode && loadedPart.loadedNodes.length !== 0) {\n parentNode.isExpanded = true;\n }\n}\n\nfunction addAttributes(node: TreeModelHierarchyNode, oldModel: TreeModel) {\n const oldNode = oldModel.idToNode.get(node.id);\n if (oldNode) {\n node.hierarchyLimit = oldNode.hierarchyLimit;\n node.instanceFilter = oldNode.instanceFilter;\n node.isSelected = oldNode.isSelected;\n }\n return node;\n}\n\nfunction collectNodes(parentId: string | undefined, model: TreeModel, pred: (node: TreeModelHierarchyNode) => boolean): TreeModelHierarchyNode[] {\n const currentChildren = model.parentChildMap.get(parentId);\n if (!currentChildren) {\n return [];\n }\n\n if (parentId === undefined) {\n return currentChildren.flatMap((child) => collectNodes(child, model, pred));\n }\n\n const currNode = model.idToNode.get(parentId);\n if (!currNode || !pred(currNode)) {\n return [];\n }\n\n return [currNode, ...currentChildren.flatMap((child) => collectNodes(child, model, pred))];\n}\n\nfunction getNonGroupedParentId(node: TreeModelHierarchyNode | TreeModelRootNode, nodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string) {\n if (!node.nodeData || !HierarchyNode.isGroupingNode(node.nodeData)) {\n return node.id;\n }\n\n if (!node.nodeData.nonGroupingAncestor) {\n return undefined;\n }\n\n return nodeIdFactory(node.nodeData.nonGroupingAncestor);\n}\n\nfunction createHierarchyLevelOptions(model: TreeModel, nodeId: string | undefined): HierarchyLevelOptions {\n if (nodeId === undefined) {\n return { instanceFilter: model.rootNode.instanceFilter, hierarchyLevelSizeLimit: model.rootNode.hierarchyLimit };\n }\n\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode) {\n return { instanceFilter: undefined, hierarchyLevelSizeLimit: undefined };\n }\n return { instanceFilter: modelNode.instanceFilter, hierarchyLevelSizeLimit: modelNode.hierarchyLimit };\n}\n\n/* c8 ignore start */\nclass NoopTreeLoader implements ITreeLoader {\n public loadNodes(): Observable<LoadedTreePart> {\n return EMPTY;\n }\n}\n/* c8 ignore end */\n\nclass TimeTracker {\n private _start: number;\n private _stopped: boolean = false;\n\n constructor(private _onFinish: (time: number) => void) {\n this._start = Date.now();\n }\n\n public [Symbol.dispose]() {\n this._stopped = true;\n }\n\n public finish() {\n /* c8 ignore next 3 */\n if (this._stopped) {\n return;\n }\n\n this._stopped = true;\n const elapsedTime = Date.now() - this._start;\n this._onFinish(elapsedTime);\n }\n}\n"],"mappings":";;;;;;;;;AAsBAA,cAAc;;AAYd,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I,KAAKiF,SACP;AAGF,OAAKA,WAAW;EAChB,MAAMI,cAAcF,KAAKC,KAAK,GAAG,KAAKJ;AACtC,OAAKE,UAAUG,YAAY"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeLoader.js","names":["catchError","EMPTY","expand","filter","from","map","mergeMap","of","toArray","createNodeId","Observable","GenericInstanceFilter","HierarchyNode","HierarchyProvider","RowsLimitExceededError","ErrorInfo","TreeModelHierarchyNode","TreeModelRootNode","LoadedTreePart","parent","loadedNodes","error","HierarchyLevelOptions","instanceFilter","hierarchyLevelSizeLimit","LoadNodesOptions","getHierarchyLevelOptions","node","shouldLoadChildren","buildNode","ignoreCache","ITreeLoader","loadNodes","options","TreeLoader","_treeNodeIdFactory","Pick","constructor","_hierarchyProvider","_onHierarchyLimitExceeded","props","parentId","limit","_onHierarchyLoadError","type","treeNodeIdFactory","loadChildren","Omit","infoNodeIdBase","id","treeModelNodesFactory","createTreeModelNodesFactory","getNodes","parentNode","nodeData","pipe","childNodes","length","const","err","hierarchyLoadErrorType","Error","isRowsLimitError","message","resultSetSizeLimit","isTimeoutError","loadedPart","modelNode","children","label","includes"],"sources":["../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"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, EMPTY, expand, filter, from, map, mergeMap, of, toArray } from \"rxjs\";\nimport { createNodeId } from \"./Utils.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { GenericInstanceFilter, HierarchyNode, HierarchyProvider, RowsLimitExceededError } from \"@itwin/presentation-hierarchies\";\nimport type { ErrorInfo } from \"../TreeNode.js\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport type LoadedTreePart = {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n} & (\n | {\n loadedNodes: TreeModelHierarchyNode[];\n }\n | {\n error: ErrorInfo;\n }\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 private _treeNodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string;\n\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\"; error: unknown }) => void,\n treeNodeIdFactory?: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string,\n ) {\n this._treeNodeIdFactory = treeNodeIdFactory ?? /* c8 ignore next */ createNodeId;\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, treeNodeIdFactory: this._treeNodeIdFactory });\n return from(\n this._hierarchyProvider.getNodes({\n parentNode: parent.nodeData,\n hierarchyLevelSizeLimit,\n instanceFilter,\n ignoreCache,\n }),\n ).pipe(\n toArray(),\n map((childNodes): LoadedTreePart => {\n return instanceFilter && childNodes.length === 0\n ? {\n parent,\n error: {\n id: `${infoNodeIdBase}-no-filter-matches`,\n type: \"NoFilterMatches\" as const,\n },\n }\n : {\n parent,\n loadedNodes: childNodes.map(treeModelNodesFactory),\n };\n }),\n catchError((err) => {\n let hierarchyLoadErrorType: \"unknown\" | \"timeout\" = \"unknown\";\n if (err instanceof Error) {\n if (isRowsLimitError(err)) {\n this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: err.limit });\n return of({\n parent,\n error: { id: `${infoNodeIdBase}-${err.message}`, type: \"ResultSetTooLarge\" as const, resultSetSizeLimit: err.limit },\n });\n }\n if (isTimeoutError(err)) {\n hierarchyLoadErrorType = \"timeout\";\n }\n }\n\n this._onHierarchyLoadError({ parentId: parent.id, type: hierarchyLoadErrorType, error: err });\n return of({\n parent,\n error: {\n id: `${infoNodeIdBase}-ChildrenLoad`,\n type: \"ChildrenLoad\" as const,\n message: \"Failed to create hierarchy level\",\n },\n });\n }),\n );\n }\n\n public loadNodes({ shouldLoadChildren, ...options }: LoadNodesOptions) {\n return this.loadChildren(options).pipe(\n expand((loadedPart) =>\n \"loadedNodes\" in loadedPart\n ? from(loadedPart.loadedNodes).pipe(\n filter((node) => shouldLoadChildren(node)),\n mergeMap((node) => this.loadChildren({ ...options, parent: node })),\n )\n : EMPTY,\n ),\n );\n }\n}\n\nfunction createTreeModelNodesFactory({\n buildNode,\n treeNodeIdFactory,\n}: {\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n treeNodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string;\n}): (node: HierarchyNode) => TreeModelHierarchyNode {\n return (node: HierarchyNode) => {\n const modelNode: TreeModelHierarchyNode = {\n id: treeNodeIdFactory(node),\n children: node.children,\n label: node.label,\n nodeData: node,\n };\n return buildNode ? buildNode(modelNode) : modelNode;\n };\n}\n\nfunction isRowsLimitError(error: Error): error is RowsLimitExceededError {\n return \"limit\" in error && error.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"],"mappings":";;;;;AA8CA,IAAakC,aAAb,MAA+C;CAC7C,AAAQC;CAERE,YACE,AAAQC,oBACR,AAAQC,2BACR,AAAQI,uBACRE,mBACA;EAJQP;EACAC;EACAI;AAGR,OAAKR,qBAAqBU,qBAA0CpC;;CAGtE,AAAQqC,aAAa,EAAE3B,QAAQO,0BAA0BG,WAAWC,eAA6D;EAC/H,MAAM,EAAEP,gBAAgBC,4BAA4BE,yBAAyBP,OAAO;EACpF,MAAM6B,iBAAiB,GAAG7B,OAAO8B,MAAM;EACvC,MAAMC,wBAAwBC,4BAA4B;GAAEtB;GAAWgB,mBAAmB,KAAKV;GAAoB,CAAC;AACpH,SAAO/B,KACL,KAAKkC,mBAAmBc,SAAS;GAC/BC,YAAYlC,OAAOmC;GACnB9B;GACAD;GACAO;GACD,CACH,CAAC,CAACyB,KACA/C,SAAS,EACTH,KAAKmD,eAA+B;AAClC,UAAOjC,kBAAkBiC,WAAWC,WAAW,IAC3C;IACEtC;IACAE,OAAO;KACL4B,IAAI,GAAGD,eAAc;KACrBJ,MAAM;KACR;IACD,GACD;IACEzB;IACAC,aAAaoC,WAAWnD,IAAI6C,sBAAqB;IAClD;IACL,EACFlD,YAAY2D,QAAQ;GAClB,IAAIC,yBAAgD;AACpD,OAAID,eAAeE,OAAO;AACxB,QAAIC,iBAAiBH,IAAI,EAAE;AACzB,UAAKpB,0BAA0B;MAAEE,UAAUtB,OAAO8B;MAAI9C,QAAQoB;MAAgBmB,OAAOiB,IAAIjB;MAAO,CAAC;AACjG,YAAOnC,GAAG;MACRY;MACAE,OAAO;OAAE4B,IAAI,GAAGD,eAAc,GAAIW,IAAII;OAAWnB,MAAM;OAA8BoB,oBAAoBL,IAAIjB;OAAM;MACpH,CAAC;;AAEJ,QAAIuB,eAAeN,IAAI,CACrBC,0BAAyB;;AAI7B,QAAKjB,sBAAsB;IAAEF,UAAUtB,OAAO8B;IAAIL,MAAMgB;IAAwBvC,OAAOsC;IAAK,CAAC;AAC7F,UAAOpD,GAAG;IACRY;IACAE,OAAO;KACL4B,IAAI,GAAGD,eAAc;KACrBJ,MAAM;KACNmB,SAAS;KACX;IACD,CAAC;IAEN,CAAC;;CAGH,AAAO/B,UAAU,EAAEJ,oBAAoB,GAAGK,WAA6B;AACrE,SAAO,KAAKa,aAAab,QAAQ,CAACsB,KAChCrD,QAAQgE,eACN,iBAAiBA,aACb9D,KAAK8D,WAAW9C,YAAY,CAACmC,KAC3BpD,QAAQwB,SAASC,mBAAmBD,KAAK,CAAC,EAC1CrB,UAAUqB,SAAS,KAAKmB,aAAa;GAAE,GAAGb;GAASd,QAAQQ;GAAM,CAAC,CACpE,CAAC,GACD1B,MAER,CAAC;;;AAIL,SAASkD,4BAA4B,EACnCtB,WACAgB,qBAIkD;AAClD,SAAQlB,SAAwB;EAC9B,MAAMwC,YAAoC;GACxClB,IAAIJ,kBAAkBlB,KAAK;GAC3ByC,UAAUzC,KAAKyC;GACfC,OAAO1C,KAAK0C;GACZf,UAAU3B;GACX;AACD,SAAOE,YAAYA,UAAUsC,UAAU,GAAGA;;;AAI9C,SAASL,iBAAiBzC,OAA+C;AACvE,QAAO,WAAWA,SAASA,MAAM0C,QAAQO,SAAS,sBAAsB;;AAG1E,SAASL,eAAe5C,OAAc;AACpC,QAAOA,MAAM0C,QAAQO,SAAS,kDAAkD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TreeModel.js","names":["GenericInstanceFilter","HierarchyNode","ErrorInfo","SelectionChangeType","TreeModelRootNode","id","nodeData","hierarchyLimit","instanceFilter","isLoading","error","TreeModelHierarchyNode","label","children","isExpanded","isSelected","TreeModel","parentChildMap","Map","idToNode","rootNode","expandNode","model","nodeId","node","get","type","removeSubTree","addHierarchyPart","rootId","hierarchyPart","parentId","set","parentNode","undefined","clearNodeError","currentChildren","delete","childId","childNode","setHierarchyLimit","limit","updateForReload","setInstanceFilter","filter","selectNodes","nodeIds","Array","changeType","find","modelNode","isNodeSelected","currentNode","getNode","setIsLoading","update"],"sources":["../../../src/presentation-hierarchies-react/internal/TreeModel.ts"],"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 type { GenericInstanceFilter, HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport type { ErrorInfo } from \"../TreeNode.js\";\nimport type { SelectionChangeType } from \"../UseSelectionHandler.js\";\n\n/** @internal */\nexport interface TreeModelRootNode {\n id: undefined;\n nodeData: undefined;\n hierarchyLimit?: number | \"unbounded\";\n instanceFilter?: GenericInstanceFilter;\n isLoading?: boolean;\n error?: ErrorInfo;\n}\n\n/** @internal */\nexport interface TreeModelHierarchyNode {\n id: string;\n nodeData: HierarchyNode;\n label: string;\n children: boolean;\n isLoading?: boolean;\n isExpanded?: boolean;\n isSelected?: boolean;\n hierarchyLimit?: number | \"unbounded\";\n instanceFilter?: GenericInstanceFilter;\n error?: ErrorInfo;\n}\n\n/** @internal */\nexport interface TreeModel {\n parentChildMap: Map<string | undefined, string[]>;\n idToNode: Map<string, TreeModelHierarchyNode>;\n rootNode: TreeModelRootNode;\n}\n\n/** @internal */\nexport namespace TreeModel {\n export function expandNode(model: TreeModel, nodeId: string, isExpanded: boolean): \"none\" | \"loadChildren\" | \"reloadChildren\" {\n const node = model.idToNode.get(nodeId);\n if (!node) {\n return \"none\";\n }\n\n node.isExpanded = isExpanded;\n if (!isExpanded) {\n return \"none\";\n }\n\n if (node.error?.type === \"ChildrenLoad\") {\n node.isLoading = true;\n // remove subtree if there `ChildrenLoad` error info in order to attempt reloading children\n TreeModel.removeSubTree(model, nodeId);\n return \"reloadChildren\";\n }\n\n if (!node.children) {\n return \"none\";\n }\n\n const children = model.parentChildMap.get(node.id);\n if (!children) {\n node.isLoading = true;\n return \"loadChildren\";\n }\n\n return \"none\";\n }\n\n /** @internal */\n export function addHierarchyPart(model: TreeModel, rootId: string | undefined, hierarchyPart: TreeModel): void {\n removeSubTree(model, rootId);\n model.rootNode.error = hierarchyPart.rootNode.error;\n\n for (const [parentId, children] of hierarchyPart.parentChildMap) {\n model.parentChildMap.set(parentId, children);\n }\n\n for (const [nodeId, node] of hierarchyPart.idToNode) {\n model.idToNode.set(nodeId, node);\n }\n\n const parentNode = rootId !== undefined ? model.idToNode.get(rootId) : model.rootNode;\n /* c8 ignore next 3*/\n if (!parentNode) {\n return;\n }\n parentNode.isLoading = false;\n }\n\n export function removeSubTree(model: TreeModel, parentId: string | undefined): void {\n clearNodeError(model, parentId);\n const currentChildren = model.parentChildMap.get(parentId);\n if (!currentChildren) {\n return;\n }\n model.parentChildMap.delete(parentId);\n\n for (const childId of currentChildren) {\n const childNode = model.idToNode.get(childId);\n if (childNode) {\n removeSubTree(model, childNode.id);\n }\n model.idToNode.delete(childId);\n }\n }\n\n export function setHierarchyLimit(model: TreeModel, nodeId: string | undefined, limit?: number | \"unbounded\"): boolean {\n return updateForReload(model, nodeId, (node) => {\n node.hierarchyLimit = limit;\n });\n }\n\n export function setInstanceFilter(model: TreeModel, nodeId: string | undefined, filter?: GenericInstanceFilter): boolean {\n return updateForReload(model, nodeId, (node) => {\n if (filter && node.id !== undefined) {\n node.isExpanded = true;\n }\n node.instanceFilter = filter;\n });\n }\n\n export function selectNodes(model: TreeModel, nodeIds: Array<string>, changeType: SelectionChangeType) {\n if (changeType === \"replace\") {\n for (const [nodeId, node] of model.idToNode) {\n node.isSelected = !!nodeIds.find((id) => id === nodeId);\n }\n return;\n }\n for (const nodeId of nodeIds) {\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode) {\n return;\n }\n modelNode.isSelected = changeType === \"add\";\n }\n }\n\n export function isNodeSelected(model: TreeModel, nodeId: string): boolean {\n const currentNode = model.idToNode.get(nodeId);\n return !!currentNode && !!currentNode.isSelected;\n }\n\n export function getNode(model: TreeModel, nodeId: string | undefined): TreeModelHierarchyNode | TreeModelRootNode | undefined {\n if (!nodeId) {\n return model.rootNode;\n }\n return model.idToNode.get(nodeId);\n }\n\n export function setIsLoading(model: TreeModel, nodeId: string | undefined, isLoading: boolean) {\n if (nodeId === undefined) {\n model.rootNode.isLoading = isLoading;\n return;\n }\n const modelNode = model.idToNode.get(nodeId);\n /* c8 ignore next 3*/\n if (!modelNode) {\n return;\n }\n modelNode.isLoading = isLoading;\n }\n}\n\nfunction updateForReload(model: TreeModel, nodeId: string | undefined, update: (node: TreeModelHierarchyNode | TreeModelRootNode) => void) {\n TreeModel.removeSubTree(model, nodeId);\n if (nodeId === undefined) {\n update(model.rootNode);\n model.rootNode.isLoading = true;\n return true;\n }\n\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode) {\n return false;\n }\n\n update(modelNode);\n if (modelNode.isExpanded) {\n modelNode.isLoading = true;\n return true;\n }\n return false;\n}\n\nfunction clearNodeError(model: TreeModel, parentId: string | undefined) {\n if (!parentId) {\n return (model.rootNode.error = undefined);\n }\n const node = model.idToNode.get(parentId);\n if (!node) {\n return;\n }\n node.error = undefined;\n}\n"],"mappings":";;;CA0CS,SAASqB,WAAWC,OAAkBC,QAAgBT,YAAiE;EAC5H,MAAMU,OAAOF,MAAMH,SAASM,IAAIF,OAAO;AACvC,MAAI,CAACC,KACH,QAAO;AAGTA,OAAKV,aAAaA;AAClB,MAAI,CAACA,WACH,QAAO;AAGT,MAAIU,KAAKd,OAAOgB,SAAS,gBAAgB;AACvCF,QAAKf,YAAY;AAEjBO,aAAUW,cAAcL,OAAOC,OAAO;AACtC,UAAO;;AAGT,MAAI,CAACC,KAAKX,SACR,QAAO;AAIT,MAAI,CADaS,MAAML,eAAeQ,IAAID,KAAKnB,GAAG,EACnC;AACbmB,QAAKf,YAAY;AACjB,UAAO;;AAGT,SAAO;;;CAIF,SAASmB,iBAAiBN,OAAkBO,QAA4BC,eAAgC;AAC7GH,gBAAcL,OAAOO,OAAO;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src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"mappings":";;;;;;;UAuBiB,4BAAA;EAoByG;;;EAhBxH,UAAA;EAAA;;;;;;;;;;;;;;EAgBA,8BAAA,IAAkC,IAAA,EAAM,wBAAA;IAA6B,GAAA,EAAK,cAAA;EAAA,GAAkB,eAAA,aAA4B,UAAA;;;;EAKxH,gBAAA,EAAkB,gBAAA;AAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UseUnifiedSelection.js","names":["useEffect","useState","assert","HierarchyNode","Selectables","GenericNodeKey","InstancesNodeKey","NonGroupingHierarchyNode","InstanceKey","Selectable","SelectionStorage","SelectionChangeType","TreeModelHierarchyNode","TreeModelRootNode","TreeSelectionOptions","isNodeSelected","nodeId","selectNodes","nodeIds","Array","changeType","UseUnifiedTreeSelectionProps","sourceName","createSelectableForGenericNode","node","key","treeModelNodeId","selectionStorage","useUnifiedTreeSelection","t0","$","_c","getTreeModelNode","t1","undefined","defaultCreateSelectableForGenericNode","options","setOptions","_temp3","t2","t3","createOptions","selectionChangeEvent","addListener","args","level","_temp","_temp2","NonNullable","identifier","data","loadInstanceKeys","source","storage","getNode","id","imodelKey","nodeSelectables","groupNodeSelectablesByIModelKey","storageSelectables","getSelection","hasAny","imodelSelectables","Map","selectablesList","get","set","forEach","selectable","push","selectables","actionProps","addToSelection","removeFromSelection","replaceSelection","modelNode","hierarchyNode","nodeData","isInstancesNode","groupIModelInstanceKeys","instanceKeys","isGroupingNode","groupingNodeSelectables","groupedInstanceKeys","isGeneric","reduce"],"sources":["../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useEffect, useState } from \"react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { Selectables } from \"@itwin/unified-selection\";\n\nimport type { GenericNodeKey, InstancesNodeKey, NonGroupingHierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { Selectable, SelectionStorage } from \"@itwin/unified-selection\";\nimport type { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @public */\nexport interface UseUnifiedTreeSelectionProps {\n /**\n * Identifier to distinguish this source of changes to the unified selection from another ones in the application.\n */\n sourceName: string;\n\n /**\n * An optional function that allows customizing the `Selectable` object that gets created for generic hierarchy nodes. When\n * not supplied, the `Selectable` is created using the following signature:\n * ```ts\n * {\n * identifier: treeModelNodeId,\n * data: node,\n * async *loadInstanceKeys() {},\n * }\n * ```\n *\n * @param node Hierarchy node to create a selectable for.\n * @param treeModelNodeId ID of the hierarchy node in the internal tree model. This ID uniquely identifies the node in the whole hierarchy, as opposed to `GenericNodeKey.id` contained within the `node`, which may not be unique.\n */\n createSelectableForGenericNode?: (node: NonGroupingHierarchyNode & { key: GenericNodeKey }, treeModelNodeId: string) => Selectable;\n\n /**\n * Unified selection storage to use for listening, getting and changing active selection.\n */\n selectionStorage: SelectionStorage;\n}\n\n/** @internal */\nexport function useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n createSelectableForGenericNode = defaultCreateSelectableForGenericNode,\n}: UseUnifiedTreeSelectionProps & { getTreeModelNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined }): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* c8 ignore next */ () => false,\n selectNodes: /* c8 ignore next */ () => {},\n }));\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (args.level > 0) {\n return;\n }\n setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));\n });\n }, [selectionStorage, createSelectableForGenericNode, getTreeModelNode, sourceName]);\n\n return options;\n}\n\nconst defaultCreateSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]> = (\n node,\n treeModelNodeId,\n): Selectable => ({\n identifier: treeModelNodeId,\n data: node,\n async *loadInstanceKeys() {},\n});\n\nfunction createOptions(\n source: string,\n storage: SelectionStorage,\n createSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]>,\n getNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined,\n): TreeSelectionOptions {\n return {\n isNodeSelected: (nodeId: string) => {\n const node = getNode(nodeId);\n if (!node || node.id === undefined) {\n return false;\n }\n for (const [imodelKey, nodeSelectables] of groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)) {\n const storageSelectables = storage.getSelection({ imodelKey, level: 0 });\n if (Selectables.hasAny(storageSelectables, nodeSelectables)) {\n return true;\n }\n }\n return false;\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n const imodelSelectables = new Map<string, Selectable[]>();\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || node.id === undefined) {\n return;\n }\n for (const [imodelKey, nodeSelectables] of groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)) {\n let selectablesList = imodelSelectables.get(imodelKey);\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables.set(imodelKey, selectablesList);\n }\n nodeSelectables.forEach((selectable) => selectablesList.push(selectable));\n }\n }\n imodelSelectables.forEach((selectables, imodelKey) => {\n const actionProps = { imodelKey, source, selectables, level: 0 };\n switch (changeType) {\n case \"add\":\n storage.addToSelection(actionProps);\n return;\n case \"remove\":\n storage.removeFromSelection(actionProps);\n return;\n case \"replace\":\n storage.replaceSelection(actionProps);\n return;\n }\n });\n },\n };\n}\n\nfunction groupNodeSelectablesByIModelKey(\n modelNode: TreeModelHierarchyNode,\n createSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]>,\n): Map<string, Selectable[]> {\n const hierarchyNode = modelNode.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);\n }\n if (HierarchyNode.isGroupingNode(hierarchyNode)) {\n const groupingNodeSelectables = new Map<string, Selectable[]>();\n groupIModelInstanceKeys(hierarchyNode.groupedInstanceKeys).forEach((instanceKeys, imodelKey) => {\n groupingNodeSelectables.set(imodelKey, [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {\n for (const key of instanceKeys) {\n yield key;\n }\n },\n },\n ]);\n });\n return groupingNodeSelectables;\n }\n assert(HierarchyNode.isGeneric(hierarchyNode));\n // note: generic nodes aren't associated with an imodel\n return new Map([[\"\", [createSelectableForGenericNode(hierarchyNode, modelNode.id)]]]);\n}\n\nfunction groupIModelInstanceKeys(instanceKeys: InstancesNodeKey[\"instanceKeys\"]) {\n return instanceKeys.reduce((imodelSelectables, key) => {\n const imodelKey = key.imodelKey ?? \"\";\n let selectablesList = imodelSelectables.get(imodelKey);\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables.set(imodelKey, selectablesList);\n }\n selectablesList.push(key);\n return imodelSelectables;\n }, new Map<string, InstanceKey[]>());\n}\n"],"mappings":";;;;;;;;AAoDA,SAAO4B,wBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAiC,MAAA,EAAAT,YAAAK,kBAAAK,kBAAAT,gCAAAU,OAAAJ;CAItC,MAAAN,iCAAAU,OAAAC,SAAAC,wCAAAF;CAEA,MAAA,CAAAG,SAAAC,cAA8BpC,SAA+BqC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AOyD;;AAEThF,QAAOC,cAAciF,UAAUR,cAAc,CAAC;AAE9C,QAAO,IAAIb,IAAI,CAAC,CAAC,IAAI,CAACxC,+BAA+BqD,eAAeD,UAAUpB,GAAG,CAAC,CAAC,CAAC,CAAC;;AAGvF,SAASwB,wBAAwBC,cAAgD;AAC/E,QAAOA,aAAaK,QAAQvB,mBAAmBrC,QAAQ;EACrD,MAAM+B,YAAY/B,IAAI+B,aAAa;EACnC,IAAIQ,kBAAkBF,kBAAkBG,IAAIT,UAAU;AACtD,MAAI,CAACQ,iBAAiB;AACpBA,qBAAkB,EAAE;AACpBF,qBAAkBI,IAAIV,WAAWQ,gBAAgB;;AAEnDA,kBAAgBK,KAAK5C,IAAI;AACzB,SAAOqC;oBACN,IAAIC,KAA4B,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utils.js","names":["HierarchyNodeKey","HierarchyNode","createNodeId","node","Pick","parentKeys","map","serializeNodeKey","key","join","convertObjectValuesToString","obj","Object","entries","value","String","sameNodes","lhs","rhs","compare","length","i","MAX_LIMIT_OVERRIDE","safeDispose","disposable","Symbol","dispose"],"sources":["../../../src/presentation-hierarchies-react/internal/Utils.ts"],"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 \"./DisposePolyfill.js\";\n\nimport { HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\n\nimport type { HierarchyNode } from \"@itwin/presentation-hierarchies\";\n\n/** @internal */\nexport function createNodeId(node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) {\n return [...node.parentKeys.map(serializeNodeKey), serializeNodeKey(node.key)].join(\";\");\n}\n\nfunction serializeNodeKey(key: HierarchyNodeKey): string {\n return convertObjectValuesToString(key);\n}\n\nfunction convertObjectValuesToString(obj: object): string {\n return Object.entries(obj)\n .map(([, value]) => {\n if (typeof value === \"object\") {\n return convertObjectValuesToString(value);\n }\n return String(value);\n })\n .join(\",\");\n}\n\n/** @internal */\nexport function sameNodes(lhs: HierarchyNode, rhs: HierarchyNode): boolean {\n if (HierarchyNodeKey.compare(lhs.key, rhs.key) !== 0) {\n return false;\n }\n\n if (lhs.parentKeys.length !== rhs.parentKeys.length) {\n return false;\n }\n\n for (let i = lhs.parentKeys.length - 1; i >= 0; --i) {\n if (HierarchyNodeKey.compare(lhs.parentKeys[i], rhs.parentKeys[i]) !== 0) {\n return false;\n }\n }\n return true;\n}\n\n/** @internal */\nexport const MAX_LIMIT_OVERRIDE = 10000;\n\n/**\n * A helper that disposes the given object, if it's disposable.\n *\n * The first option is to dispose using the deprecated `dispose` method if it exists on the object.\n * If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is\n * considered as non-disposable and nothing is done with it.\n *\n * @internal\n */\nexport function safeDispose(disposable: {} | { [Symbol.dispose]: () => void } | { dispose: () => void }) {\n if (\"dispose\" in disposable) {\n disposable.dispose();\n } else if (Symbol.dispose in disposable) {\n disposable[Symbol.dispose]();\n }\n}\n"],"mappings":";;;;;AAYA,SAAgBE,aAAaC,MAAiD;AAC5E,QAAO,CAAC,GAAGA,KAAKE,WAAWC,IAAIC,iBAAiB,EAAEA,iBAAiBJ,KAAKK,IAAI,CAAC,CAACC,KAAK,IAAI;;AAGzF,SAASF,iBAAiBC,KAA+B;AACvD,QAAOE,4BAA4BF,IAAI;;AAGzC,SAASE,4BAA4BC,KAAqB;AACxD,QAAOC,OAAOC,QAAQF,IAAI,CACvBL,KAAK,GAAGQ,WAAW;AAClB,MAAI,OAAOA,UAAU,SACnB,QAAOJ,4BAA4BI,MAAM;AAE3C,SAAOC,OAAOD,MAAM;GACpB,CACDL,KAAK,IAAI;;;AAId,SAAgBO,UAAUC,KAAoBC,KAA6B;AACzE,KAAIlB,iBAAiBmB,QAAQF,IAAIT,KAAKU,IAAIV,IAAI,KAAK,EACjD,QAAO;AAGT,KAAIS,IAAIZ,WAAWe,WAAWF,IAAIb,WAAWe,OAC3C,QAAO;AAGT,MAAK,IAAIC,IAAIJ,IAAIZ,WAAWe,SAAS,GAAGC,KAAK,GAAG,EAAEA,EAChD,KAAIrB,iBAAiBmB,QAAQF,IAAIZ,WAAWgB,IAAIH,IAAIb,WAAWgB,GAAG,KAAK,EACrE,QAAO;AAGX,QAAO;;;AAIT,MAAaC,qBAAqB;;;;;;;;;;AAWlC,SAAgBC,YAAYC,YAA6E;AACvG,KAAI,aAAaA,WACfA,YAAWE,SAAS;UACXD,OAAOC,WAAWF,WAC3BA,YAAWC,OAAOC,UAAU"}
@@ -19,9 +19,9 @@ interface ErrorItemRendererProps extends Pick<TreeRendererProps, "getHierarchyLe
19
19
  }
20
20
  /**
21
21
  * Renders StrataKit `<ErrorRegion.Item />` for all supported error types:
22
- * - `ResultSetTooLarge` - renders `LocalizedStrings.resultLimitExceeded` message with actions to increase limit or apply filtering
23
- * - `NoFilterMatches` - renders `LocalizedStrings.noFilteredChildren` message with action to change filter
24
- * - `ChildrenLoad` - renders `LocalizedStrings.failedToCreateHierarchy` message with action to retry loading
22
+ * - `ResultSetTooLarge` - renders `resultLimitExceeded` message with actions to increase limit or apply filtering
23
+ * - `NoFilterMatches` - renders `noFilteredChildren` message with action to change filter
24
+ * - `ChildrenLoad` - renders `failedToCreateHierarchy` message with action to retry loading
25
25
  * - `Unknown` - renders message set on error object.
26
26
  *
27
27
  * @alpha
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorItemRenderer.d.ts","names":[],"sources":["../../../src/presentation-hierarchies-react/stratakit/ErrorItemRenderer.tsx"],"mappings":";;;;;;;UAgBiB,sBAAA,SAA+B,IAAA,CAAK,iBAAA;EAApC;EAEf,SAAA,EAAW,UAAA,QAAkB,aAAA;;EAE7B,UAAA,GAAa,OAAA;IAAW,YAAA;EAAA;EAEE;EAA1B,YAAA,GAAe,SAAA,EAAW,QAAA;EANoB;EAQ9C,oBAAA,IAAwB,qBAAA,EAAuB,qBAAA;AAAA;;;;;;;;;;iBAYjC,iBAAA,CAAA;EACd,SAAA;EACA,wBAAA;EACA,oBAAA;EACA,UAAA;EACA;AAAA,GACC,sBAAA,GAAyB,GAAA,CAAI,OAAA"}
@@ -1,5 +1,5 @@
1
1
  import { MAX_LIMIT_OVERRIDE } from "../internal/Utils.js";
2
- import { useLocalizationContext } from "./LocalizationContext.js";
2
+ import { useTranslation } from "./LocalizationContext.js";
3
3
  import { c } from "react-compiler-runtime";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
5
5
  import { unstable_ErrorRegion } from "@stratakit/structures";
@@ -8,17 +8,17 @@ import { Anchor, Text } from "@stratakit/bricks";
8
8
  //#region src/presentation-hierarchies-react/stratakit/ErrorItemRenderer.tsx
9
9
  /**
10
10
  * Renders StrataKit `<ErrorRegion.Item />` for all supported error types:
11
- * - `ResultSetTooLarge` - renders `LocalizedStrings.resultLimitExceeded` message with actions to increase limit or apply filtering
12
- * - `NoFilterMatches` - renders `LocalizedStrings.noFilteredChildren` message with action to change filter
13
- * - `ChildrenLoad` - renders `LocalizedStrings.failedToCreateHierarchy` message with action to retry loading
11
+ * - `ResultSetTooLarge` - renders `resultLimitExceeded` message with actions to increase limit or apply filtering
12
+ * - `NoFilterMatches` - renders `noFilteredChildren` message with action to change filter
13
+ * - `ChildrenLoad` - renders `failedToCreateHierarchy` message with action to retry loading
14
14
  * - `Unknown` - renders message set on error object.
15
15
  *
16
16
  * @alpha
17
17
  */
18
18
  function ErrorItemRenderer(t0) {
19
- const $ = c(73);
19
+ const $ = c(83);
20
20
  const { errorNode, getHierarchyLevelDetails, filterHierarchyLevel, reloadTree, scrollToNode } = t0;
21
- const { localizedStrings } = useLocalizationContext();
21
+ const translate = useTranslation();
22
22
  if (errorNode.error.type === "ResultSetTooLarge") {
23
23
  const limit = errorNode.error.resultSetSizeLimit;
24
24
  let t1;
@@ -38,9 +38,9 @@ function ErrorItemRenderer(t0) {
38
38
  $[4] = t2;
39
39
  } else t2 = $[4];
40
40
  let t3;
41
- if ($[5] !== localizedStrings.increaseHierarchyLimit) {
42
- t3 = localizedStrings.increaseHierarchyLimit.replace("{{limit}}", MAX_LIMIT_OVERRIDE.toString());
43
- $[5] = localizedStrings.increaseHierarchyLimit;
41
+ if ($[5] !== translate) {
42
+ t3 = translate("increaseHierarchyLimit").replace("{{limit}}", MAX_LIMIT_OVERRIDE.toString());
43
+ $[5] = translate;
44
44
  $[6] = t3;
45
45
  } else t3 = $[6];
46
46
  let t4;
@@ -73,167 +73,197 @@ function ErrorItemRenderer(t0) {
73
73
  $[16] = t6;
74
74
  } else t6 = $[16];
75
75
  let t7;
76
- if ($[17] !== errorNode.isFilterable || $[18] !== filterHierarchyLevel) {
77
- t7 = () => !!filterHierarchyLevel && !!errorNode.isFilterable;
78
- $[17] = errorNode.isFilterable;
79
- $[18] = filterHierarchyLevel;
80
- $[19] = t7;
81
- } else t7 = $[19];
76
+ if ($[17] !== translate) {
77
+ t7 = translate("increaseHierarchyLimitWithFiltering");
78
+ $[17] = translate;
79
+ $[18] = t7;
80
+ } else t7 = $[18];
82
81
  let t8;
83
- if ($[20] !== localizedStrings.increaseHierarchyLimitWithFiltering || $[21] !== t6 || $[22] !== t7) {
84
- t8 = {
82
+ if ($[19] !== errorNode.isFilterable || $[20] !== filterHierarchyLevel) {
83
+ t8 = () => !!filterHierarchyLevel && !!errorNode.isFilterable;
84
+ $[19] = errorNode.isFilterable;
85
+ $[20] = filterHierarchyLevel;
86
+ $[21] = t8;
87
+ } else t8 = $[21];
88
+ let t9;
89
+ if ($[22] !== t6 || $[23] !== t7 || $[24] !== t8) {
90
+ t9 = {
85
91
  action: t6,
86
- label: localizedStrings.increaseHierarchyLimitWithFiltering,
87
- condition: t7
92
+ label: t7,
93
+ condition: t8
88
94
  };
89
- $[20] = localizedStrings.increaseHierarchyLimitWithFiltering;
90
- $[21] = t6;
91
- $[22] = t7;
92
- $[23] = t8;
93
- } else t8 = $[23];
94
- let t9;
95
- if ($[24] !== t5 || $[25] !== t8) {
96
- t9 = [t5, t8];
97
- $[24] = t5;
98
- $[25] = t8;
99
- $[26] = t9;
100
- } else t9 = $[26];
95
+ $[22] = t6;
96
+ $[23] = t7;
97
+ $[24] = t8;
98
+ $[25] = t9;
99
+ } else t9 = $[25];
101
100
  let t10;
102
- if ($[27] !== limit || $[28] !== localizedStrings.resultLimitExceeded) {
103
- t10 = localizedStrings.resultLimitExceeded.replace("{{limit}}", limit.toString());
104
- $[27] = limit;
105
- $[28] = localizedStrings.resultLimitExceeded;
106
- $[29] = t10;
107
- } else t10 = $[29];
101
+ if ($[26] !== t5 || $[27] !== t9) {
102
+ t10 = [t5, t9];
103
+ $[26] = t5;
104
+ $[27] = t9;
105
+ $[28] = t10;
106
+ } else t10 = $[28];
108
107
  let t11;
109
- if ($[30] !== errorNode || $[31] !== scrollToNode) {
110
- t11 = () => scrollToNode(errorNode);
111
- $[30] = errorNode;
112
- $[31] = scrollToNode;
113
- $[32] = t11;
114
- } else t11 = $[32];
108
+ if ($[29] !== limit || $[30] !== translate) {
109
+ t11 = translate("resultLimitExceeded").replace("{{limit}}", limit.toString());
110
+ $[29] = limit;
111
+ $[30] = translate;
112
+ $[31] = t11;
113
+ } else t11 = $[31];
115
114
  let t12;
116
- if ($[33] !== errorNode || $[34] !== t10 || $[35] !== t11 || $[36] !== t9) {
117
- t12 = /* @__PURE__ */ jsx(ErrorItemContainer, {
115
+ if ($[32] !== errorNode || $[33] !== scrollToNode) {
116
+ t12 = () => scrollToNode(errorNode);
117
+ $[32] = errorNode;
118
+ $[33] = scrollToNode;
119
+ $[34] = t12;
120
+ } else t12 = $[34];
121
+ let t13;
122
+ if ($[35] !== errorNode || $[36] !== t10 || $[37] !== t11 || $[38] !== t12) {
123
+ t13 = /* @__PURE__ */ jsx(ErrorItemContainer, {
118
124
  errorNode,
119
- actions: t9,
120
- message: t10,
121
- scrollToElement: t11
125
+ actions: t10,
126
+ message: t11,
127
+ scrollToElement: t12
122
128
  });
123
- $[33] = errorNode;
124
- $[34] = t10;
125
- $[35] = t11;
126
- $[36] = t9;
127
- $[37] = t12;
128
- } else t12 = $[37];
129
- return t12;
129
+ $[35] = errorNode;
130
+ $[36] = t10;
131
+ $[37] = t11;
132
+ $[38] = t12;
133
+ $[39] = t13;
134
+ } else t13 = $[39];
135
+ return t13;
130
136
  }
131
137
  if (errorNode.error.type === "NoFilterMatches") {
132
138
  let t1;
133
- if ($[38] !== errorNode.id || $[39] !== filterHierarchyLevel || $[40] !== getHierarchyLevelDetails) {
139
+ if ($[40] !== errorNode.id || $[41] !== filterHierarchyLevel || $[42] !== getHierarchyLevelDetails) {
134
140
  t1 = () => {
135
141
  const hierarchyLevelDetails_0 = getHierarchyLevelDetails(errorNode.id);
136
142
  hierarchyLevelDetails_0 && filterHierarchyLevel?.(hierarchyLevelDetails_0);
137
143
  };
138
- $[38] = errorNode.id;
139
- $[39] = filterHierarchyLevel;
140
- $[40] = getHierarchyLevelDetails;
141
- $[41] = t1;
142
- } else t1 = $[41];
144
+ $[40] = errorNode.id;
145
+ $[41] = filterHierarchyLevel;
146
+ $[42] = getHierarchyLevelDetails;
147
+ $[43] = t1;
148
+ } else t1 = $[43];
143
149
  let t2;
144
- if ($[42] !== localizedStrings.noFilteredChildrenChangeFilter || $[43] !== t1) {
145
- t2 = [{
150
+ if ($[44] !== translate) {
151
+ t2 = translate("noFilteredChildrenChangeFilter");
152
+ $[44] = translate;
153
+ $[45] = t2;
154
+ } else t2 = $[45];
155
+ let t3;
156
+ if ($[46] !== t1 || $[47] !== t2) {
157
+ t3 = [{
146
158
  action: t1,
147
- label: localizedStrings.noFilteredChildrenChangeFilter,
159
+ label: t2,
148
160
  condition: _temp
149
161
  }];
150
- $[42] = localizedStrings.noFilteredChildrenChangeFilter;
151
- $[43] = t1;
152
- $[44] = t2;
153
- } else t2 = $[44];
154
- let t3;
155
- if ($[45] !== errorNode || $[46] !== scrollToNode) {
156
- t3 = () => scrollToNode(errorNode);
157
- $[45] = errorNode;
158
- $[46] = scrollToNode;
159
- $[47] = t3;
160
- } else t3 = $[47];
162
+ $[46] = t1;
163
+ $[47] = t2;
164
+ $[48] = t3;
165
+ } else t3 = $[48];
161
166
  let t4;
162
- if ($[48] !== errorNode || $[49] !== localizedStrings.noFilteredChildren || $[50] !== t2 || $[51] !== t3) {
163
- t4 = /* @__PURE__ */ jsx(ErrorItemContainer, {
167
+ if ($[49] !== translate) {
168
+ t4 = translate("noFilteredChildren");
169
+ $[49] = translate;
170
+ $[50] = t4;
171
+ } else t4 = $[50];
172
+ let t5;
173
+ if ($[51] !== errorNode || $[52] !== scrollToNode) {
174
+ t5 = () => scrollToNode(errorNode);
175
+ $[51] = errorNode;
176
+ $[52] = scrollToNode;
177
+ $[53] = t5;
178
+ } else t5 = $[53];
179
+ let t6;
180
+ if ($[54] !== errorNode || $[55] !== t3 || $[56] !== t4 || $[57] !== t5) {
181
+ t6 = /* @__PURE__ */ jsx(ErrorItemContainer, {
164
182
  errorNode,
165
- actions: t2,
166
- message: localizedStrings.noFilteredChildren,
167
- scrollToElement: t3
183
+ actions: t3,
184
+ message: t4,
185
+ scrollToElement: t5
168
186
  });
169
- $[48] = errorNode;
170
- $[49] = localizedStrings.noFilteredChildren;
171
- $[50] = t2;
172
- $[51] = t3;
173
- $[52] = t4;
174
- } else t4 = $[52];
175
- return t4;
187
+ $[54] = errorNode;
188
+ $[55] = t3;
189
+ $[56] = t4;
190
+ $[57] = t5;
191
+ $[58] = t6;
192
+ } else t6 = $[58];
193
+ return t6;
176
194
  }
177
195
  if (errorNode.error.type === "ChildrenLoad") {
178
196
  let t1;
179
- if ($[53] !== errorNode.id || $[54] !== reloadTree) {
197
+ if ($[59] !== errorNode.id || $[60] !== reloadTree) {
180
198
  t1 = () => reloadTree({ parentNodeId: errorNode.id });
181
- $[53] = errorNode.id;
182
- $[54] = reloadTree;
183
- $[55] = t1;
184
- } else t1 = $[55];
199
+ $[59] = errorNode.id;
200
+ $[60] = reloadTree;
201
+ $[61] = t1;
202
+ } else t1 = $[61];
185
203
  let t2;
186
- if ($[56] !== localizedStrings.retry || $[57] !== t1) {
187
- t2 = [{
204
+ if ($[62] !== translate) {
205
+ t2 = translate("retry");
206
+ $[62] = translate;
207
+ $[63] = t2;
208
+ } else t2 = $[63];
209
+ let t3;
210
+ if ($[64] !== t1 || $[65] !== t2) {
211
+ t3 = [{
188
212
  action: t1,
189
- label: localizedStrings.retry,
213
+ label: t2,
190
214
  condition: _temp2
191
215
  }];
192
- $[56] = localizedStrings.retry;
193
- $[57] = t1;
194
- $[58] = t2;
195
- } else t2 = $[58];
196
- let t3;
197
- if ($[59] !== errorNode || $[60] !== scrollToNode) {
198
- t3 = () => scrollToNode(errorNode);
199
- $[59] = errorNode;
200
- $[60] = scrollToNode;
201
- $[61] = t3;
202
- } else t3 = $[61];
216
+ $[64] = t1;
217
+ $[65] = t2;
218
+ $[66] = t3;
219
+ } else t3 = $[66];
203
220
  let t4;
204
- if ($[62] !== errorNode || $[63] !== localizedStrings.failedToCreateHierarchy || $[64] !== t2 || $[65] !== t3) {
205
- t4 = /* @__PURE__ */ jsx(ErrorItemContainer, {
221
+ if ($[67] !== translate) {
222
+ t4 = translate("failedToCreateHierarchy");
223
+ $[67] = translate;
224
+ $[68] = t4;
225
+ } else t4 = $[68];
226
+ let t5;
227
+ if ($[69] !== errorNode || $[70] !== scrollToNode) {
228
+ t5 = () => scrollToNode(errorNode);
229
+ $[69] = errorNode;
230
+ $[70] = scrollToNode;
231
+ $[71] = t5;
232
+ } else t5 = $[71];
233
+ let t6;
234
+ if ($[72] !== errorNode || $[73] !== t3 || $[74] !== t4 || $[75] !== t5) {
235
+ t6 = /* @__PURE__ */ jsx(ErrorItemContainer, {
206
236
  errorNode,
207
- actions: t2,
208
- message: localizedStrings.failedToCreateHierarchy,
209
- scrollToElement: t3
237
+ actions: t3,
238
+ message: t4,
239
+ scrollToElement: t5
210
240
  });
211
- $[62] = errorNode;
212
- $[63] = localizedStrings.failedToCreateHierarchy;
213
- $[64] = t2;
214
- $[65] = t3;
215
- $[66] = t4;
216
- } else t4 = $[66];
217
- return t4;
241
+ $[72] = errorNode;
242
+ $[73] = t3;
243
+ $[74] = t4;
244
+ $[75] = t5;
245
+ $[76] = t6;
246
+ } else t6 = $[76];
247
+ return t6;
218
248
  }
219
249
  let t1;
220
- if ($[67] !== errorNode || $[68] !== scrollToNode) {
250
+ if ($[77] !== errorNode || $[78] !== scrollToNode) {
221
251
  t1 = () => scrollToNode(errorNode);
222
- $[67] = errorNode;
223
- $[68] = scrollToNode;
224
- $[69] = t1;
225
- } else t1 = $[69];
252
+ $[77] = errorNode;
253
+ $[78] = scrollToNode;
254
+ $[79] = t1;
255
+ } else t1 = $[79];
226
256
  let t2;
227
- if ($[70] !== errorNode || $[71] !== t1) {
257
+ if ($[80] !== errorNode || $[81] !== t1) {
228
258
  t2 = /* @__PURE__ */ jsx(ErrorItemContainer, {
229
259
  errorNode,
230
260
  message: errorNode.error.message,
231
261
  scrollToElement: t1
232
262
  });
233
- $[70] = errorNode;
234
- $[71] = t1;
235
- $[72] = t2;
236
- } else t2 = $[72];
263
+ $[80] = errorNode;
264
+ $[81] = t1;
265
+ $[82] = t2;
266
+ } else t2 = $[82];
237
267
  return t2;
238
268
  }
239
269
  function _temp2() {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorItemRenderer.js","names":["Anchor","Text","unstable_ErrorRegion","ErrorRegion","MAX_LIMIT_OVERRIDE","useTranslation","JSX","HierarchyLevelDetails","TreeRendererProps","TreeNode","useErrorNodes","ErrorItemRendererProps","Pick","errorNode","ReturnType","reloadTree","options","parentNodeId","scrollToNode","filterHierarchyLevel","hierarchyLevelDetails","ErrorItemRenderer","t0","$","_c","getHierarchyLevelDetails","translate","error","type","limit","resultSetSizeLimit","t1","id","setSizeLimit","onOverrideLimit","t2","t3","replace","toString","t4","t5","action","label","condition","t6","t7","t8","isFilterable","t9","t10","t11","t12","t13","hierarchyLevelDetails_0","_temp","_temp2","message","ErrorItemContainerProps","actions","MessageWithLinkProps","ErrorItemContainer","scrollToElement","filter","_temp3","map","_temp4","linkLabel","MessageWithLink","split","splitMessage","Symbol","for","display","whiteSpace","flexWrap"],"sources":["../../../src/presentation-hierarchies-react/stratakit/ErrorItemRenderer.tsx"],"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 { Anchor, Text } from \"@stratakit/bricks\";\nimport { unstable_ErrorRegion as ErrorRegion } from \"@stratakit/structures\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { useTranslation } from \"./LocalizationContext.js\";\n\nimport type { JSX } from \"react\";\nimport type { HierarchyLevelDetails, TreeRendererProps } from \"../Renderers.js\";\nimport type { TreeNode } from \"../TreeNode.js\";\nimport type { useErrorNodes } from \"./FlatTreeNode.js\";\n\n/** @alpha */\nexport interface ErrorItemRendererProps extends Pick<TreeRendererProps, \"getHierarchyLevelDetails\"> {\n /** A node containing an error. */\n errorNode: ReturnType<typeof useErrorNodes>[number];\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree: (options: { parentNodeId: string | undefined }) => void;\n /** A callback to scroll to the node associated with the error. */\n scrollToNode: (errorNode: TreeNode) => void;\n /** A callback to initiate filtering of the given hierarchy level. */\n filterHierarchyLevel?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n}\n\n/**\n * Renders StrataKit `<ErrorRegion.Item />` for all supported error types:\n * - `ResultSetTooLarge` - renders `resultLimitExceeded` message with actions to increase limit or apply filtering\n * - `NoFilterMatches` - renders `noFilteredChildren` message with action to change filter\n * - `ChildrenLoad` - renders `failedToCreateHierarchy` message with action to retry loading\n * - `Unknown` - renders message set on error object.\n *\n * @alpha\n */\nexport function ErrorItemRenderer({\n errorNode,\n getHierarchyLevelDetails,\n filterHierarchyLevel,\n reloadTree,\n scrollToNode,\n}: ErrorItemRendererProps): JSX.Element {\n const translate = useTranslation();\n\n if (errorNode.error.type === \"ResultSetTooLarge\") {\n const limit = errorNode.error.resultSetSizeLimit;\n const onOverrideLimit = () => getHierarchyLevelDetails(errorNode.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE);\n return (\n <ErrorItemContainer\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n onOverrideLimit();\n },\n label: translate(\"increaseHierarchyLimit\").replace(\"{{limit}}\", MAX_LIMIT_OVERRIDE.toString()),\n condition: () => limit < MAX_LIMIT_OVERRIDE,\n },\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails(errorNode.id);\n hierarchyLevelDetails && filterHierarchyLevel?.(hierarchyLevelDetails);\n },\n label: translate(\"increaseHierarchyLimitWithFiltering\"),\n condition: () => !!filterHierarchyLevel && !!errorNode.isFilterable,\n },\n ]}\n message={translate(\"resultLimitExceeded\").replace(\"{{limit}}\", limit.toString())}\n scrollToElement={() => scrollToNode(errorNode)}\n />\n );\n }\n if (errorNode.error.type === \"NoFilterMatches\") {\n return (\n <ErrorItemContainer\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails(errorNode.id);\n hierarchyLevelDetails && filterHierarchyLevel?.(hierarchyLevelDetails);\n },\n label: translate(\"noFilteredChildrenChangeFilter\"),\n condition: () => true,\n },\n ]}\n message={translate(\"noFilteredChildren\")}\n scrollToElement={() => scrollToNode(errorNode)}\n />\n );\n }\n if (errorNode.error.type === \"ChildrenLoad\") {\n return (\n <ErrorItemContainer\n errorNode={errorNode}\n actions={[\n {\n action: () => reloadTree({ parentNodeId: errorNode.id }),\n label: translate(\"retry\"),\n condition: () => true,\n },\n ]}\n message={translate(\"failedToCreateHierarchy\")}\n scrollToElement={() => scrollToNode(errorNode)}\n />\n );\n }\n\n return <ErrorItemContainer errorNode={errorNode} message={errorNode.error.message} scrollToElement={() => scrollToNode(errorNode)} />;\n}\n\ntype ErrorItemContainerProps = {\n errorNode: TreeNode;\n message: string;\n actions?: { action: () => void; label: string; condition: () => boolean }[];\n} & Pick<MessageWithLinkProps, \"scrollToElement\">;\n\nfunction ErrorItemContainer({ errorNode, message, actions, scrollToElement }: ErrorItemContainerProps) {\n return (\n <ErrorRegion.Item\n message={<MessageWithLink linkLabel={errorNode.label} scrollToElement={scrollToElement} message={message} />}\n messageId={errorNode.id}\n actions={actions\n ?.filter(({ condition }) => condition())\n .map(({ label, action }) => (\n <Text key={label} variant=\"body-sm\">\n <Anchor onClick={action} render={<button />}>\n {label}\n </Anchor>\n </Text>\n ))}\n />\n );\n}\n\ninterface MessageWithLinkProps {\n scrollToElement: () => void;\n message: string;\n linkLabel?: string;\n}\n\nfunction MessageWithLink({ linkLabel, scrollToElement, message }: MessageWithLinkProps) {\n const splitMessage = message.split(\"{{node}}\", 2);\n return (\n <div style={{ display: \"flex\", whiteSpace: \"pre\", flexWrap: \"wrap\" }}>\n {splitMessage[0]}\n <Anchor onClick={scrollToElement} render={<button />}>\n {linkLabel}\n </Anchor>\n {splitMessage[1] ? splitMessage[1] : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoCA,SAAOqB,kBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,GAAA;CAA2B,MAAA,EAAAX,WAAAY,0BAAAN,sBAAAJ,YAAAG,iBAAAI;CAOhC,MAAAI,YAAkBrB,gBAAgB;AAElC,KAAIQ,UAASc,MAAMC,SAAU,qBAAmB;EAC9C,MAAAC,QAAchB,UAASc,MAAMG;EAAoB,IAAAC;AAAA,MAAAR,EAAA,OAAAV,UAAAmB,MAAAT,EAAA,OAAAE,0BAAA;AACzBM,cAAMN,yBAAyBZ,UAASmB,GAAkB,EAAAC,aAAC7B,mBAAmB;AAAAmB,KAAA,KAAAV,UAAAmB;AAAAT,KAAA,KAAAE;AAAAF,KAAA,KAAAQ;QAAAA,MAAAR,EAAA;EAAtG,MAAAW,kBAAwBH;EAA+E,IAAAI;AAAA,MAAAZ,EA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