@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,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,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,EAAE,MAAM,CAAC;KAChB,GAAG,IAAI,CAAC;IAET,+BAA+B;IAC/B,cAAc,CAAC,KAAK,EAAE;QACpB,iDAAiD;QACjD,SAAS,EAAE,MAAM,CAAC;QAClB,8GAA8G;QAC9G,MAAM,EAAE,MAAM,CAAC;QACf,+CAA+C;QAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,IAAI,CAAC;IAET,yFAAyF;IACzF,YAAY,CAAC,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,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createStorage = void 0;
|
|
8
|
+
/** @packageDocumentation
|
|
9
|
+
* @module UnifiedSelection
|
|
10
|
+
*/
|
|
11
|
+
const Selectable_1 = require("./Selectable");
|
|
12
|
+
const SelectionChangeEvent_1 = require("./SelectionChangeEvent");
|
|
13
|
+
/**
|
|
14
|
+
* Creates a selection storage. When an iModel is closed `SelectionStorage.clearSelection` function should be called.
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
function createStorage() {
|
|
18
|
+
return new SelectionStorageImpl();
|
|
19
|
+
}
|
|
20
|
+
exports.createStorage = createStorage;
|
|
21
|
+
class SelectionStorageImpl {
|
|
22
|
+
_storage = new Map();
|
|
23
|
+
selectionChangeEvent;
|
|
24
|
+
constructor() {
|
|
25
|
+
this.selectionChangeEvent = new SelectionChangeEvent_1.SelectionChangeEventImpl();
|
|
26
|
+
}
|
|
27
|
+
getSelectionLevels({ iModelKey }) {
|
|
28
|
+
return this.getContainer(iModelKey).getSelectionLevels();
|
|
29
|
+
}
|
|
30
|
+
getSelection(props) {
|
|
31
|
+
const { iModelKey, level } = props;
|
|
32
|
+
return this.getContainer(iModelKey).getSelection(level ?? 0);
|
|
33
|
+
}
|
|
34
|
+
addToSelection(props) {
|
|
35
|
+
this.handleChange({ ...props, changeType: "add" });
|
|
36
|
+
}
|
|
37
|
+
removeFromSelection(props) {
|
|
38
|
+
this.handleChange({ ...props, changeType: "remove" });
|
|
39
|
+
}
|
|
40
|
+
replaceSelection(props) {
|
|
41
|
+
this.handleChange({ ...props, changeType: "replace" });
|
|
42
|
+
}
|
|
43
|
+
clearSelection(props) {
|
|
44
|
+
this.handleChange({ ...props, changeType: "clear", selectables: [] });
|
|
45
|
+
}
|
|
46
|
+
clearStorage({ iModelKey }) {
|
|
47
|
+
this.clearSelection({ source: "Clear iModel storage", iModelKey });
|
|
48
|
+
this._storage.delete(iModelKey);
|
|
49
|
+
}
|
|
50
|
+
getContainer(iModelKey) {
|
|
51
|
+
let selectionContainer = this._storage.get(iModelKey);
|
|
52
|
+
if (!selectionContainer) {
|
|
53
|
+
selectionContainer = new MultiLevelSelectablesContainer();
|
|
54
|
+
this._storage.set(iModelKey, selectionContainer);
|
|
55
|
+
}
|
|
56
|
+
return selectionContainer;
|
|
57
|
+
}
|
|
58
|
+
handleChange(props) {
|
|
59
|
+
const { iModelKey, source, level: inLevel, changeType, selectables: change } = props;
|
|
60
|
+
const container = this.getContainer(iModelKey);
|
|
61
|
+
const level = inLevel ?? 0;
|
|
62
|
+
const selectables = container.getSelection(level);
|
|
63
|
+
const selected = Selectable_1.Selectables.create(change);
|
|
64
|
+
switch (changeType) {
|
|
65
|
+
case "add":
|
|
66
|
+
if (!Selectable_1.Selectables.add(selectables, change)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
case "remove":
|
|
71
|
+
if (!Selectable_1.Selectables.remove(selectables, change)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case "replace":
|
|
76
|
+
if (Selectable_1.Selectables.size(selectables) === Selectable_1.Selectables.size(selected) && Selectable_1.Selectables.hasAll(selectables, change)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
Selectable_1.Selectables.clear(selectables);
|
|
80
|
+
Selectable_1.Selectables.add(selectables, change);
|
|
81
|
+
break;
|
|
82
|
+
case "clear":
|
|
83
|
+
if (!Selectable_1.Selectables.clear(selectables)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
container.clear(level + 1);
|
|
89
|
+
const event = {
|
|
90
|
+
source,
|
|
91
|
+
level,
|
|
92
|
+
iModelKey,
|
|
93
|
+
changeType,
|
|
94
|
+
selectables: selected,
|
|
95
|
+
timestamp: new Date(),
|
|
96
|
+
};
|
|
97
|
+
this.selectionChangeEvent.raiseEvent(event, this);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
class MultiLevelSelectablesContainer {
|
|
101
|
+
_selectablesContainers;
|
|
102
|
+
constructor() {
|
|
103
|
+
this._selectablesContainers = new Map();
|
|
104
|
+
}
|
|
105
|
+
getSelection(level) {
|
|
106
|
+
let selectables = this._selectablesContainers.get(level);
|
|
107
|
+
if (!selectables) {
|
|
108
|
+
selectables = Selectable_1.Selectables.create([]);
|
|
109
|
+
this._selectablesContainers.set(level, selectables);
|
|
110
|
+
}
|
|
111
|
+
return selectables;
|
|
112
|
+
}
|
|
113
|
+
getSelectionLevels() {
|
|
114
|
+
const levels = new Array();
|
|
115
|
+
for (const entry of this._selectablesContainers.entries()) {
|
|
116
|
+
if (!Selectable_1.Selectables.isEmpty(entry[1])) {
|
|
117
|
+
levels.push(entry[0]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return levels.sort();
|
|
121
|
+
}
|
|
122
|
+
clear(level) {
|
|
123
|
+
const storedLevels = this._selectablesContainers.keys();
|
|
124
|
+
for (const storedLevel of storedLevels) {
|
|
125
|
+
if (storedLevel >= level) {
|
|
126
|
+
const selectables = this._selectablesContainers.get(storedLevel);
|
|
127
|
+
Selectable_1.Selectables.clear(selectables);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# 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,6CAAuD;AACvD,iEAAqJ;AA6ErJ;;;GAGG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAI,oBAAoB,EAAE,CAAC;AACpC,CAAC;AAFD,sCAEC;AAED,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,EAAE,SAAS,EAAyB;QAC5D,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,CAAC;IAC3D,CAAC;IAEM,YAAY,CAAC,KAA4C;QAC9D,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QACnC,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;IAC/D,CAAC;IAEM,cAAc,CAAC,KAAuF;QAC3G,IAAI,CAAC,YAAY,CAAC,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC;IAEM,mBAAmB,CAAC,KAAuF;QAChH,IAAI,CAAC,YAAY,CAAC,EAAE,GAA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AC,CAAC;QACzD,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,wBAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACrC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;SACrD;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAEM,kBAAkB;QACvB,MAAM,MAAM,GAAG,IAAI,KAAK,EAAU,CAAC;QACnC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,sBAAsB,CAAC,OAAO,EAAE,EAAE;YACzD,IAAI,CAAC,wBAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;gBAClC,MAAM,CAAC,IAAI,CAAC,KAAK,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,wBAAW,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,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
/**
|
|
22
|
+
* @module UnifiedSelection
|
|
23
|
+
*
|
|
24
|
+
* @docs-group-description UnifiedSelection
|
|
25
|
+
* API for working with unified selection.
|
|
26
|
+
*/
|
|
27
|
+
__exportStar(require("./unified-selection/Selectable"), exports);
|
|
28
|
+
__exportStar(require("./unified-selection/SelectionStorage"), exports);
|
|
29
|
+
//# 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,iEAA+C;AAC/C,uEAAqD","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"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module UnifiedSelection
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* ECInstance selectable
|
|
6
|
+
* @beta
|
|
7
|
+
*/
|
|
8
|
+
export interface SelectableInstanceKey {
|
|
9
|
+
/** Full class name in format `SchemaName:ClassName` or `SchemaName.ClassName`. */
|
|
10
|
+
className: string;
|
|
11
|
+
/** ECInstance ID */
|
|
12
|
+
id: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A custom selectable
|
|
16
|
+
* @beta
|
|
17
|
+
*/
|
|
18
|
+
export interface CustomSelectable {
|
|
19
|
+
/** Unique identifier of the selectable. */
|
|
20
|
+
identifier: string;
|
|
21
|
+
/** Asynchronous function for loading instance keys associated with this selectable. */
|
|
22
|
+
loadInstanceKeys: () => AsyncIterableIterator<SelectableInstanceKey>;
|
|
23
|
+
/** Custom data associated with the selectable. */
|
|
24
|
+
data: unknown;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A single selectable that identifies something in an iTwin.js application
|
|
28
|
+
* @beta
|
|
29
|
+
*/
|
|
30
|
+
export type Selectable = SelectableInstanceKey | CustomSelectable;
|
|
31
|
+
/**
|
|
32
|
+
* Type of identifier that can be used to identify selectable in storage.
|
|
33
|
+
* @beta
|
|
34
|
+
*/
|
|
35
|
+
export type SelectableIdentifier = SelectableInstanceKey | Pick<CustomSelectable, "identifier">;
|
|
36
|
+
/** @beta */
|
|
37
|
+
export declare namespace Selectable {
|
|
38
|
+
/** Check if the supplied selectable is a `SelectableInstanceKey` */
|
|
39
|
+
function isInstanceKey(selectable: Selectable | SelectableIdentifier): selectable is SelectableInstanceKey;
|
|
40
|
+
/** Check if the supplied selectable is a `CustomSelectable` */
|
|
41
|
+
function isCustom(selectable: Selectable): selectable is CustomSelectable;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A collection of selectables that identify something that can be selected in an iTwin.js application
|
|
45
|
+
* @beta
|
|
46
|
+
*/
|
|
47
|
+
export interface Selectables {
|
|
48
|
+
/**
|
|
49
|
+
* Map between `SelectableInstanceKey.className` and a set of selected element IDs.
|
|
50
|
+
*/
|
|
51
|
+
instanceKeys: Map<string, Set<string>>;
|
|
52
|
+
/**
|
|
53
|
+
* Map between unique identifier of `CustomSelectable` and the selectable itself.
|
|
54
|
+
*/
|
|
55
|
+
custom: Map<string, CustomSelectable>;
|
|
56
|
+
}
|
|
57
|
+
/** @beta */
|
|
58
|
+
export declare namespace Selectables {
|
|
59
|
+
/**
|
|
60
|
+
* Creates `Selectables` from array of selectable
|
|
61
|
+
* @param source Source to create selectables from
|
|
62
|
+
* @beta
|
|
63
|
+
*/
|
|
64
|
+
function create(source: Selectable[]): Selectables;
|
|
65
|
+
/**
|
|
66
|
+
* Get the number of selectables stored in a `Selectables` object.
|
|
67
|
+
* @param selectables `Selectables` object to get size for
|
|
68
|
+
* @beta
|
|
69
|
+
*/
|
|
70
|
+
function size(selectables: Selectables): number;
|
|
71
|
+
/**
|
|
72
|
+
* Is a `Selectables` object currently empty.
|
|
73
|
+
* @param selectables `Selectables` object to check
|
|
74
|
+
* @beta
|
|
75
|
+
*/
|
|
76
|
+
function isEmpty(selectables: Selectables): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Check if a `Selectables` object contains the specified selectable.
|
|
79
|
+
* @param selectables `Selectables` object to check
|
|
80
|
+
* @param value The selectable to check for.
|
|
81
|
+
* @beta
|
|
82
|
+
*/
|
|
83
|
+
function has(selectables: Selectables, value: SelectableIdentifier): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Check if a `Selectables` object contains all the specified selectables.
|
|
86
|
+
* @param selectables `Selectables` object to check
|
|
87
|
+
* @param values The selectables to check for.
|
|
88
|
+
* @beta
|
|
89
|
+
*/
|
|
90
|
+
function hasAll(selectables: Selectables, values: SelectableIdentifier[]): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Check if a `Selectables` object contains any of the specified selectables.
|
|
93
|
+
* @param selectables `Selectables` object to check
|
|
94
|
+
* @param values The selectables to check for.
|
|
95
|
+
* @beta
|
|
96
|
+
*/
|
|
97
|
+
function hasAny(selectables: Selectables, values: SelectableIdentifier[]): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Add a one or more selectables to a `Selectables`
|
|
100
|
+
* @param selectables `Selectables` object to add selectables for
|
|
101
|
+
* @param values Selectables to add.
|
|
102
|
+
* @beta
|
|
103
|
+
*/
|
|
104
|
+
function add(selectables: Selectables, values: Selectable[]): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Removes one or more selectables from a `Selectables` object.
|
|
107
|
+
* @param selectables `Selectables` object to remove selectables for
|
|
108
|
+
* @param values Selectables to remove.
|
|
109
|
+
* @beta
|
|
110
|
+
*/
|
|
111
|
+
function remove(selectables: Selectables, values: Selectable[]): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Clear a `Selectables` object.
|
|
114
|
+
* @param selectables `Selectables` object to clear selectables for
|
|
115
|
+
* @beta
|
|
116
|
+
*/
|
|
117
|
+
function clear(selectables: Selectables): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Check whether at least one selectable passes a condition in a `Selectables` object.
|
|
120
|
+
* @param selectables `Selectables` object to check
|
|
121
|
+
* @beta
|
|
122
|
+
*/
|
|
123
|
+
function some(selectables: Selectables, callback: (selectable: Selectable) => boolean): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Iterate over all keys in a `Selectables` object.
|
|
126
|
+
* @param selectables `Selectables` object to iterate over
|
|
127
|
+
* @beta
|
|
128
|
+
*/
|
|
129
|
+
function forEach(selectables: Selectables, callback: (selectable: Selectable, index: number) => void): void;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=Selectable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Selectable.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/Selectable.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,kFAAkF;IAClF,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,uFAAuF;IACvF,gBAAgB,EAAE,MAAM,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;IACrE,kDAAkD;IAClD,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,qBAAqB,GAAG,gBAAgB,CAAC;AAElE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;AAEhG,YAAY;AAEZ,yBAAiB,UAAU,CAAC;IAC1B,oEAAoE;IACpE,SAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,oBAAoB,GAAG,UAAU,IAAI,qBAAqB,CAGhH;IAED,+DAA+D;IAC/D,SAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,I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O,WAc3F;IAED;;;;OAIG;IACH,SAAgB,OAAO,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,QAQ1G;CAKF"}
|
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
/** @beta */
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
7
|
+
export var Selectable;
|
|
8
|
+
(function (Selectable) {
|
|
9
|
+
/** Check if the supplied selectable is a `SelectableInstanceKey` */
|
|
10
|
+
function isInstanceKey(selectable) {
|
|
11
|
+
const instanceKey = selectable;
|
|
12
|
+
return !!instanceKey.className && !!instanceKey.id;
|
|
13
|
+
}
|
|
14
|
+
Selectable.isInstanceKey = isInstanceKey;
|
|
15
|
+
/** Check if the supplied selectable is a `CustomSelectable` */
|
|
16
|
+
function isCustom(selectable) {
|
|
17
|
+
return !!selectable.identifier;
|
|
18
|
+
}
|
|
19
|
+
Selectable.isCustom = isCustom;
|
|
20
|
+
})(Selectable || (Selectable = {}));
|
|
21
|
+
/** @beta */
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
23
|
+
export var Selectables;
|
|
24
|
+
(function (Selectables) {
|
|
25
|
+
/**
|
|
26
|
+
* Creates `Selectables` from array of selectable
|
|
27
|
+
* @param source Source to create selectables from
|
|
28
|
+
* @beta
|
|
29
|
+
*/
|
|
30
|
+
function create(source) {
|
|
31
|
+
const newSelectables = {
|
|
32
|
+
instanceKeys: new Map(),
|
|
33
|
+
custom: new Map(),
|
|
34
|
+
};
|
|
35
|
+
Selectables.add(newSelectables, source);
|
|
36
|
+
return newSelectables;
|
|
37
|
+
}
|
|
38
|
+
Selectables.create = create;
|
|
39
|
+
/**
|
|
40
|
+
* Get the number of selectables stored in a `Selectables` object.
|
|
41
|
+
* @param selectables `Selectables` object to get size for
|
|
42
|
+
* @beta
|
|
43
|
+
*/
|
|
44
|
+
function size(selectables) {
|
|
45
|
+
let insatanceCount = 0;
|
|
46
|
+
selectables.instanceKeys.forEach((set) => (insatanceCount += set.size));
|
|
47
|
+
return insatanceCount + selectables.custom.size;
|
|
48
|
+
}
|
|
49
|
+
Selectables.size = size;
|
|
50
|
+
/**
|
|
51
|
+
* Is a `Selectables` object currently empty.
|
|
52
|
+
* @param selectables `Selectables` object to check
|
|
53
|
+
* @beta
|
|
54
|
+
*/
|
|
55
|
+
function isEmpty(selectables) {
|
|
56
|
+
return Selectables.size(selectables) === 0;
|
|
57
|
+
}
|
|
58
|
+
Selectables.isEmpty = isEmpty;
|
|
59
|
+
/**
|
|
60
|
+
* Check if a `Selectables` object contains the specified selectable.
|
|
61
|
+
* @param selectables `Selectables` object to check
|
|
62
|
+
* @param value The selectable to check for.
|
|
63
|
+
* @beta
|
|
64
|
+
*/
|
|
65
|
+
function has(selectables, value) {
|
|
66
|
+
if (Selectable.isInstanceKey(value)) {
|
|
67
|
+
const normalizedClassName = normalizeClassName(value.className);
|
|
68
|
+
const set = selectables.instanceKeys.get(normalizedClassName);
|
|
69
|
+
return !!(set && set.has(value.id));
|
|
70
|
+
}
|
|
71
|
+
return selectables.custom.has(value.identifier);
|
|
72
|
+
}
|
|
73
|
+
Selectables.has = has;
|
|
74
|
+
/**
|
|
75
|
+
* Check if a `Selectables` object contains all the specified selectables.
|
|
76
|
+
* @param selectables `Selectables` object to check
|
|
77
|
+
* @param values The selectables to check for.
|
|
78
|
+
* @beta
|
|
79
|
+
*/
|
|
80
|
+
function hasAll(selectables, values) {
|
|
81
|
+
if (Selectables.size(selectables) < values.length) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
for (const selectable of values) {
|
|
85
|
+
if (!Selectables.has(selectables, selectable)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
Selectables.hasAll = hasAll;
|
|
92
|
+
/**
|
|
93
|
+
* Check if a `Selectables` object contains any of the specified selectables.
|
|
94
|
+
* @param selectables `Selectables` object to check
|
|
95
|
+
* @param values The selectables to check for.
|
|
96
|
+
* @beta
|
|
97
|
+
*/
|
|
98
|
+
function hasAny(selectables, values) {
|
|
99
|
+
for (const selectable of values) {
|
|
100
|
+
if (Selectables.has(selectables, selectable)) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
Selectables.hasAny = hasAny;
|
|
107
|
+
/**
|
|
108
|
+
* Add a one or more selectables to a `Selectables`
|
|
109
|
+
* @param selectables `Selectables` object to add selectables for
|
|
110
|
+
* @param values Selectables to add.
|
|
111
|
+
* @beta
|
|
112
|
+
*/
|
|
113
|
+
function add(selectables, values) {
|
|
114
|
+
let hasChanged = false;
|
|
115
|
+
for (const selectable of values) {
|
|
116
|
+
if (Selectable.isInstanceKey(selectable)) {
|
|
117
|
+
const normalizedClassName = normalizeClassName(selectable.className);
|
|
118
|
+
let set = selectables.instanceKeys.get(normalizedClassName);
|
|
119
|
+
if (!set) {
|
|
120
|
+
set = new Set();
|
|
121
|
+
}
|
|
122
|
+
if (!set.has(selectable.id)) {
|
|
123
|
+
set.add(selectable.id);
|
|
124
|
+
selectables.instanceKeys.set(normalizedClassName, set);
|
|
125
|
+
hasChanged = true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (!selectables.custom.has(selectable.identifier)) {
|
|
129
|
+
selectables.custom.set(selectable.identifier, selectable);
|
|
130
|
+
hasChanged = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return hasChanged;
|
|
134
|
+
}
|
|
135
|
+
Selectables.add = add;
|
|
136
|
+
/**
|
|
137
|
+
* Removes one or more selectables from a `Selectables` object.
|
|
138
|
+
* @param selectables `Selectables` object to remove selectables for
|
|
139
|
+
* @param values Selectables to remove.
|
|
140
|
+
* @beta
|
|
141
|
+
*/
|
|
142
|
+
function remove(selectables, values) {
|
|
143
|
+
let hasChanged = false;
|
|
144
|
+
for (const selectable of values) {
|
|
145
|
+
if (Selectable.isInstanceKey(selectable)) {
|
|
146
|
+
const normalizedClassName = normalizeClassName(selectable.className);
|
|
147
|
+
const set = selectables.instanceKeys.get(normalizedClassName);
|
|
148
|
+
if (set && set.has(selectable.id)) {
|
|
149
|
+
set.delete(selectable.id);
|
|
150
|
+
hasChanged = true;
|
|
151
|
+
if (set.size === 0) {
|
|
152
|
+
selectables.instanceKeys.delete(normalizedClassName);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (selectables.custom.has(selectable.identifier)) {
|
|
157
|
+
selectables.custom.delete(selectable.identifier);
|
|
158
|
+
hasChanged = true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return hasChanged;
|
|
162
|
+
}
|
|
163
|
+
Selectables.remove = remove;
|
|
164
|
+
/**
|
|
165
|
+
* Clear a `Selectables` object.
|
|
166
|
+
* @param selectables `Selectables` object to clear selectables for
|
|
167
|
+
* @beta
|
|
168
|
+
*/
|
|
169
|
+
function clear(selectables) {
|
|
170
|
+
if (Selectables.size(selectables) === 0) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
selectables.instanceKeys = new Map();
|
|
174
|
+
selectables.custom = new Map();
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
Selectables.clear = clear;
|
|
178
|
+
/**
|
|
179
|
+
* Check whether at least one selectable passes a condition in a `Selectables` object.
|
|
180
|
+
* @param selectables `Selectables` object to check
|
|
181
|
+
* @beta
|
|
182
|
+
*/
|
|
183
|
+
function some(selectables, callback) {
|
|
184
|
+
for (const entry of selectables.instanceKeys) {
|
|
185
|
+
for (const item of entry[1]) {
|
|
186
|
+
if (callback({ className: entry[0], id: item })) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const entry of selectables.custom) {
|
|
192
|
+
if (callback(entry[1])) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
Selectables.some = some;
|
|
199
|
+
/**
|
|
200
|
+
* Iterate over all keys in a `Selectables` object.
|
|
201
|
+
* @param selectables `Selectables` object to iterate over
|
|
202
|
+
* @beta
|
|
203
|
+
*/
|
|
204
|
+
function forEach(selectables, callback) {
|
|
205
|
+
let index = 0;
|
|
206
|
+
selectables.instanceKeys.forEach((ids, className) => {
|
|
207
|
+
ids.forEach((id) => callback({ className, id }, index++));
|
|
208
|
+
});
|
|
209
|
+
selectables.custom.forEach((data) => {
|
|
210
|
+
callback(data, index++);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
Selectables.forEach = forEach;
|
|
214
|
+
function normalizeClassName(className) {
|
|
215
|
+
return className.replace(".", ":");
|
|
216
|
+
}
|
|
217
|
+
})(Selectables || (Selectables = {}));
|
|
218
|
+
//# sourceMappingURL=Selectable.js.map
|