fix(exams): fix rich editor crashes and redesign form layout

- Fix groupBlock/questionBlock insertContent error: empty content violates
  schema "block+", now provide default empty paragraph
- Fix buildTiptapDocFromAiResponse: ensure groupBlock/questionBlock always
  have content (fallback to empty paragraph)
- Add wrapInGroup/wrapInQuestion commands to wrap selected text into
  question/group blocks (vs insert which creates empty blocks)
- Update SelectionToolbar: use wrap when text selected, insert when not
- Redesign exam-rich-form layout:
  - Merge basic info into single-row toolbar (title/subject/grade/difficulty/score/duration)
  - Remove separate "source text" textarea (user pastes directly in editor)
  - AI auto-mark now reads from editor content via getText()
  - Editor + preview takes full height (calc(100vh-180px))
- Enhance AI prompt for Chinese exam papers:
  - Support reading material (阅读理解选段)
  - Support dotted chars (加点字注音)
  - Support sub-questions (阅读理解小题)
  - Better type detection (single/multiple choice, judgment, fill, essay, composite)
- Add splitByDottedTexts helper to mark dotted chars in Tiptap doc
- Add i18n keys for titlePlaceholder, editorArea description
This commit is contained in:
SpecialX
2026-06-24 13:41:39 +08:00
parent d1e4ccbf98
commit 7380f1e6c8
8 changed files with 368 additions and 219 deletions

View File

@@ -120,12 +120,27 @@ export function SelectionToolbar({
if (!editor || !hasSelection || !coords) return null
const { from, to, empty } = editor.state.selection
const hasTextSelection = !empty && from !== to
const insertQuestion = (type: QuestionBlockType) => {
editor.chain().focus().insertQuestion({ type, score: type === "composite" ? 5 : 2 }).run()
const chain = editor.chain().focus()
if (hasTextSelection) {
// 选中文本时:包裹为题目块
chain.wrapInQuestion({ type, score: type === "composite" ? 5 : 2 }).run()
} else {
// 未选中文本时:插入空题目块
chain.insertQuestion({ type, score: type === "composite" ? 5 : 2 }).run()
}
}
const insertGroup = () => {
editor.chain().focus().insertGroup("一、选择题").run()
const chain = editor.chain().focus()
if (hasTextSelection) {
chain.wrapInGroup("一、选择题").run()
} else {
chain.insertGroup("一、选择题").run()
}
}
const toggleDotted = () => {