{"version":3,"file":"getElRefHelper.mjs","sources":[""],"sourcesContent":["import { isNode } from \"@web3r/flowerkit/dom\";\r\nimport type { RefObject } from \"react\";\r\nimport { createRef } from \"react\";\r\n\r\n/**\n * Возвращает DOM-элемент, указанный в объекте `ref`.\n * Полезно, если в компоненте используется `useImperativeHandle`.\n * @template T - тип значения, хранящегося в `ref.current`.\n * @example\n * import { useEffect, useRef } from \"react\";\n * import { DatePicker } from \"@delement/ui/components\";\n * import { getElRefHelper } from \"@delement/ui/utils/react\";\n *\r\n * const Component = () => {\r\n *\r\n *   const pickerRef = useRef(null);\r\n *\r\n *   useEffect(() => {\r\n *     const node = getElRefHelper(pickerRef);\r\n *     console.debug(node); // => HTMLElement\r\n *   });\r\n *\r\n *   return <DatePicker ref={pickerRef} />;\r\n * };\r\n * @returns {HTMLElement|null} Возвращает найденный DOM-элемент или `null`, если его не удалось извлечь из `ref`.\n */\nexport const getElRefHelper = <T = unknown>(\r\n  ref: RefObject<T | null> | HTMLElement | null | undefined = createRef<T>()\r\n): HTMLElement | null => {\r\n\r\n  if (!ref) {\r\n    return null;\r\n  }\r\n\r\n  if (typeof HTMLElement !== \"undefined\" && ref instanceof HTMLElement) {\n    return ref;\r\n  }\r\n\r\n  const current = (\"current\" in ref) ? ref.current : null;\r\n\r\n  if (current && typeof current === \"object\") {\r\n    const currentObj = current as Record<string, unknown>;\r\n\r\n    if (\"element\" in currentObj && isNode(currentObj.element)) {\r\n      return currentObj.element as HTMLElement;\r\n    }\r\n\r\n    if (\"el\" in currentObj && isNode(currentObj.el)) {\r\n      return currentObj.el as HTMLElement;\r\n    }\r\n\r\n    if (isNode(current)) {\r\n      return current as unknown as HTMLElement;\r\n    }\r\n  }\r\n\r\n  return null;\n};\n"],"names":["getElRefHelper","ref","createRef","HTMLElement","current","currentObj","isNode","element","el"],"mappings":";;;;;;;;;;;;;;;;;;;;;;GA0BO,MAAMA,eAAiB,CAC5BC,IAA4DC,eAG5D,IAAKD,IACH,OAAO,KAGT,UAAWE,cAAgB,aAAeF,eAAeE,YACvD,OAAOF,IAGT,MAAMG,QAAW,YAAaH,IAAOA,IAAIG,QAAU,KAEnD,GAAIA,gBAAkBA,UAAY,SAAU,CAC1C,MAAMC,WAAaD,QAEnB,GAAI,YAAaC,YAAcC,OAAOD,WAAWE,SAC/C,OAAOF,WAAWE,QAGpB,GAAI,OAAQF,YAAcC,OAAOD,WAAWG,IAC1C,OAAOH,WAAWG,GAGpB,GAAIF,OAAOF,SACT,OAAOA,OAEX,CAEA,OAAO"}