{"version":3,"file":"forward-ref.mjs","sources":["../../../../../../packages/components/tooltip-v2/src/forward-ref.tsx"],"sourcesContent":["import { Fragment, defineComponent, ref } from 'vue'\nimport {\n  buildProps,\n  composeRefs,\n  definePropType,\n  ensureOnlyChild,\n} from '@bigin/utils'\n\nimport type { ExtractPropTypes, VNodeArrayChildren } from 'vue'\n\nexport type RefSetter = (el: HTMLElement | null) => void\n\nexport const forwardRefProps = buildProps({\n  setRef: { type: definePropType<RefSetter>(Function), required: true },\n  onlyChild: Boolean,\n} as const)\n\nexport type ForwardRefProps = ExtractPropTypes<typeof forwardRefProps>\n\n// TODO: consider make this component a reusable component without the only child feature.\nexport default defineComponent({\n  props: forwardRefProps,\n  setup(props, { slots }) {\n    const fragmentRef = ref()\n    const setRef = composeRefs(fragmentRef, (el) => {\n      // vue fragments is represented as a text element.\n      // The first element sibling should be the first element children of fragment.\n      // This is how we get the element.\n      if (el) {\n        props.setRef(\n          (el as HTMLElement).nextElementSibling as HTMLElement | null\n        )\n      } else {\n        props.setRef(null)\n      }\n    })\n    return () => {\n      const [firstChild] = slots.default?.() || []\n      const child = props.onlyChild\n        ? ensureOnlyChild(firstChild.children as VNodeArrayChildren)\n        : firstChild.children\n      // Dunno why the ref for jsx complains about the typing issue which was not\n      // in template\n      return <Fragment ref={setRef as any}>{child}</Fragment>\n    }\n  },\n})\n"],"names":["forwardRefProps","buildProps","setRef","type","definePropType","Function","required","onlyChild","Boolean","defineComponent","props","setup","slots","fragmentRef","ref","composeRefs","el","nextElementSibling","firstChild","default","child","ensureOnlyChild","children","_createVNode","_Fragment"],"mappings":";;;;;;AAYO,MAAMA,kBAAkBC,UAAW,CAAA;AAAA,EACxCC,MAAQ,EAAA;AAAA,IAAEC,IAAAA,EAAMC,eAA0BC,QAAQ,CAAA;AAAA,IAAGC,QAAU,EAAA,IAAA;AAAA,GAAK;AAAA,EACpEC,SAAWC,EAAAA,OAAAA;AACb,CAAC,EAAA;AAKD,iBAAeC,eAAgB,CAAA;AAAA,EAC7BC,KAAOV,EAAAA,eAAAA;AAAAA,EACPW,MAAMD,KAAO,EAAA;AAAA,IAAEE,KAAAA;AAAAA,GAAS,EAAA;AACtB,IAAA,MAAMC,cAAcC,GAAK,EAAA,CAAA;AACzB,IAAMZ,MAAAA,MAAAA,GAASa,WAAYF,CAAAA,WAAAA,EAAcG,CAAO,EAAA,KAAA;AAI9C,MAAA,IAAIA,EAAI,EAAA;AACNN,QAAMR,KAAAA,CAAAA,MAAAA,CACHc,GAAmBC,kBAAkB,CAAA,CAAA;AAAA,OAEnC,MAAA;AACLP,QAAAA,KAAAA,CAAMR,OAAO,IAAI,CAAA,CAAA;AAAA,OACnB;AAAA,KACD,CAAA,CAAA;AACD,IAAA,OAAO,MAAM;AACX,MAAA,MAAM,CAACgB,UAAU,CAAA,GAAIN,KAAMO,CAAAA,OAAAA,QAAe,EAAE,CAAA;AAC5C,MAAA,MAAMC,QAAQV,KAAMH,CAAAA,SAAAA,GAChBc,gBAAgBH,UAAWI,CAAAA,QAAQ,IACnCJ,UAAWI,CAAAA,QAAAA,CAAAA;AAGf,MAAA,OAAAC,YAAAC,QAAA,EAAA;AAAA,QAAA,KAAsBtB,EAAAA,MAAAA;AAAAA,OAAM,EAAA,CAAUkB,KAAK,CAAA,CAAA,CAAA;AAAA,KAC7C,CAAA;AAAA,GACF;AACF,CAAC,CAAA;;;;"}