{"version":3,"file":"useMergeRefs.mjs","sources":["../../../src/hooks/useMergeRefs.ts"],"sourcesContent":["import { useMemo } from 'react'\n\ntype ReactRef<Node> =\n  | React.RefCallback<Node>\n  | React.MutableRefObject<Node | null>\n\ntype Ref<Node> = ReactRef<Node> | null | undefined\ntype Refs<Node> = Array<Ref<Node>>\n\nfunction assignRef<Node>(ref: Ref<Node>, value: Node | null) {\n  if (ref === null || ref === undefined) {\n    return\n  }\n\n  if (typeof ref === 'function') {\n    ref(value)\n    return\n  }\n\n  try {\n    ref.current = value\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n  } catch (error) {\n    throw new Error(`Cannot assign value '${value}' to ref '${ref}'`)\n  }\n}\n\nfunction mergeRefs<Node>(...refs: Refs<Node>) {\n  return (node: Node | null) => {\n    refs.forEach((ref) => {\n      assignRef(ref, node)\n    })\n  }\n}\n\nexport default function useMergeRefs<Node>(...refs: Refs<Node>) {\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  return useMemo(() => mergeRefs(...refs), refs)\n}\n"],"names":["assignRef","ref","value","undefined","current","error","Error","mergeRefs","refs","node","forEach","useMergeRefs","useMemo"],"mappings":";;AASA,SAASA,SAASA,CAAOC,GAAc,EAAEC,KAAkB,EAAE;AAC3D,EAAA,IAAID,GAAG,KAAK,IAAI,IAAIA,GAAG,KAAKE,SAAS,EAAE;AACrC,IAAA;AACF;AAEA,EAAA,IAAI,OAAOF,GAAG,KAAK,UAAU,EAAE;IAC7BA,GAAG,CAACC,KAAK,CAAC;AACV,IAAA;AACF;EAEA,IAAI;IACFD,GAAG,CAACG,OAAO,GAAGF,KAAK;AACnB;GACD,CAAC,OAAOG,KAAK,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,CAAA,qBAAA,EAAwBJ,KAAK,CAAaD,UAAAA,EAAAA,GAAG,GAAG,CAAC;AACnE;AACF;AAEA,SAASM,SAASA,CAAO,GAAGC,IAAgB,EAAE;AAC5C,EAAA,OAAQC,IAAiB,IAAK;AAC5BD,IAAAA,IAAI,CAACE,OAAO,CAAET,GAAG,IAAK;AACpBD,MAAAA,SAAS,CAACC,GAAG,EAAEQ,IAAI,CAAC;AACtB,KAAC,CAAC;GACH;AACH;AAEe,SAASE,YAAYA,CAAO,GAAGH,IAAgB,EAAE;AAC9D;EACA,OAAOI,OAAO,CAAC,MAAML,SAAS,CAAC,GAAGC,IAAI,CAAC,EAAEA,IAAI,CAAC;AAChD;;;;"}