@easyvision/easyvision-ui 1.6.2 → 1.7.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
@@ -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.
@@ -1204,17 +1204,25 @@
1204
1204
  outline: none;
1205
1205
  }
1206
1206
  .ev-mf-chip-select-trigger {
1207
- height: 1.75rem;
1208
- min-width: 7.5rem;
1207
+ height: auto;
1208
+ width: auto;
1209
+ min-width: 0;
1210
+ justify-content: flex-start;
1211
+ gap: 0.25rem;
1209
1212
  border: 0;
1210
1213
  background: transparent;
1211
- padding: 0 0.5rem;
1214
+ padding: 0;
1212
1215
  font-size: 0.75rem;
1213
1216
  line-height: 1rem;
1217
+ color: hsl(var(--muted-foreground, 215 16% 47%));
1214
1218
  }
1215
1219
  .ev-mf-chip-select-trigger:focus {
1216
1220
  outline: none;
1217
1221
  }
1222
+ .ev-mf-chip-select-trigger .ev-select-trigger-icon {
1223
+ width: 0.875rem;
1224
+ height: 0.875rem;
1225
+ }
1218
1226
  .ev-mf-chip-number {
1219
1227
  height: 1.75rem;
1220
1228
  width: 5rem;
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 opts = resolved ?? [];
696
- const filtered = React8.useMemo(
697
- () => opts.filter((o) => o.label.toLowerCase().includes(search.toLowerCase())),
698
- [opts, search]
699
- );
700
- const toggle = (v) => {
701
- onChange(selected.includes(v) ? selected.filter((x) => x !== v) : [...selected, v]);
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) => opts.find((o) => o.value === v)?.label ?? String(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
- filtered.map((o) => /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "ev-mf-ms-option", children: [
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: () => toggle(o.value)
772
+ onCheckedChange: () => select(o)
742
773
  }
743
774
  ),
744
775
  o.label
745
776
  ] }, String(o.value))),
746
- filtered.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "ev-mf-ms-empty", children: "Sin opciones" })
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({