@eliceio/cdk-cli 0.0.0-stage → 0.1.0-alpha.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.
- package/README.md +526 -2
- package/es/bin/index.d.ts +2 -0
- package/es/bin/index.js +10 -0
- package/es/cli.d.ts +5 -0
- package/es/cli.js +209 -0
- package/es/commands/build/index.d.ts +30 -0
- package/es/commands/build/index.js +163 -0
- package/es/commands/check/index.d.ts +9 -0
- package/es/commands/check/index.js +31 -0
- package/es/commands/create/index.d.ts +8 -0
- package/es/commands/create/index.js +22 -0
- package/es/commands/create/scaffold.d.ts +24 -0
- package/es/commands/create/scaffold.js +82 -0
- package/es/commands/dev/index.d.ts +6 -0
- package/es/commands/dev/index.js +40 -0
- package/es/commands/doctor/index.d.ts +34 -0
- package/es/commands/doctor/index.js +311 -0
- package/es/commands/guide/index.d.ts +29 -0
- package/es/commands/guide/index.js +120 -0
- package/es/commands/skill/index.d.ts +48 -0
- package/es/commands/skill/index.js +173 -0
- package/es/core/collect.d.ts +21 -0
- package/es/core/collect.js +89 -0
- package/es/core/config.d.ts +55 -0
- package/es/core/config.js +109 -0
- package/es/core/manifest.d.ts +15 -0
- package/es/core/manifest.js +43 -0
- package/es/core/minify.d.ts +18 -0
- package/es/core/minify.js +93 -0
- package/es/core/prepare.d.ts +12 -0
- package/es/core/prepare.js +86 -0
- package/es/core/protocol.d.ts +2 -0
- package/es/core/protocol.js +4 -0
- package/es/core/sandbox.d.ts +17 -0
- package/es/core/sandbox.js +182 -0
- package/es/core/zip.d.ts +4 -0
- package/es/core/zip.js +17 -0
- package/es/dev/grading.d.ts +15 -0
- package/es/dev/grading.js +37 -0
- package/es/dev/host-page.d.ts +7 -0
- package/es/dev/host-page.js +240 -0
- package/es/dev/inject.d.ts +8 -0
- package/es/dev/inject.js +38 -0
- package/es/dev/mock-api.d.ts +65 -0
- package/es/dev/mock-api.js +269 -0
- package/es/dev/server.d.ts +25 -0
- package/es/dev/server.js +309 -0
- package/es/engines/static/index.d.ts +3 -0
- package/es/engines/static/index.js +11 -0
- package/es/engines/types.d.ts +12 -0
- package/es/engines/vite/index.d.ts +2 -0
- package/es/engines/vite/index.js +4 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/rules/check.d.ts +2 -0
- package/es/rules/check.js +282 -0
- package/es/rules/index.d.ts +8 -0
- package/es/rules/index.js +7 -0
- package/es/rules/manifest.d.ts +39 -0
- package/es/rules/manifest.js +168 -0
- package/es/rules/node.d.ts +11 -0
- package/es/rules/node.js +87 -0
- package/es/rules/path.d.ts +7 -0
- package/es/rules/path.js +35 -0
- package/es/rules/refs.d.ts +19 -0
- package/es/rules/refs.js +111 -0
- package/es/rules/skip.d.ts +12 -0
- package/es/rules/skip.js +55 -0
- package/es/rules/spec.d.ts +3 -0
- package/es/rules/spec.js +6 -0
- package/es/rules/types.d.ts +140 -0
- package/es/rules/unused.d.ts +7 -0
- package/es/rules/unused.js +21 -0
- package/es/rules/zip.d.ts +13 -0
- package/es/rules/zip.js +45 -0
- package/es/rules.json.js +3 -0
- package/es/types.d.ts +4 -0
- package/es/version.d.ts +2 -0
- package/es/version.js +7 -0
- package/guides/content-development.md +207 -0
- package/package.json +50 -3
- package/rules.json +608 -0
- package/skills/_shared/always.md +7 -0
- package/skills/elice-content-check/SKILL.md +22 -0
- package/skills/elice-content-create/SKILL.md +21 -0
- package/skills/elice-content-migrate/SKILL.md +21 -0
- package/templates/_shared/lib/cdk-mock.d.ts +94 -0
- package/templates/_shared/lib/cdk-mock.js +429 -0
- package/templates/_shared/lib/cdk.js +3 -0
- package/templates/_shared/lib/elice-content.css +262 -0
- package/templates/_shared/lib/elice-content.d.ts +123 -0
- package/templates/_shared/lib/elice-content.js +534 -0
- package/templates/_shared/lib/elice-tokens.css +446 -0
- package/templates/blank/README.md +64 -0
- package/templates/blank/commentary.txt +2 -0
- package/templates/blank/content.json +4 -0
- package/templates/blank/edit.html +15 -0
- package/templates/blank/elice.config.json +12 -0
- package/templates/blank/gitignore +3 -0
- package/templates/blank/index.html +15 -0
- package/templates/blank/instructor.html +15 -0
- package/templates/blank/screens/edit.js +21 -0
- package/templates/blank/screens/instructor.js +9 -0
- package/templates/blank/screens/learn.js +19 -0
- package/templates/blank/styles.css +1 -0
- package/templates/quiz/README.md +108 -0
- package/templates/quiz/commentary.txt +2 -0
- package/templates/quiz/content.json +81 -0
- package/templates/quiz/core/behaviors.d.ts +59 -0
- package/templates/quiz/core/behaviors.js +310 -0
- package/templates/quiz/core/dom.d.ts +13 -0
- package/templates/quiz/core/dom.js +83 -0
- package/templates/quiz/core/editor.d.ts +48 -0
- package/templates/quiz/core/editor.js +206 -0
- package/templates/quiz/core/markdown.d.ts +2 -0
- package/templates/quiz/core/markdown.js +84 -0
- package/templates/quiz/core/model.d.ts +20 -0
- package/templates/quiz/core/model.js +203 -0
- package/templates/quiz/edit.html +17 -0
- package/templates/quiz/elice.config.json +14 -0
- package/templates/quiz/gitignore +3 -0
- package/templates/quiz/grading.json +13 -0
- package/templates/quiz/index.html +17 -0
- package/templates/quiz/instructor.html +17 -0
- package/templates/quiz/screens/edit.js +139 -0
- package/templates/quiz/screens/instructor.js +27 -0
- package/templates/quiz/screens/learn.js +55 -0
- package/templates/quiz/styles.css +570 -0
- package/templates/quiz/ui/templates/choice.js +22 -0
- package/templates/quiz/ui/templates/edit.d.ts +13 -0
- package/templates/quiz/ui/templates/edit.js +183 -0
- package/templates/quiz/ui/templates/group.js +68 -0
- package/templates/quiz/ui/templates/index.d.ts +5 -0
- package/templates/quiz/ui/templates/index.js +17 -0
- package/templates/quiz/ui/templates/order.js +35 -0
- package/templates/quiz/ui/templates/page.js +29 -0
- package/templates/quiz/ui/templates/question.js +28 -0
- package/templates/quiz/ui/templates/text.js +16 -0
- package/templates/quiz/ui/texts.d.ts +3 -0
- package/templates/quiz/ui/texts.js +127 -0
- package/templates/quiz/ui/theme.css +50 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
Elice Custom HTML 학습자료 프로젝트입니다.
|
|
4
|
+
|
|
5
|
+
## 고치는 곳
|
|
6
|
+
|
|
7
|
+
| 파일 | 화면 |
|
|
8
|
+
| ------------------------------------------- | ------------------------------------------------------ |
|
|
9
|
+
| `screens/learn.js` · `index.html` | 학생 화면 (무엇을 어떤 순서로 놓을지) |
|
|
10
|
+
| `screens/instructor.js` · `instructor.html` | 교육자 화면 |
|
|
11
|
+
| `screens/edit.js` · `edit.html` | 내용 편집 화면 (CMS) |
|
|
12
|
+
| `ui/` | 퀴즈의 모양: 색 · 간격 · 문구 · 마크업 (아래 표) |
|
|
13
|
+
| `content.json` | 처음 내용. 편집 화면에서 저장하면 저장한 내용을 씁니다 |
|
|
14
|
+
| `styles.css` | 이 콘텐츠의 스타일 (값은 `ui/theme.css`의 변수) |
|
|
15
|
+
| `elice.config.json` | 화면 구성(`screens`)과 지원 채점 유형(`gradingTypes`) |
|
|
16
|
+
| `grading.json` | 로컬 채점용 유형 · 정답 (zip에 들어가지 않음) |
|
|
17
|
+
|
|
18
|
+
## 퀴즈 모양 바꾸기
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
ui/ 모양 — 마음대로 고칩니다
|
|
22
|
+
├─ theme.css 색 · 간격 · 모서리 · 보기 카드 (EDS 토큰 위의 --qz-* 변수)
|
|
23
|
+
├─ texts.js 화면에 보이는 문구 전부 (탭 제목 · 불러오는 중 · 학생 · 교육자 · 편집 · 검증 문구)
|
|
24
|
+
└─ templates/ HTML 조각 (question · choice · text · order · group · page · edit)
|
|
25
|
+
screens/ 배치 — 어떤 블록을 어떤 순서로 보일지
|
|
26
|
+
core/ 동작 — 고치지 않습니다 (답 문자열 · 채점 약속, 고르기 · 끌어 놓기 · 순서 바꾸기). ui/를 부르지 않고, 템플릿 · 문구는 screens/가 넘깁니다
|
|
27
|
+
```
|
|
28
|
+
|
|
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
|
+
|
|
40
|
+
템플릿은 `` html`…` `` 조각입니다. 끼워 넣는 글자는 자동으로 이스케이프되고, 클래스 · 태그 · 배치는 자유롭게 바꿔도 됩니다. **`data-role` 속성만 남기면** 동작(`core/`)이 그대로 붙습니다.
|
|
41
|
+
|
|
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
|
+
|
|
51
|
+
보기 · 칸 · 그룹 · 문항 요소의 `data-role` · `data-option` · `data-slot` · `data-group` · `data-id`, 상태 표시 `data-result`(`correct` · `wrong`) · `data-dragging` · `data-ghost`는 동작이 붙입니다. CSS에서 이 속성으로 상태를 꾸밀 수 있습니다.
|
|
52
|
+
|
|
53
|
+
`lib/`는 플랫폼 연결 로직이라 고치지 않습니다. 화면은 **누가 보는지(학생 · 교육자 · 튜터)나 미리보기인지 몰라도 됩니다.**
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
// 학생 화면: 문항을 그리고 답을 모으고 채우는 방법만 알려 준다
|
|
57
|
+
const app = await start({ screen: 'learn' });
|
|
58
|
+
render(app.content);
|
|
59
|
+
app.useSubmit({ getAnswer, setAnswer, validate });
|
|
60
|
+
|
|
61
|
+
// 편집 화면(CMS): 고칠 칸을 그리고 저장할 내용만 알려 준다
|
|
62
|
+
const app = await start({ screen: 'edit' });
|
|
63
|
+
renderForm(app.content);
|
|
64
|
+
app.useSave({ getContent, validate });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
| 키트가 하는 일 | |
|
|
68
|
+
| -------------- | ------------------------------------------------------------------------------------------- |
|
|
69
|
+
| 상태 표시 | 로컬 mock SDK일 때만 화면 맨 위에 한 줄 (미리보기 · 교육자 · 튜터링 안내는 LXP 화면이 맡음) |
|
|
70
|
+
| 튜터링 | 화면을 읽기 전용으로 잠그고 학생 답을 채움, 제출 버튼 없음 |
|
|
71
|
+
| 제출 | 검증 문구, 중복 클릭 방지, 결과·오류 안내 |
|
|
72
|
+
| 다시 열기 | 마지막 답 복원, 지난 점수 |
|
|
73
|
+
| 저장 (편집) | 저장하지 않은 변경 표시, 검증, 저장 문구, 나가기 경고 |
|
|
74
|
+
|
|
75
|
+
필요하면 `app.viewer` · `app.readOnly` · `app.records` · `app.navigation` · `app.submit()` · `app.saveContent()`를 직접 써도 됩니다.
|
|
76
|
+
|
|
77
|
+
## SDK: mock ↔ real
|
|
78
|
+
|
|
79
|
+
키트가 자동으로 고릅니다. 화면 코드는 바꿀 필요가 없습니다.
|
|
80
|
+
|
|
81
|
+
| 언제 | SDK | 채점 · 저장 |
|
|
82
|
+
| --------------------------------------------- | -------------------------------- | ----------------------------------------------------------------------------- |
|
|
83
|
+
| 플랫폼에서 열 때 (`#token=`, 편집기 draft) | real (`lib/cdk.js`) | 서버 |
|
|
84
|
+
| 그 밖 (로컬) | mock (`lib/cdk-mock.js`) | `grading.json`(유형 · 정답)으로 로컬 채점, 저장 내용·제출은 이 브라우저에 |
|
|
85
|
+
|
|
86
|
+
- 강제로 바꾸기: 주소에 `?sdk=mock` 또는 `?sdk=real`
|
|
87
|
+
- 보는 사람 바꾸기 (mock): `#viewer=tutor` (`student` · `instructor` · `tutor`), 편집기 draft 흉내: `#preview=1` · `#edit=1`
|
|
88
|
+
- 오류 상황 (mock): `?mock=session_expired` · `rate_limited` · `request_failed` · `external_service_error` · `slow` · `content_not_ready`
|
|
89
|
+
- mock 기록 지우기: 개발자 도구에서 `localStorage`의 `elice-content-mock:*` 삭제
|
|
90
|
+
|
|
91
|
+
## 퀴즈 데이터와 정답
|
|
92
|
+
|
|
93
|
+
- `content.json`: 처음 문항. 편집 화면에서 저장하면 저장값을 씁니다. 형식은 ecdk 문서 ADR 0006.
|
|
94
|
+
- 문항 유형: 단일 선택 · 복수 선택 · 순서 맞추기 · 주관식 · 그룹 분류
|
|
95
|
+
- 학생 답은 문항마다 문자열로 제출합니다 (`{ "answers": { "q1": "b", "q2": "a,d" } }`).
|
|
96
|
+
- 정답은 LXP 편집 화면의 채점 설정에서 지정합니다. 로컬에서는 `grading.json`(기본 `pattern`: 답 전체를 비교해 모두 맞아야 100점)으로 채점합니다.
|
|
97
|
+
|
|
98
|
+
## 정답
|
|
99
|
+
|
|
100
|
+
정답은 zip에 넣지 않습니다. LXP 편집 화면의 채점 설정에서 따로 저장합니다. `elice.config.json`에는 지원 채점 유형 목록(`gradingTypes`)만 적고, 로컬 미리보기용 유형 · 정답 · 채점 기준은 `grading.json`에 둡니다. 둘 다 `ecdk build`가 zip에서 뺍니다.
|
|
101
|
+
|
|
102
|
+
## 명령
|
|
103
|
+
|
|
104
|
+
```sh
|
|
105
|
+
ecdk dev # 로컬에서 운영과 같은 조건으로 보기 (http://localhost:4170)
|
|
106
|
+
ecdk doctor # 환경·프로젝트 점검
|
|
107
|
+
ecdk build # 검사 후 dist/content.zip (편집 화면에 올릴 파일)
|
|
108
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "퍼셉트론 확인 문제",
|
|
3
|
+
"description": "5문제를 풀고 제출해요.",
|
|
4
|
+
"questions": [
|
|
5
|
+
{
|
|
6
|
+
"id": "q1",
|
|
7
|
+
"type": "select_one",
|
|
8
|
+
"title": "퍼셉트론이 1을 내보내는 조건은 무엇인가요?",
|
|
9
|
+
"description": "가중치와 편향이 어떻게 쓰이는지 떠올려 보세요.",
|
|
10
|
+
"options": [
|
|
11
|
+
{ "id": "a", "text": "입력의 합이 0보다 클 때" },
|
|
12
|
+
{ "id": "b", "text": "가중합에 편향을 더한 값이 0보다 클 때" },
|
|
13
|
+
{ "id": "c", "text": "두 입력이 모두 1일 때" },
|
|
14
|
+
{ "id": "d", "text": "편향이 0보다 클 때" }
|
|
15
|
+
],
|
|
16
|
+
"shuffle": false,
|
|
17
|
+
"explanation": {
|
|
18
|
+
"enabled": true,
|
|
19
|
+
"text": "퍼셉트론은 **w1·x1 + w2·x2 + b > 0** 이면 1을 내보냅니다."
|
|
20
|
+
}
|
|
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
|
+
}
|
|
80
|
+
]
|
|
81
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// core/behaviors.js 타입 (편집기 자동완성 · 테스트용). 템플릿 모음의 모양은 ui/templates/index.js와 같다.
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
type Fragment = HTMLElement | DocumentFragment;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 문항 HTML 조각 모음. 마크업 · 클래스는 자유, 아래 data-role만 지키면 동작이 그대로다.
|
|
7
|
+
* 동작이 직접 붙이는 것: 문항 data-role="question" · data-id · data-result, 보기 data-role="chip" · data-option,
|
|
8
|
+
* 순서 칸 data-role="slot" · data-slot, 그룹 data-role="group" · data-group
|
|
9
|
+
*/
|
|
10
|
+
export interface QuizTemplates {
|
|
11
|
+
/** data-role="result" · data-role="explanation"(hidden) */
|
|
12
|
+
question(props: {
|
|
13
|
+
q: any;
|
|
14
|
+
no: number;
|
|
15
|
+
type: string | null;
|
|
16
|
+
body: Node;
|
|
17
|
+
explanation: string | null;
|
|
18
|
+
}): HTMLElement;
|
|
19
|
+
/** 보기마다 <input data-role="choice" value="보기 id"> */
|
|
20
|
+
choice(props: { q: any; options: any[]; multiple: boolean }): HTMLElement;
|
|
21
|
+
/** data-role="input" */
|
|
22
|
+
text(props: { q: any }): HTMLElement;
|
|
23
|
+
order: {
|
|
24
|
+
/** data-role="pool" · data-role="slots" */
|
|
25
|
+
root(props: { q: any }): HTMLElement;
|
|
26
|
+
slot(props: { index: number; content: Node }): HTMLElement;
|
|
27
|
+
chip(props: { option: any; picked: boolean }): HTMLElement;
|
|
28
|
+
poolEmpty(): Fragment;
|
|
29
|
+
slotEmpty(): Fragment;
|
|
30
|
+
};
|
|
31
|
+
group: {
|
|
32
|
+
/** data-role="pool", 있으면 data-role="pool-area" · data-role="reset" */
|
|
33
|
+
root(props: { q: any; boxes: HTMLElement[] }): HTMLElement;
|
|
34
|
+
/** data-role="items" */
|
|
35
|
+
box(props: { group: any }): HTMLElement;
|
|
36
|
+
/** removable이면 data-role="remove" */
|
|
37
|
+
chip(props: { option: any; picked: boolean; removable: boolean }): HTMLElement;
|
|
38
|
+
poolEmpty(): Fragment;
|
|
39
|
+
boxEmpty(): Fragment;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 동작이 넣는 문구: 유형 이름 · 결과 문구 (ui/templates/index.js의 labels). types가 null이면 유형 표시 없음 */
|
|
44
|
+
export interface QuizLabels {
|
|
45
|
+
types: Record<string, string> | null;
|
|
46
|
+
correct: string;
|
|
47
|
+
wrong: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function renderQuestion(
|
|
50
|
+
q: any,
|
|
51
|
+
index: number,
|
|
52
|
+
opts: { templates: QuizTemplates; labels: QuizLabels; seed?: string; disabled?: boolean },
|
|
53
|
+
): {
|
|
54
|
+
el: HTMLElement;
|
|
55
|
+
getValue(): any;
|
|
56
|
+
setValue(v: any): void;
|
|
57
|
+
setResult(correct: boolean | null): void;
|
|
58
|
+
showExplanation(): void;
|
|
59
|
+
};
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// 문항 동작 (학생 · 교육자 화면, 기존 퀴즈 material UI를 순수 DOM으로 옮김, docs/quiz-spec.md §2)
|
|
2
|
+
// 고르기 · 누르고 놓기 · 끌어 놓기 · 칸끼리 바꾸기 · 결과 표시. 마크업은 ui/templates/*가 만들고,
|
|
3
|
+
// 여기서는 클래스가 아니라 data-role · data-option · data-slot · data-group으로만 요소를 찾는다.
|
|
4
|
+
// 각 문항은 { el, getValue(), setValue(v), setResult(correct | null), showExplanation() }을 돌려준다.
|
|
5
|
+
// ui/를 직접 불러오지 않는다: 템플릿과 문구는 화면(screens/)이 넘겨 준다 (ui/templates/index.js).
|
|
6
|
+
import { lock, part, parts, present } from './dom.js';
|
|
7
|
+
import { shuffled } from './model.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {object} q 문항
|
|
11
|
+
* @param {number} index 0부터
|
|
12
|
+
* @param {{ templates: object, labels: { types: object | null, correct: string, wrong: string },
|
|
13
|
+
* seed?: string, disabled?: boolean }} opts
|
|
14
|
+
* templates: HTML 조각 모음 · labels: 유형 이름 · 결과 문구 (둘 다 ui/templates/index.js) ·
|
|
15
|
+
* labels.types가 null이면 유형 표시 없음 (학생 화면) ·
|
|
16
|
+
* seed: 보기 섞기 기준(보는 사람마다 고정)
|
|
17
|
+
*/
|
|
18
|
+
export function renderQuestion(q, index, opts) {
|
|
19
|
+
const { templates: ui, labels } = opts;
|
|
20
|
+
const results = { true: ['correct', labels.correct], false: ['wrong', labels.wrong] };
|
|
21
|
+
const disabled = Boolean(opts.disabled);
|
|
22
|
+
const options = q.shuffle
|
|
23
|
+
? shuffled(q.options ?? [], `${opts.seed ?? ''}:${q.id}`)
|
|
24
|
+
: (q.options ?? []);
|
|
25
|
+
const byId = new Map((q.options ?? []).map((o) => [o.id, o]));
|
|
26
|
+
/** 템플릿이 만든 요소. 읽기 전용이면 입력 · 버튼을 막는다 */
|
|
27
|
+
const made = (node) => (disabled ? lock(node) : node);
|
|
28
|
+
|
|
29
|
+
const body = BODY[q.type]({ q, options, byId, disabled, ui, made });
|
|
30
|
+
const card = ui.question({
|
|
31
|
+
q,
|
|
32
|
+
no: index + 1,
|
|
33
|
+
type: labels.types ? (labels.types[q.type] ?? q.type) : null,
|
|
34
|
+
body: body.el,
|
|
35
|
+
explanation: q.explanation?.enabled ? (q.explanation.text ?? '') : null,
|
|
36
|
+
});
|
|
37
|
+
card.dataset.role = 'question';
|
|
38
|
+
card.dataset.id = q.id;
|
|
39
|
+
made(card);
|
|
40
|
+
const result = part(card, 'result');
|
|
41
|
+
const explanation = part(card, 'explanation');
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
el: card,
|
|
45
|
+
getValue: body.getValue,
|
|
46
|
+
setValue: body.setValue,
|
|
47
|
+
/** 문항 결과 표시. null이면 지움. 답을 다시 고치면 결과 색을 지운다 (기존 동작) */
|
|
48
|
+
setResult(correct) {
|
|
49
|
+
const [state, text] = results[String(correct)] ?? [];
|
|
50
|
+
if (state) card.dataset.result = state;
|
|
51
|
+
else delete card.dataset.result;
|
|
52
|
+
if (!result) return;
|
|
53
|
+
if (!state) {
|
|
54
|
+
result.hidden = true;
|
|
55
|
+
delete result.dataset.result;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
result.textContent = text;
|
|
59
|
+
result.dataset.result = state;
|
|
60
|
+
result.hidden = false;
|
|
61
|
+
},
|
|
62
|
+
showExplanation() {
|
|
63
|
+
if (explanation) explanation.hidden = false;
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------- 유형별 본문 ----------
|
|
69
|
+
|
|
70
|
+
function choice({ q, options, ui, made }, multiple) {
|
|
71
|
+
const list = made(ui.choice({ q, options, multiple }));
|
|
72
|
+
const inputs = () => parts(list, 'choice');
|
|
73
|
+
return {
|
|
74
|
+
el: list,
|
|
75
|
+
getValue: () => {
|
|
76
|
+
const picked = inputs()
|
|
77
|
+
.filter((i) => i.checked)
|
|
78
|
+
.map((i) => i.value);
|
|
79
|
+
return multiple ? picked : (picked[0] ?? null);
|
|
80
|
+
},
|
|
81
|
+
setValue: (v) => {
|
|
82
|
+
const set = new Set([v].flat());
|
|
83
|
+
for (const i of inputs()) i.checked = set.has(i.value);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function text({ q, ui, made }) {
|
|
89
|
+
const root = made(ui.text({ q }));
|
|
90
|
+
const input = part(root, 'input');
|
|
91
|
+
return { el: root, getValue: () => input.value, setValue: (v) => (input.value = v ?? '') };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 보기 요소에 보기 id를 붙인다 */
|
|
95
|
+
function chipOf(node, o) {
|
|
96
|
+
node.dataset.role = 'chip';
|
|
97
|
+
node.dataset.option = o.id;
|
|
98
|
+
return node;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 순서 맞추기: 보기 풀 → 답안 칸. 끌어 놓기 또는 보기를 누른 뒤 칸을 누르기 */
|
|
102
|
+
function order({ q, options, byId, disabled, ui, made }) {
|
|
103
|
+
const t = ui.order;
|
|
104
|
+
let slots = Array(q.slots).fill(null);
|
|
105
|
+
let picked = null;
|
|
106
|
+
const root = made(t.root({ q }));
|
|
107
|
+
const pool = part(root, 'pool');
|
|
108
|
+
const answer = part(root, 'slots');
|
|
109
|
+
|
|
110
|
+
const place = (id, slot) => {
|
|
111
|
+
const from = slots.indexOf(id);
|
|
112
|
+
if (slot === null) {
|
|
113
|
+
if (from >= 0) slots[from] = null;
|
|
114
|
+
} else if (from >= 0) {
|
|
115
|
+
[slots[from], slots[slot]] = [slots[slot], slots[from]];
|
|
116
|
+
} else slots[slot] = id;
|
|
117
|
+
picked = null;
|
|
118
|
+
draw();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function draw() {
|
|
122
|
+
const placed = new Set(slots.filter(Boolean));
|
|
123
|
+
const left = options.filter((o) => !placed.has(o.id));
|
|
124
|
+
pool.replaceChildren(
|
|
125
|
+
...present([...left.map(chip), left.length === 0 ? made(t.poolEmpty()) : null]),
|
|
126
|
+
);
|
|
127
|
+
answer.replaceChildren(
|
|
128
|
+
...slots.map((id, i) => {
|
|
129
|
+
const slot = made(
|
|
130
|
+
t.slot({ index: i, content: id ? chip(byId.get(id)) : made(t.slotEmpty()) }),
|
|
131
|
+
);
|
|
132
|
+
slot.dataset.role = 'slot';
|
|
133
|
+
slot.dataset.slot = String(i);
|
|
134
|
+
if (!disabled) slot.addEventListener('click', () => picked && place(picked, i));
|
|
135
|
+
return slot;
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
if (!disabled) pool.onclick = (e) => e.target === pool && picked && place(picked, null);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function chip(o) {
|
|
142
|
+
const c = chipOf(made(t.chip({ option: o, picked: picked === o.id })), o);
|
|
143
|
+
if (!disabled) {
|
|
144
|
+
c.addEventListener('click', (e) => {
|
|
145
|
+
e.stopPropagation();
|
|
146
|
+
const inSlot = c.closest('[data-role="slot"]');
|
|
147
|
+
if (picked && picked !== o.id && inSlot) return place(picked, Number(inSlot.dataset.slot));
|
|
148
|
+
picked = picked === o.id ? null : o.id;
|
|
149
|
+
draw();
|
|
150
|
+
});
|
|
151
|
+
draggable(c, (target) => {
|
|
152
|
+
const slot = target?.closest('[data-role="slot"]');
|
|
153
|
+
if (slot && answer.contains(slot)) place(o.id, Number(slot.dataset.slot));
|
|
154
|
+
else if (target && pool.contains(target)) place(o.id, null);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return c;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
draw();
|
|
161
|
+
return {
|
|
162
|
+
el: root,
|
|
163
|
+
getValue: () => [...slots],
|
|
164
|
+
setValue: (v) => {
|
|
165
|
+
slots = Array.from({ length: q.slots }, (_, i) => (v?.[i] && byId.has(v[i]) ? v[i] : null));
|
|
166
|
+
draw();
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** 그룹 분류: 보기 풀 ↔ 그룹 칸. 끌어 놓기 또는 보기를 누른 뒤 그룹을 누르기 (기존 모바일 방식) */
|
|
172
|
+
function group({ q, options, byId, disabled, ui, made }) {
|
|
173
|
+
const t = ui.group;
|
|
174
|
+
let where = {}; // 보기 id → 그룹 id
|
|
175
|
+
let picked = null;
|
|
176
|
+
const boxes = q.groups.map((g) => {
|
|
177
|
+
const box = made(t.box({ group: g }));
|
|
178
|
+
box.dataset.role = 'group';
|
|
179
|
+
box.dataset.group = g.id;
|
|
180
|
+
if (!disabled) box.addEventListener('click', () => picked && move(picked, g.id));
|
|
181
|
+
return { g, box, items: part(box, 'items') };
|
|
182
|
+
});
|
|
183
|
+
const root = made(t.root({ q, boxes: boxes.map((b) => b.box) }));
|
|
184
|
+
const pool = part(root, 'pool');
|
|
185
|
+
const poolArea = part(root, 'pool-area') ?? pool;
|
|
186
|
+
part(root, 'reset')?.addEventListener('click', () => {
|
|
187
|
+
where = {};
|
|
188
|
+
picked = null;
|
|
189
|
+
draw();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const move = (id, gid) => {
|
|
193
|
+
if (gid) where[id] = gid;
|
|
194
|
+
else delete where[id];
|
|
195
|
+
picked = null;
|
|
196
|
+
draw();
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
function chip(o) {
|
|
200
|
+
const placed = Boolean(where[o.id]);
|
|
201
|
+
const c = chipOf(
|
|
202
|
+
made(t.chip({ option: o, picked: picked === o.id, removable: placed && !disabled })),
|
|
203
|
+
o,
|
|
204
|
+
);
|
|
205
|
+
if (!disabled) {
|
|
206
|
+
part(c, 'remove')?.addEventListener('click', (e) => {
|
|
207
|
+
e.stopPropagation();
|
|
208
|
+
move(o.id, null);
|
|
209
|
+
});
|
|
210
|
+
c.addEventListener('click', (e) => {
|
|
211
|
+
e.stopPropagation();
|
|
212
|
+
picked = picked === o.id ? null : o.id;
|
|
213
|
+
draw();
|
|
214
|
+
});
|
|
215
|
+
draggable(c, (target) => {
|
|
216
|
+
const box = target?.closest('[data-role="group"]');
|
|
217
|
+
if (box && root.contains(box)) move(o.id, box.dataset.group);
|
|
218
|
+
else if (target && poolArea.contains(target)) move(o.id, null);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return c;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function draw() {
|
|
225
|
+
const left = options.filter((o) => !where[o.id]);
|
|
226
|
+
pool.replaceChildren(
|
|
227
|
+
...present([...left.map(chip), left.length === 0 ? made(t.poolEmpty()) : null]),
|
|
228
|
+
);
|
|
229
|
+
for (const { g, items } of boxes) {
|
|
230
|
+
const mine = options.filter((o) => where[o.id] === g.id);
|
|
231
|
+
items.replaceChildren(
|
|
232
|
+
...present([...mine.map(chip), mine.length === 0 ? made(t.boxEmpty()) : null]),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
draw();
|
|
238
|
+
return {
|
|
239
|
+
el: root,
|
|
240
|
+
getValue: () =>
|
|
241
|
+
Object.fromEntries(
|
|
242
|
+
q.groups.map((g) => [g.id, options.filter((o) => where[o.id] === g.id).map((o) => o.id)]),
|
|
243
|
+
),
|
|
244
|
+
setValue: (v) => {
|
|
245
|
+
where = {};
|
|
246
|
+
for (const [gid, ids] of Object.entries(v ?? {}))
|
|
247
|
+
for (const id of ids) if (byId.has(id)) where[id] = gid;
|
|
248
|
+
draw();
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const BODY = {
|
|
254
|
+
select_one: (ctx) => choice(ctx, false),
|
|
255
|
+
select_multiple: (ctx) => choice(ctx, true),
|
|
256
|
+
text,
|
|
257
|
+
order,
|
|
258
|
+
group,
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// ---------- 끌어 놓기 (마우스 · 터치 공용, Pointer Events) ----------
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 10px 넘게 움직이면 끌기 시작 (기존: 마우스 10px). 놓은 곳의 요소를 onDrop에 준다.
|
|
265
|
+
* 끄는 동안 원래 요소에 data-dragging, 손가락을 따라오는 복제본에 data-ghost를 붙인다 (styles.css).
|
|
266
|
+
*/
|
|
267
|
+
function draggable(node, onDrop) {
|
|
268
|
+
let dragged = false;
|
|
269
|
+
// 끌기로 끝났으면 뒤따르는 click을 무시 (탭 조작과 겹치지 않게)
|
|
270
|
+
node.addEventListener(
|
|
271
|
+
'click',
|
|
272
|
+
(c) => {
|
|
273
|
+
if (!dragged) return;
|
|
274
|
+
dragged = false;
|
|
275
|
+
c.stopImmediatePropagation();
|
|
276
|
+
},
|
|
277
|
+
{ capture: true },
|
|
278
|
+
);
|
|
279
|
+
node.addEventListener('pointerdown', (down) => {
|
|
280
|
+
if (down.button !== 0) return;
|
|
281
|
+
let ghost = null;
|
|
282
|
+
const start = { x: down.clientX, y: down.clientY };
|
|
283
|
+
const moveTo = (e) => {
|
|
284
|
+
if (!ghost) {
|
|
285
|
+
if (Math.hypot(e.clientX - start.x, e.clientY - start.y) < 10) return;
|
|
286
|
+
ghost = node.cloneNode(true);
|
|
287
|
+
ghost.dataset.ghost = '';
|
|
288
|
+
delete ghost.dataset.role;
|
|
289
|
+
document.body.append(ghost);
|
|
290
|
+
node.dataset.dragging = '';
|
|
291
|
+
}
|
|
292
|
+
ghost.style.left = `${e.clientX}px`;
|
|
293
|
+
ghost.style.top = `${e.clientY}px`;
|
|
294
|
+
};
|
|
295
|
+
const end = (e) => {
|
|
296
|
+
removeEventListener('pointermove', moveTo);
|
|
297
|
+
removeEventListener('pointerup', end);
|
|
298
|
+
removeEventListener('pointercancel', end);
|
|
299
|
+
if (!ghost) return;
|
|
300
|
+
ghost.remove();
|
|
301
|
+
delete node.dataset.dragging;
|
|
302
|
+
dragged = true;
|
|
303
|
+
setTimeout(() => (dragged = false), 0);
|
|
304
|
+
if (e.type === 'pointerup') onDrop(document.elementFromPoint(e.clientX, e.clientY));
|
|
305
|
+
};
|
|
306
|
+
addEventListener('pointermove', moveTo);
|
|
307
|
+
addEventListener('pointerup', end);
|
|
308
|
+
addEventListener('pointercancel', end);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// core/dom.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
export declare const present: (nodes: any[]) => any[];
|
|
4
|
+
export declare function el(
|
|
5
|
+
tag: string,
|
|
6
|
+
props?: Record<string, unknown>,
|
|
7
|
+
...children: any[]
|
|
8
|
+
): HTMLElement;
|
|
9
|
+
/** 최상위 요소가 하나면 그 요소(HTMLElement로 다룸), 아니면 DocumentFragment */
|
|
10
|
+
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): any;
|
|
11
|
+
export declare function part(root: Element, name: string): HTMLElement | null;
|
|
12
|
+
export declare function parts(root: Element, name: string): HTMLElement[];
|
|
13
|
+
export declare function lock<T extends Element>(root: T): T;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// 작은 DOM 도우미. ui/templates/*는 html`…`로 마크업을 쓰고, core/behaviors.js는 data-role로 그 안의 요소를 찾습니다.
|
|
2
|
+
|
|
3
|
+
/** 조건부로 넣은 null · undefined · false 빼기 */
|
|
4
|
+
export const present = (nodes) => nodes.filter((c) => c !== null && c !== undefined && c !== false);
|
|
5
|
+
|
|
6
|
+
export function el(tag, props = {}, ...children) {
|
|
7
|
+
const node = Object.assign(document.createElement(tag), props);
|
|
8
|
+
node.append(...present(children));
|
|
9
|
+
return node;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const escape = (s) =>
|
|
13
|
+
s
|
|
14
|
+
.replace(/&/g, '&')
|
|
15
|
+
.replace(/</g, '<')
|
|
16
|
+
.replace(/>/g, '>')
|
|
17
|
+
.replace(/"/g, '"')
|
|
18
|
+
.replace(/'/g, ''');
|
|
19
|
+
|
|
20
|
+
const MARK = 'qz-node:';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* HTML 조각 템플릿. 끼워 넣는 값은
|
|
24
|
+
* 글자 · 숫자 → 이스케이프해서 글자로 (교육자 · 학생이 쓴 내용도 안전)
|
|
25
|
+
* 요소(Node) · 배열 → 그 자리에 그대로 (태그 사이에만, 속성 값에는 글자만)
|
|
26
|
+
* null · undefined · false → 아무것도 넣지 않음 (`${cond && '…'}`)
|
|
27
|
+
* 줄바꿈이 든 앞뒤 공백은 지우므로 들여쓰기를 자유롭게 해도 됩니다 (한 줄 안의 공백은 그대로).
|
|
28
|
+
* 최상위 요소가 하나면 그 요소를, 아니면 DocumentFragment를 돌려준다.
|
|
29
|
+
*/
|
|
30
|
+
export function html(strings, ...values) {
|
|
31
|
+
const nodes = [];
|
|
32
|
+
const part = (v) => {
|
|
33
|
+
if (v === null || v === undefined || v === false) return '';
|
|
34
|
+
if (Array.isArray(v)) return v.map(part).join('');
|
|
35
|
+
if (typeof Node !== 'undefined' && v instanceof Node) {
|
|
36
|
+
nodes.push(v);
|
|
37
|
+
return `<!--${MARK}${nodes.length - 1}-->`;
|
|
38
|
+
}
|
|
39
|
+
return escape(String(v));
|
|
40
|
+
};
|
|
41
|
+
const markup = strings.reduce((out, s, i) => out + part(values[i - 1]) + s);
|
|
42
|
+
const template = document.createElement('template');
|
|
43
|
+
// 끼워 넣는 값은 모두 위에서 이스케이프하거나 주석 자리표로 바꾼다 (quiz.test.ts 'html 템플릿')
|
|
44
|
+
// ecdk-ignore-next-line sec.html-injection
|
|
45
|
+
template.innerHTML = markup.trim();
|
|
46
|
+
const walker = document.createTreeWalker(
|
|
47
|
+
template.content,
|
|
48
|
+
NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT,
|
|
49
|
+
);
|
|
50
|
+
const swap = [];
|
|
51
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) swap.push(n);
|
|
52
|
+
for (const n of swap) {
|
|
53
|
+
if (n.nodeType === Node.COMMENT_NODE && n.data.startsWith(MARK))
|
|
54
|
+
n.replaceWith(nodes[Number(n.data.slice(MARK.length))]);
|
|
55
|
+
else if (n.nodeType === Node.TEXT_NODE) {
|
|
56
|
+
// 들여쓰기: 줄바꿈이 든 앞뒤 공백은 지우고, 그것만 있는 글자 노드는 뺀다 (JSX와 같은 규칙)
|
|
57
|
+
const data = n.data.replace(/^\s*\n\s*/, '').replace(/\s*\n\s*$/, '');
|
|
58
|
+
if (data === '') n.remove();
|
|
59
|
+
else if (data !== n.data) n.data = data;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const fragment = template.content;
|
|
63
|
+
return fragment.childNodes.length === 1 && fragment.firstChild instanceof Element
|
|
64
|
+
? fragment.firstChild
|
|
65
|
+
: fragment;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** root 자신이나 그 안에서 data-role="name"인 첫 요소 */
|
|
69
|
+
export function part(root, name) {
|
|
70
|
+
const selector = `[data-role="${name}"]`;
|
|
71
|
+
return root.matches?.(selector) ? root : root.querySelector(selector);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** root 안의 data-role="name"인 모든 요소 */
|
|
75
|
+
export const parts = (root, name) => [...root.querySelectorAll(`[data-role="${name}"]`)];
|
|
76
|
+
|
|
77
|
+
/** 읽기 전용(교육자 · 튜터링)일 때 root와 그 안의 입력 · 버튼을 모두 막는다 */
|
|
78
|
+
export function lock(root) {
|
|
79
|
+
if ('disabled' in root) root.disabled = true;
|
|
80
|
+
for (const c of root.querySelectorAll('input, textarea, select, button, fieldset'))
|
|
81
|
+
c.disabled = true;
|
|
82
|
+
return root;
|
|
83
|
+
}
|