Skip to content

Commit 02c9fd3

Browse files
refactor(tree): component optimization (#5063)
Co-authored-by: Uyarn <[email protected]>
1 parent 9fd2e00 commit 02c9fd3

22 files changed

+54
-57
lines changed

packages/components/tree/hooks/useDragHandle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { TreeNode } from '../adapt';
2-
import { TreeProps, TypeDragEventState, TypeTreeState, TypeDragHandle } from '../tree-types';
1+
import { TreeNode } from '../utils/adapt';
2+
import { TreeProps, TypeDragEventState, TypeTreeState, TypeDragHandle } from '../types';
33
import { DragPosition } from './useDraggable';
4-
import { emitEvent } from '../util';
4+
import { emitEvent } from '../utils';
55

66
export default function useDragHandle(state: TypeTreeState) {
77
const { props, context, scope, store } = state;

packages/components/tree/hooks/useDraggable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { throttle } from 'lodash-es';
2-
import { reactive } from '../adapt';
3-
import { TypeTreeItemState } from '../tree-types';
2+
import { reactive } from '../utils/adapt';
3+
import { TypeTreeItemState } from '../types';
44

55
export interface TypeDragStates {
66
isDragOver: boolean;

packages/components/tree/hooks/useItemEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { TypeCheckboxProps, usePrefixClass } from '../adapt';
2-
import { TypeEventState, TypeTreeItemState } from '../tree-types';
1+
import { TypeCheckboxProps, usePrefixClass } from '../utils/adapt';
2+
import { TypeEventState, TypeTreeItemState } from '../types';
33
// 这里封装 tree-item 的一般事件
44
// 拖动事件,虚拟滚动事件不要安排到这里
55
export default function useItemEvents(state: TypeTreeItemState) {

packages/components/tree/hooks/useItemState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ref, toRefs, TypeSetupContext } from '../adapt';
2-
import { TypeTreeItemProps, TypeTreeItemState } from '../tree-types';
1+
import { ref, toRefs, TypeSetupContext } from '../utils/adapt';
2+
import { TypeTreeItemProps, TypeTreeItemState } from '../types';
33

44
// 提供公共对象
55
export default function useItemState(props: TypeTreeItemProps, context: TypeSetupContext) {

packages/components/tree/hooks/useRenderIcon.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { usePrefixClass, useGlobalIcon, TypeCreateElement, TLoading, TdCaretRightSmallIcon } from '../adapt';
2-
import { TypeTreeItemState } from '../tree-types';
3-
import { getTNode } from '../util';
1+
import { usePrefixClass, useGlobalIcon, TypeCreateElement, TLoading, TdCaretRightSmallIcon } from '../utils/adapt';
2+
import { TypeTreeItemState } from '../types';
3+
import { getTNode } from '../utils';
44

55
// 渲染节点图标
66
export default function useRenderIcon(state: TypeTreeItemState) {

packages/components/tree/hooks/useRenderLabel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isBoolean } from 'lodash-es';
2-
import { usePrefixClass, TypeCreateElement, computed, TCheckBox, TypeVNode } from '../adapt';
3-
import { TypeTreeItemState } from '../tree-types';
4-
import { getTNode } from '../util';
2+
import { usePrefixClass, TypeCreateElement, computed, TCheckBox, TypeVNode } from '../utils/adapt';
3+
import { TypeTreeItemState } from '../types';
4+
import { getTNode } from '../utils';
55
import useItemEvents from './useItemEvents';
66

77
// 渲染节点文本与内容

packages/components/tree/hooks/useRenderLine.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { usePrefixClass, TypeCreateElement, TreeNode, TypeVNode } from '../adapt';
2-
import { TypeTreeItemState } from '../tree-types';
3-
import { getTNode } from '../util';
1+
import { usePrefixClass, TypeCreateElement, TreeNode, TypeVNode } from '../utils/adapt';
2+
import { TypeTreeItemState } from '../types';
3+
import { getTNode } from '../utils';
44

55
// 渲染节点连线
66
export default function useRenderLine(state: TypeTreeItemState) {

packages/components/tree/hooks/useRenderOperations.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { usePrefixClass, TypeCreateElement, TypeVNode } from '../adapt';
2-
import { TypeTreeItemState } from '../tree-types';
3-
import { getTNode } from '../util';
1+
import { usePrefixClass, TypeCreateElement, TypeVNode } from '../utils/adapt';
2+
import { TypeTreeItemState } from '../types';
3+
import { getTNode } from '../utils';
44

55
// 渲染节点操作区域
66
export default function useRenderOperations(state: TypeTreeItemState) {

packages/components/tree/hooks/useTreeAction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { usePrefixClass } from '../adapt';
1+
import { usePrefixClass } from '../utils/adapt';
22
import {
33
TreeNodeValue,
44
TypeTreeState,
55
TypeTargetNode,
66
TypeExpandEventContext,
77
TypeActiveEventContext,
88
TypeChangeEventContext,
9-
} from '../tree-types';
10-
import { getNode, pathMatchClass } from '../util';
9+
} from '../types';
10+
import { getNode, pathMatchClass } from '../utils';
1111

1212
// tree 组件节点状态设置
1313
export default function useTreeAction(state: TypeTreeState) {

packages/components/tree/hooks/useTreeEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { TreeProps, TypeTreeState, TypeEventState } from '../tree-types';
2-
import { getMark, emitEvent } from '../util';
1+
import { TreeProps, TypeTreeState, TypeEventState } from '../types';
2+
import { getMark, emitEvent } from '../utils';
33
import useTreeAction from './useTreeAction';
44

55
// tree 组件一般事件处理

packages/components/tree/hooks/useTreeItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { onMounted, reactive, TypeCreateElement, usePrefixClass, useLazyLoad, TypeVNode } from '../adapt';
2-
import { TypeTreeItemState } from '../tree-types';
1+
import { onMounted, reactive, TypeCreateElement, usePrefixClass, useLazyLoad, TypeVNode } from '../utils/adapt';
2+
import { TypeTreeItemState } from '../types';
33
import useItemEvents from './useItemEvents';
44
import useRenderIcon from './useRenderIcon';
55
import useRenderLabel from './useRenderLabel';

packages/components/tree/hooks/useTreeNodes.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ref, watch, TypeCreateElement, privateKey, TypeVNode } from '../adapt';
2-
import { TypeTreeRow, TypeTreeNode, TypeTreeState } from '../tree-types';
1+
import { ref, watch, TypeCreateElement, privateKey, TypeVNode } from '../utils/adapt';
2+
import { TypeTreeRow, TypeTreeNode, TypeTreeState } from '../types';
33
import TreeItem from '../tree-item';
44
import useTreeEvents from './useTreeEvents';
55

packages/components/tree/hooks/useTreeScroll.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { computed, onMounted, TypeRef, useVirtualScrollNew, TypeScroll, TreeNode } from '../adapt';
1+
import { computed, onMounted, TypeRef, TypeScroll, TreeNode } from '../utils/adapt';
22
import { get } from 'lodash-es';
3-
import { TypeTreeState, TypeTimer } from '../tree-types';
3+
import { TypeTreeState, TypeTimer } from '../types';
44
import log from '@tdesign/common-js/log/index';
5+
import { useVirtualScrollNew } from '@tdesign/shared-hooks';
56

67
import type { ComponentScrollToElementParams } from '../../common';
78

packages/components/tree/hooks/useTreeState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ref, TypeRef, TreeNode, useVModel, toRefs, TypeSetupContext } from '../adapt';
2-
import { TreeProps, TypeTreeStore, TypeTreeState } from '../tree-types';
1+
import { ref, TypeRef, TreeNode, useVModel, toRefs, TypeSetupContext } from '../utils/adapt';
2+
import { TreeProps, TypeTreeStore, TypeTreeState } from '../types';
33

44
// 提供公共对象
55
export default function useTreeState(props: TreeProps, context: TypeSetupContext) {

packages/components/tree/hooks/useTreeStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { pick } from 'lodash-es';
22
import { TreeStore } from '@tdesign/common-js/tree/tree-store';
3-
import { watch, TypeRef } from '../adapt';
3+
import { watch, TypeRef } from '../utils/adapt';
44
import {
55
TreeProps,
66
TypeValueMode,
@@ -10,7 +10,7 @@ import {
1010
TypeTreeNode,
1111
TypeTNodeValue,
1212
TypeTreeState,
13-
} from '../tree-types';
13+
} from '../types';
1414

1515
export default function useTreeStore(state: TypeTreeState) {
1616
const { props, context, refProps } = state;

packages/components/tree/hooks/useTreeStyles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { computed, TypeStyles, usePrefixClass } from '../adapt';
2-
import { TypeTreeState } from '../tree-types';
1+
import { computed, TypeStyles, usePrefixClass } from '../utils/adapt';
2+
import { TypeTreeState } from '../types';
33

44
export function formatCSSUnit(unit: string | number) {
55
if (!unit) return unit;

packages/components/tree/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import _TdTree from './tree';
2-
import { withInstall } from './adapt';
2+
import { withInstall } from './utils/adapt';
33

44
import './style';
55

66
export const Tree = withInstall(_TdTree);
77

8-
export * from './tree-types';
8+
export * from './types';
99
export default Tree;

packages/components/tree/tree-item.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
TreeItemDefinition,
77
useRipple,
88
getCreateElement,
9-
} from './adapt';
10-
import { TypeTreeItemProps } from './tree-types';
9+
} from './utils/adapt';
10+
import { TypeTreeItemProps } from './types';
1111
import useItemState from './hooks/useItemState';
1212
import useTreeItem from './hooks/useTreeItem';
1313

packages/components/tree/tree.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
TypeTreeOptionData,
1212
useConfig,
1313
usePrefixClass,
14-
} from './adapt';
14+
} from './utils/adapt';
1515
import useDragHandle from './hooks/useDragHandle';
1616
import useTreeAction from './hooks/useTreeAction';
1717
import useTreeNodes from './hooks/useTreeNodes';
@@ -20,8 +20,8 @@ import useTreeState from './hooks/useTreeState';
2020
import useTreeStore from './hooks/useTreeStore';
2121
import useTreeStyles from './hooks/useTreeStyles';
2222
import props from './props';
23-
import { TreeNodeState, TreeNodeValue, TypeTreeNodeModel } from './tree-types';
24-
import { getNode } from './util';
23+
import { TreeNodeState, TreeNodeValue, TypeTreeNodeModel } from './types';
24+
import { getNode } from './utils';
2525
import { useTNodeJSX } from '@tdesign/shared-hooks';
2626

2727
// 2022.11.02 tabliang 备注
@@ -36,11 +36,7 @@ export default defineComponent({
3636
prop: 'value',
3737
event: 'change',
3838
},
39-
40-
props: {
41-
...props,
42-
},
43-
39+
props,
4440
setup(props, context) {
4541
const { t, global } = useConfig('tree');
4642
const classPrefix = usePrefixClass();

packages/components/tree/tree-types.ts renamed to packages/components/tree/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
TreeProps as AdaptTreeProps,
1414
TypeTreeInstance as AdaptTypeTreeInstance,
1515
TypeSetupContext,
16-
} from './adapt';
16+
} from './utils/adapt';
1717
import { TreeStore } from '@tdesign/common-js/tree/tree-store';
1818

1919
import { TdTreeProps, TreeNodeModel, TreeNodeValue, TreeNodeState } from './type';

packages/components/tree/adapt.ts renamed to packages/components/tree/utils/adapt.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// 除此文件之外的其他组件文件,可从 vue2 项目直接复制到 vue3 项目进行维护
33
import * as Vue from 'vue';
44
import { Ref, SetupContext, ToRefs, VNode, PropType, ComponentPublicInstance, UnwrapNestedRefs } from 'vue';
5-
import { CheckboxProps } from '../checkbox';
6-
import { ClassName, TScroll, Styles, TNode, TreeOptionData, TNodeReturnValue } from '../common';
5+
import { CheckboxProps } from '../../checkbox';
6+
import { ClassName, TScroll, Styles, TNode, TreeOptionData, TNodeReturnValue } from '../../common';
77
import { TypeTreeEventState as TreeEventState } from '@tdesign/common-js/tree/types';
8-
import { TdTreeProps, TreeInstanceFunctions } from './type';
8+
import { TdTreeProps, TreeInstanceFunctions } from '../type';
99
import {
1010
VirtualScrollConfig,
1111
useVModel as tdUseVModel,
@@ -17,8 +17,8 @@ import { TreeStore } from '@tdesign/common-js/tree/tree-store';
1717

1818
export { ref, reactive, computed, watch, onMounted, toRefs, defineComponent, TransitionGroup } from 'vue';
1919
export { CaretRightSmallIcon as TdCaretRightSmallIcon } from 'tdesign-icons-vue-next';
20-
export { Checkbox as TCheckBox } from '../checkbox';
21-
export { Loading as TLoading } from '../loading';
20+
export { Checkbox as TCheckBox } from '../../checkbox';
21+
export { Loading as TLoading } from '../../loading';
2222
export { useConfig, usePrefixClass } from '@tdesign/shared-hooks';
2323
export { useGlobalIcon } from '@tdesign/shared-hooks';
2424
export { useLazyLoad } from '@tdesign/shared-hooks';

packages/components/tree/util.ts renamed to packages/components/tree/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TypeTNodeProp,
1010
TypeGetTNodeOption,
1111
TypeTargetNode,
12-
} from './tree-types';
12+
} from '../types';
1313

1414
export function emitEvent<T extends any[]>(
1515
props: TreeProps & Record<string, any>,

0 commit comments

Comments
 (0)