@aardarch/aardink-web 0.6.3 → 0.7.0
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/README.md +35 -4
- package/index.d.ts +198 -8
- package/index.js +132 -7
- package/kotlin/aardink-web.import-object.mjs +11 -1
- package/kotlin/aardink-web.mjs +12 -0
- package/kotlin/aardink-web.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,10 +72,41 @@ await registerLanguage(
|
|
|
72
72
|
await defineTheme('toy-dark', { base: 'vs-dark', inherit: true, rules: [{ token: 'keyword', foreground: 'ff00ff' }] });
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
Completion items take Monaco's `filterText`, `sortText`
|
|
76
|
-
`inheritCompletions: false` in the definition leaves out the
|
|
77
|
-
(XML's are Android-flavoured) while keeping its diagnostics and
|
|
78
|
-
`
|
|
75
|
+
Completion items take Monaco's `filterText`, `sortText`, `range`, `detail`, `commitCharacters` and
|
|
76
|
+
`kind` names or numbers too, and `inheritCompletions: false` in the definition leaves out the
|
|
77
|
+
extended language's completions (XML's are Android-flavoured) while keeping its diagnostics and
|
|
78
|
+
folding. Answer `{ suggestions, incomplete: false }` to be asked once per word and let the editor
|
|
79
|
+
narrow the list as letters are typed. A hover can carry an `example`, shown as code.
|
|
80
|
+
|
|
81
|
+
An XML dialect can describe its vocabulary as a `schema` instead of answering completions by hand:
|
|
82
|
+
elements by what they may hold, attributes, values, required attributes and documentation. The
|
|
83
|
+
editor completes, documents and checks from it:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
await registerLanguage({
|
|
87
|
+
id: 'toy-markup',
|
|
88
|
+
extends: 'xml',
|
|
89
|
+
grammar,
|
|
90
|
+
schema: {
|
|
91
|
+
roots: ['page'],
|
|
92
|
+
elements: {
|
|
93
|
+
page: { doc: 'A page.', children: ['text'] },
|
|
94
|
+
text: { children: [], attributes: { value: { required: true }, align: { values: ['start', 'end'] } } },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The editor answers to your keys and actions as Monaco's does, and tells you what changed:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
editor.addCommand('CtrlCmd+S', save);
|
|
104
|
+
editor.addAction({ id: 'app.preview', label: 'Preview', keybindings: ['F5'], contextMenuGroupId: 'app', run: preview });
|
|
105
|
+
editor.trigger('toolbar', 'editor.action.formatDocument');
|
|
106
|
+
editor.onDidChangeContent((text, { changes }) => mirror.apply(changes));
|
|
107
|
+
editor.onDidChangeCursorSelection(({ selection, reason }) => syncPreview(selection, reason));
|
|
108
|
+
editor.revealLineInCenter(42);
|
|
109
|
+
```
|
|
79
110
|
|
|
80
111
|
The editor fills its container, so give the container a size. `createEditor` is async because
|
|
81
112
|
the first call loads the WebAssembly module (about 13 MB, 4.7 MB gzipped); every editor on the
|
package/index.d.ts
CHANGED
|
@@ -43,15 +43,48 @@ export interface AardinkOptions {
|
|
|
43
43
|
minimap?: { enabled?: boolean } | boolean;
|
|
44
44
|
/** The first lines of the blocks the top of the view is inside stay pinned at the top. Off by default. */
|
|
45
45
|
stickyScroll?: { enabled?: boolean } | boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Typing a letter in code (not in a string or comment) opens the completion list, as Monaco's
|
|
48
|
+
* option; Monaco's `{ other, comments, strings }` works too, `other` deciding. Off by default.
|
|
49
|
+
*/
|
|
50
|
+
quickSuggestions?: boolean | { other?: boolean | 'on' | 'off' | 'inline'; comments?: unknown; strings?: unknown };
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Monaco-marker shape: 1-based lines and columns, `endColumn` exclusive. A Monaco `IMarkerData`
|
|
55
|
+
* passes as it is: `startLineNumber` for `line`, a `MarkerSeverity` number for `severity`, `code`
|
|
56
|
+
* as `{ value, target }`. Reported diagnostics carry both `line` and `startLineNumber`.
|
|
57
|
+
*/
|
|
49
58
|
export interface AardinkDiagnostic {
|
|
50
|
-
line
|
|
59
|
+
/** The first line; or give `startLineNumber`. */
|
|
60
|
+
line?: number;
|
|
61
|
+
startLineNumber?: number;
|
|
51
62
|
startColumn: number;
|
|
63
|
+
/** The last line, `line` when absent. */
|
|
64
|
+
endLineNumber?: number;
|
|
52
65
|
endColumn: number;
|
|
53
66
|
message: string;
|
|
54
|
-
|
|
67
|
+
/** `'error'` when absent; Monaco's `MarkerSeverity` numbers (8, 4, 2, 1) work too. A hint gets three dots under its start and no gutter dot. */
|
|
68
|
+
severity?: 'error' | 'warning' | 'info' | 'hint' | 1 | 2 | 4 | 8;
|
|
69
|
+
/** Shown with the message, e.g. `'xml'`. */
|
|
70
|
+
source?: string;
|
|
71
|
+
/** The producer's identifier for this kind of problem, shown after `source`. Monaco's `{ value, target }` works too. */
|
|
72
|
+
code?: string | { value: string; target: string };
|
|
73
|
+
/** Where `code` is explained (Monaco's `code.target`). */
|
|
74
|
+
codeHref?: string;
|
|
75
|
+
/** Monaco's `MarkerTag`s: `1` unnecessary (drawn faded), `2` deprecated (struck through). */
|
|
76
|
+
tags?: (1 | 2)[];
|
|
77
|
+
relatedInformation?: AardinkRelatedInformation[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Monaco's `IRelatedInformation`, with the resource as a string (a Monaco `Uri` is turned into one). */
|
|
81
|
+
export interface AardinkRelatedInformation {
|
|
82
|
+
resource: string | { toString(): string };
|
|
83
|
+
message: string;
|
|
84
|
+
startLineNumber: number;
|
|
85
|
+
startColumn: number;
|
|
86
|
+
endLineNumber: number;
|
|
87
|
+
endColumn: number;
|
|
55
88
|
}
|
|
56
89
|
|
|
57
90
|
/** Monaco's `Selection`: from where it started to where the caret is, 1-based, with the range from start to end. */
|
|
@@ -66,6 +99,17 @@ export interface AardinkSelection {
|
|
|
66
99
|
readonly endColumn?: number;
|
|
67
100
|
}
|
|
68
101
|
|
|
102
|
+
/**
|
|
103
|
+
* One change to the text, as Monaco's `IModelContentChange`: `range` (1-based, `endColumn`
|
|
104
|
+
* exclusive), or `rangeOffset` and `rangeLength`, was replaced by `text`.
|
|
105
|
+
*/
|
|
106
|
+
export interface AardinkModelContentChange {
|
|
107
|
+
range: AardinkRange;
|
|
108
|
+
rangeOffset: number;
|
|
109
|
+
rangeLength: number;
|
|
110
|
+
text: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
69
113
|
/** What a content change was, as Monaco's `IModelContentChangedEvent` says it. */
|
|
70
114
|
export interface AardinkContentChange {
|
|
71
115
|
/** Goes up with every change. */
|
|
@@ -74,6 +118,29 @@ export interface AardinkContentChange {
|
|
|
74
118
|
isRedoing: boolean;
|
|
75
119
|
/** The whole text was replaced and the undo history cleared (`setValue`); `false` for `replaceValue` and `executeEdits`. */
|
|
76
120
|
isFlush: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* The changes since the last event, in the order they were made. Unlike Monaco's, each change's
|
|
123
|
+
* range is in the text as the changes before it in the list left it, so applying them in order
|
|
124
|
+
* to the previous text gives this one. Several edits within one frame come in one event.
|
|
125
|
+
*/
|
|
126
|
+
changes: AardinkModelContentChange[];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Monaco's `IPosition`: 1-based. */
|
|
130
|
+
export interface AardinkPosition {
|
|
131
|
+
lineNumber: number;
|
|
132
|
+
column: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Monaco's `ICursorSelectionChangedEvent`, with the reason as a word. */
|
|
136
|
+
export interface AardinkSelectionChangeEvent {
|
|
137
|
+
/** The primary selection. */
|
|
138
|
+
selection: AardinkSelection;
|
|
139
|
+
secondarySelections: AardinkSelection[];
|
|
140
|
+
/** Why they changed. */
|
|
141
|
+
reason: 'keyboard' | 'pointer' | 'edit' | 'undo' | 'redo' | 'flush' | 'api';
|
|
142
|
+
/** Monaco's source: `'model'` when an edit, an undo or a new text moved them. */
|
|
143
|
+
source: 'keyboard' | 'mouse' | 'api' | 'model';
|
|
77
144
|
}
|
|
78
145
|
|
|
79
146
|
/**
|
|
@@ -120,6 +187,52 @@ export interface AardinkEditor {
|
|
|
120
187
|
onDidChangeContent(listener: (text: string, change: AardinkContentChange) => void): () => void;
|
|
121
188
|
/** 1-based caret position. Returns an unsubscribe function. */
|
|
122
189
|
onDidChangeCursor(listener: (line: number, column: number) => void): () => void;
|
|
190
|
+
/** Every change to the selections, with why. Not called when they are set to what they already were. Returns an unsubscribe function. */
|
|
191
|
+
onDidChangeCursorSelection(listener: (event: AardinkSelectionChangeEvent) => void): () => void;
|
|
192
|
+
/** The text gained the keyboard focus. Returns an unsubscribe function. */
|
|
193
|
+
onDidFocusEditorText(listener: () => void): () => void;
|
|
194
|
+
/** The text lost the keyboard focus. Returns an unsubscribe function. */
|
|
195
|
+
onDidBlurEditorText(listener: () => void): () => void;
|
|
196
|
+
/** The primary caret. */
|
|
197
|
+
getPosition(): AardinkPosition;
|
|
198
|
+
/** One caret at `position`, clamped to the text; it does not scroll (see `revealPosition`). */
|
|
199
|
+
setPosition(position: AardinkPosition): void;
|
|
200
|
+
/** Scrolls `line` into view without moving the caret. */
|
|
201
|
+
revealLine(line: number): void;
|
|
202
|
+
/** Scrolls `line` to the middle of the view without moving the caret. */
|
|
203
|
+
revealLineInCenter(line: number): void;
|
|
204
|
+
/** Scrolls the start of `range` into view without moving the caret. */
|
|
205
|
+
revealRange(range: AardinkRange): void;
|
|
206
|
+
/** Scrolls the start of `range` to the middle of the view without moving the caret. */
|
|
207
|
+
revealRangeInCenter(range: AardinkRange): void;
|
|
208
|
+
/**
|
|
209
|
+
* Monaco's `trigger`: runs an action by its id, one you added with `addAction` or `addCommand`,
|
|
210
|
+
* or one of the editor's own by Monaco's id: `editor.action.formatDocument`,
|
|
211
|
+
* `editor.action.formatSelection`, `editor.action.triggerSuggest`, `editor.action.showHover`,
|
|
212
|
+
* `editor.action.quickFix`, `editor.action.rename`, `editor.action.revealDefinition`,
|
|
213
|
+
* `editor.action.goToReferences`, `editor.action.marker.next`, `editor.action.marker.prev`,
|
|
214
|
+
* `actions.find`, `editor.action.startFindReplaceAction`, `editor.action.gotoLine`,
|
|
215
|
+
* `editor.foldAll`, `editor.unfoldAll`, `editor.foldLevel1` to `7`, `undo`, `redo`,
|
|
216
|
+
* `editor.action.commentLine`, `editor.action.selectHighlights`, and
|
|
217
|
+
* `editor.action.insertSnippet` with `{ snippet }`. `source` is accepted for Monaco's shape.
|
|
218
|
+
* Returns whether it ran.
|
|
219
|
+
*/
|
|
220
|
+
trigger(source: string | null | undefined, handlerId: string, payload?: unknown): boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Monaco's `addCommand`: `handler` runs when `keybinding` is pressed in the editor, ahead of the
|
|
223
|
+
* editor's own binding for it. A keybinding is text such as `'CtrlCmd+S'`, `'Shift+Alt+F'` or
|
|
224
|
+
* `'F8'` (`CtrlCmd` is Cmd on macOS and Ctrl elsewhere; `Ctrl` is Ctrl everywhere), or Monaco's
|
|
225
|
+
* `KeyMod | KeyCode` number for a letter, digit, function, navigation or punctuation key.
|
|
226
|
+
* Returns the command's id, for `trigger`; null for a keybinding it cannot read.
|
|
227
|
+
*/
|
|
228
|
+
addCommand(keybinding: string | number, handler: () => void): string | null;
|
|
229
|
+
/**
|
|
230
|
+
* Monaco's `addAction`: `run` is called by `trigger(…, id)`, by its keybindings, and from the
|
|
231
|
+
* right-click menu when it has a `contextMenuGroupId`. Adding an id again replaces it.
|
|
232
|
+
*/
|
|
233
|
+
addAction(descriptor: AardinkActionDescriptor): { dispose(): void };
|
|
234
|
+
/** An action by its id, yours or the editor's own (see `trigger`); null for an id neither has. */
|
|
235
|
+
getAction(id: string): AardinkAction | null;
|
|
123
236
|
/**
|
|
124
237
|
* Shows these diagnostics in place of the language's own; `null` goes back to the language's
|
|
125
238
|
* own. Either way they move along with the text as it is edited, until the next list.
|
|
@@ -167,6 +280,32 @@ export interface AardinkEditor {
|
|
|
167
280
|
dispose(): void;
|
|
168
281
|
}
|
|
169
282
|
|
|
283
|
+
/** What `addAction` takes, as Monaco's `IActionDescriptor`. */
|
|
284
|
+
export interface AardinkActionDescriptor {
|
|
285
|
+
id: string;
|
|
286
|
+
label: string;
|
|
287
|
+
/** As `addCommand`'s keybinding. */
|
|
288
|
+
keybindings?: (string | number)[];
|
|
289
|
+
/** Any value puts the action in the right-click menu. */
|
|
290
|
+
contextMenuGroupId?: string;
|
|
291
|
+
contextMenuOrder?: number;
|
|
292
|
+
run(editor: AardinkEditor): void | Promise<void>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** Monaco's `IEditorAction`. */
|
|
296
|
+
export interface AardinkAction {
|
|
297
|
+
id: string;
|
|
298
|
+
label: string;
|
|
299
|
+
/** Whether it can run now. */
|
|
300
|
+
isSupported(): boolean;
|
|
301
|
+
/**
|
|
302
|
+
* Runs it. For an action added with `addAction`, settles when the promise its `run` returned
|
|
303
|
+
* does, and rejects with it; for the editor's own, once it has started (use `format()` to wait
|
|
304
|
+
* for formatting).
|
|
305
|
+
*/
|
|
306
|
+
run(): Promise<void>;
|
|
307
|
+
}
|
|
308
|
+
|
|
170
309
|
/** A language highlighted by a grammar, for `registerLanguage`. */
|
|
171
310
|
export interface AardinkLanguageDefinition {
|
|
172
311
|
/** What `createEditor`'s `language` option names it by. Registering an id again replaces it. */
|
|
@@ -192,6 +331,46 @@ export interface AardinkLanguageDefinition {
|
|
|
192
331
|
extensions?: string[];
|
|
193
332
|
/** As in Monaco's language configuration: what Ctrl/Cmd+/ comments with. */
|
|
194
333
|
comments?: { lineComment?: string; blockComment?: [string, string] };
|
|
334
|
+
/**
|
|
335
|
+
* An XML dialect's vocabulary. Completions (elements by what the element at the caret may hold,
|
|
336
|
+
* with their required attributes; attributes; values), hover documentation and checks (unknown
|
|
337
|
+
* elements and attributes, elements out of place, values not among an attribute's, required
|
|
338
|
+
* attributes left out) come from it, ahead of the language it `extends` (or built-in XML's
|
|
339
|
+
* checks, closing tags and formatting when it extends none). Your providers still come first.
|
|
340
|
+
*/
|
|
341
|
+
schema?: AardinkXmlSchema;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** An XML vocabulary, for `registerLanguage`'s `schema`. */
|
|
345
|
+
export interface AardinkXmlSchema {
|
|
346
|
+
/** The elements a document may start with; any when absent. */
|
|
347
|
+
roots?: string[];
|
|
348
|
+
/** Report elements and attributes the schema does not have. `true` by default. */
|
|
349
|
+
strict?: boolean;
|
|
350
|
+
/** A regex source: attribute values matching it (expressions, placeholders) are not checked. */
|
|
351
|
+
dynamicValue?: string;
|
|
352
|
+
elements: Record<string, AardinkXmlElement>;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface AardinkXmlElement {
|
|
356
|
+
doc?: string;
|
|
357
|
+
/** The elements it may hold; any when absent, none for `[]` (it is then completed self-closing). */
|
|
358
|
+
children?: string[];
|
|
359
|
+
attributes?: Record<string, AardinkXmlAttribute>;
|
|
360
|
+
/** What completing it inserts after `<`, as a snippet, instead of its name, required attributes and end. */
|
|
361
|
+
snippet?: string;
|
|
362
|
+
/** Report attributes it does not have. `true` by default. */
|
|
363
|
+
strictAttributes?: boolean;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export interface AardinkXmlAttribute {
|
|
367
|
+
doc?: string;
|
|
368
|
+
/** Its values; any when absent. */
|
|
369
|
+
values?: (string | { value: string; doc?: string })[];
|
|
370
|
+
/** Report it missing, and insert it when the element is completed. */
|
|
371
|
+
required?: boolean;
|
|
372
|
+
/** What its value is, e.g. `'color'`. */
|
|
373
|
+
type?: string;
|
|
195
374
|
}
|
|
196
375
|
|
|
197
376
|
/** Monaco's flags for a completion's `insertText`. */
|
|
@@ -218,12 +397,19 @@ export interface AardinkCompletionItem {
|
|
|
218
397
|
/** `CompletionItemInsertTextRule` flags, as in Monaco. */
|
|
219
398
|
insertTextRules?: number;
|
|
220
399
|
/**
|
|
221
|
-
* The icon. `'function'` is another name for `'transform'`, and `'color'` for `'colorRef'`, as
|
|
222
|
-
* Monaco
|
|
400
|
+
* The icon. `'function'` is another name for `'transform'`, and `'color'` for `'colorRef'`, as in
|
|
401
|
+
* 0.6. Monaco's other kind names (`'method'`, `'class'`, `'keyword'`, ...) and its
|
|
402
|
+
* `CompletionItemKind` numbers work too; an unknown name shows as `'value'`.
|
|
223
403
|
*/
|
|
224
|
-
kind?:
|
|
225
|
-
|
|
404
|
+
kind?:
|
|
405
|
+
| 'element' | 'attribute' | 'value' | 'snippet' | 'module' | 'property' | 'transform' | 'function' | 'colorRef' | 'color'
|
|
406
|
+
| 'method' | 'constructor' | 'field' | 'variable' | 'class' | 'struct' | 'interface' | 'enum' | 'enumMember' | 'keyword'
|
|
407
|
+
| 'text' | 'file' | 'folder' | 'reference' | 'constant' | 'event' | 'operator' | 'typeParameter' | 'unit' | 'user' | 'issue'
|
|
408
|
+
| number;
|
|
409
|
+
/** A short line about the item, such as a type or a signature, shown beside the label. */
|
|
226
410
|
detail?: string;
|
|
411
|
+
/** Characters that, typed while this item is selected, accept it and are then typed after it. Not for snippets. */
|
|
412
|
+
commitCharacters?: string[];
|
|
227
413
|
/** Shown beside the label; Monaco's `{ value }` is shown as plain text. */
|
|
228
414
|
documentation?: string | { value: string };
|
|
229
415
|
/**
|
|
@@ -247,7 +433,11 @@ export interface AardinkCompletionItem {
|
|
|
247
433
|
export interface AardinkCompletionList {
|
|
248
434
|
suggestions: AardinkCompletionItem[];
|
|
249
435
|
exclusive?: boolean;
|
|
250
|
-
/**
|
|
436
|
+
/**
|
|
437
|
+
* `false`: this list is complete for the word being typed, so your provider is asked once per
|
|
438
|
+
* word and the editor narrows the list by `filterText` (or `label`) as letters are typed. Absent
|
|
439
|
+
* or `true`: your provider is asked again on each letter, as in 0.6.
|
|
440
|
+
*/
|
|
251
441
|
incomplete?: boolean;
|
|
252
442
|
}
|
|
253
443
|
|
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// Adapts the Kotlin module's integer-handle exports (aardinkCreate, aardinkGetValue, ...) into
|
|
18
18
|
// the Monaco-shaped object described in index.d.ts.
|
|
19
19
|
|
|
20
|
-
export const version = '0.
|
|
20
|
+
export const version = '0.7.0';
|
|
21
21
|
|
|
22
22
|
/** Monaco's flags for a completion's `insertText`. */
|
|
23
23
|
export const CompletionItemInsertTextRule = Object.freeze({ None: 0, KeepWhitespace: 1, InsertAsSnippet: 4 });
|
|
@@ -83,6 +83,43 @@ function toKotlinEdit(edit) {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** Monaco's MarkerSeverity numbers, as the words the Kotlin side reads. */
|
|
87
|
+
const MARKER_SEVERITY = { 1: 'hint', 2: 'info', 4: 'warning', 8: 'error' };
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A diagnostic in the Kotlin side's shape, from ours or a Monaco marker: `startLineNumber` for
|
|
91
|
+
* `line`, a numeric severity, `code` as `{ value, target }`, related information with a Uri.
|
|
92
|
+
*/
|
|
93
|
+
function toKotlinDiagnostic(d) {
|
|
94
|
+
const code = d.code;
|
|
95
|
+
const codeIsObject = code != null && typeof code === 'object';
|
|
96
|
+
return {
|
|
97
|
+
line: d.line ?? d.startLineNumber,
|
|
98
|
+
startColumn: d.startColumn,
|
|
99
|
+
endColumn: d.endColumn,
|
|
100
|
+
endLineNumber: d.endLineNumber,
|
|
101
|
+
message: d.message,
|
|
102
|
+
severity: typeof d.severity === 'number' ? (MARKER_SEVERITY[d.severity] ?? 'info') : d.severity,
|
|
103
|
+
source: d.source,
|
|
104
|
+
code: code == null ? undefined : String(codeIsObject ? code.value : code),
|
|
105
|
+
codeHref: d.codeHref ?? (codeIsObject && code.target != null ? String(code.target) : undefined),
|
|
106
|
+
tags: d.tags,
|
|
107
|
+
relatedInformation: d.relatedInformation?.map((r) => ({
|
|
108
|
+
resource: String(r.resource ?? ''),
|
|
109
|
+
message: r.message,
|
|
110
|
+
startLineNumber: r.startLineNumber,
|
|
111
|
+
startColumn: r.startColumn,
|
|
112
|
+
endLineNumber: r.endLineNumber,
|
|
113
|
+
endColumn: r.endColumn,
|
|
114
|
+
})),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A diagnostic the Kotlin side reports, with Monaco's `startLineNumber` beside `line`. */
|
|
119
|
+
function fromKotlinDiagnostic(d) {
|
|
120
|
+
return { startLineNumber: d.line, ...d };
|
|
121
|
+
}
|
|
122
|
+
|
|
86
123
|
/** For debugging a grammar: the tokens of `text` in `languageId`, per line, as Monaco's tokenize gives them. */
|
|
87
124
|
export async function tokenize(text, languageId) {
|
|
88
125
|
const k = await load();
|
|
@@ -125,13 +162,19 @@ export async function registerLanguage(definition, providers = {}) {
|
|
|
125
162
|
displayName: definition.displayName,
|
|
126
163
|
extensions: definition.extensions,
|
|
127
164
|
inheritCompletions: definition.inheritCompletions,
|
|
165
|
+
schema: definition.schema,
|
|
128
166
|
// On the providers, as on Monaco's completion provider; the Kotlin side reads it with the definition.
|
|
129
167
|
triggerCharacters: providers.triggerCharacters,
|
|
130
168
|
grammar,
|
|
131
169
|
}),
|
|
132
170
|
(text, line, column) => answer(providers.provideCompletionItems, text, line, column),
|
|
133
171
|
(text, line, column) => answer(providers.provideHover, text, line, column),
|
|
134
|
-
(text) =>
|
|
172
|
+
(text) =>
|
|
173
|
+
answer(
|
|
174
|
+
providers.provideDiagnostics &&
|
|
175
|
+
((t) => Promise.resolve(providers.provideDiagnostics(t)).then((list) => (list == null ? null : list.map(toKotlinDiagnostic)))),
|
|
176
|
+
text,
|
|
177
|
+
),
|
|
135
178
|
);
|
|
136
179
|
if (error) throw new Error(`Aardink: ${error}`);
|
|
137
180
|
}
|
|
@@ -178,6 +221,12 @@ function toKotlinOptions(options) {
|
|
|
178
221
|
}
|
|
179
222
|
if (options.wordWrap !== undefined) out.wordWrap = options.wordWrap === 'on';
|
|
180
223
|
if (options.renderLineHighlight !== undefined) out.highlightCurrentLine = options.renderLineHighlight !== 'none';
|
|
224
|
+
if (options.quickSuggestions !== undefined) {
|
|
225
|
+
// Monaco's { other, comments, strings }: the editor opens the list in code, so `other` decides.
|
|
226
|
+
const value = options.quickSuggestions;
|
|
227
|
+
const other = typeof value === 'object' && value !== null ? value.other : value;
|
|
228
|
+
out.quickSuggestions = other !== false && other !== 'off' && other !== undefined;
|
|
229
|
+
}
|
|
181
230
|
for (const key of ['minimap', 'stickyScroll', 'bracketPairColorization']) {
|
|
182
231
|
const value = options[key];
|
|
183
232
|
if (value !== undefined) out[key] = typeof value === 'object' && value !== null ? value.enabled !== false : !!value;
|
|
@@ -194,21 +243,42 @@ export async function createEditor(container, onChange, options = {}) {
|
|
|
194
243
|
const contentListeners = new Set();
|
|
195
244
|
const cursorListeners = new Set();
|
|
196
245
|
const diagnosticsListeners = new Set();
|
|
197
|
-
|
|
198
|
-
|
|
246
|
+
const selectionListeners = new Set();
|
|
247
|
+
const focusListeners = new Set();
|
|
248
|
+
const blurListeners = new Set();
|
|
249
|
+
k.aardinkOnContentChange(id, (text, versionId, kind, changesJson) => {
|
|
250
|
+
if (contentListeners.size === 0) return;
|
|
251
|
+
const event = {
|
|
252
|
+
versionId,
|
|
253
|
+
isUndoing: kind === 'undo',
|
|
254
|
+
isRedoing: kind === 'redo',
|
|
255
|
+
isFlush: kind === 'flush',
|
|
256
|
+
changes: JSON.parse(changesJson),
|
|
257
|
+
};
|
|
199
258
|
contentListeners.forEach((listener) => listener(text, event));
|
|
200
259
|
});
|
|
201
260
|
k.aardinkOnCursorChange(id, (line, column) => cursorListeners.forEach((listener) => listener(line, column)));
|
|
261
|
+
k.aardinkOnSelectionChange(id, (json) => {
|
|
262
|
+
if (selectionListeners.size === 0) return;
|
|
263
|
+
const { selections, reason, source } = JSON.parse(json);
|
|
264
|
+
const all = selections.map(withRange);
|
|
265
|
+
const event = { selection: all[0], secondarySelections: all.slice(1), reason, source };
|
|
266
|
+
selectionListeners.forEach((listener) => listener(event));
|
|
267
|
+
});
|
|
268
|
+
k.aardinkOnFocusChange(id, (focused) => (focused ? focusListeners : blurListeners).forEach((listener) => listener()));
|
|
202
269
|
k.aardinkOnDiagnosticsChange(id, (json) => {
|
|
203
270
|
if (diagnosticsListeners.size === 0) return;
|
|
204
|
-
const diagnostics = JSON.parse(json);
|
|
271
|
+
const diagnostics = JSON.parse(json).map(fromKotlinDiagnostic);
|
|
205
272
|
diagnosticsListeners.forEach((listener) => listener(diagnostics));
|
|
206
273
|
});
|
|
207
274
|
if (onChange) contentListeners.add(onChange);
|
|
208
275
|
|
|
209
276
|
let disposed = false;
|
|
277
|
+
// What the last host action run returned, so getAction().run() can wait for it: the Kotlin
|
|
278
|
+
// side calls `run` as a () -> Unit and drops the value.
|
|
279
|
+
let actionResult;
|
|
210
280
|
|
|
211
|
-
|
|
281
|
+
const editor = {
|
|
212
282
|
getValue: () => k.aardinkGetValue(id),
|
|
213
283
|
setValue: (text) => k.aardinkSetValue(id, text),
|
|
214
284
|
replaceValue: (text) => k.aardinkReplaceValue(id, text),
|
|
@@ -229,7 +299,58 @@ export async function createEditor(container, onChange, options = {}) {
|
|
|
229
299
|
cursorListeners.add(listener);
|
|
230
300
|
return () => cursorListeners.delete(listener);
|
|
231
301
|
},
|
|
232
|
-
|
|
302
|
+
onDidChangeCursorSelection(listener) {
|
|
303
|
+
selectionListeners.add(listener);
|
|
304
|
+
return () => selectionListeners.delete(listener);
|
|
305
|
+
},
|
|
306
|
+
onDidFocusEditorText(listener) {
|
|
307
|
+
focusListeners.add(listener);
|
|
308
|
+
return () => focusListeners.delete(listener);
|
|
309
|
+
},
|
|
310
|
+
onDidBlurEditorText(listener) {
|
|
311
|
+
blurListeners.add(listener);
|
|
312
|
+
return () => blurListeners.delete(listener);
|
|
313
|
+
},
|
|
314
|
+
getPosition: () => JSON.parse(k.aardinkGetPosition(id)),
|
|
315
|
+
setPosition: (position) => k.aardinkSetPosition(id, position.lineNumber, position.column),
|
|
316
|
+
revealLine: (line) => k.aardinkRevealLine(id, line, false),
|
|
317
|
+
revealLineInCenter: (line) => k.aardinkRevealLine(id, line, true),
|
|
318
|
+
revealRange: (range) => k.aardinkRevealRange(id, range.startLineNumber, range.startColumn, false),
|
|
319
|
+
revealRangeInCenter: (range) => k.aardinkRevealRange(id, range.startLineNumber, range.startColumn, true),
|
|
320
|
+
trigger: (source, handlerId, payload) => k.aardinkTrigger(id, handlerId, JSON.stringify(payload ?? null)),
|
|
321
|
+
addCommand(keybinding, handler) {
|
|
322
|
+
const commandId = k.aardinkAddCommand(id, String(keybinding), () => handler());
|
|
323
|
+
return commandId || null;
|
|
324
|
+
},
|
|
325
|
+
addAction(descriptor) {
|
|
326
|
+
const keybindings = (descriptor.keybindings ?? []).map(String);
|
|
327
|
+
k.aardinkAddAction(id, descriptor.id, descriptor.label, keybindings.join('\n'), descriptor.contextMenuGroupId != null, () => {
|
|
328
|
+
actionResult = descriptor.run(editor);
|
|
329
|
+
});
|
|
330
|
+
return { dispose: () => k.aardinkRemoveAction(id, descriptor.id) };
|
|
331
|
+
},
|
|
332
|
+
getAction(actionId) {
|
|
333
|
+
const label = k.aardinkActionLabel(id, actionId);
|
|
334
|
+
if (!label) return null;
|
|
335
|
+
return {
|
|
336
|
+
id: actionId,
|
|
337
|
+
label,
|
|
338
|
+
isSupported: () => k.aardinkCanTrigger(id, actionId),
|
|
339
|
+
run() {
|
|
340
|
+
actionResult = undefined;
|
|
341
|
+
try {
|
|
342
|
+
k.aardinkTrigger(id, actionId, 'null');
|
|
343
|
+
} catch (e) {
|
|
344
|
+
return Promise.reject(e);
|
|
345
|
+
}
|
|
346
|
+
const result = actionResult;
|
|
347
|
+
actionResult = undefined;
|
|
348
|
+
// Settles with a host action's own promise; one of the editor's own has only started.
|
|
349
|
+
return Promise.resolve(result).then(() => undefined);
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
setDiagnostics: (diagnostics) => k.aardinkSetDiagnostics(id, JSON.stringify(diagnostics == null ? null : diagnostics.map(toKotlinDiagnostic))),
|
|
233
354
|
onDidChangeDiagnostics(listener) {
|
|
234
355
|
diagnosticsListeners.add(listener);
|
|
235
356
|
return () => diagnosticsListeners.delete(listener);
|
|
@@ -254,7 +375,11 @@ export async function createEditor(container, onChange, options = {}) {
|
|
|
254
375
|
contentListeners.clear();
|
|
255
376
|
cursorListeners.clear();
|
|
256
377
|
diagnosticsListeners.clear();
|
|
378
|
+
selectionListeners.clear();
|
|
379
|
+
focusListeners.clear();
|
|
380
|
+
blurListeners.clear();
|
|
257
381
|
k.aardinkDispose(id);
|
|
258
382
|
},
|
|
259
383
|
};
|
|
384
|
+
return editor;
|
|
260
385
|
}
|
|
@@ -216,6 +216,7 @@ const js_code = {
|
|
|
216
216
|
'org.w3c.dom.events.timeStamp_$external_prop_getter' : (_this) => _this.timeStamp,
|
|
217
217
|
'org.w3c.dom.events.preventDefault_$external_fun' : (_this, ) => _this.preventDefault(),
|
|
218
218
|
'org.w3c.dom.events.Event_$external_class_instanceof' : (x) => x instanceof Event,
|
|
219
|
+
'org.w3c.dom.events.Event_$external_class_get' : () => Event,
|
|
219
220
|
'org.w3c.dom.events.key_$external_prop_getter' : (_this) => _this.key,
|
|
220
221
|
'org.w3c.dom.events.code_$external_prop_getter' : (_this) => _this.code,
|
|
221
222
|
'org.w3c.dom.events.ctrlKey_$external_prop_getter' : (_this) => _this.ctrlKey,
|
|
@@ -235,6 +236,9 @@ const js_code = {
|
|
|
235
236
|
'org.w3c.dom.events.DOM_DELTA_PAGE_$external_prop_getter' : (_this) => _this.DOM_DELTA_PAGE,
|
|
236
237
|
'org.w3c.dom.events.Companion_$external_object_getInstance' : () => WheelEvent,
|
|
237
238
|
'org.w3c.dom.events.WheelEvent_$external_class_instanceof' : (x) => x instanceof WheelEvent,
|
|
239
|
+
'org.w3c.dom.events.WheelEvent_$external_class_get' : () => WheelEvent,
|
|
240
|
+
'org.w3c.dom.events.FocusEvent_$external_class_instanceof' : (x) => x instanceof FocusEvent,
|
|
241
|
+
'org.w3c.dom.events.FocusEvent_$external_class_get' : () => FocusEvent,
|
|
238
242
|
'org.w3c.dom.events.addEventListener_$external_fun' : (_this, p0, p1, p2) => _this.addEventListener(p0, p1, p2),
|
|
239
243
|
'org.w3c.dom.events.addEventListener_$external_fun_1' : (_this, p0, p1) => _this.addEventListener(p0, p1),
|
|
240
244
|
'org.w3c.dom.events.addEventListener_$external_fun_2' : (_this, p0, p1) => _this.addEventListener(p0, p1),
|
|
@@ -312,6 +316,8 @@ const js_code = {
|
|
|
312
316
|
'org.w3c.dom.HTMLDivElement_$external_class_get' : () => HTMLDivElement,
|
|
313
317
|
'org.w3c.dom.HTMLTextAreaElement_$external_class_instanceof' : (x) => x instanceof HTMLTextAreaElement,
|
|
314
318
|
'org.w3c.dom.HTMLTextAreaElement_$external_class_get' : () => HTMLTextAreaElement,
|
|
319
|
+
'org.w3c.dom.TouchEvent_$external_class_instanceof' : (x) => x instanceof TouchEvent,
|
|
320
|
+
'org.w3c.dom.TouchEvent_$external_class_get' : () => TouchEvent,
|
|
315
321
|
'org.w3c.dom.matches_$external_prop_getter_1' : (_this) => _this.matches,
|
|
316
322
|
'org.w3c.dom.MediaQueryListEvent_$external_class_instanceof' : (x) => x instanceof MediaQueryListEvent,
|
|
317
323
|
'org.w3c.dom.MediaQueryListEvent_$external_class_get' : () => MediaQueryListEvent,
|
|
@@ -344,10 +350,14 @@ const js_code = {
|
|
|
344
350
|
'org.w3c.dom.HTMLButtonElement_$external_class_get' : () => HTMLButtonElement,
|
|
345
351
|
'org.w3c.dom.pointerevents.pointerId_$external_prop_getter' : (_this) => _this.pointerId,
|
|
346
352
|
'org.w3c.dom.pointerevents.pressure_$external_prop_getter' : (_this) => _this.pressure,
|
|
353
|
+
'org.w3c.dom.pointerevents.PointerEvent_$external_class_instanceof' : (x) => x instanceof PointerEvent,
|
|
354
|
+
'org.w3c.dom.pointerevents.PointerEvent_$external_class_get' : () => PointerEvent,
|
|
347
355
|
'org.w3c.fetch.ok_$external_prop_getter' : (_this) => _this.ok,
|
|
348
356
|
'org.w3c.fetch.clone_$external_fun' : (_this, ) => _this.clone(),
|
|
349
357
|
'org.w3c.fetch.arrayBuffer_$external_fun' : (_this, ) => _this.arrayBuffer(),
|
|
350
358
|
'org.w3c.fetch.blob_$external_fun' : (_this, ) => _this.blob(),
|
|
359
|
+
'org.w3c.fetch.Response_$external_class_instanceof' : (x) => x instanceof Response,
|
|
360
|
+
'org.w3c.fetch.Response_$external_class_get' : () => Response,
|
|
351
361
|
'org.w3c.performance.now_$external_fun' : (_this, ) => _this.now(),
|
|
352
362
|
'org.w3c.performance.performance_$external_prop_getter' : (_this) => _this.performance,
|
|
353
363
|
'org.w3c.workers.CacheQueryOptions_js_code' : (ignoreSearch, ignoreMethod, ignoreVary, cacheName) => ({ ignoreSearch: ignoreSearch, ignoreMethod: ignoreMethod, ignoreVary: ignoreVary, cacheName: cacheName }),
|
|
@@ -582,7 +592,7 @@ const js_code = {
|
|
|
582
592
|
'com.aardarch.aardink.sampleweb.__callJsClosure_((Int,Int)->Unit)' : (f, p0, p1) => f(p0, p1),
|
|
583
593
|
'com.aardarch.aardink.sampleweb.__callJsClosure_((String,Int,Int)->Js)' : (f, p0, p1, p2) => f(p0, p1, p2),
|
|
584
594
|
'com.aardarch.aardink.sampleweb.__callJsClosure_((String)->Js)' : (f, p0) => f(p0),
|
|
585
|
-
'com.aardarch.aardink.sampleweb.__callJsClosure_((String,Int,String)->Unit)' : (f, p0, p1, p2) => f(p0, p1, p2),
|
|
595
|
+
'com.aardarch.aardink.sampleweb.__callJsClosure_((String,Int,String,String)->Unit)' : (f, p0, p1, p2, p3) => f(p0, p1, p2, p3),
|
|
586
596
|
'com.aardarch.aardink.sampleweb.__callJsClosure_((Boolean)->Unit)' : (f, p0) => f(p0),
|
|
587
597
|
'com.aardarch.aardink.sampleweb.usedJsHeapBytes' : () => (performance.memory ? performance.memory.usedJSHeapSize : -1)
|
|
588
598
|
}
|
package/kotlin/aardink-web.mjs
CHANGED
|
@@ -92,6 +92,18 @@ export const {
|
|
|
92
92
|
aardinkRegisterLanguage,
|
|
93
93
|
aardinkRegisterTheme,
|
|
94
94
|
aardinkOnContentChange,
|
|
95
|
+
aardinkOnSelectionChange,
|
|
96
|
+
aardinkOnFocusChange,
|
|
97
|
+
aardinkGetPosition,
|
|
98
|
+
aardinkSetPosition,
|
|
99
|
+
aardinkTrigger,
|
|
100
|
+
aardinkCanTrigger,
|
|
101
|
+
aardinkActionLabel,
|
|
102
|
+
aardinkAddAction,
|
|
103
|
+
aardinkRemoveAction,
|
|
104
|
+
aardinkAddCommand,
|
|
105
|
+
aardinkRevealLine,
|
|
106
|
+
aardinkRevealRange,
|
|
95
107
|
aardinkSetBaseline,
|
|
96
108
|
aardinkFormat,
|
|
97
109
|
aardinkFocus,
|
package/kotlin/aardink-web.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED