@itwin/presentation-frontend 4.0.0-dev.21 → 4.0.0-dev.23

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 (123) hide show
  1. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  2. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +47 -47
  3. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  4. package/lib/cjs/presentation-frontend/Diagnostics.d.ts +14 -14
  5. package/lib/cjs/presentation-frontend/Diagnostics.js +61 -61
  6. package/lib/cjs/presentation-frontend/Diagnostics.js.map +1 -1
  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/FrontendLoggerCategory.js.map +1 -1
  10. package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  11. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +41 -41
  12. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  13. package/lib/cjs/presentation-frontend/LocalizationHelper.d.ts +10 -10
  14. package/lib/cjs/presentation-frontend/LocalizationHelper.js +31 -31
  15. package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
  16. package/lib/cjs/presentation-frontend/Presentation.d.ts +73 -73
  17. package/lib/cjs/presentation-frontend/Presentation.js +160 -160
  18. package/lib/cjs/presentation-frontend/Presentation.js.map +1 -1
  19. package/lib/cjs/presentation-frontend/PresentationManager.d.ts +186 -186
  20. package/lib/cjs/presentation-frontend/PresentationManager.js +436 -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/RulesetManager.js.map +1 -1
  25. package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  26. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +195 -195
  27. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  28. package/lib/cjs/presentation-frontend/StateTracker.d.ts +38 -38
  29. package/lib/cjs/presentation-frontend/StateTracker.js +129 -129
  30. package/lib/cjs/presentation-frontend/StateTracker.js.map +1 -1
  31. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  32. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +525 -525
  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 +293 -293
  36. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  37. package/lib/cjs/presentation-frontend/selection/HiliteRules.json +172 -172
  38. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  39. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +97 -97
  40. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  41. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  42. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +9 -9
  43. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  44. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  45. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +33 -33
  46. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  47. package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  48. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +108 -108
  49. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  50. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts +17 -17
  51. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +40 -40
  52. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  53. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  54. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +414 -414
  55. package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
  56. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  57. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +91 -91
  58. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  59. package/lib/cjs/presentation-frontend.d.ts +34 -34
  60. package/lib/cjs/presentation-frontend.js +50 -50
  61. package/lib/cjs/presentation-frontend.js.map +1 -1
  62. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
  63. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +43 -43
  64. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  65. package/lib/esm/presentation-frontend/Diagnostics.d.ts +14 -14
  66. package/lib/esm/presentation-frontend/Diagnostics.js +56 -56
  67. package/lib/esm/presentation-frontend/Diagnostics.js.map +1 -1
  68. package/lib/esm/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
  69. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +17 -17
  70. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  71. package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
  72. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +37 -37
  73. package/lib/esm/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  74. package/lib/esm/presentation-frontend/LocalizationHelper.d.ts +10 -10
  75. package/lib/esm/presentation-frontend/LocalizationHelper.js +27 -27
  76. package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
  77. package/lib/esm/presentation-frontend/Presentation.d.ts +73 -73
  78. package/lib/esm/presentation-frontend/Presentation.js +156 -156
  79. package/lib/esm/presentation-frontend/Presentation.js.map +1 -1
  80. package/lib/esm/presentation-frontend/PresentationManager.d.ts +186 -186
  81. package/lib/esm/presentation-frontend/PresentationManager.js +431 -431
  82. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  83. package/lib/esm/presentation-frontend/RulesetManager.d.ts +63 -63
  84. package/lib/esm/presentation-frontend/RulesetManager.js +81 -81
  85. package/lib/esm/presentation-frontend/RulesetManager.js.map +1 -1
  86. package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
  87. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +191 -191
  88. package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  89. package/lib/esm/presentation-frontend/StateTracker.d.ts +38 -38
  90. package/lib/esm/presentation-frontend/StateTracker.js +125 -125
  91. package/lib/esm/presentation-frontend/StateTracker.js.map +1 -1
  92. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
  93. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +519 -519
  94. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  95. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
  96. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +285 -285
  97. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  98. package/lib/esm/presentation-frontend/selection/HiliteRules.json +172 -172
  99. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
  100. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +93 -93
  101. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  102. package/lib/esm/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
  103. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +8 -8
  104. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  105. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
  106. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +29 -29
  107. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  108. package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
  109. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +104 -104
  110. package/lib/esm/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  111. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts +17 -17
  112. package/lib/esm/presentation-frontend/selection/SelectionHelper.js +36 -36
  113. package/lib/esm/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  114. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +139 -139
  115. package/lib/esm/presentation-frontend/selection/SelectionManager.js +409 -409
  116. package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
  117. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
  118. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +85 -85
  119. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  120. package/lib/esm/presentation-frontend.d.ts +34 -34
  121. package/lib/esm/presentation-frontend.js +38 -38
  122. package/lib/esm/presentation-frontend.js.map +1 -1
  123. package/package.json +14 -14
@@ -1,294 +1,294 @@
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
+ 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;
294
294
  //# sourceMappingURL=FavoritePropertiesStorage.js.map