1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-22 20:21:56 +03:00

Got alignment buttons barely working for paragraphs

This commit is contained in:
Dan Brown
2022-01-11 18:58:24 +00:00
parent 4e5153d372
commit 6744ab2ff9
5 changed files with 120 additions and 6 deletions

View File

@ -8,6 +8,7 @@
import crel from "crelt"
import {lift, joinUp, selectParentNode, wrapIn, setBlockType} from "prosemirror-commands"
import {undo, redo} from "prosemirror-history"
import {setBlockAttr} from "../commands";
import {getIcon} from "./icons"
@ -457,6 +458,21 @@ export function blockTypeItem(nodeType, options) {
return new MenuItem(passedOptions)
}
export function setAttrItem(attrName, attrValue, options) {
const command = setBlockAttr(attrName, attrValue);
const passedOptions = {
run: command,
enable(state) { return command(state) },
active(state) {
const {$from, to, node} = state.selection
if (node) return node.attrs[attrValue] === attrValue;
return to <= $from.end() && $from.parent.attrs[attrValue] === attrValue;
}
}
for (const prop in options) passedOptions[prop] = options[prop]
return new MenuItem(passedOptions)
}
// Work around classList.toggle being broken in IE11
function setClass(dom, cls, on) {
if (on) dom.classList.add(cls)