@iyulab/components 2.0.2 → 2.1.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 +24 -0
- package/dist/components/menu/UMenu.js +2 -0
- package/dist/components/menu-item/UMenuItem.js +2 -0
- package/dist/components/tab-panel/UTabPanel.js +2 -1
- package/dist/components/tree/UTree.js +2 -0
- package/dist/components/tree-item/UTreeItem.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/utilities/clipboard.d.ts +36 -0
- package/dist/utilities/clipboard.js +87 -0
- package/dist/utilities/nestedControl.d.ts +10 -0
- package/dist/utilities/nestedControl.js +20 -0
- package/package.json +1 -1
- package/skills/iyulab-components/SKILL.md +1 -0
- package/skills/iyulab-components/references/components/menu.md +3 -0
- package/skills/iyulab-components/references/components/tab-panel.md +3 -0
- package/skills/iyulab-components/references/components/tree.md +3 -0
- package/skills/iyulab-components/references/utilities/clipboard.md +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.1.0] - 2026-10-06
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`copyFromKey(text)` / `pasteFromKey()`** — Ctrl/Cmd + C, X and V for something that is not a text
|
|
8
|
+
field (a grid's selected cells, a list's selected rows), working in every browser. They use the
|
|
9
|
+
browser's `copy`/`cut`/`paste` event and its `clipboardData` when the browser fires one — no
|
|
10
|
+
permission, any page — and the async Clipboard API when it does not: Safari fires no `copy` event
|
|
11
|
+
without a text selection. `copyFromKey` resolves `true` only once the text is on the clipboard, so a
|
|
12
|
+
cut can clear its selection safely. Call them from the shortcut's `keydown` without preventing the
|
|
13
|
+
key.
|
|
14
|
+
|
|
15
|
+
## [2.0.3] - 2026-10-06
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **A control in a tree item, menu item or tab slot keeps its own keys and clicks** (`u-tree-item`,
|
|
20
|
+
`u-menu-item`, `u-tab`). A button placed in the `prefix`/`suffix` slot could not be pressed from
|
|
21
|
+
the keyboard — Enter and Space were taken by the tree or menu and selected the item instead — an
|
|
22
|
+
arrow key on it moved to the next item, and a mouse click on it also selected or expanded the item
|
|
23
|
+
and stopped there, so a listener outside never saw it. Keys and clicks from such a control now go
|
|
24
|
+
to the control only; the item's keyboard model applies while the item itself has focus, as with
|
|
25
|
+
interactive content inside `<summary>` or `<label>`.
|
|
26
|
+
|
|
3
27
|
## [2.0.2] - 2026-10-06
|
|
4
28
|
|
|
5
29
|
### Fixed
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
2
|
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
3
|
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
|
+
import { isFromNestedControl } from "../../utilities/nestedControl.js";
|
|
4
5
|
import { UMenuItem } from "../menu-item/UMenuItem.js";
|
|
5
6
|
import { styles } from "./UMenu.styles.js";
|
|
6
7
|
import { html } from "lit";
|
|
@@ -38,6 +39,7 @@ var UMenu = class UMenu extends UElement {
|
|
|
38
39
|
this.handleKeydown = (e) => {
|
|
39
40
|
const focused = e.composedPath().find((el) => el instanceof UMenuItem);
|
|
40
41
|
if (!focused) return;
|
|
42
|
+
if (isFromNestedControl(e, focused)) return;
|
|
41
43
|
const items = this.inline ? this.getItems((item) => {
|
|
42
44
|
if (item.disabled) return false;
|
|
43
45
|
let current = item.parentItem;
|
|
@@ -5,6 +5,7 @@ import "../icon/UIcon.js";
|
|
|
5
5
|
import "../popover/UPopover.js";
|
|
6
6
|
import { UDivider } from "../divider/UDivider.js";
|
|
7
7
|
import { styles } from "./UMenuItem.styles.js";
|
|
8
|
+
import { isFromNestedControl } from "../../utilities/nestedControl.js";
|
|
8
9
|
import { html } from "lit";
|
|
9
10
|
import { customElement, property, state } from "lit/decorators.js";
|
|
10
11
|
import { live } from "lit/directives/live.js";
|
|
@@ -28,6 +29,7 @@ var UMenuItem = class UMenuItem extends UElement {
|
|
|
28
29
|
this._parentItem = null;
|
|
29
30
|
this._childItems = [];
|
|
30
31
|
this.handleHeaderClick = (e) => {
|
|
32
|
+
if (isFromNestedControl(e, this)) return;
|
|
31
33
|
e.stopPropagation();
|
|
32
34
|
if (this.disabled) return;
|
|
33
35
|
if (!this.leaf) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
2
|
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
3
|
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
|
+
import { isFromNestedControl } from "../../utilities/nestedControl.js";
|
|
4
5
|
import { UPanel } from "../panel/UPanel.js";
|
|
5
6
|
import { UTab } from "../tab/UTab.js";
|
|
6
7
|
import { styles } from "./UTabPanel.styles.js";
|
|
@@ -44,7 +45,7 @@ var UTabPanel = class UTabPanel extends UElement {
|
|
|
44
45
|
this.change(tab.value);
|
|
45
46
|
};
|
|
46
47
|
this.handleTabKeydown = (e) => {
|
|
47
|
-
if (e
|
|
48
|
+
if (isFromNestedControl(e, e.currentTarget)) return;
|
|
48
49
|
const enabledTabs = this.tabs.filter((t) => !t.disabled);
|
|
49
50
|
const currentIndex = enabledTabs.indexOf(e.currentTarget);
|
|
50
51
|
if (currentIndex === -1) return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
2
|
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
3
|
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
|
+
import { isFromNestedControl } from "../../utilities/nestedControl.js";
|
|
4
5
|
import { UTreeItem } from "../tree-item/UTreeItem.js";
|
|
5
6
|
import { styles } from "./UTree.styles.js";
|
|
6
7
|
import { html } from "lit";
|
|
@@ -71,6 +72,7 @@ var UTree = class UTree extends UElement {
|
|
|
71
72
|
this.handleKeydown = (e) => {
|
|
72
73
|
const focused = e.composedPath().find((el) => el instanceof UTreeItem);
|
|
73
74
|
if (!focused) return;
|
|
75
|
+
if (isFromNestedControl(e, focused)) return;
|
|
74
76
|
const items = this.getItems((item) => !item.disabled && (!item.parentItem || item.parentItem.expanded));
|
|
75
77
|
if (items.length === 0) return;
|
|
76
78
|
const current = focused ? items.indexOf(focused) : -1;
|
|
@@ -3,6 +3,7 @@ import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/hel
|
|
|
3
3
|
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
4
|
import "../spinner/USpinner.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
|
+
import { isFromNestedControl } from "../../utilities/nestedControl.js";
|
|
6
7
|
import { styles } from "./UTreeItem.styles.js";
|
|
7
8
|
import { html } from "lit";
|
|
8
9
|
import { customElement, property, state } from "lit/decorators.js";
|
|
@@ -40,6 +41,7 @@ var UTreeItem = class UTreeItem extends UElement {
|
|
|
40
41
|
this.propagate();
|
|
41
42
|
};
|
|
42
43
|
this.handleHeaderClick = (e) => {
|
|
44
|
+
if (isFromNestedControl(e, this)) return;
|
|
43
45
|
e.stopPropagation();
|
|
44
46
|
if (this.disabled) return;
|
|
45
47
|
if (this.selectable) this.fire("pick", { detail: {
|
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export * from './events/RemoveEvent';
|
|
|
60
60
|
export * from './events/ShiftEvent';
|
|
61
61
|
export * from './events/ShowEvent';
|
|
62
62
|
export * from './utilities/BrowserStorage.js';
|
|
63
|
+
export * from './utilities/clipboard.js';
|
|
63
64
|
export * from './utilities/converters.js';
|
|
64
65
|
export * from './utilities/devWarning.js';
|
|
65
66
|
export * from './utilities/Dialog.js';
|
package/dist/index.js
CHANGED
|
@@ -59,8 +59,9 @@ import { UTextarea } from "./components/textarea/UTextarea.js";
|
|
|
59
59
|
import { UTreeItem } from "./components/tree-item/UTreeItem.js";
|
|
60
60
|
import { UTree } from "./components/tree/UTree.js";
|
|
61
61
|
import { BrowserStorage } from "./utilities/BrowserStorage.js";
|
|
62
|
+
import { copyFromKey, pasteFromKey } from "./utilities/clipboard.js";
|
|
62
63
|
import { Dialog } from "./utilities/Dialog.js";
|
|
63
64
|
import { Theme } from "./utilities/Theme.js";
|
|
64
65
|
import { Toast } from "./utilities/Toast.js";
|
|
65
66
|
import { decodeTsv, encodeTsv } from "./utilities/tsv.js";
|
|
66
|
-
export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDateRangePicker, 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, USteps, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, createDevWarner, dateAttrConverter, dateTextPattern, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
|
|
67
|
+
export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDateRangePicker, 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, USteps, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, copyFromKey, createDevWarner, dateAttrConverter, dateTextPattern, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, pasteFromKey, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy and paste for a keyboard shortcut on something that is not a text field — a grid's selected
|
|
3
|
+
* cells, a list's selected rows.
|
|
4
|
+
*
|
|
5
|
+
* Neither browser mechanism works everywhere on its own:
|
|
6
|
+
* - The browser's `copy`/`cut`/`paste` events carry `clipboardData`, need no permission and work on
|
|
7
|
+
* any page — but Safari fires `copy`/`cut` only when the page has a text selection, so a grid
|
|
8
|
+
* whose selection is its own state never gets one there.
|
|
9
|
+
* - The async Clipboard API (`navigator.clipboard`) works in Safari inside the key press — but it
|
|
10
|
+
* needs a secure context, may be refused, and `readText()` asks the person (or is missing).
|
|
11
|
+
*
|
|
12
|
+
* These helpers use the event when the browser fires it and the Clipboard API when it does not. Call
|
|
13
|
+
* them from the `keydown` handler of the shortcut and **do not `preventDefault()` that key** — the
|
|
14
|
+
* browser's own copy or paste is what fires the event.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* onKeydown(e: KeyboardEvent) {
|
|
19
|
+
* if ((e.ctrlKey || e.metaKey) && e.key === 'x') {
|
|
20
|
+
* const range = this.selection;
|
|
21
|
+
* copyFromKey(this.selectionAsTsv()).then((ok) => { if (ok) this.clear(range); });
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Puts `text` on the clipboard for the copy or cut key being pressed. Resolves `true` once the text
|
|
28
|
+
* is on the clipboard, `false` when neither the browser's copy event nor the Clipboard API took it —
|
|
29
|
+
* clear a cut selection only on `true`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function copyFromKey(text: string): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Reads the clipboard text for the paste key being pressed — from the browser's paste event, or, when
|
|
34
|
+
* none comes, from the Clipboard API. Rejects with the Clipboard API's error when neither gives text.
|
|
35
|
+
*/
|
|
36
|
+
export declare function pasteFromKey(): Promise<string>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
//#region src/utilities/clipboard.ts
|
|
2
|
+
/**
|
|
3
|
+
* Copy and paste for a keyboard shortcut on something that is not a text field — a grid's selected
|
|
4
|
+
* cells, a list's selected rows.
|
|
5
|
+
*
|
|
6
|
+
* Neither browser mechanism works everywhere on its own:
|
|
7
|
+
* - The browser's `copy`/`cut`/`paste` events carry `clipboardData`, need no permission and work on
|
|
8
|
+
* any page — but Safari fires `copy`/`cut` only when the page has a text selection, so a grid
|
|
9
|
+
* whose selection is its own state never gets one there.
|
|
10
|
+
* - The async Clipboard API (`navigator.clipboard`) works in Safari inside the key press — but it
|
|
11
|
+
* needs a secure context, may be refused, and `readText()` asks the person (or is missing).
|
|
12
|
+
*
|
|
13
|
+
* These helpers use the event when the browser fires it and the Clipboard API when it does not. Call
|
|
14
|
+
* them from the `keydown` handler of the shortcut and **do not `preventDefault()` that key** — the
|
|
15
|
+
* browser's own copy or paste is what fires the event.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* onKeydown(e: KeyboardEvent) {
|
|
20
|
+
* if ((e.ctrlKey || e.metaKey) && e.key === 'x') {
|
|
21
|
+
* const range = this.selection;
|
|
22
|
+
* copyFromKey(this.selectionAsTsv()).then((ok) => { if (ok) this.clear(range); });
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Puts `text` on the clipboard for the copy or cut key being pressed. Resolves `true` once the text
|
|
29
|
+
* is on the clipboard, `false` when neither the browser's copy event nor the Clipboard API took it —
|
|
30
|
+
* clear a cut selection only on `true`.
|
|
31
|
+
*/
|
|
32
|
+
function copyFromKey(text) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
let settled = false;
|
|
35
|
+
const finish = (ok) => {
|
|
36
|
+
if (settled) return;
|
|
37
|
+
settled = true;
|
|
38
|
+
window.removeEventListener("copy", onEvent, true);
|
|
39
|
+
window.removeEventListener("cut", onEvent, true);
|
|
40
|
+
resolve(ok);
|
|
41
|
+
};
|
|
42
|
+
const onEvent = (e) => {
|
|
43
|
+
if (!e.clipboardData) return;
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
e.clipboardData.setData("text/plain", text);
|
|
46
|
+
finish(true);
|
|
47
|
+
};
|
|
48
|
+
window.addEventListener("copy", onEvent, true);
|
|
49
|
+
window.addEventListener("cut", onEvent, true);
|
|
50
|
+
const write = navigator.clipboard?.writeText?.(text);
|
|
51
|
+
if (!write) {
|
|
52
|
+
setTimeout(() => finish(false));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
write.then(() => finish(true), () => setTimeout(() => finish(false)));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Reads the clipboard text for the paste key being pressed — from the browser's paste event, or, when
|
|
60
|
+
* none comes, from the Clipboard API. Rejects with the Clipboard API's error when neither gives text.
|
|
61
|
+
*/
|
|
62
|
+
function pasteFromKey() {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
let settled = false;
|
|
65
|
+
const onEvent = (e) => {
|
|
66
|
+
if (settled || !e.clipboardData) return;
|
|
67
|
+
settled = true;
|
|
68
|
+
window.removeEventListener("paste", onEvent, true);
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
resolve(e.clipboardData.getData("text/plain"));
|
|
71
|
+
};
|
|
72
|
+
window.addEventListener("paste", onEvent, true);
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
if (settled) return;
|
|
75
|
+
settled = true;
|
|
76
|
+
window.removeEventListener("paste", onEvent, true);
|
|
77
|
+
const read = navigator.clipboard?.readText?.();
|
|
78
|
+
if (!read) {
|
|
79
|
+
reject(/* @__PURE__ */ new Error("Clipboard read is not available"));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
read.then(resolve, reject);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { copyFromKey, pasteFromKey };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 이벤트가 `owner` «안의» 다른 상호작용 요소(포커스를 받는 요소)에서 왔는가.
|
|
3
|
+
*
|
|
4
|
+
* 항목(탭 · 트리 항목 · 메뉴 항목)은 슬롯으로 버튼 같은 컨트롤을 받는다. 그 컨트롤의 키와 클릭은 컨트롤의 것이다 —
|
|
5
|
+
* `<summary>`·`<label>` 안의 상호작용 콘텐츠가 조상을 활성화하지 않는 것과 같다. 항목의 키보드 모델과 클릭 활성화는
|
|
6
|
+
* 이것이 거짓일 때만 해석한다.
|
|
7
|
+
*
|
|
8
|
+
* 내부 모듈이다 — 배럴에서 내보내지 않는다.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isFromNestedControl(e: Event, owner: Element): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isFocusable } from "tabbable";
|
|
2
|
+
//#region src/utilities/nestedControl.ts
|
|
3
|
+
/**
|
|
4
|
+
* 이벤트가 `owner` «안의» 다른 상호작용 요소(포커스를 받는 요소)에서 왔는가.
|
|
5
|
+
*
|
|
6
|
+
* 항목(탭 · 트리 항목 · 메뉴 항목)은 슬롯으로 버튼 같은 컨트롤을 받는다. 그 컨트롤의 키와 클릭은 컨트롤의 것이다 —
|
|
7
|
+
* `<summary>`·`<label>` 안의 상호작용 콘텐츠가 조상을 활성화하지 않는 것과 같다. 항목의 키보드 모델과 클릭 활성화는
|
|
8
|
+
* 이것이 거짓일 때만 해석한다.
|
|
9
|
+
*
|
|
10
|
+
* 내부 모듈이다 — 배럴에서 내보내지 않는다.
|
|
11
|
+
*/
|
|
12
|
+
function isFromNestedControl(e, owner) {
|
|
13
|
+
for (const node of e.composedPath()) {
|
|
14
|
+
if (node === owner) return false;
|
|
15
|
+
if (node instanceof Element && isFocusable(node)) return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isFromNestedControl };
|
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
|
- [`Locale`](./references/utilities/locale.md) — Validation-message locale registry and lookup utility
|
|
136
136
|
- [`elements`](./references/utilities/elements.md) — Shadow-DOM-aware DOM query helpers
|
|
137
137
|
- [`format`](./references/utilities/format.md) — Locale-aware number, currency and date formatting
|
|
138
|
+
- [`clipboard`](./references/utilities/clipboard.md) — `copyFromKey` / `pasteFromKey`, Ctrl/Cmd + C · X · V for a grid or list selection in every browser (Safari fires no copy event without a text selection)
|
|
138
139
|
- [`keyboard`](./references/utilities/keyboard.md) — `isImeComposing` for Enter handlers that must not fire mid-composition (Korean/Japanese/Chinese input)
|
|
139
140
|
- [`tsv`](./references/utilities/tsv.md) — `encodeTsv` / `decodeTsv`, the spreadsheet clipboard format with RFC 4180 quoting
|
|
140
141
|
- [`OverlayManager`](./references/utilities/overlay-manager.md) — Internal overlay stack and z-index manager
|
|
@@ -79,6 +79,9 @@ Keyboard-navigable menu. Supports single/multiple selection, highlight or checkm
|
|
|
79
79
|
| `suffix` | Trailing content |
|
|
80
80
|
| `children` | Nested `u-menu` for sub-menu |
|
|
81
81
|
|
|
82
|
+
A control placed in a slot (a button, a link) keeps its own keys and clicks — it does not select or
|
|
83
|
+
activate the menu item, and the menu item's arrow-key navigation applies only while the menu item itself has focus.
|
|
84
|
+
|
|
82
85
|
### Properties
|
|
83
86
|
|
|
84
87
|
| Property | Type | Default | Reflect | Description |
|
|
@@ -101,6 +101,9 @@ selected tab is a tab stop (arrow keys, Home and End move between tabs and selec
|
|
|
101
101
|
| *(default)* | Tab label |
|
|
102
102
|
| `suffix` | Trailing content |
|
|
103
103
|
|
|
104
|
+
A control placed in a slot (a button, a link) keeps its own keys and clicks — it does not select or
|
|
105
|
+
activate the tab, and the tab's arrow-key navigation applies only while the tab itself has focus.
|
|
106
|
+
|
|
104
107
|
### Properties
|
|
105
108
|
|
|
106
109
|
| Property | Type | Default | Reflect | Description |
|
|
@@ -87,6 +87,9 @@ Hierarchical tree with support for selection, checkboxes, cascade check, and dra
|
|
|
87
87
|
| *(default)* | Item label |
|
|
88
88
|
| `suffix` | Trailing content |
|
|
89
89
|
|
|
90
|
+
A control placed in a slot (a button, a link) keeps its own keys and clicks — it does not select or
|
|
91
|
+
activate the tree item, and the tree item's arrow-key navigation applies only while the tree item itself has focus.
|
|
92
|
+
|
|
90
93
|
### Properties
|
|
91
94
|
|
|
92
95
|
| Property | Type | Default | Reflect | Description |
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# clipboard
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { copyFromKey, pasteFromKey } from '@iyulab/components';
|
|
5
|
+
// or: import { copyFromKey, pasteFromKey } from '@iyulab/components/dist/utilities/clipboard.js';
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
Copy and paste for a keyboard shortcut on something that is not a text field — a grid's selected
|
|
9
|
+
cells, a list's selected rows.
|
|
10
|
+
|
|
11
|
+
Neither browser mechanism works everywhere on its own:
|
|
12
|
+
|
|
13
|
+
- The browser's `copy` / `cut` / `paste` events carry `clipboardData`, need no permission and work on
|
|
14
|
+
any page — but **Safari fires `copy`/`cut` only when the page has a text selection**, so a grid
|
|
15
|
+
whose selection is its own state never gets one there.
|
|
16
|
+
- The async Clipboard API works in Safari inside the key press — but it needs a secure context, may be
|
|
17
|
+
refused, and `readText()` asks the person (or is missing).
|
|
18
|
+
|
|
19
|
+
These helpers use the event when the browser fires it and the Clipboard API when it does not. Call
|
|
20
|
+
them from the shortcut's `keydown` handler and **do not `preventDefault()` that key** — the browser's
|
|
21
|
+
own copy or paste is what fires the event.
|
|
22
|
+
|
|
23
|
+
## `copyFromKey(text: string): Promise<boolean>`
|
|
24
|
+
|
|
25
|
+
Puts `text` on the clipboard. Resolves `true` once it is there, `false` when neither path took it. A
|
|
26
|
+
cut clears its selection only on `true` — otherwise the data is gone without being on the clipboard.
|
|
27
|
+
|
|
28
|
+
## `pasteFromKey(): Promise<string>`
|
|
29
|
+
|
|
30
|
+
Reads the clipboard text — from the paste event, or, when none comes, from `navigator.clipboard.readText()`.
|
|
31
|
+
Rejects with the Clipboard API's error when neither gives text.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
onKeydown(e: KeyboardEvent) {
|
|
35
|
+
if (!(e.ctrlKey || e.metaKey) || this.editing) return; // a text field keeps its own clipboard
|
|
36
|
+
const key = e.key.toLowerCase();
|
|
37
|
+
if (key === 'c' || key === 'x') {
|
|
38
|
+
const range = this.selection;
|
|
39
|
+
copyFromKey(encodeTsv(this.cells(range))).then((ok) => {
|
|
40
|
+
if (ok && key === 'x') this.clear(range);
|
|
41
|
+
});
|
|
42
|
+
} else if (key === 'v') {
|
|
43
|
+
pasteFromKey().then((text) => this.paste(decodeTsv(text)), (error) => this.report(error));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`flex-table`, `u-simple-sheet` and `u-rich-table` use them for Ctrl/Cmd + C, X and V.
|