style: format file

pull/3131/head^2
tangjinzhou 2020-11-07 15:37:17 +08:00
parent bd1f42a5ef
commit a13dd20f58
46 changed files with 302 additions and 304 deletions

View File

@ -10,7 +10,7 @@
"parserOptions": { "parserOptions": {
"parser": "babel-eslint" "parser": "babel-eslint"
}, },
"extends": ["plugin:vue/recommended", "prettier"], "extends": ["plugin:vue/vue3-recommended", "prettier"],
"plugins": ["markdown"], "plugins": ["markdown"],
"overrides": [ "overrides": [
{ {

View File

@ -29,9 +29,6 @@ export default defineComponent({
openCount = visible ? openCount + 1 : openCount; openCount = visible ? openCount + 1 : openCount;
return {}; return {};
}, },
updated() {
this.setWrapperClassName();
},
watch: { watch: {
visible(val) { visible(val) {
openCount = val ? openCount + 1 : openCount - 1; openCount = val ? openCount + 1 : openCount - 1;
@ -48,6 +45,9 @@ export default defineComponent({
} }
}, },
}, },
updated() {
this.setWrapperClassName();
},
beforeUnmount() { beforeUnmount() {
const { visible } = this.$props; const { visible } = this.$props;
// 离开时不会 render 导到离开时数值不变,改用 func 。。 // 离开时不会 render 导到离开时数值不变,改用 func 。。

View File

@ -23,6 +23,12 @@ function isNotGrey(color) {
export default defineComponent({ export default defineComponent({
name: 'Wave', name: 'Wave',
props: ['insertExtraNode'], props: ['insertExtraNode'],
setup() {
const configProvider = inject('configProvider', defaultConfigProvider);
return {
configProvider,
};
},
mounted() { mounted() {
nextTick(() => { nextTick(() => {
const node = findDOMNode(this); const node = findDOMNode(this);
@ -32,12 +38,6 @@ export default defineComponent({
this.instance = this.bindAnimationEvent(node); this.instance = this.bindAnimationEvent(node);
}); });
}, },
setup() {
const configProvider = inject('configProvider', defaultConfigProvider);
return {
configProvider,
};
},
beforeUnmount() { beforeUnmount() {
if (this.instance) { if (this.instance) {
this.instance.cancel(); this.instance.cancel();

View File

@ -50,14 +50,14 @@ const AffixProps = {
}; };
const Affix = defineComponent({ const Affix = defineComponent({
name: 'AAffix', name: 'AAffix',
props: AffixProps,
mixins: [BaseMixin], mixins: [BaseMixin],
props: AffixProps,
emits: ['change', 'testUpdatePosition'],
setup() { setup() {
return { return {
configProvider: inject('configProvider', defaultConfigProvider), configProvider: inject('configProvider', defaultConfigProvider),
}; };
}, },
emits: ['change', 'testUpdatePosition'],
data() { data() {
return { return {
affixStyle: undefined, affixStyle: undefined,
@ -68,25 +68,6 @@ const Affix = defineComponent({
timeout: null, timeout: null,
}; };
}, },
beforeMount() {
this.updatePosition = throttleByAnimationFrame(this.updatePosition);
this.lazyUpdatePosition = throttleByAnimationFrame(this.lazyUpdatePosition);
},
mounted() {
const { target } = this;
if (target) {
// [Legacy] Wait for parent component ref has its value.
// We should use target as directly element instead of function which makes element check hard.
this.timeout = setTimeout(() => {
addObserveTarget(target(), this);
// Mock Event object.
this.updatePosition();
});
}
},
updated() {
this.measure();
},
watch: { watch: {
target(val) { target(val) {
let newTarget = null; let newTarget = null;
@ -110,6 +91,25 @@ const Affix = defineComponent({
this.updatePosition(); this.updatePosition();
}, },
}, },
beforeMount() {
this.updatePosition = throttleByAnimationFrame(this.updatePosition);
this.lazyUpdatePosition = throttleByAnimationFrame(this.lazyUpdatePosition);
},
mounted() {
const { target } = this;
if (target) {
// [Legacy] Wait for parent component ref has its value.
// We should use target as directly element instead of function which makes element check hard.
this.timeout = setTimeout(() => {
addObserveTarget(target(), this);
// Mock Event object.
this.updatePosition();
});
}
},
updated() {
this.measure();
},
beforeUnmount() { beforeUnmount() {
clearTimeout(this.timeout); clearTimeout(this.timeout);
removeObserveTarget(this); removeObserveTarget(this);

View File

@ -59,9 +59,9 @@ export const AlertProps = {
const Alert = defineComponent({ const Alert = defineComponent({
name: 'AAlert', name: 'AAlert',
mixins: [BaseMixin],
inheritAttrs: false, inheritAttrs: false,
props: AlertProps, props: AlertProps,
mixins: [BaseMixin],
emits: ['close'], emits: ['close'],
setup() { setup() {
return { return {

View File

@ -81,6 +81,11 @@ export default defineComponent({
inheritAttrs: false, inheritAttrs: false,
props: AnchorProps, props: AnchorProps,
emits: ['change', 'click'], emits: ['change', 'click'],
setup() {
return {
configProvider: inject('configProvider', defaultConfigProvider),
};
},
data() { data() {
// this.links = []; // this.links = [];
// this.sPrefixCls = ''; // this.sPrefixCls = '';
@ -111,11 +116,6 @@ export default defineComponent({
} as AntAnchor); } as AntAnchor);
provide('antAnchorContext', this); provide('antAnchorContext', this);
}, },
setup() {
return {
configProvider: inject('configProvider', defaultConfigProvider),
};
},
mounted() { mounted() {
nextTick(() => { nextTick(() => {
const { getContainer } = this; const { getContainer } = this;

View File

@ -18,8 +18,8 @@ const props = backTopTypes();
const BackTop = defineComponent({ const BackTop = defineComponent({
name: 'ABackTop', name: 'ABackTop',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
emits: ['click'], emits: ['click'],
props: { props: {
...props, ...props,

View File

@ -51,8 +51,8 @@ export const CalendarProps = {
const Calendar = defineComponent({ const Calendar = defineComponent({
name: 'ACalendar', name: 'ACalendar',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
props: CalendarProps, props: CalendarProps,
setup() { setup() {
return { return {

View File

@ -201,17 +201,10 @@ function flattenTree(
const defaultDisplayRender = ({ labels }) => labels.join(' / '); const defaultDisplayRender = ({ labels }) => labels.join(' / ');
const Cascader = defineComponent({ const Cascader = defineComponent({
inheritAttrs: false,
name: 'ACascader', name: 'ACascader',
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
props: CascaderProps, props: CascaderProps,
// model: {
// prop: 'value',
// event: 'change',
// },
created() {
provide('savePopupRef', this.savePopupRef);
},
setup() { setup() {
return { return {
configProvider: inject('configProvider', defaultConfigProvider), configProvider: inject('configProvider', defaultConfigProvider),
@ -244,6 +237,13 @@ const Cascader = defineComponent({
} }
}, },
}, },
// model: {
// prop: 'value',
// event: 'change',
// },
created() {
provide('savePopupRef', this.savePopupRef);
},
methods: { methods: {
savePopupRef(ref: any) { savePopupRef(ref: any) {
this.popupRef = ref; this.popupRef = ref;

View File

@ -25,6 +25,11 @@ export default defineComponent({
disabled: PropTypes.looseBool, disabled: PropTypes.looseBool,
onChange: PropTypes.func, onChange: PropTypes.func,
}, },
setup() {
return {
configProvider: inject('configProvider', defaultConfigProvider),
};
},
data() { data() {
const { value, defaultValue } = this; const { value, defaultValue } = this;
@ -38,11 +43,6 @@ export default defineComponent({
this.sValue = val || []; this.sValue = val || [];
}, },
}, },
setup() {
return {
configProvider: inject('configProvider', defaultConfigProvider),
};
},
created() { created() {
provide('checkboxGroupContext', this); provide('checkboxGroupContext', this);
}, },

View File

@ -31,8 +31,8 @@ export default function createPicker<P>(
name: string, name: string,
): DefineComponent<any> { ): DefineComponent<any> {
return defineComponent({ return defineComponent({
inheritAttrs: false,
name, name,
inheritAttrs: false,
props: { props: {
...props, ...props,
allowClear: PropTypes.looseBool.def(true), allowClear: PropTypes.looseBool.def(true),

View File

@ -66,6 +66,11 @@ export default function wrapPicker<P>(
popupRef: undefined, popupRef: undefined,
}; };
}, },
watch: {
value(val) {
checkValidate('DatePicker', val, 'value', this.valueFormat);
},
},
created() { created() {
provide('savePopupRef', this.savePopupRef); provide('savePopupRef', this.savePopupRef);
}, },
@ -79,11 +84,6 @@ export default function wrapPicker<P>(
}); });
} }
}, },
watch: {
value(val) {
checkValidate('DatePicker', val, 'value', this.valueFormat);
},
},
methods: { methods: {
savePicker(node: any) { savePicker(node: any) {
this.picker = node; this.picker = node;

View File

@ -41,11 +41,6 @@ const Drawer = defineComponent({
'onUpdate:visible': PropTypes.func, 'onUpdate:visible': PropTypes.func,
}, },
mixins: [BaseMixin], mixins: [BaseMixin],
data() {
return {
sPush: false,
};
},
setup(props) { setup(props) {
const configProvider = inject('configProvider', defaultConfigProvider); const configProvider = inject('configProvider', defaultConfigProvider);
return { return {
@ -55,6 +50,11 @@ const Drawer = defineComponent({
parentDrawer: inject('parentDrawer', null), parentDrawer: inject('parentDrawer', null),
}; };
}, },
data() {
return {
sPush: false,
};
},
beforeCreate() { beforeCreate() {
provide('parentDrawer', this); provide('parentDrawer', this);
}, },

View File

@ -76,9 +76,6 @@ const Form = defineComponent({
colon: true, colon: true,
}), }),
Item: FormItem, Item: FormItem,
created() {
provide('FormContext', this);
},
setup(props) { setup(props) {
return { return {
configProvider: inject('configProvider', defaultConfigProvider), configProvider: inject('configProvider', defaultConfigProvider),
@ -95,6 +92,9 @@ const Form = defineComponent({
} }
}, },
}, },
created() {
provide('FormContext', this);
},
methods: { methods: {
addField(field: any) { addField(field: any) {
if (field) { if (field) {

View File

@ -30,22 +30,9 @@ const TextAreaProps = {
const ResizableTextArea = defineComponent({ const ResizableTextArea = defineComponent({
name: 'ResizableTextArea', name: 'ResizableTextArea',
mixins: [BaseMixin],
inheritAttrs: false, inheritAttrs: false,
props: TextAreaProps, props: TextAreaProps,
data() {
return {
textareaStyles: {},
resizeStatus: RESIZE_STATUS_NONE,
};
},
mixins: [BaseMixin],
mounted() {
this.resizeTextarea();
},
beforeUnmount() {
raf.cancel(this.nextFrameActionId);
raf.cancel(this.resizeFrameId);
},
setup() { setup() {
return { return {
nextFrameActionId: undefined, nextFrameActionId: undefined,
@ -53,6 +40,12 @@ const ResizableTextArea = defineComponent({
resizeFrameId: undefined, resizeFrameId: undefined,
}; };
}, },
data() {
return {
textareaStyles: {},
resizeStatus: RESIZE_STATUS_NONE,
};
},
watch: { watch: {
value() { value() {
nextTick(() => { nextTick(() => {
@ -60,6 +53,13 @@ const ResizableTextArea = defineComponent({
}); });
}, },
}, },
mounted() {
this.resizeTextarea();
},
beforeUnmount() {
raf.cancel(this.nextFrameActionId);
raf.cancel(this.resizeFrameId);
},
methods: { methods: {
saveTextArea(textArea: any) { saveTextArea(textArea: any) {
this.textArea = textArea; this.textArea = textArea;

View File

@ -71,6 +71,12 @@ export default defineComponent({
collapsedWidth: 80, collapsedWidth: 80,
}), }),
emits: ['breakpoint', 'update:collapsed', 'collapse'], emits: ['breakpoint', 'update:collapsed', 'collapse'],
setup() {
return {
siderHook: inject<SiderHookProvider>('siderHook', {}),
configProvider: inject('configProvider', defaultConfigProvider),
};
},
data() { data() {
const uniqueId = generateId('ant-sider-'); const uniqueId = generateId('ant-sider-');
let matchMedia: typeof window.matchMedia; let matchMedia: typeof window.matchMedia;
@ -106,12 +112,6 @@ export default defineComponent({
created() { created() {
provide('layoutSiderContext', this); // menu组件中使用 provide('layoutSiderContext', this); // menu组件中使用
}, },
setup() {
return {
siderHook: inject<SiderHookProvider>('siderHook', {}),
configProvider: inject('configProvider', defaultConfigProvider),
};
},
mounted() { mounted() {
nextTick(() => { nextTick(() => {

View File

@ -55,9 +55,9 @@ export const ListProps = () => ({
}); });
const List = defineComponent({ const List = defineComponent({
name: 'AList',
inheritAttrs: false, inheritAttrs: false,
Item, Item,
name: 'AList',
props: initDefaultProps(ListProps(), { props: initDefaultProps(ListProps(), {
dataSource: [], dataSource: [],
bordered: false, bordered: false,
@ -65,23 +65,6 @@ const List = defineComponent({
loading: false, loading: false,
pagination: false, pagination: false,
}), }),
created() {
provide('listContext', this);
this.defaultPaginationProps = {
current: 1,
pageSize: 10,
onChange: (page: number, pageSize: number) => {
const { pagination } = this;
this.paginationCurrent = page;
if (pagination && (pagination as any).onChange) {
(pagination as any).onChange(page, pageSize);
}
},
total: 0,
};
this.onPaginationChange = this.triggerPaginationEvent('onChange');
this.onPaginationShowSizeChange = this.triggerPaginationEvent('onShowSizeChange');
},
setup() { setup() {
return { return {
keys: [], keys: [],
@ -101,6 +84,23 @@ const List = defineComponent({
paginationSize: paginationObj.defaultPageSize || 10, paginationSize: paginationObj.defaultPageSize || 10,
}; };
}, },
created() {
provide('listContext', this);
this.defaultPaginationProps = {
current: 1,
pageSize: 10,
onChange: (page: number, pageSize: number) => {
const { pagination } = this;
this.paginationCurrent = page;
if (pagination && (pagination as any).onChange) {
(pagination as any).onChange(page, pageSize);
}
},
total: 0,
};
this.onPaginationChange = this.triggerPaginationEvent('onChange');
this.onPaginationShowSizeChange = this.triggerPaginationEvent('onShowSizeChange');
},
methods: { methods: {
triggerPaginationEvent(eventName) { triggerPaginationEvent(eventName) {
return (page, pageSize) => { return (page, pageSize) => {

View File

@ -51,13 +51,13 @@ export type MenuProps = Partial<ExtractPropTypes<typeof menuProps>>;
const Menu = defineComponent({ const Menu = defineComponent({
name: 'AMenu', name: 'AMenu',
mixins: [BaseMixin],
inheritAttrs: false, inheritAttrs: false,
props: menuProps, props: menuProps,
Divider: { ...Divider, name: 'AMenuDivider' }, Divider: { ...Divider, name: 'AMenuDivider' },
Item: { ...Item, name: 'AMenuItem' }, Item: { ...Item, name: 'AMenuItem' },
SubMenu: { ...SubMenu, name: 'ASubMenu' }, SubMenu: { ...SubMenu, name: 'ASubMenu' },
ItemGroup: { ...ItemGroup, name: 'AMenuItemGroup' }, ItemGroup: { ...ItemGroup, name: 'AMenuItemGroup' },
mixins: [BaseMixin],
emits: [ emits: [
'update:selectedKeys', 'update:selectedKeys',
'update:openKeys', 'update:openKeys',
@ -68,10 +68,6 @@ const Menu = defineComponent({
'select', 'select',
'deselect', 'deselect',
], ],
created() {
provide('getInlineCollapsed', this.getInlineCollapsed);
provide('menuPropsContext', this.$props);
},
setup() { setup() {
const layoutSiderContext = inject<SiderContextProps>('layoutSiderContext', {}); const layoutSiderContext = inject<SiderContextProps>('layoutSiderContext', {});
const layoutSiderCollapsed = toRef(layoutSiderContext, 'sCollapsed'); const layoutSiderCollapsed = toRef(layoutSiderContext, 'sCollapsed');
@ -85,8 +81,23 @@ const Menu = defineComponent({
inlineOpenKeys: [], inlineOpenKeys: [],
}; };
}, },
updated() { data() {
this.propsUpdating = false; const props: MenuProps = getOptionProps(this);
warning(
!('inlineCollapsed' in props && props.mode !== 'inline'),
'Menu',
"`inlineCollapsed` should only be used when Menu's `mode` is inline.",
);
let sOpenKeys;
if ('openKeys' in props) {
sOpenKeys = props.openKeys;
} else if ('defaultOpenKeys' in props) {
sOpenKeys = props.defaultOpenKeys;
}
return {
sOpenKeys,
};
}, },
// beforeUnmount() { // beforeUnmount() {
// raf.cancel(this.mountRafId); // raf.cancel(this.mountRafId);
@ -107,23 +118,12 @@ const Menu = defineComponent({
this.collapsedChange(val); this.collapsedChange(val);
}, },
}, },
data() { created() {
const props: MenuProps = getOptionProps(this); provide('getInlineCollapsed', this.getInlineCollapsed);
warning( provide('menuPropsContext', this.$props);
!('inlineCollapsed' in props && props.mode !== 'inline'), },
'Menu', updated() {
"`inlineCollapsed` should only be used when Menu's `mode` is inline.", this.propsUpdating = false;
);
let sOpenKeys;
if ('openKeys' in props) {
sOpenKeys = props.openKeys;
} else if ('defaultOpenKeys' in props) {
sOpenKeys = props.defaultOpenKeys;
}
return {
sOpenKeys,
};
}, },
methods: { methods: {
collapsedChange(val) { collapsedChange(val) {

View File

@ -19,16 +19,16 @@ export type IActionButtonProps = ExtractPropTypes<typeof ActionButtonProps>;
export default defineComponent({ export default defineComponent({
mixins: [BaseMixin], mixins: [BaseMixin],
props: ActionButtonProps, props: ActionButtonProps,
data() {
return {
loading: false,
};
},
setup() { setup() {
return { return {
timeoutId: undefined, timeoutId: undefined,
}; };
}, },
data() {
return {
loading: false,
};
},
mounted() { mounted() {
if (this.autofocus) { if (this.autofocus) {
this.timeoutId = setTimeout(() => findDOMNode(this).focus()); this.timeoutId = setTimeout(() => findDOMNode(this).focus());

View File

@ -159,6 +159,11 @@ export default defineComponent({
visible: false, visible: false,
okType: 'primary', okType: 'primary',
}), }),
setup() {
return {
configProvider: inject('configProvider', defaultConfigProvider),
};
},
data() { data() {
return { return {
sVisible: !!this.visible, sVisible: !!this.visible,
@ -169,11 +174,6 @@ export default defineComponent({
this.sVisible = val; this.sVisible = val;
}, },
}, },
setup() {
return {
configProvider: inject('configProvider', defaultConfigProvider),
};
},
methods: { methods: {
handleCancel(e: MouseEvent) { handleCancel(e: MouseEvent) {
this.$emit('update:visible', false); this.$emit('update:visible', false);

View File

@ -38,11 +38,6 @@ const Popconfirm = defineComponent({
}, },
mixins: [BaseMixin], mixins: [BaseMixin],
emits: ['update:visible', 'confirm', 'cancel', 'visibleChange'], emits: ['update:visible', 'confirm', 'cancel', 'visibleChange'],
watch: {
visible(val) {
this.sVisible = val;
},
},
setup() { setup() {
return { return {
configProvider: inject('configProvider', defaultConfigProvider), configProvider: inject('configProvider', defaultConfigProvider),
@ -59,6 +54,11 @@ const Popconfirm = defineComponent({
} }
return state; return state;
}, },
watch: {
visible(val) {
this.sVisible = val;
},
},
methods: { methods: {
onConfirmHandle(e) { onConfirmHandle(e) {
this.setVisible(false, e); this.setVisible(false, e);

View File

@ -21,12 +21,6 @@ export default defineComponent({
onChange: PropTypes.func, onChange: PropTypes.func,
}, },
emits: ['update:value', 'change'], emits: ['update:value', 'change'],
data() {
const { value, defaultValue } = this;
return {
stateValue: value === undefined ? defaultValue : value,
};
},
setup() { setup() {
return { return {
updatingValue: false, updatingValue: false,
@ -34,6 +28,18 @@ export default defineComponent({
radioGroupContext: null, radioGroupContext: null,
}; };
}, },
data() {
const { value, defaultValue } = this;
return {
stateValue: value === undefined ? defaultValue : value,
};
},
watch: {
value(val) {
this.updatingValue = false;
this.stateValue = val;
},
},
// computed: { // computed: {
// radioOptions() { // radioOptions() {
// const { disabled } = this; // const { disabled } = this;
@ -47,12 +53,6 @@ export default defineComponent({
created() { created() {
this.radioGroupContext = provide('radioGroupContext', this); this.radioGroupContext = provide('radioGroupContext', this);
}, },
watch: {
value(val) {
this.updatingValue = false;
this.stateValue = val;
},
},
methods: { methods: {
onRadioChange(ev: RadioChangeEvent) { onRadioChange(ev: RadioChangeEvent) {
const lastValue = this.stateValue; const lastValue = this.stateValue;

View File

@ -53,9 +53,9 @@ const defaultTipFormatter = (value: number) => value.toString();
const Slider = defineComponent({ const Slider = defineComponent({
name: 'ASlider', name: 'ASlider',
mixins: [BaseMixin],
inheritAttrs: false, inheritAttrs: false,
emits: ['update:value', 'change'], emits: ['update:value', 'change'],
mixins: [BaseMixin],
setup() { setup() {
return { return {
vcSlider: null, vcSlider: null,

View File

@ -46,10 +46,6 @@ export default defineComponent({
configProvider: inject('configProvider', defaultConfigProvider), configProvider: inject('configProvider', defaultConfigProvider),
}; };
}, },
created() {
this.originalUpdateSpinning = this.updateSpinning;
this.debouncifyUpdateSpinning(this.$props);
},
data() { data() {
const { spinning, delay } = this; const { spinning, delay } = this;
const shouldBeDelayed = shouldDelay(spinning, delay); const shouldBeDelayed = shouldDelay(spinning, delay);
@ -57,6 +53,10 @@ export default defineComponent({
sSpinning: spinning && !shouldBeDelayed, sSpinning: spinning && !shouldBeDelayed,
}; };
}, },
created() {
this.originalUpdateSpinning = this.updateSpinning;
this.debouncifyUpdateSpinning(this.$props);
},
mounted() { mounted() {
this.updateSpinning(); this.updateSpinning();
}, },

View File

@ -31,6 +31,13 @@ const Switch = defineComponent({
configProvider: inject('configProvider', defaultConfigProvider), configProvider: inject('configProvider', defaultConfigProvider),
}; };
}, },
created() {
warning(
hasProp(this, 'checked') || !('value' in this.$attrs),
'Switch',
'`value` is not validate prop, do you mean `checked`?',
);
},
methods: { methods: {
focus() { focus() {
this.refSwitchNode?.focus(); this.refSwitchNode?.focus();
@ -42,13 +49,6 @@ const Switch = defineComponent({
this.refSwitchNode = c; this.refSwitchNode = c;
}, },
}, },
created() {
warning(
hasProp(this, 'checked') || !('value' in this.$attrs),
'Switch',
'`value` is not validate prop, do you mean `checked`?',
);
},
render() { render() {
const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps( const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps(

View File

@ -10,17 +10,17 @@ export default defineComponent({
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false, inheritAttrs: false,
props: SelectionBoxProps, props: SelectionBoxProps,
data() {
return {
checked: false,
};
},
setup() { setup() {
return { return {
unsubscribe: null, unsubscribe: null,
}; };
}, },
data() {
return {
checked: false,
};
},
created() { created() {
this.checked = this.getCheckState(this.$props); this.checked = this.getCheckState(this.$props);

View File

@ -93,6 +93,13 @@ export default defineComponent({
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false, inheritAttrs: false,
props: SelectionCheckboxAllProps, props: SelectionCheckboxAllProps,
setup() {
return {
defaultSelections: [],
unsubscribe: null,
};
},
data() { data() {
const { $props: props } = this; const { $props: props } = this;
@ -102,11 +109,12 @@ export default defineComponent({
}; };
}, },
setup() { watch: {
return { propsSymbol: {
defaultSelections: [], handler() {
unsubscribe: null, this.setCheckState(this.$props);
}; },
},
}, },
created() { created() {
@ -125,14 +133,6 @@ export default defineComponent({
]; ];
}, },
watch: {
propsSymbol: {
handler() {
this.setCheckState(this.$props);
},
},
},
mounted() { mounted() {
this.subscribe(); this.subscribe();
}, },

View File

@ -170,13 +170,6 @@ export default defineComponent({
filterDataCnt: 0, filterDataCnt: 0,
}; };
}, },
created() {
const props = getOptionProps(this);
this.store = createStore({
selectedRowKeys: getRowSelection(props).selectedRowKeys || [],
selectionDirty: false,
});
},
watch: { watch: {
pagination: { pagination: {
handler(val) { handler(val) {
@ -242,6 +235,13 @@ export default defineComponent({
deep: true, deep: true,
}, },
}, },
created() {
const props = getOptionProps(this);
this.store = createStore({
selectedRowKeys: getRowSelection(props).selectedRowKeys || [],
selectionDirty: false,
});
},
updated() { updated() {
const { columns, sSortColumn: sortColumn, sSortOrder: sortOrder } = this; const { columns, sSortColumn: sortColumn, sSortOrder: sortOrder } = this;
if (this.getSortOrderColumns(columns).length > 0) { if (this.getSortOrderColumns(columns).length > 0) {

View File

@ -15,6 +15,11 @@ export default function createBodyRow(Component = 'tr') {
name: 'BodyRow', name: 'BodyRow',
inheritAttrs: false, inheritAttrs: false,
props: BodyRowProps, props: BodyRowProps,
setup() {
return {
unsubscribe: null,
};
},
data() { data() {
const { selectedRowKeys } = this.store.getState(); const { selectedRowKeys } = this.store.getState();
@ -22,11 +27,6 @@ export default function createBodyRow(Component = 'tr') {
selected: selectedRowKeys.indexOf(this.rowKey) >= 0, selected: selectedRowKeys.indexOf(this.rowKey) >= 0,
}; };
}, },
setup() {
return {
unsubscribe: null,
};
},
mounted() { mounted() {
this.subscribe(); this.subscribe();
}, },

View File

@ -8,8 +8,8 @@ const Table = defineComponent({
name: 'ATable', name: 'ATable',
Column: T.Column, Column: T.Column,
ColumnGroup: T.ColumnGroup, ColumnGroup: T.ColumnGroup,
props: defaultTableProps,
inheritAttrs: false, inheritAttrs: false,
props: defaultTableProps,
methods: { methods: {
normalize(elements = []) { normalize(elements = []) {
const columns = []; const columns = [];

View File

@ -76,8 +76,8 @@ export const TimePickerProps = () => ({
const TimePicker = defineComponent({ const TimePicker = defineComponent({
name: 'ATimePicker', name: 'ATimePicker',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
emits: ['update:value', 'update:open', 'change', 'openChange', 'focus', 'blur', 'keydown'], emits: ['update:value', 'update:open', 'change', 'openChange', 'focus', 'blur', 'keydown'],
props: initDefaultProps(TimePickerProps(), { props: initDefaultProps(TimePickerProps(), {
align: { align: {
@ -93,9 +93,6 @@ const TimePicker = defineComponent({
focusOnOpen: true, focusOnOpen: true,
allowClear: true, allowClear: true,
}), }),
created() {
provide('savePopupRef', this.savePopupRef);
},
setup() { setup() {
return { return {
popupRef: null, popupRef: null,
@ -124,6 +121,9 @@ const TimePicker = defineComponent({
this.setState({ sValue: stringToMoment(val, this.valueFormat) }); this.setState({ sValue: stringToMoment(val, this.valueFormat) });
}, },
}, },
created() {
provide('savePopupRef', this.savePopupRef);
},
methods: { methods: {
getDefaultFormat() { getDefaultFormat() {
const { format, use12Hours } = this; const { format, use12Hours } = this;

View File

@ -57,8 +57,8 @@ export interface TransferLocale {
const Transfer = defineComponent({ const Transfer = defineComponent({
name: 'ATransfer', name: 'ATransfer',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
props: initDefaultProps(TransferProps, { props: initDefaultProps(TransferProps, {
dataSource: [], dataSource: [],
locale: {}, locale: {},
@ -86,9 +86,6 @@ const Transfer = defineComponent({
targetSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) > -1), targetSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) > -1),
}; };
}, },
mounted() {
// this.currentProps = { ...this.$props }
},
watch: { watch: {
targetKeys() { targetKeys() {
this.updateState(); this.updateState();
@ -113,6 +110,9 @@ const Transfer = defineComponent({
} }
}, },
}, },
mounted() {
// this.currentProps = { ...this.$props }
},
methods: { methods: {
getSelectedKeysName(direction) { getSelectedKeysName(direction) {
return direction === 'left' ? 'sourceSelectedKeys' : 'targetSelectedKeys'; return direction === 'left' ? 'sourceSelectedKeys' : 'targetSelectedKeys';

View File

@ -21,8 +21,8 @@ const TreeSelect = defineComponent({
SHOW_ALL, SHOW_ALL,
SHOW_PARENT, SHOW_PARENT,
SHOW_CHILD, SHOW_CHILD,
inheritAttrs: false,
name: 'ATreeSelect', name: 'ATreeSelect',
inheritAttrs: false,
props: initDefaultProps(TreeSelectProps(), { props: initDefaultProps(TreeSelectProps(), {
transitionName: 'slide-up', transitionName: 'slide-up',
choiceTransitionName: '', choiceTransitionName: '',

View File

@ -88,9 +88,6 @@ export default defineComponent({
...state, ...state,
}; };
}, },
created() {
this.onDebounceExpand = debounce(this.expandFolderNode, 200, { leading: true });
},
watch: { watch: {
expandedKeys(val) { expandedKeys(val) {
this.setState({ _expandedKeys: val }); this.setState({ _expandedKeys: val });
@ -99,6 +96,9 @@ export default defineComponent({
this.setState({ _selectedKeys: val }); this.setState({ _selectedKeys: val });
}, },
}, },
created() {
this.onDebounceExpand = debounce(this.expandFolderNode, 200, { leading: true });
},
methods: { methods: {
handleExpand(expandedKeys, info) { handleExpand(expandedKeys, info) {
this.setUncontrolledState({ _expandedKeys: expandedKeys }); this.setUncontrolledState({ _expandedKeys: expandedKeys });

View File

@ -64,32 +64,6 @@ const Drawer = defineComponent({
container: undefined, container: undefined,
}; };
}, },
mounted() {
nextTick(() => {
if (!windowIsUndefined) {
let passiveSupported = false;
window.addEventListener(
'test',
null,
Object.defineProperty({}, 'passive', {
get: () => {
passiveSupported = true;
return null;
},
}),
);
this.passive = passiveSupported ? { passive: false } : false;
}
const open = this.getOpen();
if (this.handler || open || this.sFirstEnter) {
this.getDefault(this.$props);
if (open) {
this.isOpenChange = true;
}
this.$forceUpdate();
}
});
},
watch: { watch: {
open(val) { open(val) {
if (val !== undefined && val !== this.preProps.open) { if (val !== undefined && val !== this.preProps.open) {
@ -118,6 +92,32 @@ const Drawer = defineComponent({
this.preProps.level = val; this.preProps.level = val;
}, },
}, },
mounted() {
nextTick(() => {
if (!windowIsUndefined) {
let passiveSupported = false;
window.addEventListener(
'test',
null,
Object.defineProperty({}, 'passive', {
get: () => {
passiveSupported = true;
return null;
},
}),
);
this.passive = passiveSupported ? { passive: false } : false;
}
const open = this.getOpen();
if (this.handler || open || this.sFirstEnter) {
this.getDefault(this.$props);
if (open) {
this.isOpenChange = true;
}
this.$forceUpdate();
}
});
},
updated() { updated() {
nextTick(() => { nextTick(() => {
// dom 没渲染时,重走一遍。 // dom 没渲染时,重走一遍。

View File

@ -12,46 +12,14 @@ export default defineComponent({
props: { props: {
...defaultProps, ...defaultProps,
}, },
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
data() { data() {
this._responsiveMediaHandlers = []; this._responsiveMediaHandlers = [];
return { return {
breakpoint: null, breakpoint: null,
}; };
}, },
methods: {
innerSliderRefHandler(ref) {
this.innerSlider = ref;
},
media(query, handler) {
// javascript handler for css media query
const mql = window.matchMedia(query);
const listener = ({ matches }) => {
if (matches) {
handler();
}
};
mql.addListener(listener);
listener(mql);
this._responsiveMediaHandlers.push({ mql, query, listener });
},
slickPrev() {
this.innerSlider.slickPrev();
},
slickNext() {
this.innerSlider.slickNext();
},
slickGoTo(slide, dontAnimate = false) {
this.innerSlider.slickGoTo(slide, dontAnimate);
},
slickPause() {
this.innerSlider.pause('paused');
},
slickPlay() {
this.innerSlider.handleAutoPlay('play');
},
},
// handles responsive breakpoints // handles responsive breakpoints
beforeMount() { beforeMount() {
if (this.responsive) { if (this.responsive) {
@ -92,6 +60,38 @@ export default defineComponent({
obj.mql.removeListener(obj.listener); obj.mql.removeListener(obj.listener);
}); });
}, },
methods: {
innerSliderRefHandler(ref) {
this.innerSlider = ref;
},
media(query, handler) {
// javascript handler for css media query
const mql = window.matchMedia(query);
const listener = ({ matches }) => {
if (matches) {
handler();
}
};
mql.addListener(listener);
listener(mql);
this._responsiveMediaHandlers.push({ mql, query, listener });
},
slickPrev() {
this.innerSlider.slickPrev();
},
slickNext() {
this.innerSlider.slickNext();
},
slickGoTo(slide, dontAnimate = false) {
this.innerSlider.slickGoTo(slide, dontAnimate);
},
slickPause() {
this.innerSlider.pause('paused');
},
slickPlay() {
this.innerSlider.handleAutoPlay('play');
},
},
render() { render() {
let settings; let settings;

View File

@ -8,8 +8,8 @@ import { defineComponent } from 'vue';
const Slider = defineComponent({ const Slider = defineComponent({
name: 'Slider', name: 'Slider',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
props: { props: {
defaultValue: PropTypes.number, defaultValue: PropTypes.number,
value: PropTypes.number, value: PropTypes.number,

View File

@ -36,9 +36,9 @@ export default function createSlider(Component) {
autofocus: PropTypes.looseBool, autofocus: PropTypes.looseBool,
}; };
return defineComponent({ return defineComponent({
name: 'createSlider', name: 'CreateSlider',
inheritAttrs: false,
mixins: [BaseMixin, Component], mixins: [BaseMixin, Component],
inheritAttrs: false,
// model: { // model: {
// prop: 'value', // prop: 'value',
// event: 'change', // event: 'change',

View File

@ -34,8 +34,8 @@ function toNearestValidTime(time, hourOptions, minuteOptions, secondOptions) {
const Panel = defineComponent({ const Panel = defineComponent({
name: 'Panel', name: 'Panel',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
props: { props: {
clearText: PropTypes.string, clearText: PropTypes.string,
prefixCls: PropTypes.string.def('rc-time-picker-panel'), prefixCls: PropTypes.string.def('rc-time-picker-panel'),

View File

@ -68,8 +68,8 @@ function getWatch(keys = []) {
} }
const Select = defineComponent({ const Select = defineComponent({
name: 'Select', name: 'Select',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
props: initDefaultProps( props: initDefaultProps(
{ {
prefixCls: PropTypes.string, prefixCls: PropTypes.string,

View File

@ -43,8 +43,8 @@ function getWatch(keys = []) {
const Tree = defineComponent({ const Tree = defineComponent({
name: 'Tree', name: 'Tree',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
props: initDefaultProps( props: initDefaultProps(
{ {
prefixCls: PropTypes.string, prefixCls: PropTypes.string,

View File

@ -14,8 +14,8 @@ const defaultTitle = '---';
const TreeNode = defineComponent({ const TreeNode = defineComponent({
name: 'TreeNode', name: 'TreeNode',
inheritAttrs: false,
mixins: [BaseMixin], mixins: [BaseMixin],
inheritAttrs: false,
__ANT_TREE_NODE: true, __ANT_TREE_NODE: true,
props: initDefaultProps( props: initDefaultProps(
{ {
@ -52,6 +52,12 @@ const TreeNode = defineComponent({
}, },
{}, {},
), ),
setup() {
return {
vcTree: inject('vcTree', {}),
vcTreeNode: inject('vcTreeNode', {}),
};
},
data() { data() {
this.children = null; this.children = null;
@ -59,12 +65,6 @@ const TreeNode = defineComponent({
dragNodeHighlight: false, dragNodeHighlight: false,
}; };
}, },
setup() {
return {
vcTree: inject('vcTree', {}),
vcTreeNode: inject('vcTreeNode', {}),
};
},
created() { created() {
provide('vcTreeNode', this); provide('vcTreeNode', this);
}, },

View File

@ -76,6 +76,13 @@ export default defineComponent({
stretch: PropTypes.string, stretch: PropTypes.string,
alignPoint: PropTypes.looseBool, // Maybe we can support user pass position in the future alignPoint: PropTypes.looseBool, // Maybe we can support user pass position in the future
}, },
setup() {
return {
vcTriggerContext: inject('vcTriggerContext', {}),
savePopupRef: inject('savePopupRef', noop),
dialogContext: inject('dialogContext', null),
};
},
data() { data() {
const props = this.$props; const props = this.$props;
let popupVisible; let popupVisible;
@ -112,13 +119,6 @@ export default defineComponent({
created() { created() {
provide('vcTriggerContext', this); provide('vcTriggerContext', this);
}, },
setup() {
return {
vcTriggerContext: inject('vcTriggerContext', {}),
savePopupRef: inject('savePopupRef', noop),
dialogContext: inject('dialogContext', null),
};
},
deactivated() { deactivated() {
this.setPopupVisible(false); this.setPopupVisible(false);
}, },

View File

@ -59,8 +59,8 @@ export interface ListState<T = object> {
} }
const List = defineComponent({ const List = defineComponent({
inheritAttrs: false,
name: 'List', name: 'List',
inheritAttrs: false,
props: { props: {
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
data: PropTypes.array, data: PropTypes.array,

View File

@ -123,7 +123,7 @@
"eslint-plugin-html": "^6.0.0", "eslint-plugin-html": "^6.0.0",
"eslint-plugin-markdown": "^2.0.0-alpha.0", "eslint-plugin-markdown": "^2.0.0-alpha.0",
"eslint-plugin-prettier": "^3.1.4", "eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-vue": "^6.2.2", "eslint-plugin-vue": "^7.1.0",
"fetch-jsonp": "^1.1.3", "fetch-jsonp": "^1.1.3",
"fs-extra": "^8.0.0", "fs-extra": "^8.0.0",
"glob": "^7.1.2", "glob": "^7.1.2",

View File

@ -2,8 +2,8 @@ import glob from 'glob';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import MockDate from 'mockdate'; import MockDate from 'mockdate';
import moment from 'moment'; import moment from 'moment';
import { nextTick } from 'vue';
import antd from 'ant-design-vue'; import antd from 'ant-design-vue';
import { sleep } from '../utils';
export default function demoTest(component, options = {}) { export default function demoTest(component, options = {}) {
const suffix = options.suffix || 'md'; const suffix = options.suffix || 'md';
@ -14,12 +14,12 @@ export default function demoTest(component, options = {}) {
if (Array.isArray(options.skip) && options.skip.some(c => file.includes(c))) { if (Array.isArray(options.skip) && options.skip.some(c => file.includes(c))) {
testMethod = test.skip; testMethod = test.skip;
} }
testMethod(`renders ${file} correctly`, done => { testMethod(`renders ${file} correctly`, async () => {
MockDate.set(moment('2016-11-22')); MockDate.set(moment('2016-11-22'));
const demo = require(`../.${file}`).default || require(`../.${file}`); const demo = require(`../.${file}`).default || require(`../.${file}`);
document.body.innerHTML = ''; document.body.innerHTML = '';
const wrapper = mount(demo, { global: { plugins: [antd] }, attachTo: document.body }); const wrapper = mount(demo, { global: { plugins: [antd] }, attachTo: document.body });
nextTick(() => { await sleep();
// should get dom from element // should get dom from element
// snap files copy from antd does not need to change // snap files copy from antd does not need to change
// or just change a little // or just change a little
@ -28,8 +28,6 @@ export default function demoTest(component, options = {}) {
MockDate.reset(); MockDate.reset();
// wrapper.unmount(); // wrapper.unmount();
document.body.innerHTML = ''; document.body.innerHTML = '';
done();
});
}); });
}); });
} }