@kine-design/core 0.0.1-beta.5 → 0.0.1-beta.7
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/components/base/affix/useAffix.ts +2 -1
- package/components/base/anchor/useAnchor.ts +2 -1
- package/components/base/autoComplete/useAutoComplete.ts +2 -1
- package/components/base/carousel/useCarousel.ts +2 -1
- package/components/base/cascader/useCascader.ts +2 -1
- package/components/base/checkbox/useCheckbox.ts +2 -1
- package/components/base/collapse/useCollapse.ts +2 -1
- package/components/base/datePicker/__tests__/useDatePicker.test.ts +239 -0
- package/components/base/dropdown/useDropdown.ts +2 -1
- package/components/base/image/__tests__/useImage.test.ts +174 -0
- package/components/base/input/useInput.ts +3 -1
- package/components/base/inputNumber/__tests__/useInputNumber.test.ts +153 -0
- package/components/base/inputNumber/useInputNumber.ts +53 -11
- package/components/base/popover/usePopover.ts +4 -3
- package/components/base/rate/useRate.ts +2 -1
- package/components/base/select/useSelect.ts +2 -1
- package/components/base/slider/useSlider.ts +2 -1
- package/components/base/steps/__tests__/useSteps.test.ts +46 -0
- package/components/base/switch/useSwitch.tsx +2 -1
- package/components/base/tabs/useTabs.ts +2 -1
- package/components/base/timePicker/__tests__/useTimePicker.test.ts +118 -0
- package/components/base/transfer/useTransfer.ts +2 -1
- package/components/base/tree/__tests__/tree.test.ts +214 -0
- package/components/message/notification/__tests__/useNotification.test.ts +129 -0
- package/components/message/popover/usePopover.ts +4 -4
- package/components/other/darkMode/useDarkMode.ts +2 -2
- package/components/template/menu/__tests__/useMenu.test.ts +157 -0
- package/components/template/pagination/__tests__/usePagination.test.ts +138 -0
- package/components/template/table/__tests__/useTable.test.ts +139 -0
- package/components/template/table/useTable.ts +2 -4
- package/components/types/hook.d.ts +11 -0
- package/compositions/common/__tests__/useDebounceFn.test.ts +62 -0
- package/compositions/common/__tests__/useEventListener.test.ts +71 -0
- package/compositions/common/__tests__/usePopover.test.ts +38 -0
- package/compositions/common/__tests__/useTeleport.test.ts +25 -0
- package/compositions/common/testAnchor.ts +211 -0
- package/compositions/common/useEventListener.ts +3 -3
- package/compositions/common/useResizeObserver.ts +6 -2
- package/compositions/input/__tests__/useBooleanInput.test.ts +73 -0
- package/compositions/modal/__tests__/useModal.test.ts +92 -0
- package/compositions/modal/useModal.ts +2 -2
- package/compositions/popper/useClickAway.ts +4 -4
- package/compositions/utils/__tests__/filters.test.ts +136 -0
- package/compositions/virtualList/__tests__/useHeightCache.test.ts +97 -0
- package/dist/components/base/affix/useAffix.d.ts +2 -1
- package/dist/components/base/anchor/useAnchor.d.ts +2 -1
- package/dist/components/base/autoComplete/useAutoComplete.d.ts +2 -1
- package/dist/components/base/carousel/useCarousel.d.ts +2 -1
- package/dist/components/base/cascader/useCascader.d.ts +2 -1
- package/dist/components/base/checkbox/useCheckbox.d.ts +2 -1
- package/dist/components/base/collapse/useCollapse.d.ts +2 -1
- package/dist/components/base/datePicker/__tests__/useDatePicker.test.d.ts +1 -0
- package/dist/components/base/dropdown/useDropdown.d.ts +2 -1
- package/dist/components/base/image/__tests__/useImage.test.d.ts +1 -0
- package/dist/components/base/input/useInput.d.ts +2 -1
- package/dist/components/base/inputNumber/__tests__/useInputNumber.test.d.ts +1 -0
- package/dist/components/base/inputNumber/useInputNumber.d.ts +2 -1
- package/dist/components/base/popover/usePopover.d.ts +2 -1
- package/dist/components/base/rate/useRate.d.ts +2 -1
- package/dist/components/base/select/useSelect.d.ts +2 -1
- package/dist/components/base/slider/useSlider.d.ts +2 -1
- package/dist/components/base/steps/__tests__/useSteps.test.d.ts +1 -0
- package/dist/components/base/switch/useSwitch.d.ts +2 -1
- package/dist/components/base/tabs/useTabs.d.ts +2 -1
- package/dist/components/base/timePicker/__tests__/useTimePicker.test.d.ts +1 -0
- package/dist/components/base/transfer/useTransfer.d.ts +2 -1
- package/dist/components/base/tree/__tests__/tree.test.d.ts +1 -0
- package/dist/components/message/notification/__tests__/useNotification.test.d.ts +1 -0
- package/dist/components/message/popover/usePopover.d.ts +1 -1
- package/dist/components/other/darkMode/useDarkMode.d.ts +2 -3
- package/dist/components/template/menu/__tests__/useMenu.test.d.ts +1 -0
- package/dist/components/template/pagination/__tests__/usePagination.test.d.ts +1 -0
- package/dist/components/template/table/__tests__/useTable.test.d.ts +1 -0
- package/dist/compositions/common/__tests__/useDebounceFn.test.d.ts +1 -0
- package/dist/compositions/common/__tests__/useEventListener.test.d.ts +1 -0
- package/dist/compositions/common/__tests__/usePopover.test.d.ts +1 -0
- package/dist/compositions/common/__tests__/useTeleport.test.d.ts +1 -0
- package/dist/compositions/common/testAnchor.d.ts +40 -0
- package/dist/compositions/common/useEventListener.d.ts +2 -2
- package/dist/compositions/input/__tests__/useBooleanInput.test.d.ts +1 -0
- package/dist/compositions/modal/__tests__/useModal.test.d.ts +1 -0
- package/dist/compositions/modal/useModal.d.ts +2 -1
- package/dist/compositions/popper/useClickAway.d.ts +3 -3
- package/dist/compositions/utils/__tests__/filters.test.d.ts +1 -0
- package/dist/compositions/virtualList/__tests__/useHeightCache.test.d.ts +1 -0
- package/dist/core.js +64 -18
- package/dist/tools/__tests__/empty.test.d.ts +1 -0
- package/dist/tools/empty.d.ts +2 -2
- package/dist/tools/types.d.ts +1 -1
- package/dist/vitest.config.d.ts +10 -0
- package/package.json +6 -2
- package/tools/__tests__/empty.test.ts +72 -0
- package/tools/empty.ts +2 -2
- package/tools/types.ts +1 -1
- package/vitest.config.ts +17 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description debounceFilter / throttleFilter / createFilterWrapper 测试
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2026/3/23
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
|
|
10
|
+
import { createFilterWrapper, debounceFilter, throttleFilter } from '../filters';
|
|
11
|
+
|
|
12
|
+
beforeEach(() => { vi.useFakeTimers(); });
|
|
13
|
+
afterEach(() => { vi.useRealTimers(); });
|
|
14
|
+
|
|
15
|
+
describe('debounceFilter', () => {
|
|
16
|
+
it('延迟执行函数', () => {
|
|
17
|
+
const fn = vi.fn();
|
|
18
|
+
const debounced = createFilterWrapper(debounceFilter(100), fn);
|
|
19
|
+
|
|
20
|
+
debounced();
|
|
21
|
+
expect(fn).not.toHaveBeenCalled();
|
|
22
|
+
|
|
23
|
+
vi.advanceTimersByTime(100);
|
|
24
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('多次调用只执行最后一次', () => {
|
|
28
|
+
const fn = vi.fn();
|
|
29
|
+
const debounced = createFilterWrapper(debounceFilter(100), fn);
|
|
30
|
+
|
|
31
|
+
debounced();
|
|
32
|
+
debounced();
|
|
33
|
+
debounced();
|
|
34
|
+
|
|
35
|
+
vi.advanceTimersByTime(100);
|
|
36
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('ms <= 0 时立即执行', () => {
|
|
40
|
+
const fn = vi.fn();
|
|
41
|
+
const debounced = createFilterWrapper(debounceFilter(0), fn);
|
|
42
|
+
|
|
43
|
+
debounced();
|
|
44
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('maxWait 限制最大等待时间', () => {
|
|
48
|
+
const fn = vi.fn();
|
|
49
|
+
const debounced = createFilterWrapper(debounceFilter(100, { maxWait: 150 }), fn);
|
|
50
|
+
|
|
51
|
+
debounced();
|
|
52
|
+
vi.advanceTimersByTime(80);
|
|
53
|
+
debounced(); // 重置 debounce timer
|
|
54
|
+
vi.advanceTimersByTime(80); // 总共 160ms,超过 maxWait
|
|
55
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('maxWait <= 0 时立即执行', () => {
|
|
59
|
+
const fn = vi.fn();
|
|
60
|
+
const debounced = createFilterWrapper(debounceFilter(100, { maxWait: 0 }), fn);
|
|
61
|
+
|
|
62
|
+
debounced();
|
|
63
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('保留参数传递', () => {
|
|
67
|
+
const fn = vi.fn();
|
|
68
|
+
const debounced = createFilterWrapper(debounceFilter(50), fn);
|
|
69
|
+
|
|
70
|
+
debounced('a', 'b');
|
|
71
|
+
vi.advanceTimersByTime(50);
|
|
72
|
+
expect(fn).toHaveBeenCalledWith('a', 'b');
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('throttleFilter', () => {
|
|
77
|
+
it('首次立即执行(leading=true 默认)', () => {
|
|
78
|
+
const fn = vi.fn();
|
|
79
|
+
const throttled = createFilterWrapper(throttleFilter(100), fn);
|
|
80
|
+
|
|
81
|
+
throttled();
|
|
82
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('间隔内不重复执行', () => {
|
|
86
|
+
const fn = vi.fn();
|
|
87
|
+
const throttled = createFilterWrapper(throttleFilter(100), fn);
|
|
88
|
+
|
|
89
|
+
throttled();
|
|
90
|
+
throttled();
|
|
91
|
+
throttled();
|
|
92
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('trailing=true 时间隔结束后执行尾部调用', () => {
|
|
96
|
+
const fn = vi.fn();
|
|
97
|
+
const throttled = createFilterWrapper(throttleFilter(100, true, true), fn);
|
|
98
|
+
|
|
99
|
+
throttled(); // leading 执行
|
|
100
|
+
throttled(); // 排队 trailing
|
|
101
|
+
|
|
102
|
+
vi.advanceTimersByTime(100);
|
|
103
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('trailing=false 不执行尾部调用', () => {
|
|
107
|
+
const fn = vi.fn();
|
|
108
|
+
const throttled = createFilterWrapper(throttleFilter(100, false, true), fn);
|
|
109
|
+
|
|
110
|
+
throttled(); // leading 执行
|
|
111
|
+
throttled(); // 不排队
|
|
112
|
+
|
|
113
|
+
vi.advanceTimersByTime(100);
|
|
114
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('leading=false 首次不执行', () => {
|
|
118
|
+
const fn = vi.fn();
|
|
119
|
+
const throttled = createFilterWrapper(throttleFilter(100, true, false), fn);
|
|
120
|
+
|
|
121
|
+
throttled();
|
|
122
|
+
expect(fn).not.toHaveBeenCalled();
|
|
123
|
+
|
|
124
|
+
vi.advanceTimersByTime(100);
|
|
125
|
+
expect(fn).toHaveBeenCalledOnce();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('ms <= 0 时立即执行', () => {
|
|
129
|
+
const fn = vi.fn();
|
|
130
|
+
const throttled = createFilterWrapper(throttleFilter(0), fn);
|
|
131
|
+
|
|
132
|
+
throttled();
|
|
133
|
+
throttled();
|
|
134
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description createHeightCache 测试
|
|
3
|
+
* @author 阿怪
|
|
4
|
+
* @date 2026/3/23
|
|
5
|
+
* @version v1.0.0
|
|
6
|
+
*
|
|
7
|
+
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
|
+
*/
|
|
9
|
+
import { describe, expect, it } from 'vitest';
|
|
10
|
+
import { createHeightCache } from '../useHeightCache';
|
|
11
|
+
|
|
12
|
+
describe('createHeightCache', () => {
|
|
13
|
+
it('初始化后 getHeight 返回预估高度', () => {
|
|
14
|
+
const cache = createHeightCache(10, 40);
|
|
15
|
+
expect(cache.getHeight(0)).toBe(40);
|
|
16
|
+
expect(cache.getHeight(5)).toBe(40);
|
|
17
|
+
expect(cache.getHeight(9)).toBe(40);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('update 后 getHeight 返回实际高度', () => {
|
|
21
|
+
const cache = createHeightCache(10, 40);
|
|
22
|
+
cache.update(3, 60);
|
|
23
|
+
expect(cache.getHeight(3)).toBe(60);
|
|
24
|
+
// 其他未更新的仍为预估值
|
|
25
|
+
expect(cache.getHeight(4)).toBe(40);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('update 越界不报错', () => {
|
|
29
|
+
const cache = createHeightCache(5, 40);
|
|
30
|
+
cache.update(-1, 50); // 越界
|
|
31
|
+
cache.update(10, 50); // 越界
|
|
32
|
+
expect(cache.getHeight(0)).toBe(40); // 不受影响
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('getOffset 返回累计高度', () => {
|
|
36
|
+
const cache = createHeightCache(5, 40);
|
|
37
|
+
// 全部预估:0*40=0, 1*40=40, ...
|
|
38
|
+
expect(cache.getOffset(0)).toBe(0);
|
|
39
|
+
expect(cache.getOffset(1)).toBe(40);
|
|
40
|
+
expect(cache.getOffset(3)).toBe(120);
|
|
41
|
+
|
|
42
|
+
// 更新某项后
|
|
43
|
+
cache.update(1, 60);
|
|
44
|
+
expect(cache.getOffset(2)).toBe(40 + 60); // 100
|
|
45
|
+
expect(cache.getOffset(3)).toBe(40 + 60 + 40); // 140
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('getTotalHeight 返回所有项高度之和', () => {
|
|
49
|
+
const cache = createHeightCache(5, 40);
|
|
50
|
+
expect(cache.getTotalHeight()).toBe(200);
|
|
51
|
+
|
|
52
|
+
cache.update(0, 50);
|
|
53
|
+
expect(cache.getTotalHeight()).toBe(210);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('findIndex 二分查找定位正确', () => {
|
|
57
|
+
const cache = createHeightCache(100, 40);
|
|
58
|
+
|
|
59
|
+
// scrollTop=0 → index 0
|
|
60
|
+
expect(cache.findIndex(0)).toBe(0);
|
|
61
|
+
|
|
62
|
+
// scrollTop=40 → index 1
|
|
63
|
+
expect(cache.findIndex(40)).toBe(1);
|
|
64
|
+
|
|
65
|
+
// scrollTop=39 → 仍在 index 0 区间内
|
|
66
|
+
expect(cache.findIndex(39)).toBe(0);
|
|
67
|
+
|
|
68
|
+
// scrollTop=80 → index 2
|
|
69
|
+
expect(cache.findIndex(80)).toBe(2);
|
|
70
|
+
|
|
71
|
+
// scrollTop 超过总高度 → 最后一项
|
|
72
|
+
expect(cache.findIndex(99999)).toBe(99);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('findIndex 在实际高度不等时也能正确定位', () => {
|
|
76
|
+
const cache = createHeightCache(5, 40);
|
|
77
|
+
cache.update(0, 100); // [100, 40, 40, 40, 40]
|
|
78
|
+
|
|
79
|
+
// scrollTop=50 → 还在 index 0(0-100)
|
|
80
|
+
expect(cache.findIndex(50)).toBe(0);
|
|
81
|
+
|
|
82
|
+
// scrollTop=100 → index 1(100-140)
|
|
83
|
+
expect(cache.findIndex(100)).toBe(1);
|
|
84
|
+
|
|
85
|
+
// scrollTop=140 → index 2(140-180)
|
|
86
|
+
expect(cache.findIndex(140)).toBe(2);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('reset 重置缓存', () => {
|
|
90
|
+
const cache = createHeightCache(5, 40);
|
|
91
|
+
cache.update(0, 100);
|
|
92
|
+
|
|
93
|
+
cache.reset(3);
|
|
94
|
+
expect(cache.getHeight(0)).toBe(40); // 重置为预估值
|
|
95
|
+
expect(cache.getTotalHeight()).toBe(120); // 3 * 40
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { HookContext } from '../../types/hook';
|
|
1
2
|
import { AffixProps } from './props';
|
|
2
|
-
export declare function useAffix(props: Required<AffixProps>, emit:
|
|
3
|
+
export declare function useAffix(props: Required<AffixProps>, emit: HookContext['emit']): {
|
|
3
4
|
wrapperRef: import('vue').Ref<HTMLElement | null, HTMLElement | null>;
|
|
4
5
|
wrapRef: import('vue').Ref<HTMLElement | null, HTMLElement | null>;
|
|
5
6
|
affixed: import('vue').Ref<boolean, boolean>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { HookContext } from '../../types/hook';
|
|
1
2
|
import { AnchorProps } from './props';
|
|
2
|
-
export declare function useAnchor(props: Required<AnchorProps>, emit:
|
|
3
|
+
export declare function useAnchor(props: Required<AnchorProps>, emit: HookContext['emit']): {
|
|
3
4
|
currentLink: import('vue').Ref<string, string>;
|
|
4
5
|
registerLink: (href: string) => void;
|
|
5
6
|
unregisterLink: (href: string) => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AutoCompleteProps, AutoCompleteOption } from './props';
|
|
2
|
-
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
3
|
+
export declare function useAutoComplete(props: AutoCompleteProps, ctx: HookContext): {
|
|
3
4
|
inputValue: import('vue').Ref<string, string>;
|
|
4
5
|
isOpen: import('vue').Ref<boolean, boolean>;
|
|
5
6
|
loading: import('vue').Ref<boolean, boolean>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { HookContext } from '../../types/hook';
|
|
1
2
|
import { CarouselProps } from './props';
|
|
2
|
-
export declare function useCarousel(props: Required<CarouselProps>, emit:
|
|
3
|
+
export declare function useCarousel(props: Required<CarouselProps>, emit: HookContext['emit'], count: () => number): {
|
|
3
4
|
activeIndex: import('vue').Ref<number, number>;
|
|
4
5
|
trackIndex: import('vue').Ref<number, number>;
|
|
5
6
|
disableTransition: import('vue').Ref<boolean, boolean>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CascaderOption, CascaderProps } from './props';
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
2
3
|
/** 扁平化后的叶子路径,用于搜索 */
|
|
3
4
|
export interface FlatCascaderOption {
|
|
4
5
|
/** 从根到当前节点的完整路径节点列表 */
|
|
@@ -6,7 +7,7 @@ export interface FlatCascaderOption {
|
|
|
6
7
|
/** 路径标签拼接(用于搜索匹配) */
|
|
7
8
|
pathLabel: string;
|
|
8
9
|
}
|
|
9
|
-
export declare function useCascader(props: CascaderProps, ctx:
|
|
10
|
+
export declare function useCascader(props: CascaderProps, ctx: HookContext): {
|
|
10
11
|
isOpen: import('vue').Ref<boolean, boolean>;
|
|
11
12
|
searchQuery: import('vue').Ref<string, string>;
|
|
12
13
|
activePath: import('vue').Ref<{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CheckboxProps } from './props';
|
|
2
|
-
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
3
|
+
export declare function useCheckbox<Props extends Required<CheckboxProps>>(props: Props, ctx: HookContext): {
|
|
3
4
|
checkboxClass: (string | {
|
|
4
5
|
'm-disabled': boolean;
|
|
5
6
|
'm-indeterminate': boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CollapseProps } from './props';
|
|
2
|
-
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
3
|
+
export declare function useCollapse(props: Required<CollapseProps>, ctx: HookContext): {
|
|
3
4
|
activeNames: import('vue').ComputedRef<(string | number)[]>;
|
|
4
5
|
isActive: (name: string | number) => boolean;
|
|
5
6
|
toggle: (name: string | number, disabled: boolean) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DropdownItemProps, DropdownProps } from './props';
|
|
2
|
-
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
3
|
+
export declare function useDropdown(props: Required<DropdownProps>, ctx: HookContext): {
|
|
3
4
|
visible: import('vue').Ref<boolean, boolean>;
|
|
4
5
|
triggerRef: import('vue').Ref<HTMLElement | undefined, HTMLElement | undefined>;
|
|
5
6
|
menuRef: import('vue').Ref<HTMLElement | undefined, HTMLElement | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HTMLElementEvent } from '../../types/template';
|
|
2
|
-
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
3
|
+
export declare function useInput<Props extends Record<string, any>>(props: Props, ctx: HookContext): {
|
|
3
4
|
baseProps: {
|
|
4
5
|
autofocus: any;
|
|
5
6
|
value: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { InputNumberProps } from './props';
|
|
2
2
|
import { HTMLElementEvent } from '../../types/template';
|
|
3
|
+
import { HookContext } from '../../types/hook';
|
|
3
4
|
export type InputNumber = string | number | null;
|
|
4
|
-
export declare function useInputNumber(props: Required<InputNumberProps>, ctx:
|
|
5
|
+
export declare function useInputNumber(props: Required<InputNumberProps>, ctx: HookContext): {
|
|
5
6
|
currentValue: import('vue').Ref<string | number, string | number>;
|
|
6
7
|
handleInputChange: (e: HTMLElementEvent<HTMLInputElement>) => void;
|
|
7
8
|
handleInputBlur: () => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Placement, PopperConfig, PositionStyle, usePopper } from '../../../compositions/popper/usePopper.ts';
|
|
2
2
|
import { PopoverProps } from './props';
|
|
3
3
|
import { Ref } from 'vue';
|
|
4
|
+
import { HookContext } from '../../types/hook';
|
|
4
5
|
export type IPopper = ReturnType<typeof usePopper>;
|
|
5
6
|
/**
|
|
6
7
|
* Popover 实例,管理定位、显示/隐藏状态
|
|
@@ -32,7 +33,7 @@ export declare class PopoverImpl {
|
|
|
32
33
|
toggle(): Promise<void>;
|
|
33
34
|
destroy(): void;
|
|
34
35
|
}
|
|
35
|
-
export declare function usePopover(props: Required<PopoverProps>, ctx:
|
|
36
|
+
export declare function usePopover(props: Required<PopoverProps>, ctx: HookContext): {
|
|
36
37
|
popoverEnter: () => void;
|
|
37
38
|
popoverLeave: () => void;
|
|
38
39
|
popoverRef: Ref<HTMLElement | undefined, HTMLElement | undefined>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { HookContext } from '../../types/hook';
|
|
1
2
|
import { RateProps } from './props';
|
|
2
|
-
export declare function useRate(props: Required<RateProps>, emit:
|
|
3
|
+
export declare function useRate(props: Required<RateProps>, emit: HookContext['emit']): {
|
|
3
4
|
hoverValue: import('vue').Ref<number | null, number | null>;
|
|
4
5
|
getStarState: (index: number) => "full" | "half" | "empty";
|
|
5
6
|
onMouseEnter: (e: MouseEvent, index: number) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SelectProps } from './props';
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
2
3
|
export interface SelectOptionItem {
|
|
3
4
|
/** 原始值 */
|
|
4
5
|
value: any;
|
|
@@ -7,7 +8,7 @@ export interface SelectOptionItem {
|
|
|
7
8
|
/** 是否选中 */
|
|
8
9
|
isSelected: boolean;
|
|
9
10
|
}
|
|
10
|
-
export declare function useSelect(props: SelectProps, ctx:
|
|
11
|
+
export declare function useSelect(props: SelectProps, ctx: HookContext): {
|
|
11
12
|
inputValue: import('vue').Ref<string, string>;
|
|
12
13
|
isOpen: import('vue').Ref<boolean, boolean>;
|
|
13
14
|
fetchLoading: import('vue').Ref<boolean, boolean>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SliderProps } from './props';
|
|
2
|
-
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
3
|
+
export declare function useSlider(props: Required<SliderProps>, ctx: HookContext): {
|
|
3
4
|
btnRef: import('vue').Ref<HTMLElement | null | undefined, HTMLElement | null | undefined>;
|
|
4
5
|
sliderRef: import('vue').Ref<HTMLElement | null, HTMLElement | null>;
|
|
5
6
|
perRef: import('vue').Ref<number, number>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SwitchProps } from './props';
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
2
3
|
export declare const switchIsBoolean: (value: SwitchProps["modelValue"]) => value is boolean;
|
|
3
4
|
export declare const getIsActive: (value: SwitchProps["modelValue"], activeValue: SwitchProps["activeValue"]) => boolean;
|
|
4
|
-
export declare function useSwitch<Props extends Record<string, any>>(props: Props, ctx:
|
|
5
|
+
export declare function useSwitch<Props extends Record<string, any>>(props: Props, ctx: HookContext): {
|
|
5
6
|
getInfo: (key: keyof Pick<SwitchProps, "activeInfo" | "inactiveInfo">) => any;
|
|
6
7
|
changeSwitch: () => void;
|
|
7
8
|
switchClass: import('vue').ComputedRef<(string | {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { HookContext } from '../../types/hook';
|
|
2
|
+
export declare function useTabs<Props extends Record<string, unknown>>(props: Props, ctx: HookContext): {
|
|
2
3
|
activeTab: import('vue').ComputedRef<string | number>;
|
|
3
4
|
isActive: (name: string | number) => boolean;
|
|
4
5
|
switchTab: (name: string | number, disabled?: boolean) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TransferItem, TransferProps } from './props';
|
|
2
|
-
|
|
2
|
+
import { HookContext } from '../../types/hook';
|
|
3
|
+
export declare function useTransfer(props: TransferProps, ctx: HookContext): {
|
|
3
4
|
leftSearch: import('vue').Ref<string, string>;
|
|
4
5
|
rightSearch: import('vue').Ref<string, string>;
|
|
5
6
|
leftData: import('vue').ComputedRef<TransferItem[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { HookContext } from '../../types/hook';
|
|
1
2
|
import { DarkModeProps } from './props';
|
|
2
3
|
/** 将暗色状态同步到 html[dark] attribute */
|
|
3
4
|
declare function applyDarkAttr(isDark: boolean): void;
|
|
4
|
-
export declare function useDarkMode(props: DarkModeProps, ctx: {
|
|
5
|
-
emit: (event: string, ...args: any[]) => void;
|
|
6
|
-
}): {
|
|
5
|
+
export declare function useDarkMode(props: DarkModeProps, ctx: Pick<HookContext, 'emit'>): {
|
|
7
6
|
isDark: import('vue').Ref<boolean, boolean>;
|
|
8
7
|
toggle: () => void;
|
|
9
8
|
applyDarkAttr: typeof applyDarkAttr;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ComponentPropsOptions, EmitsOptions, InjectionKey, Ref, SetupContext, VNode } from 'vue';
|
|
2
|
+
/** Global switch provided by KConfigProvider to enable data-k rendering */
|
|
3
|
+
export declare const K_TEST_ANCHOR_KEY: InjectionKey<Ref<boolean>>;
|
|
4
|
+
/** Field identity provided by KFormItem so child inputs inherit field name */
|
|
5
|
+
export declare const K_FIELD_KEY: InjectionKey<Ref<string | undefined>>;
|
|
6
|
+
export interface KAnchorConfig {
|
|
7
|
+
/** Semantic type: 'field' | 'action' | 'table' | 'col' | 'dialog' | 'drawer' | 'tab' */
|
|
8
|
+
type: string;
|
|
9
|
+
/** Which prop to derive the identity from (e.g., 'prop' for KFormItem, 'title' for KDialog) */
|
|
10
|
+
prop?: string;
|
|
11
|
+
/** Derive identity from default slot text content (for KButton) */
|
|
12
|
+
slotText?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface KDefineComponentOptions {
|
|
15
|
+
name: string;
|
|
16
|
+
props?: ComponentPropsOptions;
|
|
17
|
+
emits?: EmitsOptions;
|
|
18
|
+
kAnchor?: KAnchorConfig;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Wrapper around Vue's defineComponent that automatically injects `data-k`
|
|
22
|
+
* test anchor attributes when testAnchor is enabled via KConfigProvider.
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* ```tsx
|
|
26
|
+
* export default kDefineComponent((_props, ctx) => {
|
|
27
|
+
* return () => <div class="k-form-item">...</div>;
|
|
28
|
+
* }, {
|
|
29
|
+
* name: 'KFormItem',
|
|
30
|
+
* props: FormCore.formItemProps,
|
|
31
|
+
* kAnchor: { type: 'field', prop: 'prop' },
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function kDefineComponent<P extends Record<string, unknown>>(setup: (props: P, ctx: SetupContext) => () => VNode | VNode[] | null | undefined, options: KDefineComponentOptions): import('vue').DefineSetupFnComponent<P, EmitsOptions, {}, P & ({
|
|
36
|
+
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
|
39
|
+
}), import('vue').PublicProps>;
|
|
40
|
+
export {};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
8
8
|
*/
|
|
9
9
|
export type EventListenerOptions = {
|
|
10
|
-
target:
|
|
10
|
+
target: EventTarget | (() => EventTarget);
|
|
11
11
|
event: string;
|
|
12
12
|
handler: EventListenerOrEventListenerObject;
|
|
13
13
|
};
|
|
@@ -15,5 +15,5 @@ export default function useEventListener(options: EventListenerOptions): {
|
|
|
15
15
|
add: () => void;
|
|
16
16
|
remove: () => void;
|
|
17
17
|
onMounted: () => void;
|
|
18
|
-
|
|
18
|
+
onBeforeUnmount: () => void;
|
|
19
19
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { HookContext } from '../../components/types/hook';
|
|
1
2
|
import { ModelMask } from '../../types/common/model';
|
|
2
3
|
export interface UseModalProps {
|
|
3
4
|
visible?: boolean;
|
|
4
5
|
mask?: ModelMask;
|
|
5
6
|
}
|
|
6
|
-
export declare function useModal(props: UseModalProps, emit:
|
|
7
|
+
export declare function useModal(props: UseModalProps, emit: HookContext['emit']): {
|
|
7
8
|
visible: import('vue').Ref<boolean, boolean>;
|
|
8
9
|
open: () => void;
|
|
9
10
|
close: () => void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export default function useClickAway(options: {
|
|
2
|
-
target:
|
|
3
|
-
handler: (event:
|
|
2
|
+
target: EventTarget | (() => EventTarget | null | undefined);
|
|
3
|
+
handler: (event: PointerEvent) => void;
|
|
4
4
|
}): {
|
|
5
5
|
add: () => void;
|
|
6
6
|
remove: () => void;
|
|
7
7
|
onMounted: () => void;
|
|
8
|
-
|
|
8
|
+
onBeforeUnmount: () => void;
|
|
9
9
|
} | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|