如何在古腾堡使用独立的块编辑器

时间:2019-12-20 01:01:14

标签: wordpress

我想在我的WordPress插件中使用此Gutenberg软件包:

https://github.com/WordPress/gutenberg/tree/master/packages/block-editor

使用情况部分说:

import {
    BlockEditorProvider,
    BlockList,
    WritingFlow,
    ObserveTyping
} from '@wordpress/block-editor';
import { Popover } from '@wordpress/components';
import { useState } from '@wordpress/element';

function MyEditorComponent () {
    const [ blocks, updateBlocks ] = useState( [] );

    return (
        <BlockEditorProvider
            value={ blocks }
            onInput={ updateBlocks }
            onChange={ updateBlocks }
        >
            <WritingFlow>
                <ObserveTyping>
                    <BlockList />
                </ObserveTyping>
            </WritingFlow>
            <Popover.Slot />
        </BlockEditorProvider>
    );
}

// Make sure to load the block editor stylesheets too
// import '@wordpress/components/build-style/style.css';
// import '@wordpress/block-editor/build-style/style.css';

我应该在哪里包含此代码?

0 个答案:

没有答案