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

@@ -8,6 +8,8 @@ import { fetchData } from './DataFetcher'
export const VersionIds = ['1.15', '1.16', '1.17', '1.18', '1.18.2', '1.19'] as const
export type VersionId = typeof VersionIds[number]
export const DEFAULT_VERSION: VersionId = '1.19'
export type BlockStateRegistry = {
[block: string]: {
properties?: {
@@ -49,6 +51,7 @@ const versionGetter: {
export let CachedDecorator: INode<any>
export let CachedFeature: INode<any>
export let CachedCollections: CollectionRegistry
export let CachedSchemas: SchemaRegistry
async function getVersion(id: VersionId): Promise<VersionData> {
if (!Versions[id]) {
@@ -121,6 +124,12 @@ export async function getBlockStates(version: VersionId): Promise<BlockStateRegi
return versionData.blockStates
}
export async function getSchemas(version: VersionId): Promise<SchemaRegistry> {
const versionData = await getVersion(version)
CachedSchemas = versionData.schemas
return versionData.schemas
}
export function checkVersion(versionId: string, minVersionId: string | undefined, maxVersionId?: string) {
const version = config.versions.findIndex(v => v.id === versionId)
const minVersion = minVersionId ? config.versions.findIndex(v => v.id === minVersionId) : 0

View File

@@ -9,7 +9,7 @@ export async function shareSnippet(type: string, version: VersionId, jsonData: a
try {
const raw = JSON.stringify(jsonData)
const data = lz.compressToBase64(raw)
console.log('Compression rate', raw.length / raw.length)
console.debug('Compression rate', raw.length / raw.length)
const body = JSON.stringify({ data, type, version, show_preview })
let id = ShareCache.get(body)
if (!id) {

View File

@@ -0,0 +1,56 @@
import yaml from 'js-yaml'
import { Store } from '../Store'
const INDENTS: Record<string, number | string | undefined> = {
'2_spaces': 2,
'4_spaces': 4,
tabs: '\t',
minified: undefined,
}
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
let commentJson: typeof import('comment-json') | null = null
const FORMATS: Record<string, {
parse: (v: string) => Promise<unknown>,
stringify: (v: unknown, indentation: string | number | undefined) => string,
}> = {
json: {
parse: async (v) => {
try {
return JSON.parse(v)
} catch (e) {
commentJson = await import('comment-json')
return commentJson.parse(v)
}
},
stringify: (v, i) => (commentJson ?? JSON).stringify(v, null, i) + '\n',
},
yaml: {
parse: async (v) => yaml.load(v),
stringify: (v, i) => yaml.dump(v, {
flowLevel: i === undefined ? 0 : -1,
indent: typeof i === 'string' ? 4 : i,
}),
},
}
export function stringifySource(data: unknown, format?: string, indent?: string) {
return FORMATS[format ?? Store.getFormat()].stringify(data, INDENTS[indent ?? Store.getIndent()])
}
export async function parseSource(data: string, format: string) {
return await FORMATS[format].parse(data)
}
export function getSourceIndent(indent: string) {
return INDENTS[indent]
}
export function getSourceIndents() {
return Object.keys(INDENTS)
}
export function getSourceFormats() {
return Object.keys(FORMATS)
}

View File

@@ -2,3 +2,4 @@ export * from './Changelogs'
export * from './DataFetcher'
export * from './Schemas'
export * from './Sharing'
export * from './Source'