@itwin/presentation-hierarchies-react 2.0.0-alpha.5 → 2.0.0-alpha.50
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 +892 -7
- package/README.md +28 -70
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +85 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.js +6 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +28 -29
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js +1 -7
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts +7 -5
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +6 -6
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +24 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js +53 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +12 -10
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +7 -22
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +33 -71
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +63 -64
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts +8 -0
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js +39 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +31 -16
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +24 -6
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +29 -33
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +6 -29
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +31 -27
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +23 -9
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +16 -29
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +27 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +74 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +48 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +73 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +133 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/{itwinui → stratakit}/LocalizationContext.js +17 -5
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +16 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +42 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts +45 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js +36 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +30 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +30 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +20 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +29 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +57 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +71 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.css +25 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +46 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +132 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +75 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +193 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react.d.ts +14 -10
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +11 -9
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +55 -47
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts +0 -15
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js +0 -22
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts +0 -21
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +0 -73
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts +0 -25
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +0 -40
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +0 -23
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +0 -72
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +0 -40
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +0 -80
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +0 -48
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeLoader.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAc,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"TreeLoader.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAc,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAIvG,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkC1C,gBAAgB;AAChB,MAAM,OAAO,UAAU;IAIX;IACA;IACA;IALF,kBAAkB,CAA8D;IAExF,YACU,kBAAqC,EACrC,yBAA+H,EAC/H,qBAA0G,EAClH,iBAA+E;QAHvE,uBAAkB,GAAlB,kBAAkB,CAAmB;QACrC,8BAAyB,GAAzB,yBAAyB,CAAsG;QAC/H,0BAAqB,GAArB,qBAAqB,CAAqF;QAGlH,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,IAAI,oBAAoB,CAAC,YAAY,CAAC;IACnF,CAAC;IAEO,YAAY,CAAC,EAAE,MAAM,EAAE,wBAAwB,EAAE,SAAS,EAAE,WAAW,EAAgD;QAC7H,MAAM,EAAE,cAAc,EAAE,uBAAuB,EAAE,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;QACrF,MAAM,cAAc,GAAG,GAAG,MAAM,CAAC,EAAE,IAAI,QAAQ,EAAE,CAAC;QAClD,MAAM,qBAAqB,GAAG,2BAA2B,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,IAA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AAC,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAY;IACpC,MAAM,WAAW,GAAG,KAA+B,CAAC;IACpD,OAAO,WAAW,CAAC,KAAK,KAAK,SAAS,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAChG,CAAC;AAED,SAAS,cAAc,CAAC,KAAY;IAClC,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,iDAAiD,CAAC,CAAC;AACnF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { catchError, EMPTY, expand, filter, from, map, mergeMap, Observable, of, toArray } from \"rxjs\";\nimport { GenericInstanceFilter, HierarchyNode, HierarchyProvider, RowsLimitExceededError } from \"@itwin/presentation-hierarchies\";\nimport { ErrorInfo } from \"../TreeNode.js\";\nimport { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\nimport { createNodeId } from \"./Utils.js\";\n\n/** @internal */\nexport type LoadedTreePart = {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n} & (\n | {\n loadedNodes: TreeModelHierarchyNode[];\n }\n | {\n error: ErrorInfo;\n }\n);\n\n/** @internal */\nexport interface HierarchyLevelOptions {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n}\n\n/** @internal */\nexport interface LoadNodesOptions {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n getHierarchyLevelOptions: (node: TreeModelRootNode | TreeModelHierarchyNode) => HierarchyLevelOptions;\n shouldLoadChildren: (node: TreeModelHierarchyNode) => boolean;\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n ignoreCache?: boolean;\n}\n\n/** @internal */\nexport interface ITreeLoader {\n loadNodes(options: LoadNodesOptions): Observable<LoadedTreePart>;\n}\n\n/** @internal */\nexport class TreeLoader implements ITreeLoader {\n private _treeNodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string;\n\n constructor(\n private _hierarchyProvider: HierarchyProvider,\n private _onHierarchyLimitExceeded: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void,\n private _onHierarchyLoadError: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void,\n treeNodeIdFactory?: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string,\n ) {\n this._treeNodeIdFactory = treeNodeIdFactory ?? /* c8 ignore next */ createNodeId;\n }\n\n private loadChildren({ parent, getHierarchyLevelOptions, buildNode, ignoreCache }: Omit<LoadNodesOptions, \"shouldLoadChildren\">) {\n const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);\n const infoNodeIdBase = `${parent.id ?? \"<root>\"}`;\n const treeModelNodesFactory = createTreeModelNodesFactory({ buildNode, treeNodeIdFactory: this._treeNodeIdFactory });\n return from(\n this._hierarchyProvider.getNodes({\n parentNode: parent.nodeData,\n hierarchyLevelSizeLimit,\n instanceFilter,\n ignoreCache,\n }),\n ).pipe(\n toArray(),\n map((childNodes): LoadedTreePart => {\n return instanceFilter && childNodes.length === 0\n ? {\n parent,\n error: {\n id: `${infoNodeIdBase}-no-filter-matches`,\n type: \"NoFilterMatches\" as const,\n },\n }\n : {\n parent,\n loadedNodes: childNodes.map(treeModelNodesFactory),\n };\n }),\n catchError((err) => {\n let hierarchyLoadErrorType: \"unknown\" | \"timeout\" = \"unknown\";\n if (err instanceof Error) {\n if (isRowsLimitError(err)) {\n this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: err.limit });\n return of({\n parent,\n error: { id: `${infoNodeIdBase}-${err.message}`, type: \"ResultSetTooLarge\" as const, resultSetSizeLimit: err.limit },\n });\n }\n if (isTimeoutError(err)) {\n hierarchyLoadErrorType = \"timeout\";\n }\n }\n\n this._onHierarchyLoadError({ parentId: parent.id, type: hierarchyLoadErrorType, error: err });\n return of({\n parent,\n error: {\n id: `${infoNodeIdBase}-ChildrenLoad`,\n type: \"ChildrenLoad\" as const,\n message: \"Failed to create hierarchy level\",\n },\n });\n }),\n );\n }\n\n public loadNodes({ shouldLoadChildren, ...options }: LoadNodesOptions) {\n return this.loadChildren(options).pipe(\n expand((loadedPart) =>\n \"loadedNodes\" in loadedPart\n ? from(loadedPart.loadedNodes).pipe(\n filter((node) => shouldLoadChildren(node)),\n mergeMap((node) => this.loadChildren({ ...options, parent: node })),\n )\n : EMPTY,\n ),\n );\n }\n}\n\nfunction createTreeModelNodesFactory({\n buildNode,\n treeNodeIdFactory,\n}: {\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n treeNodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string;\n}): (node: HierarchyNode) => TreeModelHierarchyNode {\n return (node: HierarchyNode) => {\n const modelNode: TreeModelHierarchyNode = {\n id: treeNodeIdFactory(node),\n children: node.children,\n label: node.label,\n nodeData: node,\n };\n return buildNode ? buildNode(modelNode) : modelNode;\n };\n}\n\nfunction isRowsLimitError(error: Error): error is RowsLimitExceededError {\n const asRowsError = error as RowsLimitExceededError;\n return asRowsError.limit !== undefined && asRowsError.message.includes(\"Query rows limit of\");\n}\n\nfunction isTimeoutError(error: Error) {\n return error.message.includes(\"query too long to execute or server is too busy\");\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GenericInstanceFilter, HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
+
import { ErrorInfo } from "../TreeNode.js";
|
|
2
3
|
import { SelectionChangeType } from "../UseSelectionHandler.js";
|
|
3
4
|
/** @internal */
|
|
4
5
|
export interface TreeModelRootNode {
|
|
@@ -7,6 +8,7 @@ export interface TreeModelRootNode {
|
|
|
7
8
|
hierarchyLimit?: number | "unbounded";
|
|
8
9
|
instanceFilter?: GenericInstanceFilter;
|
|
9
10
|
isLoading?: boolean;
|
|
11
|
+
error?: ErrorInfo;
|
|
10
12
|
}
|
|
11
13
|
/** @internal */
|
|
12
14
|
export interface TreeModelHierarchyNode {
|
|
@@ -19,39 +21,14 @@ export interface TreeModelHierarchyNode {
|
|
|
19
21
|
isSelected?: boolean;
|
|
20
22
|
hierarchyLimit?: number | "unbounded";
|
|
21
23
|
instanceFilter?: GenericInstanceFilter;
|
|
24
|
+
error?: ErrorInfo;
|
|
22
25
|
}
|
|
23
26
|
/** @internal */
|
|
24
|
-
export
|
|
25
|
-
id: string;
|
|
26
|
-
parentId: string | undefined;
|
|
27
|
-
type: "Unknown";
|
|
28
|
-
message: string;
|
|
29
|
-
}
|
|
30
|
-
/** @internal */
|
|
31
|
-
export interface TreeModelNoFilterMatchesInfoNode {
|
|
32
|
-
id: string;
|
|
33
|
-
parentId: string | undefined;
|
|
34
|
-
type: "NoFilterMatches";
|
|
35
|
-
}
|
|
36
|
-
/** @internal */
|
|
37
|
-
export interface TreeModelResultSetTooLargeInfoNode {
|
|
38
|
-
id: string;
|
|
39
|
-
parentId: string | undefined;
|
|
40
|
-
type: "ResultSetTooLarge";
|
|
41
|
-
resultSetSizeLimit: number;
|
|
42
|
-
}
|
|
43
|
-
/** @internal */
|
|
44
|
-
export type TreeModelInfoNode = TreeModelGenericInfoNode | TreeModelResultSetTooLargeInfoNode | TreeModelNoFilterMatchesInfoNode;
|
|
45
|
-
/** @internal */
|
|
46
|
-
export type TreeModelNode = TreeModelHierarchyNode | TreeModelInfoNode;
|
|
47
|
-
/** @internal */
|
|
48
|
-
export declare function isTreeModelHierarchyNode(node: TreeModelHierarchyNode | TreeModelInfoNode | TreeModelRootNode): node is TreeModelHierarchyNode;
|
|
49
|
-
/** @internal */
|
|
50
|
-
export declare function isTreeModelInfoNode(node: TreeModelHierarchyNode | TreeModelInfoNode | TreeModelRootNode): node is TreeModelInfoNode;
|
|
27
|
+
export declare function isTreeModelHierarchyNode(node: TreeModelHierarchyNode | ErrorInfo | TreeModelRootNode): node is TreeModelHierarchyNode;
|
|
51
28
|
/** @internal */
|
|
52
29
|
export interface TreeModel {
|
|
53
30
|
parentChildMap: Map<string | undefined, string[]>;
|
|
54
|
-
idToNode: Map<string,
|
|
31
|
+
idToNode: Map<string, TreeModelHierarchyNode>;
|
|
55
32
|
rootNode: TreeModelRootNode;
|
|
56
33
|
}
|
|
57
34
|
/** @internal */
|
|
@@ -64,7 +41,7 @@ export declare namespace TreeModel {
|
|
|
64
41
|
function setInstanceFilter(model: TreeModel, nodeId: string | undefined, filter?: GenericInstanceFilter): boolean;
|
|
65
42
|
function selectNodes(model: TreeModel, nodeIds: Array<string>, changeType: SelectionChangeType): void;
|
|
66
43
|
function isNodeSelected(model: TreeModel, nodeId: string): boolean;
|
|
67
|
-
function getNode(model: TreeModel, nodeId: string | undefined):
|
|
44
|
+
function getNode(model: TreeModel, nodeId: string | undefined): TreeModelHierarchyNode | TreeModelRootNode | undefined;
|
|
68
45
|
function setIsLoading(model: TreeModel, nodeId: string | undefined, isLoading: boolean): void;
|
|
69
46
|
}
|
|
70
47
|
//# sourceMappingURL=TreeModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeModel.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeModel.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,gBAAgB;AAChB,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,SAAS,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACtC,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,SAAS,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"TreeModel.d.ts","sourceRoot":"","sources":["../../../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|
|
9
9
|
/** @internal */
|
|
10
|
-
export function isTreeModelInfoNode(node) {
|
|
11
|
-
return "type" in node && node.type !== undefined;
|
|
12
|
-
}
|
|
13
|
-
/** @internal */
|
|
14
10
|
export var TreeModel;
|
|
15
11
|
(function (TreeModel) {
|
|
16
12
|
function expandNode(model, nodeId, isExpanded) {
|
|
17
13
|
const node = model.idToNode.get(nodeId);
|
|
18
|
-
if (!node
|
|
14
|
+
if (!node) {
|
|
19
15
|
return "none";
|
|
20
16
|
}
|
|
21
17
|
node.isExpanded = isExpanded;
|
|
22
|
-
if (!isExpanded
|
|
18
|
+
if (!isExpanded) {
|
|
23
19
|
return "none";
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
if (!children) {
|
|
21
|
+
if (node.error?.type === "ChildrenLoad") {
|
|
27
22
|
node.isLoading = true;
|
|
28
|
-
|
|
23
|
+
// remove subtree if there `ChildrenLoad` error info in order to attempt reloading children
|
|
24
|
+
TreeModel.removeSubTree(model, nodeId);
|
|
25
|
+
return "reloadChildren";
|
|
29
26
|
}
|
|
30
|
-
if (children
|
|
27
|
+
if (!node.children) {
|
|
31
28
|
return "none";
|
|
32
29
|
}
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
|
|
30
|
+
const children = model.parentChildMap.get(node.id);
|
|
31
|
+
if (!children) {
|
|
32
|
+
node.isLoading = true;
|
|
33
|
+
return "loadChildren";
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
TreeModel.removeSubTree(model, nodeId);
|
|
39
|
-
node.isLoading = true;
|
|
40
|
-
return "reloadChildren";
|
|
35
|
+
return "none";
|
|
41
36
|
}
|
|
42
37
|
TreeModel.expandNode = expandNode;
|
|
43
38
|
/** @internal */
|
|
44
39
|
function addHierarchyPart(model, rootId, hierarchyPart) {
|
|
45
40
|
removeSubTree(model, rootId);
|
|
41
|
+
model.rootNode.error = hierarchyPart.rootNode.error;
|
|
46
42
|
for (const [parentId, children] of hierarchyPart.parentChildMap) {
|
|
47
43
|
model.parentChildMap.set(parentId, children);
|
|
48
44
|
}
|
|
@@ -51,13 +47,14 @@ export var TreeModel;
|
|
|
51
47
|
}
|
|
52
48
|
const parentNode = rootId !== undefined ? model.idToNode.get(rootId) : model.rootNode;
|
|
53
49
|
/* c8 ignore next 3*/
|
|
54
|
-
if (!parentNode
|
|
50
|
+
if (!parentNode) {
|
|
55
51
|
return;
|
|
56
52
|
}
|
|
57
53
|
parentNode.isLoading = false;
|
|
58
54
|
}
|
|
59
55
|
TreeModel.addHierarchyPart = addHierarchyPart;
|
|
60
56
|
function removeSubTree(model, parentId) {
|
|
57
|
+
clearNodeError(model, parentId);
|
|
61
58
|
const currentChildren = model.parentChildMap.get(parentId);
|
|
62
59
|
if (!currentChildren) {
|
|
63
60
|
return;
|
|
@@ -65,7 +62,7 @@ export var TreeModel;
|
|
|
65
62
|
model.parentChildMap.delete(parentId);
|
|
66
63
|
for (const childId of currentChildren) {
|
|
67
64
|
const childNode = model.idToNode.get(childId);
|
|
68
|
-
if (childNode
|
|
65
|
+
if (childNode) {
|
|
69
66
|
removeSubTree(model, childNode.id);
|
|
70
67
|
}
|
|
71
68
|
model.idToNode.delete(childId);
|
|
@@ -80,7 +77,7 @@ export var TreeModel;
|
|
|
80
77
|
TreeModel.setHierarchyLimit = setHierarchyLimit;
|
|
81
78
|
function setInstanceFilter(model, nodeId, filter) {
|
|
82
79
|
return updateForReload(model, nodeId, (node) => {
|
|
83
|
-
if (filter &&
|
|
80
|
+
if (filter && node.id !== undefined) {
|
|
84
81
|
node.isExpanded = true;
|
|
85
82
|
}
|
|
86
83
|
node.instanceFilter = filter;
|
|
@@ -90,16 +87,13 @@ export var TreeModel;
|
|
|
90
87
|
function selectNodes(model, nodeIds, changeType) {
|
|
91
88
|
if (changeType === "replace") {
|
|
92
89
|
for (const [nodeId, node] of model.idToNode) {
|
|
93
|
-
if (!isTreeModelHierarchyNode(node)) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
90
|
node.isSelected = !!nodeIds.find((id) => id === nodeId);
|
|
97
91
|
}
|
|
98
92
|
return;
|
|
99
93
|
}
|
|
100
94
|
for (const nodeId of nodeIds) {
|
|
101
95
|
const modelNode = model.idToNode.get(nodeId);
|
|
102
|
-
if (!modelNode
|
|
96
|
+
if (!modelNode) {
|
|
103
97
|
return;
|
|
104
98
|
}
|
|
105
99
|
modelNode.isSelected = changeType === "add";
|
|
@@ -108,7 +102,7 @@ export var TreeModel;
|
|
|
108
102
|
TreeModel.selectNodes = selectNodes;
|
|
109
103
|
function isNodeSelected(model, nodeId) {
|
|
110
104
|
const currentNode = model.idToNode.get(nodeId);
|
|
111
|
-
return !!currentNode &&
|
|
105
|
+
return !!currentNode && !!currentNode.isSelected;
|
|
112
106
|
}
|
|
113
107
|
TreeModel.isNodeSelected = isNodeSelected;
|
|
114
108
|
function getNode(model, nodeId) {
|
|
@@ -125,7 +119,7 @@ export var TreeModel;
|
|
|
125
119
|
}
|
|
126
120
|
const modelNode = model.idToNode.get(nodeId);
|
|
127
121
|
/* c8 ignore next 3*/
|
|
128
|
-
if (!modelNode
|
|
122
|
+
if (!modelNode) {
|
|
129
123
|
return;
|
|
130
124
|
}
|
|
131
125
|
modelNode.isLoading = isLoading;
|
|
@@ -140,7 +134,7 @@ function updateForReload(model, nodeId, update) {
|
|
|
140
134
|
return true;
|
|
141
135
|
}
|
|
142
136
|
const modelNode = model.idToNode.get(nodeId);
|
|
143
|
-
if (!modelNode
|
|
137
|
+
if (!modelNode) {
|
|
144
138
|
return false;
|
|
145
139
|
}
|
|
146
140
|
update(modelNode);
|
|
@@ -150,4 +144,14 @@ function updateForReload(model, nodeId, update) {
|
|
|
150
144
|
}
|
|
151
145
|
return false;
|
|
152
146
|
}
|
|
147
|
+
function clearNodeError(model, parentId) {
|
|
148
|
+
if (!parentId) {
|
|
149
|
+
return (model.rootNode.error = undefined);
|
|
150
|
+
}
|
|
151
|
+
const node = model.idToNode.get(parentId);
|
|
152
|
+
if (!node) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
node.error = undefined;
|
|
156
|
+
}
|
|
153
157
|
//# sourceMappingURL=TreeModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeModel.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeModel.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAwDhG,gBAAgB;AAChB,MAAM,UAAU,wBAAwB,CAAC,IAAoE;IAC3G,OAAO,UAAU,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC;AAC3D,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,mBAAmB,CAAC,IAAoE;IACtG,OAAO,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;AACnD,CAAC;AASD,gBAAgB;AAChB,MAAM,KAAW,SAAS,CA+HzB;AA/HD,WAAiB,SAAS;IACxB,SAAgB,UAAU,CAAC,KAAgB,EAAE,MAAc,EAAE,UAAmB;QAC9E,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE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,CAAC;AACf,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { GenericInstanceFilter, HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { 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}\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}\n\n/** @internal */\nexport interface TreeModelGenericInfoNode {\n id: string;\n parentId: string | undefined;\n type: \"Unknown\";\n message: string;\n}\n\n/** @internal */\nexport interface TreeModelNoFilterMatchesInfoNode {\n id: string;\n parentId: string | undefined;\n type: \"NoFilterMatches\";\n}\n\n/** @internal */\nexport interface TreeModelResultSetTooLargeInfoNode {\n id: string;\n parentId: string | undefined;\n type: \"ResultSetTooLarge\";\n resultSetSizeLimit: number;\n}\n\n/** @internal */\nexport type TreeModelInfoNode = TreeModelGenericInfoNode | TreeModelResultSetTooLargeInfoNode | TreeModelNoFilterMatchesInfoNode;\n\n/** @internal */\nexport type TreeModelNode = TreeModelHierarchyNode | TreeModelInfoNode;\n\n/** @internal */\nexport function isTreeModelHierarchyNode(node: TreeModelHierarchyNode | TreeModelInfoNode | TreeModelRootNode): node is TreeModelHierarchyNode {\n return \"nodeData\" in node && node.nodeData !== undefined;\n}\n\n/** @internal */\nexport function isTreeModelInfoNode(node: TreeModelHierarchyNode | TreeModelInfoNode | TreeModelRootNode): node is TreeModelInfoNode {\n return \"type\" in node && node.type !== undefined;\n}\n\n/** @internal */\nexport interface TreeModel {\n parentChildMap: Map<string | undefined, string[]>;\n idToNode: Map<string, TreeModelNode>;\n rootNode: TreeModelRootNode;\n}\n\n/** @internal */\nexport namespace TreeModel {\n export function expandNode(model: TreeModel, nodeId: string, isExpanded: boolean): \"none\" | \"loadChildren\" | \"reloadChildren\" {\n const node = model.idToNode.get(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return \"none\";\n }\n\n node.isExpanded = isExpanded;\n if (!isExpanded || !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 if (children.length !== 1) {\n return \"none\";\n }\n\n const firstChild = TreeModel.getNode(model, children[0]);\n if (!firstChild || !isTreeModelInfoNode(firstChild) || firstChild.type !== \"Unknown\") {\n return \"none\";\n }\n\n // remove subtree if there is only one `Unknown` info node in order to attempt reloading children\n TreeModel.removeSubTree(model, nodeId);\n node.isLoading = true;\n return \"reloadChildren\";\n }\n\n /** @internal */\n export function addHierarchyPart(model: TreeModel, rootId: string | undefined, hierarchyPart: TreeModel): void {\n removeSubTree(model, rootId);\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 || isTreeModelInfoNode(parentNode)) {\n return;\n }\n parentNode.isLoading = false;\n }\n\n export function removeSubTree(model: TreeModel, parentId: string | undefined): void {\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 && isTreeModelHierarchyNode(childNode)) {\n removeSubTree(model, childNode.id);\n }\n model.idToNode.delete(childId);\n }\n }\n\n export function setHierarchyLimit(model: TreeModel, nodeId: string | undefined, limit?: number | \"unbounded\"): boolean {\n return updateForReload(model, nodeId, (node) => {\n node.hierarchyLimit = limit;\n });\n }\n\n export function setInstanceFilter(model: TreeModel, nodeId: string | undefined, filter?: GenericInstanceFilter): boolean {\n return updateForReload(model, nodeId, (node) => {\n if (filter && isTreeModelHierarchyNode(node)) {\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 if (!isTreeModelHierarchyNode(node)) {\n continue;\n }\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 || !isTreeModelHierarchyNode(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 && isTreeModelHierarchyNode(currentNode) && !!currentNode.isSelected;\n }\n\n export function getNode(model: TreeModel, nodeId: string | undefined): TreeModelNode | 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 || !isTreeModelHierarchyNode(modelNode)) {\n return;\n }\n modelNode.isLoading = isLoading;\n }\n}\n\nfunction updateForReload(model: TreeModel, nodeId: string | undefined, update: (node: TreeModelHierarchyNode | TreeModelRootNode) => void) {\n TreeModel.removeSubTree(model, nodeId);\n if (nodeId === undefined) {\n update(model.rootNode);\n model.rootNode.isLoading = true;\n return true;\n }\n\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode || !isTreeModelHierarchyNode(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"]}
|
|
1
|
+
{"version":3,"file":"TreeModel.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeModel.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AA8BhG,gBAAgB;AAChB,MAAM,UAAU,wBAAwB,CAAC,IAA4D;IACnG,OAAO,UAAU,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC;AAC3D,CAAC;AASD,gBAAgB;AAChB,MAAM,KAAW,SAAS,CA6HzB;AA7HD,WAAiB,SAAS;IACxB,SAAgB,UAAU,CAAC,KAAgB,EAAE,MAAc,EAAE,UAAmB;QAC9E,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,EAAE,IAAI,KAAK,cAAc,EAAE,CAAC;YACxC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,2FAA2F;YAC3F,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACvC,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,OAAO,cAAc,CA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CAAA;AACH,CAAC,EA7HgB,SAAS,KAAT,SAAS,QA6HzB;AAED,SAAS,eAAe,CAAC,KAAgB,EAAE,MAA0B,EAAE,MAAkE;IACvI,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvB,KAAK,CAAC,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,CAAC;IAClB,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;QACzB,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,cAAc,CAAC,KAAgB,EAAE,QAA4B;IACpE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;IACT,CAAC;IACD,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { GenericInstanceFilter, HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { ErrorInfo } from \"../TreeNode.js\";\nimport { 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 function isTreeModelHierarchyNode(node: TreeModelHierarchyNode | ErrorInfo | TreeModelRootNode): node is TreeModelHierarchyNode {\n return \"nodeData\" in node && node.nodeData !== undefined;\n}\n\n/** @internal */\nexport interface TreeModel {\n parentChildMap: Map<string | undefined, string[]>;\n idToNode: Map<string, TreeModelHierarchyNode>;\n rootNode: TreeModelRootNode;\n}\n\n/** @internal */\nexport namespace TreeModel {\n export function expandNode(model: TreeModel, nodeId: string, isExpanded: boolean): \"none\" | \"loadChildren\" | \"reloadChildren\" {\n const node = model.idToNode.get(nodeId);\n if (!node) {\n return \"none\";\n }\n\n node.isExpanded = isExpanded;\n if (!isExpanded) {\n return \"none\";\n }\n\n if (node.error?.type === \"ChildrenLoad\") {\n node.isLoading = true;\n // remove subtree if there `ChildrenLoad` error info in order to attempt reloading children\n TreeModel.removeSubTree(model, nodeId);\n return \"reloadChildren\";\n }\n\n if (!node.children) {\n return \"none\";\n }\n\n const children = model.parentChildMap.get(node.id);\n if (!children) {\n node.isLoading = true;\n return \"loadChildren\";\n }\n\n return \"none\";\n }\n\n /** @internal */\n export function addHierarchyPart(model: TreeModel, rootId: string | undefined, hierarchyPart: TreeModel): void {\n removeSubTree(model, rootId);\n model.rootNode.error = hierarchyPart.rootNode.error;\n\n for (const [parentId, children] of hierarchyPart.parentChildMap) {\n model.parentChildMap.set(parentId, children);\n }\n\n for (const [nodeId, node] of hierarchyPart.idToNode) {\n model.idToNode.set(nodeId, node);\n }\n\n const parentNode = rootId !== undefined ? model.idToNode.get(rootId) : model.rootNode;\n /* c8 ignore next 3*/\n if (!parentNode) {\n return;\n }\n parentNode.isLoading = false;\n }\n\n export function removeSubTree(model: TreeModel, parentId: string | undefined): void {\n clearNodeError(model, parentId);\n const currentChildren = model.parentChildMap.get(parentId);\n if (!currentChildren) {\n return;\n }\n model.parentChildMap.delete(parentId);\n\n for (const childId of currentChildren) {\n const childNode = model.idToNode.get(childId);\n if (childNode) {\n removeSubTree(model, childNode.id);\n }\n model.idToNode.delete(childId);\n }\n }\n\n export function setHierarchyLimit(model: TreeModel, nodeId: string | undefined, limit?: number | \"unbounded\"): boolean {\n return updateForReload(model, nodeId, (node) => {\n node.hierarchyLimit = limit;\n });\n }\n\n export function setInstanceFilter(model: TreeModel, nodeId: string | undefined, filter?: GenericInstanceFilter): boolean {\n return updateForReload(model, nodeId, (node) => {\n if (filter && node.id !== undefined) {\n node.isExpanded = true;\n }\n node.instanceFilter = filter;\n });\n }\n\n export function selectNodes(model: TreeModel, nodeIds: Array<string>, changeType: SelectionChangeType) {\n if (changeType === \"replace\") {\n for (const [nodeId, node] of model.idToNode) {\n node.isSelected = !!nodeIds.find((id) => id === nodeId);\n }\n return;\n }\n for (const nodeId of nodeIds) {\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode) {\n return;\n }\n modelNode.isSelected = changeType === \"add\";\n }\n }\n\n export function isNodeSelected(model: TreeModel, nodeId: string): boolean {\n const currentNode = model.idToNode.get(nodeId);\n return !!currentNode && !!currentNode.isSelected;\n }\n\n export function getNode(model: TreeModel, nodeId: string | undefined): TreeModelHierarchyNode | TreeModelRootNode | undefined {\n if (!nodeId) {\n return model.rootNode;\n }\n return model.idToNode.get(nodeId);\n }\n\n export function setIsLoading(model: TreeModel, nodeId: string | undefined, isLoading: boolean) {\n if (nodeId === undefined) {\n model.rootNode.isLoading = isLoading;\n return;\n }\n const modelNode = model.idToNode.get(nodeId);\n /* c8 ignore next 3*/\n if (!modelNode) {\n return;\n }\n modelNode.isLoading = isLoading;\n }\n}\n\nfunction updateForReload(model: TreeModel, nodeId: string | undefined, update: (node: TreeModelHierarchyNode | TreeModelRootNode) => void) {\n TreeModel.removeSubTree(model, nodeId);\n if (nodeId === undefined) {\n update(model.rootNode);\n model.rootNode.isLoading = true;\n return true;\n }\n\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode) {\n return false;\n }\n\n update(modelNode);\n if (modelNode.isExpanded) {\n modelNode.isLoading = true;\n return true;\n }\n return false;\n}\n\nfunction clearNodeError(model: TreeModel, parentId: string | undefined) {\n if (!parentId) {\n return (model.rootNode.error = undefined);\n }\n const node = model.idToNode.get(parentId);\n if (!node) {\n return;\n }\n node.error = undefined;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericNodeKey, NonGroupingHierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
+
import { Selectable, SelectionStorage } from "@itwin/unified-selection";
|
|
2
3
|
import { SelectionChangeType } from "../UseSelectionHandler.js";
|
|
3
|
-
import {
|
|
4
|
+
import { TreeModelHierarchyNode, TreeModelRootNode } from "./TreeModel.js";
|
|
4
5
|
/** @internal */
|
|
5
6
|
export interface TreeSelectionOptions {
|
|
6
7
|
isNodeSelected: (nodeId: string) => boolean;
|
|
@@ -13,16 +14,29 @@ export interface UseUnifiedTreeSelectionProps {
|
|
|
13
14
|
*/
|
|
14
15
|
sourceName: string;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* An optional function that allows customizing the `Selectable` object that gets created for generic hierarchy nodes. When
|
|
18
|
+
* not supplied, the `Selectable` is created using the following signature:
|
|
19
|
+
* ```ts
|
|
20
|
+
* {
|
|
21
|
+
* identifier: treeModelNodeId,
|
|
22
|
+
* data: node,
|
|
23
|
+
* async *loadInstanceKeys() {},
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
17
26
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
27
|
+
* @param node Hierarchy node to create a selectable for.
|
|
28
|
+
* @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.
|
|
29
|
+
*/
|
|
30
|
+
createSelectableForGenericNode?: (node: NonGroupingHierarchyNode & {
|
|
31
|
+
key: GenericNodeKey;
|
|
32
|
+
}, treeModelNodeId: string) => Selectable;
|
|
33
|
+
/**
|
|
34
|
+
* Unified selection storage to use for listening, getting and changing active selection.
|
|
21
35
|
*/
|
|
22
|
-
selectionStorage
|
|
36
|
+
selectionStorage: SelectionStorage;
|
|
23
37
|
}
|
|
24
38
|
/** @internal */
|
|
25
|
-
export declare function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, }: UseUnifiedTreeSelectionProps & {
|
|
26
|
-
getTreeModelNode: (nodeId: string) =>
|
|
39
|
+
export declare function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, createSelectableForGenericNode, }: UseUnifiedTreeSelectionProps & {
|
|
40
|
+
getTreeModelNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined;
|
|
27
41
|
}): TreeSelectionOptions;
|
|
28
42
|
//# sourceMappingURL=UseUnifiedSelection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseUnifiedSelection.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"UseUnifiedSelection.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAmC,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE5H,OAAO,EAAE,UAAU,EAAe,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE3E,gBAAgB;AAChB,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAChF;AAED,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;;;;;OAaG;IACH,8BAA8B,CAAC,EAAE,CAAC,IAAI,EAAE,wBAAwB,GAAG;QAAE,GAAG,EAAE,cAAc,CAAA;KAAE,EAAE,eAAe,EAAE,MAAM,KAAK,UAAU,CAAC;IAEnI;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED,gBAAgB;AAChB,wBAAgB,uBAAuB,CAAC,EACtC,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,8BAAsE,GACvE,EAAE,4BAA4B,GAAG;IAAE,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,sBAAsB,GAAG,iBAAiB,GAAG,SAAS,CAAA;CAAE,GAAG,oBAAoB,CAiBxJ"}
|
|
@@ -6,43 +6,36 @@ import { useEffect, useState } from "react";
|
|
|
6
6
|
import { assert } from "@itwin/core-bentley";
|
|
7
7
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
8
8
|
import { Selectables } from "@itwin/unified-selection";
|
|
9
|
-
import { useUnifiedSelectionStorage } from "../UnifiedSelectionContext.js";
|
|
10
|
-
import { isTreeModelHierarchyNode } from "./TreeModel.js";
|
|
11
9
|
/** @internal */
|
|
12
|
-
export function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, }) {
|
|
10
|
+
export function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, createSelectableForGenericNode = defaultCreateSelectableForGenericNode, }) {
|
|
13
11
|
const [options, setOptions] = useState(() => ({
|
|
14
12
|
isNodeSelected: /* c8 ignore next */ () => false,
|
|
15
13
|
selectNodes: /* c8 ignore next */ () => { },
|
|
16
14
|
}));
|
|
17
|
-
const deprecatedSelectionStorage = useUnifiedSelectionStorage();
|
|
18
|
-
selectionStorage ??= deprecatedSelectionStorage;
|
|
19
15
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
// TODO: make selectionStorage prop required
|
|
22
|
-
setOptions({
|
|
23
|
-
isNodeSelected: () => false,
|
|
24
|
-
selectNodes: () => { },
|
|
25
|
-
});
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));
|
|
16
|
+
setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));
|
|
29
17
|
return selectionStorage.selectionChangeEvent.addListener((args) => {
|
|
30
18
|
if (args.level > 0) {
|
|
31
19
|
return;
|
|
32
20
|
}
|
|
33
|
-
setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));
|
|
21
|
+
setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));
|
|
34
22
|
});
|
|
35
|
-
}, [selectionStorage, getTreeModelNode, sourceName]);
|
|
23
|
+
}, [selectionStorage, createSelectableForGenericNode, getTreeModelNode, sourceName]);
|
|
36
24
|
return options;
|
|
37
25
|
}
|
|
38
|
-
|
|
26
|
+
const defaultCreateSelectableForGenericNode = (node, treeModelNodeId) => ({
|
|
27
|
+
identifier: treeModelNodeId,
|
|
28
|
+
data: node,
|
|
29
|
+
async *loadInstanceKeys() { },
|
|
30
|
+
});
|
|
31
|
+
function createOptions(source, storage, createSelectableForGenericNode, getNode) {
|
|
39
32
|
return {
|
|
40
33
|
isNodeSelected: (nodeId) => {
|
|
41
34
|
const node = getNode(nodeId);
|
|
42
|
-
if (!node ||
|
|
35
|
+
if (!node || node?.id === undefined) {
|
|
43
36
|
return false;
|
|
44
37
|
}
|
|
45
|
-
return Object.entries(groupNodeSelectablesByIModelKey(node)).some(([imodelKey, nodeSelectables]) => {
|
|
38
|
+
return Object.entries(groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)).some(([imodelKey, nodeSelectables]) => {
|
|
46
39
|
const storageSelectables = storage.getSelection({ imodelKey, level: 0 });
|
|
47
40
|
return Selectables.hasAny(storageSelectables, nodeSelectables);
|
|
48
41
|
});
|
|
@@ -51,10 +44,10 @@ function createOptions(source, storage, getNode) {
|
|
|
51
44
|
const imodelSelectables = {};
|
|
52
45
|
for (const nodeId of nodeIds) {
|
|
53
46
|
const node = getNode(nodeId);
|
|
54
|
-
if (!node ||
|
|
47
|
+
if (!node || node?.id === undefined) {
|
|
55
48
|
return;
|
|
56
49
|
}
|
|
57
|
-
Object.entries(groupNodeSelectablesByIModelKey(node)).forEach(([imodelKey, nodeSelectables]) => {
|
|
50
|
+
Object.entries(groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)).forEach(([imodelKey, nodeSelectables]) => {
|
|
58
51
|
let selectablesList = imodelSelectables[imodelKey];
|
|
59
52
|
if (!selectablesList) {
|
|
60
53
|
selectablesList = [];
|
|
@@ -80,7 +73,7 @@ function createOptions(source, storage, getNode) {
|
|
|
80
73
|
},
|
|
81
74
|
};
|
|
82
75
|
}
|
|
83
|
-
function groupNodeSelectablesByIModelKey(modelNode) {
|
|
76
|
+
function groupNodeSelectablesByIModelKey(modelNode, createSelectableForGenericNode) {
|
|
84
77
|
const hierarchyNode = modelNode.nodeData;
|
|
85
78
|
if (HierarchyNode.isInstancesNode(hierarchyNode)) {
|
|
86
79
|
return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);
|
|
@@ -104,13 +97,7 @@ function groupNodeSelectablesByIModelKey(modelNode) {
|
|
|
104
97
|
assert(HierarchyNode.isGeneric(hierarchyNode));
|
|
105
98
|
return {
|
|
106
99
|
// note: generic nodes aren't associated with an imodel
|
|
107
|
-
[""]: [
|
|
108
|
-
{
|
|
109
|
-
identifier: modelNode.id,
|
|
110
|
-
data: hierarchyNode,
|
|
111
|
-
async *loadInstanceKeys() { },
|
|
112
|
-
},
|
|
113
|
-
],
|
|
100
|
+
[""]: [createSelectableForGenericNode(hierarchyNode, modelNode.id)],
|
|
114
101
|
};
|
|
115
102
|
}
|
|
116
103
|
function groupIModelInstanceKeys(instanceKeys) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseUnifiedSelection.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAoB,MAAM,iCAAiC,CAAC;AAElF,OAAO,EAAc,WAAW,EAAoB,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,wBAAwB,EAA4D,MAAM,gBAAgB,CAAC;AAyBpH,gBAAgB;AAChB,MAAM,UAAU,uBAAuB,CAAC,EACtC,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACuG;IACvH,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB,GAAG,EAAE,CAAC,CAAC;QAClE,cAAc,EAAE,oBAAoB,CAAC,GAAG,EAAE,CAAC,KAAK;QAChD,WAAW,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAE,CAAC;KAC3C,CAAC,CAAC,CAAC;IAEJ,MAAM,0BAA0B,GAAG,0BAA0B,EAAE,CAAC;IAChE,gBAAgB,KAAK,0BAA0B,CAAC;I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8C;IAC7E,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,iBAAiB,EAAE,GAAG,EAAE,EAAE;QACzB,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC;QACtC,IAAI,eAAe,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACnD,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,EAAE,CAAC;YACrB,iBAAiB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;QACjD,CAAC;QACD,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EACD,EAA4C,CAC7C,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useEffect, useState } from \"react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { HierarchyNode, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey } from \"@itwin/presentation-shared\";\nimport { Selectable, Selectables, SelectionStorage } from \"@itwin/unified-selection\";\nimport { useUnifiedSelectionStorage } from \"../UnifiedSelectionContext.js\";\nimport { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport { isTreeModelHierarchyNode, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @public */\nexport interface UseUnifiedTreeSelectionProps {\n /**\n * Identifier to distinguish this source of changes to the unified selection from another ones in the application.\n */\n sourceName: string;\n\n /**\n * Unified selection storage to use for listening, getting and changing active selection.\n *\n * When not specified, the deprecated unified selection React context is used to access the\n * selection storage (see `UnifiedSelectionProvider`). This prop will be made required in the\n * next major release, where the deprecated context will also be removed.\n */\n selectionStorage?: SelectionStorage;\n}\n\n/** @internal */\nexport function useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n}: UseUnifiedTreeSelectionProps & { getTreeModelNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined }): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* c8 ignore next */ () => false,\n selectNodes: /* c8 ignore next */ () => {},\n }));\n\n const deprecatedSelectionStorage = useUnifiedSelectionStorage();\n selectionStorage ??= deprecatedSelectionStorage;\n\n useEffect(() => {\n if (!selectionStorage) {\n // TODO: make selectionStorage prop required\n setOptions({\n isNodeSelected: () => false,\n selectNodes: () => {},\n });\n return;\n }\n\n setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (args.level > 0) {\n return;\n }\n setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));\n });\n }, [selectionStorage, getTreeModelNode, sourceName]);\n\n return options;\n}\n\nfunction createOptions(\n source: string,\n storage: SelectionStorage,\n getNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined,\n): TreeSelectionOptions {\n return {\n isNodeSelected: (nodeId: string) => {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return false;\n }\n return Object.entries(groupNodeSelectablesByIModelKey(node)).some(([imodelKey, nodeSelectables]) => {\n const storageSelectables = storage.getSelection({ imodelKey, level: 0 });\n return Selectables.hasAny(storageSelectables, nodeSelectables);\n });\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n const imodelSelectables: { [imodelKey: string]: Selectable[] } = {};\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return;\n }\n Object.entries(groupNodeSelectablesByIModelKey(node)).forEach(([imodelKey, nodeSelectables]) => {\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n nodeSelectables.forEach((selectable) => selectablesList.push(selectable));\n });\n }\n Object.entries(imodelSelectables).forEach(([imodelKey, selectables]) => {\n const actionProps = { imodelKey, source, selectables, level: 0 };\n switch (changeType) {\n case \"add\":\n storage.addToSelection(actionProps);\n return;\n case \"remove\":\n storage.removeFromSelection(actionProps);\n return;\n case \"replace\":\n storage.replaceSelection(actionProps);\n return;\n }\n });\n },\n };\n}\n\nfunction groupNodeSelectablesByIModelKey(modelNode: TreeModelHierarchyNode): { [imodelKey: string]: Selectable[] } {\n const hierarchyNode = modelNode.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);\n }\n if (HierarchyNode.isGroupingNode(hierarchyNode)) {\n return Object.entries(groupIModelInstanceKeys(hierarchyNode.groupedInstanceKeys)).reduce(\n (imodelSelectables, [imodelKey, instanceKeys]) => ({\n ...imodelSelectables,\n [imodelKey]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {\n for (const key of instanceKeys) {\n yield key;\n }\n },\n },\n ],\n }),\n {} as { [imodelKey: string]: Selectable[] },\n );\n }\n assert(HierarchyNode.isGeneric(hierarchyNode));\n return {\n // note: generic nodes aren't associated with an imodel\n [\"\"]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {},\n },\n ],\n };\n}\n\nfunction groupIModelInstanceKeys(instanceKeys: InstancesNodeKey[\"instanceKeys\"]) {\n return instanceKeys.reduce(\n (imodelSelectables, key) => {\n const imodelKey = key.imodelKey ?? \"\";\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n selectablesList.push(key);\n return imodelSelectables;\n },\n {} as { [imodelKey: string]: InstanceKey[] },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Use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AAO,CAAC,uBAAuB,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC,CAAC,MAAM,CACtF,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC;YACjD,GAAG,iBAAiB;YACpB,CAAC,SAAS,CAAC,EAAE;gBACX;oBACE,UAAU,EAAE,SAAS,CAAC,EAAE;oBACxB,IAAI,EAAE,aAAa;oBACnB,KAAK,CAAC,CAAC,gBAAgB;wBACrB,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;4BAC/B,MAAM,GAAG,CAAC;wBACZ,CAAC;oBACH,CAAC;iBACF;aACF;SACF,CAAC,EACF,EAA2C,CAC5C,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;IAC/C,OAAO;QACL,uDAAuD;QACvD,CAAC,EAAE,CAAC,EAAE,CAAC,8BAA8B,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;KACpE,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,YAA8C;IAC7E,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,iBAAiB,EAAE,GAAG,EAAE,EAAE;QACzB,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC;QACtC,IAAI,eAAe,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACnD,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,EAAE,CAAC;YACrB,iBAAiB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;QACjD,CAAC;QACD,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EACD,EAA4C,CAC7C,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useEffect, useState } from \"react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { GenericNodeKey, HierarchyNode, InstancesNodeKey, NonGroupingHierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey } from \"@itwin/presentation-shared\";\nimport { Selectable, Selectables, SelectionStorage } from \"@itwin/unified-selection\";\nimport { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @public */\nexport interface UseUnifiedTreeSelectionProps {\n /**\n * Identifier to distinguish this source of changes to the unified selection from another ones in the application.\n */\n sourceName: string;\n\n /**\n * An optional function that allows customizing the `Selectable` object that gets created for generic hierarchy nodes. When\n * not supplied, the `Selectable` is created using the following signature:\n * ```ts\n * {\n * identifier: treeModelNodeId,\n * data: node,\n * async *loadInstanceKeys() {},\n * }\n * ```\n *\n * @param node Hierarchy node to create a selectable for.\n * @param treeModelNodeId ID of the hierarchy node in the internal tree model. This ID uniquely identifies the node in the whole hierarchy, as opposed to `GenericNodeKey.id` contained within the `node`, which may not be unique.\n */\n createSelectableForGenericNode?: (node: NonGroupingHierarchyNode & { key: GenericNodeKey }, treeModelNodeId: string) => Selectable;\n\n /**\n * Unified selection storage to use for listening, getting and changing active selection.\n */\n selectionStorage: SelectionStorage;\n}\n\n/** @internal */\nexport function useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n createSelectableForGenericNode = defaultCreateSelectableForGenericNode,\n}: UseUnifiedTreeSelectionProps & { getTreeModelNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined }): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* c8 ignore next */ () => false,\n selectNodes: /* c8 ignore next */ () => {},\n }));\n\n useEffect(() => {\n setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (args.level > 0) {\n return;\n }\n setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));\n });\n }, [selectionStorage, createSelectableForGenericNode, getTreeModelNode, sourceName]);\n\n return options;\n}\n\nconst defaultCreateSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]> = (\n node,\n treeModelNodeId,\n): Selectable => ({\n identifier: treeModelNodeId,\n data: node,\n async *loadInstanceKeys() {},\n});\n\nfunction createOptions(\n source: string,\n storage: SelectionStorage,\n createSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]>,\n getNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined,\n): TreeSelectionOptions {\n return {\n isNodeSelected: (nodeId: string) => {\n const node = getNode(nodeId);\n if (!node || node?.id === undefined) {\n return false;\n }\n return Object.entries(groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)).some(([imodelKey, nodeSelectables]) => {\n const storageSelectables = storage.getSelection({ imodelKey, level: 0 });\n return Selectables.hasAny(storageSelectables, nodeSelectables);\n });\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n const imodelSelectables: { [imodelKey: string]: Selectable[] } = {};\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || node?.id === undefined) {\n return;\n }\n Object.entries(groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)).forEach(([imodelKey, nodeSelectables]) => {\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n nodeSelectables.forEach((selectable) => selectablesList.push(selectable));\n });\n }\n Object.entries(imodelSelectables).forEach(([imodelKey, selectables]) => {\n const actionProps = { imodelKey, source, selectables, level: 0 };\n switch (changeType) {\n case \"add\":\n storage.addToSelection(actionProps);\n return;\n case \"remove\":\n storage.removeFromSelection(actionProps);\n return;\n case \"replace\":\n storage.replaceSelection(actionProps);\n return;\n }\n });\n },\n };\n}\n\nfunction groupNodeSelectablesByIModelKey(\n modelNode: TreeModelHierarchyNode,\n createSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]>,\n): { [imodelKey: string]: Selectable[] } {\n const hierarchyNode = modelNode.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);\n }\n if (HierarchyNode.isGroupingNode(hierarchyNode)) {\n return Object.entries(groupIModelInstanceKeys(hierarchyNode.groupedInstanceKeys)).reduce(\n (imodelSelectables, [imodelKey, instanceKeys]) => ({\n ...imodelSelectables,\n [imodelKey]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {\n for (const key of instanceKeys) {\n yield key;\n }\n },\n },\n ],\n }),\n {} as { [imodelKey: string]: Selectable[] },\n );\n }\n assert(HierarchyNode.isGeneric(hierarchyNode));\n return {\n // note: generic nodes aren't associated with an imodel\n [\"\"]: [createSelectableForGenericNode(hierarchyNode, modelNode.id)],\n };\n}\n\nfunction groupIModelInstanceKeys(instanceKeys: InstancesNodeKey[\"instanceKeys\"]) {\n return instanceKeys.reduce(\n (imodelSelectables, key) => {\n const imodelKey = key.imodelKey ?? \"\";\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n selectablesList.push(key);\n return imodelSelectables;\n },\n {} as { [imodelKey: string]: InstanceKey[] },\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/Utils.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/Utils.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAoB,MAAM,iCAAiC,CAAC;AAElF,gBAAgB;AAChB,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,YAAY,CAAC,UAE3E;AAiBD,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAezE;AAED,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,EAAE,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,QAMtG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAiB,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAElF,gBAAgB;AAChB,MAAM,UAAU,YAAY,CAAC,IAA+C;IAC1E,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1F,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UAAU,WAAW,CAAC,UAA2E;IACrG,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;QAC5B,UAAU,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;SAAM,IAAI,MAAM,CAAC,OAAO,IAAI,UAAU,EAAE,CAAC;QACxC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/B,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./DisposePolyfill.js\";\n\nimport { HierarchyNode, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\n\n/** @internal */\nexport function createNodeId(node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) {\n return [...node.parentKeys.map(serializeNodeKey), serializeNodeKey(node.key)].join(\";\");\n}\n\nfunction serializeNodeKey(key: HierarchyNodeKey): string {\n return convertObjectValuesToString(key);\n}\n\nfunction convertObjectValuesToString(obj: object): string {\n return Object.entries(obj)\n .map(([, value]) => {\n if (typeof value === \"object\") {\n return convertObjectValuesToString(value);\n }\n return String(value);\n })\n .join(\",\");\n}\n\n/** @internal */\nexport function sameNodes(lhs: HierarchyNode, rhs: HierarchyNode): boolean {\n if (HierarchyNodeKey.compare(lhs.key, rhs.key) !== 0) {\n return false;\n }\n\n if (lhs.parentKeys.length !== rhs.parentKeys.length) {\n return false;\n }\n\n for (let i = lhs.parentKeys.length - 1; i >= 0; --i) {\n if (HierarchyNodeKey.compare(lhs.parentKeys[i], rhs.parentKeys[i]) !== 0) {\n return false;\n }\n }\n return true;\n}\n\n/** @internal */\nexport const MAX_LIMIT_OVERRIDE = 10000;\n\n/**\n * A helper that disposes the given object, if it's disposable.\n *\n * The first option is to dispose using the deprecated `dispose` method if it exists on the object.\n * If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is\n * considered as non-disposable and nothing is done with it.\n *\n * @internal\n */\nexport function safeDispose(disposable: {} | { [Symbol.dispose]: () => void } | { dispose: () => void }) {\n if (\"dispose\" in disposable) {\n disposable.dispose();\n } else if (Symbol.dispose in disposable) {\n disposable[Symbol.dispose]();\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HierarchyLevelDetails, TreeRendererProps } from "../Renderers.js";
|
|
2
|
+
import { TreeNode } from "../TreeNode.js";
|
|
3
|
+
import { useErrorNodes } from "./FlatTreeNode.js";
|
|
4
|
+
/** @alpha */
|
|
5
|
+
export interface ErrorItemRendererProps extends Pick<TreeRendererProps, "getHierarchyLevelDetails"> {
|
|
6
|
+
/** A node containing an error. */
|
|
7
|
+
errorNode: ReturnType<typeof useErrorNodes>[number];
|
|
8
|
+
/** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */
|
|
9
|
+
reloadTree: (options: {
|
|
10
|
+
parentNodeId: string | undefined;
|
|
11
|
+
}) => void;
|
|
12
|
+
/** A callback to scroll to the node associated with the error. */
|
|
13
|
+
scrollToNode: (errorNode: TreeNode) => void;
|
|
14
|
+
/** A callback to initiate filtering of the given hierarchy level. */
|
|
15
|
+
filterHierarchyLevel?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Renders StrataKit `<ErrorRegion.Item />` for all supported error types:
|
|
19
|
+
* - `ResultSetTooLarge` - renders `LocalizedStrings.resultLimitExceeded` message with actions to increase limit or apply filtering
|
|
20
|
+
* - `NoFilterMatches` - renders `LocalizedStrings.noFilteredChildren` message with action to change filter
|
|
21
|
+
* - `ChildrenLoad` - renders `LocalizedStrings.failedToCreateHierarchy` message with action to retry loading
|
|
22
|
+
* - `Unknown` - renders message set on error object.
|
|
23
|
+
*
|
|
24
|
+
* @alpha
|
|
25
|
+
*/
|
|
26
|
+
export declare function ErrorItemRenderer({ errorNode, getHierarchyLevelDetails, filterHierarchyLevel, reloadTree, scrollToNode }: ErrorItemRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
//# sourceMappingURL=ErrorItemRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorItemRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/ErrorItemRenderer.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,aAAa;AACb,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,0BAA0B,CAAC;IACjG,kCAAkC;IAClC,SAAS,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;IACpD,iGAAiG;IACjG,UAAU,EAAE,CAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,KAAK,IAAI,CAAC;IACpE,kEAAkE;IAClE,YAAY,EAAE,CAAC,SAAS,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC5C,qEAAqE;IACrE,oBAAoB,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAC/E;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,sBAAsB,2CAoEhJ"}
|