@itwin/presentation-frontend 4.5.0-dev.8 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/CHANGELOG.md +72 -1
  2. package/LICENSE.md +1 -1
  3. package/README.md +1 -1
  4. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.d.ts.map +1 -1
  5. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +10 -6
  6. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  7. package/lib/cjs/presentation-frontend/Diagnostics.d.ts.map +1 -1
  8. package/lib/cjs/presentation-frontend/Diagnostics.js +18 -13
  9. package/lib/cjs/presentation-frontend/Diagnostics.js.map +1 -1
  10. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js +3 -3
  11. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  12. package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts.map +1 -1
  13. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +3 -3
  14. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  15. package/lib/cjs/presentation-frontend/LocalizationHelper.js +3 -3
  16. package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
  17. package/lib/cjs/presentation-frontend/Presentation.d.ts +1 -1
  18. package/lib/cjs/presentation-frontend/Presentation.d.ts.map +1 -1
  19. package/lib/cjs/presentation-frontend/Presentation.js +36 -21
  20. package/lib/cjs/presentation-frontend/Presentation.js.map +1 -1
  21. package/lib/cjs/presentation-frontend/PresentationManager.d.ts +84 -21
  22. package/lib/cjs/presentation-frontend/PresentationManager.d.ts.map +1 -1
  23. package/lib/cjs/presentation-frontend/PresentationManager.js +245 -154
  24. package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
  25. package/lib/cjs/presentation-frontend/RulesetManager.d.ts.map +1 -1
  26. package/lib/cjs/presentation-frontend/RulesetManager.js +11 -7
  27. package/lib/cjs/presentation-frontend/RulesetManager.js.map +1 -1
  28. package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts.map +1 -1
  29. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +53 -31
  30. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  31. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.d.ts +30 -0
  32. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.d.ts.map +1 -0
  33. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.js +117 -0
  34. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.js.map +1 -0
  35. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +33 -4
  36. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  37. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +179 -74
  38. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  39. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts.map +1 -1
  40. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +54 -25
  41. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  42. package/lib/cjs/presentation-frontend/selection/HiliteRules.json +172 -172
  43. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts.map +1 -1
  44. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +23 -13
  45. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  46. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +3 -3
  47. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  48. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts.map +1 -1
  49. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +3 -3
  50. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  51. package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts.map +1 -1
  52. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +15 -9
  53. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  54. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  55. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +7 -5
  56. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  57. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts +22 -3
  58. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts.map +1 -1
  59. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +295 -75
  60. package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
  61. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts.map +1 -1
  62. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +25 -14
  63. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  64. package/lib/cjs/presentation-frontend.js +3 -3
  65. package/lib/cjs/presentation-frontend.js.map +1 -1
  66. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts.map +1 -1
  67. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +10 -6
  68. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  69. package/lib/esm/presentation-frontend/Diagnostics.d.ts.map +1 -1
  70. package/lib/esm/presentation-frontend/Diagnostics.js +18 -13
  71. package/lib/esm/presentation-frontend/Diagnostics.js.map +1 -1
  72. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +3 -3
  73. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  74. package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts.map +1 -1
  75. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +3 -3
  76. package/lib/esm/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  77. package/lib/esm/presentation-frontend/LocalizationHelper.js +3 -3
  78. package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
  79. package/lib/esm/presentation-frontend/Presentation.d.ts +1 -1
  80. package/lib/esm/presentation-frontend/Presentation.d.ts.map +1 -1
  81. package/lib/esm/presentation-frontend/Presentation.js +36 -21
  82. package/lib/esm/presentation-frontend/Presentation.js.map +1 -1
  83. package/lib/esm/presentation-frontend/PresentationManager.d.ts +84 -21
  84. package/lib/esm/presentation-frontend/PresentationManager.d.ts.map +1 -1
  85. package/lib/esm/presentation-frontend/PresentationManager.js +244 -152
  86. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  87. package/lib/esm/presentation-frontend/RulesetManager.d.ts.map +1 -1
  88. package/lib/esm/presentation-frontend/RulesetManager.js +11 -7
  89. package/lib/esm/presentation-frontend/RulesetManager.js.map +1 -1
  90. package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts.map +1 -1
  91. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +53 -31
  92. package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  93. package/lib/esm/presentation-frontend/StreamedResponseGenerator.d.ts +30 -0
  94. package/lib/esm/presentation-frontend/StreamedResponseGenerator.d.ts.map +1 -0
  95. package/lib/esm/presentation-frontend/StreamedResponseGenerator.js +113 -0
  96. package/lib/esm/presentation-frontend/StreamedResponseGenerator.js.map +1 -0
  97. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +33 -4
  98. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  99. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +179 -74
  100. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  101. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts.map +1 -1
  102. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +54 -25
  103. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  104. package/lib/esm/presentation-frontend/selection/HiliteRules.json +172 -172
  105. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts.map +1 -1
  106. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +24 -14
  107. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  108. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +3 -3
  109. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  110. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts.map +1 -1
  111. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +3 -3
  112. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  113. package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts.map +1 -1
  114. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +15 -9
  115. package/lib/esm/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  116. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  117. package/lib/esm/presentation-frontend/selection/SelectionHelper.js +7 -5
  118. package/lib/esm/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  119. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +22 -3
  120. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts.map +1 -1
  121. package/lib/esm/presentation-frontend/selection/SelectionManager.js +295 -75
  122. package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
  123. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts.map +1 -1
  124. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +25 -14
  125. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  126. package/lib/esm/presentation-frontend.js +3 -3
  127. package/lib/esm/presentation-frontend.js.map +1 -1
  128. package/package.json +20 -16
@@ -1 +1 @@
1
- {"version":3,"file":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C,SAAS;YAChB,OAAO;QAET,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACpF,CAAC;CACF","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/** @packageDocumentation\n * @module UnifiedSelection\n */\n\nimport { DisposableList, IDisposable } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { Keys, KeySet } from \"@itwin/presentation-common\";\nimport { ISelectionProvider } from \"./ISelectionProvider\";\nimport { SelectionChangeEventArgs, SelectionChangesListener } from \"./SelectionChangeEvent\";\nimport { SelectionManager } from \"./SelectionManager\";\n\n/**\n * Properties for creating a `SelectionHandler` instance.\n * @public\n */\nexport interface SelectionHandlerProps {\n /** SelectionManager used to store overall selection. */\n manager: SelectionManager;\n /** iModel connection the selection changes will be associated with. */\n imodel: IModelConnection;\n /**\n * Name of the selection handler. This is an identifier of what caused the\n * selection to change, set as `SelectionChangeEventArgs.source` when firing\n * selection change events. `SelectionHandler.shouldHandle` uses `name` to filter\n * events that it doesn't need to handle.\n */\n name: string;\n /**\n * ID of presentation ruleset used by the component using this handler. The ID is set as\n * `SelectionChangeEventArgs.rulesetId` when making selection changes and event\n * listeners can use or ignore this information.\n */\n rulesetId?: string;\n /** Callback function called when selection changes. */\n onSelect?: SelectionChangesListener;\n}\n\n/**\n * A class that handles selection changes and helps to change\n * internal the selection state.\n *\n * @public\n */\nexport class SelectionHandler implements IDisposable {\n private _inSelect: boolean;\n private _disposables: DisposableList;\n\n /** Selection manager used by this handler to manage selection */\n public readonly manager: SelectionManager;\n /** Name that's used as `SelectionChangeEventArgs.source` when making selection changes */\n public name: string;\n /** iModel whose selection is being handled */\n public imodel: IModelConnection;\n /**\n * Id of a ruleset selection changes will be associated with.\n * @see `SelectionHandlerProps.rulesetId`\n */\n public rulesetId?: string;\n /** Callback function called when selection changes */\n public onSelect?: SelectionChangesListener;\n\n /**\n * Constructor.\n */\n constructor(props: SelectionHandlerProps) {\n this._inSelect = false;\n this.manager = props.manager;\n this._disposables = new DisposableList();\n this.name = props.name;\n this.rulesetId = props.rulesetId;\n this.imodel = props.imodel;\n this.onSelect = props.onSelect;\n this._disposables.add(this.manager.selectionChange.addListener(this.onSelectionChanged));\n }\n\n /**\n * Destructor. Must be called before disposing this object to make sure it cleans\n * up correctly.\n */\n public dispose(): void {\n this._disposables.dispose();\n }\n\n /**\n * Called when the selection changes. Handles this callback by first checking whether\n * the event should be handled at all (using the `shouldHandle` method) and then calling `onSelect`\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n protected onSelectionChanged = (evt: SelectionChangeEventArgs, provider: ISelectionProvider): void => {\n if (!this.onSelect || !this.shouldHandle(evt))\n return;\n\n this._inSelect = true;\n this.onSelect(evt, provider);\n this._inSelect = false;\n };\n\n /** Called to check whether the event should be handled by this handler */\n protected shouldHandle(evt: SelectionChangeEventArgs): boolean {\n if (this.name === evt.source)\n return false;\n return true;\n }\n\n /** Get selection levels for the imodel managed by this handler */\n public getSelectionLevels(): number[] {\n return this.manager.getSelectionLevels(this.imodel);\n }\n\n /**\n * Get selection for the imodel managed by this handler.\n * @param level Level of the selection to get. Defaults to 0.\n */\n public getSelection(level?: number): Readonly<KeySet> {\n return this.manager.getSelection(this.imodel, level);\n }\n\n /**\n * Add to selection.\n * @param keys The keys to add to selection.\n * @param level Level of the selection.\n */\n public addToSelection(keys: Keys, level: number = 0): void {\n if (this._inSelect)\n return;\n\n return this.manager.addToSelection(this.name, this.imodel, keys, level, this.rulesetId);\n }\n\n /**\n * Remove from selection.\n * @param keys The keys to remove from selection.\n * @param level Level of the selection.\n */\n public removeFromSelection(keys: Keys, level: number = 0): void {\n if (this._inSelect)\n return;\n\n return this.manager.removeFromSelection(this.name, this.imodel, keys, level, this.rulesetId);\n }\n\n /**\n * Change selection.\n * @param keys The keys indicating the new selection.\n * @param level Level of the selection.\n */\n public replaceSelection(keys: Keys, level: number = 0): void {\n if (this._inSelect)\n return;\n\n return this.manager.replaceSelection(this.name, this.imodel, keys, level, this.rulesetId);\n }\n\n /**\n * Clear selection.\n * @param level Level of the selection.\n */\n public clearSelection(level: number = 0): void {\n if (this._inSelect)\n return;\n\n return this.manager.clearSelection(this.name, this.imodel, level, this.rulesetId);\n }\n}\n"]}
1
+ {"version":3,"file":"SelectionHandler.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionHandler.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAe,MAAM,qBAAqB,CAAC;AAiClE;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAkB3B;;OAEG;IACH,YAAY,KAA4B;QAmBxC;;;WAGG;QACH,gEAAgE;QACtD,uBAAkB,GAAG,CAAC,GAA6B,EAAE,QAA4B,EAAQ,EAAE;YACnG,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE;gBAC7C,OAAO;aACR;YAED,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC7B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACzB,CAAC,CAAC;QA/BA,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,IAAI,cAAc,EAAE,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,MAAM,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E,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/F,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAC,IAAU,EAAE,QAAgB,CAAC;QACnD,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO;SACR;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5F,CAAC;IAED;;;OAGG;IACI,cAAc,CAAC,QAAgB,CAAC;QACrC,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO;SACR;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACpF,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module UnifiedSelection\r\n */\r\n\r\nimport { DisposableList, IDisposable } from \"@itwin/core-bentley\";\r\nimport { IModelConnection } from \"@itwin/core-frontend\";\r\nimport { Keys, KeySet } from \"@itwin/presentation-common\";\r\nimport { ISelectionProvider } from \"./ISelectionProvider\";\r\nimport { SelectionChangeEventArgs, SelectionChangesListener } from \"./SelectionChangeEvent\";\r\nimport { SelectionManager } from \"./SelectionManager\";\r\n\r\n/**\r\n * Properties for creating a `SelectionHandler` instance.\r\n * @public\r\n */\r\nexport interface SelectionHandlerProps {\r\n /** SelectionManager used to store overall selection. */\r\n manager: SelectionManager;\r\n /** iModel connection the selection changes will be associated with. */\r\n imodel: IModelConnection;\r\n /**\r\n * Name of the selection handler. This is an identifier of what caused the\r\n * selection to change, set as `SelectionChangeEventArgs.source` when firing\r\n * selection change events. `SelectionHandler.shouldHandle` uses `name` to filter\r\n * events that it doesn't need to handle.\r\n */\r\n name: string;\r\n /**\r\n * ID of presentation ruleset used by the component using this handler. The ID is set as\r\n * `SelectionChangeEventArgs.rulesetId` when making selection changes and event\r\n * listeners can use or ignore this information.\r\n */\r\n rulesetId?: string;\r\n /** Callback function called when selection changes. */\r\n onSelect?: SelectionChangesListener;\r\n}\r\n\r\n/**\r\n * A class that handles selection changes and helps to change\r\n * internal the selection state.\r\n *\r\n * @public\r\n */\r\nexport class SelectionHandler implements IDisposable {\r\n private _inSelect: boolean;\r\n private _disposables: DisposableList;\r\n\r\n /** Selection manager used by this handler to manage selection */\r\n public readonly manager: SelectionManager;\r\n /** Name that's used as `SelectionChangeEventArgs.source` when making selection changes */\r\n public name: string;\r\n /** iModel whose selection is being handled */\r\n public imodel: IModelConnection;\r\n /**\r\n * Id of a ruleset selection changes will be associated with.\r\n * @see `SelectionHandlerProps.rulesetId`\r\n */\r\n public rulesetId?: string;\r\n /** Callback function called when selection changes */\r\n public onSelect?: SelectionChangesListener;\r\n\r\n /**\r\n * Constructor.\r\n */\r\n constructor(props: SelectionHandlerProps) {\r\n this._inSelect = false;\r\n this.manager = props.manager;\r\n this._disposables = new DisposableList();\r\n this.name = props.name;\r\n this.rulesetId = props.rulesetId;\r\n this.imodel = props.imodel;\r\n this.onSelect = props.onSelect;\r\n this._disposables.add(this.manager.selectionChange.addListener(this.onSelectionChanged));\r\n }\r\n\r\n /**\r\n * Destructor. Must be called before disposing this object to make sure it cleans\r\n * up correctly.\r\n */\r\n public dispose(): void {\r\n this._disposables.dispose();\r\n }\r\n\r\n /**\r\n * Called when the selection changes. Handles this callback by first checking whether\r\n * the event should be handled at all (using the `shouldHandle` method) and then calling `onSelect`\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected onSelectionChanged = (evt: SelectionChangeEventArgs, provider: ISelectionProvider): void => {\r\n if (!this.onSelect || !this.shouldHandle(evt)) {\r\n return;\r\n }\r\n\r\n this._inSelect = true;\r\n this.onSelect(evt, provider);\r\n this._inSelect = false;\r\n };\r\n\r\n /** Called to check whether the event should be handled by this handler */\r\n protected shouldHandle(evt: SelectionChangeEventArgs): boolean {\r\n if (this.name === evt.source) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /** Get selection levels for the imodel managed by this handler */\r\n public getSelectionLevels(): number[] {\r\n return this.manager.getSelectionLevels(this.imodel);\r\n }\r\n\r\n /**\r\n * Get selection for the imodel managed by this handler.\r\n * @param level Level of the selection to get. Defaults to 0.\r\n */\r\n public getSelection(level?: number): Readonly<KeySet> {\r\n return this.manager.getSelection(this.imodel, level);\r\n }\r\n\r\n /**\r\n * Add to selection.\r\n * @param keys The keys to add to selection.\r\n * @param level Level of the selection.\r\n */\r\n public addToSelection(keys: Keys, level: number = 0): void {\r\n if (this._inSelect) {\r\n return;\r\n }\r\n\r\n return this.manager.addToSelection(this.name, this.imodel, keys, level, this.rulesetId);\r\n }\r\n\r\n /**\r\n * Remove from selection.\r\n * @param keys The keys to remove from selection.\r\n * @param level Level of the selection.\r\n */\r\n public removeFromSelection(keys: Keys, level: number = 0): void {\r\n if (this._inSelect) {\r\n return;\r\n }\r\n\r\n return this.manager.removeFromSelection(this.name, this.imodel, keys, level, this.rulesetId);\r\n }\r\n\r\n /**\r\n * Change selection.\r\n * @param keys The keys indicating the new selection.\r\n * @param level Level of the selection.\r\n */\r\n public replaceSelection(keys: Keys, level: number = 0): void {\r\n if (this._inSelect) {\r\n return;\r\n }\r\n\r\n return this.manager.replaceSelection(this.name, this.imodel, keys, level, this.rulesetId);\r\n }\r\n\r\n /**\r\n * Clear selection.\r\n * @param level Level of the selection.\r\n */\r\n public clearSelection(level: number = 0): void {\r\n if (this._inSelect) {\r\n return;\r\n }\r\n\r\n return this.manager.clearSelection(this.name, this.imodel, level, this.rulesetId);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SelectionHelper.d.ts","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionHelper.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAW,MAAM,4BAA4B,CAAC;AAEhE;;;GAGG;AACH,qBAAa,eAAe;IAG1B,OAAO;IAEP;;;;OAIG;WACW,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE;CAe/D"}
1
+ {"version":3,"file":"SelectionHelper.d.ts","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionHelper.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAW,MAAM,4BAA4B,CAAC;AAEhE;;;GAGG;AACH,qBAAa,eAAe;IAE1B,OAAO;IAEP;;;;OAIG;WACW,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE;CAe/D"}
@@ -1,7 +1,7 @@
1
1
  /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
5
  /** @packageDocumentation
6
6
  * @module UnifiedSelection
7
7
  */
@@ -22,10 +22,12 @@ export class SelectionHelper {
22
22
  const result = new Array();
23
23
  keys.forEach((key) => {
24
24
  if (Key.isNodeKey(key)) {
25
- if (NodeKey.isInstancesNodeKey(key))
25
+ if (NodeKey.isInstancesNodeKey(key)) {
26
26
  result.push(...key.instanceKeys);
27
- else
27
+ }
28
+ else {
28
29
  result.push(key);
30
+ }
29
31
  }
30
32
  else {
31
33
  result.push(key);
@@ -1 +1 @@
1
- {"version":3,"file":"SelectionHelper.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionHelper.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAQ,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEhE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAE1B,uBAAuB;IACvB,gBAAwB,CAAC;IAEzB;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,IAAoB;QACpD,MAAM,MAAM,GAAG,IAAI,KAAK,EAAO,CAAC;QAChC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE;YACxB,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;gBACtB,IAAI,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC;oBACjC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC;;oBAEjC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACpB;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aAClB;QACH,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CAEF","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/** @packageDocumentation\n * @module UnifiedSelection\n */\n\nimport { Key, Keys, NodeKey } from \"@itwin/presentation-common\";\n\n/**\n * Helper class for working with selection.\n * @public\n */\nexport class SelectionHelper {\n\n // istanbul ignore next\n private constructor() { }\n\n /**\n * Re-map the given keyset for selection. This means all instance node keys get converted\n * to instance keys, because in that case we want to select instances instead of nodes. All\n * other types of keys ar left as is.\n */\n public static getKeysForSelection(keys: Readonly<Keys>): Key[] {\n const result = new Array<Key>();\n keys.forEach((key: Key) => {\n if (Key.isNodeKey(key)) {\n if (NodeKey.isInstancesNodeKey(key))\n result.push(...key.instanceKeys);\n else\n result.push(key);\n } else {\n result.push(key);\n }\n });\n return result;\n }\n\n}\n"]}
1
+ {"version":3,"file":"SelectionHelper.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionHelper.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,GAAG,EAAQ,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAEhE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAC1B,uBAAuB;IACvB,gBAAuB,CAAC;IAExB;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,IAAoB;QACpD,MAAM,MAAM,GAAG,IAAI,KAAK,EAAO,CAAC;QAChC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE;YACxB,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;gBACtB,IAAI,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE;oBACnC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC;iBAClC;qBAAM;oBACL,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;iBAClB;aACF;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aAClB;QACH,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module UnifiedSelection\r\n */\r\n\r\nimport { Key, Keys, NodeKey } from \"@itwin/presentation-common\";\r\n\r\n/**\r\n * Helper class for working with selection.\r\n * @public\r\n */\r\nexport class SelectionHelper {\r\n // istanbul ignore next\r\n private constructor() {}\r\n\r\n /**\r\n * Re-map the given keyset for selection. This means all instance node keys get converted\r\n * to instance keys, because in that case we want to select instances instead of nodes. All\r\n * other types of keys ar left as is.\r\n */\r\n public static getKeysForSelection(keys: Readonly<Keys>): Key[] {\r\n const result = new Array<Key>();\r\n keys.forEach((key: Key) => {\r\n if (Key.isNodeKey(key)) {\r\n if (NodeKey.isInstancesNodeKey(key)) {\r\n result.push(...key.instanceKeys);\r\n } else {\r\n result.push(key);\r\n }\r\n } else {\r\n result.push(key);\r\n }\r\n });\r\n return result;\r\n }\r\n}\r\n"]}
@@ -4,6 +4,7 @@
4
4
  import { Id64Arg, IDisposable } from "@itwin/core-bentley";
5
5
  import { IModelConnection } from "@itwin/core-frontend";
6
6
  import { Keys, KeySet, SelectionScope, SelectionScopeProps } from "@itwin/presentation-common";
7
+ import { SelectionStorage } from "@itwin/unified-selection";
7
8
  import { HiliteSet } from "./HiliteSetProvider";
8
9
  import { ISelectionProvider } from "./ISelectionProvider";
9
10
  import { SelectionChangeEvent } from "./SelectionChangeEvent";
@@ -15,15 +16,26 @@ import { SelectionScopesManager } from "./SelectionScopesManager";
15
16
  export interface SelectionManagerProps {
16
17
  /** A manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */
17
18
  scopes: SelectionScopesManager;
19
+ /**
20
+ * Custom unified selection storage to be used by [[SelectionManager]]. If not provided [[SelectionManager]] creates
21
+ * and maintains storage.
22
+ */
23
+ selectionStorage?: SelectionStorage;
18
24
  }
19
25
  /**
20
26
  * The selection manager which stores the overall selection.
21
27
  * @public
22
28
  */
23
29
  export declare class SelectionManager implements ISelectionProvider {
24
- private _selectionContainerMap;
30
+ private _selectionStorage;
25
31
  private _imodelToolSelectionSyncHandlers;
26
32
  private _hiliteSetProviders;
33
+ private _ownsStorage;
34
+ private _knownIModels;
35
+ private _currentSelection;
36
+ private _selectionChanges;
37
+ private _selectionEventsSubscription;
38
+ private _listeners;
27
39
  /** An event which gets broadcasted on selection changes */
28
40
  readonly selectionChange: SelectionChangeEvent;
29
41
  /** Manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */
@@ -32,8 +44,8 @@ export declare class SelectionManager implements ISelectionProvider {
32
44
  * Creates an instance of SelectionManager.
33
45
  */
34
46
  constructor(props: SelectionManagerProps);
47
+ dispose(): void;
35
48
  private onConnectionClose;
36
- private getContainer;
37
49
  /** @internal */
38
50
  getToolSelectionSyncHandler(imodel: IModelConnection): ToolSelectionSyncHandler | undefined;
39
51
  /**
@@ -47,7 +59,13 @@ export declare class SelectionManager implements ISelectionProvider {
47
59
  suspendIModelToolSelectionSync(imodel: IModelConnection): IDisposable;
48
60
  /** Get the selection levels currently stored in this manager for the specified imodel */
49
61
  getSelectionLevels(imodel: IModelConnection): number[];
50
- /** Get the selection currently stored in this manager */
62
+ /**
63
+ * Get the selection currently stored in this manager
64
+ *
65
+ * @note Calling immediately after `add*`|`replace*`|`remove*`|`clear*` method call does not guarantee
66
+ * that returned `KeySet` will include latest changes. Listen for `selectionChange` event to get the
67
+ * latest selection after changes.
68
+ */
51
69
  getSelection(imodel: IModelConnection, level?: number): Readonly<KeySet>;
52
70
  private handleEvent;
53
71
  /**
@@ -126,6 +144,7 @@ export declare class SelectionManager implements ISelectionProvider {
126
144
  */
127
145
  getHiliteSetIterator(imodel: IModelConnection): AsyncIterableIterator<HiliteSet>;
128
146
  private getHiliteSetProvider;
147
+ private streamSelectionEvents;
129
148
  }
130
149
  /** @internal */
131
150
  export declare const TRANSIENT_ELEMENT_CLASSNAME = "/TRANSIENT";
@@ -1 +1 @@
1
- {"version":3,"file":"SelectionManager.d.ts","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAQ,OAAO,EAAa,WAAW,EAAS,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAA4C,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAqB,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAClH,OAAO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M;;;OAGG;IACU,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAIvE;;;OAGG;IACI,oBAAoB,CAAC,MAAM,EAAE,gBAAgB;IAIpD,OAAO,CAAC,oBAAoB;CAQ7B;AAuCD,gBAAgB;AAChB,eAAO,MAAM,2BAA2B,eAAe,CAAC;AAExD,gBAAgB;AAChB,qBAAa,wBAAyB,YAAW,WAAW;IAE1D,OAAO,CAAC,oBAAoB,CAAU;IACtC,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,uCAAuC,CAAa;IAC5D,OAAO,CAAC,cAAc,CAA2B;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;gBAEV,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB;IAMxE,OAAO;IAId,+BAA+B;IAC/B,IAAW,aAAa,gBAAgD;IAGxE,OAAO,CAAC,sBAAsB,CAqD5B;CACH"}
1
+ {"version":3,"file":"SelectionManager.d.ts","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAQ,OAAO,EAAa,WAAW,EAAS,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAA4C,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAoD,IAAI,EAAE,MAAM,EAAW,cAAc,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC1J,OAAO,EAKL,gBAAgB,EAGjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAAqB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAiD,MAAM,wBAAwB,CAAC;AAC7G,OAAO,EAA6B,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;GAGG;AAC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AC,IAAI,CAAC;IAKhB;;;OAGG;IACU,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAIvE;;;OAGG;IACI,oBAAoB,CAAC,MAAM,EAAE,gBAAgB;IAIpD,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,qBAAqB;CA6B9B;AAED,gBAAgB;AAChB,eAAO,MAAM,2BAA2B,eAAe,CAAC;AAExD,gBAAgB;AAChB,qBAAa,wBAAyB,YAAW,WAAW;IAC1D,OAAO,CAAC,oBAAoB,CAAU;IACtC,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,uCAAuC,CAAa;IAC5D,OAAO,CAAC,cAAc,CAA2B;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;gBAEV,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB;IAMxE,OAAO;IAId,+BAA+B;IAC/B,IAAW,aAAa,gBAEvB;IAGD,OAAO,CAAC,sBAAsB,CA4D5B;CACH"}
@@ -1,13 +1,16 @@
1
1
  /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
5
  /** @packageDocumentation
6
6
  * @module UnifiedSelection
7
7
  */
8
+ import { defer, EMPTY, mergeMap, of, Subject, takeUntil, tap } from "rxjs";
8
9
  import { Id64, using } from "@itwin/core-bentley";
9
10
  import { IModelConnection, SelectionSetEventType } from "@itwin/core-frontend";
10
- import { AsyncTasksTracker, KeySet } from "@itwin/presentation-common";
11
+ import { AsyncTasksTracker, KeySet, NodeKey } from "@itwin/presentation-common";
12
+ import { createStorage, } from "@itwin/unified-selection";
13
+ import { Presentation } from "../Presentation";
11
14
  import { HiliteSetProvider } from "./HiliteSetProvider";
12
15
  import { SelectionChangeEvent, SelectionChangeType } from "./SelectionChangeEvent";
13
16
  import { createSelectionScopeProps } from "./SelectionScopesManager";
@@ -20,31 +23,43 @@ export class SelectionManager {
20
23
  * Creates an instance of SelectionManager.
21
24
  */
22
25
  constructor(props) {
23
- this._selectionContainerMap = new Map();
24
26
  this._imodelToolSelectionSyncHandlers = new Map();
25
27
  this._hiliteSetProviders = new Map();
28
+ this._knownIModels = new Map();
29
+ this._currentSelection = new CurrentSelectionStorage();
30
+ this._selectionChanges = new Subject();
31
+ this._listeners = [];
26
32
  this.selectionChange = new SelectionChangeEvent();
27
33
  this.scopes = props.scopes;
28
- IModelConnection.onClose.addListener((imodel) => {
34
+ this._selectionStorage = props.selectionStorage ?? createStorage();
35
+ this._ownsStorage = props.selectionStorage === undefined;
36
+ this._selectionStorage.selectionChangeEvent.addListener((args) => this._selectionChanges.next(args));
37
+ this._selectionEventsSubscription = this.streamSelectionEvents();
38
+ this._listeners.push(IModelConnection.onOpen.addListener((imodel) => {
39
+ this._knownIModels.set(imodel.key, imodel);
40
+ }));
41
+ this._listeners.push(IModelConnection.onClose.addListener((imodel) => {
29
42
  this.onConnectionClose(imodel);
30
- });
43
+ }));
44
+ }
45
+ dispose() {
46
+ this._selectionEventsSubscription.unsubscribe();
47
+ this._listeners.forEach((dispose) => dispose());
31
48
  }
32
49
  onConnectionClose(imodel) {
33
- this.clearSelection("Connection Close Event", imodel);
34
- this._selectionContainerMap.delete(imodel);
35
50
  this._hiliteSetProviders.delete(imodel);
36
- }
37
- getContainer(imodel) {
38
- let selectionContainer = this._selectionContainerMap.get(imodel);
39
- if (!selectionContainer) {
40
- selectionContainer = new SelectionContainer();
41
- this._selectionContainerMap.set(imodel, selectionContainer);
51
+ this._knownIModels.delete(imodel.key);
52
+ this._currentSelection.clear(imodel.key);
53
+ if (this._ownsStorage) {
54
+ this.clearSelection("Connection Close Event", imodel);
55
+ this._selectionStorage.clearStorage({ iModelKey: imodel.key });
42
56
  }
43
- return selectionContainer;
44
57
  }
45
58
  /** @internal */
46
59
  // istanbul ignore next
47
- getToolSelectionSyncHandler(imodel) { return this._imodelToolSelectionSyncHandlers.get(imodel)?.handler; }
60
+ getToolSelectionSyncHandler(imodel) {
61
+ return this._imodelToolSelectionSyncHandlers.get(imodel)?.handler;
62
+ }
48
63
  /**
49
64
  * Request the manager to sync with imodel's tool selection (see `IModelConnection.selectionSet`).
50
65
  */
@@ -77,46 +92,57 @@ export class SelectionManager {
77
92
  */
78
93
  suspendIModelToolSelectionSync(imodel) {
79
94
  const registration = this._imodelToolSelectionSyncHandlers.get(imodel);
80
- if (!registration)
95
+ if (!registration) {
81
96
  return { dispose: () => { } };
97
+ }
82
98
  const wasSuspended = registration.handler.isSuspended;
83
99
  registration.handler.isSuspended = true;
84
100
  return { dispose: () => (registration.handler.isSuspended = wasSuspended) };
85
101
  }
86
102
  /** Get the selection levels currently stored in this manager for the specified imodel */
87
103
  getSelectionLevels(imodel) {
88
- return this.getContainer(imodel).getSelectionLevels();
104
+ return this._selectionStorage.getSelectionLevels({ iModelKey: imodel.key });
89
105
  }
90
- /** Get the selection currently stored in this manager */
106
+ /**
107
+ * Get the selection currently stored in this manager
108
+ *
109
+ * @note Calling immediately after `add*`|`replace*`|`remove*`|`clear*` method call does not guarantee
110
+ * that returned `KeySet` will include latest changes. Listen for `selectionChange` event to get the
111
+ * latest selection after changes.
112
+ */
91
113
  getSelection(imodel, level = 0) {
92
- return this.getContainer(imodel).getSelection(level);
114
+ return this._currentSelection.getSelection(imodel.key, level);
93
115
  }
94
116
  handleEvent(evt) {
95
- const container = this.getContainer(evt.imodel);
96
- const selectedItemsSet = container.getSelection(evt.level);
97
- const guidBefore = selectedItemsSet.guid;
98
117
  switch (evt.changeType) {
99
118
  case SelectionChangeType.Add:
100
- selectedItemsSet.add(evt.keys);
119
+ this._selectionStorage.addToSelection({
120
+ iModelKey: evt.imodel.key,
121
+ source: evt.source,
122
+ level: evt.level,
123
+ selectables: keysToSelectable(evt.imodel, evt.keys),
124
+ });
101
125
  break;
102
126
  case SelectionChangeType.Remove:
103
- selectedItemsSet.delete(evt.keys);
127
+ this._selectionStorage.removeFromSelection({
128
+ iModelKey: evt.imodel.key,
129
+ source: evt.source,
130
+ level: evt.level,
131
+ selectables: keysToSelectable(evt.imodel, evt.keys),
132
+ });
104
133
  break;
105
134
  case SelectionChangeType.Replace:
106
- if (selectedItemsSet.size !== evt.keys.size || !selectedItemsSet.hasAll(evt.keys)) {
107
- // note: the above check is only needed to avoid changing
108
- // guid of the keyset if we're replacing keyset with the same keys
109
- selectedItemsSet.clear().add(evt.keys);
110
- }
135
+ this._selectionStorage.replaceSelection({
136
+ iModelKey: evt.imodel.key,
137
+ source: evt.source,
138
+ level: evt.level,
139
+ selectables: keysToSelectable(evt.imodel, evt.keys),
140
+ });
111
141
  break;
112
142
  case SelectionChangeType.Clear:
113
- selectedItemsSet.clear();
143
+ this._selectionStorage.clearSelection({ iModelKey: evt.imodel.key, source: evt.source, level: evt.level });
114
144
  break;
115
145
  }
116
- if (selectedItemsSet.guid === guidBefore)
117
- return;
118
- container.clear(evt.level + 1);
119
- this.selectionChange.raiseEvent(evt, this);
120
146
  }
121
147
  /**
122
148
  * Add keys to the selection
@@ -258,36 +284,30 @@ export class SelectionManager {
258
284
  }
259
285
  return provider;
260
286
  }
261
- }
262
- /** @internal */
263
- class SelectionContainer {
264
- constructor() {
265
- this._selectedItemsSetMap = new Map();
266
- }
267
- getSelection(level) {
268
- let selectedItemsSet = this._selectedItemsSetMap.get(level);
269
- if (!selectedItemsSet) {
270
- selectedItemsSet = new KeySet();
271
- this._selectedItemsSetMap.set(level, selectedItemsSet);
272
- }
273
- return selectedItemsSet;
274
- }
275
- getSelectionLevels() {
276
- const levels = new Array();
277
- for (const entry of this._selectedItemsSetMap.entries()) {
278
- if (!entry[1].isEmpty)
279
- levels.push(entry[0]);
280
- }
281
- return levels.sort();
282
- }
283
- clear(level) {
284
- const keys = this._selectedItemsSetMap.keys();
285
- for (const key of keys) {
286
- if (key >= level) {
287
- const selectedItemsSet = this._selectedItemsSetMap.get(key);
288
- selectedItemsSet.clear();
289
- }
290
- }
287
+ streamSelectionEvents() {
288
+ return this._selectionChanges
289
+ .pipe(mergeMap((args) => {
290
+ const currentSelectables = this._selectionStorage.getSelection({ iModelKey: args.iModelKey, level: args.level });
291
+ return this._currentSelection.computeSelection(args.iModelKey, args.level, currentSelectables, args.selectables).pipe(mergeMap(({ level, changedSelection }) => {
292
+ const imodel = this._knownIModels.get(args.iModelKey);
293
+ if (!imodel) {
294
+ return EMPTY;
295
+ }
296
+ return of({
297
+ imodel,
298
+ keys: changedSelection,
299
+ level,
300
+ source: args.source,
301
+ timestamp: args.timestamp,
302
+ changeType: getChangeType(args.changeType),
303
+ });
304
+ }));
305
+ }))
306
+ .subscribe({
307
+ next: (args) => {
308
+ this.selectionChange.raiseEvent(args, this);
309
+ },
310
+ });
291
311
  }
292
312
  }
293
313
  /** @internal */
@@ -300,12 +320,14 @@ export class ToolSelectionSyncHandler {
300
320
  // eslint-disable-next-line @typescript-eslint/naming-convention
301
321
  this.onToolSelectionChanged = async (ev) => {
302
322
  // ignore selection change event if the handler is suspended
303
- if (this.isSuspended)
323
+ if (this.isSuspended) {
304
324
  return;
325
+ }
305
326
  // this component only cares about its own imodel
306
327
  const imodel = ev.set.iModel;
307
- if (imodel !== this._imodel)
328
+ if (imodel !== this._imodel) {
308
329
  return;
330
+ }
309
331
  // determine the level of selection changes
310
332
  // wip: may want to allow selecting at different levels?
311
333
  const selectionLevel = 0;
@@ -354,18 +376,23 @@ export class ToolSelectionSyncHandler {
354
376
  this._imodelToolSelectionListenerDisposeFunc();
355
377
  }
356
378
  /** note: used only it tests */
357
- get pendingAsyncs() { return this._asyncsTracker.pendingAsyncs; }
379
+ get pendingAsyncs() {
380
+ return this._asyncsTracker.pendingAsyncs;
381
+ }
358
382
  }
359
383
  const parseIds = (ids) => {
360
384
  let allPersistent = true;
361
385
  let allTransient = true;
362
386
  for (const id of Id64.iterable(ids)) {
363
- if (Id64.isTransient(id))
387
+ if (Id64.isTransient(id)) {
364
388
  allPersistent = false;
365
- else
389
+ }
390
+ else {
366
391
  allTransient = false;
367
- if (!allPersistent && !allTransient)
392
+ }
393
+ if (!allPersistent && !allTransient) {
368
394
  break;
395
+ }
369
396
  }
370
397
  // avoid making a copy if ids are only persistent or only transient
371
398
  if (allPersistent) {
@@ -379,16 +406,19 @@ const parseIds = (ids) => {
379
406
  const persistentElementIds = [];
380
407
  const transientElementIds = [];
381
408
  for (const id of Id64.iterable(ids)) {
382
- if (Id64.isTransient(id))
409
+ if (Id64.isTransient(id)) {
383
410
  transientElementIds.push(id);
384
- else
411
+ }
412
+ else {
385
413
  persistentElementIds.push(id);
414
+ }
386
415
  }
387
416
  return { persistent: persistentElementIds, transient: transientElementIds };
388
417
  };
389
418
  function addTransientKeys(transientIds, keys) {
390
- for (const id of Id64.iterable(transientIds))
419
+ for (const id of Id64.iterable(transientIds)) {
391
420
  keys.add({ className: TRANSIENT_ELEMENT_CLASSNAME, id });
421
+ }
392
422
  }
393
423
  /** @internal */
394
424
  class ScopedSelectionChanger {
@@ -417,4 +447,194 @@ class ScopedSelectionChanger {
417
447
  this.manager.replaceSelection(this.name, this.imodel, keys, level);
418
448
  }
419
449
  }
450
+ /** Stores current selection in `KeySet` format per iModel. */
451
+ class CurrentSelectionStorage {
452
+ constructor() {
453
+ this._currentSelection = new Map();
454
+ }
455
+ getCurrentSelectionStorage(imodelKey) {
456
+ let storage = this._currentSelection.get(imodelKey);
457
+ if (!storage) {
458
+ storage = new IModelSelectionStorage();
459
+ this._currentSelection.set(imodelKey, storage);
460
+ }
461
+ return storage;
462
+ }
463
+ getSelection(imodelKey, level) {
464
+ return this.getCurrentSelectionStorage(imodelKey).getSelection(level);
465
+ }
466
+ clear(imodelKey) {
467
+ this._currentSelection.delete(imodelKey);
468
+ }
469
+ computeSelection(imodelKey, level, currSelectables, changedSelectables) {
470
+ return this.getCurrentSelectionStorage(imodelKey).computeSelection(level, currSelectables, changedSelectables);
471
+ }
472
+ }
473
+ /**
474
+ * Computes and stores current selection in `KeySet` format.
475
+ * It always stores result of latest resolved call to `computeSelection`.
476
+ */
477
+ class IModelSelectionStorage {
478
+ constructor() {
479
+ this._currentSelection = new Map();
480
+ }
481
+ getSelection(level) {
482
+ let entry = this._currentSelection.get(level);
483
+ if (!entry) {
484
+ entry = { value: new KeySet(), ongoingComputationDisposers: new Set() };
485
+ this._currentSelection.set(level, entry);
486
+ }
487
+ return entry.value;
488
+ }
489
+ clearSelections(level) {
490
+ const clearedLevels = [];
491
+ for (const [storedLevel] of this._currentSelection.entries()) {
492
+ if (storedLevel > level) {
493
+ clearedLevels.push(storedLevel);
494
+ }
495
+ }
496
+ clearedLevels.forEach((storedLevel) => {
497
+ const entry = this._currentSelection.get(storedLevel);
498
+ // istanbul ignore if
499
+ if (!entry) {
500
+ return;
501
+ }
502
+ for (const disposer of entry.ongoingComputationDisposers) {
503
+ disposer.next();
504
+ }
505
+ this._currentSelection.delete(storedLevel);
506
+ });
507
+ }
508
+ addDisposer(level, disposer) {
509
+ const entry = this._currentSelection.get(level);
510
+ if (!entry) {
511
+ this._currentSelection.set(level, { value: new KeySet(), ongoingComputationDisposers: new Set([disposer]) });
512
+ return;
513
+ }
514
+ entry.ongoingComputationDisposers.add(disposer);
515
+ }
516
+ setSelection(level, keys, disposer) {
517
+ const currEntry = this._currentSelection.get(level);
518
+ // istanbul ignore else
519
+ if (currEntry) {
520
+ currEntry.ongoingComputationDisposers.delete(disposer);
521
+ }
522
+ this._currentSelection.set(level, {
523
+ value: keys,
524
+ ongoingComputationDisposers: currEntry?.ongoingComputationDisposers ?? /* istanbul ignore next */ new Set(),
525
+ });
526
+ }
527
+ computeSelection(level, currSelectables, changedSelectables) {
528
+ this.clearSelections(level);
529
+ const prevComputationsDisposers = [...(this._currentSelection.get(level)?.ongoingComputationDisposers ?? [])];
530
+ const currDisposer = new Subject();
531
+ this.addDisposer(level, currDisposer);
532
+ return defer(async () => {
533
+ const convertedSelectables = [];
534
+ const [current, changed] = await Promise.all([
535
+ selectablesToKeys(currSelectables, convertedSelectables),
536
+ selectablesToKeys(changedSelectables, convertedSelectables),
537
+ ]);
538
+ const currentSelection = new KeySet([...current.keys, ...current.selectableKeys.flatMap((selectable) => selectable.keys)]);
539
+ const changedSelection = new KeySet([...changed.keys, ...changed.selectableKeys.flatMap((selectable) => selectable.keys)]);
540
+ return {
541
+ level,
542
+ currentSelection,
543
+ changedSelection,
544
+ };
545
+ }).pipe(takeUntil(currDisposer), tap({
546
+ next: (val) => {
547
+ prevComputationsDisposers.forEach((disposer) => disposer.next());
548
+ this.setSelection(val.level, val.currentSelection, currDisposer);
549
+ },
550
+ }));
551
+ }
552
+ }
553
+ function keysToSelectable(imodel, keys) {
554
+ const selectables = [];
555
+ keys.forEach((key) => {
556
+ if ("id" in key) {
557
+ selectables.push(key);
558
+ return;
559
+ }
560
+ const customSelectable = {
561
+ identifier: key.pathFromRoot.join("/"),
562
+ data: key,
563
+ loadInstanceKeys: () => createInstanceKeysIterator(imodel, key),
564
+ };
565
+ selectables.push(customSelectable);
566
+ });
567
+ return selectables;
568
+ }
569
+ async function selectablesToKeys(selectables, convertedList) {
570
+ const keys = [];
571
+ const selectableKeys = [];
572
+ for (const [className, ids] of selectables.instanceKeys) {
573
+ for (const id of ids) {
574
+ keys.push({ id, className });
575
+ }
576
+ }
577
+ for (const [_, selectable] of selectables.custom) {
578
+ if (isNodeKey(selectable.data)) {
579
+ selectableKeys.push({ identifier: selectable.identifier, keys: [selectable.data] });
580
+ continue;
581
+ }
582
+ const converted = convertedList.find((con) => con.identifier === selectable.identifier);
583
+ if (converted) {
584
+ selectableKeys.push(converted);
585
+ continue;
586
+ }
587
+ const newConverted = { identifier: selectable.identifier, keys: [] };
588
+ convertedList.push(newConverted);
589
+ for await (const instanceKey of selectable.loadInstanceKeys()) {
590
+ newConverted.keys.push(instanceKey);
591
+ }
592
+ selectableKeys.push(newConverted);
593
+ }
594
+ return { keys, selectableKeys };
595
+ }
596
+ async function* createInstanceKeysIterator(imodel, nodeKey) {
597
+ if (NodeKey.isInstancesNodeKey(nodeKey)) {
598
+ for (const key of nodeKey.instanceKeys) {
599
+ yield key;
600
+ }
601
+ return;
602
+ }
603
+ const content = await Presentation.presentation.getContentInstanceKeys({
604
+ imodel,
605
+ keys: new KeySet([nodeKey]),
606
+ rulesetOrId: {
607
+ id: "grouped-instances",
608
+ rules: [
609
+ {
610
+ ruleType: "Content",
611
+ specifications: [
612
+ {
613
+ specType: "SelectedNodeInstances",
614
+ },
615
+ ],
616
+ },
617
+ ],
618
+ },
619
+ });
620
+ for await (const key of content.items()) {
621
+ yield key;
622
+ }
623
+ }
624
+ function isNodeKey(data) {
625
+ const key = data;
626
+ return key.pathFromRoot !== undefined && key.type !== undefined;
627
+ }
628
+ function getChangeType(type) {
629
+ switch (type) {
630
+ case "add":
631
+ return SelectionChangeType.Add;
632
+ case "remove":
633
+ return SelectionChangeType.Remove;
634
+ case "replace":
635
+ return SelectionChangeType.Replace;
636
+ case "clear":
637
+ return SelectionChangeType.Clear;
638
+ }
639
+ }
420
640
  //# sourceMappingURL=SelectionManager.js.map