import React, { useState } from "react"; import { Reference } from "@/utils/global"; import { copyToClipboard, formatReferenceForCopy, formatAllReferencesForCopy, delteIndexUpdateBracketNumbersInDeltaKeepSelection, } from "@/utils/others/quillutils"; type ReferenceListProps = { references: Reference[]; addReference: (reference: Reference) => void; removeReference: (index: number) => void; setReferences: any; editor: any; }; function ReferenceList({ references, addReference, removeReference, setReferences, editor, }: ReferenceListProps) { const [newTitle, setNewTitle] = useState(""); const [newAuthor, setNewAuthor] = useState(""); const [newYear, setNewYear] = useState(2020); const [newPublisher, setNewPublisher] = useState(""); const [newUrl, setNewUrl] = useState(""); function moveReferenceUp(index: number) { setReferences((prevReferences) => { if (index === 0) return prevReferences; // 如果是第一个元素,不进行操作 const newReferences = [...prevReferences]; const temp = newReferences[index]; newReferences[index] = newReferences[index - 1]; newReferences[index - 1] = temp; console.log("moveReferenceUp", newReferences); // 调试输出 return newReferences; }); } function moveReferenceDown(index: number) { setReferences((prevReferences) => { if (index === prevReferences.length - 1) return prevReferences; // 如果是最后一个元素,不进行操作 const newReferences = [...prevReferences]; const temp = newReferences[index]; newReferences[index] = newReferences[index + 1]; newReferences[index + 1] = temp; console.log("moveReferenceDown", newReferences); // 调试输出 return newReferences; }); } function removeReferenceUpdateIndex(index: number) { removeReference(index); delteIndexUpdateBracketNumbersInDeltaKeepSelection(editor, index); } return (