@itwin/unified-selection 0.4.3 → 0.4.5
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 +16 -0
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.d.ts +4 -3
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.d.ts.map +1 -1
- package/lib/cjs/unified-selection/CachingHiliteSetProvider.js.map +1 -1
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts +1 -1
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +1 -1
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.js +15 -10
- package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.js.map +1 -1
- package/lib/cjs/unified-selection/HiliteSetProvider.d.ts +2 -1
- package/lib/cjs/unified-selection/HiliteSetProvider.d.ts.map +1 -1
- package/lib/cjs/unified-selection/HiliteSetProvider.js.map +1 -1
- package/lib/cjs/unified-selection/SelectionScope.d.ts +7 -7
- package/lib/cjs/unified-selection/SelectionScope.d.ts.map +1 -1
- package/lib/cjs/unified-selection/SelectionScope.js +1 -4
- package/lib/cjs/unified-selection/SelectionScope.js.map +1 -1
- package/lib/cjs/unified-selection/SelectionStorage.d.ts +1 -0
- package/lib/cjs/unified-selection/SelectionStorage.d.ts.map +1 -1
- package/lib/cjs/unified-selection/SelectionStorage.js.map +1 -1
- package/lib/cjs/unified-selection/types/IModel.d.ts +4 -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 +4 -3
- package/lib/esm/unified-selection/CachingHiliteSetProvider.d.ts.map +1 -1
- package/lib/esm/unified-selection/CachingHiliteSetProvider.js.map +1 -1
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts +1 -1
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +1 -1
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.js +15 -10
- package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.js.map +1 -1
- package/lib/esm/unified-selection/HiliteSetProvider.d.ts +2 -1
- package/lib/esm/unified-selection/HiliteSetProvider.d.ts.map +1 -1
- package/lib/esm/unified-selection/HiliteSetProvider.js.map +1 -1
- package/lib/esm/unified-selection/SelectionScope.d.ts +7 -7
- package/lib/esm/unified-selection/SelectionScope.d.ts.map +1 -1
- package/lib/esm/unified-selection/SelectionScope.js +1 -4
- package/lib/esm/unified-selection/SelectionScope.js.map +1 -1
- package/lib/esm/unified-selection/SelectionStorage.d.ts +1 -0
- package/lib/esm/unified-selection/SelectionStorage.d.ts.map +1 -1
- package/lib/esm/unified-selection/SelectionStorage.js.map +1 -1
- package/lib/esm/unified-selection/types/IModel.d.ts +4 -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 +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionStorage.js","sourceRoot":"","sources":["../../../src/unified-selection/SelectionStorage.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,6CAAuD;AACvD,iEAAqJ;AAsFrJ;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAI,oBAAoB,EAAE,CAAC;AACpC,CAAC;AAFD,sCAEC;AAED,gBAAgB;AACH,QAAA,mCAAmC,GAAG,kCAAkC,CAAC;AAEtF,MAAM,oBAAoB;IAChB,QAAQ,GAAG,IAAI,GAAG,EAA0C,CAAC;IAC9D,oBAAoB,CAA2B;IAEtD;QACE,IAAI,CAAC,oBAAoB,GAAG,IAAI,+CAAwB,EAAE,CAAC;IAC7D,CAAC;IAEM,kBAAkB,CAAC,KAAoB;QAC5C,OAAO,IAAI,CAAC,YAA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C,EAAE,CAAC;gBACnC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,KAAa;QACxB,MAAM,YAAY,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACxD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACvC,IAAI,WAAW,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC;gBAClE,wBAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,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 { Selectable, Selectables } from \"./Selectable\";\nimport { SelectionChangeEvent, SelectionChangeEventImpl, StorageSelectionChangeEventArgs, StorageSelectionChangeType } from \"./SelectionChangeEvent\";\n\ntype IModelKeyProp =\n | {\n /** Key of the iModel to get selection levels for. */\n imodelKey: string;\n }\n | {\n /**\n * Key of the iModel to get selection levels for.\n * @deprecated in 0.2. Use `imodelKey` instead.\n */\n iModelKey: string;\n };\n\n/**\n * Defines return value of `createStorage`.\n *\n * @beta 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 */\nexport interface SelectionStorage {\n /** An event that is raised when selection changes. */\n selectionChangeEvent: SelectionChangeEvent;\n\n /** Get the selection levels currently stored for the specified iModel. */\n getSelectionLevels(props: IModelKeyProp): number[];\n\n /** Get the selection stored in the storage. */\n getSelection(\n props: IModelKeyProp & {\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): Selectables;\n\n /** Add keys to the selection. */\n addToSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to add to selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Remove keys from current selection. */\n removeFromSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to remove from selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Replace current selection. */\n replaceSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to add to selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Clear current selection. */\n clearSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Clear storage for an iModel. This function should be called when iModel is closed. */\n clearStorage(props: IModelKeyProp): void;\n}\n\n/**\n * Creates a selection storage which stores and allows managing application-level selection.\n *\n * **Note:** `clearSelection` should be called upon iModel close to free-up memory:\n * ```ts\n * import { IModelConnection } from \"@itwin/core-frontend\";\n * IModelConnection.onClose.addListener((imodel) => {\n * storage.clearStorage(imodel.key);\n * });\n * ```\n *\n * @beta\n */\nexport function createStorage(): SelectionStorage {\n return new SelectionStorageImpl();\n}\n\n/** @internal */\nexport const IMODEL_CLOSE_SELECTION_CLEAR_SOURCE = \"Unified selection storage: clear\";\n\nclass SelectionStorageImpl implements SelectionStorage {\n private _storage = new Map<string, MultiLevelSelectablesContainer>();\n public selectionChangeEvent: SelectionChangeEventImpl;\n\n constructor() {\n this.selectionChangeEvent = new SelectionChangeEventImpl();\n }\n\n public getSelectionLevels(props: IModelKeyProp): number[] {\n return this.getContainer(getIModelKey(props)).getSelectionLevels();\n }\n\n public getSelection(props: IModelKeyProp & { level?: number }): Selectables {\n return this.getContainer(getIModelKey(props)).getSelection(props.level ?? 0);\n }\n\n public addToSelection(props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"add\" });\n }\n\n public removeFromSelection(props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"remove\" });\n }\n\n public replaceSelection(props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"replace\" });\n }\n\n public clearSelection(props: IModelKeyProp & { source: string; level?: number }): void {\n this.handleChange({ ...props, changeType: \"clear\", selectables: [] });\n }\n\n public clearStorage(props: IModelKeyProp): void {\n const imodelKey = getIModelKey(props);\n this.clearSelection({ source: IMODEL_CLOSE_SELECTION_CLEAR_SOURCE, imodelKey });\n this._storage.delete(imodelKey);\n }\n\n private getContainer(imodelKey: string): MultiLevelSelectablesContainer {\n let selectionContainer = this._storage.get(imodelKey);\n if (!selectionContainer) {\n selectionContainer = new MultiLevelSelectablesContainer();\n this._storage.set(imodelKey, selectionContainer);\n }\n return selectionContainer;\n }\n\n private handleChange(props: IModelKeyProp & { source: string; level?: number; changeType: StorageSelectionChangeType; selectables: Selectable[] }) {\n const { source, level: inLevel, changeType, selectables: change } = props;\n const imodelKey = getIModelKey(props);\n const container = this.getContainer(imodelKey);\n const level = inLevel ?? 0;\n const selectables = container.getSelection(level);\n const selected = Selectables.create(change);\n switch (changeType) {\n case \"add\":\n if (!Selectables.add(selectables, change)) {\n return;\n }\n break;\n case \"remove\":\n if (!Selectables.remove(selectables, change)) {\n return;\n }\n break;\n case \"replace\":\n if (Selectables.size(selectables) === Selectables.size(selected) && Selectables.hasAll(selectables, change)) {\n return;\n }\n Selectables.clear(selectables);\n Selectables.add(selectables, change);\n break;\n case \"clear\":\n if (!Selectables.clear(selectables)) {\n return;\n }\n break;\n }\n container.clear(level + 1);\n const event: StorageSelectionChangeEventArgs = {\n source,\n level,\n imodelKey,\n iModelKey: imodelKey,\n changeType,\n selectables: selected,\n timestamp: new Date(),\n };\n this.selectionChangeEvent.raiseEvent(event, this);\n }\n}\n\nfunction getIModelKey(props: IModelKeyProp): string {\n // eslint-disable-next-line deprecation/deprecation\n return \"imodelKey\" in props ? props.imodelKey : props.iModelKey;\n}\n\nclass MultiLevelSelectablesContainer {\n private readonly _selectablesContainers: Map<number, Selectables>;\n\n constructor() {\n this._selectablesContainers = new Map<number, Selectables>();\n }\n\n public getSelection(level: number): Selectables {\n let selectables = this._selectablesContainers.get(level);\n if (!selectables) {\n selectables = Selectables.create([]);\n this._selectablesContainers.set(level, selectables);\n }\n return selectables;\n }\n\n public getSelectionLevels(): number[] {\n const levels = new Array<number>();\n for (const entry of this._selectablesContainers.entries()) {\n if (!Selectables.isEmpty(entry[1])) {\n levels.push(entry[0]);\n }\n }\n return levels.sort();\n }\n\n public clear(level: number) {\n const storedLevels = this._selectablesContainers.keys();\n for (const storedLevel of storedLevels) {\n if (storedLevel >= level) {\n const selectables = this._selectablesContainers.get(storedLevel)!;\n Selectables.clear(selectables);\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SelectionStorage.js","sourceRoot":"","sources":["../../../src/unified-selection/SelectionStorage.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,6CAAuD;AACvD,iEAAqJ;AAuFrJ;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAI,oBAAoB,EAAE,CAAC;AACpC,CAAC;AAFD,sCAEC;AAED,gBAAgB;AACH,QAAA,mCAAmC,GAAG,kCAAkC,CAAC;AAEtF,MAAM,oBAAoB;IAChB,QAAQ,GAAG,IAAI,GAAG,EAA0C,CAAC;IAC9D,oBAAoB,CAA2B;IAEtD;QACE,IAAI,CAAC,oBAAoB,GAAG,IAAI,+CAAwB,EAAE,CAAC;IAC7D,CAAC;IAEM,kBAAkB,CAAC,KAAoB;QAC5C,OAAO,IAAI,C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AAC,CAAC,EAAE,CAAC;gBACnC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,KAAa;QACxB,MAAM,YAAY,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACxD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACvC,IAAI,WAAW,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC;gBAClE,wBAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,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 { Selectable, Selectables } from \"./Selectable\";\nimport { SelectionChangeEvent, SelectionChangeEventImpl, StorageSelectionChangeEventArgs, StorageSelectionChangeType } from \"./SelectionChangeEvent\";\n\n/** @beta */\ntype IModelKeyProp =\n | {\n /** Key of the iModel to get selection levels for. */\n imodelKey: string;\n }\n | {\n /**\n * Key of the iModel to get selection levels for.\n * @deprecated in 0.2. Use `imodelKey` instead.\n */\n iModelKey: string;\n };\n\n/**\n * Defines return value of `createStorage`.\n *\n * @beta 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 */\nexport interface SelectionStorage {\n /** An event that is raised when selection changes. */\n selectionChangeEvent: SelectionChangeEvent;\n\n /** Get the selection levels currently stored for the specified iModel. */\n getSelectionLevels(props: IModelKeyProp): number[];\n\n /** Get the selection stored in the storage. */\n getSelection(\n props: IModelKeyProp & {\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): Selectables;\n\n /** Add keys to the selection. */\n addToSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to add to selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Remove keys from current selection. */\n removeFromSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to remove from selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Replace current selection. */\n replaceSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to add to selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Clear current selection. */\n clearSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Clear storage for an iModel. This function should be called when iModel is closed. */\n clearStorage(props: IModelKeyProp): void;\n}\n\n/**\n * Creates a selection storage which stores and allows managing application-level selection.\n *\n * **Note:** `clearSelection` should be called upon iModel close to free-up memory:\n * ```ts\n * import { IModelConnection } from \"@itwin/core-frontend\";\n * IModelConnection.onClose.addListener((imodel) => {\n * storage.clearStorage(imodel.key);\n * });\n * ```\n *\n * @beta\n */\nexport function createStorage(): SelectionStorage {\n return new SelectionStorageImpl();\n}\n\n/** @internal */\nexport const IMODEL_CLOSE_SELECTION_CLEAR_SOURCE = \"Unified selection storage: clear\";\n\nclass SelectionStorageImpl implements SelectionStorage {\n private _storage = new Map<string, MultiLevelSelectablesContainer>();\n public selectionChangeEvent: SelectionChangeEventImpl;\n\n constructor() {\n this.selectionChangeEvent = new SelectionChangeEventImpl();\n }\n\n public getSelectionLevels(props: IModelKeyProp): number[] {\n return this.getContainer(getIModelKey(props)).getSelectionLevels();\n }\n\n public getSelection(props: IModelKeyProp & { level?: number }): Selectables {\n return this.getContainer(getIModelKey(props)).getSelection(props.level ?? 0);\n }\n\n public addToSelection(props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"add\" });\n }\n\n public removeFromSelection(props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"remove\" });\n }\n\n public replaceSelection(props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"replace\" });\n }\n\n public clearSelection(props: IModelKeyProp & { source: string; level?: number }): void {\n this.handleChange({ ...props, changeType: \"clear\", selectables: [] });\n }\n\n public clearStorage(props: IModelKeyProp): void {\n const imodelKey = getIModelKey(props);\n this.clearSelection({ source: IMODEL_CLOSE_SELECTION_CLEAR_SOURCE, imodelKey });\n this._storage.delete(imodelKey);\n }\n\n private getContainer(imodelKey: string): MultiLevelSelectablesContainer {\n let selectionContainer = this._storage.get(imodelKey);\n if (!selectionContainer) {\n selectionContainer = new MultiLevelSelectablesContainer();\n this._storage.set(imodelKey, selectionContainer);\n }\n return selectionContainer;\n }\n\n private handleChange(props: IModelKeyProp & { source: string; level?: number; changeType: StorageSelectionChangeType; selectables: Selectable[] }) {\n const { source, level: inLevel, changeType, selectables: change } = props;\n const imodelKey = getIModelKey(props);\n const container = this.getContainer(imodelKey);\n const level = inLevel ?? 0;\n const selectables = container.getSelection(level);\n const selected = Selectables.create(change);\n switch (changeType) {\n case \"add\":\n if (!Selectables.add(selectables, change)) {\n return;\n }\n break;\n case \"remove\":\n if (!Selectables.remove(selectables, change)) {\n return;\n }\n break;\n case \"replace\":\n if (Selectables.size(selectables) === Selectables.size(selected) && Selectables.hasAll(selectables, change)) {\n return;\n }\n Selectables.clear(selectables);\n Selectables.add(selectables, change);\n break;\n case \"clear\":\n if (!Selectables.clear(selectables)) {\n return;\n }\n break;\n }\n container.clear(level + 1);\n const event: StorageSelectionChangeEventArgs = {\n source,\n level,\n imodelKey,\n iModelKey: imodelKey,\n changeType,\n selectables: selected,\n timestamp: new Date(),\n };\n this.selectionChangeEvent.raiseEvent(event, this);\n }\n}\n\nfunction getIModelKey(props: IModelKeyProp): string {\n // eslint-disable-next-line deprecation/deprecation\n return \"imodelKey\" in props ? props.imodelKey : props.iModelKey;\n}\n\nclass MultiLevelSelectablesContainer {\n private readonly _selectablesContainers: Map<number, Selectables>;\n\n constructor() {\n this._selectablesContainers = new Map<number, Selectables>();\n }\n\n public getSelection(level: number): Selectables {\n let selectables = this._selectablesContainers.get(level);\n if (!selectables) {\n selectables = Selectables.create([]);\n this._selectablesContainers.set(level, selectables);\n }\n return selectables;\n }\n\n public getSelectionLevels(): number[] {\n const levels = new Array<number>();\n for (const entry of this._selectablesContainers.entries()) {\n if (!Selectables.isEmpty(entry[1])) {\n levels.push(entry[0]);\n }\n }\n return levels.sort();\n }\n\n public clear(level: number) {\n const storedLevels = this._selectablesContainers.keys();\n for (const storedLevel of storedLevels) {\n if (storedLevel >= level) {\n const selectables = this._selectablesContainers.get(storedLevel)!;\n Selectables.clear(selectables);\n }\n }\n }\n}\n"]}
|
|
@@ -18,7 +18,7 @@ export declare enum CoreSelectionSetEventType {
|
|
|
18
18
|
/**
|
|
19
19
|
* Payload sent to `CoreIModelSelectionSet.onChanged` event listeners to describe how the contents of the set have changed.
|
|
20
20
|
* @see https://www.itwinjs.org/reference/core-frontend/selectionset/selectionsetevent/
|
|
21
|
-
* @
|
|
21
|
+
* @beta
|
|
22
22
|
*/
|
|
23
23
|
export interface CoreSelectionSetEventUnsafe {
|
|
24
24
|
/**
|
|
@@ -39,7 +39,7 @@ export interface CoreSelectionSetEventUnsafe {
|
|
|
39
39
|
/**
|
|
40
40
|
* A set of *currently selected* elements in an iModel.
|
|
41
41
|
* @see https://www.itwinjs.org/reference/core-frontend/selectionset/
|
|
42
|
-
* @
|
|
42
|
+
* @beta
|
|
43
43
|
*/
|
|
44
44
|
export interface CoreIModelSelectionSet {
|
|
45
45
|
/** Event called whenever elements are added or removed from this SelectionSet. */
|
|
@@ -56,6 +56,7 @@ export interface CoreIModelSelectionSet {
|
|
|
56
56
|
/**
|
|
57
57
|
* A set if ID's optimized for performance-critical code which represents large sets of ID's as pairs of 32-bit integers.
|
|
58
58
|
* @see https://www.itwinjs.org/reference/core-bentley/ids/id64/id64.uint32set/
|
|
59
|
+
* @beta
|
|
59
60
|
*/
|
|
60
61
|
interface Uint32Set {
|
|
61
62
|
/** Add any number of Ids to the set. */
|
|
@@ -66,7 +67,7 @@ interface Uint32Set {
|
|
|
66
67
|
/**
|
|
67
68
|
* A set of *hilited* elements in an iModel, by element id.
|
|
68
69
|
* @see https://www.itwinjs.org/reference/core-frontend/selectionset/hiliteset/
|
|
69
|
-
* @
|
|
70
|
+
* @beta
|
|
70
71
|
*/
|
|
71
72
|
export interface CoreIModelHiliteSet {
|
|
72
73
|
/** Control whether the hilited elements should be synchronized with the contents of `CoreIModelSelectionSet`.*/
|
|
@@ -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;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD;;;;GAIG;AACH,oBAAY,yBAAyB;IACnC,2CAA2C;IAC3C,GAAG,IAAA;IACH,+CAA+C;IAC/C,MAAM,IAAA;IACN,6EAA6E;IAC7E,OAAO,IAAA;IACP,yDAAyD;IACzD,KAAK,IAAA;CACN;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;;;;;OAMG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6CAA6C;IAC7C,GAAG,EAAE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AAC,MAAM,CAAC,CAAC;IAC/B,mCAAmC;IACnC,QAAQ,IAAI,IAAI,CAAC;IACjB,wDAAwD;IACxD,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IAC5B,6DAA6D;IAC7D,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;CAChC;AAED;;;;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;;;AAKhG;;;;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 } from \"@itwin/core-bentley\";\nimport { Event } from \"@itwin/presentation-shared\";\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 * @
|
|
1
|
+
{"version":3,"file":"IModel.js","sourceRoot":"","sources":["../../../../src/unified-selection/types/IModel.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAKhG;;;;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 } from \"@itwin/core-bentley\";\nimport { Event } from \"@itwin/presentation-shared\";\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 * @beta\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 /** The element Ids removed from the set. */\n removed?: Id64Arg;\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 * @beta\n */\nexport interface 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 /** 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 * 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 * @beta\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 * @beta\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"]}
|
|
@@ -3,17 +3,18 @@ import { HiliteSet } from "./HiliteSetProvider";
|
|
|
3
3
|
import { SelectionStorage } from "./SelectionStorage";
|
|
4
4
|
/**
|
|
5
5
|
* Props for creating a `CachingHiliteSetProvider` instance.
|
|
6
|
-
* @
|
|
6
|
+
* @beta
|
|
7
7
|
*/
|
|
8
8
|
export interface CachingHiliteSetProviderProps {
|
|
9
|
+
/** Selection storage to use for retrieving the hilite set. */
|
|
9
10
|
selectionStorage: SelectionStorage;
|
|
11
|
+
/** A callback that should return iModel access by iModel key. */
|
|
10
12
|
imodelProvider: (imodelKey: string) => ECClassHierarchyInspector & ECSqlQueryExecutor;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* Defines return value of `createCachingHiliteSetProvider`.
|
|
14
16
|
*
|
|
15
|
-
* @beta
|
|
16
|
-
* consumers, may be supplemented with required attributes any time.
|
|
17
|
+
* @beta
|
|
17
18
|
*/
|
|
18
19
|
export interface CachingHiliteSetProvider {
|
|
19
20
|
/** Get the current hilite set iterator for the specified imodel */
|
|
@@ -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,qBAAqB,CAAC;AAE5F,OAAO,EAAuC,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3F;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,cAAc,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,yBAAyB,GAAG,kBAAkB,CAAC;CACvF;AAED
|
|
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,qBAAqB,CAAC;AAE5F,OAAO,EAAuC,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3F;;;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;;;;GAIG;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,0BAA0B;IAC1B,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,6BAA6B,GAAG,wBAAwB,CAE7G"}
|
|
@@ -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,qBAAqB,CAAC;AAE5F,OAAO,EAAE,mCAAmC,EAAoB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"CachingHiliteSetProvider.js","sourceRoot":"","sources":["../../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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,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,OAAO;QACZ,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;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\";\nimport { StorageSelectionChangeEventArgs } from \"./SelectionChangeEvent\";\nimport { IMODEL_CLOSE_SELECTION_CLEAR_SOURCE, SelectionStorage } from \"./SelectionStorage\";\n\n/**\n * Props for creating a `CachingHiliteSetProvider` instance.\n * @beta\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 * @beta\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 /** Disposes the cache. */\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 * @beta\n */\nexport function createCachingHiliteSetProvider(props: CachingHiliteSetProviderProps): CachingHiliteSetProvider {\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 dispose(): void {\n this._removeListener();\n this._hiliteSetProviders = new Map();\n this._cache = new Map();\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"]}
|
|
@@ -5,7 +5,7 @@ import { SelectionStorage } from "./SelectionStorage";
|
|
|
5
5
|
import { CoreIModelHiliteSet, CoreIModelSelectionSet } from "./types/IModel";
|
|
6
6
|
/**
|
|
7
7
|
* Props for `enableUnifiedSelectionSyncWithIModel`.
|
|
8
|
-
* @
|
|
8
|
+
* @beta
|
|
9
9
|
*/
|
|
10
10
|
export interface EnableUnifiedSelectionSyncWithIModelProps {
|
|
11
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnableUnifiedSelectionSyncWithIModel.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/EnableUnifiedSelectionSyncWithIModel.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,wBAAwB,EAAkC,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AAO;IASd,wGAAwG;IACjG,8BAA8B;;;IAQrC,OAAO,CAAC,4BAA4B;IA6BpC,OAAO,CAAC,yBAAyB,CAU/B;IAEF,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,wBAAwB,CAa9B;YAEY,2BAA2B;
|
|
1
|
+
{"version":3,"file":"EnableUnifiedSelectionSyncWithIModel.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/EnableUnifiedSelectionSyncWithIModel.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,wBAAwB,EAAkC,MAAM,4BAA4B,CAAC;AAItG,OAAO,EAAoB,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAA0D,MAAM,gBAAgB,CAAC;AAErI;;;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;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;CACrD;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,CAA2B;IAC5D,OAAO,CAAC,oBAAoB,CAAuC;IAEnE,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,qBAAqB,CAAuB;IACpD,OAAO,CAAC,oCAAoC,CAAa;IACzD,OAAO,CAAC,0BAA0B,CAAa;IAC/C,OAAO,CAAC,kCAAkC,CAAU;gBAEjC,KAAK,EAAE,yCAAyC;IAuB5D,OAAO;IASd,wGAAwG;IACjG,8BAA8B;;;IAQrC,OAAO,CAAC,4BAA4B;IA6BpC,OAAO,CAAC,yBAAyB,CAU/B;IAEF,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,wBAAwB,CAa9B;YAEY,2BAA2B;IAoBzC,OAAO,CAAC,wBAAwB;IAYhC,OAAO,CAAC,UAAU;CASnB"}
|
|
@@ -163,17 +163,22 @@ export class IModelSelectionHandler {
|
|
|
163
163
|
await this.handleIModelSelectionChange(event.type, scopedSelection);
|
|
164
164
|
};
|
|
165
165
|
async handleIModelSelectionChange(type, iterator) {
|
|
166
|
-
|
|
167
|
-
for await (const selectable of iterator) {
|
|
168
|
-
this._selectionStorage.removeFromSelection({ imodelKey: this._imodelAccess.key, source: this._selectionSourceName, selectables: [selectable] });
|
|
169
|
-
}
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if (type === CoreSelectionSetEventType.Replace) {
|
|
173
|
-
this._selectionStorage.clearSelection({ imodelKey: this._imodelAccess.key, source: this._selectionSourceName });
|
|
174
|
-
}
|
|
166
|
+
const selectables = [];
|
|
175
167
|
for await (const selectable of iterator) {
|
|
176
|
-
|
|
168
|
+
selectables.push(selectable);
|
|
169
|
+
}
|
|
170
|
+
const props = {
|
|
171
|
+
imodelKey: this._imodelAccess.key,
|
|
172
|
+
source: this._selectionSourceName,
|
|
173
|
+
selectables,
|
|
174
|
+
};
|
|
175
|
+
switch (type) {
|
|
176
|
+
case CoreSelectionSetEventType.Add:
|
|
177
|
+
return this._selectionStorage.addToSelection(props);
|
|
178
|
+
case CoreSelectionSetEventType.Remove:
|
|
179
|
+
return this._selectionStorage.removeFromSelection(props);
|
|
180
|
+
case CoreSelectionSetEventType.Replace:
|
|
181
|
+
return this._selectionStorage.replaceSelection(props);
|
|
177
182
|
}
|
|
178
183
|
}
|
|
179
184
|
getSelectionSetChangeIds(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnableUnifiedSelectionSyncWithIModel.js","sourceRoot":"","sources":["../../../src/unified-selection/EnableUnifiedSelectionSyncWithIModel.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,MAAM,EAAW,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAA4B,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,EAAE,uBAAuB,EAAgC,MAAM,qBAAqB,CAAC;AAG5F,OAAO,EAAE,gBAAgB,EAAyB,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAA+C,yBAAyB,EAA+B,MAAM,gBAAgB,CAAC;AAqDrI;;;;GAIG;AACH,MAAM,UAAU,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,MAAM,OAAO,sBAAsB;IACzB,oBAAoB,GAAG,MAAM,CA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KAAK,CAAC,OAAO,CAAC,CAAC;gBACxB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAEO,UAAU,CAAC,GAAY;QAC7B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,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","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\";\nimport { createHiliteSetProvider, HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider\";\nimport { SelectableInstanceKey, Selectables } from \"./Selectable\";\nimport { StorageSelectionChangeEventArgs, StorageSelectionChangeType } from \"./SelectionChangeEvent\";\nimport { computeSelection, ComputeSelectionProps } from \"./SelectionScope\";\nimport { SelectionStorage } from \"./SelectionStorage\";\nimport { CoreIModelHiliteSet, CoreIModelSelectionSet, CoreSelectionSetEventType, CoreSelectionSetEventUnsafe } from \"./types/IModel\";\n\n/**\n * Props for `enableUnifiedSelectionSyncWithIModel`.\n * @internal Not exported through barrel, but used in public API as an argument. May be supplemented with optional attributes any time.\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 * @beta\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 if (type === CoreSelectionSetEventType.Remove) {\n for await (const selectable of iterator) {\n this._selectionStorage.removeFromSelection({ imodelKey: this._imodelAccess.key, source: this._selectionSourceName, selectables: [selectable] });\n }\n return;\n }\n\n if (type === CoreSelectionSetEventType.Replace) {\n this._selectionStorage.clearSelection({ imodelKey: this._imodelAccess.key, source: this._selectionSourceName });\n }\n\n for await (const selectable of iterator) {\n this._selectionStorage.addToSelection({ imodelKey: this._imodelAccess.key, source: this._selectionSourceName, selectables: [selectable] });\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;AAEhG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,MAAM,EAAW,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAA4B,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,EAAE,uBAAuB,EAAgC,MAAM,qBAAqB,CAAC;AAG5F,OAAO,EAAE,gBAAgB,EAAyB,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAA+C,yBAAyB,EAA+B,MAAM,gBAAgB,CAAC;AAqDrI;;;;GAIG;AACH,MAAM,UAAU,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,MAAM,OAAO,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,IAAI,OAAO,EAAQ,CAAC;IAC5C,oCAA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AC;IACb,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, Subject, takeUntil } from \"rxjs\";\nimport { assert, Id64Arg, using } from \"@itwin/core-bentley\";\nimport { ECClassHierarchyInspector, ECSqlQueryExecutor } from \"@itwin/presentation-shared\";\nimport { CachingHiliteSetProvider, createCachingHiliteSetProvider } from \"./CachingHiliteSetProvider\";\nimport { createHiliteSetProvider, HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider\";\nimport { SelectableInstanceKey, Selectables } from \"./Selectable\";\nimport { StorageSelectionChangeEventArgs, StorageSelectionChangeType } from \"./SelectionChangeEvent\";\nimport { computeSelection, ComputeSelectionProps } from \"./SelectionScope\";\nimport { SelectionStorage } from \"./SelectionStorage\";\nimport { CoreIModelHiliteSet, CoreIModelSelectionSet, CoreSelectionSetEventType, CoreSelectionSetEventUnsafe } from \"./types/IModel\";\n\n/**\n * Props for `enableUnifiedSelectionSyncWithIModel`.\n * @beta\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 * @beta\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"]}
|
|
@@ -12,9 +12,10 @@ export interface HiliteSet {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Props for creating a `HiliteSetProvider` instance.
|
|
15
|
-
* @
|
|
15
|
+
* @beta
|
|
16
16
|
*/
|
|
17
17
|
export interface HiliteSetProviderProps {
|
|
18
|
+
/** An object that provides access to iModel's metadata and allows running ECSQL queries on it. */
|
|
18
19
|
imodelAccess: ECClassHierarchyInspector & ECSqlQueryExecutor;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HiliteSetProvider.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/HiliteSetProvider.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAA+B,kBAAkB,EAAiB,MAAM,4BAA4B,CAAC;AACvI,OAAO,EAAyB,WAAW,EAAE,MAAM,cAAc,CAAC;AAKlE;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,yBAAyB,GAAG,kBAAkB,CAAC;CAC9D;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,YAAY,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,WAAW,CAAA;KAAE,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;CACrF;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,sBAAsB,GAAG,iBAAiB,CAExF"}
|
|
1
|
+
{"version":3,"file":"HiliteSetProvider.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/HiliteSetProvider.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAA+B,kBAAkB,EAAiB,MAAM,4BAA4B,CAAC;AACvI,OAAO,EAAyB,WAAW,EAAE,MAAM,cAAc,CAAC;AAKlE;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,aAAa,EAAE,MAAM,EAA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AC","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, filter, forkJoin, from, map, merge, mergeMap, Observable, scan, shareReplay, Subject, toArray } from \"rxjs\";\nimport { eachValueFrom } from \"rxjs-for-await\";\nimport { ECClassHierarchyInspector, ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryRow } from \"@itwin/presentation-shared\";\nimport { SelectableInstanceKey, Selectables } from \"./Selectable\";\nimport { formIdBindings, genericExecuteQuery, releaseMainThreadOnItemsCount } from \"./Utils\";\n\nconst HILITE_SET_EMIT_FREQUENCY = 20;\n\n/**\n * A set of model, subcategory and element ids that can be used for specifying hilite.\n * @see https://www.itwinjs.org/reference/core-frontend/selectionset/hiliteset/\n * @beta\n */\nexport interface HiliteSet {\n models: string[];\n subCategories: string[];\n elements: string[];\n}\n\n/**\n * Props for creating a `HiliteSetProvider` instance.\n * @internal Not exported through barrel, but used in public API as an argument. May be supplemented with optional attributes any time.\n */\nexport interface HiliteSetProviderProps {\n imodelAccess: ECClassHierarchyInspector & ECSqlQueryExecutor;\n}\n\n/**\n * Defines return value of `createHiliteSetProvider`.\n *\n * @beta 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 */\nexport interface HiliteSetProvider {\n /** Get the current hilite set iterator for the specified imodel */\n getHiliteSet(props: { selectables: Selectables }): AsyncIterableIterator<HiliteSet>;\n}\n\n/**\n * Creates a hilite set provider that returns a `HiliteSet` for given selectables.\n * @beta\n */\nexport function createHiliteSetProvider(props: HiliteSetProviderProps): HiliteSetProvider {\n return new HiliteSetProviderImpl(props);\n}\n\nclass HiliteSetProviderImpl implements HiliteSetProvider {\n private _imodelAccess: ECClassHierarchyInspector & ECSqlQueryExecutor;\n // Map between a class name and its type\n private _classRelationCache: Map<string, InstanceIdType | Promise<InstanceIdType>>;\n\n constructor(props: HiliteSetProviderProps) {\n this._imodelAccess = props.imodelAccess;\n this._classRelationCache = new Map();\n }\n\n /**\n * Get hilite set iterator for supplied `Selectables`.\n */\n public getHiliteSet(props: { selectables: Selectables }): AsyncIterableIterator<HiliteSet> {\n const obs = this.getHiliteSetObservable(props);\n return eachValueFrom(obs);\n }\n\n /**\n * Returns a \"hot\" observable of hilite sets.\n */\n private getHiliteSetObservable({ selectables }: { selectables: Selectables }): Subject<HiliteSet> {\n const instancesByType = this.getInstancesByType(selectables);\n const observables: { [key in keyof HiliteSet]?: Observable<string> } = {\n models: this.getHilitedModels(instancesByType),\n subCategories: this.getHilitedSubCategories(instancesByType),\n elements: this.getHilitedElements(instancesByType),\n };\n\n let hiliteSet: HiliteSet = { models: [], subCategories: [], elements: [] };\n let lastEmitTime = performance.now();\n const subject = new Subject<HiliteSet>();\n const subscriptions = ([\"models\", \"subCategories\", \"elements\"] as const).map((key) =>\n observables[key]!.subscribe({\n next(val) {\n hiliteSet[key].push(val);\n if (performance.now() - lastEmitTime < HILITE_SET_EMIT_FREQUENCY) {\n return;\n }\n subject.next(hiliteSet);\n hiliteSet = { models: [], subCategories: [], elements: [] };\n lastEmitTime = performance.now();\n },\n complete() {\n observables[key] = undefined;\n if (observables.models || observables.subCategories || observables.elements) {\n return;\n }\n // Emit last batch before completing the observable.\n if (hiliteSet.elements.length || hiliteSet.models.length || hiliteSet.subCategories.length) {\n subject.next(hiliteSet);\n }\n subject.complete();\n },\n error(err) {\n subscriptions.forEach((x) => x.unsubscribe());\n subscriptions.length = 0;\n subject.error(err);\n },\n }),\n );\n\n return subject;\n }\n\n private async getType(key: SelectableInstanceKey): Promise<InstanceIdType> {\n const cachedType = this._classRelationCache.get(key.className.replace(\".\", \":\"));\n if (cachedType) {\n return cachedType;\n }\n\n const promise = this.getTypeImpl(key).then((res) => {\n // Update the cache with the result of the promise.\n this._classRelationCache.set(key.className, res);\n return res;\n });\n\n // Add the promise to cache to prevent `getTypeImpl` being called multiple times.\n this._classRelationCache.set(key.className, promise);\n return promise;\n }\n\n private async getTypeImpl(key: SelectableInstanceKey): Promise<InstanceIdType> {\n return (\n (await this.checkType(key.className, \"BisCore.Subject\", \"subject\")) ??\n (await this.checkType(key.className, \"BisCore.Model\", \"model\")) ??\n (await this.checkType(key.className, \"BisCore.Category\", \"category\")) ??\n (await this.checkType(key.className, \"BisCore.SubCategory\", \"subCategory\")) ??\n (await this.checkType(key.className, \"Functional.FunctionalElement\", \"functionalElement\")) ??\n (await this.checkType(key.className, \"BisCore.GroupInformationElement\", \"groupInformationElement\")) ??\n (await this.checkType(key.className, \"BisCore.GeometricElement\", \"geometricElement\")) ??\n (await this.checkType(key.className, \"BisCore.Element\", \"element\")) ??\n \"unknown\"\n );\n }\n\n private async checkType(keyClassName: string, checkClassName: string, type: InstanceIdType) {\n try {\n const res = this._imodelAccess.classDerivesFrom(keyClassName, checkClassName);\n const isOfType = typeof res === \"boolean\" ? res : await res;\n return isOfType ? type : undefined;\n } catch (e) {\n // we may be checking against a non-existing schema (e.g. Functional), in which case we should\n // return undefined instead of throwing an error\n if (e instanceof Error && e.message.match(/Schema \"[\\w\\d_]+\" not found/)) {\n return undefined;\n }\n throw e;\n }\n }\n\n private getInstancesByType(selectables: Selectables): InstancesByType {\n const keyTypeObs = merge(\n from(selectables.custom.values()).pipe(mergeMap((selectable) => selectable.loadInstanceKeys())),\n from(selectables.instanceKeys).pipe(mergeMap(([className, idSet]) => from(idSet).pipe(map((id) => ({ className, id }))))),\n ).pipe(\n releaseMainThreadOnItemsCount(500),\n // Get types for each instance key\n mergeMap((instanceKey) => from(this.getType(instanceKey)).pipe(map((instanceIdType) => ({ instanceId: instanceKey.id, instanceIdType })))),\n // Cache the results\n shareReplay(),\n );\n\n return Object.fromEntries(\n INSTANCE_TYPES.map((type) => [\n type,\n keyTypeObs.pipe(\n filter(({ instanceIdType }) => instanceIdType === type),\n map(({ instanceId }) => instanceId),\n unique(),\n ),\n ]),\n ) as InstancesByType;\n }\n\n private getHilitedModels(instancesByType: InstancesByType): Observable<string> {\n return forkJoin({\n modelKeys: instancesByType.model.pipe(toArray()),\n subjectKeys: instancesByType.subject.pipe(toArray()),\n }).pipe(\n mergeMap(({ modelKeys, subjectKeys }) => {\n if (!modelKeys.length && !subjectKeys.length) {\n return EMPTY;\n }\n\n const bindings: ECSqlBinding[] = [];\n const ctes = [\n `\n ChildSubjects(ECInstanceId, JsonProperties) AS (\n SELECT ECInstanceId, JsonProperties\n FROM BisCore.Subject\n WHERE ${formIdBindings(\"ECInstanceId\", subjectKeys, bindings)}\n UNION ALL\n SELECT r.ECInstanceId, r.JsonProperties\n FROM ChildSubjects s\n JOIN BisCore.Subject r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n Models(ECInstanceId) AS (\n SELECT s.ECInstanceId AS ECInstanceId\n FROM BisCore.Model s\n WHERE ${formIdBindings(\"ECInstanceId\", modelKeys, bindings)}\n )\n `,\n ];\n const ecsql = [\n `\n SELECT r.ECInstanceId AS ECInstanceId\n FROM ChildSubjects s\n JOIN BisCore.PhysicalPartition r ON r.Parent.Id = s.ECInstanceId OR json_extract(s.JsonProperties,'$.Subject.Model.TargetPartition') = printf('0x%x', r.ECInstanceId)\n `,\n `\n SELECT ECInstanceId FROM Models\n `,\n ].join(\" UNION \");\n return from(executeQuery(this._imodelAccess, { ctes, ecsql, bindings }));\n }),\n );\n }\n\n private getHilitedSubCategories(instancesByType: InstancesByType): Observable<string> {\n return forkJoin({\n subCategoryKeys: instancesByType.subCategory.pipe(toArray()),\n categoryKeys: instancesByType.category.pipe(toArray()),\n }).pipe(\n mergeMap(({ subCategoryKeys, categoryKeys }) => {\n if (!subCategoryKeys.length && !categoryKeys.length) {\n return EMPTY;\n }\n\n const bindings: ECSqlBinding[] = [];\n const ctes = [\n `\n CategorySubCategories(ECInstanceId) AS (\n SELECT r.ECInstanceId AS ECInstanceId\n FROM BisCore.Category s\n JOIN BisCore.SubCategory r ON r.Parent.Id = s.ECInstanceId\n WHERE ${formIdBindings(\"s.ECInstanceId\", categoryKeys, bindings)}\n )\n `,\n `\n SubCategories(ECInstanceId) AS (\n SELECT s.ECInstanceId AS ECInstanceId\n FROM BisCore.SubCategory s\n WHERE ${formIdBindings(\"s.ECInstanceId\", subCategoryKeys, bindings)}\n )\n `,\n ];\n const ecsql = [`SELECT ECInstanceId FROM CategorySubCategories`, `SELECT ECInstanceId FROM SubCategories`].join(\" UNION \");\n return from(executeQuery(this._imodelAccess, { ctes, ecsql, bindings }));\n }),\n );\n }\n\n private getHilitedElements(instancesByType: InstancesByType): Observable<string> {\n return forkJoin({\n groupInformationElementKeys: instancesByType.groupInformationElement.pipe(toArray()),\n geometricElementKeys: instancesByType.geometricElement.pipe(toArray()),\n functionalElements: instancesByType.functionalElement.pipe(toArray()),\n elementKeys: instancesByType.element.pipe(toArray()),\n }).pipe(\n mergeMap(({ groupInformationElementKeys, geometricElementKeys, functionalElements, elementKeys }) => {\n const hasFunctionalElements = !!functionalElements.length;\n if (!groupInformationElementKeys.length && !geometricElementKeys.length && !elementKeys.length && !hasFunctionalElements) {\n return EMPTY;\n }\n\n const bindings: ECSqlBinding[] = [];\n const ctes = [\n ...(hasFunctionalElements ? this.getHilitedFunctionalElementsQueryCTEs(functionalElements, bindings) : []),\n `\n GroupMembers(ECInstanceId, ECClassId) AS (\n SELECT TargetECInstanceId, TargetECClassId\n FROM BisCore.ElementGroupsMembers\n WHERE ${formIdBindings(\"SourceECInstanceId\", groupInformationElementKeys, bindings)}\n )\n `,\n `\n GroupGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM GroupMembers\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM GroupGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n ElementGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId\n FROM BisCore.Element\n WHERE ${formIdBindings(\"ECInstanceId\", elementKeys, bindings)}\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM ElementGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n GeometricElementGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId\n FROM BisCore.GeometricElement\n WHERE ${formIdBindings(\"ECInstanceId\", geometricElementKeys, bindings)}\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM GeometricElementGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n ];\n const ecsql = [\n ...(hasFunctionalElements ? [\"SELECT ECInstanceId FROM FunctionalElementChildGeometricElements WHERE ECClassId IS (BisCore.GeometricElement)\"] : []),\n \"SELECT ECInstanceId FROM GeometricElementGeometricElements WHERE ECClassId IS (BisCore.GeometricElement)\",\n \"SELECT ECInstanceId FROM GroupGeometricElements WHERE ECClassId IS (BisCore.GeometricElement)\",\n \"SELECT ECInstanceId FROM ElementGeometricElements WHERE ECClassId IS (BisCore.GeometricElement)\",\n ].join(\" UNION \");\n return from(executeQuery(this._imodelAccess, { ctes, ecsql, bindings }));\n }),\n );\n }\n\n private getHilitedFunctionalElementsQueryCTEs(functionalElements: string[], bindings: ECSqlBinding[]): string[] {\n return [\n `\n ChildFunctionalElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId\n FROM Functional.FunctionalElement\n WHERE ${formIdBindings(\"ECInstanceId\", functionalElements, bindings)}\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM ChildFunctionalElements s\n JOIN Functional.FunctionalElement r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n PhysicalElements(ECInstanceId, ECClassId) AS (\n SELECT r.SourceECInstanceId, r.SourceECClassId\n FROM ChildFunctionalElements s\n JOIN Functional.PhysicalElementFulfillsFunction r ON r.TargetECInstanceId = s.ECInstanceId\n )\n `,\n `\n DrawingGraphicElements(ECInstanceId, ECClassId) AS (\n SELECT r.SourceECInstanceId, r.SourceECClassId\n FROM ChildFunctionalElements s\n JOIN Functional.DrawingGraphicRepresentsFunctionalElement r ON r.TargetECInstanceId = s.ECInstanceId\n )\n `,\n `\n PhysicalElementGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM PhysicalElements\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM PhysicalElementGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n DrawingGraphicElementGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM DrawingGraphicElements\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM DrawingGraphicElementGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n FunctionalElementChildGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM PhysicalElementGeometricElements\n UNION\n SELECT ECInstanceId, ECClassId FROM DrawingGraphicElementGeometricElements\n )\n `,\n ];\n }\n}\n\nconst INSTANCE_TYPES = [\n \"subject\",\n \"model\",\n \"category\",\n \"subCategory\",\n \"functionalElement\",\n \"groupInformationElement\",\n \"geometricElement\",\n \"element\",\n \"unknown\",\n] as const;\n\ntype InstanceIdType = (typeof INSTANCE_TYPES)[number];\n\ntype InstancesByType = {\n [idType in InstanceIdType]: Observable<string>;\n};\n\nfunction unique<T>() {\n return function (obs: Observable<T>): Observable<T> {\n return obs.pipe(\n scan(\n (acc, val) => {\n if (acc.set.has(val)) {\n delete acc.val;\n return acc;\n }\n\n acc.set.add(val);\n acc.val = val;\n return acc;\n },\n { set: new Set<T>() } as { set: Set<T>; val?: T },\n ),\n map(({ val }) => val),\n filter((x): x is T => !!x),\n );\n };\n}\n\nasync function* executeQuery(queryExecutor: ECSqlQueryExecutor, query: ECSqlQueryDef): AsyncIterableIterator<string> {\n yield* genericExecuteQuery(queryExecutor, query, (row: ECSqlQueryR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S,MAAM;IACb,OAAO,UAAU,GAAkB;QACjC,OAAO,GAAG,CAAC,IAAI,CACb,IAAI,CACF,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACX,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrB,OAAO,GAAG,CAAC,GAAG,CAAC;gBACf,OAAO,GAAG,CAAC;YACb,CAAC;YAED,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;YACd,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAE,GAAG,EAAE,IAAI,GAAG,EAAK,EAA8B,CAClD,EACD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EACrB,MAAM,CAAC,CAAC,CAAC,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,YAAY,CAAC,aAAiC,EAAE,KAAoB;IAClF,KAAK,CAAC,CAAC,mBAAmB,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,GAAkB,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC7F,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 { EMPTY, filter, forkJoin, from, map, merge, mergeMap, Observable, scan, shareReplay, Subject, toArray } from \"rxjs\";\nimport { eachValueFrom } from \"rxjs-for-await\";\nimport { ECClassHierarchyInspector, ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryRow } from \"@itwin/presentation-shared\";\nimport { SelectableInstanceKey, Selectables } from \"./Selectable\";\nimport { formIdBindings, genericExecuteQuery, releaseMainThreadOnItemsCount } from \"./Utils\";\n\nconst HILITE_SET_EMIT_FREQUENCY = 20;\n\n/**\n * A set of model, subcategory and element ids that can be used for specifying hilite.\n * @see https://www.itwinjs.org/reference/core-frontend/selectionset/hiliteset/\n * @beta\n */\nexport interface HiliteSet {\n models: string[];\n subCategories: string[];\n elements: string[];\n}\n\n/**\n * Props for creating a `HiliteSetProvider` instance.\n * @beta\n */\nexport interface HiliteSetProviderProps {\n /** An object that provides access to iModel's metadata and allows running ECSQL queries on it. */\n imodelAccess: ECClassHierarchyInspector & ECSqlQueryExecutor;\n}\n\n/**\n * Defines return value of `createHiliteSetProvider`.\n *\n * @beta 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 */\nexport interface HiliteSetProvider {\n /** Get the current hilite set iterator for the specified imodel */\n getHiliteSet(props: { selectables: Selectables }): AsyncIterableIterator<HiliteSet>;\n}\n\n/**\n * Creates a hilite set provider that returns a `HiliteSet` for given selectables.\n * @beta\n */\nexport function createHiliteSetProvider(props: HiliteSetProviderProps): HiliteSetProvider {\n return new HiliteSetProviderImpl(props);\n}\n\nclass HiliteSetProviderImpl implements HiliteSetProvider {\n private _imodelAccess: ECClassHierarchyInspector & ECSqlQueryExecutor;\n // Map between a class name and its type\n private _classRelationCache: Map<string, InstanceIdType | Promise<InstanceIdType>>;\n\n constructor(props: HiliteSetProviderProps) {\n this._imodelAccess = props.imodelAccess;\n this._classRelationCache = new Map();\n }\n\n /**\n * Get hilite set iterator for supplied `Selectables`.\n */\n public getHiliteSet(props: { selectables: Selectables }): AsyncIterableIterator<HiliteSet> {\n const obs = this.getHiliteSetObservable(props);\n return eachValueFrom(obs);\n }\n\n /**\n * Returns a \"hot\" observable of hilite sets.\n */\n private getHiliteSetObservable({ selectables }: { selectables: Selectables }): Subject<HiliteSet> {\n const instancesByType = this.getInstancesByType(selectables);\n const observables: { [key in keyof HiliteSet]?: Observable<string> } = {\n models: this.getHilitedModels(instancesByType),\n subCategories: this.getHilitedSubCategories(instancesByType),\n elements: this.getHilitedElements(instancesByType),\n };\n\n let hiliteSet: HiliteSet = { models: [], subCategories: [], elements: [] };\n let lastEmitTime = performance.now();\n const subject = new Subject<HiliteSet>();\n const subscriptions = ([\"models\", \"subCategories\", \"elements\"] as const).map((key) =>\n observables[key]!.subscribe({\n next(val) {\n hiliteSet[key].push(val);\n if (performance.now() - lastEmitTime < HILITE_SET_EMIT_FREQUENCY) {\n return;\n }\n subject.next(hiliteSet);\n hiliteSet = { models: [], subCategories: [], elements: [] };\n lastEmitTime = performance.now();\n },\n complete() {\n observables[key] = undefined;\n if (observables.models || observables.subCategories || observables.elements) {\n return;\n }\n // Emit last batch before completing the observable.\n if (hiliteSet.elements.length || hiliteSet.models.length || hiliteSet.subCategories.length) {\n subject.next(hiliteSet);\n }\n subject.complete();\n },\n error(err) {\n subscriptions.forEach((x) => x.unsubscribe());\n subscriptions.length = 0;\n subject.error(err);\n },\n }),\n );\n\n return subject;\n }\n\n private async getType(key: SelectableInstanceKey): Promise<InstanceIdType> {\n const cachedType = this._classRelationCache.get(key.className.replace(\".\", \":\"));\n if (cachedType) {\n return cachedType;\n }\n\n const promise = this.getTypeImpl(key).then((res) => {\n // Update the cache with the result of the promise.\n this._classRelationCache.set(key.className, res);\n return res;\n });\n\n // Add the promise to cache to prevent `getTypeImpl` being called multiple times.\n this._classRelationCache.set(key.className, promise);\n return promise;\n }\n\n private async getTypeImpl(key: SelectableInstanceKey): Promise<InstanceIdType> {\n return (\n (await this.checkType(key.className, \"BisCore.Subject\", \"subject\")) ??\n (await this.checkType(key.className, \"BisCore.Model\", \"model\")) ??\n (await this.checkType(key.className, \"BisCore.Category\", \"category\")) ??\n (await this.checkType(key.className, \"BisCore.SubCategory\", \"subCategory\")) ??\n (await this.checkType(key.className, \"Functional.FunctionalElement\", \"functionalElement\")) ??\n (await this.checkType(key.className, \"BisCore.GroupInformationElement\", \"groupInformationElement\")) ??\n (await this.checkType(key.className, \"BisCore.GeometricElement\", \"geometricElement\")) ??\n (await this.checkType(key.className, \"BisCore.Element\", \"element\")) ??\n \"unknown\"\n );\n }\n\n private async checkType(keyClassName: string, checkClassName: string, type: InstanceIdType) {\n try {\n const res = this._imodelAccess.classDerivesFrom(keyClassName, checkClassName);\n const isOfType = typeof res === \"boolean\" ? res : await res;\n return isOfType ? type : undefined;\n } catch (e) {\n // we may be checking against a non-existing schema (e.g. Functional), in which case we should\n // return undefined instead of throwing an error\n if (e instanceof Error && e.message.match(/Schema \"[\\w\\d_]+\" not found/)) {\n return undefined;\n }\n throw e;\n }\n }\n\n private getInstancesByType(selectables: Selectables): InstancesByType {\n const keyTypeObs = merge(\n from(selectables.custom.values()).pipe(mergeMap((selectable) => selectable.loadInstanceKeys())),\n from(selectables.instanceKeys).pipe(mergeMap(([className, idSet]) => from(idSet).pipe(map((id) => ({ className, id }))))),\n ).pipe(\n releaseMainThreadOnItemsCount(500),\n // Get types for each instance key\n mergeMap((instanceKey) => from(this.getType(instanceKey)).pipe(map((instanceIdType) => ({ instanceId: instanceKey.id, instanceIdType })))),\n // Cache the results\n shareReplay(),\n );\n\n return Object.fromEntries(\n INSTANCE_TYPES.map((type) => [\n type,\n keyTypeObs.pipe(\n filter(({ instanceIdType }) => instanceIdType === type),\n map(({ instanceId }) => instanceId),\n unique(),\n ),\n ]),\n ) as InstancesByType;\n }\n\n private getHilitedModels(instancesByType: InstancesByType): Observable<string> {\n return forkJoin({\n modelKeys: instancesByType.model.pipe(toArray()),\n subjectKeys: instancesByType.subject.pipe(toArray()),\n }).pipe(\n mergeMap(({ modelKeys, subjectKeys }) => {\n if (!modelKeys.length && !subjectKeys.length) {\n return EMPTY;\n }\n\n const bindings: ECSqlBinding[] = [];\n const ctes = [\n `\n ChildSubjects(ECInstanceId, JsonProperties) AS (\n SELECT ECInstanceId, JsonProperties\n FROM BisCore.Subject\n WHERE ${formIdBindings(\"ECInstanceId\", subjectKeys, bindings)}\n UNION ALL\n SELECT r.ECInstanceId, r.JsonProperties\n FROM ChildSubjects s\n JOIN BisCore.Subject r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n Models(ECInstanceId) AS (\n SELECT s.ECInstanceId AS ECInstanceId\n FROM BisCore.Model s\n WHERE ${formIdBindings(\"ECInstanceId\", modelKeys, bindings)}\n )\n `,\n ];\n const ecsql = [\n `\n SELECT r.ECInstanceId AS ECInstanceId\n FROM ChildSubjects s\n JOIN BisCore.PhysicalPartition r ON r.Parent.Id = s.ECInstanceId OR json_extract(s.JsonProperties,'$.Subject.Model.TargetPartition') = printf('0x%x', r.ECInstanceId)\n `,\n `\n SELECT ECInstanceId FROM Models\n `,\n ].join(\" UNION \");\n return from(executeQuery(this._imodelAccess, { ctes, ecsql, bindings }));\n }),\n );\n }\n\n private getHilitedSubCategories(instancesByType: InstancesByType): Observable<string> {\n return forkJoin({\n subCategoryKeys: instancesByType.subCategory.pipe(toArray()),\n categoryKeys: instancesByType.category.pipe(toArray()),\n }).pipe(\n mergeMap(({ subCategoryKeys, categoryKeys }) => {\n if (!subCategoryKeys.length && !categoryKeys.length) {\n return EMPTY;\n }\n\n const bindings: ECSqlBinding[] = [];\n const ctes = [\n `\n CategorySubCategories(ECInstanceId) AS (\n SELECT r.ECInstanceId AS ECInstanceId\n FROM BisCore.Category s\n JOIN BisCore.SubCategory r ON r.Parent.Id = s.ECInstanceId\n WHERE ${formIdBindings(\"s.ECInstanceId\", categoryKeys, bindings)}\n )\n `,\n `\n SubCategories(ECInstanceId) AS (\n SELECT s.ECInstanceId AS ECInstanceId\n FROM BisCore.SubCategory s\n WHERE ${formIdBindings(\"s.ECInstanceId\", subCategoryKeys, bindings)}\n )\n `,\n ];\n const ecsql = [`SELECT ECInstanceId FROM CategorySubCategories`, `SELECT ECInstanceId FROM SubCategories`].join(\" UNION \");\n return from(executeQuery(this._imodelAccess, { ctes, ecsql, bindings }));\n }),\n );\n }\n\n private getHilitedElements(instancesByType: InstancesByType): Observable<string> {\n return forkJoin({\n groupInformationElementKeys: instancesByType.groupInformationElement.pipe(toArray()),\n geometricElementKeys: instancesByType.geometricElement.pipe(toArray()),\n functionalElements: instancesByType.functionalElement.pipe(toArray()),\n elementKeys: instancesByType.element.pipe(toArray()),\n }).pipe(\n mergeMap(({ groupInformationElementKeys, geometricElementKeys, functionalElements, elementKeys }) => {\n const hasFunctionalElements = !!functionalElements.length;\n if (!groupInformationElementKeys.length && !geometricElementKeys.length && !elementKeys.length && !hasFunctionalElements) {\n return EMPTY;\n }\n\n const bindings: ECSqlBinding[] = [];\n const ctes = [\n ...(hasFunctionalElements ? this.getHilitedFunctionalElementsQueryCTEs(functionalElements, bindings) : []),\n `\n GroupMembers(ECInstanceId, ECClassId) AS (\n SELECT TargetECInstanceId, TargetECClassId\n FROM BisCore.ElementGroupsMembers\n WHERE ${formIdBindings(\"SourceECInstanceId\", groupInformationElementKeys, bindings)}\n )\n `,\n `\n GroupGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM GroupMembers\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM GroupGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n ElementGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId\n FROM BisCore.Element\n WHERE ${formIdBindings(\"ECInstanceId\", elementKeys, bindings)}\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM ElementGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n GeometricElementGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId\n FROM BisCore.GeometricElement\n WHERE ${formIdBindings(\"ECInstanceId\", geometricElementKeys, bindings)}\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM GeometricElementGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n ];\n const ecsql = [\n ...(hasFunctionalElements ? [\"SELECT ECInstanceId FROM FunctionalElementChildGeometricElements WHERE ECClassId IS (BisCore.GeometricElement)\"] : []),\n \"SELECT ECInstanceId FROM GeometricElementGeometricElements WHERE ECClassId IS (BisCore.GeometricElement)\",\n \"SELECT ECInstanceId FROM GroupGeometricElements WHERE ECClassId IS (BisCore.GeometricElement)\",\n \"SELECT ECInstanceId FROM ElementGeometricElements WHERE ECClassId IS (BisCore.GeometricElement)\",\n ].join(\" UNION \");\n return from(executeQuery(this._imodelAccess, { ctes, ecsql, bindings }));\n }),\n );\n }\n\n private getHilitedFunctionalElementsQueryCTEs(functionalElements: string[], bindings: ECSqlBinding[]): string[] {\n return [\n `\n ChildFunctionalElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId\n FROM Functional.FunctionalElement\n WHERE ${formIdBindings(\"ECInstanceId\", functionalElements, bindings)}\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM ChildFunctionalElements s\n JOIN Functional.FunctionalElement r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n PhysicalElements(ECInstanceId, ECClassId) AS (\n SELECT r.SourceECInstanceId, r.SourceECClassId\n FROM ChildFunctionalElements s\n JOIN Functional.PhysicalElementFulfillsFunction r ON r.TargetECInstanceId = s.ECInstanceId\n )\n `,\n `\n DrawingGraphicElements(ECInstanceId, ECClassId) AS (\n SELECT r.SourceECInstanceId, r.SourceECClassId\n FROM ChildFunctionalElements s\n JOIN Functional.DrawingGraphicRepresentsFunctionalElement r ON r.TargetECInstanceId = s.ECInstanceId\n )\n `,\n `\n PhysicalElementGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM PhysicalElements\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM PhysicalElementGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n DrawingGraphicElementGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM DrawingGraphicElements\n UNION ALL\n SELECT r.ECInstanceId, r.ECClassId\n FROM DrawingGraphicElementGeometricElements s\n JOIN BisCore.Element r ON r.Parent.Id = s.ECInstanceId\n )\n `,\n `\n FunctionalElementChildGeometricElements(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM PhysicalElementGeometricElements\n UNION\n SELECT ECInstanceId, ECClassId FROM DrawingGraphicElementGeometricElements\n )\n `,\n ];\n }\n}\n\nconst INSTANCE_TYPES = [\n \"subject\",\n \"model\",\n \"category\",\n \"subCategory\",\n \"functionalElement\",\n \"groupInformationElement\",\n \"geometricElement\",\n \"element\",\n \"unknown\",\n] as const;\n\ntype InstanceIdType = (typeof INSTANCE_TYPES)[number];\n\ntype InstancesByType = {\n [idType in InstanceIdType]: Observable<string>;\n};\n\nfunction unique<T>() {\n return function (obs: Observable<T>): Observable<T> {\n return obs.pipe(\n scan(\n (acc, val) => {\n if (acc.set.has(val)) {\n delete acc.val;\n return acc;\n }\n\n acc.set.add(val);\n acc.val = val;\n return acc;\n },\n { set: new Set<T>() } as { set: Set<T>; val?: T },\n ),\n map(({ val }) => val),\n filter((x): x is T => !!x),\n );\n };\n}\n\nasync function* executeQuery(queryExecutor: ECSqlQueryExecutor, query: ECSqlQueryDef): AsyncIterableIterator<string> {\n yield* genericExecuteQuery(queryExecutor, query, (row: ECSqlQueryRow) => row.ECInstanceId);\n}\n"]}
|
|
@@ -2,12 +2,12 @@ import { ECSqlQueryExecutor } from "@itwin/presentation-shared";
|
|
|
2
2
|
import { SelectableInstanceKey } from "./Selectable";
|
|
3
3
|
/**
|
|
4
4
|
* Available selection scopes.
|
|
5
|
-
* @
|
|
5
|
+
* @beta
|
|
6
6
|
*/
|
|
7
7
|
export type SelectionScope = "element" | "model" | "category" | "functional";
|
|
8
8
|
/**
|
|
9
9
|
* Props for computing element selection.
|
|
10
|
-
* @
|
|
10
|
+
* @beta
|
|
11
11
|
*/
|
|
12
12
|
export interface ElementSelectionScopeProps {
|
|
13
13
|
/** Identifies this as either "element" or "functional" selection scope */
|
|
@@ -24,20 +24,20 @@ export interface ElementSelectionScopeProps {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Props for `computeSelection`.
|
|
27
|
-
* @
|
|
27
|
+
* @beta
|
|
28
28
|
*/
|
|
29
29
|
export interface ComputeSelectionProps {
|
|
30
|
+
/** iModel query executor. */
|
|
30
31
|
queryExecutor: ECSqlQueryExecutor;
|
|
32
|
+
/** IDs of elements to compute selection for. */
|
|
31
33
|
elementIds: string[];
|
|
34
|
+
/** Selection scope to compute selection with. */
|
|
32
35
|
scope: ElementSelectionScopeProps | {
|
|
33
36
|
id: SelectionScope;
|
|
34
37
|
} | SelectionScope;
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
|
-
* Computes selection from given element
|
|
38
|
-
* @param queryExecutor iModel query executor.
|
|
39
|
-
* @param elementIds ID's of elements to compute selection for.
|
|
40
|
-
* @param scope Selection scope to compute selection with.
|
|
40
|
+
* Computes selection from given element IDs.
|
|
41
41
|
* @beta
|
|
42
42
|
*/
|
|
43
43
|
export declare function computeSelection(props: ComputeSelectionProps): AsyncIterableIterator<SelectableInstanceKey>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionScope.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/SelectionScope.ts"],"names":[],"mappings":"AAMA,OAAO,EAA+B,kBAAkB,EAAiB,MAAM,4BAA4B,CAAC;AAC5G,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGrD;;;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,aAAa,EAAE,kBAAkB,CAAC;IAClC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,EAAE,0BAA0B,GAAG;QAAE,EAAE,EAAE,cAAc,CAAA;KAAE,GAAG,cAAc,CAAC;CAC7E;AAED
|
|
1
|
+
{"version":3,"file":"SelectionScope.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/SelectionScope.ts"],"names":[],"mappings":"AAMA,OAAO,EAA+B,kBAAkB,EAAiB,MAAM,4BAA4B,CAAC;AAC5G,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGrD;;;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,MAAM,EAAE,CAAC;IACrB,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,CAwBlH"}
|
|
@@ -5,10 +5,7 @@
|
|
|
5
5
|
import { Id64 } from "@itwin/core-bentley";
|
|
6
6
|
import { formIdBindings, genericExecuteQuery } from "./Utils";
|
|
7
7
|
/**
|
|
8
|
-
* Computes selection from given element
|
|
9
|
-
* @param queryExecutor iModel query executor.
|
|
10
|
-
* @param elementIds ID's of elements to compute selection for.
|
|
11
|
-
* @param scope Selection scope to compute selection with.
|
|
8
|
+
* Computes selection from given element IDs.
|
|
12
9
|
* @beta
|
|
13
10
|
*/
|
|
14
11
|
export async function* computeSelection(props) {
|