1 | import _typeof from "@babel/runtime/helpers/typeof";
|
2 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
4 | import _createClass from "@babel/runtime/helpers/createClass";
|
5 | import _inherits from "@babel/runtime/helpers/inherits";
|
6 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
7 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
8 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
9 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
10 | 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); }; }
|
11 | 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; } }
|
12 | import { Step, StepResult } from 'prosemirror-transform';
|
13 | import { Slice, Fragment } from 'prosemirror-model';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export var SetAttrsStep = function (_Step) {
|
20 | _inherits(SetAttrsStep, _Step);
|
21 | var _super = _createSuper(SetAttrsStep);
|
22 | function SetAttrsStep(pos, attrs) {
|
23 | var _this;
|
24 | _classCallCheck(this, SetAttrsStep);
|
25 | _this = _super.call(this);
|
26 | _this.pos = pos;
|
27 | _this.attrs = attrs;
|
28 | return _this;
|
29 | }
|
30 | _createClass(SetAttrsStep, [{
|
31 | key: "apply",
|
32 | value: function apply(doc) {
|
33 | var target = doc.nodeAt(this.pos);
|
34 | if (!target) {
|
35 | return StepResult.fail('No node at given position');
|
36 | }
|
37 | if (target.isText) {
|
38 | return StepResult.fail('Target is a text node. Attributes are not allowed.');
|
39 | }
|
40 | var attrs = _objectSpread(_objectSpread({}, target.attrs || {}), this.attrs || {});
|
41 | var newNode = target.type.create(attrs, Fragment.empty, target.marks);
|
42 | var slice = new Slice(Fragment.from(newNode), 0, target.isLeaf ? 0 : 1);
|
43 | return StepResult.fromReplace(doc, this.pos, this.pos + 1, slice);
|
44 | }
|
45 | }, {
|
46 | key: "invert",
|
47 | value: function invert(doc) {
|
48 | var target = doc.nodeAt(this.pos);
|
49 | return new SetAttrsStep(this.pos, target ? target.attrs : {});
|
50 | }
|
51 | }, {
|
52 | key: "map",
|
53 | value: function map(mapping) {
|
54 | var result = mapping.mapResult(this.pos, 1);
|
55 | return result.deleted ? null : new SetAttrsStep(result.pos, this.attrs);
|
56 | }
|
57 | }, {
|
58 | key: "toJSON",
|
59 | value: function toJSON() {
|
60 | return {
|
61 | stepType: 'setAttrs',
|
62 | pos: this.pos,
|
63 | attrs: this.attrs
|
64 | };
|
65 | }
|
66 | }], [{
|
67 | key: "fromJSON",
|
68 | value: function fromJSON(_schema, json) {
|
69 | if (typeof json.pos !== 'number' || json.attrs !== null && _typeof(json.attrs) !== 'object') {
|
70 | throw new RangeError('Invalid input for SetAttrsStep.fromJSON');
|
71 | }
|
72 | return new SetAttrsStep(json.pos, json.attrs);
|
73 | }
|
74 | }]);
|
75 | return SetAttrsStep;
|
76 | }(Step);
|
77 | Step.jsonID('setAttrs', SetAttrsStep); |
\ | No newline at end of file |