@@ -5,6 +5,7 @@ import parseException from './exception-parser';
55import { debug } from './logger' ;
66import { isDevMode } from './dev-mode' ;
77import { basicFetch } from './fetch' ;
8+ import { getSerializedBlocks } from './blocks' ;
89
910/**
1011 * Generic function to dispatch messages to both Android and iOS bridges.
@@ -91,51 +92,8 @@ export function onBlocksChanged( isEmpty = false ) {
9192 *
9293 * @return {void }
9394 */
94- export async function showBlockInserter ( ) {
95- // Lazy-load getBlockTypes to defer the import until this function is called.
96- // In the remote editor, dependencies are loaded asynchronously, so this ensures
97- // window.wp.blocks is defined before we access it.
98- const { getBlockTypes } = await import ( '@wordpress/blocks' ) ;
99- const blocks = getBlockTypes ( ) . map ( ( blockType ) => {
100- // Extract and serialize icon
101- let icon = null ;
102- if ( blockType . icon ) {
103- let iconSource = blockType . icon ;
104-
105- // If icon is an object with src property, extract src
106- if ( typeof iconSource === 'object' && iconSource . src ) {
107- iconSource = iconSource . src ;
108- }
109-
110- // Convert React element to SVG string
111- if (
112- typeof iconSource === 'object' &&
113- iconSource !== null &&
114- typeof iconSource . type !== 'undefined'
115- ) {
116- try {
117- icon = renderToString ( iconSource ) ;
118- } catch ( error ) {
119- // If rendering fails, ignore the icon
120- debug (
121- `Failed to render icon for block ${ blockType . name } ` ,
122- error
123- ) ;
124- }
125- } else if ( typeof iconSource === 'string' ) {
126- icon = iconSource ;
127- }
128- }
129-
130- return {
131- name : blockType . name ,
132- title : blockType . title ,
133- description : blockType . description ,
134- category : blockType . category ,
135- keywords : blockType . keywords || [ ] ,
136- icon,
137- } ;
138- } ) ;
95+ export function showBlockInserter ( ) {
96+ const blocks = getSerializedBlocks ( ) ;
13997 dispatchToBridge ( 'showBlockInserter' , { blocks } ) ;
14098}
14199
0 commit comments