@eliceio/cdk-cli 1.3.0-contenttypes.0 → 1.3.0-contenttypes.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 +21 -20
- package/es/cli.js +1 -1
- package/es/commands/create/index.js +1 -0
- package/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/commands/doctor/index.js +6 -2
- package/es/core/config.d.ts +22 -0
- package/es/core/config.js +165 -1
- package/es/dev/assets.d.ts +80 -0
- package/es/dev/assets.js +240 -0
- package/es/dev/grading.d.ts +42 -26
- package/es/dev/grading.js +88 -39
- package/es/dev/host-page.js +26 -2
- package/es/dev/inject.d.ts +2 -1
- package/es/dev/inject.js +10 -2
- package/es/dev/mock-api.d.ts +23 -2
- package/es/dev/mock-api.js +210 -40
- package/es/dev/server.d.ts +12 -1
- package/es/dev/server.js +115 -9
- package/es/rules.json.js +1 -1
- package/package.json +2 -2
- package/rules.json +3 -3
- package/skills/_shared/references/02-design-the-material.md +1 -1
- package/skills/_shared/references/03-create-the-project.md +9 -8
- package/skills/_shared/references/04-rules.md +1 -1
- package/skills/_shared/references/05-screen-code.md +22 -20
- package/skills/_shared/references/06-using-the-quiz-template.md +2 -2
- package/skills/_shared/references/08-fix-check-errors.md +1 -1
- package/skills/_shared/references/09-check.md +1 -0
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
- package/skills/elice-content-publish/SKILL.md +1 -1
- package/templates/_shared/lib/cdk-mock.d.ts +17 -0
- package/templates/_shared/lib/cdk-mock.js +212 -7
- package/templates/_shared/lib/elice-content.d.ts +61 -1
- package/templates/_shared/lib/elice-content.js +317 -10
- package/templates/blank/README.md +1 -1
- package/templates/blank/screens/instructor.js +8 -2
- package/templates/blank/screens/learn.js +1 -1
- package/templates/blank/template.json +1 -1
- package/templates/document/README.md +92 -0
- package/templates/document/commentary.txt +2 -0
- package/templates/document/core/dom.d.ts +13 -0
- package/templates/document/core/dom.js +83 -0
- package/templates/document/core/file-type.d.ts +21 -0
- package/templates/document/core/file-type.js +85 -0
- package/templates/document/core/group-3d.d.ts +20 -0
- package/templates/document/core/group-3d.js +256 -0
- package/templates/document/core/inline-edit.d.ts +15 -0
- package/templates/document/core/inline-edit.js +377 -0
- package/templates/document/core/load.d.ts +13 -0
- package/templates/document/core/load.js +40 -0
- package/templates/document/core/pdf-options.d.ts +9 -0
- package/templates/document/core/pdf-options.js +36 -0
- package/templates/document/core/pdf-worker.d.ts +24 -0
- package/templates/document/core/pdf-worker.js +122 -0
- package/templates/document/core/pdf.d.ts +12 -0
- package/templates/document/core/pdf.js +190 -0
- package/templates/document/core/pptx-edit.d.ts +14 -0
- package/templates/document/core/pptx-edit.js +137 -0
- package/templates/document/core/pptx-fonts.d.ts +5 -0
- package/templates/document/core/pptx-fonts.js +115 -0
- package/templates/document/core/pptx-media.d.ts +18 -0
- package/templates/document/core/pptx-media.js +83 -0
- package/templates/document/core/pptx-view.d.ts +5 -0
- package/templates/document/core/pptx-view.js +185 -0
- package/templates/document/core/settings.d.ts +25 -0
- package/templates/document/core/settings.js +86 -0
- package/templates/document/core/slide-edges.d.ts +3 -0
- package/templates/document/core/slide-edges.js +82 -0
- package/templates/document/core/viewer.d.ts +28 -0
- package/templates/document/core/viewer.js +159 -0
- package/templates/document/edit.html +17 -0
- package/templates/document/gitignore +4 -0
- package/templates/document/index.html +18 -0
- package/templates/document/metadata.json +9 -0
- package/templates/document/package.json +17 -0
- package/templates/document/public/fonts/OFL-Caladea.txt +93 -0
- package/templates/document/public/fonts/OFL-Carlito.txt +93 -0
- package/templates/document/public/fonts/caladea-latin-400-normal.woff2 +0 -0
- package/templates/document/public/fonts/caladea-latin-700-normal.woff2 +0 -0
- package/templates/document/public/fonts/carlito-latin-400-normal.woff2 +0 -0
- package/templates/document/public/fonts/carlito-latin-700-normal.woff2 +0 -0
- package/templates/document/screens/edit.js +574 -0
- package/templates/document/screens/learn.js +61 -0
- package/templates/document/styles.css +644 -0
- package/templates/document/template.json +6 -0
- package/templates/document/ui/templates/edit.js +82 -0
- package/templates/document/ui/templates/page.js +11 -0
- package/templates/document/ui/templates/viewer.js +41 -0
- package/templates/document/ui/texts.d.ts +3 -0
- package/templates/document/ui/texts.js +62 -0
- package/templates/document/ui/theme.css +69 -0
- package/templates/quiz/README.md +11 -9
- package/templates/quiz/core/behaviors.d.ts +4 -0
- package/templates/quiz/core/behaviors.js +4 -2
- package/templates/quiz/core/editor.d.ts +17 -2
- package/templates/quiz/core/editor.js +85 -10
- package/templates/quiz/core/markdown.d.ts +15 -0
- package/templates/quiz/core/markdown.js +164 -4
- package/templates/quiz/core/model.d.ts +6 -2
- package/templates/quiz/core/model.js +30 -4
- package/templates/quiz/core/rich-text.d.ts +1 -2
- package/templates/quiz/core/rich-text.js +7 -59
- package/templates/quiz/public/img/mascot-half.webp +0 -0
- package/templates/quiz/screens/edit.js +165 -52
- package/templates/quiz/screens/learn.js +94 -38
- package/templates/quiz/styles.css +464 -4
- package/templates/quiz/template.json +1 -1
- package/templates/quiz/ui/templates/edit.d.ts +1 -0
- package/templates/quiz/ui/templates/edit.js +65 -9
- package/templates/quiz/ui/templates/page.js +14 -0
- package/templates/quiz/ui/templates/question.js +5 -3
- package/templates/quiz/ui/texts.js +38 -20
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
// 내용 편집 화면(CMS). 기존 퀴즈 편집 폼을 옮김 (docs/quiz-spec.md §3). 저장 버튼 · 변경 표시는 키트(useSave)가 합니다.
|
|
2
2
|
// 완료 정책은 LXP 자료 편집 화면의 '설정'에서 교육자가 고릅니다 (ADR 0012). 문항 카드마다 정답을 고르고 (단일 · 복수 · 그룹은 보기 줄에서
|
|
3
3
|
// 바로, 순서 · 주관식은 아래 "정답"에서), 저장할 때 고른 답으로 정답 정규식을 만들어 검증한 뒤 settings.grading에 함께 저장합니다.
|
|
4
|
-
// 채점 방식은
|
|
5
|
-
// - pattern
|
|
6
|
-
// - partial_pattern
|
|
7
|
-
//
|
|
4
|
+
// 채점 방식은 문제가 2개 이상일 때 맨 위 "부분 채점 허용"으로 고릅니다 (연주님 부분 채점 UI, 새 퀴즈는 끔):
|
|
5
|
+
// - 끔 · 문제 하나: pattern, 정답 정규식 하나 (모두 맞혀야 100점)
|
|
6
|
+
// - 켬: partial_pattern, 문항마다 정규식 + 배점 (맞은 문항 배점의 합, 최대 100). 배점은 자동(똑같이 나눔) 또는 카드 머리에서 직접.
|
|
7
|
+
// 학생 화면이 답을 배열로 내도록 settings에 gradingType을, 배점 표시용으로 pointsMode · 문제별 points도 같이 저장 (배점은 정답이 아님)
|
|
8
8
|
// 문제 내용(content)은 학생에게도 내려가므로 정답을 넣지 않습니다 (정답은 grading에만, 서버가 학생에게 내려주지 않음).
|
|
9
9
|
// 여기서는 어떤 칸을 어떤 순서로 놓을지만 정합니다. 모양은 ui/(templates/edit.js · texts · theme.css), 동작은 core/.
|
|
10
10
|
import {
|
|
11
11
|
ANSWER_KEY_MAX,
|
|
12
|
-
showSnackbar as showNotice,
|
|
13
|
-
splitScores,
|
|
14
12
|
start,
|
|
15
13
|
validateAnswerRegex,
|
|
16
14
|
validatePartialGrading,
|
|
17
15
|
} from "../lib/elice-content.js";
|
|
18
16
|
import { renderAnswerBody } from "../core/behaviors.js";
|
|
19
17
|
import { createEditor } from "../core/editor.js";
|
|
20
|
-
import {
|
|
21
|
-
|
|
18
|
+
import {
|
|
19
|
+
assetKeysIn,
|
|
20
|
+
loadAsset,
|
|
21
|
+
resolveAssets,
|
|
22
|
+
setAssetFailedText,
|
|
23
|
+
setImages,
|
|
24
|
+
} from "../core/markdown.js";
|
|
22
25
|
import {
|
|
23
26
|
buildAnswerKey,
|
|
24
27
|
buildAnswerKeys,
|
|
25
28
|
canAddQuestion,
|
|
29
|
+
equalPoints,
|
|
26
30
|
checkAnswerKey,
|
|
27
31
|
checkAnswerKeys,
|
|
28
32
|
gradingTypeOf,
|
|
@@ -39,6 +43,7 @@ import {
|
|
|
39
43
|
parseAnswerKeys,
|
|
40
44
|
pruneAnswer,
|
|
41
45
|
scoresFor,
|
|
46
|
+
totalPoints,
|
|
42
47
|
validateAnswerKey,
|
|
43
48
|
validateQuiz,
|
|
44
49
|
withOptionAnswer,
|
|
@@ -56,37 +61,47 @@ root.replaceChildren(loading());
|
|
|
56
61
|
const app = await start({ screen: "edit" });
|
|
57
62
|
const draft = structuredClone(app.content);
|
|
58
63
|
draft.questions ??= [];
|
|
59
|
-
//
|
|
64
|
+
// 1.9.0 전에 올린 그림 (아이디 → data: 주소, 내용 images). 그대로 보이고 지울 수 있다
|
|
60
65
|
setImages(draft.images);
|
|
66
|
+
/** 지문 · 해설 글들 */
|
|
67
|
+
const richTexts = () =>
|
|
68
|
+
draft.questions.flatMap((q) => [q.description, q.explanation?.text]).filter(Boolean);
|
|
69
|
+
// 서버에 올린 그림 을 받기 시작한다. 기다리지 않고 먼저 그리고, 받으면 그 자리만 그림으로
|
|
70
|
+
// (그림 하나 10초까지, 못 받으면 새로고침 안내)
|
|
71
|
+
setAssetFailedText(texts.learn.imageExpired);
|
|
72
|
+
void resolveAssets(richTexts(), app.assets.url);
|
|
61
73
|
|
|
62
74
|
/**
|
|
63
|
-
* 지문 · 해설에 그림 올리기 (서식 도구의 그림 버튼, 연주님 최종 수정본).
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
75
|
+
* 지문 · 해설에 그림 올리기 (서식 도구의 그림 버튼, 연주님 최종 수정본). 키트가 그림을 줄여(긴 변 2048px · WebP,
|
|
76
|
+
* EXIF · GPS 제거) 서버에 올리고(app.assets.uploadImage), 글에는 파일 키 만 둔다.
|
|
77
|
+
* settings에는 키만 들어가 서버 한도(약 64KB)에 걸리지 않는다. 퀴즈 전체 LIMITS.imagesMax개까지.
|
|
78
|
+
* 끄면(false) 버튼이 숨고, 이미 넣은 그림은 그대로 보이고 지울 수 있다
|
|
67
79
|
*/
|
|
68
|
-
const IMAGE_UPLOAD =
|
|
80
|
+
const IMAGE_UPLOAD = true;
|
|
69
81
|
const imageErrors = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
total: t.md.imageTotal,
|
|
82
|
+
upload_bad_type: t.md.imageNotImage,
|
|
83
|
+
upload_bad_file: t.md.imageTooBig,
|
|
84
|
+
image_unreadable: t.md.imageUnreadable,
|
|
74
85
|
};
|
|
75
|
-
/** 그림 올리기:
|
|
86
|
+
/** 그림 올리기: 올리고 그림 칸 참조(asset:파일키)를 돌려준다. 실패는 알림으로 */
|
|
76
87
|
const imageUpload = IMAGE_UPLOAD
|
|
77
88
|
? {
|
|
78
|
-
async add(file) {
|
|
79
|
-
|
|
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)
|
|
89
|
+
async add(file, onProgress) {
|
|
90
|
+
if (richTexts().flatMap(assetKeysIn).length >= LIMITS.imagesMax)
|
|
83
91
|
throw Object.assign(new Error("total"), { code: "total" });
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
const { asset_key } = await app.assets.uploadImage(file, {
|
|
93
|
+
onProgress: ({ loaded, total }) =>
|
|
94
|
+
onProgress(total > 0 ? Math.min(100, Math.round((loaded / total) * 100)) : 0),
|
|
95
|
+
});
|
|
96
|
+
await loadAsset(asset_key, app.assets.url);
|
|
97
|
+
return `asset:${asset_key}`;
|
|
88
98
|
},
|
|
89
|
-
fail: (error) =>
|
|
99
|
+
fail: (error) =>
|
|
100
|
+
showSnackbar(
|
|
101
|
+
error.code === "total"
|
|
102
|
+
? t.md.imageTotal(LIMITS.imagesMax)
|
|
103
|
+
: (imageErrors[error.code] ?? error.message ?? t.md.imageUnreadable),
|
|
104
|
+
),
|
|
90
105
|
}
|
|
91
106
|
: undefined;
|
|
92
107
|
/** 글 칸 사이 그림 칸: 지우면 되돌리기 알림 */
|
|
@@ -94,12 +109,9 @@ const imageBlocks = {
|
|
|
94
109
|
removeLabel: t.md.imageRemove,
|
|
95
110
|
onRemoved: (undo) => showSnackbar(t.md.imageDeleted, undo),
|
|
96
111
|
};
|
|
97
|
-
/** 글에서 쓰는 그림만 (지운 그림은 저장하지 않음) */
|
|
112
|
+
/** 글에서 쓰는 옛 그림만 (지운 그림은 저장하지 않음) */
|
|
98
113
|
function usedImages() {
|
|
99
|
-
const text =
|
|
100
|
-
.flatMap((q) => [q.description, q.explanation?.text])
|
|
101
|
-
.filter(Boolean)
|
|
102
|
-
.join("\n");
|
|
114
|
+
const text = richTexts().join("\n");
|
|
103
115
|
const used = new Set([...text.matchAll(/\(image:([\w-]+)\)/g)].map((m) => m[1]));
|
|
104
116
|
const kept = Object.fromEntries(Object.entries(draft.images ?? {}).filter(([id]) => used.has(id)));
|
|
105
117
|
return Object.keys(kept).length ? kept : undefined;
|
|
@@ -109,8 +121,23 @@ const startedEmpty = draft.questions.length === 0;
|
|
|
109
121
|
if (startedEmpty)
|
|
110
122
|
draft.questions.push(newQuestion("select_one", [], texts.defaults));
|
|
111
123
|
|
|
112
|
-
// 채점 방식: 저장된 settings.grading.type (없으면 settings.gradingType, 그것도 없으면 pattern).
|
|
113
|
-
|
|
124
|
+
// 채점 방식: 저장된 settings.grading.type (없으면 settings.gradingType, 그것도 없으면 pattern). "부분 채점 허용"으로 바꾼다
|
|
125
|
+
let partialOn = gradingTypeOf(app.content, app.grading) === PARTIAL;
|
|
126
|
+
/** 부분 채점이 실제로 걸리는지: 켜져 있고 문제가 2개 이상 (문제 하나면 설정이 보이지 않고 pattern으로 저장) */
|
|
127
|
+
const partialActive = () => partialOn && draft.questions.length > 1;
|
|
128
|
+
// 배점: 저장된 grading.scores가 원본 (정규식의 문제 id로 맞춰 지금 순서로). 맞추지 못하면(문제를 더하거나 지움) 자동 배점.
|
|
129
|
+
// 자동 · 직접은 공개 값 pointsMode, 없으면(1.7.x에 저장했거나 직접 쓴 settings) 저장된 배점이 자동 배점 값과 같을 때만 자동.
|
|
130
|
+
// 1.7.x가 똑같이 나눠 저장한 33 · 33 · 34는 직접 배점으로 열어 고치지 않으면 그대로 저장된다
|
|
131
|
+
if (partialOn) {
|
|
132
|
+
const saved = app.grading?.type === PARTIAL ? app.grading : undefined;
|
|
133
|
+
const { scores, resplit } = scoresFor(draft.questions, saved, equalPoints);
|
|
134
|
+
draft.questions.forEach((q, i) => (q.points = scores[i]));
|
|
135
|
+
const even = JSON.stringify(scores) === JSON.stringify(equalPoints(draft.questions.length));
|
|
136
|
+
draft.pointsMode =
|
|
137
|
+
!resplit && (draft.pointsMode === "custom" || (draft.pointsMode !== "equal" && !even))
|
|
138
|
+
? "custom"
|
|
139
|
+
: "equal";
|
|
140
|
+
}
|
|
114
141
|
|
|
115
142
|
// 문항 id → 정답(화면 값: 선택 id · id 목록 · 그룹별 목록, 주관식은 허용 답 목록). 저장된 정규식(partial_pattern은 문항별 배열)을 읽어 채운다
|
|
116
143
|
const rawKey = app.grading?.answer_key;
|
|
@@ -690,6 +717,8 @@ function questionFields(q, i) {
|
|
|
690
717
|
max: LIMITS.titleMax,
|
|
691
718
|
// 질문은 1000자까지라 글자 수 표시는 두지 않는다 (입력 제한은 그대로)
|
|
692
719
|
showCount: false,
|
|
720
|
+
// 길면 다음 줄로 넘겨 다 보이게, Shift+Enter로 줄바꿈 (Enter는 막음)
|
|
721
|
+
softWrap: true,
|
|
693
722
|
}),
|
|
694
723
|
// 문항 설명: 필요할 때만 "설명 추가 +"로 연다. 열리면 해설과 같은 머리줄(아이콘 · 이름 · 지우기). 새 문항에는 키가 없고, 적으면 생긴다
|
|
695
724
|
form.revealable(
|
|
@@ -737,7 +766,7 @@ function questionFields(q, i) {
|
|
|
737
766
|
t.placeholder,
|
|
738
767
|
q.placeholder ?? "",
|
|
739
768
|
(v) => (q.placeholder = v),
|
|
740
|
-
{ placeholder: t.placeholderInput, max: LIMITS.placeholderMax },
|
|
769
|
+
{ placeholder: t.placeholderInput, max: LIMITS.placeholderMax, singleLine: true },
|
|
741
770
|
),
|
|
742
771
|
{
|
|
743
772
|
open: Boolean(q.placeholder),
|
|
@@ -791,8 +820,17 @@ function questionCard(q, i) {
|
|
|
791
820
|
count: draft.questions.length,
|
|
792
821
|
types: Object.entries(texts.types),
|
|
793
822
|
body: questionFields(q, i),
|
|
823
|
+
// 부분 채점일 때만 카드 머리에 배점 칸
|
|
824
|
+
points: partialActive() ? (q.points ?? 0) : undefined,
|
|
794
825
|
},
|
|
795
826
|
{
|
|
827
|
+
// 배점을 고치면 직접 배점. 다시 그리지 않고 합계만 고친다 (입력 중 초점 유지)
|
|
828
|
+
points: (value) => {
|
|
829
|
+
q.points = Math.min(100, Math.max(0, Math.round(Number(value) || 0)));
|
|
830
|
+
draft.pointsMode = "custom";
|
|
831
|
+
updateScoreSum();
|
|
832
|
+
save?.markDirty();
|
|
833
|
+
},
|
|
796
834
|
type: (type) => {
|
|
797
835
|
readAnswerViews();
|
|
798
836
|
const prev = {
|
|
@@ -813,6 +851,8 @@ function questionCard(q, i) {
|
|
|
813
851
|
...newQuestion(type, [], texts.defaults),
|
|
814
852
|
id: q.id,
|
|
815
853
|
title: q.title,
|
|
854
|
+
// 배점은 유형을 바꿔도 그대로
|
|
855
|
+
...(q.points === undefined ? {} : { points: q.points }),
|
|
816
856
|
};
|
|
817
857
|
delete answers[q.id];
|
|
818
858
|
const picked = defaultAnswer(draft.questions[i]);
|
|
@@ -879,11 +919,70 @@ function showSnackbar(text, restore) {
|
|
|
879
919
|
snackbarTimer = setTimeout(hideSnackbar, SNACKBAR_MS);
|
|
880
920
|
}
|
|
881
921
|
|
|
922
|
+
/** 부분 채점 배점 맞추기: 자동 배점이면 문제마다 ceil(100 / 문제 수)(equalPoints), 직접 배점이면 빈 배점을 0으로 */
|
|
923
|
+
function syncPoints() {
|
|
924
|
+
if (!partialActive()) return;
|
|
925
|
+
if (draft.pointsMode !== "custom") {
|
|
926
|
+
const scores = equalPoints(draft.questions.length);
|
|
927
|
+
draft.questions.forEach((q, i) => (q.points = scores[i]));
|
|
928
|
+
draft.pointsMode = "equal";
|
|
929
|
+
} else
|
|
930
|
+
for (const q of draft.questions) if (!Number.isInteger(q.points)) q.points = 0;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** 부분 채점 설정 상자 (문제가 2개 이상일 때 맨 위). 켜고 끄기 · 동일 점수로 되돌리기 */
|
|
934
|
+
let scoreBox = null;
|
|
935
|
+
function scoreSettings() {
|
|
936
|
+
const box = templates.scoreSettings({ partial: partialOn });
|
|
937
|
+
const part = (role) => box.querySelector(`[data-role="${role}"]`);
|
|
938
|
+
part("partial").addEventListener("change", (e) => {
|
|
939
|
+
partialOn = e.target.checked;
|
|
940
|
+
if (!partialOn) delete draft.pointsMode;
|
|
941
|
+
render();
|
|
942
|
+
});
|
|
943
|
+
part("equal").addEventListener("click", () => {
|
|
944
|
+
draft.pointsMode = "equal";
|
|
945
|
+
render();
|
|
946
|
+
});
|
|
947
|
+
return box;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/** 배점 합계 줄: 자동이면 안내 한 줄, 직접이면 "합계 N / 100점"과 모자람(오류) · 넘침(안내) */
|
|
951
|
+
function updateScoreSum() {
|
|
952
|
+
if (!scoreBox) return;
|
|
953
|
+
const part = (role) => scoreBox.querySelector(`[data-role="${role}"]`);
|
|
954
|
+
const sum = scoreBox.querySelector('[data-role="sum"]');
|
|
955
|
+
const total = part("total");
|
|
956
|
+
const note = part("note");
|
|
957
|
+
const equal = draft.pointsMode !== "custom";
|
|
958
|
+
if (sum) sum.dataset.mode = equal ? "equal" : "custom";
|
|
959
|
+
const button = part("equal");
|
|
960
|
+
button.hidden = equal;
|
|
961
|
+
part("mode").textContent = equal ? t.scoring.modeEqual : t.scoring.modeCustom;
|
|
962
|
+
if (equal) {
|
|
963
|
+
total.textContent = t.scoring.equalLine;
|
|
964
|
+
total.dataset.state = "ok";
|
|
965
|
+
note.textContent = "";
|
|
966
|
+
note.dataset.state = "";
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
const points = totalPoints(draft.questions);
|
|
970
|
+
const state = points < 100 ? "under" : points > 100 ? "over" : "ok";
|
|
971
|
+
total.textContent = t.scoring.total(points);
|
|
972
|
+
total.dataset.state = state;
|
|
973
|
+
note.textContent = state === "under" ? t.scoring.under : state === "over" ? t.scoring.over : "";
|
|
974
|
+
note.dataset.state = state === "under" ? "under" : "";
|
|
975
|
+
}
|
|
976
|
+
|
|
882
977
|
function render() {
|
|
883
978
|
readAnswerViews();
|
|
884
979
|
answerViews.clear();
|
|
980
|
+
syncPoints();
|
|
981
|
+
scoreBox = draft.questions.length > 1 ? scoreSettings() : null;
|
|
885
982
|
const cards = draft.questions.map(questionCard);
|
|
886
983
|
root.replaceChildren(
|
|
984
|
+
// 부분 채점 설정은 문제가 2개 이상일 때만 맨 위에
|
|
985
|
+
...(scoreBox ? [scoreBox] : []),
|
|
887
986
|
// 저장된 정답을 못 읽었을 때만 맨 위에 경고
|
|
888
987
|
...(unreadable ? [templates.answersIntro({ text: a.unreadable })] : []),
|
|
889
988
|
// 퀴즈 제목 · 안내 칸은 두지 않는다 (연주님 최종 수정본). 예전에 저장한 title · description은 draft에 그대로 남아 같이 저장된다
|
|
@@ -896,6 +995,9 @@ function render() {
|
|
|
896
995
|
draft.questions.map((q) => q.id),
|
|
897
996
|
texts.defaults,
|
|
898
997
|
);
|
|
998
|
+
// 직접 배점이면 새 문제는 100점까지 남은 배점으로 (자동 배점은 다시 나눔)
|
|
999
|
+
if (partialActive() && draft.pointsMode === "custom")
|
|
1000
|
+
added.points = Math.max(0, 100 - totalPoints(draft.questions));
|
|
899
1001
|
draft.questions.push(added);
|
|
900
1002
|
const picked = defaultAnswer(added);
|
|
901
1003
|
if (picked !== undefined) answers[added.id] = picked;
|
|
@@ -903,6 +1005,7 @@ function render() {
|
|
|
903
1005
|
})
|
|
904
1006
|
: templates.questionLimit({ text: t.questionLimit }),
|
|
905
1007
|
);
|
|
1008
|
+
updateScoreSum();
|
|
906
1009
|
save?.markDirty();
|
|
907
1010
|
}
|
|
908
1011
|
|
|
@@ -937,9 +1040,9 @@ function markAnswerError(card, message) {
|
|
|
937
1040
|
}
|
|
938
1041
|
|
|
939
1042
|
/**
|
|
940
|
-
* partial_pattern 채점 설정: 문항마다 정답 정규식(서버 한도 ANSWER_KEY_MAX는 문항 하나에 걸림)과
|
|
941
|
-
* 검증(정규식 공통 검사 → 문항별 왕복 · 오답)을 통과해야 저장한다.
|
|
942
|
-
*
|
|
1043
|
+
* partial_pattern 채점 설정: 문항마다 정답 정규식(서버 한도 ANSWER_KEY_MAX는 문항 하나에 걸림)과 배점(문제별 points).
|
|
1044
|
+
* 검증(정규식 공통 검사 → 문항별 왕복 · 오답 → 배점 규칙)을 통과해야 저장한다. 배점 규칙(0~100 정수, 합 100 이상)은
|
|
1045
|
+
* 저장 전 validateQuiz가 먼저 막는다
|
|
943
1046
|
*/
|
|
944
1047
|
function partialGrading(questions) {
|
|
945
1048
|
const keys = buildAnswerKeys(questions, answers);
|
|
@@ -969,14 +1072,10 @@ function partialGrading(questions) {
|
|
|
969
1072
|
}
|
|
970
1073
|
const keyProblem = checkAnswerKeys(questions, answers, keys, a.validation);
|
|
971
1074
|
if (keyProblem) return problemAt(keyProblem, { answer: true });
|
|
972
|
-
//
|
|
973
|
-
const
|
|
974
|
-
|
|
975
|
-
if (
|
|
976
|
-
scores = splitScores(questions.length);
|
|
977
|
-
resplit = true;
|
|
978
|
-
}
|
|
979
|
-
if (resplit) showNotice({ text: t.scoresSplit(scores) });
|
|
1075
|
+
// 배점은 문제 카드에 붙어 있어 문제 순서를 바꿔도 제 문제를 따라간다
|
|
1076
|
+
const scores = questions.map((q) => q.points);
|
|
1077
|
+
const problem = validatePartialGrading({ answer_key: keys, scores });
|
|
1078
|
+
if (problem) return problem;
|
|
980
1079
|
return { type: PARTIAL, answer_key: keys, scores };
|
|
981
1080
|
}
|
|
982
1081
|
|
|
@@ -985,19 +1084,33 @@ render();
|
|
|
985
1084
|
root.classList.add("qz-enter");
|
|
986
1085
|
save = app.useSave({
|
|
987
1086
|
label: t.done,
|
|
988
|
-
// partial_pattern이면 학생 화면이 답을 문항별 배열로 내도록 공개 값 gradingType
|
|
1087
|
+
// partial_pattern이면 학생 화면이 답을 문항별 배열로 내도록 공개 값 gradingType과 배점 표시(pointsMode · points)를 같이 저장 (정답은 아님)
|
|
989
1088
|
getContent: () => {
|
|
990
1089
|
const content = structuredClone(draft);
|
|
991
1090
|
const images = usedImages();
|
|
992
1091
|
if (images) content.images = images;
|
|
993
1092
|
else delete content.images;
|
|
994
|
-
if (
|
|
995
|
-
else
|
|
1093
|
+
if (partialActive()) content.gradingType = PARTIAL;
|
|
1094
|
+
else {
|
|
1095
|
+
delete content.gradingType;
|
|
1096
|
+
delete content.pointsMode;
|
|
1097
|
+
for (const q of content.questions) delete q.points;
|
|
1098
|
+
}
|
|
996
1099
|
return content;
|
|
997
1100
|
},
|
|
998
1101
|
validate: (content) => {
|
|
999
1102
|
const problem = validateQuiz(content, texts.validation);
|
|
1000
1103
|
if (!problem) return true;
|
|
1104
|
+
// 배점 문제: 그 문제의 배점 칸(합계면 첫 배점 칸)으로 옮기고 초점. 합계 줄은 이미 빨갛게 보인다
|
|
1105
|
+
if (problem.field === "points") {
|
|
1106
|
+
const target =
|
|
1107
|
+
problem.questionIndex >= 0
|
|
1108
|
+
? form.cardAt(problem.questionIndex)?.querySelector('[data-role="points"]')
|
|
1109
|
+
: root.querySelector('[data-role="points"]');
|
|
1110
|
+
(problem.questionIndex >= 0 ? target : scoreBox)?.scrollIntoView({ block: "center" });
|
|
1111
|
+
target?.focus({ preventScroll: true });
|
|
1112
|
+
return problem.message;
|
|
1113
|
+
}
|
|
1001
1114
|
// 라벨이 없으니 비운 필수 칸(질문)에 빨간 밑줄을 긋고, 걸린 칸에 초점을 둔다
|
|
1002
1115
|
form.markEmptyRequired();
|
|
1003
1116
|
const invalid = form
|
|
@@ -1014,7 +1127,7 @@ save = app.useSave({
|
|
|
1014
1127
|
const { questions } = draft;
|
|
1015
1128
|
const missing = validateAnswerKey(questions, answers, a.validation);
|
|
1016
1129
|
if (missing) return problemAt(missing, { answer: true });
|
|
1017
|
-
if (
|
|
1130
|
+
if (partialActive()) return partialGrading(questions);
|
|
1018
1131
|
const answerKey = buildAnswerKey(questions, answers);
|
|
1019
1132
|
// 정답 정규식은 서버 한도(ANSWER_KEY_MAX)가 퀴즈 전체에 걸린다. 한글 주관식은 한 글자가 9자로 늘어
|
|
1020
1133
|
// 몇 문항이면 넘으므로, 정규식에서 가장 긴 문항으로 옮기고 무엇을 줄일지 알려 준다
|
|
@@ -3,7 +3,13 @@
|
|
|
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 {
|
|
6
|
+
import {
|
|
7
|
+
ASSET_FILLED_EVENT,
|
|
8
|
+
ASSET_TIMEOUT_MS,
|
|
9
|
+
resolveAssets,
|
|
10
|
+
setAssetFailedText,
|
|
11
|
+
setImages,
|
|
12
|
+
} from '../core/markdown.js';
|
|
7
13
|
import {
|
|
8
14
|
decodeAnswer,
|
|
9
15
|
isAnswered,
|
|
@@ -13,7 +19,7 @@ import {
|
|
|
13
19
|
splitAnswers,
|
|
14
20
|
} from '../core/model.js';
|
|
15
21
|
import { labels, templates } from '../ui/templates/index.js';
|
|
16
|
-
import { loading, someWrong } from '../ui/templates/page.js';
|
|
22
|
+
import { loading, partialScore, someWrong } from '../ui/templates/page.js';
|
|
17
23
|
import { texts } from '../ui/texts.js';
|
|
18
24
|
|
|
19
25
|
const root = document.getElementById('app');
|
|
@@ -22,16 +28,69 @@ root.replaceChildren(loading());
|
|
|
22
28
|
const app = await start({ screen: 'learn' });
|
|
23
29
|
// 편집 화면에서 아직 내용을 저장하지 않았으면 키트 빈 안내만 보인다 (기본 문항은 없음, 모든 템플릿 공통 모양 · 문구,
|
|
24
30
|
// 교육자 · 튜터도 같은 문구 — 연주님 최종 수정본)
|
|
25
|
-
if (app.hasContent)
|
|
26
|
-
|
|
31
|
+
if (app.hasContent) {
|
|
32
|
+
// 편집 화면에서 지문 · 해설에 올린 그림 을 받기 시작한다. 기다리지 않고 문항을 먼저 그리고,
|
|
33
|
+
// 받으면 그 자리만 그림으로 바꾼다 (그림 하나 10초까지, 못 받으면 새로고침 안내). 해설 그림도 같이 받아 두어 제출 뒤 바로 보인다
|
|
34
|
+
setAssetFailedText(texts.learn.imageExpired);
|
|
35
|
+
void resolveAssets(
|
|
36
|
+
(app.content.questions ?? []).flatMap((q) => [q.description, q.explanation?.text]),
|
|
37
|
+
app.assets.url,
|
|
38
|
+
);
|
|
39
|
+
show();
|
|
40
|
+
} else root.replaceChildren(app.emptyState());
|
|
41
|
+
// 그림이 깨지면(받은 blob이 그림이 아님 등) 그 자리에 새로고침 안내 (error는 거품이 없어 capture로)
|
|
42
|
+
root.addEventListener(
|
|
43
|
+
'error',
|
|
44
|
+
(e) => {
|
|
45
|
+
const img = e.target;
|
|
46
|
+
if (!(img instanceof HTMLImageElement) || !img.dataset.asset) return;
|
|
47
|
+
const notice = document.createElement('span');
|
|
48
|
+
notice.className = 'qz-image-missing';
|
|
49
|
+
notice.setAttribute('role', 'alert');
|
|
50
|
+
notice.textContent = texts.learn.imageExpired;
|
|
51
|
+
img.replaceWith(notice);
|
|
52
|
+
},
|
|
53
|
+
true,
|
|
54
|
+
);
|
|
55
|
+
// 제출 뒤 맨 아래로(scrollOnResult 'bottom'): 키트는 그때 이미 있는 <img>만 기다린다. 아직 받는 중이던 올린 그림(해설 그림 등)이
|
|
56
|
+
// 그림 한도(10초) 안에 들어오면 한 번 더 맨 아래로 맞춘다. 학생이 직접 스크롤하면 따라가지 않는다
|
|
57
|
+
let followUntil = 0;
|
|
58
|
+
document.addEventListener(
|
|
59
|
+
'click',
|
|
60
|
+
(e) => {
|
|
61
|
+
if (e.target instanceof Element && e.target.closest('.ec-submitbar button'))
|
|
62
|
+
followUntil = Date.now() + ASSET_TIMEOUT_MS + 3000;
|
|
63
|
+
},
|
|
64
|
+
true,
|
|
65
|
+
);
|
|
66
|
+
for (const type of ['wheel', 'touchmove'])
|
|
67
|
+
addEventListener(type, () => (followUntil = 0), { passive: true });
|
|
68
|
+
document.addEventListener(ASSET_FILLED_EVENT, (e) => {
|
|
69
|
+
const element = e.detail?.element;
|
|
70
|
+
if (Date.now() > followUntil || !(element instanceof HTMLImageElement) || !root.contains(element))
|
|
71
|
+
return;
|
|
72
|
+
const go = () => {
|
|
73
|
+
const reduce =
|
|
74
|
+
typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
75
|
+
const page = document.scrollingElement ?? document.documentElement;
|
|
76
|
+
page.scrollTo?.({ top: page.scrollHeight, behavior: reduce ? 'auto' : 'smooth' });
|
|
77
|
+
};
|
|
78
|
+
if (element.complete) go();
|
|
79
|
+
else element.addEventListener('load', go, { once: true });
|
|
80
|
+
});
|
|
27
81
|
// 불러오는 자리에서 내용으로 바뀔 때 살짝 나타나게 (styles.css .qz-enter)
|
|
28
82
|
root.classList.add('qz-enter');
|
|
29
83
|
|
|
30
84
|
function show() {
|
|
31
85
|
// 퀴즈 제목 · 안내는 보이지 않는다 (연주님 최종 수정본: 문제부터 바로). 예전에 저장한 값은 settings에 그대로
|
|
32
86
|
const { questions = [] } = app.content;
|
|
33
|
-
// 편집
|
|
87
|
+
// 1.9.0 전 편집 화면이 지문 · 해설에 넣은 그림 (글에는 , 그림은 내용 images에 data: 주소로)
|
|
34
88
|
setImages(app.content.images);
|
|
89
|
+
// 답 모양은 채점 방식을 따른다 (학생 화면은 grading을 받지 못해 편집 화면이 같이 저장한 공개 값 gradingType으로 안다):
|
|
90
|
+
// pattern은 문자열 하나 "q1=b;q2=a,d;…" (ADR 0008 · 0009), partial_pattern은 문항별 배열 ["q1=b", "q2=a,d", …]
|
|
91
|
+
const partial = app.content.gradingType === PARTIAL;
|
|
92
|
+
// 부분 채점 · 직접 배점이면 문제 제목 옆에 배점 (자동 배점은 보이지 않음, 연주님 부분 채점 UI)
|
|
93
|
+
const showPoints = partial && questions.length > 1 && app.content.pointsMode === 'custom';
|
|
35
94
|
// 문항 유형은 보이지 않는다 (무엇을 할지는 질문 문장이 알려 줌). 교육자도 이 화면에서 풀어 본다 (교육자 화면 없음)
|
|
36
95
|
const views = questions.map((q, i) =>
|
|
37
96
|
renderQuestion(q, i, {
|
|
@@ -39,15 +98,13 @@ function show() {
|
|
|
39
98
|
labels: { ...labels, types: null },
|
|
40
99
|
// 문제가 하나면 번호 없이 제목만 (연주님 최종 수정본)
|
|
41
100
|
single: questions.length === 1,
|
|
101
|
+
points: showPoints,
|
|
42
102
|
seed: app.account?.anonymousId ?? '',
|
|
43
103
|
}),
|
|
44
104
|
);
|
|
45
105
|
|
|
46
106
|
root.replaceChildren(...views.map((v) => v.el));
|
|
47
107
|
|
|
48
|
-
// 답 모양은 채점 방식을 따른다 (학생 화면은 grading을 받지 못해 편집 화면이 같이 저장한 공개 값 gradingType으로 안다):
|
|
49
|
-
// pattern은 문자열 하나 "q1=b;q2=a,d;…" (ADR 0008 · 0009), partial_pattern은 문항별 배열 ["q1=b", "q2=a,d", …]
|
|
50
|
-
const partial = app.content.gradingType === PARTIAL;
|
|
51
108
|
/**
|
|
52
109
|
* 문제별 맞음 (partial_pattern), 지금 문제 순서대로. answerCorrectness[i]는 낸 답 answer[i]의 맞음이고 answer[i]는 "문제id=답"이라
|
|
53
110
|
* 문제 id로 맞춘다 (제출 뒤 교육자가 문제 순서를 바꿔도 표시가 제 문제에). 다시 열 때는 마지막 제출 기록의 answer,
|
|
@@ -65,17 +122,33 @@ function show() {
|
|
|
65
122
|
if (byId.size !== questions.length || questions.some((q) => !byId.has(q.id))) return null;
|
|
66
123
|
return questions.map((q) => byId.get(q.id));
|
|
67
124
|
};
|
|
68
|
-
//
|
|
69
|
-
// 여러 문제 중 틀린 것이 있으면
|
|
70
|
-
|
|
125
|
+
// 키트 점수 줄(정답 · 오답)은 감추고 문제 카드의 정답 · 오답과 제출 바 위 상자(.qz-overall)로 알린다 (styles.css, 연주님 디자인).
|
|
126
|
+
// pattern: 여러 문제 중 틀린 것이 있으면 한 줄 (어느 문제인지는 pattern이 알려 주지 않음).
|
|
127
|
+
// partial_pattern: 100점보다 낮으면 점수 · "아쉬워요!" · 마스코트 상자, 100점이면 상자 없음
|
|
71
128
|
const overall = someWrong();
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
129
|
+
const wrongText = overall.textContent;
|
|
130
|
+
const hideOverall = () => {
|
|
131
|
+
overall.hidden = true;
|
|
132
|
+
delete overall.dataset.result;
|
|
133
|
+
overall.classList.remove('qz-overall-mascot');
|
|
134
|
+
};
|
|
135
|
+
const showWrong = () => {
|
|
136
|
+
overall.classList.remove('qz-overall-mascot');
|
|
137
|
+
overall.textContent = wrongText;
|
|
138
|
+
overall.dataset.result = 'wrong';
|
|
139
|
+
overall.hidden = false;
|
|
140
|
+
};
|
|
141
|
+
const showScore = (score) => {
|
|
142
|
+
if (score >= 100) return hideOverall();
|
|
143
|
+
overall.replaceChildren(partialScore({ score }));
|
|
144
|
+
overall.classList.add('qz-overall-mascot');
|
|
145
|
+
overall.dataset.result = 'partial';
|
|
146
|
+
overall.hidden = false;
|
|
76
147
|
};
|
|
77
148
|
app.useSubmit({
|
|
78
149
|
label: texts.learn.submit,
|
|
150
|
+
// 제출하면 결과(점수 상자 · 제출 바)가 있는 맨 아래로 (성공 · 실패 모두, 단건 · 여러 문항 · pattern · partial_pattern 같음)
|
|
151
|
+
scrollOnResult: 'bottom',
|
|
79
152
|
getAnswer: () => {
|
|
80
153
|
const values = views.map((v) => v.getValue());
|
|
81
154
|
return partial ? joinAnswerList(questions, values) : joinAnswers(questions, values);
|
|
@@ -89,18 +162,10 @@ function show() {
|
|
|
89
162
|
if (left < 0) return true;
|
|
90
163
|
return questions.length === 1 ? texts.learn.unansweredSingle : texts.learn.unanswered(left + 1);
|
|
91
164
|
},
|
|
92
|
-
// 결과 줄(partial_pattern만 보임): 문제별 맞음이 있으면 점수와 틀린 문제 번호. 맞음 · 채점 안 함은 키트 기본 문장
|
|
93
|
-
resultText: (res) => {
|
|
94
|
-
if (res.isCorrect !== false || typeof res.score !== 'number') return undefined;
|
|
95
|
-
const marks = correctnessOf(res);
|
|
96
|
-
if (!marks) return undefined;
|
|
97
|
-
const wrong = marks.flatMap((ok, i) => (ok ? [] : [i + 1]));
|
|
98
|
-
return texts.learn.partial(res.score, marks.length - wrong.length, marks.length, wrong);
|
|
99
|
-
},
|
|
100
165
|
// partial_pattern이면 서버가 문항별 맞음 answerCorrectness를 준다 (제출 직후 · 다시 열 때 마지막 제출 기록에서).
|
|
101
166
|
// 문제 id로 맞춘 결과가 있으면 문제마다 정답 · 오답을 표시한다. 없거나([] = pattern · rubric) 맞추지 못하면 전체 결과만:
|
|
102
167
|
// 문항이 하나면 그 결과가 곧 문항의 정답 · 오답, 여러 문항이면 모두 맞았을 때만 정답 표시. 해설은 한 번이라도 제출하면
|
|
103
|
-
onResult: (res
|
|
168
|
+
onResult: (res) => {
|
|
104
169
|
const single = views.length === 1;
|
|
105
170
|
const items = correctnessOf(res);
|
|
106
171
|
views.forEach((v, i) => {
|
|
@@ -109,9 +174,10 @@ function show() {
|
|
|
109
174
|
else v.setResult(single ? correct : correct === true ? true : null);
|
|
110
175
|
v.showExplanation();
|
|
111
176
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
177
|
+
if (partial && typeof res.score === 'number') showScore(res.score);
|
|
178
|
+
else if (!partial && !single && res.isCorrect === false) showWrong();
|
|
179
|
+
else hideOverall();
|
|
180
|
+
// 만점 축하(토끼 · 소리)는 LXP가 서버 점수 변경(소켓)을 받아 보인다. 콘텐츠는 제출만 하면 된다
|
|
115
181
|
},
|
|
116
182
|
});
|
|
117
183
|
document.querySelector('.ec-submitbar')?.before(overall);
|
|
@@ -124,16 +190,6 @@ function show() {
|
|
|
124
190
|
const i = card ? questions.findIndex((q) => q.id === card.dataset.id) : -1;
|
|
125
191
|
if (i < 0 || app.readOnly) return;
|
|
126
192
|
views[i].setResult(null);
|
|
127
|
-
|
|
193
|
+
hideOverall();
|
|
128
194
|
}
|
|
129
195
|
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 방금 낸 답이 만점(100점)일 때 한 번 불린다 (다시 열 때 지난 기록으로는 불리지 않음).
|
|
133
|
-
* 만점 축하 토끼 · 소리는 콘텐츠가 보이지 않고 호스트(elice-web)가 보인다: elice-web에 같은 토끼 애니메이션
|
|
134
|
-
* (MaterialRabbitAnimation) · 소리와 기관별 켜고 끄는 설정이 있다. 콘텐츠가 호스트에 알리는 SDK 이벤트는 아직
|
|
135
|
-
* 정하지 않았으므로 지금은 아무것도 하지 않는다. 정해지면 그 SDK 호출 한 줄을 여기에 넣는다
|
|
136
|
-
*/
|
|
137
|
-
function onPerfectScore() {
|
|
138
|
-
// 호스트에 알리는 SDK 이벤트가 정해지면 여기서 부른다 (정하기 전에는 없는 API를 부르지 않는다)
|
|
139
|
-
}
|