Skip to content

Commit 956ed09

Browse files
committed
refactor: tree-select
1 parent b0678d7 commit 956ed09

File tree

12 files changed

+442
-311
lines changed

12 files changed

+442
-311
lines changed

components/_util/omit.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function omit<T extends object, K extends [...(keyof T)[]]>(
2+
obj: T,
3+
fields: K,
4+
): {
5+
[K2 in Exclude<keyof T, K[number]>]: T[K2];
6+
} {
7+
// eslint-disable-next-line prefer-object-spread
8+
const shallowCopy = Object.assign({}, obj);
9+
for (let i = 0; i < fields.length; i += 1) {
10+
const key = fields[i];
11+
delete shallowCopy[key];
12+
}
13+
return shallowCopy;
14+
}
15+
export default omit;

components/select/index.tsx

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { VNodeChild, App, PropType, Plugin } from 'vue';
1+
import type { App, PropType, Plugin, ExtractPropTypes } from 'vue';
22
import { computed, defineComponent, ref } from 'vue';
33
import omit from 'omit.js';
44
import classNames from '../_util/classNames';
55
import type { SelectProps as RcSelectProps } from '../vc-select';
6-
import RcSelect, { Option, OptGroup, BaseProps } from '../vc-select';
6+
import RcSelect, { Option, OptGroup, selectBaseProps } from '../vc-select';
77
import type { OptionProps as OptionPropsType } from '../vc-select/Option';
88
import getIcons from './utils/iconUtil';
99
import PropTypes from '../_util/vue-types';
@@ -20,36 +20,26 @@ export type OptionType = typeof Option;
2020
export interface LabeledValue {
2121
key?: string;
2222
value: RawValue;
23-
label: VNodeChild;
23+
label: any;
2424
}
2525
export type SelectValue = RawValue | RawValue[] | LabeledValue | LabeledValue[] | undefined;
2626

27-
export interface InternalSelectProps<VT> extends Omit<RcSelectProps<VT>, 'mode'> {
28-
suffixIcon?: VNodeChild;
29-
itemIcon?: VNodeChild;
27+
interface InternalSelectProps<VT> extends Omit<RcSelectProps<VT>, 'mode'> {
28+
suffixIcon?: any;
29+
itemIcon?: any;
3030
size?: SizeType;
3131
mode?: 'multiple' | 'tags' | 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
3232
bordered?: boolean;
3333
}
3434

35-
export interface SelectPropsTypes<VT>
36-
extends Omit<
37-
InternalSelectProps<VT>,
38-
'inputIcon' | 'mode' | 'getInputElement' | 'backfill' | 'class' | 'style'
39-
> {
35+
interface SelectPropsTypes<VT>
36+
extends Omit<InternalSelectProps<VT>, 'inputIcon' | 'mode' | 'getInputElement' | 'backfill'> {
4037
mode?: 'multiple' | 'tags';
4138
}
42-
export type SelectTypes = SelectPropsTypes<SelectValue>;
43-
export const SelectProps = () => ({
44-
...(omit(BaseProps(), [
45-
'inputIcon',
46-
'mode',
47-
'getInputElement',
48-
'backfill',
49-
'class',
50-
'style',
51-
]) as Omit<
52-
ReturnType<typeof BaseProps>,
39+
export type SelectProps = Partial<ExtractPropTypes<SelectPropsTypes<SelectValue>>>;
40+
export const selectProps = () => ({
41+
...(omit(selectBaseProps(), ['inputIcon', 'mode', 'getInputElement', 'backfill']) as Omit<
42+
SelectPropsTypes<SelectValue>,
5343
'inputIcon' | 'mode' | 'getInputElement' | 'backfill' | 'class' | 'style'
5444
>),
5545
value: {
@@ -58,9 +48,9 @@ export const SelectProps = () => ({
5848
defaultValue: {
5949
type: [Array, Object, String, Number] as PropType<SelectValue>,
6050
},
61-
notFoundContent: PropTypes.VNodeChild,
62-
suffixIcon: PropTypes.VNodeChild,
63-
itemIcon: PropTypes.VNodeChild,
51+
notFoundContent: PropTypes.any,
52+
suffixIcon: PropTypes.any,
53+
itemIcon: PropTypes.any,
6454
size: PropTypes.oneOf(tuple('small', 'middle', 'large', 'default')),
6555
mode: PropTypes.oneOf(tuple('multiple', 'tags', 'SECRET_COMBOBOX_MODE_DO_NOT_USE')),
6656
bordered: PropTypes.looseBool.def(true),
@@ -73,7 +63,7 @@ const Select = defineComponent({
7363
Option,
7464
OptGroup,
7565
inheritAttrs: false,
76-
props: SelectProps(),
66+
props: selectProps(),
7767
SECRET_COMBOBOX_MODE_DO_NOT_USE: 'SECRET_COMBOBOX_MODE_DO_NOT_USE',
7868
emits: ['change', 'update:value'],
7969
slots: [
@@ -146,7 +136,7 @@ const Select = defineComponent({
146136
const isMultiple = mode.value === 'multiple' || mode.value === 'tags';
147137

148138
// ===================== Empty =====================
149-
let mergedNotFound: VNodeChild;
139+
let mergedNotFound: any;
150140
if (notFoundContent !== undefined) {
151141
mergedNotFound = notFoundContent;
152142
} else if (slots.notFoundContent) {

components/vc-select/OptionList.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import classNames from '../_util/classNames';
55
import pickAttrs from '../_util/pickAttrs';
66
import { isValidElement } from '../_util/props-util';
77
import createRef from '../_util/createRef';
8-
import type { PropType, VNodeChild } from 'vue';
8+
import type { PropType } from 'vue';
99
import { computed, defineComponent, nextTick, reactive, watch } from 'vue';
1010
import List from '../vc-virtual-list/List';
1111
import type {
@@ -22,18 +22,18 @@ export interface RefOptionListProps {
2222
onKeyup: (e?: KeyboardEvent) => void;
2323
scrollTo?: (index: number) => void;
2424
}
25-
export interface OptionListProps {
25+
export interface OptionListProps<OptionType extends object> {
2626
prefixCls: string;
2727
id: string;
28-
options: SelectOptionsType;
29-
flattenOptions: FlattenOptionsType<SelectOptionsType>;
28+
options: OptionType[];
29+
flattenOptions: FlattenOptionsType<OptionType>;
3030
height: number;
3131
itemHeight: number;
3232
values: Set<RawValueType>;
3333
multiple: boolean;
3434
open: boolean;
3535
defaultActiveFirstOption?: boolean;
36-
notFoundContent?: VNodeChild;
36+
notFoundContent?: any;
3737
menuItemSelectedIcon?: RenderNode;
3838
childrenAsData: boolean;
3939
searchValue: string;
@@ -80,7 +80,7 @@ const OptionListProps = {
8080
* Using virtual list of option display.
8181
* Will fallback to dom if use customize render.
8282
*/
83-
const OptionList = defineComponent<OptionListProps, { state?: any }>({
83+
const OptionList = defineComponent<OptionListProps<SelectOptionsType[number]>, { state?: any }>({
8484
name: 'OptionList',
8585
inheritAttrs: false,
8686
slots: ['option'],
@@ -290,7 +290,7 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
290290
virtual,
291291
onScroll,
292292
onMouseenter,
293-
} = this.$props as OptionListProps;
293+
} = this.$props;
294294
const renderOption = $slots.option;
295295
const { activeIndex } = this.state;
296296
// ========================== Render ==========================

components/vc-select/Select.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ import generateSelector from './generate';
4747
import type { DefaultValueType } from './interface/generator';
4848
import warningProps from './utils/warningPropsUtil';
4949
import { defineComponent, ref } from 'vue';
50-
import omit from 'lodash-es/omit';
5150

52-
const RefSelect = generateSelector<SelectOptionsType>({
51+
const RefSelect = generateSelector<SelectOptionsType[number]>({
5352
prefixCls: 'rc-select',
5453
components: {
5554
optionList: SelectOptionList as any,
@@ -64,10 +63,17 @@ const RefSelect = generateSelector<SelectOptionsType>({
6463
fillOptionsWithMissingValue,
6564
});
6665

67-
export type ExportedSelectProps<ValueType extends DefaultValueType = DefaultValueType> =
68-
SelectProps<SelectOptionsType, ValueType>;
66+
export type ExportedSelectProps<T extends DefaultValueType = DefaultValueType> = SelectProps<
67+
SelectOptionsType[number],
68+
T
69+
>;
6970

70-
const Select = defineComponent<Omit<ExportedSelectProps, 'children'>>({
71+
const Select = defineComponent({
72+
name: 'Select',
73+
inheritAttrs: false,
74+
Option: Option,
75+
OptGroup: OptGroup,
76+
props: RefSelect.props,
7177
setup(props, { attrs, expose, slots }) {
7278
const selectRef = ref(null);
7379
expose({
@@ -91,8 +97,4 @@ const Select = defineComponent<Omit<ExportedSelectProps, 'children'>>({
9197
};
9298
},
9399
});
94-
Select.inheritAttrs = false;
95-
Select.props = omit(RefSelect.props, ['children']);
96-
Select.Option = Option;
97-
Select.OptGroup = OptGroup;
98100
export default Select;

components/vc-select/Selector/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export interface SelectorProps {
5757
onSearch: (searchText: string, fromTyping: boolean, isCompositing: boolean) => boolean;
5858
onSearchSubmit: (searchText: string) => void;
5959
onSelect: (value: RawValueType, option: { selected: boolean }) => void;
60-
onInputKeyDown?: EventHandlerNonNull;
60+
onInputKeyDown?: (e: KeyboardEvent) => void;
6161

6262
/**
6363
* @private get real dom for trigger align.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy