diff --git a/src/components/json.tsx b/src/components/json.tsx index 2baaa77..5f3c708 100644 --- a/src/components/json.tsx +++ b/src/components/json.tsx @@ -167,37 +167,59 @@ const CollapsibleItem = (props: { const [show, setShow] = createSignal(true); const isBlobContext = props.parentIsBlob ?? ctx.parentIsBlob; + const isObject = () => props.value === Object(props.value); + const isCollapsible = () => isObject() || typeof props.value === "string"; + const summary = () => { + if (typeof props.value === "string") { + const len = props.value.length; + return `${len.toLocaleString()} ${len === 1 ? "char" : "chars"}`; + } + if (Array.isArray(props.value)) { + const len = (props.value as JSONType[]).length; + return `[ ${len} ${len === 1 ? "item" : "items"} ]`; + } + if (isObject()) { + const len = Object.keys(props.value as object).length; + return `{ ${len} ${len === 1 ? "key" : "keys"} }`; + } + }; + return (