[improvement] unify mixin name (#2795)
This commit is contained in:
@@ -17,11 +17,11 @@ function assignKey(to: Object, from: Object, key: string) {
|
||||
if (!hasOwnProperty.call(to, key) || !isObj(val)) {
|
||||
to[key] = val;
|
||||
} else {
|
||||
to[key] = assign(Object(to[key]), from[key]);
|
||||
to[key] = deepAssign(Object(to[key]), from[key]);
|
||||
}
|
||||
}
|
||||
|
||||
export default function assign(to: Object, from: Object) {
|
||||
export function deepAssign(to: Object, from: Object) {
|
||||
Object.keys(from).forEach(key => {
|
||||
assignKey(to, from, key);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import deepAssign from './deep-assign';
|
||||
import { deepAssign } from './deep-assign';
|
||||
|
||||
export default function deepClone(obj: object): object {
|
||||
export function deepClone(obj: object): object {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(item => deepClone(item));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Vue Router support
|
||||
*/
|
||||
|
||||
import { RenderContext } from 'vue/types';
|
||||
import VueRouter, { RawLocation } from 'vue-router/types';
|
||||
|
||||
export type RouteConfig = {
|
||||
url?: string;
|
||||
to?: RawLocation;
|
||||
replace?: boolean;
|
||||
};
|
||||
|
||||
export function route(router: VueRouter, config: RouteConfig) {
|
||||
const { to, url, replace } = config;
|
||||
if (to && router) {
|
||||
router[replace ? 'replace' : 'push'](to);
|
||||
} else if (url) {
|
||||
replace ? location.replace(url) : (location.href = url);
|
||||
}
|
||||
}
|
||||
|
||||
export function functionalRoute(context: RenderContext) {
|
||||
route(context.parent && context.parent.$router, context.props);
|
||||
}
|
||||
|
||||
export type RouteProps = {
|
||||
url?: string,
|
||||
replace?: boolean;
|
||||
to?: RawLocation;
|
||||
}
|
||||
|
||||
export const routeProps = {
|
||||
url: String,
|
||||
replace: Boolean,
|
||||
to: [String, Object]
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
import deepClone from '../deep-clone';
|
||||
import { deepClone } from '../deep-clone';
|
||||
import { isAndroid, isDef, camelize, get } from '..';
|
||||
import { raf, cancel } from '../raf';
|
||||
import { later } from '../../../test/utils';
|
||||
import isSrc from '../validate/src';
|
||||
import isEmail from '../validate/email';
|
||||
import isMobile from '../validate/mobile';
|
||||
import isNumber from '../validate/number';
|
||||
import { isSrc } from '../validate/src';
|
||||
import { isEmail } from '../validate/email';
|
||||
import { isMobile } from '../validate/mobile';
|
||||
import { isNumber } from '../validate/number';
|
||||
|
||||
test('deepClone', () => {
|
||||
const a = { foo: 0 };
|
||||
|
||||
@@ -36,7 +36,7 @@ function prefix(name: string, mods: Mods): Mods {
|
||||
return ret;
|
||||
}
|
||||
|
||||
export default (name: string) => (el?: Mods, mods?: Mods): Mods => {
|
||||
export const useBEM = (name: string) => (el?: Mods, mods?: Mods): Mods => {
|
||||
if (el && typeof el !== 'string') {
|
||||
mods = el;
|
||||
el = '';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { get, camelize } from '..';
|
||||
import locale from '../../locale';
|
||||
|
||||
export default (name: string) => {
|
||||
export const useI18N = (name: string) => {
|
||||
const prefix = camelize(name) + '.';
|
||||
return (path: string, ...args: any[]): string => {
|
||||
const message = get(locale.messages(), prefix + path) || get(locale.messages(), path);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import useBem from './bem';
|
||||
import useSfc from './sfc';
|
||||
import useI18n from './i18n';
|
||||
import { useBEM } from './bem';
|
||||
import { useSFC } from './sfc';
|
||||
import { useI18N } from './i18n';
|
||||
|
||||
type UseReturn = [
|
||||
ReturnType<typeof useSfc>,
|
||||
ReturnType<typeof useBem>,
|
||||
ReturnType<typeof useI18n>
|
||||
ReturnType<typeof useSFC>,
|
||||
ReturnType<typeof useBEM>,
|
||||
ReturnType<typeof useI18N>
|
||||
];
|
||||
|
||||
export function use(name: string): UseReturn {
|
||||
name = 'van-' + name;
|
||||
return [useSfc(name), useBem(name), useI18n(name)];
|
||||
return [useSFC(name), useBEM(name), useI18N(name)];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import '../../locale';
|
||||
import { camelize } from '..';
|
||||
import SlotsMixin from '../../mixins/slots';
|
||||
import { SlotsMixin } from '../../mixins/slots';
|
||||
import Vue, {
|
||||
VueConstructor,
|
||||
ComponentOptions,
|
||||
@@ -35,7 +35,7 @@ export interface VantComponentOptions extends ComponentOptions<Vue> {
|
||||
|
||||
export type DefaultProps = Record<string, any>;
|
||||
|
||||
export type FunctionalComponent<
|
||||
export type FunctionComponent<
|
||||
Props = DefaultProps,
|
||||
PropDefs = PropsDefinition<Props>
|
||||
> = {
|
||||
@@ -93,6 +93,7 @@ function install(this: ComponentOptions<Vue>, Vue: VueConstructor) {
|
||||
|
||||
// unify slots & scopedSlots
|
||||
export function unifySlots(context: RenderContext) {
|
||||
// use data.scopedSlots in lower Vue version
|
||||
const scopedSlots = context.scopedSlots || context.data.scopedSlots || {};
|
||||
const slots = context.slots();
|
||||
|
||||
@@ -105,8 +106,9 @@ export function unifySlots(context: RenderContext) {
|
||||
return scopedSlots;
|
||||
}
|
||||
|
||||
function transformFunctionalComponent(
|
||||
pure: FunctionalComponent
|
||||
// should be removed after Vue 3
|
||||
function transformFunctionComponent(
|
||||
pure: FunctionComponent
|
||||
): VantComponentOptions {
|
||||
return {
|
||||
functional: true,
|
||||
@@ -117,11 +119,11 @@ function transformFunctionalComponent(
|
||||
};
|
||||
}
|
||||
|
||||
export default (name: string) => <Props = DefaultProps, Events = {}, Slots = {}>(
|
||||
sfc: VantComponentOptions | FunctionalComponent
|
||||
export const useSFC = (name: string) => <Props = DefaultProps, Events = {}, Slots = {}>(
|
||||
sfc: VantComponentOptions | FunctionComponent
|
||||
): TsxComponent<Props, Events, Slots> => {
|
||||
if (typeof sfc === 'function') {
|
||||
sfc = transformFunctionalComponent(sfc);
|
||||
sfc = transformFunctionComponent(sfc);
|
||||
}
|
||||
|
||||
if (!sfc.functional) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable */
|
||||
export default function email(value: string): boolean {
|
||||
export function isEmail(value: string): boolean {
|
||||
const reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
||||
return reg.test(value);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default function mobile(value: string): boolean {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default function number(value: string): boolean {
|
||||
export function isNumber(value: string): boolean {
|
||||
return /^\d+$/.test(value);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Is image source
|
||||
*/
|
||||
export default function src(url: string): boolean {
|
||||
export function isSrc(url: string): boolean {
|
||||
return /^(https?:)?\/\/|data:image/.test(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user