@iyulab/components 2.20.3 → 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.
- package/CHANGELOG.md +64 -0
- package/dist/components/UElement.d.ts +5 -1
- package/dist/components/UElement.js +9 -2
- package/dist/components/UFormControlElement.d.ts +7 -0
- package/dist/components/UFormControlElement.js +11 -0
- package/dist/components/calendar/datetime.d.ts +2 -3
- package/dist/components/calendar/datetime.js +3 -15
- package/dist/components/checkbox/UCheckbox.d.ts +3 -0
- package/dist/components/checkbox/UCheckbox.js +7 -0
- package/dist/components/form/UForm.js +2 -2
- package/dist/components/input/UInput.js +2 -2
- package/dist/components/select/USelect.d.ts +25 -5
- package/dist/components/select/USelect.js +25 -10
- package/dist/components/switch/USwitch.d.ts +3 -0
- package/dist/components/switch/USwitch.js +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -1
- package/dist/react/USelect.d.ts +2 -1
- package/dist/utilities/Locale.d.ts +21 -9
- package/dist/utilities/Locale.js +26 -0
- package/dist/utilities/composition.d.ts +43 -0
- package/dist/utilities/composition.js +76 -0
- package/dist/utilities/dateValue.d.ts +36 -0
- package/dist/utilities/dateValue.js +79 -0
- package/dist/utilities/format.js +8 -17
- package/dist/utilities/search.d.ts +29 -0
- package/dist/utilities/search.js +151 -0
- package/package.json +1 -1
- package/skills/iyulab-components/SKILL.md +2 -2
- package/skills/iyulab-components/references/components/form.md +2 -2
- package/skills/iyulab-components/references/components/select.md +1 -1
- package/skills/iyulab-components/references/extensions/element.md +1 -1
- package/skills/iyulab-components/references/extensions/form-control.md +6 -0
- package/skills/iyulab-components/references/utilities/format.md +29 -3
- package/skills/iyulab-components/references/utilities/keyboard.md +38 -0
- package/skills/iyulab-components/references/utilities/locale.md +26 -0
|
@@ -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,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The three kinds of date value an app receives as text, read and written in one place.
|
|
3
|
+
* The names come from Temporal:
|
|
4
|
+
*
|
|
5
|
+
* - **`instant`** — a date-time with an offset or `Z` (`2026-09-06T22:22:34Z`, `…+09:00`). It names one
|
|
6
|
+
* moment everywhere; shown here, it is this browser's wall clock at that moment.
|
|
7
|
+
* - **`plainDateTime`** — a date-time without an offset (`2026-09-06T22:22`, `2026-09-06 22:22:34`). It is a
|
|
8
|
+
* wall clock already and is read as local time, never shifted.
|
|
9
|
+
* - **`plainDate`** — a calendar day (`2026-09-06`). It is local midnight of that day. `new Date('2026-09-06')`
|
|
10
|
+
* is UTC midnight instead, which is the previous day west of Greenwich.
|
|
11
|
+
*
|
|
12
|
+
* A `Date` is an instant. Text that is none of the three, or names a day that does not exist
|
|
13
|
+
* (`2026-02-30`), reads as `null` — never a rolled-over or guessed date.
|
|
14
|
+
*/
|
|
15
|
+
export type DateValueKind = 'instant' | 'plainDateTime' | 'plainDate';
|
|
16
|
+
/** A date value with the kind its text named. `date` is the moment it means here. */
|
|
17
|
+
export interface DateValue {
|
|
18
|
+
kind: DateValueKind;
|
|
19
|
+
date: Date;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads a date value and tells which kind it is. `null` for text that is not one of the three
|
|
23
|
+
* kinds, for a day or time that does not exist, and for an invalid `Date`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readDateValue(value: Date | string): DateValue | null;
|
|
26
|
+
/** `±HH:mm` for this browser's time zone at `date` — recomputed per date, so a DST change is honoured
|
|
27
|
+
* (`getTimezoneOffset()`'s sign is the inverse of the ISO-8601 sign). */
|
|
28
|
+
export declare function localOffset(date: Date): string;
|
|
29
|
+
/** The local calendar day of `date` — `YYYY-MM-DD`. */
|
|
30
|
+
export declare function writePlainDate(date: Date): string;
|
|
31
|
+
/** The local wall clock of `date` without an offset — `YYYY-MM-DDTHH:mm:ss`, or `YYYY-MM-DDTHH:mm`
|
|
32
|
+
* when `seconds` is `false`. */
|
|
33
|
+
export declare function writePlainDateTime(date: Date, seconds?: boolean): string;
|
|
34
|
+
/** The moment `date` names, written as this browser's wall clock with its offset —
|
|
35
|
+
* `YYYY-MM-DDTHH:mm:ss±HH:mm`. `2026-09-06T22:22:34Z` read in Seoul writes `2026-09-07T07:22:34+09:00`. */
|
|
36
|
+
export declare function writeInstant(date: Date): string;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/utilities/dateValue.ts
|
|
2
|
+
var PLAIN_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
|
+
var DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|[+-]\d{2}:?\d{2})?$/i;
|
|
4
|
+
/** Whether the fields name a real calendar day and clock time — `Date` rolls `2026-02-30` into March and
|
|
5
|
+
* `24:00` into the next day; the check runs in UTC so no time zone moves a field. */
|
|
6
|
+
function realFields(y, m, d, h = 0, min = 0, s = 0) {
|
|
7
|
+
const u = new Date(Date.UTC(y, m - 1, d, h, min, s));
|
|
8
|
+
return u.getUTCFullYear() === y && u.getUTCMonth() === m - 1 && u.getUTCDate() === d && u.getUTCHours() === h && u.getUTCMinutes() === min && u.getUTCSeconds() === s;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reads a date value and tells which kind it is. `null` for text that is not one of the three
|
|
12
|
+
* kinds, for a day or time that does not exist, and for an invalid `Date`.
|
|
13
|
+
*/
|
|
14
|
+
function readDateValue(value) {
|
|
15
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : {
|
|
16
|
+
kind: "instant",
|
|
17
|
+
date: value
|
|
18
|
+
};
|
|
19
|
+
const text = value.trim();
|
|
20
|
+
const day = PLAIN_DATE.exec(text);
|
|
21
|
+
if (day) {
|
|
22
|
+
const [y, m, d] = [
|
|
23
|
+
Number(day[1]),
|
|
24
|
+
Number(day[2]),
|
|
25
|
+
Number(day[3])
|
|
26
|
+
];
|
|
27
|
+
return realFields(y, m, d) ? {
|
|
28
|
+
kind: "plainDate",
|
|
29
|
+
date: new Date(y, m - 1, d)
|
|
30
|
+
} : null;
|
|
31
|
+
}
|
|
32
|
+
const dt = DATE_TIME.exec(text);
|
|
33
|
+
if (!dt) return null;
|
|
34
|
+
const [y, m, d, h, min, s] = [
|
|
35
|
+
1,
|
|
36
|
+
2,
|
|
37
|
+
3,
|
|
38
|
+
4,
|
|
39
|
+
5,
|
|
40
|
+
6
|
|
41
|
+
].map((i) => Number(dt[i] ?? 0));
|
|
42
|
+
const ms = dt[7] ? Number(dt[7].slice(0, 3).padEnd(3, "0")) : 0;
|
|
43
|
+
if (!realFields(y, m, d, h, min, s)) return null;
|
|
44
|
+
const zone = dt[8];
|
|
45
|
+
if (!zone) return {
|
|
46
|
+
kind: "plainDateTime",
|
|
47
|
+
date: new Date(y, m - 1, d, h, min, s, ms)
|
|
48
|
+
};
|
|
49
|
+
const offset = zone.toUpperCase() === "Z" ? 0 : (zone[0] === "-" ? -1 : 1) * (Number(zone.slice(1, 3)) * 60 + Number(zone.slice(-2)));
|
|
50
|
+
return {
|
|
51
|
+
kind: "instant",
|
|
52
|
+
date: /* @__PURE__ */ new Date(Date.UTC(y, m - 1, d, h, min, s, ms) - offset * 6e4)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
56
|
+
/** `±HH:mm` for this browser's time zone at `date` — recomputed per date, so a DST change is honoured
|
|
57
|
+
* (`getTimezoneOffset()`'s sign is the inverse of the ISO-8601 sign). */
|
|
58
|
+
function localOffset(date) {
|
|
59
|
+
const minutes = -date.getTimezoneOffset();
|
|
60
|
+
const abs = Math.abs(minutes);
|
|
61
|
+
return `${minutes >= 0 ? "+" : "-"}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
|
|
62
|
+
}
|
|
63
|
+
/** The local calendar day of `date` — `YYYY-MM-DD`. */
|
|
64
|
+
function writePlainDate(date) {
|
|
65
|
+
return `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
66
|
+
}
|
|
67
|
+
/** The local wall clock of `date` without an offset — `YYYY-MM-DDTHH:mm:ss`, or `YYYY-MM-DDTHH:mm`
|
|
68
|
+
* when `seconds` is `false`. */
|
|
69
|
+
function writePlainDateTime(date, seconds = true) {
|
|
70
|
+
const time = `${pad(date.getHours())}:${pad(date.getMinutes())}${seconds ? `:${pad(date.getSeconds())}` : ""}`;
|
|
71
|
+
return `${writePlainDate(date)}T${time}`;
|
|
72
|
+
}
|
|
73
|
+
/** The moment `date` names, written as this browser's wall clock with its offset —
|
|
74
|
+
* `YYYY-MM-DDTHH:mm:ss±HH:mm`. `2026-09-06T22:22:34Z` read in Seoul writes `2026-09-07T07:22:34+09:00`. */
|
|
75
|
+
function writeInstant(date) {
|
|
76
|
+
return `${writePlainDateTime(date)}${localOffset(date)}`;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { localOffset, readDateValue, writeInstant, writePlainDate, writePlainDateTime };
|
package/dist/utilities/format.js
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
import { Locale } from "./Locale.js";
|
|
2
|
+
import { readDateValue } from "./dateValue.js";
|
|
2
3
|
//#region src/utilities/format.ts
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
9
|
-
* A full ISO datetime (e.g. `2026-02-24T09:00:00Z`) is unambiguous — it carries
|
|
10
|
-
* its own timezone — so the local-time-safe split isn't needed there; when the
|
|
11
|
-
* split doesn't yield three numbers, fall back to native parsing instead of
|
|
12
|
-
* producing an Invalid Date.
|
|
13
|
-
*/
|
|
14
|
-
function parseISODate(iso) {
|
|
15
|
-
const [y, m, d] = iso.split("-").map(Number);
|
|
16
|
-
return Number.isNaN(y) || Number.isNaN(m) || Number.isNaN(d) ? new Date(iso) : new Date(y, m - 1, d);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Resolves a Date or ISO date string to a Date object.
|
|
5
|
+
* Resolves a Date or date string to a Date — through {@link readDateValue}, so a `YYYY-MM-DD` day is local
|
|
6
|
+
* midnight (not UTC midnight, which is the previous day west of Greenwich), a date-time without an offset is
|
|
7
|
+
* local wall clock, and one with an offset is that instant. ISO-shaped text that names no real day
|
|
8
|
+
* (`2026-02-30`) is an invalid `Date` — not March 2. Other text goes to the platform parser, as it always did.
|
|
20
9
|
*/
|
|
21
10
|
function resolve(value) {
|
|
22
|
-
|
|
11
|
+
const read = readDateValue(value);
|
|
12
|
+
if (read) return read.date;
|
|
13
|
+
return typeof value === "string" && !/^\d{4}-\d{2}-\d{2}/.test(value.trim()) ? new Date(value) : /* @__PURE__ */ new Date(NaN);
|
|
23
14
|
}
|
|
24
15
|
/**
|
|
25
16
|
* Wraps `Intl.NumberFormat` with the active locale (`Locale.get()` if omitted).
|
|
@@ -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
|
@@ -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
|
|
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
|
|
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?):
|
|
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 |
|
|
@@ -52,9 +52,11 @@ formatDate('2026-03-14', { dateStyle: 'long' });
|
|
|
52
52
|
formatDate(order.createdAt, { dateStyle: 'short', timeStyle: 'short' });
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Accepts a `Date` or
|
|
56
|
-
not UTC** — `'2026-03-14'` is midnight where the user is, so a date
|
|
57
|
-
across time zones the way `new Date('2026-03-14')` does
|
|
55
|
+
Accepts a `Date` or a date string, read by [`readDateValue`](#date-values--readdatevalue-and-writers): a
|
|
56
|
+
`YYYY-MM-DD` day is **local midnight, not UTC** — `'2026-03-14'` is midnight where the user is, so a date
|
|
57
|
+
never shifts a day across time zones the way `new Date('2026-03-14')` does; a date-time without an offset is
|
|
58
|
+
local wall clock; one with an offset (`…Z`, `…+09:00`) is that instant. ISO-shaped text that names no real
|
|
59
|
+
day (`2026-02-30`) is treated as invalid rather than rolled into March; other text goes to the platform parser.
|
|
58
60
|
|
|
59
61
|
A value that cannot be resolved to a real date — a malformed string, or an already-invalid
|
|
60
62
|
`Date` — returns `String(value)` instead of throwing. `Intl.DateTimeFormat.format()` throws
|
|
@@ -65,6 +67,30 @@ That degrade is **deliberately not symmetric** with `formatCurrency`: a date arr
|
|
|
65
67
|
data (an API, a user, a stale cache), so a bad one is an expected runtime state; a currency
|
|
66
68
|
code is written at the call site, so a bad one is a bug worth surfacing.
|
|
67
69
|
|
|
70
|
+
## Date values — `readDateValue` and writers
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { readDateValue, writeInstant, writePlainDate, writePlainDateTime } from '@iyulab/components';
|
|
74
|
+
|
|
75
|
+
const read = readDateValue('2026-09-06T22:22:34Z');
|
|
76
|
+
// { kind: 'instant', date } — in Seoul, writeInstant(read.date) is '2026-09-07T07:22:34+09:00'
|
|
77
|
+
if (read?.kind === 'plainDate') console.log(writePlainDate(read.date));
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
An app receives dates as text of three kinds, named after Temporal:
|
|
81
|
+
|
|
82
|
+
| kind | text | means here |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `instant` | a date-time with `Z` or an offset (`…+09:00`, `…-0500`) | that moment; shown as this browser's wall clock |
|
|
85
|
+
| `plainDateTime` | a date-time without an offset (`2026-09-06T22:22`, `2026-09-06 22:22:34`) | that wall clock, local |
|
|
86
|
+
| `plainDate` | a day (`2026-09-06`) | local midnight of that day |
|
|
87
|
+
|
|
88
|
+
`readDateValue(value)` returns `{ kind, date }`, or `null` for text that is none of the three or names a day or
|
|
89
|
+
time that does not exist. A `Date` reads as an `instant`. Write back in the kind you read so the value keeps its
|
|
90
|
+
meaning: `writeInstant(date)` (local offset, same moment), `writePlainDateTime(date, seconds?)`,
|
|
91
|
+
`writePlainDate(date)`. `localOffset(date)` gives the `±HH:mm` of that date (daylight saving is per date).
|
|
92
|
+
`formatDate` and the date pickers read through the same function.
|
|
93
|
+
|
|
68
94
|
## Locale
|
|
69
95
|
|
|
70
96
|
All three read `Locale.get()` when `locale` is omitted, so they follow whatever
|
|
@@ -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
|