@iyulab/components 2.20.1 → 2.20.2

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.20.2] - 2026-10-12
4
+
5
+ ### Fixed
6
+
7
+ - The React wrapper types name every event's `detail` type with an import. `onPageChange` on the `UPagination`
8
+ wrapper used `PageChangeDetail` without importing it: under `skipLibCheck` the handler's event was silently
9
+ `any`, otherwise the declaration failed with `TS2304`. The wrapper generator (`plugins/vite-plugin-react-wrapper`)
10
+ now imports a detail type declared in the element's own module, and one imported from another package by its
11
+ package specifier.
12
+ - The wrapper generator types an `@event`-only event from the package's event map declarations — an element-scoped
13
+ `*EventMap`, then the `HTMLElementEventMap` / `GlobalEventHandlersEventMap` augmentations — when the event's
14
+ `detail` is `CustomEvent<T>` (or an alias of it) with `T` importable. Events dispatched by a controller rather than
15
+ `this.fire<T>()` were typed as a bare `CustomEvent`. Native-named events (`change`, `input`) are unchanged.
16
+
3
17
  ## [2.20.1] - 2026-10-12
4
18
 
5
19
  ### Fixed
@@ -14,6 +14,17 @@ interface ComponentEvent {
14
14
  * 절대화해 이 어긋남을 원천 차단한다.
15
15
  */
16
16
  detailSource: string;
17
+ /**
18
+ * detail 타입을 **다른 패키지**에서 가져올 때의 지정자(예: `@iyulab/components/dist/events/RemoveEvent.js`).
19
+ * 그 경우 `detailSource` 는 비고, d.ts 는 이 지정자 그대로 import 한다 — 비워 두면 래퍼 d.ts 가
20
+ * import 없이 이름만 써서 소비자 쪽에서 풀리지 않는다(`TS2304`).
21
+ */
22
+ detailSpecifier?: string;
23
+ }
24
+ /** detail 타입을 어디서 가져오는가 — 같은 패키지 소스(절대 경로) 또는 다른 패키지(지정자). */
25
+ interface DetailOrigin {
26
+ detailSource: string;
27
+ detailSpecifier?: string;
17
28
  }
18
29
  interface PluginOptions {
19
30
  /** 컴포넌트 소스 디렉토리 경로 (기본값: 'src/components') */
@@ -72,4 +83,19 @@ export declare function findEventDeclarationViolations(content: string, classNam
72
83
  * ⑵leaf 가 같은 이벤트를 더 구체적 타입으로 발화하면 그것이 이긴다.
73
84
  */
74
85
  export declare function collectComponentEvents(filePath: string): ComponentEvent[];
86
+ type EventEntry = {
87
+ detailType: string;
88
+ } & DetailOrigin;
89
+ /** 이벤트 맵 인터페이스의 `'name': Type;` 항목들 — `map` 은 맵 이름(예: `HTMLElementEventMap`). */
90
+ export declare function readEventMapEntries(content: string): {
91
+ map: string;
92
+ name: string;
93
+ type: string;
94
+ }[];
95
+ /**
96
+ * 이벤트 타입 글자에서 detail 타입과 그 출처를 푼다 — `CustomEvent<X>` 이거나, 같은 파일의
97
+ * `type A = CustomEvent<X>` 별칭 `A`. `X` 는 그 파일이 선언했거나 import 한 이름 하나, 또는 다른 이름을
98
+ * 참조하지 않는 인라인 타입(`{ query: string }`). 못 풀면 null — 추측해서 거짓 타입을 내지 않는다.
99
+ */
100
+ export declare function detailFromEventType(type: string, file: string, content: string): EventEntry | null;
75
101
  export {};
@@ -131,12 +131,26 @@ export function findEventDeclarationViolations(content, className, tagName, even
131
131
  */
132
132
  export function collectComponentEvents(filePath) {
133
133
  const eventMap = new Map();
134
- collectInto(eventMap, filePath, new Set());
135
- return Array.from(eventMap, ([name, { detailType, detailSource }]) => ({
134
+ const chain = new Set();
135
+ collectInto(eventMap, filePath, chain);
136
+ // `@event` 만 있고 detail 타입을 모르는 이벤트는 **이벤트 맵 선언**에서 찾는다 — 요소 범위 맵
137
+ // (`UInputEventMap` 처럼 상속 체인 파일의 `*EventMap`)이 먼저, 패키지 전역 증강
138
+ // (`HTMLElementEventMap`·`GlobalEventHandlersEventMap`)이 다음. 타입은 그 선언 한 곳이 정본이다 —
139
+ // 컨트롤러가 대신 발화하는 이벤트(`this.fire` 가 없다)도 여기서 타입을 얻는다.
140
+ const srcRoot = packageSrcRoot(filePath);
141
+ for (const [name, entry] of eventMap) {
142
+ if (entry.detailType !== 'unknown')
143
+ continue;
144
+ const found = lookupEventMaps(name, [...chain], srcRoot);
145
+ if (found)
146
+ eventMap.set(name, found);
147
+ }
148
+ return Array.from(eventMap, ([name, { detailType, detailSource, detailSpecifier }]) => ({
136
149
  name,
137
150
  reactName: toCamelEvent(name),
138
151
  detailType,
139
152
  detailSource,
153
+ ...(detailSpecifier ? { detailSpecifier } : {}),
140
154
  }));
141
155
  }
142
156
  function collectInto(eventMap, filePath, visited) {
@@ -146,15 +160,7 @@ function collectInto(eventMap, filePath, visited) {
146
160
  const content = readFileSync(filePath, 'utf-8');
147
161
  // import 구문에서 식별자 → 소스 경로 매핑 수집 (detail 타입과 베이스 클래스 양쪽에 쓴다)
148
162
  // 예: import { ShowEventDetail } from '../events/ShowEvent.js';
149
- const importMap = new Map();
150
- for (const m of content.matchAll(/import\s+\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g)) {
151
- const importPath = m[2];
152
- for (const name of m[1].split(',')) {
153
- const typeName = name.replace(/type\s+/, '').trim();
154
- if (typeName)
155
- importMap.set(typeName, importPath);
156
- }
157
- }
163
+ const importMap = readImportMap(content);
158
164
  // 베이스 클래스를 먼저 수집한다 (제네릭 베이스 `extends UFormControlElement<T>` 포함)
159
165
  const extendsMatch = content.match(/export\s+(?:abstract\s+)?class\s+\w+(?:<[^>]*>)?\s+extends\s+(\w+)/);
160
166
  if (extendsMatch) {
@@ -170,10 +176,142 @@ function collectInto(eventMap, filePath, visited) {
170
176
  // this.fire<DetailType>('eventName') 패턴 - 제네릭 타입 추출
171
177
  for (const m of content.matchAll(/this\.fire\s*(?:<([^>]+)>)?\s*\(\s*['"]([\w-]+)['"]/g)) {
172
178
  const detailType = m[1] || 'unknown';
173
- const detailSource = resolveLocalModule(filePath, importMap.get(detailType)) || '';
174
- eventMap.set(m[2], { detailType, detailSource });
179
+ eventMap.set(m[2], { detailType, ...detailOrigin(detailType, filePath, content, importMap) });
175
180
  }
176
181
  }
182
+ /** 이 파일이 그 이름을 export 선언하는가. */
183
+ function declaresExport(content, name) {
184
+ return new RegExp(`export\\s+(?:interface|type|class|enum)\\s+${name}\\b`).test(content);
185
+ }
186
+ /**
187
+ * detail 타입 이름의 출처 — 이 파일이 import 했으면 그 import 를, 이 파일이 스스로 export 선언했으면 이 파일을.
188
+ * ⚠뒤쪽이 빠져 있었다: `UPagination` 의 `PageChangeDetail` 처럼 요소 파일이 선언한 detail 은 출처가 비어
189
+ * 래퍼 d.ts 가 import 없이 이름만 썼다(`skipLibCheck` 소비자에게는 조용한 `any`, 아니면 `TS2304`).
190
+ */
191
+ function detailOrigin(name, file, content, importMap) {
192
+ const imported = importMap.get(name);
193
+ if (imported)
194
+ return resolveDetailOrigin(file, imported);
195
+ return declaresExport(content, name) ? { detailSource: file } : { detailSource: '' };
196
+ }
197
+ function readImportMap(content) {
198
+ const importMap = new Map();
199
+ for (const m of content.matchAll(/import\s+(?:type\s+)?\{([^}]+)\}\s+from\s+['"]([^'"]+)['"]/g)) {
200
+ for (const name of m[1].split(',')) {
201
+ const typeName = name.replace(/type\s+/, '').trim();
202
+ if (typeName)
203
+ importMap.set(typeName, m[2]);
204
+ }
205
+ }
206
+ return importMap;
207
+ }
208
+ /** 상대 import 는 같은 패키지 소스(절대 경로)로, 패키지 지정자는 그대로 — 둘 다 아니면 출처 없음. */
209
+ function resolveDetailOrigin(fromFile, importPath) {
210
+ if (importPath && !importPath.startsWith('.'))
211
+ return { detailSource: '', detailSpecifier: importPath };
212
+ return { detailSource: resolveLocalModule(fromFile, importPath) || '' };
213
+ }
214
+ /** 소스 파일이 속한 패키지의 `src` 디렉터리(없으면 그 파일의 디렉터리). */
215
+ function packageSrcRoot(filePath) {
216
+ const norm = filePath.split(sep).join('/');
217
+ const i = norm.lastIndexOf('/src/');
218
+ return i >= 0 ? norm.slice(0, i + 4) : dirname(filePath);
219
+ }
220
+ /** 이벤트 맵 인터페이스의 `'name': Type;` 항목들 — `map` 은 맵 이름(예: `HTMLElementEventMap`). */
221
+ export function readEventMapEntries(content) {
222
+ const out = [];
223
+ for (const m of content.matchAll(/interface\s+(\w*EventMap)\s*\{/g)) {
224
+ // 짝 맞는 닫는 중괄호까지 — 항목 타입 안의 `{ query: string }` 를 건너뛴다.
225
+ let depth = 1;
226
+ let i = m.index + m[0].length;
227
+ const start = i;
228
+ for (; i < content.length && depth > 0; i++) {
229
+ if (content[i] === '{')
230
+ depth++;
231
+ else if (content[i] === '}')
232
+ depth--;
233
+ }
234
+ const body = content.slice(start, i - 1).replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
235
+ // 항목 = 맨 바깥 깊이의 `이름: 타입;` — 인라인 객체 타입 안의 `query: string;` 을 항목으로 읽지 않는다.
236
+ let depthB = 0;
237
+ let from = 0;
238
+ for (let j = 0; j < body.length; j++) {
239
+ const c = body[j];
240
+ if (c === '{' || c === '<' || c === '(')
241
+ depthB++;
242
+ else if (c === '}' || c === '>' || c === ')')
243
+ depthB--;
244
+ else if (c === ';' && depthB === 0) {
245
+ const e = body.slice(from, j).match(/^\s*['"]?([\w-]+)['"]?\s*:\s*([\s\S]+)$/);
246
+ if (e)
247
+ out.push({ map: m[1], name: e[1], type: e[2].trim() });
248
+ from = j + 1;
249
+ }
250
+ }
251
+ }
252
+ return out;
253
+ }
254
+ const GLOBAL_EVENT_MAPS = new Set(['HTMLElementEventMap', 'GlobalEventHandlersEventMap']);
255
+ const globalMapCache = new Map();
256
+ function globalEventMapEntries(srcRoot) {
257
+ let entries = globalMapCache.get(srcRoot);
258
+ if (!entries) {
259
+ entries = [];
260
+ for (const file of globSync('**/*.ts', { cwd: srcRoot, absolute: true, ignore: ['**/*.test.ts', '**/*.d.ts'] })) {
261
+ const content = readFileSync(file, 'utf-8');
262
+ if (!content.includes('EventMap'))
263
+ continue;
264
+ for (const e of readEventMapEntries(content)) {
265
+ if (GLOBAL_EVENT_MAPS.has(e.map))
266
+ entries.push({ name: e.name, type: e.type, file });
267
+ }
268
+ }
269
+ globalMapCache.set(srcRoot, entries);
270
+ }
271
+ return entries;
272
+ }
273
+ function lookupEventMaps(name, chainFiles, srcRoot) {
274
+ // 요소 범위 맵 — 상속 체인 파일 안의 `*EventMap`. leaf 부터(가장 구체적인 선언이 이긴다).
275
+ for (const file of [...chainFiles].reverse()) {
276
+ const content = readFileSync(file, 'utf-8');
277
+ const hit = readEventMapEntries(content).find(e => e.name === name && !GLOBAL_EVENT_MAPS.has(e.map));
278
+ const resolved = hit && detailFromEventType(hit.type, file, content);
279
+ if (resolved)
280
+ return resolved;
281
+ }
282
+ for (const hit of globalEventMapEntries(srcRoot).filter(e => e.name === name)) {
283
+ const resolved = detailFromEventType(hit.type, hit.file, readFileSync(hit.file, 'utf-8'));
284
+ if (resolved)
285
+ return resolved;
286
+ }
287
+ return null;
288
+ }
289
+ const INLINE_PRIMITIVES = new Set(['string', 'number', 'boolean', 'null', 'undefined', 'unknown', 'true', 'false', 'readonly']);
290
+ /**
291
+ * 이벤트 타입 글자에서 detail 타입과 그 출처를 푼다 — `CustomEvent<X>` 이거나, 같은 파일의
292
+ * `type A = CustomEvent<X>` 별칭 `A`. `X` 는 그 파일이 선언했거나 import 한 이름 하나, 또는 다른 이름을
293
+ * 참조하지 않는 인라인 타입(`{ query: string }`). 못 풀면 null — 추측해서 거짓 타입을 내지 않는다.
294
+ */
295
+ export function detailFromEventType(type, file, content) {
296
+ const alias = type.match(/^(\w+)$/);
297
+ if (alias) {
298
+ const def = content.match(new RegExp(`type\\s+${alias[1]}\\s*=\\s*([^;]+);`));
299
+ return def ? detailFromEventType(def[1].trim(), file, content) : null;
300
+ }
301
+ const custom = type.match(/^CustomEvent<([\s\S]+)>$/);
302
+ if (!custom)
303
+ return null;
304
+ const detail = custom[1].trim();
305
+ if (/^\w+$/.test(detail)) {
306
+ const origin = detailOrigin(detail, file, content, readImportMap(content));
307
+ return origin.detailSource || origin.detailSpecifier ? { detailType: detail, ...origin } : null;
308
+ }
309
+ // 인라인 타입 — 속성 이름과 원시 타입만 쓸 때(다른 이름을 참조하면 import 할 길이 없다).
310
+ const keys = new Set([...detail.matchAll(/(\w+)\??\s*:/g)].map(k => k[1]));
311
+ const idents = (detail.replace(/(['"])(?:(?!\1).)*\1/g, '').match(/[A-Za-z_]\w*/g) ?? [])
312
+ .filter(id => !INLINE_PRIMITIVES.has(id) && !keys.has(id));
313
+ return idents.length === 0 ? { detailType: detail, detailSource: '' } : null;
314
+ }
177
315
  /** 같은 패키지 소스 안의 상대 import 를 절대 `.ts` 경로로 해석한다 (외부 모듈이면 null) */
178
316
  function resolveLocalModule(fromFile, importPath) {
179
317
  if (!importPath || !importPath.startsWith('.'))
@@ -252,8 +390,18 @@ export const ${className} = createComponent({
252
390
  // leaf 기준으로 잘못 풀리는 것을 막기 위함 — ComponentEvent.detailSource 주석 참조).
253
391
  const detailImportMap = new Map(); // 빌드경로 → [타입명]
254
392
  for (const e of events) {
255
- if (e.detailType === 'unknown' || !e.detailSource)
393
+ if (e.detailType === 'unknown')
256
394
  continue;
395
+ // 다른 패키지의 detail 타입은 그 지정자 그대로 — 이미 «패키지 스펙»이다.
396
+ if (e.detailSpecifier) {
397
+ const types = detailImportMap.get(e.detailSpecifier) || [];
398
+ if (!types.includes(e.detailType))
399
+ types.push(e.detailType);
400
+ detailImportMap.set(e.detailSpecifier, types);
401
+ continue;
402
+ }
403
+ if (!e.detailSource)
404
+ continue; // 인라인 타입(`{ query: string }`) — import 할 것이 없다
257
405
  const absEventSrc = e.detailSource.replace(/\\/g, '/');
258
406
  const eventSrcIndex = absEventSrc.indexOf('/src/');
259
407
  const relFromSrc = eventSrcIndex >= 0
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { UPagination as UPaginationElement } from '@iyulab/components/dist/components/pagination/UPagination.js';
3
+ import { type PageChangeDetail } from '@iyulab/components/dist/components/pagination/UPagination.js';
3
4
 
4
5
  type UPaginationOwnProps = Omit<UPaginationElement, keyof HTMLElement>;
5
6
 
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.20.1",
4
+ "version": "2.20.2",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",