/**
 * Blockquote Node Extension
 * 引用块节点
 */

import { NodeExtension } from '../../core/Extension';
import { wrappingInputRule } from 'prosemirror-inputrules';
import type { NodeSpec, Schema, InputRule } from '../../core/types';

export class Blockquote extends NodeExtension {
  get name() {
    return 'blockquote';
  }

  get schema(): NodeSpec {
    return {
      content: 'block+',
      group: 'block',
      defining: true,
      parseDOM: [{ tag: 'blockquote' }],
      toDOM() {
        return ['blockquote', { class: 'editor-blockquote' }, 0];
      },
    };
  }

  inputRules(schema: Schema): InputRule[] {
    const type = schema.nodes[this.name];
    if (!type) return [];

    return [
      // > 开头转换为引用块
      wrappingInputRule(/^\s*>\s$/, type),
    ];
  }
}

export default Blockquote;
