@mk-drag-and-drop/dom 0.1.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/LICENSE +21 -0
- package/README.md +460 -0
- package/dist/controller/controller-internals.d.ts +5 -0
- package/dist/controller/controller-internals.js +11 -0
- package/dist/controller/create-drag-controller.d.ts +36 -0
- package/dist/controller/create-drag-controller.js +232 -0
- package/dist/draggable/create-draggable-binding.d.ts +8 -0
- package/dist/draggable/create-draggable-binding.js +52 -0
- package/dist/draggable/create-draggable.d.ts +46 -0
- package/dist/draggable/create-draggable.js +57 -0
- package/dist/droppable/create-drop-container-binding.d.ts +8 -0
- package/dist/droppable/create-drop-container-binding.js +28 -0
- package/dist/droppable/create-drop-container.d.ts +18 -0
- package/dist/droppable/create-drop-container.js +36 -0
- package/dist/droppable/create-droppable-binding.d.ts +9 -0
- package/dist/droppable/create-droppable-binding.js +29 -0
- package/dist/droppable/create-droppable.d.ts +17 -0
- package/dist/droppable/create-droppable.js +31 -0
- package/dist/geometry/measurement.d.ts +4 -0
- package/dist/geometry/measurement.js +33 -0
- package/dist/geometry/overlay.d.ts +19 -0
- package/dist/geometry/overlay.js +32 -0
- package/dist/geometry/rects.d.ts +17 -0
- package/dist/geometry/rects.js +34 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +9 -0
- package/dist/input/config.d.ts +35 -0
- package/dist/input/config.js +56 -0
- package/dist/input/create-drag-handle.d.ts +4 -0
- package/dist/input/create-drag-handle.js +4 -0
- package/dist/input/drag-handle.d.ts +10 -0
- package/dist/input/drag-handle.js +74 -0
- package/dist/input/keyboard-drag.d.ts +28 -0
- package/dist/input/keyboard-drag.js +77 -0
- package/dist/input/pointer-activation.d.ts +31 -0
- package/dist/input/pointer-activation.js +97 -0
- package/dist/integration/index.d.ts +10 -0
- package/dist/integration/index.js +6 -0
- package/dist/modifiers/built-ins.d.ts +6 -0
- package/dist/modifiers/built-ins.js +62 -0
- package/dist/modifiers/pipeline.d.ts +18 -0
- package/dist/modifiers/pipeline.js +34 -0
- package/dist/modifiers/types.d.ts +32 -0
- package/dist/modifiers/types.js +1 -0
- package/dist/runtime/drag-runtime-handle.d.ts +22 -0
- package/dist/runtime/drag-runtime-handle.js +33 -0
- package/dist/runtime/drag-runtime.d.ts +96 -0
- package/dist/runtime/drag-runtime.js +798 -0
- package/dist/runtime/drop-target-registry.d.ts +101 -0
- package/dist/runtime/drop-target-registry.js +855 -0
- package/dist/runtime/lifecycle.d.ts +44 -0
- package/dist/runtime/lifecycle.js +1 -0
- package/dist/runtime/types.d.ts +65 -0
- package/dist/runtime/types.js +1 -0
- package/dist/sortable/create-sortable-binding.d.ts +10 -0
- package/dist/sortable/create-sortable-binding.js +58 -0
- package/dist/sortable/create-sortable.d.ts +19 -0
- package/dist/sortable/create-sortable.js +55 -0
- package/dist/sortable/sortable-options.d.ts +17 -0
- package/dist/sortable/sortable-options.js +20 -0
- package/dist/sortable/sortable-preview.d.ts +79 -0
- package/dist/sortable/sortable-preview.js +357 -0
- package/dist/sortable/sortable-registry.d.ts +113 -0
- package/dist/sortable/sortable-registry.js +145 -0
- package/dist/targeting/algorithms.d.ts +6 -0
- package/dist/targeting/algorithms.js +56 -0
- package/dist/targeting/constraints.d.ts +15 -0
- package/dist/targeting/constraints.js +58 -0
- package/dist/targeting/types.d.ts +23 -0
- package/dist/targeting/types.js +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function maxPointerDistanceToRect(options) {
|
|
2
|
+
return ({ pointerPosition, dropTarget }) => isPointWithinMaxDistanceToRect({
|
|
3
|
+
point: pointerPosition,
|
|
4
|
+
rect: dropTarget.dropTargetRect,
|
|
5
|
+
options,
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export function maxOverlayCenterDistanceToRect(options) {
|
|
9
|
+
return ({ overlayRect, dropTarget }) => {
|
|
10
|
+
if (!overlayRect) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return isPointWithinMaxDistanceToRect({
|
|
14
|
+
point: getRectCenter(overlayRect),
|
|
15
|
+
rect: dropTarget.dropTargetRect,
|
|
16
|
+
options,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function isPointWithinMaxDistanceToRect(input) {
|
|
21
|
+
const x = getAxisDistance(input.point.x, input.rect.left, input.rect.right);
|
|
22
|
+
const y = getAxisDistance(input.point.y, input.rect.top, input.rect.bottom);
|
|
23
|
+
if (input.options.maxXDistance !== undefined && x > input.options.maxXDistance) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (input.options.maxYDistance !== undefined && y > input.options.maxYDistance) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (input.options.maxDistance !== undefined &&
|
|
30
|
+
x * x + y * y > input.options.maxDistance * input.options.maxDistance) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
export function getDistanceToRect(point, rect) {
|
|
36
|
+
const x = getAxisDistance(point.x, rect.left, rect.right);
|
|
37
|
+
const y = getAxisDistance(point.y, rect.top, rect.bottom);
|
|
38
|
+
return {
|
|
39
|
+
x,
|
|
40
|
+
y,
|
|
41
|
+
distance: Math.sqrt(x * x + y * y),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function getAxisDistance(value, min, max) {
|
|
45
|
+
if (value < min) {
|
|
46
|
+
return min - value;
|
|
47
|
+
}
|
|
48
|
+
if (value > max) {
|
|
49
|
+
return value - max;
|
|
50
|
+
}
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
function getRectCenter(rect) {
|
|
54
|
+
return {
|
|
55
|
+
x: rect.left + rect.width / 2,
|
|
56
|
+
y: rect.top + rect.height / 2,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DragPoint, DragRect } from "../geometry/rects.js";
|
|
2
|
+
export type DropTarget = {
|
|
3
|
+
dropTargetId: string;
|
|
4
|
+
dropTargetRect: DragRect;
|
|
5
|
+
};
|
|
6
|
+
export type TargetingAlgorithmInput = {
|
|
7
|
+
pointerPosition: DragPoint;
|
|
8
|
+
overlayRect: DragRect | null;
|
|
9
|
+
dropTargets: readonly DropTarget[];
|
|
10
|
+
};
|
|
11
|
+
export type TargetingAlgorithmMode = "pointer" | "rect";
|
|
12
|
+
export type TargetingAlgorithm = {
|
|
13
|
+
(input: TargetingAlgorithmInput): DropTarget | null;
|
|
14
|
+
mode: TargetingAlgorithmMode;
|
|
15
|
+
};
|
|
16
|
+
export type TargetingConstraintInput = {
|
|
17
|
+
pointerPosition: DragPoint;
|
|
18
|
+
overlayRect: DragRect | null;
|
|
19
|
+
dropTarget: DropTarget;
|
|
20
|
+
};
|
|
21
|
+
export type TargetingConstraint = {
|
|
22
|
+
(input: TargetingConstraintInput): boolean;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mk-drag-and-drop/dom",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Headless DOM drag-and-drop primitives for draggable, droppable, sortable, and grouped interactions.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://mkramer.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mkramerdev/mk-drag-and-drop.git",
|
|
10
|
+
"directory": "packages/mk-drag-and-drop/dom"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/mkramerdev/mk-drag-and-drop/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"drag-and-drop",
|
|
17
|
+
"dnd",
|
|
18
|
+
"sortable",
|
|
19
|
+
"dom",
|
|
20
|
+
"headless",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./integration": {
|
|
36
|
+
"types": "./dist/integration/index.d.ts",
|
|
37
|
+
"import": "./dist/integration/index.js",
|
|
38
|
+
"default": "./dist/integration/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"eslint": "^8.57.0",
|
|
46
|
+
"jsdom": "^24.1.3",
|
|
47
|
+
"typescript": "5.5.4",
|
|
48
|
+
"vitest": "^2.1.9",
|
|
49
|
+
"@repo/eslint-config": "0.0.0",
|
|
50
|
+
"@repo/typescript-config": "0.0.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
54
|
+
"build": "pnpm run clean && tsc -p tsconfig.json",
|
|
55
|
+
"dev": "tsc -p tsconfig.json --watch --preserveWatchOutput",
|
|
56
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:watch": "vitest"
|
|
59
|
+
}
|
|
60
|
+
}
|