Commit graph

150 commits

Author SHA1 Message Date
51705f8fc7 fix(virtual_table): Commit pending changes on tab_out
When user tabs out of the table with pending changes in RowEditBuffer,
commit them before exiting. Prevents data loss when leaving ghost row.
2025-12-27 23:36:34 +01:00
ef30cc7d1b fix(table_core): Show pending values from RowEditBuffer in render
Fix Tab showing empty cell after editing:
- Add edit_buffer field to DrawRowsConfig
- drawRowsWithDataSource now checks RowEditBuffer before DataSource
- VirtualAdvancedTable passes row_edit_buffer to render

Priority: RowEditBuffer (user typed) > DataSource (DB/memory)
2025-12-27 23:00:09 +01:00
9c9c53afea feat(style): Z-Design panel color derivation system
Laravel-inspired color system for semantic panel coloring:

- Add blendTowards(target, percent) for color washing
- Add Laravel color constants (red, blue, green, amber, cyan, etc.)
- Add soft_black/soft_white for better aesthetics
- Add ThemeMode enum (dark/light)
- Add PanelColorScheme with 10 documented fields
- Implement derivePanelPalette(base, mode) to derive full palette
- deriveDarkPalette: 5% tint on dark background
- deriveLightPalette: 3% tint on light background
- Tests for blendTowards and derivePanelPalette

This enables deriving a complete 10-color panel palette from
a single base color, achieving Laravel Forge/Nova aesthetics.
2025-12-27 22:23:58 +01:00
5c7964bacc feat(tables): Tips proactivos cada ~10s
- Añade table_tips[] con 8 tips de atajos
- Añade tip_index a VirtualAdvancedTableState
- Rota tip cada 600 frames (~10s @ 60fps)
- result.current_tip contiene tip a mostrar
- Solo muestra tips con focus y sin edición activa
2025-12-27 21:47:47 +01:00
dc82340381 feat(table_core): Selection on focus Excel-style
- Añade selection_start/selection_end a CellEditState
- F2/Space selecciona todo el texto al entrar en edición
- Typing con selección reemplaza texto seleccionado
- Backspace/Delete borra selección si existe
- Flechas/Home/End limpian selección
- Dibuja highlight azul en ambas tablas (Advanced + Virtual)
2025-12-27 21:41:42 +01:00
91570368cc feat(virtual_table): Auto-scroll horizontal en navegación Tab
- Añade ensureColumnVisible() para mantener columna activa visible
- Ajusta scroll_x automáticamente al navegar con Tab/Shift+Tab
- Respeta límites max_scroll_x
2025-12-27 21:34:37 +01:00
8e9dd3a475 feat(virtual_table): deleted_row_id en result para Ctrl+Delete
- Añadido deleted_row_id: i64 a VirtualAdvancedTableResult
- handleKeyboard setea el ID de la fila seleccionada
- El panel puede usar esto para eliminar de BD
2025-12-27 21:30:10 +01:00
b73ee76872 feat(tables): Indicador ordenación ▴/▾ Unicode en headers
- SortDirection.symbol() ahora retorna ▴/▾ en vez de ^/v
- AdvancedTable usa los mismos glifos Unicode
- VirtualAdvancedTable ya usaba symbol()
2025-12-27 21:28:13 +01:00
0ca97c2ba3 refactor(advanced_table): Brain-in-Core pattern - usar processTableEvents()
Completa la limpieza del patrón Brain-in-Core:
- AdvancedTable ahora usa table_core.processTableEvents() igual que VirtualAdvancedTable
- Eliminada lógica duplicada de navegación (flechas, Home, End, PageUp/Down)
- Eliminada lógica duplicada de atajos (Ctrl+Home/End, Ctrl+N, Ctrl+Delete)
- Ctrl+B ahora funciona en ambas tablas (alias de Ctrl+Delete)
- Mantiene lógica específica: búsqueda incremental, Ctrl+A select all

Checklist Gemini completado:
[x] Manejo de flechas en Core
[x] Manejo de Ctrl+N en Core
[x] Ctrl+B implementado
[x] Ctrl+Shift+1 activa ordenación
2025-12-27 21:16:06 +01:00
aed811a102 feat(table_core): Brain-in-Core - processTableEvents() unifica toda lógica de teclado
Arquitectura diseñada por Gemini:
- TODA la lógica de decisión en table_core.zig
- Widgets solo pasan eventos y reaccionan a flags
- Cualquier tabla nueva hereda automáticamente

Cambios:
- TableEventResult: struct con TODOS los flags de acciones
- processTableEvents(): función maestra que procesa teclado
- Soporta: navegación, CRUD (Ctrl+N/B/Del), ordenación (Ctrl+Shift+1-9), edición
- VirtualAdvancedTable refactorizado al patrón Brain-in-Core
- Nuevos campos result: insert_row_requested, delete_row_requested, sort_column_index
2025-12-27 21:07:17 +01:00
7642ffe7f7 feat(table_core): Dirty tracking visual - blend naranja para filas con cambios pendientes
- Añadido dirty_row_id: ?i64 a DrawRowsConfig
- drawRowsWithDataSource aplica blendColor(state_modified, 0.25) si dirty
- VirtualAdvancedTable pasa row_edit_buffer.row_id cuando has_changes
2025-12-27 20:54:53 +01:00
d5edf2b962 docs: Update TABLES_ARCHITECTURE with FASE 5+6 2025-12-27 19:58:55 +01:00
a9caa522a1 refactor(tables): FASE 6 - Unificar scrollbars en table_core
- Añadido VerticalScrollbarParams y drawVerticalScrollbar
- Añadido HorizontalScrollbarParams y drawHorizontalScrollbar
- AdvancedTable y VirtualAdvancedTable ahora usan funciones unificadas
- Elimina duplicación de código de renderizado de scrollbars
2025-12-27 19:52:05 +01:00
253c9b2449 refactor(tables): FASE 5 - Embeber NavigationState en AdvancedTableState y VirtualAdvancedTableState
- Añadido nav: table_core.NavigationState en ambos estados
- Eliminados campos duplicados (scroll_row, scroll_x, active_col, double_click)
- Actualizado todas las referencias a usar nav.*
- Conservado scroll_offset_pixels en Virtual (específico smooth scroll)
2025-12-27 19:47:43 +01:00
913652d864 docs(TABLES_ARCHITECTURE): Update with FASE 4.5 - TableDataSource
- Add TableDataSource interface documentation
- Add adaptadores (MemoryDataSource, PagedDataSource)
- Add drawRowsWithDataSource function docs
- Update file structure with new datasource files
- Add section 'Cómo Crear un Nuevo Tipo de Tabla'
2025-12-27 19:08:28 +01:00
08ffcdbac5 refactor(tables): FASE 4.5 - AdvancedTable usa drawRowsWithDataSource
- Añadir RowState enum a table_core.zig
- Añadir getRowState a TableDataSource.VTable (opcional)
- Añadir colores de estado a RowRenderColors
- Añadir draw_row_borders a DrawRowsConfig
- Añadir getRowState a MemoryDataSource
- Nueva función handleRowClicks() separando input de rendering
- AdvancedTable usa drawRowsWithDataSource (sin bucle for propio)
- Eliminar drawRow() y drawStateIndicator() locales (~160 líneas)

Objetivo cumplido: un solo bloque de código para renderizar filas
2025-12-27 18:52:31 +01:00
b8199aec38 refactor(tables): FASE 4 - Add unified drawRowsWithDataSource
Add unified row rendering function to table_core.zig that uses
TableDataSource interface for data access.

Changes:
- Add ColumnRenderDef, RowRenderColors, DrawRowsConfig types
- Add drawRowsWithDataSource() unified rendering function
- Update VirtualAdvancedTable.drawRows to use unified function
  with PagedDataSource

Note: AdvancedTable not yet integrated due to additional complexity
(state indicators, click handling interleaved with drawing).
See PLAN_REFACTOR_TABLES_CONTINUIDAD.md for details.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 18:02:45 +01:00
cf2f91f8bc refactor(tables): FASE 4 - Add DataSource adapters
Add MemoryDataSource for AdvancedTable (in-memory ArrayList) and
PagedDataSource for VirtualAdvancedTable (paged DB data).

Both implement TableDataSource interface from table_core.zig,
enabling unified rendering patterns while respecting memory ownership.

New files:
- advanced_table/datasource.zig - MemoryDataSource
- virtual_advanced_table/paged_datasource.zig - PagedDataSource

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 17:37:04 +01:00
473bbdb648 feat(table_core): Add TableDataSource interface (FASE 3)
- TableDataSource: vtable interface for data abstraction
- getCellValueInto: buffer-based pattern to avoid memory issues
- getRowCount, getRowId: basic data access methods
- isCellEditable, invalidate: optional methods
- makeTableDataSource: helper to create from concrete types
- isGhostRow: convenience method for new row detection

This interface enables unified rendering for both memory and
paginated tables while enforcing safe memory patterns.
2025-12-27 17:13:38 +01:00
37e3b61aca refactor(states): Embed CellEditState in AdvancedTableState and VirtualAdvancedTableState
FASE 2 del refactor de tablas:
- AdvancedTableState: Embed cell_edit, delegate editing methods
- VirtualAdvancedTableState: Embed cell_edit, replace editing_cell/edit_buffer
- Update advanced_table.zig to use isEditing() and cell_edit.*
- Update virtual_advanced_table.zig to use getEditingCell()
- Update cell_editor.zig to use cell_edit.*

Reduces code duplication, centralizes editing logic in table_core
2025-12-27 16:45:58 +01:00
6819919060 refactor(table_core): Add CellEditState + NavigationState for composition
- Delete obsolete 'table_core (conflicted).zig'
- Add memory ownership protocol documentation
- Add CellEditState: embeddable edit state with buffer, cursor, escape handling
- Add NavigationState: embeddable nav state with active_col, scroll, Tab methods
- Maintains backward compatibility with existing EditState
2025-12-27 16:11:24 +01:00
d16019d54f feat(table_core): RowEditBuffer + commit al abandonar fila (Excel-style)
- RowEditBuffer: acumula cambios de fila antes de commit
- checkRowChangeAndCommit(): detecta cambio fila + commit automático
- buildCommitInfo(), isGhostRow(), NEW_ROW_ID
- VirtualAdvancedTableState: row_edit_buffer field
- VirtualAdvancedTableResult: row_committed, row_changes[], etc.
- Comportamiento: Tab entre celdas acumula, cambiar fila hace commit
2025-12-27 14:58:01 +01:00
0026dbff2a docs(TABLES_ARCHITECTURE): Add 'Lecciones Aprendidas' section
Document the Tab double-processing bug and its solution:
- Symptom: Row color alternating on Tab press
- Root cause: Tab processed twice (widget + app level)
- Solution: NavigateDirection + handled flag + app check
- General rule for keyboard handling in immediate-mode widgets

Also updated EditKeyboardResult API documentation with new fields.
2025-12-27 12:53:21 +01:00
60c3f9d456 refactor(advanced_table): Use table_core.handleEditingKeyboard (DRY)
- Remove 160 lines of duplicated keyboard handling code
- Use shared table_core.handleEditingKeyboard() for edit buffer operations
- Export NavigateDirection from table_core for external use
- Keep AdvancedTable-specific navigation logic (cell movement, auto-edit)
2025-12-27 12:24:50 +01:00
91969cb728 fix(virtual_advanced_table): Prevent double Tab processing
- Check navigate_direction before setting tab_out in handleKeyboard
- Export NavigateDirection from virtual_advanced_table module
- Use cell_editor.NavigateDirection in VirtualAdvancedTableResult

This fixes the bug where Tab was processed twice: once by CellEditor
(for cell navigation) and again by handleKeyboard (for tab_out).
2025-12-27 12:13:51 +01:00
9b2cf2a3dd refactor(cell_editor): Use table_core.handleEditingKeyboard instead of duplicated code
- Import and use table_core for keyboard handling
- Re-export NavigateDirection from table_core
- Map table_core.EditKeyboardResult to CellEditorResult
- Remove ~100 lines of duplicated keyboard handling code
- Add 'handled' field to CellEditorResult
2025-12-27 12:10:59 +01:00
49cf12f7b9 refactor(table_core): Unify EditKeyboardResult with NavigateDirection and handled flag
- Add NavigateDirection enum (none, next_cell, prev_cell, next_row, prev_row)
- Replace navigate_next/navigate_prev bools with single navigate field
- Add 'handled' flag to prevent double processing of Tab
- Add Up/Down arrow handling for row navigation
- Use getKeyEvents() loop instead of keyPressed() for consistency
2025-12-27 12:09:47 +01:00
e8b4c98d4a docs: Add TABLES_ARCHITECTURE.md - definitive reference for table widgets
Complete documentation covering:
- When to use AdvancedTable vs VirtualAdvancedTable
- Architecture diagram (table_core.zig as single source)
- How to extend functionality (always in table_core.zig)
- Complete API reference for table_core.zig
- Code examples and model differences
2025-12-27 01:58:57 +01:00
27b69cfcde refactor(table_core): Move Tab navigation logic to shared module (Norma #7 DRY)
ANTES: calculateNextCell/calculatePrevCell duplicados en:
  - AdvancedTableState
  - VirtualAdvancedTableState

AHORA: Lógica común en table_core.zig:
  - calculateNextCell() - calcula siguiente celda (Tab)
  - calculatePrevCell() - calcula celda anterior (Shift+Tab)
  - toggleSort() - alterna ordenación de columna
  - TabNavigateResult, CellPosition, SortDirection, SortToggleResult

Ambos widgets usan table_core, adaptando el resultado a su modelo:
  - AdvancedTable: selected_row/selected_col (índices)
  - VirtualAdvancedTable: selected_id + active_col (ID + columna)

Tests añadidos para calculateNextCell, calculatePrevCell, toggleSort
2025-12-27 01:49:56 +01:00
c2f0fbb19d refactor(tables): Add tabToNextCell/tabToPrevCell to both AdvancedTable and VirtualAdvancedTable
Norma #6: Abstract to library level
- Tab navigation with wrap now in library, not application
- AdvancedTableState.tabToNextCell/tabToPrevCell for in-memory data
- VirtualAdvancedTableState.tabToNextCell/tabToPrevCell for paginated data
- DRY: same logic available in both table widgets
2025-12-27 01:28:32 +01:00
702c33c13a feat(virtual_table): Tab navigation + cursor fixes + cell editing
- Tab/Shift+Tab with wrap navigation in editing mode
- tab_out/tab_shift result fields for application handling
- Cursor position, blinking, background color fixes
- markRowSaved() to clear dirty state after save
- last_edited_row only set when actual changes made
2025-12-27 01:18:54 +01:00
47fc5b28f7 refactor(tables): Add table_core.zig with shared rendering functions
- New module: table_core.zig with common table rendering logic
- drawCellActiveIndicator(): visual indicator for selected cell  
- detectDoubleClick(): timing-based double-click detection
- handleEditingKeyboard(): common keyboard handling for editing
- blendColor(), startsWithIgnoreCase(): utilities

VirtualAdvancedTable now uses table_core:
- Active cell indicator in drawRows (visible highlight on selected cell)
- Double-click detection in handleMouseClick
- Added state fields: last_click_time, last_click_row, last_click_col

AdvancedTable changes:
- Improved cell active indicator (alpha 0.35, double border)
- Added double-click fields to state
- Space starts editing with empty value
- Alphanumeric keys start editing in editable cells
2025-12-26 17:53:16 +01:00
65f6782d24 feat(virtual_advanced_table): Add keyboard/mouse editing triggers (F2, chars, column nav) 2025-12-26 14:54:24 +01:00
97ddf28c15 feat(virtual_advanced_table): Integrate CellEditor in draw loop with result handling 2025-12-26 14:51:03 +01:00
93836aef50 feat(virtual_advanced_table): Add CellEditor widget for inline editing 2025-12-26 14:49:04 +01:00
66816bcbf1 feat(virtual_advanced_table): Add CRUD Excel-style editing state
- Rename VirtualList → VirtualAdvancedTable
- Add CellId and CellGeometry types
- Add editing state fields (editing_cell, original_value, escape_count, etc.)
- Add editing methods: startEditing, commitEdit, cancelEdit, handleEscape
- Add getCellGeometry() for overlay positioning
- Add row_dirty flag for change tracking
2025-12-26 14:45:32 +01:00
7f8870d890 fix(advanced_table): Use std.mem.swap for Row sorting + doc warnings
- Replace manual temp variable swap with std.mem.swap (more explicit)
- Add documentation warning about pointer invalidation after sort/setRows
- Row contains StringHashMap with internal pointers - swap is safe but
  pointers obtained via getRow() are invalidated after mutations

Based on INFORME_AUDITORIA_PROFUNDA_20251225.md §1.2
2025-12-25 23:04:01 +01:00
1c284ed0f6 fix(virtual_list): Move footer display buffer to state struct
- Added footer_display_buf and footer_display_len to VirtualListState
- Fixes use-after-return bug: stack buffer passed to pushCommand() was
  invalidated when function returned, causing corrupted display in
  deferred rendering
2025-12-25 22:40:14 +01:00
ae55ea5488 CLAUDE.md: jj + NORMAS_ESENCIALES 2025-12-25 19:24:00 +01:00
R.Eugenio
b0b8346355 feat(virtual_list): FilterBar visual + click offset fix
- FilterBar chips con forma pill (border-radius completo)
- Esquinas redondeadas en TextInput del filtro
- Fix click offset: ahora cuenta filter_bar_h + header_h
- Corrección selección de fila por click

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-24 00:09:57 +01:00
R.Eugenio
7b2ba06035 fix(virtual_list): Borde completo + centrado texto
- Añadir borde alrededor de toda la lista (siempre visible)
- Mejorar centrado vertical del texto (y+4 → y+3)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 14:41:56 +01:00
R.Eugenio
b2bcdeae1a fix(virtual_list): Scroll arriba + footer compacto
- moveUp: Calcular screen position para scroll correcto
- footer_h: Reducir de 20 a 16 pixels para más filas visibles

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 14:31:12 +01:00
R.Eugenio
ae993a0f6f fix(virtual_list): Scroll en última fila y posición correcta
- moveDown: Calcular screen position antes de decidir scroll
- Scroll ahora ocurre cuando llega a última fila visible (no penúltima)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 14:18:47 +01:00
R.Eugenio
b9e7434ef7 fix(virtual_list): Scroll visual y click con offset correcto
- drawRows: Calcular window_offset para dibujar desde scroll_offset
- handleMouseClick: Convertir screen_row a data_idx con offset
- Antes siempre dibujaba desde índice 0 del buffer

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 14:11:12 +01:00
R.Eugenio
ab39830477 Añadir /init optimizado (lee NORMAS_ESENCIALES + teamdocs)
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 13:28:54 +01:00
R.Eugenio
edba1cc7e5 fix(virtual_list): Soportar key repeat con navKeyPressed
Cambiar de keyPressed() a navKeyPressed() permite que mantener
pulsada la flecha arriba/abajo mueva la selección continuamente.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 13:12:54 +01:00
R.Eugenio
206a997628 fix(virtual_list): Usar Style.Color y Command.rect
- VirtualListConfig.Colors ahora usa Style.Color en vez de u32
- Reemplazar Command.fill() por Command.rect() (fill no existe)
- Corregir tipo bg_color en drawRows

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 13:00:20 +01:00
R.Eugenio
2abb8547a5 feat(virtual_list): Fase 3 - Widget completo con renderizado
Implementación del widget VirtualList (~530 LOC):

virtualListRect():
- Registra focusable, maneja mouse/keyboard
- Calcula filas visibles y buffer size
- Detecta si necesita refetch (needsRefetch)
- Llama a DataProvider.fetchWindow() cuando necesario
- Actualiza counts desde provider

Renderizado:
- drawHeader(): títulos columnas, indicadores sort (^/v), click para ordenar
- drawRows(): filas con alternancia, selección con/sin focus
- drawFooter(): contador "pos de total" con soporte para "..."
- drawScrollbar(): thumb proporcional al scroll

Interacción:
- handleKeyboard(): ↑↓, PgUp/Dn, Home/End
- handleMouseClick(): click en fila selecciona

Características:
- Colores configurables (row_selected, row_selected_unfocus, etc.)
- Focus ring (fancy o simple)
- Clipping para contenido
- Footer muestra "15 de 500+..." → "15 de 1,234"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 12:46:50 +01:00
R.Eugenio
7d1919969f feat(virtual_list): Fase 2 - DataProvider interface + tipos + state
Nuevo módulo virtual_list para listas virtualizadas:

types.zig:
- RowData: datos genéricos de fila con ID persistente
- ColumnDef: definición de columnas (name, title, width)
- SortDirection: enum con toggle()
- CountInfo: conteo con estado (loading, partial, ready)
- VirtualListConfig: configuración con umbral configurable

data_provider.zig:
- DataProvider: interface vtable para fuentes de datos
- Métodos: fetchWindow, getTotalCount, setFilter, setSort
- MockProvider para tests
- Tests completos

state.zig:
- VirtualListState: estado de navegación y selección
- Selección por ID (no índice)
- Conversión global ↔ window index
- Navegación: moveUp/Down, pageUp/Down, goToStart/End
- Tests completos

virtual_list.zig:
- Re-exports de módulos
- Documentación de arquitectura
- VirtualListResult struct
- TODO: widget principal (Fase 3)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 12:27:23 +01:00
R.Eugenio
59d102315d fix(memory): Deep clone en Row + CellValue para evitar dangling pointers
- CellValue.clone(): duplica strings en lugar de copiar punteros
- CellValue.deinit(): libera strings clonados
- Row.owns_data: flag para indicar propiedad de memoria
- Row.clone(): ahora hace deep copy completo
- Row.deinit(): libera strings si owns_data=true

Soluciona crash al guardar cliente sin población/provincia/país,
donde loadWhoList() liberaba strings que Row clonada seguía referenciando.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-22 13:16:59 +01:00