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
}
}
\ No newline at end of file
width: 24, height: 24,
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"
import {
MenuItem, Dropdown, DropdownSubmenu, renderGrouped, joinUpItem, liftItem, selectParentNodeItem,
- undoItem, redoItem, wrapItem, blockTypeItem, setAttrItem,
+ undoItem, redoItem, wrapItem, blockTypeItem, setAttrItem, insertBlockBeforeItem,
} from "./menu"
import {icons} from "./icons";
import ColorPickerGrid from "./ColorPickerGrid";
}),
];
+const inserts = [
+ insertBlockBeforeItem(schema.nodes.horizontal_rule, {
+ title: "Horizontal Rule",
+ icon: icons.horizontal_rule,
+ }),
+];
+
const menu = menuBar({
floating: false,
content: [
colors,
alignments,
lists,
+ inserts,
],
});
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"
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)
/* Add space around the hr to make clicking it easier */
.ProseMirror-example-setup-style hr {
- padding: 2px 10px;
- border: none;
- margin: 1em 0;
-}
-
-.ProseMirror-example-setup-style hr:after {
- content: "";
- display: block;
- height: 1px;
- background-color: silver;
- line-height: 2px;
+ border-top: 3px solid #FFF;
+ border-bottom: 3px solid #FFF;
+ box-sizing: content-box;
}
.ProseMirror ul, .ProseMirror ol {
</ul>
<p>Lorem ipsum dolor sit amet.</p>
+
+ <hr>
+
<p class="align-right">Lorem ipsum dolor sit amet.</p>
<p class="callout info">