import { type JsonNode, JsonNodeHastElement, getAccessibleDescription, isRootKeyPath, jsonNodeToElement, jsonToTree, keyPathToId, keyPathToKey, } from "@zag-js/json-tree-utils" import { jsonTreeData } from "@zag-js/shared" import { Key } from "@zag-js/solid" import { Index, JSX } from "solid-js" import { Dynamic } from "solid-js/web" interface KeyNodeProps { node: JsonNode } const KeyNode = (props: KeyNodeProps): JSX.Element => { const key = () => keyPathToKey(props.node.keyPath, { excludeRoot: true }) return ( <> {key()} : ) } interface ValueNodeProps { node: JsonNodeHastElement } function ValueNode(props: ValueNodeProps): JSX.Element { // Handle text nodes if (props.node.type === "text") { return <>{props.node.value} } // Handle element nodes return ( {(child) => } ) } interface JsonTreeNodeProps { node: JsonNode indexPath: number[] } function JsonTreeNode(props: JsonTreeNodeProps) { const line = () => props.indexPath.reduce((acc, curr) => acc + curr, 1) const lineLength = () => props.indexPath.length - 1 const key = () => (isRootKeyPath(props.node.keyPath) ? "" : keyPathToKey(props.node.keyPath)) return ( <> {props.node.children && props.node.children.length > 0 ? (
{key() && }
keyPathToId(child.keyPath)}> {(child, index) => }
) : (
{key() && }
)} ) } export default function JsonTree() { return (
) }