@alphakits/ui 2.4.0 → 2.4.2

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.
@@ -1,109 +1,111 @@
1
- import { jsxs as f, jsx as t } from "react/jsx-runtime";
2
- import A from "@alphakits/icons/dist/TrashM";
3
- import V, { useContext as D, useState as H, useCallback as v, useEffect as q } from "react";
4
- import { Button as k } from "../../../button/component.js";
5
- import { Flex as G } from "../../../flex/component.js";
6
- import { FlexColumns as J } from "../../../flex-columns/component.js";
7
- import { IconButton as K } from "../../../icon-button/component.js";
8
- import { ModalContext as L } from "../../../modal/context.js";
9
- import { Sidepanel as N } from "../../../sidepanel/component.js";
10
- import { ToastPlate as x } from "../../../toast-plate/component.js";
1
+ import { jsxs as p, jsx as o } from "react/jsx-runtime";
2
+ import V from "@alphakits/icons/dist/TrashM";
3
+ import D, { useContext as H, useRef as q, useCallback as x, useEffect as G } from "react";
4
+ import { Button as F } from "../../../button/component.js";
5
+ import { Flex as J } from "../../../flex/component.js";
6
+ import { FlexColumns as K } from "../../../flex-columns/component.js";
7
+ import { IconButton as L } from "../../../icon-button/component.js";
8
+ import { ModalContext as N } from "../../../modal/context.js";
9
+ import { Sidepanel as O } from "../../../sidepanel/component.js";
10
+ import { ToastPlate as I } from "../../../toast-plate/component.js";
11
11
  function ie({
12
- recordId: F,
13
- title: I,
12
+ recordId: R,
13
+ title: M,
14
14
  subtitle: T,
15
- headerBottomAddons: u,
15
+ headerBottomAddons: b,
16
16
  initialValues: w,
17
17
  submitButtonText: y,
18
- customFooter: M,
19
- loading: i,
20
- updating: n,
18
+ customFooter: B,
19
+ loading: n,
20
+ updating: i,
21
21
  removing: s,
22
- customValidationFields: O,
23
- validate: Q,
24
- save: U,
22
+ customValidationFields: Q,
23
+ validate: U,
24
+ save: W,
25
25
  remove: a,
26
- close: R,
27
- back: S,
26
+ close: S,
27
+ back: z,
28
28
  t: r,
29
- children: B,
30
- headerAddon: b,
31
- error: W,
29
+ children: P,
30
+ headerAddon: h,
31
+ error: X,
32
32
  softError: d,
33
- ...z
33
+ ...g
34
34
  }) {
35
- const { setModalDirty: e, currentModalId: P } = D(L), [o] = H(P), { submitCount: l, handleSubmit: h, isValid: m, ...c } = z, p = !!F && !!a, C = v(
35
+ const { setModalDirty: e, currentModalId: l } = H(N), c = q("");
36
+ !c.current && l && (c.current = l);
37
+ const t = c.current || l, { submitCount: m, handleSubmit: C, isValid: f, ...u } = g, v = !!R && !!a, k = x(
36
38
  () => {
37
- e(o, !1), h();
39
+ e(t, !1), C();
38
40
  },
39
41
  // eslint-disable-next-line react-hooks/exhaustive-deps
40
- [o, e, h]
41
- ), g = v(() => {
42
- e(o, !1), confirm(r("common:deleteConfirm")) && a?.();
43
- }, [o, r, e, a]);
44
- q(() => {
45
- i || e(o, c.dirty);
46
- }, [c.dirty, i, o, e]);
47
- const j = p || b ? /* @__PURE__ */ f(V.Fragment, { children: [
48
- b,
49
- p && /* @__PURE__ */ t(
50
- K,
42
+ [t, e, C]
43
+ ), j = x(() => {
44
+ e(t, !1), confirm(r("common:deleteConfirm")) && a?.();
45
+ }, [t, r, e, a]);
46
+ G(() => {
47
+ n || e(t, u.dirty);
48
+ }, [u.dirty, n, t, e]);
49
+ const A = v || h ? /* @__PURE__ */ p(D.Fragment, { children: [
50
+ h,
51
+ v && /* @__PURE__ */ o(
52
+ L,
51
53
  {
52
54
  dataTestId: "removeTariffBtn",
53
55
  size: "m",
54
- disabled: n,
56
+ disabled: i,
55
57
  loading: s,
56
- onClick: g,
57
- icon: A
58
+ onClick: j,
59
+ icon: V
58
60
  }
59
61
  )
60
62
  ] }) : null;
61
- return /* @__PURE__ */ t(
62
- N,
63
+ return /* @__PURE__ */ o(
64
+ O,
63
65
  {
64
- headerRightAddons: j,
65
- title: I,
66
+ headerRightAddons: A,
67
+ title: M,
66
68
  subtitle: T,
67
- loading: n || s || i,
68
- headerBottomAddons: (u || !!d || !m && !!l) && /* @__PURE__ */ f(J, { columns: 1, gr: 8, children: [
69
- u,
70
- !!d && /* @__PURE__ */ t(x, { view: "negative", children: d }),
71
- !m && !!l && /* @__PURE__ */ t(x, { view: "negative", children: "Please correct errors before submitting form." })
69
+ loading: i || s || n,
70
+ headerBottomAddons: (b || !!d || !f && !!m) && /* @__PURE__ */ p(K, { columns: 1, gr: 8, children: [
71
+ b,
72
+ !!d && /* @__PURE__ */ o(I, { view: "negative", children: d }),
73
+ !f && !!m && /* @__PURE__ */ o(I, { view: "negative", children: "Please correct errors before submitting form." })
72
74
  ] }),
73
- back: S,
75
+ back: z,
74
76
  t: r,
75
- bottomAddons: M || /* @__PURE__ */ f(G, { gap: "md", children: [
76
- /* @__PURE__ */ t(
77
- k,
77
+ bottomAddons: B || /* @__PURE__ */ p(J, { gap: "md", children: [
78
+ /* @__PURE__ */ o(
79
+ F,
78
80
  {
79
81
  view: "primary",
80
82
  size: "s",
81
83
  block: !0,
82
- loading: i,
83
- disabled: n || s,
84
+ loading: n,
85
+ disabled: i || s,
84
86
  dataTestId: "buttonSave",
85
- onClick: () => C(),
87
+ onClick: () => k(),
86
88
  children: r(y || "save")
87
89
  }
88
90
  ),
89
- /* @__PURE__ */ t(
90
- k,
91
+ /* @__PURE__ */ o(
92
+ F,
91
93
  {
92
94
  block: !0,
93
95
  view: "secondary",
94
96
  size: "s",
95
97
  dataTestId: "buttonCancel",
96
- onClick: R,
98
+ onClick: S,
97
99
  children: r("cancel")
98
100
  }
99
101
  )
100
102
  ] }),
101
- children: B({
102
- submitCount: l,
103
- isValid: m,
104
- handleSubmit: C,
103
+ children: P({
104
+ submitCount: m,
105
+ isValid: f,
106
+ handleSubmit: k,
105
107
  initialValues: w,
106
- ...c
108
+ ...u
107
109
  })
108
110
  }
109
111
  );
@@ -1,78 +1,79 @@
1
- import { jsxs as k, jsx as n } from "react/jsx-runtime";
1
+ import { jsxs as h, jsx as i } from "react/jsx-runtime";
2
2
  import y from "classnames";
3
- import { useState as C, useLayoutEffect as d, useCallback as b, useEffect as z } from "react";
4
- import { ButtonArrow as v } from "../../../button-arrow/component.js";
5
- import o from "./index.module.css.js";
6
- const h = {
3
+ import { useState as E, useLayoutEffect as g, useCallback as k, useEffect as v } from "react";
4
+ import { ButtonArrow as x } from "../../../button-arrow/component.js";
5
+ import t from "./index.module.css.js";
6
+ const C = {
7
7
  s: 488,
8
8
  m: 888,
9
9
  full: "96%"
10
- }, j = ({ modal: e, t: l, index: p, dirtyModals: a, closeModal: f, currentModalId: r }) => {
11
- const c = -h[e.props.size] - 102, [w, m] = C(c);
12
- d(() => {
13
- setTimeout(() => m(0), 0);
14
- }, []);
15
- const u = b(
10
+ }, w = 102, F = (e) => e === "full" ? `calc(-96vw - ${w}px)` : -C[e] - w, O = ({ modal: e, t: f, index: l, dirtyModals: p, closeModal: a, currentModalId: r }) => {
11
+ const c = F(e.props.size), [b, m] = E(c);
12
+ g(() => {
13
+ const s = requestAnimationFrame(() => m(0));
14
+ return () => cancelAnimationFrame(s);
15
+ }, [e.id]);
16
+ const u = k(
16
17
  (s) => (
17
18
  // eslint-disable-next-line no-restricted-globals
18
- !a[s] || confirm(l("common:exitConfirm"))
19
+ !p[s] || confirm(f("common:exitConfirm"))
19
20
  ),
20
21
  // eslint-disable-next-line react-hooks/exhaustive-deps
21
- [a, l]
22
- ), t = b(
22
+ [p, f]
23
+ ), n = k(
23
24
  (s) => {
24
- const { id: i } = e;
25
- u(s || i) && (m(c), setTimeout(() => {
26
- e.props.closeCallback && e.props.closeCallback(), f(s || i);
25
+ const { id: o } = e;
26
+ u(s || o) && (m(c), setTimeout(() => {
27
+ e.props.closeCallback && e.props.closeCallback(), a(s || o);
27
28
  }, 250));
28
29
  },
29
- [f, u, e, c]
30
+ [a, u, e, c]
30
31
  );
31
- return z(() => {
32
- const s = (i) => {
33
- (i.key === "27" || i.key === "Escape") && t(r);
32
+ return v(() => {
33
+ const s = (o) => {
34
+ (o.key === "27" || o.key === "Escape") && n(r);
34
35
  };
35
36
  return e.id === r && window?.addEventListener("keydown", s), () => {
36
37
  window?.removeEventListener("keydown", s);
37
38
  };
38
- }, [t, r, e.id]), /* @__PURE__ */ k(
39
+ }, [n, r, e.id]), /* @__PURE__ */ h(
39
40
  "div",
40
41
  {
41
- className: o.container,
42
+ className: t.container,
42
43
  style: {
43
- zIndex: 9999998 + p
44
+ zIndex: 9999998 + l
44
45
  },
45
46
  children: [
46
- /* @__PURE__ */ n(
47
+ /* @__PURE__ */ i(
47
48
  "div",
48
49
  {
49
- className: y(o.right, o.content),
50
+ className: y(t.right, t.content),
50
51
  style: {
51
- zIndex: 9999999 + p,
52
- width: h[e.props.size],
53
- right: w
52
+ zIndex: 9999999 + l,
53
+ width: C[e.props.size],
54
+ right: b
54
55
  },
55
- children: /* @__PURE__ */ k("div", { className: o.inner, children: [
56
- /* @__PURE__ */ n(e.modal, { ...e.props, close: () => t() }),
57
- e.props.showCloser !== !1 && /* @__PURE__ */ n(
58
- v,
56
+ children: /* @__PURE__ */ h("div", { className: t.inner, children: [
57
+ /* @__PURE__ */ i(e.modal, { ...e.props, close: () => n() }),
58
+ e.props.showCloser !== !1 && /* @__PURE__ */ i(
59
+ x,
59
60
  {
60
- className: o.button,
61
+ className: t.button,
61
62
  size: "s",
62
63
  type: "close",
63
- onClick: () => t()
64
+ onClick: () => n()
64
65
  }
65
66
  )
66
67
  ] })
67
68
  }
68
69
  ),
69
- /* @__PURE__ */ n(
70
+ /* @__PURE__ */ i(
70
71
  "button",
71
72
  {
72
- className: o.bg,
73
+ className: t.bg,
73
74
  "aria-label": "close_backdrop",
74
75
  type: "button",
75
- onClick: () => t()
76
+ onClick: () => n()
76
77
  }
77
78
  )
78
79
  ]
@@ -80,5 +81,5 @@ const h = {
80
81
  );
81
82
  };
82
83
  export {
83
- j as Modal
84
+ O as Modal
84
85
  };
@@ -1,44 +1,41 @@
1
- import { jsxs as m, jsx as a } from "react/jsx-runtime";
2
- import M from "react";
3
- import { Portal as c } from "../portal/component.js";
4
- import { Modals as p } from "./components/modals/index.js";
1
+ import { jsxs as M, jsx as a } from "react/jsx-runtime";
2
+ import c, { useMemo as p } from "react";
3
+ import { Portal as u } from "../portal/component.js";
4
+ import { Modals as x } from "./components/modals/index.js";
5
5
  import { useModal as f } from "./hooks/use-modal.js";
6
- const u = M.createContext({
6
+ const v = c.createContext({
7
7
  modals: [],
8
8
  currentModalId: "",
9
9
  openModal: () => () => {
10
10
  },
11
11
  setModalDirty: () => {
12
12
  }
13
- }), h = ({ children: l, t: i, portal: o }) => {
14
- const { modals: r, openModal: t, setModalDirty: d, currentModalId: e, dirtyModals: n, closeModal: s } = f(i);
15
- return /* @__PURE__ */ m(
16
- u.Provider,
17
- {
18
- value: {
19
- modals: r,
20
- openModal: t,
21
- setModalDirty: d,
22
- currentModalId: e
23
- },
24
- children: [
25
- /* @__PURE__ */ a(c, { getPortalContainer: o ? () => o : void 0, children: /* @__PURE__ */ a(
26
- p,
27
- {
28
- modals: r,
29
- dirtyModals: n,
30
- closeModal: s,
31
- openModal: t,
32
- setModalDirty: d,
33
- currentModalId: e
34
- }
35
- ) }),
36
- l
37
- ]
38
- }
13
+ }), D = ({ children: l, t: n, portal: d }) => {
14
+ const { modals: o, openModal: r, setModalDirty: t, currentModalId: e, dirtyModals: s, closeModal: i } = f(n), m = p(
15
+ () => ({
16
+ modals: o,
17
+ openModal: r,
18
+ setModalDirty: t,
19
+ currentModalId: e
20
+ }),
21
+ [o, r, t, e]
39
22
  );
23
+ return /* @__PURE__ */ M(v.Provider, { value: m, children: [
24
+ /* @__PURE__ */ a(u, { getPortalContainer: d ? () => d : void 0, children: /* @__PURE__ */ a(
25
+ x,
26
+ {
27
+ modals: o,
28
+ dirtyModals: s,
29
+ closeModal: i,
30
+ openModal: r,
31
+ setModalDirty: t,
32
+ currentModalId: e
33
+ }
34
+ ) }),
35
+ l
36
+ ] });
40
37
  };
41
38
  export {
42
- u as ModalContext,
43
- h as ModalProvider
39
+ v as ModalContext,
40
+ D as ModalProvider
44
41
  };
@@ -1,42 +1,45 @@
1
- import n, { useEffect as I } from "react";
2
- import { v4 as S } from "uuid";
3
- import { deletePropertyById as g } from "../utils/delete-property-by-id.js";
4
- const x = (c) => {
5
- const [s, l] = n.useState([]), [u, M] = n.useState(""), [i, a] = n.useState({}), p = (t) => {
6
- a((o) => g(o, t)), l((o) => o.filter((e) => e.id !== t));
7
- }, m = (t) => {
8
- l((o) => [...o, t]);
9
- }, f = (t, o) => {
10
- a((e) => ({
11
- ...e,
12
- [t]: o
13
- }));
14
- };
15
- return I(() => {
16
- const t = [...s].pop()?.id;
17
- M(t || ""), document.body.style.overflow = s.length ? "hidden" : "unset";
18
- }, [s]), {
19
- openModal: (t, o = "s", e = !0) => {
20
- const y = (d, r) => ({
21
- id: S(),
22
- modal: t,
23
- props: {
24
- size: o,
25
- showCloser: e,
26
- closeCallback: r,
27
- t: c,
28
- ...d
29
- }
30
- });
31
- return (d, r) => {
32
- m(y(d, r));
33
- };
34
- },
35
- modals: s,
36
- setModalDirty: f,
37
- currentModalId: u,
38
- dirtyModals: i,
39
- closeModal: p
1
+ import d, { useRef as S, useCallback as s, useEffect as b } from "react";
2
+ import { v4 as h } from "uuid";
3
+ import { deletePropertyById as v } from "../utils/delete-property-by-id.js";
4
+ const x = (n) => {
5
+ const [r, l] = d.useState([]), [M, f] = d.useState(""), [p, a] = d.useState({}), c = S(n);
6
+ c.current = n;
7
+ const i = s((t) => {
8
+ a((e) => v(e, t)), l((e) => e.filter((o) => o.id !== t));
9
+ }, []), u = s((t) => {
10
+ l((e) => [...e, t]);
11
+ }, []), m = s((t, e) => {
12
+ t && a((o) => o[t] === e ? o : {
13
+ ...o,
14
+ [t]: e
15
+ });
16
+ }, []);
17
+ return b(() => {
18
+ const t = [...r].pop()?.id;
19
+ f(t || ""), document.body.style.overflow = r.length ? "hidden" : "unset";
20
+ }, [r]), {
21
+ openModal: s(
22
+ (t, e = "s", o = !0) => (y, I) => {
23
+ const R = h();
24
+ u({
25
+ id: R,
26
+ modal: t,
27
+ props: {
28
+ size: e,
29
+ showCloser: o,
30
+ closeCallback: I,
31
+ t: c.current,
32
+ ...y
33
+ }
34
+ });
35
+ },
36
+ [u]
37
+ ),
38
+ modals: r,
39
+ setModalDirty: m,
40
+ currentModalId: M,
41
+ dirtyModals: p,
42
+ closeModal: i
40
43
  };
41
44
  };
42
45
  export {
@@ -1,7 +1,7 @@
1
- import { jsx as r, jsxs as P } from "react/jsx-runtime";
2
- import { useFloating as $, autoUpdate as j, offset as D, flip as U, shift as z, arrow as V } from "@floating-ui/react-dom";
3
- import m from "classnames";
4
- import { useRef as g, useLayoutEffect as q, useEffect as N, useMemo as B, useCallback as G } from "react";
1
+ import { jsx as r, jsxs as D } from "react/jsx-runtime";
2
+ import { offset as L, flip as P, shift as U, arrow as z, useFloating as V, autoUpdate as q } from "@floating-ui/react-dom";
3
+ import c from "classnames";
4
+ import { useRef as g, useMemo as N, useEffect as B, useCallback as G } from "react";
5
5
  import { CSSTransition as H } from "react-transition-group";
6
6
  import { Portal as J } from "../portal/component.js";
7
7
  import { Stack as K } from "../stack/component.js";
@@ -21,92 +21,90 @@ const W = {
21
21
  left: "right"
22
22
  }, ct = ({
23
23
  children: R,
24
- getPortalContainer: A,
25
- transition: f = W,
26
- anchorElement: d,
27
- offset: a = [0, 0],
28
- withArrow: i = !1,
29
- withTransition: b = !0,
30
- position: y = "left",
31
- preventFlip: T,
32
- popperClassName: h,
24
+ getPortalContainer: b,
25
+ transition: m = W,
26
+ anchorElement: A,
27
+ offset: n = [0, 0],
28
+ withArrow: o = !1,
29
+ withTransition: T = !0,
30
+ position: h = "left",
31
+ preventFlip: f,
32
+ popperClassName: y,
33
33
  arrowClassName: E,
34
34
  className: O,
35
- open: u,
35
+ open: i,
36
36
  dataTestId: C,
37
37
  update: l,
38
- transitionDuration: F = `${f.timeout}ms`,
39
- zIndex: w = Q.POPOVER
38
+ transitionDuration: F = `${m.timeout}ms`,
39
+ zIndex: I = Q.POPOVER
40
40
  }) => {
41
- const p = g(null), x = g(null), {
42
- refs: n,
43
- floatingStyles: I,
44
- middlewareData: c,
45
- placement: S,
46
- update: o
47
- } = $({
48
- placement: y,
49
- whileElementsMounted: j,
50
- middleware: [
51
- D(
52
- {
53
- crossAxis: a[0],
54
- mainAxis: a[1]
55
- },
56
- [a]
57
- ),
58
- ...T ? [] : [U()],
59
- z({ padding: 4 }),
60
- ...i ? [V({ element: p })] : []
61
- ]
41
+ const d = g(null), u = g(null), M = N(
42
+ () => [
43
+ L({
44
+ crossAxis: n[0],
45
+ mainAxis: n[1]
46
+ }),
47
+ ...f ? [] : [P()],
48
+ U({ padding: 4 }),
49
+ ...o ? [z({ element: d })] : []
50
+ ],
51
+ [n[0], n[1], f, o]
52
+ ), {
53
+ refs: { setFloating: p },
54
+ floatingStyles: _,
55
+ middlewareData: a,
56
+ placement: x,
57
+ update: S
58
+ } = V({
59
+ placement: h,
60
+ open: i,
61
+ elements: { reference: A },
62
+ whileElementsMounted: i ? q : void 0,
63
+ middleware: M
62
64
  });
63
- q(() => {
64
- n.setReference(d);
65
- }, [d, n]), N(() => {
66
- l && o && (l.current = o);
67
- }, [o, l]), N(() => {
68
- o();
69
- }, [o]);
70
- const M = B(() => {
71
- if (!i || !c.arrow)
65
+ B(() => {
66
+ l && (l.current = S);
67
+ }, [S, l]);
68
+ const k = N(() => {
69
+ if (!o || !a.arrow)
72
70
  return {};
73
- const { x: t, y: s } = c.arrow, k = S.split("-")[0], L = Z[k] ?? "bottom";
71
+ const { x: t, y: s } = a.arrow, j = x.split("-")[0], w = Z[j] ?? "bottom";
74
72
  return {
75
73
  position: "absolute",
76
74
  left: t != null ? `${t}px` : void 0,
77
75
  top: s != null ? `${s}px` : void 0,
78
76
  right: "",
79
77
  bottom: "",
80
- [L]: "-4px"
78
+ [w]: "-4px"
81
79
  };
82
- }, [i, c.arrow, S]), _ = G(
80
+ }, [o, a.arrow, x]), $ = G(
83
81
  (t) => {
84
- x.current = t, n.setFloating(t);
82
+ u.current = t, p(t);
85
83
  },
86
- [n]
84
+ [p]
87
85
  ), v = (t, s) => /* @__PURE__ */ r(
88
86
  "div",
89
87
  {
90
- ref: _,
88
+ ref: $,
91
89
  style: {
92
90
  zIndex: t,
93
- ...I
91
+ ..._
94
92
  },
95
- className: m(e.component, O),
96
- children: /* @__PURE__ */ P(
93
+ className: c(e.component, O),
94
+ children: /* @__PURE__ */ D(
97
95
  "div",
98
96
  {
99
97
  "data-test-id": C,
100
- className: m(e.inner, h),
98
+ className: c(e.inner, y),
101
99
  style: s,
102
100
  children: [
103
101
  R,
104
- i && /* @__PURE__ */ r(
102
+ o && /* @__PURE__ */ r(
105
103
  "div",
106
104
  {
107
- ref: p,
108
- style: M,
109
- className: m(e.arrow, E)
105
+ ref: d,
106
+ style: k,
107
+ className: c(e.arrow, E)
110
108
  }
111
109
  )
112
110
  ]
@@ -114,17 +112,17 @@ const W = {
114
112
  )
115
113
  }
116
114
  );
117
- return /* @__PURE__ */ r(K, { value: w, children: (t) => /* @__PURE__ */ r(J, { getPortalContainer: A, children: b ? /* @__PURE__ */ r(
115
+ return /* @__PURE__ */ r(K, { value: I, children: (t) => /* @__PURE__ */ r(J, { getPortalContainer: b, children: T ? /* @__PURE__ */ r(
118
116
  Y,
119
117
  {
120
118
  unmountOnExit: !0,
121
119
  classNames: X,
122
- ...f,
123
- in: u,
124
- nodeRef: x,
120
+ ...m,
121
+ in: i,
122
+ nodeRef: u,
125
123
  children: v(t, { transitionDuration: F })
126
124
  }
127
- ) : u && v(t) }) });
125
+ ) : i && v(t) }) });
128
126
  };
129
127
  export {
130
128
  ct as Popover
@@ -1,3 +1,4 @@
1
- export declare const EmptyList: ({ language }: {
1
+ export declare const EmptyList: ({ language, columnsLength, }: {
2
2
  language: 'en' | 'de' | 'ru';
3
+ columnsLength: number;
3
4
  }) => import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,11 @@
1
1
  import { jsx as t } from "react/jsx-runtime";
2
2
  import { Typography as i } from "../../../typography/component.js";
3
3
  import { translate as m } from "../../languages/index.js";
4
- import o from "./index.module.css.js";
5
- const y = ({ language: r }) => /* @__PURE__ */ t("div", { className: o.empty_list, children: /* @__PURE__ */ t(i.Text, { color: "primary", view: "title", children: m(r)("emptyList") }) });
4
+ import e from "./index.module.css.js";
5
+ const c = ({
6
+ language: r,
7
+ columnsLength: o
8
+ }) => /* @__PURE__ */ t("tr", { children: /* @__PURE__ */ t("td", { colSpan: o, className: e.empty_list, children: /* @__PURE__ */ t(i.Text, { color: "primary", view: "title", children: m(r)("emptyList") }) }) });
6
9
  export {
7
- y as EmptyList
10
+ c as EmptyList
8
11
  };
@@ -1,3 +1,4 @@
1
- export declare const TableError: ({ language }: {
1
+ export declare const TableError: ({ language, columnsLength, }: {
2
2
  language: 'en' | 'de' | 'ru';
3
+ columnsLength: number;
3
4
  }) => import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,11 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
- import { Typography as t } from "../../../typography/component.js";
3
- import { translate as e } from "../../languages/index.js";
4
- import i from "./index.module.css.js";
5
- const a = ({ language: o }) => /* @__PURE__ */ r("div", { className: i.empty_list, children: /* @__PURE__ */ r(t.Text, { color: "primary", view: "title", children: e(o)("error") }) });
2
+ import { Typography as e } from "../../../typography/component.js";
3
+ import { translate as i } from "../../languages/index.js";
4
+ import l from "./index.module.css.js";
5
+ const c = ({
6
+ language: o,
7
+ columnsLength: t
8
+ }) => /* @__PURE__ */ r("tr", { children: /* @__PURE__ */ r("td", { colSpan: t, className: l.empty_list, children: /* @__PURE__ */ r(e.Text, { color: "primary", view: "title", children: i(o)("error") }) }) });
6
9
  export {
7
- a as TableError
10
+ c as TableError
8
11
  };
@@ -10,7 +10,7 @@ export declare function useTableData<T extends object>({ promise, records, fromP
10
10
  error: boolean;
11
11
  data: T[];
12
12
  total: number;
13
- params: QueryDTO | undefined;
13
+ params: QueryDTO;
14
14
  pagesCount: number;
15
15
  updateData: (forcedQuery?: QueryDTO) => Promise<void>;
16
16
  addParam: (patch: Query) => void;
@@ -1,115 +1,119 @@
1
1
  import { useState as u, useCallback as c, useEffect as D } from "react";
2
- import { addQueryParam as z } from "../utils/add-query-param.js";
3
- import { getQueryFromUrl as I } from "../utils/get-query-from-url.js";
2
+ import { addQueryParam as I } from "../utils/add-query-param.js";
3
+ import { getQueryFromUrl as R } from "../utils/get-query-from-url.js";
4
4
  import "query-string";
5
- import { removeQueryParam as R } from "../utils/remove-query-param.js";
6
- import { resetQueryParam as V } from "../utils/reset-query-param.js";
5
+ import { removeQueryParam as V } from "../utils/remove-query-param.js";
6
+ import { resetQueryParam as Y } from "../utils/reset-query-param.js";
7
7
  import { serializeData as b } from "../utils/serialize-data.js";
8
- const A = {
8
+ const d = {
9
9
  page: 1,
10
10
  limit: 10,
11
11
  where: {}
12
12
  // остальное добавится по мере нужды (searchText, sort, order и т.д.)
13
13
  };
14
- function v(f, s) {
15
- const n = f ?? A, a = {
14
+ function E(f, n) {
15
+ const r = f ?? d, a = {
16
+ ...r,
16
17
  ...n,
17
- ...s,
18
18
  where: {
19
- ...n.where ?? {},
20
- ...s.where ?? {}
19
+ ...r.where ?? {},
20
+ ...n.where ?? {}
21
21
  }
22
22
  };
23
23
  return a.page && (a.page = +a.page), a.limit && (a.limit = +a.limit), a;
24
24
  }
25
- function K({ promise: f, records: s, fromPath: n = !0 }) {
26
- const [a, Q] = u([]), [E, g] = u(!0), [C, d] = u(!1), [L, P] = u(0), [S, T] = u(1), [o, m] = u(void 0), w = c(
27
- (t) => n ? I() : t ?? o ?? A,
28
- [n, o]
29
- ), r = c(
25
+ function M({ promise: f, records: n, fromPath: r = !0 }) {
26
+ const [a, p] = u([]), [h, w] = u(!0), [C, A] = u(!1), [L, S] = u(0), [T, U] = u(1), [o, m] = u(void 0), y = c(
27
+ (t) => r ? R() : t ?? o ?? d,
28
+ // params не включаем при fromPath: иначе setParams на каждом fetch
29
+ // даёт новую ссылку → computeQuery/updateData меняются → бесконечный цикл.
30
+ r ? [r] : [r, o]
31
+ ), s = c(
30
32
  async (t) => {
31
- const e = w(t);
32
- if (Array.isArray(s) && (g(!1), Q(b(s, e))), m(e), f) {
33
- d(!1), g(!0);
33
+ const e = y(t);
34
+ if (Array.isArray(n) && (w(!1), p(b(n, e))), m(e), f) {
35
+ A(!1), w(!0);
34
36
  try {
35
37
  const {
36
- data: { items: i, meta: y }
38
+ data: { items: i, meta: g }
37
39
  } = await f(e);
38
- P(y.totalItems), T(y.totalPages), Q(i || []);
40
+ S(g.totalItems), U(g.totalPages), p(i || []);
39
41
  } catch {
40
- d(!0);
42
+ A(!0);
41
43
  } finally {
42
- g(!1);
44
+ w(!1);
43
45
  }
44
46
  }
45
47
  },
46
- [w, s, f]
47
- ), U = c(
48
+ [y, n, f]
49
+ ), q = c(
48
50
  (t) => {
49
- if (n) {
50
- z(t), r();
51
+ if (r) {
52
+ I(t), s();
51
53
  return;
52
54
  }
53
- const e = v(o, t);
54
- m(e), r(e);
55
+ const e = E(o, t);
56
+ m(e), s(e);
55
57
  },
56
- [n, o, r]
57
- ), p = c(
58
+ [r, o, s]
59
+ ), Q = c(
58
60
  (t, e, i) => {
59
- const y = t ?? A, l = {
60
- ...y,
61
- where: { ...y.where ?? {} }
61
+ const g = t ?? d, l = {
62
+ ...g,
63
+ where: { ...g.where ?? {} }
62
64
  }, x = l.where?.[e];
63
65
  if (Array.isArray(x) && i != null) {
64
- const h = x.filter((k) => String(k) !== String(i));
65
- h.length ? l.where[e] = h : delete l.where[e];
66
+ const v = x.filter((z) => String(z) !== String(i));
67
+ v.length ? l.where[e] = v : delete l.where[e];
66
68
  } else
67
69
  l.where && e in l.where && delete l.where[e];
68
70
  return l;
69
71
  },
70
72
  []
71
- ), q = c(
73
+ ), F = c(
72
74
  (t, e) => {
73
- if (n) {
74
- R(t, e), r();
75
+ if (r) {
76
+ V(t, e), s();
75
77
  return;
76
78
  }
77
- const i = p(o, t, e);
78
- m(i), r(i);
79
+ const i = Q(o, t, e);
80
+ m(i), s(i);
79
81
  },
80
- [n, o, r, p]
81
- ), F = c(
82
+ [r, o, s, Q]
83
+ ), P = c(
82
84
  (t) => {
83
- if (n) {
84
- V(t), r();
85
+ if (r) {
86
+ Y(t), s();
85
87
  return;
86
88
  }
87
- const e = v(A, t);
88
- m(e), r(e);
89
+ const e = E(d, t);
90
+ m(e), s(e);
89
91
  },
90
- [n, r]
92
+ [r, s]
91
93
  );
92
- return D(() => {
93
- r();
94
- }, [r]), D(() => {
95
- if (Array.isArray(s)) {
96
- const t = w();
97
- m(t), g(!1), Q(b(s, t));
94
+ D(() => {
95
+ s();
96
+ }, [s]), D(() => {
97
+ if (Array.isArray(n)) {
98
+ const t = y();
99
+ m(t), w(!1), p(b(n, t));
98
100
  }
99
- }, [s, w]), {
100
- loading: E,
101
+ }, [n, y]);
102
+ const k = o ?? y();
103
+ return {
104
+ loading: h,
101
105
  error: C,
102
106
  data: a,
103
107
  total: L,
104
- params: o,
105
- pagesCount: S,
106
- updateData: r,
108
+ params: k,
109
+ pagesCount: T,
110
+ updateData: s,
107
111
  // НОВОЕ: наружу отдаём универсальные методы для управления параметрами
108
- addParam: U,
109
- removeParam: q,
110
- resetParams: F
112
+ addParam: q,
113
+ removeParam: F,
114
+ resetParams: P
111
115
  };
112
116
  }
113
117
  export {
114
- K as useTableData
118
+ M as useTableData
115
119
  };
@@ -1 +1 @@
1
- :root{--text-primary-color: var(--color-text-primary);--text-secondary-color: var(--color-text-secondary);--text-tertiary-color: var(--color-text-tertiary);--border-radius: 4px;--focus-color: var(--color-border-link);--font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, sans-serif;--disabled-cursor: not-allowed;--arrow-transform: rotate(180deg)}.table_wrapper_SeB5{width:100%;box-sizing:border-box;position:relative}.table_9sbd{position:relative;box-sizing:border-box;border:1px solid var(--color-border-secondary);border-radius:12px 12px 0 0;background:var(--color-bg-primary);box-shadow:var(--shadow-xs);overflow:hidden}.table_9sbd table{width:100%;border-collapse:collapse;background:var(--color-bg-primary);table-layout:fixed}.table_9sbd tbody tr td{transition:background-color .15s ease}.table_9sbd.no_footer_julO{border-radius:12px}.fill_Q-ic{height:-webkit-fill-available;flex-grow:1;display:flex;flex-direction:column}.fill_Q-ic .table_9sbd{flex-grow:1;overflow:hidden}.fill_Q-ic .table_9sbd:hover{overflow:auto}.clickable_k4S8{cursor:pointer}.clickable_k4S8:hover td{background-color:color-mix(in srgb,var(--color-bg-secondary) 92%,var(--color-bg-primary))}
1
+ :root{--text-primary-color: var(--color-text-primary);--text-secondary-color: var(--color-text-secondary);--text-tertiary-color: var(--color-text-tertiary);--border-radius: 4px;--focus-color: var(--color-border-link);--font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, sans-serif;--disabled-cursor: not-allowed;--arrow-transform: rotate(180deg)}.table_wrapper_SeB5{width:100%;box-sizing:border-box;position:relative}.table_9sbd{position:relative;box-sizing:border-box;border:1px solid var(--color-border-secondary);border-radius:12px 12px 0 0;background:var(--color-bg-primary);box-shadow:var(--shadow-xs);overflow:hidden}.table_9sbd table{width:100%;border-collapse:collapse;background:var(--color-bg-primary);table-layout:auto}.table_9sbd tbody tr td{transition:background-color .15s ease}.table_9sbd.no_footer_julO{border-radius:12px}.fill_Q-ic{height:-webkit-fill-available;flex-grow:1;display:flex;flex-direction:column}.fill_Q-ic .table_9sbd{flex-grow:1;overflow:hidden}.fill_Q-ic .table_9sbd:hover{overflow:auto}.clickable_k4S8{cursor:pointer}.clickable_k4S8:hover td{background-color:color-mix(in srgb,var(--color-bg-secondary) 92%,var(--color-bg-primary))}
@@ -1,137 +1,137 @@
1
- import { jsxs as f, jsx as r } from "react/jsx-runtime";
2
- import P from "classnames";
3
- import { useMemo as j, useCallback as U } from "react";
4
- import { Cells as W } from "./components/cells/index.js";
5
- import { EmptyList as X } from "./components/empty-list/index.js";
6
- import { TableError as Y } from "./components/error/index.js";
7
- import { Loading as Z } from "./components/loading/index.js";
8
- import { Pagination as $ } from "./components/pagination/index.js";
9
- import { TableHeader as A } from "./components/table-header/index.js";
10
- import { useTableData as aa } from "./hooks/use-table-data.js";
11
- import o from "./index.module.css.js";
12
- import { getTags as ta } from "./utils/get-tags.js";
13
- import { prepareRows as ra } from "./utils/prepare-rows.js";
14
- function ha({
15
- columns: l,
16
- searchPlaceholder: E = "Поиск по таблице",
17
- records: H,
18
- hideSearch: b,
19
- rightHeaderAddons: h,
20
- leftHeaderAddons: g,
21
- filtersButtonLabel: S,
22
- createButtonLabel: _,
23
- loading: w,
24
- height: B = "fill",
25
- view: e = "default",
26
- tagsBuilder: F,
1
+ import { jsxs as h, jsx as r } from "react/jsx-runtime";
2
+ import X, { useMemo as E, useCallback as Y } from "react";
3
+ import f from "classnames";
4
+ import { Cells as Z } from "./components/cells/index.js";
5
+ import { EmptyList as $ } from "./components/empty-list/index.js";
6
+ import { Loading as A } from "./components/loading/index.js";
7
+ import { Pagination as tt } from "./components/pagination/index.js";
8
+ import { TableHeader as at } from "./components/table-header/index.js";
9
+ import { useTableData as rt } from "./hooks/use-table-data.js";
10
+ import { getTags as ot } from "./utils/get-tags.js";
11
+ import { prepareRows as et } from "./utils/prepare-rows.js";
12
+ import e from "./index.module.css.js";
13
+ import { TableError as st } from "./components/error/index.js";
14
+ function Lt({
15
+ columns: o,
16
+ searchPlaceholder: N = "Поиск по таблице",
17
+ records: j,
18
+ hideSearch: P,
19
+ rightHeaderAddons: g,
20
+ leftHeaderAddons: b,
21
+ filtersButtonLabel: H,
22
+ createButtonLabel: R,
23
+ loading: S,
24
+ height: _ = "fill",
25
+ view: s = "default",
26
+ tagsBuilder: w,
27
27
  promise: u,
28
- onRowClick: T,
29
- onCreateClick: n,
28
+ onRowClick: L,
29
+ onCreateClick: i,
30
30
  onFiltersClick: m,
31
- refetch: C,
32
- language: i,
33
- fromPath: M = !0
31
+ refetch: B,
32
+ language: n,
33
+ fromPath: F = !0
34
34
  }) {
35
35
  const {
36
- loading: R,
37
- error: x,
36
+ loading: M,
37
+ error: T,
38
38
  data: y,
39
39
  total: V,
40
- params: t,
40
+ params: a,
41
41
  pagesCount: q,
42
42
  updateData: c,
43
43
  addParam: z,
44
44
  removeParam: G,
45
- resetParams: L
46
- } = aa({
45
+ resetParams: C
46
+ } = rt({
47
47
  promise: u,
48
- records: H,
49
- fromPath: M
50
- }), k = j(
48
+ records: j,
49
+ fromPath: F
50
+ }), k = E(
51
51
  () => [...y || []].sort(
52
- (a, s) => (a.sortPosition || 0) - (s.sortPosition || 0)
52
+ (t, l) => (t.sortPosition || 0) - (l.sortPosition || 0)
53
53
  ),
54
54
  [y]
55
- ), I = (a) => T?.(a, c), J = n ? () => n(c) : void 0, K = U(
56
- (a) => {
57
- L(a);
55
+ ), I = (t) => L?.(t, c), J = i ? () => i(c) : void 0, K = Y(
56
+ (t) => {
57
+ C(t);
58
58
  },
59
- [L]
60
- ), v = () => m ? m({
61
- submitCallback: (a) => K(a),
62
- initialValues: t
63
- }) : null, d = (a) => {
64
- z(a);
65
- }, O = (a, s) => {
66
- G(a, s);
67
- }, Q = ta({
68
- params: t?.where || {},
59
+ [C]
60
+ ), x = () => m ? m({
61
+ submitCallback: (t) => K(t),
62
+ initialValues: a
63
+ }) : null, d = (t) => {
64
+ z(t);
65
+ }, O = (t, l) => {
66
+ G(t, l);
67
+ }, Q = ot({
68
+ params: a?.where || {},
69
69
  onDelete: O,
70
- tagsBuilder: F,
71
- onClick: v
72
- }), D = j(
73
- () => ra({
74
- columns: l,
75
- view: e,
70
+ tagsBuilder: w,
71
+ onClick: x
72
+ }), v = E(
73
+ () => et({
74
+ columns: o,
75
+ view: s,
76
76
  data: k,
77
- refetch: C || c
77
+ refetch: B || c
78
78
  }),
79
79
  // eslint-disable-next-line react-hooks/exhaustive-deps
80
- [k, l, e, c, C]
81
- ), p = R || w, N = !!u;
82
- return /* @__PURE__ */ f("div", { className: P(o.table_wrapper, o[B], o[e]), children: [
83
- (!b || h || g || n || m) && /* @__PURE__ */ r(
84
- A,
80
+ [k, o, s]
81
+ ), p = M || S, D = !!u;
82
+ return /* @__PURE__ */ h("div", { className: f(e.table_wrapper, e[_], e[s]), children: [
83
+ (!P || g || b || i || m) && /* @__PURE__ */ r(
84
+ at,
85
85
  {
86
- language: i,
87
- hideSearch: b,
88
- rightHeaderAddons: h,
89
- leftHeaderAddons: g,
90
- searchText: t?.searchText || "",
86
+ language: n,
87
+ hideSearch: P,
88
+ rightHeaderAddons: g,
89
+ leftHeaderAddons: b,
90
+ searchText: a?.searchText || "",
91
91
  addParam: d,
92
- searchPlaceholder: E,
93
- filtersButtonLabel: S,
92
+ searchPlaceholder: N,
93
+ filtersButtonLabel: H,
94
94
  tags: Q,
95
95
  onCreateClick: J,
96
- createButtonLabel: _,
97
- onFiltersClick: v,
96
+ createButtonLabel: R,
97
+ onFiltersClick: x,
98
98
  showFiltersButton: !!m,
99
- compact: e === "compact"
99
+ compact: s === "compact"
100
100
  }
101
101
  ),
102
- /* @__PURE__ */ r("div", { className: P(o.table, { [o.no_footer]: !N }), children: /* @__PURE__ */ f("table", { cellSpacing: "0", cellPadding: "0", children: [
102
+ /* @__PURE__ */ r("div", { className: f(e.table, { [e.no_footer]: !D }), children: /* @__PURE__ */ h("table", { cellSpacing: "0", cellPadding: "0", children: [
103
103
  /* @__PURE__ */ r(
104
- W,
104
+ Z,
105
105
  {
106
- sort: t?.sort,
107
- order: t?.order,
106
+ sort: a?.sort,
107
+ order: a?.order,
108
108
  addParam: d,
109
- columns: l,
110
- compact: e === "compact"
109
+ columns: o,
110
+ compact: s === "compact"
111
111
  }
112
112
  ),
113
- /* @__PURE__ */ f("tbody", { children: [
114
- x && /* @__PURE__ */ r(Y, { language: i }),
115
- !D.length && !p && !x && /* @__PURE__ */ r(X, { language: i }),
116
- p && /* @__PURE__ */ r(Z, { columnsLength: l.length }),
117
- D.map(({ row: a, cells: s }) => /* @__PURE__ */ r(
113
+ /* @__PURE__ */ h("tbody", { children: [
114
+ T && /* @__PURE__ */ r(st, { columnsLength: o.length, language: n }),
115
+ !v.length && !p && !T && /* @__PURE__ */ r($, { columnsLength: o.length, language: n }),
116
+ p && /* @__PURE__ */ r(A, { columnsLength: o.length }),
117
+ v.map(({ row: t, cells: l }) => /* @__PURE__ */ r(
118
118
  "tr",
119
119
  {
120
- onClick: () => I(a),
121
- className: P({ [o.clickable]: !!T }),
120
+ onClick: () => I(t),
121
+ className: f({ [e.clickable]: !!L }),
122
122
  style: { visibility: p ? "collapse" : "visible" },
123
- children: s
123
+ children: l.map((U, W) => X.cloneElement(U, { key: W }))
124
124
  },
125
- String(a.id)
125
+ String(t.id)
126
126
  ))
127
127
  ] })
128
128
  ] }) }),
129
- N && /* @__PURE__ */ r(
130
- $,
129
+ D && /* @__PURE__ */ r(
130
+ tt,
131
131
  {
132
- language: i,
133
- currentPage: t ? +t.page : 1,
134
- recordsPerPage: t ? +t.limit : 10,
132
+ language: n,
133
+ currentPage: a ? +a.page : 1,
134
+ recordsPerPage: a ? +a.limit : 10,
135
135
  pagesCount: +q,
136
136
  addParam: d,
137
137
  total: +V
@@ -140,5 +140,5 @@ function ha({
140
140
  ] });
141
141
  }
142
142
  export {
143
- ha as Table
143
+ Lt as Table
144
144
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alphakits/ui",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "files": [
5
5
  "dist"
6
6
  ],