@eliceio/cdk-cli 1.6.1 → 1.7.0
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/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/commands/dev/index.d.ts +1 -1
- package/es/commands/dev/index.js +1 -1
- package/es/dev/host-page.js +19 -3
- package/es/dev/kv-public-mock.d.ts +101 -0
- package/es/dev/kv-public-mock.js +489 -0
- package/es/dev/mock-api.d.ts +28 -6
- package/es/dev/mock-api.js +57 -59
- package/es/dev/mock-http.d.ts +28 -0
- package/es/dev/mock-http.js +53 -0
- package/es/dev/server.js +8 -3
- package/package.json +2 -2
- package/templates/_shared/lib/cdk-mock.d.ts +37 -0
- package/templates/_shared/lib/cdk-mock.js +89 -1
- package/templates/_shared/lib/elice-content.d.ts +5 -0
- package/templates/_shared/lib/elice-content.js +7 -0
- package/templates/board/README.md +118 -0
- package/templates/board/commentary.txt +6 -0
- package/templates/board/core/board.d.ts +176 -0
- package/templates/board/core/board.js +732 -0
- package/templates/board/core/dom.d.ts +13 -0
- package/templates/board/core/dom.js +83 -0
- package/templates/board/core/model.d.ts +58 -0
- package/templates/board/core/model.js +217 -0
- package/templates/board/core/settings.d.ts +44 -0
- package/templates/board/core/settings.js +131 -0
- package/templates/board/edit.html +23 -0
- package/templates/board/gitignore +4 -0
- package/templates/board/index.html +22 -0
- package/templates/board/instructor.html +23 -0
- package/templates/board/metadata.json +9 -0
- package/templates/board/package.json +13 -0
- package/templates/board/screens/board.js +318 -0
- package/templates/board/screens/edit.js +631 -0
- package/templates/board/screens/instructor.js +16 -0
- package/templates/board/screens/learn.js +14 -0
- package/templates/board/template.json +14 -0
- package/templates/board/ui/background.css +8 -0
- package/templates/board/ui/board-bg.webp +0 -0
- package/templates/board/ui/board.css +1124 -0
- package/templates/board/ui/card.js +141 -0
- package/templates/board/ui/composer.js +329 -0
- package/templates/board/ui/dropdown.js +185 -0
- package/templates/board/ui/icons.js +36 -0
- package/templates/board/ui/learn.css +141 -0
- package/templates/board/ui/menu.js +104 -0
- package/templates/board/ui/texts.d.ts +3 -0
- package/templates/board/ui/texts.js +162 -0
|
@@ -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 도우미 (퀴즈 템플릿 core/dom.js와 같음). ui/templates/*는 html`…`로 마크업을 쓰고, 동작은 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 = 'bd-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
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// core/model.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
export type CardColor = 'white' | 'yellow' | 'pink' | 'green' | 'blue' | 'purple' | 'peach';
|
|
4
|
+
|
|
5
|
+
interface PostLike {
|
|
6
|
+
id: string;
|
|
7
|
+
text: string;
|
|
8
|
+
data: Record<string, unknown>;
|
|
9
|
+
pinned?: boolean;
|
|
10
|
+
author?: { isMe: boolean };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Card {
|
|
14
|
+
column: string;
|
|
15
|
+
/** 카드 맨 위 굵은 제목 (여러 줄), 없으면 '' */
|
|
16
|
+
title: string;
|
|
17
|
+
text: string;
|
|
18
|
+
url: string | null;
|
|
19
|
+
color: CardColor;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type BodyBlock =
|
|
23
|
+
| { type: 'p'; text: string }
|
|
24
|
+
| { type: 'ul'; items: string[] }
|
|
25
|
+
| { type: 'ol'; start: number; items: string[] };
|
|
26
|
+
|
|
27
|
+
export type AddBlocked = { reason: 'closed' | 'readOnly' | 'limit'; max?: number };
|
|
28
|
+
|
|
29
|
+
export const CARD_KIND: 'card';
|
|
30
|
+
export const COLORS: readonly CardColor[];
|
|
31
|
+
export const DEFAULT_COLOR: CardColor;
|
|
32
|
+
export const TEXT_MAX: number;
|
|
33
|
+
export const CARD_TITLE_MAX: number;
|
|
34
|
+
export const URL_MAX: number;
|
|
35
|
+
export const LIST_RE: RegExp;
|
|
36
|
+
export function pinnedFirst<T>(list: T[], pick?: (x: T) => { pinned?: boolean }): T[];
|
|
37
|
+
export function normalizeUrl(raw: unknown): string | null;
|
|
38
|
+
export function readCard(post: PostLike): Card | null;
|
|
39
|
+
export function cardValue(card: {
|
|
40
|
+
column: string;
|
|
41
|
+
title?: string;
|
|
42
|
+
text?: string;
|
|
43
|
+
url?: string;
|
|
44
|
+
color?: string;
|
|
45
|
+
}): { text: string; data: Record<string, unknown> } | null;
|
|
46
|
+
export function cardsByColumn<P extends PostLike>(
|
|
47
|
+
posts: P[],
|
|
48
|
+
columns: Array<{ id: string }>
|
|
49
|
+
): Record<string, Array<{ post: P; card: Card }>>;
|
|
50
|
+
export function myCardCount(posts: PostLike[]): number;
|
|
51
|
+
export function canAdd(view: any, limit: number | null): true | AddBlocked;
|
|
52
|
+
export function parseBody(text: string): BodyBlock[];
|
|
53
|
+
export function parseInline(text: string): Array<{ text: string; bold: boolean }>;
|
|
54
|
+
export function continueList(
|
|
55
|
+
value: string,
|
|
56
|
+
pos: number
|
|
57
|
+
): { insert: string } | { clear: number } | null;
|
|
58
|
+
export function errorKind(err: any): string;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// 보드 보기(core/board.js의 view)를 칸반 화면이 쓰는 모양으로. 화면 · SDK를 모르는 순수 함수만 둡니다 (테스트가 바로 부름).
|
|
2
|
+
//
|
|
3
|
+
// 카드는 보드 모델(core/board.js)이 쓴 사람 자신의 kv `public` 줄에 넣는 글(post)입니다. 화면이 정하는 값은 글의 `data`에:
|
|
4
|
+
// 텍스트 카드 text = 내용(없으면 제목), data { kind: 'card', column: 섹션 id, color, title? }
|
|
5
|
+
// 링크 카드 text = 내용(없으면 주소), data { kind: 'card', column, color, url, title? }
|
|
6
|
+
// title: 카드 맨 위 굵은 제목 (선택, 여러 줄, 100자). 없는 옛 카드는 제목 없이 보임
|
|
7
|
+
// 보드 모델의 글은 text가 비면 안 되므로 내용이 없으면 주소 · 제목을 text에 넣고, 읽을 때 text가 그것과 같으면 내용 없음으로 봅니다.
|
|
8
|
+
// 이 키를 바꾸면 이미 쓴 카드를 읽지 못합니다. kind가 card가 아닌 글(예전 자유 캔버스 노트 등)은 보이지 않습니다.
|
|
9
|
+
// 쓴 사람 이름 · 시각은 카드 값에 넣지도, 화면에 보이지도 않습니다. 내 카드인지(post.author.isMe)는 지우기 · 메뉴에만 씁니다.
|
|
10
|
+
// 하트는 보드 좋아요(like · unlike, post.likeCount · likedByMe)입니다. 저마다 자기 카드만 지웁니다 (교육자는 남의 카드를 숨김 · 고정만).
|
|
11
|
+
|
|
12
|
+
export const CARD_KIND = 'card';
|
|
13
|
+
/** 카드 색 (ui/board.css .bw-card[data-color]) */
|
|
14
|
+
export const COLORS = Object.freeze([
|
|
15
|
+
'white',
|
|
16
|
+
'yellow',
|
|
17
|
+
'pink',
|
|
18
|
+
'green',
|
|
19
|
+
'blue',
|
|
20
|
+
'purple',
|
|
21
|
+
'peach',
|
|
22
|
+
]);
|
|
23
|
+
export const DEFAULT_COLOR = 'white';
|
|
24
|
+
export const TEXT_MAX = 500;
|
|
25
|
+
/** 카드 제목 글자 수 상한 (여러 줄 가능) */
|
|
26
|
+
export const CARD_TITLE_MAX = 100;
|
|
27
|
+
export const URL_MAX = 2000;
|
|
28
|
+
|
|
29
|
+
const colorValue = c => (COLORS.includes(c) ? c : DEFAULT_COLOR);
|
|
30
|
+
|
|
31
|
+
/** 고정한 것 먼저, 그다음 SDK가 준 순서(오래된 것부터) 그대로 */
|
|
32
|
+
export function pinnedFirst(list, pick = x => x) {
|
|
33
|
+
return list
|
|
34
|
+
.map((x, i) => ({ x, i }))
|
|
35
|
+
.sort(
|
|
36
|
+
(a, b) => Number(pick(b.x).pinned === true) - Number(pick(a.x).pinned === true) || a.i - b.i
|
|
37
|
+
)
|
|
38
|
+
.map(e => e.x);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 링크 주소 정리: 앞뒤 공백을 자르고, 앞에 http(s)://가 없으면 https://를 붙인다. http · https만 (javascript: 등은 null)
|
|
43
|
+
* @param {unknown} raw
|
|
44
|
+
*/
|
|
45
|
+
export function normalizeUrl(raw) {
|
|
46
|
+
if (typeof raw !== 'string') return null;
|
|
47
|
+
let s = raw.trim();
|
|
48
|
+
if (!s || s.length > URL_MAX || /\s/.test(s)) return null;
|
|
49
|
+
if (!/^[a-z][a-z0-9+.-]*:/i.test(s)) s = `https://${s}`;
|
|
50
|
+
try {
|
|
51
|
+
const u = new URL(s);
|
|
52
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:') return null;
|
|
53
|
+
if (!u.hostname.includes('.') && u.hostname !== 'localhost') return null;
|
|
54
|
+
return u.href;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 제목 정리: 줄바꿈은 \n으로, 앞뒤 공백을 자름. 문자열이 아니면 '' */
|
|
61
|
+
function cleanTitle(raw) {
|
|
62
|
+
return typeof raw === 'string' ? raw.replace(/\r\n?/g, '\n').trim() : '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 카드 읽기: 카드가 아니거나 틀린 값이면 null. 제목은 없으면 ''(옛 카드).
|
|
67
|
+
* 내용이 주소(링크 카드) · 제목(제목만 있는 카드)과 같으면 내용은 ''
|
|
68
|
+
*/
|
|
69
|
+
export function readCard(post) {
|
|
70
|
+
const d = post?.data;
|
|
71
|
+
if (d?.kind !== CARD_KIND || typeof d.column !== 'string') return null;
|
|
72
|
+
const url = d.url === undefined ? null : normalizeUrl(d.url);
|
|
73
|
+
if (d.url !== undefined && !url) return null;
|
|
74
|
+
const title = [...cleanTitle(d.title)].slice(0, CARD_TITLE_MAX).join('');
|
|
75
|
+
const raw = String(post.text ?? '').slice(0, TEXT_MAX);
|
|
76
|
+
return {
|
|
77
|
+
column: d.column,
|
|
78
|
+
title,
|
|
79
|
+
text: (url && raw === url) || (title && raw === title) ? '' : raw,
|
|
80
|
+
url,
|
|
81
|
+
color: colorValue(d.color),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 새 카드 { text, data }. 제목 · 내용 · 링크 중 하나는 있어야 하고, 링크는 http(s)여야 한다. 틀리면 null
|
|
87
|
+
* (제목은 여러 줄, CARD_TITLE_MAX자까지)
|
|
88
|
+
* @param {{ column: string, title?: string, text?: string, url?: string, color?: string }} card
|
|
89
|
+
*/
|
|
90
|
+
export function cardValue({ column, title, text, url, color }) {
|
|
91
|
+
const t = String(text ?? '').trim();
|
|
92
|
+
const h = cleanTitle(title ?? '');
|
|
93
|
+
if (t.length > TEXT_MAX || [...h].length > CARD_TITLE_MAX) return null;
|
|
94
|
+
const data = { kind: CARD_KIND, column, color: colorValue(color), ...(h ? { title: h } : {}) };
|
|
95
|
+
const rawUrl = String(url ?? '').trim();
|
|
96
|
+
if (rawUrl) {
|
|
97
|
+
const u = normalizeUrl(rawUrl);
|
|
98
|
+
if (!u) return null;
|
|
99
|
+
return { text: t || u, data: { ...data, url: u } };
|
|
100
|
+
}
|
|
101
|
+
if (!t && !h) return null;
|
|
102
|
+
return { text: t || h, data };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 섹션마다 카드 { 섹션 id: [{ post, card }] } (고정 먼저, 그다음 오래된 것부터). 지금 없는 섹션의 카드는 보이지 않는다
|
|
107
|
+
* @param {Array<{ data: Record<string, unknown>, pinned?: boolean }>} posts
|
|
108
|
+
* @param {Array<{ id: string }>} columns
|
|
109
|
+
*/
|
|
110
|
+
export function cardsByColumn(posts, columns) {
|
|
111
|
+
const out = Object.fromEntries(columns.map(c => [c.id, []]));
|
|
112
|
+
for (const post of posts) {
|
|
113
|
+
const card = readCard(post);
|
|
114
|
+
if (card && card.column in out) out[card.column].push({ post, card });
|
|
115
|
+
}
|
|
116
|
+
for (const id of Object.keys(out)) out[id] = pinnedFirst(out[id], e => e.post);
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 내가 쓴 카드 수 (보이는 것만: 숨긴 내 카드는 안 셈) */
|
|
121
|
+
export function myCardCount(posts) {
|
|
122
|
+
return posts.filter(p => p.author?.isMe && p.data?.kind === CARD_KIND).length;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 더 쓸 수 있는지: 보드가 받는지(canWrite) · 1인당 한도(화면 수준, 교육자는 없음).
|
|
127
|
+
* 쓸 수 있으면 true, 아니면 이유 { reason: 'closed' | 'readOnly' | 'limit', max? }
|
|
128
|
+
* @param {{ canWrite: boolean, canModerate: boolean, closed: boolean, posts: any[] }} view
|
|
129
|
+
* @param {number | null} limit settings.board.post_limit
|
|
130
|
+
*/
|
|
131
|
+
export function canAdd(view, limit) {
|
|
132
|
+
if (!view?.canWrite) return { reason: view?.closed ? 'closed' : 'readOnly' };
|
|
133
|
+
if (view.canModerate || limit == null) return true;
|
|
134
|
+
return myCardCount(view.posts) >= limit ? { reason: 'limit', max: limit } : true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 카드 내용의 간단한 마크다운 목록 줄: 들여쓰기 · 표시(- * • 1.) · 나머지 */
|
|
138
|
+
export const LIST_RE = /^(\s*)([-*•]|\d+\.)\s(.*)$/;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 카드 내용을 블록으로: 문단 { type: 'p', text } · 목록 { type: 'ul' | 'ol', start?, items: string[] }. 빈 줄은 뺀다
|
|
142
|
+
* @param {string} text
|
|
143
|
+
*/
|
|
144
|
+
export function parseBody(text) {
|
|
145
|
+
const blocks = [];
|
|
146
|
+
let list = null;
|
|
147
|
+
for (const raw of String(text ?? '').split('\n')) {
|
|
148
|
+
const m = LIST_RE.exec(raw);
|
|
149
|
+
if (m) {
|
|
150
|
+
const type = /\d/.test(m[2]) ? 'ol' : 'ul';
|
|
151
|
+
if (!list || list.type !== type) {
|
|
152
|
+
list = { type, items: [], ...(type === 'ol' ? { start: parseInt(m[2], 10) } : {}) };
|
|
153
|
+
blocks.push(list);
|
|
154
|
+
}
|
|
155
|
+
list.items.push(m[3]);
|
|
156
|
+
} else {
|
|
157
|
+
list = null;
|
|
158
|
+
if (raw.trim()) blocks.push({ type: 'p', text: raw });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return blocks;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** 한 줄 안의 **굵게**: [{ text, bold }] */
|
|
165
|
+
export function parseInline(text) {
|
|
166
|
+
return String(text ?? '')
|
|
167
|
+
.split(/(\*\*[^*\n]+\*\*)/)
|
|
168
|
+
.filter(Boolean)
|
|
169
|
+
.map(part =>
|
|
170
|
+
/^\*\*[^*\n]+\*\*$/.test(part)
|
|
171
|
+
? { text: part.slice(2, -2), bold: true }
|
|
172
|
+
: { text: part, bold: false }
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 목록 이어쓰기: 커서 앞 줄이 목록이면 Enter에 넣을 것. 다음 항목 표시를 넣거나({ insert }), 빈 항목이면 줄을 비움({ clear: 줄 시작 })
|
|
178
|
+
* 목록 줄이 아니면 null
|
|
179
|
+
* @param {string} value 입력 칸 전체 글
|
|
180
|
+
* @param {number} pos 커서 자리
|
|
181
|
+
*/
|
|
182
|
+
export function continueList(value, pos) {
|
|
183
|
+
const start = value.lastIndexOf('\n', pos - 1) + 1;
|
|
184
|
+
const m = LIST_RE.exec(value.slice(start, pos));
|
|
185
|
+
if (!m) return null;
|
|
186
|
+
const [, indent, mark, rest] = m;
|
|
187
|
+
if (!rest.trim()) return { clear: start };
|
|
188
|
+
const next = /\d/.test(mark) ? `${parseInt(mark, 10) + 1}.` : mark;
|
|
189
|
+
return { insert: `\n${indent}${next} ` };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 보드 · SDK 오류를 화면 문구 키로: closed · tooLarge · readOnly · rateLimited · invalid · permission · session · failed
|
|
194
|
+
* @param {any} err BoardError(core/board.js) · EliceCDKError
|
|
195
|
+
*/
|
|
196
|
+
export function errorKind(err) {
|
|
197
|
+
switch (err?.code) {
|
|
198
|
+
case 'board.closed':
|
|
199
|
+
return 'closed';
|
|
200
|
+
case 'board.too_large':
|
|
201
|
+
return 'tooLarge';
|
|
202
|
+
case 'read_only_mode':
|
|
203
|
+
return 'readOnly';
|
|
204
|
+
case 'rate_limited':
|
|
205
|
+
return 'rateLimited';
|
|
206
|
+
case 'invalid_input':
|
|
207
|
+
case 'invalid_param':
|
|
208
|
+
return 'invalid';
|
|
209
|
+
case 'permission_denied':
|
|
210
|
+
return 'permission';
|
|
211
|
+
case 'session_expired':
|
|
212
|
+
case 'unauthorized':
|
|
213
|
+
return 'session';
|
|
214
|
+
default:
|
|
215
|
+
return 'failed';
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// core/settings.js 타입 (편집기 자동완성 · 테스트용)
|
|
2
|
+
export interface BoardColumn {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface BoardDraft {
|
|
8
|
+
rest: Record<string, unknown>;
|
|
9
|
+
boardRest: Record<string, unknown>;
|
|
10
|
+
title: string;
|
|
11
|
+
description: string;
|
|
12
|
+
columns: BoardColumn[];
|
|
13
|
+
reactions: boolean;
|
|
14
|
+
bodyPlaceholder: string;
|
|
15
|
+
board: { requireApproval: boolean; postLimit: number | null };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SettingsLabels {
|
|
19
|
+
columnTitle: (n: number) => string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SettingsMessages {
|
|
23
|
+
titleRequired: string;
|
|
24
|
+
columnRequired: string;
|
|
25
|
+
columnTitle: (n: number) => string;
|
|
26
|
+
limitRange: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const MAX_COLUMNS: number;
|
|
30
|
+
export const NAME_MAX: number;
|
|
31
|
+
export const TITLE_MAX: number;
|
|
32
|
+
export const DESCRIPTION_MAX: number;
|
|
33
|
+
export const PLACEHOLDER_MAX: number;
|
|
34
|
+
export const DEFAULT_POST_LIMIT: number;
|
|
35
|
+
export const LIMIT_MIN: number;
|
|
36
|
+
export const LIMIT_MAX: number;
|
|
37
|
+
export function newId(existing?: Array<{ id: string }>): string;
|
|
38
|
+
export function normalizeSettings(raw: unknown, labels?: SettingsLabels): BoardDraft;
|
|
39
|
+
export function toSettings(draft: BoardDraft): Record<string, unknown>;
|
|
40
|
+
export function validateSettings(
|
|
41
|
+
draft: BoardDraft,
|
|
42
|
+
messages: SettingsMessages,
|
|
43
|
+
options?: { requireTitle?: boolean }
|
|
44
|
+
): true | string;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// 저장 모양(settings)과 검증. 편집 화면이 저장하고 학생 · 교육자 화면이 읽습니다. 키 이름을 바꾸면 저장한 자료를 읽지 못합니다.
|
|
2
|
+
//
|
|
3
|
+
// {
|
|
4
|
+
// title: '우리 반 생각 모으기',
|
|
5
|
+
// description: '…', // 선택
|
|
6
|
+
// columns: [{ id: 'c1', title: '섹션 1' }, …], // 칸반 섹션 (카드가 data.column으로 가리킴)
|
|
7
|
+
// reactions: false, // 선택. 하트를 끔 (없으면 켜짐)
|
|
8
|
+
// bodyPlaceholder: '오늘 배운 것을 적어 보세요', // 선택. 카드 내용 칸에 보일 문구
|
|
9
|
+
// board: { // 보드 설정 (보드 모델 core/board.js가 require_approval을 읽음)
|
|
10
|
+
// require_approval: false, // 학생 카드는 교육자가 승인해야 다른 학생에게 보임 (화면 수준)
|
|
11
|
+
// post_limit: 20, // 선택. 1인당 카드 수 (화면 수준, 없으면 50)
|
|
12
|
+
// },
|
|
13
|
+
// }
|
|
14
|
+
// id는 처음 한 번 만들고 바꾸지 않습니다: 카드가 id로 섹션을 가리키므로 이름만 바뀝니다.
|
|
15
|
+
// 그 밖의 키(예: 예전 보드의 views · groups · topics, 예전 board의 이름 공개 값, AI · MCP가 넣은 값)는 저장 때 그대로 둡니다.
|
|
16
|
+
// 학생에게도 내려가므로 비밀 값을 넣지 않습니다.
|
|
17
|
+
|
|
18
|
+
/** 섹션 수 상한 (화면 폭) */
|
|
19
|
+
export const MAX_COLUMNS = 8;
|
|
20
|
+
/** 섹션 이름 · 제목 · 안내 · 내용 칸 문구 글자 수 상한 */
|
|
21
|
+
export const NAME_MAX = 20;
|
|
22
|
+
export const TITLE_MAX = 80;
|
|
23
|
+
export const DESCRIPTION_MAX = 500;
|
|
24
|
+
export const PLACEHOLDER_MAX = 60;
|
|
25
|
+
/** 1인당 카드 수 범위 · 정하지 않았을 때 (비우면 50) */
|
|
26
|
+
export const DEFAULT_POST_LIMIT = 50;
|
|
27
|
+
export const LIMIT_MIN = 1;
|
|
28
|
+
export const LIMIT_MAX = 200;
|
|
29
|
+
/** 섹션 id (카드 data에 그대로 들어감) */
|
|
30
|
+
const ID_PATTERN = /^[A-Za-z0-9_-]{1,32}$/;
|
|
31
|
+
const KNOWN = ['title', 'description', 'columns', 'reactions', 'bodyPlaceholder', 'board'];
|
|
32
|
+
const BOARD_KNOWN = ['require_approval', 'post_limit'];
|
|
33
|
+
|
|
34
|
+
/** 기본 섹션 이름 (화면 문구, ui/texts.js가 넘김) */
|
|
35
|
+
const DEFAULT_LABELS = { columnTitle: n => `섹션 ${n}` };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 새 섹션 id: 'c' + 무작위 8자. 이미 있는 id와 겹치지 않게
|
|
39
|
+
* @param {Array<{ id: string }>} existing
|
|
40
|
+
*/
|
|
41
|
+
export function newId(existing = []) {
|
|
42
|
+
const taken = new Set(existing.map(e => e.id));
|
|
43
|
+
for (;;) {
|
|
44
|
+
const id = `c${Math.random().toString(36).slice(2, 10).padEnd(8, '0')}`;
|
|
45
|
+
if (!taken.has(id)) return id;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const isObject = v => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
50
|
+
const str = (v, max) => (typeof v === 'string' ? v.slice(0, max) : '');
|
|
51
|
+
|
|
52
|
+
/** 섹션 목록 읽기: id가 틀리거나 겹치면 뺀다. 비면 기본 섹션 하나 */
|
|
53
|
+
function readColumns(raw, columnTitle) {
|
|
54
|
+
const out = [];
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
for (const e of Array.isArray(raw) ? raw : []) {
|
|
57
|
+
if (!isObject(e) || typeof e.id !== 'string' || !ID_PATTERN.test(e.id) || seen.has(e.id))
|
|
58
|
+
continue;
|
|
59
|
+
seen.add(e.id);
|
|
60
|
+
out.push({ id: e.id, title: str(e.title, NAME_MAX) });
|
|
61
|
+
if (out.length >= MAX_COLUMNS) break;
|
|
62
|
+
}
|
|
63
|
+
return out.length ? out : [{ id: 'c1', title: columnTitle(1) }];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 1인당 카드 수: 범위 안 정수면 그 수, 아니면 null (한도 없음) */
|
|
67
|
+
function readLimit(v) {
|
|
68
|
+
return Number.isInteger(v) && v >= LIMIT_MIN && v <= LIMIT_MAX ? v : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 저장된 settings를 화면이 쓰는 모양으로. 모르는 값은 기본값.
|
|
73
|
+
* @param {Record<string, unknown> | null | undefined} raw
|
|
74
|
+
* @param {{ columnTitle: (n: number) => string }} [labels] 기본 이름
|
|
75
|
+
*/
|
|
76
|
+
export function normalizeSettings(raw, labels = DEFAULT_LABELS) {
|
|
77
|
+
const s = isObject(raw) ? raw : {};
|
|
78
|
+
const board = isObject(s.board) ? s.board : {};
|
|
79
|
+
return {
|
|
80
|
+
/** 저장 때 그대로 둘 다른 키 */
|
|
81
|
+
rest: Object.fromEntries(Object.entries(s).filter(([k]) => !KNOWN.includes(k))),
|
|
82
|
+
/** board 안의 모르는 키 (그대로 둠) */
|
|
83
|
+
boardRest: Object.fromEntries(Object.entries(board).filter(([k]) => !BOARD_KNOWN.includes(k))),
|
|
84
|
+
title: str(s.title, TITLE_MAX),
|
|
85
|
+
description: str(s.description, DESCRIPTION_MAX),
|
|
86
|
+
columns: readColumns(s.columns, labels.columnTitle ?? DEFAULT_LABELS.columnTitle),
|
|
87
|
+
reactions: s.reactions !== false,
|
|
88
|
+
bodyPlaceholder: str(s.bodyPlaceholder, PLACEHOLDER_MAX).trim(),
|
|
89
|
+
board: {
|
|
90
|
+
requireApproval: board.require_approval === true,
|
|
91
|
+
postLimit: readLimit(board.post_limit),
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 화면 상태를 저장 모양으로 (이름 앞뒤 공백을 자르고, 기본값인 선택 키는 넣지 않음) */
|
|
97
|
+
export function toSettings(draft) {
|
|
98
|
+
const placeholder = draft.bodyPlaceholder.trim();
|
|
99
|
+
return {
|
|
100
|
+
...draft.rest,
|
|
101
|
+
title: draft.title.trim(),
|
|
102
|
+
...(draft.description.trim() ? { description: draft.description.trim() } : {}),
|
|
103
|
+
columns: draft.columns.map(c => ({ id: c.id, title: c.title.trim() })),
|
|
104
|
+
...(draft.reactions ? {} : { reactions: false }),
|
|
105
|
+
...(placeholder ? { bodyPlaceholder: placeholder } : {}),
|
|
106
|
+
board: {
|
|
107
|
+
...draft.boardRest,
|
|
108
|
+
require_approval: draft.board.requireApproval,
|
|
109
|
+
...(draft.board.postLimit != null ? { post_limit: draft.board.postLimit } : {}),
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 저장 전 검증. 통과면 true, 아니면 화면에 보일 문구
|
|
116
|
+
* @param {ReturnType<typeof normalizeSettings>} draft
|
|
117
|
+
* @param {{ titleRequired: string, columnRequired: string, columnTitle: (n: number) => string,
|
|
118
|
+
* limitRange: string }} messages
|
|
119
|
+
* @param {{ requireTitle?: boolean }} [options] requireTitle: false면 보드 제목이 비어도 통과
|
|
120
|
+
* (편집 화면에서 카드를 올리며 함께 저장할 때. 보드 제목은 '초안으로 저장'에서만 요구)
|
|
121
|
+
*/
|
|
122
|
+
export function validateSettings(draft, messages, { requireTitle = true } = {}) {
|
|
123
|
+
if (requireTitle && !draft.title.trim()) return messages.titleRequired;
|
|
124
|
+
if (!draft.columns?.length) return messages.columnRequired;
|
|
125
|
+
const i = draft.columns.findIndex(c => !c.title.trim());
|
|
126
|
+
if (i >= 0) return messages.columnTitle(i + 1);
|
|
127
|
+
const n = draft.board?.postLimit;
|
|
128
|
+
if (n != null && !(Number.isInteger(n) && n >= LIMIT_MIN && n <= LIMIT_MAX))
|
|
129
|
+
return messages.limitRange;
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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/background.css" />
|
|
11
|
+
<link rel="stylesheet" href="ui/board.css" />
|
|
12
|
+
<script type="module" src="screens/edit.js"></script>
|
|
13
|
+
</head>
|
|
14
|
+
<body class="ec-edit-page">
|
|
15
|
+
<main id="app">
|
|
16
|
+
<div class="ec-sk ec-sk-edit" role="status">
|
|
17
|
+
<span class="ec-visually-hidden">불러오는 중…</span>
|
|
18
|
+
<div class="ec-sk-bar ec-sk-shimmer"></div>
|
|
19
|
+
<div class="ec-sk-media ec-sk-shimmer"></div>
|
|
20
|
+
</div>
|
|
21
|
+
</main>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
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/background.css" />
|
|
11
|
+
<link rel="stylesheet" href="ui/board.css" />
|
|
12
|
+
<link rel="stylesheet" href="ui/learn.css" />
|
|
13
|
+
<script type="module" src="screens/learn.js"></script>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<main id="app">
|
|
17
|
+
<div class="ec-sk ec-sk-learn ec-sk-shimmer" role="status">
|
|
18
|
+
<span class="ec-visually-hidden">불러오는 중…</span>
|
|
19
|
+
</div>
|
|
20
|
+
</main>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
<!-- 교육자 화면: 학생 화면과 같은 칸반에 승인 · 숨기기 · 고정 · 보드 닫기를 더합니다 (screens/instructor.js).
|
|
7
|
+
제목 · "불러오는 중" 문구는 ui/texts.js(page)에서 고칩니다. 여기 글은 스크립트가 돌기 전에만 보입니다 -->
|
|
8
|
+
<title>교육자 화면</title>
|
|
9
|
+
<link rel="stylesheet" href="lib/elice-tokens.css" />
|
|
10
|
+
<link rel="stylesheet" href="lib/elice-content.css" />
|
|
11
|
+
<link rel="stylesheet" href="ui/background.css" />
|
|
12
|
+
<link rel="stylesheet" href="ui/board.css" />
|
|
13
|
+
<link rel="stylesheet" href="ui/learn.css" />
|
|
14
|
+
<script type="module" src="screens/instructor.js"></script>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<main id="app">
|
|
18
|
+
<div class="ec-sk ec-sk-learn ec-sk-shimmer" role="status">
|
|
19
|
+
<span class="ec-visually-hidden">불러오는 중…</span>
|
|
20
|
+
</div>
|
|
21
|
+
</main>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|