function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import { Schema } from 'prosemirror-model';
import { EditorState } from 'prosemirror-state';
import { Plugin } from 'prosemirror-state';
import createEmptyEditorState from './createEmptyEditorState.js';
export default function convertFromJSON(json, schema, defaultSchema, effectivePlugins) {
  var editorSchema = schema || defaultSchema;
  var error = false;
  if (typeof json === 'string') {
    try {
      json = JSON.parse(json);
    } catch (ex) {
      console.error('convertFromJSON:', ex);
      error = true;
    }
  }
  if (!json || _typeof(json) !== 'object') {
    console.error('convertFromJSON: invalid object', json);
    error = true;
  }
  if (error) {
    // [FS] IRAD-1455 2021-06-16
    // Use the effectivePlugins, editor hangs, b'coz of missing default core plugins
    return createEmptyEditorState(schema, defaultSchema, effectivePlugins);
  }

  // [FS] IRAD-1067 2020-09-19
  // Handle gracefully when error thrown on invalid json
  var doc = null;
  try {
    doc = editorSchema.nodeFromJSON(json);
  } catch (error) {
    return null;
  }
  return EditorState.create({
    doc: doc,
    schema: editorSchema,
    plugins: effectivePlugins
  });
}