@eliceio/cdk-cli 1.5.4 → 1.6.0-entryqa.0

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 (70) 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 +1 -0
  24. package/skills/_shared/references/05-screen-code.md +1 -0
  25. package/templates/_shared/lib/cdk-mock.d.ts +33 -2
  26. package/templates/_shared/lib/cdk-mock.js +171 -5
  27. package/templates/_shared/lib/elice-content.d.ts +38 -0
  28. package/templates/_shared/lib/elice-content.js +85 -2
  29. package/templates/blank/template.json +1 -1
  30. package/templates/document/template.json +1 -1
  31. package/templates/entry/README.md +118 -0
  32. package/templates/entry/commentary.txt +2 -0
  33. package/templates/entry/core/autosave.d.ts +13 -0
  34. package/templates/entry/core/autosave.js +69 -0
  35. package/templates/entry/core/default-project.d.ts +2 -0
  36. package/templates/entry/core/default-project.js +139 -0
  37. package/templates/entry/core/dom.d.ts +13 -0
  38. package/templates/entry/core/dom.js +83 -0
  39. package/templates/entry/core/grading.d.ts +51 -0
  40. package/templates/entry/core/grading.js +125 -0
  41. package/templates/entry/core/pack.d.ts +12 -0
  42. package/templates/entry/core/pack.js +71 -0
  43. package/templates/entry/core/settings.d.ts +33 -0
  44. package/templates/entry/core/settings.js +79 -0
  45. package/templates/entry/core/workspace.d.ts +40 -0
  46. package/templates/entry/core/workspace.js +320 -0
  47. package/templates/entry/docs/storage.md +44 -0
  48. package/templates/entry/edit.html +17 -0
  49. package/templates/entry/gitignore +4 -0
  50. package/templates/entry/index.html +17 -0
  51. package/templates/entry/metadata.json +9 -0
  52. package/templates/entry/package.json +13 -0
  53. package/templates/entry/screens/edit/panels/answer-project.js +15 -0
  54. package/templates/entry/screens/edit/panels/grading.d.ts +18 -0
  55. package/templates/entry/screens/edit/panels/grading.js +516 -0
  56. package/templates/entry/screens/edit/panels/index.js +25 -0
  57. package/templates/entry/screens/edit/panels/preference.js +38 -0
  58. package/templates/entry/screens/edit/panels/project-panel.js +97 -0
  59. package/templates/entry/screens/edit/panels/start-project.js +6 -0
  60. package/templates/entry/screens/edit.js +263 -0
  61. package/templates/entry/screens/learn.js +255 -0
  62. package/templates/entry/styles.css +872 -0
  63. package/templates/entry/template.json +6 -0
  64. package/templates/entry/ui/templates/page.js +81 -0
  65. package/templates/entry/ui/texts.d.ts +3 -0
  66. package/templates/entry/ui/texts.js +164 -0
  67. package/templates/entry/ui/theme.css +17 -0
  68. package/templates/quiz/template.json +1 -1
  69. package/templates/steps/template.json +1 -1
  70. package/templates/video/template.json +1 -1
@@ -0,0 +1,516 @@
1
+ // 패널: 채점 방식 ('채점 설정' 탭). 일반 채점 · AI 채점과 AI 채점 기준(오브젝트 · 채점 기준 · 부분 점수)을 고릅니다.
2
+ // secret: settings.grading에 저장합니다 (학생에게 안 감). 모양은 core/grading.js, 정답 작품은 answer-project.js 패널.
3
+ // 화면 배치: 채점 방식 줄은 탭 위쪽, AI 채점 기준은 정답 작품 워크스페이스 아래 (styles.css의 order).
4
+ // 오브젝트 목록은 정답 작품에서 받습니다(ctx.objects: 정답 작품 워크스페이스의 TO_GET_OBJECTS, 띄우기 전이면 저장된 정답 → 시작 화면).
5
+ // 정답 작품은 시작 화면을 복사해 시작하므로 학생 작품과 같은 오브젝트 id를 가집니다. 작품 전체("공통") 기준은 없습니다(서버가 받지 않음):
6
+ // 새 줄은 오브젝트를 고르지 않은 채로 시작하고, 고르지 않거나 정답 작품에 없는 오브젝트면 저장을 막습니다.
7
+ import { html } from '../../../core/dom.js';
8
+ import { readGrading, RUBRIC_LIMITS, rubricsProblem } from '../../../core/grading.js';
9
+ import { texts } from '../../../ui/texts.js';
10
+
11
+ const t = texts.edit.grading;
12
+ /** 아직 고르지 않은 오브젝트 칸 */
13
+ const UNSET = '';
14
+ const emptyRow = () => ({ object: UNSET, criteria: '', score: null });
15
+
16
+ /** 요소 만들기: class · on* (이벤트) · 그 밖은 속성. false · null 속성과 null 자식은 뺌 */
17
+ function node(tag, attrs = {}, ...children) {
18
+ const e = document.createElement(tag);
19
+ for (const [k, v] of Object.entries(attrs)) {
20
+ if (v === false || v === null || v === undefined) continue;
21
+ if (k === 'class') e.className = v;
22
+ else if (k.startsWith('on')) e.addEventListener(k.slice(2), v);
23
+ else e.setAttribute(k, v === true ? '' : v);
24
+ }
25
+ e.append(...children.flat().filter(c => c !== null && c !== undefined));
26
+ return e;
27
+ }
28
+
29
+ const icon = {
30
+ close: () =>
31
+ html`<span aria-hidden="true"
32
+ ><svg
33
+ width="18"
34
+ height="18"
35
+ viewBox="0 0 24 24"
36
+ fill="none"
37
+ stroke="currentColor"
38
+ stroke-width="2"
39
+ stroke-linecap="round"
40
+ >
41
+ <path d="M6 6l12 12M18 6 6 18" /></svg
42
+ ></span>`,
43
+ plus: () =>
44
+ html`<span aria-hidden="true"
45
+ ><svg
46
+ width="16"
47
+ height="16"
48
+ viewBox="0 0 24 24"
49
+ fill="none"
50
+ stroke="currentColor"
51
+ stroke-width="2.5"
52
+ stroke-linecap="round"
53
+ >
54
+ <path d="M12 5v14M5 12h14" /></svg
55
+ ></span>`,
56
+ info: () =>
57
+ html`<span aria-hidden="true"
58
+ ><svg
59
+ width="16"
60
+ height="16"
61
+ viewBox="0 0 24 24"
62
+ fill="none"
63
+ stroke="currentColor"
64
+ stroke-width="2"
65
+ stroke-linecap="round"
66
+ >
67
+ <circle cx="12" cy="12" r="9" />
68
+ <path d="M12 11v5M12 8h.01" /></svg
69
+ ></span>`,
70
+ chevron: () =>
71
+ html`<span aria-hidden="true"
72
+ ><svg
73
+ width="16"
74
+ height="16"
75
+ viewBox="0 0 24 24"
76
+ fill="none"
77
+ stroke="currentColor"
78
+ stroke-width="2.5"
79
+ stroke-linecap="round"
80
+ stroke-linejoin="round"
81
+ >
82
+ <path d="m6 9 6 6 6-6" /></svg
83
+ ></span>`,
84
+ down: () =>
85
+ html`<span aria-hidden="true"
86
+ ><svg
87
+ width="16"
88
+ height="16"
89
+ viewBox="0 0 24 24"
90
+ fill="none"
91
+ stroke="currentColor"
92
+ stroke-width="2"
93
+ stroke-linecap="round"
94
+ stroke-linejoin="round"
95
+ >
96
+ <path d="M12 5v14M6 13l6 6 6-6" /></svg
97
+ ></span>`,
98
+ caret: () =>
99
+ html`<span class="en-select-caret" aria-hidden="true"
100
+ ><svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor">
101
+ <path d="M2 4h8L6 9z" /></svg
102
+ ></span>`,
103
+ };
104
+
105
+ /**
106
+ * 그림 주소를 이 화면에서 띄울 수 있나: data: · blob: · 콘텐츠와 같은 출처만.
107
+ * 워크스페이스가 주는 그림은 워크스페이스 출처(예: http://localhost:9000/renderer/…/thumb/…)라 콘텐츠 CSP img-src가 막는다 → 빈 칸
108
+ */
109
+ const showable = src => {
110
+ try {
111
+ const url = new URL(src, location.href);
112
+ return url.protocol === 'data:' || url.protocol === 'blob:' || url.origin === location.origin;
113
+ } catch {
114
+ return false;
115
+ }
116
+ };
117
+
118
+ /** 오브젝트 그림 칸 (그림이 없거나 띄울 수 없으면 빈 칸) */
119
+ function thumb(src) {
120
+ const box = node('span', { class: 'en-thumb', 'aria-hidden': 'true' });
121
+ if (src && showable(src)) {
122
+ const img = node('img', { src, alt: '', onerror: () => img.remove() });
123
+ box.append(img);
124
+ }
125
+ return box;
126
+ }
127
+
128
+ export default {
129
+ id: 'grading',
130
+ title: t.title,
131
+ tab: 'answer',
132
+ secret: true,
133
+ /** app.grading → { mode, rubrics } */
134
+ normalize(raw) {
135
+ const { mode, rubrics } = readGrading(raw);
136
+ return { mode, rubrics };
137
+ },
138
+ render(el, ctx) {
139
+ const get = () => ctx.value;
140
+ const update = patch => ctx.set({ ...get(), ...patch });
141
+
142
+ // 채점 방식 줄: 일반 채점 · AI 채점 + (AI일 때) 아래 기준으로 가는 링크
143
+ const modeCard = (mode, label) =>
144
+ node(
145
+ 'label',
146
+ { class: 'en-radio-card' },
147
+ node('input', {
148
+ class: 'ec-visually-hidden',
149
+ type: 'radio',
150
+ name: 'en-grading-mode',
151
+ value: mode,
152
+ checked: get().mode === mode,
153
+ onchange: e => {
154
+ if (!e.target.checked) return;
155
+ update({ mode });
156
+ showMode(true);
157
+ },
158
+ }),
159
+ node('span', { class: 'en-radio-card-title' }, label)
160
+ );
161
+ const hint = node(
162
+ 'button',
163
+ {
164
+ type: 'button',
165
+ class: 'en-hint-link',
166
+ onclick: () => {
167
+ const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
168
+ ai.scrollIntoView({ behavior: reduce ? 'auto' : 'smooth', block: 'start' });
169
+ ai.querySelector('button, input')?.focus({ preventScroll: true });
170
+ },
171
+ },
172
+ node('span', {}, t.aiHint),
173
+ icon.down()
174
+ );
175
+ const modeRow = node(
176
+ 'div',
177
+ { class: 'en-grading-mode' },
178
+ node('p', { class: 'en-field-title' }, t.method),
179
+ node(
180
+ 'fieldset',
181
+ { class: 'en-modes' },
182
+ node('legend', { class: 'ec-visually-hidden' }, t.method),
183
+ modeCard('general', t.modes.general),
184
+ modeCard('ai', t.modes.ai)
185
+ ),
186
+ hint,
187
+ // 완료 정책 안내: 채점 결과로 완료하려면 LXP 설정에서 '답안 확인 후 완료'(on_graded)
188
+ node('p', { class: 'en-grading-note' }, icon.info(), node('span', {}, t.policyNote))
189
+ );
190
+
191
+ // 채점 기준 예시 (팝오버)
192
+ const exampleButton = node(
193
+ 'button',
194
+ {
195
+ type: 'button',
196
+ class: 'en-link-button en-example-button',
197
+ 'aria-haspopup': 'true',
198
+ 'aria-expanded': 'false',
199
+ onclick: e => {
200
+ e.stopPropagation();
201
+ togglePopover();
202
+ },
203
+ },
204
+ node('span', {}, t.exampleToggle),
205
+ icon.chevron()
206
+ );
207
+ const popover = node(
208
+ 'div',
209
+ { class: 'en-popover', role: 'dialog', 'aria-label': t.exampleToggle, hidden: true },
210
+ node(
211
+ 'ul',
212
+ {},
213
+ t.examples.map(x => node('li', {}, x))
214
+ )
215
+ );
216
+ const popWrap = node('span', { class: 'en-pop-wrap' }, exampleButton, popover);
217
+ function togglePopover(force) {
218
+ const open = force ?? popover.hidden;
219
+ popover.hidden = !open;
220
+ exampleButton.setAttribute('aria-expanded', String(open));
221
+ }
222
+ document.addEventListener('click', e => popWrap.contains(e.target) || togglePopover(false));
223
+ document.addEventListener('keydown', e => e.key === 'Escape' && togglePopover(false));
224
+
225
+ const required = () => node('span', { class: 'en-required', 'aria-hidden': 'true' }, '*');
226
+ const scoreInfo = node(
227
+ 'span',
228
+ {
229
+ class: 'en-info',
230
+ role: 'img',
231
+ 'aria-label': t.scoreInfo,
232
+ title: t.scoreInfo,
233
+ tabindex: '0',
234
+ },
235
+ icon.info()
236
+ );
237
+ const list = node('div', { class: 'en-criteria' });
238
+ const addButton = node(
239
+ 'button',
240
+ { type: 'button', class: 'en-add-button', onclick: () => addRow() },
241
+ icon.plus(),
242
+ node('span', {}, t.add)
243
+ );
244
+ const ai = node(
245
+ 'div',
246
+ { class: 'en-ai' },
247
+ node(
248
+ 'div',
249
+ { class: 'en-ai-head' },
250
+ node(
251
+ 'div',
252
+ { class: 'en-ai-title' },
253
+ node('p', { class: 'en-ai-title-text' }, t.aiTitle),
254
+ node('p', { class: 'en-ai-desc-text' }, t.aiDescription)
255
+ ),
256
+ popWrap
257
+ ),
258
+ node(
259
+ 'div',
260
+ { class: 'en-criteria-form' },
261
+ node(
262
+ 'div',
263
+ { class: 'en-criteria-head', 'aria-hidden': 'true' },
264
+ node('span', {}, t.columns.object, required()),
265
+ node('span', {}, t.columns.criterion, required()),
266
+ node('span', {}, t.columns.score, required(), scoreInfo),
267
+ node('span', {})
268
+ ),
269
+ list,
270
+ addButton
271
+ )
272
+ );
273
+
274
+ // 오브젝트 목록 (정답 작품). 고를 때마다 새로 받음
275
+ let objects = [];
276
+ let loaded = false;
277
+ const loadObjects = async () => {
278
+ try {
279
+ objects = (await ctx.objects())
280
+ .filter(o => o && typeof o.id === 'string' && o.id)
281
+ .map(o => ({
282
+ id: o.id,
283
+ name: typeof o.name === 'string' && o.name ? o.name : o.id,
284
+ thumbnail: typeof o.thumbnail === 'string' ? o.thumbnail : '',
285
+ }));
286
+ loaded = true;
287
+ } catch {
288
+ // 워크스페이스가 아직 준비 전이면 이전 목록
289
+ }
290
+ };
291
+ const objectOf = id => objects.find(o => o.id === id);
292
+ // 목록을 받기 전에는 '불러오는 중'
293
+ const labelOf = id =>
294
+ id === UNSET ? t.selectObject : (objectOf(id)?.name ?? (loaded ? t.unknownObject : texts.page.loading));
295
+
296
+ // 열린 오브젝트 메뉴 닫기 (바깥 클릭 · 스크롤 · 크기 바뀜)
297
+ let closeOpenMenu = null;
298
+ const closeAny = () => closeOpenMenu?.();
299
+ document.addEventListener('click', closeAny);
300
+ document.addEventListener('scroll', closeAny, true);
301
+ addEventListener('resize', closeAny);
302
+
303
+ /** 오브젝트 고르기 (목록 상자) */
304
+ const objectSelect = index => {
305
+ const button = node('button', {
306
+ type: 'button',
307
+ class: 'en-field en-select-button',
308
+ 'aria-haspopup': 'listbox',
309
+ 'aria-expanded': 'false',
310
+ 'aria-label': t.columns.object,
311
+ // 고른 값 표시 · 메뉴 그리기는 내용 변경이 아님 (키트 저장 바의 '저장하지 않은 변경' 감지에서 뺌)
312
+ 'data-ec-quiet': true,
313
+ });
314
+ const paint = id => {
315
+ button.replaceChildren(
316
+ ...(id === UNSET ? [] : [thumb(objectOf(id)?.thumbnail)]),
317
+ node('span', { class: 'en-select-value', 'data-empty': id === UNSET }, labelOf(id)),
318
+ icon.caret()
319
+ );
320
+ };
321
+ const repaint = () => paint(get().rubrics[index]?.object ?? UNSET);
322
+ repaint();
323
+ repaints.push(repaint);
324
+ const menu = node('ul', {
325
+ class: 'en-menu',
326
+ role: 'listbox',
327
+ hidden: true,
328
+ 'aria-label': t.columns.object,
329
+ 'data-ec-quiet': true,
330
+ });
331
+ const options = () => [...menu.querySelectorAll('[role="option"]')];
332
+ const close = (focus = false) => {
333
+ if (menu.hidden) return;
334
+ menu.hidden = true;
335
+ button.setAttribute('aria-expanded', 'false');
336
+ if (closeOpenMenu === close) closeOpenMenu = null;
337
+ if (focus) button.focus();
338
+ };
339
+ const choose = id => {
340
+ updateRow(index, { object: id });
341
+ paint(id);
342
+ close(true);
343
+ };
344
+ const open = async () => {
345
+ closeAny();
346
+ await loadObjects();
347
+ const current = get().rubrics[index]?.object ?? UNSET;
348
+ const items = [...objects];
349
+ // 저장된 기준의 오브젝트가 정답 작품에 없으면 '없는 오브젝트'로 보여 줌 (고르면 바뀌고, 그대로면 저장을 막음)
350
+ if (current !== UNSET && !items.some(o => o.id === current))
351
+ items.push({ id: current, name: t.unknownObject, thumbnail: '' });
352
+ menu.replaceChildren(
353
+ ...items.map(o =>
354
+ node(
355
+ 'li',
356
+ {
357
+ class: 'en-menu-item',
358
+ role: 'option',
359
+ tabindex: '-1',
360
+ 'aria-selected': String(o.id === current),
361
+ onclick: e => {
362
+ e.stopPropagation();
363
+ choose(o.id);
364
+ },
365
+ },
366
+ thumb(o.thumbnail),
367
+ node('span', {}, o.name)
368
+ )
369
+ ),
370
+ ...(items.length ? [] : [node('li', { class: 'en-menu-empty' }, t.noObjects)])
371
+ );
372
+ menu.hidden = false;
373
+ button.setAttribute('aria-expanded', 'true');
374
+ const box = button.getBoundingClientRect();
375
+ menu.style.minWidth = `${box.width}px`;
376
+ menu.style.left = `${box.left}px`;
377
+ const height = menu.getBoundingClientRect().height;
378
+ const above = box.bottom + height + 8 > innerHeight && box.top > height + 8;
379
+ menu.style.top = `${above ? box.top - height - 4 : box.bottom + 4}px`;
380
+ closeOpenMenu = close;
381
+ (options().find(o => o.getAttribute('aria-selected') === 'true') ?? options()[0])?.focus();
382
+ };
383
+ button.addEventListener('click', e => {
384
+ e.stopPropagation();
385
+ if (menu.hidden) void open();
386
+ else close();
387
+ });
388
+ button.addEventListener('keydown', e => {
389
+ if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
390
+ e.preventDefault();
391
+ void open();
392
+ });
393
+ menu.addEventListener('keydown', e => {
394
+ const all = options();
395
+ const at = all.indexOf(document.activeElement);
396
+ if (e.key === 'ArrowDown') all[Math.min(at + 1, all.length - 1)]?.focus();
397
+ else if (e.key === 'ArrowUp') all[Math.max(at - 1, 0)]?.focus();
398
+ else if (e.key === 'Home') all[0]?.focus();
399
+ else if (e.key === 'End') all[all.length - 1]?.focus();
400
+ else if (e.key === 'Enter' || e.key === ' ') all[at]?.click();
401
+ else if (e.key === 'Escape') close(true);
402
+ else if (e.key === 'Tab') close();
403
+ else return;
404
+ e.preventDefault();
405
+ e.stopPropagation();
406
+ });
407
+ return node('div', { class: 'en-select' }, button, menu);
408
+ };
409
+
410
+ const updateRow = (index, patch) =>
411
+ update({ rubrics: get().rubrics.map((r, i) => (i === index ? { ...r, ...patch } : r)) });
412
+ const addRow = () => {
413
+ if (get().rubrics.length >= RUBRIC_LIMITS.max) return;
414
+ update({ rubrics: [...get().rubrics, emptyRow()] });
415
+ paintRows();
416
+ list.lastElementChild?.querySelector('.en-select-button')?.focus();
417
+ };
418
+ const removeRow = index => {
419
+ if (index === 0 || get().rubrics.length <= 1) return;
420
+ update({ rubrics: get().rubrics.filter((_, i) => i !== index) });
421
+ paintRows();
422
+ };
423
+
424
+ /** 오브젝트 칸마다 다시 그리기 (오브젝트 이름 · 그림을 받은 뒤) */
425
+ let repaints = [];
426
+ function paintRows() {
427
+ const rows = get().rubrics;
428
+ repaints = [];
429
+ list.replaceChildren(
430
+ ...rows.map((row, index) => {
431
+ const criteria = node('input', {
432
+ class: 'en-field',
433
+ type: 'text',
434
+ value: row.criteria,
435
+ maxlength: String(RUBRIC_LIMITS.criteriaMax),
436
+ placeholder: t.criterionPlaceholder,
437
+ 'aria-label': t.columns.criterion,
438
+ oninput: e => updateRow(index, { criteria: e.target.value }),
439
+ });
440
+ const score = node('input', {
441
+ class: 'en-score-input',
442
+ type: 'number',
443
+ inputmode: 'numeric',
444
+ min: String(RUBRIC_LIMITS.scoreMin),
445
+ max: String(RUBRIC_LIMITS.total),
446
+ step: '1',
447
+ value: row.score === null ? '' : String(row.score),
448
+ placeholder: t.scorePlaceholder,
449
+ 'aria-label': t.columns.score,
450
+ oninput: e => {
451
+ const n = e.target.value === '' ? null : Number(e.target.value);
452
+ updateRow(index, { score: Number.isInteger(n) ? n : null });
453
+ },
454
+ });
455
+ // 첫 줄은 지우지 않음 (기준은 하나 이상): 자리만 둠
456
+ const remove =
457
+ index === 0
458
+ ? node('span', {
459
+ class: 'en-icon-button en-icon-button--placeholder',
460
+ 'aria-hidden': 'true',
461
+ })
462
+ : node(
463
+ 'button',
464
+ {
465
+ type: 'button',
466
+ class: 'en-icon-button',
467
+ 'aria-label': t.remove,
468
+ title: t.remove,
469
+ onclick: () => removeRow(index),
470
+ },
471
+ icon.close()
472
+ );
473
+ return node(
474
+ 'div',
475
+ { class: 'en-criterion' },
476
+ objectSelect(index),
477
+ criteria,
478
+ node(
479
+ 'label',
480
+ { class: 'en-field en-score-field' },
481
+ score,
482
+ node('span', { class: 'en-unit' }, t.unit)
483
+ ),
484
+ remove
485
+ );
486
+ })
487
+ );
488
+ addButton.disabled = rows.length >= RUBRIC_LIMITS.max;
489
+ }
490
+
491
+ /** 방식에 맞게 보이기. AI로 바꿨는데 기준이 없으면 빈 줄 하나 */
492
+ function showMode(changed = false) {
493
+ const isAi = get().mode === 'ai';
494
+ hint.style.visibility = isAi ? 'visible' : 'hidden';
495
+ ai.hidden = !isAi;
496
+ if (changed && isAi && !get().rubrics.length) update({ rubrics: [emptyRow()] });
497
+ if (isAi) paintRows();
498
+ }
499
+
500
+ el.append(modeRow, ai);
501
+ showMode();
502
+ // 오브젝트 이름 · 그림을 받으면 다시 그림 (저장된 기준의 오브젝트 이름)
503
+ void loadObjects().then(() => repaints.forEach(repaint => repaint()));
504
+ },
505
+ validate(value) {
506
+ if (value.mode !== 'ai') return true;
507
+ const problem = rubricsProblem(value.rubrics);
508
+ if (!problem) return true;
509
+ if (problem.code === 'total') return t.errors.total(problem.total, RUBRIC_LIMITS.total);
510
+ if (problem.code === 'score')
511
+ return t.errors.score(RUBRIC_LIMITS.scoreMin, RUBRIC_LIMITS.total);
512
+ if (problem.code === 'tooLong') return t.errors.tooLong(RUBRIC_LIMITS.criteriaMax);
513
+ if (problem.code === 'tooMany') return t.errors.tooMany(RUBRIC_LIMITS.max);
514
+ return t.errors[problem.code];
515
+ },
516
+ };
@@ -0,0 +1,25 @@
1
+ // 편집 화면 패널 목록. 위에서부터 순서대로 그립니다. 새 기능 = 패널 파일 하나 + 이 목록에 한 줄.
2
+ //
3
+ // 패널 하나의 약속 (preference.js · grading.js · project-panel.js가 예):
4
+ // export default {
5
+ // id: 'blocks', // settings.entry.blocks 에 저장 (패널은 자기 칸만 읽고 씀)
6
+ // title: '쓸 블록',
7
+ // tab: 'start', // (선택) 이 탭 안에 그림: 'start'(시작 화면) · 'answer'(채점 설정). 없으면 탭 위
8
+ // secret: true, // (선택) settings.entry가 아니라 settings.grading으로 (학생에게 안 감).
9
+ // // normalize는 app.grading을 받고, screens/edit.js가 core/grading.js buildGrading으로 합침
10
+ // normalize(raw) { … }, // 저장된 값 → 패널 값 (없거나 틀리면 기본값)
11
+ // render(el, ctx) { … }, // el에 입력을 그림. ctx: { value, set(v), markDirty(), workspace(), objects(), onShow(cb), opened, app, texts }
12
+ // async collect(ctx) { … }, // (선택) 저장 직전에 값을 정함 (예: 워크스페이스에서 작품 꺼내기)
13
+ // validate(value, info) { … }, // (선택) true 또는 막을 문구. info.settingsBytes: 저장할 settings 전체 크기
14
+ // toPreference(value) { … }, // (선택) 워크스페이스 설정(GET_ELICE_PREFERENCE)에 합칠 값
15
+ // };
16
+ //
17
+ // 워크스페이스는 탭마다 하나 (ctx.workspace(): 'start' 탭 패널은 시작 화면, 'answer' 탭 패널은 정답 작품).
18
+ // 워크스페이스가 지금 받는 설정은 workspaceMode 하나뿐입니다. 숨길 블록 같은 새 설정은 워크스페이스에 받는 코드가 필요합니다.
19
+ // 채점 설정 탭의 배치(채점 방식 → 정답 작품 → AI 채점 기준)는 styles.css의 order가 정합니다.
20
+ import answerProject from './answer-project.js';
21
+ import grading from './grading.js';
22
+ import preference from './preference.js';
23
+ import startProject from './start-project.js';
24
+
25
+ export default [preference, startProject, grading, answerProject];
@@ -0,0 +1,38 @@
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
+ const info = html`<p class="ec-muted">${t.info}</p>`;
33
+ el.append(group, info);
34
+ },
35
+ toPreference(value) {
36
+ return { workspaceMode: value.workspaceMode };
37
+ },
38
+ };
@@ -0,0 +1,97 @@
1
+ // 작품 패널 만들기: 워크스페이스(?mode=skeleton) 하나 + 크기 줄 + 안내 목록. 시작 화면 · 정답 작품 패널이 씁니다.
2
+ // 저장 직전 워크스페이스에서 작품을 꺼내 core/pack.js 모양({ enc: 'gzip+base64', data })으로 줄입니다.
3
+ // 크기: 블록이 바뀌면 2초 뒤 작품을 꺼내 재고, 저장할 때 다시 잽니다. settings 전체가 서버 한도(64KB)를 넘으면 저장을 막습니다.
4
+ import { infoList } from '../../../lib/elice-content.js';
5
+ import { html } from '../../../core/dom.js';
6
+ import { packedProject } from '../../../core/grading.js';
7
+ import { formatBytes, jsonBytes, pack } from '../../../core/pack.js';
8
+ import { LIMITS } from '../../../core/settings.js';
9
+
10
+ const MEASURE_DELAY_MS = 2000;
11
+
12
+ /**
13
+ * @param {{
14
+ * id: string,
15
+ * tab: string,
16
+ * t: { title: string, info: string[], size: Function, sizeUnknown: string, tooLarge: Function, noProject: string, heldFromMenu: string },
17
+ * lazy?: boolean, // 탭을 처음 열 때 워크스페이스를 띄움 (그 전에는 저장된 값을 그대로 저장)
18
+ * secret?: boolean, // settings.entry가 아니라 settings.grading에 저장 (학생에게 안 감). normalize는 app.grading을 받음
19
+ * fromGrading?: (grading: unknown) => unknown,
20
+ * }} options
21
+ */
22
+ export function projectPanel({ id, tab, t, lazy = false, secret = false, fromGrading }) {
23
+ return {
24
+ id,
25
+ title: t.title,
26
+ tab,
27
+ secret,
28
+ normalize: raw => packedProject(secret ? fromGrading(raw) : raw),
29
+ render(el, ctx) {
30
+ const size = html`<p class="en-size" data-ec-quiet role="status">${t.sizeUnknown}</p>`;
31
+ const info = infoList(t.info);
32
+ info.setAttribute('data-ec-quiet', '');
33
+ el.append(size, info);
34
+
35
+ /** 크기 줄: 줄인 작품 크기와 settings 전체 크기 */
36
+ const paint = packed => {
37
+ const total = ctx.settingsBytes(packed);
38
+ size.textContent = t.size(
39
+ formatBytes(jsonBytes(packed)),
40
+ formatBytes(total),
41
+ formatBytes(LIMITS.settingsBytes)
42
+ );
43
+ size.dataset.over = String(total > LIMITS.settingsBytes);
44
+ };
45
+ if (ctx.value) paint(ctx.value);
46
+
47
+ let timer = null;
48
+ const open = () => {
49
+ const ws = ctx.workspace();
50
+ // 워크스페이스를 붙이는 것은 내용 변경이 아님 (키트 저장 바의 '저장하지 않은 변경' 감지에서 뺌)
51
+ ws.element.setAttribute('data-ec-quiet', '');
52
+ el.prepend(ws.element);
53
+ const measure = () => {
54
+ clearTimeout(timer);
55
+ timer = setTimeout(async () => {
56
+ try {
57
+ paint(await pack(await ws.getProject()));
58
+ } catch {
59
+ // 꺼내지 못하면(파이썬 문법 오류 등) 크기 줄은 그대로, 저장할 때 다시 시도
60
+ }
61
+ }, MEASURE_DELAY_MS);
62
+ };
63
+ // 워크스페이스 안에서 바뀐 것은 이 화면의 입력 이벤트가 아니므로 직접 '저장하지 않은 변경'으로 표시한다
64
+ ws.onChange(() => {
65
+ ctx.markDirty();
66
+ measure();
67
+ });
68
+ ctx.onHeld(() => {
69
+ ctx.markDirty();
70
+ size.textContent = t.heldFromMenu;
71
+ measure();
72
+ });
73
+ };
74
+ if (lazy) ctx.onShow(() => ctx.opened || open());
75
+ else open();
76
+ ctx.onCollected(paint);
77
+ },
78
+ /** 저장 직전: 워크스페이스에서 지금 작품을 꺼내 줄인다 (워크스페이스 '저장하기'로 받은 작품이 있으면 그것). 열지 않았으면 저장된 값 */
79
+ async collect(ctx) {
80
+ let project = ctx.takeHeld();
81
+ if (!project) {
82
+ if (!ctx.opened) return ctx.value;
83
+ try {
84
+ project = await ctx.workspace().getProject();
85
+ } catch {
86
+ throw new Error(t.noProject);
87
+ }
88
+ }
89
+ return pack(project);
90
+ },
91
+ validate(value, { settingsBytes }) {
92
+ if (settingsBytes > LIMITS.settingsBytes)
93
+ return t.tooLarge(formatBytes(settingsBytes), formatBytes(LIMITS.settingsBytes));
94
+ return true;
95
+ },
96
+ };
97
+ }
@@ -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 });