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 TableCreatorGrid from "./TableCreatorGrid";
8 import {toggleMark} from "prosemirror-commands";
9 import {menuBar} from "./menubar"
10 import schema from "../schema";
11 import {removeMarks} from "../commands";
13 import itemAnchorButtonItem from "./item-anchor-button";
14 import itemHtmlSourceButton from "./item-html-source-button";
15 import itemIframeButton from "./item-iframe-button";
18 function cmdItem(cmd, options) {
19 const passedOptions = {
23 for (const prop in options) {
24 passedOptions[prop] = options[prop];
26 if ((!options.enable || options.enable === true) && !options.select) {
27 passedOptions[options.enable ? "enable" : "select"] = function (state) {
32 return new MenuItem(passedOptions)
35 function markActive(state, type) {
36 const ref = state.selection;
37 const from = ref.from;
38 const $from = ref.$from;
40 const empty = ref.empty;
42 return type.isInSet(state.storedMarks || $from.marks())
44 return state.doc.rangeHasMark(from, to, type)
48 function markItem(markType, options) {
49 const passedOptions = {
50 active: function active(state) {
51 return markActive(state, markType)
55 for (const prop in options) {
56 passedOptions[prop] = options[prop];
59 return cmdItem(toggleMark(markType, passedOptions.attrs), passedOptions)
62 const inlineStyles = [
63 markItem(schema.marks.strong, {title: "Bold", icon: icons.strong}),
64 markItem(schema.marks.em, {title: "Italic", icon: icons.em}),
65 markItem(schema.marks.underline, {title: "Underline", icon: icons.underline}),
66 markItem(schema.marks.strike, {title: "Strikethrough", icon: icons.strike}),
67 markItem(schema.marks.superscript, {title: "Superscript", icon: icons.superscript}),
68 markItem(schema.marks.subscript, {title: "Subscript", icon: icons.subscript}),
72 blockTypeItem(schema.nodes.heading, {
73 label: "Header Large",
76 blockTypeItem(schema.nodes.heading, {
77 label: "Header Medium",
80 blockTypeItem(schema.nodes.heading, {
81 label: "Header Small",
84 blockTypeItem(schema.nodes.heading, {
88 blockTypeItem(schema.nodes.paragraph, {
92 markItem(schema.marks.code, {
97 blockTypeItem(schema.nodes.callout, {
98 label: "Info Callout",
101 blockTypeItem(schema.nodes.callout, {
102 label: "Danger Callout",
103 attrs: {type: 'danger'}
105 blockTypeItem(schema.nodes.callout, {
106 label: "Success Callout",
107 attrs: {type: 'success'}
109 blockTypeItem(schema.nodes.callout, {
110 label: "Warning Callout",
111 attrs: {type: 'warning'}
113 ], { label: 'Callouts' }),
117 setAttrItem('align', 'left', {
118 icon: icons.align_left
120 setAttrItem('align', 'center', {
121 icon: icons.align_center
123 setAttrItem('align', 'right', {
124 icon: icons.align_right
126 setAttrItem('align', 'justify', {
127 icon: icons.align_justify
131 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"];
134 new DropdownSubmenu([
135 new ColorPickerGrid(schema.marks.text_color, 'color', colorOptions),
136 ], {icon: icons.text_color}),
137 new DropdownSubmenu([
138 new ColorPickerGrid(schema.marks.background_color, 'color', colorOptions),
139 ], {icon: icons.background_color}),
143 wrapItem(schema.nodes.bullet_list, {
144 title: "Bullet List",
145 icon: icons.bullet_list,
147 wrapItem(schema.nodes.ordered_list, {
148 title: "Ordered List",
149 icon: icons.ordered_list,
154 itemAnchorButtonItem(),
155 insertBlockBeforeItem(schema.nodes.horizontal_rule, {
156 title: "Horizontal Rule",
157 icon: icons.horizontal_rule,
159 new DropdownSubmenu([
160 new TableCreatorGrid()
161 ], {icon: icons.table}),
163 wrapItem(schema.nodes.details, {
164 title: "Dropdown Block",
171 title: 'Clear Formatting',
172 icon: icons.format_clear,
174 enable: state => true,
176 itemHtmlSourceButton(),
179 const menu = menuBar({
182 [undoItem, redoItem],
183 [new DropdownSubmenu(formats, { label: 'Formats' })],
195 // !! This module defines a number of building blocks for ProseMirror
196 // menus, along with a [menu bar](#menu.menuBar) implementation.
198 // MenuElement:: interface
199 // The types defined in this module aren't the only thing you can
200 // display in your menu. Anything that conforms to this interface can
201 // be put into a menu structure.
203 // render:: (pm: EditorView) → {dom: dom.Node, update: (EditorState) → bool}
204 // Render the element for display in the menu. Must return a DOM
205 // element and a function that can be used to update the element to
206 // a new state. The `update` function will return false if the
207 // update hid the entire element.