/** @jsx jsx */
import { jsx } from '@emotion/core';
import PropTypes from 'prop-types';
import { formatBytes } from '../utils/format.js';
import { createHTML } from '../utils/markup.js';
import { ContentArea, ContentAreaHeaderBar } from './ContentArea.js';
function getBasename(path) {
let segments = path.split('/');
return segments[segments.length - 1];
}
function ImageViewer({ path, uri }) {
return (
);
}
function CodeListing({ highlights }) {
let lines = highlights.slice(0);
let hasTrailingNewline = lines.length && lines[lines.length - 1] === '';
if (hasTrailingNewline) {
lines.pop();
}
return (
{lines.map((line, index) => {
let lineNumber = index + 1;
return (
{lineNumber}
|
|
);
})}
{!hasTrailingNewline && (
\
|
No newline at end of file
|
)}
);
}
function BinaryViewer() {
return (
);
}
export default function FileViewer({
packageName,
packageVersion,
path,
details
}) {
let { highlights, uri, language, size } = details;
return (
{formatBytes(size)}
{language}
View Raw
{highlights ? (
) : uri ? (
) : (
)}
);
}
if (process.env.NODE_ENV !== 'production') {
FileViewer.propTypes = {
path: PropTypes.string.isRequired,
details: PropTypes.shape({
contentType: PropTypes.string.isRequired,
highlights: PropTypes.arrayOf(PropTypes.string), // code
uri: PropTypes.string, // images
integrity: PropTypes.string.isRequired,
language: PropTypes.string.isRequired,
size: PropTypes.number.isRequired
}).isRequired
};
}