@ledgerhq/lumen-utils-shared 0.1.2 → 0.1.4

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.
Files changed (37) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +136 -123
  4. package/dist/lib/cn.d.ts.map +1 -1
  5. package/dist/lib/components/amountDisplayHelpers/buildAriaLabel.d.ts.map +1 -1
  6. package/dist/lib/components/amountDisplayHelpers/useSplitText.d.ts.map +1 -1
  7. package/dist/lib/context/createSafeContext.d.ts.map +1 -1
  8. package/dist/lib/density/density.d.ts +2 -0
  9. package/dist/lib/density/density.d.ts.map +1 -0
  10. package/dist/lib/density/index.d.ts +2 -0
  11. package/dist/lib/density/index.d.ts.map +1 -0
  12. package/dist/lib/isTextChildren/isTextChildren.d.ts.map +1 -1
  13. package/dist/lib/resolveBaseInputPlaceholder/index.d.ts +2 -0
  14. package/dist/lib/resolveBaseInputPlaceholder/index.d.ts.map +1 -0
  15. package/dist/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.d.ts +20 -0
  16. package/dist/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.d.ts.map +1 -0
  17. package/dist/lib/throttle/throttle.d.ts.map +1 -1
  18. package/dist/lib/useMergeRef/useMergeRef.d.ts +1 -1
  19. package/dist/lib/useMergeRef/useMergeRef.d.ts.map +1 -1
  20. package/eslint.config.mjs +2 -2
  21. package/package.json +1 -1
  22. package/src/index.ts +2 -0
  23. package/src/lib/cn.ts +2 -1
  24. package/src/lib/components/amountDisplayHelpers/buildAriaLabel.ts +1 -1
  25. package/src/lib/components/amountDisplayHelpers/useSplitText.test.ts +1 -1
  26. package/src/lib/components/amountDisplayHelpers/useSplitText.ts +1 -1
  27. package/src/lib/context/createSafeContext.tsx +2 -1
  28. package/src/lib/density/density.ts +1 -0
  29. package/src/lib/density/index.ts +1 -0
  30. package/src/lib/isTextChildren/isTextChildren.test.ts +2 -1
  31. package/src/lib/isTextChildren/isTextChildren.ts +1 -1
  32. package/src/lib/resolveBaseInputPlaceholder/index.ts +1 -0
  33. package/src/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.test.ts +61 -0
  34. package/src/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.ts +44 -0
  35. package/src/lib/throttle/throttle.ts +2 -1
  36. package/src/lib/useMergeRef/useMergeRef.ts +2 -1
  37. package/vite.config.ts +1 -0
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './lib/density';
1
2
  export * from './lib/string/string';
2
3
  export * from './lib/inputFormatter';
3
4
  export * from './lib/context';
@@ -10,4 +11,5 @@ export * from './lib/throttle';
10
11
  export * from './lib/debounce';
11
12
  export * from './lib/a11y';
12
13
  export * from './lib/shallowEqual';
14
+ export * from './lib/resolveBaseInputPlaceholder';
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mCAAmC,CAAC"}
package/dist/index.js CHANGED
@@ -1,128 +1,128 @@
1
- import { jsx as v } from "react/jsx-runtime";
2
- import { createContext as L, useRef as w, useContext as W, useMemo as I } from "react";
3
- import { clsx as _ } from "clsx";
4
- import { twMerge as F } from "tailwind-merge";
5
- function J(t) {
1
+ import { jsx as k } from "react/jsx-runtime";
2
+ import { createContext as F, useRef as W, useContext as _, useMemo as I } from "react";
3
+ import { clsx as R } from "clsx";
4
+ import { twMerge as w } from "tailwind-merge";
5
+ function Q(t) {
6
6
  return t ? t.split(/[-_ ]+/).map((e) => e.charAt(0).toUpperCase() + e.slice(1).toLowerCase()).join("") : "";
7
7
  }
8
- const R = 48, B = 17, N = 2;
9
- function Q(t) {
8
+ const B = 48, N = 17, q = 2;
9
+ function Y(t) {
10
10
  const e = t.replace(/\D/g, "").length;
11
11
  return Math.max(
12
- B,
13
- R - e * N
12
+ N,
13
+ B - e * q
14
14
  );
15
15
  }
16
16
  function A(t, e = !0) {
17
17
  if (!t) return "";
18
- const i = t.includes("."), [r, c] = t.split("."), l = r.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
19
- return i && e ? c ? `${l}.${c}` : `${l}.` : l;
18
+ const r = t.includes("."), [o, s] = t.split("."), l = o.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
19
+ return r && e ? s ? `${l}.${s}` : `${l}.` : l;
20
20
  }
21
- function Y(t, e = {}) {
21
+ function tt(t, e = {}) {
22
22
  const {
23
- allowDecimals: i = !0,
24
- thousandsSeparator: r = !0,
25
- maxIntegerLength: c = 9,
23
+ allowDecimals: r = !0,
24
+ thousandsSeparator: o = !0,
25
+ maxIntegerLength: s = 9,
26
26
  maxDecimalLength: l = 9
27
- } = e, o = t.replace(",", ".").replace(/[^\d.]/g, "");
28
- let n = o;
29
- if (n = n.replace(/^0+(?=\d)/, ""), !i)
30
- return n = n.replace(/\D/g, ""), c > 0 && n.length > c && (n = n.slice(0, c)), r ? A(n) : n;
27
+ } = e, i = t.replace(",", ".").replace(/[^\d.]/g, "");
28
+ let n = i;
29
+ if (n = n.replace(/^0+(?=\d)/, ""), !r)
30
+ return n = n.replace(/\D/g, ""), s > 0 && n.length > s && (n = n.slice(0, s)), o ? A(n) : n;
31
31
  n === "." && (n = "0.");
32
32
  const a = n.indexOf(".");
33
33
  if (a !== -1) {
34
34
  let u = n.slice(0, a), f = n.slice(a + 1).replace(/\./g, "");
35
- c > 0 && u.length > c && (u = u.slice(0, c)), f = f.slice(0, l), u === "" && (u = "0");
36
- const h = o.endsWith(".") || n.endsWith(".");
35
+ s > 0 && u.length > s && (u = u.slice(0, s)), f = f.slice(0, l), u === "" && (u = "0");
36
+ const h = i.endsWith(".") || n.endsWith(".");
37
37
  n = f.length > 0 ? `${u}.${f}` : h ? `${u}.` : u;
38
38
  } else
39
- c > 0 && n.length > c && (n = n.slice(0, c));
40
- return r ? A(n) : n;
39
+ s > 0 && n.length > s && (n = n.slice(0, s));
40
+ return o ? A(n) : n;
41
41
  }
42
- function q(t, e) {
42
+ function z(t, e) {
43
43
  if (Object.is(t, e)) return !0;
44
- const i = t, r = e, c = Object.keys(i), l = Object.keys(r);
45
- return c.length !== l.length ? !1 : c.every(
46
- (o) => Object.prototype.hasOwnProperty.call(r, o) && Object.is(i[o], r[o])
44
+ const r = t, o = e, s = Object.keys(r), l = Object.keys(o);
45
+ return s.length !== l.length ? !1 : s.every(
46
+ (i) => Object.prototype.hasOwnProperty.call(o, i) && Object.is(r[i], o[i])
47
47
  );
48
48
  }
49
- function z(t, e) {
50
- const i = L(e), r = ({ children: l, value: o }) => {
51
- const n = w(o);
52
- return q(n.current, o) || (n.current = o), /* @__PURE__ */ v(i.Provider, { value: n.current, children: l });
49
+ function K(t, e) {
50
+ const r = F(e), o = ({ children: l, value: i }) => {
51
+ const n = W(i);
52
+ return z(n.current, i) || (n.current = i), /* @__PURE__ */ k(r.Provider, { value: n.current, children: l });
53
53
  };
54
- r.displayName = t + "Provider";
55
- function c({
54
+ o.displayName = t + "Provider";
55
+ function s({
56
56
  consumerName: l,
57
- contextRequired: o
57
+ contextRequired: i
58
58
  }) {
59
- const n = W(i);
59
+ const n = _(r);
60
60
  if (n)
61
61
  return n;
62
- if (o)
62
+ if (i)
63
63
  throw new Error(
64
64
  `${l} must be used within ${t}`
65
65
  );
66
66
  return e || {};
67
67
  }
68
- return [r, c];
68
+ return [o, s];
69
69
  }
70
- const [tt, K] = z("Disabled", { disabled: !1 }), et = ({
70
+ const [et, Z] = K("Disabled", { disabled: !1 }), nt = ({
71
71
  consumerName: t,
72
72
  contextRequired: e,
73
- mergeWith: i
73
+ mergeWith: r
74
74
  }) => {
75
- const r = K({
75
+ const o = Z({
76
76
  consumerName: t,
77
77
  contextRequired: e ?? !1
78
78
  });
79
- return !!(i?.disabled || r.disabled);
79
+ return !!(r?.disabled || o.disabled);
80
80
  };
81
- function nt(...t) {
82
- return F(_(t));
81
+ function rt(...t) {
82
+ return w(R(t));
83
83
  }
84
- const C = (t) => typeof t == "string" || typeof t == "number", rt = (t) => Array.isArray(t) ? t.every(C) : C(t);
85
- function M(t, e) {
84
+ const O = (t) => typeof t == "string" || typeof t == "number", ot = (t) => Array.isArray(t) ? t.every(O) : O(t);
85
+ function C(t, e) {
86
86
  if (typeof t == "function")
87
87
  return t(e);
88
88
  typeof t == "object" && t !== null && "current" in t && (t.current = e);
89
89
  }
90
- function Z(...t) {
90
+ function H(...t) {
91
91
  const e = /* @__PURE__ */ new Map();
92
- return (i) => {
93
- if (i === null) {
94
- t.forEach((r) => {
95
- const c = e.get(r);
96
- typeof c == "function" && c(), M(r, null);
92
+ return (r) => {
93
+ if (r === null) {
94
+ t.forEach((o) => {
95
+ const s = e.get(o);
96
+ typeof s == "function" && s(), C(o, null);
97
97
  }), e.clear();
98
98
  return;
99
99
  }
100
- t.forEach((r) => {
101
- const c = M(r, i);
102
- typeof c == "function" && e.set(r, c);
100
+ t.forEach((o) => {
101
+ const s = C(o, r);
102
+ typeof s == "function" && e.set(o, s);
103
103
  });
104
104
  };
105
105
  }
106
- function ot(...t) {
107
- return I(() => Z(...t), t);
106
+ function it(...t) {
107
+ return I(() => H(...t), t);
108
108
  }
109
- const it = (t, e) => {
110
- let i = t;
111
- for (const r of e) {
112
- if (i == null)
109
+ const st = (t, e) => {
110
+ let r = t;
111
+ for (const o of e) {
112
+ if (r == null)
113
113
  return;
114
- i = i[r];
114
+ r = r[o];
115
115
  }
116
- return i;
116
+ return r;
117
117
  }, ct = ({
118
118
  currentStep: t,
119
119
  totalSteps: e,
120
- size: i,
121
- label: r,
122
- strokeWidth: c = 4,
120
+ size: r,
121
+ label: o,
122
+ strokeWidth: s = 4,
123
123
  arcPercentage: l = 0.75
124
124
  }) => {
125
- const o = Math.min(Math.max(t, 0), e), n = r ?? `${o}/${e}`, a = e <= 0 ? 0 : o / e, u = (i - c) / 2, f = i / 2, h = i / 2, d = 2 * Math.PI * u, g = d * l, b = g * (1 - a), p = o <= 0, $ = `${g} ${d}`, P = p ? g - 2 : b;
125
+ const i = Math.min(Math.max(t, 0), e), n = o ?? `${i}/${e}`, a = e <= 0 ? 0 : i / e, u = (r - s) / 2, f = r / 2, h = r / 2, d = 2 * Math.PI * u, g = d * l, b = g * (1 - a), p = i <= 0, D = `${g} ${d}`, P = p ? g - 2 : b;
126
126
  return {
127
127
  displayLabel: n,
128
128
  progress: a,
@@ -132,11 +132,11 @@ const it = (t, e) => {
132
132
  circumference: d,
133
133
  trackArcLength: g,
134
134
  trackDashArray: `${g} ${d}`,
135
- progressDashArray: $,
135
+ progressDashArray: D,
136
136
  progressDashOffset: P,
137
137
  showMinimalDot: p
138
138
  };
139
- }, st = (t) => I(
139
+ }, lt = (t) => I(
140
140
  () => ({
141
141
  integerPart: Array.from(t.integerPart, (e) => ({
142
142
  value: e,
@@ -148,57 +148,57 @@ const it = (t, e) => {
148
148
  })) : []
149
149
  }),
150
150
  [t.integerPart, t.decimalPart]
151
- ), lt = (t, e, i) => {
152
- if (e) return i;
153
- const r = t.decimalPart ? `${t.decimalSeparator}${t.decimalPart}` : "", c = `${t.integerPart}${r}`;
154
- return t.currencyPosition === "end" ? `${c} ${t.currencyText}` : `${t.currencyText} ${c}`;
151
+ ), ut = (t, e, r) => {
152
+ if (e) return r;
153
+ const o = t.decimalPart ? `${t.decimalSeparator}${t.decimalPart}` : "", s = `${t.integerPart}${o}`;
154
+ return t.currencyPosition === "end" ? `${s} ${t.currencyText}` : `${t.currencyText} ${s}`;
155
155
  };
156
- function U(t, e, i = {}) {
157
- const { leading: r = !1, trailing: c = !0, maxWait: l } = i;
158
- let o = null, n = null, a = null, u = 0, f = null, h = null, d;
159
- const g = l !== void 0, b = g ? Math.max(l, e) : 0, p = (s) => {
160
- u = s;
156
+ function U(t, e, r = {}) {
157
+ const { leading: o = !1, trailing: s = !0, maxWait: l } = r;
158
+ let i = null, n = null, a = null, u = 0, f = null, h = null, d;
159
+ const g = l !== void 0, b = g ? Math.max(l, e) : 0, p = (c) => {
160
+ u = c;
161
161
  const m = f, x = h;
162
162
  return f = null, h = null, d = t.apply(x, m), d;
163
- }, $ = (s) => {
164
- const m = a ? s - a : 0;
163
+ }, D = (c) => {
164
+ const m = a ? c - a : 0;
165
165
  return e - m;
166
- }, P = (s) => {
167
- const m = a ? s - a : e, x = s - u;
166
+ }, P = (c) => {
167
+ const m = a ? c - a : e, x = c - u;
168
168
  return a === null || m >= e || m < 0 || g && x >= b;
169
- }, D = (s) => (o = null, c && f ? p(s) : (f = null, h = null, d)), y = () => {
170
- const s = Date.now();
171
- if (P(s)) {
172
- D(s);
169
+ }, $ = (c) => (i = null, s && f ? p(c) : (f = null, h = null, d)), y = () => {
170
+ const c = Date.now();
171
+ if (P(c)) {
172
+ $(c);
173
173
  return;
174
174
  }
175
- o = setTimeout(y, $(s));
176
- }, O = () => {
177
- const s = Date.now();
178
- n = null, f && (p(s), o !== null && (clearTimeout(o), o = setTimeout(y, e)));
179
- }, S = (s) => (u = s, o = setTimeout(y, e), g && (n = setTimeout(O, b)), r ? p(s) : d), E = () => {
180
- o !== null && clearTimeout(o), n !== null && clearTimeout(n), u = 0, f = null, h = null, a = null, o = null, n = null;
181
- }, j = () => o === null && n === null ? d : D(Date.now()), k = () => o !== null || n !== null, T = function(...s) {
175
+ i = setTimeout(y, D(c));
176
+ }, M = () => {
177
+ const c = Date.now();
178
+ n = null, f && (p(c), i !== null && (clearTimeout(i), i = setTimeout(y, e)));
179
+ }, E = (c) => (u = c, i = setTimeout(y, e), g && (n = setTimeout(M, b)), o ? p(c) : d), v = () => {
180
+ i !== null && clearTimeout(i), n !== null && clearTimeout(n), u = 0, f = null, h = null, a = null, i = null, n = null;
181
+ }, L = () => i === null && n === null ? d : $(Date.now()), j = () => i !== null || n !== null, T = function(...c) {
182
182
  const m = Date.now(), x = P(m);
183
- if (f = s, h = this, a = m, x) {
184
- if (o === null)
185
- return S(m);
183
+ if (f = c, h = this, a = m, x) {
184
+ if (i === null)
185
+ return E(m);
186
186
  if (g)
187
- return clearTimeout(o), o = setTimeout(y, e), p(m);
187
+ return clearTimeout(i), i = setTimeout(y, e), p(m);
188
188
  }
189
- return o === null && (o = setTimeout(y, e)), d;
189
+ return i === null && (i = setTimeout(y, e)), d;
190
190
  };
191
- return T.cancel = E, T.flush = j, T.pending = k, T;
191
+ return T.cancel = v, T.flush = L, T.pending = j, T;
192
192
  }
193
- function ut(t, e, i = {}) {
194
- const { leading: r = !0, trailing: c = !0 } = i;
193
+ function at(t, e, r = {}) {
194
+ const { leading: o = !0, trailing: s = !0 } = r;
195
195
  return U(t, e, {
196
- leading: r,
197
- trailing: c,
196
+ leading: o,
197
+ trailing: s,
198
198
  maxWait: e
199
199
  });
200
200
  }
201
- const at = ({
201
+ const ft = ({
202
202
  onClick: t,
203
203
  disabled: e
204
204
  }) => t ? e ? {
@@ -208,30 +208,43 @@ const at = ({
208
208
  } : {
209
209
  role: "button",
210
210
  tabIndex: 0,
211
- onKeyDown: (r) => {
212
- (r.key === "Enter" || r.key === " ") && (r.preventDefault(), t?.(r));
211
+ onKeyDown: (o) => {
212
+ (o.key === "Enter" || o.key === " ") && (o.preventDefault(), t?.(o));
213
213
  },
214
214
  onClick: t
215
- } : void 0;
215
+ } : void 0, S = " ", dt = ({
216
+ label: t,
217
+ placeholder: e
218
+ }) => {
219
+ const r = typeof e == "string" && e.trim().length > 0 ? e : void 0;
220
+ return t ? {
221
+ inputPlaceholder: r ?? S,
222
+ labelStaysFloatedWithPlaceholder: r !== void 0
223
+ } : {
224
+ inputPlaceholder: e ?? S,
225
+ labelStaysFloatedWithPlaceholder: !1
226
+ };
227
+ };
216
228
  export {
217
- tt as DisabledProvider,
218
- M as assignRef,
219
- lt as buildAriaLabel,
220
- nt as cn,
221
- z as createSafeContext,
229
+ et as DisabledProvider,
230
+ C as assignRef,
231
+ ut as buildAriaLabel,
232
+ rt as cn,
233
+ K as createSafeContext,
222
234
  U as debounce,
223
235
  A as formatThousands,
224
- at as getButtonA11yProps,
225
- Q as getFontSize,
226
- it as getObjectPath,
236
+ ft as getButtonA11yProps,
237
+ Y as getFontSize,
238
+ st as getObjectPath,
227
239
  ct as getStepperCalculations,
228
- rt as isTextChildren,
229
- Z as mergeRefs,
230
- q as shallowEqual,
231
- Y as textFormatter,
232
- ut as throttle,
233
- J as toPascalCase,
234
- et as useDisabledContext,
235
- ot as useMergedRef,
236
- st as useSplitText
240
+ ot as isTextChildren,
241
+ H as mergeRefs,
242
+ dt as resolveBaseInputPlaceholder,
243
+ z as shallowEqual,
244
+ tt as textFormatter,
245
+ at as throttle,
246
+ Q as toPascalCase,
247
+ nt as useDisabledContext,
248
+ it as useMergedRef,
249
+ lt as useSplitText
237
250
  };
@@ -1 +1 @@
1
- {"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/lib/cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,MAAM,MAAM,CAAC;AAGxC,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC"}
1
+ {"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/lib/cn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIvC,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"buildAriaLabel.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/buildAriaLabel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,eAAO,MAAM,cAAc,GACzB,OAAO,cAAc,EACrB,QAAQ,OAAO,EACf,aAAa,MAAM,KAClB,MAaF,CAAC"}
1
+ {"version":3,"file":"buildAriaLabel.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/buildAriaLabel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,cAAc,GACzB,OAAO,cAAc,EACrB,QAAQ,OAAO,EACf,aAAa,MAAM,KAClB,MAaF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSplitText.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/useSplitText.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,YAAY,GACvB,OAAO,cAAc,KACpB;IACD,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,WAAW,EAAE,SAAS,EAAE,CAAC;CAiB1B,CAAC"}
1
+ {"version":3,"file":"useSplitText.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/amountDisplayHelpers/useSplitText.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzD,eAAO,MAAM,YAAY,GACvB,OAAO,cAAc,KACpB;IACD,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,WAAW,EAAE,SAAS,EAAE,CAAC;CAiB1B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createSafeContext.d.ts","sourceRoot":"","sources":["../../../src/lib/context/createSafeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,EAAE,EAAE,SAAS,EAAsB,MAAM,OAAO,CAAC;AAGzE,wBAAgB,iBAAiB,CAAC,YAAY,SAAS,MAAM,EAC3D,iBAAiB,EAAE,MAAM,EACzB,cAAc,CAAC,EAAE,YAAY;cAKjB,SAAS;WACZ,YAAY;KAaG,eAAe,SAAS,OAAO,gDAGpD;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,eAAe,CAAC;CAClC,KAAG,eAAe,SAAS,IAAI,GAAG,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,EAgBxE"}
1
+ {"version":3,"file":"createSafeContext.d.ts","sourceRoot":"","sources":["../../../src/lib/context/createSafeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI3C,wBAAgB,iBAAiB,CAAC,YAAY,SAAS,MAAM,EAC3D,iBAAiB,EAAE,MAAM,EACzB,cAAc,CAAC,EAAE,YAAY;cAKjB,SAAS;WACZ,YAAY;KAaG,eAAe,SAAS,OAAO,gDAGpD;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,eAAe,CAAC;CAClC,KAAG,eAAe,SAAS,IAAI,GAAG,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,EAgBxE"}
@@ -0,0 +1,2 @@
1
+ export type Density = 'compact' | 'expanded';
2
+ //# sourceMappingURL=density.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"density.d.ts","sourceRoot":"","sources":["../../../src/lib/density/density.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './density';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/density/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"isTextChildren.d.ts","sourceRoot":"","sources":["../../../src/lib/isTextChildren/isTextChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,YAGhD,CAAC"}
1
+ {"version":3,"file":"isTextChildren.d.ts","sourceRoot":"","sources":["../../../src/lib/isTextChildren/isTextChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,YAGhD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './resolveBaseInputPlaceholder';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/resolveBaseInputPlaceholder/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,20 @@
1
+ export type ResolveBaseInputPlaceholderArgs = {
2
+ label: string | undefined;
3
+ /** Raw `placeholder` from the input props (before spreading onto the field). */
4
+ placeholder: string | undefined;
5
+ };
6
+ export type ResolveBaseInputPlaceholderResult = {
7
+ /** Value to set on the native input `placeholder`. */
8
+ inputPlaceholder: string;
9
+ /**
10
+ * When a floating label and a non-empty user placeholder are both in use, the label must
11
+ * stay in the “floated” slot (not the empty-field centered position).
12
+ */
13
+ labelStaysFloatedWithPlaceholder: boolean;
14
+ };
15
+ /**
16
+ * Derives the native `placeholder` and floating-label mode for Lumen `BaseInput`.
17
+ * Web and React Native share this so label + example copy, and prefix-only fields, stay consistent.
18
+ */
19
+ export declare const resolveBaseInputPlaceholder: ({ label, placeholder, }: ResolveBaseInputPlaceholderArgs) => ResolveBaseInputPlaceholderResult;
20
+ //# sourceMappingURL=resolveBaseInputPlaceholder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveBaseInputPlaceholder.d.ts","sourceRoot":"","sources":["../../../src/lib/resolveBaseInputPlaceholder/resolveBaseInputPlaceholder.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,+BAA+B,GAAG;IAC5C,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,gFAAgF;IAChF,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,sDAAsD;IACtD,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,gCAAgC,EAAE,OAAO,CAAC;CAC3C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,yBAGzC,+BAA+B,KAAG,iCAiBpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/lib/throttle/throttle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,IACnE,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EAC9D,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,GAC5B,iBAAiB,CAAC,CAAC,CAAC,CAQtB"}
1
+ {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../../src/lib/throttle/throttle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,IACnE,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EAC9D,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,eAAoB,GAC5B,iBAAiB,CAAC,CAAC,CAAC,CAQtB"}
@@ -1,4 +1,4 @@
1
- import { Ref, RefCallback } from 'react';
1
+ import { RefCallback, Ref } from 'react';
2
2
  type PossibleRef<T> = Ref<T> | undefined;
3
3
  type RefCleanup = void | (() => void);
4
4
  export declare function assignRef<T>(ref: PossibleRef<T>, value: T | null): RefCleanup;
@@ -1 +1 @@
1
- {"version":3,"file":"useMergeRef.d.ts","sourceRoot":"","sources":["../../../src/lib/useMergeRef/useMergeRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAW,KAAK,WAAW,EAAE,MAAM,OAAO,CAAC;AAEvD,KAAK,WAAW,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AACzC,KAAK,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAEtC,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,UAAU,CAM7E;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAuBtE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAEzE"}
1
+ {"version":3,"file":"useMergeRef.d.ts","sourceRoot":"","sources":["../../../src/lib/useMergeRef/useMergeRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAG9C,KAAK,WAAW,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AACzC,KAAK,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC;AAEtC,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,UAAU,CAM7E;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAuBtE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAEzE"}
package/eslint.config.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import baseConfig from '../../eslint.config.mjs';
1
+ import { prodConfig } from '../../eslint.config.mjs';
2
2
 
3
3
  export default [
4
- ...baseConfig,
4
+ ...prodConfig,
5
5
  {
6
6
  files: ['**/*.json'],
7
7
  rules: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/lumen-utils-shared",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './lib/density';
1
2
  export * from './lib/string/string';
2
3
  export * from './lib/inputFormatter';
3
4
  export * from './lib/context';
@@ -10,3 +11,4 @@ export * from './lib/throttle';
10
11
  export * from './lib/debounce';
11
12
  export * from './lib/a11y';
12
13
  export * from './lib/shallowEqual';
14
+ export * from './lib/resolveBaseInputPlaceholder';
package/src/lib/cn.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ClassValue, clsx } from 'clsx';
1
+ import type { ClassValue } from 'clsx';
2
+ import { clsx } from 'clsx';
2
3
  import { twMerge } from 'tailwind-merge';
3
4
 
4
5
  export function cn(...inputs: ClassValue[]) {
@@ -1,4 +1,4 @@
1
- import { FormattedValue } from './types';
1
+ import type { FormattedValue } from './types';
2
2
 
3
3
  export const buildAriaLabel = (
4
4
  parts: FormattedValue,
@@ -1,7 +1,7 @@
1
1
  import { renderHook } from '@testing-library/react';
2
2
  import { describe, it, expect } from 'vitest';
3
3
 
4
- import { FormattedValue } from './types';
4
+ import type { FormattedValue } from './types';
5
5
  import { useSplitText } from './useSplitText';
6
6
 
7
7
  const createValue = (
@@ -1,5 +1,5 @@
1
1
  import { useMemo } from 'react';
2
- import { FormattedValue, SplitChar } from './types';
2
+ import type { FormattedValue, SplitChar } from './types';
3
3
 
4
4
  export const useSplitText = (
5
5
  value: FormattedValue,
@@ -1,4 +1,5 @@
1
- import { createContext, FC, ReactNode, useContext, useRef } from 'react';
1
+ import type { FC, ReactNode } from 'react';
2
+ import { createContext, useContext, useRef } from 'react';
2
3
  import { shallowEqual } from '../shallowEqual';
3
4
 
4
5
  export function createSafeContext<ContextValue extends object>(
@@ -0,0 +1 @@
1
+ export type Density = 'compact' | 'expanded';
@@ -0,0 +1 @@
1
+ export * from './density';
@@ -1,4 +1,5 @@
1
- import React, { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
+ import React from 'react';
2
3
  import { describe, it, expect } from 'vitest';
3
4
  import { isTextChildren } from './isTextChildren';
4
5
 
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
 
3
3
  const isStringOrNumber = (element: ReactNode) =>
4
4
  typeof element === 'string' || typeof element === 'number';
@@ -0,0 +1 @@
1
+ export * from './resolveBaseInputPlaceholder';
@@ -0,0 +1,61 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { resolveBaseInputPlaceholder } from './resolveBaseInputPlaceholder';
3
+
4
+ describe('resolveBaseInputPlaceholder', () => {
5
+ it('with label: uses a single space when no user placeholder (float hack)', () => {
6
+ expect(
7
+ resolveBaseInputPlaceholder({ label: 'Email', placeholder: undefined }),
8
+ ).toEqual({
9
+ inputPlaceholder: ' ',
10
+ labelStaysFloatedWithPlaceholder: false,
11
+ });
12
+ });
13
+
14
+ it('with label: uses user placeholder and keeps label floated alongside it', () => {
15
+ expect(
16
+ resolveBaseInputPlaceholder({
17
+ label: 'Username',
18
+ placeholder: 'jane.doe',
19
+ }),
20
+ ).toEqual({
21
+ inputPlaceholder: 'jane.doe',
22
+ labelStaysFloatedWithPlaceholder: true,
23
+ });
24
+ });
25
+
26
+ it('with label: treats whitespace-only placeholder as absent', () => {
27
+ expect(
28
+ resolveBaseInputPlaceholder({ label: 'x', placeholder: ' ' }),
29
+ ).toEqual({
30
+ inputPlaceholder: ' ',
31
+ labelStaysFloatedWithPlaceholder: false,
32
+ });
33
+ });
34
+
35
+ it('without label: defaults omitted placeholder to a single space', () => {
36
+ expect(
37
+ resolveBaseInputPlaceholder({ label: undefined, placeholder: undefined }),
38
+ ).toEqual({
39
+ inputPlaceholder: ' ',
40
+ labelStaysFloatedWithPlaceholder: false,
41
+ });
42
+ });
43
+
44
+ it('without label: passes through user placeholder', () => {
45
+ expect(
46
+ resolveBaseInputPlaceholder({ label: undefined, placeholder: 'Search' }),
47
+ ).toEqual({
48
+ inputPlaceholder: 'Search',
49
+ labelStaysFloatedWithPlaceholder: false,
50
+ });
51
+ });
52
+
53
+ it('without label: keeps empty string (not coerced to space)', () => {
54
+ expect(
55
+ resolveBaseInputPlaceholder({ label: undefined, placeholder: '' }),
56
+ ).toEqual({
57
+ inputPlaceholder: '',
58
+ labelStaysFloatedWithPlaceholder: false,
59
+ });
60
+ });
61
+ });
@@ -0,0 +1,44 @@
1
+ /** Single space: drives floating-label / placeholder-shown behavior when no user-facing placeholder is set. */
2
+ const PLACEHOLDER_FOR_FLOAT = ' ';
3
+
4
+ export type ResolveBaseInputPlaceholderArgs = {
5
+ label: string | undefined;
6
+ /** Raw `placeholder` from the input props (before spreading onto the field). */
7
+ placeholder: string | undefined;
8
+ };
9
+
10
+ export type ResolveBaseInputPlaceholderResult = {
11
+ /** Value to set on the native input `placeholder`. */
12
+ inputPlaceholder: string;
13
+ /**
14
+ * When a floating label and a non-empty user placeholder are both in use, the label must
15
+ * stay in the “floated” slot (not the empty-field centered position).
16
+ */
17
+ labelStaysFloatedWithPlaceholder: boolean;
18
+ };
19
+
20
+ /**
21
+ * Derives the native `placeholder` and floating-label mode for Lumen `BaseInput`.
22
+ * Web and React Native share this so label + example copy, and prefix-only fields, stay consistent.
23
+ */
24
+ export const resolveBaseInputPlaceholder = ({
25
+ label,
26
+ placeholder,
27
+ }: ResolveBaseInputPlaceholderArgs): ResolveBaseInputPlaceholderResult => {
28
+ const userText =
29
+ typeof placeholder === 'string' && placeholder.trim().length > 0
30
+ ? placeholder
31
+ : undefined;
32
+
33
+ if (label) {
34
+ return {
35
+ inputPlaceholder: userText ?? PLACEHOLDER_FOR_FLOAT,
36
+ labelStaysFloatedWithPlaceholder: userText !== undefined,
37
+ };
38
+ }
39
+
40
+ return {
41
+ inputPlaceholder: placeholder ?? PLACEHOLDER_FOR_FLOAT,
42
+ labelStaysFloatedWithPlaceholder: false,
43
+ };
44
+ };
@@ -1,4 +1,5 @@
1
- import { debounce, DebouncedFunction } from '../debounce';
1
+ import type { DebouncedFunction } from '../debounce';
2
+ import { debounce } from '../debounce';
2
3
 
3
4
  export type ThrottleOptions = {
4
5
  /**
@@ -1,4 +1,5 @@
1
- import { Ref, useMemo, type RefCallback } from 'react';
1
+ import type { RefCallback, Ref } from 'react';
2
+ import { useMemo } from 'react';
2
3
 
3
4
  type PossibleRef<T> = Ref<T> | undefined;
4
5
  type RefCleanup = void | (() => void);
package/vite.config.ts CHANGED
@@ -35,6 +35,7 @@ export default defineConfig(() => ({
35
35
  coverage: {
36
36
  reportsDirectory: './test-output/vitest/coverage',
37
37
  provider: 'v8' as const,
38
+ reporter: ['lcov'],
38
39
  },
39
40
  },
40
41
  }));