Created
June 3, 2020 03:30
-
-
Save rheinardkorf/9d0c1b3dcececc5d69590ea8728b2b53 to your computer and use it in GitHub Desktop.
Gutenberg manipulate Editor Mode state. (Experimental)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (wp) { | |
var registerPlugin = wp.plugins.registerPlugin; | |
var PluginMoreMenuItem = wp.editPost.PluginMoreMenuItem; | |
// var image = wp.icons.image; | |
var el = wp.element.createElement; | |
var withDispatch = wp.data.withDispatch; | |
var MoreItem = function (props) { | |
return el(PluginMoreMenuItem, | |
{ | |
name: 'my-plugin-sidebar', | |
icon: 'admin-post', | |
title: 'My plugin sidebar', | |
onClick: props.setEditorValue('markdown') | |
}, | |
'Markdown Editor' | |
); | |
} | |
var MoreItemWithDispatch = withDispatch( | |
function (dispatch) { | |
return { | |
setEditorValue: function (value) { | |
dispatch('core/edit-post').switchEditorMode(value); | |
} | |
} | |
} | |
)(MoreItem) | |
registerPlugin('my-plugin-sidebar', { | |
render: function () { | |
return el(MoreItemWithDispatch); | |
}, | |
}); | |
// var PluginSidebar = wp.editPost.PluginSidebar; | |
// var el = wp.element.createElement; | |
// registerPlugin('my-plugin-sidebar', { | |
// render: function () { | |
// return el(PluginSidebar, | |
// { | |
// name: 'my-plugin-sidebar', | |
// icon: 'admin-post', | |
// title: 'My plugin sidebar', | |
// }, | |
// 'Meta field' | |
// ); | |
// }, | |
// }); | |
})(window.wp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment