Skip to content

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

Refine breakpoint and rename patterns

Danila Poyarkovbdb95a9d31b2
diff --git a/src/components/AppMenu.vue b/src/components/AppMenu.vue
index 5424b31cb..6958eff26 100644
--- a/src/components/AppMenu.vue
+++ b/src/components/AppMenu.vue
@@ -16,8 +16,9 @@ import {
import IconChevronRight from '~icons/lucide/chevron-right'
-import { ref } from 'vue'
+import { computed, ref } from 'vue'
+import { useInlineRename } from '@/composables/use-inline-rename'
import { menuContent, menuItem, menuSeparator } from '@/components/ui/menu'
import { IS_TAURI } from '@/constants'
import { openFileDialog } from '@/composables/use-menu'
@@ -25,22 +26,20 @@ import { useEditorStore } from '@/stores/editor'
const store = useEditorStore()
-const editingName = ref(false)
+const DOCUMENT_NAME_ID = 'document-name'
const nameInputRef = ref<HTMLInputElement | null>(null)
+const rename = useInlineRename<'document-name'>((_id, name) => {
+ store.state.documentName = name
+})
+const editingName = computed(() => rename.editingId.value === DOCUMENT_NAME_ID)
-async function startRename() {
- editingName.value = true
- await nextTick()
- nameInputRef.value?.focus()
- nameInputRef.value?.select()
+function startRename() {
+ rename.start(DOCUMENT_NAME_ID, store.state.documentName)
+ void rename.focusInput(nameInputRef.value)
}
function commitRename(input: HTMLInputElement) {
- const value = input.value.trim()
- if (value) {
- store.state.documentName = value
- }
- editingName.value = false
+ rename.commit(DOCUMENT_NAME_ID, input)
}
const isMac = navigator.platform.includes('Mac')
@@ -183,7 +182,7 @@ const topMenus = [
:value="store.state.documentName"
@blur="commitRename($event.target as HTMLInputElement)"
@keydown.enter="($event.target as HTMLInputElement).blur()"
- @keydown.escape="editingName = false"
+ @keydown="rename.onKeydown"
/>
<span
v-else
diff --git a/src/components/MobileDrawer.vue b/src/components/MobileDrawer.vue
index 7dfd9cb99..78652bf04 100644
--- a/src/components/MobileDrawer.vue
+++ b/src/components/MobileDrawer.vue
@@ -37,32 +37,31 @@ const snap = computed({
}
})
-const activeDrawerTab = computed<DrawerTab>({
- get: () => {
- if (store.state.activeRibbonTab === 'code') return 'code'
- if (store.state.activeRibbonTab === 'ai') return 'ai'
- return store.state.panelMode === 'design' ? 'design' : 'layers'
- },
- set: (tab) => {
- if (tab === 'code' || tab === 'ai') {
- store.state.activeRibbonTab = tab
- return
- }
- store.state.activeRibbonTab = 'panels'
- store.state.panelMode = tab
+function getDrawerTab(): DrawerTab {
+ if (store.state.activeRibbonTab === 'code') return 'code'
+ if (store.state.activeRibbonTab === 'ai') return 'ai'
+ return store.state.panelMode === 'design' ? 'design' : 'layers'
+}
+
+function setDrawerTab(tab: DrawerTab) {
+ if (tab === 'code' || tab === 'ai') {
+ store.state.activeRibbonTab = tab
+ return
}
-})
+ store.state.activeRibbonTab = 'panels'
+ store.state.panelMode = tab
+}
const isOpen = computed(() => snap.value !== 'closed')
function toggleTab(tab: DrawerTab) {
- if (activeDrawerTab.value === tab && isOpen.value) {
+ if (getDrawerTab() === tab && isOpen.value) {
snap.value = 'closed'
targetHeight.value = snapHeight('closed')
return
}
- activeDrawerTab.value = tab
+ setDrawerTab(tab)
if (!isOpen.value) {
snap.value = 'half'
targetHeight.value = snapHeight('half')
@@ -119,7 +118,7 @@ const drawerTransition = {
@pan="onPan"
@panEnd="onPanEnd"
>
- <TabsRoot :model-value="activeDrawerTab" class="flex min-h-0 flex-1 flex-col">
+ <TabsRoot :model-value="getDrawerTab()" class="flex min-h-0 flex-1 flex-col">
<nav ref="headerRef" aria-label="Mobile panel navigation" class="flex shrink-0 flex-col">
<div class="flex w-full justify-center pt-2">
<div class="h-1 w-8 rounded-full bg-muted/40" />
diff --git a/src/composables/use-canvas.ts b/src/composables/use-canvas.ts
index b1be57fb5..eba68eddd 100644
--- a/src/composables/use-canvas.ts
+++ b/src/composables/use-canvas.ts
@@ -1,4 +1,4 @@
-import { useMediaQuery, useRafFn, useResizeObserver } from '@vueuse/core'
+import { useBreakpoints, useRafFn, useResizeObserver } from '@vueuse/core'
import { onMounted, onUnmounted, type Ref } from 'vue'
import { getCanvasKit, getGpuBackend } from '@/engine/canvaskit'
@@ -128,7 +128,8 @@ export function useCanvas(canvasRef: Ref<HTMLCanvasElement | null>, store: Edito
const params = new URLSearchParams(window.location.search)
const noRulersParam = params.has('no-rulers')
- const isMobile = useMediaQuery('(max-width: 767px)')
+ const breakpoints = useBreakpoints({ mobile: 768 })
+ const isMobile = breakpoints.smaller('mobile')
function showRulers() {
return !noRulersParam && !isMobile.value
diff --git a/src/composables/use-inline-rename.ts b/src/composables/use-inline-rename.ts
index 1e38cdac9..183d0d2f2 100644
--- a/src/composables/use-inline-rename.ts
+++ b/src/composables/use-inline-rename.ts
@@ -1,10 +1,10 @@
import { nextTick, ref } from 'vue'
-export function useInlineRename(onCommit: (id: string, newName: string) => void) {
- const editingId = ref<string | null>(null)
+export function useInlineRename<T extends string>(onCommit: (id: T, newName: string) => void) {
+ const editingId = ref<T | null>(null)
let originalName = ''
- function start(id: string, currentName: string) {
+ function start(id: T, currentName: string) {
editingId.value = id
originalName = currentName
}
@@ -15,7 +15,7 @@ export function useInlineRename(onCommit: (id: string, newName: string) => void)
input?.select()
}
- function commit(id: string, input: HTMLInputElement) {
+ function commit(id: T, input: HTMLInputElement) {
if (editingId.value !== id) return
const value = input.value.trim()
if (value && value !== originalName) {