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'
12+ import { upperFirst } from ' scule'
1213
1314const { context } = useStudio ()
1415
16+ defineShortcuts ({
17+ escape : () => {
18+ context .unsetActionInProgress ()
19+ },
20+ })
21+
1522const props = defineProps ({
1623 actionId: {
1724 type: String as PropType <StudioItemActionId .CreateDocument | StudioItemActionId .CreateFolder | StudioItemActionId .RenameItem >,
@@ -48,6 +55,14 @@ const action = computed<StudioAction>(() => {
4855 return context .itemActions .value .find (action => action .id === props .actionId )!
4956})
5057
58+ const isFolderAction = computed (() => {
59+ return props .actionId === StudioItemActionId .CreateFolder
60+ || (
61+ props .actionId === StudioItemActionId .RenameItem
62+ && props .renamedItem .type === ' directory'
63+ )
64+ })
65+
5166const itemExtensionIcon = computed <string >(() => {
5267 return {
5368 md: ' i-ph-markdown-logo' ,
@@ -74,26 +89,23 @@ const tooltipText = computed(() => {
7489})
7590
7691function onSubmit(_event : FormSubmitEvent <Schema >) {
77- const fsPath = joinURL (props .parentItem .fsPath , ` ${state .name }.${state .extension } ` )
78-
7992 let params: CreateFileParams | CreateFolderParams | RenameFileParams
8093 switch (props .actionId ) {
8194 case StudioItemActionId .CreateDocument :
8295 params = {
83- routePath: routePath .value ,
84- fsPath ,
85- content: ` New ${state .name } file ` ,
96+ fsPath: withoutLeadingSlash (joinURL (props .parentItem .fsPath , ` ${state .name }.${state .extension } ` )),
97+ content: ` # ${upperFirst (state .name )} file ` ,
8698 }
8799 break
88100 case StudioItemActionId .CreateFolder :
89101 params = {
90- fsPath ,
102+ fsPath: withoutLeadingSlash ( joinURL ( props . parentItem . fsPath , state . name )) ,
91103 }
92104 break
93105 case StudioItemActionId .RenameItem :
94106 params = {
107+ newFsPath: withoutLeadingSlash (joinURL (props .parentItem .fsPath , ` ${state .name }.${state .extension } ` )),
95108 id: props .renamedItem .id ,
96- newFsPath: joinURL (props .parentItem .fsPath , ` ${state .name }.${state .extension } ` ),
97109 }
98110 break
99111 }
@@ -113,14 +125,11 @@ function onSubmit(_event: FormSubmitEvent<Schema>) {
113125 reverse
114126 class =" hover:bg-white relative w-full min-w-0"
115127 >
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- />
128+ <div
129+ v-if =" !isFolderAction"
130+ class =" relative"
131+ >
132+ <div class =" z-[-1] aspect-video rounded-lg bg-elevated" />
124133 <div class =" absolute inset-0 flex items-center justify-center" >
125134 <UIcon
126135 :name =" itemExtensionIcon"
@@ -170,15 +179,23 @@ function onSubmit(_event: FormSubmitEvent<Schema>) {
170179 <template #error >
171180 <span />
172181 </template >
173- <UInput
174- v-model =" state.name"
175- variant =" soft"
176- autofocus
177- placeholder =" File name"
178- class =" w-full"
179- />
182+ <div class =" flex items-center gap-1" >
183+ <UIcon
184+ v-if =" isFolderAction"
185+ name =" i-lucide-folder"
186+ class =" h-4 w-4 shrink-0 text-muted"
187+ />
188+ <UInput
189+ v-model =" state.name"
190+ variant =" soft"
191+ autofocus
192+ :placeholder =" isFolderAction ? 'Folder name' : 'File name'"
193+ class =" w-full"
194+ />
195+ </div >
180196 </UFormField >
181197 <UFormField
198+ v-if =" !isFolderAction"
182199 name =" extension"
183200 :ui =" { error: 'hidden' }"
184201 >
0 commit comments