@eliceio/cdk-cli 1.6.0 → 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/core/quiz-check.js +5 -5
- 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 +8 -7
- package/skills/_shared/references/02-design-the-material.md +1 -1
- package/skills/_shared/references/06-using-the-quiz-template.md +1 -0
- 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
- package/templates/quiz/README.md +16 -6
- package/templates/quiz/core/draft.d.ts +32 -0
- package/templates/quiz/core/draft.js +224 -0
- package/templates/quiz/core/model.d.ts +5 -8
- package/templates/quiz/core/model.js +11 -13
- package/templates/quiz/screens/edit.js +8 -18
- package/templates/quiz/screens/learn.js +62 -13
- package/templates/quiz/styles.css +3 -6
- package/templates/quiz/template.json +1 -1
- package/templates/quiz/ui/templates/page.js +1 -14
- package/templates/quiz/ui/texts.js +1 -5
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// 카드 한 장 (학생 · 교육자 화면, 편집 화면 미리보기가 같이 씀). 맨 위에 굵은 제목(선택, 여러 줄), 쓴 사람 이름 · 시각은 없음.
|
|
2
|
+
// 동작은 화면이 data-role로 찾아 붙입니다:
|
|
3
|
+
// heart(하트) · card-x(내 카드 지우기) · menu-btn(교육자 ⋯ 메뉴)
|
|
4
|
+
import { html } from '../core/dom.js';
|
|
5
|
+
import { parseBody, parseInline } from '../core/model.js';
|
|
6
|
+
import { icon } from './icons.js';
|
|
7
|
+
import { texts } from './texts.js';
|
|
8
|
+
|
|
9
|
+
const t = texts.board;
|
|
10
|
+
|
|
11
|
+
/** 한 줄 안의 **굵게** */
|
|
12
|
+
function inline(text) {
|
|
13
|
+
const frag = document.createDocumentFragment();
|
|
14
|
+
for (const p of parseInline(text)) {
|
|
15
|
+
if (p.bold) {
|
|
16
|
+
const b = document.createElement('strong');
|
|
17
|
+
b.textContent = p.text;
|
|
18
|
+
frag.append(b);
|
|
19
|
+
} else frag.append(p.text);
|
|
20
|
+
}
|
|
21
|
+
return frag;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 카드 내용: 문단 · 목록(- * 1.) · **굵게** */
|
|
25
|
+
export function cardBody(text) {
|
|
26
|
+
const wrap = document.createElement('div');
|
|
27
|
+
wrap.className = 'bw-card-p';
|
|
28
|
+
for (const b of parseBody(text)) {
|
|
29
|
+
if (b.type === 'p') {
|
|
30
|
+
const p = document.createElement('p');
|
|
31
|
+
p.append(inline(b.text));
|
|
32
|
+
wrap.append(p);
|
|
33
|
+
} else {
|
|
34
|
+
const list = document.createElement(b.type);
|
|
35
|
+
if (b.type === 'ol') list.start = b.start;
|
|
36
|
+
for (const item of b.items) {
|
|
37
|
+
const li = document.createElement('li');
|
|
38
|
+
li.append(inline(item));
|
|
39
|
+
list.append(li);
|
|
40
|
+
}
|
|
41
|
+
wrap.append(list);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return wrap;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {{
|
|
49
|
+
* id: string, title?: string, text: string, url: string | null, color: string,
|
|
50
|
+
* pending?: boolean, hidden?: boolean, pinned?: boolean,
|
|
51
|
+
* canDelete?: boolean, menu?: boolean,
|
|
52
|
+
* heart?: { on: boolean, count: number, disabled: boolean } | null,
|
|
53
|
+
* }} c
|
|
54
|
+
*/
|
|
55
|
+
export function cardView(c) {
|
|
56
|
+
const badges = [
|
|
57
|
+
c.pinned && html`<span class="bw-badge is-pin">${icon('pin', 12)}${t.pinned}</span>`,
|
|
58
|
+
c.pending && html`<span class="bw-badge is-pending">${t.pending}</span>`,
|
|
59
|
+
c.hidden && html`<span class="bw-badge is-hidden">${icon('eyeOff', 12)}${t.hidden}</span>`,
|
|
60
|
+
].filter(Boolean);
|
|
61
|
+
const el = html`<article class="bw-card" data-color="${c.color}" data-id="${c.id}">
|
|
62
|
+
${c.menu
|
|
63
|
+
? html`<button
|
|
64
|
+
type="button"
|
|
65
|
+
class="bw-icon bw-card-x bw-card-menu"
|
|
66
|
+
data-role="menu-btn"
|
|
67
|
+
data-key="${`menu:${c.id}`}"
|
|
68
|
+
aria-haspopup="menu"
|
|
69
|
+
aria-expanded="false"
|
|
70
|
+
aria-label="${t.cardMenu}"
|
|
71
|
+
>
|
|
72
|
+
${icon('dots', 16)}
|
|
73
|
+
</button>`
|
|
74
|
+
: c.canDelete
|
|
75
|
+
? html`<button
|
|
76
|
+
type="button"
|
|
77
|
+
class="bw-icon bw-card-x"
|
|
78
|
+
data-role="card-x"
|
|
79
|
+
data-key="${`del:${c.id}`}"
|
|
80
|
+
aria-label="${t.deleteCard}"
|
|
81
|
+
>
|
|
82
|
+
${icon('x', 14)}
|
|
83
|
+
</button>`
|
|
84
|
+
: null}
|
|
85
|
+
${c.title ? html`<h3 class="bw-card-title">${c.title}</h3>` : null}
|
|
86
|
+
${badges.length ? html`<div class="bw-badges">${badges}</div>` : null}
|
|
87
|
+
${c.text ? cardBody(c.text) : null}
|
|
88
|
+
${c.url
|
|
89
|
+
? html`<a class="bw-card-link" href="${c.url}" target="_blank" rel="noopener noreferrer"
|
|
90
|
+
>${icon('link', 14)}<span>${c.url}</span></a
|
|
91
|
+
>`
|
|
92
|
+
: null}
|
|
93
|
+
${c.heart
|
|
94
|
+
? html`<div class="bw-card-react">
|
|
95
|
+
<button
|
|
96
|
+
type="button"
|
|
97
|
+
class="${c.heart.on ? 'bw-heart is-on' : 'bw-heart'}"
|
|
98
|
+
data-role="heart"
|
|
99
|
+
data-key="${`heart:${c.id}`}"
|
|
100
|
+
aria-pressed="${String(c.heart.on)}"
|
|
101
|
+
aria-label="${c.heart.on ? t.heartOff : t.heartOn}"
|
|
102
|
+
>
|
|
103
|
+
${icon('heart', 18)}${c.heart.count
|
|
104
|
+
? html`<span>${String(c.heart.count)}</span>`
|
|
105
|
+
: null}
|
|
106
|
+
</button>
|
|
107
|
+
</div>`
|
|
108
|
+
: null}
|
|
109
|
+
</article>`;
|
|
110
|
+
if (c.hidden) el.classList.add('is-hidden');
|
|
111
|
+
if (c.pinned) el.classList.add('is-pinned');
|
|
112
|
+
const heart = el.querySelector('[data-role="heart"]');
|
|
113
|
+
if (heart && c.heart?.disabled) heart.disabled = true;
|
|
114
|
+
return el;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 지우기 버튼을 두 번 누름으로: 처음 누르면 "삭제"로 바뀌고 3초 안에 다시 누르면 onConfirm (confirm()은 샌드박스에서 막힘)
|
|
119
|
+
* @param {HTMLButtonElement} x
|
|
120
|
+
* @param {() => void} onConfirm
|
|
121
|
+
*/
|
|
122
|
+
export function confirmTwice(x, onConfirm) {
|
|
123
|
+
x.addEventListener('click', () => {
|
|
124
|
+
if (!x.classList.contains('is-confirm')) {
|
|
125
|
+
x.classList.add('is-confirm');
|
|
126
|
+
x.textContent = t.confirmDelete;
|
|
127
|
+
x.setAttribute('aria-label', t.confirmDeleteLabel);
|
|
128
|
+
setTimeout(
|
|
129
|
+
() => {
|
|
130
|
+
if (!x.isConnected || x.disabled) return;
|
|
131
|
+
x.classList.remove('is-confirm');
|
|
132
|
+
x.replaceChildren(icon('x', 14));
|
|
133
|
+
x.setAttribute('aria-label', t.deleteCard);
|
|
134
|
+
},
|
|
135
|
+
3000
|
|
136
|
+
);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
onConfirm();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// 카드 추가 창 (학생 · 교육자 · 편집 화면). 섹션 · 제목(선택, 여러 줄) · 내용(목록 이어쓰기) · 색 · 링크.
|
|
2
|
+
// 폼 제출은 샌드박스(allow-forms 없음)에서 막히므로 form · submit 이벤트를 쓰지 않고 버튼 · 키로 보낸다.
|
|
3
|
+
import { html, part } from '../core/dom.js';
|
|
4
|
+
import {
|
|
5
|
+
CARD_TITLE_MAX,
|
|
6
|
+
cardValue,
|
|
7
|
+
COLORS,
|
|
8
|
+
continueList,
|
|
9
|
+
DEFAULT_COLOR,
|
|
10
|
+
TEXT_MAX,
|
|
11
|
+
} from '../core/model.js';
|
|
12
|
+
import { closeAllDropdowns, dropdown } from './dropdown.js';
|
|
13
|
+
import { texts } from './texts.js';
|
|
14
|
+
|
|
15
|
+
const t = texts.composer;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {{
|
|
19
|
+
* columns: () => Array<{ id: string, title: string }>,
|
|
20
|
+
* placeholder: () => string,
|
|
21
|
+
* preview?: boolean | ((column: string) => string),
|
|
22
|
+
* onSubmit: (value: { text: string, data: Record<string, unknown> }) => Promise<string | void>,
|
|
23
|
+
* }} options preview: 편집 화면(카드는 바로 보드에 저장된다는 안내를 보임). 함수면 고른 섹션에 맞는 안내 문구를
|
|
24
|
+
* 돌려준다 (섹션을 바꿀 때마다 다시 물음).
|
|
25
|
+
* onSubmit은 실패 문구를 돌려주면 창에 보이고 창이 열린 채로 남는다
|
|
26
|
+
*/
|
|
27
|
+
export function createComposer({ columns, placeholder, preview = false, onSubmit }) {
|
|
28
|
+
const modal = html`<div class="bw-modal" data-role="modal" inert>
|
|
29
|
+
<div class="bw-scrim" data-role="scrim"></div>
|
|
30
|
+
<div class="bw-dlg" role="dialog" aria-modal="true" aria-labelledby="bw-dlg-t" data-role="dlg">
|
|
31
|
+
<h2 id="bw-dlg-t">${t.title}</h2>
|
|
32
|
+
<div class="bw-fld bw-fld-inline">
|
|
33
|
+
<label id="bw-c-lab">${t.section}</label>
|
|
34
|
+
<div data-role="column"></div>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="bw-fld">
|
|
37
|
+
<label for="bw-c-title">${t.cardTitle}</label>
|
|
38
|
+
<textarea
|
|
39
|
+
id="bw-c-title"
|
|
40
|
+
class="bw-field bw-ta bw-ta-title"
|
|
41
|
+
rows="2"
|
|
42
|
+
maxlength="${String(CARD_TITLE_MAX)}"
|
|
43
|
+
placeholder="${t.cardTitlePlaceholder}"
|
|
44
|
+
data-role="card-title"
|
|
45
|
+
></textarea>
|
|
46
|
+
</div>
|
|
47
|
+
<div class="bw-fld">
|
|
48
|
+
<textarea
|
|
49
|
+
class="bw-field bw-ta"
|
|
50
|
+
rows="5"
|
|
51
|
+
maxlength="${String(TEXT_MAX)}"
|
|
52
|
+
aria-label="${t.body}"
|
|
53
|
+
data-role="body"
|
|
54
|
+
></textarea>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="bw-fld">
|
|
57
|
+
<div class="bw-sw" role="radiogroup" aria-label="${t.color}" data-role="colors"></div>
|
|
58
|
+
</div>
|
|
59
|
+
<div class="bw-fld">
|
|
60
|
+
<label for="bw-c-link">${t.link}</label>
|
|
61
|
+
<input
|
|
62
|
+
id="bw-c-link"
|
|
63
|
+
class="bw-field"
|
|
64
|
+
inputmode="url"
|
|
65
|
+
placeholder="${t.linkPlaceholder}"
|
|
66
|
+
data-role="link"
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
<p class="bw-err" data-role="err" role="alert" hidden></p>
|
|
70
|
+
${preview ? html`<p class="bw-help" data-role="preview">${t.preview}</p>` : null}
|
|
71
|
+
<div class="bw-acts">
|
|
72
|
+
<button type="button" class="bw-btn" data-role="cancel">${t.cancel}</button>
|
|
73
|
+
<button type="button" class="bw-btn bw-primary" data-role="submit">${t.submit}</button>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>`;
|
|
77
|
+
const dlg = part(modal, 'dlg');
|
|
78
|
+
const bodyEl = part(modal, 'body');
|
|
79
|
+
const linkEl = part(modal, 'link');
|
|
80
|
+
const titleEl = part(modal, 'card-title');
|
|
81
|
+
const errEl = part(modal, 'err');
|
|
82
|
+
const submitBtn = part(modal, 'submit');
|
|
83
|
+
const previewEl = part(modal, 'preview');
|
|
84
|
+
const syncPreview = () => {
|
|
85
|
+
if (previewEl && typeof preview === 'function') previewEl.textContent = preview(columnDd.get());
|
|
86
|
+
};
|
|
87
|
+
const columnDd = dropdown(part(modal, 'column'), {
|
|
88
|
+
labelledBy: 'bw-c-lab',
|
|
89
|
+
onChange: syncPreview,
|
|
90
|
+
});
|
|
91
|
+
let isOpen = false;
|
|
92
|
+
let sending = false;
|
|
93
|
+
let returnFocus = null;
|
|
94
|
+
let color = DEFAULT_COLOR;
|
|
95
|
+
let lastColumn = null;
|
|
96
|
+
|
|
97
|
+
const showErr = text => {
|
|
98
|
+
errEl.textContent = text;
|
|
99
|
+
errEl.hidden = !text;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// 색 (흰색이 기본). 화살표 키로 고름 (radiogroup)
|
|
103
|
+
const swatches = COLORS.map(k => {
|
|
104
|
+
const b = document.createElement('button');
|
|
105
|
+
b.type = 'button';
|
|
106
|
+
b.className = 'bw-swatch';
|
|
107
|
+
b.setAttribute('role', 'radio');
|
|
108
|
+
b.setAttribute('aria-label', texts.colors[k]);
|
|
109
|
+
b.title = texts.colors[k];
|
|
110
|
+
b.dataset.color = k;
|
|
111
|
+
b.addEventListener('click', () => pickColor(k));
|
|
112
|
+
return b;
|
|
113
|
+
});
|
|
114
|
+
part(modal, 'colors').replaceChildren(...swatches);
|
|
115
|
+
function pickColor(k, focus = false) {
|
|
116
|
+
color = k;
|
|
117
|
+
for (const b of swatches) {
|
|
118
|
+
const on = b.dataset.color === k;
|
|
119
|
+
b.setAttribute('aria-checked', String(on));
|
|
120
|
+
b.tabIndex = on ? 0 : -1;
|
|
121
|
+
if (on && focus) b.focus();
|
|
122
|
+
}
|
|
123
|
+
bodyEl.dataset.color = k;
|
|
124
|
+
titleEl.dataset.color = k;
|
|
125
|
+
}
|
|
126
|
+
part(modal, 'colors').addEventListener('keydown', e => {
|
|
127
|
+
const step =
|
|
128
|
+
e.key === 'ArrowRight' || e.key === 'ArrowDown'
|
|
129
|
+
? 1
|
|
130
|
+
: e.key === 'ArrowLeft' || e.key === 'ArrowUp'
|
|
131
|
+
? -1
|
|
132
|
+
: 0;
|
|
133
|
+
if (!step) return;
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
const at = COLORS.indexOf(color);
|
|
136
|
+
pickColor(COLORS[(at + step + COLORS.length) % COLORS.length], true);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// 목록 이어쓰기: 목록 줄에서 Enter는 다음 항목, 빈 항목에서 Enter는 목록 끝내기. Ctrl · ⌘ + Enter는 올리기
|
|
140
|
+
const replaceRange = (from, to, text) => {
|
|
141
|
+
bodyEl.setSelectionRange(from, to);
|
|
142
|
+
// 되돌리기(Ctrl+Z)가 되도록 execCommand를 먼저 쓰고, 안 되는 브라우저는 setRangeText
|
|
143
|
+
const ok = text
|
|
144
|
+
? document.execCommand?.('insertText', false, text)
|
|
145
|
+
: document.execCommand?.('delete');
|
|
146
|
+
if (!ok) bodyEl.setRangeText(text, from, to, 'end');
|
|
147
|
+
};
|
|
148
|
+
bodyEl.addEventListener('keydown', e => {
|
|
149
|
+
if (e.key !== 'Enter' || e.isComposing) return;
|
|
150
|
+
if (e.metaKey || e.ctrlKey) {
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
submit();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (e.shiftKey || e.altKey || bodyEl.selectionStart !== bodyEl.selectionEnd) return;
|
|
156
|
+
const pos = bodyEl.selectionStart;
|
|
157
|
+
const next = continueList(bodyEl.value, pos);
|
|
158
|
+
if (!next) return;
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
if ('clear' in next) replaceRange(next.clear, pos, '');
|
|
161
|
+
else replaceRange(pos, pos, next.insert);
|
|
162
|
+
});
|
|
163
|
+
// 제목은 Enter가 줄바꿈, Ctrl · ⌘ + Enter는 올리기
|
|
164
|
+
titleEl.addEventListener('keydown', e => {
|
|
165
|
+
if (e.key === 'Enter' && !e.isComposing && (e.metaKey || e.ctrlKey)) {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
submit();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
linkEl.addEventListener('keydown', e => {
|
|
171
|
+
if (e.key === 'Enter' && !e.isComposing) {
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
submit();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
async function submit() {
|
|
178
|
+
if (sending) return;
|
|
179
|
+
const title = titleEl.value.trim();
|
|
180
|
+
const text = bodyEl.value.trim();
|
|
181
|
+
const url = linkEl.value.trim();
|
|
182
|
+
// 제목 · 내용 · 링크가 모두 비면 올리지 않는다
|
|
183
|
+
if (!title && !text && !url) {
|
|
184
|
+
bodyEl.focus();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const column = columnDd.get();
|
|
188
|
+
const value = cardValue({ column, title, text, url, color });
|
|
189
|
+
if (!value) {
|
|
190
|
+
showErr(t.badLink);
|
|
191
|
+
linkEl.focus();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
sending = true;
|
|
195
|
+
submitBtn.disabled = true;
|
|
196
|
+
showErr('');
|
|
197
|
+
const failed = await onSubmit(value).catch(() => texts.errors.failed);
|
|
198
|
+
sending = false;
|
|
199
|
+
submitBtn.disabled = false;
|
|
200
|
+
if (failed) {
|
|
201
|
+
showErr(failed);
|
|
202
|
+
// 섹션 구성은 저장되고 카드만 실패했을 수 있다: 안내를 지금 상태로
|
|
203
|
+
syncPreview();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
lastColumn = column;
|
|
207
|
+
close(false);
|
|
208
|
+
}
|
|
209
|
+
submitBtn.addEventListener('click', submit);
|
|
210
|
+
part(modal, 'cancel').addEventListener('click', () => close());
|
|
211
|
+
part(modal, 'scrim').addEventListener('click', () => close());
|
|
212
|
+
// 창 안에서만 Tab이 돈다
|
|
213
|
+
dlg.addEventListener('keydown', e => {
|
|
214
|
+
if (e.key !== 'Tab') return;
|
|
215
|
+
const f = [...dlg.querySelectorAll('button, input, select, textarea')].filter(
|
|
216
|
+
n => !n.disabled && n.tabIndex >= 0 && n.offsetParent !== null
|
|
217
|
+
);
|
|
218
|
+
if (!f.length) return;
|
|
219
|
+
if (e.shiftKey && document.activeElement === f[0]) {
|
|
220
|
+
e.preventDefault();
|
|
221
|
+
f[f.length - 1].focus();
|
|
222
|
+
} else if (!e.shiftKey && document.activeElement === f[f.length - 1]) {
|
|
223
|
+
e.preventDefault();
|
|
224
|
+
f[0].focus();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
document.addEventListener('keydown', e => {
|
|
228
|
+
if (e.key === 'Escape' && isOpen) close();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* 창을 연다. column(누른 섹션) · title · body · link를 미리 채울 수 있다
|
|
233
|
+
* @param {{ column?: string | null, title?: string, body?: string, link?: string }} [pre]
|
|
234
|
+
*/
|
|
235
|
+
function open(pre = {}) {
|
|
236
|
+
const list = columns();
|
|
237
|
+
if (!list.length) return;
|
|
238
|
+
const has = id => list.some(c => c.id === id);
|
|
239
|
+
columnDd.set(
|
|
240
|
+
list.map(c => ({ value: c.id, label: c.title || texts.board.section })),
|
|
241
|
+
has(pre.column) ? pre.column : has(lastColumn) ? lastColumn : list[0].id
|
|
242
|
+
);
|
|
243
|
+
syncPreview();
|
|
244
|
+
titleEl.value = pre.title ?? '';
|
|
245
|
+
bodyEl.value = pre.body ?? '';
|
|
246
|
+
bodyEl.placeholder = placeholder() || t.bodyPlaceholder;
|
|
247
|
+
linkEl.value = pre.link ?? '';
|
|
248
|
+
showErr('');
|
|
249
|
+
pickColor(DEFAULT_COLOR);
|
|
250
|
+
sending = false;
|
|
251
|
+
submitBtn.disabled = false;
|
|
252
|
+
returnFocus = document.activeElement;
|
|
253
|
+
isOpen = true;
|
|
254
|
+
modal.inert = false;
|
|
255
|
+
modal.classList.add('is-open');
|
|
256
|
+
// 맨 위 제목 칸부터. 붙여넣기로 내용 · 링크를 채워 열었으면 내용 칸
|
|
257
|
+
(pre.body || pre.link ? bodyEl : titleEl).focus();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function close(restore = true) {
|
|
261
|
+
if (!isOpen) return;
|
|
262
|
+
isOpen = false;
|
|
263
|
+
modal.classList.remove('is-open');
|
|
264
|
+
modal.inert = true;
|
|
265
|
+
closeAllDropdowns();
|
|
266
|
+
if (restore) returnFocus?.focus?.();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return { element: modal, open, close, isOpen: () => isOpen };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 보드 위 빈 곳 두 번 클릭 · 붙여넣기 · 파일 끌어 놓기로 카드 창 열기 (학생 · 교육자 · 편집 화면이 같이 씀)
|
|
274
|
+
* @param {{
|
|
275
|
+
* root: HTMLElement, board: HTMLElement, active: () => boolean,
|
|
276
|
+
* ignore: string, open: (pre: { column?: string | null, body?: string, link?: string }) => void,
|
|
277
|
+
* columnAt: (x: number, y: number) => string | null, notify: (text: string) => void,
|
|
278
|
+
* }} o ignore: 두 번 클릭을 받지 않을 요소 선택자
|
|
279
|
+
*/
|
|
280
|
+
export function attachQuickAdd({ root, active, ignore, open, columnAt, notify }) {
|
|
281
|
+
root.addEventListener('dblclick', e => {
|
|
282
|
+
if (!active() || !(e.target instanceof Element) || e.target.closest(ignore)) return;
|
|
283
|
+
open({ column: columnAt(e.clientX, e.clientY) });
|
|
284
|
+
});
|
|
285
|
+
// 클립보드에서 붙여넣기 (입력 칸 안에서는 기본 동작 그대로)
|
|
286
|
+
document.addEventListener('paste', e => {
|
|
287
|
+
if (!active() || (e.target instanceof Element && e.target.closest('input, textarea, select')))
|
|
288
|
+
return;
|
|
289
|
+
const hasFile = !!e.clipboardData?.files?.length;
|
|
290
|
+
const text = (e.clipboardData?.getData('text/plain') || '').trim();
|
|
291
|
+
if (!hasFile && !text) return;
|
|
292
|
+
e.preventDefault();
|
|
293
|
+
if (hasFile) notify(texts.board.noPasteFiles);
|
|
294
|
+
else if (/^https?:\/\/\S+$/i.test(text)) open({ link: text });
|
|
295
|
+
else open({ body: text.slice(0, TEXT_MAX) });
|
|
296
|
+
});
|
|
297
|
+
// 파일을 끌어다 놓으면 브라우저가 파일을 열어 버리므로 막고 안내한다
|
|
298
|
+
const hasFiles = e => [...(e.dataTransfer?.types || [])].includes('Files');
|
|
299
|
+
root.addEventListener('dragover', e => {
|
|
300
|
+
if (hasFiles(e)) e.preventDefault();
|
|
301
|
+
});
|
|
302
|
+
root.addEventListener('drop', e => {
|
|
303
|
+
if (!hasFiles(e)) return;
|
|
304
|
+
e.preventDefault();
|
|
305
|
+
if (active()) notify(texts.board.noFiles);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 누른 곳의 섹션 id (.bw-col[data-col]). 섹션이 여러 줄로 놓이므로 x가 섹션 폭 안이면서
|
|
311
|
+
* 위쪽이 y보다 위인 것 중 가장 아래 줄 (섹션 아래 빈 곳을 눌러도 그 섹션)
|
|
312
|
+
* @param {HTMLElement} board
|
|
313
|
+
* @param {number} x
|
|
314
|
+
* @param {number} [y] 없으면 x만 본다
|
|
315
|
+
*/
|
|
316
|
+
export function columnAtX(board, x, y) {
|
|
317
|
+
let hit = null;
|
|
318
|
+
let top = -Infinity;
|
|
319
|
+
for (const n of board.querySelectorAll('.bw-col')) {
|
|
320
|
+
const r = n.getBoundingClientRect();
|
|
321
|
+
if (x < r.left || x > r.right) continue;
|
|
322
|
+
if (y === undefined) return n.dataset.col ?? null;
|
|
323
|
+
if (r.top <= y && r.top > top) {
|
|
324
|
+
hit = n;
|
|
325
|
+
top = r.top;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return hit?.dataset.col ?? null;
|
|
329
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// EDS Menu 모양의 드롭다운 (OS 기본 목록 대신). 목록은 화면 기준(fixed)으로 띄워 가로 스크롤 영역에 잘리지 않는다.
|
|
2
|
+
// 키보드: ↑ ↓ Home End로 옮기고 Enter · Space로 고름, Esc로 닫음 (combobox + listbox).
|
|
3
|
+
import { icon } from './icons.js';
|
|
4
|
+
|
|
5
|
+
let seq = 0;
|
|
6
|
+
const closers = new Set();
|
|
7
|
+
/** 열린 드롭다운을 모두 닫는다 (다시 그리기 · 창 닫기 전에) */
|
|
8
|
+
export const closeAllDropdowns = () => closers.forEach(f => f());
|
|
9
|
+
|
|
10
|
+
let listening = false;
|
|
11
|
+
function listenOnce() {
|
|
12
|
+
if (listening) return;
|
|
13
|
+
listening = true;
|
|
14
|
+
document.addEventListener('click', e => {
|
|
15
|
+
if (!(e.target instanceof Element) || !e.target.closest('.bw-dd')) closeAllDropdowns();
|
|
16
|
+
});
|
|
17
|
+
// 목록은 fixed라 버튼을 따라가지 않으므로 스크롤 · 창 크기가 바뀌면 닫는다 (목록 안 스크롤은 빼고)
|
|
18
|
+
window.addEventListener(
|
|
19
|
+
'scroll',
|
|
20
|
+
e => {
|
|
21
|
+
if (e.target instanceof Element && e.target.closest('.bw-dd-list')) return;
|
|
22
|
+
closeAllDropdowns();
|
|
23
|
+
},
|
|
24
|
+
true
|
|
25
|
+
);
|
|
26
|
+
window.addEventListener('resize', closeAllDropdowns);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* host 안에 드롭다운을 그린다. set(items, value)로 항목과 값을 넣고 get()으로 읽는다
|
|
31
|
+
* @param {HTMLElement} host
|
|
32
|
+
* @param {{ labelledBy: string, onChange?: (value: string) => void }} options
|
|
33
|
+
*/
|
|
34
|
+
export function dropdown(host, { labelledBy, onChange }) {
|
|
35
|
+
listenOnce();
|
|
36
|
+
const uid = `bw-dd${++seq}`;
|
|
37
|
+
host.classList.add('bw-dd');
|
|
38
|
+
const btn = document.createElement('button');
|
|
39
|
+
btn.type = 'button';
|
|
40
|
+
btn.className = 'bw-dd-btn';
|
|
41
|
+
btn.setAttribute('role', 'combobox');
|
|
42
|
+
btn.setAttribute('aria-haspopup', 'listbox');
|
|
43
|
+
btn.setAttribute('aria-expanded', 'false');
|
|
44
|
+
btn.setAttribute('aria-controls', `${uid}-list`);
|
|
45
|
+
btn.setAttribute('aria-labelledby', `${labelledBy} ${uid}-t`);
|
|
46
|
+
const text = document.createElement('span');
|
|
47
|
+
text.className = 'bw-dd-t';
|
|
48
|
+
text.id = `${uid}-t`;
|
|
49
|
+
btn.append(text, icon('chevron', 16));
|
|
50
|
+
const list = document.createElement('div');
|
|
51
|
+
list.className = 'bw-dd-list';
|
|
52
|
+
list.id = `${uid}-list`;
|
|
53
|
+
list.setAttribute('role', 'listbox');
|
|
54
|
+
list.setAttribute('aria-labelledby', labelledBy);
|
|
55
|
+
list.hidden = true;
|
|
56
|
+
host.replaceChildren(btn, list);
|
|
57
|
+
|
|
58
|
+
/** @type {Array<{ value: string, label: string }>} */
|
|
59
|
+
let items = [];
|
|
60
|
+
/** @type {string | null} */
|
|
61
|
+
let value = null;
|
|
62
|
+
let active = -1;
|
|
63
|
+
let isOpen = false;
|
|
64
|
+
const labelOf = v => items.find(it => it.value === v)?.label ?? '';
|
|
65
|
+
const syncBtn = () => {
|
|
66
|
+
text.textContent = labelOf(value);
|
|
67
|
+
btn.title = labelOf(value);
|
|
68
|
+
};
|
|
69
|
+
const setActive = (i, scroll = true) => {
|
|
70
|
+
active = i;
|
|
71
|
+
[...list.children].forEach((n, k) => n.classList.toggle('is-active', k === i));
|
|
72
|
+
if (i >= 0 && list.children[i]) {
|
|
73
|
+
btn.setAttribute('aria-activedescendant', list.children[i].id);
|
|
74
|
+
if (scroll) list.children[i].scrollIntoView?.({ block: 'nearest' });
|
|
75
|
+
} else btn.removeAttribute('aria-activedescendant');
|
|
76
|
+
};
|
|
77
|
+
const place = () => {
|
|
78
|
+
const r = btn.getBoundingClientRect();
|
|
79
|
+
list.style.width = `${r.width}px`;
|
|
80
|
+
list.style.left = `${r.left}px`;
|
|
81
|
+
const h = list.offsetHeight;
|
|
82
|
+
let top = r.bottom + 4;
|
|
83
|
+
if (top + h > window.innerHeight - 8) top = Math.max(8, r.top - h - 4);
|
|
84
|
+
list.style.top = `${top}px`;
|
|
85
|
+
};
|
|
86
|
+
const close = () => {
|
|
87
|
+
if (!isOpen) return;
|
|
88
|
+
isOpen = false;
|
|
89
|
+
list.hidden = true;
|
|
90
|
+
btn.setAttribute('aria-expanded', 'false');
|
|
91
|
+
btn.removeAttribute('aria-activedescendant');
|
|
92
|
+
};
|
|
93
|
+
const renderList = () => {
|
|
94
|
+
list.replaceChildren(
|
|
95
|
+
...items.map((it, i) => {
|
|
96
|
+
const o = document.createElement('div');
|
|
97
|
+
o.className = 'bw-dd-opt';
|
|
98
|
+
o.id = `${uid}-o${i}`;
|
|
99
|
+
o.setAttribute('role', 'option');
|
|
100
|
+
o.setAttribute('aria-selected', String(it.value === value));
|
|
101
|
+
o.title = it.label;
|
|
102
|
+
const s = document.createElement('span');
|
|
103
|
+
s.textContent = it.label;
|
|
104
|
+
o.append(s);
|
|
105
|
+
if (it.value === value) o.append(icon('check', 16));
|
|
106
|
+
o.addEventListener('mousemove', () => {
|
|
107
|
+
if (active !== i) setActive(i, false);
|
|
108
|
+
});
|
|
109
|
+
o.addEventListener('click', () => choose(i));
|
|
110
|
+
return o;
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
const choose = i => {
|
|
115
|
+
const it = items[i];
|
|
116
|
+
if (!it) return;
|
|
117
|
+
const changed = it.value !== value;
|
|
118
|
+
value = it.value;
|
|
119
|
+
syncBtn();
|
|
120
|
+
renderList();
|
|
121
|
+
close();
|
|
122
|
+
btn.focus();
|
|
123
|
+
if (changed) onChange?.(value);
|
|
124
|
+
};
|
|
125
|
+
const open = () => {
|
|
126
|
+
if (isOpen || !items.length) return;
|
|
127
|
+
closeAllDropdowns();
|
|
128
|
+
isOpen = true;
|
|
129
|
+
list.hidden = false;
|
|
130
|
+
btn.setAttribute('aria-expanded', 'true');
|
|
131
|
+
place();
|
|
132
|
+
setActive(
|
|
133
|
+
Math.max(
|
|
134
|
+
0,
|
|
135
|
+
items.findIndex(it => it.value === value)
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
btn.addEventListener('click', () => (isOpen ? close() : open()));
|
|
140
|
+
btn.addEventListener('keydown', e => {
|
|
141
|
+
if (!isOpen) {
|
|
142
|
+
if (['ArrowDown', 'ArrowUp', 'Enter', ' '].includes(e.key)) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
open();
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (e.key === 'ArrowDown') {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
setActive(Math.min(items.length - 1, active + 1));
|
|
151
|
+
} else if (e.key === 'ArrowUp') {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
setActive(Math.max(0, active - 1));
|
|
154
|
+
} else if (e.key === 'Home') {
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
setActive(0);
|
|
157
|
+
} else if (e.key === 'End') {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
setActive(items.length - 1);
|
|
160
|
+
} else if (e.key === 'Enter' || e.key === ' ') {
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
choose(active);
|
|
163
|
+
} else if (e.key === 'Escape') {
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
e.stopPropagation();
|
|
166
|
+
close();
|
|
167
|
+
} else if (e.key === 'Tab') close();
|
|
168
|
+
});
|
|
169
|
+
btn.addEventListener('keyup', e => {
|
|
170
|
+
if (e.key === ' ') e.preventDefault();
|
|
171
|
+
});
|
|
172
|
+
closers.add(close);
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
/** 항목과 값을 넣는다 (값이 항목에 없으면 첫 항목) */
|
|
176
|
+
set(next, v) {
|
|
177
|
+
close();
|
|
178
|
+
items = next;
|
|
179
|
+
value = next.some(it => it.value === v) ? v : (next[0]?.value ?? null);
|
|
180
|
+
renderList();
|
|
181
|
+
syncBtn();
|
|
182
|
+
},
|
|
183
|
+
get: () => value,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// 선 아이콘 (24 × 24, currentColor). icon('plus', 20)처럼 이름과 크기로 만듭니다.
|
|
2
|
+
|
|
3
|
+
const PATHS = {
|
|
4
|
+
grip: '<g fill="currentColor" stroke="none"><circle cx="9" cy="6" r="1.4"/><circle cx="15" cy="6" r="1.4"/><circle cx="9" cy="12" r="1.4"/><circle cx="15" cy="12" r="1.4"/><circle cx="9" cy="18" r="1.4"/><circle cx="15" cy="18" r="1.4"/></g>',
|
|
5
|
+
dots: '<g fill="currentColor" stroke="none"><circle cx="12" cy="5" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="12" cy="19" r="1.6"/></g>',
|
|
6
|
+
plus: '<path d="M12 5v14M5 12h14"/>',
|
|
7
|
+
x: '<path d="M6 6l12 12M18 6 6 18"/>',
|
|
8
|
+
link: '<path d="M10 13a5 5 0 0 0 7.1 0l3-3a5 5 0 0 0-7.1-7.1l-1.7 1.7"/><path d="M14 11a5 5 0 0 0-7.1 0l-3 3a5 5 0 0 0 7.1 7.1l1.7-1.7"/>',
|
|
9
|
+
chevron: '<path d="M6 9l6 6 6-6"/>',
|
|
10
|
+
check: '<path d="M5 12l5 5 9-10"/>',
|
|
11
|
+
heart:
|
|
12
|
+
'<path d="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 21l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z"/>',
|
|
13
|
+
pen: '<path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z"/>',
|
|
14
|
+
left: '<path d="M19 12H5M12 19l-7-7 7-7"/>',
|
|
15
|
+
right: '<path d="M5 12h14M12 5l7 7-7 7"/>',
|
|
16
|
+
trash: '<path d="M3 6h18M8 6V4h8v2M19 6l-1 14H6L5 6M10 11v6M14 11v6"/>',
|
|
17
|
+
eye: '<path d="M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>',
|
|
18
|
+
eyeOff:
|
|
19
|
+
'<path d="M17.9 17.9A10 10 0 0 1 12 19c-6.4 0-10-7-10-7a18 18 0 0 1 4.1-5.1M9.9 5.2A9 9 0 0 1 12 5c6.4 0 10 7 10 7a18 18 0 0 1-2.2 3.2M14.1 14.1a3 3 0 1 1-4.2-4.2M2 2l20 20"/>',
|
|
20
|
+
pin: '<path d="M12 17v5M9 3h6l-1 6 3 3v2H7v-2l3-3z"/>',
|
|
21
|
+
lock: '<rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/>',
|
|
22
|
+
unlock: '<rect x="4" y="11" width="16" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 7.9-1"/>',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {keyof typeof PATHS} name
|
|
27
|
+
* @param {number} [size]
|
|
28
|
+
* @returns {SVGSVGElement}
|
|
29
|
+
*/
|
|
30
|
+
export function icon(name, size = 16) {
|
|
31
|
+
const t = document.createElement('template');
|
|
32
|
+
// 모양은 위 PATHS의 고정 글자뿐이다 (사용자 값이 들어가지 않음)
|
|
33
|
+
// ecdk-ignore-next-line sec.html-injection
|
|
34
|
+
t.innerHTML = `<svg viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${PATHS[name]}</svg>`;
|
|
35
|
+
return /** @type {SVGSVGElement} */ (t.content.firstElementChild);
|
|
36
|
+
}
|