2 MenuItem, Dropdown, DropdownSubmenu, renderGrouped, icons, joinUpItem, liftItem, selectParentNodeItem,
3 undoItem, redoItem, wrapItem, blockTypeItem, setAttrItem,
6 import {toggleMark} from "prosemirror-commands";
7 import {menuBar} from "./menubar"
8 import schema from "../schema";
11 function cmdItem(cmd, options) {
12 const passedOptions = {
16 for (const prop in options) {
17 passedOptions[prop] = options[prop];
19 if ((!options.enable || options.enable === true) && !options.select) {
20 passedOptions[options.enable ? "enable" : "select"] = function (state) {
25 return new MenuItem(passedOptions)
28 function markActive(state, type) {
29 const ref = state.selection;
30 const from = ref.from;
31 const $from = ref.$from;
33 const empty = ref.empty;
35 return type.isInSet(state.storedMarks || $from.marks())
37 return state.doc.rangeHasMark(from, to, type)
41 function markItem(markType, options) {
42 const passedOptions = {
43 active: function active(state) {
44 return markActive(state, markType)
48 for (const prop in options) {
49 passedOptions[prop] = options[prop];
52 return cmdItem(toggleMark(markType), passedOptions)
55 const inlineStyles = [
56 markItem(schema.marks.strong, {title: "Bold", icon: icons.strong}),
57 markItem(schema.marks.em, {title: "Italic", icon: icons.em}),
58 markItem(schema.marks.underline, {title: "Underline", label: 'U'}),
59 markItem(schema.marks.strike, {title: "Strikethrough", label: '-S-'}),
60 markItem(schema.marks.superscript, {title: "Superscript", label: 'sup'}),
61 markItem(schema.marks.subscript, {title: "Subscript", label: 'sub'}),
65 blockTypeItem(schema.nodes.heading, {
66 label: "Header Large",
69 blockTypeItem(schema.nodes.heading, {
70 label: "Header Medium",
73 blockTypeItem(schema.nodes.heading, {
74 label: "Header Small",
77 blockTypeItem(schema.nodes.heading, {
81 blockTypeItem(schema.nodes.paragraph, {
86 blockTypeItem(schema.nodes.callout, {
87 label: "Info Callout",
90 blockTypeItem(schema.nodes.callout, {
91 label: "Danger Callout",
92 attrs: {type: 'danger'}
94 blockTypeItem(schema.nodes.callout, {
95 label: "Success Callout",
96 attrs: {type: 'success'}
98 blockTypeItem(schema.nodes.callout, {
99 label: "Warning Callout",
100 attrs: {type: 'warning'}
102 ], { label: 'Callouts' }),
106 setAttrItem('align', 'left', {
109 setAttrItem('align', 'right', {
112 setAttrItem('align', 'center', {
113 label: 'Align Center'
115 setAttrItem('align', 'justify', {
116 label: 'Align Justify'
120 const menu = menuBar({
123 [undoItem, redoItem],
124 [new DropdownSubmenu(formats, { label: 'Formats' })],
132 // !! This module defines a number of building blocks for ProseMirror
133 // menus, along with a [menu bar](#menu.menuBar) implementation.
135 // MenuElement:: interface
136 // The types defined in this module aren't the only thing you can
137 // display in your menu. Anything that conforms to this interface can
138 // be put into a menu structure.
140 // render:: (pm: EditorView) → {dom: dom.Node, update: (EditorState) → bool}
141 // Render the element for display in the menu. Must return a DOM
142 // element and a function that can be used to update the element to
143 // a new state. The `update` function will return false if the
144 // update hid the entire element.