@easyvision/easyvision-ui 1.3.4
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 +1391 -0
- package/dist/EasyVisionTable.css +68 -0
- package/dist/easyvision.css +30 -0
- package/dist/index.cjs +2968 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +612 -0
- package/dist/index.d.ts +612 -0
- package/dist/index.js +2929 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { ComponentType, ReactNode, RefObject, Ref } from 'react';
|
|
4
|
+
import { RowData } from '@tanstack/react-table';
|
|
5
|
+
import * as zustand_vanilla from 'zustand/vanilla';
|
|
6
|
+
|
|
7
|
+
interface BaseStatefulProps<S = unknown> {
|
|
8
|
+
/** Stable identifier supplied by the user. Internal slice key derived as `${id}-${kind}`. */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Persist value across mount cycles. Default: false → cleared on unmount. */
|
|
11
|
+
persist?: boolean;
|
|
12
|
+
/** When this returns true, the slice is dropped and re-initialized. */
|
|
13
|
+
clearWhen?: (snapshot: S) => boolean;
|
|
14
|
+
/** Notified on every state change. */
|
|
15
|
+
onStateChange?: (snapshot: S) => void;
|
|
16
|
+
}
|
|
17
|
+
interface SelectorOption<V extends string | number = string | number> {
|
|
18
|
+
value: V;
|
|
19
|
+
label: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface EasyVisionInputProps extends BaseStatefulProps<string> {
|
|
23
|
+
label?: string;
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
/** Auto-fire onChange after Nms of inactivity. Default 300. */
|
|
26
|
+
debounceMs?: number;
|
|
27
|
+
mandatory?: boolean;
|
|
28
|
+
defaultValue?: string;
|
|
29
|
+
onChange?: (value: string) => void;
|
|
30
|
+
icon?: 'search' | 'none';
|
|
31
|
+
showClearButton?: boolean;
|
|
32
|
+
className?: string;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare function EasyVisionInput({ id, label, placeholder, debounceMs, mandatory, defaultValue, onChange, onStateChange, icon, showClearButton, className, disabled, persist, clearWhen, }: EasyVisionInputProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
interface EasyVisionSelectorProps<V extends string | number = string | number> extends BaseStatefulProps<V | undefined> {
|
|
39
|
+
label?: string;
|
|
40
|
+
options: SelectorOption<V>[] | (() => Promise<SelectorOption<V>[]>);
|
|
41
|
+
placeholder?: string;
|
|
42
|
+
mandatory?: boolean;
|
|
43
|
+
defaultValue?: V;
|
|
44
|
+
/** Confirm-mode parity with bench-vision SimpleSelector — value isn't committed until Confirm. */
|
|
45
|
+
confirmMode?: boolean;
|
|
46
|
+
confirmLabel?: string;
|
|
47
|
+
searchable?: boolean;
|
|
48
|
+
onChange?: (value: V | undefined) => void;
|
|
49
|
+
className?: string;
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare function EasyVisionSelector<V extends string | number = string | number>({ id, label, options, placeholder, mandatory, defaultValue, confirmMode, confirmLabel, searchable, onChange, onStateChange, className, disabled, persist, clearWhen, }: EasyVisionSelectorProps<V>): react_jsx_runtime.JSX.Element;
|
|
54
|
+
|
|
55
|
+
interface DateRangeValue {
|
|
56
|
+
from?: Date;
|
|
57
|
+
to?: Date;
|
|
58
|
+
}
|
|
59
|
+
interface NumberRangeValue {
|
|
60
|
+
min?: number;
|
|
61
|
+
max?: number;
|
|
62
|
+
}
|
|
63
|
+
interface MultifilterFieldBase {
|
|
64
|
+
id: string;
|
|
65
|
+
label: string;
|
|
66
|
+
/** API field path — e.g. 'client.country'. Optional for purely UI fields. */
|
|
67
|
+
field?: string;
|
|
68
|
+
/** Always rendered, never removable. */
|
|
69
|
+
pinned?: boolean;
|
|
70
|
+
/** Show by default in the chip area on first mount (ignored if pinned — pinned ⇒ always active). */
|
|
71
|
+
initiallyActive?: boolean;
|
|
72
|
+
/** Suppress the X chip but keep the field active. */
|
|
73
|
+
locked?: boolean;
|
|
74
|
+
mandatory?: boolean;
|
|
75
|
+
visible?: boolean | ((values: Record<string, unknown>) => boolean);
|
|
76
|
+
/**
|
|
77
|
+
* Map the user's value to a backend condition (a `where` fragment).
|
|
78
|
+
*
|
|
79
|
+
* Return shape:
|
|
80
|
+
* - `undefined` / `null` → field contributes nothing to the query.
|
|
81
|
+
* - An object starting with `$or` / `$and` → merged at the top level of
|
|
82
|
+
* `where` as-is (use this to search across multiple paths, e.g.
|
|
83
|
+
* `{ $or: [{ name: like }, { topics: like }] }`).
|
|
84
|
+
* - Anything else → wrapped under `def.field` automatically.
|
|
85
|
+
*
|
|
86
|
+
* Use this for: multi-path search bars, range encoding, value mapping
|
|
87
|
+
* (e.g. `'RECURRING' → true`), $in vs scalar tradeoffs, etc.
|
|
88
|
+
*/
|
|
89
|
+
toCondition?: (value: unknown) => unknown;
|
|
90
|
+
/** @deprecated Renamed to `toCondition`. Kept as an alias for back-compat. */
|
|
91
|
+
transform?: (value: unknown) => unknown;
|
|
92
|
+
defaultValue?: unknown;
|
|
93
|
+
placeholder?: string;
|
|
94
|
+
}
|
|
95
|
+
interface TextFieldDef extends MultifilterFieldBase {
|
|
96
|
+
type: 'text';
|
|
97
|
+
/**
|
|
98
|
+
* Render this field as a prominent full-width search bar at the top of the
|
|
99
|
+
* panel (with a magnifier icon and Enter-to-perform), instead of as an
|
|
100
|
+
* inline chip. Orthogonal to `pinned`/`initiallyActive`:
|
|
101
|
+
* - `prominent + pinned` → permanent big bar (replaces the legacy `config.searchField`).
|
|
102
|
+
* - `prominent + initiallyActive` → big bar that the user can detach via X
|
|
103
|
+
* and re-add from the `+` menu.
|
|
104
|
+
* - `prominent` (alone) → starts hidden; users opt in from the `+` menu and
|
|
105
|
+
* it then appears as a big bar.
|
|
106
|
+
*
|
|
107
|
+
* Multiple prominent fields are supported and wrap onto extra rows as needed.
|
|
108
|
+
*/
|
|
109
|
+
prominent?: boolean;
|
|
110
|
+
}
|
|
111
|
+
interface SelectorFieldDef<V extends string | number = string | number> extends MultifilterFieldBase {
|
|
112
|
+
type: 'selector';
|
|
113
|
+
options: SelectorOption<V>[] | (() => Promise<SelectorOption<V>[]>);
|
|
114
|
+
searchable?: boolean;
|
|
115
|
+
}
|
|
116
|
+
interface MultiSelectFieldDef<V extends string | number = string | number> extends MultifilterFieldBase {
|
|
117
|
+
type: 'multiselect';
|
|
118
|
+
options: SelectorOption<V>[] | (() => Promise<SelectorOption<V>[]>);
|
|
119
|
+
}
|
|
120
|
+
interface DateRangeFieldDef extends MultifilterFieldBase {
|
|
121
|
+
type: 'dateRange';
|
|
122
|
+
}
|
|
123
|
+
interface NumberRangeFieldDef extends MultifilterFieldBase {
|
|
124
|
+
type: 'numberRange';
|
|
125
|
+
}
|
|
126
|
+
interface MultifilterFieldDef extends MultifilterFieldBase {
|
|
127
|
+
type: 'multifilter';
|
|
128
|
+
config: MultifilterConfig;
|
|
129
|
+
}
|
|
130
|
+
interface CustomFieldDef extends MultifilterFieldBase {
|
|
131
|
+
type: 'custom';
|
|
132
|
+
component: ComponentType<{
|
|
133
|
+
value: unknown;
|
|
134
|
+
onChange: (value: unknown) => void;
|
|
135
|
+
onRemove: () => void;
|
|
136
|
+
definition: MultifilterFieldBase;
|
|
137
|
+
}>;
|
|
138
|
+
}
|
|
139
|
+
type FieldDef = TextFieldDef | SelectorFieldDef | MultiSelectFieldDef | DateRangeFieldDef | NumberRangeFieldDef | MultifilterFieldDef | CustomFieldDef;
|
|
140
|
+
interface MultifilterConfig {
|
|
141
|
+
/**
|
|
142
|
+
* @deprecated Prefer adding a `TextFieldDef` to `fields` with
|
|
143
|
+
* `prominent: true, pinned: true`. Kept as an alias for backward
|
|
144
|
+
* compatibility — internally treated as a prominent pinned text field.
|
|
145
|
+
*/
|
|
146
|
+
searchField?: TextFieldDef;
|
|
147
|
+
fields: FieldDef[];
|
|
148
|
+
defaultOrder?: string[];
|
|
149
|
+
defaultLimit?: number;
|
|
150
|
+
}
|
|
151
|
+
interface MultifilterLabels {
|
|
152
|
+
search: string;
|
|
153
|
+
clear: string;
|
|
154
|
+
perform: string;
|
|
155
|
+
addFilter: string;
|
|
156
|
+
noOptions: string;
|
|
157
|
+
searchPlaceholder: string;
|
|
158
|
+
}
|
|
159
|
+
interface MultifilterQuery {
|
|
160
|
+
where?: Record<string, unknown>;
|
|
161
|
+
order?: string[];
|
|
162
|
+
limit?: number;
|
|
163
|
+
}
|
|
164
|
+
interface MultifilterSnapshot {
|
|
165
|
+
values: Record<string, unknown>;
|
|
166
|
+
activeFields: string[];
|
|
167
|
+
isValid: boolean;
|
|
168
|
+
isDirty: boolean;
|
|
169
|
+
query: MultifilterQuery;
|
|
170
|
+
}
|
|
171
|
+
interface MultifilterHandle {
|
|
172
|
+
/** Programmatically trigger the perform action (same as pressing Buscar). */
|
|
173
|
+
perform: () => void;
|
|
174
|
+
/** Read the current snapshot. */
|
|
175
|
+
getSnapshot: () => MultifilterSnapshot;
|
|
176
|
+
}
|
|
177
|
+
interface EasyVisionMultifilterProps extends BaseStatefulProps<MultifilterSnapshot> {
|
|
178
|
+
config: MultifilterConfig;
|
|
179
|
+
/** Toggle add/remove (the "+" and X chips). When false, layout is fully static. Default true. */
|
|
180
|
+
editable?: boolean;
|
|
181
|
+
/** Show a Buscar button. Default false. */
|
|
182
|
+
performButton?: boolean;
|
|
183
|
+
performLabel?: string;
|
|
184
|
+
performIcon?: ReactNode;
|
|
185
|
+
performPosition?: 'inline' | 'belowRow' | 'externalRef';
|
|
186
|
+
performTargetRef?: RefObject<HTMLElement>;
|
|
187
|
+
/** Auto-fire onPerform once on mount (useful when restoring persisted state). */
|
|
188
|
+
performOnMount?: boolean;
|
|
189
|
+
onPerform?: (snap: MultifilterSnapshot) => void;
|
|
190
|
+
onChange?: (snap: MultifilterSnapshot) => void;
|
|
191
|
+
showClearAll?: boolean;
|
|
192
|
+
labels?: Partial<MultifilterLabels>;
|
|
193
|
+
className?: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
declare const EasyVisionMultifilter: React.ForwardRefExoticComponent<EasyVisionMultifilterProps & React.RefAttributes<MultifilterHandle>>;
|
|
197
|
+
|
|
198
|
+
declare const EasyVisionCard: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
199
|
+
declare const EasyVisionCardHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
200
|
+
declare const EasyVisionCardTitle: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLHeadingElement> & React.RefAttributes<HTMLHeadingElement>>;
|
|
201
|
+
declare const EasyVisionCardDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
|
202
|
+
declare const EasyVisionCardContent: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
203
|
+
declare const EasyVisionCardFooter: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* LoopBack adapter for `EasyVisionTable`.
|
|
207
|
+
*
|
|
208
|
+
* Provides the canonical LoopBack `Filter` / `WhereValue` / `CountResponse`
|
|
209
|
+
* shapes plus a fetcher factory (`createLoopbackTableFetcher`) compatible with
|
|
210
|
+
* the table's `api` pagination/ordering mode. The factory handles the
|
|
211
|
+
* boilerplate of:
|
|
212
|
+
* - mapping the table sort to LoopBack `order`
|
|
213
|
+
* - computing `skip` from page/itemsPerPage
|
|
214
|
+
* - extracting `where` from the merged filter (multifilter ∪ external)
|
|
215
|
+
* - issuing rows + count requests in parallel
|
|
216
|
+
* - only sending `where` to the count endpoint
|
|
217
|
+
*
|
|
218
|
+
* The library makes no assumptions about how the HTTP requests are issued —
|
|
219
|
+
* `fetchPage` and `fetchCount` are plain async functions. Bring your own
|
|
220
|
+
* authentication, base URL, error handling, etc.
|
|
221
|
+
*
|
|
222
|
+
* Pages can also import `LoopbackFilter` / `LoopbackWhereValue` directly to
|
|
223
|
+
* build hand-rolled filters (e.g. the `toCondition` of a custom multifilter
|
|
224
|
+
* field) without reaching for project-internal type modules.
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* LoopBack `where` clause primitive. Mirrors LoopBack 3/4 query operators.
|
|
229
|
+
*/
|
|
230
|
+
type LoopbackWhereValue = string | number | boolean | {
|
|
231
|
+
$in: (string | number | boolean)[];
|
|
232
|
+
} | {
|
|
233
|
+
$nin: (string | number | boolean)[];
|
|
234
|
+
} | {
|
|
235
|
+
$regex: string;
|
|
236
|
+
$options?: string;
|
|
237
|
+
} | {
|
|
238
|
+
$gte?: string | number;
|
|
239
|
+
$lte?: string | number;
|
|
240
|
+
} | {
|
|
241
|
+
$or: Record<string, LoopbackWhereValue>[];
|
|
242
|
+
} | {
|
|
243
|
+
$and: Record<string, LoopbackWhereValue>[];
|
|
244
|
+
} | Record<string, unknown>;
|
|
245
|
+
/**
|
|
246
|
+
* LoopBack `Filter` object. Permissive on `where` so projects' own stricter
|
|
247
|
+
* filter types remain assignable.
|
|
248
|
+
*/
|
|
249
|
+
interface LoopbackFilter {
|
|
250
|
+
where?: {
|
|
251
|
+
[key: string]: LoopbackWhereValue;
|
|
252
|
+
} | Record<string, any>;
|
|
253
|
+
fields?: string[];
|
|
254
|
+
excludeFields?: string[];
|
|
255
|
+
include?: object[];
|
|
256
|
+
order?: string[];
|
|
257
|
+
limit?: number;
|
|
258
|
+
skip?: number;
|
|
259
|
+
}
|
|
260
|
+
interface LoopbackCountResponse {
|
|
261
|
+
count: number;
|
|
262
|
+
}
|
|
263
|
+
interface CreateLoopbackTableFetcherOptions<T> {
|
|
264
|
+
/** Returns the page of rows for the given LoopBack filter. */
|
|
265
|
+
fetchPage: (filter: LoopbackFilter) => Promise<T[]>;
|
|
266
|
+
/** Returns `{ count }` for the given LoopBack filter (only `where` is used). */
|
|
267
|
+
fetchCount: (filter: LoopbackFilter) => Promise<LoopbackCountResponse>;
|
|
268
|
+
/** LoopBack `include` clause applied to every page fetch. */
|
|
269
|
+
include?: object[];
|
|
270
|
+
/** LoopBack `fields` clause (whitelist) applied to every page fetch. */
|
|
271
|
+
fields?: string[];
|
|
272
|
+
/** Order applied when the table has no active sort. */
|
|
273
|
+
defaultOrder?: string[];
|
|
274
|
+
}
|
|
275
|
+
declare function createLoopbackTableFetcher<T = unknown>(opts: CreateLoopbackTableFetcherOptions<T>): ({ page, itemsPerPage, sort, filter, }: ApiFetchParams) => Promise<ApiFetchResult<T>>;
|
|
276
|
+
/**
|
|
277
|
+
* Evaluate a LoopBack `where` clause against a single row, returning `true`
|
|
278
|
+
* iff the row satisfies the clause.
|
|
279
|
+
*
|
|
280
|
+
* This is the canonical in-memory counterpart to the LoopBack DSL spoken by
|
|
281
|
+
* `createLoopbackTableFetcher` and the multifilter. Use it to power local-mode
|
|
282
|
+
* table filtering, derive filtered selectors from cached datasets, run
|
|
283
|
+
* client-side previews of complex filters, etc. — anywhere you'd otherwise
|
|
284
|
+
* hand-write equivalent JS.
|
|
285
|
+
*
|
|
286
|
+
* Supported features:
|
|
287
|
+
* - Field equality on primitives (`{ status: 'OPEN' }`).
|
|
288
|
+
* - Operator objects: `$eq`, `$ne` / `$neq`, `$in`, `$nin`, `$gt`, `$gte`,
|
|
289
|
+
* `$lt`, `$lte`, `$regex` (with optional `$options`), `$exists`.
|
|
290
|
+
* - Logical combinators: `$and`, `$or`, `$not`.
|
|
291
|
+
* - Arbitrary-depth dotted paths (e.g. `'client.address.country'`).
|
|
292
|
+
* - Array fan-out: when a path traverses an array of objects, the field is
|
|
293
|
+
* considered to match if any element matches.
|
|
294
|
+
*
|
|
295
|
+
* Behavior on edge cases:
|
|
296
|
+
* - `undefined` / empty `where` → `true` (no filter).
|
|
297
|
+
* - Unknown `$operator` → `false` (fail-closed) to surface bugs early.
|
|
298
|
+
* - Plain-object equality (e.g. `{ a: { b: 1 } }`) is intentionally not
|
|
299
|
+
* supported; use dotted paths or `$and` instead.
|
|
300
|
+
*/
|
|
301
|
+
declare function matchLoopbackWhere(row: unknown, where: LoopbackFilter['where'] | undefined): boolean;
|
|
302
|
+
|
|
303
|
+
type TableMode = 'local' | 'api';
|
|
304
|
+
/**
|
|
305
|
+
* Controls the fallback sorting behavior when a column does not specify
|
|
306
|
+
* `sortable` explicitly:
|
|
307
|
+
* - `'nonNested'` (default): flat fields sortable, nested (dot-path) fields not.
|
|
308
|
+
* - `'all'`: every data column sortable, including nested fields.
|
|
309
|
+
* - `'disabled'`: no data column sortable unless it sets `sortable: true`.
|
|
310
|
+
*
|
|
311
|
+
* Per-column `sortable: true | false` always wins over this default.
|
|
312
|
+
*/
|
|
313
|
+
type DefaultSortingMode = 'disabled' | 'nonNested' | 'all';
|
|
314
|
+
/**
|
|
315
|
+
* Column definition for EasyVisionTable.
|
|
316
|
+
*
|
|
317
|
+
* Two variants distinguished by `type`:
|
|
318
|
+
* - `data` (default): maps to a value in the row. `field` is the dot-path used
|
|
319
|
+
* for both the column ID and value extraction. Sortable by default for flat
|
|
320
|
+
* fields; nested fields require `sortable: true` to enable sorting.
|
|
321
|
+
* - `ui`: presentational column with no underlying value. `field` is just a
|
|
322
|
+
* unique ID. `cell` is required.
|
|
323
|
+
*
|
|
324
|
+
* `cell` receives the row item directly. When omitted on a `data` column, the
|
|
325
|
+
* library renders the resolved value in a standard span.
|
|
326
|
+
*/
|
|
327
|
+
type EasyVisionColumn<T> = {
|
|
328
|
+
type?: 'data';
|
|
329
|
+
/** Dot-path to the value (e.g. `"client.name"`). Doubles as the column ID. */
|
|
330
|
+
field: string;
|
|
331
|
+
header: string | ReactNode | ((props: unknown) => ReactNode);
|
|
332
|
+
/** Custom renderer. Receives the row item directly. Omit for default span. */
|
|
333
|
+
cell?: (item: T) => ReactNode;
|
|
334
|
+
/**
|
|
335
|
+
* Force-enable or force-disable sorting. Defaults: flat fields → enabled,
|
|
336
|
+
* nested fields → disabled (because most APIs don't support nested sort).
|
|
337
|
+
*/
|
|
338
|
+
sortable?: boolean;
|
|
339
|
+
initiallyHidden?: boolean;
|
|
340
|
+
largeScreensOnly?: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Fixed column width. Number → pixels; string → any CSS width value
|
|
343
|
+
* (`'200px'`, `'12rem'`, `'min-content'`). When unset, the column grows
|
|
344
|
+
* to fit its content (the table uses `min-w-max`).
|
|
345
|
+
*/
|
|
346
|
+
width?: number | string;
|
|
347
|
+
/**
|
|
348
|
+
* Clamp the cell content to a single line with an ellipsis. For the
|
|
349
|
+
* default cell renderer the full text is also exposed via `title=` for
|
|
350
|
+
* a native hover tooltip; for custom `cell` renderers, set your own
|
|
351
|
+
* `title` if you want one.
|
|
352
|
+
*
|
|
353
|
+
* Combine with `width` (or `resizable`) to bound the column — without a
|
|
354
|
+
* width, a `<table>` cell will still expand to fit, defeating truncation.
|
|
355
|
+
*/
|
|
356
|
+
truncate?: boolean;
|
|
357
|
+
/**
|
|
358
|
+
* Allow the user to drag the column's right edge to resize it. The
|
|
359
|
+
* starting width is `width` (or 240px if unset). User-resized widths are
|
|
360
|
+
* kept in component state for the lifetime of the mount.
|
|
361
|
+
*/
|
|
362
|
+
resizable?: boolean;
|
|
363
|
+
} | {
|
|
364
|
+
type: 'ui';
|
|
365
|
+
/** Unique column ID. */
|
|
366
|
+
field: string;
|
|
367
|
+
header: string | ReactNode | ((props: unknown) => ReactNode);
|
|
368
|
+
cell: (item: T) => ReactNode;
|
|
369
|
+
initiallyHidden?: boolean;
|
|
370
|
+
largeScreensOnly?: boolean;
|
|
371
|
+
/** See data-column docs. */
|
|
372
|
+
width?: number | string;
|
|
373
|
+
/** See data-column docs. */
|
|
374
|
+
truncate?: boolean;
|
|
375
|
+
/** See data-column docs. */
|
|
376
|
+
resizable?: boolean;
|
|
377
|
+
};
|
|
378
|
+
interface ApiFetchParams {
|
|
379
|
+
page: number;
|
|
380
|
+
itemsPerPage: number;
|
|
381
|
+
sort: {
|
|
382
|
+
column: string;
|
|
383
|
+
descending: boolean;
|
|
384
|
+
} | null;
|
|
385
|
+
/** Latest perform-confirmed multifilter query, when a multifilter is bound. */
|
|
386
|
+
filter?: MultifilterQuery;
|
|
387
|
+
}
|
|
388
|
+
interface ApiFetchResult<T> {
|
|
389
|
+
rows: T[];
|
|
390
|
+
totalCount: number;
|
|
391
|
+
}
|
|
392
|
+
type SelectionChange<T = unknown> = {
|
|
393
|
+
scope: 'page';
|
|
394
|
+
ids: string[];
|
|
395
|
+
rows: T[];
|
|
396
|
+
} | {
|
|
397
|
+
scope: 'all';
|
|
398
|
+
mode: 'in-memory';
|
|
399
|
+
ids: string[];
|
|
400
|
+
rows: T[];
|
|
401
|
+
} | {
|
|
402
|
+
scope: 'all';
|
|
403
|
+
mode: 'wildcard';
|
|
404
|
+
ids: string[];
|
|
405
|
+
exceptIds: string[];
|
|
406
|
+
rows: T[];
|
|
407
|
+
};
|
|
408
|
+
interface TableLabels {
|
|
409
|
+
rowsPerPage: string;
|
|
410
|
+
results: string;
|
|
411
|
+
page: string;
|
|
412
|
+
of: string;
|
|
413
|
+
noData: string;
|
|
414
|
+
loading: string;
|
|
415
|
+
customizeColumns: string;
|
|
416
|
+
selectAllPage: string;
|
|
417
|
+
selectAllAll: string;
|
|
418
|
+
selectedAllBanner: (n: number) => string;
|
|
419
|
+
selectedCountBanner: (n: number) => string;
|
|
420
|
+
clearSelection: string;
|
|
421
|
+
}
|
|
422
|
+
interface EasyVisionTableProps<T> extends BaseStatefulProps {
|
|
423
|
+
columns: EasyVisionColumn<T>[];
|
|
424
|
+
paginationMode?: TableMode;
|
|
425
|
+
orderingMode?: TableMode;
|
|
426
|
+
/**
|
|
427
|
+
* Fallback sorting behavior for columns that don't set `sortable` explicitly.
|
|
428
|
+
* Defaults to `'nonNested'`.
|
|
429
|
+
*/
|
|
430
|
+
defaultSorting?: DefaultSortingMode;
|
|
431
|
+
/** local mode: full dataset; the table slices it. */
|
|
432
|
+
data?: T[];
|
|
433
|
+
/** api mode: server-driven. */
|
|
434
|
+
fetchData?: (params: ApiFetchParams) => Promise<ApiFetchResult<T>>;
|
|
435
|
+
/**
|
|
436
|
+
* Declarative shortcut for LoopBack-backed tables. When set, the table
|
|
437
|
+
* builds its own `fetchData` via `createLoopbackTableFetcher` and forces
|
|
438
|
+
* `paginationMode` / `orderingMode` to `'api'`. Mutually exclusive with
|
|
439
|
+
* an explicit `fetchData`.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* <EasyVisionTable
|
|
443
|
+
* id="alerts"
|
|
444
|
+
* loopback={{
|
|
445
|
+
* fetchPage: fetchAlertsByFilter,
|
|
446
|
+
* fetchCount: countAlertsByFilter,
|
|
447
|
+
* include: [{ relation: 'client' }],
|
|
448
|
+
* fields: ALERT_FIELDS,
|
|
449
|
+
* defaultOrder: ['created DESC'],
|
|
450
|
+
* }}
|
|
451
|
+
* columns={columns}
|
|
452
|
+
* />
|
|
453
|
+
*/
|
|
454
|
+
loopback?: CreateLoopbackTableFetcherOptions<T>;
|
|
455
|
+
/**
|
|
456
|
+
* Fires after each successful API fetch with the freshly loaded rows and total count.
|
|
457
|
+
* Useful when the page needs to mirror the loaded slice into another store
|
|
458
|
+
* (e.g. a global context for export/selection) without wrapping `fetchData`.
|
|
459
|
+
*/
|
|
460
|
+
onDataLoaded?: (rows: T[], totalCount: number) => void;
|
|
461
|
+
/** Declarative bound multifilter — auto-mounted in the toolbar. */
|
|
462
|
+
multifilter?: EasyVisionMultifilterProps;
|
|
463
|
+
/** Forwarded to the bound multifilter; lets callers call `perform()` programmatically. */
|
|
464
|
+
multifilterRef?: Ref<MultifilterHandle>;
|
|
465
|
+
/**
|
|
466
|
+
* Force a refetch in api mode by changing this value. The table also resets
|
|
467
|
+
* `page` to 1 on change, mirroring the multifilter Buscar semantics. Useful
|
|
468
|
+
* when the page drives its own filter UI separate from a bound multifilter.
|
|
469
|
+
*/
|
|
470
|
+
refetchSignal?: unknown;
|
|
471
|
+
/** External `where` to merge into every fetch. Used when the page drives its own filter UI. */
|
|
472
|
+
externalFilter?: {
|
|
473
|
+
where?: Record<string, unknown>;
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* In local pagination mode, this function decides whether a row passes the
|
|
477
|
+
* current `where` clause (built from the bound multifilter and/or
|
|
478
|
+
* `externalFilter`). Defaults to `matchLoopbackWhere` — a pure evaluator for
|
|
479
|
+
* the LoopBack `where` DSL — so a multifilter authored once works the same
|
|
480
|
+
* locally and against an API.
|
|
481
|
+
*
|
|
482
|
+
* Override to:
|
|
483
|
+
* - extend matching with domain rules (`(row, where) => matchLoopbackWhere(row, where) && row.isActive`)
|
|
484
|
+
* - speak a different DSL than LoopBack
|
|
485
|
+
* - run hand-written predicates that ignore `where` entirely
|
|
486
|
+
*
|
|
487
|
+
* Ignored when `paginationMode` is `'api'` (the server filters there).
|
|
488
|
+
*/
|
|
489
|
+
localMatch?: (row: T, where: LoopbackFilter['where'] | undefined) => boolean;
|
|
490
|
+
/**
|
|
491
|
+
* Resolve a stable id for a row. Defaults to `row.id` (cast to string).
|
|
492
|
+
* Override only if your rows don't have a top-level `id` field.
|
|
493
|
+
*/
|
|
494
|
+
getRowId?: (row: T) => string;
|
|
495
|
+
itemsPerPage?: number;
|
|
496
|
+
itemsPerPageOptions?: number[];
|
|
497
|
+
enableRowSelection?: boolean;
|
|
498
|
+
selectAllScope?: 'page' | 'all' | 'toggleable';
|
|
499
|
+
/**
|
|
500
|
+
* How to handle "select all matching" (wildcard) selections in api mode.
|
|
501
|
+
*
|
|
502
|
+
* - `'lazy'` (default): emit `{ scope: 'all', mode: 'wildcard', exceptIds }`.
|
|
503
|
+
* The host page is responsible for materializing the full id list when
|
|
504
|
+
* needed (typically at action time). Cheap; selection is independent of
|
|
505
|
+
* row count; column ordering remains free.
|
|
506
|
+
*
|
|
507
|
+
* - `'eager'`: as soon as the user enters wildcard, the table paginates
|
|
508
|
+
* `fetchData` with the active filter to materialize every matching id
|
|
509
|
+
* and emits `{ scope: 'all', mode: 'in-memory', ids: [...full] }` once
|
|
510
|
+
* resolved. While a wildcard selection is active, **column sorting is
|
|
511
|
+
* locked** (otherwise the captured order would silently desync from
|
|
512
|
+
* the rendered view). Best for flows that need the full id list up
|
|
513
|
+
* front (preview, reorder, in-memory transforms before submit).
|
|
514
|
+
*
|
|
515
|
+
* Has no effect when `paginationMode === 'local'` (the table already
|
|
516
|
+
* knows the full set in memory).
|
|
517
|
+
*/
|
|
518
|
+
selectAllResolution?: 'lazy' | 'eager';
|
|
519
|
+
onSelectionChange?: (event: SelectionChange<T>) => void;
|
|
520
|
+
isLoading?: boolean;
|
|
521
|
+
emptyMessage?: string;
|
|
522
|
+
emptyAction?: ReactNode;
|
|
523
|
+
onRowClick?: (row: T) => void;
|
|
524
|
+
/**
|
|
525
|
+
* Highlight rows independently of selection. Useful for master/detail UIs
|
|
526
|
+
* where the active row should stay marked. Returning `true` adds a `bg-muted/50`
|
|
527
|
+
* tint plus `data-highlighted="true"` on the row for custom styling.
|
|
528
|
+
*/
|
|
529
|
+
isRowHighlighted?: (row: T) => boolean;
|
|
530
|
+
toolbarLeft?: ReactNode;
|
|
531
|
+
toolbarRight?: ReactNode;
|
|
532
|
+
showColumnVisibility?: boolean;
|
|
533
|
+
/**
|
|
534
|
+
* Cap the table body's height so it scrolls vertically instead of expanding
|
|
535
|
+
* the page when there are many rows per page. Number → pixels; string →
|
|
536
|
+
* any CSS length (`'60vh'`, `'400px'`). The header stays sticky at the top
|
|
537
|
+
* of the scroll container while rows scroll underneath.
|
|
538
|
+
*
|
|
539
|
+
* Use together with horizontal scroll: the same container handles both, so
|
|
540
|
+
* the layout stays consistent (toolbar + clamped scrollable region +
|
|
541
|
+
* pagination footer). When unset, the table grows to its natural height
|
|
542
|
+
* and the page scrolls.
|
|
543
|
+
*/
|
|
544
|
+
maxBodyHeight?: number | string;
|
|
545
|
+
labels?: Partial<TableLabels>;
|
|
546
|
+
className?: string;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
declare function EasyVisionTable<T extends RowData>(props: EasyVisionTableProps<T>): react_jsx_runtime.JSX.Element;
|
|
550
|
+
|
|
551
|
+
type SliceKind = 'input' | 'selector' | 'multifilter' | 'table';
|
|
552
|
+
interface InputSliceData {
|
|
553
|
+
kind: 'input';
|
|
554
|
+
value: string;
|
|
555
|
+
}
|
|
556
|
+
interface SelectorSliceData {
|
|
557
|
+
kind: 'selector';
|
|
558
|
+
value: string | number | undefined;
|
|
559
|
+
}
|
|
560
|
+
interface MultifilterSliceData {
|
|
561
|
+
kind: 'multifilter';
|
|
562
|
+
activeFields: string[];
|
|
563
|
+
values: Record<string, unknown>;
|
|
564
|
+
lastConfirmedSnapshotJSON: string | null;
|
|
565
|
+
}
|
|
566
|
+
interface TableSelection {
|
|
567
|
+
ids: Record<string, true>;
|
|
568
|
+
scope: 'page' | 'all';
|
|
569
|
+
exceptIds?: Record<string, true>;
|
|
570
|
+
}
|
|
571
|
+
interface TableSliceData {
|
|
572
|
+
kind: 'table';
|
|
573
|
+
page: number;
|
|
574
|
+
itemsPerPage: number;
|
|
575
|
+
sort: {
|
|
576
|
+
column: string;
|
|
577
|
+
descending: boolean;
|
|
578
|
+
} | null;
|
|
579
|
+
selection: TableSelection;
|
|
580
|
+
}
|
|
581
|
+
type Slice = InputSliceData | SelectorSliceData | MultifilterSliceData | TableSliceData;
|
|
582
|
+
type SliceFor<K extends SliceKind> = Extract<Slice, {
|
|
583
|
+
kind: K;
|
|
584
|
+
}>;
|
|
585
|
+
|
|
586
|
+
interface RegistryState {
|
|
587
|
+
slices: Record<string, Slice>;
|
|
588
|
+
ensure: <K extends SliceKind>(kind: K, fullId: string, init: () => SliceFor<K>) => SliceFor<K>;
|
|
589
|
+
patch: <K extends SliceKind>(fullId: string, partial: Partial<SliceFor<K>>) => void;
|
|
590
|
+
drop: (fullId: string) => void;
|
|
591
|
+
reset: () => void;
|
|
592
|
+
}
|
|
593
|
+
declare const easyVisionRegistry: zustand_vanilla.StoreApi<RegistryState>;
|
|
594
|
+
declare const getSlice: <K extends SliceKind>(fullId: string) => SliceFor<K> | undefined;
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Wraps content in the standard EasyVision table cell span.
|
|
598
|
+
* Use inside `cell` when you need custom content but want consistent base styling.
|
|
599
|
+
*
|
|
600
|
+
* Pass `title` when the cell is used in a `truncate: true` column so hover
|
|
601
|
+
* still reveals the full text (the table only auto-sets `title` for data
|
|
602
|
+
* columns with a string accessor — for `type: 'ui'` columns or rich content
|
|
603
|
+
* you have to provide it explicitly).
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* cell: ({ row }) => defaultCell(<ScoringIndicator score={row.original.scoring} />)
|
|
607
|
+
* cell: ({ row }) => defaultCell(formatDateForRow(row.original.created))
|
|
608
|
+
* cell: (a) => defaultCell(a.title, a.title) // truncate-friendly
|
|
609
|
+
*/
|
|
610
|
+
declare const defaultCell: (content: ReactNode, title?: string) => ReactNode;
|
|
611
|
+
|
|
612
|
+
export { type ApiFetchParams, type ApiFetchResult, type BaseStatefulProps, type CreateLoopbackTableFetcherOptions, type CustomFieldDef, type DateRangeFieldDef, type DateRangeValue, EasyVisionCard, EasyVisionCardContent, EasyVisionCardDescription, EasyVisionCardFooter, EasyVisionCardHeader, EasyVisionCardTitle, type EasyVisionColumn, EasyVisionInput, type EasyVisionInputProps, EasyVisionMultifilter, type EasyVisionMultifilterProps, EasyVisionSelector, type EasyVisionSelectorProps, EasyVisionTable, type EasyVisionTableProps, type FieldDef, type LoopbackCountResponse, type LoopbackFilter, type LoopbackWhereValue, type MultiSelectFieldDef, type MultifilterConfig, type MultifilterFieldDef, type MultifilterHandle, type MultifilterLabels, type MultifilterQuery, type MultifilterSnapshot, type NumberRangeFieldDef, type NumberRangeValue, type SelectionChange, type SelectorFieldDef, type SelectorOption, type TableLabels, type TableMode, type TextFieldDef, createLoopbackTableFetcher, defaultCell, easyVisionRegistry, getSlice, matchLoopbackWhere };
|