Skip to content

Commit 657c49e

Browse files
committed
fix: 解决 drag 类型错误问题
1 parent bf8508e commit 657c49e

File tree

6 files changed

+46
-35
lines changed

6 files changed

+46
-35
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@types/react": "^18.0.14",
6666
"@types/react-dom": "^18.0.5",
6767
"@types/react-is": "^17.0.3",
68+
"@typescript-eslint/typescript-estree": "^5.36.2",
6869
"autoprefixer": "^10.4.7",
6970
"babel-loader": "^8.2.5",
7071
"conventional-changelog-cli": "^2.2.2",
@@ -98,7 +99,8 @@
9899
},
99100
"resolutions": {
100101
"**/@typescript-eslint/eslint-plugin": "^4.1.1",
101-
"**/@typescript-eslint/parser": "^4.1.1"
102+
"**/@typescript-eslint/parser": "^4.1.1",
103+
"**/@typescript-eslint/typescript-estree": "^5.30.5"
102104
},
103105
"jest": {
104106
"moduleNameMapper": {

src/hooks/useSortItem.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { CSSProperties, RefCallback, RefObject, useCallback, useEffect, useReducer, useRef } from 'react';
2-
import { DragSourceMonitor, useDrag } from 'react-dnd';
1+
import { CSSProperties, RefObject, useCallback, useEffect, useReducer, useRef } from 'react';
2+
import { ConnectDragSource, DragSourceMonitor, useDrag } from 'react-dnd';
33
import classnames from 'classnames';
44

55
import { assign, sleep } from '../utils/index';
@@ -24,7 +24,7 @@ type SortItemState<RT extends HTMLElement> = [
2424
remove: () => void;
2525
},
2626
RefObject<RT>,
27-
(ref: RefObject<any>) => RefCallback<any>
27+
ConnectDragSource
2828
];
2929

3030
export type SortItemDragStartEvent = {
@@ -228,7 +228,7 @@ function useSortItem<T extends ISortableItem, RT extends HTMLElement>(
228228
}),
229229
},
230230
ref,
231-
drag as any,
231+
drag,
232232
];
233233
}
234234

src/hooks/useSortItemRemove.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function useSortItemRemove(id: string) {
2020
target: sortableId,
2121
source: sortableId,
2222
});
23-
}, [sortableId]);
23+
}, [data, events, sortableId]);
2424
return handleRemove;
2525
}
2626

src/typings.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
import { EventEmitter } from 'events';
2-
import {
3-
CSSProperties,
4-
FunctionComponent,
5-
PropsWithoutRef,
6-
MutableRefObject,
7-
RefAttributes,
8-
RefCallback,
9-
RefObject,
10-
ReactNode,
11-
} from 'react';
12-
import { DragSourceMonitor, DropTargetMonitor } from 'react-dnd';
2+
import { CSSProperties, FunctionComponent, PropsWithoutRef, MutableRefObject, RefAttributes, ReactNode } from 'react';
3+
import { ConnectDragSource, DragSourceMonitor, DropTargetMonitor } from 'react-dnd';
134

145
export type SortableDirection = 'horizontal' | 'vertical';
156

@@ -230,7 +221,7 @@ export interface SortableItemProps<T extends ISortableItem = ISortableItem & { [
230221
update: (data: T & { [key: string]: any }) => void;
231222
className?: string;
232223
style?: CSSProperties;
233-
drag: (ref: RefObject<any>) => RefCallback<any>;
224+
drag: ConnectDragSource;
234225
}
235226

236227
export type SortableItemRefObject =

src/utils.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function getMonitorCoord(
100100
return NaN;
101101
},
102102
compare: (_: ICoord): Relation => {
103-
throw '未实现逻辑';
103+
throw new Error('未实现逻辑');
104104
},
105105
};
106106
}
@@ -206,11 +206,11 @@ export function getItemStyles(
206206
y += initialOffset.y;
207207
}
208208

209-
if (direction == 'vertical') {
209+
if (direction === 'vertical') {
210210
x = initialOffset.x;
211211
}
212212

213-
if (direction == 'horizontal') {
213+
if (direction === 'horizontal') {
214214
y = initialOffset.y;
215215
}
216216

yarn.lock

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3325,17 +3325,22 @@
33253325
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.33.0.tgz#a1e59036a3b53ae8430ceebf2a919dc7f9af6d72"
33263326
integrity sha512-zKp7CjQzLQImXEpLt2BUw1tvOMPfNoTAfb8l51evhYbOEEzdWyQNmHWWGPR6hwKJDAi+1VXSBmnhL9kyVTTOuQ==
33273327

3328-
"@typescript-eslint/[email protected]":
3329-
version "4.33.0"
3330-
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.33.0.tgz#0dfb51c2908f68c5c08d82aefeaf166a17c24609"
3331-
integrity sha512-rkWRY1MPFzjwnEVHsxGemDzqqddw2QbTJlICPD9p9I9LfsO8fdmfQPOX3uKfUaGRDFJbfrtm/sXhVXN4E+bzCA==
3332-
dependencies:
3333-
"@typescript-eslint/types" "4.33.0"
3334-
"@typescript-eslint/visitor-keys" "4.33.0"
3335-
debug "^4.3.1"
3336-
globby "^11.0.3"
3337-
is-glob "^4.0.1"
3338-
semver "^7.3.5"
3328+
"@typescript-eslint/[email protected]":
3329+
version "5.36.2"
3330+
resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.36.2.tgz#a5066e500ebcfcee36694186ccc57b955c05faf9"
3331+
integrity sha512-9OJSvvwuF1L5eS2EQgFUbECb99F0mwq501w0H0EkYULkhFa19Qq7WFbycdw1PexAc929asupbZcgjVIe6OK/XQ==
3332+
3333+
"@typescript-eslint/[email protected]", "@typescript-eslint/typescript-estree@^5.30.5", "@typescript-eslint/typescript-estree@^5.36.2":
3334+
version "5.36.2"
3335+
resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.36.2.tgz#0c93418b36c53ba0bc34c61fe9405c4d1d8fe560"
3336+
integrity sha512-8fyH+RfbKc0mTspfuEjlfqA4YywcwQK2Amcf6TDOwaRLg7Vwdu4bZzyvBZp4bjt1RRjQ5MDnOZahxMrt2l5v9w==
3337+
dependencies:
3338+
"@typescript-eslint/types" "5.36.2"
3339+
"@typescript-eslint/visitor-keys" "5.36.2"
3340+
debug "^4.3.4"
3341+
globby "^11.1.0"
3342+
is-glob "^4.0.3"
3343+
semver "^7.3.7"
33393344
tsutils "^3.21.0"
33403345

33413346
"@typescript-eslint/[email protected]":
@@ -3346,6 +3351,14 @@
33463351
"@typescript-eslint/types" "4.33.0"
33473352
eslint-visitor-keys "^2.0.0"
33483353

3354+
"@typescript-eslint/[email protected]":
3355+
version "5.36.2"
3356+
resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.36.2.tgz#2f8f78da0a3bad3320d2ac24965791ac39dace5a"
3357+
integrity sha512-BtRvSR6dEdrNt7Net2/XDjbYKU5Ml6GqJgVfXT0CxTCJlnIqK7rAGreuWKMT2t8cFUT2Msv5oxw0GMRD7T5J7A==
3358+
dependencies:
3359+
"@typescript-eslint/types" "5.36.2"
3360+
eslint-visitor-keys "^3.3.0"
3361+
33493362
"@webassemblyjs/[email protected]":
33503363
version "1.11.1"
33513364
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7"
@@ -5812,7 +5825,7 @@ debug@^3.0.0, debug@^3.2.6, debug@^3.2.7:
58125825
dependencies:
58135826
ms "^2.1.1"
58145827

5815-
debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1:
5828+
debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.4:
58165829
version "4.3.4"
58175830
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
58185831
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
@@ -6663,6 +6676,11 @@ eslint-visitor-keys@^2.0.0:
66636676
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
66646677
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
66656678

6679+
eslint-visitor-keys@^3.3.0:
6680+
version "3.3.0"
6681+
resolved "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
6682+
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==
6683+
66666684
eslint@^6.1.0:
66676685
version "6.8.0"
66686686
resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.8.0.tgz#62262d6729739f9275723824302fb227c8c93ffb"
@@ -7670,7 +7688,7 @@ [email protected]:
76707688
resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.0.tgz#cb76da79555669a1519d5a8edf093afaa0bf1465"
76717689
integrity sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==
76727690

7673-
globby@^11.0.2, globby@^11.0.3, globby@^11.1.0:
7691+
globby@^11.0.2, globby@^11.1.0:
76747692
version "11.1.0"
76757693
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
76767694
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
@@ -12711,7 +12729,7 @@ [email protected]:
1271112729
dependencies:
1271212730
lru-cache "^6.0.0"
1271312731

12714-
[email protected], semver@^7.1.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
12732+
[email protected], semver@^7.1.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7:
1271512733
version "7.3.7"
1271612734
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
1271712735
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==

0 commit comments

Comments
 (0)