@unana_dev/doxen 0.2.5 → 0.3.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/README.md +22 -2
- package/client/app.js +535 -10
- package/client/comments.js +352 -0
- package/client/index.html +18 -13
- package/client/style.css +633 -25
- package/package.json +2 -1
- package/src/access-worker.js +28 -0
- package/src/build.js +1 -1
- package/src/comment-report.js +82 -0
- package/src/comments.sql +10 -0
- package/src/content.js +34 -3
- package/src/deploy-state.js +1 -0
- package/src/deploy.js +5 -0
- package/src/dev.js +1 -0
- package/src/index.d.ts +1 -0
- package/src/templates/comment-report.yml +34 -0
package/README.md
CHANGED
|
@@ -218,7 +218,7 @@ guide/
|
|
|
218
218
|
└── 01-config.md
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
-
- 하위 폴더는 탐색 목록에 **경로 형태로** 표시됩니다.
|
|
221
|
+
- 하위 폴더는 탐색 목록에 **경로 형태로** 표시됩니다. 폴더의 `.xlsx` 파일도 목록에서 열어 시트별 셀 값을 확인하고 원본을 다운로드할 수 있습니다. 수식은 저장된 결과값을 표시하며 서식과 차트는 표시하지 않습니다.
|
|
222
222
|
- 숨김 파일(`.`으로 시작), `node_modules`, 심볼릭 링크 문서는 **제외**됩니다.
|
|
223
223
|
|
|
224
224
|
> ⚠️ **보안 메모**
|
|
@@ -234,7 +234,7 @@ guide/
|
|
|
234
234
|
- Mermaid 코드 블록(`mermaid`): 시퀀스·흐름도 등을 다이어그램으로 표시합니다. 언어 지정 없이 `sequenceDiagram`으로 시작하는 코드 블록도 지원합니다. 문법 오류가 있으면 안내와 원본 코드를 표시합니다.
|
|
235
235
|
- 다른 문서로의 상대 링크 (`[설치 방법](./02-installation.md)`)
|
|
236
236
|
- 한국어 제목 앵커 (`#설치-방법`)
|
|
237
|
-
-
|
|
237
|
+
- 이미지·파일 첨부: PNG / JPEG / GIF / WebP / AVIF / ICO / PDF / XLSX
|
|
238
238
|
|
|
239
239
|
### 지원하지 않는 것 ❌
|
|
240
240
|
|
|
@@ -566,3 +566,23 @@ npm pack
|
|
|
566
566
|
**구조 한 줄 요약:** `bin/docs.js` → 설정 로더 → Markdown·섹션·첨부 처리 → 정적 빌드 또는 로컬 서버. 화면과 브라우저 검색 코드는 `client/`에 있습니다.
|
|
567
567
|
|
|
568
568
|
궁금한 점이나 버그는 저장소 이슈로 남겨 주세요. 즐거운 문서 작성 되세요! 📚
|
|
569
|
+
|
|
570
|
+
### 문서 댓글 설정
|
|
571
|
+
|
|
572
|
+
댓글은 Cloudflare Access로 보호된 배포에서 선택적으로 사용할 수 있습니다. Cloudflare D1 데이터베이스를 만들고 패키지의 `src/comments.sql`을 해당 데이터베이스에 적용하세요. 예를 들어 프로젝트에 설치된 패키지를 기준으로 다음 명령을 실행합니다.
|
|
573
|
+
|
|
574
|
+
```bash
|
|
575
|
+
npx wrangler d1 execute 데이터베이스이름 --remote --file=node_modules/@unana_dev/doxen/src/comments.sql
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
직접 `docs.config.ts`에 배포 설정을 작성했다면 `deploy.comments: { databaseName: "데이터베이스이름", databaseId: "D1 데이터베이스 UUID" }`를 추가합니다. 자동 배포 설정을 사용한다면 `.doxen-deploy.json`의 최상위에 동일한 `comments` 객체를 추가한 뒤 다시 배포합니다. 배포 시 `COMMENTS_DB` D1 바인딩이 설정됩니다. 데이터베이스 생성과 SQL 적용은 별도로 필요하며, 로컬 미리보기와 정적 빌드에는 댓글 저장 기능이 없습니다.
|
|
579
|
+
|
|
580
|
+
본문의 문구를 선택한 후 해당 문단 오른쪽의 버튼을 누르거나, 문구 선택 없이 버튼을 눌러 댓글을 작성합니다. 작성자는 Access의 이메일로 표시됩니다. 문단 내용이나 같은 내용의 문단 순서가 바뀌면 기존 댓글은 본문 아래의 위치를 찾을 수 없는 댓글 목록에서 확인할 수 있습니다.
|
|
581
|
+
|
|
582
|
+
#### 매일 GitHub 이슈로 댓글 모으기
|
|
583
|
+
|
|
584
|
+
설치된 패키지의 `src/templates/comment-report.yml`을 문서 저장소의 `.github/workflows/comment-report.yml`로 복사합니다. 저장소 Actions secrets에 `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_D1_DATABASE_ID`, D1 읽기 권한의 `CLOUDFLARE_D1_READ_TOKEN`을 등록하고, 기본 브랜치에 워크플로를 반영하세요. `npm ci`를 사용하는 예제이므로 프로젝트에 npm 잠금 파일이 필요합니다.
|
|
585
|
+
|
|
586
|
+
저장소의 Actions variables에 배포된 문서 사이트 주소를 `DOXEN_SITE_URL`로 등록하세요. 설정 파일이 저장소 루트의 기본 이름이 아니라면 `DOXEN_CONFIG`에 저장소 기준 경로도 등록합니다. 보고서의 각 댓글에는 보고서 실행 시점 커밋의 GitHub 원본 파일 링크와 배포 사이트의 해당 댓글 링크가 표시됩니다. 현재 설정에서 문서를 찾지 못하면 링크 대신 안내 문구가 표시됩니다.
|
|
587
|
+
|
|
588
|
+
매일 한국 시간 오전 8시에 전날 00:00~24:00의 댓글을 하나의 이슈로 작성합니다. 댓글은 문서별로 묶이며, 같은 문서 안에서는 작성 순서대로 표시됩니다. 댓글이 없으면 이슈를 만들지 않으며, 같은 날짜의 보고서 이슈가 이미 있으면 중복 생성하지 않습니다. Actions 화면의 수동 실행에서 날짜를 입력해 누락된 날을 다시 집계할 수 있습니다. 이슈 본문 양식은 패키지의 `src/comment-report.js`에서 확인할 수 있으며 필요에 맞게 복사해 수정하세요. 댓글 내용과 작성자 이메일이 이슈 저장소의 열람자에게 공개되므로 접근 권한을 확인하세요. GitHub 예약 실행은 지연되거나 누락될 수 있습니다.
|
package/client/app.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { searchDocuments, matchRanges, matchesRow } from "./search.js";
|
|
2
|
+
import { attachComments } from "./comments.js";
|
|
2
3
|
|
|
3
4
|
const $ = (selector) => document.querySelector(selector);
|
|
4
5
|
const el = (tag, text, className) => {
|
|
@@ -189,10 +190,418 @@ function renderFolder(folderPath) {
|
|
|
189
190
|
window.scrollTo(0, 0);
|
|
190
191
|
}
|
|
191
192
|
|
|
193
|
+
const columnLetter = (index) => {
|
|
194
|
+
let name = "";
|
|
195
|
+
for (let n = index + 1; n > 0; n = Math.floor((n - 1) / 26))
|
|
196
|
+
name = String.fromCharCode(65 + ((n - 1) % 26)) + name;
|
|
197
|
+
return name;
|
|
198
|
+
};
|
|
199
|
+
const ROW_HEAD = 46;
|
|
200
|
+
const COL_HEAD = 26;
|
|
201
|
+
|
|
202
|
+
function prepareSheet(sheet) {
|
|
203
|
+
const source = Array.isArray(sheet.data) ? sheet.data : [];
|
|
204
|
+
const columns = Math.max(1, ...source.map((row) => row.length));
|
|
205
|
+
const rows = (source.length ? source : [[]]).map((row) =>
|
|
206
|
+
Array.from({ length: columns }, (_, c) => row[c] ?? null),
|
|
207
|
+
);
|
|
208
|
+
const widths = Array.from({ length: columns }, (_, c) => {
|
|
209
|
+
let longest = 0;
|
|
210
|
+
for (const row of rows.slice(0, 200)) {
|
|
211
|
+
for (const line of String(row[c] ?? "").split("\n")) {
|
|
212
|
+
let width = 0;
|
|
213
|
+
for (const char of line) width += /[\u1100-\u11ff\u2e80-\ua4cf\uac00-\ud7af\uf900-\ufaff\uff00-\uffef]/.test(char) ? 14 : 8;
|
|
214
|
+
longest = Math.max(longest, width);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return Math.min(340, Math.max(72, longest + 24));
|
|
218
|
+
});
|
|
219
|
+
return { name: String(sheet.sheet ?? ""), rows, widths };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function spreadsheetViewer(doc, rawSheets) {
|
|
223
|
+
const sheets = (rawSheets.length ? rawSheets : [{ sheet: "Sheet1", data: [] }]).map(prepareSheet);
|
|
224
|
+
const selection = sheets.map((sheet) => ({ r: sheet.rows.length > 1 ? 1 : 0, c: 0 }));
|
|
225
|
+
const state = { sheet: 0, wrap: false, full: false, query: "", matches: [], matchIndex: -1, expanded: null };
|
|
226
|
+
const button = (text, className, title) => {
|
|
227
|
+
const node = el("button", text, className);
|
|
228
|
+
node.type = "button";
|
|
229
|
+
if (title) node.title = title;
|
|
230
|
+
return node;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const viewer = el("div", undefined, "sheet-viewer");
|
|
234
|
+
const toolbar = el("div", undefined, "sheet-toolbar");
|
|
235
|
+
const finder = el("label", undefined, "sheet-find");
|
|
236
|
+
const findInput = el("input");
|
|
237
|
+
findInput.type = "search";
|
|
238
|
+
findInput.placeholder = "시트에서 찾기 (Enter: 다음)";
|
|
239
|
+
findInput.setAttribute("aria-label", "시트에서 찾기");
|
|
240
|
+
const matchLabel = el("span", "", "sheet-find-count");
|
|
241
|
+
matchLabel.setAttribute("aria-live", "polite");
|
|
242
|
+
finder.append(el("span", undefined, "sheet-find-icon"), findInput, matchLabel);
|
|
243
|
+
const wrapButton = button("텍스트 줄바꿈", "sheet-button");
|
|
244
|
+
wrapButton.setAttribute("aria-pressed", "false");
|
|
245
|
+
const fullButton = button(undefined, "sheet-full-button", "펼치기");
|
|
246
|
+
fullButton.setAttribute("aria-label", "펼치기");
|
|
247
|
+
fullButton.setAttribute("aria-pressed", "false");
|
|
248
|
+
fullButton.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 3h7v7M21 3l-7 7M10 21H3v-7M3 21l7-7"/></svg>';
|
|
249
|
+
const download = el("a", "다운로드", "sheet-download");
|
|
250
|
+
download.href = doc.spreadsheet.file;
|
|
251
|
+
download.download = doc.title;
|
|
252
|
+
download.setAttribute("aria-label", "엑셀 파일 다운로드");
|
|
253
|
+
toolbar.append(fullButton, finder, el("span", undefined, "sheet-spacer"), wrapButton, download);
|
|
254
|
+
|
|
255
|
+
const formula = el("div", undefined, "sheet-formula");
|
|
256
|
+
const nameBox = el("div", "", "sheet-name-box");
|
|
257
|
+
const formulaValue = el("div", "", "sheet-formula-value");
|
|
258
|
+
formula.append(nameBox, el("div", "fx", "sheet-fx"), formulaValue);
|
|
259
|
+
|
|
260
|
+
const grid = el("div", undefined, "sheet-grid spreadsheet-table");
|
|
261
|
+
grid.tabIndex = 0;
|
|
262
|
+
grid.setAttribute("role", "grid");
|
|
263
|
+
grid.setAttribute("aria-label", `${doc.title} 시트`);
|
|
264
|
+
|
|
265
|
+
const footer = el("div", undefined, "sheet-footer");
|
|
266
|
+
const arrows = el("div", undefined, "sheet-arrows");
|
|
267
|
+
const prev = button("‹", "sheet-arrow", "이전 시트 (Ctrl+PgUp)");
|
|
268
|
+
const next = button("›", "sheet-arrow", "다음 시트 (Ctrl+PgDn)");
|
|
269
|
+
prev.setAttribute("aria-label", "이전 시트");
|
|
270
|
+
next.setAttribute("aria-label", "다음 시트");
|
|
271
|
+
arrows.append(prev, next);
|
|
272
|
+
const tabs = el("div", undefined, "sheet-tabs");
|
|
273
|
+
tabs.setAttribute("role", "tablist");
|
|
274
|
+
tabs.setAttribute("aria-label", "시트 선택");
|
|
275
|
+
const status = el("div", undefined, "sheet-status");
|
|
276
|
+
const statusMessage = el("span", "");
|
|
277
|
+
statusMessage.setAttribute("aria-live", "polite");
|
|
278
|
+
const dims = el("span", "");
|
|
279
|
+
status.append(statusMessage, dims);
|
|
280
|
+
footer.append(arrows, tabs, status);
|
|
281
|
+
viewer.append(toolbar, formula, grid, footer);
|
|
282
|
+
|
|
283
|
+
const tabButtons = sheets.map((sheet, i) => {
|
|
284
|
+
const tab = button(undefined, "sheet-tab");
|
|
285
|
+
tab.setAttribute("role", "tab");
|
|
286
|
+
tab.append(el("span", sheet.name), el("span", String(Math.max(0, sheet.rows.length - 1)), "sheet-tab-count"));
|
|
287
|
+
tab.onclick = () => goSheet(i);
|
|
288
|
+
tabs.append(tab);
|
|
289
|
+
return tab;
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
let cells = [];
|
|
293
|
+
let colHeads = [];
|
|
294
|
+
let rowHeads = [];
|
|
295
|
+
let cols = [];
|
|
296
|
+
let table;
|
|
297
|
+
|
|
298
|
+
const cellValue = (r, c) => {
|
|
299
|
+
const value = sheets[state.sheet].rows[r]?.[c];
|
|
300
|
+
return value == null ? "" : String(value);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
function updateFormula() {
|
|
304
|
+
const { r, c } = selection[state.sheet];
|
|
305
|
+
nameBox.textContent = `${columnLetter(c)}${r + 1}`;
|
|
306
|
+
formulaValue.textContent = cellValue(r, c) || " ";
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function scrollToCell({ r, c }) {
|
|
310
|
+
const cell = cells[r]?.[c];
|
|
311
|
+
if (!cell) return;
|
|
312
|
+
const top = COL_HEAD + (r > 0 ? cells[0][0].offsetHeight : 0);
|
|
313
|
+
if (cell.offsetLeft - ROW_HEAD < grid.scrollLeft) grid.scrollLeft = cell.offsetLeft - ROW_HEAD;
|
|
314
|
+
else if (cell.offsetLeft + cell.offsetWidth > grid.scrollLeft + grid.clientWidth)
|
|
315
|
+
grid.scrollLeft = cell.offsetLeft + cell.offsetWidth - grid.clientWidth;
|
|
316
|
+
if (r === 0) return;
|
|
317
|
+
if (cell.offsetTop - top < grid.scrollTop) grid.scrollTop = cell.offsetTop - top;
|
|
318
|
+
else if (cell.offsetTop + cell.offsetHeight > grid.scrollTop + grid.clientHeight)
|
|
319
|
+
grid.scrollTop = cell.offsetTop + cell.offsetHeight - grid.clientHeight;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function mark(on) {
|
|
323
|
+
const { r, c } = selection[state.sheet];
|
|
324
|
+
cells[r]?.[c]?.classList.toggle("is-selected", on);
|
|
325
|
+
cells[r]?.[c]?.setAttribute("aria-selected", String(on));
|
|
326
|
+
colHeads[c]?.classList.toggle("is-active", on);
|
|
327
|
+
rowHeads[r]?.classList.toggle("is-active", on);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function select(r, c, { scroll = true } = {}) {
|
|
331
|
+
mark(false);
|
|
332
|
+
if (state.expanded) {
|
|
333
|
+
cells[state.expanded.r]?.[state.expanded.c]?.classList.remove("is-expanded");
|
|
334
|
+
state.expanded = null;
|
|
335
|
+
}
|
|
336
|
+
selection[state.sheet] = { r, c };
|
|
337
|
+
mark(true);
|
|
338
|
+
statusMessage.textContent = "";
|
|
339
|
+
updateFormula();
|
|
340
|
+
if (scroll) scrollToCell({ r, c });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function paintMatches() {
|
|
344
|
+
for (const row of cells) for (const cell of row) cell.classList.remove("is-match", "is-current-match");
|
|
345
|
+
const query = state.query.trim().toLocaleLowerCase();
|
|
346
|
+
state.matches = [];
|
|
347
|
+
if (query) {
|
|
348
|
+
for (const [r, row] of sheets[state.sheet].rows.entries())
|
|
349
|
+
for (const [c, value] of row.entries())
|
|
350
|
+
if (String(value ?? "").toLocaleLowerCase().includes(query)) {
|
|
351
|
+
state.matches.push({ r, c });
|
|
352
|
+
cells[r][c].classList.add("is-match");
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const current = state.matches[state.matchIndex];
|
|
356
|
+
if (current) cells[current.r][current.c].classList.add("is-current-match");
|
|
357
|
+
matchLabel.textContent = query
|
|
358
|
+
? state.matches.length
|
|
359
|
+
? `${state.matchIndex >= 0 ? state.matchIndex + 1 : 0}/${state.matches.length}`
|
|
360
|
+
: "0건"
|
|
361
|
+
: "";
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function buildGrid() {
|
|
365
|
+
const sheet = sheets[state.sheet];
|
|
366
|
+
table = el("table");
|
|
367
|
+
const colgroup = el("colgroup");
|
|
368
|
+
colgroup.append(Object.assign(el("col"), { style: `width:${ROW_HEAD}px` }));
|
|
369
|
+
cols = sheet.widths.map((width) => {
|
|
370
|
+
const col = el("col");
|
|
371
|
+
col.style.width = `${width}px`;
|
|
372
|
+
colgroup.append(col);
|
|
373
|
+
return col;
|
|
374
|
+
});
|
|
375
|
+
const head = el("thead");
|
|
376
|
+
const headRow = el("tr");
|
|
377
|
+
headRow.append(el("th", "", "sheet-corner"));
|
|
378
|
+
colHeads = sheet.widths.map((_, c) => {
|
|
379
|
+
const th = el("th", columnLetter(c), "sheet-col-head");
|
|
380
|
+
th.scope = "col";
|
|
381
|
+
const handle = el("span", undefined, "sheet-resize");
|
|
382
|
+
handle.setAttribute("aria-hidden", "true");
|
|
383
|
+
handle.onpointerdown = (event) => startResize(event, c);
|
|
384
|
+
th.append(handle);
|
|
385
|
+
headRow.append(th);
|
|
386
|
+
return th;
|
|
387
|
+
});
|
|
388
|
+
head.append(headRow);
|
|
389
|
+
const body = el("tbody");
|
|
390
|
+
rowHeads = [];
|
|
391
|
+
cells = sheet.rows.map((row, r) => {
|
|
392
|
+
const tr = el("tr");
|
|
393
|
+
const number = el("th", String(r + 1), "sheet-row-head");
|
|
394
|
+
number.scope = "row";
|
|
395
|
+
rowHeads.push(number);
|
|
396
|
+
tr.append(number);
|
|
397
|
+
const rowCells = row.map((value, c) => {
|
|
398
|
+
const td = el("td");
|
|
399
|
+
td.dataset.cell = `${r}-${c}`;
|
|
400
|
+
td.setAttribute("role", "gridcell");
|
|
401
|
+
if (typeof value === "number") td.classList.add("is-number");
|
|
402
|
+
td.append(el("div", value == null ? "" : String(value)));
|
|
403
|
+
tr.append(td);
|
|
404
|
+
return td;
|
|
405
|
+
});
|
|
406
|
+
if (r === 0) tr.classList.add("sheet-header-row");
|
|
407
|
+
body.append(tr);
|
|
408
|
+
return rowCells;
|
|
409
|
+
});
|
|
410
|
+
table.append(colgroup, head, body);
|
|
411
|
+
updateWidth();
|
|
412
|
+
grid.replaceChildren(table);
|
|
413
|
+
grid.scrollTop = 0;
|
|
414
|
+
grid.scrollLeft = 0;
|
|
415
|
+
mark(true);
|
|
416
|
+
updateFormula();
|
|
417
|
+
paintMatches();
|
|
418
|
+
dims.textContent = `${Math.max(0, sheet.rows.length - 1)}행 × ${sheet.widths.length}열`;
|
|
419
|
+
for (const [i, tab] of tabButtons.entries()) {
|
|
420
|
+
tab.classList.toggle("is-active", i === state.sheet);
|
|
421
|
+
tab.setAttribute("aria-selected", String(i === state.sheet));
|
|
422
|
+
}
|
|
423
|
+
tabButtons[state.sheet]?.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function updateWidth() {
|
|
427
|
+
table.style.width = `${ROW_HEAD + sheets[state.sheet].widths.reduce((a, b) => a + b, 0)}px`;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function startResize(event, c) {
|
|
431
|
+
event.preventDefault();
|
|
432
|
+
event.stopPropagation();
|
|
433
|
+
const widths = sheets[state.sheet].widths;
|
|
434
|
+
const x0 = event.clientX;
|
|
435
|
+
const w0 = widths[c];
|
|
436
|
+
const move = (moveEvent) => {
|
|
437
|
+
widths[c] = Math.max(40, Math.round(w0 + moveEvent.clientX - x0));
|
|
438
|
+
cols[c].style.width = `${widths[c]}px`;
|
|
439
|
+
updateWidth();
|
|
440
|
+
};
|
|
441
|
+
const up = () => {
|
|
442
|
+
window.removeEventListener("pointermove", move);
|
|
443
|
+
window.removeEventListener("pointerup", up);
|
|
444
|
+
viewer.classList.remove("is-resizing");
|
|
445
|
+
};
|
|
446
|
+
viewer.classList.add("is-resizing");
|
|
447
|
+
window.addEventListener("pointermove", move);
|
|
448
|
+
window.addEventListener("pointerup", up);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function goSheet(index) {
|
|
452
|
+
state.sheet = (index + sheets.length) % sheets.length;
|
|
453
|
+
state.matchIndex = -1;
|
|
454
|
+
state.expanded = null;
|
|
455
|
+
statusMessage.textContent = "";
|
|
456
|
+
buildGrid();
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function setFull(full) {
|
|
460
|
+
state.full = full;
|
|
461
|
+
viewer.classList.toggle("is-full", full);
|
|
462
|
+
document.body.classList.toggle("sheet-fullscreen", full);
|
|
463
|
+
const label = full ? "좁히기" : "펼치기";
|
|
464
|
+
fullButton.title = label;
|
|
465
|
+
fullButton.setAttribute("aria-label", label);
|
|
466
|
+
fullButton.querySelector("path").setAttribute("d", full
|
|
467
|
+
? "M14 4v6h6M14 10l7-7M10 20v-6H4M10 14l-7 7"
|
|
468
|
+
: "M14 3h7v7M21 3l-7 7M10 21H3v-7M3 21l7-7");
|
|
469
|
+
fullButton.setAttribute("aria-pressed", String(full));
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
grid.addEventListener("pointerdown", (event) => {
|
|
473
|
+
const cell = event.target.closest("td[data-cell]");
|
|
474
|
+
if (!cell) return;
|
|
475
|
+
const [r, c] = cell.dataset.cell.split("-").map(Number);
|
|
476
|
+
select(r, c, { scroll: false });
|
|
477
|
+
setTimeout(() => grid.focus({ preventScroll: true }));
|
|
478
|
+
});
|
|
479
|
+
grid.addEventListener("dblclick", (event) => {
|
|
480
|
+
const cell = event.target.closest("td[data-cell]");
|
|
481
|
+
if (!cell) return;
|
|
482
|
+
const [r, c] = cell.dataset.cell.split("-").map(Number);
|
|
483
|
+
const same = state.expanded?.r === r && state.expanded?.c === c;
|
|
484
|
+
if (state.expanded) cells[state.expanded.r][state.expanded.c].classList.remove("is-expanded");
|
|
485
|
+
state.expanded = same ? null : { r, c };
|
|
486
|
+
cell.classList.toggle("is-expanded", !same);
|
|
487
|
+
});
|
|
488
|
+
grid.addEventListener("keydown", (event) => {
|
|
489
|
+
const rows = sheets[state.sheet].rows;
|
|
490
|
+
const { r, c } = selection[state.sheet];
|
|
491
|
+
const lastRow = rows.length - 1;
|
|
492
|
+
const lastCol = rows[0].length - 1;
|
|
493
|
+
const mod = event.metaKey || event.ctrlKey;
|
|
494
|
+
if (mod && (event.key === "PageUp" || event.key === "PageDown")) {
|
|
495
|
+
event.preventDefault();
|
|
496
|
+
goSheet(state.sheet + (event.key === "PageUp" ? -1 : 1));
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
if (mod && event.key.toLowerCase() === "c" && !getSelection()?.toString()) {
|
|
500
|
+
event.preventDefault();
|
|
501
|
+
navigator.clipboard?.writeText(cellValue(r, c)).then(
|
|
502
|
+
() => (statusMessage.textContent = `${columnLetter(c)}${r + 1} 복사됨`),
|
|
503
|
+
() => (statusMessage.textContent = "복사하지 못했습니다"),
|
|
504
|
+
);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (event.key === "Escape" && state.full) {
|
|
508
|
+
event.preventDefault();
|
|
509
|
+
setFull(false);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const move = {
|
|
513
|
+
ArrowUp: [-1, 0],
|
|
514
|
+
ArrowDown: [1, 0],
|
|
515
|
+
ArrowLeft: [0, -1],
|
|
516
|
+
ArrowRight: [0, 1],
|
|
517
|
+
Enter: [event.shiftKey ? -1 : 1, 0],
|
|
518
|
+
Tab: [0, event.shiftKey ? -1 : 1],
|
|
519
|
+
}[event.key];
|
|
520
|
+
const clamp = (value, max) => Math.min(max, Math.max(0, value));
|
|
521
|
+
if (move) {
|
|
522
|
+
event.preventDefault();
|
|
523
|
+
const nr = mod && move[0] ? (move[0] > 0 ? lastRow : 0) : clamp(r + move[0], lastRow);
|
|
524
|
+
const nc = mod && move[1] ? (move[1] > 0 ? lastCol : 0) : clamp(c + move[1], lastCol);
|
|
525
|
+
select(nr, nc);
|
|
526
|
+
} else if (event.key === "Home") {
|
|
527
|
+
event.preventDefault();
|
|
528
|
+
select(mod ? 0 : r, 0);
|
|
529
|
+
} else if (event.key === "End") {
|
|
530
|
+
event.preventDefault();
|
|
531
|
+
select(mod ? lastRow : r, lastCol);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
findInput.addEventListener("input", () => {
|
|
535
|
+
state.query = findInput.value;
|
|
536
|
+
state.matchIndex = -1;
|
|
537
|
+
paintMatches();
|
|
538
|
+
});
|
|
539
|
+
findInput.addEventListener("keydown", (event) => {
|
|
540
|
+
if (event.key === "Escape" && state.full) return setFull(false);
|
|
541
|
+
if (event.key !== "Enter" || !state.matches.length) return;
|
|
542
|
+
event.preventDefault();
|
|
543
|
+
const count = state.matches.length;
|
|
544
|
+
state.matchIndex = (state.matchIndex + (event.shiftKey ? -1 : 1) + count) % count;
|
|
545
|
+
paintMatches();
|
|
546
|
+
const { r, c } = state.matches[state.matchIndex];
|
|
547
|
+
select(r, c);
|
|
548
|
+
});
|
|
549
|
+
wrapButton.onclick = () => {
|
|
550
|
+
state.wrap = !state.wrap;
|
|
551
|
+
viewer.classList.toggle("is-wrapped", state.wrap);
|
|
552
|
+
wrapButton.setAttribute("aria-pressed", String(state.wrap));
|
|
553
|
+
};
|
|
554
|
+
fullButton.onclick = () => setFull(!state.full);
|
|
555
|
+
prev.onclick = () => goSheet(state.sheet - 1);
|
|
556
|
+
next.onclick = () => goSheet(state.sheet + 1);
|
|
557
|
+
|
|
558
|
+
buildGrid();
|
|
559
|
+
return viewer;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function renderModified(doc) {
|
|
563
|
+
if (!doc.modified?.date) return;
|
|
564
|
+
const date = new Date(doc.modified.date);
|
|
565
|
+
if (Number.isNaN(date.getTime())) return;
|
|
566
|
+
const label = `최종 수정 ${date.toLocaleDateString("ko-KR")}${doc.modified.author ? ` · ${doc.modified.author}` : ""}`;
|
|
567
|
+
$("#article h1").after(el("p", label, "document-modified"));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
async function renderSpreadsheet(doc) {
|
|
571
|
+
const article = $("#article");
|
|
572
|
+
const content = el("p", "엑셀 파일을 불러오는 중입니다.", "sheet-message");
|
|
573
|
+
article.replaceChildren(el("h1", doc.title), content);
|
|
574
|
+
renderModified(doc);
|
|
575
|
+
try {
|
|
576
|
+
const response = await fetch(doc.spreadsheet.data);
|
|
577
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
578
|
+
const sheets = await response.json();
|
|
579
|
+
if (current !== doc) return;
|
|
580
|
+
content.replaceWith(
|
|
581
|
+
spreadsheetViewer(doc, sheets),
|
|
582
|
+
el(
|
|
583
|
+
"p",
|
|
584
|
+
"방향키로 셀 이동 · 더블클릭 또는 줄바꿈으로 전체 내용 보기 · 열 경계 드래그로 너비 조절 · Ctrl+C 셀 복사",
|
|
585
|
+
"sheet-hint",
|
|
586
|
+
),
|
|
587
|
+
);
|
|
588
|
+
} catch {
|
|
589
|
+
if (current === doc) content.textContent = "엑셀 파일을 불러오지 못했습니다.";
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
192
593
|
function render() {
|
|
193
|
-
|
|
594
|
+
document.body.classList.remove('has-comments', 'comment-card-open');
|
|
595
|
+
$('#article').commentLaneObserver?.disconnect();
|
|
596
|
+
$('#article').commentDismissController?.abort();
|
|
597
|
+
$('.compact-toc').hidden = true;
|
|
598
|
+
$('#compact-toc-links').hidden = true;
|
|
599
|
+
$('#compact-toc-toggle').setAttribute('aria-expanded', 'false');
|
|
600
|
+
let id, anchor, commentId;
|
|
194
601
|
try {
|
|
195
|
-
[id, anchor] = location.hash.slice(2).split("/").map(decodeURIComponent);
|
|
602
|
+
[id, anchor, commentId] = location.hash.slice(2).split("/").map(decodeURIComponent);
|
|
603
|
+
if (anchor !== 'comment') commentId = undefined;
|
|
604
|
+
if (commentId) anchor = undefined;
|
|
196
605
|
} catch {
|
|
197
606
|
id = "invalid";
|
|
198
607
|
}
|
|
@@ -209,6 +618,9 @@ function render() {
|
|
|
209
618
|
const isFolder = folderPath && site.documents.some(
|
|
210
619
|
(doc) => doc.tab === activeTab && doc.path.startsWith(folderPath),
|
|
211
620
|
);
|
|
621
|
+
$("#article").dataset.commentDocument = "";
|
|
622
|
+
document.body.classList.toggle("is-spreadsheet", Boolean(current?.spreadsheet));
|
|
623
|
+
document.body.classList.remove("sheet-fullscreen");
|
|
212
624
|
renderNavigation(isFolder ? folderPath : null);
|
|
213
625
|
$("#toc").replaceChildren();
|
|
214
626
|
$("#pagination").replaceChildren();
|
|
@@ -239,8 +651,17 @@ function render() {
|
|
|
239
651
|
title: current.path.split("/").at(-1).replace(/\.md$/i, ""),
|
|
240
652
|
id: current.id,
|
|
241
653
|
});
|
|
654
|
+
if (current.spreadsheet) {
|
|
655
|
+
$(".toc").hidden = true;
|
|
656
|
+
$("#pagination").hidden = true;
|
|
657
|
+
renderSpreadsheet(current);
|
|
658
|
+
window.scrollTo(0, 0);
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
$("#article").dataset.commentDocument = current.id;
|
|
242
662
|
$("#article").innerHTML = current.html;
|
|
243
663
|
if (!$("#article h1")) $("#article").prepend(el("h1", current.title));
|
|
664
|
+
renderModified(current);
|
|
244
665
|
for (const heading of $("#article").querySelectorAll("h2, h3, h4, h5, h6")) {
|
|
245
666
|
if (/^version\s*:\s*\S+/i.test(heading.textContent.trim()))
|
|
246
667
|
heading.classList.add("document-version");
|
|
@@ -257,6 +678,9 @@ function render() {
|
|
|
257
678
|
link.style.paddingLeft = `${Math.max(0, heading.level - 2) * 12}px`;
|
|
258
679
|
$("#toc").append(link);
|
|
259
680
|
}
|
|
681
|
+
$('#compact-toc-links').replaceChildren(...[...$('#toc').children].map((link) => link.cloneNode(true)));
|
|
682
|
+
requestAnimationFrame(updateTocFades);
|
|
683
|
+
$('.compact-toc').hidden = !$('#toc').children.length;
|
|
260
684
|
const siblings = site.documents.filter((doc) => doc.tab === activeTab);
|
|
261
685
|
const index = siblings.indexOf(current);
|
|
262
686
|
for (const [label, doc] of [
|
|
@@ -273,6 +697,7 @@ function render() {
|
|
|
273
697
|
$("#pagination").append(link);
|
|
274
698
|
}
|
|
275
699
|
attachTableSearches();
|
|
700
|
+
attachComments($("#article"), current.id, commentId);
|
|
276
701
|
const diagrams = [...$("#article").querySelectorAll("pre > code")].filter(
|
|
277
702
|
(code) => code.classList.contains("language-mermaid") ||
|
|
278
703
|
(!code.className && /^\s*sequenceDiagram\b/.test(code.textContent)),
|
|
@@ -294,16 +719,50 @@ function render() {
|
|
|
294
719
|
} else window.scrollTo(0, 0);
|
|
295
720
|
}
|
|
296
721
|
|
|
722
|
+
let searchTab = null;
|
|
723
|
+
|
|
297
724
|
function renderResults() {
|
|
298
725
|
const query = $("#global-search").value;
|
|
299
|
-
const results = searchDocuments(site.documents, query);
|
|
726
|
+
const results = searchDocuments(searchTab ? site.documents.filter((doc) => doc.tab === searchTab.slug) : site.documents, query);
|
|
727
|
+
$("#clear-search").hidden = !query;
|
|
728
|
+
const suggestions = $("#search-suggestions");
|
|
729
|
+
suggestions.replaceChildren();
|
|
730
|
+
suggestions.hidden = true;
|
|
731
|
+
if (!searchTab && /^#[^ ]*$/.test(query)) {
|
|
732
|
+
const tabs = site.tabs.filter((tab) => tab.title.toLocaleLowerCase().includes(query.slice(1).toLocaleLowerCase()));
|
|
733
|
+
if (tabs.length) {
|
|
734
|
+
suggestions.hidden = false;
|
|
735
|
+
suggestions.append(el("p", "탭으로 범위 지정"));
|
|
736
|
+
for (const tab of tabs) {
|
|
737
|
+
const button = el("button", undefined, "search-suggestion");
|
|
738
|
+
button.type = "button";
|
|
739
|
+
button.append(el("span", `# ${tab.title}`), el("small", `문서 ${site.documents.filter((doc) => doc.tab === tab.slug).length}개`));
|
|
740
|
+
button.onclick = () => selectSearchTab(tab);
|
|
741
|
+
suggestions.append(button);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
$("#search-count").hidden = !suggestions.hidden;
|
|
300
746
|
$("#search-count").textContent = query.trim()
|
|
301
747
|
? results.length
|
|
302
|
-
? `${results.length}개 결과${results.length === 80 ? " (최대 80개 표시)" : ""}`
|
|
748
|
+
? `${searchTab ? `${searchTab.title} 탭에서 ` : ""}${results.length}개 결과${results.length === 80 ? " (최대 80개 표시)" : ""}`
|
|
303
749
|
: "일치하는 내용이 없습니다."
|
|
304
|
-
: "한국어와 영문으로 모든 탭의 내용을 검색합니다.";
|
|
750
|
+
: searchTab ? `${searchTab.title} 탭에서 검색합니다.` : "한국어와 영문으로 모든 탭의 내용을 검색합니다.";
|
|
305
751
|
$("#results").replaceChildren();
|
|
306
|
-
|
|
752
|
+
if (query.trim() && !results.length && suggestions.hidden) {
|
|
753
|
+
const empty = el("div", undefined, "search-empty");
|
|
754
|
+
empty.append(el("strong", searchTab ? `‘${searchTab.title}’에 ‘${query}’ 결과가 없어요` : `‘${query}’ 검색 결과가 없어요`));
|
|
755
|
+
if (searchTab) {
|
|
756
|
+
const otherCount = searchDocuments(site.documents, query).length;
|
|
757
|
+
empty.append(el("p", `전체 탭에서 ${otherCount}개를 찾았습니다.`));
|
|
758
|
+
const button = el("button", "모든 탭에서 검색");
|
|
759
|
+
button.type = "button";
|
|
760
|
+
button.onclick = clearSearchTab;
|
|
761
|
+
empty.append(button);
|
|
762
|
+
}
|
|
763
|
+
$("#results").append(empty);
|
|
764
|
+
}
|
|
765
|
+
for (const { doc, section } of suggestions.hidden ? results : []) {
|
|
307
766
|
const link = el("a", undefined, "result");
|
|
308
767
|
link.href = route(doc.id, section.anchor);
|
|
309
768
|
const title = el("strong", section.title);
|
|
@@ -332,20 +791,78 @@ function renderResults() {
|
|
|
332
791
|
}
|
|
333
792
|
}
|
|
334
793
|
|
|
794
|
+
function selectSearchTab(tab) {
|
|
795
|
+
searchTab = tab;
|
|
796
|
+
$("#global-search").value = "";
|
|
797
|
+
$("#search-tag-label").textContent = `# ${tab.title}`;
|
|
798
|
+
$("#search-tag").hidden = false;
|
|
799
|
+
renderResults();
|
|
800
|
+
$("#global-search").focus();
|
|
801
|
+
}
|
|
802
|
+
function clearSearchTab() {
|
|
803
|
+
searchTab = null;
|
|
804
|
+
$("#search-tag").hidden = true;
|
|
805
|
+
renderResults();
|
|
806
|
+
$("#global-search").focus();
|
|
807
|
+
}
|
|
808
|
+
function positionSearch() {
|
|
809
|
+
const rect = $("#content").getBoundingClientRect();
|
|
810
|
+
dialog.style.left = `${rect.left}px`;
|
|
811
|
+
dialog.style.width = `${rect.width}px`;
|
|
812
|
+
}
|
|
335
813
|
const openSearch = () => {
|
|
336
814
|
if (!site) return;
|
|
815
|
+
positionSearch();
|
|
337
816
|
dialog.showModal();
|
|
338
817
|
$("#global-search").focus();
|
|
339
818
|
renderResults();
|
|
340
819
|
};
|
|
820
|
+
const closeCompactToc = () => {
|
|
821
|
+
$('#compact-toc-links').hidden = true;
|
|
822
|
+
$('#compact-toc-toggle').setAttribute('aria-expanded', 'false');
|
|
823
|
+
};
|
|
824
|
+
$('#compact-toc-toggle').onclick = () => {
|
|
825
|
+
const links = $('#compact-toc-links');
|
|
826
|
+
links.hidden = !links.hidden;
|
|
827
|
+
$('#compact-toc-toggle').setAttribute('aria-expanded', String(!links.hidden));
|
|
828
|
+
};
|
|
829
|
+
$('#compact-toc-links').onclick = (event) => {
|
|
830
|
+
if (event.target.closest('a')) closeCompactToc();
|
|
831
|
+
};
|
|
832
|
+
document.addEventListener('click', (event) => {
|
|
833
|
+
if (!event.target.closest('.compact-toc')) closeCompactToc();
|
|
834
|
+
});
|
|
835
|
+
document.addEventListener('keydown', (event) => {
|
|
836
|
+
if (event.key === 'Escape' && !$('#compact-toc-links').hidden) {
|
|
837
|
+
closeCompactToc();
|
|
838
|
+
$('#compact-toc-toggle').focus();
|
|
839
|
+
}
|
|
840
|
+
});
|
|
341
841
|
$("#open-search").onclick = openSearch;
|
|
342
842
|
$("#close-search").onclick = () => dialog.close();
|
|
343
|
-
$("#
|
|
843
|
+
$("#clear-search-tag").onclick = clearSearchTab;
|
|
844
|
+
$("#clear-search").onclick = () => { $("#global-search").value = ""; renderResults(); $("#global-search").focus(); };
|
|
845
|
+
window.addEventListener("resize", () => { if (dialog.open) positionSearch(); });
|
|
846
|
+
$("#global-search").oninput = (event) => {
|
|
847
|
+
const input = event.target;
|
|
848
|
+
if (!searchTab && !event.isComposing) {
|
|
849
|
+
const tab = site.tabs.find((item) => input.value.startsWith(`#${item.title} `));
|
|
850
|
+
if (tab) {
|
|
851
|
+
searchTab = tab;
|
|
852
|
+
input.value = input.value.slice(tab.title.length + 2);
|
|
853
|
+
$("#search-tag-label").textContent = `# ${tab.title}`;
|
|
854
|
+
$("#search-tag").hidden = false;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
renderResults();
|
|
858
|
+
};
|
|
344
859
|
$("#global-search").onkeydown = (event) => {
|
|
345
|
-
if (event.key === "
|
|
860
|
+
if (event.key === "Backspace" && !event.isComposing && searchTab && !event.target.value && event.target.selectionStart === 0) {
|
|
861
|
+
clearSearchTab();
|
|
862
|
+
} else if (event.key === "ArrowDown") {
|
|
346
863
|
event.preventDefault();
|
|
347
|
-
$("#results a")?.focus();
|
|
348
|
-
} else if (event.key === "Enter") $("#results a")?.click();
|
|
864
|
+
$("#search-suggestions:not([hidden]) button, #results a")?.focus();
|
|
865
|
+
} else if (event.key === "Enter") $("#search-suggestions:not([hidden]) button, #results a")?.click();
|
|
349
866
|
};
|
|
350
867
|
$("#results").onkeydown = (event) => {
|
|
351
868
|
if (!["ArrowDown", "ArrowUp"].includes(event.key)) return;
|
|
@@ -376,6 +893,14 @@ dialog.addEventListener("click", (event) => {
|
|
|
376
893
|
dialog.close();
|
|
377
894
|
}
|
|
378
895
|
});
|
|
896
|
+
const updateTocFades = () => {
|
|
897
|
+
const toc = $('#toc');
|
|
898
|
+
const frame = $('.toc-frame');
|
|
899
|
+
frame.classList.toggle('has-above', toc.scrollTop > 1);
|
|
900
|
+
frame.classList.toggle('has-below', toc.scrollTop + toc.clientHeight < toc.scrollHeight - 1);
|
|
901
|
+
};
|
|
902
|
+
$('#toc').addEventListener('scroll', updateTocFades);
|
|
903
|
+
new ResizeObserver(updateTocFades).observe($('.toc-frame'));
|
|
379
904
|
window.addEventListener("hashchange", () => {
|
|
380
905
|
if (site) render();
|
|
381
906
|
});
|