import { Command as ProseCommand } from "prosemirror-commands" ; import { Node as ProseNode , ResolvedPos , NodeType } from "prosemirror-model" ; import { liftTarget } from "prosemirror-transform" ; todo todo export function incrHeadingLevelCmd ( incr , options , bottomType ? ) { return ( state , dispatch , view ) => { if ( options . requireEmptySelection && ! state . selection . empty ) { return false ; } let { $anchor } = state . selection ; if ( options . requireTextblockStart ) { if ( view ? ! view . endOfTextblock ( "backward" , state ) : $anchor . parentOffset > 0 ) { return false ; } } let parent = $anchor . parent ; todo if ( parent . type . name !== "heading" ) { return false ; } let headingPos = $anchor . before ( $anchor . depth ) ; let targetLevel = Math . min ( 6 , Math . max ( 0 , parent . attrs . level + incr ) ) ; if ( targetLevel > 0 ) { if ( dispatch ) { dispatch ( state . tr . setNodeMarkup ( headingPos , undefined , { level : targetLevel } ) ) ; } return true ; } if ( bottomType ) { if ( dispatch ) { dispatch ( state . tr . setNodeMarkup ( headingPos , bottomType ) ) ; } return true ; } return false ; } ; }