@dnd-kit/helpers 0.0.3 → 0.0.4-beta-20240621030124

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/dist/index.cjs CHANGED
@@ -74,11 +74,13 @@ function mutate(items, source, target, mutation) {
74
74
  if (sourceIndex2 === -1 || targetIndex2 === -1) {
75
75
  return items;
76
76
  }
77
- const { dragOperation: dragOperation2 } = source.manager;
78
- if (!dragOperation2.canceled && "index" in source && typeof source.index === "number") {
79
- const projectedSourceIndex = source.index;
80
- if (projectedSourceIndex !== sourceIndex2) {
81
- return mutation(items, sourceIndex2, projectedSourceIndex);
77
+ if (source.manager) {
78
+ const { dragOperation: dragOperation2 } = source.manager;
79
+ if (!dragOperation2.canceled && "index" in source && typeof source.index === "number") {
80
+ const projectedSourceIndex = source.index;
81
+ if (projectedSourceIndex !== sourceIndex2) {
82
+ return mutation(items, sourceIndex2, projectedSourceIndex);
83
+ }
82
84
  }
83
85
  }
84
86
  return mutation(items, sourceIndex2, targetIndex2);
@@ -108,6 +110,7 @@ function mutate(items, source, target, mutation) {
108
110
  break;
109
111
  }
110
112
  }
113
+ if (!source.manager) return items;
111
114
  const { dragOperation } = source.manager;
112
115
  const position = dragOperation.position.current;
113
116
  if (targetParent == null) {
@@ -0,0 +1,17 @@
1
+ import { UniqueIdentifier, Draggable, Droppable } from '@dnd-kit/abstract';
2
+
3
+ /**
4
+ * Move an array item to a different position. Returns a new array with the item moved to the new position.
5
+ */
6
+ declare function arrayMove<T extends any[]>(array: T, from: number, to: number): T;
7
+ /**
8
+ * Move an array item to a different position. Returns a new array with the item moved to the new position.
9
+ */
10
+ declare function arraySwap<T extends any[]>(array: T, from: number, to: number): T;
11
+ type Items = UniqueIdentifier[] | {
12
+ id: UniqueIdentifier;
13
+ }[];
14
+ declare function move<T extends Items | Record<UniqueIdentifier, Items>, U extends Draggable, V extends Droppable>(items: T, source: U | null, target: V | null): T;
15
+ declare function swap<T extends Items | Record<UniqueIdentifier, Items>, U extends Draggable, V extends Droppable>(items: T, source: U | null, target: V | null): T;
16
+
17
+ export { arrayMove, arraySwap, move, swap };
package/dist/index.js CHANGED
@@ -48,11 +48,13 @@ function mutate(items, source, target, mutation) {
48
48
  if (sourceIndex2 === -1 || targetIndex2 === -1) {
49
49
  return items;
50
50
  }
51
- const { dragOperation: dragOperation2 } = source.manager;
52
- if (!dragOperation2.canceled && "index" in source && typeof source.index === "number") {
53
- const projectedSourceIndex = source.index;
54
- if (projectedSourceIndex !== sourceIndex2) {
55
- return mutation(items, sourceIndex2, projectedSourceIndex);
51
+ if (source.manager) {
52
+ const { dragOperation: dragOperation2 } = source.manager;
53
+ if (!dragOperation2.canceled && "index" in source && typeof source.index === "number") {
54
+ const projectedSourceIndex = source.index;
55
+ if (projectedSourceIndex !== sourceIndex2) {
56
+ return mutation(items, sourceIndex2, projectedSourceIndex);
57
+ }
56
58
  }
57
59
  }
58
60
  return mutation(items, sourceIndex2, targetIndex2);
@@ -82,6 +84,7 @@ function mutate(items, source, target, mutation) {
82
84
  break;
83
85
  }
84
86
  }
87
+ if (!source.manager) return items;
85
88
  const { dragOperation } = source.manager;
86
89
  const position = dragOperation.position.current;
87
90
  if (targetParent == null) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dnd-kit/helpers",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4-beta-20240621030124",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -24,14 +24,14 @@
24
24
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
25
25
  },
26
26
  "dependencies": {
27
- "@dnd-kit/abstract": "^0.0.3",
27
+ "@dnd-kit/abstract": "0.0.4-beta-20240621030124",
28
28
  "tslib": "^2.6.2"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@dnd-kit/eslint-config": "*",
32
32
  "eslint": "^8.38.0",
33
- "tsup": "^6.7.0",
34
- "typescript": "^5.0.4"
33
+ "tsup": "^8.1.0",
34
+ "typescript": "^5.5.2"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"