]> BookStack Code Mirror - bookstack/blobdiff - resources/js/editor/menu/menu.js
Added horizonal rule insert
[bookstack] / resources / js / editor / menu / menu.js
index b292794f82198226bdb1f01b11e8ebf08578efe1..082264e7e18b3ecbf7020ed62dae749d52abbd6c 100644 (file)
@@ -8,7 +8,7 @@
 import crel from "crelt"
 import {lift, joinUp, selectParentNode, wrapIn, setBlockType, toggleMark} from "prosemirror-commands"
 import {undo, redo} from "prosemirror-history"
-import {setBlockAttr} from "../commands";
+import {setBlockAttr, insertBlockBefore} from "../commands";
 
 import {getIcon, icons} from "./icons"
 
@@ -420,6 +420,19 @@ export function setAttrItem(attrName, attrValue, options) {
   return new MenuItem(passedOptions)
 }
 
+export function insertBlockBeforeItem(blockType, options) {
+  const command = insertBlockBefore(blockType);
+  const passedOptions = {
+    run: command,
+    enable(state) { return command(state) },
+    active(state) {
+      return false;
+    }
+  }
+  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)