@itwin/unified-selection 1.1.2 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +18 -12
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.d.ts +15 -2
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.d.ts.map +1 -1
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.js +6 -1
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.js.map +1 -1
- package/lib/cjs/unified-selection/DisposePolyfill.d.ts +1 -0
- package/lib/cjs/unified-selection/DisposePolyfill.d.ts.map +1 -0
- package/lib/cjs/unified-selection/DisposePolyfill.js +11 -0
- package/lib/cjs/unified-selection/DisposePolyfill.js.map +1 -0
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts +14 -9
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +1 -1
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.js +173 -85
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.js.map +1 -1
- package/lib/cjs/unified-selection/SelectionScope.d.ts +2 -1
- package/lib/cjs/unified-selection/SelectionScope.d.ts.map +1 -1
- package/lib/cjs/unified-selection/SelectionScope.js +10 -5
- package/lib/cjs/unified-selection/SelectionScope.js.map +1 -1
- package/lib/cjs/unified-selection/SelectionStorage.d.ts +3 -1
- package/lib/cjs/unified-selection/SelectionStorage.d.ts.map +1 -1
- package/lib/cjs/unified-selection/SelectionStorage.js +3 -1
- package/lib/cjs/unified-selection/SelectionStorage.js.map +1 -1
- package/lib/cjs/unified-selection/Utils.d.ts +15 -0
- package/lib/cjs/unified-selection/Utils.d.ts.map +1 -1
- package/lib/cjs/unified-selection/Utils.js +19 -0
- package/lib/cjs/unified-selection/Utils.js.map +1 -1
- package/lib/cjs/unified-selection/types/IModel.d.ts +51 -3
- package/lib/cjs/unified-selection/types/IModel.d.ts.map +1 -1
- package/lib/cjs/unified-selection/types/IModel.js.map +1 -1
- package/lib/esm/unified-selection/CachingHiliteSetProvider.d.ts +15 -2
- package/lib/esm/unified-selection/CachingHiliteSetProvider.d.ts.map +1 -1
- package/lib/esm/unified-selection/CachingHiliteSetProvider.js +6 -1
- package/lib/esm/unified-selection/CachingHiliteSetProvider.js.map +1 -1
- package/lib/esm/unified-selection/DisposePolyfill.d.ts +2 -0
- package/lib/esm/unified-selection/DisposePolyfill.d.ts.map +1 -0
- package/lib/esm/unified-selection/DisposePolyfill.js +11 -0
- package/lib/esm/unified-selection/DisposePolyfill.js.map +1 -0
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts +14 -9
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +1 -1
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.js +174 -86
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.js.map +1 -1
- package/lib/esm/unified-selection/SelectionScope.d.ts +2 -1
- package/lib/esm/unified-selection/SelectionScope.d.ts.map +1 -1
- package/lib/esm/unified-selection/SelectionScope.js +10 -5
- package/lib/esm/unified-selection/SelectionScope.js.map +1 -1
- package/lib/esm/unified-selection/SelectionStorage.d.ts +3 -1
- package/lib/esm/unified-selection/SelectionStorage.d.ts.map +1 -1
- package/lib/esm/unified-selection/SelectionStorage.js +3 -1
- package/lib/esm/unified-selection/SelectionStorage.js.map +1 -1
- package/lib/esm/unified-selection/Utils.d.ts +15 -0
- package/lib/esm/unified-selection/Utils.d.ts.map +1 -1
- package/lib/esm/unified-selection/Utils.js +18 -0
- package/lib/esm/unified-selection/Utils.js.map +1 -1
- package/lib/esm/unified-selection/types/IModel.d.ts +51 -3
- package/lib/esm/unified-selection/types/IModel.d.ts.map +1 -1
- package/lib/esm/unified-selection/types/IModel.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @itwin/unified-selection
|
|
2
2
|
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#828](https://github.com/iTwin/presentation/pull/828): Polyfill `Symbol.dispose` and `Symbol.asyncDispose` to make sure that code using the upcoming JS recource management API works in all environments.
|
|
8
|
+
|
|
9
|
+
## 1.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#800](https://github.com/iTwin/presentation/pull/800): Add support for Models and SubCategories selection that's going to be available in `@itwin/core-frontend` version `5`.
|
|
14
|
+
|
|
15
|
+
The changes in `@itwin/core-frontend` allow us to stop manually syncing `HiliteSet` with `SelectionSet` and rely on automatic syncing instead.
|
|
16
|
+
|
|
17
|
+
- [#800](https://github.com/iTwin/presentation/pull/800): `computeSelection`: Broadened the type of `elementIds` prop from `Id64String[]` to `Id64Arg`.
|
|
18
|
+
- [#802](https://github.com/iTwin/presentation/pull/802): Prefer `Symbol.dispose` over `dispose` for disposable objects.
|
|
19
|
+
|
|
20
|
+
The package contained a number of types for disposable objects, that had a requirement of `dispose` method being called on them after they are no longer needed. In conjunction with the `using` utility from `@itwin/core-bentley`, usage of such objects looked like this:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
class MyDisposable() {
|
|
24
|
+
dispose() {
|
|
25
|
+
// do some cleanup
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
using(new MyDisposable(), (obj) => {
|
|
29
|
+
// do something with obj, it'll get disposed when the callback returns
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
In version `5.2`, TypeScript [introduced](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management) `Disposable` type and `using` declarations (from the upcoming [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management) feature in ECMAScript). Now we're making use of those new utilities in this package (while still supporting the old `dispose` method), which allows using `MyDisposable` from the above snippet like this:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
using obj = new MyDisposable();
|
|
37
|
+
// do something with obj, it'll get disposed when it goes out of scope
|
|
38
|
+
```
|
|
39
|
+
|
|
3
40
|
## 1.1.2
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -32,8 +32,9 @@ const unifiedSelection = createStore();
|
|
|
32
32
|
|
|
33
33
|
// the store should to be cleaned up when iModels are closed to free up memory, e.g.:
|
|
34
34
|
import { IModelConnection } from "@itwin/core-frontend";
|
|
35
|
+
import { createIModelKey } from "@itwin/presentation-core-interop";
|
|
35
36
|
IModelConnection.onClose.addListener((imodel) => {
|
|
36
|
-
unifiedSelection.clearStorage(imodel
|
|
37
|
+
unifiedSelection.clearStorage(createIModelKey(imodel));
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
// add a demo selection listener
|
|
@@ -59,7 +60,7 @@ unifiedSelection.selectionChangeEvent.addListener(({ imodelKey, source, changeTy
|
|
|
59
60
|
|
|
60
61
|
// in some component
|
|
61
62
|
MyComponent.onECInstanceSelected((imodel: IModelConnection, key: { className: string; id: Id64String }) => {
|
|
62
|
-
unifiedSelection.addToSelection({ imodelKey: imodel
|
|
63
|
+
unifiedSelection.addToSelection({ imodelKey: createIModelKey(imodel), source: "MyComponent", selectables: [key] });
|
|
63
64
|
});
|
|
64
65
|
```
|
|
65
66
|
|
|
@@ -111,6 +112,8 @@ The `@itwin/unified-selection` package delivers APIs for creating a `HiliteSet`
|
|
|
111
112
|
import { IModelConnection } from "@itwin/core-frontend";
|
|
112
113
|
import { createECSqlQueryExecutor, createECSchemaProvider } from "@itwin/presentation-core-interop";
|
|
113
114
|
import { createHiliteSetProvider } from "@itwin/unified-selection";
|
|
115
|
+
|
|
116
|
+
const imodel: IModelConnection; // initialized elsewhere
|
|
114
117
|
const hiliteProvider = createHiliteSetProvider({
|
|
115
118
|
imodelAccess: {
|
|
116
119
|
...createECSchemaProvider(imodel),
|
|
@@ -119,17 +122,20 @@ const hiliteProvider = createHiliteSetProvider({
|
|
|
119
122
|
});
|
|
120
123
|
const hiliteSet = await hiliteProvider.getHiliteSet({ selectables });
|
|
121
124
|
|
|
122
|
-
// Some others may want to get a hilite set for _current_ selection in storage - use `createCachingHiliteSetProvider`
|
|
123
|
-
// recommended to keep a single instance of this provider per application as it caches hilite sets per each iModel's selection.
|
|
125
|
+
// Some others may want to get a hilite set for _current_ selection for specific iModel in storage - use `createCachingHiliteSetProvider`
|
|
126
|
+
// for that. It's recommended to keep a single instance of this provider per application as it caches hilite sets per each iModel's selection.
|
|
124
127
|
import { createCachingHiliteSetProvider } from "@itwin/unified-selection";
|
|
125
|
-
|
|
128
|
+
import { createIModelKey } from "@itwin/presentation-core-interop";
|
|
129
|
+
|
|
130
|
+
// Note the use of `using` keyword here. The caching provider registers a selection change listener and should be disposed, in case
|
|
131
|
+
// its lifetime is shorter than that of `SelectionStorage`, to unregister the listener. The `using` keyword ensures that the provider
|
|
132
|
+
// is disposed when it goes out of scope.
|
|
133
|
+
using selectionHiliteProvider = createCachingHiliteSetProvider({
|
|
126
134
|
selectionStorage,
|
|
127
|
-
|
|
135
|
+
// this is called to get iModel access based on the iModel key, used to get hilite set for that iModel (see below)
|
|
136
|
+
imodelProvider: (imodelKey) => getIModelByKey(imodelKey),
|
|
128
137
|
});
|
|
129
|
-
const selectionHiliteSet = await selectionHiliteProvider.getHiliteSet({ imodel
|
|
130
|
-
// The caching provider registers a selection change listener and should be disposed, in case its lifetime
|
|
131
|
-
// is shorter than that of `SelectionStorage`, to unregister the listener.
|
|
132
|
-
selectionHiliteProvider.dispose();
|
|
138
|
+
const selectionHiliteSet = await selectionHiliteProvider.getHiliteSet({ imodelKey: createIModelKey(imodel) });
|
|
133
139
|
```
|
|
134
140
|
|
|
135
141
|
### Selection scopes
|
|
@@ -171,13 +177,13 @@ const selection = computeSelection({ queryExecutor, elementIds, scope: { id: "el
|
|
|
171
177
|
The `@itwin/unified-selection` package delivers a `enableUnifiedSelectionSyncWithIModel` function to enable selection synchronization between an iModel and a `SelectionStorage`. When called, it returns a cleanup function that should be used to disable the synchronization. There should only be one active synchronization between a single iModel and a `SelectionStorage` at a given time. For example, this function could be used inside a `useEffect` hook in a component that holds an iModel:
|
|
172
178
|
|
|
173
179
|
```ts
|
|
174
|
-
import { createECSqlQueryExecutor, createECSchemaProvider } from "@itwin/presentation-core-interop";
|
|
180
|
+
import { createECSqlQueryExecutor, createECSchemaProvider, createIModelKey } from "@itwin/presentation-core-interop";
|
|
175
181
|
useEffect(() => {
|
|
176
182
|
return enableUnifiedSelectionSyncWithIModel({
|
|
177
183
|
imodelAccess: {
|
|
178
184
|
...createECSqlQueryExecutor(imodel),
|
|
179
185
|
...createECSchemaProvider(imodel),
|
|
180
|
-
key: imodel
|
|
186
|
+
key: createIModelKey(imodel),
|
|
181
187
|
hiliteSet: imodel.hilited,
|
|
182
188
|
selectionSet: imodel.selectionSet,
|
|
183
189
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "./DisposePolyfill.js";
|
|
1
2
|
import { ECClassHierarchyInspector, ECSqlQueryExecutor } from "@itwin/presentation-shared";
|
|
2
3
|
import { HiliteSet } from "./HiliteSetProvider.js";
|
|
3
4
|
import { SelectionStorage } from "./SelectionStorage.js";
|
|
@@ -26,7 +27,17 @@ export interface CachingHiliteSetProvider {
|
|
|
26
27
|
/** iModel to get hilite set for */
|
|
27
28
|
imodelKey: string;
|
|
28
29
|
}): AsyncIterableIterator<HiliteSet>;
|
|
29
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Disposes the cache.
|
|
32
|
+
*
|
|
33
|
+
* Optional to avoid breaking the API. Will be made required when the deprecated
|
|
34
|
+
* `dispose` is removed.
|
|
35
|
+
*/
|
|
36
|
+
[Symbol.dispose]?: () => void;
|
|
37
|
+
/**
|
|
38
|
+
* Disposes the cache.
|
|
39
|
+
* @deprecated in 1.2. Use `[Symbol.dispose]` instead.
|
|
40
|
+
*/
|
|
30
41
|
dispose(): void;
|
|
31
42
|
}
|
|
32
43
|
/**
|
|
@@ -34,5 +45,7 @@ export interface CachingHiliteSetProvider {
|
|
|
34
45
|
* hilite set requests for the same iModel don't cost until selection in given selection storage changes.
|
|
35
46
|
* @public
|
|
36
47
|
*/
|
|
37
|
-
export declare function createCachingHiliteSetProvider(props: CachingHiliteSetProviderProps): CachingHiliteSetProvider
|
|
48
|
+
export declare function createCachingHiliteSetProvider(props: CachingHiliteSetProviderProps): CachingHiliteSetProvider & {
|
|
49
|
+
[Symbol.dispose]: () => void;
|
|
50
|
+
};
|
|
38
51
|
//# sourceMappingURL=CachingHiliteSetProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CachingHiliteSetProvider.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/CachingHiliteSetProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CachingHiliteSetProvider.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/CachingHiliteSetProvider.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAC;AAG9B,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAA2B,SAAS,EAAqB,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAAuC,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9F;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,8DAA8D;IAC9D,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,iEAAiE;IACjE,cAAc,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,yBAAyB,GAAG,kBAAkB,CAAC;CACvF;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,wBAAwB;IACvC,mEAAmE;IACnE,YAAY,CAAC,KAAK,EAAE;QAClB,mCAAmC;QACnC,SAAS,EAAE,MAAM,CAAC;KACnB,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAErC;;;;;OAKG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC;IAE9B;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,6BAA6B,GAAG,wBAAwB,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,CAEhJ"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.createCachingHiliteSetProvider = createCachingHiliteSetProvider;
|
|
8
|
+
require("./DisposePolyfill.js");
|
|
8
9
|
const rxjs_1 = require("rxjs");
|
|
9
10
|
const rxjs_for_await_1 = require("rxjs-for-await");
|
|
10
11
|
const HiliteSetProvider_js_1 = require("./HiliteSetProvider.js");
|
|
@@ -44,11 +45,15 @@ class CachingHiliteSetProviderImpl {
|
|
|
44
45
|
}
|
|
45
46
|
return (0, rxjs_for_await_1.eachValueFrom)(hiliteSet);
|
|
46
47
|
}
|
|
47
|
-
dispose() {
|
|
48
|
+
[Symbol.dispose]() {
|
|
48
49
|
this._removeListener();
|
|
49
50
|
this._hiliteSetProviders = new Map();
|
|
50
51
|
this._cache = new Map();
|
|
51
52
|
}
|
|
53
|
+
/* c8 ignore next 3 */
|
|
54
|
+
dispose() {
|
|
55
|
+
this[Symbol.dispose]();
|
|
56
|
+
}
|
|
52
57
|
getHiliteSetProvider(imodelKey, imodelAccess) {
|
|
53
58
|
let provider = this._hiliteSetProviders.get(imodelKey);
|
|
54
59
|
if (!provider) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CachingHiliteSetProvider.js","sourceRoot":"","sources":["../../../src/unified-selection/CachingHiliteSetProvider.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;
|
|
1
|
+
{"version":3,"file":"CachingHiliteSetProvider.js","sourceRoot":"","sources":["../../../src/unified-selection/CachingHiliteSetProvider.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAyDhG,wEAEC;AAzDD,gCAA8B;AAC9B,+BAAqD;AACrD,mDAA+C;AAE/C,iEAA+F;AAE/F,+DAA8F;AA4C9F;;;;GAIG;AACH,SAAgB,8BAA8B,CAAC,KAAoC;IACjF,OAAO,IAAI,4BAA4B,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,4BAA4B;IACxB,iBAAiB,CAAmB;IACpC,mBAAmB,GAAG,IAAI,GAAG,EAA6B,CAAC;IAC3D,MAAM,GAAG,IAAI,GAAG,EAAiC,CAAC;IAClD,eAAe,CAAa;IAC5B,eAAe,CAAwE;IAE/F,YAAY,KAAoC;QAC9C,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,gBAAgB,CAAC;QAChD,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,cAAc,CAAC;QAC5C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,IAAqC,EAAE,EAAE;YACvH,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnC,IAAI,IAAI,CAAC,UAAU,KAAK,OAAO,IAAI,IAAI,CAAC,MAAM,KAAK,yDAAmC,EAAE,CAAC;gBACvF,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAClD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,YAAY,CAAC,EAAE,SAAS,EAAyB;QACtD,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACpE,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAE3C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;YACvE,SAAS,GAAG,IAAA,WAAI,EAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAA,kBAAW,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC/F,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,IAAA,8BAAa,EAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,IAAI,CAAC,mBAAmB,GAAG,IAAI,GAAG,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED,sBAAsB;IACf,OAAO;QACZ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACzB,CAAC;IAEO,oBAAoB,CAAC,SAAiB,EAAE,YAA4D;QAC1G,IAAI,QAAQ,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAA,8CAAuB,EAAC,EAAE,YAAY,EAAE,CAAC,CAAC;YACrD,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./DisposePolyfill.js\";\nimport { from, Observable, shareReplay } from \"rxjs\";\nimport { eachValueFrom } from \"rxjs-for-await\";\nimport { ECClassHierarchyInspector, ECSqlQueryExecutor } from \"@itwin/presentation-shared\";\nimport { createHiliteSetProvider, HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider.js\";\nimport { StorageSelectionChangeEventArgs } from \"./SelectionChangeEvent.js\";\nimport { IMODEL_CLOSE_SELECTION_CLEAR_SOURCE, SelectionStorage } from \"./SelectionStorage.js\";\n\n/**\n * Props for creating a `CachingHiliteSetProvider` instance.\n * @public\n */\nexport interface CachingHiliteSetProviderProps {\n /** Selection storage to use for retrieving the hilite set. */\n selectionStorage: SelectionStorage;\n /** A callback that should return iModel access by iModel key. */\n imodelProvider: (imodelKey: string) => ECClassHierarchyInspector & ECSqlQueryExecutor;\n}\n\n/**\n * Defines return value of `createCachingHiliteSetProvider`.\n *\n * **Warning:** Used in public API as a return value. Not expected to be created / extended by package\n * consumers, may be supplemented with required attributes any time.\n *\n * @see `createCachingHiliteSetProvider`\n * @public\n */\nexport interface CachingHiliteSetProvider {\n /** Get the current hilite set iterator for the specified imodel */\n getHiliteSet(props: {\n /** iModel to get hilite set for */\n imodelKey: string;\n }): AsyncIterableIterator<HiliteSet>;\n\n /**\n * Disposes the cache.\n *\n * Optional to avoid breaking the API. Will be made required when the deprecated\n * `dispose` is removed.\n */\n [Symbol.dispose]?: () => void;\n\n /**\n * Disposes the cache.\n * @deprecated in 1.2. Use `[Symbol.dispose]` instead.\n */\n dispose(): void;\n}\n\n/**\n * Creates a hilite set provider that caches hilite set for current selection for given iModel so any subsequent\n * hilite set requests for the same iModel don't cost until selection in given selection storage changes.\n * @public\n */\nexport function createCachingHiliteSetProvider(props: CachingHiliteSetProviderProps): CachingHiliteSetProvider & { [Symbol.dispose]: () => void } {\n return new CachingHiliteSetProviderImpl(props);\n}\n\nclass CachingHiliteSetProviderImpl implements CachingHiliteSetProvider {\n private _selectionStorage: SelectionStorage;\n private _hiliteSetProviders = new Map<string, HiliteSetProvider>();\n private _cache = new Map<string, Observable<HiliteSet>>();\n private _removeListener: () => void;\n private _imodelProvider: (imodelKey: string) => ECClassHierarchyInspector & ECSqlQueryExecutor;\n\n constructor(props: CachingHiliteSetProviderProps) {\n this._selectionStorage = props.selectionStorage;\n this._imodelProvider = props.imodelProvider;\n this._removeListener = this._selectionStorage.selectionChangeEvent.addListener((args: StorageSelectionChangeEventArgs) => {\n this._cache.delete(args.imodelKey);\n if (args.changeType === \"clear\" && args.source === IMODEL_CLOSE_SELECTION_CLEAR_SOURCE) {\n this._hiliteSetProviders.delete(args.imodelKey);\n }\n });\n }\n\n public getHiliteSet({ imodelKey }: { imodelKey: string }): AsyncIterableIterator<HiliteSet> {\n const imodelAccess = this._imodelProvider(imodelKey);\n const provider = this.getHiliteSetProvider(imodelKey, imodelAccess);\n let hiliteSet = this._cache.get(imodelKey);\n\n if (!hiliteSet) {\n const selectables = this._selectionStorage.getSelection({ imodelKey });\n hiliteSet = from(provider.getHiliteSet({ selectables })).pipe(shareReplay({ refCount: true }));\n this._cache.set(imodelKey, hiliteSet);\n }\n\n return eachValueFrom(hiliteSet);\n }\n\n public [Symbol.dispose](): void {\n this._removeListener();\n this._hiliteSetProviders = new Map();\n this._cache = new Map();\n }\n\n /* c8 ignore next 3 */\n public dispose(): void {\n this[Symbol.dispose]();\n }\n\n private getHiliteSetProvider(imodelKey: string, imodelAccess: ECClassHierarchyInspector & ECSqlQueryExecutor) {\n let provider = this._hiliteSetProviders.get(imodelKey);\n if (!provider) {\n provider = createHiliteSetProvider({ imodelAccess });\n this._hiliteSetProviders.set(imodelKey, provider);\n }\n return provider;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=DisposePolyfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DisposePolyfill.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/DisposePolyfill.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management
|
|
8
|
+
*/
|
|
9
|
+
Symbol.dispose ??= Symbol("Symbol.dispose");
|
|
10
|
+
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
|
11
|
+
//# sourceMappingURL=DisposePolyfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DisposePolyfill.js","sourceRoot":"","sources":["../../../src/unified-selection/DisposePolyfill.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG;;GAEG;AACF,MAAc,CAAC,OAAO,KAAK,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACpD,MAAc,CAAC,YAAY,KAAK,MAAM,CAAC,qBAAqB,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\n/**\n * Polyfill for upcoming resource management feature: https://github.com/tc39/proposal-explicit-resource-management\n */\n(Symbol as any).dispose ??= Symbol(\"Symbol.dispose\");\n(Symbol as any).asyncDispose ??= Symbol(\"Symbol.asyncDispose\");\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "./DisposePolyfill.js";
|
|
1
2
|
import { ECClassHierarchyInspector, ECSqlQueryExecutor } from "@itwin/presentation-shared";
|
|
2
3
|
import { CachingHiliteSetProvider } from "./CachingHiliteSetProvider.js";
|
|
3
4
|
import { ComputeSelectionProps } from "./SelectionScope.js";
|
|
@@ -15,7 +16,7 @@ export interface EnableUnifiedSelectionSyncWithIModelProps {
|
|
|
15
16
|
* `hilited` and `selectionSet` attributes like this:
|
|
16
17
|
*
|
|
17
18
|
* ```ts
|
|
18
|
-
* import { createECSqlQueryExecutor, createECSchemaProvider } from "@itwin/presentation-core-interop";
|
|
19
|
+
* import { createECSqlQueryExecutor, createECSchemaProvider, createIModelKey } from "@itwin/presentation-core-interop";
|
|
19
20
|
* import { createCachingECClassHierarchyInspector } from "@itwin/presentation-shared";
|
|
20
21
|
* import { IModelConnection } from "@itwin/core-frontend";
|
|
21
22
|
*
|
|
@@ -23,7 +24,7 @@ export interface EnableUnifiedSelectionSyncWithIModelProps {
|
|
|
23
24
|
* const imodelAccess = {
|
|
24
25
|
* ...createECSqlQueryExecutor(imodel),
|
|
25
26
|
* ...createCachingECClassHierarchyInspector({ schemaProvider: createECSchemaProvider(MyAppFrontend.getSchemaContext(imodel)) }),
|
|
26
|
-
* key: imodel
|
|
27
|
+
* key: createIModelKey(imodel),
|
|
27
28
|
* hiliteSet: imodel.hilited,
|
|
28
29
|
* selectionSet: imodel.selectionSet,
|
|
29
30
|
* };
|
|
@@ -46,8 +47,13 @@ export interface EnableUnifiedSelectionSyncWithIModelProps {
|
|
|
46
47
|
* will be created for the given iModel using the provided `imodelAccess`.
|
|
47
48
|
* If the consuming application already has a `CachingHiliteSetProvider` defined, it should be provided instead
|
|
48
49
|
* to reuse the cache and avoid creating new providers for each iModel.
|
|
50
|
+
*
|
|
51
|
+
* The type is defined in a way that makes it required for provider to have either the deprecated `dispose` or the
|
|
52
|
+
* new `Symbol.dispose` method.
|
|
49
53
|
*/
|
|
50
|
-
cachingHiliteSetProvider?: CachingHiliteSetProvider
|
|
54
|
+
cachingHiliteSetProvider?: CachingHiliteSetProvider | (Omit<CachingHiliteSetProvider, "dispose"> & {
|
|
55
|
+
[Symbol.dispose]: () => void;
|
|
56
|
+
});
|
|
51
57
|
}
|
|
52
58
|
/**
|
|
53
59
|
* Enables synchronization between iModel selection and unified selection.
|
|
@@ -69,14 +75,14 @@ export declare class IModelSelectionHandler {
|
|
|
69
75
|
private _activeScopeProvider;
|
|
70
76
|
private _isSuspended;
|
|
71
77
|
private _cancelOngoingChanges;
|
|
72
|
-
private
|
|
73
|
-
private
|
|
78
|
+
private _unregisterUnifiedSelectionListener;
|
|
79
|
+
private _unregisterIModelSelectionSetListener;
|
|
74
80
|
private _hasCustomCachingHiliteSetProvider;
|
|
75
81
|
constructor(props: EnableUnifiedSelectionSyncWithIModelProps);
|
|
76
|
-
dispose(): void;
|
|
77
|
-
/** Temporarily suspends tool selection synchronization until the returned
|
|
82
|
+
[Symbol.dispose](): void;
|
|
83
|
+
/** Temporarily suspends tool selection synchronization until the returned disposable object is disposed. */
|
|
78
84
|
suspendIModelToolSelectionSync(): {
|
|
79
|
-
dispose: () =>
|
|
85
|
+
[Symbol.dispose]: () => void;
|
|
80
86
|
};
|
|
81
87
|
private handleUnifiedSelectionChange;
|
|
82
88
|
private onUnifiedSelectionChanged;
|
|
@@ -86,6 +92,5 @@ export declare class IModelSelectionHandler {
|
|
|
86
92
|
private onIModelSelectionChanged;
|
|
87
93
|
private handleIModelSelectionChange;
|
|
88
94
|
private getSelectionSetChangeIds;
|
|
89
|
-
private idArgToIds;
|
|
90
95
|
}
|
|
91
96
|
//# sourceMappingURL=EnableUnifiedSelectionSyncWithIModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnableUnifiedSelectionSyncWithIModel.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/EnableUnifiedSelectionSyncWithIModel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EnableUnifiedSelectionSyncWithIModel.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/EnableUnifiedSelectionSyncWithIModel.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,wBAAwB,EAAkC,MAAM,+BAA+B,CAAC;AAIzG,OAAO,EAAoB,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAA6E,MAAM,mBAAmB,CAAC;AAG3J;;;GAGG;AACH,MAAM,WAAW,yCAAyC;IACxD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,YAAY,EAAE,kBAAkB,GAC9B,yBAAyB,GAAG;QAC1B,sEAAsE;QACtE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,mFAAmF;QACnF,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;QACxC,yFAAyF;QACzF,QAAQ,CAAC,YAAY,EAAE,sBAAsB,CAAC;KAC/C,CAAC;IAEJ,qEAAqE;IACrE,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC,6BAA6B;IAC7B,mBAAmB,EAAE,MAAM,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAE1D;;;;;;;;OAQG;IACH,wBAAwB,CAAC,EAAE,wBAAwB,GAAG,CAAC,IAAI,CAAC,wBAAwB,EAAE,SAAS,CAAC,GAAG;QAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC,CAAC;CACtI;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAAC,KAAK,EAAE,yCAAyC,GAAG,MAAM,IAAI,CAGjH;AAED;;;;GAIG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,oBAAoB,CAAU;IAEtC,OAAO,CAAC,aAAa,CAA4D;IACjF,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,yBAAyB,CAAqF;IACtH,OAAO,CAAC,oBAAoB,CAAuC;IAEnE,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,qBAAqB,CAAuB;IACpD,OAAO,CAAC,mCAAmC,CAAa;IACxD,OAAO,CAAC,qCAAqC,CAAa;IAC1D,OAAO,CAAC,kCAAkC,CAAU;gBAEjC,KAAK,EAAE,yCAAyC;IAqB5D,CAAC,MAAM,CAAC,OAAO,CAAC;IASvB,4GAA4G;IACrG,8BAA8B;;;IAUrC,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,yBAAyB,CAU/B;IAEF,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,eAAe;IAuBvB,OAAO,CAAC,wBAAwB,CAmB9B;YAEY,2BAA2B;IAiBzC,OAAO,CAAC,wBAAwB;CAcjC"}
|