@itwin/unified-selection 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE.md +9 -0
- package/README.md +90 -0
- package/lib/cjs/unified-selection/Selectable.d.ts +131 -0
- package/lib/cjs/unified-selection/Selectable.d.ts.map +1 -0
- package/lib/cjs/unified-selection/Selectable.js +221 -0
- package/lib/cjs/unified-selection/Selectable.js.map +1 -0
- package/lib/cjs/unified-selection/SelectionChangeEvent.d.ts +89 -0
- package/lib/cjs/unified-selection/SelectionChangeEvent.d.ts.map +1 -0
- package/lib/cjs/unified-selection/SelectionChangeEvent.js +43 -0
- package/lib/cjs/unified-selection/SelectionChangeEvent.js.map +1 -0
- package/lib/cjs/unified-selection/SelectionStorage.d.ts +78 -0
- package/lib/cjs/unified-selection/SelectionStorage.d.ts.map +1 -0
- package/lib/cjs/unified-selection/SelectionStorage.js +132 -0
- package/lib/cjs/unified-selection/SelectionStorage.js.map +1 -0
- package/lib/cjs/unified-selection.d.ts +10 -0
- package/lib/cjs/unified-selection.d.ts.map +1 -0
- package/lib/cjs/unified-selection.js +29 -0
- package/lib/cjs/unified-selection.js.map +1 -0
- package/lib/esm/unified-selection/Selectable.d.ts +131 -0
- package/lib/esm/unified-selection/Selectable.d.ts.map +1 -0
- package/lib/esm/unified-selection/Selectable.js +218 -0
- package/lib/esm/unified-selection/Selectable.js.map +1 -0
- package/lib/esm/unified-selection/SelectionChangeEvent.d.ts +89 -0
- package/lib/esm/unified-selection/SelectionChangeEvent.d.ts.map +1 -0
- package/lib/esm/unified-selection/SelectionChangeEvent.js +39 -0
- package/lib/esm/unified-selection/SelectionChangeEvent.js.map +1 -0
- package/lib/esm/unified-selection/SelectionStorage.d.ts +78 -0
- package/lib/esm/unified-selection/SelectionStorage.d.ts.map +1 -0
- package/lib/esm/unified-selection/SelectionStorage.js +128 -0
- package/lib/esm/unified-selection/SelectionStorage.js.map +1 -0
- package/lib/esm/unified-selection.d.ts +10 -0
- package/lib/esm/unified-selection.d.ts.map +1 -0
- package/lib/esm/unified-selection.js +13 -0
- package/lib/esm/unified-selection.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Selectable.js","sourceRoot":"","sources":["../../../src/unified-selection/Selectable.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AA0ChG,YAAY;AACZ,2DAA2D;AAC3D,MAAM,KAAW,UAAU,CAW1B;AAXD,WAAiB,UAAU;IACzB,oEAAoE;IACpE,SAAgB,aAAa,CAAC,UAA6C;QACzE,MAAM,WAAW,GAAG,UAAmC,CAAC;QACxD,OAAO,CAAC,CAAC,WAAW,CAAC,SAAS,IAAI,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC;IACrD,CAAC;IAHe,wBAAa,gBAG5B,CAAA;IAED,+DAA+D;IAC/D,SAAgB,QAAQ,CAAC,UAAsB;QAC7C,OAAO,CAAC,CAAE,UAA+B,CAAC,UAAU,CAAC;IACvD,CAAC;IAFe,mBAAQ,WAEvB,CAAA;AACH,CAAC,EAXgB,UAAU,KAAV,UAAU,QAW1B;AAiBD,YAAY;AACZ,2DAA2D;AAC3D,MAAM,KAAW,WAAW,CA+L3B;AA/LD,WAAiB,WAAW;IAC1B;;;;OAIG;IACH,SAAgB,MAAM,CAAC,MAAoB;QACzC,MAAM,cAAc,GAAG;YACrB,YAAY,EAAE,IAAI,GAAG,EAAuB;YAC5C,MAAM,EAAE,IAAI,GAAG,EAA4B;SAC5C,CAAC;QACF,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,cAAc,CAAC;IACxB,CAAC;IAPe,kBAAM,SAOrB,CAAA;IAED;;;;OAIG;IACH,SAAgB,IAAI,CAAC,WAAwB;QAC3C,IAAI,cAAc,GAAG,CAAC,CAAC;QACvB,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,GAAgB,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AA6C;QAC1F,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,YAAY,EAAE;YAC5C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;gBAC3B,IAAI,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;oBAC/C,OAAO,IAAI,CAAC;iBACb;aACF;SACF;QACD,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,MAAM,EAAE;YACtC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;gBACtB,OAAO,IAAI,CAAC;aACb;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAde,gBAAI,OAcnB,CAAA;IAED;;;;OAIG;IACH,SAAgB,OAAO,CAAC,WAAwB,EAAE,QAAyD;QACzG,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,GAAgB,EAAE,SAAiB,EAAE,EAAE;YACvE,GAAG,CAAC,OAAO,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;QACH,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAClC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IARe,mBAAO,UAQtB,CAAA;IAED,SAAS,kBAAkB,CAAC,SAAiB;QAC3C,OAAO,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC;AACH,CAAC,EA/LgB,WAAW,KAAX,WAAW,QA+L3B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module UnifiedSelection\n */\n\n/**\n * ECInstance selectable\n * @beta\n */\nexport interface SelectableInstanceKey {\n /** Full class name in format `SchemaName:ClassName` or `SchemaName.ClassName`. */\n className: string;\n /** ECInstance ID */\n id: string;\n}\n\n/**\n * A custom selectable\n * @beta\n */\nexport interface CustomSelectable {\n /** Unique identifier of the selectable. */\n identifier: string;\n /** Asynchronous function for loading instance keys associated with this selectable. */\n loadInstanceKeys: () => AsyncIterableIterator<SelectableInstanceKey>;\n /** Custom data associated with the selectable. */\n data: unknown;\n}\n\n/**\n * A single selectable that identifies something in an iTwin.js application\n * @beta\n */\nexport type Selectable = SelectableInstanceKey | CustomSelectable;\n\n/**\n * Type of identifier that can be used to identify selectable in storage.\n * @beta\n */\nexport type SelectableIdentifier = SelectableInstanceKey | Pick<CustomSelectable, \"identifier\">;\n\n/** @beta */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport namespace Selectable {\n /** Check if the supplied selectable is a `SelectableInstanceKey` */\n export function isInstanceKey(selectable: Selectable | SelectableIdentifier): selectable is SelectableInstanceKey {\n const instanceKey = selectable as SelectableInstanceKey;\n return !!instanceKey.className && !!instanceKey.id;\n }\n\n /** Check if the supplied selectable is a `CustomSelectable` */\n export function isCustom(selectable: Selectable): selectable is CustomSelectable {\n return !!(selectable as CustomSelectable).identifier;\n }\n}\n\n/**\n * A collection of selectables that identify something that can be selected in an iTwin.js application\n * @beta\n */\nexport interface Selectables {\n /**\n * Map between `SelectableInstanceKey.className` and a set of selected element IDs.\n */\n instanceKeys: Map<string, Set<string>>;\n /**\n * Map between unique identifier of `CustomSelectable` and the selectable itself.\n */\n custom: Map<string, CustomSelectable>;\n}\n\n/** @beta */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport namespace Selectables {\n /**\n * Creates `Selectables` from array of selectable\n * @param source Source to create selectables from\n * @beta\n */\n export function create(source: Selectable[]): Selectables {\n const newSelectables = {\n instanceKeys: new Map<string, Set<string>>(),\n custom: new Map<string, CustomSelectable>(),\n };\n Selectables.add(newSelectables, source);\n return newSelectables;\n }\n\n /**\n * Get the number of selectables stored in a `Selectables` object.\n * @param selectables `Selectables` object to get size for\n * @beta\n */\n export function size(selectables: Selectables): number {\n let insatanceCount = 0;\n selectables.instanceKeys.forEach((set: Set<string>) => (insatanceCount += set.size));\n return insatanceCount + selectables.custom.size;\n }\n\n /**\n * Is a `Selectables` object currently empty.\n * @param selectables `Selectables` object to check\n * @beta\n */\n export function isEmpty(selectables: Selectables): boolean {\n return Selectables.size(selectables) === 0;\n }\n\n /**\n * Check if a `Selectables` object contains the specified selectable.\n * @param selectables `Selectables` object to check\n * @param value The selectable to check for.\n * @beta\n */\n export function has(selectables: Selectables, value: SelectableIdentifier): boolean {\n if (Selectable.isInstanceKey(value)) {\n const normalizedClassName = normalizeClassName(value.className);\n const set = selectables.instanceKeys.get(normalizedClassName);\n return !!(set && set.has(value.id));\n }\n return selectables.custom.has(value.identifier);\n }\n\n /**\n * Check if a `Selectables` object contains all the specified selectables.\n * @param selectables `Selectables` object to check\n * @param values The selectables to check for.\n * @beta\n */\n export function hasAll(selectables: Selectables, values: SelectableIdentifier[]): boolean {\n if (Selectables.size(selectables) < values.length) {\n return false;\n }\n for (const selectable of values) {\n if (!Selectables.has(selectables, selectable)) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * Check if a `Selectables` object contains any of the specified selectables.\n * @param selectables `Selectables` object to check\n * @param values The selectables to check for.\n * @beta\n */\n export function hasAny(selectables: Selectables, values: SelectableIdentifier[]): boolean {\n for (const selectable of values) {\n if (Selectables.has(selectables, selectable)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Add a one or more selectables to a `Selectables`\n * @param selectables `Selectables` object to add selectables for\n * @param values Selectables to add.\n * @beta\n */\n export function add(selectables: Selectables, values: Selectable[]): boolean {\n let hasChanged = false;\n for (const selectable of values) {\n if (Selectable.isInstanceKey(selectable)) {\n const normalizedClassName = normalizeClassName(selectable.className);\n let set = selectables.instanceKeys.get(normalizedClassName);\n if (!set) {\n set = new Set<string>();\n }\n if (!set.has(selectable.id)) {\n set.add(selectable.id);\n selectables.instanceKeys.set(normalizedClassName, set);\n hasChanged = true;\n }\n } else if (!selectables.custom.has(selectable.identifier)) {\n selectables.custom.set(selectable.identifier, selectable);\n hasChanged = true;\n }\n }\n return hasChanged;\n }\n\n /**\n * Removes one or more selectables from a `Selectables` object.\n * @param selectables `Selectables` object to remove selectables for\n * @param values Selectables to remove.\n * @beta\n */\n export function remove(selectables: Selectables, values: Selectable[]): boolean {\n let hasChanged = false;\n for (const selectable of values) {\n if (Selectable.isInstanceKey(selectable)) {\n const normalizedClassName = normalizeClassName(selectable.className);\n const set = selectables.instanceKeys.get(normalizedClassName);\n if (set && set.has(selectable.id)) {\n set.delete(selectable.id);\n hasChanged = true;\n if (set.size === 0) {\n selectables.instanceKeys.delete(normalizedClassName);\n }\n }\n } else if (selectables.custom.has(selectable.identifier)) {\n selectables.custom.delete(selectable.identifier);\n hasChanged = true;\n }\n }\n return hasChanged;\n }\n\n /**\n * Clear a `Selectables` object.\n * @param selectables `Selectables` object to clear selectables for\n * @beta\n */\n export function clear(selectables: Selectables): boolean {\n if (Selectables.size(selectables) === 0) {\n return false;\n }\n selectables.instanceKeys = new Map<string, Set<string>>();\n selectables.custom = new Map<string, CustomSelectable>();\n return true;\n }\n\n /**\n * Check whether at least one selectable passes a condition in a `Selectables` object.\n * @param selectables `Selectables` object to check\n * @beta\n */\n export function some(selectables: Selectables, callback: (selectable: Selectable) => boolean) {\n for (const entry of selectables.instanceKeys) {\n for (const item of entry[1]) {\n if (callback({ className: entry[0], id: item })) {\n return true;\n }\n }\n }\n for (const entry of selectables.custom) {\n if (callback(entry[1])) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Iterate over all keys in a `Selectables` object.\n * @param selectables `Selectables` object to iterate over\n * @beta\n */\n export function forEach(selectables: Selectables, callback: (selectable: Selectable, index: number) => void) {\n let index = 0;\n selectables.instanceKeys.forEach((ids: Set<string>, className: string) => {\n ids.forEach((id: string) => callback({ className, id }, index++));\n });\n selectables.custom.forEach((data) => {\n callback(data, index++);\n });\n }\n\n function normalizeClassName(className: string): string {\n return className.replace(\".\", \":\");\n }\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Selectables } from "./Selectable";
|
|
2
|
+
import { SelectionStorage } from "./SelectionStorage";
|
|
3
|
+
/** @packageDocumentation
|
|
4
|
+
* @module UnifiedSelection
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The type of selection change
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export type StorageSelectionChangeType =
|
|
11
|
+
/** Added to selection. */
|
|
12
|
+
"add"
|
|
13
|
+
/** Removed from selection. */
|
|
14
|
+
| "remove"
|
|
15
|
+
/** Selection was replaced. */
|
|
16
|
+
| "replace"
|
|
17
|
+
/** Selection was cleared. */
|
|
18
|
+
| "clear";
|
|
19
|
+
/**
|
|
20
|
+
* The event object that is sent when the selection changes.
|
|
21
|
+
* @beta
|
|
22
|
+
*/
|
|
23
|
+
export interface StorageSelectionChangeEventArgs {
|
|
24
|
+
/** The name of the selection source which caused the selection change. */
|
|
25
|
+
source: string;
|
|
26
|
+
/** Level of the selection. */
|
|
27
|
+
level: number;
|
|
28
|
+
/** The selection change type. */
|
|
29
|
+
changeType: StorageSelectionChangeType;
|
|
30
|
+
/** Selectables affected by this selection change event. */
|
|
31
|
+
selectables: Selectables;
|
|
32
|
+
/** iModel key with which the selection is associated with. */
|
|
33
|
+
iModelKey: string;
|
|
34
|
+
/** The timestamp of when the selection change happened */
|
|
35
|
+
timestamp: Date;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An interface for selection change listeners
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export declare type StorageSelectionChangesListener = (args: StorageSelectionChangeEventArgs, storage: SelectionStorage) => void;
|
|
42
|
+
/**
|
|
43
|
+
* An interface that allows subscribing and unsubscribing listeners that
|
|
44
|
+
* are called when a selection has changed.
|
|
45
|
+
* @beta
|
|
46
|
+
*/
|
|
47
|
+
export interface SelectionChangeEvent {
|
|
48
|
+
/**
|
|
49
|
+
* Registers a Listener to be executed whenever this event is raised
|
|
50
|
+
* @param listener The function to be executed when the event is raised
|
|
51
|
+
* @returns A function that will remove this event listener
|
|
52
|
+
* @beta
|
|
53
|
+
*/
|
|
54
|
+
addListener(listener: StorageSelectionChangesListener): () => void;
|
|
55
|
+
/**
|
|
56
|
+
* Un-register a previously registered listener
|
|
57
|
+
* @param listener The listener to be unregistered
|
|
58
|
+
* @beta
|
|
59
|
+
*/
|
|
60
|
+
removeListener(listener: StorageSelectionChangesListener): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* An event broadcasted on selection changes
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export declare class SelectionChangeEventImpl implements SelectionChangeEvent {
|
|
67
|
+
private _listeners;
|
|
68
|
+
/**
|
|
69
|
+
* Registers a Listener to be executed whenever this event is raised
|
|
70
|
+
* @param listener The function to be executed when the event is raised
|
|
71
|
+
* @returns A function that will remove this event listener
|
|
72
|
+
* @beta
|
|
73
|
+
*/
|
|
74
|
+
addListener(listener: StorageSelectionChangesListener): () => void;
|
|
75
|
+
/**
|
|
76
|
+
* Un-register a previously registered listener
|
|
77
|
+
* @param listener The listener to be unregistered
|
|
78
|
+
* @beta
|
|
79
|
+
*/
|
|
80
|
+
removeListener(listener: StorageSelectionChangesListener): void;
|
|
81
|
+
/**
|
|
82
|
+
* Raises the event by calling each registered listener with the supplied arguments
|
|
83
|
+
* @param args Event arguments
|
|
84
|
+
* @param storage Storage that the selection changed in
|
|
85
|
+
* @beta
|
|
86
|
+
*/
|
|
87
|
+
raiseEvent(args: StorageSelectionChangeEventArgs, storage: SelectionStorage): void;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=SelectionChangeEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionChangeEvent.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/SelectionChangeEvent.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;GAEG;AAEH;;;GAGG;AACH,MAAM,MAAM,0BAA0B;AACpC,0BAA0B;AACxB,KAAK;AACP,8BAA8B;GAC5B,QAAQ;AACV,8BAA8B;GAC5B,SAAS;AACX,6BAA6B;GAC3B,OAAO,CAAC;AAEZ;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,UAAU,EAAE,0BAA0B,CAAC;IACvC,2DAA2D;IAC3D,WAAW,EAAE,WAAW,CAAC;IACzB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,MAAM,+BAA+B,GAAG,CAAC,IAAI,EAAE,+BAA+B,EAAE,OAAO,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAEjI;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,WAAW,CAAC,QAAQ,EAAE,+BAA+B,GAAG,MAAM,IAAI,CAAC;IACnE;;;;OAIG;IACH,cAAc,CAAC,QAAQ,EAAE,+BAA+B,GAAG,IAAI,CAAC;CACjE;AAED;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,oBAAoB;IACnE,OAAO,CAAC,UAAU,CAAyC;IAE3D;;;;;OAKG;IACI,WAAW,CAAC,QAAQ,EAAE,+BAA+B,GAAG,MAAM,IAAI;IAKzE;;;;OAIG;IACI,cAAc,CAAC,QAAQ,EAAE,+BAA+B,GAAG,IAAI;IAItE;;;;;OAKG;IACI,UAAU,CAAC,IAAI,EAAE,+BAA+B,EAAE,OAAO,EAAE,gBAAgB;CAGnF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* An event broadcasted on selection changes
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class SelectionChangeEventImpl {
|
|
10
|
+
_listeners = [];
|
|
11
|
+
/**
|
|
12
|
+
* Registers a Listener to be executed whenever this event is raised
|
|
13
|
+
* @param listener The function to be executed when the event is raised
|
|
14
|
+
* @returns A function that will remove this event listener
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
addListener(listener) {
|
|
18
|
+
this._listeners.push(listener);
|
|
19
|
+
return () => this.removeListener(listener);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Un-register a previously registered listener
|
|
23
|
+
* @param listener The listener to be unregistered
|
|
24
|
+
* @beta
|
|
25
|
+
*/
|
|
26
|
+
removeListener(listener) {
|
|
27
|
+
this._listeners = this._listeners.filter((x) => x !== listener);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Raises the event by calling each registered listener with the supplied arguments
|
|
31
|
+
* @param args Event arguments
|
|
32
|
+
* @param storage Storage that the selection changed in
|
|
33
|
+
* @beta
|
|
34
|
+
*/
|
|
35
|
+
raiseEvent(args, storage) {
|
|
36
|
+
this._listeners.forEach((listener) => listener(args, storage));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=SelectionChangeEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionChangeEvent.js","sourceRoot":"","sources":["../../../src/unified-selection/SelectionChangeEvent.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAqEhG;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IAC3B,UAAU,GAAsC,EAAE,CAAC;IAE3D;;;;;OAKG;IACI,WAAW,CAAC,QAAyC;QAC1D,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,QAAyC;QAC7D,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACI,UAAU,CAAC,IAAqC,EAAE,OAAyB;QAChF,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACjE,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 { Selectables } from \"./Selectable\";\nimport { SelectionStorage } from \"./SelectionStorage\";\n\n/** @packageDocumentation\n * @module UnifiedSelection\n */\n\n/**\n * The type of selection change\n * @beta\n */\nexport type StorageSelectionChangeType =\n /** Added to selection. */\n | \"add\"\n /** Removed from selection. */\n | \"remove\"\n /** Selection was replaced. */\n | \"replace\"\n /** Selection was cleared. */\n | \"clear\";\n\n/**\n * The event object that is sent when the selection changes.\n * @beta\n */\nexport interface StorageSelectionChangeEventArgs {\n /** The name of the selection source which caused the selection change. */\n source: string;\n /** Level of the selection. */\n level: number;\n /** The selection change type. */\n changeType: StorageSelectionChangeType;\n /** Selectables affected by this selection change event. */\n selectables: Selectables;\n /** iModel key with which the selection is associated with. */\n iModelKey: string;\n /** The timestamp of when the selection change happened */\n timestamp: Date;\n}\n\n/**\n * An interface for selection change listeners\n * @beta\n */\nexport declare type StorageSelectionChangesListener = (args: StorageSelectionChangeEventArgs, storage: SelectionStorage) => void;\n\n/**\n * An interface that allows subscribing and unsubscribing listeners that\n * are called when a selection has changed.\n * @beta\n */\nexport interface SelectionChangeEvent {\n /**\n * Registers a Listener to be executed whenever this event is raised\n * @param listener The function to be executed when the event is raised\n * @returns A function that will remove this event listener\n * @beta\n */\n addListener(listener: StorageSelectionChangesListener): () => void;\n /**\n * Un-register a previously registered listener\n * @param listener The listener to be unregistered\n * @beta\n */\n removeListener(listener: StorageSelectionChangesListener): void;\n}\n\n/**\n * An event broadcasted on selection changes\n * @internal\n */\nexport class SelectionChangeEventImpl implements SelectionChangeEvent {\n private _listeners: StorageSelectionChangesListener[] = [];\n\n /**\n * Registers a Listener to be executed whenever this event is raised\n * @param listener The function to be executed when the event is raised\n * @returns A function that will remove this event listener\n * @beta\n */\n public addListener(listener: StorageSelectionChangesListener): () => void {\n this._listeners.push(listener);\n return () => this.removeListener(listener);\n }\n\n /**\n * Un-register a previously registered listener\n * @param listener The listener to be unregistered\n * @beta\n */\n public removeListener(listener: StorageSelectionChangesListener): void {\n this._listeners = this._listeners.filter((x) => x !== listener);\n }\n\n /**\n * Raises the event by calling each registered listener with the supplied arguments\n * @param args Event arguments\n * @param storage Storage that the selection changed in\n * @beta\n */\n public raiseEvent(args: StorageSelectionChangeEventArgs, storage: SelectionStorage) {\n this._listeners.forEach((listener) => listener(args, storage));\n }\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module UnifiedSelection
|
|
3
|
+
*/
|
|
4
|
+
import { Selectable, Selectables } from "./Selectable";
|
|
5
|
+
import { SelectionChangeEvent } from "./SelectionChangeEvent";
|
|
6
|
+
/**
|
|
7
|
+
* Selection storage interface which provides main selection and sub-selection.
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export interface SelectionStorage {
|
|
11
|
+
/** An event that is raised when selection changes. */
|
|
12
|
+
selectionChangeEvent: SelectionChangeEvent;
|
|
13
|
+
/** Get the selection levels currently stored for the specified iModel. */
|
|
14
|
+
getSelectionLevels(props: {
|
|
15
|
+
/** Key of the iModel to get selection levels for. */
|
|
16
|
+
iModelKey: string;
|
|
17
|
+
}): number[];
|
|
18
|
+
/** Get the selection stored in the storage. */
|
|
19
|
+
getSelection(props: {
|
|
20
|
+
/** Key of the iModel to get selection for. */
|
|
21
|
+
iModelKey: string;
|
|
22
|
+
/** Level of the selection. Defaults to `0`. */
|
|
23
|
+
level?: number;
|
|
24
|
+
}): Selectables;
|
|
25
|
+
/** Add keys to the selection. */
|
|
26
|
+
addToSelection(props: {
|
|
27
|
+
/** Key of the iModel to change selection for. */
|
|
28
|
+
iModelKey: string;
|
|
29
|
+
/** Name of the selection source. Generally, this identifies the component that makes the selection change. */
|
|
30
|
+
source: string;
|
|
31
|
+
/** The selectables to add to selection. */
|
|
32
|
+
selectables: Selectable[];
|
|
33
|
+
/** Level of the selection. Defaults to `0`. */
|
|
34
|
+
level?: number;
|
|
35
|
+
}): void;
|
|
36
|
+
/** Remove keys from current selection. */
|
|
37
|
+
removeFromSelection(props: {
|
|
38
|
+
/** Key of the iModel to change selection for. */
|
|
39
|
+
iModelKey: string;
|
|
40
|
+
/** Name of the selection source. Generally, this identifies the component that makes the selection change. */
|
|
41
|
+
source: string;
|
|
42
|
+
/** The selectables to remove from selection. */
|
|
43
|
+
selectables: Selectable[];
|
|
44
|
+
/** Level of the selection. Defaults to `0`. */
|
|
45
|
+
level?: number;
|
|
46
|
+
}): void;
|
|
47
|
+
/** Replace current selection. */
|
|
48
|
+
replaceSelection(props: {
|
|
49
|
+
/** Key of the iModel to change selection for. */
|
|
50
|
+
iModelKey: string;
|
|
51
|
+
/** Name of the selection source. Generally, this identifies the component that makes the selection change. */
|
|
52
|
+
source: string;
|
|
53
|
+
/** The selectables to add to selection. */
|
|
54
|
+
selectables: Selectable[];
|
|
55
|
+
/** Level of the selection. Defaults to `0`. */
|
|
56
|
+
level?: number;
|
|
57
|
+
}): void;
|
|
58
|
+
/** Clear current selection. */
|
|
59
|
+
clearSelection(props: {
|
|
60
|
+
/** Key of the iModel to change selection for. */
|
|
61
|
+
iModelKey: string;
|
|
62
|
+
/** Name of the selection source. Generally, this identifies the component that makes the selection change. */
|
|
63
|
+
source: string;
|
|
64
|
+
/** Level of the selection. Defaults to `0`. */
|
|
65
|
+
level?: number;
|
|
66
|
+
}): void;
|
|
67
|
+
/** Clear storage for an iModel. This function should be called when iModel is closed. */
|
|
68
|
+
clearStorage(props: {
|
|
69
|
+
/** Key of the iModel to change selection for. */
|
|
70
|
+
iModelKey: string;
|
|
71
|
+
}): void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a selection storage. When an iModel is closed `SelectionStorage.clearSelection` function should be called.
|
|
75
|
+
* @beta
|
|
76
|
+
*/
|
|
77
|
+
export declare function createStorage(): SelectionStorage;
|
|
78
|
+
//# sourceMappingURL=SelectionStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionStorage.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/SelectionStorage.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAyF,MAAM,wBAAwB,CAAC;AAErJ;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,oBAAoB,EAAE,oBAAoB,CAAC;IAE3C,0EAA0E;IAC1E,kBAAkB,CAAC,KAAK,EAAE;QACxB,qDAAqD;QACrD,SAAS,EAAE,MAAM,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C,KAAK,EAAE;QAClB,iDAAiD;QACjD,SAAS,EAAE,MAAM,CAAC;KACnB,GAAG,IAAI,CAAC;CACV;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,gBAAgB,CAEhD"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module UnifiedSelection
|
|
7
|
+
*/
|
|
8
|
+
import { Selectables } from "./Selectable";
|
|
9
|
+
import { SelectionChangeEventImpl } from "./SelectionChangeEvent";
|
|
10
|
+
/**
|
|
11
|
+
* Creates a selection storage. When an iModel is closed `SelectionStorage.clearSelection` function should be called.
|
|
12
|
+
* @beta
|
|
13
|
+
*/
|
|
14
|
+
export function createStorage() {
|
|
15
|
+
return new SelectionStorageImpl();
|
|
16
|
+
}
|
|
17
|
+
class SelectionStorageImpl {
|
|
18
|
+
_storage = new Map();
|
|
19
|
+
selectionChangeEvent;
|
|
20
|
+
constructor() {
|
|
21
|
+
this.selectionChangeEvent = new SelectionChangeEventImpl();
|
|
22
|
+
}
|
|
23
|
+
getSelectionLevels({ iModelKey }) {
|
|
24
|
+
return this.getContainer(iModelKey).getSelectionLevels();
|
|
25
|
+
}
|
|
26
|
+
getSelection(props) {
|
|
27
|
+
const { iModelKey, level } = props;
|
|
28
|
+
return this.getContainer(iModelKey).getSelection(level ?? 0);
|
|
29
|
+
}
|
|
30
|
+
addToSelection(props) {
|
|
31
|
+
this.handleChange({ ...props, changeType: "add" });
|
|
32
|
+
}
|
|
33
|
+
removeFromSelection(props) {
|
|
34
|
+
this.handleChange({ ...props, changeType: "remove" });
|
|
35
|
+
}
|
|
36
|
+
replaceSelection(props) {
|
|
37
|
+
this.handleChange({ ...props, changeType: "replace" });
|
|
38
|
+
}
|
|
39
|
+
clearSelection(props) {
|
|
40
|
+
this.handleChange({ ...props, changeType: "clear", selectables: [] });
|
|
41
|
+
}
|
|
42
|
+
clearStorage({ iModelKey }) {
|
|
43
|
+
this.clearSelection({ source: "Clear iModel storage", iModelKey });
|
|
44
|
+
this._storage.delete(iModelKey);
|
|
45
|
+
}
|
|
46
|
+
getContainer(iModelKey) {
|
|
47
|
+
let selectionContainer = this._storage.get(iModelKey);
|
|
48
|
+
if (!selectionContainer) {
|
|
49
|
+
selectionContainer = new MultiLevelSelectablesContainer();
|
|
50
|
+
this._storage.set(iModelKey, selectionContainer);
|
|
51
|
+
}
|
|
52
|
+
return selectionContainer;
|
|
53
|
+
}
|
|
54
|
+
handleChange(props) {
|
|
55
|
+
const { iModelKey, source, level: inLevel, changeType, selectables: change } = props;
|
|
56
|
+
const container = this.getContainer(iModelKey);
|
|
57
|
+
const level = inLevel ?? 0;
|
|
58
|
+
const selectables = container.getSelection(level);
|
|
59
|
+
const selected = Selectables.create(change);
|
|
60
|
+
switch (changeType) {
|
|
61
|
+
case "add":
|
|
62
|
+
if (!Selectables.add(selectables, change)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case "remove":
|
|
67
|
+
if (!Selectables.remove(selectables, change)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
case "replace":
|
|
72
|
+
if (Selectables.size(selectables) === Selectables.size(selected) && Selectables.hasAll(selectables, change)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
Selectables.clear(selectables);
|
|
76
|
+
Selectables.add(selectables, change);
|
|
77
|
+
break;
|
|
78
|
+
case "clear":
|
|
79
|
+
if (!Selectables.clear(selectables)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
container.clear(level + 1);
|
|
85
|
+
const event = {
|
|
86
|
+
source,
|
|
87
|
+
level,
|
|
88
|
+
iModelKey,
|
|
89
|
+
changeType,
|
|
90
|
+
selectables: selected,
|
|
91
|
+
timestamp: new Date(),
|
|
92
|
+
};
|
|
93
|
+
this.selectionChangeEvent.raiseEvent(event, this);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class MultiLevelSelectablesContainer {
|
|
97
|
+
_selectablesContainers;
|
|
98
|
+
constructor() {
|
|
99
|
+
this._selectablesContainers = new Map();
|
|
100
|
+
}
|
|
101
|
+
getSelection(level) {
|
|
102
|
+
let selectables = this._selectablesContainers.get(level);
|
|
103
|
+
if (!selectables) {
|
|
104
|
+
selectables = Selectables.create([]);
|
|
105
|
+
this._selectablesContainers.set(level, selectables);
|
|
106
|
+
}
|
|
107
|
+
return selectables;
|
|
108
|
+
}
|
|
109
|
+
getSelectionLevels() {
|
|
110
|
+
const levels = new Array();
|
|
111
|
+
for (const entry of this._selectablesContainers.entries()) {
|
|
112
|
+
if (!Selectables.isEmpty(entry[1])) {
|
|
113
|
+
levels.push(entry[0]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return levels.sort();
|
|
117
|
+
}
|
|
118
|
+
clear(level) {
|
|
119
|
+
const storedLevels = this._selectablesContainers.keys();
|
|
120
|
+
for (const storedLevel of storedLevels) {
|
|
121
|
+
if (storedLevel >= level) {
|
|
122
|
+
const selectables = this._selectablesContainers.get(storedLevel);
|
|
123
|
+
Selectables.clear(selectables);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=SelectionStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionStorage.js","sourceRoot":"","sources":["../../../src/unified-selection/SelectionStorage.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG;;GAEG;AAEH,OAAO,EAAc,WAAW,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAwB,wBAAwB,EAA+D,MAAM,wBAAwB,CAAC;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AK,CAAC,CAAC,CAAC,CAAC,CAAC;aACvB;SACF;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;YACtC,IAAI,WAAW,IAAI,KAAK,EAAE;gBACxB,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC;gBAClE,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;aAChC;SACF;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\n/** @packageDocumentation\n * @module UnifiedSelection\n */\n\nimport { Selectable, Selectables } from \"./Selectable\";\nimport { SelectionChangeEvent, SelectionChangeEventImpl, StorageSelectionChangeEventArgs, StorageSelectionChangeType } from \"./SelectionChangeEvent\";\n\n/**\n * Selection storage interface which provides main selection and sub-selection.\n * @beta\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: {\n /** Key of the iModel to get selection levels for. */\n iModelKey: string;\n }): number[];\n\n /** Get the selection stored in the storage. */\n getSelection(props: {\n /** Key of the iModel to get selection for. */\n iModelKey: string;\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n }): Selectables;\n\n /** Add keys to the selection. */\n addToSelection(props: {\n /** Key of the iModel to change selection for. */\n iModelKey: string;\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 }): void;\n\n /** Remove keys from current selection. */\n removeFromSelection(props: {\n /** Key of the iModel to change selection for. */\n iModelKey: string;\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 }): void;\n\n /** Replace current selection. */\n replaceSelection(props: {\n /** Key of the iModel to change selection for. */\n iModelKey: string;\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 }): void;\n\n /** Clear current selection. */\n clearSelection(props: {\n /** Key of the iModel to change selection for. */\n iModelKey: string;\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 }): void;\n\n /** Clear storage for an iModel. This function should be called when iModel is closed. */\n clearStorage(props: {\n /** Key of the iModel to change selection for. */\n iModelKey: string;\n }): void;\n}\n\n/**\n * Creates a selection storage. When an iModel is closed `SelectionStorage.clearSelection` function should be called.\n * @beta\n */\nexport function createStorage(): SelectionStorage {\n return new SelectionStorageImpl();\n}\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({ iModelKey }: { iModelKey: string }): number[] {\n return this.getContainer(iModelKey).getSelectionLevels();\n }\n\n public getSelection(props: { iModelKey: string; level?: number }): Selectables {\n const { iModelKey, level } = props;\n return this.getContainer(iModelKey).getSelection(level ?? 0);\n }\n\n public addToSelection(props: { source: string; iModelKey: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"add\" });\n }\n\n public removeFromSelection(props: { source: string; iModelKey: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"remove\" });\n }\n\n public replaceSelection(props: { source: string; iModelKey: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"replace\" });\n }\n\n public clearSelection(props: { source: string; iModelKey: string; level?: number }): void {\n this.handleChange({ ...props, changeType: \"clear\", selectables: [] });\n }\n\n public clearStorage({ iModelKey }: { iModelKey: string }): void {\n this.clearSelection({ source: \"Clear iModel storage\", 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: { source: string; iModelKey: string; level?: number; changeType: StorageSelectionChangeType; selectables: Selectable[] }) {\n const { iModelKey, source, level: inLevel, changeType, selectables: change } = 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 changeType,\n selectables: selected,\n timestamp: new Date(),\n };\n this.selectionChangeEvent.raiseEvent(event, this);\n }\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"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module UnifiedSelection
|
|
3
|
+
*
|
|
4
|
+
* @docs-group-description UnifiedSelection
|
|
5
|
+
* API for working with unified selection.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./unified-selection/Selectable";
|
|
8
|
+
export * from "./unified-selection/SelectionStorage";
|
|
9
|
+
export { StorageSelectionChangeType, StorageSelectionChangeEventArgs, StorageSelectionChangesListener, SelectionChangeEvent, } from "./unified-selection/SelectionChangeEvent";
|
|
10
|
+
//# sourceMappingURL=unified-selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified-selection.d.ts","sourceRoot":"","sources":["../../src/unified-selection.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC;AACrD,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/**
|
|
6
|
+
* @module UnifiedSelection
|
|
7
|
+
*
|
|
8
|
+
* @docs-group-description UnifiedSelection
|
|
9
|
+
* API for working with unified selection.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./unified-selection/Selectable";
|
|
12
|
+
export * from "./unified-selection/SelectionStorage";
|
|
13
|
+
//# sourceMappingURL=unified-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unified-selection.js","sourceRoot":"","sources":["../../src/unified-selection.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG;;;;;GAKG;AACH,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\n/**\n * @module UnifiedSelection\n *\n * @docs-group-description UnifiedSelection\n * API for working with unified selection.\n */\nexport * from \"./unified-selection/Selectable\";\nexport * from \"./unified-selection/SelectionStorage\";\nexport {\n StorageSelectionChangeType,\n StorageSelectionChangeEventArgs,\n StorageSelectionChangesListener,\n SelectionChangeEvent,\n} from \"./unified-selection/SelectionChangeEvent\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@itwin/unified-selection",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Package for managing unified selection",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/iTwin/presentation.git",
|
|
8
|
+
"directory": "packages/unified-selection"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"Bentley",
|
|
12
|
+
"EC",
|
|
13
|
+
"Unified selection",
|
|
14
|
+
"iTwin.js"
|
|
15
|
+
],
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Bentley Systems, Inc.",
|
|
18
|
+
"url": "http://www.bentley.com"
|
|
19
|
+
},
|
|
20
|
+
"main": "lib/cjs/unified-selection.js",
|
|
21
|
+
"module": "lib/esm/unified-selection.js",
|
|
22
|
+
"types": "lib/cjs/unified-selection.d.ts",
|
|
23
|
+
"dependencies": {},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@itwin/build-tools": "^4.4.0",
|
|
26
|
+
"@itwin/eslint-plugin": "4.0.0-dev.48",
|
|
27
|
+
"@types/chai": "^4.3.11",
|
|
28
|
+
"@types/chai-as-promised": "^7.1.8",
|
|
29
|
+
"@types/mocha": "^10.0.6",
|
|
30
|
+
"@types/node": "^18.17.7",
|
|
31
|
+
"@types/sinon": "^17.0.3",
|
|
32
|
+
"@types/sinon-chai": "^3.2.12",
|
|
33
|
+
"chai": "^4.4.1",
|
|
34
|
+
"chai-as-promised": "^7.1.1",
|
|
35
|
+
"cpx2": "^7.0.1",
|
|
36
|
+
"eslint": "^8.56.0",
|
|
37
|
+
"mocha": "^10.3.0",
|
|
38
|
+
"nyc": "^15.1.0",
|
|
39
|
+
"sinon": "^17.0.1",
|
|
40
|
+
"sinon-chai": "^3.7.0",
|
|
41
|
+
"source-map-support": "^0.5.21",
|
|
42
|
+
"typescript": "~5.0.4"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "npm run -s build:cjs && npm run -s build:esm",
|
|
46
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
47
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
48
|
+
"build:watch": "npm run -s build:cjs -- -w",
|
|
49
|
+
"clean": "rimraf lib build",
|
|
50
|
+
"cover": "nyc npm -s test",
|
|
51
|
+
"lint": "eslint ./src/**/*.ts",
|
|
52
|
+
"test": "mocha --config ./.mocharc.json \"./lib/cjs/test/**/*.test.js\"",
|
|
53
|
+
"test:watch": "npm -s test -- --reporter min --watch-extensions ts --watch",
|
|
54
|
+
"extract-api": "betools extract-api --entry=unified-selection --apiReportFolder=./api --apiReportTempFolder=./api/temp --apiSummaryFolder=./api",
|
|
55
|
+
"check-internal": "node ../../scripts/checkInternal.js --apiSummary ./api/unified-selection.api.md"
|
|
56
|
+
}
|
|
57
|
+
}
|