UNPKG

4 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2import _createClass from "@babel/runtime/helpers/createClass";
3import _inherits from "@babel/runtime/helpers/inherits";
4import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6function _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); }; }
7function _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; } }
8import { Slice } from 'prosemirror-model';
9import { ReplaceStep, Step, StepMap, StepResult } from 'prosemirror-transform';
10export var insertTypeAheadStepType = 'atlaskit-insert-type-ahead';
11export var InsertTypeAheadStages = /*#__PURE__*/function (InsertTypeAheadStages) {
12 InsertTypeAheadStages["DELETING_RAW_QUERY"] = "DELETING_RAW_QUERY";
13 InsertTypeAheadStages["INSERTING_ITEM"] = "INSERTING_ITEM";
14 return InsertTypeAheadStages;
15}({});
16export var InsertTypeAheadStep = /*#__PURE__*/function (_Step) {
17 _inherits(InsertTypeAheadStep, _Step);
18 var _super = _createSuper(InsertTypeAheadStep);
19 function InsertTypeAheadStep(_ref) {
20 var _this;
21 var stage = _ref.stage,
22 query = _ref.query,
23 trigger = _ref.trigger,
24 selectedIndex = _ref.selectedIndex;
25 var isInvertStep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
26 _classCallCheck(this, InsertTypeAheadStep);
27 _this = _super.call(this);
28 _this.isInvertStep = isInvertStep;
29 _this.stage = stage;
30 _this.query = query;
31 _this.trigger = trigger;
32 _this.selectedIndex = selectedIndex;
33 return _this;
34 }
35 _createClass(InsertTypeAheadStep, [{
36 key: "invert",
37 value: function invert() {
38 var config = {
39 stage: this.stage,
40 query: this.query,
41 trigger: this.trigger,
42 selectedIndex: this.selectedIndex
43 };
44 return new InsertTypeAheadStep(config, !this.isInvertStep);
45 }
46 }, {
47 key: "apply",
48 value: function apply(doc) {
49 return StepResult.ok(doc);
50 }
51 }, {
52 key: "merge",
53 value: function merge() {
54 return null;
55 }
56 }, {
57 key: "isInsertionStep",
58 value: function isInsertionStep() {
59 return !this.isInvertStep;
60 }
61 }, {
62 key: "isUndoingStep",
63 value: function isUndoingStep() {
64 return this.isInvertStep;
65 }
66 }, {
67 key: "map",
68 value: function map(mapping) {
69 var config = {
70 stage: this.stage,
71 query: this.query,
72 trigger: this.trigger,
73 selectedIndex: this.selectedIndex
74 };
75 // Return the same events, this step will never be removed
76 return new InsertTypeAheadStep(config, this.isInvertStep);
77 }
78 }, {
79 key: "getMap",
80 value: function getMap() {
81 return new StepMap([0, 0, 0]);
82 }
83 }, {
84 key: "toJSON",
85 value: function toJSON() {
86 // When serialized we should create a noop Replace step
87 return {
88 stepType: 'replace',
89 from: 0,
90 to: 0
91 };
92 }
93 }], [{
94 key: "fromJSON",
95 value: function fromJSON() {
96 // This is a "local custom step" once serialized
97 // we need to transform it in a no-operation action
98 return new ReplaceStep(0, 0, Slice.empty);
99 }
100 }]);
101 return InsertTypeAheadStep;
102}(Step);
103
104/** Register this step with Prosemirror */
105Step.jsonID(insertTypeAheadStepType, InsertTypeAheadStep);
\No newline at end of file