Skip to content

Commit

Permalink
Update browser-fs-access
Browse files Browse the repository at this point in the history
description needs to be set to workaround Chrome on Linux bug, use a better default description than 'Files'

GoogleChromeLabs/browser-fs-access#118
  • Loading branch information
ngyikp committed Jul 3, 2022
1 parent 68bdd4d commit 2daa199
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
38 changes: 23 additions & 15 deletions flow-typed/browser-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,64 @@ type WellKnownDirectory =

declare module 'browser-fs-access' {
/**
* For opening files, dynamically either loads the File System Access API module
* or the legacy method.
* Opens file(s) from disk.
*/
declare function fileOpen(options?: {
// Set to `true` for allowing multiple files, defaults to `false`.
// Allow multiple files to be selected. Defaults to `false`.
multiple?: boolean,

// Suggested directory in which the file picker opens. A well-known directory or a file handle.
startIn?: WellKnownDirectory | FileSystemHandle,

// By specifying an ID, the user agent can remember different directories for different IDs.
id?: string,

// Include an option to not apply any filter in the file picker, defaults to `false`.
excludeAcceptAllOption?: boolean,

// List of allowed file extensions (with leading '.'), defaults to `''`.
// Acceptable file extensions. Defaults to `[""]`.
extensions?: Array<string>,

// Textual description for file dialog , defaults to `''`.
description?: string,
// Suggested file description. Defaults to `""`.
description: string,

// List of allowed MIME types, defaults to `*/*`.
// Acceptable MIME types. Defaults to `[]`.
mimeTypes?: Array<string>,
}): Promise<FileWithHandle>;

/**
* For saving files, dynamically either loads the File System Access API module
* or the legacy method.
* Saves a file to disk.
*/
declare function fileSave(
// To-be-saved `Blob` or `Response`
blobOrPromiseBlobOrResponse: Blob | Promise<Blob> | Response,

options?: {
// Suggested file name to use, defaults to `''`.
// Suggested file name. Defaults to `"Untitled"`.
fileName?: string,

// Suggested directory in which the file picker opens. A well-known directory or a file handle.
startIn?: WellKnownDirectory | FileSystemHandle,

// By specifying an ID, the user agent can remember different directories for different IDs.
id?: string,

// Include an option to not apply any filter in the file picker, defaults to `false`.
excludeAcceptAllOption?: boolean,

// Suggested file extensions (with leading '.'), defaults to `''`.
// Acceptable file extensions. Defaults to `[""]`.
extensions?: Array<string>,

// Suggested file description. Defaults to `""`.
description: string,

// Acceptable MIME types. Defaults to `[]`.
mimeTypes?: Array<string>,
},

// A potentially existing file handle for a file to save to. Defaults to `null`.
existingHandle?: ?FileSystemFileHandle,

// Determines whether to throw (rather than open a new file save dialog) when `existingHandle` is no longer good. Defaults to `false`.
throwIfExistingHandleNotGood?: boolean,

// A callback to be called when the file picker was shown (which only happens when no `existingHandle` is provided). Defaults to `null`.
filePickerShown?: ?(handle: ?FileSystemFileHandle) => void
): Promise<?FileSystemFileHandle>;
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@szhsin/react-menu": "3.1.1",
"base64-arraybuffer": "1.0.2",
"browser-fs-access": "0.30.1",
"browser-fs-access": "0.30.2",
"history": "5.3.0",
"pako": "2.0.4",
"react": "18.2.0",
Expand Down
1 change: 1 addition & 0 deletions src/dog/DogEditorDataSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default function LevelEditorDataSelector(props: Props): React$Node {
blob,
{
fileName: 'drawdog.json',
description: 'JSON',
},
existingHandle
);
Expand Down
1 change: 1 addition & 0 deletions src/dog/editor/DogEditorFileInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function DogEditorFileInput(props: Props): React$Node {
async function openFile() {
const blob = await fileOpen({
extensions: ['.png'],
description: 'PNG image',
});

const reader = new FileReader();
Expand Down
1 change: 1 addition & 0 deletions src/levelEditor/header/LevelEditorDataSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function LevelEditorDataSelector(): React$Node {
blob,
{
fileName: 'level_data',
description: 'JSON',
},
existingHandle
);
Expand Down
2 changes: 2 additions & 0 deletions src/levelEditor/terrainEditor/LevelTerrainEditorModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default function LevelTerrainEditorModal(props: Props): React$Node {
async function openFile() {
const blob = await fileOpen({
extensions: ['.png'],
description: 'PNG image',
});

setErrorMessage(null);
Expand Down Expand Up @@ -186,6 +187,7 @@ export default function LevelTerrainEditorModal(props: Props): React$Node {
fileSave(blob, {
fileName: `Level Geometry (${currentCoordinates[0]}_${currentCoordinates[1]}_${currentCoordinates[2]})`,
extensions: ['.png'],
description: 'PNG image',
});
});
}
Expand Down

0 comments on commit 2daa199

Please sign in to comment.