next-data-kit 8.0.0 → 8.1.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 +16 -2
- package/dist/{action-pIfOi9UC.d.cts → action-DdkPkUFP.d.cts} +13 -7
- package/dist/{action-pIfOi9UC.d.ts → action-DdkPkUFP.d.ts} +13 -7
- package/dist/client/components/data-kit-infinity.d.ts +1 -2
- package/dist/client/components/data-kit-infinity.d.ts.map +1 -1
- package/dist/client/components/data-kit-infinity.js +2 -2
- package/dist/client/components/data-kit-infinity.js.map +1 -1
- package/dist/client/components/data-kit-table.d.ts +1 -2
- package/dist/client/components/data-kit-table.d.ts.map +1 -1
- package/dist/client/components/data-kit-table.js +3 -3
- package/dist/client/components/data-kit-table.js.map +1 -1
- package/dist/client/components/data-kit.d.ts +1 -2
- package/dist/client/components/data-kit.d.ts.map +1 -1
- package/dist/client/components/data-kit.js +2 -2
- package/dist/client/components/data-kit.js.map +1 -1
- package/dist/client/components/ui/switch.d.ts +2 -2
- package/dist/client/components/ui/switch.d.ts.map +1 -1
- package/dist/client/components/ui/switch.js +4 -4
- package/dist/client/components/ui/switch.js.map +1 -1
- package/dist/client/hooks/useDataKit.d.ts.map +1 -1
- package/dist/client/hooks/useDataKit.js +14 -6
- package/dist/client/hooks/useDataKit.js.map +1 -1
- package/dist/index.cjs +32 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -8
- package/dist/index.d.ts +17 -8
- package/dist/index.js +32 -25
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +3 -2
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +3 -2
- package/dist/server.js.map +1 -1
- package/dist/types/client/component.d.ts +2 -1
- package/dist/types/client/component.d.ts.map +1 -1
- package/dist/types/client/hook.d.ts +5 -2
- package/dist/types/client/hook.d.ts.map +1 -1
- package/dist/types/index.d.cts +7 -3
- package/dist/types/next-data-kit.d.ts +12 -6
- package/dist/types/next-data-kit.d.ts.map +1 -1
- package/dist/types/server/action.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -78,28 +78,34 @@ type TSortEntry = {
|
|
|
78
78
|
path: string;
|
|
79
79
|
value: 1 | -1;
|
|
80
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Filter configuration item
|
|
83
|
+
*/
|
|
84
|
+
type TFilterConfiguration = {
|
|
85
|
+
type: 'REGEX' | 'EXACT';
|
|
86
|
+
field?: string;
|
|
87
|
+
};
|
|
81
88
|
/**
|
|
82
89
|
* Filter configuration for automatic filtering
|
|
83
90
|
*/
|
|
84
91
|
type TFilterConfig = {
|
|
85
|
-
[key: string]:
|
|
86
|
-
type: 'REGEX' | 'EXACT';
|
|
87
|
-
field?: string;
|
|
88
|
-
};
|
|
92
|
+
[key: string]: TFilterConfiguration;
|
|
89
93
|
};
|
|
90
94
|
/**
|
|
91
95
|
* Custom filter configuration
|
|
92
96
|
* Allows defining custom filter functions for specific filter keys
|
|
97
|
+
* The value parameter can be typed by using a type assertion in the function definition
|
|
93
98
|
*/
|
|
94
99
|
type TFilterCustomConfig<T = unknown> = {
|
|
95
|
-
[id: string]: (data:
|
|
100
|
+
[id: string]: (data: any) => TMongoFilterQuery<T>;
|
|
96
101
|
};
|
|
97
102
|
/**
|
|
98
103
|
* Variant of TFilterCustomConfig that allows customizing the returned filter shape.
|
|
99
104
|
* Useful for Mongo (operator-based) vs. other ORMs (where clauses) in the future.
|
|
105
|
+
* The value parameter can be typed by using a type assertion in the function definition
|
|
100
106
|
*/
|
|
101
107
|
type TFilterCustomConfigWithFilter<TDoc = unknown, TFilter = TMongoFilterQuery<TDoc>> = {
|
|
102
|
-
[id: string]: (data:
|
|
108
|
+
[id: string]: (data: any) => TFilter;
|
|
103
109
|
};
|
|
104
110
|
/**
|
|
105
111
|
* React Data Kit server action input
|
|
@@ -265,7 +271,10 @@ type TUseDataKitOptions<T = unknown, R = unknown> = {
|
|
|
265
271
|
query?: Record<string, unknown>;
|
|
266
272
|
};
|
|
267
273
|
memory?: 'memory' | 'search-params';
|
|
268
|
-
|
|
274
|
+
filters?: {
|
|
275
|
+
id: string;
|
|
276
|
+
configuration?: TFilterConfiguration;
|
|
277
|
+
}[];
|
|
269
278
|
action: (input: TDataKitInput<T>) => Promise<TDataKitResult<R>>;
|
|
270
279
|
onSuccess?: (result: TDataKitResult<R>) => void;
|
|
271
280
|
onError?: (error: Error) => void;
|
|
@@ -379,6 +388,7 @@ type TDataKitFilterItemBase = {
|
|
|
379
388
|
id: string;
|
|
380
389
|
label: string;
|
|
381
390
|
placeholder?: string;
|
|
391
|
+
configuration?: TFilterConfiguration;
|
|
382
392
|
};
|
|
383
393
|
/**
|
|
384
394
|
* Text filter item
|
|
@@ -571,7 +581,6 @@ declare const DefaultDataKitContext: React$1.Context<TDataKitContextValue<unknow
|
|
|
571
581
|
declare const DataKit: <TAction extends (input: TDataKitInput<unknown>) => Promise<TDataKitResult<TDataKitSelectableItem>>>(props: Readonly<{
|
|
572
582
|
action: TAction;
|
|
573
583
|
query?: Record<string, unknown>;
|
|
574
|
-
filterConfig?: TFilterConfig;
|
|
575
584
|
filters?: TDataKitFilterItem[];
|
|
576
585
|
limit?: {
|
|
577
586
|
default: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -78,28 +78,34 @@ type TSortEntry = {
|
|
|
78
78
|
path: string;
|
|
79
79
|
value: 1 | -1;
|
|
80
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Filter configuration item
|
|
83
|
+
*/
|
|
84
|
+
type TFilterConfiguration = {
|
|
85
|
+
type: 'REGEX' | 'EXACT';
|
|
86
|
+
field?: string;
|
|
87
|
+
};
|
|
81
88
|
/**
|
|
82
89
|
* Filter configuration for automatic filtering
|
|
83
90
|
*/
|
|
84
91
|
type TFilterConfig = {
|
|
85
|
-
[key: string]:
|
|
86
|
-
type: 'REGEX' | 'EXACT';
|
|
87
|
-
field?: string;
|
|
88
|
-
};
|
|
92
|
+
[key: string]: TFilterConfiguration;
|
|
89
93
|
};
|
|
90
94
|
/**
|
|
91
95
|
* Custom filter configuration
|
|
92
96
|
* Allows defining custom filter functions for specific filter keys
|
|
97
|
+
* The value parameter can be typed by using a type assertion in the function definition
|
|
93
98
|
*/
|
|
94
99
|
type TFilterCustomConfig<T = unknown> = {
|
|
95
|
-
[id: string]: (data:
|
|
100
|
+
[id: string]: (data: any) => TMongoFilterQuery<T>;
|
|
96
101
|
};
|
|
97
102
|
/**
|
|
98
103
|
* Variant of TFilterCustomConfig that allows customizing the returned filter shape.
|
|
99
104
|
* Useful for Mongo (operator-based) vs. other ORMs (where clauses) in the future.
|
|
105
|
+
* The value parameter can be typed by using a type assertion in the function definition
|
|
100
106
|
*/
|
|
101
107
|
type TFilterCustomConfigWithFilter<TDoc = unknown, TFilter = TMongoFilterQuery<TDoc>> = {
|
|
102
|
-
[id: string]: (data:
|
|
108
|
+
[id: string]: (data: any) => TFilter;
|
|
103
109
|
};
|
|
104
110
|
/**
|
|
105
111
|
* React Data Kit server action input
|
|
@@ -265,7 +271,10 @@ type TUseDataKitOptions<T = unknown, R = unknown> = {
|
|
|
265
271
|
query?: Record<string, unknown>;
|
|
266
272
|
};
|
|
267
273
|
memory?: 'memory' | 'search-params';
|
|
268
|
-
|
|
274
|
+
filters?: {
|
|
275
|
+
id: string;
|
|
276
|
+
configuration?: TFilterConfiguration;
|
|
277
|
+
}[];
|
|
269
278
|
action: (input: TDataKitInput<T>) => Promise<TDataKitResult<R>>;
|
|
270
279
|
onSuccess?: (result: TDataKitResult<R>) => void;
|
|
271
280
|
onError?: (error: Error) => void;
|
|
@@ -379,6 +388,7 @@ type TDataKitFilterItemBase = {
|
|
|
379
388
|
id: string;
|
|
380
389
|
label: string;
|
|
381
390
|
placeholder?: string;
|
|
391
|
+
configuration?: TFilterConfiguration;
|
|
382
392
|
};
|
|
383
393
|
/**
|
|
384
394
|
* Text filter item
|
|
@@ -571,7 +581,6 @@ declare const DefaultDataKitContext: React$1.Context<TDataKitContextValue<unknow
|
|
|
571
581
|
declare const DataKit: <TAction extends (input: TDataKitInput<unknown>) => Promise<TDataKitResult<TDataKitSelectableItem>>>(props: Readonly<{
|
|
572
582
|
action: TAction;
|
|
573
583
|
query?: Record<string, unknown>;
|
|
574
|
-
filterConfig?: TFilterConfig;
|
|
575
584
|
filters?: TDataKitFilterItem[];
|
|
576
585
|
limit?: {
|
|
577
586
|
default: number;
|
package/dist/index.js
CHANGED
|
@@ -111,6 +111,7 @@ var mongooseAdapter = (model, options = {}) => {
|
|
|
111
111
|
if (filter && !customFilter) {
|
|
112
112
|
if (input.filterConfig) {
|
|
113
113
|
Object.entries(filter).forEach(([key, value]) => {
|
|
114
|
+
if (filterCustom && filterCustom[key]) return;
|
|
114
115
|
if (isProvided(value) && isSafeKey(key) && input.filterConfig?.[key]) {
|
|
115
116
|
const config = input.filterConfig[key];
|
|
116
117
|
const fieldName = config?.field ?? key;
|
|
@@ -126,6 +127,7 @@ var mongooseAdapter = (model, options = {}) => {
|
|
|
126
127
|
});
|
|
127
128
|
} else {
|
|
128
129
|
Object.entries(filter).forEach(([key, value]) => {
|
|
130
|
+
if (filterCustom && filterCustom[key]) return;
|
|
129
131
|
if (isProvided(value) && isSafeKey(key)) {
|
|
130
132
|
if (typeof value === "string") {
|
|
131
133
|
filterQuery[key] = {
|
|
@@ -222,8 +224,7 @@ async function executeDataKit(input, adapter, item, maxLimit, filterAllowed, que
|
|
|
222
224
|
}
|
|
223
225
|
async function dataKitServerAction(props) {
|
|
224
226
|
const { input, item, maxLimit = 100, queryAllowed, filterAllowed: explicitFilterAllowed, sortAllowed } = props;
|
|
225
|
-
const
|
|
226
|
-
const filterAllowed = explicitFilterAllowed ?? (filterCustom ? Object.keys(filterCustom) : void 0);
|
|
227
|
+
const filterAllowed = explicitFilterAllowed;
|
|
227
228
|
let finalAdapter;
|
|
228
229
|
if ("adapter" in props && props.adapter) {
|
|
229
230
|
finalAdapter = props.adapter;
|
|
@@ -410,7 +411,7 @@ var stateToUrlParams = (state) => {
|
|
|
410
411
|
|
|
411
412
|
// src/client/hooks/useDataKit.ts
|
|
412
413
|
var useDataKit = (props) => {
|
|
413
|
-
const { initial = {}, memory: memoryMode = "memory",
|
|
414
|
+
const { initial = {}, memory: memoryMode = "memory", filters, action, onSuccess, onError, autoFetch = true, debounce: debounceDelay = 300 } = props;
|
|
414
415
|
const { page: initialPage = 1, limit: initialLimit = 10, sorts: initialSorts = [], filter: initialFilter = {}, query: initialQuery = {} } = initial;
|
|
415
416
|
const [page, setPageState] = useState(initialPage);
|
|
416
417
|
const [limit, setLimitState] = useState(initialLimit);
|
|
@@ -428,11 +429,11 @@ var useDataKit = (props) => {
|
|
|
428
429
|
const actionRef = useRef(action);
|
|
429
430
|
const onSuccessRef = useRef(onSuccess);
|
|
430
431
|
const onErrorRef = useRef(onError);
|
|
431
|
-
const
|
|
432
|
+
const filtersRef = useRef(filters);
|
|
432
433
|
actionRef.current = action;
|
|
433
434
|
onSuccessRef.current = onSuccess;
|
|
434
435
|
onErrorRef.current = onError;
|
|
435
|
-
|
|
436
|
+
filtersRef.current = filters;
|
|
436
437
|
const getInput = useCallback(() => {
|
|
437
438
|
const input = {
|
|
438
439
|
action: "FETCH",
|
|
@@ -442,8 +443,11 @@ var useDataKit = (props) => {
|
|
|
442
443
|
filter: debouncedFilter,
|
|
443
444
|
query
|
|
444
445
|
};
|
|
445
|
-
if (
|
|
446
|
-
input.filterConfig =
|
|
446
|
+
if (filtersRef.current) {
|
|
447
|
+
input.filterConfig = filtersRef.current.reduce((acc, f) => {
|
|
448
|
+
if (f.configuration) acc[f.id] = f.configuration;
|
|
449
|
+
return acc;
|
|
450
|
+
}, {});
|
|
447
451
|
}
|
|
448
452
|
return input;
|
|
449
453
|
}, [page, limit, sorts, debouncedFilter, query]);
|
|
@@ -497,8 +501,8 @@ var useDataKit = (props) => {
|
|
|
497
501
|
setFilterState((prev) => ({ ...prev, [key]: value }));
|
|
498
502
|
setPageState(1);
|
|
499
503
|
}, []);
|
|
500
|
-
const setFilters = useCallback((
|
|
501
|
-
setFilterState((prev) => ({ ...prev, ...
|
|
504
|
+
const setFilters = useCallback((filters2) => {
|
|
505
|
+
setFilterState((prev) => ({ ...prev, ...filters2 }));
|
|
502
506
|
setPageState(1);
|
|
503
507
|
}, []);
|
|
504
508
|
const clearFilters = useCallback(() => {
|
|
@@ -592,7 +596,10 @@ var useDataKit = (props) => {
|
|
|
592
596
|
limit,
|
|
593
597
|
sorts,
|
|
594
598
|
filter,
|
|
595
|
-
filterConfig,
|
|
599
|
+
filterConfig: filters?.reduce((acc, f) => {
|
|
600
|
+
if (f.configuration) acc[f.id] = f.configuration;
|
|
601
|
+
return acc;
|
|
602
|
+
}, {}),
|
|
596
603
|
query,
|
|
597
604
|
items,
|
|
598
605
|
total,
|
|
@@ -925,7 +932,7 @@ function Switch({
|
|
|
925
932
|
{
|
|
926
933
|
"data-slot": "switch",
|
|
927
934
|
className: cn(
|
|
928
|
-
"peer data-[state=checked]:bg-
|
|
935
|
+
"peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
|
929
936
|
className
|
|
930
937
|
),
|
|
931
938
|
...props,
|
|
@@ -934,7 +941,7 @@ function Switch({
|
|
|
934
941
|
{
|
|
935
942
|
"data-slot": "switch-thumb",
|
|
936
943
|
className: cn(
|
|
937
|
-
"pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0
|
|
944
|
+
"bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0"
|
|
938
945
|
)
|
|
939
946
|
}
|
|
940
947
|
)
|
|
@@ -1232,7 +1239,6 @@ var DataKitRoot = (props) => {
|
|
|
1232
1239
|
const {
|
|
1233
1240
|
action,
|
|
1234
1241
|
query,
|
|
1235
|
-
filterConfig,
|
|
1236
1242
|
table: columns,
|
|
1237
1243
|
filters = [],
|
|
1238
1244
|
selectable,
|
|
@@ -1269,7 +1275,7 @@ var DataKitRoot = (props) => {
|
|
|
1269
1275
|
}, [initialState]);
|
|
1270
1276
|
const dataKit = useDataKit({
|
|
1271
1277
|
action,
|
|
1272
|
-
|
|
1278
|
+
filters,
|
|
1273
1279
|
autoFetch,
|
|
1274
1280
|
debounce: debounce2,
|
|
1275
1281
|
memory: memoryMode,
|
|
@@ -1493,18 +1499,20 @@ var DataKitRoot = (props) => {
|
|
|
1493
1499
|
] }, rowId);
|
|
1494
1500
|
}) })
|
|
1495
1501
|
] }) }),
|
|
1496
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1497
|
-
/* @__PURE__ */ jsxs("
|
|
1498
|
-
"
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1502
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4", children: [
|
|
1503
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-[140px]", children: [
|
|
1504
|
+
/* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground", children: [
|
|
1505
|
+
"Page ",
|
|
1506
|
+
dataKit.page,
|
|
1507
|
+
" of ",
|
|
1508
|
+
pagination.totalPages
|
|
1509
|
+
] }),
|
|
1510
|
+
selectable?.enabled && selectedCount > 0 && /* @__PURE__ */ jsxs("p", { className: "text-sm text-foreground", children: [
|
|
1504
1511
|
selectedCount,
|
|
1505
|
-
" selected
|
|
1512
|
+
" selected"
|
|
1506
1513
|
] })
|
|
1507
1514
|
] }),
|
|
1515
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1" }),
|
|
1508
1516
|
paginationType === "SIMPLE" ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
1509
1517
|
/* @__PURE__ */ jsx(
|
|
1510
1518
|
Button,
|
|
@@ -1579,7 +1587,6 @@ var DataKitInner = (props, ref) => {
|
|
|
1579
1587
|
const {
|
|
1580
1588
|
action,
|
|
1581
1589
|
query,
|
|
1582
|
-
filterConfig,
|
|
1583
1590
|
filters = [],
|
|
1584
1591
|
limit: limitConfig,
|
|
1585
1592
|
defaultSort = [],
|
|
@@ -1599,7 +1606,7 @@ var DataKitInner = (props, ref) => {
|
|
|
1599
1606
|
const overlayContainer = containerRef.current;
|
|
1600
1607
|
const dataKit = useDataKit({
|
|
1601
1608
|
action,
|
|
1602
|
-
|
|
1609
|
+
filters,
|
|
1603
1610
|
autoFetch,
|
|
1604
1611
|
debounce: debounce2,
|
|
1605
1612
|
memory: memoryMode,
|