11<script setup lang="ts">
22import { computed , reactive , type PropType } from ' vue'
3- import { Image } from ' @unpic/vue'
43import * as z from ' zod'
54import type { FormSubmitEvent } from ' @nuxt/ui'
65import { type CreateFileParams , type CreateFolderParams , type RenameFileParams , type StudioAction , type TreeItem , ContentFileExtension } from ' ../../../types'
7- import { joinURL , withLeadingSlash } from ' ufo'
6+ import { joinURL , withLeadingSlash , withoutLeadingSlash } from ' ufo'
87import { contentFileExtensions } from ' ../../../utils/content'
98import { useStudio } from ' ../../../composables/useStudio'
109import { StudioItemActionId } from ' ../../../types'
1110import { stripNumericPrefix } from ' ../../../utils/string'
11+ import { defineShortcuts } from ' #imports'
1212
1313const { context } = useStudio ()
1414
15+ defineShortcuts ({
16+ escape : () => {
17+ context .unsetActionInProgress ()
18+ },
19+ })
20+
1521const props = defineProps ({
1622 actionId: {
1723 type: String as PropType <StudioItemActionId .CreateDocument | StudioItemActionId .CreateFolder | StudioItemActionId .RenameItem >,
@@ -48,6 +54,14 @@ const action = computed<StudioAction>(() => {
4854 return context .itemActions .value .find (action => action .id === props .actionId )!
4955})
5056
57+ const isFolderAction = computed (() => {
58+ return props .actionId === StudioItemActionId .CreateFolder
59+ || (
60+ props .actionId === StudioItemActionId .RenameItem
61+ && props .renamedItem .type === ' directory'
62+ )
63+ })
64+
5165const itemExtensionIcon = computed <string >(() => {
5266 return {
5367 md: ' i-ph-markdown-logo' ,
@@ -74,26 +88,25 @@ const tooltipText = computed(() => {
7488})
7589
7690function onSubmit(_event : FormSubmitEvent <Schema >) {
77- const fsPath = joinURL (props .parentItem .fsPath , ` ${state .name }.${state .extension } ` )
78-
7991 let params: CreateFileParams | CreateFolderParams | RenameFileParams
8092 switch (props .actionId ) {
8193 case StudioItemActionId .CreateDocument :
8294 params = {
95+ fsPath: withoutLeadingSlash (joinURL (props .parentItem .fsPath , ` ${state .name }.${state .extension } ` )),
8396 routePath: routePath .value ,
84- fsPath ,
8597 content: ` New ${state .name } file ` ,
8698 }
8799 break
88100 case StudioItemActionId .CreateFolder :
89101 params = {
90- fsPath ,
102+ fsPath: withoutLeadingSlash (joinURL (props .parentItem .fsPath , state .name )),
103+ routePath: routePath .value ,
91104 }
92105 break
93106 case StudioItemActionId .RenameItem :
94107 params = {
108+ newFsPath: withoutLeadingSlash (joinURL (props .parentItem .fsPath , ` ${state .name }.${state .extension } ` )),
95109 id: props .renamedItem .id ,
96- newFsPath: joinURL (props .parentItem .fsPath , ` ${state .name }.${state .extension } ` ),
97110 }
98111 break
99112 }
@@ -113,14 +126,11 @@ function onSubmit(_event: FormSubmitEvent<Schema>) {
113126 reverse
114127 class="hover:bg-white relative w-full min-w-0"
115128 >
116- <div class =" relative" >
117- <Image
118- src="https://placehold.co /1920x1080/f9fafc/f9fafc"
119- width="426"
120- height="240"
121- alt="Card placeholder"
122- class="z-[-1] rounded-t-lg"
123- />
129+ <div
130+ v-if =" !isFolderAction"
131+ class =" relative"
132+ >
133+ <div class =" z-[-1] aspect-video rounded-lg bg-elevated" />
124134 <div class =" absolute inset-0 flex items-center justify-center" >
125135 <UIcon
126136 :name =" itemExtensionIcon "
@@ -170,15 +180,23 @@ function onSubmit(_event: FormSubmitEvent<Schema>) {
170180 <template #error >
171181 <span />
172182 </template >
173- <UInput
174- v-model =" state .name "
175- variant="soft"
176- autofocus
177- placeholder="File name"
178- class="w-full"
179- />
183+ <div class =" flex items-center gap-1" >
184+ <UIcon
185+ v-if =" isFolderAction "
186+ name="i-lucide-folder"
187+ class="h-4 w-4 shrink-0 text-muted"
188+ />
189+ <UInput
190+ v-model =" state .name "
191+ variant="soft"
192+ autofocus
193+ :placeholder =" isFolderAction ? ' Folder name' : ' File name' "
194+ class="w-full"
195+ />
196+ </div >
180197 </UFormField >
181198 <UFormField
199+ v-if =" ! isFolderAction "
182200 name="extension"
183201 :ui =" { error: ' hidden' } "
184202 >
0 commit comments