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

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 (38) hide show
  1. package/es/dev/learner-files.d.ts +88 -0
  2. package/es/dev/learner-files.js +282 -0
  3. package/es/dev/mock-api.d.ts +13 -0
  4. package/es/dev/mock-api.js +27 -3
  5. package/es/dev/server.d.ts +3 -0
  6. package/es/dev/server.js +35 -1
  7. package/es/rules/csp.d.ts +1 -0
  8. package/es/rules/csp.js +2 -0
  9. package/package.json +2 -2
  10. package/skills/_shared/references/02-design-the-material.md +1 -1
  11. package/skills/_shared/references/12-upload-with-the-material-mcp.md +1 -1
  12. package/templates/_shared/lib/cdk-mock.d.ts +18 -0
  13. package/templates/_shared/lib/cdk-mock.js +45 -0
  14. package/templates/_shared/lib/elice-content.d.ts +22 -0
  15. package/templates/_shared/lib/elice-content.js +50 -0
  16. package/templates/document/template.json +3 -2
  17. package/templates/entry/README.md +19 -8
  18. package/templates/entry/core/grading.d.ts +1 -0
  19. package/templates/entry/core/grading.js +14 -0
  20. package/templates/entry/core/ml-data.d.ts +51 -0
  21. package/templates/entry/core/ml-data.js +480 -0
  22. package/templates/entry/core/workspace.d.ts +2 -0
  23. package/templates/entry/core/workspace.js +21 -1
  24. package/templates/entry/docs/storage.md +5 -2
  25. package/templates/entry/screens/edit/panels/grading.js +165 -47
  26. package/templates/entry/screens/edit/panels/preference.js +19 -1
  27. package/templates/entry/screens/edit/panels/project-panel.js +24 -28
  28. package/templates/entry/screens/edit.js +34 -3
  29. package/templates/entry/screens/learn.js +51 -18
  30. package/templates/entry/styles.css +230 -65
  31. package/templates/entry/template.json +1 -1
  32. package/templates/entry/ui/templates/page.js +31 -6
  33. package/templates/entry/ui/texts.js +48 -52
  34. package/templates/quiz/README.md +1 -1
  35. package/templates/quiz/template.json +3 -2
  36. package/templates/survey/README.md +1 -0
  37. package/templates/survey/template.json +3 -2
  38. package/templates/video/template.json +3 -2
@@ -1,17 +1,24 @@
1
1
  // 패널: 채점 방식 ('채점 설정' 탭). 일반 채점 · AI 채점과 AI 채점 기준(오브젝트 · 채점 기준 · 부분 점수)을 고릅니다.
2
2
  // secret: settings.grading에 저장합니다 (학생에게 안 감). 모양은 core/grading.js, 정답 작품은 answer-project.js 패널.
3
- // 화면 배치: 채점 방식 줄은 탭 위쪽, AI 채점 기준은 정답 작품 워크스페이스 아래 (styles.css의 order).
3
+ // 화면 배치: 정답 작품 워크스페이스 → 채점 방식 줄 → AI 채점 기준 상자 (styles.css의 order). 정답 블록을 만든 뒤 채점 방식을 고르는 흐름.
4
+ // 검사: 저장을 누르면 칸마다 아래에 빨간 글(오브젝트 · 채점 기준 · 점수, 마지막 줄 점수 칸에 총점)을 띄우고 첫 칸으로 옮기며,
5
+ // 저장 바에는 요약 한 줄. 그 뒤로는 고칠 때마다 다시 그림. 총점이 100을 넘으면 저장 전에도 보임.
4
6
  // 오브젝트 목록은 정답 작품에서 받습니다(ctx.objects: 정답 작품 워크스페이스의 TO_GET_OBJECTS, 띄우기 전이면 저장된 정답 → 시작 화면).
5
7
  // 정답 작품은 시작 화면을 복사해 시작하므로 학생 작품과 같은 오브젝트 id를 가집니다. 작품 전체("공통") 기준은 없습니다(서버가 받지 않음):
6
8
  // 새 줄은 오브젝트를 고르지 않은 채로 시작하고, 고르지 않거나 정답 작품에 없는 오브젝트면 저장을 막습니다.
7
9
  import { html } from '../../../core/dom.js';
8
- import { readGrading, RUBRIC_LIMITS, rubricsProblem } from '../../../core/grading.js';
10
+ import { equalScores, readGrading, RUBRIC_LIMITS, rubricTotal, rubricsProblem } from '../../../core/grading.js';
9
11
  import { texts } from '../../../ui/texts.js';
12
+ import { workspaceOrigin } from '../../../core/workspace.js';
10
13
 
11
14
  const t = texts.edit.grading;
15
+ const fe = t.fieldErrors;
12
16
  /** 아직 고르지 않은 오브젝트 칸 */
13
17
  const UNSET = '';
14
18
  const emptyRow = () => ({ object: UNSET, criteria: '', score: null });
19
+ /** 그린 패널과 validate를 잇는 것 (패널은 화면에 하나): 칸 아래 오류를 띄우고 첫 칸으로 옮김. 오류가 있으면 true */
20
+ const view = { reveal: null };
21
+ const reduceMotion = () => globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
15
22
 
16
23
  /** 요소 만들기: class · on* (이벤트) · 그 밖은 속성. false · null 속성과 null 자식은 뺌 */
17
24
  function node(tag, attrs = {}, ...children) {
@@ -81,7 +88,7 @@ const icon = {
81
88
  >
82
89
  <path d="m6 9 6 6 6-6" /></svg
83
90
  ></span>`,
84
- down: () =>
91
+ sparkle: () =>
85
92
  html`<span aria-hidden="true"
86
93
  ><svg
87
94
  width="16"
@@ -90,10 +97,10 @@ const icon = {
90
97
  fill="none"
91
98
  stroke="currentColor"
92
99
  stroke-width="2"
93
- stroke-linecap="round"
94
100
  stroke-linejoin="round"
95
101
  >
96
- <path d="M12 5v14M6 13l6 6 6-6" /></svg
102
+ <path d="M10 3l1.9 5.1L17 10l-5.1 1.9L10 17l-1.9-5.1L3 10l5.1-1.9z" />
103
+ <path d="M18 14l.9 2.1L21 17l-2.1.9L18 20l-.9-2.1L15 17l2.1-.9z" /></svg
97
104
  ></span>`,
98
105
  caret: () =>
99
106
  html`<span class="en-select-caret" aria-hidden="true"
@@ -103,13 +110,19 @@ const icon = {
103
110
  };
104
111
 
105
112
  /**
106
- * 그림 주소를 이 화면에서 띄울 수 있나: data: · blob: · 콘텐츠와 같은 출처만.
107
- * 워크스페이스가 주는 그림은 워크스페이스 출처(예: http://localhost:9000/renderer/…/thumb/…)라 콘텐츠 CSP img-src가 막는다 → 빈 칸
113
+ * 그림 주소를 이 화면에서 띄울 수 있나: data: · blob: · 콘텐츠와 같은 출처 · 워크스페이스 출처.
114
+ * 워크스페이스가 주는 그림은 워크스페이스 출처(예: https://entry-workspace.elice.io/renderer/…/thumb/…)다.
115
+ * 서버 콘텐츠 CSP img-src가 워크스페이스 출처를 허용해야 보이고, 막히면 onerror로 빈 칸이 된다
108
116
  */
109
117
  const showable = src => {
110
118
  try {
111
119
  const url = new URL(src, location.href);
112
- return url.protocol === 'data:' || url.protocol === 'blob:' || url.origin === location.origin;
120
+ return (
121
+ url.protocol === 'data:' ||
122
+ url.protocol === 'blob:' ||
123
+ url.origin === location.origin ||
124
+ url.origin === workspaceOrigin()
125
+ );
113
126
  } catch {
114
127
  return false;
115
128
  }
@@ -139,7 +152,7 @@ export default {
139
152
  const get = () => ctx.value;
140
153
  const update = patch => ctx.set({ ...get(), ...patch });
141
154
 
142
- // 채점 방식 줄: 일반 채점 · AI 채점 + (AI일 때) 아래 기준으로 가는 링크
155
+ // 채점 방식 줄 (정답 작품 아래): 일반 채점 · AI 채점 + 완료 정책 안내
143
156
  const modeCard = (mode, label) =>
144
157
  node(
145
158
  'label',
@@ -158,20 +171,6 @@ export default {
158
171
  }),
159
172
  node('span', { class: 'en-radio-card-title' }, label)
160
173
  );
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
174
  const modeRow = node(
176
175
  'div',
177
176
  { class: 'en-grading-mode' },
@@ -183,7 +182,6 @@ export default {
183
182
  modeCard('general', t.modes.general),
184
183
  modeCard('ai', t.modes.ai)
185
184
  ),
186
- hint,
187
185
  // 완료 정책 안내: 채점 결과로 완료하려면 LXP 설정에서 '답안 확인 후 완료'(on_graded)
188
186
  node('p', { class: 'en-grading-note' }, icon.info(), node('span', {}, t.policyNote))
189
187
  );
@@ -223,16 +221,31 @@ export default {
223
221
  document.addEventListener('keydown', e => e.key === 'Escape' && togglePopover(false));
224
222
 
225
223
  const required = () => node('span', { class: 'en-required', 'aria-hidden': 'true' }, '*');
224
+ // 부분 점수 안내: 마우스를 올리거나 포커스하면 말풍선
225
+ const tooltip = node(
226
+ 'span',
227
+ { class: 'en-tooltip', role: 'tooltip', id: 'en-score-tip', hidden: true },
228
+ t.scoreInfo
229
+ );
230
+ const showTip = on => {
231
+ tooltip.hidden = !on;
232
+ };
226
233
  const scoreInfo = node(
227
234
  'span',
228
235
  {
229
236
  class: 'en-info',
230
237
  role: 'img',
231
238
  'aria-label': t.scoreInfo,
232
- title: t.scoreInfo,
239
+ 'aria-describedby': 'en-score-tip',
233
240
  tabindex: '0',
241
+ onmouseenter: () => showTip(true),
242
+ onmouseleave: () => showTip(false),
243
+ onfocus: () => showTip(true),
244
+ onblur: () => showTip(false),
245
+ onkeydown: e => e.key === 'Escape' && showTip(false),
234
246
  },
235
- icon.info()
247
+ icon.info(),
248
+ tooltip
236
249
  );
237
250
  const list = node('div', { class: 'en-criteria' });
238
251
  const addButton = node(
@@ -241,6 +254,13 @@ export default {
241
254
  icon.plus(),
242
255
  node('span', {}, t.add)
243
256
  );
257
+ // 자동 배점: 기준 수로 100점을 고르게 나눔 (core/grading.js equalScores)
258
+ const autoButton = node(
259
+ 'button',
260
+ { type: 'button', class: 'en-link-button en-auto-button', onclick: () => autoScore() },
261
+ icon.sparkle(),
262
+ node('span', {}, t.autoScore)
263
+ );
244
264
  const ai = node(
245
265
  'div',
246
266
  { class: 'en-ai' },
@@ -260,14 +280,14 @@ export default {
260
280
  { class: 'en-criteria-form' },
261
281
  node(
262
282
  'div',
263
- { class: 'en-criteria-head', 'aria-hidden': 'true' },
283
+ { class: 'en-criteria-head' },
264
284
  node('span', {}, t.columns.object, required()),
265
285
  node('span', {}, t.columns.criterion, required()),
266
286
  node('span', {}, t.columns.score, required(), scoreInfo),
267
287
  node('span', {})
268
288
  ),
269
289
  list,
270
- addButton
290
+ node('div', { class: 'en-criteria-actions' }, addButton, autoButton)
271
291
  )
272
292
  );
273
293
 
@@ -407,25 +427,103 @@ export default {
407
427
  return node('div', { class: 'en-select' }, button, menu);
408
428
  };
409
429
 
410
- const updateRow = (index, patch) =>
430
+ const updateRow = (index, patch) => {
411
431
  update({ rubrics: get().rubrics.map((r, i) => (i === index ? { ...r, ...patch } : r)) });
432
+ paintErrors();
433
+ };
412
434
  const addRow = () => {
413
435
  if (get().rubrics.length >= RUBRIC_LIMITS.max) return;
414
436
  update({ rubrics: [...get().rubrics, emptyRow()] });
415
437
  paintRows();
416
- list.lastElementChild?.querySelector('.en-select-button')?.focus();
438
+ cells.at(-1)?.selectButton.focus();
417
439
  };
418
440
  const removeRow = index => {
419
441
  if (index === 0 || get().rubrics.length <= 1) return;
420
442
  update({ rubrics: get().rubrics.filter((_, i) => i !== index) });
421
443
  paintRows();
422
444
  };
445
+ /** 자동 배점: 기준 수로 100점을 고르게 (합은 늘 100, 나머지는 앞 기준부터) */
446
+ const autoScore = () => {
447
+ const scores = equalScores(get().rubrics.length);
448
+ if (!scores.length) return;
449
+ update({ rubrics: get().rubrics.map((r, i) => ({ ...r, score: scores[i] })) });
450
+ paintRows();
451
+ };
452
+
453
+ // 칸 아래 오류: 저장을 누른 뒤부터(revealed) 칸마다. 총점이 100을 넘는 것은 늘 (마지막 줄 점수 칸 아래)
454
+ let revealed = false;
455
+ /** 줄마다 칸 요소 { selectBox, selectButton, selectMessage, criteria, criteriaMessage, scoreBox, score, scoreMessage } */
456
+ let cells = [];
457
+ const errorLine = () => node('p', { class: 'en-field-error', hidden: true });
458
+ /** 줄마다 칸의 문제 (문구, 없으면 '') */
459
+ const rowProblems = () => {
460
+ const rows = get().rubrics;
461
+ const total = rubricTotal(rows);
462
+ const filled = rows.length > 0 && rows.every(r => r.score !== null);
463
+ return rows.map((r, i) => {
464
+ const last = i === rows.length - 1;
465
+ const scoreOk = Number.isInteger(r.score) && r.score >= RUBRIC_LIMITS.scoreMin && r.score <= RUBRIC_LIMITS.total;
466
+ let totalError = '';
467
+ if (last && total > RUBRIC_LIMITS.total) totalError = fe.over;
468
+ else if (last && revealed && filled && total !== RUBRIC_LIMITS.total) totalError = fe.under;
469
+ const object =
470
+ r.object === UNSET ? fe.object : loaded && !objectOf(r.object) ? fe.unknownObject : '';
471
+ return {
472
+ object: revealed ? object : '',
473
+ criteria: revealed && !r.criteria.trim() ? fe.criterion : '',
474
+ score: revealed && r.score === null ? fe.score : revealed && !scoreOk ? fe.scoreRange(RUBRIC_LIMITS.scoreMin, RUBRIC_LIMITS.total) : '',
475
+ total: totalError,
476
+ };
477
+ });
478
+ };
479
+ const mark = (box, message, text, invalid, input) => {
480
+ box.dataset.invalid = String(invalid);
481
+ message.textContent = text;
482
+ message.hidden = !text;
483
+ input.setAttribute('aria-invalid', String(invalid));
484
+ };
485
+ function paintErrors() {
486
+ const problems = rowProblems();
487
+ cells.forEach((c, i) => {
488
+ const p = problems[i];
489
+ if (!p) return;
490
+ mark(c.selectBox, c.selectMessage, p.object, Boolean(p.object), c.selectButton);
491
+ mark(c.criteria, c.criteriaMessage, p.criteria, Boolean(p.criteria), c.criteria);
492
+ mark(c.scoreBox, c.scoreMessage, p.score || p.total, Boolean(p.score || p.total), c.score);
493
+ });
494
+ }
495
+ /** 저장 직전 (validate): 오류를 띄우고 첫 문제 칸으로 옮김. 문제가 있으면 true */
496
+ view.reveal = () => {
497
+ if (get().mode !== 'ai') return false;
498
+ if (!get().rubrics.length) {
499
+ update({ rubrics: [emptyRow()] });
500
+ paintRows();
501
+ }
502
+ revealed = true;
503
+ paintErrors();
504
+ const problems = rowProblems();
505
+ let target = null;
506
+ problems.forEach((p, i) => {
507
+ if (target) return;
508
+ if (p.object) target = cells[i].selectButton;
509
+ else if (p.criteria) target = cells[i].criteria;
510
+ else if (p.score || p.total) target = cells[i].score;
511
+ });
512
+ if (!target) return false;
513
+ ctx.showTab?.();
514
+ requestAnimationFrame(() => {
515
+ ai.scrollIntoView?.({ behavior: reduceMotion() ? 'auto' : 'smooth', block: 'start' });
516
+ target.focus({ preventScroll: true });
517
+ });
518
+ return true;
519
+ };
423
520
 
424
521
  /** 오브젝트 칸마다 다시 그리기 (오브젝트 이름 · 그림을 받은 뒤) */
425
522
  let repaints = [];
426
523
  function paintRows() {
427
524
  const rows = get().rubrics;
428
525
  repaints = [];
526
+ cells = [];
429
527
  list.replaceChildren(
430
528
  ...rows.map((row, index) => {
431
529
  const criteria = node('input', {
@@ -452,6 +550,24 @@ export default {
452
550
  updateRow(index, { score: Number.isInteger(n) ? n : null });
453
551
  },
454
552
  });
553
+ const scoreBox = node(
554
+ 'label',
555
+ { class: 'en-field en-score-field' },
556
+ score,
557
+ node('span', { class: 'en-unit' }, t.unit)
558
+ );
559
+ const selectBox = objectSelect(index);
560
+ const cell = {
561
+ selectBox,
562
+ selectButton: selectBox.querySelector('button'),
563
+ selectMessage: errorLine(),
564
+ criteria,
565
+ criteriaMessage: errorLine(),
566
+ scoreBox,
567
+ score,
568
+ scoreMessage: errorLine(),
569
+ };
570
+ cells.push(cell);
455
571
  // 첫 줄은 지우지 않음 (기준은 하나 이상): 자리만 둠
456
572
  const remove =
457
573
  index === 0
@@ -473,44 +589,46 @@ export default {
473
589
  return node(
474
590
  'div',
475
591
  { 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
- ),
592
+ node('div', { class: 'en-cell' }, selectBox, cell.selectMessage),
593
+ node('div', { class: 'en-cell' }, criteria, cell.criteriaMessage),
594
+ node('div', { class: 'en-cell' }, scoreBox, cell.scoreMessage),
484
595
  remove
485
596
  );
486
597
  })
487
598
  );
488
599
  addButton.disabled = rows.length >= RUBRIC_LIMITS.max;
600
+ autoButton.disabled = rows.length < 1;
601
+ paintErrors();
489
602
  }
490
603
 
491
- /** 방식에 맞게 보이기. AI로 바꿨는데 기준이 없으면 빈 줄 하나 */
604
+ /** 방식에 맞게 보이기. AI로 바꿨는데 기준이 없으면 빈 줄 하나, 바꾼 뒤에는 기준 상자가 보이게 스크롤 */
492
605
  function showMode(changed = false) {
493
606
  const isAi = get().mode === 'ai';
494
- hint.style.visibility = isAi ? 'visible' : 'hidden';
495
607
  ai.hidden = !isAi;
496
608
  if (changed && isAi && !get().rubrics.length) update({ rubrics: [emptyRow()] });
497
609
  if (isAi) paintRows();
610
+ if (changed && isAi)
611
+ requestAnimationFrame(() =>
612
+ ai.scrollIntoView?.({ behavior: reduceMotion() ? 'auto' : 'smooth', block: 'nearest' })
613
+ );
498
614
  }
499
615
 
500
616
  el.append(modeRow, ai);
501
617
  showMode();
502
- // 오브젝트 이름 · 그림을 받으면 다시 그림 (저장된 기준의 오브젝트 이름)
503
- void loadObjects().then(() => repaints.forEach(repaint => repaint()));
618
+ // 오브젝트 이름 · 그림을 받으면 다시 그림 (저장된 기준의 오브젝트 이름 · 없는 오브젝트 표시)
619
+ void loadObjects().then(() => {
620
+ repaints.forEach(repaint => repaint());
621
+ paintErrors();
622
+ });
504
623
  },
624
+ /** AI 채점 기준 검사. 칸 문제는 칸 아래에 띄우고 저장 바에는 요약 한 줄 */
505
625
  validate(value) {
506
626
  if (value.mode !== 'ai') return true;
627
+ const shown = view.reveal?.() ?? false;
507
628
  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);
629
+ if (!problem) return shown ? t.errors.summary : true;
512
630
  if (problem.code === 'tooLong') return t.errors.tooLong(RUBRIC_LIMITS.criteriaMax);
513
631
  if (problem.code === 'tooMany') return t.errors.tooMany(RUBRIC_LIMITS.max);
514
- return t.errors[problem.code];
632
+ return t.errors.summary;
515
633
  },
516
634
  };
@@ -29,7 +29,25 @@ export default {
29
29
  if (input.checked) ctx.set({ workspaceMode: input.value });
30
30
  });
31
31
  }
32
- const info = html`<p class="ec-muted">${t.info}</p>`;
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>`;
33
51
  el.append(group, info);
34
52
  },
35
53
  toPreference(value) {
@@ -1,11 +1,13 @@
1
- // 작품 패널 만들기: 워크스페이스(?mode=skeleton) 하나 + 크기 줄 + 안내 목록. 시작 화면 · 정답 작품 패널이 씁니다.
1
+ // 작품 패널 만들기: 워크스페이스(?mode=skeleton) 하나 + 아래 줄(왼쪽 안내 목록 · 오른쪽 용량 칩). 시작 화면 · 정답 작품 패널이 씁니다.
2
2
  // 저장 직전 워크스페이스에서 작품을 꺼내 core/pack.js 모양({ enc: 'gzip+base64', data })으로 줄입니다.
3
- // 크기: 블록이 바뀌면 2초 뒤 작품을 꺼내 재고, 저장할 때 다시 잽니다. settings 전체가 서버 한도(64KB)를 넘으면 저장을 막습니다.
3
+ // 용량: 블록이 바뀌면 2초 뒤 작품을 꺼내 settings 전체 크기를 다시 재고(칩은 screens/edit.js가 두 탭 모두 같이 바꿈),
4
+ // 저장할 때 다시 잽니다. settings 전체가 서버 한도(64KB)를 넘으면 칩 위에 빨간 글을 띄우고 저장을 막습니다.
4
5
  import { infoList } from '../../../lib/elice-content.js';
5
6
  import { html } from '../../../core/dom.js';
6
7
  import { packedProject } from '../../../core/grading.js';
7
- import { formatBytes, jsonBytes, pack } from '../../../core/pack.js';
8
+ import { formatBytes, pack } from '../../../core/pack.js';
8
9
  import { LIMITS } from '../../../core/settings.js';
10
+ import { texts } from '../../../ui/texts.js';
9
11
 
10
12
  const MEASURE_DELAY_MS = 2000;
11
13
 
@@ -13,7 +15,7 @@ const MEASURE_DELAY_MS = 2000;
13
15
  * @param {{
14
16
  * id: string,
15
17
  * tab: string,
16
- * t: { title: string, info: string[], size: Function, sizeUnknown: string, tooLarge: Function, noProject: string, heldFromMenu: string },
18
+ * t: { title: string, info: string[], noProject: string },
17
19
  * lazy?: boolean, // 탭을 처음 열 때 워크스페이스를 띄움 (그 전에는 저장된 값을 그대로 저장)
18
20
  * secret?: boolean, // settings.entry가 아니라 settings.grading에 저장 (학생에게 안 감). normalize는 app.grading을 받음
19
21
  * fromGrading?: (grading: unknown) => unknown,
@@ -27,22 +29,10 @@ export function projectPanel({ id, tab, t, lazy = false, secret = false, fromGra
27
29
  secret,
28
30
  normalize: raw => packedProject(secret ? fromGrading(raw) : raw),
29
31
  render(el, ctx) {
30
- const size = html`<p class="en-size" data-ec-quiet role="status">${t.sizeUnknown}</p>`;
31
32
  const info = infoList(t.info);
32
33
  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);
34
+ const footer = html`<div class="en-panel-footer">${info}${ctx.sizeBox()}</div>`;
35
+ el.append(footer);
46
36
 
47
37
  let timer = null;
48
38
  const open = () => {
@@ -52,28 +42,31 @@ export function projectPanel({ id, tab, t, lazy = false, secret = false, fromGra
52
42
  el.prepend(ws.element);
53
43
  const measure = () => {
54
44
  clearTimeout(timer);
55
- timer = setTimeout(async () => {
56
- try {
57
- paint(await pack(await ws.getProject()));
58
- } catch {
59
- // 꺼내지 못하면(파이썬 문법 오류 등) 크기 줄은 그대로, 저장할 때 다시 시도
60
- }
61
- }, MEASURE_DELAY_MS);
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
+ );
62
55
  };
63
56
  // 워크스페이스 안에서 바뀐 것은 이 화면의 입력 이벤트가 아니므로 직접 '저장하지 않은 변경'으로 표시한다
64
57
  ws.onChange(() => {
65
58
  ctx.markDirty();
66
59
  measure();
67
60
  });
61
+ // 워크스페이스 '저장하기'로 받은 작품도 저장 바의 '저장하지 않은 변경'으로 (아래 저장을 눌러야 저장됨)
68
62
  ctx.onHeld(() => {
69
63
  ctx.markDirty();
70
- size.textContent = t.heldFromMenu;
71
64
  measure();
72
65
  });
73
66
  };
74
67
  if (lazy) ctx.onShow(() => ctx.opened || open());
75
68
  else open();
76
- ctx.onCollected(paint);
69
+ ctx.onCollected(packed => ctx.measured(packed));
77
70
  },
78
71
  /** 저장 직전: 워크스페이스에서 지금 작품을 꺼내 줄인다 (워크스페이스 '저장하기'로 받은 작품이 있으면 그것). 열지 않았으면 저장된 값 */
79
72
  async collect(ctx) {
@@ -90,7 +83,10 @@ export function projectPanel({ id, tab, t, lazy = false, secret = false, fromGra
90
83
  },
91
84
  validate(value, { settingsBytes }) {
92
85
  if (settingsBytes > LIMITS.settingsBytes)
93
- return t.tooLarge(formatBytes(settingsBytes), formatBytes(LIMITS.settingsBytes));
86
+ return texts.edit.size.tooLarge(
87
+ formatBytes(settingsBytes),
88
+ formatBytes(LIMITS.settingsBytes)
89
+ );
94
90
  return true;
95
91
  },
96
92
  };
@@ -11,10 +11,10 @@
11
11
  import { start } from '../lib/elice-content.js';
12
12
  import { part } from '../core/dom.js';
13
13
  import { buildGrading, hasGradable, hasUnknownObject, projectObjects } from '../core/grading.js';
14
- import { jsonBytes, unpack } from '../core/pack.js';
15
- import { joinSettings, splitSettings } from '../core/settings.js';
14
+ import { formatBytes, jsonBytes, unpack } from '../core/pack.js';
15
+ import { joinSettings, LIMITS, splitSettings } from '../core/settings.js';
16
16
  import { connectWorkspace } from '../core/workspace.js';
17
- import { loading, panelSection, tabCard, unavailable } from '../ui/templates/page.js';
17
+ import { loading, panelSection, sizeBox, tabCard, unavailable } from '../ui/templates/page.js';
18
18
  import { texts } from '../ui/texts.js';
19
19
  import panels from './edit/panels/index.js';
20
20
 
@@ -72,6 +72,7 @@ const providers = {
72
72
 
73
73
  function workspace(name) {
74
74
  if (workspaces[name]) return workspaces[name];
75
+ // mlData(AI 학습 저장)를 넘기지 않는다: 편집 화면에는 학생 파일 폴더가 없음 (core/workspace.js 주석)
75
76
  const ws = connectWorkspace({
76
77
  mode: 'skeleton',
77
78
  title: texts.page.workspace,
@@ -107,6 +108,22 @@ async function reloadWorkspaces() {
107
108
  }
108
109
  }
109
110
 
111
+ // 용량 칩 (작품 패널 아래 오른쪽, 탭마다 하나): settings 전체 크기 / 서버 한도. 넘으면 칩 위에 빨간 글
112
+ const sizeBoxes = [];
113
+ let lastTotal = null;
114
+ function showTotal(total) {
115
+ lastTotal = total;
116
+ const over = total > LIMITS.settingsBytes;
117
+ for (const { chip, message } of sizeBoxes) {
118
+ chip.textContent = texts.edit.size.chip(formatBytes(total), formatBytes(LIMITS.settingsBytes));
119
+ chip.dataset.over = String(over);
120
+ message.textContent = over
121
+ ? texts.edit.size.tooLarge(formatBytes(total), formatBytes(LIMITS.settingsBytes))
122
+ : '';
123
+ message.hidden = !over;
124
+ }
125
+ }
126
+
110
127
  /** 탭을 보일 때 부를 것 (패널마다) */
111
128
  const showListeners = new Map(panels.map(p => [p, new Set()]));
112
129
 
@@ -126,6 +143,7 @@ const contexts = new Map(
126
143
  save.markDirty();
127
144
  if (panel.toPreference) void reloadWorkspaces();
128
145
  if (panel.id === 'grading') paintStartWarning();
146
+ showTotal(totalBytes({}));
129
147
  },
130
148
  markDirty: () => save.markDirty(),
131
149
  /** 이 패널 탭의 워크스페이스 (처음 부르면 띄움) */
@@ -148,6 +166,17 @@ const contexts = new Map(
148
166
  onShow: cb => showListeners.get(panel).add(cb),
149
167
  /** 이 패널 값이 v일 때 settings 전체 크기 (바이트, grading 포함) */
150
168
  settingsBytes: v => totalBytes({ [panel.id]: v }),
169
+ /** 용량 칩 하나 (작품 패널 아래). 칩은 모든 탭이 같은 값 */
170
+ sizeBox() {
171
+ const box = sizeBox();
172
+ sizeBoxes.push({ chip: part(box, 'size-chip'), message: part(box, 'size-message') });
173
+ showTotal(lastTotal ?? totalBytes({}));
174
+ return box;
175
+ },
176
+ /** 워크스페이스에서 잰 이 패널의 작품(줄인 것)으로 용량 칩을 다시 그림 */
177
+ measured: v => showTotal(totalBytes({ [panel.id]: v })),
178
+ /** 이 패널의 탭을 보임 (저장 전 검사가 문제 칸으로 옮길 때) */
179
+ showTab: () => selectTab?.(panel.tab),
151
180
  /** 워크스페이스 '저장하기'로 작품을 받았을 때 */
152
181
  onHeld: cb => heldListeners[wsName].add(cb),
153
182
  /** 받은 작품을 가져가고 비운다 (없으면 null) */
@@ -172,6 +201,7 @@ const sections = panels.map(panel => {
172
201
  root.replaceChildren(...sections);
173
202
 
174
203
  // 탭 카드: 탭이 있는 패널을 모아 첫 탭 패널 자리에 둔다
204
+ let selectTab = null;
175
205
  const tabbed = panels.map((panel, i) => ({ panel, section: sections[i] })).filter(x => x.panel.tab);
176
206
  const tabNames = [...new Set(tabbed.map(x => x.panel.tab))];
177
207
  if (tabbed.length) {
@@ -203,6 +233,7 @@ if (tabbed.length) {
203
233
  select(tabs[(i + step + tabs.length) % tabs.length].dataset.tab, true);
204
234
  });
205
235
  }
236
+ selectTab = select;
206
237
  select(tabNames[0]);
207
238
  }
208
239