@iyulab/components 1.50.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 +30 -0
- package/README.md +1 -1
- package/dist/components/input/UInput.js +2 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/utilities/Dialog.js +2 -1
- package/dist/utilities/OverlayManager.js +2 -1
- package/dist/utilities/keyboard.d.ts +20 -0
- package/dist/utilities/keyboard.js +25 -0
- 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 +2 -0
- package/skills/iyulab-components/references/utilities/keyboard.md +27 -0
- package/skills/iyulab-components/references/utilities/tsv.md +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
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
|
+
|
|
13
|
+
## [1.51.0] - 2026-09-30
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- `isImeComposing(event)` — whether a key event belongs to an IME composition (Korean, Japanese,
|
|
18
|
+
Chinese …). It checks `isComposing` and also `keyCode` 229, because Safari delivers the key that
|
|
19
|
+
confirms a composition after `compositionend` with `isComposing` false. Use it in any handler that
|
|
20
|
+
acts on Enter while the user types text.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **`Dialog.prompt` no longer confirms on the Enter that finishes an IME composition** — typing a
|
|
25
|
+
Korean name and pressing Enter closed the dialog before the last syllable was committed.
|
|
26
|
+
- `u-input` no longer submits its form on Safari's composition-confirming Enter (it already ignored
|
|
27
|
+
the Enter that Chrome and Firefox send while composing).
|
|
28
|
+
|
|
29
|
+
### Documentation
|
|
30
|
+
|
|
31
|
+
- README component list includes `u-expander`.
|
|
32
|
+
|
|
3
33
|
## [1.50.0] - 2026-09-29
|
|
4
34
|
|
|
5
35
|
### Added
|
package/README.md
CHANGED
|
@@ -100,7 +100,7 @@ npx skills add ./node_modules/@iyulab/components
|
|
|
100
100
|
|
|
101
101
|
**Navigation** — `u-menu`, `u-menu-item`, `u-tab-panel`, `u-breadcrumb`, `u-breadcrumb-item`, `u-tree`, `u-tree-item`
|
|
102
102
|
|
|
103
|
-
**Layout & Display** — `u-avatar`, `u-card`, `u-carousel`, `u-divider`, `u-icon`, `u-panel`, `u-split-panel`, `u-tag`, `u-text`
|
|
103
|
+
**Layout & Display** — `u-avatar`, `u-card`, `u-carousel`, `u-divider`, `u-expander`, `u-icon`, `u-panel`, `u-split-panel`, `u-tag`, `u-text`
|
|
104
104
|
|
|
105
105
|
## Theming
|
|
106
106
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorateMetadata.js";
|
|
2
2
|
import __decorate from "../../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/decorate.js";
|
|
3
3
|
import { UFormControlElement } from "../UFormControlElement.js";
|
|
4
|
+
import { isImeComposing } from "../../utilities/keyboard.js";
|
|
4
5
|
import "../spinner/USpinner.js";
|
|
5
6
|
import "../icon/UIcon.js";
|
|
6
7
|
import { Locale } from "../../utilities/Locale.js";
|
|
@@ -356,7 +357,7 @@ var UInput = class UInput extends UFormControlElement {
|
|
|
356
357
|
* 아니면 `requestSubmit()` 한다(검증도 그 안에서 돈다).
|
|
357
358
|
*/
|
|
358
359
|
handleImplicitSubmission(e) {
|
|
359
|
-
if (e
|
|
360
|
+
if (isImeComposing(e) || this.composing || e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return;
|
|
360
361
|
setTimeout(() => {
|
|
361
362
|
const form = this.form;
|
|
362
363
|
if (e.defaultPrevented || !form || !this.isConnected) return;
|
package/dist/index.d.ts
CHANGED
|
@@ -64,7 +64,9 @@ export * from './utilities/Dialog.js';
|
|
|
64
64
|
export * from './utilities/elements.js';
|
|
65
65
|
export * from './utilities/format.js';
|
|
66
66
|
export * from './utilities/icons.js';
|
|
67
|
+
export * from './utilities/keyboard.js';
|
|
67
68
|
export * from './utilities/Locale.js';
|
|
68
69
|
export * from './utilities/OverlayManager.js';
|
|
69
70
|
export * from './utilities/Theme.js';
|
|
70
71
|
export * from './utilities/Toast.js';
|
|
72
|
+
export * from './utilities/tsv.js';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { UElement } from "./components/UElement.js";
|
|
|
2
2
|
import { getParentElement, isCoarsePointer, isFocusCandidate, querySelectorAllWithin, querySelectorDeep, querySelectorWithin } from "./utilities/elements.js";
|
|
3
3
|
import { UFloatingElement } from "./components/UFloatingElement.js";
|
|
4
4
|
import { UFormControlElement } from "./components/UFormControlElement.js";
|
|
5
|
+
import { isImeComposing } from "./utilities/keyboard.js";
|
|
5
6
|
import { OverlayManager } from "./utilities/OverlayManager.js";
|
|
6
7
|
import { arrayAttrConverter, booleanAttrConverter, dateAttrConverter, jsonAttrConverter, urlAttrConverter } from "./utilities/converters.js";
|
|
7
8
|
import { UOverlayElement } from "./components/UOverlayElement.js";
|
|
@@ -59,4 +60,5 @@ import { BrowserStorage } from "./utilities/BrowserStorage.js";
|
|
|
59
60
|
import { Dialog } from "./utilities/Dialog.js";
|
|
60
61
|
import { Theme } from "./utilities/Theme.js";
|
|
61
62
|
import { Toast } from "./utilities/Toast.js";
|
|
62
|
-
|
|
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 };
|
package/dist/utilities/Dialog.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isImeComposing } from "./keyboard.js";
|
|
1
2
|
import "../components/button/UButton.js";
|
|
2
3
|
import { Locale } from "./Locale.js";
|
|
3
4
|
import { UDialog } from "../components/dialog/UDialog.js";
|
|
@@ -60,7 +61,7 @@ var Dialog = class {
|
|
|
60
61
|
inputValue = e.target.value || "";
|
|
61
62
|
}}
|
|
62
63
|
@keydown=${(e) => {
|
|
63
|
-
if (e.key === "Enter") {
|
|
64
|
+
if (e.key === "Enter" && !isImeComposing(e)) {
|
|
64
65
|
const input = e.target;
|
|
65
66
|
inputValue = input.value || "";
|
|
66
67
|
const buttons = input.closest("u-dialog").querySelectorAll("u-button");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isImeComposing } from "./keyboard.js";
|
|
1
2
|
//#region src/utilities/OverlayManager.ts
|
|
2
3
|
/**
|
|
3
4
|
* OverlayManager는 **겹치는 표면 전체의 층(layer)을 소유**합니다.
|
|
@@ -86,7 +87,7 @@ var OverlayManager = class OverlayManager {
|
|
|
86
87
|
}
|
|
87
88
|
static {
|
|
88
89
|
this.handleLayerKeydown = (e) => {
|
|
89
|
-
if (e.key !== "Escape" || e
|
|
90
|
+
if (e.key !== "Escape" || isImeComposing(e) || e.defaultPrevented) return;
|
|
90
91
|
const top = OverlayManager.layers[OverlayManager.layers.length - 1];
|
|
91
92
|
if (!top) return;
|
|
92
93
|
if (top.onEscape(e) === false) return;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a key event belongs to an IME composition — typing Korean, Japanese, Chinese and other
|
|
3
|
+
* languages that build a character from several keystrokes.
|
|
4
|
+
*
|
|
5
|
+
* The Enter (or Escape) that confirms a composition is not a command: a handler that submits,
|
|
6
|
+
* commits a cell or closes a layer on Enter should ignore it, or the last syllable is sent twice
|
|
7
|
+
* or the action fires in the middle of a word.
|
|
8
|
+
*
|
|
9
|
+
* `isComposing` alone is not enough — Safari delivers the confirming key after `compositionend`,
|
|
10
|
+
* with `isComposing` false and `keyCode` 229 ("IME is processing").
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* onKeydown(e: KeyboardEvent) {
|
|
15
|
+
* if (e.key !== 'Enter' || isImeComposing(e)) return;
|
|
16
|
+
* this.submit();
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function isImeComposing(e: KeyboardEvent): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/utilities/keyboard.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whether a key event belongs to an IME composition — typing Korean, Japanese, Chinese and other
|
|
4
|
+
* languages that build a character from several keystrokes.
|
|
5
|
+
*
|
|
6
|
+
* The Enter (or Escape) that confirms a composition is not a command: a handler that submits,
|
|
7
|
+
* commits a cell or closes a layer on Enter should ignore it, or the last syllable is sent twice
|
|
8
|
+
* or the action fires in the middle of a word.
|
|
9
|
+
*
|
|
10
|
+
* `isComposing` alone is not enough — Safari delivers the confirming key after `compositionend`,
|
|
11
|
+
* with `isComposing` false and `keyCode` 229 ("IME is processing").
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* onKeydown(e: KeyboardEvent) {
|
|
16
|
+
* if (e.key !== 'Enter' || isImeComposing(e)) return;
|
|
17
|
+
* this.submit();
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function isImeComposing(e) {
|
|
22
|
+
return e.isComposing || e.keyCode === 229;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { isImeComposing };
|
|
@@ -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
|
@@ -134,6 +134,8 @@ carries the control's role, not on the host element. Native nodes use native `di
|
|
|
134
134
|
- [`Locale`](./references/utilities/locale.md) — Validation-message locale registry and lookup utility
|
|
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
|
+
- [`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
|
|
137
139
|
- [`OverlayManager`](./references/utilities/overlay-manager.md) — Internal overlay stack and z-index manager
|
|
138
140
|
|
|
139
141
|
---
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# keyboard
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { isImeComposing } from '@iyulab/components';
|
|
5
|
+
// or: import { isImeComposing } from '@iyulab/components/dist/utilities/keyboard.js';
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
## `isImeComposing(event: KeyboardEvent): boolean`
|
|
9
|
+
|
|
10
|
+
Whether a key event belongs to an IME composition — typing Korean, Japanese, Chinese and other
|
|
11
|
+
languages that build a character from several keystrokes.
|
|
12
|
+
|
|
13
|
+
The Enter (or Escape) that confirms a composition is not a command. A handler that submits, commits a
|
|
14
|
+
cell, or closes a layer on Enter should ignore it; otherwise the action fires in the middle of a word,
|
|
15
|
+
or the last syllable is committed after the action and sent twice.
|
|
16
|
+
|
|
17
|
+
`event.isComposing` alone is not enough: Safari delivers the confirming key after `compositionend`,
|
|
18
|
+
with `isComposing` false and `keyCode` 229. This helper checks both.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
onKeydown(e: KeyboardEvent) {
|
|
22
|
+
if (e.key !== 'Enter' || isImeComposing(e)) return;
|
|
23
|
+
this.submit();
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`u-input` (implicit form submission), `Dialog.prompt`, and the overlay Escape handling already use it.
|
|
@@ -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.
|