mirror of https://github.com/writeas/writefreely
A focused writing and publishing space.
https://write.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
834 B
26 lines
834 B
import { MenuItem } from "prosemirror-menu";
|
|
import { buildMenuItems } from "prosemirror-example-setup";
|
|
|
|
import { writeFreelySchema } from "./schema";
|
|
|
|
function canInsert(state, nodeType, attrs) {
|
|
let $from = state.selection.$from
|
|
for (let d = $from.depth; d >= 0; d--) {
|
|
let index = $from.index(d)
|
|
if ($from.node(d).canReplaceWith(index, index, nodeType, attrs)) return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
const ReadMoreItem = new MenuItem({
|
|
label: "Read more",
|
|
select: (state) => canInsert(state, writeFreelySchema.nodes.readmore),
|
|
run(state, dispatch) {
|
|
dispatch(state.tr.replaceSelectionWith(writeFreelySchema.nodes.readmore.create()))
|
|
},
|
|
});
|
|
|
|
export const getMenu = ()=> {
|
|
const menuContent = [...buildMenuItems(writeFreelySchema).fullMenu, [ReadMoreItem]];
|
|
return menuContent
|
|
}
|
|
|