@octanejs/dnd-kit 0.1.1 → 0.1.4
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 +7 -0
- package/package.json +3 -3
- package/src/sortable/useSortable.ts +19 -4
package/README.md
CHANGED
|
@@ -40,5 +40,12 @@ The public entry points mirror `@dnd-kit/react@0.5.0`:
|
|
|
40
40
|
- `@octanejs/dnd-kit/sortable`
|
|
41
41
|
- `@octanejs/dnd-kit/utilities`
|
|
42
42
|
|
|
43
|
+
Octane's default `useSortable` plugins retain dnd-kit's keyboard mechanics but
|
|
44
|
+
omit `OptimisticSortingPlugin`. That upstream plugin reparents the single host
|
|
45
|
+
element before application state commits; doing so can split an Octane keyed
|
|
46
|
+
item's owned DOM range. Update list state from the drag events as in the example
|
|
47
|
+
above and Octane performs the visible keyed move. An explicit `plugins` array is
|
|
48
|
+
still used exactly as supplied.
|
|
49
|
+
|
|
43
50
|
This package targets the modern dnd-kit API. The legacy `@dnd-kit/core` 6.x
|
|
44
51
|
API is not included.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/dnd-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@dnd-kit/state": "0.5.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"octane": "0.1.
|
|
49
|
+
"octane": "0.1.9"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@dnd-kit/helpers": "0.5.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"react": "^19.2.0",
|
|
58
58
|
"react-dom": "^19.2.0",
|
|
59
59
|
"vitest": "^4.1.9",
|
|
60
|
-
"octane": "0.1.
|
|
60
|
+
"octane": "0.1.9"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"test": "vitest run --root ../.. --project dnd-kit",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'octane';
|
|
2
|
-
import type { Data } from '@dnd-kit/abstract';
|
|
3
|
-
import { Sortable, defaultSortableTransition } from '@dnd-kit/dom/sortable';
|
|
2
|
+
import type { Customizable, Data, Plugins } from '@dnd-kit/abstract';
|
|
3
|
+
import { Sortable, SortableKeyboardPlugin, defaultSortableTransition } from '@dnd-kit/dom/sortable';
|
|
4
4
|
import type { SortableInput } from '@dnd-kit/dom/sortable';
|
|
5
5
|
import { batch, deepEqual } from '@dnd-kit/state';
|
|
6
6
|
import { useInstance } from '../core/hooks/useInstance';
|
|
@@ -21,6 +21,19 @@ export interface UseSortableInput<T extends Data = Data> extends Omit<
|
|
|
21
21
|
target?: RefOrValue<Element>;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// The DOM core's other default sortable plugin optimistically reparents only
|
|
25
|
+
// the referenced host Element. Octane keyed items can own a wider marker range,
|
|
26
|
+
// so that move splits the framework-owned range before application state has
|
|
27
|
+
// committed and makes the subsequent keyed reconciliation unsafe. Keep the
|
|
28
|
+
// keyboard mechanics by default and let Octane perform the visible move from
|
|
29
|
+
// the consumer's drag handler. Explicit plugin arrays remain authoritative.
|
|
30
|
+
const OCTANE_SORTABLE_DEFAULT_PLUGINS: Plugins = [SortableKeyboardPlugin];
|
|
31
|
+
|
|
32
|
+
function resolveSortablePlugins(value: Customizable<Plugins> | undefined): Plugins {
|
|
33
|
+
if (value === undefined) return OCTANE_SORTABLE_DEFAULT_PLUGINS;
|
|
34
|
+
return typeof value === 'function' ? value([...OCTANE_SORTABLE_DEFAULT_PLUGINS]) : value;
|
|
35
|
+
}
|
|
36
|
+
|
|
24
37
|
export function useSortable<T extends Data = Data>(input: UseSortableInput<T>, slot?: symbol) {
|
|
25
38
|
const {
|
|
26
39
|
accept,
|
|
@@ -39,12 +52,14 @@ export function useSortable<T extends Data = Data>(input: UseSortableInput<T>, s
|
|
|
39
52
|
type,
|
|
40
53
|
plugins,
|
|
41
54
|
} = input;
|
|
55
|
+
const resolvedPlugins = resolveSortablePlugins(plugins);
|
|
42
56
|
const transition = { ...defaultSortableTransition, ...input.transition };
|
|
43
57
|
const sortable = useInstance(
|
|
44
58
|
(manager) =>
|
|
45
59
|
new Sortable(
|
|
46
60
|
{
|
|
47
61
|
...input,
|
|
62
|
+
plugins: resolvedPlugins,
|
|
48
63
|
transition,
|
|
49
64
|
register: false,
|
|
50
65
|
handle: currentValue(handle),
|
|
@@ -116,8 +131,8 @@ export function useSortable<T extends Data = Data>(input: UseSortableInput<T>, s
|
|
|
116
131
|
subSlot(slot, 'priority'),
|
|
117
132
|
);
|
|
118
133
|
useOnValueChange(
|
|
119
|
-
|
|
120
|
-
() => (sortable.plugins =
|
|
134
|
+
resolvedPlugins,
|
|
135
|
+
() => (sortable.plugins = resolvedPlugins),
|
|
121
136
|
undefined,
|
|
122
137
|
deepEqual,
|
|
123
138
|
subSlot(slot, 'plugins'),
|