@eliceio/cdk-cli 1.2.0 → 1.3.0-contenttypes.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -60
- package/es/cli.js +11 -2
- package/es/commands/build/index.js +12 -0
- package/es/commands/create/index.js +2 -1
- package/es/commands/create/scaffold.d.ts +2 -2
- package/es/commands/create/scaffold.js +3 -3
- package/es/commands/dev/index.d.ts +10 -1
- package/es/commands/dev/index.js +47 -7
- package/es/core/config.d.ts +20 -9
- package/es/core/config.js +53 -12
- package/es/core/project-check.d.ts +3 -2
- package/es/core/project-check.js +14 -3
- package/es/core/regex.d.ts +11 -0
- package/es/core/regex.js +41 -0
- package/es/core/sandbox.d.ts +26 -0
- package/es/core/sandbox.js +240 -30
- package/es/dev/check.d.ts +30 -0
- package/es/dev/check.js +224 -34
- package/es/dev/grading.d.ts +20 -1
- package/es/dev/grading.js +38 -7
- package/es/dev/host-page.js +1 -1
- package/es/dev/mock-api.d.ts +3 -1
- package/es/dev/mock-api.js +20 -11
- package/es/engines/vite/index.js +1 -1
- package/es/engines/vite/plugin.d.ts +2 -0
- package/es/engines/vite/plugin.js +33 -5
- package/es/rules/answers.d.ts +13 -0
- package/es/rules/answers.js +94 -0
- package/es/rules/check.js +70 -1
- package/es/rules/index.d.ts +1 -0
- package/es/rules/index.js +1 -0
- package/es/rules/size.d.ts +31 -0
- package/es/rules/size.js +58 -0
- package/es/rules/types.d.ts +12 -0
- package/es/rules.json.js +2 -2
- package/package.json +2 -2
- package/rules.json +32 -3
- package/skills/_shared/always.md +3 -3
- package/skills/_shared/references/00-what-the-person-decides.md +1 -1
- package/skills/_shared/references/02-design-the-material.md +10 -7
- package/skills/_shared/references/03-create-the-project.md +2 -1
- package/skills/_shared/references/05-screen-code.md +49 -22
- package/skills/_shared/references/06-using-the-quiz-template.md +7 -6
- package/skills/_shared/references/08-fix-check-errors.md +23 -22
- package/skills/_shared/references/09-check.md +7 -6
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +13 -13
- package/skills/_shared/references/13-edit-screen-design.md +122 -0
- package/skills/_shared/references/14-layouts.md +96 -0
- package/skills/elice-content-check/SKILL.md +2 -2
- package/skills/elice-content-create/SKILL.md +1 -1
- package/skills/elice-content-migrate/SKILL.md +1 -1
- package/templates/_shared/lib/cdk-mock.d.ts +30 -3
- package/templates/_shared/lib/cdk-mock.js +88 -15
- package/templates/_shared/lib/elice-content-editor.js +89 -58
- package/templates/_shared/lib/elice-content.css +1313 -126
- package/templates/_shared/lib/elice-content.d.ts +162 -23
- package/templates/_shared/lib/elice-content.js +865 -84
- package/templates/_shared/lib/icons/empty-content.d.ts +2 -0
- package/templates/_shared/lib/icons/empty-content.js +11 -0
- package/templates/_shared/lib/icons/file-video.d.ts +2 -0
- package/templates/_shared/lib/icons/file-video.js +11 -0
- package/templates/_shared/lib/icons/file.d.ts +2 -0
- package/templates/_shared/lib/icons/file.js +11 -0
- package/templates/blank/README.md +5 -3
- package/templates/blank/edit.html +8 -2
- package/templates/blank/index.html +6 -1
- package/templates/blank/instructor.html +6 -1
- package/templates/blank/template.json +1 -1
- package/templates/quiz/README.md +28 -12
- package/templates/quiz/core/behaviors.d.ts +13 -7
- package/templates/quiz/core/behaviors.js +36 -51
- package/templates/quiz/core/editor.d.ts +10 -0
- package/templates/quiz/core/editor.js +471 -8
- package/templates/quiz/core/markdown.d.ts +4 -0
- package/templates/quiz/core/markdown.js +65 -11
- package/templates/quiz/core/model.d.ts +34 -1
- package/templates/quiz/core/model.js +89 -7
- package/templates/quiz/core/rich-text.d.ts +19 -0
- package/templates/quiz/core/rich-text.js +521 -0
- package/templates/quiz/edit.html +12 -3
- package/templates/quiz/index.html +12 -3
- package/templates/quiz/screens/edit.js +848 -168
- package/templates/quiz/screens/learn.js +90 -14
- package/templates/quiz/styles.css +889 -213
- package/templates/quiz/template.json +9 -2
- package/templates/quiz/ui/templates/edit.d.ts +19 -6
- package/templates/quiz/ui/templates/edit.js +666 -87
- package/templates/quiz/ui/templates/group.js +19 -8
- package/templates/quiz/ui/templates/order.js +25 -24
- package/templates/quiz/ui/templates/page.js +19 -8
- package/templates/quiz/ui/templates/question.js +2 -2
- package/templates/quiz/ui/texts.js +104 -35
- package/templates/quiz/ui/theme.css +8 -9
- package/templates/steps/README.md +77 -0
- package/templates/steps/commentary.txt +7 -0
- package/templates/steps/edit.html +21 -0
- package/templates/steps/gitignore +4 -0
- package/templates/steps/index.html +69 -0
- package/templates/steps/metadata.json +9 -0
- package/templates/steps/package.json +13 -0
- package/templates/steps/screens/edit.js +32 -0
- package/templates/steps/screens/learn.js +108 -0
- package/templates/steps/styles.css +54 -0
- package/templates/steps/template.json +6 -0
|
@@ -1,47 +1,151 @@
|
|
|
1
1
|
// 내용 편집 화면(CMS). 기존 퀴즈 편집 폼을 옮김 (docs/quiz-spec.md §3). 저장 버튼 · 변경 표시는 키트(useSave)가 합니다.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// 완료 정책은 LXP 자료 편집 화면의 '설정'에서 교육자가 고릅니다 (ADR 0012). 문항 카드마다 정답을 고르고 (단일 · 복수 · 그룹은 보기 줄에서
|
|
3
|
+
// 바로, 순서 · 주관식은 아래 "정답"에서), 저장할 때 고른 답으로 정답 정규식을 만들어 검증한 뒤 settings.grading에 함께 저장합니다.
|
|
4
|
+
// 채점 방식은 저장된 것을 그대로 씁니다 (작성자가 정함, 새 퀴즈는 pattern):
|
|
5
|
+
// - pattern: 정답 정규식 하나 (모두 맞혀야 100점)
|
|
6
|
+
// - partial_pattern: 문항마다 정규식 + 점수 (맞은 문항 점수의 합). 점수는 이 화면에서 고치지 않는다: 문항 수가 같으면 저장된 점수,
|
|
7
|
+
// 바뀌었으면 똑같이 나눈 점수로 저장하고 짧게 알린다. 학생 화면이 답을 배열로 내도록 settings에 gradingType도 같이 저장
|
|
4
8
|
// 문제 내용(content)은 학생에게도 내려가므로 정답을 넣지 않습니다 (정답은 grading에만, 서버가 학생에게 내려주지 않음).
|
|
5
9
|
// 여기서는 어떤 칸을 어떤 순서로 놓을지만 정합니다. 모양은 ui/(templates/edit.js · texts · theme.css), 동작은 core/.
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
import {
|
|
11
|
+
ANSWER_KEY_MAX,
|
|
12
|
+
showSnackbar as showNotice,
|
|
13
|
+
splitScores,
|
|
14
|
+
start,
|
|
15
|
+
validateAnswerRegex,
|
|
16
|
+
validatePartialGrading,
|
|
17
|
+
} from "../lib/elice-content.js";
|
|
18
|
+
import { renderAnswerBody } from "../core/behaviors.js";
|
|
19
|
+
import { createEditor } from "../core/editor.js";
|
|
20
|
+
import { setImages } from "../core/markdown.js";
|
|
21
|
+
import { compressImage } from "../core/rich-text.js";
|
|
9
22
|
import {
|
|
10
23
|
buildAnswerKey,
|
|
24
|
+
buildAnswerKeys,
|
|
11
25
|
canAddQuestion,
|
|
12
26
|
checkAnswerKey,
|
|
13
|
-
|
|
27
|
+
checkAnswerKeys,
|
|
28
|
+
gradingTypeOf,
|
|
14
29
|
INLINE_ANSWER_TYPES,
|
|
15
30
|
isAnswered,
|
|
31
|
+
joinAnswerList,
|
|
16
32
|
joinAnswers,
|
|
17
33
|
LIMITS,
|
|
18
34
|
newQuestion,
|
|
35
|
+
nextId,
|
|
19
36
|
optionAnswer,
|
|
37
|
+
PARTIAL,
|
|
20
38
|
parseAnswerKey,
|
|
39
|
+
parseAnswerKeys,
|
|
21
40
|
pruneAnswer,
|
|
41
|
+
scoresFor,
|
|
22
42
|
validateAnswerKey,
|
|
23
43
|
validateQuiz,
|
|
24
44
|
withOptionAnswer,
|
|
25
|
-
} from
|
|
26
|
-
import * as templates from
|
|
27
|
-
import { templates as quizTemplates } from
|
|
28
|
-
import { loading } from
|
|
29
|
-
import { texts } from
|
|
45
|
+
} from "../core/model.js";
|
|
46
|
+
import * as templates from "../ui/templates/edit.js";
|
|
47
|
+
import { templates as quizTemplates } from "../ui/templates/index.js";
|
|
48
|
+
import { loading } from "../ui/templates/page.js";
|
|
49
|
+
import { texts } from "../ui/texts.js";
|
|
30
50
|
|
|
31
51
|
const t = texts.edit;
|
|
32
52
|
const a = texts.answers;
|
|
33
|
-
const root = document.getElementById(
|
|
53
|
+
const root = document.getElementById("app");
|
|
34
54
|
document.title = texts.page.edit;
|
|
35
55
|
root.replaceChildren(loading());
|
|
36
|
-
const app = await start({ screen:
|
|
56
|
+
const app = await start({ screen: "edit" });
|
|
37
57
|
const draft = structuredClone(app.content);
|
|
38
58
|
draft.questions ??= [];
|
|
59
|
+
// 지문 · 해설에 올린 그림 (아이디 → data: 주소). 글에는 만 두고 그림은 내용 images에 (학생 화면도 같이 받음)
|
|
60
|
+
setImages(draft.images);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 지문 · 해설에 그림 올리기 (서식 도구의 그림 버튼, 연주님 최종 수정본). 그림은 줄여서 settings 내용(images)에 data: 주소로
|
|
64
|
+
* 저장한다 (한 장 40만 자 · 모두 합쳐 270만 자, 약 2MB). 끄면(false) 버튼이 숨고, 이미 저장된 그림은 그대로 보이고 지울 수 있다
|
|
65
|
+
* 지금은 끔: 서버 settings 한도가 약 64KB라 사진 한 장도 저장되지 않는다(2026-11-17 실측). 서버 /storage/upload-url이
|
|
66
|
+
* 이미지를 받고 SDK assets가 이미지를 올릴 수 있게 되면 파일 업로드 방식으로 바꿔 다시 켠다
|
|
67
|
+
*/
|
|
68
|
+
const IMAGE_UPLOAD = false;
|
|
69
|
+
const imageErrors = {
|
|
70
|
+
"not-image": t.md.imageNotImage,
|
|
71
|
+
unreadable: t.md.imageUnreadable,
|
|
72
|
+
"too-big": t.md.imageTooBig,
|
|
73
|
+
total: t.md.imageTotal,
|
|
74
|
+
};
|
|
75
|
+
/** 그림 올리기: 파일을 줄여 images에 넣고 아이디를 돌려준다. 실패는 알림으로 */
|
|
76
|
+
const imageUpload = IMAGE_UPLOAD
|
|
77
|
+
? {
|
|
78
|
+
async add(file) {
|
|
79
|
+
const url = await compressImage(file, LIMITS.imageChars);
|
|
80
|
+
const images = (draft.images ??= {});
|
|
81
|
+
const total = Object.values(images).reduce((sum, v) => sum + v.length, 0);
|
|
82
|
+
if (total + url.length > LIMITS.imagesTotalChars)
|
|
83
|
+
throw Object.assign(new Error("total"), { code: "total" });
|
|
84
|
+
const id = nextId(Object.keys(images), "i");
|
|
85
|
+
images[id] = url;
|
|
86
|
+
setImages(images);
|
|
87
|
+
return id;
|
|
88
|
+
},
|
|
89
|
+
fail: (error) => showSnackbar(imageErrors[error.code] ?? t.md.imageUnreadable),
|
|
90
|
+
}
|
|
91
|
+
: undefined;
|
|
92
|
+
/** 글 칸 사이 그림 칸: 지우면 되돌리기 알림 */
|
|
93
|
+
const imageBlocks = {
|
|
94
|
+
removeLabel: t.md.imageRemove,
|
|
95
|
+
onRemoved: (undo) => showSnackbar(t.md.imageDeleted, undo),
|
|
96
|
+
};
|
|
97
|
+
/** 글에서 쓰는 그림만 (지운 그림은 저장하지 않음) */
|
|
98
|
+
function usedImages() {
|
|
99
|
+
const text = draft.questions
|
|
100
|
+
.flatMap((q) => [q.description, q.explanation?.text])
|
|
101
|
+
.filter(Boolean)
|
|
102
|
+
.join("\n");
|
|
103
|
+
const used = new Set([...text.matchAll(/\(image:([\w-]+)\)/g)].map((m) => m[1]));
|
|
104
|
+
const kept = Object.fromEntries(Object.entries(draft.images ?? {}).filter(([id]) => used.has(id)));
|
|
105
|
+
return Object.keys(kept).length ? kept : undefined;
|
|
106
|
+
}
|
|
107
|
+
// 처음 열면 문항 1이 이미 있는 상태로 시작한다
|
|
108
|
+
const startedEmpty = draft.questions.length === 0;
|
|
109
|
+
if (startedEmpty)
|
|
110
|
+
draft.questions.push(newQuestion("select_one", [], texts.defaults));
|
|
39
111
|
|
|
40
|
-
//
|
|
41
|
-
const
|
|
42
|
-
|
|
112
|
+
// 채점 방식: 저장된 settings.grading.type (없으면 settings.gradingType, 그것도 없으면 pattern). 이 화면은 바꾸지 않는다
|
|
113
|
+
const gradingType = gradingTypeOf(app.content, app.grading);
|
|
114
|
+
|
|
115
|
+
// 문항 id → 정답(화면 값: 선택 id · id 목록 · 그룹별 목록, 주관식은 허용 답 목록). 저장된 정규식(partial_pattern은 문항별 배열)을 읽어 채운다
|
|
116
|
+
const rawKey = app.grading?.answer_key;
|
|
117
|
+
const savedKey = Array.isArray(rawKey) && rawKey.length === 0 ? null : rawKey;
|
|
118
|
+
const parsed = Array.isArray(savedKey)
|
|
119
|
+
? parseAnswerKeys(draft.questions, savedKey)
|
|
120
|
+
: savedKey
|
|
121
|
+
? parseAnswerKey(draft.questions, savedKey)
|
|
122
|
+
: {};
|
|
43
123
|
/** @type {Record<string, unknown>} */
|
|
44
124
|
const answers = parsed ?? {};
|
|
125
|
+
/** 새 문항의 기본 정답: 첫 번째 보기 하나 (단일 · 복수 선택만, 나머지 유형은 직접 고른다) */
|
|
126
|
+
function defaultAnswer(q) {
|
|
127
|
+
const first = q.options?.[0]?.id;
|
|
128
|
+
if (first === undefined) return undefined;
|
|
129
|
+
if (q.type === "select_one") return first;
|
|
130
|
+
if (q.type === "select_multiple") return [first];
|
|
131
|
+
// 순서 맞추기: 적은 순서가 곧 정답 순서
|
|
132
|
+
if (q.type === "order") return q.options.map((o) => o.id);
|
|
133
|
+
if (q.type === "group") {
|
|
134
|
+
// 보기 1 → 그룹 A, 보기 2 → 그룹 B처럼 하나씩 배정해 시작한다
|
|
135
|
+
const out = Object.fromEntries(q.groups.map((g) => [g.id, []]));
|
|
136
|
+
q.groups.forEach((g, k) => {
|
|
137
|
+
if (q.options[k]) out[g.id].push(q.options[k].id);
|
|
138
|
+
});
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
// 처음 열어 자동으로 만든 문항 1은 첫 번째 보기가 정답으로 선택된 채 시작한다 (저장된 정답이 있으면 그대로)
|
|
144
|
+
if (startedEmpty && !savedKey) {
|
|
145
|
+
const first = draft.questions[0];
|
|
146
|
+
const picked = defaultAnswer(first);
|
|
147
|
+
if (picked !== undefined) answers[first.id] = picked;
|
|
148
|
+
}
|
|
45
149
|
const unreadable = Boolean(savedKey) && parsed === null;
|
|
46
150
|
// 순서 맞추기 정답 칸 (문항 id → 화면). 끌어 놓기는 window에서 끝나 이벤트로 읽으면 마지막 놓기를 놓치므로,
|
|
47
151
|
// 값이 필요할 때(저장 · 다시 그리기 · 보기 삭제) 칸에서 바로 읽는다
|
|
@@ -49,8 +153,6 @@ const answerViews = new Map();
|
|
|
49
153
|
const readAnswerViews = () => {
|
|
50
154
|
for (const [id, view] of answerViews) answers[id] = view.getValue();
|
|
51
155
|
};
|
|
52
|
-
// 유형을 바꿔 정답을 다시 골라야 하는 문항 id (다음 저장까지 카드 위에 알림)
|
|
53
|
-
const retyped = new Set();
|
|
54
156
|
|
|
55
157
|
const form = createEditor({
|
|
56
158
|
rerender: render,
|
|
@@ -69,25 +171,417 @@ const swap = (list, i, j) => {
|
|
|
69
171
|
render();
|
|
70
172
|
};
|
|
71
173
|
|
|
174
|
+
/** 오답 보기 상자를 열어 둔 문항 id. 열려 있으면 보기가 없어도 상자가 남고, 머리줄의 ✕로만 닫는다 */
|
|
175
|
+
const noneOpen = new Set();
|
|
176
|
+
|
|
177
|
+
/** 그룹 상자 q.groups[].id(오답은 "")에 들어 있는 보기들 (보기 목록의 순서 그대로) */
|
|
178
|
+
function groupMembers(q, gid) {
|
|
179
|
+
const value = answers[q.id] ?? {};
|
|
180
|
+
const assigned = new Set(Object.values(value).flat());
|
|
181
|
+
return q.options.filter((o) =>
|
|
182
|
+
gid === "" ? !assigned.has(o.id) : (value[gid] ?? []).includes(o.id),
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** 보기를 toGroup 상자로 옮긴다 (beforeId 보기 앞에, 없으면 그 상자의 맨 끝에). 정답은 상자로 정해지므로 정답도 같이 바뀐다 */
|
|
187
|
+
function moveItem(q, optionId, toGroup, beforeId) {
|
|
188
|
+
answers[q.id] = withOptionAnswer(q, answers[q.id] ?? {}, optionId, toGroup);
|
|
189
|
+
const [opt] = q.options.splice(
|
|
190
|
+
q.options.findIndex((o) => o.id === optionId),
|
|
191
|
+
1,
|
|
192
|
+
);
|
|
193
|
+
let at = beforeId ? q.options.findIndex((o) => o.id === beforeId) : -1;
|
|
194
|
+
if (at < 0) {
|
|
195
|
+
const mine = new Set(groupMembers(q, toGroup).map((o) => o.id));
|
|
196
|
+
let last = -1;
|
|
197
|
+
q.options.forEach((o, i) => {
|
|
198
|
+
if (mine.has(o.id)) last = i;
|
|
199
|
+
});
|
|
200
|
+
at = last < 0 ? q.options.length : last + 1;
|
|
201
|
+
}
|
|
202
|
+
q.options.splice(at, 0, opt);
|
|
203
|
+
render();
|
|
204
|
+
root.querySelector(`[data-option-handle="${optionId}"]`)?.focus();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** 키보드 ↑ · ↓: 상자 안에서 한 칸, 끝에서는 이웃 상자로 (마지막 그룹 아래는 오답 보기) */
|
|
208
|
+
function keyMove(q, optionId, gid, dir) {
|
|
209
|
+
const boxIds = [...q.groups.map((g) => g.id), ""];
|
|
210
|
+
const items = groupMembers(q, gid);
|
|
211
|
+
const idx = items.findIndex((o) => o.id === optionId);
|
|
212
|
+
if (dir < 0) {
|
|
213
|
+
if (idx > 0) return moveItem(q, optionId, gid, items[idx - 1].id);
|
|
214
|
+
const prev = boxIds[boxIds.indexOf(gid) - 1];
|
|
215
|
+
if (prev !== undefined) moveItem(q, optionId, prev, null);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (idx < items.length - 1)
|
|
219
|
+
return moveItem(q, optionId, gid, items[idx + 2]?.id ?? null);
|
|
220
|
+
const next = boxIds[boxIds.indexOf(gid) + 1];
|
|
221
|
+
if (next !== undefined)
|
|
222
|
+
moveItem(q, optionId, next, groupMembers(q, next)[0]?.id ?? null);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 그룹 분류 편집판 (그룹별 상자): 그룹마다 상자가 있고 그 안에 보기를 적는다. 어느 그룹에도 속하지 않는 보기는
|
|
227
|
+
* "오답 보기" 상자 (없으면 "오답 보기 추가" 버튼만). 보기는 손잡이를 끌어 다른 상자로 옮긴다.
|
|
228
|
+
* 저장하는 정답은 그룹별 보기 목록 그대로라 데이터는 바뀌지 않는다
|
|
229
|
+
*/
|
|
230
|
+
function groupBoard(q, shuffle) {
|
|
231
|
+
const fullOptions = q.options.length >= LIMITS.optionsMax;
|
|
232
|
+
const canDeleteOption = q.options.length > LIMITS.optionsMin;
|
|
233
|
+
|
|
234
|
+
const addOption = (gid) => {
|
|
235
|
+
const opt = { id: nextId(q.options.map((o) => o.id)), text: "" };
|
|
236
|
+
q.options.push(opt);
|
|
237
|
+
if (!gid) noneOpen.add(q.id);
|
|
238
|
+
if (gid) answers[q.id] = withOptionAnswer(q, answers[q.id] ?? {}, opt.id, gid);
|
|
239
|
+
render();
|
|
240
|
+
root.querySelector(`[data-option="${opt.id}"] [data-role="input"]`)?.focus();
|
|
241
|
+
};
|
|
242
|
+
const addButton = (gid) => {
|
|
243
|
+
const add = templates.addButton({
|
|
244
|
+
kind: "option",
|
|
245
|
+
full: fullOptions,
|
|
246
|
+
max: LIMITS.optionsMax,
|
|
247
|
+
});
|
|
248
|
+
add.addEventListener("click", () => addOption(gid));
|
|
249
|
+
return add;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const rowFor = (o, gid) => {
|
|
253
|
+
const row = templates.row({
|
|
254
|
+
kind: "option",
|
|
255
|
+
index: q.options.indexOf(o),
|
|
256
|
+
canDelete: canDeleteOption,
|
|
257
|
+
min: LIMITS.optionsMin,
|
|
258
|
+
numbered: false,
|
|
259
|
+
});
|
|
260
|
+
row.dataset.role = "row";
|
|
261
|
+
row.dataset.option = o.id;
|
|
262
|
+
const input = row.querySelector('[data-role="input"]');
|
|
263
|
+
input.value = o.text;
|
|
264
|
+
input.addEventListener("input", () => {
|
|
265
|
+
o.text = input.value;
|
|
266
|
+
});
|
|
267
|
+
row.querySelector('[data-role="delete"]').addEventListener("click", () => {
|
|
268
|
+
const undo = restorer(q, true);
|
|
269
|
+
q.options.splice(q.options.indexOf(o), 1);
|
|
270
|
+
answers[q.id] = pruneAnswer(q, answers[q.id] ?? {});
|
|
271
|
+
render();
|
|
272
|
+
if (o.text.trim()) showSnackbar(t.optionDeleted, () => (undo(), render()));
|
|
273
|
+
});
|
|
274
|
+
const handle = row.querySelector('[data-role="handle"]');
|
|
275
|
+
handle.dataset.optionHandle = o.id;
|
|
276
|
+
form.dragAcross(handle, row, {
|
|
277
|
+
boxSelector: "[data-group-box]",
|
|
278
|
+
onDrop: (box, before) =>
|
|
279
|
+
moveItem(q, o.id, box.dataset.group, before?.dataset.option ?? null),
|
|
280
|
+
onKey: (dir) => keyMove(q, o.id, gid, dir),
|
|
281
|
+
});
|
|
282
|
+
return row;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
const boxes = q.groups.map((g, gi) => {
|
|
286
|
+
const box = templates.groupBox({
|
|
287
|
+
letter: String.fromCharCode(65 + gi),
|
|
288
|
+
canDelete: q.groups.length > LIMITS.groupsMin,
|
|
289
|
+
nameLabel: t.groupName(gi + 1),
|
|
290
|
+
namePlaceholder: t.group(gi + 1),
|
|
291
|
+
deleteLabel: t.groupDelete(gi + 1),
|
|
292
|
+
deleteTitle: t.groupsMin(LIMITS.groupsMin),
|
|
293
|
+
rows: groupMembers(q, g.id).map((o) => rowFor(o, g.id)),
|
|
294
|
+
add: addButton(g.id),
|
|
295
|
+
});
|
|
296
|
+
box.dataset.group = g.id;
|
|
297
|
+
const name = box.querySelector('[data-role="group-name"]');
|
|
298
|
+
name.value = g.name;
|
|
299
|
+
name.addEventListener("input", () => {
|
|
300
|
+
g.name = name.value;
|
|
301
|
+
});
|
|
302
|
+
// 지운 그룹에 넣은 보기는 오답 보기로
|
|
303
|
+
box.querySelector('[data-role="group-delete"]').addEventListener("click", () => {
|
|
304
|
+
q.groups.splice(gi, 1);
|
|
305
|
+
answers[q.id] = pruneAnswer(q, answers[q.id] ?? {});
|
|
306
|
+
render();
|
|
307
|
+
});
|
|
308
|
+
return box;
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const addGroup = templates.addButton({
|
|
312
|
+
kind: "group",
|
|
313
|
+
full: q.groups.length >= LIMITS.groupsMax,
|
|
314
|
+
max: LIMITS.groupsMax,
|
|
315
|
+
});
|
|
316
|
+
addGroup.addEventListener("click", () => {
|
|
317
|
+
q.groups.push({
|
|
318
|
+
id: nextId(q.groups.map((g) => g.id), "g"),
|
|
319
|
+
name: texts.defaults.group(String.fromCharCode(65 + q.groups.length)),
|
|
320
|
+
});
|
|
321
|
+
render();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const none = noneArea(q, {
|
|
325
|
+
items: groupMembers(q, ""),
|
|
326
|
+
rowFor: (o) => rowFor(o, ""),
|
|
327
|
+
addOption,
|
|
328
|
+
addButton,
|
|
329
|
+
fullOptions,
|
|
330
|
+
hint: t.noneHint,
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
return form.ui.section({
|
|
334
|
+
label: t.groupBoard,
|
|
335
|
+
hint: a.hint.group,
|
|
336
|
+
hintInline: true,
|
|
337
|
+
action: shuffle,
|
|
338
|
+
body: templates.groupBoard({ boxes, add: addGroup, none }),
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* 오답 보기 영역 (그룹 분류 · 순서 맞추기 공통): 보기가 있거나 열어 둔 문항이면 점선 상자, 아니면 "오답 보기 추가 +" 버튼.
|
|
344
|
+
* 머리줄의 ✕로 상자를 닫으면 안의 오답 보기도 함께 지운다 (있었다면 되돌리기 알림).
|
|
345
|
+
* 오답 보기가 하나만 남으면 그 줄의 ✕는 끄고 상자의 ✕로 닫으라고 안내한다 (빈 상자가 남지 않게)
|
|
346
|
+
*/
|
|
347
|
+
function noneArea(q, { items, rowFor, addOption, addButton, fullOptions, hint }) {
|
|
348
|
+
if (items.length) noneOpen.add(q.id);
|
|
349
|
+
if (!noneOpen.has(q.id)) {
|
|
350
|
+
const none = templates.noneAdd();
|
|
351
|
+
const button = none.querySelector('[data-role="none-add"]');
|
|
352
|
+
button.disabled = fullOptions;
|
|
353
|
+
button.addEventListener("click", () => addOption(""));
|
|
354
|
+
return none;
|
|
355
|
+
}
|
|
356
|
+
const canClose = q.options.length - items.length >= LIMITS.optionsMin;
|
|
357
|
+
const rows = items.map((o) => rowFor(o));
|
|
358
|
+
if (rows.length === 1) {
|
|
359
|
+
const remove = rows[0].querySelector('[data-role="delete"]');
|
|
360
|
+
remove.disabled = true;
|
|
361
|
+
remove.title = t.noneRowMin;
|
|
362
|
+
}
|
|
363
|
+
const none = templates.noneBox({
|
|
364
|
+
rows,
|
|
365
|
+
add: addButton(""),
|
|
366
|
+
hint,
|
|
367
|
+
canClose,
|
|
368
|
+
closeTitle: t.optionsMin(LIMITS.optionsMin),
|
|
369
|
+
});
|
|
370
|
+
none.dataset.group = "";
|
|
371
|
+
none.querySelector('[data-role="none-close"]').addEventListener("click", () => {
|
|
372
|
+
const prev = {
|
|
373
|
+
options: structuredClone(q.options),
|
|
374
|
+
answer: structuredClone(answers[q.id]),
|
|
375
|
+
};
|
|
376
|
+
const ids = new Set(items.map((o) => o.id));
|
|
377
|
+
q.options = q.options.filter((o) => !ids.has(o.id));
|
|
378
|
+
noneOpen.delete(q.id);
|
|
379
|
+
render();
|
|
380
|
+
if (ids.size)
|
|
381
|
+
showSnackbar(t.noneDeleted(ids.size), () => {
|
|
382
|
+
q.options = prev.options;
|
|
383
|
+
if (prev.answer !== undefined) answers[q.id] = prev.answer;
|
|
384
|
+
noneOpen.add(q.id);
|
|
385
|
+
render();
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
return none;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// ---- 순서 맞추기: 정답 순서 = answers[q.id] (보기 id의 순서), 순서에 들어가지 않은 보기 = 오답 보기 ----
|
|
392
|
+
|
|
393
|
+
/** 정답 순서에 들어 있는 보기 id들 (지운 보기는 뺌) */
|
|
394
|
+
function orderIds(q) {
|
|
395
|
+
const exists = new Set(q.options.map((o) => o.id));
|
|
396
|
+
return (answers[q.id] ?? []).filter((id) => exists.has(id));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** 정답 순서의 칸 수는 순서 목록의 길이 (학생 화면의 답안 칸 수) */
|
|
400
|
+
function syncSlots(q) {
|
|
401
|
+
q.slots = Math.max(1, orderIds(q).length);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** 보기를 정답 순서("order") 또는 오답 보기("")로 옮긴다 (순서 목록에서는 beforeId 보기 앞에, 없으면 맨 끝) */
|
|
405
|
+
function moveOrderItem(q, optionId, to, beforeId) {
|
|
406
|
+
const ids = orderIds(q).filter((id) => id !== optionId);
|
|
407
|
+
if (to === "order") {
|
|
408
|
+
const at = beforeId ? ids.indexOf(beforeId) : -1;
|
|
409
|
+
ids.splice(at < 0 ? ids.length : at, 0, optionId);
|
|
410
|
+
}
|
|
411
|
+
answers[q.id] = ids;
|
|
412
|
+
syncSlots(q);
|
|
413
|
+
render();
|
|
414
|
+
root.querySelector(`[data-option-handle="${optionId}"]`)?.focus();
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** 키보드 ↑ · ↓: 순서 목록 안에서 한 칸, 맨 아래에서 ↓는 오답 보기로, 오답 보기에서 ↑는 순서 목록 맨 끝으로 */
|
|
418
|
+
function orderKeyMove(q, optionId, box, dir) {
|
|
419
|
+
const ids = orderIds(q);
|
|
420
|
+
if (box === "") {
|
|
421
|
+
if (dir < 0) moveOrderItem(q, optionId, "order", null);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const idx = ids.indexOf(optionId);
|
|
425
|
+
if (dir < 0) {
|
|
426
|
+
if (idx > 0) moveOrderItem(q, optionId, "order", ids[idx - 1]);
|
|
427
|
+
} else if (idx < ids.length - 1)
|
|
428
|
+
moveOrderItem(q, optionId, "order", ids[idx + 2] ?? null);
|
|
429
|
+
else moveOrderItem(q, optionId, "", null);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* 순서 맞추기 편집판 (Zep 순서맞추기와 같은 방식): 보기를 정답 순서대로 번호 목록에 적으면 그 순서가 정답이다.
|
|
434
|
+
* 순서에 넣지 않을 보기는 "오답 보기" 상자에 둔다. 손잡이를 끌어 순서를 바꾸고 두 곳 사이를 옮긴다
|
|
435
|
+
*/
|
|
436
|
+
function orderBoard(q, shuffle) {
|
|
437
|
+
const fullOptions = q.options.length >= LIMITS.optionsMax;
|
|
438
|
+
const canDeleteOption = q.options.length > LIMITS.optionsMin;
|
|
439
|
+
|
|
440
|
+
const addOption = (box) => {
|
|
441
|
+
const opt = { id: nextId(q.options.map((o) => o.id)), text: "" };
|
|
442
|
+
q.options.push(opt);
|
|
443
|
+
if (box === "order") {
|
|
444
|
+
answers[q.id] = [...orderIds(q), opt.id];
|
|
445
|
+
syncSlots(q);
|
|
446
|
+
} else noneOpen.add(q.id);
|
|
447
|
+
render();
|
|
448
|
+
root.querySelector(`[data-option="${opt.id}"] [data-role="input"]`)?.focus();
|
|
449
|
+
};
|
|
450
|
+
const addButton = (box) => {
|
|
451
|
+
const add = templates.addButton({
|
|
452
|
+
kind: "option",
|
|
453
|
+
full: fullOptions,
|
|
454
|
+
max: LIMITS.optionsMax,
|
|
455
|
+
});
|
|
456
|
+
add.addEventListener("click", () => addOption(box));
|
|
457
|
+
return add;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
const rowFor = (o, box, index) => {
|
|
461
|
+
const row = templates.row({
|
|
462
|
+
kind: "option",
|
|
463
|
+
index,
|
|
464
|
+
canDelete: canDeleteOption,
|
|
465
|
+
min: LIMITS.optionsMin,
|
|
466
|
+
numbered: box === "order",
|
|
467
|
+
});
|
|
468
|
+
row.dataset.role = "row";
|
|
469
|
+
row.dataset.option = o.id;
|
|
470
|
+
const input = row.querySelector('[data-role="input"]');
|
|
471
|
+
input.value = o.text;
|
|
472
|
+
input.addEventListener("input", () => {
|
|
473
|
+
o.text = input.value;
|
|
474
|
+
});
|
|
475
|
+
row.querySelector('[data-role="delete"]').addEventListener("click", () => {
|
|
476
|
+
const undo = restorer(q, true);
|
|
477
|
+
q.options.splice(q.options.indexOf(o), 1);
|
|
478
|
+
answers[q.id] = orderIds(q);
|
|
479
|
+
syncSlots(q);
|
|
480
|
+
render();
|
|
481
|
+
if (o.text.trim()) showSnackbar(t.optionDeleted, () => (undo(), render()));
|
|
482
|
+
});
|
|
483
|
+
const handle = row.querySelector('[data-role="handle"]');
|
|
484
|
+
handle.dataset.optionHandle = o.id;
|
|
485
|
+
form.dragAcross(handle, row, {
|
|
486
|
+
boxSelector: "[data-group-box]",
|
|
487
|
+
onDrop: (target, before) =>
|
|
488
|
+
moveOrderItem(q, o.id, target.dataset.group, before?.dataset.option ?? null),
|
|
489
|
+
onKey: (dir) => orderKeyMove(q, o.id, box, dir),
|
|
490
|
+
});
|
|
491
|
+
return row;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const byId = new Map(q.options.map((o) => [o.id, o]));
|
|
495
|
+
const ordered = orderIds(q).map((id) => byId.get(id));
|
|
496
|
+
const inOrder = new Set(ordered.map((o) => o.id));
|
|
497
|
+
const list = templates.orderList({
|
|
498
|
+
rows: ordered.map((o, i) => rowFor(o, "order", i)),
|
|
499
|
+
add: addButton("order"),
|
|
500
|
+
});
|
|
501
|
+
const none = noneArea(q, {
|
|
502
|
+
items: q.options.filter((o) => !inOrder.has(o.id)),
|
|
503
|
+
rowFor: (o) => rowFor(o, "", q.options.indexOf(o)),
|
|
504
|
+
addOption,
|
|
505
|
+
addButton,
|
|
506
|
+
fullOptions,
|
|
507
|
+
hint: t.noneHintOrder,
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
return form.ui.section({
|
|
511
|
+
label: t.orderTitle,
|
|
512
|
+
hint: a.hint.order,
|
|
513
|
+
hintInline: true,
|
|
514
|
+
action: shuffle,
|
|
515
|
+
body: templates.orderBoard({ list, none }),
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
|
|
72
519
|
/** 순서 · 주관식 문항 카드의 "정답": 학생 화면과 같은 보기 · 칸으로 고른다 (주관식은 허용 답 여러 개) */
|
|
73
520
|
function answerField(q) {
|
|
74
|
-
if (q.type ===
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
answers[q.id] =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
521
|
+
if (q.type === "text") {
|
|
522
|
+
// 정답 목록: 줄마다 밑줄 칸 하나, 유사 정답은 "+ 유사 정답 추가"로 늘린다.
|
|
523
|
+
// 저장하는 값은 앞뒤 공백을 자른 비어 있지 않은 답의 목록 (칸은 비어 있어도 목록에는 넣지 않음)
|
|
524
|
+
const rows = (answers[q.id] ?? []).length ? [...answers[q.id]] : [""];
|
|
525
|
+
const body = document.createElement("div");
|
|
526
|
+
const sync = () => {
|
|
527
|
+
answers[q.id] = rows.map((v) => v.trim()).filter(Boolean);
|
|
528
|
+
};
|
|
529
|
+
const paint = (focusAt) => {
|
|
530
|
+
const nodes = rows.map((value, i) => {
|
|
531
|
+
const row = templates.textAnswerRow({ index: i, canDelete: rows.length > 1 });
|
|
532
|
+
const input = row.querySelector('[data-role="input"]');
|
|
533
|
+
input.value = value;
|
|
534
|
+
input.addEventListener("input", () => {
|
|
535
|
+
rows[i] = input.value;
|
|
536
|
+
sync();
|
|
537
|
+
});
|
|
538
|
+
// Enter: 다음 칸으로 (마지막이면 새 칸). 한글 조합 중의 Enter는 무시
|
|
539
|
+
input.addEventListener("keydown", (e) => {
|
|
540
|
+
if (e.key !== "Enter" || e.isComposing) return;
|
|
541
|
+
e.preventDefault();
|
|
542
|
+
if (i === rows.length - 1) rows.push("");
|
|
543
|
+
paint(i + 1);
|
|
544
|
+
});
|
|
545
|
+
// 글이 있던 정답을 지우면 "정답을 삭제했습니다. 되돌리기"
|
|
546
|
+
row.querySelector('[data-role="delete"]').addEventListener("click", () => {
|
|
547
|
+
const [removed] = rows.splice(i, 1);
|
|
548
|
+
sync();
|
|
549
|
+
paint(Math.min(i, rows.length - 1));
|
|
550
|
+
if (!removed.trim()) return;
|
|
551
|
+
showSnackbar(t.answerDeleted, () => {
|
|
552
|
+
rows.splice(i, 0, removed);
|
|
553
|
+
sync();
|
|
554
|
+
render();
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
return row;
|
|
558
|
+
});
|
|
559
|
+
const add = templates.textAnswerAdd();
|
|
560
|
+
add.addEventListener("click", () => {
|
|
561
|
+
rows.push("");
|
|
562
|
+
paint(rows.length - 1);
|
|
563
|
+
});
|
|
564
|
+
body.replaceChildren(templates.textAnswers({ rows: nodes, add }));
|
|
565
|
+
if (focusAt !== undefined)
|
|
566
|
+
body.querySelectorAll('[data-role="input"]')[focusAt]?.focus();
|
|
567
|
+
};
|
|
568
|
+
paint();
|
|
569
|
+
return form.ui.section({
|
|
570
|
+
label: a.label,
|
|
571
|
+
hint: a.hint.text,
|
|
572
|
+
hintInline: true,
|
|
573
|
+
body,
|
|
84
574
|
});
|
|
85
|
-
return form.ui.section({ label: a.label, hint: a.hint.text, body: node });
|
|
86
575
|
}
|
|
87
576
|
const view = renderAnswerBody(q, { templates: quizTemplates });
|
|
88
577
|
if (answers[q.id] !== undefined) view.setValue(answers[q.id]);
|
|
89
578
|
answerViews.set(q.id, view);
|
|
90
|
-
return form.ui.section({
|
|
579
|
+
return form.ui.section({
|
|
580
|
+
label: a.label,
|
|
581
|
+
hint: a.hint[q.type],
|
|
582
|
+
hintInline: true,
|
|
583
|
+
body: view.el,
|
|
584
|
+
});
|
|
91
585
|
}
|
|
92
586
|
|
|
93
587
|
/**
|
|
@@ -95,14 +589,38 @@ function answerField(q) {
|
|
|
95
589
|
* 순서를 바꿔도 그대로이고, 보기를 지우면 정답에서 뺀다 (optionsOpts의 onDelete)
|
|
96
590
|
*/
|
|
97
591
|
function inlineAnswer(q) {
|
|
98
|
-
const types = {
|
|
592
|
+
const types = {
|
|
593
|
+
select_one: "radio",
|
|
594
|
+
select_multiple: "checkbox",
|
|
595
|
+
group: "select",
|
|
596
|
+
};
|
|
99
597
|
return {
|
|
100
598
|
type: types[q.type],
|
|
101
599
|
// 문항마다 다른 이름 (같은 문항의 radio끼리만 묶임)
|
|
102
600
|
name: `answer-${q.id}`,
|
|
103
|
-
choices:
|
|
104
|
-
|
|
105
|
-
|
|
601
|
+
choices:
|
|
602
|
+
q.type === "group" ? q.groups.map((g) => [g.id, g.name]) : undefined,
|
|
603
|
+
get: (option) => optionAnswer(q, answers[q.id], option.id),
|
|
604
|
+
set: (option, value) =>
|
|
605
|
+
(answers[q.id] = withOptionAnswer(q, answers[q.id], option.id, value)),
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* 보기를 지우기 전 상태로 되돌리는 함수 (되돌리기 알림). 정답 · 순서 맞추기 칸 수, withOptions면 보기 목록도
|
|
611
|
+
*/
|
|
612
|
+
function restorer(q, withOptions = false) {
|
|
613
|
+
const prev = {
|
|
614
|
+
options: withOptions ? structuredClone(q.options) : undefined,
|
|
615
|
+
answer: structuredClone(answers[q.id]),
|
|
616
|
+
slots: q.slots,
|
|
617
|
+
};
|
|
618
|
+
return () => {
|
|
619
|
+
if (prev.options) q.options = prev.options;
|
|
620
|
+
if (prev.answer === undefined) delete answers[q.id];
|
|
621
|
+
else answers[q.id] = prev.answer;
|
|
622
|
+
if (prev.slots !== undefined) q.slots = prev.slots;
|
|
623
|
+
answerViews.delete(q.id);
|
|
106
624
|
};
|
|
107
625
|
}
|
|
108
626
|
|
|
@@ -112,15 +630,23 @@ function optionsOpts(q) {
|
|
|
112
630
|
return {
|
|
113
631
|
// 순서 맞추기 칸 수를 따로 정하지 않았으면(보기 수와 같음) 보기를 더할 때 같이 늘린다
|
|
114
632
|
onAdd: () => {
|
|
115
|
-
if (q.type ===
|
|
633
|
+
if (q.type === "order" && q.slots === q.options.length - 1)
|
|
634
|
+
q.slots = q.options.length;
|
|
116
635
|
},
|
|
117
636
|
onDelete: () => {
|
|
118
637
|
readAnswerViews();
|
|
119
|
-
if (q.type ===
|
|
120
|
-
if (answers[q.id] !== undefined)
|
|
638
|
+
if (q.type === "order") q.slots = Math.min(q.slots, q.options.length);
|
|
639
|
+
if (answers[q.id] !== undefined)
|
|
640
|
+
answers[q.id] = pruneAnswer(q, answers[q.id]);
|
|
121
641
|
// 다시 그릴 때 지우기 전 칸 값으로 덮지 않게
|
|
122
642
|
answerViews.delete(q.id);
|
|
123
643
|
},
|
|
644
|
+
// 글이 있던 보기를 지우면 "보기를 삭제했습니다. 되돌리기" (정답 · 칸 수도 되돌림)
|
|
645
|
+
snapshot: () => {
|
|
646
|
+
readAnswerViews();
|
|
647
|
+
return restorer(q);
|
|
648
|
+
},
|
|
649
|
+
onRemoved: (undo) => showSnackbar(t.optionDeleted, undo),
|
|
124
650
|
// 순서 맞추기: 보기 글을 고치면 정답 칸의 보기 이름도 바로 바꾼다 (다시 그리면 입력 중 초점을 잃음)
|
|
125
651
|
onInput:
|
|
126
652
|
q.type === 'order'
|
|
@@ -131,95 +657,129 @@ function optionsOpts(q) {
|
|
|
131
657
|
}
|
|
132
658
|
: undefined,
|
|
133
659
|
answer: inline ? inlineAnswer(q) : undefined,
|
|
660
|
+
// 단일 · 복수 선택은 정답 체크가 있어 번호를 두지 않는다 (순서 맞추기 · 그룹 분류는 번호 유지)
|
|
661
|
+
numbered: q.type !== "select_one" && q.type !== "select_multiple",
|
|
134
662
|
};
|
|
135
663
|
}
|
|
136
664
|
|
|
137
665
|
/** 정답을 고르는 묶음 (저장하지 못한 정답 문제를 여기에 표시) */
|
|
138
|
-
const answerArea = section => {
|
|
139
|
-
section.dataset.role =
|
|
666
|
+
const answerArea = (section) => {
|
|
667
|
+
section.dataset.role = "answers";
|
|
140
668
|
return section;
|
|
141
669
|
};
|
|
142
670
|
|
|
143
671
|
/** 문항 카드 안의 칸들. 유형마다 보이는 칸이 다르다 */
|
|
144
672
|
function questionFields(q, i) {
|
|
673
|
+
// 보기 순서 섞기: 보기 제목줄 오른쪽 (주관식은 보기가 없음)
|
|
674
|
+
const shuffle =
|
|
675
|
+
q.type === "text"
|
|
676
|
+
? undefined
|
|
677
|
+
: form.toggle(
|
|
678
|
+
t.shuffle,
|
|
679
|
+
q.shuffle,
|
|
680
|
+
(v) => (q.shuffle = v),
|
|
681
|
+
t.shuffleHint,
|
|
682
|
+
"shuffle",
|
|
683
|
+
);
|
|
145
684
|
const body = [
|
|
146
|
-
|
|
147
|
-
form.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
685
|
+
// 질문 · 설명: 라벨 없이 바로 쓰는 칸 (퀴즈 제목 · 안내와 같은 방식, 화면 낭독기용 이름은 aria-label)
|
|
686
|
+
form.inlineField(t.title, q.title, (v) => (q.title = v), {
|
|
687
|
+
placeholder: t.titlePlaceholder,
|
|
688
|
+
size: "question",
|
|
689
|
+
required: true,
|
|
690
|
+
max: LIMITS.titleMax,
|
|
691
|
+
// 질문은 1000자까지라 글자 수 표시는 두지 않는다 (입력 제한은 그대로)
|
|
692
|
+
showCount: false,
|
|
152
693
|
}),
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
if (q.type === 'group') {
|
|
176
|
-
const groups = form.itemList('group', q.groups, `${i}g`, {
|
|
177
|
-
// 지운 그룹에 넣은 보기는 "오답 (그룹 없음)"으로
|
|
178
|
-
onDelete: () => {
|
|
179
|
-
if (answers[q.id] !== undefined) answers[q.id] = pruneAnswer(q, answers[q.id]);
|
|
694
|
+
// 문항 설명: 필요할 때만 "설명 추가 +"로 연다. 열리면 해설과 같은 머리줄(아이콘 · 이름 · 지우기). 새 문항에는 키가 없고, 적으면 생긴다
|
|
695
|
+
form.revealable(
|
|
696
|
+
t.addDescription,
|
|
697
|
+
form.richField(
|
|
698
|
+
t.description,
|
|
699
|
+
q.description ?? "",
|
|
700
|
+
(v) => (q.description = v),
|
|
701
|
+
{ placeholder: t.descriptionPlaceholder, images: imageBlocks },
|
|
702
|
+
),
|
|
703
|
+
{
|
|
704
|
+
open: Boolean(q.description),
|
|
705
|
+
title: t.description,
|
|
706
|
+
icon: "comment",
|
|
707
|
+
// 서식 도구 (굵게 · 기울임 · 취소선 · 목록 · 코드 · 그림) — 연주님 최종 수정본
|
|
708
|
+
tools: t.md,
|
|
709
|
+
images: imageUpload,
|
|
710
|
+
onRemoved: (text) =>
|
|
711
|
+
showSnackbar(t.fieldDeleted(t.description), () => {
|
|
712
|
+
q.description = text;
|
|
713
|
+
render();
|
|
714
|
+
}),
|
|
180
715
|
},
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
},
|
|
186
|
-
});
|
|
716
|
+
),
|
|
717
|
+
];
|
|
718
|
+
if (q.type === "select_one" || q.type === "select_multiple") {
|
|
719
|
+
const options = form.itemList("option", q.options, `${i}o`, optionsOpts(q));
|
|
187
720
|
body.push(
|
|
188
|
-
form.ui.section({ label: t.groups, body: groups }),
|
|
189
721
|
answerArea(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
body: form.itemList('option', q.options, `${i}o`, optionsOpts(q)),
|
|
194
|
-
})
|
|
195
|
-
)
|
|
722
|
+
// 단일 · 복수 선택은 체크 원과 기본 정답으로 알 수 있어 힌트를 두지 않는다 (그룹 분류 · 순서 맞추기는 따로 둠)
|
|
723
|
+
form.ui.section({ label: t.options, body: options, action: shuffle }),
|
|
724
|
+
),
|
|
196
725
|
);
|
|
197
726
|
}
|
|
198
|
-
if (q.type ===
|
|
727
|
+
if (q.type === "order") body.push(answerArea(orderBoard(q, shuffle)));
|
|
728
|
+
if (q.type === "group") body.push(answerArea(groupBoard(q, shuffle)));
|
|
729
|
+
if (!INLINE_ANSWER_TYPES.includes(q.type) && q.type !== "order")
|
|
730
|
+
body.push(answerArea(answerField(q)));
|
|
731
|
+
if (q.type === "text")
|
|
199
732
|
body.push(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
733
|
+
// 입력란 힌트: 정답 아래에서 필요할 때만 "입력란 힌트 추가 +"로 연다 (설명 · 해설과 같은 구조)
|
|
734
|
+
form.revealable(
|
|
735
|
+
t.addPlaceholder,
|
|
736
|
+
form.inlineField(
|
|
737
|
+
t.placeholder,
|
|
738
|
+
q.placeholder ?? "",
|
|
739
|
+
(v) => (q.placeholder = v),
|
|
740
|
+
{ placeholder: t.placeholderInput, max: LIMITS.placeholderMax },
|
|
741
|
+
),
|
|
742
|
+
{
|
|
743
|
+
open: Boolean(q.placeholder),
|
|
744
|
+
title: t.placeholder,
|
|
745
|
+
icon: "textbox",
|
|
746
|
+
hint: t.placeholderHint,
|
|
747
|
+
onRemoved: (text) =>
|
|
748
|
+
showSnackbar(t.fieldDeleted(t.placeholder), () => {
|
|
749
|
+
q.placeholder = text;
|
|
750
|
+
render();
|
|
751
|
+
}),
|
|
752
|
+
},
|
|
753
|
+
),
|
|
204
754
|
);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
755
|
+
// 해설: 정답 아래에서 필요할 때만 "+ 해설 추가"로 연다. 열면 사용, 비운 채 닫으면 사용 안 함
|
|
756
|
+
body.push(
|
|
757
|
+
form.revealable(
|
|
758
|
+
t.addExplanation,
|
|
759
|
+
form.richField(
|
|
760
|
+
t.explanation,
|
|
761
|
+
q.explanation?.text ?? "",
|
|
762
|
+
(v) => (q.explanation = { text: v, enabled: true }),
|
|
763
|
+
{ placeholder: t.explanationPlaceholder, images: imageBlocks },
|
|
764
|
+
),
|
|
765
|
+
{
|
|
766
|
+
open: Boolean(q.explanation?.enabled),
|
|
767
|
+
onOpen: () =>
|
|
768
|
+
(q.explanation = { text: q.explanation?.text ?? "", enabled: true }),
|
|
769
|
+
onClose: () => (q.explanation = { text: "", enabled: false }),
|
|
770
|
+
title: t.explanation,
|
|
771
|
+
icon: "bulb",
|
|
772
|
+
tools: t.md,
|
|
773
|
+
images: imageUpload,
|
|
774
|
+
hint: t.explanationHint,
|
|
775
|
+
onRemoved: (text) =>
|
|
776
|
+
showSnackbar(t.fieldDeleted(t.explanation), () => {
|
|
777
|
+
q.explanation = { text, enabled: true };
|
|
778
|
+
render();
|
|
779
|
+
}),
|
|
780
|
+
},
|
|
781
|
+
),
|
|
214
782
|
);
|
|
215
|
-
if (q.explanation?.enabled)
|
|
216
|
-
display.push(
|
|
217
|
-
form.field(t.explanation, q.explanation.text, v => (q.explanation.text = v), {
|
|
218
|
-
multiline: true,
|
|
219
|
-
showOptional: false,
|
|
220
|
-
})
|
|
221
|
-
);
|
|
222
|
-
body.push(templates.displayOptions({ label: t.display, body: display }));
|
|
223
783
|
return body.filter(Boolean);
|
|
224
784
|
}
|
|
225
785
|
|
|
@@ -233,86 +793,115 @@ function questionCard(q, i) {
|
|
|
233
793
|
body: questionFields(q, i),
|
|
234
794
|
},
|
|
235
795
|
{
|
|
236
|
-
type: type => {
|
|
796
|
+
type: (type) => {
|
|
237
797
|
readAnswerViews();
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
798
|
+
const prev = {
|
|
799
|
+
q: structuredClone(q),
|
|
800
|
+
answer: structuredClone(answers[q.id]),
|
|
801
|
+
};
|
|
802
|
+
// 유형을 바꾸면 제목만 남기고 나머지(설명 · 보기 · 해설 · 정답)는 새 유형의 기본값으로 시작한다
|
|
803
|
+
const fresh = {
|
|
804
|
+
...newQuestion(prev.q.type, [], texts.defaults),
|
|
805
|
+
id: q.id,
|
|
806
|
+
title: q.title,
|
|
807
|
+
};
|
|
808
|
+
// 바꾸기 전에 입력한 내용이 기본값과 다를 때만 되돌리기 알림을 띄운다
|
|
809
|
+
const edited =
|
|
810
|
+
JSON.stringify(prev.q) !== JSON.stringify(fresh) ||
|
|
811
|
+
JSON.stringify(prev.answer) !== JSON.stringify(defaultAnswer(fresh));
|
|
812
|
+
draft.questions[i] = {
|
|
813
|
+
...newQuestion(type, [], texts.defaults),
|
|
814
|
+
id: q.id,
|
|
815
|
+
title: q.title,
|
|
816
|
+
};
|
|
241
817
|
delete answers[q.id];
|
|
818
|
+
const picked = defaultAnswer(draft.questions[i]);
|
|
819
|
+
if (picked !== undefined) answers[q.id] = picked;
|
|
242
820
|
answerViews.delete(q.id);
|
|
243
|
-
|
|
821
|
+
noneOpen.delete(q.id);
|
|
244
822
|
render();
|
|
823
|
+
if (edited)
|
|
824
|
+
showSnackbar(t.typeChanged, () => {
|
|
825
|
+
draft.questions[i] = prev.q;
|
|
826
|
+
if (prev.answer !== undefined) answers[q.id] = prev.answer;
|
|
827
|
+
else delete answers[q.id];
|
|
828
|
+
render();
|
|
829
|
+
});
|
|
245
830
|
},
|
|
246
831
|
up: () => swap(draft.questions, i, i - 1),
|
|
247
832
|
down: () => swap(draft.questions, i, i + 1),
|
|
248
833
|
// 지운 문항은 알림의 "되돌리기"로 같은 자리에 되살린다 (정답도 함께)
|
|
249
834
|
remove: () => {
|
|
250
835
|
readAnswerViews();
|
|
251
|
-
const removed = {
|
|
836
|
+
const removed = {
|
|
837
|
+
q: structuredClone(q),
|
|
838
|
+
answer: structuredClone(answers[q.id]),
|
|
839
|
+
};
|
|
252
840
|
draft.questions.splice(i, 1);
|
|
253
841
|
delete answers[q.id];
|
|
254
842
|
answerViews.delete(q.id);
|
|
255
|
-
|
|
256
|
-
|
|
843
|
+
render();
|
|
844
|
+
showSnackbar(t.questionDeleted(i + 1), () => {
|
|
257
845
|
draft.questions.splice(i, 0, removed.q);
|
|
258
846
|
if (removed.answer !== undefined) answers[q.id] = removed.answer;
|
|
259
847
|
render();
|
|
260
|
-
};
|
|
261
|
-
undoAt = i;
|
|
262
|
-
render();
|
|
848
|
+
});
|
|
263
849
|
},
|
|
264
|
-
}
|
|
850
|
+
},
|
|
265
851
|
);
|
|
266
852
|
}
|
|
267
853
|
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
854
|
+
/**
|
|
855
|
+
* 스낵바 (EDS Snackbar): 문항 삭제 · 유형 변경 뒤 "되돌리기"를 화면 아래에 잠깐 띄운다.
|
|
856
|
+
* 한 번에 하나만 보이고(새 알림이 앞의 것을 대체), 화면 영역 밖(body)에 붙여 다시 그려도 사라지지 않으며
|
|
857
|
+
* 변경 표시(저장하지 않은 변경)를 만들지 않는다. 초점을 빼앗지 않는다
|
|
858
|
+
*/
|
|
859
|
+
const SNACKBAR_MS = 6000;
|
|
860
|
+
let snackbarNode = null;
|
|
861
|
+
let snackbarTimer = null;
|
|
862
|
+
|
|
863
|
+
function hideSnackbar() {
|
|
864
|
+
clearTimeout(snackbarTimer);
|
|
865
|
+
snackbarNode?.remove();
|
|
866
|
+
snackbarNode = null;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/** restore가 없으면 알림만 (되돌리기 버튼 없음) */
|
|
870
|
+
function showSnackbar(text, restore) {
|
|
871
|
+
hideSnackbar();
|
|
872
|
+
const node = templates.snackbar({ text, action: restore ? t.undo : null });
|
|
873
|
+
node.querySelector('[data-role="undo"]')?.addEventListener("click", () => {
|
|
874
|
+
hideSnackbar();
|
|
875
|
+
restore();
|
|
876
|
+
});
|
|
877
|
+
document.body.append(node);
|
|
878
|
+
snackbarNode = node;
|
|
879
|
+
snackbarTimer = setTimeout(hideSnackbar, SNACKBAR_MS);
|
|
286
880
|
}
|
|
287
881
|
|
|
288
882
|
function render() {
|
|
289
883
|
readAnswerViews();
|
|
290
884
|
answerViews.clear();
|
|
291
885
|
const cards = draft.questions.map(questionCard);
|
|
292
|
-
if (undo) cards.splice(undoAt, 0, undoNotice(undo, undoAt));
|
|
293
|
-
undo = null;
|
|
294
886
|
root.replaceChildren(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
// 퀴즈
|
|
298
|
-
form.field(t.quizDescription, draft.description, v => (draft.description = v), {
|
|
299
|
-
multiline: true,
|
|
300
|
-
showOptional: false,
|
|
301
|
-
}),
|
|
887
|
+
// 저장된 정답을 못 읽었을 때만 맨 위에 경고
|
|
888
|
+
...(unreadable ? [templates.answersIntro({ text: a.unreadable })] : []),
|
|
889
|
+
// 퀴즈 제목 · 안내 칸은 두지 않는다 (연주님 최종 수정본). 예전에 저장한 title · description은 draft에 그대로 남아 같이 저장된다
|
|
302
890
|
...cards,
|
|
303
|
-
//
|
|
891
|
+
// 문항은 LIMITS.questionsMax개까지: 다 차면 "문항 추가" 대신 안내
|
|
304
892
|
canAddQuestion(draft.questions)
|
|
305
893
|
? form.addQuestion(() => {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
texts.defaults
|
|
311
|
-
)
|
|
894
|
+
const added = newQuestion(
|
|
895
|
+
"select_one",
|
|
896
|
+
draft.questions.map((q) => q.id),
|
|
897
|
+
texts.defaults,
|
|
312
898
|
);
|
|
899
|
+
draft.questions.push(added);
|
|
900
|
+
const picked = defaultAnswer(added);
|
|
901
|
+
if (picked !== undefined) answers[added.id] = picked;
|
|
313
902
|
render();
|
|
314
903
|
})
|
|
315
|
-
: templates.
|
|
904
|
+
: templates.questionLimit({ text: t.questionLimit }),
|
|
316
905
|
);
|
|
317
906
|
save?.markDirty();
|
|
318
907
|
}
|
|
@@ -325,7 +914,7 @@ const problemAt = (problem, { answer = false } = {}) => {
|
|
|
325
914
|
const card = form.cardAt(problem.questionIndex);
|
|
326
915
|
const pick = answer ? card?.querySelector('[data-role="answer"]') : null;
|
|
327
916
|
if (answer) markAnswerError(card, problem.message);
|
|
328
|
-
(pick ?? card)?.scrollIntoView({ block:
|
|
917
|
+
(pick ?? card)?.scrollIntoView({ block: "center" });
|
|
329
918
|
pick?.focus({ preventScroll: true });
|
|
330
919
|
return problem.message;
|
|
331
920
|
};
|
|
@@ -335,23 +924,89 @@ function markAnswerError(card, message) {
|
|
|
335
924
|
const area = card?.querySelector('[data-role="answers"]');
|
|
336
925
|
if (!area) return;
|
|
337
926
|
area.querySelector('[data-role="answer-error"]')?.remove();
|
|
338
|
-
area.dataset.error =
|
|
927
|
+
area.dataset.error = "";
|
|
339
928
|
area.lastElementChild.before(templates.answerError({ text: message }));
|
|
340
929
|
const clear = () => {
|
|
341
930
|
delete area.dataset.error;
|
|
342
931
|
area.querySelector('[data-role="answer-error"]')?.remove();
|
|
343
|
-
for (const type of [
|
|
932
|
+
for (const type of ["input", "change", "pointerup"])
|
|
933
|
+
area.removeEventListener(type, clear);
|
|
344
934
|
};
|
|
345
|
-
for (const type of [
|
|
935
|
+
for (const type of ["input", "change", "pointerup"])
|
|
936
|
+
area.addEventListener(type, clear);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* partial_pattern 채점 설정: 문항마다 정답 정규식(서버 한도 ANSWER_KEY_MAX는 문항 하나에 걸림)과 점수.
|
|
941
|
+
* 검증(정규식 공통 검사 → 문항별 왕복 · 오답)을 통과해야 저장한다. 점수는 문항 수가 같으면 저장된 그대로,
|
|
942
|
+
* 바뀌었거나 저장된 점수가 규칙(0~100 정수, 합 100 이상)에 맞지 않으면 똑같이 나누고 짧게 알린다
|
|
943
|
+
*/
|
|
944
|
+
function partialGrading(questions) {
|
|
945
|
+
const keys = buildAnswerKeys(questions, answers);
|
|
946
|
+
const base = questions.map((q) =>
|
|
947
|
+
q.type === "text" ? (answers[q.id] ?? [])[0] : answers[q.id],
|
|
948
|
+
);
|
|
949
|
+
for (const [i, key] of keys.entries()) {
|
|
950
|
+
if (key.length > ANSWER_KEY_MAX)
|
|
951
|
+
return problemAt(
|
|
952
|
+
{
|
|
953
|
+
questionIndex: i,
|
|
954
|
+
message: a.validation.at(
|
|
955
|
+
i + 1,
|
|
956
|
+
a.validation.tooLongItem(key.length, ANSWER_KEY_MAX),
|
|
957
|
+
),
|
|
958
|
+
},
|
|
959
|
+
{ answer: true },
|
|
960
|
+
);
|
|
961
|
+
const regexProblem = validateAnswerRegex(key, [
|
|
962
|
+
joinAnswerList([questions[i]], [base[i]])[0],
|
|
963
|
+
]);
|
|
964
|
+
if (regexProblem)
|
|
965
|
+
return problemAt(
|
|
966
|
+
{ questionIndex: i, message: a.validation.at(i + 1, regexProblem) },
|
|
967
|
+
{ answer: true },
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
const keyProblem = checkAnswerKeys(questions, answers, keys, a.validation);
|
|
971
|
+
if (keyProblem) return problemAt(keyProblem, { answer: true });
|
|
972
|
+
// 저장된 점수는 저장된 정규식의 문제 id를 따라간다 (문제 순서를 바꿔도 제 문제에)
|
|
973
|
+
const saved = app.grading?.type === PARTIAL ? app.grading : undefined;
|
|
974
|
+
let { scores, resplit } = scoresFor(questions, saved, splitScores);
|
|
975
|
+
if (validatePartialGrading({ answer_key: keys, scores })) {
|
|
976
|
+
scores = splitScores(questions.length);
|
|
977
|
+
resplit = true;
|
|
978
|
+
}
|
|
979
|
+
if (resplit) showNotice({ text: t.scoresSplit(scores) });
|
|
980
|
+
return { type: PARTIAL, answer_key: keys, scores };
|
|
346
981
|
}
|
|
347
982
|
|
|
348
983
|
render();
|
|
984
|
+
// 불러오는 자리에서 내용으로 바뀔 때 살짝 나타나게 (styles.css .qz-enter)
|
|
985
|
+
root.classList.add("qz-enter");
|
|
349
986
|
save = app.useSave({
|
|
350
987
|
label: t.done,
|
|
351
|
-
|
|
352
|
-
|
|
988
|
+
// partial_pattern이면 학생 화면이 답을 문항별 배열로 내도록 공개 값 gradingType을 같이 저장 (정답은 아님)
|
|
989
|
+
getContent: () => {
|
|
990
|
+
const content = structuredClone(draft);
|
|
991
|
+
const images = usedImages();
|
|
992
|
+
if (images) content.images = images;
|
|
993
|
+
else delete content.images;
|
|
994
|
+
if (gradingType === PARTIAL) content.gradingType = PARTIAL;
|
|
995
|
+
else delete content.gradingType;
|
|
996
|
+
return content;
|
|
997
|
+
},
|
|
998
|
+
validate: (content) => {
|
|
353
999
|
const problem = validateQuiz(content, texts.validation);
|
|
354
|
-
|
|
1000
|
+
if (!problem) return true;
|
|
1001
|
+
// 라벨이 없으니 비운 필수 칸(질문)에 빨간 밑줄을 긋고, 걸린 칸에 초점을 둔다
|
|
1002
|
+
form.markEmptyRequired();
|
|
1003
|
+
const invalid = form
|
|
1004
|
+
.cardAt(problem.questionIndex)
|
|
1005
|
+
?.querySelector("[aria-invalid]");
|
|
1006
|
+
if (!invalid) return problemAt(problem);
|
|
1007
|
+
invalid.scrollIntoView({ block: "center" });
|
|
1008
|
+
invalid.focus({ preventScroll: true });
|
|
1009
|
+
return problem.message;
|
|
355
1010
|
},
|
|
356
1011
|
// 정답 → 정답 정규식. 검증(정답 · 지운 보기 → 정규식 공통 검사 → 왕복 · 오답)을 통과해야 저장한다
|
|
357
1012
|
getGrading: () => {
|
|
@@ -359,15 +1014,40 @@ save = app.useSave({
|
|
|
359
1014
|
const { questions } = draft;
|
|
360
1015
|
const missing = validateAnswerKey(questions, answers, a.validation);
|
|
361
1016
|
if (missing) return problemAt(missing, { answer: true });
|
|
1017
|
+
if (gradingType === PARTIAL) return partialGrading(questions);
|
|
362
1018
|
const answerKey = buildAnswerKey(questions, answers);
|
|
363
|
-
|
|
364
|
-
|
|
1019
|
+
// 정답 정규식은 서버 한도(ANSWER_KEY_MAX)가 퀴즈 전체에 걸린다. 한글 주관식은 한 글자가 9자로 늘어
|
|
1020
|
+
// 몇 문항이면 넘으므로, 정규식에서 가장 긴 문항으로 옮기고 무엇을 줄일지 알려 준다
|
|
1021
|
+
if (answerKey.length > ANSWER_KEY_MAX) {
|
|
1022
|
+
const lengths = questions.map(
|
|
1023
|
+
(q) => buildAnswerKey([q], { [q.id]: answers[q.id] }).length,
|
|
1024
|
+
);
|
|
1025
|
+
const longest = lengths.indexOf(Math.max(...lengths));
|
|
1026
|
+
return problemAt(
|
|
1027
|
+
{
|
|
1028
|
+
questionIndex: longest,
|
|
1029
|
+
message: a.validation.at(
|
|
1030
|
+
longest + 1,
|
|
1031
|
+
a.validation.tooLong(answerKey.length, ANSWER_KEY_MAX),
|
|
1032
|
+
),
|
|
1033
|
+
},
|
|
1034
|
+
{ answer: true },
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
const base = questions.map((q) =>
|
|
1038
|
+
q.type === "text" ? (answers[q.id] ?? [])[0] : answers[q.id],
|
|
1039
|
+
);
|
|
1040
|
+
const regexProblem = validateAnswerRegex(answerKey, [
|
|
1041
|
+
joinAnswers(questions, base),
|
|
1042
|
+
]);
|
|
365
1043
|
if (regexProblem) return regexProblem;
|
|
366
|
-
const keyProblem = checkAnswerKey(
|
|
1044
|
+
const keyProblem = checkAnswerKey(
|
|
1045
|
+
questions,
|
|
1046
|
+
answers,
|
|
1047
|
+
answerKey,
|
|
1048
|
+
a.validation,
|
|
1049
|
+
);
|
|
367
1050
|
if (keyProblem) return problemAt(keyProblem, { answer: true });
|
|
368
|
-
|
|
369
|
-
retyped.clear();
|
|
370
|
-
for (const node of root.querySelectorAll('[data-role="type-warning"]')) node.remove();
|
|
371
|
-
return { type: 'pattern', answer_key: answerKey };
|
|
1051
|
+
return { type: "pattern", answer_key: answerKey };
|
|
372
1052
|
},
|
|
373
1053
|
});
|