@mapples/dnd 1.0.1

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 (70) hide show
  1. package/README.md +390 -0
  2. package/dist/components/DnDRootView.d.ts +13 -0
  3. package/dist/components/DnDRootView.d.ts.map +1 -0
  4. package/dist/components/DnDRootView.js +98 -0
  5. package/dist/components/DnDRootView.js.map +1 -0
  6. package/dist/components/DropArea.d.ts +13 -0
  7. package/dist/components/DropArea.d.ts.map +1 -0
  8. package/dist/components/DropArea.js +16 -0
  9. package/dist/components/DropArea.js.map +1 -0
  10. package/dist/components/index.d.ts +3 -0
  11. package/dist/components/index.d.ts.map +1 -0
  12. package/dist/components/index.js +3 -0
  13. package/dist/components/index.js.map +1 -0
  14. package/dist/constants/index.d.ts +15 -0
  15. package/dist/constants/index.d.ts.map +1 -0
  16. package/dist/constants/index.js +16 -0
  17. package/dist/constants/index.js.map +1 -0
  18. package/dist/context/DnDContext.d.ts +14 -0
  19. package/dist/context/DnDContext.d.ts.map +1 -0
  20. package/dist/context/DnDContext.js +22 -0
  21. package/dist/context/DnDContext.js.map +1 -0
  22. package/dist/context/DropContext.d.ts +17 -0
  23. package/dist/context/DropContext.d.ts.map +1 -0
  24. package/dist/context/DropContext.js +16 -0
  25. package/dist/context/DropContext.js.map +1 -0
  26. package/dist/context/index.d.ts +5 -0
  27. package/dist/context/index.d.ts.map +1 -0
  28. package/dist/context/index.js +5 -0
  29. package/dist/context/index.js.map +1 -0
  30. package/dist/hooks/index.d.ts +5 -0
  31. package/dist/hooks/index.d.ts.map +1 -0
  32. package/dist/hooks/index.js +5 -0
  33. package/dist/hooks/index.js.map +1 -0
  34. package/dist/hooks/useDnD.d.ts +13 -0
  35. package/dist/hooks/useDnD.d.ts.map +1 -0
  36. package/dist/hooks/useDnD.js +16 -0
  37. package/dist/hooks/useDnD.js.map +1 -0
  38. package/dist/hooks/useDrag.d.ts +24 -0
  39. package/dist/hooks/useDrag.d.ts.map +1 -0
  40. package/dist/hooks/useDrag.js +74 -0
  41. package/dist/hooks/useDrag.js.map +1 -0
  42. package/dist/hooks/useDrop.d.ts +31 -0
  43. package/dist/hooks/useDrop.d.ts.map +1 -0
  44. package/dist/hooks/useDrop.js +108 -0
  45. package/dist/hooks/useDrop.js.map +1 -0
  46. package/dist/hooks/useDropContext.d.ts +12 -0
  47. package/dist/hooks/useDropContext.d.ts.map +1 -0
  48. package/dist/hooks/useDropContext.js +14 -0
  49. package/dist/hooks/useDropContext.js.map +1 -0
  50. package/dist/index.d.ts +5 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +5 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/monitor/Monitor.d.ts +223 -0
  55. package/dist/monitor/Monitor.d.ts.map +1 -0
  56. package/dist/monitor/Monitor.js +573 -0
  57. package/dist/monitor/Monitor.js.map +1 -0
  58. package/dist/monitor/index.d.ts +3 -0
  59. package/dist/monitor/index.d.ts.map +1 -0
  60. package/dist/monitor/index.js +3 -0
  61. package/dist/monitor/index.js.map +1 -0
  62. package/dist/types/index.d.ts +208 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/index.js +33 -0
  65. package/dist/types/index.js.map +1 -0
  66. package/dist/utils/index.d.ts +11 -0
  67. package/dist/utils/index.d.ts.map +1 -0
  68. package/dist/utils/index.js +13 -0
  69. package/dist/utils/index.js.map +1 -0
  70. package/package.json +62 -0
@@ -0,0 +1,16 @@
1
+ import { createContext } from 'react';
2
+ /**
3
+ * React context for drop area hierarchy.
4
+ * Provides access to the parent drop target ID for establishing parent-child relationships.
5
+ * @public
6
+ */
7
+ const DropContext = createContext({
8
+ parent: null,
9
+ });
10
+ /**
11
+ * Provider component for the drop context.
12
+ * @public
13
+ */
14
+ export const DropContextProvider = DropContext.Provider;
15
+ export default DropContext;
16
+ //# sourceMappingURL=DropContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DropContext.js","sourceRoot":"","sources":["../../src/context/DropContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC;;;;GAIG;AACH,MAAM,WAAW,GAAG,aAAa,CAA4B;IAC3D,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,QAAQ,CAAC;AAExD,eAAe,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { default as DnDContext } from './DnDContext';
2
+ export * from './DnDContext';
3
+ export { default as DropContext } from './DropContext';
4
+ export * from './DropContext';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,cAAc,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { default as DnDContext } from './DnDContext';
2
+ export * from './DnDContext';
3
+ export { default as DropContext } from './DropContext';
4
+ export * from './DropContext';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,cAAc,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { default as useDnD } from './useDnD';
2
+ export { default as useDrag } from './useDrag';
3
+ export { default as useDrop } from './useDrop';
4
+ export { default as useDropContext } from './useDropContext';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { default as useDnD } from './useDnD';
2
+ export { default as useDrag } from './useDrag';
3
+ export { default as useDrop } from './useDrop';
4
+ export { default as useDropContext } from './useDropContext';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { DnDContextType } from '../types';
2
+ /**
3
+ * Hook to access the drag and drop context.
4
+ * This hook provides access to the monitor, drag state, and shared values.
5
+ *
6
+ * @template DragData - The type of data being dragged
7
+ * @template DropData - The type of data for drop targets (defaults to DragData)
8
+ * @returns The drag and drop context with monitor and state
9
+ * @public
10
+ */
11
+ declare const useDnD: <DragData extends object, DropData extends object = DragData>() => DnDContextType<DragData, DropData>;
12
+ export default useDnD;
13
+ //# sourceMappingURL=useDnD.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDnD.d.ts","sourceRoot":"","sources":["../../src/hooks/useDnD.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;;GAQG;AACH,QAAA,MAAM,MAAM,GACV,QAAQ,SAAS,MAAM,EACvB,QAAQ,SAAS,MAAM,GAAG,QAAQ,OAED,cAAc,CAAC,QAAQ,EAAE,QAAQ,CACnE,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { useContext } from 'react';
2
+ import { DnDContext } from '../context';
3
+ /**
4
+ * Hook to access the drag and drop context.
5
+ * This hook provides access to the monitor, drag state, and shared values.
6
+ *
7
+ * @template DragData - The type of data being dragged
8
+ * @template DropData - The type of data for drop targets (defaults to DragData)
9
+ * @returns The drag and drop context with monitor and state
10
+ * @public
11
+ */
12
+ const useDnD = () => {
13
+ return useContext(DnDContext);
14
+ };
15
+ export default useDnD;
16
+ //# sourceMappingURL=useDnD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDnD.js","sourceRoot":"","sources":["../../src/hooks/useDnD.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;;;;;GAQG;AACH,MAAM,MAAM,GAAG,GAGX,EAAE;IACJ,OAAO,UAAU,CAAC,UAAU,CAAuC,CAAC;AACtE,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { RefObject } from 'react';
2
+ import { View } from 'react-native';
3
+ import { DragItem } from '../types';
4
+ /**
5
+ * Hook that makes a view draggable within the drag and drop system.
6
+ * This hook registers the view as a drag source and tracks its drag state.
7
+ *
8
+ * @template DragData - The type of data being dragged
9
+ * @template DropData - The type of data for drop targets (defaults to DragData)
10
+ * @param ref - Reference to the view element that should be draggable
11
+ * @param item - The drag item configuration with data and metadata
12
+ * @returns Object containing drag state and utilities
13
+ * @public
14
+ */
15
+ declare const useDrag: <DragData extends object, DropData extends object = DragData>(ref: RefObject<View | null>, item: DragItem<DragData>) => {
16
+ /** The unique ID of the drag element */
17
+ id: number | null;
18
+ /** Function to update the element's layout information */
19
+ updateLayout: () => void;
20
+ /** Whether this element is currently being dragged */
21
+ isDragging: boolean;
22
+ };
23
+ export default useDrag;
24
+ //# sourceMappingURL=useDrag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDrag.d.ts","sourceRoot":"","sources":["../../src/hooks/useDrag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+B,MAAM,OAAO,CAAC;AAE/D,OAAO,EAAmB,IAAI,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAAgB,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIlD;;;;;;;;;;GAUG;AACH,QAAA,MAAM,OAAO,GAAI,QAAQ,SAAS,MAAM,EAAE,QAAQ,SAAS,MAAM,GAAG,QAAQ,EAC1E,KAAK,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,EAC3B,MAAM,QAAQ,CAAC,QAAQ,CAAC;IAgEtB,wCAAwC;;IAExC,0DAA0D;;IAE1D,sDAAsD;;CAGzD,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { filter } from 'rxjs';
3
+ import { DnDEventType } from '../types';
4
+ import useDnD from './useDnD';
5
+ /**
6
+ * Hook that makes a view draggable within the drag and drop system.
7
+ * This hook registers the view as a drag source and tracks its drag state.
8
+ *
9
+ * @template DragData - The type of data being dragged
10
+ * @template DropData - The type of data for drop targets (defaults to DragData)
11
+ * @param ref - Reference to the view element that should be draggable
12
+ * @param item - The drag item configuration with data and metadata
13
+ * @returns Object containing drag state and utilities
14
+ * @public
15
+ */
16
+ const useDrag = (ref, item) => {
17
+ const { monitor } = useDnD();
18
+ const [isDragging, setIsDragging] = useState(false);
19
+ const idRef = useRef(null);
20
+ const layoutRef = useRef(null);
21
+ useEffect(() => {
22
+ ref.current?.measureInWindow?.((x, y, width, height) => {
23
+ layoutRef.current = { x, y, width, height };
24
+ if (idRef.current) {
25
+ monitor.updateDragElement(idRef.current, layoutRef.current, item);
26
+ return;
27
+ }
28
+ idRef.current = monitor.registerDragElement(layoutRef.current, item);
29
+ });
30
+ }, [item, monitor, ref]);
31
+ useEffect(() => {
32
+ return () => {
33
+ if (!idRef.current)
34
+ return;
35
+ monitor.unregisterDragElement(idRef.current);
36
+ };
37
+ }, [monitor]);
38
+ /**
39
+ * Updates the layout information for the drag element.
40
+ * This function should be called when the element's position or size changes.
41
+ */
42
+ const updateLayout = useRef(() => {
43
+ ref.current?.measureInWindow?.((x, y, width, height) => {
44
+ layoutRef.current = { x, y, width, height };
45
+ });
46
+ if (!idRef.current || !layoutRef.current)
47
+ return;
48
+ monitor.updateDragElementLayout(idRef.current, layoutRef.current);
49
+ }).current;
50
+ useEffect(() => {
51
+ const events = monitor.events
52
+ .pipe(filter((e) => e.type === DnDEventType.DragStart ||
53
+ e.type === DnDEventType.DragEnd))
54
+ .subscribe((e) => {
55
+ if (e.type === DnDEventType.DragStart) {
56
+ setIsDragging(e.target === idRef.current);
57
+ }
58
+ else {
59
+ setIsDragging(false);
60
+ }
61
+ });
62
+ return () => events.unsubscribe();
63
+ }, [monitor.events]);
64
+ return {
65
+ /** The unique ID of the drag element */
66
+ id: idRef.current,
67
+ /** Function to update the element's layout information */
68
+ updateLayout,
69
+ /** Whether this element is currently being dragged */
70
+ isDragging,
71
+ };
72
+ };
73
+ export default useDrag;
74
+ //# sourceMappingURL=useDrag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDrag.js","sourceRoot":"","sources":["../../src/hooks/useDrag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG/D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,YAAY,EAAY,MAAM,UAAU,CAAC;AAElD,OAAO,MAAM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 -0,0 +1,31 @@
1
+ import { RefObject } from 'react';
2
+ import { View } from 'react-native';
3
+ import { DropTarget, DropTargetConfig } from '../types';
4
+ /**
5
+ * Hook that makes a view a drop target within the drag and drop system.
6
+ * This hook registers the view as a drop target and tracks drop state.
7
+ *
8
+ * @template DragData - The type of data being dragged
9
+ * @template DropData - The type of data for drop targets (defaults to DragData)
10
+ * @param ref - Reference to the view element that should be a drop target
11
+ * @param config - Optional configuration for the drop target behavior
12
+ * @param data - Optional data associated with this drop target
13
+ * @returns Object containing drop state and utilities
14
+ * @public
15
+ */
16
+ declare const useDrop: <DragData extends object, DropData extends object = DragData>(ref: RefObject<View | null>, config?: DropTargetConfig, data?: DropData) => {
17
+ /** The unique ID of the drop element */
18
+ id: number | null;
19
+ /** Whether a drag is currently over this drop target */
20
+ isOver: boolean;
21
+ /** The current drop target information */
22
+ dropTarget: DropTarget<DropData> | null;
23
+ /** The index position within the drop target */
24
+ dropTargetIndex: number | null;
25
+ /** Whether any drag operation is currently active */
26
+ isDragging: boolean;
27
+ /** Function to update the element's layout information */
28
+ updateLayout: () => void;
29
+ };
30
+ export default useDrop;
31
+ //# sourceMappingURL=useDrop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDrop.d.ts","sourceRoot":"","sources":["../../src/hooks/useDrop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgD,MAAM,OAAO,CAAC;AAEhF,OAAO,EAAwC,IAAI,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EAAgB,UAAU,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAMtE;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,OAAO,GAAI,QAAQ,SAAS,MAAM,EAAE,QAAQ,SAAS,MAAM,GAAG,QAAQ,EAC1E,KAAK,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,EAC3B,SAAS,gBAAgB,EACzB,OAAO,QAAQ;IAqGb,wCAAwC;;IAExC,wDAAwD;;IAExD,0CAA0C;;IAE1C,gDAAgD;;IAEhD,qDAAqD;;IAErD,0DAA0D;;CAG7D,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,108 @@
1
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import { useWindowDimensions } from 'react-native';
3
+ import { filter } from 'rxjs';
4
+ import { DnDEventType } from '../types';
5
+ import { filterEvents } from '../utils';
6
+ import useDnD from './useDnD';
7
+ import useDropContext from './useDropContext';
8
+ /**
9
+ * Hook that makes a view a drop target within the drag and drop system.
10
+ * This hook registers the view as a drop target and tracks drop state.
11
+ *
12
+ * @template DragData - The type of data being dragged
13
+ * @template DropData - The type of data for drop targets (defaults to DragData)
14
+ * @param ref - Reference to the view element that should be a drop target
15
+ * @param config - Optional configuration for the drop target behavior
16
+ * @param data - Optional data associated with this drop target
17
+ * @returns Object containing drop state and utilities
18
+ * @public
19
+ */
20
+ const useDrop = (ref, config, data) => {
21
+ const [dropTarget, setDropTarget] = useState(null);
22
+ const { monitor, isDragging } = useDnD();
23
+ const { parent } = useDropContext();
24
+ const { width, height } = useWindowDimensions();
25
+ const [id, setId] = useState(null);
26
+ const [isOver, setIsOver] = useState(false);
27
+ const [dropTargetIndex, setDropTargetIndex] = useState(null);
28
+ const idRef = useRef(null);
29
+ const layoutRef = useRef(null);
30
+ useLayoutEffect(() => {
31
+ ref.current?.measureInWindow?.((x, y, width, height) => {
32
+ layoutRef.current = { x, y, width, height };
33
+ if (idRef.current) {
34
+ monitor.updateDropElement(idRef.current, layoutRef.current, config, data);
35
+ return;
36
+ }
37
+ idRef.current = monitor.registerDropElement(layoutRef.current, parent, config, data);
38
+ setId(idRef.current);
39
+ });
40
+ }, [config, data, monitor, parent, ref]);
41
+ useEffect(() => {
42
+ return () => {
43
+ if (idRef.current) {
44
+ monitor.unregisterDropElement(idRef.current);
45
+ }
46
+ };
47
+ }, [monitor]);
48
+ useEffect(() => {
49
+ const subscription = monitor.events
50
+ .pipe(filter(filterEvents(DnDEventType.Drag, DnDEventType.DragEnd)))
51
+ .subscribe((e) => {
52
+ if (e.type === DnDEventType.DragEnd) {
53
+ setIsOver(false);
54
+ setDropTarget(null);
55
+ return;
56
+ }
57
+ setDropTarget(e.dropTarget || null);
58
+ setIsOver(e.dropTarget?.id === idRef.current);
59
+ setDropTargetIndex(e.dropTargetIndex || 0);
60
+ });
61
+ return () => {
62
+ subscription.unsubscribe();
63
+ };
64
+ }, [monitor, monitor.events]);
65
+ /**
66
+ * Updates the layout information for the drop element.
67
+ * This function should be called when the element's position or size changes.
68
+ */
69
+ const updateLayout = useRef(() => {
70
+ ref.current?.measureInWindow?.((x, y, width, height) => {
71
+ layoutRef.current = { x, y, width, height };
72
+ if (idRef.current) {
73
+ monitor.updateDropElement(idRef.current, layoutRef.current);
74
+ }
75
+ });
76
+ }).current;
77
+ useEffect(() => {
78
+ const subscription = monitor.events
79
+ .pipe(filter(filterEvents(DnDEventType.LayoutForceUpdate)))
80
+ .subscribe(() => {
81
+ updateLayout();
82
+ });
83
+ return () => {
84
+ subscription.unsubscribe();
85
+ };
86
+ }, [monitor.events, updateLayout]);
87
+ useEffect(() => {
88
+ if (width || height) {
89
+ updateLayout();
90
+ }
91
+ }, [width, height, updateLayout]);
92
+ return {
93
+ /** The unique ID of the drop element */
94
+ id,
95
+ /** Whether a drag is currently over this drop target */
96
+ isOver,
97
+ /** The current drop target information */
98
+ dropTarget,
99
+ /** The index position within the drop target */
100
+ dropTargetIndex,
101
+ /** Whether any drag operation is currently active */
102
+ isDragging,
103
+ /** Function to update the element's layout information */
104
+ updateLayout,
105
+ };
106
+ };
107
+ export default useDrop;
108
+ //# sourceMappingURL=useDrop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDrop.js","sourceRoot":"","sources":["../../src/hooks/useDrop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhF,OAAO,EAA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;IAElC,OAAO;QACL,wCAAwC;QACxC,EAAE;QACF,wDAAwD;QACxD,MAAM;QACN,0CAA0C;QAC1C,UAAU;QACV,gDAAgD;QAChD,eAAe;QACf,qDAAqD;QACrD,UAAU;QACV,0DAA0D;QAC1D,YAAY;KACb,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Hook to access the drop context.
3
+ * This hook provides access to the parent drop target ID for establishing hierarchy.
4
+ *
5
+ * @returns The drop context with parent information
6
+ * @public
7
+ */
8
+ declare const useDropContext: () => {
9
+ parent: number | null;
10
+ };
11
+ export default useDropContext;
12
+ //# sourceMappingURL=useDropContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDropContext.d.ts","sourceRoot":"","sources":["../../src/hooks/useDropContext.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,QAAA,MAAM,cAAc;;CAEnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { useContext } from 'react';
2
+ import { DropContext } from '../context';
3
+ /**
4
+ * Hook to access the drop context.
5
+ * This hook provides access to the parent drop target ID for establishing hierarchy.
6
+ *
7
+ * @returns The drop context with parent information
8
+ * @public
9
+ */
10
+ const useDropContext = () => {
11
+ return useContext(DropContext);
12
+ };
13
+ export default useDropContext;
14
+ //# sourceMappingURL=useDropContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDropContext.js","sourceRoot":"","sources":["../../src/hooks/useDropContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,OAAO,UAAU,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './components';
2
+ export * from './hooks';
3
+ export * from './types';
4
+ export * from './utils';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './components';
2
+ export * from './hooks';
3
+ export * from './types';
4
+ export * from './utils';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,223 @@
1
+ import { LayoutRectangle } from 'react-native';
2
+ import { Subject } from 'rxjs';
3
+ import { DnDEvent, DragCoords, DragElementTarget, DragItem, DropTarget, DropTargetConfig, MonitorConfig } from '../types';
4
+ /**
5
+ * Core monitor class that manages drag and drop operations.
6
+ * This class tracks drag elements, drop targets, handles hit detection, and emits events.
7
+ *
8
+ * @template DragData - The type of data being dragged
9
+ * @template DropData - The type of data for drop targets (defaults to DragData)
10
+ * @public
11
+ */
12
+ declare class Monitor<DragData extends object, DropData extends object = DragData> {
13
+ /** Observable stream of drag and drop events */
14
+ events: Subject<DnDEvent<DragData, DropData>>;
15
+ /** Padding around drop targets for hit detection */
16
+ private readonly padding;
17
+ /** Counter for generating unique drag element IDs */
18
+ private dragElementIds;
19
+ /** Counter for generating unique drop element IDs */
20
+ private dropElementIds;
21
+ /** Map of registered drag elements by ID */
22
+ private dragElements;
23
+ /** Tree structure of registered drop elements */
24
+ private dropElementsTree;
25
+ /** ID of the currently active drag target */
26
+ private dragTargetId;
27
+ /** Currently active drop target */
28
+ private dropTarget;
29
+ /** Index position within the current drop target */
30
+ private dropTargetIndex;
31
+ /** Whether to track drag operations outside the root element */
32
+ private trackOutside;
33
+ /**
34
+ * Creates a new Monitor instance.
35
+ * @param config - Configuration options for the monitor
36
+ */
37
+ constructor(config: MonitorConfig);
38
+ /**
39
+ * Gets the ID of the currently active drag target.
40
+ * @returns The drag target ID or null if no drag is active
41
+ */
42
+ getDragTargetId(): number | null;
43
+ /**
44
+ * Sets the ID of the currently active drag target.
45
+ * @param id - The drag target ID or null
46
+ */
47
+ private setDragTargetId;
48
+ /**
49
+ * Triggers a force layout update event.
50
+ * This causes all registered elements to recalculate their layout information.
51
+ */
52
+ triggerForceLayoutUpdate(): void;
53
+ /**
54
+ * Gets the currently active drop target.
55
+ * @returns The drop target or null if no drop target is active
56
+ */
57
+ getDropTarget(): DropTarget<DropData> | null;
58
+ /**
59
+ * Sets the currently active drop target.
60
+ * @param target - The drop target or null
61
+ */
62
+ setDropTarget(target: DropTarget<DropData> | null): void;
63
+ /**
64
+ * Gets the drag target data for a specific ID.
65
+ * @param id - The drag target ID
66
+ * @returns The drag element target data or undefined if not found
67
+ */
68
+ getDragTargetData(id: number): DragElementTarget<DragData> | undefined;
69
+ /**
70
+ * Sets the index position within the current drop target.
71
+ * @param index - The index position or null
72
+ */
73
+ setDropTargetIndex(index: number | null): void;
74
+ /**
75
+ * Gets the index position within the current drop target.
76
+ * @returns The index position or null if no drop target is active
77
+ */
78
+ getDropTargetIndex(): number | null;
79
+ /**
80
+ * Registers a new drag element with the monitor.
81
+ * @param layout - The layout rectangle of the drag element
82
+ * @param item - The drag item configuration
83
+ * @returns The unique ID assigned to the drag element
84
+ */
85
+ registerDragElement(layout: LayoutRectangle, item: DragItem<DragData>): number;
86
+ /**
87
+ * Unregisters a drag element from the monitor.
88
+ * @param id - The ID of the drag element to unregister
89
+ */
90
+ unregisterDragElement(id: number): void;
91
+ /**
92
+ * Updates the layout and item data for a registered drag element.
93
+ * @param id - The ID of the drag element
94
+ * @param layout - The new layout rectangle
95
+ * @param item - The new drag item configuration
96
+ */
97
+ updateDragElement(id: number, layout: LayoutRectangle, item: DragItem<DragData>): void;
98
+ /**
99
+ * Updates only the layout information for a registered drag element.
100
+ * @param id - The ID of the drag element
101
+ * @param layout - The new layout rectangle
102
+ */
103
+ updateDragElementLayout(id: number, layout: LayoutRectangle): void;
104
+ /**
105
+ * Handles the start of a drag operation.
106
+ * @param dragCoords - The coordinates where the drag started
107
+ */
108
+ onDragStart(dragCoords: DragCoords): void;
109
+ /**
110
+ * Handles drag movement during a drag operation.
111
+ * @param dragCoords - The current coordinates of the drag
112
+ */
113
+ onDrag(dragCoords: DragCoords): void;
114
+ /**
115
+ * Handles selection/tap events.
116
+ * @param dragCoords - The coordinates where the selection occurred
117
+ */
118
+ onSelect(dragCoords: DragCoords): void;
119
+ /**
120
+ * Checks if the given coordinates are inside the first root element.
121
+ * @param dragCoords - The coordinates to check
122
+ * @returns True if inside the first root element
123
+ * @private
124
+ */
125
+ private isInsideFirstRootElement;
126
+ /**
127
+ * Handles external selection by data query.
128
+ * @param dataQuery - Partial data to match against drop targets
129
+ */
130
+ onExternalSelect(dataQuery: Partial<DropData>): void;
131
+ /**
132
+ * Handles the end of a drag operation.
133
+ */
134
+ onDragEnd(): void;
135
+ /**
136
+ * Registers a new drop element with the monitor.
137
+ * @param layout - The layout rectangle of the drop element
138
+ * @param parent - The ID of the parent drop element, or null for root level
139
+ * @param config - Optional configuration for the drop target
140
+ * @param data - Optional data associated with the drop target
141
+ * @returns The unique ID assigned to the drop element
142
+ */
143
+ registerDropElement(layout: LayoutRectangle, parent: number | null, config?: DropTargetConfig, data?: DropData): number;
144
+ /**
145
+ * Unregisters a drop element from the monitor.
146
+ * @param id - The ID of the drop element to unregister
147
+ */
148
+ unregisterDropElement(id: number): void;
149
+ /**
150
+ * Updates the layout and configuration for a registered drop element.
151
+ * @param id - The ID of the drop element
152
+ * @param layout - The new layout rectangle
153
+ * @param config - Optional new configuration
154
+ * @param data - Optional new data
155
+ */
156
+ updateDropElement(id: number, layout: LayoutRectangle, config?: DropTargetConfig, data?: DropData): void;
157
+ /**
158
+ * Finds a drop target by ID in the tree structure.
159
+ * @param id - The ID to search for
160
+ * @param tree - The tree to search in
161
+ * @returns The drop item or null if not found
162
+ * @private
163
+ */
164
+ private findDropTarget;
165
+ /**
166
+ * Finds a drop target by matching data properties.
167
+ * @param dataQuery - Partial data to match against
168
+ * @param tree - The tree to search in
169
+ * @returns The drop target or null if not found
170
+ * @private
171
+ */
172
+ private findDropTargetByData;
173
+ /**
174
+ * Performs a partial match between target data and query data.
175
+ * @param targetData - The target data to match against
176
+ * @param query - The query data to match
177
+ * @returns True if the query matches the target data
178
+ * @private
179
+ */
180
+ private partialMatch;
181
+ /**
182
+ * Finds the parent of a drop target by ID.
183
+ * @param id - The ID of the child drop target
184
+ * @param tree - The tree to search in
185
+ * @returns The parent drop item or null if not found
186
+ * @private
187
+ */
188
+ private findDropTargetParent;
189
+ /**
190
+ * Gets all drop targets that contain the given coordinates.
191
+ * @param dropCoords - The coordinates to check
192
+ * @param tree - The tree to search in
193
+ * @returns Array of drop targets or null if none found
194
+ * @private
195
+ */
196
+ private getDropTargets;
197
+ /**
198
+ * Gets the shallowest (topmost) drop target from a list of targets.
199
+ * @param targets - Array of drop targets
200
+ * @param dragCoords - The current drag coordinates
201
+ * @returns The shallowest drop target or null
202
+ * @private
203
+ */
204
+ private getShallowTarget;
205
+ /**
206
+ * Calculates the drop target index based on drag coordinates and target layout.
207
+ * @param dragCoords - The current drag coordinates
208
+ * @param target - The drop target to calculate index for
209
+ * @returns The calculated index or null
210
+ * @private
211
+ */
212
+ private getDropTargetIndexData;
213
+ /**
214
+ * Gets the drag target ID for the given coordinates.
215
+ * @param dragCoords - The coordinates to check
216
+ * @returns The drag target ID or null if none found
217
+ * @private
218
+ */
219
+ private getDragTarget;
220
+ }
221
+ export { Monitor };
222
+ export default Monitor;
223
+ //# sourceMappingURL=Monitor.d.ts.map