UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

1 lines 1.94 kB
{"version":3,"file":"Link.mjs","names":["Link: FC<LinkProps>","Citation","A"],"sources":["../../../src/mdx/mdxComponents/Link.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport A from '@/A';\nimport type { AProps } from '@/types';\nimport type { CitationItem } from '@/types/citation';\nimport { safeParseJSON } from '@/utils/safeParseJSON';\n\nimport Citation from './Citation';\n\nexport interface LinkProps extends AProps {\n 'aria-describedby'?: string;\n 'citations'?: CitationItem[];\n 'data-footnote-ref'?: boolean;\n 'data-link'?: string;\n 'id'?: string;\n 'node'?: any;\n}\n\nconst Link: FC<LinkProps> = ({ href, target, citations, ...rest }) => {\n // [^1] 格式类型\n if (rest['data-footnote-ref']) {\n return (\n <Citation citationDetail={safeParseJSON(rest['data-link'])} href={href} id={rest.id!} inSup>\n {rest.children}\n </Citation>\n );\n }\n\n // [1] 格式类型,搭配 citations 注入\n const match = href?.match(/citation-(\\d+)/);\n\n if (match) {\n const index = Number.parseInt(match[1]) - 1;\n\n const detail = citations?.[index];\n\n return (\n <Citation citationDetail={detail} id={match[1]}>\n {match[1]}\n </Citation>\n );\n }\n\n const isNewWindow = href?.startsWith('http');\n\n return <A href={href} target={target || isNewWindow ? '_blank' : undefined} {...rest} />;\n};\n\nLink.displayName = 'MdxLink';\n\nexport default Link;\n"],"mappings":";;;;;;;;AAoBA,MAAMA,QAAuB,EAAE,MAAM,QAAQ,WAAW,GAAG,WAAW;AAEpE,KAAI,KAAK,qBACP,QACE,oBAACC;EAAS,gBAAgB,cAAc,KAAK,aAAa;EAAQ;EAAM,IAAI,KAAK;EAAK;YACnF,KAAK;GACG;CAKf,MAAM,QAAQ,MAAM,MAAM,iBAAiB;AAE3C,KAAI,OAAO;EACT,MAAM,QAAQ,OAAO,SAAS,MAAM,GAAG,GAAG;EAE1C,MAAM,SAAS,YAAY;AAE3B,SACE,oBAACA;GAAS,gBAAgB;GAAQ,IAAI,MAAM;aACzC,MAAM;IACE;;CAIf,MAAM,cAAc,MAAM,WAAW,OAAO;AAE5C,QAAO,oBAACC;EAAQ;EAAM,QAAQ,UAAU,cAAc,WAAW;EAAW,GAAI;GAAQ;;AAG1F,KAAK,cAAc;AAEnB,mBAAe"}