@adara-cs/utils 2.9.0 → 2.10.0

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.
package/dist/csx.js CHANGED
@@ -1,4 +1,4 @@
1
- const e = (...o) => o.filter(Boolean).join(" ");
1
+ const e = (...o) => Array.from(new Set(o.filter(Boolean))).join(" ");
2
2
  export {
3
3
  e as csx
4
4
  };
package/dist/csx.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"csx.js","sources":["../src/csx.ts"],"sourcesContent":["export const csx = (...rest: (string | undefined)[]) => rest.filter(Boolean).join(' ')"],"names":["csx","rest"],"mappings":"AAAa,MAAAA,IAAM,IAAIC,MAAiCA,EAAK,OAAO,OAAO,EAAE,KAAK,GAAG;"}
1
+ {"version":3,"file":"csx.js","sources":["../src/csx.ts"],"sourcesContent":["export const csx = (...rest: (string | undefined)[]) => Array.from(new Set(rest.filter(Boolean))).join(' ')"],"names":["csx","rest"],"mappings":"AAAO,MAAMA,IAAM,IAAIC,MAAiC,MAAM,KAAK,IAAI,IAAIA,EAAK,OAAO,OAAO,CAAC,CAAC,EAAE,KAAK,GAAG;"}
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './csx';
2
2
  export * from './mergeRefs';
3
3
  export * from './inRange';
4
4
  export * from './getElementRef';
5
+ export * from './mergeProps.ts';
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import { csx as o } from "./csx.js";
2
- import { mergeRefs as m } from "./mergeRefs.js";
3
- import { inRange as x } from "./inRange.js";
2
+ import { mergeRefs as f } from "./mergeRefs.js";
3
+ import { inRange as p } from "./inRange.js";
4
4
  import { getElementRef as g } from "./getElementRef.js";
5
+ import { mergeProps as s } from "./mergeProps.js";
5
6
  export {
6
7
  o as csx,
7
8
  g as getElementRef,
8
- x as inRange,
9
- m as mergeRefs
9
+ p as inRange,
10
+ s as mergeProps,
11
+ f as mergeRefs
10
12
  };
11
13
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Merges multiple props objects together into a single props object.
3
+ *
4
+ * - ✅ Event handlers (`onClick`, `onChange`, etc.) are chained in order of appearance.
5
+ * - ✅ `className` values are concatenated with space.
6
+ * - ✅ `id` is deduplicated: the first defined value is preserved.
7
+ * - ✅ All other props are shallow-merged, with the last one winning.
8
+ *
9
+ * This function is especially useful for composing component props,
10
+ * e.g., merging parent and child props in polymorphic or slot-based components.
11
+ *
12
+ * @template T - Type of the props object.
13
+ * @param {...T[]} args - One or more props objects to merge together.
14
+ * @returns {T} - A new object containing the merged props.
15
+ *
16
+ * @example
17
+ * const props = mergeProps(
18
+ * { className: 'btn', onClick: () => console.log('base') },
19
+ * { className: 'primary', onClick: () => console.log('override') }
20
+ * );
21
+ *
22
+ * // props.className === 'btn primary'
23
+ * // props.onClick calls both handlers
24
+ */
25
+ export declare function mergeProps<T extends Record<string, unknown>>(...args: T[]): T;
@@ -0,0 +1,40 @@
1
+ import { csx as r } from "./csx.js";
2
+ import { mergeRefs as s } from "./mergeRefs.js";
3
+ function m(...c) {
4
+ const e = {};
5
+ for (const f of c)
6
+ for (const o in f) {
7
+ const t = f[o], n = e[o];
8
+ if (typeof n == "function" && typeof t == "function" && /^on[A-Z]/.test(o)) {
9
+ e[o] = (...i) => {
10
+ n(...i), t(...i);
11
+ };
12
+ continue;
13
+ }
14
+ if (o === "ref") {
15
+ e[o] = s([n, t]);
16
+ continue;
17
+ }
18
+ if (o === "style" && typeof n == "object" && typeof t == "object") {
19
+ e[o] = {
20
+ ...n,
21
+ ...t
22
+ };
23
+ continue;
24
+ }
25
+ if (o === "className") {
26
+ e[o] = r(n, t);
27
+ continue;
28
+ }
29
+ if (o === "id") {
30
+ e[o] = n ?? t;
31
+ continue;
32
+ }
33
+ e[o] = t;
34
+ }
35
+ return e;
36
+ }
37
+ export {
38
+ m as mergeProps
39
+ };
40
+ //# sourceMappingURL=mergeProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeProps.js","sources":["../src/mergeProps.ts"],"sourcesContent":["import { csx } from './csx';\nimport { mergeRefs } from './mergeRefs';\nimport { Ref } from 'react';\n\n/**\n * Merges multiple props objects together into a single props object.\n *\n * - ✅ Event handlers (`onClick`, `onChange`, etc.) are chained in order of appearance.\n * - ✅ `className` values are concatenated with space.\n * - ✅ `id` is deduplicated: the first defined value is preserved.\n * - ✅ All other props are shallow-merged, with the last one winning.\n *\n * This function is especially useful for composing component props,\n * e.g., merging parent and child props in polymorphic or slot-based components.\n *\n * @template T - Type of the props object.\n * @param {...T[]} args - One or more props objects to merge together.\n * @returns {T} - A new object containing the merged props.\n *\n * @example\n * const props = mergeProps(\n * { className: 'btn', onClick: () => console.log('base') },\n * { className: 'primary', onClick: () => console.log('override') }\n * );\n *\n * // props.className === 'btn primary'\n * // props.onClick calls both handlers\n */\nexport function mergeProps<T extends Record<string, unknown>>(...args: T[]): T {\n const result: Record<string, unknown> = {};\n\n for (const props of args) {\n for (const key in props) {\n const newValue = props[key];\n const existingValue = result[key];\n\n if (\n typeof existingValue === 'function' &&\n typeof newValue === 'function' &&\n /^on[A-Z]/.test(key)\n ) {\n result[key] = (...args: unknown[]) => {\n existingValue(...args);\n newValue(...args);\n };\n continue;\n }\n\n if (key === 'ref') {\n result[key] = mergeRefs([existingValue as Ref<unknown>, newValue as Ref<unknown>])\n continue\n }\n\n if (key === 'style' && typeof existingValue === 'object' && typeof newValue === 'object') {\n result[key] = {\n ...existingValue,\n ...newValue,\n }\n continue;\n }\n\n if (key === 'className') {\n result[key] = csx(existingValue as string, newValue as string);\n continue;\n }\n\n if (key === 'id') {\n result[key] = existingValue ?? newValue;\n continue;\n }\n\n result[key] = newValue;\n }\n }\n\n return result as T;\n}"],"names":["mergeProps","args","result","props","key","newValue","existingValue","mergeRefs","csx"],"mappings":";;AA4BO,SAASA,KAAiDC,GAAc;AAC7E,QAAMC,IAAkC,CAAC;AAEzC,aAAWC,KAASF;AAClB,eAAWG,KAAOD,GAAO;AACjB,YAAAE,IAAWF,EAAMC,CAAG,GACpBE,IAAgBJ,EAAOE,CAAG;AAG9B,UAAA,OAAOE,KAAkB,cACzB,OAAOD,KAAa,cACpB,WAAW,KAAKD,CAAG,GACnB;AACO,QAAAF,EAAAE,CAAG,IAAI,IAAIH,MAAoB;AACpC,UAAAK,EAAc,GAAGL,CAAI,GACrBI,EAAS,GAAGJ,CAAI;AAAA,QAClB;AACA;AAAA,MAAA;AAGF,UAAIG,MAAQ,OAAO;AACjB,QAAAF,EAAOE,CAAG,IAAIG,EAAU,CAACD,GAA+BD,CAAwB,CAAC;AACjF;AAAA,MAAA;AAGF,UAAID,MAAQ,WAAW,OAAOE,KAAkB,YAAY,OAAOD,KAAa,UAAU;AACxF,QAAAH,EAAOE,CAAG,IAAI;AAAA,UACZ,GAAGE;AAAA,UACH,GAAGD;AAAA,QACL;AACA;AAAA,MAAA;AAGF,UAAID,MAAQ,aAAa;AACvB,QAAAF,EAAOE,CAAG,IAAII,EAAIF,GAAyBD,CAAkB;AAC7D;AAAA,MAAA;AAGF,UAAID,MAAQ,MAAM;AACT,QAAAF,EAAAE,CAAG,IAAIE,KAAiBD;AAC/B;AAAA,MAAA;AAGF,MAAAH,EAAOE,CAAG,IAAIC;AAAA,IAAA;AAIX,SAAAH;AACT;"}
@@ -1,2 +1,2 @@
1
- import { LegacyRef, MutableRefObject, RefCallback } from 'react';
2
- export declare const mergeRefs: <T = never>(refs: Array<MutableRefObject<T> | LegacyRef<T> | undefined | null>) => RefCallback<T>;
1
+ import { Ref, RefCallback } from 'react';
2
+ export declare const mergeRefs: <T = unknown>(refs: Array<Ref<T> | undefined | null>) => RefCallback<T>;
package/dist/mergeRefs.js CHANGED
@@ -1,9 +1,9 @@
1
- const o = (e) => (t) => {
2
- e.forEach((n) => {
3
- typeof n == "function" ? n(t) : n != null && (n.current = t);
1
+ const n = (e) => (o) => {
2
+ e.forEach((t) => {
3
+ typeof t == "function" ? t(o) : t != null && typeof t == "object" && (t.current = o);
4
4
  });
5
5
  };
6
6
  export {
7
- o as mergeRefs
7
+ n as mergeRefs
8
8
  };
9
9
  //# sourceMappingURL=mergeRefs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mergeRefs.js","sources":["../src/mergeRefs.ts"],"sourcesContent":["import { LegacyRef, MutableRefObject, RefCallback } from 'react';\n\nexport const mergeRefs = <T = never>(\n refs: Array<MutableRefObject<T> | LegacyRef<T> | undefined | null>\n): RefCallback<T> => {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref != null) {\n (ref as MutableRefObject<T | null>).current = value;\n }\n });\n };\n}"],"names":["mergeRefs","refs","value","ref"],"mappings":"AAEa,MAAAA,IAAY,CACvBC,MAEO,CAACC,MAAU;AACX,EAAAD,EAAA,QAAQ,CAACE,MAAQ;AAChB,IAAA,OAAOA,KAAQ,aACjBA,EAAID,CAAK,IACAC,KAAO,SACfA,EAAmC,UAAUD;AAAA,EAChD,CACD;AACH;"}
1
+ {"version":3,"file":"mergeRefs.js","sources":["../src/mergeRefs.ts"],"sourcesContent":["import { Ref, RefCallback, RefObject } from 'react';\n\nexport const mergeRefs = <T = unknown>(\n refs: Array<Ref<T> | undefined | null>\n): RefCallback<T> => {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref != null && typeof ref === 'object') {\n (ref as RefObject<T | null>).current = value;\n }\n });\n };\n}"],"names":["mergeRefs","refs","value","ref"],"mappings":"AAEa,MAAAA,IAAY,CACvBC,MAEO,CAACC,MAAU;AACX,EAAAD,EAAA,QAAQ,CAACE,MAAQ;AAChB,IAAA,OAAOA,KAAQ,aACjBA,EAAID,CAAK,IACAC,KAAO,QAAQ,OAAOA,KAAQ,aACtCA,EAA4B,UAAUD;AAAA,EACzC,CACD;AACH;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adara-cs/utils",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Utilities for @adara-cs/ui-kit-web",
5
5
  "license": "MIT",
6
6
  "keywords": [