@os-design/drag-sort 1.0.45 → 1.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Droppable.d.ts +2 -2
- package/dist/Droppable.d.ts.map +1 -1
- package/dist/Droppable.js +8 -8
- package/dist/utils/NodeList.d.ts +5 -5
- package/dist/utils/NodeList.d.ts.map +1 -1
- package/dist/utils/useAppendClassName.d.ts +1 -1
- package/dist/utils/useAppendClassName.d.ts.map +1 -1
- package/dist/utils/useGeneratedId.d.ts.map +1 -1
- package/dist/utils/useGeneratedId.js +3 -1
- package/dist/utils/useInitRect.d.ts.map +1 -1
- package/dist/utils/useInitRect.js +15 -11
- package/dist/utils/useInitScrollOffset.d.ts +1 -1
- package/dist/utils/useInitScrollOffset.d.ts.map +1 -1
- package/dist/utils/useInitScrollOffset.js +13 -9
- package/dist/utils/useTargetList.d.ts.map +1 -1
- package/dist/utils/useTargetList.js +10 -6
- package/package.json +15 -15
- package/src/Droppable.tsx +11 -21
- package/src/utils/NodeList.ts +5 -5
- package/src/utils/useAppendClassName.ts +4 -1
- package/src/utils/useGeneratedId.ts +1 -0
- package/src/utils/useInitRect.ts +21 -11
- package/src/utils/useInitScrollOffset.ts +17 -9
- package/src/utils/useTargetList.ts +12 -5
package/dist/Droppable.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ export interface DroppableChildrenProps {
|
|
|
5
5
|
* The reference to the list.
|
|
6
6
|
* If a virtual list is used, pass it to the outerRef prop.
|
|
7
7
|
*/
|
|
8
|
-
ref: RefObject<HTMLDivElement>;
|
|
8
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
9
9
|
/**
|
|
10
10
|
* The reference to the container inside the virtual list.
|
|
11
11
|
* Pass it to the innerRef prop.
|
|
12
12
|
*/
|
|
13
|
-
innerRef: RefObject<HTMLDivElement>;
|
|
13
|
+
innerRef: RefObject<HTMLDivElement | null>;
|
|
14
14
|
}
|
|
15
15
|
export interface DroppableProps {
|
|
16
16
|
/**
|
package/dist/Droppable.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Droppable.d.ts","sourceRoot":"","sources":["../src/Droppable.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"Droppable.d.ts","sourceRoot":"","sources":["../src/Droppable.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAiB,EAGf,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAC;AAK7B,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,GAAG,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACtC;;;OAGG;IACH,QAAQ,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IACrC;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,KAAK,CAAC,SAAS,CAAC;CAC9D;AAED,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA8EvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/dist/Droppable.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import useMemoObject from '@os-design/use-memo-object';
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
3
3
|
import NodeList from './utils/NodeList.js';
|
|
4
4
|
import useDragAndDrop from './utils/useDragAndDrop.js';
|
|
5
5
|
import { DroppableContext } from './utils/useDroppable.js';
|
|
@@ -55,18 +55,18 @@ const Droppable = ({
|
|
|
55
55
|
const listId = listRef.current.id;
|
|
56
56
|
return () => deregisterList(listId);
|
|
57
57
|
}, [deregisterList, registerList]);
|
|
58
|
-
const registerNode =
|
|
59
|
-
const deregisterNode =
|
|
58
|
+
const registerNode = props => listRef.current.add(props);
|
|
59
|
+
const deregisterNode = node => {
|
|
60
60
|
listRef.current.remove(node);
|
|
61
|
-
}
|
|
61
|
+
};
|
|
62
62
|
|
|
63
63
|
// Handlers that determine whether a user clicks on the node
|
|
64
|
-
const mouseDownHandler =
|
|
64
|
+
const mouseDownHandler = (e, node) => {
|
|
65
65
|
onMouseDown(e, listRef.current, node);
|
|
66
|
-
}
|
|
67
|
-
const touchStartHandler =
|
|
66
|
+
};
|
|
67
|
+
const touchStartHandler = (e, node) => {
|
|
68
68
|
onTouchStart(e, listRef.current, node);
|
|
69
|
-
}
|
|
69
|
+
};
|
|
70
70
|
const droppableContext = useMemoObject({
|
|
71
71
|
registerNode,
|
|
72
72
|
deregisterNode,
|
package/dist/utils/NodeList.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React, { type CSSProperties, type RefObject } from 'react';
|
|
|
2
2
|
export type Node = [Node, Node, RefObject<any>, (style: CSSProperties) => void, number, string] | null;
|
|
3
3
|
export type ExistingNode = Exclude<Node, null>;
|
|
4
4
|
export interface NodeProps {
|
|
5
|
-
ref: React.
|
|
5
|
+
ref: React.RefObject<any>;
|
|
6
6
|
setStyle: (style: CSSProperties) => void;
|
|
7
7
|
index: number;
|
|
8
8
|
id: string;
|
|
@@ -24,8 +24,8 @@ interface RenderDraggedNodeProps {
|
|
|
24
24
|
export type RenderDraggedNode = (props: RenderDraggedNodeProps) => React.ReactNode;
|
|
25
25
|
interface InitProps {
|
|
26
26
|
id: string;
|
|
27
|
-
ref: RefObject<HTMLDivElement>;
|
|
28
|
-
innerRef: RefObject<HTMLDivElement>;
|
|
27
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
28
|
+
innerRef: RefObject<HTMLDivElement | null>;
|
|
29
29
|
horizontal: boolean;
|
|
30
30
|
renderDraggedNode: RenderDraggedNode;
|
|
31
31
|
}
|
|
@@ -41,12 +41,12 @@ declare class NodeList {
|
|
|
41
41
|
/**
|
|
42
42
|
* The ref to the list.
|
|
43
43
|
*/
|
|
44
|
-
ref: RefObject<HTMLDivElement>;
|
|
44
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
45
45
|
/**
|
|
46
46
|
* The inner ref to the list.
|
|
47
47
|
* Used by the virtual list.
|
|
48
48
|
*/
|
|
49
|
-
innerRef: RefObject<HTMLDivElement>;
|
|
49
|
+
innerRef: RefObject<HTMLDivElement | null>;
|
|
50
50
|
/**
|
|
51
51
|
* Whether the list is horizontal.
|
|
52
52
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeList.d.ts","sourceRoot":"","sources":["../../src/utils/NodeList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlE,MAAM,MAAM,IAAI,GACZ,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAC5E,IAAI,CAAC;AAET,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAE/C,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"NodeList.d.ts","sourceRoot":"","sources":["../../src/utils/NodeList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKlE,MAAM,MAAM,IAAI,GACZ,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAC5E,IAAI,CAAC;AAET,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAE/C,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,sBAAsB;IAC9B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,MAAM,iBAAiB,GAAG,CAC9B,KAAK,EAAE,sBAAsB,KAC1B,KAAK,CAAC,SAAS,CAAC;AAErB,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACtC,QAAQ,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC3C,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED;;;GAGG;AACH,cAAM,QAAQ;IACZ;;OAEG;IACI,EAAE,EAAE,MAAM,CAAC;IAElB;;OAEG;IACI,GAAG,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAE7C;;;OAGG;IACI,QAAQ,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAElD;;OAEG;IACI,UAAU,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACI,iBAAiB,EAAE,iBAAiB,CAAC;IAE5C;;OAEG;IACH,OAAO,CAAC,IAAI,CAAO;IAEnB;;OAEG;IACH,OAAO,CAAC,IAAI,CAAO;IAEnB;;OAEG;IACH,OAAO,CAAC,SAAS,CAAoC;gBAElC,KAAK,EAAE,SAAS;IAW5B,OAAO;IAIP,OAAO;IAId;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAezB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAenB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ;IAMvB;;;;OAIG;IACI,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY;IA2C1C;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,YAAY;IAuBzB,WAAW,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI;IAIhD,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI;CAI3D;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -2,6 +2,6 @@ import { type RefObject } from 'react';
|
|
|
2
2
|
/**
|
|
3
3
|
* Adds a new class name to the element.
|
|
4
4
|
*/
|
|
5
|
-
declare const useAppendClassName: (ref: RefObject<HTMLElement>, className: string) => void;
|
|
5
|
+
declare const useAppendClassName: (ref: RefObject<HTMLElement | null>, className: string) => void;
|
|
6
6
|
export default useAppendClassName;
|
|
7
7
|
//# sourceMappingURL=useAppendClassName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAppendClassName.d.ts","sourceRoot":"","sources":["../../src/utils/useAppendClassName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,OAAO,CAAC;AAElD;;GAEG;AACH,QAAA,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"useAppendClassName.d.ts","sourceRoot":"","sources":["../../src/utils/useAppendClassName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,OAAO,CAAC;AAElD;;GAEG;AACH,QAAA,MAAM,kBAAkB,GACtB,KAAK,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,EAClC,WAAW,MAAM,SAalB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGeneratedId.d.ts","sourceRoot":"","sources":["../../src/utils/useGeneratedId.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"useGeneratedId.d.ts","sourceRoot":"","sources":["../../src/utils/useGeneratedId.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,cAAc,cAEoC,CAAC;AAEzD,eAAe,cAAc,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
const useGeneratedId = () =>
|
|
2
|
+
const useGeneratedId = () =>
|
|
3
|
+
// eslint-disable-next-line react-hooks/purity
|
|
4
|
+
useMemo(() => Math.random().toString(16).slice(2), []);
|
|
3
5
|
export default useGeneratedId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInitRect.d.ts","sourceRoot":"","sources":["../../src/utils/useInitRect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"useInitRect.d.ts","sourceRoot":"","sources":["../../src/utils/useInitRect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAE5D,QAAA,MAAM,WAAW,GAAI,MAAM,SAAS,CAAC,WAAW,CAAC;WAEtC,MAAM;WACN,MAAM;eACF,MAAM;gBACL,MAAM;QAiBrB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const useInitRect = ref =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
const useInitRect = ref => {
|
|
3
|
+
const [rect, setRect] = useState(null);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (!ref || !ref.current) return;
|
|
6
|
+
const domRect = ref.current.getBoundingClientRect();
|
|
7
|
+
setRect({
|
|
8
|
+
initX: domRect.x,
|
|
9
|
+
initY: domRect.y,
|
|
10
|
+
initWidth: domRect.width,
|
|
11
|
+
initHeight: domRect.height
|
|
12
|
+
});
|
|
13
|
+
}, [ref]);
|
|
14
|
+
return rect;
|
|
15
|
+
};
|
|
12
16
|
export default useInitRect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInitScrollOffset.d.ts","sourceRoot":"","sources":["../../src/utils/useInitScrollOffset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"useInitScrollOffset.d.ts","sourceRoot":"","sources":["../../src/utils/useInitScrollOffset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAG5D,QAAA,MAAM,mBAAmB,GAAI,MAAM,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC;oBAE5C,MAAM;mBACP,MAAM;QAexB,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
2
|
import getElementScroll from './getElementScroll.js';
|
|
3
|
-
const useInitScrollOffset = ref =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const useInitScrollOffset = ref => {
|
|
4
|
+
const [scrollOffset, setScrollOffset] = useState(null);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (!ref || !ref.current) return;
|
|
7
|
+
const offset = getElementScroll(ref.current);
|
|
8
|
+
setScrollOffset({
|
|
9
|
+
initScrollLeft: offset.scrollLeft,
|
|
10
|
+
initScrollTop: offset.scrollTop
|
|
11
|
+
});
|
|
12
|
+
}, [ref]);
|
|
13
|
+
return scrollOffset;
|
|
14
|
+
};
|
|
11
15
|
export default useInitScrollOffset;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTargetList.d.ts","sourceRoot":"","sources":["../../src/utils/useTargetList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"useTargetList.d.ts","sourceRoot":"","sources":["../../src/utils/useTargetList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,KAAK,SAAS,EAAoC,MAAM,OAAO,CAAC;AACzE,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAGvC,QAAA,MAAM,aAAa,GACjB,UAAU,QAAQ,GAAG,IAAI,EACzB,cAAc,SAAS,CAAC,SAAS,CAAC,2CA2BnC,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import useThrottle from '@os-design/use-throttle';
|
|
2
|
-
import { useCallback,
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
3
|
import useScrollEventByPoint from './useScrollEventByPoint.js';
|
|
4
4
|
const useTargetList = (position, listStoreRef) => {
|
|
5
5
|
const [number, setNumber] = useState(0);
|
|
6
|
-
const targetList =
|
|
7
|
-
|
|
6
|
+
const [targetList, setTargetList] = useState(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (!position || !listStoreRef.current) {
|
|
9
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
10
|
+
setTargetList(null);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
8
13
|
const {
|
|
9
14
|
x,
|
|
10
15
|
y
|
|
11
16
|
} = position;
|
|
12
17
|
const list = listStoreRef.current.findByPosition(x, y);
|
|
13
|
-
|
|
14
|
-
}, [listStoreRef, position, number]);
|
|
15
|
-
|
|
18
|
+
setTargetList(list || null);
|
|
19
|
+
}, [listStoreRef, position, number]);
|
|
16
20
|
const forceUpdate = useCallback(() => {
|
|
17
21
|
setNumber(n => n + 1);
|
|
18
22
|
}, []);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@os-design/drag-sort",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.47",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": "git@gitlab.com:os-team/libs/os-design.git",
|
|
6
6
|
"type": "module",
|
|
@@ -19,32 +19,32 @@
|
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"scripts": {
|
|
22
|
-
"clean": "
|
|
22
|
+
"clean": "rm -r dist",
|
|
23
23
|
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx --out-dir dist",
|
|
24
24
|
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly --declaration --declarationDir dist",
|
|
25
25
|
"build": "yarn clean && npm-run-all 'build:*'",
|
|
26
|
-
"ncu": "ncu -u '/^(?!(react
|
|
26
|
+
"ncu": "ncu -u '/^(?!(react-window)$).*$/'"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@os-design/portal": "^1.0.
|
|
33
|
-
"@os-design/use-auto-scroll": "^1.0.
|
|
34
|
-
"@os-design/use-drag": "^1.0.
|
|
35
|
-
"@os-design/use-event": "^1.0.
|
|
36
|
-
"@os-design/use-memo-object": "^1.0.
|
|
37
|
-
"@os-design/use-prevent-default-event": "^1.0.
|
|
38
|
-
"@os-design/use-throttle": "^1.0.
|
|
32
|
+
"@os-design/portal": "^1.0.29",
|
|
33
|
+
"@os-design/use-auto-scroll": "^1.0.33",
|
|
34
|
+
"@os-design/use-drag": "^1.0.32",
|
|
35
|
+
"@os-design/use-event": "^1.0.34",
|
|
36
|
+
"@os-design/use-memo-object": "^1.0.30",
|
|
37
|
+
"@os-design/use-prevent-default-event": "^1.0.31",
|
|
38
|
+
"@os-design/use-throttle": "^1.0.33"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@os-design/omit-emotion-props": "^1.0.
|
|
42
|
-
"@os-design/use-size": "^1.0.
|
|
41
|
+
"@os-design/omit-emotion-props": "^1.0.32",
|
|
42
|
+
"@os-design/use-size": "^1.0.35",
|
|
43
43
|
"react-window": "^1.8.11"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"react": "
|
|
47
|
-
"react-dom": "
|
|
46
|
+
"react": "19",
|
|
47
|
+
"react-dom": "19"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "83ca5af2bb91d07d64440f87b7ab23f5100daa02"
|
|
50
50
|
}
|
package/src/Droppable.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import React, {
|
|
|
3
3
|
type MouseEvent,
|
|
4
4
|
type RefObject,
|
|
5
5
|
type TouchEvent,
|
|
6
|
-
useCallback,
|
|
7
6
|
useEffect,
|
|
8
7
|
useMemo,
|
|
9
8
|
useRef,
|
|
@@ -22,12 +21,12 @@ export interface DroppableChildrenProps {
|
|
|
22
21
|
* The reference to the list.
|
|
23
22
|
* If a virtual list is used, pass it to the outerRef prop.
|
|
24
23
|
*/
|
|
25
|
-
ref: RefObject<HTMLDivElement>;
|
|
24
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
26
25
|
/**
|
|
27
26
|
* The reference to the container inside the virtual list.
|
|
28
27
|
* Pass it to the innerRef prop.
|
|
29
28
|
*/
|
|
30
|
-
innerRef: RefObject<HTMLDivElement>;
|
|
29
|
+
innerRef: RefObject<HTMLDivElement | null>;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
export interface DroppableProps {
|
|
@@ -102,27 +101,18 @@ const Droppable: React.FC<DroppableProps> = ({
|
|
|
102
101
|
return () => deregisterList(listId);
|
|
103
102
|
}, [deregisterList, registerList]);
|
|
104
103
|
|
|
105
|
-
const registerNode =
|
|
106
|
-
|
|
107
|
-
[]
|
|
108
|
-
);
|
|
109
|
-
const deregisterNode = useCallback((node: ExistingNode) => {
|
|
104
|
+
const registerNode = (props: NodeProps) => listRef.current.add(props);
|
|
105
|
+
const deregisterNode = (node: ExistingNode) => {
|
|
110
106
|
listRef.current.remove(node);
|
|
111
|
-
}
|
|
107
|
+
};
|
|
112
108
|
|
|
113
109
|
// Handlers that determine whether a user clicks on the node
|
|
114
|
-
const mouseDownHandler =
|
|
115
|
-
(e
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const touchStartHandler = useCallback(
|
|
121
|
-
(e: TouchEvent, node: ExistingNode) => {
|
|
122
|
-
onTouchStart(e, listRef.current, node);
|
|
123
|
-
},
|
|
124
|
-
[onTouchStart]
|
|
125
|
-
);
|
|
110
|
+
const mouseDownHandler = (e: MouseEvent, node: ExistingNode) => {
|
|
111
|
+
onMouseDown(e, listRef.current, node);
|
|
112
|
+
};
|
|
113
|
+
const touchStartHandler = (e: TouchEvent, node: ExistingNode) => {
|
|
114
|
+
onTouchStart(e, listRef.current, node);
|
|
115
|
+
};
|
|
126
116
|
|
|
127
117
|
const droppableContext = useMemoObject({
|
|
128
118
|
registerNode,
|
package/src/utils/NodeList.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type Node =
|
|
|
10
10
|
export type ExistingNode = Exclude<Node, null>;
|
|
11
11
|
|
|
12
12
|
export interface NodeProps {
|
|
13
|
-
ref: React.
|
|
13
|
+
ref: React.RefObject<any>;
|
|
14
14
|
setStyle: (style: CSSProperties) => void;
|
|
15
15
|
index: number;
|
|
16
16
|
id: string;
|
|
@@ -37,8 +37,8 @@ export type RenderDraggedNode = (
|
|
|
37
37
|
|
|
38
38
|
interface InitProps {
|
|
39
39
|
id: string;
|
|
40
|
-
ref: RefObject<HTMLDivElement>;
|
|
41
|
-
innerRef: RefObject<HTMLDivElement>;
|
|
40
|
+
ref: RefObject<HTMLDivElement | null>;
|
|
41
|
+
innerRef: RefObject<HTMLDivElement | null>;
|
|
42
42
|
horizontal: boolean;
|
|
43
43
|
renderDraggedNode: RenderDraggedNode;
|
|
44
44
|
}
|
|
@@ -56,13 +56,13 @@ class NodeList {
|
|
|
56
56
|
/**
|
|
57
57
|
* The ref to the list.
|
|
58
58
|
*/
|
|
59
|
-
public ref: RefObject<HTMLDivElement>;
|
|
59
|
+
public ref: RefObject<HTMLDivElement | null>;
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* The inner ref to the list.
|
|
63
63
|
* Used by the virtual list.
|
|
64
64
|
*/
|
|
65
|
-
public innerRef: RefObject<HTMLDivElement>;
|
|
65
|
+
public innerRef: RefObject<HTMLDivElement | null>;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Whether the list is horizontal.
|
|
@@ -3,7 +3,10 @@ import { type RefObject, useEffect } from 'react';
|
|
|
3
3
|
/**
|
|
4
4
|
* Adds a new class name to the element.
|
|
5
5
|
*/
|
|
6
|
-
const useAppendClassName = (
|
|
6
|
+
const useAppendClassName = (
|
|
7
|
+
ref: RefObject<HTMLElement | null>,
|
|
8
|
+
className: string
|
|
9
|
+
) => {
|
|
7
10
|
useEffect(() => {
|
|
8
11
|
const element = ref.current;
|
|
9
12
|
if (!element) return () => {};
|
package/src/utils/useInitRect.ts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import { type RefObject,
|
|
1
|
+
import { type RefObject, useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
const useInitRect = (ref?: RefObject<HTMLElement>) =>
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const useInitRect = (ref?: RefObject<HTMLElement>) => {
|
|
4
|
+
const [rect, setRect] = useState<{
|
|
5
|
+
initX: number;
|
|
6
|
+
initY: number;
|
|
7
|
+
initWidth: number;
|
|
8
|
+
initHeight: number;
|
|
9
|
+
} | null>(null);
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!ref || !ref.current) return;
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const domRect = ref.current.getBoundingClientRect();
|
|
15
|
+
|
|
16
|
+
setRect({
|
|
17
|
+
initX: domRect.x,
|
|
18
|
+
initY: domRect.y,
|
|
19
|
+
initWidth: domRect.width,
|
|
20
|
+
initHeight: domRect.height,
|
|
21
|
+
});
|
|
15
22
|
}, [ref]);
|
|
16
23
|
|
|
24
|
+
return rect;
|
|
25
|
+
};
|
|
26
|
+
|
|
17
27
|
export default useInitRect;
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { type RefObject,
|
|
1
|
+
import { type RefObject, useEffect, useState } from 'react';
|
|
2
2
|
import getElementScroll from './getElementScroll.js';
|
|
3
3
|
|
|
4
|
-
const useInitScrollOffset = (ref?: RefObject<HTMLElement>) =>
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const useInitScrollOffset = (ref?: RefObject<HTMLElement | null>) => {
|
|
5
|
+
const [scrollOffset, setScrollOffset] = useState<{
|
|
6
|
+
initScrollLeft: number;
|
|
7
|
+
initScrollTop: number;
|
|
8
|
+
} | null>(null);
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!ref || !ref.current) return;
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const offset = getElementScroll(ref.current);
|
|
14
|
+
|
|
15
|
+
setScrollOffset({
|
|
16
|
+
initScrollLeft: offset.scrollLeft,
|
|
17
|
+
initScrollTop: offset.scrollTop,
|
|
18
|
+
});
|
|
14
19
|
}, [ref]);
|
|
15
20
|
|
|
21
|
+
return scrollOffset;
|
|
22
|
+
};
|
|
23
|
+
|
|
16
24
|
export default useInitScrollOffset;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Position } from '@os-design/use-drag';
|
|
2
2
|
import useThrottle from '@os-design/use-throttle';
|
|
3
|
-
import { type RefObject, useCallback,
|
|
3
|
+
import { type RefObject, useCallback, useEffect, useState } from 'react';
|
|
4
4
|
import ListStore from './ListStore.js';
|
|
5
5
|
import useScrollEventByPoint from './useScrollEventByPoint.js';
|
|
6
6
|
|
|
@@ -9,13 +9,20 @@ const useTargetList = (
|
|
|
9
9
|
listStoreRef: RefObject<ListStore>
|
|
10
10
|
) => {
|
|
11
11
|
const [number, setNumber] = useState(0);
|
|
12
|
+
const [targetList, setTargetList] = useState<NonNullable<
|
|
13
|
+
ReturnType<ListStore['findByPosition']>
|
|
14
|
+
> | null>(null);
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
if (!position || !listStoreRef.current)
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!position || !listStoreRef.current) {
|
|
18
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
19
|
+
setTargetList(null);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
15
22
|
const { x, y } = position;
|
|
16
23
|
const list = listStoreRef.current.findByPosition(x, y);
|
|
17
|
-
|
|
18
|
-
}, [listStoreRef, position, number]);
|
|
24
|
+
setTargetList(list || null);
|
|
25
|
+
}, [listStoreRef, position, number]);
|
|
19
26
|
|
|
20
27
|
const forceUpdate = useCallback(() => {
|
|
21
28
|
setNumber((n) => n + 1);
|