Skip to content

Commit 76ee4d6

Browse files
committed
refactor: tree-select
1 parent 1581943 commit 76ee4d6

File tree

18 files changed

+97
-121
lines changed

18 files changed

+97
-121
lines changed

components/_util/props-util/initDefaultProps.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ const initDefaultProps = <T>(
1717
Object.keys(defaultProps).forEach(k => {
1818
const prop = propTypes[k] as VueTypeValidableDef;
1919
if (prop) {
20-
prop.default = defaultProps[k];
20+
if (prop.type || prop.default) {
21+
prop.default = defaultProps[k];
22+
} else if (prop.def) {
23+
prop.def(defaultProps[k]);
24+
} else {
25+
propTypes[k] = { type: prop, default: defaultProps[k] };
26+
}
2127
} else {
2228
throw new Error(`not have ${k} prop`);
2329
}

components/tree-select/index.tsx

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import VcTreeSelect, {
1111
import classNames from '../_util/classNames';
1212
import initDefaultProps from '../_util/props-util/initDefaultProps';
1313
import type { SizeType } from '../config-provider';
14-
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
15-
import CaretDownOutlined from '@ant-design/icons-vue/CaretDownOutlined';
1614
import type { DefaultValueType, FieldNames } from '../vc-tree-select/interface';
1715
import omit from '../_util/omit';
1816
import PropTypes from '../_util/vue-types';
@@ -237,78 +235,6 @@ const TreeSelect = defineComponent({
237235
);
238236
};
239237
},
240-
241-
methods: {
242-
saveTreeSelect(node: any) {
243-
this.vcTreeSelect = node;
244-
},
245-
focus() {
246-
this.vcTreeSelect.focus();
247-
},
248-
249-
blur() {
250-
this.vcTreeSelect.blur();
251-
},
252-
renderSwitcherIcon(prefixCls: string, { isLeaf, loading }) {
253-
if (loading) {
254-
return <LoadingOutlined class={`${prefixCls}-switcher-loading-icon`} />;
255-
}
256-
if (isLeaf) {
257-
return null;
258-
}
259-
return <CaretDownOutlined class={`${prefixCls}-switcher-icon`} />;
260-
},
261-
handleChange(...args: any[]) {
262-
this.$emit('update:value', args[0]);
263-
this.$emit('change', ...args);
264-
},
265-
handleTreeExpand(...args: any[]) {
266-
this.$emit('update:treeExpandedKeys', args[0]);
267-
this.$emit('treeExpand', ...args);
268-
},
269-
handleSearch(...args: any[]) {
270-
this.$emit('update:searchValue', args[0]);
271-
this.$emit('search', ...args);
272-
},
273-
updateTreeData(treeData: any[]) {
274-
const { $slots } = this;
275-
const defaultFields = {
276-
children: 'children',
277-
title: 'title',
278-
key: 'key',
279-
label: 'label',
280-
value: 'value',
281-
};
282-
const replaceFields = { ...defaultFields, ...this.$props.replaceFields };
283-
return treeData.map(item => {
284-
const { slots = {} } = item;
285-
const label = item[replaceFields.label];
286-
const title = item[replaceFields.title];
287-
const value = item[replaceFields.value];
288-
const key = item[replaceFields.key];
289-
const children = item[replaceFields.children];
290-
let newLabel = typeof label === 'function' ? label() : label;
291-
let newTitle = typeof title === 'function' ? title() : title;
292-
if (!newLabel && slots.label && $slots[slots.label]) {
293-
newLabel = <>{$slots[slots.label](item)}</>;
294-
}
295-
if (!newTitle && slots.title && $slots[slots.title]) {
296-
newTitle = <>{$slots[slots.title](item)}</>;
297-
}
298-
const treeNodeProps = {
299-
...item,
300-
title: newTitle || newLabel,
301-
value,
302-
dataRef: item,
303-
key,
304-
};
305-
if (children) {
306-
return { ...treeNodeProps, children: this.updateTreeData(children) };
307-
}
308-
return treeNodeProps;
309-
});
310-
},
311-
},
312238
});
313239

314240
/* istanbul ignore next */

components/tree/Tree.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import PropTypes from '../_util/vue-types';
88
import { filterEmpty } from '../_util/props-util';
99
import initDefaultProps from '../_util/props-util/initDefaultProps';
1010
import type { DataNode, DragNodeEvent, FieldNames, Key } from '../vc-tree/interface';
11+
import type { TreeNodeProps } from '../vc-tree/props';
1112
import { treeProps as vcTreeProps } from '../vc-tree/props';
1213
import useConfigInject from '../_util/hooks/useConfigInject';
1314
import renderSwitcherIcon from './utils/iconUtil';
@@ -35,7 +36,7 @@ export interface AntdTreeNodeAttribute {
3536
disableCheckbox: boolean;
3637
}
3738

38-
export type AntTreeNodeProps = DataNode;
39+
export type AntTreeNodeProps = TreeNodeProps;
3940

4041
// [Legacy] Compatible for v2
4142
export type TreeDataItem = DataNode;

components/tree/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export {
1111
AntTreeNodeCheckedEvent,
1212
AntTreeNodeSelectedEvent,
1313
AntdTreeNodeAttribute,
14-
AntTreeNodeProps,
1514
TreeDataItem,
1615
} from './Tree';
1716

components/tree/utils/dictUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DataNode, Key } from 'ant-design-vue/es/vc-tree/interface';
1+
import type { DataNode, Key } from '../../vc-tree/interface';
22

33
enum Record {
44
None,

components/tree/utils/iconUtil.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import MinusSquareOutlined from '@ant-design/icons-vue/MinusSquareOutlined';
44
import PlusSquareOutlined from '@ant-design/icons-vue/PlusSquareOutlined';
55
import CaretDownFilled from '@ant-design/icons-vue/CaretDownFilled';
66
import type { AntTreeNodeProps } from '../Tree';
7-
import { isValidElement } from 'ant-design-vue/es/_util/props-util';
7+
import { isValidElement } from '../../_util/props-util';
88

99
import { cloneVNode } from 'vue';
1010

components/vc-select/Selector/SingleSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { VNodeChild } from 'vue';
55
import { Fragment } from 'vue';
66
import { computed, defineComponent, ref, watch } from 'vue';
77
import PropTypes from '../../_util/vue-types';
8-
import { useInjectTreeSelectContext } from 'ant-design-vue/es/vc-tree-select/Context';
8+
import { useInjectTreeSelectContext } from '../../vc-tree-select/Context';
99

1010
interface SelectorProps extends InnerSelectorProps {
1111
inputElement: VNodeChild;

components/vc-select/generate.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ export default function generateSelector<
10341034
internalProps = {},
10351035

10361036
...restProps
1037-
} = props; //as SelectProps<OptionType[], ValueType>;
1037+
} = { ...props, ...attrs }; //as SelectProps<OptionType[], ValueType>;
10381038
// ============================= Input ==============================
10391039
// Only works in `combobox`
10401040
const customizeInputElement: VNodeChild | JSX.Element =
@@ -1144,9 +1144,8 @@ export default function generateSelector<
11441144
});
11451145
return (
11461146
<div
1147-
{...attrs}
1148-
class={mergedClassName}
11491147
{...domProps}
1148+
class={mergedClassName}
11501149
ref={containerRef}
11511150
onMousedown={onInternalMouseDown}
11521151
onKeydown={onInternalKeyDown}

components/vc-tree-select/OptionList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export default defineComponent({
143143
activeKey.value = key;
144144
};
145145
expose({
146-
scrollTo: (...args: any[]) => treeRef.value.scrollTo?.(...args),
146+
scrollTo: (...args: any[]) => treeRef.value?.scrollTo?.(...args),
147147
onKeydown: (event: KeyboardEvent) => {
148148
const { which } = event;
149149
switch (which) {

components/vc-tree-select/generate.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const OMIT_PROPS: (keyof TreeSelectProps)[] = [
6464
'treeDataSimpleMode',
6565
'treeNodeLabelProp',
6666
'treeDefaultExpandedKeys',
67+
'bordered',
6768
];
6869

6970
export default function generate(config: {
@@ -236,8 +237,9 @@ export default function generate(config: {
236237
...checkedKeys.map(key => getEntityByKey(key).data.value),
237238
];
238239
rawHalfCheckedKeys.value = halfCheckedKeys;
240+
} else {
241+
[rawValues.value, rawHalfCheckedKeys.value] = [newRawValues, valueHalfCheckedKeys];
239242
}
240-
[rawValues.value, rawHalfCheckedKeys.value] = [newRawValues, valueHalfCheckedKeys];
241243
});
242244

243245
const selectValues = useSelectValues(rawValues, {
@@ -378,7 +380,7 @@ export default function generate(config: {
378380
option: DataNode,
379381
source: SelectSource,
380382
) => {
381-
const eventValue = mergedLabelInValue.value ? selectValue : selectValue;
383+
const eventValue = selectValue;
382384

383385
let newRawValues = removeValue(rawValues.value, selectValue);
384386

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