2 MenuItem, Dropdown, DropdownSubmenu, renderGrouped, joinUpItem, liftItem, selectParentNodeItem,
3 undoItem, redoItem, wrapItem, blockTypeItem, setAttrItem, insertBlockBeforeItem,
5 import {icons} from "./icons";
6 import ColorPickerGrid from "./ColorPickerGrid";
7 import DialogBox from "./DialogBox";
8 import {toggleMark} from "prosemirror-commands";
9 import {menuBar} from "./menubar"
10 import schema from "../schema";
11 import {removeMarks} from "../commands";
12 import DialogForm from "./DialogForm";
13 import DialogInput from "./DialogInput";
15 import itemAnchorButtonItem from "./item-anchor-button";
16 import itemHtmlSourceButton from "./item-html-source-button";
19 function cmdItem(cmd, options) {
20 const passedOptions = {
24 for (const prop in options) {
25 passedOptions[prop] = options[prop];
27 if ((!options.enable || options.enable === true) && !options.select) {
28 passedOptions[options.enable ? "enable" : "select"] = function (state) {
33 return new MenuItem(passedOptions)
36 function markActive(state, type) {
37 const ref = state.selection;
38 const from = ref.from;
39 const $from = ref.$from;
41 const empty = ref.empty;
43 return type.isInSet(state.storedMarks || $from.marks())
45 return state.doc.rangeHasMark(from, to, type)
49 function markItem(markType, options) {
50 const passedOptions = {
51 active: function active(state) {
52 return markActive(state, markType)
56 for (const prop in options) {
57 passedOptions[prop] = options[prop];
60 return cmdItem(toggleMark(markType, passedOptions.attrs), passedOptions)
63 const inlineStyles = [
64 markItem(schema.marks.strong, {title: "Bold", icon: icons.strong}),
65 markItem(schema.marks.em, {title: "Italic", icon: icons.em}),
66 markItem(schema.marks.underline, {title: "Underline", icon: icons.underline}),
67 markItem(schema.marks.strike, {title: "Strikethrough", icon: icons.strike}),
68 markItem(schema.marks.superscript, {title: "Superscript", icon: icons.superscript}),
69 markItem(schema.marks.subscript, {title: "Subscript", icon: icons.subscript}),
73 blockTypeItem(schema.nodes.heading, {
74 label: "Header Large",
77 blockTypeItem(schema.nodes.heading, {
78 label: "Header Medium",
81 blockTypeItem(schema.nodes.heading, {
82 label: "Header Small",
85 blockTypeItem(schema.nodes.heading, {
89 blockTypeItem(schema.nodes.paragraph, {
93 markItem(schema.marks.code, {
98 blockTypeItem(schema.nodes.callout, {
99 label: "Info Callout",
100 attrs: {type: 'info'}
102 blockTypeItem(schema.nodes.callout, {
103 label: "Danger Callout",
104 attrs: {type: 'danger'}
106 blockTypeItem(schema.nodes.callout, {
107 label: "Success Callout",
108 attrs: {type: 'success'}
110 blockTypeItem(schema.nodes.callout, {
111 label: "Warning Callout",
112 attrs: {type: 'warning'}
114 ], { label: 'Callouts' }),
118 setAttrItem('align', 'left', {
119 icon: icons.align_left
121 setAttrItem('align', 'center', {
122 icon: icons.align_center
124 setAttrItem('align', 'right', {
125 icon: icons.align_right
127 setAttrItem('align', 'justify', {
128 icon: icons.align_justify
132 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"];
135 new DropdownSubmenu([
136 new ColorPickerGrid(schema.marks.text_color, 'color', colorOptions),
137 ], {icon: icons.text_color}),
138 new DropdownSubmenu([
139 new ColorPickerGrid(schema.marks.background_color, 'color', colorOptions),
140 ], {icon: icons.background_color}),
144 wrapItem(schema.nodes.bullet_list, {
145 title: "Bullet List",
146 icon: icons.bullet_list,
148 wrapItem(schema.nodes.ordered_list, {
149 title: "Ordered List",
150 icon: icons.ordered_list,
155 itemAnchorButtonItem(),
156 insertBlockBeforeItem(schema.nodes.horizontal_rule, {
157 title: "Horizontal Rule",
158 icon: icons.horizontal_rule,
160 itemHtmlSourceButton(),
165 title: 'Clear Formatting',
166 icon: icons.format_clear,
168 enable: state => true,
172 const menu = menuBar({
175 [undoItem, redoItem],
176 [new DropdownSubmenu(formats, { label: 'Formats' })],
188 // !! This module defines a number of building blocks for ProseMirror
189 // menus, along with a [menu bar](#menu.menuBar) implementation.
191 // MenuElement:: interface
192 // The types defined in this module aren't the only thing you can
193 // display in your menu. Anything that conforms to this interface can
194 // be put into a menu structure.
196 // render:: (pm: EditorView) → {dom: dom.Node, update: (EditorState) → bool}
197 // Render the element for display in the menu. Must return a DOM
198 // element and a function that can be used to update the element to
199 // a new state. The `update` function will return false if the
200 // update hid the entire element.