/** * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates * SPDX-License-Identifier: MIT */ import React from 'react'; import { type IJsonSchema, type JsonSchemaTypeManager, useTypeManager, } from '@flowgram.ai/json-schema'; import './styles.css'; interface PropsType { value?: IJsonSchema; parentKey?: string; depth?: number; drilldown?: boolean; showIcon?: boolean; typeManager?: JsonSchemaTypeManager; } export function DisplaySchemaTree(props: Omit) { return ; } function SchemaTree(props: PropsType) { const { value: schema = {}, drilldown = true, depth = 0, showIcon = true, parentKey = '', } = props || {}; const typeManager = useTypeManager() as JsonSchemaTypeManager; const config = typeManager.getTypeBySchema(schema); const title = typeManager.getComplexText(schema); const icon = typeManager?.getDisplayIcon(schema); let properties: IJsonSchema['properties'] = drilldown && config ? config.getTypeSchemaProperties(schema) : {}; const childEntries = Object.entries(properties || {}); return (
{depth !== 0 &&
} {showIcon && icon && React.cloneElement(icon, { className: 'tree-icon', })}
{parentKey ? ( <> {`${parentKey} (`} {title} {')'} ) : ( title )}
{childEntries?.length ? (
{childEntries.map(([key, value]) => ( ))}
) : null}
); }