@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/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
|
-
|
|
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';
|
|
@@ -380,8 +393,9 @@ type EasyVisionColumn<T> = {
|
|
|
380
393
|
truncate?: boolean;
|
|
381
394
|
/**
|
|
382
395
|
* Allow the user to drag the column's right edge to resize it. The
|
|
383
|
-
* starting width is `width` (or 240px if unset). User-resized widths
|
|
384
|
-
*
|
|
396
|
+
* starting width is `width` (or 240px if unset). User-resized widths
|
|
397
|
+
* live in the table slice alongside page / sort / visibility, so they
|
|
398
|
+
* survive unmount when the table is mounted with `persist`.
|
|
385
399
|
*/
|
|
386
400
|
resizable?: boolean;
|
|
387
401
|
} | {
|
|
@@ -618,6 +632,8 @@ interface TableSliceData {
|
|
|
618
632
|
descending: boolean;
|
|
619
633
|
} | null;
|
|
620
634
|
selection: TableSelection;
|
|
635
|
+
columnVisibility: Record<string, boolean>;
|
|
636
|
+
columnSizing: Record<string, number>;
|
|
621
637
|
}
|
|
622
638
|
type Slice = InputSliceData | SelectorSliceData | MultifilterSliceData | TableSliceData;
|
|
623
639
|
type SliceFor<K extends SliceKind> = Extract<Slice, {
|
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
|
-
|
|
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';
|
|
@@ -380,8 +393,9 @@ type EasyVisionColumn<T> = {
|
|
|
380
393
|
truncate?: boolean;
|
|
381
394
|
/**
|
|
382
395
|
* Allow the user to drag the column's right edge to resize it. The
|
|
383
|
-
* starting width is `width` (or 240px if unset). User-resized widths
|
|
384
|
-
*
|
|
396
|
+
* starting width is `width` (or 240px if unset). User-resized widths
|
|
397
|
+
* live in the table slice alongside page / sort / visibility, so they
|
|
398
|
+
* survive unmount when the table is mounted with `persist`.
|
|
385
399
|
*/
|
|
386
400
|
resizable?: boolean;
|
|
387
401
|
} | {
|
|
@@ -618,6 +632,8 @@ interface TableSliceData {
|
|
|
618
632
|
descending: boolean;
|
|
619
633
|
} | null;
|
|
620
634
|
selection: TableSelection;
|
|
635
|
+
columnVisibility: Record<string, boolean>;
|
|
636
|
+
columnSizing: Record<string, number>;
|
|
621
637
|
}
|
|
622
638
|
type Slice = InputSliceData | SelectorSliceData | MultifilterSliceData | TableSliceData;
|
|
623
639
|
type SliceFor<K extends SliceKind> = Extract<Slice, {
|
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
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
);
|
|
675
|
-
const
|
|
676
|
-
|
|
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) =>
|
|
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
|
-
|
|
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: () =>
|
|
747
|
+
onCheckedChange: () => select(o)
|
|
717
748
|
}
|
|
718
749
|
),
|
|
719
750
|
o.label
|
|
720
751
|
] }, String(o.value))),
|
|
721
|
-
|
|
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({
|
|
@@ -2182,7 +2205,11 @@ function EasyVisionTable(props) {
|
|
|
2182
2205
|
selection: {
|
|
2183
2206
|
ids: {},
|
|
2184
2207
|
scope: selectAllScope === "all" ? "all" : "page"
|
|
2185
|
-
}
|
|
2208
|
+
},
|
|
2209
|
+
// Visibility starts empty: defaults from `initiallyHidden` are merged in
|
|
2210
|
+
// at read time, so columns added later still honor their declared default.
|
|
2211
|
+
columnVisibility: {},
|
|
2212
|
+
columnSizing: {}
|
|
2186
2213
|
}),
|
|
2187
2214
|
persist
|
|
2188
2215
|
});
|
|
@@ -2340,13 +2367,23 @@ function EasyVisionTable(props) {
|
|
|
2340
2367
|
};
|
|
2341
2368
|
return [checkboxCol, ...tanstackColumns];
|
|
2342
2369
|
}, [enableRowSelection, tanstackColumns]);
|
|
2343
|
-
const
|
|
2370
|
+
const visibilityDefaults = useMemo(() => {
|
|
2344
2371
|
const v = {};
|
|
2345
2372
|
for (const c of columns) {
|
|
2346
2373
|
if (c.initiallyHidden) v[c.field] = false;
|
|
2347
2374
|
}
|
|
2348
2375
|
return v;
|
|
2349
|
-
});
|
|
2376
|
+
}, [columns]);
|
|
2377
|
+
const columnVisibility = useMemo(
|
|
2378
|
+
() => ({ ...visibilityDefaults, ...slice.columnVisibility }),
|
|
2379
|
+
[visibilityDefaults, slice.columnVisibility]
|
|
2380
|
+
);
|
|
2381
|
+
const resizableFields = useMemo(() => {
|
|
2382
|
+
const s = /* @__PURE__ */ new Set();
|
|
2383
|
+
for (const c of columns) if (c.resizable) s.add(c.field);
|
|
2384
|
+
return s;
|
|
2385
|
+
}, [columns]);
|
|
2386
|
+
const columnSizing = slice.columnSizing;
|
|
2350
2387
|
const rowSelection = useMemo(() => {
|
|
2351
2388
|
if (selection.scope === "all") return {};
|
|
2352
2389
|
const r = {};
|
|
@@ -2360,10 +2397,22 @@ function EasyVisionTable(props) {
|
|
|
2360
2397
|
columns: allColumns,
|
|
2361
2398
|
state: {
|
|
2362
2399
|
columnVisibility,
|
|
2400
|
+
columnSizing,
|
|
2363
2401
|
...enableRowSelection ? { rowSelection } : {},
|
|
2364
2402
|
sorting: sortingState
|
|
2365
2403
|
},
|
|
2366
|
-
onColumnVisibilityChange:
|
|
2404
|
+
onColumnVisibilityChange: (updater) => {
|
|
2405
|
+
const next = typeof updater === "function" ? updater(columnVisibility) : updater;
|
|
2406
|
+
patch({ columnVisibility: next });
|
|
2407
|
+
},
|
|
2408
|
+
onColumnSizingChange: (updater) => {
|
|
2409
|
+
const next = typeof updater === "function" ? updater(columnSizing) : updater;
|
|
2410
|
+
const filtered = {};
|
|
2411
|
+
for (const k in next) {
|
|
2412
|
+
if (resizableFields.has(k)) filtered[k] = next[k];
|
|
2413
|
+
}
|
|
2414
|
+
patch({ columnSizing: filtered });
|
|
2415
|
+
},
|
|
2367
2416
|
enableRowSelection,
|
|
2368
2417
|
onRowSelectionChange: enableRowSelection ? (updater) => {
|
|
2369
2418
|
const next = typeof updater === "function" ? updater(rowSelection) : updater;
|