File tree Expand file tree Collapse file tree
packages/editor/src/plugins/toolbar Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import LinkIcon from '@material-ui/icons/InsertLink'
99import ImageIcon from '@material-ui/icons/InsertPhoto'
1010import QuoteIcon from '@material-ui/icons/FormatQuote'
1111import CodeIcon from '@material-ui/icons/Code'
12+ import ListIcon from '@material-ui/icons/List'
1213// import ListIcon from '@material-ui/icons/FormatListBulleted'
1314// import StrikethroughIcon from '@material-ui/icons/StrikethroughS'
1415// import HeadingIcon from '@material-ui/icons/Title'
@@ -145,6 +146,12 @@ const buttons = [
145146 isActive : isActive ( 'image' )
146147 } ,
147148 { separator : true } ,
149+ {
150+ title : 'Insert Bulleted List' ,
151+ Icon : ListIcon ,
152+ command : 'toggleBulletedList' ,
153+ isActive : isActive ( 'list-item' )
154+ } ,
148155 {
149156 title : 'Insert JSX Block' ,
150157 Icon : JSX ,
Original file line number Diff line number Diff line change @@ -20,6 +20,20 @@ const hasBlock = (editor, type) => {
2020 return editor . value . blocks . some ( node => node . type === type )
2121}
2222
23+ const toggleBulletedList = editor => {
24+ const {
25+ value : { startBlock, document }
26+ } = editor
27+ const parent = document . getParent ( startBlock . key )
28+
29+ const isList =
30+ parent && ( parent . type === 'list-item-child' || parent . type === 'list-item' )
31+
32+ return isList
33+ ? editor . unwrapList ( )
34+ : editor . wrapList ( { type : 'bulleted-list' } )
35+ }
36+
2337const toggleBlock = ( editor , type ) => {
2438 if ( editor . hasBlock ( type ) ) {
2539 editor . setBlocks ( DEFAULT_BLOCK )
@@ -69,6 +83,7 @@ export default (opts = {}) => ({
6983 toggleBlockQuote,
7084 toggleHeadingOne,
7185 toggleHeadingTwo,
86+ toggleBulletedList,
7287 toggleJSX,
7388 togglePre
7489 } ,
You can’t perform that action at this time.
0 commit comments