@eliceio/cdk-cli 0.1.0-alpha.1 → 0.1.0-alpha.3
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 +171 -136
- package/es/cli.js +119 -26
- package/es/commands/build/index.d.ts +4 -1
- package/es/commands/build/index.js +28 -9
- package/es/commands/check/index.d.ts +8 -2
- package/es/commands/check/index.js +45 -5
- package/es/commands/create/index.d.ts +2 -0
- package/es/commands/create/index.js +28 -3
- package/es/commands/create/scaffold.d.ts +2 -0
- package/es/commands/create/scaffold.js +10 -6
- package/es/commands/dev/index.d.ts +1 -1
- package/es/commands/dev/index.js +6 -2
- package/es/commands/doctor/index.d.ts +12 -0
- package/es/commands/doctor/index.js +217 -7
- package/es/commands/guide/index.d.ts +29 -0
- package/es/commands/guide/index.js +120 -0
- package/es/commands/mcp/index.d.ts +134 -0
- package/es/commands/mcp/index.js +399 -0
- package/es/commands/setup/index.d.ts +40 -0
- package/es/commands/setup/index.js +157 -0
- package/es/commands/skill/index.d.ts +45 -0
- package/es/commands/skill/index.js +145 -0
- package/es/core/config.d.ts +63 -19
- package/es/core/config.js +108 -32
- package/es/core/prepare.js +3 -5
- package/es/core/project-check.d.ts +15 -0
- package/es/core/project-check.js +26 -0
- package/es/core/sandbox.d.ts +17 -0
- package/es/core/sandbox.js +182 -0
- package/es/core/templates.d.ts +25 -0
- package/es/core/templates.js +41 -0
- package/es/dev/grading.d.ts +14 -7
- package/es/dev/grading.js +27 -13
- package/es/dev/host-page.d.ts +1 -1
- package/es/dev/host-page.js +33 -33
- package/es/dev/mock-api.d.ts +20 -4
- package/es/dev/mock-api.js +70 -9
- package/es/dev/server.d.ts +9 -1
- package/es/dev/server.js +101 -25
- package/es/rules/check.js +126 -4
- package/es/rules/index.d.ts +1 -1
- package/es/rules/index.js +1 -1
- package/es/rules/manifest.d.ts +23 -9
- package/es/rules/manifest.js +60 -35
- package/es/rules/node.js +3 -1
- package/es/rules/semver.d.ts +5 -0
- package/es/rules/semver.js +32 -0
- package/es/rules/types.d.ts +29 -6
- package/es/rules.json.js +1 -1
- package/es/version.d.ts +2 -1
- package/es/version.js +5 -1
- package/guides/content-development.md +294 -0
- package/package.json +4 -2
- package/rules.json +113 -5
- package/skills/_shared/always.md +9 -0
- package/skills/elice-content-check/SKILL.md +22 -0
- package/skills/elice-content-create/SKILL.md +21 -0
- package/skills/elice-content-migrate/SKILL.md +21 -0
- package/skills/elice-content-publish/SKILL.md +22 -0
- package/templates/_shared/lib/cdk-mock.d.ts +21 -3
- package/templates/_shared/lib/cdk-mock.js +239 -80
- package/templates/_shared/lib/cdk.js +2 -2
- package/templates/_shared/lib/elice-content.css +206 -0
- package/templates/_shared/lib/elice-content.d.ts +112 -5
- package/templates/_shared/lib/elice-content.js +660 -62
- package/templates/blank/README.md +14 -5
- package/templates/blank/commentary.txt +2 -0
- package/templates/blank/completion.html +15 -0
- package/templates/blank/elice.config.json +3 -5
- package/templates/blank/gitignore +1 -0
- package/templates/blank/screens/completion.js +7 -0
- package/templates/blank/screens/edit.js +3 -0
- package/templates/blank/template.json +6 -0
- package/templates/quiz/README.md +37 -30
- package/templates/quiz/commentary.txt +2 -0
- package/templates/quiz/content.json +17 -63
- package/templates/quiz/core/behaviors.d.ts +8 -3
- package/templates/quiz/core/behaviors.js +15 -2
- package/templates/quiz/core/model.d.ts +27 -1
- package/templates/quiz/core/model.js +199 -4
- package/templates/quiz/elice.config.json +1 -6
- package/templates/quiz/gitignore +1 -0
- package/templates/quiz/grading.json +1 -10
- package/templates/quiz/screens/edit.js +106 -32
- package/templates/quiz/screens/learn.js +13 -9
- package/templates/quiz/styles.css +84 -24
- package/templates/quiz/template.json +6 -0
- package/templates/quiz/ui/templates/edit.d.ts +2 -1
- package/templates/quiz/ui/templates/edit.js +16 -13
- package/templates/quiz/ui/templates/group.js +29 -8
- package/templates/quiz/ui/templates/question.js +3 -3
- package/templates/quiz/ui/texts.js +53 -29
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// content.json / 편집 화면이 저장하는 settings (학생에게 공개, 정답 없음)
|
|
4
4
|
// { title, description, questions: [{ id, type, title, description, options?, groups?, slots?,
|
|
5
5
|
// shuffle?, placeholder?, explanation: { enabled, text } }] }
|
|
6
|
-
// 제출하는
|
|
7
|
-
//
|
|
6
|
+
// 제출하는 답: 문자열 하나 (ADR 0008). 문항 순서대로 `문항id=답`을 `;`로 잇고, 주관식 답은 encodeURIComponent
|
|
7
|
+
// "q1=b;q2=a,d;q3=c,a,b;q4=%EA%B0%80%EC%A4%91%EC%B9%98;q5=g1:a|g2:b,c"
|
|
8
|
+
// 퀴즈는 완료 정책 on_graded + 채점 방식 pattern 고정 (ADR 0009, completionPolicies ["on_graded"]). 정답(settings.grading)은 편집 화면이 문항마다 고른 답으로
|
|
9
|
+
// 만든 정규식 하나: { type: 'pattern', answer_key: '^q1=b;…$' }
|
|
8
10
|
|
|
9
11
|
// 화면에 보이는 문구는 여기 두지 않습니다 (ui/texts.js). 문구가 필요한 함수는 화면(screens/)이 문구를 넘겨 줍니다.
|
|
10
12
|
|
|
@@ -46,7 +48,7 @@ export function newQuestion(type, usedIds, names) {
|
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
50
|
* 유형을 바꿀 때 데이터 변환 (기존 편집 화면처럼 보기 텍스트는 최대한 살림).
|
|
49
|
-
* 정답은
|
|
51
|
+
* 정답은 편집 화면이 따로 모아 settings.grading에 저장하므로 여기서는 다루지 않는다. names: newQuestion과 같음
|
|
50
52
|
*/
|
|
51
53
|
export function convertType(q, type, names) {
|
|
52
54
|
const next = { ...q, type };
|
|
@@ -109,7 +111,7 @@ export function validateQuiz(content, v) {
|
|
|
109
111
|
return null;
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
// ---------- 답 문자열 (
|
|
114
|
+
// ---------- 답 문자열 (편집 화면이 같은 모양으로 정답 정규식을 만든다) ----------
|
|
113
115
|
|
|
114
116
|
/**
|
|
115
117
|
* 화면의 답 → 문항의 답 문자열
|
|
@@ -160,6 +162,199 @@ export function decodeAnswer(q, text) {
|
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
|
|
165
|
+
// ---------- 제출 답 하나로 잇기 · 풀기 (ADR 0008) ----------
|
|
166
|
+
|
|
167
|
+
/** 문항별 답 문자열 → 제출할 답 문자열 하나. 주관식 답은 encodeURIComponent (`;` · `=` · `|`가 들어가도 경계가 그대로) */
|
|
168
|
+
export function joinAnswers(questions, values) {
|
|
169
|
+
return questions
|
|
170
|
+
.map((q, i) => {
|
|
171
|
+
const a = encodeAnswer(q, values[i]);
|
|
172
|
+
return `${q.id}=${q.type === 'text' ? encodeURIComponent(a) : a}`;
|
|
173
|
+
})
|
|
174
|
+
.join(';');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 제출한 답 → 문항 id별 답 문자열 (다시 열기 · 튜터링). 옛 답 `{ answers: { q1: "b" } }`도 받는다.
|
|
179
|
+
* `;`로 나누고 첫 `=`에서 문항 id와 답을 나눈 뒤, 주관식은 decodeURIComponent
|
|
180
|
+
*/
|
|
181
|
+
export function splitAnswers(questions, answer) {
|
|
182
|
+
if (answer && typeof answer === 'object') return { ...(answer.answers ?? {}) };
|
|
183
|
+
if (typeof answer !== 'string') return {};
|
|
184
|
+
const byId = Object.fromEntries(questions.map((q) => [q.id, q]));
|
|
185
|
+
const out = {};
|
|
186
|
+
for (const part of answer.split(';')) {
|
|
187
|
+
const at = part.indexOf('=');
|
|
188
|
+
if (at < 0) continue;
|
|
189
|
+
const id = part.slice(0, at);
|
|
190
|
+
let value = part.slice(at + 1);
|
|
191
|
+
if (byId[id]?.type === 'text') {
|
|
192
|
+
try {
|
|
193
|
+
value = decodeURIComponent(value);
|
|
194
|
+
} catch {
|
|
195
|
+
// 잘못된 인코딩은 그대로 둔다
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
out[id] = value;
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ---------- 정답 정규식 (편집 화면, ADR 0009) ----------
|
|
204
|
+
|
|
205
|
+
const escapeRegex = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
206
|
+
const unescapeRegex = (text) => text.replace(/\\(.)/g, '$1');
|
|
207
|
+
|
|
208
|
+
/** 정답 하나(화면 값) → 문항 정규식 조각. 주관식은 허용 답 여러 개를 (?:…|…)로 */
|
|
209
|
+
function keyPart(q, value) {
|
|
210
|
+
if (q.type === 'text') {
|
|
211
|
+
const alts = (value ?? []).map((t) => String(t).trim()).filter(Boolean);
|
|
212
|
+
return `(?:${alts.map((t) => escapeRegex(encodeURIComponent(t))).join('|')})`;
|
|
213
|
+
}
|
|
214
|
+
return escapeRegex(encodeAnswer(q, value));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 문항별 정답(화면 값: 주관식은 허용 답 배열) → regex 정답 정규식 하나.
|
|
219
|
+
* 인코딩 → 정규식 이스케이프 → `|`로 묶기 → 전체를 `^…$` (ADR 0008 §4)
|
|
220
|
+
*/
|
|
221
|
+
export function buildAnswerKey(questions, key) {
|
|
222
|
+
return `^${questions.map((q) => `${escapeRegex(q.id)}=${keyPart(q, key[q.id])}`).join(';')}$`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* buildAnswerKey가 만든 정규식 → 문항별 정답(화면 값). 다른 모양(손으로 쓴 정규식)이면 null.
|
|
227
|
+
* 문항이 바뀌었으면 있는 문항만 돌려준다 (없는 문항은 validateAnswerKey가 알려 줌)
|
|
228
|
+
*/
|
|
229
|
+
export function parseAnswerKey(questions, regex) {
|
|
230
|
+
if (typeof regex !== 'string' || !regex.startsWith('^') || !regex.endsWith('$')) return null;
|
|
231
|
+
const byId = Object.fromEntries(questions.map((q) => [q.id, q]));
|
|
232
|
+
const out = {};
|
|
233
|
+
// 정답 조각 안의 `;`는 주관식 인코딩(%3B)이라 나오지 않는다
|
|
234
|
+
for (const part of regex.slice(1, -1).split(';')) {
|
|
235
|
+
const at = part.indexOf('=');
|
|
236
|
+
if (at < 0) return null;
|
|
237
|
+
const id = unescapeRegex(part.slice(0, at));
|
|
238
|
+
const body = part.slice(at + 1);
|
|
239
|
+
const q = byId[id];
|
|
240
|
+
if (!q) continue;
|
|
241
|
+
if (q.type === 'text') {
|
|
242
|
+
if (!body.startsWith('(?:') || !body.endsWith(')')) return null;
|
|
243
|
+
try {
|
|
244
|
+
out[id] = body
|
|
245
|
+
.slice(3, -1)
|
|
246
|
+
.split(/(?<!\\)\|/)
|
|
247
|
+
.map((t) => decodeURIComponent(unescapeRegex(t)))
|
|
248
|
+
.filter(Boolean);
|
|
249
|
+
} catch {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
} else out[id] = decodeAnswer(q, unescapeRegex(body));
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 정답 검증 1: 모든 문항에 정답이 있고, 정답이 지금 있는 보기 · 그룹을 가리키는지 (G63).
|
|
259
|
+
* 문제가 없으면 null, 있으면 { questionIndex, message }
|
|
260
|
+
* @param {object} v 검증 문구 (ui/texts.js의 answers.validation)
|
|
261
|
+
*/
|
|
262
|
+
export function validateAnswerKey(questions, key, v) {
|
|
263
|
+
for (const [i, q] of questions.entries()) {
|
|
264
|
+
const at = (message) => ({ questionIndex: i, message: v.at(i + 1, message) });
|
|
265
|
+
const value = key[q.id];
|
|
266
|
+
if (q.type === 'text') {
|
|
267
|
+
if (!(value ?? []).some((t) => String(t).trim())) return at(v.noAnswer);
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (!isAnswered(q, value)) return at(v.noAnswer);
|
|
271
|
+
const ids = new Set((q.options ?? []).map((o) => o.id));
|
|
272
|
+
const chosen =
|
|
273
|
+
q.type === 'group'
|
|
274
|
+
? Object.values(value ?? {}).flat()
|
|
275
|
+
: q.type === 'select_one'
|
|
276
|
+
? [value]
|
|
277
|
+
: (value ?? []);
|
|
278
|
+
if (chosen.some((id) => !ids.has(id))) return at(v.missingOption);
|
|
279
|
+
if (q.type === 'group' && Object.keys(value ?? {}).some((g) => !q.groups.some((x) => x.id === g)))
|
|
280
|
+
return at(v.missingOption);
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** 정답(화면 값)을 다른 답으로 하나 바꾼 값. 바꿀 수 없으면 undefined (오답 검증용) */
|
|
286
|
+
export function wrongValue(q, value) {
|
|
287
|
+
const ids = (q.options ?? []).map((o) => o.id);
|
|
288
|
+
switch (q.type) {
|
|
289
|
+
case 'select_one':
|
|
290
|
+
return ids.find((id) => id !== value);
|
|
291
|
+
case 'select_multiple': {
|
|
292
|
+
const set = new Set(value ?? []);
|
|
293
|
+
const flip = ids[0];
|
|
294
|
+
if (flip === undefined) return undefined;
|
|
295
|
+
if (set.has(flip)) set.delete(flip);
|
|
296
|
+
else set.add(flip);
|
|
297
|
+
return [...set];
|
|
298
|
+
}
|
|
299
|
+
case 'order': {
|
|
300
|
+
const list = [...(value ?? [])];
|
|
301
|
+
if (list.length >= 2) {
|
|
302
|
+
[list[0], list[1]] = [list[1], list[0]];
|
|
303
|
+
return list;
|
|
304
|
+
}
|
|
305
|
+
const other = ids.find((id) => !list.includes(id));
|
|
306
|
+
return other === undefined ? undefined : [other];
|
|
307
|
+
}
|
|
308
|
+
case 'group': {
|
|
309
|
+
const groups = q.groups.map((g) => g.id);
|
|
310
|
+
const out = Object.fromEntries(groups.map((g) => [g, [...(value?.[g] ?? [])]]));
|
|
311
|
+
const from = groups.find((g) => out[g].length > 0);
|
|
312
|
+
const to = groups.find((g) => g !== from);
|
|
313
|
+
if (!from || !to) return undefined;
|
|
314
|
+
out[to].push(out[from].shift());
|
|
315
|
+
return out;
|
|
316
|
+
}
|
|
317
|
+
case 'text':
|
|
318
|
+
return ['\u0000오답'];
|
|
319
|
+
default:
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 정답 검증 2 (ADR 0009 §3): 만든 정규식이 학생 화면이 제출할 문자열과 맞는지.
|
|
326
|
+
* - 왕복: 정답을 학생 화면과 같은 joinAnswers로 이은 문자열이 맞아야 한다 (주관식 허용 답은 하나씩 모두)
|
|
327
|
+
* - 오답: 문항 하나를 다른 답으로 바꾼 문자열은 맞지 않아야 한다 (너무 넓은 정규식 방지)
|
|
328
|
+
* 문제가 없으면 null, 있으면 { questionIndex, message }
|
|
329
|
+
* @param {object} v 검증 문구 (ui/texts.js의 answers.validation)
|
|
330
|
+
*/
|
|
331
|
+
export function checkAnswerKey(questions, key, regex, v) {
|
|
332
|
+
let re;
|
|
333
|
+
try {
|
|
334
|
+
re = new RegExp(regex);
|
|
335
|
+
} catch {
|
|
336
|
+
return { questionIndex: -1, message: v.badRegex };
|
|
337
|
+
}
|
|
338
|
+
// 화면 값으로: 주관식은 허용 답 중 하나
|
|
339
|
+
const base = questions.map((q) => (q.type === 'text' ? (key[q.id] ?? [])[0] : key[q.id]));
|
|
340
|
+
if (!re.test(joinAnswers(questions, base))) return { questionIndex: -1, message: v.roundTrip };
|
|
341
|
+
for (const [i, q] of questions.entries()) {
|
|
342
|
+
const at = (message) => ({ questionIndex: i, message: v.at(i + 1, message) });
|
|
343
|
+
if (q.type === 'text')
|
|
344
|
+
for (const alt of key[q.id] ?? []) {
|
|
345
|
+
const values = [...base];
|
|
346
|
+
values[i] = alt;
|
|
347
|
+
if (!re.test(joinAnswers(questions, values))) return at(v.roundTrip);
|
|
348
|
+
}
|
|
349
|
+
const wrong = wrongValue(q, key[q.id]);
|
|
350
|
+
if (wrong === undefined) continue;
|
|
351
|
+
const values = [...base];
|
|
352
|
+
values[i] = q.type === 'text' ? wrong[0] : wrong;
|
|
353
|
+
if (re.test(joinAnswers(questions, values))) return at(v.tooWide);
|
|
354
|
+
}
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
|
|
163
358
|
/** 이 문항에 답했는지 (기존 규칙: 순서는 칸을 모두 채움, 그룹은 하나라도 배치, 나머지는 비어 있지 않음) */
|
|
164
359
|
export function isAnswered(q, value) {
|
|
165
360
|
switch (q.type) {
|
package/templates/quiz/gitignore
CHANGED
|
@@ -1,21 +1,43 @@
|
|
|
1
1
|
// 내용 편집 화면(CMS). 기존 퀴즈 편집 폼을 옮김 (docs/quiz-spec.md §3). 저장 버튼 · 변경 표시는 키트(useSave)가 합니다.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
2
|
+
// 퀴즈는 완료 정책 on_graded + 채점 방식 pattern 고정 (ADR 0009, elice.config.json completionPolicies ["on_graded"]): 문항 카드마다 "정답"에서
|
|
3
|
+
// 답을 고르고, 저장할 때 고른 답으로 정답 정규식 하나를 만들어 검증한 뒤 settings.grading에 함께 저장합니다.
|
|
4
|
+
// 문제 내용(content)은 학생에게도 내려가므로 정답을 넣지 않습니다 (정답은 grading에만, 서버가 학생에게 내려주지 않음).
|
|
5
|
+
// 여기서는 어떤 칸을 어떤 순서로 놓을지만 정합니다. 모양은 ui/(templates/edit.js · texts · theme.css), 동작은 core/.
|
|
6
|
+
import { start, validateAnswerRegex } from '../lib/elice-content.js';
|
|
7
|
+
import { renderAnswerBody } from '../core/behaviors.js';
|
|
6
8
|
import { createEditor } from '../core/editor.js';
|
|
7
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
buildAnswerKey,
|
|
11
|
+
checkAnswerKey,
|
|
12
|
+
convertType,
|
|
13
|
+
joinAnswers,
|
|
14
|
+
LIMITS,
|
|
15
|
+
newQuestion,
|
|
16
|
+
parseAnswerKey,
|
|
17
|
+
validateAnswerKey,
|
|
18
|
+
validateQuiz,
|
|
19
|
+
} from '../core/model.js';
|
|
8
20
|
import * as templates from '../ui/templates/edit.js';
|
|
21
|
+
import { templates as quizTemplates } from '../ui/templates/index.js';
|
|
9
22
|
import { loading } from '../ui/templates/page.js';
|
|
10
23
|
import { texts } from '../ui/texts.js';
|
|
11
24
|
|
|
12
25
|
const t = texts.edit;
|
|
26
|
+
const a = texts.answers;
|
|
13
27
|
const root = document.getElementById('app');
|
|
14
28
|
document.title = texts.page.edit;
|
|
15
29
|
root.replaceChildren(loading());
|
|
16
30
|
const app = await start({ screen: 'edit' });
|
|
17
31
|
const draft = structuredClone(app.content);
|
|
18
32
|
draft.questions ??= [];
|
|
33
|
+
|
|
34
|
+
// 문항 id → 정답(화면 값: 선택 id · id 목록 · 그룹별 목록, 주관식은 허용 답 목록). 저장된 정규식을 읽어 채운다
|
|
35
|
+
const savedKey = app.grading?.answer_key;
|
|
36
|
+
const parsed = savedKey ? parseAnswerKey(draft.questions, savedKey) : {};
|
|
37
|
+
/** @type {Record<string, unknown>} */
|
|
38
|
+
const answers = parsed ?? {};
|
|
39
|
+
const unreadable = Boolean(savedKey) && parsed === null;
|
|
40
|
+
|
|
19
41
|
const form = createEditor({
|
|
20
42
|
rerender: render,
|
|
21
43
|
root,
|
|
@@ -35,11 +57,35 @@ const swap = (list, i, j) => {
|
|
|
35
57
|
render();
|
|
36
58
|
};
|
|
37
59
|
|
|
60
|
+
/** 문항 카드의 "정답": 학생 화면과 같은 보기 · 칸 · 그룹으로 고른다 (주관식은 허용 답 여러 개) */
|
|
61
|
+
function answerField(q) {
|
|
62
|
+
if (q.type === 'text') {
|
|
63
|
+
const node = templates.textAnswers({ placeholder: a.textPlaceholder });
|
|
64
|
+
// 조각이 칸 자체이거나 칸을 감싼 요소여도 된다
|
|
65
|
+
const input = node.matches('[data-role="input"]') ? node : node.querySelector('[data-role="input"]');
|
|
66
|
+
input.value = (answers[q.id] ?? []).join('\n');
|
|
67
|
+
input.addEventListener('input', () => {
|
|
68
|
+
answers[q.id] = input.value
|
|
69
|
+
.split('\n')
|
|
70
|
+
.map(s => s.trim())
|
|
71
|
+
.filter(Boolean);
|
|
72
|
+
});
|
|
73
|
+
return form.ui.section({ label: a.label, hint: a.hint.text, body: node });
|
|
74
|
+
}
|
|
75
|
+
const view = renderAnswerBody(q, { templates: quizTemplates });
|
|
76
|
+
if (answers[q.id] !== undefined) view.setValue(answers[q.id]);
|
|
77
|
+
// 누르기 · 끌어 놓기가 끝난 뒤 값을 읽는다
|
|
78
|
+
const read = () => queueMicrotask(() => (answers[q.id] = view.getValue()));
|
|
79
|
+
for (const type of ['input', 'change', 'click', 'pointerup'])
|
|
80
|
+
view.el.addEventListener(type, read);
|
|
81
|
+
return form.ui.section({ label: a.label, hint: a.hint[q.type], body: view.el });
|
|
82
|
+
}
|
|
83
|
+
|
|
38
84
|
/** 문항 카드 안의 칸들. 유형마다 보이는 칸이 다르다 */
|
|
39
85
|
function questionFields(q, i) {
|
|
40
86
|
const body = [
|
|
41
|
-
form.field(t.title, q.title,
|
|
42
|
-
form.markdownField(t.description, q.description,
|
|
87
|
+
form.field(t.title, q.title, v => (q.title = v), { required: true, max: LIMITS.titleMax }),
|
|
88
|
+
form.markdownField(t.description, q.description, v => (q.description = v)),
|
|
43
89
|
];
|
|
44
90
|
if (q.type === 'select_one' || q.type === 'select_multiple' || q.type === 'order') {
|
|
45
91
|
const options = form.itemList('option', q.options, `${i}o`, {
|
|
@@ -49,10 +95,18 @@ function questionFields(q, i) {
|
|
|
49
95
|
});
|
|
50
96
|
body.push(form.ui.section({ label: t.options, body: options }));
|
|
51
97
|
}
|
|
52
|
-
if (q.type === 'order')
|
|
53
|
-
|
|
54
|
-
|
|
98
|
+
if (q.type === 'order') {
|
|
99
|
+
const slots = form.numberField(
|
|
100
|
+
t.slots,
|
|
101
|
+
t.slotsHint,
|
|
102
|
+
q.slots,
|
|
103
|
+
q.options.length,
|
|
104
|
+
v => (q.slots = v)
|
|
55
105
|
);
|
|
106
|
+
// 칸 수가 바뀌면 정답 칸도 다시 그린다 (입력하는 동안이 아니라 확정했을 때)
|
|
107
|
+
slots.querySelector('[data-role="input"]')?.addEventListener('change', render);
|
|
108
|
+
body.push(slots);
|
|
109
|
+
}
|
|
56
110
|
if (q.type === 'group')
|
|
57
111
|
body.push(
|
|
58
112
|
form.ui.section({ label: t.groups, body: form.itemList('group', q.groups, `${i}g`) }),
|
|
@@ -60,26 +114,25 @@ function questionFields(q, i) {
|
|
|
60
114
|
label: t.options,
|
|
61
115
|
hint: t.groupOptionsHint,
|
|
62
116
|
body: form.itemList('option', q.options, `${i}o`),
|
|
63
|
-
})
|
|
117
|
+
})
|
|
64
118
|
);
|
|
65
119
|
if (q.type === 'text')
|
|
66
120
|
body.push(
|
|
67
|
-
form.field(t.placeholder, q.placeholder,
|
|
121
|
+
form.field(t.placeholder, q.placeholder, v => (q.placeholder = v), {
|
|
68
122
|
max: LIMITS.placeholderMax,
|
|
69
123
|
hint: t.placeholderHint,
|
|
70
|
-
})
|
|
124
|
+
})
|
|
71
125
|
);
|
|
72
|
-
|
|
126
|
+
body.push(answerField(q));
|
|
127
|
+
if (q.type !== 'text') body.push(form.toggle(t.shuffle, q.shuffle, v => (q.shuffle = v)));
|
|
73
128
|
body.push(
|
|
74
|
-
form.toggle(t.explanationOn, q.explanation?.enabled,
|
|
129
|
+
form.toggle(t.explanationOn, q.explanation?.enabled, v => {
|
|
75
130
|
q.explanation = { ...(q.explanation ?? { text: '' }), enabled: v };
|
|
76
131
|
render();
|
|
77
|
-
})
|
|
132
|
+
})
|
|
78
133
|
);
|
|
79
134
|
if (q.explanation?.enabled)
|
|
80
|
-
body.push(
|
|
81
|
-
form.markdownField(t.explanation, q.explanation.text, (v) => (q.explanation.text = v)),
|
|
82
|
-
);
|
|
135
|
+
body.push(form.markdownField(t.explanation, q.explanation.text, v => (q.explanation.text = v)));
|
|
83
136
|
return body;
|
|
84
137
|
}
|
|
85
138
|
|
|
@@ -93,47 +146,68 @@ function questionCard(q, i) {
|
|
|
93
146
|
body: questionFields(q, i),
|
|
94
147
|
},
|
|
95
148
|
{
|
|
96
|
-
type:
|
|
149
|
+
type: type => {
|
|
97
150
|
draft.questions[i] = convertType(q, type, texts.defaults);
|
|
151
|
+
// 유형이 바뀌면 답 모양이 달라지므로 정답을 다시 고른다
|
|
152
|
+
delete answers[q.id];
|
|
98
153
|
render();
|
|
99
154
|
},
|
|
100
155
|
up: () => swap(draft.questions, i, i - 1),
|
|
101
156
|
down: () => swap(draft.questions, i, i + 1),
|
|
102
157
|
remove: () => {
|
|
103
158
|
draft.questions.splice(i, 1);
|
|
159
|
+
delete answers[q.id];
|
|
104
160
|
render();
|
|
105
161
|
},
|
|
106
|
-
}
|
|
162
|
+
}
|
|
107
163
|
);
|
|
108
164
|
}
|
|
109
165
|
|
|
110
166
|
function render() {
|
|
111
167
|
root.replaceChildren(
|
|
112
|
-
|
|
113
|
-
form.field(t.quizTitle, draft.title,
|
|
114
|
-
form.markdownField(t.quizDescription, draft.description,
|
|
168
|
+
templates.answersIntro({ text: unreadable ? `${a.unreadable} ${a.intro}` : a.intro }),
|
|
169
|
+
form.field(t.quizTitle, draft.title, v => (draft.title = v), { required: true }),
|
|
170
|
+
form.markdownField(t.quizDescription, draft.description, v => (draft.description = v)),
|
|
115
171
|
...draft.questions.map(questionCard),
|
|
116
172
|
form.addQuestion(() => {
|
|
117
173
|
draft.questions.push(
|
|
118
174
|
newQuestion(
|
|
119
175
|
'select_one',
|
|
120
|
-
draft.questions.map(
|
|
121
|
-
texts.defaults
|
|
122
|
-
)
|
|
176
|
+
draft.questions.map(q => q.id),
|
|
177
|
+
texts.defaults
|
|
178
|
+
)
|
|
123
179
|
);
|
|
124
180
|
render();
|
|
125
|
-
})
|
|
181
|
+
})
|
|
126
182
|
);
|
|
127
183
|
save?.markDirty();
|
|
128
184
|
}
|
|
129
185
|
|
|
186
|
+
/** 문제가 있는 문항 카드로 옮기고 문장을 돌려준다 */
|
|
187
|
+
const problemAt = problem => {
|
|
188
|
+
form.cardAt(problem.questionIndex)?.scrollIntoView({ block: 'center' });
|
|
189
|
+
return problem.message;
|
|
190
|
+
};
|
|
191
|
+
|
|
130
192
|
render();
|
|
131
193
|
save = app.useSave({
|
|
194
|
+
label: t.done,
|
|
132
195
|
getContent: () => structuredClone(draft),
|
|
133
|
-
validate:
|
|
196
|
+
validate: content => {
|
|
134
197
|
const problem = validateQuiz(content, texts.validation);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
198
|
+
return problem ? problemAt(problem) : true;
|
|
199
|
+
},
|
|
200
|
+
// 정답 → 정답 정규식. 검증(정답 · 지운 보기 → 정규식 공통 검사 → 왕복 · 오답)을 통과해야 저장한다
|
|
201
|
+
getGrading: () => {
|
|
202
|
+
const { questions } = draft;
|
|
203
|
+
const missing = validateAnswerKey(questions, answers, a.validation);
|
|
204
|
+
if (missing) return problemAt(missing);
|
|
205
|
+
const answerKey = buildAnswerKey(questions, answers);
|
|
206
|
+
const base = questions.map(q => (q.type === 'text' ? (answers[q.id] ?? [])[0] : answers[q.id]));
|
|
207
|
+
const regexProblem = validateAnswerRegex(answerKey, [joinAnswers(questions, base)]);
|
|
208
|
+
if (regexProblem) return regexProblem;
|
|
209
|
+
const keyProblem = checkAnswerKey(questions, answers, answerKey, a.validation);
|
|
210
|
+
if (keyProblem) return problemAt(keyProblem);
|
|
211
|
+
return { type: 'pattern', answer_key: answerKey };
|
|
138
212
|
},
|
|
139
213
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// 모양은 ui/(templates · texts · theme.css), 동작은 core/에 있습니다.
|
|
4
4
|
import { start } from '../lib/elice-content.js';
|
|
5
5
|
import { renderQuestion } from '../core/behaviors.js';
|
|
6
|
-
import { decodeAnswer,
|
|
6
|
+
import { decodeAnswer, isAnswered, joinAnswers, splitAnswers } from '../core/model.js';
|
|
7
7
|
import { labels, templates } from '../ui/templates/index.js';
|
|
8
8
|
import { learnHeader, loading } from '../ui/templates/page.js';
|
|
9
9
|
import { texts } from '../ui/texts.js';
|
|
@@ -13,20 +13,24 @@ document.title = texts.page.learn;
|
|
|
13
13
|
root.replaceChildren(loading());
|
|
14
14
|
const app = await start({ screen: 'learn' });
|
|
15
15
|
const { title, description, questions = [] } = app.content;
|
|
16
|
+
// 학생 화면에는 문항 유형을 보이지 않는다 (무엇을 할지는 질문 문장이 알려 줌). 교육자 화면에는 보인다
|
|
16
17
|
const views = questions.map((q, i) =>
|
|
17
|
-
renderQuestion(q, i, {
|
|
18
|
+
renderQuestion(q, i, {
|
|
19
|
+
templates,
|
|
20
|
+
labels: { ...labels, types: null },
|
|
21
|
+
seed: app.account?.anonymousId ?? '',
|
|
22
|
+
}),
|
|
18
23
|
);
|
|
19
24
|
|
|
20
25
|
root.replaceChildren(learnHeader({ title: title ?? '', description }), ...views.map((v) => v.el));
|
|
21
26
|
|
|
27
|
+
// 답은 문자열 하나로 낸다 (편집 화면이 만든 정답 정규식과 전체 비교, ADR 0008 · 0009): "q1=b;q2=a,d;…"
|
|
22
28
|
app.useSubmit({
|
|
23
|
-
getAnswer: () => (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
),
|
|
27
|
-
}
|
|
28
|
-
setAnswer: (answer) =>
|
|
29
|
-
questions.forEach((q, i) => views[i].setValue(decodeAnswer(q, answer?.answers?.[q.id]))),
|
|
29
|
+
getAnswer: () => joinAnswers(questions, views.map((v) => v.getValue())),
|
|
30
|
+
setAnswer: (answer) => {
|
|
31
|
+
const byId = splitAnswers(questions, answer);
|
|
32
|
+
questions.forEach((q, i) => views[i].setValue(decodeAnswer(q, byId[q.id])));
|
|
33
|
+
},
|
|
30
34
|
validate: () => {
|
|
31
35
|
const left = questions.findIndex((q, i) => !isAnswered(q, views[i].getValue()));
|
|
32
36
|
return left < 0 || texts.learn.unanswered(left + 1);
|