@eliceio/cdk-cli 1.1.0 → 1.2.1
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 +65 -38
- package/es/cli.js +35 -2
- package/es/commands/create/index.js +2 -2
- package/es/commands/dev/index.d.ts +8 -3
- package/es/commands/dev/index.js +72 -3
- package/es/commands/doctor/index.d.ts +1 -1
- package/es/commands/doctor/index.js +10 -13
- package/es/commands/setup/index.d.ts +1 -1
- package/es/commands/setup/index.js +4 -3
- package/es/commands/uninstall/index.d.ts +1 -1
- package/es/commands/uninstall/index.js +7 -30
- package/es/core/config.d.ts +2 -2
- package/es/core/config.js +2 -2
- package/es/core/skills.d.ts +22 -4
- package/es/core/skills.js +89 -17
- package/es/dev/browser.d.ts +22 -0
- package/es/dev/browser.js +105 -0
- package/es/dev/check.d.ts +84 -0
- package/es/dev/check.js +326 -0
- package/es/dev/host-page.js +10 -0
- package/es/dev/mock-api.js +1 -1
- package/es/dev/server.d.ts +2 -0
- package/es/dev/server.js +1 -0
- package/es/rules/check.js +1 -1
- package/es/rules/manifest.d.ts +1 -1
- package/es/rules/manifest.js +2 -2
- package/es/test-old-skill.d.ts +5 -0
- package/package.json +3 -2
- package/skills/_shared/always.md +13 -5
- package/skills/{elice-content-guide/topics → _shared/references}/00-what-the-person-decides.md +2 -2
- package/skills/{elice-content-guide/topics → _shared/references}/02-design-the-material.md +13 -4
- package/skills/{elice-content-guide/topics → _shared/references}/03-create-the-project.md +2 -2
- package/skills/_shared/references/05-screen-code.md +169 -0
- package/skills/{elice-content-guide/topics → _shared/references}/06-using-the-quiz-template.md +4 -3
- package/skills/{elice-content-guide/topics → _shared/references}/07-move-existing-html.md +1 -1
- package/skills/_shared/references/08-fix-check-errors.md +28 -0
- package/skills/_shared/references/09-check.md +29 -0
- package/skills/_shared/references/10-build.md +8 -0
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +83 -0
- package/skills/elice-content-check/SKILL.md +7 -9
- package/skills/elice-content-create/SKILL.md +12 -10
- package/skills/elice-content-migrate/SKILL.md +10 -8
- package/skills/elice-content-publish/SKILL.md +10 -8
- package/templates/_shared/lib/cdk-mock.d.ts +1 -1
- package/templates/_shared/lib/cdk-mock.js +2 -2
- package/templates/_shared/lib/elice-content.css +1 -1
- package/templates/_shared/lib/elice-content.d.ts +1 -1
- package/templates/_shared/lib/elice-content.js +35 -18
- package/templates/blank/README.md +24 -21
- package/templates/blank/screens/edit.js +1 -1
- package/templates/blank/template.json +1 -1
- package/templates/quiz/README.md +8 -7
- package/templates/quiz/core/editor.js +141 -4
- package/templates/quiz/core/model.js +4 -3
- package/templates/quiz/metadata.json +1 -1
- package/templates/quiz/screens/edit.js +673 -162
- package/templates/quiz/screens/learn.js +1 -1
- package/templates/quiz/styles.css +557 -73
- package/templates/quiz/template.json +2 -2
- package/templates/quiz/ui/templates/edit.d.ts +1 -1
- package/templates/quiz/ui/templates/edit.js +417 -76
- package/templates/quiz/ui/templates/page.js +2 -17
- package/templates/quiz/ui/templates/question.js +1 -1
- package/templates/quiz/ui/texts.js +40 -27
- package/skills/elice-content-guide/SKILL.md +0 -42
- package/skills/elice-content-guide/topics/05-screen-code.md +0 -132
- package/skills/elice-content-guide/topics/08-fix-check-errors.md +0 -27
- package/skills/elice-content-guide/topics/09-check.md +0 -11
- package/skills/elice-content-guide/topics/10-build.md +0 -8
- package/skills/elice-content-guide/topics/12-upload-with-the-material-mcp.md +0 -41
- package/templates/quiz/instructor.html +0 -17
- package/templates/quiz/screens/instructor.js +0 -33
- /package/skills/{elice-content-guide/topics → _shared/references}/01-check-the-environment.md +0 -0
- /package/skills/{elice-content-guide/topics → _shared/references}/04-rules.md +0 -0
- /package/skills/{elice-content-guide/topics → _shared/references}/11-more.md +0 -0
|
@@ -1,47 +1,79 @@
|
|
|
1
1
|
// 내용 편집 화면(CMS). 기존 퀴즈 편집 폼을 옮김 (docs/quiz-spec.md §3). 저장 버튼 · 변경 표시는 키트(useSave)가 합니다.
|
|
2
|
-
// 퀴즈는 채점 방식 pattern 고정 (ADR 0009, 완료 정책은 LXP 설정
|
|
2
|
+
// 퀴즈는 채점 방식 pattern 고정 (ADR 0009, 완료 정책은 LXP 자료 편집 화면의 '설정'에서 교육자가 고름, ADR 0012): 문항 카드마다 정답을
|
|
3
3
|
// 고르고 (단일 · 복수 · 그룹은 보기 줄에서 바로, 순서 · 주관식은 아래 "정답"에서), 저장할 때 고른 답으로 정답 정규식 하나를 만들어 검증한 뒤 settings.grading에 함께 저장합니다.
|
|
4
4
|
// 문제 내용(content)은 학생에게도 내려가므로 정답을 넣지 않습니다 (정답은 grading에만, 서버가 학생에게 내려주지 않음).
|
|
5
5
|
// 여기서는 어떤 칸을 어떤 순서로 놓을지만 정합니다. 모양은 ui/(templates/edit.js · texts · theme.css), 동작은 core/.
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import {
|
|
7
|
+
ANSWER_KEY_MAX,
|
|
8
|
+
start,
|
|
9
|
+
validateAnswerRegex,
|
|
10
|
+
} from "../lib/elice-content.js";
|
|
11
|
+
import { renderAnswerBody } from "../core/behaviors.js";
|
|
12
|
+
import { createEditor } from "../core/editor.js";
|
|
9
13
|
import {
|
|
10
14
|
buildAnswerKey,
|
|
11
15
|
canAddQuestion,
|
|
12
16
|
checkAnswerKey,
|
|
13
|
-
convertType,
|
|
14
17
|
INLINE_ANSWER_TYPES,
|
|
15
18
|
isAnswered,
|
|
16
19
|
joinAnswers,
|
|
17
20
|
LIMITS,
|
|
18
21
|
newQuestion,
|
|
22
|
+
nextId,
|
|
19
23
|
optionAnswer,
|
|
20
24
|
parseAnswerKey,
|
|
21
25
|
pruneAnswer,
|
|
22
26
|
validateAnswerKey,
|
|
23
27
|
validateQuiz,
|
|
24
28
|
withOptionAnswer,
|
|
25
|
-
} from
|
|
26
|
-
import * as templates from
|
|
27
|
-
import { templates as quizTemplates } from
|
|
28
|
-
import { loading } from
|
|
29
|
-
import { texts } from
|
|
29
|
+
} from "../core/model.js";
|
|
30
|
+
import * as templates from "../ui/templates/edit.js";
|
|
31
|
+
import { templates as quizTemplates } from "../ui/templates/index.js";
|
|
32
|
+
import { loading } from "../ui/templates/page.js";
|
|
33
|
+
import { texts } from "../ui/texts.js";
|
|
30
34
|
|
|
31
35
|
const t = texts.edit;
|
|
32
36
|
const a = texts.answers;
|
|
33
|
-
const root = document.getElementById(
|
|
37
|
+
const root = document.getElementById("app");
|
|
34
38
|
document.title = texts.page.edit;
|
|
35
39
|
root.replaceChildren(loading());
|
|
36
|
-
const app = await start({ screen:
|
|
40
|
+
const app = await start({ screen: "edit" });
|
|
37
41
|
const draft = structuredClone(app.content);
|
|
38
42
|
draft.questions ??= [];
|
|
43
|
+
// 처음 열면 문항 1이 이미 있는 상태로 시작한다
|
|
44
|
+
const startedEmpty = draft.questions.length === 0;
|
|
45
|
+
if (startedEmpty)
|
|
46
|
+
draft.questions.push(newQuestion("select_one", [], texts.defaults));
|
|
39
47
|
|
|
40
48
|
// 문항 id → 정답(화면 값: 선택 id · id 목록 · 그룹별 목록, 주관식은 허용 답 목록). 저장된 정규식을 읽어 채운다
|
|
41
49
|
const savedKey = app.grading?.answer_key;
|
|
42
50
|
const parsed = savedKey ? parseAnswerKey(draft.questions, savedKey) : {};
|
|
43
51
|
/** @type {Record<string, unknown>} */
|
|
44
52
|
const answers = parsed ?? {};
|
|
53
|
+
/** 새 문항의 기본 정답: 첫 번째 보기 하나 (단일 · 복수 선택만, 나머지 유형은 직접 고른다) */
|
|
54
|
+
function defaultAnswer(q) {
|
|
55
|
+
const first = q.options?.[0]?.id;
|
|
56
|
+
if (first === undefined) return undefined;
|
|
57
|
+
if (q.type === "select_one") return first;
|
|
58
|
+
if (q.type === "select_multiple") return [first];
|
|
59
|
+
// 순서 맞추기: 적은 순서가 곧 정답 순서
|
|
60
|
+
if (q.type === "order") return q.options.map((o) => o.id);
|
|
61
|
+
if (q.type === "group") {
|
|
62
|
+
// 보기 1 → 그룹 A, 보기 2 → 그룹 B처럼 하나씩 배정해 시작한다
|
|
63
|
+
const out = Object.fromEntries(q.groups.map((g) => [g.id, []]));
|
|
64
|
+
q.groups.forEach((g, k) => {
|
|
65
|
+
if (q.options[k]) out[g.id].push(q.options[k].id);
|
|
66
|
+
});
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
// 처음 열어 자동으로 만든 문항 1은 첫 번째 보기가 정답으로 선택된 채 시작한다 (저장된 정답이 있으면 그대로)
|
|
72
|
+
if (startedEmpty && !savedKey) {
|
|
73
|
+
const first = draft.questions[0];
|
|
74
|
+
const picked = defaultAnswer(first);
|
|
75
|
+
if (picked !== undefined) answers[first.id] = picked;
|
|
76
|
+
}
|
|
45
77
|
const unreadable = Boolean(savedKey) && parsed === null;
|
|
46
78
|
// 순서 맞추기 정답 칸 (문항 id → 화면). 끌어 놓기는 window에서 끝나 이벤트로 읽으면 마지막 놓기를 놓치므로,
|
|
47
79
|
// 값이 필요할 때(저장 · 다시 그리기 · 보기 삭제) 칸에서 바로 읽는다
|
|
@@ -49,8 +81,6 @@ const answerViews = new Map();
|
|
|
49
81
|
const readAnswerViews = () => {
|
|
50
82
|
for (const [id, view] of answerViews) answers[id] = view.getValue();
|
|
51
83
|
};
|
|
52
|
-
// 유형을 바꿔 정답을 다시 골라야 하는 문항 id (다음 저장까지 카드 위에 알림)
|
|
53
|
-
const retyped = new Set();
|
|
54
84
|
|
|
55
85
|
const form = createEditor({
|
|
56
86
|
rerender: render,
|
|
@@ -69,25 +99,399 @@ const swap = (list, i, j) => {
|
|
|
69
99
|
render();
|
|
70
100
|
};
|
|
71
101
|
|
|
102
|
+
/** 오답 보기 상자를 열어 둔 문항 id. 열려 있으면 보기가 없어도 상자가 남고, 머리줄의 ✕로만 닫는다 */
|
|
103
|
+
const noneOpen = new Set();
|
|
104
|
+
|
|
105
|
+
/** 그룹 상자 q.groups[].id(오답은 "")에 들어 있는 보기들 (보기 목록의 순서 그대로) */
|
|
106
|
+
function groupMembers(q, gid) {
|
|
107
|
+
const value = answers[q.id] ?? {};
|
|
108
|
+
const assigned = new Set(Object.values(value).flat());
|
|
109
|
+
return q.options.filter((o) =>
|
|
110
|
+
gid === "" ? !assigned.has(o.id) : (value[gid] ?? []).includes(o.id),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 보기를 toGroup 상자로 옮긴다 (beforeId 보기 앞에, 없으면 그 상자의 맨 끝에). 정답은 상자로 정해지므로 정답도 같이 바뀐다 */
|
|
115
|
+
function moveItem(q, optionId, toGroup, beforeId) {
|
|
116
|
+
answers[q.id] = withOptionAnswer(q, answers[q.id] ?? {}, optionId, toGroup);
|
|
117
|
+
const [opt] = q.options.splice(
|
|
118
|
+
q.options.findIndex((o) => o.id === optionId),
|
|
119
|
+
1,
|
|
120
|
+
);
|
|
121
|
+
let at = beforeId ? q.options.findIndex((o) => o.id === beforeId) : -1;
|
|
122
|
+
if (at < 0) {
|
|
123
|
+
const mine = new Set(groupMembers(q, toGroup).map((o) => o.id));
|
|
124
|
+
let last = -1;
|
|
125
|
+
q.options.forEach((o, i) => {
|
|
126
|
+
if (mine.has(o.id)) last = i;
|
|
127
|
+
});
|
|
128
|
+
at = last < 0 ? q.options.length : last + 1;
|
|
129
|
+
}
|
|
130
|
+
q.options.splice(at, 0, opt);
|
|
131
|
+
render();
|
|
132
|
+
root.querySelector(`[data-option-handle="${optionId}"]`)?.focus();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 키보드 ↑ · ↓: 상자 안에서 한 칸, 끝에서는 이웃 상자로 (마지막 그룹 아래는 오답 보기) */
|
|
136
|
+
function keyMove(q, optionId, gid, dir) {
|
|
137
|
+
const boxIds = [...q.groups.map((g) => g.id), ""];
|
|
138
|
+
const items = groupMembers(q, gid);
|
|
139
|
+
const idx = items.findIndex((o) => o.id === optionId);
|
|
140
|
+
if (dir < 0) {
|
|
141
|
+
if (idx > 0) return moveItem(q, optionId, gid, items[idx - 1].id);
|
|
142
|
+
const prev = boxIds[boxIds.indexOf(gid) - 1];
|
|
143
|
+
if (prev !== undefined) moveItem(q, optionId, prev, null);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (idx < items.length - 1)
|
|
147
|
+
return moveItem(q, optionId, gid, items[idx + 2]?.id ?? null);
|
|
148
|
+
const next = boxIds[boxIds.indexOf(gid) + 1];
|
|
149
|
+
if (next !== undefined)
|
|
150
|
+
moveItem(q, optionId, next, groupMembers(q, next)[0]?.id ?? null);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 그룹 분류 편집판 (그룹별 상자): 그룹마다 상자가 있고 그 안에 보기를 적는다. 어느 그룹에도 속하지 않는 보기는
|
|
155
|
+
* "오답 보기" 상자 (없으면 "오답 보기 추가" 버튼만). 보기는 손잡이를 끌어 다른 상자로 옮긴다.
|
|
156
|
+
* 저장하는 정답은 그룹별 보기 목록 그대로라 데이터는 바뀌지 않는다
|
|
157
|
+
*/
|
|
158
|
+
function groupBoard(q, shuffle) {
|
|
159
|
+
const fullOptions = q.options.length >= LIMITS.optionsMax;
|
|
160
|
+
const canDeleteOption = q.options.length > LIMITS.optionsMin;
|
|
161
|
+
|
|
162
|
+
const addOption = (gid) => {
|
|
163
|
+
const opt = { id: nextId(q.options.map((o) => o.id)), text: "" };
|
|
164
|
+
q.options.push(opt);
|
|
165
|
+
if (!gid) noneOpen.add(q.id);
|
|
166
|
+
if (gid) answers[q.id] = withOptionAnswer(q, answers[q.id] ?? {}, opt.id, gid);
|
|
167
|
+
render();
|
|
168
|
+
root.querySelector(`[data-option="${opt.id}"] [data-role="input"]`)?.focus();
|
|
169
|
+
};
|
|
170
|
+
const addButton = (gid) => {
|
|
171
|
+
const add = templates.addButton({
|
|
172
|
+
kind: "option",
|
|
173
|
+
full: fullOptions,
|
|
174
|
+
max: LIMITS.optionsMax,
|
|
175
|
+
});
|
|
176
|
+
add.addEventListener("click", () => addOption(gid));
|
|
177
|
+
return add;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const rowFor = (o, gid) => {
|
|
181
|
+
const row = templates.row({
|
|
182
|
+
kind: "option",
|
|
183
|
+
index: q.options.indexOf(o),
|
|
184
|
+
canDelete: canDeleteOption,
|
|
185
|
+
min: LIMITS.optionsMin,
|
|
186
|
+
numbered: false,
|
|
187
|
+
});
|
|
188
|
+
row.dataset.role = "row";
|
|
189
|
+
row.dataset.option = o.id;
|
|
190
|
+
const input = row.querySelector('[data-role="input"]');
|
|
191
|
+
input.value = o.text;
|
|
192
|
+
input.addEventListener("input", () => {
|
|
193
|
+
o.text = input.value;
|
|
194
|
+
});
|
|
195
|
+
row.querySelector('[data-role="delete"]').addEventListener("click", () => {
|
|
196
|
+
q.options.splice(q.options.indexOf(o), 1);
|
|
197
|
+
answers[q.id] = pruneAnswer(q, answers[q.id] ?? {});
|
|
198
|
+
render();
|
|
199
|
+
});
|
|
200
|
+
const handle = row.querySelector('[data-role="handle"]');
|
|
201
|
+
handle.dataset.optionHandle = o.id;
|
|
202
|
+
form.dragAcross(handle, row, {
|
|
203
|
+
boxSelector: "[data-group-box]",
|
|
204
|
+
onDrop: (box, before) =>
|
|
205
|
+
moveItem(q, o.id, box.dataset.group, before?.dataset.option ?? null),
|
|
206
|
+
onKey: (dir) => keyMove(q, o.id, gid, dir),
|
|
207
|
+
});
|
|
208
|
+
return row;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const boxes = q.groups.map((g, gi) => {
|
|
212
|
+
const box = templates.groupBox({
|
|
213
|
+
letter: String.fromCharCode(65 + gi),
|
|
214
|
+
canDelete: q.groups.length > LIMITS.groupsMin,
|
|
215
|
+
nameLabel: t.groupName(gi + 1),
|
|
216
|
+
namePlaceholder: t.group(gi + 1),
|
|
217
|
+
deleteLabel: t.groupDelete(gi + 1),
|
|
218
|
+
deleteTitle: t.groupsMin(LIMITS.groupsMin),
|
|
219
|
+
rows: groupMembers(q, g.id).map((o) => rowFor(o, g.id)),
|
|
220
|
+
add: addButton(g.id),
|
|
221
|
+
});
|
|
222
|
+
box.dataset.group = g.id;
|
|
223
|
+
const name = box.querySelector('[data-role="group-name"]');
|
|
224
|
+
name.value = g.name;
|
|
225
|
+
name.addEventListener("input", () => {
|
|
226
|
+
g.name = name.value;
|
|
227
|
+
});
|
|
228
|
+
// 지운 그룹에 넣은 보기는 오답 보기로
|
|
229
|
+
box.querySelector('[data-role="group-delete"]').addEventListener("click", () => {
|
|
230
|
+
q.groups.splice(gi, 1);
|
|
231
|
+
answers[q.id] = pruneAnswer(q, answers[q.id] ?? {});
|
|
232
|
+
render();
|
|
233
|
+
});
|
|
234
|
+
return box;
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const addGroup = templates.addButton({
|
|
238
|
+
kind: "group",
|
|
239
|
+
full: q.groups.length >= LIMITS.groupsMax,
|
|
240
|
+
max: LIMITS.groupsMax,
|
|
241
|
+
});
|
|
242
|
+
addGroup.addEventListener("click", () => {
|
|
243
|
+
q.groups.push({
|
|
244
|
+
id: nextId(q.groups.map((g) => g.id), "g"),
|
|
245
|
+
name: texts.defaults.group(String.fromCharCode(65 + q.groups.length)),
|
|
246
|
+
});
|
|
247
|
+
render();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const none = noneArea(q, {
|
|
251
|
+
items: groupMembers(q, ""),
|
|
252
|
+
rowFor: (o) => rowFor(o, ""),
|
|
253
|
+
addOption,
|
|
254
|
+
addButton,
|
|
255
|
+
fullOptions,
|
|
256
|
+
hint: t.noneHint,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
return form.ui.section({
|
|
260
|
+
label: t.groupBoard,
|
|
261
|
+
hint: a.hint.group,
|
|
262
|
+
hintInline: true,
|
|
263
|
+
action: shuffle,
|
|
264
|
+
body: templates.groupBoard({ boxes, add: addGroup, none }),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* 오답 보기 영역 (그룹 분류 · 순서 맞추기 공통): 보기가 있거나 열어 둔 문항이면 점선 상자, 아니면 "오답 보기 추가 +" 버튼.
|
|
270
|
+
* 머리줄의 ✕로 상자를 닫으면 안의 오답 보기도 함께 지운다 (있었다면 되돌리기 알림)
|
|
271
|
+
*/
|
|
272
|
+
function noneArea(q, { items, rowFor, addOption, addButton, fullOptions, hint }) {
|
|
273
|
+
if (items.length) noneOpen.add(q.id);
|
|
274
|
+
if (!noneOpen.has(q.id)) {
|
|
275
|
+
const none = templates.noneAdd();
|
|
276
|
+
const button = none.querySelector('[data-role="none-add"]');
|
|
277
|
+
button.disabled = fullOptions;
|
|
278
|
+
button.addEventListener("click", () => addOption(""));
|
|
279
|
+
return none;
|
|
280
|
+
}
|
|
281
|
+
const canClose = q.options.length - items.length >= LIMITS.optionsMin;
|
|
282
|
+
const none = templates.noneBox({
|
|
283
|
+
rows: items.map((o) => rowFor(o)),
|
|
284
|
+
add: addButton(""),
|
|
285
|
+
hint,
|
|
286
|
+
canClose,
|
|
287
|
+
closeTitle: t.optionsMin(LIMITS.optionsMin),
|
|
288
|
+
});
|
|
289
|
+
none.dataset.group = "";
|
|
290
|
+
none.querySelector('[data-role="none-close"]').addEventListener("click", () => {
|
|
291
|
+
const prev = {
|
|
292
|
+
options: structuredClone(q.options),
|
|
293
|
+
answer: structuredClone(answers[q.id]),
|
|
294
|
+
};
|
|
295
|
+
const ids = new Set(items.map((o) => o.id));
|
|
296
|
+
q.options = q.options.filter((o) => !ids.has(o.id));
|
|
297
|
+
noneOpen.delete(q.id);
|
|
298
|
+
render();
|
|
299
|
+
if (ids.size)
|
|
300
|
+
showSnackbar(t.noneDeleted(ids.size), () => {
|
|
301
|
+
q.options = prev.options;
|
|
302
|
+
if (prev.answer !== undefined) answers[q.id] = prev.answer;
|
|
303
|
+
noneOpen.add(q.id);
|
|
304
|
+
render();
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
return none;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ---- 순서 맞추기: 정답 순서 = answers[q.id] (보기 id의 순서), 순서에 들어가지 않은 보기 = 오답 보기 ----
|
|
311
|
+
|
|
312
|
+
/** 정답 순서에 들어 있는 보기 id들 (지운 보기는 뺌) */
|
|
313
|
+
function orderIds(q) {
|
|
314
|
+
const exists = new Set(q.options.map((o) => o.id));
|
|
315
|
+
return (answers[q.id] ?? []).filter((id) => exists.has(id));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** 정답 순서의 칸 수는 순서 목록의 길이 (학생 화면의 답안 칸 수) */
|
|
319
|
+
function syncSlots(q) {
|
|
320
|
+
q.slots = Math.max(1, orderIds(q).length);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** 보기를 정답 순서("order") 또는 오답 보기("")로 옮긴다 (순서 목록에서는 beforeId 보기 앞에, 없으면 맨 끝) */
|
|
324
|
+
function moveOrderItem(q, optionId, to, beforeId) {
|
|
325
|
+
const ids = orderIds(q).filter((id) => id !== optionId);
|
|
326
|
+
if (to === "order") {
|
|
327
|
+
const at = beforeId ? ids.indexOf(beforeId) : -1;
|
|
328
|
+
ids.splice(at < 0 ? ids.length : at, 0, optionId);
|
|
329
|
+
}
|
|
330
|
+
answers[q.id] = ids;
|
|
331
|
+
syncSlots(q);
|
|
332
|
+
render();
|
|
333
|
+
root.querySelector(`[data-option-handle="${optionId}"]`)?.focus();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** 키보드 ↑ · ↓: 순서 목록 안에서 한 칸, 맨 아래에서 ↓는 오답 보기로, 오답 보기에서 ↑는 순서 목록 맨 끝으로 */
|
|
337
|
+
function orderKeyMove(q, optionId, box, dir) {
|
|
338
|
+
const ids = orderIds(q);
|
|
339
|
+
if (box === "") {
|
|
340
|
+
if (dir < 0) moveOrderItem(q, optionId, "order", null);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const idx = ids.indexOf(optionId);
|
|
344
|
+
if (dir < 0) {
|
|
345
|
+
if (idx > 0) moveOrderItem(q, optionId, "order", ids[idx - 1]);
|
|
346
|
+
} else if (idx < ids.length - 1)
|
|
347
|
+
moveOrderItem(q, optionId, "order", ids[idx + 2] ?? null);
|
|
348
|
+
else moveOrderItem(q, optionId, "", null);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* 순서 맞추기 편집판 (Zep 순서맞추기와 같은 방식): 보기를 정답 순서대로 번호 목록에 적으면 그 순서가 정답이다.
|
|
353
|
+
* 순서에 넣지 않을 보기는 "오답 보기" 상자에 둔다. 손잡이를 끌어 순서를 바꾸고 두 곳 사이를 옮긴다
|
|
354
|
+
*/
|
|
355
|
+
function orderBoard(q, shuffle) {
|
|
356
|
+
const fullOptions = q.options.length >= LIMITS.optionsMax;
|
|
357
|
+
const canDeleteOption = q.options.length > LIMITS.optionsMin;
|
|
358
|
+
|
|
359
|
+
const addOption = (box) => {
|
|
360
|
+
const opt = { id: nextId(q.options.map((o) => o.id)), text: "" };
|
|
361
|
+
q.options.push(opt);
|
|
362
|
+
if (box === "order") {
|
|
363
|
+
answers[q.id] = [...orderIds(q), opt.id];
|
|
364
|
+
syncSlots(q);
|
|
365
|
+
} else noneOpen.add(q.id);
|
|
366
|
+
render();
|
|
367
|
+
root.querySelector(`[data-option="${opt.id}"] [data-role="input"]`)?.focus();
|
|
368
|
+
};
|
|
369
|
+
const addButton = (box) => {
|
|
370
|
+
const add = templates.addButton({
|
|
371
|
+
kind: "option",
|
|
372
|
+
full: fullOptions,
|
|
373
|
+
max: LIMITS.optionsMax,
|
|
374
|
+
});
|
|
375
|
+
add.addEventListener("click", () => addOption(box));
|
|
376
|
+
return add;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const rowFor = (o, box, index) => {
|
|
380
|
+
const row = templates.row({
|
|
381
|
+
kind: "option",
|
|
382
|
+
index,
|
|
383
|
+
canDelete: canDeleteOption,
|
|
384
|
+
min: LIMITS.optionsMin,
|
|
385
|
+
numbered: box === "order",
|
|
386
|
+
});
|
|
387
|
+
row.dataset.role = "row";
|
|
388
|
+
row.dataset.option = o.id;
|
|
389
|
+
const input = row.querySelector('[data-role="input"]');
|
|
390
|
+
input.value = o.text;
|
|
391
|
+
input.addEventListener("input", () => {
|
|
392
|
+
o.text = input.value;
|
|
393
|
+
});
|
|
394
|
+
row.querySelector('[data-role="delete"]').addEventListener("click", () => {
|
|
395
|
+
q.options.splice(q.options.indexOf(o), 1);
|
|
396
|
+
answers[q.id] = orderIds(q);
|
|
397
|
+
syncSlots(q);
|
|
398
|
+
render();
|
|
399
|
+
});
|
|
400
|
+
const handle = row.querySelector('[data-role="handle"]');
|
|
401
|
+
handle.dataset.optionHandle = o.id;
|
|
402
|
+
form.dragAcross(handle, row, {
|
|
403
|
+
boxSelector: "[data-group-box]",
|
|
404
|
+
onDrop: (target, before) =>
|
|
405
|
+
moveOrderItem(q, o.id, target.dataset.group, before?.dataset.option ?? null),
|
|
406
|
+
onKey: (dir) => orderKeyMove(q, o.id, box, dir),
|
|
407
|
+
});
|
|
408
|
+
return row;
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const byId = new Map(q.options.map((o) => [o.id, o]));
|
|
412
|
+
const ordered = orderIds(q).map((id) => byId.get(id));
|
|
413
|
+
const inOrder = new Set(ordered.map((o) => o.id));
|
|
414
|
+
const list = templates.orderList({
|
|
415
|
+
rows: ordered.map((o, i) => rowFor(o, "order", i)),
|
|
416
|
+
add: addButton("order"),
|
|
417
|
+
});
|
|
418
|
+
const none = noneArea(q, {
|
|
419
|
+
items: q.options.filter((o) => !inOrder.has(o.id)),
|
|
420
|
+
rowFor: (o) => rowFor(o, "", q.options.indexOf(o)),
|
|
421
|
+
addOption,
|
|
422
|
+
addButton,
|
|
423
|
+
fullOptions,
|
|
424
|
+
hint: t.noneHintOrder,
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
return form.ui.section({
|
|
428
|
+
label: t.orderTitle,
|
|
429
|
+
hint: a.hint.order,
|
|
430
|
+
hintInline: true,
|
|
431
|
+
action: shuffle,
|
|
432
|
+
body: templates.orderBoard({ list, none }),
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
72
436
|
/** 순서 · 주관식 문항 카드의 "정답": 학생 화면과 같은 보기 · 칸으로 고른다 (주관식은 허용 답 여러 개) */
|
|
73
437
|
function answerField(q) {
|
|
74
|
-
if (q.type ===
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
answers[q.id] =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
438
|
+
if (q.type === "text") {
|
|
439
|
+
// 정답 목록: 줄마다 밑줄 칸 하나, 유사 정답은 "+ 유사 정답 추가"로 늘린다.
|
|
440
|
+
// 저장하는 값은 앞뒤 공백을 자른 비어 있지 않은 답의 목록 (칸은 비어 있어도 목록에는 넣지 않음)
|
|
441
|
+
const rows = (answers[q.id] ?? []).length ? [...answers[q.id]] : [""];
|
|
442
|
+
const body = document.createElement("div");
|
|
443
|
+
const sync = () => {
|
|
444
|
+
answers[q.id] = rows.map((v) => v.trim()).filter(Boolean);
|
|
445
|
+
};
|
|
446
|
+
const paint = (focusAt) => {
|
|
447
|
+
const nodes = rows.map((value, i) => {
|
|
448
|
+
const row = templates.textAnswerRow({ index: i, canDelete: rows.length > 1 });
|
|
449
|
+
const input = row.querySelector('[data-role="input"]');
|
|
450
|
+
input.value = value;
|
|
451
|
+
input.addEventListener("input", () => {
|
|
452
|
+
rows[i] = input.value;
|
|
453
|
+
sync();
|
|
454
|
+
});
|
|
455
|
+
// Enter: 다음 칸으로 (마지막이면 새 칸). 한글 조합 중의 Enter는 무시
|
|
456
|
+
input.addEventListener("keydown", (e) => {
|
|
457
|
+
if (e.key !== "Enter" || e.isComposing) return;
|
|
458
|
+
e.preventDefault();
|
|
459
|
+
if (i === rows.length - 1) rows.push("");
|
|
460
|
+
paint(i + 1);
|
|
461
|
+
});
|
|
462
|
+
row.querySelector('[data-role="delete"]').addEventListener("click", () => {
|
|
463
|
+
rows.splice(i, 1);
|
|
464
|
+
sync();
|
|
465
|
+
paint(Math.min(i, rows.length - 1));
|
|
466
|
+
});
|
|
467
|
+
return row;
|
|
468
|
+
});
|
|
469
|
+
const add = templates.textAnswerAdd();
|
|
470
|
+
add.addEventListener("click", () => {
|
|
471
|
+
rows.push("");
|
|
472
|
+
paint(rows.length - 1);
|
|
473
|
+
});
|
|
474
|
+
body.replaceChildren(templates.textAnswers({ rows: nodes, add }));
|
|
475
|
+
if (focusAt !== undefined)
|
|
476
|
+
body.querySelectorAll('[data-role="input"]')[focusAt]?.focus();
|
|
477
|
+
};
|
|
478
|
+
paint();
|
|
479
|
+
return form.ui.section({
|
|
480
|
+
label: a.label,
|
|
481
|
+
hint: a.hint.text,
|
|
482
|
+
hintInline: true,
|
|
483
|
+
body,
|
|
84
484
|
});
|
|
85
|
-
return form.ui.section({ label: a.label, hint: a.hint.text, body: node });
|
|
86
485
|
}
|
|
87
486
|
const view = renderAnswerBody(q, { templates: quizTemplates });
|
|
88
487
|
if (answers[q.id] !== undefined) view.setValue(answers[q.id]);
|
|
89
488
|
answerViews.set(q.id, view);
|
|
90
|
-
return form.ui.section({
|
|
489
|
+
return form.ui.section({
|
|
490
|
+
label: a.label,
|
|
491
|
+
hint: a.hint[q.type],
|
|
492
|
+
hintInline: true,
|
|
493
|
+
body: view.el,
|
|
494
|
+
});
|
|
91
495
|
}
|
|
92
496
|
|
|
93
497
|
/**
|
|
@@ -95,14 +499,20 @@ function answerField(q) {
|
|
|
95
499
|
* 순서를 바꿔도 그대로이고, 보기를 지우면 정답에서 뺀다 (optionsOpts의 onDelete)
|
|
96
500
|
*/
|
|
97
501
|
function inlineAnswer(q) {
|
|
98
|
-
const types = {
|
|
502
|
+
const types = {
|
|
503
|
+
select_one: "radio",
|
|
504
|
+
select_multiple: "checkbox",
|
|
505
|
+
group: "select",
|
|
506
|
+
};
|
|
99
507
|
return {
|
|
100
508
|
type: types[q.type],
|
|
101
509
|
// 문항마다 다른 이름 (같은 문항의 radio끼리만 묶임)
|
|
102
510
|
name: `answer-${q.id}`,
|
|
103
|
-
choices:
|
|
104
|
-
|
|
105
|
-
|
|
511
|
+
choices:
|
|
512
|
+
q.type === "group" ? q.groups.map((g) => [g.id, g.name]) : undefined,
|
|
513
|
+
get: (option) => optionAnswer(q, answers[q.id], option.id),
|
|
514
|
+
set: (option, value) =>
|
|
515
|
+
(answers[q.id] = withOptionAnswer(q, answers[q.id], option.id, value)),
|
|
106
516
|
};
|
|
107
517
|
}
|
|
108
518
|
|
|
@@ -112,12 +522,14 @@ function optionsOpts(q) {
|
|
|
112
522
|
return {
|
|
113
523
|
// 순서 맞추기 칸 수를 따로 정하지 않았으면(보기 수와 같음) 보기를 더할 때 같이 늘린다
|
|
114
524
|
onAdd: () => {
|
|
115
|
-
if (q.type ===
|
|
525
|
+
if (q.type === "order" && q.slots === q.options.length - 1)
|
|
526
|
+
q.slots = q.options.length;
|
|
116
527
|
},
|
|
117
528
|
onDelete: () => {
|
|
118
529
|
readAnswerViews();
|
|
119
|
-
if (q.type ===
|
|
120
|
-
if (answers[q.id] !== undefined)
|
|
530
|
+
if (q.type === "order") q.slots = Math.min(q.slots, q.options.length);
|
|
531
|
+
if (answers[q.id] !== undefined)
|
|
532
|
+
answers[q.id] = pruneAnswer(q, answers[q.id]);
|
|
121
533
|
// 다시 그릴 때 지우기 전 칸 값으로 덮지 않게
|
|
122
534
|
answerViews.delete(q.id);
|
|
123
535
|
},
|
|
@@ -131,95 +543,111 @@ function optionsOpts(q) {
|
|
|
131
543
|
}
|
|
132
544
|
: undefined,
|
|
133
545
|
answer: inline ? inlineAnswer(q) : undefined,
|
|
546
|
+
// 단일 · 복수 선택은 정답 체크가 있어 번호를 두지 않는다 (순서 맞추기 · 그룹 분류는 번호 유지)
|
|
547
|
+
numbered: q.type !== "select_one" && q.type !== "select_multiple",
|
|
134
548
|
};
|
|
135
549
|
}
|
|
136
550
|
|
|
137
551
|
/** 정답을 고르는 묶음 (저장하지 못한 정답 문제를 여기에 표시) */
|
|
138
|
-
const answerArea = section => {
|
|
139
|
-
section.dataset.role =
|
|
552
|
+
const answerArea = (section) => {
|
|
553
|
+
section.dataset.role = "answers";
|
|
140
554
|
return section;
|
|
141
555
|
};
|
|
142
556
|
|
|
143
557
|
/** 문항 카드 안의 칸들. 유형마다 보이는 칸이 다르다 */
|
|
144
558
|
function questionFields(q, i) {
|
|
559
|
+
// 보기 순서 섞기: 보기 제목줄 오른쪽 (주관식은 보기가 없음)
|
|
560
|
+
const shuffle =
|
|
561
|
+
q.type === "text"
|
|
562
|
+
? undefined
|
|
563
|
+
: form.toggle(
|
|
564
|
+
t.shuffle,
|
|
565
|
+
q.shuffle,
|
|
566
|
+
(v) => (q.shuffle = v),
|
|
567
|
+
t.shuffleHint,
|
|
568
|
+
"shuffle",
|
|
569
|
+
);
|
|
145
570
|
const body = [
|
|
146
|
-
|
|
147
|
-
form.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
571
|
+
// 질문 · 설명: 라벨 없이 바로 쓰는 칸 (퀴즈 제목 · 안내와 같은 방식, 화면 낭독기용 이름은 aria-label)
|
|
572
|
+
form.inlineField(t.title, q.title, (v) => (q.title = v), {
|
|
573
|
+
placeholder: t.titlePlaceholder,
|
|
574
|
+
size: "question",
|
|
575
|
+
required: true,
|
|
576
|
+
max: LIMITS.titleMax,
|
|
577
|
+
// 질문은 1000자까지라 글자 수 표시는 두지 않는다 (입력 제한은 그대로)
|
|
578
|
+
showCount: false,
|
|
152
579
|
}),
|
|
580
|
+
// 문항 설명: 필요할 때만 "설명 추가 +"로 연다. 열리면 해설과 같은 머리줄(아이콘 · 이름 · 지우기). 새 문항에는 키가 없고, 적으면 생긴다
|
|
581
|
+
form.revealable(
|
|
582
|
+
t.addDescription,
|
|
583
|
+
form.inlineField(
|
|
584
|
+
t.description,
|
|
585
|
+
q.description ?? "",
|
|
586
|
+
(v) => (q.description = v),
|
|
587
|
+
{
|
|
588
|
+
placeholder: t.descriptionPlaceholder,
|
|
589
|
+
multiline: true,
|
|
590
|
+
},
|
|
591
|
+
),
|
|
592
|
+
{ open: Boolean(q.description), title: t.description, icon: "align" },
|
|
593
|
+
),
|
|
153
594
|
];
|
|
154
|
-
if (q.type ===
|
|
155
|
-
const options = form.itemList(
|
|
156
|
-
const section = form.ui.section({
|
|
157
|
-
label: t.options,
|
|
158
|
-
hint: q.type === 'order' ? undefined : a.hint[q.type],
|
|
159
|
-
body: options,
|
|
160
|
-
});
|
|
161
|
-
body.push(q.type === 'order' ? section : answerArea(section));
|
|
162
|
-
}
|
|
163
|
-
if (q.type === 'order') {
|
|
164
|
-
const slots = form.numberField(
|
|
165
|
-
t.slots,
|
|
166
|
-
t.slotsHint,
|
|
167
|
-
q.slots,
|
|
168
|
-
q.options.length,
|
|
169
|
-
v => (q.slots = v)
|
|
170
|
-
);
|
|
171
|
-
// 칸 수가 바뀌면 정답 칸도 다시 그린다 (입력하는 동안이 아니라 확정했을 때)
|
|
172
|
-
slots.querySelector('[data-role="input"]')?.addEventListener('change', render);
|
|
173
|
-
body.push(slots);
|
|
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]);
|
|
180
|
-
},
|
|
181
|
-
// 그룹 이름을 고치면 보기 줄의 그룹 고르기 이름도 바로 바꾼다 (다시 그리면 입력 중 초점을 잃음)
|
|
182
|
-
onInput: g => {
|
|
183
|
-
for (const select of root.querySelectorAll(`select[name="answer-${q.id}"]`))
|
|
184
|
-
for (const option of select.options) if (option.value === g.id) option.textContent = g.name;
|
|
185
|
-
},
|
|
186
|
-
});
|
|
595
|
+
if (q.type === "select_one" || q.type === "select_multiple") {
|
|
596
|
+
const options = form.itemList("option", q.options, `${i}o`, optionsOpts(q));
|
|
187
597
|
body.push(
|
|
188
|
-
form.ui.section({ label: t.groups, body: groups }),
|
|
189
598
|
answerArea(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
body: form.itemList('option', q.options, `${i}o`, optionsOpts(q)),
|
|
194
|
-
})
|
|
195
|
-
)
|
|
599
|
+
// 단일 · 복수 선택은 체크 원과 기본 정답으로 알 수 있어 힌트를 두지 않는다 (그룹 분류 · 순서 맞추기는 따로 둠)
|
|
600
|
+
form.ui.section({ label: t.options, body: options, action: shuffle }),
|
|
601
|
+
),
|
|
196
602
|
);
|
|
197
603
|
}
|
|
198
|
-
if (q.type ===
|
|
604
|
+
if (q.type === "order") body.push(answerArea(orderBoard(q, shuffle)));
|
|
605
|
+
if (q.type === "group") body.push(answerArea(groupBoard(q, shuffle)));
|
|
606
|
+
if (!INLINE_ANSWER_TYPES.includes(q.type) && q.type !== "order")
|
|
607
|
+
body.push(answerArea(answerField(q)));
|
|
608
|
+
if (q.type === "text")
|
|
199
609
|
body.push(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
610
|
+
// 입력란 힌트: 정답 아래에서 필요할 때만 "입력란 힌트 추가 +"로 연다 (설명 · 해설과 같은 구조)
|
|
611
|
+
form.revealable(
|
|
612
|
+
t.addPlaceholder,
|
|
613
|
+
form.inlineField(
|
|
614
|
+
t.placeholder,
|
|
615
|
+
q.placeholder ?? "",
|
|
616
|
+
(v) => (q.placeholder = v),
|
|
617
|
+
{ placeholder: t.placeholderInput, max: LIMITS.placeholderMax },
|
|
618
|
+
),
|
|
619
|
+
{
|
|
620
|
+
open: Boolean(q.placeholder),
|
|
621
|
+
title: t.placeholder,
|
|
622
|
+
icon: "textbox",
|
|
623
|
+
hint: t.placeholderHint,
|
|
624
|
+
},
|
|
625
|
+
),
|
|
204
626
|
);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
627
|
+
// 해설: 정답 아래에서 필요할 때만 "+ 해설 추가"로 연다. 열면 사용, 비운 채 닫으면 사용 안 함
|
|
628
|
+
body.push(
|
|
629
|
+
form.revealable(
|
|
630
|
+
t.addExplanation,
|
|
631
|
+
form.inlineField(
|
|
632
|
+
t.explanation,
|
|
633
|
+
q.explanation?.text ?? "",
|
|
634
|
+
(v) => (q.explanation = { text: v, enabled: true }),
|
|
635
|
+
{
|
|
636
|
+
placeholder: t.explanationPlaceholder,
|
|
637
|
+
multiline: true,
|
|
638
|
+
},
|
|
639
|
+
),
|
|
640
|
+
{
|
|
641
|
+
open: Boolean(q.explanation?.enabled),
|
|
642
|
+
onOpen: () =>
|
|
643
|
+
(q.explanation = { text: q.explanation?.text ?? "", enabled: true }),
|
|
644
|
+
onClose: () => (q.explanation = { text: "", enabled: false }),
|
|
645
|
+
title: t.explanation,
|
|
646
|
+
icon: "bulb",
|
|
647
|
+
hint: t.explanationHint,
|
|
648
|
+
},
|
|
649
|
+
),
|
|
214
650
|
);
|
|
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
651
|
return body.filter(Boolean);
|
|
224
652
|
}
|
|
225
653
|
|
|
@@ -233,86 +661,132 @@ function questionCard(q, i) {
|
|
|
233
661
|
body: questionFields(q, i),
|
|
234
662
|
},
|
|
235
663
|
{
|
|
236
|
-
type: type => {
|
|
664
|
+
type: (type) => {
|
|
237
665
|
readAnswerViews();
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
666
|
+
const prev = {
|
|
667
|
+
q: structuredClone(q),
|
|
668
|
+
answer: structuredClone(answers[q.id]),
|
|
669
|
+
};
|
|
670
|
+
// 유형을 바꾸면 제목만 남기고 나머지(설명 · 보기 · 해설 · 정답)는 새 유형의 기본값으로 시작한다
|
|
671
|
+
const fresh = {
|
|
672
|
+
...newQuestion(prev.q.type, [], texts.defaults),
|
|
673
|
+
id: q.id,
|
|
674
|
+
title: q.title,
|
|
675
|
+
};
|
|
676
|
+
// 바꾸기 전에 입력한 내용이 기본값과 다를 때만 되돌리기 알림을 띄운다
|
|
677
|
+
const edited =
|
|
678
|
+
JSON.stringify(prev.q) !== JSON.stringify(fresh) ||
|
|
679
|
+
JSON.stringify(prev.answer) !== JSON.stringify(defaultAnswer(fresh));
|
|
680
|
+
draft.questions[i] = {
|
|
681
|
+
...newQuestion(type, [], texts.defaults),
|
|
682
|
+
id: q.id,
|
|
683
|
+
title: q.title,
|
|
684
|
+
};
|
|
241
685
|
delete answers[q.id];
|
|
686
|
+
const picked = defaultAnswer(draft.questions[i]);
|
|
687
|
+
if (picked !== undefined) answers[q.id] = picked;
|
|
242
688
|
answerViews.delete(q.id);
|
|
243
|
-
|
|
689
|
+
noneOpen.delete(q.id);
|
|
244
690
|
render();
|
|
691
|
+
if (edited)
|
|
692
|
+
showSnackbar(t.typeChanged, () => {
|
|
693
|
+
draft.questions[i] = prev.q;
|
|
694
|
+
if (prev.answer !== undefined) answers[q.id] = prev.answer;
|
|
695
|
+
else delete answers[q.id];
|
|
696
|
+
render();
|
|
697
|
+
});
|
|
245
698
|
},
|
|
246
699
|
up: () => swap(draft.questions, i, i - 1),
|
|
247
700
|
down: () => swap(draft.questions, i, i + 1),
|
|
248
701
|
// 지운 문항은 알림의 "되돌리기"로 같은 자리에 되살린다 (정답도 함께)
|
|
249
702
|
remove: () => {
|
|
250
703
|
readAnswerViews();
|
|
251
|
-
const removed = {
|
|
704
|
+
const removed = {
|
|
705
|
+
q: structuredClone(q),
|
|
706
|
+
answer: structuredClone(answers[q.id]),
|
|
707
|
+
};
|
|
252
708
|
draft.questions.splice(i, 1);
|
|
253
709
|
delete answers[q.id];
|
|
254
710
|
answerViews.delete(q.id);
|
|
255
|
-
|
|
256
|
-
|
|
711
|
+
render();
|
|
712
|
+
showSnackbar(t.questionDeleted(i + 1), () => {
|
|
257
713
|
draft.questions.splice(i, 0, removed.q);
|
|
258
714
|
if (removed.answer !== undefined) answers[q.id] = removed.answer;
|
|
259
715
|
render();
|
|
260
|
-
};
|
|
261
|
-
undoAt = i;
|
|
262
|
-
render();
|
|
716
|
+
});
|
|
263
717
|
},
|
|
264
|
-
}
|
|
718
|
+
},
|
|
265
719
|
);
|
|
266
720
|
}
|
|
267
721
|
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
722
|
+
/**
|
|
723
|
+
* 스낵바 (EDS Snackbar): 문항 삭제 · 유형 변경 뒤 "되돌리기"를 화면 아래에 잠깐 띄운다.
|
|
724
|
+
* 한 번에 하나만 보이고(새 알림이 앞의 것을 대체), 화면 영역 밖(body)에 붙여 다시 그려도 사라지지 않으며
|
|
725
|
+
* 변경 표시(저장하지 않은 변경)를 만들지 않는다. 초점을 빼앗지 않는다
|
|
726
|
+
*/
|
|
727
|
+
const SNACKBAR_MS = 6000;
|
|
728
|
+
let snackbarNode = null;
|
|
729
|
+
let snackbarTimer = null;
|
|
730
|
+
|
|
731
|
+
function hideSnackbar() {
|
|
732
|
+
clearTimeout(snackbarTimer);
|
|
733
|
+
snackbarNode?.remove();
|
|
734
|
+
snackbarNode = null;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function showSnackbar(text, restore) {
|
|
738
|
+
hideSnackbar();
|
|
739
|
+
const node = templates.snackbar({ text, action: t.undo });
|
|
740
|
+
node.querySelector('[data-role="undo"]').addEventListener("click", () => {
|
|
741
|
+
hideSnackbar();
|
|
742
|
+
restore();
|
|
743
|
+
});
|
|
744
|
+
document.body.append(node);
|
|
745
|
+
snackbarNode = node;
|
|
746
|
+
snackbarTimer = setTimeout(hideSnackbar, SNACKBAR_MS);
|
|
286
747
|
}
|
|
287
748
|
|
|
288
749
|
function render() {
|
|
289
750
|
readAnswerViews();
|
|
290
751
|
answerViews.clear();
|
|
291
752
|
const cards = draft.questions.map(questionCard);
|
|
292
|
-
if (undo) cards.splice(undoAt, 0, undoNotice(undo, undoAt));
|
|
293
|
-
undo = null;
|
|
294
753
|
root.replaceChildren(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
// 퀴즈 안내: 라벨
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
754
|
+
// 상시 안내는 두지 않는다 (정답 위치는 보기 목록 힌트 · "정답" 열이 알려 줌). 저장된 정답을 못 읽었을 때만 경고
|
|
755
|
+
...(unreadable ? [templates.answersIntro({ text: a.unreadable })] : []),
|
|
756
|
+
// 퀴즈 제목 · 안내: 라벨 없이 큰 제목 + 안내를 항상 보이는 칸으로 둔다 (카드 모양 없이 배경 위에 바로)
|
|
757
|
+
templates.quizInfo({
|
|
758
|
+
body: [
|
|
759
|
+
form.inlineField(t.quizTitle, draft.title, (v) => (draft.title = v), {
|
|
760
|
+
placeholder: t.quizTitlePlaceholder,
|
|
761
|
+
size: "title",
|
|
762
|
+
required: true,
|
|
763
|
+
}),
|
|
764
|
+
form.inlineField(
|
|
765
|
+
t.quizDescription,
|
|
766
|
+
draft.description,
|
|
767
|
+
(v) => (draft.description = v),
|
|
768
|
+
{
|
|
769
|
+
placeholder: t.quizDescriptionPlaceholder,
|
|
770
|
+
multiline: true,
|
|
771
|
+
},
|
|
772
|
+
),
|
|
773
|
+
],
|
|
301
774
|
}),
|
|
302
775
|
...cards,
|
|
303
|
-
//
|
|
776
|
+
// 문항은 LIMITS.questionsMax개까지: 다 차면 "문항 추가" 대신 안내
|
|
304
777
|
canAddQuestion(draft.questions)
|
|
305
778
|
? form.addQuestion(() => {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
texts.defaults
|
|
311
|
-
)
|
|
779
|
+
const added = newQuestion(
|
|
780
|
+
"select_one",
|
|
781
|
+
draft.questions.map((q) => q.id),
|
|
782
|
+
texts.defaults,
|
|
312
783
|
);
|
|
784
|
+
draft.questions.push(added);
|
|
785
|
+
const picked = defaultAnswer(added);
|
|
786
|
+
if (picked !== undefined) answers[added.id] = picked;
|
|
313
787
|
render();
|
|
314
788
|
})
|
|
315
|
-
: templates.
|
|
789
|
+
: templates.questionLimit({ text: t.questionLimit }),
|
|
316
790
|
);
|
|
317
791
|
save?.markDirty();
|
|
318
792
|
}
|
|
@@ -325,7 +799,7 @@ const problemAt = (problem, { answer = false } = {}) => {
|
|
|
325
799
|
const card = form.cardAt(problem.questionIndex);
|
|
326
800
|
const pick = answer ? card?.querySelector('[data-role="answer"]') : null;
|
|
327
801
|
if (answer) markAnswerError(card, problem.message);
|
|
328
|
-
(pick ?? card)?.scrollIntoView({ block:
|
|
802
|
+
(pick ?? card)?.scrollIntoView({ block: "center" });
|
|
329
803
|
pick?.focus({ preventScroll: true });
|
|
330
804
|
return problem.message;
|
|
331
805
|
};
|
|
@@ -335,23 +809,36 @@ function markAnswerError(card, message) {
|
|
|
335
809
|
const area = card?.querySelector('[data-role="answers"]');
|
|
336
810
|
if (!area) return;
|
|
337
811
|
area.querySelector('[data-role="answer-error"]')?.remove();
|
|
338
|
-
area.dataset.error =
|
|
812
|
+
area.dataset.error = "";
|
|
339
813
|
area.lastElementChild.before(templates.answerError({ text: message }));
|
|
340
814
|
const clear = () => {
|
|
341
815
|
delete area.dataset.error;
|
|
342
816
|
area.querySelector('[data-role="answer-error"]')?.remove();
|
|
343
|
-
for (const type of [
|
|
817
|
+
for (const type of ["input", "change", "pointerup"])
|
|
818
|
+
area.removeEventListener(type, clear);
|
|
344
819
|
};
|
|
345
|
-
for (const type of [
|
|
820
|
+
for (const type of ["input", "change", "pointerup"])
|
|
821
|
+
area.addEventListener(type, clear);
|
|
346
822
|
}
|
|
347
823
|
|
|
348
824
|
render();
|
|
349
825
|
save = app.useSave({
|
|
350
826
|
label: t.done,
|
|
351
827
|
getContent: () => structuredClone(draft),
|
|
352
|
-
validate: content => {
|
|
828
|
+
validate: (content) => {
|
|
353
829
|
const problem = validateQuiz(content, texts.validation);
|
|
354
|
-
|
|
830
|
+
if (!problem) return true;
|
|
831
|
+
// 라벨이 없으니 비운 필수 칸(퀴즈 제목 · 질문)에 빨간 밑줄을 긋고, 걸린 칸에 초점을 둔다
|
|
832
|
+
form.markEmptyRequired();
|
|
833
|
+
const scope =
|
|
834
|
+
problem.questionIndex === -1 ? root.querySelector(".qe-quiz-info") : null;
|
|
835
|
+
const invalid = (
|
|
836
|
+
scope ?? form.cardAt(problem.questionIndex)
|
|
837
|
+
)?.querySelector("[aria-invalid]");
|
|
838
|
+
if (!invalid) return problemAt(problem);
|
|
839
|
+
invalid.scrollIntoView({ block: "center" });
|
|
840
|
+
invalid.focus({ preventScroll: true });
|
|
841
|
+
return problem.message;
|
|
355
842
|
},
|
|
356
843
|
// 정답 → 정답 정규식. 검증(정답 · 지운 보기 → 정규식 공통 검사 → 왕복 · 오답)을 통과해야 저장한다
|
|
357
844
|
getGrading: () => {
|
|
@@ -360,14 +847,38 @@ save = app.useSave({
|
|
|
360
847
|
const missing = validateAnswerKey(questions, answers, a.validation);
|
|
361
848
|
if (missing) return problemAt(missing, { answer: true });
|
|
362
849
|
const answerKey = buildAnswerKey(questions, answers);
|
|
363
|
-
|
|
364
|
-
|
|
850
|
+
// 정답 정규식은 서버 한도(ANSWER_KEY_MAX)가 퀴즈 전체에 걸린다. 한글 주관식은 한 글자가 9자로 늘어
|
|
851
|
+
// 몇 문항이면 넘으므로, 정규식에서 가장 긴 문항으로 옮기고 무엇을 줄일지 알려 준다
|
|
852
|
+
if (answerKey.length > ANSWER_KEY_MAX) {
|
|
853
|
+
const lengths = questions.map(
|
|
854
|
+
(q) => buildAnswerKey([q], { [q.id]: answers[q.id] }).length,
|
|
855
|
+
);
|
|
856
|
+
const longest = lengths.indexOf(Math.max(...lengths));
|
|
857
|
+
return problemAt(
|
|
858
|
+
{
|
|
859
|
+
questionIndex: longest,
|
|
860
|
+
message: a.validation.at(
|
|
861
|
+
longest + 1,
|
|
862
|
+
a.validation.tooLong(answerKey.length, ANSWER_KEY_MAX),
|
|
863
|
+
),
|
|
864
|
+
},
|
|
865
|
+
{ answer: true },
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
const base = questions.map((q) =>
|
|
869
|
+
q.type === "text" ? (answers[q.id] ?? [])[0] : answers[q.id],
|
|
870
|
+
);
|
|
871
|
+
const regexProblem = validateAnswerRegex(answerKey, [
|
|
872
|
+
joinAnswers(questions, base),
|
|
873
|
+
]);
|
|
365
874
|
if (regexProblem) return regexProblem;
|
|
366
|
-
const keyProblem = checkAnswerKey(
|
|
875
|
+
const keyProblem = checkAnswerKey(
|
|
876
|
+
questions,
|
|
877
|
+
answers,
|
|
878
|
+
answerKey,
|
|
879
|
+
a.validation,
|
|
880
|
+
);
|
|
367
881
|
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 };
|
|
882
|
+
return { type: "pattern", answer_key: answerKey };
|
|
372
883
|
},
|
|
373
884
|
});
|