@alphakits/ui 2.5.8 → 2.5.10

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,157 +1,170 @@
1
- import { jsx as w, jsxs as V } from "react/jsx-runtime";
2
- import P from "classnames";
3
- import { forwardRef as X, useRef as Y, useState as _, useEffect as tt, useCallback as d, Fragment as et } from "react";
4
- import { getCurrencySymbol as nt } from "../utils/get-currency-symbol/util.js";
5
- import { Input as rt } from "../input/component.js";
6
- import { THINSP as b, isCurrencyFirst as st } from "../utils/format-amount/util.js";
7
- import { withSuffix as it } from "../with-suffix/component.js";
1
+ import { jsxs as p, jsx as M } from "react/jsx-runtime";
2
+ import j from "classnames";
3
+ import { forwardRef as rt, useRef as O, useState as P, useEffect as it, useCallback as S, useLayoutEffect as st, Fragment as at } from "react";
4
+ import { getCurrencySymbol as ot } from "../utils/get-currency-symbol/util.js";
5
+ import { Input as ct } from "../input/component.js";
6
+ import { THINSP as $, isCurrencyFirst as lt } from "../utils/format-amount/util.js";
7
+ import { withSuffix as ut } from "../with-suffix/component.js";
8
8
  import i from "./index.module.css.js";
9
- import { formatAmountInputValue as q, getAmountValueFromStr as ot, isPhantomZeroDisplay as x, normalizeAmountDisplay as at, getFormattedValue as ct } from "./utils/index.js";
10
- const lt = it(rt), Vt = X(
9
+ import { formatAmountInputValue as T, getAmountValueFromStr as mt, isPhantomZeroDisplay as z, stripAmountFormatting as g, normalizeAmountDisplay as ft, shouldShowMinorPart as dt, getFormattedValue as pt, getRawCaretIndex as ht, getCaretPositionForRawIndex as wt, isWholeAmountType as St } from "./utils/index.js";
10
+ const xt = ut(ct), Et = rt(
11
11
  ({
12
12
  value: o = null,
13
- integerLength: j = 9,
14
- suffix: a = "RUR",
15
- placeholder: z = "0",
16
- bold: D = !0,
17
- type: u = "default",
18
- className: W,
19
- focusedClassName: k,
20
- required: v,
21
- dataTestId: B,
22
- clear: H = !1,
23
- allowNegative: A = !1,
24
- onChange: c,
25
- onClear: p,
26
- onBlur: h,
27
- onFocus: S,
28
- ...L
29
- }, M) => {
30
- const l = u === "default", g = Y(!1), [n, m] = _(
31
- () => q(o, u, a)
13
+ integerLength: C = 9,
14
+ suffix: c = "RUR",
15
+ placeholder: k = "0",
16
+ bold: V = !0,
17
+ type: s = "default",
18
+ className: v,
19
+ focusedClassName: B,
20
+ required: H,
21
+ dataTestId: U,
22
+ clear: Z = !1,
23
+ allowNegative: E = !1,
24
+ onChange: l,
25
+ onClear: x,
26
+ onBlur: F,
27
+ onFocus: A,
28
+ ...u
29
+ }, G) => {
30
+ const R = St(s), y = O(!1), [r, f] = P(
31
+ () => T(o, s, c)
32
32
  );
33
- tt(() => {
34
- g.current || m(q(o, u, a));
35
- }, [o, u, a]);
36
- const F = d(
33
+ it(() => {
34
+ y.current || f(T(o, s, c));
35
+ }, [o, s, c]);
36
+ const I = S(
37
37
  (e, t) => {
38
- c && c(e, {
39
- value: ot(t, l),
38
+ l && l(e, {
39
+ value: mt(t, s),
40
40
  valueString: t
41
41
  });
42
42
  },
43
- [l, c]
44
- ), T = (e) => {
43
+ [l, s]
44
+ ), J = (e) => {
45
45
  const t = e.target;
46
- let r = t.value.replace(/\s/g, "").replace(".", ",");
47
- const O = n.replace(/\s/g, "");
48
- x(O) && /^-?0[1-9](?!,)/.test(r.replace(/\s/g, "")) && (r = r.replace(/^(-?)0([1-9])/, "$1$2"));
49
- const I = r.startsWith("-");
50
- if (I) {
51
- if (!A) {
52
- const s = t.selectionStart - 1;
46
+ let n = g(t.value);
47
+ const et = g(r);
48
+ z(et) && /^-?0[1-9](?!,)/.test(n) && (n = n.replace(/^(-?)0([1-9])/, "$1$2"));
49
+ const D = n.startsWith("-");
50
+ if (D) {
51
+ if (!E) {
52
+ const a = t.selectionStart - 1;
53
53
  window.requestAnimationFrame(() => {
54
- t.selectionStart = s, t.selectionEnd = s;
54
+ t.selectionStart = a, t.selectionEnd = a;
55
55
  });
56
56
  return;
57
57
  }
58
- r = r.slice(1);
58
+ n = n.slice(1);
59
59
  }
60
- if (!RegExp(`(^[0-9]{1,${j}}(,([0-9]+)?)?$|^\\s*$)`).test(
61
- r
62
- )) {
63
- const s = t.selectionStart - 1;
60
+ if (!(R ? RegExp(`(^[0-9]{1,${C}}$|^\\s*$)`).test(n) : RegExp(`(^[0-9]{1,${C}}(,([0-9]+)?)?$|^\\s*$)`).test(
61
+ n
62
+ ))) {
63
+ const a = t.selectionStart - 1;
64
64
  window.requestAnimationFrame(() => {
65
- t.selectionStart = s, t.selectionEnd = s;
65
+ t.selectionStart = a, t.selectionEnd = a;
66
66
  });
67
67
  return;
68
68
  }
69
- I && A && (r = `-${r}`);
70
- const f = ct(r, l);
71
- if (f === n) {
72
- const s = t.selectionStart;
73
- window.requestAnimationFrame(() => {
74
- t.selectionStart = s, t.selectionEnd = s;
75
- });
76
- } else {
77
- const [s, R] = r.replace("-", "").split(/\.|,/);
78
- let $ = s.length;
79
- R && ($ += 1 + R.slice(0, 2).length);
80
- const Q = f.length - $, C = t.selectionStart + Q;
81
- window.requestAnimationFrame(() => {
82
- t.selectionStart = C, t.selectionEnd = C;
83
- });
69
+ D && E && (n = `-${n}`);
70
+ const N = pt(n, s), nt = ht(t.value, t.selectionStart ?? 0);
71
+ f(N), I(e, N), window.requestAnimationFrame(() => {
72
+ const a = wt(N, nt);
73
+ t.selectionStart = a, t.selectionEnd = a;
74
+ });
75
+ }, h = r.replace(/^-/, ""), K = r.startsWith("-"), d = h.indexOf(","), L = d === -1 ? h : h.slice(0, d), W = d === -1 ? void 0 : h.slice(d + 1), Q = !R && d !== -1, w = ot(c) || c, m = lt(c), b = O(null), [X, q] = P(0);
76
+ st(() => {
77
+ if (!m) {
78
+ q(0);
79
+ return;
84
80
  }
85
- m(f), F(e, f);
86
- }, U = d(
81
+ const e = b.current;
82
+ e && q(e.offsetWidth);
83
+ }, [m, w, V]);
84
+ const Y = S(
87
85
  (e) => {
88
- g.current = !0, x(n) && (o == null || o === 0) && m(""), S && S(e);
86
+ y.current = !0;
87
+ const t = e.currentTarget;
88
+ z(g(r)) && (o == null || o === 0) && f(""), !u.readOnly && !u.disabled && window.requestAnimationFrame(() => {
89
+ t.select();
90
+ }), A && A(e);
89
91
  },
90
- [n, S, o]
91
- ), Z = d(
92
+ [r, A, u.disabled, u.readOnly, o]
93
+ ), _ = S(
92
94
  (e) => {
93
- g.current = !1;
94
- const t = at(n, l);
95
- t !== n && (m(t), F(e, t)), h && h(e);
95
+ y.current = !1;
96
+ const t = ft(r, s);
97
+ t !== r && (f(t), I(e, t)), F && F(e);
96
98
  },
97
- [F, n, l, h]
98
- ), G = d(
99
+ [I, r, F, s]
100
+ ), tt = S(
99
101
  (e) => {
100
- m(""), c && c(
102
+ f(""), l && l(
101
103
  e,
102
104
  {
103
105
  value: null,
104
106
  valueString: ""
105
107
  }
106
- ), p && p(e);
108
+ ), x && x(e);
107
109
  },
108
- [c, p]
109
- ), [J, N] = n.replace("-", "").split(","), K = n.startsWith("-"), y = nt(a) || a, E = st(a);
110
- return /* @__PURE__ */ w(
110
+ [l, x]
111
+ );
112
+ return /* @__PURE__ */ p(
111
113
  "div",
112
114
  {
113
- className: P(i.container, {
114
- [i.bold]: D,
115
- [i.filled]: !!n
115
+ className: j(i.container, {
116
+ [i.bold]: V,
117
+ [i.filled]: !!r
116
118
  }),
117
- children: /* @__PURE__ */ w(
118
- lt,
119
- {
120
- ...L,
121
- suffix: /* @__PURE__ */ V(et, { children: [
122
- E && /* @__PURE__ */ V("span", { className: i.currency, children: [
123
- y,
124
- b
119
+ children: [
120
+ m && /* @__PURE__ */ p("span", { ref: b, className: i.prefixMeasure, "aria-hidden": !0, children: [
121
+ w,
122
+ $
123
+ ] }),
124
+ /* @__PURE__ */ M(
125
+ xt,
126
+ {
127
+ ...u,
128
+ autoComplete: "off",
129
+ style: {
130
+ ...u.style,
131
+ ...m ? { textIndent: X } : null
132
+ },
133
+ suffix: /* @__PURE__ */ p(at, { children: [
134
+ m && /* @__PURE__ */ p("span", { className: i.currency, children: [
135
+ w,
136
+ $
137
+ ] }),
138
+ K && "-",
139
+ L,
140
+ Q && /* @__PURE__ */ M("span", { className: i.minorPart, children: dt(W) ? `,${W}` : "," }),
141
+ !m && /* @__PURE__ */ p("span", { className: i.currency, children: [
142
+ $,
143
+ w
144
+ ] })
125
145
  ] }),
126
- K && "-",
127
- J,
128
- N !== void 0 && /* @__PURE__ */ w("span", { className: i.minorPart, children: `,${N}` }),
129
- !E && /* @__PURE__ */ V("span", { className: i.currency, children: [
130
- b,
131
- y
132
- ] })
133
- ] }),
134
- suffixContainerClassName: i.suffixContainer,
135
- clear: H,
136
- required: v,
137
- placeholder: z,
138
- value: n,
139
- className: P(i.component, W),
140
- focusedClassName: k,
141
- inputClassName: i.input,
142
- inputMode: "decimal",
143
- onChange: T,
144
- onFocus: U,
145
- onBlur: Z,
146
- onClear: G,
147
- dataTestId: B,
148
- ref: M
149
- }
150
- )
146
+ suffixContainerClassName: i.suffixContainer,
147
+ clear: Z,
148
+ required: H,
149
+ placeholder: k,
150
+ value: r,
151
+ className: j(i.component, v),
152
+ focusedClassName: B,
153
+ inputClassName: i.input,
154
+ inputMode: R ? "numeric" : "decimal",
155
+ onChange: J,
156
+ onFocus: Y,
157
+ onBlur: _,
158
+ onClear: tt,
159
+ dataTestId: U,
160
+ ref: G
161
+ }
162
+ )
163
+ ]
151
164
  }
152
165
  );
153
166
  }
154
167
  );
155
168
  export {
156
- Vt as AmountInput
169
+ Et as AmountInput
157
170
  };
@@ -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)}:root{--amount-input-minor-part-and-currency-color: var(--color-text-secondary)}.container_AHkd{position:relative}.minorPart_Yv3O,.currency_ROce{color:var(--amount-input-minor-part-and-currency-color)}.suffixContainer_J46v>*:first-child{display:none}.filled_GrmG .input_Ims0,.input_Ims0:focus{-webkit-text-fill-color:transparent;caret-color:currentColor;font-size:16px!important}.bold_tpPh .input_Ims0,.bold_tpPh .suffix{font-weight:700}
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)}:root{--amount-input-minor-part-and-currency-color: var(--color-text-secondary)}.container_AHkd{position:relative}.minorPart_Yv3O,.currency_ROce{color:var(--amount-input-minor-part-and-currency-color)}.suffixContainer_J46v>*:first-child{display:none}.prefixMeasure_o-kM{font-size:16px!important;line-height:20px;font-weight:400;font-family:var(--font-family);position:absolute;visibility:hidden;pointer-events:none;white-space:pre;font-size:16px}.bold_tpPh .prefixMeasure_o-kM{font-weight:700}.filled_GrmG .input_Ims0,.input_Ims0:focus{-webkit-text-fill-color:transparent;caret-color:currentColor;font-size:16px!important}.bold_tpPh .input_Ims0,.bold_tpPh .suffix{font-weight:700}
@@ -1,21 +1,23 @@
1
1
  import * as __css from './index.css';
2
2
  export const __cssModule = __css;
3
- const n = "container_AHkd", t = "minorPart_Yv3O", o = "currency_ROce", r = "suffixContainer_J46v", c = "filled_GrmG", i = "input_Ims0", e = "bold_tpPh", s = {
3
+ const n = "container_AHkd", r = "minorPart_Yv3O", e = "currency_ROce", t = "suffixContainer_J46v", o = "prefixMeasure_o-kM", i = "bold_tpPh", c = "filled_GrmG", s = "input_Ims0", a = {
4
4
  container: n,
5
- minorPart: t,
6
- currency: o,
7
- suffixContainer: r,
5
+ minorPart: r,
6
+ currency: e,
7
+ suffixContainer: t,
8
+ prefixMeasure: o,
9
+ bold: i,
8
10
  filled: c,
9
- input: i,
10
- bold: e
11
+ input: s
11
12
  };
12
13
  export {
13
- e as bold,
14
+ i as bold,
14
15
  n as container,
15
- o as currency,
16
- s as default,
16
+ e as currency,
17
+ a as default,
17
18
  c as filled,
18
- i as input,
19
- t as minorPart,
20
- r as suffixContainer
19
+ s as input,
20
+ r as minorPart,
21
+ o as prefixMeasure,
22
+ t as suffixContainer
21
23
  };
@@ -1,7 +1,13 @@
1
1
  import { CurrencyCodes } from '../../utils/data/currency-codes';
2
2
  import { AmountValueType } from '../../utils/format-amount/util';
3
+ export declare function isWholeAmountType(amountType: AmountValueType): boolean;
4
+ export declare function stripAmountFormatting(str: string): string;
5
+ export declare function getRawCaretIndex(value: string, caret: number): number;
6
+ export declare function getCaretPositionForRawIndex(formatted: string, rawIndex: number): number;
7
+ export declare function hideZeroMinorPart(formatted: string): string;
8
+ export declare function shouldShowMinorPart(minorPart: string | undefined): boolean;
3
9
  export declare function formatAmountInputValue(value: number | null | undefined, amountType: AmountValueType, currency: CurrencyCodes): string;
4
- export declare function getFormattedValue(enteredValue: string, integer: boolean): string;
5
- export declare function getAmountValueFromStr(str: string, integer: boolean): number | null;
6
- export declare function normalizeAmountDisplay(str: string, integer: boolean): string;
10
+ export declare function getFormattedValue(enteredValue: string, amountType: AmountValueType): string;
11
+ export declare function getAmountValueFromStr(str: string, amountType: AmountValueType): number | null;
12
+ export declare function normalizeAmountDisplay(str: string, amountType: AmountValueType): string;
7
13
  export declare function isPhantomZeroDisplay(str: string): boolean;
@@ -1,48 +1,98 @@
1
- import { formatAmount as a } from "../../utils/format-amount/util.js";
2
- function f(t, i, e) {
1
+ import { formatAmount as d, THINSP as p } from "../../utils/format-amount/util.js";
2
+ import { splitAmount as h } from "../../utils/split-amount/util.js";
3
+ const m = /* @__PURE__ */ new Set([" ", p]), N = 3, A = 4;
4
+ function c(t) {
5
+ return t === "default";
6
+ }
7
+ function l(t) {
8
+ return t.split("").filter((r) => !m.has(r)).join("").replace(".", ",");
9
+ }
10
+ function $(t) {
11
+ const r = l(t).replace(/\D/g, "");
12
+ if (!r)
13
+ return "0";
14
+ const e = r.replace(/^0+(?=\d)/, "") || r;
15
+ return h(e, N, p, A);
16
+ }
17
+ function R(t, r) {
18
+ return l(t.slice(0, r)).length;
19
+ }
20
+ function _(t, r) {
21
+ if (r <= 0)
22
+ return t.startsWith("-") ? 1 : 0;
23
+ let e = 0;
24
+ for (let n = 0; n < t.length; n++) {
25
+ const o = t[n];
26
+ if (!m.has(o) && (e += 1, e >= r))
27
+ return n + 1;
28
+ }
29
+ return t.length;
30
+ }
31
+ function g(t) {
32
+ return t.endsWith(",00") ? t.slice(0, -3) : t;
33
+ }
34
+ function D(t) {
35
+ return t !== void 0 && t !== "" && t !== "00";
36
+ }
37
+ function F(t, r, e) {
3
38
  if (t == null)
4
39
  return "";
5
- const n = i === "default" ? t : t / 100;
6
- return a({
40
+ const n = c(r) ? t : t / 100, o = d({
7
41
  value: n,
8
42
  currency: e,
9
43
  type: "default"
10
44
  }).formatted;
45
+ return c(r) ? o : g(o);
11
46
  }
12
- function l(t, i) {
47
+ function M(t, r) {
13
48
  if (!t) return t;
14
- const e = t.startsWith("-"), [n, r] = t.replace("-", "").split(","), o = n.replace(/^0+(?=\d)/, "") || n, { majorPart: u } = a({
15
- value: Number(o),
16
- currency: "RUR",
17
- type: "default"
18
- });
19
- return i ? e ? `-${u}` : u : !r && t.includes(",") ? e ? `-${u},` : `${u},` : r ? e ? `-${u},${r.slice(0, 2)}` : `${u},${r.slice(0, 2)}` : e ? `-${u}` : u;
49
+ const e = l(t), n = e.startsWith("-"), o = n ? e.slice(1) : e, [f, u] = o.split(","), i = $(f);
50
+ if (c(r))
51
+ return n ? `-${i}` : i;
52
+ if (!u && e.includes(","))
53
+ return n ? `-${i},` : `${i},`;
54
+ if (u) {
55
+ const s = u.slice(0, 2);
56
+ return s === "00" && u.length >= 2 ? n ? `-${i}` : i : n ? `-${i},${s}` : `${i},${s}`;
57
+ }
58
+ return n ? `-${i}` : i;
20
59
  }
21
- function s(t, i) {
60
+ function I(t, r) {
22
61
  if (!t) return null;
23
- const e = t.startsWith("-"), n = t.replace(/[^0-9,]/g, "").replace(",", "."), r = Number(n);
24
- if (Number.isNaN(r)) return null;
25
- const o = Math.round(i ? r : r * 100);
26
- return e ? -o : o;
62
+ const e = l(t), n = e.startsWith("-"), o = e.replace(/^-/, "");
63
+ if (c(r)) {
64
+ const s = o.replace(/\D/g, "");
65
+ if (!s) return null;
66
+ const a = Number(s);
67
+ return Number.isNaN(a) ? null : n ? -a : a;
68
+ }
69
+ const f = o.replace(",", "."), u = Number(f);
70
+ if (Number.isNaN(u)) return null;
71
+ const i = Math.round(u * 100);
72
+ return n ? -i : i;
27
73
  }
28
- function m(t, i) {
74
+ function P(t, r) {
29
75
  if (!t || t === "-" || t === "-," || !t.replace(/[^0-9]/g, ""))
30
76
  return "";
31
- let n = l(t, i);
32
- if (i)
77
+ let n = M(t, r);
78
+ if (c(r) || !n.includes(","))
33
79
  return n;
34
- if (!n.includes(","))
35
- return `${n},00`;
36
- const [, r = ""] = n.split(",");
37
- return r ? r.length === 1 ? `${n}0` : n : `${n}00`;
80
+ const [, o = ""] = n.split(",");
81
+ return o ? (o.length === 1 && (n = `${n}0`), g(n)) : n.replace(/,$/, "");
38
82
  }
39
- function p(t) {
40
- return t.replace(/\s/g, "") === "0";
83
+ function T(t) {
84
+ return l(t) === "0";
41
85
  }
42
86
  export {
43
- f as formatAmountInputValue,
44
- s as getAmountValueFromStr,
45
- l as getFormattedValue,
46
- p as isPhantomZeroDisplay,
47
- m as normalizeAmountDisplay
87
+ F as formatAmountInputValue,
88
+ I as getAmountValueFromStr,
89
+ _ as getCaretPositionForRawIndex,
90
+ M as getFormattedValue,
91
+ R as getRawCaretIndex,
92
+ g as hideZeroMinorPart,
93
+ T as isPhantomZeroDisplay,
94
+ c as isWholeAmountType,
95
+ P as normalizeAmountDisplay,
96
+ D as shouldShowMinorPart,
97
+ l as stripAmountFormatting
48
98
  };
@@ -18,7 +18,7 @@ export declare const Toast: import('react').ForwardRefExoticComponent<import('re
18
18
  hasCloser?: boolean | undefined;
19
19
  block?: boolean | undefined;
20
20
  onClose?: ((event?: import('react').MouseEvent<HTMLButtonElement, MouseEvent> | undefined) => void) | undefined;
21
- } & Pick<PopoverProps, "open" | "getPortalContainer" | "transition" | "offset" | "position" | "preventFlip"> & {
21
+ } & Pick<PopoverProps, "open" | "getPortalContainer" | "position" | "transition" | "offset" | "preventFlip"> & {
22
22
  anchorElement?: HTMLElement | undefined;
23
23
  autoCloseDelay?: number | undefined;
24
24
  onClose: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alphakits/ui",
3
- "version": "2.5.8",
3
+ "version": "2.5.10",
4
4
  "files": [
5
5
  "dist"
6
6
  ],