@easyvision/easyvision-ui 1.3.9 → 1.5.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.
package/README.md CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  - [`EasyVisionMultifilter`](#easyvisionmultifilter)
27
27
  - [Field types](#field-types)
28
28
  - [Pinned, chip, locked](#pinned-chip-locked)
29
- - [Buscar (perform) button](#buscar-perform-button)
29
+ - [Perform: live vs manual](#perform-live-vs-manual)
30
30
  - [Standalone usage (no table)](#standalone-usage-no-table)
31
31
  - [Nesting](#nesting)
32
32
  - [Snapshot shape](#snapshot-shape)
@@ -364,11 +364,45 @@ To make the multifilter fully static (no `+`, no X), set `editable={false}` on t
364
364
  <EasyVisionMultifilter editable={false} config={...} />
365
365
  ```
366
366
 
367
- ### Buscar (perform) button
367
+ ### Perform: live vs manual
368
368
 
369
- > **Terminology.** "Perform" is the generic name for "user committed the filter" — i.e. the **Buscar / Search** action. It's called `perform` (not `onSearch`) because the multifilter is generic: the same event can drive a list refetch, an export, a recalculation, a navigation. The default button label is `"Buscar"`; override via `performLabel`.
369
+ > **Terminology.** "Perform" is the generic name for "user committed the filter" — i.e. the **Buscar / Search** action. It's called `perform` (not `onSearch`) because the multifilter is generic: the same event can drive a list refetch, an export, a recalculation, a navigation.
370
370
 
371
- Set `performButton={true}` and an `onPerform` callback. The button's enable state combines:
371
+ Perform fires through one of four paths:
372
+
373
+ 1. The user clicks the **Buscar** button (when `performButton: true`).
374
+ 2. The user presses Enter in a prominent text field (when `performButton: true`).
375
+ 3. `performOnMount` triggers it once after the multifilter mounts, if there's any non-empty value to re-emit (used to restore persisted state on remount).
376
+ 4. The imperative ref handle: `ref.current.perform()`.
377
+
378
+ In addition, **live mode** auto-fires perform on every change to the active values / fields. Use it for in-memory tables where filtering is cheap and per-change UI updates feel natural. Manual mode stays explicit — typically what you want for API-backed tables, where every perform = a network request.
379
+
380
+ ```tsx
381
+ <EasyVisionMultifilter
382
+ id="alerts"
383
+ performMode="live" // 'live' | 'manual' | 'auto' (default 'auto')
384
+ performDebounceMs={150} // debounce window for live mode; default 0
385
+ performOnMount // still useful for restoring persisted state
386
+ onPerform={(snap) => api.list(snap.query)}
387
+ config={...}
388
+ />
389
+ ```
390
+
391
+ `performMode: 'auto'` (the default) means **"ask the parent"**. When the multifilter is mounted inside an [`EasyVisionTable`](#binding-a-multifilter) via that table's `multifilter` prop, the table picks `'live'` for `paginationMode: 'local'` and `'manual'` for `paginationMode: 'api'`. Standalone, `'auto'` resolves to `'manual'` — safer for unknown consumers and matches the historical default.
392
+
393
+ The two modes compose with the rest of the perform machinery:
394
+
395
+ | | Manual | Live |
396
+ |---|---|---|
397
+ | Buscar button (`performButton: true`) | Visible if dirty + valid; press commits. | Visible if dirty + valid; press just forces an immediate perform (debounce skipped). |
398
+ | `performOnMount` | Fires once on mount when values are present. | Same. |
399
+ | Imperative `ref.current.perform()` | Always available. | Always available; flushes the debounce timer. |
400
+ | Field add/remove (`+` / `X`) | Stages; no perform until Buscar / ref / unmount. | Counts as a change; debounced perform follows. |
401
+ | Per-keystroke `onChange` | Always fires; perform doesn't follow. | Always fires; perform follows after `performDebounceMs`. |
402
+
403
+ #### Buscar button
404
+
405
+ Set `performButton={true}` to render the button. Its enable state combines:
372
406
 
373
407
  - `editable !== false` — the multifilter must be active.
374
408
  - `isValid` — every `mandatory` field has a non-empty value (recursively, including nested multifilters).
@@ -398,6 +432,8 @@ const ref = useRef<MultifilterHandle>(null);
398
432
  // ref.current?.getSnapshot();
399
433
  ```
400
434
 
435
+ > **Note on `onPerform` timing.** `onPerform` is dispatched on a microtask after the internal snapshot commit, so it's safe to call `setState` on a parent component inside the callback. The microtask deferral prevents React's "Cannot update a component while rendering a different component" warning that would otherwise fire when perform happens inside a commit phase (e.g. via `performOnMount` or live-mode auto-fire).
436
+
401
437
  ### Standalone usage (no table)
402
438
 
403
439
  Nothing about the multifilter is table-specific — it's a generic, persisted, validated form-snapshot component. Use it on its own to drive a chart, a KPI panel, an export, a URL query, or any other consumer.
@@ -519,7 +555,9 @@ Override per field with `toCondition: (value) => unknown` (return either a primi
519
555
  | `performPosition` | `'inline' \| 'belowRow' \| 'externalRef'` | `'inline'` | |
520
556
  | `performTargetRef` | `RefObject<HTMLElement>` | — | Required if `performPosition === 'externalRef'` (TODO portal). |
521
557
  | `performOnMount` | `boolean` | `false` | Fire `onPerform` once if seeded state has values. |
522
- | `onPerform` | `(snap) => void` | — | Fires when the user clicks Buscar (or `performOnMount` triggers it). |
558
+ | `performMode` | `'live' \| 'manual' \| 'auto'` | `'auto'` | When perform fires automatically. `'auto'` defers to the bound table's `paginationMode` (local → live, api → manual); standalone, resolves to manual. See [Perform: live vs manual](#perform-live-vs-manual). |
559
+ | `performDebounceMs` | `number` | `0` | Debounce window before a live-mode perform fires after the last change. |
560
+ | `onPerform` | `(snap) => void` | — | Fires when perform commits — from Buscar, `performOnMount`, the imperative `perform()` ref, or (live mode) any value/field change after the debounce. Dispatched on a microtask so calling `setState` inside is safe. |
523
561
  | `onChange` | `(snap) => void` | — | Every change (per keystroke / option toggle). |
524
562
  | `onStateChange` | `(snap) => void` | — | Same as `onChange`; provided for API symmetry. |
525
563
  | `showClearAll` | `boolean` | `editable` | Clears values & active fields. |
@@ -830,17 +868,24 @@ Highlighted rows get a `bg-muted/50` tint plus `data-highlighted="true"` on the
830
868
 
831
869
  ### Binding a multifilter
832
870
 
833
- Pass a multifilter declaration via the `multifilter` prop. It auto-mounts in the toolbar and inherits the table's namespace. Pressing Buscar resets `page = 1`, stores the snapshot, and refetches (api) or applies the where-clause client-side (local).
871
+ Pass a multifilter declaration via the `multifilter` prop. It auto-mounts in the toolbar and inherits the table's namespace. A perform resets `page = 1`, stores the snapshot, and refetches (api) or applies the where-clause client-side (local).
872
+
873
+ **Perform timing is auto-selected.** Unless you pass an explicit `performMode`, the bound multifilter resolves `'auto'` to:
874
+
875
+ - `'live'` when `paginationMode === 'local'` — filters apply as the user picks, no Buscar button needed.
876
+ - `'manual'` when `paginationMode === 'api'` — values stage until the user clicks Buscar (or you call `ref.current.perform()`), so you don't fire one request per keystroke.
877
+
878
+ Override per-table with `multifilter.performMode = 'live' | 'manual'`. Add `multifilter.performDebounceMs` to collapse rapid changes in live mode (useful for `type: 'text'` fields — pair with the input's own `debounceMs` if you want both layers).
834
879
 
835
880
  ```tsx
836
881
  <EasyVisionTable<Alert>
837
882
  id="alerts"
838
- paginationMode="api" orderingMode="api"
883
+ paginationMode="api" orderingMode="api" // → manual perform by default
839
884
  fetchData={fetchAlerts}
840
885
  getRowId={(a) => a.id}
841
886
  multifilter={{
842
887
  id: 'mainFilter',
843
- performButton: true,
888
+ performButton: true, // explicit Buscar UI for the manual flow
844
889
  config: {
845
890
  fields: [
846
891
  { id: 'q', type: 'text', field: 'client.name', label: 'Búsqueda', prominent: true, pinned: true },
@@ -850,6 +895,18 @@ Pass a multifilter declaration via the `multifilter` prop. It auto-mounts in the
850
895
  }}
851
896
  columns={[/* ... */]}
852
897
  />
898
+
899
+ <EasyVisionTable<Bank>
900
+ id="banks"
901
+ paginationMode="local" orderingMode="local" // → live perform by default
902
+ data={banks}
903
+ multifilter={{
904
+ id: 'banksFilter',
905
+ performDebounceMs: 150, // optional; smooths rapid edits
906
+ config: { fields: [/* ... */] },
907
+ }}
908
+ columns={[/* ... */]}
909
+ />
853
910
  ```
854
911
 
855
912
  ### External filter and manual refetch
@@ -1,9 +1,85 @@
1
- /* EasyVision table scroll wrapper — show both axes' scrollbars.
2
- * Co-located with the component so it ships wherever EasyVision is used,
3
- * even when the host project hides scrollbars globally.
4
- * Uses theme-agnostic rgba so it works without any CSS variable setup. */
1
+ /*
2
+ * EasyVisionTable styles — fully self-contained so consumer projects don't
3
+ * need their Tailwind to scan node_modules to render the table correctly.
4
+ *
5
+ * Colors use Shadcn-style HSL CSS variables defined by the host project
6
+ * (--border, --card, --muted, --muted-foreground, --primary, --background).
7
+ * Falls back to readable defaults via the second arg to var() when those
8
+ * vars aren't defined.
9
+ */
5
10
 
11
+ /* ---------- Outer card ---------- */
12
+ .ev-table-card {
13
+ border-radius: 0.375rem;
14
+ border: 1px solid hsl(var(--border, 220 13% 91%));
15
+ background: hsl(var(--card, 0 0% 100%));
16
+ overflow: hidden;
17
+ }
18
+
19
+ .ev-table-multifilter {
20
+ margin-bottom: 0.5rem;
21
+ }
22
+
23
+ /* ---------- Toolbar ---------- */
24
+ .ev-table-toolbar {
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: space-between;
28
+ gap: 0.5rem;
29
+ padding: 0.5rem 1rem;
30
+ border-bottom: 1px solid hsl(var(--border, 220 13% 91%));
31
+ }
32
+
33
+ .ev-table-toolbar-section {
34
+ display: flex;
35
+ align-items: center;
36
+ gap: 0.5rem;
37
+ }
38
+
39
+ /* ---------- Selection banner ---------- */
40
+ .ev-table-sel-banner {
41
+ display: flex;
42
+ align-items: center;
43
+ gap: 0.5rem;
44
+ border: 1px solid hsl(var(--primary, 222 47% 11%) / 0.3);
45
+ background: hsl(var(--primary, 222 47% 11%) / 0.05);
46
+ border-radius: 0.125rem;
47
+ padding: 0.25rem 0.75rem;
48
+ font-size: 0.75rem;
49
+ line-height: 1rem;
50
+ }
51
+
52
+ .ev-table-sel-banner-spinner {
53
+ width: 0.75rem;
54
+ height: 0.75rem;
55
+ color: hsl(var(--primary, 222 47% 11%));
56
+ animation: ev-spin 1s linear infinite;
57
+ }
58
+
59
+ .ev-table-sel-banner-text {
60
+ color: hsl(var(--primary, 222 47% 11%));
61
+ font-weight: 500;
62
+ }
63
+
64
+ .ev-table-clear-btn {
65
+ margin-left: auto;
66
+ height: 1.5rem;
67
+ font-size: 0.75rem;
68
+ line-height: 1rem;
69
+ }
70
+
71
+ .ev-table-clear-icon {
72
+ width: 0.75rem;
73
+ height: 0.75rem;
74
+ margin-right: 0.25rem;
75
+ }
76
+
77
+ /* ---------- Scroll wrapper (also enables horizontal scrollbar visibility
78
+ * even when host projects hide scrollbars globally) ---------- */
6
79
  .easyvision-table-scroll {
80
+ position: relative;
81
+ width: 100%;
82
+ overflow: auto;
7
83
  scrollbar-width: thin; /* Firefox */
8
84
  scrollbar-color: rgba(0, 0, 0, 0.4) transparent;
9
85
  -ms-overflow-style: auto; /* IE/Edge */
@@ -14,30 +90,24 @@
14
90
  width: 10px;
15
91
  height: 10px;
16
92
  }
17
-
18
93
  .easyvision-table-scroll::-webkit-scrollbar-track {
19
94
  background: transparent;
20
95
  }
21
-
22
96
  .easyvision-table-scroll::-webkit-scrollbar-thumb {
23
97
  background: rgba(0, 0, 0, 0.35);
24
98
  border-radius: 10px;
25
99
  border: 2px solid transparent;
26
100
  background-clip: padding-box;
27
101
  }
28
-
29
102
  .easyvision-table-scroll::-webkit-scrollbar-thumb:hover {
30
103
  background: rgba(0, 0, 0, 0.55);
31
104
  background-clip: padding-box;
32
105
  border: 2px solid transparent;
33
106
  }
34
-
35
107
  .easyvision-table-scroll::-webkit-scrollbar-corner {
36
108
  background: transparent;
37
109
  }
38
110
 
39
- /* Dark mode — works with either `prefers-color-scheme` or a `.dark` class
40
- * on a parent element (the convention used by Shadcn/UI). */
41
111
  @media (prefers-color-scheme: dark) {
42
112
  .easyvision-table-scroll {
43
113
  scrollbar-color: rgba(255, 255, 255, 0.4) transparent;
@@ -51,7 +121,6 @@
51
121
  background-clip: padding-box;
52
122
  }
53
123
  }
54
-
55
124
  .dark .easyvision-table-scroll,
56
125
  [data-theme='dark'] .easyvision-table-scroll {
57
126
  scrollbar-color: rgba(255, 255, 255, 0.4) transparent;
@@ -66,3 +135,260 @@
66
135
  background: rgba(255, 255, 255, 0.5);
67
136
  background-clip: padding-box;
68
137
  }
138
+
139
+ /* ---------- Table element ---------- */
140
+ .ev-table {
141
+ width: 100%;
142
+ min-width: max-content;
143
+ caption-side: bottom;
144
+ font-size: 0.875rem;
145
+ line-height: 1.25rem;
146
+ border-collapse: collapse;
147
+ }
148
+
149
+ /* Sticky header (used when maxBodyHeight is set) */
150
+ .ev-table thead.ev-table-thead-sticky {
151
+ position: sticky;
152
+ top: 0;
153
+ z-index: 10;
154
+ background: hsl(var(--card, 0 0% 100%));
155
+ box-shadow: inset 0 -1px 0 0 hsl(var(--border, 220 13% 91%));
156
+ }
157
+
158
+ /* Row borders / hover / selection / highlight */
159
+ .ev-table tr {
160
+ border-bottom: 1px solid hsl(var(--border, 220 13% 91%));
161
+ transition: background-color 0.15s;
162
+ }
163
+ .ev-table tbody tr:last-child {
164
+ border-bottom-width: 0;
165
+ }
166
+ .ev-table tbody tr:hover {
167
+ background: hsl(var(--muted, 210 40% 96%) / 0.5);
168
+ }
169
+ .ev-table tr[data-state="selected"] {
170
+ background: hsl(var(--muted, 210 40% 96%));
171
+ }
172
+ .ev-table tr[data-highlighted="true"] {
173
+ background: hsl(var(--muted, 210 40% 96%) / 0.5);
174
+ }
175
+ .ev-table-row-clickable {
176
+ cursor: pointer;
177
+ }
178
+
179
+ /* th / td defaults */
180
+ .ev-table th {
181
+ height: 3rem;
182
+ padding: 0 1rem;
183
+ text-align: left;
184
+ vertical-align: middle;
185
+ font-weight: 500;
186
+ color: hsl(var(--muted-foreground, 215 16% 47%));
187
+ position: relative;
188
+ }
189
+ .ev-table th:has([role=checkbox]) {
190
+ padding-right: 0;
191
+ }
192
+ .ev-table td {
193
+ padding: 1rem;
194
+ vertical-align: middle;
195
+ }
196
+ .ev-table td:has([role=checkbox]) {
197
+ padding-right: 0;
198
+ }
199
+
200
+ /* Large-screens-only column (matches Tailwind's lg breakpoint = 1024px) */
201
+ @media (max-width: 1023.98px) {
202
+ .ev-table .ev-table-large-only {
203
+ display: none;
204
+ }
205
+ }
206
+
207
+ /* Checkbox column width */
208
+ .ev-table-th-checkbox {
209
+ width: 60px;
210
+ white-space: nowrap;
211
+ }
212
+
213
+ /* Sortable header button */
214
+ .ev-table-sort-btn {
215
+ display: inline-flex;
216
+ align-items: center;
217
+ gap: 0.25rem;
218
+ user-select: none;
219
+ background: transparent;
220
+ border: 0;
221
+ padding: 0;
222
+ color: inherit;
223
+ font: inherit;
224
+ cursor: pointer;
225
+ }
226
+ .ev-table-sort-btn:hover {
227
+ opacity: 0.7;
228
+ }
229
+ .ev-table-sort-icon {
230
+ width: 0.75rem;
231
+ height: 0.75rem;
232
+ }
233
+ .ev-table-sort-icon-inactive {
234
+ color: hsl(var(--muted-foreground, 215 16% 47%));
235
+ opacity: 0.5;
236
+ }
237
+
238
+ /* ---------- Resize handle ---------- */
239
+ .ev-resize-handle {
240
+ position: absolute;
241
+ top: 0;
242
+ right: 0;
243
+ height: 100%;
244
+ width: 0.75rem;
245
+ margin-right: -0.375rem;
246
+ cursor: col-resize;
247
+ user-select: none;
248
+ touch-action: none;
249
+ }
250
+ .ev-resize-handle::after {
251
+ content: '';
252
+ position: absolute;
253
+ right: 0.375rem;
254
+ top: 50%;
255
+ transform: translateY(-50%);
256
+ height: 50%;
257
+ width: 1px;
258
+ background: hsl(var(--border, 220 13% 91%));
259
+ transition: all 0.15s;
260
+ }
261
+ .ev-resize-handle:hover::after {
262
+ width: 0.375rem;
263
+ height: 100%;
264
+ top: 0;
265
+ transform: translateY(0);
266
+ background: hsl(var(--primary, 222 47% 11%) / 0.3);
267
+ }
268
+ .ev-resize-handle.is-resizing::after {
269
+ width: 0.375rem;
270
+ height: 100%;
271
+ top: 0;
272
+ transform: translateY(0);
273
+ background: hsl(var(--primary, 222 47% 11%) / 0.6);
274
+ }
275
+
276
+ /* ---------- Truncate cell ---------- */
277
+ .ev-table-cell-truncate {
278
+ max-width: 0;
279
+ }
280
+ .ev-table-cell-truncate-inner {
281
+ overflow: hidden;
282
+ text-overflow: ellipsis;
283
+ white-space: nowrap;
284
+ }
285
+
286
+ /* ---------- Empty / loading state ---------- */
287
+ .ev-table-empty-cell {
288
+ height: 12rem;
289
+ text-align: center;
290
+ }
291
+ .ev-table-spinner-wrapper {
292
+ display: flex;
293
+ align-items: center;
294
+ justify-content: center;
295
+ }
296
+ .ev-table-loading-spinner {
297
+ width: 1.5rem;
298
+ height: 1.5rem;
299
+ color: hsl(var(--muted-foreground, 215 16% 47%));
300
+ animation: ev-spin 1s linear infinite;
301
+ }
302
+ .ev-table-empty-state {
303
+ display: flex;
304
+ flex-direction: column;
305
+ align-items: center;
306
+ gap: 0.75rem;
307
+ }
308
+ .ev-table-empty-text {
309
+ color: hsl(var(--muted-foreground, 215 16% 47%));
310
+ }
311
+
312
+ @keyframes ev-spin {
313
+ to { transform: rotate(360deg); }
314
+ }
315
+
316
+ /* ---------- Pagination footer ---------- */
317
+ .ev-table-footer {
318
+ display: flex;
319
+ align-items: center;
320
+ justify-content: space-between;
321
+ padding: 1rem;
322
+ border-top: 1px solid hsl(var(--border, 220 13% 91%));
323
+ font-size: 0.875rem;
324
+ line-height: 1.25rem;
325
+ color: hsl(var(--muted-foreground, 215 16% 47%));
326
+ }
327
+ .ev-table-footer-section {
328
+ display: flex;
329
+ align-items: center;
330
+ gap: 0.75rem;
331
+ }
332
+ .ev-table-footer-ipp {
333
+ height: 2.25rem;
334
+ width: 70px;
335
+ border: 1px solid hsl(var(--border, 220 13% 91%));
336
+ }
337
+ .ev-table-footer-pg {
338
+ height: 2.25rem;
339
+ width: 4rem;
340
+ border: 1px solid hsl(var(--border, 220 13% 91%));
341
+ }
342
+ .ev-table-footer-nav {
343
+ display: flex;
344
+ align-items: center;
345
+ gap: 0.25rem;
346
+ margin-left: 0.25rem;
347
+ }
348
+ .ev-table-footer-nav-btn {
349
+ height: 2rem;
350
+ width: 2rem;
351
+ }
352
+ .ev-table-footer-nav-icon {
353
+ width: 1rem;
354
+ height: 1rem;
355
+ }
356
+
357
+ /* ---------- Select-all control ---------- */
358
+ .ev-sa-control {
359
+ display: inline-flex;
360
+ align-items: center;
361
+ gap: 0.25rem;
362
+ }
363
+ .ev-sa-toggle {
364
+ display: inline-flex;
365
+ align-items: center;
366
+ justify-content: center;
367
+ height: 1.25rem;
368
+ width: 1.25rem;
369
+ border-radius: 0.25rem;
370
+ border: 1px solid hsl(var(--border, 220 13% 91%));
371
+ background: hsl(var(--background, 0 0% 100%));
372
+ cursor: pointer;
373
+ }
374
+ .ev-sa-toggle:hover {
375
+ background: hsl(var(--muted, 210 40% 96%));
376
+ }
377
+ .ev-sa-toggle-icon {
378
+ width: 0.875rem;
379
+ height: 0.875rem;
380
+ }
381
+
382
+ /* ---------- Column visibility menu ---------- */
383
+ .ev-cv-icon {
384
+ margin-right: 0.5rem;
385
+ width: 1rem;
386
+ height: 1rem;
387
+ }
388
+ .ev-cv-menu {
389
+ max-height: 16rem;
390
+ overflow-y: auto;
391
+ }
392
+ .ev-cv-item {
393
+ text-transform: capitalize;
394
+ }