import type { VarType } from '../types' import type { ChunkInfo } from '@/app/components/rag-pipeline/components/chunk-card-list/types' import type { ParentMode } from '@/models/datasets' import { cn } from '@langgenius/dify-ui/cn' import { ToggleGroup, ToggleGroupItem } from '@langgenius/dify-ui/toggle-group' import { useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { Markdown } from '@/app/components/base/markdown' import Textarea from '@/app/components/base/textarea' import { ChunkCardList } from '@/app/components/rag-pipeline/components/chunk-card-list' import SchemaEditor from '@/app/components/workflow/nodes/llm/components/json-schema-config-modal/schema-editor' import { ChunkingMode } from '@/models/datasets' import { PreviewType, ViewMode } 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 } export function 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 viewOptions = [ { value: ViewMode.Code, label: t('nodes.templateTransform.code', { ns: 'workflow' }), iconClassName: 'i-ri-braces-line' }, { value: ViewMode.Preview, label: t('common.preview', { ns: 'workflow' }), iconClassName: 'i-ri-eye-line' }, ] const selectedViewMode = viewMode[0] ?? ViewMode.Code 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})` : ''}
)} aria-label={t('common.preview', { ns: 'workflow' })} value={viewMode} onValueChange={setViewMode} className="shrink-0 rounded-md p-px" > {viewOptions.map(({ value, label, iconClassName }) => (