79 lines
3.4 KiB
Vue
79 lines
3.4 KiB
Vue
<script setup lang="ts">
|
|
const ed = useEditor()
|
|
const fileInput = ref<HTMLInputElement>()
|
|
const renaming = ref<string | null>(null)
|
|
const renameText = ref('')
|
|
const confirmDelete = ref<string | null>(null)
|
|
|
|
const close = () => (ed.dialog.value = null)
|
|
const when = (t: number) => new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(t)
|
|
|
|
function open(id: string) {
|
|
ed.switchProject(id)
|
|
close()
|
|
}
|
|
|
|
function startRename(id: string, name: string) {
|
|
renaming.value = id
|
|
renameText.value = name
|
|
nextTick(() => document.querySelector<HTMLInputElement>('.project-list input')?.select())
|
|
}
|
|
|
|
function finishRename() {
|
|
if (renaming.value) ed.renameProject(renaming.value, renameText.value)
|
|
renaming.value = null
|
|
}
|
|
|
|
function onFile(e: Event) {
|
|
const file = (e.target as HTMLInputElement).files?.[0]
|
|
if (file) ed.importAsProject(file).then(close)
|
|
;(e.target as HTMLInputElement).value = ''
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="modal-backdrop" @click.self="close">
|
|
<div class="modal" role="dialog" aria-labelledby="projects-title">
|
|
<div class="flex items-start justify-between gap-4">
|
|
<h2 id="projects-title">Projects</h2>
|
|
<button class="tb-btn" title="Close" @click="close"><Icon name="lucide:x" class="size-4" /></button>
|
|
</div>
|
|
<p class="hint mt-1">Saved in this browser as you work. Projects with a link are also saved online.</p>
|
|
|
|
<ul class="project-list">
|
|
<li v-for="m in ed.projects.value" :key="m.id" :class="{ current: m.id === ed.meta.value.id }">
|
|
<input
|
|
v-if="renaming === m.id"
|
|
v-model="renameText"
|
|
class="rename"
|
|
@keydown.enter="finishRename"
|
|
@keydown.esc="renaming = null"
|
|
@blur="finishRename"
|
|
/>
|
|
<button v-else class="pick" @click="open(m.id)">
|
|
<span class="name">
|
|
{{ m.name }}
|
|
<span v-if="m.id === ed.meta.value.id" class="badge">open</span>
|
|
</span>
|
|
<span class="meta">
|
|
{{ when(m.updated) }}
|
|
<template v-if="m.link"> · <Icon name="lucide:link" class="size-3" /> {{ m.link.key ? 'your link' : 'from a link' }}</template>
|
|
</span>
|
|
</button>
|
|
<button class="icon-btn" title="Rename" @click="startRename(m.id, m.name)"><Icon name="lucide:pencil" class="size-3.5" /></button>
|
|
<button class="icon-btn" title="Duplicate" @click="ed.duplicateProject(m.id); close()"><Icon name="lucide:copy" class="size-3.5" /></button>
|
|
<button v-if="confirmDelete !== m.id" class="icon-btn" title="Delete" @click="confirmDelete = m.id"><Icon name="lucide:trash-2" class="size-3.5" /></button>
|
|
<button v-else class="btn-sm btn-danger" @click="ed.deleteProject(m.id); confirmDelete = null">Delete?</button>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="mt-4 flex flex-wrap gap-2">
|
|
<button class="btn" @click="ed.newProject(false); close()"><Icon name="lucide:file" class="size-4" /> New (NAND only)</button>
|
|
<button class="btn" @click="ed.newProject(true); close()"><Icon name="lucide:file-plus" class="size-4" /> New with examples</button>
|
|
<button class="btn" @click="fileInput?.click()"><Icon name="lucide:folder-open" class="size-4" /> Open file</button>
|
|
<input ref="fileInput" type="file" accept="application/json,.json" class="hidden" @change="onFile" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|