How to use the prosemirror-commands.setBlockType function in prosemirror-commands

To help you get started, we’ve selected a few prosemirror-commands examples, based on popular ways it is used in public projects.

github pubpub / pubpub-editor / src / plugins / keymap.js View on Github external
);
			return true;
		});
		bind('Mod-Enter', cmd);
		bind('Shift-Enter', cmd);
		if (mac) bind('Ctrl-Enter', cmd);
	}
	if (schema.nodes.list_item) {
		bind('Enter', splitListItem(schema.nodes.list_item));
		bind('Mod-[', liftListItem(schema.nodes.list_item));
		bind('Mod-]', sinkListItem(schema.nodes.list_item));
		bind('Tab', sinkListItem(schema.nodes.list_item));
		bind('Shift-Tab', liftListItem(schema.nodes.list_item));
	}
	if (schema.nodes.paragraph) {
		bind('Shift-Ctrl-0', setBlockType(schema.nodes.paragraph));
	}
	if (schema.nodes.code_block) {
		bind('Shift-Ctrl-\\', setBlockType(schema.nodes.code_block));
	}
	if (schema.nodes.heading) {
		for (let index = 1; index <= 6; index += 1) {
			bind(`Shift-Ctrl-${index}`, setBlockType(schema.nodes.heading, { level: index }));
		}
	}
	if (schema.nodes.horizontal_rule) {
		bind('Mod-_', (state, dispatch) => {
			dispatch(
				state.tr
					.replaceSelectionWith(schema.nodes.horizontal_rule.create())
					.scrollIntoView(),
			);
github pubpub / pubpub-editor / src / plugins / keymap.js View on Github external
bind('Mod-Enter', cmd);
		bind('Shift-Enter', cmd);
		if (mac) bind('Ctrl-Enter', cmd);
	}
	if (schema.nodes.list_item) {
		bind('Enter', splitListItem(schema.nodes.list_item));
		bind('Mod-[', liftListItem(schema.nodes.list_item));
		bind('Mod-]', sinkListItem(schema.nodes.list_item));
		bind('Tab', sinkListItem(schema.nodes.list_item));
		bind('Shift-Tab', liftListItem(schema.nodes.list_item));
	}
	if (schema.nodes.paragraph) {
		bind('Shift-Ctrl-0', setBlockType(schema.nodes.paragraph));
	}
	if (schema.nodes.code_block) {
		bind('Shift-Ctrl-\\', setBlockType(schema.nodes.code_block));
	}
	if (schema.nodes.heading) {
		for (let index = 1; index <= 6; index += 1) {
			bind(`Shift-Ctrl-${index}`, setBlockType(schema.nodes.heading, { level: index }));
		}
	}
	if (schema.nodes.horizontal_rule) {
		bind('Mod-_', (state, dispatch) => {
			dispatch(
				state.tr
					.replaceSelectionWith(schema.nodes.horizontal_rule.create())
					.scrollIntoView(),
			);
			return true;
		});
	}
github scrumpy / tiptap / packages / tiptap-commands / src / commands / toggleBlockType.js View on Github external
return (state, dispatch, view) => {
    const isActive = nodeIsActive(state, type, attrs)

    if (isActive) {
      return setBlockType(toggletype)(state, dispatch, view)
    }

    return setBlockType(type, attrs)(state, dispatch, view)
  }
}
github tinacms / tinacms / packages / tinacms / fields / src / Wysiwyg / state / plugins / keymap / keymap.ts View on Github external
bind('Mod-0', toggleMark(type))
  }

  /**
   * Blockquote
   */
  if ((type = schema.nodes.blockquote)) {
    bind('Mod->', wrapIn(type))
    bind('Mod-<', liftBlockquote)
  }

  /**
   * Paragraph – <p />
   */
  if ((type = schema.nodes.paragraph)) {
    bind('Mod-Alt-9', setBlockType(type))
    bind('Shift-Ctrl-0', setBlockType(type))
  }

  /**
   * Horizontal Rule
   */
  if ((type = schema.nodes.horizontal_rule)) {
    bind('Mod-Enter', insertHr)
  }

  /**
   * Lists
   */
  if ((type = schema.nodes.list_item)) {
    bind('Enter', splitListItem(type))
    bind('Tab', sinkListItem(type))
github pubpub / pubpub-editor / packages / pubpub-editor / src / prosemirror-setup / menu-config / menuItems.js View on Github external
function blockTypeItem(nodeType, options) {
	let command = setBlockType(nodeType, options.attrs)
	let passedOptions = {
		run: command,
		select(state) { return command(state) },
		active(state) {
			let {$from, to, node} = state.selection
			if (node) return node.hasMarkup(nodeType, options.attrs)
			return to <= $from.end() && $from.parent.hasMarkup(nodeType, options.attrs)
		}
	}
	for (let prop in options) passedOptions[prop] = options[prop]
	return new MenuItem(passedOptions)
}
exports.blockTypeItem = blockTypeItem
github cosmocode / dokuwiki-plugin-prosemirror / script / plugins / Menu / menu.js View on Github external
label: 'Wrap in ordered list',
});

const liftListItemMenuItem = new MenuItem({
    icon: svgIcon('arrow-expand-left'),
    command: liftListItem(schema.nodes.list_item),
    label: 'Lift list item',
});
const sinkListItemMenuItem = new MenuItem({
    icon: svgIcon('arrow-expand-right'),
    command: sinkListItem(schema.nodes.list_item),
    label: 'Sink list item',
});

const paragraphMenuItem = new MenuItem({
    command: setBlockType(schema.nodes.paragraph),
    icon: svgIcon('format-paragraph'),
    label: 'Paragraph',
});

const codeBlockMenuItem = new MenuItem({
    command: setBlockTypeNoAttrCheck(schema.nodes.code_block),
    icon: svgIcon('code-braces'),
    label: 'Code Block',
});

const blockquoteMenuItem = new MenuItem({
    command: wrapIn(schema.nodes.blockquote),
    icon: svgIcon('format-quote-close'),
    label: 'Blockquote',
});
github ProseMirror / prosemirror-example-setup / src / keymap.js View on Github external
})
    bind("Mod-Enter", cmd)
    bind("Shift-Enter", cmd)
    if (mac) bind("Ctrl-Enter", cmd)
  }
  if (type = schema.nodes.list_item) {
    bind("Enter", splitListItem(type))
    bind("Mod-[", liftListItem(type))
    bind("Mod-]", sinkListItem(type))
  }
  if (type = schema.nodes.paragraph)
    bind("Shift-Ctrl-0", setBlockType(type))
  if (type = schema.nodes.code_block)
    bind("Shift-Ctrl-\\", setBlockType(type))
  if (type = schema.nodes.heading)
    for (let i = 1; i <= 6; i++) bind("Shift-Ctrl-" + i, setBlockType(type, {level: i}))
  if (type = schema.nodes.horizontal_rule) {
    let hr = type
    bind("Mod-_", (state, dispatch) => {
      dispatch(state.tr.replaceSelectionWith(hr.create()).scrollIntoView())
      return true
    })
  }

  return keys
}
github ifiokjr / remirror / @remirror / core-extensions / src / nodes / heading-extension.ts View on Github external
this.options.levels.forEach(level => {
      keys[`Shift-Ctrl-${level}`] = setBlockType(type, { level });
    });
    return keys;
github netlify / netlify-cms / src / components / Widgets / Markdown / MarkdownControl / VisualEditor / keymap.js View on Github external
if (type = schema.nodes.hard_break) {
    let br = type, cmd = chainCommands(newlineInCode, (state, onAction) => {
        onAction(state.tr.replaceSelection(br.create()).scrollAction());
        return true;
      });
    bind('Mod-Enter', cmd);
    bind('Shift-Enter', cmd);
    if (mac) bind('Ctrl-Enter', cmd);
  }
  if (type = schema.nodes.list_item) {
    bind('Enter', splitListItem(type));
    bind('Mod-[', liftListItem(type));
    bind('Mod-]', sinkListItem(type));
  }
  if (type = schema.nodes.paragraph)
    bind('Shift-Ctrl-0', setBlockType(type));
  if (type = schema.nodes.code_block)
    bind('Shift-Ctrl-\\', setBlockType(type));
  if (type = schema.nodes.heading)
    for (let i = 1; i <= 6; i++) bind(`Shift-Ctrl-${ i }`, setBlockType(type, { level: i }));
  if (type = schema.nodes.horizontal_rule) {
    const hr = type;
    bind('Mod-_', (state, onAction) => {
      onAction(state.tr.replaceSelection(hr.create()).scrollAction());
      return true;
    });
  }

  if (schema.nodes.table_row) {
    bind('Tab', selectNextCell);
    bind('Shift-Tab', selectPreviousCell);
  }
github taktik / icure-backend / web / icure-ht / app / src / elements / prose-editor / prose-editor / prose-editor.ts View on Github external
doHeading(e: CustomEvent) {
    e.stopPropagation()
    e.preventDefault()
    if (this.editorView && e.detail && e.detail.value && e.detail.value.length) {
      setBlockType(this.editorSchema.nodes.heading, {level: parseInt(e.detail.value.replace(/.+ ([0-9]+)/, '$1'))})(this.editorView.state, this.editorView.dispatch)
      this.editorView.focus()
    }
  }