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