@abhishekzambare/react-grid-dnd 0.0.4 → 0.0.6

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.
@@ -0,0 +1,29 @@
1
+ import { Bounds } from './use-measure';
2
+ import { GridSettings, TraverseType } from './grid-types';
3
+ import { ReactNode } from 'react';
4
+ interface RegisterOptions extends Bounds {
5
+ /** The number of documents in each grid */
6
+ count: number;
7
+ /** grid info (boxes per row) */
8
+ grid: GridSettings;
9
+ /** whether the dropzone is disabled for dropping */
10
+ disableDrop: boolean;
11
+ remeasure: () => void;
12
+ }
13
+ interface GridContextType {
14
+ register: (id: string, options: RegisterOptions) => void;
15
+ remove: (id: string) => void;
16
+ measureAll: () => void;
17
+ getActiveDropId: (sourceId: string, x: number, y: number) => string | null;
18
+ startTraverse: (sourceId: string, targetId: string, x: number, y: number, sourceIndex: number) => void;
19
+ traverse: TraverseType | null;
20
+ endTraverse: () => void;
21
+ onChange: (sourceId: string, sourceIndex: number, targetIndex: number, targetId?: string) => void;
22
+ }
23
+ export declare const GridContext: import('react').Context<GridContextType>;
24
+ interface GridContextProviderProps {
25
+ children: ReactNode;
26
+ onChange: (sourceId: string, sourceIndex: number, targetIndex: number, targetId?: string) => void;
27
+ }
28
+ export declare function GridContextProvider({ children, onChange, }: GridContextProviderProps): import("react/jsx-runtime").JSX.Element;
29
+ export {};
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ export interface GridDropZoneProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ boxesPerRow: number;
4
+ rowHeight: number;
5
+ id: string;
6
+ children: React.ReactNode[];
7
+ disableDrag?: boolean;
8
+ disableDrop?: boolean;
9
+ style?: React.CSSProperties;
10
+ }
11
+ export declare function GridDropZone({ id, boxesPerRow, children, style, disableDrag, disableDrop, rowHeight, ...other }: GridDropZoneProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export declare function GridItem({ children, style, className, ...other }: any): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { StateType } from './gesture-responder';
2
+ import { GridSettings } from './grid-types';
3
+ import * as React from "react";
4
+ export interface GridItemContextType {
5
+ top: number;
6
+ disableDrag: boolean;
7
+ endTraverse: () => void;
8
+ mountWithTraverseTarget?: [number, number];
9
+ left: number;
10
+ i: number;
11
+ onMove: (state: StateType, x: number, y: number) => void;
12
+ onEnd: (state: StateType, x: number, y: number) => void;
13
+ onStart: () => void;
14
+ grid: GridSettings;
15
+ dragging: boolean;
16
+ }
17
+ export declare const GridItemContext: React.Context<GridItemContextType | null>;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The responder takes its inspiration from react-native's
3
+ * pan-responder. Learn more about react-native's
4
+ * system here:
5
+ *
6
+ * https://facebook.github.io/react-native/docs/gesture-responder-system.html
7
+ *
8
+ * Basic usage:
9
+ *
10
+ * const bind = useGestureResponder({
11
+ * onStartShouldSet: () => true,
12
+ * onGrant: () => highlight(),
13
+ * onMove: () => updatePosition(),
14
+ * onRelease: () => unhighlight(),
15
+ * onTerminate: () => unhighlight()
16
+ * })
17
+ *
18
+ * The main benefit this provides is the ability to reconcile
19
+ * multiple gestures, and give priority to one.
20
+ *
21
+ * You can use a combination of useStartShouldSet, useStartShouldSetCapture,
22
+ * onMoveShouldSetCapture, and onMoveShouldSet to dictate
23
+ * which gets priority.
24
+ *
25
+ * Typically you'd want to avoid capture since it's generally
26
+ * preferable to have child elements gain touch access.
27
+ */
28
+ export type ResponderEvent = TouchEvent | MouseEvent | Event;
29
+ export type CallbackQueryType = (state: StateType, e: ResponderEvent) => boolean;
30
+ export type CallbackType = (state: StateType, e: ResponderEvent) => void;
31
+ export interface Callbacks {
32
+ onStartShouldSetCapture?: CallbackQueryType;
33
+ onStartShouldSet?: CallbackQueryType;
34
+ onMoveShouldSetCapture?: CallbackQueryType;
35
+ onMoveShouldSet?: CallbackQueryType;
36
+ onGrant?: CallbackType;
37
+ onMove?: CallbackType;
38
+ onRelease?: CallbackType;
39
+ onTerminate?: (state: StateType, e?: ResponderEvent) => void;
40
+ onTerminationRequest?: (state: StateType, e?: ResponderEvent) => boolean;
41
+ }
42
+ export interface StateType {
43
+ time: number;
44
+ xy: [number, number];
45
+ delta: [number, number];
46
+ initial: [number, number];
47
+ previous: [number, number];
48
+ direction: [number, number];
49
+ initialDirection: [number, number];
50
+ local: [number, number];
51
+ lastLocal: [number, number];
52
+ velocity: number;
53
+ distance: number;
54
+ }
55
+ interface Config {
56
+ uid?: string;
57
+ enableMouse?: boolean;
58
+ }
59
+ export interface GrantedTouch {
60
+ id: string | number;
61
+ onTerminationRequest: (e?: ResponderEvent) => boolean;
62
+ onTerminate: (e?: ResponderEvent) => void;
63
+ }
64
+ export declare function useGestureResponder(options?: Callbacks, config?: Config): {
65
+ bind: {
66
+ onMouseDown: (e: MouseEvent) => void;
67
+ onMouseDownCapture: (e: MouseEvent) => void;
68
+ onTouchStart: (e: ResponderEvent) => void;
69
+ onTouchEnd: (e: ResponderEvent) => void;
70
+ onTouchMove: (e: ResponderEvent) => void;
71
+ onTouchStartCapture: (e: ResponderEvent) => void;
72
+ onTouchMoveCapture: (e: ResponderEvent) => void;
73
+ } | {
74
+ onMouseDown?: undefined;
75
+ onMouseDownCapture?: undefined;
76
+ onTouchStart: (e: ResponderEvent) => void;
77
+ onTouchEnd: (e: ResponderEvent) => void;
78
+ onTouchMove: (e: ResponderEvent) => void;
79
+ onTouchStartCapture: (e: ResponderEvent) => void;
80
+ onTouchMoveCapture: (e: ResponderEvent) => void;
81
+ };
82
+ terminateCurrentResponder: () => void;
83
+ getCurrentResponder: () => GrantedTouch | null;
84
+ };
85
+ export {};
@@ -0,0 +1,26 @@
1
+ export interface GridSettings {
2
+ boxesPerRow: number;
3
+ rowHeight: number;
4
+ columnWidth: number;
5
+ }
6
+ export type ChildRender = (component: any, props: any, state: {
7
+ dragging: boolean;
8
+ disabled: boolean;
9
+ i: number;
10
+ grid: GridSettings;
11
+ }) => React.ReactNode;
12
+ /**
13
+ * A traverse captures information about dragging a grid item
14
+ * from one list to another.
15
+ */
16
+ export interface TraverseType {
17
+ sourceId: string;
18
+ targetId: string;
19
+ rx: number;
20
+ ry: number;
21
+ tx: number;
22
+ ty: number;
23
+ sourceIndex: number;
24
+ targetIndex: number;
25
+ execute?: boolean;
26
+ }
@@ -0,0 +1,39 @@
1
+ import { GridSettings } from './grid-types';
2
+ /**
3
+ * Get the relative top, left position for a particular
4
+ * index in a grid
5
+ * @param i
6
+ * @param grid
7
+ * @param traverseIndex (destination for traverse)
8
+ */
9
+ export declare function getPositionForIndex(i: number, { boxesPerRow, rowHeight, columnWidth }: GridSettings, traverseIndex?: number | false | null): {
10
+ xy: number[];
11
+ };
12
+ /**
13
+ * Get the active drag position given its initial
14
+ * coordinates and grid meta
15
+ * @param index
16
+ * @param grid
17
+ * @param dx
18
+ * @param dy
19
+ */
20
+ export declare function getDragPosition(index: number, grid: GridSettings, dx: number, dy: number, center?: boolean): {
21
+ xy: number[];
22
+ };
23
+ /**
24
+ * Given relative coordinates, determine which index
25
+ * we are currently in
26
+ * @param x
27
+ * @param y
28
+ * @param param2
29
+ */
30
+ export declare function getIndexFromCoordinates(x: number, y: number, { rowHeight, boxesPerRow, columnWidth }: GridSettings, count: number): number;
31
+ /**
32
+ * Get the target index during a drag
33
+ * @param startIndex
34
+ * @param grid
35
+ * @param count
36
+ * @param dx
37
+ * @param dy
38
+ */
39
+ export declare function getTargetIndex(startIndex: number, grid: GridSettings, count: number, dx: number, dy: number): number;
@@ -0,0 +1,5 @@
1
+ export * from './GridContext';
2
+ export * from './GridDropZone';
3
+ export * from './move';
4
+ export * from './swap';
5
+ export * from './GridItem';
@@ -0,0 +1 @@
1
+ export declare function move<T>(source: T[], destination: T[], droppableSource: number, droppableDestination: number): T[][];
@@ -0,0 +1 @@
1
+ export declare function swap<T>(array: T[], moveIndex: number, toIndex: number): T[];
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ export interface Bounds {
3
+ left: number;
4
+ height: number;
5
+ top: number;
6
+ right: number;
7
+ bottom: number;
8
+ width: number;
9
+ }
10
+ export declare function useMeasure(ref: React.RefObject<HTMLDivElement | null>): {
11
+ bounds: Bounds;
12
+ remeasure: () => void;
13
+ };
@@ -0,0 +1,2 @@
1
+ declare function App(): import("react/jsx-runtime").JSX.Element;
2
+ export default App;
File without changes
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@abhishekzambare/react-grid-dnd",
3
3
  "description": "grid style drag and drop for react",
4
+ "version": "0.0.6",
4
5
  "author": "Abhishek Zambare",
5
6
  "license": "MIT",
6
7
  "private": false,
@@ -23,7 +24,6 @@
23
24
  "require": "./dist/react-grid-dnd.umd.cjs"
24
25
  }
25
26
  },
26
- "version": "0.0.4",
27
27
  "homepage": "https://github.com/Macintosh98/react-grid-dnd",
28
28
  "bugs": {
29
29
  "url": "https://github.com/Macintosh98/react-grid-dnd/issues"
@@ -41,12 +41,9 @@
41
41
  "dependencies": {
42
42
  "motion": "^12.38.0",
43
43
  "resize-observer-polyfill": "^1.5.1",
44
- "uuid": "^14.0.0",
45
- "vite-tsconfig-paths": "^6.1.1"
44
+ "uuid": "^14.0.0"
46
45
  },
47
46
  "devDependencies": {
48
- "react": "^19.2.5",
49
- "react-dom": "^19.2.5",
50
47
  "@babel/core": "^7.29.0",
51
48
  "@eslint/js": "^10.0.1",
52
49
  "@rolldown/plugin-babel": "^0.2.3",
@@ -60,9 +57,12 @@
60
57
  "eslint-plugin-react-hooks": "^7.1.1",
61
58
  "eslint-plugin-react-refresh": "^0.5.2",
62
59
  "globals": "^17.6.0",
60
+ "react": "^19.2.5",
61
+ "react-dom": "^19.2.5",
63
62
  "typescript": "~6.0.3",
64
63
  "typescript-eslint": "^8.59.1",
65
- "vite": "^8.0.10"
64
+ "vite": "^8.0.10",
65
+ "vite-plugin-dts": "^5.0.0"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "react": "^19",