@@ -39,6 +39,7 @@ export interface BlocklyComponentType {
3939
4040/** Interface for props passed to the BlocklyComponent. */
4141export interface BlocklyComponentProps {
42+ onBlocklyComponentCreated : ( blocklyComponent : BlocklyComponentType ) => void ;
4243 theme : string ;
4344 onWorkspaceRecreated : ( workspace : Blockly . WorkspaceSvg ) => void ;
4445}
@@ -80,8 +81,8 @@ const WORKSPACE_STYLE: React.CSSProperties = {
8081 * React component that renders a Blockly workspace with proper initialization,
8182 * cleanup, and resize handling.
8283 */
83- const BlocklyComponent = React . forwardRef < BlocklyComponentType | null , BlocklyComponentProps > (
84- ( props , ref ) : React . JSX . Element => {
84+ export default function BlocklyComponent ( props : BlocklyComponentProps ) : React . JSX . Element {
85+ // TODO(lizlooney ): Fix indentation in a separate commit.
8586 const blocklyDiv = React . useRef < HTMLDivElement | null > ( null ) ;
8687 const workspaceRef = React . useRef < Blockly . WorkspaceSvg | null > ( null ) ;
8788
@@ -249,6 +250,12 @@ const BlocklyComponent = React.forwardRef<BlocklyComponentType | null, BlocklyCo
249250
250251 // Initialize Blockly workspace
251252 React . useEffect ( ( ) => {
253+ if ( props . onBlocklyComponentCreated ) {
254+ const blocklyComponent : BlocklyComponentType = {
255+ getBlocklyWorkspace,
256+ } ;
257+ props . onBlocklyComponentCreated ( blocklyComponent ) ;
258+ }
252259 initializeWorkspace ( ) ;
253260 return cleanupWorkspace ;
254261 } , [ ] ) ;
@@ -270,23 +277,9 @@ const BlocklyComponent = React.forwardRef<BlocklyComponentType | null, BlocklyCo
270277 return setupResizeObserver ( ) ;
271278 } , [ ] ) ;
272279
273- // Expose methods through ref
274- React . useImperativeHandle (
275- ref ,
276- ( ) : BlocklyComponentType => ( {
277- getBlocklyWorkspace,
278- } ) ,
279- [ ]
280- ) ;
281-
282280 return (
283281 < div className = "blockly-workspace-container" style = { FULL_SIZE_STYLE } >
284282 < div ref = { blocklyDiv } style = { WORKSPACE_STYLE } />
285283 </ div >
286284 ) ;
287285 }
288- ) ;
289-
290- BlocklyComponent . displayName = 'BlocklyComponent' ;
291-
292- export default BlocklyComponent ;
0 commit comments