"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _prosemirrorTransform = require("prosemirror-transform");

var _prosemirrorModel = require("prosemirror-model");

var _prosemirrorState = require("prosemirror-state");

var _SimpleConnector = _interopRequireWildcard(require("./SimpleConnector"));

var _EditorConnection = _interopRequireDefault(require("./EditorConnection"));

var _Reporter = _interopRequireDefault(require("./Reporter"));

var _reactDom = _interopRequireDefault(require("react-dom"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

class CollabConnector extends _SimpleConnector.default {
  constructor(editorState, setState, config, _schema, plugins, onReady) {
    super(editorState, setState);

    _defineProperty(this, "_clientID", void 0);

    _defineProperty(this, "_connected", void 0);

    _defineProperty(this, "_connection", void 0);

    _defineProperty(this, "_docID", void 0);

    _defineProperty(this, "_stepKeys", void 0);

    _defineProperty(this, "onEdit", transaction => {
      if (!this._connection.ready) {
        console.warn('not ready');
        return;
      }

      _reactDom.default.unstable_batchedUpdates(() => {
        this._connection.dispatch({
          type: 'transaction',
          transaction
        });
      });
    });

    _defineProperty(this, "updateSchema", schema => {
      this._connection.updateSchema(schema);
    });

    const {
      docID,
      collabServiceURL
    } = config;
    this._docID = docID; // [FS] IRAD-1553 2021-08-26
    // Configurable Collaboration Service URL.

    const url = collabServiceURL + '/docs/' + docID;
    this._connection = new _EditorConnection.default(onReady, new _Reporter.default(), url, plugins, _schema);
    this._connection.view = {
      updateState: s => {
        setState({
          editorState: s
        }, () => {});
      }
    };
  }

}

var _default = CollabConnector;
exports.default = _default;