feat(exercises): implement inline media support in exercise content
Deploy Development / deploy (push) Successful in 37s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
Deploy Development / deploy (push) Successful in 37s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
- Added functionality for inline media references in exercise text using `{{exerciseMedia:id}}` syntax, which normalizes to a canonical `<span>` element.
- Updated the frontend to utilize `ExerciseRichTextBlock` for rendering exercise content, allowing for embedded media display.
- Enhanced the Rich Text Editor to support inserting inline media placeholders.
- Version bump to 0.8.60 to reflect these changes in media handling and exercise content management.
This commit is contained in:
1 parent
f745e5d082
commit
cc51b0f08f
17 files changed
+655
-149
No files matched your search
@@ -45,10 +45,50 @@ function normalText() {
|
||||
formatBlock('p')
|
||||
}
|
||||
|
||||
function insertExerciseMediaPlaceholder(editorEl, mediaId) {
|
||||
if (!editorEl || mediaId == null) return
|
||||
const sid = parseInt(String(mediaId), 10)
|
||||
if (!Number.isFinite(sid) || sid < 1) return
|
||||
editorEl.focus()
|
||||
const sel = window.getSelection()
|
||||
if (!sel) return
|
||||
let range = null
|
||||
if (sel?.rangeCount) {
|
||||
try {
|
||||
const r0 = sel.getRangeAt(0)
|
||||
if (editorEl.contains(r0.commonAncestorContainer)) range = r0
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
if (!range) {
|
||||
range = document.createRange()
|
||||
range.selectNodeContents(editorEl)
|
||||
range.collapse(false)
|
||||
}
|
||||
const span = document.createElement('span')
|
||||
span.setAttribute('data-shinkan-exercise-media', String(sid))
|
||||
span.className = 'shinkan-inline-media'
|
||||
span.appendChild(document.createTextNode('\u2060'))
|
||||
range.deleteContents()
|
||||
range.insertNode(span)
|
||||
range.setStartAfter(span)
|
||||
range.collapse(true)
|
||||
sel.removeAllRanges()
|
||||
sel.addRange(range)
|
||||
}
|
||||
|
||||
/**
|
||||
* Leichter WYSIWYG (contenteditable). Wert kommt von außen zuverlässig ins DOM (Edit-Modus).
|
||||
* @param {{ id: number, label: string }[]} [insertExerciseMediaSlots] — §11 Verweise auf exercise_media.id
|
||||
*/
|
||||
export default function RichTextEditor({ value, onChange, placeholder, minHeight = '140px' }) {
|
||||
export default function RichTextEditor({
|
||||
value,
|
||||
onChange,
|
||||
placeholder,
|
||||
minHeight = '140px',
|
||||
insertExerciseMediaSlots,
|
||||
}) {
|
||||
const ref = useRef(null)
|
||||
const [focused, setFocused] = useState(false)
|
||||
|
||||
@@ -98,6 +138,38 @@ export default function RichTextEditor({ value, onChange, placeholder, minHeight
|
||||
}
|
||||
}
|
||||
|
||||
const showMediaPick = Array.isArray(insertExerciseMediaSlots) && insertExerciseMediaSlots.length > 0
|
||||
|
||||
const onInsertExerciseMediaClick = (e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
const el = ref.current
|
||||
if (!el || !insertExerciseMediaSlots?.length) return
|
||||
let choice = ''
|
||||
if (insertExerciseMediaSlots.length === 1) {
|
||||
choice = String(insertExerciseMediaSlots[0].id)
|
||||
} else {
|
||||
choice = window.prompt(
|
||||
`Medium-ID eingeben oder aus Liste:\n${insertExerciseMediaSlots
|
||||
.slice(0, 30)
|
||||
.map((s) => `${s.id}: ${s.label}`)
|
||||
.join('\n')}`,
|
||||
'',
|
||||
)
|
||||
}
|
||||
const idParsed = parseInt(String(choice).trim(), 10)
|
||||
if (!Number.isFinite(idParsed)) return
|
||||
if (!insertExerciseMediaSlots.some((s) => Number(s.id) === idParsed)) {
|
||||
alert('Diese Übungs-ID ist nicht in der Medienliste.')
|
||||
return
|
||||
}
|
||||
const saved = saveSelectionInside(el)
|
||||
el.focus()
|
||||
restoreSelection(saved)
|
||||
insertExerciseMediaPlaceholder(el, idParsed)
|
||||
sync()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rich-text-editor-wrap">
|
||||
<div className="rich-text-toolbar" role="toolbar" aria-label="Formatierung">
|
||||
@@ -133,6 +205,16 @@ export default function RichTextEditor({ value, onChange, placeholder, minHeight
|
||||
<button type="button" className="rte-btn" title="Link einfügen" onMouseDown={onLink}>
|
||||
Link
|
||||
</button>
|
||||
{showMediaPick ? (
|
||||
<button
|
||||
type="button"
|
||||
className="rte-btn"
|
||||
title="Übungs-Medium inline einfügen (§11)"
|
||||
onMouseDown={onInsertExerciseMediaClick}
|
||||
>
|
||||
Bild/Video im Text
|
||||
</button>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
className="rte-btn"
|
||||
|
||||
Reference in new issue
Block a user