Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gutenberg block to use api version 2 #24

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
48 changes: 29 additions & 19 deletions admin/assets/js/draw-attention-block.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender;
(function(blocks, element, serverSideRender, blockEditor )
{
var el = element.createElement,
registerBlockType = blocks.registerBlockType,
ServerSideRender = serverSideRender,
useBlockProps = blockEditor.useBlockProps;

registerBlockType( 'draw-attention/image', {
title: 'Draw Attention Image',
icon: 'images-alt2',
category: 'widgets',
registerBlockType( 'draw-attention/image', {
apiVersion: 2,
title: 'Draw Attention Image',
icon: 'images-alt2',
category: 'widgets',

edit: function() {
return [
el( ServerSideRender, {
block: 'draw-attention/image'
} )
];
},

save: function() {
return null;
},
} );
edit: function(props) {
var blockProps = useBlockProps();
return el(
'div',
blockProps,
el(ServerSideRender, {
block: 'draw-attention/image',
attributes: props.attributes,
})
);
},
} );
})(
window.wp.blocks,
window.wp.element,
window.wp.serverSideRender,
window.wp.blockEditor
);
3 changes: 2 additions & 1 deletion public/includes/class-block-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function register_image_block() {
wp_register_script(
'drawattention-image-block-js',
trailingslashit( $this->plugin->get_plugin_url() ) . 'admin/assets/js/draw-attention-block.js',
array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor' )
array( 'wp-blocks', 'wp-element', 'wp-server-side-render', 'wp-block-editor' )
);

wp_register_style(
Expand All @@ -56,6 +56,7 @@ function register_image_block() {
);

register_block_type( 'draw-attention/image', array(
'api_version' => 2,
'editor_script' => 'drawattention-image-block-js',
'editor_style' => 'drawattention-image-block-css',
'keywords' => array( 'image', 'hotspot', 'map' ),
Expand Down
Loading