Repository navigation
Expand file tree
/
Copy pathindex.d.ts
More file actions
1121 lines (960 loc) · 27 KB
/
Copy pathindex.d.ts
File metadata and controls
1121 lines (960 loc) · 27 KB
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* 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, LanguageSupport } 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 cmLangMarkdown from '@codemirror/lang-markdown';
import type * as cmCommands from '@codemirror/commands';
import type * as cmSearch from '@codemirror/search';
import type * as cmAutocomplete from '@codemirror/autocomplete';
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';
declare global {
/**
* 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).
*/
const __FILE_PATH__: string | undefined;
}
export const MarkEdit: Readonly<MarkEdit>;
export interface MarkEdit {
/**
* Configuration of the current editor.
*/
editorConfig: EditorConfig;
/**
* User-defined settings loaded from the [settings.json](https://github.com/MarkEdit-app/MarkEdit/wiki/Customization#advanced-settings) file.
*
* For example, user-defined scripts can use this to provide additional configurations.
*/
userSettings: JSONObject;
/**
* CodeMirror EditorView instance of the current editor.
*/
editorView: EditorView;
/**
* Convenient text editing interfaces.
*/
editorAPI: TextEditable;
/**
* Keychain-backed secret storage for the current script.
*/
secretStorage: SecretStorage;
/**
* Retrieves a generative language model by name.
*/
languageModel(name: LanguageModelName): LanguageModel;
/**
* Retrieves the system translation service.
*/
translationService: TranslationService;
/**
* 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/lang-markdown` module.
*/
langMarkdown: typeof cmLangMarkdown;
/**
* The `@codemirror/commands` module.
*/
commands: typeof cmCommands;
/**
* The `@codemirror/search` module.
*/
search: typeof cmSearch;
/**
* The `@codemirror/autocomplete` module.
*/
autocomplete: typeof cmAutocomplete;
};
/**
* 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 information about the runtime.
*/
runtimeInfo(): RuntimeInfo;
/**
* Terminate the application. Unsaved changes will prompt for confirmation.
*/
terminateApp(): void;
/**
* Relaunch the application. Unsaved changes will prompt for confirmation.
*/
relaunchApp(): void;
/**
* Play the system beep.
*/
playSystemBeep(): void;
/**
* Get notified when the app is ready.
*
* For a user script, this is ensured to be called only once during the app lifecycle.
* @param listener The callback function to be called when the app is ready.
*/
onAppReady(listener: () => void): void;
/**
* Get notified when the editor is initialized.
* @param listener The callback function with the initialized editor instance.
*/
onEditorReady(listener: (editorView: EditorView) => void): void;
/**
* Get notified when the editor configuration changes.
* @param listener The callback function with the changed key and new value.
*/
onEditorConfigChange(listener: (key: EditorConfigChange[0], value: EditorConfigChange[1]) => void): void;
/**
* Open a plain text file in MarkEdit, or focus it if already open.
* @param path The file path.
* @param options Where to open the document.
* @returns True on success; false on failure, without external fallback.
*/
openDocument(path: string, options?: { target?: 'automatic' | 'window' | 'tab' }): Promise<boolean>;
/**
* Save the current document to disk.
* @returns True if the document was successfully saved.
*/
saveDocument(): Promise<boolean>;
/**
* Close the current document.
* @returns True if the document was successfully closed.
*/
closeDocument(): Promise<boolean>;
/**
* Get the paths of recently opened documents, sorted most recent first.
* @returns The file-system paths, or an empty array if there are no recent documents.
*/
recentDocumentPaths(): Promise<string[]>;
/**
* Open a file in the file system.
* @param path The file path.
* @returns True if the file was successfully opened.
*/
openFile(path: string): Promise<boolean>;
/**
* Create a file in the file system.
* @param options The options, including path and content.
* @returns True if the file was successfully created.
*/
createFile(options: CreateFileOptions): Promise<boolean>;
/**
* Delete a file from the file system.
* @param path The file path.
* @returns True if the file was successfully deleted.
*/
deleteFile(path: string): Promise<boolean>;
/**
* Move a file in the file system.
* @param options The source and destination paths.
* @returns True if the file was successfully moved.
*/
moveFile(options: MoveFileOptions): Promise<boolean>;
/**
* Reveal a file in Finder.
* @param path The file path. The current file is used as a fallback.
* @returns True if the file was successfully revealed.
*/
revealFile(path?: string): Promise<boolean>;
/**
* List all files under a directory.
* @param path The directory path.
* @returns All file names as a string array, or undefined if failed.
*/
listFiles(path: string): Promise<string[] | undefined>;
/**
* Get the content of a file.
* @param path The file path. The current file is used as a fallback.
* @returns The file content as a string, or undefined if failed.
*/
getFileContent(path?: string): Promise<string | undefined>;
/**
* Get the binary data and type information of a file.
* @param path The file path. The current file is used as a fallback.
* @returns The file object, or undefined if failed.
*/
getFileObject(path?: string): Promise<FileObject | undefined>;
/**
* Get the information of a file.
* @param path The file path. The current file is used as a fallback.
* @returns The file information, or undefined if not found.
*/
getFileInfo(path?: string): Promise<FileInfo | undefined>;
/**
* Get the path of a standard directory.
* @param type The directory type.
* @returns The directory path.
*/
getDirectoryPath(type: DirectoryType): string;
/**
* Get all available versions of the current document, sorted newest to oldest.
* @returns The list of file versions, or an empty array if no versions are available.
*/
getFileVersions(): Promise<FileVersion[]>;
/**
* Get the text content of a specific file version.
* @param id The unique identifier of the version.
* @returns The text content, or undefined if the version is not found.
*/
getFileVersionContent(id: string): Promise<string | undefined>;
/**
* Restore the document to a specific file version.
* @param id The unique identifier of the version.
* @returns True if the version was successfully restored.
*/
restoreFileVersion(id: string): Promise<boolean>;
/**
* Delete specific file versions, this works for local versions only.
* @param ids The unique identifiers of the versions to delete.
* @returns True if the versions were successfully deleted.
*/
deleteLocalFileVersions(ids: string[]): Promise<boolean>;
/**
* 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 | MarkdownConfig[]): void;
/**
* Add a language to be highlighted (in code blocks) to MarkEdit.
* @param language The language description.
*/
addCodeLanguage(language: LanguageDescription | LanguageDescription[]): void;
/**
* Override the built-in HTML language.
* @param provider A function that returns a LanguageSupport instance for HTML.
*/
overrideHTMLLanguage(provider: (config?: { matchClosingTags?: boolean }) => LanguageSupport): void;
/**
* Declare a main-menu item once, synchronously when your script runs.
* @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;
/**
* Register a toolbar item once, synchronously when your script runs.
* @param item The toolbar item to register, or an array of items.
*/
addToolbarItem(item: ToolbarItem | ToolbarItem[]): void;
/**
* Refresh state for an item and its segments or menu entries in the current editor.
* Button and menu state getters can also override the item's title and icon.
* Call for changes outside toolbar actions or after async work.
* Unknown IDs are logged and ignored.
*/
invalidateToolbarItem(id: string): 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.
* @param options The menu's presentation behavior.
*/
showContextMenu(items: MenuItem[], location?: Point, options?: ContextMenuOptions): 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>;
/**
* Present an open panel for selecting files or folders without opening them.
* @param options The panel information and selection behavior.
* @returns A nonempty array of absolute file paths, or undefined if cancelled or failed.
*/
showOpenPanel(options?: OpenPanelOptions): Promise<string[] | undefined>;
/**
* Present a save panel for saving the file.
* @param options The panel information, including the data and optionally a default file name.
* @returns True if the file was successfully saved.
*/
showSavePanel(options: SavePanelOptions): Promise<boolean>;
/**
* Present the print panel for content of a supported type.
* @param options The content to print and optionally a job title.
* @returns True if the print operation was accepted.
*/
showPrintPanel(options: PrintPanelOptions): Promise<boolean>;
/**
* Run a [system service](https://support.apple.com/guide/mac-help/mchlp1012/mac) with input.
* @param name The name of the system service.
* @param input The input to pass to the service.
* @returns True if the service performed successfully.
*/
runService(name: string, input?: string): Promise<boolean>;
}
export interface EditorConfig {
theme: string;
fontFace: { family: string; weight?: string; style?: string; };
fontSize: number;
showLineNumbers: boolean;
showActiveLineIndicator: boolean;
invisiblesBehavior: 'never' | 'selection' | 'trailing' | 'always';
readOnlyMode: boolean;
typewriterMode: boolean;
focusMode: boolean;
lineWrapping: boolean;
lineHeight: number;
suggestWhileTyping: boolean;
standardDirectories: { [key: string]: string };
runtimeInfo?: RuntimeInfo;
defaultLineBreak?: string;
tabKeyBehavior?: number;
indentUnit?: string;
smartQuotesEnabled: boolean;
}
export type EditorConfigChange = {
[Key in keyof EditorConfig]-?: [key: Key, value: EditorConfig[Key]];
}[keyof EditorConfig];
/**
* Information about the runtime.
*/
export type RuntimeInfo = {
/**
* Application version, such as `1.0`.
*/
appVersion: string;
/**
* Application build number, such as `100`.
*/
appBuild: string;
/**
* Operating system version, such as `15.0`.
*/
osVersion: string;
/**
* WebKit version, such as `620.1.16`.
*/
webkitVersion: string;
};
/**
* 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;
}
/**
* Secret storage in macOS Keychain, each extension has its own store.
*
* Reading a secret requires MarkEdit confirmation to provide context to the user.
* macOS may separately require authentication for any operation.
*
* Operations reject if the user denies or cancels access, no script context is available, or storage fails.
*/
export interface SecretStorage {
/**
* Check whether a secret exists without retrieving its value or showing MarkEdit confirmation.
* @returns True if the secret exists, or false only if it does not exist.
*/
has(key: string): Promise<boolean>;
/**
* Get a secret after native confirmation showing its key, script identity, and script path.
*
* Each call requires approval before accessing Keychain.
* @returns The secret, or undefined only if it does not exist.
*/
get(key: string): Promise<string | undefined>;
/**
* Store or replace a secret.
*/
set(key: string, value: string): Promise<void>;
/**
* Delete a secret.
* @returns True if deleted, or false only if the secret did not exist.
*/
delete(key: string): Promise<boolean>;
}
/**
* Unique identifier of a generative language model.
*
* `Private-Cloud-Compute` works in macOS 27.0 and later.
*/
export type LanguageModelName = 'Apple-Foundation-Models' | 'Private-Cloud-Compute';
/**
* Response of a language model content generation.
*
* For non-streaming scenarios, `done` is always true.
*/
export type LanguageModelResponse = {
content?: string;
error?: string;
done: boolean;
};
/**
* Response notifier for language model streaming responses.
*/
export type LanguageModelStream = (response: LanguageModelResponse) => void;
/**
* Interfaces for a generative language model.
*/
export interface LanguageModel {
/**
* Check the language model availability.
*/
availability(): Promise<LanguageModelAvailability>;
/**
* Create a new language model session.
*/
createSession(options?: { instructions?: string }): Promise<LanguageModelSession>;
}
/**
* Generative language model session.
*/
export interface LanguageModelSession {
/**
* Indicates a response is being generated.
*/
isResponding(): Promise<boolean>;
/**
* Produces a response to a prompt.
*/
respondTo(prompt: string, options?: LanguageModelGenerationOptions): Promise<LanguageModelResponse>;
/**
* Produces a response stream to a prompt.
*
* Each update delivers the latest snapshot of the content, not partial chunks.
*/
streamResponseTo(
prompt: string,
options: LanguageModelGenerationOptions | LanguageModelStream,
stream?: LanguageModelStream,
): void;
}
export type LanguageModelAvailability = {
isAvailable: boolean;
unavailableReason?: string;
};
export type LanguageModelGenerationOptions = {
/**
* In macOS 27.0 and later, provide attachments to the language model.
*/
attachments?: FileObject[];
sampling?: LanguageModelSampling;
temperature?: number;
maximumResponseTokens?: number;
};
export type LanguageModelSampling =
| { mode: 'greedy' }
| { mode: 'top-k' | 'top-p'; value: number; seed?: number };
/**
* The system translation service.
*/
export interface TranslationService {
/**
* Translate the text with language pair.
*
* Use BCP-47 language tags, such as `en-US`, `zh-CN`.
*/
translate(text: string, languages?: { from?: string; to?: string }): Promise<TranslationResponse>;
}
export type TranslationResponse =
| { succeeded: true; text: string }
| { succeeded: false; error: string };
/**
* Represents a file object with data and type information.
*/
export type FileObject = {
/**
* Base64 representation of the file.
*/
data: string;
/**
* Uniform Type Identifier (UTI) of the file.
*/
typeIdentifier?: string;
/**
* MIME type of the file.
*/
mimeType?: string;
/**
* File extension of the file.
*/
filenameExtension?: string;
}
/**
* Information of a file in the file system.
*/
export type FileInfo = {
filePath: string;
fileSize: number;
creationDate: Date;
modificationDate: Date;
parentPath: string;
isDirectory: boolean;
};
/**
* 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;
state?: () => MenuItemState;
/**
* Icon for the item.
*
* This can be either a base64 string or a SF Symbol name.
*/
icon?: string;
/**
* 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[];
};
/**
* A native toolbar control.
* Declare each item once, synchronously during initial script execution.
* The item set and structure stay fixed; use state getters for runtime changes.
* State refreshes after actions, including menu actions and failures.
* Async actions are not awaited; invalidate explicitly after later state changes.
*/
export type ToolbarItem = {
/**
* Stable, extension-namespaced ID, unique within each editor. Do not localize.
* Duplicate registrations are rejected.
*/
id: string;
/**
* Localized default toolbar label.
*/
title: string;
/**
* Default toolbar icon: SF Symbol name or base64 image data.
*/
icon: string;
/**
* Placement when this ID is first introduced. Defaults to 'customization'.
* 'toolbar' adds the item at the leading end; 'customization' only offers it in Customize Toolbar.
* Later changes to this option do not affect placement.
*/
initialPlacement?: 'toolbar' | 'customization';
} & (
| {
/**
* Button that invokes an action.
*/
type: 'button';
/**
* Action invoked when the button is pressed.
*/
action: () => void;
/**
* Synchronous, side-effect-free state getter.
*/
state?: () => ToolbarItemState;
}
| {
/**
* Button that opens a menu.
*/
type: 'menu';
/**
* Menu entries, including separators and nested submenus.
*/
children: MenuItem[];
/**
* Synchronous, side-effect-free state getter.
*/
state?: () => ToolbarItemState;
}
| {
/**
* Single-selection segmented presentation.
*/
type: 'segmented';
/**
* Nonempty, ordered list of mutually exclusive choices.
*/
segments: ToolbarSegment[];
}
);
/**
* State of a toolbar button or menu.
*/
export type ToolbarItemState = {
/**
* Whether enabled; defaults to true.
*/
isEnabled?: boolean;
/**
* Localized title override. Omit to restore the registered title.
*/
title?: string;
/**
* Icon override: SF Symbol name or base64 image data.
* Omit to restore the registered icon.
*/
icon?: string;
};
/**
* A choice in a segmented toolbar control.
*/
export type ToolbarSegment = {
/**
* Localized label for tooltips, overflow, and accessibility.
*/
title: string;
/**
* Segment icon: SF Symbol name or base64 image data.
*/
icon: string;
/**
* State refreshes automatically after the action, including on failure.
* Async work is not awaited; invalidate explicitly after later state changes.
*/
action: () => void;
/**
* Synchronous, side-effect-free state getter.
* At most one segment may be selected; no selection is allowed.
* isEnabled defaults to true.
*/
state: () => { isSelected: boolean; isEnabled?: boolean };
};
/**
* Represents the state of a menu item.
*/
export type MenuItemState = {
/**
* Whether enabled; defaults to true.
*/
isEnabled?: boolean;
/**
* Whether selected; defaults to false.
*/
isSelected?: boolean;
};
/**
* Represents a location on the screen.
*/
export type Point = {
x: number;
y: number;
};
/**
* Represents options to present a contextual menu.
*/
export type ContextMenuOptions = {
/**
* Index of the item to highlight when the menu opens (zero-based).
*
* If omitted, invalid, or pointing to a separator or disabled item,
* the menu opens without an initial highlight.
*/
highlightedIndex?: 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;
/**
* Represents options to create a file.
*/
export type CreateFileOptions = {
/**
* File path.
*/
path: string;
/**
* If set to true, a directory will be created instead.
*/
isDirectory?: boolean;
/**
* If set to true, existing files with the same path will be overwritten.
*/
overwrites?: boolean;
/**
* String representation of the file, if applicable.
*/
string?: string;
/**
* Base64 representation of the file, if applicable.
*/
data?: string;
};
/**
* Represents options to move a file.
*/
export type MoveFileOptions = {
/**
* Source file path.
*/
source: string;
/**
* Destination file path.