@octanejs/dnd-kit-modifiers 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/LICENSE.upstream +21 -0
- package/README.md +44 -2
- package/UPSTREAM.md +55 -0
- package/package.json +56 -3
- package/src/createSnapModifier.ts +9 -0
- package/src/index.ts +7 -0
- package/src/restrictToFirstScrollableAncestor.ts +16 -0
- package/src/restrictToHorizontalAxis.ts +8 -0
- package/src/restrictToParentElement.ts +14 -0
- package/src/restrictToVerticalAxis.ts +8 -0
- package/src/restrictToWindowEdges.ts +11 -0
- package/src/snapCenterToCursor.ts +23 -0
- package/src/utilities/index.ts +1 -0
- package/src/utilities/restrictToBoundingRect.ts +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dominic Gannaway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/LICENSE.upstream
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021, Claudéric Demers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@octanejs/dnd-kit-modifiers`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Movement modifiers for the legacy dnd kit API on Octane: the `restrictTo*`
|
|
4
|
+
modifiers, `snapCenterToCursor`, and `createSnapModifier`, ported from
|
|
5
|
+
`@dnd-kit/modifiers` 9.0.0. Pass them to `DndContext` or `DragOverlay` from
|
|
6
|
+
`@octanejs/dnd-kit-core`.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @octanejs/dnd-kit-modifiers @octanejs/dnd-kit-core octane
|
|
12
|
+
pnpm add @octanejs/dnd-kit-modifiers @octanejs/dnd-kit-core octane
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Replace imports from `@dnd-kit/modifiers` with `@octanejs/dnd-kit-modifiers`;
|
|
16
|
+
[`@octanejs/codemod`](../codemod) rewrites them for you.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```tsrx
|
|
21
|
+
import { DndContext } from '@octanejs/dnd-kit-core';
|
|
22
|
+
import { restrictToFirstScrollableAncestor, restrictToHorizontalAxis } from '@octanejs/dnd-kit-modifiers';
|
|
23
|
+
|
|
24
|
+
const modifiers = [restrictToHorizontalAxis, restrictToFirstScrollableAncestor];
|
|
25
|
+
|
|
26
|
+
export function Tabs() @{
|
|
27
|
+
<DndContext modifiers={modifiers}>
|
|
28
|
+
<nav>{/* draggable tabs */}</nav>
|
|
29
|
+
</DndContext>
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## About this port
|
|
34
|
+
|
|
35
|
+
This package is part of Octane's port of the legacy dnd kit API, the
|
|
36
|
+
`@dnd-kit/core` 6.x family: `@octanejs/dnd-kit-core`, `@octanejs/dnd-kit-sortable`,
|
|
37
|
+
`@octanejs/dnd-kit-modifiers`, `@octanejs/dnd-kit-utilities`, and
|
|
38
|
+
`@octanejs/dnd-kit-accessibility`, one per upstream package. For the modern
|
|
39
|
+
`@dnd-kit/react` API, use [`@octanejs/dnd-kit`](../dnd-kit).
|
|
40
|
+
|
|
41
|
+
Parity is `recorded-unverified`. Upstream's own unit tests are placeholders, so
|
|
42
|
+
each package runs them pristine and adapted, and a repo-authored differential test
|
|
43
|
+
runs the same fixtures against the published React package and compares the DOM
|
|
44
|
+
after every drag step. See [`UPSTREAM.md`](./UPSTREAM.md) for the pin and the
|
|
45
|
+
evidence.
|
package/UPSTREAM.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# `@octanejs/dnd-kit-modifiers` upstream ledger
|
|
2
|
+
|
|
3
|
+
`@octanejs/dnd-kit-modifiers` ports `@dnd-kit/modifiers@9.0.0` from
|
|
4
|
+
`https://github.com/clauderic/dnd-kit.git`, the legacy dnd kit API.
|
|
5
|
+
|
|
6
|
+
## Pin
|
|
7
|
+
|
|
8
|
+
- Package: `@dnd-kit/modifiers@9.0.0`, the latest release.
|
|
9
|
+
- Source commit: `e9215e820798459ae036896fce7fd9a6fe855772`, the `@dnd-kit/core@6.3.1` release tag. It holds all
|
|
10
|
+
five legacy packages at their latest releases. Their trees there are
|
|
11
|
+
byte-identical to their own release tags; this package's tag is
|
|
12
|
+
`@dnd-kit/modifiers@9.0.0` at `2d862922975e5fa73e1a11845f8c781296f21d4b`.
|
|
13
|
+
- npm integrity: `sha512-ybiLc66qRGuZoC20wdSSG6pDXFikui/dCNGthxv4Ndy8ylErY0N3KVxY2bgo7AWwIbxDmXDg3ylAFmnrjcbVvw==`
|
|
14
|
+
- npm tarball SHA-256: `1ad2f9ecf7b65bd58de367c7b9226b62951916ca2694ad66440a3c8978ebdc29`
|
|
15
|
+
- License: MIT. `LICENSE.upstream` is the upstream package's license, byte for byte.
|
|
16
|
+
- React oracle: `react@19.2.7` and `react-dom@19.2.7` from the default catalog.
|
|
17
|
+
|
|
18
|
+
The legacy packages were published without a `gitHead` or npm provenance, so the
|
|
19
|
+
repository's preflight cannot tie the npm artifact to a commit on its own. The
|
|
20
|
+
source is pinned to the release tag instead, and the parity status stays
|
|
21
|
+
`recorded-unverified`.
|
|
22
|
+
|
|
23
|
+
`upstream/` holds the pinned package directory byte for byte. Each file
|
|
24
|
+
is checked against its git blob SHA in `audit/upstream.lock.json`:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pnpm react-port:materialize run --check --package-dir packages/dnd-kit-modifiers
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Source boundary
|
|
31
|
+
|
|
32
|
+
`src/` mirrors `upstream/src/` file for file, formatted with the repository's
|
|
33
|
+
Prettier settings, with `react`/`react-dom` imports pointed at `octane` and
|
|
34
|
+
`@dnd-kit/*` imports pointed at the `@octanejs/dnd-kit-*` packages. Files that
|
|
35
|
+
change beyond that:
|
|
36
|
+
|
|
37
|
+
- Every module is copied from `upstream/src/` with its `@dnd-kit/*` imports pointed at the Octane packages; no file has a behavioral change.
|
|
38
|
+
|
|
39
|
+
## Public surface
|
|
40
|
+
|
|
41
|
+
Every runtime export of `@dnd-kit/modifiers@9.0.0` is ported under the same name: `createSnapModifier`, the five `restrictTo*` modifiers, and `snapCenterToCursor`.
|
|
42
|
+
`tests/exports.test.ts` compares the export names and value kinds with the published
|
|
43
|
+
package, and `typetests/public-api.test-d.ts` checks the public types.
|
|
44
|
+
|
|
45
|
+
## Tests
|
|
46
|
+
|
|
47
|
+
| Upstream | Disposition |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `test/modifiers.test.tsx (2 cases: `restrictToHorizontalAxis`, `restrictToVerticalAxis`)` | Runs unchanged against the pinned source and React (`dnd-kit-modifiers-pristine`), and regenerated from the lock against the port (`dnd-kit-modifiers-upstream`). |
|
|
50
|
+
| Repository Cypress specs (`cypress/integration/draggable_spec.ts`, `sortable_spec.ts`) | Not ported. They drive the Storybook stories outside the package boundary. The differential below covers the same pointer and keyboard drags against the published package. |
|
|
51
|
+
|
|
52
|
+
Because the upstream unit tests are placeholders, the behavioral contract is the
|
|
53
|
+
repo-authored differential: `tests/differential/parity.test.ts` (horizontal axis with the first scrollable ancestor, vertical axis with the parent element, window edges, a snap grid, and DragOverlay modifiers). `audit/react-parity.json` registers all three
|
|
54
|
+
lanes; `node scripts/react-parity/dnd-kit-legacy-manifest.mjs` regenerates it and
|
|
55
|
+
the runtime inventories.
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/dnd-kit-modifiers",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22.22.2"
|
|
9
|
+
},
|
|
10
|
+
"description": "dnd kit modifiers for the octane renderer — a port of the legacy @dnd-kit/modifiers 9.0.0 restrictTo* and snap modifiers.",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Dominic Gannaway",
|
|
13
|
+
"email": "dg@domgan.com"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/octanejs/octane.git",
|
|
21
|
+
"directory": "packages/dnd-kit-modifiers"
|
|
22
|
+
},
|
|
23
|
+
"main": "src/index.ts",
|
|
24
|
+
"module": "src/index.ts",
|
|
25
|
+
"types": "src/index.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"README.md",
|
|
29
|
+
"UPSTREAM.md",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"LICENSE.upstream"
|
|
32
|
+
],
|
|
33
|
+
"exports": {
|
|
34
|
+
".": "./src/index.ts"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@octanejs/dnd-kit-utilities": "0.0.1"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@octanejs/dnd-kit-core": "0.0.1",
|
|
41
|
+
"octane": "^0.16.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@dnd-kit/core": "6.3.1",
|
|
45
|
+
"@dnd-kit/modifiers": "9.0.0",
|
|
46
|
+
"@dnd-kit/utilities": "3.2.2",
|
|
47
|
+
"@octanejs/dnd-kit-core": "0.0.1",
|
|
48
|
+
"@tsrx/react": "^0.4.5",
|
|
49
|
+
"esbuild": "^0.28.1",
|
|
50
|
+
"octane": "0.16.4",
|
|
51
|
+
"react": "19.2.7",
|
|
52
|
+
"react-dom": "19.2.7",
|
|
53
|
+
"vitest": "^4.1.10"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"test": "vitest run --root ../.. --project dnd-kit-modifiers",
|
|
57
|
+
"typecheck": "octane-tsc -p tsconfig.json"
|
|
58
|
+
}
|
|
6
59
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Modifier } from '@octanejs/dnd-kit-core';
|
|
2
|
+
|
|
3
|
+
export function createSnapModifier(gridSize: number): Modifier {
|
|
4
|
+
return ({ transform }) => ({
|
|
5
|
+
...transform,
|
|
6
|
+
x: Math.ceil(transform.x / gridSize) * gridSize,
|
|
7
|
+
y: Math.ceil(transform.y / gridSize) * gridSize,
|
|
8
|
+
});
|
|
9
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createSnapModifier } from './createSnapModifier';
|
|
2
|
+
export { restrictToHorizontalAxis } from './restrictToHorizontalAxis';
|
|
3
|
+
export { restrictToParentElement } from './restrictToParentElement';
|
|
4
|
+
export { restrictToFirstScrollableAncestor } from './restrictToFirstScrollableAncestor';
|
|
5
|
+
export { restrictToVerticalAxis } from './restrictToVerticalAxis';
|
|
6
|
+
export { restrictToWindowEdges } from './restrictToWindowEdges';
|
|
7
|
+
export { snapCenterToCursor } from './snapCenterToCursor';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Modifier } from '@octanejs/dnd-kit-core';
|
|
2
|
+
import { restrictToBoundingRect } from './utilities';
|
|
3
|
+
|
|
4
|
+
export const restrictToFirstScrollableAncestor: Modifier = ({
|
|
5
|
+
draggingNodeRect,
|
|
6
|
+
transform,
|
|
7
|
+
scrollableAncestorRects,
|
|
8
|
+
}) => {
|
|
9
|
+
const firstScrollableAncestorRect = scrollableAncestorRects[0];
|
|
10
|
+
|
|
11
|
+
if (!draggingNodeRect || !firstScrollableAncestorRect) {
|
|
12
|
+
return transform;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return restrictToBoundingRect(transform, draggingNodeRect, firstScrollableAncestorRect);
|
|
16
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Modifier } from '@octanejs/dnd-kit-core';
|
|
2
|
+
import { restrictToBoundingRect } from './utilities';
|
|
3
|
+
|
|
4
|
+
export const restrictToParentElement: Modifier = ({
|
|
5
|
+
containerNodeRect,
|
|
6
|
+
draggingNodeRect,
|
|
7
|
+
transform,
|
|
8
|
+
}) => {
|
|
9
|
+
if (!draggingNodeRect || !containerNodeRect) {
|
|
10
|
+
return transform;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return restrictToBoundingRect(transform, draggingNodeRect, containerNodeRect);
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Modifier } from '@octanejs/dnd-kit-core';
|
|
2
|
+
|
|
3
|
+
import { restrictToBoundingRect } from './utilities';
|
|
4
|
+
|
|
5
|
+
export const restrictToWindowEdges: Modifier = ({ transform, draggingNodeRect, windowRect }) => {
|
|
6
|
+
if (!draggingNodeRect || !windowRect) {
|
|
7
|
+
return transform;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return restrictToBoundingRect(transform, draggingNodeRect, windowRect);
|
|
11
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Modifier } from '@octanejs/dnd-kit-core';
|
|
2
|
+
import { getEventCoordinates } from '@octanejs/dnd-kit-utilities';
|
|
3
|
+
|
|
4
|
+
export const snapCenterToCursor: Modifier = ({ activatorEvent, draggingNodeRect, transform }) => {
|
|
5
|
+
if (draggingNodeRect && activatorEvent) {
|
|
6
|
+
const activatorCoordinates = getEventCoordinates(activatorEvent);
|
|
7
|
+
|
|
8
|
+
if (!activatorCoordinates) {
|
|
9
|
+
return transform;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const offsetX = activatorCoordinates.x - draggingNodeRect.left;
|
|
13
|
+
const offsetY = activatorCoordinates.y - draggingNodeRect.top;
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...transform,
|
|
17
|
+
x: transform.x + offsetX - draggingNodeRect.width / 2,
|
|
18
|
+
y: transform.y + offsetY - draggingNodeRect.height / 2,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return transform;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { restrictToBoundingRect } from './restrictToBoundingRect';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ClientRect } from '@octanejs/dnd-kit-core';
|
|
2
|
+
import type { Transform } from '@octanejs/dnd-kit-utilities';
|
|
3
|
+
|
|
4
|
+
export function restrictToBoundingRect(
|
|
5
|
+
transform: Transform,
|
|
6
|
+
rect: ClientRect,
|
|
7
|
+
boundingRect: ClientRect,
|
|
8
|
+
): Transform {
|
|
9
|
+
const value = {
|
|
10
|
+
...transform,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
if (rect.top + transform.y <= boundingRect.top) {
|
|
14
|
+
value.y = boundingRect.top - rect.top;
|
|
15
|
+
} else if (rect.bottom + transform.y >= boundingRect.top + boundingRect.height) {
|
|
16
|
+
value.y = boundingRect.top + boundingRect.height - rect.bottom;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (rect.left + transform.x <= boundingRect.left) {
|
|
20
|
+
value.x = boundingRect.left - rect.left;
|
|
21
|
+
} else if (rect.right + transform.x >= boundingRect.left + boundingRect.width) {
|
|
22
|
+
value.x = boundingRect.left + boundingRect.width - rect.right;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return value;
|
|
26
|
+
}
|