UNPKG

@ant-design/pro-flow

Version:
63 lines 3.54 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import { Doc, UndoManager } from 'yjs'; var UserAction = /*#__PURE__*/_createClass(function UserAction(params) { _classCallCheck(this, UserAction); _defineProperty(this, "type", void 0); _defineProperty(this, "name", void 0); _defineProperty(this, "timestamp", void 0); this.type = params.type; this.name = params.name; this.timestamp = params.timestamp; }); export var DocWithHistoryManager = /*#__PURE__*/function (_Doc) { _inherits(DocWithHistoryManager, _Doc); var _super = _createSuper(DocWithHistoryManager); function DocWithHistoryManager(params) { var _this; _classCallCheck(this, DocWithHistoryManager); _this = _super.call(this, params); _defineProperty(_assertThisInitialized(_this), "_internalHistoryKey", '__INTERNAL_HISTORY_MAP__'); _defineProperty(_assertThisInitialized(_this), "undoManager", void 0); _defineProperty(_assertThisInitialized(_this), "updateHistoryData", function (value) { var map = _this.getMap(_this._internalHistoryKey); Object.entries(value).forEach(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1]; map.set(key, value); }); }); _defineProperty(_assertThisInitialized(_this), "recordHistoryData", function (value, userAction) { _this.transact(function () { _this.updateHistoryData(value); }, new UserAction(userAction)); }); _defineProperty(_assertThisInitialized(_this), "getHistoryMap", function () { return _this.getMap(_this._internalHistoryKey); }); _defineProperty(_assertThisInitialized(_this), "getHistoryJSON", function () { var map = _this.getMap(_this._internalHistoryKey); return map.toJSON(); }); _defineProperty(_assertThisInitialized(_this), "redo", function () { return _this.undoManager.redo(); }); _defineProperty(_assertThisInitialized(_this), "undo", function () { return _this.undoManager.undo(); }); _this.undoManager = new UndoManager(_this.getHistoryMap(), { trackedOrigins: new Set([UserAction]) }); return _this; } return _createClass(DocWithHistoryManager); }(Doc);