@roots/bud-dashboard
Version:
bud.js core module
52 lines (51 loc) • 2.52 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@roots/bud-support/jsx-runtime";
import View from '@roots/bud-dashboard/components/view';
import { Box, Text } from '@roots/bud-support/ink';
export default function Debug({ compilation, debug }) {
if (!debug)
return null;
if (!compilation)
return null;
const format = (obj) => Object.entries(obj ?? {})
.filter(([k, v]) => typeof v !== `undefined` &&
typeof v !== `string` &&
typeof v !== `number` &&
v !== null &&
!(Array.isArray(v) && v.length === 0))
.map(([k, v]) => [k, typeof v === `function` ? `function` : v]);
return (_jsx(_Fragment, { children: format(compilation).map(([key, fields], id) => {
if (typeof key !== `string`)
return null;
return (_jsx(View, { footer: _jsxs(Text, { color: "dim", children: ["debug config: ", `${id + 1}`, " /", ` `, `${format(compilation).length}`] }), head: _jsxs(Text, { color: "cyan", children: ["stats: ", key] }), children: _jsx(Box, { flexDirection: "column", gap: 0, children: _jsx(Fields, { fields: fields }) }) }, id));
}) }));
}
const isPrimitive = (field) => {
return typeof field === `string` || typeof field === `number`;
};
const Fields = ({ fields }) => {
if (fields === undefined) {
return _jsx(Text, { wrap: "truncate-end", children: "undefined" });
}
if (typeof fields === `boolean`) {
return _jsx(Text, { children: `${fields}` });
}
if (fields === null) {
return _jsx(Text, { wrap: "truncate-end", children: "null" });
}
if (Array.isArray(fields) && fields.length === 0) {
return _jsx(Text, { wrap: "truncate-end", children: "[]" });
}
if (isPrimitive(fields)) {
const preLoaderSplit = `${fields}`.split(`!`).pop();
if (!preLoaderSplit)
return null;
return (_jsx(Text, { wrap: "truncate-end", children: preLoaderSplit.split(`?`).pop() }));
}
return Object.entries(fields)
.filter(([k, v]) => v !== undefined && v !== null)
.map(([key, fields], id) => {
if (!fields)
return null;
return (_jsxs(Box, { borderTop: !isPrimitive(fields), flexDirection: isPrimitive(fields) ? `row` : `column`, gap: isPrimitive(fields) ? 1 : 0, overflowX: "hidden", paddingLeft: 1, children: [_jsxs(Text, { color: "cyan", children: [typeof key === `string` ? key : `-`, ":"] }), _jsx(Fields, { fields: fields })] }, id));
});
};