refactor: auto-complete by ts
parent
64fef377c0
commit
712f2b1599
|
@ -1 +1 @@
|
||||||
Subproject commit 83ab203d1ab9861132f6efd1e74015507c0e45f6
|
Subproject commit 88970d13f8e2e6f5c96a28697fe0b399eccdcb07
|
|
@ -1,7 +1,7 @@
|
||||||
import { cloneElement } from '../_util/vnode';
|
import { cloneElement } from '../_util/vnode';
|
||||||
import { flattenChildren } from '../_util/props-util';
|
import { flattenChildren } from '../_util/props-util';
|
||||||
|
|
||||||
const InputElement = (_, { attrs, slots }) => {
|
const InputElement = (_: any, { attrs, slots }) => {
|
||||||
const children = flattenChildren(slots.default?.())[0];
|
const children = flattenChildren(slots.default?.())[0];
|
||||||
return cloneElement(children, { ...attrs });
|
return cloneElement(children, { ...attrs });
|
||||||
};
|
};
|
|
@ -1,4 +1,4 @@
|
||||||
import { inject, provide } from 'vue';
|
import { App, defineComponent, inject, provide } from 'vue';
|
||||||
import { Option, OptGroup } from '../vc-select';
|
import { Option, OptGroup } from '../vc-select';
|
||||||
import Select, { AbstractSelectProps, SelectValue } from '../select';
|
import Select, { AbstractSelectProps, SelectValue } from '../select';
|
||||||
import Input from '../input';
|
import Input from '../input';
|
||||||
|
@ -7,20 +7,7 @@ import PropTypes from '../_util/vue-types';
|
||||||
import { defaultConfigProvider } from '../config-provider';
|
import { defaultConfigProvider } from '../config-provider';
|
||||||
import { getComponent, getOptionProps, isValidElement, getSlot } from '../_util/props-util';
|
import { getComponent, getOptionProps, isValidElement, getSlot } from '../_util/props-util';
|
||||||
|
|
||||||
// const DataSourceItemObject = PropTypes.shape({
|
function isSelectOptionOrSelectOptGroup(child: any): Boolean {
|
||||||
// value: String,
|
|
||||||
// text: String,
|
|
||||||
// }).loose
|
|
||||||
// const DataSourceItemType = PropTypes.oneOfType([
|
|
||||||
// PropTypes.string,
|
|
||||||
// DataSourceItemObject,
|
|
||||||
// ]).isRequired
|
|
||||||
|
|
||||||
// export interface AutoCompleteInputProps {
|
|
||||||
// onChange?: React.FormEventHandler<any>;
|
|
||||||
// value: any;
|
|
||||||
// }
|
|
||||||
function isSelectOptionOrSelectOptGroup(child) {
|
|
||||||
return child && child.type && (child.type.isSelectOption || child.type.isSelectOptGroup);
|
return child && child.type && (child.type.isSelectOption || child.type.isSelectOptGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,15 +17,16 @@ const AutoCompleteProps = {
|
||||||
defaultValue: SelectValue,
|
defaultValue: SelectValue,
|
||||||
dataSource: PropTypes.array,
|
dataSource: PropTypes.array,
|
||||||
dropdownMenuStyle: PropTypes.object,
|
dropdownMenuStyle: PropTypes.object,
|
||||||
optionLabelProp: String,
|
optionLabelProp: PropTypes.string,
|
||||||
dropdownMatchSelectWidth: PropTypes.looseBool,
|
dropdownMatchSelectWidth: PropTypes.looseBool,
|
||||||
// onChange?: (value: SelectValue) => void;
|
// onChange?: (value: SelectValue) => void;
|
||||||
// onSelect?: (value: SelectValue, option: Object) => any;
|
// onSelect?: (value: SelectValue, option: Object) => any;
|
||||||
};
|
};
|
||||||
|
|
||||||
const AutoComplete = {
|
const AutoComplete = defineComponent({
|
||||||
name: 'AAutoComplete',
|
name: 'AAutoComplete',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
emits: ['change', 'select', 'focus', 'blur'],
|
||||||
props: {
|
props: {
|
||||||
...AutoCompleteProps,
|
...AutoCompleteProps,
|
||||||
prefixCls: PropTypes.string.def('ant-select'),
|
prefixCls: PropTypes.string.def('ant-select'),
|
||||||
|
@ -53,23 +41,21 @@ const AutoComplete = {
|
||||||
},
|
},
|
||||||
Option: { ...Option, name: 'AAutoCompleteOption' },
|
Option: { ...Option, name: 'AAutoCompleteOption' },
|
||||||
OptGroup: { ...OptGroup, name: 'AAutoCompleteOptGroup' },
|
OptGroup: { ...OptGroup, name: 'AAutoCompleteOptGroup' },
|
||||||
// model: {
|
|
||||||
// prop: 'value',
|
|
||||||
// event: 'change',
|
|
||||||
// },
|
|
||||||
setup() {
|
setup() {
|
||||||
return {
|
return {
|
||||||
configProvider: inject('configProvider', defaultConfigProvider),
|
configProvider: inject('configProvider', defaultConfigProvider),
|
||||||
|
popupRef: null,
|
||||||
|
select: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
provide('savePopupRef', this.savePopupRef);
|
provide('savePopupRef', this.savePopupRef);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
savePopupRef(ref) {
|
savePopupRef(ref: any) {
|
||||||
this.popupRef = ref;
|
this.popupRef = ref;
|
||||||
},
|
},
|
||||||
saveSelect(node) {
|
saveSelect(node: any) {
|
||||||
this.select = node;
|
this.select = node;
|
||||||
},
|
},
|
||||||
getInputElement() {
|
getInputElement() {
|
||||||
|
@ -100,7 +86,7 @@ const AutoComplete = {
|
||||||
|
|
||||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
const prefixCls = getPrefixCls('select', customizePrefixCls);
|
const prefixCls = getPrefixCls('select', customizePrefixCls);
|
||||||
const { class: className } = this.$attrs;
|
const { class: className} = this.$attrs as any;
|
||||||
const cls = {
|
const cls = {
|
||||||
[className]: !!className,
|
[className]: !!className,
|
||||||
[`${prefixCls}-lg`]: size === 'large',
|
[`${prefixCls}-lg`]: size === 'large',
|
||||||
|
@ -115,7 +101,7 @@ const AutoComplete = {
|
||||||
options = childArray;
|
options = childArray;
|
||||||
} else {
|
} else {
|
||||||
options = dataSource
|
options = dataSource
|
||||||
? dataSource.map(item => {
|
? dataSource.map((item: any) => {
|
||||||
if (isValidElement(item)) {
|
if (isValidElement(item)) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
@ -145,10 +131,10 @@ const AutoComplete = {
|
||||||
};
|
};
|
||||||
return <Select {...selectProps}>{options}</Select>;
|
return <Select {...selectProps}>{options}</Select>;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
AutoComplete.install = function(app) {
|
AutoComplete.install = function(app: App) {
|
||||||
app.component(AutoComplete.name, AutoComplete);
|
app.component(AutoComplete.name, AutoComplete);
|
||||||
app.component(AutoComplete.Option.name, AutoComplete.Option);
|
app.component(AutoComplete.Option.name, AutoComplete.Option);
|
||||||
app.component(AutoComplete.OptGroup.name, AutoComplete.OptGroup);
|
app.component(AutoComplete.OptGroup.name, AutoComplete.OptGroup);
|
|
@ -21,7 +21,7 @@ function getMonthsLocale(value) {
|
||||||
export const HeaderProps = {
|
export const HeaderProps = {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
locale: PropTypes.any,
|
locale: PropTypes.any,
|
||||||
fullscreen: PropTypes.looseBoolean,
|
fullscreen: PropTypes.looseBool,
|
||||||
yearSelectOffset: PropTypes.number,
|
yearSelectOffset: PropTypes.number,
|
||||||
yearSelectTotal: PropTypes.number,
|
yearSelectTotal: PropTypes.number,
|
||||||
type: PropTypes.string,
|
type: PropTypes.string,
|
||||||
|
|
|
@ -160,7 +160,7 @@ export const defaultConfigProvider = {
|
||||||
return `ant-${suffixCls}`;
|
return `ant-${suffixCls}`;
|
||||||
},
|
},
|
||||||
renderEmpty: defaultRenderEmpty,
|
renderEmpty: defaultRenderEmpty,
|
||||||
};
|
} as any;
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
ConfigProvider.install = function(app: App) {
|
ConfigProvider.install = function(app: App) {
|
||||||
|
|
|
@ -39,9 +39,9 @@ export const ValidationRule = {
|
||||||
/** built-in validation type, available options: https://github.com/yiminghe/async-validator#type */
|
/** built-in validation type, available options: https://github.com/yiminghe/async-validator#type */
|
||||||
type: PropTypes.string,
|
type: PropTypes.string,
|
||||||
/** indicates whether field is required */
|
/** indicates whether field is required */
|
||||||
required: PropTypes.looseBoolean,
|
required: PropTypes.looseBool,
|
||||||
/** treat required fields that only contain whitespace as errors */
|
/** treat required fields that only contain whitespace as errors */
|
||||||
whitespace: PropTypes.looseBoolean,
|
whitespace: PropTypes.looseBool,
|
||||||
/** validate the exact length of a field */
|
/** validate the exact length of a field */
|
||||||
len: PropTypes.number,
|
len: PropTypes.number,
|
||||||
/** validate the min length of a field */
|
/** validate the min length of a field */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { inject, withDirectives } from 'vue';
|
import { defineComponent, inject, withDirectives } from 'vue';
|
||||||
import antInputDirective from '../_util/antInputDirective';
|
import antInputDirective from '../_util/antInputDirective';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
|
@ -48,7 +48,7 @@ export function getInputClassName(prefixCls, size, disabled) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
name: 'AInput',
|
name: 'AInput',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
|
@ -227,4 +227,4 @@ export default {
|
||||||
};
|
};
|
||||||
return <ClearableLabeledInput {...props} ref={this.saveClearableInput} />;
|
return <ClearableLabeledInput {...props} ref={this.saveClearableInput} />;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { defaultConfigProvider } from '../config-provider';
|
||||||
|
|
||||||
export const BasicProps = {
|
export const BasicProps = {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
hasSider: PropTypes.looseBoolean,
|
hasSider: PropTypes.looseBool,
|
||||||
tagName: PropTypes.string,
|
tagName: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { provide, inject } from 'vue';
|
import { provide, inject, defineComponent, App } from 'vue';
|
||||||
import warning from '../_util/warning';
|
import warning from '../_util/warning';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
import PropTypes, { withUndefined } from '../_util/vue-types';
|
import PropTypes, { withUndefined } from '../_util/vue-types';
|
||||||
|
@ -65,7 +65,7 @@ const SelectProps = {
|
||||||
maxTagTextLength: PropTypes.number,
|
maxTagTextLength: PropTypes.number,
|
||||||
dropdownMatchSelectWidth: PropTypes.looseBool,
|
dropdownMatchSelectWidth: PropTypes.looseBool,
|
||||||
optionFilterProp: PropTypes.string,
|
optionFilterProp: PropTypes.string,
|
||||||
labelInValue: PropTypes.looseBoolean,
|
labelInValue: PropTypes.looseBool,
|
||||||
getPopupContainer: PropTypes.func,
|
getPopupContainer: PropTypes.func,
|
||||||
tokenSeparators: PropTypes.arrayOf(PropTypes.string),
|
tokenSeparators: PropTypes.arrayOf(PropTypes.string),
|
||||||
getInputElement: PropTypes.func,
|
getInputElement: PropTypes.func,
|
||||||
|
@ -89,7 +89,7 @@ const SelectPropTypes = {
|
||||||
|
|
||||||
export { AbstractSelectProps, SelectValue, SelectProps };
|
export { AbstractSelectProps, SelectValue, SelectProps };
|
||||||
const SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
|
const SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
|
||||||
const Select = {
|
const Select = defineComponent({
|
||||||
SECRET_COMBOBOX_MODE_DO_NOT_USE,
|
SECRET_COMBOBOX_MODE_DO_NOT_USE,
|
||||||
Option: { ...Option, name: 'ASelectOption' },
|
Option: { ...Option, name: 'ASelectOption' },
|
||||||
OptGroup: { ...OptGroup, name: 'ASelectOptGroup' },
|
OptGroup: { ...OptGroup, name: 'ASelectOptGroup' },
|
||||||
|
@ -104,6 +104,7 @@ const Select = {
|
||||||
setup() {
|
setup() {
|
||||||
return {
|
return {
|
||||||
configProvider: inject('configProvider', defaultConfigProvider),
|
configProvider: inject('configProvider', defaultConfigProvider),
|
||||||
|
popupRef: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -117,7 +118,7 @@ const Select = {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getNotFoundContent(renderEmpty) {
|
getNotFoundContent(renderEmpty: any) {
|
||||||
const notFoundContent = getComponent(this, 'notFoundContent');
|
const notFoundContent = getComponent(this, 'notFoundContent');
|
||||||
if (notFoundContent !== undefined) {
|
if (notFoundContent !== undefined) {
|
||||||
return notFoundContent;
|
return notFoundContent;
|
||||||
|
@ -131,10 +132,10 @@ const Select = {
|
||||||
this.popupRef = ref;
|
this.popupRef = ref;
|
||||||
},
|
},
|
||||||
focus() {
|
focus() {
|
||||||
this.$refs.vcSelect.focus();
|
(this.$refs.vcSelect as any).focus();
|
||||||
},
|
},
|
||||||
blur() {
|
blur() {
|
||||||
this.$refs.vcSelect.blur();
|
(this.$refs.vcSelect as any).blur();
|
||||||
},
|
},
|
||||||
|
|
||||||
isCombobox() {
|
isCombobox() {
|
||||||
|
@ -167,7 +168,7 @@ const Select = {
|
||||||
showArrow,
|
showArrow,
|
||||||
...restProps
|
...restProps
|
||||||
} = getOptionProps(this);
|
} = getOptionProps(this);
|
||||||
const { class: className } = this.$attrs;
|
const { class: className } = this.$attrs as any;
|
||||||
|
|
||||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
const renderEmpty = this.configProvider.renderEmpty;
|
const renderEmpty = this.configProvider.renderEmpty;
|
||||||
|
@ -182,7 +183,7 @@ const Select = {
|
||||||
menuItemSelectedIcon = Array.isArray(menuItemSelectedIcon)
|
menuItemSelectedIcon = Array.isArray(menuItemSelectedIcon)
|
||||||
? menuItemSelectedIcon[0]
|
? menuItemSelectedIcon[0]
|
||||||
: menuItemSelectedIcon;
|
: menuItemSelectedIcon;
|
||||||
const rest = omit(restProps, [
|
const rest = omit(restProps as any, [
|
||||||
'inputIcon',
|
'inputIcon',
|
||||||
'removeIcon',
|
'removeIcon',
|
||||||
'clearIcon',
|
'clearIcon',
|
||||||
|
@ -254,10 +255,10 @@ const Select = {
|
||||||
};
|
};
|
||||||
return <VcSelect {...selectProps} __propsSymbol__={[]} />;
|
return <VcSelect {...selectProps} __propsSymbol__={[]} />;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Select.install = function(app) {
|
Select.install = function(app: App) {
|
||||||
app.component(Select.name, Select);
|
app.component(Select.name, Select);
|
||||||
app.component(Select.Option.name, Select.Option);
|
app.component(Select.Option.name, Select.Option);
|
||||||
app.component(Select.OptGroup.name, Select.OptGroup);
|
app.component(Select.OptGroup.name, Select.OptGroup);
|
|
@ -28,7 +28,7 @@ export const ColumnProps = {
|
||||||
filterDropdown: PropTypes.any,
|
filterDropdown: PropTypes.any,
|
||||||
filterDropdownVisible: PropTypes.looseBool,
|
filterDropdownVisible: PropTypes.looseBool,
|
||||||
// onFilterDropdownVisibleChange?: (visible: boolean) => void;
|
// onFilterDropdownVisibleChange?: (visible: boolean) => void;
|
||||||
sorter: PropTypes.oneOfType([PropTypes.looseBoolean, PropTypes.func]),
|
sorter: PropTypes.oneOfType([PropTypes.looseBool, PropTypes.func]),
|
||||||
defaultSortOrder: PropTypes.oneOf(['ascend', 'descend']),
|
defaultSortOrder: PropTypes.oneOf(['ascend', 'descend']),
|
||||||
colSpan: PropTypes.number,
|
colSpan: PropTypes.number,
|
||||||
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
|
|
@ -21,7 +21,7 @@ export const TransferItem = {
|
||||||
export const TransferProps = {
|
export const TransferProps = {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
dataSource: PropTypes.arrayOf(PropTypes.shape(TransferItem).loose),
|
dataSource: PropTypes.arrayOf(PropTypes.shape(TransferItem).loose),
|
||||||
disabled: PropTypes.looseBoolean,
|
disabled: PropTypes.looseBool,
|
||||||
targetKeys: PropTypes.arrayOf(PropTypes.string),
|
targetKeys: PropTypes.arrayOf(PropTypes.string),
|
||||||
selectedKeys: PropTypes.arrayOf(PropTypes.string),
|
selectedKeys: PropTypes.arrayOf(PropTypes.string),
|
||||||
render: PropTypes.func,
|
render: PropTypes.func,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import PropTypes from '../../_util/vue-types';
|
||||||
|
|
||||||
export const OptionProps = {
|
export const OptionProps = {
|
||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
disabled: PropTypes.looseBoolean,
|
disabled: PropTypes.looseBool,
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
export default {
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
@ -8,4 +9,4 @@ export default {
|
||||||
render() {
|
render() {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
@ -11,4 +12,4 @@ export default {
|
||||||
render() {
|
render() {
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { TransitionGroup, withDirectives } from 'vue';
|
import { defineComponent, TransitionGroup, withDirectives } from 'vue';
|
||||||
import KeyCode from '../_util/KeyCode';
|
import KeyCode from '../_util/KeyCode';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import classnames from '../_util/classNames';
|
import classnames from '../_util/classNames';
|
||||||
|
@ -71,7 +71,7 @@ function chaining(...fns) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const Select = {
|
const Select = defineComponent({
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
Option,
|
Option,
|
||||||
OptGroup,
|
OptGroup,
|
||||||
|
@ -1599,6 +1599,6 @@ const Select = {
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
export { Select };
|
export { Select };
|
||||||
export default Select;
|
export default Select;
|
||||||
|
|
|
@ -14,9 +14,9 @@ import SingleSelector from './SingleSelector';
|
||||||
import { LabelValueType, RawValueType, CustomTagProps } from '../interface/generator';
|
import { LabelValueType, RawValueType, CustomTagProps } from '../interface/generator';
|
||||||
import { RenderNode, Mode } from '../interface';
|
import { RenderNode, Mode } from '../interface';
|
||||||
import useLock from '../hooks/useLock';
|
import useLock from '../hooks/useLock';
|
||||||
import { defineComponent, VNode, VNodeChild } from 'vue';
|
import { defineComponent, VNodeChild } from 'vue';
|
||||||
import createRef, { RefObject } from '../../_util/createRef';
|
import createRef, { RefObject } from '../../_util/createRef';
|
||||||
import PropTypes from '../../_util/vue-types copy';
|
import PropTypes from '../../_util/vue-types';
|
||||||
|
|
||||||
export interface InnerSelectorProps {
|
export interface InnerSelectorProps {
|
||||||
prefixCls: string;
|
prefixCls: string;
|
||||||
|
|
Loading…
Reference in New Issue