2 MenuItem, Dropdown, DropdownSubmenu, renderGrouped, joinUpItem, liftItem, selectParentNodeItem,
3 undoItem, redoItem, wrapItem, blockTypeItem, setAttrItem,
5 import {icons} from "./icons";
6 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", icon: icons.underline}),
60 markItem(schema.marks.strike, {title: "Strikethrough", icon: icons.strike}),
61 markItem(schema.marks.superscript, {title: "Superscript", icon: icons.superscript}),
62 markItem(schema.marks.subscript, {title: "Subscript", icon: icons.subscript}),
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', {
108 icon: icons.align_left
110 setAttrItem('align', 'center', {
111 icon: icons.align_center
113 setAttrItem('align', 'right', {
114 icon: icons.align_right
116 setAttrItem('align', 'justify', {
117 icon: icons.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 ], {icon: icons.text_color}),
127 new DropdownSubmenu([
128 new ColorPickerGrid(schema.marks.background_color, 'color', colorOptions),
129 ], {icon: icons.background_color}),
133 wrapItem(schema.nodes.bullet_list, {
134 title: "Bullet List",
135 icon: icons.bullet_list,
137 wrapItem(schema.nodes.ordered_list, {
138 title: "Ordered List",
139 icon: icons.ordered_list,
143 const menu = menuBar({
146 [undoItem, redoItem],
147 [new DropdownSubmenu(formats, { label: 'Formats' })],
157 // !! This module defines a number of building blocks for ProseMirror
158 // menus, along with a [menu bar](#menu.menuBar) implementation.
160 // MenuElement:: interface
161 // The types defined in this module aren't the only thing you can
162 // display in your menu. Anything that conforms to this interface can
163 // be put into a menu structure.
165 // render:: (pm: EditorView) → {dom: dom.Node, update: (EditorState) → bool}
166 // Render the element for display in the menu. Must return a DOM
167 // element and a function that can be used to update the element to
168 // a new state. The `update` function will return false if the
169 // update hid the entire element.