mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-15 12:41:52 +03:00
Added horizonal rule insert
This commit is contained in:
@ -33,6 +33,18 @@ export function setBlockAttr(attrName, attrValue) {
|
|||||||
dispatch(tr);
|
dispatch(tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function insertBlockBefore(blockType) {
|
||||||
|
return function (state, dispatch) {
|
||||||
|
const startPosition = state.selection.$from.before(1);
|
||||||
|
|
||||||
|
if (dispatch) {
|
||||||
|
dispatch(state.tr.insert(startPosition, blockType.create()));
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -101,6 +101,10 @@ export const icons = {
|
|||||||
width: 24, height: 24,
|
width: 24, height: 24,
|
||||||
path: "M3 21h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18V7H3v2zm0-6v2h18V3H3z"
|
path: "M3 21h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18V7H3v2zm0-6v2h18V3H3z"
|
||||||
},
|
},
|
||||||
|
horizontal_rule: {
|
||||||
|
width: 24, height: 24,
|
||||||
|
path: "m 4,11 h 16 v 2 H 4 Z"
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const SVG = "http://www.w3.org/2000/svg"
|
const SVG = "http://www.w3.org/2000/svg"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
MenuItem, Dropdown, DropdownSubmenu, renderGrouped, joinUpItem, liftItem, selectParentNodeItem,
|
MenuItem, Dropdown, DropdownSubmenu, renderGrouped, joinUpItem, liftItem, selectParentNodeItem,
|
||||||
undoItem, redoItem, wrapItem, blockTypeItem, setAttrItem,
|
undoItem, redoItem, wrapItem, blockTypeItem, setAttrItem, insertBlockBeforeItem,
|
||||||
} from "./menu"
|
} from "./menu"
|
||||||
import {icons} from "./icons";
|
import {icons} from "./icons";
|
||||||
import ColorPickerGrid from "./ColorPickerGrid";
|
import ColorPickerGrid from "./ColorPickerGrid";
|
||||||
@ -140,6 +140,13 @@ const lists = [
|
|||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const inserts = [
|
||||||
|
insertBlockBeforeItem(schema.nodes.horizontal_rule, {
|
||||||
|
title: "Horizontal Rule",
|
||||||
|
icon: icons.horizontal_rule,
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
const menu = menuBar({
|
const menu = menuBar({
|
||||||
floating: false,
|
floating: false,
|
||||||
content: [
|
content: [
|
||||||
@ -149,6 +156,7 @@ const menu = menuBar({
|
|||||||
colors,
|
colors,
|
||||||
alignments,
|
alignments,
|
||||||
lists,
|
lists,
|
||||||
|
inserts,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
import crel from "crelt"
|
import crel from "crelt"
|
||||||
import {lift, joinUp, selectParentNode, wrapIn, setBlockType, toggleMark} from "prosemirror-commands"
|
import {lift, joinUp, selectParentNode, wrapIn, setBlockType, toggleMark} from "prosemirror-commands"
|
||||||
import {undo, redo} from "prosemirror-history"
|
import {undo, redo} from "prosemirror-history"
|
||||||
import {setBlockAttr} from "../commands";
|
import {setBlockAttr, insertBlockBefore} from "../commands";
|
||||||
|
|
||||||
import {getIcon, icons} from "./icons"
|
import {getIcon, icons} from "./icons"
|
||||||
|
|
||||||
@ -420,6 +420,19 @@ export function setAttrItem(attrName, attrValue, options) {
|
|||||||
return new MenuItem(passedOptions)
|
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
|
// Work around classList.toggle being broken in IE11
|
||||||
function setClass(dom, cls, on) {
|
function setClass(dom, cls, on) {
|
||||||
if (on) dom.classList.add(cls)
|
if (on) dom.classList.add(cls)
|
||||||
|
@ -259,17 +259,9 @@ img.ProseMirror-separator {
|
|||||||
/* Add space around the hr to make clicking it easier */
|
/* Add space around the hr to make clicking it easier */
|
||||||
|
|
||||||
.ProseMirror-example-setup-style hr {
|
.ProseMirror-example-setup-style hr {
|
||||||
padding: 2px 10px;
|
border-top: 3px solid #FFF;
|
||||||
border: none;
|
border-bottom: 3px solid #FFF;
|
||||||
margin: 1em 0;
|
box-sizing: content-box;
|
||||||
}
|
|
||||||
|
|
||||||
.ProseMirror-example-setup-style hr:after {
|
|
||||||
content: "";
|
|
||||||
display: block;
|
|
||||||
height: 1px;
|
|
||||||
background-color: silver;
|
|
||||||
line-height: 2px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.ProseMirror ul, .ProseMirror ol {
|
.ProseMirror ul, .ProseMirror ol {
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>Lorem ipsum dolor sit amet.</p>
|
<p>Lorem ipsum dolor sit amet.</p>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
<p class="align-right">Lorem ipsum dolor sit amet.</p>
|
<p class="align-right">Lorem ipsum dolor sit amet.</p>
|
||||||
|
|
||||||
<p class="callout info">
|
<p class="callout info">
|
||||||
|
Reference in New Issue
Block a user