@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
44 lines (43 loc) • 2.25 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import ArrayValue from "./ArrayValue.js";
import DataGridDetails from "./DataGridDetails.js";
import SimpleField from "./SimpleField.js";
import UriAttribute from "./UriField.js";
import { accessNested, generateMaxWidth } from "./util.js";
import { isObject, isUriLocation } from "../../util/index.js";
const MAX_FIELD_NAME_WIDTH = 170;
const globalOmit = [
'__jbrowsefmt',
'length',
'position',
'subfeatures',
'uniqueId',
'exonFrames',
'parentId',
'thickStart',
'thickEnd',
'_lineHash',
];
export default function Attributes(props) {
const { attributes, omit = [], omitSingleLevel = [], descriptions, formatter, hideUris, prefix = [], } = props;
const omits = new Set([...omit, ...globalOmit, ...omitSingleLevel]);
const { __jbrowsefmt, ...rest } = attributes;
const filteredFormattedAttributes = Object.entries({
...rest,
...__jbrowsefmt,
}).filter(([k, v]) => v != null && !omits.has(k));
const maxLabelWidth = generateMaxWidth(filteredFormattedAttributes, prefix);
return (_jsx(_Fragment, { children: filteredFormattedAttributes.map(([key, value]) => {
const description = accessNested([...prefix, key], descriptions);
if (Array.isArray(value)) {
return value.length > 1 && value.every(val => isObject(val)) ? (_jsx(DataGridDetails, { name: key, prefix: prefix, value: value }, key)) : (_jsx(ArrayValue, { name: key, value: value, formatter: formatter, description: description, prefix: prefix }, key));
}
else if (isObject(value)) {
const { omitSingleLevel, ...rest } = props;
return isUriLocation(value) ? (hideUris ? null : (_jsx(UriAttribute, { name: key, prefix: prefix, value: value }, key))) : (_jsx(Attributes, { ...rest, formatter: formatter, attributes: value, descriptions: descriptions, prefix: [...prefix, key] }, key));
}
else {
return (_jsx(SimpleField, { name: key, formatter: formatter, value: value, description: description, prefix: prefix, width: Math.min(maxLabelWidth, MAX_FIELD_NAME_WIDTH) }, key));
}
}) }));
}