@eliceio/cdk-cli 1.5.4 → 1.6.0-entryqa.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 (74) hide show
  1. package/README.md +31 -29
  2. package/es/commands/create/index.js +1 -0
  3. package/es/commands/create/scaffold.d.ts +1 -1
  4. package/es/commands/create/scaffold.js +1 -1
  5. package/es/core/config.d.ts +61 -2
  6. package/es/core/config.js +309 -3
  7. package/es/dev/grading.d.ts +31 -2
  8. package/es/dev/grading.js +68 -1
  9. package/es/dev/mock-api.d.ts +3 -1
  10. package/es/dev/mock-api.js +34 -4
  11. package/es/dev/server.js +5 -4
  12. package/es/rules/answers.d.ts +1 -0
  13. package/es/rules/answers.js +3 -0
  14. package/es/rules/check.js +8 -1
  15. package/es/rules/csp.d.ts +7 -0
  16. package/es/rules/csp.js +24 -3
  17. package/es/rules/index.d.ts +1 -1
  18. package/es/rules/index.js +1 -1
  19. package/es/rules/types.d.ts +4 -3
  20. package/es/rules.json.js +1 -1
  21. package/package.json +2 -2
  22. package/rules.json +5 -4
  23. package/skills/_shared/references/02-design-the-material.md +2 -1
  24. package/skills/_shared/references/05-screen-code.md +1 -0
  25. package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
  26. package/templates/_shared/lib/cdk-mock.d.ts +33 -2
  27. package/templates/_shared/lib/cdk-mock.js +171 -5
  28. package/templates/_shared/lib/elice-content.d.ts +38 -0
  29. package/templates/_shared/lib/elice-content.js +85 -2
  30. package/templates/blank/template.json +1 -1
  31. package/templates/document/template.json +3 -2
  32. package/templates/entry/README.md +117 -0
  33. package/templates/entry/commentary.txt +2 -0
  34. package/templates/entry/core/autosave.d.ts +13 -0
  35. package/templates/entry/core/autosave.js +69 -0
  36. package/templates/entry/core/default-project.d.ts +2 -0
  37. package/templates/entry/core/default-project.js +139 -0
  38. package/templates/entry/core/dom.d.ts +13 -0
  39. package/templates/entry/core/dom.js +83 -0
  40. package/templates/entry/core/grading.d.ts +52 -0
  41. package/templates/entry/core/grading.js +139 -0
  42. package/templates/entry/core/pack.d.ts +12 -0
  43. package/templates/entry/core/pack.js +71 -0
  44. package/templates/entry/core/settings.d.ts +33 -0
  45. package/templates/entry/core/settings.js +79 -0
  46. package/templates/entry/core/workspace.d.ts +40 -0
  47. package/templates/entry/core/workspace.js +320 -0
  48. package/templates/entry/docs/storage.md +44 -0
  49. package/templates/entry/edit.html +17 -0
  50. package/templates/entry/gitignore +4 -0
  51. package/templates/entry/index.html +17 -0
  52. package/templates/entry/metadata.json +9 -0
  53. package/templates/entry/package.json +13 -0
  54. package/templates/entry/screens/edit/panels/answer-project.js +15 -0
  55. package/templates/entry/screens/edit/panels/grading.d.ts +18 -0
  56. package/templates/entry/screens/edit/panels/grading.js +627 -0
  57. package/templates/entry/screens/edit/panels/index.js +25 -0
  58. package/templates/entry/screens/edit/panels/preference.js +56 -0
  59. package/templates/entry/screens/edit/panels/project-panel.js +93 -0
  60. package/templates/entry/screens/edit/panels/start-project.js +6 -0
  61. package/templates/entry/screens/edit.js +293 -0
  62. package/templates/entry/screens/learn.js +268 -0
  63. package/templates/entry/styles.css +1037 -0
  64. package/templates/entry/template.json +6 -0
  65. package/templates/entry/ui/templates/page.js +106 -0
  66. package/templates/entry/ui/texts.d.ts +3 -0
  67. package/templates/entry/ui/texts.js +160 -0
  68. package/templates/entry/ui/theme.css +17 -0
  69. package/templates/quiz/README.md +1 -1
  70. package/templates/quiz/template.json +3 -2
  71. package/templates/steps/template.json +1 -1
  72. package/templates/survey/README.md +1 -0
  73. package/templates/survey/template.json +3 -2
  74. package/templates/video/template.json +3 -2
@@ -0,0 +1,56 @@
1
+ // 패널: 언어 선택 (블록 코딩 · 엔트리파이썬). settings.entry.preference = { workspaceMode }
2
+ // 학생 화면은 이 값을 워크스페이스 GET_ELICE_PREFERENCE 답으로 줍니다. 편집 화면은 바꾸면 워크스페이스를 다시 엽니다 (screens/edit.js).
3
+ import { html } from '../../../core/dom.js';
4
+ import { normalizePreference, WORKSPACE_MODES } from '../../../core/settings.js';
5
+ import { texts } from '../../../ui/texts.js';
6
+
7
+ export default {
8
+ id: 'preference',
9
+ title: texts.edit.preference.title,
10
+ normalize: normalizePreference,
11
+ render(el, ctx) {
12
+ const t = texts.edit.preference;
13
+ const name = 'en-workspace-mode';
14
+ const group = html`
15
+ <fieldset class="en-modes">
16
+ <legend class="ec-visually-hidden">${t.title}</legend>
17
+ ${WORKSPACE_MODES.map(
18
+ mode =>
19
+ html`<label class="en-radio-card">
20
+ <input class="ec-visually-hidden" type="radio" name="${name}" value="${mode}" />
21
+ <span class="en-radio-card-title">${t.modes[mode]}</span>
22
+ </label>`
23
+ )}
24
+ </fieldset>
25
+ `;
26
+ for (const input of group.querySelectorAll('input')) {
27
+ input.checked = input.value === ctx.value.workspaceMode;
28
+ input.addEventListener('change', () => {
29
+ if (input.checked) ctx.set({ workspaceMode: input.value });
30
+ });
31
+ }
32
+ // 안내 한 줄: 파란 정보 아이콘 + 글 (바꾸면 워크스페이스를 다시 엶)
33
+ const info = html`<div class="en-alert" role="status">
34
+ <span class="en-alert-icon" aria-hidden="true"
35
+ ><svg
36
+ width="20"
37
+ height="20"
38
+ viewBox="0 0 24 24"
39
+ fill="none"
40
+ stroke="currentColor"
41
+ stroke-width="1.75"
42
+ stroke-linecap="round"
43
+ stroke-linejoin="round"
44
+ >
45
+ <circle cx="12" cy="12" r="9.25" />
46
+ <path d="M12 11v6" />
47
+ <circle cx="12" cy="7.75" r="0.6" fill="currentColor" /></svg
48
+ ></span>
49
+ <span>${t.info}</span>
50
+ </div>`;
51
+ el.append(group, info);
52
+ },
53
+ toPreference(value) {
54
+ return { workspaceMode: value.workspaceMode };
55
+ },
56
+ };
@@ -0,0 +1,93 @@
1
+ // 작품 패널 만들기: 워크스페이스(?mode=skeleton) 하나 + 아래 줄(왼쪽 안내 목록 · 오른쪽 용량 칩). 시작 화면 · 정답 작품 패널이 씁니다.
2
+ // 저장 직전 워크스페이스에서 작품을 꺼내 core/pack.js 모양({ enc: 'gzip+base64', data })으로 줄입니다.
3
+ // 용량: 블록이 바뀌면 2초 뒤 작품을 꺼내 settings 전체 크기를 다시 재고(칩은 screens/edit.js가 두 탭 모두 같이 바꿈),
4
+ // 저장할 때 다시 잽니다. settings 전체가 서버 한도(64KB)를 넘으면 칩 위에 빨간 글을 띄우고 저장을 막습니다.
5
+ import { infoList } from '../../../lib/elice-content.js';
6
+ import { html } from '../../../core/dom.js';
7
+ import { packedProject } from '../../../core/grading.js';
8
+ import { formatBytes, pack } from '../../../core/pack.js';
9
+ import { LIMITS } from '../../../core/settings.js';
10
+ import { texts } from '../../../ui/texts.js';
11
+
12
+ const MEASURE_DELAY_MS = 2000;
13
+
14
+ /**
15
+ * @param {{
16
+ * id: string,
17
+ * tab: string,
18
+ * t: { title: string, info: string[], noProject: string },
19
+ * lazy?: boolean, // 탭을 처음 열 때 워크스페이스를 띄움 (그 전에는 저장된 값을 그대로 저장)
20
+ * secret?: boolean, // settings.entry가 아니라 settings.grading에 저장 (학생에게 안 감). normalize는 app.grading을 받음
21
+ * fromGrading?: (grading: unknown) => unknown,
22
+ * }} options
23
+ */
24
+ export function projectPanel({ id, tab, t, lazy = false, secret = false, fromGrading }) {
25
+ return {
26
+ id,
27
+ title: t.title,
28
+ tab,
29
+ secret,
30
+ normalize: raw => packedProject(secret ? fromGrading(raw) : raw),
31
+ render(el, ctx) {
32
+ const info = infoList(t.info);
33
+ info.setAttribute('data-ec-quiet', '');
34
+ const footer = html`<div class="en-panel-footer">${info}${ctx.sizeBox()}</div>`;
35
+ el.append(footer);
36
+
37
+ let timer = null;
38
+ const open = () => {
39
+ const ws = ctx.workspace();
40
+ // 워크스페이스를 붙이는 것은 내용 변경이 아님 (키트 저장 바의 '저장하지 않은 변경' 감지에서 뺌)
41
+ ws.element.setAttribute('data-ec-quiet', '');
42
+ el.prepend(ws.element);
43
+ const measure = () => {
44
+ clearTimeout(timer);
45
+ timer = setTimeout(
46
+ async () => {
47
+ try {
48
+ ctx.measured(await pack(await ws.getProject()));
49
+ } catch {
50
+ // 꺼내지 못하면(파이썬 문법 오류 등) 칩은 그대로, 저장할 때 다시 시도
51
+ }
52
+ },
53
+ MEASURE_DELAY_MS
54
+ );
55
+ };
56
+ // 워크스페이스 안에서 바뀐 것은 이 화면의 입력 이벤트가 아니므로 직접 '저장하지 않은 변경'으로 표시한다
57
+ ws.onChange(() => {
58
+ ctx.markDirty();
59
+ measure();
60
+ });
61
+ // 워크스페이스 '저장하기'로 받은 작품도 저장 바의 '저장하지 않은 변경'으로 (아래 저장을 눌러야 저장됨)
62
+ ctx.onHeld(() => {
63
+ ctx.markDirty();
64
+ measure();
65
+ });
66
+ };
67
+ if (lazy) ctx.onShow(() => ctx.opened || open());
68
+ else open();
69
+ ctx.onCollected(packed => ctx.measured(packed));
70
+ },
71
+ /** 저장 직전: 워크스페이스에서 지금 작품을 꺼내 줄인다 (워크스페이스 '저장하기'로 받은 작품이 있으면 그것). 열지 않았으면 저장된 값 */
72
+ async collect(ctx) {
73
+ let project = ctx.takeHeld();
74
+ if (!project) {
75
+ if (!ctx.opened) return ctx.value;
76
+ try {
77
+ project = await ctx.workspace().getProject();
78
+ } catch {
79
+ throw new Error(t.noProject);
80
+ }
81
+ }
82
+ return pack(project);
83
+ },
84
+ validate(value, { settingsBytes }) {
85
+ if (settingsBytes > LIMITS.settingsBytes)
86
+ return texts.edit.size.tooLarge(
87
+ formatBytes(settingsBytes),
88
+ formatBytes(LIMITS.settingsBytes)
89
+ );
90
+ return true;
91
+ },
92
+ };
93
+ }
@@ -0,0 +1,6 @@
1
+ // 패널: 시작 화면 ('시작 화면' 탭). 교육자가 워크스페이스에서 만든 작품을 settings.entry.startProject에 저장합니다.
2
+ // 학생은 이 작품으로 시작합니다. 모양 · 크기 검사는 project-panel.js.
3
+ import { texts } from '../../../ui/texts.js';
4
+ import { projectPanel } from './project-panel.js';
5
+
6
+ export default projectPanel({ id: 'startProject', tab: 'start', t: texts.edit.startProject });
@@ -0,0 +1,293 @@
1
+ // 내용 편집 화면. 위에 언어 선택, 아래 탭 카드('시작 화면' · '채점 설정')에 패널(screens/edit/panels/index.js)을 그리고,
2
+ // 키트 저장 바(useSave)로 저장합니다. 새 기능은 패널 파일 하나 + 목록에 한 줄 (panels/index.js 머리 주석).
3
+ //
4
+ // 저장하는 곳 (docs/storage.md):
5
+ // settings.entry.<패널 id> : 학생에게도 내려가는 값 (시작 화면 작품 · 언어)
6
+ // settings.grading : secret 패널(채점 방식 · 정답 작품)을 core/grading.js buildGrading으로 합친 것. 서버가 학생에게 내려주지 않음
7
+ //
8
+ // 워크스페이스(?mode=skeleton)는 탭마다 하나: 시작 화면은 처음부터 띄우고, 정답 작품은 '채점 설정' 탭을 처음 열 때 띄웁니다.
9
+ // 저장 전 검사(서버 422와 같은 규칙): AI 채점은 정답 작품 · 시작 화면 작품이 있어야 하고 기준의 오브젝트가 정답 작품에 있어야 함,
10
+ // 일반 채점은 정답 작품에 블록(또는 전역 리스트)이 있어야 함. 서버가 그래도 거절하면 키트가 서버 코드를 한국어 문구로 보여 줌.
11
+ import { start } from '../lib/elice-content.js';
12
+ import { part } from '../core/dom.js';
13
+ import { buildGrading, hasGradable, hasUnknownObject, projectObjects } from '../core/grading.js';
14
+ import { formatBytes, jsonBytes, unpack } from '../core/pack.js';
15
+ import { joinSettings, LIMITS, splitSettings } from '../core/settings.js';
16
+ import { connectWorkspace } from '../core/workspace.js';
17
+ import { loading, panelSection, sizeBox, tabCard, unavailable } from '../ui/templates/page.js';
18
+ import { texts } from '../ui/texts.js';
19
+ import panels from './edit/panels/index.js';
20
+
21
+ const root = document.getElementById('app');
22
+ document.title = texts.page.edit;
23
+ root.replaceChildren(loading('edit'));
24
+ const app = await start({ screen: 'edit' });
25
+ const { rest, entry: savedEntry } = splitSettings(app.content);
26
+
27
+ /** 패널 값 (id → 값). 저장된 값을 패널이 고친 모양으로. secret 패널은 settings.grading(app.grading)에서 */
28
+ const values = Object.fromEntries(
29
+ panels.map(p => {
30
+ const raw = p.secret ? app.grading : savedEntry[p.id];
31
+ return [p.id, p.normalize ? p.normalize(raw) : raw];
32
+ })
33
+ );
34
+ const secretIds = new Set(panels.filter(p => p.secret).map(p => p.id));
35
+
36
+ /** settings.entry에 넣을 값: 저장돼 있던 entry의 다른 칸(모르는 패널)은 그대로 두고 패널 값으로 덮는다. secret 패널 칸은 넣지 않음 */
37
+ const settingsWith = over => {
38
+ const entry = { ...savedEntry, ...values, ...over };
39
+ for (const id of secretIds) delete entry[id];
40
+ return joinSettings(rest, entry);
41
+ };
42
+ /** settings.grading (정답 작품이 없으면 null) */
43
+ const gradingWith = over => {
44
+ const v = { ...values, ...over };
45
+ return buildGrading(v.grading, v.answerProject);
46
+ };
47
+ /** 서버가 재는 settings 전체 크기 (grading 포함) */
48
+ const totalBytes = over => {
49
+ const grading = gradingWith(over);
50
+ return jsonBytes(grading ? { ...settingsWith(over), grading } : settingsWith(over));
51
+ };
52
+
53
+ /** 패널들의 toPreference를 합친 워크스페이스 설정 */
54
+ const preference = () =>
55
+ Object.assign({}, ...panels.map(p => (p.toPreference ? p.toPreference(values[p.id]) : {})));
56
+
57
+ // 워크스페이스: 'start'(시작 화면) · 'answer'(정답 작품). ctx.workspace()가 처음 부를 때 띄움
58
+ const startProject = await unpack(values.startProject);
59
+ const savedAnswer = await unpack(values.answerProject);
60
+ const workspaces = { start: null, answer: null };
61
+ // 워크스페이스 '저장하기'로 받은 작품 (저장 버튼이 쓰면 비움)
62
+ const held = { start: null, answer: null };
63
+ const heldListeners = { start: new Set(), answer: new Set() };
64
+ /** 정답 작품 워크스페이스가 처음 열 작품: 저장된 정답 → 없으면 지금 시작 화면 작품 (오브젝트 id가 같아야 AI 채점 기준이 맞음) */
65
+ const answerStart = async () =>
66
+ savedAnswer ?? (await workspaces.start?.getProject().catch(() => null)) ?? startProject;
67
+
68
+ const providers = {
69
+ start: { getProject: () => startProject, getInitialProject: () => startProject },
70
+ answer: { getProject: answerStart, getInitialProject: answerStart },
71
+ };
72
+
73
+ function workspace(name) {
74
+ if (workspaces[name]) return workspaces[name];
75
+ const ws = connectWorkspace({
76
+ mode: 'skeleton',
77
+ title: texts.page.workspace,
78
+ preference: preference(),
79
+ provider: {
80
+ ...providers[name],
81
+ saveProject: project => {
82
+ if (!project) return;
83
+ held[name] = project;
84
+ for (const cb of heldListeners[name]) cb(project);
85
+ },
86
+ },
87
+ });
88
+ ws.ready.catch(e => {
89
+ ws.element.replaceWith(
90
+ unavailable(e?.code === 'blocked' ? texts.unavailable.blocked : texts.unavailable.timeout)
91
+ );
92
+ });
93
+ workspaces[name] = ws;
94
+ return ws;
95
+ }
96
+
97
+ /** 언어를 바꾸면 띄운 워크스페이스를 지금 작품 그대로 다시 연다 (워크스페이스는 처음 열 때만 언어 설정을 물음) */
98
+ async function reloadWorkspaces() {
99
+ for (const ws of Object.values(workspaces)) {
100
+ if (!ws) continue;
101
+ ws.setPreference(preference());
102
+ try {
103
+ await ws.load(await ws.getProject());
104
+ } catch {
105
+ // 작품을 꺼내지 못하면(파이썬 문법 오류 등) 그대로 둠
106
+ }
107
+ }
108
+ }
109
+
110
+ // 용량 칩 (작품 패널 아래 오른쪽, 탭마다 하나): settings 전체 크기 / 서버 한도. 넘으면 칩 위에 빨간 글
111
+ const sizeBoxes = [];
112
+ let lastTotal = null;
113
+ function showTotal(total) {
114
+ lastTotal = total;
115
+ const over = total > LIMITS.settingsBytes;
116
+ for (const { chip, message } of sizeBoxes) {
117
+ chip.textContent = texts.edit.size.chip(formatBytes(total), formatBytes(LIMITS.settingsBytes));
118
+ chip.dataset.over = String(over);
119
+ message.textContent = over
120
+ ? texts.edit.size.tooLarge(formatBytes(total), formatBytes(LIMITS.settingsBytes))
121
+ : '';
122
+ message.hidden = !over;
123
+ }
124
+ }
125
+
126
+ /** 탭을 보일 때 부를 것 (패널마다) */
127
+ const showListeners = new Map(panels.map(p => [p, new Set()]));
128
+
129
+ /** 패널마다 넘기는 것 (패널마다 하나) */
130
+ const contexts = new Map(
131
+ panels.map(panel => {
132
+ const wsName = panel.tab === 'answer' ? 'answer' : 'start';
133
+ const collected = new Set();
134
+ const ctx = {
135
+ app,
136
+ texts,
137
+ get value() {
138
+ return values[panel.id];
139
+ },
140
+ set(v) {
141
+ values[panel.id] = v;
142
+ save.markDirty();
143
+ if (panel.toPreference) void reloadWorkspaces();
144
+ if (panel.id === 'grading') paintStartWarning();
145
+ showTotal(totalBytes({}));
146
+ },
147
+ markDirty: () => save.markDirty(),
148
+ /** 이 패널 탭의 워크스페이스 (처음 부르면 띄움) */
149
+ workspace: () => workspace(wsName),
150
+ /** 띄웠는지 */
151
+ get opened() {
152
+ return workspaces[wsName] !== null;
153
+ },
154
+ /**
155
+ * 정답 작품의 오브젝트 [{ id, name, thumbnail }] (AI 채점 기준은 정답 작품의 오브젝트 id로 맞춤).
156
+ * 정답 작품 워크스페이스를 띄웠으면 거기서, 아직이면 그 워크스페이스가 처음 열 작품(저장된 정답 → 시작 화면)에서 (그림 없음)
157
+ */
158
+ objects: async () => {
159
+ const ws = workspaces.answer;
160
+ if (!ws) return projectObjects(await answerStart());
161
+ await ws.ready;
162
+ return ws.getObjects();
163
+ },
164
+ /** 이 패널 탭을 보일 때 (처음 포함) */
165
+ onShow: cb => showListeners.get(panel).add(cb),
166
+ /** 이 패널 값이 v일 때 settings 전체 크기 (바이트, grading 포함) */
167
+ settingsBytes: v => totalBytes({ [panel.id]: v }),
168
+ /** 용량 칩 하나 (작품 패널 아래). 칩은 모든 탭이 같은 값 */
169
+ sizeBox() {
170
+ const box = sizeBox();
171
+ sizeBoxes.push({ chip: part(box, 'size-chip'), message: part(box, 'size-message') });
172
+ showTotal(lastTotal ?? totalBytes({}));
173
+ return box;
174
+ },
175
+ /** 워크스페이스에서 잰 이 패널의 작품(줄인 것)으로 용량 칩을 다시 그림 */
176
+ measured: v => showTotal(totalBytes({ [panel.id]: v })),
177
+ /** 이 패널의 탭을 보임 (저장 전 검사가 문제 칸으로 옮길 때) */
178
+ showTab: () => selectTab?.(panel.tab),
179
+ /** 워크스페이스 '저장하기'로 작품을 받았을 때 */
180
+ onHeld: cb => heldListeners[wsName].add(cb),
181
+ /** 받은 작품을 가져가고 비운다 (없으면 null) */
182
+ takeHeld() {
183
+ const p = held[wsName];
184
+ held[wsName] = null;
185
+ return p;
186
+ },
187
+ /** 저장 직전 collect가 값을 정했을 때 */
188
+ onCollected: cb => collected.add(cb),
189
+ collected,
190
+ };
191
+ return [panel, ctx];
192
+ })
193
+ );
194
+
195
+ const sections = panels.map(panel => {
196
+ const section = panelSection({ id: panel.id, title: panel.title, inTab: Boolean(panel.tab) });
197
+ panel.render(part(section, 'body'), contexts.get(panel));
198
+ return section;
199
+ });
200
+ root.replaceChildren(...sections);
201
+
202
+ // 탭 카드: 탭이 있는 패널을 모아 첫 탭 패널 자리에 둔다
203
+ let selectTab = null;
204
+ const tabbed = panels.map((panel, i) => ({ panel, section: sections[i] })).filter(x => x.panel.tab);
205
+ const tabNames = [...new Set(tabbed.map(x => x.panel.tab))];
206
+ if (tabbed.length) {
207
+ const card = tabCard({ tabs: tabNames });
208
+ tabbed[0].section.before(card);
209
+ card.append(...tabbed.map(x => x.section));
210
+ const tabs = [...card.querySelectorAll('[data-role="tab"]')];
211
+ const select = (name, focus = false) => {
212
+ for (const tab of tabs) {
213
+ const on = tab.dataset.tab === name;
214
+ tab.setAttribute('aria-selected', String(on));
215
+ tab.tabIndex = on ? 0 : -1;
216
+ if (on && focus) tab.focus();
217
+ }
218
+ for (const { panel, section } of tabbed) {
219
+ const on = panel.tab === name;
220
+ section.hidden = !on;
221
+ section.setAttribute('aria-labelledby', `en-tab-${panel.tab}`);
222
+ section.setAttribute('role', 'tabpanel');
223
+ if (on) for (const cb of showListeners.get(panel)) cb();
224
+ }
225
+ };
226
+ for (const [i, tab] of tabs.entries()) {
227
+ tab.addEventListener('click', () => select(tab.dataset.tab));
228
+ tab.addEventListener('keydown', e => {
229
+ const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;
230
+ if (!step) return;
231
+ e.preventDefault();
232
+ select(tabs[(i + step + tabs.length) % tabs.length].dataset.tab, true);
233
+ });
234
+ }
235
+ selectTab = select;
236
+ select(tabNames[0]);
237
+ }
238
+
239
+ // 시작 화면을 바꿀 때 경고 (막지 않음): AI 채점은 학생 작품을 지금 시작 화면과 비교해 '아직 안 함'을 가린다.
240
+ // 이미 시작한 학생은 옛 시작 화면에서 출발했으므로 바꾸면 채점이 틀릴 수 있다. SDK가 공개(버전) 여부를 알려 주지 않아
241
+ // 시작 화면을 저장한 적이 있는 자료면 보인다 (문구가 '이미 공개했다면'으로 조건을 말함)
242
+ const startWarning = document.createElement('p');
243
+ startWarning.className = 'en-warning';
244
+ startWarning.setAttribute('role', 'status');
245
+ startWarning.setAttribute('data-ec-quiet', '');
246
+ startWarning.textContent = texts.edit.startProject.changedWarning;
247
+ startWarning.hidden = true;
248
+ let startChanged = false;
249
+ function paintStartWarning() {
250
+ startWarning.hidden = !(startChanged && savedEntry.startProject && values.grading.mode === 'ai');
251
+ }
252
+ const startSection = sections[panels.findIndex(p => p.id === 'startProject')];
253
+ if (startSection) {
254
+ part(startSection, 'body').append(startWarning);
255
+ workspaces.start?.onChange(() => {
256
+ startChanged = true;
257
+ paintStartWarning();
258
+ });
259
+ }
260
+
261
+ /** 저장 직전에 푼 정답 작품 (검사용). 정답 작품이 없으면 null */
262
+ let answerDecoded = null;
263
+
264
+ const save = app.useSave({
265
+ label: texts.edit.save,
266
+ // 저장 직전: collect가 있는 패널은 값을 새로 정한다 (작품은 워크스페이스에서 꺼냄)
267
+ getContent: async () => {
268
+ for (const panel of panels) {
269
+ if (!panel.collect) continue;
270
+ const ctx = contexts.get(panel);
271
+ values[panel.id] = await panel.collect(ctx);
272
+ for (const cb of ctx.collected) cb(values[panel.id]);
273
+ }
274
+ answerDecoded = await unpack(values.answerProject);
275
+ return settingsWith({});
276
+ },
277
+ validate: () => {
278
+ const info = { settingsBytes: totalBytes({}) };
279
+ for (const panel of panels) {
280
+ const ok = panel.validate ? panel.validate(values[panel.id], info) : true;
281
+ if (ok !== true) return ok;
282
+ }
283
+ const g = texts.edit.grading.errors;
284
+ if (values.grading.mode === 'ai') {
285
+ if (!values.answerProject) return texts.edit.answerProject.missing;
286
+ if (!values.startProject) return g.noStartProject;
287
+ if (answerDecoded && hasUnknownObject(values.grading.rubrics, answerDecoded)) return g.unknownObject;
288
+ } else if (values.answerProject && answerDecoded && !hasGradable(answerDecoded)) return g.emptyAnswer;
289
+ return true;
290
+ },
291
+ // settings.grading: 정답 작품이 없으면(채점 설정 탭을 열지 않은 새 자료, 일반 채점) 저장된 채점 설정을 그대로 둠
292
+ getGrading: () => gradingWith({}) ?? undefined,
293
+ });