@eliceio/cdk-cli 0.1.0-alpha.2 → 0.1.0-alpha.3
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.
- package/README.md +158 -138
- package/es/cli.js +88 -33
- package/es/commands/build/index.d.ts +1 -1
- package/es/commands/build/index.js +16 -6
- package/es/commands/check/index.d.ts +8 -2
- package/es/commands/check/index.js +45 -5
- package/es/commands/create/index.d.ts +2 -0
- package/es/commands/create/index.js +28 -3
- package/es/commands/create/scaffold.d.ts +2 -0
- package/es/commands/create/scaffold.js +10 -6
- package/es/commands/dev/index.d.ts +1 -1
- package/es/commands/dev/index.js +6 -2
- package/es/commands/doctor/index.d.ts +11 -0
- package/es/commands/doctor/index.js +155 -26
- package/es/commands/mcp/index.d.ts +134 -0
- package/es/commands/mcp/index.js +399 -0
- package/es/commands/setup/index.d.ts +40 -0
- package/es/commands/setup/index.js +157 -0
- package/es/commands/skill/index.d.ts +2 -5
- package/es/commands/skill/index.js +1 -29
- package/es/core/config.d.ts +63 -19
- package/es/core/config.js +108 -32
- package/es/core/prepare.js +3 -5
- package/es/core/project-check.d.ts +15 -0
- package/es/core/project-check.js +26 -0
- package/es/core/templates.d.ts +25 -0
- package/es/core/templates.js +41 -0
- package/es/dev/grading.d.ts +14 -7
- package/es/dev/grading.js +27 -13
- package/es/dev/host-page.d.ts +1 -1
- package/es/dev/host-page.js +33 -33
- package/es/dev/mock-api.d.ts +20 -4
- package/es/dev/mock-api.js +70 -9
- package/es/dev/server.d.ts +7 -0
- package/es/dev/server.js +84 -23
- package/es/rules/check.js +56 -7
- package/es/rules/index.d.ts +1 -1
- package/es/rules/index.js +1 -1
- package/es/rules/manifest.d.ts +23 -9
- package/es/rules/manifest.js +60 -35
- package/es/rules/node.js +3 -1
- package/es/rules/semver.d.ts +5 -0
- package/es/rules/semver.js +32 -0
- package/es/rules/types.d.ts +27 -6
- package/es/rules.json.js +1 -1
- package/guides/content-development.md +136 -49
- package/package.json +2 -2
- package/rules.json +62 -7
- package/skills/_shared/always.md +3 -1
- package/skills/elice-content-check/SKILL.md +1 -1
- package/skills/elice-content-create/SKILL.md +4 -4
- package/skills/elice-content-migrate/SKILL.md +1 -1
- package/skills/elice-content-publish/SKILL.md +22 -0
- package/templates/_shared/lib/cdk-mock.d.ts +21 -3
- package/templates/_shared/lib/cdk-mock.js +239 -80
- package/templates/_shared/lib/cdk.js +2 -2
- package/templates/_shared/lib/elice-content.css +196 -0
- package/templates/_shared/lib/elice-content.d.ts +110 -5
- package/templates/_shared/lib/elice-content.js +643 -38
- package/templates/blank/README.md +12 -3
- package/templates/blank/completion.html +15 -0
- package/templates/blank/elice.config.json +3 -5
- package/templates/blank/gitignore +1 -0
- package/templates/blank/screens/completion.js +7 -0
- package/templates/blank/screens/edit.js +3 -0
- package/templates/blank/template.json +6 -0
- package/templates/quiz/README.md +35 -28
- package/templates/quiz/content.json +17 -63
- package/templates/quiz/core/behaviors.d.ts +5 -0
- package/templates/quiz/core/behaviors.js +12 -0
- package/templates/quiz/core/model.d.ts +27 -1
- package/templates/quiz/core/model.js +199 -4
- package/templates/quiz/elice.config.json +1 -6
- package/templates/quiz/gitignore +1 -0
- package/templates/quiz/grading.json +1 -10
- package/templates/quiz/screens/edit.js +105 -31
- package/templates/quiz/screens/learn.js +7 -8
- package/templates/quiz/template.json +6 -0
- package/templates/quiz/ui/templates/edit.d.ts +2 -0
- package/templates/quiz/ui/templates/edit.js +16 -9
- package/templates/quiz/ui/texts.js +52 -27
|
@@ -9,9 +9,10 @@ Elice Custom HTML 학습자료 프로젝트입니다.
|
|
|
9
9
|
| `screens/learn.js` · `index.html` | 학생 화면 |
|
|
10
10
|
| `screens/instructor.js` · `instructor.html` | 교육자 화면 |
|
|
11
11
|
| `screens/edit.js` · `edit.html` | 내용 편집 화면 (CMS) |
|
|
12
|
+
| `screens/completion.js` · `completion.html` | 완료 정책 화면 (교육자가 고름, 고칠 일 거의 없음) |
|
|
12
13
|
| `content.json` | 처음 내용. 편집 화면에서 저장하면 저장한 내용을 씁니다 |
|
|
13
14
|
| `styles.css` | 이 콘텐츠의 스타일 |
|
|
14
|
-
| `elice.config.json` | 화면 구성(`screens`)
|
|
15
|
+
| `elice.config.json` | 화면 구성(`screens`) · 지원하는 완료 정책(`completionPolicies`) |
|
|
15
16
|
|
|
16
17
|
`lib/`는 플랫폼 연결 로직이라 고치지 않습니다. 화면은 **누가 보는지(학생 · 교육자 · 튜터)나 미리보기인지 몰라도 됩니다.**
|
|
17
18
|
|
|
@@ -21,6 +22,10 @@ const app = await start({ screen: 'learn' });
|
|
|
21
22
|
render(app.content);
|
|
22
23
|
app.useSubmit({ getAnswer, setAnswer, validate });
|
|
23
24
|
|
|
25
|
+
// 여러 단계(슬라이드 · STEP)인 자료: 양옆 화살표와 n / N을 키트가 그린다.
|
|
26
|
+
// 첫 · 마지막 단계에서는 LXP 이전 · 다음 수업 자료로 가는 버튼(이전 자료 · 다음 자료). 아래 이전 · 다음 막대는 만들지 않는다
|
|
27
|
+
app.usePaging({ count: steps.length, onChange: i => showStep(i) });
|
|
28
|
+
|
|
24
29
|
// 편집 화면(CMS): 고칠 칸을 그리고 저장할 내용만 알려 준다
|
|
25
30
|
const app = await start({ screen: 'edit' });
|
|
26
31
|
renderForm(app.content);
|
|
@@ -44,7 +49,7 @@ app.useSave({ getContent, validate });
|
|
|
44
49
|
| 언제 | SDK | 채점 · 저장 |
|
|
45
50
|
| --------------------------------------------- | -------------------------------- | ----------------------------------------------------------------------------- |
|
|
46
51
|
| 플랫폼에서 열 때 (`#token=`, 편집기 draft) | real (`lib/cdk.js`) | 서버 |
|
|
47
|
-
| 그 밖 (로컬) | mock (`lib/cdk-mock.js`) | `grading.json`(
|
|
52
|
+
| 그 밖 (로컬) | mock (`lib/cdk-mock.js`) | `grading.json`(완료 정책 · 정답)으로 로컬 채점, 저장 내용·제출은 이 브라우저에 |
|
|
48
53
|
|
|
49
54
|
- 강제로 바꾸기: 주소에 `?sdk=mock` 또는 `?sdk=real`
|
|
50
55
|
- 보는 사람 바꾸기 (mock): `#viewer=tutor` (`student` · `instructor` · `tutor`), 편집기 draft 흉내: `#preview=1` · `#edit=1`
|
|
@@ -53,7 +58,11 @@ app.useSave({ getContent, validate });
|
|
|
53
58
|
|
|
54
59
|
## 정답
|
|
55
60
|
|
|
56
|
-
정답은 zip에 넣지
|
|
61
|
+
정답은 zip에 넣지 않습니다 (ADR 0009, `ecdk guide 2` · `5`).
|
|
62
|
+
|
|
63
|
+
- **채점 방식 · 답**: 답을 채점하는 자료면 편집 화면에 키트의 채점 블록을 붙입니다: `const grading = app.useGradingBlock();` 후 `app.useSave({ …, getGrading: () => grading.getGrading() })`. LXP와 같은 문구로 기준 답안(정규표현식) · 평가 기준을 받아 `settings.grading`에 저장합니다 (학생에게는 내려가지 않음).
|
|
64
|
+
- **완료 정책**: `elice.config.json`의 `completionPolicies` (필수). 이 자료가 지원하는 정책이고, LXP에 올리면 서버가 **첫 값**으로 완료 정책을 정합니다. 기본은 `["on_submit", "on_access"]`(제출하면 완료, 교육자가 열면 완료로 바꿀 수 있음)이고, 교육자는 완료 정책 화면(`completion.html`, `screens.completionPolicy`)에서 이 안에서만 고릅니다. 하나로 고정하려면 `["on_submit"]`처럼 하나만 적고 완료 정책 화면(`completion.html` · `screens/completion.js` · `screens.completionPolicy`)을 지웁니다.
|
|
65
|
+
- 채점해 통과하면 완료(`on_graded`)를 넣으려면 편집 화면에 채점 블록이 있어야 합니다 (위). 로컬 채점 흉내는 `grading.json` (`{ "type": "pattern", "answer_key": "^…$" }` · `{ "type": "rubric", "rubric": "…" }`), 로컬 완료 정책은 `.ecdk/completion.json`. `ecdk dev`의 내용 편집 · 완료 정책 보기에서 저장하면 이 파일들에 씁니다. 둘 다 `ecdk build`가 zip에서 뺍니다.
|
|
57
66
|
|
|
58
67
|
## 명령
|
|
59
68
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="ko">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>완료 정책</title>
|
|
7
|
+
<link rel="stylesheet" href="lib/elice-tokens.css" />
|
|
8
|
+
<link rel="stylesheet" href="lib/elice-content.css" />
|
|
9
|
+
<link rel="stylesheet" href="styles.css" />
|
|
10
|
+
<script type="module" src="screens/completion.js"></script>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<main id="app"><p class="ec-muted">불러오는 중…</p></main>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
"screens": {
|
|
4
4
|
"learn": "index.html",
|
|
5
5
|
"instructor": "instructor.html",
|
|
6
|
-
"edit": "edit.html"
|
|
6
|
+
"edit": "edit.html",
|
|
7
|
+
"completionPolicy": "completion.html"
|
|
7
8
|
},
|
|
8
|
-
"
|
|
9
|
-
"on_submit",
|
|
10
|
-
"on_access"
|
|
11
|
-
]
|
|
9
|
+
"completionPolicies": ["on_submit", "on_access"]
|
|
12
10
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// 완료 정책 화면 (LXP 편집 페이지 설정 탭, screens.completionPolicy). 라디오 · 저장 · 변경 표시는 키트(useCompletion)가 합니다.
|
|
2
|
+
// elice.config.json completionPolicies에 적은 정책만 보이고, 저장하면 SDK saveCompletionPolicy로 자료의 완료 정책이 바뀝니다.
|
|
3
|
+
// 정책을 하나만 두면(고정) 이 화면은 지우고 elice.config.json screens에서도 뺍니다.
|
|
4
|
+
import { start } from '../lib/elice-content.js';
|
|
5
|
+
|
|
6
|
+
const app = await start({ screen: 'completionPolicy' });
|
|
7
|
+
app.useCompletion();
|
|
@@ -15,6 +15,9 @@ const message = Object.assign(document.createElement('textarea'), {
|
|
|
15
15
|
});
|
|
16
16
|
root.replaceChildren(title, message);
|
|
17
17
|
|
|
18
|
+
// 답을 채점하는 자료면 채점 방식 · 답 블록을 붙이고 getGrading을 넘깁니다 (ADR 0009, ecdk guide 5):
|
|
19
|
+
// const grading = app.useGradingBlock();
|
|
20
|
+
// app.useSave({ getContent, validate, getGrading: () => grading.getGrading() });
|
|
18
21
|
app.useSave({
|
|
19
22
|
getContent: () => ({ ...app.content, title: title.value, message: message.value }),
|
|
20
23
|
validate: (c) => c.title.trim() !== '' || '제목을 입력해 주세요.',
|
package/templates/quiz/README.md
CHANGED
|
@@ -10,10 +10,10 @@ Elice Custom HTML 학습자료 프로젝트입니다.
|
|
|
10
10
|
| `screens/instructor.js` · `instructor.html` | 교육자 화면 |
|
|
11
11
|
| `screens/edit.js` · `edit.html` | 내용 편집 화면 (CMS) |
|
|
12
12
|
| `ui/` | 퀴즈의 모양: 색 · 간격 · 문구 · 마크업 (아래 표) |
|
|
13
|
-
| `content.json` | 처음
|
|
13
|
+
| `content.json` | 처음 내용 (단일 선택 한 문제). 편집 화면에서 저장하면 저장한 내용을 씁니다. 다섯 유형 모두 편집 화면 "문항 추가"로 더함 |
|
|
14
14
|
| `styles.css` | 이 콘텐츠의 스타일 (값은 `ui/theme.css`의 변수) |
|
|
15
|
-
| `elice.config.json` | 화면 구성(`screens`)
|
|
16
|
-
| `grading.json` | 로컬 채점용
|
|
15
|
+
| `elice.config.json` | 화면 구성(`screens`) · 완료 정책(`completionPolicies`) |
|
|
16
|
+
| `grading.json` | 로컬 채점용 정답 정규식 (zip에 들어가지 않음) |
|
|
17
17
|
|
|
18
18
|
## 퀴즈 모양 바꾸기
|
|
19
19
|
|
|
@@ -26,27 +26,27 @@ screens/ 배치 — 어떤 블록을 어떤 순서로 보일지
|
|
|
26
26
|
core/ 동작 — 고치지 않습니다 (답 문자열 · 채점 약속, 고르기 · 끌어 놓기 · 순서 바꾸기). ui/를 부르지 않고, 템플릿 · 문구는 screens/가 넘깁니다
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
| 바꾸고 싶은 것
|
|
30
|
-
|
|
|
31
|
-
| 색 · 간격 · 모서리
|
|
32
|
-
| 문구 ("확인 문제", "정답", 탭 제목 등)
|
|
33
|
-
| 보기 카드 마크업
|
|
34
|
-
| 문항 겉모양 · 결과 · 해설 자리
|
|
35
|
-
| 순서 맞추기 · 그룹 분류 배치
|
|
36
|
-
| 화면 머리 (배지 · 제목 · 요약) · 불러오는 중 | `ui/templates/page.js`
|
|
37
|
-
| 편집 화면 칸 · 버튼
|
|
38
|
-
| 블록 순서 · 편집 화면에서 보일 칸
|
|
29
|
+
| 바꾸고 싶은 것 | 고치는 곳 |
|
|
30
|
+
| -------------------------------------------- | ------------------------------------------------------------------------- |
|
|
31
|
+
| 색 · 간격 · 모서리 | `ui/theme.css`의 `--qz-*` 변수 (예: `--qz-accent`, `--qz-option-padding`) |
|
|
32
|
+
| 문구 ("확인 문제", "정답", 탭 제목 등) | `ui/texts.js` (HTML의 제목 · "불러오는 중"은 스크립트가 돌기 전 대비용) |
|
|
33
|
+
| 보기 카드 마크업 | `ui/templates/choice.js` (모양은 `styles.css`의 `.qz-option`) |
|
|
34
|
+
| 문항 겉모양 · 결과 · 해설 자리 | `ui/templates/question.js` |
|
|
35
|
+
| 순서 맞추기 · 그룹 분류 배치 | `ui/templates/order.js` · `ui/templates/group.js` |
|
|
36
|
+
| 화면 머리 (배지 · 제목 · 요약) · 불러오는 중 | `ui/templates/page.js` |
|
|
37
|
+
| 편집 화면 칸 · 버튼 | `ui/templates/edit.js` |
|
|
38
|
+
| 블록 순서 · 편집 화면에서 보일 칸 | `screens/*.js` |
|
|
39
39
|
|
|
40
40
|
템플릿은 `` html`…` `` 조각입니다. 끼워 넣는 글자는 자동으로 이스케이프되고, 클래스 · 태그 · 배치는 자유롭게 바꿔도 됩니다. **`data-role` 속성만 남기면** 동작(`core/`)이 그대로 붙습니다.
|
|
41
41
|
|
|
42
|
-
| `data-role`
|
|
43
|
-
|
|
|
44
|
-
| `result` · `explanation`
|
|
45
|
-
| `choice` (`<input value="보기 id">`)
|
|
46
|
-
| `input`
|
|
47
|
-
| `pool` · `slots`
|
|
48
|
-
| `pool` · `items`, 있으면 `pool-area` · `reset` · `remove`
|
|
49
|
-
| `preview-toggle` · `preview` · `count` · `handle` · `delete` · `type` · `up` · `down` | 편집 화면 (`edit.js`)
|
|
42
|
+
| `data-role` | 어디 |
|
|
43
|
+
| ------------------------------------------------------------------------------------- | ----------------------------------- |
|
|
44
|
+
| `result` · `explanation` | 문항 (`question.js`) |
|
|
45
|
+
| `choice` (`<input value="보기 id">`) | 객관식 보기 (`choice.js`) |
|
|
46
|
+
| `input` | 주관식 입력란 (`text.js`) · 편집 칸 |
|
|
47
|
+
| `pool` · `slots` | 순서 맞추기 (`order.js`) |
|
|
48
|
+
| `pool` · `items`, 있으면 `pool-area` · `reset` · `remove` | 그룹 분류 (`group.js`) |
|
|
49
|
+
| `preview-toggle` · `preview` · `count` · `handle` · `delete` · `type` · `up` · `down` | 편집 화면 (`edit.js`) |
|
|
50
50
|
|
|
51
51
|
보기 · 칸 · 그룹 · 문항 요소의 `data-role` · `data-option` · `data-slot` · `data-group` · `data-id`, 상태 표시 `data-result`(`correct` · `wrong`) · `data-dragging` · `data-ghost`는 동작이 붙입니다. CSS에서 이 속성으로 상태를 꾸밀 수 있습니다.
|
|
52
52
|
|
|
@@ -78,10 +78,10 @@ app.useSave({ getContent, validate });
|
|
|
78
78
|
|
|
79
79
|
키트가 자동으로 고릅니다. 화면 코드는 바꿀 필요가 없습니다.
|
|
80
80
|
|
|
81
|
-
| 언제
|
|
82
|
-
|
|
|
83
|
-
| 플랫폼에서 열 때 (`#token=`, 편집기 draft)
|
|
84
|
-
| 그 밖 (로컬)
|
|
81
|
+
| 언제 | SDK | 채점 · 저장 |
|
|
82
|
+
| ------------------------------------------ | ------------------------ | ------------------------------------------------------------------------------ |
|
|
83
|
+
| 플랫폼에서 열 때 (`#token=`, 편집기 draft) | real (`lib/cdk.js`) | 서버 |
|
|
84
|
+
| 그 밖 (로컬) | mock (`lib/cdk-mock.js`) | `grading.json`(완료 정책 · 정답)으로 로컬 채점, 저장 내용·제출은 이 브라우저에 |
|
|
85
85
|
|
|
86
86
|
- 강제로 바꾸기: 주소에 `?sdk=mock` 또는 `?sdk=real`
|
|
87
87
|
- 보는 사람 바꾸기 (mock): `#viewer=tutor` (`student` · `instructor` · `tutor`), 편집기 draft 흉내: `#preview=1` · `#edit=1`
|
|
@@ -92,12 +92,19 @@ app.useSave({ getContent, validate });
|
|
|
92
92
|
|
|
93
93
|
- `content.json`: 처음 문항. 편집 화면에서 저장하면 저장값을 씁니다. 형식은 ecdk 문서 ADR 0006.
|
|
94
94
|
- 문항 유형: 단일 선택 · 복수 선택 · 순서 맞추기 · 주관식 · 그룹 분류
|
|
95
|
-
- 학생 답은
|
|
96
|
-
-
|
|
95
|
+
- 학생 답은 문자열 하나로 제출합니다: 문항 순서대로 `문항id=답`을 `;`로 잇고 주관식은 URL 인코딩 (`q1=b;q2=a,d;q4=%EA%B0%80…`).
|
|
96
|
+
- 퀴즈는 완료 정책 **채점해 통과하면 완료(on_graded)** · 채점 방식 **기준 답안(pattern)** 고정입니다 (`elice.config.json` `"completionPolicies": ["on_graded"]`, ADR 0009). 하나뿐이라 완료 정책 화면이 없고, 모든 문항을 맞혀야 100점입니다 (문항별 점수 없음). 편집 화면은 답(`settings.grading`)만 저장하고 완료 정책은 보내지 않습니다.
|
|
97
97
|
|
|
98
98
|
## 정답
|
|
99
99
|
|
|
100
|
-
정답은 zip에 넣지 않습니다.
|
|
100
|
+
정답은 zip에 넣지 않습니다. **내용 편집 화면**(`edit.html`)에서 문항을 만들면서 같은 카드의 **정답**에서 답을 고릅니다 (주관식은 허용 답을 줄마다 하나). 저장할 때 고른 답으로 정답 정규식 하나를 만들어 `settings.grading`에 넣고 (학생에게는 내려가지 않음), 저장 전에 검증합니다 (ADR 0009):
|
|
101
|
+
|
|
102
|
+
1. 모든 문항에 정답이 있고, 지운 보기를 가리키지 않는다
|
|
103
|
+
2. 정규식이 컴파일되고 `^…$`로 감싸져 있으며 너무 길거나 느리지 않다
|
|
104
|
+
3. 정답을 학생 화면과 같은 방식으로 이은 답이 맞는다 (주관식 허용 답은 하나씩 모두)
|
|
105
|
+
4. 문항 하나를 다른 답으로 바꾸면 맞지 않는다 (너무 넓은 정답 방지)
|
|
106
|
+
|
|
107
|
+
로컬에서는 `ecdk dev`의 **내용 편집**에서 저장하면 `grading.json`에 쓰고, 학생 보기가 그 정답으로 채점합니다. `elice.config.json` · `grading.json`은 `ecdk build`가 zip에서 뺍니다.
|
|
101
108
|
|
|
102
109
|
## 명령
|
|
103
110
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "퍼셉트론 확인 문제",
|
|
3
|
-
"description": "
|
|
3
|
+
"description": "문제를 풀고 제출해요.",
|
|
4
4
|
"questions": [
|
|
5
5
|
{
|
|
6
6
|
"id": "q1",
|
|
@@ -8,74 +8,28 @@
|
|
|
8
8
|
"title": "퍼셉트론이 1을 내보내는 조건은 무엇인가요?",
|
|
9
9
|
"description": "가중치와 편향이 어떻게 쓰이는지 떠올려 보세요.",
|
|
10
10
|
"options": [
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
{
|
|
12
|
+
"id": "a",
|
|
13
|
+
"text": "입력의 합이 0보다 클 때"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"id": "b",
|
|
17
|
+
"text": "가중합에 편향을 더한 값이 0보다 클 때"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "c",
|
|
21
|
+
"text": "두 입력이 모두 1일 때"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "d",
|
|
25
|
+
"text": "편향이 0보다 클 때"
|
|
26
|
+
}
|
|
15
27
|
],
|
|
16
28
|
"shuffle": false,
|
|
17
29
|
"explanation": {
|
|
18
30
|
"enabled": true,
|
|
19
31
|
"text": "퍼셉트론은 **w1·x1 + w2·x2 + b > 0** 이면 1을 내보냅니다."
|
|
20
32
|
}
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"id": "q2",
|
|
24
|
-
"type": "select_multiple",
|
|
25
|
-
"title": "단층 퍼셉트론으로 만들 수 있는 게이트를 모두 고르세요.",
|
|
26
|
-
"description": "",
|
|
27
|
-
"options": [
|
|
28
|
-
{ "id": "a", "text": "AND" },
|
|
29
|
-
{ "id": "b", "text": "OR" },
|
|
30
|
-
{ "id": "c", "text": "XOR" },
|
|
31
|
-
{ "id": "d", "text": "NAND" }
|
|
32
|
-
],
|
|
33
|
-
"shuffle": true,
|
|
34
|
-
"explanation": {
|
|
35
|
-
"enabled": true,
|
|
36
|
-
"text": "XOR은 선형으로 나눌 수 없어 단층 퍼셉트론으로는 만들 수 없습니다."
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"id": "q3",
|
|
41
|
-
"type": "order",
|
|
42
|
-
"title": "퍼셉트론이 출력을 내는 순서대로 놓으세요.",
|
|
43
|
-
"description": "",
|
|
44
|
-
"options": [
|
|
45
|
-
{ "id": "a", "text": "입력에 가중치를 곱한다" },
|
|
46
|
-
{ "id": "b", "text": "편향을 더한다" },
|
|
47
|
-
{ "id": "c", "text": "활성화 함수로 0 또는 1을 낸다" },
|
|
48
|
-
{ "id": "d", "text": "입력을 정렬한다" }
|
|
49
|
-
],
|
|
50
|
-
"slots": 3,
|
|
51
|
-
"shuffle": true,
|
|
52
|
-
"explanation": { "enabled": false, "text": "" }
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"id": "q4",
|
|
56
|
-
"type": "text",
|
|
57
|
-
"title": "입력마다 곱하는 값을 무엇이라고 하나요?",
|
|
58
|
-
"description": "",
|
|
59
|
-
"placeholder": "한 단어로 입력해 주세요.",
|
|
60
|
-
"explanation": { "enabled": true, "text": "입력마다 곱하는 값은 **가중치(weight)** 입니다." }
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"id": "q5",
|
|
64
|
-
"type": "group",
|
|
65
|
-
"title": "선형 분리 가능한 게이트와 아닌 게이트로 나누세요.",
|
|
66
|
-
"description": "",
|
|
67
|
-
"groups": [
|
|
68
|
-
{ "id": "g1", "name": "선형 분리 가능" },
|
|
69
|
-
{ "id": "g2", "name": "선형 분리 불가능" }
|
|
70
|
-
],
|
|
71
|
-
"options": [
|
|
72
|
-
{ "id": "a", "text": "AND" },
|
|
73
|
-
{ "id": "b", "text": "OR" },
|
|
74
|
-
{ "id": "c", "text": "XOR" },
|
|
75
|
-
{ "id": "d", "text": "XNOR" }
|
|
76
|
-
],
|
|
77
|
-
"shuffle": false,
|
|
78
|
-
"explanation": { "enabled": false, "text": "" }
|
|
79
33
|
}
|
|
80
34
|
]
|
|
81
35
|
}
|
|
@@ -46,6 +46,11 @@ export interface QuizLabels {
|
|
|
46
46
|
correct: string;
|
|
47
47
|
wrong: string;
|
|
48
48
|
}
|
|
49
|
+
/** 문항 본문(보기 · 답안 칸 · 그룹)만. 편집 화면에서 정답을 고를 때 */
|
|
50
|
+
export declare function renderAnswerBody(
|
|
51
|
+
q: any,
|
|
52
|
+
opts: { templates: QuizTemplates },
|
|
53
|
+
): { el: HTMLElement; getValue(): any; setValue(v: any): void };
|
|
49
54
|
export declare function renderQuestion(
|
|
50
55
|
q: any,
|
|
51
56
|
index: number,
|
|
@@ -65,6 +65,18 @@ export function renderQuestion(q, index, opts) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* 문항 본문(보기 · 답안 칸 · 그룹)만. 편집 화면에서 정답을 고를 때 쓴다 (문항 카드 · 결과 · 해설 없음, 보기는 섞지 않음).
|
|
70
|
+
* @param {object} q 문항
|
|
71
|
+
* @param {{ templates: object }} opts
|
|
72
|
+
* @returns {{ el: Element, getValue: () => unknown, setValue: (v: unknown) => void }}
|
|
73
|
+
*/
|
|
74
|
+
export function renderAnswerBody(q, opts) {
|
|
75
|
+
const options = q.options ?? [];
|
|
76
|
+
const byId = new Map(options.map((o) => [o.id, o]));
|
|
77
|
+
return BODY[q.type]({ q, options, byId, disabled: false, ui: opts.templates, made: (n) => n });
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
// ---------- 유형별 본문 ----------
|
|
69
81
|
|
|
70
82
|
function choice({ q, options, ui, made }, multiple) {
|
|
@@ -12,9 +12,35 @@ export declare function convertType(q: any, type: string, names: DefaultNames):
|
|
|
12
12
|
/** messages: 검증 문구 (ui/texts.js의 validation) */
|
|
13
13
|
export declare function validateQuiz(
|
|
14
14
|
content: any,
|
|
15
|
-
messages: Record<string, any
|
|
15
|
+
messages: Record<string, any>
|
|
16
16
|
): { questionIndex: number; message: string } | null;
|
|
17
17
|
export declare function encodeAnswer(q: any, value: any): string;
|
|
18
18
|
export declare function decodeAnswer(q: any, text: string | undefined): any;
|
|
19
19
|
export declare function isAnswered(q: any, value: any): boolean;
|
|
20
|
+
/** 문항별 화면 값 → 제출할 답 문자열 하나 ("q1=b;q2=a,d;…", 주관식은 encodeURIComponent) */
|
|
21
|
+
export declare function joinAnswers(questions: any[], values: any[]): string;
|
|
22
|
+
/** 제출한 답(문자열 또는 옛 { answers }) → 문항 id별 답 문자열 */
|
|
23
|
+
export declare function splitAnswers(questions: any[], answer: unknown): Record<string, string>;
|
|
24
|
+
/** 문항별 정답(화면 값, 주관식은 허용 답 배열) → pattern 정답 정규식 하나 */
|
|
25
|
+
export declare function buildAnswerKey(questions: any[], key: Record<string, any>): string;
|
|
26
|
+
/** buildAnswerKey가 만든 정규식 → 문항별 정답. 다른 모양이면 null */
|
|
27
|
+
export declare function parseAnswerKey(
|
|
28
|
+
questions: any[],
|
|
29
|
+
regex: unknown
|
|
30
|
+
): Record<string, any> | null;
|
|
31
|
+
/** 정답 검증 1 (정답 없음 · 지워진 보기를 가리키는 정답) */
|
|
32
|
+
export declare function validateAnswerKey(
|
|
33
|
+
questions: any[],
|
|
34
|
+
key: Record<string, any>,
|
|
35
|
+
messages: Record<string, any>
|
|
36
|
+
): { questionIndex: number; message: string } | null;
|
|
37
|
+
/** 정답(화면 값)을 다른 답으로 하나 바꾼 값. 바꿀 수 없으면 undefined */
|
|
38
|
+
export declare function wrongValue(q: any, value: any): any;
|
|
39
|
+
/** 정답 검증 2: 왕복(정답 → 제출 문자열이 맞음) · 오답(하나 바꾸면 안 맞음) */
|
|
40
|
+
export declare function checkAnswerKey(
|
|
41
|
+
questions: any[],
|
|
42
|
+
key: Record<string, any>,
|
|
43
|
+
regex: string,
|
|
44
|
+
messages: Record<string, any>
|
|
45
|
+
): { questionIndex: number; message: string } | null;
|
|
20
46
|
export declare function shuffled<T>(items: T[], seed: string): T[];
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// content.json / 편집 화면이 저장하는 settings (학생에게 공개, 정답 없음)
|
|
4
4
|
// { title, description, questions: [{ id, type, title, description, options?, groups?, slots?,
|
|
5
5
|
// shuffle?, placeholder?, explanation: { enabled, text } }] }
|
|
6
|
-
// 제출하는
|
|
7
|
-
//
|
|
6
|
+
// 제출하는 답: 문자열 하나 (ADR 0008). 문항 순서대로 `문항id=답`을 `;`로 잇고, 주관식 답은 encodeURIComponent
|
|
7
|
+
// "q1=b;q2=a,d;q3=c,a,b;q4=%EA%B0%80%EC%A4%91%EC%B9%98;q5=g1:a|g2:b,c"
|
|
8
|
+
// 퀴즈는 완료 정책 on_graded + 채점 방식 pattern 고정 (ADR 0009, completionPolicies ["on_graded"]). 정답(settings.grading)은 편집 화면이 문항마다 고른 답으로
|
|
9
|
+
// 만든 정규식 하나: { type: 'pattern', answer_key: '^q1=b;…$' }
|
|
8
10
|
|
|
9
11
|
// 화면에 보이는 문구는 여기 두지 않습니다 (ui/texts.js). 문구가 필요한 함수는 화면(screens/)이 문구를 넘겨 줍니다.
|
|
10
12
|
|
|
@@ -46,7 +48,7 @@ export function newQuestion(type, usedIds, names) {
|
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
50
|
* 유형을 바꿀 때 데이터 변환 (기존 편집 화면처럼 보기 텍스트는 최대한 살림).
|
|
49
|
-
* 정답은
|
|
51
|
+
* 정답은 편집 화면이 따로 모아 settings.grading에 저장하므로 여기서는 다루지 않는다. names: newQuestion과 같음
|
|
50
52
|
*/
|
|
51
53
|
export function convertType(q, type, names) {
|
|
52
54
|
const next = { ...q, type };
|
|
@@ -109,7 +111,7 @@ export function validateQuiz(content, v) {
|
|
|
109
111
|
return null;
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
// ---------- 답 문자열 (
|
|
114
|
+
// ---------- 답 문자열 (편집 화면이 같은 모양으로 정답 정규식을 만든다) ----------
|
|
113
115
|
|
|
114
116
|
/**
|
|
115
117
|
* 화면의 답 → 문항의 답 문자열
|
|
@@ -160,6 +162,199 @@ export function decodeAnswer(q, text) {
|
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
|
|
165
|
+
// ---------- 제출 답 하나로 잇기 · 풀기 (ADR 0008) ----------
|
|
166
|
+
|
|
167
|
+
/** 문항별 답 문자열 → 제출할 답 문자열 하나. 주관식 답은 encodeURIComponent (`;` · `=` · `|`가 들어가도 경계가 그대로) */
|
|
168
|
+
export function joinAnswers(questions, values) {
|
|
169
|
+
return questions
|
|
170
|
+
.map((q, i) => {
|
|
171
|
+
const a = encodeAnswer(q, values[i]);
|
|
172
|
+
return `${q.id}=${q.type === 'text' ? encodeURIComponent(a) : a}`;
|
|
173
|
+
})
|
|
174
|
+
.join(';');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 제출한 답 → 문항 id별 답 문자열 (다시 열기 · 튜터링). 옛 답 `{ answers: { q1: "b" } }`도 받는다.
|
|
179
|
+
* `;`로 나누고 첫 `=`에서 문항 id와 답을 나눈 뒤, 주관식은 decodeURIComponent
|
|
180
|
+
*/
|
|
181
|
+
export function splitAnswers(questions, answer) {
|
|
182
|
+
if (answer && typeof answer === 'object') return { ...(answer.answers ?? {}) };
|
|
183
|
+
if (typeof answer !== 'string') return {};
|
|
184
|
+
const byId = Object.fromEntries(questions.map((q) => [q.id, q]));
|
|
185
|
+
const out = {};
|
|
186
|
+
for (const part of answer.split(';')) {
|
|
187
|
+
const at = part.indexOf('=');
|
|
188
|
+
if (at < 0) continue;
|
|
189
|
+
const id = part.slice(0, at);
|
|
190
|
+
let value = part.slice(at + 1);
|
|
191
|
+
if (byId[id]?.type === 'text') {
|
|
192
|
+
try {
|
|
193
|
+
value = decodeURIComponent(value);
|
|
194
|
+
} catch {
|
|
195
|
+
// 잘못된 인코딩은 그대로 둔다
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
out[id] = value;
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ---------- 정답 정규식 (편집 화면, ADR 0009) ----------
|
|
204
|
+
|
|
205
|
+
const escapeRegex = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
206
|
+
const unescapeRegex = (text) => text.replace(/\\(.)/g, '$1');
|
|
207
|
+
|
|
208
|
+
/** 정답 하나(화면 값) → 문항 정규식 조각. 주관식은 허용 답 여러 개를 (?:…|…)로 */
|
|
209
|
+
function keyPart(q, value) {
|
|
210
|
+
if (q.type === 'text') {
|
|
211
|
+
const alts = (value ?? []).map((t) => String(t).trim()).filter(Boolean);
|
|
212
|
+
return `(?:${alts.map((t) => escapeRegex(encodeURIComponent(t))).join('|')})`;
|
|
213
|
+
}
|
|
214
|
+
return escapeRegex(encodeAnswer(q, value));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 문항별 정답(화면 값: 주관식은 허용 답 배열) → regex 정답 정규식 하나.
|
|
219
|
+
* 인코딩 → 정규식 이스케이프 → `|`로 묶기 → 전체를 `^…$` (ADR 0008 §4)
|
|
220
|
+
*/
|
|
221
|
+
export function buildAnswerKey(questions, key) {
|
|
222
|
+
return `^${questions.map((q) => `${escapeRegex(q.id)}=${keyPart(q, key[q.id])}`).join(';')}$`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* buildAnswerKey가 만든 정규식 → 문항별 정답(화면 값). 다른 모양(손으로 쓴 정규식)이면 null.
|
|
227
|
+
* 문항이 바뀌었으면 있는 문항만 돌려준다 (없는 문항은 validateAnswerKey가 알려 줌)
|
|
228
|
+
*/
|
|
229
|
+
export function parseAnswerKey(questions, regex) {
|
|
230
|
+
if (typeof regex !== 'string' || !regex.startsWith('^') || !regex.endsWith('$')) return null;
|
|
231
|
+
const byId = Object.fromEntries(questions.map((q) => [q.id, q]));
|
|
232
|
+
const out = {};
|
|
233
|
+
// 정답 조각 안의 `;`는 주관식 인코딩(%3B)이라 나오지 않는다
|
|
234
|
+
for (const part of regex.slice(1, -1).split(';')) {
|
|
235
|
+
const at = part.indexOf('=');
|
|
236
|
+
if (at < 0) return null;
|
|
237
|
+
const id = unescapeRegex(part.slice(0, at));
|
|
238
|
+
const body = part.slice(at + 1);
|
|
239
|
+
const q = byId[id];
|
|
240
|
+
if (!q) continue;
|
|
241
|
+
if (q.type === 'text') {
|
|
242
|
+
if (!body.startsWith('(?:') || !body.endsWith(')')) return null;
|
|
243
|
+
try {
|
|
244
|
+
out[id] = body
|
|
245
|
+
.slice(3, -1)
|
|
246
|
+
.split(/(?<!\\)\|/)
|
|
247
|
+
.map((t) => decodeURIComponent(unescapeRegex(t)))
|
|
248
|
+
.filter(Boolean);
|
|
249
|
+
} catch {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
} else out[id] = decodeAnswer(q, unescapeRegex(body));
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 정답 검증 1: 모든 문항에 정답이 있고, 정답이 지금 있는 보기 · 그룹을 가리키는지 (G63).
|
|
259
|
+
* 문제가 없으면 null, 있으면 { questionIndex, message }
|
|
260
|
+
* @param {object} v 검증 문구 (ui/texts.js의 answers.validation)
|
|
261
|
+
*/
|
|
262
|
+
export function validateAnswerKey(questions, key, v) {
|
|
263
|
+
for (const [i, q] of questions.entries()) {
|
|
264
|
+
const at = (message) => ({ questionIndex: i, message: v.at(i + 1, message) });
|
|
265
|
+
const value = key[q.id];
|
|
266
|
+
if (q.type === 'text') {
|
|
267
|
+
if (!(value ?? []).some((t) => String(t).trim())) return at(v.noAnswer);
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (!isAnswered(q, value)) return at(v.noAnswer);
|
|
271
|
+
const ids = new Set((q.options ?? []).map((o) => o.id));
|
|
272
|
+
const chosen =
|
|
273
|
+
q.type === 'group'
|
|
274
|
+
? Object.values(value ?? {}).flat()
|
|
275
|
+
: q.type === 'select_one'
|
|
276
|
+
? [value]
|
|
277
|
+
: (value ?? []);
|
|
278
|
+
if (chosen.some((id) => !ids.has(id))) return at(v.missingOption);
|
|
279
|
+
if (q.type === 'group' && Object.keys(value ?? {}).some((g) => !q.groups.some((x) => x.id === g)))
|
|
280
|
+
return at(v.missingOption);
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** 정답(화면 값)을 다른 답으로 하나 바꾼 값. 바꿀 수 없으면 undefined (오답 검증용) */
|
|
286
|
+
export function wrongValue(q, value) {
|
|
287
|
+
const ids = (q.options ?? []).map((o) => o.id);
|
|
288
|
+
switch (q.type) {
|
|
289
|
+
case 'select_one':
|
|
290
|
+
return ids.find((id) => id !== value);
|
|
291
|
+
case 'select_multiple': {
|
|
292
|
+
const set = new Set(value ?? []);
|
|
293
|
+
const flip = ids[0];
|
|
294
|
+
if (flip === undefined) return undefined;
|
|
295
|
+
if (set.has(flip)) set.delete(flip);
|
|
296
|
+
else set.add(flip);
|
|
297
|
+
return [...set];
|
|
298
|
+
}
|
|
299
|
+
case 'order': {
|
|
300
|
+
const list = [...(value ?? [])];
|
|
301
|
+
if (list.length >= 2) {
|
|
302
|
+
[list[0], list[1]] = [list[1], list[0]];
|
|
303
|
+
return list;
|
|
304
|
+
}
|
|
305
|
+
const other = ids.find((id) => !list.includes(id));
|
|
306
|
+
return other === undefined ? undefined : [other];
|
|
307
|
+
}
|
|
308
|
+
case 'group': {
|
|
309
|
+
const groups = q.groups.map((g) => g.id);
|
|
310
|
+
const out = Object.fromEntries(groups.map((g) => [g, [...(value?.[g] ?? [])]]));
|
|
311
|
+
const from = groups.find((g) => out[g].length > 0);
|
|
312
|
+
const to = groups.find((g) => g !== from);
|
|
313
|
+
if (!from || !to) return undefined;
|
|
314
|
+
out[to].push(out[from].shift());
|
|
315
|
+
return out;
|
|
316
|
+
}
|
|
317
|
+
case 'text':
|
|
318
|
+
return ['\u0000오답'];
|
|
319
|
+
default:
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* 정답 검증 2 (ADR 0009 §3): 만든 정규식이 학생 화면이 제출할 문자열과 맞는지.
|
|
326
|
+
* - 왕복: 정답을 학생 화면과 같은 joinAnswers로 이은 문자열이 맞아야 한다 (주관식 허용 답은 하나씩 모두)
|
|
327
|
+
* - 오답: 문항 하나를 다른 답으로 바꾼 문자열은 맞지 않아야 한다 (너무 넓은 정규식 방지)
|
|
328
|
+
* 문제가 없으면 null, 있으면 { questionIndex, message }
|
|
329
|
+
* @param {object} v 검증 문구 (ui/texts.js의 answers.validation)
|
|
330
|
+
*/
|
|
331
|
+
export function checkAnswerKey(questions, key, regex, v) {
|
|
332
|
+
let re;
|
|
333
|
+
try {
|
|
334
|
+
re = new RegExp(regex);
|
|
335
|
+
} catch {
|
|
336
|
+
return { questionIndex: -1, message: v.badRegex };
|
|
337
|
+
}
|
|
338
|
+
// 화면 값으로: 주관식은 허용 답 중 하나
|
|
339
|
+
const base = questions.map((q) => (q.type === 'text' ? (key[q.id] ?? [])[0] : key[q.id]));
|
|
340
|
+
if (!re.test(joinAnswers(questions, base))) return { questionIndex: -1, message: v.roundTrip };
|
|
341
|
+
for (const [i, q] of questions.entries()) {
|
|
342
|
+
const at = (message) => ({ questionIndex: i, message: v.at(i + 1, message) });
|
|
343
|
+
if (q.type === 'text')
|
|
344
|
+
for (const alt of key[q.id] ?? []) {
|
|
345
|
+
const values = [...base];
|
|
346
|
+
values[i] = alt;
|
|
347
|
+
if (!re.test(joinAnswers(questions, values))) return at(v.roundTrip);
|
|
348
|
+
}
|
|
349
|
+
const wrong = wrongValue(q, key[q.id]);
|
|
350
|
+
if (wrong === undefined) continue;
|
|
351
|
+
const values = [...base];
|
|
352
|
+
values[i] = q.type === 'text' ? wrong[0] : wrong;
|
|
353
|
+
if (re.test(joinAnswers(questions, values))) return at(v.tooWide);
|
|
354
|
+
}
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
|
|
163
358
|
/** 이 문항에 답했는지 (기존 규칙: 순서는 칸을 모두 채움, 그룹은 하나라도 배치, 나머지는 비어 있지 않음) */
|
|
164
359
|
export function isAnswered(q, value) {
|
|
165
360
|
switch (q.type) {
|
package/templates/quiz/gitignore
CHANGED