mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 02:16:12 +08:00
[improvement] organize type definitions
This commit is contained in:
parent
96b1d8f81d
commit
7755b1738e
@ -7,7 +7,7 @@ import Popup from '../popup';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
import { PopupMixinProps } from '../mixins/popup/type';
|
import { PopupMixinProps } from '../mixins/popup/type';
|
||||||
|
|
||||||
export type ActionSheetItem = {
|
export type ActionSheetItem = {
|
||||||
|
@ -7,7 +7,7 @@ import Radio from '../radio';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type AddressItemData = {
|
export type AddressItemData = {
|
||||||
id: string | number;
|
id: string | number;
|
||||||
|
@ -6,7 +6,7 @@ import AddressItem, { AddressItemData } from './Item';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { ScopedSlot, DefaultSlots } from '../utils/use/sfc';
|
import { ScopedSlot, DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type AddressListProps = {
|
export type AddressListProps = {
|
||||||
value?: string | number;
|
value?: string | number;
|
||||||
|
@ -5,7 +5,7 @@ import Loading, { LoadingType } from '../loading';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type ButtonType = 'default' | 'primary' | 'info' | 'warning' | 'danger';
|
export type ButtonType = 'default' | 'primary' | 'info' | 'warning' | 'danger';
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import Tag from '../tag';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots, ScopedSlot } from '../utils/use/sfc';
|
import { DefaultSlots, ScopedSlot } from '../utils/types';
|
||||||
|
|
||||||
export type CardProps = {
|
export type CardProps = {
|
||||||
tag?: string;
|
tag?: string;
|
||||||
|
@ -3,7 +3,7 @@ import { inherit } from '../utils/functional';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type CellGroupProps = {
|
export type CellGroupProps = {
|
||||||
title?: string;
|
title?: string;
|
||||||
|
@ -6,7 +6,7 @@ import Icon from '../icon';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { ScopedSlot, DefaultSlots } from '../utils/use/sfc';
|
import { ScopedSlot, DefaultSlots } from '../utils/types';
|
||||||
import { Mods } from '../utils/use/bem';
|
import { Mods } from '../utils/use/bem';
|
||||||
|
|
||||||
export type CellProps = RouteProps &
|
export type CellProps = RouteProps &
|
||||||
|
@ -4,7 +4,7 @@ import Cell from '../cell';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
const [sfc, bem, t] = use('contact-card');
|
const [sfc, bem, t] = use('contact-card');
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import RadioGroup from '../radio-group';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type ContactListItem = {
|
export type ContactListItem = {
|
||||||
id: string | number;
|
id: string | number;
|
||||||
|
@ -4,7 +4,7 @@ import Cell from '../cell';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
import { Coupon } from '../coupon/shared';
|
import { Coupon } from '../coupon/shared';
|
||||||
|
|
||||||
export type CouponCellProps = {
|
export type CouponCellProps = {
|
||||||
|
@ -5,7 +5,7 @@ import { functionalRoute, routeProps, RouteProps } from '../utils/router';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type GoodsActionButtonProps = RouteProps & {
|
export type GoodsActionButtonProps = RouteProps & {
|
||||||
text?: string;
|
text?: string;
|
||||||
|
@ -5,7 +5,7 @@ import { functionalRoute, routeProps, RouteProps } from '../utils/router';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type GoodsActionIconProps = RouteProps & {
|
export type GoodsActionIconProps = RouteProps & {
|
||||||
icon: string;
|
icon: string;
|
||||||
|
@ -3,7 +3,7 @@ import { inherit } from '../utils/functional';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type GoodsActionProps = {
|
export type GoodsActionProps = {
|
||||||
safeAreaInsetBottom?: boolean;
|
safeAreaInsetBottom?: boolean;
|
||||||
|
@ -5,7 +5,7 @@ import { isSrc } from '../utils/validate/src';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type IconProps = {
|
export type IconProps = {
|
||||||
tag: keyof HTMLElementTagNameMap | string;
|
tag: keyof HTMLElementTagNameMap | string;
|
||||||
|
@ -3,7 +3,7 @@ import { inherit } from '../utils/functional';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type InfoProps = {
|
export type InfoProps = {
|
||||||
info?: string | number;
|
info?: string | number;
|
||||||
|
@ -3,7 +3,7 @@ import { inherit } from '../utils/functional';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type LoadingType = 'circular' | 'spinner';
|
export type LoadingType = 'circular' | 'spinner';
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import Icon from '../icon';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { ScopedSlot, DefaultSlots } from '../utils/use/sfc';
|
import { ScopedSlot, DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type NavBarProps = {
|
export type NavBarProps = {
|
||||||
title?: string;
|
title?: string;
|
||||||
|
@ -6,7 +6,7 @@ import Popup from '../popup';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
import { PopupMixinProps } from '../mixins/popup/type';
|
import { PopupMixinProps } from '../mixins/popup/type';
|
||||||
|
|
||||||
export type NotifyProps = PopupMixinProps & {
|
export type NotifyProps = PopupMixinProps & {
|
||||||
|
@ -4,7 +4,7 @@ import { preventDefault } from '../utils/event';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type OverlayProps = {
|
export type OverlayProps = {
|
||||||
zIndex?: number;
|
zIndex?: number;
|
||||||
|
@ -5,7 +5,7 @@ import { inherit } from '../utils/functional';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { ScopedSlot, DefaultSlots } from '../utils/use/sfc';
|
import { ScopedSlot, DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type PanelProps = {
|
export type PanelProps = {
|
||||||
icon?: string;
|
icon?: string;
|
||||||
|
@ -3,7 +3,7 @@ import { emit, inherit } from '../utils/functional';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type PasswordInputProps = {
|
export type PasswordInputProps = {
|
||||||
mask: boolean;
|
mask: boolean;
|
||||||
|
@ -6,7 +6,7 @@ import Icon from '../icon';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
const [sfc, bem] = use('rate');
|
const [sfc, bem] = use('rate');
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import Field from '../field';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots, ScopedSlot } from '../utils/use/sfc';
|
import { DefaultSlots, ScopedSlot } from '../utils/types';
|
||||||
|
|
||||||
const [sfc, bem, t] = use('search');
|
const [sfc, bem, t] = use('search');
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { inherit } from '../utils/functional';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type SkeletonProps = {
|
export type SkeletonProps = {
|
||||||
row: number;
|
row: number;
|
||||||
|
@ -4,7 +4,7 @@ import Button from '../../button';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import Vue, { CreateElement, RenderContext } from 'vue/types';
|
import Vue, { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../../utils/use/sfc';
|
import { DefaultSlots } from '../../utils/types';
|
||||||
|
|
||||||
export type SkuActionsProps = {
|
export type SkuActionsProps = {
|
||||||
buyText?: string;
|
buyText?: string;
|
||||||
|
@ -4,7 +4,7 @@ import Icon from '../../icon';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import Vue, { CreateElement, RenderContext } from 'vue/types';
|
import Vue, { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../../utils/use/sfc';
|
import { DefaultSlots } from '../../utils/types';
|
||||||
import { SkuData, SkuGoodsData, SelectedSkuData } from '../type';
|
import { SkuData, SkuGoodsData, SelectedSkuData } from '../type';
|
||||||
|
|
||||||
export type SkuHeaderProps = {
|
export type SkuHeaderProps = {
|
||||||
|
@ -3,7 +3,7 @@ import { inherit } from '../../utils/functional';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../../utils/use/sfc';
|
import { DefaultSlots } from '../../utils/types';
|
||||||
import { SkuTreeItemData } from '../type';
|
import { SkuTreeItemData } from '../type';
|
||||||
|
|
||||||
export type SkuRowProps = {
|
export type SkuRowProps = {
|
||||||
|
@ -5,7 +5,7 @@ import Icon from '../icon';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { ScopedSlot, DefaultSlots } from '../utils/use/sfc';
|
import { ScopedSlot, DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type SubmitBarProps = {
|
export type SubmitBarProps = {
|
||||||
tip?: string;
|
tip?: string;
|
||||||
|
@ -6,7 +6,7 @@ import { switchProps, SharedSwitchProps } from '../switch/shared';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type SwitchCellProps = SharedSwitchProps & {
|
export type SwitchCellProps = SharedSwitchProps & {
|
||||||
size: string;
|
size: string;
|
||||||
|
@ -6,7 +6,7 @@ import Loading from '../loading';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type SwitchEvents = {
|
export type SwitchEvents = {
|
||||||
onChange?(checked: boolean): void;
|
onChange?(checked: boolean): void;
|
||||||
|
@ -4,7 +4,7 @@ import { RED, BLUE, GREEN, GRAY_DARK } from '../utils/color';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type TagType = 'primary' | 'success' | 'danger';
|
export type TagType = 'primary' | 'success' | 'danger';
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import Icon from '../icon';
|
|||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CreateElement, RenderContext } from 'vue/types';
|
import { CreateElement, RenderContext } from 'vue/types';
|
||||||
import { DefaultSlots } from '../utils/use/sfc';
|
import { DefaultSlots } from '../utils/types';
|
||||||
|
|
||||||
export type TreeSelectItem = {
|
export type TreeSelectItem = {
|
||||||
text: string;
|
text: string;
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
/* eslint-disable no-use-before-define */
|
/* eslint-disable no-use-before-define */
|
||||||
import { isDef, isObj } from '.';
|
import { isDef, isObj } from '.';
|
||||||
|
import { ObjectIndex } from './types';
|
||||||
|
|
||||||
const { hasOwnProperty } = Object.prototype;
|
const { hasOwnProperty } = Object.prototype;
|
||||||
|
|
||||||
type Object = {
|
function assignKey(to: ObjectIndex, from: ObjectIndex, key: string) {
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
function assignKey(to: Object, from: Object, key: string) {
|
|
||||||
const val = from[key];
|
const val = from[key];
|
||||||
|
|
||||||
if (!isDef(val)) {
|
if (!isDef(val)) {
|
||||||
@ -21,7 +18,7 @@ function assignKey(to: Object, from: Object, key: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deepAssign(to: Object, from: Object) {
|
export function deepAssign(to: ObjectIndex, from: ObjectIndex): ObjectIndex {
|
||||||
Object.keys(from).forEach(key => {
|
Object.keys(from).forEach(key => {
|
||||||
assignKey(to, from, key);
|
assignKey(to, from, key);
|
||||||
});
|
});
|
||||||
|
@ -4,8 +4,10 @@ export function deepClone(obj: object): object {
|
|||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
return obj.map(item => deepClone(item));
|
return obj.map(item => deepClone(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof obj === 'object') {
|
if (typeof obj === 'object') {
|
||||||
return deepAssign({}, obj);
|
return deepAssign({}, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
/* eslint-disable getter-return */
|
/* eslint-disable getter-return */
|
||||||
/* eslint-disable import/no-mutable-exports */
|
/* eslint-disable import/no-mutable-exports */
|
||||||
import { isServer } from '.';
|
import { isServer } from '.';
|
||||||
|
import { EventHanlder } from './types';
|
||||||
type EventHanlder = (event?: Event) => void;
|
|
||||||
|
|
||||||
export let supportsPassive = false;
|
export let supportsPassive = false;
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import Vue, { RenderContext, VNodeData } from 'vue';
|
import Vue, { RenderContext, VNodeData } from 'vue';
|
||||||
|
import { ObjectIndex } from './types';
|
||||||
type ObjectIndex = {
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Context = RenderContext & { data: VNodeData & ObjectIndex };
|
type Context = RenderContext & { data: VNodeData & ObjectIndex };
|
||||||
|
|
||||||
@ -22,10 +19,7 @@ const inheritKey = [
|
|||||||
const mapInheritKey: ObjectIndex = { nativeOn: 'on' };
|
const mapInheritKey: ObjectIndex = { nativeOn: 'on' };
|
||||||
|
|
||||||
// inherit partial context, map nativeOn to on
|
// inherit partial context, map nativeOn to on
|
||||||
export function inherit(
|
export function inherit(context: Context, inheritListeners?: boolean): InheritContext {
|
||||||
context: Context,
|
|
||||||
inheritListeners?: boolean
|
|
||||||
): InheritContext {
|
|
||||||
const result = inheritKey.reduce(
|
const result = inheritKey.reduce(
|
||||||
(obj, key) => {
|
(obj, key) => {
|
||||||
if (context.data[key]) {
|
if (context.data[key]) {
|
||||||
|
34
packages/utils/types.ts
Normal file
34
packages/utils/types.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { VNode, CreateElement, RenderContext } from 'vue';
|
||||||
|
import { InjectOptions, PropsDefinition } from 'vue/types/options';
|
||||||
|
|
||||||
|
export type EventHanlder = (eventName?: Event) => void;
|
||||||
|
|
||||||
|
export type ObjectIndex = {
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ScopedSlot<Props = any> = (props?: Props) => VNode[] | VNode | undefined;
|
||||||
|
|
||||||
|
export type DefaultSlots = {
|
||||||
|
default?: ScopedSlot;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ScopedSlots = DefaultSlots & {
|
||||||
|
[key: string]: ScopedSlot | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ModelOptions = {
|
||||||
|
prop?: string;
|
||||||
|
event?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type DefaultProps = Record<string, any>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
@ -36,7 +36,8 @@ function prefix(name: string, mods: Mods): Mods {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useBEM = (name: string) => (el?: Mods, mods?: Mods): Mods => {
|
export function useBEM(name: string) {
|
||||||
|
return function (el?: Mods, mods?: Mods): Mods {
|
||||||
if (el && typeof el !== 'string') {
|
if (el && typeof el !== 'string') {
|
||||||
mods = el;
|
mods = el;
|
||||||
el = '';
|
el = '';
|
||||||
@ -45,3 +46,4 @@ export const useBEM = (name: string) => (el?: Mods, mods?: Mods): Mods => {
|
|||||||
|
|
||||||
return mods ? [el, prefix(el, mods)] : el;
|
return mods ? [el, prefix(el, mods)] : el;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { get, camelize } from '..';
|
import { get, camelize } from '..';
|
||||||
import locale from '../../locale';
|
import locale from '../../locale';
|
||||||
|
|
||||||
export const useI18N = (name: string) => {
|
export function useI18N(name: string) {
|
||||||
const prefix = camelize(name) + '.';
|
const prefix = camelize(name) + '.';
|
||||||
return (path: string, ...args: any[]): string => {
|
|
||||||
|
return function (path: string, ...args: any[]): string {
|
||||||
const message = get(locale.messages(), prefix + path) || get(locale.messages(), path);
|
const message = get(locale.messages(), prefix + path) || get(locale.messages(), path);
|
||||||
return typeof message === 'function' ? message(...args) : message;
|
return typeof message === 'function' ? message(...args) : message;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
@ -4,52 +4,14 @@
|
|||||||
import '../../locale';
|
import '../../locale';
|
||||||
import { camelize } from '..';
|
import { camelize } from '..';
|
||||||
import { SlotsMixin } from '../../mixins/slots';
|
import { SlotsMixin } from '../../mixins/slots';
|
||||||
import Vue, {
|
import Vue, { VNode, VueConstructor, ComponentOptions, RenderContext } from 'vue';
|
||||||
VNode,
|
import { DefaultProps, FunctionComponent } from '../types';
|
||||||
VueConstructor,
|
|
||||||
ComponentOptions,
|
|
||||||
CreateElement,
|
|
||||||
RenderContext
|
|
||||||
} from 'vue';
|
|
||||||
import { InjectOptions, PropsDefinition } from 'vue/types/options';
|
|
||||||
|
|
||||||
export type ScopedSlot<Props = any> = (props?: Props) => VNode[] | VNode | undefined;
|
|
||||||
|
|
||||||
export type DefaultSlots = {
|
|
||||||
default?: ScopedSlot;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ScopedSlots = DefaultSlots & {
|
|
||||||
[key: string]: ScopedSlot | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ModelOptions = {
|
|
||||||
prop?: string;
|
|
||||||
event?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface VantComponentOptions extends ComponentOptions<Vue> {
|
export interface VantComponentOptions extends ComponentOptions<Vue> {
|
||||||
functional?: boolean;
|
functional?: boolean;
|
||||||
install?: (Vue: VueConstructor) => void;
|
install?: (Vue: VueConstructor) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DefaultProps = Record<string, any>;
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type TsxBaseProps<Slots> = {
|
export type TsxBaseProps<Slots> = {
|
||||||
key: string | number;
|
key: string | number;
|
||||||
// hack for jsx prop spread
|
// hack for jsx prop spread
|
||||||
@ -105,21 +67,19 @@ export function unifySlots(context: RenderContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// should be removed after Vue 3
|
// should be removed after Vue 3
|
||||||
function transformFunctionComponent(
|
function transformFunctionComponent(pure: FunctionComponent): VantComponentOptions {
|
||||||
pure: FunctionComponent
|
|
||||||
): VantComponentOptions {
|
|
||||||
return {
|
return {
|
||||||
functional: true,
|
functional: true,
|
||||||
props: pure.props,
|
props: pure.props,
|
||||||
model: pure.model,
|
model: pure.model,
|
||||||
render: (h, context): any =>
|
render: (h, context): any => pure(h, context.props, unifySlots(context), context)
|
||||||
pure(h, context.props, unifySlots(context), context)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useSFC = (name: string) => <Props = DefaultProps, Events = {}, Slots = {}>(
|
export function useSFC(name: string) {
|
||||||
|
return function<Props = DefaultProps, Events = {}, Slots = {}> (
|
||||||
sfc: VantComponentOptions | FunctionComponent
|
sfc: VantComponentOptions | FunctionComponent
|
||||||
): TsxComponent<Props, Events, Slots> => {
|
): TsxComponent<Props, Events, Slots> {
|
||||||
if (typeof sfc === 'function') {
|
if (typeof sfc === 'function') {
|
||||||
sfc = transformFunctionComponent(sfc);
|
sfc = transformFunctionComponent(sfc);
|
||||||
}
|
}
|
||||||
@ -138,3 +98,4 @@ export const useSFC = (name: string) => <Props = DefaultProps, Events = {}, Slot
|
|||||||
|
|
||||||
return sfc as TsxComponent<Props, Events, Slots>;
|
return sfc as TsxComponent<Props, Events, Slots>;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user