@itwin/presentation-frontend 5.0.0-dev.55 → 5.0.0-dev.57

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 (53) hide show
  1. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +10 -8
  2. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  3. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +2 -1
  4. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  5. package/lib/cjs/presentation-frontend/LocalizationHelper.js +1 -0
  6. package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
  7. package/lib/cjs/presentation-frontend/PresentationManager.js +21 -12
  8. package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
  9. package/lib/cjs/presentation-frontend/RulesetManager.js +2 -4
  10. package/lib/cjs/presentation-frontend/RulesetManager.js.map +1 -1
  11. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +4 -2
  12. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  13. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.js +1 -0
  14. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.js.map +1 -1
  15. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +128 -120
  16. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  17. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +19 -15
  18. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  19. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +2 -0
  20. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  21. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +27 -12
  22. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  23. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +86 -70
  24. package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
  25. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +3 -0
  26. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  27. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +10 -8
  28. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  29. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +2 -1
  30. package/lib/esm/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  31. package/lib/esm/presentation-frontend/LocalizationHelper.js +1 -0
  32. package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
  33. package/lib/esm/presentation-frontend/PresentationManager.js +21 -12
  34. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  35. package/lib/esm/presentation-frontend/RulesetManager.js +2 -4
  36. package/lib/esm/presentation-frontend/RulesetManager.js.map +1 -1
  37. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +4 -2
  38. package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  39. package/lib/esm/presentation-frontend/StreamedResponseGenerator.js +1 -0
  40. package/lib/esm/presentation-frontend/StreamedResponseGenerator.js.map +1 -1
  41. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +128 -120
  42. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  43. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +19 -15
  44. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  45. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +2 -0
  46. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  47. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +27 -12
  48. package/lib/esm/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  49. package/lib/esm/presentation-frontend/selection/SelectionManager.js +86 -70
  50. package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
  51. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +3 -0
  52. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  53. package/package.json +17 -16
@@ -137,22 +137,11 @@ class IModelAppFavoritePropertiesStorage {
137
137
  exports.IModelAppFavoritePropertiesStorage = IModelAppFavoritePropertiesStorage;
138
138
  /** @internal */
139
139
  class OfflineCachingFavoritePropertiesStorage {
140
+ _connectivityInfo;
141
+ _impl;
142
+ _propertiesOfflineCache = new DictionaryWithReservations(iTwinAndIModelIdsKeyComparer);
143
+ _propertiesOrderOfflineCache = new DictionaryWithReservations(iTwinAndIModelIdsKeyComparer);
140
144
  constructor(props) {
141
- this._propertiesOfflineCache = new DictionaryWithReservations(iTwinAndIModelIdsKeyComparer);
142
- this._propertiesOrderOfflineCache = new DictionaryWithReservations(iTwinAndIModelIdsKeyComparer);
143
- this.onConnectivityStatusChanged = (args) => {
144
- // istanbul ignore else
145
- if (args.status === core_common_1.InternetConnectivityStatus.Online) {
146
- // note: we're copying the cached values to temp arrays because `saveProperties` and `savePropertiesOrder` both
147
- // attempt to modify cache dictionaries
148
- const propertiesCache = new Array();
149
- this._propertiesOfflineCache.forEach((key, value) => propertiesCache.push({ properties: value, iTwinId: key[0], imodelId: key[1] }));
150
- propertiesCache.forEach(async (cached) => this.saveProperties(cached.properties, cached.iTwinId, cached.imodelId));
151
- const ordersCache = new Array();
152
- this._propertiesOrderOfflineCache.forEach((key, value) => ordersCache.push({ order: value, iTwinId: key[0], imodelId: key[1] }));
153
- ordersCache.forEach(async (cached) => this.savePropertiesOrder(cached.order, cached.iTwinId, cached.imodelId));
154
- }
155
- };
156
145
  this._impl = props.impl;
157
146
  // istanbul ignore next
158
147
  this._connectivityInfo = props.connectivityInfo ?? new ConnectivityInformationProvider_1.ConnectivityInformationProvider();
@@ -164,6 +153,19 @@ class OfflineCachingFavoritePropertiesStorage {
164
153
  get impl() {
165
154
  return this._impl;
166
155
  }
156
+ onConnectivityStatusChanged = (args) => {
157
+ // istanbul ignore else
158
+ if (args.status === core_common_1.InternetConnectivityStatus.Online) {
159
+ // note: we're copying the cached values to temp arrays because `saveProperties` and `savePropertiesOrder` both
160
+ // attempt to modify cache dictionaries
161
+ const propertiesCache = new Array();
162
+ this._propertiesOfflineCache.forEach((key, value) => propertiesCache.push({ properties: value, iTwinId: key[0], imodelId: key[1] }));
163
+ propertiesCache.forEach(async (cached) => this.saveProperties(cached.properties, cached.iTwinId, cached.imodelId));
164
+ const ordersCache = new Array();
165
+ this._propertiesOrderOfflineCache.forEach((key, value) => ordersCache.push({ order: value, iTwinId: key[0], imodelId: key[1] }));
166
+ ordersCache.forEach(async (cached) => this.savePropertiesOrder(cached.order, cached.iTwinId, cached.imodelId));
167
+ }
168
+ };
167
169
  async loadProperties(iTwinId, imodelId) {
168
170
  if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Online) {
169
171
  try {
@@ -219,6 +221,7 @@ class OfflineCachingFavoritePropertiesStorage {
219
221
  }
220
222
  exports.OfflineCachingFavoritePropertiesStorage = OfflineCachingFavoritePropertiesStorage;
221
223
  class DictionaryWithReservations {
224
+ _impl;
222
225
  constructor(compareKeys) {
223
226
  this._impl = new core_bentley_1.Dictionary(compareKeys);
224
227
  }
@@ -277,6 +280,7 @@ class NoopFavoritePropertiesStorage {
277
280
  exports.NoopFavoritePropertiesStorage = NoopFavoritePropertiesStorage;
278
281
  /** @internal */
279
282
  class BrowserLocalFavoritePropertiesStorage {
283
+ _localStorage;
280
284
  constructor(props) {
281
285
  // istanbul ignore next
282
286
  this._localStorage = props?.localStorage ?? window.localStorage;
@@ -1 +1 @@
1
- {"version":3,"file":"FavoritePropertiesStorage.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/favorite-properties/FavoritePropertiesStorage.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAkEH,0EASC;AAzED,sDAAqH;A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OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IACrH,CAAC;IAEM,KAAK,CAAC,mBAAmB,CAAC,OAA2B,EAAE,QAAgB;QAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC5F,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,UAAU,GAAkC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,CAAC;YACtF,GAAG,IAAI;YACP,gBAAgB,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC;SAClD,CAAC,CAAC,CAAC;QACJ,OAAO,UAAU,CAAC;IACpB,CAAC;IAEM,KAAK,CAAC,mBAAmB,CAAC,UAAyC,EAAE,OAA2B,EAAE,QAAgB;QACvH,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5G,CAAC;CACF;AA7CD,sFA6CC","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 { AccessToken, compareStrings, Dictionary, Guid, isDisposable, OrderedComparator } from \"@itwin/core-bentley\";\nimport { InternetConnectivityStatus } from \"@itwin/core-common\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { PresentationError, PresentationStatus } from \"@itwin/presentation-common\";\nimport { ConnectivityInformationProvider, IConnectivityInformationProvider } from \"../ConnectivityInformationProvider\";\nimport { FavoritePropertiesOrderInfo, PropertyFullName } from \"./FavoritePropertiesManager\";\n\n/** @internal */\nexport const IMODELJS_PRESENTATION_SETTING_NAMESPACE = \"imodeljs.presentation\";\n/** @internal */\nexport const DEPRECATED_PROPERTIES_SETTING_NAMESPACE = \"Properties\";\n/** @internal */\nexport const FAVORITE_PROPERTIES_SETTING_NAME = \"FavoriteProperties\";\n/** @internal */\nexport const FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME = \"FavoritePropertiesOrderInfo\";\n\n/**\n * Stores user preferences for favorite properties.\n * @public\n */\nexport interface IFavoritePropertiesStorage {\n /** Load Favorite properties from user-specific settings.\n * @param iTwinId ITwin Id, if the settings is specific to a iTwin, otherwise undefined.\n * @param imodelId iModel Id, if the setting is specific to an iModel, otherwise undefined. The iTwinId must be specified if iModelId is specified.\n */\n loadProperties(iTwinId?: string, imodelId?: string): Promise<Set<PropertyFullName> | undefined>;\n /** Saves Favorite properties to user-specific settings.\n * @param properties Favorite properties to save.\n * @param iTwinId iTwin Id, if the settings is specific to a iTwin, otherwise undefined.\n * @param iModelId iModel Id, if the setting is specific to an iModel, otherwise undefined. The iTwinId must be specified if iModelId is specified.\n */\n saveProperties(properties: Set<PropertyFullName>, iTwinId?: string, imodelId?: string): Promise<void>;\n /** Load array of FavoritePropertiesOrderInfo from user-specific settings.\n * Setting is specific to an iModel.\n * @param iTwinId iTwin Id.\n * @param imodelId iModel Id.\n */\n loadPropertiesOrder(iTwinId: string | undefined, imodelId: string): Promise<FavoritePropertiesOrderInfo[] | undefined>;\n /** Saves FavoritePropertiesOrderInfo array to user-specific settings.\n * Setting is specific to an iModel.\n * @param orderInfo Array of FavoritePropertiesOrderInfo to save.\n * @param iTwinId iTwin Id.\n * @param imodelId iModel Id.\n */\n savePropertiesOrder(orderInfos: FavoritePropertiesOrderInfo[], iTwinId: string | undefined, imodelId: string): Promise<void>;\n}\n\n/**\n * Available implementations of [[IFavoritePropertiesStorage]].\n * @public\n */\nexport enum DefaultFavoritePropertiesStorageTypes {\n /** A no-op storage that doesn't store or return anything. Used for cases when favorite properties aren't used by the application. */\n Noop,\n /** A storage that stores favorite properties information in a browser local storage. */\n BrowserLocalStorage,\n /** A storage that stores favorite properties in a user preferences storage (see [[IModelApp.userPreferences]]). */\n UserPreferencesStorage,\n}\n\n/**\n * A factory method to create one of the available [[IFavoritePropertiesStorage]] implementations.\n * @public\n */\nexport function createFavoritePropertiesStorage(type: DefaultFavoritePropertiesStorageTypes): IFavoritePropertiesStorage {\n switch (type) {\n case DefaultFavoritePropertiesStorageTypes.Noop:\n return new NoopFavoritePropertiesStorage();\n case DefaultFavoritePropertiesStorageTypes.BrowserLocalStorage:\n return new BrowserLocalFavoritePropertiesStorage();\n case DefaultFavoritePropertiesStorageTypes.UserPreferencesStorage:\n return new OfflineCachingFavoritePropertiesStorage({ impl: new IModelAppFavoritePropertiesStorage() });\n }\n}\n\n/**\n * @internal\n */\nexport class IModelAppFavoritePropertiesStorage implements IFavoritePropertiesStorage {\n private async ensureIsSignedIn(): Promise<{ accessToken: AccessToken }> {\n const accessToken = IModelApp.authorizationClient ? await IModelApp.authorizationClient.getAccessToken() : \"\";\n if (accessToken) {\n return { accessToken };\n }\n throw new PresentationError(PresentationStatus.Error, \"Current user is not authorized to use the settings service\");\n }\n\n public async loadProperties(iTwinId?: string, imodelId?: string): Promise<Set<PropertyFullName> | undefined> {\n if (!IModelApp.userPreferences) {\n throw new PresentationError(PresentationStatus.Error, \"User preferences service is not set up\");\n }\n\n const { accessToken } = await this.ensureIsSignedIn();\n let setting = await IModelApp.userPreferences.get({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: IMODELJS_PRESENTATION_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_SETTING_NAME,\n });\n\n if (setting !== undefined) {\n return new Set<PropertyFullName>(setting);\n }\n\n // try to check the old namespace\n setting = await IModelApp.userPreferences.get({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: DEPRECATED_PROPERTIES_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_SETTING_NAME,\n });\n\n if (\n setting !== undefined &&\n setting.hasOwnProperty(\"nestedContentInfos\") &&\n setting.hasOwnProperty(\"propertyInfos\") &&\n setting.hasOwnProperty(\"baseFieldInfos\")\n ) {\n return new Set<PropertyFullName>([...setting.nestedContentInfos, ...setting.propertyInfos, ...setting.baseFieldInfos]);\n }\n\n return undefined;\n }\n\n public async saveProperties(properties: Set<PropertyFullName>, iTwinId?: string, imodelId?: string): Promise<void> {\n if (!IModelApp.userPreferences) {\n throw new PresentationError(PresentationStatus.Error, \"User preferences service is not set up\");\n }\n\n const { accessToken } = await this.ensureIsSignedIn();\n await IModelApp.userPreferences.save({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: IMODELJS_PRESENTATION_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_SETTING_NAME,\n content: Array.from(properties),\n });\n }\n\n public async loadPropertiesOrder(iTwinId: string | undefined, imodelId: string): Promise<FavoritePropertiesOrderInfo[] | undefined> {\n if (!IModelApp.userPreferences) {\n throw new PresentationError(PresentationStatus.Error, \"User preferences service is not set up\");\n }\n\n const { accessToken } = await this.ensureIsSignedIn();\n const setting = await IModelApp.userPreferences.get({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: IMODELJS_PRESENTATION_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME,\n });\n return setting as FavoritePropertiesOrderInfo[];\n }\n\n public async savePropertiesOrder(orderInfos: FavoritePropertiesOrderInfo[], iTwinId: string | undefined, imodelId: string) {\n if (!IModelApp.userPreferences) {\n throw new PresentationError(PresentationStatus.Error, \"User preferences service is not set up\");\n }\n\n const { accessToken } = await this.ensureIsSignedIn();\n await IModelApp.userPreferences.save({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: IMODELJS_PRESENTATION_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME,\n content: orderInfos,\n });\n }\n}\n\n/** @internal */\nexport interface OfflineCachingFavoritePropertiesStorageProps {\n impl: IFavoritePropertiesStorage;\n connectivityInfo?: IConnectivityInformationProvider;\n}\n/** @internal */\nexport class OfflineCachingFavoritePropertiesStorage implements IFavoritePropertiesStorage, Disposable {\n private _connectivityInfo: IConnectivityInformationProvider;\n private _impl: IFavoritePropertiesStorage;\n private _propertiesOfflineCache = new DictionaryWithReservations<ITwinAndIModelIdsKey, Set<PropertyFullName>>(iTwinAndIModelIdsKeyComparer);\n private _propertiesOrderOfflineCache = new DictionaryWithReservations<ITwinAndIModelIdsKey, FavoritePropertiesOrderInfo[]>(iTwinAndIModelIdsKeyComparer);\n\n public constructor(props: OfflineCachingFavoritePropertiesStorageProps) {\n this._impl = props.impl;\n // istanbul ignore next\n this._connectivityInfo = props.connectivityInfo ?? new ConnectivityInformationProvider();\n this._connectivityInfo.onInternetConnectivityChanged.addListener(this.onConnectivityStatusChanged);\n }\n\n public [Symbol.dispose]() {\n isDisposable(this._connectivityInfo) && this._connectivityInfo[Symbol.dispose]();\n }\n\n public get impl() {\n return this._impl;\n }\n\n private onConnectivityStatusChanged = (args: { status: InternetConnectivityStatus }) => {\n // istanbul ignore else\n if (args.status === InternetConnectivityStatus.Online) {\n // note: we're copying the cached values to temp arrays because `saveProperties` and `savePropertiesOrder` both\n // attempt to modify cache dictionaries\n\n const propertiesCache = new Array<{ properties: Set<PropertyFullName>; iTwinId?: string; imodelId?: string }>();\n this._propertiesOfflineCache.forEach((key, value) => propertiesCache.push({ properties: value, iTwinId: key[0], imodelId: key[1] }));\n propertiesCache.forEach(async (cached) => this.saveProperties(cached.properties, cached.iTwinId, cached.imodelId));\n\n const ordersCache = new Array<{ order: FavoritePropertiesOrderInfo[]; iTwinId?: string; imodelId: string }>();\n this._propertiesOrderOfflineCache.forEach((key, value) => ordersCache.push({ order: value, iTwinId: key[0], imodelId: key[1]! }));\n ordersCache.forEach(async (cached) => this.savePropertiesOrder(cached.order, cached.iTwinId, cached.imodelId));\n }\n };\n\n public async loadProperties(iTwinId?: string, imodelId?: string) {\n if (this._connectivityInfo.status === InternetConnectivityStatus.Online) {\n try {\n return await this._impl.loadProperties(iTwinId, imodelId);\n } catch {\n // return from offline cache if the above fails\n }\n }\n return this._propertiesOfflineCache.get([iTwinId, imodelId]);\n }\n\n public async saveProperties(properties: Set<PropertyFullName>, iTwinId?: string, imodelId?: string) {\n const key: ITwinAndIModelIdsKey = [iTwinId, imodelId];\n if (this._connectivityInfo.status === InternetConnectivityStatus.Offline) {\n this._propertiesOfflineCache.set(key, properties);\n return;\n }\n const reservationId = this._propertiesOfflineCache.reserve(key);\n try {\n await this._impl.saveProperties(properties, iTwinId, imodelId);\n this._propertiesOfflineCache.reservedDelete(key, reservationId);\n } catch {\n this._propertiesOfflineCache.reservedSet(key, properties, reservationId);\n }\n }\n\n public async loadPropertiesOrder(iTwinId: string | undefined, imodelId: string) {\n if (this._connectivityInfo.status === InternetConnectivityStatus.Online) {\n try {\n return await this._impl.loadPropertiesOrder(iTwinId, imodelId);\n } catch {\n // return from offline cache if the above fails\n }\n }\n return this._propertiesOrderOfflineCache.get([iTwinId, imodelId]);\n }\n\n public async savePropertiesOrder(orderInfos: FavoritePropertiesOrderInfo[], iTwinId: string | undefined, imodelId: string) {\n const key: ITwinAndIModelIdsKey = [iTwinId, imodelId];\n if (this._connectivityInfo.status === InternetConnectivityStatus.Offline) {\n this._propertiesOrderOfflineCache.set(key, orderInfos);\n return;\n }\n const reservationId = this._propertiesOrderOfflineCache.reserve(key);\n try {\n await this._impl.savePropertiesOrder(orderInfos, iTwinId, imodelId);\n this._propertiesOrderOfflineCache.reservedDelete(key, reservationId);\n } catch {\n this._propertiesOrderOfflineCache.reservedSet(key, orderInfos, reservationId);\n }\n }\n}\n\nclass DictionaryWithReservations<TKey, TValue> {\n private _impl: Dictionary<TKey, { value?: TValue; lastReservationId?: string }>;\n public constructor(compareKeys: OrderedComparator<TKey>) {\n this._impl = new Dictionary(compareKeys);\n }\n public get(key: TKey) {\n return this._impl.get(key)?.value;\n }\n public forEach(func: (key: TKey, value: TValue) => void): void {\n this._impl.forEach((key, entry) => {\n // istanbul ignore else\n if (entry.value) {\n func(key, entry.value);\n }\n });\n }\n public reserve(key: TKey) {\n const reservationId = Guid.createValue();\n this._impl.set(key, { lastReservationId: reservationId });\n return reservationId;\n }\n public set(key: TKey, value: TValue) {\n return this._impl.set(key, { value });\n }\n public reservedSet(key: TKey, value: TValue, reservationId: string) {\n const entry = this._impl.get(key);\n if (entry && entry.lastReservationId === reservationId) {\n this._impl.set(key, { value });\n }\n }\n public reservedDelete(key: TKey, reservationId: string) {\n const entry = this._impl.get(key);\n if (entry && entry.lastReservationId === reservationId) {\n this._impl.delete(key);\n }\n }\n}\ntype ITwinAndIModelIdsKey = [string | undefined, string | undefined];\n\n// istanbul ignore next\nfunction iTwinAndIModelIdsKeyComparer(lhs: ITwinAndIModelIdsKey, rhs: ITwinAndIModelIdsKey) {\n const iTwinIdCompare = compareStrings(lhs[0] ?? \"\", rhs[0] ?? \"\");\n return iTwinIdCompare !== 0 ? iTwinIdCompare : compareStrings(lhs[1] ?? \"\", rhs[1] ?? \"\");\n}\n\n/** @internal */\nexport class NoopFavoritePropertiesStorage implements IFavoritePropertiesStorage {\n // istanbul ignore next\n public async loadProperties(_iTwinId?: string, _imodelId?: string): Promise<Set<PropertyFullName> | undefined> {\n return undefined;\n }\n // istanbul ignore next\n public async saveProperties(_properties: Set<PropertyFullName>, _iTwinId?: string, _imodelId?: string) {}\n // istanbul ignore next\n public async loadPropertiesOrder(_iTwinId: string | undefined, _imodelId: string): Promise<FavoritePropertiesOrderInfo[] | undefined> {\n return undefined;\n }\n // istanbul ignore next\n public async savePropertiesOrder(_orderInfos: FavoritePropertiesOrderInfo[], _iTwinId: string | undefined, _imodelId: string): Promise<void> {}\n}\n\n/** @internal */\nexport class BrowserLocalFavoritePropertiesStorage implements IFavoritePropertiesStorage {\n private _localStorage: Storage;\n\n public constructor(props?: { localStorage?: Storage }) {\n // istanbul ignore next\n this._localStorage = props?.localStorage ?? window.localStorage;\n }\n\n public createFavoritesSettingItemKey(iTwinId?: string, imodelId?: string): string {\n return `${IMODELJS_PRESENTATION_SETTING_NAMESPACE}${FAVORITE_PROPERTIES_SETTING_NAME}?iTwinId=${iTwinId}&imodelId=${imodelId}`;\n }\n public createOrderSettingItemKey(iTwinId?: string, imodelId?: string): string {\n return `${IMODELJS_PRESENTATION_SETTING_NAMESPACE}${FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME}?iTwinId=${iTwinId}&imodelId=${imodelId}`;\n }\n\n public async loadProperties(iTwinId?: string, imodelId?: string): Promise<Set<PropertyFullName> | undefined> {\n const value = this._localStorage.getItem(this.createFavoritesSettingItemKey(iTwinId, imodelId));\n if (!value) {\n return undefined;\n }\n\n const properties: PropertyFullName[] = JSON.parse(value);\n return new Set(properties);\n }\n\n public async saveProperties(properties: Set<PropertyFullName>, iTwinId?: string, imodelId?: string) {\n this._localStorage.setItem(this.createFavoritesSettingItemKey(iTwinId, imodelId), JSON.stringify([...properties]));\n }\n\n public async loadPropertiesOrder(iTwinId: string | undefined, imodelId: string): Promise<FavoritePropertiesOrderInfo[] | undefined> {\n const value = this._localStorage.getItem(this.createOrderSettingItemKey(iTwinId, imodelId));\n if (!value) {\n return undefined;\n }\n\n const orderInfos: FavoritePropertiesOrderInfo[] = JSON.parse(value).map((json: any) => ({\n ...json,\n orderedTimestamp: new Date(json.orderedTimestamp),\n }));\n return orderInfos;\n }\n\n public async savePropertiesOrder(orderInfos: FavoritePropertiesOrderInfo[], iTwinId: string | undefined, imodelId: string): Promise<void> {\n this._localStorage.setItem(this.createOrderSettingItemKey(iTwinId, imodelId), JSON.stringify(orderInfos));\n }\n}\n"]}
1
+ {"version":3,"file":"FavoritePropertiesStorage.js","sourceRoot":"","sources":["../../../../src/presentation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AAK,CAAC,CAAC;QACzD,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,UAAiC,EAAE,OAAgB,EAAE,QAAiB;QAChG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IACrH,CAAC;IAEM,KAAK,CAAC,mBAAmB,CAAC,OAA2B,EAAE,QAAgB;QAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC5F,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,UAAU,GAAkC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,CAAC;YACtF,GAAG,IAAI;YACP,gBAAgB,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC;SAClD,CAAC,CAAC,CAAC;QACJ,OAAO,UAAU,CAAC;IACpB,CAAC;IAEM,KAAK,CAAC,mBAAmB,CAAC,UAAyC,EAAE,OAA2B,EAAE,QAAgB;QACvH,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5G,CAAC;CACF;AA7CD,sFA6CC","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 { AccessToken, compareStrings, Dictionary, Guid, isDisposable, OrderedComparator } from \"@itwin/core-bentley\";\nimport { InternetConnectivityStatus } from \"@itwin/core-common\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { PresentationError, PresentationStatus } from \"@itwin/presentation-common\";\nimport { ConnectivityInformationProvider, IConnectivityInformationProvider } from \"../ConnectivityInformationProvider\";\nimport { FavoritePropertiesOrderInfo, PropertyFullName } from \"./FavoritePropertiesManager\";\n\n/** @internal */\nexport const IMODELJS_PRESENTATION_SETTING_NAMESPACE = \"imodeljs.presentation\";\n/** @internal */\nexport const DEPRECATED_PROPERTIES_SETTING_NAMESPACE = \"Properties\";\n/** @internal */\nexport const FAVORITE_PROPERTIES_SETTING_NAME = \"FavoriteProperties\";\n/** @internal */\nexport const FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME = \"FavoritePropertiesOrderInfo\";\n\n/**\n * Stores user preferences for favorite properties.\n * @public\n */\nexport interface IFavoritePropertiesStorage {\n /** Load Favorite properties from user-specific settings.\n * @param iTwinId ITwin Id, if the settings is specific to a iTwin, otherwise undefined.\n * @param imodelId iModel Id, if the setting is specific to an iModel, otherwise undefined. The iTwinId must be specified if iModelId is specified.\n */\n loadProperties(iTwinId?: string, imodelId?: string): Promise<Set<PropertyFullName> | undefined>;\n /** Saves Favorite properties to user-specific settings.\n * @param properties Favorite properties to save.\n * @param iTwinId iTwin Id, if the settings is specific to a iTwin, otherwise undefined.\n * @param iModelId iModel Id, if the setting is specific to an iModel, otherwise undefined. The iTwinId must be specified if iModelId is specified.\n */\n saveProperties(properties: Set<PropertyFullName>, iTwinId?: string, imodelId?: string): Promise<void>;\n /** Load array of FavoritePropertiesOrderInfo from user-specific settings.\n * Setting is specific to an iModel.\n * @param iTwinId iTwin Id.\n * @param imodelId iModel Id.\n */\n loadPropertiesOrder(iTwinId: string | undefined, imodelId: string): Promise<FavoritePropertiesOrderInfo[] | undefined>;\n /** Saves FavoritePropertiesOrderInfo array to user-specific settings.\n * Setting is specific to an iModel.\n * @param orderInfo Array of FavoritePropertiesOrderInfo to save.\n * @param iTwinId iTwin Id.\n * @param imodelId iModel Id.\n */\n savePropertiesOrder(orderInfos: FavoritePropertiesOrderInfo[], iTwinId: string | undefined, imodelId: string): Promise<void>;\n}\n\n/**\n * Available implementations of [[IFavoritePropertiesStorage]].\n * @public\n */\nexport enum DefaultFavoritePropertiesStorageTypes {\n /** A no-op storage that doesn't store or return anything. Used for cases when favorite properties aren't used by the application. */\n Noop,\n /** A storage that stores favorite properties information in a browser local storage. */\n BrowserLocalStorage,\n /** A storage that stores favorite properties in a user preferences storage (see [[IModelApp.userPreferences]]). */\n UserPreferencesStorage,\n}\n\n/**\n * A factory method to create one of the available [[IFavoritePropertiesStorage]] implementations.\n * @public\n */\nexport function createFavoritePropertiesStorage(type: DefaultFavoritePropertiesStorageTypes): IFavoritePropertiesStorage {\n switch (type) {\n case DefaultFavoritePropertiesStorageTypes.Noop:\n return new NoopFavoritePropertiesStorage();\n case DefaultFavoritePropertiesStorageTypes.BrowserLocalStorage:\n return new BrowserLocalFavoritePropertiesStorage();\n case DefaultFavoritePropertiesStorageTypes.UserPreferencesStorage:\n return new OfflineCachingFavoritePropertiesStorage({ impl: new IModelAppFavoritePropertiesStorage() });\n }\n}\n\n/**\n * @internal\n */\nexport class IModelAppFavoritePropertiesStorage implements IFavoritePropertiesStorage {\n private async ensureIsSignedIn(): Promise<{ accessToken: AccessToken }> {\n const accessToken = IModelApp.authorizationClient ? await IModelApp.authorizationClient.getAccessToken() : \"\";\n if (accessToken) {\n return { accessToken };\n }\n throw new PresentationError(PresentationStatus.Error, \"Current user is not authorized to use the settings service\");\n }\n\n public async loadProperties(iTwinId?: string, imodelId?: string): Promise<Set<PropertyFullName> | undefined> {\n if (!IModelApp.userPreferences) {\n throw new PresentationError(PresentationStatus.Error, \"User preferences service is not set up\");\n }\n\n const { accessToken } = await this.ensureIsSignedIn();\n let setting = await IModelApp.userPreferences.get({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: IMODELJS_PRESENTATION_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_SETTING_NAME,\n });\n\n if (setting !== undefined) {\n return new Set<PropertyFullName>(setting);\n }\n\n // try to check the old namespace\n setting = await IModelApp.userPreferences.get({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: DEPRECATED_PROPERTIES_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_SETTING_NAME,\n });\n\n if (\n setting !== undefined &&\n setting.hasOwnProperty(\"nestedContentInfos\") &&\n setting.hasOwnProperty(\"propertyInfos\") &&\n setting.hasOwnProperty(\"baseFieldInfos\")\n ) {\n return new Set<PropertyFullName>([...setting.nestedContentInfos, ...setting.propertyInfos, ...setting.baseFieldInfos]);\n }\n\n return undefined;\n }\n\n public async saveProperties(properties: Set<PropertyFullName>, iTwinId?: string, imodelId?: string): Promise<void> {\n if (!IModelApp.userPreferences) {\n throw new PresentationError(PresentationStatus.Error, \"User preferences service is not set up\");\n }\n\n const { accessToken } = await this.ensureIsSignedIn();\n await IModelApp.userPreferences.save({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: IMODELJS_PRESENTATION_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_SETTING_NAME,\n content: Array.from(properties),\n });\n }\n\n public async loadPropertiesOrder(iTwinId: string | undefined, imodelId: string): Promise<FavoritePropertiesOrderInfo[] | undefined> {\n if (!IModelApp.userPreferences) {\n throw new PresentationError(PresentationStatus.Error, \"User preferences service is not set up\");\n }\n\n const { accessToken } = await this.ensureIsSignedIn();\n const setting = await IModelApp.userPreferences.get({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: IMODELJS_PRESENTATION_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME,\n });\n return setting as FavoritePropertiesOrderInfo[];\n }\n\n public async savePropertiesOrder(orderInfos: FavoritePropertiesOrderInfo[], iTwinId: string | undefined, imodelId: string) {\n if (!IModelApp.userPreferences) {\n throw new PresentationError(PresentationStatus.Error, \"User preferences service is not set up\");\n }\n\n const { accessToken } = await this.ensureIsSignedIn();\n await IModelApp.userPreferences.save({\n accessToken,\n iTwinId,\n iModelId: imodelId,\n namespace: IMODELJS_PRESENTATION_SETTING_NAMESPACE,\n key: FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME,\n content: orderInfos,\n });\n }\n}\n\n/** @internal */\nexport interface OfflineCachingFavoritePropertiesStorageProps {\n impl: IFavoritePropertiesStorage;\n connectivityInfo?: IConnectivityInformationProvider;\n}\n/** @internal */\nexport class OfflineCachingFavoritePropertiesStorage implements IFavoritePropertiesStorage, Disposable {\n private _connectivityInfo: IConnectivityInformationProvider;\n private _impl: IFavoritePropertiesStorage;\n private _propertiesOfflineCache = new DictionaryWithReservations<ITwinAndIModelIdsKey, Set<PropertyFullName>>(iTwinAndIModelIdsKeyComparer);\n private _propertiesOrderOfflineCache = new DictionaryWithReservations<ITwinAndIModelIdsKey, FavoritePropertiesOrderInfo[]>(iTwinAndIModelIdsKeyComparer);\n\n public constructor(props: OfflineCachingFavoritePropertiesStorageProps) {\n this._impl = props.impl;\n // istanbul ignore next\n this._connectivityInfo = props.connectivityInfo ?? new ConnectivityInformationProvider();\n this._connectivityInfo.onInternetConnectivityChanged.addListener(this.onConnectivityStatusChanged);\n }\n\n public [Symbol.dispose]() {\n isDisposable(this._connectivityInfo) && this._connectivityInfo[Symbol.dispose]();\n }\n\n public get impl() {\n return this._impl;\n }\n\n private onConnectivityStatusChanged = (args: { status: InternetConnectivityStatus }) => {\n // istanbul ignore else\n if (args.status === InternetConnectivityStatus.Online) {\n // note: we're copying the cached values to temp arrays because `saveProperties` and `savePropertiesOrder` both\n // attempt to modify cache dictionaries\n\n const propertiesCache = new Array<{ properties: Set<PropertyFullName>; iTwinId?: string; imodelId?: string }>();\n this._propertiesOfflineCache.forEach((key, value) => propertiesCache.push({ properties: value, iTwinId: key[0], imodelId: key[1] }));\n propertiesCache.forEach(async (cached) => this.saveProperties(cached.properties, cached.iTwinId, cached.imodelId));\n\n const ordersCache = new Array<{ order: FavoritePropertiesOrderInfo[]; iTwinId?: string; imodelId: string }>();\n this._propertiesOrderOfflineCache.forEach((key, value) => ordersCache.push({ order: value, iTwinId: key[0], imodelId: key[1]! }));\n ordersCache.forEach(async (cached) => this.savePropertiesOrder(cached.order, cached.iTwinId, cached.imodelId));\n }\n };\n\n public async loadProperties(iTwinId?: string, imodelId?: string) {\n if (this._connectivityInfo.status === InternetConnectivityStatus.Online) {\n try {\n return await this._impl.loadProperties(iTwinId, imodelId);\n } catch {\n // return from offline cache if the above fails\n }\n }\n return this._propertiesOfflineCache.get([iTwinId, imodelId]);\n }\n\n public async saveProperties(properties: Set<PropertyFullName>, iTwinId?: string, imodelId?: string) {\n const key: ITwinAndIModelIdsKey = [iTwinId, imodelId];\n if (this._connectivityInfo.status === InternetConnectivityStatus.Offline) {\n this._propertiesOfflineCache.set(key, properties);\n return;\n }\n const reservationId = this._propertiesOfflineCache.reserve(key);\n try {\n await this._impl.saveProperties(properties, iTwinId, imodelId);\n this._propertiesOfflineCache.reservedDelete(key, reservationId);\n } catch {\n this._propertiesOfflineCache.reservedSet(key, properties, reservationId);\n }\n }\n\n public async loadPropertiesOrder(iTwinId: string | undefined, imodelId: string) {\n if (this._connectivityInfo.status === InternetConnectivityStatus.Online) {\n try {\n return await this._impl.loadPropertiesOrder(iTwinId, imodelId);\n } catch {\n // return from offline cache if the above fails\n }\n }\n return this._propertiesOrderOfflineCache.get([iTwinId, imodelId]);\n }\n\n public async savePropertiesOrder(orderInfos: FavoritePropertiesOrderInfo[], iTwinId: string | undefined, imodelId: string) {\n const key: ITwinAndIModelIdsKey = [iTwinId, imodelId];\n if (this._connectivityInfo.status === InternetConnectivityStatus.Offline) {\n this._propertiesOrderOfflineCache.set(key, orderInfos);\n return;\n }\n const reservationId = this._propertiesOrderOfflineCache.reserve(key);\n try {\n await this._impl.savePropertiesOrder(orderInfos, iTwinId, imodelId);\n this._propertiesOrderOfflineCache.reservedDelete(key, reservationId);\n } catch {\n this._propertiesOrderOfflineCache.reservedSet(key, orderInfos, reservationId);\n }\n }\n}\n\nclass DictionaryWithReservations<TKey, TValue> {\n private _impl: Dictionary<TKey, { value?: TValue; lastReservationId?: string }>;\n public constructor(compareKeys: OrderedComparator<TKey>) {\n this._impl = new Dictionary(compareKeys);\n }\n public get(key: TKey) {\n return this._impl.get(key)?.value;\n }\n public forEach(func: (key: TKey, value: TValue) => void): void {\n this._impl.forEach((key, entry) => {\n // istanbul ignore else\n if (entry.value) {\n func(key, entry.value);\n }\n });\n }\n public reserve(key: TKey) {\n const reservationId = Guid.createValue();\n this._impl.set(key, { lastReservationId: reservationId });\n return reservationId;\n }\n public set(key: TKey, value: TValue) {\n return this._impl.set(key, { value });\n }\n public reservedSet(key: TKey, value: TValue, reservationId: string) {\n const entry = this._impl.get(key);\n if (entry && entry.lastReservationId === reservationId) {\n this._impl.set(key, { value });\n }\n }\n public reservedDelete(key: TKey, reservationId: string) {\n const entry = this._impl.get(key);\n if (entry && entry.lastReservationId === reservationId) {\n this._impl.delete(key);\n }\n }\n}\ntype ITwinAndIModelIdsKey = [string | undefined, string | undefined];\n\n// istanbul ignore next\nfunction iTwinAndIModelIdsKeyComparer(lhs: ITwinAndIModelIdsKey, rhs: ITwinAndIModelIdsKey) {\n const iTwinIdCompare = compareStrings(lhs[0] ?? \"\", rhs[0] ?? \"\");\n return iTwinIdCompare !== 0 ? iTwinIdCompare : compareStrings(lhs[1] ?? \"\", rhs[1] ?? \"\");\n}\n\n/** @internal */\nexport class NoopFavoritePropertiesStorage implements IFavoritePropertiesStorage {\n // istanbul ignore next\n public async loadProperties(_iTwinId?: string, _imodelId?: string): Promise<Set<PropertyFullName> | undefined> {\n return undefined;\n }\n // istanbul ignore next\n public async saveProperties(_properties: Set<PropertyFullName>, _iTwinId?: string, _imodelId?: string) {}\n // istanbul ignore next\n public async loadPropertiesOrder(_iTwinId: string | undefined, _imodelId: string): Promise<FavoritePropertiesOrderInfo[] | undefined> {\n return undefined;\n }\n // istanbul ignore next\n public async savePropertiesOrder(_orderInfos: FavoritePropertiesOrderInfo[], _iTwinId: string | undefined, _imodelId: string): Promise<void> {}\n}\n\n/** @internal */\nexport class BrowserLocalFavoritePropertiesStorage implements IFavoritePropertiesStorage {\n private _localStorage: Storage;\n\n public constructor(props?: { localStorage?: Storage }) {\n // istanbul ignore next\n this._localStorage = props?.localStorage ?? window.localStorage;\n }\n\n public createFavoritesSettingItemKey(iTwinId?: string, imodelId?: string): string {\n return `${IMODELJS_PRESENTATION_SETTING_NAMESPACE}${FAVORITE_PROPERTIES_SETTING_NAME}?iTwinId=${iTwinId}&imodelId=${imodelId}`;\n }\n public createOrderSettingItemKey(iTwinId?: string, imodelId?: string): string {\n return `${IMODELJS_PRESENTATION_SETTING_NAMESPACE}${FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME}?iTwinId=${iTwinId}&imodelId=${imodelId}`;\n }\n\n public async loadProperties(iTwinId?: string, imodelId?: string): Promise<Set<PropertyFullName> | undefined> {\n const value = this._localStorage.getItem(this.createFavoritesSettingItemKey(iTwinId, imodelId));\n if (!value) {\n return undefined;\n }\n\n const properties: PropertyFullName[] = JSON.parse(value);\n return new Set(properties);\n }\n\n public async saveProperties(properties: Set<PropertyFullName>, iTwinId?: string, imodelId?: string) {\n this._localStorage.setItem(this.createFavoritesSettingItemKey(iTwinId, imodelId), JSON.stringify([...properties]));\n }\n\n public async loadPropertiesOrder(iTwinId: string | undefined, imodelId: string): Promise<FavoritePropertiesOrderInfo[] | undefined> {\n const value = this._localStorage.getItem(this.createOrderSettingItemKey(iTwinId, imodelId));\n if (!value) {\n return undefined;\n }\n\n const orderInfos: FavoritePropertiesOrderInfo[] = JSON.parse(value).map((json: any) => ({\n ...json,\n orderedTimestamp: new Date(json.orderedTimestamp),\n }));\n return orderInfos;\n }\n\n public async savePropertiesOrder(orderInfos: FavoritePropertiesOrderInfo[], iTwinId: string | undefined, imodelId: string): Promise<void> {\n this._localStorage.setItem(this.createOrderSettingItemKey(iTwinId, imodelId), JSON.stringify(orderInfos));\n }\n}\n"]}
@@ -26,6 +26,8 @@ const HILITE_RULESET = HiliteRules_json_1.default;
26
26
  * @public
27
27
  */
28
28
  class HiliteSetProvider {
29
+ _imodel;
30
+ _cache;
29
31
  constructor(props) {
30
32
  this._imodel = props.imodel;
31
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"HiliteSetProvider.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/HiliteSetProvider.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;AAEH,+BAAqD;AACrD,mDAA+C;AAG/C,oEAAgK;AAChK,kDAA+C;AAC/C,0EAA+C;AAC/C,gEAAuE;AAEvE,MAAM,cAAc,GAAG,0BAAwB,CAAC;AAsBhD;;;;;;GAMG;AACH,MAAa,iBAAiB;IAI5B,YAAoB,KAA6B;QAC/C,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,MAAM,CAAC,KAA6B;QAChD,OAAO,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,YAAY,CAAC,SAA2B;QACnD,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAc,CAAC;QACzC,MAAM,cAAc,GAAG,IAAI,KAAK,EAAc,CAAC;QAC/C,MAAM,UAAU,GAAG,IAAI,KAAK,EAAc,CAAC;QAE3C,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;QACtD,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YACjC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;YACrC,cAAc,CAAC,IAAI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C,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,SAAS,KAAK,+CAA2B,EAAE,CAAC;gBAC5E,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAC1B,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;QACH,OAAO;YACL,YAAY;YACZ,IAAI;SACL,CAAC;IACJ,CAAC;CACF;AA9ID,8CA8IC;AAED,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC,MAAM,aAAa,GAAG,CAAC,GAAS,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC;AAElF,MAAM,mBAAmB,GAAG,CAAC,GAAS,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,YAAY,CAAC,aAAa,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module UnifiedSelection\n */\n\nimport { from, Observable, shareReplay } from \"rxjs\";\nimport { eachValueFrom } from \"rxjs-for-await\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { ContentFlags, DEFAULT_KEYS_BATCH_SIZE, DefaultContentDisplayTypes, DescriptorOverrides, Item, Key, KeySet, Ruleset } from \"@itwin/presentation-common\";\nimport { Presentation } from \"../Presentation\";\nimport hiliteRuleset from \"./HiliteRules.json\";\nimport { TRANSIENT_ELEMENT_CLASSNAME } from \"@itwin/unified-selection\";\n\nconst HILITE_RULESET = hiliteRuleset as Ruleset;\n\n/**\n * A set of model, subcategory and element ids that can be used for specifying\n * viewport hilite.\n *\n * @public\n */\nexport interface HiliteSet {\n models?: Id64String[];\n subCategories?: Id64String[];\n elements?: Id64String[];\n}\n\n/**\n * Properties for creating a `HiliteSetProvider` instance.\n * @public\n */\nexport interface HiliteSetProviderProps {\n imodel: IModelConnection;\n}\n\n/**\n * Presentation-based provider which uses presentation ruleset to determine\n * what `HiliteSet` should be hilited in the graphics viewport based on the\n * supplied `KeySet`.\n *\n * @public\n */\nexport class HiliteSetProvider {\n private _imodel: IModelConnection;\n private _cache: undefined | { keysGuid: string; observable: Observable<HiliteSet> };\n\n private constructor(props: HiliteSetProviderProps) {\n this._imodel = props.imodel;\n }\n\n /**\n * Create a hilite set provider for the specified iModel.\n */\n public static create(props: HiliteSetProviderProps) {\n return new HiliteSetProvider(props);\n }\n\n /**\n * Get hilite set for instances and/or nodes whose keys are specified in the\n * given KeySet.\n *\n * Note: The provider caches result of the last request, so subsequent requests\n * for the same input doesn't cost.\n */\n public async getHiliteSet(selection: Readonly<KeySet>): Promise<HiliteSet> {\n const modelIds = new Array<Id64String>();\n const subCategoryIds = new Array<Id64String>();\n const elementIds = new Array<Id64String>();\n\n const iterator = this.getHiliteSetIterator(selection);\n for await (const set of iterator) {\n modelIds.push(...(set.models ?? []));\n subCategoryIds.push(...(set.subCategories ?? []));\n elementIds.push(...(set.elements ?? []));\n }\n\n return {\n models: modelIds.length ? modelIds : undefined,\n subCategories: subCategoryIds.length ? subCategoryIds : undefined,\n elements: elementIds.length ? elementIds : undefined,\n };\n }\n\n /**\n * Get hilite set iterator for provided keys. It loads content in batches and\n * yields hilite set created from each batch after it is loaded.\n */\n public getHiliteSetIterator(selection: Readonly<KeySet>) {\n if (!this._cache || this._cache.keysGuid !== selection.guid) {\n this._cache = {\n keysGuid: selection.guid,\n observable: from(this.createHiliteSetIterator(selection)).pipe(shareReplay({ refCount: true })),\n };\n }\n\n return eachValueFrom(this._cache.observable);\n }\n\n private async *createHiliteSetIterator(selection: Readonly<KeySet>) {\n const { keys, transientIds } = this.handleTransientKeys(selection);\n const { options, keyBatches } = this.getContentOptions(keys);\n\n if (transientIds.length !== 0) {\n yield { elements: transientIds };\n }\n\n for (const batch of keyBatches) {\n let loadedItems = 0;\n while (true) {\n const content = await Presentation.presentation.getContentIterator({\n ...options,\n paging: { start: loadedItems, size: CONTENT_SET_PAGE_SIZE },\n keys: batch,\n });\n if (!content) {\n break;\n }\n\n const items = new Array<Item>();\n for await (const item of content.items) {\n items.push(item);\n }\n const result = this.createHiliteSet(items);\n yield result;\n\n loadedItems += items.length;\n if (loadedItems >= content.total) {\n break;\n }\n }\n }\n }\n\n private createHiliteSet(records: Item[]): HiliteSet {\n const modelIds = new Array<Id64String>();\n const subCategoryIds = new Array<Id64String>();\n const elementIds = new Array<Id64String>();\n records.forEach((rec) => {\n const ids = isModelRecord(rec) ? modelIds : isSubCategoryRecord(rec) ? subCategoryIds : elementIds;\n rec.primaryKeys.forEach((pk) => ids.push(pk.id));\n });\n return {\n models: modelIds.length ? modelIds : undefined,\n subCategories: subCategoryIds.length ? subCategoryIds : undefined,\n elements: elementIds.length ? elementIds : undefined,\n };\n }\n\n private getContentOptions(keys: KeySet) {\n const descriptor: DescriptorOverrides = {\n displayType: DefaultContentDisplayTypes.Viewport,\n contentFlags: ContentFlags.KeysOnly,\n };\n const options = {\n imodel: this._imodel,\n rulesetOrId: HILITE_RULESET,\n descriptor,\n };\n const keyBatches = new Array<KeySet>();\n keys.forEachBatch(DEFAULT_KEYS_BATCH_SIZE, (batch: KeySet) => {\n keyBatches.push(batch);\n });\n return {\n options,\n keyBatches,\n };\n }\n\n private handleTransientKeys(selection: Readonly<KeySet>) {\n // need to create a new set without transients\n const transientIds = new Array<Id64String>();\n const keys = new KeySet();\n keys.add(selection, (key: Key) => {\n if (Key.isInstanceKey(key) && key.className === TRANSIENT_ELEMENT_CLASSNAME) {\n transientIds.push(key.id);\n return false;\n }\n return true;\n });\n return {\n transientIds,\n keys,\n };\n }\n}\n\nconst CONTENT_SET_PAGE_SIZE = 1000;\n\nconst isModelRecord = (rec: Item) => rec.extendedData && rec.extendedData.isModel;\n\nconst isSubCategoryRecord = (rec: Item) => rec.extendedData && rec.extendedData.isSubCategory;\n"]}
1
+ {"version":3,"file":"HiliteSetProvider.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/HiliteSetProvider.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;AAEH,+BAAqD;AACrD,mDAA+C;AAG/C,oEAAgK;AAChK,kDAA+C;AAC/C,0EAA+C;AAC/C,gEAAuE;AAEvE,MAAM,cAAc,GAAG,0BAAwB,CAAC;AAsBhD;;;;;;GAMG;AACH,MAAa,iBAAiB;IACpB,OAAO,CAAmB;IAC1B,MAAM,CAAsE;IAEpF,YAAoB,KAA6B;QAC/C,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,MAAM,CAAC,KAA6B;QAChD,OAAO,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,YAAY,CAAC,SAA2B;QACnD,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAc,CAAC;QACzC,MAAM,cAAc,GAAG,IAAI,KAAK,EAAc,CAAC;QAC/C,MAAM,UAAU,GAAG,IAAI,KAAK,EAAc,CAAC;QAE3C,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;QACtD,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YACjC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;YACrC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,CAAC;YAClD,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO;YACL,MAAM,EAAE,QAA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,CAAC,CAAC,CAAC;QACH,OAAO;YACL,YAAY;YACZ,IAAI;SACL,CAAC;IACJ,CAAC;CACF;AA9ID,8CA8IC;AAED,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC,MAAM,aAAa,GAAG,CAAC,GAAS,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC;AAElF,MAAM,mBAAmB,GAAG,CAAC,GAAS,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,YAAY,CAAC,aAAa,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module UnifiedSelection\n */\n\nimport { from, Observable, shareReplay } from \"rxjs\";\nimport { eachValueFrom } from \"rxjs-for-await\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { ContentFlags, DEFAULT_KEYS_BATCH_SIZE, DefaultContentDisplayTypes, DescriptorOverrides, Item, Key, KeySet, Ruleset } from \"@itwin/presentation-common\";\nimport { Presentation } from \"../Presentation\";\nimport hiliteRuleset from \"./HiliteRules.json\";\nimport { TRANSIENT_ELEMENT_CLASSNAME } from \"@itwin/unified-selection\";\n\nconst HILITE_RULESET = hiliteRuleset as Ruleset;\n\n/**\n * A set of model, subcategory and element ids that can be used for specifying\n * viewport hilite.\n *\n * @public\n */\nexport interface HiliteSet {\n models?: Id64String[];\n subCategories?: Id64String[];\n elements?: Id64String[];\n}\n\n/**\n * Properties for creating a `HiliteSetProvider` instance.\n * @public\n */\nexport interface HiliteSetProviderProps {\n imodel: IModelConnection;\n}\n\n/**\n * Presentation-based provider which uses presentation ruleset to determine\n * what `HiliteSet` should be hilited in the graphics viewport based on the\n * supplied `KeySet`.\n *\n * @public\n */\nexport class HiliteSetProvider {\n private _imodel: IModelConnection;\n private _cache: undefined | { keysGuid: string; observable: Observable<HiliteSet> };\n\n private constructor(props: HiliteSetProviderProps) {\n this._imodel = props.imodel;\n }\n\n /**\n * Create a hilite set provider for the specified iModel.\n */\n public static create(props: HiliteSetProviderProps) {\n return new HiliteSetProvider(props);\n }\n\n /**\n * Get hilite set for instances and/or nodes whose keys are specified in the\n * given KeySet.\n *\n * Note: The provider caches result of the last request, so subsequent requests\n * for the same input doesn't cost.\n */\n public async getHiliteSet(selection: Readonly<KeySet>): Promise<HiliteSet> {\n const modelIds = new Array<Id64String>();\n const subCategoryIds = new Array<Id64String>();\n const elementIds = new Array<Id64String>();\n\n const iterator = this.getHiliteSetIterator(selection);\n for await (const set of iterator) {\n modelIds.push(...(set.models ?? []));\n subCategoryIds.push(...(set.subCategories ?? []));\n elementIds.push(...(set.elements ?? []));\n }\n\n return {\n models: modelIds.length ? modelIds : undefined,\n subCategories: subCategoryIds.length ? subCategoryIds : undefined,\n elements: elementIds.length ? elementIds : undefined,\n };\n }\n\n /**\n * Get hilite set iterator for provided keys. It loads content in batches and\n * yields hilite set created from each batch after it is loaded.\n */\n public getHiliteSetIterator(selection: Readonly<KeySet>) {\n if (!this._cache || this._cache.keysGuid !== selection.guid) {\n this._cache = {\n keysGuid: selection.guid,\n observable: from(this.createHiliteSetIterator(selection)).pipe(shareReplay({ refCount: true })),\n };\n }\n\n return eachValueFrom(this._cache.observable);\n }\n\n private async *createHiliteSetIterator(selection: Readonly<KeySet>) {\n const { keys, transientIds } = this.handleTransientKeys(selection);\n const { options, keyBatches } = this.getContentOptions(keys);\n\n if (transientIds.length !== 0) {\n yield { elements: transientIds };\n }\n\n for (const batch of keyBatches) {\n let loadedItems = 0;\n while (true) {\n const content = await Presentation.presentation.getContentIterator({\n ...options,\n paging: { start: loadedItems, size: CONTENT_SET_PAGE_SIZE },\n keys: batch,\n });\n if (!content) {\n break;\n }\n\n const items = new Array<Item>();\n for await (const item of content.items) {\n items.push(item);\n }\n const result = this.createHiliteSet(items);\n yield result;\n\n loadedItems += items.length;\n if (loadedItems >= content.total) {\n break;\n }\n }\n }\n }\n\n private createHiliteSet(records: Item[]): HiliteSet {\n const modelIds = new Array<Id64String>();\n const subCategoryIds = new Array<Id64String>();\n const elementIds = new Array<Id64String>();\n records.forEach((rec) => {\n const ids = isModelRecord(rec) ? modelIds : isSubCategoryRecord(rec) ? subCategoryIds : elementIds;\n rec.primaryKeys.forEach((pk) => ids.push(pk.id));\n });\n return {\n models: modelIds.length ? modelIds : undefined,\n subCategories: subCategoryIds.length ? subCategoryIds : undefined,\n elements: elementIds.length ? elementIds : undefined,\n };\n }\n\n private getContentOptions(keys: KeySet) {\n const descriptor: DescriptorOverrides = {\n displayType: DefaultContentDisplayTypes.Viewport,\n contentFlags: ContentFlags.KeysOnly,\n };\n const options = {\n imodel: this._imodel,\n rulesetOrId: HILITE_RULESET,\n descriptor,\n };\n const keyBatches = new Array<KeySet>();\n keys.forEachBatch(DEFAULT_KEYS_BATCH_SIZE, (batch: KeySet) => {\n keyBatches.push(batch);\n });\n return {\n options,\n keyBatches,\n };\n }\n\n private handleTransientKeys(selection: Readonly<KeySet>) {\n // need to create a new set without transients\n const transientIds = new Array<Id64String>();\n const keys = new KeySet();\n keys.add(selection, (key: Key) => {\n if (Key.isInstanceKey(key) && key.className === TRANSIENT_ELEMENT_CLASSNAME) {\n transientIds.push(key.id);\n return false;\n }\n return true;\n });\n return {\n transientIds,\n keys,\n };\n }\n}\n\nconst CONTENT_SET_PAGE_SIZE = 1000;\n\nconst isModelRecord = (rec: Item) => rec.extendedData && rec.extendedData.isModel;\n\nconst isSubCategoryRecord = (rec: Item) => rec.extendedData && rec.extendedData.isSubCategory;\n"]}
@@ -16,22 +16,25 @@ const core_bentley_1 = require("@itwin/core-bentley");
16
16
  * @public
17
17
  */
18
18
  class SelectionHandler {
19
+ _inSelect;
20
+ _disposables;
21
+ /** Selection manager used by this handler to manage selection */
22
+ manager;
23
+ /** Name that's used as `SelectionChangeEventArgs.source` when making selection changes */
24
+ name;
25
+ /** iModel whose selection is being handled */
26
+ imodel;
27
+ /**
28
+ * Id of a ruleset selection changes will be associated with.
29
+ * @see `SelectionHandlerProps.rulesetId`
30
+ */
31
+ rulesetId;
32
+ /** Callback function called when selection changes */
33
+ onSelect;
19
34
  /**
20
35
  * Constructor.
21
36
  */
22
37
  constructor(props) {
23
- /**
24
- * Called when the selection changes. Handles this callback by first checking whether
25
- * the event should be handled at all (using the `shouldHandle` method) and then calling `onSelect`
26
- */
27
- this.onSelectionChanged = (evt, provider) => {
28
- if (!this.onSelect || !this.shouldHandle(evt)) {
29
- return;
30
- }
31
- this._inSelect = true;
32
- this.onSelect(evt, provider);
33
- this._inSelect = false;
34
- };
35
38
  this._inSelect = false;
36
39
  this.manager = props.manager;
37
40
  this._disposables = new core_bentley_1.DisposableList();
@@ -53,6 +56,18 @@ class SelectionHandler {
53
56
  dispose() {
54
57
  this[Symbol.dispose]();
55
58
  }
59
+ /**
60
+ * Called when the selection changes. Handles this callback by first checking whether
61
+ * the event should be handled at all (using the `shouldHandle` method) and then calling `onSelect`
62
+ */
63
+ onSelectionChanged = (evt, provider) => {
64
+ if (!this.onSelect || !this.shouldHandle(evt)) {
65
+ return;
66
+ }
67
+ this._inSelect = true;
68
+ this.onSelect(evt, provider);
69
+ this._inSelect = false;
70
+ };
56
71
  /** Called to check whether the event should be handled by this handler */
57
72
  shouldHandle(evt) {
58
73
  if (this.name === evt.source) {
@@ -1 +1 @@
1
- {"version":3,"file":"SelectionHandler.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionHandler.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAEH,sDAAqD;AAiCrD;;;;;GAKG;AACH,MAAa,gBAAgB;IAkB3B;;OAEG;IACH,YAAY,KAA4B;QAyBxC;;;WAGG;QACO,uBAAkB,GAAG,CAAC,GAA6B,EAAE,QAA4B,EAAQ,EAAE;YACnG,IAAI,CAAC,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C,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACpF,CAAC;CACF;AAnID,4CAmIC","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 } 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 Disposable {\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 [Symbol.dispose](): void {\n this._disposables.dispose();\n }\n\n /** @deprecated in 5.0 Use [Symbol.dispose] instead. */\n // istanbul ignore next\n public dispose() {\n this[Symbol.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 protected onSelectionChanged = (evt: SelectionChangeEventArgs, provider: ISelectionProvider): void => {\n if (!this.onSelect || !this.shouldHandle(evt)) {\n return;\n }\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 }\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\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\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\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\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,sDAAqD;AAiCrD;;;;;GAKG;AACH,MAAa,gBAAgB;IACnB,SAAS,CAAU;IACnB,YAAY,CAAiB;IAErC,iEAAiE;IACjD,OAAO,CAAmB;IAC1C,0FAA0F;IACnF,IAAI,CAAS;IACpB,8CAA8C;IACvC,MAAM,CAAmB;IAChC;;;OAGG;IACI,SAAS,CAAU;IAC1B,sDAAsD;IAC/C,QAAQ,CAA4B;IAE3C;;OAEG;IACH,YAAY,KAA4B;QACtC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,IAAI,6BAAc,EAAE,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,WAAW,CAAC,IA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,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1F,CAAC;IAED;;;;OAIG;IACI,mBAAmB,CAAC,IAAU,EAAE,QAAgB,CAAC;QACtD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,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,CAAC;YACnB,OAAO;QACT,CAAC;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,CAAC;YACnB,OAAO;QACT,CAAC;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;AAnID,4CAmIC","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 } 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 Disposable {\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 [Symbol.dispose](): void {\n this._disposables.dispose();\n }\n\n /** @deprecated in 5.0 Use [Symbol.dispose] instead. */\n // istanbul ignore next\n public dispose() {\n this[Symbol.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 protected onSelectionChanged = (evt: SelectionChangeEventArgs, provider: ISelectionProvider): void => {\n if (!this.onSelect || !this.shouldHandle(evt)) {\n return;\n }\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 }\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\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\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\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\n return this.manager.clearSelection(this.name, this.imodel, level, this.rulesetId);\n }\n}\n"]}
@@ -74,16 +74,28 @@ const SelectionScopesManager_1 = require("./SelectionScopesManager");
74
74
  * @public
75
75
  */
76
76
  class SelectionManager {
77
+ _imodelKeyFactory;
78
+ _imodelToolSelectionSyncHandlers = new Map();
79
+ _hiliteSetProviders = new Map();
80
+ _ownsStorage;
81
+ _knownIModels = new Set();
82
+ _currentSelection = new CurrentSelectionStorage();
83
+ _selectionChanges = new rxjs_1.Subject();
84
+ _selectionEventsSubscription;
85
+ _listeners = [];
86
+ /**
87
+ * Underlying selection storage used by this selection manager. Ideally, consumers should use
88
+ * the storage directly instead of using this manager to manipulate selection.
89
+ */
90
+ selectionStorage;
91
+ /** An event which gets broadcasted on selection changes */
92
+ selectionChange;
93
+ /** Manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */
94
+ scopes;
77
95
  /**
78
96
  * Creates an instance of SelectionManager.
79
97
  */
80
98
  constructor(props) {
81
- this._imodelToolSelectionSyncHandlers = new Map();
82
- this._hiliteSetProviders = new Map();
83
- this._knownIModels = new Set();
84
- this._currentSelection = new CurrentSelectionStorage();
85
- this._selectionChanges = new rxjs_1.Subject();
86
- this._listeners = [];
87
99
  this.selectionChange = new SelectionChangeEvent_1.SelectionChangeEvent();
88
100
  this.scopes = props.scopes;
89
101
  this.selectionStorage = props.selectionStorage ?? (0, unified_selection_1.createStorage)();
@@ -390,65 +402,13 @@ function findIModel(set, imodelKeyFactory, key) {
390
402
  }
391
403
  /** @internal */
392
404
  class ToolSelectionSyncHandler {
405
+ _selectionSourceName = "Tool";
406
+ _logicalSelection;
407
+ _imodel;
408
+ _imodelToolSelectionListenerDisposeFunc;
409
+ _asyncsTracker = new presentation_common_1.AsyncTasksTracker();
410
+ isSuspended;
393
411
  constructor(imodel, logicalSelection) {
394
- this._selectionSourceName = "Tool";
395
- this._asyncsTracker = new presentation_common_1.AsyncTasksTracker();
396
- this.onToolSelectionChanged = async (ev) => {
397
- const env_1 = { stack: [], error: void 0, hasError: false };
398
- try {
399
- // ignore selection change event if the handler is suspended
400
- if (this.isSuspended) {
401
- return;
402
- }
403
- // this component only cares about its own imodel
404
- const imodel = ev.set.iModel;
405
- if (imodel !== this._imodel) {
406
- return;
407
- }
408
- // determine the level of selection changes
409
- // wip: may want to allow selecting at different levels?
410
- const selectionLevel = 0;
411
- let ids;
412
- switch (ev.type) {
413
- case core_frontend_1.SelectionSetEventType.Add:
414
- ids = ev.additions;
415
- break;
416
- case core_frontend_1.SelectionSetEventType.Replace:
417
- ids = ev.set.active;
418
- break;
419
- default:
420
- ids = ev.removals;
421
- break;
422
- }
423
- // we're always using scoped selection changer even if the scope is set to "element" - that
424
- // makes sure we're adding to selection keys with concrete classes and not "BisCore:Element", which
425
- // we can't because otherwise our keys compare fails (presentation components load data with
426
- // concrete classes)
427
- const changer = new ScopedSelectionChanger(this._selectionSourceName, this._imodel, this._logicalSelection, (0, SelectionScopesManager_1.createSelectionScopeProps)(this._logicalSelection.scopes.activeScope));
428
- const _r = __addDisposableResource(env_1, this._asyncsTracker.trackAsyncTask(), false);
429
- switch (ev.type) {
430
- case core_frontend_1.SelectionSetEventType.Add:
431
- await changer.add(ids, selectionLevel);
432
- break;
433
- case core_frontend_1.SelectionSetEventType.Replace:
434
- await changer.replace(ids, selectionLevel);
435
- break;
436
- case core_frontend_1.SelectionSetEventType.Remove:
437
- await changer.remove(ids, selectionLevel);
438
- break;
439
- case core_frontend_1.SelectionSetEventType.Clear:
440
- await changer.clear(selectionLevel);
441
- break;
442
- }
443
- }
444
- catch (e_1) {
445
- env_1.error = e_1;
446
- env_1.hasError = true;
447
- }
448
- finally {
449
- __disposeResources(env_1);
450
- }
451
- };
452
412
  this._imodel = imodel;
453
413
  this._logicalSelection = logicalSelection;
454
414
  this._imodelToolSelectionListenerDisposeFunc = imodel.selectionSet.onChanged.addListener(this.onToolSelectionChanged);
@@ -460,6 +420,62 @@ class ToolSelectionSyncHandler {
460
420
  get pendingAsyncs() {
461
421
  return this._asyncsTracker.pendingAsyncs;
462
422
  }
423
+ onToolSelectionChanged = async (ev) => {
424
+ const env_1 = { stack: [], error: void 0, hasError: false };
425
+ try {
426
+ // ignore selection change event if the handler is suspended
427
+ if (this.isSuspended) {
428
+ return;
429
+ }
430
+ // this component only cares about its own imodel
431
+ const imodel = ev.set.iModel;
432
+ if (imodel !== this._imodel) {
433
+ return;
434
+ }
435
+ // determine the level of selection changes
436
+ // wip: may want to allow selecting at different levels?
437
+ const selectionLevel = 0;
438
+ let ids;
439
+ switch (ev.type) {
440
+ case core_frontend_1.SelectionSetEventType.Add:
441
+ ids = ev.additions;
442
+ break;
443
+ case core_frontend_1.SelectionSetEventType.Replace:
444
+ ids = ev.set.active;
445
+ break;
446
+ default:
447
+ ids = ev.removals;
448
+ break;
449
+ }
450
+ // we're always using scoped selection changer even if the scope is set to "element" - that
451
+ // makes sure we're adding to selection keys with concrete classes and not "BisCore:Element", which
452
+ // we can't because otherwise our keys compare fails (presentation components load data with
453
+ // concrete classes)
454
+ const changer = new ScopedSelectionChanger(this._selectionSourceName, this._imodel, this._logicalSelection, (0, SelectionScopesManager_1.createSelectionScopeProps)(this._logicalSelection.scopes.activeScope));
455
+ const _r = __addDisposableResource(env_1, this._asyncsTracker.trackAsyncTask(), false);
456
+ switch (ev.type) {
457
+ case core_frontend_1.SelectionSetEventType.Add:
458
+ await changer.add(ids, selectionLevel);
459
+ break;
460
+ case core_frontend_1.SelectionSetEventType.Replace:
461
+ await changer.replace(ids, selectionLevel);
462
+ break;
463
+ case core_frontend_1.SelectionSetEventType.Remove:
464
+ await changer.remove(ids, selectionLevel);
465
+ break;
466
+ case core_frontend_1.SelectionSetEventType.Clear:
467
+ await changer.clear(selectionLevel);
468
+ break;
469
+ }
470
+ }
471
+ catch (e_1) {
472
+ env_1.error = e_1;
473
+ env_1.hasError = true;
474
+ }
475
+ finally {
476
+ __disposeResources(env_1);
477
+ }
478
+ };
463
479
  }
464
480
  exports.ToolSelectionSyncHandler = ToolSelectionSyncHandler;
465
481
  const parseElementIds = (ids) => {
@@ -503,6 +519,10 @@ function addKeys(target, className, ids) {
503
519
  }
504
520
  }
505
521
  class ScopedSelectionChanger {
522
+ name;
523
+ imodel;
524
+ manager;
525
+ scope;
506
526
  constructor(name, imodel, manager, scope) {
507
527
  this.name = name;
508
528
  this.imodel = imodel;
@@ -542,9 +562,7 @@ class ScopedSelectionChanger {
542
562
  }
543
563
  /** Stores current selection in `KeySet` format per iModel. */
544
564
  class CurrentSelectionStorage {
545
- constructor() {
546
- this._currentSelection = new Map();
547
- }
565
+ _currentSelection = new Map();
548
566
  getCurrentSelectionStorage(imodelKey) {
549
567
  let storage = this._currentSelection.get(imodelKey);
550
568
  if (!storage) {
@@ -568,9 +586,7 @@ class CurrentSelectionStorage {
568
586
  * It always stores result of latest resolved call to `computeSelection`.
569
587
  */
570
588
  class IModelSelectionStorage {
571
- constructor() {
572
- this._currentSelection = new Map();
573
- }
589
+ _currentSelection = new Map();
574
590
  getSelection(level) {
575
591
  let entry = this._currentSelection.get(level);
576
592
  if (!entry) {