logigate/app/components/editor/App.vue

88 lines
3.6 KiB
Vue
Raw Normal View History

<script setup lang="ts">
const ed = useEditor()
const updateReady = useState('update-ready', () => false)
function reload() {
// Unsaved changes are written when the page unloads.
location.reload()
}
const hasSelection = computed(() => ed.selection.value.length + ed.wireSel.value.length > 0)
const link = computed(() => {
const l = ed.linking.value
const end = l?.queue[l.at]
return l && end ? { n: l.at + 1, total: l.queue.length, label: end.label, dir: end.dir } : null
})
onMounted(() => {
const stop = ed.startLoop()
onBeforeUnmount(stop)
void ed.startAccount()
})
// The first time into the editor, the help explains the basics.
watch(
ed.screen,
s => {
try {
if (s === 'editor' && !localStorage.getItem('logigate:help-seen')) ed.showHelp.value = true
} catch {}
},
{ immediate: true },
)
</script>
<template>
<div class="app">
<EditorMainMenu v-if="ed.screen.value === 'menu'" />
<template v-else>
<div class="workspace" :class="{ 'no-panel': !ed.panelOpen.value, 'has-selection': hasSelection }">
<EditorInspector v-if="ed.panelOpen.value" />
<EditorRail v-else />
<main class="stage">
<EditorCanvas />
</main>
<EditorSelectionPanel v-if="hasSelection" />
<EditorToolbar />
<EditorBottomBar />
</div>
</template>
<Transition name="fade">
<div v-if="ed.notice.value" class="toast" :class="ed.notice.value.kind">{{ ed.notice.value.text }}</div>
</Transition>
<div v-if="updateReady" class="update-bar" role="status">
<Icon name="lucide:sparkles" class="size-4 shrink-0" />
<span>A new version of Logigate is ready. Your work is saved.</span>
<button class="btn-sm" @click="reload">Reload now</button>
<button class="icon-btn" title="Later" @click="updateReady = false"><Icon name="lucide:x" class="size-3.5" /></button>
</div>
<div v-if="ed.cabling.value" class="placing-hint">
<strong>Cable with {{ ed.cabling.value.wires.length }} wires:</strong>
{{ ed.cabling.value.start ? 'click where it ends (its split).' : 'click where it starts (its bundle).' }} <kbd>Esc</kbd> cancels.
</div>
<div v-else-if="ed.placing.value" class="placing-hint">
Click on the canvas to place. <kbd>Shift</kbd> places several, <kbd>Esc</kbd> stops.
</div>
<div v-else-if="link" class="placing-hint">
<template v-if="link.total > 1">
<strong>{{ link.n }} of {{ link.total }}<template v-if="link.label">: {{ link.label }}</template></strong> ·
</template>
Click the pin {{ link.dir === 'out' ? 'it goes to' : 'it comes from' }}, or a part to use its next free pin. <kbd>Shift</kbd> + click: one more from the same signal. <kbd>Esc</kbd> stops.
</div>
<EditorTruthTableDialog v-if="ed.dialog.value === 'table'" />
<EditorPublishDialog v-if="ed.dialog.value === 'publish'" />
<EditorConnectorDialog v-if="ed.dialog.value === 'connector'" />
<EditorHelp v-if="ed.showHelp.value" />
<EditorPauseMenu v-if="ed.paused.value && ed.screen.value === 'editor'" />
<EditorShareDialog v-if="ed.dialog.value === 'share'" />
<EditorAccountDialog v-if="ed.dialog.value === 'account'" />
<EditorVersionsDialog v-if="ed.dialog.value === 'versions'" />
<EditorSettingsDialog v-if="ed.dialog.value === 'settings'" />
<EditorSearchDialog v-if="ed.dialog.value === 'search'" />
<EditorFaceDialog v-if="ed.dialog.value === 'face'" />
<EditorLibraryDialog v-if="ed.dialog.value === 'library'" />
<EditorLibraryPublishDialog v-if="ed.dialog.value === 'library-publish'" />
</div>
</template>