Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor(design): remove rc-virtual-list for Tree (#6631)

白熱b77794fd3c5e
diff --git a/packages/design/package.json b/packages/design/package.json
index 08a5f540cb..384c93c81c 100644
--- a/packages/design/package.json
+++ b/packages/design/package.json
@@ -81,7 +81,6 @@
"dayjs": "^1.11.19",
"rc-dropdown": "^4.2.1",
"rc-menu": "^9.16.0",
- "rc-virtual-list": "^3.16.1",
"react-grid-layout": "^1.5.1",
"react-transition-group": "^4.4.5",
"sonner": "^2.0.7",
diff --git a/packages/design/src/components/tree/Tree.tsx b/packages/design/src/components/tree/Tree.tsx
index 1294eb3a23..3a61ca4f7c 100644
--- a/packages/design/src/components/tree/Tree.tsx
+++ b/packages/design/src/components/tree/Tree.tsx
@@ -16,13 +16,12 @@
import type { CSSProperties, ReactNode } from 'react';
import { DropdownIcon } from '@univerjs/icons';
-import VirtualList from 'rc-virtual-list';
import { useEffect, useMemo, useState } from 'react';
import { clsx } from '../../helper/clsx';
import { Checkbox } from '../checkbox/Checkbox';
import { Tooltip } from '../tooltip/Tooltip';
+import { VirtualList } from '../virtual-list';
import { createCacheWithFindNodePathFromTree, isIntermediated } from './util';
-import './index.css';
export enum TreeSelectionMode {
ONLY_LEAF_NODE,
@@ -143,18 +142,19 @@ export function Tree(props: ITreeProps) {
return (
<div
key={key}
- className={clsx('univer-tree-list-item', treeNodeClassName)}
+ className={clsx('univer-relative univer-text-[13px]', treeNodeClassName)}
style={{ paddingLeft: `${level * 20}px` }}
>
<div
- className={clsx('univer-tree-list-item-content', {
- 'univer-tree-list-item-content-selected': selected,
- })}
+ className="univer-relative univer-my-1 univer-flex univer-w-full univer-items-center"
>
{treeItem.children && treeItem.children.length > 0 && (
<span
- className={clsx('univer-tree-icon', {
- 'univer-tree-icon-expand': expended,
+ className={clsx(`
+ univer-absolute univer-left-[-16px] univer-top-1/2 univer-flex univer--translate-y-1/2
+ univer-items-center univer-justify-center univer-text-[8px]
+ `, {
+ 'univer-rotate-[-90deg]': !expended,
})}
onClick={(e) => {
e.stopPropagation();
@@ -172,7 +172,10 @@ export function Tree(props: ITreeProps) {
}}
/>
<div
- className="univer-tree-list-item-title"
+ className="
+ univer-mx-1 univer-inline-block univer-h-full univer-shrink univer-overflow-hidden
+ univer-text-ellipsis univer-whitespace-nowrap
+ "
onClick={(e) => {
e.stopPropagation();
handleExpendItem(treeItem);
@@ -192,8 +195,13 @@ export function Tree(props: ITreeProps) {
}
return (
- <section className="univer-tree">
- <div className="univer-tree-list" style={style}>
+ <section
+ className="
+ univer-relative univer-select-none univer-text-gray-900
+ dark:!univer-text-white
+ "
+ >
+ <div className="univer-m-0 univer-h-full univer-list-none univer-p-0" style={style}>
<VirtualList
data={flatData}
itemKey={(item) => item.key}
diff --git a/packages/design/src/components/tree/index.css b/packages/design/src/components/tree/index.css
deleted file mode 100644
index 5876764218..0000000000
--- a/packages/design/src/components/tree/index.css
+++ /dev/null
@@ -1,85 +0,0 @@
-.univer-tree {
- user-select: none;
- position: relative;
- @apply univer-text-gray-900;
-}
-.univer-dark .univer-tree {
- @apply univer-text-white;
-}
-
-.univer-tree-icon {
- position: absolute;
- top: 50%;
- left: calc(-1 * 16px);
- transform: translateY(-50%) rotateZ(-90deg);
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 8px;
-}
-
-.univer-tree-icon-expand {
- transform: translateY(-50%);
-}
-
-.univer-tree-list {
- margin: 0;
- padding: 0;
- list-style: none;
- height: 100%;
-}
-
-.univer-tree-list .univer-tree-list {
- overflow: hidden;
- height: 0;
-}
-
-.univer-tree-list .univer-tree-list-expand {
- height: inherit;
-}
-
-.univer-tree-list-item {
- position: relative;
- padding-left: 20px;
- font-size: 13px;
-}
-
-.univer-tree-list-item > a {
- position: relative;
- display: flex;
- align-items: center;
- cursor: pointer;
-}
-
-.univer-tree-list-item-title {
- display: inline-block;
- height: 100%;
- margin: 0 4px;
- flex-shrink: 1;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
-}
-
-.univer-tree-list-item-content {
- margin: 4px 0;
- width: 100%;
- position: relative;
- display: flex;
- align-items: center;
-}
-
-.univer-tree-list-item-content-selected-icon {
- position: absolute;
- top: 50%;
- left: calc(-1 * 20px);
- transform: translateY(-50%);
- display: flex;
- align-items: center;
- justify-content: center;
- @apply univer-text-base;
-}
-
-.univer-wrap-anywhere {
- overflow-wrap: anywhere;
-}
diff --git a/packages/design/src/components/virtual-list/VirtualList.tsx b/packages/design/src/components/virtual-list/VirtualList.tsx
new file mode 100644
index 0000000000..b56b6ddeea
--- /dev/null
+++ b/packages/design/src/components/virtual-list/VirtualList.tsx
@@ -0,0 +1,82 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { CSSProperties, Key, ReactNode } from 'react';
+import { useState } from 'react';
+
+export interface IVirtualListProps<T extends object> {
+ data: T[];
+ itemKey: Key | ((item: T) => Key);
+ children: (item: T, index: number) => ReactNode;
+ height?: number;
+ itemHeight?: number;
+ overscan?: number;
+ className?: string;
+ style?: CSSProperties;
+}
+
+export function VirtualList<T extends object>(props: IVirtualListProps<T>) {
+ const { data, itemKey, children, height, itemHeight, overscan = 2, className, style } = props;
+ const [scrollTop, setScrollTop] = useState(0);
+
+ if (!height || !itemHeight || itemHeight <= 0) {
+ return (
+ <div className={className} style={style}>
+ {data.map((item, index) => {
+ const key = typeof itemKey === 'function' ? itemKey(item) : (item[itemKey as keyof T] as Key);
+ return (
+ <div key={key}>
+ {children(item, index)}
+ </div>
+ );
+ })}
+ </div>
+ );
+ }
+
+ const start = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);
+ const visibleCount = Math.ceil(height / itemHeight) + overscan * 2;
+ const end = Math.min(data.length, start + visibleCount);
+ const offsetY = start * itemHeight;
+ const totalHeight = data.length * itemHeight;
+
+ const visibleItems = data.slice(start, end);
+
+ return (
+ <div
+ className={className}
+ style={{
+ ...style,
+ height,
+ overflowY: 'auto',
+ }}
+ onScroll={(e) => setScrollTop(e.currentTarget.scrollTop)}
+ >
+ <div style={{ height: totalHeight, position: 'relative' }}>
+ <div style={{ transform: `translateY(${offsetY}px)` }}>
+ {visibleItems.map((item, index) => {
+ const key = typeof itemKey === 'function' ? itemKey(item) : (item[itemKey as keyof T] as Key);
+ return (
+ <div key={key}>
+ {children(item, start + index)}
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/design/src/components/virtual-list/index.ts b/packages/design/src/components/virtual-list/index.ts
new file mode 100644
index 0000000000..8496379d77
--- /dev/null
+++ b/packages/design/src/components/virtual-list/index.ts
@@ -0,0 +1,17 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export { type IVirtualListProps, VirtualList } from './VirtualList';
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
index 0b3f184fac..28138c9c83 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
@@ -134,11 +134,13 @@ export function HelpFunction(props: IHelpFunctionProps) {
>
<div
className={clsx(`
- univer-wrap-anywhere univer-box-border univer-flex univer-items-center
- univer-justify-between univer-px-4 univer-py-3 univer-text-xs univer-font-medium
- univer-text-gray-900
+ univer-box-border univer-flex univer-items-center univer-justify-between univer-px-4
+ univer-py-3 univer-text-xs univer-font-medium univer-text-gray-900
dark:!univer-text-white
`, borderTopClassName)}
+ style={{
+ overflowWrap: 'anywhere',
+ }}
>
<Help
prefix={functionInfo.functionName}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 601e570531..a5f2f19880 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -904,9 +904,6 @@ importers:
rc-menu:
specifier: ^9.16.0
- rc-virtual-list:
- specifier: ^3.16.1
react-grid-layout:
specifier: ^1.5.1
@@ -9733,13 +9730,6 @@ packages:
react: 19.2.4
react-dom: 19.2.4
- resolution: {integrity: sha512-TQ5SsutL3McvWmmxqQtMIbfeoE3dGjJrRSfKekgby7WQMpPIFvv4ghytp5Z0s3D8Nik9i9YNOCqHBfk86AwgAA==}
- engines: {node: '>=8.x'}
- peerDependencies:
- react: 19.2.4
- react-dom: 19.2.4
-
resolution: {integrity: sha512-btXCnMmRIBINM2LDZoEmOogIZU7Qe7zn4BpomSKZ/ykbLObuBdvG+mFq11DL6fjH1DRwHhrlgtYWG96bJiC7Cg==}
@@ -18290,15 +18280,6 @@ snapshots:
react-dom: 19.2.4([email protected])
react-is: 18.3.1
- dependencies:
- '@babel/runtime': 7.27.1
- classnames: 2.5.1
- react: 19.2.4
- react-dom: 19.2.4([email protected])
-
dependencies:
defu: 6.1.4