Skip to content

Commit 139d129

Browse files
committed
chore: use @rc-component/resize-observer
1 parent 82566ea commit 139d129

14 files changed

+62
-57
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ lib/
77
~*
88
yarn.lock
99
package-lock.json
10-
!tests/__mocks__/rc-util/lib
10+
pnpm-lock.yaml
11+
!tests/__mocks__/@rc-component/util/lib
1112
bun.lockb
1213

1314
# umi

examples/animate.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as React from 'react';
55
import CSSMotion from 'rc-animate/lib/CSSMotion';
66
import classNames from 'classnames';
77
import List, { ListRef } from '../src/List';
8-
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
8+
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
99
import './animate.less';
1010

1111
let uuid = 0;
@@ -74,7 +74,7 @@ const MyItem: React.ForwardRefRenderFunction<any, MyItemProps> = (
7474
motionName="motion"
7575
motionAppear={motionAppear}
7676
onAppearStart={getCollapsedHeight}
77-
onAppearActive={node => {
77+
onAppearActive={(node) => {
7878
motionRef.current = true;
7979
return getMaxHeight(node);
8080
}}
@@ -135,7 +135,7 @@ const Demo = () => {
135135
const [animating, setAnimating] = React.useState(false);
136136
const [insertIndex, setInsertIndex] = React.useState<number>();
137137

138-
const listRef = React.useRef<ListRef>();
138+
const listRef = React.useRef<ListRef>(null);
139139

140140
const onClose = (id: string) => {
141141
setCloseMap({
@@ -145,7 +145,7 @@ const Demo = () => {
145145
};
146146

147147
const onLeave = (id: string) => {
148-
const newData = data.filter(item => item.id !== id);
148+
const newData = data.filter((item) => item.id !== id);
149149
setData(newData);
150150
};
151151

@@ -159,14 +159,14 @@ const Demo = () => {
159159
}
160160

161161
const onInsertBefore = (id: string) => {
162-
const index = data.findIndex(item => item.id === id);
162+
const index = data.findIndex((item) => item.id === id);
163163
const newData = [...data.slice(0, index), genItem(), ...data.slice(index)];
164164
setInsertIndex(index);
165165
setData(newData);
166166
lockForAnimation();
167167
};
168168
const onInsertAfter = (id: string) => {
169-
const index = data.findIndex(item => item.id === id) + 1;
169+
const index = data.findIndex((item) => item.id === id) + 1;
170170
const newData = [...data.slice(0, index), genItem(), ...data.slice(index)];
171171
setInsertIndex(index);
172172
setData(newData);

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "rc-virtual-list",
3-
"version": "3.18.1",
2+
"name": "@rc-component/virtual-list",
3+
"version": "1.0.0",
44
"description": "React Virtual List Component",
55
"engines": {
66
"node": ">=8.x"
@@ -36,9 +36,11 @@
3636
"test": "rc-test",
3737
"now-build": "npm run build"
3838
},
39-
"peerDependencies": {
40-
"react": ">=16.9.0",
41-
"react-dom": ">=16.9.0"
39+
"dependencies": {
40+
"@babel/runtime": "^7.20.0",
41+
"@rc-component/resize-observer": "^1.0.0",
42+
"@rc-component/util": "^1.2.0",
43+
"classnames": "^2.2.6"
4244
},
4345
"devDependencies": {
4446
"@rc-component/father-plugin": "^1.0.2",
@@ -47,8 +49,8 @@
4749
"@types/classnames": "^2.2.10",
4850
"@types/enzyme": "^3.10.5",
4951
"@types/jest": "^25.1.3",
50-
"@types/react": "^18.0.8",
51-
"@types/react-dom": "^18.0.3",
52+
"@types/react": "^19.0.8",
53+
"@types/react-dom": "^19.0.3",
5254
"@types/warning": "^3.0.0",
5355
"cheerio": "1.0.0-rc.12",
5456
"cross-env": "^5.2.0",
@@ -63,14 +65,12 @@
6365
"np": "^5.0.3",
6466
"rc-animate": "^2.9.1",
6567
"rc-test": "^7.0.15",
66-
"react": "16.14.0",
67-
"react-dom": "16.14.0",
68+
"react": "^19.0.0",
69+
"react-dom": "^19.0.0",
6870
"typescript": "^5.0.0"
6971
},
70-
"dependencies": {
71-
"@babel/runtime": "^7.20.0",
72-
"classnames": "^2.2.6",
73-
"rc-resize-observer": "^1.0.0",
74-
"rc-util": "^5.36.0"
72+
"peerDependencies": {
73+
"react": ">=16.9.0",
74+
"react-dom": ">=16.9.0"
7575
}
7676
}

src/Filler.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import ResizeObserver from 'rc-resize-observer';
2+
import ResizeObserver from '@rc-component/resize-observer';
33
import classNames from 'classnames';
44

55
export type InnerProps = Pick<React.HTMLAttributes<HTMLDivElement>, 'role' | 'id'>;
@@ -95,6 +95,8 @@ const Filler = React.forwardRef(
9595
},
9696
);
9797

98-
Filler.displayName = 'Filler';
98+
if (process.env.NODE_ENV !== 'production') {
99+
Filler.displayName = 'Filler';
100+
}
99101

100102
export default Filler;

src/List.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import classNames from 'classnames';
2-
import type { ResizeObserverProps } from 'rc-resize-observer';
3-
import ResizeObserver from 'rc-resize-observer';
4-
import { useEvent } from 'rc-util';
5-
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
2+
import type { ResizeObserverProps } from '@rc-component/resize-observer';
3+
import ResizeObserver from '@rc-component/resize-observer';
4+
import { useEvent } from '@rc-component/util';
5+
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
66
import * as React from 'react';
77
import { useRef, useState } from 'react';
88
import { flushSync } from 'react-dom';
@@ -148,9 +148,9 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
148148

149149
const mergedClassName = classNames(prefixCls, { [`${prefixCls}-rtl`]: isRTL }, className);
150150
const mergedData = data || EMPTY_DATA;
151-
const componentRef = useRef<HTMLDivElement>();
152-
const fillerInnerRef = useRef<HTMLDivElement>();
153-
const containerRef = useRef<HTMLDivElement>();
151+
const componentRef = useRef<HTMLDivElement>(null);
152+
const fillerInnerRef = useRef<HTMLDivElement>(null);
153+
const containerRef = useRef<HTMLDivElement>(null);
154154

155155
// =============================== Item Key ===============================
156156

@@ -190,7 +190,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
190190
// Put ref here since the range is generate by follow
191191
const rangeRef = useRef({ start: 0, end: mergedData.length });
192192

193-
const diffItemRef = useRef<T>();
193+
const diffItemRef = useRef<T>(null);
194194
const [diffItem] = useDiffItem(mergedData, getKey);
195195
diffItemRef.current = diffItem;
196196

@@ -303,8 +303,8 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
303303
};
304304

305305
// Hack on scrollbar to enable flash call
306-
const verticalScrollBarRef = useRef<ScrollBarRef>();
307-
const horizontalScrollBarRef = useRef<ScrollBarRef>();
306+
const verticalScrollBarRef = useRef<ScrollBarRef>(null);
307+
const horizontalScrollBarRef = useRef<ScrollBarRef>(null);
308308

309309
const horizontalScrollBarSpinSize = React.useMemo(
310310
() => getSpinSize(size.width, scrollWidth),
@@ -587,17 +587,15 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
587587
}
588588

589589
const containerProps: React.HTMLAttributes<HTMLDivElement> = {};
590+
590591
if (isRTL) {
591592
containerProps.dir = 'rtl';
592593
}
593594

594595
return (
595596
<div
596597
ref={containerRef}
597-
style={{
598-
...style,
599-
position: 'relative',
600-
}}
598+
style={{ ...style, position: 'relative' }}
601599
className={mergedClassName}
602600
{...containerProps}
603601
{...restProps}
@@ -669,7 +667,9 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
669667

670668
const List = React.forwardRef<ListRef, ListProps<any>>(RawList);
671669

672-
List.displayName = 'List';
670+
if (process.env.NODE_ENV !== 'production') {
671+
List.displayName = 'List';
672+
}
673673

674674
export default List as <Item = any>(
675675
props: ListProps<Item> & { ref?: React.Ref<ListRef> },

src/ScrollBar.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import raf from 'rc-util/lib/raf';
2+
import raf from '@rc-component/util/lib/raf';
33
import * as React from 'react';
44
import { getPageXY } from './hooks/useScrollDrag';
55

@@ -49,12 +49,12 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
4949
const isLTR = !rtl;
5050

5151
// ========================= Refs =========================
52-
const scrollbarRef = React.useRef<HTMLDivElement>();
53-
const thumbRef = React.useRef<HTMLDivElement>();
52+
const scrollbarRef = React.useRef<HTMLDivElement>(null);
53+
const thumbRef = React.useRef<HTMLDivElement>(null);
5454

5555
// ======================= Visible ========================
5656
const [visible, setVisible] = React.useState(showScrollBar);
57-
const visibleTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>();
57+
const visibleTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>(null);
5858

5959
const delayHidden = () => {
6060
if (showScrollBar === true || showScrollBar === false) return;
@@ -120,9 +120,9 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
120120
}, []);
121121

122122
// Pass to effect
123-
const enableScrollRangeRef = React.useRef<number>();
123+
const enableScrollRangeRef = React.useRef<number>(null);
124124
enableScrollRangeRef.current = enableScrollRange;
125-
const enableOffsetRangeRef = React.useRef<number>();
125+
const enableOffsetRangeRef = React.useRef<number>(null);
126126
enableOffsetRangeRef.current = enableOffsetRange;
127127

128128
React.useEffect(() => {

src/hooks/useFrameWheel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import raf from 'rc-util/lib/raf';
1+
import raf from '@rc-component/util/lib/raf';
22
import { useRef } from 'react';
33
import isFF from '../utils/isFirefox';
44
import useOriginScroll from './useOriginScroll';

src/hooks/useHeights.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
1+
import findDOMNode from '@rc-component/util/lib/Dom/findDOMNode';
22
import * as React from 'react';
33
import { useEffect, useRef } from 'react';
44
import type { GetKey } from '../interface';

src/hooks/useMobileTouchMove.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
1+
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
22
import type * as React from 'react';
33
import { useRef } from 'react';
44

src/hooks/useScrollDrag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import raf from 'rc-util/lib/raf';
1+
import raf from '@rc-component/util/lib/raf';
22
import * as React from 'react';
33

44
function smoothScrollOffset(offset: number) {

src/hooks/useScrollTo.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable no-param-reassign */
22
import * as React from 'react';
3-
import raf from 'rc-util/lib/raf';
3+
import raf from '@rc-component/util/lib/raf';
44
import type { GetKey } from '../interface';
55
import type CacheMap from '../utils/CacheMap';
6-
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
7-
import { warning } from 'rc-util';
6+
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
7+
import { warning } from '@rc-component/util';
88

99
const MAX_TIMES = 10;
1010

@@ -37,7 +37,7 @@ export default function useScrollTo<T>(
3737
syncScrollTop: (newTop: number) => void,
3838
triggerFlash: () => void,
3939
): (arg: number | ScrollTarget) => void {
40-
const scrollRef = React.useRef<number>();
40+
const scrollRef = React.useRef<number>(null);
4141

4242
const [syncState, setSyncState] = React.useState<{
4343
times: number;

src/mock.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const List = React.forwardRef((props: ListProps<any>, ref: React.Ref<ListRef>) =
88
props: React.PropsWithChildren<ListProps<Item>> & { ref?: React.Ref<ListRef> },
99
) => React.ReactElement;
1010

11-
(List as any).displayName = 'List';
11+
if (process.env.NODE_ENV !== 'production') {
12+
(List as any).displayName = 'List';
13+
}
1214

1315
export default List;

tests/scroll.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import '@testing-library/jest-dom';
22
import { act, createEvent, fireEvent, render } from '@testing-library/react';
33
import { mount } from 'enzyme';
4-
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
5-
import { resetWarned } from 'rc-util/lib/warning';
4+
import { _rs as onLibResize } from '@rc-component/resize-observer/lib/utils/observerUtil';
5+
import { resetWarned } from '@rc-component/util/lib/warning';
66
import React from 'react';
77
import List from '../src';
88
import { spyElementPrototypes } from './utils/domHook';

tests/scrollWidth.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '@testing-library/jest-dom';
22
import { act, fireEvent, render } from '@testing-library/react';
3-
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
4-
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
3+
import { _rs as onLibResize } from '@rc-component/resize-observer/lib/utils/observerUtil';
4+
import { spyElementPrototypes } from '@rc-component/util/lib/test/domHook';
55
import React from 'react';
66
import type { ListRef } from '../src';
77
import List, { type ListProps } from '../src';

0 commit comments

Comments
 (0)