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.
Files changed (43) hide show
  1. package/README.md +16 -2
  2. package/dist/{action-pIfOi9UC.d.cts → action-DdkPkUFP.d.cts} +13 -7
  3. package/dist/{action-pIfOi9UC.d.ts → action-DdkPkUFP.d.ts} +13 -7
  4. package/dist/client/components/data-kit-infinity.d.ts +1 -2
  5. package/dist/client/components/data-kit-infinity.d.ts.map +1 -1
  6. package/dist/client/components/data-kit-infinity.js +2 -2
  7. package/dist/client/components/data-kit-infinity.js.map +1 -1
  8. package/dist/client/components/data-kit-table.d.ts +1 -2
  9. package/dist/client/components/data-kit-table.d.ts.map +1 -1
  10. package/dist/client/components/data-kit-table.js +3 -3
  11. package/dist/client/components/data-kit-table.js.map +1 -1
  12. package/dist/client/components/data-kit.d.ts +1 -2
  13. package/dist/client/components/data-kit.d.ts.map +1 -1
  14. package/dist/client/components/data-kit.js +2 -2
  15. package/dist/client/components/data-kit.js.map +1 -1
  16. package/dist/client/components/ui/switch.d.ts +2 -2
  17. package/dist/client/components/ui/switch.d.ts.map +1 -1
  18. package/dist/client/components/ui/switch.js +4 -4
  19. package/dist/client/components/ui/switch.js.map +1 -1
  20. package/dist/client/hooks/useDataKit.d.ts.map +1 -1
  21. package/dist/client/hooks/useDataKit.js +14 -6
  22. package/dist/client/hooks/useDataKit.js.map +1 -1
  23. package/dist/index.cjs +32 -25
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +17 -8
  26. package/dist/index.d.ts +17 -8
  27. package/dist/index.js +32 -25
  28. package/dist/index.js.map +1 -1
  29. package/dist/server.cjs +3 -2
  30. package/dist/server.cjs.map +1 -1
  31. package/dist/server.d.cts +2 -2
  32. package/dist/server.d.ts +2 -2
  33. package/dist/server.js +3 -2
  34. package/dist/server.js.map +1 -1
  35. package/dist/types/client/component.d.ts +2 -1
  36. package/dist/types/client/component.d.ts.map +1 -1
  37. package/dist/types/client/hook.d.ts +5 -2
  38. package/dist/types/client/hook.d.ts.map +1 -1
  39. package/dist/types/index.d.cts +7 -3
  40. package/dist/types/next-data-kit.d.ts +12 -6
  41. package/dist/types/next-data-kit.d.ts.map +1 -1
  42. package/dist/types/server/action.d.ts.map +1 -1
  43. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -137,6 +137,7 @@ var mongooseAdapter = (model, options = {}) => {
137
137
  if (filter && !customFilter) {
138
138
  if (input.filterConfig) {
139
139
  Object.entries(filter).forEach(([key, value]) => {
140
+ if (filterCustom && filterCustom[key]) return;
140
141
  if (isProvided(value) && isSafeKey(key) && input.filterConfig?.[key]) {
141
142
  const config = input.filterConfig[key];
142
143
  const fieldName = config?.field ?? key;
@@ -152,6 +153,7 @@ var mongooseAdapter = (model, options = {}) => {
152
153
  });
153
154
  } else {
154
155
  Object.entries(filter).forEach(([key, value]) => {
156
+ if (filterCustom && filterCustom[key]) return;
155
157
  if (isProvided(value) && isSafeKey(key)) {
156
158
  if (typeof value === "string") {
157
159
  filterQuery[key] = {
@@ -248,8 +250,7 @@ async function executeDataKit(input, adapter, item, maxLimit, filterAllowed, que
248
250
  }
249
251
  async function dataKitServerAction(props) {
250
252
  const { input, item, maxLimit = 100, queryAllowed, filterAllowed: explicitFilterAllowed, sortAllowed } = props;
251
- const filterCustom = "filterCustom" in props ? props.filterCustom : void 0;
252
- const filterAllowed = explicitFilterAllowed ?? (filterCustom ? Object.keys(filterCustom) : void 0);
253
+ const filterAllowed = explicitFilterAllowed;
253
254
  let finalAdapter;
254
255
  if ("adapter" in props && props.adapter) {
255
256
  finalAdapter = props.adapter;
@@ -436,7 +437,7 @@ var stateToUrlParams = (state) => {
436
437
 
437
438
  // src/client/hooks/useDataKit.ts
438
439
  var useDataKit = (props) => {
439
- const { initial = {}, memory: memoryMode = "memory", filterConfig, action, onSuccess, onError, autoFetch = true, debounce: debounceDelay = 300 } = props;
440
+ const { initial = {}, memory: memoryMode = "memory", filters, action, onSuccess, onError, autoFetch = true, debounce: debounceDelay = 300 } = props;
440
441
  const { page: initialPage = 1, limit: initialLimit = 10, sorts: initialSorts = [], filter: initialFilter = {}, query: initialQuery = {} } = initial;
441
442
  const [page, setPageState] = React2.useState(initialPage);
442
443
  const [limit, setLimitState] = React2.useState(initialLimit);
@@ -454,11 +455,11 @@ var useDataKit = (props) => {
454
455
  const actionRef = React2.useRef(action);
455
456
  const onSuccessRef = React2.useRef(onSuccess);
456
457
  const onErrorRef = React2.useRef(onError);
457
- const filterConfigRef = React2.useRef(filterConfig);
458
+ const filtersRef = React2.useRef(filters);
458
459
  actionRef.current = action;
459
460
  onSuccessRef.current = onSuccess;
460
461
  onErrorRef.current = onError;
461
- filterConfigRef.current = filterConfig;
462
+ filtersRef.current = filters;
462
463
  const getInput = React2.useCallback(() => {
463
464
  const input = {
464
465
  action: "FETCH",
@@ -468,8 +469,11 @@ var useDataKit = (props) => {
468
469
  filter: debouncedFilter,
469
470
  query
470
471
  };
471
- if (filterConfigRef.current) {
472
- input.filterConfig = filterConfigRef.current;
472
+ if (filtersRef.current) {
473
+ input.filterConfig = filtersRef.current.reduce((acc, f) => {
474
+ if (f.configuration) acc[f.id] = f.configuration;
475
+ return acc;
476
+ }, {});
473
477
  }
474
478
  return input;
475
479
  }, [page, limit, sorts, debouncedFilter, query]);
@@ -523,8 +527,8 @@ var useDataKit = (props) => {
523
527
  setFilterState((prev) => ({ ...prev, [key]: value }));
524
528
  setPageState(1);
525
529
  }, []);
526
- const setFilters = React2.useCallback((filters) => {
527
- setFilterState((prev) => ({ ...prev, ...filters }));
530
+ const setFilters = React2.useCallback((filters2) => {
531
+ setFilterState((prev) => ({ ...prev, ...filters2 }));
528
532
  setPageState(1);
529
533
  }, []);
530
534
  const clearFilters = React2.useCallback(() => {
@@ -618,7 +622,10 @@ var useDataKit = (props) => {
618
622
  limit,
619
623
  sorts,
620
624
  filter,
621
- filterConfig,
625
+ filterConfig: filters?.reduce((acc, f) => {
626
+ if (f.configuration) acc[f.id] = f.configuration;
627
+ return acc;
628
+ }, {}),
622
629
  query,
623
630
  items,
624
631
  total,
@@ -951,7 +958,7 @@ function Switch({
951
958
  {
952
959
  "data-slot": "switch",
953
960
  className: cn(
954
- "peer data-[state=checked]:bg-gray-900 data-[state=unchecked]:bg-gray-200 dark:data-[state=checked]:bg-gray-100 dark:data-[state=unchecked]:bg-gray-800 focus-visible:ring-black/20 dark:focus-visible:ring-white/20 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",
961
+ "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",
955
962
  className
956
963
  ),
957
964
  ...props,
@@ -960,7 +967,7 @@ function Switch({
960
967
  {
961
968
  "data-slot": "switch-thumb",
962
969
  className: cn(
963
- "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 bg-white dark:data-[state=unchecked]:bg-gray-100 dark:data-[state=checked]:bg-gray-900"
970
+ "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"
964
971
  )
965
972
  }
966
973
  )
@@ -1258,7 +1265,6 @@ var DataKitRoot = (props) => {
1258
1265
  const {
1259
1266
  action,
1260
1267
  query,
1261
- filterConfig,
1262
1268
  table: columns,
1263
1269
  filters = [],
1264
1270
  selectable,
@@ -1295,7 +1301,7 @@ var DataKitRoot = (props) => {
1295
1301
  }, [initialState]);
1296
1302
  const dataKit = useDataKit({
1297
1303
  action,
1298
- filterConfig,
1304
+ filters,
1299
1305
  autoFetch,
1300
1306
  debounce: debounce2,
1301
1307
  memory: memoryMode,
@@ -1519,18 +1525,20 @@ var DataKitRoot = (props) => {
1519
1525
  ] }, rowId);
1520
1526
  }) })
1521
1527
  ] }) }),
1522
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
1523
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-muted-foreground", children: [
1524
- "Page ",
1525
- dataKit.page,
1526
- " of ",
1527
- pagination.totalPages,
1528
- selectable?.enabled && selectedCount > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-2 text-foreground", children: [
1529
- "(",
1528
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-4", children: [
1529
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-[140px]", children: [
1530
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-muted-foreground", children: [
1531
+ "Page ",
1532
+ dataKit.page,
1533
+ " of ",
1534
+ pagination.totalPages
1535
+ ] }),
1536
+ selectable?.enabled && selectedCount > 0 && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-foreground", children: [
1530
1537
  selectedCount,
1531
- " selected)"
1538
+ " selected"
1532
1539
  ] })
1533
1540
  ] }),
1541
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1" }),
1534
1542
  paginationType === "SIMPLE" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1", children: [
1535
1543
  /* @__PURE__ */ jsxRuntime.jsx(
1536
1544
  Button,
@@ -1605,7 +1613,6 @@ var DataKitInner = (props, ref) => {
1605
1613
  const {
1606
1614
  action,
1607
1615
  query,
1608
- filterConfig,
1609
1616
  filters = [],
1610
1617
  limit: limitConfig,
1611
1618
  defaultSort = [],
@@ -1625,7 +1632,7 @@ var DataKitInner = (props, ref) => {
1625
1632
  const overlayContainer = containerRef.current;
1626
1633
  const dataKit = useDataKit({
1627
1634
  action,
1628
- filterConfig,
1635
+ filters,
1629
1636
  autoFetch,
1630
1637
  debounce: debounce2,
1631
1638
  memory: memoryMode,