import React, { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiBracesLine, RiEyeLine } from '@remixicon/react' import Textarea from '@/app/components/base/textarea' import { Markdown } from '@/app/components/base/markdown' import SchemaEditor from '@/app/components/workflow/nodes/llm/components/json-schema-config-modal/schema-editor' import { SegmentedControl } from '@/app/components/base/segmented-control' import cn from '@/utils/classnames' import { ChunkCardList } from '@/app/components/rag-pipeline/components/chunk-card-list' import type { ChunkInfo } from '@/app/components/rag-pipeline/components/chunk-card-list/types' import type { ParentMode } from '@/models/datasets' import { ChunkingMode } from '@/models/datasets' import { PreviewType, ViewMode } from './types' import type { VarType } from '../types' type DisplayContentProps = { previewType: PreviewType varType: VarType schemaType?: string mdString?: string jsonString?: string readonly: boolean handleTextChange?: (value: string) => void handleEditorChange?: (value: string) => void className?: string } const DisplayContent = (props: DisplayContentProps) => { const { previewType, varType, schemaType, mdString, jsonString, readonly, handleTextChange, handleEditorChange, className } = props const [viewMode, setViewMode] = useState(ViewMode.Code) const [isFocused, setIsFocused] = useState(false) const { t } = useTranslation() const chunkType = useMemo(() => { if (previewType !== PreviewType.Chunks || !schemaType) return undefined if (schemaType === 'general_structure') return ChunkingMode.text if (schemaType === 'parent_child_structure') return ChunkingMode.parentChild if (schemaType === 'qa_structure') return ChunkingMode.qa }, [previewType, schemaType]) const parentMode = useMemo(() => { if (previewType !== PreviewType.Chunks || !schemaType || !jsonString) return undefined if (schemaType === 'parent_child_structure') return JSON.parse(jsonString!)?.parent_mode as ParentMode return undefined }, [previewType, schemaType, jsonString]) return (
{previewType === PreviewType.Markdown && (
{previewType.toUpperCase()}
)} {previewType === PreviewType.Chunks && (
{varType.toUpperCase()}{schemaType ? `(${schemaType})` : ''}
)}
{viewMode === ViewMode.Code && ( previewType === PreviewType.Markdown ?