@asteby/metacore-runtime-react 53.20.0 → 53.21.0

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/attention/apply-nav-badges.d.ts +10 -0
  3. package/dist/attention/apply-nav-badges.d.ts.map +1 -0
  4. package/dist/attention/apply-nav-badges.js +35 -0
  5. package/dist/attention/index.d.ts +4 -0
  6. package/dist/attention/index.d.ts.map +1 -0
  7. package/dist/attention/index.js +3 -0
  8. package/dist/attention/use-document-attention.d.ts +10 -0
  9. package/dist/attention/use-document-attention.d.ts.map +1 -0
  10. package/dist/attention/use-document-attention.js +66 -0
  11. package/dist/attention/use-nav-badges.d.ts +42 -0
  12. package/dist/attention/use-nav-badges.d.ts.map +1 -0
  13. package/dist/attention/use-nav-badges.js +54 -0
  14. package/dist/dynamic-columns.js +1 -1
  15. package/dist/dynamic-table.js +3 -3
  16. package/dist/genui/index.d.ts +2 -0
  17. package/dist/genui/index.d.ts.map +1 -0
  18. package/dist/genui/index.js +1 -0
  19. package/dist/genui/settings-block.d.ts +31 -0
  20. package/dist/genui/settings-block.d.ts.map +1 -0
  21. package/dist/genui/settings-block.js +100 -0
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -0
  25. package/dist/setup/addon-config-surface.d.ts +14 -1
  26. package/dist/setup/addon-config-surface.d.ts.map +1 -1
  27. package/dist/setup/addon-config-surface.js +109 -6
  28. package/dist/setup/messages.d.ts.map +1 -1
  29. package/dist/setup/messages.js +50 -0
  30. package/dist/setup/secret-field-model.d.ts +47 -0
  31. package/dist/setup/secret-field-model.d.ts.map +1 -0
  32. package/dist/setup/secret-field-model.js +95 -0
  33. package/dist/view-system/card-spec.d.ts +24 -0
  34. package/dist/view-system/card-spec.d.ts.map +1 -0
  35. package/dist/view-system/card-spec.js +40 -0
  36. package/dist/view-system/cards-view.d.ts +17 -0
  37. package/dist/view-system/cards-view.d.ts.map +1 -0
  38. package/dist/view-system/cards-view.js +37 -0
  39. package/dist/view-system/index.d.ts +10 -0
  40. package/dist/view-system/index.d.ts.map +1 -0
  41. package/dist/view-system/index.js +9 -0
  42. package/dist/view-system/model-view.d.ts +31 -0
  43. package/dist/view-system/model-view.d.ts.map +1 -0
  44. package/dist/view-system/model-view.js +50 -0
  45. package/dist/view-system/saved-views.d.ts +22 -0
  46. package/dist/view-system/saved-views.d.ts.map +1 -0
  47. package/dist/view-system/saved-views.js +53 -0
  48. package/dist/view-system/types.d.ts +63 -0
  49. package/dist/view-system/types.d.ts.map +1 -0
  50. package/dist/view-system/types.js +1 -0
  51. package/dist/view-system/use-view-mode.d.ts +26 -0
  52. package/dist/view-system/use-view-mode.d.ts.map +1 -0
  53. package/dist/view-system/use-view-mode.js +60 -0
  54. package/dist/view-system/view-state.d.ts +19 -0
  55. package/dist/view-system/view-state.d.ts.map +1 -0
  56. package/dist/view-system/view-state.js +66 -0
  57. package/dist/view-system/view-switcher.d.ts +14 -0
  58. package/dist/view-system/view-switcher.d.ts.map +1 -0
  59. package/dist/view-system/view-switcher.js +26 -0
  60. package/dist/view-system/view-toolbar.d.ts +19 -0
  61. package/dist/view-system/view-toolbar.d.ts.map +1 -0
  62. package/dist/view-system/view-toolbar.js +33 -0
  63. package/package.json +14 -5
  64. package/src/__tests__/addon-config-surface.test.tsx +67 -1
  65. package/src/__tests__/attention-view-system.test.tsx +128 -0
  66. package/src/__tests__/genui-settings-block.test.tsx +73 -0
  67. package/src/attention/apply-nav-badges.ts +42 -0
  68. package/src/attention/index.ts +11 -0
  69. package/src/attention/use-document-attention.ts +62 -0
  70. package/src/attention/use-nav-badges.ts +94 -0
  71. package/src/dynamic-columns.tsx +1 -1
  72. package/src/dynamic-table.tsx +3 -3
  73. package/src/genui/index.ts +1 -0
  74. package/src/genui/settings-block.tsx +123 -0
  75. package/src/index.ts +2 -0
  76. package/src/setup/addon-config-surface.tsx +297 -16
  77. package/src/setup/messages.ts +50 -0
  78. package/src/setup/secret-field-model.test.ts +67 -0
  79. package/src/setup/secret-field-model.ts +104 -0
  80. package/src/view-system/card-spec.tsx +78 -0
  81. package/src/view-system/cards-view.tsx +61 -0
  82. package/src/view-system/index.ts +9 -0
  83. package/src/view-system/model-view.tsx +105 -0
  84. package/src/view-system/saved-views.ts +66 -0
  85. package/src/view-system/types.ts +63 -0
  86. package/src/view-system/use-view-mode.ts +79 -0
  87. package/src/view-system/view-state.ts +61 -0
  88. package/src/view-system/view-switcher.tsx +53 -0
  89. package/src/view-system/view-toolbar.tsx +119 -0
@@ -0,0 +1,53 @@
1
+ import { LayoutGrid, Map as MapIcon, Table2 } from 'lucide-react'
2
+ import { useTranslation } from 'react-i18next'
3
+ import { cn } from '@asteby/metacore-ui/lib'
4
+ import type { ViewModeDef, ViewModeKey } from './types'
5
+
6
+ const ICON = { cards: LayoutGrid, table: Table2, map: MapIcon } as const
7
+ const DEFAULT_LABEL: Record<string, [string, string]> = {
8
+ cards: ['views.cards', 'Tarjetas'],
9
+ table: ['views.data', 'Datos'],
10
+ map: ['views.map', 'Mapa'],
11
+ }
12
+
13
+ export interface ViewSwitcherProps {
14
+ modes: ViewModeDef[]
15
+ active: ViewModeKey
16
+ onChange: (key: ViewModeKey) => void
17
+ className?: string
18
+ }
19
+
20
+ /**
21
+ * Generic "Tarjetas | Datos (| Mapa)" toggle over the SAME data. Labels default
22
+ * to i18n; a module overrides the cards label via `modes[].label` (manifest).
23
+ * Hidden with a single mode. role=group + aria-pressed.
24
+ */
25
+ export function ViewSwitcher({ modes, active, onChange, className }: ViewSwitcherProps) {
26
+ const { t } = useTranslation()
27
+ if (modes.length < 2) return null
28
+ return (
29
+ <div role='group' aria-label={t('views.switch', { defaultValue: 'Vista' })} className={cn('inline-flex rounded-lg border bg-muted/40 p-0.5', className)}>
30
+ {modes.map((m) => {
31
+ const Icon = ICON[m.key as keyof typeof ICON] ?? LayoutGrid
32
+ const [k, d] = DEFAULT_LABEL[m.key] ?? [`views.${m.key}`, m.key]
33
+ const on = m.key === active
34
+ return (
35
+ <button
36
+ key={m.key}
37
+ type='button'
38
+ aria-pressed={on}
39
+ data-mode={m.key}
40
+ onClick={() => onChange(m.key)}
41
+ className={cn(
42
+ 'inline-flex items-center gap-1.5 rounded-md px-3 py-1 text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
43
+ on ? 'bg-background font-medium text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground',
44
+ )}
45
+ >
46
+ <Icon className='size-4' aria-hidden='true' />
47
+ <span>{m.label ?? t(k, { defaultValue: d })}</span>
48
+ </button>
49
+ )
50
+ })}
51
+ </div>
52
+ )
53
+ }
@@ -0,0 +1,119 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { Bookmark, Search, X } from 'lucide-react'
3
+ import { useTranslation } from 'react-i18next'
4
+ import { Button, Input } from '@asteby/metacore-ui/primitives'
5
+ import { cn } from '@asteby/metacore-ui/lib'
6
+ import { useDebouncedValue } from '../use-debounced-value'
7
+ import { isViewStateEmpty } from './view-state'
8
+ import type { QuickFilterDef, SavedView, SortSpec, ViewState } from './types'
9
+
10
+ export interface ViewToolbarProps {
11
+ state: ViewState
12
+ onChange: (next: ViewState) => void
13
+ quickFilters?: QuickFilterDef[]
14
+ /** Filtered total; when set renders "7,358 hallazgos · ordenados por prioridad". */
15
+ total?: number
16
+ /** Plural noun for the counter ("hallazgos"). */
17
+ noun?: string
18
+ sort?: SortSpec
19
+ savedViews?: SavedView[]
20
+ onSaveView?: (name: string) => void
21
+ onApplySavedView?: (v: SavedView) => void
22
+ onRemoveSavedView?: (id: string) => void
23
+ locale?: string
24
+ }
25
+
26
+ /** Search + quick chips + counter/sort + saved views. Pure view over `state`; the shell owns it so every mode shares it. */
27
+ export function ViewToolbar(p: ViewToolbarProps) {
28
+ const { state, onChange, quickFilters = [], total, noun, sort, savedViews = [] } = p
29
+ const { t, i18n } = useTranslation()
30
+ const [text, setText] = useState(state.search)
31
+ const debounced = useDebouncedValue(text)
32
+ useEffect(() => setText(state.search), [state.search])
33
+ useEffect(() => {
34
+ if (debounced !== state.search) onChange({ ...state, search: debounced })
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ }, [debounced])
37
+ const chips: QuickFilterDef[] = [{ key: '', label: t('views.all', { defaultValue: 'Todos' }), params: {} }, ...quickFilters]
38
+ return (
39
+ <div className='flex flex-col gap-2'>
40
+ <div className='flex flex-wrap items-center gap-2'>
41
+ <div className='relative min-w-48 flex-1 sm:max-w-sm'>
42
+ <Search className='pointer-events-none absolute start-2.5 top-2.5 size-4 text-muted-foreground' aria-hidden='true' />
43
+ <Input
44
+ type='search'
45
+ value={text}
46
+ onChange={(e) => setText(e.target.value)}
47
+ placeholder={t('views.search', { defaultValue: 'Buscar…' })}
48
+ aria-label={t('views.search', { defaultValue: 'Buscar…' })}
49
+ className='ps-8'
50
+ />
51
+ </div>
52
+ <div role='group' aria-label={t('views.quick_filters', { defaultValue: 'Filtros rápidos' })} className='flex flex-wrap gap-1'>
53
+ {chips.map((c) => {
54
+ const on = state.quick === c.key
55
+ return (
56
+ <button
57
+ key={c.key || '__all'}
58
+ type='button'
59
+ aria-pressed={on}
60
+ onClick={() => onChange({ ...state, quick: c.key })}
61
+ className={cn('rounded-full border px-3 py-1 text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring', on ? 'border-primary bg-primary text-primary-foreground' : 'text-muted-foreground hover:text-foreground')}
62
+ >
63
+ {c.label}
64
+ </button>
65
+ )
66
+ })}
67
+ </div>
68
+ {!isViewStateEmpty(state) && (
69
+ <Button variant='ghost' size='sm' onClick={() => onChange({ search: '', quick: '', filters: {}, sort: state.sort })}>
70
+ <X className='me-1 size-4' aria-hidden='true' />
71
+ {t('views.clear', { defaultValue: 'Limpiar' })}
72
+ </Button>
73
+ )}
74
+ {p.onSaveView && (
75
+ <details className='relative'>
76
+ <summary className='inline-flex cursor-pointer list-none items-center gap-1 rounded-md border px-3 py-1.5 text-sm'>
77
+ <Bookmark className='size-4' aria-hidden='true' />
78
+ {t('views.saved', { defaultValue: 'Vistas' })}
79
+ </summary>
80
+ <div className='absolute end-0 z-20 mt-1 w-64 rounded-md border bg-popover p-2 text-popover-foreground shadow-md'>
81
+ {savedViews.length === 0 && <p className='px-2 py-1 text-xs text-muted-foreground'>{t('views.saved_empty', { defaultValue: 'Aún no guardas vistas' })}</p>}
82
+ {savedViews.map((v) => (
83
+ <div key={v.id} className='flex items-center justify-between gap-1'>
84
+ <button type='button' className='flex-1 truncate rounded px-2 py-1 text-start text-sm hover:bg-accent' onClick={() => p.onApplySavedView?.(v)}>
85
+ {v.name}
86
+ </button>
87
+ <button type='button' aria-label={t('views.remove', { defaultValue: 'Eliminar' })} className='rounded p-1 hover:bg-accent' onClick={() => p.onRemoveSavedView?.(v.id)}>
88
+ <X className='size-3.5' aria-hidden='true' />
89
+ </button>
90
+ </div>
91
+ ))}
92
+ <form
93
+ className='mt-2 flex gap-1 border-t pt-2'
94
+ onSubmit={(e) => {
95
+ e.preventDefault()
96
+ const name = String(new FormData(e.currentTarget).get('name') ?? '').trim()
97
+ if (name) {
98
+ p.onSaveView?.(name)
99
+ e.currentTarget.reset()
100
+ }
101
+ }}
102
+ >
103
+ <Input name='name' maxLength={60} placeholder={t('views.save_current', { defaultValue: 'Guardar vista actual…' })} aria-label={t('views.save_current', { defaultValue: 'Guardar vista actual…' })} />
104
+ <Button type='submit' size='sm'>{t('common.save', { defaultValue: 'Guardar' })}</Button>
105
+ </form>
106
+ </div>
107
+ </details>
108
+ )}
109
+ </div>
110
+ {total !== undefined && (
111
+ <p className='text-sm text-muted-foreground' aria-live='polite'>
112
+ {new Intl.NumberFormat(p.locale ?? i18n.language).format(total)}
113
+ {noun ? ` ${noun}` : ''}
114
+ {sort?.label ? ` · ${t('views.sorted_by', { defaultValue: 'ordenados por {{by}}', by: sort.label })}` : ''}
115
+ </p>
116
+ )}
117
+ </div>
118
+ )
119
+ }