mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-05 10:05:05 +08:00
### What problem does this PR solve? Fix: Interoperate with the pipeline rerun and unbindTask interfaces. #9869 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import { CheckedState } from '@radix-ui/react-checkbox';
|
|
import { ChunkTextMode } from '../../constant';
|
|
import { ArrayContainer, parserKeyMap } from './json-parser';
|
|
import { ObjectContainer } from './object-parser';
|
|
interface FormatPreserveEditorProps {
|
|
initialValue: {
|
|
key: keyof typeof parserKeyMap | 'text' | 'html';
|
|
type: string;
|
|
value: Array<{ [key: string]: string }>;
|
|
};
|
|
onSave: (value: any) => void;
|
|
className?: string;
|
|
isSelect?: boolean;
|
|
isDelete?: boolean;
|
|
isChunck?: boolean;
|
|
handleCheckboxClick?: (id: string | number, checked: boolean) => void;
|
|
selectedChunkIds?: string[];
|
|
textMode?: ChunkTextMode;
|
|
}
|
|
const FormatPreserveEditor = ({
|
|
initialValue,
|
|
onSave,
|
|
className,
|
|
isChunck,
|
|
handleCheckboxClick,
|
|
selectedChunkIds,
|
|
textMode,
|
|
}: FormatPreserveEditorProps) => {
|
|
console.log('initialValue', initialValue);
|
|
|
|
const escapeNewlines = (text: string) => {
|
|
return text.replace(/\n/g, '\\n');
|
|
};
|
|
const unescapeNewlines = (text: string) => {
|
|
return text.replace(/\\n/g, '\n');
|
|
};
|
|
const handleCheck = (e: CheckedState, id: string | number) => {
|
|
handleCheckboxClick?.(id, e === 'indeterminate' ? false : e);
|
|
};
|
|
|
|
return (
|
|
<div className="editor-container">
|
|
{['json', 'chunks'].includes(initialValue.key) && (
|
|
<ArrayContainer
|
|
className={className}
|
|
initialValue={initialValue}
|
|
handleCheck={handleCheck}
|
|
selectedChunkIds={selectedChunkIds}
|
|
onSave={onSave}
|
|
escapeNewlines={escapeNewlines}
|
|
unescapeNewlines={unescapeNewlines}
|
|
textMode={textMode}
|
|
isChunck={isChunck}
|
|
/>
|
|
)}
|
|
|
|
{['text', 'html'].includes(initialValue.key) && (
|
|
<ObjectContainer
|
|
className={className}
|
|
initialValue={initialValue}
|
|
handleCheck={handleCheck}
|
|
selectedChunkIds={selectedChunkIds}
|
|
onSave={onSave}
|
|
escapeNewlines={escapeNewlines}
|
|
unescapeNewlines={unescapeNewlines}
|
|
textMode={textMode}
|
|
isChunck={isChunck}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default FormatPreserveEditor;
|