@itwin/tree-widget-react 3.13.2 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -2
- package/README.md +43 -15
- package/lib/cjs/tree-widget-react/components/trees/common/UseNodeHighlighting.js +7 -4
- package/lib/cjs/tree-widget-react/components/trees/common/UseNodeHighlighting.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/common/Utils.d.ts +3 -1
- package/lib/cjs/tree-widget-react/components/trees/common/Utils.js +9 -10
- package/lib/cjs/tree-widget-react/components/trees/common/Utils.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +3 -5
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +2 -2
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/UseModelsTree.d.ts +4 -3
- package/lib/cjs/tree-widget-react/components/trees/models-tree/UseModelsTree.js +51 -29
- package/lib/cjs/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js +8 -5
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/Utils.d.ts +3 -1
- package/lib/esm/tree-widget-react/components/trees/common/Utils.js +9 -10
- package/lib/esm/tree-widget-react/components/trees/common/Utils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +3 -5
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +3 -3
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.d.ts +4 -3
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +51 -29
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
# Change Log - @itwin/tree-widget-react
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on Thu,
|
|
3
|
+
<!-- This log was last generated on Thu, 21 Aug 2025 11:00:29 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 3.14.0
|
|
8
|
+
|
|
9
|
+
Thu, 21 Aug 2025 11:00:29 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Allow Model tree's `getFilteredPaths` prop function to return `undefined` paths. In that case, it's considered that filtering should not be applied, and the full unfiltered tree should be loaded. ([#1417](https://github.com/iTwin/viewer-components-react/pull/1417))
|
|
14
|
+
|
|
7
15
|
## 3.13.2
|
|
8
16
|
|
|
9
|
-
Thu, 07 Aug 2025 18:
|
|
17
|
+
Thu, 07 Aug 2025 18:43:06 GMT
|
|
10
18
|
|
|
11
19
|
### Patches
|
|
12
20
|
|
package/README.md
CHANGED
|
@@ -320,40 +320,67 @@ Use `getFilteredPaths` when you need more control over filtering behaviour. Here
|
|
|
320
320
|
|
|
321
321
|
<!-- END EXTRACTION -->
|
|
322
322
|
|
|
323
|
-
- **Apply custom logic to generate instance keys**: Generate instance keys using custom implementation. For example:
|
|
324
|
-
|
|
325
|
-
|
|
323
|
+
- **Apply custom logic to generate instance keys**: Generate instance keys using custom implementation. For example: only apply the given filter string to `bis.Subject` and `bis.Model` instances, but not others (`bis.Category`, `bis.GeometricElement`).
|
|
324
|
+
<!-- [[include: [TreeWidget.GetFilteredPathsComponentWithFilterAndTargetItemsExample], tsx]] -->
|
|
325
|
+
<!-- BEGIN EXTRACTION -->
|
|
326
|
+
|
|
326
327
|
```tsx
|
|
327
328
|
function CustomModelsTreeComponentWithFilterAndTargetItems({
|
|
328
329
|
viewport,
|
|
329
330
|
selectionStorage,
|
|
330
331
|
imodel,
|
|
332
|
+
filter,
|
|
331
333
|
}: {
|
|
332
334
|
viewport: Viewport;
|
|
333
335
|
selectionStorage: SelectionStorage;
|
|
334
336
|
imodel: IModelConnection;
|
|
337
|
+
filter: string | undefined;
|
|
335
338
|
}) {
|
|
336
339
|
const getFilteredPaths = useCallback<GetFilteredPathsType>(
|
|
337
|
-
async ({ createInstanceKeyPaths, filter }) => {
|
|
340
|
+
async ({ createInstanceKeyPaths, filter: activeFilter }) => {
|
|
341
|
+
if (!activeFilter) {
|
|
342
|
+
// if filter is not defined, return `undefined` to avoid applying empty filter
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
338
345
|
const targetItems = new Array<InstanceKey>();
|
|
339
346
|
for await (const row of imodel.createQueryReader(
|
|
340
347
|
`
|
|
341
|
-
SELECT
|
|
342
|
-
FROM
|
|
343
|
-
|
|
348
|
+
SELECT ClassName, Id
|
|
349
|
+
FROM (
|
|
350
|
+
SELECT
|
|
351
|
+
ec_classname(e.ECClassId, 's.c') ClassName,
|
|
352
|
+
e.ECInstanceId Id,
|
|
353
|
+
COALESCE(e.UserLabel, e.CodeValue) Label
|
|
354
|
+
FROM BisCore.Subject e
|
|
355
|
+
|
|
356
|
+
UNION ALL
|
|
357
|
+
|
|
358
|
+
SELECT
|
|
359
|
+
ec_classname(m.ECClassId, 's.c') ClassName,
|
|
360
|
+
m.ECInstanceId Id,
|
|
361
|
+
COALESCE(e.UserLabel, e.CodeValue) Label
|
|
362
|
+
FROM BisCore.GeometricModel3d m
|
|
363
|
+
JOIN BisCore.Element e ON e.ECInstanceId = m.ModeledElement.Id
|
|
364
|
+
WHERE NOT m.IsPrivate
|
|
365
|
+
AND EXISTS (SELECT 1 FROM BisCore.Element WHERE Model.Id = m.ECInstanceId)
|
|
366
|
+
AND json_extract(e.JsonProperties, '$.PhysicalPartition.Model.Content') IS NULL
|
|
367
|
+
AND json_extract(e.JsonProperties, '$.GraphicalPartition3d.Model.Content') IS NULL
|
|
368
|
+
)
|
|
369
|
+
WHERE Label LIKE '%${activeFilter.replaceAll(/[%_\\]/g, "\\$&")}%' ESCAPE '\\'
|
|
344
370
|
`,
|
|
345
371
|
undefined,
|
|
346
372
|
{ rowFormat: QueryRowFormat.UseJsPropertyNames },
|
|
347
373
|
)) {
|
|
348
|
-
targetItems.push({ id: row.
|
|
374
|
+
targetItems.push({ id: row.Id, className: row.ClassName });
|
|
349
375
|
}
|
|
350
|
-
|
|
376
|
+
// `createInstanceKeyPaths` doesn't automatically set the `autoExpand` flag - set it here
|
|
377
|
+
const paths = await createInstanceKeyPaths({ targetItems });
|
|
378
|
+
return paths.map((path) => ({ ...path, options: { autoExpand: true } }));
|
|
351
379
|
},
|
|
352
380
|
[imodel],
|
|
353
381
|
);
|
|
354
382
|
|
|
355
|
-
const { modelsTreeProps, rendererProps } = useModelsTree({ activeView: viewport, getFilteredPaths, filter
|
|
356
|
-
|
|
383
|
+
const { modelsTreeProps, rendererProps } = useModelsTree({ activeView: viewport, getFilteredPaths, filter });
|
|
357
384
|
return (
|
|
358
385
|
<VisibilityTree
|
|
359
386
|
{...modelsTreeProps}
|
|
@@ -365,14 +392,15 @@ Use `getFilteredPaths` when you need more control over filtering behaviour. Here
|
|
|
365
392
|
);
|
|
366
393
|
}
|
|
367
394
|
```
|
|
368
|
-
|
|
395
|
+
|
|
396
|
+
<!-- END EXTRACTION -->
|
|
369
397
|
|
|
370
398
|
Use `getSubTreePaths` when you need to restrict the visible hierarchy to a specific sub-tree of nodes, without changing how filtering works. Here is an example use case:
|
|
371
399
|
|
|
372
400
|
**Restrict the hierarchy to a sub-tree and keep the default filtering logic**: You already have a list of `InstanceKey` items that should remain in the tree. Pass them as `targetItems` to `createInstanceKeyPaths`. This will restrict the hierarchy to a sub-tree, but filtering will work as before.
|
|
373
401
|
|
|
374
|
-
|
|
375
|
-
|
|
402
|
+
<!-- [[include: [TreeWidget.GetSubTreePathsComponentWithTargetItemsExample], tsx]] -->
|
|
403
|
+
<!-- BEGIN EXTRACTION -->
|
|
376
404
|
|
|
377
405
|
```tsx
|
|
378
406
|
type UseModelsTreeProps = Props<typeof useModelsTree>;
|
|
@@ -414,7 +442,7 @@ function CustomModelsTreeComponentWithTargetItems({
|
|
|
414
442
|
}
|
|
415
443
|
```
|
|
416
444
|
|
|
417
|
-
|
|
445
|
+
<!-- END EXTRACTION -->
|
|
418
446
|
|
|
419
447
|
### Categories tree
|
|
420
448
|
|
|
@@ -61,10 +61,13 @@ function computeHighlightState(rootNodes, searchText, state, activeNodeId, activ
|
|
|
61
61
|
if (!(0, presentation_hierarchies_react_1.isPresentationHierarchyNode)(node)) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
if (node.nodeData.filtering?.isFilterTarget) {
|
|
65
|
+
const matches = findChunks(node.label, searchText);
|
|
66
|
+
newState.nodeInfoMap.set(node.id, { startIndex: newState.totalMatches, matches });
|
|
67
|
+
newState.totalMatches += matches.length;
|
|
68
|
+
}
|
|
69
|
+
if (typeof node.children !== "boolean" &&
|
|
70
|
+
(presentation_hierarchies_react_1.HierarchyNode.isGroupingNode(node.nodeData) || node.nodeData.filtering?.filteredChildrenIdentifierPaths?.length)) {
|
|
68
71
|
computeHighlightStateRecursively(node.children);
|
|
69
72
|
}
|
|
70
73
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseNodeHighlighting.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I,SAAoE,CAAC;IACzE,IAAI,cAAkC,CAAC;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,CAAC,KAAK,WAAW,CAAC;QACnC,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACxF,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAC/B,SAAS;QACX,CAAC;QACD,QAAQ,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QACxD,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACzC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { isPresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport { useLatest } from \"./Utils.js\";\n\nimport type { PresentationHierarchyNode, PresentationTreeNode } from \"@itwin/presentation-hierarchies-react\";\n\n/** @beta */\nexport interface HighlightInfo {\n text: string;\n}\n\ninterface UseNodeHighlightingProps {\n rootNodes: PresentationTreeNode[] | undefined;\n // TODO: move activeMatchIndex and onHighlightChanged to HighlightInfo when it's implemented.\n highlight?: HighlightInfo & {\n activeMatchIndex?: number;\n onHighlightChanged?: (activeMatchIndex: number, matches: number) => void;\n };\n}\n\ninterface HighlightedChunk {\n start: number;\n end: number;\n}\n\ninterface NodeChunkInfo {\n chunks: HighlightedChunk[];\n activeChunkIndex?: number;\n}\n\ninterface NodeHighlightInfo {\n startIndex: number;\n matches: HighlightedChunk[];\n}\n\ninterface HighlightState {\n nodeInfoMap: Map<string, NodeHighlightInfo>;\n totalMatches: number;\n}\n\ninterface UseNodeHighlightingResult {\n activeNodeId?: string;\n getLabel: (node: PresentationHierarchyNode) => React.ReactElement;\n}\n\nexport function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const state = useRef<HighlightState>({ nodeInfoMap: new Map(), totalMatches: 0 });\n const [activeNodeId, setActiveNodeId] = useState<string | undefined>();\n const activeMatchIndexRef = useLatest(highlight?.activeMatchIndex);\n const activeNodeIdRef = useLatest(activeNodeId);\n const onHighlightChangedRef = useLatest(highlight?.onHighlightChanged);\n const searchText = highlight?.text;\n\n useEffect(() => {\n const { state: newState, activeIndex } =\n rootNodes && searchText\n ? computeHighlightState(rootNodes, searchText, state.current, activeNodeIdRef.current, activeMatchIndexRef.current)\n : { state: { nodeInfoMap: new Map(), totalMatches: 0 }, activeIndex: 0 };\n\n state.current = newState;\n if (newState.totalMatches === 0) {\n setActiveNodeId(undefined);\n }\n onHighlightChangedRef.current?.(newState.totalMatches === 0 ? 0 : activeIndex, newState.totalMatches);\n }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef]);\n\n useEffect(() => {\n for (const nodeId of state.current.nodeInfoMap.keys()) {\n if (getNodeChunkInfo(state.current, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {\n setActiveNodeId(nodeId);\n }\n }\n }, [highlight?.activeMatchIndex]);\n\n const getLabel = useCallback(\n (node: PresentationHierarchyNode) => {\n const chunkInfo = getNodeChunkInfo(state.current, node.id, highlight?.activeMatchIndex);\n if (searchText && chunkInfo) {\n return <>{markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex)}</>;\n }\n return <span>{node.label}</span>;\n },\n [searchText, highlight?.activeMatchIndex],\n );\n\n return { activeNodeId, getLabel };\n}\n\nfunction getNodeChunkInfo(state: HighlightState, nodeId: string, activeIndex?: number): NodeChunkInfo | undefined {\n const info = state.nodeInfoMap.get(nodeId);\n if (!info) {\n return undefined;\n }\n if (activeIndex === undefined) {\n return { chunks: info.matches };\n }\n const isActive = info && activeIndex >= info.startIndex && activeIndex < info.startIndex + info.matches.length;\n return isActive ? { activeChunkIndex: activeIndex - info.startIndex, chunks: info.matches } : { chunks: info.matches };\n}\n\nfunction computeHighlightState(rootNodes: PresentationTreeNode[], searchText: string, state: HighlightState, activeNodeId?: string, activeMatchIndex?: number) {\n const newState: HighlightState = { nodeInfoMap: new Map(), totalMatches: 0 };\n let newActiveIndex = activeMatchIndex ?? 0;\n\n const computeHighlightStateRecursively = (nodes: Array<PresentationTreeNode>) => {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n\n const matches = findChunks(node.label, searchText);\n newState.nodeInfoMap.set(node.id, { startIndex: newState.totalMatches, matches });\n newState.totalMatches += matches.length;\n\n if (typeof node.children !== \"boolean\") {\n computeHighlightStateRecursively(node.children);\n }\n });\n };\n\n computeHighlightStateRecursively(rootNodes);\n\n // update active index to not cause active chunk jumps when hierarchy changes\n if (activeNodeId && newActiveIndex !== 0) {\n const activeNodeInfo = getNodeChunkInfo(state, activeNodeId, activeMatchIndex);\n const updatedInfo = newState.nodeInfoMap.get(activeNodeId);\n\n if (updatedInfo && activeNodeInfo?.activeChunkIndex !== undefined) {\n newActiveIndex = updatedInfo.startIndex + activeNodeInfo.activeChunkIndex;\n }\n }\n\n return { state: newState, activeIndex: newActiveIndex };\n}\n\nfunction findChunks(text: string, searchText: string): HighlightedChunk[] {\n const chunks: HighlightedChunk[] = [];\n\n const contentText = text.toLowerCase();\n const inputText = searchText.toLowerCase();\n let index = contentText.indexOf(inputText);\n\n while (index !== -1) {\n chunks.push({ start: index, end: index + inputText.length });\n index = contentText.indexOf(inputText, index + 1);\n }\n\n return chunks;\n}\n\nfunction markChunks(text: string, chunks: HighlightedChunk[], activeChunk?: number) {\n const markedText: React.ReactElement[] = [];\n let previousIndex = 0;\n\n const { mergedChunks, newActiveIndex } = mergeChunks(chunks, activeChunk);\n\n for (let i = 0; i < mergedChunks.length; i++) {\n const { start, end } = mergedChunks[i];\n\n // add unmarked text between previous chunk and current one\n const nonMarkedText = text.substring(previousIndex, start);\n nonMarkedText.length && markedText.push(<span key={previousIndex}>{nonMarkedText}</span>);\n\n // add marked chunk text\n markedText.push(\n <mark key={start} className={i === newActiveIndex ? \"tw-active-match-highlight\" : undefined}>\n {text.substring(start, end)}\n </mark>,\n );\n previousIndex = end;\n }\n\n // add unmarked text after last chunk\n const lastNonMarkedText = text.substring(previousIndex, text.length);\n lastNonMarkedText.length && markedText.push(<span key={previousIndex}>{lastNonMarkedText}</span>);\n\n return markedText;\n}\n\nfunction mergeChunks(chunks: HighlightedChunk[], activeChunk?: number) {\n const mergedChunks: HighlightedChunk[] = [];\n let lastChunk: { isActive: boolean; info: HighlightedChunk } | undefined;\n let newActiveIndex: number | undefined;\n\n for (let i = 0; i < chunks.length; i++) {\n const chunk = chunks[i];\n const isActive = i === activeChunk;\n if (lastChunk && lastChunk.info.end === chunk.start && !isActive && !lastChunk.isActive) {\n lastChunk.info.end = chunk.end;\n continue;\n }\n isActive && (newActiveIndex = mergedChunks.length);\n const newChunk = { start: chunk.start, end: chunk.end };\n lastChunk = { isActive, info: newChunk };\n mergedChunks.push(newChunk);\n }\n return { mergedChunks, newActiveIndex };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseNodeH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B,CAAC,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC,2CAA2B,iBAAiB,IAAjC,aAAa,CAA4B,CAAC,CAAC;IAElG,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,WAAW,CAAC,MAA0B,EAAE,WAAoB;IACnE,MAAM,YAAY,GAAuB,EAAE,CAAC;IAC5C,IAAI,SAAoE,CAAC;IACzE,IAAI,cAAkC,CAAC;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,CAAC,KAAK,WAAW,CAAC;QACnC,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACxF,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAC/B,SAAS;QACX,CAAC;QACD,QAAQ,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QACxD,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACzC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { HierarchyNode, isPresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport { useLatest } from \"./Utils.js\";\n\nimport type { PresentationHierarchyNode, PresentationTreeNode } from \"@itwin/presentation-hierarchies-react\";\n\n/** @beta */\nexport interface HighlightInfo {\n text: string;\n}\n\ninterface UseNodeHighlightingProps {\n rootNodes: PresentationTreeNode[] | undefined;\n // TODO: move activeMatchIndex and onHighlightChanged to HighlightInfo when it's implemented.\n highlight?: HighlightInfo & {\n activeMatchIndex?: number;\n onHighlightChanged?: (activeMatchIndex: number, matches: number) => void;\n };\n}\n\ninterface HighlightedChunk {\n start: number;\n end: number;\n}\n\ninterface NodeChunkInfo {\n chunks: HighlightedChunk[];\n activeChunkIndex?: number;\n}\n\ninterface NodeHighlightInfo {\n startIndex: number;\n matches: HighlightedChunk[];\n}\n\ninterface HighlightState {\n nodeInfoMap: Map<string, NodeHighlightInfo>;\n totalMatches: number;\n}\n\ninterface UseNodeHighlightingResult {\n activeNodeId?: string;\n getLabel: (node: PresentationHierarchyNode) => React.ReactElement;\n}\n\nexport function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const state = useRef<HighlightState>({ nodeInfoMap: new Map(), totalMatches: 0 });\n const [activeNodeId, setActiveNodeId] = useState<string | undefined>();\n const activeMatchIndexRef = useLatest(highlight?.activeMatchIndex);\n const activeNodeIdRef = useLatest(activeNodeId);\n const onHighlightChangedRef = useLatest(highlight?.onHighlightChanged);\n const searchText = highlight?.text;\n\n useEffect(() => {\n const { state: newState, activeIndex } =\n rootNodes && searchText\n ? computeHighlightState(rootNodes, searchText, state.current, activeNodeIdRef.current, activeMatchIndexRef.current)\n : { state: { nodeInfoMap: new Map(), totalMatches: 0 }, activeIndex: 0 };\n\n state.current = newState;\n if (newState.totalMatches === 0) {\n setActiveNodeId(undefined);\n }\n onHighlightChangedRef.current?.(newState.totalMatches === 0 ? 0 : activeIndex, newState.totalMatches);\n }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef]);\n\n useEffect(() => {\n for (const nodeId of state.current.nodeInfoMap.keys()) {\n if (getNodeChunkInfo(state.current, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {\n setActiveNodeId(nodeId);\n }\n }\n }, [highlight?.activeMatchIndex]);\n\n const getLabel = useCallback(\n (node: PresentationHierarchyNode) => {\n const chunkInfo = getNodeChunkInfo(state.current, node.id, highlight?.activeMatchIndex);\n if (searchText && chunkInfo) {\n return <>{markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex)}</>;\n }\n return <span>{node.label}</span>;\n },\n [searchText, highlight?.activeMatchIndex],\n );\n\n return { activeNodeId, getLabel };\n}\n\nfunction getNodeChunkInfo(state: HighlightState, nodeId: string, activeIndex?: number): NodeChunkInfo | undefined {\n const info = state.nodeInfoMap.get(nodeId);\n if (!info) {\n return undefined;\n }\n if (activeIndex === undefined) {\n return { chunks: info.matches };\n }\n const isActive = info && activeIndex >= info.startIndex && activeIndex < info.startIndex + info.matches.length;\n return isActive ? { activeChunkIndex: activeIndex - info.startIndex, chunks: info.matches } : { chunks: info.matches };\n}\n\nfunction computeHighlightState(rootNodes: PresentationTreeNode[], searchText: string, state: HighlightState, activeNodeId?: string, activeMatchIndex?: number) {\n const newState: HighlightState = { nodeInfoMap: new Map(), totalMatches: 0 };\n let newActiveIndex = activeMatchIndex ?? 0;\n\n const computeHighlightStateRecursively = (nodes: Array<PresentationTreeNode>) => {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n\n if (node.nodeData.filtering?.isFilterTarget) {\n const matches = findChunks(node.label, searchText);\n newState.nodeInfoMap.set(node.id, { startIndex: newState.totalMatches, matches });\n newState.totalMatches += matches.length;\n }\n\n if (\n typeof node.children !== \"boolean\" &&\n (HierarchyNode.isGroupingNode(node.nodeData) || node.nodeData.filtering?.filteredChildrenIdentifierPaths?.length)\n ) {\n computeHighlightStateRecursively(node.children);\n }\n });\n };\n\n computeHighlightStateRecursively(rootNodes);\n\n // update active index to not cause active chunk jumps when hierarchy changes\n if (activeNodeId && newActiveIndex !== 0) {\n const activeNodeInfo = getNodeChunkInfo(state, activeNodeId, activeMatchIndex);\n const updatedInfo = newState.nodeInfoMap.get(activeNodeId);\n\n if (updatedInfo && activeNodeInfo?.activeChunkIndex !== undefined) {\n newActiveIndex = updatedInfo.startIndex + activeNodeInfo.activeChunkIndex;\n }\n }\n\n return { state: newState, activeIndex: newActiveIndex };\n}\n\nfunction findChunks(text: string, searchText: string): HighlightedChunk[] {\n const chunks: HighlightedChunk[] = [];\n\n const contentText = text.toLowerCase();\n const inputText = searchText.toLowerCase();\n let index = contentText.indexOf(inputText);\n\n while (index !== -1) {\n chunks.push({ start: index, end: index + inputText.length });\n index = contentText.indexOf(inputText, index + 1);\n }\n\n return chunks;\n}\n\nfunction markChunks(text: string, chunks: HighlightedChunk[], activeChunk?: number) {\n const markedText: React.ReactElement[] = [];\n let previousIndex = 0;\n\n const { mergedChunks, newActiveIndex } = mergeChunks(chunks, activeChunk);\n\n for (let i = 0; i < mergedChunks.length; i++) {\n const { start, end } = mergedChunks[i];\n\n // add unmarked text between previous chunk and current one\n const nonMarkedText = text.substring(previousIndex, start);\n nonMarkedText.length && markedText.push(<span key={previousIndex}>{nonMarkedText}</span>);\n\n // add marked chunk text\n markedText.push(\n <mark key={start} className={i === newActiveIndex ? \"tw-active-match-highlight\" : undefined}>\n {text.substring(start, end)}\n </mark>,\n );\n previousIndex = end;\n }\n\n // add unmarked text after last chunk\n const lastNonMarkedText = text.substring(previousIndex, text.length);\n lastNonMarkedText.length && markedText.push(<span key={previousIndex}>{lastNonMarkedText}</span>);\n\n return markedText;\n}\n\nfunction mergeChunks(chunks: HighlightedChunk[], activeChunk?: number) {\n const mergedChunks: HighlightedChunk[] = [];\n let lastChunk: { isActive: boolean; info: HighlightedChunk } | undefined;\n let newActiveIndex: number | undefined;\n\n for (let i = 0; i < chunks.length; i++) {\n const chunk = chunks[i];\n const isActive = i === activeChunk;\n if (lastChunk && lastChunk.info.end === chunk.start && !isActive && !lastChunk.isActive) {\n lastChunk.info.end = chunk.end;\n continue;\n }\n isActive && (newActiveIndex = mergedChunks.length);\n const newChunk = { start: chunk.start, end: chunk.end };\n lastChunk = { isActive, info: newChunk };\n mergedChunks.push(newChunk);\n }\n return { mergedChunks, newActiveIndex };\n}\n"]}
|
|
@@ -11,6 +11,8 @@ export declare function parseIdsSelectorResult(selectorResult: any): Id64Array;
|
|
|
11
11
|
export declare function pushToMap<TKey, TValue>(targetMap: Map<TKey, Set<TValue>>, key: TKey, value: TValue): void;
|
|
12
12
|
/** @internal */
|
|
13
13
|
export declare function useLatest<T>(value: T): import("react").MutableRefObject<T>;
|
|
14
|
+
/** @public */
|
|
15
|
+
export type NormalizedHierarchyFilteringPath = ReturnType<(typeof HierarchyFilteringPath)["normalize"]>;
|
|
14
16
|
/** @internal */
|
|
15
|
-
export declare function joinHierarchyFilteringPaths(subTreePaths: HierarchyNodeIdentifiersPath[], filteringPaths:
|
|
17
|
+
export declare function joinHierarchyFilteringPaths(subTreePaths: HierarchyNodeIdentifiersPath[], filteringPaths: NormalizedHierarchyFilteringPath[]): NormalizedHierarchyFilteringPath[];
|
|
16
18
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -51,31 +51,30 @@ function useLatest(value) {
|
|
|
51
51
|
}
|
|
52
52
|
/** @internal */
|
|
53
53
|
function joinHierarchyFilteringPaths(subTreePaths, filteringPaths) {
|
|
54
|
-
const normalizedFilteringPaths = filteringPaths.map((filteringPath) => presentation_hierarchies_1.HierarchyFilteringPath.normalize(filteringPath));
|
|
55
54
|
const result = new Array();
|
|
56
55
|
const filteringPathsToIncludeIndexes = new Set();
|
|
57
56
|
subTreePaths.forEach((subTreePath) => {
|
|
58
57
|
let options;
|
|
59
58
|
let addSubTreePathToResult = false;
|
|
60
|
-
for (let i = 0; i <
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
59
|
+
for (let i = 0; i < filteringPaths.length; ++i) {
|
|
60
|
+
const filteringPath = filteringPaths[i];
|
|
61
|
+
if (filteringPath.path.length === 0) {
|
|
63
62
|
continue;
|
|
64
63
|
}
|
|
65
64
|
for (let j = 0; j < subTreePath.length; ++j) {
|
|
66
65
|
const identifier = subTreePath[j];
|
|
67
|
-
if (
|
|
66
|
+
if (filteringPath.path.length <= j || !presentation_hierarchies_1.HierarchyNodeIdentifier.equal(filteringPath.path[j], identifier)) {
|
|
68
67
|
break;
|
|
69
68
|
}
|
|
70
69
|
// filtering paths that are shorter or equal than subTree paths length don't need to be added to the result
|
|
71
|
-
if (
|
|
70
|
+
if (filteringPath.path.length === j + 1) {
|
|
72
71
|
addSubTreePathToResult = true;
|
|
73
72
|
// If filtering path has autoExpand set to true, it means that we should expand only to the targeted filtered node
|
|
74
73
|
// This is done by setting depthInPath
|
|
75
74
|
options =
|
|
76
|
-
|
|
77
|
-
? presentation_hierarchies_1.HierarchyFilteringPath.mergeOptions(options,
|
|
78
|
-
: { autoExpand: { depthInPath:
|
|
75
|
+
filteringPath.options?.autoExpand !== true
|
|
76
|
+
? presentation_hierarchies_1.HierarchyFilteringPath.mergeOptions(options, filteringPath.options)
|
|
77
|
+
: { autoExpand: { depthInPath: filteringPath.path.length } };
|
|
79
78
|
break;
|
|
80
79
|
}
|
|
81
80
|
// filtering paths that are longer than subTree paths need to be added to the result
|
|
@@ -93,7 +92,7 @@ function joinHierarchyFilteringPaths(subTreePaths, filteringPaths) {
|
|
|
93
92
|
}
|
|
94
93
|
});
|
|
95
94
|
for (const index of filteringPathsToIncludeIndexes) {
|
|
96
|
-
result.push(
|
|
95
|
+
result.push(filteringPaths[index]);
|
|
97
96
|
}
|
|
98
97
|
return result;
|
|
99
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/Utils.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;A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C,CAAC,CAAC;IACH,KAAK,MAAM,KAAK,IAAI,8BAA8B,EAAE,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,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, useRef } from \"react\";\nimport { HierarchyFilteringPath, HierarchyNodeIdentifier } from \"@itwin/presentation-hierarchies\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { HierarchyFilteringPathOptions, HierarchyNodeIdentifiersPath } from \"@itwin/presentation-hierarchies\";\n\n/** @beta */\nexport type FunctionProps<THook extends (props: any) => any> = Parameters<THook>[0];\n\n/** @internal */\nexport function createIdsSelector(ids: Id64Array): string {\n // Note: `json_array` function only accepts up to 127 arguments and we may have more `ids` than that. As a workaround,\n // we're creating an array of arrays\n const slices = new Array<Id64String[]>();\n for (let sliceStartIndex = 0; sliceStartIndex < ids.length; sliceStartIndex += 127) {\n let sliceEndIndex: number | undefined = sliceStartIndex + 127;\n if (sliceEndIndex > ids.length) {\n sliceEndIndex = undefined;\n }\n slices.push(ids.slice(sliceStartIndex, sliceEndIndex));\n }\n return `json_array(${slices.map((sliceIds) => `json_array(${sliceIds.map((id) => `'${id}'`).join(\",\")})`).join(\",\")})`;\n}\n\n/** @internal */\nexport function parseIdsSelectorResult(selectorResult: any): Id64Array {\n if (!Array.isArray(selectorResult)) {\n return [];\n }\n return selectorResult.reduce((arr, ids: Id64String | Id64String[]) => [...arr, ...(Array.isArray(ids) ? ids : [ids])], new Array<Id64String>());\n}\n\n/** @internal */\nexport function pushToMap<TKey, TValue>(targetMap: Map<TKey, Set<TValue>>, key: TKey, value: TValue) {\n let set = targetMap.get(key);\n if (!set) {\n set = new Set();\n targetMap.set(key, set);\n }\n set.add(value);\n}\n\n/** @internal */\nexport function useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref;\n}\n\n/** @public */\nexport type NormalizedHierarchyFilteringPath = ReturnType<(typeof HierarchyFilteringPath)[\"normalize\"]>;\n\n/** @internal */\nexport function joinHierarchyFilteringPaths(\n subTreePaths: HierarchyNodeIdentifiersPath[],\n filteringPaths: NormalizedHierarchyFilteringPath[],\n): NormalizedHierarchyFilteringPath[] {\n const result = new Array<NormalizedHierarchyFilteringPath>();\n const filteringPathsToIncludeIndexes = new Set<number>();\n\n subTreePaths.forEach((subTreePath) => {\n let options: HierarchyFilteringPathOptions | undefined;\n let addSubTreePathToResult = false;\n\n for (let i = 0; i < filteringPaths.length; ++i) {\n const filteringPath = filteringPaths[i];\n if (filteringPath.path.length === 0) {\n continue;\n }\n\n for (let j = 0; j < subTreePath.length; ++j) {\n const identifier = subTreePath[j];\n if (filteringPath.path.length <= j || !HierarchyNodeIdentifier.equal(filteringPath.path[j], identifier)) {\n break;\n }\n\n // filtering paths that are shorter or equal than subTree paths length don't need to be added to the result\n if (filteringPath.path.length === j + 1) {\n addSubTreePathToResult = true;\n // If filtering path has autoExpand set to true, it means that we should expand only to the targeted filtered node\n // This is done by setting depthInPath\n options =\n filteringPath.options?.autoExpand !== true\n ? HierarchyFilteringPath.mergeOptions(options, filteringPath.options)\n : { autoExpand: { depthInPath: filteringPath.path.length } };\n break;\n }\n\n // filtering paths that are longer than subTree paths need to be added to the result\n if (subTreePath.length === j + 1) {\n addSubTreePathToResult = true;\n filteringPathsToIncludeIndexes.add(i);\n }\n }\n }\n\n if (addSubTreePathToResult) {\n result.push({\n path: subTreePath,\n options,\n });\n }\n });\n for (const index of filteringPathsToIncludeIndexes) {\n result.push(filteringPaths[index]);\n }\n return result;\n}\n"]}
|
|
@@ -100,7 +100,7 @@ function ModelsTreeComponentImpl({ iModel, viewport, headerButtons, onFeatureUse
|
|
|
100
100
|
return ((0, jsx_runtime_1.jsx)(UseTelemetryContext_js_1.TelemetryContextProvider, { componentIdentifier: exports.ModelsTreeComponent.id, onFeatureUsed: onFeatureUsed, onPerformanceMeasured: onPerformanceMeasured, children: (0, jsx_runtime_1.jsx)(TreeWithHeader_js_1.TreeWithHeader, { filteringProps: {
|
|
101
101
|
onFilterStart: applyFilter,
|
|
102
102
|
onFilterClear: clearFilter,
|
|
103
|
-
isDisabled: instanceFocusEnabled
|
|
103
|
+
isDisabled: instanceFocusEnabled,
|
|
104
104
|
}, buttons: buttons, density: density, children: (0, jsx_runtime_1.jsx)(ModelsTree_js_1.ModelsTree, { ...treeProps, imodel: iModel, activeView: viewport, filter: filter, onModelsFiltered: onModelsFiltered }) }) }));
|
|
105
105
|
}
|
|
106
106
|
//# sourceMappingURL=ModelsTreeComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelsTreeComponent.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.tsx"],"names":[],"mappings":";;;;;AAAA;;;gGAGgG;AAEhG,iCAA4C;AAC5C,oDAA+D;AAC/D,0DAAoD;AACpD,2EAAqE;AACrE,qFAAmH;AACnH,yEAAmE;AACnE,+DAAyD;AACzD,6EAA4E;AAC5E,mDAA6C;AAC7C,iEAQgC;AAwChC;;;;;GAKG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAA+B,EAAE,EAAE;IACrE,MAAM,MAAM,GAAG,IAAA,uCAAyB,GAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,wCAAiB,GAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,uBAAC,4DAA+B,IAAC,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,YAC9F,uBAAC,uBAAuB,OAAK,K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BAAgB;aACjE,EACD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,YAEhB,uBAAC,0BAAU,OAAK,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,GAAI,GACxG,GACQ,CAC5B,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 { Fragment, useEffect } from \"react\";\nimport { useActiveIModelConnection } from \"@itwin/appui-react\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { TreeWithHeader } from \"../../tree-header/TreeWithHeader.js\";\nimport { FocusedInstancesContextProvider, useFocusedInstancesContext } from \"../common/FocusedInstancesContext.js\";\nimport { useActiveViewport } from \"../common/UseActiveViewport.js\";\nimport { useFiltering } from \"../common/UseFiltering.js\";\nimport { TelemetryContextProvider } from \"../common/UseTelemetryContext.js\";\nimport { ModelsTree } from \"./ModelsTree.js\";\nimport {\n HideAllButton,\n InvertButton,\n ShowAllButton,\n ToggleInstancesFocusButton,\n useModelsTreeButtonProps,\n View2DButton,\n View3DButton,\n} from \"./ModelsTreeButtons.js\";\n\nimport type { ModelsTreeProps } from \"./ModelsTree.js\";\nimport type { ReactNode } from \"react\";\nimport type { IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport type { ModelsTreeHeaderButtonProps, ModelsTreeHeaderButtonType } from \"./ModelsTreeButtons.js\";\n\n/** @public */\ninterface ModelsTreeComponentProps\n extends Pick<\n ModelsTreeProps,\n | \"getSchemaContext\"\n | \"selectionStorage\"\n | \"density\"\n | \"hierarchyLevelConfig\"\n | \"selectionMode\"\n | \"selectionPredicate\"\n | \"hierarchyConfig\"\n | \"visibilityHandlerOverrides\"\n | \"getFilteredPaths\"\n | \"getSubTreePaths\"\n > {\n /**\n * Renderers of header buttons. Defaults to:\n * ```ts\n * [\n * ModelsTreeComponent.ShowAllButton,\n * ModelsTreeComponent.HideAllButton,\n * ModelsTreeComponent.InvertButton,\n * ModelsTreeComponent.View2DButton,\n * ModelsTreeComponent.View3DButton,\n * ModelsTreeComponent.ToggleInstancesFocusButton,\n * ]\n * ```\n */\n headerButtons?: Array<(props: ModelsTreeHeaderButtonProps) => React.ReactNode>;\n onPerformanceMeasured?: (featureId: string, duration: number) => void;\n onFeatureUsed?: (feature: string) => void;\n}\n\n/**\n * A component that renders `ModelsTree` and a header with filtering capabilities\n * and header buttons.\n *\n * @public\n */\nexport const ModelsTreeComponent = (props: ModelsTreeComponentProps) => {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return (\n <FocusedInstancesContextProvider selectionStorage={props.selectionStorage} imodelKey={iModel.key}>\n <ModelsTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />\n </FocusedInstancesContextProvider>\n );\n};\n\n/**\n * Renders a \"Show all\" button that enables display of all models.\n * @public\n */\nModelsTreeComponent.ShowAllButton = ShowAllButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"Hide all\" button that disables display of all models.\n * @public\n */\nModelsTreeComponent.HideAllButton = HideAllButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders an \"Invert all\" button that inverts display of all models.\n * @public\n */\nModelsTreeComponent.InvertButton = InvertButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"View 2D\" button that enables display of all plan projection models and disables all others.\n * @public\n */\nModelsTreeComponent.View2DButton = View2DButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"View 3D\" button that enables display of all non-plan projection models and disables all plan projection ones.\n * @public\n */\nModelsTreeComponent.View3DButton = View3DButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders an \"Instance focus\" toggle button that enables/disables instances focusing mode.\n *\n * Requires instances focus context to be provided using `FocusedInstancesContextProvider`. The context\n * is provided automatically, when using `ModelsTreeComponent`, but needs to be provided by consumers\n * when rendering `ToggleInstancesFocusButton` outside of `ModelsTreeComponent`.\n *\n * @public\n */\nModelsTreeComponent.ToggleInstancesFocusButton = ToggleInstancesFocusButton as ModelsTreeHeaderButtonType;\n\n/**\n * Id of the component. May be used when a creating a `TreeDefinition` for `SelectableTree`.\n * @public\n */\nModelsTreeComponent.id = \"models-tree-v2\";\n\n/**\n * Label of the component. May be used when a creating a `TreeDefinition` for `SelectableTree`.\n * @public\n */\nModelsTreeComponent.getLabel = () => TreeWidget.translate(\"modelsTree.label\");\n\nfunction ModelsTreeComponentImpl({\n iModel,\n viewport,\n headerButtons,\n onFeatureUsed,\n onPerformanceMeasured,\n ...treeProps\n}: ModelsTreeComponentProps & { iModel: IModelConnection; viewport: ScreenViewport }) {\n const { buttonProps, onModelsFiltered } = useModelsTreeButtonProps({ imodel: iModel, viewport });\n const { filter, applyFilter, clearFilter } = useFiltering();\n const { enabled: instanceFocusEnabled } = useFocusedInstancesContext();\n const density = treeProps.density;\n\n const buttons: ReactNode = headerButtons\n ? headerButtons.map((btn, index) => <Fragment key={index}>{btn({ ...buttonProps, onFeatureUsed })}</Fragment>)\n : [\n <ShowAllButton {...buttonProps} key=\"show-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <HideAllButton {...buttonProps} key=\"hide-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <InvertButton {...buttonProps} key=\"invert-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <View2DButton {...buttonProps} key=\"view-2d-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <View3DButton {...buttonProps} key=\"view-3d-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <ToggleInstancesFocusButton key=\"toggle-instances-focus-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n ];\n\n useEffect(() => {\n if (instanceFocusEnabled) {\n clearFilter();\n }\n }, [instanceFocusEnabled, clearFilter]);\n\n return (\n <TelemetryContextProvider componentIdentifier={ModelsTreeComponent.id} onFeatureUsed={onFeatureUsed} onPerformanceMeasured={onPerformanceMeasured}>\n <TreeWithHeader\n filteringProps={{\n onFilterStart: applyFilter,\n onFilterClear: clearFilter,\n isDisabled: instanceFocusEnabled || !!treeProps.getFilteredPaths,\n }}\n buttons={buttons}\n density={density}\n >\n <ModelsTree {...treeProps} imodel={iModel} activeView={viewport} filter={filter} onModelsFiltered={onModelsFiltered} />\n </TreeWithHeader>\n </TelemetryContextProvider>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ModelsTreeComponent.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.tsx"],"names":[],"mappings":";;;;;AAAA;;;gGAGgG;AAEhG,iCAA4C;AAC5C,oDAA+D;AAC/D,0DAAoD;AACpD,2EAAqE;AACrE,qFAAmH;AACnH,yEAAmE;AACnE,+DAAyD;AACzD,6EAA4E;AAC5E,mDAA6C;AAC7C,iEAQgC;AAwChC;;;;;GAKG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAA+B,EAAE,EAAE;IACrE,MAAM,MAAM,GAAG,IAAA,uCAAyB,GAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,wCAAiB,GAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,uBAAC,4DAA+B,IAAC,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,YAC9F,uBAAC,uBAAuB,OAAK,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAI,GAC1C,CACnC,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,mBAAmB,uBAa9B;AAEF;;;GAGG;AACH,2BAAmB,CAAC,aAAa,GAAG,oCAA2C,CAAC;AAEhF;;;GAGG;AACH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ent":["/*---------------------------------------------------------------------------------------------\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 { Fragment, useEffect } from \"react\";\nimport { useActiveIModelConnection } from \"@itwin/appui-react\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { TreeWithHeader } from \"../../tree-header/TreeWithHeader.js\";\nimport { FocusedInstancesContextProvider, useFocusedInstancesContext } from \"../common/FocusedInstancesContext.js\";\nimport { useActiveViewport } from \"../common/UseActiveViewport.js\";\nimport { useFiltering } from \"../common/UseFiltering.js\";\nimport { TelemetryContextProvider } from \"../common/UseTelemetryContext.js\";\nimport { ModelsTree } from \"./ModelsTree.js\";\nimport {\n HideAllButton,\n InvertButton,\n ShowAllButton,\n ToggleInstancesFocusButton,\n useModelsTreeButtonProps,\n View2DButton,\n View3DButton,\n} from \"./ModelsTreeButtons.js\";\n\nimport type { ModelsTreeProps } from \"./ModelsTree.js\";\nimport type { ReactNode } from \"react\";\nimport type { IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport type { ModelsTreeHeaderButtonProps, ModelsTreeHeaderButtonType } from \"./ModelsTreeButtons.js\";\n\n/** @public */\ninterface ModelsTreeComponentProps\n extends Pick<\n ModelsTreeProps,\n | \"getSchemaContext\"\n | \"selectionStorage\"\n | \"density\"\n | \"hierarchyLevelConfig\"\n | \"selectionMode\"\n | \"selectionPredicate\"\n | \"hierarchyConfig\"\n | \"visibilityHandlerOverrides\"\n | \"getFilteredPaths\"\n | \"getSubTreePaths\"\n > {\n /**\n * Renderers of header buttons. Defaults to:\n * ```ts\n * [\n * ModelsTreeComponent.ShowAllButton,\n * ModelsTreeComponent.HideAllButton,\n * ModelsTreeComponent.InvertButton,\n * ModelsTreeComponent.View2DButton,\n * ModelsTreeComponent.View3DButton,\n * ModelsTreeComponent.ToggleInstancesFocusButton,\n * ]\n * ```\n */\n headerButtons?: Array<(props: ModelsTreeHeaderButtonProps) => React.ReactNode>;\n onPerformanceMeasured?: (featureId: string, duration: number) => void;\n onFeatureUsed?: (feature: string) => void;\n}\n\n/**\n * A component that renders `ModelsTree` and a header with filtering capabilities\n * and header buttons.\n *\n * @public\n */\nexport const ModelsTreeComponent = (props: ModelsTreeComponentProps) => {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return (\n <FocusedInstancesContextProvider selectionStorage={props.selectionStorage} imodelKey={iModel.key}>\n <ModelsTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />\n </FocusedInstancesContextProvider>\n );\n};\n\n/**\n * Renders a \"Show all\" button that enables display of all models.\n * @public\n */\nModelsTreeComponent.ShowAllButton = ShowAllButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"Hide all\" button that disables display of all models.\n * @public\n */\nModelsTreeComponent.HideAllButton = HideAllButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders an \"Invert all\" button that inverts display of all models.\n * @public\n */\nModelsTreeComponent.InvertButton = InvertButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"View 2D\" button that enables display of all plan projection models and disables all others.\n * @public\n */\nModelsTreeComponent.View2DButton = View2DButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"View 3D\" button that enables display of all non-plan projection models and disables all plan projection ones.\n * @public\n */\nModelsTreeComponent.View3DButton = View3DButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders an \"Instance focus\" toggle button that enables/disables instances focusing mode.\n *\n * Requires instances focus context to be provided using `FocusedInstancesContextProvider`. The context\n * is provided automatically, when using `ModelsTreeComponent`, but needs to be provided by consumers\n * when rendering `ToggleInstancesFocusButton` outside of `ModelsTreeComponent`.\n *\n * @public\n */\nModelsTreeComponent.ToggleInstancesFocusButton = ToggleInstancesFocusButton as ModelsTreeHeaderButtonType;\n\n/**\n * Id of the component. May be used when a creating a `TreeDefinition` for `SelectableTree`.\n * @public\n */\nModelsTreeComponent.id = \"models-tree-v2\";\n\n/**\n * Label of the component. May be used when a creating a `TreeDefinition` for `SelectableTree`.\n * @public\n */\nModelsTreeComponent.getLabel = () => TreeWidget.translate(\"modelsTree.label\");\n\nfunction ModelsTreeComponentImpl({\n iModel,\n viewport,\n headerButtons,\n onFeatureUsed,\n onPerformanceMeasured,\n ...treeProps\n}: ModelsTreeComponentProps & { iModel: IModelConnection; viewport: ScreenViewport }) {\n const { buttonProps, onModelsFiltered } = useModelsTreeButtonProps({ imodel: iModel, viewport });\n const { filter, applyFilter, clearFilter } = useFiltering();\n const { enabled: instanceFocusEnabled } = useFocusedInstancesContext();\n const density = treeProps.density;\n\n const buttons: ReactNode = headerButtons\n ? headerButtons.map((btn, index) => <Fragment key={index}>{btn({ ...buttonProps, onFeatureUsed })}</Fragment>)\n : [\n <ShowAllButton {...buttonProps} key=\"show-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <HideAllButton {...buttonProps} key=\"hide-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <InvertButton {...buttonProps} key=\"invert-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <View2DButton {...buttonProps} key=\"view-2d-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <View3DButton {...buttonProps} key=\"view-3d-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <ToggleInstancesFocusButton key=\"toggle-instances-focus-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n ];\n\n useEffect(() => {\n if (instanceFocusEnabled) {\n clearFilter();\n }\n }, [instanceFocusEnabled, clearFilter]);\n\n return (\n <TelemetryContextProvider componentIdentifier={ModelsTreeComponent.id} onFeatureUsed={onFeatureUsed} onPerformanceMeasured={onPerformanceMeasured}>\n <TreeWithHeader\n filteringProps={{\n onFilterStart: applyFilter,\n onFilterClear: clearFilter,\n isDisabled: instanceFocusEnabled,\n }}\n buttons={buttons}\n density={density}\n >\n <ModelsTree {...treeProps} imodel={iModel} activeView={viewport} filter={filter} onModelsFiltered={onModelsFiltered} />\n </TreeWithHeader>\n </TelemetryContextProvider>\n );\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ProcessedHierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
+
import type { NormalizedHierarchyFilteringPath } from "../common/Utils.js";
|
|
2
3
|
import type { Id64String } from "@itwin/core-bentley";
|
|
3
4
|
import type { ECClassHierarchyInspector, ECSchemaProvider, InstanceKey } from "@itwin/presentation-shared";
|
|
4
|
-
import type { ClassGroupingNodeKey,
|
|
5
|
+
import type { ClassGroupingNodeKey, DefineHierarchyLevelProps, GroupingHierarchyNode, HierarchyDefinition, HierarchyLevelDefinition, LimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
|
|
5
6
|
import type { ModelsTreeIdsCache } from "./internal/ModelsTreeIdsCache.js";
|
|
6
7
|
/** @beta */
|
|
7
8
|
export type ClassGroupingHierarchyNode = GroupingHierarchyNode & {
|
|
@@ -56,9 +57,6 @@ type ModelsTreeInstanceKeyPathsFromInstanceLabelProps = {
|
|
|
56
57
|
label: string;
|
|
57
58
|
} & ModelsTreeInstanceKeyPathsBaseProps;
|
|
58
59
|
export type ModelsTreeInstanceKeyPathsProps = ModelsTreeInstanceKeyPathsFromTargetItemsProps | ModelsTreeInstanceKeyPathsFromInstanceLabelProps;
|
|
59
|
-
type HierarchyProviderProps = Parameters<typeof createIModelHierarchyProvider>[0];
|
|
60
|
-
type HierarchyFilteringPaths = NonNullable<NonNullable<HierarchyProviderProps["filtering"]>["paths"]>;
|
|
61
|
-
type HierarchyFilteringPath = HierarchyFilteringPaths[number];
|
|
62
60
|
export declare namespace ModelsTreeInstanceKeyPathsProps {
|
|
63
61
|
function isLabelProps(props: ModelsTreeInstanceKeyPathsProps): props is ModelsTreeInstanceKeyPathsFromInstanceLabelProps;
|
|
64
62
|
}
|
|
@@ -78,7 +76,7 @@ export declare class ModelsTreeDefinition implements HierarchyDefinition {
|
|
|
78
76
|
private createGeometricModel3dChildrenQuery;
|
|
79
77
|
private createSpatialCategoryChildrenQuery;
|
|
80
78
|
private createGeometricElement3dChildrenQuery;
|
|
81
|
-
static createInstanceKeyPaths(props: ModelsTreeInstanceKeyPathsProps): Promise<
|
|
79
|
+
static createInstanceKeyPaths(props: ModelsTreeInstanceKeyPathsProps): Promise<NormalizedHierarchyFilteringPath[]>;
|
|
82
80
|
private supportsFiltering;
|
|
83
81
|
private isSupported;
|
|
84
82
|
}
|
|
@@ -506,7 +506,7 @@ function createGeometricElementInstanceKeyPaths(imodelAccess, idsCache, hierarch
|
|
|
506
506
|
newModelPath.pop(); // model is already included in the element hierarchy path
|
|
507
507
|
const path = [...newModelPath, ...elementHierarchyPath];
|
|
508
508
|
if (!groupingNode) {
|
|
509
|
-
return path;
|
|
509
|
+
return { path };
|
|
510
510
|
}
|
|
511
511
|
return {
|
|
512
512
|
path,
|
|
@@ -581,7 +581,7 @@ function createInstanceKeyPathsFromTargetItemsObs({ targetItems, imodelAccess, h
|
|
|
581
581
|
elements: new Array(),
|
|
582
582
|
}), (0, rxjs_1.switchMap)(async (ids) => {
|
|
583
583
|
const elementsLength = ids.elements.length;
|
|
584
|
-
return (0, Rxjs_js_1.collect)((0, rxjs_1.merge)((0, rxjs_1.from)(ids.subjects).pipe((0, rxjs_1.mergeMap)((id) => (0, rxjs_1.from)(idsCache.createSubjectInstanceKeysPath(id)))), (0, rxjs_1.from)(ids.models).pipe((0, rxjs_1.mergeMap)((id) => (0, rxjs_1.from)(idsCache.createModelInstanceKeyPaths(id)).pipe((0, rxjs_1.mergeAll)()))), (0, rxjs_1.from)(ids.categories).pipe((0, rxjs_1.mergeMap)((id) => (0, rxjs_1.from)(idsCache.createCategoryInstanceKeyPaths(id)).pipe((0, rxjs_1.mergeAll)()))), (0, rxjs_1.from)(ids.elements).pipe((0, rxjs_1.bufferCount)(Math.ceil(elementsLength / Math.ceil(elementsLength / 5000))), (0, Utils_js_2.releaseMainThreadOnItemsCount)(1), (0, rxjs_1.mergeMap)((block) => createGeometricElementInstanceKeyPaths(imodelAccess, idsCache, hierarchyConfig, block), 10))));
|
|
584
|
+
return (0, Rxjs_js_1.collect)((0, rxjs_1.merge)((0, rxjs_1.from)(ids.subjects).pipe((0, rxjs_1.mergeMap)((id) => (0, rxjs_1.from)(idsCache.createSubjectInstanceKeysPath(id)).pipe((0, rxjs_1.map)(presentation_hierarchies_1.HierarchyFilteringPath.normalize)))), (0, rxjs_1.from)(ids.models).pipe((0, rxjs_1.mergeMap)((id) => (0, rxjs_1.from)(idsCache.createModelInstanceKeyPaths(id)).pipe((0, rxjs_1.mergeAll)(), (0, rxjs_1.map)(presentation_hierarchies_1.HierarchyFilteringPath.normalize)))), (0, rxjs_1.from)(ids.categories).pipe((0, rxjs_1.mergeMap)((id) => (0, rxjs_1.from)(idsCache.createCategoryInstanceKeyPaths(id)).pipe((0, rxjs_1.mergeAll)(), (0, rxjs_1.map)(presentation_hierarchies_1.HierarchyFilteringPath.normalize)))), (0, rxjs_1.from)(ids.elements).pipe((0, rxjs_1.bufferCount)(Math.ceil(elementsLength / Math.ceil(elementsLength / 5000))), (0, Utils_js_2.releaseMainThreadOnItemsCount)(1), (0, rxjs_1.mergeMap)((block) => createGeometricElementInstanceKeyPaths(imodelAccess, idsCache, hierarchyConfig, block), 10))));
|
|
585
585
|
}));
|
|
586
586
|
}
|
|
587
587
|
function createInstanceKeyPathsFromInstanceLabelObs(props) {
|