chore: migrate to useCustomFieldValue (#9201)

This commit is contained in:
neverland 2021-08-07 16:22:02 +08:00 committed by GitHub
parent 6de05f45d2
commit 1bfcbab2fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 113 additions and 103 deletions

View File

@ -6,8 +6,7 @@ import {
} from 'vue'; } from 'vue';
// Utils // Utils
import { createNamespace, extend } from '../utils'; import { createNamespace, BORDER_SURROUND, extend } from '../utils';
import { BORDER_SURROUND } from '../utils/constant';
import { useRoute, routeProps } from '../composables/use-route'; import { useRoute, routeProps } from '../composables/use-route';
// Components // Components

View File

@ -1,6 +1,5 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { truthProp, createNamespace } from '../utils'; import { truthProp, createNamespace, BORDER_TOP_BOTTOM } from '../utils';
import { BORDER_TOP_BOTTOM } from '../utils/constant';
const [name, bem] = createNamespace('cell-group'); const [name, bem] = createNamespace('cell-group');

View File

@ -10,9 +10,8 @@ import {
import { createNamespace } from '../utils'; import { createNamespace } from '../utils';
// Composables // Composables
import { useChildren } from '@vant/use'; import { useChildren, useCustomFieldValue } from '@vant/use';
import { useExpose } from '../composables/use-expose'; import { useExpose } from '../composables/use-expose';
import { useLinkField } from '../composables/use-link-field';
// Types // Types
import type { CheckerDirection } from '../checkbox/Checker'; import type { CheckerDirection } from '../checkbox/Checker';
@ -81,7 +80,7 @@ export default defineComponent({
); );
useExpose<CheckboxGroupExpose>({ toggleAll }); useExpose<CheckboxGroupExpose>({ toggleAll });
useLinkField(() => props.modelValue); useCustomFieldValue(() => props.modelValue);
linkChildren({ linkChildren({
props, props,
updateValue, updateValue,

View File

@ -5,9 +5,8 @@ import { createNamespace, extend, pick, truthProp } from '../utils';
import { CHECKBOX_GROUP_KEY } from '../checkbox-group/CheckboxGroup'; import { CHECKBOX_GROUP_KEY } from '../checkbox-group/CheckboxGroup';
// Composables // Composables
import { useParent } from '@vant/use'; import { useParent, useCustomFieldValue } from '@vant/use';
import { useExpose } from '../composables/use-expose'; import { useExpose } from '../composables/use-expose';
import { useLinkField } from '../composables/use-link-field';
// Components // Components
import Checker, { checkerProps } from './Checker'; import Checker, { checkerProps } from './Checker';
@ -82,7 +81,7 @@ export default defineComponent({
); );
useExpose<CheckboxExpose>({ toggle, props, checked }); useExpose<CheckboxExpose>({ toggle, props, checked });
useLinkField(() => props.modelValue); useCustomFieldValue(() => props.modelValue);
return () => ( return () => (
<Checker <Checker

View File

@ -1,6 +1,5 @@
import { PropType, defineComponent, InjectionKey } from 'vue'; import { PropType, defineComponent, InjectionKey } from 'vue';
import { truthProp, createNamespace } from '../utils'; import { truthProp, createNamespace, BORDER_TOP_BOTTOM } from '../utils';
import { BORDER_TOP_BOTTOM } from '../utils/constant';
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';
const [name, bem] = createNamespace('collapse'); const [name, bem] = createNamespace('collapse');

View File

@ -1,19 +0,0 @@
import { watch, inject, InjectionKey } from 'vue';
import type { FormProvide } from '../form/types';
import type { FieldProvide } from '../field/types';
export const FORM_KEY: InjectionKey<FormProvide> = Symbol('van-form');
export const FIELD_KEY: InjectionKey<FieldProvide> = Symbol('van-field');
export function useLinkField(getValue: () => unknown) {
const field = inject(FIELD_KEY, null);
if (field && !field.childFieldValue.value) {
field.childFieldValue.value = getValue;
watch(getValue, () => {
field.resetValidation();
field.validateWithTrigger('onChange');
});
}
}

View File

@ -7,11 +7,12 @@ import {
addUnit, addUnit,
truthProp, truthProp,
isFunction, isFunction,
BORDER_TOP,
BORDER_LEFT,
unknownProp, unknownProp,
callInterceptor,
createNamespace, createNamespace,
} from '../utils'; } from '../utils';
import { callInterceptor } from '../utils/interceptor';
import { BORDER_TOP, BORDER_LEFT } from '../utils/constant';
import { popupSharedProps, popupSharedPropKeys } from '../popup/shared'; import { popupSharedProps, popupSharedPropKeys } from '../popup/shared';
// Components // Components

View File

@ -1,6 +1,11 @@
import { App, CSSProperties, TeleportProps } from 'vue'; import { App, CSSProperties, TeleportProps } from 'vue';
import { inBrowser, ComponentInstance, withInstall, extend } from '../utils'; import {
import { Interceptor } from '../utils/interceptor'; extend,
inBrowser,
withInstall,
Interceptor,
ComponentInstance,
} from '../utils';
import { mountComponent, usePopupState } from '../utils/mount-component'; import { mountComponent, usePopupState } from '../utils/mount-component';
import VanDialog, { import VanDialog, {
DialogTheme, DialogTheme,

View File

@ -16,6 +16,7 @@ import {
isDef, isDef,
extend, extend,
addUnit, addUnit,
FORM_KEY,
unknownProp, unknownProp,
resetScroll, resetScroll,
formatNumber, formatNumber,
@ -34,9 +35,8 @@ import {
import { cellProps } from '../cell/Cell'; import { cellProps } from '../cell/Cell';
// Composables // Composables
import { useParent } from '@vant/use'; import { CUSTOM_FIELD_INJECTION_KEY, useParent } from '@vant/use';
import { useExpose } from '../composables/use-expose'; import { useExpose } from '../composables/use-expose';
import { FORM_KEY, FIELD_KEY } from '../composables/use-link-field';
// Components // Components
import { Icon } from '../icon'; import { Icon } from '../icon';
@ -146,7 +146,7 @@ export default defineComponent({
}); });
const inputRef = ref<HTMLInputElement>(); const inputRef = ref<HTMLInputElement>();
const childFieldValue = ref<() => unknown>(); const customValue = ref<() => unknown>();
const { parent: form } = useParent(FORM_KEY); const { parent: form } = useParent(FORM_KEY);
@ -176,8 +176,8 @@ export default defineComponent({
}); });
const formValue = computed(() => { const formValue = computed(() => {
if (childFieldValue.value && slots.input) { if (customValue.value && slots.input) {
return childFieldValue.value(); return customValue.value();
} }
return props.modelValue; return props.modelValue;
}); });
@ -522,8 +522,8 @@ export default defineComponent({
resetValidation, resetValidation,
}); });
provide(FIELD_KEY, { provide(CUSTOM_FIELD_INJECTION_KEY, {
childFieldValue, customValue,
resetValidation, resetValidation,
validateWithTrigger, validateWithTrigger,
}); });

View File

@ -1,4 +1,4 @@
import type { ComponentPublicInstance, ComputedRef, Ref } from 'vue'; import type { ComputedRef, ComponentPublicInstance } from 'vue';
import type { FieldProps } from './Field'; import type { FieldProps } from './Field';
export type FieldType = export type FieldType =
@ -40,12 +40,6 @@ export type FieldRule = {
formatter?: (value: any, rule: FieldRule) => string; formatter?: (value: any, rule: FieldRule) => string;
}; };
export type FieldProvide = {
childFieldValue: Ref<(() => unknown) | undefined>;
resetValidation: () => void;
validateWithTrigger: (trigger: FieldValidateTrigger) => void;
};
// Shared props of Field and Form // Shared props of Field and Form
export type FieldFormSharedProps = export type FieldFormSharedProps =
| 'colon' | 'colon'

View File

@ -1,11 +1,10 @@
import { PropType, defineComponent, ExtractPropTypes } from 'vue'; import { PropType, defineComponent, ExtractPropTypes } from 'vue';
// Utils // Utils
import { truthProp, createNamespace } from '../utils'; import { truthProp, FORM_KEY, createNamespace } from '../utils';
// Composables // Composables
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';
import { FORM_KEY } from '../composables/use-link-field';
import { useExpose } from '../composables/use-expose'; import { useExpose } from '../composables/use-expose';
// Types // Types

View File

@ -1,8 +1,7 @@
import { computed, CSSProperties, defineComponent } from 'vue'; import { computed, CSSProperties, defineComponent } from 'vue';
// Utils // Utils
import { createNamespace, addUnit, extend } from '../utils'; import { createNamespace, BORDER, addUnit, extend } from '../utils';
import { BORDER } from '../utils/constant';
import { GRID_KEY } from '../grid/Grid'; import { GRID_KEY } from '../grid/Grid';
// Composables // Composables

View File

@ -14,10 +14,11 @@ import {
pick, pick,
truthProp, truthProp,
unknownProp, unknownProp,
Interceptor,
callInterceptor,
createNamespace, createNamespace,
ComponentInstance, ComponentInstance,
} from '../utils'; } from '../utils';
import { callInterceptor, Interceptor } from '../utils/interceptor';
// Composables // Composables
import { useWindowSize } from '@vant/use'; import { useWindowSize } from '@vant/use';

View File

@ -1,7 +1,12 @@
import { App, CSSProperties, TeleportProps } from 'vue'; import { App, CSSProperties, TeleportProps } from 'vue';
import { ComponentInstance, extend, inBrowser, withInstall } from '../utils'; import {
extend,
inBrowser,
withInstall,
Interceptor,
ComponentInstance,
} from '../utils';
import { mountComponent, usePopupState } from '../utils/mount-component'; import { mountComponent, usePopupState } from '../utils/mount-component';
import { Interceptor } from '../utils/interceptor';
import { PopupCloseIconPosition } from '../popup'; import { PopupCloseIconPosition } from '../popup';
import VanImagePreview from './ImagePreview'; import VanImagePreview from './ImagePreview';

View File

@ -1,8 +1,12 @@
import { ref, reactive, computed, CSSProperties, defineComponent } from 'vue'; import { ref, reactive, computed, CSSProperties, defineComponent } from 'vue';
// Utils // Utils
import { createNamespace, extend, getZIndexStyle } from '../utils'; import {
import { BORDER_BOTTOM } from '../utils/constant'; extend,
BORDER_BOTTOM,
getZIndexStyle,
createNamespace,
} from '../utils';
import { INDEX_BAR_KEY } from '../index-bar/IndexBar'; import { INDEX_BAR_KEY } from '../index-bar/IndexBar';
import { getScrollTop, getRootScrollTop } from '../utils/dom/scroll'; import { getScrollTop, getRootScrollTop } from '../utils/dom/scroll';

View File

@ -1,8 +1,12 @@
import { ref, CSSProperties, defineComponent } from 'vue'; import { ref, CSSProperties, defineComponent } from 'vue';
// Utils // Utils
import { truthProp, createNamespace, getZIndexStyle } from '../utils'; import {
import { BORDER_BOTTOM } from '../utils/constant'; truthProp,
BORDER_BOTTOM,
getZIndexStyle,
createNamespace,
} from '../utils';
// Composables // Composables
import { usePlaceholder } from '../composables/use-placeholder'; import { usePlaceholder } from '../composables/use-placeholder';

View File

@ -1,6 +1,5 @@
import { computed, watch, PropType, defineComponent } from 'vue'; import { computed, watch, PropType, defineComponent } from 'vue';
import { createNamespace } from '../utils'; import { BORDER, createNamespace } from '../utils';
import { BORDER } from '../utils/constant';
const [name, bem, t] = createNamespace('pagination'); const [name, bem, t] = createNamespace('pagination');

View File

@ -1,6 +1,11 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { createNamespace, addUnit, truthProp } from '../utils'; import {
import { BORDER_LEFT, BORDER_SURROUND } from '../utils/constant'; addUnit,
truthProp,
BORDER_LEFT,
BORDER_SURROUND,
createNamespace,
} from '../utils';
const [name, bem] = createNamespace('password-input'); const [name, bem] = createNamespace('password-input');

View File

@ -14,8 +14,8 @@ import {
truthProp, truthProp,
preventDefault, preventDefault,
createNamespace, createNamespace,
BORDER_UNSET_TOP_BOTTOM,
} from '../utils'; } from '../utils';
import { BORDER_UNSET_TOP_BOTTOM } from '../utils/constant';
// Composables // Composables
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';

View File

@ -17,10 +17,10 @@ import {
extend, extend,
truthProp, truthProp,
unknownProp, unknownProp,
BORDER_BOTTOM,
createNamespace, createNamespace,
ComponentInstance, ComponentInstance,
} from '../utils'; } from '../utils';
import { BORDER_BOTTOM } from '../utils/constant';
// Composables // Composables
import { useClickAway } from '@vant/use'; import { useClickAway } from '@vant/use';

View File

@ -15,8 +15,7 @@ import {
// Utils // Utils
import { popupSharedProps } from './shared'; import { popupSharedProps } from './shared';
import { createNamespace, extend, isDef } from '../utils'; import { extend, isDef, callInterceptor, createNamespace } from '../utils';
import { callInterceptor } from '../utils/interceptor';
// Composables // Composables
import { useEventListener } from '@vant/use'; import { useEventListener } from '@vant/use';

View File

@ -1,6 +1,5 @@
import { PropType, CSSProperties, TeleportProps } from 'vue'; import { PropType, CSSProperties, TeleportProps } from 'vue';
import { truthProp, unknownProp } from '../utils'; import { truthProp, unknownProp, Interceptor } from '../utils';
import type { Interceptor } from '../utils/interceptor';
export const popupSharedProps = { export const popupSharedProps = {
// whether to show popup // whether to show popup

View File

@ -6,8 +6,7 @@ import {
ExtractPropTypes, ExtractPropTypes,
} from 'vue'; } from 'vue';
import { unknownProp, createNamespace } from '../utils'; import { unknownProp, createNamespace } from '../utils';
import { useChildren } from '@vant/use'; import { useChildren, useCustomFieldValue } from '@vant/use';
import { useLinkField } from '../composables/use-link-field';
import type { CheckerDirection } from '../checkbox/Checker'; import type { CheckerDirection } from '../checkbox/Checker';
const [name, bem] = createNamespace('radio-group'); const [name, bem] = createNamespace('radio-group');
@ -49,7 +48,7 @@ export default defineComponent({
updateValue, updateValue,
}); });
useLinkField(() => props.modelValue); useCustomFieldValue(() => props.modelValue);
return () => ( return () => (
<div class={bem([props.direction])} role="radiogroup"> <div class={bem([props.direction])} role="radiogroup">

View File

@ -4,9 +4,9 @@ import { computed, defineComponent } from 'vue';
import { addUnit, truthProp, createNamespace, preventDefault } from '../utils'; import { addUnit, truthProp, createNamespace, preventDefault } from '../utils';
// Composables // Composables
import { useCustomFieldValue } from '@vant/use';
import { useRefs } from '../composables/use-refs'; import { useRefs } from '../composables/use-refs';
import { useTouch } from '../composables/use-touch'; import { useTouch } from '../composables/use-touch';
import { useLinkField } from '../composables/use-link-field';
// Components // Components
import { Icon } from '../icon'; import { Icon } from '../icon';
@ -221,7 +221,7 @@ export default defineComponent({
); );
}; };
useLinkField(() => props.modelValue); useCustomFieldValue(() => props.modelValue);
return () => ( return () => (
<div <div

View File

@ -12,9 +12,8 @@ import {
} from '../utils'; } from '../utils';
// Composables // Composables
import { useRect } from '@vant/use'; import { useRect, useCustomFieldValue } from '@vant/use';
import { useTouch } from '../composables/use-touch'; import { useTouch } from '../composables/use-touch';
import { useLinkField } from '../composables/use-link-field';
const [name, bem] = createNamespace('slider'); const [name, bem] = createNamespace('slider');
@ -285,7 +284,7 @@ export default defineComponent({
// format initial value // format initial value
updateValue(props.modelValue); updateValue(props.modelValue);
useLinkField(() => props.modelValue); useCustomFieldValue(() => props.modelValue);
return () => ( return () => (
<div <div

View File

@ -1,8 +1,7 @@
import { computed, defineComponent } from 'vue'; import { computed, defineComponent } from 'vue';
// Utils // Utils
import { createNamespace } from '../utils'; import { BORDER, createNamespace } from '../utils';
import { BORDER } from '../utils/constant';
import { STEPS_KEY } from '../steps/Steps'; import { STEPS_KEY } from '../steps/Steps';
// Composables // Composables

View File

@ -7,15 +7,16 @@ import {
addNumber, addNumber,
truthProp, truthProp,
resetScroll, resetScroll,
Interceptor,
formatNumber, formatNumber,
getSizeStyle, getSizeStyle,
preventDefault, preventDefault,
createNamespace, createNamespace,
callInterceptor,
} from '../utils'; } from '../utils';
// Composables // Composables
import { useLinkField } from '../composables/use-link-field'; import { useCustomFieldValue } from '@vant/use';
import { Interceptor, callInterceptor } from '../utils/interceptor';
const [name, bem] = createNamespace('stepper'); const [name, bem] = createNamespace('stepper');
@ -291,7 +292,7 @@ export default defineComponent({
emit('change', value, { name: props.name }); emit('change', value, { name: props.name });
}); });
useLinkField(() => props.modelValue); useCustomFieldValue(() => props.modelValue);
return () => ( return () => (
<div class={bem([props.theme])}> <div class={bem([props.theme])}>

View File

@ -9,8 +9,14 @@ import {
} from 'vue'; } from 'vue';
// Utils // Utils
import { clamp, isDef, createNamespace, preventDefault } from '../utils'; import {
import { callInterceptor, Interceptor } from '../utils/interceptor'; clamp,
isDef,
Interceptor,
preventDefault,
callInterceptor,
createNamespace,
} from '../utils';
// Composables // Composables
import { useRect, useClickAway } from '@vant/use'; import { useRect, useClickAway } from '@vant/use';

View File

@ -1,6 +1,6 @@
import { defineComponent } from 'vue'; import { defineComponent } from 'vue';
import { createNamespace, addUnit, unknownProp } from '../utils'; import { createNamespace, addUnit, unknownProp } from '../utils';
import { useLinkField } from '../composables/use-link-field'; import { useCustomFieldValue } from '@vant/use';
import { Loading } from '../loading'; import { Loading } from '../loading';
const [name, bem] = createNamespace('switch'); const [name, bem] = createNamespace('switch');
@ -45,7 +45,7 @@ export default defineComponent({
} }
}; };
useLinkField(() => props.modelValue); useCustomFieldValue(() => props.modelValue);
return () => { return () => {
const { size, loading, disabled, activeColor, inactiveColor } = props; const { size, loading, disabled, activeColor, inactiveColor } = props;

View File

@ -7,9 +7,14 @@ import {
} from 'vue'; } from 'vue';
// Utils // Utils
import { truthProp, createNamespace, getZIndexStyle } from '../utils'; import {
import { BORDER_TOP_BOTTOM } from '../utils/constant'; truthProp,
import { callInterceptor, Interceptor } from '../utils/interceptor'; Interceptor,
getZIndexStyle,
createNamespace,
callInterceptor,
BORDER_TOP_BOTTOM,
} from '../utils';
// Composables // Composables
import { useChildren } from '@vant/use'; import { useChildren } from '@vant/use';

View File

@ -21,16 +21,17 @@ import {
isHidden, isHidden,
unitToPx, unitToPx,
truthProp, truthProp,
Interceptor,
getVisibleTop, getVisibleTop,
getElementTop, getElementTop,
callInterceptor,
createNamespace, createNamespace,
getVisibleHeight, getVisibleHeight,
setRootScrollTop, setRootScrollTop,
ComponentInstance, ComponentInstance,
BORDER_TOP_BOTTOM,
} from '../utils'; } from '../utils';
import { scrollLeftTo, scrollTopTo } from './utils'; import { scrollLeftTo, scrollTopTo } from './utils';
import { BORDER_TOP_BOTTOM } from '../utils/constant';
import { callInterceptor, Interceptor } from '../utils/interceptor';
// Composables // Composables
import { import {

View File

@ -12,6 +12,7 @@ import {
extend, extend,
isPromise, isPromise,
truthProp, truthProp,
Interceptor,
getSizeStyle, getSizeStyle,
ComponentInstance, ComponentInstance,
} from '../utils'; } from '../utils';
@ -26,8 +27,8 @@ import {
} from './utils'; } from './utils';
// Composables // Composables
import { useCustomFieldValue } from '@vant/use';
import { useExpose } from '../composables/use-expose'; import { useExpose } from '../composables/use-expose';
import { useLinkField } from '../composables/use-link-field';
// Components // Components
import { Icon } from '../icon'; import { Icon } from '../icon';
@ -36,7 +37,6 @@ import UploaderPreviewItem from './UploaderPreviewItem';
// Types // Types
import type { ImageFit } from '../image'; import type { ImageFit } from '../image';
import type { Interceptor } from '../utils/interceptor';
import type { import type {
UploaderExpose, UploaderExpose,
UploaderMaxSize, UploaderMaxSize,
@ -359,8 +359,7 @@ export default defineComponent({
chooseFile, chooseFile,
closeImagePreview, closeImagePreview,
}); });
useCustomFieldValue(() => props.modelValue);
useLinkField(() => props.modelValue);
return () => ( return () => (
<div class={bem()}> <div class={bem()}>

View File

@ -2,8 +2,13 @@ import { PropType, defineComponent } from 'vue';
// Utils // Utils
import { bem, isImageFile } from './utils'; import { bem, isImageFile } from './utils';
import { isDef, getSizeStyle, extend } from '../utils'; import {
import { callInterceptor, Interceptor } from '../utils/interceptor'; isDef,
extend,
Interceptor,
getSizeStyle,
callInterceptor,
} from '../utils';
// Components // Components
import { Icon } from '../icon'; import { Icon } from '../icon';

View File

@ -1,6 +1,6 @@
import type { ComponentPublicInstance } from 'vue'; import type { ComponentPublicInstance } from 'vue';
import type { ImageFit } from '../image'; import type { ImageFit } from '../image';
import type { Interceptor } from '../utils/interceptor'; import type { Interceptor } from '../utils';
import type { UploaderProps } from './Uploader'; import type { UploaderProps } from './Uploader';
export type UploaderResultType = 'dataUrl' | 'text' | 'file'; export type UploaderResultType = 'dataUrl' | 'text' | 'file';

View File

@ -1,4 +1,6 @@
// border import type { InjectionKey } from 'vue';
import type { FormProvide } from '../form/types';
export const BORDER = 'van-hairline'; export const BORDER = 'van-hairline';
export const BORDER_TOP = `${BORDER}--top`; export const BORDER_TOP = `${BORDER}--top`;
export const BORDER_LEFT = `${BORDER}--left`; export const BORDER_LEFT = `${BORDER}--left`;
@ -6,3 +8,5 @@ export const BORDER_BOTTOM = `${BORDER}--bottom`;
export const BORDER_SURROUND = `${BORDER}--surround`; export const BORDER_SURROUND = `${BORDER}--surround`;
export const BORDER_TOP_BOTTOM = `${BORDER}--top-bottom`; export const BORDER_TOP_BOTTOM = `${BORDER}--top-bottom`;
export const BORDER_UNSET_TOP_BOTTOM = `${BORDER}-unset--top-bottom`; export const BORDER_UNSET_TOP_BOTTOM = `${BORDER}-unset--top-bottom`;
export const FORM_KEY: InjectionKey<FormProvide> = Symbol('van-form');

View File

@ -1,10 +1,12 @@
export * from './base'; export * from './base';
export * from './create'; export * from './create';
export * from './constant';
export * from './validate'; export * from './validate';
export * from './dom/style';
export * from './dom/event';
export * from './dom/scroll';
export * from './interceptor';
export * from './with-install'; export * from './with-install';
export * from './format/unit'; export * from './format/unit';
export * from './format/number'; export * from './format/number';
export * from './format/string'; export * from './format/string';
export * from './dom/style';
export * from './dom/event';
export * from './dom/scroll';