snap-dnd 0.1.3 → 0.2.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.
- package/README.md +105 -0
- package/dist/behaviors/AutoScroll.d.ts +20 -0
- package/dist/behaviors/ConstraintAxis.d.ts +37 -0
- package/dist/behaviors/SnapGrid.d.ts +38 -0
- package/dist/behaviors/index.d.ts +3 -0
- package/dist/core/DragEngine.d.ts +60 -0
- package/dist/core/DragState.d.ts +67 -0
- package/dist/core/DropZone.d.ts +97 -0
- package/dist/core/Snap.d.ts +85 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/index.d.ts +62 -0
- package/dist/plugins/FileDrop.d.ts +33 -0
- package/dist/plugins/Kanban.d.ts +40 -0
- package/dist/plugins/Sortable.d.ts +33 -0
- package/dist/plugins/index.d.ts +3 -0
- package/dist/sensors/FileSensor.d.ts +51 -0
- package/dist/sensors/PointerSensor.d.ts +79 -0
- package/dist/sensors/index.d.ts +2 -0
- package/dist/snap.core.js +2 -2
- package/dist/snap.core.js.map +7 -0
- package/dist/snap.esm.js +11 -11
- package/dist/snap.esm.js.map +7 -0
- package/dist/snap.umd.js +11 -11
- package/dist/snap.umd.js.map +7 -0
- package/dist/types/index.d.ts +161 -0
- package/dist/utils/BoundsCache.d.ts +54 -0
- package/dist/utils/DataTransfer.d.ts +32 -0
- package/dist/utils/EventEmitter.d.ts +37 -0
- package/dist/utils/ObjectPool.d.ts +38 -0
- package/dist/utils/RAFThrottle.d.ts +39 -0
- package/dist/utils/index.d.ts +5 -0
- package/package.json +2 -3
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom DataTransfer implementation for passing data during drag operations
|
|
3
|
+
* Not the browser's native DataTransfer
|
|
4
|
+
*/
|
|
5
|
+
import type { DataTransfer as IDataTransfer } from '../types/index.js';
|
|
6
|
+
export declare class SnapDataTransfer implements IDataTransfer {
|
|
7
|
+
private _data;
|
|
8
|
+
/**
|
|
9
|
+
* Set data for a given type
|
|
10
|
+
*/
|
|
11
|
+
setData(type: string, value: unknown): void;
|
|
12
|
+
/**
|
|
13
|
+
* Get data for a given type
|
|
14
|
+
*/
|
|
15
|
+
getData<T = unknown>(type: string): T | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a type exists
|
|
18
|
+
*/
|
|
19
|
+
hasType(type: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Get all registered types
|
|
22
|
+
*/
|
|
23
|
+
get types(): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Clear all data
|
|
26
|
+
*/
|
|
27
|
+
clear(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Create a copy of this transfer
|
|
30
|
+
*/
|
|
31
|
+
clone(): SnapDataTransfer;
|
|
32
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight pub/sub event emitter
|
|
3
|
+
* Optimized for minimal allocations
|
|
4
|
+
*/
|
|
5
|
+
import type { Unsubscribe } from '../types/index.js';
|
|
6
|
+
export type EventCallback<T = unknown> = (data: T) => void;
|
|
7
|
+
export declare class EventEmitter<Events extends Record<string, unknown>> {
|
|
8
|
+
private _listeners;
|
|
9
|
+
/**
|
|
10
|
+
* Subscribe to an event
|
|
11
|
+
*/
|
|
12
|
+
on<K extends keyof Events>(event: K, callback: EventCallback<Events[K]>): Unsubscribe;
|
|
13
|
+
/**
|
|
14
|
+
* Subscribe to an event once
|
|
15
|
+
*/
|
|
16
|
+
once<K extends keyof Events>(event: K, callback: EventCallback<Events[K]>): Unsubscribe;
|
|
17
|
+
/**
|
|
18
|
+
* Emit an event to all subscribers
|
|
19
|
+
*/
|
|
20
|
+
emit<K extends keyof Events>(event: K, data: Events[K]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Remove all listeners for an event, or all listeners
|
|
23
|
+
*/
|
|
24
|
+
off<K extends keyof Events>(event?: K): void;
|
|
25
|
+
/**
|
|
26
|
+
* Check if there are any listeners for an event
|
|
27
|
+
*/
|
|
28
|
+
hasListeners<K extends keyof Events>(event: K): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Get the number of listeners for an event
|
|
31
|
+
*/
|
|
32
|
+
listenerCount<K extends keyof Events>(event: K): number;
|
|
33
|
+
/**
|
|
34
|
+
* Clear all listeners
|
|
35
|
+
*/
|
|
36
|
+
destroy(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic object pool for reusing frequently allocated objects
|
|
3
|
+
* Reduces GC pressure during drag operations
|
|
4
|
+
*/
|
|
5
|
+
export declare class ObjectPool<T> {
|
|
6
|
+
private _pool;
|
|
7
|
+
private _factory;
|
|
8
|
+
private _reset;
|
|
9
|
+
private _maxSize;
|
|
10
|
+
constructor(factory: () => T, reset: (obj: T) => void, initialSize?: number, maxSize?: number);
|
|
11
|
+
/**
|
|
12
|
+
* Get an object from the pool or create a new one
|
|
13
|
+
*/
|
|
14
|
+
acquire(): T;
|
|
15
|
+
/**
|
|
16
|
+
* Return an object to the pool for reuse
|
|
17
|
+
*/
|
|
18
|
+
release(obj: T): void;
|
|
19
|
+
/**
|
|
20
|
+
* Clear all pooled objects
|
|
21
|
+
*/
|
|
22
|
+
clear(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Current pool size
|
|
25
|
+
*/
|
|
26
|
+
get size(): number;
|
|
27
|
+
}
|
|
28
|
+
import type { Point, Rect } from '../types/index.js';
|
|
29
|
+
export declare const pointPool: ObjectPool<Point>;
|
|
30
|
+
export declare const rectPool: ObjectPool<Rect>;
|
|
31
|
+
/**
|
|
32
|
+
* Helper to get a point from pool with initial values
|
|
33
|
+
*/
|
|
34
|
+
export declare function acquirePoint(x: number, y: number): Point;
|
|
35
|
+
/**
|
|
36
|
+
* Helper to get a rect from pool with initial values
|
|
37
|
+
*/
|
|
38
|
+
export declare function acquireRect(x: number, y: number, width: number, height: number): Rect;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RAF-based throttling for high-frequency events
|
|
3
|
+
* Ensures only one callback per animation frame
|
|
4
|
+
*/
|
|
5
|
+
export declare class RAFThrottle<T> {
|
|
6
|
+
private _rafId;
|
|
7
|
+
private _pending;
|
|
8
|
+
private _callback;
|
|
9
|
+
constructor(callback: (data: T) => void);
|
|
10
|
+
/**
|
|
11
|
+
* Queue data to be processed on next animation frame
|
|
12
|
+
* Only the most recent data will be processed
|
|
13
|
+
*/
|
|
14
|
+
queue(data: T): void;
|
|
15
|
+
/**
|
|
16
|
+
* Cancel any pending frame
|
|
17
|
+
*/
|
|
18
|
+
cancel(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Process immediately if there's pending data
|
|
21
|
+
*/
|
|
22
|
+
flush(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Check if there's a pending frame
|
|
25
|
+
*/
|
|
26
|
+
get isPending(): boolean;
|
|
27
|
+
private _process;
|
|
28
|
+
/**
|
|
29
|
+
* Cleanup
|
|
30
|
+
*/
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a throttled function using RAF
|
|
35
|
+
*/
|
|
36
|
+
export declare function rafThrottle<T extends (...args: unknown[]) => void>(fn: T): T & {
|
|
37
|
+
cancel: () => void;
|
|
38
|
+
flush: () => void;
|
|
39
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ObjectPool, pointPool, rectPool, acquirePoint, acquireRect } from './ObjectPool.js';
|
|
2
|
+
export { EventEmitter, type EventCallback } from './EventEmitter.js';
|
|
3
|
+
export { BoundsCache, boundsCache, pointInRect, rectsIntersect, rectCenter, distance } from './BoundsCache.js';
|
|
4
|
+
export { RAFThrottle, rafThrottle } from './RAFThrottle.js';
|
|
5
|
+
export { SnapDataTransfer } from './DataTransfer.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snap-dnd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A zero-dependency, memory-optimized drag and drop library for vanilla JS and Web Components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/snap.umd.js",
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
|
-
"dist
|
|
20
|
-
"dist/**/*.d.ts"
|
|
19
|
+
"dist"
|
|
21
20
|
],
|
|
22
21
|
"sideEffects": false,
|
|
23
22
|
"scripts": {
|