UNPKG

@itwin/unified-selection

Version:

Package for managing unified selection in iTwin.js applications.

147 lines 5.63 kB
import { Id64String } from "@itwin/core-bentley"; /** * ECInstance selectable * @public */ export interface SelectableInstanceKey { /** Full class name in format `SchemaName:ClassName` or `SchemaName.ClassName`. */ className: string; /** ECInstance ID */ id: string; } /** * A custom selectable, which has an identifier, knows how to loads its associated selectable instance keys * and has custom data associated with it. * * An example of such selectable could be an instance grouping node: * - `identifier` could be a GUID, associated with the node, * - `loadInstanceKeys` would know how to load grouped instance keys from the node, * - `data` could be set to the node itself. * * @public */ export interface CustomSelectable { /** Unique identifier of the selectable. */ identifier: string; /** Asynchronous function for loading instance keys associated with this selectable. */ loadInstanceKeys: () => AsyncIterableIterator<SelectableInstanceKey>; /** Custom data associated with the selectable. */ data: unknown; } /** * A single selectable that identifies something that can be selected in an iTwin.js application. * @public */ export type Selectable = SelectableInstanceKey | CustomSelectable; /** * A type of identifier that can be used to identify a selectable in selection storage. * @public */ export type SelectableIdentifier = SelectableInstanceKey | Pick<CustomSelectable, "identifier">; /** @public */ export declare namespace Selectable { /** Check if the supplied selectable is a `SelectableInstanceKey` */ function isInstanceKey(selectable: Selectable | SelectableIdentifier): selectable is SelectableInstanceKey; /** Check if the supplied selectable is a `CustomSelectable` */ function isCustom(selectable: Selectable): selectable is CustomSelectable; } /** * A collection of selectables that identify something that can be selected in an iTwin.js application * @public */ export interface Selectables { /** * A map between `SelectableInstanceKey.className` and a set of selected instance IDs. */ instanceKeys: Map<string, Set<Id64String>>; /** * A map between `CustomSelectable.identifier` and the selectable itself. */ custom: Map<string, CustomSelectable>; } /** * Class name used to create `SelectableInstanceKey` for transient elements. * @public */ export declare const TRANSIENT_ELEMENT_CLASSNAME = "/TRANSIENT"; /** @public */ export declare namespace Selectables { /** * Creates `Selectables` from array of selectable * @param source Source to create selectables from * @public */ function create(source: Selectable[]): Selectables; /** * Get the number of selectables stored in a `Selectables` object. * @param selectables `Selectables` object to get size for * @public */ function size(selectables: Selectables): number; /** * Is a `Selectables` object currently empty. * @param selectables `Selectables` object to check * @public */ function isEmpty(selectables: Selectables): boolean; /** * Check if a `Selectables` object contains the specified selectable. * @param selectables `Selectables` object to check * @param value The selectable to check for. * @public */ function has(selectables: Selectables, value: SelectableIdentifier): boolean; /** * Check if a `Selectables` object contains all the specified selectables. * @param selectables `Selectables` object to check * @param values The selectables to check for. * @public */ function hasAll(selectables: Selectables, values: SelectableIdentifier[]): boolean; /** * Check if a `Selectables` object contains any of the specified selectables. * @param selectables `Selectables` object to check * @param values The selectables to check for. * @public */ function hasAny(selectables: Selectables, values: SelectableIdentifier[]): boolean; /** * Add a one or more selectables to a `Selectables` * @param selectables `Selectables` object to add selectables for * @param values Selectables to add. * @public */ function add(selectables: Selectables, values: Selectable[]): boolean; /** * Removes one or more selectables from a `Selectables` object. * @param selectables `Selectables` object to remove selectables for * @param values Selectables to remove. * @public */ function remove(selectables: Selectables, values: Selectable[]): boolean; /** * Clear a `Selectables` object. * @param selectables `Selectables` object to clear selectables for * @public */ function clear(selectables: Selectables): boolean; /** * Check whether at least one selectable passes a condition in a `Selectables` object. * @param selectables `Selectables` object to check * @public */ function some(selectables: Selectables, callback: (selectable: Selectable) => boolean): boolean; /** * Iterate over all keys in a `Selectables` object. * @param selectables `Selectables` object to iterate over * @public */ function forEach(selectables: Selectables, callback: (selectable: Selectable, index: number) => void): void; /** * Load all instance keys from the given `Selectables` object. * @param selectables `Selectables` object to load instance keys from * @public */ function load(selectables: Selectables): AsyncIterableIterator<SelectableInstanceKey>; } //# sourceMappingURL=Selectable.d.ts.map