How to use the prosemirror-commands.chainCommands 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.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tinacms / tinacms / packages / tinacms / fields / src / Wysiwyg / state / plugins / keymap / keymap.ts View on Github external
})
  }

  /**
   * Underline – <span style="text-decoration: underline">
   */
  if ((type = schema.marks.underline)) {
    bind('Mod-u', toggleMark(type))
  }

  /**
   * Hard Break – <br>
   */
  if ((type = schema.nodes.hard_break)) {
    const br = type,
      cmd = chainCommands(exitCode, (state, dispatch) =&gt; {
        // @ts-ignore
        dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView())
        return true
      })
    if (!schema.nodes.paragraph) {
      bind('Enter', cmd)
    }
    bind('Mod-Enter', cmd)
    bind('Shift-Enter', cmd)
    if (mac) bind('Ctrl-Enter', cmd)
  }

  /**
   * Headings - 
   */
  if ((type = schema.nodes.heading)) {</span>
github zodiac-team / zodiac-ui / libs / editor / src / plugins / block-type / keymap.ts View on Github external
EXTERNAL = "external",
    FORMATTING = "autoformatting",
    FLOATING_TB = "floatingToolbar",
    KEYBOARD = "keyboard",
    INSERT_MENU = "insertMenu",
    MANUAL = "manual",
    PICKER = "picker",
    PICKER_CLOUD = "cloudPicker",
    QUICK_INSERT = "quickInsert",
    SHORTCUT = "shortcut",
    TOOLBAR = "toolbar",
    TYPEAHEAD = "typeAhead",
}

const not = (fn: (args: T) =&gt; boolean) =&gt; (arg: T) =&gt; !fn(arg)
const tryUndoInputRuleElseUndoHistory = chainCommands(undoInputRule, undoCmd)

export const removeBlockMarks = (
    state: EditorState,
    marks: Array,
): Transaction | undefined =&gt; {
    // tslint:disable-next-line:no-shadowed-variable
    const { selection, schema } = state
    let { tr } = state

    // Marks might not exist in Schema
    const marksToRemove = marks.filter(Boolean)
    if (marksToRemove.length === 0) {
        return undefined
    }

    /** Saves an extra dispatch */
github tinacms / tinacms / packages / tinacms / fields / src / Wysiwyg / state / plugins / keymap / keymap.ts View on Github external
function bind(key: string, cmd: any) {
    if (keys[key]) {
      cmd = chainCommands(cmd, keys[key])
    }
    keys[key] = cmd
  }
github tinacms / tinacms / packages / @tinacms / fields / src / Wysiwyg / state / buildKeymap.ts View on Github external
function bind(key: string, cmd: any) {
    if (keys[key]) {
      cmd = chainCommands(cmd, keys[key])
    }
    keys[key] = cmd
  }
github pubpub / pubpub-editor / src / schema / setup / keymap.js View on Github external
}
	if (schema.marks.link) {
		bind('Mod-k', toggleMark(schema.marks.link));
	}

	if (schema.nodes.bullet_list) {
		bind('Shift-Ctrl-8', wrapInList(schema.nodes.bullet_list));
	}
	if (schema.nodes.ordered_list) {
		bind('Shift-Ctrl-9', wrapInList(schema.nodes.ordered_list));
	}
	if (schema.nodes.blockquote) {
		bind('Ctrl->', wrapIn(schema.nodes.blockquote));
	}
	if (schema.nodes.hard_break) {
		const cmd = chainCommands(exitCode, (state, dispatch) => {
			dispatch(state.tr.replaceSelectionWith(schema.nodes.hard_break.create()).scrollIntoView());
			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));
github gamejolt / frontend-lib / components / content / content-editor / plugins / commands / keymap.ts View on Github external
'Mod-k': showLinkModal(editor.capabilities, schema),
	} as { [k: string]: any };

	const enterCommands = [] as PMKeymapCommand[];

	if (editor.capabilities.heading) {
		enterCommands.push(splitHeading());
	}

	if (editor.capabilities.list) {
		enterCommands.push(splitListItem(schema.nodes.listItem));
		keymap['Shift-Tab'] = ContentListService.liftListItem(schema.nodes.listItem);
		keymap['Tab'] = sinkListItem(schema.nodes.listItem);
	}

	keymap['Enter'] = chainCommands(...enterCommands);

	if (!isMac) {
		keymap['Mod-y'] = redo;
	}

	return keymap;
}
github ifiokjr / remirror / @remirror / core-extensions / src / nodes / hard-break-extension.ts View on Github external
public keys({ type }: ExtensionManagerNodeTypeParams) {
    const command = chainCommands(exitCode, (state, dispatch) => {
      if (dispatch) {
        dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
      }

      return true;
    });
    return {
      'Mod-Enter': command,
      'Shift-Enter': command,
    };
  }
}
github ifiokjr / remirror / @remirror / core-extensions / src / nodes / hard-break.ts View on Github external
public keys({ type }: SchemaNodeTypeParams) {
    const command = chainCommands(exitCode, (state, dispatch) => {
      if (dispatch) {
        dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
      }

      return true;
    });
    return {
      'Mod-Enter': command,
      'Shift-Enter': command,
    };
  }
}