@@ -35,7 +35,6 @@ const BLOCK_TYPE = 'block';
3535export class BlockFlyoutInflater implements IFlyoutInflater {
3636 protected permanentlyDisabledBlocks = new Set < BlockSvg > ( ) ;
3737 protected listeners = new Map < string , browserEvents . Data [ ] > ( ) ;
38- protected flyoutWorkspace ?: WorkspaceSvg ;
3938 protected flyout ?: IFlyout ;
4039 private capacityWrapper : ( event : AbstractEvent ) => void ;
4140
@@ -50,13 +49,12 @@ export class BlockFlyoutInflater implements IFlyoutInflater {
5049 * Inflates a flyout block from the given state and adds it to the flyout.
5150 *
5251 * @param state A JSON representation of a flyout block.
53- * @param flyoutWorkspace The workspace to create the block on.
52+ * @param flyout The flyout to create the block on.
5453 * @returns A newly created block.
5554 */
56- load ( state : object , flyoutWorkspace : WorkspaceSvg ) : FlyoutItem {
57- this . setFlyoutWorkspace ( flyoutWorkspace ) ;
58- this . flyout = flyoutWorkspace . targetWorkspace ?. getFlyout ( ) ?? undefined ;
59- const block = this . createBlock ( state as BlockInfo , flyoutWorkspace ) ;
55+ load ( state : object , flyout : IFlyout ) : FlyoutItem {
56+ this . setFlyout ( flyout ) ;
57+ const block = this . createBlock ( state as BlockInfo , flyout . getWorkspace ( ) ) ;
6058
6159 if ( ! block . isEnabled ( ) ) {
6260 // Record blocks that were initially disabled.
@@ -157,22 +155,18 @@ export class BlockFlyoutInflater implements IFlyoutInflater {
157155 }
158156
159157 /**
160- * Updates this inflater's flyout workspace .
158+ * Updates this inflater's flyout.
161159 *
162- * @param workspace The workspace of the flyout that owns this inflater.
160+ * @param flyout The flyout that owns this inflater.
163161 */
164- protected setFlyoutWorkspace ( workspace : WorkspaceSvg ) {
165- if ( this . flyoutWorkspace === workspace ) return ;
162+ protected setFlyout ( flyout : IFlyout ) {
163+ if ( this . flyout === flyout ) return ;
166164
167- if ( this . flyoutWorkspace ) {
168- this . flyoutWorkspace . targetWorkspace ?. removeChangeListener (
169- this . capacityWrapper ,
170- ) ;
165+ if ( this . flyout ) {
166+ this . flyout . targetWorkspace ?. removeChangeListener ( this . capacityWrapper ) ;
171167 }
172- this . flyoutWorkspace = workspace ;
173- this . flyoutWorkspace . targetWorkspace ?. addChangeListener (
174- this . capacityWrapper ,
175- ) ;
168+ this . flyout = flyout ;
169+ this . flyout . targetWorkspace ?. addChangeListener ( this . capacityWrapper ) ;
176170 }
177171
178172 /**
@@ -182,7 +176,7 @@ export class BlockFlyoutInflater implements IFlyoutInflater {
182176 * @param block The block to update the enabled/disabled state of.
183177 */
184178 private updateStateBasedOnCapacity ( block : BlockSvg ) {
185- const enable = this . flyoutWorkspace ?. targetWorkspace ?. isCapacityAvailable (
179+ const enable = this . flyout ?. targetWorkspace ?. isCapacityAvailable (
186180 common . getBlockTypeCounts ( block ) ,
187181 ) ;
188182 let currentBlock : BlockSvg | null = block ;
@@ -209,26 +203,25 @@ export class BlockFlyoutInflater implements IFlyoutInflater {
209203 'pointerdown' ,
210204 block ,
211205 ( e : PointerEvent ) => {
212- const gesture = this . flyoutWorkspace ?. targetWorkspace ?. getGesture ( e ) ;
213- const flyout = this . flyoutWorkspace ?. targetWorkspace ?. getFlyout ( ) ;
214- if ( gesture && flyout ) {
206+ const gesture = this . flyout ?. targetWorkspace ?. getGesture ( e ) ;
207+ if ( gesture && this . flyout ) {
215208 gesture . setStartBlock ( block ) ;
216- gesture . handleFlyoutStart ( e , flyout ) ;
209+ gesture . handleFlyoutStart ( e , this . flyout ) ;
217210 }
218211 } ,
219212 ) ,
220213 ) ;
221214
222215 blockListeners . push (
223216 browserEvents . bind ( block . getSvgRoot ( ) , 'pointerenter' , null , ( ) => {
224- if ( ! this . flyoutWorkspace ?. targetWorkspace ?. isDragging ( ) ) {
217+ if ( ! this . flyout ?. targetWorkspace ?. isDragging ( ) ) {
225218 block . addSelect ( ) ;
226219 }
227220 } ) ,
228221 ) ;
229222 blockListeners . push (
230223 browserEvents . bind ( block . getSvgRoot ( ) , 'pointerleave' , null , ( ) => {
231- if ( ! this . flyoutWorkspace ?. targetWorkspace ?. isDragging ( ) ) {
224+ if ( ! this . flyout ?. targetWorkspace ?. isDragging ( ) ) {
232225 block . removeSelect ( ) ;
233226 }
234227 } ) ,
@@ -245,7 +238,7 @@ export class BlockFlyoutInflater implements IFlyoutInflater {
245238 */
246239 private filterFlyoutBasedOnCapacity ( event : AbstractEvent ) {
247240 if (
248- ! this . flyoutWorkspace ||
241+ ! this . flyout ||
249242 ( event &&
250243 ! (
251244 event . type === EventType . BLOCK_CREATE ||
@@ -254,11 +247,14 @@ export class BlockFlyoutInflater implements IFlyoutInflater {
254247 )
255248 return ;
256249
257- this . flyoutWorkspace . getTopBlocks ( false ) . forEach ( ( block ) => {
258- if ( ! this . permanentlyDisabledBlocks . has ( block ) ) {
259- this . updateStateBasedOnCapacity ( block ) ;
260- }
261- } ) ;
250+ this . flyout
251+ . getWorkspace ( )
252+ . getTopBlocks ( false )
253+ . forEach ( ( block ) => {
254+ if ( ! this . permanentlyDisabledBlocks . has ( block ) ) {
255+ this . updateStateBasedOnCapacity ( block ) ;
256+ }
257+ } ) ;
262258 }
263259
264260 /**
0 commit comments