@wordrhyme/auto-crud 1.1.3 → 1.1.5
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.cjs +111 -26
- package/dist/index.d.cts +20 -18
- package/dist/index.d.ts +20 -18
- package/dist/index.js +111 -26
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1065,6 +1065,7 @@ function FacetedItem(props) {
|
|
|
1065
1065
|
else if (context.onItemSelect) context.onItemSelect(currentValue);
|
|
1066
1066
|
}, [onSelect, context]);
|
|
1067
1067
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.CommandItem, {
|
|
1068
|
+
value,
|
|
1068
1069
|
"aria-selected": isSelected,
|
|
1069
1070
|
"data-selected": isSelected,
|
|
1070
1071
|
className: cn("gap-2", className),
|
|
@@ -1943,6 +1944,13 @@ const DEBOUNCE_MS$1 = 300;
|
|
|
1943
1944
|
const THROTTLE_MS$1 = 50;
|
|
1944
1945
|
const FILTER_SHORTCUT_KEY = "f";
|
|
1945
1946
|
const REMOVE_FILTER_SHORTCUTS = ["backspace", "delete"];
|
|
1947
|
+
function getOptionCommandValue$2(option) {
|
|
1948
|
+
return [
|
|
1949
|
+
option.value,
|
|
1950
|
+
option.label,
|
|
1951
|
+
option.searchText
|
|
1952
|
+
].filter(Boolean).join(" ");
|
|
1953
|
+
}
|
|
1946
1954
|
function DataTableFilterMenu({ table, debounceMs = DEBOUNCE_MS$1, throttleMs = THROTTLE_MS$1, shallow = true, disabled,...props }) {
|
|
1947
1955
|
const id = react.useId();
|
|
1948
1956
|
const columns = react.useMemo(() => {
|
|
@@ -2221,7 +2229,7 @@ function FilterValueSelector({ column, value, onSelect }) {
|
|
|
2221
2229
|
})] });
|
|
2222
2230
|
case "select":
|
|
2223
2231
|
case "multiSelect": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.CommandGroup, { children: column.columnDef.meta?.options?.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.CommandItem, {
|
|
2224
|
-
value: option
|
|
2232
|
+
value: getOptionCommandValue$2(option),
|
|
2225
2233
|
onSelect: () => onSelect(option.value),
|
|
2226
2234
|
children: [
|
|
2227
2235
|
option.icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(option.icon, {}),
|
|
@@ -2348,7 +2356,7 @@ function onFilterInputRender({ filter, column, inputId, onFilterUpdate, showValu
|
|
|
2348
2356
|
align: "start",
|
|
2349
2357
|
className: "w-48 p-0",
|
|
2350
2358
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Command, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.CommandInput, { placeholder: "Search options..." }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.CommandList, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.CommandEmpty, { children: "No options found." }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.CommandGroup, { children: options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.CommandItem, {
|
|
2351
|
-
value: option
|
|
2359
|
+
value: getOptionCommandValue$2(option),
|
|
2352
2360
|
onSelect: () => {
|
|
2353
2361
|
const value = filter.variant === "multiSelect" ? selectedValues.includes(option.value) ? selectedValues.filter((v) => v !== option.value) : [...selectedValues, option.value] : option.value;
|
|
2354
2362
|
onFilterUpdate(filter.filterId, { value });
|
|
@@ -2774,32 +2782,65 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2774
2782
|
const [expanded, setExpanded] = react.useState(false);
|
|
2775
2783
|
const [visibleCount, setVisibleCount] = react.useState(null);
|
|
2776
2784
|
const containerRef = react.useRef(null);
|
|
2785
|
+
const hasLeading = leading != null;
|
|
2786
|
+
const filterMeasureKey = react.useMemo(() => filters.map((filter) => [
|
|
2787
|
+
filter.id,
|
|
2788
|
+
filter.operator,
|
|
2789
|
+
Array.isArray(filter.value) ? filter.value.join(",") : String(filter.value ?? "")
|
|
2790
|
+
].join(":")).join("|"), [filters]);
|
|
2777
2791
|
const calcVisibleCount = react.useCallback(() => {
|
|
2778
2792
|
const el = containerRef.current;
|
|
2779
2793
|
if (!el) return;
|
|
2780
|
-
const items = el.querySelectorAll("[data-filter-item]");
|
|
2781
|
-
if (items.length === 0)
|
|
2794
|
+
const items = Array.from(el.querySelectorAll("[data-filter-item]"));
|
|
2795
|
+
if (items.length === 0) {
|
|
2796
|
+
setVisibleCount(null);
|
|
2797
|
+
return;
|
|
2798
|
+
}
|
|
2782
2799
|
const restoreList = [];
|
|
2783
|
-
el.querySelectorAll(".hidden").forEach((node) => {
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
restoreList.push(htmlNode);
|
|
2800
|
+
el.querySelectorAll("[data-filter-item].hidden, [data-filter-toggle].hidden").forEach((node) => {
|
|
2801
|
+
node.classList.remove("hidden");
|
|
2802
|
+
restoreList.push(node);
|
|
2787
2803
|
});
|
|
2788
|
-
el.
|
|
2789
|
-
el.
|
|
2790
|
-
const
|
|
2804
|
+
const availableWidth = el.getBoundingClientRect().width;
|
|
2805
|
+
const previousFlex = el.style.flex;
|
|
2806
|
+
const previousWidth = el.style.width;
|
|
2807
|
+
el.style.flex = `0 0 ${availableWidth}px`;
|
|
2808
|
+
el.style.width = `${availableWidth}px`;
|
|
2809
|
+
el.getBoundingClientRect();
|
|
2810
|
+
const computedStyle = window.getComputedStyle(el);
|
|
2811
|
+
const gap = Number.parseFloat(computedStyle.columnGap) || Number.parseFloat(computedStyle.gap) || 0;
|
|
2812
|
+
const leadingEl = el.querySelector("[data-filter-leading]");
|
|
2813
|
+
const toggle = el.querySelector("[data-filter-toggle]");
|
|
2814
|
+
const reset = el.querySelector("[data-filter-reset]");
|
|
2815
|
+
const addWidth = (current, next) => {
|
|
2816
|
+
if (next <= 0) return current;
|
|
2817
|
+
if (current === 0) return next;
|
|
2818
|
+
return current + gap + next;
|
|
2819
|
+
};
|
|
2820
|
+
const leadingWidth = leadingEl?.offsetWidth ?? 0;
|
|
2821
|
+
const itemWidths = items.map((item) => item.offsetWidth);
|
|
2822
|
+
const toggleWidth = toggle?.offsetWidth ?? 0;
|
|
2823
|
+
const resetWidth = reset?.offsetWidth ?? 0;
|
|
2824
|
+
if (itemWidths.reduce((width, itemWidth) => addWidth(width, itemWidth), addWidth(leadingWidth, resetWidth)) <= availableWidth) {
|
|
2825
|
+
el.style.flex = previousFlex;
|
|
2826
|
+
el.style.width = previousWidth;
|
|
2827
|
+
restoreList.forEach((node) => node.classList.add("hidden"));
|
|
2828
|
+
setVisibleCount(null);
|
|
2829
|
+
return;
|
|
2830
|
+
}
|
|
2831
|
+
const trailingWidth = addWidth(addWidth(0, toggleWidth), resetWidth);
|
|
2832
|
+
let usedWidth = leadingWidth;
|
|
2791
2833
|
let count = 0;
|
|
2792
|
-
for (const
|
|
2793
|
-
|
|
2834
|
+
for (const itemWidth of itemWidths) {
|
|
2835
|
+
const nextWidth = addWidth(usedWidth, itemWidth);
|
|
2836
|
+
if (addWidth(nextWidth, trailingWidth) > availableWidth) break;
|
|
2837
|
+
usedWidth = nextWidth;
|
|
2794
2838
|
count++;
|
|
2795
2839
|
}
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
if (btn.offsetTop > firstTop) count--;
|
|
2799
|
-
}
|
|
2800
|
-
el.style.flex = "";
|
|
2840
|
+
el.style.flex = previousFlex;
|
|
2841
|
+
el.style.width = previousWidth;
|
|
2801
2842
|
restoreList.forEach((node) => node.classList.add("hidden"));
|
|
2802
|
-
setVisibleCount(count
|
|
2843
|
+
setVisibleCount(count);
|
|
2803
2844
|
}, []);
|
|
2804
2845
|
react.useLayoutEffect(() => {
|
|
2805
2846
|
if (!mounted) return;
|
|
@@ -2807,6 +2848,9 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2807
2848
|
}, [
|
|
2808
2849
|
mounted,
|
|
2809
2850
|
filterColumns.length,
|
|
2851
|
+
hasLeading,
|
|
2852
|
+
hasFilters,
|
|
2853
|
+
filterMeasureKey,
|
|
2810
2854
|
calcVisibleCount
|
|
2811
2855
|
]);
|
|
2812
2856
|
react.useEffect(() => {
|
|
@@ -2829,6 +2873,7 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2829
2873
|
}, [
|
|
2830
2874
|
mounted,
|
|
2831
2875
|
filterColumns.length,
|
|
2876
|
+
hasLeading,
|
|
2832
2877
|
calcVisibleCount
|
|
2833
2878
|
]);
|
|
2834
2879
|
if (!mounted) return null;
|
|
@@ -2836,7 +2881,11 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2836
2881
|
ref: containerRef,
|
|
2837
2882
|
className: "flex flex-1 flex-wrap items-center gap-2 min-w-0",
|
|
2838
2883
|
children: [
|
|
2839
|
-
leading,
|
|
2884
|
+
leading != null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2885
|
+
className: "shrink-0",
|
|
2886
|
+
"data-filter-leading": true,
|
|
2887
|
+
children: leading
|
|
2888
|
+
}) : null,
|
|
2840
2889
|
filterColumns.map((column, index) => {
|
|
2841
2890
|
const meta = column.columnDef.meta;
|
|
2842
2891
|
const value = getFilterValue(column.id);
|
|
@@ -2900,6 +2949,7 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2900
2949
|
children: expanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronUp, { className: "size-4" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "size-4" })
|
|
2901
2950
|
}),
|
|
2902
2951
|
hasFilters && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Button, {
|
|
2952
|
+
"data-filter-reset": true,
|
|
2903
2953
|
variant: "outline",
|
|
2904
2954
|
size: "sm",
|
|
2905
2955
|
className: "h-8 border-dashed shrink-0",
|
|
@@ -2909,6 +2959,13 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2909
2959
|
]
|
|
2910
2960
|
});
|
|
2911
2961
|
}
|
|
2962
|
+
function getOptionCommandValue$1(option) {
|
|
2963
|
+
return [
|
|
2964
|
+
option.value,
|
|
2965
|
+
option.label,
|
|
2966
|
+
option.searchText
|
|
2967
|
+
].filter(Boolean).join(" ");
|
|
2968
|
+
}
|
|
2912
2969
|
function SimpleFacetedFilter({ title, options, multiple, value, onChange }) {
|
|
2913
2970
|
const [open, setOpen] = react.useState(false);
|
|
2914
2971
|
const selectedValues = react.useMemo(() => new Set(value), [value]);
|
|
@@ -2988,6 +3045,7 @@ function SimpleFacetedFilter({ title, options, multiple, value, onChange }) {
|
|
|
2988
3045
|
children: options.map((option) => {
|
|
2989
3046
|
const isSelected = selectedValues.has(option.value);
|
|
2990
3047
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.CommandItem, {
|
|
3048
|
+
value: getOptionCommandValue$1(option),
|
|
2991
3049
|
onSelect: () => onItemSelect(option, isSelected),
|
|
2992
3050
|
children: [
|
|
2993
3051
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -4814,7 +4872,7 @@ function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection
|
|
|
4814
4872
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4815
4873
|
className: "flex w-full items-start justify-between gap-2 p-1",
|
|
4816
4874
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4817
|
-
className: "flex flex-1 items-start gap-2
|
|
4875
|
+
className: "flex min-h-[40px] min-w-0 flex-1 items-start gap-2",
|
|
4818
4876
|
"data-filter-parent": true,
|
|
4819
4877
|
children: [
|
|
4820
4878
|
currentMode !== "simple" && searchInput,
|
|
@@ -5012,7 +5070,7 @@ function createEditFormSchema(schema, options) {
|
|
|
5012
5070
|
|
|
5013
5071
|
//#endregion
|
|
5014
5072
|
//#region src/components/auto-crud/auto-form.tsx
|
|
5015
|
-
const COMBOBOX_LIST_CLASS = "[&_[cmdk-list]]:max-h-[360px]";
|
|
5073
|
+
const COMBOBOX_LIST_CLASS = "[&_[cmdk-list]]:max-h-[360px] [&_[cmdk-list]]:overflow-x-hidden [&_[cmdk-list]]:overflow-y-auto";
|
|
5016
5074
|
const FormilySwitch = (0, __formily_react.connect)(__pixpilot_shadcn.Switch, (0, __formily_react.mapProps)({
|
|
5017
5075
|
value: "checked",
|
|
5018
5076
|
onInput: "onCheckedChange"
|
|
@@ -5884,6 +5942,28 @@ function ImportDialog({ open, onOpenChange, onImport, columns = [], title, local
|
|
|
5884
5942
|
|
|
5885
5943
|
//#endregion
|
|
5886
5944
|
//#region src/components/auto-crud/auto-crud-table.tsx
|
|
5945
|
+
function mergeFieldPart(base, override) {
|
|
5946
|
+
if (override === void 0) return base;
|
|
5947
|
+
if (override === false || base === false || typeof base !== "object" || typeof override !== "object" || base === null || override === null || Array.isArray(base) || Array.isArray(override)) return override;
|
|
5948
|
+
return {
|
|
5949
|
+
...base,
|
|
5950
|
+
...override
|
|
5951
|
+
};
|
|
5952
|
+
}
|
|
5953
|
+
function mergeFieldConfig(base, override) {
|
|
5954
|
+
return {
|
|
5955
|
+
...base,
|
|
5956
|
+
...override,
|
|
5957
|
+
table: mergeFieldPart(base?.table, override?.table),
|
|
5958
|
+
filter: mergeFieldPart(base?.filter, override?.filter),
|
|
5959
|
+
form: mergeFieldPart(base?.form, override?.form)
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
function mergeFields(base, override) {
|
|
5963
|
+
if (!base && !override) return void 0;
|
|
5964
|
+
const keys = new Set([...Object.keys(base ?? {}), ...Object.keys(override ?? {})]);
|
|
5965
|
+
return Object.fromEntries(Array.from(keys).map((key) => [key, mergeFieldConfig(base?.[key], override?.[key])]));
|
|
5966
|
+
}
|
|
5887
5967
|
/**
|
|
5888
5968
|
* 从统一配置生成表格 overrides
|
|
5889
5969
|
* 当 filter 配置存在时,合并到 meta 中(不影响列隐藏)
|
|
@@ -6176,10 +6256,7 @@ function resolveActions(actionsOrFn, defaults, rowActionsLocale) {
|
|
|
6176
6256
|
function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, permissions, actions: actionItems, toolbarActions, locale: localeProp, onCreate }) {
|
|
6177
6257
|
const locale = resolveLocale(localeProp);
|
|
6178
6258
|
const resolvedSchema = resource.schema ?? schema;
|
|
6179
|
-
const resolvedFields = react.useMemo(() => ({
|
|
6180
|
-
...fields,
|
|
6181
|
-
...resource.fields
|
|
6182
|
-
}), [fields, resource.fields]);
|
|
6259
|
+
const resolvedFields = react.useMemo(() => mergeFields(resource.fields, fields) ?? {}, [fields, resource.fields]);
|
|
6183
6260
|
const can = {
|
|
6184
6261
|
create: permissions?.can?.create ?? true,
|
|
6185
6262
|
update: permissions?.can?.update ?? true,
|
|
@@ -6503,6 +6580,13 @@ function DataTableAdvancedToolbar({ table, children, className,...props }) {
|
|
|
6503
6580
|
|
|
6504
6581
|
//#endregion
|
|
6505
6582
|
//#region src/components/data-table/data-table-faceted-filter.tsx
|
|
6583
|
+
function getOptionCommandValue(option) {
|
|
6584
|
+
return [
|
|
6585
|
+
option.value,
|
|
6586
|
+
option.label,
|
|
6587
|
+
option.searchText
|
|
6588
|
+
].filter(Boolean).join(" ");
|
|
6589
|
+
}
|
|
6506
6590
|
function DataTableFacetedFilter({ column, title, options, multiple }) {
|
|
6507
6591
|
const [open, setOpen] = react.useState(false);
|
|
6508
6592
|
const columnFilterValue = column?.getFilterValue();
|
|
@@ -6584,6 +6668,7 @@ function DataTableFacetedFilter({ column, title, options, multiple }) {
|
|
|
6584
6668
|
children: options.map((option) => {
|
|
6585
6669
|
const isSelected = selectedValues.has(option.value);
|
|
6586
6670
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.CommandItem, {
|
|
6671
|
+
value: getOptionCommandValue(option),
|
|
6587
6672
|
onSelect: () => onItemSelect(option, isSelected),
|
|
6588
6673
|
children: [
|
|
6589
6674
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react_jsx_runtime2 from "react/jsx-runtime";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import * as _tanstack_react_table0 from "@tanstack/react-table";
|
|
4
4
|
import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
|
|
@@ -361,7 +361,7 @@ declare function AutoTableActionBar<TData>({
|
|
|
361
361
|
enableDelete,
|
|
362
362
|
extraActions,
|
|
363
363
|
actions
|
|
364
|
-
}: AutoTableActionBarProps<TData>):
|
|
364
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
365
365
|
//#endregion
|
|
366
366
|
//#region src/lib/schema-bridge/types.d.ts
|
|
367
367
|
/**
|
|
@@ -529,7 +529,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
529
529
|
showDefaultExport,
|
|
530
530
|
onSelectedCountChange,
|
|
531
531
|
getSelectedRows
|
|
532
|
-
}: AutoTableProps<T>):
|
|
532
|
+
}: AutoTableProps<T>): react_jsx_runtime2.JSX.Element;
|
|
533
533
|
//#endregion
|
|
534
534
|
//#region src/i18n/locale.d.ts
|
|
535
535
|
/**
|
|
@@ -635,6 +635,7 @@ interface FilterConfig {
|
|
|
635
635
|
options?: Array<{
|
|
636
636
|
label: string;
|
|
637
637
|
value: string;
|
|
638
|
+
searchText?: string;
|
|
638
639
|
count?: number;
|
|
639
640
|
icon?: React$1.FC<React$1.SVGProps<SVGSVGElement>>;
|
|
640
641
|
}>;
|
|
@@ -874,7 +875,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
874
875
|
toolbarActions,
|
|
875
876
|
locale: localeProp,
|
|
876
877
|
onCreate
|
|
877
|
-
}: AutoCrudTableProps<TSchema>):
|
|
878
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime2.JSX.Element;
|
|
878
879
|
//#endregion
|
|
879
880
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
880
881
|
interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
@@ -882,11 +883,11 @@ interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
|
882
883
|
initialValues?: Partial<z.infer<T>>;
|
|
883
884
|
onSubmit: (values: z.infer<T>) => void | Promise<void>;
|
|
884
885
|
overrides?: FormSchemaOverrides;
|
|
885
|
-
mode?:
|
|
886
|
+
mode?: 'create' | 'edit';
|
|
886
887
|
loading?: boolean;
|
|
887
888
|
gridColumns?: number;
|
|
888
889
|
/** Label 对齐方式 */
|
|
889
|
-
labelAlign?:
|
|
890
|
+
labelAlign?: 'left' | 'top' | 'right';
|
|
890
891
|
/** Label 宽度(labelAlign 为 left 时有效) */
|
|
891
892
|
labelWidth?: number | string;
|
|
892
893
|
/** 是否显示提交按钮(默认 true) */
|
|
@@ -906,7 +907,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
906
907
|
labelAlign,
|
|
907
908
|
labelWidth,
|
|
908
909
|
showSubmitButton
|
|
909
|
-
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>):
|
|
910
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime2.JSX.Element;
|
|
910
911
|
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
911
912
|
ref?: React.Ref<AutoFormRef>;
|
|
912
913
|
}) => ReturnType<typeof AutoFormInner>;
|
|
@@ -1176,6 +1177,7 @@ interface QueryKeys {
|
|
|
1176
1177
|
interface Option {
|
|
1177
1178
|
label: string;
|
|
1178
1179
|
value: string;
|
|
1180
|
+
searchText?: string;
|
|
1179
1181
|
count?: number;
|
|
1180
1182
|
icon?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
1181
1183
|
}
|
|
@@ -1207,7 +1209,7 @@ declare function AutoTableSimpleFilters<TData>({
|
|
|
1207
1209
|
filters: externalFilters,
|
|
1208
1210
|
onFiltersChange,
|
|
1209
1211
|
leading
|
|
1210
|
-
}: AutoTableSimpleFiltersProps<TData>):
|
|
1212
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime2.JSX.Element | null;
|
|
1211
1213
|
//#endregion
|
|
1212
1214
|
//#region src/components/auto-crud/form-modal.d.ts
|
|
1213
1215
|
type ModalVariant = "dialog" | "sheet";
|
|
@@ -1249,7 +1251,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1249
1251
|
labelAlign,
|
|
1250
1252
|
labelWidth,
|
|
1251
1253
|
className
|
|
1252
|
-
}: CrudFormModalProps<T>):
|
|
1254
|
+
}: CrudFormModalProps<T>): react_jsx_runtime2.JSX.Element;
|
|
1253
1255
|
//#endregion
|
|
1254
1256
|
//#region src/components/auto-crud/import-dialog.d.ts
|
|
1255
1257
|
interface ImportDialogProps {
|
|
@@ -1271,7 +1273,7 @@ declare function ImportDialog({
|
|
|
1271
1273
|
columns,
|
|
1272
1274
|
title,
|
|
1273
1275
|
locale
|
|
1274
|
-
}: ImportDialogProps):
|
|
1276
|
+
}: ImportDialogProps): react_jsx_runtime2.JSX.Element;
|
|
1275
1277
|
//#endregion
|
|
1276
1278
|
//#region src/components/auto-crud/export-dialog.d.ts
|
|
1277
1279
|
type ExportMode = "selected" | "filtered";
|
|
@@ -1291,7 +1293,7 @@ declare function ExportDialog({
|
|
|
1291
1293
|
selectedCount,
|
|
1292
1294
|
onExport,
|
|
1293
1295
|
canExportFiltered
|
|
1294
|
-
}: ExportDialogProps):
|
|
1296
|
+
}: ExportDialogProps): react_jsx_runtime2.JSX.Element;
|
|
1295
1297
|
//#endregion
|
|
1296
1298
|
//#region src/components/data-table/data-table.d.ts
|
|
1297
1299
|
interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1304,7 +1306,7 @@ declare function DataTable<TData>({
|
|
|
1304
1306
|
children,
|
|
1305
1307
|
className,
|
|
1306
1308
|
...props
|
|
1307
|
-
}: DataTableProps<TData>):
|
|
1309
|
+
}: DataTableProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1308
1310
|
//#endregion
|
|
1309
1311
|
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
1310
1312
|
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1315,7 +1317,7 @@ declare function DataTableAdvancedToolbar<TData>({
|
|
|
1315
1317
|
children,
|
|
1316
1318
|
className,
|
|
1317
1319
|
...props
|
|
1318
|
-
}: DataTableAdvancedToolbarProps<TData>):
|
|
1320
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1319
1321
|
//#endregion
|
|
1320
1322
|
//#region src/components/data-table/data-table-column-header.d.ts
|
|
1321
1323
|
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
@@ -1327,7 +1329,7 @@ declare function DataTableColumnHeader<TData, TValue>({
|
|
|
1327
1329
|
label,
|
|
1328
1330
|
className,
|
|
1329
1331
|
...props
|
|
1330
|
-
}: DataTableColumnHeaderProps<TData, TValue>):
|
|
1332
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
|
|
1331
1333
|
//#endregion
|
|
1332
1334
|
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
1333
1335
|
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
@@ -1341,7 +1343,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
|
|
|
1341
1343
|
title,
|
|
1342
1344
|
options,
|
|
1343
1345
|
multiple
|
|
1344
|
-
}: DataTableFacetedFilterProps<TData, TValue>):
|
|
1346
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
|
|
1345
1347
|
//#endregion
|
|
1346
1348
|
//#region src/components/data-table/data-table-pagination.d.ts
|
|
1347
1349
|
interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
|
|
@@ -1353,7 +1355,7 @@ declare function DataTablePagination<TData>({
|
|
|
1353
1355
|
pageSizeOptions,
|
|
1354
1356
|
className,
|
|
1355
1357
|
...props
|
|
1356
|
-
}: DataTablePaginationProps<TData>):
|
|
1358
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1357
1359
|
//#endregion
|
|
1358
1360
|
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
1359
1361
|
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1364,7 +1366,7 @@ declare function DataTableToolbar<TData>({
|
|
|
1364
1366
|
children,
|
|
1365
1367
|
className,
|
|
1366
1368
|
...props
|
|
1367
|
-
}: DataTableToolbarProps<TData>):
|
|
1369
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1368
1370
|
//#endregion
|
|
1369
1371
|
//#region src/components/data-table/data-table-view-options.d.ts
|
|
1370
1372
|
interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
|
|
@@ -1375,7 +1377,7 @@ declare function DataTableViewOptions<TData>({
|
|
|
1375
1377
|
table,
|
|
1376
1378
|
disabled,
|
|
1377
1379
|
...props
|
|
1378
|
-
}: DataTableViewOptionsProps<TData>):
|
|
1380
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1379
1381
|
//#endregion
|
|
1380
1382
|
//#region src/hooks/use-data-table.d.ts
|
|
1381
1383
|
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as _tanstack_react_table0 from "@tanstack/react-table";
|
|
|
3
3
|
import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
|
|
4
4
|
import { DropdownMenuTrigger, PopoverContent } from "@pixpilot/shadcn";
|
|
5
5
|
import { ClassValue } from "clsx";
|
|
6
|
-
import * as
|
|
6
|
+
import * as react_jsx_runtime13 from "react/jsx-runtime";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { ISchema } from "@formily/json-schema";
|
|
9
9
|
|
|
@@ -361,7 +361,7 @@ declare function AutoTableActionBar<TData>({
|
|
|
361
361
|
enableDelete,
|
|
362
362
|
extraActions,
|
|
363
363
|
actions
|
|
364
|
-
}: AutoTableActionBarProps<TData>):
|
|
364
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime13.JSX.Element;
|
|
365
365
|
//#endregion
|
|
366
366
|
//#region src/lib/schema-bridge/types.d.ts
|
|
367
367
|
/**
|
|
@@ -529,7 +529,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
529
529
|
showDefaultExport,
|
|
530
530
|
onSelectedCountChange,
|
|
531
531
|
getSelectedRows
|
|
532
|
-
}: AutoTableProps<T>):
|
|
532
|
+
}: AutoTableProps<T>): react_jsx_runtime13.JSX.Element;
|
|
533
533
|
//#endregion
|
|
534
534
|
//#region src/i18n/locale.d.ts
|
|
535
535
|
/**
|
|
@@ -635,6 +635,7 @@ interface FilterConfig {
|
|
|
635
635
|
options?: Array<{
|
|
636
636
|
label: string;
|
|
637
637
|
value: string;
|
|
638
|
+
searchText?: string;
|
|
638
639
|
count?: number;
|
|
639
640
|
icon?: React$1.FC<React$1.SVGProps<SVGSVGElement>>;
|
|
640
641
|
}>;
|
|
@@ -874,7 +875,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
874
875
|
toolbarActions,
|
|
875
876
|
locale: localeProp,
|
|
876
877
|
onCreate
|
|
877
|
-
}: AutoCrudTableProps<TSchema>):
|
|
878
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime13.JSX.Element;
|
|
878
879
|
//#endregion
|
|
879
880
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
880
881
|
interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
@@ -882,11 +883,11 @@ interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
|
882
883
|
initialValues?: Partial<z.infer<T>>;
|
|
883
884
|
onSubmit: (values: z.infer<T>) => void | Promise<void>;
|
|
884
885
|
overrides?: FormSchemaOverrides;
|
|
885
|
-
mode?:
|
|
886
|
+
mode?: 'create' | 'edit';
|
|
886
887
|
loading?: boolean;
|
|
887
888
|
gridColumns?: number;
|
|
888
889
|
/** Label 对齐方式 */
|
|
889
|
-
labelAlign?:
|
|
890
|
+
labelAlign?: 'left' | 'top' | 'right';
|
|
890
891
|
/** Label 宽度(labelAlign 为 left 时有效) */
|
|
891
892
|
labelWidth?: number | string;
|
|
892
893
|
/** 是否显示提交按钮(默认 true) */
|
|
@@ -906,7 +907,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
906
907
|
labelAlign,
|
|
907
908
|
labelWidth,
|
|
908
909
|
showSubmitButton
|
|
909
|
-
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>):
|
|
910
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime13.JSX.Element;
|
|
910
911
|
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
911
912
|
ref?: React.Ref<AutoFormRef>;
|
|
912
913
|
}) => ReturnType<typeof AutoFormInner>;
|
|
@@ -1176,6 +1177,7 @@ interface QueryKeys {
|
|
|
1176
1177
|
interface Option {
|
|
1177
1178
|
label: string;
|
|
1178
1179
|
value: string;
|
|
1180
|
+
searchText?: string;
|
|
1179
1181
|
count?: number;
|
|
1180
1182
|
icon?: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
1181
1183
|
}
|
|
@@ -1207,7 +1209,7 @@ declare function AutoTableSimpleFilters<TData>({
|
|
|
1207
1209
|
filters: externalFilters,
|
|
1208
1210
|
onFiltersChange,
|
|
1209
1211
|
leading
|
|
1210
|
-
}: AutoTableSimpleFiltersProps<TData>):
|
|
1212
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime13.JSX.Element | null;
|
|
1211
1213
|
//#endregion
|
|
1212
1214
|
//#region src/components/auto-crud/form-modal.d.ts
|
|
1213
1215
|
type ModalVariant = "dialog" | "sheet";
|
|
@@ -1249,7 +1251,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1249
1251
|
labelAlign,
|
|
1250
1252
|
labelWidth,
|
|
1251
1253
|
className
|
|
1252
|
-
}: CrudFormModalProps<T>):
|
|
1254
|
+
}: CrudFormModalProps<T>): react_jsx_runtime13.JSX.Element;
|
|
1253
1255
|
//#endregion
|
|
1254
1256
|
//#region src/components/auto-crud/import-dialog.d.ts
|
|
1255
1257
|
interface ImportDialogProps {
|
|
@@ -1271,7 +1273,7 @@ declare function ImportDialog({
|
|
|
1271
1273
|
columns,
|
|
1272
1274
|
title,
|
|
1273
1275
|
locale
|
|
1274
|
-
}: ImportDialogProps):
|
|
1276
|
+
}: ImportDialogProps): react_jsx_runtime13.JSX.Element;
|
|
1275
1277
|
//#endregion
|
|
1276
1278
|
//#region src/components/auto-crud/export-dialog.d.ts
|
|
1277
1279
|
type ExportMode = "selected" | "filtered";
|
|
@@ -1291,7 +1293,7 @@ declare function ExportDialog({
|
|
|
1291
1293
|
selectedCount,
|
|
1292
1294
|
onExport,
|
|
1293
1295
|
canExportFiltered
|
|
1294
|
-
}: ExportDialogProps):
|
|
1296
|
+
}: ExportDialogProps): react_jsx_runtime13.JSX.Element;
|
|
1295
1297
|
//#endregion
|
|
1296
1298
|
//#region src/components/data-table/data-table.d.ts
|
|
1297
1299
|
interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1304,7 +1306,7 @@ declare function DataTable<TData>({
|
|
|
1304
1306
|
children,
|
|
1305
1307
|
className,
|
|
1306
1308
|
...props
|
|
1307
|
-
}: DataTableProps<TData>):
|
|
1309
|
+
}: DataTableProps<TData>): react_jsx_runtime13.JSX.Element;
|
|
1308
1310
|
//#endregion
|
|
1309
1311
|
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
1310
1312
|
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1315,7 +1317,7 @@ declare function DataTableAdvancedToolbar<TData>({
|
|
|
1315
1317
|
children,
|
|
1316
1318
|
className,
|
|
1317
1319
|
...props
|
|
1318
|
-
}: DataTableAdvancedToolbarProps<TData>):
|
|
1320
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime13.JSX.Element;
|
|
1319
1321
|
//#endregion
|
|
1320
1322
|
//#region src/components/data-table/data-table-column-header.d.ts
|
|
1321
1323
|
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
@@ -1327,7 +1329,7 @@ declare function DataTableColumnHeader<TData, TValue>({
|
|
|
1327
1329
|
label,
|
|
1328
1330
|
className,
|
|
1329
1331
|
...props
|
|
1330
|
-
}: DataTableColumnHeaderProps<TData, TValue>):
|
|
1332
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime13.JSX.Element;
|
|
1331
1333
|
//#endregion
|
|
1332
1334
|
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
1333
1335
|
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
@@ -1341,7 +1343,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
|
|
|
1341
1343
|
title,
|
|
1342
1344
|
options,
|
|
1343
1345
|
multiple
|
|
1344
|
-
}: DataTableFacetedFilterProps<TData, TValue>):
|
|
1346
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime13.JSX.Element;
|
|
1345
1347
|
//#endregion
|
|
1346
1348
|
//#region src/components/data-table/data-table-pagination.d.ts
|
|
1347
1349
|
interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
|
|
@@ -1353,7 +1355,7 @@ declare function DataTablePagination<TData>({
|
|
|
1353
1355
|
pageSizeOptions,
|
|
1354
1356
|
className,
|
|
1355
1357
|
...props
|
|
1356
|
-
}: DataTablePaginationProps<TData>):
|
|
1358
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime13.JSX.Element;
|
|
1357
1359
|
//#endregion
|
|
1358
1360
|
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
1359
1361
|
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1364,7 +1366,7 @@ declare function DataTableToolbar<TData>({
|
|
|
1364
1366
|
children,
|
|
1365
1367
|
className,
|
|
1366
1368
|
...props
|
|
1367
|
-
}: DataTableToolbarProps<TData>):
|
|
1369
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime13.JSX.Element;
|
|
1368
1370
|
//#endregion
|
|
1369
1371
|
//#region src/components/data-table/data-table-view-options.d.ts
|
|
1370
1372
|
interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
|
|
@@ -1375,7 +1377,7 @@ declare function DataTableViewOptions<TData>({
|
|
|
1375
1377
|
table,
|
|
1376
1378
|
disabled,
|
|
1377
1379
|
...props
|
|
1378
|
-
}: DataTableViewOptionsProps<TData>):
|
|
1380
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime13.JSX.Element;
|
|
1379
1381
|
//#endregion
|
|
1380
1382
|
//#region src/hooks/use-data-table.d.ts
|
|
1381
1383
|
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
package/dist/index.js
CHANGED
|
@@ -1022,6 +1022,7 @@ function FacetedItem(props) {
|
|
|
1022
1022
|
else if (context.onItemSelect) context.onItemSelect(currentValue);
|
|
1023
1023
|
}, [onSelect, context]);
|
|
1024
1024
|
return /* @__PURE__ */ jsxs(CommandItem, {
|
|
1025
|
+
value,
|
|
1025
1026
|
"aria-selected": isSelected,
|
|
1026
1027
|
"data-selected": isSelected,
|
|
1027
1028
|
className: cn("gap-2", className),
|
|
@@ -1900,6 +1901,13 @@ const DEBOUNCE_MS$1 = 300;
|
|
|
1900
1901
|
const THROTTLE_MS$1 = 50;
|
|
1901
1902
|
const FILTER_SHORTCUT_KEY = "f";
|
|
1902
1903
|
const REMOVE_FILTER_SHORTCUTS = ["backspace", "delete"];
|
|
1904
|
+
function getOptionCommandValue$2(option) {
|
|
1905
|
+
return [
|
|
1906
|
+
option.value,
|
|
1907
|
+
option.label,
|
|
1908
|
+
option.searchText
|
|
1909
|
+
].filter(Boolean).join(" ");
|
|
1910
|
+
}
|
|
1903
1911
|
function DataTableFilterMenu({ table, debounceMs = DEBOUNCE_MS$1, throttleMs = THROTTLE_MS$1, shallow = true, disabled,...props }) {
|
|
1904
1912
|
const id = React.useId();
|
|
1905
1913
|
const columns = React.useMemo(() => {
|
|
@@ -2178,7 +2186,7 @@ function FilterValueSelector({ column, value, onSelect }) {
|
|
|
2178
2186
|
})] });
|
|
2179
2187
|
case "select":
|
|
2180
2188
|
case "multiSelect": return /* @__PURE__ */ jsx(CommandGroup, { children: column.columnDef.meta?.options?.map((option) => /* @__PURE__ */ jsxs(CommandItem, {
|
|
2181
|
-
value: option
|
|
2189
|
+
value: getOptionCommandValue$2(option),
|
|
2182
2190
|
onSelect: () => onSelect(option.value),
|
|
2183
2191
|
children: [
|
|
2184
2192
|
option.icon && /* @__PURE__ */ jsx(option.icon, {}),
|
|
@@ -2305,7 +2313,7 @@ function onFilterInputRender({ filter, column, inputId, onFilterUpdate, showValu
|
|
|
2305
2313
|
align: "start",
|
|
2306
2314
|
className: "w-48 p-0",
|
|
2307
2315
|
children: /* @__PURE__ */ jsxs(Command, { children: [/* @__PURE__ */ jsx(CommandInput, { placeholder: "Search options..." }), /* @__PURE__ */ jsxs(CommandList, { children: [/* @__PURE__ */ jsx(CommandEmpty, { children: "No options found." }), /* @__PURE__ */ jsx(CommandGroup, { children: options.map((option) => /* @__PURE__ */ jsxs(CommandItem, {
|
|
2308
|
-
value: option
|
|
2316
|
+
value: getOptionCommandValue$2(option),
|
|
2309
2317
|
onSelect: () => {
|
|
2310
2318
|
const value = filter.variant === "multiSelect" ? selectedValues.includes(option.value) ? selectedValues.filter((v) => v !== option.value) : [...selectedValues, option.value] : option.value;
|
|
2311
2319
|
onFilterUpdate(filter.filterId, { value });
|
|
@@ -2731,32 +2739,65 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2731
2739
|
const [expanded, setExpanded] = React.useState(false);
|
|
2732
2740
|
const [visibleCount, setVisibleCount] = React.useState(null);
|
|
2733
2741
|
const containerRef = React.useRef(null);
|
|
2742
|
+
const hasLeading = leading != null;
|
|
2743
|
+
const filterMeasureKey = React.useMemo(() => filters.map((filter) => [
|
|
2744
|
+
filter.id,
|
|
2745
|
+
filter.operator,
|
|
2746
|
+
Array.isArray(filter.value) ? filter.value.join(",") : String(filter.value ?? "")
|
|
2747
|
+
].join(":")).join("|"), [filters]);
|
|
2734
2748
|
const calcVisibleCount = React.useCallback(() => {
|
|
2735
2749
|
const el = containerRef.current;
|
|
2736
2750
|
if (!el) return;
|
|
2737
|
-
const items = el.querySelectorAll("[data-filter-item]");
|
|
2738
|
-
if (items.length === 0)
|
|
2751
|
+
const items = Array.from(el.querySelectorAll("[data-filter-item]"));
|
|
2752
|
+
if (items.length === 0) {
|
|
2753
|
+
setVisibleCount(null);
|
|
2754
|
+
return;
|
|
2755
|
+
}
|
|
2739
2756
|
const restoreList = [];
|
|
2740
|
-
el.querySelectorAll(".hidden").forEach((node) => {
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
restoreList.push(htmlNode);
|
|
2757
|
+
el.querySelectorAll("[data-filter-item].hidden, [data-filter-toggle].hidden").forEach((node) => {
|
|
2758
|
+
node.classList.remove("hidden");
|
|
2759
|
+
restoreList.push(node);
|
|
2744
2760
|
});
|
|
2745
|
-
el.
|
|
2746
|
-
el.
|
|
2747
|
-
const
|
|
2761
|
+
const availableWidth = el.getBoundingClientRect().width;
|
|
2762
|
+
const previousFlex = el.style.flex;
|
|
2763
|
+
const previousWidth = el.style.width;
|
|
2764
|
+
el.style.flex = `0 0 ${availableWidth}px`;
|
|
2765
|
+
el.style.width = `${availableWidth}px`;
|
|
2766
|
+
el.getBoundingClientRect();
|
|
2767
|
+
const computedStyle = window.getComputedStyle(el);
|
|
2768
|
+
const gap = Number.parseFloat(computedStyle.columnGap) || Number.parseFloat(computedStyle.gap) || 0;
|
|
2769
|
+
const leadingEl = el.querySelector("[data-filter-leading]");
|
|
2770
|
+
const toggle = el.querySelector("[data-filter-toggle]");
|
|
2771
|
+
const reset = el.querySelector("[data-filter-reset]");
|
|
2772
|
+
const addWidth = (current, next) => {
|
|
2773
|
+
if (next <= 0) return current;
|
|
2774
|
+
if (current === 0) return next;
|
|
2775
|
+
return current + gap + next;
|
|
2776
|
+
};
|
|
2777
|
+
const leadingWidth = leadingEl?.offsetWidth ?? 0;
|
|
2778
|
+
const itemWidths = items.map((item) => item.offsetWidth);
|
|
2779
|
+
const toggleWidth = toggle?.offsetWidth ?? 0;
|
|
2780
|
+
const resetWidth = reset?.offsetWidth ?? 0;
|
|
2781
|
+
if (itemWidths.reduce((width, itemWidth) => addWidth(width, itemWidth), addWidth(leadingWidth, resetWidth)) <= availableWidth) {
|
|
2782
|
+
el.style.flex = previousFlex;
|
|
2783
|
+
el.style.width = previousWidth;
|
|
2784
|
+
restoreList.forEach((node) => node.classList.add("hidden"));
|
|
2785
|
+
setVisibleCount(null);
|
|
2786
|
+
return;
|
|
2787
|
+
}
|
|
2788
|
+
const trailingWidth = addWidth(addWidth(0, toggleWidth), resetWidth);
|
|
2789
|
+
let usedWidth = leadingWidth;
|
|
2748
2790
|
let count = 0;
|
|
2749
|
-
for (const
|
|
2750
|
-
|
|
2791
|
+
for (const itemWidth of itemWidths) {
|
|
2792
|
+
const nextWidth = addWidth(usedWidth, itemWidth);
|
|
2793
|
+
if (addWidth(nextWidth, trailingWidth) > availableWidth) break;
|
|
2794
|
+
usedWidth = nextWidth;
|
|
2751
2795
|
count++;
|
|
2752
2796
|
}
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
if (btn.offsetTop > firstTop) count--;
|
|
2756
|
-
}
|
|
2757
|
-
el.style.flex = "";
|
|
2797
|
+
el.style.flex = previousFlex;
|
|
2798
|
+
el.style.width = previousWidth;
|
|
2758
2799
|
restoreList.forEach((node) => node.classList.add("hidden"));
|
|
2759
|
-
setVisibleCount(count
|
|
2800
|
+
setVisibleCount(count);
|
|
2760
2801
|
}, []);
|
|
2761
2802
|
React.useLayoutEffect(() => {
|
|
2762
2803
|
if (!mounted) return;
|
|
@@ -2764,6 +2805,9 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2764
2805
|
}, [
|
|
2765
2806
|
mounted,
|
|
2766
2807
|
filterColumns.length,
|
|
2808
|
+
hasLeading,
|
|
2809
|
+
hasFilters,
|
|
2810
|
+
filterMeasureKey,
|
|
2767
2811
|
calcVisibleCount
|
|
2768
2812
|
]);
|
|
2769
2813
|
React.useEffect(() => {
|
|
@@ -2786,6 +2830,7 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2786
2830
|
}, [
|
|
2787
2831
|
mounted,
|
|
2788
2832
|
filterColumns.length,
|
|
2833
|
+
hasLeading,
|
|
2789
2834
|
calcVisibleCount
|
|
2790
2835
|
]);
|
|
2791
2836
|
if (!mounted) return null;
|
|
@@ -2793,7 +2838,11 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2793
2838
|
ref: containerRef,
|
|
2794
2839
|
className: "flex flex-1 flex-wrap items-center gap-2 min-w-0",
|
|
2795
2840
|
children: [
|
|
2796
|
-
leading,
|
|
2841
|
+
leading != null ? /* @__PURE__ */ jsx("div", {
|
|
2842
|
+
className: "shrink-0",
|
|
2843
|
+
"data-filter-leading": true,
|
|
2844
|
+
children: leading
|
|
2845
|
+
}) : null,
|
|
2797
2846
|
filterColumns.map((column, index) => {
|
|
2798
2847
|
const meta = column.columnDef.meta;
|
|
2799
2848
|
const value = getFilterValue(column.id);
|
|
@@ -2857,6 +2906,7 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2857
2906
|
children: expanded ? /* @__PURE__ */ jsx(ChevronUp, { className: "size-4" }) : /* @__PURE__ */ jsx(ChevronDown, { className: "size-4" })
|
|
2858
2907
|
}),
|
|
2859
2908
|
hasFilters && /* @__PURE__ */ jsxs(Button, {
|
|
2909
|
+
"data-filter-reset": true,
|
|
2860
2910
|
variant: "outline",
|
|
2861
2911
|
size: "sm",
|
|
2862
2912
|
className: "h-8 border-dashed shrink-0",
|
|
@@ -2866,6 +2916,13 @@ function AutoTableSimpleFilters({ table, shallow = false, filters: externalFilte
|
|
|
2866
2916
|
]
|
|
2867
2917
|
});
|
|
2868
2918
|
}
|
|
2919
|
+
function getOptionCommandValue$1(option) {
|
|
2920
|
+
return [
|
|
2921
|
+
option.value,
|
|
2922
|
+
option.label,
|
|
2923
|
+
option.searchText
|
|
2924
|
+
].filter(Boolean).join(" ");
|
|
2925
|
+
}
|
|
2869
2926
|
function SimpleFacetedFilter({ title, options, multiple, value, onChange }) {
|
|
2870
2927
|
const [open, setOpen] = React.useState(false);
|
|
2871
2928
|
const selectedValues = React.useMemo(() => new Set(value), [value]);
|
|
@@ -2945,6 +3002,7 @@ function SimpleFacetedFilter({ title, options, multiple, value, onChange }) {
|
|
|
2945
3002
|
children: options.map((option) => {
|
|
2946
3003
|
const isSelected = selectedValues.has(option.value);
|
|
2947
3004
|
return /* @__PURE__ */ jsxs(CommandItem, {
|
|
3005
|
+
value: getOptionCommandValue$1(option),
|
|
2948
3006
|
onSelect: () => onItemSelect(option, isSelected),
|
|
2949
3007
|
children: [
|
|
2950
3008
|
/* @__PURE__ */ jsx("div", {
|
|
@@ -4771,7 +4829,7 @@ function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection
|
|
|
4771
4829
|
/* @__PURE__ */ jsxs("div", {
|
|
4772
4830
|
className: "flex w-full items-start justify-between gap-2 p-1",
|
|
4773
4831
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
4774
|
-
className: "flex flex-1 items-start gap-2
|
|
4832
|
+
className: "flex min-h-[40px] min-w-0 flex-1 items-start gap-2",
|
|
4775
4833
|
"data-filter-parent": true,
|
|
4776
4834
|
children: [
|
|
4777
4835
|
currentMode !== "simple" && searchInput,
|
|
@@ -4969,7 +5027,7 @@ function createEditFormSchema(schema, options) {
|
|
|
4969
5027
|
|
|
4970
5028
|
//#endregion
|
|
4971
5029
|
//#region src/components/auto-crud/auto-form.tsx
|
|
4972
|
-
const COMBOBOX_LIST_CLASS = "[&_[cmdk-list]]:max-h-[360px]";
|
|
5030
|
+
const COMBOBOX_LIST_CLASS = "[&_[cmdk-list]]:max-h-[360px] [&_[cmdk-list]]:overflow-x-hidden [&_[cmdk-list]]:overflow-y-auto";
|
|
4973
5031
|
const FormilySwitch = connect(Switch, mapProps({
|
|
4974
5032
|
value: "checked",
|
|
4975
5033
|
onInput: "onCheckedChange"
|
|
@@ -5841,6 +5899,28 @@ function ImportDialog({ open, onOpenChange, onImport, columns = [], title, local
|
|
|
5841
5899
|
|
|
5842
5900
|
//#endregion
|
|
5843
5901
|
//#region src/components/auto-crud/auto-crud-table.tsx
|
|
5902
|
+
function mergeFieldPart(base, override) {
|
|
5903
|
+
if (override === void 0) return base;
|
|
5904
|
+
if (override === false || base === false || typeof base !== "object" || typeof override !== "object" || base === null || override === null || Array.isArray(base) || Array.isArray(override)) return override;
|
|
5905
|
+
return {
|
|
5906
|
+
...base,
|
|
5907
|
+
...override
|
|
5908
|
+
};
|
|
5909
|
+
}
|
|
5910
|
+
function mergeFieldConfig(base, override) {
|
|
5911
|
+
return {
|
|
5912
|
+
...base,
|
|
5913
|
+
...override,
|
|
5914
|
+
table: mergeFieldPart(base?.table, override?.table),
|
|
5915
|
+
filter: mergeFieldPart(base?.filter, override?.filter),
|
|
5916
|
+
form: mergeFieldPart(base?.form, override?.form)
|
|
5917
|
+
};
|
|
5918
|
+
}
|
|
5919
|
+
function mergeFields(base, override) {
|
|
5920
|
+
if (!base && !override) return void 0;
|
|
5921
|
+
const keys = new Set([...Object.keys(base ?? {}), ...Object.keys(override ?? {})]);
|
|
5922
|
+
return Object.fromEntries(Array.from(keys).map((key) => [key, mergeFieldConfig(base?.[key], override?.[key])]));
|
|
5923
|
+
}
|
|
5844
5924
|
/**
|
|
5845
5925
|
* 从统一配置生成表格 overrides
|
|
5846
5926
|
* 当 filter 配置存在时,合并到 meta 中(不影响列隐藏)
|
|
@@ -6133,10 +6213,7 @@ function resolveActions(actionsOrFn, defaults, rowActionsLocale) {
|
|
|
6133
6213
|
function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, permissions, actions: actionItems, toolbarActions, locale: localeProp, onCreate }) {
|
|
6134
6214
|
const locale = resolveLocale(localeProp);
|
|
6135
6215
|
const resolvedSchema = resource.schema ?? schema;
|
|
6136
|
-
const resolvedFields = React.useMemo(() => ({
|
|
6137
|
-
...fields,
|
|
6138
|
-
...resource.fields
|
|
6139
|
-
}), [fields, resource.fields]);
|
|
6216
|
+
const resolvedFields = React.useMemo(() => mergeFields(resource.fields, fields) ?? {}, [fields, resource.fields]);
|
|
6140
6217
|
const can = {
|
|
6141
6218
|
create: permissions?.can?.create ?? true,
|
|
6142
6219
|
update: permissions?.can?.update ?? true,
|
|
@@ -6460,6 +6537,13 @@ function DataTableAdvancedToolbar({ table, children, className,...props }) {
|
|
|
6460
6537
|
|
|
6461
6538
|
//#endregion
|
|
6462
6539
|
//#region src/components/data-table/data-table-faceted-filter.tsx
|
|
6540
|
+
function getOptionCommandValue(option) {
|
|
6541
|
+
return [
|
|
6542
|
+
option.value,
|
|
6543
|
+
option.label,
|
|
6544
|
+
option.searchText
|
|
6545
|
+
].filter(Boolean).join(" ");
|
|
6546
|
+
}
|
|
6463
6547
|
function DataTableFacetedFilter({ column, title, options, multiple }) {
|
|
6464
6548
|
const [open, setOpen] = React.useState(false);
|
|
6465
6549
|
const columnFilterValue = column?.getFilterValue();
|
|
@@ -6541,6 +6625,7 @@ function DataTableFacetedFilter({ column, title, options, multiple }) {
|
|
|
6541
6625
|
children: options.map((option) => {
|
|
6542
6626
|
const isSelected = selectedValues.has(option.value);
|
|
6543
6627
|
return /* @__PURE__ */ jsxs(CommandItem, {
|
|
6628
|
+
value: getOptionCommandValue(option),
|
|
6544
6629
|
onSelect: () => onItemSelect(option, isSelected),
|
|
6545
6630
|
children: [
|
|
6546
6631
|
/* @__PURE__ */ jsx("div", {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordrhyme/auto-crud",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.5",
|
|
5
5
|
"description": "Schema-first CRUD components with auto-generated tables and forms",
|
|
6
6
|
"author": "wordrhyme",
|
|
7
7
|
"license": "MIT",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"tailwind-merge": "^3.5.0",
|
|
67
67
|
"vaul": "^1.1.2",
|
|
68
68
|
"@pixpilot/formily-shadcn": "1.11.20",
|
|
69
|
-
"@pixpilot/shadcn
|
|
70
|
-
"@pixpilot/shadcn": "1.
|
|
69
|
+
"@pixpilot/shadcn": "1.2.7",
|
|
70
|
+
"@pixpilot/shadcn-ui": "1.21.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@tanstack/react-query": "^5.90.15",
|
|
@@ -83,9 +83,9 @@
|
|
|
83
83
|
"tsdown": "^0.15.12",
|
|
84
84
|
"typescript": "^5.9.3",
|
|
85
85
|
"@internal/eslint-config": "0.3.0",
|
|
86
|
+
"@internal/prettier-config": "0.0.1",
|
|
86
87
|
"@internal/tsconfig": "0.1.0",
|
|
87
88
|
"@internal/tsdown-config": "0.1.0",
|
|
88
|
-
"@internal/prettier-config": "0.0.1",
|
|
89
89
|
"@internal/vitest-config": "0.1.0"
|
|
90
90
|
},
|
|
91
91
|
"prettier": "@internal/prettier-config",
|