@innertia-solutions/innertia-nuxt 0.1.82 → 0.1.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,155 @@
1
+ <script setup>
2
+ /**
3
+ * <Files.DriveBrowser> — panel para navegar Google Drive (Mi unidad + unidades compartidas).
4
+ *
5
+ * mode="items" (default) v-model = DriveEntry[] seleccionados (multiple o single).
6
+ * mode="folder" solo carpetas; emite `pick` con {id,name} al elegir la carpeta actual.
7
+ * accept=['image/*'] limita qué archivos se pueden elegir (las carpetas solo se navegan).
8
+ *
9
+ * <Files.DriveBrowser drive-base="platform" v-model="selection" />
10
+ */
11
+ import { IconFolder, IconFile, IconPhoto, IconFileTypePdf, IconFileText, IconTable, IconPresentation, IconChevronRight, IconBrandGoogleDrive, IconUsersGroup, IconFolderPlus, IconCheck } from '@tabler/icons-vue'
12
+ import { isSelectable, toggleSelection } from '../../composables/useDriveBrowser/internal/browser'
13
+
14
+ const props = defineProps({
15
+ driveBase: { type: String, default: '' },
16
+ mode: { type: String, default: 'items', validator: v => ['items', 'folder'].includes(v) },
17
+ modelValue: { type: Array, default: () => [] },
18
+ multiple: { type: Boolean, default: true },
19
+ accept: { type: Array, default: () => [] },
20
+ /** Abre el panel en este ítem (id de carpeta) al montar. */
21
+ startAt: { type: String, default: null },
22
+ allowCreate: { type: Boolean, default: true },
23
+ })
24
+ const emit = defineEmits(['update:modelValue', 'pick'])
25
+
26
+ const toast = useToast()
27
+ const browser = useDriveBrowser(() => ({ base: props.driveBase, foldersOnly: props.mode === 'folder' }))
28
+
29
+ onMounted(async () => {
30
+ if (!props.startAt) return
31
+ try { await browser.openAt(props.startAt) } catch { /* sin acceso: queda en la raíz */ }
32
+ })
33
+
34
+ const selectedIds = computed(() => new Set(props.modelValue.map(e => e.id)))
35
+
36
+ function onRow(entry) {
37
+ if (entry.is_folder) {
38
+ browser.enter(entry)
39
+ return
40
+ }
41
+ if (props.mode === 'items' && isSelectable(entry, props.accept)) {
42
+ emit('update:modelValue', toggleSelection(props.modelValue, entry, props.multiple))
43
+ }
44
+ }
45
+
46
+ function toggleFolder(entry) {
47
+ if (props.mode === 'items' && isSelectable(entry, props.accept)) {
48
+ emit('update:modelValue', toggleSelection(props.modelValue, entry, props.multiple))
49
+ }
50
+ }
51
+
52
+ const creating = ref(false)
53
+ const newName = ref('')
54
+ async function createFolder() {
55
+ const name = newName.value.trim()
56
+ if (!name) return
57
+ try {
58
+ await browser.createFolder.mutateAsync(name)
59
+ newName.value = ''
60
+ creating.value = false
61
+ } catch (e) {
62
+ toast.error(e?.data?.message ?? 'No se pudo crear la carpeta.')
63
+ }
64
+ }
65
+
66
+ function iconFor(entry) {
67
+ if (entry.is_folder) return IconFolder
68
+ const m = entry.mime_type ?? ''
69
+ if (m.startsWith('image/')) return IconPhoto
70
+ if (m === 'application/pdf') return IconFileTypePdf
71
+ if (m.includes('spreadsheet')) return IconTable
72
+ if (m.includes('presentation')) return IconPresentation
73
+ if (m.includes('document') || m.startsWith('text/')) return IconFileText
74
+ return IconFile
75
+ }
76
+ </script>
77
+
78
+ <template>
79
+ <div class="space-y-3">
80
+ <!-- Unidades -->
81
+ <div class="flex flex-wrap gap-1.5">
82
+ <button type="button" class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-control border text-xs transition-colors"
83
+ :class="!browser.location.value.drive ? 'border-primary bg-primary/5 text-primary' : 'border-card-line text-muted-foreground hover:border-primary/50'"
84
+ @click="browser.selectDrive(null)">
85
+ <IconBrandGoogleDrive class="size-3.5" /> Mi unidad
86
+ </button>
87
+ <button v-for="d in browser.sharedDrives.value" :key="d.id" type="button"
88
+ class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-control border text-xs transition-colors"
89
+ :class="browser.location.value.drive?.id === d.id ? 'border-primary bg-primary/5 text-primary' : 'border-card-line text-muted-foreground hover:border-primary/50'"
90
+ @click="browser.selectDrive(d)">
91
+ <IconUsersGroup class="size-3.5" /> {{ d.name }}
92
+ </button>
93
+ </div>
94
+
95
+ <!-- Migas -->
96
+ <nav class="flex flex-wrap items-center gap-1 text-sm">
97
+ <template v-for="(c, i) in browser.breadcrumb.value" :key="c.id + i">
98
+ <IconChevronRight v-if="i > 0" class="size-3.5 text-muted-foreground" />
99
+ <button type="button" class="hover:text-primary truncate max-w-48"
100
+ :class="i === browser.breadcrumb.value.length - 1 ? 'text-foreground font-medium' : 'text-muted-foreground'"
101
+ @click="browser.goTo(i)">{{ c.name }}</button>
102
+ </template>
103
+ </nav>
104
+
105
+ <!-- Lista -->
106
+ <div class="rounded-control border border-card-line divide-y divide-card-line max-h-80 overflow-y-auto">
107
+ <p v-if="browser.isLoading.value && !browser.items.value.length" class="p-4 text-sm text-muted-foreground">Cargando…</p>
108
+ <p v-else-if="browser.error.value" class="p-4 text-sm text-red-600 dark:text-red-400">{{ browser.error.value }}</p>
109
+ <p v-else-if="!browser.items.value.length" class="p-4 text-sm text-muted-foreground">{{ mode === 'folder' ? 'Sin subcarpetas.' : 'Carpeta vacía.' }}</p>
110
+ <div v-for="entry in (browser.error.value ? [] : browser.items.value)" :key="entry.id"
111
+ class="flex items-center gap-2 px-3 py-2 text-sm"
112
+ :class="[
113
+ selectedIds.has(entry.id) ? 'bg-primary/5' : 'hover:bg-primary/5',
114
+ !entry.is_folder && mode === 'items' && !isSelectable(entry, accept) ? 'opacity-50' : 'cursor-pointer',
115
+ ]"
116
+ :role="entry.is_folder || (mode === 'items' && isSelectable(entry, accept)) ? 'button' : undefined"
117
+ :tabindex="entry.is_folder || (mode === 'items' && isSelectable(entry, accept)) ? 0 : undefined"
118
+ @click="onRow(entry)"
119
+ @keydown.enter.self.prevent="onRow(entry)"
120
+ @keydown.space.self.prevent="onRow(entry)">
121
+ <button v-if="mode === 'items' && isSelectable(entry, accept)" type="button"
122
+ class="size-4 shrink-0 rounded-control border flex items-center justify-center"
123
+ :class="selectedIds.has(entry.id) ? 'bg-primary border-primary text-white' : 'border-card-line'"
124
+ :aria-label="selectedIds.has(entry.id) ? 'Quitar de la selección' : 'Seleccionar'"
125
+ @click.stop="entry.is_folder ? toggleFolder(entry) : onRow(entry)">
126
+ <IconCheck v-if="selectedIds.has(entry.id)" class="size-3" />
127
+ </button>
128
+ <component :is="iconFor(entry)" class="size-4 shrink-0 text-muted-foreground" />
129
+ <span class="flex-1 truncate text-foreground">{{ entry.name }}</span>
130
+ <span v-if="entry.is_native" class="text-[10px] uppercase tracking-wide text-muted-foreground">Google</span>
131
+ <IconChevronRight v-if="entry.is_folder" class="size-3.5 text-muted-foreground" />
132
+ </div>
133
+ </div>
134
+
135
+ <!-- Acciones -->
136
+ <div class="flex flex-wrap items-center justify-between gap-2">
137
+ <form v-if="allowCreate && creating" class="flex flex-1 items-center gap-2" @submit.prevent="createFolder">
138
+ <input v-model="newName" autofocus placeholder="Nombre de la carpeta"
139
+ class="flex-1 h-8 rounded-control border border-card-line bg-card text-sm text-foreground px-3 focus:outline-hidden focus:ring-2 focus:ring-primary/30">
140
+ <AppButton text="Crear" severity="primary" size="sm" :loading="browser.createFolder.isPending.value" @click="createFolder" />
141
+ <AppButton text="Cancelar" severity="secondary" size="sm" @click="creating = false" />
142
+ </form>
143
+ <button v-else-if="allowCreate" type="button" class="inline-flex items-center gap-1.5 text-xs text-primary hover:underline disabled:opacity-50"
144
+ :disabled="!!browser.error.value" @click="creating = true">
145
+ <IconFolderPlus class="size-4" /> Nueva carpeta en “{{ browser.current.value.name }}”
146
+ </button>
147
+
148
+ <AppButton v-if="mode === 'folder'" :text="`Usar “${browser.current.value.name}”`" severity="primary" size="sm"
149
+ :disabled="!browser.canPickCurrent.value || !!browser.error.value"
150
+ @click="emit('pick', browser.current.value)" />
151
+ <span v-else-if="modelValue.length" class="text-xs text-muted-foreground">{{ modelValue.length }} seleccionado(s)</span>
152
+ </div>
153
+ <p v-if="mode === 'folder' && !browser.canPickCurrent.value" class="text-[11px] text-muted-foreground">Entra a una carpeta (o crea una) para elegirla.</p>
154
+ </div>
155
+ </template>
@@ -0,0 +1,77 @@
1
+ <script setup>
2
+ /**
3
+ * <Files.DriveFolderField> — campo "carpeta de Google Drive" (v-model = id de carpeta).
4
+ * Muestra nombre + ruta + enlace, y abre <Files.DriveBrowser mode="folder"> en un modal.
5
+ *
6
+ * <Files.DriveFolderField v-model="form.drive_folder_id" drive-base="platform" />
7
+ */
8
+ import { IconBrandGoogleDrive, IconExternalLink, IconX } from '@tabler/icons-vue'
9
+
10
+ const props = defineProps({
11
+ modelValue: { type: String, default: '' },
12
+ driveBase: { type: String, default: '' },
13
+ title: { type: String, default: 'Elegir carpeta de Drive' },
14
+ })
15
+ const emit = defineEmits(['update:modelValue'])
16
+
17
+ const { info } = useDriveBrowser(() => ({ base: props.driveBase, foldersOnly: true, enabled: false }))
18
+ const current = ref(null) // { item, path }
19
+ const error = ref(null)
20
+ const open = ref(false)
21
+
22
+ let seq = 0
23
+ async function load(id) {
24
+ const mine = ++seq
25
+ current.value = null
26
+ error.value = null
27
+ if (!id) return
28
+ try {
29
+ const res = await info(id)
30
+ if (mine === seq) current.value = res
31
+ } catch (e) {
32
+ if (mine === seq) error.value = e?.data?.message ?? 'No se pudo leer la carpeta.'
33
+ }
34
+ }
35
+ watch(() => props.modelValue, load, { immediate: true })
36
+
37
+ const pathLabel = computed(() => (current.value?.path ?? []).map(c => c.name).join(' › '))
38
+
39
+ function onPick(folder) {
40
+ emit('update:modelValue', folder.id)
41
+ open.value = false
42
+ }
43
+ </script>
44
+
45
+ <template>
46
+ <div>
47
+ <div class="flex items-center gap-2 rounded-control border border-card-line bg-card px-3 min-h-9 py-1.5">
48
+ <IconBrandGoogleDrive class="size-4 shrink-0 text-muted-foreground" />
49
+ <div class="flex-1 min-w-0 text-sm">
50
+ <span v-if="!modelValue" class="text-muted-foreground">Sin carpeta elegida</span>
51
+ <template v-else-if="current">
52
+ <p class="text-foreground truncate font-medium">{{ current.item.name }}</p>
53
+ <p v-if="pathLabel" class="text-[11px] text-muted-foreground truncate">{{ pathLabel }}</p>
54
+ </template>
55
+ <template v-else-if="error">
56
+ <p class="text-foreground truncate font-mono text-xs">{{ modelValue }}</p>
57
+ <p class="text-[11px] text-red-600 dark:text-red-400 truncate">{{ error }}</p>
58
+ </template>
59
+ <span v-else class="text-muted-foreground">Cargando…</span>
60
+ </div>
61
+ <a v-if="current?.item?.web_url" :href="current.item.web_url" target="_blank" rel="noopener" class="text-muted-foreground hover:text-primary" title="Abrir en Drive">
62
+ <IconExternalLink class="size-4" />
63
+ </a>
64
+ <button v-if="modelValue" type="button" class="text-muted-foreground hover:text-red-600" title="Quitar" @click="emit('update:modelValue', '')">
65
+ <IconX class="size-4" />
66
+ </button>
67
+ <AppButton :text="modelValue ? 'Cambiar' : 'Elegir carpeta'" severity="secondary" size="sm" @click="open = true" />
68
+ </div>
69
+
70
+ <ModalForm v-model="open" :title="title" size="lg">
71
+ <FilesDriveBrowser v-if="open" mode="folder" :drive-base="driveBase" :start-at="modelValue || null" @pick="onPick" />
72
+ <template #footer>
73
+ <AppButton text="Cerrar" severity="secondary" size="sm" @click="open = false" />
74
+ </template>
75
+ </ModalForm>
76
+ </div>
77
+ </template>
@@ -0,0 +1,157 @@
1
+ <script setup>
2
+ /**
3
+ * <Files.DriveImport> — modal autocontenido para importar desde Google Drive al storage.
4
+ * Pasos: elegir → opciones → progreso/resumen. Cerrar no cancela (el proceso sigue en cola);
5
+ * `resume-id` permite reabrir el seguimiento de un import en curso.
6
+ *
7
+ * <Files.DriveImport v-model="showImport" drive-base="platform" :directory-id="currentDir?.id" @done="refetch" />
8
+ */
9
+ import { IconCircleCheck, IconAlertTriangle, IconLoader2, IconChevronDown } from '@tabler/icons-vue'
10
+ import { groupItems, itemLabel, isFinished, progressPercent, selectionFlags } from '../../composables/useFileImports/internal/progress'
11
+
12
+ const props = defineProps({
13
+ modelValue: { type: Boolean, default: false },
14
+ driveBase: { type: String, default: '' },
15
+ directoryId: { type: String, default: null },
16
+ /** Si el producto tiene Directories apagado: avisa y bloquea carpetas. */
17
+ foldersAllowed: { type: Boolean, default: true },
18
+ visibility: { type: String, default: null },
19
+ resumeId: { type: String, default: null },
20
+ })
21
+ const emit = defineEmits(['update:modelValue', 'done'])
22
+
23
+ const toast = useToast()
24
+ const { start, track } = useFileImports(() => props.driveBase)
25
+
26
+ const step = ref('pick') // pick | options | progress
27
+ const selection = ref([])
28
+ const nativeFormat = ref('office')
29
+ const importId = ref(null)
30
+ const tracker = track(importId)
31
+ const current = computed(() => tracker.data.value ?? null)
32
+
33
+ const flags = computed(() => selectionFlags(selection.value))
34
+ const blockedFolders = computed(() => flags.value.hasFolders && !props.foldersAllowed)
35
+
36
+ watch(() => props.modelValue, (open) => {
37
+ if (!open) return
38
+ if (props.resumeId) {
39
+ importId.value = props.resumeId
40
+ step.value = 'progress'
41
+ } else if (step.value !== 'progress' || isFinished(current.value?.status) || tracker.isError.value) {
42
+ step.value = 'pick'
43
+ selection.value = []
44
+ importId.value = null
45
+ }
46
+ }, { immediate: true })
47
+
48
+ watch(() => current.value?.status, (status) => {
49
+ if (isFinished(status)) emit('done', current.value)
50
+ })
51
+
52
+ function close() { emit('update:modelValue', false) }
53
+
54
+ async function launch() {
55
+ try {
56
+ const imp = await start.mutateAsync({ items: selection.value, directoryId: props.directoryId, nativeFormat: nativeFormat.value, visibility: props.visibility })
57
+ importId.value = imp.id
58
+ step.value = 'progress'
59
+ } catch (e) {
60
+ toast.error(e?.data?.message ?? 'No se pudo iniciar la importación.')
61
+ }
62
+ }
63
+
64
+ /** Siempre pasa por opciones: muestra el conteo, el formato si hay nativos y el aviso de carpetas. */
65
+ function next() {
66
+ step.value = 'options'
67
+ }
68
+
69
+ const percent = computed(() => (current.value ? progressPercent(current.value) : null))
70
+ const groups = computed(() => groupItems(current.value?.items ?? []))
71
+ const expanded = reactive({})
72
+ </script>
73
+
74
+ <template>
75
+ <ModalForm :model-value="modelValue" title="Importar desde Google Drive" size="lg" @update:model-value="emit('update:modelValue', $event)">
76
+ <!-- 1. Elegir -->
77
+ <div v-if="step === 'pick'" class="space-y-2">
78
+ <p class="text-xs text-muted-foreground">Elige archivos y carpetas. Se copian a este directorio; las carpetas se importan con todo su contenido.</p>
79
+ <FilesDriveBrowser v-model="selection" :drive-base="driveBase" />
80
+ </div>
81
+
82
+ <!-- 2. Opciones -->
83
+ <div v-else-if="step === 'options'" class="space-y-4">
84
+ <p class="text-sm text-foreground">{{ selection.length }} elemento(s) seleccionado(s).</p>
85
+
86
+ <div v-if="flags.hasNatives" class="space-y-2">
87
+ <p class="text-sm font-medium text-foreground">Documentos de Google (Docs, Sheets, Slides)</p>
88
+ <label class="flex items-start gap-2 text-sm">
89
+ <input v-model="nativeFormat" type="radio" value="office" class="mt-0.5">
90
+ <span><span class="text-foreground">Formato Office</span> <span class="text-muted-foreground">(.docx, .xlsx, .pptx — editables)</span></span>
91
+ </label>
92
+ <label class="flex items-start gap-2 text-sm">
93
+ <input v-model="nativeFormat" type="radio" value="pdf" class="mt-0.5">
94
+ <span><span class="text-foreground">PDF</span> <span class="text-muted-foreground">(foto fiel, no editable)</span></span>
95
+ </label>
96
+ <p class="text-[11px] text-muted-foreground">Formularios, sitios y accesos directos no se importan.</p>
97
+ </div>
98
+
99
+ <div v-if="blockedFolders" class="rounded-control border border-amber-200 bg-amber-50 dark:border-amber-500/30 dark:bg-amber-500/10 p-3 text-xs text-amber-800 dark:text-amber-300">
100
+ Este explorador no admite carpetas: quita las carpetas de la selección.
101
+ </div>
102
+ </div>
103
+
104
+ <!-- 3. Progreso / resumen -->
105
+ <div v-else class="space-y-4">
106
+ <p v-if="!current && tracker.isError.value" class="text-sm text-red-600 dark:text-red-400">{{ tracker.error.value?.data?.message ?? 'No se pudo consultar el estado de la importación.' }}</p>
107
+ <div v-else-if="!current" class="flex items-center gap-2 text-sm text-muted-foreground"><IconLoader2 class="size-4 animate-spin" /> Iniciando…</div>
108
+ <template v-else>
109
+ <div class="flex items-center gap-2 text-sm font-medium"
110
+ :class="current.status === 'failed' ? 'text-red-600 dark:text-red-400' : current.status === 'done' ? 'text-emerald-700 dark:text-emerald-400' : 'text-foreground'">
111
+ <IconLoader2 v-if="!isFinished(current.status)" class="size-4 animate-spin" />
112
+ <IconCircleCheck v-else-if="current.status === 'done'" class="size-4" />
113
+ <IconAlertTriangle v-else class="size-4" />
114
+ {{ current.status === 'done' ? 'Importación terminada' : current.status === 'failed' ? 'La importación falló' : 'Importando… puedes cerrar esta ventana' }}
115
+ </div>
116
+ <p v-if="current.error" class="text-xs text-red-600 dark:text-red-400">{{ current.error }}</p>
117
+
118
+ <div v-if="!isFinished(current.status)" class="h-2 rounded-control bg-card-line overflow-hidden">
119
+ <div class="h-full bg-primary transition-all" :class="percent === null ? 'w-1/3 animate-pulse' : ''" :style="percent === null ? {} : { width: `${percent}%` }" />
120
+ </div>
121
+
122
+ <div class="grid grid-cols-5 gap-2 text-center">
123
+ <div v-for="k in ['imported', 'updated', 'unchanged', 'skipped', 'failed']" :key="k" class="rounded-control border border-card-line p-2">
124
+ <p class="text-base font-semibold text-foreground">{{ current[k] }}</p>
125
+ <p class="text-[10px] text-muted-foreground">{{ { imported: 'Importados', updated: 'Actualizados', unchanged: 'Sin cambios', skipped: 'Omitidos', failed: 'Con error' }[k] }}</p>
126
+ </div>
127
+ </div>
128
+
129
+ <div v-for="g in groups" :key="g.result" class="rounded-control border border-card-line">
130
+ <button type="button" class="w-full flex items-center justify-between px-3 py-2 text-sm text-foreground" @click="expanded[g.result] = !expanded[g.result]">
131
+ <span>{{ g.label }} ({{ g.items.length }})</span>
132
+ <IconChevronDown class="size-4 transition-transform" :class="expanded[g.result] ? 'rotate-180' : ''" />
133
+ </button>
134
+ <ul v-if="expanded[g.result]" class="border-t border-card-line max-h-48 overflow-y-auto divide-y divide-card-line">
135
+ <li v-for="(item, i) in g.items" :key="i" class="px-3 py-1.5 text-xs">
136
+ <p class="text-foreground truncate">{{ itemLabel(item) }}</p>
137
+ <p v-if="item.reason" class="text-muted-foreground">{{ item.reason }}</p>
138
+ </li>
139
+ </ul>
140
+ </div>
141
+ </template>
142
+ </div>
143
+
144
+ <template #footer>
145
+ <div class="flex w-full items-center justify-between gap-2">
146
+ <AppButton v-if="step === 'options'" text="Atrás" severity="secondary" size="sm" @click="step = 'pick'" />
147
+ <span v-else />
148
+ <div class="flex gap-2">
149
+ <AppButton :text="step === 'progress' ? 'Cerrar' : 'Cancelar'" severity="secondary" size="sm" @click="close" />
150
+ <AppButton v-if="step === 'pick'" text="Siguiente" severity="primary" size="sm" :disabled="!selection.length" @click="next" />
151
+ <AppButton v-else-if="step === 'options'" text="Importar" severity="primary" size="sm"
152
+ :disabled="!selection.length || blockedFolders" :loading="start.isPending.value" @click="launch" />
153
+ </div>
154
+ </div>
155
+ </template>
156
+ </ModalForm>
157
+ </template>
@@ -0,0 +1,70 @@
1
+ <script setup>
2
+ /**
3
+ * <Files.ProviderOrigin> — franja "Importado de Google Drive" con "Actualizar" y "Abrir en Drive".
4
+ * Solo se muestra si el archivo vino de un proveedor (file.provider). El botón aparece si
5
+ * file.can_refresh (fuente disponible). Emite `changed` cuando hubo versión nueva.
6
+ *
7
+ * <Files.ProviderOrigin :file="file" drive-base="platform" @changed="refetch" />
8
+ */
9
+ import { IconBrandGoogleDrive, IconRefresh, IconExternalLink } from '@tabler/icons-vue'
10
+ import { isFinished, refreshOutcome } from '../../composables/useFileImports/internal/progress'
11
+
12
+ const props = defineProps({
13
+ file: { type: Object, required: true },
14
+ driveBase: { type: String, default: '' },
15
+ })
16
+ const emit = defineEmits(['changed'])
17
+
18
+ const toast = useToast()
19
+ const queryClient = useQueryClient()
20
+ const { refresh, track } = useFileImports(() => props.driveBase)
21
+ const importId = ref(null)
22
+ const tracker = track(importId)
23
+ const busy = computed(() => refresh.isPending.value || (!!importId.value && !isFinished(tracker.data.value?.status)))
24
+
25
+ const syncedLabel = computed(() => {
26
+ const at = props.file.external_synced_at
27
+ return at ? new Date(at).toLocaleString('es-CL', { dateStyle: 'medium', timeStyle: 'short' }) : null
28
+ })
29
+
30
+ async function onRefresh() {
31
+ try {
32
+ const imp = await refresh.mutateAsync(props.file.id)
33
+ importId.value = imp.id
34
+ } catch (e) {
35
+ toast.error(e?.data?.message ?? 'No se pudo actualizar desde Google Drive.')
36
+ }
37
+ }
38
+
39
+ watch(() => tracker.data.value?.status, (status) => {
40
+ if (!isFinished(status)) return
41
+ const outcome = refreshOutcome(tracker.data.value)
42
+ if (outcome.kind === 'failed') toast.error(outcome.message)
43
+ else toast.success(outcome.message)
44
+ if (outcome.kind === 'updated') {
45
+ queryClient.invalidateQueries({ queryKey: ['files', 'versions'] })
46
+ emit('changed')
47
+ }
48
+ importId.value = null
49
+ })
50
+
51
+ // Sin esto, un error al consultar el estado deja el botón cargando para siempre.
52
+ watch(() => tracker.isError.value, (failed) => {
53
+ if (!failed || !importId.value) return
54
+ toast.error(tracker.error.value?.data?.message ?? 'No se pudo consultar el estado de la actualización.')
55
+ importId.value = null
56
+ })
57
+ </script>
58
+
59
+ <template>
60
+ <div v-if="file.provider" class="flex flex-wrap items-center gap-2 rounded-control border border-card-line bg-card px-3 py-2 text-xs">
61
+ <IconBrandGoogleDrive class="size-4 shrink-0 text-muted-foreground" />
62
+ <span class="flex-1 min-w-0 text-muted-foreground">
63
+ Importado de Google Drive<template v-if="syncedLabel"> · sincronizado {{ syncedLabel }}</template>
64
+ </span>
65
+ <a v-if="file.external_url" :href="file.external_url" target="_blank" rel="noopener" class="inline-flex items-center gap-1 text-muted-foreground hover:text-primary">
66
+ <IconExternalLink class="size-3.5" /> Abrir en Drive
67
+ </a>
68
+ <AppButton v-if="file.can_refresh" text="Actualizar" :icon="IconRefresh" severity="secondary" size="xs" :loading="busy" @click="onRefresh" />
69
+ </div>
70
+ </template>
@@ -0,0 +1,90 @@
1
+ <script setup>
2
+ /**
3
+ * <Files.VersionHistory> — historial de versiones de un archivo: descargar cualquiera,
4
+ * restaurar (crea una versión nueva) y subir una versión nueva.
5
+ *
6
+ * <Files.VersionHistory files-base="platform/files" :file-id="file.id" @changed="refetch" />
7
+ */
8
+ import { IconDownload, IconRestore, IconUpload, IconHistory } from '@tabler/icons-vue'
9
+ import { versionSourceLabel, formatBytes, versionResultMessage } from '../../composables/useFileVersions/internal/versions'
10
+
11
+ const props = defineProps({
12
+ filesBase: { type: String, required: true },
13
+ fileId: { type: String, required: true },
14
+ allowRestore: { type: Boolean, default: true },
15
+ allowUpload: { type: Boolean, default: true },
16
+ })
17
+ const emit = defineEmits(['changed'])
18
+
19
+ const toast = useToast()
20
+ const { confirm } = useModal()
21
+ const { list, restore, replace } = useFileVersions(() => ({ filesBase: props.filesBase, fileId: props.fileId }))
22
+ const versions = computed(() => list.data.value ?? [])
23
+ const restoring = ref(null)
24
+
25
+ function fmtDate(v) {
26
+ return v ? new Date(v).toLocaleString('es-CL', { dateStyle: 'medium', timeStyle: 'short' }) : '—'
27
+ }
28
+
29
+ async function onRestore(v) {
30
+ if (!await confirm({ title: `Restaurar v${v.version}`, message: 'Se creará una versión nueva con este contenido. El historial no se borra.', confirmText: 'Restaurar' })) return
31
+ restoring.value = v.version
32
+ try {
33
+ const res = await restore.mutateAsync(v.version)
34
+ toast.success(versionResultMessage(res))
35
+ if (res.status === 'created') emit('changed', res.file)
36
+ } catch (e) {
37
+ toast.error(e?.data?.message ?? 'No se pudo restaurar la versión.')
38
+ } finally {
39
+ restoring.value = null
40
+ }
41
+ }
42
+
43
+ const picker = ref(null)
44
+ async function onPick(e) {
45
+ const file = e.target.files?.[0]
46
+ e.target.value = ''
47
+ if (!file) return
48
+ try {
49
+ const res = await replace.mutateAsync(file)
50
+ toast.success(versionResultMessage(res))
51
+ if (res.status === 'created') emit('changed', res.file)
52
+ } catch (err) {
53
+ toast.error(err?.data?.message ?? 'No se pudo subir la nueva versión.')
54
+ }
55
+ }
56
+ </script>
57
+
58
+ <template>
59
+ <div class="rounded-card border border-card-line bg-card">
60
+ <div class="flex items-center justify-between gap-2 px-4 py-3 border-b border-card-line">
61
+ <p class="flex items-center gap-1.5 text-sm font-medium text-foreground"><IconHistory class="size-4 text-muted-foreground" /> Versiones</p>
62
+ <template v-if="allowUpload">
63
+ <input ref="picker" type="file" class="hidden" @change="onPick">
64
+ <AppButton text="Subir nueva versión" :icon="IconUpload" severity="secondary" size="xs" :loading="replace.isPending.value" @click="picker?.click()" />
65
+ </template>
66
+ </div>
67
+
68
+ <p v-if="list.isLoading.value" class="px-4 py-3 text-sm text-muted-foreground">Cargando…</p>
69
+ <p v-else-if="list.error.value" class="px-4 py-3 text-sm text-red-600 dark:text-red-400">{{ list.error.value?.data?.message ?? 'No se pudo cargar el historial.' }}</p>
70
+ <ul v-else class="divide-y divide-card-line">
71
+ <li v-for="v in versions" :key="v.version" class="flex items-center gap-3 px-4 py-2.5 text-sm">
72
+ <span class="w-9 shrink-0 font-mono text-xs" :class="v.is_current ? 'text-primary font-semibold' : 'text-muted-foreground'">v{{ v.version }}</span>
73
+ <div class="flex-1 min-w-0">
74
+ <p class="text-foreground truncate">
75
+ {{ versionSourceLabel(v.source, v.restored_from_version) }}
76
+ <span v-if="v.is_current" class="ml-1 rounded-control bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary">Vigente</span>
77
+ </p>
78
+ <p class="text-[11px] text-muted-foreground">{{ fmtDate(v.created_at) }} · {{ formatBytes(v.size) }}</p>
79
+ </div>
80
+ <a v-if="v.download_url" :href="v.download_url" class="text-muted-foreground hover:text-primary" title="Descargar">
81
+ <IconDownload class="size-4" />
82
+ </a>
83
+ <button v-if="allowRestore && !v.is_current" type="button" class="text-muted-foreground hover:text-primary disabled:opacity-50"
84
+ :disabled="restoring !== null" title="Restaurar" @click="onRestore(v)">
85
+ <IconRestore class="size-4" :class="restoring === v.version ? 'animate-spin' : ''" />
86
+ </button>
87
+ </li>
88
+ </ul>
89
+ </div>
90
+ </template>
@@ -0,0 +1,25 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { readFileSync } from 'node:fs'
3
+ import { resolve } from 'node:path'
4
+ import { parse, compileScript, compileTemplate } from 'vue/compiler-sfc'
5
+
6
+ const COMPONENTS = ['DriveBrowser', 'DriveFolderField', 'DriveImport', 'VersionHistory', 'ProviderOrigin']
7
+
8
+ describe('SFC de Files (Drive y versiones) compilan', () => {
9
+ for (const name of COMPONENTS) {
10
+ it(name, () => {
11
+ const filename = resolve(__dirname, `../${name}.vue`)
12
+ const { descriptor, errors } = parse(readFileSync(filename, 'utf8'), { filename })
13
+ expect(errors).toEqual([])
14
+
15
+ const script = compileScript(descriptor, { id: name })
16
+ const tpl = compileTemplate({
17
+ source: descriptor.template!.content,
18
+ filename,
19
+ id: name,
20
+ compilerOptions: { bindingMetadata: script.bindings },
21
+ })
22
+ expect(tpl.errors).toEqual([])
23
+ })
24
+ }
25
+ })
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { ref, computed, watch, nextTick } from 'vue'
2
+ import { ref, computed, watch, nextTick, useAttrs } from 'vue'
3
3
 
4
4
  /*
5
5
  * CurrencyInput — input de moneda con formato SOLO visual.
@@ -72,15 +72,29 @@ function onBlur() {
72
72
  const baseClasses = computed(() =>
73
73
  `innertia-field${props.size === 'sm' ? ' innertia-field-sm' : ''}`,
74
74
  )
75
+ // Los atributos no declarados (maxlength, min, max, step, required, inputmode,
76
+ // name, id, aria-*, data-*) y los listeners (@blur, @keydown, @focus…) van al
77
+ // <input>; solo class/style quedan en el <div> raíz para no romper el layout.
78
+ defineOptions({ inheritAttrs: false })
79
+ const attrs = useAttrs()
80
+ // Funciones (no computed): useAttrs() no es reactivo, el render sí se re-ejecuta.
81
+ function rootAttrs() {
82
+ return { class: attrs.class, style: attrs.style }
83
+ }
84
+ function inputAttrs() {
85
+ const { class: _class, style: _style, ...rest } = attrs
86
+ return rest
87
+ }
75
88
  </script>
76
89
 
77
90
  <template>
78
- <div class="w-full">
91
+ <div class="w-full" v-bind="rootAttrs()">
79
92
  <label v-if="label" class="block text-sm font-medium text-foreground mb-1.5">
80
93
  {{ label }}
81
94
  </label>
82
95
 
83
96
  <input
97
+ v-bind="inputAttrs()"
84
98
  ref="inputEl"
85
99
  type="text"
86
100
  inputmode="numeric"
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { ref, computed } from 'vue'
2
+ import { ref, computed, useAttrs } from 'vue'
3
3
  import { IconEye, IconEyeOff } from '@tabler/icons-vue'
4
4
 
5
5
  const props = defineProps<{
@@ -27,10 +27,23 @@ const inputType = computed(() => {
27
27
  const baseClasses = computed(() =>
28
28
  `innertia-field${props.size === 'sm' ? ' innertia-field-sm' : ''}`
29
29
  )
30
+ // Los atributos no declarados (maxlength, min, max, step, required, inputmode,
31
+ // name, id, aria-*, data-*) y los listeners (@blur, @keydown, @focus…) van al
32
+ // <input>; solo class/style quedan en el <div> raíz para no romper el layout.
33
+ defineOptions({ inheritAttrs: false })
34
+ const attrs = useAttrs()
35
+ // Funciones (no computed): useAttrs() no es reactivo, el render sí se re-ejecuta.
36
+ function rootAttrs() {
37
+ return { class: attrs.class, style: attrs.style }
38
+ }
39
+ function inputAttrs() {
40
+ const { class: _class, style: _style, ...rest } = attrs
41
+ return rest
42
+ }
30
43
  </script>
31
44
 
32
45
  <template>
33
- <div class="w-full">
46
+ <div class="w-full" v-bind="rootAttrs()">
34
47
  <label v-if="label" class="block text-sm font-medium text-foreground mb-1.5">
35
48
  {{ label }}
36
49
  </label>
@@ -42,6 +55,7 @@ const baseClasses = computed(() =>
42
55
  </div>
43
56
 
44
57
  <input
58
+ v-bind="inputAttrs()"
45
59
  v-model="modelValue"
46
60
  :type="inputType"
47
61
  :placeholder="placeholder"