@codemirror/autocomplete 0.19.14 → 0.20.1
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/CHANGELOG.md +36 -0
- package/dist/index.cjs +355 -64
- package/dist/index.d.ts +98 -16
- package/dist/index.js +333 -48
- package/package.json +5 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _codemirror_state from '@codemirror/state';
|
|
2
|
-
import { EditorState, Transaction, StateCommand, Facet, Extension } from '@codemirror/state';
|
|
2
|
+
import { EditorState, Transaction, StateCommand, Facet, Extension, StateEffect } from '@codemirror/state';
|
|
3
3
|
import { EditorView, KeyBinding, Command } from '@codemirror/view';
|
|
4
4
|
import * as _lezer_common from '@lezer/common';
|
|
5
5
|
|
|
@@ -18,6 +18,11 @@ interface CompletionConfig {
|
|
|
18
18
|
*/
|
|
19
19
|
override?: readonly CompletionSource[] | null;
|
|
20
20
|
/**
|
|
21
|
+
Determines whether the completion tooltip is closed when the
|
|
22
|
+
editor loses focus. Defaults to true.
|
|
23
|
+
*/
|
|
24
|
+
closeOnBlur?: boolean;
|
|
25
|
+
/**
|
|
21
26
|
The maximum number of options to render to the DOM.
|
|
22
27
|
*/
|
|
23
28
|
maxRenderedOptions?: number;
|
|
@@ -52,8 +57,7 @@ interface CompletionConfig {
|
|
|
52
57
|
completion, and should produce a DOM node to show. `position`
|
|
53
58
|
determines where in the DOM the result appears, relative to
|
|
54
59
|
other added widgets and the standard content. The default icons
|
|
55
|
-
have position 20, the label position 50, and the detail position
|
|
56
|
-
70.
|
|
60
|
+
have position 20, the label position 50, and the detail position 70.
|
|
57
61
|
*/
|
|
58
62
|
addToOptions?: {
|
|
59
63
|
render: (completion: Completion, state: EditorState) => Node | null;
|
|
@@ -81,7 +85,7 @@ interface Completion {
|
|
|
81
85
|
a plain string or a function that'll render the DOM structure to
|
|
82
86
|
show when invoked.
|
|
83
87
|
*/
|
|
84
|
-
info?: string | ((completion: Completion) => (Node | Promise<Node>));
|
|
88
|
+
info?: string | ((completion: Completion) => (Node | null | Promise<Node | null>));
|
|
85
89
|
/**
|
|
86
90
|
How to apply the completion. The default is to replace it with
|
|
87
91
|
its [label](https://codemirror.net/6/docs/ref/#autocomplete.Completion.label). When this holds a
|
|
@@ -226,23 +230,40 @@ interface CompletionResult {
|
|
|
226
230
|
*/
|
|
227
231
|
options: readonly Completion[];
|
|
228
232
|
/**
|
|
229
|
-
When given, further
|
|
230
|
-
between ([mapped](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) `from`
|
|
231
|
-
match this regular expression
|
|
232
|
-
source again, but continue with
|
|
233
|
-
help a lot with responsiveness,
|
|
234
|
-
list to be updated synchronously.
|
|
233
|
+
When given, further typing or deletion that causes the part of
|
|
234
|
+
the document between ([mapped](https://codemirror.net/6/docs/ref/#state.ChangeDesc.mapPos)) `from`
|
|
235
|
+
and `to` to match this regular expression or predicate function
|
|
236
|
+
will not query the completion source again, but continue with
|
|
237
|
+
this list of options. This can help a lot with responsiveness,
|
|
238
|
+
since it allows the completion list to be updated synchronously.
|
|
235
239
|
*/
|
|
236
|
-
|
|
240
|
+
validFor?: RegExp | ((text: string, from: number, to: number, state: EditorState) => boolean);
|
|
237
241
|
/**
|
|
238
242
|
By default, the library filters and scores completions. Set
|
|
239
243
|
`filter` to `false` to disable this, and cause your completions
|
|
240
244
|
to all be included, in the order they were given. When there are
|
|
241
245
|
other sources, unfiltered completions appear at the top of the
|
|
242
|
-
list of completions. `
|
|
243
|
-
`false`, because it only works when filtering.
|
|
246
|
+
list of completions. `validFor` must not be given when `filter`
|
|
247
|
+
is `false`, because it only works when filtering.
|
|
244
248
|
*/
|
|
245
249
|
filter?: boolean;
|
|
250
|
+
/**
|
|
251
|
+
When [`filter`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.filter) is set to
|
|
252
|
+
`false`, this may be provided to compute the ranges on the label
|
|
253
|
+
that match the input. Should return an array of numbers where
|
|
254
|
+
each pair of adjacent numbers provide the start and end of a
|
|
255
|
+
range.
|
|
256
|
+
*/
|
|
257
|
+
getMatch?: (completion: Completion) => readonly number[];
|
|
258
|
+
/**
|
|
259
|
+
Synchronously update the completion result after typing or
|
|
260
|
+
deletion. If given, this should not do any expensive work, since
|
|
261
|
+
it will be called during editor state updates. The function
|
|
262
|
+
should make sure (similar to
|
|
263
|
+
[`validFor`](https://codemirror.net/6/docs/ref/#autocomplete.CompletionResult.validFor)) that the
|
|
264
|
+
completion still applies in the new state.
|
|
265
|
+
*/
|
|
266
|
+
update?: (current: CompletionResult, from: number, to: number, context: CompletionContext) => CompletionResult | null;
|
|
246
267
|
}
|
|
247
268
|
/**
|
|
248
269
|
This annotation is added to transactions that are produced by
|
|
@@ -251,8 +272,9 @@ picking a completion.
|
|
|
251
272
|
declare const pickedCompletion: _codemirror_state.AnnotationType<Completion>;
|
|
252
273
|
|
|
253
274
|
/**
|
|
254
|
-
Convert a snippet template to a function that can
|
|
255
|
-
Snippets are written
|
|
275
|
+
Convert a snippet template to a function that can
|
|
276
|
+
[apply](https://codemirror.net/6/docs/ref/#autocomplete.Completion.apply) it. Snippets are written
|
|
277
|
+
using syntax like this:
|
|
256
278
|
|
|
257
279
|
"for (let ${index} = 0; ${index} < ${end}; ${index}++) {\n\t${}\n}"
|
|
258
280
|
|
|
@@ -331,6 +353,56 @@ return those as completions.
|
|
|
331
353
|
*/
|
|
332
354
|
declare const completeAnyWord: CompletionSource;
|
|
333
355
|
|
|
356
|
+
/**
|
|
357
|
+
Configures bracket closing behavior for a syntax (via
|
|
358
|
+
[language data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt)) using the `"closeBrackets"`
|
|
359
|
+
identifier.
|
|
360
|
+
*/
|
|
361
|
+
interface CloseBracketConfig {
|
|
362
|
+
/**
|
|
363
|
+
The opening brackets to close. Defaults to `["(", "[", "{", "'",
|
|
364
|
+
'"']`. Brackets may be single characters or a triple of quotes
|
|
365
|
+
(as in `"''''"`).
|
|
366
|
+
*/
|
|
367
|
+
brackets?: string[];
|
|
368
|
+
/**
|
|
369
|
+
Characters in front of which newly opened brackets are
|
|
370
|
+
automatically closed. Closing always happens in front of
|
|
371
|
+
whitespace. Defaults to `")]}:;>"`.
|
|
372
|
+
*/
|
|
373
|
+
before?: string;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
Extension to enable bracket-closing behavior. When a closeable
|
|
377
|
+
bracket is typed, its closing bracket is immediately inserted
|
|
378
|
+
after the cursor. When closing a bracket directly in front of a
|
|
379
|
+
closing bracket inserted by the extension, the cursor moves over
|
|
380
|
+
that bracket.
|
|
381
|
+
*/
|
|
382
|
+
declare function closeBrackets(): Extension;
|
|
383
|
+
/**
|
|
384
|
+
Command that implements deleting a pair of matching brackets when
|
|
385
|
+
the cursor is between them.
|
|
386
|
+
*/
|
|
387
|
+
declare const deleteBracketPair: StateCommand;
|
|
388
|
+
/**
|
|
389
|
+
Close-brackets related key bindings. Binds Backspace to
|
|
390
|
+
[`deleteBracketPair`](https://codemirror.net/6/docs/ref/#autocomplete.deleteBracketPair).
|
|
391
|
+
*/
|
|
392
|
+
declare const closeBracketsKeymap: readonly KeyBinding[];
|
|
393
|
+
/**
|
|
394
|
+
Implements the extension's behavior on text insertion. If the
|
|
395
|
+
given string counts as a bracket in the language around the
|
|
396
|
+
selection, and replacing the selection with it requires custom
|
|
397
|
+
behavior (inserting a closing version or skipping past a
|
|
398
|
+
previously-closed bracket), this function returns a transaction
|
|
399
|
+
representing that custom behavior. (You only need this if you want
|
|
400
|
+
to programmatically insert brackets—the
|
|
401
|
+
[`closeBrackets`](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets) extension will
|
|
402
|
+
take care of running this for user input.)
|
|
403
|
+
*/
|
|
404
|
+
declare function insertBracket(state: EditorState, bracket: string): Transaction | null;
|
|
405
|
+
|
|
334
406
|
/**
|
|
335
407
|
Returns an extension that enables autocompletion.
|
|
336
408
|
*/
|
|
@@ -362,5 +434,15 @@ declare function currentCompletions(state: EditorState): readonly Completion[];
|
|
|
362
434
|
Return the currently selected completion, if any.
|
|
363
435
|
*/
|
|
364
436
|
declare function selectedCompletion(state: EditorState): Completion | null;
|
|
437
|
+
/**
|
|
438
|
+
Returns the currently selected position in the active completion
|
|
439
|
+
list, or null if no completions are active.
|
|
440
|
+
*/
|
|
441
|
+
declare function selectedCompletionIndex(state: EditorState): number | null;
|
|
442
|
+
/**
|
|
443
|
+
Create an effect that can be attached to a transaction to change
|
|
444
|
+
the currently selected completion.
|
|
445
|
+
*/
|
|
446
|
+
declare function setSelectedCompletion(index: number): StateEffect<unknown>;
|
|
365
447
|
|
|
366
|
-
export { Completion, CompletionContext, CompletionResult, CompletionSource, acceptCompletion, autocompletion, clearSnippet, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, ifIn, ifNotIn, moveCompletionSelection, nextSnippetField, pickedCompletion, prevSnippetField, selectedCompletion, snippet, snippetCompletion, snippetKeymap, startCompletion };
|
|
448
|
+
export { CloseBracketConfig, Completion, CompletionContext, CompletionResult, CompletionSource, acceptCompletion, autocompletion, clearSnippet, closeBrackets, closeBracketsKeymap, closeCompletion, completeAnyWord, completeFromList, completionKeymap, completionStatus, currentCompletions, deleteBracketPair, ifIn, ifNotIn, insertBracket, moveCompletionSelection, nextSnippetField, pickedCompletion, prevSnippetField, selectedCompletion, selectedCompletionIndex, setSelectedCompletion, snippet, snippetCompletion, snippetKeymap, startCompletion };
|