Skip to content

Commit

Permalink
Merge pull request #137 from ant-design/fix/sortable-tree
Browse files Browse the repository at this point in the history
feat: sortable tree support virtual scroll
  • Loading branch information
ONLY-yours authored Jan 2, 2024
2 parents 47041c6 + 6fc13ef commit b4e49e4
Show file tree
Hide file tree
Showing 10 changed files with 5,576 additions and 88 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
"react-layout-kit": "^1.7.4",
"react-markdown": "^8.0.7",
"react-rnd": "^10.4.1",
"react-virtualized-auto-sizer": "^1.0.20",
"react-window": "^1.8.10",
"reactflow": "^11.10.1",
"rehype-katex": "^6.0.3",
"remark-gfm": "^3.0.1",
Expand All @@ -129,6 +131,7 @@
"@types/json-schema": "^7.0.15",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@types/react-window": "^1.8.8",
"@umijs/lint": "^4.0.90",
"@vitest/coverage-v8": "latest",
"antd": "^5.12.5",
Expand Down
6 changes: 6 additions & 0 deletions src/SortableTree/components/TreeItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export interface TreeItemProps extends Omit<HTMLAttributes<HTMLLIElement>, 'id'>
* @title 样式类名前缀
*/
prefixCls: string;
/**
* 虚拟滚动添加样式
*/
virtualStyle?: CSSProperties;
}

const animateLayoutChanges: AnimateLayoutChanges = ({ isSorting, wasDragging }) =>
Expand All @@ -134,6 +138,7 @@ const TreeItem: FC<TreeItemProps> = memo(
hideRemove,
node,
prefixCls,
virtualStyle,
...props
}) => {
const prefix = `${prefixCls}-node`;
Expand Down Expand Up @@ -200,6 +205,7 @@ const TreeItem: FC<TreeItemProps> = memo(

transform: CSS.Translate.toString(transform),
transition,
...virtualStyle,
} as CSSProperties
}
onClick={(e) => {
Expand Down
9 changes: 8 additions & 1 deletion src/SortableTree/container/StoreUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SortableTreeInstance, useSortableTree } from '../hooks/useSortableTree'
import type { ControlledState, OnTreeDataChange } from '../store';
import { useStoreApi } from '../store';

import type { FlattenNode, Projected, RenderNodeProps, TreeData } from '../types';
import type { FlattenNode, Projected, RenderNodeProps, TreeData, VirtualConfig } from '../types';

export interface StoreUpdaterProps<T = any> extends ControlledState {
/**
Expand Down Expand Up @@ -46,6 +46,11 @@ export interface StoreUpdaterProps<T = any> extends ControlledState {
targetNode: FlattenNode<T>;
projected: Projected;
}) => boolean;

/**
* 开启虚拟滚动
*/
virtual?: VirtualConfig;
}

const StoreUpdater = ({
Expand All @@ -61,6 +66,7 @@ const StoreUpdater = ({
indentationWidth,
disableDrag,
sortableRule,
virtual,
}: StoreUpdaterProps) => {
const storeApi = useStoreApi();

Expand All @@ -75,6 +81,7 @@ const StoreUpdater = ({
useStoreUpdater('indentationWidth', indentationWidth);
useStoreUpdater('hideAdd', hideAdd);
useStoreUpdater('hideRemove', hideRemove);
useStoreUpdater('virtual', virtual);
useStoreUpdater('disableDrag', disableDrag);
useStoreUpdater('sortableRule', sortableRule);

Expand Down
Loading

0 comments on commit b4e49e4

Please sign in to comment.