@ledgerhq/lumen-utils-shared 0.0.12 → 0.0.14

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 (86) hide show
  1. package/dist/index.d.ts +7 -6
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +64 -56
  4. package/dist/lib/{create-safe-context/create-safe-context.d.ts → createSafeContext/createSafeContext.d.ts} +1 -1
  5. package/dist/lib/createSafeContext/createSafeContext.d.ts.map +1 -0
  6. package/dist/lib/createSafeContext/index.d.ts +2 -0
  7. package/dist/lib/createSafeContext/index.d.ts.map +1 -0
  8. package/dist/lib/extractSlottable/extractSlottable.d.ts +29 -0
  9. package/dist/lib/extractSlottable/extractSlottable.d.ts.map +1 -0
  10. package/dist/lib/extractSlottable/index.d.ts +2 -0
  11. package/dist/lib/extractSlottable/index.d.ts.map +1 -0
  12. package/dist/lib/{get-object-path/get-object-path.d.ts → getObjectPath/getObjectPath.d.ts} +1 -1
  13. package/dist/lib/getObjectPath/getObjectPath.d.ts.map +1 -0
  14. package/dist/lib/getObjectPath/index.d.ts +2 -0
  15. package/dist/lib/getObjectPath/index.d.ts.map +1 -0
  16. package/dist/lib/{input-formatter/font-size-formatter.d.ts → inputFormatter/fontSizeFormatter.d.ts} +1 -1
  17. package/dist/lib/inputFormatter/fontSizeFormatter.d.ts.map +1 -0
  18. package/dist/lib/{input-formatter/format-thousands.d.ts → inputFormatter/formatThousands.d.ts} +1 -1
  19. package/dist/lib/inputFormatter/formatThousands.d.ts.map +1 -0
  20. package/dist/lib/inputFormatter/index.d.ts +4 -0
  21. package/dist/lib/inputFormatter/index.d.ts.map +1 -0
  22. package/dist/lib/{input-formatter/text-formatter.d.ts → inputFormatter/textFormatter.d.ts} +1 -1
  23. package/dist/lib/inputFormatter/textFormatter.d.ts.map +1 -0
  24. package/dist/lib/isTextChildren/index.d.ts +2 -0
  25. package/dist/lib/isTextChildren/index.d.ts.map +1 -0
  26. package/dist/lib/{is-text-children/is-text-children.d.ts → isTextChildren/isTextChildren.d.ts} +1 -1
  27. package/dist/lib/isTextChildren/isTextChildren.d.ts.map +1 -0
  28. package/dist/lib/string/index.d.ts +2 -0
  29. package/dist/lib/string/index.d.ts.map +1 -0
  30. package/dist/lib/{string-utils/string-utils.d.ts → string/string.d.ts} +1 -1
  31. package/dist/lib/string/string.d.ts.map +1 -0
  32. package/dist/lib/useMergeRef/index.d.ts +2 -0
  33. package/dist/lib/useMergeRef/index.d.ts.map +1 -0
  34. package/dist/lib/{use-merge-ref/use-merge-ref.d.ts → useMergeRef/useMergeRef.d.ts} +1 -1
  35. package/dist/lib/useMergeRef/useMergeRef.d.ts.map +1 -0
  36. package/package.json +1 -1
  37. package/src/index.ts +7 -6
  38. package/src/lib/{create-safe-context/create-safe-context.test.tsx → createSafeContext/createSafeContext.test.tsx} +1 -1
  39. package/src/lib/createSafeContext/index.ts +1 -0
  40. package/src/lib/extractSlottable/extractSlottable.test.ts +97 -0
  41. package/src/lib/extractSlottable/extractSlottable.ts +49 -0
  42. package/src/lib/extractSlottable/index.ts +1 -0
  43. package/src/lib/{get-object-path/get-object-path.test.ts → getObjectPath/getObjectPath.test.ts} +1 -1
  44. package/src/lib/getObjectPath/index.ts +1 -0
  45. package/src/lib/{input-formatter/format-thousands.test.ts → inputFormatter/formatThousands.test.ts} +1 -1
  46. package/src/lib/inputFormatter/index.ts +3 -0
  47. package/src/lib/{input-formatter/text-formatter.test.ts → inputFormatter/textFormatter.test.ts} +1 -1
  48. package/src/lib/{input-formatter/text-formatter.ts → inputFormatter/textFormatter.ts} +1 -1
  49. package/src/lib/isTextChildren/index.ts +1 -0
  50. package/src/lib/{is-text-children/is-text-children.test.ts → isTextChildren/isTextChildren.test.ts} +1 -1
  51. package/src/lib/string/index.ts +1 -0
  52. package/src/lib/{string-utils/string-utils.test.ts → string/string.test.ts} +1 -1
  53. package/src/lib/useMergeRef/index.ts +1 -0
  54. package/dist/lib/create-safe-context/create-safe-context.d.ts.map +0 -1
  55. package/dist/lib/create-safe-context/index.d.ts +0 -2
  56. package/dist/lib/create-safe-context/index.d.ts.map +0 -1
  57. package/dist/lib/get-object-path/get-object-path.d.ts.map +0 -1
  58. package/dist/lib/get-object-path/index.d.ts +0 -2
  59. package/dist/lib/get-object-path/index.d.ts.map +0 -1
  60. package/dist/lib/input-formatter/font-size-formatter.d.ts.map +0 -1
  61. package/dist/lib/input-formatter/format-thousands.d.ts.map +0 -1
  62. package/dist/lib/input-formatter/index.d.ts +0 -4
  63. package/dist/lib/input-formatter/index.d.ts.map +0 -1
  64. package/dist/lib/input-formatter/text-formatter.d.ts.map +0 -1
  65. package/dist/lib/is-text-children/index.d.ts +0 -2
  66. package/dist/lib/is-text-children/index.d.ts.map +0 -1
  67. package/dist/lib/is-text-children/is-text-children.d.ts.map +0 -1
  68. package/dist/lib/string-utils/index.d.ts +0 -2
  69. package/dist/lib/string-utils/index.d.ts.map +0 -1
  70. package/dist/lib/string-utils/string-utils.d.ts.map +0 -1
  71. package/dist/lib/use-merge-ref/index.d.ts +0 -2
  72. package/dist/lib/use-merge-ref/index.d.ts.map +0 -1
  73. package/dist/lib/use-merge-ref/use-merge-ref.d.ts.map +0 -1
  74. package/src/lib/create-safe-context/index.ts +0 -1
  75. package/src/lib/get-object-path/index.ts +0 -1
  76. package/src/lib/input-formatter/index.ts +0 -3
  77. package/src/lib/is-text-children/index.ts +0 -1
  78. package/src/lib/string-utils/index.ts +0 -1
  79. package/src/lib/use-merge-ref/index.ts +0 -1
  80. /package/src/lib/{create-safe-context/create-safe-context.tsx → createSafeContext/createSafeContext.tsx} +0 -0
  81. /package/src/lib/{get-object-path/get-object-path.ts → getObjectPath/getObjectPath.ts} +0 -0
  82. /package/src/lib/{input-formatter/font-size-formatter.ts → inputFormatter/fontSizeFormatter.ts} +0 -0
  83. /package/src/lib/{input-formatter/format-thousands.ts → inputFormatter/formatThousands.ts} +0 -0
  84. /package/src/lib/{is-text-children/is-text-children.ts → isTextChildren/isTextChildren.ts} +0 -0
  85. /package/src/lib/{string-utils/string-utils.ts → string/string.ts} +0 -0
  86. /package/src/lib/{use-merge-ref/use-merge-ref.ts → useMergeRef/useMergeRef.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export * from './lib/string-utils/string-utils';
2
- export * from './lib/input-formatter';
3
- export * from './lib/create-safe-context';
1
+ export * from './lib/string/string';
2
+ export * from './lib/inputFormatter';
3
+ export * from './lib/createSafeContext';
4
4
  export * from './lib/cn';
5
- export * from './lib/is-text-children';
6
- export * from './lib/use-merge-ref';
7
- export * from './lib/get-object-path';
5
+ export * from './lib/extractSlottable';
6
+ export * from './lib/isTextChildren';
7
+ export * from './lib/useMergeRef';
8
+ export * from './lib/getObjectPath';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,UAAU,CAAC;AACzB,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,UAAU,CAAC;AACzB,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,97 +1,104 @@
1
- import { jsx as h } from "react/jsx-runtime";
2
- import { createContext as x, useMemo as m, useContext as y } from "react";
3
- import { clsx as P } from "clsx";
4
- import { twMerge as S } from "tailwind-merge";
5
- function w(t) {
1
+ import { jsx as y } from "react/jsx-runtime";
2
+ import { createContext as x, useMemo as d, useContext as C, Children as S, isValidElement as f } from "react";
3
+ import { clsx as A } from "clsx";
4
+ import { twMerge as P } from "tailwind-merge";
5
+ function j(t) {
6
6
  return t ? t.split(/[-_ ]+/).map((n) => n.charAt(0).toUpperCase() + n.slice(1).toLowerCase()).join("") : "";
7
7
  }
8
- const C = 48, A = 17, M = 2;
9
- function E(t) {
8
+ const E = 48, M = 17, $ = 2;
9
+ function F(t) {
10
10
  const n = t.replace(/\D/g, "").length;
11
11
  return Math.max(
12
- A,
13
- C - n * M
12
+ M,
13
+ E - n * $
14
14
  );
15
15
  }
16
- function f(t, n = !0) {
16
+ function p(t, n = !0) {
17
17
  if (!t) return "";
18
- const i = t.includes("."), [o, r] = t.split("."), c = o.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
19
- return i && n ? r ? `${c}.${r}` : `${c}.` : c;
18
+ const i = t.includes("."), [o, r] = t.split("."), s = o.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
19
+ return i && n ? r ? `${s}.${r}` : `${s}.` : s;
20
20
  }
21
- function T(t, n = {}) {
21
+ function I(t, n = {}) {
22
22
  const {
23
23
  allowDecimals: i = !0,
24
24
  thousandsSeparator: o = !0,
25
25
  maxIntegerLength: r = 9,
26
- maxDecimalLength: c = 9
27
- } = n, a = t.replace(",", ".").replace(/[^\d.]/g, "");
28
- let e = a;
26
+ maxDecimalLength: s = 9
27
+ } = n, c = t.replace(",", ".").replace(/[^\d.]/g, "");
28
+ let e = c;
29
29
  if (e = e.replace(/^0+(?=\d)/, ""), !i)
30
- return e = e.replace(/\D/g, ""), r > 0 && e.length > r && (e = e.slice(0, r)), o ? f(e) : e;
30
+ return e = e.replace(/\D/g, ""), r > 0 && e.length > r && (e = e.slice(0, r)), o ? p(e) : e;
31
31
  e === "." && (e = "0.");
32
- const l = e.indexOf(".");
33
- if (l !== -1) {
34
- let s = e.slice(0, l), u = e.slice(l + 1).replace(/\./g, "");
35
- r > 0 && s.length > r && (s = s.slice(0, r)), u = u.slice(0, c), s === "" && (s = "0");
36
- const d = a.endsWith(".") || e.endsWith(".");
37
- e = u.length > 0 ? `${s}.${u}` : d ? `${s}.` : s;
32
+ const u = e.indexOf(".");
33
+ if (u !== -1) {
34
+ let a = e.slice(0, u), l = e.slice(u + 1).replace(/\./g, "");
35
+ r > 0 && a.length > r && (a = a.slice(0, r)), l = l.slice(0, s), a === "" && (a = "0");
36
+ const h = c.endsWith(".") || e.endsWith(".");
37
+ e = l.length > 0 ? `${a}.${l}` : h ? `${a}.` : a;
38
38
  } else
39
39
  r > 0 && e.length > r && (e = e.slice(0, r));
40
- return o ? f(e) : e;
40
+ return o ? p(e) : e;
41
41
  }
42
- function _(t, n) {
43
- const i = x(n), o = ({ children: c, value: a }) => {
44
- const e = m(
45
- () => a,
46
- Object.values(a ?? {})
42
+ function O(t, n) {
43
+ const i = x(n), o = ({ children: s, value: c }) => {
44
+ const e = d(
45
+ () => c,
46
+ Object.values(c ?? {})
47
47
  );
48
- return /* @__PURE__ */ h(i.Provider, { value: e, children: c });
48
+ return /* @__PURE__ */ y(i.Provider, { value: e, children: s });
49
49
  };
50
50
  o.displayName = t + "Provider";
51
51
  function r({
52
- consumerName: c,
53
- contextRequired: a
52
+ consumerName: s,
53
+ contextRequired: c
54
54
  }) {
55
- const e = y(i);
55
+ const e = C(i);
56
56
  if (e)
57
57
  return e;
58
- if (a)
58
+ if (c)
59
59
  throw new Error(
60
- `${c} must be used within ${t}`
60
+ `${s} must be used within ${t}`
61
61
  );
62
62
  return n || {};
63
63
  }
64
64
  return [o, r];
65
65
  }
66
- function j(...t) {
67
- return S(P(t));
66
+ function z(...t) {
67
+ return P(A(t));
68
68
  }
69
- const p = (t) => typeof t == "string" || typeof t == "number", F = (t) => Array.isArray(t) ? t.every(p) : p(t);
70
- function g(t, n) {
69
+ function L(t, n) {
70
+ const i = S.toArray(t), o = typeof n == "string" ? (c) => f(c) && c.props["data-slot"] === n : (c) => f(c) && c.type === n, r = i.find(o), s = i.filter((c) => !o(c));
71
+ return {
72
+ slotElement: r ?? null,
73
+ remainingChildren: s
74
+ };
75
+ }
76
+ const g = (t) => typeof t == "string" || typeof t == "number", R = (t) => Array.isArray(t) ? t.every(g) : g(t);
77
+ function m(t, n) {
71
78
  if (typeof t == "function")
72
79
  return t(n);
73
80
  typeof t == "object" && t !== null && "current" in t && (t.current = n);
74
81
  }
75
- function $(...t) {
82
+ function b(...t) {
76
83
  const n = /* @__PURE__ */ new Map();
77
84
  return (i) => {
78
85
  if (i === null) {
79
86
  t.forEach((o) => {
80
87
  const r = n.get(o);
81
- typeof r == "function" && r(), g(o, null);
88
+ typeof r == "function" && r(), m(o, null);
82
89
  }), n.clear();
83
90
  return;
84
91
  }
85
92
  t.forEach((o) => {
86
- const r = g(o, i);
93
+ const r = m(o, i);
87
94
  typeof r == "function" && n.set(o, r);
88
95
  });
89
96
  };
90
97
  }
91
- function I(...t) {
92
- return m(() => $(...t), t);
98
+ function T(...t) {
99
+ return d(() => b(...t), t);
93
100
  }
94
- const z = (t, n) => {
101
+ const V = (t, n) => {
95
102
  let i = t;
96
103
  for (const o of n) {
97
104
  if (i == null)
@@ -101,15 +108,16 @@ const z = (t, n) => {
101
108
  return i;
102
109
  };
103
110
  export {
104
- g as assignRef,
105
- j as cn,
106
- _ as createSafeContext,
107
- f as formatThousands,
108
- E as getFontSize,
109
- z as getObjectPath,
110
- F as isTextChildren,
111
- $ as mergeRefs,
112
- T as textFormatter,
113
- w as toPascalCase,
114
- I as useMergedRef
111
+ m as assignRef,
112
+ z as cn,
113
+ O as createSafeContext,
114
+ L as extractSlottable,
115
+ p as formatThousands,
116
+ F as getFontSize,
117
+ V as getObjectPath,
118
+ R as isTextChildren,
119
+ b as mergeRefs,
120
+ I as textFormatter,
121
+ j as toPascalCase,
122
+ T as useMergedRef
115
123
  };
@@ -6,4 +6,4 @@ export declare function createSafeContext<ContextValue extends object>(rootCompo
6
6
  consumerName: string;
7
7
  contextRequired: ContextRequired;
8
8
  }) => ContextRequired extends true ? ContextValue : Partial<ContextValue>];
9
- //# sourceMappingURL=create-safe-context.d.ts.map
9
+ //# sourceMappingURL=createSafeContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSafeContext.d.ts","sourceRoot":"","sources":["../../../src/lib/createSafeContext/createSafeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,EAAE,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAE1E,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 * from './createSafeContext';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/createSafeContext/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { ComponentType, ReactNode } from 'react';
2
+ /**
3
+ * Extracts children with a specific data-slot attribute or component type from a React children collection.
4
+ * Useful for separating specific components from general content in composite patterns.
5
+ *
6
+ * @param children - React children to process
7
+ * @param slotNameOrType - The data-slot value to extract, or the component type to match
8
+ * @returns An object containing the extracted slot element and remaining children
9
+ *
10
+ * @example
11
+ * // Extract by data-slot attribute
12
+ * const { slotElement, remainingChildren } = extractSlottable(children, 'secondary-action');
13
+ *
14
+ * @example
15
+ * // Extract by component type
16
+ * const { slotElement, remainingChildren } = extractSlottable(children, MyComponent);
17
+ *
18
+ * return (
19
+ * <div>
20
+ * {slotElement}
21
+ * <button>{remainingChildren}</button>
22
+ * </div>
23
+ * );
24
+ */
25
+ export declare function extractSlottable(children: ReactNode, slotNameOrType: string | ComponentType<any>): {
26
+ slotElement: ReactNode;
27
+ remainingChildren: ReactNode[];
28
+ };
29
+ //# sourceMappingURL=extractSlottable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractSlottable.d.ts","sourceRoot":"","sources":["../../../src/lib/extractSlottable/extractSlottable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,aAAa,EAAkB,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,SAAS,EACnB,cAAc,EAAE,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,GAC1C;IACD,WAAW,EAAE,SAAS,CAAC;IACvB,iBAAiB,EAAE,SAAS,EAAE,CAAC;CAChC,CAiBA"}
@@ -0,0 +1,2 @@
1
+ export * from './extractSlottable';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/extractSlottable/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -15,4 +15,4 @@
15
15
  * ```
16
16
  */
17
17
  export declare const getObjectPath: <T = unknown>(obj: Record<string, unknown>, path: string[]) => T | undefined;
18
- //# sourceMappingURL=get-object-path.d.ts.map
18
+ //# sourceMappingURL=getObjectPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getObjectPath.d.ts","sourceRoot":"","sources":["../../../src/lib/getObjectPath/getObjectPath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,GAAG,OAAO,EACvC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,MAAM,MAAM,EAAE,KACb,CAAC,GAAG,SAWN,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { getObjectPath } from './getObjectPath';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/getObjectPath/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Scales from 48px (max) to 17px (min) as digit count increases.
4
4
  */
5
5
  export declare function getFontSize(value: string): number;
6
- //# sourceMappingURL=font-size-formatter.d.ts.map
6
+ //# sourceMappingURL=fontSizeFormatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fontSizeFormatter.d.ts","sourceRoot":"","sources":["../../../src/lib/inputFormatter/fontSizeFormatter.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOjD"}
@@ -15,4 +15,4 @@ export declare function formatThousands(
15
15
  value: string,
16
16
  /** Whether to preserve decimal places */
17
17
  preserveDecimals?: boolean): string;
18
- //# sourceMappingURL=format-thousands.d.ts.map
18
+ //# sourceMappingURL=formatThousands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatThousands.d.ts","sourceRoot":"","sources":["../../../src/lib/inputFormatter/formatThousands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe;AAC7B,0BAA0B;AAC1B,KAAK,EAAE,MAAM;AACb,yCAAyC;AACzC,gBAAgB,UAAO,GACtB,MAAM,CAgBR"}
@@ -0,0 +1,4 @@
1
+ export { getFontSize } from './fontSizeFormatter';
2
+ export { formatThousands } from './formatThousands';
3
+ export { textFormatter } from './textFormatter';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/inputFormatter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -28,4 +28,4 @@ export type TextFormatterOptions = {
28
28
  export declare function textFormatter(
29
29
  /** The input value to format */
30
30
  value: string, options?: TextFormatterOptions): string;
31
- //# sourceMappingURL=text-formatter.d.ts.map
31
+ //# sourceMappingURL=textFormatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textFormatter.d.ts","sourceRoot":"","sources":["../../../src/lib/inputFormatter/textFormatter.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAAG;IACjC,sCAAsC;IACtC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa;AAC3B,gCAAgC;AAChC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,oBAAyB,GACjC,MAAM,CA4DR"}
@@ -0,0 +1,2 @@
1
+ export * from './isTextChildren';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/isTextChildren/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import { ReactNode } from 'react';
2
2
  export declare const isTextChildren: (element: ReactNode) => boolean;
3
- //# sourceMappingURL=is-text-children.d.ts.map
3
+ //# sourceMappingURL=isTextChildren.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ export * from './string';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * e.g., 'arrow-up' -> 'ArrowUp'
4
4
  */
5
5
  export declare function toPascalCase(str: string): string;
6
- //# sourceMappingURL=string-utils.d.ts.map
6
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src/lib/string/string.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMhD"}
@@ -0,0 +1,2 @@
1
+ export * from './useMergeRef';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/useMergeRef/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -5,4 +5,4 @@ export declare function assignRef<T>(ref: PossibleRef<T>, value: T | null): RefC
5
5
  export declare function mergeRefs<T>(...refs: PossibleRef<T>[]): RefCallback<T>;
6
6
  export declare function useMergedRef<T>(...refs: PossibleRef<T>[]): RefCallback<T>;
7
7
  export {};
8
- //# sourceMappingURL=use-merge-ref.d.ts.map
8
+ //# sourceMappingURL=useMergeRef.d.ts.map
@@ -0,0 +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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/lumen-utils-shared",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
- export * from './lib/string-utils/string-utils';
2
- export * from './lib/input-formatter';
3
- export * from './lib/create-safe-context';
1
+ export * from './lib/string/string';
2
+ export * from './lib/inputFormatter';
3
+ export * from './lib/createSafeContext';
4
4
  export * from './lib/cn';
5
- export * from './lib/is-text-children';
6
- export * from './lib/use-merge-ref';
7
- export * from './lib/get-object-path';
5
+ export * from './lib/extractSlottable';
6
+ export * from './lib/isTextChildren';
7
+ export * from './lib/useMergeRef';
8
+ export * from './lib/getObjectPath';
@@ -1,6 +1,6 @@
1
1
  import { cleanup, render } from '@testing-library/react';
2
2
  import React from 'react';
3
- import { createSafeContext } from './create-safe-context.js';
3
+ import { createSafeContext } from './createSafeContext.js';
4
4
 
5
5
  afterEach(() => {
6
6
  cleanup();
@@ -0,0 +1 @@
1
+ export * from './createSafeContext';
@@ -0,0 +1,97 @@
1
+ import { createElement } from 'react';
2
+ import { describe, it, expect } from 'vitest';
3
+ import { extractSlottable } from './extractSlottable';
4
+
5
+ describe('extractSlottable', () => {
6
+ it('should extract element with matching data-slot', () => {
7
+ const children = [
8
+ createElement('div', { 'data-slot': 'target', key: '1' }, 'Target'),
9
+ createElement('div', { key: '2' }, 'Other 1'),
10
+ createElement('div', { key: '3' }, 'Other 2'),
11
+ ];
12
+
13
+ const { slotElement, remainingChildren } = extractSlottable(
14
+ children,
15
+ 'target',
16
+ );
17
+
18
+ expect(slotElement).toBeTruthy();
19
+ expect(remainingChildren).toHaveLength(2);
20
+ });
21
+
22
+ it('should return null slotElement when no match found', () => {
23
+ const children = [
24
+ createElement('div', { key: '1' }, 'Child 1'),
25
+ createElement('div', { key: '2' }, 'Child 2'),
26
+ ];
27
+
28
+ const { slotElement, remainingChildren } = extractSlottable(
29
+ children,
30
+ 'non-existent',
31
+ );
32
+
33
+ expect(slotElement).toBeNull();
34
+ expect(remainingChildren).toHaveLength(2);
35
+ });
36
+
37
+ it('should handle empty children', () => {
38
+ const { slotElement, remainingChildren } = extractSlottable([], 'target');
39
+
40
+ expect(slotElement).toBeNull();
41
+ expect(remainingChildren).toHaveLength(0);
42
+ });
43
+
44
+ it('should handle single child', () => {
45
+ const child = createElement(
46
+ 'div',
47
+ { 'data-slot': 'target' },
48
+ 'Single Target',
49
+ );
50
+
51
+ const { slotElement, remainingChildren } = extractSlottable(
52
+ child,
53
+ 'target',
54
+ );
55
+
56
+ expect(slotElement).toBeTruthy();
57
+ expect(remainingChildren).toHaveLength(0);
58
+ });
59
+
60
+ it('should extract only first matching element', () => {
61
+ const children = [
62
+ createElement('div', { 'data-slot': 'target', key: '1' }, 'Target 1'),
63
+ createElement('div', { key: '2' }, 'Other'),
64
+ createElement('div', { 'data-slot': 'target', key: '3' }, 'Target 2'),
65
+ ];
66
+
67
+ const { slotElement, remainingChildren } = extractSlottable(
68
+ children,
69
+ 'target',
70
+ );
71
+
72
+ expect(slotElement).toBeTruthy();
73
+ // Remaining should include only the non-target element (second target is also filtered out)
74
+ expect(remainingChildren).toHaveLength(1);
75
+ });
76
+
77
+ it('should preserve non-element children', () => {
78
+ const children = [
79
+ 'Text node',
80
+ createElement('div', { 'data-slot': 'target', key: '1' }, 'Target'),
81
+ createElement('div', { key: '2' }, 'Element'),
82
+ 123,
83
+ null,
84
+ undefined,
85
+ ];
86
+
87
+ const { slotElement, remainingChildren } = extractSlottable(
88
+ children,
89
+ 'target',
90
+ );
91
+
92
+ expect(slotElement).toBeTruthy();
93
+ // React.Children.toArray() filters out null and undefined automatically
94
+ // Should preserve text, number, and other element (3 items)
95
+ expect(remainingChildren).toHaveLength(3);
96
+ });
97
+ });
@@ -0,0 +1,49 @@
1
+ import { Children, ComponentType, isValidElement, ReactNode } from 'react';
2
+
3
+ /**
4
+ * Extracts children with a specific data-slot attribute or component type from a React children collection.
5
+ * Useful for separating specific components from general content in composite patterns.
6
+ *
7
+ * @param children - React children to process
8
+ * @param slotNameOrType - The data-slot value to extract, or the component type to match
9
+ * @returns An object containing the extracted slot element and remaining children
10
+ *
11
+ * @example
12
+ * // Extract by data-slot attribute
13
+ * const { slotElement, remainingChildren } = extractSlottable(children, 'secondary-action');
14
+ *
15
+ * @example
16
+ * // Extract by component type
17
+ * const { slotElement, remainingChildren } = extractSlottable(children, MyComponent);
18
+ *
19
+ * return (
20
+ * <div>
21
+ * {slotElement}
22
+ * <button>{remainingChildren}</button>
23
+ * </div>
24
+ * );
25
+ */
26
+ export function extractSlottable(
27
+ children: ReactNode,
28
+ slotNameOrType: string | ComponentType<any>,
29
+ ): {
30
+ slotElement: ReactNode;
31
+ remainingChildren: ReactNode[];
32
+ } {
33
+ const childArray = Children.toArray(children);
34
+
35
+ const matcher =
36
+ typeof slotNameOrType === 'string'
37
+ ? (child: ReactNode) =>
38
+ isValidElement(child) && child.props['data-slot'] === slotNameOrType
39
+ : (child: ReactNode) =>
40
+ isValidElement(child) && child.type === slotNameOrType;
41
+
42
+ const slotElement = childArray.find(matcher);
43
+ const remainingChildren = childArray.filter((child) => !matcher(child));
44
+
45
+ return {
46
+ slotElement: slotElement ?? null,
47
+ remainingChildren,
48
+ };
49
+ }
@@ -0,0 +1 @@
1
+ export * from './extractSlottable';
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { getObjectPath } from './get-object-path';
2
+ import { getObjectPath } from './getObjectPath';
3
3
 
4
4
  describe('getObjectPath', () => {
5
5
  const testObj = {
@@ -0,0 +1 @@
1
+ export { getObjectPath } from './getObjectPath';
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { formatThousands } from './format-thousands';
2
+ import { formatThousands } from './formatThousands';
3
3
 
4
4
  describe('formatThousands', () => {
5
5
  it('should format thousands with spaces', () => {
@@ -0,0 +1,3 @@
1
+ export { getFontSize } from './fontSizeFormatter';
2
+ export { formatThousands } from './formatThousands';
3
+ export { textFormatter } from './textFormatter';
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { textFormatter } from './text-formatter.js';
2
+ import { textFormatter } from './textFormatter.js';
3
3
 
4
4
  describe('textFormatter', () => {
5
5
  describe('decimal handling with allowDecimals=true (default)', () => {
@@ -1,4 +1,4 @@
1
- import { formatThousands } from './format-thousands';
1
+ import { formatThousands } from './formatThousands';
2
2
 
3
3
  export type TextFormatterOptions = {
4
4
  /** Whether to allow decimal values */
@@ -0,0 +1 @@
1
+ export * from './isTextChildren';
@@ -1,6 +1,6 @@
1
1
  import React, { ReactNode } from 'react';
2
2
  import { describe, it, expect } from 'vitest';
3
- import { isTextChildren } from './is-text-children';
3
+ import { isTextChildren } from './isTextChildren';
4
4
 
5
5
  describe('isAllowedTextChildren', () => {
6
6
  type Case = { name: string; input: unknown; expected: boolean };
@@ -0,0 +1 @@
1
+ export * from './string';
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { toPascalCase } from './string-utils.js';
2
+ import { toPascalCase } from './string.js';
3
3
 
4
4
  describe('toPascalCase', () => {
5
5
  it('should convert kebab-case to PascalCase', () => {
@@ -0,0 +1 @@
1
+ export * from './useMergeRef';
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-safe-context.d.ts","sourceRoot":"","sources":["../../../src/lib/create-safe-context/create-safe-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,EAAE,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAE1E,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,2 +0,0 @@
1
- export * from './create-safe-context';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/create-safe-context/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-object-path.d.ts","sourceRoot":"","sources":["../../../src/lib/get-object-path/get-object-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,GAAG,OAAO,EACvC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,MAAM,MAAM,EAAE,KACb,CAAC,GAAG,SAWN,CAAC"}
@@ -1,2 +0,0 @@
1
- export { getObjectPath } from './get-object-path';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/get-object-path/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"font-size-formatter.d.ts","sourceRoot":"","sources":["../../../src/lib/input-formatter/font-size-formatter.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOjD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"format-thousands.d.ts","sourceRoot":"","sources":["../../../src/lib/input-formatter/format-thousands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe;AAC7B,0BAA0B;AAC1B,KAAK,EAAE,MAAM;AACb,yCAAyC;AACzC,gBAAgB,UAAO,GACtB,MAAM,CAgBR"}
@@ -1,4 +0,0 @@
1
- export { getFontSize } from './font-size-formatter';
2
- export { formatThousands } from './format-thousands';
3
- export { textFormatter } from './text-formatter';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/input-formatter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"text-formatter.d.ts","sourceRoot":"","sources":["../../../src/lib/input-formatter/text-formatter.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAAG;IACjC,sCAAsC;IACtC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa;AAC3B,gCAAgC;AAChC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,oBAAyB,GACjC,MAAM,CA4DR"}
@@ -1,2 +0,0 @@
1
- export * from './is-text-children';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/is-text-children/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-text-children.d.ts","sourceRoot":"","sources":["../../../src/lib/is-text-children/is-text-children.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlC,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,YAGhD,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './string-utils';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/string-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/string-utils/string-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMhD"}
@@ -1,2 +0,0 @@
1
- export * from './use-merge-ref';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/use-merge-ref/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-merge-ref.d.ts","sourceRoot":"","sources":["../../../src/lib/use-merge-ref/use-merge-ref.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 +0,0 @@
1
- export * from './create-safe-context';
@@ -1 +0,0 @@
1
- export { getObjectPath } from './get-object-path';
@@ -1,3 +0,0 @@
1
- export { getFontSize } from './font-size-formatter';
2
- export { formatThousands } from './format-thousands';
3
- export { textFormatter } from './text-formatter';
@@ -1 +0,0 @@
1
- export * from './is-text-children';
@@ -1 +0,0 @@
1
- export * from './string-utils';
@@ -1 +0,0 @@
1
- export * from './use-merge-ref';