@easyvision/easyvision-ui 1.8.0 → 1.9.1

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
@@ -43,6 +43,9 @@ import {
43
43
  - [Binding a multifilter](#binding-a-multifilter)
44
44
  - [External filter and manual refetch](#external-filter-and-manual-refetch)
45
45
  - [Toolbar slots](#toolbar-slots)
46
+ - [`EasyVisionExportButton`](#easyvisionexportbutton)
47
+ - [What gets exported](#what-gets-exported)
48
+ - [Resolving table ids](#resolving-table-ids)
46
49
  - [Migration cookbook](#migration-cookbook)
47
50
  - [Integration recipes](#integration-recipes)
48
51
  - [API adapters: LoopBack](#api-adapters-loopback)
@@ -649,13 +652,13 @@ interface MultifilterSnapshot {
649
652
  ```
650
653
 
651
654
  The default `query.where` builder uses these conventions per type:
652
- - `text` → `{ [field]: { $regex: `.*${value}.*`, $options: 'i' } }`
655
+ - `text` → `{ [field]: { $regex: `.*${value}.*`, $options: 'i' } }` (regex metacharacters in `value` are escaped, so the text matches literally)
653
656
  - `selector` → `{ [field]: value }`
654
657
  - `multiselect` → `{ [field]: { $in: value } }`
655
658
  - `dateRange` → `{ [field]: { $gte, $lte } }` (ISO strings)
656
659
  - `numberRange` → `{ [field]: { $gte, $lte } }`
657
660
 
658
- Override per field with `toCondition: (value) => unknown` (return either a primitive — wrapped in `{ [field]: ... }` — or a full clause containing `$or`/`$and`, which is merged at the top level of `where`). Useful for searching multiple paths with one input, or for translating UI values into a backend-specific shape.
661
+ To search several paths with one input, give a `text` field `fields` instead of `field`. It builds one `$or` with the same escaped, case-insensitive match on each path:
659
662
 
660
663
  ```ts
661
664
  // Search bar that matches client.name OR title OR topics:
@@ -664,19 +667,12 @@ Override per field with `toCondition: (value) => unknown` (return either a primi
664
667
  type: 'text',
665
668
  prominent: true,
666
669
  pinned: true,
667
- toCondition: (v) => {
668
- const s = String(v ?? '').trim();
669
- if (!s) return undefined;
670
- const like = { $regex: `.*${s}.*`, $options: 'i' };
671
- return { $or: [
672
- { 'client.name': like },
673
- { title: like },
674
- { relatedTopicsText: like },
675
- ]};
676
- },
670
+ fields: ['client.name', 'title', 'relatedTopicsText'],
677
671
  }
678
672
  ```
679
673
 
674
+ Override per field with `toCondition: (value) => unknown` (return either a primitive — wrapped in `{ [field]: ... }` — or a full clause containing `$or`/`$and`, which is merged at the top level of `where`). Useful for translating UI values into a backend-specific shape. A `toCondition` replaces the default builder entirely, so if it builds a `$regex` from user text it must escape that text itself.
675
+
680
676
  > `transform` is the deprecated old name for `toCondition` and is still accepted as an alias.
681
677
 
682
678
  ### Multifilter props
@@ -796,6 +792,14 @@ type DataColumn<T> = {
796
792
  truncate?: boolean;
797
793
  /** Allow the user to drag the right edge of the header to resize this column. */
798
794
  resizable?: boolean;
795
+ /** Header text in an exported sheet. Defaults to `header` when it's a plain string, else `field`. */
796
+ exportHeader?: string;
797
+ /** Cell value in an exported sheet. Defaults to the value at `field` (arrays joined by ", "). */
798
+ exportValue?: (item: T) => ExportCellValue;
799
+ /** Per-cell styling in an exported sheet. Return `undefined` to leave a cell unstyled. */
800
+ exportStyle?: (value: ExportCellValue, item: T) => ExportCellStyle | undefined;
801
+ /** Include this column in exports. Default: `true` for `data` columns, `false` for `ui` columns. */
802
+ exportable?: boolean;
799
803
  };
800
804
 
801
805
  // UI column — no underlying value, never sortable.
@@ -809,11 +813,34 @@ type UiColumn<T> = {
809
813
  width?: number | string;
810
814
  truncate?: boolean;
811
815
  resizable?: boolean;
816
+ /** See data-column docs. */
817
+ exportHeader?: string;
818
+ /** See data-column docs. A `ui` column has no underlying value, so this is the only way to give it one. */
819
+ exportValue?: (item: T) => ExportCellValue;
820
+ /** See data-column docs. */
821
+ exportStyle?: (value: ExportCellValue, item: T) => ExportCellStyle | undefined;
822
+ /** `ui` columns default to `false` here — opt in alongside `exportValue` to export a computed column. */
823
+ exportable?: boolean;
812
824
  };
813
825
 
814
826
  export type EasyVisionColumn<T> = DataColumn<T> | UiColumn<T>;
815
827
  ```
816
828
 
829
+ `exportHeader` / `exportValue` / `exportStyle` / `exportable` only affect [`EasyVisionExportButton`](#easyvisionexportbutton) — they have no effect on what's rendered on screen. A worked `exportStyle` example, colouring a score cell by band:
830
+
831
+ ```ts
832
+ {
833
+ field: 'score',
834
+ header: 'Score',
835
+ exportStyle: (value) =>
836
+ typeof value === 'number' && value >= 3.5
837
+ ? { fill: 'FF991B1B', fontColor: 'FFFFFFFF', bold: true } // dark red, white bold text
838
+ : typeof value === 'number' && value >= 2
839
+ ? { fill: 'FFF59E0B', fontColor: 'FF1F2937' } // amber
840
+ : undefined, // leave low scores unstyled
841
+ }
842
+ ```
843
+
817
844
  **`field` does double duty on data columns:** it's both the column ID and the dot-path used to resolve the value. Internally the library generates an `accessorFn` that reads `row.client?.name` for `field: 'client.name'`. UI columns don't get an accessor — `field` there is just an ID.
818
845
 
819
846
  **`cell` receives the row item directly** (no `{ row, getValue }` wrappers). For columns where you only want the resolved value with default styling, omit `cell` and the library renders it in a standard span. To get the same span styling around custom content, wrap with `defaultCell(content)`. `defaultCell` accepts an optional second argument that becomes the cell's native `title` tooltip — useful when `truncate: true` is set and you want the full text to appear on hover:
@@ -1216,6 +1243,61 @@ interface TableLabels {
1216
1243
 
1217
1244
  ---
1218
1245
 
1246
+ ## `EasyVisionExportButton`
1247
+
1248
+ Writes one or more registered tables into a single `.xlsx` file, one worksheet per table. It doesn't hold any data itself — every mounted `EasyVisionTable` registers an **export source** (a pair of resolvers: columns and rows) keyed by its `fullId`, and the button just looks those up by the ids you pass in `tables`.
1249
+
1250
+ ### Minimal usage
1251
+
1252
+ ```tsx
1253
+ <EasyVisionExportButton
1254
+ tables={['localTable', 'apiTable']}
1255
+ sheetNames={{ localTable: 'Local', apiTable: 'API' }}
1256
+ filename="risk-evaluations"
1257
+ />
1258
+ ```
1259
+
1260
+ Clicking it resolves `localTable` and `apiTable` against the tables mounted nearby, pulls each one's current rows and visible columns, and downloads `risk-evaluations_<ISO timestamp>.xlsx` with two sheets named `Local` and `API`. A table id with no `sheetNames` override falls back to the table's own `id` as the sheet name.
1261
+
1262
+ ### Props
1263
+
1264
+ | prop | type | default | notes |
1265
+ |---|---|---|---|
1266
+ | `tables` | `string[]` | — required | Table ids, in sheet order. See [Resolving table ids](#resolving-table-ids) below. |
1267
+ | `filename` | `string` | — required | Base name. An ISO timestamp and `.xlsx` are appended. |
1268
+ | `sheetNames` | `Record<string, string>` | — | Per-table sheet-name override, keyed by the same id passed in `tables`. Sheet names are sanitized (invalid Excel characters replaced with `-`, truncated to 31 chars) and de-duplicated automatically. |
1269
+ | `labels` | `Partial<ExportLabels>` | Spanish defaults | `{ export, exporting }` — button text for idle and in-flight states. |
1270
+ | `onError` | `(error: unknown) => void` | — | A fetch or workbook-building failure aborts the whole export — no partial file is written. Also fires when *some but not all* ids in `tables` fail to resolve, with an `Error` naming the unresolved ids — this catches a typo'd or unmounted table id before it can silently drop a sheet from an otherwise-successful export. |
1271
+ | `onEmpty` | `() => void` | — | Fires when nothing was written: **no** id in `tables` resolved to a mounted table (every id failed together, e.g. the button rendered before any table mounted), or every sheet that did resolve had zero visible columns or zero matching rows. A *partial* resolution failure — some ids resolved, some didn't — is reported via `onError` instead, not `onEmpty`, so it isn't mistaken for "nothing to export". The button does **not** disable itself when a table id fails to resolve or a table has nothing to export — it always attempts the export and reports the outcome via `onEmpty` / `onError`, since a source can legitimately empty out between renders (a hidden column, a narrowed multifilter, an unmounted table). |
1272
+ | `disabled` | `boolean` | `false` | External disable, e.g. while a parent form is invalid. |
1273
+ | `className` | `string` | — | |
1274
+ | `icon` | `ReactNode` | a download icon | Replaces the default idle-state icon. The spinner shown while exporting is not overridable. |
1275
+
1276
+ ### What gets exported
1277
+
1278
+ **Rows** are the ticked selection when there is one — page-scope ids, or an all-scope selection minus any `exceptIds` — and otherwise every row matching the table's current multifilter plus `externalFilter`. To assemble "every row" in API mode, the export first pages through `fetchData` under the hood to collect the complete matching set (the same helper `selectAllResolution="eager"` uses internally), then applies the selection filter to it — so an export is never limited to whatever page happens to be on screen, and behaves the same regardless of the table's `selectAllResolution` setting. Local mode already holds the filtered set in memory, so no extra fetching happens there.
1279
+
1280
+ **Columns** are the table's currently visible, exportable columns, in declared order. Concretely:
1281
+ - A column must pass `isVisible` — the same visibility state `ColumnVisibilityMenu` (the **Columnas** button in the table toolbar) toggles. Hide a column there and it's gone from the sheet; show it and it reappears. This makes `ColumnVisibilityMenu` double as export column customization — there is no separate export-column picker.
1282
+ - A column must be exportable: `data` columns are exportable by default, `ui` columns are not (a `ui` column has no underlying value — opt it in with `exportable: true` plus an `exportValue` to export something computed).
1283
+ - **`largeScreensOnly` columns always export**, even when the viewport is too narrow to render them. `largeScreensOnly` is a CSS-only responsive hint — it never enters the visibility state — so if it affected the export, the same click would produce a different file on a phone than on a wide monitor. Hide a column from exports on purpose with `exportable: false` instead.
1284
+
1285
+ Both resolvers run at export-click time, not at table-mount time, so a column toggle, a fresh multifilter query, or a changed selection made a second before clicking is always reflected — nothing needs to be re-registered.
1286
+
1287
+ ### Resolving table ids
1288
+
1289
+ The button must render **inside the same namespace as the tables it names**. An id in `tables` is qualified through the surrounding namespace first, the same way a nested multifilter field is (see [The `id` rule](#the-id-rule)): `'localTable'` becomes `localTable-table` when the button sits at the top level (no enclosing namespace), or `parentId.localTable-table` when it's nested under something with `id="parentId"`.
1290
+
1291
+ Rendering the button as a plain sibling of the tables — as in the demo — is the simple case: both the tables and the button see the same (usually empty) surrounding namespace, so local ids just work.
1292
+
1293
+ Rendering it **inside a table's own `toolbarLeft` / `toolbarRight`** (a natural spot per [Toolbar slots](#toolbar-slots)) is different: that slot renders inside *that table's* namespace, so a local id would be qualified as `<hostTableId>-table.<name>-table` — which never matches, even for the table hosting the button itself. In that placement, pass the target table's **fully-qualified id** instead (its own `id` with `-table` appended, e.g. `'orders-table'`).
1294
+
1295
+ Resolution is always **namespace-first**: the id is qualified through the surrounding namespace and looked up under that name first; only if that lookup misses is the raw id tried verbatim as a fallback. A fully-qualified id (one already ending in `-table`) doesn't *bypass* namespace resolution — the namespaced probe still runs first and would win if it happened to match — it just normally misses (a genuine local id doesn't already carry a `-table` suffix), so the fallback is what actually resolves it. This fallback is the escape hatch for exporting a table the button can't reach by local-id lookup, including the table it's nested inside.
1296
+
1297
+ If the target table is itself nested under another namespaced component, its fully-qualified id is the **full chain**, not just its own `id` with `-table` appended: a table declared with `id="orders"` inside something with `id="page"` registers as `page-table.orders-table`, so that's the string to pass — `'orders-table'` alone won't match it.
1298
+
1299
+ ---
1300
+
1219
1301
  ## Migration cookbook
1220
1302
 
1221
1303
  Use this when replacing an existing filter panel or table with EasyVision components. The mappings below cover the most common shapes — TanStack-based and prop-driven implementations — but the pattern generalizes.
@@ -392,3 +392,10 @@
392
392
  .ev-cv-item {
393
393
  text-transform: capitalize;
394
394
  }
395
+
396
+ /* ---------- Export button ---------- */
397
+ .ev-export-icon {
398
+ margin-right: 0.5rem;
399
+ height: 1rem;
400
+ width: 1rem;
401
+ }