@alphakits/ui 2.4.1 → 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,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,115 +1,117 @@
1
- import { useState as u, useCallback as c, useEffect as b } from "react";
1
+ import { useState as u, useCallback as c, useEffect as D } from "react";
2
2
  import { addQueryParam as I } from "../utils/add-query-param.js";
3
3
  import { getQueryFromUrl as R } from "../utils/get-query-from-url.js";
4
4
  import "query-string";
5
5
  import { removeQueryParam as V } from "../utils/remove-query-param.js";
6
6
  import { resetQueryParam as Y } from "../utils/reset-query-param.js";
7
- import { serializeData as v } from "../utils/serialize-data.js";
8
- const A = {
7
+ import { serializeData as b } from "../utils/serialize-data.js";
8
+ const d = {
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 E(f, n) {
15
+ const r = f ?? d, a = {
16
16
  ...r,
17
- ...s,
17
+ ...n,
18
18
  where: {
19
19
  ...r.where ?? {},
20
- ...s.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 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 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
28
  // params не включаем при fromPath: иначе setParams на каждом fetch
29
29
  // даёт новую ссылку → computeQuery/updateData меняются → бесконечный цикл.
30
- r ? [r] : [r, i]
31
- ), n = c(
30
+ r ? [r] : [r, o]
31
+ ), s = c(
32
32
  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);
33
+ const e = y(t);
34
+ if (Array.isArray(n) && (w(!1), p(b(n, e))), m(e), f) {
35
+ A(!1), w(!0);
36
36
  try {
37
37
  const {
38
- data: { items: o, meta: g }
38
+ data: { items: i, meta: g }
39
39
  } = await f(e);
40
- T(g.totalItems), q(g.totalPages), Q(o || []);
40
+ S(g.totalItems), U(g.totalPages), p(i || []);
41
41
  } catch {
42
- d(!0);
42
+ A(!0);
43
43
  } finally {
44
44
  w(!1);
45
45
  }
46
46
  }
47
47
  },
48
- [m, s, f]
49
- ), F = c(
48
+ [y, n, f]
49
+ ), q = c(
50
50
  (t) => {
51
51
  if (r) {
52
- I(t), n();
52
+ I(t), s();
53
53
  return;
54
54
  }
55
- const e = E(i, t);
56
- y(e), n(e);
55
+ const e = E(o, t);
56
+ m(e), s(e);
57
57
  },
58
- [r, i, n]
59
- ), p = c(
60
- (t, e, o) => {
61
- const g = t ?? A, l = {
58
+ [r, o, s]
59
+ ), Q = c(
60
+ (t, e, i) => {
61
+ const g = t ?? d, l = {
62
62
  ...g,
63
63
  where: { ...g.where ?? {} }
64
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];
65
+ if (Array.isArray(x) && i != null) {
66
+ const v = x.filter((z) => String(z) !== String(i));
67
+ v.length ? l.where[e] = v : delete l.where[e];
68
68
  } else
69
69
  l.where && e in l.where && delete l.where[e];
70
70
  return l;
71
71
  },
72
72
  []
73
- ), h = c(
73
+ ), F = c(
74
74
  (t, e) => {
75
75
  if (r) {
76
- V(t, e), n();
76
+ V(t, e), s();
77
77
  return;
78
78
  }
79
- const o = p(i, t, e);
80
- y(o), n(o);
79
+ const i = Q(o, t, e);
80
+ m(i), s(i);
81
81
  },
82
- [r, i, n, p]
83
- ), k = c(
82
+ [r, o, s, Q]
83
+ ), P = c(
84
84
  (t) => {
85
85
  if (r) {
86
- Y(t), n();
86
+ Y(t), s();
87
87
  return;
88
88
  }
89
- const e = E(A, t);
90
- y(e), n(e);
89
+ const e = E(d, t);
90
+ m(e), s(e);
91
91
  },
92
- [r, n]
92
+ [r, s]
93
93
  );
94
- return b(() => {
95
- n();
96
- }, [n]), b(() => {
97
- if (Array.isArray(s)) {
98
- const t = m();
99
- r || y(t), w(!1), Q(v(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));
100
100
  }
101
- }, [s, m]), {
102
- loading: C,
103
- error: L,
101
+ }, [n, y]);
102
+ const k = o ?? y();
103
+ return {
104
+ loading: h,
105
+ error: C,
104
106
  data: a,
105
- total: S,
106
- params: i,
107
- pagesCount: U,
108
- updateData: n,
107
+ total: L,
108
+ params: k,
109
+ pagesCount: T,
110
+ updateData: s,
109
111
  // НОВОЕ: наружу отдаём универсальные методы для управления параметрами
110
- addParam: F,
111
- removeParam: h,
112
- resetParams: k
112
+ addParam: q,
113
+ removeParam: F,
114
+ resetParams: P
113
115
  };
114
116
  }
115
117
  export {
@@ -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.2",
4
4
  "files": [
5
5
  "dist"
6
6
  ],