@innertia-solutions/innertia-nuxt 0.1.9 → 0.1.11

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.
@@ -1,10 +1,12 @@
1
1
  <script setup>
2
2
  import {
3
- IconLoader2, IconSearch, IconRefresh, IconPlus,
3
+ IconLoader2, IconSearch, IconRefresh, IconPlus, IconBolt, IconReload,
4
4
  IconLayoutColumns, IconChevronDown, IconX, IconDownload,
5
5
  IconFileTypeXls, IconFileTypeCsv, IconFileTypePdf, IconCodeDots,
6
6
  } from '@tabler/icons-vue'
7
7
 
8
+ const slots = useSlots()
9
+
8
10
  const props = defineProps({
9
11
  // Required: backend route that returns DataTree-shaped responses.
10
12
  endpoint: { type: String, required: true },
@@ -31,6 +33,11 @@ const props = defineProps({
31
33
  showExport: { type: Boolean, default: true },
32
34
  showReloadButton: { type: Boolean, default: true },
33
35
 
36
+ // Cacheo en sessionStorage. Cuando true, al montar el componente intenta
37
+ // restaurar la última respuesta cacheada (≤10 min) y muestra el badge
38
+ // "Instant" hasta que el usuario haga reload manual.
39
+ cached: { type: Boolean, default: false },
40
+
34
41
  // Checkbox selection (multi-select).
35
42
  checkable: { type: Boolean, default: false },
36
43
 
@@ -40,11 +47,26 @@ const props = defineProps({
40
47
 
41
48
  // Empty state.
42
49
  emptyMessage: { type: String, default: 'No hay registros.' },
50
+
51
+ // Variante visual:
52
+ // 'table' — clásico con filas, columnas y bordes (default)
53
+ // 'list' — compacto tipo file-tree explorer (sin tabla, sin bordes de fila)
54
+ variant: { type: String, default: 'table' },
55
+
56
+ // ─── Preview overlay panel (mismo patrón que Table.Standard) ───────────
57
+ // El panel se activa automáticamente si el consumer declara <slot name="preview">.
58
+ // Click en una fila → set previewRow → overlay absoluto sobre la derecha de la tabla.
59
+ previewHref: { type: [String, Function], default: null },
60
+ previewDeletable: { type: Boolean, default: false },
61
+ autoClosePreview: { type: Boolean, default: true },
62
+ /** Porcentaje inicial de la tabla (0-100). El resto lo ocupa el preview. */
63
+ splitRatio: { type: Number, default: 55 },
43
64
  })
44
65
 
45
66
  const emit = defineEmits([
46
67
  'row-click', 'loaded', 'expand',
47
68
  'update:checked', 'export',
69
+ 'preview-delete',
48
70
  ])
49
71
 
50
72
  const api = useApi()
@@ -54,6 +76,47 @@ const roots = ref([])
54
76
  const meta = ref(null)
55
77
  const loading = ref(false)
56
78
  const isFetching = ref(false)
79
+ const isDataFromCache = ref(false)
80
+
81
+ // ─── Preview state — la UI vive en <DataPreview>, este file solo le pasa la fila activa ─
82
+ const previewEnabled = computed(() => !!slots.preview)
83
+ const previewRow = ref(null)
84
+ const containerRef = ref(null)
85
+ const dataPreviewRef = ref(null)
86
+
87
+ const closePreview = () => { previewRow.value = null }
88
+
89
+ // Endpoint de historial — derivado del meta del backend.
90
+ // El backend debe devolver { meta: { has_history: true, entity_type: 'departments' } }
91
+ // para activar el tab "Bitácora" del DataPreview.
92
+ const resolvedHistoryEndpoint = computed(() => {
93
+ if (!meta.value?.has_history || !previewRow.value?.id || !meta.value?.entity_type) return null
94
+ return `history/${meta.value.entity_type}/${previewRow.value.id}`
95
+ })
96
+
97
+ const { collapseDock } = useDockedPreviews()
98
+
99
+ const handleRowClick = (node) => {
100
+ emit('row-click', node)
101
+ if (!previewEnabled.value) return
102
+ if (previewRow.value?.id === node.id) return
103
+ collapseDock()
104
+ previewRow.value = node
105
+ }
106
+
107
+ // ESC + click-fuera (la UI los maneja, este file detecta cuándo cerrar).
108
+ const onEsc = (e) => {
109
+ if (e.key !== 'Escape') return
110
+ if (previewRow.value) closePreview()
111
+ else collapseDock()
112
+ }
113
+ const onDocMousedown = (e) => {
114
+ if (!props.autoClosePreview || !previewRow.value) return
115
+ const panelEl = dataPreviewRef.value?.panelRef
116
+ if (containerRef.value?.contains(e.target)) return
117
+ if (panelEl?.contains(e.target)) return
118
+ closePreview()
119
+ }
57
120
  const search = ref('')
58
121
  const expandedSet = ref(new Set())
59
122
  const loadingSet = ref(new Set())
@@ -107,11 +170,13 @@ const buildBody = (extra = {}) => ({
107
170
  const fetchInitial = async () => {
108
171
  loading.value = true
109
172
  isFetching.value = true
173
+ isDataFromCache.value = false
110
174
  try {
111
175
  const res = await api.post(props.endpoint, buildBody())
112
176
  roots.value = res?.data ?? []
113
177
  meta.value = res?.meta ?? null
114
178
  childrenById.value = {}
179
+ if (props.cached) saveToCache()
115
180
  emit('loaded', res)
116
181
  } catch (e) {
117
182
  console.error('[Tree.Standard] initial fetch failed:', e)
@@ -122,6 +187,56 @@ const fetchInitial = async () => {
122
187
  }
123
188
  }
124
189
 
190
+ // ─── Cache ────────────────────────────────────────────────────────────────────
191
+ const cacheKey = computed(() => {
192
+ if (!props.cached || !props.name) return null
193
+ const base = `tree_${props.name}`
194
+ if (!Object.keys(props.params).length) return base
195
+ try { return base + '_' + btoa(JSON.stringify(props.params)) } catch { return base }
196
+ })
197
+
198
+ const saveToCache = () => {
199
+ if (!cacheKey.value || !roots.value.length) return
200
+ try {
201
+ sessionStorage.setItem(cacheKey.value, JSON.stringify({
202
+ roots: roots.value,
203
+ meta: meta.value,
204
+ childrenById: childrenById.value,
205
+ expanded: [...expandedSet.value],
206
+ search: search.value,
207
+ filters: activeFilters.value,
208
+ columnVisibility: columnVisibility.value,
209
+ timestamp: Date.now(),
210
+ }))
211
+ } catch (e) {
212
+ console.warn('[Tree.Standard] cache save error:', e)
213
+ }
214
+ }
215
+
216
+ const loadFromCacheOnMount = () => {
217
+ if (!cacheKey.value) return false
218
+ try {
219
+ const raw = sessionStorage.getItem(cacheKey.value)
220
+ if (!raw) return false
221
+ const cached = JSON.parse(raw)
222
+ if (Date.now() - cached.timestamp > 10 * 60 * 1000) {
223
+ sessionStorage.removeItem(cacheKey.value)
224
+ return false
225
+ }
226
+ roots.value = cached.roots ?? []
227
+ meta.value = cached.meta ?? null
228
+ childrenById.value = cached.childrenById ?? {}
229
+ expandedSet.value = new Set(cached.expanded ?? [])
230
+ search.value = cached.search ?? ''
231
+ activeFilters.value = cached.filters ?? {}
232
+ columnVisibility.value = cached.columnVisibility ?? columnVisibility.value
233
+ isDataFromCache.value = true
234
+ return true
235
+ } catch {
236
+ return false
237
+ }
238
+ }
239
+
125
240
  const fetchChildren = async (nodeId) => {
126
241
  if (childrenById.value[nodeId]) return
127
242
  if (loadingSet.value.has(nodeId)) return
@@ -218,10 +333,100 @@ const someChecked = computed(() =>
218
333
  && !allChecked.value
219
334
  )
220
335
 
336
+ // ─── Tree-aware check helpers ─────────────────────────────────────────────────
337
+ // Buscan en el árbol roots + en childrenById (lazy-loaded). Devuelven children
338
+ // directos de un nodo, o lo buscan por id.
339
+ const getChildren = (node) => {
340
+ if (Array.isArray(node.children) && node.children.length) return node.children
341
+ return childrenById.value[node.id] ?? []
342
+ }
343
+
344
+ const findNode = (id, nodes = roots.value) => {
345
+ for (const n of nodes) {
346
+ if (n.id === id) return n
347
+ const kids = getChildren(n)
348
+ if (kids.length) {
349
+ const found = findNode(id, kids)
350
+ if (found) return found
351
+ }
352
+ }
353
+ return null
354
+ }
355
+
356
+ const findParent = (childId, nodes = roots.value, parent = null) => {
357
+ for (const n of nodes) {
358
+ if (n.id === childId) return parent
359
+ const kids = getChildren(n)
360
+ if (kids.length) {
361
+ const found = findParent(childId, kids, n)
362
+ if (found !== null || kids.some(k => k.id === childId)) return found ?? n
363
+ }
364
+ }
365
+ return null
366
+ }
367
+
368
+ // Todos los descendientes (no incluye el propio nodo).
369
+ const getDescendantIds = (node) => {
370
+ const out = []
371
+ const walk = (n) => {
372
+ for (const c of getChildren(n)) {
373
+ out.push(c.id)
374
+ walk(c)
375
+ }
376
+ }
377
+ walk(node)
378
+ return out
379
+ }
380
+
381
+ // Estado de checked agregado de un nodo: { full, none, some } basado en hijos directos.
382
+ const aggregateCheck = (node, set) => {
383
+ const kids = getChildren(node)
384
+ if (!kids.length) return set.has(node.id) ? 'full' : 'none'
385
+ let checked = 0
386
+ let partial = 0
387
+ for (const c of kids) {
388
+ const s = aggregateCheck(c, set)
389
+ if (s === 'full') checked++
390
+ else if (s === 'some') partial++
391
+ }
392
+ if (partial > 0) return 'some'
393
+ if (checked === 0) return 'none'
394
+ if (checked === kids.length) return 'full'
395
+ return 'some'
396
+ }
397
+
398
+ // indeterminateSet — nodos donde algunos descendientes están checked, no todos.
399
+ const indeterminateSet = computed(() => {
400
+ const out = new Set()
401
+ const walk = (nodes) => {
402
+ for (const n of nodes) {
403
+ if (aggregateCheck(n, checkedSet.value) === 'some') out.add(n.id)
404
+ const kids = getChildren(n)
405
+ if (kids.length) walk(kids)
406
+ }
407
+ }
408
+ walk(roots.value)
409
+ return out
410
+ })
411
+
221
412
  const toggleCheck = (node) => {
222
413
  const next = new Set(checkedSet.value)
223
- if (next.has(node.id)) next.delete(node.id)
224
- else next.add(node.id)
414
+ const ids = [node.id, ...getDescendantIds(node)]
415
+ const willCheck = !next.has(node.id)
416
+ for (const id of ids) {
417
+ if (willCheck) next.add(id)
418
+ else next.delete(id)
419
+ }
420
+
421
+ // Re-evaluar ancestros: un padre queda checked sólo si TODOS sus descendientes lo están.
422
+ let ancestor = findParent(node.id)
423
+ while (ancestor) {
424
+ const state = aggregateCheck(ancestor, next)
425
+ if (state === 'full') next.add(ancestor.id)
426
+ else next.delete(ancestor.id)
427
+ ancestor = findParent(ancestor.id)
428
+ }
429
+
225
430
  checkedSet.value = next
226
431
  emit('update:checked', [...next])
227
432
  }
@@ -283,7 +488,18 @@ const performExport = () => {
283
488
  }
284
489
 
285
490
  // ─── Lifecycle ────────────────────────────────────────────────────────────────
286
- onMounted(fetchInitial)
491
+ onMounted(() => {
492
+ window.addEventListener('keydown', onEsc)
493
+ document.addEventListener('mousedown', onDocMousedown)
494
+ // Si tenemos cache de datos válido, lo mostramos al toque sin esperar el fetch.
495
+ if (loadFromCacheOnMount()) return
496
+ fetchInitial()
497
+ })
498
+
499
+ onBeforeUnmount(() => {
500
+ window.removeEventListener('keydown', onEsc)
501
+ document.removeEventListener('mousedown', onDocMousedown)
502
+ })
287
503
 
288
504
  defineExpose({
289
505
  refresh: fetchInitial,
@@ -293,14 +509,14 @@ defineExpose({
293
509
  </script>
294
510
 
295
511
  <template>
296
- <div class="relative">
512
+ <div class="relative" ref="containerRef">
297
513
 
298
514
  <!-- ── Toolbar ────────────────────────────────────────────────────────── -->
299
515
  <div class="flex flex-wrap items-center gap-2 mb-2">
300
516
 
301
517
  <!-- Search -->
302
518
  <div v-if="showSearch" class="flex-1 min-w-48 max-w-xs">
303
- <Forms.Input v-model="search" type="search" :placeholder="searchPlaceholder" :icon-left="IconSearch" size="sm" />
519
+ <Forms.Input v-model="search" type="text" :placeholder="searchPlaceholder" :icon-right="IconSearch" size="sm" />
304
520
  </div>
305
521
 
306
522
  <!-- + Filtros -->
@@ -309,7 +525,7 @@ defineExpose({
309
525
  type="button"
310
526
  @click="openFilterMenu"
311
527
  :class="[
312
- 'inline-flex items-center gap-1.5 py-1.5 px-3 text-sm font-medium rounded-lg border transition-colors',
528
+ 'inline-flex items-center gap-1.5 py-1.5 px-3 text-sm font-medium rounded-control border transition-colors',
313
529
  activeFilterList.length
314
530
  ? 'border-primary/40 bg-primary/10 text-primary'
315
531
  : 'border-card-line bg-card text-muted-foreground-1 hover:bg-muted-hover',
@@ -330,7 +546,7 @@ defineExpose({
330
546
  >
331
547
  <div
332
548
  v-if="showFilterPanel"
333
- class="absolute left-0 top-full mt-1 z-30 w-80 bg-card border border-card-line rounded-xl shadow-xl p-4"
549
+ class="absolute left-0 top-full mt-1 z-30 w-80 bg-card border border-card-line rounded-popover shadow-xl p-4"
334
550
  @click.stop
335
551
  >
336
552
  <TableFilter :model-value="activeFilters" :columns="filterableColumns" @update:model-value="updateFilters" />
@@ -358,7 +574,7 @@ defineExpose({
358
574
  @click="showColumnPanel = !showColumnPanel"
359
575
  title="Columnas"
360
576
  :class="[
361
- 'p-1.5 inline-flex items-center justify-center rounded-lg border transition-colors',
577
+ 'p-1.5 inline-flex items-center justify-center rounded-control border transition-colors',
362
578
  showColumnPanel
363
579
  ? 'border-primary/40 bg-primary/10 text-primary'
364
580
  : 'border-transparent text-muted-foreground hover:border-card-line hover:bg-muted-hover hover:text-foreground',
@@ -377,7 +593,7 @@ defineExpose({
377
593
  >
378
594
  <div
379
595
  v-if="showColumnPanel"
380
- class="absolute right-0 top-full mt-1 z-30 w-56 bg-card border border-card-line rounded-xl shadow-xl p-2"
596
+ class="absolute right-0 top-full mt-1 z-30 w-56 bg-card border border-card-line rounded-popover shadow-xl p-2"
381
597
  @click.stop
382
598
  >
383
599
  <p class="px-2 py-1 text-xs font-semibold text-muted-foreground uppercase tracking-wide">
@@ -385,7 +601,7 @@ defineExpose({
385
601
  </p>
386
602
  <ul class="mt-1 space-y-0.5">
387
603
  <li v-for="col in columns" :key="col.key">
388
- <label class="flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-muted-hover cursor-pointer text-sm">
604
+ <label class="flex items-center gap-2 px-2 py-1.5 rounded-control hover:bg-muted-hover cursor-pointer text-sm">
389
605
  <input
390
606
  type="checkbox"
391
607
  :checked="columnVisibility[col.key] !== false"
@@ -408,7 +624,7 @@ defineExpose({
408
624
  @click="showExportPanel = !showExportPanel"
409
625
  title="Exportar"
410
626
  :class="[
411
- 'p-1.5 inline-flex items-center justify-center rounded-lg border transition-colors',
627
+ 'p-1.5 inline-flex items-center justify-center rounded-control border transition-colors',
412
628
  showExportPanel
413
629
  ? 'border-primary/40 bg-primary/10 text-primary'
414
630
  : 'border-transparent text-muted-foreground hover:border-card-line hover:bg-muted-hover hover:text-foreground',
@@ -427,7 +643,7 @@ defineExpose({
427
643
  >
428
644
  <div
429
645
  v-if="showExportPanel"
430
- class="absolute right-0 top-full mt-1 z-30 w-72 bg-card border border-card-line rounded-xl shadow-xl p-3 space-y-3"
646
+ class="absolute right-0 top-full mt-1 z-30 w-72 bg-card border border-card-line rounded-popover shadow-xl p-3 space-y-3"
431
647
  @click.stop
432
648
  >
433
649
  <div>
@@ -435,7 +651,7 @@ defineExpose({
435
651
  <input
436
652
  v-model="exportFilename"
437
653
  type="text"
438
- class="w-full text-sm px-2 py-1.5 border border-card-line rounded-md bg-transparent focus:outline-none focus:border-primary/50"
654
+ class="innertia-field innertia-field-sm"
439
655
  />
440
656
  </div>
441
657
  <div>
@@ -447,7 +663,7 @@ defineExpose({
447
663
  type="button"
448
664
  @click="exportFormat = f.value"
449
665
  :class="[
450
- 'flex items-center gap-1.5 px-2.5 py-1.5 text-xs rounded-md border transition-colors',
666
+ 'flex items-center gap-1.5 px-2.5 py-1.5 text-xs rounded-control border transition-colors',
451
667
  exportFormat === f.value
452
668
  ? 'border-primary/40 bg-primary/10 text-primary'
453
669
  : 'border-card-line text-foreground hover:bg-muted-hover',
@@ -467,24 +683,13 @@ defineExpose({
467
683
  <button
468
684
  type="button"
469
685
  @click="performExport"
470
- class="text-xs px-3 py-1.5 rounded-md bg-primary text-primary-foreground hover:bg-primary-hover"
686
+ class="text-xs px-3 py-1.5 rounded-control bg-primary text-primary-foreground hover:bg-primary-hover"
471
687
  >Exportar</button>
472
688
  </div>
473
689
  </div>
474
690
  </Transition>
475
691
  </div>
476
692
 
477
- <!-- Reload -->
478
- <button
479
- v-if="showReloadButton"
480
- type="button"
481
- @click="fetchInitial"
482
- :disabled="isFetching"
483
- title="Recargar"
484
- class="p-1.5 inline-flex items-center justify-center rounded-lg border border-transparent text-muted-foreground hover:border-card-line hover:bg-muted-hover hover:text-foreground transition-colors disabled:opacity-50"
485
- >
486
- <IconRefresh class="size-4" :class="isFetching ? 'animate-spin' : ''" />
487
- </button>
488
693
  </div>
489
694
  </div>
490
695
 
@@ -493,7 +698,7 @@ defineExpose({
493
698
  <div
494
699
  v-for="chip in activeFilterList"
495
700
  :key="chip.key"
496
- class="inline-flex items-center text-xs rounded-lg border border-card-line bg-card overflow-hidden"
701
+ class="inline-flex items-center text-xs rounded-control border border-card-line bg-card overflow-hidden"
497
702
  >
498
703
  <span class="px-2.5 py-1 text-foreground font-medium border-r border-card-line bg-surface">{{ chip.label }}</span>
499
704
  <span class="px-2 py-1 text-primary font-medium">{{ chip.displayVal }}</span>
@@ -507,29 +712,14 @@ defineExpose({
507
712
  </div>
508
713
  </div>
509
714
 
510
- <!-- ── Selection bar (when items checked) ─────────────────────────────── -->
715
+ <!-- ── Table wrapper (rounded + scroll) ───────────────────────────────── -->
511
716
  <div
512
- v-if="checkable && checkedSet.size > 0"
513
- class="flex items-center justify-between gap-2 mb-2 px-3 py-2 rounded-lg bg-primary/5 border border-primary/20"
717
+ class="border border-card-line rounded-card overflow-hidden flex flex-col w-full"
514
718
  >
515
- <span class="text-sm text-primary font-medium">
516
- {{ checkedSet.size }} seleccionado{{ checkedSet.size === 1 ? '' : 's' }}
517
- </span>
518
- <div class="flex items-center gap-2">
519
- <slot name="selection-actions" :checked="[...checkedSet]" :clear="clearChecked" />
520
- <button
521
- type="button"
522
- @click="clearChecked"
523
- class="text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1"
524
- >
525
- <IconX class="size-3" /> Limpiar
526
- </button>
527
- </div>
528
- </div>
719
+ <div class="overflow-auto" style="min-height: 30rem; max-height: 36rem">
529
720
 
530
- <!-- ── Table wrapper (rounded) ────────────────────────────────────────── -->
531
- <div class="overflow-x-auto border border-card-line rounded-xl">
532
- <table class="w-full divide-y divide-card-line" style="table-layout: auto">
721
+ <!-- ════════════ Variante 'table' ════════════ -->
722
+ <table v-if="variant === 'table'" class="w-full divide-y divide-card-line" style="table-layout: auto">
533
723
 
534
724
  <!-- Header -->
535
725
  <thead class="relative z-10 bg-card">
@@ -596,10 +786,11 @@ defineExpose({
596
786
  :name-col-key="nameColKey"
597
787
  :checkable="checkable"
598
788
  :checked-set="checkedSet"
789
+ :indeterminate-set="indeterminateSet"
599
790
  :column-visibility="columnVisibility"
600
791
  @toggle="toggle"
601
792
  @check="toggleCheck"
602
- @row-click="(n) => emit('row-click', n)"
793
+ @row-click="handleRowClick"
603
794
  >
604
795
  <template v-for="col in columns" :key="col.key" #[`cell-${col.key}`]="slotProps">
605
796
  <slot :name="`cell-${col.key}`" v-bind="slotProps" />
@@ -607,17 +798,114 @@ defineExpose({
607
798
  </TreeNode>
608
799
  </template>
609
800
  </tbody>
610
- </table>
611
- </div>
801
+ </table>
802
+
803
+ <!-- ════════════ Variante 'list' (compacto, sin tabla) ════════════ -->
804
+ <div v-else class="py-2">
805
+ <!-- Loading skeleton -->
806
+ <div v-if="loading" class="space-y-1 px-2">
807
+ <div v-for="i in 6" :key="`sk-${i}`" class="h-7 bg-muted/60 rounded animate-pulse" :style="{ width: `${60 + (i % 3) * 10}%` }" />
808
+ </div>
809
+
810
+ <!-- Empty -->
811
+ <div v-else-if="!roots.length" class="py-12 text-center text-sm text-muted-foreground">
812
+ {{ emptyMessage }}
813
+ </div>
814
+
815
+ <!-- Tree -->
816
+ <div v-else class="px-1.5">
817
+ <TreeNode
818
+ v-for="root in roots"
819
+ :key="root.id"
820
+ :node="root"
821
+ :columns="columns"
822
+ :depth="0"
823
+ variant="list"
824
+ :expanded="expandedSet"
825
+ :loading-set="loadingSet"
826
+ :children-by-id="childrenById"
827
+ :row-href="rowHref"
828
+ :clickable-rows="clickableRows"
829
+ :name-col-key="nameColKey"
830
+ :checkable="checkable"
831
+ :checked-set="checkedSet"
832
+ :indeterminate-set="indeterminateSet"
833
+ :column-visibility="columnVisibility"
834
+ @toggle="toggle"
835
+ @check="toggleCheck"
836
+ @row-click="handleRowClick"
837
+ >
838
+ <template v-for="col in columns" :key="col.key" #[`cell-${col.key}`]="slotProps">
839
+ <slot :name="`cell-${col.key}`" v-bind="slotProps" />
840
+ </template>
841
+ </TreeNode>
842
+ </div>
843
+ </div>
844
+ </div>
845
+
846
+ <!-- ── Footer bar (reload + total + cache badge) — DENTRO del wrapper ── -->
847
+ <div class="flex flex-col sm:flex-row items-center justify-between gap-y-3 sm:gap-y-0 px-4 py-3 border-t border-card-line bg-card">
848
+ <div class="flex items-center gap-x-4 flex-wrap gap-y-2">
849
+ <!-- Reload button -->
850
+ <div v-if="showReloadButton" class="flex items-center gap-x-2">
851
+ <IconReload
852
+ v-if="!isFetching"
853
+ class="size-4 cursor-pointer text-muted-foreground hover:text-muted-foreground-1 transition-colors"
854
+ @click="fetchInitial"
855
+ />
856
+ <IconLoader2 v-else class="size-4 text-muted-foreground-2 animate-spin" />
857
+ </div>
858
+
859
+ <!-- Total nodes -->
860
+ <p class="text-sm text-foreground font-medium">
861
+ {{ totalRendered }} {{ totalRendered === 1 ? 'nodo' : 'nodos' }}
862
+ </p>
612
863
 
613
- <!-- ── Footer ─────────────────────────────────────────────────────────── -->
614
- <div class="flex items-center justify-between gap-2 mt-2 px-1 text-xs text-muted-foreground">
615
- <div class="flex items-center gap-2">
616
- <IconLoader2 v-if="isFetching && !loading" class="size-3.5 animate-spin" />
617
- <span>{{ totalRendered }} {{ totalRendered === 1 ? 'nodo' : 'nodos' }}</span>
864
+ <!-- Cache badge (instant) -->
865
+ <div v-if="isDataFromCache && cached" class="group relative flex items-center">
866
+ <div class="flex items-center gap-x-1.5 py-1 px-2.5 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 rounded-badge cursor-help hover:bg-emerald-500/20 transition-colors">
867
+ <IconBolt class="size-3.5 fill-current" />
868
+ <span class="text-[10px] font-bold uppercase tracking-wider">Instant</span>
869
+ </div>
870
+ <div class="absolute bottom-full mb-2 left-0 hidden group-hover:block w-48 p-2.5 bg-slate-900 text-white text-[11px] leading-relaxed rounded-popover shadow-2xl z-50">
871
+ <div class="font-bold mb-1 flex items-center gap-x-1.5 text-emerald-400">
872
+ <IconBolt class="size-3" /> Datos en caché
873
+ </div>
874
+ Se cargaron al instante desde la memoria local. Hacé reload para sincronizar con el servidor.
875
+ <div class="absolute top-full left-4 -mt-1 border-4 border-transparent border-t-slate-900"></div>
876
+ </div>
877
+ </div>
878
+ </div>
618
879
  </div>
619
- <div></div>
620
880
  </div>
881
+ <!-- ↑ table wrapper cierra acá. DataPreview va FUERA como hermano. -->
882
+
883
+ <!-- ── Preview compartido (panel overlay + chip flotante) ───────────── -->
884
+ <DataPreview
885
+ ref="dataPreviewRef"
886
+ v-model:row="previewRow"
887
+ :enabled="previewEnabled"
888
+ :name="props.name || 'tree'"
889
+ :cached="cached"
890
+ :preview-href="previewHref"
891
+ :preview-deletable="previewDeletable"
892
+ :split-ratio="splitRatio"
893
+ :container-ref="containerRef"
894
+ :history-endpoint="resolvedHistoryEndpoint"
895
+ @delete="emit('preview-delete', $event)"
896
+ >
897
+ <template #header="bind">
898
+ <slot name="preview-header" v-bind="bind">
899
+ <div class="font-semibold text-foreground truncate">{{ bind.row.name ?? 'Detalle' }}</div>
900
+ </slot>
901
+ </template>
902
+ <template #actions="bind">
903
+ <slot name="preview-actions" v-bind="bind" />
904
+ </template>
905
+ <template #default="bind">
906
+ <slot name="preview" v-bind="bind" />
907
+ </template>
908
+ </DataPreview>
621
909
 
622
910
  </div>
623
911
  </template>
@@ -11,10 +11,14 @@ export function useTable(tableOrName?: TableConfig) {
11
11
  return;
12
12
  }
13
13
 
14
- const fullCacheKey = `table_cache_${tableName}`;
15
-
16
14
  try {
17
- sessionStorage.removeItem(fullCacheKey);
15
+ const prefix = `full_table_${tableName}`
16
+ for (const key of Object.keys(sessionStorage)) {
17
+ if (key === prefix || key.startsWith(prefix + '_')) {
18
+ sessionStorage.removeItem(key)
19
+ }
20
+ }
21
+ sessionStorage.removeItem(`table_cache_${tableName}`)
18
22
  } catch (error) {
19
23
  console.warn('[useTable] Error invalidating cache:', error);
20
24
  }