Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the File System Access API to edit a local style #964

Closed
josxha opened this issue Jan 6, 2025 · 5 comments
Closed

Use the File System Access API to edit a local style #964

josxha opened this issue Jan 6, 2025 · 5 comments

Comments

@josxha
Copy link
Contributor

josxha commented Jan 6, 2025

User Story

As a style developer, I want to create incremental changes to a map style and version control them in git. The current development process allows me to upload a local style and modify it, after that I need to download it and replace it with the obsolete version of the style in the version controled directory. I would prefer to open and edit my local style directly from my file system to prevent any manual replacement.

Possible Solution

This functionality is possible by using the File System API, in more particular the FileSystemFileHandle.

async function writeFile(fileHandle, contents) {
  // Create a FileSystemWritableFileStream to write to.
  const writable = await fileHandle.createWritable();

  // Write the contents of the file to the stream.
  await writable.write(contents);

  // Close the file and write the contents to disk.
  await writable.close();
}

This relatively new API is supported by all major browsers. A nice example use of this functioanlity has been implemented by https://app.diagrams.net/.

Image

Loosly Related

@HarelM
Copy link
Collaborator

HarelM commented Jan 6, 2025

I think you can use the docker image to achieve this functionality along with the desktop version, can't you?

@josxha
Copy link
Contributor Author

josxha commented Jan 6, 2025

@HarelM Yes this is indeed possible by using a local instance of Maputnik. Although, if moving the downloaded file to the correct directory is a workaround, setting up a local deployment seems to me like a workaround as well. I'm not saying that those are not valid options, but that the File System API might be a better solution.

@HarelM
Copy link
Collaborator

HarelM commented Jan 6, 2025

It might be and you are welcome to explore it, but the fact is that there is a solution to what you want to achieve, so this is a really nice to have if you'd ask me.
I never said anything about a workaround...

@josxha
Copy link
Contributor Author

josxha commented Jan 6, 2025

Created a pull request in #965 👍

HarelM added a commit that referenced this issue Jan 9, 2025
…stem (#965)

## Launch Checklist

<!-- Thanks for the PR! Feel free to add or remove items from the
checklist. -->


 - [x] Briefly describe the changes in this PR.
 - [x] Link to related issues.
- [x] Include before/after visuals or gifs if this PR includes visual
changes.
 - [ ] Write tests for all new functionality.
 - [x] Add an entry to `CHANGELOG.md` under the `## main` section.

## Changes

- This pull request makes use of the FileSystemFileHandle API to modify
a local file. No need to download it - just click save.
- I don't know how to cover this functionality by tests so I need
directions in case test coverage is required.
- The pull request adds
[@types/wicg-file-system-access](https://www.npmjs.com/package/@types/wicg-file-system-access)
as a new dev dependency which I am not really pleased about but can't
think of a way around it.

## Known Limitations

- The used File API is only available in when accessed from https or on
localhost.
- There is no visual indicator that the file has been saved. Previously
the browser showed it as a new download.

## Issue

- #964

## Screenshots

### Menu
<img
src="https://github.com/user-attachments/assets/dfcfc5c2-0019-4857-ba26-224b5598fc11"
/>

### Open modal
<img
src="https://github.com/user-attachments/assets/4e1293e8-16b6-4b86-925b-3bebb49d8ca6"
height="200px" />

### Save modal
<img
src="https://github.com/user-attachments/assets/4f10e2c0-2dd3-4726-a613-30e0406619b0"
height="200px" />

---------

Co-authored-by: Harel M <[email protected]>
@josxha
Copy link
Contributor Author

josxha commented Jan 9, 2025

Implemented in #965

@josxha josxha closed this as completed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants