@itwin/presentation-frontend 4.0.0-dev.7 → 4.0.0-dev.72

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 (113) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  3. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +47 -47
  4. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  5. package/lib/cjs/presentation-frontend/Diagnostics.d.ts +14 -14
  6. package/lib/cjs/presentation-frontend/Diagnostics.js +61 -61
  7. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  8. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js +20 -20
  9. package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  10. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +41 -41
  11. package/lib/cjs/presentation-frontend/LocalizationHelper.d.ts +10 -10
  12. package/lib/cjs/presentation-frontend/LocalizationHelper.js +31 -31
  13. package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
  14. package/lib/cjs/presentation-frontend/Presentation.d.ts +73 -75
  15. package/lib/cjs/presentation-frontend/Presentation.d.ts.map +1 -1
  16. package/lib/cjs/presentation-frontend/Presentation.js +159 -162
  17. package/lib/cjs/presentation-frontend/Presentation.js.map +1 -1
  18. package/lib/cjs/presentation-frontend/PresentationManager.d.ts +205 -186
  19. package/lib/cjs/presentation-frontend/PresentationManager.d.ts.map +1 -1
  20. package/lib/cjs/presentation-frontend/PresentationManager.js +438 -436
  21. package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
  22. package/lib/cjs/presentation-frontend/RulesetManager.d.ts +63 -63
  23. package/lib/cjs/presentation-frontend/RulesetManager.js +85 -85
  24. package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  25. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +195 -195
  26. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  27. package/lib/cjs/presentation-frontend/StateTracker.d.ts +38 -38
  28. package/lib/cjs/presentation-frontend/StateTracker.js +128 -129
  29. package/lib/cjs/presentation-frontend/StateTracker.js.map +1 -1
  30. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  31. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  32. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +519 -518
  33. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  34. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  35. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +290 -293
  36. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  37. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  38. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +97 -97
  39. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  40. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +9 -9
  41. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  42. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +33 -33
  43. package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  44. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +108 -108
  45. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts +17 -14
  46. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  47. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +40 -37
  48. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  49. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  50. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +414 -414
  51. package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
  52. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  53. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +91 -91
  54. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  55. package/lib/cjs/presentation-frontend.d.ts +34 -34
  56. package/lib/cjs/presentation-frontend.js +54 -50
  57. package/lib/cjs/presentation-frontend.js.map +1 -1
  58. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  59. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +43 -43
  60. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  61. package/lib/esm/presentation-frontend/Diagnostics.d.ts +14 -14
  62. package/lib/esm/presentation-frontend/Diagnostics.js +56 -56
  63. package/lib/esm/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  64. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +17 -17
  65. package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  66. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +37 -37
  67. package/lib/esm/presentation-frontend/LocalizationHelper.d.ts +10 -10
  68. package/lib/esm/presentation-frontend/LocalizationHelper.js +27 -27
  69. package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
  70. package/lib/esm/presentation-frontend/Presentation.d.ts +73 -75
  71. package/lib/esm/presentation-frontend/Presentation.d.ts.map +1 -1
  72. package/lib/esm/presentation-frontend/Presentation.js +155 -158
  73. package/lib/esm/presentation-frontend/Presentation.js.map +1 -1
  74. package/lib/esm/presentation-frontend/PresentationManager.d.ts +205 -186
  75. package/lib/esm/presentation-frontend/PresentationManager.d.ts.map +1 -1
  76. package/lib/esm/presentation-frontend/PresentationManager.js +433 -431
  77. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  78. package/lib/esm/presentation-frontend/RulesetManager.d.ts +63 -63
  79. package/lib/esm/presentation-frontend/RulesetManager.js +81 -81
  80. package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  81. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +191 -191
  82. package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  83. package/lib/esm/presentation-frontend/StateTracker.d.ts +38 -38
  84. package/lib/esm/presentation-frontend/StateTracker.js +124 -125
  85. package/lib/esm/presentation-frontend/StateTracker.js.map +1 -1
  86. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  87. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  88. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +514 -512
  89. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  90. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  91. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +282 -285
  92. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  93. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  94. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +93 -93
  95. package/lib/esm/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  96. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +8 -8
  97. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  98. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +29 -29
  99. package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  100. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +104 -104
  101. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts +17 -14
  102. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  103. package/lib/esm/presentation-frontend/selection/SelectionHelper.js +36 -33
  104. package/lib/esm/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  105. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  106. package/lib/esm/presentation-frontend/selection/SelectionManager.js +409 -409
  107. package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
  108. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  109. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +85 -85
  110. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  111. package/lib/esm/presentation-frontend.d.ts +34 -34
  112. package/lib/esm/presentation-frontend.js +38 -38
  113. package/package.json +20 -20
@@ -1,294 +1,291 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Core
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.BrowserLocalFavoritePropertiesStorage = exports.NoopFavoritePropertiesStorage = exports.OfflineCachingFavoritePropertiesStorage = exports.IModelAppFavoritePropertiesStorage = exports.createFavoritePropertiesStorage = exports.DefaultFavoritePropertiesStorageTypes = exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME = exports.FAVORITE_PROPERTIES_SETTING_NAME = exports.DEPRECATED_PROPERTIES_SETTING_NAMESPACE = exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const core_common_1 = require("@itwin/core-common");
13
- const core_frontend_1 = require("@itwin/core-frontend");
14
- const presentation_common_1 = require("@itwin/presentation-common");
15
- const ConnectivityInformationProvider_1 = require("../ConnectivityInformationProvider");
16
- /** @internal */
17
- exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE = "imodeljs.presentation";
18
- /** @internal */
19
- exports.DEPRECATED_PROPERTIES_SETTING_NAMESPACE = "Properties";
20
- /** @internal */
21
- exports.FAVORITE_PROPERTIES_SETTING_NAME = "FavoriteProperties";
22
- /** @internal */
23
- exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME = "FavoritePropertiesOrderInfo";
24
- /**
25
- * Available implementations of [[IFavoritePropertiesStorage]].
26
- * @public
27
- */
28
- var DefaultFavoritePropertiesStorageTypes;
29
- (function (DefaultFavoritePropertiesStorageTypes) {
30
- /** A no-op storage that doesn't store or return anything. Used for cases when favorite properties aren't used by the application. */
31
- DefaultFavoritePropertiesStorageTypes[DefaultFavoritePropertiesStorageTypes["Noop"] = 0] = "Noop";
32
- /** A storage that stores favorite properties information in a browser local storage. */
33
- DefaultFavoritePropertiesStorageTypes[DefaultFavoritePropertiesStorageTypes["BrowserLocalStorage"] = 1] = "BrowserLocalStorage";
34
- /** A storage that stores favorite properties in a user preferences storage (see [[IModelApp.userPreferences]]). */
35
- DefaultFavoritePropertiesStorageTypes[DefaultFavoritePropertiesStorageTypes["UserPreferencesStorage"] = 2] = "UserPreferencesStorage";
36
- })(DefaultFavoritePropertiesStorageTypes = exports.DefaultFavoritePropertiesStorageTypes || (exports.DefaultFavoritePropertiesStorageTypes = {}));
37
- /**
38
- * A factory method to create one of the available [[IFavoritePropertiesStorage]] implementations.
39
- * @public
40
- */
41
- function createFavoritePropertiesStorage(type) {
42
- switch (type) {
43
- case DefaultFavoritePropertiesStorageTypes.Noop: return new NoopFavoritePropertiesStorage();
44
- case DefaultFavoritePropertiesStorageTypes.BrowserLocalStorage: return new BrowserLocalFavoritePropertiesStorage();
45
- case DefaultFavoritePropertiesStorageTypes.UserPreferencesStorage: return new OfflineCachingFavoritePropertiesStorage({ impl: new IModelAppFavoritePropertiesStorage() });
46
- }
47
- }
48
- exports.createFavoritePropertiesStorage = createFavoritePropertiesStorage;
49
- /**
50
- * @internal
51
- */
52
- class IModelAppFavoritePropertiesStorage {
53
- async ensureIsSignedIn() {
54
- const accessToken = core_frontend_1.IModelApp.authorizationClient ? await core_frontend_1.IModelApp.authorizationClient.getAccessToken() : "";
55
- if (accessToken)
56
- return { accessToken };
57
- throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "Current user is not authorized to use the settings service");
58
- }
59
- async loadProperties(iTwinId, imodelId) {
60
- if (!core_frontend_1.IModelApp.userPreferences)
61
- throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "User preferences service is not set up");
62
- const { accessToken } = await this.ensureIsSignedIn();
63
- let setting = await core_frontend_1.IModelApp.userPreferences.get({
64
- accessToken,
65
- iTwinId,
66
- iModelId: imodelId,
67
- namespace: exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE,
68
- key: exports.FAVORITE_PROPERTIES_SETTING_NAME,
69
- });
70
- if (setting !== undefined)
71
- return new Set(setting);
72
- // try to check the old namespace
73
- setting = await core_frontend_1.IModelApp.userPreferences.get({
74
- accessToken,
75
- iTwinId,
76
- iModelId: imodelId,
77
- namespace: exports.DEPRECATED_PROPERTIES_SETTING_NAMESPACE,
78
- key: exports.FAVORITE_PROPERTIES_SETTING_NAME,
79
- });
80
- if (setting !== undefined && setting.hasOwnProperty("nestedContentInfos") && setting.hasOwnProperty("propertyInfos") && setting.hasOwnProperty("baseFieldInfos"))
81
- return new Set([...setting.nestedContentInfos, ...setting.propertyInfos, ...setting.baseFieldInfos]);
82
- return undefined;
83
- }
84
- async saveProperties(properties, iTwinId, imodelId) {
85
- if (!core_frontend_1.IModelApp.userPreferences)
86
- throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "User preferences service is not set up");
87
- const { accessToken } = await this.ensureIsSignedIn();
88
- await core_frontend_1.IModelApp.userPreferences.save({
89
- accessToken,
90
- iTwinId,
91
- iModelId: imodelId,
92
- namespace: exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE,
93
- key: exports.FAVORITE_PROPERTIES_SETTING_NAME,
94
- content: Array.from(properties),
95
- });
96
- }
97
- async loadPropertiesOrder(iTwinId, imodelId) {
98
- if (!core_frontend_1.IModelApp.userPreferences)
99
- throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "User preferences service is not set up");
100
- const { accessToken } = await this.ensureIsSignedIn();
101
- const setting = await core_frontend_1.IModelApp.userPreferences.get({
102
- accessToken,
103
- iTwinId,
104
- iModelId: imodelId,
105
- namespace: exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE,
106
- key: exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME,
107
- });
108
- return setting;
109
- }
110
- async savePropertiesOrder(orderInfos, iTwinId, imodelId) {
111
- if (!core_frontend_1.IModelApp.userPreferences)
112
- throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "User preferences service is not set up");
113
- const { accessToken } = await this.ensureIsSignedIn();
114
- await core_frontend_1.IModelApp.userPreferences.save({
115
- accessToken,
116
- iTwinId,
117
- iModelId: imodelId,
118
- namespace: exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE,
119
- key: exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME,
120
- content: orderInfos,
121
- });
122
- }
123
- }
124
- exports.IModelAppFavoritePropertiesStorage = IModelAppFavoritePropertiesStorage;
125
- /** @internal */
126
- class OfflineCachingFavoritePropertiesStorage {
127
- constructor(props) {
128
- var _a;
129
- this._propertiesOfflineCache = new DictionaryWithReservations(iTwinAndIModelIdsKeyComparer);
130
- this._propertiesOrderOfflineCache = new DictionaryWithReservations(iTwinAndIModelIdsKeyComparer);
131
- // eslint-disable-next-line @typescript-eslint/naming-convention
132
- this.onConnectivityStatusChanged = (args) => {
133
- // istanbul ignore else
134
- if (args.status === core_common_1.InternetConnectivityStatus.Online) {
135
- // note: we're copying the cached values to temp arrays because `saveProperties` and `savePropertiesOrder` both
136
- // attempt to modify cache dictionaries
137
- const propertiesCache = new Array();
138
- this._propertiesOfflineCache.forEach((key, value) => propertiesCache.push({ properties: value, iTwinId: key[0], imodelId: key[1] }));
139
- propertiesCache.forEach(async (cached) => this.saveProperties(cached.properties, cached.iTwinId, cached.imodelId));
140
- const ordersCache = new Array();
141
- this._propertiesOrderOfflineCache.forEach((key, value) => ordersCache.push({ order: value, iTwinId: key[0], imodelId: key[1] }));
142
- ordersCache.forEach(async (cached) => this.savePropertiesOrder(cached.order, cached.iTwinId, cached.imodelId));
143
- }
144
- };
145
- this._impl = props.impl;
146
- // istanbul ignore next
147
- this._connectivityInfo = (_a = props.connectivityInfo) !== null && _a !== void 0 ? _a : new ConnectivityInformationProvider_1.ConnectivityInformationProvider();
148
- this._connectivityInfo.onInternetConnectivityChanged.addListener(this.onConnectivityStatusChanged);
149
- }
150
- dispose() {
151
- if ((0, core_bentley_1.isIDisposable)(this._connectivityInfo))
152
- this._connectivityInfo.dispose();
153
- }
154
- get impl() { return this._impl; }
155
- async loadProperties(iTwinId, imodelId) {
156
- if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Online) {
157
- try {
158
- return await this._impl.loadProperties(iTwinId, imodelId);
159
- }
160
- catch {
161
- // return from offline cache if the above fails
162
- }
163
- }
164
- return this._propertiesOfflineCache.get([iTwinId, imodelId]);
165
- }
166
- async saveProperties(properties, iTwinId, imodelId) {
167
- const key = [iTwinId, imodelId];
168
- if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Offline) {
169
- this._propertiesOfflineCache.set(key, properties);
170
- return;
171
- }
172
- const reservationId = this._propertiesOfflineCache.reserve(key);
173
- try {
174
- await this._impl.saveProperties(properties, iTwinId, imodelId);
175
- this._propertiesOfflineCache.reservedDelete(key, reservationId);
176
- }
177
- catch {
178
- this._propertiesOfflineCache.reservedSet(key, properties, reservationId);
179
- }
180
- }
181
- async loadPropertiesOrder(iTwinId, imodelId) {
182
- if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Online) {
183
- try {
184
- return await this._impl.loadPropertiesOrder(iTwinId, imodelId);
185
- }
186
- catch {
187
- // return from offline cache if the above fails
188
- }
189
- }
190
- return this._propertiesOrderOfflineCache.get([iTwinId, imodelId]);
191
- }
192
- async savePropertiesOrder(orderInfos, iTwinId, imodelId) {
193
- const key = [iTwinId, imodelId];
194
- if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Offline) {
195
- this._propertiesOrderOfflineCache.set(key, orderInfos);
196
- return;
197
- }
198
- const reservationId = this._propertiesOrderOfflineCache.reserve(key);
199
- try {
200
- await this._impl.savePropertiesOrder(orderInfos, iTwinId, imodelId);
201
- this._propertiesOrderOfflineCache.reservedDelete(key, reservationId);
202
- }
203
- catch {
204
- this._propertiesOrderOfflineCache.reservedSet(key, orderInfos, reservationId);
205
- }
206
- }
207
- }
208
- exports.OfflineCachingFavoritePropertiesStorage = OfflineCachingFavoritePropertiesStorage;
209
- class DictionaryWithReservations {
210
- constructor(compareKeys) {
211
- this._impl = new core_bentley_1.Dictionary(compareKeys);
212
- }
213
- get(key) { var _a; return (_a = this._impl.get(key)) === null || _a === void 0 ? void 0 : _a.value; }
214
- forEach(func) {
215
- this._impl.forEach((key, entry) => {
216
- // istanbul ignore else
217
- if (entry.value)
218
- func(key, entry.value);
219
- });
220
- }
221
- reserve(key) {
222
- const reservationId = core_bentley_1.Guid.createValue();
223
- this._impl.set(key, { lastReservationId: reservationId });
224
- return reservationId;
225
- }
226
- set(key, value) { return this._impl.set(key, { value }); }
227
- reservedSet(key, value, reservationId) {
228
- const entry = this._impl.get(key);
229
- if (entry && entry.lastReservationId === reservationId)
230
- this._impl.set(key, { value });
231
- }
232
- reservedDelete(key, reservationId) {
233
- const entry = this._impl.get(key);
234
- if (entry && entry.lastReservationId === reservationId)
235
- this._impl.delete(key);
236
- }
237
- }
238
- // istanbul ignore next
239
- function iTwinAndIModelIdsKeyComparer(lhs, rhs) {
240
- var _a, _b, _c, _d;
241
- const iTwinIdCompare = (0, core_bentley_1.compareStrings)((_a = lhs[0]) !== null && _a !== void 0 ? _a : "", (_b = rhs[0]) !== null && _b !== void 0 ? _b : "");
242
- return (iTwinIdCompare !== 0) ? iTwinIdCompare : (0, core_bentley_1.compareStrings)((_c = lhs[1]) !== null && _c !== void 0 ? _c : "", (_d = rhs[1]) !== null && _d !== void 0 ? _d : "");
243
- }
244
- /** @internal */
245
- class NoopFavoritePropertiesStorage {
246
- // istanbul ignore next
247
- async loadProperties(_iTwinId, _imodelId) { return undefined; }
248
- // istanbul ignore next
249
- async saveProperties(_properties, _iTwinId, _imodelId) { }
250
- // istanbul ignore next
251
- async loadPropertiesOrder(_iTwinId, _imodelId) { return undefined; }
252
- // istanbul ignore next
253
- async savePropertiesOrder(_orderInfos, _iTwinId, _imodelId) { }
254
- }
255
- exports.NoopFavoritePropertiesStorage = NoopFavoritePropertiesStorage;
256
- /** @internal */
257
- class BrowserLocalFavoritePropertiesStorage {
258
- constructor(props) {
259
- var _a;
260
- // istanbul ignore next
261
- this._localStorage = (_a = props === null || props === void 0 ? void 0 : props.localStorage) !== null && _a !== void 0 ? _a : window.localStorage;
262
- }
263
- createFavoritesSettingItemKey(iTwinId, imodelId) {
264
- return `${exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE}${exports.FAVORITE_PROPERTIES_SETTING_NAME}?iTwinId=${iTwinId}&imodelId=${imodelId}`;
265
- }
266
- createOrderSettingItemKey(iTwinId, imodelId) {
267
- return `${exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE}${exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME}?iTwinId=${iTwinId}&imodelId=${imodelId}`;
268
- }
269
- async loadProperties(iTwinId, imodelId) {
270
- const value = this._localStorage.getItem(this.createFavoritesSettingItemKey(iTwinId, imodelId));
271
- if (!value)
272
- return undefined;
273
- const properties = JSON.parse(value);
274
- return new Set(properties);
275
- }
276
- async saveProperties(properties, iTwinId, imodelId) {
277
- this._localStorage.setItem(this.createFavoritesSettingItemKey(iTwinId, imodelId), JSON.stringify([...properties]));
278
- }
279
- async loadPropertiesOrder(iTwinId, imodelId) {
280
- const value = this._localStorage.getItem(this.createOrderSettingItemKey(iTwinId, imodelId));
281
- if (!value)
282
- return undefined;
283
- const orderInfos = JSON.parse(value).map((json) => ({
284
- ...json,
285
- orderedTimestamp: new Date(json.orderedTimestamp),
286
- }));
287
- return orderInfos;
288
- }
289
- async savePropertiesOrder(orderInfos, iTwinId, imodelId) {
290
- this._localStorage.setItem(this.createOrderSettingItemKey(iTwinId, imodelId), JSON.stringify(orderInfos));
291
- }
292
- }
293
- exports.BrowserLocalFavoritePropertiesStorage = BrowserLocalFavoritePropertiesStorage;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Core
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.BrowserLocalFavoritePropertiesStorage = exports.NoopFavoritePropertiesStorage = exports.OfflineCachingFavoritePropertiesStorage = exports.IModelAppFavoritePropertiesStorage = exports.createFavoritePropertiesStorage = exports.DefaultFavoritePropertiesStorageTypes = exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME = exports.FAVORITE_PROPERTIES_SETTING_NAME = exports.DEPRECATED_PROPERTIES_SETTING_NAMESPACE = exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ const core_frontend_1 = require("@itwin/core-frontend");
14
+ const presentation_common_1 = require("@itwin/presentation-common");
15
+ const ConnectivityInformationProvider_1 = require("../ConnectivityInformationProvider");
16
+ /** @internal */
17
+ exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE = "imodeljs.presentation";
18
+ /** @internal */
19
+ exports.DEPRECATED_PROPERTIES_SETTING_NAMESPACE = "Properties";
20
+ /** @internal */
21
+ exports.FAVORITE_PROPERTIES_SETTING_NAME = "FavoriteProperties";
22
+ /** @internal */
23
+ exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME = "FavoritePropertiesOrderInfo";
24
+ /**
25
+ * Available implementations of [[IFavoritePropertiesStorage]].
26
+ * @public
27
+ */
28
+ var DefaultFavoritePropertiesStorageTypes;
29
+ (function (DefaultFavoritePropertiesStorageTypes) {
30
+ /** A no-op storage that doesn't store or return anything. Used for cases when favorite properties aren't used by the application. */
31
+ DefaultFavoritePropertiesStorageTypes[DefaultFavoritePropertiesStorageTypes["Noop"] = 0] = "Noop";
32
+ /** A storage that stores favorite properties information in a browser local storage. */
33
+ DefaultFavoritePropertiesStorageTypes[DefaultFavoritePropertiesStorageTypes["BrowserLocalStorage"] = 1] = "BrowserLocalStorage";
34
+ /** A storage that stores favorite properties in a user preferences storage (see [[IModelApp.userPreferences]]). */
35
+ DefaultFavoritePropertiesStorageTypes[DefaultFavoritePropertiesStorageTypes["UserPreferencesStorage"] = 2] = "UserPreferencesStorage";
36
+ })(DefaultFavoritePropertiesStorageTypes = exports.DefaultFavoritePropertiesStorageTypes || (exports.DefaultFavoritePropertiesStorageTypes = {}));
37
+ /**
38
+ * A factory method to create one of the available [[IFavoritePropertiesStorage]] implementations.
39
+ * @public
40
+ */
41
+ function createFavoritePropertiesStorage(type) {
42
+ switch (type) {
43
+ case DefaultFavoritePropertiesStorageTypes.Noop: return new NoopFavoritePropertiesStorage();
44
+ case DefaultFavoritePropertiesStorageTypes.BrowserLocalStorage: return new BrowserLocalFavoritePropertiesStorage();
45
+ case DefaultFavoritePropertiesStorageTypes.UserPreferencesStorage: return new OfflineCachingFavoritePropertiesStorage({ impl: new IModelAppFavoritePropertiesStorage() });
46
+ }
47
+ }
48
+ exports.createFavoritePropertiesStorage = createFavoritePropertiesStorage;
49
+ /**
50
+ * @internal
51
+ */
52
+ class IModelAppFavoritePropertiesStorage {
53
+ async ensureIsSignedIn() {
54
+ const accessToken = core_frontend_1.IModelApp.authorizationClient ? await core_frontend_1.IModelApp.authorizationClient.getAccessToken() : "";
55
+ if (accessToken)
56
+ return { accessToken };
57
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "Current user is not authorized to use the settings service");
58
+ }
59
+ async loadProperties(iTwinId, imodelId) {
60
+ if (!core_frontend_1.IModelApp.userPreferences)
61
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "User preferences service is not set up");
62
+ const { accessToken } = await this.ensureIsSignedIn();
63
+ let setting = await core_frontend_1.IModelApp.userPreferences.get({
64
+ accessToken,
65
+ iTwinId,
66
+ iModelId: imodelId,
67
+ namespace: exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE,
68
+ key: exports.FAVORITE_PROPERTIES_SETTING_NAME,
69
+ });
70
+ if (setting !== undefined)
71
+ return new Set(setting);
72
+ // try to check the old namespace
73
+ setting = await core_frontend_1.IModelApp.userPreferences.get({
74
+ accessToken,
75
+ iTwinId,
76
+ iModelId: imodelId,
77
+ namespace: exports.DEPRECATED_PROPERTIES_SETTING_NAMESPACE,
78
+ key: exports.FAVORITE_PROPERTIES_SETTING_NAME,
79
+ });
80
+ if (setting !== undefined && setting.hasOwnProperty("nestedContentInfos") && setting.hasOwnProperty("propertyInfos") && setting.hasOwnProperty("baseFieldInfos"))
81
+ return new Set([...setting.nestedContentInfos, ...setting.propertyInfos, ...setting.baseFieldInfos]);
82
+ return undefined;
83
+ }
84
+ async saveProperties(properties, iTwinId, imodelId) {
85
+ if (!core_frontend_1.IModelApp.userPreferences)
86
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "User preferences service is not set up");
87
+ const { accessToken } = await this.ensureIsSignedIn();
88
+ await core_frontend_1.IModelApp.userPreferences.save({
89
+ accessToken,
90
+ iTwinId,
91
+ iModelId: imodelId,
92
+ namespace: exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE,
93
+ key: exports.FAVORITE_PROPERTIES_SETTING_NAME,
94
+ content: Array.from(properties),
95
+ });
96
+ }
97
+ async loadPropertiesOrder(iTwinId, imodelId) {
98
+ if (!core_frontend_1.IModelApp.userPreferences)
99
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "User preferences service is not set up");
100
+ const { accessToken } = await this.ensureIsSignedIn();
101
+ const setting = await core_frontend_1.IModelApp.userPreferences.get({
102
+ accessToken,
103
+ iTwinId,
104
+ iModelId: imodelId,
105
+ namespace: exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE,
106
+ key: exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME,
107
+ });
108
+ return setting;
109
+ }
110
+ async savePropertiesOrder(orderInfos, iTwinId, imodelId) {
111
+ if (!core_frontend_1.IModelApp.userPreferences)
112
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.Error, "User preferences service is not set up");
113
+ const { accessToken } = await this.ensureIsSignedIn();
114
+ await core_frontend_1.IModelApp.userPreferences.save({
115
+ accessToken,
116
+ iTwinId,
117
+ iModelId: imodelId,
118
+ namespace: exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE,
119
+ key: exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME,
120
+ content: orderInfos,
121
+ });
122
+ }
123
+ }
124
+ exports.IModelAppFavoritePropertiesStorage = IModelAppFavoritePropertiesStorage;
125
+ /** @internal */
126
+ class OfflineCachingFavoritePropertiesStorage {
127
+ constructor(props) {
128
+ this._propertiesOfflineCache = new DictionaryWithReservations(iTwinAndIModelIdsKeyComparer);
129
+ this._propertiesOrderOfflineCache = new DictionaryWithReservations(iTwinAndIModelIdsKeyComparer);
130
+ // eslint-disable-next-line @typescript-eslint/naming-convention
131
+ this.onConnectivityStatusChanged = (args) => {
132
+ // istanbul ignore else
133
+ if (args.status === core_common_1.InternetConnectivityStatus.Online) {
134
+ // note: we're copying the cached values to temp arrays because `saveProperties` and `savePropertiesOrder` both
135
+ // attempt to modify cache dictionaries
136
+ const propertiesCache = new Array();
137
+ this._propertiesOfflineCache.forEach((key, value) => propertiesCache.push({ properties: value, iTwinId: key[0], imodelId: key[1] }));
138
+ propertiesCache.forEach(async (cached) => this.saveProperties(cached.properties, cached.iTwinId, cached.imodelId));
139
+ const ordersCache = new Array();
140
+ this._propertiesOrderOfflineCache.forEach((key, value) => ordersCache.push({ order: value, iTwinId: key[0], imodelId: key[1] }));
141
+ ordersCache.forEach(async (cached) => this.savePropertiesOrder(cached.order, cached.iTwinId, cached.imodelId));
142
+ }
143
+ };
144
+ this._impl = props.impl;
145
+ // istanbul ignore next
146
+ this._connectivityInfo = props.connectivityInfo ?? new ConnectivityInformationProvider_1.ConnectivityInformationProvider();
147
+ this._connectivityInfo.onInternetConnectivityChanged.addListener(this.onConnectivityStatusChanged);
148
+ }
149
+ dispose() {
150
+ if ((0, core_bentley_1.isIDisposable)(this._connectivityInfo))
151
+ this._connectivityInfo.dispose();
152
+ }
153
+ get impl() { return this._impl; }
154
+ async loadProperties(iTwinId, imodelId) {
155
+ if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Online) {
156
+ try {
157
+ return await this._impl.loadProperties(iTwinId, imodelId);
158
+ }
159
+ catch {
160
+ // return from offline cache if the above fails
161
+ }
162
+ }
163
+ return this._propertiesOfflineCache.get([iTwinId, imodelId]);
164
+ }
165
+ async saveProperties(properties, iTwinId, imodelId) {
166
+ const key = [iTwinId, imodelId];
167
+ if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Offline) {
168
+ this._propertiesOfflineCache.set(key, properties);
169
+ return;
170
+ }
171
+ const reservationId = this._propertiesOfflineCache.reserve(key);
172
+ try {
173
+ await this._impl.saveProperties(properties, iTwinId, imodelId);
174
+ this._propertiesOfflineCache.reservedDelete(key, reservationId);
175
+ }
176
+ catch {
177
+ this._propertiesOfflineCache.reservedSet(key, properties, reservationId);
178
+ }
179
+ }
180
+ async loadPropertiesOrder(iTwinId, imodelId) {
181
+ if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Online) {
182
+ try {
183
+ return await this._impl.loadPropertiesOrder(iTwinId, imodelId);
184
+ }
185
+ catch {
186
+ // return from offline cache if the above fails
187
+ }
188
+ }
189
+ return this._propertiesOrderOfflineCache.get([iTwinId, imodelId]);
190
+ }
191
+ async savePropertiesOrder(orderInfos, iTwinId, imodelId) {
192
+ const key = [iTwinId, imodelId];
193
+ if (this._connectivityInfo.status === core_common_1.InternetConnectivityStatus.Offline) {
194
+ this._propertiesOrderOfflineCache.set(key, orderInfos);
195
+ return;
196
+ }
197
+ const reservationId = this._propertiesOrderOfflineCache.reserve(key);
198
+ try {
199
+ await this._impl.savePropertiesOrder(orderInfos, iTwinId, imodelId);
200
+ this._propertiesOrderOfflineCache.reservedDelete(key, reservationId);
201
+ }
202
+ catch {
203
+ this._propertiesOrderOfflineCache.reservedSet(key, orderInfos, reservationId);
204
+ }
205
+ }
206
+ }
207
+ exports.OfflineCachingFavoritePropertiesStorage = OfflineCachingFavoritePropertiesStorage;
208
+ class DictionaryWithReservations {
209
+ constructor(compareKeys) {
210
+ this._impl = new core_bentley_1.Dictionary(compareKeys);
211
+ }
212
+ get(key) { return this._impl.get(key)?.value; }
213
+ forEach(func) {
214
+ this._impl.forEach((key, entry) => {
215
+ // istanbul ignore else
216
+ if (entry.value)
217
+ func(key, entry.value);
218
+ });
219
+ }
220
+ reserve(key) {
221
+ const reservationId = core_bentley_1.Guid.createValue();
222
+ this._impl.set(key, { lastReservationId: reservationId });
223
+ return reservationId;
224
+ }
225
+ set(key, value) { return this._impl.set(key, { value }); }
226
+ reservedSet(key, value, reservationId) {
227
+ const entry = this._impl.get(key);
228
+ if (entry && entry.lastReservationId === reservationId)
229
+ this._impl.set(key, { value });
230
+ }
231
+ reservedDelete(key, reservationId) {
232
+ const entry = this._impl.get(key);
233
+ if (entry && entry.lastReservationId === reservationId)
234
+ this._impl.delete(key);
235
+ }
236
+ }
237
+ // istanbul ignore next
238
+ function iTwinAndIModelIdsKeyComparer(lhs, rhs) {
239
+ const iTwinIdCompare = (0, core_bentley_1.compareStrings)(lhs[0] ?? "", rhs[0] ?? "");
240
+ return (iTwinIdCompare !== 0) ? iTwinIdCompare : (0, core_bentley_1.compareStrings)(lhs[1] ?? "", rhs[1] ?? "");
241
+ }
242
+ /** @internal */
243
+ class NoopFavoritePropertiesStorage {
244
+ // istanbul ignore next
245
+ async loadProperties(_iTwinId, _imodelId) { return undefined; }
246
+ // istanbul ignore next
247
+ async saveProperties(_properties, _iTwinId, _imodelId) { }
248
+ // istanbul ignore next
249
+ async loadPropertiesOrder(_iTwinId, _imodelId) { return undefined; }
250
+ // istanbul ignore next
251
+ async savePropertiesOrder(_orderInfos, _iTwinId, _imodelId) { }
252
+ }
253
+ exports.NoopFavoritePropertiesStorage = NoopFavoritePropertiesStorage;
254
+ /** @internal */
255
+ class BrowserLocalFavoritePropertiesStorage {
256
+ constructor(props) {
257
+ // istanbul ignore next
258
+ this._localStorage = props?.localStorage ?? window.localStorage;
259
+ }
260
+ createFavoritesSettingItemKey(iTwinId, imodelId) {
261
+ return `${exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE}${exports.FAVORITE_PROPERTIES_SETTING_NAME}?iTwinId=${iTwinId}&imodelId=${imodelId}`;
262
+ }
263
+ createOrderSettingItemKey(iTwinId, imodelId) {
264
+ return `${exports.IMODELJS_PRESENTATION_SETTING_NAMESPACE}${exports.FAVORITE_PROPERTIES_ORDER_INFO_SETTING_NAME}?iTwinId=${iTwinId}&imodelId=${imodelId}`;
265
+ }
266
+ async loadProperties(iTwinId, imodelId) {
267
+ const value = this._localStorage.getItem(this.createFavoritesSettingItemKey(iTwinId, imodelId));
268
+ if (!value)
269
+ return undefined;
270
+ const properties = JSON.parse(value);
271
+ return new Set(properties);
272
+ }
273
+ async saveProperties(properties, iTwinId, imodelId) {
274
+ this._localStorage.setItem(this.createFavoritesSettingItemKey(iTwinId, imodelId), JSON.stringify([...properties]));
275
+ }
276
+ async loadPropertiesOrder(iTwinId, imodelId) {
277
+ const value = this._localStorage.getItem(this.createOrderSettingItemKey(iTwinId, imodelId));
278
+ if (!value)
279
+ return undefined;
280
+ const orderInfos = JSON.parse(value).map((json) => ({
281
+ ...json,
282
+ orderedTimestamp: new Date(json.orderedTimestamp),
283
+ }));
284
+ return orderInfos;
285
+ }
286
+ async savePropertiesOrder(orderInfos, iTwinId, imodelId) {
287
+ this._localStorage.setItem(this.createOrderSettingItemKey(iTwinId, imodelId), JSON.stringify(orderInfos));
288
+ }
289
+ }
290
+ exports.BrowserLocalFavoritePropertiesStorage = BrowserLocalFavoritePropertiesStorage;
294
291
  //# sourceMappingURL=FavoritePropertiesStorage.js.map