chore: ts type
parent
6e6fd3af79
commit
f875b3add1
|
@ -11,9 +11,8 @@ export default defineComponent({
|
||||||
children: PropTypes.any.isRequired,
|
children: PropTypes.any.isRequired,
|
||||||
didUpdate: PropTypes.func,
|
didUpdate: PropTypes.func,
|
||||||
},
|
},
|
||||||
data() {
|
beforeCreate() {
|
||||||
this._container = null;
|
this._container = null;
|
||||||
return {};
|
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.createContainer();
|
this.createContainer();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const isNumeric = value => {
|
const isNumeric = (value: any): boolean => {
|
||||||
return !isNaN(parseFloat(value)) && isFinite(value);
|
return !isNaN(parseFloat(value)) && isFinite(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default isNumeric;
|
export default isNumeric;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { isVNode, Fragment, Comment, Text, h, VNode, ComponentPublicInstance } from 'vue';
|
import { isVNode, Fragment, Comment, Text, h, VNode, ComponentPublicInstance, Slots } from 'vue';
|
||||||
import isPlainObject from 'lodash-es/isPlainObject';
|
import isPlainObject from 'lodash-es/isPlainObject';
|
||||||
import { camelize, hyphenate, isOn, resolvePropValue } from './util';
|
import { camelize, hyphenate, isOn, resolvePropValue } from './util';
|
||||||
import isValid from './isValid';
|
import isValid from './isValid';
|
||||||
|
@ -148,6 +148,16 @@ const getOptionProps = (instance: ComponentPublicInstance) => {
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getComponentFromSetup = (
|
||||||
|
props: Record<string, unknown>,
|
||||||
|
slots: Slots,
|
||||||
|
name: string,
|
||||||
|
options?: unknown,
|
||||||
|
) => {
|
||||||
|
return props[name] ? props[name] : slots[name]?.(options);
|
||||||
|
};
|
||||||
|
|
||||||
const getComponent = (
|
const getComponent = (
|
||||||
instance: ComponentPublicInstance,
|
instance: ComponentPublicInstance,
|
||||||
prop: string = 'default',
|
prop: string = 'default',
|
||||||
|
@ -403,5 +413,6 @@ export {
|
||||||
getAllChildren,
|
getAllChildren,
|
||||||
findDOMNode,
|
findDOMNode,
|
||||||
flattenChildren,
|
flattenChildren,
|
||||||
|
getComponentFromSetup,
|
||||||
};
|
};
|
||||||
export default hasProp;
|
export default hasProp;
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
import raf from 'raf';
|
import raf from 'raf';
|
||||||
|
|
||||||
let id = 0;
|
interface RafMap {
|
||||||
const ids = {};
|
[id: number]: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
let id: number = 0;
|
||||||
|
const ids: RafMap = {};
|
||||||
|
|
||||||
// Support call raf with delay specified frame
|
// Support call raf with delay specified frame
|
||||||
export default function wrapperRaf(callback, delayFrames = 1) {
|
export default function wrapperRaf(callback: () => void, delayFrames: number = 1): number {
|
||||||
const myId = id++;
|
const myId = id++;
|
||||||
let restFrames = delayFrames;
|
let restFrames = delayFrames;
|
||||||
|
|
||||||
|
@ -24,9 +28,10 @@ export default function wrapperRaf(callback, delayFrames = 1) {
|
||||||
return myId;
|
return myId;
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapperRaf.cancel = function(pid) {
|
wrapperRaf.cancel = function(pid?: number) {
|
||||||
if (pid === undefined) return;
|
if (pid === undefined) return;
|
||||||
raf.cancel(ids[pid]);
|
raf.cancel(ids[pid]);
|
||||||
delete ids[pid];
|
delete ids[pid];
|
||||||
};
|
};
|
||||||
|
|
||||||
wrapperRaf.ids = ids; // export this for test usage
|
wrapperRaf.ids = ids; // export this for test usage
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const isStyleSupport = styleName => {
|
const isStyleSupport = (styleName: string | string[]): boolean => {
|
||||||
if (typeof window !== 'undefined' && window.document && window.document.documentElement) {
|
if (typeof window !== 'undefined' && window.document && window.document.documentElement) {
|
||||||
const styleNameList = Array.isArray(styleName) ? styleName : [styleName];
|
const styleNameList = Array.isArray(styleName) ? styleName : [styleName];
|
||||||
const { documentElement } = window.document;
|
const { documentElement } = window.document;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default function triggerEvent(el, type) {
|
export default function triggerEvent(el: HTMLElement, type: string) {
|
||||||
if ('createEvent' in document) {
|
if ('createEvent' in document) {
|
||||||
// modern browsers, IE9+
|
// modern browsers, IE9+
|
||||||
const e = document.createEvent('HTMLEvents');
|
const e = document.createEvent('HTMLEvents');
|
||||||
|
|
|
@ -7,22 +7,22 @@ export const isObject = (val: unknown): val is object => val !== null && typeof
|
||||||
const onRE = /^on[^a-z]/;
|
const onRE = /^on[^a-z]/;
|
||||||
const isOn = (key: string) => onRE.test(key);
|
const isOn = (key: string) => onRE.test(key);
|
||||||
|
|
||||||
const cacheStringFunction = fn => {
|
const cacheStringFunction = (fn: (str: string) => string) => {
|
||||||
const cache = Object.create(null);
|
const cache = Object.create(null);
|
||||||
return str => {
|
return (str: string) => {
|
||||||
const hit = cache[str];
|
const hit = cache[str];
|
||||||
return hit || (cache[str] = fn(str));
|
return hit || (cache[str] = fn(str));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const camelizeRE = /-(\w)/g;
|
const camelizeRE = /-(\w)/g;
|
||||||
const camelize = cacheStringFunction(str => {
|
const camelize = cacheStringFunction((str: string) => {
|
||||||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
|
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
|
||||||
});
|
});
|
||||||
|
|
||||||
const hyphenateRE = /\B([A-Z])/g;
|
const hyphenateRE = /\B([A-Z])/g;
|
||||||
const hyphenate = cacheStringFunction((str: string) => {
|
const hyphenate = cacheStringFunction((str: string) =>
|
||||||
return str.replace(hyphenateRE, '-$1').toLowerCase();
|
str.replace(hyphenateRE, '-$1').toLowerCase(),
|
||||||
});
|
);
|
||||||
|
|
||||||
const capitalize = cacheStringFunction((str: string) => {
|
const capitalize = cacheStringFunction((str: string) => {
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||||
|
|
|
@ -186,11 +186,11 @@ export const validateType = (type, value, silent = false) => {
|
||||||
return valid;
|
return valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
let warn = noop;
|
let warn: any = noop;
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
const hasConsole = typeof console !== 'undefined';
|
const hasConsole = typeof console !== 'undefined';
|
||||||
warn = msg => {
|
warn = (msg: string) => {
|
||||||
if (hasConsole) {
|
if (hasConsole) {
|
||||||
console.warn(`[VueTypes warn]: ${msg}`);
|
console.warn(`[VueTypes warn]: ${msg}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue