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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/CHANGELOG.md +63 -1
  2. package/LICENSE.md +1 -1
  3. package/README.md +1 -1
  4. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.d.ts.map +1 -1
  5. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +10 -6
  6. package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  7. package/lib/cjs/presentation-frontend/Diagnostics.d.ts.map +1 -1
  8. package/lib/cjs/presentation-frontend/Diagnostics.js +18 -13
  9. package/lib/cjs/presentation-frontend/Diagnostics.js.map +1 -1
  10. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js +3 -3
  11. package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  12. package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts.map +1 -1
  13. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +3 -3
  14. package/lib/cjs/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  15. package/lib/cjs/presentation-frontend/LocalizationHelper.js +3 -3
  16. package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
  17. package/lib/cjs/presentation-frontend/Presentation.d.ts +1 -1
  18. package/lib/cjs/presentation-frontend/Presentation.d.ts.map +1 -1
  19. package/lib/cjs/presentation-frontend/Presentation.js +36 -21
  20. package/lib/cjs/presentation-frontend/Presentation.js.map +1 -1
  21. package/lib/cjs/presentation-frontend/PresentationManager.d.ts +84 -21
  22. package/lib/cjs/presentation-frontend/PresentationManager.d.ts.map +1 -1
  23. package/lib/cjs/presentation-frontend/PresentationManager.js +245 -154
  24. package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
  25. package/lib/cjs/presentation-frontend/RulesetManager.d.ts.map +1 -1
  26. package/lib/cjs/presentation-frontend/RulesetManager.js +11 -7
  27. package/lib/cjs/presentation-frontend/RulesetManager.js.map +1 -1
  28. package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts.map +1 -1
  29. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +53 -31
  30. package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  31. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.d.ts +30 -0
  32. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.d.ts.map +1 -0
  33. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.js +117 -0
  34. package/lib/cjs/presentation-frontend/StreamedResponseGenerator.js.map +1 -0
  35. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +33 -4
  36. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  37. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +172 -67
  38. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  39. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts.map +1 -1
  40. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +54 -25
  41. package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  42. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts.map +1 -1
  43. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +23 -13
  44. package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  45. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +3 -3
  46. package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  47. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts.map +1 -1
  48. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +3 -3
  49. package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  50. package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts.map +1 -1
  51. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +15 -9
  52. package/lib/cjs/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  53. package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  54. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +7 -5
  55. package/lib/cjs/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  56. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts +22 -3
  57. package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts.map +1 -1
  58. package/lib/cjs/presentation-frontend/selection/SelectionManager.js +295 -75
  59. package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
  60. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts.map +1 -1
  61. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +25 -14
  62. package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  63. package/lib/cjs/presentation-frontend.js +3 -3
  64. package/lib/cjs/presentation-frontend.js.map +1 -1
  65. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts.map +1 -1
  66. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +10 -6
  67. package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
  68. package/lib/esm/presentation-frontend/Diagnostics.d.ts.map +1 -1
  69. package/lib/esm/presentation-frontend/Diagnostics.js +18 -13
  70. package/lib/esm/presentation-frontend/Diagnostics.js.map +1 -1
  71. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +3 -3
  72. package/lib/esm/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
  73. package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts.map +1 -1
  74. package/lib/esm/presentation-frontend/IpcRequestsHandler.js +3 -3
  75. package/lib/esm/presentation-frontend/IpcRequestsHandler.js.map +1 -1
  76. package/lib/esm/presentation-frontend/LocalizationHelper.js +3 -3
  77. package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
  78. package/lib/esm/presentation-frontend/Presentation.d.ts +1 -1
  79. package/lib/esm/presentation-frontend/Presentation.d.ts.map +1 -1
  80. package/lib/esm/presentation-frontend/Presentation.js +36 -21
  81. package/lib/esm/presentation-frontend/Presentation.js.map +1 -1
  82. package/lib/esm/presentation-frontend/PresentationManager.d.ts +84 -21
  83. package/lib/esm/presentation-frontend/PresentationManager.d.ts.map +1 -1
  84. package/lib/esm/presentation-frontend/PresentationManager.js +244 -152
  85. package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
  86. package/lib/esm/presentation-frontend/RulesetManager.d.ts.map +1 -1
  87. package/lib/esm/presentation-frontend/RulesetManager.js +11 -7
  88. package/lib/esm/presentation-frontend/RulesetManager.js.map +1 -1
  89. package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts.map +1 -1
  90. package/lib/esm/presentation-frontend/RulesetVariablesManager.js +53 -31
  91. package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
  92. package/lib/esm/presentation-frontend/StreamedResponseGenerator.d.ts +30 -0
  93. package/lib/esm/presentation-frontend/StreamedResponseGenerator.d.ts.map +1 -0
  94. package/lib/esm/presentation-frontend/StreamedResponseGenerator.js +113 -0
  95. package/lib/esm/presentation-frontend/StreamedResponseGenerator.js.map +1 -0
  96. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +33 -4
  97. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts.map +1 -1
  98. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +172 -67
  99. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
  100. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts.map +1 -1
  101. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +54 -25
  102. package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
  103. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts.map +1 -1
  104. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +24 -14
  105. package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
  106. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +3 -3
  107. package/lib/esm/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
  108. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts.map +1 -1
  109. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +3 -3
  110. package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
  111. package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts.map +1 -1
  112. package/lib/esm/presentation-frontend/selection/SelectionHandler.js +15 -9
  113. package/lib/esm/presentation-frontend/selection/SelectionHandler.js.map +1 -1
  114. package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts.map +1 -1
  115. package/lib/esm/presentation-frontend/selection/SelectionHelper.js +7 -5
  116. package/lib/esm/presentation-frontend/selection/SelectionHelper.js.map +1 -1
  117. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +22 -3
  118. package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts.map +1 -1
  119. package/lib/esm/presentation-frontend/selection/SelectionManager.js +295 -75
  120. package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
  121. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts.map +1 -1
  122. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +25 -14
  123. package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
  124. package/lib/esm/presentation-frontend.js +3 -3
  125. package/lib/esm/presentation-frontend.js.map +1 -1
  126. package/package.json +20 -16
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
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
- *--------------------------------------------------------------------------------------------*/
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
6
  /** @packageDocumentation
7
7
  * @module Core
8
8
  */
@@ -32,21 +32,23 @@ class FavoritePropertiesManager {
32
32
  this.onFavoritesChanged = new core_bentley_1.BeEvent();
33
33
  /**
34
34
  * Initialize favorite properties for the provided IModelConnection.
35
+ * @deprecated in 4.5. Initialization is performed automatically by all async methods and only needed for deprecated [[FavoritePropertiesManager.has]] and [[FavoritePropertiesManager.sortFields]].
35
36
  */
36
37
  this.initializeConnection = async (imodel) => {
37
38
  const imodelId = imodel.iModelId;
38
39
  const iTwinId = imodel.iTwinId;
39
- if (this._globalProperties === undefined)
40
- this._globalProperties = await this._storage.loadProperties() || new Set();
40
+ if (this._globalProperties === undefined) {
41
+ this._globalProperties = (await this._storage.loadProperties()) || new Set();
42
+ }
41
43
  if (!this._iTwinProperties.has(iTwinId)) {
42
- const iTwinProperties = await this._storage.loadProperties(iTwinId) || new Set();
44
+ const iTwinProperties = (await this._storage.loadProperties(iTwinId)) || new Set();
43
45
  this._iTwinProperties.set(iTwinId, iTwinProperties);
44
46
  }
45
47
  if (!this._imodelProperties.has(getiModelInfo(iTwinId, imodelId))) {
46
- const imodelProperties = await this._storage.loadProperties(iTwinId, imodelId) || new Set();
48
+ const imodelProperties = (await this._storage.loadProperties(iTwinId, imodelId)) || new Set();
47
49
  this._imodelProperties.set(getiModelInfo(iTwinId, imodelId), imodelProperties);
48
50
  }
49
- const propertiesOrder = await this._storage.loadPropertiesOrder(iTwinId, imodelId) || [];
51
+ const propertiesOrder = (await this._storage.loadPropertiesOrder(iTwinId, imodelId)) || [];
50
52
  this._propertiesOrder.set(getiModelInfo(iTwinId, imodelId), propertiesOrder);
51
53
  await this._adjustPropertyOrderInfos(iTwinId, imodelId);
52
54
  };
@@ -62,10 +64,12 @@ class FavoritePropertiesManager {
62
64
  // favorite property infos that need to be added to the propertiesOrder array
63
65
  const infosToAdd = new Set([...globalProperties, ...iTwinProperties, ...imodelProperties]);
64
66
  for (let i = propertiesOrder.length - 1; i >= 0; i--) {
65
- if (infosToAdd.has(propertiesOrder[i].name))
67
+ if (infosToAdd.has(propertiesOrder[i].name)) {
66
68
  infosToAdd.delete(propertiesOrder[i].name);
67
- else
69
+ }
70
+ else {
68
71
  propertiesOrder.splice(i, 1);
72
+ }
69
73
  }
70
74
  infosToAdd.forEach((info) => propertiesOrder.push({
71
75
  name: info,
@@ -74,7 +78,7 @@ class FavoritePropertiesManager {
74
78
  priority: 0,
75
79
  }));
76
80
  let priority = propertiesOrder.length;
77
- propertiesOrder.forEach((oi) => oi.priority = priority--);
81
+ propertiesOrder.forEach((oi) => (oi.priority = priority--));
78
82
  };
79
83
  /**
80
84
  * Sorts an array of fields with respect to favorite property order.
@@ -82,6 +86,7 @@ class FavoritePropertiesManager {
82
86
  * @param imodel IModelConnection.
83
87
  * @param fields Array of Field's that needs to be sorted.
84
88
  * @note `initializeConnection` must be called with the `imodel` before calling this function.
89
+ * @deprecated in 4.5. Use [[FavoritePropertiesManager.sortFieldsAsync]] instead. This method is not async, therefore it requires early initialization by calling [[FavoritePropertiesManager.initializeConnection]].
85
90
  */
86
91
  this.sortFields = (imodel, fields) => {
87
92
  this.validateInitialization(imodel);
@@ -92,11 +97,15 @@ class FavoritePropertiesManager {
92
97
  const sortFunction = (left, right) => {
93
98
  const lp = fieldPriority.get(left);
94
99
  const rp = fieldPriority.get(right);
95
- return lp < rp ? 1 :
96
- lp > rp ? -1 :
97
- left.priority < right.priority ? 1 : // if favorite fields have equal priorities, sort by field priority
98
- left.priority > right.priority ? -1 :
99
- left.name.localeCompare(right.name);
100
+ return lp < rp
101
+ ? 1
102
+ : lp > rp
103
+ ? -1
104
+ : left.priority < right.priority
105
+ ? 1 // if favorite fields have equal priorities, sort by field priority
106
+ : left.priority > right.priority
107
+ ? -1
108
+ : left.name.localeCompare(right.name);
100
109
  };
101
110
  return fields.sort(sortFunction);
102
111
  };
@@ -105,17 +114,21 @@ class FavoritePropertiesManager {
105
114
  const imodelId = imodel.iModelId;
106
115
  const imodelInfo = getiModelInfo(iTwinId, imodelId);
107
116
  let baseClasses;
108
- if (this._imodelBaseClassesByClass.has(imodelInfo))
117
+ if (this._imodelBaseClassesByClass.has(imodelInfo)) {
109
118
  baseClasses = this._imodelBaseClassesByClass.get(imodelInfo);
110
- else
111
- this._imodelBaseClassesByClass.set(imodelInfo, baseClasses = {});
119
+ }
120
+ else {
121
+ this._imodelBaseClassesByClass.set(imodelInfo, (baseClasses = {}));
122
+ }
112
123
  const missingClasses = new Set();
113
124
  neededClasses.forEach((className) => {
114
- if (!baseClasses.hasOwnProperty(className))
125
+ if (!baseClasses.hasOwnProperty(className)) {
115
126
  missingClasses.add(className);
127
+ }
116
128
  });
117
- if (missingClasses.size === 0)
129
+ if (missingClasses.size === 0) {
118
130
  return baseClasses;
131
+ }
119
132
  const query = `
120
133
  SELECT (derivedSchema.Name || ':' || derivedClass.Name) AS "ClassFullName", (baseSchema.Name || ':' || baseClass.Name) AS "BaseClassFullName"
121
134
  FROM ECDbMeta.ClassHasAllBaseClasses baseClassRels
@@ -127,8 +140,9 @@ class FavoritePropertiesManager {
127
140
  const reader = imodel.createQueryReader(query, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames });
128
141
  while (await reader.step()) {
129
142
  const row = reader.current.toRow();
130
- if (!(row.classFullName in baseClasses))
143
+ if (!(row.classFullName in baseClasses)) {
131
144
  baseClasses[row.classFullName] = [];
145
+ }
132
146
  baseClasses[row.classFullName].push(row.baseClassFullName);
133
147
  }
134
148
  return baseClasses;
@@ -138,27 +152,67 @@ class FavoritePropertiesManager {
138
152
  this._imodelProperties = new Map();
139
153
  this._propertiesOrder = new Map();
140
154
  this._imodelBaseClassesByClass = new Map();
155
+ this._imodelInitializationPromises = new Map();
141
156
  }
142
157
  dispose() {
143
158
  // istanbul ignore else
144
- if ((0, core_bentley_1.isIDisposable)(this._storage))
159
+ if ((0, core_bentley_1.isIDisposable)(this._storage)) {
145
160
  this._storage.dispose();
161
+ }
146
162
  }
163
+ isInitialized(imodel) {
164
+ const iTwinId = imodel.iTwinId;
165
+ const imodelId = imodel.iModelId;
166
+ return this._imodelProperties.has(getiModelInfo(iTwinId, imodelId));
167
+ }
168
+ /**
169
+ * Checks if [[FavoritePropertiesManager.initializeConnection]] has been called for a given imodel.
170
+ * Can be removed when [[FavoritePropertiesManager.has]] and [[FavoritePropertiesManager.sortFields]] are removed.
171
+ */
147
172
  validateInitialization(imodel) {
148
173
  const iTwinId = imodel.iTwinId;
149
174
  const imodelId = imodel.iModelId;
150
- if (!this._imodelProperties.has(getiModelInfo(iTwinId, imodelId)))
175
+ if (!this.isInitialized(imodel)) {
151
176
  throw Error(`Favorite properties are not initialized for iModel: '${imodelId}', in iTwin: '${iTwinId}'. Call initializeConnection() with an IModelConnection to initialize.`);
177
+ }
178
+ }
179
+ /**
180
+ * Calls [[FavoritePropertiesManager.initializeConnection]] and caches the promise which should be awaited by calling [[FavoritePropertiesManager.ensureInitialized]].
181
+ * @internal
182
+ */
183
+ startConnectionInitialization(imodel) {
184
+ if (!this.isInitialized(imodel) && !this._imodelInitializationPromises.has(imodel)) {
185
+ // eslint-disable-next-line deprecation/deprecation
186
+ this._imodelInitializationPromises.set(imodel, this.initializeConnection(imodel));
187
+ }
188
+ }
189
+ /**
190
+ * Performs the initialization process or finishes the one that was started by [[FavoritePropertiesManager.startConnectionInitialization]].
191
+ * @internal
192
+ */
193
+ async ensureInitialized(imodel) {
194
+ if (this.isInitialized(imodel)) {
195
+ return;
196
+ }
197
+ let promise = this._imodelInitializationPromises.get(imodel);
198
+ if (!promise) {
199
+ // eslint-disable-next-line deprecation/deprecation
200
+ promise = this.initializeConnection(imodel);
201
+ // Put the promise in the map to avoid possible multiple initializations from different promises.
202
+ this._imodelInitializationPromises.set(imodel, promise);
203
+ }
204
+ await promise;
205
+ // Remove this promise from the map, because the next time this method is called, `this.isInitialized` should return true.
206
+ this._imodelInitializationPromises.delete(imodel);
152
207
  }
153
208
  /**
154
209
  * Adds favorite properties into a certain scope.
155
210
  * @param field Field that contains properties. If field contains multiple properties, all of them will be favorited.
156
211
  * @param imodel IModelConnection.
157
212
  * @param scope FavoritePropertiesScope to put the favorite properties into.
158
- * @note `initializeConnection` must be called with the `imodel` before calling this function.
159
213
  */
160
214
  async add(field, imodel, scope) {
161
- this.validateInitialization(imodel);
215
+ await this.ensureInitialized(imodel);
162
216
  const iTwinId = imodel.iTwinId;
163
217
  const imodelId = imodel.iModelId;
164
218
  let favoriteProperties;
@@ -194,10 +248,9 @@ class FavoritePropertiesManager {
194
248
  * @param field Field that contains properties. If field contains multiple properties, all of them will be un-favorited.
195
249
  * @param imodel IModelConnection.
196
250
  * @param scope FavoritePropertiesScope to remove the favorite properties from. It also removes from more general scopes.
197
- * @note `initializeConnection` must be called with the `imodel` before calling this function.
198
251
  */
199
252
  async remove(field, imodel, scope) {
200
- this.validateInitialization(imodel);
253
+ await this.ensureInitialized(imodel);
201
254
  const iTwinId = imodel.iTwinId;
202
255
  const imodelId = imodel.iModelId;
203
256
  const fieldInfos = (0, exports.getFieldInfos)(field);
@@ -228,8 +281,9 @@ class FavoritePropertiesManager {
228
281
  favoritesChanged = true;
229
282
  }
230
283
  }
231
- if (!favoritesChanged)
284
+ if (!favoritesChanged) {
232
285
  return;
286
+ }
233
287
  const propertiesOrder = this._propertiesOrder.get(getiModelInfo(iTwinId, imodelId));
234
288
  removeOrderInfos(propertiesOrder, (0, exports.createFieldOrderInfos)(field));
235
289
  saves.push(this._storage.savePropertiesOrder(propertiesOrder, iTwinId, imodelId));
@@ -240,10 +294,9 @@ class FavoritePropertiesManager {
240
294
  * Removes all favorite properties from a certain scope.
241
295
  * @param imodel IModelConnection.
242
296
  * @param scope FavoritePropertiesScope to remove the favorite properties from.
243
- * @note `initializeConnection` must be called with the `imodel` before calling this function.
244
297
  */
245
298
  async clear(imodel, scope) {
246
- this.validateInitialization(imodel);
299
+ await this.ensureInitialized(imodel);
247
300
  const iTwinId = imodel.iTwinId;
248
301
  const imodelId = imodel.iModelId;
249
302
  let favoriteProperties;
@@ -261,8 +314,9 @@ class FavoritePropertiesManager {
261
314
  favoriteProperties = this._imodelProperties.get(getiModelInfo(iTwinId, imodelId));
262
315
  saveProperties = async () => this._storage.saveProperties(new Set(), iTwinId, imodelId);
263
316
  }
264
- if (favoriteProperties.size === 0)
317
+ if (favoriteProperties.size === 0) {
265
318
  return;
319
+ }
266
320
  favoriteProperties.clear();
267
321
  const saves = [];
268
322
  saves.push(saveProperties());
@@ -276,21 +330,45 @@ class FavoritePropertiesManager {
276
330
  * @param imodel IModelConnection.
277
331
  * @param scope FavoritePropertiesScope to check for favorite properties. It also checks the more general scopes.
278
332
  * @note `initializeConnection` must be called with the `imodel` before calling this function.
333
+ * @deprecated in 4.5. Use [[FavoritePropertiesManager.hasAsync]] instead. This method is not async, therefore it requires early initialization by calling [[FavoritePropertiesManager.initializeConnection]].
279
334
  */
280
335
  has(field, imodel, scope) {
281
336
  this.validateInitialization(imodel);
282
337
  const iTwinId = imodel.iTwinId;
283
338
  const imodelId = imodel.iModelId;
284
339
  const fieldInfos = (0, exports.getFieldInfos)(field);
285
- return setHasAny(this._globalProperties, fieldInfos) ||
340
+ return (setHasAny(this._globalProperties, fieldInfos) ||
286
341
  (scope !== FavoritePropertiesScope.Global && setHasAny(this._iTwinProperties.get(iTwinId), fieldInfos)) ||
287
- (scope === FavoritePropertiesScope.IModel && setHasAny(this._imodelProperties.get(getiModelInfo(iTwinId, imodelId)), fieldInfos));
342
+ (scope === FavoritePropertiesScope.IModel && setHasAny(this._imodelProperties.get(getiModelInfo(iTwinId, imodelId)), fieldInfos)));
343
+ }
344
+ /**
345
+ * Check if field contains at least one favorite property.
346
+ * @param field Field that contains properties.
347
+ * @param imodel IModelConnection.
348
+ * @param scope FavoritePropertiesScope to check for favorite properties. It also checks the more general scopes.
349
+ */
350
+ async hasAsync(field, imodel, scope) {
351
+ await this.ensureInitialized(imodel);
352
+ // eslint-disable-next-line deprecation/deprecation
353
+ return this.has(field, imodel, scope);
354
+ }
355
+ /**
356
+ * Sorts an array of fields with respect to favorite property order.
357
+ * Non-favorited fields get sorted by their default priority and always have lower priority than favorited fields.
358
+ * @param imodel IModelConnection.
359
+ * @param fields Array of Field's that needs to be sorted.
360
+ */
361
+ async sortFieldsAsync(imodel, fields) {
362
+ await this.ensureInitialized(imodel);
363
+ // eslint-disable-next-line deprecation/deprecation
364
+ return this.sortFields(imodel, fields);
288
365
  }
289
366
  getFieldPriority(field, iTwinId, imodelId) {
290
367
  const orderInfos = this._propertiesOrder.get(getiModelInfo(iTwinId, imodelId));
291
368
  const fieldOrderInfos = getFieldOrderInfos(field, orderInfos);
292
- if (fieldOrderInfos.length === 0)
369
+ if (fieldOrderInfos.length === 0) {
293
370
  return -1;
371
+ }
294
372
  const mostRecent = getMostRecentOrderInfo(fieldOrderInfos);
295
373
  return mostRecent.priority;
296
374
  }
@@ -299,7 +377,6 @@ class FavoritePropertiesManager {
299
377
  * @param field Field that priority is being changed.
300
378
  * @param afterField Field that goes before the moved field. If undefined the moving field is changed to the highest priority (to the top).
301
379
  * @param visibleFields Array of fields to move the field in.
302
- * @note `initializeConnection` must be called with the `imodel` before calling this function.
303
380
  */
304
381
  async changeFieldPriority(imodel, field, afterField, visibleFields) {
305
382
  /**
@@ -314,23 +391,26 @@ class FavoritePropertiesManager {
314
391
  * 4. Irrelevant orderInfos's get moved after `orderInfo` (depends on the direction)
315
392
  * 5. All `field` orderInfo's get moved after `afterOrderInfo`
316
393
  */
317
- this.validateInitialization(imodel);
394
+ await this.ensureInitialized(imodel);
318
395
  const iTwinId = imodel.iTwinId;
319
396
  const imodelId = imodel.iModelId;
320
- if (field === afterField)
397
+ if (field === afterField) {
321
398
  throw Error("`field` can not be the same as `afterField`.");
399
+ }
322
400
  const allOrderInfos = this._propertiesOrder.get(getiModelInfo(iTwinId, imodelId));
323
401
  const findFieldOrderInfoData = (f) => {
324
- if (!visibleFields.includes(f))
402
+ if (!visibleFields.includes(f)) {
325
403
  throw Error("Field is not contained in visible fields.");
404
+ }
326
405
  const infos = getFieldOrderInfos(f, allOrderInfos);
327
- if (infos.length === 0)
406
+ if (infos.length === 0) {
328
407
  throw Error("Field has no property order information.");
408
+ }
329
409
  const info = getMostRecentOrderInfo(infos);
330
410
  const index = allOrderInfos.indexOf(info);
331
411
  return { infos, mostRecent: { info, index } };
332
412
  };
333
- const { infos: movingOrderInfos, mostRecent: { index: orderInfoIndex } } = findFieldOrderInfoData(field);
413
+ const { infos: movingOrderInfos, mostRecent: { index: orderInfoIndex }, } = findFieldOrderInfoData(field);
334
414
  let afterOrderInfo;
335
415
  let afterOrderInfoIndex;
336
416
  if (afterField === undefined) {
@@ -338,7 +418,9 @@ class FavoritePropertiesManager {
338
418
  afterOrderInfoIndex = -1;
339
419
  }
340
420
  else {
341
- ({ mostRecent: { info: afterOrderInfo, index: afterOrderInfoIndex } } = findFieldOrderInfoData(afterField));
421
+ ({
422
+ mostRecent: { info: afterOrderInfo, index: afterOrderInfoIndex },
423
+ } = findFieldOrderInfoData(afterField));
342
424
  }
343
425
  let direction; // where to go from `afterOrderInfo` to `orderInfo`
344
426
  let startIndex;
@@ -351,8 +433,9 @@ class FavoritePropertiesManager {
351
433
  startIndex = afterOrderInfoIndex + 1;
352
434
  }
353
435
  const neededClassNames = allOrderInfos.reduce((classNames, oi) => {
354
- if (oi.parentClassName)
436
+ if (oi.parentClassName) {
355
437
  classNames.add(oi.parentClassName);
438
+ }
356
439
  return classNames;
357
440
  }, new Set());
358
441
  const baseClassesByClass = await this._getBaseClassesByClass(imodel, neededClassNames);
@@ -362,20 +445,24 @@ class FavoritePropertiesManager {
362
445
  for (let i = startIndex; i !== orderInfoIndex; i += direction) {
363
446
  const currOrderInfo = allOrderInfos[i];
364
447
  // primitive properties are always relevant, because we can't determine their relevance based on the class hierarchy
365
- if (currOrderInfo.parentClassName === undefined)
448
+ if (currOrderInfo.parentClassName === undefined) {
366
449
  continue;
450
+ }
367
451
  const visible = visibleOrderInfos.includes(currOrderInfo);
368
452
  if (visible) {
369
453
  relevantClasses.add(currOrderInfo.parentClassName);
370
454
  continue;
371
455
  }
372
456
  const hasBaseClasses = baseClassesByClass[currOrderInfo.parentClassName].some((classId) => relevantClasses.has(classId));
373
- if (hasBaseClasses)
457
+ if (hasBaseClasses) {
374
458
  continue;
375
- if (direction === Direction.Down)
459
+ }
460
+ if (direction === Direction.Down) {
376
461
  irrelevantOrderInfos.push(currOrderInfo);
377
- else
462
+ }
463
+ else {
378
464
  irrelevantOrderInfos.unshift(currOrderInfo);
465
+ }
379
466
  }
380
467
  // remove irrelevantOrderInfo's to add them after the `orderInfo`
381
468
  irrelevantOrderInfos.forEach((foi) => {
@@ -387,13 +474,13 @@ class FavoritePropertiesManager {
387
474
  const index = allOrderInfos.findIndex((oi) => oi.parentClassName === foi.parentClassName && oi.name === foi.name);
388
475
  allOrderInfos.splice(index, 1);
389
476
  });
390
- movingOrderInfos.forEach((oi) => oi.orderedTimestamp = new Date());
477
+ movingOrderInfos.forEach((oi) => (oi.orderedTimestamp = new Date()));
391
478
  afterOrderInfoIndex = afterOrderInfo === undefined ? -1 : allOrderInfos.indexOf(afterOrderInfo);
392
479
  allOrderInfos.splice(afterOrderInfoIndex + 1, 0, ...movingOrderInfos);
393
480
  allOrderInfos.splice(afterOrderInfoIndex + 1 + (direction === Direction.Up ? movingOrderInfos.length : 0), 0, ...irrelevantOrderInfos);
394
481
  // reassign priority numbers
395
482
  let priority = allOrderInfos.length;
396
- allOrderInfos.forEach((oi) => oi.priority = priority--);
483
+ allOrderInfos.forEach((oi) => (oi.priority = priority--));
397
484
  await this._storage.savePropertiesOrder(allOrderInfos, iTwinId, imodelId);
398
485
  this.onFavoritesChanged.raiseEvent();
399
486
  }
@@ -429,37 +516,46 @@ const getNestingPrefix = (field) => {
429
516
  });
430
517
  curr = curr.parent;
431
518
  }
432
- if (path.length === 0)
519
+ if (path.length === 0) {
433
520
  return "";
521
+ }
434
522
  path.reverse();
435
523
  return `${path.join("-")}-`;
436
524
  };
437
525
  const getPropertyClassName = (propertyName) => {
438
526
  const propertyNameStart = propertyName.split("-")[0];
439
527
  const parts = propertyNameStart.split(":").length;
440
- if (parts === 1) // primitive
528
+ if (parts === 1) {
529
+ // primitive
441
530
  return undefined;
442
- if (parts === 2) // nested property OR nested property parent class OR regular property parent class
531
+ }
532
+ if (parts === 2) {
533
+ // nested property OR nested property parent class OR regular property parent class
443
534
  return propertyNameStart;
535
+ }
444
536
  // regular property without parent class
445
537
  return propertyNameStart.substring(0, propertyName.lastIndexOf(":"));
446
538
  };
447
539
  /** @internal */
448
540
  const getFieldInfos = (field) => {
449
541
  const fieldInfos = new Set();
450
- if (field.isPropertiesField())
542
+ if (field.isPropertiesField()) {
451
543
  getPropertiesFieldPropertyNames(field).forEach((info) => fieldInfos.add(info));
452
- else if (field.isNestedContentField())
544
+ }
545
+ else if (field.isNestedContentField()) {
453
546
  fieldInfos.add(getNestedContentFieldPropertyName(field));
454
- else
547
+ }
548
+ else {
455
549
  fieldInfos.add(`${FavoritePropertiesManager.FAVORITES_IDENTIFIER_PREFIX}${field.name}`);
550
+ }
456
551
  return fieldInfos;
457
552
  };
458
553
  exports.getFieldInfos = getFieldInfos;
459
554
  const setHasAny = (set, lookup) => {
460
555
  for (const key of lookup) {
461
- if (set.has(key))
556
+ if (set.has(key)) {
462
557
  return true;
558
+ }
463
559
  }
464
560
  return false;
465
561
  };
@@ -472,26 +568,29 @@ const addOrderInfos = (dest, source) => {
472
568
  }
473
569
  });
474
570
  let priority = dest.length;
475
- dest.forEach((info) => info.priority = priority--);
571
+ dest.forEach((info) => (info.priority = priority--));
476
572
  };
477
573
  const removeOrderInfos = (container, toRemove) => {
478
574
  toRemove.forEach((roi) => {
479
575
  const index = container.findIndex((oi) => oi.name === roi.name);
480
576
  /* istanbul ignore else */
481
- if (index >= 0)
577
+ if (index >= 0) {
482
578
  container.splice(index, 1);
579
+ }
483
580
  });
484
581
  };
485
582
  /** @internal */
486
583
  const createFieldOrderInfos = (field) => {
487
584
  if (field.isNestedContentField()) {
488
585
  const propertyName = getNestedContentFieldPropertyName(field);
489
- return [{
586
+ return [
587
+ {
490
588
  parentClassName: getPropertyClassName(propertyName),
491
589
  name: propertyName,
492
590
  priority: 0,
493
591
  orderedTimestamp: new Date(),
494
- }];
592
+ },
593
+ ];
495
594
  }
496
595
  if (field.isPropertiesField()) {
497
596
  return getPropertiesFieldPropertyNames(field).map((propertyName) => ({
@@ -501,28 +600,34 @@ const createFieldOrderInfos = (field) => {
501
600
  orderedTimestamp: new Date(),
502
601
  }));
503
602
  }
504
- return [{
603
+ return [
604
+ {
505
605
  parentClassName: undefined,
506
606
  name: field.name,
507
607
  priority: 0,
508
608
  orderedTimestamp: new Date(),
509
- }];
609
+ },
610
+ ];
510
611
  };
511
612
  exports.createFieldOrderInfos = createFieldOrderInfos;
512
613
  const getFieldOrderInfos = (field, orderInfos) => {
513
614
  const fieldOrderInfos = [];
514
615
  const tryAddOrderInfo = (name) => {
515
616
  const fieldOrderInfo = orderInfos.find((oi) => oi.name === name);
516
- if (fieldOrderInfo !== undefined)
617
+ if (fieldOrderInfo !== undefined) {
517
618
  fieldOrderInfos.push(fieldOrderInfo);
619
+ }
518
620
  };
519
- if (field.isPropertiesField())
621
+ if (field.isPropertiesField()) {
520
622
  getPropertiesFieldPropertyNames(field).forEach(tryAddOrderInfo);
521
- else if (field.isNestedContentField())
623
+ }
624
+ else if (field.isNestedContentField()) {
522
625
  tryAddOrderInfo(getNestedContentFieldPropertyName(field));
523
- else
626
+ }
627
+ else {
524
628
  tryAddOrderInfo(field.name);
629
+ }
525
630
  return fieldOrderInfos;
526
631
  };
527
- const getMostRecentOrderInfo = (orderInfos) => orderInfos.reduce((recent, curr) => (recent && recent.orderedTimestamp >= curr.orderedTimestamp) ? recent : curr);
632
+ const getMostRecentOrderInfo = (orderInfos) => orderInfos.reduce((recent, curr) => (recent && recent.orderedTimestamp >= curr.orderedTimestamp ? recent : curr));
528
633
  //# sourceMappingURL=FavoritePropertiesManager.js.map