{"version":3,"file":"mergeRefs.mjs","names":[],"sources":["../../../../package/common/utils/mergeRefs.ts"],"sourcesContent":["import type { Ref } from 'react';\n\n/**\n * Fans one element out to several refs, for a component that needs the node itself *and*\n * hands it to the consumer through a `ref` prop.\n *\n * The returned callback is a new function on every render, so React detaches and reattaches\n * it each time (null, then the node). Every ref here is therefore written twice per render,\n * which is fine for storing a node and wrong for anything with a side effect. Call it inline\n * rather than memoising: a memo would have to list the refs it closes over, and a consumer\n * passing an inline callback ref changes that identity every render anyway.\n */\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): (node: T | null) => void {\n  return (node) => {\n    for (const ref of refs) {\n      if (typeof ref === 'function') ref(node);\n      else if (ref) (ref as { current: T | null }).current = node;\n    }\n  };\n}\n"],"mappings":"aAYA,SAAgB,EAAa,GAAG,EAAwD,CACtF,MAAQ,IAAS,CACf,IAAK,IAAM,KAAO,EACZ,OAAO,GAAQ,WAAY,EAAI,CAAI,EAC9B,IAAK,EAA+B,QAAU,EAE3D,CACF"}