import { InputRule } from 'prosemirror-inputrules';
import { EditorState } from 'prosemirror-state';
import { Transform } from 'prosemirror-transform';
import { BLOCKQUOTE } from './NodeNames.js';
import toggleBlockquote from './toggleBlockquote.js';

// Given a blockquote node type, returns an input rule that turns `"> "`
// at the start of a textblock into a blockquote.
var MACRO_PATTERN = /^\s*>\s$/;
function handleBlockQuoteInputRule(state, match, start, end) {
  var schema = state.schema;
  var tr = state.tr;
  var nodeType = schema.nodes[BLOCKQUOTE];
  if (!nodeType) {
    return tr;
  }
  tr = toggleBlockquote(tr, schema);
  if (tr.docChanged) {
    tr = tr["delete"](start, end);
  }
  return tr;
}
export default function blockQuoteInputRule() {
  return new InputRule(MACRO_PATTERN, handleBlockQuoteInputRule);
}