import { DOMParser, Schema } from 'prosemirror-model';
import { EditorState, Plugin } from 'prosemirror-state';
import { getAttrs } from './DocNodeSpec.js';
import EditorPlugins from './EditorPlugins.js';
import EditorSchema from './EditorSchema.js';
export default function convertFromDOMElement(el, schema, plugins) {
  var effectiveSchema = schema || EditorSchema;
  var effectivePlugins = plugins || EditorPlugins;
  var bodyEl = el.querySelector('body');

  // https://prosemirror.net/docs/ref/#model.ParseOptions.preserveWhitespace
  var doc = DOMParser.fromSchema(effectiveSchema).parse(el, {
    preserveWhitespace: true
  });
  if (bodyEl) {
    // Unfortunately the root node `doc` does not supoort `parseDOM`, thus
    // we'd have to assign its `attrs` manually.
    doc.attrs = getAttrs(bodyEl);
  }
  return EditorState.create({
    doc: doc,
    plugins: effectivePlugins
  });
}