@itwin/presentation-hierarchies-react 2.0.0-alpha.61 → 2.0.0-alpha.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @itwin/presentation-hierarchies-react
2
2
 
3
+ ## 2.0.0-alpha.62
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1304](https://github.com/iTwin/presentation/pull/1304): Remove `@stratakit/bricks` and `@stratakit/structures` from peer dependencies list.
8
+
9
+ Only `@stratakit/foundations` and `@stratakit/icons` are required as peer dependencies when using StrataKit components, the rest of `@stratakit` packages can be used as direct dependencies.
10
+
11
+ - Updated dependencies:
12
+ - @itwin/presentation-hierarchies@2.0.0-alpha.15
13
+ - @itwin/presentation-shared@2.0.0-alpha.10
14
+ - @itwin/unified-selection@1.7.1-alpha.0
15
+
3
16
  ## 2.0.0-alpha.61
4
17
 
5
18
  ### Minor Changes
@@ -958,6 +971,22 @@
958
971
 
959
972
  - [#847](https://github.com/iTwin/presentation/pull/847): Moving tree rendering components to a new design systems.
960
973
 
974
+ ## 1.10.1
975
+
976
+ ### Patch Changes
977
+
978
+ - [#1286](https://github.com/iTwin/presentation/pull/1286): Bump dependencies.
979
+ - Updated dependencies:
980
+ - @itwin/presentation-hierarchies@1.7.12
981
+ - @itwin/presentation-shared@1.2.11
982
+ - @itwin/unified-selection@1.7.0
983
+
984
+ ## 1.10.0
985
+
986
+ ### Minor Changes
987
+
988
+ - [#1258](https://github.com/iTwin/presentation/pull/1258): Introduced new import paths: `@itwin/presentation-hierarchies-react/core` and `@itwin/presentation-hierarchies-react/itwinui`. They should allow to use this package without `@itwin/itwinui-react` dependency.
989
+
961
990
  ## 1.9.13
962
991
 
963
992
  ### Patch Changes
package/README.md CHANGED
@@ -64,11 +64,7 @@ The hook takes 2 required properties:
64
64
  import { IModelConnection } from "@itwin/core-frontend";
65
65
  import { createCachingECClassHierarchyInspector } from "@itwin/presentation-shared";
66
66
  import { createECSchemaProvider, createECSqlQueryExecutor, createIModelKey } from "@itwin/presentation-core-interop";
67
- import {
68
- createLimitingECSqlQueryExecutor,
69
- createNodesQueryClauseFactory,
70
- HierarchyDefinition,
71
- } from "@itwin/presentation-hierarchies";
67
+ import { createLimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
72
68
 
73
69
  function createIModelAccess(imodel: IModelConnection) {
74
70
  const schemaProvider = createECSchemaProvider(imodel.schemaContext);
@@ -105,15 +101,9 @@ The component renders a virtualized tree using the `Tree` component from `@strat
105
101
 
106
102
  ```tsx
107
103
  import { IModelConnection } from "@itwin/core-frontend";
108
- import { createCachingECClassHierarchyInspector } from "@itwin/presentation-shared";
104
+ import { createCachingECClassHierarchyInspector, Props } from "@itwin/presentation-shared";
109
105
  import { createECSchemaProvider, createECSqlQueryExecutor, createIModelKey } from "@itwin/presentation-core-interop";
110
- import {
111
- createLimitingECSqlQueryExecutor,
112
- createNodesQueryClauseFactory,
113
- HierarchyDefinition,
114
- } from "@itwin/presentation-hierarchies";
115
-
116
- import { createBisInstanceLabelSelectClauseFactory, Props } from "@itwin/presentation-shared";
106
+ import { createLimitingECSqlQueryExecutor, HierarchyDefinition } from "@itwin/presentation-hierarchies";
117
107
 
118
108
  import { useIModelUnifiedSelectionTree } from "@itwin/presentation-hierarchies-react";
119
109
  import { StrataKitTreeRenderer, StrataKitRootErrorRenderer } from "@itwin/presentation-hierarchies-react/stratakit";
@@ -154,25 +144,19 @@ type IModelAccess = Props<typeof useIModelUnifiedSelectionTree>["imodelAccess"];
154
144
 
155
145
  // The hierarchy definition describes the hierarchy using ECSQL queries; here it just returns all `BisCore.PhysicalModel` instances
156
146
  function getHierarchyDefinition({ imodelAccess }: { imodelAccess: IModelAccess }): HierarchyDefinition {
157
- // Create a factory for building labels SELECT query clauses according to BIS conventions
158
- const labelsQueryFactory = createBisInstanceLabelSelectClauseFactory({ classHierarchyInspector: imodelAccess });
159
- // Create a factory for building nodes SELECT query clauses in a format understood by the provider
160
- const nodesQueryFactory = createNodesQueryClauseFactory({
161
- imodelAccess,
162
- instanceLabelSelectClauseFactory: labelsQueryFactory,
163
- });
164
147
  return {
165
- defineHierarchyLevel: async () => [
148
+ // The `instanceLabelSelectClauseFactory` and `nodeSelectClauseFactory` are provided automatically by the hierarchy provider
149
+ defineHierarchyLevel: async ({ instanceLabelSelectClauseFactory, nodeSelectClauseFactory }) => [
166
150
  {
167
151
  fullClassName: "BisCore.PhysicalModel",
168
152
  query: {
169
153
  ecsql: `
170
154
  SELECT
171
- ${await nodesQueryFactory.createSelectClause({
155
+ ${await nodeSelectClauseFactory.createSelectClause({
172
156
  ecClassId: { selector: "this.ECClassId" },
173
157
  ecInstanceId: { selector: "this.ECInstanceId" },
174
158
  nodeLabel: {
175
- selector: await labelsQueryFactory.createSelectClause({
159
+ selector: await instanceLabelSelectClauseFactory.createSelectClause({
176
160
  classAlias: "this",
177
161
  className: "BisCore.PhysicalModel",
178
162
  }),
@@ -212,7 +212,6 @@ function useTreeInternal({ getHierarchyProvider, getSearchPaths, onPerformanceMe
212
212
  const isNodeSelected = useCallback((nodeId_2) => TreeModel.isNodeSelected(state.model, nodeId_2), [state]);
213
213
  const setFormatter = useCallback((formatter) => {
214
214
  currentFormatter.current = formatter;
215
- /* c8 ignore next 3 */
216
215
  if (!hierarchyProvider) return;
217
216
  hierarchyProvider.setFormatter(formatter);
218
217
  }, [hierarchyProvider]);
@@ -1 +1 @@
1
- {"version":3,"file":"UseTree.js","names":["useCallback","useEffect","useMemo","useRef","useState","HierarchyNode","TreeActions","TreeModel","useUnifiedTreeSelection","safeDispose","useLatest","GenericInstanceFilter","HierarchyProvider","HierarchySearchTree","IPrimitiveValueFormatter","TreeModelHierarchyNode","TreeModelRootNode","UseUnifiedTreeSelectionProps","RootErrorRendererProps","TreeRendererProps","ErrorInfo","TreeNode","SelectionChangeType","useTree","props","$","_c","t0","useTreeInternal","rest","getTreeModelNode","_","t1","useUnifiedSelectionTree","createSelectableForGenericNode","selectionStorage","sourceName","t2","selectionProps","rootErrorRendererProps","undefined","treeRendererProps","rootNodes","t3","t4","UseTreeProps","getHierarchyProvider","getSearchPaths","abortSignal","AbortSignal","Promise","onPerformanceMeasured","action","duration","onHierarchyLimitExceeded","parentId","filter","limit","onHierarchyLoadError","type","error","getTreeNodeErrors","node","UseTreeResult","isReloading","getNode","nodeId","setFormatter","formatter","RendererProps","TreeState","model","Array","state","setState","idToNode","Map","parentChildMap","rootNode","id","nodeData","onPerformanceMeasuredRef","onHierarchyLimitExceededRef","onHierarchyLoadErrorRef","getTreeNodeErrorsRef","actions","get","generateTreeStructure","current","actionType","currentFormatter","hierarchyProvider","setHierarchyProvider","provider","removeHierarchyChangedListener","hierarchyChanged","addListener","hierarchyChangeArgs","shouldDiscardState","searchChange","newSearch","reloadTree","reset","isSearching","setIsSearching","disposed","controller","AbortController","setHierarchySearch","paths","signal","abort","createTreeNode","expandNode","isExpanded","options","selectNodes","nodeIds","changeType","isNodeSelected","getHierarchyLevelDetails","hierarchyNode","isGroupingNode","getInstanceKeysIterator","getNodeInstanceKeys","parentNode","instanceFilter","hierarchyLevelSizeLimit","setInstanceFilter","sizeLimit","hierarchyLimit","setSizeLimit","value","setHierarchyLimit","renderProps","isLoading","parentNodeId","currentChildren","map","childId","modelNode","allErrors","children","label","isFilterable","supportsFiltering","isFiltered","errors"],"sources":["../../src/presentation-hierarchies-react/UseTree.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 { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { TreeModel } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { useLatest } from \"./Utils.js\";\n\nimport type { GenericInstanceFilter, HierarchyProvider, HierarchySearchTree } from \"@itwin/presentation-hierarchies\";\nimport type { IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport type { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport type { RootErrorRendererProps, TreeRendererProps } from \"./Renderers.js\";\nimport type { ErrorInfo, TreeNode } from \"./TreeNode.js\";\nimport type { SelectionChangeType } from \"./UseSelectionHandler.js\";\n\n/**\n * A React hook that creates state for a tree component.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({\n sourceName,\n selectionStorage,\n createSelectableForGenericNode,\n ...props\n}: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n const selectionProps = useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n createSelectableForGenericNode,\n });\n if (rest.rootErrorRendererProps === undefined && rest.treeRendererProps?.rootNodes) {\n return { ...rest, treeRendererProps: { ...rest.treeRendererProps, ...selectionProps } };\n }\n return rest;\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to search nodes. */\n getSearchPaths?: ({ abortSignal }: { abortSignal: AbortSignal }) => Promise<HierarchySearchTree[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: {\n parentId?: string;\n filter?: GenericInstanceFilter;\n limit?: number | \"unbounded\";\n }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n /**\n * Callback to set custom TreeNode errors.\n * Errors returned from this callback are combined with internal errors when populating `TreeNode.errors`.\n */\n getTreeNodeErrors?: (node: HierarchyNode) => ErrorInfo[];\n}\n\n/** @public */\nexport type UseTreeResult = {\n /**\n * Specifies whether tree is reloading or not. It is set to `false` when initial tree load is in progress to check if\n * or tree is reloading.\n */\n isReloading: boolean;\n /**\n * Get a tree node by id\n */\n getNode: (nodeId: string) => TreeNode | undefined;\n /**\n * Sets a formatter for the primitive values that are displayed in the hierarchy.\n */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n} & RendererProps;\n\n/**.\n * @alpha\n */\ntype RendererProps =\n | {\n /**\n * An object containing information used to render root error handling UI.\n * Use in combination with `RootErrorRenderer` or your custom implementation.\n * Defined when root nodes fail to load.\n */\n rootErrorRendererProps: RootErrorRendererProps;\n }\n | {\n /** Is undefined when rootNodes were successfully loaded or are in initial loading process. */\n rootErrorRendererProps: undefined;\n /**\n * An object containing information used to render tree.\n * Use with `TreeRenderer` or your custom implementation.\n * Is undefined on initial loading process.\n */\n treeRendererProps?: TreeRendererProps;\n };\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<TreeNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getSearchPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n getTreeNodeErrors,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelHierarchyNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n const getTreeNodeErrorsRef = useLatest(getTreeNodeErrors);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes =\n model.parentChildMap.get(undefined) !== undefined\n ? generateTreeStructure(undefined, model, getTreeNodeErrorsRef.current)\n : undefined;\n setState({ model, rootNodes });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs.searchChange?.newSearch !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isSearching, setIsSearching] = useState(false);\n useEffect(() => {\n let disposed = false as boolean;\n const controller = new AbortController();\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getSearchPaths) {\n hierarchyProvider.setHierarchySearch(undefined);\n // reload tree in case hierarchy provider does not use hierarchy search to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsSearching(false);\n return;\n }\n\n setIsSearching(true);\n let paths: HierarchySearchTree[] | undefined;\n try {\n paths = await getSearchPaths({ abortSignal: controller.signal });\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchySearch(paths ? { paths } : undefined);\n setIsSearching(false);\n }\n }\n })();\n return () => {\n controller.abort();\n disposed = true;\n };\n }, [hierarchyProvider, getSearchPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelHierarchyNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): TreeNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || node.id === undefined) {\n return undefined;\n }\n return createTreeNode(node, state.model, getTreeNodeErrorsRef.current);\n },\n [actions, getTreeNodeErrorsRef, state.model],\n );\n\n const expandNode = useCallback<TreeRendererProps[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<TreeRendererProps[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<TreeRendererProps[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<TreeRendererProps[\"isNodeSelected\"]>(\n (nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId),\n [state],\n );\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<TreeRendererProps[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n const renderProps: RendererProps = useMemo(() => {\n if (state.model.rootNode.error) {\n return { rootErrorRendererProps: { error: state.model.rootNode.error, reloadTree, getHierarchyLevelDetails } };\n }\n return {\n rootErrorRendererProps: undefined,\n treeRendererProps: state.rootNodes\n ? { rootNodes: state.rootNodes, expandNode, selectNodes, isNodeSelected, reloadTree, getHierarchyLevelDetails }\n : undefined,\n };\n }, [\n expandNode,\n getHierarchyLevelDetails,\n isNodeSelected,\n reloadTree,\n selectNodes,\n state.model.rootNode.error,\n state.rootNodes,\n ]);\n\n return {\n ...renderProps,\n isReloading: !!state.model.rootNode.isLoading || isSearching,\n getTreeModelNode,\n getNode,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(\n parentNodeId: string | undefined,\n model: TreeModel,\n getTreeNodeErrors?: (node: HierarchyNode) => ErrorInfo[],\n): Array<TreeNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelHierarchyNode => !!node)\n .map<TreeNode>((node) => {\n return createTreeNode(node, model, getTreeNodeErrors);\n });\n}\n\nfunction createTreeNode(\n modelNode: TreeModelHierarchyNode,\n model: TreeModel,\n getTreeNodeErrors?: (node: HierarchyNode) => ErrorInfo[],\n): TreeNode {\n const allErrors = [\n // internal errors\n ...(modelNode.error ? [modelNode.error] : []),\n // external errors\n ...(getTreeNodeErrors?.(modelNode.nodeData) ?? []),\n ];\n\n let children: Array<TreeNode> | undefined;\n return {\n id: modelNode.id,\n label: modelNode.label,\n nodeData: modelNode.nodeData,\n isLoading: !!modelNode.isLoading,\n isExpanded: !!modelNode.isExpanded,\n isFilterable:\n !HierarchyNode.isGroupingNode(modelNode.nodeData) && !!modelNode.nodeData.supportsFiltering && modelNode.children,\n isFiltered: !!modelNode.instanceFilter,\n errors: allErrors,\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model, getTreeNodeErrors);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiCA,SAAOuB,QAAAC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CACoC,MAAAC,KAAAC,gBAAgBJ,MAAM;CAAA,IAAAK;AAAA,KAAAJ,EAAA,OAAAE,IAAA;EAA/D,MAAA,EAAAG,kBAAAC,GAAA,GAAAC,OAAyCL;AAAzCE,SAAAG;AAAgEP,IAAA,KAAAE;AAAAF,IAAA,KAAAI;OAAAA,QAAAJ,EAAA;AAAA,QACzDI;;;;;;;;;;;;;;;;;AAkBT,SAAOI,wBAAAN,IAAA;CAAA,MAAAF,IAAAC,EAAA,GAAA;CAAA,IAAAQ;CAAA,IAAAV;CAAA,IAAAW;CAAA,IAAAC;AAAA,KAAAX,EAAA,OAAAE,IAAA;AAAiC,GAAA,CAAAS,YAAAD,kBAAAD,mCAAAV,SAAAG;AAKMF,IAAA,KAAAE;AAAAF,IAAA,KAAAS;AAAAT,IAAA,KAAAD;AAAAC,IAAA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OAAO,EAAE;;EAEvE"}
1
+ {"version":3,"file":"UseTree.js","names":["useCallback","useEffect","useMemo","useRef","useState","HierarchyNode","TreeActions","TreeModel","useUnifiedTreeSelection","safeDispose","useLatest","GenericInstanceFilter","HierarchyProvider","HierarchySearchTree","IPrimitiveValueFormatter","TreeModelHierarchyNode","TreeModelRootNode","UseUnifiedTreeSelectionProps","RootErrorRendererProps","TreeRendererProps","ErrorInfo","TreeNode","SelectionChangeType","useTree","props","$","_c","t0","useTreeInternal","rest","getTreeModelNode","_","t1","useUnifiedSelectionTree","createSelectableForGenericNode","selectionStorage","sourceName","t2","selectionProps","rootErrorRendererProps","undefined","treeRendererProps","rootNodes","t3","t4","UseTreeProps","getHierarchyProvider","getSearchPaths","abortSignal","AbortSignal","Promise","onPerformanceMeasured","action","duration","onHierarchyLimitExceeded","parentId","filter","limit","onHierarchyLoadError","type","error","getTreeNodeErrors","node","UseTreeResult","isReloading","getNode","nodeId","setFormatter","formatter","RendererProps","TreeState","model","Array","state","setState","idToNode","Map","parentChildMap","rootNode","id","nodeData","onPerformanceMeasuredRef","onHierarchyLimitExceededRef","onHierarchyLoadErrorRef","getTreeNodeErrorsRef","actions","get","generateTreeStructure","current","actionType","currentFormatter","hierarchyProvider","setHierarchyProvider","provider","removeHierarchyChangedListener","hierarchyChanged","addListener","hierarchyChangeArgs","shouldDiscardState","searchChange","newSearch","reloadTree","reset","isSearching","setIsSearching","disposed","controller","AbortController","setHierarchySearch","paths","signal","abort","createTreeNode","expandNode","isExpanded","options","selectNodes","nodeIds","changeType","isNodeSelected","getHierarchyLevelDetails","hierarchyNode","isGroupingNode","getInstanceKeysIterator","getNodeInstanceKeys","parentNode","instanceFilter","hierarchyLevelSizeLimit","setInstanceFilter","sizeLimit","hierarchyLimit","setSizeLimit","value","setHierarchyLimit","renderProps","isLoading","parentNodeId","currentChildren","map","childId","modelNode","allErrors","children","label","isFilterable","supportsFiltering","isFiltered","errors"],"sources":["../../src/presentation-hierarchies-react/UseTree.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 { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { TreeModel } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { useLatest } from \"./Utils.js\";\n\nimport type { GenericInstanceFilter, HierarchyProvider, HierarchySearchTree } from \"@itwin/presentation-hierarchies\";\nimport type { IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport type { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport type { RootErrorRendererProps, TreeRendererProps } from \"./Renderers.js\";\nimport type { ErrorInfo, TreeNode } from \"./TreeNode.js\";\nimport type { SelectionChangeType } from \"./UseSelectionHandler.js\";\n\n/**\n * A React hook that creates state for a tree component.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({\n sourceName,\n selectionStorage,\n createSelectableForGenericNode,\n ...props\n}: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n const selectionProps = useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n createSelectableForGenericNode,\n });\n if (rest.rootErrorRendererProps === undefined && rest.treeRendererProps?.rootNodes) {\n return { ...rest, treeRendererProps: { ...rest.treeRendererProps, ...selectionProps } };\n }\n return rest;\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to search nodes. */\n getSearchPaths?: ({ abortSignal }: { abortSignal: AbortSignal }) => Promise<HierarchySearchTree[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: {\n parentId?: string;\n filter?: GenericInstanceFilter;\n limit?: number | \"unbounded\";\n }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n /**\n * Callback to set custom TreeNode errors.\n * Errors returned from this callback are combined with internal errors when populating `TreeNode.errors`.\n */\n getTreeNodeErrors?: (node: HierarchyNode) => ErrorInfo[];\n}\n\n/** @public */\nexport type UseTreeResult = {\n /**\n * Specifies whether tree is reloading or not. It is set to `false` when initial tree load is in progress to check if\n * or tree is reloading.\n */\n isReloading: boolean;\n /**\n * Get a tree node by id\n */\n getNode: (nodeId: string) => TreeNode | undefined;\n /**\n * Sets a formatter for the primitive values that are displayed in the hierarchy.\n */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n} & RendererProps;\n\n/**.\n * @alpha\n */\ntype RendererProps =\n | {\n /**\n * An object containing information used to render root error handling UI.\n * Use in combination with `RootErrorRenderer` or your custom implementation.\n * Defined when root nodes fail to load.\n */\n rootErrorRendererProps: RootErrorRendererProps;\n }\n | {\n /** Is undefined when rootNodes were successfully loaded or are in initial loading process. */\n rootErrorRendererProps: undefined;\n /**\n * An object containing information used to render tree.\n * Use with `TreeRenderer` or your custom implementation.\n * Is undefined on initial loading process.\n */\n treeRendererProps?: TreeRendererProps;\n };\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<TreeNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getSearchPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n getTreeNodeErrors,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelHierarchyNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n const getTreeNodeErrorsRef = useLatest(getTreeNodeErrors);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes =\n model.parentChildMap.get(undefined) !== undefined\n ? generateTreeStructure(undefined, model, getTreeNodeErrorsRef.current)\n : undefined;\n setState({ model, rootNodes });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs.searchChange?.newSearch !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isSearching, setIsSearching] = useState(false);\n useEffect(() => {\n let disposed = false as boolean;\n const controller = new AbortController();\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getSearchPaths) {\n hierarchyProvider.setHierarchySearch(undefined);\n // reload tree in case hierarchy provider does not use hierarchy search to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsSearching(false);\n return;\n }\n\n setIsSearching(true);\n let paths: HierarchySearchTree[] | undefined;\n try {\n paths = await getSearchPaths({ abortSignal: controller.signal });\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchySearch(paths ? { paths } : undefined);\n setIsSearching(false);\n }\n }\n })();\n return () => {\n controller.abort();\n disposed = true;\n };\n }, [hierarchyProvider, getSearchPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelHierarchyNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): TreeNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || node.id === undefined) {\n return undefined;\n }\n return createTreeNode(node, state.model, getTreeNodeErrorsRef.current);\n },\n [actions, getTreeNodeErrorsRef, state.model],\n );\n\n const expandNode = useCallback<TreeRendererProps[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<TreeRendererProps[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<TreeRendererProps[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<TreeRendererProps[\"isNodeSelected\"]>(\n (nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId),\n [state],\n );\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<TreeRendererProps[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n const renderProps: RendererProps = useMemo(() => {\n if (state.model.rootNode.error) {\n return { rootErrorRendererProps: { error: state.model.rootNode.error, reloadTree, getHierarchyLevelDetails } };\n }\n return {\n rootErrorRendererProps: undefined,\n treeRendererProps: state.rootNodes\n ? { rootNodes: state.rootNodes, expandNode, selectNodes, isNodeSelected, reloadTree, getHierarchyLevelDetails }\n : undefined,\n };\n }, [\n expandNode,\n getHierarchyLevelDetails,\n isNodeSelected,\n reloadTree,\n selectNodes,\n state.model.rootNode.error,\n state.rootNodes,\n ]);\n\n return {\n ...renderProps,\n isReloading: !!state.model.rootNode.isLoading || isSearching,\n getTreeModelNode,\n getNode,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(\n parentNodeId: string | undefined,\n model: TreeModel,\n getTreeNodeErrors?: (node: HierarchyNode) => ErrorInfo[],\n): Array<TreeNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelHierarchyNode => !!node)\n .map<TreeNode>((node) => {\n return createTreeNode(node, model, getTreeNodeErrors);\n });\n}\n\nfunction createTreeNode(\n modelNode: TreeModelHierarchyNode,\n model: TreeModel,\n getTreeNodeErrors?: (node: HierarchyNode) => ErrorInfo[],\n): TreeNode {\n const allErrors = [\n // internal errors\n ...(modelNode.error ? [modelNode.error] : []),\n // external errors\n ...(getTreeNodeErrors?.(modelNode.nodeData) ?? []),\n ];\n\n let children: Array<TreeNode> | undefined;\n return {\n id: modelNode.id,\n label: modelNode.label,\n nodeData: modelNode.nodeData,\n isLoading: !!modelNode.isLoading,\n isExpanded: !!modelNode.isExpanded,\n isFilterable:\n !HierarchyNode.isGroupingNode(modelNode.nodeData) && !!modelNode.nodeData.supportsFiltering && modelNode.children,\n isFiltered: !!modelNode.instanceFilter,\n errors: allErrors,\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model, getTreeNodeErrors);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiCA,SAAOuB,QAAAC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CACoC,MAAAC,KAAAC,gBAAgBJ,MAAM;CAAA,IAAAK;AAAA,KAAAJ,EAAA,OAAAE,IAAA;EAA/D,MAAA,EAAAG,kBAAAC,GAAA,GAAAC,OAAyCL;AAAzCE,SAAAG;AAAgEP,IAAA,KAAAE;AAAAF,IAAA,KAAAI;O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,YAAY,CAAC,CAAC0B,UAAU1B;EACxB8B,cACE,CAAC3I,cAAcqH,eAAekB,UAAU5D,SAAS,IAAI,CAAC,CAAC4D,UAAU5D,SAASiE,qBAAqBL,UAAUE;EAC3GI,YAAY,CAAC,CAACN,UAAUd;EACxBqB,QAAQN;EACR,IAAIC,WAAW;AACb,OAAI,CAACA,SACHA,YAAWvD,sBAAsBqD,UAAU7D,IAAIR,OAAOV,kBAAkB;AAE1E,UAAOiF,WAAWA,WAAWF,UAAUE,aAAa,OAAO,OAAO,EAAE;;EAEvE"}
@@ -21,14 +21,14 @@ var TreeActions = class {
21
21
  this._onHierarchyLoadError = _onHierarchyLoadError;
22
22
  this._loader = new NoopTreeLoader();
23
23
  this._nodeIdFactory = nodeIdFactory ?? createNodeId;
24
- this._currentModel = seed ?? ( /* c8 ignore next */ {
24
+ this._currentModel = seed ?? {
25
25
  idToNode: /* @__PURE__ */ new Map(),
26
26
  parentChildMap: /* @__PURE__ */ new Map(),
27
27
  rootNode: {
28
28
  id: void 0,
29
29
  nodeData: void 0
30
30
  }
31
- });
31
+ };
32
32
  this._nodeLoader = this.createNodeLoader();
33
33
  }
34
34
  createNodeLoader() {
@@ -93,7 +93,6 @@ var TreeActions = class {
93
93
  }
94
94
  loadNodes(parentId, ignoreCache) {
95
95
  const parentNode = this._currentModel.idToNode.get(parentId);
96
- /* c8 ignore next 3 */
97
96
  if (!parentNode) return { complete: Promise.resolve() };
98
97
  return this.loadSubTree({
99
98
  parent: parentNode,
@@ -121,7 +120,6 @@ var TreeActions = class {
121
120
  };
122
121
  const buildNode = (node) => !!options?.discardState || node.id === parentId ? node : addAttributes(node, oldModel);
123
122
  const rootNode = parentId !== void 0 ? this.getNode(parentId) : currModel.rootNode;
124
- /* c8 ignore next 3 */
125
123
  if (!rootNode) return { complete: Promise.resolve() };
126
124
  if (parentId === void 0) this._reset.next();
127
125
  return this.loadSubTree({
@@ -263,13 +261,11 @@ function createHierarchyLevelOptions(model, nodeId) {
263
261
  hierarchyLevelSizeLimit: modelNode.hierarchyLimit
264
262
  };
265
263
  }
266
- /* c8 ignore start */
267
264
  var NoopTreeLoader = class {
268
265
  loadNodes() {
269
266
  return EMPTY;
270
267
  }
271
268
  };
272
- /* c8 ignore end */
273
269
  var TimeTracker = class {
274
270
  _start;
275
271
  _stopped = false;
@@ -281,7 +277,6 @@ var TimeTracker = class {
281
277
  this._stopped = true;
282
278
  }
283
279
  finish() {
284
- /* c8 ignore next 3 */
285
280
  if (this._stopped) return;
286
281
  this._stopped = true;
287
282
  const elapsedTime = Date.now() - this._start;
@@ -1 +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: {\n parentId?: string;\n filter?: GenericInstanceFilter;\n limit?: number | \"unbounded\";\n }) => 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\n ? \"initial-load\"\n : parentId === undefined\n ? \"reload\"\n : \"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({\n loadOptions: options,\n onComplete: resolve,\n timeTracker,\n parentId: options.parent.id,\n initialRootNode,\n discardState,\n });\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) =>\n createHierarchyLevelOptions(this._currentModel, getNonGroupedParentId(node, this._nodeIdFactory)),\n shouldLoadChildren: (node) => !!node.nodeData.autoExpand,\n ignoreCache,\n });\n }\n\n private reloadSubTree(\n parentId: string | undefined,\n oldModel: TreeModel,\n options?: { discardState?: boolean; ignoreCache?: boolean },\n ) {\n const currModel = this._currentModel;\n const expandedNodes = !!options?.discardState\n ? []\n : collectNodes(parentId, oldModel, (node) => node.isExpanded === true);\n const collapsedNodes = !!options?.discardState\n ? []\n : 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) =>\n !!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(\n model: TreeModel,\n loadedPart: { parent: TreeModelHierarchyNode | TreeModelRootNode; error: ErrorInfo },\n) {\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(\n model: TreeModel,\n loadedPart: { parent: TreeModelHierarchyNode | TreeModelRootNode; loadedNodes: TreeModelHierarchyNode[] },\n) {\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(\n parentId: string | undefined,\n model: TreeModel,\n pred: (node: TreeModelHierarchyNode) => boolean,\n): 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(\n node: TreeModelHierarchyNode | TreeModelRootNode,\n nodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string,\n) {\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,IAAasC,cAAb,MAAyB;CACvB;CACA;CACA;CACA,SAAiB,IA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["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: {\n parentId?: string;\n filter?: GenericInstanceFilter;\n limit?: number | \"unbounded\";\n }) => 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 ?? {\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\n ? \"initial-load\"\n : parentId === undefined\n ? \"reload\"\n : \"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({\n loadOptions: options,\n onComplete: resolve,\n timeTracker,\n parentId: options.parent.id,\n initialRootNode,\n discardState,\n });\n }),\n };\n }\n\n private loadNodes(parentId: string, ignoreCache?: boolean) {\n const parentNode = this._currentModel.idToNode.get(parentId);\n if (!parentNode) {\n return { complete: Promise.resolve() };\n }\n return this.loadSubTree({\n parent: parentNode,\n getHierarchyLevelOptions: (node) =>\n createHierarchyLevelOptions(this._currentModel, getNonGroupedParentId(node, this._nodeIdFactory)),\n shouldLoadChildren: (node) => !!node.nodeData.autoExpand,\n ignoreCache,\n });\n }\n\n private reloadSubTree(\n parentId: string | undefined,\n oldModel: TreeModel,\n options?: { discardState?: boolean; ignoreCache?: boolean },\n ) {\n const currModel = this._currentModel;\n const expandedNodes = !!options?.discardState\n ? []\n : collectNodes(parentId, oldModel, (node) => node.isExpanded === true);\n const collapsedNodes = !!options?.discardState\n ? []\n : 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) =>\n !!options?.discardState || node.id === parentId ? node : addAttributes(node, oldModel);\n\n const rootNode = parentId !== undefined ? this.getNode(parentId) : currModel.rootNode;\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 : 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(\n model: TreeModel,\n loadedPart: { parent: TreeModelHierarchyNode | TreeModelRootNode; error: ErrorInfo },\n) {\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(\n model: TreeModel,\n loadedPart: { parent: TreeModelHierarchyNode | TreeModelRootNode; loadedNodes: TreeModelHierarchyNode[] },\n) {\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(\n parentId: string | undefined,\n model: TreeModel,\n pred: (node: TreeModelHierarchyNode) => boolean,\n): 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(\n node: TreeModelHierarchyNode | TreeModelRootNode,\n nodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string,\n) {\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\nclass NoopTreeLoader implements ITreeLoader {\n public loadNodes(): Observable<LoadedTreePart> {\n return EMPTY;\n }\n}\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 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,IAAasC,cAAb,MAAyB;CACvB;CACA;CACA;CACA,SAAiB,IAAI7B,SAAe;CACpC;CAEAqC,YACE,iBACA,SACA,2BAKA,uBACAa,eACAC,MACA;AAVQb,OAAAA,kBAAAA;AACAE,OAAAA,UAAAA;AACAG,OAAAA,4BAAAA;AAKAI,OAAAA,wBAAAA;AAIR,OAAKjB,UAAU,IAAIsB,gBAAgB;AACnC,OAAKrB,iBAAiBmB,iBAAiB3C;AACvC,OAAK2B,gBAAgBiB,QAAQ;GAC3BE,0BAAU,IAAIC,KAAK;GACnBC,gCAAgB,IAAID,KAAK;GACzBE,UAAU;IAAEC,IAAIC,KAAAA;IAAWC,UAAUD,KAAAA;IAAU;GAChD;AAED,OAAKtB,cAAc,KAAKwB,kBAAkB;;CAG5C,mBAA2B;EACzB,MAAMC,UAAU,IAAI7D,SAAoC;AACxD6D,UACGC,KACClE,SAASmE,SAASA,K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AAAA,EACb,QAAO;EAAEqD,gBAAgBxE,MAAMiB,SAASuD;EAAgBC,yBAAyBzE,MAAMiB,SAAS8F;EAAgB;CAGlH,MAAMS,YAAYxH,MAAMc,SAASyB,IAAI+C,OAAO;AAC5C,KAAI,CAACkC,UACH,QAAO;EAAEhD,gBAAgBrD,KAAAA;EAAWsD,yBAAyBtD,KAAAA;EAAW;AAE1E,QAAO;EAAEqD,gBAAgBgD,UAAUhD;EAAgBC,yBAAyB+C,UAAUT;EAAgB;;AAGxG,IAAMlG,iBAAN,MAA4C;CAC1C,YAA+C;AAC7C,SAAOzD;;;AAIX,IAAM8B,cAAN,MAAkB;CAChB;CACA,WAA4B;CAE5BY,YAAY,WAA2C;AAAnC6H,OAAAA,YAAAA;AAClB,OAAKF,SAASG,KAAKC,KAAK;;CAG1B,CAAQ7F,OAAOC,WAAW;AACxB,OAAKyF,WAAW;;CAGlB,SAAgB;AACd,MAAI,KAAKA,SACP;AAGF,OAAKA,WAAW;EAChB,MAAMI,cAAcF,KAAKC,KAAK,GAAG,KAAKJ;AACtC,OAAKE,UAAUG,YAAY"}
@@ -1 +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 {\n GenericInstanceFilter,\n HierarchyNode,\n HierarchyProvider,\n RowsLimitExceededError,\n} from \"@itwin/presentation-hierarchies\";\nimport type { ErrorInfo } from \"../TreeNode.js\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport type LoadedTreePart = { parent: TreeModelHierarchyNode | TreeModelRootNode } & (\n | { loadedNodes: TreeModelHierarchyNode[] }\n | { error: ErrorInfo }\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: {\n parentId?: string;\n filter?: GenericInstanceFilter;\n limit?: number | \"unbounded\";\n }) => 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({\n parent,\n getHierarchyLevelOptions,\n buildNode,\n ignoreCache,\n }: Omit<LoadNodesOptions, \"shouldLoadChildren\">) {\n const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);\n const infoNodeIdBase = `${parent.id ?? \"<root>\"}`;\n const treeModelNodesFactory = createTreeModelNodesFactory({\n buildNode,\n treeNodeIdFactory: this._treeNodeIdFactory,\n });\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 ? { parent, error: { id: `${infoNodeIdBase}-no-filter-matches`, type: \"NoFilterMatches\" as const } }\n : { parent, loadedNodes: childNodes.map(treeModelNodesFactory) };\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: {\n id: `${infoNodeIdBase}-${err.message}`,\n type: \"ResultSetTooLarge\" as const,\n resultSetSizeLimit: err.limit,\n },\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":";;;;AA6CA,IAAakC,aAAb,MAA+C;CAC7C;CAEAG,YACE,oBACA,2BAKA,uBACAQ,mBACA;AARQP,OAAAA,qBAAAA;AACAC,OAAAA,4BAAAA;AAKAI,OAAAA,wBAAAA;AAGR,OAAKR,qBAAqBU,qBAA0CpC;;CAGtE,aAAqB,EACnBU,QACAO,0BACAG,WACAC,eAC+C;EAC/C,MAAM,EAAEP,gBAAgBC,4BAA4BE,yBAAyBP,OAAO;EACpF,MAAM6B,iBAAiB,GAAG7B,OAAO8B,MAAM;EACvC,MAAMC,wBAAwBC,4BAA4B;GACxDtB;GACAgB,mBAAmB,KAAKV;GACzB,CAAC;AACF,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,UAAO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AUzC,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"}
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 {\n GenericInstanceFilter,\n HierarchyNode,\n HierarchyProvider,\n RowsLimitExceededError,\n} from \"@itwin/presentation-hierarchies\";\nimport type { ErrorInfo } from \"../TreeNode.js\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport type LoadedTreePart = { parent: TreeModelHierarchyNode | TreeModelRootNode } & (\n | { loadedNodes: TreeModelHierarchyNode[] }\n | { error: ErrorInfo }\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: {\n parentId?: string;\n filter?: GenericInstanceFilter;\n limit?: number | \"unbounded\";\n }) => 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 ?? createNodeId;\n }\n\n private loadChildren({\n parent,\n getHierarchyLevelOptions,\n buildNode,\n ignoreCache,\n }: Omit<LoadNodesOptions, \"shouldLoadChildren\">) {\n const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);\n const infoNodeIdBase = `${parent.id ?? \"<root>\"}`;\n const treeModelNodesFactory = createTreeModelNodesFactory({\n buildNode,\n treeNodeIdFactory: this._treeNodeIdFactory,\n });\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 ? { parent, error: { id: `${infoNodeIdBase}-no-filter-matches`, type: \"NoFilterMatches\" as const } }\n : { parent, loadedNodes: childNodes.map(treeModelNodesFactory) };\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: {\n id: `${infoNodeIdBase}-${err.message}`,\n type: \"ResultSetTooLarge\" as const,\n resultSetSizeLimit: err.limit,\n },\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":";;;;AA6CA,IAAakC,aAAb,MAA+C;CAC7C;CAEAG,YACE,oBACA,2BAKA,uBACAQ,mBACA;AARQP,OAAAA,qBAAAA;AACAC,OAAAA,4BAAAA;AAKAI,OAAAA,wBAAAA;AAGR,OAAKR,qBAAqBU,qBAAqBpC;;CAGjD,aAAqB,EACnBU,QACAO,0BACAG,WACAC,eAC+C;EAC/C,MAAM,EAAEP,gBAAgBC,4BAA4BE,yBAAyBP,OAAO;EACpF,MAAM6B,iBAAiB,GAAG7B,OAAO8B,MAAM;EACvC,MAAMC,wBAAwBC,4BAA4B;GACxDtB;GACAgB,mBAAmB,KAAKV;GACzB,CAAC;AACF,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;IAAEtC;IAAQE,OAAO;KAAE4B,IAAI,GAAGD,eAAc;KAAsBJ,MAAM;KAA2B;IAAG,GAClG;IAAEzB;IAAQC,aAAaoC,WAAWnD,IAAI6C,sBAAqB;IAAG;IAClE,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;OACL4B,IAAI,GAAGD,eAAc,GAAIW,IAAII;OAC7BnB,MAAM;OACNoB,oBAAoBL,IAAIjB;OAC1B;MACD,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,UAAiB,EAAEnC,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"}
@@ -25,7 +25,6 @@ let TreeModel;
25
25
  for (const [parentId, children] of hierarchyPart.parentChildMap) model.parentChildMap.set(parentId, children);
26
26
  for (const [nodeId, node] of hierarchyPart.idToNode) model.idToNode.set(nodeId, node);
27
27
  const parentNode = rootId !== void 0 ? model.idToNode.get(rootId) : model.rootNode;
28
- /* c8 ignore next 3*/
29
28
  if (!parentNode) return;
30
29
  parentNode.isLoading = false;
31
30
  }
@@ -83,7 +82,6 @@ let TreeModel;
83
82
  return;
84
83
  }
85
84
  const modelNode = model.idToNode.get(nodeId);
86
- /* c8 ignore next 3*/
87
85
  if (!modelNode) return;
88
86
  modelNode.isLoading = isLoading;
89
87
  }
@@ -1 +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(\n model: TreeModel,\n nodeId: string,\n isExpanded: boolean,\n ): \"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(\n model: TreeModel,\n nodeId: string | undefined,\n limit?: number | \"unbounded\",\n ): boolean {\n return updateForReload(model, nodeId, (node) => {\n node.hierarchyLimit = limit;\n });\n }\n\n export function setInstanceFilter(\n model: TreeModel,\n nodeId: string | undefined,\n filter?: GenericInstanceFilter,\n ): 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(\n model: TreeModel,\n nodeId: string | undefined,\n ): 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(\n model: TreeModel,\n nodeId: string | undefined,\n update: (node: TreeModelHierarchyNode | TreeModelRootNode) => void,\n) {\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 const node = !parentId ? model.rootNode : model.idToNode.get(parentId);\n if (node) {\n node.error = undefined;\n }\n}\n"],"mappings":";AAyCO,IAAA;;CACE,SAASqB,WACdC,OACAC,QACAT,YAC4C;EAC5C,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;AAC5BP,QAAMF,SAASV,QAAQoB,cAAcV,SAASV;AAE9C,OAAK,MAAM,CAACqB,UAAUlB,aAAaiB,cAAcb,eAC/CK,OAAML,eAAee,IAAID,UAAUlB,SAAS;AAG9C,OAAK,MAAM,CAACU,QAAQC,SAASM,cAAcX,SACzCG,OAAMH,SAASa,IAAIT,QAAQC,KAAK;EAGlC,MAAMS,aAAaJ,WAAWK,KAAAA,IAAYZ,MAAMH,SAASM,IAAII,OAAO,GAAGP,MAAMF;;AAE7E,MAAI,CAACa,WACH;AAEFA,aAAWxB,YAAY;;;CAGlB,SAASkB,cAAcL,OAAkBS,UAAoC;AAClFI,iBAAeb,OAAOS,SAAS;EAC/B,MAAMK,kBAAkBd,MAAML,eAAeQ,IAAIM,SAAS;AAC1D,MAAI,CAACK,gBACH;AAEFd,QAAML,eAAeoB,OAAON,SAAS;AAErC,OAAK,MAAMO,WAAWF,iBAAiB;GACrC,MAAMG,YAAYjB,MAAMH,SAASM,IAAIa,QAAQ;AAC7C,OAAIC,UACFZ,eAAcL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QACA;AACAvC,WAAUW,cAAcL,OAAOC,OAAO;AACtC,KAAIA,WAAWW,KAAAA,GAAW;AACxBqB,SAAOjC,MAAMF,SAAS;AACtBE,QAAMF,SAASX,YAAY;AAC3B,SAAO;;CAGT,MAAMyC,YAAY5B,MAAMH,SAASM,IAAIF,OAAO;AAC5C,KAAI,CAAC2B,UACH,QAAO;AAGTK,QAAOL,UAAU;AACjB,KAAIA,UAAUpC,YAAY;AACxBoC,YAAUzC,YAAY;AACtB,SAAO;;AAET,QAAO;;AAGT,SAAS0B,eAAeb,OAAkBS,UAA8B;CACtE,MAAMP,OAAO,CAACO,WAAWT,MAAMF,WAAWE,MAAMH,SAASM,IAAIM,SAAS;AACtE,KAAIP,KACFA,MAAKd,QAAQwB,KAAAA"}
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(\n model: TreeModel,\n nodeId: string,\n isExpanded: boolean,\n ): \"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 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(\n model: TreeModel,\n nodeId: string | undefined,\n limit?: number | \"unbounded\",\n ): boolean {\n return updateForReload(model, nodeId, (node) => {\n node.hierarchyLimit = limit;\n });\n }\n\n export function setInstanceFilter(\n model: TreeModel,\n nodeId: string | undefined,\n filter?: GenericInstanceFilter,\n ): 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(\n model: TreeModel,\n nodeId: string | undefined,\n ): 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 if (!modelNode) {\n return;\n }\n modelNode.isLoading = isLoading;\n }\n}\n\nfunction updateForReload(\n model: TreeModel,\n nodeId: string | undefined,\n update: (node: TreeModelHierarchyNode | TreeModelRootNode) => void,\n) {\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 const node = !parentId ? model.rootNode : model.idToNode.get(parentId);\n if (node) {\n node.error = undefined;\n }\n}\n"],"mappings":";AAyCO,IAAA;;CACE,SAASqB,WACdC,OACAC,QACAT,YAC4C;EAC5C,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;AAC5BP,QAAMF,SAASV,QAAQoB,cAAcV,SAASV;AAE9C,OAAK,MAAM,CAACqB,UAAUlB,aAAaiB,cAAcb,eAC/CK,OAAML,eAAee,IAAID,UAAUlB,SAAS;AAG9C,OAAK,MAAM,CAACU,QAAQC,SAASM,cAAcX,SACzCG,OAAMH,SAASa,IAAIT,QAAQC,KAAK;EAGlC,MAAMS,aAAaJ,WAAWK,KAAAA,IAAYZ,MAAMH,SAASM,IAAII,OAAO,GAAGP,MAAMF;AAC7E,MAAI,CAACa,WACH;AAEFA,aAAWxB,YAAY;;;CAGlB,SAASkB,cAAcL,OAAkBS,UAAoC;AAClFI,iBAAeb,OAAOS,SAAS;EAC/B,MAAMK,kBAAkBd,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W,KAAAA,GAAW;AACxBZ,SAAMF,SAASX,YAAYA;AAC3B;;EAEF,MAAMyC,YAAY5B,MAAMH,SAASM,IAAIF,OAAO;AAC5C,MAAI,CAAC2B,UACH;AAEFA,YAAUzC,YAAYA;;;iCAE1B;AAEA,SAASiC,gBACPpB,OACAC,QACAgC,QACA;AACAvC,WAAUW,cAAcL,OAAOC,OAAO;AACtC,KAAIA,WAAWW,KAAAA,GAAW;AACxBqB,SAAOjC,MAAMF,SAAS;AACtBE,QAAMF,SAASX,YAAY;AAC3B,SAAO;;CAGT,MAAMyC,YAAY5B,MAAMH,SAASM,IAAIF,OAAO;AAC5C,KAAI,CAAC2B,UACH,QAAO;AAGTK,QAAOL,UAAU;AACjB,KAAIA,UAAUpC,YAAY;AACxBoC,YAAUzC,YAAY;AACtB,SAAO;;AAET,QAAO;;AAGT,SAAS0B,eAAeb,OAAkBS,UAA8B;CACtE,MAAMP,OAAO,CAACO,WAAWT,MAAMF,WAAWE,MAAMH,SAASM,IAAIM,SAAS;AACtE,KAAIP,KACFA,MAAKd,QAAQwB,KAAAA"}
@@ -1 +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?: (\n node: NonGroupingHierarchyNode & { key: GenericNodeKey },\n treeModelNodeId: string,\n ) => 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 & {\n getTreeModelNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined;\n}): 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<\n UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]\n> = (node, treeModelNodeId): Selectable => ({ identifier: treeModelNodeId, data: node, async *loadInstanceKeys() {} });\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(\n node,\n createSelectableForGenericNode,\n )) {\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(\n node,\n createSelectableForGenericNode,\n )) {\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":";;;;;;;AAuDA,SAAO4B,wBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAiC,MAAA,EAAAT,YAAAK,kBAAAK,kBAAAT,gCAAAU,OAAAJ;CAItC,MAAAN,iCAAAU,OAAAC,KAAAA,IAAAC,wCAAAF;CAIA,MAAA,CAAAG,SAAAC,cAA8BpC,SAA+BqC,OAG1D;CAAC,IAAAC;CAAA,IAAAC;AAAA,KAAAV,EAAA,OAAAP,kCAAAO,EAAA,OAAAE,oBAAAF,EAAA,OAAAH,oBAAAG,EAAA,OAAAR,YAAA;AAEMiB,aAAA;AAERF,cAAWI,cAAcnB,YAAYK,kBAAkBJ,gCAAgCS,iBAAiB,CAAC;AAAA,UAClGL,iBAAgBe,qBAAqBC,aAAaC,SAAA;AACvD,QAAIA,KAAIC,QAAS,EAAC;AAGlBR,eAAWI,cAAcnB,YAAYK,kBAAkBJ,gCAAgCS,iBAAiB,CAAC;KACzG;;AACDQ,OAAA;GAACb;GAAkBJ;GAAgCS;GAAkBV;GAAW;AAAAQ,IAAA,KAAAP;AAAAO,IAAA,KAAAE;AAAAF,IAAA,KAAAH;AAAAG,IAAA,KAAAR;AAAAQ,IAAA,KAAAS;AAAAT,IAAA,KAAAU;QAAA;AAAAD,OAAAT,EAAA;AAAAU,OAAAV,EAAA;;AATnF9B,WAAUuC,IASPC,GAAiF;AAAA,QAE7EJ;;AAxBF,SAAAE,SAAA;AAAA,QAQ+D;EAAAvB,gBAC7B+B;EAAW7B,aACd8B;EACnC;;AAXI,SAAAA,SAAA;AAAA,SAAAD,QAAA;AAAA,QASwC;;AAkB/C,MAAMX,yCAEDX,MA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iB,WACApD,gCAC2B;CAC3B,MAAMqD,gBAAgBD,UAAUE;AAChC,KAAI1E,cAAc2E,gBAAgBF,cAAc,CAC9C,QAAOG,wBAAwBH,cAAcnD,IAAIuD,aAAa;AAEhE,KAAI7E,cAAc8E,eAAeL,cAAc,EAAE;EAC/C,MAAMM,0CAA0B,IAAInB,KAA2B;AAC/DgB,0BAAwBH,cAAcO,oBAAoB,CAAChB,SAASa,cAAcxB,cAAc;AAC9F0B,2BAAwBhB,IAAIV,WAAW,CACrC;IACEP,YAAY0B,UAAUpB;IACtBL,MAAM0B;IACN,OAAOzB,mBAAmB;AACxB,UAAK,MAAM1B,OAAOuD,aAChB,OAAMvD;;IAGX,CACF,CAAC;IACF;AACF,SAAOyD;;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"}
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?: (\n node: NonGroupingHierarchyNode & { key: GenericNodeKey },\n treeModelNodeId: string,\n ) => 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 & {\n getTreeModelNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined;\n}): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: () => false,\n selectNodes: () => {},\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<\n UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]\n> = (node, treeModelNodeId): Selectable => ({ identifier: treeModelNodeId, data: node, async *loadInstanceKeys() {} });\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(\n node,\n createSelectableForGenericNode,\n )) {\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(\n node,\n createSelectableForGenericNode,\n )) {\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":";;;;;;;AAuDA,SAAO4B,wBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAiC,MAAA,EAAAT,YAAAK,kBAAAK,kBAAAT,gCAAAU,OAAAJ;CAItC,MAAAN,iCAAAU,OAAAC,KAAAA,IAAAC,wCAAAF;CAIA,MAAA,CAAAG,SAAAC,cAA8BpC,SAA+BqC,OAG1D;CAAC,IAAAC;CAAA,IAAAC;AAAA,KAAAV,EAAA,OAAAP,kCAAAO,EAAA,OAAAE,oBAAAF,EAAA,OAAAH,oBAAAG,EAAA,OAAAR,YAAA;AAEMiB,aAAA;AAERF,cAAWI,cAAcnB,YAAYK,kBAAkBJ,gCAAgCS,iBAAiB,CAAC;AAAA,UAClGL,iBAAgBe,qBAAqBC,aAAaC,SAAA;AACvD,QAAIA,KAAIC,QAAS,EAAC;AAGlBR,eAAWI,cAAcnB,YAAYK,kBAAkBJ,gCAAgCS,iBAAiB,CAAC;KACzG;;AACDQ,OAAA;GAACb;GAAkBJ;GAAgCS;GAAkBV;GAAW;AAAAQ,IAAA,KAAAP;AAAAO,IAAA,KAAAE;AAAAF,IAAA,KAAAH;AAAAG,IAAA,KAAAR;AAAAQ,IAAA,KAAAS;AAAAT,IAAA,KAAAU;QAAA;AAAAD,OAAAT,EAA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
17
17
  function ErrorItemRenderer(t0) {
18
- const $ = c(87);
18
+ const $ = c(84);
19
19
  const { treeNode, error, getHierarchyLevelDetails, filterHierarchyLevel, reloadTree, scrollToNode } = t0;
20
20
  const translate = useTranslation();
21
21
  if (error.type === "ResultSetTooLarge") {
@@ -118,158 +118,152 @@ function ErrorItemRenderer(t0) {
118
118
  $[34] = t12;
119
119
  } else t12 = $[34];
120
120
  let t13;
121
- if ($[35] !== error || $[36] !== t10 || $[37] !== t11 || $[38] !== t12 || $[39] !== treeNode) {
121
+ if ($[35] !== t10 || $[36] !== t11 || $[37] !== t12 || $[38] !== treeNode) {
122
122
  t13 = /* @__PURE__ */ jsx(ErrorItemContainer, {
123
123
  treeNode,
124
- error,
125
124
  actions: t10,
126
125
  message: t11,
127
126
  scrollToElement: t12
128
127
  });
129
- $[35] = error;
130
- $[36] = t10;
131
- $[37] = t11;
132
- $[38] = t12;
133
- $[39] = treeNode;
134
- $[40] = t13;
135
- } else t13 = $[40];
128
+ $[35] = t10;
129
+ $[36] = t11;
130
+ $[37] = t12;
131
+ $[38] = treeNode;
132
+ $[39] = t13;
133
+ } else t13 = $[39];
136
134
  return t13;
137
135
  }
138
136
  if (error.type === "NoFilterMatches") {
139
137
  let t1;
140
- if ($[41] !== filterHierarchyLevel || $[42] !== getHierarchyLevelDetails || $[43] !== treeNode) {
138
+ if ($[40] !== filterHierarchyLevel || $[41] !== getHierarchyLevelDetails || $[42] !== treeNode) {
141
139
  t1 = () => {
142
140
  const hierarchyLevelDetails_0 = getHierarchyLevelDetails(treeNode.id);
143
141
  hierarchyLevelDetails_0 && filterHierarchyLevel?.(hierarchyLevelDetails_0);
144
142
  };
145
- $[41] = filterHierarchyLevel;
146
- $[42] = getHierarchyLevelDetails;
147
- $[43] = treeNode;
148
- $[44] = t1;
149
- } else t1 = $[44];
143
+ $[40] = filterHierarchyLevel;
144
+ $[41] = getHierarchyLevelDetails;
145
+ $[42] = treeNode;
146
+ $[43] = t1;
147
+ } else t1 = $[43];
150
148
  let t2;
151
- if ($[45] !== translate) {
149
+ if ($[44] !== translate) {
152
150
  t2 = translate("noFilteredChildrenChangeFilter");
153
- $[45] = translate;
154
- $[46] = t2;
155
- } else t2 = $[46];
151
+ $[44] = translate;
152
+ $[45] = t2;
153
+ } else t2 = $[45];
156
154
  let t3;
157
- if ($[47] !== t1 || $[48] !== t2) {
155
+ if ($[46] !== t1 || $[47] !== t2) {
158
156
  t3 = [{
159
157
  action: t1,
160
158
  label: t2,
161
159
  condition: _temp
162
160
  }];
163
- $[47] = t1;
164
- $[48] = t2;
165
- $[49] = t3;
166
- } else t3 = $[49];
161
+ $[46] = t1;
162
+ $[47] = t2;
163
+ $[48] = t3;
164
+ } else t3 = $[48];
167
165
  let t4;
168
- if ($[50] !== translate) {
166
+ if ($[49] !== translate) {
169
167
  t4 = translate("noFilteredChildren");
170
- $[50] = translate;
171
- $[51] = t4;
172
- } else t4 = $[51];
168
+ $[49] = translate;
169
+ $[50] = t4;
170
+ } else t4 = $[50];
173
171
  let t5;
174
- if ($[52] !== scrollToNode || $[53] !== treeNode) {
172
+ if ($[51] !== scrollToNode || $[52] !== treeNode) {
175
173
  t5 = () => scrollToNode(treeNode);
176
- $[52] = scrollToNode;
177
- $[53] = treeNode;
178
- $[54] = t5;
179
- } else t5 = $[54];
174
+ $[51] = scrollToNode;
175
+ $[52] = treeNode;
176
+ $[53] = t5;
177
+ } else t5 = $[53];
180
178
  let t6;
181
- if ($[55] !== error || $[56] !== t3 || $[57] !== t4 || $[58] !== t5 || $[59] !== treeNode) {
179
+ if ($[54] !== t3 || $[55] !== t4 || $[56] !== t5 || $[57] !== treeNode) {
182
180
  t6 = /* @__PURE__ */ jsx(ErrorItemContainer, {
183
181
  treeNode,
184
- error,
185
182
  actions: t3,
186
183
  message: t4,
187
184
  scrollToElement: t5
188
185
  });
189
- $[55] = error;
190
- $[56] = t3;
191
- $[57] = t4;
192
- $[58] = t5;
193
- $[59] = treeNode;
194
- $[60] = t6;
195
- } else t6 = $[60];
186
+ $[54] = t3;
187
+ $[55] = t4;
188
+ $[56] = t5;
189
+ $[57] = treeNode;
190
+ $[58] = t6;
191
+ } else t6 = $[58];
196
192
  return t6;
197
193
  }
198
194
  if (error.type === "ChildrenLoad") {
199
195
  let t1;
200
- if ($[61] !== reloadTree || $[62] !== treeNode) {
196
+ if ($[59] !== reloadTree || $[60] !== treeNode) {
201
197
  t1 = () => reloadTree({ parentNodeId: treeNode.id });
202
- $[61] = reloadTree;
203
- $[62] = treeNode;
204
- $[63] = t1;
205
- } else t1 = $[63];
198
+ $[59] = reloadTree;
199
+ $[60] = treeNode;
200
+ $[61] = t1;
201
+ } else t1 = $[61];
206
202
  let t2;
207
- if ($[64] !== translate) {
203
+ if ($[62] !== translate) {
208
204
  t2 = translate("retry");
209
- $[64] = translate;
210
- $[65] = t2;
211
- } else t2 = $[65];
205
+ $[62] = translate;
206
+ $[63] = t2;
207
+ } else t2 = $[63];
212
208
  let t3;
213
- if ($[66] !== t1 || $[67] !== t2) {
209
+ if ($[64] !== t1 || $[65] !== t2) {
214
210
  t3 = [{
215
211
  action: t1,
216
212
  label: t2,
217
213
  condition: _temp2
218
214
  }];
219
- $[66] = t1;
220
- $[67] = t2;
221
- $[68] = t3;
222
- } else t3 = $[68];
215
+ $[64] = t1;
216
+ $[65] = t2;
217
+ $[66] = t3;
218
+ } else t3 = $[66];
223
219
  let t4;
224
- if ($[69] !== translate) {
220
+ if ($[67] !== translate) {
225
221
  t4 = translate("failedToCreateHierarchy");
226
- $[69] = translate;
227
- $[70] = t4;
228
- } else t4 = $[70];
222
+ $[67] = translate;
223
+ $[68] = t4;
224
+ } else t4 = $[68];
229
225
  let t5;
230
- if ($[71] !== scrollToNode || $[72] !== treeNode) {
226
+ if ($[69] !== scrollToNode || $[70] !== treeNode) {
231
227
  t5 = () => scrollToNode(treeNode);
232
- $[71] = scrollToNode;
233
- $[72] = treeNode;
234
- $[73] = t5;
235
- } else t5 = $[73];
228
+ $[69] = scrollToNode;
229
+ $[70] = treeNode;
230
+ $[71] = t5;
231
+ } else t5 = $[71];
236
232
  let t6;
237
- if ($[74] !== error || $[75] !== t3 || $[76] !== t4 || $[77] !== t5 || $[78] !== treeNode) {
233
+ if ($[72] !== t3 || $[73] !== t4 || $[74] !== t5 || $[75] !== treeNode) {
238
234
  t6 = /* @__PURE__ */ jsx(ErrorItemContainer, {
239
235
  treeNode,
240
- error,
241
236
  actions: t3,
242
237
  message: t4,
243
238
  scrollToElement: t5
244
239
  });
245
- $[74] = error;
246
- $[75] = t3;
247
- $[76] = t4;
248
- $[77] = t5;
249
- $[78] = treeNode;
250
- $[79] = t6;
251
- } else t6 = $[79];
240
+ $[72] = t3;
241
+ $[73] = t4;
242
+ $[74] = t5;
243
+ $[75] = treeNode;
244
+ $[76] = t6;
245
+ } else t6 = $[76];
252
246
  return t6;
253
247
  }
254
248
  let t1;
255
- if ($[80] !== scrollToNode || $[81] !== treeNode) {
249
+ if ($[77] !== scrollToNode || $[78] !== treeNode) {
256
250
  t1 = () => scrollToNode(treeNode);
257
- $[80] = scrollToNode;
258
- $[81] = treeNode;
259
- $[82] = t1;
260
- } else t1 = $[82];
251
+ $[77] = scrollToNode;
252
+ $[78] = treeNode;
253
+ $[79] = t1;
254
+ } else t1 = $[79];
261
255
  let t2;
262
- if ($[83] !== error.message || $[84] !== t1 || $[85] !== treeNode) {
256
+ if ($[80] !== error.message || $[81] !== t1 || $[82] !== treeNode) {
263
257
  t2 = /* @__PURE__ */ jsx(ErrorItemContainer, {
264
258
  treeNode,
265
259
  message: error.message,
266
260
  scrollToElement: t1
267
261
  });
268
- $[83] = error.message;
269
- $[84] = t1;
270
- $[85] = treeNode;
271
- $[86] = t2;
272
- } else t2 = $[86];
262
+ $[80] = error.message;
263
+ $[81] = t1;
264
+ $[82] = treeNode;
265
+ $[83] = t2;
266
+ } else t2 = $[83];
273
267
  return t2;
274
268
  }
275
269
  function _temp2() {
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorItemRenderer.js","names":["Anchor","Text","unstable_ErrorRegion","ErrorRegion","MAX_LIMIT_OVERRIDE","useTranslation","JSX","HierarchyLevelDetails","TreeRendererProps","ErrorInfo","TreeNode","ErrorItemRendererProps","Pick","treeNode","Omit","error","reloadTree","options","parentNodeId","scrollToNode","filterHierarchyLevel","hierarchyLevelDetails","ErrorItemRenderer","t0","$","_c","getHierarchyLevelDetails","translate","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 { ErrorInfo, TreeNode } from \"../TreeNode.js\";\n\n/** @alpha */\nexport interface ErrorItemRendererProps extends Pick<TreeRendererProps, \"getHierarchyLevelDetails\"> {\n /** The tree node associated with the error. Used for displaying the node label in error messages and for scrolling to the node. */\n treeNode: Omit<TreeNode, \"errors\">;\n /** The error to render. */\n error: ErrorInfo;\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: (treeNode: Omit<TreeNode, \"errors\">) => 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 treeNode,\n error,\n getHierarchyLevelDetails,\n filterHierarchyLevel,\n reloadTree,\n scrollToNode,\n}: ErrorItemRendererProps): JSX.Element {\n const translate = useTranslation();\n\n if (error.type === \"ResultSetTooLarge\") {\n const limit = error.resultSetSizeLimit;\n const onOverrideLimit = () => getHierarchyLevelDetails(treeNode.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE);\n return (\n <ErrorItemContainer\n treeNode={treeNode}\n error={error}\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(treeNode.id);\n hierarchyLevelDetails && filterHierarchyLevel?.(hierarchyLevelDetails);\n },\n label: translate(\"increaseHierarchyLimitWithFiltering\"),\n condition: () => !!filterHierarchyLevel && !!treeNode.isFilterable,\n },\n ]}\n message={translate(\"resultLimitExceeded\").replace(\"{{limit}}\", limit.toString())}\n scrollToElement={() => scrollToNode(treeNode)}\n />\n );\n }\n if (error.type === \"NoFilterMatches\") {\n return (\n <ErrorItemContainer\n treeNode={treeNode}\n error={error}\n actions={[\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails(treeNode.id);\n hierarchyLevelDetails && filterHierarchyLevel?.(hierarchyLevelDetails);\n },\n label: translate(\"noFilteredChildrenChangeFilter\"),\n condition: () => true,\n },\n ]}\n message={translate(\"noFilteredChildren\")}\n scrollToElement={() => scrollToNode(treeNode)}\n />\n );\n }\n if (error.type === \"ChildrenLoad\") {\n return (\n <ErrorItemContainer\n treeNode={treeNode}\n error={error}\n actions={[\n { action: () => reloadTree({ parentNodeId: treeNode.id }), label: translate(\"retry\"), condition: () => true },\n ]}\n message={translate(\"failedToCreateHierarchy\")}\n scrollToElement={() => scrollToNode(treeNode)}\n />\n );\n }\n return (\n <ErrorItemContainer treeNode={treeNode} message={error.message} scrollToElement={() => scrollToNode(treeNode)} />\n );\n}\n\ntype ErrorItemContainerProps = {\n treeNode: Omit<TreeNode, \"errors\">;\n message: string;\n actions?: { action: () => void; label: string; condition: () => boolean }[];\n} & Pick<MessageWithLinkProps, \"scrollToElement\">;\n\nfunction ErrorItemContainer({ treeNode, message, actions, scrollToElement }: ErrorItemContainerProps) {\n return (\n <ErrorRegion.Item\n message={<MessageWithLink linkLabel={treeNode.label} scrollToElement={scrollToElement} message={message} />}\n messageId={treeNode.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":";;;;;;;;;;;;;;;;AAqCA,SAAOsB,kBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,GAAA;CAA2B,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B,IAAA,KAAA6C,aAAA;AAAA7C,IAAA,KAAAe;AAAAf,IAAA,KAAAgB;AAAAhB,IAAA,MAAAoB;OAAAA,MAAApB,EAAA;AAAA,QANNoB"}
1
+ {"version":3,"file":"ErrorItemRenderer.js","names":["Anchor","Text","unstable_ErrorRegion","ErrorRegion","MAX_LIMIT_OVERRIDE","useTranslation","JSX","HierarchyLevelDetails","TreeRendererProps","ErrorInfo","TreeNode","ErrorItemRendererProps","Pick","treeNode","Omit","error","reloadTree","options","parentNodeId","scrollToNode","filterHierarchyLevel","hierarchyLevelDetails","ErrorItemRenderer","t0","$","_c","getHierarchyLevelDetails","translate","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 { ErrorInfo, TreeNode } from \"../TreeNode.js\";\n\n/** @alpha */\nexport interface ErrorItemRendererProps extends Pick<TreeRendererProps, \"getHierarchyLevelDetails\"> {\n /** The tree node associated with the error. Used for displaying the node label in error messages and for scrolling to the node. */\n treeNode: Omit<TreeNode, \"errors\">;\n /** The error to render. */\n error: ErrorInfo;\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: (treeNode: Omit<TreeNode, \"errors\">) => 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 treeNode,\n error,\n getHierarchyLevelDetails,\n filterHierarchyLevel,\n reloadTree,\n scrollToNode,\n}: ErrorItemRendererProps): JSX.Element {\n const translate = useTranslation();\n\n if (error.type === \"ResultSetTooLarge\") {\n const limit = error.resultSetSizeLimit;\n const onOverrideLimit = () => getHierarchyLevelDetails(treeNode.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE);\n return (\n <ErrorItemContainer\n treeNode={treeNode}\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(treeNode.id);\n hierarchyLevelDetails && filterHierarchyLevel?.(hierarchyLevelDetails);\n },\n label: translate(\"increaseHierarchyLimitWithFiltering\"),\n condition: () => !!filterHierarchyLevel && !!treeNode.isFilterable,\n },\n ]}\n message={translate(\"resultLimitExceeded\").replace(\"{{limit}}\", limit.toString())}\n scrollToElement={() => scrollToNode(treeNode)}\n />\n );\n }\n if (error.type === \"NoFilterMatches\") {\n return (\n <ErrorItemContainer\n treeNode={treeNode}\n actions={[\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails(treeNode.id);\n hierarchyLevelDetails && filterHierarchyLevel?.(hierarchyLevelDetails);\n },\n label: translate(\"noFilteredChildrenChangeFilter\"),\n condition: () => true,\n },\n ]}\n message={translate(\"noFilteredChildren\")}\n scrollToElement={() => scrollToNode(treeNode)}\n />\n );\n }\n if (error.type === \"ChildrenLoad\") {\n return (\n <ErrorItemContainer\n treeNode={treeNode}\n actions={[\n { action: () => reloadTree({ parentNodeId: treeNode.id }), label: translate(\"retry\"), condition: () => true },\n ]}\n message={translate(\"failedToCreateHierarchy\")}\n scrollToElement={() => scrollToNode(treeNode)}\n />\n );\n }\n return (\n <ErrorItemContainer treeNode={treeNode} message={error.message} scrollToElement={() => scrollToNode(treeNode)} />\n );\n}\n\ntype ErrorItemContainerProps = {\n treeNode: Omit<TreeNode, \"errors\">;\n message: string;\n actions?: { action: () => void; label: string; condition: () => boolean }[];\n} & Pick<MessageWithLinkProps, \"scrollToElement\">;\n\nfunction ErrorItemContainer({ treeNode, message, actions, scrollToElement }: ErrorItemContainerProps) {\n return (\n <ErrorRegion.Item\n message={<MessageWithLink linkLabel={treeNode.label} scrollToElement={scrollToElement} message={message} />}\n messageId={treeNode.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[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AA6C,aAAA;AAAA7C,IAAA,KAAAe;AAAAf,IAAA,KAAAgB;AAAAhB,IAAA,MAAAoB;OAAAA,MAAApB,EAAA;AAAA,QANNoB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-hierarchies-react",
3
- "version": "2.0.0-alpha.61",
3
+ "version": "2.0.0-alpha.62",
4
4
  "description": "React components based on `@itwin/presentation-hierarchies`",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -41,97 +41,74 @@
41
41
  "./package.json": "./package.json"
42
42
  },
43
43
  "dependencies": {
44
- "@itwin/core-bentley": "^5.7.2",
44
+ "@itwin/core-bentley": "^5.8.0",
45
+ "@stratakit/bricks": "^0.5.4",
46
+ "@stratakit/structures": "^0.5.6",
45
47
  "@tanstack/react-virtual": "^3.13.13",
46
48
  "classnames": "^2.5.1",
47
49
  "immer": "^10.2.0",
48
50
  "react-compiler-runtime": "^1.0.0",
49
51
  "react-error-boundary": "^4.1.2",
50
52
  "rxjs": "^7.8.2",
51
- "@itwin/presentation-shared": "2.0.0-alpha.9",
52
- "@itwin/unified-selection": "^1.6.8",
53
- "@itwin/presentation-hierarchies": "2.0.0-alpha.14"
53
+ "@itwin/presentation-hierarchies": "2.0.0-alpha.15",
54
+ "@itwin/presentation-shared": "2.0.0-alpha.10",
55
+ "@itwin/unified-selection": "^1.7.1-alpha.0"
54
56
  },
55
57
  "peerDependencies": {
56
- "@stratakit/bricks": "^0.5.4",
57
58
  "@stratakit/foundations": "^0.4.7",
58
59
  "@stratakit/icons": "^0.3.1",
59
- "@stratakit/structures": "^0.5.6",
60
60
  "react": "^17.0 || ^18.0",
61
61
  "react-dom": "^17.0 || ^18.0"
62
62
  },
63
63
  "peerDependenciesMeta": {
64
- "@stratakit/bricks": {
65
- "optional": true
66
- },
67
64
  "@stratakit/foundations": {
68
65
  "optional": true
69
66
  },
70
- "@stratakit/structures": {
71
- "optional": true
72
- },
73
67
  "@stratakit/icons": {
74
68
  "optional": true
75
69
  }
76
70
  },
77
71
  "devDependencies": {
78
- "@itwin/build-tools": "^5.7.2",
72
+ "@itwin/build-tools": "^5.8.0",
79
73
  "@itwin/eslint-plugin": "5.1.0",
80
74
  "@rolldown/plugin-babel": "^0.2.2",
81
- "@stratakit/bricks": "^0.5.4",
82
75
  "@stratakit/foundations": "^0.4.7",
83
76
  "@stratakit/icons": "^0.3.1",
84
- "@stratakit/structures": "^0.5.6",
85
77
  "@testing-library/dom": "^10.4.1",
86
78
  "@testing-library/react": "^16.3.2",
87
79
  "@testing-library/user-event": "^14.6.1",
88
- "@types/chai": "^5.2.3",
89
- "@types/chai-as-promised": "^8.0.2",
90
- "@types/jsdom": "^21.1.7",
91
- "@types/mocha": "^10.0.10",
92
- "@types/node": "^24.12.0",
80
+ "@types/node": "^24.12.2",
93
81
  "@types/react": "^18.3.28",
94
82
  "@types/react-dom": "^18.3.7",
95
- "@types/sinon": "^17.0.4",
96
- "@types/sinon-chai": "^4.0.0",
97
83
  "@vitejs/plugin-react": "^6.0.1",
98
84
  "babel-plugin-react-compiler": "^1.0.0",
99
- "chai": "^5.3.3",
100
- "chai-as-promised": "^8.0.2",
101
- "cpx2": "^7.0.2",
102
- "cross-env": "^7.0.3",
85
+ "@vitest/coverage-v8": "^4.1.3",
103
86
  "eslint": "^9.39.4",
104
87
  "eslint-plugin-react": "^7.37.5",
105
88
  "eslint-plugin-react-hooks": "^7.0.1",
106
- "fast-glob": "^3.3.3",
107
- "global-jsdom": "^26.0.0",
108
- "ignore-styles": "^5.0.1",
109
- "jsdom": "^26.1.0",
110
- "mocha": "^11.7.5",
89
+ "happy-dom": "^20.8.9",
111
90
  "react": "^18.3.1",
112
91
  "react-dom": "^18.3.1",
113
92
  "rimraf": "^6.1.3",
114
- "sinon": "^19.0.5",
115
- "sinon-chai": "^4.0.1",
116
93
  "tsdown": "^0.21.4",
117
94
  "typescript": "~5.7.3",
118
- "vite": "^8.0.0",
95
+ "vitest": "^4.1.3",
119
96
  "presentation-test-utilities": "0.0.1"
120
97
  },
121
98
  "scripts": {
122
- "build": "tsdown && npm run -s build:locale && npm run -s copy && npm run -s build:test",
99
+ "build": "npm run -s typecheck && tsdown && npm run -s build:locale && npm run -s copy",
123
100
  "build:locale": "tsc -p tsconfig.utils.json && node ./lib/build/utils/BuildLocale.js",
124
101
  "copy": "npm run -s copy:css && npm run -s copy:assets",
125
102
  "copy:css": "cpx \"./src/**/*.css\" \"./lib\"",
126
103
  "copy:assets": "cpx \"./src/public/**/*\" \"./lib/public\"",
127
- "build:test": "tsdown --config tsdown.test.config.ts",
128
104
  "clean": "rimraf lib build",
129
105
  "cover": "npm -s test",
130
106
  "lint": "eslint \"./src/**/*.{ts,tsx}\"",
131
- "test:dev": "node --experimental-test-module-mocks --enable-source-maps --import presentation-test-utilities/node-hooks/ignore-styles ./node_modules/mocha/bin/mocha.js --config ./.mocharc.json",
132
- "test": "npm run test:dev -- --parallel --jobs=4",
107
+ "test": "vitest run",
108
+ "test:watch": "vitest",
133
109
  "extract-api": "betools extract-api --entry=lib/presentation-hierarchies-react-extract --apiReportFolder=./api --apiReportTempFolder=./api/temp --apiSummaryFolder=./api --includeUnexportedApis",
134
110
  "check-internal": "node ../../scripts/checkInternal.js --apiSummary ./api/presentation-hierarchies-react-extract.api.md",
111
+ "typecheck": "tsc -p tsconfig.json --noEmit",
135
112
  "update-extractions": "node ../../scripts/updateExtractions.js --targets=./README.md",
136
113
  "check-extractions": "node ../../scripts/updateExtractions.js --targets=./README.md --check",
137
114
  "validate-markdowns": "node ../../scripts/validateMarkdowns.js README.md"