@krosoft/react 0.0.97 → 0.0.98

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 (57) hide show
  1. package/dist/{AppSubTitle-Bc8utqt7.js → AppSubTitle-Bt3_01sd.js} +1 -1
  2. package/dist/{AppTitle-QlMMlpbQ.js → AppTitle-cR9yMcWN.js} +6 -6
  3. package/dist/{AppVerticalTabs--Kb9OFa4.js → AppVerticalTabs-Br5Y27x2.js} +5 -5
  4. package/dist/{ConfirmationDialog-Bv-O4ui4.js → ConfirmationDialog-Bhboi93k.js} +6 -6
  5. package/dist/{DataTable-DWGao3TY.js → DataTable-7kgRjvT3.js} +229 -213
  6. package/dist/{ErrorAlert-DpOsMww8.js → ErrorAlert-D1laKrGq.js} +2 -2
  7. package/dist/{LoadingState-M_TV_5Ui.js → LoadingState-DiBl13bH.js} +1 -1
  8. package/dist/{MetricCard-BjTGW3b2.js → MetricCard-5xmlrXzH.js} +5 -5
  9. package/dist/{SearchInput-CKG1_3iS.js → SearchInput-CcCFcweT.js} +6 -6
  10. package/dist/{TableFilter-oBrNz-v_.js → TableFilter-Dd9SvVEF.js} +8 -8
  11. package/dist/{ThemeSelector-Bzxc7UEq.js → ThemeSelector-Cl2EWB-n.js} +3 -3
  12. package/dist/{Topbar-QKCJiWdO.js → Topbar-6UWKhkXJ.js} +3 -3
  13. package/dist/{alert-sHZy6NHC.js → alert-srKINZRG.js} +2 -2
  14. package/dist/{badge-C09fRxvd.js → badge-BmjaQmQ3.js} +2 -2
  15. package/dist/components/core/cards/index.js +1 -1
  16. package/dist/components/core/dialogs/index.js +2 -2
  17. package/dist/components/core/filters/index.js +1 -1
  18. package/dist/components/core/index.js +13 -13
  19. package/dist/components/core/inputs/index.js +1 -1
  20. package/dist/components/core/layouts/index.js +2 -2
  21. package/dist/components/core/navbar/index.js +1 -1
  22. package/dist/components/core/states/index.js +2 -2
  23. package/dist/components/core/table/DataTable.d.ts +9 -1
  24. package/dist/components/core/table/DataTable.d.ts.map +1 -1
  25. package/dist/components/core/table/index.js +1 -1
  26. package/dist/components/core/tabs/index.js +1 -1
  27. package/dist/components/core/theme/index.js +1 -1
  28. package/dist/components/index.js +18 -18
  29. package/dist/components/ui/button.d.ts +1 -1
  30. package/dist/components/ui/index.js +6 -6
  31. package/dist/{ellipsis-vertical-BVxSFNOa.js → ellipsis-vertical-DHhj4CGv.js} +1 -1
  32. package/dist/{grip-vertical-CJ07_87Y.js → grip-vertical-PGZER0-H.js} +1 -1
  33. package/dist/helpers/index.d.ts +1 -0
  34. package/dist/helpers/index.d.ts.map +1 -1
  35. package/dist/helpers/index.js +47 -2
  36. package/dist/helpers/supabase.helper.d.ts +75 -0
  37. package/dist/helpers/supabase.helper.d.ts.map +1 -0
  38. package/dist/hooks/index.d.ts +1 -0
  39. package/dist/hooks/index.d.ts.map +1 -1
  40. package/dist/hooks/index.js +46 -10
  41. package/dist/hooks/ui/useDataTable.d.ts +1 -1
  42. package/dist/hooks/ui/useDataTable.d.ts.map +1 -1
  43. package/dist/hooks/ui/useServerTable.d.ts +22 -0
  44. package/dist/hooks/ui/useServerTable.d.ts.map +1 -0
  45. package/dist/{index-DSyPHOLE.js → index-BSI9LuBZ.js} +1 -1
  46. package/dist/{loader-circle-GAYBtm3z.js → loader-circle-DEbczXZA.js} +1 -1
  47. package/dist/{select-zzSnHs9S.js → select-CDIMkakd.js} +3 -3
  48. package/dist/{toaster-B09ou5gw.js → toaster-Cz2Lbp2C.js} +4 -4
  49. package/dist/{toggle-group-iLf3T7oV.js → toggle-group-pAjKlGGO.js} +4 -4
  50. package/dist/{tooltip-CAu4DEhc.js → tooltip-mWS3Mix6.js} +2 -2
  51. package/dist/types/UseDataTableProps.d.ts +8 -0
  52. package/dist/types/UseDataTableProps.d.ts.map +1 -1
  53. package/dist/useDataTable-CxcA5S-s.js +126 -0
  54. package/dist/{useTheme-Bn8z_uxy.js → useTheme-BtR4Ahrp.js} +2 -2
  55. package/package.json +1 -1
  56. package/dist/useDataTable-CQpx3zTg.js +0 -91
  57. /package/dist/{index-gWiv5-6R.js → tailwind.helper-gWiv5-6R.js} +0 -0
@@ -0,0 +1,22 @@
1
+ export interface UseServerTableResult<TFilters> {
2
+ currentPage: number;
3
+ onPageChange: React.Dispatch<React.SetStateAction<number>>;
4
+ pageSize: number;
5
+ onPageSizeChange: (size: number) => void;
6
+ sortColumn: string | null;
7
+ sortDirection: "asc" | "desc";
8
+ onSortChange: (col: string | null, dir: "asc" | "desc") => void;
9
+ searchText: string;
10
+ debouncedSearchText: string;
11
+ onSearchChange: (text: string) => void;
12
+ appliedFilters: TFilters;
13
+ onFiltersChange: (filters: TFilters) => void;
14
+ }
15
+ export declare function useServerTable<TFilters>(initialFilters: TFilters, initialSortColumn?: string | null, options?: {
16
+ initialSortDirection?: "asc" | "desc";
17
+ initialSearchText?: string;
18
+ initialPage?: number;
19
+ initialPageSize?: number;
20
+ debounceMs?: number;
21
+ }): UseServerTableResult<TFilters>;
22
+ //# sourceMappingURL=useServerTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useServerTable.d.ts","sourceRoot":"","sources":["../../../src/hooks/ui/useServerTable.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB,CAAC,QAAQ;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,KAAK,GAAG,MAAM,CAAC;IAC9B,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,MAAM,KAAK,IAAI,CAAC;IAChE,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,cAAc,EAAE,QAAQ,CAAC;IACzB,eAAe,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC9C;AAED,wBAAgB,cAAc,CAAC,QAAQ,EACrC,cAAc,EAAE,QAAQ,EACxB,iBAAiB,GAAE,MAAM,GAAG,IAAY,EACxC,OAAO,GAAE;IACP,oBAAoB,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACtC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CAChB,GACL,oBAAoB,CAAC,QAAQ,CAAC,CAqDhC"}
@@ -1,5 +1,5 @@
1
1
  import { useContext as W, createContext as g, forwardRef as A, createElement as k } from "react";
2
- import { a as L } from "./index-gWiv5-6R.js";
2
+ import { a as L } from "./tailwind.helper-gWiv5-6R.js";
3
3
  /**
4
4
  * @license lucide-react v1.16.0 - ISC
5
5
  *
@@ -1,4 +1,4 @@
1
- import { c } from "./index-DSyPHOLE.js";
1
+ import { c } from "./index-BSI9LuBZ.js";
2
2
  /**
3
3
  * @license lucide-react v1.16.0 - ISC
4
4
  *
@@ -1,11 +1,11 @@
1
1
  import { jsx as v, jsxs as q, Fragment as Ge } from "react/jsx-runtime";
2
- import { c as Q } from "./index-gWiv5-6R.js";
2
+ import { c as Q } from "./tailwind.helper-gWiv5-6R.js";
3
3
  import * as a from "react";
4
4
  import re, { useState as fn } from "react";
5
5
  import * as ut from "react-dom";
6
6
  import pn from "react-dom";
7
- import { f as dt, g as ft, u as B, h as We, P as A, i as G, A as mn, j as M, k as Ye, l as pt, D as vn, m as hn, n as qe, R as gn, V as Sn, o as yn, C as mt } from "./tooltip-CAu4DEhc.js";
8
- import { c as Xe } from "./index-DSyPHOLE.js";
7
+ import { f as dt, g as ft, u as B, h as We, P as A, i as G, A as mn, j as M, k as Ye, l as pt, D as vn, m as hn, n as qe, R as gn, V as Sn, o as yn, C as mt } from "./tooltip-mWS3Mix6.js";
8
+ import { c as Xe } from "./index-BSI9LuBZ.js";
9
9
  // @__NO_SIDE_EFFECTS__
10
10
  function Qe(e) {
11
11
  const t = /* @__PURE__ */ wn(e), n = a.forwardRef((r, o) => {
@@ -1,10 +1,10 @@
1
1
  import * as c from "react";
2
2
  import "react-dom";
3
- import { e as m } from "./tooltip-CAu4DEhc.js";
3
+ import { e as m } from "./tooltip-mWS3Mix6.js";
4
4
  import { jsx as a, jsxs as l } from "react/jsx-runtime";
5
- import { cf as g, cg as v, ch as b, ci as h, cj as w, ck as x, cl as y, c4 as T, c0 as N, c5 as R, c3 as C, c2 as $, c6 as P } from "./toggle-group-iLf3T7oV.js";
6
- import { c as n } from "./index-gWiv5-6R.js";
7
- import { G as S } from "./grip-vertical-CJ07_87Y.js";
5
+ import { cf as g, cg as v, ch as b, ci as h, cj as w, ck as x, cl as y, c4 as T, c0 as N, c5 as R, c3 as C, c2 as $, c6 as P } from "./toggle-group-pAjKlGGO.js";
6
+ import { c as n } from "./tailwind.helper-gWiv5-6R.js";
7
+ import { G as S } from "./grip-vertical-PGZER0-H.js";
8
8
  import { useTheme as j } from "next-themes";
9
9
  import { u as A } from "./useToast-BFTk4lWz.js";
10
10
  var z = [
@@ -6,12 +6,12 @@ var dn = (e, t, r) => (af(e, t, "read from private field"), r ? r.call(e) : t.ge
6
6
  import { jsx as m, jsxs as ce, Fragment as Mt } from "react/jsx-runtime";
7
7
  import * as f from "react";
8
8
  import E, { createContext as qv, useContext as Wv, useCallback as et, useRef as Xe, useLayoutEffect as Qc, useState as qt, useEffect as Wt, useMemo as br, isValidElement as Po, PureComponent as ea, forwardRef as zv, useImperativeHandle as Jc, cloneElement as __, useSyncExternalStore as E_, useId as P_ } from "react";
9
- import { c as I, a as wr } from "./index-gWiv5-6R.js";
10
- import { n as Ae, P as Z, k as De, j as q, p as Ie, g as ze, u as ue, i as Qt, C as jv, f as Tt, q as R_, D as zn, d as Gr, e as ta, h as Me, S as Hv, B as Gv, r as ra, l as on, A as na, m as eu, s as Oo, R as oa, o as tu, t as M_, v as T_, w as Vv, x as N_ } from "./tooltip-CAu4DEhc.js";
11
- import { j as cr, u as zt, P as aa, R as ru, k as nu, l as ou, F as au, m as jn, C as ia, X as iu, n as su } from "./select-zzSnHs9S.js";
9
+ import { c as I, a as wr } from "./tailwind.helper-gWiv5-6R.js";
10
+ import { n as Ae, P as Z, k as De, j as q, p as Ie, g as ze, u as ue, i as Qt, C as jv, f as Tt, q as R_, D as zn, d as Gr, e as ta, h as Me, S as Hv, B as Gv, r as ra, l as on, A as na, m as eu, s as Oo, R as oa, o as tu, t as M_, v as T_, w as Vv, x as N_ } from "./tooltip-mWS3Mix6.js";
11
+ import { j as cr, u as zt, P as aa, R as ru, k as nu, l as ou, F as au, m as jn, C as ia, X as iu, n as su } from "./select-CDIMkakd.js";
12
12
  import * as O_ from "react-dom";
13
13
  import Yv from "react-dom";
14
- import { c as ur, a as Hn } from "./index-DSyPHOLE.js";
14
+ import { c as ur, a as Hn } from "./index-BSI9LuBZ.js";
15
15
  const D_ = f.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ m("div", { ref: r, className: I("rounded-lg border bg-card text-card-foreground shadow-sm", e), ...t }));
16
16
  D_.displayName = "Card";
17
17
  const A_ = f.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ m("div", { ref: r, className: I("flex flex-col space-y-1.5 p-6", e), ...t }));
@@ -1,6 +1,6 @@
1
- import { c as dn, a as pn } from "./index-DSyPHOLE.js";
1
+ import { c as dn, a as pn } from "./index-BSI9LuBZ.js";
2
2
  import { jsx as P, Fragment as mn, jsxs as hn } from "react/jsx-runtime";
3
- import { c as yt } from "./index-gWiv5-6R.js";
3
+ import { c as yt } from "./tailwind.helper-gWiv5-6R.js";
4
4
  import * as l from "react";
5
5
  import { useLayoutEffect as gn } from "react";
6
6
  import * as vt from "react-dom";
@@ -9,5 +9,13 @@ export interface UseDataTableProps<T> {
9
9
  actions?: RowAction<T>[];
10
10
  bulkActions?: BulkAction[];
11
11
  columnVisibility?: boolean;
12
+ totalRows?: number;
13
+ currentPage?: number;
14
+ pageSize?: number;
15
+ onPageChange?: (page: number) => void;
16
+ onPageSizeChange?: (pageSize: number) => void;
17
+ sortColumn?: string | null;
18
+ sortDirection?: "asc" | "desc";
19
+ onSortChange?: (column: string | null, direction: "asc" | "desc") => void;
12
20
  }
13
21
  //# sourceMappingURL=UseDataTableProps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UseDataTableProps.d.ts","sourceRoot":"","sources":["../../src/types/UseDataTableProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B"}
1
+ {"version":3,"file":"UseDataTableProps.d.ts","sourceRoot":"","sources":["../../src/types/UseDataTableProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAG3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAG9C,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC/B,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,SAAS,EAAE,KAAK,GAAG,MAAM,KAAK,IAAI,CAAC;CAC3E"}
@@ -0,0 +1,126 @@
1
+ import { useState as c, useRef as g, useMemo as M, useCallback as u } from "react";
2
+ function Ve({
3
+ data: l,
4
+ columns: o,
5
+ getRowId: Y,
6
+ defaultPageSize: Z,
7
+ actions: E,
8
+ bulkActions: I,
9
+ columnVisibility: _ = !0,
10
+ totalRows: p,
11
+ currentPage: $,
12
+ pageSize: K,
13
+ onPageChange: V,
14
+ onPageSizeChange: k,
15
+ sortColumn: T,
16
+ sortDirection: ee,
17
+ onSortChange: h
18
+ }) {
19
+ var Q;
20
+ const [te, ne] = c(((Q = o.find((e) => e.sortable === !0)) == null ? void 0 : Q.key) ?? null), i = T !== void 0 ? T : te, [re, se] = c("asc"), a = ee ?? re, [m, v] = c([]), [x, oe] = c(new Set(o.filter((e) => e.defaultVisible !== !1).map((e) => e.key))), [L, le] = c(o.map((e) => e.key)), [w, ie] = c(o.reduce((e, t) => ({ ...e, [t.key]: t.minWidth ?? 100 }), {})), [ce, R] = c(1), S = $ ?? ce, [ue, ae] = c(Z), d = K ?? ue, de = g(null), y = g(null), X = g(0), U = g(0), f = g(null), B = g(null), F = E !== void 0 && E.length > 0, j = I !== void 0 && I.length > 0, z = M(() => L.map((e) => o.find((t) => t.key === e)).filter((e) => e !== void 0), [L, o]), q = M(() => z.filter((e) => x.has(e.key)), [z, x]), fe = q.length + (j ? 1 : 0) + (F || _ ? 1 : 0), G = p ?? l.length, O = Math.max(1, Math.ceil(G / d)), H = S > O ? O : S, C = G === 0 ? 0 : (H - 1) * d, W = p !== void 0 ? Math.min(C + l.length, p) : Math.min(C + d, l.length), D = u(
21
+ (e) => {
22
+ V ? V(e) : R(e);
23
+ },
24
+ [V]
25
+ ), J = u(
26
+ (e) => {
27
+ k ? k(e) : (ae(e), R(1));
28
+ },
29
+ [k]
30
+ ), ge = u(
31
+ (e) => {
32
+ const t = typeof e == "function" ? e(S) : e;
33
+ D(t);
34
+ },
35
+ [S, D]
36
+ ), pe = u(
37
+ (e) => {
38
+ const t = typeof e == "function" ? e(d) : e;
39
+ J(t);
40
+ },
41
+ [d, J]
42
+ ), he = u(
43
+ (e) => {
44
+ const t = o.find((r) => r.key === e);
45
+ if ((t == null ? void 0 : t.sortable) !== !0) return;
46
+ let n = "asc";
47
+ i === e && (n = a === "asc" ? "desc" : "asc"), h ? h(e, n) : (ne(e), se(n), D(1));
48
+ },
49
+ [o, i, a, h, D]
50
+ ), P = u((e) => {
51
+ const t = y.current;
52
+ if (t === null) return;
53
+ const n = e.clientX - X.current, r = Math.max(80, U.current + n);
54
+ ie((s) => ({
55
+ ...s,
56
+ [t]: r
57
+ }));
58
+ }, []), N = u(
59
+ function e() {
60
+ y.current = null, document.removeEventListener("mousemove", P), document.removeEventListener("mouseup", e);
61
+ },
62
+ [P]
63
+ ), me = u(
64
+ (e, t) => {
65
+ e.preventDefault(), e.stopPropagation(), y.current = t, X.current = e.clientX, U.current = w[t], document.addEventListener("mousemove", P), document.addEventListener("mouseup", N);
66
+ },
67
+ [w, P, N]
68
+ ), ve = (e, t) => {
69
+ f.current = t, e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/html", t);
70
+ }, Se = (e, t) => {
71
+ e.preventDefault(), e.dataTransfer.dropEffect = "move", B.current = t;
72
+ }, Ce = (e, t) => {
73
+ if (e.preventDefault(), f.current === null || f.current === t) return;
74
+ const n = [...L], r = n.indexOf(f.current), s = n.indexOf(t);
75
+ n.splice(r, 1), n.splice(s, 0, f.current), le(n), f.current = null, B.current = null;
76
+ }, A = M(() => h !== void 0 ? l : [...l].sort((e, t) => {
77
+ if (i === null) return 0;
78
+ const n = o.find((b) => b.key === i), r = (n == null ? void 0 : n.getSortValue) !== void 0 ? n.getSortValue(e) : e[i], s = (n == null ? void 0 : n.getSortValue) !== void 0 ? n.getSortValue(t) : t[i];
79
+ if (typeof r == "string" && typeof s == "string") {
80
+ const b = r.localeCompare(s);
81
+ return a === "asc" ? b : -b;
82
+ }
83
+ return r === s ? 0 : r == null ? 1 : s == null ? -1 : r < s ? a === "asc" ? -1 : 1 : r > s ? a === "asc" ? 1 : -1 : 0;
84
+ }), [l, i, a, o, h]), xe = M(() => p !== void 0 ? A : A.slice(C, W), [A, C, W, p]);
85
+ return {
86
+ sortColumn: i,
87
+ sortDirection: a,
88
+ selectedRows: m,
89
+ setSelectedRows: v,
90
+ visibleColumns: x,
91
+ columnWidths: w,
92
+ currentPage: S,
93
+ setCurrentPage: ge,
94
+ pageSize: d,
95
+ setPageSize: pe,
96
+ totalPages: O,
97
+ safeCurrentPage: H,
98
+ startIndex: C,
99
+ endIndex: W,
100
+ tableRef: de,
101
+ hasActions: F,
102
+ hasBulkActions: j,
103
+ orderedColumns: z,
104
+ visibleColumnsArray: q,
105
+ colSpanCount: fe,
106
+ paginatedData: xe,
107
+ handleSort: he,
108
+ handleMouseDown: me,
109
+ handleDragStart: ve,
110
+ handleDragOver: Se,
111
+ handleDrop: Ce,
112
+ toggleColumnVisibility: (e) => {
113
+ const t = new Set(x);
114
+ t.has(e) ? t.delete(e) : t.add(e), oe(t);
115
+ },
116
+ toggleRowSelection: (e) => {
117
+ m.includes(e) ? v(m.filter((t) => t !== e)) : v([...m, e]);
118
+ },
119
+ toggleSelectAll: () => {
120
+ m.length === l.length ? v([]) : v(l.map((e) => Y(e)));
121
+ }
122
+ };
123
+ }
124
+ export {
125
+ Ve as u
126
+ };
@@ -26,6 +26,6 @@ function g(e) {
26
26
  };
27
27
  }
28
28
  export {
29
- g as a,
30
- T as u
29
+ T as a,
30
+ g as u
31
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krosoft/react",
3
- "version": "0.0.97",
3
+ "version": "0.0.98",
4
4
  "description": "Krosoft shared React package",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,91 +0,0 @@
1
- import { useState as l, useRef as d, useMemo as S, useCallback as O } from "react";
2
- function ue({
3
- data: i,
4
- columns: o,
5
- getRowId: j,
6
- defaultPageSize: q,
7
- actions: R,
8
- bulkActions: y,
9
- columnVisibility: G = !0
10
- }) {
11
- var F;
12
- const [u, H] = l(((F = o.find((e) => e.sortable === !0)) == null ? void 0 : F.key) ?? null), [c, P] = l("asc"), [g, f] = l([]), [h, J] = l(new Set(o.filter((e) => e.defaultVisible !== !1).map((e) => e.key))), [b, N] = l(o.map((e) => e.key)), [w, Q] = l(o.reduce((e, t) => ({ ...e, [t.key]: t.minWidth ?? 100 }), {})), [V, A] = l(1), [m, Y] = l(q), Z = d(null), x = d(null), E = d(0), W = d(0), a = d(null), z = d(null), I = R !== void 0 && R.length > 0, L = y !== void 0 && y.length > 0, M = S(() => b.map((e) => o.find((t) => t.key === e)).filter((e) => e !== void 0), [b, o]), T = S(() => M.filter((e) => h.has(e.key)), [M, h]), _ = T.length + (L ? 1 : 0) + (I || G ? 1 : 0), k = Math.max(1, Math.ceil(i.length / m)), X = V > k ? k : V, p = i.length === 0 ? 0 : (X - 1) * m, D = Math.min(p + m, i.length), $ = (e) => {
13
- const t = o.find((n) => n.key === e);
14
- (t == null ? void 0 : t.sortable) === !0 && (u === e ? P(c === "asc" ? "desc" : "asc") : (H(e), P("asc")), A(1));
15
- }, v = O((e) => {
16
- const t = x.current;
17
- if (t === null) return;
18
- const n = e.clientX - E.current, r = Math.max(80, W.current + n);
19
- Q((s) => ({
20
- ...s,
21
- [t]: r
22
- }));
23
- }, []), U = O(
24
- function e() {
25
- x.current = null, document.removeEventListener("mousemove", v), document.removeEventListener("mouseup", e);
26
- },
27
- [v]
28
- ), K = O(
29
- (e, t) => {
30
- e.preventDefault(), e.stopPropagation(), x.current = t, E.current = e.clientX, W.current = w[t], document.addEventListener("mousemove", v), document.addEventListener("mouseup", U);
31
- },
32
- [w, v, U]
33
- ), ee = (e, t) => {
34
- a.current = t, e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/html", t);
35
- }, te = (e, t) => {
36
- e.preventDefault(), e.dataTransfer.dropEffect = "move", z.current = t;
37
- }, ne = (e, t) => {
38
- if (e.preventDefault(), a.current === null || a.current === t) return;
39
- const n = [...b], r = n.indexOf(a.current), s = n.indexOf(t);
40
- n.splice(r, 1), n.splice(s, 0, a.current), N(n), a.current = null, z.current = null;
41
- }, B = S(() => [...i].sort((e, t) => {
42
- if (u === null) return 0;
43
- const n = o.find((C) => C.key === u), r = (n == null ? void 0 : n.getSortValue) !== void 0 ? n.getSortValue(e) : e[u], s = (n == null ? void 0 : n.getSortValue) !== void 0 ? n.getSortValue(t) : t[u];
44
- if (typeof r == "string" && typeof s == "string") {
45
- const C = r.localeCompare(s);
46
- return c === "asc" ? C : -C;
47
- }
48
- return r === s ? 0 : r == null ? 1 : s == null ? -1 : r < s ? c === "asc" ? -1 : 1 : r > s ? c === "asc" ? 1 : -1 : 0;
49
- }), [i, u, c, o]), re = S(() => B.slice(p, D), [B, p, D]);
50
- return {
51
- sortColumn: u,
52
- sortDirection: c,
53
- selectedRows: g,
54
- setSelectedRows: f,
55
- visibleColumns: h,
56
- columnWidths: w,
57
- currentPage: V,
58
- setCurrentPage: A,
59
- pageSize: m,
60
- setPageSize: Y,
61
- totalPages: k,
62
- safeCurrentPage: X,
63
- startIndex: p,
64
- endIndex: D,
65
- tableRef: Z,
66
- hasActions: I,
67
- hasBulkActions: L,
68
- orderedColumns: M,
69
- visibleColumnsArray: T,
70
- colSpanCount: _,
71
- paginatedData: re,
72
- handleSort: $,
73
- handleMouseDown: K,
74
- handleDragStart: ee,
75
- handleDragOver: te,
76
- handleDrop: ne,
77
- toggleColumnVisibility: (e) => {
78
- const t = new Set(h);
79
- t.has(e) ? t.delete(e) : t.add(e), J(t);
80
- },
81
- toggleRowSelection: (e) => {
82
- g.includes(e) ? f(g.filter((t) => t !== e)) : f([...g, e]);
83
- },
84
- toggleSelectAll: () => {
85
- g.length === i.length ? f([]) : f(i.map((e) => j(e)));
86
- }
87
- };
88
- }
89
- export {
90
- ue as u
91
- };