import React from 'react'; import clsx from 'clsx'; import classes from './styles.module.scss'; import renderReflection from './renderReflection'; import Params from './Params'; import useReflectionIndex from './useReflectionIndex'; import Badges from './Badges'; const thirdPartiesMap: Record = { '@native-html/transient-render-engine': 'https://github.com/native-html/core/tree/master/packages/transient-render-engine', '@native-html/css-processor': 'https://github.com/native-html/core/tree/master/packages/css-processor', domhandler: 'https://github.com/fb55/domhandler' }; function extractLibName(fileName: string) { const fragments = fileName.split('/'); try { // remove node_modules fragment fragments.splice(0, 1); if (fragments[0].startsWith('@')) { return fragments[0] + '/' + fragments[1]; } return fragments[0]; } catch (e) { console.error(e); } return ''; } function ExternalSource({ libraryName }: { libraryName: string }) { if (!(libraryName in thirdPartiesMap)) { throw new Error(`${libraryName} is not registered as third party`); } return ( {libraryName} ); } export default function HeaderTypeBox({ reflectionId, version }: { reflectionId: number; version: string; }) { const index = useReflectionIndex(); const reflection = index[reflectionId]; const isExternal = reflection.flags.isExternal; const source = reflection.sources?.[0]; const libraryName = extractLibName(source.fileName); return ( <>
{renderReflection(reflection, new Params((id) => index[id]))}
Defined in{' '} {!isExternal && source && ( {source.fileName} {/* {`react-native-render-html/…/${source.fileName .split('/') .pop()}#L${source.line}`} */} )} {isExternal && source && }
); }