Skip to content

Commit 9e7b7a3

Browse files
aduthnoisysocks
authored andcommitted
Blocks: Reimplement shared block as embedded editor
- Publish shared blocks when creating and editing them - Fix exception when converting a shared block to static - Fix 'Convert to Regular Block' button - Remove the block when deleting a shared block
1 parent 4a184d5 commit 9e7b7a3

File tree

23 files changed

+275
-1168
lines changed

23 files changed

+275
-1168
lines changed

core-blocks/block/selection.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { Component } from '@wordpress/element';
5+
import { withSelect, withDispatch } from '@wordpress/data';
6+
import { compose } from '@wordpress/compose';
7+
8+
class SharedBlockSelection extends Component {
9+
componentDidUpdate( prevProps ) {
10+
const {
11+
isSharedBlockSelected,
12+
hasSelection,
13+
clearSelectedBlock,
14+
onBlockSelection,
15+
} = this.props;
16+
17+
if ( ! isSharedBlockSelected && prevProps.isSharedBlockSelected ) {
18+
clearSelectedBlock();
19+
}
20+
21+
if ( hasSelection && ! prevProps.hasSelection ) {
22+
onBlockSelection();
23+
}
24+
}
25+
26+
render() {
27+
return this.props.children;
28+
}
29+
}
30+
31+
export default compose( [
32+
withSelect( ( select ) => {
33+
const { getBlockSelectionStart } = select( 'core/editor' );
34+
35+
return {
36+
hasSelection: !! getBlockSelectionStart(),
37+
};
38+
} ),
39+
withDispatch( ( dispatch ) => {
40+
const { clearSelectedBlock } = dispatch( 'core/editor' );
41+
return { clearSelectedBlock };
42+
} ),
43+
] )( SharedBlockSelection );

lib/class-wp-rest-blocks-controller.php

-123
This file was deleted.

lib/load.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// These files only need to be loaded if within a rest server instance
1313
// which this class will exist if that is the case.
1414
if ( class_exists( 'WP_REST_Controller' ) ) {
15-
require dirname( __FILE__ ) . '/class-wp-rest-blocks-controller.php';
1615
require dirname( __FILE__ ) . '/class-wp-rest-autosaves-controller.php';
1716
require dirname( __FILE__ ) . '/class-wp-rest-block-renderer-controller.php';
1817
require dirname( __FILE__ ) . '/class-wp-rest-search-controller.php';

lib/register.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -461,21 +461,20 @@ function gutenberg_register_post_types() {
461461
register_post_type(
462462
'wp_block',
463463
array(
464-
'labels' => array(
464+
'labels' => array(
465465
'name' => 'Blocks',
466466
'singular_name' => 'Block',
467467
),
468-
'public' => false,
469-
'rewrite' => false,
470-
'show_in_rest' => true,
471-
'rest_base' => 'blocks',
472-
'rest_controller_class' => 'WP_REST_Blocks_Controller',
473-
'capability_type' => 'block',
468+
'public' => false,
469+
'rewrite' => false,
470+
'show_in_rest' => true,
471+
'rest_base' => 'blocks',
472+
'capability_type' => 'block',
474473
'capabilities' => array(
475474
'read' => 'read_blocks',
476475
'create_posts' => 'create_blocks',
477476
),
478-
'map_meta_cap' => true,
477+
'map_meta_cap' => true,
479478
)
480479
);
481480

packages/block-library/src/block/edit-panel/index.js

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { over, compact } from 'lodash';
5+
16
/**
27
* WordPress dependencies
38
*/
49
import { Button } from '@wordpress/components';
510
import { Component, Fragment, createRef } from '@wordpress/element';
611
import { __ } from '@wordpress/i18n';
712
import { ESCAPE } from '@wordpress/keycodes';
8-
import { withInstanceId } from '@wordpress/compose';
13+
import { withSelect, withDispatch } from '@wordpress/data';
14+
import { withInstanceId, compose } from '@wordpress/compose';
915

1016
class ReusableBlockEditPanel extends Component {
1117
constructor() {
@@ -115,4 +121,33 @@ class ReusableBlockEditPanel extends Component {
115121
}
116122
}
117123

118-
export default withInstanceId( ReusableBlockEditPanel );
124+
export default compose( [
125+
withInstanceId,
126+
withSelect( ( select ) => {
127+
const { getEditedPostAttribute } = select( 'core/editor' );
128+
129+
return {
130+
title: getEditedPostAttribute( 'title' ),
131+
};
132+
} ),
133+
withDispatch( ( dispatch, ownProps ) => {
134+
const {
135+
editPost,
136+
undoAll,
137+
savePost,
138+
clearSelectedBlock,
139+
} = dispatch( 'core/editor' );
140+
141+
const withClearAndFinish = ( fn ) => over( compact( [
142+
clearSelectedBlock,
143+
ownProps.onFinishedEditing,
144+
fn,
145+
] ) );
146+
147+
return {
148+
onChangeTitle: ( title ) => editPost( { title } ),
149+
onSave: withClearAndFinish( savePost ),
150+
onCancel: withClearAndFinish( undoAll ),
151+
};
152+
} ),
153+
] )( ReusableBlockEditPanel );

0 commit comments

Comments
 (0)