From 513d989cc5ddcc5961175d5128c0bfa7ef95350f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sun, 26 Jan 2025 07:12:39 +0800 Subject: [PATCH 1/6] chore: use rc-component/util --- .gitignore | 1 + package.json | 12 ++++++------ src/Portal.tsx | 11 +++++------ src/useDom.tsx | 14 ++++++++------ src/useScrollLocker.tsx | 14 ++++++++------ tests/index.test.tsx | 2 +- tests/webkit.test.tsx | 7 +++---- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 21dbd0b..7b52cf3 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ coverage yarn.lock /es/ package-lock.json +pnpm-lock.yaml .doc # dumi diff --git a/package.json b/package.json index 036c123..99f4897 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rc-component/portal", - "version": "1.1.2", + "version": "2.0.0", "description": "React Portal Component", "keywords": [ "react", @@ -45,8 +45,8 @@ }, "dependencies": { "@babel/runtime": "^7.18.0", - "classnames": "^2.3.2", - "rc-util": "^5.24.4" + "@rc-component/util": "^1.2.0", + "classnames": "^2.3.2" }, "devDependencies": { "@rc-component/father-plugin": "^1.0.0", @@ -54,9 +54,10 @@ "@testing-library/react": "^13.0.0", "@types/jest": "^26.0.20", "@types/node": "^20.9.0", - "@types/react": "^18.0.0", - "@types/react-dom": "^18.0.0", + "@types/react": "^19.0.8", + "@types/react-dom": "^19.0.3", "@umijs/fabric": "^3.0.0", + "cheerio": "1.0.0-rc.12", "dumi": "^2.0.0", "eslint": "^7.18.0", "father": "^4.0.0", @@ -67,7 +68,6 @@ "react": "^18.0.0", "react-dom": "^18.0.0", "typescript": "^5.0.0", - "cheerio": "1.0.0-rc.12", "umi-test": "^1.9.7" }, "peerDependencies": { diff --git a/src/Portal.tsx b/src/Portal.tsx index 5fc4d79..0423ad9 100644 --- a/src/Portal.tsx +++ b/src/Portal.tsx @@ -1,8 +1,8 @@ import * as React from 'react'; import { createPortal } from 'react-dom'; -import canUseDom from 'rc-util/lib/Dom/canUseDom'; -import warning from 'rc-util/lib/warning'; -import { supportRef, useComposeRef } from 'rc-util/lib/ref'; +import canUseDom from '@rc-component/util/lib/Dom/canUseDom'; +import warning from '@rc-component/util/lib/warning'; +import { supportRef, useComposeRef } from '@rc-component/util/lib/ref'; import OrderContext from './Context'; import useDom from './useDom'; import useScrollLocker from './useScrollLocker'; @@ -125,10 +125,9 @@ const Portal = React.forwardRef((props, ref) => { const renderInline = mergedContainer === false || inlineMock(); let reffedChildren = children; + if (ref) { - reffedChildren = React.cloneElement(children as any, { - ref: mergedRef, - }); + reffedChildren = React.cloneElement(children as any, { ref: mergedRef }); } return ( diff --git a/src/useDom.tsx b/src/useDom.tsx index 784aaae..a64b77d 100644 --- a/src/useDom.tsx +++ b/src/useDom.tsx @@ -1,19 +1,19 @@ import * as React from 'react'; -import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; -import canUseDom from 'rc-util/lib/Dom/canUseDom'; +import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import canUseDom from '@rc-component/util/lib/Dom/canUseDom'; import OrderContext from './Context'; import type { QueueCreate } from './Context'; -const EMPTY_LIST = []; +const EMPTY_LIST: VoidFunction[] = []; /** * Will add `div` to document. Nest call will keep order * @param render Render DOM in document */ -export default function useDom( +const useDom = ( render: boolean, debug?: string, -): [HTMLDivElement, QueueCreate] { +): [HTMLDivElement, QueueCreate] => { const [ele] = React.useState(() => { if (!canUseDom()) { return null; @@ -82,4 +82,6 @@ export default function useDom( }, [queue]); return [ele, mergedQueueCreate]; -} +}; + +export default useDom; diff --git a/src/useScrollLocker.tsx b/src/useScrollLocker.tsx index febc78b..e386f30 100644 --- a/src/useScrollLocker.tsx +++ b/src/useScrollLocker.tsx @@ -1,14 +1,14 @@ import * as React from 'react'; -import { updateCSS, removeCSS } from 'rc-util/lib/Dom/dynamicCSS'; -import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; -import { getTargetScrollBarSize } from 'rc-util/lib/getScrollBarSize'; +import { updateCSS, removeCSS } from '@rc-component/util/lib/Dom/dynamicCSS'; +import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import { getTargetScrollBarSize } from '@rc-component/util/lib/getScrollBarSize'; import { isBodyOverflowing } from './util'; -const UNIQUE_ID = `rc-util-locker-${Date.now()}`; +const UNIQUE_ID = `@rc-component/util-locker-${Date.now()}`; let uuid = 0; -export default function useScrollLocker(lock?: boolean) { +const useScrollLocker = (lock?: boolean) => { const mergedLock = !!lock; const [id] = React.useState(() => { uuid += 1; @@ -36,4 +36,6 @@ html body { removeCSS(id); }; }, [mergedLock, id]); -} +}; + +export default useScrollLocker; diff --git a/tests/index.test.tsx b/tests/index.test.tsx index c433ea0..49ea581 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -13,7 +13,7 @@ jest.mock('../src/util', () => { }); // Revert `useLayoutEffect` back to real one since we should keep order for test -jest.mock('rc-util/lib/hooks/useLayoutEffect', () => { +jest.mock('@rc-component/util/lib/hooks/useLayoutEffect', () => { const origin = jest.requireActual('react'); return origin.useLayoutEffect; }); diff --git a/tests/webkit.test.tsx b/tests/webkit.test.tsx index 48757a2..7fc95ca 100644 --- a/tests/webkit.test.tsx +++ b/tests/webkit.test.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { render } from '@testing-library/react'; import Portal from '../src'; -import { updateCSS } from 'rc-util/lib/Dom/dynamicCSS'; jest.mock('../src/util', () => { const origin = jest.requireActual('../src/util'); @@ -12,14 +11,14 @@ jest.mock('../src/util', () => { }); // Revert `useLayoutEffect` back to real one since we should keep order for test -jest.mock('rc-util/lib/hooks/useLayoutEffect', () => { +jest.mock('@rc-component/util/lib/hooks/useLayoutEffect', () => { const origin = jest.requireActual('react'); return origin.useLayoutEffect; }); // Revert `useLayoutEffect` back to real one since we should keep order for test -jest.mock('rc-util/lib/getScrollBarSize', () => { - const origin = jest.requireActual('rc-util/lib/getScrollBarSize'); +jest.mock('@rc-component/util/lib/getScrollBarSize', () => { + const origin = jest.requireActual('@rc-component/util/lib/getScrollBarSize'); return { ...origin, From 63b5d8415a44241b293c2ffd84f8b9dee1c1ccff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sun, 26 Jan 2025 07:15:50 +0800 Subject: [PATCH 2/6] docs update --- docs/examples/getContainer.tsx | 2 +- tests/index.test.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/examples/getContainer.tsx b/docs/examples/getContainer.tsx index 1cf2c0b..b8ee9b1 100644 --- a/docs/examples/getContainer.tsx +++ b/docs/examples/getContainer.tsx @@ -10,7 +10,7 @@ const Content = (): React.ReactElement => { }; export default () => { - const divRef = React.useRef(); + const divRef = React.useRef(null); return (
{ }; const Demo = () => { - const divRef = React.useRef(); + const divRef = React.useRef(null); return (
@@ -231,7 +231,7 @@ describe('Portal', () => { let checked = false; const Demo = ({ open }: { open?: boolean }) => { - const pRef = React.useRef(); + const pRef = React.useRef(null); React.useEffect(() => { if (open) { From 1e625ffcb2bcec7f48d6872f7f1bf67073d2c809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sun, 26 Jan 2025 07:21:19 +0800 Subject: [PATCH 3/6] fix: fix --- package.json | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 99f4897..1bc7218 100644 --- a/package.json +++ b/package.json @@ -50,9 +50,9 @@ }, "devDependencies": { "@rc-component/father-plugin": "^1.0.0", - "@testing-library/jest-dom": "^5.16.4", - "@testing-library/react": "^13.0.0", - "@types/jest": "^26.0.20", + "@testing-library/jest-dom": "^6.6.3", + "@testing-library/react": "^16.2.0", + "@types/jest": "^29.5.14", "@types/node": "^20.9.0", "@types/react": "^19.0.8", "@types/react-dom": "^19.0.3", @@ -65,15 +65,11 @@ "glob": "^10.0.0", "np": "^5.0.3", "prettier": "^2.1.2", - "react": "^18.0.0", - "react-dom": "^18.0.0", + "react": "^19.0.0", + "react-dom": "^19.0.0", "typescript": "^5.0.0", "umi-test": "^1.9.7" }, - "peerDependencies": { - "react": ">=16.9.0", - "react-dom": ">=16.9.0" - }, "engines": { "node": ">=8.x" } From ba38c9925d79c3c299c073237176b4fac940dc9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Sun, 26 Jan 2025 07:22:25 +0800 Subject: [PATCH 4/6] fix: fix --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 1bc7218..5556244 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,10 @@ "typescript": "^5.0.0", "umi-test": "^1.9.7" }, + "peerDependencies": { + "react": ">=16.9.0", + "react-dom": ">=16.9.0" + }, "engines": { "node": ">=8.x" } From 0f7ff351c5ad4f4bffeedd20e83efbbba1ebd4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Tue, 28 Jan 2025 14:41:32 +0800 Subject: [PATCH 5/6] chore: rerun --- src/Portal.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Portal.tsx b/src/Portal.tsx index 0423ad9..c8f5a6c 100644 --- a/src/Portal.tsx +++ b/src/Portal.tsx @@ -26,7 +26,6 @@ export interface PortalProps { autoDestroy?: boolean; /** Lock screen scroll when open */ autoLock?: boolean; - /** @private debug name. Do not use in prod */ debug?: string; } From ce0366ec286c4d19d53f31a33bad583fa0e2ae78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Thu, 30 Jan 2025 18:14:10 +0800 Subject: [PATCH 6/6] fix: fix --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5556244..17c54dd 100644 --- a/package.json +++ b/package.json @@ -65,8 +65,8 @@ "glob": "^10.0.0", "np": "^5.0.3", "prettier": "^2.1.2", - "react": "^19.0.0", - "react-dom": "^19.0.0", + "react": "^18.0.0", + "react-dom": "^18.0.0", "typescript": "^5.0.0", "umi-test": "^1.9.7" },