@difizen/libro-codemirror 0.0.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/auto-complete/closebrackets.d.ts +12 -0
  4. package/es/auto-complete/closebrackets.d.ts.map +1 -0
  5. package/es/auto-complete/closebrackets.js +408 -0
  6. package/es/auto-complete/completion.d.ts +57 -0
  7. package/es/auto-complete/completion.d.ts.map +1 -0
  8. package/es/auto-complete/completion.js +265 -0
  9. package/es/auto-complete/config.d.ts +22 -0
  10. package/es/auto-complete/config.d.ts.map +1 -0
  11. package/es/auto-complete/config.js +44 -0
  12. package/es/auto-complete/filter.d.ts +13 -0
  13. package/es/auto-complete/filter.d.ts.map +1 -0
  14. package/es/auto-complete/filter.js +191 -0
  15. package/es/auto-complete/index.d.ts +17 -0
  16. package/es/auto-complete/index.d.ts.map +1 -0
  17. package/es/auto-complete/index.js +107 -0
  18. package/es/auto-complete/snippet.d.ts +14 -0
  19. package/es/auto-complete/snippet.d.ts.map +1 -0
  20. package/es/auto-complete/snippet.js +447 -0
  21. package/es/auto-complete/state.d.ts +63 -0
  22. package/es/auto-complete/state.d.ts.map +1 -0
  23. package/es/auto-complete/state.js +452 -0
  24. package/es/auto-complete/theme.d.ts +6 -0
  25. package/es/auto-complete/theme.d.ts.map +1 -0
  26. package/es/auto-complete/theme.js +151 -0
  27. package/es/auto-complete/tooltip.d.ts +5 -0
  28. package/es/auto-complete/tooltip.d.ts.map +1 -0
  29. package/es/auto-complete/tooltip.js +365 -0
  30. package/es/auto-complete/view.d.ts +43 -0
  31. package/es/auto-complete/view.d.ts.map +1 -0
  32. package/es/auto-complete/view.js +372 -0
  33. package/es/auto-complete/word.d.ts +3 -0
  34. package/es/auto-complete/word.d.ts.map +1 -0
  35. package/es/auto-complete/word.js +119 -0
  36. package/es/completion.d.ts +6 -0
  37. package/es/completion.d.ts.map +1 -0
  38. package/es/completion.js +84 -0
  39. package/es/config.d.ts +184 -0
  40. package/es/config.d.ts.map +1 -0
  41. package/es/config.js +473 -0
  42. package/es/editor.d.ts +361 -0
  43. package/es/editor.d.ts.map +1 -0
  44. package/es/editor.js +1126 -0
  45. package/es/factory.d.ts +3 -0
  46. package/es/factory.d.ts.map +1 -0
  47. package/es/factory.js +12 -0
  48. package/es/hyperlink.d.ts +15 -0
  49. package/es/hyperlink.d.ts.map +1 -0
  50. package/es/hyperlink.js +120 -0
  51. package/es/indent.d.ts +8 -0
  52. package/es/indent.d.ts.map +1 -0
  53. package/es/indent.js +58 -0
  54. package/es/indentation-markers/config.d.ts +17 -0
  55. package/es/indentation-markers/config.d.ts.map +1 -0
  56. package/es/indentation-markers/config.js +10 -0
  57. package/es/indentation-markers/index.d.ts +3 -0
  58. package/es/indentation-markers/index.d.ts.map +1 -0
  59. package/es/indentation-markers/index.js +160 -0
  60. package/es/indentation-markers/map.d.ts +77 -0
  61. package/es/indentation-markers/map.d.ts.map +1 -0
  62. package/es/indentation-markers/map.js +265 -0
  63. package/es/indentation-markers/utils.d.ts +27 -0
  64. package/es/indentation-markers/utils.d.ts.map +1 -0
  65. package/es/indentation-markers/utils.js +91 -0
  66. package/es/index.d.ts +11 -0
  67. package/es/index.d.ts.map +1 -0
  68. package/es/index.js +10 -0
  69. package/es/libro-icon.d.ts +3 -0
  70. package/es/libro-icon.d.ts.map +1 -0
  71. package/es/libro-icon.js +2 -0
  72. package/es/mimetype.d.ts +22 -0
  73. package/es/mimetype.d.ts.map +1 -0
  74. package/es/mimetype.js +59 -0
  75. package/es/mode.d.ts +86 -0
  76. package/es/mode.d.ts.map +1 -0
  77. package/es/mode.js +284 -0
  78. package/es/monitor.d.ts +32 -0
  79. package/es/monitor.d.ts.map +1 -0
  80. package/es/monitor.js +129 -0
  81. package/es/python-lang.d.ts +3 -0
  82. package/es/python-lang.d.ts.map +1 -0
  83. package/es/python-lang.js +7 -0
  84. package/es/style/base.css +131 -0
  85. package/es/style/theme.css +12 -0
  86. package/es/style/variables.css +403 -0
  87. package/es/theme.d.ts +35 -0
  88. package/es/theme.d.ts.map +1 -0
  89. package/es/theme.js +225 -0
  90. package/es/tooltip.d.ts +10 -0
  91. package/es/tooltip.d.ts.map +1 -0
  92. package/es/tooltip.js +170 -0
  93. package/package.json +74 -0
  94. package/src/auto-complete/README.md +71 -0
  95. package/src/auto-complete/closebrackets.ts +423 -0
  96. package/src/auto-complete/completion.ts +345 -0
  97. package/src/auto-complete/config.ts +101 -0
  98. package/src/auto-complete/filter.ts +215 -0
  99. package/src/auto-complete/index.ts +112 -0
  100. package/src/auto-complete/snippet.ts +394 -0
  101. package/src/auto-complete/state.ts +472 -0
  102. package/src/auto-complete/theme.ts +126 -0
  103. package/src/auto-complete/tooltip.ts +386 -0
  104. package/src/auto-complete/view.ts +343 -0
  105. package/src/auto-complete/word.ts +118 -0
  106. package/src/completion.ts +61 -0
  107. package/src/config.ts +689 -0
  108. package/src/editor.ts +1078 -0
  109. package/src/factory.ts +10 -0
  110. package/src/hyperlink.ts +95 -0
  111. package/src/indent.ts +69 -0
  112. package/src/indentation-markers/config.ts +31 -0
  113. package/src/indentation-markers/index.ts +192 -0
  114. package/src/indentation-markers/map.ts +273 -0
  115. package/src/indentation-markers/utils.ts +84 -0
  116. package/src/index.ts +11 -0
  117. package/src/libro-icon.ts +4 -0
  118. package/src/mimetype.ts +49 -0
  119. package/src/mode.ts +269 -0
  120. package/src/monitor.ts +105 -0
  121. package/src/python-lang.ts +7 -0
  122. package/src/style/base.css +129 -0
  123. package/src/style/theme.css +12 -0
  124. package/src/style/variables.css +405 -0
  125. package/src/theme.ts +231 -0
  126. package/src/tooltip.ts +145 -0
@@ -0,0 +1,452 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
3
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
4
+ 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); }; }
5
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
6
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
7
+ 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; } }
8
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
9
+ 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; }
10
+ 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; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
18
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
19
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
20
+ /* eslint-disable @typescript-eslint/no-this-alias */
21
+ /* eslint-disable @typescript-eslint/no-use-before-define */
22
+ /* eslint-disable @typescript-eslint/no-parameter-properties */
23
+ /* eslint-disable @typescript-eslint/parameter-properties */
24
+ /* eslint-disable prefer-const */
25
+
26
+ import { StateField, StateEffect } from '@codemirror/state';
27
+ import { EditorView, showTooltip } from '@codemirror/view';
28
+ import { Option, cur, asSource, ensureAnchor, CompletionContext } from "./completion.js";
29
+ import { completionConfig } from "./config.js";
30
+ import { FuzzyMatcher } from "./filter.js";
31
+ import { completionTooltip } from "./tooltip.js";
32
+
33
+ // Used to pick a preferred option when two options with the same
34
+ // label occur in the result.
35
+ function score(option) {
36
+ return (option.boost || 0) * 100 + (option.apply ? 10 : 0) + (option.info ? 5 : 0) + (option.type ? 1 : 0);
37
+ }
38
+ function sortOptions(active, state) {
39
+ var options = [],
40
+ i = 0;
41
+ var _iterator = _createForOfIteratorHelper(active),
42
+ _step;
43
+ try {
44
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
45
+ var a = _step.value;
46
+ if (a.hasResult()) {
47
+ if (a.result.filter === false) {
48
+ var getMatch = a.result.getMatch;
49
+ var _iterator3 = _createForOfIteratorHelper(a.result.options),
50
+ _step3;
51
+ try {
52
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
53
+ var option = _step3.value;
54
+ var match = [1e9 - i++];
55
+ if (getMatch) {
56
+ var _iterator4 = _createForOfIteratorHelper(getMatch(option)),
57
+ _step4;
58
+ try {
59
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
60
+ var n = _step4.value;
61
+ match.push(n);
62
+ }
63
+ } catch (err) {
64
+ _iterator4.e(err);
65
+ } finally {
66
+ _iterator4.f();
67
+ }
68
+ }
69
+ options.push(new Option(option, a, match));
70
+ }
71
+ } catch (err) {
72
+ _iterator3.e(err);
73
+ } finally {
74
+ _iterator3.f();
75
+ }
76
+ } else {
77
+ var matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to)),
78
+ _match = void 0;
79
+ var _iterator5 = _createForOfIteratorHelper(a.result.options),
80
+ _step5;
81
+ try {
82
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
83
+ var _option = _step5.value;
84
+ if (_match = matcher.match(_option.label)) {
85
+ if (_option.boost !== undefined) {
86
+ _match[0] += _option.boost;
87
+ }
88
+ options.push(new Option(_option, a, _match));
89
+ }
90
+ }
91
+ } catch (err) {
92
+ _iterator5.e(err);
93
+ } finally {
94
+ _iterator5.f();
95
+ }
96
+ }
97
+ }
98
+ }
99
+ } catch (err) {
100
+ _iterator.e(err);
101
+ } finally {
102
+ _iterator.f();
103
+ }
104
+ var result = [],
105
+ prev = null;
106
+ var compare = state.facet(completionConfig).compareCompletions;
107
+ var _iterator2 = _createForOfIteratorHelper(options.sort(function (a, b) {
108
+ return b.match[0] - a.match[0] || compare(a.completion, b.completion);
109
+ })),
110
+ _step2;
111
+ try {
112
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
113
+ var opt = _step2.value;
114
+ if (!prev || prev.label !== opt.completion.label || prev.detail !== opt.completion.detail || prev.type !== null && opt.completion.type !== null && prev.type !== opt.completion.type || prev.apply !== opt.completion.apply) {
115
+ result.push(opt);
116
+ } else if (score(opt.completion) > score(prev)) {
117
+ result[result.length - 1] = opt;
118
+ }
119
+ prev = opt.completion;
120
+ }
121
+ } catch (err) {
122
+ _iterator2.e(err);
123
+ } finally {
124
+ _iterator2.f();
125
+ }
126
+ return result;
127
+ }
128
+ var CompletionDialog = /*#__PURE__*/function () {
129
+ function CompletionDialog(options, attrs, tooltip, timestamp, selected) {
130
+ _classCallCheck(this, CompletionDialog);
131
+ this.options = options;
132
+ this.attrs = attrs;
133
+ this.tooltip = tooltip;
134
+ this.timestamp = timestamp;
135
+ this.selected = selected;
136
+ }
137
+ _createClass(CompletionDialog, [{
138
+ key: "setSelected",
139
+ value: function setSelected(selected, id) {
140
+ return selected === this.selected || selected >= this.options.length ? this : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected);
141
+ }
142
+ }, {
143
+ key: "map",
144
+ value: function map(changes) {
145
+ return new CompletionDialog(this.options, this.attrs, _objectSpread(_objectSpread({}, this.tooltip), {}, {
146
+ pos: changes.mapPos(this.tooltip.pos)
147
+ }), this.timestamp, this.selected);
148
+ }
149
+ }], [{
150
+ key: "build",
151
+ value: function build(active, state, id, prev, conf) {
152
+ var options = sortOptions(active, state);
153
+ if (!options.length) {
154
+ return null;
155
+ }
156
+ var selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
157
+ if (prev && prev.selected !== selected && prev.selected !== -1) {
158
+ var selectedValue = prev.options[prev.selected].completion;
159
+ for (var i = 0; i < options.length; i++) {
160
+ if (options[i].completion === selectedValue) {
161
+ selected = i;
162
+ break;
163
+ }
164
+ }
165
+ }
166
+ return new CompletionDialog(options, makeAttrs(id, selected), {
167
+ pos: active.reduce(function (a, b) {
168
+ return b.hasResult() ? Math.min(a, b.from) : a;
169
+ }, 1e8),
170
+ create: completionTooltip(completionState),
171
+ above: conf.aboveCursor
172
+ }, prev ? prev.timestamp : Date.now(), selected);
173
+ }
174
+ }]);
175
+ return CompletionDialog;
176
+ }();
177
+ export var CompletionState = /*#__PURE__*/function () {
178
+ function CompletionState(active, id, open) {
179
+ _classCallCheck(this, CompletionState);
180
+ this.active = active;
181
+ this.id = id;
182
+ this.open = open;
183
+ }
184
+ _createClass(CompletionState, [{
185
+ key: "update",
186
+ value: function update(tr) {
187
+ var _this = this;
188
+ var state = tr.state,
189
+ conf = state.facet(completionConfig);
190
+ var sources = conf.override || state.languageDataAt('autocomplete', cur(state)).map(asSource);
191
+ var active = sources.map(function (source) {
192
+ var value = _this.active.find(function (s) {
193
+ return s.source === source;
194
+ }) || new ActiveSource(source, _this.active.some(function (a) {
195
+ return a.state !== State.Inactive;
196
+ }) ? State.Pending : State.Inactive);
197
+ return value.update(tr, conf);
198
+ });
199
+ if (active.length === this.active.length && active.every(function (a, i) {
200
+ return a === _this.active[i];
201
+ })) {
202
+ active = this.active;
203
+ }
204
+ var open = tr.selection || active.some(function (a) {
205
+ return a.hasResult() && tr.changes.touchesRange(a.from, a.to);
206
+ }) || !sameResults(active, this.active) ? CompletionDialog.build(active, state, this.id, this.open, conf) : this.open && tr.docChanged ? this.open.map(tr.changes) : this.open;
207
+ if (!open && active.every(function (a) {
208
+ return a.state !== State.Pending;
209
+ }) && active.some(function (a) {
210
+ return a.hasResult();
211
+ })) {
212
+ active = active.map(function (a) {
213
+ return a.hasResult() ? new ActiveSource(a.source, State.Inactive) : a;
214
+ });
215
+ }
216
+ var _iterator6 = _createForOfIteratorHelper(tr.effects),
217
+ _step6;
218
+ try {
219
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
220
+ var effect = _step6.value;
221
+ if (effect.is(setSelectedEffect)) {
222
+ open = open && open.setSelected(effect.value, this.id);
223
+ }
224
+ }
225
+ } catch (err) {
226
+ _iterator6.e(err);
227
+ } finally {
228
+ _iterator6.f();
229
+ }
230
+ return active === this.active && open === this.open ? this : new CompletionState(active, this.id, open);
231
+ }
232
+ }, {
233
+ key: "tooltip",
234
+ get: function get() {
235
+ return this.open ? this.open.tooltip : null;
236
+ }
237
+ }, {
238
+ key: "attrs",
239
+ get: function get() {
240
+ return this.open ? this.open.attrs : baseAttrs;
241
+ }
242
+ }], [{
243
+ key: "start",
244
+ value: function start() {
245
+ return new CompletionState(none, 'cm-ac-' + Math.floor(Math.random() * 2e6).toString(36), null);
246
+ }
247
+ }]);
248
+ return CompletionState;
249
+ }();
250
+ function sameResults(a, b) {
251
+ if (a === b) {
252
+ return true;
253
+ }
254
+ for (var iA = 0, iB = 0;;) {
255
+ while (iA < a.length && !a[iA].hasResult) {
256
+ iA++;
257
+ }
258
+ while (iB < b.length && !b[iB].hasResult) {
259
+ iB++;
260
+ }
261
+ var endA = iA === a.length,
262
+ endB = iB === b.length;
263
+ if (endA || endB) {
264
+ return endA === endB;
265
+ }
266
+ if (a[iA++].result !== b[iB++].result) {
267
+ return false;
268
+ }
269
+ }
270
+ }
271
+ var baseAttrs = {
272
+ 'aria-autocomplete': 'list'
273
+ };
274
+ function makeAttrs(id, selected) {
275
+ var result = {
276
+ 'aria-autocomplete': 'list',
277
+ 'aria-haspopup': 'listbox',
278
+ 'aria-controls': id
279
+ };
280
+ if (selected > -1) {
281
+ result['aria-activedescendant'] = id + '-' + selected;
282
+ }
283
+ return result;
284
+ }
285
+ var none = [];
286
+ export var State = /*#__PURE__*/function (State) {
287
+ State[State["Inactive"] = 0] = "Inactive";
288
+ State[State["Pending"] = 1] = "Pending";
289
+ State[State["Result"] = 2] = "Result";
290
+ return State;
291
+ }({});
292
+ export function getUserEvent(tr) {
293
+ return tr.isUserEvent('input.type') ? 'input' : tr.isUserEvent('delete.backward') ? 'delete' : null;
294
+ }
295
+ export var ActiveSource = /*#__PURE__*/function () {
296
+ function ActiveSource(source, state) {
297
+ var explicitPos = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
298
+ _classCallCheck(this, ActiveSource);
299
+ this.source = source;
300
+ this.state = state;
301
+ this.explicitPos = explicitPos;
302
+ }
303
+ _createClass(ActiveSource, [{
304
+ key: "hasResult",
305
+ value: function hasResult() {
306
+ return false;
307
+ }
308
+ }, {
309
+ key: "update",
310
+ value: function update(tr, conf) {
311
+ var event = getUserEvent(tr),
312
+ value = this;
313
+ if (event) {
314
+ value = value.handleUserEvent(tr, event, conf);
315
+ } else if (tr.docChanged) {
316
+ value = value.handleChange(tr);
317
+ } else if (tr.selection && value.state !== State.Inactive) {
318
+ value = new ActiveSource(value.source, State.Inactive);
319
+ }
320
+ var _iterator7 = _createForOfIteratorHelper(tr.effects),
321
+ _step7;
322
+ try {
323
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
324
+ var effect = _step7.value;
325
+ if (effect.is(startCompletionEffect)) {
326
+ value = new ActiveSource(value.source, State.Pending, effect.value ? cur(tr.state) : -1);
327
+ } else if (effect.is(closeCompletionEffect)) {
328
+ value = new ActiveSource(value.source, State.Inactive);
329
+ } else if (effect.is(setActiveEffect)) {
330
+ var _iterator8 = _createForOfIteratorHelper(effect.value),
331
+ _step8;
332
+ try {
333
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
334
+ var _active = _step8.value;
335
+ if (_active.source === value.source) {
336
+ value = _active;
337
+ }
338
+ }
339
+ } catch (err) {
340
+ _iterator8.e(err);
341
+ } finally {
342
+ _iterator8.f();
343
+ }
344
+ }
345
+ }
346
+ } catch (err) {
347
+ _iterator7.e(err);
348
+ } finally {
349
+ _iterator7.f();
350
+ }
351
+ return value;
352
+ }
353
+ }, {
354
+ key: "handleUserEvent",
355
+ value: function handleUserEvent(tr, type, conf) {
356
+ return type === 'delete' || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, State.Pending);
357
+ }
358
+ }, {
359
+ key: "handleChange",
360
+ value: function handleChange(tr) {
361
+ return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, State.Inactive) : this.map(tr.changes);
362
+ }
363
+ }, {
364
+ key: "map",
365
+ value: function map(changes) {
366
+ return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
367
+ }
368
+ }]);
369
+ return ActiveSource;
370
+ }();
371
+ export var ActiveResult = /*#__PURE__*/function (_ActiveSource) {
372
+ _inherits(ActiveResult, _ActiveSource);
373
+ var _super = _createSuper(ActiveResult);
374
+ function ActiveResult(source, explicitPos, result, from, to) {
375
+ var _this2;
376
+ _classCallCheck(this, ActiveResult);
377
+ _this2 = _super.call(this, source, State.Result, explicitPos);
378
+ _this2.result = result;
379
+ _this2.from = from;
380
+ _this2.to = to;
381
+ return _this2;
382
+ }
383
+ _createClass(ActiveResult, [{
384
+ key: "hasResult",
385
+ value: function hasResult() {
386
+ return true;
387
+ }
388
+ }, {
389
+ key: "handleUserEvent",
390
+ value: function handleUserEvent(tr, type, conf) {
391
+ var from = tr.changes.mapPos(this.from),
392
+ to = tr.changes.mapPos(this.to, 1);
393
+ var pos = cur(tr.state);
394
+ if ((this.explicitPos < 0 ? pos <= from : pos < this.from) || pos > to || type === 'delete' && cur(tr.startState) === this.from) {
395
+ return new ActiveSource(this.source, type === 'input' && conf.activateOnTyping ? State.Pending : State.Inactive);
396
+ }
397
+ var explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos),
398
+ updated;
399
+ if (checkValid(this.result.validFor, tr.state, from, to)) {
400
+ return new ActiveResult(this.source, explicitPos, this.result, from, to);
401
+ }
402
+ if (this.result.update && (updated = this.result.update(this.result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0)))) {
403
+ var _updated$to;
404
+ return new ActiveResult(this.source, explicitPos, updated, updated.from, (_updated$to = updated.to) !== null && _updated$to !== void 0 ? _updated$to : cur(tr.state));
405
+ }
406
+ return new ActiveSource(this.source, State.Pending, explicitPos);
407
+ }
408
+ }, {
409
+ key: "handleChange",
410
+ value: function handleChange(tr) {
411
+ return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, State.Inactive) : this.map(tr.changes);
412
+ }
413
+ }, {
414
+ key: "map",
415
+ value: function map(mapping) {
416
+ return mapping.empty ? this : new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
417
+ }
418
+ }]);
419
+ return ActiveResult;
420
+ }(ActiveSource);
421
+ function checkValid(validFor, state, from, to) {
422
+ if (!validFor) {
423
+ return false;
424
+ }
425
+ var text = state.sliceDoc(from, to);
426
+ return typeof validFor === 'function' ? validFor(text, from, to, state) : ensureAnchor(validFor, true).test(text);
427
+ }
428
+ export var startCompletionEffect = StateEffect.define();
429
+ export var closeCompletionEffect = StateEffect.define();
430
+ export var setActiveEffect = StateEffect.define({
431
+ map: function map(sources, mapping) {
432
+ return sources.map(function (s) {
433
+ return s.map(mapping);
434
+ });
435
+ }
436
+ });
437
+ export var setSelectedEffect = StateEffect.define();
438
+ export var completionState = StateField.define({
439
+ create: function create() {
440
+ return CompletionState.start();
441
+ },
442
+ update: function update(value, tr) {
443
+ return value.update(tr);
444
+ },
445
+ provide: function provide(f) {
446
+ return [showTooltip.from(f, function (val) {
447
+ return val.tooltip;
448
+ }), EditorView.contentAttributes.from(f, function (state) {
449
+ return state.attrs;
450
+ })];
451
+ }
452
+ });
@@ -0,0 +1,6 @@
1
+ export declare const enum Info {
2
+ Margin = 30,
3
+ Width = 400
4
+ }
5
+ export declare const baseTheme: import("@codemirror/state").Extension;
6
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/auto-complete/theme.ts"],"names":[],"mappings":"AAEA,0BAAkB,IAAI;IACpB,MAAM,KAAK;IACX,KAAK,MAAM;CACZ;AAED,eAAO,MAAM,SAAS,uCAsHpB,CAAC"}
@@ -0,0 +1,151 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ export var Info = /*#__PURE__*/function (Info) {
3
+ Info[Info["Margin"] = 30] = "Margin";
4
+ Info[Info["Width"] = 400] = "Width";
5
+ return Info;
6
+ }({});
7
+ export var baseTheme = EditorView.baseTheme({
8
+ '.cm-tooltip.cm-tooltip-autocomplete': {
9
+ '& > ul': {
10
+ fontFamily: 'monospace',
11
+ whiteSpace: 'nowrap',
12
+ overflow: 'hidden auto',
13
+ maxWidth_fallback: '700px',
14
+ maxWidth: 'min(700px, 95vw)',
15
+ minWidth: '250px',
16
+ maxHeight: '10em',
17
+ listStyle: 'none',
18
+ margin: 0,
19
+ padding: 0,
20
+ '& > li': {
21
+ overflowX: 'hidden',
22
+ textOverflow: 'ellipsis',
23
+ cursor: 'pointer',
24
+ padding: '1px 3px',
25
+ lineHeight: 1.2
26
+ }
27
+ }
28
+ },
29
+ '&light .cm-tooltip-autocomplete ul li[aria-selected]': {
30
+ background: '#17c',
31
+ color: 'white'
32
+ },
33
+ '&dark .cm-tooltip-autocomplete ul li[aria-selected]': {
34
+ background: '#347',
35
+ color: 'white'
36
+ },
37
+ '.cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after': {
38
+ content: '"···"',
39
+ opacity: 0.5,
40
+ display: 'block',
41
+ textAlign: 'center'
42
+ },
43
+ '.cm-tooltip.cm-completionInfo': {
44
+ position: 'absolute',
45
+ padding: '3px 9px',
46
+ width: 'max-content',
47
+ maxWidth: "".concat(Info.Width, "px"),
48
+ boxSizing: 'border-box',
49
+ maxHeight: '500px',
50
+ overflow: 'auto'
51
+ },
52
+ '.cm-completionInfo.cm-completionInfo-left': {
53
+ right: '100%'
54
+ },
55
+ '.cm-completionInfo.cm-completionInfo-right': {
56
+ left: '100%'
57
+ },
58
+ '.cm-completionInfo.cm-completionInfo-left-narrow': {
59
+ right: "".concat(Info.Margin, "px")
60
+ },
61
+ '.cm-completionInfo.cm-completionInfo-right-narrow': {
62
+ left: "".concat(Info.Margin, "px")
63
+ },
64
+ '&light .cm-snippetField': {
65
+ backgroundColor: '#00000022'
66
+ },
67
+ '&dark .cm-snippetField': {
68
+ backgroundColor: '#ffffff22'
69
+ },
70
+ '.cm-snippetFieldPosition': {
71
+ verticalAlign: 'text-top',
72
+ width: 0,
73
+ height: '1.15em',
74
+ display: 'inline-block',
75
+ margin: '0 -0.7px -.7em',
76
+ borderLeft: '1.4px dotted #888'
77
+ },
78
+ '.cm-completionMatchedText': {
79
+ textDecoration: 'underline'
80
+ },
81
+ '.cm-completionDetail': {
82
+ marginLeft: '0.5em',
83
+ fontStyle: 'italic'
84
+ },
85
+ '.cm-completionIcon': {
86
+ fontSize: '90%',
87
+ width: '.8em',
88
+ display: 'inline-block',
89
+ textAlign: 'center',
90
+ paddingRight: '.6em',
91
+ opacity: '0.6'
92
+ },
93
+ '.cm-completionIcon-function, .cm-completionIcon-method': {
94
+ '&:after': {
95
+ content: "'ƒ'"
96
+ }
97
+ },
98
+ '.cm-completionIcon-class': {
99
+ '&:after': {
100
+ content: "'○'"
101
+ }
102
+ },
103
+ '.cm-completionIcon-interface': {
104
+ '&:after': {
105
+ content: "'◌'"
106
+ }
107
+ },
108
+ '.cm-completionIcon-variable': {
109
+ '&:after': {
110
+ content: "'𝑥'"
111
+ }
112
+ },
113
+ '.cm-completionIcon-constant': {
114
+ '&:after': {
115
+ content: "'𝐶'"
116
+ }
117
+ },
118
+ '.cm-completionIcon-type': {
119
+ '&:after': {
120
+ content: "'𝑡'"
121
+ }
122
+ },
123
+ '.cm-completionIcon-enum': {
124
+ '&:after': {
125
+ content: "'∪'"
126
+ }
127
+ },
128
+ '.cm-completionIcon-property': {
129
+ '&:after': {
130
+ content: "'□'"
131
+ }
132
+ },
133
+ '.cm-completionIcon-keyword': {
134
+ '&:after': {
135
+ content: "'\uD83D\uDD11\uFE0E'"
136
+ } // Disable emoji rendering
137
+ },
138
+
139
+ '.cm-completionIcon-namespace': {
140
+ '&:after': {
141
+ content: "'▢'"
142
+ }
143
+ },
144
+ '.cm-completionIcon-text': {
145
+ '&:after': {
146
+ content: "'abc'",
147
+ fontSize: '50%',
148
+ verticalAlign: 'middle'
149
+ }
150
+ }
151
+ });
@@ -0,0 +1,5 @@
1
+ import type { StateField } from '@codemirror/state';
2
+ import type { EditorView, TooltipView } from '@codemirror/view';
3
+ import type { CompletionState } from './state.js';
4
+ export declare function completionTooltip(stateField: StateField<CompletionState>): (view: EditorView) => TooltipView;
5
+ //# sourceMappingURL=tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/auto-complete/tooltip.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAc,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAyWlD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,CAAC,eAAe,CAAC,UACzD,UAAU,KAAG,WAAW,CACvC"}