@eliceio/cdk-cli 0.1.0-alpha.5 → 0.1.0-alpha.7

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 (87) hide show
  1. package/README.md +110 -84
  2. package/es/cli.js +7 -22
  3. package/es/commands/build/index.d.ts +5 -3
  4. package/es/commands/build/index.js +20 -11
  5. package/es/commands/create/scaffold.d.ts +2 -0
  6. package/es/commands/create/scaffold.js +15 -1
  7. package/es/commands/dev/index.d.ts +1 -1
  8. package/es/commands/dev/index.js +1 -1
  9. package/es/commands/doctor/index.d.ts +1 -1
  10. package/es/commands/doctor/index.js +5 -6
  11. package/es/commands/setup/index.d.ts +4 -7
  12. package/es/commands/setup/index.js +41 -70
  13. package/es/commands/uninstall/index.d.ts +9 -8
  14. package/es/commands/uninstall/index.js +41 -47
  15. package/es/commands/update/index.d.ts +4 -2
  16. package/es/commands/update/index.js +27 -18
  17. package/es/core/collect.js +1 -1
  18. package/es/core/config.d.ts +1 -1
  19. package/es/core/config.js +3 -3
  20. package/es/{commands/mcp/index.d.ts → core/mcp.d.ts} +11 -18
  21. package/es/{commands/mcp/index.js → core/mcp.js} +29 -51
  22. package/es/core/minify.js +31 -2
  23. package/es/core/prepare.js +1 -1
  24. package/es/core/sandbox.d.ts +25 -0
  25. package/es/core/sandbox.js +110 -8
  26. package/es/{commands/skill/index.d.ts → core/skills.d.ts} +1 -17
  27. package/es/{commands/skill/index.js → core/skills.js} +6 -22
  28. package/es/dev/grading.d.ts +1 -1
  29. package/es/dev/grading.js +1 -1
  30. package/es/dev/host-page.js +20 -5
  31. package/es/dev/inject.d.ts +6 -0
  32. package/es/dev/inject.js +16 -1
  33. package/es/dev/mock-api.js +0 -16
  34. package/es/dev/server.d.ts +4 -2
  35. package/es/dev/server.js +11 -3
  36. package/es/rules/check.js +71 -8
  37. package/es/rules/csp.d.ts +26 -0
  38. package/es/rules/csp.js +42 -0
  39. package/es/rules/index.d.ts +2 -1
  40. package/es/rules/index.js +2 -1
  41. package/es/rules/refs.d.ts +12 -2
  42. package/es/rules/refs.js +50 -18
  43. package/es/rules/types.d.ts +5 -0
  44. package/es/rules/unused.d.ts +2 -0
  45. package/es/rules/unused.js +4 -3
  46. package/es/rules.json.js +2 -2
  47. package/package.json +2 -2
  48. package/rules.json +37 -15
  49. package/skills/_shared/always.md +2 -1
  50. package/skills/elice-content-create/SKILL.md +2 -1
  51. package/skills/elice-content-guide/SKILL.md +1 -1
  52. package/skills/elice-content-guide/topics/01-check-the-environment.md +2 -2
  53. package/skills/elice-content-guide/topics/02-design-the-material.md +2 -0
  54. package/skills/elice-content-guide/topics/03-create-the-project.md +2 -2
  55. package/skills/elice-content-guide/topics/04-rules.md +3 -1
  56. package/skills/elice-content-guide/topics/05-screen-code.md +44 -13
  57. package/skills/elice-content-guide/topics/07-move-existing-html.md +1 -1
  58. package/skills/elice-content-guide/topics/08-fix-check-errors.md +21 -18
  59. package/skills/elice-content-guide/topics/09-check.md +1 -0
  60. package/skills/elice-content-guide/topics/10-build.md +1 -1
  61. package/skills/elice-content-guide/topics/12-upload-with-the-material-mcp.md +2 -2
  62. package/skills/elice-content-migrate/SKILL.md +4 -3
  63. package/skills/elice-content-publish/SKILL.md +1 -1
  64. package/templates/_shared/lib/cdk-mock.js +3 -3
  65. package/templates/_shared/lib/elice-content-editor.d.ts +80 -0
  66. package/templates/_shared/lib/elice-content-editor.js +1062 -0
  67. package/templates/_shared/lib/elice-content.css +354 -1
  68. package/templates/_shared/lib/elice-content.js +10 -3
  69. package/templates/blank/README.md +27 -2
  70. package/templates/blank/commentary.txt +5 -0
  71. package/templates/blank/screens/edit.js +38 -17
  72. package/templates/blank/screens/instructor.js +20 -8
  73. package/templates/blank/screens/learn.js +151 -13
  74. package/templates/blank/styles.css +171 -0
  75. package/templates/blank/template.json +2 -2
  76. package/templates/quiz/README.md +2 -2
  77. package/templates/quiz/core/editor.d.ts +2 -0
  78. package/templates/quiz/core/editor.js +16 -6
  79. package/templates/quiz/core/model.js +1 -1
  80. package/templates/quiz/screens/edit.js +117 -24
  81. package/templates/quiz/styles.css +86 -12
  82. package/templates/quiz/template.json +1 -1
  83. package/templates/quiz/ui/templates/edit.d.ts +4 -0
  84. package/templates/quiz/ui/templates/edit.js +46 -10
  85. package/templates/quiz/ui/templates/page.js +1 -2
  86. package/templates/quiz/ui/templates/text.js +10 -7
  87. package/templates/quiz/ui/texts.js +13 -9
@@ -1,24 +1,162 @@
1
- // 학생 화면. 내용을 그리고, 답을 모으고 채우는 방법만 키트에 알려 줍니다.
2
- // 튜터링 잠금 · 미리보기 안내 · 답 복원 · 결과와 오류 표시는 키트(useSubmit)가 합니다.
1
+ // 학생 화면 예제 "예측하고 확인하기": 항목마다 값을 막대로 예측하고, 정답 보기로 실제 값과 비교합니다.
2
+ // 내용(app.content)은 편집 화면이 저장한 { title, intro, unit, items: [{ name, value, note }] }입니다 (screens/edit.js).
3
+ // 이 자료에 맞게 바꿀 곳: show() 안의 화면. 내용 모양을 바꾸면 screens/edit.js의 schema · sample도 같이 바꿉니다.
3
4
  import { start } from '../lib/elice-content.js';
4
5
 
5
6
  const app = await start({ screen: 'learn' });
6
7
  const root = document.getElementById('app');
7
8
  // 편집 화면에서 아직 내용을 저장하지 않았으면 안내만 보인다 (기본 내용은 없음)
8
- if (app.hasContent) show();
9
+ if (app.hasContent) show(app.content);
9
10
  else root.replaceChildren(app.emptyState());
10
11
 
11
- function show() {
12
- const title = Object.assign(document.createElement('h1'), { textContent: app.content.title ?? '' });
13
- const message = Object.assign(document.createElement('p'), {
14
- textContent: app.content.message ?? '',
12
+ function h(tag, props = {}, ...children) {
13
+ const el = Object.assign(document.createElement(tag), props);
14
+ el.append(...children);
15
+ return el;
16
+ }
17
+ function fmt(n) {
18
+ return n.toLocaleString('ko-KR', { maximumFractionDigits: 1 });
19
+ }
20
+
21
+ /** 축 끝: 가장 큰 값의 1.5배를 보기 좋은 수(1 · 2 · 2.5 · 5 × 10ⁿ)로 올림 */
22
+ function axisMax(values) {
23
+ const raw = Math.max(...values, 0) * 1.5;
24
+ if (!(raw > 0)) return 10;
25
+ const p = 10 ** Math.floor(Math.log10(raw));
26
+ return [1, 2, 2.5, 5, 10].map(m => m * p).find(x => x >= raw);
27
+ }
28
+
29
+ function show({ title = '', intro = '', unit = '', items = [] }) {
30
+ const list = items.filter(it => it && Number.isFinite(it.value));
31
+ const max = axisMax(list.map(it => it.value));
32
+ const step = max / 100;
33
+ const start = Math.round(max / 2 / step) * step;
34
+ const withUnit = n => `${fmt(n)}${unit ? ` ${unit}` : ''}`;
35
+ let predictions = list.map(() => start);
36
+ let revealed = false;
37
+
38
+ // 항목 한 줄: 이름 · 막대(끌거나 ← → 키) · 숫자 칸. 정답 보기 뒤에는 실제 값 표시와 차이
39
+ const rows = list.map((it, i) => {
40
+ const id = `predict-${i}`;
41
+ const range = h('input', { type: 'range', id, min: 0, max, step, className: 'predict-range' });
42
+ const number = h('input', { type: 'number', min: 0, step: 'any', className: 'predict-number' });
43
+ number.setAttribute('aria-label', `${it.name} 예측 값${unit ? ` (${unit})` : ''}`);
44
+ const real = h('span', { className: 'predict-real', hidden: true });
45
+ real.append(
46
+ h('span', { className: 'predict-real-label', textContent: `실제 ${withUnit(it.value)}` })
47
+ );
48
+ const diff = h('p', { className: 'predict-diff', hidden: true });
49
+ range.addEventListener('input', () => set(i, Number(range.value)));
50
+ number.addEventListener('input', () => {
51
+ if (number.value.trim() !== '') set(i, Number(number.value), { fromNumber: true });
52
+ });
53
+ number.addEventListener('change', () => paint());
54
+ const row = h(
55
+ 'div',
56
+ { className: 'predict-row' },
57
+ h('label', { htmlFor: id, className: 'predict-name', textContent: it.name }),
58
+ h('div', { className: 'predict-track' }, range, real),
59
+ number,
60
+ diff
61
+ );
62
+ return { row, range, number, real, diff };
15
63
  });
16
- const answer = Object.assign(document.createElement('textarea'), { ariaLabel: '답' });
17
- root.replaceChildren(title, message, answer);
18
64
 
19
- app.useSubmit({
20
- getAnswer: () => ({ text: answer.value }),
21
- setAnswer: (a) => (answer.value = a?.text ?? ''),
22
- validate: (a) => a.text.trim() !== '' || '답을 입력해 주세요.',
65
+ const total = h('p', { className: 'predict-total' });
66
+ const ranking = h('p', { className: 'predict-ranking' });
67
+ const summary = h('div', { className: 'predict-summary' }, total, ranking);
68
+ summary.setAttribute('aria-live', 'polite');
69
+ const reveal = h('button', { type: 'button', className: 'ec-primary', textContent: '정답 보기' });
70
+ const again = h('button', { type: 'button', textContent: '다시 예측', hidden: true });
71
+ reveal.addEventListener('click', () => {
72
+ revealed = true;
73
+ paint();
74
+ again.focus();
23
75
  });
76
+ again.addEventListener('click', () => {
77
+ revealed = false;
78
+ predictions = list.map(() => start);
79
+ paint();
80
+ rows[0]?.range.focus();
81
+ });
82
+
83
+ root.replaceChildren(
84
+ h('h1', { textContent: title }),
85
+ h('p', { className: 'predict-intro', textContent: intro }),
86
+ h('div', { className: 'predict-chart' }, ...rows.map(r => r.row)),
87
+ summary,
88
+ h('div', { className: 'predict-actions' }, again, reveal)
89
+ );
90
+
91
+ function set(i, v, { fromNumber = false } = {}) {
92
+ if (revealed || !Number.isFinite(v)) return;
93
+ predictions[i] = Math.min(Math.max(0, v), max);
94
+ paint({ keepNumber: fromNumber ? i : -1 });
95
+ }
96
+
97
+ /** 큰 순서 이름 (같으면 원래 순서) */
98
+ const order = values =>
99
+ values
100
+ .map((v, i) => [v, i])
101
+ .sort((a, b) => b[0] - a[0] || a[1] - b[1])
102
+ .map(([, i]) => i);
103
+
104
+ function paint({ keepNumber = -1 } = {}) {
105
+ rows.forEach((r, i) => {
106
+ const p = predictions[i];
107
+ const it = list[i];
108
+ r.range.value = String(p);
109
+ r.range.style.setProperty('--fill', `${(p / max) * 100}%`);
110
+ r.range.setAttribute('aria-valuetext', withUnit(p));
111
+ // 숫자 칸에 입력 중이면 고쳐 쓰지 않는다 (지우고 다시 쓰는 중일 수 있음)
112
+ if (i !== keepNumber) r.number.value = String(Math.round(p * 10) / 10);
113
+ r.range.disabled = r.number.disabled = revealed;
114
+ r.real.hidden = r.diff.hidden = !revealed;
115
+ r.real.style.setProperty('--at', `${(Math.min(it.value, max) / max) * 100}%`);
116
+ if (revealed) {
117
+ const d = p - it.value;
118
+ const pct = it.value ? Math.round((Math.abs(d) / it.value) * 100) : 0;
119
+ const close = pct <= 5;
120
+ r.diff.className = `predict-diff ${close ? 'ok' : 'no'}`;
121
+ r.diff.textContent = close
122
+ ? `거의 맞았어요 (차이 ${withUnit(Math.abs(d))})`
123
+ : `${d > 0 ? '+' : '−'}${withUnit(Math.abs(d))} · ${pct}% ${d > 0 ? '크게' : '작게'} 예측`;
124
+ if (it.note)
125
+ r.diff.append(h('span', { className: 'predict-note', textContent: ` · ${it.note}` }));
126
+ }
127
+ });
128
+ const sum = predictions.reduce(
129
+ (a, b) => a + b,
130
+ 0
131
+ );
132
+ const mine = order(predictions);
133
+ const names = idx => idx.map(i => list[i].name).join(' › ');
134
+ if (!revealed) {
135
+ total.textContent = `예측 합계 ${withUnit(sum)}`;
136
+ ranking.textContent = `예측한 큰 순서: ${names(mine)}`;
137
+ } else {
138
+ const truth = order(list.map(it => it.value));
139
+ const hit = truth.filter((i, k) => mine[k] === i).length;
140
+ total.textContent = `예측 합계 ${withUnit(sum)} · 실제 합계 ${withUnit(
141
+ list.reduce(
142
+ (a, it) => a + it.value,
143
+ 0
144
+ )
145
+ )}`;
146
+ ranking.textContent = `실제 큰 순서: ${names(truth)} (순서 ${hit} / ${list.length}자리 맞음)`;
147
+ }
148
+ reveal.hidden = revealed;
149
+ again.hidden = !revealed;
150
+ }
151
+ paint();
152
+
153
+ // 제출을 받으려면 (교육자가 LXP 설정에서 '제출하면 완료'를 고를 수 있게) 주석을 풉니다. 기본은 제출 없음(열면 완료).
154
+ // 답은 작은 JSON으로 냅니다. 다시 열면 키트가 setAnswer로 채워 줍니다.
155
+ // app.useSubmit({
156
+ // getAnswer: () => ({ predictions: list.map((it, i) => ({ name: it.name, value: predictions[i] })) }),
157
+ // setAnswer: a => {
158
+ // a?.predictions?.forEach((p, i) => (predictions[i] = p.value));
159
+ // paint();
160
+ // },
161
+ // });
24
162
  }
@@ -1 +1,172 @@
1
1
  /* 이 콘텐츠만의 스타일. lib/elice-content.css의 --ec-* 변수를 덮어써도 됩니다 */
2
+
3
+ /* 예제 "예측하고 확인하기" (screens/learn.js · instructor.js). 이 자료에 맞게 바꿀 곳 */
4
+ .predict-intro {
5
+ color: var(--ec-muted);
6
+ word-break: keep-all;
7
+ }
8
+ .predict-chart {
9
+ display: flex;
10
+ flex-direction: column;
11
+ /* 정답 보기의 실제 값 이름표가 위 줄에 겹치지 않게 */
12
+ gap: 28px;
13
+ }
14
+ /* 데스크톱: 이름 | 막대 | 숫자 한 줄, 차이는 막대 아래 */
15
+ .predict-row {
16
+ display: grid;
17
+ grid-template-columns: 6em 1fr 8em;
18
+ grid-template-areas:
19
+ 'name track number'
20
+ '. diff diff';
21
+ align-items: center;
22
+ gap: 4px 12px;
23
+ }
24
+ .predict-name {
25
+ grid-area: name;
26
+ font-weight: var(--eds-fw-semibold);
27
+ word-break: keep-all;
28
+ }
29
+ .predict-track {
30
+ grid-area: track;
31
+ position: relative;
32
+ }
33
+ .predict-number {
34
+ grid-area: number;
35
+ text-align: right;
36
+ }
37
+ .predict-diff {
38
+ grid-area: diff;
39
+ font-size: var(--eds-fs-body2);
40
+ }
41
+ .predict-diff.ok {
42
+ color: var(--ec-ok);
43
+ }
44
+ .predict-diff.no {
45
+ color: var(--ec-no);
46
+ }
47
+ .predict-note {
48
+ color: var(--ec-muted);
49
+ }
50
+ /* 막대 = 가로 range. 채운 부분이 예측 값(--fill), 손잡이는 막대 끝의 세로 손잡이. 끌거나 ← → 키 */
51
+ .predict-range {
52
+ display: block;
53
+ width: 100%;
54
+ height: 36px;
55
+ margin: 0;
56
+ padding: 0;
57
+ border: 0;
58
+ border-radius: 6px;
59
+ appearance: none;
60
+ background: linear-gradient(
61
+ to right,
62
+ var(--ec-accent) var(--fill, 50%),
63
+ var(--ec-surface) var(--fill, 50%)
64
+ );
65
+ cursor: pointer;
66
+ touch-action: pan-y;
67
+ }
68
+ .predict-range::-webkit-slider-thumb {
69
+ appearance: none;
70
+ width: 12px;
71
+ height: 44px;
72
+ border-radius: 6px;
73
+ border: 2px solid var(--ec-bg);
74
+ background: var(--ec-accent-dark);
75
+ box-shadow: var(--ec-shadow);
76
+ }
77
+ .predict-range::-moz-range-thumb {
78
+ width: 12px;
79
+ height: 44px;
80
+ border-radius: 6px;
81
+ border: 2px solid var(--ec-bg);
82
+ background: var(--ec-accent-dark);
83
+ }
84
+ .predict-range:focus-visible {
85
+ outline: 2px solid var(--ec-accent);
86
+ outline-offset: 3px;
87
+ }
88
+ .predict-range:disabled {
89
+ cursor: default;
90
+ opacity: 0.7;
91
+ }
92
+ /* 정답 보기 뒤 실제 값: 막대 위 세로선 + 이름표 */
93
+ .predict-real {
94
+ position: absolute;
95
+ top: -6px;
96
+ bottom: -6px;
97
+ left: var(--at);
98
+ width: 0;
99
+ border-left: 3px solid var(--ec-fg);
100
+ pointer-events: none;
101
+ }
102
+ .predict-real-label {
103
+ position: absolute;
104
+ bottom: 100%;
105
+ left: 0;
106
+ translate: -50% 0;
107
+ padding: 0 4px;
108
+ border-radius: 4px;
109
+ background: var(--ec-fg);
110
+ color: var(--ec-bg);
111
+ font-size: var(--eds-fs-caption);
112
+ font-weight: var(--eds-fw-semibold);
113
+ white-space: nowrap;
114
+ }
115
+ .predict-summary {
116
+ display: flex;
117
+ flex-direction: column;
118
+ gap: 4px;
119
+ padding: 12px 16px;
120
+ border-radius: var(--ec-radius);
121
+ background: var(--ec-surface);
122
+ }
123
+ .predict-total {
124
+ font-weight: var(--eds-fw-bold);
125
+ }
126
+ .predict-ranking {
127
+ color: var(--ec-muted);
128
+ word-break: keep-all;
129
+ }
130
+ .predict-actions {
131
+ display: flex;
132
+ justify-content: flex-end;
133
+ gap: 8px;
134
+ }
135
+ /* 모바일: 이름 · 숫자 한 줄, 막대는 그 아래 전체 폭 */
136
+ @media (max-width: 511.98px) {
137
+ .predict-row {
138
+ grid-template-columns: 1fr 7em;
139
+ grid-template-areas:
140
+ 'name number'
141
+ 'track track'
142
+ 'diff diff';
143
+ gap: 8px;
144
+ }
145
+ .predict-row .predict-track {
146
+ margin-top: 14px;
147
+ }
148
+ .predict-actions button {
149
+ flex: 1;
150
+ }
151
+ }
152
+
153
+ /* 교육자 화면 표 */
154
+ .predict-table {
155
+ width: 100%;
156
+ border-collapse: collapse;
157
+ font-size: var(--eds-fs-body2);
158
+ }
159
+ .predict-table th,
160
+ .predict-table td {
161
+ padding: 8px 10px;
162
+ border-bottom: 1px solid var(--ec-line);
163
+ text-align: left;
164
+ }
165
+ .predict-table th {
166
+ color: var(--ec-muted);
167
+ font-weight: var(--eds-fw-semibold);
168
+ }
169
+ .predict-table td:nth-child(2) {
170
+ text-align: right;
171
+ font-variant-numeric: tabular-nums;
172
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blank",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "title": "빈 자료",
5
- "description": "퀴즈가 아닌 모든 자료(시뮬레이션 · 시각화 · 활동 · 설명 · 플래시카드 · 설문)를 직접 만들 때. 학생 · 교육자 · 편집 화면 골격 (완료 정책은 LXP 설정 탭에서 교육자가 고름)"
5
+ "description": "퀴즈가 아닌 모든 자료(시뮬레이션 · 시각화 · 활동 · 설명 · 플래시카드 · 설문)를 직접 만들 때. 예제 \"예측하고 확인하기\"(막대 예측 · 정답 보기)와 내용 JSON 편집기(폼 보기 · 코드 보기)로 시작 (완료 정책은 LXP 설정 탭에서 교육자가 고름)"
6
6
  }
@@ -28,7 +28,7 @@ core/ 동작 — 고치지 않습니다 (답 문자열 · 채점 약속,
28
28
  | 바꾸고 싶은 것 | 고치는 곳 |
29
29
  | -------------------------------------------- | ------------------------------------------------------------------------- |
30
30
  | 색 · 간격 · 모서리 | `ui/theme.css`의 `--qz-*` 변수 (예: `--qz-accent`, `--qz-option-padding`) |
31
- | 문구 ("확인 문제", "정답", 탭 제목 등) | `ui/texts.js` (HTML의 제목 · "불러오는 중"은 스크립트가 돌기 전 대비용) |
31
+ | 문구 ("정답", "편집 완료", 탭 제목 등) | `ui/texts.js` (HTML의 제목 · "불러오는 중"은 스크립트가 돌기 전 대비용) |
32
32
  | 보기 카드 마크업 | `ui/templates/choice.js` (모양은 `styles.css`의 `.qz-option`) |
33
33
  | 문항 겉모양 · 결과 · 해설 자리 | `ui/templates/question.js` |
34
34
  | 순서 맞추기 · 그룹 분류 배치 | `ui/templates/order.js` · `ui/templates/group.js` |
@@ -45,7 +45,7 @@ core/ 동작 — 고치지 않습니다 (답 문자열 · 채점 약속,
45
45
  | `input` | 주관식 입력란 (`text.js`) · 편집 칸 |
46
46
  | `pool` · `slots` | 순서 맞추기 (`order.js`) |
47
47
  | `pool` · `items`, 있으면 `pool-area` · `reset` · `remove` | 그룹 분류 (`group.js`) |
48
- | `count` · `handle` · `delete` · `type` · `up` · `down` | 편집 화면 (`edit.js`) |
48
+ | `count` · `handle` · `delete` · `type` · `up` · `down` · `answer` · `undo` · `type-warning` · `answer-error` | 편집 화면 (`edit.js`) |
49
49
 
50
50
  보기 · 칸 · 그룹 · 문항 요소의 `data-role` · `data-option` · `data-slot` · `data-group` · `data-id`, 상태 표시 `data-result`(`correct` · `wrong`) · `data-dragging` · `data-ghost`는 동작이 붙입니다. CSS에서 이 속성으로 상태를 꾸밀 수 있습니다.
51
51
 
@@ -38,6 +38,8 @@ export declare function createEditor(opts: {
38
38
  items: any[],
39
39
  key: string,
40
40
  opts?: {
41
+ /** 추가한 뒤 (예: 순서 맞추기 칸 수 늘리기) */
42
+ onAdd?: () => void;
41
43
  onDelete?: () => void;
42
44
  onInput?: (item: any) => void;
43
45
  /** 줄마다 정답 칸 (data-role="answer"): radio · checkbox · select(choices: [값, 이름]) */
@@ -68,12 +68,14 @@ export function createEditor({ rerender, root, templates, labels }) {
68
68
  * @param {'option' | 'group'} kind
69
69
  * @param {object[]} items q.options 또는 q.groups (직접 고침)
70
70
  * @param {string} key 키보드로 옮긴 뒤 초점을 찾을 이름 (화면에서 겹치지 않게)
71
- * @param {{ onDelete?: () => void, onInput?: (item: object) => void,
71
+ * 정답으로 고른 줄에는 data-correct를 붙인다 (그룹은 그룹에 넣은 보기)
72
+ * @param {{ onAdd?: () => void, onDelete?: () => void, onInput?: (item: object) => void,
72
73
  * answer?: { type: 'radio' | 'checkbox' | 'select', name: string, choices?: [string, string][],
73
74
  * get: (item: object) => boolean | string, set: (item: object, value: boolean | string) => void } }} [opts]
75
+ * onAdd: 추가한 뒤 할 일 (예: 순서 맞추기 칸 수 늘리기) ·
74
76
  * onDelete: 지운 뒤 할 일 (예: 순서 맞추기 칸 수 줄이기, 정답에서 빼기) · onInput: 글을 고친 뒤 할 일
75
77
  */
76
- function itemList(kind, items, key, { onDelete, onInput, answer } = {}) {
78
+ function itemList(kind, items, key, { onAdd, onDelete, onInput, answer } = {}) {
77
79
  const isGroup = kind === 'group';
78
80
  const text = isGroup ? 'name' : 'text';
79
81
  const min = isGroup ? LIMITS.groupsMin : LIMITS.optionsMin;
@@ -98,10 +100,13 @@ export function createEditor({ rerender, root, templates, labels }) {
98
100
  const value = answer.get(item);
99
101
  if (answer.type === 'select') pick.value = String(value ?? '');
100
102
  else pick.checked = Boolean(value);
101
- pick.addEventListener('change', () =>
102
- answer.set(item, answer.type === 'select' ? pick.value : pick.checked),
103
- );
103
+ pick.addEventListener('change', () => {
104
+ answer.set(item, answer.type === 'select' ? pick.value : pick.checked);
105
+ // radio는 다른 줄의 정답도 바뀌므로 줄마다 다시 표시
106
+ rows.forEach((r, j) => markCorrect(r, items[j]));
107
+ });
104
108
  }
109
+ markCorrect(row, item);
105
110
  part(row, 'delete').addEventListener('click', () => {
106
111
  items.splice(i, 1);
107
112
  onDelete?.();
@@ -110,6 +115,9 @@ export function createEditor({ rerender, root, templates, labels }) {
110
115
  sortHandle(part(row, 'handle'), items, i, key);
111
116
  return row;
112
117
  });
118
+ function markCorrect(row, item) {
119
+ if (answer) row.toggleAttribute('data-correct', Boolean(answer.get(item)));
120
+ }
113
121
  const full = items.length >= max;
114
122
  const add = ui.addButton({ kind, full, max });
115
123
  add.addEventListener('click', () => {
@@ -122,9 +130,11 @@ export function createEditor({ rerender, root, templates, labels }) {
122
130
  }
123
131
  : { id: nextId(ids), text: '' },
124
132
  );
133
+ onAdd?.();
125
134
  rerender();
126
135
  });
127
- return ui.list({ rows, add });
136
+ // 정답 칸이 있으면 목록 위에 "정답" 열 머리 · 최소 개수라 지울 수 없으면 목록 아래 안내
137
+ return ui.list({ kind, rows, add, answer: answer?.type, atMin: items.length <= min, min });
128
138
  }
129
139
 
130
140
  /** list[from]을 to 자리로 옮기고 다시 그린 뒤, 키보드로 옮겼으면 옮긴 손잡이에 초점을 둔다 */
@@ -260,7 +260,7 @@ export function parseAnswerKey(questions, regex) {
260
260
  }
261
261
 
262
262
  /**
263
- * 정답 검증 1: 모든 문항에 정답이 있고, 정답이 지금 있는 보기 · 그룹을 가리키는지 (G63).
263
+ * 정답 검증 1: 모든 문항에 정답이 있고, 정답이 지금 있는 보기 · 그룹을 가리키는지.
264
264
  * 문제가 없으면 null, 있으면 { questionIndex, message }
265
265
  * @param {object} v 검증 문구 (ui/texts.js의 answers.validation)
266
266
  */