@os-design/drag-sort 1.0.13 → 1.0.15
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/cjs/DragAndDrop.js +50 -72
- package/dist/cjs/DragAndDrop.js.map +1 -1
- package/dist/cjs/Draggable.js +19 -36
- package/dist/cjs/Draggable.js.map +1 -1
- package/dist/cjs/Droppable.js +24 -33
- package/dist/cjs/Droppable.js.map +1 -1
- package/dist/cjs/index.js +0 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/ListStore.js +4 -13
- package/dist/cjs/utils/ListStore.js.map +1 -1
- package/dist/cjs/utils/NodeList.js +25 -56
- package/dist/cjs/utils/NodeList.js.map +1 -1
- package/dist/cjs/utils/getElementOffset.js +0 -4
- package/dist/cjs/utils/getElementOffset.js.map +1 -1
- package/dist/cjs/utils/getElementScroll.js +0 -4
- package/dist/cjs/utils/getElementScroll.js.map +1 -1
- package/dist/cjs/utils/getNodeRect.js +9 -18
- package/dist/cjs/utils/getNodeRect.js.map +1 -1
- package/dist/cjs/utils/useAppendClassName.js +0 -3
- package/dist/cjs/utils/useAppendClassName.js.map +1 -1
- package/dist/cjs/utils/useBlankNode.js +17 -26
- package/dist/cjs/utils/useBlankNode.js.map +1 -1
- package/dist/cjs/utils/useDragAndDrop.js +0 -8
- package/dist/cjs/utils/useDragAndDrop.js.map +1 -1
- package/dist/cjs/utils/useDragEffect.js +104 -163
- package/dist/cjs/utils/useDragEffect.js.map +1 -1
- package/dist/cjs/utils/useDroppable.js +0 -8
- package/dist/cjs/utils/useDroppable.js.map +1 -1
- package/dist/cjs/utils/useGeneratedId.js +0 -3
- package/dist/cjs/utils/useGeneratedId.js.map +1 -1
- package/dist/cjs/utils/useGetNodeStyle.js +0 -3
- package/dist/cjs/utils/useGetNodeStyle.js.map +1 -1
- package/dist/cjs/utils/useInitRect.js +0 -3
- package/dist/cjs/utils/useInitRect.js.map +1 -1
- package/dist/cjs/utils/useInitScrollOffset.js +0 -5
- package/dist/cjs/utils/useInitScrollOffset.js.map +1 -1
- package/dist/cjs/utils/useMoveNode.js +23 -48
- package/dist/cjs/utils/useMoveNode.js.map +1 -1
- package/dist/cjs/utils/useScrollEventByPoint.js +2 -10
- package/dist/cjs/utils/useScrollEventByPoint.js.map +1 -1
- package/dist/cjs/utils/useTargetList.js +8 -21
- package/dist/cjs/utils/useTargetList.js.map +1 -1
- package/dist/cjs/utils/useTransitionStyle.js +2 -5
- package/dist/cjs/utils/useTransitionStyle.js.map +1 -1
- package/dist/esm/DragAndDrop.js +19 -12
- package/dist/esm/DragAndDrop.js.map +1 -1
- package/dist/esm/Draggable.js +10 -9
- package/dist/esm/Draggable.js.map +1 -1
- package/dist/esm/Droppable.js +17 -14
- package/dist/esm/Droppable.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/ListStore.js +3 -8
- package/dist/esm/utils/ListStore.js.map +1 -1
- package/dist/esm/utils/NodeList.js +17 -36
- package/dist/esm/utils/NodeList.js.map +1 -1
- package/dist/esm/utils/getElementOffset.js +0 -3
- package/dist/esm/utils/getElementOffset.js.map +1 -1
- package/dist/esm/utils/getElementScroll.js +0 -3
- package/dist/esm/utils/getElementScroll.js.map +1 -1
- package/dist/esm/utils/getNodeRect.js +1 -2
- package/dist/esm/utils/getNodeRect.js.map +1 -1
- package/dist/esm/utils/useAppendClassName.js +1 -2
- package/dist/esm/utils/useAppendClassName.js.map +1 -1
- package/dist/esm/utils/useBlankNode.js +10 -9
- package/dist/esm/utils/useBlankNode.js.map +1 -1
- package/dist/esm/utils/useDragAndDrop.js +0 -2
- package/dist/esm/utils/useDragAndDrop.js.map +1 -1
- package/dist/esm/utils/useDragEffect.js +57 -60
- package/dist/esm/utils/useDragEffect.js.map +1 -1
- package/dist/esm/utils/useDroppable.js +0 -2
- package/dist/esm/utils/useDroppable.js.map +1 -1
- package/dist/esm/utils/useGeneratedId.js +0 -2
- package/dist/esm/utils/useGeneratedId.js.map +1 -1
- package/dist/esm/utils/useGetNodeStyle.js +0 -2
- package/dist/esm/utils/useGetNodeStyle.js.map +1 -1
- package/dist/esm/utils/useInitRect.js +0 -2
- package/dist/esm/utils/useInitRect.js.map +1 -1
- package/dist/esm/utils/useInitScrollOffset.js +0 -2
- package/dist/esm/utils/useInitScrollOffset.js.map +1 -1
- package/dist/esm/utils/useMoveNode.js +1 -11
- package/dist/esm/utils/useMoveNode.js.map +1 -1
- package/dist/esm/utils/useScrollEventByPoint.js +0 -5
- package/dist/esm/utils/useScrollEventByPoint.js.map +1 -1
- package/dist/esm/utils/useTargetList.js +2 -3
- package/dist/esm/utils/useTargetList.js.map +1 -1
- package/dist/esm/utils/useTransitionStyle.js +0 -2
- package/dist/esm/utils/useTransitionStyle.js.map +1 -1
- package/package.json +11 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import getNodeRect from './getNodeRect';
|
|
3
|
-
|
|
4
3
|
/* eslint-disable no-constant-condition */
|
|
4
|
+
|
|
5
5
|
const useMoveNode = props => {
|
|
6
6
|
const {
|
|
7
7
|
position,
|
|
@@ -22,27 +22,22 @@ const useMoveNode = props => {
|
|
|
22
22
|
const startRectProp = list.horizontal ? 'left' : 'top';
|
|
23
23
|
const endRectProp = list.horizontal ? 'right' : 'bottom';
|
|
24
24
|
let node = startNode;
|
|
25
|
-
|
|
26
25
|
if (direction === 'up') {
|
|
27
26
|
while (true) {
|
|
28
27
|
const [prev,,, nodeSetStyle, nodeIndex] = node;
|
|
29
28
|
if (!prev) return node;
|
|
30
29
|
const [,, prevNodeRef, prevNodeSetStyle, prevNodeIndex] = prev;
|
|
31
|
-
|
|
32
30
|
if (destination === 'cursor') {
|
|
33
31
|
const prevNodeRect = getNodeRect(prevNodeRef);
|
|
34
|
-
|
|
35
32
|
if (prevNodeRect && position[axis] > prevNodeRect[endRectProp]) {
|
|
36
33
|
return node;
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
if (isAnotherList || prevNodeIndex < draggedNodeIndex) {
|
|
41
37
|
prevNodeSetStyle(getNodeStyle('down', list.horizontal));
|
|
42
38
|
} else if (nodeIndex > draggedNodeIndex) {
|
|
43
39
|
nodeSetStyle(getNodeStyle('init', list.horizontal));
|
|
44
40
|
}
|
|
45
|
-
|
|
46
41
|
node = prev;
|
|
47
42
|
}
|
|
48
43
|
} else {
|
|
@@ -50,26 +45,21 @@ const useMoveNode = props => {
|
|
|
50
45
|
const [, next,, nodeSetStyle, nodeIndex] = node;
|
|
51
46
|
if (!next) return node;
|
|
52
47
|
const [,, nextNodeRef, nextNodeSetStyle, nextNodeIndex] = next;
|
|
53
|
-
|
|
54
48
|
if (destination === 'cursor') {
|
|
55
49
|
const nextNodeRect = getNodeRect(nextNodeRef);
|
|
56
|
-
|
|
57
50
|
if (nextNodeRect && position[axis] < nextNodeRect[startRectProp]) {
|
|
58
51
|
return node;
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
if (isAnotherList || nodeIndex < draggedNodeIndex) {
|
|
63
55
|
nodeSetStyle(getNodeStyle('init', list.horizontal));
|
|
64
56
|
} else if (nextNodeIndex > draggedNodeIndex) {
|
|
65
57
|
nextNodeSetStyle(getNodeStyle('up', list.horizontal));
|
|
66
58
|
}
|
|
67
|
-
|
|
68
59
|
node = next;
|
|
69
60
|
}
|
|
70
61
|
}
|
|
71
62
|
}, [draggedNode, getNodeStyle, position]);
|
|
72
63
|
};
|
|
73
|
-
|
|
74
64
|
export default useMoveNode;
|
|
75
65
|
//# sourceMappingURL=useMoveNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMoveNode.js","names":["useCallback","getNodeRect","useMoveNode","props","position","draggedNode","getNodeStyle","options","list","startNode","direction","destination","isAnotherList","draggedNodeIndex","node","axis","horizontal","startRectProp","endRectProp","prev","nodeSetStyle","nodeIndex","prevNodeRef","prevNodeSetStyle","prevNodeIndex","prevNodeRect","next","nextNodeRef","nextNodeSetStyle","nextNodeIndex","nextNodeRect"],"sources":["../../../src/utils/useMoveNode.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { Position } from '@os-design/use-drag';\nimport NodeList, { ExistingNode } from './NodeList';\nimport getNodeRect from './getNodeRect';\nimport { NodeStyleGetter } from './useGetNodeStyle';\n\ninterface DraggedNode {\n node: ExistingNode;\n}\n\ninterface UseMoveNodeProps {\n position: Position | null;\n draggedNode: DraggedNode | null;\n getNodeStyle: NodeStyleGetter;\n}\n\ninterface MoveProps {\n list: NodeList;\n startNode: ExistingNode;\n direction: 'up' | 'down';\n destination: 'cursor' | 'end';\n isAnotherList?: boolean;\n}\n\n/* eslint-disable no-constant-condition */\n\nconst useMoveNode = (props: UseMoveNodeProps) => {\n const { position, draggedNode, getNodeStyle } = props;\n\n return useCallback(\n (options: MoveProps) => {\n const {\n list,\n startNode,\n direction,\n destination,\n isAnotherList = false,\n } = options;\n\n if (!draggedNode || !position) return startNode;\n const [, , , , draggedNodeIndex] = draggedNode.node;\n const axis = list.horizontal ? 'x' : 'y';\n const startRectProp = list.horizontal ? 'left' : 'top';\n const endRectProp = list.horizontal ? 'right' : 'bottom';\n let node = startNode;\n\n if (direction === 'up') {\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n if (!prev) return node;\n\n const [, , prevNodeRef, prevNodeSetStyle, prevNodeIndex] = prev;\n\n if (destination === 'cursor') {\n const prevNodeRect = getNodeRect(prevNodeRef);\n if (prevNodeRect && position[axis] > prevNodeRect[endRectProp]) {\n return node;\n }\n }\n\n if (isAnotherList || prevNodeIndex < draggedNodeIndex) {\n prevNodeSetStyle(getNodeStyle('down', list.horizontal));\n } else if (nodeIndex > draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n }\n\n node = prev;\n }\n } else {\n while (true) {\n const [, next, , nodeSetStyle, nodeIndex] = node;\n if (!next) return node;\n\n const [, , nextNodeRef, nextNodeSetStyle, nextNodeIndex] = next;\n\n if (destination === 'cursor') {\n const nextNodeRect = getNodeRect(nextNodeRef);\n if (nextNodeRect && position[axis] < nextNodeRect[startRectProp]) {\n return node;\n }\n }\n\n if (isAnotherList || nodeIndex < draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n } else if (nextNodeIndex > draggedNodeIndex) {\n nextNodeSetStyle(getNodeStyle('up', list.horizontal));\n }\n\n node = next;\n }\n }\n },\n [draggedNode, getNodeStyle, position]\n );\n};\n\nexport default useMoveNode;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"useMoveNode.js","names":["useCallback","getNodeRect","useMoveNode","props","position","draggedNode","getNodeStyle","options","list","startNode","direction","destination","isAnotherList","draggedNodeIndex","node","axis","horizontal","startRectProp","endRectProp","prev","nodeSetStyle","nodeIndex","prevNodeRef","prevNodeSetStyle","prevNodeIndex","prevNodeRect","next","nextNodeRef","nextNodeSetStyle","nextNodeIndex","nextNodeRect"],"sources":["../../../src/utils/useMoveNode.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { Position } from '@os-design/use-drag';\nimport NodeList, { ExistingNode } from './NodeList';\nimport getNodeRect from './getNodeRect';\nimport { NodeStyleGetter } from './useGetNodeStyle';\n\ninterface DraggedNode {\n node: ExistingNode;\n}\n\ninterface UseMoveNodeProps {\n position: Position | null;\n draggedNode: DraggedNode | null;\n getNodeStyle: NodeStyleGetter;\n}\n\ninterface MoveProps {\n list: NodeList;\n startNode: ExistingNode;\n direction: 'up' | 'down';\n destination: 'cursor' | 'end';\n isAnotherList?: boolean;\n}\n\n/* eslint-disable no-constant-condition */\n\nconst useMoveNode = (props: UseMoveNodeProps) => {\n const { position, draggedNode, getNodeStyle } = props;\n\n return useCallback(\n (options: MoveProps) => {\n const {\n list,\n startNode,\n direction,\n destination,\n isAnotherList = false,\n } = options;\n\n if (!draggedNode || !position) return startNode;\n const [, , , , draggedNodeIndex] = draggedNode.node;\n const axis = list.horizontal ? 'x' : 'y';\n const startRectProp = list.horizontal ? 'left' : 'top';\n const endRectProp = list.horizontal ? 'right' : 'bottom';\n let node = startNode;\n\n if (direction === 'up') {\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n if (!prev) return node;\n\n const [, , prevNodeRef, prevNodeSetStyle, prevNodeIndex] = prev;\n\n if (destination === 'cursor') {\n const prevNodeRect = getNodeRect(prevNodeRef);\n if (prevNodeRect && position[axis] > prevNodeRect[endRectProp]) {\n return node;\n }\n }\n\n if (isAnotherList || prevNodeIndex < draggedNodeIndex) {\n prevNodeSetStyle(getNodeStyle('down', list.horizontal));\n } else if (nodeIndex > draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n }\n\n node = prev;\n }\n } else {\n while (true) {\n const [, next, , nodeSetStyle, nodeIndex] = node;\n if (!next) return node;\n\n const [, , nextNodeRef, nextNodeSetStyle, nextNodeIndex] = next;\n\n if (destination === 'cursor') {\n const nextNodeRect = getNodeRect(nextNodeRef);\n if (nextNodeRect && position[axis] < nextNodeRect[startRectProp]) {\n return node;\n }\n }\n\n if (isAnotherList || nodeIndex < draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n } else if (nextNodeIndex > draggedNodeIndex) {\n nextNodeSetStyle(getNodeStyle('up', list.horizontal));\n }\n\n node = next;\n }\n }\n },\n [draggedNode, getNodeStyle, position]\n );\n};\n\nexport default useMoveNode;\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,OAAO;AAGnC,OAAOC,WAAW,MAAM,eAAe;AAqBvC;;AAEA,MAAMC,WAAW,GAAIC,KAAuB,IAAK;EAC/C,MAAM;IAAEC,QAAQ;IAAEC,WAAW;IAAEC;EAAa,CAAC,GAAGH,KAAK;EAErD,OAAOH,WAAW,CACfO,OAAkB,IAAK;IACtB,MAAM;MACJC,IAAI;MACJC,SAAS;MACTC,SAAS;MACTC,WAAW;MACXC,aAAa,GAAG;IAClB,CAAC,GAAGL,OAAO;IAEX,IAAI,CAACF,WAAW,IAAI,CAACD,QAAQ,EAAE,OAAOK,SAAS;IAC/C,MAAM,MAASI,gBAAgB,CAAC,GAAGR,WAAW,CAACS,IAAI;IACnD,MAAMC,IAAI,GAAGP,IAAI,CAACQ,UAAU,GAAG,GAAG,GAAG,GAAG;IACxC,MAAMC,aAAa,GAAGT,IAAI,CAACQ,UAAU,GAAG,MAAM,GAAG,KAAK;IACtD,MAAME,WAAW,GAAGV,IAAI,CAACQ,UAAU,GAAG,OAAO,GAAG,QAAQ;IACxD,IAAIF,IAAI,GAAGL,SAAS;IAEpB,IAAIC,SAAS,KAAK,IAAI,EAAE;MACtB,OAAO,IAAI,EAAE;QACX,MAAM,CAACS,IAAI,IAAMC,YAAY,EAAEC,SAAS,CAAC,GAAGP,IAAI;QAChD,IAAI,CAACK,IAAI,EAAE,OAAOL,IAAI;QAEtB,MAAM,IAAKQ,WAAW,EAAEC,gBAAgB,EAAEC,aAAa,CAAC,GAAGL,IAAI;QAE/D,IAAIR,WAAW,KAAK,QAAQ,EAAE;UAC5B,MAAMc,YAAY,GAAGxB,WAAW,CAACqB,WAAW,CAAC;UAC7C,IAAIG,YAAY,IAAIrB,QAAQ,CAACW,IAAI,CAAC,GAAGU,YAAY,CAACP,WAAW,CAAC,EAAE;YAC9D,OAAOJ,IAAI;UACb;QACF;QAEA,IAAIF,aAAa,IAAIY,aAAa,GAAGX,gBAAgB,EAAE;UACrDU,gBAAgB,CAACjB,YAAY,CAAC,MAAM,EAAEE,IAAI,CAACQ,UAAU,CAAC,CAAC;QACzD,CAAC,MAAM,IAAIK,SAAS,GAAGR,gBAAgB,EAAE;UACvCO,YAAY,CAACd,YAAY,CAAC,MAAM,EAAEE,IAAI,CAACQ,UAAU,CAAC,CAAC;QACrD;QAEAF,IAAI,GAAGK,IAAI;MACb;IACF,CAAC,MAAM;MACL,OAAO,IAAI,EAAE;QACX,MAAM,GAAGO,IAAI,GAAIN,YAAY,EAAEC,SAAS,CAAC,GAAGP,IAAI;QAChD,IAAI,CAACY,IAAI,EAAE,OAAOZ,IAAI;QAEtB,MAAM,IAAKa,WAAW,EAAEC,gBAAgB,EAAEC,aAAa,CAAC,GAAGH,IAAI;QAE/D,IAAIf,WAAW,KAAK,QAAQ,EAAE;UAC5B,MAAMmB,YAAY,GAAG7B,WAAW,CAAC0B,WAAW,CAAC;UAC7C,IAAIG,YAAY,IAAI1B,QAAQ,CAACW,IAAI,CAAC,GAAGe,YAAY,CAACb,aAAa,CAAC,EAAE;YAChE,OAAOH,IAAI;UACb;QACF;QAEA,IAAIF,aAAa,IAAIS,SAAS,GAAGR,gBAAgB,EAAE;UACjDO,YAAY,CAACd,YAAY,CAAC,MAAM,EAAEE,IAAI,CAACQ,UAAU,CAAC,CAAC;QACrD,CAAC,MAAM,IAAIa,aAAa,GAAGhB,gBAAgB,EAAE;UAC3Ce,gBAAgB,CAACtB,YAAY,CAAC,IAAI,EAAEE,IAAI,CAACQ,UAAU,CAAC,CAAC;QACvD;QAEAF,IAAI,GAAGY,IAAI;MACb;IACF;EACF,CAAC,EACD,CAACrB,WAAW,EAAEC,YAAY,EAAEF,QAAQ,CAAC,CACtC;AACH,CAAC;AAED,eAAeF,WAAW"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import { getScrollableElements } from '@os-design/use-auto-scroll';
|
|
3
|
-
|
|
4
3
|
const compare = (prevArr, nextArr) => {
|
|
5
4
|
const remove = [];
|
|
6
5
|
const add = [];
|
|
@@ -15,7 +14,6 @@ const compare = (prevArr, nextArr) => {
|
|
|
15
14
|
add
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
|
-
|
|
19
17
|
/**
|
|
20
18
|
* Sets the listener that will be called whenever the scroll event occurs
|
|
21
19
|
* in one of the elements located under the specified point.
|
|
@@ -34,9 +32,7 @@ const useScrollEventByPoint = (point, listener) => {
|
|
|
34
32
|
remove,
|
|
35
33
|
add
|
|
36
34
|
} = compare(elementsRef.current, scrollableElements);
|
|
37
|
-
|
|
38
35
|
const getTarget = item => item === document.body ? window : item;
|
|
39
|
-
|
|
40
36
|
remove.forEach(item => {
|
|
41
37
|
const index = elementsRef.current.indexOf(item);
|
|
42
38
|
if (index >= 0) elementsRef.current.splice(index, 1);
|
|
@@ -48,6 +44,5 @@ const useScrollEventByPoint = (point, listener) => {
|
|
|
48
44
|
});
|
|
49
45
|
}, [eventListener, point]);
|
|
50
46
|
};
|
|
51
|
-
|
|
52
47
|
export default useScrollEventByPoint;
|
|
53
48
|
//# sourceMappingURL=useScrollEventByPoint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScrollEventByPoint.js","names":["useCallback","useEffect","useRef","getScrollableElements","compare","prevArr","nextArr","remove","add","forEach","item","includes","push","useScrollEventByPoint","point","listener","listenerRef","current","eventListener","e","elementsRef","scrollableElements","x","y","getTarget","document","body","window","index","indexOf","splice","removeEventListener","addEventListener"],"sources":["../../../src/utils/useScrollEventByPoint.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport { getScrollableElements } from '@os-design/use-auto-scroll';\n\nconst compare = <T>(prevArr: T[], nextArr: T[]) => {\n const remove: T[] = [];\n const add: T[] = [];\n prevArr.forEach((item) => {\n if (!nextArr.includes(item)) remove.push(item);\n });\n nextArr.forEach((item) => {\n if (!prevArr.includes(item)) add.push(item);\n });\n return { remove, add };\n};\n\nexport interface Point {\n x: number;\n y: number;\n}\n\n/**\n * Sets the listener that will be called whenever the scroll event occurs\n * in one of the elements located under the specified point.\n */\nconst useScrollEventByPoint = (\n point: Point | null,\n listener: (e: Event) => void\n) => {\n const listenerRef = useRef(listener);\n useEffect(() => {\n listenerRef.current = listener;\n }, [listener]);\n\n const eventListener = useCallback((e: Event) => listenerRef.current(e), []);\n const elementsRef = useRef<Element[]>([]);\n\n useEffect(() => {\n if (!point) return;\n const scrollableElements = getScrollableElements(point.x, point.y);\n const { remove, add } = compare(elementsRef.current, scrollableElements);\n const getTarget = (item: Element) =>\n item === document.body ? window : item;\n\n remove.forEach((item) => {\n const index = elementsRef.current.indexOf(item);\n if (index >= 0) elementsRef.current.splice(index, 1);\n getTarget(item).removeEventListener('scroll', eventListener);\n });\n add.forEach((item) => {\n elementsRef.current.push(item);\n getTarget(item).addEventListener('scroll', eventListener);\n });\n }, [eventListener, point]);\n};\n\nexport default useScrollEventByPoint;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"useScrollEventByPoint.js","names":["useCallback","useEffect","useRef","getScrollableElements","compare","prevArr","nextArr","remove","add","forEach","item","includes","push","useScrollEventByPoint","point","listener","listenerRef","current","eventListener","e","elementsRef","scrollableElements","x","y","getTarget","document","body","window","index","indexOf","splice","removeEventListener","addEventListener"],"sources":["../../../src/utils/useScrollEventByPoint.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport { getScrollableElements } from '@os-design/use-auto-scroll';\n\nconst compare = <T>(prevArr: T[], nextArr: T[]) => {\n const remove: T[] = [];\n const add: T[] = [];\n prevArr.forEach((item) => {\n if (!nextArr.includes(item)) remove.push(item);\n });\n nextArr.forEach((item) => {\n if (!prevArr.includes(item)) add.push(item);\n });\n return { remove, add };\n};\n\nexport interface Point {\n x: number;\n y: number;\n}\n\n/**\n * Sets the listener that will be called whenever the scroll event occurs\n * in one of the elements located under the specified point.\n */\nconst useScrollEventByPoint = (\n point: Point | null,\n listener: (e: Event) => void\n) => {\n const listenerRef = useRef(listener);\n useEffect(() => {\n listenerRef.current = listener;\n }, [listener]);\n\n const eventListener = useCallback((e: Event) => listenerRef.current(e), []);\n const elementsRef = useRef<Element[]>([]);\n\n useEffect(() => {\n if (!point) return;\n const scrollableElements = getScrollableElements(point.x, point.y);\n const { remove, add } = compare(elementsRef.current, scrollableElements);\n const getTarget = (item: Element) =>\n item === document.body ? window : item;\n\n remove.forEach((item) => {\n const index = elementsRef.current.indexOf(item);\n if (index >= 0) elementsRef.current.splice(index, 1);\n getTarget(item).removeEventListener('scroll', eventListener);\n });\n add.forEach((item) => {\n elementsRef.current.push(item);\n getTarget(item).addEventListener('scroll', eventListener);\n });\n }, [eventListener, point]);\n};\n\nexport default useScrollEventByPoint;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACtD,SAASC,qBAAqB,QAAQ,4BAA4B;AAElE,MAAMC,OAAO,GAAG,CAAIC,OAAY,EAAEC,OAAY,KAAK;EACjD,MAAMC,MAAW,GAAG,EAAE;EACtB,MAAMC,GAAQ,GAAG,EAAE;EACnBH,OAAO,CAACI,OAAO,CAAEC,IAAI,IAAK;IACxB,IAAI,CAACJ,OAAO,CAACK,QAAQ,CAACD,IAAI,CAAC,EAAEH,MAAM,CAACK,IAAI,CAACF,IAAI,CAAC;EAChD,CAAC,CAAC;EACFJ,OAAO,CAACG,OAAO,CAAEC,IAAI,IAAK;IACxB,IAAI,CAACL,OAAO,CAACM,QAAQ,CAACD,IAAI,CAAC,EAAEF,GAAG,CAACI,IAAI,CAACF,IAAI,CAAC;EAC7C,CAAC,CAAC;EACF,OAAO;IAAEH,MAAM;IAAEC;EAAI,CAAC;AACxB,CAAC;AAOD;AACA;AACA;AACA;AACA,MAAMK,qBAAqB,GAAG,CAC5BC,KAAmB,EACnBC,QAA4B,KACzB;EACH,MAAMC,WAAW,GAAGd,MAAM,CAACa,QAAQ,CAAC;EACpCd,SAAS,CAAC,MAAM;IACde,WAAW,CAACC,OAAO,GAAGF,QAAQ;EAChC,CAAC,EAAE,CAACA,QAAQ,CAAC,CAAC;EAEd,MAAMG,aAAa,GAAGlB,WAAW,CAAEmB,CAAQ,IAAKH,WAAW,CAACC,OAAO,CAACE,CAAC,CAAC,EAAE,EAAE,CAAC;EAC3E,MAAMC,WAAW,GAAGlB,MAAM,CAAY,EAAE,CAAC;EAEzCD,SAAS,CAAC,MAAM;IACd,IAAI,CAACa,KAAK,EAAE;IACZ,MAAMO,kBAAkB,GAAGlB,qBAAqB,CAACW,KAAK,CAACQ,CAAC,EAAER,KAAK,CAACS,CAAC,CAAC;IAClE,MAAM;MAAEhB,MAAM;MAAEC;IAAI,CAAC,GAAGJ,OAAO,CAACgB,WAAW,CAACH,OAAO,EAAEI,kBAAkB,CAAC;IACxE,MAAMG,SAAS,GAAId,IAAa,IAC9BA,IAAI,KAAKe,QAAQ,CAACC,IAAI,GAAGC,MAAM,GAAGjB,IAAI;IAExCH,MAAM,CAACE,OAAO,CAAEC,IAAI,IAAK;MACvB,MAAMkB,KAAK,GAAGR,WAAW,CAACH,OAAO,CAACY,OAAO,CAACnB,IAAI,CAAC;MAC/C,IAAIkB,KAAK,IAAI,CAAC,EAAER,WAAW,CAACH,OAAO,CAACa,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;MACpDJ,SAAS,CAACd,IAAI,CAAC,CAACqB,mBAAmB,CAAC,QAAQ,EAAEb,aAAa,CAAC;IAC9D,CAAC,CAAC;IACFV,GAAG,CAACC,OAAO,CAAEC,IAAI,IAAK;MACpBU,WAAW,CAACH,OAAO,CAACL,IAAI,CAACF,IAAI,CAAC;MAC9Bc,SAAS,CAACd,IAAI,CAAC,CAACsB,gBAAgB,CAAC,QAAQ,EAAEd,aAAa,CAAC;IAC3D,CAAC,CAAC;EACJ,CAAC,EAAE,CAACA,aAAa,EAAEJ,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED,eAAeD,qBAAqB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useCallback, useMemo, useState } from 'react';
|
|
2
2
|
import useThrottle from '@os-design/use-throttle';
|
|
3
3
|
import useScrollEventByPoint from './useScrollEventByPoint';
|
|
4
|
-
|
|
5
4
|
const useTargetList = (position, listStoreRef) => {
|
|
6
5
|
const [number, setNumber] = useState(0);
|
|
7
6
|
const targetList = useMemo(() => {
|
|
@@ -16,12 +15,12 @@ const useTargetList = (position, listStoreRef) => {
|
|
|
16
15
|
|
|
17
16
|
const forceUpdate = useCallback(() => {
|
|
18
17
|
setNumber(n => n + 1);
|
|
19
|
-
}, []);
|
|
18
|
+
}, []);
|
|
20
19
|
|
|
20
|
+
// Update the target list if one of the elements located under the specified point has been scrolled
|
|
21
21
|
const [throttledForceUpdate] = useThrottle(forceUpdate, 100);
|
|
22
22
|
useScrollEventByPoint(position, throttledForceUpdate);
|
|
23
23
|
return targetList;
|
|
24
24
|
};
|
|
25
|
-
|
|
26
25
|
export default useTargetList;
|
|
27
26
|
//# sourceMappingURL=useTargetList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTargetList.js","names":["useCallback","useMemo","useState","useThrottle","useScrollEventByPoint","useTargetList","position","listStoreRef","number","setNumber","targetList","current","x","y","list","findByPosition","forceUpdate","n","throttledForceUpdate"],"sources":["../../../src/utils/useTargetList.ts"],"sourcesContent":["import { RefObject, useCallback, useMemo, useState } from 'react';\nimport useThrottle from '@os-design/use-throttle';\nimport { Position } from '@os-design/use-drag';\nimport ListStore from './ListStore';\nimport useScrollEventByPoint from './useScrollEventByPoint';\n\nconst useTargetList = (\n position: Position | null,\n listStoreRef: RefObject<ListStore>\n) => {\n const [number, setNumber] = useState(0);\n\n const targetList = useMemo(() => {\n if (!position || !listStoreRef.current) return null;\n const { x, y } = position;\n const list = listStoreRef.current.findByPosition(x, y);\n return list || null;\n }, [listStoreRef, position, number]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const forceUpdate = useCallback(() => {\n setNumber((n) => n + 1);\n }, []);\n\n // Update the target list if one of the elements located under the specified point has been scrolled\n const [throttledForceUpdate] = useThrottle(forceUpdate, 100);\n useScrollEventByPoint(position, throttledForceUpdate);\n\n return targetList;\n};\n\nexport default useTargetList;\n"],"mappings":"AAAA,SAAoBA,
|
|
1
|
+
{"version":3,"file":"useTargetList.js","names":["useCallback","useMemo","useState","useThrottle","useScrollEventByPoint","useTargetList","position","listStoreRef","number","setNumber","targetList","current","x","y","list","findByPosition","forceUpdate","n","throttledForceUpdate"],"sources":["../../../src/utils/useTargetList.ts"],"sourcesContent":["import { RefObject, useCallback, useMemo, useState } from 'react';\nimport useThrottle from '@os-design/use-throttle';\nimport { Position } from '@os-design/use-drag';\nimport ListStore from './ListStore';\nimport useScrollEventByPoint from './useScrollEventByPoint';\n\nconst useTargetList = (\n position: Position | null,\n listStoreRef: RefObject<ListStore>\n) => {\n const [number, setNumber] = useState(0);\n\n const targetList = useMemo(() => {\n if (!position || !listStoreRef.current) return null;\n const { x, y } = position;\n const list = listStoreRef.current.findByPosition(x, y);\n return list || null;\n }, [listStoreRef, position, number]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const forceUpdate = useCallback(() => {\n setNumber((n) => n + 1);\n }, []);\n\n // Update the target list if one of the elements located under the specified point has been scrolled\n const [throttledForceUpdate] = useThrottle(forceUpdate, 100);\n useScrollEventByPoint(position, throttledForceUpdate);\n\n return targetList;\n};\n\nexport default useTargetList;\n"],"mappings":"AAAA,SAAoBA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACjE,OAAOC,WAAW,MAAM,yBAAyB;AAGjD,OAAOC,qBAAqB,MAAM,yBAAyB;AAE3D,MAAMC,aAAa,GAAG,CACpBC,QAAyB,EACzBC,YAAkC,KAC/B;EACH,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAGP,QAAQ,CAAC,CAAC,CAAC;EAEvC,MAAMQ,UAAU,GAAGT,OAAO,CAAC,MAAM;IAC/B,IAAI,CAACK,QAAQ,IAAI,CAACC,YAAY,CAACI,OAAO,EAAE,OAAO,IAAI;IACnD,MAAM;MAAEC,CAAC;MAAEC;IAAE,CAAC,GAAGP,QAAQ;IACzB,MAAMQ,IAAI,GAAGP,YAAY,CAACI,OAAO,CAACI,cAAc,CAACH,CAAC,EAAEC,CAAC,CAAC;IACtD,OAAOC,IAAI,IAAI,IAAI;EACrB,CAAC,EAAE,CAACP,YAAY,EAAED,QAAQ,EAAEE,MAAM,CAAC,CAAC,CAAC,CAAC;;EAEtC,MAAMQ,WAAW,GAAGhB,WAAW,CAAC,MAAM;IACpCS,SAAS,CAAEQ,CAAC,IAAKA,CAAC,GAAG,CAAC,CAAC;EACzB,CAAC,EAAE,EAAE,CAAC;;EAEN;EACA,MAAM,CAACC,oBAAoB,CAAC,GAAGf,WAAW,CAACa,WAAW,EAAE,GAAG,CAAC;EAC5DZ,qBAAqB,CAACE,QAAQ,EAAEY,oBAAoB,CAAC;EAErD,OAAOR,UAAU;AACnB,CAAC;AAED,eAAeL,aAAa"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Creates the global style for setting the transition delay.
|
|
5
4
|
*/
|
|
@@ -19,6 +18,5 @@ const useTransitionStyle = props => {
|
|
|
19
18
|
};
|
|
20
19
|
}, [className, enabled, ms]);
|
|
21
20
|
};
|
|
22
|
-
|
|
23
21
|
export default useTransitionStyle;
|
|
24
22
|
//# sourceMappingURL=useTransitionStyle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransitionStyle.js","names":["useEffect","useTransitionStyle","props","className","ms","enabled","style","document","createElement","innerHTML","child","head","appendChild","removeChild"],"sources":["../../../src/utils/useTransitionStyle.ts"],"sourcesContent":["import { useEffect } from 'react';\n\ninterface UseTransitionStyleProps {\n className: string;\n ms: number;\n enabled: boolean;\n}\n\n/**\n * Creates the global style for setting the transition delay.\n */\nconst useTransitionStyle = (props: UseTransitionStyleProps) => {\n const { className, ms, enabled } = props;\n\n useEffect(() => {\n if (!enabled) return () => {};\n const style = document.createElement('style');\n style.innerHTML = `.${className}{transition:transform ${ms}ms;}`;\n const child = document.head.appendChild(style);\n return () => {\n document.head.removeChild(child);\n };\n }, [className, enabled, ms]);\n};\n\nexport default useTransitionStyle;\n"],"mappings":"AAAA,SAASA,
|
|
1
|
+
{"version":3,"file":"useTransitionStyle.js","names":["useEffect","useTransitionStyle","props","className","ms","enabled","style","document","createElement","innerHTML","child","head","appendChild","removeChild"],"sources":["../../../src/utils/useTransitionStyle.ts"],"sourcesContent":["import { useEffect } from 'react';\n\ninterface UseTransitionStyleProps {\n className: string;\n ms: number;\n enabled: boolean;\n}\n\n/**\n * Creates the global style for setting the transition delay.\n */\nconst useTransitionStyle = (props: UseTransitionStyleProps) => {\n const { className, ms, enabled } = props;\n\n useEffect(() => {\n if (!enabled) return () => {};\n const style = document.createElement('style');\n style.innerHTML = `.${className}{transition:transform ${ms}ms;}`;\n const child = document.head.appendChild(style);\n return () => {\n document.head.removeChild(child);\n };\n }, [className, enabled, ms]);\n};\n\nexport default useTransitionStyle;\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAQjC;AACA;AACA;AACA,MAAMC,kBAAkB,GAAIC,KAA8B,IAAK;EAC7D,MAAM;IAAEC,SAAS;IAAEC,EAAE;IAAEC;EAAQ,CAAC,GAAGH,KAAK;EAExCF,SAAS,CAAC,MAAM;IACd,IAAI,CAACK,OAAO,EAAE,OAAO,MAAM,CAAC,CAAC;IAC7B,MAAMC,KAAK,GAAGC,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC;IAC7CF,KAAK,CAACG,SAAS,GAAI,IAAGN,SAAU,yBAAwBC,EAAG,MAAK;IAChE,MAAMM,KAAK,GAAGH,QAAQ,CAACI,IAAI,CAACC,WAAW,CAACN,KAAK,CAAC;IAC9C,OAAO,MAAM;MACXC,QAAQ,CAACI,IAAI,CAACE,WAAW,CAACH,KAAK,CAAC;IAClC,CAAC;EACH,CAAC,EAAE,CAACP,SAAS,EAAEE,OAAO,EAAED,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED,eAAeH,kBAAkB"}
|
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.15",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": "git@gitlab.com:os-team/libs/os-design.git",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -29,22 +29,22 @@
|
|
|
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.7",
|
|
33
|
+
"@os-design/use-auto-scroll": "^1.0.8",
|
|
34
|
+
"@os-design/use-drag": "^1.0.6",
|
|
35
|
+
"@os-design/use-event": "^1.0.11",
|
|
36
|
+
"@os-design/use-memo-object": "^1.0.6",
|
|
37
|
+
"@os-design/use-prevent-default-event": "^1.0.6",
|
|
38
|
+
"@os-design/use-throttle": "^1.0.12"
|
|
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.8",
|
|
42
|
+
"@os-design/use-size": "^1.0.11",
|
|
43
43
|
"react-window": "^1.8.7"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=18",
|
|
47
47
|
"react-dom": ">=18"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "8cb28f6719d699c014fbce91d832a9ff06abe515"
|
|
50
50
|
}
|