-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkedit.d.ts
340 lines (288 loc) · 7.6 KB
/
markedit.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/**
* https://github.com/MarkEdit-app/MarkEdit-api
*
* - [MarkEdit Customization Guide](https://github.com/MarkEdit-app/MarkEdit/wiki/Customization)
* - [Example: Markdown Table Editor](https://github.com/MarkEdit-app/MarkEdit-mte)
* - [Example: Text Highlight](https://github.com/MarkEdit-app/MarkEdit-highlight)
* - [Example: Vue Language Package](https://github.com/MarkEdit-app/MarkEdit-lang-vue)
*/
import type { EditorView } from '@codemirror/view';
import type { Extension } from '@codemirror/state';
import type { LanguageDescription } from '@codemirror/language';
import type { MarkdownConfig } from '@lezer/markdown';
import type * as cmView from '@codemirror/view';
import type * as cmState from '@codemirror/state';
import type * as cmLanguage from '@codemirror/language';
import type * as cmCommands from '@codemirror/commands';
import type * as cmSearch from '@codemirror/search';
import type * as lezerCommon from '@lezer/common';
import type * as lezerHighlight from '@lezer/highlight';
import type * as lezerMarkdown from '@lezer/markdown';
import type * as lezerLr from '@lezer/lr';
export const MarkEdit: MarkEdit;
export interface MarkEdit {
/**
* CodeMirror EditorView instance of the current editor.
*/
editorView: EditorView;
/**
* Convenient text editing interfaces.
*/
editorAPI: TextEditable;
/**
* CodeMirror modules used by MarkEdit.
*/
codemirror: {
/**
* The `@codemirror/view` module.
*/
view: typeof cmView;
/**
* The `@codemirror/state` module.
*/
state: typeof cmState;
/**
* The `@codemirror/language` module.
*/
language: typeof cmLanguage;
/**
* The `@codemirror/commands` module.
*/
commands: typeof cmCommands;
/**
* The `@codemirror/search` module.
*/
search: typeof cmSearch;
};
/**
* Lezer modules used by MarkEdit.
*/
lezer: {
/**
* The `@lezer/common` module.
*/
common: typeof lezerCommon;
/**
* The `@lezer/highlight` module.
*/
highlight: typeof lezerHighlight;
/**
* The `@lezer/markdown` module.
*/
markdown: typeof lezerMarkdown;
/**
* The `@lezer/lr` module.
*/
lr: typeof lezerLr;
};
/**
* Get notified when the editor is initialized.
* @param listener The callback function with the initialized editor instance.
*/
onEditorReady(listener: (editorView: EditorView) => void): void;
/**
* Get information of the current file.
* @returns The file information, or undefined for unsaved new drafts.
*/
getFileInfo(): Promise<FileInfo | undefined>;
/**
* Get all items from the native pasteboard.
* @returns The items from the native (general) pasteboard.
*/
getPasteboardItems(): Promise<PasteboardItem[]>;
/**
* Get the string from the native pasteboard.
* @returns The string from the native (general) pasteboard, if applicable.
*/
getPasteboardString(): Promise<string | undefined>;
/**
* Add an extension to MarkEdit.
* @param extension CodeMirror extension.
*/
addExtension(extension: Extension): void;
/**
* Add a Markdown config to MarkEdit.
* @param config Markdown config.
*/
addMarkdownConfig(config: MarkdownConfig): void;
/**
* Add a language to be highlighted (in code blocks) to MarkEdit.
* @param language The language description.
*/
addCodeLanguage(language: LanguageDescription): void;
/**
* Add a menu item to the status bar.
* @param item The menu item to add, which will be placed under the "Extensions" submenu. It can either perform an action or contain a submenu.
*/
addMainMenuItem(item: MenuItem | MenuItem[]): void;
/**
* Present a contextual menu to receive user input.
* @param items The items in the menu.
* @param location The location to show the menu, with the default value set to the caret position.
*/
showContextMenu(items: MenuItem[], location?: Point): void;
/**
* Present an alert to receive user input.
* @param alert The alert to present.
* @returns The index of the chosen button, 0-indexed.
*/
showAlert(alert: Alert): Promise<number>;
/**
* Present a text box to receive user input.
* @param textBox The text box to present.
* @returns The input string, or undefined if no value is provided.
*/
showTextBox(textBox?: TextBox): Promise<string | undefined>;
}
/**
* Abstract editor to provide convenient text editing interfaces.
*/
export interface TextEditable {
/**
* Get text of the document.
* @param range The range of the text. If no range is provided, the entire document is returned.
*/
getText(range?: TextRange): string;
/**
* Set text for the document.
* @param text The text to set.
* @param range The range of the text. If no range is provided, the entire document is overwritten.
*/
setText(text: string, range?: TextRange): void;
/**
* Get text selections.
*/
getSelections(): TextRange[];
/**
* Set text selections.
* @param ranges Text ranges to set.
*/
setSelections(ranges: TextRange[]): void;
/**
* Get the line number (0-indexed) of given text position.
* @param position The text position.
*/
getLineNumber(position: number): number;
/**
* Get line range of given row (0-indexed).
* @param row The line number.
*/
getLineRange(row: number): TextRange;
/**
* Get number of lines.
*/
getLineCount(): number;
/**
* Get line separator.
*/
getLineBreak(): string;
/**
* Get CodeMirror syntax node name of given position.
* @param position The text position.
*/
getNodeName(position: number): string;
/**
* Undo a change.
*/
undo(): void;
/**
* Redo a change.
*/
redo(): void;
}
/**
* Information of a file in the file system.
*/
export type FileInfo = {
filePath: string;
fileSize: number;
creationDate: Date;
modificationDate: Date;
};
/**
* Represents a native pasteboard item.
*/
export type PasteboardItem = {
/**
* Type name, such as `public.utf8-plain-text`.
*/
type: string;
/**
* Base64 representation of the pasteboard data.
*/
data: string;
/**
* String representation of the pasteboard data, if applicable.
*/
string?: string;
};
/**
* Represents a portion of text.
*/
export type TextRange = {
from: number;
to: number;
};
/**
* Represents a menu item in native menus.
*/
export type MenuItem = {
title?: string;
action?: () => void;
/**
* Whether an item is a separator used to logically group other items.
*/
separator?: boolean;
/**
* Key equivalent of the action.
*/
key?: string;
/**
* Key modifiers of the action. Valid values are `Shift`, `Control`, `Command`, and `Option`.
*
* The order does not matter but they are case sensitive.
*
* When `key` is uppercase, `Shift` is automatically enabled.
*/
modifiers?: ('Shift' | 'Control' | 'Command' | 'Option')[];
/**
* Child items to build a submenu.
*/
children?: MenuItem[];
};
/**
* Represents a location on the screen.
*/
export type Point = {
x: number;
y: number;
};
/**
* Represents a native alert to present.
*
* If it's a string, it will be used as the title.
*/
export type Alert = {
/**
* The title that is displayed prominently in the alert.
*/
title?: string;
/**
* The informative message for more details.
*/
message?: string;
/**
* The button titles.
*/
buttons?: string[];
} | string;
/**
* Represents a text box to receive input.
*
* If it's a string, it will be used as the title.
*/
export type TextBox = {
title?: string;
placeholder?: string;
defaultValue?: string;
} | string;