@easyvision/easyvision-ui 1.6.2 → 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/dist/index.d.cts CHANGED
@@ -115,7 +115,20 @@ interface SelectorFieldDef<V extends string | number = string | number> extends
115
115
  }
116
116
  interface MultiSelectFieldDef<V extends string | number = string | number> extends MultifilterFieldBase {
117
117
  type: 'multiselect';
118
- options: SelectorOption<V>[] | (() => Promise<SelectorOption<V>[]>);
118
+ /**
119
+ * The selectable options — a static array, or an async loader called once on
120
+ * mount. Optional when `searchOptions` is provided; still used (when present)
121
+ * to resolve labels for already-selected values.
122
+ */
123
+ options?: SelectorOption<V>[] | (() => Promise<SelectorOption<V>[]>);
124
+ /**
125
+ * Per-keystroke async search. When set, the popover's search box queries this
126
+ * (debounced) instead of filtering the static `options` list in memory — use
127
+ * for option sets too large to load up front, or that live behind an API.
128
+ * Labels of options the user picks are remembered for the session so the
129
+ * selected badges stay readable after the search box is cleared.
130
+ */
131
+ searchOptions?: (term: string) => Promise<SelectorOption<V>[]>;
119
132
  }
120
133
  interface DateRangeFieldDef extends MultifilterFieldBase {
121
134
  type: 'dateRange';
package/dist/index.d.ts CHANGED
@@ -115,7 +115,20 @@ interface SelectorFieldDef<V extends string | number = string | number> extends
115
115
  }
116
116
  interface MultiSelectFieldDef<V extends string | number = string | number> extends MultifilterFieldBase {
117
117
  type: 'multiselect';
118
- options: SelectorOption<V>[] | (() => Promise<SelectorOption<V>[]>);
118
+ /**
119
+ * The selectable options — a static array, or an async loader called once on
120
+ * mount. Optional when `searchOptions` is provided; still used (when present)
121
+ * to resolve labels for already-selected values.
122
+ */
123
+ options?: SelectorOption<V>[] | (() => Promise<SelectorOption<V>[]>);
124
+ /**
125
+ * Per-keystroke async search. When set, the popover's search box queries this
126
+ * (debounced) instead of filtering the static `options` list in memory — use
127
+ * for option sets too large to load up front, or that live behind an API.
128
+ * Labels of options the user picks are remembered for the session so the
129
+ * selected badges stay readable after the search box is cleared.
130
+ */
131
+ searchOptions?: (term: string) => Promise<SelectorOption<V>[]>;
119
132
  }
120
133
  interface DateRangeFieldDef extends MultifilterFieldBase {
121
134
  type: 'dateRange';
package/dist/index.js CHANGED
@@ -656,6 +656,8 @@ function MultiSelectWidget({
656
656
  onRemove
657
657
  }) {
658
658
  const [search, setSearch] = useState("");
659
+ const searchFn = definition.searchOptions;
660
+ const hasSearchOptions = typeof searchFn === "function";
659
661
  const [resolved, setResolved] = useState(
660
662
  Array.isArray(definition.options) ? definition.options : null
661
663
  );
@@ -666,17 +668,46 @@ function MultiSelectWidget({
666
668
  setResolved(definition.options);
667
669
  }
668
670
  }, [definition.options, resolved]);
671
+ const [searchResults, setSearchResults] = useState([]);
672
+ useEffect(() => {
673
+ if (!searchFn) return;
674
+ if (search.trim() === "") {
675
+ setSearchResults([]);
676
+ return;
677
+ }
678
+ let cancelled = false;
679
+ const handle = setTimeout(() => {
680
+ void searchFn(search).then((r) => {
681
+ if (!cancelled) setSearchResults(r);
682
+ }).catch(() => {
683
+ if (!cancelled) setSearchResults([]);
684
+ });
685
+ }, 300);
686
+ return () => {
687
+ cancelled = true;
688
+ clearTimeout(handle);
689
+ };
690
+ }, [search, searchFn]);
669
691
  const selected = Array.isArray(value) ? value : [];
670
- const opts = resolved ?? [];
671
- const filtered = useMemo(
672
- () => opts.filter((o) => o.label.toLowerCase().includes(search.toLowerCase())),
673
- [opts, search]
674
- );
675
- const toggle = (v) => {
676
- onChange(selected.includes(v) ? selected.filter((x) => x !== v) : [...selected, v]);
692
+ const baseOpts = resolved ?? [];
693
+ const labelCache = useRef(/* @__PURE__ */ new Map());
694
+ useEffect(() => {
695
+ baseOpts.forEach((o) => labelCache.current.set(o.value, o.label));
696
+ }, [baseOpts]);
697
+ const listOpts = useMemo(() => {
698
+ if (hasSearchOptions) return searchResults;
699
+ return baseOpts.filter(
700
+ (o) => o.label.toLowerCase().includes(search.toLowerCase())
701
+ );
702
+ }, [hasSearchOptions, searchResults, baseOpts, search]);
703
+ const select = (opt) => {
704
+ labelCache.current.set(opt.value, opt.label);
705
+ onChange(
706
+ selected.includes(opt.value) ? selected.filter((x) => x !== opt.value) : [...selected, opt.value]
707
+ );
677
708
  };
678
709
  const removeOne = (v) => onChange(selected.filter((x) => x !== v));
679
- const labelOf = (v) => opts.find((o) => o.value === v)?.label ?? String(v);
710
+ const labelOf = (v) => labelCache.current.get(v) ?? baseOpts.find((o) => o.value === v)?.label ?? String(v);
680
711
  return /* @__PURE__ */ jsxs("div", { className: "ev-mf-chip is-wrap", children: [
681
712
  /* @__PURE__ */ jsxs("span", { className: "ev-mf-chip-label", children: [
682
713
  definition.label,
@@ -708,29 +739,21 @@ function MultiSelectWidget({
708
739
  }
709
740
  ),
710
741
  /* @__PURE__ */ jsxs("div", { className: "ev-mf-ms-list", children: [
711
- filtered.map((o) => /* @__PURE__ */ jsxs("label", { className: "ev-mf-ms-option", children: [
742
+ listOpts.map((o) => /* @__PURE__ */ jsxs("label", { className: "ev-mf-ms-option", children: [
712
743
  /* @__PURE__ */ jsx(
713
744
  Checkbox,
714
745
  {
715
746
  checked: selected.includes(o.value),
716
- onCheckedChange: () => toggle(o.value)
747
+ onCheckedChange: () => select(o)
717
748
  }
718
749
  ),
719
750
  o.label
720
751
  ] }, String(o.value))),
721
- filtered.length === 0 && /* @__PURE__ */ jsx("p", { className: "ev-mf-ms-empty", children: "Sin opciones" })
752
+ listOpts.length === 0 && /* @__PURE__ */ jsx("p", { className: "ev-mf-ms-empty", children: hasSearchOptions && search.trim() === "" ? "Escribe para buscar..." : "Sin opciones" })
722
753
  ] })
723
754
  ] })
724
755
  ] }),
725
- onRemove && /* @__PURE__ */ jsx(
726
- "button",
727
- {
728
- type: "button",
729
- onClick: onRemove,
730
- className: "ev-mf-chip-remove",
731
- children: /* @__PURE__ */ jsx(X, {})
732
- }
733
- )
756
+ onRemove && /* @__PURE__ */ jsx("button", { type: "button", onClick: onRemove, className: "ev-mf-chip-remove", children: /* @__PURE__ */ jsx(X, {}) })
734
757
  ] });
735
758
  }
736
759
  function Calendar({