@hortiview/shared-components 0.0.10589 → 0.0.11114

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.
@@ -0,0 +1,561 @@
1
+ import Q, { useRef as X, useState as xe, useEffect as ve, useMemo as Re, useLayoutEffect as _e } from "react";
2
+ function pe(e, r) {
3
+ var a = {};
4
+ for (var n in e)
5
+ Object.prototype.hasOwnProperty.call(e, n) && r.indexOf(n) < 0 && (a[n] = e[n]);
6
+ if (e != null && typeof Object.getOwnPropertySymbols == "function")
7
+ for (var t = 0, n = Object.getOwnPropertySymbols(e); t < n.length; t++)
8
+ r.indexOf(n[t]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[t]) && (a[n[t]] = e[n[t]]);
9
+ return a;
10
+ }
11
+ var ae;
12
+ (function(e) {
13
+ e.event = "event", e.props = "prop";
14
+ })(ae || (ae = {}));
15
+ function Z() {
16
+ }
17
+ function Fe(e) {
18
+ var r, a = void 0;
19
+ return function() {
20
+ for (var n = [], t = arguments.length; t--; )
21
+ n[t] = arguments[t];
22
+ return r && n.length === r.length && n.every(function(o, f) {
23
+ return o === r[f];
24
+ }) || (r = n, a = e.apply(void 0, n)), a;
25
+ };
26
+ }
27
+ function te(e) {
28
+ return !!(e || "").match(/\d/);
29
+ }
30
+ function Y(e) {
31
+ return e == null;
32
+ }
33
+ function Me(e) {
34
+ return typeof e == "number" && isNaN(e);
35
+ }
36
+ function Ve(e) {
37
+ return Y(e) || Me(e) || typeof e == "number" && !isFinite(e);
38
+ }
39
+ function ye(e) {
40
+ return e.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
41
+ }
42
+ function je(e) {
43
+ switch (e) {
44
+ case "lakh":
45
+ return /(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/g;
46
+ case "wan":
47
+ return /(\d)(?=(\d{4})+(?!\d))/g;
48
+ case "thousand":
49
+ default:
50
+ return /(\d)(?=(\d{3})+(?!\d))/g;
51
+ }
52
+ }
53
+ function Le(e, r, a) {
54
+ var n = je(a), t = e.search(/[1-9]/);
55
+ return t = t === -1 ? e.length : t, e.substring(0, t) + e.substring(t, e.length).replace(n, "$1" + r);
56
+ }
57
+ function ke(e) {
58
+ var r = X(e);
59
+ r.current = e;
60
+ var a = X(function() {
61
+ for (var n = [], t = arguments.length; t--; )
62
+ n[t] = arguments[t];
63
+ return r.current.apply(r, n);
64
+ });
65
+ return a.current;
66
+ }
67
+ function de(e, r) {
68
+ r === void 0 && (r = !0);
69
+ var a = e[0] === "-", n = a && r;
70
+ e = e.replace("-", "");
71
+ var t = e.split("."), o = t[0], f = t[1] || "";
72
+ return {
73
+ beforeDecimal: o,
74
+ afterDecimal: f,
75
+ hasNegation: a,
76
+ addNegation: n
77
+ };
78
+ }
79
+ function Pe(e) {
80
+ if (!e)
81
+ return e;
82
+ var r = e[0] === "-";
83
+ r && (e = e.substring(1, e.length));
84
+ var a = e.split("."), n = a[0].replace(/^0+/, "") || "0", t = a[1] || "";
85
+ return (r ? "-" : "") + n + (t ? "." + t : "");
86
+ }
87
+ function be(e, r, a) {
88
+ for (var n = "", t = a ? "0" : "", o = 0; o <= r - 1; o++)
89
+ n += e[o] || t;
90
+ return n;
91
+ }
92
+ function ge(e, r) {
93
+ return Array(r + 1).join(e);
94
+ }
95
+ function we(e) {
96
+ var r = e + "", a = r[0] === "-" ? "-" : "";
97
+ a && (r = r.substring(1));
98
+ var n = r.split(/[eE]/g), t = n[0], o = n[1];
99
+ if (o = Number(o), !o)
100
+ return a + t;
101
+ t = t.replace(".", "");
102
+ var f = 1 + o, m = t.length;
103
+ return f < 0 ? t = "0." + ge("0", Math.abs(f)) + t : f >= m ? t = t + ge("0", f - m) : t = (t.substring(0, f) || "0") + "." + t.substring(f), a + t;
104
+ }
105
+ function me(e, r, a) {
106
+ if (["", "-"].indexOf(e) !== -1)
107
+ return e;
108
+ var n = (e.indexOf(".") !== -1 || a) && r, t = de(e), o = t.beforeDecimal, f = t.afterDecimal, m = t.hasNegation, V = parseFloat("0." + (f || "0")), y = f.length <= r ? "0." + f : V.toFixed(r), S = y.split("."), g = o;
109
+ o && Number(S[0]) && (g = o.split("").reverse().reduce(function(I, C, s) {
110
+ return I.length > s ? (Number(I[0]) + Number(C)).toString() + I.substring(1, I.length) : C + I;
111
+ }, S[0]));
112
+ var h = be(S[1] || "", r, a), x = m ? "-" : "", v = n ? "." : "";
113
+ return "" + x + g + v + h;
114
+ }
115
+ function z(e, r) {
116
+ if (e.value = e.value, e !== null) {
117
+ if (e.createTextRange) {
118
+ var a = e.createTextRange();
119
+ return a.move("character", r), a.select(), !0;
120
+ }
121
+ return e.selectionStart || e.selectionStart === 0 ? (e.focus(), e.setSelectionRange(r, r), !0) : (e.focus(), !1);
122
+ }
123
+ }
124
+ var Ne = Fe(function(e, r) {
125
+ for (var a = 0, n = 0, t = e.length, o = r.length; e[a] === r[a] && a < t; )
126
+ a++;
127
+ for (; e[t - 1 - n] === r[o - 1 - n] && o - n > a && t - n > a; )
128
+ n++;
129
+ return {
130
+ from: { start: a, end: t - n },
131
+ to: { start: a, end: o - n }
132
+ };
133
+ }), Ke = function(e, r) {
134
+ var a = Math.min(e.selectionStart, r);
135
+ return {
136
+ from: { start: a, end: e.selectionEnd },
137
+ to: { start: a, end: r }
138
+ };
139
+ };
140
+ function Ue(e, r, a) {
141
+ return Math.min(Math.max(e, r), a);
142
+ }
143
+ function ce(e) {
144
+ return Math.max(e.selectionStart, e.selectionEnd);
145
+ }
146
+ function We() {
147
+ return typeof navigator < "u" && !(navigator.platform && /iPhone|iPod/.test(navigator.platform));
148
+ }
149
+ function $e(e) {
150
+ return {
151
+ from: {
152
+ start: 0,
153
+ end: 0
154
+ },
155
+ to: {
156
+ start: 0,
157
+ end: e.length
158
+ },
159
+ lastValue: ""
160
+ };
161
+ }
162
+ function Ge(e) {
163
+ var r = e.currentValue, a = e.formattedValue, n = e.currentValueIndex, t = e.formattedValueIndex;
164
+ return r[n] === a[t];
165
+ }
166
+ function Ze(e, r, a, n, t, o, f) {
167
+ f === void 0 && (f = Ge);
168
+ var m = t.findIndex(function(L) {
169
+ return L;
170
+ }), V = e.slice(0, m);
171
+ !r && !a.startsWith(V) && (r = V, a = V + a, n = n + V.length);
172
+ for (var y = a.length, S = e.length, g = {}, h = new Array(y), x = 0; x < y; x++) {
173
+ h[x] = -1;
174
+ for (var v = 0, I = S; v < I; v++) {
175
+ var C = f({
176
+ currentValue: a,
177
+ lastValue: r,
178
+ formattedValue: e,
179
+ currentValueIndex: x,
180
+ formattedValueIndex: v
181
+ });
182
+ if (C && g[v] !== !0) {
183
+ h[x] = v, g[v] = !0;
184
+ break;
185
+ }
186
+ }
187
+ }
188
+ for (var s = n; s < y && (h[s] === -1 || !o(a[s])); )
189
+ s++;
190
+ var T = s === y || h[s] === -1 ? S : h[s];
191
+ for (s = n - 1; s > 0 && h[s] === -1; )
192
+ s--;
193
+ var R = s === -1 || h[s] === -1 ? 0 : h[s] + 1;
194
+ return R > T ? T : n - R < T - n ? R : T;
195
+ }
196
+ function he(e, r, a, n) {
197
+ var t = e.length;
198
+ if (r = Ue(r, 0, t), n === "left") {
199
+ for (; r >= 0 && !a[r]; )
200
+ r--;
201
+ r === -1 && (r = a.indexOf(!0));
202
+ } else {
203
+ for (; r <= t && !a[r]; )
204
+ r++;
205
+ r > t && (r = a.lastIndexOf(!0));
206
+ }
207
+ return r === -1 && (r = t), r;
208
+ }
209
+ function qe(e) {
210
+ for (var r = Array.from({ length: e.length + 1 }).map(function() {
211
+ return !0;
212
+ }), a = 0, n = r.length; a < n; a++)
213
+ r[a] = !!(te(e[a]) || te(e[a - 1]));
214
+ return r;
215
+ }
216
+ function De(e, r, a, n, t, o) {
217
+ o === void 0 && (o = Z);
218
+ var f = ke(function(v, I) {
219
+ var C, s;
220
+ return Ve(v) ? (s = "", C = "") : typeof v == "number" || I ? (s = typeof v == "number" ? we(v) : v, C = n(s)) : (s = t(v, void 0), C = n(s)), { formattedValue: C, numAsString: s };
221
+ }), m = xe(function() {
222
+ return f(Y(e) ? r : e, a);
223
+ }), V = m[0], y = m[1], S = function(v, I) {
224
+ v.formattedValue !== V.formattedValue && y({
225
+ formattedValue: v.formattedValue,
226
+ numAsString: v.value
227
+ }), o(v, I);
228
+ }, g = e, h = a;
229
+ Y(e) && (g = V.numAsString, h = !0);
230
+ var x = f(g, h);
231
+ return Re(function() {
232
+ y(x);
233
+ }, [x.formattedValue]), [V, S];
234
+ }
235
+ function ze(e) {
236
+ return e.replace(/[^0-9]/g, "");
237
+ }
238
+ function He(e) {
239
+ return e;
240
+ }
241
+ function Je(e) {
242
+ var r = e.type;
243
+ r === void 0 && (r = "text");
244
+ var a = e.displayType;
245
+ a === void 0 && (a = "input");
246
+ var n = e.customInput, t = e.renderText, o = e.getInputRef, f = e.format;
247
+ f === void 0 && (f = He);
248
+ var m = e.removeFormatting;
249
+ m === void 0 && (m = ze);
250
+ var V = e.defaultValue, y = e.valueIsNumericString, S = e.onValueChange, g = e.isAllowed, h = e.onChange;
251
+ h === void 0 && (h = Z);
252
+ var x = e.onKeyDown;
253
+ x === void 0 && (x = Z);
254
+ var v = e.onMouseUp;
255
+ v === void 0 && (v = Z);
256
+ var I = e.onFocus;
257
+ I === void 0 && (I = Z);
258
+ var C = e.onBlur;
259
+ C === void 0 && (C = Z);
260
+ var s = e.value, T = e.getCaretBoundary;
261
+ T === void 0 && (T = qe);
262
+ var R = e.isValidInputCharacter;
263
+ R === void 0 && (R = te);
264
+ var L = e.isCharacterSame, F = pe(e, ["type", "displayType", "customInput", "renderText", "getInputRef", "format", "removeFormatting", "defaultValue", "valueIsNumericString", "onValueChange", "isAllowed", "onChange", "onKeyDown", "onMouseUp", "onFocus", "onBlur", "value", "getCaretBoundary", "isValidInputCharacter", "isCharacterSame"]), q = De(s, V, !!y, f, m, S), k = q[0], b = k.formattedValue, M = k.numAsString, K = q[1], j = X(), U = X({ formattedValue: b, numAsString: M }), W = function(i, u) {
265
+ U.current = { formattedValue: i.formattedValue, numAsString: i.value }, K(i, u);
266
+ }, H = xe(!1), ee = H[0], d = H[1], l = X(null), w = X({
267
+ setCaretTimeout: null,
268
+ focusTimeout: null
269
+ });
270
+ ve(function() {
271
+ return d(!0), function() {
272
+ clearTimeout(w.current.setCaretTimeout), clearTimeout(w.current.focusTimeout);
273
+ };
274
+ }, []);
275
+ var E = f, B = function(i, u) {
276
+ var c = parseFloat(u);
277
+ return {
278
+ formattedValue: i,
279
+ value: u,
280
+ floatValue: isNaN(c) ? void 0 : c
281
+ };
282
+ }, A = function(i, u, c) {
283
+ i.selectionStart === 0 && i.selectionEnd === i.value.length || (z(i, u), w.current.setCaretTimeout = setTimeout(function() {
284
+ i.value === c && i.selectionStart !== u && z(i, u);
285
+ }, 0));
286
+ }, O = function(i, u, c) {
287
+ return he(i, u, T(i), c);
288
+ }, J = function(i, u, c) {
289
+ var N = T(u), _ = Ze(u, b, i, c, N, R, L);
290
+ return _ = he(u, _, N), _;
291
+ }, oe = function(i) {
292
+ var u = i.formattedValue;
293
+ u === void 0 && (u = "");
294
+ var c = i.input, N = i.source, _ = i.event, D = i.numAsString, p;
295
+ if (c) {
296
+ var P = i.inputValue || c.value, $ = ce(c);
297
+ c.value = u, p = J(P, u, $), p !== void 0 && A(c, p, u);
298
+ }
299
+ u !== b && W(B(u, D), { event: _, source: N });
300
+ };
301
+ ve(function() {
302
+ var i = U.current, u = i.formattedValue, c = i.numAsString;
303
+ (b !== u || M !== c) && W(B(b, M), {
304
+ event: void 0,
305
+ source: ae.props
306
+ });
307
+ }, [b, M]);
308
+ var re = l.current ? ce(l.current) : void 0, ne = typeof window < "u" ? _e : ve;
309
+ ne(function() {
310
+ var i = l.current;
311
+ if (b !== U.current.formattedValue && i) {
312
+ var u = J(U.current.formattedValue, b, re);
313
+ i.value = b, A(i, u, b);
314
+ }
315
+ }, [b]);
316
+ var ue = function(i, u, c) {
317
+ var N = u.target, _ = j.current ? Ke(j.current, N.selectionEnd) : Ne(b, i), D = Object.assign(Object.assign({}, _), { lastValue: b }), p = m(i, D), P = E(p);
318
+ if (p = m(P, void 0), g && !g(B(P, p))) {
319
+ var $ = u.target, G = ce($), le = J(i, b, G);
320
+ return $.value = b, A($, le, b), !1;
321
+ }
322
+ return oe({
323
+ formattedValue: P,
324
+ numAsString: p,
325
+ inputValue: i,
326
+ event: u,
327
+ source: c,
328
+ input: u.target
329
+ }), !0;
330
+ }, fe = function(i, u) {
331
+ u === void 0 && (u = 0);
332
+ var c = i.selectionStart, N = i.selectionEnd;
333
+ j.current = { selectionStart: c, selectionEnd: N + u };
334
+ }, Ie = function(i) {
335
+ var u = i.target, c = u.value, N = ue(c, i, ae.event);
336
+ N && h(i), j.current = void 0;
337
+ }, Ce = function(i) {
338
+ var u = i.target, c = i.key, N = u.selectionStart, _ = u.selectionEnd, D = u.value;
339
+ D === void 0 && (D = "");
340
+ var p;
341
+ c === "ArrowLeft" || c === "Backspace" ? p = Math.max(N - 1, 0) : c === "ArrowRight" ? p = Math.min(N + 1, D.length) : c === "Delete" && (p = N);
342
+ var P = 0;
343
+ c === "Delete" && N === _ && (P = 1);
344
+ var $ = c === "ArrowLeft" || c === "ArrowRight";
345
+ if (p === void 0 || N !== _ && !$) {
346
+ x(i), fe(u, P);
347
+ return;
348
+ }
349
+ var G = p;
350
+ if ($) {
351
+ var le = c === "ArrowLeft" ? "left" : "right";
352
+ G = O(D, p, le), G !== p && i.preventDefault();
353
+ } else
354
+ c === "Delete" && !R(D[p]) ? G = O(D, p, "right") : c === "Backspace" && !R(D[p]) && (G = O(D, p, "left"));
355
+ G !== p && A(u, G, D), x(i), fe(u, P);
356
+ }, Ae = function(i) {
357
+ var u = i.target, c = function() {
358
+ var N = u.selectionStart, _ = u.selectionEnd, D = u.value;
359
+ if (D === void 0 && (D = ""), N === _) {
360
+ var p = O(D, N);
361
+ p !== N && A(u, p, D);
362
+ }
363
+ };
364
+ c(), requestAnimationFrame(function() {
365
+ c();
366
+ }), v(i), fe(u);
367
+ }, Ee = function(i) {
368
+ i.persist && i.persist();
369
+ var u = i.target, c = i.currentTarget;
370
+ l.current = u, w.current.focusTimeout = setTimeout(function() {
371
+ var N = u.selectionStart, _ = u.selectionEnd, D = u.value;
372
+ D === void 0 && (D = "");
373
+ var p = O(D, N);
374
+ p !== N && !(N === 0 && _ === D.length) && A(u, p, D), I(Object.assign(Object.assign({}, i), { currentTarget: c }));
375
+ }, 0);
376
+ }, Be = function(i) {
377
+ l.current = null, clearTimeout(w.current.focusTimeout), clearTimeout(w.current.setCaretTimeout), C(i);
378
+ }, Oe = ee && We() ? "numeric" : void 0, se = Object.assign({ inputMode: Oe }, F, {
379
+ type: r,
380
+ value: b,
381
+ onChange: Ie,
382
+ onKeyDown: Ce,
383
+ onMouseUp: Ae,
384
+ onFocus: Ee,
385
+ onBlur: Be
386
+ });
387
+ if (a === "text")
388
+ return t ? Q.createElement(Q.Fragment, null, t(b, F) || null) : Q.createElement("span", Object.assign({}, F, { ref: o }), b);
389
+ if (n) {
390
+ var Te = n;
391
+ return Q.createElement(Te, Object.assign({}, se, { ref: o }));
392
+ }
393
+ return Q.createElement("input", Object.assign({}, se, { ref: o }));
394
+ }
395
+ function Se(e, r) {
396
+ var a = r.decimalScale, n = r.fixedDecimalScale, t = r.prefix;
397
+ t === void 0 && (t = "");
398
+ var o = r.suffix;
399
+ o === void 0 && (o = "");
400
+ var f = r.allowNegative, m = r.thousandsGroupStyle;
401
+ if (m === void 0 && (m = "thousand"), e === "" || e === "-")
402
+ return e;
403
+ var V = ie(r), y = V.thousandSeparator, S = V.decimalSeparator, g = a !== 0 && e.indexOf(".") !== -1 || a && n, h = de(e, f), x = h.beforeDecimal, v = h.afterDecimal, I = h.addNegation;
404
+ return a !== void 0 && (v = be(v, a, !!n)), y && (x = Le(x, y, m)), t && (x = t + x), o && (v = v + o), I && (x = "-" + x), e = x + (g && S || "") + v, e;
405
+ }
406
+ function ie(e) {
407
+ var r = e.decimalSeparator;
408
+ r === void 0 && (r = ".");
409
+ var a = e.thousandSeparator, n = e.allowedDecimalSeparators;
410
+ return a === !0 && (a = ","), n || (n = [r, "."]), {
411
+ decimalSeparator: r,
412
+ thousandSeparator: a,
413
+ allowedDecimalSeparators: n
414
+ };
415
+ }
416
+ function Qe(e, r) {
417
+ e === void 0 && (e = "");
418
+ var a = new RegExp("(-)"), n = new RegExp("(-)(.)*(-)"), t = a.test(e), o = n.test(e);
419
+ return e = e.replace(/-/g, ""), t && !o && r && (e = "-" + e), e;
420
+ }
421
+ function Xe(e, r) {
422
+ return new RegExp("(^-)|[0-9]|" + ye(e), r ? "g" : void 0);
423
+ }
424
+ function Ye(e, r, a) {
425
+ return e === "" ? !0 : !r?.match(/\d/) && !a?.match(/\d/) && typeof e == "string" && !isNaN(Number(e));
426
+ }
427
+ function er(e, r, a) {
428
+ var n;
429
+ r === void 0 && (r = $e(e));
430
+ var t = a.allowNegative, o = a.prefix;
431
+ o === void 0 && (o = "");
432
+ var f = a.suffix;
433
+ f === void 0 && (f = "");
434
+ var m = a.decimalScale, V = r.from, y = r.to, S = y.start, g = y.end, h = ie(a), x = h.allowedDecimalSeparators, v = h.decimalSeparator, I = e[g] === v;
435
+ if (te(e) && (e === o || e === f) && r.lastValue === "")
436
+ return e;
437
+ if (g - S === 1 && x.indexOf(e[S]) !== -1) {
438
+ var C = m === 0 ? "" : v;
439
+ e = e.substring(0, S) + C + e.substring(S + 1, e.length);
440
+ }
441
+ var s = function(l, w, E) {
442
+ var B = !1, A = !1;
443
+ o.startsWith("-") ? B = !1 : l.startsWith("--") ? (B = !1, A = !0) : f.startsWith("-") && l.length === f.length ? B = !1 : l[0] === "-" && (B = !0);
444
+ var O = B ? 1 : 0;
445
+ return A && (O = 2), O && (l = l.substring(O), w -= O, E -= O), { value: l, start: w, end: E, hasNegation: B };
446
+ }, T = s(e, S, g), R = T.hasNegation;
447
+ n = T, e = n.value, S = n.start, g = n.end;
448
+ var L = s(r.lastValue, V.start, V.end), F = L.start, q = L.end, k = L.value, b = e.substring(S, g);
449
+ e.length && k.length && (F > k.length - f.length || q < o.length) && !(b && f.startsWith(b)) && (e = k);
450
+ var M = 0;
451
+ e.startsWith(o) ? M += o.length : S < o.length && (M = S), e = e.substring(M), g -= M;
452
+ var K = e.length, j = e.length - f.length;
453
+ e.endsWith(f) ? K = j : (g > j || g > e.length - f.length) && (K = g), e = e.substring(0, K), e = Qe(R ? "-" + e : e, t), e = (e.match(Xe(v, !0)) || []).join("");
454
+ var U = e.indexOf(v);
455
+ e = e.replace(new RegExp(ye(v), "g"), function(l, w) {
456
+ return w === U ? "." : "";
457
+ });
458
+ var W = de(e, t), H = W.beforeDecimal, ee = W.afterDecimal, d = W.addNegation;
459
+ return y.end - y.start < V.end - V.start && H === "" && I && !parseFloat(ee) && (e = d ? "-" : ""), e;
460
+ }
461
+ function rr(e, r) {
462
+ var a = r.prefix;
463
+ a === void 0 && (a = "");
464
+ var n = r.suffix;
465
+ n === void 0 && (n = "");
466
+ var t = Array.from({ length: e.length + 1 }).map(function() {
467
+ return !0;
468
+ }), o = e[0] === "-";
469
+ t.fill(!1, 0, a.length + (o ? 1 : 0));
470
+ var f = e.length;
471
+ return t.fill(!1, f - n.length + 1, f + 1), t;
472
+ }
473
+ function ar(e) {
474
+ var r = ie(e), a = r.thousandSeparator, n = r.decimalSeparator, t = e.prefix;
475
+ t === void 0 && (t = "");
476
+ var o = e.allowNegative;
477
+ if (o === void 0 && (o = !0), a === n)
478
+ throw new Error(`
479
+ Decimal separator can't be same as thousand separator.
480
+ thousandSeparator: ` + a + ` (thousandSeparator = {true} is same as thousandSeparator = ",")
481
+ decimalSeparator: ` + n + ` (default value for decimalSeparator is .)
482
+ `);
483
+ return t.startsWith("-") && o && (console.error(`
484
+ Prefix can't start with '-' when allowNegative is true.
485
+ prefix: ` + t + `
486
+ allowNegative: ` + o + `
487
+ `), o = !1), Object.assign(Object.assign({}, e), { allowNegative: o });
488
+ }
489
+ function tr(e) {
490
+ e = ar(e), e.decimalSeparator, e.allowedDecimalSeparators, e.thousandsGroupStyle;
491
+ var r = e.suffix, a = e.allowNegative, n = e.allowLeadingZeros, t = e.onKeyDown;
492
+ t === void 0 && (t = Z);
493
+ var o = e.onBlur;
494
+ o === void 0 && (o = Z);
495
+ var f = e.thousandSeparator, m = e.decimalScale, V = e.fixedDecimalScale, y = e.prefix;
496
+ y === void 0 && (y = "");
497
+ var S = e.defaultValue, g = e.value, h = e.valueIsNumericString, x = e.onValueChange, v = pe(e, ["decimalSeparator", "allowedDecimalSeparators", "thousandsGroupStyle", "suffix", "allowNegative", "allowLeadingZeros", "onKeyDown", "onBlur", "thousandSeparator", "decimalScale", "fixedDecimalScale", "prefix", "defaultValue", "value", "valueIsNumericString", "onValueChange"]), I = ie(e), C = I.decimalSeparator, s = I.allowedDecimalSeparators, T = function(d) {
498
+ return Se(d, e);
499
+ }, R = function(d, l) {
500
+ return er(d, l, e);
501
+ }, L = Y(g) ? S : g, F = h ?? Ye(L, y, r);
502
+ Y(g) ? Y(S) || (F = F || typeof S == "number") : F = F || typeof g == "number";
503
+ var q = function(d) {
504
+ return Ve(d) ? d : (typeof d == "number" && (d = we(d)), F && typeof m == "number" ? me(d, m, !!V) : d);
505
+ }, k = De(q(g), q(S), !!F, T, R, x), b = k[0], M = b.numAsString, K = b.formattedValue, j = k[1], U = function(d) {
506
+ var l = d.target, w = d.key, E = l.selectionStart, B = l.selectionEnd, A = l.value;
507
+ if (A === void 0 && (A = ""), (w === "Backspace" || w === "Delete") && B < y.length) {
508
+ d.preventDefault();
509
+ return;
510
+ }
511
+ if (E !== B) {
512
+ t(d);
513
+ return;
514
+ }
515
+ w === "Backspace" && A[0] === "-" && E === y.length + 1 && a && z(l, 1), m && V && (w === "Backspace" && A[E - 1] === C ? (z(l, E - 1), d.preventDefault()) : w === "Delete" && A[E] === C && d.preventDefault()), s?.includes(w) && A[E] === C && z(l, E + 1);
516
+ var O = f === !0 ? "," : f;
517
+ w === "Backspace" && A[E - 1] === O && z(l, E - 1), w === "Delete" && A[E] === O && z(l, E + 1), t(d);
518
+ }, W = function(d) {
519
+ var l = M;
520
+ if (l.match(/\d/g) || (l = ""), n || (l = Pe(l)), V && m && (l = me(l, m, V)), l !== M) {
521
+ var w = Se(l, e);
522
+ j({
523
+ formattedValue: w,
524
+ value: l,
525
+ floatValue: parseFloat(l)
526
+ }, {
527
+ event: d,
528
+ source: ae.event
529
+ });
530
+ }
531
+ o(d);
532
+ }, H = function(d) {
533
+ return d === C ? !0 : te(d);
534
+ }, ee = function(d) {
535
+ var l = d.currentValue, w = d.lastValue, E = d.formattedValue, B = d.currentValueIndex, A = d.formattedValueIndex, O = l[B], J = E[A], oe = Ne(w, l), re = oe.to, ne = function(ue) {
536
+ return R(ue).indexOf(".") + y.length;
537
+ };
538
+ return g === 0 && V && m && l[re.start] === C && ne(l) < B && ne(E) > A ? !1 : B >= re.start && B < re.end && s && s.includes(O) && J === C ? !0 : O === J;
539
+ };
540
+ return Object.assign(Object.assign({}, v), {
541
+ value: K,
542
+ valueIsNumericString: !1,
543
+ isValidInputCharacter: H,
544
+ isCharacterSame: ee,
545
+ onValueChange: j,
546
+ format: T,
547
+ removeFormatting: R,
548
+ getCaretBoundary: function(d) {
549
+ return rr(d, e);
550
+ },
551
+ onKeyDown: U,
552
+ onBlur: W
553
+ });
554
+ }
555
+ function ir(e) {
556
+ var r = tr(e);
557
+ return Q.createElement(Je, Object.assign({}, r));
558
+ }
559
+ export {
560
+ ir as N
561
+ };
@@ -0,0 +1,10 @@
1
+ import { FieldValues } from 'react-hook-form';
2
+ import { FormNumberProps } from '../components/FormComponents/FormNumber/FormNumber';
3
+ /**
4
+ * a hook to determine the decimal separator for a specific language
5
+ */
6
+ export declare function useDecimalSeparator<T extends FieldValues>(languageCode: FormNumberProps<T>['languageCode']): string;
7
+ /**
8
+ * a hook to determine the thousand separator for a specific language
9
+ */
10
+ export declare function useThousandSeparator<T extends FieldValues>(languageCode: FormNumberProps<T>['languageCode']): string;
@@ -0,0 +1,17 @@
1
+ import { useMemo as e } from "react";
2
+ function n(r) {
3
+ return e(() => {
4
+ const t = Intl.NumberFormat(r).formatToParts(1234.45).find((o) => o.type === "decimal")?.value;
5
+ return t || ".";
6
+ }, [r]);
7
+ }
8
+ function u(r) {
9
+ return e(() => {
10
+ const t = Intl.NumberFormat(r).formatToParts(1234.45).find((o) => o.type === "group")?.value;
11
+ return t || ",";
12
+ }, [r]);
13
+ }
14
+ export {
15
+ n as useDecimalSeparator,
16
+ u as useThousandSeparator
17
+ };
@@ -1,3 +1,4 @@
1
+ import { LANGUAGE_CODES } from '../types/Languages';
1
2
  /**
2
3
  * Capitalizes the first letter of every word in a given text string
3
4
  * @param text string in any text case
@@ -10,3 +11,14 @@ export declare const capitalizeFirstLetters: (text: string) => string;
10
11
  * @returns
11
12
  */
12
13
  export declare const trimLeadingAndTrailingSpaces: <T extends Record<string, unknown>>(obj: T) => T;
14
+ /**
15
+ * Receives a number and returns the value as a locale string.
16
+ * Note: Should only be used for displaying numbers, not for calculations
17
+ * and not for values that are supposed to be send to the backend.
18
+ *
19
+ * @param locale - The locale code ('en' for English, 'es' for Spanish).
20
+ * @param value - The number to be formatted.
21
+ * @param maximumFractionDigits - The maximum number of decimal digits (default is 2).
22
+ * @returns The language-specific formatted number.
23
+ */
24
+ export declare const getNumberAsLocaleString: (locale: LANGUAGE_CODES, value?: number, maximumFractionDigits?: number) => string;
@@ -1,15 +1,22 @@
1
- import { _ as e, a as n, b as a, i as o } from "../isArray-thIeLpc5.js";
2
- import { i as c } from "../isPlainObject-BlCDf1Kc.js";
3
- import { g } from "../_commonjsHelpers-CT_km90n.js";
4
- var m = e, p = n, f = a, b = "[object String]";
1
+ import { _ as e, a as o, b as a, i as c } from "../isArray-thIeLpc5.js";
2
+ import { i as g } from "../isPlainObject-BlCDf1Kc.js";
3
+ import { g as m } from "../_commonjsHelpers-CT_km90n.js";
4
+ import { LANGUAGE_CODES_MAPPER as p } from "../types/Languages.js";
5
+ var f = e, b = o, A = a, S = "[object String]";
5
6
  function j(r) {
6
- return typeof r == "string" || !p(r) && f(r) && m(r) == b;
7
+ return typeof r == "string" || !b(r) && A(r) && f(r) == S;
7
8
  }
8
- var S = j;
9
- const A = /* @__PURE__ */ g(S), T = (r) => r.split(" ").map((t) => t.charAt(0).toUpperCase() + t.slice(1).toLowerCase()).join(" "), L = (r) => Object.fromEntries(
10
- Object.entries(r).map(([t, s]) => [t, i(s)])
11
- ), i = (r) => o(r) ? r.map(i) : c(r) ? L(r) : A(r) ? r.trim() : r;
9
+ var L = j;
10
+ const _ = /* @__PURE__ */ m(L), G = (r) => r.split(" ").map((t) => t.charAt(0).toUpperCase() + t.slice(1).toLowerCase()).join(" "), C = (r) => Object.fromEntries(
11
+ Object.entries(r).map(([t, i]) => [t, s(i)])
12
+ ), s = (r) => c(r) ? r.map(s) : g(r) ? C(r) : _(r) ? r.trim() : r, T = (r, t, i = 2) => {
13
+ if (!t)
14
+ return "0";
15
+ const n = p[r];
16
+ return t.toLocaleString(n, { maximumFractionDigits: i });
17
+ };
12
18
  export {
13
- T as capitalizeFirstLetters,
14
- L as trimLeadingAndTrailingSpaces
19
+ G as capitalizeFirstLetters,
20
+ T as getNumberAsLocaleString,
21
+ C as trimLeadingAndTrailingSpaces
15
22
  };
@@ -0,0 +1,3 @@
1
+ export type LANGUAGE_COUNTRY_CODES = 'de-DE' | 'es-MX' | 'fr-FR' | 'en-US' | 'de-CH';
2
+ export type LANGUAGE_CODES = 'es' | 'en';
3
+ export declare const LANGUAGE_CODES_MAPPER: Record<LANGUAGE_CODES, LANGUAGE_COUNTRY_CODES>;
@@ -0,0 +1,7 @@
1
+ const e = {
2
+ en: "en-US",
3
+ es: "es-MX"
4
+ };
5
+ export {
6
+ e as LANGUAGE_CODES_MAPPER
7
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hortiview/shared-components",
3
3
  "description": "This is a shared component library. It should used in the HortiView platform and its modules.",
4
- "version": "0.0.10589",
4
+ "version": "0.0.11114",
5
5
  "type": "module",
6
6
  "repository": "https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared",
7
7
  "author": "Falk Menge <falk.menge.ext@bayer.com>",
@@ -31,7 +31,8 @@
31
31
  "lodash": "^4.17.21",
32
32
  "react": "^18.3.1",
33
33
  "react-dom": "^18.3.1",
34
- "react-hook-form": "^7.51.2"
34
+ "react-hook-form": "^7.51.2",
35
+ "react-number-format": "^5.4.3"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@chromatic-com/storybook": "1.5.0",
@@ -67,6 +68,7 @@
67
68
  "react": "^18.3.1",
68
69
  "react-dom": "^18.3.1",
69
70
  "react-hook-form": "^7.51.2",
71
+ "react-number-format": "^5.4.3",
70
72
  "react-tooltip": "^5.26.4",
71
73
  "storybook": "^8.2.5",
72
74
  "typescript": "^5.2.2",