2 MenuItem, Dropdown, DropdownSubmenu, renderGrouped, icons, joinUpItem, liftItem, selectParentNodeItem,
3 undoItem, redoItem, wrapItem, blockTypeItem, setAttrItem,
5 import ColorPickerGrid from "./ColorPickerGrid";
7 import {toggleMark} from "prosemirror-commands";
8 import {menuBar} from "./menubar"
9 import schema from "../schema";
12 function cmdItem(cmd, options) {
13 const passedOptions = {
17 for (const prop in options) {
18 passedOptions[prop] = options[prop];
20 if ((!options.enable || options.enable === true) && !options.select) {
21 passedOptions[options.enable ? "enable" : "select"] = function (state) {
26 return new MenuItem(passedOptions)
29 function markActive(state, type) {
30 const ref = state.selection;
31 const from = ref.from;
32 const $from = ref.$from;
34 const empty = ref.empty;
36 return type.isInSet(state.storedMarks || $from.marks())
38 return state.doc.rangeHasMark(from, to, type)
42 function markItem(markType, options) {
43 const passedOptions = {
44 active: function active(state) {
45 return markActive(state, markType)
49 for (const prop in options) {
50 passedOptions[prop] = options[prop];
53 return cmdItem(toggleMark(markType, passedOptions.attrs), passedOptions)
56 const inlineStyles = [
57 markItem(schema.marks.strong, {title: "Bold", icon: icons.strong}),
58 markItem(schema.marks.em, {title: "Italic", icon: icons.em}),
59 markItem(schema.marks.underline, {title: "Underline", label: 'U'}),
60 markItem(schema.marks.strike, {title: "Strikethrough", label: '-S-'}),
61 markItem(schema.marks.superscript, {title: "Superscript", label: 'sup'}),
62 markItem(schema.marks.subscript, {title: "Subscript", label: 'sub'}),
66 blockTypeItem(schema.nodes.heading, {
67 label: "Header Large",
70 blockTypeItem(schema.nodes.heading, {
71 label: "Header Medium",
74 blockTypeItem(schema.nodes.heading, {
75 label: "Header Small",
78 blockTypeItem(schema.nodes.heading, {
82 blockTypeItem(schema.nodes.paragraph, {
87 blockTypeItem(schema.nodes.callout, {
88 label: "Info Callout",
91 blockTypeItem(schema.nodes.callout, {
92 label: "Danger Callout",
93 attrs: {type: 'danger'}
95 blockTypeItem(schema.nodes.callout, {
96 label: "Success Callout",
97 attrs: {type: 'success'}
99 blockTypeItem(schema.nodes.callout, {
100 label: "Warning Callout",
101 attrs: {type: 'warning'}
103 ], { label: 'Callouts' }),
107 setAttrItem('align', 'left', {
110 setAttrItem('align', 'right', {
113 setAttrItem('align', 'center', {
114 label: 'Align Center'
116 setAttrItem('align', 'justify', {
117 label: 'Align Justify'
121 const colorOptions = ["#000000","#993300","#333300","#003300","#003366","#000080","#333399","#333333","#800000","#FF6600","#808000","#008000","#008080","#0000FF","#666699","#808080","#FF0000","#FF9900","#99CC00","#339966","#33CCCC","#3366FF","#800080","#999999","#FF00FF","#FFCC00","#FFFF00","#00FF00","#00FFFF","#00CCFF","#993366","#FFFFFF","#FF99CC","#FFCC99","#FFFF99","#CCFFCC","#CCFFFF","#99CCFF","#CC99FF"];
124 new DropdownSubmenu([
125 new ColorPickerGrid(schema.marks.text_color, 'color', colorOptions),
126 ], {label: 'Text Color'}),
127 new DropdownSubmenu([
128 new ColorPickerGrid(schema.marks.background_color, 'color', colorOptions),
129 ], {label: 'Background Color'}),
132 const menu = menuBar({
135 [undoItem, redoItem],
136 [new DropdownSubmenu(formats, { label: 'Formats' })],
145 // !! This module defines a number of building blocks for ProseMirror
146 // menus, along with a [menu bar](#menu.menuBar) implementation.
148 // MenuElement:: interface
149 // The types defined in this module aren't the only thing you can
150 // display in your menu. Anything that conforms to this interface can
151 // be put into a menu structure.
153 // render:: (pm: EditorView) → {dom: dom.Node, update: (EditorState) → bool}
154 // Render the element for display in the menu. Must return a DOM
155 // element and a function that can be used to update the element to
156 // a new state. The `update` function will return false if the
157 // update hid the entire element.