@os-design/drag-sort 1.0.0

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.
Files changed (135) hide show
  1. package/LICENCE.md +1 -0
  2. package/README.md +15 -0
  3. package/dist/cjs/DragAndDrop.js +197 -0
  4. package/dist/cjs/DragAndDrop.js.map +1 -0
  5. package/dist/cjs/Draggable.js +97 -0
  6. package/dist/cjs/Draggable.js.map +1 -0
  7. package/dist/cjs/Droppable.js +112 -0
  8. package/dist/cjs/Droppable.js.map +1 -0
  9. package/dist/cjs/index.js +77 -0
  10. package/dist/cjs/index.js.map +1 -0
  11. package/dist/cjs/utils/ListStore.js +68 -0
  12. package/dist/cjs/utils/ListStore.js.map +1 -0
  13. package/dist/cjs/utils/NodeList.js +266 -0
  14. package/dist/cjs/utils/NodeList.js.map +1 -0
  15. package/dist/cjs/utils/getElementOffset.js +27 -0
  16. package/dist/cjs/utils/getElementOffset.js.map +1 -0
  17. package/dist/cjs/utils/getElementScroll.js +27 -0
  18. package/dist/cjs/utils/getElementScroll.js.map +1 -0
  19. package/dist/cjs/utils/getNodeRect.js +48 -0
  20. package/dist/cjs/utils/getNodeRect.js.map +1 -0
  21. package/dist/cjs/utils/useAppendClassName.js +27 -0
  22. package/dist/cjs/utils/useAppendClassName.js.map +1 -0
  23. package/dist/cjs/utils/useBlankNode.js +103 -0
  24. package/dist/cjs/utils/useBlankNode.js.map +1 -0
  25. package/dist/cjs/utils/useDragAndDrop.js +32 -0
  26. package/dist/cjs/utils/useDragAndDrop.js.map +1 -0
  27. package/dist/cjs/utils/useDragEffect.js +509 -0
  28. package/dist/cjs/utils/useDragEffect.js.map +1 -0
  29. package/dist/cjs/utils/useDroppable.js +35 -0
  30. package/dist/cjs/utils/useDroppable.js.map +1 -0
  31. package/dist/cjs/utils/useGeneratedId.js +22 -0
  32. package/dist/cjs/utils/useGeneratedId.js.map +1 -0
  33. package/dist/cjs/utils/useGetNodeStyle.js +28 -0
  34. package/dist/cjs/utils/useGetNodeStyle.js.map +1 -0
  35. package/dist/cjs/utils/useInitRect.js +25 -0
  36. package/dist/cjs/utils/useInitRect.js.map +1 -0
  37. package/dist/cjs/utils/useInitScrollOffset.js +27 -0
  38. package/dist/cjs/utils/useInitScrollOffset.js.map +1 -0
  39. package/dist/cjs/utils/useMoveNode.js +110 -0
  40. package/dist/cjs/utils/useMoveNode.js.map +1 -0
  41. package/dist/cjs/utils/useScrollEventByPoint.js +66 -0
  42. package/dist/cjs/utils/useScrollEventByPoint.js.map +1 -0
  43. package/dist/cjs/utils/useTargetList.js +58 -0
  44. package/dist/cjs/utils/useTargetList.js.map +1 -0
  45. package/dist/cjs/utils/useTransitionStyle.js +30 -0
  46. package/dist/cjs/utils/useTransitionStyle.js.map +1 -0
  47. package/dist/esm/DragAndDrop.js +139 -0
  48. package/dist/esm/DragAndDrop.js.map +1 -0
  49. package/dist/esm/Draggable.js +62 -0
  50. package/dist/esm/Draggable.js.map +1 -0
  51. package/dist/esm/Droppable.js +84 -0
  52. package/dist/esm/Droppable.js.map +1 -0
  53. package/dist/esm/index.js +7 -0
  54. package/dist/esm/index.js.map +1 -0
  55. package/dist/esm/utils/ListStore.js +46 -0
  56. package/dist/esm/utils/ListStore.js.map +1 -0
  57. package/dist/esm/utils/NodeList.js +207 -0
  58. package/dist/esm/utils/NodeList.js.map +1 -0
  59. package/dist/esm/utils/getElementOffset.js +19 -0
  60. package/dist/esm/utils/getElementOffset.js.map +1 -0
  61. package/dist/esm/utils/getElementScroll.js +19 -0
  62. package/dist/esm/utils/getElementScroll.js.map +1 -0
  63. package/dist/esm/utils/getNodeRect.js +36 -0
  64. package/dist/esm/utils/getNodeRect.js.map +1 -0
  65. package/dist/esm/utils/useAppendClassName.js +19 -0
  66. package/dist/esm/utils/useAppendClassName.js.map +1 -0
  67. package/dist/esm/utils/useBlankNode.js +81 -0
  68. package/dist/esm/utils/useBlankNode.js.map +1 -0
  69. package/dist/esm/utils/useDragAndDrop.js +13 -0
  70. package/dist/esm/utils/useDragAndDrop.js.map +1 -0
  71. package/dist/esm/utils/useDragEffect.js +417 -0
  72. package/dist/esm/utils/useDragEffect.js.map +1 -0
  73. package/dist/esm/utils/useDroppable.js +14 -0
  74. package/dist/esm/utils/useDroppable.js.map +1 -0
  75. package/dist/esm/utils/useGeneratedId.js +7 -0
  76. package/dist/esm/utils/useGeneratedId.js.map +1 -0
  77. package/dist/esm/utils/useGetNodeStyle.js +20 -0
  78. package/dist/esm/utils/useGetNodeStyle.js.map +1 -0
  79. package/dist/esm/utils/useInitRect.js +15 -0
  80. package/dist/esm/utils/useInitRect.js.map +1 -0
  81. package/dist/esm/utils/useInitScrollOffset.js +14 -0
  82. package/dist/esm/utils/useInitScrollOffset.js.map +1 -0
  83. package/dist/esm/utils/useMoveNode.js +62 -0
  84. package/dist/esm/utils/useMoveNode.js.map +1 -0
  85. package/dist/esm/utils/useScrollEventByPoint.js +53 -0
  86. package/dist/esm/utils/useScrollEventByPoint.js.map +1 -0
  87. package/dist/esm/utils/useTargetList.js +27 -0
  88. package/dist/esm/utils/useTargetList.js.map +1 -0
  89. package/dist/esm/utils/useTransitionStyle.js +24 -0
  90. package/dist/esm/utils/useTransitionStyle.js.map +1 -0
  91. package/dist/types/DragAndDrop.d.ts +16 -0
  92. package/dist/types/DragAndDrop.d.ts.map +1 -0
  93. package/dist/types/Draggable.d.ts +17 -0
  94. package/dist/types/Draggable.d.ts.map +1 -0
  95. package/dist/types/Droppable.d.ts +15 -0
  96. package/dist/types/Droppable.d.ts.map +1 -0
  97. package/dist/types/index.d.ts +7 -0
  98. package/dist/types/index.d.ts.map +1 -0
  99. package/dist/types/utils/ListStore.d.ts +10 -0
  100. package/dist/types/utils/ListStore.d.ts.map +1 -0
  101. package/dist/types/utils/NodeList.d.ts +42 -0
  102. package/dist/types/utils/NodeList.d.ts.map +1 -0
  103. package/dist/types/utils/getElementOffset.d.ts +6 -0
  104. package/dist/types/utils/getElementOffset.d.ts.map +1 -0
  105. package/dist/types/utils/getElementScroll.d.ts +6 -0
  106. package/dist/types/utils/getElementScroll.d.ts.map +1 -0
  107. package/dist/types/utils/getNodeRect.d.ts +9 -0
  108. package/dist/types/utils/getNodeRect.d.ts.map +1 -0
  109. package/dist/types/utils/useAppendClassName.d.ts +4 -0
  110. package/dist/types/utils/useAppendClassName.d.ts.map +1 -0
  111. package/dist/types/utils/useBlankNode.d.ts +14 -0
  112. package/dist/types/utils/useBlankNode.d.ts.map +1 -0
  113. package/dist/types/utils/useDragAndDrop.d.ts +20 -0
  114. package/dist/types/utils/useDragAndDrop.d.ts.map +1 -0
  115. package/dist/types/utils/useDragEffect.d.ts +23 -0
  116. package/dist/types/utils/useDragEffect.d.ts.map +1 -0
  117. package/dist/types/utils/useDroppable.d.ts +12 -0
  118. package/dist/types/utils/useDroppable.d.ts.map +1 -0
  119. package/dist/types/utils/useGeneratedId.d.ts +3 -0
  120. package/dist/types/utils/useGeneratedId.d.ts.map +1 -0
  121. package/dist/types/utils/useGetNodeStyle.d.ts +9 -0
  122. package/dist/types/utils/useGetNodeStyle.d.ts.map +1 -0
  123. package/dist/types/utils/useInitRect.d.ts +9 -0
  124. package/dist/types/utils/useInitRect.d.ts.map +1 -0
  125. package/dist/types/utils/useInitScrollOffset.d.ts +7 -0
  126. package/dist/types/utils/useInitScrollOffset.d.ts.map +1 -0
  127. package/dist/types/utils/useMoveNode.d.ts +15 -0
  128. package/dist/types/utils/useMoveNode.d.ts.map +1 -0
  129. package/dist/types/utils/useScrollEventByPoint.d.ts +7 -0
  130. package/dist/types/utils/useScrollEventByPoint.d.ts.map +1 -0
  131. package/dist/types/utils/useTargetList.d.ts +6 -0
  132. package/dist/types/utils/useTargetList.d.ts.map +1 -0
  133. package/dist/types/utils/useTransitionStyle.d.ts +8 -0
  134. package/dist/types/utils/useTransitionStyle.d.ts.map +1 -0
  135. package/package.json +49 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/useMoveNode.ts"],"names":["useCallback","getNodeRect","useMoveNode","position","draggedNode","getNodeStyle","props","list","startNode","type","untilTheEnd","insideAnotherList","draggedNodeIndex","node","axis","horizontal","prev","nodeSetStyle","nodeIndex","prevNodeRef","prevNodeSetStyle","prevNodeIndex","prevNodeRect","rectProp","next","nextNodeRef","nextNodeSetStyle","nextNodeIndex","nextNodeRect"],"mappings":"AAAA,SAASA,WAAT,QAA4B,OAA5B;AAKA,OAAOC,WAAP,MAAwB,eAAxB;;AAWA;AAEA,MAAMC,WAAW,GAAG,CAClBC,QADkB,EAElBC,WAFkB,EAGlBC,YAHkB,KAKlBL,WAAW,CACRM,KAAD,IAAsB;AACpB,QAAM;AACJC,IAAAA,IADI;AAEJC,IAAAA,SAFI;AAGJC,IAAAA,IAHI;AAIJC,IAAAA,WAAW,GAAG,KAJV;AAKJC,IAAAA,iBAAiB,GAAG;AALhB,MAMFL,KANJ;AAQA,MAAI,CAACF,WAAD,IAAgB,CAACD,QAArB,EAA+B,OAAOK,SAAP;AAC/B,QAAM,MAASI,gBAAT,IAA6BR,WAAW,CAACS,IAA/C;AACA,QAAMC,IAAI,GAAGP,IAAI,CAACQ,UAAL,GAAkB,GAAlB,GAAwB,GAArC;AACA,MAAIF,IAAI,GAAGL,SAAX;;AAEA,MAAIC,IAAI,KAAK,IAAb,EAAmB;AACjB,WAAO,IAAP,EAAa;AACX,YAAM,CAACO,IAAD,IAAWC,YAAX,EAAyBC,SAAzB,IAAsCL,IAA5C;AACA,UAAI,CAACG,IAAL,EAAW,OAAOH,IAAP;AACX,YAAM,IAAKM,WAAL,EAAkBC,gBAAlB,EAAoCC,aAApC,IAAqDL,IAA3D;;AACA,UAAI,CAACN,WAAL,EAAkB;AAChB,cAAMY,YAAY,GAAGrB,WAAW,CAACkB,WAAD,CAAhC;AACA,cAAMI,QAAQ,GAAGhB,IAAI,CAACQ,UAAL,GAAkB,OAAlB,GAA4B,QAA7C;AACA,YAAIO,YAAY,IAAInB,QAAQ,CAACW,IAAD,CAAR,GAAiBQ,YAAY,CAACC,QAAD,CAAjD,EACE,OAAOV,IAAP;AACH;;AACD,UAAIF,iBAAiB,IAAIU,aAAa,GAAGT,gBAAzC,EAA2D;AACzDQ,QAAAA,gBAAgB,CAACf,YAAY,CAAC,MAAD,EAASE,IAAI,CAACQ,UAAd,CAAb,CAAhB;AACD,OAFD,MAEO,IAAIG,SAAS,GAAGN,gBAAhB,EAAkC;AACvCK,QAAAA,YAAY,CAACZ,YAAY,CAAC,MAAD,EAASE,IAAI,CAACQ,UAAd,CAAb,CAAZ;AACD;;AACDF,MAAAA,IAAI,GAAGG,IAAP;AACD;AACF,GAlBD,MAkBO;AACL,WAAO,IAAP,EAAa;AACX,YAAM,GAAGQ,IAAH,GAAWP,YAAX,EAAyBC,SAAzB,IAAsCL,IAA5C;AACA,UAAI,CAACW,IAAL,EAAW,OAAOX,IAAP;AACX,YAAM,IAAKY,WAAL,EAAkBC,gBAAlB,EAAoCC,aAApC,IAAqDH,IAA3D;;AACA,UAAI,CAACd,WAAL,EAAkB;AAChB,cAAMkB,YAAY,GAAG3B,WAAW,CAACwB,WAAD,CAAhC;AACA,cAAMF,QAAQ,GAAGhB,IAAI,CAACQ,UAAL,GAAkB,MAAlB,GAA2B,KAA5C;AACA,YAAIa,YAAY,IAAIzB,QAAQ,CAACW,IAAD,CAAR,GAAiBc,YAAY,CAACL,QAAD,CAAjD,EACE,OAAOV,IAAP;AACH;;AACD,UAAIF,iBAAiB,IAAIO,SAAS,GAAGN,gBAArC,EAAuD;AACrDK,QAAAA,YAAY,CAACZ,YAAY,CAAC,MAAD,EAASE,IAAI,CAACQ,UAAd,CAAb,CAAZ;AACD,OAFD,MAEO,IAAIY,aAAa,GAAGf,gBAApB,EAAsC;AAC3Cc,QAAAA,gBAAgB,CAACrB,YAAY,CAAC,IAAD,EAAOE,IAAI,CAACQ,UAAZ,CAAb,CAAhB;AACD;;AACDF,MAAAA,IAAI,GAAGW,IAAP;AACD;AACF;AACF,CApDQ,EAqDT,CAACpB,WAAD,EAAcC,YAAd,EAA4BF,QAA5B,CArDS,CALb;;AA6DA,eAAeD,WAAf","sourcesContent":["import { useCallback } from 'react';\nimport { Position } from '@os-design/use-drag';\nimport NodeList, { ExistingNode } from './NodeList';\n// eslint-disable-next-line import/no-cycle\nimport { DraggedNode } from './useDragEffect';\nimport getNodeRect from './getNodeRect';\nimport { NodeStyleGetter } from './useGetNodeStyle';\n\ninterface MoveProps {\n list: NodeList;\n startNode: ExistingNode;\n type: 'up' | 'down';\n untilTheEnd?: boolean;\n insideAnotherList?: boolean;\n}\n\n/* eslint-disable no-constant-condition */\n\nconst useMoveNode = (\n position: Position | null,\n draggedNode: DraggedNode | null,\n getNodeStyle: NodeStyleGetter\n) =>\n useCallback(\n (props: MoveProps) => {\n const {\n list,\n startNode,\n type,\n untilTheEnd = false,\n insideAnotherList = false,\n } = props;\n\n if (!draggedNode || !position) return startNode;\n const [, , , , draggedNodeIndex] = draggedNode.node;\n const axis = list.horizontal ? 'x' : 'y';\n let node = startNode;\n\n if (type === 'up') {\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n if (!prev) return node;\n const [, , prevNodeRef, prevNodeSetStyle, prevNodeIndex] = prev;\n if (!untilTheEnd) {\n const prevNodeRect = getNodeRect(prevNodeRef);\n const rectProp = list.horizontal ? 'right' : 'bottom';\n if (prevNodeRect && position[axis] > prevNodeRect[rectProp])\n return node;\n }\n if (insideAnotherList || prevNodeIndex < draggedNodeIndex) {\n prevNodeSetStyle(getNodeStyle('down', list.horizontal));\n } else if (nodeIndex > draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n }\n node = prev;\n }\n } else {\n while (true) {\n const [, next, , nodeSetStyle, nodeIndex] = node;\n if (!next) return node;\n const [, , nextNodeRef, nextNodeSetStyle, nextNodeIndex] = next;\n if (!untilTheEnd) {\n const nextNodeRect = getNodeRect(nextNodeRef);\n const rectProp = list.horizontal ? 'left' : 'top';\n if (nextNodeRect && position[axis] < nextNodeRect[rectProp])\n return node;\n }\n if (insideAnotherList || nodeIndex < draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n } else if (nextNodeIndex > draggedNodeIndex) {\n nextNodeSetStyle(getNodeStyle('up', list.horizontal));\n }\n node = next;\n }\n }\n },\n [draggedNode, getNodeStyle, position]\n );\n\nexport default useMoveNode;\n"],"file":"useMoveNode.js"}
@@ -0,0 +1,53 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { getScrollableElements } from '@os-design/use-auto-scroll';
3
+
4
+ const compare = (prevArr, nextArr) => {
5
+ const remove = [];
6
+ const add = [];
7
+ prevArr.forEach(item => {
8
+ if (!nextArr.includes(item)) remove.push(item);
9
+ });
10
+ nextArr.forEach(item => {
11
+ if (!prevArr.includes(item)) add.push(item);
12
+ });
13
+ return {
14
+ remove,
15
+ add
16
+ };
17
+ };
18
+
19
+ /**
20
+ * Sets the listener that will be called whenever the scroll event occurs
21
+ * in one of the elements located under the specified point.
22
+ */
23
+ const useScrollEventByPoint = (point, listener) => {
24
+ const listenerRef = useRef(listener);
25
+ useEffect(() => {
26
+ listenerRef.current = listener;
27
+ }, [listener]);
28
+ const eventListener = useCallback(e => listenerRef.current(e), []);
29
+ const elementsRef = useRef([]);
30
+ useEffect(() => {
31
+ if (!point) return;
32
+ const scrollableElements = getScrollableElements(point.x, point.y);
33
+ const {
34
+ remove,
35
+ add
36
+ } = compare(elementsRef.current, scrollableElements);
37
+
38
+ const getTarget = item => item === document.body ? window : item;
39
+
40
+ remove.forEach(item => {
41
+ const index = elementsRef.current.indexOf(item);
42
+ if (index >= 0) elementsRef.current.splice(index, 1);
43
+ getTarget(item).removeEventListener('scroll', eventListener);
44
+ });
45
+ add.forEach(item => {
46
+ elementsRef.current.push(item);
47
+ getTarget(item).addEventListener('scroll', eventListener);
48
+ });
49
+ }, [eventListener, point]);
50
+ };
51
+
52
+ export default useScrollEventByPoint;
53
+ //# sourceMappingURL=useScrollEventByPoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/useScrollEventByPoint.ts"],"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"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,MAAjC,QAA+C,OAA/C;AACA,SAASC,qBAAT,QAAsC,4BAAtC;;AAEA,MAAMC,OAAO,GAAG,CAAIC,OAAJ,EAAkBC,OAAlB,KAAmC;AACjD,QAAMC,MAAW,GAAG,EAApB;AACA,QAAMC,GAAQ,GAAG,EAAjB;AACAH,EAAAA,OAAO,CAACI,OAAR,CAAiBC,IAAD,IAAU;AACxB,QAAI,CAACJ,OAAO,CAACK,QAAR,CAAiBD,IAAjB,CAAL,EAA6BH,MAAM,CAACK,IAAP,CAAYF,IAAZ;AAC9B,GAFD;AAGAJ,EAAAA,OAAO,CAACG,OAAR,CAAiBC,IAAD,IAAU;AACxB,QAAI,CAACL,OAAO,CAACM,QAAR,CAAiBD,IAAjB,CAAL,EAA6BF,GAAG,CAACI,IAAJ,CAASF,IAAT;AAC9B,GAFD;AAGA,SAAO;AAAEH,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAP;AACD,CAVD;;AAiBA;AACA;AACA;AACA;AACA,MAAMK,qBAAqB,GAAG,CAC5BC,KAD4B,EAE5BC,QAF4B,KAGzB;AACH,QAAMC,WAAW,GAAGd,MAAM,CAACa,QAAD,CAA1B;AACAd,EAAAA,SAAS,CAAC,MAAM;AACde,IAAAA,WAAW,CAACC,OAAZ,GAAsBF,QAAtB;AACD,GAFQ,EAEN,CAACA,QAAD,CAFM,CAAT;AAIA,QAAMG,aAAa,GAAGlB,WAAW,CAAEmB,CAAD,IAAcH,WAAW,CAACC,OAAZ,CAAoBE,CAApB,CAAf,EAAuC,EAAvC,CAAjC;AACA,QAAMC,WAAW,GAAGlB,MAAM,CAAY,EAAZ,CAA1B;AAEAD,EAAAA,SAAS,CAAC,MAAM;AACd,QAAI,CAACa,KAAL,EAAY;AACZ,UAAMO,kBAAkB,GAAGlB,qBAAqB,CAACW,KAAK,CAACQ,CAAP,EAAUR,KAAK,CAACS,CAAhB,CAAhD;AACA,UAAM;AAAEhB,MAAAA,MAAF;AAAUC,MAAAA;AAAV,QAAkBJ,OAAO,CAACgB,WAAW,CAACH,OAAb,EAAsBI,kBAAtB,CAA/B;;AACA,UAAMG,SAAS,GAAId,IAAD,IAChBA,IAAI,KAAKe,QAAQ,CAACC,IAAlB,GAAyBC,MAAzB,GAAkCjB,IADpC;;AAGAH,IAAAA,MAAM,CAACE,OAAP,CAAgBC,IAAD,IAAU;AACvB,YAAMkB,KAAK,GAAGR,WAAW,CAACH,OAAZ,CAAoBY,OAApB,CAA4BnB,IAA5B,CAAd;AACA,UAAIkB,KAAK,IAAI,CAAb,EAAgBR,WAAW,CAACH,OAAZ,CAAoBa,MAApB,CAA2BF,KAA3B,EAAkC,CAAlC;AAChBJ,MAAAA,SAAS,CAACd,IAAD,CAAT,CAAgBqB,mBAAhB,CAAoC,QAApC,EAA8Cb,aAA9C;AACD,KAJD;AAKAV,IAAAA,GAAG,CAACC,OAAJ,CAAaC,IAAD,IAAU;AACpBU,MAAAA,WAAW,CAACH,OAAZ,CAAoBL,IAApB,CAAyBF,IAAzB;AACAc,MAAAA,SAAS,CAACd,IAAD,CAAT,CAAgBsB,gBAAhB,CAAiC,QAAjC,EAA2Cd,aAA3C;AACD,KAHD;AAID,GAhBQ,EAgBN,CAACA,aAAD,EAAgBJ,KAAhB,CAhBM,CAAT;AAiBD,CA7BD;;AA+BA,eAAeD,qBAAf","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"],"file":"useScrollEventByPoint.js"}
@@ -0,0 +1,27 @@
1
+ import { useCallback, useMemo, useState } from 'react';
2
+ import useThrottle from '@os-design/use-throttle';
3
+ import useScrollEventByPoint from './useScrollEventByPoint';
4
+
5
+ const useTargetList = (position, listStoreRef) => {
6
+ const [number, setNumber] = useState(0);
7
+ const targetList = useMemo(() => {
8
+ if (!position || !listStoreRef.current) return null;
9
+ const {
10
+ x,
11
+ y
12
+ } = position;
13
+ const list = listStoreRef.current.findByPosition(x, y);
14
+ return list || null;
15
+ }, [listStoreRef, position, number]); // eslint-disable-line react-hooks/exhaustive-deps
16
+
17
+ const forceUpdate = useCallback(() => {
18
+ setNumber(n => n + 1);
19
+ }, []); // Update the target list if one of the elements located under the specified point has been scrolled
20
+
21
+ const [throttledForceUpdate] = useThrottle(forceUpdate, 100);
22
+ useScrollEventByPoint(position, throttledForceUpdate);
23
+ return targetList;
24
+ };
25
+
26
+ export default useTargetList;
27
+ //# sourceMappingURL=useTargetList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/useTargetList.ts"],"names":["useCallback","useMemo","useState","useThrottle","useScrollEventByPoint","useTargetList","position","listStoreRef","number","setNumber","targetList","current","x","y","list","findByPosition","forceUpdate","n","throttledForceUpdate"],"mappings":"AAAA,SAAoBA,WAApB,EAAiCC,OAAjC,EAA0CC,QAA1C,QAA0D,OAA1D;AACA,OAAOC,WAAP,MAAwB,yBAAxB;AAGA,OAAOC,qBAAP,MAAkC,yBAAlC;;AAEA,MAAMC,aAAa,GAAG,CACpBC,QADoB,EAEpBC,YAFoB,KAGjB;AACH,QAAM,CAACC,MAAD,EAASC,SAAT,IAAsBP,QAAQ,CAAC,CAAD,CAApC;AAEA,QAAMQ,UAAU,GAAGT,OAAO,CAAC,MAAM;AAC/B,QAAI,CAACK,QAAD,IAAa,CAACC,YAAY,CAACI,OAA/B,EAAwC,OAAO,IAAP;AACxC,UAAM;AAAEC,MAAAA,CAAF;AAAKC,MAAAA;AAAL,QAAWP,QAAjB;AACA,UAAMQ,IAAI,GAAGP,YAAY,CAACI,OAAb,CAAqBI,cAArB,CAAoCH,CAApC,EAAuCC,CAAvC,CAAb;AACA,WAAOC,IAAI,IAAI,IAAf;AACD,GALyB,EAKvB,CAACP,YAAD,EAAeD,QAAf,EAAyBE,MAAzB,CALuB,CAA1B,CAHG,CAQmC;;AAEtC,QAAMQ,WAAW,GAAGhB,WAAW,CAAC,MAAM;AACpCS,IAAAA,SAAS,CAAEQ,CAAD,IAAOA,CAAC,GAAG,CAAZ,CAAT;AACD,GAF8B,EAE5B,EAF4B,CAA/B,CAVG,CAcH;;AACA,QAAM,CAACC,oBAAD,IAAyBf,WAAW,CAACa,WAAD,EAAc,GAAd,CAA1C;AACAZ,EAAAA,qBAAqB,CAACE,QAAD,EAAWY,oBAAX,CAArB;AAEA,SAAOR,UAAP;AACD,CAtBD;;AAwBA,eAAeL,aAAf","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"],"file":"useTargetList.js"}
@@ -0,0 +1,24 @@
1
+ import { useEffect } from 'react';
2
+
3
+ /**
4
+ * Creates the global style for setting the transition delay.
5
+ */
6
+ const useTransitionStyle = props => {
7
+ const {
8
+ className,
9
+ ms,
10
+ enabled
11
+ } = props;
12
+ useEffect(() => {
13
+ if (!enabled) return () => {};
14
+ const style = document.createElement('style');
15
+ style.innerHTML = `.${className}{transition:transform ${ms}ms;}`;
16
+ const child = document.head.appendChild(style);
17
+ return () => {
18
+ document.head.removeChild(child);
19
+ };
20
+ }, [className, enabled, ms]);
21
+ };
22
+
23
+ export default useTransitionStyle;
24
+ //# sourceMappingURL=useTransitionStyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/useTransitionStyle.ts"],"names":["useEffect","useTransitionStyle","props","className","ms","enabled","style","document","createElement","innerHTML","child","head","appendChild","removeChild"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;;AAQA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAIC,KAAD,IAAoC;AAC7D,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,EAAb;AAAiBC,IAAAA;AAAjB,MAA6BH,KAAnC;AAEAF,EAAAA,SAAS,CAAC,MAAM;AACd,QAAI,CAACK,OAAL,EAAc,OAAO,MAAM,CAAE,CAAf;AACd,UAAMC,KAAK,GAAGC,QAAQ,CAACC,aAAT,CAAuB,OAAvB,CAAd;AACAF,IAAAA,KAAK,CAACG,SAAN,GAAmB,IAAGN,SAAU,yBAAwBC,EAAG,MAA3D;AACA,UAAMM,KAAK,GAAGH,QAAQ,CAACI,IAAT,CAAcC,WAAd,CAA0BN,KAA1B,CAAd;AACA,WAAO,MAAM;AACXC,MAAAA,QAAQ,CAACI,IAAT,CAAcE,WAAd,CAA0BH,KAA1B;AACD,KAFD;AAGD,GARQ,EAQN,CAACP,SAAD,EAAYE,OAAZ,EAAqBD,EAArB,CARM,CAAT;AASD,CAZD;;AAcA,eAAeH,kBAAf","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"],"file":"useTransitionStyle.js"}
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { PortalProps } from '@os-design/portal';
3
+ import { DragEndHandler } from './utils/useDragEffect';
4
+ export interface DragAndDropProps {
5
+ draggedNodeContainer?: PortalProps['container'];
6
+ minMouseDistPx?: number;
7
+ longPressMs?: number;
8
+ autoScrollDistPercent?: number;
9
+ autoScrollMaxSpeedPx?: number;
10
+ transitionDelayMs?: number;
11
+ onDragEnd?: DragEndHandler;
12
+ }
13
+ declare const DragAndDrop: React.FC<DragAndDropProps>;
14
+ export type { DragEndHandler } from './utils/useDragEffect';
15
+ export default DragAndDrop;
16
+ //# sourceMappingURL=DragAndDrop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DragAndDrop.d.ts","sourceRoot":"","sources":["../../src/DragAndDrop.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AASf,OAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKxD,OAAsB,EACpB,cAAc,EAEf,MAAM,uBAAuB,CAAC;AAI/B,MAAM,WAAW,gBAAgB;IAK/B,oBAAoB,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IAKhD,cAAc,CAAC,EAAE,MAAM,CAAC;IAKxB,WAAW,CAAC,EAAE,MAAM,CAAC;IAKrB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAK/B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAK9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAK3B,SAAS,CAAC,EAAE,cAAc,CAAC;CAC5B;AAUD,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CA6I3C,CAAC;AAEF,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,eAAe,WAAW,CAAC"}
@@ -0,0 +1,17 @@
1
+ import React, { CSSProperties, RefObject, MouseEvent, TouchEvent } from 'react';
2
+ export interface DraggableHandlers {
3
+ onMouseDown: (e: MouseEvent) => void;
4
+ onTouchStart: (e: TouchEvent) => void;
5
+ }
6
+ export interface DraggableChildrenProps {
7
+ ref: RefObject<HTMLDivElement>;
8
+ style: CSSProperties;
9
+ handlers: DraggableHandlers;
10
+ }
11
+ export interface DraggableProps {
12
+ index: number;
13
+ children: (props: DraggableChildrenProps) => React.ReactNode;
14
+ }
15
+ declare const Draggable: React.FC<DraggableProps>;
16
+ export default Draggable;
17
+ //# sourceMappingURL=Draggable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Draggable.d.ts","sourceRoot":"","sources":["../../src/Draggable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,SAAS,EAKT,UAAU,EACV,UAAU,EACX,MAAM,OAAO,CAAC;AAOf,MAAM,WAAW,iBAAiB;IAIhC,WAAW,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IAIrC,YAAY,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,sBAAsB;IAIrC,GAAG,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAI/B,KAAK,EAAE,aAAa,CAAC;IAIrB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAI7B,KAAK,EAAE,MAAM,CAAC;IAId,QAAQ,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,KAAK,CAAC,SAAS,CAAC;CAC9D;AAED,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA+CvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,15 @@
1
+ import React, { RefObject } from 'react';
2
+ import { RenderDraggedNode } from './utils/NodeList';
3
+ export interface DroppableChildrenProps {
4
+ ref: RefObject<HTMLDivElement>;
5
+ innerRef: RefObject<HTMLDivElement>;
6
+ }
7
+ export interface DroppableProps {
8
+ renderDraggedNode: RenderDraggedNode;
9
+ id?: string;
10
+ horizontal?: boolean;
11
+ children: React.ReactNode | ((props: DroppableChildrenProps) => React.ReactNode);
12
+ }
13
+ declare const Droppable: React.FC<DroppableProps>;
14
+ export default Droppable;
15
+ //# sourceMappingURL=Droppable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Droppable.d.ts","sourceRoot":"","sources":["../../src/Droppable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,SAAS,EAOV,MAAM,OAAO,CAAC;AAEf,OAAiB,EAGf,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAK1B,MAAM,WAAW,sBAAsB;IAKrC,GAAG,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAK/B,QAAQ,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,cAAc;IAI7B,iBAAiB,EAAE,iBAAiB,CAAC;IAMrC,EAAE,CAAC,EAAE,MAAM,CAAC;IAKZ,UAAU,CAAC,EAAE,OAAO,CAAC;IAIrB,QAAQ,EACJ,KAAK,CAAC,SAAS,GACf,CAAC,CAAC,KAAK,EAAE,sBAAsB,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;CAC1D;AAED,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAyFvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { default as DragAndDrop } from './DragAndDrop';
2
+ export { default as Droppable } from './Droppable';
3
+ export { default as Draggable } from './Draggable';
4
+ export * from './DragAndDrop';
5
+ export * from './Droppable';
6
+ export * from './Draggable';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,10 @@
1
+ import NodeList from './NodeList';
2
+ declare class ListStore {
3
+ private lists;
4
+ constructor();
5
+ add(list: NodeList): void;
6
+ remove(id: string): void;
7
+ findByPosition(x: number, y: number): NodeList | undefined;
8
+ }
9
+ export default ListStore;
10
+ //# sourceMappingURL=ListStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListStore.d.ts","sourceRoot":"","sources":["../../../src/utils/ListStore.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAKlC,cAAM,SAAS;IACb,OAAO,CAAC,KAAK,CAAa;;IASnB,GAAG,CAAC,IAAI,EAAE,QAAQ;IAOlB,MAAM,CAAC,EAAE,EAAE,MAAM;IASjB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;CAa3C;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,42 @@
1
+ import React, { CSSProperties, RefObject } from 'react';
2
+ export declare type Node = [Node, Node, RefObject<any>, (style: CSSProperties) => void, number] | null;
3
+ export declare type ExistingNode = Exclude<Node, null>;
4
+ export interface NodeProps {
5
+ ref: React.MutableRefObject<any>;
6
+ setStyle: (style: CSSProperties) => void;
7
+ index: number;
8
+ }
9
+ interface RenderDraggedNodeProps {
10
+ index: number;
11
+ style: CSSProperties;
12
+ }
13
+ export declare type RenderDraggedNode = (props: RenderDraggedNodeProps) => React.ReactNode;
14
+ interface InitProps {
15
+ id: string;
16
+ ref: RefObject<HTMLDivElement>;
17
+ innerRef: RefObject<HTMLDivElement>;
18
+ horizontal: boolean;
19
+ renderDraggedNode: RenderDraggedNode;
20
+ }
21
+ declare class NodeList {
22
+ id: string;
23
+ ref: RefObject<HTMLDivElement>;
24
+ innerRef: RefObject<HTMLDivElement>;
25
+ horizontal: boolean;
26
+ renderDraggedNode: RenderDraggedNode;
27
+ private head;
28
+ private tail;
29
+ private listeners;
30
+ constructor(props: InitProps);
31
+ getHead(): Node;
32
+ getTail(): Node;
33
+ private addToTheBeginning;
34
+ private addToTheEnd;
35
+ private static addAfter;
36
+ add(props: NodeProps): ExistingNode;
37
+ remove(node: ExistingNode): void;
38
+ addListener(callback: (props: NodeProps) => void): void;
39
+ removeListener(callback: (props: NodeProps) => void): void;
40
+ }
41
+ export default NodeList;
42
+ //# sourceMappingURL=NodeList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeList.d.ts","sourceRoot":"","sources":["../../../src/utils/NodeList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKxD,oBAAY,IAAI,GACZ,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAAE,MAAM,CAAC,GACpE,IAAI,CAAC;AAET,oBAAY,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAE/C,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACjC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,sBAAsB;IAI9B,KAAK,EAAE,MAAM,CAAC;IAId,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,oBAAY,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,CAAC,CAAC;IAC/B,QAAQ,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAMD,cAAM,QAAQ;IAIL,EAAE,EAAE,MAAM,CAAC;IAKX,GAAG,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAM/B,QAAQ,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAKpC,UAAU,EAAE,OAAO,CAAC;IAKpB,iBAAiB,EAAE,iBAAiB,CAAC;IAK5C,OAAO,CAAC,IAAI,CAAO;IAKnB,OAAO,CAAC,IAAI,CAAO;IAKnB,OAAO,CAAC,SAAS,CAAoC;gBAElC,KAAK,EAAE,SAAS;IAW5B,OAAO;IAIP,OAAO;IAQd,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,MAAM,CAAC,QAAQ;IAWhB,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY;IAgDnC,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"}
@@ -0,0 +1,6 @@
1
+ declare const getElementOffset: (element: HTMLElement) => {
2
+ offsetLeft: number;
3
+ offsetTop: number;
4
+ };
5
+ export default getElementOffset;
6
+ //# sourceMappingURL=getElementOffset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getElementOffset.d.ts","sourceRoot":"","sources":["../../../src/utils/getElementOffset.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,YAAa,WAAW;;;CAU7C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const getElementScroll: (element: HTMLElement) => {
2
+ scrollLeft: number;
3
+ scrollTop: number;
4
+ };
5
+ export default getElementScroll;
6
+ //# sourceMappingURL=getElementScroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getElementScroll.d.ts","sourceRoot":"","sources":["../../../src/utils/getElementScroll.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,gBAAgB,YAAa,WAAW;;;CAU7C,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { RefObject } from 'react';
2
+ declare const getNodeRect: (ref: RefObject<HTMLElement>) => {
3
+ left: number;
4
+ top: number;
5
+ right: number;
6
+ bottom: number;
7
+ } | null;
8
+ export default getNodeRect;
9
+ //# sourceMappingURL=getNodeRect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getNodeRect.d.ts","sourceRoot":"","sources":["../../../src/utils/getNodeRect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOlC,QAAA,MAAM,WAAW,QAAS,UAAU,WAAW,CAAC;;;;;QAmB/C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { RefObject } from 'react';
2
+ declare const useAppendClassName: (ref: RefObject<HTMLElement>, className: string) => void;
3
+ export default useAppendClassName;
4
+ //# sourceMappingURL=useAppendClassName.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAppendClassName.d.ts","sourceRoot":"","sources":["../../../src/utils/useAppendClassName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAK7C,QAAA,MAAM,kBAAkB,QAAS,UAAU,WAAW,CAAC,aAAa,MAAM,SAYzE,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import NodeList from './NodeList';
2
+ import { DraggedNode } from './useDragEffect';
3
+ interface InitSize {
4
+ initWidth: number;
5
+ initHeight: number;
6
+ }
7
+ interface UseBlankNodeProps {
8
+ draggedNode: DraggedNode | null;
9
+ targetList: NodeList | null;
10
+ initDraggedNodeRect: InitSize | null;
11
+ }
12
+ declare const useBlankNode: (props: UseBlankNodeProps) => () => void;
13
+ export default useBlankNode;
14
+ //# sourceMappingURL=useBlankNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlankNode.d.ts","sourceRoot":"","sources":["../../../src/utils/useBlankNode.ts"],"names":[],"mappings":"AACA,OAAO,QAA0B,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,UAAU,QAAQ;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,iBAAiB;IACzB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5B,mBAAmB,EAAE,QAAQ,GAAG,IAAI,CAAC;CACtC;AAWD,QAAA,MAAM,YAAY,UAAW,iBAAiB,eAyE7C,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,20 @@
1
+ import React, { MouseEvent, TouchEvent } from 'react';
2
+ import { Position } from '@os-design/use-drag';
3
+ import NodeList, { ExistingNode } from './NodeList';
4
+ export interface SetDraggedNodeProps {
5
+ list: NodeList;
6
+ node: ExistingNode;
7
+ position: Position;
8
+ }
9
+ declare type NodeEventHandler<T> = (e: T, list: NodeList, node: ExistingNode) => void;
10
+ interface DragAndDropContextProps {
11
+ registerList: (list: NodeList) => void;
12
+ deregisterList: (id: string) => void;
13
+ onMouseDown: NodeEventHandler<MouseEvent>;
14
+ onTouchStart: NodeEventHandler<TouchEvent>;
15
+ nodeClassName: string;
16
+ }
17
+ export declare const DragAndDropContext: React.Context<DragAndDropContextProps>;
18
+ declare const useDragAndDrop: () => DragAndDropContextProps;
19
+ export default useDragAndDrop;
20
+ //# sourceMappingURL=useDragAndDrop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDragAndDrop.d.ts","sourceRoot":"","sources":["../../../src/utils/useDragAndDrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAc,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,QAAQ,EAAE,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,aAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;AAE9E,UAAU,uBAAuB;IAC/B,YAAY,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACvC,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC1C,YAAY,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC3C,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,eAAO,MAAM,kBAAkB,wCAM7B,CAAC;AAEH,QAAA,MAAM,cAAc,QAAO,uBACK,CAAC;AAEjC,eAAe,cAAc,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Position } from '@os-design/use-drag';
2
+ import { RefObject } from 'react';
3
+ import NodeList, { ExistingNode } from './NodeList';
4
+ import ListStore from './ListStore';
5
+ export interface DraggedNode {
6
+ list: NodeList;
7
+ node: ExistingNode;
8
+ position: Position;
9
+ }
10
+ export interface ItemLocation {
11
+ id: string;
12
+ index: number;
13
+ }
14
+ export declare type DragEndHandler = (dragged: ItemLocation, target: ItemLocation) => void;
15
+ interface UseDragEffectProps {
16
+ draggedNode: DraggedNode | null;
17
+ cursorPosition: Position;
18
+ listStoreRef: RefObject<ListStore>;
19
+ onDragEnd: DragEndHandler;
20
+ }
21
+ declare const useDragEffect: (props: UseDragEffectProps) => void;
22
+ export default useDragEffect;
23
+ //# sourceMappingURL=useDragEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDragEffect.d.ts","sourceRoot":"","sources":["../../../src/utils/useDragEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAEL,SAAS,EAKV,MAAM,OAAO,CAAC;AAGf,OAAO,QAAQ,EAAE,EAAE,YAAY,EAAmB,MAAM,YAAY,CAAC;AACrE,OAAO,SAAS,MAAM,aAAa,CAAC;AAYpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAOD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,oBAAY,cAAc,GAAG,CAC3B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,YAAY,KACjB,IAAI,CAAC;AAEV,UAAU,kBAAkB;IAC1B,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,QAAQ,CAAC;IACzB,YAAY,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACnC,SAAS,EAAE,cAAc,CAAC;CAC3B;AAiBD,QAAA,MAAM,aAAa,UAAW,kBAAkB,SAqY/C,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,12 @@
1
+ import React, { MouseEvent, TouchEvent } from 'react';
2
+ import { ExistingNode, NodeProps } from './NodeList';
3
+ interface DroppableContextProps {
4
+ registerNode: (props: NodeProps) => ExistingNode;
5
+ deregisterNode: (node: ExistingNode) => void;
6
+ onMouseDown: (e: MouseEvent, node: ExistingNode) => void;
7
+ onTouchStart: (e: TouchEvent, node: ExistingNode) => void;
8
+ }
9
+ export declare const DroppableContext: React.Context<DroppableContextProps>;
10
+ declare const useDroppable: () => DroppableContextProps;
11
+ export default useDroppable;
12
+ //# sourceMappingURL=useDroppable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDroppable.d.ts","sourceRoot":"","sources":["../../../src/utils/useDroppable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAc,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAErD,UAAU,qBAAqB;IAC7B,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,YAAY,CAAC;IACjD,cAAc,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IAC7C,WAAW,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACzD,YAAY,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;CAC3D;AAED,eAAO,MAAM,gBAAgB,sCAM3B,CAAC;AAEH,QAAA,MAAM,YAAY,QAAO,qBAAqD,CAAC;AAE/E,eAAe,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const useGeneratedId: (size: number) => string;
2
+ export default useGeneratedId;
3
+ //# sourceMappingURL=useGeneratedId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGeneratedId.d.ts","sourceRoot":"","sources":["../../../src/utils/useGeneratedId.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,cAAc,SAAU,MAAM,WAC6B,CAAC;AAElE,eAAe,cAAc,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { CSSProperties } from 'react';
2
+ interface InitSize {
3
+ initWidth: number;
4
+ initHeight: number;
5
+ }
6
+ export declare type NodeStyleGetter = (type: 'up' | 'down' | 'init', horizontal: boolean) => CSSProperties;
7
+ declare const useGetNodeStyle: (size: InitSize | null) => NodeStyleGetter;
8
+ export default useGetNodeStyle;
9
+ //# sourceMappingURL=useGetNodeStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGetNodeStyle.d.ts","sourceRoot":"","sources":["../../../src/utils/useGetNodeStyle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkC,MAAM,OAAO,CAAC;AAEtE,UAAU,QAAQ;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,oBAAY,eAAe,GAAG,CAC5B,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC5B,UAAU,EAAE,OAAO,KAChB,aAAa,CAAC;AAEnB,QAAA,MAAM,eAAe,SAAU,QAAQ,GAAG,IAAI,KAAG,eAmBhD,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { RefObject } from 'react';
2
+ declare const useInitRect: (ref?: RefObject<HTMLElement> | undefined) => {
3
+ initX: number;
4
+ initY: number;
5
+ initWidth: number;
6
+ initHeight: number;
7
+ } | null;
8
+ export default useInitRect;
9
+ //# sourceMappingURL=useInitRect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInitRect.d.ts","sourceRoot":"","sources":["../../../src/utils/useInitRect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AAE3C,QAAA,MAAM,WAAW;;;;;QAUN,CAAC;AAEZ,eAAe,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { RefObject } from 'react';
2
+ declare const useInitScrollOffset: (ref?: RefObject<HTMLElement> | undefined) => {
3
+ initScrollLeft: number;
4
+ initScrollTop: number;
5
+ } | null;
6
+ export default useInitScrollOffset;
7
+ //# sourceMappingURL=useInitScrollOffset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInitScrollOffset.d.ts","sourceRoot":"","sources":["../../../src/utils/useInitScrollOffset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AAG3C,QAAA,MAAM,mBAAmB;;;QAQd,CAAC;AAEZ,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { Position } from '@os-design/use-drag';
3
+ import NodeList, { ExistingNode } from './NodeList';
4
+ import { DraggedNode } from './useDragEffect';
5
+ import { NodeStyleGetter } from './useGetNodeStyle';
6
+ interface MoveProps {
7
+ list: NodeList;
8
+ startNode: ExistingNode;
9
+ type: 'up' | 'down';
10
+ untilTheEnd?: boolean;
11
+ insideAnotherList?: boolean;
12
+ }
13
+ declare const useMoveNode: (position: Position | null, draggedNode: DraggedNode | null, getNodeStyle: NodeStyleGetter) => (props: MoveProps) => [import("./NodeList").Node, import("./NodeList").Node, import("react").RefObject<any>, (style: import("react").CSSProperties) => void, number];
14
+ export default useMoveNode;
15
+ //# sourceMappingURL=useMoveNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMoveNode.d.ts","sourceRoot":"","sources":["../../../src/utils/useMoveNode.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,QAAQ,EAAE,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,UAAU,SAAS;IACjB,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,YAAY,CAAC;IACxB,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAID,QAAA,MAAM,WAAW,aACL,QAAQ,GAAG,IAAI,eACZ,WAAW,GAAG,IAAI,gBACjB,eAAe,aAGnB,SAAS,mJAqDlB,CAAC;AAEJ,eAAe,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ export interface Point {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ declare const useScrollEventByPoint: (point: Point | null, listener: (e: Event) => void) => void;
6
+ export default useScrollEventByPoint;
7
+ //# sourceMappingURL=useScrollEventByPoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScrollEventByPoint.d.ts","sourceRoot":"","sources":["../../../src/utils/useScrollEventByPoint.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAMD,QAAA,MAAM,qBAAqB,UAClB,KAAK,GAAG,IAAI,gBACL,KAAK,KAAK,IAAI,SA2B7B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { RefObject } from 'react';
2
+ import { Position } from '@os-design/use-drag';
3
+ import ListStore from './ListStore';
4
+ declare const useTargetList: (position: Position | null, listStoreRef: RefObject<ListStore>) => import("./NodeList").default | null;
5
+ export default useTargetList;
6
+ //# sourceMappingURL=useTargetList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTargetList.d.ts","sourceRoot":"","sources":["../../../src/utils/useTargetList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC,QAAA,MAAM,aAAa,aACP,QAAQ,GAAG,IAAI,gBACX,UAAU,SAAS,CAAC,wCAoBnC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ interface UseTransitionStyleProps {
2
+ className: string;
3
+ ms: number;
4
+ enabled: boolean;
5
+ }
6
+ declare const useTransitionStyle: (props: UseTransitionStyleProps) => void;
7
+ export default useTransitionStyle;
8
+ //# sourceMappingURL=useTransitionStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTransitionStyle.d.ts","sourceRoot":"","sources":["../../../src/utils/useTransitionStyle.ts"],"names":[],"mappings":"AAEA,UAAU,uBAAuB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;CAClB;AAKD,QAAA,MAAM,kBAAkB,UAAW,uBAAuB,SAYzD,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@os-design/drag-sort",
3
+ "version": "1.0.0",
4
+ "license": "UNLICENSED",
5
+ "repository": "git@gitlab.com:os-team/libs/os-design.git",
6
+ "main": "dist/cjs/index.js",
7
+ "module": "dist/esm/index.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "require": "./dist/cjs/index.js",
12
+ "default": "./dist/esm/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "sideEffects": false,
19
+ "scripts": {
20
+ "clean": "rimraf dist",
21
+ "build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx --out-dir dist/esm --source-maps",
22
+ "build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx --out-dir dist/cjs --source-maps",
23
+ "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
24
+ "build": "yarn clean && npm-run-all build:*",
25
+ "ncu": "ncu -u"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "dependencies": {
31
+ "@os-design/portal": "^1.0.0",
32
+ "@os-design/use-auto-scroll": "^1.0.0",
33
+ "@os-design/use-drag": "^1.0.0",
34
+ "@os-design/use-event": "^1.0.5",
35
+ "@os-design/use-memo-object": "^1.0.0",
36
+ "@os-design/use-prevent-default-event": "^1.0.0",
37
+ "@os-design/use-throttle": "^1.0.5"
38
+ },
39
+ "devDependencies": {
40
+ "@os-design/omit-emotion-props": "^1.0.2",
41
+ "@os-design/use-size": "^1.0.5",
42
+ "react-window": "^1.8.6"
43
+ },
44
+ "peerDependencies": {
45
+ "react": ">=17",
46
+ "react-dom": ">=17"
47
+ },
48
+ "gitHead": "4f41a962d4c0afb57d65e8c3e104215794d3c6a7"
49
+ }