markedit-api 0.0.0-stage → 0.39.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MarkEdit.app
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,138 @@
1
- # Temporary Holding Version
1
+ # MarkEdit-api
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Type definitions for the latest [MarkEdit](https://github.com/MarkEdit-app/MarkEdit) API.
4
+
5
+ ## References
6
+
7
+ - [MarkEdit Customization Guide](https://github.com/MarkEdit-app/MarkEdit/wiki/Customization)
8
+ - [MarkEdit Extensions](https://markedit-app.github.io/extensions/)
9
+ - [Example: Markdown Table Editor](https://github.com/MarkEdit-app/MarkEdit-mte)
10
+ - [Example: Text Highlight](https://github.com/MarkEdit-app/MarkEdit-highlight)
11
+ - [Example: Vue Language Package](https://github.com/MarkEdit-app/MarkEdit-lang-vue)
12
+
13
+ ## Usage
14
+
15
+ > The general workflow for creating a MarkEdit script involves leveraging [CodeMirror extensions](https://codemirror.net/docs/extensions/) or [Lezer parsers](https://lezer.codemirror.net/) to modify the app's behavior.
16
+
17
+ Add `markedit-api` to your (TypeScript) project's devDependencies:
18
+
19
+ ```json
20
+ {
21
+ "devDependencies": {
22
+ "markedit-api": "0.39.0"
23
+ }
24
+ }
25
+ ```
26
+
27
+ Import type declarations with:
28
+
29
+ ```ts
30
+ import { MarkEdit } from 'markedit-api';
31
+ ```
32
+
33
+ Refer to the [index.d.ts](index.d.ts) file for all available interfaces and type definitions.
34
+
35
+ Also, you can import and use [CodeMirror](https://codemirror.net/) and [Lezer](https://lezer.codemirror.net/) dependencies like this:
36
+
37
+ ```ts
38
+ import { keymap } from '@codemirror/view';
39
+ import { Prec } from '@codemirror/state';
40
+ import { Tag } from '@lezer/highlight';
41
+ import { MarkdownConfig } from '@lezer/markdown';
42
+ ```
43
+
44
+ Build [CodeMirror extension](https://codemirror.net/docs/extensions/) with these dependencies, and add it to MarkEdit with:
45
+
46
+ ```ts
47
+ MarkEdit.addExtension(extension); // Can also add an array of extensions
48
+ ```
49
+
50
+ Build [MarkdownConfig](https://github.com/lezer-parser/markdown?tab=readme-ov-file#user-content-markdownconfig) with these dependencies, and add it to MarkEdit with:
51
+
52
+ ```ts
53
+ MarkEdit.addMarkdownConfig(config);
54
+ ```
55
+
56
+ MarkEdit supports syntax highlighting for code blocks, you can also build your own [Language Package](https://codemirror.net/examples/lang-package/), and add it to MarkEdit with:
57
+
58
+ ```ts
59
+ MarkEdit.addCodeLanguage(language);
60
+ ```
61
+
62
+ > While extensions and configs can theoretically be added at any time, it is recommended that they be added immediately after loading the script.
63
+
64
+ ## Handling User Input
65
+
66
+ While you can certainly build user interfaces with JavaScript and CSS, leveraging native UI components might be a better option.
67
+
68
+ To create UI entries for your features, use `addMainMenuItem`, which adds an item to the "Extensions" submenu of the main menu, with keyboard shortcuts support.
69
+
70
+ To request user input, try using `showContextMenu`, `showAlert`, and `showTextBox`.
71
+
72
+ ## Building
73
+
74
+ In your build configuration, mark used MarkEdit and CodeMirror dependencies as `external`.
75
+
76
+ Here is an example of [vite](https://vitejs.dev/) config:
77
+
78
+ ```ts
79
+ import { defineConfig } from 'vite';
80
+
81
+ export default defineConfig({
82
+ build: {
83
+ rollupOptions: {
84
+ external: [
85
+ 'markedit-api',
86
+ '@codemirror/view',
87
+ '@codemirror/state',
88
+ // ...
89
+ ],
90
+ },
91
+ lib: {
92
+ entry: 'main.ts',
93
+ formats: ['cjs'], // CommonJS
94
+ },
95
+ },
96
+ });
97
+ ```
98
+
99
+ > Note: If you're using packages that are **not** supported in MarkEdit, such as leveraging [@codemirror/lang-vue](https://github.com/codemirror/lang-vue) to add syntax highlighting for Vue, they should **not** be marked as external.
100
+
101
+ It is recommended to build as [cjs](https://commonjs.org/), building as [umd](https://github.com/umdjs/umd) should work too. If you build it as an [iife](https://developer.mozilla.org/en-US/docs/Glossary/IIFE), make sure to replace imports as globals like this:
102
+
103
+ ```
104
+ rollupOptions: {
105
+ external: [
106
+ 'markedit-api',
107
+ '@codemirror/view',
108
+ '@codemirror/state',
109
+ ],
110
+ output: {
111
+ globals: {
112
+ 'markedit-api': 'MarkEdit',
113
+ '@codemirror/view': 'MarkEdit.codemirror.view',
114
+ '@codemirror/state': 'MarkEdit.codemirror.state',
115
+ },
116
+ },
117
+ },
118
+ ```
119
+
120
+ The reason is to ensure that user scripts and MarkEdit use the same modules, rather than being separately bundled from different projects.
121
+
122
+ The final step is to copy the built script to `~/Library/Containers/app.cyan.markedit/Data/Documents/scripts/`, and restart the app.
123
+
124
+ Ensure the build system produces a single JavaScript file. If the build generates multiple chunks, you can use [vite-plugin-singlefile](https://github.com/richardtallent/vite-plugin-singlefile) to bundle everything into one file.
125
+
126
+ > [!TIP]
127
+ > You can also use [MarkEdit-vite](https://github.com/MarkEdit-app/MarkEdit-vite) to simplify the workflow.
128
+
129
+ ## Using JavaScript
130
+
131
+ You can directly access CodeMirror and MarkEdit interfaces through objects assigned to the `MarkEdit` object. For example:
132
+
133
+ ```js
134
+ const keymap = MarkEdit.codemirror.view.keymap;
135
+ const editorAPI = MarkEdit.editorAPI;
136
+ ```
137
+
138
+ This is useful when you simply want to prototype something quickly.
package/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ const MarkEdit = Object.freeze({ /* stub */ });
2
+ exports.MarkEdit = MarkEdit;
package/index.d.cts ADDED
@@ -0,0 +1 @@
1
+ export * from './index.js';
package/index.d.ts ADDED
@@ -0,0 +1,982 @@
1
+ /**
2
+ * https://github.com/MarkEdit-app/MarkEdit-api
3
+ *
4
+ * - [MarkEdit Customization Guide](https://github.com/MarkEdit-app/MarkEdit/wiki/Customization)
5
+ * - [Example: Markdown Table Editor](https://github.com/MarkEdit-app/MarkEdit-mte)
6
+ * - [Example: Text Highlight](https://github.com/MarkEdit-app/MarkEdit-highlight)
7
+ * - [Example: Vue Language Package](https://github.com/MarkEdit-app/MarkEdit-lang-vue)
8
+ */
9
+
10
+ import type { EditorView } from '@codemirror/view';
11
+ import type { Extension } from '@codemirror/state';
12
+ import type { LanguageDescription, LanguageSupport } from '@codemirror/language';
13
+ import type { MarkdownConfig } from '@lezer/markdown';
14
+
15
+ import type * as cmView from '@codemirror/view';
16
+ import type * as cmState from '@codemirror/state';
17
+ import type * as cmLanguage from '@codemirror/language';
18
+ import type * as cmLangMarkdown from '@codemirror/lang-markdown';
19
+ import type * as cmCommands from '@codemirror/commands';
20
+ import type * as cmSearch from '@codemirror/search';
21
+ import type * as cmAutocomplete from '@codemirror/autocomplete';
22
+
23
+ import type * as lezerCommon from '@lezer/common';
24
+ import type * as lezerHighlight from '@lezer/highlight';
25
+ import type * as lezerMarkdown from '@lezer/markdown';
26
+ import type * as lezerLr from '@lezer/lr';
27
+
28
+ declare global {
29
+ /**
30
+ * File path of the current user script, or undefined if not applicable (e.g., in the DevTools console, which is not a user script context).
31
+ */
32
+ const __FILE_PATH__: string | undefined;
33
+ }
34
+
35
+ export const MarkEdit: Readonly<MarkEdit>;
36
+
37
+ export interface MarkEdit {
38
+ /**
39
+ * Configuration of the current editor.
40
+ */
41
+ editorConfig: EditorConfig;
42
+
43
+ /**
44
+ * User-defined settings loaded from the [settings.json](https://github.com/MarkEdit-app/MarkEdit/wiki/Customization#advanced-settings) file.
45
+ *
46
+ * For example, user-defined scripts can use this to provide additional configurations.
47
+ */
48
+ userSettings: JSONObject;
49
+
50
+ /**
51
+ * CodeMirror EditorView instance of the current editor.
52
+ */
53
+ editorView: EditorView;
54
+
55
+ /**
56
+ * Convenient text editing interfaces.
57
+ */
58
+ editorAPI: TextEditable;
59
+
60
+ /**
61
+ * Keychain-backed secret storage for the current script.
62
+ */
63
+ secretStorage: SecretStorage;
64
+
65
+ /**
66
+ * Retrieves a generative language model by name.
67
+ */
68
+ languageModel(name: LanguageModelName): LanguageModel;
69
+
70
+ /**
71
+ * Retrieves the system translation service.
72
+ */
73
+ translationService: TranslationService;
74
+
75
+ /**
76
+ * CodeMirror modules used by MarkEdit.
77
+ */
78
+ codemirror: {
79
+ /**
80
+ * The `@codemirror/view` module.
81
+ */
82
+ view: typeof cmView;
83
+
84
+ /**
85
+ * The `@codemirror/state` module.
86
+ */
87
+ state: typeof cmState;
88
+
89
+ /**
90
+ * The `@codemirror/language` module.
91
+ */
92
+ language: typeof cmLanguage;
93
+
94
+ /**
95
+ * The `@codemirror/lang-markdown` module.
96
+ */
97
+ langMarkdown: typeof cmLangMarkdown;
98
+
99
+ /**
100
+ * The `@codemirror/commands` module.
101
+ */
102
+ commands: typeof cmCommands;
103
+
104
+ /**
105
+ * The `@codemirror/search` module.
106
+ */
107
+ search: typeof cmSearch;
108
+
109
+ /**
110
+ * The `@codemirror/autocomplete` module.
111
+ */
112
+ autocomplete: typeof cmAutocomplete;
113
+ };
114
+
115
+ /**
116
+ * Lezer modules used by MarkEdit.
117
+ */
118
+ lezer: {
119
+ /**
120
+ * The `@lezer/common` module.
121
+ */
122
+ common: typeof lezerCommon;
123
+
124
+ /**
125
+ * The `@lezer/highlight` module.
126
+ */
127
+ highlight: typeof lezerHighlight;
128
+
129
+ /**
130
+ * The `@lezer/markdown` module.
131
+ */
132
+ markdown: typeof lezerMarkdown;
133
+
134
+ /**
135
+ * The `@lezer/lr` module.
136
+ */
137
+ lr: typeof lezerLr;
138
+ };
139
+
140
+ /**
141
+ * Get information about the runtime.
142
+ */
143
+ runtimeInfo(): RuntimeInfo;
144
+
145
+ /**
146
+ * Terminate the application. Unsaved changes will prompt for confirmation.
147
+ */
148
+ terminateApp(): void;
149
+
150
+ /**
151
+ * Relaunch the application. Unsaved changes will prompt for confirmation.
152
+ */
153
+ relaunchApp(): void;
154
+
155
+ /**
156
+ * Play the system beep.
157
+ */
158
+ playSystemBeep(): void;
159
+
160
+ /**
161
+ * Get notified when the app is ready.
162
+ *
163
+ * For a user script, this is ensured to be called only once during the app lifecycle.
164
+ * @param listener The callback function to be called when the app is ready.
165
+ */
166
+ onAppReady(listener: () => void): void;
167
+
168
+ /**
169
+ * Get notified when the editor is initialized.
170
+ * @param listener The callback function with the initialized editor instance.
171
+ */
172
+ onEditorReady(listener: (editorView: EditorView) => void): void;
173
+
174
+ /**
175
+ * Get notified when the editor configuration changes.
176
+ * @param listener The callback function with the changed key and new value.
177
+ */
178
+ onEditorConfigChange(listener: (key: EditorConfigChange[0], value: EditorConfigChange[1]) => void): void;
179
+
180
+ /**
181
+ * Open a plain text file in MarkEdit, or focus it if already open.
182
+ * @param path The file path.
183
+ * @param options Where to open the document.
184
+ * @returns True on success; false on failure, without external fallback.
185
+ */
186
+ openDocument(path: string, options?: { target?: 'automatic' | 'window' | 'tab' }): Promise<boolean>;
187
+
188
+ /**
189
+ * Save the current document to disk.
190
+ * @returns True if the document was successfully saved.
191
+ */
192
+ saveDocument(): Promise<boolean>;
193
+
194
+ /**
195
+ * Close the current document.
196
+ * @returns True if the document was successfully closed.
197
+ */
198
+ closeDocument(): Promise<boolean>;
199
+
200
+ /**
201
+ * Get the paths of recently opened documents, sorted most recent first.
202
+ * @returns The file-system paths, or an empty array if there are no recent documents.
203
+ */
204
+ recentDocumentPaths(): Promise<string[]>;
205
+
206
+ /**
207
+ * Open a file in the file system.
208
+ * @param path The file path.
209
+ * @returns True if the file was successfully opened.
210
+ */
211
+ openFile(path: string): Promise<boolean>;
212
+
213
+ /**
214
+ * Create a file in the file system.
215
+ * @param options The options, including path and content.
216
+ * @returns True if the file was successfully created.
217
+ */
218
+ createFile(options: CreateFileOptions): Promise<boolean>;
219
+
220
+ /**
221
+ * Delete a file from the file system.
222
+ * @param path The file path.
223
+ * @returns True if the file was successfully deleted.
224
+ */
225
+ deleteFile(path: string): Promise<boolean>;
226
+
227
+ /**
228
+ * Move a file in the file system.
229
+ * @param options The source and destination paths.
230
+ * @returns True if the file was successfully moved.
231
+ */
232
+ moveFile(options: MoveFileOptions): Promise<boolean>;
233
+
234
+ /**
235
+ * Reveal a file in Finder.
236
+ * @param path The file path. The current file is used as a fallback.
237
+ * @returns True if the file was successfully revealed.
238
+ */
239
+ revealFile(path?: string): Promise<boolean>;
240
+
241
+ /**
242
+ * List all files under a directory.
243
+ * @param path The directory path.
244
+ * @returns All file names as a string array, or undefined if failed.
245
+ */
246
+ listFiles(path: string): Promise<string[] | undefined>;
247
+
248
+ /**
249
+ * Get the content of a file.
250
+ * @param path The file path. The current file is used as a fallback.
251
+ * @returns The file content as a string, or undefined if failed.
252
+ */
253
+ getFileContent(path?: string): Promise<string | undefined>;
254
+
255
+ /**
256
+ * Get the binary data and type information of a file.
257
+ * @param path The file path. The current file is used as a fallback.
258
+ * @returns The file object, or undefined if failed.
259
+ */
260
+ getFileObject(path?: string): Promise<FileObject | undefined>;
261
+
262
+ /**
263
+ * Get the information of a file.
264
+ * @param path The file path. The current file is used as a fallback.
265
+ * @returns The file information, or undefined if not found.
266
+ */
267
+ getFileInfo(path?: string): Promise<FileInfo | undefined>;
268
+
269
+ /**
270
+ * Get the path of a standard directory.
271
+ * @param type The directory type.
272
+ * @returns The directory path.
273
+ */
274
+ getDirectoryPath(type: DirectoryType): string;
275
+
276
+ /**
277
+ * Get all available versions of the current document, sorted newest to oldest.
278
+ * @returns The list of file versions, or an empty array if no versions are available.
279
+ */
280
+ getFileVersions(): Promise<FileVersion[]>;
281
+
282
+ /**
283
+ * Get the text content of a specific file version.
284
+ * @param id The unique identifier of the version.
285
+ * @returns The text content, or undefined if the version is not found.
286
+ */
287
+ getFileVersionContent(id: string): Promise<string | undefined>;
288
+
289
+ /**
290
+ * Restore the document to a specific file version.
291
+ * @param id The unique identifier of the version.
292
+ * @returns True if the version was successfully restored.
293
+ */
294
+ restoreFileVersion(id: string): Promise<boolean>;
295
+
296
+ /**
297
+ * Delete specific file versions, this works for local versions only.
298
+ * @param ids The unique identifiers of the versions to delete.
299
+ * @returns True if the versions were successfully deleted.
300
+ */
301
+ deleteLocalFileVersions(ids: string[]): Promise<boolean>;
302
+
303
+ /**
304
+ * Get all items from the native pasteboard.
305
+ * @returns The items from the native (general) pasteboard.
306
+ */
307
+ getPasteboardItems(): Promise<PasteboardItem[]>;
308
+
309
+ /**
310
+ * Get the string from the native pasteboard.
311
+ * @returns The string from the native (general) pasteboard, if applicable.
312
+ */
313
+ getPasteboardString(): Promise<string | undefined>;
314
+
315
+ /**
316
+ * Add an extension to MarkEdit.
317
+ * @param extension CodeMirror extension.
318
+ */
319
+ addExtension(extension: Extension): void;
320
+
321
+ /**
322
+ * Add a Markdown config to MarkEdit.
323
+ * @param config Markdown config.
324
+ */
325
+ addMarkdownConfig(config: MarkdownConfig | MarkdownConfig[]): void;
326
+
327
+ /**
328
+ * Add a language to be highlighted (in code blocks) to MarkEdit.
329
+ * @param language The language description.
330
+ */
331
+ addCodeLanguage(language: LanguageDescription | LanguageDescription[]): void;
332
+
333
+ /**
334
+ * Override the built-in HTML language.
335
+ * @param provider A function that returns a LanguageSupport instance for HTML.
336
+ */
337
+ overrideHTMLLanguage(provider: (config?: { matchClosingTags?: boolean }) => LanguageSupport): void;
338
+
339
+ /**
340
+ * Add a menu item to the status bar.
341
+ * @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.
342
+ */
343
+ addMainMenuItem(item: MenuItem | MenuItem[]): void;
344
+
345
+ /**
346
+ * Present a contextual menu to receive user input.
347
+ * @param items The items in the menu.
348
+ * @param location The location to show the menu, with the default value set to the caret position.
349
+ * @param options The menu's presentation behavior.
350
+ */
351
+ showContextMenu(items: MenuItem[], location?: Point, options?: ContextMenuOptions): void;
352
+
353
+ /**
354
+ * Present an alert to receive user input.
355
+ * @param alert The alert to present.
356
+ * @returns The index of the chosen button, 0-indexed.
357
+ */
358
+ showAlert(alert: Alert): Promise<number>;
359
+
360
+ /**
361
+ * Present a text box to receive user input.
362
+ * @param textBox The text box to present.
363
+ * @returns The input string, or undefined if no value is provided.
364
+ */
365
+ showTextBox(textBox?: TextBox): Promise<string | undefined>;
366
+
367
+ /**
368
+ * Present an open panel for selecting files or folders without opening them.
369
+ * @param options The panel information and selection behavior.
370
+ * @returns A nonempty array of absolute file paths, or undefined if cancelled or failed.
371
+ */
372
+ showOpenPanel(options?: OpenPanelOptions): Promise<string[] | undefined>;
373
+
374
+ /**
375
+ * Present a save panel for saving the file.
376
+ * @param options The panel information, including the data and optionally a default file name.
377
+ * @returns True if the file was successfully saved.
378
+ */
379
+ showSavePanel(options: SavePanelOptions): Promise<boolean>;
380
+
381
+ /**
382
+ * Present the print panel for content of a supported type.
383
+ * @param options The content to print and optionally a job title.
384
+ * @returns True if the print operation was accepted.
385
+ */
386
+ showPrintPanel(options: PrintPanelOptions): Promise<boolean>;
387
+
388
+ /**
389
+ * Run a [system service](https://support.apple.com/guide/mac-help/mchlp1012/mac) with input.
390
+ * @param name The name of the system service.
391
+ * @param input The input to pass to the service.
392
+ * @returns True if the service performed successfully.
393
+ */
394
+ runService(name: string, input?: string): Promise<boolean>;
395
+ }
396
+
397
+ export interface EditorConfig {
398
+ theme: string;
399
+ fontFace: { family: string; weight?: string; style?: string; };
400
+ fontSize: number;
401
+ showLineNumbers: boolean;
402
+ showActiveLineIndicator: boolean;
403
+ invisiblesBehavior: 'never' | 'selection' | 'trailing' | 'always';
404
+ readOnlyMode: boolean;
405
+ typewriterMode: boolean;
406
+ focusMode: boolean;
407
+ lineWrapping: boolean;
408
+ lineHeight: number;
409
+ suggestWhileTyping: boolean;
410
+ standardDirectories: { [key: string]: string };
411
+ runtimeInfo?: RuntimeInfo;
412
+ defaultLineBreak?: string;
413
+ tabKeyBehavior?: number;
414
+ indentUnit?: string;
415
+ smartQuotesEnabled: boolean;
416
+ }
417
+
418
+ export type EditorConfigChange = {
419
+ [Key in keyof EditorConfig]-?: [key: Key, value: EditorConfig[Key]];
420
+ }[keyof EditorConfig];
421
+
422
+ /**
423
+ * Information about the runtime.
424
+ */
425
+ export type RuntimeInfo = {
426
+ /**
427
+ * Application version, such as `1.0`.
428
+ */
429
+ appVersion: string;
430
+
431
+ /**
432
+ * Application build number, such as `100`.
433
+ */
434
+ appBuild: string;
435
+
436
+ /**
437
+ * Operating system version, such as `15.0`.
438
+ */
439
+ osVersion: string;
440
+
441
+ /**
442
+ * WebKit version, such as `620.1.16`.
443
+ */
444
+ webkitVersion: string;
445
+ };
446
+
447
+ /**
448
+ * Abstract editor to provide convenient text editing interfaces.
449
+ */
450
+ export interface TextEditable {
451
+ /**
452
+ * Get text of the document.
453
+ * @param range The range of the text. If no range is provided, the entire document is returned.
454
+ */
455
+ getText(range?: TextRange): string;
456
+
457
+ /**
458
+ * Set text for the document.
459
+ * @param text The text to set.
460
+ * @param range The range of the text. If no range is provided, the entire document is overwritten.
461
+ */
462
+ setText(text: string, range?: TextRange): void;
463
+
464
+ /**
465
+ * Get text selections.
466
+ */
467
+ getSelections(): TextRange[];
468
+
469
+ /**
470
+ * Set text selections.
471
+ * @param ranges Text ranges to set.
472
+ */
473
+ setSelections(ranges: TextRange[]): void;
474
+
475
+ /**
476
+ * Get the line number (0-indexed) of given text position.
477
+ * @param position The text position.
478
+ */
479
+ getLineNumber(position: number): number;
480
+
481
+ /**
482
+ * Get line range of given row (0-indexed).
483
+ * @param row The line number.
484
+ */
485
+ getLineRange(row: number): TextRange;
486
+
487
+ /**
488
+ * Get number of lines.
489
+ */
490
+ getLineCount(): number;
491
+
492
+ /**
493
+ * Get line separator.
494
+ */
495
+ getLineBreak(): string;
496
+
497
+ /**
498
+ * Get CodeMirror syntax node name of given position.
499
+ * @param position The text position.
500
+ */
501
+ getNodeName(position: number): string;
502
+
503
+ /**
504
+ * Undo a change.
505
+ */
506
+ undo(): void;
507
+
508
+ /**
509
+ * Redo a change.
510
+ */
511
+ redo(): void;
512
+ }
513
+
514
+ /**
515
+ * Secret storage in macOS Keychain, each extension has its own store.
516
+ *
517
+ * Reading a secret requires MarkEdit confirmation to provide context to the user.
518
+ * macOS may separately require authentication for any operation.
519
+ *
520
+ * Operations reject if the user denies or cancels access, no script context is available, or storage fails.
521
+ */
522
+ export interface SecretStorage {
523
+ /**
524
+ * Check whether a secret exists without retrieving its value or showing MarkEdit confirmation.
525
+ * @returns True if the secret exists, or false only if it does not exist.
526
+ */
527
+ has(key: string): Promise<boolean>;
528
+
529
+ /**
530
+ * Get a secret after native confirmation showing its key, script identity, and script path.
531
+ *
532
+ * Each call requires approval before accessing Keychain.
533
+ * @returns The secret, or undefined only if it does not exist.
534
+ */
535
+ get(key: string): Promise<string | undefined>;
536
+
537
+ /**
538
+ * Store or replace a secret.
539
+ */
540
+ set(key: string, value: string): Promise<void>;
541
+
542
+ /**
543
+ * Delete a secret.
544
+ * @returns True if deleted, or false only if the secret did not exist.
545
+ */
546
+ delete(key: string): Promise<boolean>;
547
+ }
548
+
549
+ /**
550
+ * Unique identifier of a generative language model.
551
+ *
552
+ * `Private-Cloud-Compute` works in macOS 27.0 and later.
553
+ */
554
+ export type LanguageModelName = 'Apple-Foundation-Models' | 'Private-Cloud-Compute';
555
+
556
+ /**
557
+ * Response of a language model content generation.
558
+ *
559
+ * For non-streaming scenarios, `done` is always true.
560
+ */
561
+ export type LanguageModelResponse = {
562
+ content?: string;
563
+ error?: string;
564
+ done: boolean;
565
+ };
566
+
567
+ /**
568
+ * Response notifier for language model streaming responses.
569
+ */
570
+ export type LanguageModelStream = (response: LanguageModelResponse) => void;
571
+
572
+ /**
573
+ * Interfaces for a generative language model.
574
+ */
575
+ export interface LanguageModel {
576
+ /**
577
+ * Check the language model availability.
578
+ */
579
+ availability(): Promise<LanguageModelAvailability>;
580
+
581
+ /**
582
+ * Create a new language model session.
583
+ */
584
+ createSession(options?: { instructions?: string }): Promise<LanguageModelSession>;
585
+ }
586
+
587
+ /**
588
+ * Generative language model session.
589
+ */
590
+ export interface LanguageModelSession {
591
+ /**
592
+ * Indicates a response is being generated.
593
+ */
594
+ isResponding(): Promise<boolean>;
595
+
596
+ /**
597
+ * Produces a response to a prompt.
598
+ */
599
+ respondTo(prompt: string, options?: LanguageModelGenerationOptions): Promise<LanguageModelResponse>;
600
+
601
+ /**
602
+ * Produces a response stream to a prompt.
603
+ *
604
+ * Each update delivers the latest snapshot of the content, not partial chunks.
605
+ */
606
+ streamResponseTo(
607
+ prompt: string,
608
+ options: LanguageModelGenerationOptions | LanguageModelStream,
609
+ stream?: LanguageModelStream,
610
+ ): void;
611
+ }
612
+
613
+ export type LanguageModelAvailability = {
614
+ isAvailable: boolean;
615
+ unavailableReason?: string;
616
+ };
617
+
618
+ export type LanguageModelGenerationOptions = {
619
+ /**
620
+ * In macOS 27.0 and later, provide attachments to the language model.
621
+ */
622
+ attachments?: FileObject[];
623
+ sampling?: LanguageModelSampling;
624
+ temperature?: number;
625
+ maximumResponseTokens?: number;
626
+ };
627
+
628
+ export type LanguageModelSampling =
629
+ | { mode: 'greedy' }
630
+ | { mode: 'top-k' | 'top-p'; value: number; seed?: number };
631
+
632
+ /**
633
+ * The system translation service.
634
+ */
635
+ export interface TranslationService {
636
+ /**
637
+ * Translate the text with language pair.
638
+ *
639
+ * Use BCP-47 language tags, such as `en-US`, `zh-CN`.
640
+ */
641
+ translate(text: string, languages?: { from?: string; to?: string }): Promise<TranslationResponse>;
642
+ }
643
+
644
+ export type TranslationResponse =
645
+ | { succeeded: true; text: string }
646
+ | { succeeded: false; error: string };
647
+
648
+ /**
649
+ * Represents a file object with data and type information.
650
+ */
651
+ export type FileObject = {
652
+ /**
653
+ * Base64 representation of the file.
654
+ */
655
+ data: string;
656
+
657
+ /**
658
+ * Uniform Type Identifier (UTI) of the file.
659
+ */
660
+ typeIdentifier?: string;
661
+
662
+ /**
663
+ * MIME type of the file.
664
+ */
665
+ mimeType?: string;
666
+
667
+ /**
668
+ * File extension of the file.
669
+ */
670
+ filenameExtension?: string;
671
+ }
672
+
673
+ /**
674
+ * Information of a file in the file system.
675
+ */
676
+ export type FileInfo = {
677
+ filePath: string;
678
+ fileSize: number;
679
+ creationDate: Date;
680
+ modificationDate: Date;
681
+ parentPath: string;
682
+ isDirectory: boolean;
683
+ };
684
+
685
+ /**
686
+ * Represents a native pasteboard item.
687
+ */
688
+ export type PasteboardItem = {
689
+ /**
690
+ * Type name, such as `public.utf8-plain-text`.
691
+ */
692
+ type: string;
693
+
694
+ /**
695
+ * Base64 representation of the pasteboard data.
696
+ */
697
+ data: string;
698
+
699
+ /**
700
+ * String representation of the pasteboard data, if applicable.
701
+ */
702
+ string?: string;
703
+ };
704
+
705
+ /**
706
+ * Represents a portion of text.
707
+ */
708
+ export type TextRange = {
709
+ from: number;
710
+ to: number;
711
+ };
712
+
713
+ /**
714
+ * Represents a menu item in native menus.
715
+ */
716
+ export type MenuItem = {
717
+ title?: string;
718
+ action?: () => void;
719
+ state?: () => MenuItemState;
720
+
721
+ /**
722
+ * Icon for the item.
723
+ *
724
+ * This can be either a base64 string or a SF Symbol name.
725
+ */
726
+ icon?: string;
727
+
728
+ /**
729
+ * Whether an item is a separator used to logically group other items.
730
+ */
731
+ separator?: boolean;
732
+
733
+ /**
734
+ * Key equivalent of the action.
735
+ */
736
+ key?: string;
737
+
738
+ /**
739
+ * Key modifiers of the action. Valid values are `Shift`, `Control`, `Command`, and `Option`.
740
+ *
741
+ * The order does not matter but they are case sensitive.
742
+ *
743
+ * When `key` is uppercase, `Shift` is automatically enabled.
744
+ */
745
+ modifiers?: ('Shift' | 'Control' | 'Command' | 'Option')[];
746
+
747
+ /**
748
+ * Child items to build a submenu.
749
+ */
750
+ children?: MenuItem[];
751
+ };
752
+
753
+ /**
754
+ * Represents the state of a menu item.
755
+ */
756
+ export type MenuItemState = {
757
+ /**
758
+ * Whether enabled; defaults to true.
759
+ */
760
+ isEnabled?: boolean;
761
+ /**
762
+ * Whether selected; defaults to false.
763
+ */
764
+ isSelected?: boolean;
765
+ };
766
+
767
+ /**
768
+ * Represents a location on the screen.
769
+ */
770
+ export type Point = {
771
+ x: number;
772
+ y: number;
773
+ };
774
+
775
+ /**
776
+ * Represents options to present a contextual menu.
777
+ */
778
+ export type ContextMenuOptions = {
779
+ /**
780
+ * Index of the item to highlight when the menu opens (zero-based).
781
+ *
782
+ * If omitted, invalid, or pointing to a separator or disabled item,
783
+ * the menu opens without an initial highlight.
784
+ */
785
+ highlightedIndex?: number;
786
+ };
787
+
788
+ /**
789
+ * Represents a native alert to present.
790
+ *
791
+ * If it's a string, it will be used as the title.
792
+ */
793
+ export type Alert = {
794
+ /**
795
+ * The title that is displayed prominently in the alert.
796
+ */
797
+ title?: string;
798
+
799
+ /**
800
+ * The informative message for more details.
801
+ */
802
+ message?: string;
803
+
804
+ /**
805
+ * The button titles.
806
+ */
807
+ buttons?: string[];
808
+ } | string;
809
+
810
+ /**
811
+ * Represents a text box to receive input.
812
+ *
813
+ * If it's a string, it will be used as the title.
814
+ */
815
+ export type TextBox = {
816
+ title?: string;
817
+ placeholder?: string;
818
+ defaultValue?: string;
819
+ } | string;
820
+
821
+ /**
822
+ * Represents options to create a file.
823
+ */
824
+ export type CreateFileOptions = {
825
+ /**
826
+ * File path.
827
+ */
828
+ path: string;
829
+
830
+ /**
831
+ * If set to true, a directory will be created instead.
832
+ */
833
+ isDirectory?: boolean;
834
+
835
+ /**
836
+ * If set to true, existing files with the same path will be overwritten.
837
+ */
838
+ overwrites?: boolean;
839
+
840
+ /**
841
+ * String representation of the file, if applicable.
842
+ */
843
+ string?: string;
844
+
845
+ /**
846
+ * Base64 representation of the file, if applicable.
847
+ */
848
+ data?: string;
849
+ };
850
+
851
+ /**
852
+ * Represents options to move a file.
853
+ */
854
+ export type MoveFileOptions = {
855
+ /**
856
+ * Source file path.
857
+ */
858
+ source: string;
859
+
860
+ /**
861
+ * Destination file path.
862
+ */
863
+ destination: string;
864
+
865
+ /**
866
+ * If set to true, existing files at the destination will be overwritten.
867
+ */
868
+ overwrites?: boolean;
869
+ };
870
+
871
+ /**
872
+ * Represents standard directory types.
873
+ */
874
+ export type DirectoryType = 'home' | 'documents' | 'library' | 'caches' | 'temporary' | 'sharedContainer';
875
+
876
+ /**
877
+ * Represents options to show the open panel.
878
+ */
879
+ export type OpenPanelOptions = {
880
+ /**
881
+ * Panel title. Uses the system default if omitted.
882
+ */
883
+ title?: string;
884
+
885
+ /**
886
+ * Instructions displayed in the panel.
887
+ */
888
+ message?: string;
889
+
890
+ /**
891
+ * Confirmation button label. Uses the system default if omitted.
892
+ */
893
+ prompt?: string;
894
+
895
+ /**
896
+ * Types of items that can be selected. Defaults to 'files'.
897
+ */
898
+ selectionType?: 'files' | 'directories' | 'both';
899
+
900
+ /**
901
+ * Allow selecting multiple items. Defaults to false.
902
+ */
903
+ allowsMultipleSelection?: boolean;
904
+ };
905
+
906
+ /**
907
+ * Represents options to show the save panel.
908
+ */
909
+ export type SavePanelOptions = {
910
+ /**
911
+ * String representation of the file, if applicable.
912
+ */
913
+ string?: string;
914
+
915
+ /**
916
+ * Base64 representation of the file, if applicable.
917
+ */
918
+ data?: string;
919
+
920
+ /**
921
+ * Default file name.
922
+ */
923
+ fileName?: string;
924
+ };
925
+
926
+ /**
927
+ * Represents options to show the print panel for content of a supported type.
928
+ */
929
+ export type PrintPanelOptions = {
930
+ /**
931
+ * Content type to print. Currently only PDF is supported.
932
+ */
933
+ type: 'pdf';
934
+
935
+ /**
936
+ * Base64 representation of the content to print. For 'pdf', this is PDF data.
937
+ */
938
+ data: string;
939
+
940
+ /**
941
+ * Job title shown in the print panel and print queue.
942
+ */
943
+ title?: string;
944
+ };
945
+
946
+ /**
947
+ * Represents a historical version of the current document.
948
+ */
949
+ export type FileVersion = {
950
+ /**
951
+ * Unique identifier for this version, valid for the current session.
952
+ */
953
+ id: string;
954
+
955
+ /**
956
+ * Modification date of this version.
957
+ */
958
+ modificationDate: Date;
959
+
960
+ /**
961
+ * Whether this version is stored locally or in iCloud.
962
+ */
963
+ isLocal: boolean;
964
+ };
965
+
966
+ /**
967
+ * Typed JSON value.
968
+ */
969
+ type JSONValue =
970
+ | string
971
+ | number
972
+ | boolean
973
+ | null
974
+ | JSONObject
975
+ | JSONValue[];
976
+
977
+ /**
978
+ * Typed JSON Object.
979
+ */
980
+ type JSONObject = {
981
+ [key: string]: JSONValue;
982
+ };
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ const MarkEdit = Object.freeze({ /* stub */ });
2
+ export { MarkEdit };
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "markedit-api",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.39.0",
4
+ "description": "Type definitions for the latest MarkEdit API.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/MarkEdit-app/MarkEdit-api.git"
8
+ },
9
+ "files": [
10
+ "index.js",
11
+ "index.cjs",
12
+ "index.d.ts",
13
+ "index.d.cts"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public",
17
+ "registry": "https://registry.npmjs.org"
18
+ },
19
+ "type": "module",
20
+ "main": "./index.cjs",
21
+ "module": "./index.js",
22
+ "types": "./index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "types": "./index.d.ts",
27
+ "default": "./index.js"
28
+ },
29
+ "require": {
30
+ "types": "./index.d.cts",
31
+ "default": "./index.cjs"
32
+ }
33
+ }
34
+ },
35
+ "license": "MIT",
36
+ "peerDependencies": {
37
+ "@codemirror/autocomplete": "^6.0.0",
38
+ "@codemirror/commands": "^6.0.0",
39
+ "@codemirror/lang-markdown": "^6.0.0",
40
+ "@codemirror/language": "^6.0.0",
41
+ "@codemirror/search": "^6.0.0",
42
+ "@codemirror/state": "^6.0.0",
43
+ "@codemirror/view": "^6.0.0",
44
+ "@lezer/common": "^1.0.0",
45
+ "@lezer/highlight": "^1.0.0",
46
+ "@lezer/lr": "^1.0.0",
47
+ "@lezer/markdown": "^1.0.0"
48
+ }
49
+ }