nfx-ui 0.6.3 → 0.7.1

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.
@@ -1,413 +1 @@
1
- import { ButtonHTMLAttributes } from 'react';
2
- import { ForwardRefExoticComponent } from 'react';
3
- import { InputHTMLAttributes } from 'react';
4
- import { JSX } from 'react/jsx-runtime';
5
- import * as LucideIcons from '@/icons/lucide';
6
- import { LucideProps } from 'lucide-react';
7
- import { MemoExoticComponent } from 'react';
8
- import { NamedExoticComponent } from 'react';
9
- import { QueryErrorResetBoundaryProps } from '@tanstack/react-query';
10
- import { ReactNode } from 'react';
11
- import { RefAttributes } from 'react';
12
- import { SuspenseProps as SuspenseProps_2 } from 'react';
13
- import { TextareaHTMLAttributes } from 'react';
14
- import { VirtualizerOptions } from '@tanstack/react-virtual';
15
-
16
- export declare const Button: ForwardRefExoticComponent<ButtonProps & RefAttributes<HTMLButtonElement>>;
17
-
18
- export declare interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "size"> {
19
- variant?: "primary" | "secondary" | "outline" | "ghost" | "danger";
20
- size?: "small" | "medium" | "large";
21
- fullWidth?: boolean;
22
- leftIcon?: ReactNode;
23
- rightIcon?: ReactNode;
24
- /** 上方图标。Top icon. */
25
- topIcon?: ReactNode;
26
- /** 下方图标。Bottom icon. */
27
- bottomIcon?: ReactNode;
28
- /** 仅图标无文案。Icon only, no text. */
29
- iconOnly?: boolean;
30
- /** 图标尺寸覆盖。Override icon size. */
31
- iconSize?: number;
32
- loading?: boolean;
33
- children?: ReactNode;
34
- }
35
-
36
- export declare const Dropdown: NamedExoticComponent<DropdownProps>;
37
-
38
- export declare interface DropdownOption {
39
- /** 选项值。Option value. */
40
- value: string;
41
- /** 选项展示文案。Option label. */
42
- label: string;
43
- }
44
-
45
- export declare interface DropdownProps {
46
- /** 选项列表。Options list. */
47
- options: DropdownOption[];
48
- /** 当前选中值。Current value. */
49
- value: string;
50
- /** 选中回调。Change callback. */
51
- onChange: (value: string) => void;
52
- /** 占位符。Placeholder. */
53
- placeholder?: string;
54
- /** 是否禁用。Disabled. */
55
- disabled?: boolean;
56
- /** 是否错误态。Error state. */
57
- error?: boolean;
58
- /** 容器 className。Container className. */
59
- className?: string;
60
- }
61
-
62
- export declare const Icon: MemoExoticComponent<({ name, ...props }: IconProps) => JSX.Element | null>;
63
-
64
- export declare type IconName = keyof Omit<typeof LucideIcons, "LucideIcon">;
65
-
66
- export declare interface IconProps extends LucideProps {
67
- /** 图标名(lucide 注册名)。Icon name (lucide registered name). */
68
- name: IconName;
69
- }
70
-
71
- export declare const Input: ForwardRefExoticComponent<InputProps & RefAttributes<HTMLInputElement>>;
72
-
73
- export declare interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
74
- /** 标签文案。Label text. */
75
- label?: string;
76
- /** 错误信息。Error message. */
77
- error?: string;
78
- /** 辅助说明。Helper text. */
79
- helperText?: string;
80
- /** 左侧图标。Left icon. */
81
- leftIcon?: ReactNode;
82
- /** 右侧图标。Right icon. */
83
- rightIcon?: ReactNode;
84
- /** 为 true 时 rightIcon 可点击(如密码切换、清除按钮)。When true, right icon is clickable (e.g. password toggle, clear). */
85
- rightIconInteractive?: boolean;
86
- /** 尺寸。Size. */
87
- size?: "small" | "medium" | "large";
88
- /** 视觉变体。Variant. */
89
- variant?: "default" | "filled";
90
- /** 是否占满宽度。Full width. */
91
- fullWidth?: boolean;
92
- }
93
-
94
- export declare const KeyValueEditor: MemoExoticComponent<({ label, pairs, onChange, valueType, keyPlaceholder, valuePlaceholder, valueArrayPlaceholder, removeAriaLabel, addLabel, error, }: KeyValueEditorProps) => JSX.Element>;
95
-
96
- export declare interface KeyValueEditorProps {
97
- /** 表单项标签。Field label. */
98
- label: string;
99
- /** 键值对列表。Key-value pairs. */
100
- pairs: KeyValuePair[];
101
- /** 列表变化回调。Change callback. */
102
- onChange: (pairs: KeyValuePair[]) => void;
103
- /** 值类型:string 或 array。Value type: string or array. */
104
- valueType?: "string" | "array";
105
- /** 键占位符。Key placeholder. */
106
- keyPlaceholder?: string;
107
- /** 值占位符(string 模式)。Value placeholder (string mode). */
108
- valuePlaceholder?: string;
109
- /** 值占位符(array 模式)。Value placeholder (array mode). */
110
- valueArrayPlaceholder?: string;
111
- /** 删除按钮 aria-label。Remove button aria-label. */
112
- removeAriaLabel?: string;
113
- /** 新增按钮文案。Add button label. */
114
- addLabel?: string;
115
- /** 错误信息。Error message. */
116
- error?: string;
117
- }
118
-
119
- export declare interface KeyValuePair {
120
- /** 键。Key. */
121
- key: string;
122
- /** 值(字符串或字符串数组)。Value (string or string[]). */
123
- value: string | string[];
124
- }
125
-
126
- /**
127
- * 布局模式枚举与常量。Layout mode enum and constants.
128
- */
129
- declare enum LayoutModeEnum {
130
- SHOW = "show",
131
- HIDE = "hide"
132
- }
133
-
134
- export declare const LayoutSwitcher: MemoExoticComponent<({ status, getLayoutDisplayName, handleChangeLayoutMode }: LayoutSwitcherProps) => JSX.Element>;
135
-
136
- /** 布局切换器 props。LayoutSwitcher props. */
137
- export declare interface LayoutSwitcherProps {
138
- /** 样式状态。Visual status. */
139
- status?: "primary" | "default";
140
- /** 显示模式标签(未传 getLayoutDisplayName 且无内置翻译时使用)。Show mode label. */
141
- showLabel?: string;
142
- /** 隐藏模式标签(未传 getLayoutDisplayName 且无内置翻译时使用)。Hide mode label. */
143
- hideLabel?: string;
144
- /** 根据布局模式返回展示名;未传则使用 showLabel / hideLabel。Display name for layout mode; default uses showLabel/hideLabel. */
145
- getLayoutDisplayName?: (mode: LayoutModeEnum) => string;
146
- /** 处理布局模式改变。Handle layout mode change. */
147
- handleChangeLayoutMode?: (mode: LayoutModeEnum) => void;
148
- }
149
-
150
- export declare const SearchInput: MemoExoticComponent<({ value, onChange, placeholder, clearButtonAriaLabel }: SearchInputProps) => JSX.Element>;
151
-
152
- export declare interface SearchInputProps {
153
- /** 当前输入值。Current value. */
154
- value: string;
155
- /** 值变化回调。Change callback. */
156
- onChange: (value: string) => void;
157
- /** 占位符,由调用方传入。Placeholder; pass from caller. */
158
- placeholder?: string;
159
- /** 清除按钮 aria-label;由调用方传入(可来自 i18n)。Clear button aria-label; pass from caller. */
160
- clearButtonAriaLabel?: string;
161
- }
162
-
163
- export declare const ShowFilter: MemoExoticComponent<({ value, onChange, filterEnabled, filterDisabled, enableFilterAriaLabel, disableFilterAriaLabel, all, show, hide, }: ShowFilterProps) => JSX.Element>;
164
-
165
- export declare interface ShowFilterProps {
166
- /** 当前值。Current value. */
167
- value: ShowFilterValue;
168
- /** 值变化回调。Change callback. */
169
- onChange: (value: ShowFilterValue) => void;
170
- /** 筛选开启时的按钮文案。Label when filter enabled. */
171
- filterEnabled?: string;
172
- /** 筛选关闭时的按钮文案。Label when filter disabled. */
173
- filterDisabled?: string;
174
- /** 开启筛选按钮的 aria-label。Aria-label for enable filter button. */
175
- enableFilterAriaLabel?: string;
176
- /** 关闭筛选按钮的 aria-label。Aria-label for disable filter button. */
177
- disableFilterAriaLabel?: string;
178
- /** 「全部」选项文案。Label for "all" option. */
179
- all?: string;
180
- /** 「显示」选项文案。Label for "show" option. */
181
- show?: string;
182
- /** 「隐藏」选项文案。Label for "hide" option. */
183
- hide?: string;
184
- }
185
-
186
- export declare interface ShowFilterValue {
187
- /** 筛选是否启用。Whether filter is enabled. */
188
- enabled: boolean;
189
- /** 显示/隐藏:null=全部,true=显示,false=隐藏。Show/hide: null=all, true=show, false=hide. */
190
- value: boolean | null;
191
- }
192
-
193
- export declare const SlideDownSwitcher: typeof SlideDownSwitcherInner & {
194
- displayName?: string;
195
- };
196
-
197
- declare const SlideDownSwitcherInner: <T extends string>({ value, options, getDisplayName, onChange, status }: SlideDownSwitcherProps<T>) => JSX.Element;
198
-
199
- export declare interface SlideDownSwitcherProps<T extends string> {
200
- /** 当前选中的值(enum 或 string) */
201
- value: T;
202
- /** 可选项列表(如 Object.values(SomeEnum)) */
203
- options: readonly T[];
204
- /** 选项展示文案 */
205
- getDisplayName: (value: T) => string;
206
- /** 选中后回调 */
207
- onChange: (value: T) => void;
208
- status?: "primary" | "default";
209
- }
210
-
211
- export declare const Slider: NamedExoticComponent<SliderProps & RefAttributes<HTMLDivElement>>;
212
-
213
- export declare interface SliderProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
214
- /** 当前值。Current value. */
215
- value: number;
216
- /** 值变化回调。Change callback. */
217
- onChange: (value: number) => void;
218
- /** 最小值。Minimum. */
219
- min?: number;
220
- /** 最大值。Maximum. */
221
- max?: number;
222
- /** 步长。Step. */
223
- step?: number;
224
- /** 是否显示数值。Show value. */
225
- showValue?: boolean;
226
- /** 是否占满宽度。Full width. */
227
- fullWidth?: boolean;
228
- /** 标签文案。Label text. */
229
- label?: string;
230
- /** 错误信息。Error message. */
231
- error?: string;
232
- /** 辅助说明。Helper text. */
233
- helperText?: string;
234
- /** 是否必填。Required. */
235
- required?: boolean;
236
- }
237
-
238
- export declare const Suspense: MemoExoticComponent<({ fallback, test, loadingType, loadingShape, loadingClassName, loadingText, loadingSize, loadingContainerClassName, loadingTextClassName, children, errorFallback, errorTitle, errorDescription, retryText, errorDetailsText, clearLocalDataText, onClearLocalData, errorContainerClassName, errorDetailsClassName, showErrorDetails, ...restProps }: SuspenseProps) => JSX.Element>;
239
-
240
- export declare interface SuspenseProps extends Omit<SuspenseProps_2, "fallback">, Omit<QueryErrorResetBoundaryProps, "children"> {
241
- /** 自定义 fallback。Custom fallback. */
242
- fallback?: ReactNode;
243
- /** 测试用:始终挂起。Test: always suspend. */
244
- test?: boolean;
245
- /** 加载动画类型。Loading type. */
246
- loadingType?: "ecg" | "truck" | "bounce";
247
- /** 加载图形形状。Loading shape. */
248
- loadingShape?: "square" | "circle";
249
- /** 加载中文案,由调用方传入。Loading text; pass from caller (e.g. i18n). */
250
- loadingText?: string;
251
- /** 加载图尺寸。Loading size. */
252
- loadingSize?: "small" | "medium" | "large";
253
- /** 加载容器 className。Loading container className. */
254
- loadingContainerClassName?: string;
255
- /** 加载文案 className。Loading text className. */
256
- loadingTextClassName?: string;
257
- /** 加载图 className。Loading className. */
258
- loadingClassName?: string;
259
- /** 自定义错误 UI。Custom error fallback. */
260
- errorFallback?: (args: {
261
- error: Error | null;
262
- retry: () => void;
263
- }) => ReactNode;
264
- /** 错误标题,由调用方传入。Error title; pass from caller. */
265
- errorTitle?: string;
266
- /** 错误描述,由调用方传入。Error description; pass from caller. */
267
- errorDescription?: string;
268
- /** 重试按钮文案,由调用方传入。Retry text; pass from caller. */
269
- retryText?: string;
270
- /** 错误详情折叠文案。Error details text. */
271
- errorDetailsText?: string;
272
- /** 清除本地数据按钮文案。Clear local data text. */
273
- clearLocalDataText?: string;
274
- /** 点击「清除本地数据」后执行(如跳转登录页),由调用方传入。Called after clear local data (e.g. navigate to login); pass from caller. */
275
- onClearLocalData?: () => void;
276
- /** 错误容器 className。Error container className. */
277
- errorContainerClassName?: string;
278
- /** 错误详情 className。Error details className. */
279
- errorDetailsClassName?: string;
280
- /** 是否展示错误详情。Show error details. */
281
- showErrorDetails?: boolean;
282
- }
283
-
284
- export declare const Textarea: ForwardRefExoticComponent<TextareaProps & RefAttributes<HTMLTextAreaElement>>;
285
-
286
- export declare interface TextareaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "size"> {
287
- /** 标签文案。Label text. */
288
- label?: string;
289
- /** 错误信息。Error message. */
290
- error?: string;
291
- /** 辅助说明。Helper text. */
292
- helperText?: string;
293
- /** 左侧图标。Left icon. */
294
- leftIcon?: ReactNode;
295
- /** 右侧图标。Right icon. */
296
- rightIcon?: ReactNode;
297
- /** 尺寸。Size. */
298
- size?: "small" | "medium" | "large";
299
- /** 视觉变体。Variant. */
300
- variant?: "default" | "filled";
301
- /** 是否占满宽度。Full width. */
302
- fullWidth?: boolean;
303
- }
304
-
305
- /** 颜色主题枚举 */
306
- declare enum ThemeEnum {
307
- DEFAULT = "default",
308
- LIGHT = "light",
309
- CORPORATE = "corporate",
310
- FOREST = "forest",
311
- DARK = "dark",
312
- COSMIC = "cosmic",
313
- COFFEE = "coffee",
314
- WINE = "wine",
315
- /** 麦田:default 基础上白红色改为金黄色 */
316
- WHEAT = "wheat"
317
- }
318
-
319
- export declare const ThemeSwitcher: MemoExoticComponent<({ status, getThemeDisplayName, handleChangeTheme }: ThemeSwitcherProps) => JSX.Element>;
320
-
321
- /** 主题切换器 props。ThemeSwitcher props. */
322
- export declare interface ThemeSwitcherProps {
323
- /** 样式状态。Visual status. */
324
- status?: "primary" | "default";
325
- /** 根据 theme 返回显示名称;未传则使用 theme 原值。Display name for theme; default is theme value. */
326
- getThemeDisplayName?: (theme: ThemeEnum) => string;
327
- /** 处理主题改变。Handle theme change. */
328
- handleChangeTheme?: (theme: ThemeEnum) => void;
329
- }
330
-
331
- export declare const VirtualList: typeof VirtualListComponent;
332
-
333
- declare function VirtualListComponent<T>({ data, hasNextPage, isFetchingNextPage, fetchNextPage, renderItem, estimateSize, overscan, height, getItemKey, emptyState, loadingIndicator, endOfListIndicator, emptyText, loadingMoreText, endOfListText, flexClass, outerClass, innerClass, ...virtualizerOptions }: VirtualListProps<T>): JSX.Element;
334
-
335
- export declare interface VirtualListProps<T> extends Partial<Omit<VirtualizerOptions<HTMLDivElement, Element>, "count" | "getScrollElement" | "observeElementRect" | "observeElementOffset" | "scrollToFn" | "getItemKey" | "estimateSize">> {
336
- /** 数据列表。Data array. */
337
- data: T[];
338
- /** 是否有下一页。Has next page. */
339
- hasNextPage?: boolean;
340
- /** 是否正在拉取下一页。Is fetching next page. */
341
- isFetchingNextPage?: boolean;
342
- /** 拉取下一页。Fetch next page. */
343
- fetchNextPage?: () => void;
344
- /** 单项渲染。Render item. */
345
- renderItem: (item: T, index: number) => ReactNode;
346
- /** 单项高度估计。Estimate item size. */
347
- estimateSize?: number | ((index: number) => number);
348
- /** 列表高度。List height. */
349
- height?: string | number;
350
- /** 单项 key。Get item key. */
351
- getItemKey: (item: T, index: number) => string | number;
352
- /** 空状态自定义节点。Empty state node. */
353
- emptyState?: ReactNode;
354
- /** 加载更多指示器。Loading indicator node. */
355
- loadingIndicator?: ReactNode;
356
- /** 列表底指示器。End of list indicator node. */
357
- endOfListIndicator?: ReactNode;
358
- /** 当未提供 emptyState 时使用的文案,由调用方传入。Text when no data; used when emptyState not provided. */
359
- emptyText?: string;
360
- /** 当未提供 loadingIndicator 时使用的文案。Text when loading more. */
361
- loadingMoreText?: string;
362
- /** 当未提供 endOfListIndicator 时使用的文案。Text at end of list. */
363
- endOfListText?: string;
364
- /** 列表项容器 className。Flex container class. */
365
- flexClass?: string;
366
- /** 外层容器 className。Outer class. */
367
- outerClass?: string;
368
- /** 内层容器 className。Inner class. */
369
- innerClass?: string;
370
- }
371
-
372
- export declare const VirtualWindowList: typeof VirtualWindowListComponent;
373
-
374
- declare function VirtualWindowListComponent<T>({ data, hasNextPage, isFetchingNextPage, fetchNextPage, renderItem, estimateSize, overscan, height, getItemKey, emptyState, loadingIndicator, endOfListIndicator, emptyText, loadingMoreText, endOfListText, flexClass, outerClass, innerClass, ...virtualizerOptions }: VirtualWindowListProps<T>): JSX.Element;
375
-
376
- export declare interface VirtualWindowListProps<T> extends Partial<Omit<VirtualizerOptions<Window, Element>, "count" | "getScrollElement" | "observeElementRect" | "observeElementOffset" | "scrollToFn" | "estimateSize" | "getItemKey">> {
377
- /** 数据列表。Data array. */
378
- data: T[];
379
- /** 是否有下一页。Has next page. */
380
- hasNextPage?: boolean;
381
- /** 是否正在拉取下一页。Is fetching next page. */
382
- isFetchingNextPage?: boolean;
383
- /** 拉取下一页。Fetch next page. */
384
- fetchNextPage?: () => void;
385
- /** 单项渲染。Render item. */
386
- renderItem: (item: T, index: number) => ReactNode;
387
- /** 单项高度估计。Estimate item size. */
388
- estimateSize?: number | ((index: number) => number);
389
- /** 列表高度。List height. */
390
- height?: string | number;
391
- /** 单项 key。Get item key. */
392
- getItemKey: (item: T, index: number) => string | number;
393
- /** 空状态自定义节点。Empty state node. */
394
- emptyState?: ReactNode;
395
- /** 加载更多指示器。Loading indicator node. */
396
- loadingIndicator?: ReactNode;
397
- /** 列表底指示器。End of list indicator node. */
398
- endOfListIndicator?: ReactNode;
399
- /** 空状态文案(未提供 emptyState 时)。Empty text. */
400
- emptyText?: string;
401
- /** 加载更多文案。Loading more text. */
402
- loadingMoreText?: string;
403
- /** 列表底文案。End of list text. */
404
- endOfListText?: string;
405
- /** 列表项容器 className。Flex container class. */
406
- flexClass?: string;
407
- /** 外层容器 className。Outer class. */
408
- outerClass?: string;
409
- /** 内层容器 className。Inner class. */
410
- innerClass?: string;
411
- }
412
-
413
1
  export { }
@@ -1,130 +1 @@
1
- import { QueryKey } from '@tanstack/react-query';
2
-
3
- /** 单条 key 片段。Item key segment. */
4
- export declare const CACHE_ITEM = "item";
5
-
6
- /** 列表 key 片段。List key segment. */
7
- export declare const CACHE_LIST = "list";
8
-
9
- /**
10
- * 创建「单条」query key 工厂(可链式 .withPrefix):支持传入一个或多个 id,返回 [domain, CACHE_ITEM, subDomain, ...ids]
11
- * Creates an item query key factory (chainable .withPrefix): accepts one or more ids, returns [domain, CACHE_ITEM, subDomain, ...ids].
12
- *
13
- * @param domain - 域名。Domain name (e.g. "catalog", "auth").
14
- * @param subDomain - 子域。Sub-domain (e.g. "category", "product").
15
- * @returns 可调用的 key 工厂,带 withPrefix 可链式加前缀。Callable key factory with withPrefix for chaining.
16
- * @example
17
- * ```ts
18
- * const getKey = createItemKey("catalog", "category");
19
- * getKey("abc");
20
- * * => ["catalog", "item", "category", "abc"]
21
- * getKey.getPrefix
22
- * * => ["catalog", "item", "category"]
23
- * createItemKey("catalog", "category").withPrefix("api").withPrefix("v1").getPrefix;
24
- * * => ["v1", "api", "catalog", "item", "category"]
25
- * ```
26
- */
27
- export declare function createItemKey(domain: string, subDomain: string): ItemKeyChainable;
28
-
29
- /**
30
- * 创建自定义 query key(任意片段,用于 stats 等)
31
- * Creates a custom query key from arbitrary segments (e.g. for stats).
32
- *
33
- * @param segments - 任意片段(字符串或其它)。Arbitrary segments (strings or other).
34
- * @returns 由片段组成的 query key。Query key composed of the segments.
35
- * @example
36
- * ```ts
37
- * const key = createKey("catalog", "stats", "category", "count");
38
- * * key => ["catalog", "stats", "category", "count"]
39
- * ```
40
- */
41
- export declare function createKey(...segments: unknown[]): QueryKey;
42
-
43
- /**
44
- * 创建「列表」query key(可链式 .withPrefix):[domain, CACHE_LIST, subDomain]
45
- * Creates a list query key (chainable .withPrefix): [domain, CACHE_LIST, subDomain].
46
- *
47
- * @param domain - 域名。Domain name (e.g. "catalog", "auth").
48
- * @param subDomain - 子域。Sub-domain (e.g. "category", "product").
49
- * @returns 列表 query key(数组),带 withPrefix 可链式加前缀。List query key (array) with withPrefix for chaining.
50
- * @example
51
- * ```ts
52
- * const key = createListKey("catalog", "category");
53
- * * key => ["catalog", "list", "category"]
54
- * key.getPrefix
55
- * * => ["catalog", "list", "category"]
56
- * createListKey("catalog", "category").withPrefix("api").withPrefix("v1").getPrefix;
57
- * * => ["v1", "api", "catalog", "list", "category"]
58
- * ```
59
- */
60
- export declare function createListKey(domain: string, subDomain: string): ListKeyChainable;
61
-
62
- /**
63
- * 根据同一 domain + subDomain 生成 list key 与 item key 工厂
64
- * Returns both list key and item key factory for the given domain and subDomain.
65
- *
66
- * @param domain - 域名。Domain name (e.g. "catalog", "auth").
67
- * @param subDomain - 子域。Sub-domain (e.g. "category", "product").
68
- * @returns 含 list、item 及 withPrefix 的 bundle,可链式加前缀。Bundle with list, item, and chainable withPrefix.
69
- * @example
70
- * ```ts
71
- * const { list, item } = createQueryKeys("catalog", "category");
72
- * * list => ["catalog", "list", "category"]
73
- * * item("id-1") => ["catalog", "item", "category", "id-1"]
74
- * const withApi = createQueryKeys("catalog", "category").withPrefix("api");
75
- * * withApi.list => ["api", "catalog", "list", "category"]
76
- * * withApi.item("id-1") => ["api", "catalog", "item", "category", "id-1"]
77
- * ```
78
- */
79
- export declare function createQueryKeys(domain: string, subDomain: string): QueryKeysBundle;
80
-
81
- export declare type DefinedEnum<M extends EnumMetaMap> = {
82
- Values: readonly (keyof M)[];
83
- pickMap<P extends keyof M[keyof M]>(prop: P): {
84
- [K in keyof M]: M[K][P];
85
- };
86
- get<K extends keyof M>(key: K): M[K];
87
- };
88
-
89
- export declare function defineEnum<const M extends EnumMetaMap>(metaMap: M): DefinedEnum<M>;
90
-
91
- export declare type EnumInferMeta<E> = E extends DefinedEnum<infer M> ? M : never;
92
-
93
- export declare type EnumMetaMap = Record<string, Record<PropertyKey, unknown>>;
94
-
95
- export declare function enumPickMap<M extends EnumMetaMap, P extends keyof M[keyof M]>(e: DefinedEnum<M>, prop: P): {
96
- [K in keyof M]: M[K][P];
97
- };
98
-
99
- export declare type EnumValue<E extends {
100
- Values: readonly PropertyKey[];
101
- }> = E["Values"][number];
102
-
103
- /**
104
- * 链式单条 key 类型:可调用 (...ids) => QueryKey,且带 withPrefix、getPrefix。
105
- * Chainable item key type: callable (...ids) => QueryKey, with withPrefix() and getPrefix.
106
- */
107
- export declare type ItemKeyChainable = ((...ids: string[]) => QueryKey) & {
108
- withPrefix(...prefix: unknown[]): ItemKeyChainable;
109
- /** 不含 id 的前缀,用于 invalidation 等。Prefix without ids, e.g. for invalidation. */
110
- getPrefix: QueryKey;
111
- };
112
-
113
- /**
114
- * 链式列表 key 类型:本身即 QueryKey(数组),且带 withPrefix、getPrefix。
115
- * Chainable list key type: is a QueryKey (array) and has withPrefix(), getPrefix.
116
- */
117
- export declare type ListKeyChainable = QueryKey & {
118
- withPrefix(...prefix: unknown[]): ListKeyChainable;
119
- /** 列表 key 的前缀(即完整 list key,用于 invalidation 等)。Prefix (full list key) for invalidation. */
120
- getPrefix: QueryKey;
121
- };
122
-
123
- /** 含 list / item 且可链式 withPrefix 的 bundle 类型 */
124
- export declare type QueryKeysBundle = {
125
- list: ListKeyChainable;
126
- item: ItemKeyChainable;
127
- withPrefix(...prefix: unknown[]): QueryKeysBundle;
128
- };
129
-
130
1
  export { }
package/dist/events.d.ts CHANGED
@@ -1,61 +1 @@
1
- /**
2
- * 定义品牌类型:用于 defineXxx 的返回值,仅对应的 createXxx/构造函数可接受;Tag 区分不同定义(如 "events" | "router")。
3
- * Define brand type: for defineXxx return value, only the matching createXxx accepts; Tag discriminates (e.g. "events" | "router").
4
- * @example Defined<{ HOME: "/" }, "router"> 仅能传入 createRouter;Defined<{ FOO: "x" }, "events"> 仅能传入 EventEmitter
5
- */
6
- declare type Defined<T, Tag extends string> = T & {
7
- readonly __defineBrand?: Tag;
8
- };
9
-
10
- /** 由 defineEvents 返回的「已规范事件名对象」类型;constructor 只接受此类型。 */
11
- export declare type DefinedEvents<T extends Record<string, string>> = Defined<T, "events">;
12
-
13
- /**
14
- * 规范创建「一级 key-value」事件名对象:仅允许 key → 字符串 value,禁止嵌套(类型约束)。
15
- * 返回 DefinedEvents<T>,供 EventEmitter 构造使用。
16
- * Define events object: one-level key-value (string values), no nested objects (type-only). Returns DefinedEvents<T> for EventEmitter.
17
- *
18
- * @param events - 事件名 key-value 对象。Event name key-value object (e.g. { FOO: "DOMAIN:FOO" }).
19
- * @returns DefinedEvents<E>,仅此类型可传入 EventEmitter 构造。DefinedEvents<E>; only this type is accepted by EventEmitter constructor.
20
- * @example
21
- * ```ts
22
- * const routerEvents = defineEvents({ NAVIGATE: "ROUTER:NAVIGATE", NAVIGATE_BACK: "ROUTER:NAVIGATE_BACK" });
23
- * class RouterEmitter extends EventEmitter<EventNamesOf<typeof routerEvents>> { constructor() { super(routerEvents); } }
24
- * ```
25
- */
26
- export declare function defineEvents<E extends Record<string, string>>(events: E): DefinedEvents<E>;
27
-
28
- /** 回调类型:内部存储与 on/off 默认(unknown)时均用此,任意函数即可,无需 as 断言。 */
29
- export declare type EventCallback = (...args: any[]) => void;
30
-
31
- /**
32
- * 泛型 EventEmitter:构造函数仅接受 defineEvents 返回的 DefinedEvents 类型,提供 on / off / emit。
33
- * PayloadMap[K] 可为 void(无参)、单类型 T(单参)、或元组 [A, B, ...](多参),统一规范为参数列表。
34
- * PayloadMap[K] can be void (no args), single type T (one arg), or tuple [A, B, ...] (multi arg).
35
- *
36
- * @param events - 须为 defineEvents(...) 的返回值(DefinedEvents)。Must be the return value of defineEvents(...) (DefinedEvents).
37
- */
38
- export declare class EventEmitter<E extends string, PayloadMap extends Record<E, unknown> = Record<E, unknown>> {
39
- private listeners;
40
- constructor(events: DefinedEvents<Record<string, E>>);
41
- /** 注册事件监听;回调为任意函数,由 emit 时传入的参数决定实际类型。 */
42
- on<K extends E>(event: K, callback: EventCallback): void;
43
- /** 移除事件监听(需与 on 时同一引用)。 */
44
- off<K extends E>(event: K, callback: EventCallback): void;
45
- /**
46
- * 触发事件;参数与 PayloadMap[K] 一致:void 无参,T 单参,[A,B] 多参。
47
- * Emit an event; args match PayloadMap[K]: void → no args, T → one arg, [A,B] → spread.
48
- */
49
- emit<K extends E>(event: K, ...args: ToArgs<PayloadMap[K]>): void;
50
- }
51
-
52
- /** 从 events 对象推导出事件名联合类型。Event name union from an events key-value object. */
53
- export declare type EventNamesOf<T> = T extends Defined<infer O, "events"> ? O[keyof O] : T extends Record<string, string> ? T[keyof T] : never;
54
-
55
- /**
56
- * 将 PayloadMap[K] 规范为参数元组。
57
- * void→[];unknown(默认)→ [] | [unknown];单类型 T→[T];元组→不变。
58
- */
59
- declare type ToArgs<P> = P extends void ? [] : unknown extends P ? [] | [P] : P extends unknown[] ? P : [P];
60
-
61
1
  export { }