@iyulab/components 2.34.0 → 2.35.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 +43 -0
- package/README.md +1 -1
- package/dist/assets/locales/ar.json.js +3 -1
- package/dist/assets/locales/de.json.js +3 -1
- package/dist/assets/locales/en.json.js +3 -1
- package/dist/assets/locales/es.json.js +3 -1
- package/dist/assets/locales/fr.json.js +3 -1
- package/dist/assets/locales/id.json.js +3 -1
- package/dist/assets/locales/ja.json.js +3 -1
- package/dist/assets/locales/ko.json.js +3 -1
- package/dist/assets/locales/pt-BR.json.js +3 -1
- package/dist/assets/locales/ru.json.js +3 -1
- package/dist/assets/locales/th.json.js +3 -1
- package/dist/assets/locales/vi.json.js +3 -1
- package/dist/assets/locales/zh-CN.json.js +3 -1
- package/dist/assets/locales/zh-TW.json.js +3 -1
- package/dist/components/UOverlayElement.d.ts +2 -0
- package/dist/components/UOverlayElement.js +6 -0
- package/dist/components/auto-scroll/UAutoScroll.d.ts +12 -0
- package/dist/components/auto-scroll/UAutoScroll.js +30 -0
- package/dist/components/carousel/UCarousel.d.ts +33 -0
- package/dist/components/carousel/UCarousel.js +33 -3
- package/dist/components/command-palette/UCommandPalette.d.ts +126 -0
- package/dist/components/command-palette/UCommandPalette.js +260 -0
- package/dist/components/command-palette/UCommandPalette.styles.d.ts +1 -0
- package/dist/components/command-palette/UCommandPalette.styles.js +142 -0
- package/dist/components/select/USelect.d.ts +15 -0
- package/dist/components/select/USelect.js +48 -12
- package/dist/components/select/USelect.styles.js +5 -0
- package/dist/components/steps/USteps.d.ts +14 -3
- package/dist/components/steps/USteps.js +12 -2
- package/dist/components/steps/USteps.styles.js +53 -0
- package/dist/components/tab/UTab.d.ts +9 -3
- package/dist/components/tab/UTab.js +8 -3
- package/dist/components/tab/UTab.styles.js +21 -0
- package/dist/components/tab-nav/UTabNav.d.ts +10 -1
- package/dist/components/tab-nav/UTabNav.js +5 -0
- package/dist/components/tab-nav/UTabNav.styles.js +24 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/react/UCarousel.d.ts +3 -1
- package/dist/react/UCarousel.js +3 -1
- package/dist/react/UCommandPalette.d.ts +20 -0
- package/dist/react/UCommandPalette.js +14 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/utilities/Locale.d.ts +1 -1
- package/package.json +1 -1
- package/skills/iyulab-components/SKILL.md +1 -0
- package/skills/iyulab-components/references/components/auto-scroll.md +19 -2
- package/skills/iyulab-components/references/components/carousel.md +21 -0
- package/skills/iyulab-components/references/components/command-palette.md +96 -0
- package/skills/iyulab-components/references/components/select.md +1 -1
- package/skills/iyulab-components/references/components/steps.md +16 -1
- package/skills/iyulab-components/references/components/tab-nav.md +19 -1
- package/skills/iyulab-components/references/components/tab-panel.md +1 -1
|
@@ -51,9 +51,20 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
51
51
|
};
|
|
52
52
|
this.goTo = (index) => {
|
|
53
53
|
if (index < 0 || index > this.maxIndex || index === this.index) return;
|
|
54
|
+
const previousIndex = this.index;
|
|
54
55
|
this.index = index;
|
|
55
56
|
if (this.rotating) this.startAutoplay();
|
|
57
|
+
this.fire("change", {
|
|
58
|
+
detail: {
|
|
59
|
+
index,
|
|
60
|
+
previousIndex,
|
|
61
|
+
cause: this.moveCause
|
|
62
|
+
},
|
|
63
|
+
bubbles: false,
|
|
64
|
+
composed: false
|
|
65
|
+
});
|
|
56
66
|
};
|
|
67
|
+
this.moveCause = "user";
|
|
57
68
|
this.handleDragStart = (e) => {
|
|
58
69
|
e.preventDefault();
|
|
59
70
|
};
|
|
@@ -188,6 +199,7 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
188
199
|
}
|
|
189
200
|
updated(changedProperties) {
|
|
190
201
|
super.updated(changedProperties);
|
|
202
|
+
if (changedProperties.has("index") || changedProperties.has("slideCount") || changedProperties.has("slidesPerView")) this.syncInertSlides();
|
|
191
203
|
if (changedProperties.has("autoplay") || changedProperties.has("autoplayInterval") || changedProperties.has("rotationStopped") || changedProperties.has("hovered")) {
|
|
192
204
|
if (this.rotating) this.startAutoplay();
|
|
193
205
|
else this.stopAutoplay();
|
|
@@ -272,7 +284,12 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
272
284
|
startAutoplay() {
|
|
273
285
|
this.stopAutoplay();
|
|
274
286
|
this.autoplayTimer = window.setInterval(() => {
|
|
275
|
-
this.
|
|
287
|
+
this.moveCause = "autoplay";
|
|
288
|
+
try {
|
|
289
|
+
this.next();
|
|
290
|
+
} finally {
|
|
291
|
+
this.moveCause = "user";
|
|
292
|
+
}
|
|
276
293
|
}, this.autoplayInterval);
|
|
277
294
|
}
|
|
278
295
|
stopAutoplay() {
|
|
@@ -302,7 +319,8 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
302
319
|
owned = [
|
|
303
320
|
"role",
|
|
304
321
|
"aria-roledescription",
|
|
305
|
-
"aria-label"
|
|
322
|
+
"aria-label",
|
|
323
|
+
"inert"
|
|
306
324
|
].filter((name) => !slide.hasAttribute(name));
|
|
307
325
|
this.ownedSlideAttrs.set(slide, owned);
|
|
308
326
|
}
|
|
@@ -314,7 +332,19 @@ var UCarousel = class UCarousel extends UElement {
|
|
|
314
332
|
total
|
|
315
333
|
})
|
|
316
334
|
};
|
|
317
|
-
for (const name of owned) slide.setAttribute(name, values[name]);
|
|
335
|
+
for (const name of owned) if (name in values) slide.setAttribute(name, values[name]);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* 보이지 않는 장을 `inert` 로 — 화면 밖 장의 링크 · 단추가 Tab 순서에 남고 읽기 순서에서 보이는 장과 섞이지 않게(APG Carousel).
|
|
339
|
+
* 여러 장을 함께 보이면(`slides-per-view`) 그 범위 밖만. 소비자가 처음부터 단 `inert` 는 우리 것이 아니라 건드리지 않는다.
|
|
340
|
+
*/
|
|
341
|
+
syncInertSlides() {
|
|
342
|
+
const from = this.index;
|
|
343
|
+
const to = this.index + this.perView;
|
|
344
|
+
this.slides.forEach((slide, i) => {
|
|
345
|
+
if (!this.ownedSlideAttrs.get(slide)?.includes("inert")) return;
|
|
346
|
+
slide.toggleAttribute("inert", i < from || i >= to);
|
|
347
|
+
});
|
|
318
348
|
}
|
|
319
349
|
/** 슬롯을 떠난 슬라이드에서 우리가 단 속성을 걷는다. */
|
|
320
350
|
releaseSlide(slide) {
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { CSSResultGroup, PropertyValues } from 'lit';
|
|
2
|
+
import { UOverlayElement } from '../UOverlayElement.js';
|
|
3
|
+
/** 팔레트의 항목 하나. */
|
|
4
|
+
export interface CommandItem {
|
|
5
|
+
/** 출처 안에서 고유한 값. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** 보이는 이름. */
|
|
8
|
+
label: string;
|
|
9
|
+
/** 이름 옆의 보조 글(경로 · 상태 등). 접근 가능한 설명으로도 나간다. */
|
|
10
|
+
description?: string;
|
|
11
|
+
/** 아이콘 이름(`u-icon` 의 `name`). */
|
|
12
|
+
icon?: string;
|
|
13
|
+
/** 아이콘 라이브러리(`u-icon` 의 `lib`). */
|
|
14
|
+
iconLib?: string;
|
|
15
|
+
/** 고르면 갈 곳. `command` 이벤트를 취소하지 않으면 그 주소로 이동한다. */
|
|
16
|
+
href?: string;
|
|
17
|
+
/** 일치 판정에 함께 쓰는 낱말(`filterCommands` 가 본다). */
|
|
18
|
+
keywords?: string[];
|
|
19
|
+
/** 앱이 실어 두는 값 — 팔레트는 읽지 않는다. */
|
|
20
|
+
data?: unknown;
|
|
21
|
+
}
|
|
22
|
+
/** 출처의 검색 — 새 검색어가 오면 이전 요청의 `signal` 이 중단된다. */
|
|
23
|
+
export type CommandSearch = (query: string, options: {
|
|
24
|
+
signal: AbortSignal;
|
|
25
|
+
}) => CommandItem[] | Promise<CommandItem[]>;
|
|
26
|
+
/** 항목을 내는 곳 하나 — 결과는 출처 순서대로 묶이고 묶음 머리는 `label` 이다. */
|
|
27
|
+
export interface CommandSource {
|
|
28
|
+
/** 출처의 고유값(`command` 이벤트의 `source`). */
|
|
29
|
+
id: string;
|
|
30
|
+
/** 묶음 머리. */
|
|
31
|
+
label: string;
|
|
32
|
+
search: CommandSearch;
|
|
33
|
+
}
|
|
34
|
+
/** `command` 이벤트의 detail. */
|
|
35
|
+
export interface UCommandPaletteCommandDetail {
|
|
36
|
+
item: CommandItem;
|
|
37
|
+
/** 그 항목을 낸 출처의 `id`. */
|
|
38
|
+
source: string;
|
|
39
|
+
}
|
|
40
|
+
/** Events `<u-command-palette>` dispatches (plus `show` · `hide` from the overlay base). */
|
|
41
|
+
export interface UCommandPaletteEventMap {
|
|
42
|
+
/** An item was chosen (Enter or click). Cancelable — when not canceled and the item has `href`, the page goes there. Does not bubble. */
|
|
43
|
+
'command': CustomEvent<UCommandPaletteCommandDetail>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 정적 항목을 검색어로 거른다 — 이름 · 설명 · 낱말을 활성 로케일의 검색 일치로 견준다(`u-select` 와 같은 규칙). 빈 검색어는 모두다.
|
|
47
|
+
* 출처의 `search` 를 짓는 도우미: `search: (q) => filterCommands(items, q)`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function filterCommands(items: readonly CommandItem[], query: string): CommandItem[];
|
|
50
|
+
/**
|
|
51
|
+
* 명령 팔레트 — 한 칸에서 화면 · 레코드 · 동작을 찾아 고른다(Ctrl/⌘ K 류). 대화상자 안의 검색 칸(WAI-ARIA APG combobox)과
|
|
52
|
+
* 결과 목록(listbox)이고, 결과는 출처(`sources`)마다 묶인다.
|
|
53
|
+
*
|
|
54
|
+
* - 열면 칸에 초점이 가고 빈 검색어로 출처를 부른다(최근 항목 · 화면 목록처럼 «찾기 전» 에 보일 것). 치면 `debounce` 뒤에 다시
|
|
55
|
+
* 부르고, 새 검색어는 이전 요청을 `AbortSignal` 로 중단한다. 한 출처의 실패 · 지연은 다른 출처의 결과를 막지 않는다.
|
|
56
|
+
* - ↑ ↓ 로 항목을 옮기고(끝에서 처음으로 돈다) Enter 로 고른다 · Escape 로 닫는다. 입력기 조합을 확정하는 Enter 는 고르지 않는다.
|
|
57
|
+
* - 고르면 `command` 를 내고 닫는다. 취소하지 않았고 항목에 `href` 가 있으면 그 주소로 간다 — 클라이언트 라우터를 쓰는 앱은
|
|
58
|
+
* 취소하고 스스로 옮긴다. 닫으면 열기 전의 초점으로 돌아간다.
|
|
59
|
+
*
|
|
60
|
+
* 단축키(Ctrl/⌘ K)는 이 요소가 걸지 않는다 — 어디서 여는가는 앱(또는 셸)의 몫이다.
|
|
61
|
+
*
|
|
62
|
+
* @event command - 항목을 골랐다. `detail: { item, source }` · 취소 가능 · 거품 없음.
|
|
63
|
+
* @event show - 열리기 직전(취소하면 열리지 않는다).
|
|
64
|
+
* @event hide - 닫히기 직전(취소하면 닫히지 않는다).
|
|
65
|
+
*
|
|
66
|
+
* @csspart panel - 대화상자 상자
|
|
67
|
+
* @csspart input - 검색 칸
|
|
68
|
+
* @csspart listbox - 결과 목록
|
|
69
|
+
* @csspart group-label - 묶음 머리
|
|
70
|
+
* @csspart option - 항목
|
|
71
|
+
* @csspart status - 불러오는 중 · 결과 없음 · 출처 오류 줄
|
|
72
|
+
*/
|
|
73
|
+
export declare class UCommandPalette extends UOverlayElement {
|
|
74
|
+
static styles: CSSResultGroup;
|
|
75
|
+
/** 항목을 내는 곳들 — 묶음은 이 순서다. 프로퍼티로만 준다. */
|
|
76
|
+
sources: CommandSource[];
|
|
77
|
+
/** 검색 칸의 자리표시 글. */
|
|
78
|
+
placeholder: string;
|
|
79
|
+
/** 검색 칸의 접근 가능한 이름 — 비면 로캘 `search`. */
|
|
80
|
+
label: string;
|
|
81
|
+
/** 치기를 멈춘 뒤 출처를 부르기까지(ms). */
|
|
82
|
+
debounce: number;
|
|
83
|
+
private query;
|
|
84
|
+
private results;
|
|
85
|
+
private activeKey?;
|
|
86
|
+
private inputEl?;
|
|
87
|
+
private readonly idBase;
|
|
88
|
+
private controller?;
|
|
89
|
+
private timer?;
|
|
90
|
+
protected ownInitialFocus(): HTMLElement | null;
|
|
91
|
+
connectedCallback(): void;
|
|
92
|
+
disconnectedCallback(): void;
|
|
93
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
94
|
+
protected updated(changed: PropertyValues): void;
|
|
95
|
+
protected localeChanged(): void;
|
|
96
|
+
render(): import('lit-html').TemplateResult<1>;
|
|
97
|
+
private renderGroup;
|
|
98
|
+
/** 보이는 순서의 항목들(출처 순 → 출처가 준 순). */
|
|
99
|
+
private get rows();
|
|
100
|
+
private rowKey;
|
|
101
|
+
/** 항목의 id — 섀도 안의 같은 트리라 `aria-activedescendant` IDREF 가 닿는다. */
|
|
102
|
+
private optionId;
|
|
103
|
+
private handleInput;
|
|
104
|
+
private handleKeydown;
|
|
105
|
+
/** 검색어로 출처를 부른다 — 이전 요청은 중단하고, 출처마다 따로 끝난다. */
|
|
106
|
+
private run;
|
|
107
|
+
private settle;
|
|
108
|
+
/** 검색어가 바뀌면 첫 항목이 후보다(APG «list autocomplete with automatic selection») — 지금 후보가 남아 있으면 그대로. */
|
|
109
|
+
private syncActive;
|
|
110
|
+
private choose;
|
|
111
|
+
private cancel;
|
|
112
|
+
}
|
|
113
|
+
/** Typed listeners for {@link UCommandPaletteEventMap} — element-scoped, the DOM's own pattern (`HTMLMediaElementEventMap`). */
|
|
114
|
+
export interface UCommandPalette {
|
|
115
|
+
addEventListener<K extends keyof UCommandPaletteEventMap>(type: K, listener: (this: UCommandPalette, ev: UCommandPaletteEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
|
|
116
|
+
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: UCommandPalette, ev: HTMLElementEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
|
|
117
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
118
|
+
removeEventListener<K extends keyof UCommandPaletteEventMap>(type: K, listener: (this: UCommandPalette, ev: UCommandPaletteEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
|
|
119
|
+
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: UCommandPalette, ev: HTMLElementEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
|
|
120
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
121
|
+
}
|
|
122
|
+
declare global {
|
|
123
|
+
interface HTMLElementTagNameMap {
|
|
124
|
+
'u-command-palette': UCommandPalette;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { Locale } from "../../utilities/Locale.js";
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorate.js";
|
|
4
|
+
import { isImeComposing } from "../../utilities/keyboard.js";
|
|
5
|
+
import { UOverlayElement } from "../UOverlayElement.js";
|
|
6
|
+
import "../spinner/USpinner.js";
|
|
7
|
+
import "../icon/UIcon.js";
|
|
8
|
+
import { styles } from "./UCommandPalette.styles.js";
|
|
9
|
+
import { html, nothing } from "lit";
|
|
10
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
|
11
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
12
|
+
// src/components/command-palette/UCommandPalette.ts
|
|
13
|
+
/**
|
|
14
|
+
* 정적 항목을 검색어로 거른다 — 이름 · 설명 · 낱말을 활성 로케일의 검색 일치로 견준다(`u-select` 와 같은 규칙). 빈 검색어는 모두다.
|
|
15
|
+
* 출처의 `search` 를 짓는 도우미: `search: (q) => filterCommands(items, q)`.
|
|
16
|
+
*/
|
|
17
|
+
function filterCommands(items, query) {
|
|
18
|
+
const q = query.trim();
|
|
19
|
+
if (!q) return [...items];
|
|
20
|
+
return items.filter((item) => [
|
|
21
|
+
item.label,
|
|
22
|
+
item.description ?? "",
|
|
23
|
+
...item.keywords ?? []
|
|
24
|
+
].some((text) => text && Locale.matchesSearch(text, q)));
|
|
25
|
+
}
|
|
26
|
+
var nextId = 0;
|
|
27
|
+
var UCommandPalette = class UCommandPalette extends UOverlayElement {
|
|
28
|
+
constructor(..._args) {
|
|
29
|
+
super(..._args);
|
|
30
|
+
this.sources = [];
|
|
31
|
+
this.placeholder = "";
|
|
32
|
+
this.label = "";
|
|
33
|
+
this.debounce = 150;
|
|
34
|
+
this.query = "";
|
|
35
|
+
this.results = [];
|
|
36
|
+
this.idBase = `u-command-palette-${++nextId}`;
|
|
37
|
+
this.handleInput = (e) => {
|
|
38
|
+
const value = e.target.value;
|
|
39
|
+
this.query = value;
|
|
40
|
+
window.clearTimeout(this.timer);
|
|
41
|
+
if (!value.trim()) {
|
|
42
|
+
this.run("");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.timer = window.setTimeout(() => this.run(value), Math.max(0, this.debounce));
|
|
46
|
+
};
|
|
47
|
+
this.handleKeydown = (e) => {
|
|
48
|
+
const rows = this.rows;
|
|
49
|
+
switch (e.key) {
|
|
50
|
+
case "ArrowDown":
|
|
51
|
+
case "ArrowUp": {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
if (!rows.length) return;
|
|
54
|
+
const at = rows.findIndex((r) => r.key === this.activeKey);
|
|
55
|
+
const step = e.key === "ArrowDown" ? 1 : -1;
|
|
56
|
+
const next = at === -1 ? step === 1 ? 0 : rows.length - 1 : (at + step + rows.length) % rows.length;
|
|
57
|
+
this.activeKey = rows[next].key;
|
|
58
|
+
this.updateComplete.then(() => this.renderRoot.querySelector(".option[data-active]")?.scrollIntoView?.({ block: "nearest" }));
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "Enter": {
|
|
62
|
+
if (isImeComposing(e)) return;
|
|
63
|
+
const row = rows.find((r) => r.key === this.activeKey);
|
|
64
|
+
if (row) {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
this.choose(row);
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
static {
|
|
74
|
+
this.styles = [super.styles, styles];
|
|
75
|
+
}
|
|
76
|
+
ownInitialFocus() {
|
|
77
|
+
return this.inputEl ?? null;
|
|
78
|
+
}
|
|
79
|
+
connectedCallback() {
|
|
80
|
+
super.connectedCallback();
|
|
81
|
+
if (!this.hasAttribute("aria-label")) this.aria.set("aria-label", this.label || Locale.getValue("search"));
|
|
82
|
+
}
|
|
83
|
+
disconnectedCallback() {
|
|
84
|
+
this.cancel();
|
|
85
|
+
super.disconnectedCallback();
|
|
86
|
+
}
|
|
87
|
+
willUpdate(changed) {
|
|
88
|
+
super.willUpdate(changed);
|
|
89
|
+
if (changed.has("label")) this.aria.set("aria-label", this.label || Locale.getValue("search"));
|
|
90
|
+
}
|
|
91
|
+
updated(changed) {
|
|
92
|
+
super.updated(changed);
|
|
93
|
+
if (changed.has("open")) {
|
|
94
|
+
if (this.open) {
|
|
95
|
+
this.query = "";
|
|
96
|
+
if (this.inputEl) this.inputEl.value = "";
|
|
97
|
+
this.run("");
|
|
98
|
+
} else this.cancel();
|
|
99
|
+
} else if (changed.has("sources") && this.open) this.run(this.query);
|
|
100
|
+
}
|
|
101
|
+
localeChanged() {
|
|
102
|
+
if (this.label === "") this.aria.set("aria-label", Locale.getValue("search"));
|
|
103
|
+
super.localeChanged();
|
|
104
|
+
}
|
|
105
|
+
render() {
|
|
106
|
+
const rows = this.rows;
|
|
107
|
+
const listboxId = `${this.idBase}-listbox`;
|
|
108
|
+
const active = rows.find((r) => r.key === this.activeKey);
|
|
109
|
+
const settled = this.results.length > 0 && this.results.every((r) => r.status !== "loading");
|
|
110
|
+
const loading = this.results.some((r) => r.status === "loading");
|
|
111
|
+
return html`
|
|
112
|
+
<div class="container">
|
|
113
|
+
<div class="panel" part="panel">
|
|
114
|
+
<div class="field">
|
|
115
|
+
<u-icon class="field-icon" lib="internal" name="search" aria-hidden="true"></u-icon>
|
|
116
|
+
<input class="input" part="input"
|
|
117
|
+
type="text"
|
|
118
|
+
role="combobox"
|
|
119
|
+
autocomplete="off"
|
|
120
|
+
spellcheck="false"
|
|
121
|
+
aria-autocomplete="list"
|
|
122
|
+
aria-haspopup="listbox"
|
|
123
|
+
aria-expanded="true"
|
|
124
|
+
aria-controls=${listboxId}
|
|
125
|
+
aria-activedescendant=${ifDefined(active ? this.optionId(active) : void 0)}
|
|
126
|
+
aria-label=${this.label || Locale.getValue("search")}
|
|
127
|
+
placeholder=${this.placeholder}
|
|
128
|
+
@input=${this.handleInput}
|
|
129
|
+
@keydown=${this.handleKeydown} />
|
|
130
|
+
${loading ? html`<u-spinner class="field-spinner" aria-hidden="true"></u-spinner>` : nothing}
|
|
131
|
+
</div>
|
|
132
|
+
<div class="listbox" part="listbox" role="listbox" id=${listboxId}
|
|
133
|
+
aria-label=${this.label || Locale.getValue("search")}
|
|
134
|
+
?hidden=${rows.length === 0}>
|
|
135
|
+
${this.results.map((state) => this.renderGroup(state))}
|
|
136
|
+
</div>
|
|
137
|
+
${this.results.filter((r) => r.status === "error").map((r) => html`
|
|
138
|
+
<div class="error" part="status">${Locale.getValue("searchFailed", { source: r.source.label })}</div>`)}
|
|
139
|
+
<div class="status" part="status" role="status">${settled && rows.length === 0 ? Locale.getValue("noMatches") : loading && rows.length === 0 ? Locale.getValue("loading") : ""}</div>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
renderGroup(state) {
|
|
145
|
+
const headingId = `${this.idBase}-g-${state.source.id}`;
|
|
146
|
+
if (state.status === "error" || state.items.length === 0) return nothing;
|
|
147
|
+
return html`
|
|
148
|
+
<div role="group" aria-labelledby=${headingId} class="group">
|
|
149
|
+
<div class="group-label" part="group-label" id=${headingId} role="presentation">${state.source.label}</div>
|
|
150
|
+
${state.items.map((item) => {
|
|
151
|
+
const row = {
|
|
152
|
+
key: this.rowKey(state.source.id, item),
|
|
153
|
+
item,
|
|
154
|
+
source: state.source.id
|
|
155
|
+
};
|
|
156
|
+
const isActive = row.key === this.activeKey;
|
|
157
|
+
const descId = item.description ? `${this.optionId(row)}-d` : void 0;
|
|
158
|
+
return html`
|
|
159
|
+
<div class="option" part="option" role="option"
|
|
160
|
+
id=${this.optionId(row)}
|
|
161
|
+
aria-selected=${isActive ? "true" : "false"}
|
|
162
|
+
aria-describedby=${ifDefined(descId)}
|
|
163
|
+
?data-active=${isActive}
|
|
164
|
+
@pointermove=${() => {
|
|
165
|
+
if (this.activeKey !== row.key) this.activeKey = row.key;
|
|
166
|
+
}}
|
|
167
|
+
@click=${() => this.choose(row)}>
|
|
168
|
+
${item.icon ? html`<u-icon class="option-icon" lib=${ifDefined(item.iconLib)} name=${item.icon} aria-hidden="true"></u-icon>` : nothing}
|
|
169
|
+
<span class="option-label">${item.label}</span>
|
|
170
|
+
${item.description ? html`<span class="option-description" id=${ifDefined(descId)}>${item.description}</span>` : nothing}
|
|
171
|
+
</div>`;
|
|
172
|
+
})}
|
|
173
|
+
</div>
|
|
174
|
+
`;
|
|
175
|
+
}
|
|
176
|
+
/** 보이는 순서의 항목들(출처 순 → 출처가 준 순). */
|
|
177
|
+
get rows() {
|
|
178
|
+
return this.results.flatMap((state) => state.status === "error" ? [] : state.items.map((item) => ({
|
|
179
|
+
key: this.rowKey(state.source.id, item),
|
|
180
|
+
item,
|
|
181
|
+
source: state.source.id
|
|
182
|
+
})));
|
|
183
|
+
}
|
|
184
|
+
rowKey(source, item) {
|
|
185
|
+
return `${source}\u0000${item.id}`;
|
|
186
|
+
}
|
|
187
|
+
/** 항목의 id — 섀도 안의 같은 트리라 `aria-activedescendant` IDREF 가 닿는다. */
|
|
188
|
+
optionId(row) {
|
|
189
|
+
const index = this.rows.findIndex((r) => r.key === row.key);
|
|
190
|
+
return `${this.idBase}-o-${index}`;
|
|
191
|
+
}
|
|
192
|
+
/** 검색어로 출처를 부른다 — 이전 요청은 중단하고, 출처마다 따로 끝난다. */
|
|
193
|
+
run(query) {
|
|
194
|
+
window.clearTimeout(this.timer);
|
|
195
|
+
this.controller?.abort();
|
|
196
|
+
const controller = new AbortController();
|
|
197
|
+
this.controller = controller;
|
|
198
|
+
const previous = new Map(this.results.map((r) => [r.source.id, r.items]));
|
|
199
|
+
this.results = this.sources.map((source) => ({
|
|
200
|
+
source,
|
|
201
|
+
status: "loading",
|
|
202
|
+
items: previous.get(source.id) ?? []
|
|
203
|
+
}));
|
|
204
|
+
this.sources.forEach((source, i) => {
|
|
205
|
+
Promise.resolve().then(() => source.search(query, { signal: controller.signal })).then((items) => this.settle(controller, i, {
|
|
206
|
+
source,
|
|
207
|
+
status: "done",
|
|
208
|
+
items: Array.isArray(items) ? items : []
|
|
209
|
+
}), (error) => {
|
|
210
|
+
if (controller.signal.aborted) return;
|
|
211
|
+
console.warn(`[@iyulab/components] u-command-palette: source "${source.id}" failed`, error);
|
|
212
|
+
this.settle(controller, i, {
|
|
213
|
+
source,
|
|
214
|
+
status: "error",
|
|
215
|
+
items: []
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
if (this.sources.length === 0) this.syncActive();
|
|
220
|
+
}
|
|
221
|
+
settle(controller, index, state) {
|
|
222
|
+
if (controller !== this.controller || controller.signal.aborted) return;
|
|
223
|
+
const next = [...this.results];
|
|
224
|
+
next[index] = state;
|
|
225
|
+
this.results = next;
|
|
226
|
+
this.syncActive();
|
|
227
|
+
}
|
|
228
|
+
/** 검색어가 바뀌면 첫 항목이 후보다(APG «list autocomplete with automatic selection») — 지금 후보가 남아 있으면 그대로. */
|
|
229
|
+
syncActive() {
|
|
230
|
+
const rows = this.rows;
|
|
231
|
+
if (!rows.some((r) => r.key === this.activeKey)) this.activeKey = rows[0]?.key;
|
|
232
|
+
}
|
|
233
|
+
choose(row) {
|
|
234
|
+
const proceed = this.fire("command", {
|
|
235
|
+
detail: {
|
|
236
|
+
item: row.item,
|
|
237
|
+
source: row.source
|
|
238
|
+
},
|
|
239
|
+
bubbles: false,
|
|
240
|
+
composed: false
|
|
241
|
+
});
|
|
242
|
+
this.hide();
|
|
243
|
+
if (proceed && row.item.href) window.location.assign(row.item.href);
|
|
244
|
+
}
|
|
245
|
+
cancel() {
|
|
246
|
+
window.clearTimeout(this.timer);
|
|
247
|
+
this.controller?.abort();
|
|
248
|
+
this.controller = void 0;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
__decorate([property({ attribute: false }), __decorateMetadata("design:type", Array)], UCommandPalette.prototype, "sources", void 0);
|
|
252
|
+
__decorate([property({ type: String }), __decorateMetadata("design:type", Object)], UCommandPalette.prototype, "placeholder", void 0);
|
|
253
|
+
__decorate([property({ type: String }), __decorateMetadata("design:type", Object)], UCommandPalette.prototype, "label", void 0);
|
|
254
|
+
__decorate([property({ type: Number }), __decorateMetadata("design:type", Object)], UCommandPalette.prototype, "debounce", void 0);
|
|
255
|
+
__decorate([state(), __decorateMetadata("design:type", Object)], UCommandPalette.prototype, "query", void 0);
|
|
256
|
+
__decorate([state(), __decorateMetadata("design:type", Array)], UCommandPalette.prototype, "results", void 0);
|
|
257
|
+
__decorate([state(), __decorateMetadata("design:type", String)], UCommandPalette.prototype, "activeKey", void 0);
|
|
258
|
+
__decorate([query("input.input"), __decorateMetadata("design:type", typeof HTMLInputElement === "undefined" ? Object : HTMLInputElement)], UCommandPalette.prototype, "inputEl", void 0);
|
|
259
|
+
UCommandPalette = __decorate([customElement("u-command-palette")], UCommandPalette);
|
|
260
|
+
export { UCommandPalette, filterCommands };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: import('lit').CSSResult;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
// src/components/command-palette/UCommandPalette.styles.ts
|
|
3
|
+
var styles = css`
|
|
4
|
+
|
|
5
|
+
.container {
|
|
6
|
+
display: flex;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
align-items: flex-start;
|
|
9
|
+
width: 100%;
|
|
10
|
+
height: 100%;
|
|
11
|
+
padding: min(12vh, 96px) var(--u-space-lg, 16px) var(--u-space-lg, 16px);
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
pointer-events: none;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.panel {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
width: min(var(--command-palette-width, 40rem), 100%);
|
|
20
|
+
max-height: min(70vh, 36rem);
|
|
21
|
+
border: 1px solid var(--u-border-color, #E0E0E0);
|
|
22
|
+
border-radius: var(--u-radius-lg, 6px);
|
|
23
|
+
background: var(--u-panel-bg-color, #FFFFFF);
|
|
24
|
+
color: var(--u-txt-color, #212121);
|
|
25
|
+
box-shadow: var(--u-shadow-xl, 0 6px 18px rgba(0, 0, 0, 0.24), 0 2px 6px rgba(0, 0, 0, 0.08));
|
|
26
|
+
pointer-events: auto;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
opacity: 0;
|
|
29
|
+
transform: translateY(-8px);
|
|
30
|
+
transition:
|
|
31
|
+
opacity var(--u-duration-fast, 140ms) var(--u-ease-standard, cubic-bezier(0.2, 0, 0, 1)),
|
|
32
|
+
transform var(--u-duration-fast, 140ms) var(--u-ease-standard, cubic-bezier(0.2, 0, 0, 1));
|
|
33
|
+
}
|
|
34
|
+
:host([open]) .panel {
|
|
35
|
+
opacity: 1;
|
|
36
|
+
transform: none;
|
|
37
|
+
}
|
|
38
|
+
@media (prefers-reduced-motion: reduce) {
|
|
39
|
+
.panel { transition: none; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.field {
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
gap: var(--u-space-sm, 8px);
|
|
46
|
+
padding: 0 var(--u-space-md, 12px);
|
|
47
|
+
border-bottom: 1px solid var(--u-border-color, #E0E0E0);
|
|
48
|
+
}
|
|
49
|
+
.field-icon {
|
|
50
|
+
flex: none;
|
|
51
|
+
font-size: 1.125em;
|
|
52
|
+
color: var(--u-txt-color-weak, #616161);
|
|
53
|
+
}
|
|
54
|
+
.field-spinner {
|
|
55
|
+
flex: none;
|
|
56
|
+
font-size: 1em;
|
|
57
|
+
}
|
|
58
|
+
.input {
|
|
59
|
+
all: unset;
|
|
60
|
+
flex: 1;
|
|
61
|
+
min-width: 0;
|
|
62
|
+
min-block-size: 3rem;
|
|
63
|
+
font: inherit;
|
|
64
|
+
font-size: var(--u-text-body-size, 14px);
|
|
65
|
+
color: inherit;
|
|
66
|
+
}
|
|
67
|
+
.input::placeholder {
|
|
68
|
+
color: var(--u-txt-color-weak, #616161);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.listbox {
|
|
72
|
+
flex: 1;
|
|
73
|
+
min-height: 0;
|
|
74
|
+
overflow-y: auto;
|
|
75
|
+
padding: var(--u-space-xs, 6px);
|
|
76
|
+
}
|
|
77
|
+
.listbox[hidden] {
|
|
78
|
+
display: none;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.group + .group {
|
|
82
|
+
margin-top: var(--u-space-xs, 6px);
|
|
83
|
+
}
|
|
84
|
+
.group-label {
|
|
85
|
+
padding: var(--u-space-sm, 8px) var(--u-space-sm, 8px) var(--u-space-xs, 6px);
|
|
86
|
+
font-size: var(--u-text-label-size, 13px);
|
|
87
|
+
font-weight: 600;
|
|
88
|
+
color: var(--u-txt-color-weak, #616161);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.option {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
gap: var(--u-space-sm, 8px);
|
|
95
|
+
|
|
96
|
+
min-height: max(2.5rem, var(--u-target-size, 0px));
|
|
97
|
+
padding: 0 var(--u-space-sm, 8px);
|
|
98
|
+
border-radius: var(--u-radius-md, 4px);
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
}
|
|
101
|
+
.option[data-active] {
|
|
102
|
+
background: var(--u-primary-bg-color, #E3F2FD);
|
|
103
|
+
}
|
|
104
|
+
.option-icon {
|
|
105
|
+
flex: none;
|
|
106
|
+
color: var(--u-txt-color-weak, #616161);
|
|
107
|
+
}
|
|
108
|
+
.option-label {
|
|
109
|
+
flex: 0 1 auto;
|
|
110
|
+
min-width: 0;
|
|
111
|
+
overflow: hidden;
|
|
112
|
+
text-overflow: ellipsis;
|
|
113
|
+
white-space: nowrap;
|
|
114
|
+
}
|
|
115
|
+
.option-description {
|
|
116
|
+
flex: 1 1 auto;
|
|
117
|
+
min-width: 0;
|
|
118
|
+
overflow: hidden;
|
|
119
|
+
text-overflow: ellipsis;
|
|
120
|
+
white-space: nowrap;
|
|
121
|
+
font-size: var(--u-text-label-size, 13px);
|
|
122
|
+
color: var(--u-txt-color-weak, #616161);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.status:empty {
|
|
126
|
+
display: none;
|
|
127
|
+
}
|
|
128
|
+
.status,
|
|
129
|
+
.error {
|
|
130
|
+
padding: var(--u-space-md, 12px);
|
|
131
|
+
font-size: var(--u-text-label-size, 13px);
|
|
132
|
+
color: var(--u-txt-color-weak, #616161);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@media (forced-colors: active) {
|
|
136
|
+
.option[data-active] {
|
|
137
|
+
outline: 2px solid Highlight;
|
|
138
|
+
outline-offset: -2px;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
export { styles };
|
|
@@ -106,6 +106,7 @@ export declare class USelect extends UFormControlElement<string | string[]> {
|
|
|
106
106
|
private readonly idBase;
|
|
107
107
|
private readonly listboxId;
|
|
108
108
|
private readonly popupId;
|
|
109
|
+
private readonly chipsId;
|
|
109
110
|
protected shouldValidate(changed: PropertyValues): boolean;
|
|
110
111
|
private get valueAsString();
|
|
111
112
|
private get valueAsArray();
|
|
@@ -144,6 +145,20 @@ export declare class USelect extends UFormControlElement<string | string[]> {
|
|
|
144
145
|
* 바깥 클릭으로 닫힐 때는 포커스가 이미 다른 곳에 있으므로 건드리지 않는다.
|
|
145
146
|
*/
|
|
146
147
|
private handlePopoverHide;
|
|
148
|
+
/**
|
|
149
|
+
* 검색 가능 단일 선택의 입력 글자 = 고른 옵션의 글자(APG «editable combobox»: 입력의 값이 곧 콤보박스의 값이다).
|
|
150
|
+
* 보조기술 · 접근성 트리는 닫힌 콤보박스의 값을 이 글자로 읽는다. 다중 선택에서는 입력이 검색어 칸이라 비어 있고,
|
|
151
|
+
* 고른 값(칩 묶음)은 `aria-describedby` 로 잇는다.
|
|
152
|
+
*/
|
|
153
|
+
private get inputText();
|
|
154
|
+
/** 입력에 사용자가 친 글자가 있는가 — 고른 값의 글자 그대로면 검색어가 아니다. */
|
|
155
|
+
private isEdited;
|
|
156
|
+
/** 친 글자가 없을 때 입력을 고른 값의 글자에 맞춘다(값 · 옵션이 바뀔 때). 치는 중이면 건드리지 않는다. */
|
|
157
|
+
private syncSearchInput;
|
|
158
|
+
/** 친 글자를 걷고 고른 값의 글자로 — 빈 검색어의 `search` 가 함께 나간다. */
|
|
159
|
+
private revertSearchInput;
|
|
160
|
+
/** 들어오면 고른 값의 글자를 통째로 고른다 — 첫 글자(한글 조합의 첫 음절까지)가 그것을 바꿔 검색어가 된다. */
|
|
161
|
+
private handleSearchFocus;
|
|
147
162
|
/** 검색 가능일 때 목록을 연다(여닫기는 이 요소가 한다 — 팝오버는 `trigger="manual"`). */
|
|
148
163
|
private openPopup;
|
|
149
164
|
/** 트리거를 누르면 — 검색 가능이면 입력에 포커스를 두고 여닫는다(열린 채 입력을 눌러 캐럿을 옮기는 것은 닫지 않는다). */
|