@@ -46,8 +46,6 @@ const INPUT_COMPONENTS = 'COMPONENTS';
4646const INPUT_PRIVATE_COMPONENTS = 'PRIVATE_COMPONENTS' ;
4747const INPUT_EVENTS = 'EVENTS' ;
4848
49- export const TOOLBOX_UPDATE_EVENT = 'toolbox-update-requested' ;
50-
5149type MechanismComponentHolderExtraState = {
5250 hideMechanisms ?: boolean ;
5351 hidePrivateComponents ?: boolean ;
@@ -62,7 +60,6 @@ interface MechanismComponentHolderMixin extends MechanismComponentHolderMixinTyp
6260 mrcComponentBlockIds : string ,
6361 mrcPrivateComponentBlockIds : string ,
6462 mrcEventBlockIds : string ,
65- mrcToolboxUpdateTimeout : NodeJS . Timeout | null ;
6663}
6764type MechanismComponentHolderMixinType = typeof MECHANISM_COMPONENT_HOLDER ;
6865
@@ -78,7 +75,6 @@ const MECHANISM_COMPONENT_HOLDER = {
7875 this . mrcComponentBlockIds = '' ;
7976 this . mrcPrivateComponentBlockIds = '' ;
8077 this . mrcEventBlockIds = '' ;
81- this . mrcToolboxUpdateTimeout = null ;
8278 } ,
8379 ...NONCOPYABLE_BLOCK ,
8480 saveExtraState : function ( this : MechanismComponentHolderBlock ) : MechanismComponentHolderExtraState {
@@ -135,21 +131,21 @@ const MECHANISM_COMPONENT_HOLDER = {
135131 * mrcOnLoad is called for each MechanismComponentHolderBlock when the blocks are loaded in the blockly
136132 * workspace.
137133 */
138- mrcOnLoad : function ( this : MechanismComponentHolderBlock , _editor : Editor ) : void {
139- this . collectDescendants ( false ) ;
134+ mrcOnLoad : function ( this : MechanismComponentHolderBlock , editor : Editor ) : void {
135+ this . collectDescendants ( editor , false ) ;
140136 } ,
141137 /**
142138 * mrcOnDescendantDisconnect is called for each MechanismComponentHolderBlock when any descendant is
143139 * disconnected.
144140 */
145- mrcOnDescendantDisconnect : function ( this : MechanismComponentHolderBlock ) : void {
146- this . collectDescendants ( true ) ;
141+ mrcOnDescendantDisconnect : function ( this : MechanismComponentHolderBlock , editor : Editor ) : void {
142+ this . collectDescendants ( editor , true ) ;
147143 } ,
148- mrcDescendantsMayHaveChanged : function ( this : MechanismComponentHolderBlock ) : void {
149- this . collectDescendants ( true ) ;
144+ mrcDescendantsMayHaveChanged : function ( this : MechanismComponentHolderBlock , editor : Editor ) : void {
145+ this . collectDescendants ( editor , true ) ;
150146 } ,
151147 collectDescendants : function (
152- this : MechanismComponentHolderBlock , updateToolboxIfDescendantsChanged : boolean ) : void {
148+ this : MechanismComponentHolderBlock , editor : Editor , updateToolboxIfDescendantsChanged : boolean ) : void {
153149 let mechanismBlockIds = '' ;
154150 let componentBlockIds = '' ;
155151 let privateComponentBlockIds = '' ;
@@ -209,7 +205,7 @@ const MECHANISM_COMPONENT_HOLDER = {
209205 componentBlockIds !== this . mrcComponentBlockIds ||
210206 privateComponentBlockIds !== this . mrcPrivateComponentBlockIds ||
211207 eventBlockIds !== this . mrcEventBlockIds ) {
212- this . updateToolboxAfterDelay ( ) ;
208+ editor . updateToolboxAfterDelay ( ) ;
213209 }
214210 }
215211
@@ -218,21 +214,6 @@ const MECHANISM_COMPONENT_HOLDER = {
218214 this . mrcPrivateComponentBlockIds = privateComponentBlockIds ;
219215 this . mrcEventBlockIds = eventBlockIds ;
220216 } ,
221- updateToolboxAfterDelay : function ( this : MechanismComponentHolderBlock ) : void {
222- if ( this . mrcToolboxUpdateTimeout ) {
223- clearTimeout ( this . mrcToolboxUpdateTimeout ) ;
224- }
225- this . mrcToolboxUpdateTimeout = setTimeout ( ( ) => {
226- const event = new CustomEvent ( TOOLBOX_UPDATE_EVENT , {
227- detail : {
228- timestamp : Date . now ( ) ,
229- workspaceId : this . workspace . id ,
230- }
231- } ) ;
232- window . dispatchEvent ( event ) ;
233- this . mrcToolboxUpdateTimeout = null ;
234- } , 100 ) ;
235- } ,
236217 /**
237218 * setNameOfChildBlock is called from mrc_mechanism, mrc_component, and mrc_event blocks when they
238219 * connect to this mrc_mechanism_component_holder block.
@@ -515,10 +496,10 @@ export function getEvents(
515496 } ) ;
516497}
517498
518- export function mrcDescendantsMayHaveChanged ( workspace : Blockly . Workspace ) : void {
499+ export function mrcDescendantsMayHaveChanged ( workspace : Blockly . Workspace , editor : Editor ) : void {
519500 // Get the holder block and call its mrcDescendantsMayHaveChanged method.
520501 workspace . getBlocksByType ( BLOCK_NAME ) . forEach ( block => {
521- ( block as MechanismComponentHolderBlock ) . mrcDescendantsMayHaveChanged ( ) ;
502+ ( block as MechanismComponentHolderBlock ) . mrcDescendantsMayHaveChanged ( editor ) ;
522503 } ) ;
523504}
524505
0 commit comments