@alphakits/ui 2.4.1 → 2.4.3

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,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, { useCallback as I, useEffect as S } from "react";
2
- import { v4 as b } from "uuid";
3
- import { deletePropertyById as g } from "../utils/delete-property-by-id.js";
4
- const x = (c) => {
5
- const [r, l] = n.useState([]), [u, M] = n.useState(""), [p, a] = n.useState({}), f = (t) => {
6
- a((o) => g(o, t)), l((o) => o.filter((e) => e.id !== t));
7
- }, i = (t) => {
8
- l((o) => [...o, t]);
9
- }, m = I((t, o) => {
10
- t && a((e) => e[t] === o ? e : {
11
- ...e,
12
- [t]: o
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
13
15
  });
14
16
  }, []);
15
- return S(() => {
17
+ return b(() => {
16
18
  const t = [...r].pop()?.id;
17
- M(t || ""), document.body.style.overflow = r.length ? "hidden" : "unset";
19
+ f(t || ""), document.body.style.overflow = r.length ? "hidden" : "unset";
18
20
  }, [r]), {
19
- openModal: (t, o = "s", e = !0) => {
20
- const y = (s, d) => ({
21
- id: b(),
22
- modal: t,
23
- props: {
24
- size: o,
25
- showCloser: e,
26
- closeCallback: d,
27
- t: c,
28
- ...s
29
- }
30
- });
31
- return (s, d) => {
32
- i(y(s, d));
33
- };
34
- },
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
+ ),
35
38
  modals: r,
36
39
  setModalDirty: m,
37
- currentModalId: u,
40
+ currentModalId: M,
38
41
  dirtyModals: p,
39
- closeModal: f
42
+ closeModal: i
40
43
  };
41
44
  };
42
45
  export {
@@ -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,117 +1,123 @@
1
- import { useState as u, useCallback as c, useEffect as b } from "react";
2
- import { addQueryParam as I } from "../utils/add-query-param.js";
3
- import { getQueryFromUrl as R } from "../utils/get-query-from-url.js";
1
+ import { useState as u, useRef as b, useCallback as l, useEffect as E } from "react";
2
+ import { addQueryParam as h } from "../utils/add-query-param.js";
3
+ import { getQueryFromUrl as j } from "../utils/get-query-from-url.js";
4
4
  import "query-string";
5
- import { removeQueryParam as V } from "../utils/remove-query-param.js";
6
- import { resetQueryParam as Y } from "../utils/reset-query-param.js";
7
- import { serializeData as v } from "../utils/serialize-data.js";
8
- const A = {
5
+ import { removeQueryParam as B } from "../utils/remove-query-param.js";
6
+ import { resetQueryParam as G } from "../utils/reset-query-param.js";
7
+ import { serializeData as C } from "../utils/serialize-data.js";
8
+ const p = {
9
9
  page: 1,
10
10
  limit: 10,
11
11
  where: {}
12
12
  // остальное добавится по мере нужды (searchText, sort, order и т.д.)
13
13
  };
14
- function E(f, s) {
15
- const r = f ?? A, a = {
14
+ function L(w, a) {
15
+ const r = w ?? p, n = {
16
16
  ...r,
17
- ...s,
17
+ ...a,
18
18
  where: {
19
19
  ...r.where ?? {},
20
- ...s.where ?? {}
20
+ ...a.where ?? {}
21
21
  }
22
22
  };
23
- return a.page && (a.page = +a.page), a.limit && (a.limit = +a.limit), a;
23
+ return n.page && (n.page = +n.page), n.limit && (n.limit = +n.limit), n;
24
24
  }
25
- function M({ promise: f, records: s, fromPath: r = !0 }) {
26
- const [a, Q] = u([]), [C, w] = u(!0), [L, d] = u(!1), [S, T] = u(0), [U, q] = u(1), [i, y] = u(void 0), m = c(
27
- (t) => r ? R() : t ?? i ?? A,
25
+ function X({ promise: w, records: a, fromPath: r = !0 }) {
26
+ const [n, A] = u([]), [S, d] = u(!0), [T, Q] = u(!1), [U, q] = u(0), [F, k] = u(1), [c, f] = u(void 0), x = b(w);
27
+ x.current = w;
28
+ const v = b(a);
29
+ v.current = a;
30
+ const m = l(
31
+ (t) => r ? j() : t ?? c ?? p,
28
32
  // params не включаем при fromPath: иначе setParams на каждом fetch
29
33
  // даёт новую ссылку → computeQuery/updateData меняются → бесконечный цикл.
30
- r ? [r] : [r, i]
31
- ), n = c(
34
+ r ? [r] : [r, c]
35
+ ), s = l(
32
36
  async (t) => {
33
- const e = m(t);
34
- if (Array.isArray(s) && (w(!1), Q(v(s, e))), r || y(e), f) {
35
- d(!1), w(!0);
37
+ const e = m(t), i = v.current, y = x.current;
38
+ if (Array.isArray(i) && (d(!1), A(C(i, e))), r || f(e), y) {
39
+ Q(!1), d(!0);
36
40
  try {
37
41
  const {
38
42
  data: { items: o, meta: g }
39
- } = await f(e);
40
- T(g.totalItems), q(g.totalPages), Q(o || []);
43
+ } = await y(e);
44
+ q(g.totalItems), k(g.totalPages), A(o || []);
41
45
  } catch {
42
- d(!0);
46
+ Q(!0);
43
47
  } finally {
44
- w(!1);
48
+ d(!1);
45
49
  }
46
50
  }
47
51
  },
48
- [m, s, f]
49
- ), F = c(
52
+ [m, r]
53
+ ), z = l(
50
54
  (t) => {
51
55
  if (r) {
52
- I(t), n();
56
+ h(t), s();
53
57
  return;
54
58
  }
55
- const e = E(i, t);
56
- y(e), n(e);
59
+ const e = L(c, t);
60
+ f(e), s(e);
57
61
  },
58
- [r, i, n]
59
- ), p = c(
60
- (t, e, o) => {
61
- const g = t ?? A, l = {
62
- ...g,
63
- where: { ...g.where ?? {} }
64
- }, x = l.where?.[e];
65
- if (Array.isArray(x) && o != null) {
66
- const D = x.filter((z) => String(z) !== String(o));
67
- D.length ? l.where[e] = D : delete l.where[e];
62
+ [r, c, s]
63
+ ), D = l(
64
+ (t, e, i) => {
65
+ const y = t ?? p, o = {
66
+ ...y,
67
+ where: { ...y.where ?? {} }
68
+ }, g = o.where?.[e];
69
+ if (Array.isArray(g) && i != null) {
70
+ const R = g.filter((_) => String(_) !== String(i));
71
+ R.length ? o.where[e] = R : delete o.where[e];
68
72
  } else
69
- l.where && e in l.where && delete l.where[e];
70
- return l;
73
+ o.where && e in o.where && delete o.where[e];
74
+ return o;
71
75
  },
72
76
  []
73
- ), h = c(
77
+ ), I = l(
74
78
  (t, e) => {
75
79
  if (r) {
76
- V(t, e), n();
80
+ B(t, e), s();
77
81
  return;
78
82
  }
79
- const o = p(i, t, e);
80
- y(o), n(o);
83
+ const i = D(c, t, e);
84
+ f(i), s(i);
81
85
  },
82
- [r, i, n, p]
83
- ), k = c(
86
+ [r, c, s, D]
87
+ ), V = l(
84
88
  (t) => {
85
89
  if (r) {
86
- Y(t), n();
90
+ G(t), s();
87
91
  return;
88
92
  }
89
- const e = E(A, t);
90
- y(e), n(e);
93
+ const e = L(p, t);
94
+ f(e), s(e);
91
95
  },
92
- [r, n]
96
+ [r, s]
93
97
  );
94
- return b(() => {
95
- n();
96
- }, [n]), b(() => {
97
- if (Array.isArray(s)) {
98
+ E(() => {
99
+ s();
100
+ }, [s]), E(() => {
101
+ if (Array.isArray(a)) {
98
102
  const t = m();
99
- r || y(t), w(!1), Q(v(s, t));
103
+ r || f(t), d(!1), A(C(a, t));
100
104
  }
101
- }, [s, m]), {
102
- loading: C,
103
- error: L,
104
- data: a,
105
- total: S,
106
- params: i,
107
- pagesCount: U,
108
- updateData: n,
105
+ }, [a, m]);
106
+ const Y = c ?? m();
107
+ return {
108
+ loading: S,
109
+ error: T,
110
+ data: n,
111
+ total: U,
112
+ params: Y,
113
+ pagesCount: F,
114
+ updateData: s,
109
115
  // НОВОЕ: наружу отдаём универсальные методы для управления параметрами
110
- addParam: F,
111
- removeParam: h,
112
- resetParams: k
116
+ addParam: z,
117
+ removeParam: I,
118
+ resetParams: V
113
119
  };
114
120
  }
115
121
  export {
116
- M as useTableData
122
+ X as useTableData
117
123
  };
@@ -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))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alphakits/ui",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "files": [
5
5
  "dist"
6
6
  ],