@itwin/unified-selection 1.1.1 → 1.2.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.
- package/CHANGELOG.md +38 -0
- package/README.md +5 -5
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.d.ts +14 -2
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.d.ts.map +1 -1
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.js +5 -1
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.js.map +1 -1
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts +11 -7
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +1 -1
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.js +172 -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/Utils.d.ts +14 -0
- package/lib/cjs/unified-selection/Utils.d.ts.map +1 -1
- package/lib/cjs/unified-selection/Utils.js +18 -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 +14 -2
- package/lib/esm/unified-selection/CachingHiliteSetProvider.d.ts.map +1 -1
- package/lib/esm/unified-selection/CachingHiliteSetProvider.js +5 -1
- package/lib/esm/unified-selection/CachingHiliteSetProvider.js.map +1 -1
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts +11 -7
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +1 -1
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.js +173 -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/Utils.d.ts +14 -0
- package/lib/esm/unified-selection/Utils.d.ts.map +1 -1
- package/lib/esm/unified-selection/Utils.js +17 -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 +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnableUnifiedSelectionSyncWithIModel.js","sourceRoot":"","sources":["../../../src/unified-selection/EnableUnifiedSelectionSyncWithIModel.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAqEhG,oFAGC;AAtED,+BAAgD;AAChD,sDAA6D;AAE7D,+EAAyG;AACzG,iEAA+F;AAG/F,2DAA8E;AAE9E,iDAAwI;AAqDxI;;;;GAIG;AACH,SAAgB,oCAAoC,CAAC,KAAgD;IACnG,MAAM,gBAAgB,GAAG,IAAI,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAC3D,OAAO,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAa,sBAAsB;IACzB,oBAAoB,GAAG,MAAM,CAAC;IAE9B,aAAa,CAA4D;IACzE,iBAAiB,CAAmB;IACpC,kBAAkB,CAAoB;IACtC,yBAAyB,CAA2B;IACpD,oBAAoB,CAAuC;IAE3D,YAAY,CAAU;IACtB,qBAAqB,GAAG,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CAAC;QACf,CAAC;QACD,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;QAClB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA1MD,wDA0MC","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 { from, Subject, takeUntil } from \"rxjs\";\nimport { assert, Id64Arg, using } from \"@itwin/core-bentley\";\nimport { ECClassHierarchyInspector, ECSqlQueryExecutor } from \"@itwin/presentation-shared\";\nimport { CachingHiliteSetProvider, createCachingHiliteSetProvider } from \"./CachingHiliteSetProvider.js\";\nimport { createHiliteSetProvider, HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider.js\";\nimport { SelectableInstanceKey, Selectables } from \"./Selectable.js\";\nimport { StorageSelectionChangeEventArgs, StorageSelectionChangeType } from \"./SelectionChangeEvent.js\";\nimport { computeSelection, ComputeSelectionProps } from \"./SelectionScope.js\";\nimport { SelectionStorage } from \"./SelectionStorage.js\";\nimport { CoreIModelHiliteSet, CoreIModelSelectionSet, CoreSelectionSetEventType, CoreSelectionSetEventUnsafe } from \"./types/IModel.js\";\n\n/**\n * Props for `enableUnifiedSelectionSyncWithIModel`.\n * @public\n */\nexport interface EnableUnifiedSelectionSyncWithIModelProps {\n /**\n * Provides access to different iModel's features: query executing, class hierarchy, selection and hilite sets.\n * It's recommended to use `@itwin/presentation-core-interop` to create `ECSqlQueryExecutor` and `ECSchemaProvider` from\n * [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/) and map its `key`,\n * `hilited` and `selectionSet` attributes like this:\n *\n * ```ts\n * import { createECSqlQueryExecutor, createECSchemaProvider } from \"@itwin/presentation-core-interop\";\n * import { createCachingECClassHierarchyInspector } from \"@itwin/presentation-shared\";\n * import { IModelConnection } from \"@itwin/core-frontend\";\n *\n * const imodel: IModelConnection = ...\n * const imodelAccess = {\n * ...createECSqlQueryExecutor(imodel),\n * ...createCachingECClassHierarchyInspector({ schemaProvider: createECSchemaProvider(MyAppFrontend.getSchemaContext(imodel)) }),\n * key: imodel.key,\n * hiliteSet: imodel.hilited,\n * selectionSet: imodel.selectionSet,\n * };\n * ```.\n */\n imodelAccess: ECSqlQueryExecutor &\n ECClassHierarchyInspector & {\n /** Key of the iModel. Generally taken from `IModelConnection.key`. */\n readonly key: string;\n /** The set of currently hilited elements taken from `IModelConnection.hilited`. */\n readonly hiliteSet: CoreIModelHiliteSet;\n /** The set of currently selected elements taken from `IModelConnection.selectionSet`. */\n readonly selectionSet: CoreIModelSelectionSet;\n };\n\n /** Selection storage to synchronize IModel's tool selection with. */\n selectionStorage: SelectionStorage;\n\n /** Active scope provider. */\n activeScopeProvider: () => ComputeSelectionProps[\"scope\"];\n\n /**\n * A caching hilite set provider used to retrieve hilite sets for an iModel. If not provided, a new `CachingHiliteSetProvider`\n * will be created for the given iModel using the provided `imodelAccess`.\n * If the consuming application already has a `CachingHiliteSetProvider` defined, it should be provided instead\n * to reuse the cache and avoid creating new providers for each iModel.\n */\n cachingHiliteSetProvider?: CachingHiliteSetProvider;\n}\n\n/**\n * Enables synchronization between iModel selection and unified selection.\n * @returns function for disposing the synchronization.\n * @public\n */\nexport function enableUnifiedSelectionSyncWithIModel(props: EnableUnifiedSelectionSyncWithIModelProps): () => void {\n const selectionHandler = new IModelSelectionHandler(props);\n return () => selectionHandler.dispose();\n}\n\n/**\n * A handler that syncs selection between unified selection storage\n * (`SelectionStorage`) and an iModel (`iModel.selectionSet`, `iModel.hilited`).\n * @internal\n */\nexport class IModelSelectionHandler {\n private _selectionSourceName = \"Tool\";\n\n private _imodelAccess: EnableUnifiedSelectionSyncWithIModelProps[\"imodelAccess\"];\n private _selectionStorage: SelectionStorage;\n private _hiliteSetProvider: HiliteSetProvider;\n private _cachingHiliteSetProvider: CachingHiliteSetProvider;\n private _activeScopeProvider: () => ComputeSelectionProps[\"scope\"];\n\n private _isSuspended: boolean;\n private _cancelOngoingChanges = new Subject<void>();\n private _unifiedSelectionListenerDisposeFunc: () => void;\n private _imodelListenerDisposeFunc: () => void;\n private _hasCustomCachingHiliteSetProvider: boolean;\n\n public constructor(props: EnableUnifiedSelectionSyncWithIModelProps) {\n this._imodelAccess = props.imodelAccess;\n this._selectionStorage = props.selectionStorage;\n this._activeScopeProvider = props.activeScopeProvider;\n this._isSuspended = false;\n this._hasCustomCachingHiliteSetProvider = !!props.cachingHiliteSetProvider;\n\n this._cachingHiliteSetProvider =\n props.cachingHiliteSetProvider ??\n createCachingHiliteSetProvider({\n selectionStorage: this._selectionStorage,\n imodelProvider: () => this._imodelAccess,\n });\n\n this._hiliteSetProvider = createHiliteSetProvider({ imodelAccess: this._imodelAccess });\n this._imodelListenerDisposeFunc = this._imodelAccess.selectionSet.onChanged.addListener(this.onIModelSelectionChanged);\n this._unifiedSelectionListenerDisposeFunc = this._selectionStorage.selectionChangeEvent.addListener(this.onUnifiedSelectionChanged);\n\n // stop imodel from syncing tool selection with hilited list - we want to override that behavior\n this._imodelAccess.hiliteSet.wantSyncWithSelectionSet = false;\n this.applyCurrentHiliteSet({ activeSelectionAction: \"clearAll\" });\n }\n\n public dispose() {\n this._cancelOngoingChanges.next();\n this._imodelListenerDisposeFunc();\n this._unifiedSelectionListenerDisposeFunc();\n if (!this._hasCustomCachingHiliteSetProvider) {\n this._cachingHiliteSetProvider.dispose();\n }\n }\n\n /** Temporarily suspends tool selection synchronization until the returned `IDisposable` is disposed. */\n public suspendIModelToolSelectionSync() {\n const wasSuspended = this._isSuspended;\n this._isSuspended = true;\n return {\n dispose: () => (this._isSuspended = wasSuspended),\n };\n }\n\n private handleUnifiedSelectionChange(changeType: StorageSelectionChangeType, selectables: Selectables, source: string) {\n if (changeType === \"clear\" || changeType === \"replace\") {\n this.applyCurrentHiliteSet({ activeSelectionAction: changeType === \"replace\" && source === \"Tool\" ? \"clearHilited\" : \"clearAll\" });\n return;\n }\n\n if (changeType === \"add\") {\n from(this._hiliteSetProvider.getHiliteSet({ selectables }))\n .pipe(takeUntil(this._cancelOngoingChanges))\n .subscribe({\n next: (set) => {\n this.addHiliteSet(set);\n },\n });\n return;\n }\n\n from(this._hiliteSetProvider.getHiliteSet({ selectables }))\n .pipe(takeUntil(this._cancelOngoingChanges))\n .subscribe({\n next: (set) => {\n this.removeHiliteSet(set);\n },\n complete: () => {\n this.applyCurrentHiliteSet({ activeSelectionAction: \"keep\" });\n },\n });\n }\n\n private onUnifiedSelectionChanged = (args: StorageSelectionChangeEventArgs) => {\n // iModels are only interested in top-level selection changes\n if (args.imodelKey !== this._imodelAccess.key || args.level !== 0) {\n return;\n }\n\n if (args.changeType === \"replace\" || args.changeType === \"clear\") {\n this._cancelOngoingChanges.next();\n }\n this.handleUnifiedSelectionChange(args.changeType, args.selectables, args.source);\n };\n\n private applyCurrentHiliteSet({ activeSelectionAction }: { activeSelectionAction: \"clearAll\" | \"clearHilited\" | \"keep\" }) {\n if (activeSelectionAction !== \"keep\") {\n using(this.suspendIModelToolSelectionSync(), (_) => {\n this._imodelAccess.hiliteSet.clear();\n if (activeSelectionAction === \"clearAll\") {\n this._imodelAccess.selectionSet.emptyAll();\n }\n });\n }\n\n from(this._cachingHiliteSetProvider.getHiliteSet({ imodelKey: this._imodelAccess.key }))\n .pipe(takeUntil(this._cancelOngoingChanges))\n .subscribe({\n next: (ids) => {\n this.addHiliteSet(ids);\n },\n });\n }\n\n private addHiliteSet(set: HiliteSet) {\n using(this.suspendIModelToolSelectionSync(), (_) => {\n if (set.models && set.models.length) {\n this._imodelAccess.hiliteSet.models.addIds(set.models);\n }\n if (set.subCategories && set.subCategories.length) {\n this._imodelAccess.hiliteSet.subcategories.addIds(set.subCategories);\n }\n if (set.elements && set.elements.length) {\n this._imodelAccess.hiliteSet.elements.addIds(set.elements);\n this._imodelAccess.selectionSet.add(set.elements);\n }\n });\n }\n\n private removeHiliteSet(set: HiliteSet) {\n using(this.suspendIModelToolSelectionSync(), (_) => {\n if (set.models.length) {\n this._imodelAccess.hiliteSet.models.deleteIds(set.models);\n }\n if (set.subCategories.length) {\n this._imodelAccess.hiliteSet.subcategories.deleteIds(set.subCategories);\n }\n if (set.elements.length) {\n this._imodelAccess.hiliteSet.elements.deleteIds(set.elements);\n this._imodelAccess.selectionSet.remove(set.elements);\n }\n });\n }\n\n private onIModelSelectionChanged = async (event?: CoreSelectionSetEventUnsafe): Promise<void> => {\n if (this._isSuspended) {\n return;\n }\n\n if (CoreSelectionSetEventType.Clear === event!.type) {\n this._selectionStorage.clearSelection({ imodelKey: this._imodelAccess.key, source: this._selectionSourceName });\n return;\n }\n\n const elementIds = this.getSelectionSetChangeIds(event!);\n const scopedSelection = computeSelection({ queryExecutor: this._imodelAccess, elementIds, scope: this._activeScopeProvider() });\n await this.handleIModelSelectionChange(event!.type, scopedSelection);\n };\n\n private async handleIModelSelectionChange(type: CoreSelectionSetEventType, iterator: AsyncIterableIterator<SelectableInstanceKey>) {\n const selectables: SelectableInstanceKey[] = [];\n for await (const selectable of iterator) {\n selectables.push(selectable);\n }\n const props = {\n imodelKey: this._imodelAccess.key,\n source: this._selectionSourceName,\n selectables,\n };\n switch (type) {\n case CoreSelectionSetEventType.Add:\n return this._selectionStorage.addToSelection(props);\n case CoreSelectionSetEventType.Remove:\n return this._selectionStorage.removeFromSelection(props);\n case CoreSelectionSetEventType.Replace:\n return this._selectionStorage.replaceSelection(props);\n }\n }\n\n private getSelectionSetChangeIds(event: CoreSelectionSetEventUnsafe): string[] {\n switch (event.type) {\n case CoreSelectionSetEventType.Add:\n case CoreSelectionSetEventType.Replace:\n assert(!!event.added);\n return this.idArgToIds(event.added);\n default:\n assert(!!event.removed);\n return this.idArgToIds(event.removed);\n }\n }\n\n private idArgToIds(ids: Id64Arg): string[] {\n if (typeof ids === \"string\") {\n return [ids];\n }\n if (ids instanceof Set) {\n return [...ids];\n }\n return ids;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EnableUnifiedSelectionSyncWithIModel.js","sourceRoot":"","sources":["../../../src/unified-selection/EnableUnifiedSelectionSyncWithIModel.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEhG,oFAGC;AAzED,+BAAwG;AAExG,+EAAyG;AACzG,iEAA+F;AAG/F,2DAA8E;AAE9E,iDAA2J;AAC3J,yCAAyC;AAwDzC;;;;GAIG;AACH,SAAgB,oCAAoC,CAAC,KAAgD;IACnG,MAAM,gBAAgB,GAAG,IAAI,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAC3D,OAAO,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAa,sBAAsB;IACzB,oBAAoB,GAAG,MAAM,CAAC;IAE9B,aAAa,CAA4D;IACzE,iBAAiB,CAAmB;IACpC,kBAAkB,CAAoB;IACtC,yBAAyB,CAAqF;IAC9G,oBAAoB,CAAuC;IAE3D,YAAY,CAAU;IACtB,qBAAqB,GAAG,IAAI,cAAO,EAAQ,CAAC;IAC5C,mCAAmC,CAAa;IAChD,qCAAqC,CAAa;IAClD,kCAAkC,CAAU;IAEpD,YAAmB,KAAgD;QACjE,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,gBAAgB,CAAC;QAChD,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC,mBAAmB,CAAC;QACtD,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,kCAAkC,GAAG,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC;QAE3E,IAAI,CAAC,yBAAyB;YAC5B,KAAK,CAAC,wBAAwB;gBAC9B,IAAA,4DAA8B,EAAC;oBAC7B,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AAK,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;YAChG,KAAK,qCAAyB,CAAC,MAAM;gBACnC,OAAO,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;YACnG,KAAK,qCAAyB,CAAC,OAAO;gBACpC,OAAO,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QACvF,CAAC;IACH,CAAC;CACF;AAlND,wDAkNC","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 { EMPTY, firstValueFrom, from, map, merge, Observable, Subject, takeUntil, toArray } from \"rxjs\";\nimport { ECClassHierarchyInspector, ECSqlQueryExecutor } from \"@itwin/presentation-shared\";\nimport { CachingHiliteSetProvider, createCachingHiliteSetProvider } from \"./CachingHiliteSetProvider.js\";\nimport { createHiliteSetProvider, HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider.js\";\nimport { SelectableInstanceKey, Selectables } from \"./Selectable.js\";\nimport { StorageSelectionChangeEventArgs, StorageSelectionChangeType } from \"./SelectionChangeEvent.js\";\nimport { computeSelection, ComputeSelectionProps } from \"./SelectionScope.js\";\nimport { SelectionStorage } from \"./SelectionStorage.js\";\nimport { CoreIModelHiliteSet, CoreIModelSelectionSet, CoreSelectableIds, CoreSelectionSetEventType, CoreSelectionSetEventUnsafe } from \"./types/IModel.js\";\nimport { safeDispose } from \"./Utils.js\";\n\n/**\n * Props for `enableUnifiedSelectionSyncWithIModel`.\n * @public\n */\nexport interface EnableUnifiedSelectionSyncWithIModelProps {\n /**\n * Provides access to different iModel's features: query executing, class hierarchy, selection and hilite sets.\n * It's recommended to use `@itwin/presentation-core-interop` to create `ECSqlQueryExecutor` and `ECSchemaProvider` from\n * [IModelConnection](https://www.itwinjs.org/reference/core-frontend/imodelconnection/imodelconnection/) and map its `key`,\n * `hilited` and `selectionSet` attributes like this:\n *\n * ```ts\n * import { createECSqlQueryExecutor, createECSchemaProvider } from \"@itwin/presentation-core-interop\";\n * import { createCachingECClassHierarchyInspector } from \"@itwin/presentation-shared\";\n * import { IModelConnection } from \"@itwin/core-frontend\";\n *\n * const imodel: IModelConnection = ...\n * const imodelAccess = {\n * ...createECSqlQueryExecutor(imodel),\n * ...createCachingECClassHierarchyInspector({ schemaProvider: createECSchemaProvider(MyAppFrontend.getSchemaContext(imodel)) }),\n * key: imodel.key,\n * hiliteSet: imodel.hilited,\n * selectionSet: imodel.selectionSet,\n * };\n * ```.\n */\n imodelAccess: ECSqlQueryExecutor &\n ECClassHierarchyInspector & {\n /** Key of the iModel. Generally taken from `IModelConnection.key`. */\n readonly key: string;\n /** The set of currently hilited elements taken from `IModelConnection.hilited`. */\n readonly hiliteSet: CoreIModelHiliteSet;\n /** The set of currently selected elements taken from `IModelConnection.selectionSet`. */\n readonly selectionSet: CoreIModelSelectionSet;\n };\n\n /** Selection storage to synchronize IModel's tool selection with. */\n selectionStorage: SelectionStorage;\n\n /** Active scope provider. */\n activeScopeProvider: () => ComputeSelectionProps[\"scope\"];\n\n /**\n * A caching hilite set provider used to retrieve hilite sets for an iModel. If not provided, a new `CachingHiliteSetProvider`\n * will be created for the given iModel using the provided `imodelAccess`.\n * If the consuming application already has a `CachingHiliteSetProvider` defined, it should be provided instead\n * to reuse the cache and avoid creating new providers for each iModel.\n *\n * The type is defined in a way that makes it required for provider to have either the deprecated `dispose` or the\n * new `Symbol.dispose` method.\n */\n cachingHiliteSetProvider?: CachingHiliteSetProvider | (Omit<CachingHiliteSetProvider, \"dispose\"> & { [Symbol.dispose]: () => void });\n}\n\n/**\n * Enables synchronization between iModel selection and unified selection.\n * @returns function for disposing the synchronization.\n * @public\n */\nexport function enableUnifiedSelectionSyncWithIModel(props: EnableUnifiedSelectionSyncWithIModelProps): () => void {\n const selectionHandler = new IModelSelectionHandler(props);\n return () => selectionHandler[Symbol.dispose]();\n}\n\n/**\n * A handler that syncs selection between unified selection storage\n * (`SelectionStorage`) and an iModel (`iModel.selectionSet`, `iModel.hilited`).\n * @internal\n */\nexport class IModelSelectionHandler {\n private _selectionSourceName = \"Tool\";\n\n private _imodelAccess: EnableUnifiedSelectionSyncWithIModelProps[\"imodelAccess\"];\n private _selectionStorage: SelectionStorage;\n private _hiliteSetProvider: HiliteSetProvider;\n private _cachingHiliteSetProvider: NonNullable<EnableUnifiedSelectionSyncWithIModelProps[\"cachingHiliteSetProvider\"]>;\n private _activeScopeProvider: () => ComputeSelectionProps[\"scope\"];\n\n private _isSuspended: boolean;\n private _cancelOngoingChanges = new Subject<void>();\n private _unregisterUnifiedSelectionListener: () => void;\n private _unregisterIModelSelectionSetListener: () => void;\n private _hasCustomCachingHiliteSetProvider: boolean;\n\n public constructor(props: EnableUnifiedSelectionSyncWithIModelProps) {\n this._imodelAccess = props.imodelAccess;\n this._selectionStorage = props.selectionStorage;\n this._activeScopeProvider = props.activeScopeProvider;\n this._isSuspended = false;\n this._hasCustomCachingHiliteSetProvider = !!props.cachingHiliteSetProvider;\n\n this._cachingHiliteSetProvider =\n props.cachingHiliteSetProvider ??\n createCachingHiliteSetProvider({\n selectionStorage: this._selectionStorage,\n imodelProvider: () => this._imodelAccess,\n });\n\n this._hiliteSetProvider = createHiliteSetProvider({ imodelAccess: this._imodelAccess });\n this._unregisterIModelSelectionSetListener = this._imodelAccess.selectionSet.onChanged.addListener(this.onIModelSelectionChanged);\n this._unregisterUnifiedSelectionListener = this._selectionStorage.selectionChangeEvent.addListener(this.onUnifiedSelectionChanged);\n\n this.applyCurrentHiliteSet({ activeSelectionAction: \"clear\" });\n }\n\n public [Symbol.dispose]() {\n this._cancelOngoingChanges.next();\n this._unregisterIModelSelectionSetListener();\n this._unregisterUnifiedSelectionListener();\n if (!this._hasCustomCachingHiliteSetProvider) {\n safeDispose(this._cachingHiliteSetProvider);\n }\n }\n\n /** Temporarily suspends tool selection synchronization until the returned disposable object is disposed. */\n public suspendIModelToolSelectionSync() {\n const wasSuspended = this._isSuspended;\n this._isSuspended = true;\n return {\n [Symbol.dispose]: () => {\n this._isSuspended = wasSuspended;\n },\n };\n }\n\n private handleUnifiedSelectionChange(changeType: StorageSelectionChangeType, selectables: Selectables, source: string): void {\n switch (changeType) {\n case \"clear\":\n case \"replace\":\n return this.applyCurrentHiliteSet({ activeSelectionAction: source === \"Tool\" ? \"keep\" : \"clear\" });\n case \"add\":\n return void from(this._hiliteSetProvider.getHiliteSet({ selectables }))\n .pipe(takeUntil(this._cancelOngoingChanges))\n .subscribe({\n next: (set) => {\n this.addHiliteSet(set);\n },\n });\n case \"remove\":\n return void from(this._hiliteSetProvider.getHiliteSet({ selectables }))\n .pipe(takeUntil(this._cancelOngoingChanges))\n .subscribe({\n next: (set) => {\n this.removeHiliteSet(set);\n },\n complete: () => {\n this.applyCurrentHiliteSet({ activeSelectionAction: \"keep\" });\n },\n });\n }\n }\n\n private onUnifiedSelectionChanged = (args: StorageSelectionChangeEventArgs) => {\n // iModels are only interested in top-level selection changes\n if (args.imodelKey !== this._imodelAccess.key || args.level !== 0) {\n return;\n }\n\n if (args.changeType === \"replace\" || args.changeType === \"clear\") {\n this._cancelOngoingChanges.next();\n }\n this.handleUnifiedSelectionChange(args.changeType, args.selectables, args.source);\n };\n\n private applyCurrentHiliteSet({ activeSelectionAction }: { activeSelectionAction: \"clear\" | \"keep\" }) {\n if (activeSelectionAction === \"clear\") {\n using _dispose = this.suspendIModelToolSelectionSync();\n this._imodelAccess.hiliteSet.clear();\n this._imodelAccess.selectionSet.emptyAll();\n }\n\n from(this._cachingHiliteSetProvider.getHiliteSet({ imodelKey: this._imodelAccess.key }))\n .pipe(takeUntil(this._cancelOngoingChanges))\n .subscribe({\n next: (ids) => {\n this.addHiliteSet(ids);\n },\n });\n }\n\n private addHiliteSet(set: HiliteSet) {\n using _dispose = this.suspendIModelToolSelectionSync();\n if (\"active\" in this._imodelAccess.selectionSet) {\n // the `active` property tells us we're using 5.0 core, which supports models and subcategories\n // in selection set - we can simply add the set as a whole\n this._imodelAccess.selectionSet.add({\n models: set.models,\n subcategories: set.subCategories,\n elements: set.elements,\n });\n } else {\n // pre-5.0 core requires adding models and subcategories to hilite set separately\n if (set.models.length) {\n this._imodelAccess.hiliteSet.models.addIds(set.models);\n }\n if (set.subCategories.length) {\n this._imodelAccess.hiliteSet.subcategories.addIds(set.subCategories);\n }\n if (set.elements.length) {\n this._imodelAccess.selectionSet.add(set.elements);\n }\n }\n }\n\n private removeHiliteSet(set: HiliteSet) {\n using _dispose = this.suspendIModelToolSelectionSync();\n if (\"active\" in this._imodelAccess.selectionSet) {\n // the `active` property tells us we're using 5.0 core, which supports models and subcategories\n // in selection set - we can simply remove the set as a whole\n this._imodelAccess.selectionSet.remove({\n models: set.models,\n subcategories: set.subCategories,\n elements: set.elements,\n });\n } else {\n if (set.models.length) {\n this._imodelAccess.hiliteSet.models.deleteIds(set.models);\n }\n if (set.subCategories.length) {\n this._imodelAccess.hiliteSet.subcategories.deleteIds(set.subCategories);\n }\n if (set.elements.length) {\n this._imodelAccess.selectionSet.remove(set.elements);\n }\n }\n }\n\n private onIModelSelectionChanged = async (event: CoreSelectionSetEventUnsafe): Promise<void> => {\n if (this._isSuspended) {\n return;\n }\n\n if (CoreSelectionSetEventType.Clear === event.type) {\n this._selectionStorage.clearSelection({ imodelKey: this._imodelAccess.key, source: this._selectionSourceName });\n return;\n }\n\n const ids = this.getSelectionSetChangeIds(event);\n const scopedSelection = merge(\n ids.elements\n ? from(computeSelection({ queryExecutor: this._imodelAccess, elementIds: ids.elements, scope: this._activeScopeProvider() }))\n : /* c8 ignore next */ EMPTY,\n ids.models ? from(ids.models).pipe(map((id) => ({ className: \"BisCore.Model\", id }))) : /* c8 ignore next */ EMPTY,\n ids.subcategories ? from(ids.subcategories).pipe(map((id) => ({ className: \"BisCore.SubCategory\", id }))) : /* c8 ignore next */ EMPTY,\n );\n await this.handleIModelSelectionChange(event.type, scopedSelection);\n };\n\n private async handleIModelSelectionChange(type: CoreSelectionSetEventType, keys: Observable<SelectableInstanceKey>) {\n const selectables = await firstValueFrom(keys.pipe(toArray()));\n const props = {\n imodelKey: this._imodelAccess.key,\n source: this._selectionSourceName,\n selectables,\n };\n switch (type) {\n case CoreSelectionSetEventType.Add:\n return this._selectionStorage.addToSelection(props);\n case CoreSelectionSetEventType.Remove:\n return this._selectionStorage.removeFromSelection(props);\n case CoreSelectionSetEventType.Replace:\n return this._selectionStorage.replaceSelection(props);\n }\n }\n\n private getSelectionSetChangeIds(\n event: Omit<CoreSelectionSetEventUnsafe, \"type\"> & {\n type: CoreSelectionSetEventType.Add | CoreSelectionSetEventType.Remove | CoreSelectionSetEventType.Replace;\n },\n ): CoreSelectableIds {\n switch (event.type) {\n case CoreSelectionSetEventType.Add:\n return event.additions ?? (event.added ? { elements: event.added } : /* c8 ignore next */ {});\n case CoreSelectionSetEventType.Remove:\n return event.removals ?? (event.removed ? { elements: event.removed } : /* c8 ignore next */ {});\n case CoreSelectionSetEventType.Replace:\n return \"active\" in event.set ? event.set.active : { elements: event.set.elements };\n }\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Id64Arg } from "@itwin/core-bentley";
|
|
1
2
|
import { ECSqlQueryExecutor } from "@itwin/presentation-shared";
|
|
2
3
|
import { SelectableInstanceKey } from "./Selectable.js";
|
|
3
4
|
/**
|
|
@@ -30,7 +31,7 @@ export interface ComputeSelectionProps {
|
|
|
30
31
|
/** iModel query executor. */
|
|
31
32
|
queryExecutor: ECSqlQueryExecutor;
|
|
32
33
|
/** IDs of elements to compute selection for. */
|
|
33
|
-
elementIds:
|
|
34
|
+
elementIds: Id64Arg;
|
|
34
35
|
/** Selection scope to compute selection with. */
|
|
35
36
|
scope: ElementSelectionScopeProps | {
|
|
36
37
|
id: SelectionScope;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionScope.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/SelectionScope.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SelectionScope.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/SelectionScope.ts"],"names":[],"mappings":"AAKA,OAAO,EAAQ,OAAO,EAAa,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAA+B,kBAAkB,EAAiB,MAAM,4BAA4B,CAAC;AAC5G,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,YAAY,CAAC;AAE7E;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,0EAA0E;IAC1E,EAAE,EAAE,SAAS,GAAG,YAAY,CAAC;IAC7B;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,6BAA6B;IAC7B,aAAa,EAAE,kBAAkB,CAAC;IAClC,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;IACpB,iDAAiD;IACjD,KAAK,EAAE,0BAA0B,GAAG;QAAE,EAAE,EAAE,cAAc,CAAA;KAAE,GAAG,cAAc,CAAC;CAC7E;AAED;;;GAGG;AACH,wBAAuB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,CA6BlH"}
|
|
@@ -17,19 +17,24 @@ async function* computeSelection(props) {
|
|
|
17
17
|
yield* computeSelection({ queryExecutor, elementIds, scope: { id: scope } });
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const nonTransientIds = [];
|
|
21
|
+
for (const id of core_bentley_1.Id64.iterable(elementIds)) {
|
|
22
|
+
if (!core_bentley_1.Id64.isTransient(id)) {
|
|
23
|
+
nonTransientIds.push(id);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
21
26
|
switch (scope.id) {
|
|
22
27
|
case "element":
|
|
23
|
-
yield* computeElementSelection(queryExecutor,
|
|
28
|
+
yield* computeElementSelection(queryExecutor, nonTransientIds, scope.ancestorLevel ?? 0);
|
|
24
29
|
return;
|
|
25
30
|
case "category":
|
|
26
|
-
yield* computeCategorySelection(queryExecutor,
|
|
31
|
+
yield* computeCategorySelection(queryExecutor, nonTransientIds);
|
|
27
32
|
return;
|
|
28
33
|
case "model":
|
|
29
|
-
yield* computeModelSelection(queryExecutor,
|
|
34
|
+
yield* computeModelSelection(queryExecutor, nonTransientIds);
|
|
30
35
|
return;
|
|
31
36
|
case "functional":
|
|
32
|
-
yield* computeFunctionalElementSelection(queryExecutor,
|
|
37
|
+
yield* computeFunctionalElementSelection(queryExecutor, nonTransientIds, scope.ancestorLevel ?? 0);
|
|
33
38
|
return;
|
|
34
39
|
}
|
|
35
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionScope.js","sourceRoot":"","sources":["../../../src/unified-selection/SelectionScope.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAgDhG,4CAwBC;AAtED,sDAA2C;AAG3C,yCAAiE;AAuCjE;;;GAGG;AACI,KAAK,SAAS,CAAC,CAAC,gBAAgB,CAAC,KAA4B;IAClE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAEnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,KAAK,CAAC,CAAC,gBAAgB,CAAC,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE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;;gBAO/E,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe;;KAElD;QACD;;gDAE4C,wBAAwB,CAAC,aAAa,EAAE,QAAQ,CAAC;;gBAEjF,IAAA,yBAAc,EAAC,iBAAiB,EAAE,GAAG,EAAE,QAAQ,CAAC;;;;;gBAKhD,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe;;KAElD;QACD;;;;;;;gBAOY,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,mBAAmB;;KAEtD;KACF,CAAC;IACF,MAAM,KAAK,GAAG;QACZ;;;eAGW,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc;KAChD;QACD;;KAEC;KACF,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClB,KAAK,CAAC,CAAC,YAAY,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,wBAAwB,CAAC,aAAqB,EAAE,QAAwB;IAC/E,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;IACrD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,YAAY,CAAC,aAAiC,EAAE,KAAoB;IAClF,KAAK,CAAC,CAAC,IAAA,8BAAmB,EAAC,aAAa,EAAE,KAAK,EAAE,CAAC,GAAkB,EAAE,EAAE,CAAC,CAAC;QACxE,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,EAAE,EAAE,GAAG,CAAC,YAAY;KACrB,CAAC,CAAC,CAAC;AACN,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\nimport { Id64 } from \"@itwin/core-bentley\";\nimport { ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryRow } from \"@itwin/presentation-shared\";\nimport { SelectableInstanceKey } from \"./Selectable.js\";\nimport { formIdBindings, genericExecuteQuery } from \"./Utils.js\";\n\n/**\n * Available selection scopes.\n * @public\n */\nexport type SelectionScope = \"element\" | \"model\" | \"category\" | \"functional\";\n\n/**\n * Props for computing element selection.\n * @public\n */\nexport interface ElementSelectionScopeProps {\n /** Identifies this as either \"element\" or \"functional\" selection scope */\n id: \"element\" | \"functional\";\n /**\n * Specifies how far \"up\" we should walk to find the target element. When not specified or `0`,\n * the target element matches the request element. When set to `1`, the target element matches the direct parent element.\n * When set to `2`, the target element is parent of the parent element and so on. In all situations when this is `> 0`,\n * we're not walking further than the last existing element, for example when `ancestorLevel = 1` (direct parent\n * element is requested), but the request element doesn't have a parent, the request element is returned as the result.\n * A negative value would result in the top-most element to be returned.\n */\n ancestorLevel?: number;\n}\n\n/**\n * Props for `computeSelection`.\n * @public\n */\nexport interface ComputeSelectionProps {\n /** iModel query executor. */\n queryExecutor: ECSqlQueryExecutor;\n /** IDs of elements to compute selection for. */\n elementIds: string[];\n /** Selection scope to compute selection with. */\n scope: ElementSelectionScopeProps | { id: SelectionScope } | SelectionScope;\n}\n\n/**\n * Computes selection from given element IDs.\n * @public\n */\nexport async function* computeSelection(props: ComputeSelectionProps): AsyncIterableIterator<SelectableInstanceKey> {\n const { queryExecutor, elementIds, scope } = props;\n\n if (typeof scope === \"string\") {\n yield* computeSelection({ queryExecutor, elementIds, scope: { id: scope } });\n return;\n }\n\n const nonTransientKeys = elementIds.filter((key) => !Id64.isTransient(key));\n\n switch (scope.id) {\n case \"element\":\n yield* computeElementSelection(queryExecutor, nonTransientKeys, (scope as ElementSelectionScopeProps).ancestorLevel ?? 0);\n return;\n case \"category\":\n yield* computeCategorySelection(queryExecutor, nonTransientKeys);\n return;\n case \"model\":\n yield* computeModelSelection(queryExecutor, nonTransientKeys);\n return;\n case \"functional\":\n yield* computeFunctionalElementSelection(queryExecutor, nonTransientKeys, (scope as ElementSelectionScopeProps).ancestorLevel ?? 0);\n return;\n }\n}\n\nasync function* computeElementSelection(\n queryExecutor: ECSqlQueryExecutor,\n elementIds: string[],\n ancestorLevel: number,\n): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const recurseUntilRoot = ancestorLevel < 0;\n const ctes = [\n `\n AncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT ECInstanceId, ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, Parent.Id\n FROM BisCore.Element\n WHERE ${formIdBindings(\"ECInstanceId\", elementIds, bindings)}\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, a.Depth - 1, pe.Parent.Id\n FROM AncestorElements a\n JOIN BisCore.Element pe ON pe.ECInstanceId = a.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n ];\n const ecsql = `\n SELECT DISTINCT ECInstanceId, ec_classname(ECClassId, 's.c') AS ClassName\n FROM AncestorElements\n WHERE ${recurseUntilRoot ? \"\" : \"Depth = 0 OR\"} ParentId IS NULL\n `;\n yield* executeQuery(queryExecutor, { ctes, ecsql, bindings });\n}\n\nasync function* computeCategorySelection(queryExecutor: ECSqlQueryExecutor, ids: string[]): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const ecsql = [\n `\n SELECT DISTINCT c.ECInstanceId, ec_classname(c.ECClassId, 's.c') AS ClassName\n FROM BisCore.Category c\n JOIN BisCore.GeometricElement2d ge ON ge.Category.Id = c.ECInstanceId\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n `,\n `\n SELECT DISTINCT c.ECInstanceId, ec_classname(c.ECClassId, 's.c') AS ClassName\n FROM BisCore.Category c\n JOIN BisCore.GeometricElement3d ge ON ge.Category.Id = c.ECInstanceId\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n `,\n ].join(\" UNION ALL \");\n yield* executeQuery(queryExecutor, { ecsql, bindings });\n}\n\nasync function* computeModelSelection(queryExecutor: ECSqlQueryExecutor, ids: string[]): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const ecsql = `\n SELECT DISTINCT m.ECInstanceId, ec_classname(m.ECClassId, 's.c') AS ClassName\n FROM BisCore.Model m\n JOIN BisCore.Element e ON e.Model.Id = m.ECInstanceId\n WHERE ${formIdBindings(\"e.ECInstanceId\", ids, bindings)}\n `;\n yield* executeQuery(queryExecutor, { ecsql, bindings });\n}\n\nasync function* computeFunctionalElementSelection(\n queryExecutor: ECSqlQueryExecutor,\n ids: string[],\n ancestorLevel: number,\n): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const recurseUntilRoot = ancestorLevel < 0;\n const ctes = [\n `\n Elements2dOrNearestFunctionalElements(OriginalECInstanceId, OriginalECClassId, ECInstanceId, ECClassId, ParentId) AS (\n SELECT ECInstanceId, ECClassId, ECInstanceId, ECClassId, Parent.Id\n FROM BisCore.Element\n WHERE ${formIdBindings(\"ECInstanceId\", ids, bindings)} AND ECClassId IS NOT (BisCore.GeometricElement3d)\n UNION ALL\n SELECT\n e2onfe.OriginalECInstanceId,\n e2onfe.OriginalECClassId,\n COALESCE(dgrfe.TargetECInstanceId, pe.ECInstanceId),\n COALESCE(dgrfe.TargetECClassId, pe.ECClassId),\n pe.Parent.Id\n FROM Elements2dOrNearestFunctionalElements e2onfe\n LEFT JOIN BisCore.Element pe ON pe.ECInstanceId = e2onfe.ParentId\n LEFT JOIN Functional.DrawingGraphicRepresentsFunctionalElement dgrfe ON dgrfe.SourceECInstanceId = e2onfe.ECInstanceId\n WHERE e2onfe.ECClassId IS NOT (Functional.FunctionalElement) AND (e2onfe.ParentId IS NOT NULL OR dgrfe.TargetECInstanceId IS NOT NULL)\n )\n `,\n `\n Element2dNearestFunctionalElements(OriginalECInstanceId, ECInstanceId, ECClassId) AS (\n SELECT OriginalECInstanceId, ECInstanceId, ECClassId\n FROM Elements2dOrNearestFunctionalElements\n WHERE ECClassId IS (Functional.FunctionalElement)\n )\n `,\n `\n Elements2dWithoutFunctionalElement(ECInstanceId, ECClassId) AS (\n SELECT e2wfe.OriginalECInstanceId, OriginalECClassId\n FROM Elements2dOrNearestFunctionalElements e2wfe\n LEFT JOIN Element2dNearestFunctionalElements e2nfe ON e2nfe.OriginalECInstanceId = e2wfe.OriginalECInstanceId\n WHERE e2wfe.ParentId IS NULL AND e2nfe.ECInstanceId IS NULL\n )\n `,\n `\n Elements2d(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM Element2dNearestFunctionalElements\n UNION\n SELECT ECInstanceId, ECClassId FROM Elements2dWithoutFunctionalElement\n )\n `,\n `\n Element2dAncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT e.ECInstanceId, e.ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, e.Parent.Id\n FROM BisCore.Element e\n JOIN Elements2d e2d ON e2d.ECInstanceId = e.ECInstanceId\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, e2ae.Depth - 1, pe.Parent.Id\n FROM Element2dAncestorElements e2ae\n JOIN BisCore.Element pe ON pe.ECInstanceId = e2ae.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n `\n Element3dAncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT ge.ECInstanceId, ge.ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, ge.Parent.Id\n FROM BisCore.GeometricElement3d ge\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, e3ae.Depth - 1, pe.Parent.Id\n FROM Element3dAncestorElements e3ae\n JOIN BisCore.Element pe ON pe.ECInstanceId = e3ae.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n `\n Element3dAncestorRelatedFunctionalElement(ECInstanceId, ClassName) AS (\n SELECT\n COALESCE(peff.TargetECInstanceId, e3ae.ECInstanceId),\n ec_classname(COALESCE(peff.TargetECClassId, e3ae.ECClassId), 's.c')\n FROM Element3dAncestorElements e3ae\n LEFT JOIN Functional.PhysicalElementFulfillsFunction peff ON peff.SourceECInstanceId = e3ae.ECInstanceId\n WHERE ${recurseUntilRoot ? \"\" : \"e3ae.Depth = 0 OR\"} e3ae.ParentId IS NULL\n )\n `,\n ];\n const ecsql = [\n `\n SELECT DISTINCT ECInstanceId, ec_classname(ECClassId, 's.c') AS ClassName\n FROM Element2dAncestorElements\n WHERE ${recurseUntilRoot ? \"\" : \"Depth = 0 OR\"} ParentId IS NULL\n `,\n `\n SELECT DISTINCT ECInstanceId, ClassName FROM Element3dAncestorRelatedFunctionalElement\n `,\n ].join(\" UNION \");\n yield* executeQuery(queryExecutor, { ctes, ecsql, bindings });\n}\n\nfunction formAncestorLevelBinding(ancestorLevel: number, bindings: ECSqlBinding[]) {\n bindings.push({ type: \"int\", value: ancestorLevel });\n return \"?\";\n}\n\nasync function* executeQuery(queryExecutor: ECSqlQueryExecutor, query: ECSqlQueryDef): AsyncIterableIterator<SelectableInstanceKey> {\n yield* genericExecuteQuery(queryExecutor, query, (row: ECSqlQueryRow) => ({\n className: row.ClassName,\n id: row.ECInstanceId,\n }));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SelectionScope.js","sourceRoot":"","sources":["../../../src/unified-selection/SelectionScope.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAgDhG,4CA6BC;AA3ED,sDAA+D;AAG/D,yCAAiE;AAuCjE;;;GAGG;AACI,KAAK,SAAS,CAAC,CAAC,gBAAgB,CAAC,KAA4B;IAClE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,EA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AE,KAAK,EAAE,CAAC,GAAkB,EAAE,EAAE,CAAC,CAAC;QACxE,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,EAAE,EAAE,GAAG,CAAC,YAAY;KACrB,CAAC,CAAC,CAAC;AACN,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\nimport { Id64, Id64Arg, Id64Array } from \"@itwin/core-bentley\";\nimport { ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryRow } from \"@itwin/presentation-shared\";\nimport { SelectableInstanceKey } from \"./Selectable.js\";\nimport { formIdBindings, genericExecuteQuery } from \"./Utils.js\";\n\n/**\n * Available selection scopes.\n * @public\n */\nexport type SelectionScope = \"element\" | \"model\" | \"category\" | \"functional\";\n\n/**\n * Props for computing element selection.\n * @public\n */\nexport interface ElementSelectionScopeProps {\n /** Identifies this as either \"element\" or \"functional\" selection scope */\n id: \"element\" | \"functional\";\n /**\n * Specifies how far \"up\" we should walk to find the target element. When not specified or `0`,\n * the target element matches the request element. When set to `1`, the target element matches the direct parent element.\n * When set to `2`, the target element is parent of the parent element and so on. In all situations when this is `> 0`,\n * we're not walking further than the last existing element, for example when `ancestorLevel = 1` (direct parent\n * element is requested), but the request element doesn't have a parent, the request element is returned as the result.\n * A negative value would result in the top-most element to be returned.\n */\n ancestorLevel?: number;\n}\n\n/**\n * Props for `computeSelection`.\n * @public\n */\nexport interface ComputeSelectionProps {\n /** iModel query executor. */\n queryExecutor: ECSqlQueryExecutor;\n /** IDs of elements to compute selection for. */\n elementIds: Id64Arg;\n /** Selection scope to compute selection with. */\n scope: ElementSelectionScopeProps | { id: SelectionScope } | SelectionScope;\n}\n\n/**\n * Computes selection from given element IDs.\n * @public\n */\nexport async function* computeSelection(props: ComputeSelectionProps): AsyncIterableIterator<SelectableInstanceKey> {\n const { queryExecutor, elementIds, scope } = props;\n\n if (typeof scope === \"string\") {\n yield* computeSelection({ queryExecutor, elementIds, scope: { id: scope } });\n return;\n }\n\n const nonTransientIds: Id64Array = [];\n for (const id of Id64.iterable(elementIds)) {\n if (!Id64.isTransient(id)) {\n nonTransientIds.push(id);\n }\n }\n\n switch (scope.id) {\n case \"element\":\n yield* computeElementSelection(queryExecutor, nonTransientIds, (scope as ElementSelectionScopeProps).ancestorLevel ?? 0);\n return;\n case \"category\":\n yield* computeCategorySelection(queryExecutor, nonTransientIds);\n return;\n case \"model\":\n yield* computeModelSelection(queryExecutor, nonTransientIds);\n return;\n case \"functional\":\n yield* computeFunctionalElementSelection(queryExecutor, nonTransientIds, (scope as ElementSelectionScopeProps).ancestorLevel ?? 0);\n return;\n }\n}\n\nasync function* computeElementSelection(\n queryExecutor: ECSqlQueryExecutor,\n elementIds: string[],\n ancestorLevel: number,\n): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const recurseUntilRoot = ancestorLevel < 0;\n const ctes = [\n `\n AncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT ECInstanceId, ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, Parent.Id\n FROM BisCore.Element\n WHERE ${formIdBindings(\"ECInstanceId\", elementIds, bindings)}\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, a.Depth - 1, pe.Parent.Id\n FROM AncestorElements a\n JOIN BisCore.Element pe ON pe.ECInstanceId = a.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n ];\n const ecsql = `\n SELECT DISTINCT ECInstanceId, ec_classname(ECClassId, 's.c') AS ClassName\n FROM AncestorElements\n WHERE ${recurseUntilRoot ? \"\" : \"Depth = 0 OR\"} ParentId IS NULL\n `;\n yield* executeQuery(queryExecutor, { ctes, ecsql, bindings });\n}\n\nasync function* computeCategorySelection(queryExecutor: ECSqlQueryExecutor, ids: string[]): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const ecsql = [\n `\n SELECT DISTINCT c.ECInstanceId, ec_classname(c.ECClassId, 's.c') AS ClassName\n FROM BisCore.Category c\n JOIN BisCore.GeometricElement2d ge ON ge.Category.Id = c.ECInstanceId\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n `,\n `\n SELECT DISTINCT c.ECInstanceId, ec_classname(c.ECClassId, 's.c') AS ClassName\n FROM BisCore.Category c\n JOIN BisCore.GeometricElement3d ge ON ge.Category.Id = c.ECInstanceId\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n `,\n ].join(\" UNION ALL \");\n yield* executeQuery(queryExecutor, { ecsql, bindings });\n}\n\nasync function* computeModelSelection(queryExecutor: ECSqlQueryExecutor, ids: string[]): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const ecsql = `\n SELECT DISTINCT m.ECInstanceId, ec_classname(m.ECClassId, 's.c') AS ClassName\n FROM BisCore.Model m\n JOIN BisCore.Element e ON e.Model.Id = m.ECInstanceId\n WHERE ${formIdBindings(\"e.ECInstanceId\", ids, bindings)}\n `;\n yield* executeQuery(queryExecutor, { ecsql, bindings });\n}\n\nasync function* computeFunctionalElementSelection(\n queryExecutor: ECSqlQueryExecutor,\n ids: string[],\n ancestorLevel: number,\n): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const recurseUntilRoot = ancestorLevel < 0;\n const ctes = [\n `\n Elements2dOrNearestFunctionalElements(OriginalECInstanceId, OriginalECClassId, ECInstanceId, ECClassId, ParentId) AS (\n SELECT ECInstanceId, ECClassId, ECInstanceId, ECClassId, Parent.Id\n FROM BisCore.Element\n WHERE ${formIdBindings(\"ECInstanceId\", ids, bindings)} AND ECClassId IS NOT (BisCore.GeometricElement3d)\n UNION ALL\n SELECT\n e2onfe.OriginalECInstanceId,\n e2onfe.OriginalECClassId,\n COALESCE(dgrfe.TargetECInstanceId, pe.ECInstanceId),\n COALESCE(dgrfe.TargetECClassId, pe.ECClassId),\n pe.Parent.Id\n FROM Elements2dOrNearestFunctionalElements e2onfe\n LEFT JOIN BisCore.Element pe ON pe.ECInstanceId = e2onfe.ParentId\n LEFT JOIN Functional.DrawingGraphicRepresentsFunctionalElement dgrfe ON dgrfe.SourceECInstanceId = e2onfe.ECInstanceId\n WHERE e2onfe.ECClassId IS NOT (Functional.FunctionalElement) AND (e2onfe.ParentId IS NOT NULL OR dgrfe.TargetECInstanceId IS NOT NULL)\n )\n `,\n `\n Element2dNearestFunctionalElements(OriginalECInstanceId, ECInstanceId, ECClassId) AS (\n SELECT OriginalECInstanceId, ECInstanceId, ECClassId\n FROM Elements2dOrNearestFunctionalElements\n WHERE ECClassId IS (Functional.FunctionalElement)\n )\n `,\n `\n Elements2dWithoutFunctionalElement(ECInstanceId, ECClassId) AS (\n SELECT e2wfe.OriginalECInstanceId, OriginalECClassId\n FROM Elements2dOrNearestFunctionalElements e2wfe\n LEFT JOIN Element2dNearestFunctionalElements e2nfe ON e2nfe.OriginalECInstanceId = e2wfe.OriginalECInstanceId\n WHERE e2wfe.ParentId IS NULL AND e2nfe.ECInstanceId IS NULL\n )\n `,\n `\n Elements2d(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM Element2dNearestFunctionalElements\n UNION\n SELECT ECInstanceId, ECClassId FROM Elements2dWithoutFunctionalElement\n )\n `,\n `\n Element2dAncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT e.ECInstanceId, e.ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, e.Parent.Id\n FROM BisCore.Element e\n JOIN Elements2d e2d ON e2d.ECInstanceId = e.ECInstanceId\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, e2ae.Depth - 1, pe.Parent.Id\n FROM Element2dAncestorElements e2ae\n JOIN BisCore.Element pe ON pe.ECInstanceId = e2ae.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n `\n Element3dAncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT ge.ECInstanceId, ge.ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, ge.Parent.Id\n FROM BisCore.GeometricElement3d ge\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, e3ae.Depth - 1, pe.Parent.Id\n FROM Element3dAncestorElements e3ae\n JOIN BisCore.Element pe ON pe.ECInstanceId = e3ae.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n `\n Element3dAncestorRelatedFunctionalElement(ECInstanceId, ClassName) AS (\n SELECT\n COALESCE(peff.TargetECInstanceId, e3ae.ECInstanceId),\n ec_classname(COALESCE(peff.TargetECClassId, e3ae.ECClassId), 's.c')\n FROM Element3dAncestorElements e3ae\n LEFT JOIN Functional.PhysicalElementFulfillsFunction peff ON peff.SourceECInstanceId = e3ae.ECInstanceId\n WHERE ${recurseUntilRoot ? \"\" : \"e3ae.Depth = 0 OR\"} e3ae.ParentId IS NULL\n )\n `,\n ];\n const ecsql = [\n `\n SELECT DISTINCT ECInstanceId, ec_classname(ECClassId, 's.c') AS ClassName\n FROM Element2dAncestorElements\n WHERE ${recurseUntilRoot ? \"\" : \"Depth = 0 OR\"} ParentId IS NULL\n `,\n `\n SELECT DISTINCT ECInstanceId, ClassName FROM Element3dAncestorRelatedFunctionalElement\n `,\n ].join(\" UNION \");\n yield* executeQuery(queryExecutor, { ctes, ecsql, bindings });\n}\n\nfunction formAncestorLevelBinding(ancestorLevel: number, bindings: ECSqlBinding[]) {\n bindings.push({ type: \"int\", value: ancestorLevel });\n return \"?\";\n}\n\nasync function* executeQuery(queryExecutor: ECSqlQueryExecutor, query: ECSqlQueryDef): AsyncIterableIterator<SelectableInstanceKey> {\n yield* genericExecuteQuery(queryExecutor, query, (row: ECSqlQueryRow) => ({\n className: row.ClassName,\n id: row.ECInstanceId,\n }));\n}\n"]}
|
|
@@ -15,4 +15,18 @@ export declare function genericExecuteQuery<T>(queryExecutor: ECSqlQueryExecutor
|
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
17
|
export declare function releaseMainThreadOnItemsCount<T>(elementCount: number): (obs: Observable<T>) => Observable<T>;
|
|
18
|
+
/**
|
|
19
|
+
* A helper that disposes the given object, if it's disposable.
|
|
20
|
+
*
|
|
21
|
+
* The first option is to dispose using the deprecated `dispose` method if it exists on the object.
|
|
22
|
+
* If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is
|
|
23
|
+
* considered as non-disposable and nothing is done with it.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare function safeDispose(disposable: {} | {
|
|
28
|
+
[Symbol.dispose]: () => void;
|
|
29
|
+
} | {
|
|
30
|
+
dispose: () => void;
|
|
31
|
+
}): void;
|
|
18
32
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/Utils.ts"],"names":[],"mappings":"AAKA,OAAO,EAA4C,UAAU,EAAM,MAAM,MAAM,CAAC;AAChF,OAAO,EAA8C,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAExJ;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAYhG;AAED;;;GAGG;AACH,wBAAuB,mBAAmB,CAAC,CAAC,EAC1C,aAAa,EAAE,kBAAkB,EACjC,KAAK,EAAE,aAAa,EACpB,aAAa,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,CAAC,GACvC,qBAAqB,CAAC,CAAC,CAAC,CAO1B;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,SACtD,UAAU,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAAC,CAa3C"}
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/Utils.ts"],"names":[],"mappings":"AAKA,OAAO,EAA4C,UAAU,EAAM,MAAM,MAAM,CAAC;AAChF,OAAO,EAA8C,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAExJ;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAYhG;AAED;;;GAGG;AACH,wBAAuB,mBAAmB,CAAC,CAAC,EAC1C,aAAa,EAAE,kBAAkB,EACjC,KAAK,EAAE,aAAa,EACpB,aAAa,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,CAAC,GACvC,qBAAqB,CAAC,CAAC,CAAC,CAO1B;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,SACtD,UAAU,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAAC,CAa3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,EAAE,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,QAMtG"}
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.formIdBindings = formIdBindings;
|
|
8
8
|
exports.genericExecuteQuery = genericExecuteQuery;
|
|
9
9
|
exports.releaseMainThreadOnItemsCount = releaseMainThreadOnItemsCount;
|
|
10
|
+
exports.safeDispose = safeDispose;
|
|
10
11
|
const rxjs_1 = require("rxjs");
|
|
11
12
|
const presentation_shared_1 = require("@itwin/presentation-shared");
|
|
12
13
|
/**
|
|
@@ -51,4 +52,21 @@ function releaseMainThreadOnItemsCount(elementCount) {
|
|
|
51
52
|
}), (0, rxjs_1.concatAll)());
|
|
52
53
|
};
|
|
53
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* A helper that disposes the given object, if it's disposable.
|
|
57
|
+
*
|
|
58
|
+
* The first option is to dispose using the deprecated `dispose` method if it exists on the object.
|
|
59
|
+
* If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is
|
|
60
|
+
* considered as non-disposable and nothing is done with it.
|
|
61
|
+
*
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
function safeDispose(disposable) {
|
|
65
|
+
if ("dispose" in disposable) {
|
|
66
|
+
disposable.dispose();
|
|
67
|
+
}
|
|
68
|
+
else if (Symbol.dispose in disposable) {
|
|
69
|
+
disposable[Symbol.dispose]();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
54
72
|
//# sourceMappingURL=Utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/unified-selection/Utils.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAShG,wCAYC;AAMD,kDAWC;AAMD,sEAcC;
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/unified-selection/Utils.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAShG,wCAYC;AAMD,kDAWC;AAMD,sEAcC;AAWD,kCAMC;AAzED,+BAAgF;AAChF,oEAAwJ;AAExJ;;;GAGG;AACH,SAAgB,cAAc,CAAC,QAAgB,EAAE,GAAa,EAAE,QAAwB;IACtF,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;QACtB,QAAQ,CAAC,IAAI,CAAC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;gBAC1C,OAAO,GAAG,CAAC;YACb,CAAC;YACD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAA,YAAK,EAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC,CAAC,EACF,IAAA,gBAAS,GAAE,CACZ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAC,UAA2E;IACrG,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;QAC5B,UAAU,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;SAAM,IAAI,MAAM,CAAC,OAAO,IAAI,UAAU,EAAE,CAAC;QACxC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/B,CAAC;AACH,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\nimport { bufferCount, concatAll, concatMap, delay, Observable, of } from \"rxjs\";\nimport { createMainThreadReleaseOnTimePassedHandler, ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryRow } from \"@itwin/presentation-shared\";\n\n/**\n * Forms ECSql bindings from given ID's.\n * @internal\n */\nexport function formIdBindings(property: string, ids: string[], bindings: ECSqlBinding[]): string {\n if (ids.length > 1000) {\n bindings.push({ type: \"idset\", value: ids });\n return `InVirtualSet(?, ${property})`;\n }\n\n if (ids.length === 0) {\n return `FALSE`;\n }\n\n ids.forEach((id) => bindings.push({ type: \"id\", value: id }));\n return `${property} IN (${ids.map(() => \"?\").join(\",\")})`;\n}\n\n/**\n * Executes given ECSql query and extracts data from rows. Additionally handles main thread releasing.\n * @internal\n */\nexport async function* genericExecuteQuery<T>(\n queryExecutor: ECSqlQueryExecutor,\n query: ECSqlQueryDef,\n parseQueryRow: (row: ECSqlQueryRow) => T,\n): AsyncIterableIterator<T> {\n const releaseMainThread = createMainThreadReleaseOnTimePassedHandler();\n const reader = queryExecutor.createQueryReader(query);\n for await (const row of reader) {\n yield parseQueryRow(row);\n await releaseMainThread();\n }\n}\n\n/**\n * Emits a certain amount of values, then releases the main thread for other timers to use.\n * @internal\n */\nexport function releaseMainThreadOnItemsCount<T>(elementCount: number) {\n return (obs: Observable<T>): Observable<T> => {\n return obs.pipe(\n bufferCount(elementCount),\n concatMap((buff, i) => {\n const out = of(buff);\n if (i === 0 && buff.length < elementCount) {\n return out;\n }\n return out.pipe(delay(0));\n }),\n concatAll(),\n );\n };\n}\n\n/**\n * A helper that disposes the given object, if it's disposable.\n *\n * The first option is to dispose using the deprecated `dispose` method if it exists on the object.\n * If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is\n * considered as non-disposable and nothing is done with it.\n *\n * @internal\n */\nexport function safeDispose(disposable: {} | { [Symbol.dispose]: () => void } | { dispose: () => void }) {\n if (\"dispose\" in disposable) {\n disposable.dispose();\n } else if (Symbol.dispose in disposable) {\n disposable[Symbol.dispose]();\n }\n}\n"]}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import { Id64Arg } from "@itwin/core-bentley";
|
|
1
|
+
import { Id64Arg, Id64Set } from "@itwin/core-bentley";
|
|
2
2
|
import { Event } from "@itwin/presentation-shared";
|
|
3
|
+
/**
|
|
4
|
+
* A collection of geometric element, model and subcategory ids that can be added to
|
|
5
|
+
* a [[SelectionSet]] or [[HiliteSet]].
|
|
6
|
+
*
|
|
7
|
+
* **Warning:** This type was added to `@itwin/core-frontend` in 5.0.
|
|
8
|
+
*
|
|
9
|
+
* @see https://www.itwinjs.org/reference/core-frontend/selectionset/selectableids/
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export interface CoreSelectableIds {
|
|
13
|
+
elements?: Id64Arg;
|
|
14
|
+
models?: Id64Arg;
|
|
15
|
+
subcategories?: Id64Arg;
|
|
16
|
+
}
|
|
3
17
|
/**
|
|
4
18
|
* Identifies the type of changes made to the `CoreIModelSelectionSet` to produce a `CoreSelectionSetEvent`.
|
|
5
19
|
* @see https://www.itwinjs.org/reference/core-frontend/selectionset/selectionseteventtype/
|
|
@@ -31,8 +45,20 @@ export interface CoreSelectionSetEventUnsafe {
|
|
|
31
45
|
type: number;
|
|
32
46
|
/** The element Ids added to the set. */
|
|
33
47
|
added?: Id64Arg;
|
|
48
|
+
/**
|
|
49
|
+
* A collection of geometric element, model and subcategory ids that have been removed from selection set.
|
|
50
|
+
*
|
|
51
|
+
* **Warning:** This property was added to `@itwin/core-frontend` in 5.0.
|
|
52
|
+
*/
|
|
53
|
+
additions?: CoreSelectableIds;
|
|
34
54
|
/** The element Ids removed from the set. */
|
|
35
55
|
removed?: Id64Arg;
|
|
56
|
+
/**
|
|
57
|
+
* A collection of geometric element, model and subcategory ids that have been added to selection set.
|
|
58
|
+
*
|
|
59
|
+
* **Warning:** This property was added to `@itwin/core-frontend` in 5.0.
|
|
60
|
+
*/
|
|
61
|
+
removals?: CoreSelectableIds;
|
|
36
62
|
/** The affected `CoreIModelSelectionSet`. */
|
|
37
63
|
set: CoreIModelSelectionSet;
|
|
38
64
|
}
|
|
@@ -41,18 +67,40 @@ export interface CoreSelectionSetEventUnsafe {
|
|
|
41
67
|
* @see https://www.itwinjs.org/reference/core-frontend/selectionset/
|
|
42
68
|
* @public
|
|
43
69
|
*/
|
|
44
|
-
export
|
|
70
|
+
export type CoreIModelSelectionSet = {
|
|
45
71
|
/** Event called whenever elements are added or removed from this SelectionSet. */
|
|
46
72
|
onChanged: Event<(ev: CoreSelectionSetEventUnsafe) => void>;
|
|
47
73
|
/** The IDs of the selected elements. */
|
|
48
74
|
readonly elements: Set<string>;
|
|
49
75
|
/** Clear current selection set. */
|
|
50
76
|
emptyAll(): void;
|
|
77
|
+
} & ({
|
|
51
78
|
/** Add one or more Ids to the current selection set. */
|
|
52
79
|
add(elem: Id64Arg): boolean;
|
|
53
80
|
/** Remove one or more Ids from the current selection set. */
|
|
54
81
|
remove(elem: Id64Arg): boolean;
|
|
55
|
-
}
|
|
82
|
+
} | {
|
|
83
|
+
/**
|
|
84
|
+
* Get the active selection as a collection of geometric element, model and subcategory ids.
|
|
85
|
+
*/
|
|
86
|
+
readonly active: {
|
|
87
|
+
[P in keyof CoreSelectableIds]-?: Id64Set;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Adds a collection of geometric element, model and subcategory ids to this selection set.
|
|
91
|
+
*
|
|
92
|
+
* The overload was added only in 5.0 `@itwin/core-frontend`. The `active` property can be used
|
|
93
|
+
* to check if this `overload` is available.
|
|
94
|
+
*/
|
|
95
|
+
add: (ids: Id64Arg | CoreSelectableIds) => boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Adds a collection of geometric element, model and subcategory ids to this selection set.
|
|
98
|
+
*
|
|
99
|
+
* The overload was added only in 5.0 `@itwin/core-frontend`. The `active` property can be used
|
|
100
|
+
* to check if this `overload` is available.
|
|
101
|
+
*/
|
|
102
|
+
remove: (ids: Id64Arg | CoreSelectableIds) => boolean;
|
|
103
|
+
});
|
|
56
104
|
/**
|
|
57
105
|
* A set if ID's optimized for performance-critical code which represents large sets of ID's as pairs of 32-bit integers.
|
|
58
106
|
* @see https://www.itwinjs.org/reference/core-bentley/ids/id64/id64.uint32set/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModel.d.ts","sourceRoot":"","sources":["../../../../src/unified-selection/types/IModel.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"IModel.d.ts","sourceRoot":"","sources":["../../../../src/unified-selection/types/IModel.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAC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AAC;IAEnD;;;;;OAKG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,iBAAiB,KAAK,OAAO,CAAC;CACvD,CACJ,CAAC;AAEF;;;;GAIG;AACH,UAAU,SAAS;IACjB,wCAAwC;IACxC,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,6CAA6C;IAC7C,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,gHAAgH;IAChH,wBAAwB,EAAE,OAAO,CAAC;IAClC,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,wCAAwC;IACxC,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC;IAClC,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,gDAAgD;IAChD,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModel.js","sourceRoot":"","sources":["../../../../src/unified-selection/types/IModel.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;
|
|
1
|
+
{"version":3,"file":"IModel.js","sourceRoot":"","sources":["../../../../src/unified-selection/types/IModel.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAoBhG;;;;GAIG;AACH,IAAY,yBASX;AATD,WAAY,yBAAyB;IACnC,2CAA2C;IAC3C,uEAAG,CAAA;IACH,+CAA+C;IAC/C,6EAAM,CAAA;IACN,6EAA6E;IAC7E,+EAAO,CAAA;IACP,yDAAyD;IACzD,2EAAK,CAAA;AACP,CAAC,EATW,yBAAyB,yCAAzB,yBAAyB,QASpC","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 { Id64Arg, Id64Set } from \"@itwin/core-bentley\";\nimport { Event } from \"@itwin/presentation-shared\";\n\n/**\n * A collection of geometric element, model and subcategory ids that can be added to\n * a [[SelectionSet]] or [[HiliteSet]].\n *\n * **Warning:** This type was added to `@itwin/core-frontend` in 5.0.\n *\n * @see https://www.itwinjs.org/reference/core-frontend/selectionset/selectableids/\n * @public\n */\nexport interface CoreSelectableIds {\n elements?: Id64Arg;\n models?: Id64Arg;\n subcategories?: Id64Arg;\n}\n\n/**\n * Identifies the type of changes made to the `CoreIModelSelectionSet` to produce a `CoreSelectionSetEvent`.\n * @see https://www.itwinjs.org/reference/core-frontend/selectionset/selectionseteventtype/\n * @internal\n */\nexport enum CoreSelectionSetEventType {\n /** Elements have been added to the set. */\n Add,\n /** Elements have been removed from the set. */\n Remove,\n /** Some elements have been added to the set and others have been removed. */\n Replace,\n /** All elements are about to be removed from the set. */\n Clear,\n}\n\n/**\n * Payload sent to `CoreIModelSelectionSet.onChanged` event listeners to describe how the contents of the set have changed.\n * @see https://www.itwinjs.org/reference/core-frontend/selectionset/selectionsetevent/\n * @public\n */\nexport interface CoreSelectionSetEventUnsafe {\n /**\n * The type of operation that produced this event.\n *\n * Actually, this should be `CoreSelectionSetEventType`, however we can't use it here because in TS two identical enums with\n * different names aren't equal, so [`SelectionSetEventType `](https://www.itwinjs.org/reference/core-frontend/selectionset/selectionseteventtype/)\n * doesn't map to `CoreSelectionSetEventType` as far as TS is concerned. Due to this reason, this interface is marked as `unsafe`.\n */\n type: number;\n /** The element Ids added to the set. */\n added?: Id64Arg;\n /**\n * A collection of geometric element, model and subcategory ids that have been removed from selection set.\n *\n * **Warning:** This property was added to `@itwin/core-frontend` in 5.0.\n */\n additions?: CoreSelectableIds;\n /** The element Ids removed from the set. */\n removed?: Id64Arg;\n /**\n * A collection of geometric element, model and subcategory ids that have been added to selection set.\n *\n * **Warning:** This property was added to `@itwin/core-frontend` in 5.0.\n */\n removals?: CoreSelectableIds;\n /** The affected `CoreIModelSelectionSet`. */\n set: CoreIModelSelectionSet;\n}\n\n/**\n * A set of *currently selected* elements in an iModel.\n * @see https://www.itwinjs.org/reference/core-frontend/selectionset/\n * @public\n */\nexport type CoreIModelSelectionSet = {\n /** Event called whenever elements are added or removed from this SelectionSet. */\n onChanged: Event<(ev: CoreSelectionSetEventUnsafe) => void>;\n /** The IDs of the selected elements. */\n readonly elements: Set<string>;\n /** Clear current selection set. */\n emptyAll(): void;\n} & (\n | {\n /** Add one or more Ids to the current selection set. */\n add(elem: Id64Arg): boolean;\n /** Remove one or more Ids from the current selection set. */\n remove(elem: Id64Arg): boolean;\n }\n | {\n /**\n * Get the active selection as a collection of geometric element, model and subcategory ids.\n */\n readonly active: { [P in keyof CoreSelectableIds]-?: Id64Set };\n\n /**\n * Adds a collection of geometric element, model and subcategory ids to this selection set.\n *\n * The overload was added only in 5.0 `@itwin/core-frontend`. The `active` property can be used\n * to check if this `overload` is available.\n */\n add: (ids: Id64Arg | CoreSelectableIds) => boolean;\n\n /**\n * Adds a collection of geometric element, model and subcategory ids to this selection set.\n *\n * The overload was added only in 5.0 `@itwin/core-frontend`. The `active` property can be used\n * to check if this `overload` is available.\n */\n remove: (ids: Id64Arg | CoreSelectableIds) => boolean;\n }\n);\n\n/**\n * A set if ID's optimized for performance-critical code which represents large sets of ID's as pairs of 32-bit integers.\n * @see https://www.itwinjs.org/reference/core-bentley/ids/id64/id64.uint32set/\n * @public\n */\ninterface Uint32Set {\n /** Add any number of Ids to the set. */\n addIds(ids: Id64Arg): void;\n /** Remove any number of Ids from the set. */\n deleteIds(ids: Id64Arg): void;\n}\n\n/**\n * A set of *hilited* elements in an iModel, by element id.\n * @see https://www.itwinjs.org/reference/core-frontend/selectionset/hiliteset/\n * @public\n */\nexport interface CoreIModelHiliteSet {\n /** Control whether the hilited elements should be synchronized with the contents of `CoreIModelSelectionSet`.*/\n wantSyncWithSelectionSet: boolean;\n /** The set of hilited elements. */\n readonly elements: Uint32Set;\n /** The set of hilited subcategories. */\n readonly subcategories: Uint32Set;\n /** The set of hilited models. */\n readonly models: Uint32Set;\n /** Remove all elements from the hilited set. */\n clear(): void;\n}\n"]}
|
|
@@ -26,7 +26,17 @@ export interface CachingHiliteSetProvider {
|
|
|
26
26
|
/** iModel to get hilite set for */
|
|
27
27
|
imodelKey: string;
|
|
28
28
|
}): AsyncIterableIterator<HiliteSet>;
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Disposes the cache.
|
|
31
|
+
*
|
|
32
|
+
* Optional to avoid breaking the API. Will be made required when the deprecated
|
|
33
|
+
* `dispose` is removed.
|
|
34
|
+
*/
|
|
35
|
+
[Symbol.dispose]?: () => void;
|
|
36
|
+
/**
|
|
37
|
+
* Disposes the cache.
|
|
38
|
+
* @deprecated in 1.2. Use `[Symbol.dispose]` instead.
|
|
39
|
+
*/
|
|
30
40
|
dispose(): void;
|
|
31
41
|
}
|
|
32
42
|
/**
|
|
@@ -34,5 +44,7 @@ export interface CachingHiliteSetProvider {
|
|
|
34
44
|
* hilite set requests for the same iModel don't cost until selection in given selection storage changes.
|
|
35
45
|
* @public
|
|
36
46
|
*/
|
|
37
|
-
export declare function createCachingHiliteSetProvider(props: CachingHiliteSetProviderProps): CachingHiliteSetProvider
|
|
47
|
+
export declare function createCachingHiliteSetProvider(props: CachingHiliteSetProviderProps): CachingHiliteSetProvider & {
|
|
48
|
+
[Symbol.dispose]: () => void;
|
|
49
|
+
};
|
|
38
50
|
//# sourceMappingURL=CachingHiliteSetProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CachingHiliteSetProvider.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/CachingHiliteSetProvider.ts"],"names":[],"mappings":"AAOA,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,
|
|
1
|
+
{"version":3,"file":"CachingHiliteSetProvider.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/CachingHiliteSetProvider.ts"],"names":[],"mappings":"AAOA,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"}
|
|
@@ -41,11 +41,15 @@ class CachingHiliteSetProviderImpl {
|
|
|
41
41
|
}
|
|
42
42
|
return eachValueFrom(hiliteSet);
|
|
43
43
|
}
|
|
44
|
-
dispose() {
|
|
44
|
+
[Symbol.dispose]() {
|
|
45
45
|
this._removeListener();
|
|
46
46
|
this._hiliteSetProviders = new Map();
|
|
47
47
|
this._cache = new Map();
|
|
48
48
|
}
|
|
49
|
+
/* c8 ignore next 3 */
|
|
50
|
+
dispose() {
|
|
51
|
+
this[Symbol.dispose]();
|
|
52
|
+
}
|
|
49
53
|
getHiliteSetProvider(imodelKey, imodelAccess) {
|
|
50
54
|
let provider = this._hiliteSetProviders.get(imodelKey);
|
|
51
55
|
if (!provider) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CachingHiliteSetProvider.js","sourceRoot":"","sources":["../../../src/unified-selection/CachingHiliteSetProvider.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,IAAI,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,uBAAuB,EAAgC,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAAE,mCAAmC,EAAoB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"CachingHiliteSetProvider.js","sourceRoot":"","sources":["../../../src/unified-selection/CachingHiliteSetProvider.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,IAAI,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,uBAAuB,EAAgC,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAAE,mCAAmC,EAAoB,MAAM,uBAAuB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AAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,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,aAAa,CAAC,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,uBAAuB,CAAC,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 { 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"]}
|
|
@@ -46,8 +46,13 @@ export interface EnableUnifiedSelectionSyncWithIModelProps {
|
|
|
46
46
|
* will be created for the given iModel using the provided `imodelAccess`.
|
|
47
47
|
* If the consuming application already has a `CachingHiliteSetProvider` defined, it should be provided instead
|
|
48
48
|
* to reuse the cache and avoid creating new providers for each iModel.
|
|
49
|
+
*
|
|
50
|
+
* The type is defined in a way that makes it required for provider to have either the deprecated `dispose` or the
|
|
51
|
+
* new `Symbol.dispose` method.
|
|
49
52
|
*/
|
|
50
|
-
cachingHiliteSetProvider?: CachingHiliteSetProvider
|
|
53
|
+
cachingHiliteSetProvider?: CachingHiliteSetProvider | (Omit<CachingHiliteSetProvider, "dispose"> & {
|
|
54
|
+
[Symbol.dispose]: () => void;
|
|
55
|
+
});
|
|
51
56
|
}
|
|
52
57
|
/**
|
|
53
58
|
* Enables synchronization between iModel selection and unified selection.
|
|
@@ -69,14 +74,14 @@ export declare class IModelSelectionHandler {
|
|
|
69
74
|
private _activeScopeProvider;
|
|
70
75
|
private _isSuspended;
|
|
71
76
|
private _cancelOngoingChanges;
|
|
72
|
-
private
|
|
73
|
-
private
|
|
77
|
+
private _unregisterUnifiedSelectionListener;
|
|
78
|
+
private _unregisterIModelSelectionSetListener;
|
|
74
79
|
private _hasCustomCachingHiliteSetProvider;
|
|
75
80
|
constructor(props: EnableUnifiedSelectionSyncWithIModelProps);
|
|
76
|
-
dispose(): void;
|
|
77
|
-
/** Temporarily suspends tool selection synchronization until the returned
|
|
81
|
+
[Symbol.dispose](): void;
|
|
82
|
+
/** Temporarily suspends tool selection synchronization until the returned disposable object is disposed. */
|
|
78
83
|
suspendIModelToolSelectionSync(): {
|
|
79
|
-
dispose: () =>
|
|
84
|
+
[Symbol.dispose]: () => void;
|
|
80
85
|
};
|
|
81
86
|
private handleUnifiedSelectionChange;
|
|
82
87
|
private onUnifiedSelectionChanged;
|
|
@@ -86,6 +91,5 @@ export declare class IModelSelectionHandler {
|
|
|
86
91
|
private onIModelSelectionChanged;
|
|
87
92
|
private handleIModelSelectionChange;
|
|
88
93
|
private getSelectionSetChangeIds;
|
|
89
|
-
private idArgToIds;
|
|
90
94
|
}
|
|
91
95
|
//# 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/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