Skip to content

Commit 7674ad3

Browse files
committed
Add a few file system APIs
1 parent d0b2133 commit 7674ad3

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Add `markedit-api` to your (TypeScript) project's devDependencies:
1919
```json
2020
{
2121
"devDependencies": {
22-
"markedit-api": "https://github.com/MarkEdit-app/MarkEdit-api#v0.15.0"
22+
"markedit-api": "https://github.com/MarkEdit-app/MarkEdit-api#v0.16.0"
2323
}
2424
}
2525
```
@@ -50,8 +50,16 @@ interface MarkEdit {
5050
lezer: { common, highlight, markdown, lr };
5151
// Get notified when the editor is initialized.
5252
onEditorReady(listener: (editorView: EditorView) => void): void;
53-
// Get information of the current file.
54-
getFileInfo(): Promise<FileInfo | undefined>;
53+
// Create a file in the file system.
54+
createFile(options: CreateFileOptions): Promise<boolean>;
55+
// Delete a file from the file system.
56+
deleteFile(path: string): Promise<boolean>;
57+
// List all files under a directory.
58+
listFiles(path: string): Promise<string[] | undefined>;
59+
// Get the content of a file.
60+
getFileContent(path?: string): Promise<string | undefined>;
61+
// Get the information of a file.
62+
getFileInfo(path?: string): Promise<FileInfo | undefined>;
5563
// Get all items from the native pasteboard.
5664
getPasteboardItems(): Promise<PasteboardItem[]>;
5765
// Get the string from the native pasteboard.

index.d.ts

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,39 @@ export interface MarkEdit {
127127
onEditorReady(listener: (editorView: EditorView) => void): void;
128128

129129
/**
130-
* Get information of the current file.
131-
* @returns The file information, or undefined for unsaved new drafts.
130+
* Create a file in the file system.
131+
* @param options The options, including path and content.
132+
* @returns True if the file was successfully created.
132133
*/
133-
getFileInfo(): Promise<FileInfo | undefined>;
134+
createFile(options: CreateFileOptions): Promise<boolean>;
135+
136+
/**
137+
* Delete a file from the file system.
138+
* @param path The file path. It must be one that the app can access. See the [wiki](https://github.com/MarkEdit-app/MarkEdit/wiki/Customization#grant-folder-access) for more details.
139+
* @returns True if the file was successfully deleted.
140+
*/
141+
deleteFile(path: string): Promise<boolean>;
142+
143+
/**
144+
* List all files under a directory.
145+
* @param path The directory path. It must be one that the app can access. See the [wiki](https://github.com/MarkEdit-app/MarkEdit/wiki/Customization#grant-folder-access) for more details.
146+
* @returns All file names as a string array, or undefined if failed.
147+
*/
148+
listFiles(path: string): Promise<string[] | undefined>;
149+
150+
/**
151+
* Get the content of a file.
152+
* @param path The file path. The current file is used as a fallback.
153+
* @returns The file content as a string, or undefined if failed.
154+
*/
155+
getFileContent(path?: string): Promise<string | undefined>;
156+
157+
/**
158+
* Get the information of a file.
159+
* @param path The file path. The current file is used as a fallback.
160+
* @returns The file information, or undefined if not found.
161+
*/
162+
getFileInfo(path?: string): Promise<FileInfo | undefined>;
134163

135164
/**
136165
* Get all items from the native pasteboard.
@@ -359,6 +388,8 @@ export type FileInfo = {
359388
fileSize: number;
360389
creationDate: Date;
361390
modificationDate: Date;
391+
parentPath: string;
392+
isDirectory: boolean;
362393
};
363394

364395
/**
@@ -484,6 +515,38 @@ export type TextBox = {
484515
defaultValue?: string;
485516
} | string;
486517

518+
/**
519+
* Represents options to create a file.
520+
*/
521+
export type CreateFileOptions = {
522+
/**
523+
* File path.
524+
*
525+
* It must be one that the app can access. See the [wiki](https://github.com/MarkEdit-app/MarkEdit/wiki/Customization#grant-folder-access) for more details.
526+
*/
527+
path: string;
528+
529+
/**
530+
* If set to true, a directory will be created instead.
531+
*/
532+
isDirectory?: boolean;
533+
534+
/**
535+
* If set to true, existing files with the same path will be overwritten.
536+
*/
537+
overwrites?: boolean;
538+
539+
/**
540+
* String representation of the file, if applicable.
541+
*/
542+
string?: string;
543+
544+
/**
545+
* Base64 representation of the file, if applicable.
546+
*/
547+
data?: string;
548+
};
549+
487550
/**
488551
* Represents options to show the save panel.
489552
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "markedit-api",
3-
"version": "0.15.0",
3+
"version": "0.16.0",
44
"description": "Type definitions for the latest MakrEdit API.",
55
"main": "./index.cjs",
66
"module": "./index.js",

0 commit comments

Comments
 (0)