diff --git a/package-lock.json b/package-lock.json index 013e1ab..b9f344e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "react-dom": "^18.3.1", "react-i18next": "^13.5.0", "react-icons": "^4.12.0", + "react-intersection-observer": "^9.13.1", "react-katex": "^3.0.1", "react-latex": "^2.0.0", "react-latex-next": "^3.0.0", @@ -8928,6 +8929,20 @@ "react": "*" } }, + "node_modules/react-intersection-observer": { + "version": "9.13.1", + "resolved": "https://registry.npmjs.org/react-intersection-observer/-/react-intersection-observer-9.13.1.tgz", + "integrity": "sha512-tSzDaTy0qwNPLJHg8XZhlyHTgGW6drFKTtvjdL+p6um12rcnp8Z5XstE+QNBJ7c64n5o0Lj4ilUleA41bmDoMw==", + "peerDependencies": { + "react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + } + } + }, "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", @@ -17330,6 +17345,12 @@ "integrity": "sha512-IBaDuHiShdZqmfc/TwHu6+d6k2ltNCf3AszxNmjJc1KUfXdEeRJOKyNvLmAHaarhzGmTSVygNdyu8/opXv2gaw==", "requires": {} }, + "react-intersection-observer": { + "version": "9.13.1", + "resolved": "https://registry.npmjs.org/react-intersection-observer/-/react-intersection-observer-9.13.1.tgz", + "integrity": "sha512-tSzDaTy0qwNPLJHg8XZhlyHTgGW6drFKTtvjdL+p6um12rcnp8Z5XstE+QNBJ7c64n5o0Lj4ilUleA41bmDoMw==", + "requires": {} + }, "react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", diff --git a/package.json b/package.json index cf0a973..337da57 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "react-dom": "^18.3.1", "react-i18next": "^13.5.0", "react-icons": "^4.12.0", + "react-intersection-observer": "^9.13.1", "react-katex": "^3.0.1", "react-latex": "^2.0.0", "react-latex-next": "^3.0.0", diff --git a/src/Components/LatextInput/LaTeXInput.tsx b/src/Components/LatextInput/LaTeXInput.tsx index e87f079..a7be123 100644 --- a/src/Components/LatextInput/LaTeXInput.tsx +++ b/src/Components/LatextInput/LaTeXInput.tsx @@ -22,12 +22,6 @@ const LaTeXInput = ({name,label,...props}:ILaTeXInput) => { const { ShowLatexOption } = useObjectToEdit(); const [showPreview, setShowPreview] = useState(false) ; const value = getFieldProps(name)?.value - const handleChangeInput = - ( - e: React.ChangeEvent, - ) => { - setFieldValue(name,e.target.value); - }; const Preview = parseTextAndLatex(value ?? "") ; @@ -54,6 +48,12 @@ const LaTeXInput = ({name,label,...props}:ILaTeXInput) => { setLatex(item) setIsEditModalOpen(true) } + + const [curCentValue, setCurrentValue] = useState(value) + const handleChangeInput = (e: React.ChangeEvent) => { + setFieldValue(name, e.target.value); + setCurrentValue(e.target.value) + }; return (
@@ -69,7 +69,7 @@ const LaTeXInput = ({name,label,...props}:ILaTeXInput) => { autoSize={{ minRows: 6, maxRows: 10 }} style={{height:"400px"}} onChange={handleChangeInput} - value={value} + value={curCentValue} {...props} /> diff --git a/src/Components/LatextInput/LaTeXInputMemo.tsx b/src/Components/LatextInput/LaTeXInputMemo.tsx index a302601..22cae6a 100644 --- a/src/Components/LatextInput/LaTeXInputMemo.tsx +++ b/src/Components/LatextInput/LaTeXInputMemo.tsx @@ -21,13 +21,7 @@ const LaTeXInputMemo: React.FC = React.memo(({ field ,form, label, ...prop const { setFieldValue } = form; const { ShowLatexOption } = useObjectToEdit(); - const [showPreview, setShowPreview] = useState(false); - - const handleChangeInput = (e: React.ChangeEvent) => { - setFieldValue(name, e.target.value); - }; - console.log(name,"name"); - + const [showPreview, setShowPreview] = useState(false); const Preview = parseTextAndLatex(value ?? ""); const onPreviewChange: CheckboxProps['onChange'] = (e) => { @@ -50,6 +44,15 @@ const LaTeXInputMemo: React.FC = React.memo(({ field ,form, label, ...prop setIsEditModalOpen(true); }; + const [curCentValue, setCurrentValue] = useState(value) + const handleChangeInput = (e: React.ChangeEvent) => { + setCurrentValue(e.target.value) + }; + const onBlur = ()=>{ + + setFieldValue(name, curCentValue); + } + return (