@eliceio/cdk-cli 1.2.1 → 1.3.0-contenttypes.1
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 +63 -53
- package/es/cli.js +11 -2
- package/es/commands/build/index.js +12 -0
- package/es/commands/create/index.js +2 -0
- package/es/commands/create/scaffold.d.ts +2 -2
- package/es/commands/create/scaffold.js +3 -3
- package/es/commands/dev/index.d.ts +10 -1
- package/es/commands/dev/index.js +47 -7
- package/es/commands/doctor/index.js +6 -2
- package/es/core/config.d.ts +42 -9
- package/es/core/config.js +217 -12
- package/es/core/project-check.d.ts +3 -2
- package/es/core/project-check.js +14 -3
- package/es/core/regex.d.ts +11 -0
- package/es/core/regex.js +41 -0
- package/es/core/sandbox.d.ts +26 -0
- package/es/core/sandbox.js +240 -30
- package/es/dev/assets.d.ts +80 -0
- package/es/dev/assets.js +240 -0
- package/es/dev/check.d.ts +30 -0
- package/es/dev/check.js +224 -34
- package/es/dev/grading.d.ts +49 -14
- package/es/dev/grading.js +109 -29
- package/es/dev/host-page.js +27 -3
- package/es/dev/inject.d.ts +2 -1
- package/es/dev/inject.js +10 -2
- package/es/dev/mock-api.d.ts +26 -3
- package/es/dev/mock-api.js +219 -40
- package/es/dev/server.d.ts +12 -1
- package/es/dev/server.js +115 -9
- package/es/engines/vite/index.js +1 -1
- package/es/engines/vite/plugin.d.ts +2 -0
- package/es/engines/vite/plugin.js +33 -5
- package/es/rules/answers.d.ts +13 -0
- package/es/rules/answers.js +94 -0
- package/es/rules/check.js +70 -1
- package/es/rules/index.d.ts +1 -0
- package/es/rules/index.js +1 -0
- package/es/rules/size.d.ts +31 -0
- package/es/rules/size.js +58 -0
- package/es/rules/types.d.ts +12 -0
- package/es/rules.json.js +2 -2
- package/package.json +2 -2
- package/rules.json +34 -5
- package/skills/_shared/always.md +3 -3
- package/skills/_shared/references/00-what-the-person-decides.md +1 -1
- package/skills/_shared/references/02-design-the-material.md +10 -7
- package/skills/_shared/references/03-create-the-project.md +10 -8
- package/skills/_shared/references/04-rules.md +1 -1
- package/skills/_shared/references/05-screen-code.md +52 -23
- package/skills/_shared/references/06-using-the-quiz-template.md +7 -6
- package/skills/_shared/references/08-fix-check-errors.md +23 -22
- package/skills/_shared/references/09-check.md +8 -6
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +13 -13
- package/skills/_shared/references/13-edit-screen-design.md +122 -0
- package/skills/_shared/references/14-layouts.md +96 -0
- package/skills/elice-content-check/SKILL.md +2 -2
- package/skills/elice-content-create/SKILL.md +1 -1
- package/skills/elice-content-migrate/SKILL.md +1 -1
- package/skills/elice-content-publish/SKILL.md +1 -1
- package/templates/_shared/lib/cdk-mock.d.ts +47 -3
- package/templates/_shared/lib/cdk-mock.js +293 -15
- package/templates/_shared/lib/elice-content-editor.js +89 -58
- package/templates/_shared/lib/elice-content.css +1313 -126
- package/templates/_shared/lib/elice-content.d.ts +222 -23
- package/templates/_shared/lib/elice-content.js +1176 -88
- package/templates/_shared/lib/icons/empty-content.d.ts +2 -0
- package/templates/_shared/lib/icons/empty-content.js +11 -0
- package/templates/_shared/lib/icons/file-video.d.ts +2 -0
- package/templates/_shared/lib/icons/file-video.js +11 -0
- package/templates/_shared/lib/icons/file.d.ts +2 -0
- package/templates/_shared/lib/icons/file.js +11 -0
- package/templates/blank/README.md +6 -4
- package/templates/blank/edit.html +8 -2
- package/templates/blank/index.html +6 -1
- package/templates/blank/instructor.html +6 -1
- package/templates/blank/screens/instructor.js +8 -2
- package/templates/blank/screens/learn.js +1 -1
- package/templates/blank/template.json +1 -1
- package/templates/document/README.md +92 -0
- package/templates/document/commentary.txt +2 -0
- package/templates/document/core/dom.d.ts +13 -0
- package/templates/document/core/dom.js +83 -0
- package/templates/document/core/file-type.d.ts +21 -0
- package/templates/document/core/file-type.js +85 -0
- package/templates/document/core/group-3d.d.ts +20 -0
- package/templates/document/core/group-3d.js +256 -0
- package/templates/document/core/inline-edit.d.ts +15 -0
- package/templates/document/core/inline-edit.js +377 -0
- package/templates/document/core/load.d.ts +13 -0
- package/templates/document/core/load.js +40 -0
- package/templates/document/core/pdf-options.d.ts +9 -0
- package/templates/document/core/pdf-options.js +36 -0
- package/templates/document/core/pdf-worker.d.ts +24 -0
- package/templates/document/core/pdf-worker.js +122 -0
- package/templates/document/core/pdf.d.ts +12 -0
- package/templates/document/core/pdf.js +190 -0
- package/templates/document/core/pptx-edit.d.ts +14 -0
- package/templates/document/core/pptx-edit.js +137 -0
- package/templates/document/core/pptx-fonts.d.ts +5 -0
- package/templates/document/core/pptx-fonts.js +115 -0
- package/templates/document/core/pptx-media.d.ts +18 -0
- package/templates/document/core/pptx-media.js +83 -0
- package/templates/document/core/pptx-view.d.ts +5 -0
- package/templates/document/core/pptx-view.js +185 -0
- package/templates/document/core/settings.d.ts +25 -0
- package/templates/document/core/settings.js +86 -0
- package/templates/document/core/slide-edges.d.ts +3 -0
- package/templates/document/core/slide-edges.js +82 -0
- package/templates/document/core/viewer.d.ts +28 -0
- package/templates/document/core/viewer.js +159 -0
- package/templates/document/edit.html +17 -0
- package/templates/document/gitignore +4 -0
- package/templates/document/index.html +18 -0
- package/templates/document/metadata.json +9 -0
- package/templates/document/package.json +17 -0
- package/templates/document/public/fonts/OFL-Caladea.txt +93 -0
- package/templates/document/public/fonts/OFL-Carlito.txt +93 -0
- package/templates/document/public/fonts/caladea-latin-400-normal.woff2 +0 -0
- package/templates/document/public/fonts/caladea-latin-700-normal.woff2 +0 -0
- package/templates/document/public/fonts/carlito-latin-400-normal.woff2 +0 -0
- package/templates/document/public/fonts/carlito-latin-700-normal.woff2 +0 -0
- package/templates/document/screens/edit.js +574 -0
- package/templates/document/screens/learn.js +61 -0
- package/templates/document/styles.css +644 -0
- package/templates/document/template.json +6 -0
- package/templates/document/ui/templates/edit.js +82 -0
- package/templates/document/ui/templates/page.js +11 -0
- package/templates/document/ui/templates/viewer.js +41 -0
- package/templates/document/ui/texts.d.ts +3 -0
- package/templates/document/ui/texts.js +62 -0
- package/templates/document/ui/theme.css +69 -0
- package/templates/quiz/README.md +32 -14
- package/templates/quiz/core/behaviors.d.ts +17 -7
- package/templates/quiz/core/behaviors.js +40 -53
- package/templates/quiz/core/editor.d.ts +27 -2
- package/templates/quiz/core/editor.js +412 -11
- package/templates/quiz/core/markdown.d.ts +19 -0
- package/templates/quiz/core/markdown.js +225 -11
- package/templates/quiz/core/model.d.ts +40 -3
- package/templates/quiz/core/model.js +112 -5
- package/templates/quiz/core/rich-text.d.ts +18 -0
- package/templates/quiz/core/rich-text.js +469 -0
- package/templates/quiz/edit.html +12 -3
- package/templates/quiz/index.html +12 -3
- package/templates/quiz/public/img/mascot-half.webp +0 -0
- package/templates/quiz/screens/edit.js +331 -49
- package/templates/quiz/screens/learn.js +147 -15
- package/templates/quiz/styles.css +1244 -622
- package/templates/quiz/template.json +9 -2
- package/templates/quiz/ui/templates/edit.d.ts +19 -5
- package/templates/quiz/ui/templates/edit.js +371 -77
- package/templates/quiz/ui/templates/group.js +19 -8
- package/templates/quiz/ui/templates/order.js +25 -24
- package/templates/quiz/ui/templates/page.js +33 -8
- package/templates/quiz/ui/templates/question.js +6 -4
- package/templates/quiz/ui/texts.js +91 -26
- package/templates/quiz/ui/theme.css +8 -9
- package/templates/steps/README.md +77 -0
- package/templates/steps/commentary.txt +7 -0
- package/templates/steps/edit.html +21 -0
- package/templates/steps/gitignore +4 -0
- package/templates/steps/index.html +69 -0
- package/templates/steps/metadata.json +9 -0
- package/templates/steps/package.json +13 -0
- package/templates/steps/screens/edit.js +32 -0
- package/templates/steps/screens/learn.js +108 -0
- package/templates/steps/styles.css +54 -0
- package/templates/steps/template.json +6 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
// 지문 · 해설 편집 칸: 보이는 그대로 고치는 글 칸(contenteditable)과 마크다운 사이를 오간다 (연주님 최종 수정본).
|
|
2
|
+
// 저장하는 값은 늘 마크다운이라 학생 화면(core/markdown.js)이 그대로 읽는다. 붙여 넣기는 글자만 받는다.
|
|
3
|
+
// 서식: 굵게 · 기울임 · 취소선 · 글머리 · 번호 목록 · 코드(한 문단 안은 `코드`, 여러 문단을 고르면 코드 블록)
|
|
4
|
+
import { lineNumbers, markdown } from './markdown.js';
|
|
5
|
+
|
|
6
|
+
// 서식은 브라우저 편집 명령으로 (없는 환경에서는 아무 일도 하지 않음)
|
|
7
|
+
const command = (...args) => document.execCommand?.(...args);
|
|
8
|
+
const commandState = (name) => Boolean(document.queryCommandState?.(name));
|
|
9
|
+
|
|
10
|
+
const BLOCK_TAGS = new Set([
|
|
11
|
+
'P',
|
|
12
|
+
'DIV',
|
|
13
|
+
'UL',
|
|
14
|
+
'OL',
|
|
15
|
+
'LI',
|
|
16
|
+
'PRE',
|
|
17
|
+
'BLOCKQUOTE',
|
|
18
|
+
'H1',
|
|
19
|
+
'H2',
|
|
20
|
+
'H3',
|
|
21
|
+
'H4',
|
|
22
|
+
'H5',
|
|
23
|
+
'H6',
|
|
24
|
+
]);
|
|
25
|
+
const isBlock = (node) => node.nodeType === 1 && BLOCK_TAGS.has(node.tagName);
|
|
26
|
+
// 글 속 서식 기호는 \로 막아 마크다운으로 읽히지 않게 (코드 안은 \ · `만)
|
|
27
|
+
const escapeText = (s) => s.replace(/ /g, ' ').replace(/[\\*`[\]~]/g, '\\$&');
|
|
28
|
+
const escapeCode = (s) => s.replace(/ /g, ' ').replace(/[\\`]/g, '\\$&');
|
|
29
|
+
const wrap = (s, mark) => (s.trim() === '' ? s : `${mark}${s}${mark}`);
|
|
30
|
+
|
|
31
|
+
/** 한 문단 안의 글과 서식을 마크다운으로 */
|
|
32
|
+
function inlineMarkdown(node, inCode = false) {
|
|
33
|
+
let out = '';
|
|
34
|
+
for (const child of node.childNodes) {
|
|
35
|
+
if (child.nodeType === 3) {
|
|
36
|
+
out += inCode ? escapeCode(child.data) : escapeText(child.data);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (child.nodeType !== 1) continue;
|
|
40
|
+
const tag = child.tagName;
|
|
41
|
+
if (tag === 'BR') {
|
|
42
|
+
out += '\n';
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (tag === 'IMG') {
|
|
46
|
+
// zip 안 그림(img/…)만 글 속에 남는다. 올린 그림은 칸 사이 그림 칸(블록)으로 따로 둔다
|
|
47
|
+
const src = child.getAttribute('src') ?? '';
|
|
48
|
+
if (/^img\//.test(src))
|
|
49
|
+
out += `![${(child.getAttribute('alt') ?? '').replace(/[[\]]/g, '')}](${src})`;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const inner = inlineMarkdown(child, inCode || tag === 'CODE');
|
|
53
|
+
if (!inner) continue;
|
|
54
|
+
if (inCode) out += inner;
|
|
55
|
+
else if (tag === 'STRONG' || tag === 'B') out += wrap(inner, '**');
|
|
56
|
+
else if (tag === 'EM' || tag === 'I') out += wrap(inner, '*');
|
|
57
|
+
else if (tag === 'DEL' || tag === 'S' || tag === 'STRIKE') out += wrap(inner, '~~');
|
|
58
|
+
else if (tag === 'CODE') out += inner.trim() === '' ? inner : `\`${inner}\``;
|
|
59
|
+
else if (tag === 'A') {
|
|
60
|
+
const href = child.getAttribute('href') ?? '';
|
|
61
|
+
out += /^https?:\/\//.test(href) ? `[${inner}](${href})` : inner;
|
|
62
|
+
} else out += inner;
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 문단 첫머리의 # · - · 1. 은 제목 · 목록으로 읽히지 않게 막는다 */
|
|
68
|
+
const paragraph = (s) =>
|
|
69
|
+
s
|
|
70
|
+
.split('\n')
|
|
71
|
+
.map((line) =>
|
|
72
|
+
line
|
|
73
|
+
.replace(/^(\s*)(#{1,3})(\s)/, '$1\\$2$3')
|
|
74
|
+
.replace(/^(\s*)-(\s)/, '$1\\-$2')
|
|
75
|
+
.replace(/^(\s*)(\d+)\.(\s)/, '$1$2\\.$3'),
|
|
76
|
+
)
|
|
77
|
+
.join('\n')
|
|
78
|
+
.replace(/^\n+|\n+$/g, '')
|
|
79
|
+
.trim();
|
|
80
|
+
|
|
81
|
+
/** 서식 없이 글만 (코드 블록) */
|
|
82
|
+
function plainText(node) {
|
|
83
|
+
let out = '';
|
|
84
|
+
const walk = (n) => {
|
|
85
|
+
for (const child of n.childNodes) {
|
|
86
|
+
if (child.nodeType === 3) out += child.data.replace(/ /g, ' ');
|
|
87
|
+
else if (child.tagName === 'BR') out += '\n';
|
|
88
|
+
else walk(child);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
walk(node);
|
|
92
|
+
return out.replace(/\n+$/, '');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 칸 안의 문단들을 마크다운 덩어리로 */
|
|
96
|
+
function blocks(root) {
|
|
97
|
+
const out = [];
|
|
98
|
+
let loose = [];
|
|
99
|
+
const flush = () => {
|
|
100
|
+
if (!loose.length) return;
|
|
101
|
+
const box = document.createElement('div');
|
|
102
|
+
for (const n of loose) box.append(n.cloneNode(true));
|
|
103
|
+
const text = paragraph(inlineMarkdown(box));
|
|
104
|
+
if (text) out.push(text);
|
|
105
|
+
loose = [];
|
|
106
|
+
};
|
|
107
|
+
for (const node of root.childNodes) {
|
|
108
|
+
if (node.nodeType === 3 || (node.nodeType === 1 && !isBlock(node))) {
|
|
109
|
+
loose.push(node);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
flush();
|
|
113
|
+
if (node.nodeType !== 1) continue;
|
|
114
|
+
const tag = node.tagName;
|
|
115
|
+
if (tag === 'UL' || tag === 'OL') {
|
|
116
|
+
const items = [...node.children]
|
|
117
|
+
.filter((li) => li.tagName === 'LI')
|
|
118
|
+
.map((li, i) => [
|
|
119
|
+
tag === 'UL' ? '- ' : `${i + 1}. `,
|
|
120
|
+
inlineMarkdown(li).replace(/\n+/g, ' ').trim(),
|
|
121
|
+
])
|
|
122
|
+
.filter(([, text]) => text)
|
|
123
|
+
.map(([mark, text]) => mark + text);
|
|
124
|
+
if (items.length) out.push(items.join('\n'));
|
|
125
|
+
} else if (tag === 'PRE') {
|
|
126
|
+
const code = plainText(node);
|
|
127
|
+
if (code.trim()) out.push(`\`\`\`\n${code}\n\`\`\``);
|
|
128
|
+
} else if (/^H[1-6]$/.test(tag)) {
|
|
129
|
+
const text = inlineMarkdown(node).replace(/\n+/g, ' ').trim();
|
|
130
|
+
if (text) out.push(`${'#'.repeat(Math.min(3, Math.max(1, Number(tag[1]) - 2)))} ${text}`);
|
|
131
|
+
} else if (node.querySelector('p, div, ul, ol, pre, h1, h2, h3, h4, h5, h6')) {
|
|
132
|
+
out.push(...blocks(node));
|
|
133
|
+
} else {
|
|
134
|
+
const text = paragraph(inlineMarkdown(node));
|
|
135
|
+
if (text) out.push(text);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
flush();
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** 글 칸(또는 그 일부)을 마크다운으로 */
|
|
143
|
+
export const toMarkdown = (root) => blocks(root).join('\n\n');
|
|
144
|
+
|
|
145
|
+
const LAST_BLOCK = /^(PRE|UL|OL|H[1-6])$/;
|
|
146
|
+
const emptyParagraph = () => {
|
|
147
|
+
const p = document.createElement('p');
|
|
148
|
+
p.append(document.createElement('br'));
|
|
149
|
+
return p;
|
|
150
|
+
};
|
|
151
|
+
/** 마지막이 목록 · 코드 블록이면 뒤에 빈 문단을 두어 그 밖으로 이어 쓸 수 있게 */
|
|
152
|
+
function keepTrailingParagraph(root) {
|
|
153
|
+
const last = root.lastElementChild;
|
|
154
|
+
if (!last || LAST_BLOCK.test(last.tagName)) root.append(emptyParagraph());
|
|
155
|
+
}
|
|
156
|
+
/** 커서를 요소 처음(false) · 끝(true)으로 */
|
|
157
|
+
function caretAt(node, atEnd) {
|
|
158
|
+
const range = document.createRange();
|
|
159
|
+
range.selectNodeContents(node);
|
|
160
|
+
range.collapse(!atEnd);
|
|
161
|
+
const selection = getSelection();
|
|
162
|
+
selection.removeAllRanges();
|
|
163
|
+
selection.addRange(range);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 글 칸 하나를 보이는 그대로 고치는 칸으로. 고칠 때마다 onChange(마크다운)
|
|
168
|
+
* @param {HTMLElement} el contenteditable 요소
|
|
169
|
+
* @param {{ onChange: (markdown: string) => void }} opts
|
|
170
|
+
*/
|
|
171
|
+
export function richText(el, { onChange }) {
|
|
172
|
+
let saved = null;
|
|
173
|
+
const remember = () => {
|
|
174
|
+
const selection = getSelection();
|
|
175
|
+
if (selection.rangeCount && el.contains(selection.anchorNode))
|
|
176
|
+
saved = selection.getRangeAt(0).cloneRange();
|
|
177
|
+
};
|
|
178
|
+
/** 서식 버튼을 누를 때 칸의 선택 범위 (초점이 버튼에 가 있었으면 마지막 선택을 되살림) */
|
|
179
|
+
const range = () => {
|
|
180
|
+
el.focus();
|
|
181
|
+
const selection = getSelection();
|
|
182
|
+
if (selection.rangeCount && el.contains(selection.anchorNode)) return selection.getRangeAt(0);
|
|
183
|
+
if (saved && el.contains(saved.startContainer)) {
|
|
184
|
+
selection.removeAllRanges();
|
|
185
|
+
selection.addRange(saved);
|
|
186
|
+
return saved;
|
|
187
|
+
}
|
|
188
|
+
caretAt(el, true);
|
|
189
|
+
return selection.getRangeAt(0);
|
|
190
|
+
};
|
|
191
|
+
/** 칸 바로 아래 문단 */
|
|
192
|
+
const topBlock = (node) => {
|
|
193
|
+
let n = node;
|
|
194
|
+
while (n && n.parentNode !== el) n = n.parentNode;
|
|
195
|
+
return n && n !== el ? n : null;
|
|
196
|
+
};
|
|
197
|
+
const closest = (node, tag) => {
|
|
198
|
+
for (let n = node; n && n !== el; n = n.parentNode) if (n.tagName === tag) return n;
|
|
199
|
+
return null;
|
|
200
|
+
};
|
|
201
|
+
const markLines = () => {
|
|
202
|
+
for (const pre of el.querySelectorAll('pre')) {
|
|
203
|
+
const count = plainText(pre).split('\n').length;
|
|
204
|
+
if (count >= 3) {
|
|
205
|
+
pre.classList.add('qz-lines');
|
|
206
|
+
pre.dataset.lines = lineNumbers(count);
|
|
207
|
+
} else {
|
|
208
|
+
pre.classList.remove('qz-lines');
|
|
209
|
+
delete pre.dataset.lines;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const markEmpty = () => el.toggleAttribute('data-empty', toMarkdown(el) === '');
|
|
214
|
+
const changed = () => {
|
|
215
|
+
markLines();
|
|
216
|
+
markEmpty();
|
|
217
|
+
onChange(toMarkdown(el));
|
|
218
|
+
};
|
|
219
|
+
const tidy = () => {
|
|
220
|
+
if (!el.childNodes.length || (el.childNodes.length === 1 && el.firstChild.nodeName === 'BR')) {
|
|
221
|
+
el.replaceChildren(emptyParagraph());
|
|
222
|
+
caretAt(el, false);
|
|
223
|
+
}
|
|
224
|
+
keepTrailingParagraph(el);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
el.addEventListener('input', () => {
|
|
228
|
+
tidy();
|
|
229
|
+
changed();
|
|
230
|
+
remember();
|
|
231
|
+
});
|
|
232
|
+
for (const type of ['keyup', 'mouseup', 'touchend', 'focusout'])
|
|
233
|
+
el.addEventListener(type, remember);
|
|
234
|
+
el.addEventListener('paste', (e) => {
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
command('insertText', false, e.clipboardData?.getData('text/plain') ?? '');
|
|
237
|
+
});
|
|
238
|
+
// 코드 블록 안에서 Enter는 블록을 끝내지 않고 줄만 바꾼다
|
|
239
|
+
el.addEventListener('keydown', (e) => {
|
|
240
|
+
if (e.key !== 'Enter' || e.shiftKey || e.isComposing) return;
|
|
241
|
+
const selection = getSelection();
|
|
242
|
+
if (selection.rangeCount && closest(selection.anchorNode, 'PRE')) {
|
|
243
|
+
e.preventDefault();
|
|
244
|
+
command('insertLineBreak');
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const textOf = (node) => {
|
|
249
|
+
let out = '';
|
|
250
|
+
for (const child of node.childNodes)
|
|
251
|
+
out += child.nodeType === 3 ? child.data : child.tagName === 'BR' ? '\n' : textOf(child);
|
|
252
|
+
return out.replace(/ /g, ' ');
|
|
253
|
+
};
|
|
254
|
+
/** 코드 블록을 줄마다 문단으로 */
|
|
255
|
+
const unwrapPre = (pre) => {
|
|
256
|
+
const fragment = document.createDocumentFragment();
|
|
257
|
+
for (const line of plainText(pre).split('\n')) {
|
|
258
|
+
const p = document.createElement('p');
|
|
259
|
+
if (line) p.textContent = line;
|
|
260
|
+
else p.append(document.createElement('br'));
|
|
261
|
+
fragment.append(p);
|
|
262
|
+
}
|
|
263
|
+
pre.replaceWith(fragment);
|
|
264
|
+
};
|
|
265
|
+
/** first부터 last까지 문단을 코드 블록 하나로 */
|
|
266
|
+
const wrapPre = (first, last) => {
|
|
267
|
+
const nodes = [];
|
|
268
|
+
for (let n = first; n; n = n.nextSibling) {
|
|
269
|
+
nodes.push(n);
|
|
270
|
+
if (n === last) break;
|
|
271
|
+
}
|
|
272
|
+
const lines = nodes.flatMap((n) =>
|
|
273
|
+
n.tagName === 'UL' || n.tagName === 'OL'
|
|
274
|
+
? [...n.children].map((li) => li.textContent)
|
|
275
|
+
: n.tagName === 'PRE'
|
|
276
|
+
? plainText(n).split('\n')
|
|
277
|
+
: textOf(n).split('\n'),
|
|
278
|
+
);
|
|
279
|
+
const pre = document.createElement('pre');
|
|
280
|
+
const code = document.createElement('code');
|
|
281
|
+
code.textContent = lines.join('\n');
|
|
282
|
+
pre.append(code);
|
|
283
|
+
first.before(pre);
|
|
284
|
+
for (const n of nodes) n.remove();
|
|
285
|
+
caretAt(code, true);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const editor = {
|
|
289
|
+
el,
|
|
290
|
+
set(value) {
|
|
291
|
+
el.replaceChildren(...markdown(value ?? '').childNodes);
|
|
292
|
+
keepTrailingParagraph(el);
|
|
293
|
+
markLines();
|
|
294
|
+
markEmpty();
|
|
295
|
+
},
|
|
296
|
+
get: () => toMarkdown(el),
|
|
297
|
+
focus(atEnd = false) {
|
|
298
|
+
el.focus();
|
|
299
|
+
caretAt(el, atEnd);
|
|
300
|
+
},
|
|
301
|
+
/** 커서 앞 · 뒤 글 (그 자리에 그림을 넣을 때) */
|
|
302
|
+
split() {
|
|
303
|
+
const at = range();
|
|
304
|
+
const before = document.createRange();
|
|
305
|
+
before.selectNodeContents(el);
|
|
306
|
+
before.setEnd(at.startContainer, at.startOffset);
|
|
307
|
+
const after = document.createRange();
|
|
308
|
+
after.selectNodeContents(el);
|
|
309
|
+
after.setStart(at.endContainer, at.endOffset);
|
|
310
|
+
return {
|
|
311
|
+
before: toMarkdown(before.cloneContents()),
|
|
312
|
+
after: toMarkdown(after.cloneContents()),
|
|
313
|
+
};
|
|
314
|
+
},
|
|
315
|
+
/** 서식 버튼 눌림 표시 */
|
|
316
|
+
state() {
|
|
317
|
+
const selection = getSelection();
|
|
318
|
+
const inside = selection.rangeCount && el.contains(selection.anchorNode);
|
|
319
|
+
return {
|
|
320
|
+
bold: inside && commandState('bold'),
|
|
321
|
+
italic: inside && commandState('italic'),
|
|
322
|
+
strike: inside && commandState('strikeThrough'),
|
|
323
|
+
ul: inside && Boolean(closest(selection.anchorNode, 'UL')),
|
|
324
|
+
ol: inside && Boolean(closest(selection.anchorNode, 'OL')),
|
|
325
|
+
code:
|
|
326
|
+
inside &&
|
|
327
|
+
Boolean(closest(selection.anchorNode, 'CODE') || closest(selection.anchorNode, 'PRE')),
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
bold() {
|
|
331
|
+
range();
|
|
332
|
+
if (!editor.state().code) command('bold');
|
|
333
|
+
},
|
|
334
|
+
italic() {
|
|
335
|
+
range();
|
|
336
|
+
if (!editor.state().code) command('italic');
|
|
337
|
+
},
|
|
338
|
+
strike() {
|
|
339
|
+
range();
|
|
340
|
+
if (!editor.state().code) command('strikeThrough');
|
|
341
|
+
},
|
|
342
|
+
/** 고른 문단을 목록으로 · 같은 목록이면 문단으로 · 다른 목록이면 종류만 바꿈 */
|
|
343
|
+
list(tag = 'ul') {
|
|
344
|
+
const at = range();
|
|
345
|
+
if (editor.state().code) return;
|
|
346
|
+
const first = topBlock(at.startContainer);
|
|
347
|
+
const last = topBlock(at.endContainer);
|
|
348
|
+
if (!first || !last) return;
|
|
349
|
+
const selection = getSelection();
|
|
350
|
+
const { anchorNode, anchorOffset, focusNode, focusOffset } = selection;
|
|
351
|
+
const isList = (n) => n.tagName === 'UL' || n.tagName === 'OL';
|
|
352
|
+
let caret;
|
|
353
|
+
if (isList(first) && first === last && first.tagName !== tag.toUpperCase()) {
|
|
354
|
+
const next = document.createElement(tag);
|
|
355
|
+
next.append(...first.childNodes);
|
|
356
|
+
first.replaceWith(next);
|
|
357
|
+
caret = next.lastElementChild;
|
|
358
|
+
} else if (isList(first) && first === last) {
|
|
359
|
+
const fragment = document.createDocumentFragment();
|
|
360
|
+
for (const li of first.children) {
|
|
361
|
+
const p = document.createElement('p');
|
|
362
|
+
p.append(...li.childNodes);
|
|
363
|
+
if (!p.childNodes.length) p.append(document.createElement('br'));
|
|
364
|
+
fragment.append(p);
|
|
365
|
+
caret = p;
|
|
366
|
+
}
|
|
367
|
+
first.replaceWith(fragment);
|
|
368
|
+
} else {
|
|
369
|
+
const nodes = [];
|
|
370
|
+
for (let n = first; n; n = n.nextSibling) {
|
|
371
|
+
nodes.push(n);
|
|
372
|
+
if (n === last) break;
|
|
373
|
+
}
|
|
374
|
+
const list = document.createElement(tag);
|
|
375
|
+
for (const n of nodes) {
|
|
376
|
+
if (isList(n)) list.append(...n.children);
|
|
377
|
+
else if (n.tagName === 'PRE') {
|
|
378
|
+
const li = document.createElement('li');
|
|
379
|
+
li.textContent = plainText(n);
|
|
380
|
+
list.append(li);
|
|
381
|
+
} else {
|
|
382
|
+
const li = document.createElement('li');
|
|
383
|
+
li.append(...n.childNodes);
|
|
384
|
+
if (!li.childNodes.length) li.append(document.createElement('br'));
|
|
385
|
+
list.append(li);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
first.before(list);
|
|
389
|
+
for (const n of nodes) n.remove();
|
|
390
|
+
caret = list.lastElementChild;
|
|
391
|
+
}
|
|
392
|
+
if (anchorNode && focusNode && el.contains(anchorNode) && el.contains(focusNode))
|
|
393
|
+
selection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
394
|
+
else if (caret) caretAt(caret, true);
|
|
395
|
+
tidy();
|
|
396
|
+
changed();
|
|
397
|
+
remember();
|
|
398
|
+
},
|
|
399
|
+
/** 코드: 코드 블록 안이면 풀고, 여러 문단을 골랐으면 코드 블록, 아니면 `코드` 켜고 끄기 (빈 커서면 sample을 넣음) */
|
|
400
|
+
code(sample) {
|
|
401
|
+
const at = range();
|
|
402
|
+
const pre = closest(at.startContainer, 'PRE');
|
|
403
|
+
if (pre) unwrapPre(pre);
|
|
404
|
+
else {
|
|
405
|
+
const first = topBlock(at.startContainer);
|
|
406
|
+
const last = topBlock(at.endContainer);
|
|
407
|
+
if (first && last && first !== last) wrapPre(first, last);
|
|
408
|
+
else {
|
|
409
|
+
const start = closest(at.startContainer, 'CODE');
|
|
410
|
+
const end = closest(at.endContainer, 'CODE');
|
|
411
|
+
if (start && (at.collapsed || start === end)) start.replaceWith(...start.childNodes);
|
|
412
|
+
else {
|
|
413
|
+
if (start) at.setStartBefore(start);
|
|
414
|
+
if (end) at.setEndAfter(end);
|
|
415
|
+
const code = document.createElement('code');
|
|
416
|
+
if (at.collapsed) code.textContent = sample;
|
|
417
|
+
else code.append(at.extractContents());
|
|
418
|
+
for (const inner of code.querySelectorAll('code, b, strong, i, em, s, del, strike'))
|
|
419
|
+
inner.replaceWith(...inner.childNodes);
|
|
420
|
+
at.insertNode(code);
|
|
421
|
+
const selection = getSelection();
|
|
422
|
+
selection.removeAllRanges();
|
|
423
|
+
const picked = document.createRange();
|
|
424
|
+
picked.selectNodeContents(code);
|
|
425
|
+
selection.addRange(picked);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
tidy();
|
|
430
|
+
changed();
|
|
431
|
+
remember();
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
// Enter로 새 문단을 <p>로 (브라우저 기본 <div> 대신)
|
|
435
|
+
command('defaultParagraphSeparator', false, 'p');
|
|
436
|
+
return editor;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** 한 줄을 차지하는 그림: 올린 그림 asset:파일키 · 옛 그림 image:아이디 */
|
|
440
|
+
const IMAGE_LINE =
|
|
441
|
+
/^!\[([^\]]*)\]\((image:[\w-]+|asset:assets\/[\w-]+\/[\w-]+\.(?:png|jpe?g|webp|gif))\)$/i;
|
|
442
|
+
/**
|
|
443
|
+
* 마크다운을 글 칸 · 그림 칸 차례로 나눈다 (한 줄을 차지하는 올린 그림  · 옛 만 그림 칸)
|
|
444
|
+
* @returns {({ type: 'text', text: string } | { type: 'image', alt: string, ref: string })[]}
|
|
445
|
+
*/
|
|
446
|
+
export function splitBlocks(source) {
|
|
447
|
+
const out = [];
|
|
448
|
+
let lines = [];
|
|
449
|
+
const flush = () => {
|
|
450
|
+
out.push({ type: 'text', text: lines.join('\n').replace(/^\n+|\n+$/g, '') });
|
|
451
|
+
lines = [];
|
|
452
|
+
};
|
|
453
|
+
for (const line of String(source ?? '').split('\n')) {
|
|
454
|
+
const image = IMAGE_LINE.exec(line.trim());
|
|
455
|
+
if (image) {
|
|
456
|
+
flush();
|
|
457
|
+
out.push({ type: 'image', alt: image[1], ref: image[2] });
|
|
458
|
+
} else lines.push(line);
|
|
459
|
+
}
|
|
460
|
+
flush();
|
|
461
|
+
return out;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** splitBlocks의 반대 (빈 글 칸은 뺀다) */
|
|
465
|
+
export const joinBlocks = (items) =>
|
|
466
|
+
items
|
|
467
|
+
.map((b) => (b.type === 'image' ? `` : b.text.replace(/^\n+|\n+$/g, '')))
|
|
468
|
+
.filter((s) => s !== '')
|
|
469
|
+
.join('\n\n');
|
package/templates/quiz/edit.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<!-- 제목 ·
|
|
6
|
+
<!-- 제목 · 불러오는 동안 화면 읽기 문구는 ui/texts.js(page)에서 고칩니다. #app 안은 스크립트가 돌기 전 자리로, ui/templates/page.js loading()과 같은 퀴즈 모양 (질문 막대 + 보기 막대 넷) -->
|
|
7
7
|
<title>내용 편집</title>
|
|
8
8
|
<link rel="stylesheet" href="lib/elice-tokens.css" />
|
|
9
9
|
<link rel="stylesheet" href="lib/elice-content.css" />
|
|
@@ -11,7 +11,16 @@
|
|
|
11
11
|
<link rel="stylesheet" href="styles.css" />
|
|
12
12
|
<script type="module" src="screens/edit.js"></script>
|
|
13
13
|
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<main id="app"
|
|
14
|
+
<body class="ec-edit-page">
|
|
15
|
+
<main id="app">
|
|
16
|
+
<div class="qz-skeleton" role="status">
|
|
17
|
+
<span class="ec-visually-hidden">불러오는 중…</span>
|
|
18
|
+
<span class="qz-sk qz-sk-title"></span>
|
|
19
|
+
<span class="qz-sk qz-sk-option"></span>
|
|
20
|
+
<span class="qz-sk qz-sk-option"></span>
|
|
21
|
+
<span class="qz-sk qz-sk-option"></span>
|
|
22
|
+
<span class="qz-sk qz-sk-option"></span>
|
|
23
|
+
</div>
|
|
24
|
+
</main>
|
|
16
25
|
</body>
|
|
17
26
|
</html>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<!-- 제목 ·
|
|
6
|
+
<!-- 제목 · 불러오는 동안 화면 읽기 문구는 ui/texts.js(page)에서 고칩니다. #app 안은 스크립트가 돌기 전 자리로, ui/templates/page.js loading()과 같은 퀴즈 모양 (질문 막대 + 보기 막대 넷) -->
|
|
7
7
|
<title>학생 화면</title>
|
|
8
8
|
<link rel="stylesheet" href="lib/elice-tokens.css" />
|
|
9
9
|
<link rel="stylesheet" href="lib/elice-content.css" />
|
|
@@ -11,7 +11,16 @@
|
|
|
11
11
|
<link rel="stylesheet" href="styles.css" />
|
|
12
12
|
<script type="module" src="screens/learn.js"></script>
|
|
13
13
|
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<main id="app"
|
|
14
|
+
<body class="qz-page">
|
|
15
|
+
<main id="app">
|
|
16
|
+
<div class="qz-skeleton" role="status">
|
|
17
|
+
<span class="ec-visually-hidden">불러오는 중…</span>
|
|
18
|
+
<span class="qz-sk qz-sk-title"></span>
|
|
19
|
+
<span class="qz-sk qz-sk-option"></span>
|
|
20
|
+
<span class="qz-sk qz-sk-option"></span>
|
|
21
|
+
<span class="qz-sk qz-sk-option"></span>
|
|
22
|
+
<span class="qz-sk qz-sk-option"></span>
|
|
23
|
+
</div>
|
|
24
|
+
</main>
|
|
16
25
|
</body>
|
|
17
26
|
</html>
|
|
Binary file
|