Skip to content
Snippets Groups Projects
Commit 07e43e5d authored by chris's avatar chris
Browse files

create menu command files

parent 36f16d82
No related branches found
No related tags found
1 merge request!38Develop
...@@ -21,47 +21,13 @@ import TableDropDown from "../components/TableDropDown"; ...@@ -21,47 +21,13 @@ import TableDropDown from "../components/TableDropDown";
import ImageUpload from "../components/ImageUpload"; import ImageUpload from "../components/ImageUpload";
import HeadingsDropDown from "../components/HeadingsDropDown"; import HeadingsDropDown from "../components/HeadingsDropDown";
const markActive = type => state => { import {
const { from, $from, to, empty } = state.selection; markActive,
blockActive,
return empty canInsert,
? type.isInSet(state.storedMarks || $from.marks()) promptForURL,
: state.doc.rangeHasMark(from, to, type); createTable
}; } from "./MainMenuCommands";
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;
};
export default { export default {
undo: { undo: {
...@@ -279,23 +245,7 @@ export default { ...@@ -279,23 +245,7 @@ export default {
return canInsert(state.config.schema.nodes.table)(state); return canInsert(state.config.schema.nodes.table)(state);
}, },
run: (state, dispatch) => { run: (state, dispatch) => {
let rowCount = window && window.prompt("How many rows?", 2); return createTable(state, dispatch);
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));
}, },
select: state => true, select: state => true,
menu: props => <Button key={uuid()} {...props} /> 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"; ...@@ -3,16 +3,7 @@ import { v4 as uuid } from "uuid";
import { setBlockType } from "prosemirror-commands"; import { setBlockType } from "prosemirror-commands";
import Button from "../components/button/Button"; import Button from "../components/button/Button";
import { blockActive } from "./SideMenuItems";
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 default { export default {
title: { title: {
title: "Change to Title", title: "Change to Title",
......
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