@nibling/editor 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +53 -2
- package/dist/commands/autoclose.d.ts +13 -0
- package/dist/commands/autoclose.js +78 -0
- package/dist/commands/commands.d.ts +104 -0
- package/dist/commands/commands.js +442 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.js +9 -0
- package/dist/commands/fold.d.ts +18 -0
- package/dist/commands/fold.js +75 -0
- package/dist/commands/keymap.d.ts +40 -0
- package/dist/commands/keymap.js +118 -0
- package/dist/complete/autocomplete.d.ts +35 -0
- package/dist/complete/autocomplete.js +386 -0
- package/dist/complete/source.d.ts +72 -0
- package/dist/complete/source.js +52 -0
- package/dist/complete/words.d.ts +53 -0
- package/dist/complete/words.js +203 -0
- package/dist/element.d.ts +119 -0
- package/dist/element.js +1011 -0
- package/dist/expand/expansions.d.ts +68 -0
- package/dist/expand/expansions.js +143 -0
- package/dist/expand/projection.d.ts +73 -0
- package/dist/expand/projection.js +189 -0
- package/dist/expand/resolver.d.ts +42 -0
- package/dist/expand/resolver.js +585 -0
- package/dist/expand/slice-tokens.d.ts +25 -0
- package/dist/expand/slice-tokens.js +79 -0
- package/dist/extension.d.ts +58 -0
- package/dist/extension.js +1 -0
- package/dist/find/find.d.ts +12 -0
- package/dist/find/find.js +469 -0
- package/dist/find/search.d.ts +81 -0
- package/dist/find/search.js +308 -0
- package/dist/headless.d.ts +16 -0
- package/dist/headless.js +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/inline-expansion.d.ts +89 -0
- package/dist/inline-expansion.js +324 -0
- package/dist/input/edit-context.d.ts +23 -0
- package/dist/input/edit-context.js +102 -0
- package/dist/input/surface.d.ts +101 -0
- package/dist/input/surface.js +84 -0
- package/dist/input/textarea.d.ts +26 -0
- package/dist/input/textarea.js +125 -0
- package/dist/sheet.d.ts +6 -0
- package/dist/sheet.js +12 -0
- package/dist/state/core.d.ts +73 -0
- package/dist/state/core.js +86 -0
- package/dist/state/fold-ranges.d.ts +41 -0
- package/dist/state/fold-ranges.js +167 -0
- package/dist/state/folds.d.ts +45 -0
- package/dist/state/folds.js +240 -0
- package/dist/state/history.d.ts +25 -0
- package/dist/state/history.js +127 -0
- package/dist/state/indent.d.ts +33 -0
- package/dist/state/indent.js +121 -0
- package/dist/state/selection.d.ts +45 -0
- package/dist/state/selection.js +106 -0
- package/dist/state/whitespace.d.ts +16 -0
- package/dist/state/whitespace.js +54 -0
- package/dist/text/changeset.d.ts +56 -0
- package/dist/text/changeset.js +321 -0
- package/dist/text/text.d.ts +30 -0
- package/dist/text/text.js +321 -0
- package/dist/tokens/bridge.d.ts +107 -0
- package/dist/tokens/bridge.js +461 -0
- package/dist/tokens/engine.d.ts +39 -0
- package/dist/tokens/engine.js +360 -0
- package/dist/tokens/protocol.d.ts +113 -0
- package/dist/tokens/protocol.js +38 -0
- package/dist/tokens/textmate/ascii-regex.d.ts +5 -0
- package/dist/tokens/textmate/ascii-regex.js +156 -0
- package/dist/tokens/textmate/index.d.ts +7 -0
- package/dist/tokens/textmate/index.js +19 -0
- package/dist/tokens/textmate/linker.d.ts +67 -0
- package/dist/tokens/textmate/linker.js +238 -0
- package/dist/tokens/textmate/scopes.d.ts +14 -0
- package/dist/tokens/textmate/scopes.js +54 -0
- package/dist/tokens/textmate/theme.d.ts +54 -0
- package/dist/tokens/textmate/theme.js +138 -0
- package/dist/tokens/textmate/tokenizer.d.ts +29 -0
- package/dist/tokens/textmate/tokenizer.js +684 -0
- package/dist/tokens/textmate.d.ts +49 -0
- package/dist/tokens/textmate.js +4 -0
- package/dist/view/decorations.d.ts +183 -0
- package/dist/view/decorations.js +51 -0
- package/dist/view/guides.d.ts +58 -0
- package/dist/view/guides.js +174 -0
- package/dist/view/heightmap.d.ts +97 -0
- package/dist/view/heightmap.js +229 -0
- package/dist/view/line-dom.d.ts +54 -0
- package/dist/view/line-dom.js +168 -0
- package/dist/view/measure.d.ts +37 -0
- package/dist/view/measure.js +136 -0
- package/dist/view/overlays.d.ts +32 -0
- package/dist/view/overlays.js +135 -0
- package/dist/view/rail.d.ts +27 -0
- package/dist/view/rail.js +232 -0
- package/dist/view/remote.d.ts +24 -0
- package/dist/view/remote.js +143 -0
- package/dist/view/scope-focus.d.ts +27 -0
- package/dist/view/scope-focus.js +255 -0
- package/dist/view/view.d.ts +114 -0
- package/dist/view/view.js +1231 -0
- package/dist/vite.d.ts +12 -0
- package/dist/vite.js +64 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +64 -0
- package/grammars/astro.mjs +2 -0
- package/grammars/chunks/r-90cb351dba.mjs +1 -0
- package/grammars/chunks/r-b92a500aab.mjs +1 -0
- package/grammars/chunks/r-ced5311992.mjs +1 -0
- package/grammars/chunks/r-ebae91d4ec.mjs +1 -0
- package/grammars/chunks/s-1821e66170.mjs +1 -0
- package/grammars/css.mjs +1 -0
- package/grammars/diff.mjs +1 -0
- package/grammars/docker.mjs +1 -0
- package/grammars/dotenv.mjs +1 -0
- package/grammars/graphql.mjs +1 -0
- package/grammars/html.mjs +2 -0
- package/grammars/ini.mjs +1 -0
- package/grammars/javascript.mjs +5 -0
- package/grammars/json.mjs +1 -0
- package/grammars/json5.mjs +1 -0
- package/grammars/jsonc.mjs +1 -0
- package/grammars/less.mjs +1 -0
- package/grammars/manifest.json +58 -0
- package/grammars/markdown.mjs +1 -0
- package/grammars/mdx.mjs +1 -0
- package/grammars/pug.mjs +1 -0
- package/grammars/scss.mjs +1 -0
- package/grammars/shellscript.mjs +1 -0
- package/grammars/sql.mjs +1 -0
- package/grammars/stylus.mjs +1 -0
- package/grammars/svelte.mjs +1 -0
- package/grammars/toml.mjs +1 -0
- package/grammars/tsx.mjs +5 -0
- package/grammars/typescript.mjs +2 -0
- package/grammars/vue.mjs +1 -0
- package/grammars/yaml.mjs +1 -0
- package/package.json +71 -3
- package/themes/dark-plus.json +1 -0
- package/themes/light-plus.json +1 -0
- package/themes/monokai.json +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Text } from '../text/text.ts';
|
|
2
|
+
import type { ChangeSet } from '../text/changeset.ts';
|
|
3
|
+
import type { CompletionContext, CompletionResult, CompletionSource } from './source.ts';
|
|
4
|
+
/** Words shorter than this are never suggested, and longer ones (hashes, base64) never indexed. */
|
|
5
|
+
export declare const MIN_WORD = 2;
|
|
6
|
+
export declare const MAX_WORD = 64;
|
|
7
|
+
export declare function endsWithWordChar(s: string): boolean;
|
|
8
|
+
/** The word that ends at `pos`, within its line, or null when `pos` follows no word (or a number). */
|
|
9
|
+
export declare function wordBefore(text: Text, pos: number): {
|
|
10
|
+
from: number;
|
|
11
|
+
text: string;
|
|
12
|
+
} | null;
|
|
13
|
+
/** The word characters right after `pos`, within its line. */
|
|
14
|
+
export declare function wordCharsAfter(text: Text, pos: number): string;
|
|
15
|
+
/**
|
|
16
|
+
* Every word in the document with its count, built in slices (`scan`) and kept current per edit
|
|
17
|
+
* (`apply`), so a query never scans the document. Lines 1..scanned are indexed; an edit at or
|
|
18
|
+
* below that line costs the touched lines only, and an edit past it costs nothing.
|
|
19
|
+
*/
|
|
20
|
+
export declare class WordIndex {
|
|
21
|
+
#private;
|
|
22
|
+
/** Whether every line of the document is indexed. */
|
|
23
|
+
get complete(): boolean;
|
|
24
|
+
get size(): number;
|
|
25
|
+
/** Index up to `maxLines` more lines of `text`, the current document. True when done. */
|
|
26
|
+
scan(text: Text, maxLines: number): boolean;
|
|
27
|
+
clear(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Follow one edit. Each change's lines leave the index as they were and come back as they are;
|
|
30
|
+
* an edit straddling the scanned edge drops its old lines and moves the edge back to them. An
|
|
31
|
+
* edit over more than `bulkLines` lines (select all and delete, a huge paste) clears the index
|
|
32
|
+
* instead, to be rebuilt in slices, so no single edit pays for the whole document.
|
|
33
|
+
*/
|
|
34
|
+
apply(changes: ChangeSet, before: Text, after: Text, bulkLines?: number): void;
|
|
35
|
+
count(word: string): number;
|
|
36
|
+
/** Indexed words longer than `prefix` that start with it, ignoring case. Unordered. */
|
|
37
|
+
matching(prefix: string): Iterable<string>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Words within `radius` characters of `pos` (snapped out to whole lines) that start with `prefix`
|
|
41
|
+
* ignoring case, each with its distance from `pos`. The occurrence starting at `skip` (the word
|
|
42
|
+
* being typed) doesn't count.
|
|
43
|
+
*/
|
|
44
|
+
export declare function nearbyWords(text: Text, pos: number, prefix: string, skip: number, radius?: number): Map<string, number>;
|
|
45
|
+
/**
|
|
46
|
+
* Pure. Document words for the word before the caret: those near the caret first, nearest first,
|
|
47
|
+
* then the rest of the index by how often they occur. Capped at `limit`. Marked incomplete when
|
|
48
|
+
* capped or while the index is still building, so the next keystroke asks again rather than
|
|
49
|
+
* filtering a list that is missing words.
|
|
50
|
+
*/
|
|
51
|
+
export declare function completeWords(ctx: Pick<CompletionContext, 'state' | 'pos' | 'word'>, index: WordIndex | null, limit?: number): CompletionResult | null;
|
|
52
|
+
/** A source over `completeWords`, as a fallback to any richer source. */
|
|
53
|
+
export declare function wordSource(index: () => WordIndex | null): CompletionSource;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Document words for completion. The same word characters as word motion (commands.ts), but a
|
|
2
|
+
// word starts with a letter or underscore: "404" or "2px" is not worth suggesting.
|
|
3
|
+
const WORD_RUN_END = /[\p{L}\p{N}\p{M}_]+$/u;
|
|
4
|
+
const WORD_RUN_START = /^[\p{L}\p{N}\p{M}_]*/u;
|
|
5
|
+
const WORD_START = /^[\p{L}_]/u;
|
|
6
|
+
const LAST_WORD_CHAR = /[\p{L}\p{N}\p{M}_]$/u;
|
|
7
|
+
/** A whole word in a line: not preceded by a word character, so "x2y" never yields "y". */
|
|
8
|
+
const WORDS = /(?<![\p{L}\p{N}\p{M}_])[\p{L}_][\p{L}\p{N}\p{M}_]*/gu;
|
|
9
|
+
/** Words shorter than this are never suggested, and longer ones (hashes, base64) never indexed. */
|
|
10
|
+
export const MIN_WORD = 2;
|
|
11
|
+
export const MAX_WORD = 64;
|
|
12
|
+
export function endsWithWordChar(s) {
|
|
13
|
+
return LAST_WORD_CHAR.test(s);
|
|
14
|
+
}
|
|
15
|
+
/** The word that ends at `pos`, within its line, or null when `pos` follows no word (or a number). */
|
|
16
|
+
export function wordBefore(text, pos) {
|
|
17
|
+
const line = text.lineAt(pos);
|
|
18
|
+
const start = Math.max(line.from, pos - MAX_WORD);
|
|
19
|
+
const m = WORD_RUN_END.exec(text.slice(start, pos));
|
|
20
|
+
if (!m || !WORD_START.test(m[0]))
|
|
21
|
+
return null;
|
|
22
|
+
return { from: pos - m[0].length, text: m[0] };
|
|
23
|
+
}
|
|
24
|
+
/** The word characters right after `pos`, within its line. */
|
|
25
|
+
export function wordCharsAfter(text, pos) {
|
|
26
|
+
const line = text.lineAt(pos);
|
|
27
|
+
return WORD_RUN_START.exec(text.slice(pos, Math.min(line.to, pos + MAX_WORD)))[0];
|
|
28
|
+
}
|
|
29
|
+
function eachWord(s, f) {
|
|
30
|
+
WORDS.lastIndex = 0;
|
|
31
|
+
for (let m = WORDS.exec(s); m; m = WORDS.exec(s))
|
|
32
|
+
if (m[0].length >= MIN_WORD && m[0].length <= MAX_WORD)
|
|
33
|
+
f(m[0], m.index);
|
|
34
|
+
}
|
|
35
|
+
/** Bucket key: the first code point, lowercased, so a prefix lookup reads one bucket. */
|
|
36
|
+
const bucketOf = (word) => String.fromCodePoint(word.codePointAt(0)).toLowerCase();
|
|
37
|
+
/**
|
|
38
|
+
* Every word in the document with its count, built in slices (`scan`) and kept current per edit
|
|
39
|
+
* (`apply`), so a query never scans the document. Lines 1..scanned are indexed; an edit at or
|
|
40
|
+
* below that line costs the touched lines only, and an edit past it costs nothing.
|
|
41
|
+
*/
|
|
42
|
+
export class WordIndex {
|
|
43
|
+
#counts = new Map();
|
|
44
|
+
#buckets = new Map();
|
|
45
|
+
#scanned = 0;
|
|
46
|
+
#lines = 0;
|
|
47
|
+
/** Whether every line of the document is indexed. */
|
|
48
|
+
get complete() {
|
|
49
|
+
return this.#scanned >= this.#lines && this.#lines > 0;
|
|
50
|
+
}
|
|
51
|
+
get size() {
|
|
52
|
+
return this.#counts.size;
|
|
53
|
+
}
|
|
54
|
+
/** Index up to `maxLines` more lines of `text`, the current document. True when done. */
|
|
55
|
+
scan(text, maxLines) {
|
|
56
|
+
this.#lines = text.lines;
|
|
57
|
+
const end = Math.min(text.lines, this.#scanned + maxLines);
|
|
58
|
+
if (end > this.#scanned) {
|
|
59
|
+
const from = text.line(this.#scanned + 1).from;
|
|
60
|
+
this.#add(text.slice(from, text.line(end).to));
|
|
61
|
+
this.#scanned = end;
|
|
62
|
+
}
|
|
63
|
+
return this.complete;
|
|
64
|
+
}
|
|
65
|
+
clear() {
|
|
66
|
+
this.#counts.clear();
|
|
67
|
+
this.#buckets.clear();
|
|
68
|
+
this.#scanned = 0;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Follow one edit. Each change's lines leave the index as they were and come back as they are;
|
|
72
|
+
* an edit straddling the scanned edge drops its old lines and moves the edge back to them. An
|
|
73
|
+
* edit over more than `bulkLines` lines (select all and delete, a huge paste) clears the index
|
|
74
|
+
* instead, to be rebuilt in slices, so no single edit pays for the whole document.
|
|
75
|
+
*/
|
|
76
|
+
apply(changes, before, after, bulkLines = 5000) {
|
|
77
|
+
this.#lines = after.lines;
|
|
78
|
+
if (this.#scanned === 0)
|
|
79
|
+
return;
|
|
80
|
+
// Line spans of each change, merged where they share a line: [a0, a1] before, [b0, b1] after.
|
|
81
|
+
const spans = [];
|
|
82
|
+
changes.iterChanges((fromA, toA, fromB, toB) => {
|
|
83
|
+
const a0 = before.lineAt(fromA).number;
|
|
84
|
+
const a1 = before.lineAt(toA).number;
|
|
85
|
+
const b0 = after.lineAt(fromB).number;
|
|
86
|
+
const b1 = after.lineAt(toB).number;
|
|
87
|
+
const last = spans[spans.length - 1];
|
|
88
|
+
if (last && a0 <= last[1]) {
|
|
89
|
+
last[1] = a1;
|
|
90
|
+
last[3] = b1;
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
spans.push([a0, a1, b0, b1]);
|
|
94
|
+
});
|
|
95
|
+
let delta = 0;
|
|
96
|
+
for (const [a0, a1, b0, b1] of spans) {
|
|
97
|
+
if (a0 > this.#scanned)
|
|
98
|
+
break;
|
|
99
|
+
if (Math.min(a1, this.#scanned) - a0 > bulkLines || b1 - b0 > bulkLines)
|
|
100
|
+
return this.clear();
|
|
101
|
+
if (a1 > this.#scanned) {
|
|
102
|
+
this.#remove(before.slice(before.line(a0).from, before.line(this.#scanned).to));
|
|
103
|
+
this.#scanned = b0 - 1;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.#remove(before.slice(before.line(a0).from, before.line(a1).to));
|
|
107
|
+
this.#add(after.slice(after.line(b0).from, after.line(b1).to));
|
|
108
|
+
delta += b1 - b0 - (a1 - a0);
|
|
109
|
+
}
|
|
110
|
+
this.#scanned += delta;
|
|
111
|
+
}
|
|
112
|
+
count(word) {
|
|
113
|
+
return this.#counts.get(word) ?? 0;
|
|
114
|
+
}
|
|
115
|
+
/** Indexed words longer than `prefix` that start with it, ignoring case. Unordered. */
|
|
116
|
+
*matching(prefix) {
|
|
117
|
+
if (!prefix)
|
|
118
|
+
return;
|
|
119
|
+
const bucket = this.#buckets.get(bucketOf(prefix));
|
|
120
|
+
if (!bucket)
|
|
121
|
+
return;
|
|
122
|
+
const lower = prefix.toLowerCase();
|
|
123
|
+
for (const w of bucket)
|
|
124
|
+
if (w.length > prefix.length && w.slice(0, prefix.length).toLowerCase() === lower)
|
|
125
|
+
yield w;
|
|
126
|
+
}
|
|
127
|
+
#add(s) {
|
|
128
|
+
eachWord(s, (w) => {
|
|
129
|
+
const n = this.#counts.get(w) ?? 0;
|
|
130
|
+
this.#counts.set(w, n + 1);
|
|
131
|
+
if (n > 0)
|
|
132
|
+
return;
|
|
133
|
+
const key = bucketOf(w);
|
|
134
|
+
let b = this.#buckets.get(key);
|
|
135
|
+
if (!b)
|
|
136
|
+
this.#buckets.set(key, (b = new Set()));
|
|
137
|
+
b.add(w);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
#remove(s) {
|
|
141
|
+
eachWord(s, (w) => {
|
|
142
|
+
const n = this.#counts.get(w) ?? 0;
|
|
143
|
+
if (n > 1)
|
|
144
|
+
return void this.#counts.set(w, n - 1);
|
|
145
|
+
this.#counts.delete(w);
|
|
146
|
+
this.#buckets.get(bucketOf(w))?.delete(w);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Words within `radius` characters of `pos` (snapped out to whole lines) that start with `prefix`
|
|
152
|
+
* ignoring case, each with its distance from `pos`. The occurrence starting at `skip` (the word
|
|
153
|
+
* being typed) doesn't count.
|
|
154
|
+
*/
|
|
155
|
+
export function nearbyWords(text, pos, prefix, skip, radius = 20_000) {
|
|
156
|
+
const from = text.lineAt(Math.max(0, pos - radius)).from;
|
|
157
|
+
const to = text.lineAt(Math.min(text.length, pos + radius)).to;
|
|
158
|
+
const s = text.slice(from, to);
|
|
159
|
+
const lower = prefix.toLowerCase();
|
|
160
|
+
const near = new Map();
|
|
161
|
+
eachWord(s, (w, i) => {
|
|
162
|
+
const at = from + i;
|
|
163
|
+
if (at === skip || w.length <= prefix.length || w.slice(0, prefix.length).toLowerCase() !== lower)
|
|
164
|
+
return;
|
|
165
|
+
const d = Math.abs(at - pos);
|
|
166
|
+
const prev = near.get(w);
|
|
167
|
+
if (prev === undefined || d < prev)
|
|
168
|
+
near.set(w, d);
|
|
169
|
+
});
|
|
170
|
+
return near;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Pure. Document words for the word before the caret: those near the caret first, nearest first,
|
|
174
|
+
* then the rest of the index by how often they occur. Capped at `limit`. Marked incomplete when
|
|
175
|
+
* capped or while the index is still building, so the next keystroke asks again rather than
|
|
176
|
+
* filtering a list that is missing words.
|
|
177
|
+
*/
|
|
178
|
+
export function completeWords(ctx, index, limit = 200) {
|
|
179
|
+
const word = ctx.word;
|
|
180
|
+
if (!word)
|
|
181
|
+
return null;
|
|
182
|
+
const { text } = ctx.state;
|
|
183
|
+
// The word under the caret, whole: it occurs once (here) unless it's also elsewhere.
|
|
184
|
+
const current = word.text + wordCharsAfter(text, ctx.pos);
|
|
185
|
+
const near = nearbyWords(text, ctx.pos, word.text, word.from);
|
|
186
|
+
const ranked = [...near].sort((a, b) => a[1] - b[1] || (a[0] < b[0] ? -1 : 1)).map(([w]) => w);
|
|
187
|
+
let rest = [];
|
|
188
|
+
if (index) {
|
|
189
|
+
for (const w of index.matching(word.text))
|
|
190
|
+
if (!near.has(w) && (w !== current || index.count(w) > 1))
|
|
191
|
+
rest.push(w);
|
|
192
|
+
rest.sort((a, b) => index.count(b) - index.count(a) || (a < b ? -1 : 1));
|
|
193
|
+
}
|
|
194
|
+
const all = ranked.concat(rest);
|
|
195
|
+
if (all.length === 0)
|
|
196
|
+
return null;
|
|
197
|
+
const items = all.slice(0, limit).map((label) => ({ label }));
|
|
198
|
+
return { from: word.from, items, incomplete: all.length > limit || (index !== null && !index.complete) };
|
|
199
|
+
}
|
|
200
|
+
/** A source over `completeWords`, as a fallback to any richer source. */
|
|
201
|
+
export function wordSource(index) {
|
|
202
|
+
return { fallback: true, complete: (ctx) => completeWords(ctx, index()) };
|
|
203
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type Snapshot, type TransactionSpec, type Update } from './state/core.ts';
|
|
2
|
+
import { type Command } from './commands/commands.ts';
|
|
3
|
+
import { FoldState } from './state/folds.ts';
|
|
4
|
+
import { type WorkerLike } from './tokens/bridge.ts';
|
|
5
|
+
import { type CompiledTheme, type GrammarManifest, type ThemePair } from './tokens/protocol.ts';
|
|
6
|
+
import { type WhitespaceMode } from './state/whitespace.ts';
|
|
7
|
+
import type { Extension } from './extension.ts';
|
|
8
|
+
import { InlineExpansions } from './expand/expansions.ts';
|
|
9
|
+
/** `change` event detail. The Update itself: domain types only (Text, ChangeSet, Selection). */
|
|
10
|
+
export type EditorChangeEvent = CustomEvent<Update>;
|
|
11
|
+
/**
|
|
12
|
+
* Process-wide defaults the host sets once, before or after elements exist. Per-element
|
|
13
|
+
* properties override them. `input` is read when an element first connects.
|
|
14
|
+
*/
|
|
15
|
+
export declare const editorDefaults: {
|
|
16
|
+
grammars: GrammarManifest | null;
|
|
17
|
+
theme: CompiledTheme | null;
|
|
18
|
+
/** A light and a dark theme (Light+ and Dark+). Syntax and chrome colors become
|
|
19
|
+
* `light-dark(light, dark)`, so the editor follows the `color-scheme` it inherits. Wins over
|
|
20
|
+
* `theme` at the same level (defaults here, or an element's own properties). */
|
|
21
|
+
themes: ThemePair | null;
|
|
22
|
+
/** 'textarea' is the default: EditContext exposes no value to screen readers (D2). 'auto' keeps
|
|
23
|
+
* feature detection (EditContext where present), and 'editcontext' forces it where available. */
|
|
24
|
+
input: 'textarea' | 'editcontext' | 'auto';
|
|
25
|
+
/** Which modifier adds a cursor on click, as VS Code's editor.multiCursorModifier: 'mod' is Cmd
|
|
26
|
+
* on Apple platforms and Ctrl elsewhere ('ctrlCmd' there), 'alt' is Option or Alt. */
|
|
27
|
+
multiCursorModifier: 'mod' | 'alt';
|
|
28
|
+
/** Typing within this many ms of the previous keystroke joins its undo step. Read when an
|
|
29
|
+
* element is created. */
|
|
30
|
+
undoGroupDelay: number;
|
|
31
|
+
/** How long a newly opened document's text may stay hidden while its first syntax colors are
|
|
32
|
+
* computed, so it doesn't flash plain. 0 shows plain text at once. */
|
|
33
|
+
highlightHold: number;
|
|
34
|
+
/** Draw indent guides. Elements without an `indent-guides` attribute follow it. */
|
|
35
|
+
indentGuides: boolean;
|
|
36
|
+
/** Which whitespace to mark, as VS Code's editor.renderWhitespace. 'selection' (the default)
|
|
37
|
+
* marks whitespace only inside a selection. Elements without a `whitespace` attribute follow it. */
|
|
38
|
+
whitespace: WhitespaceMode;
|
|
39
|
+
/** Inline expansion (a prototype, off by default): Mod-Alt-Enter or Alt-click on a call opens
|
|
40
|
+
* its definition below the line as an editor of its own. Elements without an
|
|
41
|
+
* `inline-expansion` attribute follow it. Read when an element renders. */
|
|
42
|
+
inlineExpansion: boolean;
|
|
43
|
+
/** The completion popup over document words and any registered CompletionSource
|
|
44
|
+
* (`EditorContext.completions`). Read when an element connects. */
|
|
45
|
+
autocomplete: boolean;
|
|
46
|
+
worker: () => WorkerLike;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* `<nib-editor>`. The shell that wires the followers to one EditorCore; it holds no editing logic
|
|
50
|
+
* of its own beyond routing SurfaceEvents to commands.
|
|
51
|
+
*
|
|
52
|
+
* Followers, in listen order: History, TokenBridge, EditorView, then the element (surface sync,
|
|
53
|
+
* `change` and `selectionchange` events) and extensions. Each keeps its own state, and the view
|
|
54
|
+
* only reads others' state inside its rAF frame.
|
|
55
|
+
*
|
|
56
|
+
* Core, History, and Keymap live as long as the element, so moving it in the DOM keeps undo.
|
|
57
|
+
* Everything else lives for one connection. The tokenizer and view are rebuilt when grammars or a
|
|
58
|
+
* theme first become available, since the worker needs both to open the document.
|
|
59
|
+
*
|
|
60
|
+
* Attributes: `language`, `indent-guides` ("false" turns guides off), and `whitespace` (a
|
|
61
|
+
* WhitespaceMode), all reflected; `aria-label` (forwarded to the textarea when there is one).
|
|
62
|
+
* Properties: value, state, language, indentGuides, whitespace, theme, themes, grammars. Events: `change` (EditorChangeEvent, for
|
|
63
|
+
* docChanged updates), `selectionchange` (for selection changes).
|
|
64
|
+
*/
|
|
65
|
+
export declare class NibEditor extends HTMLElement {
|
|
66
|
+
#private;
|
|
67
|
+
static observedAttributes: string[];
|
|
68
|
+
constructor();
|
|
69
|
+
/** The whole document as a string. O(n); prefer `state.text` for repeated reads. */
|
|
70
|
+
get value(): string;
|
|
71
|
+
/** Replaces the document, puts a cursor at 0, clears undo. Works before connection. */
|
|
72
|
+
set value(v: string);
|
|
73
|
+
get state(): Snapshot;
|
|
74
|
+
/** Open inline expansions (see `inlineExpansion`). */
|
|
75
|
+
get expansions(): InlineExpansions;
|
|
76
|
+
/** Whether Mod-Alt-Enter and Alt-click expand definitions inline. Reflects `inline-expansion`;
|
|
77
|
+
* without it, editorDefaults. A prototype; off by default. */
|
|
78
|
+
get inlineExpansion(): boolean;
|
|
79
|
+
set inlineExpansion(v: boolean);
|
|
80
|
+
/** Which regions are folded. Folds live as long as the element and map through every edit. */
|
|
81
|
+
get folds(): FoldState;
|
|
82
|
+
get language(): string;
|
|
83
|
+
set language(v: string);
|
|
84
|
+
/** Whether indent guides are drawn. Reflects `indent-guides`; without it, editorDefaults. */
|
|
85
|
+
get indentGuides(): boolean;
|
|
86
|
+
set indentGuides(v: boolean);
|
|
87
|
+
/** Which whitespace is marked. Reflects `whitespace`; without a valid one, editorDefaults. */
|
|
88
|
+
get whitespace(): WhitespaceMode;
|
|
89
|
+
set whitespace(v: WhitespaceMode);
|
|
90
|
+
get theme(): CompiledTheme | null;
|
|
91
|
+
set theme(v: CompiledTheme | null);
|
|
92
|
+
/** A light and a dark theme, followed through the inherited `color-scheme` with no retokenize
|
|
93
|
+
* (see editorDefaults.themes). Wins over `theme`; either one set here wins over the defaults. */
|
|
94
|
+
get themes(): ThemePair | null;
|
|
95
|
+
set themes(v: ThemePair | null);
|
|
96
|
+
get grammars(): GrammarManifest | null;
|
|
97
|
+
set grammars(v: GrammarManifest | null);
|
|
98
|
+
/** Runs a command (from `commands`) as its key binding would. False when it declined. */
|
|
99
|
+
run(command: Command): boolean;
|
|
100
|
+
/** Scrolls `pos` into view without moving the selection, as following a collaborator does. */
|
|
101
|
+
revealPos(pos: number): void;
|
|
102
|
+
/** Undo, through whichever undo owns this editor (History, or an extension's). */
|
|
103
|
+
undo(): boolean;
|
|
104
|
+
redo(): boolean;
|
|
105
|
+
/** Programmatic edit. Origin defaults to 'host.apply' (its own undo step). */
|
|
106
|
+
apply(spec: Omit<TransactionSpec, 'origin'> & {
|
|
107
|
+
origin?: TransactionSpec['origin'];
|
|
108
|
+
}): Update | null;
|
|
109
|
+
/** Install an extension. Resolves to its disposer once its setup has run. Extensions used
|
|
110
|
+
* before connect wait for it; disconnecting removes them. */
|
|
111
|
+
use(extension: Extension): Promise<() => void>;
|
|
112
|
+
connectedCallback(): void;
|
|
113
|
+
disconnectedCallback(): void;
|
|
114
|
+
attributeChangedCallback(name: string): void;
|
|
115
|
+
/** Overrides editorDefaults.multiCursorModifier for this editor. */
|
|
116
|
+
multiCursorModifier: 'mod' | 'alt' | undefined;
|
|
117
|
+
}
|
|
118
|
+
/** Idempotent: defining twice is a no-op, so two bundles importing the entry do not throw. */
|
|
119
|
+
export declare function defineEditor(tag?: string): void;
|