@innertia-solutions/innertia-nuxt 0.1.81 → 0.1.83
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.
- package/CHANGELOG.md +1 -1
- package/components/Auth/PasskeyButton.vue +4 -2
- package/components/Auth/PasskeyInvite.vue +4 -2
- package/components/Auth/PasskeyManager.vue +10 -2
- package/components/Auth/PasskeySettings.vue +130 -0
- package/components/Files/DriveBrowser.vue +155 -0
- package/components/Files/DriveFolderField.vue +77 -0
- package/components/Files/DriveImport.vue +157 -0
- package/components/Files/ProviderOrigin.vue +70 -0
- package/components/Files/VersionHistory.vue +90 -0
- package/components/Files/__tests__/sfc-compile.test.ts +25 -0
- package/composables/useDriveBrowser/index.ts +72 -0
- package/composables/useDriveBrowser/internal/__tests__/browser.test.ts +97 -0
- package/composables/useDriveBrowser/internal/browser.ts +113 -0
- package/composables/useFileImports/index.ts +40 -0
- package/composables/useFileImports/internal/__tests__/progress.test.ts +65 -0
- package/composables/useFileImports/internal/progress.ts +100 -0
- package/composables/useFileVersions/index.ts +34 -0
- package/composables/useFileVersions/internal/__tests__/versions.test.ts +30 -0
- package/composables/useFileVersions/internal/versions.ts +52 -0
- package/composables/usePasskeys/index.ts +52 -2
- package/composables/usePasskeys/internal/__tests__/statusCache.test.ts +38 -0
- package/composables/usePasskeys/internal/statusCache.ts +43 -0
- package/docs/files-drive.md +112 -0
- package/docs/passkeys.md +12 -5
- package/nuxt.config.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,7 @@ All notable changes to `@innertia-solutions/innertia-nuxt` are documented here.
|
|
|
6
6
|
|
|
7
7
|
### Added
|
|
8
8
|
|
|
9
|
-
- Passkeys (WebAuthn): composable `usePasskeys()`, componentes `Auth.PasskeyButton` (login tenant y `/platform`, con autocompletado), `Auth.PasskeyInvite`, `Auth.PasskeyManager` y `Auth.UserPasskeys`, y rutas BFF `/_auth/passkey/login` y `/_auth/platform/passkey/login` que sellan la sesión solo si hay token.
|
|
9
|
+
- Passkeys (WebAuthn): composable `usePasskeys()`, componentes `Auth.PasskeyButton` (login tenant y `/platform`, con autocompletado), `Auth.PasskeyInvite`, `Auth.PasskeyManager` y `Auth.UserPasskeys`, y rutas BFF `/_auth/passkey/login` y `/_auth/platform/passkey/login` que sellan la sesión solo si hay token. Se activa y desactiva desde `/platform` con `Auth.PasskeySettings` (sin variables de entorno). Ver `docs/passkeys.md`.
|
|
10
10
|
- `Kanban.Standard`: reordenamiento intra-columna con drag&drop (prop `reorderEndpoint`); orden por `position`, placeholder de inserción, y persistencia vía POST. Retrocompatible: sin la prop se comporta igual que antes (solo cross-column).
|
|
11
11
|
|
|
12
12
|
### Fixed
|
|
@@ -6,6 +6,8 @@ import { IconFingerprint } from '@tabler/icons-vue'
|
|
|
6
6
|
// sin contexts el composable lanza 'PasskeyButton requiere contexts' antes de
|
|
7
7
|
// cualquier ceremonia (el backend exige al menos uno).
|
|
8
8
|
// - platform: login de /platform.
|
|
9
|
+
// - Solo se muestra si el navegador lo soporta y el interruptor de plataforma está
|
|
10
|
+
// encendido (GET auth/passkey/status); si no, no renderiza nada.
|
|
9
11
|
// - autofill: además arranca el autocompletado (el campo de correo del form
|
|
10
12
|
// debe tener autocomplete="username webauthn"; sin ese input no arranca).
|
|
11
13
|
// Emite success(data) con el body del BFF (data.context; data.tenantDestination
|
|
@@ -25,7 +27,7 @@ const props = defineProps({
|
|
|
25
27
|
})
|
|
26
28
|
const emit = defineEmits(['success', 'pending', 'error'])
|
|
27
29
|
|
|
28
|
-
const passkeys = usePasskeys()
|
|
30
|
+
const passkeys = usePasskeys({ platform: props.platform })
|
|
29
31
|
const loading = ref(false)
|
|
30
32
|
const error = ref('')
|
|
31
33
|
let mounted = false
|
|
@@ -86,7 +88,7 @@ onBeforeUnmount(() => {
|
|
|
86
88
|
</script>
|
|
87
89
|
|
|
88
90
|
<template>
|
|
89
|
-
<div v-if="passkeys.
|
|
91
|
+
<div v-if="passkeys.available.value" class="space-y-2">
|
|
90
92
|
<button
|
|
91
93
|
type="button"
|
|
92
94
|
:disabled="loading"
|
|
@@ -8,7 +8,7 @@ const props = defineProps({
|
|
|
8
8
|
base: { type: String, default: 'auth' },
|
|
9
9
|
})
|
|
10
10
|
|
|
11
|
-
const passkeys = usePasskeys()
|
|
11
|
+
const passkeys = usePasskeys({ platform: props.base === 'platform/auth' })
|
|
12
12
|
const authStore = useAuthStore()
|
|
13
13
|
const toast = useToast()
|
|
14
14
|
const visible = ref(false)
|
|
@@ -28,11 +28,13 @@ function dismiss() {
|
|
|
28
28
|
// usePasskeys resuelve `supported` en su propio onMounted, que corre antes que este.
|
|
29
29
|
onMounted(async () => {
|
|
30
30
|
if (!userId.value || !passkeys.supported.value) return
|
|
31
|
+
// Interruptor apagado: ni se consulta la lista.
|
|
32
|
+
if (!(await passkeys.ensureEnabled())) return
|
|
31
33
|
let hasPasskeys = true
|
|
32
34
|
try { hasPasskeys = (await passkeys.list(props.base)).length > 0 } catch { return }
|
|
33
35
|
visible.value = shouldShowPasskeyInvite({
|
|
34
36
|
supported: passkeys.supported.value,
|
|
35
|
-
enabled:
|
|
37
|
+
enabled: passkeys.enabled.value,
|
|
36
38
|
dismissed: dismissed(),
|
|
37
39
|
hasPasskeys,
|
|
38
40
|
loggedInWithPasskey: passkeys.loggedInWithPasskey(),
|
|
@@ -6,7 +6,7 @@ const props = defineProps({
|
|
|
6
6
|
base: { type: String, default: 'auth' },
|
|
7
7
|
})
|
|
8
8
|
|
|
9
|
-
const passkeys = usePasskeys()
|
|
9
|
+
const passkeys = usePasskeys({ platform: props.base === 'platform/auth' })
|
|
10
10
|
const toast = useToast()
|
|
11
11
|
const { confirm } = useModal()
|
|
12
12
|
const items = ref([])
|
|
@@ -22,6 +22,10 @@ const fmt = (iso) => iso ? new Date(iso).toLocaleDateString('es-CL', { day: 'num
|
|
|
22
22
|
async function load() {
|
|
23
23
|
loading.value = true
|
|
24
24
|
loadError.value = ''
|
|
25
|
+
if (!(await passkeys.ensureEnabled())) {
|
|
26
|
+
loading.value = false
|
|
27
|
+
return
|
|
28
|
+
}
|
|
25
29
|
try {
|
|
26
30
|
items.value = await passkeys.list(props.base)
|
|
27
31
|
} catch (e) {
|
|
@@ -99,7 +103,7 @@ onMounted(load)
|
|
|
99
103
|
<p class="mt-0.5 text-xs text-muted-foreground">Ingresa con tu huella, rostro o PIN del dispositivo, sin contraseña.</p>
|
|
100
104
|
</div>
|
|
101
105
|
<App.Button
|
|
102
|
-
v-if="passkeys.ready.value && passkeys.
|
|
106
|
+
v-if="passkeys.ready.value && passkeys.available.value"
|
|
103
107
|
text="Agregar en este dispositivo"
|
|
104
108
|
:icon="IconPlus"
|
|
105
109
|
severity="primary"
|
|
@@ -111,6 +115,10 @@ onMounted(load)
|
|
|
111
115
|
|
|
112
116
|
<div v-if="!passkeys.ready.value" class="px-5 py-6 text-sm text-muted-foreground">Cargando…</div>
|
|
113
117
|
|
|
118
|
+
<p v-else-if="!passkeys.enabled.value" class="px-5 py-4 text-sm text-muted-foreground">
|
|
119
|
+
El ingreso con passkey está desactivado.
|
|
120
|
+
</p>
|
|
121
|
+
|
|
114
122
|
<p v-else-if="!passkeys.supported.value" class="px-5 py-4 text-sm text-muted-foreground">
|
|
115
123
|
Este navegador no permite usar passkeys.
|
|
116
124
|
</p>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
// Consola /platform: interruptor del ingreso con passkey (guardado en BD).
|
|
3
|
+
// El producto registra las rutas con \Innertia\Passkeys\Routes::platformSettings('')
|
|
4
|
+
// en su grupo platform. GET/PUT platform/passkeys/settings.
|
|
5
|
+
const api = useApi()
|
|
6
|
+
const toast = useToast()
|
|
7
|
+
const passkeys = usePasskeys({ platform: true })
|
|
8
|
+
|
|
9
|
+
const settings = ref(null)
|
|
10
|
+
const loading = ref(true)
|
|
11
|
+
const loadError = ref('')
|
|
12
|
+
const saving = ref(false)
|
|
13
|
+
|
|
14
|
+
function errorText(e) {
|
|
15
|
+
return e?.data?.message || e?.message || 'No se pudo completar la operación.'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function load() {
|
|
19
|
+
loading.value = true
|
|
20
|
+
loadError.value = ''
|
|
21
|
+
try {
|
|
22
|
+
const res = await api.get('platform/passkeys/settings')
|
|
23
|
+
if (!res) throw new Error('Tu sesión expiró.')
|
|
24
|
+
settings.value = res
|
|
25
|
+
} catch (e) {
|
|
26
|
+
loadError.value = errorText(e)
|
|
27
|
+
} finally {
|
|
28
|
+
loading.value = false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Optimista: se refleja al instante y se revierte si el servidor falla.
|
|
33
|
+
async function toggle(key) {
|
|
34
|
+
if (!settings.value || saving.value) return
|
|
35
|
+
const previous = { ...settings.value }
|
|
36
|
+
const next = !settings.value[key]
|
|
37
|
+
settings.value = { ...settings.value, [key]: next }
|
|
38
|
+
saving.value = true
|
|
39
|
+
try {
|
|
40
|
+
const body = { enabled: key === 'enabled' ? next : previous.enabled }
|
|
41
|
+
if (key === 'allow_subdomains') body.allow_subdomains = next
|
|
42
|
+
const res = await api.put('platform/passkeys/settings', body)
|
|
43
|
+
if (!res) throw new Error('Tu sesión expiró.')
|
|
44
|
+
settings.value = res
|
|
45
|
+
await passkeys.refreshStatus()
|
|
46
|
+
toast.success('Configuración de passkeys guardada.')
|
|
47
|
+
} catch (e) {
|
|
48
|
+
settings.value = previous
|
|
49
|
+
toast.error(errorText(e))
|
|
50
|
+
} finally {
|
|
51
|
+
saving.value = false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onMounted(load)
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<template>
|
|
59
|
+
<div class="rounded-card border border-card-line bg-card">
|
|
60
|
+
<div class="border-b border-card-line px-5 py-4">
|
|
61
|
+
<h3 class="text-sm font-semibold text-foreground">Passkeys</h3>
|
|
62
|
+
<p class="mt-0.5 text-xs text-muted-foreground">Configuración del ingreso con passkey para todos los usuarios.</p>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<div v-if="loading" class="px-5 py-6 text-sm text-muted-foreground">Cargando…</div>
|
|
66
|
+
|
|
67
|
+
<div v-else-if="loadError" class="flex items-center justify-between gap-3 px-5 py-6" role="alert">
|
|
68
|
+
<p class="text-sm text-red-600">{{ loadError }}</p>
|
|
69
|
+
<App.Button text="Reintentar" size="sm" @click="load" />
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div v-else-if="settings" class="divide-y divide-card-line">
|
|
73
|
+
<div class="flex items-start justify-between gap-6 px-5 py-4">
|
|
74
|
+
<div class="space-y-1">
|
|
75
|
+
<p class="text-sm font-medium text-foreground">Ingreso con passkey</p>
|
|
76
|
+
<p class="text-sm text-muted-foreground">
|
|
77
|
+
Permite ingresar con huella, rostro o PIN del dispositivo. La contraseña sigue funcionando.
|
|
78
|
+
</p>
|
|
79
|
+
</div>
|
|
80
|
+
<button
|
|
81
|
+
type="button"
|
|
82
|
+
role="switch"
|
|
83
|
+
:aria-checked="!!settings.enabled"
|
|
84
|
+
:disabled="saving"
|
|
85
|
+
class="relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors focus:outline-hidden focus:ring-2 focus:ring-primary/30 disabled:opacity-50"
|
|
86
|
+
:class="settings.enabled ? 'bg-primary' : 'bg-slate-300 dark:bg-slate-600'"
|
|
87
|
+
@click="toggle('enabled')"
|
|
88
|
+
>
|
|
89
|
+
<span class="sr-only">Ingreso con passkey</span>
|
|
90
|
+
<span
|
|
91
|
+
class="inline-block size-5 rounded-full bg-white shadow transition-transform"
|
|
92
|
+
:class="settings.enabled ? 'translate-x-5' : 'translate-x-0.5'"
|
|
93
|
+
/>
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<div class="flex items-start justify-between gap-6 px-5 py-4">
|
|
98
|
+
<div class="space-y-1">
|
|
99
|
+
<p class="text-sm font-medium text-foreground">Permitir subdominios</p>
|
|
100
|
+
<p class="text-sm text-muted-foreground">
|
|
101
|
+
Las passkeys valen también en los subdominios de los tenants (por ejemplo, acme.{{ settings.rp_id }}).
|
|
102
|
+
Actívalo solo si los tenants viven en subdominios.
|
|
103
|
+
</p>
|
|
104
|
+
</div>
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
role="switch"
|
|
108
|
+
:aria-checked="!!settings.allow_subdomains"
|
|
109
|
+
:disabled="saving"
|
|
110
|
+
class="relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors focus:outline-hidden focus:ring-2 focus:ring-primary/30 disabled:opacity-50"
|
|
111
|
+
:class="settings.allow_subdomains ? 'bg-primary' : 'bg-slate-300 dark:bg-slate-600'"
|
|
112
|
+
@click="toggle('allow_subdomains')"
|
|
113
|
+
>
|
|
114
|
+
<span class="sr-only">Permitir subdominios</span>
|
|
115
|
+
<span
|
|
116
|
+
class="inline-block size-5 rounded-full bg-white shadow transition-transform"
|
|
117
|
+
:class="settings.allow_subdomains ? 'translate-x-5' : 'translate-x-0.5'"
|
|
118
|
+
/>
|
|
119
|
+
</button>
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<div class="space-y-1 px-5 py-4 text-xs text-muted-foreground">
|
|
123
|
+
<p>Dominio: <span class="font-medium text-foreground">{{ settings.rp_id }}</span></p>
|
|
124
|
+
<p v-if="settings.origins?.length">
|
|
125
|
+
Orígenes: <span class="text-foreground">{{ settings.origins.join(', ') }}</span>
|
|
126
|
+
</p>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
</template>
|
|
@@ -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>
|