@itwin/tree-widget-react 4.0.0-alpha.5 → 4.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.md +2 -1
  3. package/lib/esm/tree-widget-react/TreeWidget.js +1 -1
  4. package/lib/esm/tree-widget-react/TreeWidget.js.map +1 -1
  5. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js +1 -1
  6. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
  7. package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js +1 -1
  8. package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js.map +1 -1
  9. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.d.ts +1 -0
  10. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +3 -2
  11. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js.map +1 -1
  12. package/lib/esm/tree-widget-react/components/tree-header/SelectableTree.css +2 -1
  13. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.d.ts +2 -2
  14. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js +3 -2
  15. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js.map +1 -1
  16. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.d.ts +9 -2
  17. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +53 -7
  18. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  19. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.d.ts +1 -1
  20. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.js +1 -1
  21. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
  22. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +30 -3
  23. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +588 -170
  24. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  25. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.d.ts +15 -4
  26. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +149 -56
  27. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  28. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +30 -15
  29. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +192 -38
  30. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
  31. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +18 -3
  32. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +30 -3
  33. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -1
  34. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.d.ts +24 -0
  35. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js +785 -0
  36. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js.map +1 -0
  37. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.d.ts +39 -0
  38. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.js +221 -0
  39. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.js.map +1 -0
  40. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +5 -17
  41. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +5 -62
  42. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  43. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.d.ts +2 -0
  44. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js +4 -2
  45. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  46. package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.d.ts +1 -0
  47. package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js +2 -1
  48. package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js.map +1 -1
  49. package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.d.ts +1 -0
  50. package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.js +2 -1
  51. package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.js.map +1 -1
  52. package/lib/esm/tree-widget-react/components/trees/common/Utils.d.ts +33 -23
  53. package/lib/esm/tree-widget-react/components/trees/common/Utils.js +60 -47
  54. package/lib/esm/tree-widget-react/components/trees/common/Utils.js.map +1 -1
  55. package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js +3 -3
  56. package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js.map +1 -1
  57. package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.d.ts +1 -0
  58. package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.js +1 -0
  59. package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.js.map +1 -1
  60. package/lib/esm/tree-widget-react/components/trees/common/components/EmptyTree.css +1 -0
  61. package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.d.ts +1 -0
  62. package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.js +4 -3
  63. package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.js.map +1 -1
  64. package/lib/esm/tree-widget-react/components/trees/{categories-tree/internal/ClassNameDefinitions.js → common/components/SkeletonTree.css} +12 -7
  65. package/lib/esm/tree-widget-react/components/trees/common/components/SkeletonTree.d.ts +4 -0
  66. package/lib/esm/tree-widget-react/components/trees/common/components/SkeletonTree.js +16 -0
  67. package/lib/esm/tree-widget-react/components/trees/common/components/SkeletonTree.js.map +1 -0
  68. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.css +11 -0
  69. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.d.ts +1 -0
  70. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +8 -7
  71. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  72. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js +3 -3
  73. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js.map +1 -1
  74. package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.d.ts +1 -0
  75. package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js +1 -0
  76. package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js.map +1 -1
  77. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js +1 -1
  78. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js.map +1 -1
  79. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -1
  80. package/lib/esm/tree-widget-react/components/trees/common/internal/AlwaysAndNeverDrawnElementInfo.d.ts +44 -0
  81. package/lib/esm/tree-widget-react/components/trees/{models-tree → common}/internal/AlwaysAndNeverDrawnElementInfo.js +81 -31
  82. package/lib/esm/tree-widget-react/components/trees/common/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -0
  83. package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.d.ts +33 -0
  84. package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.js +37 -0
  85. package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.js.map +1 -0
  86. package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.d.ts +16 -0
  87. package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.js +72 -0
  88. package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.js.map +1 -0
  89. package/lib/esm/tree-widget-react/components/trees/common/{Rxjs.d.ts → internal/Rxjs.d.ts} +9 -2
  90. package/lib/esm/tree-widget-react/components/trees/common/{Rxjs.js → internal/Rxjs.js} +9 -2
  91. package/lib/esm/tree-widget-react/components/trees/common/internal/Rxjs.js.map +1 -0
  92. package/lib/esm/tree-widget-react/components/trees/common/{Tooltip.d.ts → internal/Tooltip.d.ts} +5 -1
  93. package/lib/esm/tree-widget-react/components/trees/common/{Tooltip.js → internal/Tooltip.js} +7 -1
  94. package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js.map +1 -0
  95. package/lib/esm/tree-widget-react/components/trees/common/internal/Types.d.ts +14 -0
  96. package/lib/esm/tree-widget-react/components/trees/common/internal/Types.js +6 -0
  97. package/lib/esm/tree-widget-react/components/trees/common/internal/Types.js.map +1 -0
  98. package/lib/esm/tree-widget-react/components/trees/common/internal/UseActiveViewport.js.map +1 -0
  99. package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchiesLocalization.d.ts → internal/UseHierarchiesLocalization.d.ts} +1 -0
  100. package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchiesLocalization.js → internal/UseHierarchiesLocalization.js} +6 -2
  101. package/lib/esm/tree-widget-react/components/trees/common/internal/UseHierarchiesLocalization.js.map +1 -0
  102. package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchyFiltering.d.ts → internal/UseHierarchyFiltering.d.ts} +1 -0
  103. package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchyFiltering.js → internal/UseHierarchyFiltering.js} +4 -3
  104. package/lib/esm/tree-widget-react/components/trees/common/internal/UseHierarchyFiltering.js.map +1 -0
  105. package/lib/esm/tree-widget-react/components/trees/common/{UseIModelChangeListener.d.ts → internal/UseIModelChangeListener.d.ts} +1 -0
  106. package/lib/esm/tree-widget-react/components/trees/common/{UseIModelChangeListener.js → internal/UseIModelChangeListener.js} +1 -0
  107. package/lib/esm/tree-widget-react/components/trees/common/internal/UseIModelChangeListener.js.map +1 -0
  108. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.d.ts +47 -0
  109. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js +101 -0
  110. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js.map +1 -0
  111. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityChangeEventListener.d.ts +20 -0
  112. package/lib/esm/tree-widget-react/components/trees/{models-tree → common}/internal/VisibilityChangeEventListener.js +17 -9
  113. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityChangeEventListener.js.map +1 -0
  114. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.d.ts +82 -0
  115. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js +234 -0
  116. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js.map +1 -0
  117. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +7 -2
  118. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +24 -18
  119. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  120. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeComponent.d.ts +1 -1
  121. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  122. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.d.ts +1 -0
  123. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +1 -0
  124. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
  125. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +9 -2
  126. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +44 -34
  127. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  128. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +1 -1
  129. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  130. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +13 -0
  131. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +39 -38
  132. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
  133. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.d.ts +5 -5
  134. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js +25 -24
  135. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js.map +1 -1
  136. package/lib/esm/tree-widget-react/components/trees/index.d.ts +4 -2
  137. package/lib/esm/tree-widget-react/components/trees/index.js +4 -2
  138. package/lib/esm/tree-widget-react/components/trees/index.js.map +1 -1
  139. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.d.ts +2 -2
  140. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js +2 -2
  141. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js.map +1 -1
  142. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +15 -11
  143. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  144. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.d.ts +1 -1
  145. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js +1 -1
  146. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  147. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +7 -2
  148. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +73 -70
  149. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
  150. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.d.ts +5 -1
  151. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +73 -49
  152. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
  153. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.d.ts +7 -9
  154. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +4 -6
  155. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
  156. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +4 -5
  157. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +54 -104
  158. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  159. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +0 -26
  160. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +75 -291
  161. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  162. package/lib/public/locales/en/TreeWidget.json +55 -6
  163. package/package.json +17 -18
  164. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +0 -37
  165. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +0 -214
  166. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +0 -1
  167. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +0 -7
  168. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +0 -1
  169. package/lib/esm/tree-widget-react/components/trees/common/Rxjs.js.map +0 -1
  170. package/lib/esm/tree-widget-react/components/trees/common/Tooltip.js.map +0 -1
  171. package/lib/esm/tree-widget-react/components/trees/common/UseActiveViewport.js.map +0 -1
  172. package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.d.ts +0 -11
  173. package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.js +0 -24
  174. package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.js.map +0 -1
  175. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchiesLocalization.js.map +0 -1
  176. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyFiltering.js.map +0 -1
  177. package/lib/esm/tree-widget-react/components/trees/common/UseIModelChangeListener.js.map +0 -1
  178. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.d.ts +0 -7
  179. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js +0 -21
  180. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js.map +0 -1
  181. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.d.ts +0 -29
  182. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +0 -1
  183. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/VisibilityChangeEventListener.d.ts +0 -12
  184. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/VisibilityChangeEventListener.js.map +0 -1
  185. /package/lib/esm/tree-widget-react/components/trees/common/{UseActiveViewport.d.ts → internal/UseActiveViewport.d.ts} +0 -0
  186. /package/lib/esm/tree-widget-react/components/trees/common/{UseActiveViewport.js → internal/UseActiveViewport.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"CategoriesVisibilityUtils.js","sourceR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,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACnC,SAAS;SACV;QACD,iJAAiJ;QACjJ,IAAI,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,EAAE;YAC/F,KAAK,MAAM,WAAW,IAAI,QAAQ,CAAC,cAAc,EAAE;gBACjD,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aAC/H;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACnC;KACF;IAED,kBAAkB;IAClB,oBAAoB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAE5D,kBAAkB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9D,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 { QueryRowFormat } from \"@itwin/core-common\";\nimport { PerModelCategoryVisibility } from \"@itwin/core-frontend\";\n\nimport type { Viewport } from \"@itwin/core-frontend\";\n\n/**\n * Data structure that describes category.\n * @beta\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Toggles visibility of categories to show or hide.\n */\nexport async function toggleAllCategories(viewport: Viewport, display: boolean) {\n const ids = await getCategories(viewport);\n if (ids.length === 0) {\n return;\n }\n\n await enableCategoryDisplay(viewport, ids, display);\n}\n\n/**\n * Gets ids of all categories from specified imodel and viewport.\n */\nasync function getCategories(viewport: Viewport) {\n const categories = await loadCategoriesFromViewport(viewport);\n return categories.map((category) => category.categoryId);\n}\n\n/**\n * Changes category display in the viewport.\n */\nexport async function enableCategoryDisplay(viewport: Viewport, ids: string[], enabled: boolean, enableAllSubCategories = true) {\n viewport.changeCategoryDisplay(ids, enabled, enableAllSubCategories);\n\n // remove category overrides per model\n const modelsContainingOverrides: string[] = [];\n for (const ovr of viewport.perModelCategoryVisibility) {\n if (ids.findIndex((id) => id === ovr.categoryId) !== -1) {\n modelsContainingOverrides.push(ovr.modelId);\n }\n }\n viewport.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, PerModelCategoryVisibility.Override.None);\n\n // changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.\n if (false === enabled) {\n (await viewport.iModel.categories.getCategoryInfo(ids)).forEach((categoryInfo) => {\n categoryInfo.subCategories.forEach((value) => enableSubCategoryDisplay(viewport, value.id, false));\n });\n }\n}\n\n/**\n * Changes subcategory display in the viewport\n */\nexport function enableSubCategoryDisplay(viewport: Viewport, key: string, enabled: boolean) {\n viewport.changeSubCategoryDisplay(key, enabled);\n}\n\nexport async function loadCategoriesFromViewport(vp: Viewport) {\n // Query categories and add them to state\n const selectUsedSpatialCategoryIds =\n \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)\";\n const selectUsedDrawingCategoryIds =\n \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)\";\n const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;\n const ecsql2 = `SELECT ECInstanceId as id FROM ${vp.view.is3d() ? \"BisCore.SpatialCategory\" : \"BisCore.DrawingCategory\"} WHERE ECInstanceId IN (${ecsql})`;\n\n const categories: CategoryInfo[] = [];\n\n const rows = await vp.iModel.createQueryReader(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames }).toArray();\n (await vp.iModel.categories.getCategoryInfo(rows.map((row) => row.id))).forEach((val) => {\n categories.push({ categoryId: val.id, subCategoryIds: val.subCategories.size ? [...val.subCategories.keys()] : undefined });\n });\n return categories;\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, false));\n\n await enableCategoryDisplay(viewport, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, true));\n\n await enableCategoryDisplay(viewport, disabled, true, true);\n}\n"]}
1
+ {"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAchG;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAqB,EAAE,QAAkB;IAC/E,MAAM,qBAAqB,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAqB,EAAE,QAAkB;IAC/E,MAAM,qBAAqB,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,UAA0B,EAAE,QAAkB;IACtF,MAAM,OAAO,GAAG,IAAI,KAAK,EAAc,CAAC;IACxC,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAc,CAAC;IACzC,MAAM,oBAAoB,GAAG,IAAI,KAAK,EAAc,CAAC;IACrD,MAAM,qBAAqB,GAAG,IAAI,KAAK,EAAc,CAAC;IAEtD,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;QACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;YACrD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACnC,SAAS;SACV;QACD,iJAAiJ;QACjJ,IAAI,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,EAAE;YAC/F,KAAK,MAAM,WAAW,IAAI,QAAQ,CAAC,cAAc,EAAE;gBACjD,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aAC/H;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACnC;KACF;IAED,kBAAkB;IAClB,oBAAoB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAE5D,kBAAkB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9D,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 { enableCategoryDisplay, enableSubCategoryDisplay } from \"./internal/VisibilityUtils.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { Viewport } from \"@itwin/core-frontend\";\n\n/**\n * Data structure that describes category.\n * @beta\n */\nexport interface CategoryInfo {\n categoryId: Id64String;\n subCategoryIds?: Id64Array;\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: Id64Array, viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: Id64Array, viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled = new Array<Id64String>();\n const disabled = new Array<Id64String>();\n const enabledSubCategories = new Array<Id64String>();\n const disabledSubCategories = new Array<Id64String>();\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, false));\n\n await enableCategoryDisplay(viewport, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, true));\n\n await enableCategoryDisplay(viewport, disabled, true, true);\n}\n"]}
@@ -29,6 +29,7 @@ export interface HierarchyVisibilityHandler extends IDisposable {
29
29
  interface UseHierarchyVisibilityProps {
30
30
  visibilityHandlerFactory: () => HierarchyVisibilityHandler;
31
31
  }
32
+ /** @internal */
32
33
  export declare function useHierarchyVisibility({ visibilityHandlerFactory, }: UseHierarchyVisibilityProps): TreeItemVisibilityButtonProps & {
33
34
  triggerRefresh: () => void;
34
35
  };
@@ -50,6 +51,7 @@ export type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc exte
50
51
  * @beta
51
52
  */
52
53
  export type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult : never;
54
+ /** @internal */
53
55
  export declare function createVisibilityHandlerResult<TResult, TOverrideProps>(handler: HierarchyVisibilityHandler, props: TOverrideProps, obs: Observable<TResult>, override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined): Observable<TResult>;
54
56
  export {};
55
57
  //# sourceMappingURL=UseHierarchyVisibility.d.ts.map
@@ -5,10 +5,11 @@
5
5
  import { useEffect, useRef, useState } from "react";
6
6
  import { asyncScheduler, defer, distinct, EMPTY, from, lastValueFrom, mergeMap, observeOn, onErrorResumeNextWith, Subject, takeUntil, tap, throttleTime, } from "rxjs";
7
7
  import { useTelemetryContext } from "./UseTelemetryContext.js";
8
+ /** @internal */
8
9
  export function useHierarchyVisibility({ visibilityHandlerFactory, }) {
9
10
  const visibilityStatusMap = useRef(new Map());
10
11
  const [state, setState] = useState({
11
- getVisibilityButtonState: () => ({ state: "hidden", isDisabled: true }),
12
+ getVisibilityButtonState: () => ({ state: "visible", isDisabled: true }),
12
13
  onVisibilityButtonClick: () => { },
13
14
  triggerRefresh: () => { },
14
15
  });
@@ -86,7 +87,7 @@ function createStateGetter(map, calculateVisibility) {
86
87
  const entry = map.current.get(node.id);
87
88
  if (entry === undefined) {
88
89
  calculateVisibility(node);
89
- return { state: "hidden", isDisabled: true };
90
+ return { state: "visible", isDisabled: true };
90
91
  }
91
92
  if (entry.needsRefresh) {
92
93
  calculateVisibility(node);
@@ -99,6 +100,7 @@ function createStateGetter(map, calculateVisibility) {
99
100
  };
100
101
  };
101
102
  }
103
+ /** @internal */
102
104
  export function createVisibilityHandlerResult(handler, props, obs, override) {
103
105
  return override
104
106
  ? from(override({
@@ -1 +1 @@
1
- {"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,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C,IAAI,CAAC,EAAE,CAAC,CAAC;QACvC,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,mBAAmB,CAAC,IAAI,CAAC,CAAC;YAC1B,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;SAC9C;QACD,IAAI,KAAK,CAAC,YAAY,EAAE;YACtB,mBAAmB,CAAC,IAAI,CAAC,CAAC;SAC3B;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA0BD,MAAM,UAAU,6BAA6B,CAC3C,OAAmC,EACnC,KAAqB,EACrB,GAAwB,EACxB,QAA8G;IAE9G,OAAO,QAAQ;QACb,CAAC,CAAC,IAAI,CACF,QAAQ,CAAC;YACP,GAAG,KAAK;YACR,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,SAAoB,EAAE,CAAC;YAC9F,OAAO;SACR,CAAC,CACH;QACH,CAAC,CAAC,GAAG,CAAC;AACV,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, useState } from \"react\";\nimport {\n asyncScheduler,\n defer,\n distinct,\n EMPTY,\n from,\n lastValueFrom,\n mergeMap,\n observeOn,\n onErrorResumeNextWith,\n Subject,\n takeUntil,\n tap,\n throttleTime,\n} from \"rxjs\";\nimport { useTelemetryContext } from \"./UseTelemetryContext.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeItemVisibilityButtonProps } from \"./components/TreeNodeVisibilityButton.js\";\n\n/**\n * Data structure that describes instance visibility status.\n * @beta\n */\nexport interface VisibilityStatus {\n /** Instance visibility state. */\n state: \"visible\" | \"partial\" | \"hidden\";\n /** Specifies whether visibility changing is disabled or not. */\n isDisabled?: boolean;\n /** Tooltip that should be displayed when hovering over the visibility checkbox. */\n tooltip?: string;\n}\n\n/**\n * Handler that can be used to determine and change visibility of instances represented by tree nodes.\n * @beta\n */\nexport interface HierarchyVisibilityHandler extends IDisposable {\n /** Event used to notify tree about visibility changes from outside. */\n readonly onVisibilityChange: BeEvent<() => void>;\n /** Returns current visibility status for tree node. */\n getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;\n /** Changes visibility of the instance represented by tree node. */\n changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;\n}\n\ninterface UseHierarchyVisibilityProps {\n visibilityHandlerFactory: () => HierarchyVisibilityHandler;\n}\n\nexport function useHierarchyVisibility({\n visibilityHandlerFactory,\n}: UseHierarchyVisibilityProps): TreeItemVisibilityButtonProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeItemVisibilityButtonProps & { triggerRefresh: () => void }>({\n getVisibilityButtonState: () => ({ state: \"hidden\", isDisabled: true }),\n onVisibilityButtonClick: () => {},\n triggerRefresh: () => {},\n });\n const { onFeatureUsed } = useTelemetryContext();\n\n useEffect(() => {\n visibilityStatusMap.current.clear();\n const handler = visibilityHandlerFactory();\n\n const visibilityChanged = new Subject<void>();\n const calculate = new Subject<PresentationHierarchyNode>();\n const calculateNodeStatus = (node: PresentationHierarchyNode) => {\n calculate.next(node);\n };\n\n const resetCache = () => {\n visibilityStatusMap.current.forEach((value) => {\n value.needsRefresh = true;\n });\n visibilityChanged.next();\n };\n\n const triggerCheckboxUpdate = () => {\n setState((prev) => ({\n ...prev,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n }));\n };\n\n const subscription = calculate\n .pipe(\n distinct(undefined, visibilityChanged),\n observeOn(asyncScheduler),\n mergeMap((node) =>\n defer(async () => handler.getVisibilityStatus(node.nodeData)).pipe(\n tap({\n next: (status) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status,\n needsRefresh: false,\n });\n },\n }),\n takeUntil(visibilityChanged),\n onErrorResumeNextWith(EMPTY),\n ),\n ),\n throttleTime(100, undefined, { leading: false, trailing: true }),\n )\n .subscribe({\n next: () => {\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility: TreeItemVisibilityButtonProps[\"onVisibilityButtonClick\"] = (node, visibilityState) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n // visible should become hidden, partial and hidden should become visible TODO: redo for clarity\n const on = visibilityState === \"visible\" ? false : true;\n void handler.changeVisibility(node.nodeData, on);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = visibilityState;\n entry.status.tooltip = undefined;\n triggerCheckboxUpdate();\n };\n\n setState({\n onVisibilityButtonClick: changeVisibility,\n getVisibilityButtonState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n triggerRefresh: () => {\n resetCache();\n triggerCheckboxUpdate();\n },\n });\n\n const removeListener = handler.onVisibilityChange.addListener(() => {\n resetCache();\n triggerCheckboxUpdate();\n });\n\n return () => {\n subscription.unsubscribe();\n removeListener();\n handler.dispose();\n };\n }, [visibilityHandlerFactory, onFeatureUsed]);\n\n return state;\n}\n\nfunction createStateGetter(\n map: MutableRefObject<Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>>,\n calculateVisibility: (node: PresentationHierarchyNode) => void,\n): TreeItemVisibilityButtonProps[\"getVisibilityButtonState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"hidden\", isDisabled: true };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state,\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n\n/**\n * Properties for an overridden method of a `HierarchyVisibilityHandler` implementation.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc extends (props: infer TProps) => infer TResult\n ? TProps & {\n /** A callback that produces the value from the original implementation. */\n readonly originalImplementation: () => TResult;\n /**\n * Reference to the hierarchy based handler.\n * @note Calling `getVisibility` or `changeVisibility` of this object invokes the overridden implementation as well.\n */\n readonly handler: HierarchyVisibilityHandler;\n }\n : never;\n\n/**\n * Function type for an overridden method of `HierarchyVisibilityHandler`.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult\n ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult\n : never;\n\nexport function createVisibilityHandlerResult<TResult, TOverrideProps>(\n handler: HierarchyVisibilityHandler,\n props: TOverrideProps,\n obs: Observable<TResult>,\n override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined,\n): Observable<TResult> {\n return override\n ? from(\n override({\n ...props,\n originalImplementation: async () => lastValueFrom(obs, { defaultValue: undefined as TResult }),\n handler,\n }),\n )\n : obs;\n}\n"]}
1
+ {"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,cAAc,EACd,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,qBAAqB,EACrB,OAA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,UAAU,EAAE,IAAI,EAAE,CAAC;SAC/C;QACD,IAAI,KAAK,CAAC,YAAY,EAAE;YACtB,mBAAmB,CAAC,IAAI,CAAC,CAAC;SAC3B;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA0BD,gBAAgB;AAChB,MAAM,UAAU,6BAA6B,CAC3C,OAAmC,EACnC,KAAqB,EACrB,GAAwB,EACxB,QAA8G;IAE9G,OAAO,QAAQ;QACb,CAAC,CAAC,IAAI,CACF,QAAQ,CAAC;YACP,GAAG,KAAK;YACR,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,SAAoB,EAAE,CAAC;YAC9F,OAAO;SACR,CAAC,CACH;QACH,CAAC,CAAC,GAAG,CAAC;AACV,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, useState } from \"react\";\nimport {\n asyncScheduler,\n defer,\n distinct,\n EMPTY,\n from,\n lastValueFrom,\n mergeMap,\n observeOn,\n onErrorResumeNextWith,\n Subject,\n takeUntil,\n tap,\n throttleTime,\n} from \"rxjs\";\nimport { useTelemetryContext } from \"./UseTelemetryContext.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeItemVisibilityButtonProps } from \"./components/TreeNodeVisibilityButton.js\";\n\n/**\n * Data structure that describes instance visibility status.\n * @beta\n */\nexport interface VisibilityStatus {\n /** Instance visibility state. */\n state: \"visible\" | \"partial\" | \"hidden\";\n /** Specifies whether visibility changing is disabled or not. */\n isDisabled?: boolean;\n /** Tooltip that should be displayed when hovering over the visibility checkbox. */\n tooltip?: string;\n}\n\n/**\n * Handler that can be used to determine and change visibility of instances represented by tree nodes.\n * @beta\n */\nexport interface HierarchyVisibilityHandler extends IDisposable {\n /** Event used to notify tree about visibility changes from outside. */\n readonly onVisibilityChange: BeEvent<() => void>;\n /** Returns current visibility status for tree node. */\n getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;\n /** Changes visibility of the instance represented by tree node. */\n changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;\n}\n\ninterface UseHierarchyVisibilityProps {\n visibilityHandlerFactory: () => HierarchyVisibilityHandler;\n}\n\n/** @internal */\nexport function useHierarchyVisibility({\n visibilityHandlerFactory,\n}: UseHierarchyVisibilityProps): TreeItemVisibilityButtonProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeItemVisibilityButtonProps & { triggerRefresh: () => void }>({\n getVisibilityButtonState: () => ({ state: \"visible\", isDisabled: true }),\n onVisibilityButtonClick: () => {},\n triggerRefresh: () => {},\n });\n const { onFeatureUsed } = useTelemetryContext();\n\n useEffect(() => {\n visibilityStatusMap.current.clear();\n const handler = visibilityHandlerFactory();\n\n const visibilityChanged = new Subject<void>();\n const calculate = new Subject<PresentationHierarchyNode>();\n const calculateNodeStatus = (node: PresentationHierarchyNode) => {\n calculate.next(node);\n };\n\n const resetCache = () => {\n visibilityStatusMap.current.forEach((value) => {\n value.needsRefresh = true;\n });\n visibilityChanged.next();\n };\n\n const triggerCheckboxUpdate = () => {\n setState((prev) => ({\n ...prev,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n }));\n };\n\n const subscription = calculate\n .pipe(\n distinct(undefined, visibilityChanged),\n observeOn(asyncScheduler),\n mergeMap((node) =>\n defer(async () => handler.getVisibilityStatus(node.nodeData)).pipe(\n tap({\n next: (status) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status,\n needsRefresh: false,\n });\n },\n }),\n takeUntil(visibilityChanged),\n onErrorResumeNextWith(EMPTY),\n ),\n ),\n throttleTime(100, undefined, { leading: false, trailing: true }),\n )\n .subscribe({\n next: () => {\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility: TreeItemVisibilityButtonProps[\"onVisibilityButtonClick\"] = (node, visibilityState) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n // visible should become hidden, partial and hidden should become visible TODO: redo for clarity\n const on = visibilityState === \"visible\" ? false : true;\n void handler.changeVisibility(node.nodeData, on);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = visibilityState;\n entry.status.tooltip = undefined;\n triggerCheckboxUpdate();\n };\n\n setState({\n onVisibilityButtonClick: changeVisibility,\n getVisibilityButtonState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n triggerRefresh: () => {\n resetCache();\n triggerCheckboxUpdate();\n },\n });\n\n const removeListener = handler.onVisibilityChange.addListener(() => {\n resetCache();\n triggerCheckboxUpdate();\n });\n\n return () => {\n subscription.unsubscribe();\n removeListener();\n handler.dispose();\n };\n }, [visibilityHandlerFactory, onFeatureUsed]);\n\n return state;\n}\n\nfunction createStateGetter(\n map: MutableRefObject<Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>>,\n calculateVisibility: (node: PresentationHierarchyNode) => void,\n): TreeItemVisibilityButtonProps[\"getVisibilityButtonState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"visible\", isDisabled: true };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state,\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n\n/**\n * Properties for an overridden method of a `HierarchyVisibilityHandler` implementation.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc extends (props: infer TProps) => infer TResult\n ? TProps & {\n /** A callback that produces the value from the original implementation. */\n readonly originalImplementation: () => TResult;\n /**\n * Reference to the hierarchy based handler.\n * @note Calling `getVisibility` or `changeVisibility` of this object invokes the overridden implementation as well.\n */\n readonly handler: HierarchyVisibilityHandler;\n }\n : never;\n\n/**\n * Function type for an overridden method of `HierarchyVisibilityHandler`.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult\n ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult\n : never;\n\n/** @internal */\nexport function createVisibilityHandlerResult<TResult, TOverrideProps>(\n handler: HierarchyVisibilityHandler,\n props: TOverrideProps,\n obs: Observable<TResult>,\n override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined,\n): Observable<TResult> {\n return override\n ? from(\n override({\n ...props,\n originalImplementation: async () => lastValueFrom(obs, { defaultValue: undefined as TResult }),\n handler,\n }),\n )\n : obs;\n}\n"]}
@@ -15,6 +15,7 @@ interface UseNodeHighlightingResult {
15
15
  activeNodeId?: string;
16
16
  getLabel: (node: PresentationHierarchyNode) => React.ReactElement;
17
17
  }
18
+ /** @internal */
18
19
  export declare function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult;
19
20
  export {};
20
21
  //# sourceMappingURL=UseNodeHighlighting.d.ts.map
@@ -5,7 +5,8 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  import { useCallback, useEffect, useRef, useState } from "react";
7
7
  import { isPresentationHierarchyNode } from "@itwin/presentation-hierarchies-react";
8
- import { useLatest } from "./Utils.js";
8
+ import { useLatest } from "./internal/Utils.js";
9
+ /** @internal */
9
10
  export function useNodeHighlighting({ rootNodes, highlight }) {
10
11
  const state = useRef({ nodeInfoMap: new Map(), totalMatches: 0 });
11
12
  const [activeNodeId, setActiveNodeId] = useState();
@@ -1 +1 @@
1
- {"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseNodeHighlighting.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA2CvC,MAAM,UAAU,mBAAmB,CAAC,EAAE,SAAS,EAAE,SAAS,EAA4B;IACpF,MAAM,KAAK,GAAG,MAAM,CAAiB,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC;IAClF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,EAAsB,CAAC;IACvE,MAAM,mBAAmB,GAAG,SAAS,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IACnE,MAAM,eAAe,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IAChD,MAAM,qBAAqB,GAAG,SAAS,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,SAAS,EAAE,IAAI,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,GACpC,SAAS,IAAI,UAAU;YACrB,CAAC,CAAC,qBAAqB,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC;YACnH,CAAC,CAA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,yBAA2B,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;QACtC,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;YACvF,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAC/B,SAAS;SACV;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;KAC7B;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/UseNodeHighlighting.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AA2ChD,gBAAgB;AAChB,MAAM,UAAU,mBAAmB,CAAC,EAAE,SAAS,EAAE,SAAS,EAA4B;IACpF,MAAM,KAAK,GAAG,MAAM,CAAiB,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC;IAClF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,EAAsB,CAAC;IACvE,MAAM,mBAAmB,GAAG,SAAS,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IACnE,MAAM,eAAe,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IAChD,MAAM,qBAAqB,GAAG,SAAS,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,SAAS,EAAE,IAAI,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,GACpC,SAAS,IAAI,UAAU;YACrB,CAAC,CAAC,qBAAqB,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC;YACnH,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,E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AED,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;QACtC,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;YACvF,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAC/B,SAAS;SACV;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;KAC7B;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 \"./internal/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\n/** @internal */\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"]}
@@ -18,6 +18,7 @@ export interface TelemetryContextProviderProps {
18
18
  }
19
19
  /** @beta */
20
20
  export declare function TelemetryContextProvider({ children, onPerformanceMeasured, onFeatureUsed, componentIdentifier, }: PropsWithChildren<TelemetryContextProviderProps>): import("react/jsx-runtime").JSX.Element;
21
+ /** @internal */
21
22
  export declare function useTelemetryContext(): TelemetryContext;
22
23
  interface UseReportingActionProps<TAction> {
23
24
  action: TAction;
@@ -4,7 +4,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  import { createContext, useCallback, useContext, useMemo } from "react";
7
- import { useLatest } from "./Utils.js";
7
+ import { useLatest } from "./internal/Utils.js";
8
8
  const telemetryContext = createContext(undefined);
9
9
  /** @beta */
10
10
  export function TelemetryContextProvider({ children, onPerformanceMeasured, onFeatureUsed, componentIdentifier, }) {
@@ -29,6 +29,7 @@ const defaultContextValue = {
29
29
  onPerformanceMeasured: () => { },
30
30
  onFeatureUsed: () => { },
31
31
  };
32
+ /** @internal */
32
33
  export function useTelemetryContext() {
33
34
  return useContext(telemetryContext) ?? defaultContextValue;
34
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"UseTelemetryContext.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseTelemetryContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAkBvC,MAAM,gBAAgB,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAYhF,YAAY;AACZ,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,EACR,qBAAqB,EACrB,aAAa,EACb,mBAAmB,GAC8B;IACjD,MAAM,wBAAwB,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAClE,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,IAAI,EAAE,CAAC,CAAC;QACtD,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAClB,CAAC,EACD,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,CACnC,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 { createContext, useCallback, useContext, useMemo } from \"react\";\nimport { useLatest } from \"./Utils.js\";\n\nimport type { PropsWithChildren } from \"react\";\n\ntype TrackedFeatures =\n | \"visibility-change\"\n | \"hierarchy-level-filtering\"\n | \"filtering\"\n | \"hierarchy-level-size-limit-hit\"\n | \"zoom-to-node\"\n | \"error-timeout\"\n | \"error-unknown\";\n\ninterface TelemetryContext {\n onPerformanceMeasured: (featureId: string, duration: number) => void;\n onFeatureUsed: (props: { featureId?: TrackedFeatures; reportInteraction: boolean }) => void;\n}\n\nconst telemetryContext = createContext<TelemetryContext | undefined>(undefined);\n\n/** @beta */\nexport interface TelemetryContextProviderProps {\n /** Callback that is invoked when performance of tracked feature is measured. */\n onPerformanceMeasured?: (featureId: string, duration: number) => void;\n /** Callback that is invoked when a tracked feature is used. */\n onFeatureUsed?: (featureId: string) => void;\n /** Unique identifier that is appended to feature id to help track which component used that feature. */\n componentIdentifier: string;\n}\n\n/** @beta */\nexport function TelemetryContextProvider({\n children,\n onPerformanceMeasured,\n onFeatureUsed,\n componentIdentifier,\n}: PropsWithChildren<TelemetryContextProviderProps>) {\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onFeatureUsedRef = useLatest(onFeatureUsed);\n\n const contextValue = useMemo<TelemetryContext>(() => {\n return {\n onPerformanceMeasured: (featureId, duration) => onPerformanceMeasuredRef.current?.(`${componentIdentifier}-${featureId}`, duration),\n onFeatureUsed: ({ featureId, reportInteraction }) => {\n if (reportInteraction !== false) {\n onFeatureUsedRef.current?.(`use-${componentIdentifier}`);\n }\n if (featureId) {\n onFeatureUsedRef.current?.(`${componentIdentifier}-${featureId}`);\n }\n },\n };\n }, [componentIdentifier, onPerformanceMeasuredRef, onFeatureUsedRef]);\n\n return <telemetryContext.Provider value={contextValue}>{children}</telemetryContext.Provider>;\n}\n\nconst defaultContextValue: TelemetryContext = {\n onPerformanceMeasured: () => {},\n onFeatureUsed: () => {},\n};\n\nexport function useTelemetryContext() {\n return useContext(telemetryContext) ?? defaultContextValue;\n}\n\ninterface UseReportingActionProps<TAction> {\n action: TAction;\n featureId?: TrackedFeatures;\n}\n\n/** @internal */\nexport function useReportingAction<TAction extends (...args: any[]) => void>({ action, featureId }: UseReportingActionProps<TAction>) {\n const { onFeatureUsed } = useTelemetryContext();\n return useCallback<(...args: Parameters<TAction>) => void>(\n (...args) => {\n onFeatureUsed({ featureId, reportInteraction: true });\n action(...args);\n },\n [action, featureId, onFeatureUsed],\n );\n}\n"]}
1
+ {"version":3,"file":"UseTelemetryContext.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseTelemetryContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAkBhD,MAAM,gBAAgB,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAYhF,YAAY;AACZ,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,EACR,qBAAqB,EACrB,aAAa,EACb,mBAAmB,GAC8B;IACjD,MAAM,wBAAwB,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAClE,MAAM,gBAAgB,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IAElD,MAAM,YAAY,GAAG,OAAO,CAAmB,GAAG,EAAE;QAClD,OAAO;YACL,qBAAqB,EAAE,CAAC,SAAS,EAAE,QAAQ,E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,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { createContext, useCallback, useContext, useMemo } from \"react\";\nimport { useLatest } from \"./internal/Utils.js\";\n\nimport type { PropsWithChildren } from \"react\";\n\ntype TrackedFeatures =\n | \"visibility-change\"\n | \"hierarchy-level-filtering\"\n | \"filtering\"\n | \"hierarchy-level-size-limit-hit\"\n | \"zoom-to-node\"\n | \"error-timeout\"\n | \"error-unknown\";\n\ninterface TelemetryContext {\n onPerformanceMeasured: (featureId: string, duration: number) => void;\n onFeatureUsed: (props: { featureId?: TrackedFeatures; reportInteraction: boolean }) => void;\n}\n\nconst telemetryContext = createContext<TelemetryContext | undefined>(undefined);\n\n/** @beta */\nexport interface TelemetryContextProviderProps {\n /** Callback that is invoked when performance of tracked feature is measured. */\n onPerformanceMeasured?: (featureId: string, duration: number) => void;\n /** Callback that is invoked when a tracked feature is used. */\n onFeatureUsed?: (featureId: string) => void;\n /** Unique identifier that is appended to feature id to help track which component used that feature. */\n componentIdentifier: string;\n}\n\n/** @beta */\nexport function TelemetryContextProvider({\n children,\n onPerformanceMeasured,\n onFeatureUsed,\n componentIdentifier,\n}: PropsWithChildren<TelemetryContextProviderProps>) {\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onFeatureUsedRef = useLatest(onFeatureUsed);\n\n const contextValue = useMemo<TelemetryContext>(() => {\n return {\n onPerformanceMeasured: (featureId, duration) => onPerformanceMeasuredRef.current?.(`${componentIdentifier}-${featureId}`, duration),\n onFeatureUsed: ({ featureId, reportInteraction }) => {\n if (reportInteraction !== false) {\n onFeatureUsedRef.current?.(`use-${componentIdentifier}`);\n }\n if (featureId) {\n onFeatureUsedRef.current?.(`${componentIdentifier}-${featureId}`);\n }\n },\n };\n }, [componentIdentifier, onPerformanceMeasuredRef, onFeatureUsedRef]);\n\n return <telemetryContext.Provider value={contextValue}>{children}</telemetryContext.Provider>;\n}\n\nconst defaultContextValue: TelemetryContext = {\n onPerformanceMeasured: () => {},\n onFeatureUsed: () => {},\n};\n\n/** @internal */\nexport function useTelemetryContext() {\n return useContext(telemetryContext) ?? defaultContextValue;\n}\n\ninterface UseReportingActionProps<TAction> {\n action: TAction;\n featureId?: TrackedFeatures;\n}\n\n/** @internal */\nexport function useReportingAction<TAction extends (...args: any[]) => void>({ action, featureId }: UseReportingActionProps<TAction>) {\n const { onFeatureUsed } = useTelemetryContext();\n return useCallback<(...args: Parameters<TAction>) => void>(\n (...args) => {\n onFeatureUsed({ featureId, reportInteraction: true });\n action(...args);\n },\n [action, featureId, onFeatureUsed],\n );\n}\n"]}
@@ -1,27 +1,37 @@
1
- /// <reference types="react" />
1
+ import type { Viewport } from "@itwin/core-frontend";
2
2
  import type { Id64Array } from "@itwin/core-bentley";
3
- import type { IModelConnection } from "@itwin/core-frontend";
4
- import type { SchemaContext } from "@itwin/ecschema-metadata";
5
3
  /** @beta */
6
4
  export type FunctionProps<THook extends (props: any) => any> = Parameters<THook>[0];
7
- /** @internal */
8
- export declare function createIdsSelector(ids: Id64Array): string;
9
- /** @internal */
10
- export declare function parseIdsSelectorResult(selectorResult: any): Id64Array;
11
- /** @internal */
12
- export declare function pushToMap<TKey, TValue>(targetMap: Map<TKey, Set<TValue>>, key: TKey, value: TValue): void;
13
- /** @internal */
14
- export declare function createIModelAccess({ imodel, getSchemaContext }: {
15
- imodel: IModelConnection;
16
- getSchemaContext: (imodel: IModelConnection) => SchemaContext;
17
- }): {
18
- createQueryReader(query: import("@itwin/presentation-shared").ECSqlQueryDef, config?: (import("@itwin/presentation-shared").ECSqlQueryReaderOptions & {
19
- limit?: number | "unbounded" | undefined;
20
- }) | undefined): AsyncIterableIterator<import("@itwin/presentation-shared").ECSqlQueryRow>;
21
- classDerivesFrom(derivedClassFullName: string, candidateBaseClassFullName: string): boolean | Promise<boolean>;
22
- getSchema(schemaName: string): Promise<import("@itwin/presentation-shared").EC.Schema | undefined>;
23
- imodelKey: string;
24
- };
25
- /** @internal */
26
- export declare function useLatest<T>(value: T): import("react").MutableRefObject<T>;
5
+ /**
6
+ * Disables display of all given models.
7
+ * @public
8
+ */
9
+ export declare function hideAllModels(models: string[], viewport: Viewport): Promise<void>;
10
+ /**
11
+ * Enables display of all given models. Also enables display of all categories and clears always and
12
+ * never drawn lists in the viewport.
13
+ * @public
14
+ */
15
+ export declare function showAll(props: {
16
+ /** ID's of models to enable */
17
+ models: Id64Array;
18
+ /** ID's of categories to enable, if set to undefined, all categories will be enabled */
19
+ categories?: Id64Array;
20
+ viewport: Viewport;
21
+ }): Promise<void>;
22
+ /**
23
+ * Inverts display of all given models.
24
+ * @public
25
+ */
26
+ export declare function invertAllModels(models: Id64Array, viewport: Viewport): Promise<void>;
27
+ /**
28
+ * Based on the value of `enable` argument, either enables or disables display of given models.
29
+ * @public
30
+ */
31
+ export declare function toggleModels(models: string[], enable: boolean, viewport: Viewport): Promise<void>;
32
+ /**
33
+ * Checks if all given models are displayed in given viewport.
34
+ * @public
35
+ */
36
+ export declare function areAllModelsVisible(models: string[], viewport: Viewport): boolean;
27
37
  //# sourceMappingURL=Utils.d.ts.map
@@ -2,57 +2,70 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { useEffect, useRef } from "react";
6
- import { createECSchemaProvider, createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
7
- import { createLimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
8
- import { createCachingECClassHierarchyInspector } from "@itwin/presentation-shared";
9
- /** @internal */
10
- export function createIdsSelector(ids) {
11
- // Note: `json_array` function only accepts up to 127 arguments and we may have more `ids` than that. As a workaround,
12
- // we're creating an array of arrays
13
- const slices = new Array();
14
- for (let sliceStartIndex = 0; sliceStartIndex < ids.length; sliceStartIndex += 127) {
15
- let sliceEndIndex = sliceStartIndex + 127;
16
- if (sliceEndIndex > ids.length) {
17
- sliceEndIndex = undefined;
18
- }
19
- slices.push(ids.slice(sliceStartIndex, sliceEndIndex));
20
- }
21
- return `json_array(${slices.map((sliceIds) => `json_array(${sliceIds.map((id) => `'${id}'`).join(",")})`).join(",")})`;
5
+ import { showAllCategories } from "./CategoriesVisibilityUtils.js";
6
+ import { toggleAllCategories } from "./internal/VisibilityUtils.js";
7
+ /**
8
+ * Disables display of all given models.
9
+ * @public
10
+ */
11
+ export async function hideAllModels(models, viewport) {
12
+ viewport.changeModelDisplay(models, false);
22
13
  }
23
- /** @internal */
24
- export function parseIdsSelectorResult(selectorResult) {
25
- if (!Array.isArray(selectorResult)) {
26
- return [];
14
+ /**
15
+ * Enables display of all given models. Also enables display of all categories and clears always and
16
+ * never drawn lists in the viewport.
17
+ * @public
18
+ */
19
+ export async function showAll(props) {
20
+ const { models, categories, viewport } = props;
21
+ await viewport.addViewedModels(models);
22
+ viewport.clearNeverDrawn();
23
+ viewport.clearAlwaysDrawn();
24
+ if (categories) {
25
+ await showAllCategories(categories, viewport);
27
26
  }
28
- return selectorResult.reduce((arr, ids) => [...arr, ...(Array.isArray(ids) ? ids : [ids])], new Array());
29
- }
30
- /** @internal */
31
- export function pushToMap(targetMap, key, value) {
32
- let set = targetMap.get(key);
33
- if (!set) {
34
- set = new Set();
35
- targetMap.set(key, set);
27
+ else {
28
+ await toggleAllCategories(viewport, true);
36
29
  }
37
- set.add(value);
38
30
  }
39
- /** @internal */
40
- export function createIModelAccess({ imodel, getSchemaContext }) {
41
- const schemas = getSchemaContext(imodel);
42
- const schemaProvider = createECSchemaProvider(schemas);
43
- return {
44
- imodelKey: imodel.key,
45
- ...schemaProvider,
46
- ...createCachingECClassHierarchyInspector({ schemaProvider, cacheSize: 100 }),
47
- ...createLimitingECSqlQueryExecutor(createECSqlQueryExecutor(imodel), 1000),
48
- };
31
+ /**
32
+ * Inverts display of all given models.
33
+ * @public
34
+ */
35
+ export async function invertAllModels(models, viewport) {
36
+ const notViewedModels = new Array();
37
+ const viewedModels = new Array();
38
+ models.forEach((modelId) => {
39
+ if (viewport.viewsModel(modelId)) {
40
+ viewedModels.push(modelId);
41
+ }
42
+ else {
43
+ notViewedModels.push(modelId);
44
+ }
45
+ });
46
+ await viewport.addViewedModels(notViewedModels);
47
+ viewport.changeModelDisplay(viewedModels, false);
48
+ }
49
+ /**
50
+ * Based on the value of `enable` argument, either enables or disables display of given models.
51
+ * @public
52
+ */
53
+ export async function toggleModels(models, enable, viewport) {
54
+ if (!models) {
55
+ return;
56
+ }
57
+ if (enable) {
58
+ viewport.changeModelDisplay(models, false);
59
+ }
60
+ else {
61
+ await viewport.addViewedModels(models);
62
+ }
49
63
  }
50
- /** @internal */
51
- export function useLatest(value) {
52
- const ref = useRef(value);
53
- useEffect(() => {
54
- ref.current = value;
55
- }, [value]);
56
- return ref;
64
+ /**
65
+ * Checks if all given models are displayed in given viewport.
66
+ * @public
67
+ */
68
+ export function areAllModelsVisible(models, viewport) {
69
+ return models.length !== 0 ? models.every((id) => viewport.viewsModel(id)) : false;
57
70
  }
58
71
  //# sourceMappingURL=Utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACpG,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,sCAAsC,EAAE,MAAM,4BAA4B,CAAC;AASpF,gBAAgB;AAChB,MAAM,UAAU,iBAAiB,CAAC,GAAc;IAC9C,sHAAsH;IACtH,oCAAoC;IACpC,MAAM,MAAM,GAAG,IAAI,KAAK,EAAgB,CAAC;IACzC,KAAK,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,GAAG,EAAE,GAAG,CAAC,CAAC;KACzB;IACD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,kBAAkB,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAA+F;IAC1J,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,cAAc,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACvD,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,GAAG;QACrB,GAAG,cAAc;QACjB,GAAG,sCAAsC,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;QAC7E,GAAG,gCAAgC,CAAC,wBAAwB,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;KAC5E,CAAC;AACJ,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,SAAS,CAAI,KAAQ;IACnC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,GAAG,CAAC;AACb,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 { createECSchemaProvider, createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { createLimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport { createCachingECClassHierarchyInspector } from \"@itwin/presentation-shared\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { SchemaContext } from \"@itwin/ecschema-metadata\";\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 createIModelAccess({ imodel, getSchemaContext }: { imodel: IModelConnection; getSchemaContext: (imodel: IModelConnection) => SchemaContext }) {\n const schemas = getSchemaContext(imodel);\n const schemaProvider = createECSchemaProvider(schemas);\n return {\n imodelKey: imodel.key,\n ...schemaProvider,\n ...createCachingECClassHierarchyInspector({ schemaProvider, cacheSize: 100 }),\n ...createLimitingECSqlQueryExecutor(createECSqlQueryExecutor(imodel), 1000),\n };\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"]}
1
+ {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EA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C;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAgB,EAAE,MAAe,EAAE,QAAkB;IACtF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO;KACR;IACD,IAAI,MAAM,EAAE;QACV,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KAC5C;SAAM;QACL,MAAM,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;KACxC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAgB,EAAE,QAAkB;IACtE,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACrF,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 type { Viewport } from \"@itwin/core-frontend\";\nimport { showAllCategories } from \"./CategoriesVisibilityUtils.js\";\nimport { toggleAllCategories } from \"./internal/VisibilityUtils.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\n\n/** @beta */\nexport type FunctionProps<THook extends (props: any) => any> = Parameters<THook>[0];\n\n/**\n * Disables display of all given models.\n * @public\n */\nexport async function hideAllModels(models: string[], viewport: Viewport) {\n viewport.changeModelDisplay(models, false);\n}\n\n/**\n * Enables display of all given models. Also enables display of all categories and clears always and\n * never drawn lists in the viewport.\n * @public\n */\nexport async function showAll(props: {\n /** ID's of models to enable */\n models: Id64Array;\n /** ID's of categories to enable, if set to undefined, all categories will be enabled */\n categories?: Id64Array;\n viewport: Viewport;\n}) {\n const { models, categories, viewport } = props;\n await viewport.addViewedModels(models);\n viewport.clearNeverDrawn();\n viewport.clearAlwaysDrawn();\n if (categories) {\n await showAllCategories(categories, viewport);\n } else {\n await toggleAllCategories(viewport, true);\n }\n}\n\n/**\n * Inverts display of all given models.\n * @public\n */\nexport async function invertAllModels(models: Id64Array, viewport: Viewport) {\n const notViewedModels = new Array<Id64String>();\n const viewedModels = new Array<Id64String>();\n models.forEach((modelId) => {\n if (viewport.viewsModel(modelId)) {\n viewedModels.push(modelId);\n } else {\n notViewedModels.push(modelId);\n }\n });\n await viewport.addViewedModels(notViewedModels);\n viewport.changeModelDisplay(viewedModels, false);\n}\n\n/**\n * Based on the value of `enable` argument, either enables or disables display of given models.\n * @public\n */\nexport async function toggleModels(models: string[], enable: boolean, viewport: Viewport) {\n if (!models) {\n return;\n }\n if (enable) {\n viewport.changeModelDisplay(models, false);\n } else {\n await viewport.addViewedModels(models);\n }\n}\n\n/**\n * Checks if all given models are displayed in given viewport.\n * @public\n */\nexport function areAllModelsVisible(models: string[], viewport: Viewport) {\n return models.length !== 0 ? models.every((id) => viewport.viewsModel(id)) : false;\n}\n"]}
@@ -4,11 +4,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  /* eslint-disable @itwin/no-internal */
7
- import { LocalizationContextProvider, TreeRenderer as PresentationTree } from "@itwin/presentation-hierarchies-react";
8
- import { useHierarchiesLocalization } from "../UseHierarchiesLocalization.js";
7
+ import { TreeRenderer as PresentationTree } from "@itwin/presentation-hierarchies-react";
8
+ import { useHierarchiesLocalization } from "../internal/UseHierarchiesLocalization.js";
9
9
  /** @internal */
10
10
  export function BaseTreeRenderer({ rootNodes, onNodeClick, expandNode, actions, ...props }) {
11
11
  const localizedStrings = useHierarchiesLocalization();
12
- return (_jsx(LocalizationContextProvider, { localizedStrings: localizedStrings, children: _jsx(PresentationTree, { ...props, onNodeClick: onNodeClick, expandNode: expandNode, rootNodes: rootNodes, actions: actions }) }));
12
+ return (_jsx(PresentationTree, { ...props, onNodeClick: onNodeClick, localizedStrings: localizedStrings, expandNode: expandNode, rootNodes: rootNodes, actions: actions }));
13
13
  }
14
14
  //# sourceMappingURL=BaseTreeRenderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseTreeRenderer.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/BaseTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG,uCAAuC;AAEvC,OAAO,EAAE,2BAA2B,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACtH,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAK9E,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,KAAK,EAAyB;IAC/G,MAAM,gBAAgB,GAAG,0BAA0B,EAAE,CAAC;IACtD,OAAO,CACL,KAAC,2BAA2B,IAAC,gBAAgB,EAAE,gBAAgB,YAC7D,KAAC,gBAAgB,OAAK,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAI,GAC7F,CAC/B,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/* eslint-disable @itwin/no-internal */\n\nimport { LocalizationContextProvider, TreeRenderer as PresentationTree } from \"@itwin/presentation-hierarchies-react\";\nimport { useHierarchiesLocalization } from \"../UseHierarchiesLocalization.js\";\n\n/** @beta */\nexport type BaseTreeRendererProps = React.ComponentPropsWithoutRef<typeof PresentationTree>;\n\n/** @internal */\nexport function BaseTreeRenderer({ rootNodes, onNodeClick, expandNode, actions, ...props }: BaseTreeRendererProps) {\n const localizedStrings = useHierarchiesLocalization();\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n <PresentationTree {...props} onNodeClick={onNodeClick} expandNode={expandNode} rootNodes={rootNodes} actions={actions} />\n </LocalizationContextProvider>\n );\n}\n"]}
1
+ {"version":3,"file":"BaseTreeRenderer.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/BaseTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG,uCAAuC;AAEvC,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAKvF,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,KAAK,EAAyB;IAC/G,MAAM,gBAAgB,GAAG,0BAA0B,EAAE,CAAC;IACtD,OAAO,CACL,KAAC,gBAAgB,OACX,KAAK,EACT,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,GAChB,CACH,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/* eslint-disable @itwin/no-internal */\n\nimport { TreeRenderer as PresentationTree } from \"@itwin/presentation-hierarchies-react\";\nimport { useHierarchiesLocalization } from \"../internal/UseHierarchiesLocalization.js\";\n\n/** @beta */\nexport type BaseTreeRendererProps = React.ComponentPropsWithoutRef<typeof PresentationTree>;\n\n/** @internal */\nexport function BaseTreeRenderer({ rootNodes, onNodeClick, expandNode, actions, ...props }: BaseTreeRendererProps) {\n const localizedStrings = useHierarchiesLocalization();\n return (\n <PresentationTree\n {...props}\n onNodeClick={onNodeClick}\n localizedStrings={localizedStrings}\n expandNode={expandNode}\n rootNodes={rootNodes}\n actions={actions}\n />\n );\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { PropsWithChildren } from "react";
2
+ /** @internal */
2
3
  export declare function Delayed({ show, children }: PropsWithChildren<{
3
4
  show: boolean;
4
5
  }>): import("react/jsx-runtime").JSX.Element | null;
@@ -4,6 +4,7 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  import { useLayoutEffect, useState } from "react";
7
+ /** @internal */
7
8
  export function Delayed({ show, children }) {
8
9
  const [visible, setVisible] = useState(false);
9
10
  useLayoutEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"Delayed.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/Delayed.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIlD,MAAM,UAAU,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAwC;IAC9E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9C,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,IAAI,EAAE;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO;SACR;QAED,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,UAAU,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,EAAE,GAAG,CAAC,CAAC;QACR,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IAED,OAAO,4BAAG,QAAQ,GAAI,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 { useLayoutEffect, useState } from \"react\";\n\nimport type { PropsWithChildren } from \"react\";\n\nexport function Delayed({ show, children }: PropsWithChildren<{ show: boolean }>) {\n const [visible, setVisible] = useState(false);\n\n useLayoutEffect(() => {\n if (!show) {\n setVisible(false);\n return;\n }\n\n const timer = setTimeout(() => {\n setVisible(show);\n }, 250);\n return () => {\n clearTimeout(timer);\n };\n }, [show]);\n\n if (!visible) {\n return null;\n }\n\n return <>{children}</>;\n}\n"]}
1
+ {"version":3,"file":"Delayed.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/Delayed.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIlD,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAwC;IAC9E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9C,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,IAAI,EAAE;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO;SACR;QAED,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,UAAU,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,EAAE,GAAG,CAAC,CAAC;QACR,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IAED,OAAO,4BAAG,QAAQ,GAAI,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 { useLayoutEffect, useState } from \"react\";\n\nimport type { PropsWithChildren } from \"react\";\n\n/** @internal */\nexport function Delayed({ show, children }: PropsWithChildren<{ show: boolean }>) {\n const [visible, setVisible] = useState(false);\n\n useLayoutEffect(() => {\n if (!show) {\n setVisible(false);\n return;\n }\n\n const timer = setTimeout(() => {\n setVisible(show);\n }, 250);\n return () => {\n clearTimeout(timer);\n };\n }, [show]);\n\n if (!visible) {\n return null;\n }\n\n return <>{children}</>;\n}\n"]}
@@ -10,6 +10,7 @@
10
10
  text-align: center;
11
11
  padding-right: var(--iui-size-xl);
12
12
  padding-left: var(--iui-size-xl);
13
+ padding-top: var(--iui-size-xs);
13
14
  }
14
15
 
15
16
  .tw-empty-tree-container {
@@ -1,3 +1,4 @@
1
1
  import "./ProgressOverlay.css";
2
+ /** @internal */
2
3
  export declare function ProgressOverlay(): import("react/jsx-runtime").JSX.Element;
3
4
  //# sourceMappingURL=ProgressOverlay.d.ts.map
@@ -4,9 +4,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  import "./ProgressOverlay.css";
7
- import { Spinner } from "@itwin/itwinui-react/bricks";
8
- // TODO: replace spinner with ProgressLinear equivalent
7
+ import { ProgressBar, VisuallyHidden } from "@itwin/itwinui-react/bricks";
8
+ import { TreeWidget } from "../../../../TreeWidget.js";
9
+ /** @internal */
9
10
  export function ProgressOverlay() {
10
- return (_jsxs("div", { className: "tw-progress-overlay-container", children: [_jsx(Spinner, {}), _jsx("div", { className: "tw-progress-overlay-backdrop" })] }));
11
+ return (_jsxs("div", { className: "tw-progress-overlay-container", children: [_jsx(ProgressBar, { "aria-labelledby": "tw-progress-bar", tone: "accent" }), _jsx(VisuallyHidden, { id: "tw-progress-bar", children: TreeWidget.translate("loading.filter") }), _jsx("div", { className: "tw-progress-overlay-backdrop" })] }));
11
12
  }
12
13
  //# sourceMappingURL=ProgressOverlay.js.map