Skip to content

Commit

Permalink
Google Map: Render block in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
iandunn committed Nov 13, 2023
1 parent d146c0f commit bfa544e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
3 changes: 1 addition & 2 deletions mu-plugins/blocks/google-map-event-filters/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@
"supports": {
"inserter": false
},
"editorScript": "file:./index.js",
"style": "file:./style.css"
"editorScript": "file:./index.js"
}
17 changes: 8 additions & 9 deletions mu-plugins/blocks/google-map-event-filters/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { Placeholder } from '@wordpress/components';
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -12,13 +11,13 @@ import metadata from './block.json';

function Edit() {
return (
<Placeholder
instructions={ __(
'This is a placeholder for the editor until a back-end UI is built. See the README for instructions on supplying data.',
'wporg'
) }
label={ __( 'Google Map Event Filters', 'wporg' ) }
/>
<div { ...useBlockProps() }>
<InnerBlocks
allowedBlocks={ [ 'wporg/google-map' ] }
template={ [ [ 'wporg/google-map' ] ] }
templateLock="all"
/>
</div>
);
}

Expand Down
9 changes: 9 additions & 0 deletions mu-plugins/blocks/google-map/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ function render( $attributes, $content, $block ) {
'before'
);

wp_add_inline_script(
$block->block_type->editor_script_handles[0],
sprintf(
'const wporgGoogleMap = %s;',
wp_json_encode( $attributes )
),
'before'
);

$wrapper_attributes = get_block_wrapper_attributes( array( 'id' => $attributes['id'] ) );

ob_start();
Expand Down
1 change: 1 addition & 0 deletions mu-plugins/blocks/google-map/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"inserter": false
},
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"viewScript": "file:./front.js",
"style": "file:./style.css"
}
16 changes: 7 additions & 9 deletions mu-plugins/blocks/google-map/src/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
/* global wporgGoogleMap */

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { Placeholder } from '@wordpress/components';
import { useBlockProps } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import metadata from './block.json';
import Main from './components/main';

function Edit() {
return (
<Placeholder
instructions={ __(
'This is a placeholder for the editor. Data is supplied to this block via the pattern that includes it.',
'wporg'
) }
label={ __( 'WordPress.org Google Map', 'wporg' ) }
/>
<div { ...useBlockProps() }>
<Main { ...wporgGoogleMap } />
</div>
);
}

Expand Down

0 comments on commit bfa544e

Please sign in to comment.