@easyvision/easyvision-ui 1.6.1 → 1.7.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 +50 -0
- package/dist/index.cjs +73 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +73 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -353,6 +353,56 @@ Common base fields on every field def:
|
|
|
353
353
|
}
|
|
354
354
|
```
|
|
355
355
|
|
|
356
|
+
### Multiselect options: static, async, and live search
|
|
357
|
+
|
|
358
|
+
A `'multiselect'` field draws its choices from `options` — either a static array or an async
|
|
359
|
+
loader run **once on mount**:
|
|
360
|
+
|
|
361
|
+
```tsx
|
|
362
|
+
// static
|
|
363
|
+
{ id: 'level', type: 'multiselect', field: 'level', label: 'Nivel',
|
|
364
|
+
options: [{ value: 'CRITICAL', label: 'Crítico' }, { value: 'HIGH', label: 'Alto' }] }
|
|
365
|
+
|
|
366
|
+
// async — fetched once when the field mounts
|
|
367
|
+
{ id: 'sector', type: 'multiselect', field: 'sectorId', label: 'Sector',
|
|
368
|
+
options: async () => (await api.getSectors()).map(s => ({ value: s.id, label: s.name })) }
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
For option sets too large to load up front — or that only exist behind a search API — a
|
|
372
|
+
`'multiselect'` field can instead (or also) provide **`searchOptions`**: a per-keystroke async
|
|
373
|
+
search wired to the popover's search box.
|
|
374
|
+
|
|
375
|
+
```tsx
|
|
376
|
+
{
|
|
377
|
+
id: 'sector',
|
|
378
|
+
type: 'multiselect',
|
|
379
|
+
field: 'sectorId',
|
|
380
|
+
label: 'Sector / CNAE',
|
|
381
|
+
// Called on every keystroke (debounced 300ms, matching EasyVisionInput).
|
|
382
|
+
// The popover lists whatever this resolves to.
|
|
383
|
+
searchOptions: async (term) => {
|
|
384
|
+
const rows = await api.searchSectors(term);
|
|
385
|
+
return rows.map((s) => ({ value: s.id, label: `${s.cnae} — ${s.name}` }));
|
|
386
|
+
},
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
| | `options` | `searchOptions` |
|
|
391
|
+
|---|---|---|
|
|
392
|
+
| When it runs | once on mount | on every keystroke (debounced 300ms) |
|
|
393
|
+
| Popover search box | filters the loaded list in memory | drives the query; results come from your fn |
|
|
394
|
+
| Good for | small / bounded option sets | large sets, or options that live behind an API |
|
|
395
|
+
|
|
396
|
+
Notes:
|
|
397
|
+
- `options` is **optional** when `searchOptions` is set. You may supply both: `searchOptions`
|
|
398
|
+
powers the search box, while `options` (when present) still resolves labels for
|
|
399
|
+
already-selected values.
|
|
400
|
+
- With `searchOptions` only, the widget caches the labels of options the user picks for the
|
|
401
|
+
session, so the selected badges stay readable after the search box is cleared. A value
|
|
402
|
+
persisted from a previous session but never re-searched falls back to showing its raw value
|
|
403
|
+
until it appears in a search result again.
|
|
404
|
+
- Stale in-flight responses are discarded — only the latest query's results are shown.
|
|
405
|
+
|
|
356
406
|
### Pinned, chip, locked
|
|
357
407
|
|
|
358
408
|
- **`pinned: true`** — always rendered in the pinned row, never has an X chip, never appears in the "+" popover.
|
package/dist/index.cjs
CHANGED
|
@@ -681,6 +681,8 @@ function MultiSelectWidget({
|
|
|
681
681
|
onRemove
|
|
682
682
|
}) {
|
|
683
683
|
const [search, setSearch] = React8.useState("");
|
|
684
|
+
const searchFn = definition.searchOptions;
|
|
685
|
+
const hasSearchOptions = typeof searchFn === "function";
|
|
684
686
|
const [resolved, setResolved] = React8.useState(
|
|
685
687
|
Array.isArray(definition.options) ? definition.options : null
|
|
686
688
|
);
|
|
@@ -691,17 +693,46 @@ function MultiSelectWidget({
|
|
|
691
693
|
setResolved(definition.options);
|
|
692
694
|
}
|
|
693
695
|
}, [definition.options, resolved]);
|
|
696
|
+
const [searchResults, setSearchResults] = React8.useState([]);
|
|
697
|
+
React8.useEffect(() => {
|
|
698
|
+
if (!searchFn) return;
|
|
699
|
+
if (search.trim() === "") {
|
|
700
|
+
setSearchResults([]);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
let cancelled = false;
|
|
704
|
+
const handle = setTimeout(() => {
|
|
705
|
+
void searchFn(search).then((r) => {
|
|
706
|
+
if (!cancelled) setSearchResults(r);
|
|
707
|
+
}).catch(() => {
|
|
708
|
+
if (!cancelled) setSearchResults([]);
|
|
709
|
+
});
|
|
710
|
+
}, 300);
|
|
711
|
+
return () => {
|
|
712
|
+
cancelled = true;
|
|
713
|
+
clearTimeout(handle);
|
|
714
|
+
};
|
|
715
|
+
}, [search, searchFn]);
|
|
694
716
|
const selected = Array.isArray(value) ? value : [];
|
|
695
|
-
const
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
);
|
|
700
|
-
const
|
|
701
|
-
|
|
717
|
+
const baseOpts = resolved ?? [];
|
|
718
|
+
const labelCache = React8.useRef(/* @__PURE__ */ new Map());
|
|
719
|
+
React8.useEffect(() => {
|
|
720
|
+
baseOpts.forEach((o) => labelCache.current.set(o.value, o.label));
|
|
721
|
+
}, [baseOpts]);
|
|
722
|
+
const listOpts = React8.useMemo(() => {
|
|
723
|
+
if (hasSearchOptions) return searchResults;
|
|
724
|
+
return baseOpts.filter(
|
|
725
|
+
(o) => o.label.toLowerCase().includes(search.toLowerCase())
|
|
726
|
+
);
|
|
727
|
+
}, [hasSearchOptions, searchResults, baseOpts, search]);
|
|
728
|
+
const select = (opt) => {
|
|
729
|
+
labelCache.current.set(opt.value, opt.label);
|
|
730
|
+
onChange(
|
|
731
|
+
selected.includes(opt.value) ? selected.filter((x) => x !== opt.value) : [...selected, opt.value]
|
|
732
|
+
);
|
|
702
733
|
};
|
|
703
734
|
const removeOne = (v) => onChange(selected.filter((x) => x !== v));
|
|
704
|
-
const labelOf = (v) =>
|
|
735
|
+
const labelOf = (v) => labelCache.current.get(v) ?? baseOpts.find((o) => o.value === v)?.label ?? String(v);
|
|
705
736
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ev-mf-chip is-wrap", children: [
|
|
706
737
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ev-mf-chip-label", children: [
|
|
707
738
|
definition.label,
|
|
@@ -733,29 +764,21 @@ function MultiSelectWidget({
|
|
|
733
764
|
}
|
|
734
765
|
),
|
|
735
766
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ev-mf-ms-list", children: [
|
|
736
|
-
|
|
767
|
+
listOpts.map((o) => /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "ev-mf-ms-option", children: [
|
|
737
768
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
738
769
|
Checkbox,
|
|
739
770
|
{
|
|
740
771
|
checked: selected.includes(o.value),
|
|
741
|
-
onCheckedChange: () =>
|
|
772
|
+
onCheckedChange: () => select(o)
|
|
742
773
|
}
|
|
743
774
|
),
|
|
744
775
|
o.label
|
|
745
776
|
] }, String(o.value))),
|
|
746
|
-
|
|
777
|
+
listOpts.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "ev-mf-ms-empty", children: hasSearchOptions && search.trim() === "" ? "Escribe para buscar..." : "Sin opciones" })
|
|
747
778
|
] })
|
|
748
779
|
] })
|
|
749
780
|
] }),
|
|
750
|
-
onRemove && /* @__PURE__ */ jsxRuntime.jsx(
|
|
751
|
-
"button",
|
|
752
|
-
{
|
|
753
|
-
type: "button",
|
|
754
|
-
onClick: onRemove,
|
|
755
|
-
className: "ev-mf-chip-remove",
|
|
756
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, {})
|
|
757
|
-
}
|
|
758
|
-
)
|
|
781
|
+
onRemove && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onRemove, className: "ev-mf-chip-remove", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, {}) })
|
|
759
782
|
] });
|
|
760
783
|
}
|
|
761
784
|
function Calendar({
|
|
@@ -2207,7 +2230,11 @@ function EasyVisionTable(props) {
|
|
|
2207
2230
|
selection: {
|
|
2208
2231
|
ids: {},
|
|
2209
2232
|
scope: selectAllScope === "all" ? "all" : "page"
|
|
2210
|
-
}
|
|
2233
|
+
},
|
|
2234
|
+
// Visibility starts empty: defaults from `initiallyHidden` are merged in
|
|
2235
|
+
// at read time, so columns added later still honor their declared default.
|
|
2236
|
+
columnVisibility: {},
|
|
2237
|
+
columnSizing: {}
|
|
2211
2238
|
}),
|
|
2212
2239
|
persist
|
|
2213
2240
|
});
|
|
@@ -2365,13 +2392,23 @@ function EasyVisionTable(props) {
|
|
|
2365
2392
|
};
|
|
2366
2393
|
return [checkboxCol, ...tanstackColumns];
|
|
2367
2394
|
}, [enableRowSelection, tanstackColumns]);
|
|
2368
|
-
const
|
|
2395
|
+
const visibilityDefaults = React8.useMemo(() => {
|
|
2369
2396
|
const v = {};
|
|
2370
2397
|
for (const c of columns) {
|
|
2371
2398
|
if (c.initiallyHidden) v[c.field] = false;
|
|
2372
2399
|
}
|
|
2373
2400
|
return v;
|
|
2374
|
-
});
|
|
2401
|
+
}, [columns]);
|
|
2402
|
+
const columnVisibility = React8.useMemo(
|
|
2403
|
+
() => ({ ...visibilityDefaults, ...slice.columnVisibility }),
|
|
2404
|
+
[visibilityDefaults, slice.columnVisibility]
|
|
2405
|
+
);
|
|
2406
|
+
const resizableFields = React8.useMemo(() => {
|
|
2407
|
+
const s = /* @__PURE__ */ new Set();
|
|
2408
|
+
for (const c of columns) if (c.resizable) s.add(c.field);
|
|
2409
|
+
return s;
|
|
2410
|
+
}, [columns]);
|
|
2411
|
+
const columnSizing = slice.columnSizing;
|
|
2375
2412
|
const rowSelection = React8.useMemo(() => {
|
|
2376
2413
|
if (selection.scope === "all") return {};
|
|
2377
2414
|
const r = {};
|
|
@@ -2385,10 +2422,22 @@ function EasyVisionTable(props) {
|
|
|
2385
2422
|
columns: allColumns,
|
|
2386
2423
|
state: {
|
|
2387
2424
|
columnVisibility,
|
|
2425
|
+
columnSizing,
|
|
2388
2426
|
...enableRowSelection ? { rowSelection } : {},
|
|
2389
2427
|
sorting: sortingState
|
|
2390
2428
|
},
|
|
2391
|
-
onColumnVisibilityChange:
|
|
2429
|
+
onColumnVisibilityChange: (updater) => {
|
|
2430
|
+
const next = typeof updater === "function" ? updater(columnVisibility) : updater;
|
|
2431
|
+
patch({ columnVisibility: next });
|
|
2432
|
+
},
|
|
2433
|
+
onColumnSizingChange: (updater) => {
|
|
2434
|
+
const next = typeof updater === "function" ? updater(columnSizing) : updater;
|
|
2435
|
+
const filtered = {};
|
|
2436
|
+
for (const k in next) {
|
|
2437
|
+
if (resizableFields.has(k)) filtered[k] = next[k];
|
|
2438
|
+
}
|
|
2439
|
+
patch({ columnSizing: filtered });
|
|
2440
|
+
},
|
|
2392
2441
|
enableRowSelection,
|
|
2393
2442
|
onRowSelectionChange: enableRowSelection ? (updater) => {
|
|
2394
2443
|
const next = typeof updater === "function" ? updater(rowSelection) : updater;
|