{"version":3,"file":"merge-refs.cjs","names":[],"sources":["../../src/utils/merge-refs.ts"],"sourcesContent":["import { type Ref, type RefCallback } from \"react\";\nimport { isFunction } from \"@rzl-zone/utils-js/predicates\";\n\n/** -------------------------------------------------------------------\n * * ***Merges multiple React refs into a single ref callback,\n * allowing them to be assigned simultaneously.***\n * --------------------------------------------------------------------\n *\n * This utility enables safe composition of refs when multiple components,\n * hooks, or consumers need access to the same underlying DOM element\n * or component instance.\n *\n * It supports both:\n * - **Callback refs**\n * - **Mutable object refs** (`RefObject`)\n *\n * - **Behavior:**\n *    - Invokes all function refs with the provided value\n *    - Assigns the value to `.current` for object refs\n *    - Safely ignores `undefined` refs\n *    - Preserves invocation order from left to right\n *\n * This is especially useful in **React** when combining forwarded refs\n * with internal refs.\n *\n * @typeParam T - The type of the ref value (e.g. `HTMLDivElement`).\n * @param refs - A list of refs to merge. Each ref may be a callback,\n * a ref object, or `undefined`.\n *\n * @returns A single `RefCallback` that updates all provided refs.\n *\n * @example\n * ```tsx\n * const localRef = useRef<HTMLDivElement>(null);\n *\n * function Component(props: { ref?: Ref<HTMLDivElement> }) {\n *   return (\n *     <div ref={mergeRefs(localRef, props.ref)} />\n *   );\n * }\n * ```\n */\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T> {\n  return (value) => {\n    refs.forEach((ref) => {\n      if (isFunction(ref)) {\n        ref(value);\n      } else if (ref) {\n        ref.current = value;\n      }\n    });\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,UAAa,GAAG,MAA8C;CAC5E,QAAQ,UAAU;EAChB,KAAK,SAAS,QAAQ;GACpB,kDAAe,GAAG,GAChB,IAAI,KAAK;QACJ,IAAI,KACT,IAAI,UAAU;EAElB,CAAC;CACH;AACF"}
