Project tree view and creation (#203)

* Implement creating and importing new projects

* Add downloading a zip of a project

* Project validation (WIP)

* Add project side panel, remove project pages

* Project file saving

* Add file tree actions to rename and delete

* Fix file creation auto focus

* Add button to save file from menu

* Add project creation

* Fix specificity on version switcher button

* Update default version to 1.19

* List project files by type, remember project and delete project
This commit is contained in:
Misode
2022-06-14 16:48:55 +02:00
committed by GitHub
parent 4942729e7c
commit 90eac0f9b8
39 changed files with 1132 additions and 267 deletions

View File

@@ -1,5 +1,6 @@
import type { DataModel } from '@mcschema/core'
import { Path } from '@mcschema/core'
import * as zip from '@zip.js/zip.js'
import yaml from 'js-yaml'
import { route } from 'preact-router'
import rfdc from 'rfdc'
@@ -285,3 +286,24 @@ export class BiMap<A, B> {
return b
}
}
export async function readZip(file: File): Promise<[string, string][]> {
const buffer = await file.arrayBuffer()
const reader = new zip.ZipReader(new zip.BlobReader(new Blob([buffer])))
const entries = await reader.getEntries()
return await Promise.all(entries
.filter(e => !e.directory)
.map(async e => {
const writer = new zip.TextWriter('utf-8')
return [e.filename, await e.getData?.(writer)] as [string, string]
})
)
}
export async function writeZip(entries: [string, string][]): Promise<string> {
const writer = new zip.ZipWriter(new zip.Data64URIWriter('application/zip'))
await Promise.all(entries.map(async ([name, data]) => {
await writer.add(name, new zip.TextReader(data))
}))
return await writer.close()
}