@iyulab/components 2.21.0 → 2.22.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/components/UElement.d.ts +5 -1
  3. package/dist/components/UElement.js +9 -2
  4. package/dist/components/UFormControlElement.d.ts +7 -0
  5. package/dist/components/UFormControlElement.js +11 -0
  6. package/dist/components/checkbox/UCheckbox.d.ts +3 -0
  7. package/dist/components/checkbox/UCheckbox.js +7 -0
  8. package/dist/components/form/UForm.js +2 -2
  9. package/dist/components/input/UInput.js +2 -2
  10. package/dist/components/select/USelect.d.ts +25 -5
  11. package/dist/components/select/USelect.js +25 -10
  12. package/dist/components/switch/USwitch.d.ts +3 -0
  13. package/dist/components/switch/USwitch.js +7 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +3 -1
  16. package/dist/react/USelect.d.ts +2 -1
  17. package/dist/utilities/Locale.d.ts +21 -9
  18. package/dist/utilities/Locale.js +26 -0
  19. package/dist/utilities/composition.d.ts +43 -0
  20. package/dist/utilities/composition.js +76 -0
  21. package/dist/utilities/search.d.ts +29 -0
  22. package/dist/utilities/search.js +151 -0
  23. package/package.json +1 -1
  24. package/skills/iyulab-components/SKILL.md +2 -2
  25. package/skills/iyulab-components/references/components/form.md +2 -2
  26. package/skills/iyulab-components/references/components/select.md +1 -1
  27. package/skills/iyulab-components/references/extensions/element.md +1 -1
  28. package/skills/iyulab-components/references/extensions/form-control.md +6 -0
  29. package/skills/iyulab-components/references/utilities/keyboard.md +38 -0
  30. package/skills/iyulab-components/references/utilities/locale.md +26 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,52 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.22.0] - 2026-10-13
4
+
5
+ ### Added
6
+
7
+ - `u-select` `search` carries `detail.composing` — `true` while an IME composition (Korean, Japanese, Chinese) is in
8
+ progress, so `query` ends in a partial syllable (`ㅅ`, `성` on the way to `서울`). When the composition ends the event
9
+ fires again with `composing: false` and the finished text; Chromium sends no plain `input` at that point, so a
10
+ consumer that skipped composing events had no way to see the finished query. A consumer that searches a server can
11
+ now skip composing queries. `search` no longer repeats an unchanged query.
12
+ - **Search matching** — `Locale.matchesSearch(text, query, options?)` and `Locale.registerSearch(locale, matcher)`. The
13
+ default rule folds case and diacritics and compares Hangul syllables whole; with `composing: true` the query's last
14
+ syllable, still being typed, is compared as the jamo in typing order, so it matches the word it is becoming (`성`
15
+ and `서우` match `서울`). A query of consonants only matches initials (`ㅅㅇ` finds `서울`). `defaultSearchMatch`,
16
+ `foldForSearch`, `hangulKeystrokes` and `initialsOf` are exported from `utilities/search`;
17
+ `CompositionTracker.searchQuery(input)` gives the query and the flag together.
18
+ `u-select searchable` filters with it — typing `서울` with a Korean IME narrows to `서울` and `성남` at `성` and to
19
+ `서울` at `서우`, instead of waiting for the syllable to be committed. A language's own rule is registered with
20
+ `registerSearch`.
21
+ - `CompositionTracker` and `replayInput` (`utilities/composition`) — for an input that filters or searches as you type.
22
+ Attach a tracker to the input's `compositionstart`, `compositionupdate` and `compositionend`; `composing` says an IME
23
+ composition is in progress and `settled(input)` gives the text without the syllable still being composed. Filtering
24
+ on the settled text never hides an item the finished text would match. `new CompositionTracker(replayInput)` re-runs
25
+ the input's own `input` handler when the composition ends, for an input that waits until then.
26
+ - `modelValue` on form controls — the value a `u-form` reads into and writes from its `model`. It is `value` by
27
+ default; `u-checkbox` and `u-switch` exchange `checked`. A custom control whose state lives in another property
28
+ overrides it.
29
+
30
+ ### Fixed
31
+
32
+ - `u-select searchable` no longer hides options or announces "No matches" for a syllable still being composed. It
33
+ filtered on every composition step, so typing «서울» with a Korean IME showed no options and announced "No matches"
34
+ at «ㅅ», and showed only «성남» at «성». While composing it now filters on the committed part only, which never hides
35
+ an option the finished text would match; "No matches" appears only when the committed part already matches nothing.
36
+ - `u-input` keeps `value` in step with the box during an IME composition. It used to update only when the composition
37
+ ended, so the `input` events an ancestor received during composition read an old value (`undefined` or the previous
38
+ syllable while the box showed «서울»). These events are now re-dispatched from the host and keep `isComposing`.
39
+ - Events re-dispatched from a control's host now bubble and cross shadow roots. `relay()` copied the original event
40
+ with object spread, which does not include `bubbles`, `composed`, `cancelable` or `InputEvent` fields (they are
41
+ prototype getters), so the re-dispatched event reached only listeners on the host itself. Affected: `change` from
42
+ `u-checkbox`, `u-switch`, `u-textarea` and `u-file-input`, and `input` from `u-input` and `u-textarea`. A listener
43
+ on an ancestor — a delegated handler, a dirty-state tracker, `u-form` — now receives each of these once, and
44
+ `InputEvent.data` and `inputType` are kept.
45
+ - `u-form` keeps `model` in step with checkboxes and switches in both directions. It used to read and write their
46
+ `value` (the submitted text), so a checked box put `undefined` in the model and `model.agree = true` did not check
47
+ the box. With the propagation fix above, user edits in a checkbox, switch, textarea or file input now update
48
+ `model` — before, only `u-input` reached it.
49
+
3
50
  ## [2.21.0] - 2026-10-12
4
51
 
5
52
  ### Added
@@ -33,9 +33,13 @@ export declare class UElement extends LitElement {
33
33
  protected fire<T>(name: string, options?: CustomEventInit): boolean;
34
34
  /**
35
35
  * 네이티브 이벤트를 호스트 엘리먼트에서 (재)발행합니다.
36
- * 기존 이벤트를 전달하면 원본을 중단하고 동일 타입으로 재발행하며,
36
+ * 기존 이벤트를 전달하면 원본을 중단하고 동일 타입·동일 초기값으로 재발행하며,
37
37
  * 새 이벤트를 직접 전달할 수도 있습니다.
38
38
  *
39
+ * 재발행한 이벤트는 원본의 `bubbles`·`cancelable` 과 타입별 값(`InputEvent` 의 `data`·`inputType`,
40
+ * `CustomEvent` 의 `detail` 등)을 잇고, 호스트가 공개 경계이므로 `composed: true` 로 섀도를 넘는다
41
+ * (`fire()` 와 같은 전파). 네이티브 `change` 처럼 원본이 섀도 안에 머무는 이벤트도 호스트의 조상에 닿는다.
42
+ *
39
43
  * @param event - 재발행할 이벤트 또는 새로 생성한 네이티브 이벤트
40
44
  * @param options - EventInit 오버라이드
41
45
  * @returns preventDefault가 호출되지 않았으면 true
@@ -90,18 +90,25 @@ var UElement = class extends LitElement {
90
90
  }
91
91
  /**
92
92
  * 네이티브 이벤트를 호스트 엘리먼트에서 (재)발행합니다.
93
- * 기존 이벤트를 전달하면 원본을 중단하고 동일 타입으로 재발행하며,
93
+ * 기존 이벤트를 전달하면 원본을 중단하고 동일 타입·동일 초기값으로 재발행하며,
94
94
  * 새 이벤트를 직접 전달할 수도 있습니다.
95
95
  *
96
+ * 재발행한 이벤트는 원본의 `bubbles`·`cancelable` 과 타입별 값(`InputEvent` 의 `data`·`inputType`,
97
+ * `CustomEvent` 의 `detail` 등)을 잇고, 호스트가 공개 경계이므로 `composed: true` 로 섀도를 넘는다
98
+ * (`fire()` 와 같은 전파). 네이티브 `change` 처럼 원본이 섀도 안에 머무는 이벤트도 호스트의 조상에 닿는다.
99
+ *
96
100
  * @param event - 재발행할 이벤트 또는 새로 생성한 네이티브 이벤트
97
101
  * @param options - EventInit 오버라이드
98
102
  * @returns preventDefault가 호출되지 않았으면 true
99
103
  */
100
104
  relay(event, options) {
101
105
  event.stopImmediatePropagation();
106
+ const init = {};
107
+ for (const key in event) init[key] = event[key];
102
108
  const ctor = event.constructor;
103
109
  return this.dispatchEvent(new ctor(event.type, {
104
- ...event,
110
+ ...init,
111
+ composed: true,
105
112
  ...options
106
113
  }));
107
114
  }
@@ -38,6 +38,13 @@ export declare abstract class UFormControlElement<T> extends UElement {
38
38
  * (이전의 type: Object는 JSON.parse 실패로 일반 문자열 attribute가 silently null이 되는 갭이 있었다)
39
39
  * string이 아닌 값 타입을 갖는 컨트롤(URating/USlider/USelect multiple)은 자신의 converter로 override한다. */
40
40
  value?: T;
41
+ /**
42
+ * `u-form` 의 `model` 과 주고받는 값. 기본은 `value` 다.
43
+ * 상태를 다른 속성에 두는 컨트롤(체크박스 · 스위치의 `checked`)은 그 상태를 돌려주고 받도록 재정의한다 —
44
+ * 제출값(`value`)과 모델이 담을 상태는 다를 수 있다.
45
+ */
46
+ get modelValue(): unknown;
47
+ set modelValue(value: unknown);
41
48
  /**
42
49
  * ElementInternals는 폼과의 연동, 유효성 검사 상태 관리 등을 지원하는 네이티브 API입니다.
43
50
  */
@@ -23,6 +23,17 @@ var UFormControlElement = class extends UElement {
23
23
  return this.disabled || this.formDisabled;
24
24
  }
25
25
  /**
26
+ * `u-form` 의 `model` 과 주고받는 값. 기본은 `value` 다.
27
+ * 상태를 다른 속성에 두는 컨트롤(체크박스 · 스위치의 `checked`)은 그 상태를 돌려주고 받도록 재정의한다 —
28
+ * 제출값(`value`)과 모델이 담을 상태는 다를 수 있다.
29
+ */
30
+ get modelValue() {
31
+ return this.value;
32
+ }
33
+ set modelValue(value) {
34
+ this.value = value;
35
+ }
36
+ /**
26
37
  * 폼과의 연동을 위해 `form` 속성을 제공합니다. ElementInternals를 지원하는 브라우저에서 폼 요소에 접근할 수 있습니다.
27
38
  * 지원하지 않는 브라우저에서는 null을 반환합니다.
28
39
  */
@@ -32,6 +32,9 @@ export declare class UCheckbox extends UFormControlElement<string> {
32
32
  indeterminate: boolean;
33
33
  /** 체크 여부 */
34
34
  checked: boolean;
35
+ /** `u-form` 의 `model` 에는 제출값(`value`)이 아니라 켬/끔 상태를 싣는다. */
36
+ get modelValue(): unknown;
37
+ set modelValue(value: unknown);
35
38
  /**
36
39
  * 네이티브 `defaultChecked` 에 해당하는 값 — **처음 연결될 때의 `checked` 속성**.
37
40
  * `checked` 는 반영(reflect)되는 속성이라 사용자가 바꾸면 속성도 바뀐다. 그래서 속성을
@@ -29,6 +29,13 @@ var UCheckbox = class UCheckbox extends UFormControlElement {
29
29
  static {
30
30
  this.styles = [super.styles, styles];
31
31
  }
32
+ /** `u-form` 의 `model` 에는 제출값(`value`)이 아니라 켬/끔 상태를 싣는다. */
33
+ get modelValue() {
34
+ return this.checked;
35
+ }
36
+ set modelValue(value) {
37
+ this.checked = Boolean(value);
38
+ }
32
39
  connectedCallback() {
33
40
  this.defaultChecked ??= this.hasAttribute("checked");
34
41
  super.connectedCallback();
@@ -20,7 +20,7 @@ var UForm = class UForm extends UElement {
20
20
  const target = e.target;
21
21
  if (!(target instanceof UFormControlElement)) return;
22
22
  const name = target.name;
23
- const value = target.value;
23
+ const value = target.modelValue;
24
24
  if (!name) return;
25
25
  if (!this.isIncluded(target)) return;
26
26
  if (this.model && typeof this.model === "object") this.model[name] = value;
@@ -81,7 +81,7 @@ var UForm = class UForm extends UElement {
81
81
  }
82
82
  sync() {
83
83
  if (!this.model) return;
84
- for (const control of this.getControls()) if (control.name && control.name in this.model) control.value = this.model[control.name];
84
+ for (const control of this.getControls()) if (control.name && control.name in this.model) control.modelValue = this.model[control.name];
85
85
  }
86
86
  /**
87
87
  * 포함된 컨트롤을 문서 순서로 모은다 — 슬롯에 배정된 요소 **와 그 자손**이 대상이다. 감싸개(`u-field` 등) 안의
@@ -53,8 +53,8 @@ var UInput = class UInput extends UFormControlElement {
53
53
  this.inputEl?.dispatchEvent(new InputEvent("input", { bubbles: true }));
54
54
  };
55
55
  this.handleInputInput = (e) => {
56
- if (this.composing) return;
57
56
  if (this.type === "number") {
57
+ if (this.composing) return;
58
58
  const text = this.inputEl?.value ?? "";
59
59
  if (text === this.numberText) return;
60
60
  this.syncNumberFromText(text);
@@ -62,7 +62,7 @@ var UInput = class UInput extends UFormControlElement {
62
62
  return;
63
63
  }
64
64
  const next = this.inputEl?.value;
65
- if (next === this.value) return;
65
+ if (!e.isTrusted && next === this.value) return;
66
66
  this.value = next;
67
67
  this.relay(e);
68
68
  };
@@ -35,7 +35,7 @@ import { UPopover } from '../popover/UPopover.js';
35
35
  *
36
36
  * @event change - 사용자 상호작용(옵션 클릭·칩 제거·지우기)으로 선택 값이 변경될 때 발생.
37
37
  * 네이티브 select와 동일하게 프로그램적 value 세팅·옵션 등록으로는 발화하지 않는다.
38
- * @event search - `searchable`일 때 검색 입력이 바뀔 때마다 발생(`detail: { query: string }`).
38
+ * @event search - `searchable`일 때 검색어가 바뀔 때마다 발생(`detail: { query: string; composing: boolean }` — IME 조합 중이면 `composing: true`, 조합이 끝나면 `false` 로 한 번 더).
39
39
  * 로컬 필터링(이미 렌더된 `u-option`의 `hidden` 토글)과 별개로 발행되므로, 서버/원격 검색이
40
40
  * 필요한 소비자는 이 이벤트를 구독해 자체적으로 옵션을 갱신할 수 있다.
41
41
  */
@@ -85,6 +85,8 @@ export declare class USelect extends UFormControlElement<string | string[]> {
85
85
  private options;
86
86
  /** 검색칸의 지금 검색어(소문자 · 앞뒤 공백 없음). */
87
87
  private query;
88
+ /** `query` 의 마지막 음절이 아직 조합 중인가 — 검색 일치가 그 음절을 자모 앞부분으로 견준다. */
89
+ private queryComposing;
88
90
  /** 검색어가 있는데 보이는 옵션이 없다 — 팝업에 «일치하는 항목 없음» 을 알린다. */
89
91
  private noMatches;
90
92
  /** aria-expanded 배선용 팝오버 열림 상태 */
@@ -128,7 +130,16 @@ export declare class USelect extends UFormControlElement<string | string[]> {
128
130
  private handlePopoverHide;
129
131
  private handleOptionClick;
130
132
  private handleOptionKeydown;
133
+ /**
134
+ * 검색칸의 IME 조합. 조합 중인 음절(«ㅅ» · «성» → «서울» 의 가는 길)은 «진행 중» 이라 거르기에 쓰지 않는다 — 확정된
135
+ * 부분으로 거르면 사용자가 찾는 옵션을 숨기지 않고 «일치 없음» 도 정말 없을 때만 알린다. Chromium 은 조합의 마지막
136
+ * `input` 을 `isComposing: true` 로 내고 끝내므로, 확정된 질의는 조합 끝에 낸다.
137
+ */
138
+ private readonly composition;
139
+ /** 마지막으로 낸 `search` — 조합 끝의 `search` 와 그 뒤 브라우저가 내는 `input`(Firefox)이 같은 질의를 두 번 내지 않게. */
140
+ private lastSearch?;
131
141
  private handleSearchInput;
142
+ private updateSearch;
132
143
  /**
133
144
  * 지금 검색어를 지금 옵션에 적용한다 — 입력 때뿐 아니라 옵션이 바뀔 때도(재사용된 `u-option` 이 앞 검색의 `hidden` 을
134
145
  * 들고 남지 않게). `filter="none"` 이면 아무것도 숨기지 않는다.
@@ -142,12 +153,21 @@ export declare class USelect extends UFormControlElement<string | string[]> {
142
153
  private handleClearKeydown;
143
154
  private handleChipRemove;
144
155
  }
156
+ /** Detail of `<u-select>`'s `search` event. */
157
+ export interface USelectSearchDetail {
158
+ /** The search box text, trimmed and lower-cased — including a syllable still being composed. */
159
+ query: string;
160
+ /**
161
+ * `true` while an IME composition (Korean, Japanese, Chinese) is in progress, so `query` ends in a partial
162
+ * syllable (`ㅅ`, `성` on the way to `서울`). When the composition ends the event fires again with `false`. A consumer
163
+ * that searches a server can skip composing queries.
164
+ */
165
+ composing: boolean;
166
+ }
145
167
  /** Custom events `<u-select>` dispatches (its `change`/`input` are the native form-control events). */
146
168
  export interface USelectEventMap {
147
- /** The search box changed (`searchable`). `query` is the trimmed, lower-cased text. */
148
- 'search': CustomEvent<{
149
- query: string;
150
- }>;
169
+ /** The search box changed (`searchable`). */
170
+ 'search': CustomEvent<USelectSearchDetail>;
151
171
  }
152
172
  /** Typed listeners for {@link USelectEventMap} — element-scoped, the DOM's own pattern (`HTMLMediaElementEventMap`). */
153
173
  export interface USelect {
@@ -9,6 +9,7 @@ import "../field/UField.js";
9
9
  import "../popover/UPopover.js";
10
10
  import { CharsWidthController } from "../../utilities/chars.js";
11
11
  import { UOption } from "../option/UOption.js";
12
+ import { CompositionTracker } from "../../utilities/composition.js";
12
13
  import { styles } from "./USelect.styles.js";
13
14
  import { html } from "lit";
14
15
  import { customElement, property, query, state } from "lit/decorators.js";
@@ -31,6 +32,7 @@ var USelect = class USelect extends UFormControlElement {
31
32
  this.loading = false;
32
33
  this.options = [];
33
34
  this.query = "";
35
+ this.queryComposing = false;
34
36
  this.noMatches = false;
35
37
  this.open = false;
36
38
  this.idBase = `u-select-${Math.random().toString(36).slice(2, 8)}`;
@@ -97,14 +99,9 @@ var USelect = class USelect extends UFormControlElement {
97
99
  this.popoverEl?.hide();
98
100
  }
99
101
  };
102
+ this.composition = new CompositionTracker((input) => this.updateSearch(input));
100
103
  this.handleSearchInput = (e) => {
101
- const input = e.target;
102
- this.query = input.value.toLowerCase().trim();
103
- this.applyFilter();
104
- this.fire("search", {
105
- detail: { query: this.query },
106
- cancelable: false
107
- });
104
+ this.updateSearch(e.target);
108
105
  };
109
106
  this.handleSearchKeydown = (e) => {
110
107
  const options = this.options.filter((o) => !o.hidden && !o.disabled);
@@ -248,6 +245,9 @@ var USelect = class USelect extends UFormControlElement {
248
245
  aria-label=${Locale.getValue("search")}
249
246
  aria-controls=${this.listboxId}
250
247
  @input=${this.handleSearchInput}
248
+ @compositionstart=${this.composition}
249
+ @compositionupdate=${this.composition}
250
+ @compositionend=${this.composition}
251
251
  @keydown=${this.handleSearchKeydown}
252
252
  />
253
253
  </div>
@@ -346,6 +346,22 @@ var USelect = class USelect extends UFormControlElement {
346
346
  composed: true
347
347
  }));
348
348
  }
349
+ updateSearch(input) {
350
+ const { query, composing } = this.composition.searchQuery(input);
351
+ this.query = query.trim();
352
+ this.queryComposing = composing;
353
+ this.applyFilter();
354
+ const detail = {
355
+ query: input.value.toLowerCase().trim(),
356
+ composing: this.composition.composing
357
+ };
358
+ if (this.lastSearch && this.lastSearch.query === detail.query && this.lastSearch.composing === detail.composing) return;
359
+ this.lastSearch = detail;
360
+ this.fire("search", {
361
+ detail,
362
+ cancelable: false
363
+ });
364
+ }
349
365
  /**
350
366
  * 지금 검색어를 지금 옵션에 적용한다 — 입력 때뿐 아니라 옵션이 바뀔 때도(재사용된 `u-option` 이 앞 검색의 `hidden` 을
351
367
  * 들고 남지 않게). `filter="none"` 이면 아무것도 숨기지 않는다.
@@ -354,9 +370,8 @@ var USelect = class USelect extends UFormControlElement {
354
370
  const query = this.filter === "none" ? "" : this.query;
355
371
  for (const option of this.options) if (!query) option.hidden = false;
356
372
  else {
357
- const label = option.getText().toLowerCase();
358
- const value = option.value.toLowerCase();
359
- option.hidden = !label.includes(query) && !value.includes(query);
373
+ const options = { composing: this.queryComposing };
374
+ option.hidden = !Locale.matchesSearch(option.getText(), query, options) && !Locale.matchesSearch(option.value, query, options);
360
375
  }
361
376
  this.noMatches = !!this.query && !this.loading && !this.options.some((o) => !o.hidden);
362
377
  }
@@ -32,6 +32,9 @@ export declare class USwitch extends UFormControlElement<string> {
32
32
  static styles: import('lit').CSSResultGroup[];
33
33
  /** 체크 여부 */
34
34
  checked: boolean;
35
+ /** `u-form` 의 `model` 에는 제출값(`value`)이 아니라 켬/끔 상태를 싣는다. */
36
+ get modelValue(): unknown;
37
+ set modelValue(value: unknown);
35
38
  /**
36
39
  * 네이티브 `defaultChecked` 에 해당하는 값 — **처음 연결될 때의 `checked` 속성**.
37
40
  * `checked` 는 반영(reflect)되는 속성이라 사용자가 바꾸면 속성도 바뀐다. 그래서 속성을
@@ -24,6 +24,13 @@ var USwitch = class USwitch extends UFormControlElement {
24
24
  static {
25
25
  this.styles = [super.styles, styles];
26
26
  }
27
+ /** `u-form` 의 `model` 에는 제출값(`value`)이 아니라 켬/끔 상태를 싣는다. */
28
+ get modelValue() {
29
+ return this.checked;
30
+ }
31
+ set modelValue(value) {
32
+ this.checked = Boolean(value);
33
+ }
27
34
  connectedCallback() {
28
35
  this.defaultChecked ??= this.hasAttribute("checked");
29
36
  super.connectedCallback();
package/dist/index.d.ts CHANGED
@@ -70,6 +70,8 @@ export * from './utilities/elements.js';
70
70
  export * from './utilities/format.js';
71
71
  export * from './utilities/icons.js';
72
72
  export * from './utilities/keyboard.js';
73
+ export * from './utilities/composition.js';
74
+ export * from './utilities/search.js';
73
75
  export * from './utilities/Locale.js';
74
76
  export * from './utilities/OverlayManager.js';
75
77
  export * from './utilities/Theme.js';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { defaultSearchMatch, foldForSearch, hangulKeystrokes, initialsOf, isHangul } from "./utilities/search.js";
1
2
  import { Locale } from "./utilities/Locale.js";
2
3
  import { UElement } from "./components/UElement.js";
3
4
  import { getParentElement, isCoarsePointer, isFocusCandidate, isFromControl, querySelectorAllWithin, querySelectorDeep, querySelectorWithin } from "./utilities/elements.js";
@@ -42,6 +43,7 @@ import { UOption } from "./components/option/UOption.js";
42
43
  import { UInput } from "./components/input/UInput.js";
43
44
  import { UMenuItem } from "./components/menu-item/UMenuItem.js";
44
45
  import { UMenu } from "./components/menu/UMenu.js";
46
+ import { CompositionTracker, replayInput } from "./utilities/composition.js";
45
47
  import { USelect } from "./components/select/USelect.js";
46
48
  import { UPagination } from "./components/pagination/UPagination.js";
47
49
  import { UPanel } from "./components/panel/UPanel.js";
@@ -66,4 +68,4 @@ import { Dialog } from "./utilities/Dialog.js";
66
68
  import { Theme } from "./utilities/Theme.js";
67
69
  import { Toast } from "./utilities/Toast.js";
68
70
  import { decodeDelimited, decodeTsv, encodeTsv } from "./utilities/tsv.js";
69
- 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, UPagination, 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, decodeDelimited, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isFromControl, isImeComposing, isTextEntry, jsonAttrConverter, localOffset, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, pasteFromKey, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, readDateValue, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter, writeInstant, writePlainDate, writePlainDateTime };
71
+ export { ALERT_STATUSES, BrowserStorage, CompositionTracker, 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, UPagination, 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, decodeDelimited, decodeTsv, defaultSearchMatch, devWarnOnce, encodeTsv, foldForSearch, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, hangulKeystrokes, initialsOf, isCoarsePointer, isFocusCandidate, isFromControl, isHangul, isImeComposing, isTextEntry, jsonAttrConverter, localOffset, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, pasteFromKey, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, readDateValue, replayInput, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter, writeInstant, writePlainDate, writePlainDateTime };
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { USelect as USelectElement } from '@iyulab/components/dist/components/select/USelect.js';
3
+ import { type USelectSearchDetail } from '@iyulab/components/dist/components/select/USelect.js';
3
4
 
4
5
  type EventOf<K extends string> = K extends keyof HTMLElementEventMap ? HTMLElementEventMap[K] : CustomEvent;
5
6
  type USelectOwnProps = Omit<USelectElement, keyof HTMLElement>;
@@ -10,7 +11,7 @@ export declare const USelect: React.ForwardRefExoticComponent<
10
11
  & React.RefAttributes<USelectElement>
11
12
  & {
12
13
  onChange?: (event: EventOf<'change'>) => void;
13
- onSearch?: (event: CustomEvent<{ query: string }>) => void;
14
+ onSearch?: (event: CustomEvent<USelectSearchDetail>) => void;
14
15
  }
15
16
  >;
16
17
 
@@ -1,12 +1,4 @@
1
- /**
2
- * @iyulab/components 의 경량 로케일 유틸리티.
3
- *
4
- * 범위: 라이브러리가 스스로 생성하는 chrome 문자열(검증 메시지 등)만 대상.
5
- * 일반 i18n 프레임워크가 아니다. 앱 콘텐츠 번역은 consumer 의 i18n 계층이 담당한다.
6
- *
7
- * `SupportedLocale` 의 14개 언어가 빌드 시점에 내장된다 (src/assets/locales/*.json).
8
- * 그 외 언어는 register()로 테이블 단위 등록/오버라이드한다.
9
- */
1
+ import { SearchMatchOptions } from './search.js';
10
2
  /** 라이브러리가 기본 제공하는 로케일. */
11
3
  export type SupportedLocale = 'en' | 'ko' | 'ja' | 'zh-CN' | 'zh-TW' | 'es' | 'fr' | 'de' | 'pt-BR' | 'vi' | 'th' | 'id' | 'ru' | 'ar';
12
4
  /** 내장 로케일은 자동완성되지만, 임의의 BCP47 태그도 그대로 받는다. */
@@ -14,6 +6,11 @@ export type LocaleTag = SupportedLocale | (string & {});
14
6
  /** 라이브러리가 제공하는 chrome 문자열 키. 지금은 검증 메시지뿐이지만 이후 다른 UI 문구도 추가될 수 있다. */
15
7
  export type LocaleMessageKey = 'valueMissing' | 'badInput' | 'typeMismatch' | 'patternMismatch' | 'rangeUnderflow' | 'rangeOverflow' | 'stepMismatch' | 'tooShort' | 'tooLong' | 'increment' | 'decrement' | 'clear' | 'today' | 'time' | 'showPassword' | 'hidePassword' | 'previousSlide' | 'nextSlide' | 'goToSlide' | 'carousel' | 'slide' | 'slideOf' | 'stopSlideRotation' | 'startSlideRotation' | 'chooseDate' | 'chooseDateRange' | 'yesterday' | 'last7Days' | 'last30Days' | 'thisWeek' | 'lastWeek' | 'thisMonth' | 'lastMonth' | 'thisYear' | 'quickRanges' | 'rangeStartChosen' | 'previousMonth' | 'nextMonth' | 'close' | 'copy' | 'copied' | 'chooseFile' | 'noFileChosen' | 'filesSelected' | 'resizePanels' | 'loading' | 'breadcrumb' | 'search' | 'noMatches' | 'alertError' | 'alertWarning' | 'alertSuccess' | 'alertInfo' | 'alertNotice' | 'alertMessage' | 'remove' | 'closeTab' | 'confirm' | 'cancel' | 'ok' | 'stepComplete' | 'stepOnHold' | 'apply' | 'dateUnavailable' | 'startTime' | 'endTime' | 'timeAm' | 'timePm' | 'pagination' | 'previousPage' | 'nextPage' | 'pageN' | 'rowsPerPage' | 'rangeOfTotal';
16
8
  type LocaleTable = Record<LocaleMessageKey, string>;
9
+ /**
10
+ * 글자가 검색어를 담는가 — 사람이 «찾았다» 고 여기는 일치. 글자마다 거르는 칸(`u-select` 의 검색 등)이 쓴다.
11
+ * `text` 는 옵션 글자 같은 대상, `query` 는 사람이 친 검색어 — `options.composing` 이면 마지막 음절이 아직 조합 중이다.
12
+ */
13
+ export type SearchMatcher = (text: string, query: string, options: SearchMatchOptions) => boolean;
17
14
  /**
18
15
  * 한 패키지(또는 앱 영역)의 문자열 묶음.
19
16
  *
@@ -76,6 +73,21 @@ export declare class Locale {
76
73
  * `params`가 있으면 템플릿의 `{name}` 자리를 치환합니다.
77
74
  */
78
75
  static getValue(key: LocaleMessageKey, params?: Record<string, string | number>, locale?: LocaleTag): string;
76
+ /**
77
+ * 한 언어의 검색 일치를 등록합니다 — 그 언어에서 `u-select` 의 검색 같은 거르기가 이 규칙을 씁니다.
78
+ *
79
+ * 기본 규칙(대소문자 · 발음 구별 기호 접기, 한글 자모 · 초성 일치)은 문자 체계에 매여 있어 모든 언어에 이미 있습니다.
80
+ * 언어에 매인 규칙만 여기 둡니다 — 터키어의 `İ`/`ı` 처럼. 기본 규칙을 이어 쓰려면 `defaultSearchMatch` 를 부르세요.
81
+ */
82
+ static registerSearch(locale: LocaleTag, matcher: SearchMatcher): void;
83
+ /**
84
+ * `text` 가 `query` 를 담는가 — 활성 로케일(또는 `options.locale`)에 등록된 검색 일치로, 없으면 기본 규칙으로.
85
+ * 빈 검색어는 모두를 담습니다. 질의의 마지막 음절이 아직 IME 로 조합 중이면 `composing: true` 를 넘기세요 — 그 음절은
86
+ * 자모 앞부분으로 견줍니다(`CompositionTracker.searchQuery()` 가 둘을 함께 줍니다).
87
+ */
88
+ static matchesSearch(text: string, query: string, options?: SearchMatchOptions & {
89
+ locale?: LocaleTag;
90
+ }): boolean;
79
91
  /**
80
92
  * 네임스페이스 핸들을 얻습니다 — 같은 이름이면 **같은 저장소**를 가리킵니다.
81
93
  *
@@ -12,6 +12,7 @@ import th_default from "../assets/locales/th.json.js";
12
12
  import vi_default from "../assets/locales/vi.json.js";
13
13
  import zh_CN_default from "../assets/locales/zh-CN.json.js";
14
14
  import zh_TW_default from "../assets/locales/zh-TW.json.js";
15
+ import { defaultSearchMatch } from "./search.js";
15
16
  //#region src/utilities/Locale.ts
16
17
  var builtins = new Map(Object.entries(/* #__PURE__ */ Object.assign({
17
18
  "../assets/locales/ar.json": ar_default,
@@ -105,6 +106,8 @@ function lookup(locale, key) {
105
106
  }
106
107
  /** ns → 정규화 로케일 태그 → 테이블. */
107
108
  var namespaces = /* @__PURE__ */ new Map();
109
+ /** 정규화 로케일 태그 → 그 언어에 등록된 검색 일치. 없으면 문자 체계 기본 규칙(`defaultSearchMatch`). */
110
+ var searchMatchers = /* @__PURE__ */ new Map();
108
111
  /**
109
112
  * 검증 메시지 로케일을 관리하는 정적 유틸리티입니다.
110
113
  */
@@ -160,6 +163,29 @@ var Locale = class {
160
163
  return interpolate(lookup(locale ?? active, key), params);
161
164
  }
162
165
  /**
166
+ * 한 언어의 검색 일치를 등록합니다 — 그 언어에서 `u-select` 의 검색 같은 거르기가 이 규칙을 씁니다.
167
+ *
168
+ * 기본 규칙(대소문자 · 발음 구별 기호 접기, 한글 자모 · 초성 일치)은 문자 체계에 매여 있어 모든 언어에 이미 있습니다.
169
+ * 언어에 매인 규칙만 여기 둡니다 — 터키어의 `İ`/`ı` 처럼. 기본 규칙을 이어 쓰려면 `defaultSearchMatch` 를 부르세요.
170
+ */
171
+ static registerSearch(locale, matcher) {
172
+ searchMatchers.set(locale.toLowerCase(), matcher);
173
+ notify();
174
+ }
175
+ /**
176
+ * `text` 가 `query` 를 담는가 — 활성 로케일(또는 `options.locale`)에 등록된 검색 일치로, 없으면 기본 규칙으로.
177
+ * 빈 검색어는 모두를 담습니다. 질의의 마지막 음절이 아직 IME 로 조합 중이면 `composing: true` 를 넘기세요 — 그 음절은
178
+ * 자모 앞부분으로 견줍니다(`CompositionTracker.searchQuery()` 가 둘을 함께 줍니다).
179
+ */
180
+ static matchesSearch(text, query, options = {}) {
181
+ const { locale, ...rest } = options;
182
+ for (const tag of chainOf(locale || active)) {
183
+ const matcher = searchMatchers.get(tag);
184
+ if (matcher) return matcher(text, query, rest);
185
+ }
186
+ return defaultSearchMatch(text, query, rest);
187
+ }
188
+ /**
163
189
  * 네임스페이스 핸들을 얻습니다 — 같은 이름이면 **같은 저장소**를 가리킵니다.
164
190
  *
165
191
  * 상위 패키지가 자기 화면 문자열을 담는 자리입니다. 검증 메시지(`getValue`)의 키셋과
@@ -0,0 +1,43 @@
1
+ /**
2
+ * IME 조합(한국어 · 일본어 · 중국어)을 따라가는 입력 도우미 — 조합 중인 음절을 뺀 «확정된 글자» 를 준다.
3
+ *
4
+ * 글자마다 거르거나 찾는 입력은 조합 단계(«서울» 의 가는 길 «ㅅ» · «서» · «성» · «서우»)마다 그 글자로 거른다. 조합 중인
5
+ * 음절은 아직 무엇이 될지 모르는 «진행 중» 이라, 그것으로 거르면 사용자가 찾는 항목을 숨기고 «결과 없음» 을 알린다.
6
+ * 확정된 부분을 담는 항목은 최종 글자를 담는 항목의 상위 집합이므로(포함 · 접두 일치 둘 다), 확정된 부분으로 거르면 찾는
7
+ * 항목을 숨기지 않는다.
8
+ *
9
+ * 리스너 객체로 입력 요소에 건다 — Lit 템플릿에서는
10
+ * `@compositionstart=${tracker} @compositionupdate=${tracker} @compositionend=${tracker}`.
11
+ *
12
+ * Chromium 은 조합의 마지막 `input` 을 `isComposing: true` 로 내고 `compositionend` 로 끝낸다 — 조합 끝의 확정 글자로
13
+ * 다시 거르려면 `onEnd` 를 받는다.
14
+ */
15
+ export declare class CompositionTracker implements EventListenerObject {
16
+ private readonly onEnd?;
17
+ /** 조합이 시작된 자리 — 조합 중이 아니면 `null`. */
18
+ private start;
19
+ /** 지금 조합 중인 글자. */
20
+ private text;
21
+ /** @param onEnd 조합이 끝났을 때(확정 글자가 입력 요소에 들어간 뒤) 부른다. */
22
+ constructor(onEnd?: ((input: HTMLInputElement | HTMLTextAreaElement) => void) | undefined);
23
+ /** 조합이 진행 중인가. */
24
+ get composing(): boolean;
25
+ handleEvent(event: Event): void;
26
+ /**
27
+ * 검색 일치(`Locale.matchesSearch`)에 넘길 질의 — `{ query, composing }`. 글 끝에서 조합 중인 글자가 한글이면 그것까지
28
+ * 담고 `composing: true` 다: 한글의 조합 중 음절은 자모로 풀면 최종 글자 자모의 앞부분이라(`성` → `ㅅㅓㅇ` ⊂ `서울` →
29
+ * `ㅅㅓㅇㅜㄹ`) 검색 일치가 그 음절을 앞부분으로 견준다. 그 성질은 조합이 글 끝에 있을 때만 서고(가운데라면 뒤 글자가
30
+ * 붙는다), 다른 문자 체계의 조합 글자(가나 → 한자 변환 전)는 최종 글자와 견줄 수 없어 확정된 부분만 준다.
31
+ */
32
+ searchQuery(input: HTMLInputElement | HTMLTextAreaElement): {
33
+ query: string;
34
+ composing: boolean;
35
+ };
36
+ /** 입력의 확정된 글자 — 조합 중인 음절을 뺀 값. 조합 중이 아니면 값 그대로. */
37
+ settled(input: HTMLInputElement | HTMLTextAreaElement): string;
38
+ }
39
+ /**
40
+ * 입력 칸의 `input` 처리기를 다시 부른다 — 그 칸 자신의 처리기만(전파하지 않는다). 조합 중에는 거르기·검색을 멈추는
41
+ * 칸이 조합 끝에 확정 글자로 다시 돌게 하는 `onEnd`: `new CompositionTracker(replayInput)`.
42
+ */
43
+ export declare function replayInput(input: HTMLInputElement | HTMLTextAreaElement): void;
@@ -0,0 +1,76 @@
1
+ import { isHangul } from "./search.js";
2
+ //#region src/utilities/composition.ts
3
+ /**
4
+ * IME 조합(한국어 · 일본어 · 중국어)을 따라가는 입력 도우미 — 조합 중인 음절을 뺀 «확정된 글자» 를 준다.
5
+ *
6
+ * 글자마다 거르거나 찾는 입력은 조합 단계(«서울» 의 가는 길 «ㅅ» · «서» · «성» · «서우»)마다 그 글자로 거른다. 조합 중인
7
+ * 음절은 아직 무엇이 될지 모르는 «진행 중» 이라, 그것으로 거르면 사용자가 찾는 항목을 숨기고 «결과 없음» 을 알린다.
8
+ * 확정된 부분을 담는 항목은 최종 글자를 담는 항목의 상위 집합이므로(포함 · 접두 일치 둘 다), 확정된 부분으로 거르면 찾는
9
+ * 항목을 숨기지 않는다.
10
+ *
11
+ * 리스너 객체로 입력 요소에 건다 — Lit 템플릿에서는
12
+ * `@compositionstart=${tracker} @compositionupdate=${tracker} @compositionend=${tracker}`.
13
+ *
14
+ * Chromium 은 조합의 마지막 `input` 을 `isComposing: true` 로 내고 `compositionend` 로 끝낸다 — 조합 끝의 확정 글자로
15
+ * 다시 거르려면 `onEnd` 를 받는다.
16
+ */
17
+ var CompositionTracker = class {
18
+ /** @param onEnd 조합이 끝났을 때(확정 글자가 입력 요소에 들어간 뒤) 부른다. */
19
+ constructor(onEnd) {
20
+ this.onEnd = onEnd;
21
+ this.start = null;
22
+ this.text = "";
23
+ }
24
+ /** 조합이 진행 중인가. */
25
+ get composing() {
26
+ return this.start !== null;
27
+ }
28
+ handleEvent(event) {
29
+ const input = event.target;
30
+ switch (event.type) {
31
+ case "compositionstart":
32
+ this.start = input.selectionStart ?? input.value.length;
33
+ this.text = "";
34
+ break;
35
+ case "compositionupdate":
36
+ this.text = event.data ?? "";
37
+ break;
38
+ case "compositionend":
39
+ this.start = null;
40
+ this.text = "";
41
+ this.onEnd?.(input);
42
+ }
43
+ }
44
+ /**
45
+ * 검색 일치(`Locale.matchesSearch`)에 넘길 질의 — `{ query, composing }`. 글 끝에서 조합 중인 글자가 한글이면 그것까지
46
+ * 담고 `composing: true` 다: 한글의 조합 중 음절은 자모로 풀면 최종 글자 자모의 앞부분이라(`성` → `ㅅㅓㅇ` ⊂ `서울` →
47
+ * `ㅅㅓㅇㅜㄹ`) 검색 일치가 그 음절을 앞부분으로 견준다. 그 성질은 조합이 글 끝에 있을 때만 서고(가운데라면 뒤 글자가
48
+ * 붙는다), 다른 문자 체계의 조합 글자(가나 → 한자 변환 전)는 최종 글자와 견줄 수 없어 확정된 부분만 준다.
49
+ */
50
+ searchQuery(input) {
51
+ return this.start !== null && this.start + this.text.length === input.value.length && isHangul(this.text) ? {
52
+ query: input.value,
53
+ composing: true
54
+ } : {
55
+ query: this.settled(input),
56
+ composing: false
57
+ };
58
+ }
59
+ /** 입력의 확정된 글자 — 조합 중인 음절을 뺀 값. 조합 중이 아니면 값 그대로. */
60
+ settled(input) {
61
+ if (this.start === null) return input.value;
62
+ return input.value.slice(0, this.start) + input.value.slice(this.start + this.text.length);
63
+ }
64
+ };
65
+ /**
66
+ * 입력 칸의 `input` 처리기를 다시 부른다 — 그 칸 자신의 처리기만(전파하지 않는다). 조합 중에는 거르기·검색을 멈추는
67
+ * 칸이 조합 끝에 확정 글자로 다시 돌게 하는 `onEnd`: `new CompositionTracker(replayInput)`.
68
+ */
69
+ function replayInput(input) {
70
+ input.dispatchEvent(new Event("input", {
71
+ bubbles: false,
72
+ composed: false
73
+ }));
74
+ }
75
+ //#endregion
76
+ export { CompositionTracker, replayInput };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 검색 일치 — 사람이 «찾았다» 고 여기는 일치. 글자마다 거르는 칸(선택기의 검색 · 표의 필터)이 쓴다.
3
+ *
4
+ * 기본 규칙은 문자 체계에 매여 있어 어느 언어 화면에서나 같다:
5
+ * - 대소문자와 발음 구별 기호를 접는다 — `Ä` · `ä` · `a` 가 같다. 한글 음절은 음절 그대로 견준다(`서` 는 `성` 이 아니다).
6
+ * - 질의의 마지막 음절이 **아직 조합 중**이면(`composing`) 그 음절은 자판으로 친 순서의 자모로 앞부분 일치한다 — 치는
7
+ * 도중의 `성` 이 `서울`(`ㅅㅓㅇ` ⊂ `ㅅㅓㅇㅜㄹ`)을, `서우` 가 `서울` 을 맞춘다. 겹모음 · 겹받침은 두 글쇠로 풀어 `고` 가
8
+ * `과` 의 앞부분이 된다. 유니코드 정규화(NFD)로는 안 된다 — 받침 `ᆼ` 과 초성 `ᄋ` 이 다른 글자다.
9
+ * - 질의가 한글 자음만이면 초성끼리도 맞춘다 — `ㅅㅇ` 이 `서울` 을 맞춘다.
10
+ *
11
+ * 언어에 매인 규칙(터키어의 `İ`/`ı` 처럼)은 `Locale.registerSearch()` 로 그 언어에 등록한다.
12
+ */
13
+ /** 검색 일치의 선택 — `composing`: 질의의 마지막 음절이 아직 IME 로 조합 중이다. */
14
+ export interface SearchMatchOptions {
15
+ composing?: boolean;
16
+ }
17
+ /** 글자가 한글(음절 · 호환 자모)만으로 되어 있는가 — 빈 글자는 아니다. */
18
+ export declare function isHangul(text: string): boolean;
19
+ /** 대소문자 · 발음 구별 기호를 접는다 — 한글은 그대로(음절 그대로 견준다). */
20
+ export declare function foldForSearch(text: string): string;
21
+ /**
22
+ * 한글을 자판으로 친 순서의 호환 자모로 푼다(`과` → `ㄱㅗㅏ` · `닭` → `ㄷㅏㄹㄱ`) — 그 밖의 글자는 `foldForSearch` 처럼 접는다.
23
+ * 조합 중 음절의 풀이는 늘 최종 글자 풀이의 앞부분이다.
24
+ */
25
+ export declare function hangulKeystrokes(text: string): string;
26
+ /** 한글 음절의 초성들 — 음절이 아닌 글자는 그대로(`서울 2` → `ㅅㅇ 2`). */
27
+ export declare function initialsOf(text: string): string;
28
+ /** 글자가 검색어를 담는가 — 기본 규칙(이 모듈 머리말). 빈 검색어는 모두를 담는다. */
29
+ export declare function defaultSearchMatch(text: string, query: string, options?: SearchMatchOptions): boolean;
@@ -0,0 +1,151 @@
1
+ //#region src/utilities/search.ts
2
+ var HANGUL_BASE = 44032;
3
+ var HANGUL_LAST = 55203;
4
+ /** 초성 19 — 호환 자모. */
5
+ var INITIALS = "ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ";
6
+ /** 중성 21 — 자판으로 친 순서(겹모음은 두 글쇠). */
7
+ var MEDIALS = [
8
+ "ㅏ",
9
+ "ㅐ",
10
+ "ㅑ",
11
+ "ㅒ",
12
+ "ㅓ",
13
+ "ㅔ",
14
+ "ㅕ",
15
+ "ㅖ",
16
+ "ㅗ",
17
+ "ㅗㅏ",
18
+ "ㅗㅐ",
19
+ "ㅗㅣ",
20
+ "ㅛ",
21
+ "ㅜ",
22
+ "ㅜㅓ",
23
+ "ㅜㅔ",
24
+ "ㅜㅣ",
25
+ "ㅠ",
26
+ "ㅡ",
27
+ "ㅡㅣ",
28
+ "ㅣ"
29
+ ];
30
+ /** 종성 28(없음 포함) — 자판으로 친 순서(겹받침은 두 글쇠). */
31
+ var FINALS = [
32
+ "",
33
+ "ㄱ",
34
+ "ㄲ",
35
+ "ㄱㅅ",
36
+ "ㄴ",
37
+ "ㄴㅈ",
38
+ "ㄴㅎ",
39
+ "ㄷ",
40
+ "ㄹ",
41
+ "ㄹㄱ",
42
+ "ㄹㅁ",
43
+ "ㄹㅂ",
44
+ "ㄹㅅ",
45
+ "ㄹㅌ",
46
+ "ㄹㅍ",
47
+ "ㄹㅎ",
48
+ "ㅁ",
49
+ "ㅂ",
50
+ "ㅂㅅ",
51
+ "ㅅ",
52
+ "ㅆ",
53
+ "ㅇ",
54
+ "ㅈ",
55
+ "ㅊ",
56
+ "ㅋ",
57
+ "ㅌ",
58
+ "ㅍ",
59
+ "ㅎ"
60
+ ];
61
+ /** 호환 자모 중 두 글쇠로 치는 것(겹모음 · 겹받침). */
62
+ var COMPOUND_JAMO = {
63
+ "ㅘ": "ㅗㅏ",
64
+ "ㅙ": "ㅗㅐ",
65
+ "ㅚ": "ㅗㅣ",
66
+ "ㅝ": "ㅜㅓ",
67
+ "ㅞ": "ㅜㅔ",
68
+ "ㅟ": "ㅜㅣ",
69
+ "ㅢ": "ㅡㅣ",
70
+ "ㄳ": "ㄱㅅ",
71
+ "ㄵ": "ㄴㅈ",
72
+ "ㄶ": "ㄴㅎ",
73
+ "ㄺ": "ㄹㄱ",
74
+ "ㄻ": "ㄹㅁ",
75
+ "ㄼ": "ㄹㅂ",
76
+ "ㄽ": "ㄹㅅ",
77
+ "ㄾ": "ㄹㅌ",
78
+ "ㄿ": "ㄹㅍ",
79
+ "ㅀ": "ㄹㅎ",
80
+ "ㅄ": "ㅂㅅ"
81
+ };
82
+ function isSyllable(code) {
83
+ return code >= HANGUL_BASE && code <= HANGUL_LAST;
84
+ }
85
+ /** 호환 자모(ㄱ–ㅣ). */
86
+ function isCompatJamo(code) {
87
+ return code >= 12593 && code <= 12643;
88
+ }
89
+ function isHangulChar(ch) {
90
+ const code = ch.codePointAt(0);
91
+ return isSyllable(code) || isCompatJamo(code);
92
+ }
93
+ /** 글자가 한글(음절 · 호환 자모)만으로 되어 있는가 — 빈 글자는 아니다. */
94
+ function isHangul(text) {
95
+ if (!text) return false;
96
+ for (const ch of text) if (!isHangulChar(ch)) return false;
97
+ return true;
98
+ }
99
+ /** 대소문자 · 발음 구별 기호를 접는다 — 한글은 그대로(음절 그대로 견준다). */
100
+ function foldForSearch(text) {
101
+ let out = "";
102
+ for (const ch of text) out += isHangulChar(ch) ? ch : ch.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
103
+ return out;
104
+ }
105
+ /**
106
+ * 한글을 자판으로 친 순서의 호환 자모로 푼다(`과` → `ㄱㅗㅏ` · `닭` → `ㄷㅏㄹㄱ`) — 그 밖의 글자는 `foldForSearch` 처럼 접는다.
107
+ * 조합 중 음절의 풀이는 늘 최종 글자 풀이의 앞부분이다.
108
+ */
109
+ function hangulKeystrokes(text) {
110
+ let out = "";
111
+ for (const ch of text) {
112
+ const code = ch.codePointAt(0);
113
+ if (isSyllable(code)) {
114
+ const offset = code - HANGUL_BASE;
115
+ out += INITIALS[Math.floor(offset / 588)] + MEDIALS[Math.floor(offset % 588 / 28)] + FINALS[offset % 28];
116
+ } else if (isCompatJamo(code)) out += COMPOUND_JAMO[ch] ?? ch;
117
+ else out += foldForSearch(ch);
118
+ }
119
+ return out;
120
+ }
121
+ /** 한글 음절의 초성들 — 음절이 아닌 글자는 그대로(`서울 2` → `ㅅㅇ 2`). */
122
+ function initialsOf(text) {
123
+ let out = "";
124
+ for (const ch of text) {
125
+ const code = ch.codePointAt(0);
126
+ out += isSyllable(code) ? INITIALS[Math.floor((code - HANGUL_BASE) / 588)] : ch;
127
+ }
128
+ return out;
129
+ }
130
+ /** 질의가 한글 자음(초성으로 쓰이는 것)만으로 되어 있는가. */
131
+ function isInitialsQuery(query) {
132
+ if (!query) return false;
133
+ for (const ch of query) if (!INITIALS.includes(ch)) return false;
134
+ return true;
135
+ }
136
+ /** 글자가 검색어를 담는가 — 기본 규칙(이 모듈 머리말). 빈 검색어는 모두를 담는다. */
137
+ function defaultSearchMatch(text, query, options = {}) {
138
+ const q = query.trim();
139
+ if (!q) return true;
140
+ if (isInitialsQuery(q) && initialsOf(text).includes(q)) return true;
141
+ const chars = [...q];
142
+ const last = chars[chars.length - 1];
143
+ const folded = foldForSearch(text);
144
+ if (!options.composing || !isHangulChar(last)) return folded.includes(foldForSearch(q));
145
+ const head = foldForSearch(chars.slice(0, -1).join(""));
146
+ const tail = hangulKeystrokes(last);
147
+ for (let at = folded.indexOf(head); at !== -1 && at < folded.length; at = folded.indexOf(head, at + 1)) if (hangulKeystrokes(folded.slice(at + head.length)).startsWith(tail)) return true;
148
+ return false;
149
+ }
150
+ //#endregion
151
+ export { defaultSearchMatch, foldForSearch, hangulKeystrokes, initialsOf, isHangul };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iyulab/components",
3
3
  "description": "web-components library based on lit-element made by iyulab",
4
- "version": "2.21.0",
4
+ "version": "2.22.0",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",
@@ -142,11 +142,11 @@ set on the host yourself always wins and is never overwritten.
142
142
  - [`IconRegistry`](./references/utilities/icons.md) — Register and resolve icon libraries
143
143
  - [`BrowserStorage`](./references/utilities/browser-storage.md) — Unified localStorage / Cookie API
144
144
  - [`converters`](./references/utilities/converters.md) — Lit property attribute converters (array, JSON, date, url…)
145
- - [`Locale`](./references/utilities/locale.md) — Validation-message locale registry and lookup utility
145
+ - [`Locale`](./references/utilities/locale.md) — Validation-message locale registry and lookup utility · search matching (`matchesSearch` — Hangul jamo and initials)
146
146
  - [`elements`](./references/utilities/elements.md) — Shadow-DOM-aware DOM query helpers
147
147
  - [`format`](./references/utilities/format.md) — Locale-aware number, currency and date formatting
148
148
  - [`clipboard`](./references/utilities/clipboard.md) — `copyFromKey` / `pasteFromKey` / `isTextEntry`, Ctrl/Cmd + C · X · V for a grid or list selection in every browser (Safari fires no copy event without a text selection)
149
- - [`keyboard`](./references/utilities/keyboard.md) — `isImeComposing` for Enter handlers that must not fire mid-composition (Korean/Japanese/Chinese input)
149
+ - [`keyboard`](./references/utilities/keyboard.md) — `isImeComposing` for Enter handlers that must not fire mid-composition (Korean/Japanese/Chinese input) · `CompositionTracker` / `replayInput` for inputs that filter as you type
150
150
  - [`tsv`](./references/utilities/tsv.md) — `encodeTsv` / `decodeTsv`, the spreadsheet clipboard format with RFC 4180 quoting
151
151
  - [`OverlayManager`](./references/utilities/overlay-manager.md) — Internal overlay stack and z-index manager
152
152
 
@@ -52,7 +52,7 @@ form.reset();
52
52
 
53
53
  | Property | Type | Default | Description |
54
54
  |----------|------|---------|-------------|
55
- | `model` | `Record<string, unknown>` | — | Two-way bound data model |
55
+ | `model` | `Record<string, unknown>` | — | Two-way bound data model, keyed by control `name`. Each control exchanges its `modelValue` — `value` for most controls, the `checked` boolean for `u-checkbox` and `u-switch` |
56
56
  | `includes` | `string[]` | `[]` | Only include these field names (empty = all) |
57
57
  | `excludes` | `string[]` | `[]` | Exclude these field names |
58
58
 
@@ -60,7 +60,7 @@ form.reset();
60
60
 
61
61
  | Event | Description |
62
62
  |-------|-------------|
63
- | `change` | Fires when any control value changes |
63
+ | `change` | Fires when a control in the form changes through user input, after `model` is updated |
64
64
 
65
65
  ## Methods
66
66
 
@@ -62,7 +62,7 @@ Dropdown select with single or multiple selection, search, and clear support. Fo
62
62
  | Event | Description |
63
63
  |-------|-------------|
64
64
  | `change` | Fires when selection changes |
65
- | `search` | Fires on every search input change when `searchable` (`detail: { query: string }`). With `filter="none"` the select hides nothing, so the options you set from the server are shown as they are — otherwise the built-in local filter runs too |
65
+ | `search` | Fires when the search text changes, when `searchable` (`detail: { query: string; composing: boolean }`). While an IME composition is in progress (Korean, Japanese, Chinese) `composing` is `true` and `query` ends in a partial syllable; when it ends the event fires again with `false` — a server search can skip composing queries. While composing, the built-in filter uses only the committed part, so it never hides an option the finished text would match. With `filter="none"` the select hides nothing, so the options you set from the server are shown as they are — otherwise the built-in local filter runs too |
66
66
 
67
67
  ## Methods
68
68
 
@@ -30,7 +30,7 @@ export class MyBadge extends UElement {
30
30
  | Method | Signature | Description |
31
31
  |--------|-----------|-------------|
32
32
  | `fire` | `fire<T>(name, options?): boolean` | Dispatch a `CustomEvent` on the host. `bubbles`, `composed`, `cancelable` are `true` by default. Returns `false` if the event was cancelled. |
33
- | `relay` | `relay(event, options?): void` | Re-dispatch a native DOM event from the host (stops original event, re-fires as new). Useful for surfacing inner element events to light DOM. |
33
+ | `relay` | `relay(event, options?): boolean` | Re-dispatch a DOM event from the host: stops the original and fires the same type with the same init — `bubbles`, `cancelable` and type-specific fields (`InputEvent.data`/`inputType`, `CustomEvent.detail`) — and `composed: true`, so listeners on the host's ancestors receive it. Use it to surface inner element events (a native `change` stays inside the shadow root otherwise). Returns `false` if the event was cancelled. |
34
34
  | `replace` | `replace(value, options?): void` | Replace the entire shadow DOM render output with a new Lit `TemplateResult`. Preserves `<style>` tags. |
35
35
 
36
36
  ## Static members
@@ -78,6 +78,12 @@ export class MyInput extends UFormControlElement<string> {
78
78
  | `form` | `HTMLFormElement \| null` | Associated form element |
79
79
  | `validity` | `ValidityState \| undefined` | Native validity state |
80
80
 
81
+ ## Model value (`u-form`)
82
+
83
+ `modelValue` (getter/setter, `unknown`) is the value a `u-form` reads into and writes from its `model`. It defaults to
84
+ `value`. Override it when the control's state lives in another property — `u-checkbox` and `u-switch` exchange
85
+ `checked` (a boolean), not the submitted `value`.
86
+
81
87
  ## Abstract Methods (must implement)
82
88
 
83
89
  | Method | Returns | Description |
@@ -25,3 +25,41 @@ onKeydown(e: KeyboardEvent) {
25
25
  ```
26
26
 
27
27
  `u-input` (implicit form submission), `Dialog.prompt`, and the overlay Escape handling already use it.
28
+
29
+ ## Filtering as you type — `CompositionTracker`, `replayInput`
30
+
31
+ ```ts
32
+ import { CompositionTracker, replayInput } from '@iyulab/components';
33
+ // or: '@iyulab/components/dist/utilities/composition.js'
34
+ ```
35
+
36
+ An input that filters or searches on every `input` event sees each step of an IME composition: typing
37
+ «서울» in Korean passes through `ㅅ`, `서`, `성`, `서우`. Filtering on those hides what the person is
38
+ looking for, shows "No results", and — for a server search — sends queries for half-typed syllables.
39
+ Chromium sends the composition's last `input` with `isComposing: true` and then `compositionend`, so
40
+ a handler that only skips composing events never sees the finished text.
41
+
42
+ Attach a tracker to the input's composition events (it is an event listener object):
43
+
44
+ ```ts
45
+ private readonly ime = new CompositionTracker(replayInput);
46
+
47
+ render() {
48
+ return html`<input
49
+ @compositionstart=${this.ime} @compositionupdate=${this.ime} @compositionend=${this.ime}
50
+ @input=${this.onInput}>`;
51
+ }
52
+ ```
53
+
54
+ - `ime.composing` — a composition is in progress.
55
+ - `ime.settled(input)` — the text without the part still being composed. Items containing the settled
56
+ text are a superset of items containing the finished text, so filtering on it never hides a match.
57
+ - `ime.searchQuery(input)` — `{ query, composing }` for `Locale.matchesSearch(text, query, { composing })`:
58
+ the settled text plus a Hangul syllable being composed at the end, which the matcher compares as a
59
+ partial syllable.
60
+ - `replayInput` as the `onEnd` callback re-runs the input's own `input` handler when the composition
61
+ ends. Use it for an input that waits: a server search, or a filter whose rule is not «contains»
62
+ (equals, wildcard) or that announces its value to the outside.
63
+
64
+ Keep the text bound to the input (`.value=${…}`) as the whole box text — binding the settled text
65
+ re-renders the input mid-composition and cancels it.
@@ -42,6 +42,8 @@ same chain.
42
42
  | `Locale.namespace(name)` | A string table for a package or app area, keyed by its own union — returns a handle (below) |
43
43
  | `Locale.subscribe(listener)` | Call `listener` whenever the locale changes (`set` to another locale, any `register`) — returns the unsubscribe function |
44
44
  | `Locale.revision` | A number that grows on every change — a snapshot or cache key (`get()` stays the same when only a table changes) |
45
+ | `Locale.matchesSearch(text, query, options?)` | Whether `text` contains `query` as a person searching means it — the rule registered for the locale (`options.locale`, or the active one), or the default (below). `options.composing`: the query's last syllable is still being composed with an IME |
46
+ | `Locale.registerSearch(locale, matcher)` | Register a language's own search rule, `(text, query, { composing }) => boolean` |
45
47
 
46
48
  ### Switching at runtime
47
49
 
@@ -75,6 +77,30 @@ t.textIn(el.locale, 'empty'); // a given locale (e.g. an element's own
75
77
  A key missing from every table in the chain returns the key itself, so a gap shows on screen
76
78
  instead of rendering as an empty string.
77
79
 
80
+ ### Search matching
81
+
82
+ `u-select`'s search filters options with `Locale.matchesSearch`. The default rule belongs to the
83
+ writing system, so it applies under every locale (`defaultSearchMatch`, `foldForSearch`,
84
+ `hangulKeystrokes` and `initialsOf` are exported from `utilities/search`):
85
+
86
+ - Case and diacritics fold — `Ä`, `ä` and `a` match. Hangul syllables are compared whole: `서` does
87
+ not match `성남`.
88
+ - With `composing: true`, the query's last syllable is still being typed, and it is compared as the
89
+ jamo in typing order (`과` → `ㄱㅗㅏ`, `닭` → `ㄷㅏㄹㄱ`) against the start of what follows: `성` and
90
+ `서우` on the way to `서울` both match `서울`. Unicode normalization cannot do this — a final `ㅇ`
91
+ and an initial `ㅇ` are different characters there. `CompositionTracker.searchQuery(input)` gives
92
+ the query and this flag together.
93
+ - A query of Hangul consonants only also matches initials: `ㅅㅇ` finds `서울`.
94
+
95
+ Register a rule only for what belongs to a language:
96
+
97
+ ```ts
98
+ import { Locale, defaultSearchMatch } from '@iyulab/components';
99
+
100
+ Locale.registerSearch('tr', (text, query, options) =>
101
+ text.toLocaleLowerCase('tr').includes(query.toLocaleLowerCase('tr')) || defaultSearchMatch(text, query, options));
102
+ ```
103
+
78
104
  ## Example
79
105
 
80
106
  ```ts