import { Step } from 'prosemirror-transform';
import EditorSchema from './EditorSchema';
export default function rebaseDocWithSteps(clientID, docJSON, stepsJSON) {
  return new Promise(function (resolve, reject) {
    // TODO: Move this into a separate server request.
    var docNode = EditorSchema.nodeFromJSON(docJSON);
    var steps = stepsJSON.map(function (step) {
      var result = Step.fromJSON(EditorSchema, step);
      result.clientID = clientID;
      return result;
    });
    steps.forEach(function (step) {
      var result = step.apply(docNode);
      docNode = result.doc;
    });
    var newDocJSON = docNode.toJSON();
    var newStepsJSON = steps.map(function (step) {
      return step.toJSON();
    });
    resolve({
      docJSON: newDocJSON,
      stepsJSON: newStepsJSON
    });
  });
}