@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
114 lines (113 loc) • 4.76 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.insertTypeAheadStepType = exports.InsertTypeAheadStep = exports.InsertTypeAheadStages = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _prosemirrorModel = require("prosemirror-model");
var _prosemirrorTransform = require("prosemirror-transform");
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(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; } }
var insertTypeAheadStepType = 'atlaskit-insert-type-ahead';
exports.insertTypeAheadStepType = insertTypeAheadStepType;
var InsertTypeAheadStages = /*#__PURE__*/function (InsertTypeAheadStages) {
InsertTypeAheadStages["DELETING_RAW_QUERY"] = "DELETING_RAW_QUERY";
InsertTypeAheadStages["INSERTING_ITEM"] = "INSERTING_ITEM";
return InsertTypeAheadStages;
}({});
exports.InsertTypeAheadStages = InsertTypeAheadStages;
var InsertTypeAheadStep = /*#__PURE__*/function (_Step) {
(0, _inherits2.default)(InsertTypeAheadStep, _Step);
var _super = _createSuper(InsertTypeAheadStep);
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;
(0, _classCallCheck2.default)(this, InsertTypeAheadStep);
_this = _super.call(this);
_this.isInvertStep = isInvertStep;
_this.stage = stage;
_this.query = query;
_this.trigger = trigger;
_this.selectedIndex = selectedIndex;
return _this;
}
(0, _createClass2.default)(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 _prosemirrorTransform.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(mapping) {
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 _prosemirrorTransform.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 _prosemirrorTransform.ReplaceStep(0, 0, _prosemirrorModel.Slice.empty);
}
}]);
return InsertTypeAheadStep;
}(_prosemirrorTransform.Step);
/** Register this step with Prosemirror */
exports.InsertTypeAheadStep = InsertTypeAheadStep;
_prosemirrorTransform.Step.jsonID(insertTypeAheadStepType, InsertTypeAheadStep);
;