@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,48 @@
|
|
|
1
|
+
// core/editor.js 타입 (편집기 자동완성 · 테스트용). templates는 ui/templates/edit.js와 같은 모양
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
/** 동작이 바꾸는 문구 (미리보기 버튼 · 글자 수 · 새 그룹 이름) */
|
|
4
|
+
export interface EditorLabels {
|
|
5
|
+
preview: string;
|
|
6
|
+
previewClose: string;
|
|
7
|
+
count(length: number, max: number): string;
|
|
8
|
+
group(letter: string): string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createEditor(opts: {
|
|
11
|
+
rerender: () => void;
|
|
12
|
+
root: Element;
|
|
13
|
+
templates: Record<string, (props?: any) => any>;
|
|
14
|
+
labels: EditorLabels;
|
|
15
|
+
}): {
|
|
16
|
+
ui: Record<string, (props?: any) => any>;
|
|
17
|
+
field(
|
|
18
|
+
label: string,
|
|
19
|
+
value: string | undefined,
|
|
20
|
+
onInput: (v: string) => void,
|
|
21
|
+
opts?: { multiline?: boolean; required?: boolean; max?: number; hint?: string },
|
|
22
|
+
): HTMLElement;
|
|
23
|
+
markdownField(
|
|
24
|
+
label: string,
|
|
25
|
+
value: string | undefined,
|
|
26
|
+
onInput: (v: string) => void,
|
|
27
|
+
): HTMLElement;
|
|
28
|
+
numberField(
|
|
29
|
+
label: string,
|
|
30
|
+
hint: string,
|
|
31
|
+
value: number,
|
|
32
|
+
max: number,
|
|
33
|
+
onInput: (v: number) => void,
|
|
34
|
+
): HTMLElement;
|
|
35
|
+
toggle(label: string, checked: boolean | undefined, onChange: (v: boolean) => void): HTMLElement;
|
|
36
|
+
itemList(
|
|
37
|
+
kind: 'option' | 'group',
|
|
38
|
+
items: any[],
|
|
39
|
+
key: string,
|
|
40
|
+
opts?: { onDelete?: () => void },
|
|
41
|
+
): HTMLElement;
|
|
42
|
+
card(
|
|
43
|
+
props: { q: any; index: number; count: number; types: [string, string][]; body: Node[] },
|
|
44
|
+
on: { type(value: string): void; up(): void; down(): void; remove(): void },
|
|
45
|
+
): HTMLElement;
|
|
46
|
+
addQuestion(onClick: () => void): HTMLElement;
|
|
47
|
+
cardAt(index: number): HTMLElement | undefined;
|
|
48
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// 편집 화면 동작: 칸에 값 넣기 · 입력 반영 · 마크다운 미리보기 · 보기/그룹 목록 (추가 · 삭제 · 끌어서 순서 바꾸기).
|
|
2
|
+
// 마크업은 ui/templates/edit.js가 만들고, 여기서는 data-role로만 요소를 찾는다.
|
|
3
|
+
// ui/를 직접 불러오지 않는다: 템플릿과 문구는 화면(screens/edit.js)이 넘겨 준다.
|
|
4
|
+
import { part, parts } from './dom.js';
|
|
5
|
+
import { markdown } from './markdown.js';
|
|
6
|
+
import { LIMITS, nextId } from './model.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 편집 폼 도우미. rerender: 데이터를 바꾼 뒤 폼을 다시 그리는 함수 · root: 폼이 놓인 요소(키보드로 옮긴 뒤 초점 찾기)
|
|
10
|
+
* templates: HTML 조각 모음(ui/templates/edit.js) · labels: 동작이 바꾸는 문구 (미리보기 버튼 · 글자 수 · 새 그룹 이름)
|
|
11
|
+
* @param {{ rerender: () => void, root: Element, templates: object,
|
|
12
|
+
* labels: { preview: string, previewClose: string, count: (length: number, max: number) => string,
|
|
13
|
+
* group: (letter: string) => string } }} opts
|
|
14
|
+
*/
|
|
15
|
+
export function createEditor({ rerender, root, templates, labels }) {
|
|
16
|
+
const ui = templates;
|
|
17
|
+
|
|
18
|
+
/** 글 입력 칸. 값을 넣고, 고치면 onInput(값)과 글자 수 · 미리보기를 갱신 */
|
|
19
|
+
function field(label, value, onInput, { multiline = false, required = false, max, hint } = {}) {
|
|
20
|
+
return bindField(ui.field({ label, required, hint, max, multiline }), value, onInput, max);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 마크다운 입력 + 미리보기 (기존 WYSIWYG 대신) */
|
|
24
|
+
function markdownField(label, value, onInput) {
|
|
25
|
+
const node = bindField(ui.field({ label, multiline: true, markdown: true }), value, (v) => {
|
|
26
|
+
onInput(v);
|
|
27
|
+
if (!preview.hidden) preview.replaceChildren(markdown(v));
|
|
28
|
+
});
|
|
29
|
+
const input = part(node, 'input');
|
|
30
|
+
const preview = part(node, 'preview');
|
|
31
|
+
const toggle = part(node, 'preview-toggle');
|
|
32
|
+
toggle.addEventListener('click', () => {
|
|
33
|
+
preview.hidden = !preview.hidden;
|
|
34
|
+
toggle.textContent = preview.hidden ? labels.preview : labels.previewClose;
|
|
35
|
+
preview.replaceChildren(markdown(input.value));
|
|
36
|
+
});
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function bindField(node, value, onInput, max) {
|
|
41
|
+
const input = part(node, 'input');
|
|
42
|
+
const count = part(node, 'count');
|
|
43
|
+
input.value = value ?? '';
|
|
44
|
+
if (max) input.maxLength = max;
|
|
45
|
+
const showCount = () =>
|
|
46
|
+
count && (count.textContent = labels.count(input.value.length, max));
|
|
47
|
+
showCount();
|
|
48
|
+
input.addEventListener('input', () => {
|
|
49
|
+
onInput(input.value);
|
|
50
|
+
showCount();
|
|
51
|
+
});
|
|
52
|
+
return node;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 숫자 칸 */
|
|
56
|
+
function numberField(label, hint, value, max, onInput) {
|
|
57
|
+
const node = ui.numberField({ label, hint, max });
|
|
58
|
+
const input = part(node, 'input');
|
|
59
|
+
input.value = value;
|
|
60
|
+
input.addEventListener('input', () => onInput(Number(input.value)));
|
|
61
|
+
return node;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 켜고 끄기 */
|
|
65
|
+
function toggle(label, checked, onChange) {
|
|
66
|
+
const node = ui.toggle({ label });
|
|
67
|
+
const input = part(node, 'input');
|
|
68
|
+
input.checked = Boolean(checked);
|
|
69
|
+
input.addEventListener('change', () => onChange(input.checked));
|
|
70
|
+
return node;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 보기 · 그룹 목록 (단일 · 복수 · 순서 · 그룹 공통). 정답 표시 없음. 손잡이를 끌어 순서 바꾸기
|
|
75
|
+
* @param {'option' | 'group'} kind
|
|
76
|
+
* @param {object[]} items q.options 또는 q.groups (직접 고침)
|
|
77
|
+
* @param {string} key 키보드로 옮긴 뒤 초점을 찾을 이름 (화면에서 겹치지 않게)
|
|
78
|
+
* @param {{ onDelete?: () => void }} [opts] 지운 뒤 할 일 (예: 순서 맞추기 칸 수 줄이기)
|
|
79
|
+
*/
|
|
80
|
+
function itemList(kind, items, key, { onDelete } = {}) {
|
|
81
|
+
const isGroup = kind === 'group';
|
|
82
|
+
const text = isGroup ? 'name' : 'text';
|
|
83
|
+
const min = isGroup ? LIMITS.groupsMin : LIMITS.optionsMin;
|
|
84
|
+
const max = isGroup ? LIMITS.groupsMax : LIMITS.optionsMax;
|
|
85
|
+
const rows = items.map((item, i) => {
|
|
86
|
+
const row = ui.row({ kind, index: i, canDelete: items.length > min, min });
|
|
87
|
+
row.dataset.role = 'row';
|
|
88
|
+
const input = part(row, 'input');
|
|
89
|
+
input.value = item[text];
|
|
90
|
+
input.addEventListener('input', () => (item[text] = input.value));
|
|
91
|
+
part(row, 'delete').addEventListener('click', () => {
|
|
92
|
+
items.splice(i, 1);
|
|
93
|
+
onDelete?.();
|
|
94
|
+
rerender();
|
|
95
|
+
});
|
|
96
|
+
sortHandle(part(row, 'handle'), items, i, key);
|
|
97
|
+
return row;
|
|
98
|
+
});
|
|
99
|
+
const full = items.length >= max;
|
|
100
|
+
const add = ui.addButton({ kind, full, max });
|
|
101
|
+
add.addEventListener('click', () => {
|
|
102
|
+
const ids = items.map((x) => x.id);
|
|
103
|
+
items.push(
|
|
104
|
+
isGroup
|
|
105
|
+
? {
|
|
106
|
+
id: nextId(ids, 'g'),
|
|
107
|
+
name: labels.group(String.fromCharCode(65 + items.length)),
|
|
108
|
+
}
|
|
109
|
+
: { id: nextId(ids), text: '' },
|
|
110
|
+
);
|
|
111
|
+
rerender();
|
|
112
|
+
});
|
|
113
|
+
return ui.list({ rows, add });
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** list[from]을 to 자리로 옮기고 다시 그린 뒤, 키보드로 옮겼으면 옮긴 손잡이에 초점을 둔다 */
|
|
117
|
+
function moveTo(list, from, to, key, refocus) {
|
|
118
|
+
if (to === from || to < 0 || to >= list.length) return;
|
|
119
|
+
const [item] = list.splice(from, 1);
|
|
120
|
+
list.splice(to, 0, item);
|
|
121
|
+
rerender();
|
|
122
|
+
if (refocus) root.querySelector(`[data-sort="${key}:${to}"]`)?.focus();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 끌어서 순서 바꾸는 손잡이 (마우스 · 터치 공용 Pointer Events). 끄는 동안 다른 줄이 비켜 자리를 보여 준다.
|
|
127
|
+
* 키보드: 손잡이에서 ↑ · ↓. 끄는 줄에는 data-dragging이 붙는다 (styles.css).
|
|
128
|
+
*/
|
|
129
|
+
function sortHandle(handle, list, i, key) {
|
|
130
|
+
handle.dataset.sort = `${key}:${i}`;
|
|
131
|
+
handle.addEventListener('keydown', (e) => {
|
|
132
|
+
const d = { ArrowUp: -1, ArrowDown: 1 }[e.key];
|
|
133
|
+
if (!d) return;
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
moveTo(list, i, i + d, key, true);
|
|
136
|
+
});
|
|
137
|
+
handle.addEventListener('pointerdown', (down) => {
|
|
138
|
+
if (down.button !== 0) return;
|
|
139
|
+
down.preventDefault();
|
|
140
|
+
const row = handle.closest('[data-role="row"]');
|
|
141
|
+
const rows = [...row.parentElement.querySelectorAll(':scope > [data-role="row"]')];
|
|
142
|
+
const rects = rows.map((r) => r.getBoundingClientRect());
|
|
143
|
+
const step = rects.length > 1 ? Math.abs(rects[1].top - rects[0].top) : rects[0].height;
|
|
144
|
+
handle.setPointerCapture(down.pointerId);
|
|
145
|
+
row.dataset.dragging = '';
|
|
146
|
+
let to = i;
|
|
147
|
+
const onMove = (e) => {
|
|
148
|
+
const dy = e.clientY - down.clientY;
|
|
149
|
+
row.style.transform = `translateY(${dy}px)`;
|
|
150
|
+
const center = rects[i].top + rects[i].height / 2 + dy;
|
|
151
|
+
to = rects.filter((r, j) => j !== i && r.top + r.height / 2 < center).length;
|
|
152
|
+
rows.forEach((r, j) => {
|
|
153
|
+
if (j === i) return;
|
|
154
|
+
const shift = j > i && j <= to ? -step : j < i && j >= to ? step : 0;
|
|
155
|
+
r.style.transform = shift ? `translateY(${shift}px)` : '';
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
const end = (e) => {
|
|
159
|
+
handle.removeEventListener('pointermove', onMove);
|
|
160
|
+
handle.removeEventListener('pointerup', end);
|
|
161
|
+
handle.removeEventListener('pointercancel', end);
|
|
162
|
+
delete row.dataset.dragging;
|
|
163
|
+
for (const r of rows) r.style.transform = '';
|
|
164
|
+
if (e.type === 'pointerup') moveTo(list, i, to, key, false);
|
|
165
|
+
};
|
|
166
|
+
handle.addEventListener('pointermove', onMove);
|
|
167
|
+
handle.addEventListener('pointerup', end);
|
|
168
|
+
handle.addEventListener('pointercancel', end);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 문항 카드: 유형 바꾸기 · 위로 · 아래로 · 삭제를 붙인다. on: { type(값), up(), down(), remove() }
|
|
174
|
+
*/
|
|
175
|
+
function card(props, on) {
|
|
176
|
+
const node = ui.card(props);
|
|
177
|
+
node.dataset.role = 'card';
|
|
178
|
+
node.dataset.index = String(props.index);
|
|
179
|
+
const type = part(node, 'type');
|
|
180
|
+
type.addEventListener('change', () => on.type(type.value));
|
|
181
|
+
part(node, 'up').addEventListener('click', on.up);
|
|
182
|
+
part(node, 'down').addEventListener('click', on.down);
|
|
183
|
+
part(node, 'delete').addEventListener('click', on.remove);
|
|
184
|
+
return node;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** 문항 추가 버튼 */
|
|
188
|
+
function addQuestion(onClick) {
|
|
189
|
+
const node = ui.addQuestion();
|
|
190
|
+
node.addEventListener('click', onClick);
|
|
191
|
+
return node;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
ui,
|
|
196
|
+
field,
|
|
197
|
+
markdownField,
|
|
198
|
+
numberField,
|
|
199
|
+
toggle,
|
|
200
|
+
itemList,
|
|
201
|
+
card,
|
|
202
|
+
addQuestion,
|
|
203
|
+
/** 검증에 걸린 문항 카드 */
|
|
204
|
+
cardAt: (index) => parts(root, 'card').find((c) => c.dataset.index === String(index)),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// 지문 · 해설용 작은 마크다운 (외부 라이브러리 없이). 먼저 HTML을 모두 이스케이프하므로 교육자가 쓴 태그는 그대로 글자로 보인다.
|
|
2
|
+
// 지원: 문단 · 줄바꿈 · # 제목 · **굵게** · *기울임* · `코드` · ```코드 블록``` · - 목록 · 1. 목록 · [링크](https://…)
|
|
3
|
+
|
|
4
|
+
const escape = (s) =>
|
|
5
|
+
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
6
|
+
|
|
7
|
+
function inline(s) {
|
|
8
|
+
return s
|
|
9
|
+
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
10
|
+
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
11
|
+
.replace(/\*([^*]+)\*/g, '<em>$1</em>')
|
|
12
|
+
.replace(
|
|
13
|
+
/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,
|
|
14
|
+
'<a href="$2" target="_blank" rel="noopener">$1</a>',
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function markdownToHtml(source) {
|
|
19
|
+
const lines = escape(String(source ?? '')).split('\n');
|
|
20
|
+
const out = [];
|
|
21
|
+
let list = null;
|
|
22
|
+
let code = null;
|
|
23
|
+
let para = [];
|
|
24
|
+
const flushPara = () => {
|
|
25
|
+
if (para.length) out.push(`<p>${inline(para.join('<br>'))}</p>`);
|
|
26
|
+
para = [];
|
|
27
|
+
};
|
|
28
|
+
const flushList = () => {
|
|
29
|
+
if (list)
|
|
30
|
+
out.push(
|
|
31
|
+
`<${list.tag}>${list.items.map((i) => `<li>${inline(i)}</li>`).join('')}</${list.tag}>`,
|
|
32
|
+
);
|
|
33
|
+
list = null;
|
|
34
|
+
};
|
|
35
|
+
for (const line of lines) {
|
|
36
|
+
if (code) {
|
|
37
|
+
if (line.startsWith('```')) {
|
|
38
|
+
out.push(`<pre><code>${code.join('\n')}</code></pre>`);
|
|
39
|
+
code = null;
|
|
40
|
+
} else code.push(line);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (line.startsWith('```')) {
|
|
44
|
+
flushPara();
|
|
45
|
+
flushList();
|
|
46
|
+
code = [];
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const heading = line.match(/^(#{1,3})\s+(.*)$/);
|
|
50
|
+
const bullet = line.match(/^\s*[-*]\s+(.*)$/);
|
|
51
|
+
const numbered = line.match(/^\s*\d+\.\s+(.*)$/);
|
|
52
|
+
if (heading) {
|
|
53
|
+
flushPara();
|
|
54
|
+
flushList();
|
|
55
|
+
out.push(`<h${heading[1].length + 2}>${inline(heading[2])}</h${heading[1].length + 2}>`);
|
|
56
|
+
} else if (bullet || numbered) {
|
|
57
|
+
flushPara();
|
|
58
|
+
const tag = bullet ? 'ul' : 'ol';
|
|
59
|
+
if (list?.tag !== tag) flushList();
|
|
60
|
+
list ??= { tag, items: [] };
|
|
61
|
+
list.items.push((bullet ?? numbered)[1]);
|
|
62
|
+
} else if (line.trim() === '') {
|
|
63
|
+
flushPara();
|
|
64
|
+
flushList();
|
|
65
|
+
} else {
|
|
66
|
+
flushList();
|
|
67
|
+
para.push(line);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (code) out.push(`<pre><code>${code.join('\n')}</code></pre>`);
|
|
71
|
+
flushPara();
|
|
72
|
+
flushList();
|
|
73
|
+
return out.join('');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 마크다운을 안전하게 넣은 요소 */
|
|
77
|
+
export function markdown(source, className = 'qz-markdown') {
|
|
78
|
+
const el = document.createElement('div');
|
|
79
|
+
el.className = className;
|
|
80
|
+
// markdownToHtml은 먼저 전부 이스케이프하고 정해진 태그만 만든다 (quiz.test.ts '마크다운')
|
|
81
|
+
// ecdk-ignore-next-line sec.html-injection
|
|
82
|
+
el.innerHTML = markdownToHtml(source);
|
|
83
|
+
return el;
|
|
84
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// core/model.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
/** 새 보기 · 그룹에 채우는 이름 (ui/texts.js의 defaults) */
|
|
4
|
+
export interface DefaultNames {
|
|
5
|
+
option(no: number): string;
|
|
6
|
+
group(letter: string): string;
|
|
7
|
+
}
|
|
8
|
+
export declare const LIMITS: Record<string, number>;
|
|
9
|
+
export declare function nextId(used: string[], prefix?: string): string;
|
|
10
|
+
export declare function newQuestion(type: string, usedIds: string[], names: DefaultNames): any;
|
|
11
|
+
export declare function convertType(q: any, type: string, names: DefaultNames): any;
|
|
12
|
+
/** messages: 검증 문구 (ui/texts.js의 validation) */
|
|
13
|
+
export declare function validateQuiz(
|
|
14
|
+
content: any,
|
|
15
|
+
messages: Record<string, any>,
|
|
16
|
+
): { questionIndex: number; message: string } | null;
|
|
17
|
+
export declare function encodeAnswer(q: any, value: any): string;
|
|
18
|
+
export declare function decodeAnswer(q: any, text: string | undefined): any;
|
|
19
|
+
export declare function isAnswered(q: any, value: any): boolean;
|
|
20
|
+
export declare function shuffled<T>(items: T[], seed: string): T[];
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// 퀴즈 데이터 모델. 학생 · 교육자 · 편집 화면이 같이 씁니다. (기존 퀴즈 material 명세: docs/quiz-spec.md)
|
|
2
|
+
//
|
|
3
|
+
// content.json / 편집 화면이 저장하는 settings (학생에게 공개, 정답 없음)
|
|
4
|
+
// { title, description, questions: [{ id, type, title, description, options?, groups?, slots?,
|
|
5
|
+
// shuffle?, placeholder?, explanation: { enabled, text } }] }
|
|
6
|
+
// 제출하는 답 (문항마다 정해진 모양의 문자열, 채점은 서버가 답 묶음 전체를 비교: pattern)
|
|
7
|
+
// { answers: { q1: "b", q2: "a,d", q3: "c,a,b", q4: "가중치", q5: "g1:a|g2:b,c" } }
|
|
8
|
+
|
|
9
|
+
// 화면에 보이는 문구는 여기 두지 않습니다 (ui/texts.js). 문구가 필요한 함수는 화면(screens/)이 문구를 넘겨 줍니다.
|
|
10
|
+
|
|
11
|
+
/** 편집 규칙 (기존 퀴즈 편집 화면과 같은 값) */
|
|
12
|
+
export const LIMITS = {
|
|
13
|
+
titleMax: 1000,
|
|
14
|
+
placeholderMax: 1000,
|
|
15
|
+
optionsMin: 2,
|
|
16
|
+
optionsMax: 20,
|
|
17
|
+
groupsMin: 2,
|
|
18
|
+
groupsMax: 6,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const hasOptions = (type) => type !== 'text';
|
|
22
|
+
|
|
23
|
+
/** 보기·그룹 id는 답 문자열에 그대로 들어가므로 영문 소문자·숫자만 (구분자 , | : 를 쓰지 않음) */
|
|
24
|
+
export function nextId(used, prefix = '') {
|
|
25
|
+
const taken = new Set(used);
|
|
26
|
+
if (!prefix) {
|
|
27
|
+
for (const c of 'abcdefghijklmnopqrstuvwxyz') if (!taken.has(c)) return c;
|
|
28
|
+
}
|
|
29
|
+
for (let n = 1; ; n++) if (!taken.has(`${prefix || 'o'}${n}`)) return `${prefix || 'o'}${n}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {{ option: (no: number) => string, group: (letter: string) => string }} names
|
|
34
|
+
* 새 보기 · 그룹에 채우는 이름 (ui/texts.js의 defaults)
|
|
35
|
+
*/
|
|
36
|
+
export function newQuestion(type, usedIds, names) {
|
|
37
|
+
const q = {
|
|
38
|
+
id: nextId(usedIds, 'q'),
|
|
39
|
+
type,
|
|
40
|
+
title: '',
|
|
41
|
+
description: '',
|
|
42
|
+
explanation: { enabled: false, text: '' },
|
|
43
|
+
};
|
|
44
|
+
return convertType(q, type, names);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 유형을 바꿀 때 데이터 변환 (기존 편집 화면처럼 보기 텍스트는 최대한 살림).
|
|
49
|
+
* 정답은 LXP 채점 설정에 있으므로 여기서는 다루지 않는다. names: newQuestion과 같음
|
|
50
|
+
*/
|
|
51
|
+
export function convertType(q, type, names) {
|
|
52
|
+
const next = { ...q, type };
|
|
53
|
+
if (hasOptions(type)) {
|
|
54
|
+
const options = (q.options ?? []).map((o) => ({ ...o }));
|
|
55
|
+
while (options.length < LIMITS.optionsMin)
|
|
56
|
+
options.push({
|
|
57
|
+
id: nextId(options.map((o) => o.id)),
|
|
58
|
+
text: names.option(options.length + 1),
|
|
59
|
+
});
|
|
60
|
+
next.options = options;
|
|
61
|
+
next.shuffle = Boolean(q.shuffle);
|
|
62
|
+
} else {
|
|
63
|
+
delete next.options;
|
|
64
|
+
delete next.shuffle;
|
|
65
|
+
}
|
|
66
|
+
if (type === 'order')
|
|
67
|
+
next.slots = Math.min(Math.max(1, q.slots ?? next.options.length), next.options.length);
|
|
68
|
+
else delete next.slots;
|
|
69
|
+
if (type === 'group')
|
|
70
|
+
next.groups =
|
|
71
|
+
q.groups && q.groups.length >= LIMITS.groupsMin
|
|
72
|
+
? q.groups
|
|
73
|
+
: [
|
|
74
|
+
{ id: 'g1', name: names.group('A') },
|
|
75
|
+
{ id: 'g2', name: names.group('B') },
|
|
76
|
+
];
|
|
77
|
+
else delete next.groups;
|
|
78
|
+
if (type === 'text') next.placeholder = q.placeholder ?? '';
|
|
79
|
+
else delete next.placeholder;
|
|
80
|
+
return next;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 편집 화면 검증. 문제가 없으면 null, 있으면 { questionIndex, message }
|
|
85
|
+
* @param {object} v 검증 문구 (ui/texts.js의 validation)
|
|
86
|
+
*/
|
|
87
|
+
export function validateQuiz(content, v) {
|
|
88
|
+
if (!content.title?.trim()) return { questionIndex: -1, message: v.quizTitle };
|
|
89
|
+
if (!content.questions?.length) return { questionIndex: -1, message: v.noQuestions };
|
|
90
|
+
for (const [i, q] of content.questions.entries()) {
|
|
91
|
+
const at = (message) => ({ questionIndex: i, message: v.at(i + 1, message) });
|
|
92
|
+
if (!q.title?.trim()) return at(v.title);
|
|
93
|
+
if (q.title.length > LIMITS.titleMax) return at(v.titleMax(LIMITS.titleMax));
|
|
94
|
+
if (hasOptions(q.type)) {
|
|
95
|
+
if (q.options.length < LIMITS.optionsMin) return at(v.optionsMin(LIMITS.optionsMin));
|
|
96
|
+
if (q.options.length > LIMITS.optionsMax) return at(v.optionsMax(LIMITS.optionsMax));
|
|
97
|
+
if (q.options.some((o) => !o.text?.trim())) return at(v.optionText);
|
|
98
|
+
}
|
|
99
|
+
if (q.type === 'order' && !(q.slots >= 1 && q.slots <= q.options.length)) return at(v.slots);
|
|
100
|
+
if (q.type === 'group') {
|
|
101
|
+
if (q.groups.length < LIMITS.groupsMin) return at(v.groupsMin(LIMITS.groupsMin));
|
|
102
|
+
if (q.groups.length > LIMITS.groupsMax) return at(v.groupsMax(LIMITS.groupsMax));
|
|
103
|
+
if (q.groups.some((g) => !g.name?.trim())) return at(v.groupName);
|
|
104
|
+
}
|
|
105
|
+
if (q.type === 'text' && (q.placeholder ?? '').length > LIMITS.placeholderMax)
|
|
106
|
+
return at(v.placeholderMax(LIMITS.placeholderMax));
|
|
107
|
+
if (q.explanation?.enabled && !q.explanation.text?.trim()) return at(v.explanation);
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ---------- 답 문자열 (LXP 채점 설정이 같은 모양으로 정답을 만든다) ----------
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 화면의 답 → 문항의 답 문자열
|
|
116
|
+
* select_one "b" · select_multiple "a,d"(정렬) · order "c,a,b"(순서 유지) · text 앞뒤 공백 제거 ·
|
|
117
|
+
* group "g1:a|g2:b,c"(그룹은 정의 순서, 그룹 안 정렬, 빈 그룹은 "g1:")
|
|
118
|
+
*/
|
|
119
|
+
export function encodeAnswer(q, value) {
|
|
120
|
+
switch (q.type) {
|
|
121
|
+
case 'select_one':
|
|
122
|
+
return value ?? '';
|
|
123
|
+
case 'select_multiple':
|
|
124
|
+
return [...(value ?? [])].sort().join(',');
|
|
125
|
+
case 'order':
|
|
126
|
+
return (value ?? []).join(',');
|
|
127
|
+
case 'text':
|
|
128
|
+
return String(value ?? '').trim();
|
|
129
|
+
case 'group':
|
|
130
|
+
return q.groups
|
|
131
|
+
.map((g) => `${g.id}:${[...(value?.[g.id] ?? [])].sort().join(',')}`)
|
|
132
|
+
.join('|');
|
|
133
|
+
default:
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 답 문자열 → 화면의 답 (다시 열었을 때 · 튜터링) */
|
|
139
|
+
export function decodeAnswer(q, text) {
|
|
140
|
+
const s = typeof text === 'string' ? text : '';
|
|
141
|
+
const list = (x) => (x ? x.split(',').filter(Boolean) : []);
|
|
142
|
+
switch (q.type) {
|
|
143
|
+
case 'select_one':
|
|
144
|
+
return s || null;
|
|
145
|
+
case 'select_multiple':
|
|
146
|
+
case 'order':
|
|
147
|
+
return list(s);
|
|
148
|
+
case 'text':
|
|
149
|
+
return s;
|
|
150
|
+
case 'group': {
|
|
151
|
+
const out = Object.fromEntries(q.groups.map((g) => [g.id, []]));
|
|
152
|
+
for (const part of s.split('|')) {
|
|
153
|
+
const [gid, items] = part.split(':');
|
|
154
|
+
if (gid && gid in out) out[gid] = list(items);
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
default:
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 이 문항에 답했는지 (기존 규칙: 순서는 칸을 모두 채움, 그룹은 하나라도 배치, 나머지는 비어 있지 않음) */
|
|
164
|
+
export function isAnswered(q, value) {
|
|
165
|
+
switch (q.type) {
|
|
166
|
+
case 'select_one':
|
|
167
|
+
return Boolean(value);
|
|
168
|
+
case 'select_multiple':
|
|
169
|
+
return (value ?? []).length > 0;
|
|
170
|
+
case 'order':
|
|
171
|
+
return (value ?? []).length === q.slots && value.every(Boolean);
|
|
172
|
+
case 'text':
|
|
173
|
+
return String(value ?? '').trim() !== '';
|
|
174
|
+
case 'group':
|
|
175
|
+
return Object.values(value ?? {}).some((items) => items.length > 0);
|
|
176
|
+
default:
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ---------- 보기 섞기 (보는 사람마다 고정, 화면 순서만 바꿈 · 답은 보기 id라 채점과 무관) ----------
|
|
182
|
+
|
|
183
|
+
function hash(text) {
|
|
184
|
+
let h = 2166136261;
|
|
185
|
+
for (let i = 0; i < text.length; i++) h = Math.imul(h ^ text.charCodeAt(i), 16777619);
|
|
186
|
+
return h >>> 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function shuffled(items, seed) {
|
|
190
|
+
let x = hash(seed) || 1;
|
|
191
|
+
const rand = () => {
|
|
192
|
+
x ^= x << 13;
|
|
193
|
+
x ^= x >>> 17;
|
|
194
|
+
x ^= x << 5;
|
|
195
|
+
return (x >>> 0) / 4294967296;
|
|
196
|
+
};
|
|
197
|
+
const out = [...items];
|
|
198
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
199
|
+
const j = Math.floor(rand() * (i + 1));
|
|
200
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
<!-- 제목 · "불러오는 중" 문구는 ui/texts.js(page)에서 고칩니다. 여기 글은 스크립트가 돌기 전에만 보입니다 -->
|
|
7
|
+
<title>내용 편집</title>
|
|
8
|
+
<link rel="stylesheet" href="lib/elice-tokens.css" />
|
|
9
|
+
<link rel="stylesheet" href="lib/elice-content.css" />
|
|
10
|
+
<link rel="stylesheet" href="ui/theme.css" />
|
|
11
|
+
<link rel="stylesheet" href="styles.css" />
|
|
12
|
+
<script type="module" src="screens/edit.js"></script>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<main id="app"><p class="ec-muted">불러오는 중…</p></main>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
<!-- 제목 · "불러오는 중" 문구는 ui/texts.js(page)에서 고칩니다. 여기 글은 스크립트가 돌기 전에만 보입니다 -->
|
|
7
|
+
<title>학생 화면</title>
|
|
8
|
+
<link rel="stylesheet" href="lib/elice-tokens.css" />
|
|
9
|
+
<link rel="stylesheet" href="lib/elice-content.css" />
|
|
10
|
+
<link rel="stylesheet" href="ui/theme.css" />
|
|
11
|
+
<link rel="stylesheet" href="styles.css" />
|
|
12
|
+
<script type="module" src="screens/learn.js"></script>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<main id="app"><p class="ec-muted">불러오는 중…</p></main>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
<!-- 제목 · "불러오는 중" 문구는 ui/texts.js(page)에서 고칩니다. 여기 글은 스크립트가 돌기 전에만 보입니다 -->
|
|
7
|
+
<title>교육자 화면</title>
|
|
8
|
+
<link rel="stylesheet" href="lib/elice-tokens.css" />
|
|
9
|
+
<link rel="stylesheet" href="lib/elice-content.css" />
|
|
10
|
+
<link rel="stylesheet" href="ui/theme.css" />
|
|
11
|
+
<link rel="stylesheet" href="styles.css" />
|
|
12
|
+
<script type="module" src="screens/instructor.js"></script>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<main id="app"><p class="ec-muted">불러오는 중…</p></main>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|