@@ -133,8 +133,8 @@ abstract class ToolbarContextBase {
133
133
) ;
134
134
}
135
135
136
- getSurfaceModelsByType < M extends abstract new ( ...args : any ) => any > (
137
- klass : M
136
+ getSurfaceModelsByType < T extends abstract new ( ...args : any ) => any > (
137
+ klass : T
138
138
) {
139
139
if ( this . hasSelectedSurfaceModels ) {
140
140
const elements = this . elementsMap$ . peek ( ) . get ( this . flavour$ . peek ( ) ) ;
@@ -145,6 +145,20 @@ abstract class ToolbarContextBase {
145
145
return [ ] ;
146
146
}
147
147
148
+ getSurfaceBlocksByType < T extends abstract new ( ...args : any ) => any > (
149
+ klass : T
150
+ ) {
151
+ if ( this . hasSelectedSurfaceModels ) {
152
+ const elements = this . elementsMap$ . peek ( ) . get ( this . flavour$ . peek ( ) ) ;
153
+ if ( elements ?. length ) {
154
+ return elements
155
+ . map ( model => this . gfx . view . get ( model . id ) )
156
+ . filter ( block => block && this . matchBlock ( block , klass ) ) ;
157
+ }
158
+ }
159
+ return [ ] ;
160
+ }
161
+
148
162
getCurrentBlockBy < T extends SelectionConstructor > ( type : T ) {
149
163
const selection = this . selection . find ( type ) ;
150
164
if ( ! selection ) return null ;
@@ -165,17 +179,17 @@ abstract class ToolbarContextBase {
165
179
: this . getCurrentBlockBy ( BlockSelection ) ;
166
180
}
167
181
168
- getCurrentBlockByType < K extends abstract new ( ...args : any ) => any > (
169
- klass : K
182
+ getCurrentBlockByType < T extends abstract new ( ...args : any ) => any > (
183
+ klass : T
170
184
) {
171
185
const block = this . getCurrentBlock ( ) ;
172
186
return this . matchBlock ( block , klass ) ? block : null ;
173
187
}
174
188
175
- matchBlock < K extends abstract new ( ...args : any ) => any > (
189
+ matchBlock < T extends abstract new ( ...args : any ) => any > (
176
190
component : GfxElementModelView | BlockComponent | null ,
177
- klass : K
178
- ) : component is InstanceType < K > {
191
+ klass : T
192
+ ) : component is InstanceType < T > {
179
193
return component instanceof klass ;
180
194
}
181
195
@@ -189,23 +203,23 @@ abstract class ToolbarContextBase {
189
203
return this . store . getBlock ( selection . blockId ) ?. model ?? null ;
190
204
}
191
205
192
- getCurrentModel ( ) {
206
+ getCurrentModel ( ) : GfxModel | BlockModel | null {
193
207
return this . hasSelectedSurfaceModels
194
208
? this . getCurrentModelBy ( SurfaceSelection )
195
209
: this . getCurrentModelBy ( BlockSelection ) ;
196
210
}
197
211
198
- getCurrentModelByType < M extends abstract new ( ...args : any ) => any > (
199
- klass : M
212
+ getCurrentModelByType < T extends abstract new ( ...args : any ) => any > (
213
+ klass : T
200
214
) {
201
215
const model = this . getCurrentModel ( ) ;
202
216
return this . matchModel ( model , klass ) ? model : null ;
203
217
}
204
218
205
- matchModel < K extends abstract new ( ...args : any ) => any > (
219
+ matchModel < T extends abstract new ( ...args : any ) => any > (
206
220
model : GfxModel | BlockModel | null ,
207
- klass : K
208
- ) : model is InstanceType < K > {
221
+ klass : T
222
+ ) : model is InstanceType < T > {
209
223
return model instanceof klass ;
210
224
}
211
225
0 commit comments