Skip to content

Commit b856166

Browse files
author
undefined
committed
chore: update to ts
1 parent dffb0cc commit b856166

File tree

10 files changed

+62
-47
lines changed

10 files changed

+62
-47
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ build/Release
3636
node_modules/
3737
jspm_packages/
3838

39-
# Typescript v1 declaration files
40-
typings/
41-
4239
# Optional npm cache directory
4340
.npm
4441

antdv-demo

components/_util/callMoment.ts

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

components/_util/createRef.js

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

components/_util/createRef.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
interface RefObject<T> extends Function {
2+
current?: T | null;
3+
}
4+
5+
function createRef<T>(): RefObject<T> {
6+
const func: RefObject<T> = (node: T | null) => {
7+
func.current = node;
8+
};
9+
return func;
10+
}
11+
12+
export default createRef;

components/_util/css-animation/Event.js renamed to components/_util/css-animation/Event.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const START_EVENT_NAME_MAP = {
1+
const START_EVENT_NAME_MAP: Record<string, Record<string, string>> = {
22
transitionstart: {
33
transition: 'transitionstart',
44
WebkitTransition: 'webkitTransitionStart',
@@ -16,7 +16,7 @@ const START_EVENT_NAME_MAP = {
1616
},
1717
};
1818

19-
const END_EVENT_NAME_MAP = {
19+
const END_EVENT_NAME_MAP: Record<string, Record<string, string>> = {
2020
transitionend: {
2121
transition: 'transitionend',
2222
WebkitTransition: 'webkitTransitionEnd',
@@ -34,8 +34,8 @@ const END_EVENT_NAME_MAP = {
3434
},
3535
};
3636

37-
const startEvents = [];
38-
const endEvents = [];
37+
const startEvents: any[] = [];
38+
const endEvents: any[] = [];
3939

4040
function detectEvents() {
4141
const testEl = document.createElement('div');
@@ -51,7 +51,7 @@ function detectEvents() {
5151
delete END_EVENT_NAME_MAP.transitionend.transition;
5252
}
5353

54-
function process(EVENT_NAME_MAP, events) {
54+
function process(EVENT_NAME_MAP: Record<string, Record<string, string>>, events: any[]) {
5555
for (const baseEventName in EVENT_NAME_MAP) {
5656
if (EVENT_NAME_MAP.hasOwnProperty(baseEventName)) {
5757
const baseEvents = EVENT_NAME_MAP[baseEventName];
@@ -73,19 +73,19 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
7373
detectEvents();
7474
}
7575

76-
function addEventListener(node, eventName, eventListener) {
76+
function addEventListener(node: Element, eventName: string, eventListener: any) {
7777
node.addEventListener(eventName, eventListener, false);
7878
}
7979

80-
function removeEventListener(node, eventName, eventListener) {
80+
function removeEventListener(node: Element, eventName: string, eventListener: any) {
8181
node.removeEventListener(eventName, eventListener, false);
8282
}
8383

8484
const TransitionEvents = {
8585
// Start events
8686
startEvents,
8787

88-
addStartEventListener(node, eventListener) {
88+
addStartEventListener(node: Element, eventListener: any) {
8989
if (startEvents.length === 0) {
9090
window.setTimeout(eventListener, 0);
9191
return;
@@ -95,7 +95,7 @@ const TransitionEvents = {
9595
});
9696
},
9797

98-
removeStartEventListener(node, eventListener) {
98+
removeStartEventListener(node: Element, eventListener: any) {
9999
if (startEvents.length === 0) {
100100
return;
101101
}
@@ -107,7 +107,7 @@ const TransitionEvents = {
107107
// End events
108108
endEvents,
109109

110-
addEndEventListener(node, eventListener) {
110+
addEndEventListener(node: Element, eventListener: any) {
111111
if (endEvents.length === 0) {
112112
window.setTimeout(eventListener, 0);
113113
return;
@@ -117,7 +117,7 @@ const TransitionEvents = {
117117
});
118118
},
119119

120-
removeEndEventListener(node, eventListener) {
120+
removeEndEventListener(node: Element, eventListener: any) {
121121
if (endEvents.length === 0) {
122122
return;
123123
}

components/_util/css-animation/index.js renamed to components/_util/css-animation/index.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ const capitalPrefixes = [
1414
];
1515
const prefixes = ['-webkit-', '-moz-', '-o-', 'ms-', ''];
1616

17-
function getStyleProperty(node, name) {
17+
interface CustomHTMLElement extends HTMLElement {
18+
rcEndAnimTimeout?: any;
19+
rcAnimTimeout?: any;
20+
rcEndListener?: Function | null;
21+
}
22+
23+
function getStyleProperty(node: HTMLElement, name: string) {
1824
// old ff need null, https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle
1925
const style = window.getComputedStyle(node, null);
2026
let ret = '';
@@ -27,7 +33,7 @@ function getStyleProperty(node, name) {
2733
return ret;
2834
}
2935

30-
function fixBrowserByTimeout(node) {
36+
function fixBrowserByTimeout(node: CustomHTMLElement) {
3137
if (isCssAnimationSupported) {
3238
const transitionDelay = parseFloat(getStyleProperty(node, 'transition-delay')) || 0;
3339
const transitionDuration = parseFloat(getStyleProperty(node, 'transition-duration')) || 0;
@@ -44,20 +50,29 @@ function fixBrowserByTimeout(node) {
4450
}
4551
}
4652

47-
function clearBrowserBugTimeout(node) {
53+
function clearBrowserBugTimeout(node: CustomHTMLElement) {
4854
if (node.rcEndAnimTimeout) {
4955
clearTimeout(node.rcEndAnimTimeout);
5056
node.rcEndAnimTimeout = null;
5157
}
5258
}
53-
54-
const cssAnimation = (node, transitionName, endCallback) => {
59+
interface TransitionName {
60+
name?: string;
61+
active?: string;
62+
}
63+
const cssAnimation = (
64+
node: CustomHTMLElement,
65+
transitionName: string | TransitionName,
66+
endCallback?: any,
67+
) => {
5568
const nameIsObj = typeof transitionName === 'object';
56-
const className = nameIsObj ? transitionName.name : transitionName;
57-
const activeClassName = nameIsObj ? transitionName.active : `${transitionName}-active`;
69+
const className = nameIsObj ? (transitionName as TransitionName).name : transitionName;
70+
const activeClassName = nameIsObj
71+
? (transitionName as TransitionName).active
72+
: `${transitionName}-active`;
5873
let end = endCallback;
5974
let start;
60-
let active;
75+
let active: any;
6176
const nodeClasses = classes(node);
6277

6378
if (endCallback && Object.prototype.toString.call(endCallback) === '[object Object]') {
@@ -70,7 +85,7 @@ const cssAnimation = (node, transitionName, endCallback) => {
7085
node.rcEndListener();
7186
}
7287

73-
node.rcEndListener = e => {
88+
node.rcEndListener = (e: Event) => {
7489
if (e && e.target !== node) {
7590
return;
7691
}
@@ -124,12 +139,12 @@ const cssAnimation = (node, transitionName, endCallback) => {
124139
};
125140
};
126141

127-
cssAnimation.style = (node, style, callback) => {
142+
cssAnimation.style = (node: CustomHTMLElement, style: Record<string, any>, callback?: Function) => {
128143
if (node.rcEndListener) {
129144
node.rcEndListener();
130145
}
131146

132-
node.rcEndListener = e => {
147+
node.rcEndListener = (e: Event) => {
133148
if (e && e.target !== node) {
134149
return;
135150
}
@@ -156,15 +171,15 @@ cssAnimation.style = (node, style, callback) => {
156171
node.rcAnimTimeout = requestAnimationTimeout(() => {
157172
for (const s in style) {
158173
if (style.hasOwnProperty(s)) {
159-
node.style[s] = style[s];
174+
node.style[s as any] = style[s];
160175
}
161176
}
162177
node.rcAnimTimeout = null;
163178
fixBrowserByTimeout(node);
164179
}, 0);
165180
};
166181

167-
cssAnimation.setTransition = (node, p, value) => {
182+
cssAnimation.setTransition = (node: HTMLElement, p?: any, value?: any) => {
168183
let property = p;
169184
let v = value;
170185
if (value === undefined) {
@@ -173,7 +188,7 @@ cssAnimation.setTransition = (node, p, value) => {
173188
}
174189
property = property || '';
175190
capitalPrefixes.forEach(prefix => {
176-
node.style[`${prefix}Transition${property}`] = v;
191+
node.style[`${prefix}Transition${property}` as any] = v;
177192
});
178193
};
179194

components/_util/openAnimation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import cssAnimation from './css-animation';
22
import raf from 'raf';
33
import { nextTick } from 'vue';
44

5-
function animate(node, show, done) {
6-
let height;
7-
let requestAnimationFrameId;
8-
let appearRequestAnimationFrameId;
5+
function animate(node: HTMLElement, show: boolean, done: () => void) {
6+
let height: number;
7+
let requestAnimationFrameId: number;
8+
let appearRequestAnimationFrameId: number;
99
return cssAnimation(node, 'ant-motion-collapse-legacy', {
1010
start() {
1111
if (appearRequestAnimationFrameId) {
@@ -54,12 +54,12 @@ function animate(node, show, done) {
5454
}
5555

5656
const animation = {
57-
onEnter(node, done) {
57+
onEnter(node: HTMLElement, done: () => void) {
5858
nextTick(() => {
5959
animate(node, true, done);
6060
});
6161
},
62-
onLeave(node, done) {
62+
onLeave(node: HTMLElement, done: () => void) {
6363
return animate(node, false, done);
6464
},
6565
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
},
198198
"dependencies": {
199199
"@ant-design-vue/use": "^0.0.1-0",
200+
"@ant-design/css-animation": "^1.7.3",
200201
"@ant-design/icons-vue": "^5.1.5",
201202
"@babel/runtime": "^7.10.5",
202203
"@simonwep/pickr": "~1.7.0",

typings/custom-typings.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module '@ant-design/css-animation*';
2+
declare module 'component-classes';

0 commit comments

Comments
 (0)