@iyulab/components 1.51.0 → 1.52.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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/utilities/tsv.d.ts +28 -0
- package/dist/utilities/tsv.js +86 -0
- package/package.json +1 -1
- package/skills/iyulab-components/SKILL.md +1 -0
- package/skills/iyulab-components/references/utilities/tsv.md +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.52.0] - 2026-09-30
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `encodeTsv(rows)` and `decodeTsv(text)` — the clipboard format spreadsheets use for copy and paste
|
|
8
|
+
(tab-separated, RFC 4180 quoting). A cell containing a tab, a line break or a double quote is quoted,
|
|
9
|
+
so a multi-line cell pastes into Excel as one cell instead of several rows; reading accepts CRLF,
|
|
10
|
+
keeps rows of empty cells and treats a quote in the middle of a cell as text.
|
|
11
|
+
`decodeTsv(encodeTsv(rows))` returns `rows`.
|
|
12
|
+
|
|
3
13
|
## [1.51.0] - 2026-09-30
|
|
4
14
|
|
|
5
15
|
### Added
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -60,4 +60,5 @@ import { BrowserStorage } from "./utilities/BrowserStorage.js";
|
|
|
60
60
|
import { Dialog } from "./utilities/Dialog.js";
|
|
61
61
|
import { Theme } from "./utilities/Theme.js";
|
|
62
62
|
import { Toast } from "./utilities/Toast.js";
|
|
63
|
-
|
|
63
|
+
import { decodeTsv, encodeTsv } from "./utilities/tsv.js";
|
|
64
|
+
export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOverlayElement, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, createDevWarner, dateAttrConverter, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 스프레드시트 클립보드 형식(TSV)의 인코더·디코더 — Excel·Google Sheets 와 복사·붙여넣기로 오가는 표.
|
|
3
|
+
*
|
|
4
|
+
* 규칙은 RFC 4180 의 인용 규칙을 탭 구분자에 적용한 것이다(Excel 이 클립보드에 쓰는 형식):
|
|
5
|
+
* - 셀에 탭·줄바꿈·큰따옴표가 있으면 셀 전체를 큰따옴표로 감싸고 안의 큰따옴표는 둘로 적는다.
|
|
6
|
+
* 감싸지 않으면 줄바꿈이 든 셀 하나가 붙여넣는 쪽에서 여러 행으로 쪼개진다.
|
|
7
|
+
* - 인용은 **셀의 첫 글자**가 큰따옴표일 때만 시작한다 — `5" 나사` 처럼 셀 중간의 따옴표는 글자다.
|
|
8
|
+
* - 행은 LF 로 잇고 끝에는 붙이지 않는다(한 셀을 복사해 입력란에 붙여넣을 때 줄바꿈이 따라오지 않게).
|
|
9
|
+
* 읽을 때는 CRLF·CR·LF 를 모두 받고, 스프레드시트가 붙이는 끝의 줄바꿈 **하나**는 새 행으로 세지 않는다.
|
|
10
|
+
* 마지막 행이 빈 셀 하나면 그 행을 잃지 않도록 줄바꿈으로 닫는다 — 그래서
|
|
11
|
+
* `decodeTsv(encodeTsv(rows))` 는 `rows` 와 같다.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* 2차원 셀 배열을 스프레드시트에 붙여넣을 수 있는 TSV 로 씁니다.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* encodeTsv([['이름', '비고'], ['가', '첫 줄\n둘째 줄']]);
|
|
18
|
+
* // '이름\t비고\n가\t"첫 줄\n둘째 줄"'
|
|
19
|
+
*/
|
|
20
|
+
export declare function encodeTsv(rows: readonly (readonly string[])[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* 스프레드시트에서 복사한 TSV 를 2차원 셀 배열로 읽습니다. `encodeTsv` 의 역입니다.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* decodeTsv('가\t"첫 줄\r\n둘째 줄"\r\n');
|
|
26
|
+
* // [['가', '첫 줄\r\n둘째 줄']]
|
|
27
|
+
*/
|
|
28
|
+
export declare function decodeTsv(text: string): string[][];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//#region src/utilities/tsv.ts
|
|
2
|
+
/**
|
|
3
|
+
* 스프레드시트 클립보드 형식(TSV)의 인코더·디코더 — Excel·Google Sheets 와 복사·붙여넣기로 오가는 표.
|
|
4
|
+
*
|
|
5
|
+
* 규칙은 RFC 4180 의 인용 규칙을 탭 구분자에 적용한 것이다(Excel 이 클립보드에 쓰는 형식):
|
|
6
|
+
* - 셀에 탭·줄바꿈·큰따옴표가 있으면 셀 전체를 큰따옴표로 감싸고 안의 큰따옴표는 둘로 적는다.
|
|
7
|
+
* 감싸지 않으면 줄바꿈이 든 셀 하나가 붙여넣는 쪽에서 여러 행으로 쪼개진다.
|
|
8
|
+
* - 인용은 **셀의 첫 글자**가 큰따옴표일 때만 시작한다 — `5" 나사` 처럼 셀 중간의 따옴표는 글자다.
|
|
9
|
+
* - 행은 LF 로 잇고 끝에는 붙이지 않는다(한 셀을 복사해 입력란에 붙여넣을 때 줄바꿈이 따라오지 않게).
|
|
10
|
+
* 읽을 때는 CRLF·CR·LF 를 모두 받고, 스프레드시트가 붙이는 끝의 줄바꿈 **하나**는 새 행으로 세지 않는다.
|
|
11
|
+
* 마지막 행이 빈 셀 하나면 그 행을 잃지 않도록 줄바꿈으로 닫는다 — 그래서
|
|
12
|
+
* `decodeTsv(encodeTsv(rows))` 는 `rows` 와 같다.
|
|
13
|
+
*/
|
|
14
|
+
/** 이 셀은 인용해야 하는가 */
|
|
15
|
+
var NEEDS_QUOTE = /[\t\n\r"]/;
|
|
16
|
+
/**
|
|
17
|
+
* 2차원 셀 배열을 스프레드시트에 붙여넣을 수 있는 TSV 로 씁니다.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* encodeTsv([['이름', '비고'], ['가', '첫 줄\n둘째 줄']]);
|
|
21
|
+
* // '이름\t비고\n가\t"첫 줄\n둘째 줄"'
|
|
22
|
+
*/
|
|
23
|
+
function encodeTsv(rows) {
|
|
24
|
+
const lines = rows.map((row) => row.map((cell) => NEEDS_QUOTE.test(cell) ? `"${cell.replace(/"/g, "\"\"")}"` : cell).join(" "));
|
|
25
|
+
const text = lines.join("\n");
|
|
26
|
+
return lines.length > 0 && lines[lines.length - 1] === "" ? `${text}\n` : text;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 스프레드시트에서 복사한 TSV 를 2차원 셀 배열로 읽습니다. `encodeTsv` 의 역입니다.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* decodeTsv('가\t"첫 줄\r\n둘째 줄"\r\n');
|
|
33
|
+
* // [['가', '첫 줄\r\n둘째 줄']]
|
|
34
|
+
*/
|
|
35
|
+
function decodeTsv(text) {
|
|
36
|
+
const rows = [];
|
|
37
|
+
if (text === "") return rows;
|
|
38
|
+
let row = [];
|
|
39
|
+
let cell = "";
|
|
40
|
+
let i = 0;
|
|
41
|
+
const len = text.length;
|
|
42
|
+
let atCellStart = true;
|
|
43
|
+
const endCell = () => {
|
|
44
|
+
row.push(cell);
|
|
45
|
+
cell = "";
|
|
46
|
+
atCellStart = true;
|
|
47
|
+
};
|
|
48
|
+
const endRow = () => {
|
|
49
|
+
endCell();
|
|
50
|
+
rows.push(row);
|
|
51
|
+
row = [];
|
|
52
|
+
};
|
|
53
|
+
while (i < len) {
|
|
54
|
+
const ch = text[i];
|
|
55
|
+
if (atCellStart && ch === "\"") {
|
|
56
|
+
atCellStart = false;
|
|
57
|
+
i++;
|
|
58
|
+
while (i < len) if (text[i] === "\"") {
|
|
59
|
+
if (text[i + 1] === "\"") {
|
|
60
|
+
cell += "\"";
|
|
61
|
+
i += 2;
|
|
62
|
+
} else {
|
|
63
|
+
i++;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
} else cell += text[i++];
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
atCellStart = false;
|
|
70
|
+
if (ch === " ") {
|
|
71
|
+
endCell();
|
|
72
|
+
i++;
|
|
73
|
+
} else if (ch === "\r" || ch === "\n") {
|
|
74
|
+
endRow();
|
|
75
|
+
i += ch === "\r" && text[i + 1] === "\n" ? 2 : 1;
|
|
76
|
+
if (i === len) return rows;
|
|
77
|
+
} else {
|
|
78
|
+
cell += ch;
|
|
79
|
+
i++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
endRow();
|
|
83
|
+
return rows;
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
export { decodeTsv, encodeTsv };
|
package/package.json
CHANGED
|
@@ -135,6 +135,7 @@ carries the control's role, not on the host element. Native nodes use native `di
|
|
|
135
135
|
- [`elements`](./references/utilities/elements.md) — Shadow-DOM-aware DOM query helpers
|
|
136
136
|
- [`format`](./references/utilities/format.md) — Locale-aware number, currency and date formatting
|
|
137
137
|
- [`keyboard`](./references/utilities/keyboard.md) — `isImeComposing` for Enter handlers that must not fire mid-composition (Korean/Japanese/Chinese input)
|
|
138
|
+
- [`tsv`](./references/utilities/tsv.md) — `encodeTsv` / `decodeTsv`, the spreadsheet clipboard format with RFC 4180 quoting
|
|
138
139
|
- [`OverlayManager`](./references/utilities/overlay-manager.md) — Internal overlay stack and z-index manager
|
|
139
140
|
|
|
140
141
|
---
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# tsv
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { encodeTsv, decodeTsv } from '@iyulab/components';
|
|
5
|
+
// or: import { encodeTsv, decodeTsv } from '@iyulab/components/dist/utilities/tsv.js';
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
The clipboard format spreadsheets use for copy and paste (Excel, Google Sheets, LibreOffice): cells
|
|
9
|
+
separated by tabs, rows separated by line breaks, and RFC 4180 quoting.
|
|
10
|
+
|
|
11
|
+
## `encodeTsv(rows: readonly (readonly string[])[]): string`
|
|
12
|
+
|
|
13
|
+
Writes a table that pastes into a spreadsheet cell for cell. A cell containing a tab, a line break, or a
|
|
14
|
+
double quote is wrapped in double quotes, with inner quotes doubled — without that, a cell with a line
|
|
15
|
+
break is split into several rows by the application you paste into. Rows are joined with `\n` and no line
|
|
16
|
+
break follows the last one, so a single copied cell pastes into a text field as just its text. (A last
|
|
17
|
+
row made of one empty cell is closed with `\n` so that it survives the round trip.)
|
|
18
|
+
|
|
19
|
+
## `decodeTsv(text: string): string[][]`
|
|
20
|
+
|
|
21
|
+
Reads what a spreadsheet put on the clipboard. Accepts `\r\n`, `\r` and `\n`; quoting starts only when a
|
|
22
|
+
cell's first character is a double quote (`5" bolt` is plain text); one trailing line break does not open
|
|
23
|
+
a new row, so a row of empty cells is kept. `decodeTsv(encodeTsv(rows))` returns `rows`.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
onCopy(e: ClipboardEvent) {
|
|
27
|
+
e.clipboardData?.setData('text/plain', encodeTsv(selectedCells));
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
}
|
|
30
|
+
onPaste(e: ClipboardEvent) {
|
|
31
|
+
const rows = decodeTsv(e.clipboardData?.getData('text/plain') ?? '');
|
|
32
|
+
// rows[r][c] are strings — convert per column
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`@iyulab/flex-table` and the `u-simple-sheet` / `u-rich-table` of `@iyulab/data-components` use it for
|
|
37
|
+
their clipboard.
|