A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
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.
 
 
 
 
 

33 lines
843 B

  1. import { MenuItem } from "prosemirror-menu";
  2. import { buildMenuItems } from "prosemirror-example-setup";
  3. import { writeFreelySchema } from "./schema";
  4. function canInsert(state, nodeType, attrs) {
  5. let $from = state.selection.$from;
  6. for (let d = $from.depth; d >= 0; d--) {
  7. let index = $from.index(d);
  8. if ($from.node(d).canReplaceWith(index, index, nodeType, attrs))
  9. return true;
  10. }
  11. return false;
  12. }
  13. const ReadMoreItem = new MenuItem({
  14. label: "Read more",
  15. select: (state) => canInsert(state, writeFreelySchema.nodes.readmore),
  16. run(state, dispatch) {
  17. dispatch(
  18. state.tr.replaceSelectionWith(writeFreelySchema.nodes.readmore.create())
  19. );
  20. },
  21. });
  22. export const getMenu = () => {
  23. const menuContent = [
  24. ...buildMenuItems(writeFreelySchema).fullMenu,
  25. [ReadMoreItem],
  26. ];
  27. return menuContent;
  28. };