UNPKG

@atlaskit/editor-plugin-editor-viewmode-effects

Version:

Editor-Viewmode effects plugin for @atlaskit/editor-core

176 lines (175 loc) 4.94 kB
import _readOnlyError from "@babel/runtime/helpers/readOnlyError"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import { Slice } from '@atlaskit/editor-prosemirror/model'; import { ReplaceStep, Step, StepMap, StepResult } from '@atlaskit/editor-prosemirror/transform'; export var ViewModeStep = /*#__PURE__*/function (_Step) { function ViewModeStep(_ref) { var _this; var inverted = _ref.inverted, from = _ref.from, to = _ref.to, mark = _ref.mark; _classCallCheck(this, ViewModeStep); _this = _callSuper(this, ViewModeStep); _this.inverted = Boolean(inverted); _this.from = from; _this.to = to; _this.mark = mark; return _this; } _inherits(ViewModeStep, _Step); return _createClass(ViewModeStep, [{ key: "invert", value: function invert(doc) { return new ViewModeStep({ inverted: true, from: this.from, to: this.to, mark: this.mark }); } }, { key: "apply", value: function apply(doc) { return StepResult.ok(doc); } }, { key: "merge", value: function merge() { return null; } }, { key: "map", value: function map(mapping) { var mappedFrom = mapping.mapResult(this.from, 1); var mappedTo = mapping.mapResult(this.to, 1); if (mappedFrom.deleted || mappedTo.deleted) { return null; } return new ViewModeStep({ inverted: this.inverted, from: mappedFrom.pos, to: mappedTo.pos }); } }, { key: "getMap", value: function getMap() { return new StepMap([0, 0, 0]); } }, { key: "toJSON", value: function toJSON() { // When serialized we should create a noop Replace step return { stepType: 'replace', from: 0, to: 0 }; } }], [{ key: "fromJSON", value: function fromJSON() { // This is a "local custom step" once serialized // we need to transform it in a no-operation action return new ReplaceStep(0, 0, Slice.empty); } }, { key: "from", value: function from(step) { var mark = step.mark, from = step.from, to = step.to; return new ViewModeStep({ mark: mark, from: from, to: to }); } }]); }(Step); export var ViewModeNodeStep = /*#__PURE__*/function (_Step2) { function ViewModeNodeStep(_ref2) { var _this2; var inverted = _ref2.inverted, pos = _ref2.pos, mark = _ref2.mark; _classCallCheck(this, ViewModeNodeStep); _this2 = _callSuper(this, ViewModeNodeStep); _this2.inverted = Boolean(inverted); _this2.pos = pos; _this2.mark = mark; return _this2; } _inherits(ViewModeNodeStep, _Step2); return _createClass(ViewModeNodeStep, [{ key: "invert", value: function invert(doc) { return new ViewModeNodeStep({ inverted: true, pos: this.pos, mark: this.mark }); } }, { key: "apply", value: function apply(doc) { return StepResult.ok(doc); } }, { key: "merge", value: function merge() { return null; } }, { key: "map", value: function map(mapping) { var mappedPos = mapping.mapResult(this.pos, 1); if (mappedPos.deleted) { return null; } return new ViewModeNodeStep({ inverted: this.inverted, pos: mappedPos.pos }); } }, { key: "getMap", value: function getMap() { return new StepMap([0, 0, 0]); } }, { key: "toJSON", value: function toJSON() { // When serialized we should create a noop Replace step return { stepType: 'replace', from: 0, to: 0 }; } }], [{ key: "fromJSON", value: function fromJSON() { // This is a "local custom step" once serialized // we need to transform it in a no-operation action return new ReplaceStep(0, 0, Slice.empty); } }, { key: "from", value: function from(step) { var mark = step.mark, pos = step.pos; return new ViewModeNodeStep({ mark: mark, pos: pos }); } }]); }(Step);