// Copyright 2017-2026 @pezkuwi/app-js authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Log } from './types.js'; import React from 'react'; import { styled } from '@pezkuwi/react-components'; import { isError, isNull, isUndefined } from '@pezkuwi/util'; interface Props { children?: React.ReactNode; className?: string; logs: Log[]; } const format = (value: unknown): string => { if (isError(value)) { return value.stack ? value.stack : value.toString(); } else if (isUndefined(value)) { return 'undefined'; } else if (isNull(value)) { return 'null'; } else if (Array.isArray(value)) { return `[${value.map(format).join(', ')}]`; } else if (value instanceof Map) { return `{${[...value.entries()] .map(([k, v]) => `${(k as string).toString()}: ${format(v)}`) .join(', ')}}`; } // This _could_ fail as well, hence the catch below return (value as string).toString(); }; const renderEntry = ({ args, type }: Log, index: number): React.ReactNode => { try { return (
{logs.map(renderEntry)}