Skip to content

Commit

Permalink
Use a Control
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Feb 2, 2021
1 parent 2184faf commit 76aa918
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/class-wp-sidebar-block-editor-control.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

class WP_Sidebar_Block_Editor_Control extends WP_Customize_Control {
public $type = 'sidebar_block_editor';

public function enqueue() {
gutenberg_widgets_init( 'gutenberg_customizer' );
}
Expand Down
23 changes: 23 additions & 0 deletions packages/edit-widgets/src/create-customizer-control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* WordPress dependencies
*/
import { render } from '@wordpress/element';

/**
* Internal dependencies
*/
import Layout from './components/layout';

const { wp } = window;

const createCustomizerControl = ( { settings } ) =>
wp.customize.Control.extend( {
ready() {
render(
<Layout blockEditorSettings={ settings } isInCustomizer />,
this.container[ 0 ]
);
},
} );

export default createCustomizerControl;
11 changes: 4 additions & 7 deletions packages/edit-widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import './hooks';
import { create as createLegacyWidget } from './blocks/legacy-widget';
import * as widgetArea from './blocks/widget-area';
import Layout from './components/layout';
import createCustomizerControl from './create-customizer-control';

/**
* Initializes the block editor in the widgets screen.
Expand Down Expand Up @@ -56,13 +57,9 @@ export function initializeCustomizer( id, settings ) {
registerBlock( createLegacyWidget( settings ) );
registerBlock( widgetArea );

// The code executes before the target DOM has been attached, so we use a hacky timeout to delay the render
setTimeout( () => {
render(
<Layout blockEditorSettings={ settings } isInCustomizer />,
document.getElementById( id )
);
}, 0 );
window.wp.customize.controlConstructor.sidebar_block_editor = createCustomizerControl(
{ settings }
);
}

/**
Expand Down

0 comments on commit 76aa918

Please sign in to comment.