Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | 208x 8x 8x 8x 8x 18x 18x 18x 18x 19x 16x 16x | import { Box, Chip, Paper, Stack, Typography } from "@mui/material";
import { alpha, useTheme } from "@mui/material/styles";
import React, { memo } from "react";
import DragIndicatorIcon from "@mui/icons-material/DragIndicator";
import RichTextContent from "@/utils/components/question-bank/question-display/utils/RichTextContent";
import ReadOnlyMathEditor from "@/utils/components/TinyMCETextEditorReadOnly";
import SubmissionGraphAnswer from "@/utils/components/submission-review/SubmissionGraphAnswer";
import { sanitizeRichText } from "@/utils/helpers/sanitizeHtml";
import {
answerHiddenSurfaceSx,
answerRevealedSurfaceSx,
correctAnswerSurfaceBg,
inlineBlankZoneColors,
inlineSelectBlankColors,
questionItemNumberSx,
questionStemTypographySx,
readOnlyMathSurfaceSx,
} from "@/utils/components/question-bank/question-display/utils/questionCardStyles";
import ChoiceOptionRow from "@/utils/components/question-bank/question-display/utils/ChoiceOptionRow";
import {
extractAnswerContent,
getPrimaryAnswerContent,
htmlContentEquals,
isChoiceCorrect,
} from "@/utils/components/question-bank/question-display/utils/questionAnswerUtils";
const letters = Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i));
// Same "unwrap the single <p> wrapper" step DropDownMenuViewOnly uses — a
// choice's HTML is TinyMCE-wrapped in one <p>, which would otherwise force a
// line break inside this inline blank span.
const unwrapBlock = (html) => {
if (typeof document === "undefined" || !html) return html || "";
const el = document.createElement("div");
el.innerHTML = html;
if (el.children.length === 1 && el.children[0].tagName === "P") {
return el.children[0].innerHTML;
}
return html;
};
/** A "drop-down" group's own content with its `__blank__` markers replaced by
* the selected/correct answer at each blank — mirrors DropDownMenuViewOnly's
* buildSelectHTML, scoped to one group's own choices/correctAnswer instead of
* the top-level question's. */
const buildDropdownGroupHtml = (group, showAnswers, theme) => {
let blankIndex = 0;
return (group.content || "").replace(/__blank__/g, () => {
const idx = blankIndex++;
const answerContent = extractAnswerContent(group.correctAnswer?.answers?.[idx]);
const isAnswer = showAnswers && answerContent;
const colors = inlineSelectBlankColors(theme, isAnswer);
let displayContent = "Select...";
if (isAnswer) {
const items = group.choices?.[idx]?.items || [];
const matched = items.find((item) => htmlContentEquals(item, answerContent));
displayContent = unwrapBlock(matched || answerContent);
}
return (
`<span style="display:inline-block;padding:2px 8px;` +
`border:1px solid ${colors.borderColor};border-radius:4px;background-color:${colors.backgroundColor};` +
`vertical-align:middle;margin:0 4px;color:${colors.color};` +
`white-space:nowrap;line-height:normal;">` +
`${displayContent}</span>`
);
});
};
/** A "drag-and-drop" group's own content with its `__blank__` markers
* replaced by the correct answer at each blank — mirrors DragDropViewOnly's
* buildDropZoneSpan, scoped to one group's own content/correctAnswer instead
* of the top-level question's. */
const buildDragDropGroupHtml = (group, showAnswers, theme) => {
let blankIndex = 0;
return (group.content || "").replace(/__blank__/g, () => {
const idx = blankIndex++;
const answerContent = extractAnswerContent(group.correctAnswer?.answers?.[idx]);
const isAnswer = showAnswers && answerContent;
const colors = inlineBlankZoneColors(theme, isAnswer);
const answerHtml = isAnswer ? unwrapBlock(answerContent) : "Drop here";
return (
`<span style="display:inline-block;padding:2px 16px;margin:0 10px;border-radius:8px;` +
`border:2px ${colors.borderStyle} ${colors.borderColor};background-color:${colors.backgroundColor};` +
`vertical-align:middle;white-space:nowrap;line-height:normal;font-size:inherit;` +
`font-weight:${isAnswer ? 500 : 400};color:${colors.color};">${answerHtml}</span>`
);
});
};
/**
* Read-only display for a Single-Stimulus question — the main question
* once, then every group's own choices stacked below it (not paginated, so a
* reviewer sees the whole question at a glance). Each group delegates to the
* same ChoiceOptionRow every Multiple-choice/Checkbox display already uses.
*/
const SingleStimulusViewOnly = ({ question, showAnswers, itemNumber }) => {
const theme = useTheme();
const answerBg = correctAnswerSurfaceBg(theme);
const groups = Array.isArray(question.groups) ? question.groups : [];
return (
<Box sx={{ width: "100%" }}>
<Box sx={{ display: "flex", alignItems: "flex-start", gap: 1, mb: 1.5 }}>
{itemNumber != null && itemNumber !== false && (
<Typography component="span" sx={questionItemNumberSx}>
{itemNumber}.
</Typography>
)}
<Typography component="div" sx={{ ...questionStemTypographySx, flex: 1, ...readOnlyMathSurfaceSx }}>
<RichTextContent content={question.question} sx={{ padding: "6px 10px" }} />
</Typography>
</Box>
<Stack spacing={2} sx={{ ml: itemNumber ? 3.5 : 0 }}>
{groups.map((group, groupIndex) => (
<Box key={group.group_id ?? groupIndex}>
<Stack direction="row" spacing={1} alignItems="center" sx={{ mb: 0.75 }}>
<Typography variant="subtitle2" fontWeight={600}>
Group {groupIndex + 1}
</Typography>
<Chip
size="small"
label={`${group.points ?? 1} pt${(group.points ?? 1) === 1 ? "" : "s"}`}
variant="outlined"
/>
</Stack>
{(group.type === "multiple-choice" || group.type === "checkbox") && (
<Box sx={{ display: "flex", flexDirection: "column", gap: 0.625 }}>
{(group.choices || []).map((choice, choiceIndex) => {
const isAnswer =
showAnswers && isChoiceCorrect(group.correctAnswer?.answers, choice.text);
return (
<ChoiceOptionRow
key={choice.id ?? choiceIndex}
theme={theme}
isAnswer={isAnswer}
letter={letters[choiceIndex]}
content={choice.text}
/>
);
})}
</Box>
)}
{group.type === "free-response" &&
(showAnswers ? (
<Paper elevation={0} sx={answerRevealedSurfaceSx(theme)}>
<ReadOnlyMathEditor
content={getPrimaryAnswerContent(group.correctAnswer?.answers)}
backgroundColor={answerBg}
/>
</Paper>
) : (
<Paper elevation={0} sx={answerHiddenSurfaceSx(theme)}>
<Typography variant="body2" sx={{ color: "text.secondary", fontStyle: "italic" }}>
Answer hidden
</Typography>
</Paper>
))}
{group.type === "graph" &&
(showAnswers ? (
<Box sx={{ display: "flex", justifyContent: "center" }}>
<SubmissionGraphAnswer content={group.correctAnswer?.answers} />
</Box>
) : (
<Paper elevation={0} sx={answerHiddenSurfaceSx(theme)}>
<Typography variant="body2" sx={{ color: "text.secondary", fontStyle: "italic" }}>
Answer hidden
</Typography>
</Paper>
))}
{group.type === "drop-down" && (
<Paper elevation={0} sx={readOnlyMathSurfaceSx}>
<ReadOnlyMathEditor content={buildDropdownGroupHtml(group, showAnswers, theme)} />
</Paper>
)}
{group.type === "drag-and-drop" && (
<Box>
<Paper elevation={0} sx={readOnlyMathSurfaceSx}>
<ReadOnlyMathEditor content={buildDragDropGroupHtml(group, showAnswers, theme)} />
</Paper>
<Box
sx={{
display: "flex",
flexWrap: "wrap",
alignItems: "center",
gap: 1,
mt: 1,
p: 1.5,
bgcolor: alpha(theme.palette.grey[500], 0.06),
borderRadius: 1.5,
border: `1px solid ${alpha(theme.palette.grey[500], 0.12)}`,
}}
>
{(group.choices ?? []).map((choiceObj, index) => (
<Box
key={choiceObj.id ?? index}
sx={{
display: "flex",
alignItems: "center",
gap: 0.5,
px: 1.25,
py: 0.65,
bgcolor: alpha(theme.palette.primary.main, 0.12),
color: "primary.dark",
borderRadius: 1.5,
border: `1px solid ${alpha(theme.palette.primary.main, 0.2)}`,
}}
>
<DragIndicatorIcon sx={{ fontSize: 18, opacity: 0.8, flexShrink: 0 }} />
<Box
dangerouslySetInnerHTML={{
__html: sanitizeRichText(unwrapBlock(choiceObj.text)),
}}
sx={{
fontWeight: 500,
fontSize: "0.9375rem",
lineHeight: "normal",
"& p": { margin: 0, padding: 0 },
"& .mfe-formula": { color: "inherit", bgcolor: "transparent" },
}}
/>
</Box>
))}
</Box>
</Box>
)}
</Box>
))}
</Stack>
</Box>
);
};
export default memo(SingleStimulusViewOnly);
|