10000 Mark more parts of the API as optional · 1j01/jspaint@2fe8c35 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Mark more parts of the API as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed May 12, 2024
1 parent cb8bc88 commit 2fe8c35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,16 +681,16 @@ This is used both for saving images, as well as palette files, and animations.
Arguments:
- `formats`: an array of objects representing types of files, with the following properties:
- `formatID`: a string that uniquely identifies the format (may be the same as `mimeType`)
- `mimeType`: the file format's designated [media type](https://en.wikipedia.org/wiki/Media_type), e.g. `"image/png"`
- `mimeType` (optional): the file format's designated [media type](https://en.wikipedia.org/wiki/Media_type), e.g. `"image/png"` (palette formats do not have this property)
- `name`: the file format's name, e.g. `"WebP"`
- `nameWithExtensions`: the file format's name followed by a list of extensions, e.g. `"TIFF (*.tif;*.tiff)"`
- `extensions`: an array of file extensions, excluding the dot, with the preferred extension first, e.g. `["bmp", "dib"]`
- `defaultFileName`: a suggested file name, e.g. `"Untitled.png"` or the name of an open document.
- `defaultFileName` (optional): a suggested file name, e.g. `"Untitled.png"` or the name of an open document.
- `defaultPath` (optional): a file handle for a document that was opened, so you can save to the same folder easily. Misnomer: this may not be a path, it depends on how you define file handles.
- `defaultFileFormatID`: the `formatID` of a file format to select by default.
- `defaultFileFormatID` (optional): the `formatID` of a file format to select by default.
- `async function getBlob(formatID)`: a function you call to get a file in one of the supported formats. It takes a `formatID` and returns a `Promise` that resolves with a `Blob` representing the file contents to save.
- `function savedCallbackUnreliable({ newFileName, newFileFormatID, newFileHandle, newBlob })`: a function you call when the user has saved the file. The `newBlob` should come from `getBlob(newFileFormatID)`.
- `dialogTitle`: a title for the save dialog.
- `function savedCallbackUnreliable({ newFileName, newFileFormatID, newFileHandle, newBlob })` (optional): a function you call when the user has saved the file. The `newBlob` should come from `getBlob(newFileFormatID)`.
- `dialogTitle` (optional): a title for the save dialog.

Note the inversion of control here:
JS Paint calls your `systemHooks.showSaveFileDialog` function, and then you call JS Paint's `getBlob` function.
Expand Down
10 changes: 5 additions & 5 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,12 @@ declare const showSaveFilePicker: (any) => any;
// The JS Paint `systemHooks` API
interface SaveFileDialogOptions {
formats: FileFormat[];
defaultFileName: string;
defaultFileName?: string;
defaultPath?: UserFileHandle; // a bit of a misnomer since UserFileHandle is not _necessarily_ a path
defaultFileFormatID: string;
defaultFileFormatID?: string;
getBlob: (formatID: string) => Promise<Blob>;
savedCallbackUnreliable: (params: { newFileName: string; newFileFormatID: string; newFileHandle: any; newBlob: Blob }) => void;
dialogTitle: string;
savedCallbackUnreliable?: (params: { newFileName: string; newFileFormatID: string; newFileHandle: any; newBlob: Blob }) => void;
dialogTitle?: string;
}

interface OpenFileDialogOptions {
Expand All @@ -516,7 +516,7 @@ interface SystemHooks {
showSaveFileDialog(options: SaveFileDialogOptions): Promise<void>;
showOpenFileDialog(options: OpenFileDialogOptions): Promise<{ file: Blob; fileHandle?: UserFileHandle; }>;
writeBlobToHandle(fileHandle: UserFileHandle, blob: Blob): Promise<boolean | undefined>;
readBlobFromHandle(fileHandle: UserFileHandle): Promise<Blob>;
readBlobFromHandle(fileHandle: UserFileHandle): Promise<Blob | undefined>;
setWallpaperTiled(canvas: HTMLCanvasElement): void;
setWallpaperCentered(canvas: HTMLCanvasElement): void;
}
Expand Down

0 comments on commit 2fe8c35

Please sign in to comment.
0