forked from ant-design/ant-design-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor type definitions (ant-design#2323)
* refactor(util): noImplicitAny * refactor(accordion): type definitions improvements * refactor(action-sheet): add missing type definitions * chore: configuration * refactor(activity-indicator): type definitions * chore: configuration * refactor(badge): type definitions * refactor(button): type definitions * refactor(calendar): type definitions * refactor(card): type definitions * refactor(carousel): add type definitions and refactor native part * refactor(checkbox): type definitions * refactor(list): type definitions * refactor(date-picker): type definitions * refactor(date-picker-view): type definitions * refactor(drawer): type definitions * refactor(flex): type definitions * refactor(grid): type definitions * refactor(icon): type definitions * refactor(image-picker): type definitions * refactor(input-item): type definitions and code refactor * refactor(locale-provider): type definitions * refactor(menu): type definitions * refactor(modal): type definitions * refactor(nav-bar): type definitions * refactor(notice-bar): type definitions * refactor(pagination): type definitions * refactor(picker): type definitions * refactor(picker-view): type definitions * refactor(popover): type definitions * refactor(progress): type definitions * refactor(radio): type definitions * refactor(range): type definitions * refactor(result): type definitions * refactor(search-bar): type definitions * refactor(segmented-control): type definitions * refactor(slider): type definitions * refactor(stepper): type definitions * refactor(steps): type definitions * refactor(swipe-action): type definitions * refactor(switch): type definitions * refactor(tab-bar): type definitions * refactor(tabs): type definitions * refactor(tag): type definitions * refactor(view|text): type definitions * refactor(textarea-item): type definitions * refactor(toast): type definitions * refactor(white-space): type definitions * refactor(wing-blank): type definitions * refactor(list-view): type definitions * refactor(demo): any * chore(style): use ant-tools tslint configurations * test: update snapshots * chore: remove unnecessary configurations and deps * chore: tslint * chore: add setup file * fix: ant-design#2302 * test: update snap * chore: update deps and fix tests * chore: try to let jest faster * refactor(Icon): extends from SVG Props
- Loading branch information
1 parent
35a1338
commit 71a4ccc
Showing
255 changed files
with
6,157 additions
and
3,295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
export default function closest(el, selector) { | ||
const matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector; | ||
while (el) { | ||
if (matchesSelector.call(el, selector)) { | ||
return el; | ||
export default function closest(el: Element, selector: string) { | ||
const matchesSelector = | ||
el.matches || | ||
el.webkitMatchesSelector || | ||
(el as any).mozMatchesSelector || | ||
el.msMatchesSelector; | ||
let p: Element | null = el; | ||
while (p) { | ||
if (matchesSelector.call(p, selector)) { | ||
return p; | ||
} | ||
el = el.parentElement; | ||
p = p.parentElement; | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// @see https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-307871458 | ||
export type Diff<T extends string, U extends string> = ({ [P in T]: P } & | ||
{ [P in U]: never } & { [x: string]: never })[T]; | ||
// get all from A except B* | ||
// type C = Omit<A,'B1'|'B2'> | ||
export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// tslint:disable | ||
if ( | ||
typeof process !== 'undefined' && | ||
process.env.NODE_ENV === 'development' && | ||
!process.env.DISABLE_ANTD_MOBILE_UPGRADE | ||
) { | ||
try { | ||
const localVersion = require('./version.json'); | ||
if (!localVersion._disable && fetch) { | ||
//#region fetch-jsonp | ||
const defaultOptions = { | ||
timeout: 5000, | ||
jsonpCallback: 'callback', | ||
jsonpCallbackFunction: null, | ||
}; | ||
|
||
function generateCallbackFunction() { | ||
return `jsonp_${Date.now()}_${Math.ceil(Math.random() * 100000)}`; | ||
} | ||
|
||
function clearFunction(functionName: string) { | ||
// IE8 throws an exception when you try to delete a property on window | ||
// http://stackoverflow.com/a/1824228/751089 | ||
try { | ||
delete (window as any)[functionName]; | ||
} catch (e) { | ||
(window as any)[functionName] = undefined; | ||
} | ||
} | ||
|
||
function removeScript(scriptId: string) { | ||
const script = document.getElementById(scriptId); | ||
if (script) { | ||
document.getElementsByTagName('head')[0].removeChild(script); | ||
} | ||
} | ||
|
||
function fetchJsonp(_url: string, options: any = {}) { | ||
// to avoid param reassign | ||
let url = _url; | ||
const timeout = options.timeout || defaultOptions.timeout; | ||
const jsonpCallback = | ||
options.jsonpCallback || defaultOptions.jsonpCallback; | ||
|
||
let timeoutId: number; | ||
|
||
return new Promise((resolve, reject) => { | ||
const callbackFunction = | ||
options.jsonpCallbackFunction || generateCallbackFunction(); | ||
const scriptId = `${jsonpCallback}_${callbackFunction}`; | ||
(window as any)[callbackFunction] = (response: any) => { | ||
resolve({ | ||
ok: true, | ||
// keep consistent with fetch API | ||
json: () => Promise.resolve(response), | ||
}); | ||
|
||
if (timeoutId) { | ||
clearTimeout(timeoutId); | ||
} | ||
|
||
removeScript(scriptId); | ||
|
||
clearFunction(callbackFunction); | ||
}; | ||
|
||
// Check if the user set their own params, and if not add a ? to start a list of params | ||
url += url.indexOf('?') === -1 ? '?' : '&'; | ||
|
||
const jsonpScript = document.createElement('script'); | ||
jsonpScript.setAttribute( | ||
'src', | ||
`${url}${jsonpCallback}=${callbackFunction}` | ||
); | ||
if (options.charset) { | ||
jsonpScript.setAttribute('charset', options.charset); | ||
} | ||
jsonpScript.id = scriptId; | ||
document.getElementsByTagName('head')[0].appendChild(jsonpScript); | ||
|
||
timeoutId = setTimeout(() => { | ||
reject(new Error(`JSONP request to ${_url} timed out`)); | ||
|
||
clearFunction(callbackFunction); | ||
removeScript(scriptId); | ||
(window as any)[callbackFunction] = () => { | ||
clearFunction(callbackFunction); | ||
}; | ||
}, timeout); | ||
|
||
// Caught if got 404/500 | ||
jsonpScript.onerror = () => { | ||
reject(new Error(`JSONP request to ${_url} failed`)); | ||
|
||
clearFunction(callbackFunction); | ||
removeScript(scriptId); | ||
if (timeoutId) { | ||
clearTimeout(timeoutId); | ||
} | ||
}; | ||
}); | ||
} | ||
//#endregion | ||
|
||
const gateway = | ||
'https://basement-gzone.alipay.com/mgw_proxy/unauthorized_endpoint'; | ||
const params = { | ||
path: 'antd-mobile-upgrade-tip/upgrade-tip-h5data', | ||
'x-basement-operation': 'com.alipay.h5data.fengdie.get', | ||
}; | ||
const requestData = encodeURIComponent(JSON.stringify([params])); | ||
|
||
fetchJsonp(`${gateway}?requestData=${requestData}`) | ||
.then((res: any) => res.json()) | ||
.then(data => { | ||
if (!data.result || !data.result.success) { | ||
return; | ||
} else { | ||
data = data.result.result; | ||
} | ||
let notice = ''; | ||
const tipComponents = data.filter((item: any) => { | ||
const key = item.name; | ||
if (key === '[notice]') { | ||
notice = item.tip; | ||
} | ||
if (!localVersion[key]) { | ||
return false; | ||
} | ||
const oldVer = localVersion[key].split('.') as string[]; | ||
const newVer = item.version.split('.') as string[]; | ||
let result = false; | ||
const length = Math.max(oldVer.length, newVer.length); | ||
for (let i = 0; i < length; i++) { | ||
if (oldVer[i] !== newVer[i]) { | ||
const newVerNum = +newVer[i]; | ||
const oldVerNum = +oldVer[i]; | ||
const hasNaN = isNaN(newVerNum) || isNaN(oldVerNum); | ||
result = !(!hasNaN && oldVerNum >= newVerNum); | ||
if (result) { | ||
break; | ||
} | ||
} | ||
} | ||
return result; | ||
}); | ||
|
||
if (notice) { | ||
console.warn( | ||
'--------------------------------------------------------\n', | ||
'[antd-mobile-upgrade-tip] Notice:\n', | ||
`${notice}\n`, | ||
'--------------------------------------------------------' | ||
); | ||
} | ||
|
||
if (tipComponents.length > 0) { | ||
console.warn( | ||
'--------------------------------------------------------\n', | ||
'[antd-mobile-upgrade-tip] some components is expired:\n', | ||
'\n', | ||
...tipComponents.map((newData: any) => { | ||
const key = newData.name; | ||
return `${key}: ${localVersion[key]} => ${newData.version} ${ | ||
newData.tip | ||
} ${newData.url}\n`; | ||
}), | ||
'\n', | ||
'[you can reinstall node_modules to upgrade all of them.]\n', | ||
'[about this] http://mobile.ant.design/docs/react/upgrade-tip-cn\n', | ||
'--------------------------------------------------------' | ||
); | ||
} | ||
}) | ||
.catch(() => {}); | ||
} | ||
} catch (error) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
interface AccordionProps { | ||
style?: any; | ||
activeKey?: string | Array<string>; | ||
defaultActiveKey?: string | Array<string>; | ||
export interface AccordionPropsTypes { | ||
activeKey?: string | string[]; | ||
defaultActiveKey?: string | string[]; | ||
onChange?: (x: any) => void; | ||
} | ||
|
||
export default AccordionProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.