@eliceio/cdk-cli 1.2.1 → 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.
Files changed (169) hide show
  1. package/README.md +63 -53
  2. package/es/cli.js +11 -2
  3. package/es/commands/build/index.js +12 -0
  4. package/es/commands/create/index.js +2 -0
  5. package/es/commands/create/scaffold.d.ts +2 -2
  6. package/es/commands/create/scaffold.js +3 -3
  7. package/es/commands/dev/index.d.ts +10 -1
  8. package/es/commands/dev/index.js +47 -7
  9. package/es/commands/doctor/index.js +6 -2
  10. package/es/core/config.d.ts +42 -9
  11. package/es/core/config.js +217 -12
  12. package/es/core/project-check.d.ts +3 -2
  13. package/es/core/project-check.js +14 -3
  14. package/es/core/regex.d.ts +11 -0
  15. package/es/core/regex.js +41 -0
  16. package/es/core/sandbox.d.ts +26 -0
  17. package/es/core/sandbox.js +240 -30
  18. package/es/dev/assets.d.ts +80 -0
  19. package/es/dev/assets.js +240 -0
  20. package/es/dev/check.d.ts +30 -0
  21. package/es/dev/check.js +224 -34
  22. package/es/dev/grading.d.ts +49 -14
  23. package/es/dev/grading.js +109 -29
  24. package/es/dev/host-page.js +27 -3
  25. package/es/dev/inject.d.ts +2 -1
  26. package/es/dev/inject.js +10 -2
  27. package/es/dev/mock-api.d.ts +26 -3
  28. package/es/dev/mock-api.js +219 -40
  29. package/es/dev/server.d.ts +12 -1
  30. package/es/dev/server.js +115 -9
  31. package/es/engines/vite/index.js +1 -1
  32. package/es/engines/vite/plugin.d.ts +2 -0
  33. package/es/engines/vite/plugin.js +33 -5
  34. package/es/rules/answers.d.ts +13 -0
  35. package/es/rules/answers.js +94 -0
  36. package/es/rules/check.js +70 -1
  37. package/es/rules/index.d.ts +1 -0
  38. package/es/rules/index.js +1 -0
  39. package/es/rules/size.d.ts +31 -0
  40. package/es/rules/size.js +58 -0
  41. package/es/rules/types.d.ts +12 -0
  42. package/es/rules.json.js +2 -2
  43. package/package.json +2 -2
  44. package/rules.json +34 -5
  45. package/skills/_shared/always.md +3 -3
  46. package/skills/_shared/references/00-what-the-person-decides.md +1 -1
  47. package/skills/_shared/references/02-design-the-material.md +10 -7
  48. package/skills/_shared/references/03-create-the-project.md +10 -8
  49. package/skills/_shared/references/04-rules.md +1 -1
  50. package/skills/_shared/references/05-screen-code.md +52 -23
  51. package/skills/_shared/references/06-using-the-quiz-template.md +7 -6
  52. package/skills/_shared/references/08-fix-check-errors.md +23 -22
  53. package/skills/_shared/references/09-check.md +8 -6
  54. package/skills/_shared/references/12-upload-with-the-material-mcp.md +13 -13
  55. package/skills/_shared/references/13-edit-screen-design.md +122 -0
  56. package/skills/_shared/references/14-layouts.md +96 -0
  57. package/skills/elice-content-check/SKILL.md +2 -2
  58. package/skills/elice-content-create/SKILL.md +1 -1
  59. package/skills/elice-content-migrate/SKILL.md +1 -1
  60. package/skills/elice-content-publish/SKILL.md +1 -1
  61. package/templates/_shared/lib/cdk-mock.d.ts +47 -3
  62. package/templates/_shared/lib/cdk-mock.js +293 -15
  63. package/templates/_shared/lib/elice-content-editor.js +89 -58
  64. package/templates/_shared/lib/elice-content.css +1313 -126
  65. package/templates/_shared/lib/elice-content.d.ts +222 -23
  66. package/templates/_shared/lib/elice-content.js +1176 -88
  67. package/templates/_shared/lib/icons/empty-content.d.ts +2 -0
  68. package/templates/_shared/lib/icons/empty-content.js +11 -0
  69. package/templates/_shared/lib/icons/file-video.d.ts +2 -0
  70. package/templates/_shared/lib/icons/file-video.js +11 -0
  71. package/templates/_shared/lib/icons/file.d.ts +2 -0
  72. package/templates/_shared/lib/icons/file.js +11 -0
  73. package/templates/blank/README.md +6 -4
  74. package/templates/blank/edit.html +8 -2
  75. package/templates/blank/index.html +6 -1
  76. package/templates/blank/instructor.html +6 -1
  77. package/templates/blank/screens/instructor.js +8 -2
  78. package/templates/blank/screens/learn.js +1 -1
  79. package/templates/blank/template.json +1 -1
  80. package/templates/document/README.md +92 -0
  81. package/templates/document/commentary.txt +2 -0
  82. package/templates/document/core/dom.d.ts +13 -0
  83. package/templates/document/core/dom.js +83 -0
  84. package/templates/document/core/file-type.d.ts +21 -0
  85. package/templates/document/core/file-type.js +85 -0
  86. package/templates/document/core/group-3d.d.ts +20 -0
  87. package/templates/document/core/group-3d.js +256 -0
  88. package/templates/document/core/inline-edit.d.ts +15 -0
  89. package/templates/document/core/inline-edit.js +377 -0
  90. package/templates/document/core/load.d.ts +13 -0
  91. package/templates/document/core/load.js +40 -0
  92. package/templates/document/core/pdf-options.d.ts +9 -0
  93. package/templates/document/core/pdf-options.js +36 -0
  94. package/templates/document/core/pdf-worker.d.ts +24 -0
  95. package/templates/document/core/pdf-worker.js +122 -0
  96. package/templates/document/core/pdf.d.ts +12 -0
  97. package/templates/document/core/pdf.js +190 -0
  98. package/templates/document/core/pptx-edit.d.ts +14 -0
  99. package/templates/document/core/pptx-edit.js +137 -0
  100. package/templates/document/core/pptx-fonts.d.ts +5 -0
  101. package/templates/document/core/pptx-fonts.js +115 -0
  102. package/templates/document/core/pptx-media.d.ts +18 -0
  103. package/templates/document/core/pptx-media.js +83 -0
  104. package/templates/document/core/pptx-view.d.ts +5 -0
  105. package/templates/document/core/pptx-view.js +185 -0
  106. package/templates/document/core/settings.d.ts +25 -0
  107. package/templates/document/core/settings.js +86 -0
  108. package/templates/document/core/slide-edges.d.ts +3 -0
  109. package/templates/document/core/slide-edges.js +82 -0
  110. package/templates/document/core/viewer.d.ts +28 -0
  111. package/templates/document/core/viewer.js +159 -0
  112. package/templates/document/edit.html +17 -0
  113. package/templates/document/gitignore +4 -0
  114. package/templates/document/index.html +18 -0
  115. package/templates/document/metadata.json +9 -0
  116. package/templates/document/package.json +17 -0
  117. package/templates/document/public/fonts/OFL-Caladea.txt +93 -0
  118. package/templates/document/public/fonts/OFL-Carlito.txt +93 -0
  119. package/templates/document/public/fonts/caladea-latin-400-normal.woff2 +0 -0
  120. package/templates/document/public/fonts/caladea-latin-700-normal.woff2 +0 -0
  121. package/templates/document/public/fonts/carlito-latin-400-normal.woff2 +0 -0
  122. package/templates/document/public/fonts/carlito-latin-700-normal.woff2 +0 -0
  123. package/templates/document/screens/edit.js +574 -0
  124. package/templates/document/screens/learn.js +61 -0
  125. package/templates/document/styles.css +644 -0
  126. package/templates/document/template.json +6 -0
  127. package/templates/document/ui/templates/edit.js +82 -0
  128. package/templates/document/ui/templates/page.js +11 -0
  129. package/templates/document/ui/templates/viewer.js +41 -0
  130. package/templates/document/ui/texts.d.ts +3 -0
  131. package/templates/document/ui/texts.js +62 -0
  132. package/templates/document/ui/theme.css +69 -0
  133. package/templates/quiz/README.md +32 -14
  134. package/templates/quiz/core/behaviors.d.ts +17 -7
  135. package/templates/quiz/core/behaviors.js +40 -53
  136. package/templates/quiz/core/editor.d.ts +27 -2
  137. package/templates/quiz/core/editor.js +412 -11
  138. package/templates/quiz/core/markdown.d.ts +19 -0
  139. package/templates/quiz/core/markdown.js +225 -11
  140. package/templates/quiz/core/model.d.ts +40 -3
  141. package/templates/quiz/core/model.js +112 -5
  142. package/templates/quiz/core/rich-text.d.ts +18 -0
  143. package/templates/quiz/core/rich-text.js +469 -0
  144. package/templates/quiz/edit.html +12 -3
  145. package/templates/quiz/index.html +12 -3
  146. package/templates/quiz/public/img/mascot-half.webp +0 -0
  147. package/templates/quiz/screens/edit.js +331 -49
  148. package/templates/quiz/screens/learn.js +147 -15
  149. package/templates/quiz/styles.css +1244 -622
  150. package/templates/quiz/template.json +9 -2
  151. package/templates/quiz/ui/templates/edit.d.ts +19 -5
  152. package/templates/quiz/ui/templates/edit.js +371 -77
  153. package/templates/quiz/ui/templates/group.js +19 -8
  154. package/templates/quiz/ui/templates/order.js +25 -24
  155. package/templates/quiz/ui/templates/page.js +33 -8
  156. package/templates/quiz/ui/templates/question.js +6 -4
  157. package/templates/quiz/ui/texts.js +91 -26
  158. package/templates/quiz/ui/theme.css +8 -9
  159. package/templates/steps/README.md +77 -0
  160. package/templates/steps/commentary.txt +7 -0
  161. package/templates/steps/edit.html +21 -0
  162. package/templates/steps/gitignore +4 -0
  163. package/templates/steps/index.html +69 -0
  164. package/templates/steps/metadata.json +9 -0
  165. package/templates/steps/package.json +13 -0
  166. package/templates/steps/screens/edit.js +32 -0
  167. package/templates/steps/screens/learn.js +108 -0
  168. package/templates/steps/styles.css +54 -0
  169. package/templates/steps/template.json +6 -0
@@ -1,28 +1,49 @@
1
1
  // 내용 편집 화면(CMS). 기존 퀴즈 편집 폼을 옮김 (docs/quiz-spec.md §3). 저장 버튼 · 변경 표시는 키트(useSave)가 합니다.
2
- // 퀴즈는 채점 방식 pattern 고정 (ADR 0009, 완료 정책은 LXP 자료 편집 화면의 '설정'에서 교육자가 고름, ADR 0012): 문항 카드마다 정답을
3
- // 고르고 (단일 · 복수 · 그룹은 보기 줄에서 바로, 순서 · 주관식은 아래 "정답"에서), 저장할 때 고른 답으로 정답 정규식 하나를 만들어 검증한 뒤 settings.grading에 함께 저장합니다.
2
+ // 완료 정책은 LXP 자료 편집 화면의 '설정'에서 교육자가 고릅니다 (ADR 0012). 문항 카드마다 정답을 고르고 (단일 · 복수 · 그룹은 보기 줄에서
3
+ // 바로, 순서 · 주관식은 아래 "정답"에서), 저장할 때 고른 답으로 정답 정규식을 만들어 검증한 뒤 settings.grading에 함께 저장합니다.
4
+ // 채점 방식은 문제가 2개 이상일 때 맨 위 "부분 채점 허용"으로 고릅니다 (연주님 부분 채점 UI, 새 퀴즈는 끔):
5
+ // - 끔 · 문제 하나: pattern, 정답 정규식 하나 (모두 맞혀야 100점)
6
+ // - 켬: partial_pattern, 문항마다 정규식 + 배점 (맞은 문항 배점의 합, 최대 100). 배점은 자동(똑같이 나눔) 또는 카드 머리에서 직접.
7
+ // 학생 화면이 답을 배열로 내도록 settings에 gradingType을, 배점 표시용으로 pointsMode · 문제별 points도 같이 저장 (배점은 정답이 아님)
4
8
  // 문제 내용(content)은 학생에게도 내려가므로 정답을 넣지 않습니다 (정답은 grading에만, 서버가 학생에게 내려주지 않음).
5
9
  // 여기서는 어떤 칸을 어떤 순서로 놓을지만 정합니다. 모양은 ui/(templates/edit.js · texts · theme.css), 동작은 core/.
6
10
  import {
7
11
  ANSWER_KEY_MAX,
8
12
  start,
9
13
  validateAnswerRegex,
14
+ validatePartialGrading,
10
15
  } from "../lib/elice-content.js";
11
16
  import { renderAnswerBody } from "../core/behaviors.js";
12
17
  import { createEditor } from "../core/editor.js";
18
+ import {
19
+ assetKeysIn,
20
+ loadAsset,
21
+ resolveAssets,
22
+ setAssetFailedText,
23
+ setImages,
24
+ } from "../core/markdown.js";
13
25
  import {
14
26
  buildAnswerKey,
27
+ buildAnswerKeys,
15
28
  canAddQuestion,
29
+ equalPoints,
16
30
  checkAnswerKey,
31
+ checkAnswerKeys,
32
+ gradingTypeOf,
17
33
  INLINE_ANSWER_TYPES,
18
34
  isAnswered,
35
+ joinAnswerList,
19
36
  joinAnswers,
20
37
  LIMITS,
21
38
  newQuestion,
22
39
  nextId,
23
40
  optionAnswer,
41
+ PARTIAL,
24
42
  parseAnswerKey,
43
+ parseAnswerKeys,
25
44
  pruneAnswer,
45
+ scoresFor,
46
+ totalPoints,
26
47
  validateAnswerKey,
27
48
  validateQuiz,
28
49
  withOptionAnswer,
@@ -40,14 +61,92 @@ root.replaceChildren(loading());
40
61
  const app = await start({ screen: "edit" });
41
62
  const draft = structuredClone(app.content);
42
63
  draft.questions ??= [];
64
+ // 1.9.0 전에 올린 그림 (아이디 → data: 주소, 내용 images). 그대로 보이고 지울 수 있다
65
+ setImages(draft.images);
66
+ /** 지문 · 해설 글들 */
67
+ const richTexts = () =>
68
+ draft.questions.flatMap((q) => [q.description, q.explanation?.text]).filter(Boolean);
69
+ // 서버에 올린 그림 ![설명](asset:파일키)을 받기 시작한다. 기다리지 않고 먼저 그리고, 받으면 그 자리만 그림으로
70
+ // (그림 하나 10초까지, 못 받으면 새로고침 안내)
71
+ setAssetFailedText(texts.learn.imageExpired);
72
+ void resolveAssets(richTexts(), app.assets.url);
73
+
74
+ /**
75
+ * 지문 · 해설에 그림 올리기 (서식 도구의 그림 버튼, 연주님 최종 수정본). 키트가 그림을 줄여(긴 변 2048px · WebP,
76
+ * EXIF · GPS 제거) 서버에 올리고(app.assets.uploadImage), 글에는 파일 키 ![](asset:파일키)만 둔다.
77
+ * settings에는 키만 들어가 서버 한도(약 64KB)에 걸리지 않는다. 퀴즈 전체 LIMITS.imagesMax개까지.
78
+ * 끄면(false) 버튼이 숨고, 이미 넣은 그림은 그대로 보이고 지울 수 있다
79
+ */
80
+ const IMAGE_UPLOAD = true;
81
+ const imageErrors = {
82
+ upload_bad_type: t.md.imageNotImage,
83
+ upload_bad_file: t.md.imageTooBig,
84
+ image_unreadable: t.md.imageUnreadable,
85
+ };
86
+ /** 그림 올리기: 올리고 그림 칸 참조(asset:파일키)를 돌려준다. 실패는 알림으로 */
87
+ const imageUpload = IMAGE_UPLOAD
88
+ ? {
89
+ async add(file, onProgress) {
90
+ if (richTexts().flatMap(assetKeysIn).length >= LIMITS.imagesMax)
91
+ throw Object.assign(new Error("total"), { code: "total" });
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}`;
98
+ },
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
+ ),
105
+ }
106
+ : undefined;
107
+ /** 글 칸 사이 그림 칸: 지우면 되돌리기 알림 */
108
+ const imageBlocks = {
109
+ removeLabel: t.md.imageRemove,
110
+ onRemoved: (undo) => showSnackbar(t.md.imageDeleted, undo),
111
+ };
112
+ /** 글에서 쓰는 옛 그림만 (지운 그림은 저장하지 않음) */
113
+ function usedImages() {
114
+ const text = richTexts().join("\n");
115
+ const used = new Set([...text.matchAll(/\(image:([\w-]+)\)/g)].map((m) => m[1]));
116
+ const kept = Object.fromEntries(Object.entries(draft.images ?? {}).filter(([id]) => used.has(id)));
117
+ return Object.keys(kept).length ? kept : undefined;
118
+ }
43
119
  // 처음 열면 문항 1이 이미 있는 상태로 시작한다
44
120
  const startedEmpty = draft.questions.length === 0;
45
121
  if (startedEmpty)
46
122
  draft.questions.push(newQuestion("select_one", [], texts.defaults));
47
123
 
48
- // 문항 id → 정답(화면 값: 선택 id · id 목록 · 그룹별 목록, 주관식은 허용 답 목록). 저장된 정규식을 읽어 채운다
49
- const savedKey = app.grading?.answer_key;
50
- const parsed = savedKey ? parseAnswerKey(draft.questions, savedKey) : {};
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
+ }
141
+
142
+ // 문항 id → 정답(화면 값: 선택 id · id 목록 · 그룹별 목록, 주관식은 허용 답 목록). 저장된 정규식(partial_pattern은 문항별 배열)을 읽어 채운다
143
+ const rawKey = app.grading?.answer_key;
144
+ const savedKey = Array.isArray(rawKey) && rawKey.length === 0 ? null : rawKey;
145
+ const parsed = Array.isArray(savedKey)
146
+ ? parseAnswerKeys(draft.questions, savedKey)
147
+ : savedKey
148
+ ? parseAnswerKey(draft.questions, savedKey)
149
+ : {};
51
150
  /** @type {Record<string, unknown>} */
52
151
  const answers = parsed ?? {};
53
152
  /** 새 문항의 기본 정답: 첫 번째 보기 하나 (단일 · 복수 선택만, 나머지 유형은 직접 고른다) */
@@ -193,9 +292,11 @@ function groupBoard(q, shuffle) {
193
292
  o.text = input.value;
194
293
  });
195
294
  row.querySelector('[data-role="delete"]').addEventListener("click", () => {
295
+ const undo = restorer(q, true);
196
296
  q.options.splice(q.options.indexOf(o), 1);
197
297
  answers[q.id] = pruneAnswer(q, answers[q.id] ?? {});
198
298
  render();
299
+ if (o.text.trim()) showSnackbar(t.optionDeleted, () => (undo(), render()));
199
300
  });
200
301
  const handle = row.querySelector('[data-role="handle"]');
201
302
  handle.dataset.optionHandle = o.id;
@@ -267,7 +368,8 @@ function groupBoard(q, shuffle) {
267
368
 
268
369
  /**
269
370
  * 오답 보기 영역 (그룹 분류 · 순서 맞추기 공통): 보기가 있거나 열어 둔 문항이면 점선 상자, 아니면 "오답 보기 추가 +" 버튼.
270
- * 머리줄의 ✕로 상자를 닫으면 안의 오답 보기도 함께 지운다 (있었다면 되돌리기 알림)
371
+ * 머리줄의 ✕로 상자를 닫으면 안의 오답 보기도 함께 지운다 (있었다면 되돌리기 알림).
372
+ * 오답 보기가 하나만 남으면 그 줄의 ✕는 끄고 상자의 ✕로 닫으라고 안내한다 (빈 상자가 남지 않게)
271
373
  */
272
374
  function noneArea(q, { items, rowFor, addOption, addButton, fullOptions, hint }) {
273
375
  if (items.length) noneOpen.add(q.id);
@@ -279,8 +381,14 @@ function noneArea(q, { items, rowFor, addOption, addButton, fullOptions, hint })
279
381
  return none;
280
382
  }
281
383
  const canClose = q.options.length - items.length >= LIMITS.optionsMin;
384
+ const rows = items.map((o) => rowFor(o));
385
+ if (rows.length === 1) {
386
+ const remove = rows[0].querySelector('[data-role="delete"]');
387
+ remove.disabled = true;
388
+ remove.title = t.noneRowMin;
389
+ }
282
390
  const none = templates.noneBox({
283
- rows: items.map((o) => rowFor(o)),
391
+ rows,
284
392
  add: addButton(""),
285
393
  hint,
286
394
  canClose,
@@ -392,10 +500,12 @@ function orderBoard(q, shuffle) {
392
500
  o.text = input.value;
393
501
  });
394
502
  row.querySelector('[data-role="delete"]').addEventListener("click", () => {
503
+ const undo = restorer(q, true);
395
504
  q.options.splice(q.options.indexOf(o), 1);
396
505
  answers[q.id] = orderIds(q);
397
506
  syncSlots(q);
398
507
  render();
508
+ if (o.text.trim()) showSnackbar(t.optionDeleted, () => (undo(), render()));
399
509
  });
400
510
  const handle = row.querySelector('[data-role="handle"]');
401
511
  handle.dataset.optionHandle = o.id;
@@ -459,10 +569,17 @@ function answerField(q) {
459
569
  if (i === rows.length - 1) rows.push("");
460
570
  paint(i + 1);
461
571
  });
572
+ // 글이 있던 정답을 지우면 "정답을 삭제했습니다. 되돌리기"
462
573
  row.querySelector('[data-role="delete"]').addEventListener("click", () => {
463
- rows.splice(i, 1);
574
+ const [removed] = rows.splice(i, 1);
464
575
  sync();
465
576
  paint(Math.min(i, rows.length - 1));
577
+ if (!removed.trim()) return;
578
+ showSnackbar(t.answerDeleted, () => {
579
+ rows.splice(i, 0, removed);
580
+ sync();
581
+ render();
582
+ });
466
583
  });
467
584
  return row;
468
585
  });
@@ -516,6 +633,24 @@ function inlineAnswer(q) {
516
633
  };
517
634
  }
518
635
 
636
+ /**
637
+ * 보기를 지우기 전 상태로 되돌리는 함수 (되돌리기 알림). 정답 · 순서 맞추기 칸 수, withOptions면 보기 목록도
638
+ */
639
+ function restorer(q, withOptions = false) {
640
+ const prev = {
641
+ options: withOptions ? structuredClone(q.options) : undefined,
642
+ answer: structuredClone(answers[q.id]),
643
+ slots: q.slots,
644
+ };
645
+ return () => {
646
+ if (prev.options) q.options = prev.options;
647
+ if (prev.answer === undefined) delete answers[q.id];
648
+ else answers[q.id] = prev.answer;
649
+ if (prev.slots !== undefined) q.slots = prev.slots;
650
+ answerViews.delete(q.id);
651
+ };
652
+ }
653
+
519
654
  /** 보기 목록 옵션: 지우면 정답에서 빼고, 단일 · 복수 · 그룹은 줄마다 정답 칸 */
520
655
  function optionsOpts(q) {
521
656
  const inline = INLINE_ANSWER_TYPES.includes(q.type);
@@ -533,6 +668,12 @@ function optionsOpts(q) {
533
668
  // 다시 그릴 때 지우기 전 칸 값으로 덮지 않게
534
669
  answerViews.delete(q.id);
535
670
  },
671
+ // 글이 있던 보기를 지우면 "보기를 삭제했습니다. 되돌리기" (정답 · 칸 수도 되돌림)
672
+ snapshot: () => {
673
+ readAnswerViews();
674
+ return restorer(q);
675
+ },
676
+ onRemoved: (undo) => showSnackbar(t.optionDeleted, undo),
536
677
  // 순서 맞추기: 보기 글을 고치면 정답 칸의 보기 이름도 바로 바꾼다 (다시 그리면 입력 중 초점을 잃음)
537
678
  onInput:
538
679
  q.type === 'order'
@@ -576,20 +717,31 @@ function questionFields(q, i) {
576
717
  max: LIMITS.titleMax,
577
718
  // 질문은 1000자까지라 글자 수 표시는 두지 않는다 (입력 제한은 그대로)
578
719
  showCount: false,
720
+ // 길면 다음 줄로 넘겨 다 보이게, Shift+Enter로 줄바꿈 (Enter는 막음)
721
+ softWrap: true,
579
722
  }),
580
723
  // 문항 설명: 필요할 때만 "설명 추가 +"로 연다. 열리면 해설과 같은 머리줄(아이콘 · 이름 · 지우기). 새 문항에는 키가 없고, 적으면 생긴다
581
724
  form.revealable(
582
725
  t.addDescription,
583
- form.inlineField(
726
+ form.richField(
584
727
  t.description,
585
728
  q.description ?? "",
586
729
  (v) => (q.description = v),
587
- {
588
- placeholder: t.descriptionPlaceholder,
589
- multiline: true,
590
- },
730
+ { placeholder: t.descriptionPlaceholder, images: imageBlocks },
591
731
  ),
592
- { open: Boolean(q.description), title: t.description, icon: "align" },
732
+ {
733
+ open: Boolean(q.description),
734
+ title: t.description,
735
+ icon: "comment",
736
+ // 서식 도구 (굵게 · 기울임 · 취소선 · 목록 · 코드 · 그림) — 연주님 최종 수정본
737
+ tools: t.md,
738
+ images: imageUpload,
739
+ onRemoved: (text) =>
740
+ showSnackbar(t.fieldDeleted(t.description), () => {
741
+ q.description = text;
742
+ render();
743
+ }),
744
+ },
593
745
  ),
594
746
  ];
595
747
  if (q.type === "select_one" || q.type === "select_multiple") {
@@ -614,13 +766,18 @@ function questionFields(q, i) {
614
766
  t.placeholder,
615
767
  q.placeholder ?? "",
616
768
  (v) => (q.placeholder = v),
617
- { placeholder: t.placeholderInput, max: LIMITS.placeholderMax },
769
+ { placeholder: t.placeholderInput, max: LIMITS.placeholderMax, singleLine: true },
618
770
  ),
619
771
  {
620
772
  open: Boolean(q.placeholder),
621
773
  title: t.placeholder,
622
774
  icon: "textbox",
623
775
  hint: t.placeholderHint,
776
+ onRemoved: (text) =>
777
+ showSnackbar(t.fieldDeleted(t.placeholder), () => {
778
+ q.placeholder = text;
779
+ render();
780
+ }),
624
781
  },
625
782
  ),
626
783
  );
@@ -628,14 +785,11 @@ function questionFields(q, i) {
628
785
  body.push(
629
786
  form.revealable(
630
787
  t.addExplanation,
631
- form.inlineField(
788
+ form.richField(
632
789
  t.explanation,
633
790
  q.explanation?.text ?? "",
634
791
  (v) => (q.explanation = { text: v, enabled: true }),
635
- {
636
- placeholder: t.explanationPlaceholder,
637
- multiline: true,
638
- },
792
+ { placeholder: t.explanationPlaceholder, images: imageBlocks },
639
793
  ),
640
794
  {
641
795
  open: Boolean(q.explanation?.enabled),
@@ -644,7 +798,14 @@ function questionFields(q, i) {
644
798
  onClose: () => (q.explanation = { text: "", enabled: false }),
645
799
  title: t.explanation,
646
800
  icon: "bulb",
801
+ tools: t.md,
802
+ images: imageUpload,
647
803
  hint: t.explanationHint,
804
+ onRemoved: (text) =>
805
+ showSnackbar(t.fieldDeleted(t.explanation), () => {
806
+ q.explanation = { text, enabled: true };
807
+ render();
808
+ }),
648
809
  },
649
810
  ),
650
811
  );
@@ -659,8 +820,17 @@ function questionCard(q, i) {
659
820
  count: draft.questions.length,
660
821
  types: Object.entries(texts.types),
661
822
  body: questionFields(q, i),
823
+ // 부분 채점일 때만 카드 머리에 배점 칸
824
+ points: partialActive() ? (q.points ?? 0) : undefined,
662
825
  },
663
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
+ },
664
834
  type: (type) => {
665
835
  readAnswerViews();
666
836
  const prev = {
@@ -681,6 +851,8 @@ function questionCard(q, i) {
681
851
  ...newQuestion(type, [], texts.defaults),
682
852
  id: q.id,
683
853
  title: q.title,
854
+ // 배점은 유형을 바꿔도 그대로
855
+ ...(q.points === undefined ? {} : { points: q.points }),
684
856
  };
685
857
  delete answers[q.id];
686
858
  const picked = defaultAnswer(draft.questions[i]);
@@ -734,10 +906,11 @@ function hideSnackbar() {
734
906
  snackbarNode = null;
735
907
  }
736
908
 
909
+ /** restore가 없으면 알림만 (되돌리기 버튼 없음) */
737
910
  function showSnackbar(text, restore) {
738
911
  hideSnackbar();
739
- const node = templates.snackbar({ text, action: t.undo });
740
- node.querySelector('[data-role="undo"]').addEventListener("click", () => {
912
+ const node = templates.snackbar({ text, action: restore ? t.undo : null });
913
+ node.querySelector('[data-role="undo"]')?.addEventListener("click", () => {
741
914
  hideSnackbar();
742
915
  restore();
743
916
  });
@@ -746,32 +919,73 @@ function showSnackbar(text, restore) {
746
919
  snackbarTimer = setTimeout(hideSnackbar, SNACKBAR_MS);
747
920
  }
748
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
+
749
977
  function render() {
750
978
  readAnswerViews();
751
979
  answerViews.clear();
980
+ syncPoints();
981
+ scoreBox = draft.questions.length > 1 ? scoreSettings() : null;
752
982
  const cards = draft.questions.map(questionCard);
753
983
  root.replaceChildren(
754
- // 상시 안내는 두지 않는다 (정답 위치는 보기 목록 힌트 · "정답" 열이 알려 줌). 저장된 정답을 못 읽었을 때만 경고
984
+ // 부분 채점 설정은 문제가 2개 이상일 때만 맨 위에
985
+ ...(scoreBox ? [scoreBox] : []),
986
+ // 저장된 정답을 못 읽었을 때만 맨 위에 경고
755
987
  ...(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
- ],
774
- }),
988
+ // 퀴즈 제목 · 안내 칸은 두지 않는다 (연주님 최종 수정본). 예전에 저장한 title · description은 draft에 그대로 남아 같이 저장된다
775
989
  ...cards,
776
990
  // 문항은 LIMITS.questionsMax개까지: 다 차면 "문항 추가" 대신 안내
777
991
  canAddQuestion(draft.questions)
@@ -781,6 +995,9 @@ function render() {
781
995
  draft.questions.map((q) => q.id),
782
996
  texts.defaults,
783
997
  );
998
+ // 직접 배점이면 새 문제는 100점까지 남은 배점으로 (자동 배점은 다시 나눔)
999
+ if (partialActive() && draft.pointsMode === "custom")
1000
+ added.points = Math.max(0, 100 - totalPoints(draft.questions));
784
1001
  draft.questions.push(added);
785
1002
  const picked = defaultAnswer(added);
786
1003
  if (picked !== undefined) answers[added.id] = picked;
@@ -788,6 +1005,7 @@ function render() {
788
1005
  })
789
1006
  : templates.questionLimit({ text: t.questionLimit }),
790
1007
  );
1008
+ updateScoreSum();
791
1009
  save?.markDirty();
792
1010
  }
793
1011
 
@@ -821,20 +1039,83 @@ function markAnswerError(card, message) {
821
1039
  area.addEventListener(type, clear);
822
1040
  }
823
1041
 
1042
+ /**
1043
+ * partial_pattern 채점 설정: 문항마다 정답 정규식(서버 한도 ANSWER_KEY_MAX는 문항 하나에 걸림)과 배점(문제별 points).
1044
+ * 검증(정규식 공통 검사 → 문항별 왕복 · 오답 → 배점 규칙)을 통과해야 저장한다. 배점 규칙(0~100 정수, 합 100 이상)은
1045
+ * 저장 전 validateQuiz가 먼저 막는다
1046
+ */
1047
+ function partialGrading(questions) {
1048
+ const keys = buildAnswerKeys(questions, answers);
1049
+ const base = questions.map((q) =>
1050
+ q.type === "text" ? (answers[q.id] ?? [])[0] : answers[q.id],
1051
+ );
1052
+ for (const [i, key] of keys.entries()) {
1053
+ if (key.length > ANSWER_KEY_MAX)
1054
+ return problemAt(
1055
+ {
1056
+ questionIndex: i,
1057
+ message: a.validation.at(
1058
+ i + 1,
1059
+ a.validation.tooLongItem(key.length, ANSWER_KEY_MAX),
1060
+ ),
1061
+ },
1062
+ { answer: true },
1063
+ );
1064
+ const regexProblem = validateAnswerRegex(key, [
1065
+ joinAnswerList([questions[i]], [base[i]])[0],
1066
+ ]);
1067
+ if (regexProblem)
1068
+ return problemAt(
1069
+ { questionIndex: i, message: a.validation.at(i + 1, regexProblem) },
1070
+ { answer: true },
1071
+ );
1072
+ }
1073
+ const keyProblem = checkAnswerKeys(questions, answers, keys, a.validation);
1074
+ if (keyProblem) return problemAt(keyProblem, { answer: true });
1075
+ // 배점은 문제 카드에 붙어 있어 문제 순서를 바꿔도 제 문제를 따라간다
1076
+ const scores = questions.map((q) => q.points);
1077
+ const problem = validatePartialGrading({ answer_key: keys, scores });
1078
+ if (problem) return problem;
1079
+ return { type: PARTIAL, answer_key: keys, scores };
1080
+ }
1081
+
824
1082
  render();
1083
+ // 불러오는 자리에서 내용으로 바뀔 때 살짝 나타나게 (styles.css .qz-enter)
1084
+ root.classList.add("qz-enter");
825
1085
  save = app.useSave({
826
1086
  label: t.done,
827
- getContent: () => structuredClone(draft),
1087
+ // partial_pattern이면 학생 화면이 답을 문항별 배열로 내도록 공개 값 gradingType과 배점 표시(pointsMode · points)를 같이 저장 (정답은 아님)
1088
+ getContent: () => {
1089
+ const content = structuredClone(draft);
1090
+ const images = usedImages();
1091
+ if (images) content.images = images;
1092
+ else delete content.images;
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
+ }
1099
+ return content;
1100
+ },
828
1101
  validate: (content) => {
829
1102
  const problem = validateQuiz(content, texts.validation);
830
1103
  if (!problem) return true;
831
- // 라벨이 없으니 비운 필수 칸(퀴즈 제목 · 질문)에 빨간 밑줄을 긋고, 걸린 칸에 초점을 둔다
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
+ }
1114
+ // 라벨이 없으니 비운 필수 칸(질문)에 빨간 밑줄을 긋고, 걸린 칸에 초점을 둔다
832
1115
  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]");
1116
+ const invalid = form
1117
+ .cardAt(problem.questionIndex)
1118
+ ?.querySelector("[aria-invalid]");
838
1119
  if (!invalid) return problemAt(problem);
839
1120
  invalid.scrollIntoView({ block: "center" });
840
1121
  invalid.focus({ preventScroll: true });
@@ -846,6 +1127,7 @@ save = app.useSave({
846
1127
  const { questions } = draft;
847
1128
  const missing = validateAnswerKey(questions, answers, a.validation);
848
1129
  if (missing) return problemAt(missing, { answer: true });
1130
+ if (partialActive()) return partialGrading(questions);
849
1131
  const answerKey = buildAnswerKey(questions, answers);
850
1132
  // 정답 정규식은 서버 한도(ANSWER_KEY_MAX)가 퀴즈 전체에 걸린다. 한글 주관식은 한 글자가 9자로 늘어
851
1133
  // 몇 문항이면 넘으므로, 정규식에서 가장 긴 문항으로 옮기고 무엇을 줄일지 알려 준다