@itwin/unified-selection 1.8.2 → 2.0.0-alpha.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +1 -1
  3. package/lib/{cjs/unified-selection → unified-selection}/CachingHiliteSetProvider.d.ts +3 -3
  4. package/lib/unified-selection/CachingHiliteSetProvider.d.ts.map +1 -0
  5. package/lib/unified-selection/CachingHiliteSetProvider.js.map +1 -0
  6. package/lib/unified-selection/DisposePolyfill.d.ts.map +1 -0
  7. package/lib/unified-selection/DisposePolyfill.js.map +1 -0
  8. package/lib/{cjs/unified-selection → unified-selection}/EnableUnifiedSelectionSyncWithIModel.d.ts +7 -7
  9. package/lib/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +1 -0
  10. package/lib/{esm/unified-selection → unified-selection}/EnableUnifiedSelectionSyncWithIModel.js +1 -1
  11. package/lib/unified-selection/EnableUnifiedSelectionSyncWithIModel.js.map +1 -0
  12. package/lib/{cjs/unified-selection → unified-selection}/HiliteSetProvider.d.ts +3 -3
  13. package/lib/unified-selection/HiliteSetProvider.d.ts.map +1 -0
  14. package/lib/{esm/unified-selection → unified-selection}/HiliteSetProvider.js +2 -2
  15. package/lib/unified-selection/HiliteSetProvider.js.map +1 -0
  16. package/lib/{esm/unified-selection → unified-selection}/IModelHiliteSetProvider.d.ts +4 -3
  17. package/lib/unified-selection/IModelHiliteSetProvider.d.ts.map +1 -0
  18. package/lib/unified-selection/IModelHiliteSetProvider.js.map +1 -0
  19. package/lib/{esm/unified-selection → unified-selection}/Selectable.d.ts +1 -1
  20. package/lib/unified-selection/Selectable.d.ts.map +1 -0
  21. package/lib/unified-selection/Selectable.js.map +1 -0
  22. package/lib/{cjs/unified-selection → unified-selection}/SelectionChangeEvent.d.ts +2 -2
  23. package/lib/unified-selection/SelectionChangeEvent.d.ts.map +1 -0
  24. package/lib/unified-selection/SelectionChangeEvent.js.map +1 -0
  25. package/lib/{cjs/unified-selection → unified-selection}/SelectionScope.d.ts +3 -3
  26. package/lib/unified-selection/SelectionScope.d.ts.map +1 -0
  27. package/lib/unified-selection/SelectionScope.js.map +1 -0
  28. package/lib/{esm/unified-selection → unified-selection}/SelectionStorage.d.ts +4 -3
  29. package/lib/unified-selection/SelectionStorage.d.ts.map +1 -0
  30. package/lib/unified-selection/SelectionStorage.js.map +1 -0
  31. package/lib/{esm/unified-selection → unified-selection}/Utils.d.ts +3 -3
  32. package/lib/unified-selection/Utils.d.ts.map +1 -0
  33. package/lib/{esm/unified-selection → unified-selection}/Utils.js +1 -1
  34. package/lib/unified-selection/Utils.js.map +1 -0
  35. package/lib/{esm/unified-selection → unified-selection}/types/IModel.d.ts +2 -2
  36. package/lib/unified-selection/types/IModel.d.ts.map +1 -0
  37. package/lib/unified-selection/types/IModel.js.map +1 -0
  38. package/lib/unified-selection.d.ts +16 -0
  39. package/lib/unified-selection.d.ts.map +1 -0
  40. package/lib/{esm/unified-selection.js → unified-selection.js} +2 -3
  41. package/lib/unified-selection.js.map +1 -0
  42. package/package.json +17 -19
  43. package/lib/cjs/package.json +0 -1
  44. package/lib/cjs/unified-selection/CachingHiliteSetProvider.d.ts.map +0 -1
  45. package/lib/cjs/unified-selection/CachingHiliteSetProvider.js +0 -27
  46. package/lib/cjs/unified-selection/CachingHiliteSetProvider.js.map +0 -1
  47. package/lib/cjs/unified-selection/DisposePolyfill.d.ts +0 -1
  48. package/lib/cjs/unified-selection/DisposePolyfill.d.ts.map +0 -1
  49. package/lib/cjs/unified-selection/DisposePolyfill.js +0 -11
  50. package/lib/cjs/unified-selection/DisposePolyfill.js.map +0 -1
  51. package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +0 -1
  52. package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.js +0 -392
  53. package/lib/cjs/unified-selection/EnableUnifiedSelectionSyncWithIModel.js.map +0 -1
  54. package/lib/cjs/unified-selection/HiliteSetProvider.d.ts.map +0 -1
  55. package/lib/cjs/unified-selection/HiliteSetProvider.js +0 -382
  56. package/lib/cjs/unified-selection/HiliteSetProvider.js.map +0 -1
  57. package/lib/cjs/unified-selection/IModelHiliteSetProvider.d.ts +0 -51
  58. package/lib/cjs/unified-selection/IModelHiliteSetProvider.d.ts.map +0 -1
  59. package/lib/cjs/unified-selection/IModelHiliteSetProvider.js +0 -66
  60. package/lib/cjs/unified-selection/IModelHiliteSetProvider.js.map +0 -1
  61. package/lib/cjs/unified-selection/Selectable.d.ts +0 -150
  62. package/lib/cjs/unified-selection/Selectable.d.ts.map +0 -1
  63. package/lib/cjs/unified-selection/Selectable.js +0 -238
  64. package/lib/cjs/unified-selection/Selectable.js.map +0 -1
  65. package/lib/cjs/unified-selection/SelectionChangeEvent.d.ts.map +0 -1
  66. package/lib/cjs/unified-selection/SelectionChangeEvent.js +0 -7
  67. package/lib/cjs/unified-selection/SelectionChangeEvent.js.map +0 -1
  68. package/lib/cjs/unified-selection/SelectionScope.d.ts.map +0 -1
  69. package/lib/cjs/unified-selection/SelectionScope.js +0 -252
  70. package/lib/cjs/unified-selection/SelectionScope.js.map +0 -1
  71. package/lib/cjs/unified-selection/SelectionStorage.d.ts +0 -105
  72. package/lib/cjs/unified-selection/SelectionStorage.d.ts.map +0 -1
  73. package/lib/cjs/unified-selection/SelectionStorage.js +0 -153
  74. package/lib/cjs/unified-selection/SelectionStorage.js.map +0 -1
  75. package/lib/cjs/unified-selection/Utils.d.ts +0 -39
  76. package/lib/cjs/unified-selection/Utils.d.ts.map +0 -1
  77. package/lib/cjs/unified-selection/Utils.js +0 -82
  78. package/lib/cjs/unified-selection/Utils.js.map +0 -1
  79. package/lib/cjs/unified-selection/types/IModel.d.ts +0 -133
  80. package/lib/cjs/unified-selection/types/IModel.d.ts.map +0 -1
  81. package/lib/cjs/unified-selection/types/IModel.js +0 -24
  82. package/lib/cjs/unified-selection/types/IModel.js.map +0 -1
  83. package/lib/cjs/unified-selection.d.ts +0 -10
  84. package/lib/cjs/unified-selection.d.ts.map +0 -1
  85. package/lib/cjs/unified-selection.js +0 -27
  86. package/lib/cjs/unified-selection.js.map +0 -1
  87. package/lib/esm/unified-selection/CachingHiliteSetProvider.d.ts +0 -56
  88. package/lib/esm/unified-selection/CachingHiliteSetProvider.d.ts.map +0 -1
  89. package/lib/esm/unified-selection/CachingHiliteSetProvider.js.map +0 -1
  90. package/lib/esm/unified-selection/DisposePolyfill.d.ts.map +0 -1
  91. package/lib/esm/unified-selection/DisposePolyfill.js.map +0 -1
  92. package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts +0 -119
  93. package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.d.ts.map +0 -1
  94. package/lib/esm/unified-selection/EnableUnifiedSelectionSyncWithIModel.js.map +0 -1
  95. package/lib/esm/unified-selection/HiliteSetProvider.d.ts +0 -48
  96. package/lib/esm/unified-selection/HiliteSetProvider.d.ts.map +0 -1
  97. package/lib/esm/unified-selection/HiliteSetProvider.js.map +0 -1
  98. package/lib/esm/unified-selection/IModelHiliteSetProvider.d.ts.map +0 -1
  99. package/lib/esm/unified-selection/IModelHiliteSetProvider.js.map +0 -1
  100. package/lib/esm/unified-selection/Selectable.d.ts.map +0 -1
  101. package/lib/esm/unified-selection/Selectable.js.map +0 -1
  102. package/lib/esm/unified-selection/SelectionChangeEvent.d.ts +0 -60
  103. package/lib/esm/unified-selection/SelectionChangeEvent.d.ts.map +0 -1
  104. package/lib/esm/unified-selection/SelectionChangeEvent.js.map +0 -1
  105. package/lib/esm/unified-selection/SelectionScope.d.ts +0 -54
  106. package/lib/esm/unified-selection/SelectionScope.d.ts.map +0 -1
  107. package/lib/esm/unified-selection/SelectionScope.js.map +0 -1
  108. package/lib/esm/unified-selection/SelectionStorage.d.ts.map +0 -1
  109. package/lib/esm/unified-selection/SelectionStorage.js.map +0 -1
  110. package/lib/esm/unified-selection/Utils.d.ts.map +0 -1
  111. package/lib/esm/unified-selection/Utils.js.map +0 -1
  112. package/lib/esm/unified-selection/types/IModel.d.ts.map +0 -1
  113. package/lib/esm/unified-selection/types/IModel.js.map +0 -1
  114. package/lib/esm/unified-selection.d.ts +0 -10
  115. package/lib/esm/unified-selection.d.ts.map +0 -1
  116. package/lib/esm/unified-selection.js.map +0 -1
  117. /package/lib/{esm/unified-selection → unified-selection}/CachingHiliteSetProvider.js +0 -0
  118. /package/lib/{esm/unified-selection → unified-selection}/DisposePolyfill.d.ts +0 -0
  119. /package/lib/{esm/unified-selection → unified-selection}/DisposePolyfill.js +0 -0
  120. /package/lib/{esm/unified-selection → unified-selection}/IModelHiliteSetProvider.js +0 -0
  121. /package/lib/{esm/unified-selection → unified-selection}/Selectable.js +0 -0
  122. /package/lib/{esm/unified-selection → unified-selection}/SelectionChangeEvent.js +0 -0
  123. /package/lib/{esm/unified-selection → unified-selection}/SelectionScope.js +0 -0
  124. /package/lib/{esm/unified-selection → unified-selection}/SelectionStorage.js +0 -0
  125. /package/lib/{esm/unified-selection → unified-selection}/types/IModel.js +0 -0
@@ -1,252 +0,0 @@
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.computeSelection = computeSelection;
8
- const core_bentley_1 = require("@itwin/core-bentley");
9
- const Selectable_js_1 = require("./Selectable.js");
10
- const Utils_js_1 = require("./Utils.js");
11
- /**
12
- * Computes selection from given element IDs.
13
- * @public
14
- */
15
- async function* computeSelection(props) {
16
- const { queryExecutor, elementIds, scope } = props;
17
- const componentId = props.componentId ?? core_bentley_1.Guid.createValue();
18
- const componentName = "computeSelection";
19
- if (typeof scope === "string") {
20
- yield* computeSelection({ queryExecutor, elementIds, scope: { id: scope }, componentId });
21
- return;
22
- }
23
- const { persistent: persistentIds, transient: transientIds } = parseElementIds(elementIds);
24
- for (const id of transientIds) {
25
- yield { id, className: Selectable_js_1.TRANSIENT_ELEMENT_CLASSNAME };
26
- }
27
- switch (scope.id) {
28
- case "element":
29
- yield* computeElementSelection(queryExecutor, persistentIds, scope.ancestorLevel ?? 0, componentId, componentName);
30
- return;
31
- case "category":
32
- yield* computeCategorySelection(queryExecutor, persistentIds, componentId, componentName);
33
- return;
34
- case "model":
35
- yield* computeModelSelection(queryExecutor, persistentIds, componentId, componentName);
36
- return;
37
- case "functional":
38
- yield* computeFunctionalElementSelection(queryExecutor, persistentIds, scope.ancestorLevel ?? 0, componentId, componentName);
39
- return;
40
- }
41
- }
42
- async function* computeElementSelection(queryExecutor, ids, ancestorLevel, componentId, componentName) {
43
- const bindings = [];
44
- const recurseUntilRoot = ancestorLevel < 0;
45
- const ctes = [
46
- `
47
- AncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (
48
- SELECT ECInstanceId, ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, Parent.Id
49
- FROM BisCore.Element
50
- WHERE ${(0, Utils_js_1.formIdBindings)("ECInstanceId", ids, bindings)}
51
- UNION ALL
52
- SELECT pe.ECInstanceId, pe.ECClassId, a.Depth - 1, pe.Parent.Id
53
- FROM AncestorElements a
54
- JOIN BisCore.Element pe ON pe.ECInstanceId = a.ParentId
55
- WHERE ${recurseUntilRoot ? "" : "Depth > 0 AND"} ParentId IS NOT NULL
56
- )
57
- `,
58
- ];
59
- const ecsql = `
60
- SELECT DISTINCT ECInstanceId, ec_classname(ECClassId, 's.c') AS ClassName
61
- FROM AncestorElements
62
- WHERE ${recurseUntilRoot ? "" : "Depth = 0 OR"} ParentId IS NULL
63
- `;
64
- yield* executeQuery({
65
- queryExecutor,
66
- query: { ctes, ecsql, bindings },
67
- config: { restartToken: `${componentName}/${componentId}/element/${core_bentley_1.Guid.createValue()}` },
68
- });
69
- }
70
- async function* computeCategorySelection(queryExecutor, ids, componentId, componentName) {
71
- const bindings = [];
72
- const ecsql = [
73
- `
74
- SELECT DISTINCT c.ECInstanceId, ec_classname(c.ECClassId, 's.c') AS ClassName
75
- FROM BisCore.Category c
76
- JOIN BisCore.GeometricElement2d ge ON ge.Category.Id = c.ECInstanceId
77
- WHERE ${(0, Utils_js_1.formIdBindings)("ge.ECInstanceId", ids, bindings)}
78
- `,
79
- `
80
- SELECT DISTINCT c.ECInstanceId, ec_classname(c.ECClassId, 's.c') AS ClassName
81
- FROM BisCore.Category c
82
- JOIN BisCore.GeometricElement3d ge ON ge.Category.Id = c.ECInstanceId
83
- WHERE ${(0, Utils_js_1.formIdBindings)("ge.ECInstanceId", ids, bindings)}
84
- `,
85
- ].join(" UNION ALL ");
86
- yield* executeQuery({
87
- queryExecutor,
88
- query: { ecsql, bindings },
89
- config: { restartToken: `${componentName}/${componentId}/category/${core_bentley_1.Guid.createValue()}` },
90
- });
91
- }
92
- async function* computeModelSelection(queryExecutor, ids, componentId, componentName) {
93
- const bindings = [];
94
- const ecsql = `
95
- SELECT DISTINCT m.ECInstanceId, ec_classname(m.ECClassId, 's.c') AS ClassName
96
- FROM BisCore.Model m
97
- JOIN BisCore.Element e ON e.Model.Id = m.ECInstanceId
98
- WHERE ${(0, Utils_js_1.formIdBindings)("e.ECInstanceId", ids, bindings)}
99
- `;
100
- yield* executeQuery({
101
- queryExecutor,
102
- query: { ecsql, bindings },
103
- config: { restartToken: `${componentName}/${componentId}/model/${core_bentley_1.Guid.createValue()}` },
104
- });
105
- }
106
- async function* computeFunctionalElementSelection(queryExecutor, ids, ancestorLevel, componentId, componentName) {
107
- const bindings = [];
108
- const recurseUntilRoot = ancestorLevel < 0;
109
- // cspell:disable
110
- const ctes = [
111
- `
112
- Elements2dOrNearestFunctionalElements(OriginalECInstanceId, OriginalECClassId, ECInstanceId, ECClassId, ParentId) AS (
113
- SELECT ECInstanceId, ECClassId, ECInstanceId, ECClassId, Parent.Id
114
- FROM BisCore.Element
115
- WHERE ${(0, Utils_js_1.formIdBindings)("ECInstanceId", ids, bindings)} AND ECClassId IS NOT (BisCore.GeometricElement3d)
116
- UNION ALL
117
- SELECT
118
- e2onfe.OriginalECInstanceId,
119
- e2onfe.OriginalECClassId,
120
- COALESCE(dgrfe.TargetECInstanceId, pe.ECInstanceId),
121
- COALESCE(dgrfe.TargetECClassId, pe.ECClassId),
122
- pe.Parent.Id
123
- FROM Elements2dOrNearestFunctionalElements e2onfe
124
- LEFT JOIN BisCore.Element pe ON pe.ECInstanceId = e2onfe.ParentId
125
- LEFT JOIN Functional.DrawingGraphicRepresentsFunctionalElement dgrfe ON dgrfe.SourceECInstanceId = e2onfe.ECInstanceId
126
- WHERE e2onfe.ECClassId IS NOT (Functional.FunctionalElement) AND (e2onfe.ParentId IS NOT NULL OR dgrfe.TargetECInstanceId IS NOT NULL)
127
- )
128
- `,
129
- `
130
- Element2dNearestFunctionalElements(OriginalECInstanceId, ECInstanceId, ECClassId) AS (
131
- SELECT OriginalECInstanceId, ECInstanceId, ECClassId
132
- FROM Elements2dOrNearestFunctionalElements
133
- WHERE ECClassId IS (Functional.FunctionalElement)
134
- )
135
- `,
136
- `
137
- Elements2dWithoutFunctionalElement(ECInstanceId, ECClassId) AS (
138
- SELECT e2wfe.OriginalECInstanceId, OriginalECClassId
139
- FROM Elements2dOrNearestFunctionalElements e2wfe
140
- LEFT JOIN Element2dNearestFunctionalElements e2nfe ON e2nfe.OriginalECInstanceId = e2wfe.OriginalECInstanceId
141
- WHERE e2wfe.ParentId IS NULL AND e2nfe.ECInstanceId IS NULL
142
- )
143
- `,
144
- `
145
- Elements2d(ECInstanceId, ECClassId) AS (
146
- SELECT ECInstanceId, ECClassId FROM Element2dNearestFunctionalElements
147
- UNION
148
- SELECT ECInstanceId, ECClassId FROM Elements2dWithoutFunctionalElement
149
- )
150
- `,
151
- `
152
- Element2dAncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (
153
- SELECT e.ECInstanceId, e.ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, e.Parent.Id
154
- FROM BisCore.Element e
155
- JOIN Elements2d e2d ON e2d.ECInstanceId = e.ECInstanceId
156
- UNION ALL
157
- SELECT pe.ECInstanceId, pe.ECClassId, e2ae.Depth - 1, pe.Parent.Id
158
- FROM Element2dAncestorElements e2ae
159
- JOIN BisCore.Element pe ON pe.ECInstanceId = e2ae.ParentId
160
- WHERE ${recurseUntilRoot ? "" : "Depth > 0 AND"} ParentId IS NOT NULL
161
- )
162
- `,
163
- `
164
- Element3dAncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (
165
- SELECT ge.ECInstanceId, ge.ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, ge.Parent.Id
166
- FROM BisCore.GeometricElement3d ge
167
- WHERE ${(0, Utils_js_1.formIdBindings)("ge.ECInstanceId", ids, bindings)}
168
- UNION ALL
169
- SELECT pe.ECInstanceId, pe.ECClassId, e3ae.Depth - 1, pe.Parent.Id
170
- FROM Element3dAncestorElements e3ae
171
- JOIN BisCore.Element pe ON pe.ECInstanceId = e3ae.ParentId
172
- WHERE ${recurseUntilRoot ? "" : "Depth > 0 AND"} ParentId IS NOT NULL
173
- )
174
- `,
175
- `
176
- Element3dAncestorRelatedFunctionalElement(ECInstanceId, ClassName) AS (
177
- SELECT
178
- COALESCE(peff.TargetECInstanceId, e3ae.ECInstanceId),
179
- ec_classname(COALESCE(peff.TargetECClassId, e3ae.ECClassId), 's.c')
180
- FROM Element3dAncestorElements e3ae
181
- LEFT JOIN Functional.PhysicalElementFulfillsFunction peff ON peff.SourceECInstanceId = e3ae.ECInstanceId
182
- WHERE ${recurseUntilRoot ? "" : "e3ae.Depth = 0 OR"} e3ae.ParentId IS NULL
183
- )
184
- `,
185
- ];
186
- const ecsql = [
187
- `
188
- SELECT DISTINCT ECInstanceId, ec_classname(ECClassId, 's.c') AS ClassName
189
- FROM Element2dAncestorElements
190
- WHERE ${recurseUntilRoot ? "" : "Depth = 0 OR"} ParentId IS NULL
191
- `,
192
- `
193
- SELECT DISTINCT ECInstanceId, ClassName FROM Element3dAncestorRelatedFunctionalElement
194
- `,
195
- ].join(" UNION ");
196
- // cspell:enable
197
- yield* executeQuery({
198
- queryExecutor,
199
- query: { ctes, ecsql, bindings },
200
- config: { restartToken: `${componentName}/${componentId}/functional-element/${core_bentley_1.Guid.createValue()}` },
201
- });
202
- }
203
- function formAncestorLevelBinding(ancestorLevel, bindings) {
204
- bindings.push({ type: "int", value: ancestorLevel });
205
- return "?";
206
- }
207
- async function* executeQuery(props) {
208
- yield* (0, Utils_js_1.genericExecuteQuery)({
209
- ...props,
210
- parseQueryRow: (row) => ({ className: row.ClassName, id: row.ECInstanceId }),
211
- });
212
- }
213
- function parseElementIds(ids) {
214
- if (typeof ids === "string") {
215
- ids = [ids];
216
- }
217
- // detect if all ids are either transient or persistent to avoid unnecessary copying
218
- let allPersistent = true;
219
- let allTransient = true;
220
- for (const id of ids) {
221
- if (core_bentley_1.Id64.isTransient(id)) {
222
- allPersistent = false;
223
- }
224
- else {
225
- allTransient = false;
226
- }
227
- if (!allPersistent && !allTransient) {
228
- break;
229
- }
230
- }
231
- // avoid making a copy if ids are only persistent or only transient
232
- if (allPersistent) {
233
- return { persistent: ids, transient: [] };
234
- }
235
- else if (allTransient) {
236
- return { persistent: [], transient: ids };
237
- }
238
- // if `ids` contain mixed ids, we have to copy.. use Array instead of
239
- // a Set for performance
240
- const persistentElementIds = [];
241
- const transientElementIds = [];
242
- for (const id of ids) {
243
- if (core_bentley_1.Id64.isTransient(id)) {
244
- transientElementIds.push(id);
245
- }
246
- else {
247
- persistentElementIds.push(id);
248
- }
249
- }
250
- return { persistent: persistentElementIds, transient: transientElementIds };
251
- }
252
- //# sourceMappingURL=SelectionScope.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectionScope.js","sourceRoot":"","sources":["../../../src/unified-selection/SelectionScope.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AA+DhG,4CAyCC;AAtGD,sDAA8E;AAQ9E,mDAAqF;AACrF,yCA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,CAAC;IACd,CAAC;IAED,oFAAoF;IACpF,IAAI,aAAa,GAAG,IAAI,CAAC;IACzB,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,mBAAI,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC;YACzB,aAAa,GAAG,KAAK,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;QAED,IAAI,CAAC,aAAa,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,MAAM;QACR,CAAC;IACH,CAAC;IAED,mEAAmE;IACnE,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;IAC5C,CAAC;SAAM,IAAI,YAAY,EAAE,CAAC;QACxB,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;IAC5C,CAAC;IAED,qEAAqE;IACrE,wBAAwB;IACxB,MAAM,oBAAoB,GAAc,EAAE,CAAC;IAC3C,MAAM,mBAAmB,GAAc,EAAE,CAAC;IAC1C,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,mBAAI,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC;YACzB,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC;AAC9E,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { Guid, Id64, Id64Arg, Id64Array, Id64Set } from \"@itwin/core-bentley\";\nimport {\n ECSqlBinding,\n ECSqlQueryDef,\n ECSqlQueryExecutor,\n ECSqlQueryReaderOptions,\n ECSqlQueryRow,\n} from \"@itwin/presentation-shared\";\nimport { SelectableInstanceKey, TRANSIENT_ELEMENT_CLASSNAME } from \"./Selectable.js\";\nimport { formIdBindings, genericExecuteQuery } from \"./Utils.js\";\n\n/**\n * Available selection scopes.\n * @public\n */\ntype SelectionScopeIdentifier = \"element\" | \"model\" | \"category\" | \"functional\";\n\n/**\n * Props for computing element selection.\n * @public\n */\nexport interface ElementSelectionScopeProps {\n /** Identifies this as either \"element\" or \"functional\" selection scope */\n id: \"element\" | \"functional\";\n /**\n * Specifies how far \"up\" we should walk to find the target element. When not specified or `0`,\n * the target element matches the request element. When set to `1`, the target element matches the direct parent element.\n * When set to `2`, the target element is parent of the parent element and so on. In all situations when this is `> 0`,\n * we're not walking further than the last existing element, for example when `ancestorLevel = 1` (direct parent\n * element is requested), but the request element doesn't have a parent, the request element is returned as the result.\n * A negative value would result in the top-most element to be returned.\n */\n ancestorLevel?: number;\n}\n\n/**\n * A union of types that can be used to define a selection scope.\n * @public\n * @since 1.4.0\n */\nexport type SelectionScope = ElementSelectionScopeProps | { id: SelectionScopeIdentifier } | SelectionScopeIdentifier;\n\n/**\n * Props for `computeSelection`.\n * @public\n */\nexport interface ComputeSelectionProps {\n /** iModel query executor. */\n queryExecutor: ECSqlQueryExecutor;\n /** IDs of elements to compute selection for. */\n elementIds: Id64Arg;\n /** Selection scope to compute selection with. */\n scope: SelectionScope;\n /** Optional unique id of the component that consumes this function. It can be any string, as long as it is not shared across different components. */\n componentId?: string;\n}\n\n/**\n * Computes selection from given element IDs.\n * @public\n */\nexport async function* computeSelection(props: ComputeSelectionProps): AsyncIterableIterator<SelectableInstanceKey> {\n const { queryExecutor, elementIds, scope } = props;\n const componentId = props.componentId ?? Guid.createValue();\n const componentName = \"computeSelection\";\n if (typeof scope === \"string\") {\n yield* computeSelection({ queryExecutor, elementIds, scope: { id: scope }, componentId });\n return;\n }\n\n const { persistent: persistentIds, transient: transientIds } = parseElementIds(elementIds);\n\n for (const id of transientIds) {\n yield { id, className: TRANSIENT_ELEMENT_CLASSNAME };\n }\n\n switch (scope.id) {\n case \"element\":\n yield* computeElementSelection(\n queryExecutor,\n persistentIds,\n (scope as ElementSelectionScopeProps).ancestorLevel ?? 0,\n componentId,\n componentName,\n );\n return;\n case \"category\":\n yield* computeCategorySelection(queryExecutor, persistentIds, componentId, componentName);\n return;\n case \"model\":\n yield* computeModelSelection(queryExecutor, persistentIds, componentId, componentName);\n return;\n case \"functional\":\n yield* computeFunctionalElementSelection(\n queryExecutor,\n persistentIds,\n (scope as ElementSelectionScopeProps).ancestorLevel ?? 0,\n componentId,\n componentName,\n );\n return;\n }\n}\n\nasync function* computeElementSelection(\n queryExecutor: ECSqlQueryExecutor,\n ids: Id64Array | Id64Set,\n ancestorLevel: number,\n componentId: string,\n componentName: string,\n): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const recurseUntilRoot = ancestorLevel < 0;\n const ctes = [\n `\n AncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT ECInstanceId, ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, Parent.Id\n FROM BisCore.Element\n WHERE ${formIdBindings(\"ECInstanceId\", ids, bindings)}\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, a.Depth - 1, pe.Parent.Id\n FROM AncestorElements a\n JOIN BisCore.Element pe ON pe.ECInstanceId = a.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n ];\n const ecsql = `\n SELECT DISTINCT ECInstanceId, ec_classname(ECClassId, 's.c') AS ClassName\n FROM AncestorElements\n WHERE ${recurseUntilRoot ? \"\" : \"Depth = 0 OR\"} ParentId IS NULL\n `;\n yield* executeQuery({\n queryExecutor,\n query: { ctes, ecsql, bindings },\n config: { restartToken: `${componentName}/${componentId}/element/${Guid.createValue()}` },\n });\n}\n\nasync function* computeCategorySelection(\n queryExecutor: ECSqlQueryExecutor,\n ids: Id64Array | Id64Set,\n componentId: string,\n componentName: string,\n): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const ecsql = [\n `\n SELECT DISTINCT c.ECInstanceId, ec_classname(c.ECClassId, 's.c') AS ClassName\n FROM BisCore.Category c\n JOIN BisCore.GeometricElement2d ge ON ge.Category.Id = c.ECInstanceId\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n `,\n `\n SELECT DISTINCT c.ECInstanceId, ec_classname(c.ECClassId, 's.c') AS ClassName\n FROM BisCore.Category c\n JOIN BisCore.GeometricElement3d ge ON ge.Category.Id = c.ECInstanceId\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n `,\n ].join(\" UNION ALL \");\n yield* executeQuery({\n queryExecutor,\n query: { ecsql, bindings },\n config: { restartToken: `${componentName}/${componentId}/category/${Guid.createValue()}` },\n });\n}\n\nasync function* computeModelSelection(\n queryExecutor: ECSqlQueryExecutor,\n ids: Id64Array | Id64Set,\n componentId: string,\n componentName: string,\n): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const ecsql = `\n SELECT DISTINCT m.ECInstanceId, ec_classname(m.ECClassId, 's.c') AS ClassName\n FROM BisCore.Model m\n JOIN BisCore.Element e ON e.Model.Id = m.ECInstanceId\n WHERE ${formIdBindings(\"e.ECInstanceId\", ids, bindings)}\n `;\n yield* executeQuery({\n queryExecutor,\n query: { ecsql, bindings },\n config: { restartToken: `${componentName}/${componentId}/model/${Guid.createValue()}` },\n });\n}\n\nasync function* computeFunctionalElementSelection(\n queryExecutor: ECSqlQueryExecutor,\n ids: Id64Array | Id64Set,\n ancestorLevel: number,\n componentId: string,\n componentName: string,\n): AsyncIterableIterator<SelectableInstanceKey> {\n const bindings: ECSqlBinding[] = [];\n const recurseUntilRoot = ancestorLevel < 0;\n // cspell:disable\n const ctes = [\n `\n Elements2dOrNearestFunctionalElements(OriginalECInstanceId, OriginalECClassId, ECInstanceId, ECClassId, ParentId) AS (\n SELECT ECInstanceId, ECClassId, ECInstanceId, ECClassId, Parent.Id\n FROM BisCore.Element\n WHERE ${formIdBindings(\"ECInstanceId\", ids, bindings)} AND ECClassId IS NOT (BisCore.GeometricElement3d)\n UNION ALL\n SELECT\n e2onfe.OriginalECInstanceId,\n e2onfe.OriginalECClassId,\n COALESCE(dgrfe.TargetECInstanceId, pe.ECInstanceId),\n COALESCE(dgrfe.TargetECClassId, pe.ECClassId),\n pe.Parent.Id\n FROM Elements2dOrNearestFunctionalElements e2onfe\n LEFT JOIN BisCore.Element pe ON pe.ECInstanceId = e2onfe.ParentId\n LEFT JOIN Functional.DrawingGraphicRepresentsFunctionalElement dgrfe ON dgrfe.SourceECInstanceId = e2onfe.ECInstanceId\n WHERE e2onfe.ECClassId IS NOT (Functional.FunctionalElement) AND (e2onfe.ParentId IS NOT NULL OR dgrfe.TargetECInstanceId IS NOT NULL)\n )\n `,\n `\n Element2dNearestFunctionalElements(OriginalECInstanceId, ECInstanceId, ECClassId) AS (\n SELECT OriginalECInstanceId, ECInstanceId, ECClassId\n FROM Elements2dOrNearestFunctionalElements\n WHERE ECClassId IS (Functional.FunctionalElement)\n )\n `,\n `\n Elements2dWithoutFunctionalElement(ECInstanceId, ECClassId) AS (\n SELECT e2wfe.OriginalECInstanceId, OriginalECClassId\n FROM Elements2dOrNearestFunctionalElements e2wfe\n LEFT JOIN Element2dNearestFunctionalElements e2nfe ON e2nfe.OriginalECInstanceId = e2wfe.OriginalECInstanceId\n WHERE e2wfe.ParentId IS NULL AND e2nfe.ECInstanceId IS NULL\n )\n `,\n `\n Elements2d(ECInstanceId, ECClassId) AS (\n SELECT ECInstanceId, ECClassId FROM Element2dNearestFunctionalElements\n UNION\n SELECT ECInstanceId, ECClassId FROM Elements2dWithoutFunctionalElement\n )\n `,\n `\n Element2dAncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT e.ECInstanceId, e.ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, e.Parent.Id\n FROM BisCore.Element e\n JOIN Elements2d e2d ON e2d.ECInstanceId = e.ECInstanceId\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, e2ae.Depth - 1, pe.Parent.Id\n FROM Element2dAncestorElements e2ae\n JOIN BisCore.Element pe ON pe.ECInstanceId = e2ae.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n `\n Element3dAncestorElements(ECInstanceId, ECClassId, Depth, ParentId) AS (\n SELECT ge.ECInstanceId, ge.ECClassId, ${formAncestorLevelBinding(ancestorLevel, bindings)}, ge.Parent.Id\n FROM BisCore.GeometricElement3d ge\n WHERE ${formIdBindings(\"ge.ECInstanceId\", ids, bindings)}\n UNION ALL\n SELECT pe.ECInstanceId, pe.ECClassId, e3ae.Depth - 1, pe.Parent.Id\n FROM Element3dAncestorElements e3ae\n JOIN BisCore.Element pe ON pe.ECInstanceId = e3ae.ParentId\n WHERE ${recurseUntilRoot ? \"\" : \"Depth > 0 AND\"} ParentId IS NOT NULL\n )\n `,\n `\n Element3dAncestorRelatedFunctionalElement(ECInstanceId, ClassName) AS (\n SELECT\n COALESCE(peff.TargetECInstanceId, e3ae.ECInstanceId),\n ec_classname(COALESCE(peff.TargetECClassId, e3ae.ECClassId), 's.c')\n FROM Element3dAncestorElements e3ae\n LEFT JOIN Functional.PhysicalElementFulfillsFunction peff ON peff.SourceECInstanceId = e3ae.ECInstanceId\n WHERE ${recurseUntilRoot ? \"\" : \"e3ae.Depth = 0 OR\"} e3ae.ParentId IS NULL\n )\n `,\n ];\n const ecsql = [\n `\n SELECT DISTINCT ECInstanceId, ec_classname(ECClassId, 's.c') AS ClassName\n FROM Element2dAncestorElements\n WHERE ${recurseUntilRoot ? \"\" : \"Depth = 0 OR\"} ParentId IS NULL\n `,\n `\n SELECT DISTINCT ECInstanceId, ClassName FROM Element3dAncestorRelatedFunctionalElement\n `,\n ].join(\" UNION \");\n // cspell:enable\n yield* executeQuery({\n queryExecutor,\n query: { ctes, ecsql, bindings },\n config: { restartToken: `${componentName}/${componentId}/functional-element/${Guid.createValue()}` },\n });\n}\n\nfunction formAncestorLevelBinding(ancestorLevel: number, bindings: ECSqlBinding[]) {\n bindings.push({ type: \"int\", value: ancestorLevel });\n return \"?\";\n}\n\nasync function* executeQuery(props: {\n queryExecutor: ECSqlQueryExecutor;\n query: ECSqlQueryDef;\n config?: ECSqlQueryReaderOptions;\n}): AsyncIterableIterator<SelectableInstanceKey> {\n yield* genericExecuteQuery({\n ...props,\n parseQueryRow: (row: ECSqlQueryRow) => ({ className: row.ClassName, id: row.ECInstanceId }),\n });\n}\n\nfunction parseElementIds(ids: Id64Arg): { persistent: Id64Set | Id64Array; transient: Id64Set | Id64Array } {\n if (typeof ids === \"string\") {\n ids = [ids];\n }\n\n // detect if all ids are either transient or persistent to avoid unnecessary copying\n let allPersistent = true;\n let allTransient = true;\n for (const id of ids) {\n if (Id64.isTransient(id)) {\n allPersistent = false;\n } else {\n allTransient = false;\n }\n\n if (!allPersistent && !allTransient) {\n break;\n }\n }\n\n // avoid making a copy if ids are only persistent or only transient\n if (allPersistent) {\n return { persistent: ids, transient: [] };\n } else if (allTransient) {\n return { persistent: [], transient: ids };\n }\n\n // if `ids` contain mixed ids, we have to copy.. use Array instead of\n // a Set for performance\n const persistentElementIds: Id64Array = [];\n const transientElementIds: Id64Array = [];\n for (const id of ids) {\n if (Id64.isTransient(id)) {\n transientElementIds.push(id);\n } else {\n persistentElementIds.push(id);\n }\n }\n\n return { persistent: persistentElementIds, transient: transientElementIds };\n}\n"]}
@@ -1,105 +0,0 @@
1
- import { Event } from "@itwin/presentation-shared";
2
- import { Selectable, Selectables } from "./Selectable.js";
3
- import { StorageSelectionChangesListener } from "./SelectionChangeEvent.js";
4
- /** @public */
5
- type IModelKeyProp = {
6
- /**
7
- * Key of the iModel. It's recommended to use `createIModelKey` function from `@itwin/presentation-core-interop`
8
- * package to create the key for an iModel.
9
- *
10
- * Defaults to an empty string when not supplied.
11
- */
12
- imodelKey?: string;
13
- iModelKey?: never;
14
- } | {
15
- imodelKey?: never;
16
- /**
17
- * Key of the iModel. It's recommended to use `createIModelKey` function from `@itwin/presentation-core-interop`
18
- * package to create the key for an iModel.
19
- *
20
- * Defaults to an empty string when not supplied.
21
- *
22
- * @deprecated in 0.2. Use `imodelKey` instead.
23
- */
24
- iModelKey?: string;
25
- };
26
- /**
27
- * Defines return value of `createStorage`.
28
- *
29
- * **Warning:** Used in public API as a return value. Not expected to be created / extended by package
30
- * consumers, may be supplemented with required attributes any time.
31
- *
32
- * @see `createStorage`
33
- * @public
34
- */
35
- export interface SelectionStorage {
36
- /** An event that is raised when selection changes. */
37
- selectionChangeEvent: Event<StorageSelectionChangesListener>;
38
- /** Get the selection levels currently stored for the specified iModel. */
39
- getSelectionLevels(props: IModelKeyProp): number[];
40
- /** Get the selection stored in the storage. */
41
- getSelection(props: IModelKeyProp & {
42
- /** Level of the selection. Defaults to `0`. */
43
- level?: number;
44
- }): Selectables;
45
- /** Add keys to the selection. */
46
- addToSelection(props: IModelKeyProp & {
47
- /** Name of the selection source. Generally, this identifies the component that makes the selection change. */
48
- source: string;
49
- /** The selectables to add to selection. */
50
- selectables: Selectable[];
51
- /** Level of the selection. Defaults to `0`. */
52
- level?: number;
53
- }): void;
54
- /** Remove keys from current selection. */
55
- removeFromSelection(props: IModelKeyProp & {
56
- /** Name of the selection source. Generally, this identifies the component that makes the selection change. */
57
- source: string;
58
- /** The selectables to remove from selection. */
59
- selectables: Selectable[];
60
- /** Level of the selection. Defaults to `0`. */
61
- level?: number;
62
- }): void;
63
- /** Replace current selection. */
64
- replaceSelection(props: IModelKeyProp & {
65
- /** Name of the selection source. Generally, this identifies the component that makes the selection change. */
66
- source: string;
67
- /** The selectables to add to selection. */
68
- selectables: Selectable[];
69
- /** Level of the selection. Defaults to `0`. */
70
- level?: number;
71
- }): void;
72
- /** Clear current selection. */
73
- clearSelection(props: IModelKeyProp & {
74
- /** Name of the selection source. Generally, this identifies the component that makes the selection change. */
75
- source: string;
76
- /** Level of the selection. Defaults to `0`. */
77
- level?: number;
78
- }): void;
79
- /** Clear storage for an iModel. This function should be called when iModel is closed. */
80
- clearStorage(props: IModelKeyProp): void;
81
- }
82
- /**
83
- * Creates a selection storage which stores and allows managing application-level selection.
84
- *
85
- * **Note:** `clearSelection` should be called upon iModel close to free-up memory:
86
- *
87
- * ```ts
88
- * import { IModelConnection } from "@itwin/core-frontend";
89
- * import { createIModelKey } from "@itwin/presentation-core-interop";
90
- *
91
- * IModelConnection.onClose.addListener((imodel) => {
92
- * storage.clearStorage(createIModelKey(imodel));
93
- * });
94
- * ```
95
- *
96
- * @public
97
- */
98
- export declare function createStorage(): SelectionStorage;
99
- /**
100
- * The source name used when selection change is caused by clearing the selection storage. Used when change is performed by `clearStorage`.
101
- * @public
102
- */
103
- export declare const CLEAR_SELECTION_STORAGE_SOURCE = "Unified selection storage: clear";
104
- export {};
105
- //# sourceMappingURL=SelectionStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectionStorage.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/SelectionStorage.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAEL,+BAA+B,EAEhC,MAAM,2BAA2B,CAAC;AAEnC,cAAc;AACd,KAAK,aAAa,GACd;IACE;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB,GACD;IACE,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB;;;;;;;OAOG;I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C;IAER,yFAAyF;IACzF,YAAY,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,IAAI,gBAAgB,CAEhD;AAED;;;GAGG;AACH,eAAO,MAAM,8BAA8B,qCAAqC,CAAC"}
@@ -1,153 +0,0 @@
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.CLEAR_SELECTION_STORAGE_SOURCE = void 0;
8
- exports.createStorage = createStorage;
9
- const core_bentley_1 = require("@itwin/core-bentley");
10
- const Selectable_js_1 = require("./Selectable.js");
11
- /**
12
- * Creates a selection storage which stores and allows managing application-level selection.
13
- *
14
- * **Note:** `clearSelection` should be called upon iModel close to free-up memory:
15
- *
16
- * ```ts
17
- * import { IModelConnection } from "@itwin/core-frontend";
18
- * import { createIModelKey } from "@itwin/presentation-core-interop";
19
- *
20
- * IModelConnection.onClose.addListener((imodel) => {
21
- * storage.clearStorage(createIModelKey(imodel));
22
- * });
23
- * ```
24
- *
25
- * @public
26
- */
27
- function createStorage() {
28
- return new SelectionStorageImpl();
29
- }
30
- /**
31
- * The source name used when selection change is caused by clearing the selection storage. Used when change is performed by `clearStorage`.
32
- * @public
33
- */
34
- exports.CLEAR_SELECTION_STORAGE_SOURCE = "Unified selection storage: clear";
35
- class SelectionStorageImpl {
36
- _storage = new Map();
37
- selectionChangeEvent;
38
- constructor() {
39
- this.selectionChangeEvent = new core_bentley_1.BeEvent();
40
- }
41
- getSelectionLevels(props) {
42
- return this.getContainer(getIModelKey(props)).getSelectionLevels();
43
- }
44
- getSelection(props) {
45
- return this.getContainer(getIModelKey(props)).getSelection(props.level ?? 0);
46
- }
47
- addToSelection(props) {
48
- this.handleChange({ ...props, changeType: "add" });
49
- }
50
- removeFromSelection(props) {
51
- this.handleChange({ ...props, changeType: "remove" });
52
- }
53
- replaceSelection(props) {
54
- this.handleChange({ ...props, changeType: "replace" });
55
- }
56
- clearSelection(props) {
57
- this.handleChange({ ...props, changeType: "clear", selectables: [] });
58
- }
59
- clearStorage(props) {
60
- const imodelKey = getIModelKey(props);
61
- this.clearSelection({ source: exports.CLEAR_SELECTION_STORAGE_SOURCE, imodelKey });
62
- this._storage.delete(imodelKey);
63
- }
64
- getContainer(imodelKey) {
65
- let selectionContainer = this._storage.get(imodelKey);
66
- if (!selectionContainer) {
67
- selectionContainer = new MultiLevelSelectablesContainer();
68
- this._storage.set(imodelKey, selectionContainer);
69
- }
70
- return selectionContainer;
71
- }
72
- handleChange(props) {
73
- const { source, level: inLevel, changeType, selectables: change } = props;
74
- const imodelKey = getIModelKey(props);
75
- const container = this.getContainer(imodelKey);
76
- const level = inLevel ?? 0;
77
- const selectables = container.getSelection(level);
78
- const selected = Selectable_js_1.Selectables.create(change);
79
- switch (changeType) {
80
- case "add":
81
- if (!Selectable_js_1.Selectables.add(selectables, change)) {
82
- return;
83
- }
84
- break;
85
- case "remove":
86
- if (!Selectable_js_1.Selectables.remove(selectables, change)) {
87
- return;
88
- }
89
- break;
90
- case "replace":
91
- if (Selectable_js_1.Selectables.size(selectables) === Selectable_js_1.Selectables.size(selected) && Selectable_js_1.Selectables.hasAll(selectables, change)) {
92
- return;
93
- }
94
- Selectable_js_1.Selectables.clear(selectables);
95
- Selectable_js_1.Selectables.add(selectables, change);
96
- break;
97
- case "clear":
98
- if (!Selectable_js_1.Selectables.clear(selectables)) {
99
- return;
100
- }
101
- break;
102
- }
103
- container.clear(level + 1);
104
- const event = {
105
- source,
106
- level,
107
- imodelKey,
108
- iModelKey: imodelKey,
109
- changeType,
110
- selectables: selected,
111
- timestamp: new Date(),
112
- storage: this,
113
- };
114
- this.selectionChangeEvent.raiseEvent(event, this);
115
- }
116
- }
117
- function getIModelKey(props) {
118
- // eslint-disable-next-line @typescript-eslint/no-deprecated
119
- return ("imodelKey" in props ? props.imodelKey : props.iModelKey) ?? "";
120
- }
121
- class MultiLevelSelectablesContainer {
122
- _selectablesContainers;
123
- constructor() {
124
- this._selectablesContainers = new Map();
125
- }
126
- getSelection(level) {
127
- let selectables = this._selectablesContainers.get(level);
128
- if (!selectables) {
129
- selectables = Selectable_js_1.Selectables.create([]);
130
- this._selectablesContainers.set(level, selectables);
131
- }
132
- return selectables;
133
- }
134
- getSelectionLevels() {
135
- const levels = new Array();
136
- for (const entry of this._selectablesContainers.entries()) {
137
- if (!Selectable_js_1.Selectables.isEmpty(entry[1])) {
138
- levels.push(entry[0]);
139
- }
140
- }
141
- return levels.sort();
142
- }
143
- clear(level) {
144
- const storedLevels = this._selectablesContainers.keys();
145
- for (const storedLevel of storedLevels) {
146
- if (storedLevel >= level) {
147
- const selectables = this._selectablesContainers.get(storedLevel);
148
- Selectable_js_1.Selectables.clear(selectables);
149
- }
150
- }
151
- }
152
- }
153
- //# sourceMappingURL=SelectionStorage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectionStorage.js","sourceRoot":"","sources":["../../../src/unified-selection/SelectionStorage.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AA8HhG,sCAEC;AA9HD,sDAA8C;AAE9C,mDAA0D;AA0G1D;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAI,oBAAoB,EAAE,CAAC;AACpC,CAAC;AAED;;;GAGG;AACU,QAAA,8BAA8B,GAAG,kCAAkC,CAAC;AAEjF,MAAM,oBAAoB;IAChB,QAAQ,GAAG,IAAI,GAAG,EAA0C,CAAC;IAC9D,oBAAoB,CAA2C;IAEtE;QACE,IAAI,CAAC,oBAAoB,GAAG,IAAI,sBAAO,EAAE,CAAC;IAC5C,CAAC;IAEM,kBAAkB,CAAC,KAAoB;QAC5C,OAAO,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,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AAC,EAAE,CAAC;gBACnC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,KAAa;QACxB,MAAM,YAAY,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACxD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACvC,IAAI,WAAW,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC;gBAClE,2BAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { Event } from \"@itwin/presentation-shared\";\nimport { Selectable, Selectables } from \"./Selectable.js\";\nimport {\n StorageSelectionChangeEventArgs,\n StorageSelectionChangesListener,\n StorageSelectionChangeType,\n} from \"./SelectionChangeEvent.js\";\n\n/** @public */\ntype IModelKeyProp =\n | {\n /**\n * Key of the iModel. It's recommended to use `createIModelKey` function from `@itwin/presentation-core-interop`\n * package to create the key for an iModel.\n *\n * Defaults to an empty string when not supplied.\n */\n imodelKey?: string;\n iModelKey?: never;\n }\n | {\n imodelKey?: never;\n /**\n * Key of the iModel. It's recommended to use `createIModelKey` function from `@itwin/presentation-core-interop`\n * package to create the key for an iModel.\n *\n * Defaults to an empty string when not supplied.\n *\n * @deprecated in 0.2. Use `imodelKey` instead.\n */\n iModelKey?: string;\n };\n\n/**\n * Defines return value of `createStorage`.\n *\n * **Warning:** Used in public API as a return value. Not expected to be created / extended by package\n * consumers, may be supplemented with required attributes any time.\n *\n * @see `createStorage`\n * @public\n */\nexport interface SelectionStorage {\n /** An event that is raised when selection changes. */\n selectionChangeEvent: Event<StorageSelectionChangesListener>;\n\n /** Get the selection levels currently stored for the specified iModel. */\n getSelectionLevels(props: IModelKeyProp): number[];\n\n /** Get the selection stored in the storage. */\n getSelection(\n props: IModelKeyProp & {\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): Selectables;\n\n /** Add keys to the selection. */\n addToSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to add to selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Remove keys from current selection. */\n removeFromSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to remove from selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Replace current selection. */\n replaceSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** The selectables to add to selection. */\n selectables: Selectable[];\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Clear current selection. */\n clearSelection(\n props: IModelKeyProp & {\n /** Name of the selection source. Generally, this identifies the component that makes the selection change. */\n source: string;\n /** Level of the selection. Defaults to `0`. */\n level?: number;\n },\n ): void;\n\n /** Clear storage for an iModel. This function should be called when iModel is closed. */\n clearStorage(props: IModelKeyProp): void;\n}\n\n/**\n * Creates a selection storage which stores and allows managing application-level selection.\n *\n * **Note:** `clearSelection` should be called upon iModel close to free-up memory:\n *\n * ```ts\n * import { IModelConnection } from \"@itwin/core-frontend\";\n * import { createIModelKey } from \"@itwin/presentation-core-interop\";\n *\n * IModelConnection.onClose.addListener((imodel) => {\n * storage.clearStorage(createIModelKey(imodel));\n * });\n * ```\n *\n * @public\n */\nexport function createStorage(): SelectionStorage {\n return new SelectionStorageImpl();\n}\n\n/**\n * The source name used when selection change is caused by clearing the selection storage. Used when change is performed by `clearStorage`.\n * @public\n */\nexport const CLEAR_SELECTION_STORAGE_SOURCE = \"Unified selection storage: clear\";\n\nclass SelectionStorageImpl implements SelectionStorage {\n private _storage = new Map<string, MultiLevelSelectablesContainer>();\n public selectionChangeEvent: BeEvent<StorageSelectionChangesListener>;\n\n constructor() {\n this.selectionChangeEvent = new BeEvent();\n }\n\n public getSelectionLevels(props: IModelKeyProp): number[] {\n return this.getContainer(getIModelKey(props)).getSelectionLevels();\n }\n\n public getSelection(props: IModelKeyProp & { level?: number }): Selectables {\n return this.getContainer(getIModelKey(props)).getSelection(props.level ?? 0);\n }\n\n public addToSelection(props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"add\" });\n }\n\n public removeFromSelection(\n props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number },\n ): void {\n this.handleChange({ ...props, changeType: \"remove\" });\n }\n\n public replaceSelection(props: IModelKeyProp & { source: string; selectables: Selectable[]; level?: number }): void {\n this.handleChange({ ...props, changeType: \"replace\" });\n }\n\n public clearSelection(props: IModelKeyProp & { source: string; level?: number }): void {\n this.handleChange({ ...props, changeType: \"clear\", selectables: [] });\n }\n\n public clearStorage(props: IModelKeyProp): void {\n const imodelKey = getIModelKey(props);\n this.clearSelection({ source: CLEAR_SELECTION_STORAGE_SOURCE, imodelKey });\n this._storage.delete(imodelKey);\n }\n\n private getContainer(imodelKey: string): MultiLevelSelectablesContainer {\n let selectionContainer = this._storage.get(imodelKey);\n if (!selectionContainer) {\n selectionContainer = new MultiLevelSelectablesContainer();\n this._storage.set(imodelKey, selectionContainer);\n }\n return selectionContainer;\n }\n\n private handleChange(\n props: IModelKeyProp & {\n source: string;\n level?: number;\n changeType: StorageSelectionChangeType;\n selectables: Selectable[];\n },\n ) {\n const { source, level: inLevel, changeType, selectables: change } = props;\n const imodelKey = getIModelKey(props);\n const container = this.getContainer(imodelKey);\n const level = inLevel ?? 0;\n const selectables = container.getSelection(level);\n const selected = Selectables.create(change);\n switch (changeType) {\n case \"add\":\n if (!Selectables.add(selectables, change)) {\n return;\n }\n break;\n case \"remove\":\n if (!Selectables.remove(selectables, change)) {\n return;\n }\n break;\n case \"replace\":\n if (Selectables.size(selectables) === Selectables.size(selected) && Selectables.hasAll(selectables, change)) {\n return;\n }\n Selectables.clear(selectables);\n Selectables.add(selectables, change);\n break;\n case \"clear\":\n if (!Selectables.clear(selectables)) {\n return;\n }\n break;\n }\n container.clear(level + 1);\n const event: StorageSelectionChangeEventArgs = {\n source,\n level,\n imodelKey,\n iModelKey: imodelKey,\n changeType,\n selectables: selected,\n timestamp: new Date(),\n storage: this,\n };\n this.selectionChangeEvent.raiseEvent(event, this);\n }\n}\n\nfunction getIModelKey(props: IModelKeyProp): string {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n return (\"imodelKey\" in props ? props.imodelKey : props.iModelKey) ?? \"\";\n}\n\nclass MultiLevelSelectablesContainer {\n private readonly _selectablesContainers: Map<number, Selectables>;\n\n constructor() {\n this._selectablesContainers = new Map<number, Selectables>();\n }\n\n public getSelection(level: number): Selectables {\n let selectables = this._selectablesContainers.get(level);\n if (!selectables) {\n selectables = Selectables.create([]);\n this._selectablesContainers.set(level, selectables);\n }\n return selectables;\n }\n\n public getSelectionLevels(): number[] {\n const levels = new Array<number>();\n for (const entry of this._selectablesContainers.entries()) {\n if (!Selectables.isEmpty(entry[1])) {\n levels.push(entry[0]);\n }\n }\n return levels.sort();\n }\n\n public clear(level: number) {\n const storedLevels = this._selectablesContainers.keys();\n for (const storedLevel of storedLevels) {\n if (storedLevel >= level) {\n const selectables = this._selectablesContainers.get(storedLevel)!;\n Selectables.clear(selectables);\n }\n }\n }\n}\n"]}
@@ -1,39 +0,0 @@
1
- import "./DisposePolyfill.js";
2
- import { Observable } from "rxjs";
3
- import { Id64Array, Id64Set } from "@itwin/core-bentley";
4
- import { ECSqlBinding, ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryReaderOptions, ECSqlQueryRow } from "@itwin/presentation-shared";
5
- /**
6
- * Forms ECSql bindings from given ID's.
7
- * @internal
8
- */
9
- export declare function formIdBindings(property: string, ids: Id64Array | Id64Set, bindings: ECSqlBinding[]): string;
10
- /**
11
- * Executes given ECSql query and extracts data from rows. Additionally handles main thread releasing.
12
- * @internal
13
- */
14
- export declare function genericExecuteQuery<T>({ queryExecutor, parseQueryRow, query, config, }: {
15
- queryExecutor: ECSqlQueryExecutor;
16
- query: ECSqlQueryDef;
17
- parseQueryRow: (row: ECSqlQueryRow) => T;
18
- config?: ECSqlQueryReaderOptions;
19
- }): AsyncIterableIterator<T>;
20
- /**
21
- * Emits a certain amount of values, then releases the main thread for other timers to use.
22
- * @internal
23
- */
24
- export declare function releaseMainThreadOnItemsCount<T>(elementCount: number): (obs: Observable<T>) => Observable<T>;
25
- /**
26
- * A helper that disposes the given object, if it's disposable.
27
- *
28
- * The first option is to dispose using the deprecated `dispose` method if it exists on the object.
29
- * If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is
30
- * considered as non-disposable and nothing is done with it.
31
- *
32
- * @internal
33
- */
34
- export declare function safeDispose(disposable: {} | {
35
- [Symbol.dispose]: () => void;
36
- } | {
37
- dispose: () => void;
38
- }): void;
39
- //# sourceMappingURL=Utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/unified-selection/Utils.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAA4C,UAAU,EAAM,MAAM,MAAM,CAAC;AAChF,OAAO,EAAQ,SAAS,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACd,MAAM,4BAA4B,CAAC;AAEpC;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,GAAG,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAoB3G;AAED;;;GAGG;AACH,wBAAuB,mBAAmB,CAAC,CAAC,EAAE,EAC5C,aAAa,EACb,aAAa,EACb,KAAK,EACL,MAAM,GACP,EAAE;IACD,aAAa,EAAE,kBAAkB,CAAC;IAClC,KAAK,EAAE,aAAa,CAAC;IACrB,aAAa,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,CAAC,CAAC;IACzC,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAO3B;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,IAC3D,KAAK,UAAU,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAAC,CAa3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,EAAE,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,QAMtG"}