Skip to content

Commit 8cb7c65

Browse files
author
undefined
committed
Merge branch 'next' of github.com:vueComponent/ant-design-vue into next
2 parents b856166 + 2fd0459 commit 8cb7c65

29 files changed

+302
-210
lines changed

.jest.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ if (process.env.WORKFLOW === 'true') {
1313
module.exports = {
1414
testURL: 'http://localhost/',
1515
setupFiles: ['./tests/setup.js'],
16-
moduleFileExtensions: ['js', 'jsx', 'json', 'vue', 'md', 'jpg'],
16+
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'vue', 'md', 'jpg'],
1717
modulePathIgnorePatterns: ['/_site/'],
1818
testPathIgnorePatterns: testPathIgnorePatterns,
1919
transform: {
2020
'^.+\\.(vue|md)$': '<rootDir>/node_modules/vue-jest',
2121
'^.+\\.(js|jsx)$': '<rootDir>/node_modules/babel-jest',
22+
'^.+\\.(ts|tsx)$': '<rootDir>/node_modules/ts-jest',
2223
'^.+\\.svg$': '<rootDir>/node_modules/jest-transform-stub',
2324
},
2425
testRegex: libDir === 'dist' ? 'demo\\.test\\.js$' : '.*\\.test\\.js$',
@@ -45,4 +46,9 @@ module.exports = {
4546
],
4647
testEnvironment: 'jest-environment-jsdom-fifteen',
4748
transformIgnorePatterns,
49+
globals: {
50+
'ts-jest': {
51+
babelConfig: true,
52+
},
53+
},
4854
};

components/_util/BaseMixin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getOptionProps } from './props-util';
22

33
export default {
44
methods: {
5-
setState(state = {}, callback: () => any) {
5+
setState(state = {}, callback: () => void) {
66
let newState = typeof state === 'function' ? state(this.$data, this.$props) : state;
77
if (this.getDerivedStateFromProps) {
88
const s = this.getDerivedStateFromProps(getOptionProps(this), {

components/_util/classNames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type ClassValue =
1616
| boolean;
1717

1818
function classNames(...args: ClassValue[]): string {
19-
const classes = [];
19+
const classes: string[] = [];
2020
for (let i = 0; i < args.length; i++) {
2121
const value = args[i];
2222
if (!value) {

components/_util/type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PropType } from 'vue';
1+
import { PropType, VNodeProps } from 'vue';
22

33
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
44
// https://stackoverflow.com/questions/46176165/ways-to-get-string-literal-type-of-array-values-without-enum-overhead
@@ -25,6 +25,8 @@ export type EventHandlers<E> = {
2525

2626
export type Data = Record<string, unknown>;
2727

28+
export type Key = string | number;
29+
2830
export declare type DefaultFactory<T> = (props: Data) => T | null | undefined;
2931
export declare interface PropOptions<T = any, D = T> {
3032
type?: PropType<T> | true | null;

components/_util/vue-types/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { PropType } from 'vue';
22
import isPlainObject from 'lodash-es/isPlainObject';
33
import { toType, getType, isFunction, validateType, isInteger, isArray, warn } from './utils';
4-
interface BaseTypes {
5-
type: any;
6-
def: Function;
7-
validator: Function;
8-
}
4+
5+
// interface BaseTypes {
6+
// type: any;
7+
// def: Function;
8+
// validator: Function;
9+
// }
10+
911
const PropTypes = {
1012
get any() {
1113
return toType('any', {
@@ -16,7 +18,7 @@ const PropTypes = {
1618
get func() {
1719
return {
1820
type: Function,
19-
} as BaseTypes;
21+
};
2022
},
2123

2224
get bool() {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

components/tag/index.tsx

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
defineComponent,
66
SetupContext,
77
App,
8-
watchEffect,
98
VNodeTypes,
109
CSSProperties,
1110
} from 'vue';
@@ -44,29 +43,8 @@ const Tag = defineComponent({
4443
const { getPrefixCls } = inject('configProvider', defaultConfigProvider);
4544

4645
const visible = ref(true);
47-
4846
const props = attrs as TagProps;
4947

50-
watchEffect(() => {
51-
if ('visible' in props) {
52-
visible.value = props.visible!;
53-
}
54-
});
55-
56-
const handleCloseClick = (e: MouseEvent) => {
57-
e.stopPropagation();
58-
if (props.onClose) {
59-
props.onClose(e);
60-
}
61-
62-
if (e.defaultPrevented) {
63-
return;
64-
}
65-
if (!('visible' in props)) {
66-
visible.value = false;
67-
}
68-
};
69-
7048
return () => {
7149
const {
7250
prefixCls: customizePrefixCls,
@@ -79,6 +57,24 @@ const Tag = defineComponent({
7957
...restProps
8058
} = props;
8159

60+
if ('visible' in props) {
61+
visible.value = props.visible!;
62+
}
63+
64+
const handleCloseClick = (e: MouseEvent) => {
65+
e.stopPropagation();
66+
if (props.onClose) {
67+
props.onClose(e);
68+
}
69+
70+
if (e.defaultPrevented) {
71+
return;
72+
}
73+
if (!('visible' in props)) {
74+
visible.value = false;
75+
}
76+
};
77+
8278
const isPresetColor = (): boolean => {
8379
if (!color) {
8480
return false;

components/vc-resize-observer/index.jsx renamed to components/vc-resize-observer/index.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
// based on rc-resize-observer 0.1.3
2+
import { defineComponent, PropType } from 'vue';
23
import ResizeObserver from 'resize-observer-polyfill';
34
import BaseMixin from '../_util/BaseMixin';
45
import { findDOMNode } from '../_util/props-util';
56

67
// Still need to be compatible with React 15, we use class component here
7-
const VueResizeObserver = {
8+
const VueResizeObserver = defineComponent({
89
name: 'ResizeObserver',
910
mixins: [BaseMixin],
1011
props: {
1112
disabled: Boolean,
12-
onResize: Function,
13+
onResize: Function as PropType<
14+
(size: { width: number; height: number; offsetWidth: number; offsetHeight: number }) => void
15+
>,
1316
},
14-
data() {
17+
beforeCreate() {
1518
this.currentElement = null;
1619
this.resizeObserver = null;
20+
},
21+
data() {
1722
return {
1823
width: 0,
1924
height: 0,
@@ -54,7 +59,7 @@ const VueResizeObserver = {
5459
}
5560
},
5661

57-
handleResize(entries) {
62+
handleResize(entries: ResizeObserverEntry[]) {
5863
const { target } = entries[0];
5964
const { width, height } = target.getBoundingClientRect();
6065
/**
@@ -82,8 +87,8 @@ const VueResizeObserver = {
8287
},
8388

8489
render() {
85-
return this.$slots.default && this.$slots.default()[0];
90+
return this.$slots.default?.()[0];
8691
},
87-
};
92+
});
8893

8994
export default VueResizeObserver;

components/vc-virtual-list/Filler.jsx renamed to components/vc-virtual-list/Filler.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import classNames from '../_util/classNames';
22
import ResizeObserver from '../vc-resize-observer';
3+
import { CSSProperties, FunctionalComponent } from 'vue';
34

4-
const Filter = ({ height, offset, prefixCls, onInnerResize }, { slots }) => {
5+
interface FillerProps {
6+
prefixCls?: string;
7+
/** Virtual filler height. Should be `count * itemMinHeight` */
8+
height: number;
9+
/** Set offset of visible items. Should be the top of start item position */
10+
offset?: number;
11+
onInnerResize?: () => void;
12+
}
13+
14+
const Filter: FunctionalComponent<FillerProps> = (
15+
{ height, offset, prefixCls, onInnerResize },
16+
{ slots },
17+
) => {
518
let outerStyle = {};
619

7-
let innerStyle = {
20+
let innerStyle: CSSProperties = {
821
display: 'flex',
922
flexDirection: 'column',
1023
};
@@ -43,15 +56,8 @@ const Filter = ({ height, offset, prefixCls, onInnerResize }, { slots }) => {
4356
</div>
4457
);
4558
};
59+
4660
Filter.displayName = 'Filter';
4761
Filter.inheritAttrs = false;
48-
Filter.props = {
49-
prefixCls: String,
50-
/** Virtual filler height. Should be `count * itemMinHeight` */
51-
height: Number,
52-
/** Set offset of visible items. Should be the top of start item position */
53-
offset: Number,
54-
onInnerResize: Function,
55-
};
5662

5763
export default Filter;

components/vc-virtual-list/Item.jsx

Lines changed: 0 additions & 17 deletions
This file was deleted.

components/vc-virtual-list/Item.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { cloneVNode, FunctionalComponent } from 'vue';
2+
3+
export interface ItemProps {
4+
setRef: (element: HTMLElement) => void;
5+
}
6+
7+
const Item: FunctionalComponent<ItemProps> = ({ setRef }, { slots }) => {
8+
const children = slots.default?.();
9+
10+
return children && children.length
11+
? cloneVNode(children[0], {
12+
ref: setRef,
13+
})
14+
: children;
15+
};
16+
17+
export default Item;

0 commit comments

Comments
 (0)