Skip to content

AI-native design editor. Open-source Figma alternative.

Split PagesPanel into separate component, inline page rename

Danila Poyarkov803b69eee62d
diff --git a/components.d.ts b/components.d.ts
index be8db16f6..f219eb0f8 100644
--- a/components.d.ts
+++ b/components.d.ts
@@ -42,6 +42,7 @@ declare module 'vue' {
LayersPanel: typeof import('./src/components/LayersPanel.vue')['default']
LayoutSection: typeof import('./src/components/properties/LayoutSection.vue')['default']
PageSection: typeof import('./src/components/properties/PageSection.vue')['default']
+ PagesPanel: typeof import('./src/components/PagesPanel.vue')['default']
PositionSection: typeof import('./src/components/properties/PositionSection.vue')['default']
PropertiesPanel: typeof import('./src/components/PropertiesPanel.vue')['default']
ScrubInput: typeof import('./src/components/ScrubInput.vue')['default']
diff --git a/src/components/LayersPanel.vue b/src/components/LayersPanel.vue
index dfd923d3d..8fb76e760 100644
--- a/src/components/LayersPanel.vue
+++ b/src/components/LayersPanel.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { ref, computed, watch } from 'vue'
+import { ref, watch } from 'vue'
import { useEventListener } from '@vueuse/core'
import { TreeRoot, TreeItem } from 'reka-ui'
@@ -11,6 +11,7 @@ import IconPenTool from '~icons/lucide/pen-tool'
import IconSquare from '~icons/lucide/square'
import IconType from '~icons/lucide/type'
+import PagesPanel from './PagesPanel.vue'
import { useEditorStore } from '../stores/editor'
const store = useEditorStore()
@@ -59,11 +60,6 @@ watch(
}
)
-const pages = computed(() => {
- void store.state.renderVersion
- return store.graph.getPages()
-})
-
const expanded = ref<string[]>([])
function onSelect(ev: CustomEvent) {
@@ -76,13 +72,6 @@ function onSelect(ev: CustomEvent) {
}
}
-function renamePage(pageId: string, currentName: string) {
- const name = prompt('Rename page', currentName)
- if (name && name !== currentName) {
- store.renamePage(pageId, name)
- }
-}
-
function toggleExpand(id: string) {
const idx = expanded.value.indexOf(id)
if (idx >= 0) {
@@ -172,7 +161,7 @@ function updateDropTarget(ev: PointerEvent) {
}
if (mouseY <= rowMid) {
- const parentId = rowNode.parentId ?? store.graph.rootId
+ const parentId = rowNode.parentId ?? store.state.currentPageId
const parent = store.graph.getNode(parentId)
if (parent) {
const idx = parent.childIds.indexOf(rowId)
@@ -183,7 +172,7 @@ function updateDropTarget(ev: PointerEvent) {
}
if (i === rows.length - 1 && mouseY > rowMid) {
- const parentId = rowNode.parentId ?? store.graph.rootId
+ const parentId = rowNode.parentId ?? store.state.currentPageId
const parent = store.graph.getNode(parentId)
if (parent) {
const idx = parent.childIds.indexOf(rowId)
@@ -213,30 +202,7 @@ function updateDropTarget(ev: PointerEvent) {
<template>
<aside class="flex w-60 flex-col overflow-y-auto border-r border-border bg-panel">
- <!-- Pages -->
- <div class="shrink-0 border-b border-border">
- <div class="flex items-center justify-between px-3 py-1.5">
- <span class="text-[11px] uppercase tracking-wider text-muted">Pages</span>
- <button
- class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
- title="Add page"
- @click="store.addPage()"
- >+</button>
- </div>
- <div class="px-1 pb-1">
- <button
- v-for="page in pages"
- :key="page.id"
- class="flex w-full cursor-pointer items-center gap-1.5 rounded border-none px-2 py-1 text-left text-xs"
- :class="page.id === store.state.currentPageId ? 'bg-hover text-surface' : 'bg-transparent text-muted hover:bg-hover hover:text-surface'"
- @click="store.switchPage(page.id)"
- @dblclick="renamePage(page.id, page.name)"
- >
- <icon-lucide-file class="size-3 shrink-0" />
- {{ page.name }}
- </button>
- </div>
- </div>
+ <PagesPanel />
<header class="shrink-0 px-3 py-2 text-[11px] uppercase tracking-wider text-muted">Layers</header>
<div ref="listRef" class="relative flex-1 overflow-y-auto px-1">
<TreeRoot
diff --git a/src/components/PagesPanel.vue b/src/components/PagesPanel.vue
new file mode 100644
index 000000000..6496b930d
--- /dev/null
+++ b/src/components/PagesPanel.vue
@@ -0,0 +1,70 @@
+<script setup lang="ts">
+import { computed, ref, nextTick } from 'vue'
+
+import { useEditorStore } from '../stores/editor'
+
+const store = useEditorStore()
+
+const pages = computed(() => {
+ void store.state.renderVersion
+ return store.graph.getPages()
+})
+
+const editingPageId = ref<string | null>(null)
+const editInput = ref<HTMLInputElement | null>(null)
+
+function startRename(pageId: string) {
+ editingPageId.value = pageId
+ nextTick(() => {
+ editInput.value?.select()
+ })
+}
+
+function commitRename(pageId: string) {
+ const value = editInput.value?.value.trim()
+ if (value && value !== store.graph.getNode(pageId)?.name) {
+ store.renamePage(pageId, value)
+ }
+ editingPageId.value = null
+}
+
+function cancelRename() {
+ editingPageId.value = null
+}
+</script>
+
+<template>
+ <div class="shrink-0 border-b border-border">
+ <div class="flex items-center justify-between px-3 py-1.5">
+ <span class="text-[11px] uppercase tracking-wider text-muted">Pages</span>
+ <button
+ class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
+ title="Add page"
+ @click="store.addPage()"
+ >+</button>
+ </div>
+ <div class="px-1 pb-1">
+ <div v-for="pg in pages" :key="pg.id">
+ <input
+ v-if="editingPageId === pg.id"
+ ref="editInput"
+ class="w-full rounded border border-accent bg-input px-2 py-1 text-xs text-surface outline-none"
+ :value="pg.name"
+ @blur="commitRename(pg.id)"
+ @keydown.enter="commitRename(pg.id)"
+ @keydown.escape="cancelRename()"
+ />
+ <button
+ v-else
+ class="flex w-full cursor-pointer items-center gap-1.5 rounded border-none px-2 py-1 text-left text-xs"
+ :class="pg.id === store.state.currentPageId ? 'bg-hover text-surface' : 'bg-transparent text-muted hover:bg-hover hover:text-surface'"
+ @click="store.switchPage(pg.id)"
+ @dblclick="startRename(pg.id)"
+ >
+ <icon-lucide-file class="size-3 shrink-0" />
+ {{ pg.name }}
+ </button>
+ </div>
+ </div>
+ </div>
+</template>