mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore: prettier all ts code
This commit is contained in:
parent
04c49b645a
commit
207e80f396
@ -14,7 +14,7 @@ export type SharedCellProps = {
|
||||
value?: string | number;
|
||||
label?: string | number;
|
||||
arrowDirection?: 'up' | 'down' | 'left' | 'right';
|
||||
}
|
||||
};
|
||||
|
||||
export const cellProps = {
|
||||
icon: String,
|
||||
|
@ -20,7 +20,10 @@ export const ClickOutsideMixin = (config: ClickOutsideMixinConfig) =>
|
||||
|
||||
data() {
|
||||
const clickOutsideHandler = (event: Event) => {
|
||||
if (this.closeOnClickOutside && !this.$el.contains(event.target as Node)) {
|
||||
if (
|
||||
this.closeOnClickOutside &&
|
||||
!this.$el.contains(event.target as Node)
|
||||
) {
|
||||
(this as any)[config.method]();
|
||||
}
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ function getElement(selector: string | GetContainer): Element | null {
|
||||
export function PortalMixin({ ref, afterPortal }: PortalMixinOptions) {
|
||||
return Vue.extend({
|
||||
props: {
|
||||
getContainer: [String, Function] as (PropType<string | GetContainer>),
|
||||
getContainer: [String, Function] as PropType<string | GetContainer>,
|
||||
},
|
||||
|
||||
watch: {
|
||||
@ -33,7 +33,7 @@ export function PortalMixin({ ref, afterPortal }: PortalMixinOptions) {
|
||||
methods: {
|
||||
portal() {
|
||||
const { getContainer } = this;
|
||||
const el = ref ? this.$refs[ref] as HTMLElement : this.$el;
|
||||
const el = ref ? (this.$refs[ref] as HTMLElement) : this.$el;
|
||||
|
||||
let container;
|
||||
if (getContainer) {
|
||||
|
@ -25,7 +25,10 @@ type ChildrenMixinThis = {
|
||||
disableBindRelation?: boolean;
|
||||
};
|
||||
|
||||
export function ChildrenMixin(parent: string, options: ChildrenMixinOptions = {}) {
|
||||
export function ChildrenMixin(
|
||||
parent: string,
|
||||
options: ChildrenMixinOptions = {}
|
||||
) {
|
||||
const indexKey = options.indexKey || 'index';
|
||||
|
||||
return Vue.extend({
|
||||
@ -56,7 +59,9 @@ export function ChildrenMixin(parent: string, options: ChildrenMixinOptions = {}
|
||||
|
||||
beforeDestroy() {
|
||||
if (this.parent) {
|
||||
this.parent.children = this.parent.children.filter((item: any) => item !== this);
|
||||
this.parent.children = this.parent.children.filter(
|
||||
(item: any) => item !== this
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@ -68,7 +73,9 @@ export function ChildrenMixin(parent: string, options: ChildrenMixinOptions = {}
|
||||
|
||||
const children = [...this.parent.children, this];
|
||||
const vnodes = flattenVNodes(this.parent.slots());
|
||||
children.sort((a, b) => vnodes.indexOf(a.$vnode) - vnodes.indexOf(b.$vnode));
|
||||
children.sort(
|
||||
(a, b) => vnodes.indexOf(a.$vnode) - vnodes.indexOf(b.$vnode)
|
||||
);
|
||||
|
||||
this.parent.children = children;
|
||||
},
|
||||
|
@ -58,7 +58,8 @@ export const TouchMixin = Vue.extend({
|
||||
// avoid Vue 2.6 event bubble issues by manually binding events
|
||||
// https://github.com/youzan/vant/issues/3015
|
||||
bindTouchEvent(el: HTMLElement) {
|
||||
const { onTouchStart, onTouchMove, onTouchEnd } = (this as any);
|
||||
const { onTouchStart, onTouchMove, onTouchEnd } = this as any;
|
||||
|
||||
on(el, 'touchstart', onTouchStart);
|
||||
on(el, 'touchmove', onTouchMove);
|
||||
|
||||
|
@ -6,7 +6,7 @@ export type SharedPickerProps = {
|
||||
visibleItemCount: number;
|
||||
cancelButtonText?: string;
|
||||
confirmButtonText?: string;
|
||||
}
|
||||
};
|
||||
|
||||
export const pickerProps = {
|
||||
title: String,
|
||||
|
@ -16,14 +16,16 @@ export default {
|
||||
stock: '剩余',
|
||||
stockUnit: '件',
|
||||
quotaTip: (quota: number) => `每人限购${quota}件`,
|
||||
quotaUsedTip: (quota: number, count: number) => `每人限购${quota}件,你已购买${count}件`,
|
||||
quotaUsedTip: (quota: number, count: number) =>
|
||||
`每人限购${quota}件,你已购买${count}件`,
|
||||
},
|
||||
vanSkuActions: {
|
||||
buy: '立即购买',
|
||||
addCart: '加入购物车',
|
||||
},
|
||||
vanSkuImgUploader: {
|
||||
oversize: (maxSize: number) => `最大可上传图片为${maxSize}MB,请尝试压缩图片尺寸`,
|
||||
oversize: (maxSize: number) =>
|
||||
`最大可上传图片为${maxSize}MB,请尝试压缩图片尺寸`,
|
||||
fail: '上传失败<br />重新上传',
|
||||
},
|
||||
vanSkuStepper: {
|
||||
|
@ -48,7 +48,6 @@ const group3 = [
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
export const enUSData = [
|
||||
{
|
||||
text: 'Group 1',
|
||||
|
@ -4,7 +4,12 @@
|
||||
import '../../locale';
|
||||
import { camelize } from '../format/string';
|
||||
import { SlotsMixin } from '../../mixins/slots';
|
||||
import Vue, { VNode, VueConstructor, ComponentOptions, RenderContext } from 'vue';
|
||||
import Vue, {
|
||||
VNode,
|
||||
VueConstructor,
|
||||
ComponentOptions,
|
||||
RenderContext,
|
||||
} from 'vue';
|
||||
import { DefaultProps, FunctionComponent } from '../types';
|
||||
|
||||
export interface VantComponentOptions extends ComponentOptions<Vue> {
|
||||
@ -47,17 +52,20 @@ export function unifySlots(context: RenderContext) {
|
||||
}
|
||||
|
||||
// should be removed after Vue 3
|
||||
function transformFunctionComponent(pure: FunctionComponent): VantComponentOptions {
|
||||
function transformFunctionComponent(
|
||||
pure: FunctionComponent
|
||||
): VantComponentOptions {
|
||||
return {
|
||||
functional: true,
|
||||
props: pure.props,
|
||||
model: pure.model,
|
||||
render: (h, context): any => pure(h, context.props, unifySlots(context), context),
|
||||
render: (h, context): any =>
|
||||
pure(h, context.props, unifySlots(context), context),
|
||||
};
|
||||
}
|
||||
|
||||
export function createComponent(name: string) {
|
||||
return function<Props = DefaultProps, Events = {}, Slots = {}> (
|
||||
return function<Props = DefaultProps, Events = {}, Slots = {}>(
|
||||
sfc: VantComponentOptions | FunctionComponent
|
||||
): TsxComponent<Props, Events, Slots> {
|
||||
if (typeof sfc === 'function') {
|
||||
|
@ -6,7 +6,9 @@ export function createI18N(name: string) {
|
||||
const prefix = camelize(name) + '.';
|
||||
|
||||
return function(path: string, ...args: any[]): string {
|
||||
const message = get(locale.messages(), prefix + path) || get(locale.messages(), path);
|
||||
const messages = locale.messages();
|
||||
const message = get(messages, prefix + path) || get(messages, path);
|
||||
|
||||
return typeof message === 'function' ? message(...args) : message;
|
||||
};
|
||||
}
|
||||
|
@ -10,7 +10,11 @@ function assignKey(to: ObjectIndex, from: ObjectIndex, key: string) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasOwnProperty.call(to, key) || !isObj(val) || typeof val === 'function') {
|
||||
if (
|
||||
!hasOwnProperty.call(to, key) ||
|
||||
!isObj(val) ||
|
||||
typeof val === 'function'
|
||||
) {
|
||||
to[key] = val;
|
||||
} else {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
|
@ -15,7 +15,7 @@ if (!isServer) {
|
||||
},
|
||||
});
|
||||
window.addEventListener('test-passive', null as any, opts);
|
||||
// eslint-disable-next-line no-empty
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
@ -34,11 +34,7 @@ export function on(
|
||||
}
|
||||
}
|
||||
|
||||
export function off(
|
||||
target: EventTarget,
|
||||
event: string,
|
||||
handler: EventHandler
|
||||
) {
|
||||
export function off(target: EventTarget, event: string, handler: EventHandler) {
|
||||
if (!isServer) {
|
||||
target.removeEventListener(event, handler);
|
||||
}
|
||||
|
@ -4,41 +4,56 @@ type ScrollElement = HTMLElement | Window;
|
||||
// http://w3help.org/zh-cn/causes/SD9013
|
||||
// http://stackoverflow.com/questions/17016740/onscroll-function-is-not-working-for-chrome
|
||||
const overflowScrollReg = /scroll|auto/i;
|
||||
export function getScroller(element: HTMLElement, rootParent: ScrollElement = window) {
|
||||
let node = element;
|
||||
export function getScroller(el: HTMLElement, root: ScrollElement = window) {
|
||||
let node = el;
|
||||
|
||||
while (
|
||||
node &&
|
||||
node.tagName !== 'HTML' &&
|
||||
node.nodeType === 1 &&
|
||||
node !== rootParent
|
||||
node !== root
|
||||
) {
|
||||
const { overflowY } = window.getComputedStyle(node);
|
||||
|
||||
if (overflowScrollReg.test(<string>overflowY)) {
|
||||
if (node.tagName !== 'BODY') {
|
||||
return node;
|
||||
}
|
||||
|
||||
// see: https://github.com/youzan/vant/issues/3823
|
||||
const { overflowY: htmlOverflowY } = window.getComputedStyle(<Element>node.parentNode);
|
||||
const { overflowY: htmlOverflowY } = window.getComputedStyle(
|
||||
<Element>node.parentNode
|
||||
);
|
||||
|
||||
if (overflowScrollReg.test(<string>htmlOverflowY)) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
node = <HTMLElement>node.parentNode;
|
||||
}
|
||||
return rootParent;
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
export function getScrollTop(element: ScrollElement): number {
|
||||
return 'scrollTop' in element ? element.scrollTop : element.pageYOffset;
|
||||
export function getScrollTop(el: ScrollElement): number {
|
||||
return 'scrollTop' in el ? el.scrollTop : el.pageYOffset;
|
||||
}
|
||||
|
||||
export function setScrollTop(element: ScrollElement, value: number) {
|
||||
'scrollTop' in element ? (element.scrollTop = value) : element.scrollTo(element.scrollX, value);
|
||||
export function setScrollTop(el: ScrollElement, value: number) {
|
||||
if ('scrollTop' in el) {
|
||||
el.scrollTop = value;
|
||||
} else {
|
||||
el.scrollTo(el.scrollX, value);
|
||||
}
|
||||
}
|
||||
|
||||
export function getRootScrollTop(): number {
|
||||
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
||||
return (
|
||||
window.pageYOffset ||
|
||||
document.documentElement.scrollTop ||
|
||||
document.body.scrollTop ||
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
export function setRootScrollTop(value: number) {
|
||||
@ -47,19 +62,25 @@ export function setRootScrollTop(value: number) {
|
||||
}
|
||||
|
||||
// get distance from element top to page top
|
||||
export function getElementTop(element: ScrollElement) {
|
||||
return (
|
||||
(element === window ? 0 : (<HTMLElement>element).getBoundingClientRect().top) +
|
||||
getRootScrollTop()
|
||||
);
|
||||
export function getElementTop(el: ScrollElement) {
|
||||
if (el === window) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (el as HTMLElement).getBoundingClientRect().top + getRootScrollTop();
|
||||
}
|
||||
|
||||
export function getVisibleHeight(element: ScrollElement) {
|
||||
return element === window
|
||||
? element.innerHeight
|
||||
: (<HTMLElement>element).getBoundingClientRect().height;
|
||||
export function getVisibleHeight(el: ScrollElement) {
|
||||
if (el === window) {
|
||||
return el.innerHeight;
|
||||
}
|
||||
|
||||
return (el as HTMLElement).getBoundingClientRect().height;
|
||||
}
|
||||
|
||||
export function getVisibleTop(element: ScrollElement) {
|
||||
return element === window ? 0 : (<HTMLElement>element).getBoundingClientRect().top;
|
||||
export function getVisibleTop(el: ScrollElement) {
|
||||
if (el === window) {
|
||||
return 0;
|
||||
}
|
||||
return (el as HTMLElement).getBoundingClientRect().top;
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
export function isHidden(element: HTMLElement) {
|
||||
const style = window.getComputedStyle(element);
|
||||
const isHidden = style.display === 'none';
|
||||
export function isHidden(el: HTMLElement) {
|
||||
const style = window.getComputedStyle(el);
|
||||
const hidden = style.display === 'none';
|
||||
|
||||
// offsetParent returns null in the following situations:
|
||||
// 1. The element or its parent element has the display property set to none.
|
||||
// 2. The element has the position property set to fixed
|
||||
const isParentHidden = element.offsetParent === null && style.position !== 'fixed';
|
||||
const parentHidden = el.offsetParent === null && style.position !== 'fixed';
|
||||
|
||||
return isHidden || isParentHidden;
|
||||
return hidden || parentHidden;
|
||||
}
|
||||
|
@ -19,16 +19,16 @@ const inheritKey = [
|
||||
const mapInheritKey: ObjectIndex = { nativeOn: 'on' };
|
||||
|
||||
// inherit partial context, map nativeOn to on
|
||||
export function inherit(context: Context, inheritListeners?: boolean): InheritContext {
|
||||
const result = inheritKey.reduce(
|
||||
(obj, key) => {
|
||||
if (context.data[key]) {
|
||||
obj[mapInheritKey[key] || key] = context.data[key];
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
{} as InheritContext
|
||||
);
|
||||
export function inherit(
|
||||
context: Context,
|
||||
inheritListeners?: boolean
|
||||
): InheritContext {
|
||||
const result = inheritKey.reduce((obj, key) => {
|
||||
if (context.data[key]) {
|
||||
obj[mapInheritKey[key] || key] = context.data[key];
|
||||
}
|
||||
return obj;
|
||||
}, {} as InheritContext);
|
||||
|
||||
if (inheritListeners) {
|
||||
result.on = result.on || {};
|
||||
|
@ -5,7 +5,9 @@ export type EventHandler = (event: Event) => void;
|
||||
|
||||
export type ObjectIndex = Record<string, any>;
|
||||
|
||||
export type ScopedSlot<Props = any> = (props?: Props) => VNode[] | VNode | undefined;
|
||||
export type ScopedSlot<Props = any> = (
|
||||
props?: Props
|
||||
) => VNode[] | VNode | undefined;
|
||||
|
||||
export type DefaultSlots = {
|
||||
default?: ScopedSlot;
|
||||
@ -22,10 +24,16 @@ export type ModelOptions = {
|
||||
|
||||
export type DefaultProps = ObjectIndex;
|
||||
|
||||
export type FunctionComponent<Props = DefaultProps, PropDefs = PropsDefinition<Props>> = {
|
||||
(h: CreateElement, props: Props, slots: ScopedSlots, context: RenderContext<Props>):
|
||||
| VNode
|
||||
| undefined;
|
||||
export type FunctionComponent<
|
||||
Props = DefaultProps,
|
||||
PropDefs = PropsDefinition<Props>
|
||||
> = {
|
||||
(
|
||||
h: CreateElement,
|
||||
props: Props,
|
||||
slots: ScopedSlots,
|
||||
context: RenderContext<Props>
|
||||
): VNode | undefined;
|
||||
props?: PropDefs;
|
||||
model?: ModelOptions;
|
||||
inject?: InjectOptions;
|
||||
|
@ -2,6 +2,7 @@ import { isNaN } from './number';
|
||||
|
||||
export function isDate(date: Date): boolean {
|
||||
return (
|
||||
Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime())
|
||||
Object.prototype.toString.call(date) === '[object Date]' &&
|
||||
!isNaN(date.getTime())
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
export function isMobile(value: string): boolean {
|
||||
value = value.replace(/[^-|\d]/g, '');
|
||||
return /^((\+86)|(86))?(1)\d{10}$/.test(value) || /^0[0-9-]{10,13}$/.test(value);
|
||||
return (
|
||||
/^((\+86)|(86))?(1)\d{10}$/.test(value) || /^0[0-9-]{10,13}$/.test(value)
|
||||
);
|
||||
}
|
||||
|
@ -7,5 +7,7 @@ export function isAndroid(): boolean {
|
||||
|
||||
export function isIOS(): boolean {
|
||||
/* istanbul ignore next */
|
||||
return isServer ? false : /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
|
||||
return isServer
|
||||
? false
|
||||
: /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user