Commit 07e43e5d authored by chris's avatar chris

create menu command files

parent 36f16d82
......@@ -21,47 +21,13 @@ import TableDropDown from "../components/TableDropDown";
import ImageUpload from "../components/ImageUpload";
import HeadingsDropDown from "../components/HeadingsDropDown";
const markActive = type => state => {
const { from, $from, to, empty } = state.selection;
return empty
? type.isInSet(state.storedMarks || $from.marks())
: state.doc.rangeHasMark(from, to, type);
};
const blockActive = (type, attrs = {}) => state => {
const { $from, to, node } = state.selection;
if (node) {
return node.hasMarkup(type, attrs);
}
return to <= $from.end() && $from.parent.hasMarkup(type, attrs);
};
const canInsert = type => state => {
const { $from } = state.selection;
for (let d = $from.depth; d >= 0; d--) {
const index = $from.index(d);
if ($from.node(d).canReplaceWith(index, index, type)) {
return true;
}
}
return false;
};
const promptForURL = () => {
let url = window && window.prompt("Enter the URL", "https://");
if (url && !/^https?:\/\//i.test(url)) {
url = "http://" + url;
}
return url;
};
import {
markActive,
blockActive,
canInsert,
promptForURL,
createTable
} from "./MainMenuCommands";
export default {
undo: {
......@@ -279,23 +245,7 @@ export default {
return canInsert(state.config.schema.nodes.table)(state);
},
run: (state, dispatch) => {
let rowCount = window && window.prompt("How many rows?", 2);
let colCount = window && window.prompt("How many columns?", 2);
const cells = [];
while (colCount--) {
cells.push(state.config.schema.nodes.table_cell.createAndFill());
}
const rows = [];
while (rowCount--) {
rows.push(
state.config.schema.nodes.table_row.createAndFill(null, cells)
);
}
const table = state.config.schema.nodes.table.createAndFill(null, rows);
dispatch(state.tr.replaceSelectionWith(table));
return createTable(state, dispatch);
},
select: state => true,
menu: props => <Button key={uuid()} {...props} />
......
const markActive = type => state => {
const { from, $from, to, empty } = state.selection;
return empty
? type.isInSet(state.storedMarks || $from.marks())
: state.doc.rangeHasMark(from, to, type);
};
const blockActive = (type, attrs = {}) => state => {
const { $from, to, node } = state.selection;
if (node) {
return node.hasMarkup(type, attrs);
}
return to <= $from.end() && $from.parent.hasMarkup(type, attrs);
};
const canInsert = type => state => {
const { $from } = state.selection;
for (let d = $from.depth; d >= 0; d--) {
const index = $from.index(d);
if ($from.node(d).canReplaceWith(index, index, type)) {
return true;
}
}
return false;
};
const promptForURL = () => {
let url = window && window.prompt("Enter the URL", "https://");
if (url && !/^https?:\/\//i.test(url)) {
url = "http://" + url;
}
return url;
};
const createTable = (state, dispatch) => {
let rowCount = window && window.prompt("How many rows?", 2);
let colCount = window && window.prompt("How many columns?", 2);
const cells = [];
while (colCount--) {
cells.push(state.config.schema.nodes.table_cell.createAndFill());
}
const rows = [];
while (rowCount--) {
rows.push(state.config.schema.nodes.table_row.createAndFill(null, cells));
}
const table = state.config.schema.nodes.table.createAndFill(null, rows);
dispatch(state.tr.replaceSelectionWith(table));
};
export { markActive, blockActive, canInsert, promptForURL, createTable };
const blockActive = (type, attrs = {}) => state => {
const { $from, to, node } = state.selection;
if (node) {
return node.hasMarkup(type, attrs);
}
return to <= $from.end() && $from.parent.hasMarkup(type, attrs);
};
export { blockActive };
......@@ -3,16 +3,7 @@ import { v4 as uuid } from "uuid";
import { setBlockType } from "prosemirror-commands";
import Button from "../components/button/Button";
const blockActive = (type, attrs = {}) => state => {
const { $from, to, node } = state.selection;
if (node) {
return node.hasMarkup(type, attrs);
}
return to <= $from.end() && $from.parent.hasMarkup(type, attrs);
};
import { blockActive } from "./SideMenuItems";
export default {
title: {
title: "Change to Title",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment