@veltra/desktop 1.2.16 → 1.2.17

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 (78) hide show
  1. package/dist/components/action/action-group.vue.d.ts +2 -2
  2. package/dist/components/action/action.vue.d.ts +1 -1
  3. package/dist/components/auto-complete/auto-complete.vue.d.ts +2 -2
  4. package/dist/components/batch-edit/batch-edit.vue.d.ts +2 -2
  5. package/dist/components/cascade/cascade.vue.d.ts +8 -8
  6. package/dist/components/checkbox/checkbox-button.vue.d.ts +1 -1
  7. package/dist/components/checkbox-group/checkbox-group.vue.d.ts +2 -2
  8. package/dist/components/code-editor/basic-setup.js +7 -7
  9. package/dist/components/code-editor/code-editor.js +7 -7
  10. package/dist/components/code-editor/code-editor.js.map +1 -1
  11. package/dist/components/date-panel/date-panel.vue.d.ts +1 -1
  12. package/dist/components/date-picker/date-picker.vue.d.ts +3 -3
  13. package/dist/components/date-range-picker/date-range-picker.vue.d.ts +3 -3
  14. package/dist/components/file-picker/file-picker.vue.d.ts +1 -1
  15. package/dist/components/input/input.vue.d.ts +4 -4
  16. package/dist/components/multi-select/multi-select.vue.d.ts +5 -5
  17. package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +8 -8
  18. package/dist/components/number-input/number-input.vue.d.ts +4 -4
  19. package/dist/components/number-range-input/number-range-input.vue.d.ts +1 -1
  20. package/dist/components/password-input/password-input.vue.d.ts +1 -1
  21. package/dist/components/progress-nodes/progress-nodes.vue.d.ts +1 -1
  22. package/dist/components/radio-group/radio-group.vue.d.ts +2 -2
  23. package/dist/components/rich-text-editor/rich-text-editor.vue.d.ts +1 -1
  24. package/dist/components/select/select.vue.d.ts +4 -4
  25. package/dist/components/steps/steps.vue.d.ts +2 -2
  26. package/dist/components/tabs/tabs-horizontal.vue.d.ts +1 -1
  27. package/dist/components/tabs/tabs.vue.d.ts +1 -1
  28. package/dist/components/textarea/textarea.vue.d.ts +4 -4
  29. package/dist/components/tree/tree.vue.d.ts +2 -2
  30. package/dist/components/tree-select/tree-select.vue.d.ts +7 -7
  31. package/dist/components/watermark/watermark.vue.d.ts +1 -1
  32. package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js +1750 -0
  33. package/dist/node_modules/.bun/@codemirror_autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js.map +1 -0
  34. package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js +1719 -0
  35. package/dist/node_modules/.bun/@codemirror_commands@6.10.4/node_modules/@codemirror/commands/dist/index.js.map +1 -0
  36. package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js +51 -0
  37. package/dist/node_modules/.bun/@codemirror_lang-java@6.0.2/node_modules/@codemirror/lang-java/dist/index.js.map +1 -0
  38. package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js +378 -0
  39. package/dist/node_modules/.bun/@codemirror_lang-javascript@6.2.5/node_modules/@codemirror/lang-javascript/dist/index.js.map +1 -0
  40. package/dist/node_modules/.bun/@codemirror_lang-json@6.0.2/node_modules/@codemirror/lang-json/dist/index.js +31 -0
  41. package/dist/node_modules/.bun/@codemirror_lang-json@6.0.2/node_modules/@codemirror/lang-json/dist/index.js.map +1 -0
  42. package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js +601 -0
  43. package/dist/node_modules/.bun/@codemirror_lang-sql@6.10.0/node_modules/@codemirror/lang-sql/dist/index.js.map +1 -0
  44. package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js +1767 -0
  45. package/dist/node_modules/.bun/@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js.map +1 -0
  46. package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js +569 -0
  47. package/dist/node_modules/.bun/@codemirror_lint@6.9.7/node_modules/@codemirror/lint/dist/index.js.map +1 -0
  48. package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js +1142 -0
  49. package/dist/node_modules/.bun/@codemirror_search@6.7.1/node_modules/@codemirror/search/dist/index.js.map +1 -0
  50. package/dist/node_modules/.bun/@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js +3372 -0
  51. package/dist/node_modules/.bun/@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js.map +1 -0
  52. package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js +165 -0
  53. package/dist/node_modules/.bun/@codemirror_theme-one-dark@6.1.3/node_modules/@codemirror/theme-one-dark/dist/index.js.map +1 -0
  54. package/dist/node_modules/.bun/@codemirror_view@6.43.3/node_modules/@codemirror/view/dist/index.js +8862 -0
  55. package/dist/node_modules/.bun/@codemirror_view@6.43.3/node_modules/@codemirror/view/dist/index.js.map +1 -0
  56. package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js +8856 -0
  57. package/dist/node_modules/.bun/@codemirror_view@6.43.4/node_modules/@codemirror/view/dist/index.js.map +1 -0
  58. package/dist/node_modules/.bun/@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js +1567 -0
  59. package/dist/node_modules/.bun/@lezer_common@1.5.2/node_modules/@lezer/common/dist/index.js.map +1 -0
  60. package/dist/node_modules/.bun/@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js +864 -0
  61. package/dist/node_modules/.bun/@lezer_highlight@1.2.3/node_modules/@lezer/highlight/dist/index.js.map +1 -0
  62. package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js +235 -0
  63. package/dist/node_modules/.bun/@lezer_java@1.1.3/node_modules/@lezer/java/dist/index.js.map +1 -0
  64. package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js +470 -0
  65. package/dist/node_modules/.bun/@lezer_javascript@1.5.4/node_modules/@lezer/javascript/dist/index.js.map +1 -0
  66. package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js +55 -0
  67. package/dist/node_modules/.bun/@lezer_json@1.0.3/node_modules/@lezer/json/dist/index.js.map +1 -0
  68. package/dist/node_modules/.bun/@lezer_lr@1.4.10/node_modules/@lezer/lr/dist/index.js +1485 -0
  69. package/dist/node_modules/.bun/@lezer_lr@1.4.10/node_modules/@lezer/lr/dist/index.js.map +1 -0
  70. package/dist/node_modules/.bun/@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js +73 -0
  71. package/dist/node_modules/.bun/@marijn_find-cluster-break@1.0.2/node_modules/@marijn/find-cluster-break/src/index.js.map +1 -0
  72. package/dist/node_modules/.bun/crelt@1.0.6/node_modules/crelt/index.js +26 -0
  73. package/dist/node_modules/.bun/crelt@1.0.6/node_modules/crelt/index.js.map +1 -0
  74. package/dist/node_modules/.bun/style-mod@4.1.3/node_modules/style-mod/src/style-mod.js +95 -0
  75. package/dist/node_modules/.bun/style-mod@4.1.3/node_modules/style-mod/src/style-mod.js.map +1 -0
  76. package/dist/node_modules/.bun/w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js +104 -0
  77. package/dist/node_modules/.bun/w3c-keyname@2.2.8/node_modules/w3c-keyname/index.js.map +1 -0
  78. package/package.json +20 -18
@@ -0,0 +1,1750 @@
1
+ import { Annotation, CharCategory, EditorSelection, Facet, MapMode, Prec, RangeSet, RangeValue, StateEffect, StateField, Text, Transaction, codePointAt, codePointSize, combineConfig, fromCodePoint } from "../../../../../@codemirror_state@6.7.0/node_modules/@codemirror/state/dist/index.js";
2
+ import { Decoration, Direction, EditorView, ViewPlugin, WidgetType, getTooltip, keymap, logException, showTooltip } from "../../../../../@codemirror_view@6.43.3/node_modules/@codemirror/view/dist/index.js";
3
+ import { indentUnit, syntaxTree } from "../../../../../@codemirror_language@6.12.4/node_modules/@codemirror/language/dist/index.js";
4
+ //#region ../../node_modules/.bun/@codemirror+autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js
5
+ /**
6
+ An instance of this is passed to completion source functions.
7
+ */
8
+ var CompletionContext = class {
9
+ /**
10
+ Create a new completion context. (Mostly useful for testing
11
+ completion sources—in the editor, the extension will create
12
+ these for you.)
13
+ */
14
+ constructor(state, pos, explicit, view) {
15
+ this.state = state;
16
+ this.pos = pos;
17
+ this.explicit = explicit;
18
+ this.view = view;
19
+ /**
20
+ @internal
21
+ */
22
+ this.abortListeners = [];
23
+ /**
24
+ @internal
25
+ */
26
+ this.abortOnDocChange = false;
27
+ }
28
+ /**
29
+ Get the extent, content, and (if there is a token) type of the
30
+ token before `this.pos`.
31
+ */
32
+ tokenBefore(types) {
33
+ let token = syntaxTree(this.state).resolveInner(this.pos, -1);
34
+ while (token && types.indexOf(token.name) < 0) token = token.parent;
35
+ return token ? {
36
+ from: token.from,
37
+ to: this.pos,
38
+ text: this.state.sliceDoc(token.from, this.pos),
39
+ type: token.type
40
+ } : null;
41
+ }
42
+ /**
43
+ Get the match of the given expression directly before the
44
+ cursor.
45
+ */
46
+ matchBefore(expr) {
47
+ let line = this.state.doc.lineAt(this.pos);
48
+ let start = Math.max(line.from, this.pos - 250);
49
+ let str = line.text.slice(start - line.from, this.pos - line.from);
50
+ let found = str.search(ensureAnchor(expr, false));
51
+ return found < 0 ? null : {
52
+ from: start + found,
53
+ to: this.pos,
54
+ text: str.slice(found)
55
+ };
56
+ }
57
+ /**
58
+ Yields true when the query has been aborted. Can be useful in
59
+ asynchronous queries to avoid doing work that will be ignored.
60
+ */
61
+ get aborted() {
62
+ return this.abortListeners == null;
63
+ }
64
+ /**
65
+ Allows you to register abort handlers, which will be called when
66
+ the query is
67
+ [aborted](https://codemirror.net/6/docs/ref/#autocomplete.CompletionContext.aborted).
68
+
69
+ By default, running queries will not be aborted for regular
70
+ typing or backspacing, on the assumption that they are likely to
71
+ return a result with a
72
+ [`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor) field that
73
+ allows the result to be used after all. Passing `onDocChange:
74
+ true` will cause this query to be aborted for any document
75
+ change.
76
+ */
77
+ addEventListener(type, listener, options) {
78
+ if (type == "abort" && this.abortListeners) {
79
+ this.abortListeners.push(listener);
80
+ if (options && options.onDocChange) this.abortOnDocChange = true;
81
+ }
82
+ }
83
+ };
84
+ function toSet(chars) {
85
+ let flat = Object.keys(chars).join("");
86
+ let words = /\w/.test(flat);
87
+ if (words) flat = flat.replace(/\w/g, "");
88
+ return `[${words ? "\\w" : ""}${flat.replace(/[^\w\s]/g, "\\$&")}]`;
89
+ }
90
+ function prefixMatch(options) {
91
+ let first = Object.create(null), rest = Object.create(null);
92
+ for (let { label } of options) {
93
+ first[label[0]] = true;
94
+ for (let i = 1; i < label.length; i++) rest[label[i]] = true;
95
+ }
96
+ let source = toSet(first) + toSet(rest) + "*$";
97
+ return [new RegExp("^" + source), new RegExp(source)];
98
+ }
99
+ /**
100
+ Given a a fixed array of options, return an autocompleter that
101
+ completes them.
102
+ */
103
+ function completeFromList(list) {
104
+ let options = list.map((o) => typeof o == "string" ? { label: o } : o);
105
+ let [validFor, match] = options.every((o) => /^\w+$/.test(o.label)) ? [/\w*$/, /\w+$/] : prefixMatch(options);
106
+ return (context) => {
107
+ let token = context.matchBefore(match);
108
+ return token || context.explicit ? {
109
+ from: token ? token.from : context.pos,
110
+ options,
111
+ validFor
112
+ } : null;
113
+ };
114
+ }
115
+ /**
116
+ Wrap the given completion source so that it will not fire when the
117
+ cursor is in a syntax node with one of the given names.
118
+ */
119
+ function ifNotIn(nodes, source) {
120
+ return (context) => {
121
+ for (let pos = syntaxTree(context.state).resolveInner(context.pos, -1); pos; pos = pos.parent) {
122
+ if (nodes.indexOf(pos.name) > -1) return null;
123
+ if (pos.type.isTop) break;
124
+ }
125
+ return source(context);
126
+ };
127
+ }
128
+ var Option = class {
129
+ constructor(completion, source, match, score) {
130
+ this.completion = completion;
131
+ this.source = source;
132
+ this.match = match;
133
+ this.score = score;
134
+ }
135
+ };
136
+ function cur(state) {
137
+ return state.selection.main.from;
138
+ }
139
+ function ensureAnchor(expr, start) {
140
+ var _a;
141
+ let { source } = expr;
142
+ let addStart = start && source[0] != "^", addEnd = source[source.length - 1] != "$";
143
+ if (!addStart && !addEnd) return expr;
144
+ return new RegExp(`${addStart ? "^" : ""}(?:${source})${addEnd ? "$" : ""}`, (_a = expr.flags) !== null && _a !== void 0 ? _a : expr.ignoreCase ? "i" : "");
145
+ }
146
+ /**
147
+ This annotation is added to transactions that are produced by
148
+ picking a completion.
149
+ */
150
+ const pickedCompletion = /*@__PURE__*/ Annotation.define();
151
+ /**
152
+ Helper function that returns a transaction spec which inserts a
153
+ completion's text in the main selection range, and any other
154
+ selection range that has the same text in front of it.
155
+ */
156
+ function insertCompletionText(state, text, from, to) {
157
+ let { main } = state.selection, fromOff = from - main.from, toOff = to - main.from;
158
+ return {
159
+ ...state.changeByRange((range) => {
160
+ if (range != main && from != to && state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to)) return { range };
161
+ let lines = state.toText(text);
162
+ return {
163
+ changes: {
164
+ from: range.from + fromOff,
165
+ to: to == main.from ? range.to : range.from + toOff,
166
+ insert: lines
167
+ },
168
+ range: EditorSelection.cursor(range.from + fromOff + lines.length)
169
+ };
170
+ }),
171
+ scrollIntoView: true,
172
+ userEvent: "input.complete"
173
+ };
174
+ }
175
+ const SourceCache = /*@__PURE__*/ new WeakMap();
176
+ function asSource(source) {
177
+ if (!Array.isArray(source)) return source;
178
+ let known = SourceCache.get(source);
179
+ if (!known) SourceCache.set(source, known = completeFromList(source));
180
+ return known;
181
+ }
182
+ const startCompletionEffect = /*@__PURE__*/ StateEffect.define();
183
+ const closeCompletionEffect = /*@__PURE__*/ StateEffect.define();
184
+ var FuzzyMatcher = class {
185
+ constructor(pattern) {
186
+ this.pattern = pattern;
187
+ this.chars = [];
188
+ this.folded = [];
189
+ this.any = [];
190
+ this.precise = [];
191
+ this.byWord = [];
192
+ this.score = 0;
193
+ this.matched = [];
194
+ for (let p = 0; p < pattern.length;) {
195
+ let char = codePointAt(pattern, p), size = codePointSize(char);
196
+ this.chars.push(char);
197
+ let part = pattern.slice(p, p + size), upper = part.toUpperCase();
198
+ this.folded.push(codePointAt(upper == part ? part.toLowerCase() : upper, 0));
199
+ p += size;
200
+ }
201
+ this.astral = pattern.length != this.chars.length;
202
+ }
203
+ ret(score, matched) {
204
+ this.score = score;
205
+ this.matched = matched;
206
+ return this;
207
+ }
208
+ match(word) {
209
+ if (this.pattern.length == 0) return this.ret(-100, []);
210
+ if (word.length < this.pattern.length) return null;
211
+ let { chars, folded, any, precise, byWord } = this;
212
+ if (chars.length == 1) {
213
+ let first = codePointAt(word, 0), firstSize = codePointSize(first);
214
+ let score = firstSize == word.length ? 0 : -100;
215
+ if (first == chars[0]);
216
+ else if (first == folded[0]) score += -200;
217
+ else return null;
218
+ return this.ret(score, [0, firstSize]);
219
+ }
220
+ let direct = word.indexOf(this.pattern);
221
+ if (direct == 0) return this.ret(word.length == this.pattern.length ? 0 : -100, [0, this.pattern.length]);
222
+ let len = chars.length, anyTo = 0;
223
+ if (direct < 0) {
224
+ for (let i = 0, e = Math.min(word.length, 200); i < e && anyTo < len;) {
225
+ let next = codePointAt(word, i);
226
+ if (next == chars[anyTo] || next == folded[anyTo]) any[anyTo++] = i;
227
+ i += codePointSize(next);
228
+ }
229
+ if (anyTo < len) return null;
230
+ }
231
+ let preciseTo = 0;
232
+ let byWordTo = 0, byWordFolded = false;
233
+ let adjacentTo = 0, adjacentStart = -1, adjacentEnd = -1;
234
+ let hasLower = /[a-z]/.test(word), wordAdjacent = true;
235
+ for (let i = 0, e = Math.min(word.length, 200), prevType = 0; i < e && byWordTo < len;) {
236
+ let next = codePointAt(word, i);
237
+ if (direct < 0) {
238
+ if (preciseTo < len && next == chars[preciseTo]) precise[preciseTo++] = i;
239
+ if (adjacentTo < len) if (next == chars[adjacentTo] || next == folded[adjacentTo]) {
240
+ if (adjacentTo == 0) adjacentStart = i;
241
+ adjacentEnd = i + 1;
242
+ adjacentTo++;
243
+ } else adjacentTo = 0;
244
+ }
245
+ let ch, type = next < 255 ? next >= 48 && next <= 57 || next >= 97 && next <= 122 ? 2 : next >= 65 && next <= 90 ? 1 : 0 : (ch = fromCodePoint(next)) != ch.toLowerCase() ? 1 : ch != ch.toUpperCase() ? 2 : 0;
246
+ if (!i || type == 1 && hasLower || prevType == 0 && type != 0) {
247
+ if (chars[byWordTo] == next || folded[byWordTo] == next && (byWordFolded = true)) byWord[byWordTo++] = i;
248
+ else if (byWord.length) wordAdjacent = false;
249
+ }
250
+ prevType = type;
251
+ i += codePointSize(next);
252
+ }
253
+ if (byWordTo == len && byWord[0] == 0 && wordAdjacent) return this.result(-100 + (byWordFolded ? -200 : 0), byWord, word);
254
+ if (adjacentTo == len && adjacentStart == 0) return this.ret(-200 - word.length + (adjacentEnd == word.length ? 0 : -100), [0, adjacentEnd]);
255
+ if (direct > -1) return this.ret(-700 - word.length, [direct, direct + this.pattern.length]);
256
+ if (adjacentTo == len) return this.ret(-900 - word.length, [adjacentStart, adjacentEnd]);
257
+ if (byWordTo == len) return this.result(-100 + (byWordFolded ? -200 : 0) + -700 + (wordAdjacent ? 0 : -1100), byWord, word);
258
+ return chars.length == 2 ? null : this.result((any[0] ? -700 : 0) + -200 + -1100, any, word);
259
+ }
260
+ result(score, positions, word) {
261
+ let result = [], i = 0;
262
+ for (let pos of positions) {
263
+ let to = pos + (this.astral ? codePointSize(codePointAt(word, pos)) : 1);
264
+ if (i && result[i - 1] == pos) result[i - 1] = to;
265
+ else {
266
+ result[i++] = pos;
267
+ result[i++] = to;
268
+ }
269
+ }
270
+ return this.ret(score - word.length, result);
271
+ }
272
+ };
273
+ var StrictMatcher = class {
274
+ constructor(pattern) {
275
+ this.pattern = pattern;
276
+ this.matched = [];
277
+ this.score = 0;
278
+ this.folded = pattern.toLowerCase();
279
+ }
280
+ match(word) {
281
+ if (word.length < this.pattern.length) return null;
282
+ let start = word.slice(0, this.pattern.length);
283
+ let match = start == this.pattern ? 0 : start.toLowerCase() == this.folded ? -200 : null;
284
+ if (match == null) return null;
285
+ this.matched = [0, start.length];
286
+ this.score = match + (word.length == this.pattern.length ? 0 : -100);
287
+ return this;
288
+ }
289
+ };
290
+ const completionConfig = /*@__PURE__*/ Facet.define({ combine(configs) {
291
+ return combineConfig(configs, {
292
+ activateOnTyping: true,
293
+ activateOnCompletion: () => false,
294
+ activateOnTypingDelay: 100,
295
+ selectOnOpen: true,
296
+ override: null,
297
+ closeOnBlur: true,
298
+ maxRenderedOptions: 100,
299
+ defaultKeymap: true,
300
+ tooltipClass: () => "",
301
+ optionClass: () => "",
302
+ aboveCursor: false,
303
+ icons: true,
304
+ addToOptions: [],
305
+ positionInfo: defaultPositionInfo,
306
+ filterStrict: false,
307
+ compareCompletions: (a, b) => (a.sortText || a.label).localeCompare(b.sortText || b.label),
308
+ interactionDelay: 75,
309
+ updateSyncTime: 100
310
+ }, {
311
+ defaultKeymap: (a, b) => a && b,
312
+ closeOnBlur: (a, b) => a && b,
313
+ icons: (a, b) => a && b,
314
+ tooltipClass: (a, b) => (c) => joinClass(a(c), b(c)),
315
+ optionClass: (a, b) => (c) => joinClass(a(c), b(c)),
316
+ addToOptions: (a, b) => a.concat(b),
317
+ filterStrict: (a, b) => a || b
318
+ });
319
+ } });
320
+ function joinClass(a, b) {
321
+ return a ? b ? a + " " + b : a : b;
322
+ }
323
+ function defaultPositionInfo(view, list, option, info, space, tooltip) {
324
+ let rtl = view.textDirection == Direction.RTL, left = rtl, narrow = false;
325
+ let side = "top", offset, maxWidth;
326
+ let spaceLeft = list.left - space.left, spaceRight = space.right - list.right;
327
+ let infoWidth = info.right - info.left, infoHeight = info.bottom - info.top;
328
+ if (left && spaceLeft < Math.min(infoWidth, spaceRight)) left = false;
329
+ else if (!left && spaceRight < Math.min(infoWidth, spaceLeft)) left = true;
330
+ if (infoWidth <= (left ? spaceLeft : spaceRight)) {
331
+ offset = Math.max(space.top, Math.min(option.top, space.bottom - infoHeight)) - list.top;
332
+ maxWidth = Math.min(400, left ? spaceLeft : spaceRight);
333
+ } else {
334
+ narrow = true;
335
+ maxWidth = Math.min(400, (rtl ? list.right : space.right - list.left) - 30);
336
+ let spaceBelow = space.bottom - list.bottom;
337
+ if (spaceBelow >= infoHeight || spaceBelow > list.top) offset = option.bottom - list.top;
338
+ else {
339
+ side = "bottom";
340
+ offset = list.bottom - option.top;
341
+ }
342
+ }
343
+ let scaleY = (list.bottom - list.top) / tooltip.offsetHeight;
344
+ let scaleX = (list.right - list.left) / tooltip.offsetWidth;
345
+ return {
346
+ style: `${side}: ${offset / scaleY}px; max-width: ${maxWidth / scaleX}px`,
347
+ class: "cm-completionInfo-" + (narrow ? rtl ? "left-narrow" : "right-narrow" : left ? "left" : "right")
348
+ };
349
+ }
350
+ const setSelectedEffect = /*@__PURE__*/ StateEffect.define();
351
+ function optionContent(config) {
352
+ let content = config.addToOptions.slice();
353
+ if (config.icons) content.push({
354
+ render(completion) {
355
+ let icon = document.createElement("div");
356
+ icon.classList.add("cm-completionIcon");
357
+ if (completion.type) icon.classList.add(...completion.type.split(/\s+/g).map((cls) => "cm-completionIcon-" + cls));
358
+ icon.setAttribute("aria-hidden", "true");
359
+ return icon;
360
+ },
361
+ position: 20
362
+ });
363
+ content.push({
364
+ render(completion, _s, _v, match) {
365
+ let labelElt = document.createElement("span");
366
+ labelElt.className = "cm-completionLabel";
367
+ let label = completion.displayLabel || completion.label, off = 0;
368
+ for (let j = 0; j < match.length;) {
369
+ let from = match[j++], to = match[j++];
370
+ if (from > off) labelElt.appendChild(document.createTextNode(label.slice(off, from)));
371
+ let span = labelElt.appendChild(document.createElement("span"));
372
+ span.appendChild(document.createTextNode(label.slice(from, to)));
373
+ span.className = "cm-completionMatchedText";
374
+ off = to;
375
+ }
376
+ if (off < label.length) labelElt.appendChild(document.createTextNode(label.slice(off)));
377
+ return labelElt;
378
+ },
379
+ position: 50
380
+ }, {
381
+ render(completion) {
382
+ if (!completion.detail) return null;
383
+ let detailElt = document.createElement("span");
384
+ detailElt.className = "cm-completionDetail";
385
+ detailElt.textContent = completion.detail;
386
+ return detailElt;
387
+ },
388
+ position: 80
389
+ });
390
+ return content.sort((a, b) => a.position - b.position).map((a) => a.render);
391
+ }
392
+ function rangeAroundSelected(total, selected, max) {
393
+ if (total <= max) return {
394
+ from: 0,
395
+ to: total
396
+ };
397
+ if (selected < 0) selected = 0;
398
+ if (selected <= total >> 1) {
399
+ let off = Math.floor(selected / max);
400
+ return {
401
+ from: off * max,
402
+ to: (off + 1) * max
403
+ };
404
+ }
405
+ let off = Math.ceil((total - selected) / max);
406
+ return {
407
+ from: total - off * max,
408
+ to: total - (off - 1) * max
409
+ };
410
+ }
411
+ var CompletionTooltip = class {
412
+ constructor(view, stateField, applyCompletion) {
413
+ this.view = view;
414
+ this.stateField = stateField;
415
+ this.applyCompletion = applyCompletion;
416
+ this.info = null;
417
+ this.infoDestroy = null;
418
+ this.placeInfoReq = {
419
+ read: () => this.measureInfo(),
420
+ write: (pos) => this.placeInfo(pos),
421
+ key: this
422
+ };
423
+ this.space = null;
424
+ this.currentClass = "";
425
+ let cState = view.state.field(stateField);
426
+ let { options, selected } = cState.open;
427
+ let config = view.state.facet(completionConfig);
428
+ this.optionContent = optionContent(config);
429
+ this.optionClass = config.optionClass;
430
+ this.tooltipClass = config.tooltipClass;
431
+ this.range = rangeAroundSelected(options.length, selected, config.maxRenderedOptions);
432
+ this.dom = document.createElement("div");
433
+ this.dom.className = "cm-tooltip-autocomplete";
434
+ this.updateTooltipClass(view.state);
435
+ this.dom.addEventListener("mousedown", (e) => {
436
+ let { options } = view.state.field(stateField).open;
437
+ for (let dom = e.target, match; dom && dom != this.dom; dom = dom.parentNode) if (dom.nodeName == "LI" && (match = /-(\d+)$/.exec(dom.id)) && +match[1] < options.length) {
438
+ this.applyCompletion(view, options[+match[1]]);
439
+ e.preventDefault();
440
+ return;
441
+ }
442
+ if (e.target == this.list) {
443
+ let move = this.list.classList.contains("cm-completionListIncompleteTop") && e.clientY < this.list.firstChild.getBoundingClientRect().top ? this.range.from - 1 : this.list.classList.contains("cm-completionListIncompleteBottom") && e.clientY > this.list.lastChild.getBoundingClientRect().bottom ? this.range.to : null;
444
+ if (move != null) {
445
+ view.dispatch({ effects: setSelectedEffect.of(move) });
446
+ e.preventDefault();
447
+ }
448
+ }
449
+ });
450
+ this.dom.addEventListener("focusout", (e) => {
451
+ let state = view.state.field(this.stateField, false);
452
+ if (state && state.tooltip && view.state.facet(completionConfig).closeOnBlur && e.relatedTarget != view.contentDOM) view.dispatch({ effects: closeCompletionEffect.of(null) });
453
+ });
454
+ this.showOptions(options, cState.id);
455
+ }
456
+ mount() {
457
+ this.updateSel();
458
+ }
459
+ showOptions(options, id) {
460
+ if (this.list) this.list.remove();
461
+ this.list = this.dom.appendChild(this.createListBox(options, id, this.range));
462
+ this.list.addEventListener("scroll", () => {
463
+ if (this.info) this.view.requestMeasure(this.placeInfoReq);
464
+ });
465
+ }
466
+ update(update) {
467
+ var _a;
468
+ let cState = update.state.field(this.stateField);
469
+ let prevState = update.startState.field(this.stateField);
470
+ this.updateTooltipClass(update.state);
471
+ if (cState != prevState) {
472
+ let { options, selected, disabled } = cState.open;
473
+ if (!prevState.open || prevState.open.options != options) {
474
+ this.range = rangeAroundSelected(options.length, selected, update.state.facet(completionConfig).maxRenderedOptions);
475
+ this.showOptions(options, cState.id);
476
+ }
477
+ this.updateSel();
478
+ if (disabled != ((_a = prevState.open) === null || _a === void 0 ? void 0 : _a.disabled)) this.dom.classList.toggle("cm-tooltip-autocomplete-disabled", !!disabled);
479
+ }
480
+ }
481
+ updateTooltipClass(state) {
482
+ let cls = this.tooltipClass(state);
483
+ if (cls != this.currentClass) {
484
+ for (let c of this.currentClass.split(" ")) if (c) this.dom.classList.remove(c);
485
+ for (let c of cls.split(" ")) if (c) this.dom.classList.add(c);
486
+ this.currentClass = cls;
487
+ }
488
+ }
489
+ positioned(space) {
490
+ this.space = space;
491
+ if (this.info) this.view.requestMeasure(this.placeInfoReq);
492
+ }
493
+ updateSel() {
494
+ let cState = this.view.state.field(this.stateField), open = cState.open;
495
+ if (open.selected > -1 && open.selected < this.range.from || open.selected >= this.range.to) {
496
+ this.range = rangeAroundSelected(open.options.length, open.selected, this.view.state.facet(completionConfig).maxRenderedOptions);
497
+ this.showOptions(open.options, cState.id);
498
+ }
499
+ let newSel = this.updateSelectedOption(open.selected);
500
+ if (newSel) {
501
+ this.destroyInfo();
502
+ let { completion } = open.options[open.selected];
503
+ let { info } = completion;
504
+ if (!info) return;
505
+ let infoResult = typeof info === "string" ? document.createTextNode(info) : info(completion);
506
+ if (!infoResult) return;
507
+ if ("then" in infoResult) infoResult.then((obj) => {
508
+ if (obj && this.view.state.field(this.stateField, false) == cState) this.addInfoPane(obj, completion);
509
+ }).catch((e) => logException(this.view.state, e, "completion info"));
510
+ else {
511
+ this.addInfoPane(infoResult, completion);
512
+ newSel.setAttribute("aria-describedby", this.info.id);
513
+ }
514
+ }
515
+ }
516
+ addInfoPane(content, completion) {
517
+ this.destroyInfo();
518
+ let wrap = this.info = document.createElement("div");
519
+ wrap.className = "cm-tooltip cm-completionInfo";
520
+ wrap.id = "cm-completionInfo-" + Math.floor(Math.random() * 65535).toString(16);
521
+ if (content.nodeType != null) {
522
+ wrap.appendChild(content);
523
+ this.infoDestroy = null;
524
+ } else {
525
+ let { dom, destroy } = content;
526
+ wrap.appendChild(dom);
527
+ this.infoDestroy = destroy || null;
528
+ }
529
+ this.dom.appendChild(wrap);
530
+ this.view.requestMeasure(this.placeInfoReq);
531
+ }
532
+ updateSelectedOption(selected) {
533
+ let set = null;
534
+ for (let opt = this.list.firstChild, i = this.range.from; opt; opt = opt.nextSibling, i++) if (opt.nodeName != "LI" || !opt.id) i--;
535
+ else if (i == selected) {
536
+ if (!opt.hasAttribute("aria-selected")) {
537
+ opt.setAttribute("aria-selected", "true");
538
+ set = opt;
539
+ }
540
+ } else if (opt.hasAttribute("aria-selected")) {
541
+ opt.removeAttribute("aria-selected");
542
+ opt.removeAttribute("aria-describedby");
543
+ }
544
+ if (set) scrollIntoView(this.list, set);
545
+ return set;
546
+ }
547
+ measureInfo() {
548
+ let sel = this.dom.querySelector("[aria-selected]");
549
+ if (!sel || !this.info) return null;
550
+ let listRect = this.dom.getBoundingClientRect();
551
+ let infoRect = this.info.getBoundingClientRect();
552
+ let selRect = sel.getBoundingClientRect();
553
+ let space = this.space;
554
+ if (!space) {
555
+ let docElt = this.dom.ownerDocument.documentElement;
556
+ space = {
557
+ left: 0,
558
+ top: 0,
559
+ right: docElt.clientWidth,
560
+ bottom: docElt.clientHeight
561
+ };
562
+ }
563
+ if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 || selRect.bottom < Math.max(space.top, listRect.top) + 10) return null;
564
+ return this.view.state.facet(completionConfig).positionInfo(this.view, listRect, selRect, infoRect, space, this.dom);
565
+ }
566
+ placeInfo(pos) {
567
+ if (this.info) if (pos) {
568
+ if (pos.style) this.info.style.cssText = pos.style;
569
+ this.info.className = "cm-tooltip cm-completionInfo " + (pos.class || "");
570
+ } else this.info.style.cssText = "top: -1e6px";
571
+ }
572
+ createListBox(options, id, range) {
573
+ const ul = document.createElement("ul");
574
+ ul.id = id;
575
+ ul.setAttribute("role", "listbox");
576
+ ul.setAttribute("aria-expanded", "true");
577
+ ul.setAttribute("aria-label", this.view.state.phrase("Completions"));
578
+ ul.addEventListener("mousedown", (e) => {
579
+ if (e.target == ul) e.preventDefault();
580
+ });
581
+ let curSection = null;
582
+ for (let i = range.from; i < range.to; i++) {
583
+ let { completion, match } = options[i], { section } = completion;
584
+ if (section) {
585
+ let name = typeof section == "string" ? section : section.name;
586
+ if (name != curSection && (i > range.from || range.from == 0)) {
587
+ curSection = name;
588
+ if (typeof section != "string" && section.header) ul.appendChild(section.header(section));
589
+ else {
590
+ let header = ul.appendChild(document.createElement("completion-section"));
591
+ header.textContent = name;
592
+ }
593
+ }
594
+ }
595
+ const li = ul.appendChild(document.createElement("li"));
596
+ li.id = id + "-" + i;
597
+ li.setAttribute("role", "option");
598
+ let cls = this.optionClass(completion);
599
+ if (cls) li.className = cls;
600
+ for (let source of this.optionContent) {
601
+ let node = source(completion, this.view.state, this.view, match);
602
+ if (node) li.appendChild(node);
603
+ }
604
+ }
605
+ if (range.from) ul.classList.add("cm-completionListIncompleteTop");
606
+ if (range.to < options.length) ul.classList.add("cm-completionListIncompleteBottom");
607
+ return ul;
608
+ }
609
+ destroyInfo() {
610
+ if (this.info) {
611
+ if (this.infoDestroy) this.infoDestroy();
612
+ this.info.remove();
613
+ this.info = null;
614
+ }
615
+ }
616
+ destroy() {
617
+ this.destroyInfo();
618
+ }
619
+ };
620
+ function completionTooltip(stateField, applyCompletion) {
621
+ return (view) => new CompletionTooltip(view, stateField, applyCompletion);
622
+ }
623
+ function scrollIntoView(container, element) {
624
+ let parent = container.getBoundingClientRect();
625
+ let self = element.getBoundingClientRect();
626
+ let scaleY = parent.height / container.offsetHeight;
627
+ if (self.top < parent.top) container.scrollTop -= (parent.top - self.top) / scaleY;
628
+ else if (self.bottom > parent.bottom) container.scrollTop += (self.bottom - parent.bottom) / scaleY;
629
+ }
630
+ function score(option) {
631
+ return (option.boost || 0) * 100 + (option.apply ? 10 : 0) + (option.info ? 5 : 0) + (option.type ? 1 : 0);
632
+ }
633
+ function sortOptions(active, state) {
634
+ let options = [];
635
+ let sections = null, dynamicSectionScore = null;
636
+ let addOption = (option) => {
637
+ options.push(option);
638
+ let { section } = option.completion;
639
+ if (section) {
640
+ if (!sections) sections = [];
641
+ let name = typeof section == "string" ? section : section.name;
642
+ if (!sections.some((s) => s.name == name)) sections.push(typeof section == "string" ? { name } : section);
643
+ }
644
+ };
645
+ let conf = state.facet(completionConfig);
646
+ for (let a of active) if (a.hasResult()) {
647
+ let getMatch = a.result.getMatch;
648
+ if (a.result.filter === false) for (let option of a.result.options) addOption(new Option(option, a.source, getMatch ? getMatch(option) : [], 1e9 - options.length));
649
+ else {
650
+ let pattern = state.sliceDoc(a.from, a.to), match;
651
+ let matcher = conf.filterStrict ? new StrictMatcher(pattern) : new FuzzyMatcher(pattern);
652
+ for (let option of a.result.options) if (match = matcher.match(option.label)) {
653
+ let matched = !option.displayLabel ? match.matched : getMatch ? getMatch(option, match.matched) : [];
654
+ let score = match.score + (option.boost || 0);
655
+ addOption(new Option(option, a.source, matched, score));
656
+ if (typeof option.section == "object" && option.section.rank === "dynamic") {
657
+ let { name } = option.section;
658
+ if (!dynamicSectionScore) dynamicSectionScore = Object.create(null);
659
+ dynamicSectionScore[name] = Math.max(score, dynamicSectionScore[name] || -1e9);
660
+ }
661
+ }
662
+ }
663
+ }
664
+ if (sections) {
665
+ let sectionOrder = Object.create(null), pos = 0;
666
+ let cmp = (a, b) => {
667
+ return (a.rank === "dynamic" && b.rank === "dynamic" ? dynamicSectionScore[b.name] - dynamicSectionScore[a.name] : 0) || (typeof a.rank == "number" ? a.rank : 1e9) - (typeof b.rank == "number" ? b.rank : 1e9) || (a.name < b.name ? -1 : 1);
668
+ };
669
+ for (let s of sections.sort(cmp)) {
670
+ pos -= 1e5;
671
+ sectionOrder[s.name] = pos;
672
+ }
673
+ for (let option of options) {
674
+ let { section } = option.completion;
675
+ if (section) option.score += sectionOrder[typeof section == "string" ? section : section.name];
676
+ }
677
+ }
678
+ let result = [], prev = null;
679
+ let compare = conf.compareCompletions;
680
+ for (let opt of options.sort((a, b) => b.score - a.score || compare(a.completion, b.completion))) {
681
+ let cur = opt.completion;
682
+ if (!prev || prev.label != cur.label || prev.detail != cur.detail || prev.type != null && cur.type != null && prev.type != cur.type || prev.apply != cur.apply || prev.boost != cur.boost) result.push(opt);
683
+ else if (score(opt.completion) > score(prev)) result[result.length - 1] = opt;
684
+ prev = opt.completion;
685
+ }
686
+ return result;
687
+ }
688
+ var CompletionDialog = class CompletionDialog {
689
+ constructor(options, attrs, tooltip, timestamp, selected, disabled) {
690
+ this.options = options;
691
+ this.attrs = attrs;
692
+ this.tooltip = tooltip;
693
+ this.timestamp = timestamp;
694
+ this.selected = selected;
695
+ this.disabled = disabled;
696
+ }
697
+ setSelected(selected, id) {
698
+ return selected == this.selected || selected >= this.options.length ? this : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
699
+ }
700
+ static build(active, state, id, prev, conf, didSetActive) {
701
+ if (prev && !didSetActive && active.some((s) => s.isPending)) return prev.setDisabled();
702
+ let options = sortOptions(active, state);
703
+ if (!options.length) return prev && active.some((a) => a.isPending) ? prev.setDisabled() : null;
704
+ let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
705
+ if (prev && prev.selected != selected && prev.selected != -1) {
706
+ let selectedValue = prev.options[prev.selected].completion;
707
+ for (let i = 0; i < options.length; i++) if (options[i].completion == selectedValue) {
708
+ selected = i;
709
+ break;
710
+ }
711
+ }
712
+ return new CompletionDialog(options, makeAttrs(id, selected), {
713
+ pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
714
+ create: createTooltip,
715
+ above: conf.aboveCursor
716
+ }, prev ? prev.timestamp : Date.now(), selected, false);
717
+ }
718
+ map(changes) {
719
+ return new CompletionDialog(this.options, this.attrs, {
720
+ ...this.tooltip,
721
+ pos: changes.mapPos(this.tooltip.pos)
722
+ }, this.timestamp, this.selected, this.disabled);
723
+ }
724
+ setDisabled() {
725
+ return new CompletionDialog(this.options, this.attrs, this.tooltip, this.timestamp, this.selected, true);
726
+ }
727
+ };
728
+ var CompletionState = class CompletionState {
729
+ constructor(active, id, open) {
730
+ this.active = active;
731
+ this.id = id;
732
+ this.open = open;
733
+ }
734
+ static start() {
735
+ return new CompletionState(none, "cm-ac-" + Math.floor(Math.random() * 2e6).toString(36), null);
736
+ }
737
+ update(tr) {
738
+ let { state } = tr, conf = state.facet(completionConfig);
739
+ let active = (conf.override || state.languageDataAt("autocomplete", cur(state)).map(asSource)).map((source) => {
740
+ return (this.active.find((s) => s.source == source) || new ActiveSource(source, this.active.some((a) => a.state != 0) ? 1 : 0)).update(tr, conf);
741
+ });
742
+ if (active.length == this.active.length && active.every((a, i) => a == this.active[i])) active = this.active;
743
+ let open = this.open, didSet = tr.effects.some((e) => e.is(setActiveEffect));
744
+ if (open && tr.docChanged) open = open.map(tr.changes);
745
+ if (tr.selection || active.some((a) => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) || !sameResults(active, this.active) || didSet) open = CompletionDialog.build(active, state, this.id, open, conf, didSet);
746
+ else if (open && open.disabled && !active.some((a) => a.isPending)) open = null;
747
+ if (!open && active.every((a) => !a.isPending) && active.some((a) => a.hasResult())) active = active.map((a) => a.hasResult() ? new ActiveSource(a.source, 0) : a);
748
+ for (let effect of tr.effects) if (effect.is(setSelectedEffect)) open = open && open.setSelected(effect.value, this.id);
749
+ return active == this.active && open == this.open ? this : new CompletionState(active, this.id, open);
750
+ }
751
+ get tooltip() {
752
+ return this.open ? this.open.tooltip : null;
753
+ }
754
+ get attrs() {
755
+ return this.open ? this.open.attrs : this.active.length ? baseAttrs : noAttrs;
756
+ }
757
+ };
758
+ function sameResults(a, b) {
759
+ if (a == b) return true;
760
+ for (let iA = 0, iB = 0;;) {
761
+ while (iA < a.length && !a[iA].hasResult()) iA++;
762
+ while (iB < b.length && !b[iB].hasResult()) iB++;
763
+ let endA = iA == a.length, endB = iB == b.length;
764
+ if (endA || endB) return endA == endB;
765
+ if (a[iA++].result != b[iB++].result) return false;
766
+ }
767
+ }
768
+ const baseAttrs = { "aria-autocomplete": "list" };
769
+ const noAttrs = {};
770
+ function makeAttrs(id, selected) {
771
+ let result = {
772
+ "aria-autocomplete": "list",
773
+ "aria-haspopup": "listbox",
774
+ "aria-controls": id
775
+ };
776
+ if (selected > -1) result["aria-activedescendant"] = id + "-" + selected;
777
+ return result;
778
+ }
779
+ const none = [];
780
+ function getUpdateType(tr, conf) {
781
+ if (tr.isUserEvent("input.complete")) {
782
+ let completion = tr.annotation(pickedCompletion);
783
+ if (completion && conf.activateOnCompletion(completion)) return 12;
784
+ }
785
+ let typing = tr.isUserEvent("input.type");
786
+ return typing && conf.activateOnTyping ? 5 : typing ? 1 : tr.isUserEvent("delete.backward") ? 2 : tr.selection ? 8 : tr.docChanged ? 16 : 0;
787
+ }
788
+ var ActiveSource = class ActiveSource {
789
+ constructor(source, state, explicit = false) {
790
+ this.source = source;
791
+ this.state = state;
792
+ this.explicit = explicit;
793
+ }
794
+ hasResult() {
795
+ return false;
796
+ }
797
+ get isPending() {
798
+ return this.state == 1;
799
+ }
800
+ update(tr, conf) {
801
+ let type = getUpdateType(tr, conf), value = this;
802
+ if (type & 8 || type & 16 && this.touches(tr)) value = new ActiveSource(value.source, 0);
803
+ if (type & 4 && value.state == 0) value = new ActiveSource(this.source, 1);
804
+ value = value.updateFor(tr, type);
805
+ for (let effect of tr.effects) if (effect.is(startCompletionEffect)) value = new ActiveSource(value.source, 1, effect.value);
806
+ else if (effect.is(closeCompletionEffect)) value = new ActiveSource(value.source, 0);
807
+ else if (effect.is(setActiveEffect)) {
808
+ for (let active of effect.value) if (active.source == value.source) value = active;
809
+ }
810
+ return value;
811
+ }
812
+ updateFor(tr, type) {
813
+ return this.map(tr.changes);
814
+ }
815
+ map(changes) {
816
+ return this;
817
+ }
818
+ touches(tr) {
819
+ return tr.changes.touchesRange(cur(tr.state));
820
+ }
821
+ };
822
+ var ActiveResult = class ActiveResult extends ActiveSource {
823
+ constructor(source, explicit, limit, result, from, to) {
824
+ super(source, 3, explicit);
825
+ this.limit = limit;
826
+ this.result = result;
827
+ this.from = from;
828
+ this.to = to;
829
+ }
830
+ hasResult() {
831
+ return true;
832
+ }
833
+ updateFor(tr, type) {
834
+ var _a;
835
+ if (!(type & 3)) return this.map(tr.changes);
836
+ let result = this.result;
837
+ if (result.map && !tr.changes.empty) result = result.map(result, tr.changes);
838
+ let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
839
+ let pos = cur(tr.state);
840
+ if (pos > to || !result || type & 2 && (cur(tr.startState) == this.from || pos < this.limit)) return new ActiveSource(this.source, type & 4 ? 1 : 0);
841
+ let limit = tr.changes.mapPos(this.limit);
842
+ if (checkValid(result.validFor, tr.state, from, to)) return new ActiveResult(this.source, this.explicit, limit, result, from, to);
843
+ if (result.update && (result = result.update(result, from, to, new CompletionContext(tr.state, pos, false)))) return new ActiveResult(this.source, this.explicit, limit, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
844
+ return new ActiveSource(this.source, 1, this.explicit);
845
+ }
846
+ map(mapping) {
847
+ if (mapping.empty) return this;
848
+ let result = this.result.map ? this.result.map(this.result, mapping) : this.result;
849
+ if (!result) return new ActiveSource(this.source, 0);
850
+ return new ActiveResult(this.source, this.explicit, mapping.mapPos(this.limit), result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
851
+ }
852
+ touches(tr) {
853
+ return tr.changes.touchesRange(this.from, this.to);
854
+ }
855
+ };
856
+ function checkValid(validFor, state, from, to) {
857
+ if (!validFor) return false;
858
+ let text = state.sliceDoc(from, to);
859
+ return typeof validFor == "function" ? validFor(text, from, to, state) : ensureAnchor(validFor, true).test(text);
860
+ }
861
+ const setActiveEffect = /*@__PURE__*/ StateEffect.define({ map(sources, mapping) {
862
+ return sources.map((s) => s.map(mapping));
863
+ } });
864
+ const completionState = /*@__PURE__*/ StateField.define({
865
+ create() {
866
+ return CompletionState.start();
867
+ },
868
+ update(value, tr) {
869
+ return value.update(tr);
870
+ },
871
+ provide: (f) => [showTooltip.from(f, (val) => val.tooltip), EditorView.contentAttributes.from(f, (state) => state.attrs)]
872
+ });
873
+ function applyCompletion(view, option) {
874
+ const apply = option.completion.apply || option.completion.label;
875
+ let result = view.state.field(completionState).active.find((a) => a.source == option.source);
876
+ if (!(result instanceof ActiveResult)) return false;
877
+ if (typeof apply == "string") view.dispatch({
878
+ ...insertCompletionText(view.state, apply, result.from, result.to),
879
+ annotations: pickedCompletion.of(option.completion)
880
+ });
881
+ else apply(view, option.completion, result.from, result.to);
882
+ return true;
883
+ }
884
+ const createTooltip = /*@__PURE__*/ completionTooltip(completionState, applyCompletion);
885
+ /**
886
+ Returns a command that moves the completion selection forward or
887
+ backward by the given amount.
888
+ */
889
+ function moveCompletionSelection(forward, by = "option") {
890
+ return (view) => {
891
+ let cState = view.state.field(completionState, false);
892
+ if (!cState || !cState.open || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) return false;
893
+ let step = 1, tooltip;
894
+ if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip))) step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector("li").offsetHeight) - 1);
895
+ let { length } = cState.open.options;
896
+ let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length - 1;
897
+ if (selected < 0) selected = by == "page" ? 0 : length - 1;
898
+ else if (selected >= length) selected = by == "page" ? length - 1 : 0;
899
+ view.dispatch({ effects: setSelectedEffect.of(selected) });
900
+ return true;
901
+ };
902
+ }
903
+ /**
904
+ Accept the current completion.
905
+ */
906
+ const acceptCompletion = (view) => {
907
+ let cState = view.state.field(completionState, false);
908
+ if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay) return false;
909
+ return applyCompletion(view, cState.open.options[cState.open.selected]);
910
+ };
911
+ /**
912
+ Explicitly start autocompletion.
913
+ */
914
+ const startCompletion = (view) => {
915
+ if (!view.state.field(completionState, false)) return false;
916
+ view.dispatch({ effects: startCompletionEffect.of(true) });
917
+ return true;
918
+ };
919
+ /**
920
+ Close the currently active completion.
921
+ */
922
+ const closeCompletion = (view) => {
923
+ let cState = view.state.field(completionState, false);
924
+ if (!cState || !cState.active.some((a) => a.state != 0)) return false;
925
+ view.dispatch({ effects: closeCompletionEffect.of(null) });
926
+ return true;
927
+ };
928
+ var RunningQuery = class {
929
+ constructor(active, context) {
930
+ this.active = active;
931
+ this.context = context;
932
+ this.time = Date.now();
933
+ this.updates = [];
934
+ this.done = void 0;
935
+ }
936
+ };
937
+ const MaxUpdateCount = 50, MinAbortTime = 1e3;
938
+ const completionPlugin = /*@__PURE__*/ ViewPlugin.fromClass(class {
939
+ constructor(view) {
940
+ this.view = view;
941
+ this.debounceUpdate = -1;
942
+ this.running = [];
943
+ this.debounceAccept = -1;
944
+ this.pendingStart = false;
945
+ this.composing = 0;
946
+ for (let active of view.state.field(completionState).active) if (active.isPending) this.startQuery(active);
947
+ }
948
+ update(update) {
949
+ let cState = update.state.field(completionState);
950
+ let conf = update.state.facet(completionConfig);
951
+ if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState) return;
952
+ let doesReset = update.transactions.some((tr) => {
953
+ let type = getUpdateType(tr, conf);
954
+ return type & 8 || (tr.selection || tr.docChanged) && !(type & 3);
955
+ });
956
+ for (let i = 0; i < this.running.length; i++) {
957
+ let query = this.running[i];
958
+ if (doesReset || query.context.abortOnDocChange && update.docChanged || query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
959
+ for (let handler of query.context.abortListeners) try {
960
+ handler();
961
+ } catch (e) {
962
+ logException(this.view.state, e);
963
+ }
964
+ query.context.abortListeners = null;
965
+ this.running.splice(i--, 1);
966
+ } else query.updates.push(...update.transactions);
967
+ }
968
+ if (this.debounceUpdate > -1) clearTimeout(this.debounceUpdate);
969
+ if (update.transactions.some((tr) => tr.effects.some((e) => e.is(startCompletionEffect)))) this.pendingStart = true;
970
+ let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
971
+ this.debounceUpdate = cState.active.some((a) => a.isPending && !this.running.some((q) => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), delay) : -1;
972
+ if (this.composing != 0) {
973
+ for (let tr of update.transactions) if (tr.isUserEvent("input.type")) this.composing = 2;
974
+ else if (this.composing == 2 && tr.selection) this.composing = 3;
975
+ }
976
+ }
977
+ startUpdate() {
978
+ this.debounceUpdate = -1;
979
+ this.pendingStart = false;
980
+ let { state } = this.view, cState = state.field(completionState);
981
+ for (let active of cState.active) if (active.isPending && !this.running.some((r) => r.active.source == active.source)) this.startQuery(active);
982
+ if (this.running.length && cState.open && cState.open.disabled) this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime);
983
+ }
984
+ startQuery(active) {
985
+ let { state } = this.view;
986
+ let context = new CompletionContext(state, cur(state), active.explicit, this.view);
987
+ let pending = new RunningQuery(active, context);
988
+ this.running.push(pending);
989
+ Promise.resolve(active.source(context)).then((result) => {
990
+ if (!pending.context.aborted) {
991
+ pending.done = result || null;
992
+ this.scheduleAccept();
993
+ }
994
+ }, (err) => {
995
+ this.view.dispatch({ effects: closeCompletionEffect.of(null) });
996
+ logException(this.view.state, err);
997
+ });
998
+ }
999
+ scheduleAccept() {
1000
+ if (this.running.every((q) => q.done !== void 0)) this.accept();
1001
+ else if (this.debounceAccept < 0) this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime);
1002
+ }
1003
+ accept() {
1004
+ var _a;
1005
+ if (this.debounceAccept > -1) clearTimeout(this.debounceAccept);
1006
+ this.debounceAccept = -1;
1007
+ let updated = [];
1008
+ let conf = this.view.state.facet(completionConfig), cState = this.view.state.field(completionState);
1009
+ for (let i = 0; i < this.running.length; i++) {
1010
+ let query = this.running[i];
1011
+ if (query.done === void 0) continue;
1012
+ this.running.splice(i--, 1);
1013
+ if (query.done) {
1014
+ let pos = cur(query.updates.length ? query.updates[0].startState : this.view.state);
1015
+ let limit = Math.min(pos, query.done.from + (query.active.explicit ? 0 : 1));
1016
+ let active = new ActiveResult(query.active.source, query.active.explicit, limit, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : pos);
1017
+ for (let tr of query.updates) active = active.update(tr, conf);
1018
+ if (active.hasResult()) {
1019
+ updated.push(active);
1020
+ continue;
1021
+ }
1022
+ }
1023
+ let current = cState.active.find((a) => a.source == query.active.source);
1024
+ if (current && current.isPending) if (query.done == null) {
1025
+ let active = new ActiveSource(query.active.source, 0);
1026
+ for (let tr of query.updates) active = active.update(tr, conf);
1027
+ if (!active.isPending) updated.push(active);
1028
+ } else this.startQuery(current);
1029
+ }
1030
+ if (updated.length || cState.open && cState.open.disabled) this.view.dispatch({ effects: setActiveEffect.of(updated) });
1031
+ }
1032
+ }, { eventHandlers: {
1033
+ blur(event) {
1034
+ let state = this.view.state.field(completionState, false);
1035
+ if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
1036
+ let dialog = state.open && getTooltip(this.view, state.open.tooltip);
1037
+ if (!dialog || !dialog.dom.contains(event.relatedTarget)) setTimeout(() => this.view.dispatch({ effects: closeCompletionEffect.of(null) }), 10);
1038
+ }
1039
+ },
1040
+ compositionstart() {
1041
+ this.composing = 1;
1042
+ },
1043
+ compositionend() {
1044
+ if (this.composing == 3) setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20);
1045
+ this.composing = 0;
1046
+ }
1047
+ } });
1048
+ const windows = typeof navigator == "object" && /*@__PURE__*/ /Win/.test(navigator.platform);
1049
+ const commitCharacters = /*@__PURE__*/ Prec.highest(/*@__PURE__*/ EditorView.domEventHandlers({ keydown(event, view) {
1050
+ let field = view.state.field(completionState, false);
1051
+ if (!field || !field.open || field.open.disabled || field.open.selected < 0 || event.key.length > 1 || event.ctrlKey && !(windows && event.altKey) || event.metaKey) return false;
1052
+ let option = field.open.options[field.open.selected];
1053
+ let result = field.active.find((a) => a.source == option.source);
1054
+ let commitChars = option.completion.commitCharacters || result.result.commitCharacters;
1055
+ if (commitChars && commitChars.indexOf(event.key) > -1) applyCompletion(view, option);
1056
+ return false;
1057
+ } }));
1058
+ const baseTheme = /*@__PURE__*/ EditorView.baseTheme({
1059
+ ".cm-tooltip.cm-tooltip-autocomplete": { "& > ul": {
1060
+ fontFamily: "monospace",
1061
+ whiteSpace: "nowrap",
1062
+ overflow: "hidden auto",
1063
+ maxWidth_fallback: "700px",
1064
+ maxWidth: "min(700px, 95vw)",
1065
+ minWidth: "250px",
1066
+ maxHeight: "10em",
1067
+ height: "100%",
1068
+ listStyle: "none",
1069
+ margin: 0,
1070
+ padding: 0,
1071
+ "& > li, & > completion-section": {
1072
+ padding: "1px 3px",
1073
+ lineHeight: 1.2
1074
+ },
1075
+ "& > li": {
1076
+ overflowX: "hidden",
1077
+ textOverflow: "ellipsis",
1078
+ cursor: "pointer"
1079
+ },
1080
+ "& > completion-section": {
1081
+ display: "list-item",
1082
+ borderBottom: "1px solid silver",
1083
+ paddingLeft: "0.5em",
1084
+ opacity: .7
1085
+ }
1086
+ } },
1087
+ "&light .cm-tooltip-autocomplete ul li[aria-selected]": {
1088
+ background: "#17c",
1089
+ color: "white"
1090
+ },
1091
+ "&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]": { background: "#777" },
1092
+ "&dark .cm-tooltip-autocomplete ul li[aria-selected]": {
1093
+ background: "#347",
1094
+ color: "white"
1095
+ },
1096
+ "&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]": { background: "#444" },
1097
+ ".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after": {
1098
+ content: "\"···\"",
1099
+ opacity: .5,
1100
+ display: "block",
1101
+ textAlign: "center",
1102
+ cursor: "pointer"
1103
+ },
1104
+ ".cm-tooltip.cm-completionInfo": {
1105
+ position: "absolute",
1106
+ padding: "3px 9px",
1107
+ width: "max-content",
1108
+ maxWidth: `400px`,
1109
+ boxSizing: "border-box",
1110
+ whiteSpace: "pre-line"
1111
+ },
1112
+ ".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
1113
+ ".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
1114
+ ".cm-completionInfo.cm-completionInfo-left-narrow": { right: `30px` },
1115
+ ".cm-completionInfo.cm-completionInfo-right-narrow": { left: `30px` },
1116
+ "&light .cm-snippetField": { backgroundColor: "#00000022" },
1117
+ "&dark .cm-snippetField": { backgroundColor: "#ffffff22" },
1118
+ ".cm-snippetFieldPosition": {
1119
+ verticalAlign: "text-top",
1120
+ width: 0,
1121
+ height: "1.15em",
1122
+ display: "inline-block",
1123
+ margin: "0 -0.7px -.7em",
1124
+ borderLeft: "1.4px dotted #888"
1125
+ },
1126
+ ".cm-completionMatchedText": { textDecoration: "underline" },
1127
+ ".cm-completionDetail": {
1128
+ marginLeft: "0.5em",
1129
+ fontStyle: "italic"
1130
+ },
1131
+ ".cm-completionIcon": {
1132
+ fontSize: "90%",
1133
+ width: ".8em",
1134
+ display: "inline-block",
1135
+ textAlign: "center",
1136
+ paddingRight: ".6em",
1137
+ opacity: "0.6",
1138
+ boxSizing: "content-box"
1139
+ },
1140
+ ".cm-completionIcon-function, .cm-completionIcon-method": { "&:after": { content: "'ƒ'" } },
1141
+ ".cm-completionIcon-class": { "&:after": { content: "'○'" } },
1142
+ ".cm-completionIcon-interface": { "&:after": { content: "'◌'" } },
1143
+ ".cm-completionIcon-variable": { "&:after": { content: "'𝑥'" } },
1144
+ ".cm-completionIcon-constant": { "&:after": { content: "'𝐶'" } },
1145
+ ".cm-completionIcon-type": { "&:after": { content: "'𝑡'" } },
1146
+ ".cm-completionIcon-enum": { "&:after": { content: "'∪'" } },
1147
+ ".cm-completionIcon-property": { "&:after": { content: "'□'" } },
1148
+ ".cm-completionIcon-keyword": { "&:after": { content: "'🔑︎'" } },
1149
+ ".cm-completionIcon-namespace": { "&:after": { content: "'▢'" } },
1150
+ ".cm-completionIcon-text": { "&:after": {
1151
+ content: "'abc'",
1152
+ fontSize: "50%",
1153
+ verticalAlign: "middle"
1154
+ } }
1155
+ });
1156
+ var FieldPos = class {
1157
+ constructor(field, line, from, to) {
1158
+ this.field = field;
1159
+ this.line = line;
1160
+ this.from = from;
1161
+ this.to = to;
1162
+ }
1163
+ };
1164
+ var FieldRange = class FieldRange {
1165
+ constructor(field, from, to) {
1166
+ this.field = field;
1167
+ this.from = from;
1168
+ this.to = to;
1169
+ }
1170
+ map(changes) {
1171
+ let from = changes.mapPos(this.from, -1, MapMode.TrackDel);
1172
+ let to = changes.mapPos(this.to, 1, MapMode.TrackDel);
1173
+ return from == null || to == null ? null : new FieldRange(this.field, from, to);
1174
+ }
1175
+ };
1176
+ var Snippet = class Snippet {
1177
+ constructor(lines, fieldPositions) {
1178
+ this.lines = lines;
1179
+ this.fieldPositions = fieldPositions;
1180
+ }
1181
+ instantiate(state, pos) {
1182
+ let text = [], lineStart = [pos];
1183
+ let lineObj = state.doc.lineAt(pos), baseIndent = /^\s*/.exec(lineObj.text)[0];
1184
+ for (let line of this.lines) {
1185
+ if (text.length) {
1186
+ let indent = baseIndent, tabs = /^\t*/.exec(line)[0].length;
1187
+ for (let i = 0; i < tabs; i++) indent += state.facet(indentUnit);
1188
+ lineStart.push(pos + indent.length - tabs);
1189
+ line = indent + line.slice(tabs);
1190
+ }
1191
+ text.push(line);
1192
+ pos += line.length + 1;
1193
+ }
1194
+ return {
1195
+ text,
1196
+ ranges: this.fieldPositions.map((pos) => new FieldRange(pos.field, lineStart[pos.line] + pos.from, lineStart[pos.line] + pos.to))
1197
+ };
1198
+ }
1199
+ static parse(template) {
1200
+ let fields = [];
1201
+ let lines = [], positions = [], m;
1202
+ for (let line of template.split(/\r\n?|\n/)) {
1203
+ while (m = /[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(line)) {
1204
+ let seq = m[1] ? +m[1] : null, rawName = m[2] || m[3] || "", found = -1;
1205
+ if (seq === 0) seq = 1e9;
1206
+ let name = rawName.replace(/\\[{}]/g, (m) => m[1]);
1207
+ for (let i = 0; i < fields.length; i++) if (seq != null ? fields[i].seq == seq : name ? fields[i].name == name : false) found = i;
1208
+ if (found < 0) {
1209
+ let i = 0;
1210
+ while (i < fields.length && (seq == null || fields[i].seq != null && fields[i].seq < seq)) i++;
1211
+ fields.splice(i, 0, {
1212
+ seq,
1213
+ name
1214
+ });
1215
+ found = i;
1216
+ for (let pos of positions) if (pos.field >= found) pos.field++;
1217
+ }
1218
+ for (let pos of positions) if (pos.line == lines.length && pos.from > m.index) {
1219
+ let snip = m[2] ? 3 + (m[1] || "").length : 2;
1220
+ pos.from -= snip;
1221
+ pos.to -= snip;
1222
+ }
1223
+ positions.push(new FieldPos(found, lines.length, m.index, m.index + name.length));
1224
+ line = line.slice(0, m.index) + rawName + line.slice(m.index + m[0].length);
1225
+ }
1226
+ line = line.replace(/\\([{}])/g, (_, brace, index) => {
1227
+ for (let pos of positions) if (pos.line == lines.length && pos.from > index) {
1228
+ pos.from--;
1229
+ pos.to--;
1230
+ }
1231
+ return brace;
1232
+ });
1233
+ lines.push(line);
1234
+ }
1235
+ return new Snippet(lines, positions);
1236
+ }
1237
+ };
1238
+ let fieldMarker = /*@__PURE__*/ Decoration.widget({ widget: /*@__PURE__*/ new class extends WidgetType {
1239
+ toDOM() {
1240
+ let span = document.createElement("span");
1241
+ span.className = "cm-snippetFieldPosition";
1242
+ return span;
1243
+ }
1244
+ ignoreEvent() {
1245
+ return false;
1246
+ }
1247
+ }() });
1248
+ let fieldRange = /*@__PURE__*/ Decoration.mark({ class: "cm-snippetField" });
1249
+ var ActiveSnippet = class ActiveSnippet {
1250
+ constructor(ranges, active) {
1251
+ this.ranges = ranges;
1252
+ this.active = active;
1253
+ this.deco = Decoration.set(ranges.map((r) => (r.from == r.to ? fieldMarker : fieldRange).range(r.from, r.to)), true);
1254
+ }
1255
+ map(changes) {
1256
+ let ranges = [];
1257
+ for (let r of this.ranges) {
1258
+ let mapped = r.map(changes);
1259
+ if (!mapped) return null;
1260
+ ranges.push(mapped);
1261
+ }
1262
+ return new ActiveSnippet(ranges, this.active);
1263
+ }
1264
+ selectionInsideField(sel) {
1265
+ return sel.ranges.every((range) => this.ranges.some((r) => r.field == this.active && r.from <= range.from && r.to >= range.to));
1266
+ }
1267
+ };
1268
+ const setActive = /*@__PURE__*/ StateEffect.define({ map(value, changes) {
1269
+ return value && value.map(changes);
1270
+ } });
1271
+ const moveToField = /*@__PURE__*/ StateEffect.define();
1272
+ const snippetState = /*@__PURE__*/ StateField.define({
1273
+ create() {
1274
+ return null;
1275
+ },
1276
+ update(value, tr) {
1277
+ for (let effect of tr.effects) {
1278
+ if (effect.is(setActive)) return effect.value;
1279
+ if (effect.is(moveToField) && value) return new ActiveSnippet(value.ranges, effect.value);
1280
+ }
1281
+ if (value && tr.docChanged) value = value.map(tr.changes);
1282
+ if (value && tr.selection && !value.selectionInsideField(tr.selection)) value = null;
1283
+ return value;
1284
+ },
1285
+ provide: (f) => EditorView.decorations.from(f, (val) => val ? val.deco : Decoration.none)
1286
+ });
1287
+ function fieldSelection(ranges, field) {
1288
+ return EditorSelection.create(ranges.filter((r) => r.field == field).map((r) => EditorSelection.range(r.from, r.to)));
1289
+ }
1290
+ /**
1291
+ Convert a snippet template to a function that can
1292
+ [apply](https://codemirror.net/6/docs/ref/#autocomplete.Completion.apply) it. Snippets are written
1293
+ using syntax like this:
1294
+
1295
+ "for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}"
1296
+
1297
+ Each `${}` placeholder (you may also use `#{}`) indicates a field
1298
+ that the user can fill in. Its name, if any, will be the default
1299
+ content for the field.
1300
+
1301
+ When the snippet is activated by calling the returned function,
1302
+ the code is inserted at the given position. Newlines in the
1303
+ template are indented by the indentation of the start line, plus
1304
+ one [indent unit](https://codemirror.net/6/docs/ref/#language.indentUnit) per tab character after
1305
+ the newline.
1306
+
1307
+ On activation, (all instances of) the first field are selected.
1308
+ The user can move between fields with Tab and Shift-Tab as long as
1309
+ the fields are active. Moving to the last field or moving the
1310
+ cursor out of the current field deactivates the fields.
1311
+
1312
+ The order of fields defaults to textual order, but you can add
1313
+ numbers to placeholders (`${1}` or `${1:defaultText}`) to provide
1314
+ a custom order. `${0}` is special—it is always the last stop, where
1315
+ the cursor ends up after tabbing through the other fields.
1316
+
1317
+ To include a literal `{` or `}` in your template, put a backslash
1318
+ in front of it. This will be removed and the brace will not be
1319
+ interpreted as indicating a placeholder.
1320
+ */
1321
+ function snippet(template) {
1322
+ let snippet = Snippet.parse(template);
1323
+ return (editor, completion, from, to) => {
1324
+ let { text, ranges } = snippet.instantiate(editor.state, from);
1325
+ let { main } = editor.state.selection;
1326
+ let spec = {
1327
+ changes: {
1328
+ from,
1329
+ to: to == main.from ? main.to : to,
1330
+ insert: Text.of(text)
1331
+ },
1332
+ scrollIntoView: true,
1333
+ annotations: completion ? [pickedCompletion.of(completion), Transaction.userEvent.of("input.complete")] : void 0
1334
+ };
1335
+ if (ranges.length) spec.selection = fieldSelection(ranges, 0);
1336
+ if (ranges.some((r) => r.field > 0)) {
1337
+ let active = new ActiveSnippet(ranges, 0);
1338
+ let effects = spec.effects = [setActive.of(active)];
1339
+ if (editor.state.field(snippetState, false) === void 0) effects.push(StateEffect.appendConfig.of([
1340
+ snippetState,
1341
+ addSnippetKeymap,
1342
+ snippetPointerHandler,
1343
+ baseTheme
1344
+ ]));
1345
+ }
1346
+ editor.dispatch(editor.state.update(spec));
1347
+ };
1348
+ }
1349
+ function moveField(dir) {
1350
+ return ({ state, dispatch }) => {
1351
+ let active = state.field(snippetState, false);
1352
+ if (!active || dir < 0 && active.active == 0) return false;
1353
+ let next = active.active + dir, last = dir > 0 && !active.ranges.some((r) => r.field == next + dir);
1354
+ dispatch(state.update({
1355
+ selection: fieldSelection(active.ranges, next),
1356
+ effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next)),
1357
+ scrollIntoView: true
1358
+ }));
1359
+ return true;
1360
+ };
1361
+ }
1362
+ /**
1363
+ A command that clears the active snippet, if any.
1364
+ */
1365
+ const clearSnippet = ({ state, dispatch }) => {
1366
+ if (!state.field(snippetState, false)) return false;
1367
+ dispatch(state.update({ effects: setActive.of(null) }));
1368
+ return true;
1369
+ };
1370
+ const defaultSnippetKeymap = [{
1371
+ key: "Tab",
1372
+ run: /* @__PURE__ */ moveField(1),
1373
+ shift: /* @__PURE__ */ moveField(-1)
1374
+ }, {
1375
+ key: "Escape",
1376
+ run: clearSnippet
1377
+ }];
1378
+ /**
1379
+ A facet that can be used to configure the key bindings used by
1380
+ snippets. The default binds Tab to
1381
+ [`nextSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.nextSnippetField), Shift-Tab to
1382
+ [`prevSnippetField`](https://codemirror.net/6/docs/ref/#autocomplete.prevSnippetField), and Escape
1383
+ to [`clearSnippet`](https://codemirror.net/6/docs/ref/#autocomplete.clearSnippet).
1384
+ */
1385
+ const snippetKeymap = /*@__PURE__*/ Facet.define({ combine(maps) {
1386
+ return maps.length ? maps[0] : defaultSnippetKeymap;
1387
+ } });
1388
+ const addSnippetKeymap = /*@__PURE__*/ Prec.highest(/*@__PURE__*/ keymap.compute([snippetKeymap], (state) => state.facet(snippetKeymap)));
1389
+ /**
1390
+ Create a completion from a snippet. Returns an object with the
1391
+ properties from `completion`, plus an `apply` function that
1392
+ applies the snippet.
1393
+ */
1394
+ function snippetCompletion(template, completion) {
1395
+ return {
1396
+ ...completion,
1397
+ apply: snippet(template)
1398
+ };
1399
+ }
1400
+ const snippetPointerHandler = /*@__PURE__*/ EditorView.domEventHandlers({ mousedown(event, view) {
1401
+ let active = view.state.field(snippetState, false), pos;
1402
+ if (!active || (pos = view.posAtCoords({
1403
+ x: event.clientX,
1404
+ y: event.clientY
1405
+ })) == null) return false;
1406
+ let match = active.ranges.find((r) => r.from <= pos && r.to >= pos);
1407
+ if (!match || match.field == active.active) return false;
1408
+ view.dispatch({
1409
+ selection: fieldSelection(active.ranges, match.field),
1410
+ effects: setActive.of(active.ranges.some((r) => r.field > match.field) ? new ActiveSnippet(active.ranges, match.field) : null),
1411
+ scrollIntoView: true
1412
+ });
1413
+ return true;
1414
+ } });
1415
+ const defaults = {
1416
+ brackets: [
1417
+ "(",
1418
+ "[",
1419
+ "{",
1420
+ "'",
1421
+ "\""
1422
+ ],
1423
+ before: ")]}:;>",
1424
+ stringPrefixes: []
1425
+ };
1426
+ const closeBracketEffect = /*@__PURE__*/ StateEffect.define({ map(value, mapping) {
1427
+ let mapped = mapping.mapPos(value, -1, MapMode.TrackAfter);
1428
+ return mapped == null ? void 0 : mapped;
1429
+ } });
1430
+ const closedBracket = /*@__PURE__*/ new class extends RangeValue {}();
1431
+ closedBracket.startSide = 1;
1432
+ closedBracket.endSide = -1;
1433
+ const bracketState = /*@__PURE__*/ StateField.define({
1434
+ create() {
1435
+ return RangeSet.empty;
1436
+ },
1437
+ update(value, tr) {
1438
+ value = value.map(tr.changes);
1439
+ if (tr.selection) {
1440
+ let line = tr.state.doc.lineAt(tr.selection.main.head);
1441
+ value = value.update({ filter: (from) => from >= line.from && from <= line.to });
1442
+ }
1443
+ for (let effect of tr.effects) if (effect.is(closeBracketEffect)) value = value.update({ add: [closedBracket.range(effect.value, effect.value + 1)] });
1444
+ return value;
1445
+ }
1446
+ });
1447
+ /**
1448
+ Extension to enable bracket-closing behavior. When a closeable
1449
+ bracket is typed, its closing bracket is immediately inserted
1450
+ after the cursor. When closing a bracket directly in front of a
1451
+ closing bracket inserted by the extension, the cursor moves over
1452
+ that bracket.
1453
+ */
1454
+ function closeBrackets() {
1455
+ return [inputHandler, bracketState];
1456
+ }
1457
+ const definedClosing = "()[]{}<>«»»«[]{}";
1458
+ function closing(ch) {
1459
+ for (let i = 0; i < 16; i += 2) if (definedClosing.charCodeAt(i) == ch) return definedClosing.charAt(i + 1);
1460
+ return fromCodePoint(ch < 128 ? ch : ch + 1);
1461
+ }
1462
+ function config(state, pos) {
1463
+ return state.languageDataAt("closeBrackets", pos)[0] || defaults;
1464
+ }
1465
+ const android = typeof navigator == "object" && /*@__PURE__*/ /Android\b/.test(navigator.userAgent);
1466
+ const inputHandler = /*@__PURE__*/ EditorView.inputHandler.of((view, from, to, insert) => {
1467
+ if ((android ? view.composing : view.compositionStarted) || view.state.readOnly) return false;
1468
+ let sel = view.state.selection.main;
1469
+ if (insert.length > 2 || insert.length == 2 && codePointSize(codePointAt(insert, 0)) == 1 || from != sel.from || to != sel.to) return false;
1470
+ let tr = insertBracket(view.state, insert);
1471
+ if (!tr) return false;
1472
+ view.dispatch(tr);
1473
+ return true;
1474
+ });
1475
+ /**
1476
+ Command that implements deleting a pair of matching brackets when
1477
+ the cursor is between them.
1478
+ */
1479
+ const deleteBracketPair = ({ state, dispatch }) => {
1480
+ if (state.readOnly) return false;
1481
+ let tokens = config(state, state.selection.main.head).brackets || defaults.brackets;
1482
+ let dont = null, changes = state.changeByRange((range) => {
1483
+ if (range.empty) {
1484
+ let before = prevChar(state.doc, range.head);
1485
+ for (let token of tokens) if (token == before && nextChar(state.doc, range.head) == closing(codePointAt(token, 0))) return {
1486
+ changes: {
1487
+ from: range.head - token.length,
1488
+ to: range.head + token.length
1489
+ },
1490
+ range: EditorSelection.cursor(range.head - token.length)
1491
+ };
1492
+ }
1493
+ return { range: dont = range };
1494
+ });
1495
+ if (!dont) dispatch(state.update(changes, {
1496
+ scrollIntoView: true,
1497
+ userEvent: "delete.backward"
1498
+ }));
1499
+ return !dont;
1500
+ };
1501
+ /**
1502
+ Close-brackets related key bindings. Binds Backspace to
1503
+ [`deleteBracketPair`](https://codemirror.net/6/docs/ref/#autocomplete.deleteBracketPair).
1504
+ */
1505
+ const closeBracketsKeymap = [{
1506
+ key: "Backspace",
1507
+ run: deleteBracketPair
1508
+ }];
1509
+ /**
1510
+ Implements the extension's behavior on text insertion. If the
1511
+ given string counts as a bracket in the language around the
1512
+ selection, and replacing the selection with it requires custom
1513
+ behavior (inserting a closing version or skipping past a
1514
+ previously-closed bracket), this function returns a transaction
1515
+ representing that custom behavior. (You only need this if you want
1516
+ to programmatically insert brackets—the
1517
+ [`closeBrackets`](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets) extension will
1518
+ take care of running this for user input.)
1519
+ */
1520
+ function insertBracket(state, bracket) {
1521
+ let conf = config(state, state.selection.main.head);
1522
+ let tokens = conf.brackets || defaults.brackets;
1523
+ for (let tok of tokens) {
1524
+ let closed = closing(codePointAt(tok, 0));
1525
+ if (bracket == tok) return closed == tok ? handleSame(state, tok, tokens.indexOf(tok + tok + tok) > -1, conf) : handleOpen(state, tok, closed, conf.before || defaults.before);
1526
+ if (bracket == closed && closedBracketAt(state, state.selection.main.from)) return handleClose(state, tok, closed);
1527
+ }
1528
+ return null;
1529
+ }
1530
+ function closedBracketAt(state, pos) {
1531
+ let found = false;
1532
+ state.field(bracketState).between(0, state.doc.length, (from) => {
1533
+ if (from == pos) found = true;
1534
+ });
1535
+ return found;
1536
+ }
1537
+ function nextChar(doc, pos) {
1538
+ let next = doc.sliceString(pos, pos + 2);
1539
+ return next.slice(0, codePointSize(codePointAt(next, 0)));
1540
+ }
1541
+ function prevChar(doc, pos) {
1542
+ let prev = doc.sliceString(pos - 2, pos);
1543
+ return codePointSize(codePointAt(prev, 0)) == prev.length ? prev : prev.slice(1);
1544
+ }
1545
+ function handleOpen(state, open, close, closeBefore) {
1546
+ let dont = null, changes = state.changeByRange((range) => {
1547
+ if (!range.empty) return {
1548
+ changes: [{
1549
+ insert: open,
1550
+ from: range.from
1551
+ }, {
1552
+ insert: close,
1553
+ from: range.to
1554
+ }],
1555
+ effects: closeBracketEffect.of(range.to + open.length),
1556
+ range: EditorSelection.range(range.anchor + open.length, range.head + open.length)
1557
+ };
1558
+ let next = nextChar(state.doc, range.head);
1559
+ if (!next || /\s/.test(next) || closeBefore.indexOf(next) > -1) return {
1560
+ changes: {
1561
+ insert: open + close,
1562
+ from: range.head
1563
+ },
1564
+ effects: closeBracketEffect.of(range.head + open.length),
1565
+ range: EditorSelection.cursor(range.head + open.length)
1566
+ };
1567
+ return { range: dont = range };
1568
+ });
1569
+ return dont ? null : state.update(changes, {
1570
+ scrollIntoView: true,
1571
+ userEvent: "input.type"
1572
+ });
1573
+ }
1574
+ function handleClose(state, _open, close) {
1575
+ let dont = null, changes = state.changeByRange((range) => {
1576
+ if (range.empty && nextChar(state.doc, range.head) == close) return {
1577
+ changes: {
1578
+ from: range.head,
1579
+ to: range.head + close.length,
1580
+ insert: close
1581
+ },
1582
+ range: EditorSelection.cursor(range.head + close.length)
1583
+ };
1584
+ return dont = { range };
1585
+ });
1586
+ return dont ? null : state.update(changes, {
1587
+ scrollIntoView: true,
1588
+ userEvent: "input.type"
1589
+ });
1590
+ }
1591
+ function handleSame(state, token, allowTriple, config) {
1592
+ let stringPrefixes = config.stringPrefixes || defaults.stringPrefixes;
1593
+ let dont = null, changes = state.changeByRange((range) => {
1594
+ if (!range.empty) return {
1595
+ changes: [{
1596
+ insert: token,
1597
+ from: range.from
1598
+ }, {
1599
+ insert: token,
1600
+ from: range.to
1601
+ }],
1602
+ effects: closeBracketEffect.of(range.to + token.length),
1603
+ range: EditorSelection.range(range.anchor + token.length, range.head + token.length)
1604
+ };
1605
+ let pos = range.head, next = nextChar(state.doc, pos), start;
1606
+ if (next == token) {
1607
+ if (nodeStart(state, pos)) return {
1608
+ changes: {
1609
+ insert: token + token,
1610
+ from: pos
1611
+ },
1612
+ effects: closeBracketEffect.of(pos + token.length),
1613
+ range: EditorSelection.cursor(pos + token.length)
1614
+ };
1615
+ else if (closedBracketAt(state, pos)) {
1616
+ let content = allowTriple && state.sliceDoc(pos, pos + token.length * 3) == token + token + token ? token + token + token : token;
1617
+ return {
1618
+ changes: {
1619
+ from: pos,
1620
+ to: pos + content.length,
1621
+ insert: content
1622
+ },
1623
+ range: EditorSelection.cursor(pos + content.length)
1624
+ };
1625
+ }
1626
+ } else if (allowTriple && state.sliceDoc(pos - 2 * token.length, pos) == token + token && (start = canStartStringAt(state, pos - 2 * token.length, stringPrefixes)) > -1 && nodeStart(state, start)) return {
1627
+ changes: {
1628
+ insert: token + token + token + token,
1629
+ from: pos
1630
+ },
1631
+ effects: closeBracketEffect.of(pos + token.length),
1632
+ range: EditorSelection.cursor(pos + token.length)
1633
+ };
1634
+ else if (state.charCategorizer(pos)(next) != CharCategory.Word) {
1635
+ if (canStartStringAt(state, pos, stringPrefixes) > -1 && !probablyInString(state, pos, token, stringPrefixes)) return {
1636
+ changes: {
1637
+ insert: token + token,
1638
+ from: pos
1639
+ },
1640
+ effects: closeBracketEffect.of(pos + token.length),
1641
+ range: EditorSelection.cursor(pos + token.length)
1642
+ };
1643
+ }
1644
+ return { range: dont = range };
1645
+ });
1646
+ return dont ? null : state.update(changes, {
1647
+ scrollIntoView: true,
1648
+ userEvent: "input.type"
1649
+ });
1650
+ }
1651
+ function nodeStart(state, pos) {
1652
+ let tree = syntaxTree(state).resolveInner(pos + 1);
1653
+ return tree.parent && tree.from == pos;
1654
+ }
1655
+ function probablyInString(state, pos, quoteToken, prefixes) {
1656
+ let node = syntaxTree(state).resolveInner(pos, -1);
1657
+ let maxPrefix = prefixes.reduce((m, p) => Math.max(m, p.length), 0);
1658
+ for (let i = 0; i < 5; i++) {
1659
+ let start = state.sliceDoc(node.from, Math.min(node.to, node.from + quoteToken.length + maxPrefix));
1660
+ let quotePos = start.indexOf(quoteToken);
1661
+ if (!quotePos || quotePos > -1 && prefixes.indexOf(start.slice(0, quotePos)) > -1) {
1662
+ let first = node.firstChild;
1663
+ while (first && first.from == node.from && first.to - first.from > quoteToken.length + quotePos) {
1664
+ if (state.sliceDoc(first.to - quoteToken.length, first.to) == quoteToken) return false;
1665
+ first = first.firstChild;
1666
+ }
1667
+ return true;
1668
+ }
1669
+ let parent = node.to == pos && node.parent;
1670
+ if (!parent) break;
1671
+ node = parent;
1672
+ }
1673
+ return false;
1674
+ }
1675
+ function canStartStringAt(state, pos, prefixes) {
1676
+ let charCat = state.charCategorizer(pos);
1677
+ if (charCat(state.sliceDoc(pos - 1, pos)) != CharCategory.Word) return pos;
1678
+ for (let prefix of prefixes) {
1679
+ let start = pos - prefix.length;
1680
+ if (state.sliceDoc(start, pos) == prefix && charCat(state.sliceDoc(start - 1, start)) != CharCategory.Word) return start;
1681
+ }
1682
+ return -1;
1683
+ }
1684
+ /**
1685
+ Returns an extension that enables autocompletion.
1686
+ */
1687
+ function autocompletion(config = {}) {
1688
+ return [
1689
+ commitCharacters,
1690
+ completionState,
1691
+ completionConfig.of(config),
1692
+ completionPlugin,
1693
+ completionKeymapExt,
1694
+ baseTheme
1695
+ ];
1696
+ }
1697
+ /**
1698
+ Basic keybindings for autocompletion.
1699
+
1700
+ - Ctrl-Space (and Alt-\` or Alt-i on macOS): [`startCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.startCompletion)
1701
+ - Escape: [`closeCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.closeCompletion)
1702
+ - ArrowDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true)`
1703
+ - ArrowUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false)`
1704
+ - PageDown: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(true, "page")`
1705
+ - PageUp: [`moveCompletionSelection`](https://codemirror.net/6/docs/ref/#autocomplete.moveCompletionSelection)`(false, "page")`
1706
+ - Enter: [`acceptCompletion`](https://codemirror.net/6/docs/ref/#autocomplete.acceptCompletion)
1707
+ */
1708
+ const completionKeymap = [
1709
+ {
1710
+ key: "Ctrl-Space",
1711
+ run: startCompletion
1712
+ },
1713
+ {
1714
+ mac: "Alt-`",
1715
+ run: startCompletion
1716
+ },
1717
+ {
1718
+ mac: "Alt-i",
1719
+ run: startCompletion
1720
+ },
1721
+ {
1722
+ key: "Escape",
1723
+ run: closeCompletion
1724
+ },
1725
+ {
1726
+ key: "ArrowDown",
1727
+ run: /*@__PURE__*/ moveCompletionSelection(true)
1728
+ },
1729
+ {
1730
+ key: "ArrowUp",
1731
+ run: /*@__PURE__*/ moveCompletionSelection(false)
1732
+ },
1733
+ {
1734
+ key: "PageDown",
1735
+ run: /*@__PURE__*/ moveCompletionSelection(true, "page")
1736
+ },
1737
+ {
1738
+ key: "PageUp",
1739
+ run: /*@__PURE__*/ moveCompletionSelection(false, "page")
1740
+ },
1741
+ {
1742
+ key: "Enter",
1743
+ run: acceptCompletion
1744
+ }
1745
+ ];
1746
+ const completionKeymapExt = /*@__PURE__*/ Prec.highest(/*@__PURE__*/ keymap.computeN([completionConfig], (state) => state.facet(completionConfig).defaultKeymap ? [completionKeymap] : []));
1747
+ //#endregion
1748
+ export { autocompletion, closeBrackets, closeBracketsKeymap, completeFromList, completionKeymap, ifNotIn, snippetCompletion };
1749
+
1750
+ //# sourceMappingURL=index.js.map