@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
103 lines (102 loc) • 3.67 kB
JavaScript
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 insertTypeAheadStepType = 'atlaskit-insert-type-ahead';
export var InsertTypeAheadStages = /*#__PURE__*/function (InsertTypeAheadStages) {
InsertTypeAheadStages["DELETING_RAW_QUERY"] = "DELETING_RAW_QUERY";
InsertTypeAheadStages["INSERTING_ITEM"] = "INSERTING_ITEM";
return InsertTypeAheadStages;
}({});
export var InsertTypeAheadStep = /*#__PURE__*/function (_Step) {
function InsertTypeAheadStep(_ref) {
var _this;
var stage = _ref.stage,
query = _ref.query,
trigger = _ref.trigger,
selectedIndex = _ref.selectedIndex;
var isInvertStep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
_classCallCheck(this, InsertTypeAheadStep);
_this = _callSuper(this, InsertTypeAheadStep);
_this.isInvertStep = isInvertStep;
_this.stage = stage;
_this.query = query;
_this.trigger = trigger;
_this.selectedIndex = selectedIndex;
return _this;
}
_inherits(InsertTypeAheadStep, _Step);
return _createClass(InsertTypeAheadStep, [{
key: "invert",
value: function invert() {
var config = {
stage: this.stage,
query: this.query,
trigger: this.trigger,
selectedIndex: this.selectedIndex
};
return new InsertTypeAheadStep(config, !this.isInvertStep);
}
}, {
key: "apply",
value: function apply(doc) {
return StepResult.ok(doc);
}
}, {
key: "merge",
value: function merge() {
return null;
}
}, {
key: "isInsertionStep",
value: function isInsertionStep() {
return !this.isInvertStep;
}
}, {
key: "isUndoingStep",
value: function isUndoingStep() {
return this.isInvertStep;
}
}, {
key: "map",
value: function map() {
var config = {
stage: this.stage,
query: this.query,
trigger: this.trigger,
selectedIndex: this.selectedIndex
};
// Return the same events, this step will never be removed
return new InsertTypeAheadStep(config, this.isInvertStep);
}
}, {
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);
}
}]);
}(Step);
/** Register this step with Prosemirror */
Step.jsonID(insertTypeAheadStepType, InsertTypeAheadStep);