@difizen/libro-codemirror 0.0.0-snapshot-20241017072317

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 (163) 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 +409 -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 +267 -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 +190 -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 +445 -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 +448 -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 +150 -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 +38 -0
  31. package/es/auto-complete/view.d.ts.map +1 -0
  32. package/es/auto-complete/view.js +368 -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 +189 -0
  40. package/es/config.d.ts.map +1 -0
  41. package/es/config.js +482 -0
  42. package/es/editor-contribution.d.ts +9 -0
  43. package/es/editor-contribution.d.ts.map +1 -0
  44. package/es/editor-contribution.js +35 -0
  45. package/es/editor.d.ts +397 -0
  46. package/es/editor.d.ts.map +1 -0
  47. package/es/editor.js +1338 -0
  48. package/es/factory.d.ts +4 -0
  49. package/es/factory.d.ts.map +1 -0
  50. package/es/factory.js +24 -0
  51. package/es/hyperlink.d.ts +15 -0
  52. package/es/hyperlink.d.ts.map +1 -0
  53. package/es/hyperlink.js +120 -0
  54. package/es/indent.d.ts +8 -0
  55. package/es/indent.d.ts.map +1 -0
  56. package/es/indent.js +58 -0
  57. package/es/indentation-markers/config.d.ts +17 -0
  58. package/es/indentation-markers/config.d.ts.map +1 -0
  59. package/es/indentation-markers/config.js +10 -0
  60. package/es/indentation-markers/index.d.ts +3 -0
  61. package/es/indentation-markers/index.d.ts.map +1 -0
  62. package/es/indentation-markers/index.js +160 -0
  63. package/es/indentation-markers/map.d.ts +77 -0
  64. package/es/indentation-markers/map.d.ts.map +1 -0
  65. package/es/indentation-markers/map.js +265 -0
  66. package/es/indentation-markers/utils.d.ts +27 -0
  67. package/es/indentation-markers/utils.d.ts.map +1 -0
  68. package/es/indentation-markers/utils.js +91 -0
  69. package/es/index.d.ts +13 -0
  70. package/es/index.d.ts.map +1 -0
  71. package/es/index.js +12 -0
  72. package/es/libro-icon.d.ts +3 -0
  73. package/es/libro-icon.d.ts.map +1 -0
  74. package/es/libro-icon.js +2 -0
  75. package/es/lsp/completion.d.ts +5 -0
  76. package/es/lsp/completion.d.ts.map +1 -0
  77. package/es/lsp/completion.js +245 -0
  78. package/es/lsp/format.d.ts +7 -0
  79. package/es/lsp/format.d.ts.map +1 -0
  80. package/es/lsp/format.js +193 -0
  81. package/es/lsp/index.d.ts +7 -0
  82. package/es/lsp/index.d.ts.map +1 -0
  83. package/es/lsp/index.js +6 -0
  84. package/es/lsp/lint.d.ts +3 -0
  85. package/es/lsp/lint.d.ts.map +1 -0
  86. package/es/lsp/lint.js +113 -0
  87. package/es/lsp/protocol.d.ts +7 -0
  88. package/es/lsp/protocol.d.ts.map +1 -0
  89. package/es/lsp/protocol.js +1 -0
  90. package/es/lsp/tooltip.d.ts +3 -0
  91. package/es/lsp/tooltip.d.ts.map +1 -0
  92. package/es/lsp/tooltip.js +113 -0
  93. package/es/lsp/util.d.ts +15 -0
  94. package/es/lsp/util.d.ts.map +1 -0
  95. package/es/lsp/util.js +57 -0
  96. package/es/mimetype.d.ts +22 -0
  97. package/es/mimetype.d.ts.map +1 -0
  98. package/es/mimetype.js +59 -0
  99. package/es/mode.d.ts +86 -0
  100. package/es/mode.d.ts.map +1 -0
  101. package/es/mode.js +280 -0
  102. package/es/module.d.ts +3 -0
  103. package/es/module.d.ts.map +1 -0
  104. package/es/module.js +4 -0
  105. package/es/monitor.d.ts +32 -0
  106. package/es/monitor.d.ts.map +1 -0
  107. package/es/monitor.js +129 -0
  108. package/es/python-lang.d.ts +3 -0
  109. package/es/python-lang.d.ts.map +1 -0
  110. package/es/python-lang.js +7 -0
  111. package/es/style/base.css +129 -0
  112. package/es/style/theme.css +12 -0
  113. package/es/style/variables.css +405 -0
  114. package/es/theme.d.ts +35 -0
  115. package/es/theme.d.ts.map +1 -0
  116. package/es/theme.js +223 -0
  117. package/es/tooltip.d.ts +10 -0
  118. package/es/tooltip.d.ts.map +1 -0
  119. package/es/tooltip.js +168 -0
  120. package/package.json +74 -0
  121. package/src/auto-complete/README.md +71 -0
  122. package/src/auto-complete/closebrackets.ts +423 -0
  123. package/src/auto-complete/completion.ts +345 -0
  124. package/src/auto-complete/config.ts +101 -0
  125. package/src/auto-complete/filter.ts +214 -0
  126. package/src/auto-complete/index.ts +112 -0
  127. package/src/auto-complete/snippet.ts +392 -0
  128. package/src/auto-complete/state.ts +465 -0
  129. package/src/auto-complete/theme.ts +127 -0
  130. package/src/auto-complete/tooltip.ts +386 -0
  131. package/src/auto-complete/view.ts +339 -0
  132. package/src/auto-complete/word.ts +118 -0
  133. package/src/completion.ts +61 -0
  134. package/src/config.ts +701 -0
  135. package/src/editor-contribution.ts +22 -0
  136. package/src/editor.ts +1287 -0
  137. package/src/factory.ts +31 -0
  138. package/src/hyperlink.ts +95 -0
  139. package/src/indent.ts +69 -0
  140. package/src/indentation-markers/config.ts +31 -0
  141. package/src/indentation-markers/index.ts +192 -0
  142. package/src/indentation-markers/map.ts +273 -0
  143. package/src/indentation-markers/utils.ts +84 -0
  144. package/src/index.spec.ts +12 -0
  145. package/src/index.ts +14 -0
  146. package/src/libro-icon.tsx +4 -0
  147. package/src/lsp/completion.ts +175 -0
  148. package/src/lsp/format.ts +144 -0
  149. package/src/lsp/index.ts +6 -0
  150. package/src/lsp/lint.ts +125 -0
  151. package/src/lsp/protocol.ts +8 -0
  152. package/src/lsp/tooltip.ts +76 -0
  153. package/src/lsp/util.ts +69 -0
  154. package/src/mimetype.ts +49 -0
  155. package/src/mode.ts +265 -0
  156. package/src/module.ts +8 -0
  157. package/src/monitor.ts +105 -0
  158. package/src/python-lang.ts +7 -0
  159. package/src/style/base.css +129 -0
  160. package/src/style/theme.css +12 -0
  161. package/src/style/variables.css +405 -0
  162. package/src/theme.ts +231 -0
  163. package/src/tooltip.ts +143 -0
@@ -0,0 +1,368 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ 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; } } }; }
7
+ 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); }
8
+ 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; }
9
+ 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); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ import { ViewPlugin, logException, getTooltip } from '@codemirror/view';
15
+ import { cur, CompletionContext, applyCompletion } from "./completion.js";
16
+ import { completionConfig } from "./config.js";
17
+ import { completionState, setSelectedEffect, startCompletionEffect, closeCompletionEffect, setActiveEffect, State, ActiveSource, ActiveResult, getUserEvent } from "./state.js";
18
+
19
+ /// Returns a command that moves the completion selection forward or
20
+ /// backward by the given amount.
21
+ export function moveCompletionSelection(forward) {
22
+ var by = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'option';
23
+ return function (view) {
24
+ var cState = view.state.field(completionState, false);
25
+ if (!cState || !cState.open || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) {
26
+ return false;
27
+ }
28
+ var step = 1,
29
+ tooltip;
30
+ if (by === 'page' && (tooltip = getTooltip(view, cState.open.tooltip))) {
31
+ step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector('li').offsetHeight) - 1);
32
+ }
33
+ var length = cState.open.options.length;
34
+ var selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1;
35
+ if (selected < 0) {
36
+ selected = by === 'page' ? 0 : length - 1;
37
+ } else if (selected >= length) {
38
+ selected = by === 'page' ? length - 1 : 0;
39
+ }
40
+ view.dispatch({
41
+ effects: setSelectedEffect.of(selected)
42
+ });
43
+ return true;
44
+ };
45
+ }
46
+
47
+ /// Accept the current completion.
48
+ export var acceptCompletion = function acceptCompletion(view) {
49
+ var cState = view.state.field(completionState, false);
50
+ if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) {
51
+ return false;
52
+ }
53
+ applyCompletion(view, cState.open.options[cState.open.selected]);
54
+ return true;
55
+ };
56
+
57
+ /// Explicitly start autocompletion.
58
+ export var startCompletion = function startCompletion(view) {
59
+ var cState = view.state.field(completionState, false);
60
+ if (!cState) {
61
+ return false;
62
+ }
63
+ view.dispatch({
64
+ effects: startCompletionEffect.of(true)
65
+ });
66
+ return true;
67
+ };
68
+
69
+ /// Close the currently active completion.
70
+ export var closeCompletion = function closeCompletion(view) {
71
+ var cState = view.state.field(completionState, false);
72
+ if (!cState || !cState.active.some(function (a) {
73
+ return a.state !== State.Inactive;
74
+ })) {
75
+ return false;
76
+ }
77
+ view.dispatch({
78
+ effects: closeCompletionEffect.of(null)
79
+ });
80
+ return true;
81
+ };
82
+ var RunningQuery = /*#__PURE__*/_createClass(function RunningQuery(active, context) {
83
+ _classCallCheck(this, RunningQuery);
84
+ this.active = active;
85
+ this.context = context;
86
+ this.time = Date.now();
87
+ this.updates = [];
88
+ // Note that 'undefined' means 'not done yet', whereas 'null' means
89
+ // 'query returned null'.
90
+ this.done = undefined;
91
+ });
92
+ var DebounceTime = 50,
93
+ MaxUpdateCount = 50,
94
+ MinAbortTime = 1000;
95
+ var CompositionState = /*#__PURE__*/function (CompositionState) {
96
+ CompositionState[CompositionState["None"] = 0] = "None";
97
+ CompositionState[CompositionState["Started"] = 1] = "Started";
98
+ CompositionState[CompositionState["Changed"] = 2] = "Changed";
99
+ CompositionState[CompositionState["ChangedAndMoved"] = 3] = "ChangedAndMoved";
100
+ return CompositionState;
101
+ }(CompositionState || {});
102
+ export var completionPlugin = ViewPlugin.fromClass( /*#__PURE__*/function () {
103
+ function _class(view) {
104
+ _classCallCheck(this, _class);
105
+ this.view = view;
106
+ this.debounceUpdate = -1;
107
+ this.running = [];
108
+ this.debounceAccept = -1;
109
+ this.composing = CompositionState.None;
110
+ var _iterator = _createForOfIteratorHelper(view.state.field(completionState).active),
111
+ _step;
112
+ try {
113
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
114
+ var _active = _step.value;
115
+ if (_active.state === State.Pending) {
116
+ this.startQuery(_active);
117
+ }
118
+ }
119
+ } catch (err) {
120
+ _iterator.e(err);
121
+ } finally {
122
+ _iterator.f();
123
+ }
124
+ }
125
+ _createClass(_class, [{
126
+ key: "update",
127
+ value: function update(_update) {
128
+ var _this = this;
129
+ var cState = _update.state.field(completionState);
130
+ if (!_update.selectionSet && !_update.docChanged && _update.startState.field(completionState) === cState) {
131
+ return;
132
+ }
133
+ var doesReset = _update.transactions.some(function (tr) {
134
+ return (tr.selection || tr.docChanged) && !getUserEvent(tr);
135
+ });
136
+ for (var i = 0; i < this.running.length; i++) {
137
+ var query = this.running[i];
138
+ if (doesReset || query.updates.length + _update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
139
+ var _iterator2 = _createForOfIteratorHelper(query.context.abortListeners),
140
+ _step2;
141
+ try {
142
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
143
+ var handler = _step2.value;
144
+ try {
145
+ handler();
146
+ } catch (e) {
147
+ logException(this.view.state, e);
148
+ }
149
+ }
150
+ } catch (err) {
151
+ _iterator2.e(err);
152
+ } finally {
153
+ _iterator2.f();
154
+ }
155
+ query.context.abortListeners = null;
156
+ this.running.splice(i--, 1);
157
+ } else {
158
+ var _query$updates;
159
+ (_query$updates = query.updates).push.apply(_query$updates, _toConsumableArray(_update.transactions));
160
+ }
161
+ }
162
+ if (this.debounceUpdate > -1) {
163
+ clearTimeout(this.debounceUpdate);
164
+ }
165
+ this.debounceUpdate = cState.active.some(function (a) {
166
+ return a.state === State.Pending && !_this.running.some(function (q) {
167
+ return q.active.source === a.source;
168
+ });
169
+ }) ? setTimeout(function () {
170
+ return _this.startUpdate();
171
+ }, DebounceTime) : -1;
172
+ if (this.composing !== CompositionState.None) {
173
+ var _iterator3 = _createForOfIteratorHelper(_update.transactions),
174
+ _step3;
175
+ try {
176
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
177
+ var tr = _step3.value;
178
+ if (getUserEvent(tr) === 'input') {
179
+ this.composing = CompositionState.Changed;
180
+ } else if (this.composing === CompositionState.Changed && tr.selection) {
181
+ this.composing = CompositionState.ChangedAndMoved;
182
+ }
183
+ }
184
+ } catch (err) {
185
+ _iterator3.e(err);
186
+ } finally {
187
+ _iterator3.f();
188
+ }
189
+ }
190
+ }
191
+ }, {
192
+ key: "startUpdate",
193
+ value: function startUpdate() {
194
+ var _this2 = this;
195
+ this.debounceUpdate = -1;
196
+ var state = this.view.state,
197
+ cState = state.field(completionState);
198
+ var _iterator4 = _createForOfIteratorHelper(cState.active),
199
+ _step4;
200
+ try {
201
+ var _loop = function _loop() {
202
+ var active = _step4.value;
203
+ if (active.state === State.Pending && !_this2.running.some(function (r) {
204
+ return r.active.source === active.source;
205
+ })) {
206
+ _this2.startQuery(active);
207
+ }
208
+ };
209
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
210
+ _loop();
211
+ }
212
+ } catch (err) {
213
+ _iterator4.e(err);
214
+ } finally {
215
+ _iterator4.f();
216
+ }
217
+ }
218
+ }, {
219
+ key: "startQuery",
220
+ value: function startQuery(active) {
221
+ var _this3 = this;
222
+ var state = this.view.state,
223
+ pos = cur(state);
224
+ var context = new CompletionContext(state, pos, active.explicitPos === pos);
225
+ var pending = new RunningQuery(active, context);
226
+ this.running.push(pending);
227
+ Promise.resolve(active.source(context)).then(function (result) {
228
+ if (!pending.context.aborted) {
229
+ pending.done = result || null;
230
+ return _this3.scheduleAccept();
231
+ }
232
+ return undefined;
233
+ }, function (err) {
234
+ _this3.view.dispatch({
235
+ effects: closeCompletionEffect.of(null)
236
+ });
237
+ logException(_this3.view.state, err);
238
+ return undefined;
239
+ }).catch(console.error);
240
+ }
241
+ }, {
242
+ key: "scheduleAccept",
243
+ value: function scheduleAccept() {
244
+ var _this4 = this;
245
+ if (this.running.every(function (q) {
246
+ return q.done !== undefined;
247
+ })) {
248
+ this.accept();
249
+ } else if (this.debounceAccept < 0) {
250
+ this.debounceAccept = setTimeout(function () {
251
+ return _this4.accept();
252
+ }, DebounceTime);
253
+ }
254
+ }
255
+
256
+ // For each finished query in this.running, try to create a result
257
+ // or, if appropriate, restart the query.
258
+ }, {
259
+ key: "accept",
260
+ value: function accept() {
261
+ var _this5 = this;
262
+ if (this.debounceAccept > -1) {
263
+ clearTimeout(this.debounceAccept);
264
+ }
265
+ this.debounceAccept = -1;
266
+ var updated = [];
267
+ var conf = this.view.state.facet(completionConfig);
268
+ var _loop2 = function _loop2(_i) {
269
+ var query = _this5.running[_i];
270
+ if (query.done === undefined) {
271
+ i = _i;
272
+ return 0; // continue
273
+ }
274
+ _this5.running.splice(_i--, 1);
275
+ if (query.done) {
276
+ var _query$done$to;
277
+ var _active2 = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_query$done$to = query.done.to) !== null && _query$done$to !== void 0 ? _query$done$to : cur(query.updates.length ? query.updates[0].startState : _this5.view.state));
278
+ // Replay the transactions that happened since the start of
279
+ // the request and see if that preserves the result
280
+ var _iterator5 = _createForOfIteratorHelper(query.updates),
281
+ _step5;
282
+ try {
283
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
284
+ var tr = _step5.value;
285
+ _active2 = _active2.update(tr, conf);
286
+ }
287
+ } catch (err) {
288
+ _iterator5.e(err);
289
+ } finally {
290
+ _iterator5.f();
291
+ }
292
+ if (_active2.hasResult()) {
293
+ updated.push(_active2);
294
+ i = _i;
295
+ return 0; // continue
296
+ }
297
+ }
298
+ var current = _this5.view.state.field(completionState).active.find(function (a) {
299
+ return a.source === query.active.source;
300
+ });
301
+ if (current && current.state === State.Pending) {
302
+ if (query.done === null) {
303
+ // Explicitly failed. Should clear the pending status if it
304
+ // hasn't been re-set in the meantime.
305
+ var _active3 = new ActiveSource(query.active.source, State.Inactive);
306
+ var _iterator6 = _createForOfIteratorHelper(query.updates),
307
+ _step6;
308
+ try {
309
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
310
+ var _tr = _step6.value;
311
+ _active3 = _active3.update(_tr, conf);
312
+ }
313
+ } catch (err) {
314
+ _iterator6.e(err);
315
+ } finally {
316
+ _iterator6.f();
317
+ }
318
+ if (_active3.state !== State.Pending) {
319
+ updated.push(_active3);
320
+ }
321
+ } else {
322
+ // Cleared by subsequent transactions. Restart.
323
+ _this5.startQuery(current);
324
+ }
325
+ }
326
+ i = _i;
327
+ },
328
+ _ret;
329
+ for (var i = 0; i < this.running.length; i++) {
330
+ _ret = _loop2(i);
331
+ if (_ret === 0) continue;
332
+ }
333
+ if (updated.length) {
334
+ this.view.dispatch({
335
+ effects: setActiveEffect.of(updated)
336
+ });
337
+ }
338
+ }
339
+ }]);
340
+ return _class;
341
+ }(), {
342
+ eventHandlers: {
343
+ blur: function blur() {
344
+ var state = this.view.state.field(completionState, false);
345
+ if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
346
+ this.view.dispatch({
347
+ effects: closeCompletionEffect.of(null)
348
+ });
349
+ }
350
+ },
351
+ compositionstart: function compositionstart() {
352
+ this.composing = CompositionState.Started;
353
+ },
354
+ compositionend: function compositionend() {
355
+ var _this6 = this;
356
+ if (this.composing === CompositionState.ChangedAndMoved) {
357
+ // Safari fires compositionend events synchronously, possibly
358
+ // from inside an update, so dispatch asynchronously to avoid reentrancy
359
+ setTimeout(function () {
360
+ return _this6.view.dispatch({
361
+ effects: startCompletionEffect.of(false)
362
+ });
363
+ }, 20);
364
+ }
365
+ this.composing = CompositionState.None;
366
+ }
367
+ }
368
+ });
@@ -0,0 +1,3 @@
1
+ import type { CompletionSource } from './completion.js';
2
+ export declare const completeAnyWord: CompletionSource;
3
+ //# sourceMappingURL=word.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"word.d.ts","sourceRoot":"","sources":["../../src/auto-complete/word.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AA+FpE,eAAO,MAAM,eAAe,EAAE,gBAkB7B,CAAC"}
@@ -0,0 +1,119 @@
1
+ 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; } } }; }
2
+ 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); }
3
+ 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; }
4
+ /* eslint-disable prefer-const */
5
+ /* eslint-disable @typescript-eslint/no-shadow */
6
+ var C = /*#__PURE__*/function (C) {
7
+ C[C["Range"] = 50000] = "Range";
8
+ C[C["MinCacheLen"] = 1000] = "MinCacheLen";
9
+ C[C["MaxList"] = 2000] = "MaxList";
10
+ return C;
11
+ }(C || {});
12
+ function wordRE(wordChars) {
13
+ var escaped = wordChars.replace(/[\\[.+*?(){|^$]/g, '\\$&');
14
+ try {
15
+ return new RegExp("[\\p{Alphabetic}\\p{Number}_".concat(escaped, "]+"), 'ug');
16
+ } catch (_unused) {
17
+ // eslint-disable-next-line no-useless-escape
18
+ return new RegExp("[w".concat(escaped, "]"), 'g');
19
+ }
20
+ }
21
+ function mapRE(re, f) {
22
+ return new RegExp(f(re.source), re.unicode ? 'u' : '');
23
+ }
24
+ var wordCaches = Object.create(null);
25
+ function wordCache(wordChars) {
26
+ return wordCaches[wordChars] || (wordCaches[wordChars] = new WeakMap());
27
+ }
28
+ function storeWords(doc, wordRE, result, seen, ignoreAt) {
29
+ for (var lines = doc.iterLines(), pos = 0; !lines.next().done;) {
30
+ var value = lines.value,
31
+ m = void 0;
32
+ wordRE.lastIndex = 0;
33
+ while (m = wordRE.exec(value)) {
34
+ if (!seen[m[0]] && pos + m.index !== ignoreAt) {
35
+ result.push({
36
+ type: 'text',
37
+ label: m[0]
38
+ });
39
+ seen[m[0]] = true;
40
+ if (result.length >= C.MaxList) {
41
+ return;
42
+ }
43
+ }
44
+ }
45
+ pos += value.length + 1;
46
+ }
47
+ }
48
+ function collectWords(doc, cache, wordRE, to, ignoreAt) {
49
+ var big = doc.length >= C.MinCacheLen;
50
+ var cached = big && cache.get(doc);
51
+ if (cached) {
52
+ return cached;
53
+ }
54
+ var result = [],
55
+ seen = Object.create(null);
56
+ if (doc.children) {
57
+ var pos = 0;
58
+ var _iterator = _createForOfIteratorHelper(doc.children),
59
+ _step;
60
+ try {
61
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
62
+ var ch = _step.value;
63
+ if (ch.length >= C.MinCacheLen) {
64
+ var _iterator2 = _createForOfIteratorHelper(collectWords(ch, cache, wordRE, to - pos, ignoreAt - pos)),
65
+ _step2;
66
+ try {
67
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
68
+ var c = _step2.value;
69
+ if (!seen[c.label]) {
70
+ seen[c.label] = true;
71
+ result.push(c);
72
+ }
73
+ }
74
+ } catch (err) {
75
+ _iterator2.e(err);
76
+ } finally {
77
+ _iterator2.f();
78
+ }
79
+ } else {
80
+ storeWords(ch, wordRE, result, seen, ignoreAt - pos);
81
+ }
82
+ pos += ch.length + 1;
83
+ }
84
+ } catch (err) {
85
+ _iterator.e(err);
86
+ } finally {
87
+ _iterator.f();
88
+ }
89
+ } else {
90
+ storeWords(doc, wordRE, result, seen, ignoreAt);
91
+ }
92
+ if (big && result.length < C.MaxList) {
93
+ cache.set(doc, result);
94
+ }
95
+ return result;
96
+ }
97
+
98
+ /// A completion source that will scan the document for words (using a
99
+ /// [character categorizer](#state.EditorState.charCategorizer)), and
100
+ /// return those as completions.
101
+ export var completeAnyWord = function completeAnyWord(context) {
102
+ var wordChars = context.state.languageDataAt('wordChars', context.pos).join('');
103
+ var re = wordRE(wordChars);
104
+ var token = context.matchBefore(mapRE(re, function (s) {
105
+ return s + '$';
106
+ }));
107
+ if (!token && !context.explicit) {
108
+ return null;
109
+ }
110
+ var from = token ? token.from : context.pos;
111
+ var options = collectWords(context.state.doc, wordCache(wordChars), re, C.Range, from);
112
+ return {
113
+ from: from,
114
+ options: options,
115
+ validFor: mapRE(re, function (s) {
116
+ return '^' + s;
117
+ })
118
+ };
119
+ };
@@ -0,0 +1,6 @@
1
+ import type { CompletionSource } from '@codemirror/autocomplete';
2
+ import type { CompletionProvider } from '@difizen/libro-code-editor';
3
+ type EditorCompletion = (provider: CompletionProvider | undefined) => CompletionSource;
4
+ export declare const kernelCompletions: EditorCompletion;
5
+ export {};
6
+ //# sourceMappingURL=completion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../src/completion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,4BAA4B,CAAC;AAGtF,KAAK,gBAAgB,GAAG,CAAC,QAAQ,EAAE,kBAAkB,GAAG,SAAS,KAAK,gBAAgB,CAAC;AAEvF,eAAO,MAAM,iBAAiB,EAAE,gBAsD7B,CAAC"}
@@ -0,0 +1,84 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ export var kernelCompletions = function kernelCompletions(provider) {
6
+ return /*#__PURE__*/function () {
7
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(context) {
8
+ var _result$cursor_start;
9
+ var word, result, timeout, metadata, types, items;
10
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
11
+ while (1) switch (_context.prev = _context.next) {
12
+ case 0:
13
+ if (!(!provider || !context.explicit)) {
14
+ _context.next = 2;
15
+ break;
16
+ }
17
+ return _context.abrupt("return", null);
18
+ case 2:
19
+ word = context.matchBefore(/\w*/);
20
+ timeout = 500;
21
+ _context.prev = 4;
22
+ _context.next = 7;
23
+ return Promise.any([provider({
24
+ cursorPosition: context.pos
25
+ }), new Promise(function (resolve, reject) {
26
+ setTimeout(function () {
27
+ reject("request time out in ".concat(timeout, "ms"));
28
+ }, timeout);
29
+ })]);
30
+ case 7:
31
+ result = _context.sent;
32
+ _context.next = 14;
33
+ break;
34
+ case 10:
35
+ _context.prev = 10;
36
+ _context.t0 = _context["catch"](4);
37
+ console.error('provider error', _context.t0);
38
+ return _context.abrupt("return", null);
39
+ case 14:
40
+ if (word) {
41
+ _context.next = 16;
42
+ break;
43
+ }
44
+ return _context.abrupt("return", null);
45
+ case 16:
46
+ if (!(word.from === word.to)) {
47
+ _context.next = 18;
48
+ break;
49
+ }
50
+ return _context.abrupt("return", null);
51
+ case 18:
52
+ metadata = result.metadata || {};
53
+ types = metadata['_jupyter_types_experimental'];
54
+ if (types) {
55
+ items = types.map(function (item) {
56
+ return {
57
+ label: item['text'],
58
+ type: item['type'] === '<unknown>' ? undefined : item['type']
59
+ };
60
+ });
61
+ } else {
62
+ items = result.matches.map(function (item) {
63
+ return {
64
+ label: item,
65
+ type: 'text'
66
+ };
67
+ });
68
+ }
69
+ return _context.abrupt("return", {
70
+ from: (_result$cursor_start = result.cursor_start) !== null && _result$cursor_start !== void 0 ? _result$cursor_start : word.from,
71
+ to: result.cursor_end,
72
+ options: items
73
+ });
74
+ case 22:
75
+ case "end":
76
+ return _context.stop();
77
+ }
78
+ }, _callee, null, [[4, 10]]);
79
+ }));
80
+ return function (_x) {
81
+ return _ref.apply(this, arguments);
82
+ };
83
+ }();
84
+ };