@itwin/presentation-frontend 4.5.0-dev.40 → 4.5.0-dev.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Change Log - @itwin/presentation-frontend
2
2
 
3
- This log was last generated on Mon, 25 Mar 2024 16:58:09 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 25 Mar 2024 22:23:34 GMT and should not be manually modified.
4
+
5
+ ## 4.4.8
6
+ Mon, 25 Mar 2024 22:22:26 GMT
7
+
8
+ _Version update only_
4
9
 
5
10
  ## 4.4.7
6
11
  Fri, 15 Mar 2024 19:15:14 GMT
@@ -13,7 +13,7 @@ export interface PresentationProps {
13
13
  /** Props for [[PresentationManager]]. */
14
14
  presentation?: PresentationManagerProps;
15
15
  /** Props for [[SelectionManager]]. */
16
- selection?: SelectionManagerProps;
16
+ selection?: Partial<SelectionManagerProps>;
17
17
  /** Props for [[FavoritePropertiesManager]]. */
18
18
  favorites?: FavoritePropertiesManagerProps;
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Presentation.d.ts","sourceRoot":"","sources":["../../../src/presentation-frontend/Presentation.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AAG5H,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAUvF;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,YAAY,CAAC,EAAE,wBAAwB,CAAC;IAExC,sCAAsC;IACtC,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAElC,+CAA+C;IAC/C,SAAS,CAAC,EAAE,8BAA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C,qBAAqB,CAAC,CAAC;IAE3C,+CAA+C;IAC/C,SAAS,CAAC,EAAE,8BAA8B,CAAC;CAC5C;AAED;;;;;;;;GAQG;AACH,qBAAa,YAAY;IAEvB,OAAO;IAEP;;;;;;;;;OASG;WACiB,UAAU,CAAC,KAAK,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA4CxE;;;OAGG;WACW,SAAS,IAAI,IAAI;IAyB/B;;;OAGG;WACW,6BAA6B,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI;IAIrF,4CAA4C;IAC5C,WAAkB,YAAY,IAAI,mBAAmB,CAKpD;IAED,gBAAgB;WACF,sBAAsB,CAAC,KAAK,EAAE,mBAAmB;IAO/D,yCAAyC;IACzC,WAAkB,SAAS,IAAI,gBAAgB,CAK9C;IAED,gBAAgB;WACF,mBAAmB,CAAC,KAAK,EAAE,gBAAgB;IAIzD;;;OAGG;IACH,WAAkB,kBAAkB,IAAI,yBAAyB,CAKhE;IAED,gBAAgB;WACF,4BAA4B,CAAC,KAAK,EAAE,yBAAyB;IAO3E;;OAEG;IACH,WAAkB,YAAY,IAAI,YAAY,CAK7C;IAED,gBAAgB;WACF,eAAe,CAAC,KAAK,EAAE,YAAY;CAGlD"}
@@ -60,11 +60,13 @@ class Presentation {
60
60
  presentationManager = PresentationManager_1.PresentationManager.create(managerProps);
61
61
  }
62
62
  if (!selectionManager) {
63
- selectionManager = new SelectionManager_1.SelectionManager(props?.selection ?? {
64
- scopes: new SelectionScopesManager_1.SelectionScopesManager({
65
- rpcRequestsHandler: presentationManager.rpcRequestsHandler,
66
- localeProvider: () => this.presentation.activeLocale,
67
- }),
63
+ selectionManager = new SelectionManager_1.SelectionManager({
64
+ ...props?.selection,
65
+ scopes: props?.selection?.scopes ??
66
+ new SelectionScopesManager_1.SelectionScopesManager({
67
+ rpcRequestsHandler: presentationManager.rpcRequestsHandler,
68
+ localeProvider: () => this.presentation.activeLocale,
69
+ }),
68
70
  });
69
71
  }
70
72
  if (!favoritePropertiesManager) {
@@ -100,6 +102,9 @@ class Presentation {
100
102
  favoritePropertiesManager.dispose();
101
103
  }
102
104
  favoritePropertiesManager = undefined;
105
+ if (selectionManager) {
106
+ selectionManager.dispose();
107
+ }
103
108
  selectionManager = undefined;
104
109
  localization = undefined;
105
110
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Presentation.js","sourceRoot":"","sources":["../../../src/presentation-frontend/Presentation.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,wDAAiD;AAEjD,oEAAmF;AACnF,+FAA4H;AAC5H,+FAAyI;AACzI,6DAAkE;AAClE,+DAAsF;AACtF,mEAAuF;AACvF,+EAA4E;AAE5E,IAAI,YAAsC,CAAC;AAC3C,IAAI,mBAAoD,CAAC;AACzD,IAAI,gBAA8C,CAAC;AACnD,IAAI,yBAAgE,CAAC;AACrE,MAAM,sBAAsB,GAA8C,EAAE,CAAC;AAC7E,MAAM,mBAAmB,GAAsB,EAAE,CAAC;AAiBlD;;;;;;;;GAQG;AACH,MAAa,YAAY;IACvB,0BAA0B;IAC1B,gBAAuB,CAAC;IAExB;;;;;;;;;OASG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,KAAyB;QACtD,IAAI,CAAC,yBAAS,CAAC,WAAW,EAAE;YAC1B,MAAM,IAAI,uCAAiB,CAAC,wCAAkB,CAAC,cAAc,EAAE,yEAAyE,CAAC,CAAC;SAC3I;QACD,IAAI,CAAC,YAAY,EAAE;YACjB,YAAY,GAAG,yBAAS,CAAC,YAAY,CAAC;SACvC;QACD,IAAI,CAAC,mBAAmB,EAAE;YACxB,MAAM,YAAY,GAAG,KAAK,EAAE,YAAY,IAAI,EAAE,CAAC;YAC/C,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;gBAC9B,MAAM,SAAS,GAAG,YAAY,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC;gBAC9D,YAAY,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C,IAAI,CAAC,yBAAyB,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;SACrG;QACD,OAAO,yBAAyB,CAAC;IACnC,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,4BAA4B,CAAC,KAAgC;QACzE,IAAI,yBAAyB,EAAE;YAC7B,yBAAyB,CAAC,OAAO,EAAE,CAAC;SACrC;QACD,yBAAyB,GAAG,KAAK,CAAC;IACpC,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,YAAY;QAC5B,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;SAC9F;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,eAAe,CAAC,KAAmB;QAC/C,YAAY,GAAG,KAAK,CAAC;IACvB,CAAC;CACF;AAzJD,oCAyJC","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 Core\n */\n\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { Localization } from \"@itwin/core-common\";\nimport { PresentationError, PresentationStatus } from \"@itwin/presentation-common\";\nimport { FavoritePropertiesManager, FavoritePropertiesManagerProps } from \"./favorite-properties/FavoritePropertiesManager\";\nimport { createFavoritePropertiesStorage, DefaultFavoritePropertiesStorageTypes } from \"./favorite-properties/FavoritePropertiesStorage\";\nimport { FrontendLocalizationHelper } from \"./LocalizationHelper\";\nimport { PresentationManager, PresentationManagerProps } from \"./PresentationManager\";\nimport { SelectionManager, SelectionManagerProps } from \"./selection/SelectionManager\";\nimport { SelectionScopesManager } from \"./selection/SelectionScopesManager\";\n\nlet localization: Localization | undefined;\nlet presentationManager: PresentationManager | undefined;\nlet selectionManager: SelectionManager | undefined;\nlet favoritePropertiesManager: FavoritePropertiesManager | undefined;\nconst initializationHandlers: Array<() => Promise<(() => void) | void>> = [];\nconst terminationHandlers: Array<() => void> = [];\n\n/**\n * Props for initializing [[Presentation]].\n * @public\n */\nexport interface PresentationProps {\n /** Props for [[PresentationManager]]. */\n presentation?: PresentationManagerProps;\n\n /** Props for [[SelectionManager]]. */\n selection?: SelectionManagerProps;\n\n /** Props for [[FavoritePropertiesManager]]. */\n favorites?: FavoritePropertiesManagerProps;\n}\n\n/**\n * Static class used to statically set up Presentation library for the frontend.\n * Basically what it does is:\n * - Create a singleton [[PresentationManager]] instance\n * - Create a singleton [[SelectionManager]] instance\n * - Create a singleton [[FavoritePropertiesManager]]] instance\n *\n * @public\n */\nexport class Presentation {\n /* istanbul ignore next */\n private constructor() {}\n\n /**\n * Initializes Presentation library for the frontend.\n *\n * Example:\n * ``` ts\n * [[include:Presentation.Frontend.Initialization]]\n * ```\n *\n * The method should be called after a call to [IModelApp.startup]($core-frontend).\n */\n public static async initialize(props?: PresentationProps): Promise<void> {\n if (!IModelApp.initialized) {\n throw new PresentationError(PresentationStatus.NotInitialized, \"IModelApp.startup must be called before calling Presentation.initialize\");\n }\n if (!localization) {\n localization = IModelApp.localization;\n }\n if (!presentationManager) {\n const managerProps = props?.presentation ?? {};\n if (!managerProps.activeLocale) {\n const languages = Presentation.localization.getLanguageList();\n managerProps.activeLocale = languages.length ? languages[0] : undefined;\n }\n presentationManager = PresentationManager.create(managerProps);\n }\n if (!selectionManager) {\n selectionManager = new SelectionManager(\n props?.selection ?? {\n scopes: new SelectionScopesManager({\n rpcRequestsHandler: presentationManager.rpcRequestsHandler,\n localeProvider: () => this.presentation.activeLocale,\n }),\n },\n );\n }\n if (!favoritePropertiesManager) {\n favoritePropertiesManager = new FavoritePropertiesManager({\n storage: props?.favorites ? props.favorites.storage : createFavoritePropertiesStorage(DefaultFavoritePropertiesStorageTypes.Noop),\n });\n }\n\n presentationManager.startIModelInitialization = (imodel) => favoritePropertiesManager?.startConnectionInitialization(imodel);\n presentationManager.ensureIModelInitialized = async (imodel) => favoritePropertiesManager?.ensureInitialized(imodel);\n\n await FrontendLocalizationHelper.registerNamespaces();\n for (const handler of initializationHandlers) {\n const cleanup = await handler();\n if (cleanup) {\n terminationHandlers.push(cleanup);\n }\n }\n }\n\n /**\n * Terminates Presentation library frontend. This method should be called\n * before a call to [IModelApp.shutdown]($core-frontend)\n */\n public static terminate(): void {\n terminationHandlers.forEach((handler) => handler());\n terminationHandlers.length = 0;\n\n if (localization) {\n FrontendLocalizationHelper.unregisterNamespaces();\n }\n\n if (presentationManager) {\n presentationManager.dispose();\n }\n presentationManager = undefined;\n\n if (favoritePropertiesManager) {\n favoritePropertiesManager.dispose();\n }\n favoritePropertiesManager = undefined;\n\n selectionManager = undefined;\n localization = undefined;\n }\n\n /**\n * Registers an additional handler which will be invoked during Presentation library frontend\n * initialization.\n */\n public static registerInitializationHandler(handler: () => Promise<() => void>): void {\n initializationHandlers.push(handler);\n }\n\n /** The singleton [[PresentationManager]] */\n public static get presentation(): PresentationManager {\n if (!presentationManager) {\n throw new Error(\"Presentation must be first initialized by calling Presentation.initialize\");\n }\n return presentationManager;\n }\n\n /** @internal */\n public static setPresentationManager(value: PresentationManager) {\n if (presentationManager) {\n presentationManager.dispose();\n }\n presentationManager = value;\n }\n\n /** The singleton [[SelectionManager]] */\n public static get selection(): SelectionManager {\n if (!selectionManager) {\n throw new Error(\"Presentation must be first initialized by calling Presentation.initialize\");\n }\n return selectionManager;\n }\n\n /** @internal */\n public static setSelectionManager(value: SelectionManager) {\n selectionManager = value;\n }\n\n /**\n * The singleton [[FavoritePropertiesManager]]\n * @public\n */\n public static get favoriteProperties(): FavoritePropertiesManager {\n if (!favoritePropertiesManager) {\n throw new Error(\"Favorite Properties must be first initialized by calling Presentation.initialize\");\n }\n return favoritePropertiesManager;\n }\n\n /** @internal */\n public static setFavoritePropertiesManager(value: FavoritePropertiesManager) {\n if (favoritePropertiesManager) {\n favoritePropertiesManager.dispose();\n }\n favoritePropertiesManager = value;\n }\n\n /**\n * The localization manager used by Presentation frontend. Returns the result of `IModelApp.i18n`.\n */\n public static get localization(): Localization {\n if (!localization) {\n throw new Error(\"Presentation must be first initialized by calling Presentation.initialize\");\n }\n return localization;\n }\n\n /** @internal */\n public static setLocalization(value: Localization) {\n localization = value;\n }\n}\n"]}
1
+ {"version":3,"file":"Presentation.js","sourceRoot":"","sources":["../../../src/presentation-frontend/Presentation.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,wDAAiD;AAEjD,oEAAmF;AACnF,+FAA4H;AAC5H,+FAAyI;AACzI,6DAAkE;AAClE,+DAAsF;AACtF,mEAAuF;AACvF,+EAA4E;AAE5E,IAAI,YAAsC,CAAC;AAC3C,IAAI,mBAAoD,CAAC;AACzD,IAAI,gBAA8C,CAAC;AACnD,IAAI,yBAAgE,CAAC;AACrE,MAAM,sBAAsB,GAA8C,EAAE,CAAC;AAC7E,MAAM,mBAAmB,GAAsB,EAAE,CAAC;AAiBlD;;;;;;;;GAQG;AACH,MAAa,YAAY;IACvB,0BAA0B;IAC1B,gBAAuB,CAAC;IAExB;;;;;;;;;OASG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,KAAyB;QACtD,IAAI,CAAC,yBAAS,CAAC,WAAW,EAAE;YAC1B,MAAM,IAAI,uCAAiB,CAAC,wCAAkB,CAAC,cAAc,EAAE,yEAAyE,CAAC,CAAC;SAC3I;QACD,IAAI,CAAC,YAAY,EAAE;YACjB,YAAY,GAAG,yBAAS,CAAC,YAAY,CAAC;SACvC;QACD,IAAI,CAAC,mBAAmB,EAAE;YACxB,MAAM,YAAY,GAAG,KAAK,EAAE,YAAY,IAAI,EAAE,CAAC;YAC/C,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;gBAC9B,MAAM,SAAS,GAAG,YAAY,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC;gBAC9D,YAAY,CAAC,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAA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AAK,CAAC;IAC3B,CAAC;IAED;;;OAGG;IACI,MAAM,KAAK,kBAAkB;QAClC,IAAI,CAAC,yBAAyB,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;SACrG;QACD,OAAO,yBAAyB,CAAC;IACnC,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,4BAA4B,CAAC,KAAgC;QACzE,IAAI,yBAAyB,EAAE;YAC7B,yBAAyB,CAAC,OAAO,EAAE,CAAC;SACrC;QACD,yBAAyB,GAAG,KAAK,CAAC;IACpC,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,YAAY;QAC5B,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;SAC9F;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,eAAe,CAAC,KAAmB;QAC/C,YAAY,GAAG,KAAK,CAAC;IACvB,CAAC;CACF;AA7JD,oCA6JC","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 Core\n */\n\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { Localization } from \"@itwin/core-common\";\nimport { PresentationError, PresentationStatus } from \"@itwin/presentation-common\";\nimport { FavoritePropertiesManager, FavoritePropertiesManagerProps } from \"./favorite-properties/FavoritePropertiesManager\";\nimport { createFavoritePropertiesStorage, DefaultFavoritePropertiesStorageTypes } from \"./favorite-properties/FavoritePropertiesStorage\";\nimport { FrontendLocalizationHelper } from \"./LocalizationHelper\";\nimport { PresentationManager, PresentationManagerProps } from \"./PresentationManager\";\nimport { SelectionManager, SelectionManagerProps } from \"./selection/SelectionManager\";\nimport { SelectionScopesManager } from \"./selection/SelectionScopesManager\";\n\nlet localization: Localization | undefined;\nlet presentationManager: PresentationManager | undefined;\nlet selectionManager: SelectionManager | undefined;\nlet favoritePropertiesManager: FavoritePropertiesManager | undefined;\nconst initializationHandlers: Array<() => Promise<(() => void) | void>> = [];\nconst terminationHandlers: Array<() => void> = [];\n\n/**\n * Props for initializing [[Presentation]].\n * @public\n */\nexport interface PresentationProps {\n /** Props for [[PresentationManager]]. */\n presentation?: PresentationManagerProps;\n\n /** Props for [[SelectionManager]]. */\n selection?: Partial<SelectionManagerProps>;\n\n /** Props for [[FavoritePropertiesManager]]. */\n favorites?: FavoritePropertiesManagerProps;\n}\n\n/**\n * Static class used to statically set up Presentation library for the frontend.\n * Basically what it does is:\n * - Create a singleton [[PresentationManager]] instance\n * - Create a singleton [[SelectionManager]] instance\n * - Create a singleton [[FavoritePropertiesManager]]] instance\n *\n * @public\n */\nexport class Presentation {\n /* istanbul ignore next */\n private constructor() {}\n\n /**\n * Initializes Presentation library for the frontend.\n *\n * Example:\n * ``` ts\n * [[include:Presentation.Frontend.Initialization]]\n * ```\n *\n * The method should be called after a call to [IModelApp.startup]($core-frontend).\n */\n public static async initialize(props?: PresentationProps): Promise<void> {\n if (!IModelApp.initialized) {\n throw new PresentationError(PresentationStatus.NotInitialized, \"IModelApp.startup must be called before calling Presentation.initialize\");\n }\n if (!localization) {\n localization = IModelApp.localization;\n }\n if (!presentationManager) {\n const managerProps = props?.presentation ?? {};\n if (!managerProps.activeLocale) {\n const languages = Presentation.localization.getLanguageList();\n managerProps.activeLocale = languages.length ? languages[0] : undefined;\n }\n presentationManager = PresentationManager.create(managerProps);\n }\n if (!selectionManager) {\n selectionManager = new SelectionManager({\n ...props?.selection,\n scopes:\n props?.selection?.scopes ??\n new SelectionScopesManager({\n rpcRequestsHandler: presentationManager.rpcRequestsHandler,\n localeProvider: () => this.presentation.activeLocale,\n }),\n });\n }\n if (!favoritePropertiesManager) {\n favoritePropertiesManager = new FavoritePropertiesManager({\n storage: props?.favorites ? props.favorites.storage : createFavoritePropertiesStorage(DefaultFavoritePropertiesStorageTypes.Noop),\n });\n }\n\n presentationManager.startIModelInitialization = (imodel) => favoritePropertiesManager?.startConnectionInitialization(imodel);\n presentationManager.ensureIModelInitialized = async (imodel) => favoritePropertiesManager?.ensureInitialized(imodel);\n\n await FrontendLocalizationHelper.registerNamespaces();\n for (const handler of initializationHandlers) {\n const cleanup = await handler();\n if (cleanup) {\n terminationHandlers.push(cleanup);\n }\n }\n }\n\n /**\n * Terminates Presentation library frontend. This method should be called\n * before a call to [IModelApp.shutdown]($core-frontend)\n */\n public static terminate(): void {\n terminationHandlers.forEach((handler) => handler());\n terminationHandlers.length = 0;\n\n if (localization) {\n FrontendLocalizationHelper.unregisterNamespaces();\n }\n\n if (presentationManager) {\n presentationManager.dispose();\n }\n presentationManager = undefined;\n\n if (favoritePropertiesManager) {\n favoritePropertiesManager.dispose();\n }\n favoritePropertiesManager = undefined;\n\n if (selectionManager) {\n selectionManager.dispose();\n }\n selectionManager = undefined;\n localization = undefined;\n }\n\n /**\n * Registers an additional handler which will be invoked during Presentation library frontend\n * initialization.\n */\n public static registerInitializationHandler(handler: () => Promise<() => void>): void {\n initializationHandlers.push(handler);\n }\n\n /** The singleton [[PresentationManager]] */\n public static get presentation(): PresentationManager {\n if (!presentationManager) {\n throw new Error(\"Presentation must be first initialized by calling Presentation.initialize\");\n }\n return presentationManager;\n }\n\n /** @internal */\n public static setPresentationManager(value: PresentationManager) {\n if (presentationManager) {\n presentationManager.dispose();\n }\n presentationManager = value;\n }\n\n /** The singleton [[SelectionManager]] */\n public static get selection(): SelectionManager {\n if (!selectionManager) {\n throw new Error(\"Presentation must be first initialized by calling Presentation.initialize\");\n }\n return selectionManager;\n }\n\n /** @internal */\n public static setSelectionManager(value: SelectionManager) {\n selectionManager = value;\n }\n\n /**\n * The singleton [[FavoritePropertiesManager]]\n * @public\n */\n public static get favoriteProperties(): FavoritePropertiesManager {\n if (!favoritePropertiesManager) {\n throw new Error(\"Favorite Properties must be first initialized by calling Presentation.initialize\");\n }\n return favoritePropertiesManager;\n }\n\n /** @internal */\n public static setFavoritePropertiesManager(value: FavoritePropertiesManager) {\n if (favoritePropertiesManager) {\n favoritePropertiesManager.dispose();\n }\n favoritePropertiesManager = value;\n }\n\n /**\n * The localization manager used by Presentation frontend. Returns the result of `IModelApp.i18n`.\n */\n public static get localization(): Localization {\n if (!localization) {\n throw new Error(\"Presentation must be first initialized by calling Presentation.initialize\");\n }\n return localization;\n }\n\n /** @internal */\n public static setLocalization(value: Localization) {\n localization = value;\n }\n}\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;A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O,CAAC,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"}
@@ -8,9 +8,12 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.ToolSelectionSyncHandler = exports.TRANSIENT_ELEMENT_CLASSNAME = exports.SelectionManager = void 0;
11
+ const rxjs_1 = require("rxjs");
11
12
  const core_bentley_1 = require("@itwin/core-bentley");
12
13
  const core_frontend_1 = require("@itwin/core-frontend");
13
14
  const presentation_common_1 = require("@itwin/presentation-common");
15
+ const unified_selection_1 = require("@itwin/unified-selection");
16
+ const Presentation_1 = require("../Presentation");
14
17
  const HiliteSetProvider_1 = require("./HiliteSetProvider");
15
18
  const SelectionChangeEvent_1 = require("./SelectionChangeEvent");
16
19
  const SelectionScopesManager_1 = require("./SelectionScopesManager");
@@ -23,27 +26,37 @@ class SelectionManager {
23
26
  * Creates an instance of SelectionManager.
24
27
  */
25
28
  constructor(props) {
26
- this._selectionContainerMap = new Map();
27
29
  this._imodelToolSelectionSyncHandlers = new Map();
28
30
  this._hiliteSetProviders = new Map();
31
+ this._knownIModels = new Map();
32
+ this._currentSelection = new CurrentSelectionStorage();
33
+ this._selectionChanges = new rxjs_1.Subject();
34
+ this._listeners = [];
29
35
  this.selectionChange = new SelectionChangeEvent_1.SelectionChangeEvent();
30
36
  this.scopes = props.scopes;
31
- core_frontend_1.IModelConnection.onClose.addListener((imodel) => {
37
+ this._selectionStorage = props.selectionStorage ?? (0, unified_selection_1.createStorage)();
38
+ this._ownsStorage = props.selectionStorage === undefined;
39
+ this._selectionStorage.selectionChangeEvent.addListener((args) => this._selectionChanges.next(args));
40
+ this._selectionEventsSubscription = this.streamSelectionEvents();
41
+ this._listeners.push(core_frontend_1.IModelConnection.onOpen.addListener((imodel) => {
42
+ this._knownIModels.set(imodel.key, imodel);
43
+ }));
44
+ this._listeners.push(core_frontend_1.IModelConnection.onClose.addListener((imodel) => {
32
45
  this.onConnectionClose(imodel);
33
- });
46
+ }));
47
+ }
48
+ dispose() {
49
+ this._selectionEventsSubscription.unsubscribe();
50
+ this._listeners.forEach((dispose) => dispose());
34
51
  }
35
52
  onConnectionClose(imodel) {
36
- this.clearSelection("Connection Close Event", imodel);
37
- this._selectionContainerMap.delete(imodel);
38
53
  this._hiliteSetProviders.delete(imodel);
39
- }
40
- getContainer(imodel) {
41
- let selectionContainer = this._selectionContainerMap.get(imodel);
42
- if (!selectionContainer) {
43
- selectionContainer = new SelectionContainer();
44
- this._selectionContainerMap.set(imodel, selectionContainer);
54
+ this._knownIModels.delete(imodel.key);
55
+ this._currentSelection.clear(imodel.key);
56
+ if (this._ownsStorage) {
57
+ this.clearSelection("Connection Close Event", imodel);
58
+ this._selectionStorage.clearStorage({ iModelKey: imodel.key });
45
59
  }
46
- return selectionContainer;
47
60
  }
48
61
  /** @internal */
49
62
  // istanbul ignore next
@@ -91,39 +104,48 @@ class SelectionManager {
91
104
  }
92
105
  /** Get the selection levels currently stored in this manager for the specified imodel */
93
106
  getSelectionLevels(imodel) {
94
- return this.getContainer(imodel).getSelectionLevels();
107
+ return this._selectionStorage.getSelectionLevels({ iModelKey: imodel.key });
95
108
  }
96
- /** Get the selection currently stored in this manager */
109
+ /**
110
+ * Get the selection currently stored in this manager
111
+ *
112
+ * @note Calling immediately after `add*`|`replace*`|`remove*`|`clear*` method call does not guarantee
113
+ * that returned `KeySet` will include latest changes. Listen for `selectionChange` event to get the
114
+ * latest selection after changes.
115
+ */
97
116
  getSelection(imodel, level = 0) {
98
- return this.getContainer(imodel).getSelection(level);
117
+ return this._currentSelection.getSelection(imodel.key, level);
99
118
  }
100
119
  handleEvent(evt) {
101
- const container = this.getContainer(evt.imodel);
102
- const selectedItemsSet = container.getSelection(evt.level);
103
- const guidBefore = selectedItemsSet.guid;
104
120
  switch (evt.changeType) {
105
121
  case SelectionChangeEvent_1.SelectionChangeType.Add:
106
- selectedItemsSet.add(evt.keys);
122
+ this._selectionStorage.addToSelection({
123
+ iModelKey: evt.imodel.key,
124
+ source: evt.source,
125
+ level: evt.level,
126
+ selectables: keysToSelectable(evt.imodel, evt.keys),
127
+ });
107
128
  break;
108
129
  case SelectionChangeEvent_1.SelectionChangeType.Remove:
109
- selectedItemsSet.delete(evt.keys);
130
+ this._selectionStorage.removeFromSelection({
131
+ iModelKey: evt.imodel.key,
132
+ source: evt.source,
133
+ level: evt.level,
134
+ selectables: keysToSelectable(evt.imodel, evt.keys),
135
+ });
110
136
  break;
111
137
  case SelectionChangeEvent_1.SelectionChangeType.Replace:
112
- if (selectedItemsSet.size !== evt.keys.size || !selectedItemsSet.hasAll(evt.keys)) {
113
- // note: the above check is only needed to avoid changing
114
- // guid of the keyset if we're replacing keyset with the same keys
115
- selectedItemsSet.clear().add(evt.keys);
116
- }
138
+ this._selectionStorage.replaceSelection({
139
+ iModelKey: evt.imodel.key,
140
+ source: evt.source,
141
+ level: evt.level,
142
+ selectables: keysToSelectable(evt.imodel, evt.keys),
143
+ });
117
144
  break;
118
145
  case SelectionChangeEvent_1.SelectionChangeType.Clear:
119
- selectedItemsSet.clear();
146
+ this._selectionStorage.clearSelection({ iModelKey: evt.imodel.key, source: evt.source, level: evt.level });
120
147
  break;
121
148
  }
122
- if (selectedItemsSet.guid === guidBefore) {
123
- return;
124
- }
125
- container.clear(evt.level + 1);
126
- this.selectionChange.raiseEvent(evt, this);
127
149
  }
128
150
  /**
129
151
  * Add keys to the selection
@@ -265,40 +287,33 @@ class SelectionManager {
265
287
  }
266
288
  return provider;
267
289
  }
268
- }
269
- exports.SelectionManager = SelectionManager;
270
- /** @internal */
271
- class SelectionContainer {
272
- constructor() {
273
- this._selectedItemsSetMap = new Map();
274
- }
275
- getSelection(level) {
276
- let selectedItemsSet = this._selectedItemsSetMap.get(level);
277
- if (!selectedItemsSet) {
278
- selectedItemsSet = new presentation_common_1.KeySet();
279
- this._selectedItemsSetMap.set(level, selectedItemsSet);
280
- }
281
- return selectedItemsSet;
282
- }
283
- getSelectionLevels() {
284
- const levels = new Array();
285
- for (const entry of this._selectedItemsSetMap.entries()) {
286
- if (!entry[1].isEmpty) {
287
- levels.push(entry[0]);
288
- }
289
- }
290
- return levels.sort();
291
- }
292
- clear(level) {
293
- const keys = this._selectedItemsSetMap.keys();
294
- for (const key of keys) {
295
- if (key >= level) {
296
- const selectedItemsSet = this._selectedItemsSetMap.get(key);
297
- selectedItemsSet.clear();
298
- }
299
- }
290
+ streamSelectionEvents() {
291
+ return this._selectionChanges
292
+ .pipe((0, rxjs_1.mergeMap)((args) => {
293
+ const currentSelectables = this._selectionStorage.getSelection({ iModelKey: args.iModelKey, level: args.level });
294
+ return this._currentSelection.computeSelection(args.iModelKey, args.level, currentSelectables, args.selectables).pipe((0, rxjs_1.mergeMap)(({ level, changedSelection }) => {
295
+ const imodel = this._knownIModels.get(args.iModelKey);
296
+ if (!imodel) {
297
+ return rxjs_1.EMPTY;
298
+ }
299
+ return (0, rxjs_1.of)({
300
+ imodel,
301
+ keys: changedSelection,
302
+ level,
303
+ source: args.source,
304
+ timestamp: args.timestamp,
305
+ changeType: getChangeType(args.changeType),
306
+ });
307
+ }));
308
+ }))
309
+ .subscribe({
310
+ next: (args) => {
311
+ this.selectionChange.raiseEvent(args, this);
312
+ },
313
+ });
300
314
  }
301
315
  }
316
+ exports.SelectionManager = SelectionManager;
302
317
  /** @internal */
303
318
  exports.TRANSIENT_ELEMENT_CLASSNAME = "/TRANSIENT";
304
319
  /** @internal */
@@ -437,4 +452,194 @@ class ScopedSelectionChanger {
437
452
  this.manager.replaceSelection(this.name, this.imodel, keys, level);
438
453
  }
439
454
  }
455
+ /** Stores current selection in `KeySet` format per iModel. */
456
+ class CurrentSelectionStorage {
457
+ constructor() {
458
+ this._currentSelection = new Map();
459
+ }
460
+ getCurrentSelectionStorage(imodelKey) {
461
+ let storage = this._currentSelection.get(imodelKey);
462
+ if (!storage) {
463
+ storage = new IModelSelectionStorage();
464
+ this._currentSelection.set(imodelKey, storage);
465
+ }
466
+ return storage;
467
+ }
468
+ getSelection(imodelKey, level) {
469
+ return this.getCurrentSelectionStorage(imodelKey).getSelection(level);
470
+ }
471
+ clear(imodelKey) {
472
+ this._currentSelection.delete(imodelKey);
473
+ }
474
+ computeSelection(imodelKey, level, currSelectables, changedSelectables) {
475
+ return this.getCurrentSelectionStorage(imodelKey).computeSelection(level, currSelectables, changedSelectables);
476
+ }
477
+ }
478
+ /**
479
+ * Computes and stores current selection in `KeySet` format.
480
+ * It always stores result of latest resolved call to `computeSelection`.
481
+ */
482
+ class IModelSelectionStorage {
483
+ constructor() {
484
+ this._currentSelection = new Map();
485
+ }
486
+ getSelection(level) {
487
+ let entry = this._currentSelection.get(level);
488
+ if (!entry) {
489
+ entry = { value: new presentation_common_1.KeySet(), ongoingComputationDisposers: new Set() };
490
+ this._currentSelection.set(level, entry);
491
+ }
492
+ return entry.value;
493
+ }
494
+ clearSelections(level) {
495
+ const clearedLevels = [];
496
+ for (const [storedLevel] of this._currentSelection.entries()) {
497
+ if (storedLevel > level) {
498
+ clearedLevels.push(storedLevel);
499
+ }
500
+ }
501
+ clearedLevels.forEach((storedLevel) => {
502
+ const entry = this._currentSelection.get(storedLevel);
503
+ // istanbul ignore if
504
+ if (!entry) {
505
+ return;
506
+ }
507
+ for (const disposer of entry.ongoingComputationDisposers) {
508
+ disposer.next();
509
+ }
510
+ this._currentSelection.delete(storedLevel);
511
+ });
512
+ }
513
+ addDisposer(level, disposer) {
514
+ const entry = this._currentSelection.get(level);
515
+ if (!entry) {
516
+ this._currentSelection.set(level, { value: new presentation_common_1.KeySet(), ongoingComputationDisposers: new Set([disposer]) });
517
+ return;
518
+ }
519
+ entry.ongoingComputationDisposers.add(disposer);
520
+ }
521
+ setSelection(level, keys, disposer) {
522
+ const currEntry = this._currentSelection.get(level);
523
+ // istanbul ignore else
524
+ if (currEntry) {
525
+ currEntry.ongoingComputationDisposers.delete(disposer);
526
+ }
527
+ this._currentSelection.set(level, {
528
+ value: keys,
529
+ ongoingComputationDisposers: currEntry?.ongoingComputationDisposers ?? /* istanbul ignore next */ new Set(),
530
+ });
531
+ }
532
+ computeSelection(level, currSelectables, changedSelectables) {
533
+ this.clearSelections(level);
534
+ const prevComputationsDisposers = [...(this._currentSelection.get(level)?.ongoingComputationDisposers ?? [])];
535
+ const currDisposer = new rxjs_1.Subject();
536
+ this.addDisposer(level, currDisposer);
537
+ return (0, rxjs_1.defer)(async () => {
538
+ const convertedSelectables = [];
539
+ const [current, changed] = await Promise.all([
540
+ selectablesToKeys(currSelectables, convertedSelectables),
541
+ selectablesToKeys(changedSelectables, convertedSelectables),
542
+ ]);
543
+ const currentSelection = new presentation_common_1.KeySet([...current.keys, ...current.selectableKeys.flatMap((selectable) => selectable.keys)]);
544
+ const changedSelection = new presentation_common_1.KeySet([...changed.keys, ...changed.selectableKeys.flatMap((selectable) => selectable.keys)]);
545
+ return {
546
+ level,
547
+ currentSelection,
548
+ changedSelection,
549
+ };
550
+ }).pipe((0, rxjs_1.takeUntil)(currDisposer), (0, rxjs_1.tap)({
551
+ next: (val) => {
552
+ prevComputationsDisposers.forEach((disposer) => disposer.next());
553
+ this.setSelection(val.level, val.currentSelection, currDisposer);
554
+ },
555
+ }));
556
+ }
557
+ }
558
+ function keysToSelectable(imodel, keys) {
559
+ const selectables = [];
560
+ keys.forEach((key) => {
561
+ if ("id" in key) {
562
+ selectables.push(key);
563
+ return;
564
+ }
565
+ const customSelectable = {
566
+ identifier: key.pathFromRoot.join("/"),
567
+ data: key,
568
+ loadInstanceKeys: () => createInstanceKeysIterator(imodel, key),
569
+ };
570
+ selectables.push(customSelectable);
571
+ });
572
+ return selectables;
573
+ }
574
+ async function selectablesToKeys(selectables, convertedList) {
575
+ const keys = [];
576
+ const selectableKeys = [];
577
+ for (const [className, ids] of selectables.instanceKeys) {
578
+ for (const id of ids) {
579
+ keys.push({ id, className });
580
+ }
581
+ }
582
+ for (const [_, selectable] of selectables.custom) {
583
+ if (isNodeKey(selectable.data)) {
584
+ selectableKeys.push({ identifier: selectable.identifier, keys: [selectable.data] });
585
+ continue;
586
+ }
587
+ const converted = convertedList.find((con) => con.identifier === selectable.identifier);
588
+ if (converted) {
589
+ selectableKeys.push(converted);
590
+ continue;
591
+ }
592
+ const newConverted = { identifier: selectable.identifier, keys: [] };
593
+ convertedList.push(newConverted);
594
+ for await (const instanceKey of selectable.loadInstanceKeys()) {
595
+ newConverted.keys.push(instanceKey);
596
+ }
597
+ selectableKeys.push(newConverted);
598
+ }
599
+ return { keys, selectableKeys };
600
+ }
601
+ async function* createInstanceKeysIterator(imodel, nodeKey) {
602
+ if (presentation_common_1.NodeKey.isInstancesNodeKey(nodeKey)) {
603
+ for (const key of nodeKey.instanceKeys) {
604
+ yield key;
605
+ }
606
+ return;
607
+ }
608
+ const content = await Presentation_1.Presentation.presentation.getContentInstanceKeys({
609
+ imodel,
610
+ keys: new presentation_common_1.KeySet([nodeKey]),
611
+ rulesetOrId: {
612
+ id: "grouped-instances",
613
+ rules: [
614
+ {
615
+ ruleType: "Content",
616
+ specifications: [
617
+ {
618
+ specType: "SelectedNodeInstances",
619
+ },
620
+ ],
621
+ },
622
+ ],
623
+ },
624
+ });
625
+ for await (const key of content.items()) {
626
+ yield key;
627
+ }
628
+ }
629
+ function isNodeKey(data) {
630
+ const key = data;
631
+ return key.pathFromRoot !== undefined && key.type !== undefined;
632
+ }
633
+ function getChangeType(type) {
634
+ switch (type) {
635
+ case "add":
636
+ return SelectionChangeEvent_1.SelectionChangeType.Add;
637
+ case "remove":
638
+ return SelectionChangeEvent_1.SelectionChangeType.Remove;
639
+ case "replace":
640
+ return SelectionChangeEvent_1.SelectionChangeType.Replace;
641
+ case "clear":
642
+ return SelectionChangeEvent_1.SelectionChangeType.Clear;
643
+ }
644
+ }
440
645
  //# sourceMappingURL=SelectionManager.js.map