UNPKG

@itwin/unified-selection

Version:

Package for managing unified selection in iTwin.js applications.

91 lines 3.82 kB
import { Event } from "@itwin/presentation-shared"; import { Selectable, Selectables } from "./Selectable.js"; import { StorageSelectionChangesListener } from "./SelectionChangeEvent.js"; /** @public */ type IModelKeyProp = { /** Key of the iModel. It's recommended to use `createIModelKey` function from `@itwin/presentation-core-interop` package to create the key for an iModel. */ imodelKey: string; } | { /** * Key of the iModel. It's recommended to use `createIModelKey` function from `@itwin/presentation-core-interop` package to create the key for an iModel. * @deprecated in 0.2. Use `imodelKey` instead. */ iModelKey: string; }; /** * Defines return value of `createStorage`. * * **Warning:** Used in public API as a return value. Not expected to be created / extended by package * consumers, may be supplemented with required attributes any time. * * @see `createStorage` * @public */ export interface SelectionStorage { /** An event that is raised when selection changes. */ selectionChangeEvent: Event<StorageSelectionChangesListener>; /** Get the selection levels currently stored for the specified iModel. */ getSelectionLevels(props: IModelKeyProp): number[]; /** Get the selection stored in the storage. */ getSelection(props: IModelKeyProp & { /** Level of the selection. Defaults to `0`. */ level?: number; }): Selectables; /** Add keys to the selection. */ addToSelection(props: IModelKeyProp & { /** Name of the selection source. Generally, this identifies the component that makes the selection change. */ source: string; /** The selectables to add to selection. */ selectables: Selectable[]; /** Level of the selection. Defaults to `0`. */ level?: number; }): void; /** Remove keys from current selection. */ removeFromSelection(props: IModelKeyProp & { /** Name of the selection source. Generally, this identifies the component that makes the selection change. */ source: string; /** The selectables to remove from selection. */ selectables: Selectable[]; /** Level of the selection. Defaults to `0`. */ level?: number; }): void; /** Replace current selection. */ replaceSelection(props: IModelKeyProp & { /** Name of the selection source. Generally, this identifies the component that makes the selection change. */ source: string; /** The selectables to add to selection. */ selectables: Selectable[]; /** Level of the selection. Defaults to `0`. */ level?: number; }): void; /** Clear current selection. */ clearSelection(props: IModelKeyProp & { /** Name of the selection source. Generally, this identifies the component that makes the selection change. */ source: string; /** Level of the selection. Defaults to `0`. */ level?: number; }): void; /** Clear storage for an iModel. This function should be called when iModel is closed. */ clearStorage(props: IModelKeyProp): void; } /** * Creates a selection storage which stores and allows managing application-level selection. * * **Note:** `clearSelection` should be called upon iModel close to free-up memory: * * ```ts * import { IModelConnection } from "@itwin/core-frontend"; * import { createIModelKey } from "@itwin/presentation-core-interop"; * * IModelConnection.onClose.addListener((imodel) => { * storage.clearStorage(createIModelKey(imodel)); * }); * ``` * * @public */ export declare function createStorage(): SelectionStorage; /** @internal */ export declare const IMODEL_CLOSE_SELECTION_CLEAR_SOURCE = "Unified selection storage: clear"; export {}; //# sourceMappingURL=SelectionStorage.d.ts.map