@dnd-kit/react 0.0.8 → 0.0.9-beta-20250205134032

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/hooks.cjs CHANGED
@@ -59,7 +59,7 @@ function useComputed(compute, dependencies = [], sync = false) {
59
59
  sync
60
60
  );
61
61
  }
62
- function useDeepSignal(target) {
62
+ function useDeepSignal(target, synchronous) {
63
63
  const tracked = react.useRef(/* @__PURE__ */ new Map());
64
64
  const forceUpdate = useForceUpdate();
65
65
  useIsomorphicLayoutEffect(() => {
@@ -68,7 +68,9 @@ function useDeepSignal(target) {
68
68
  return;
69
69
  }
70
70
  return state.effect(() => {
71
+ var _a;
71
72
  let stale = false;
73
+ let sync = false;
72
74
  for (const entry of tracked.current) {
73
75
  const [key] = entry;
74
76
  const value = state.untracked(() => entry[1]);
@@ -76,9 +78,12 @@ function useDeepSignal(target) {
76
78
  if (value !== latestValue) {
77
79
  stale = true;
78
80
  tracked.current.set(key, latestValue);
81
+ sync = (_a = synchronous == null ? void 0 : synchronous(key, value, latestValue)) != null ? _a : false;
79
82
  }
80
83
  }
81
- if (stale) forceUpdate();
84
+ if (stale) {
85
+ sync ? reactDom.flushSync(forceUpdate) : forceUpdate();
86
+ }
82
87
  });
83
88
  }, [target]);
84
89
  return react.useMemo(
package/hooks.d.ts CHANGED
@@ -9,7 +9,7 @@ declare function useComputed<T = any>(compute: () => T, dependencies?: any[], sy
9
9
  };
10
10
 
11
11
  /** Trigger a re-render when reading signal properties of an object. */
12
- declare function useDeepSignal<T extends object | null | undefined>(target: T): T;
12
+ declare function useDeepSignal<T extends object | null | undefined>(target: T, synchronous?: (property: keyof T, oldValue: any, newValue: any) => boolean): T;
13
13
 
14
14
  declare function useImmediateEffect(callback: EffectCallback, _?: DependencyList): void;
15
15
 
package/hooks.js CHANGED
@@ -57,7 +57,7 @@ function useComputed(compute, dependencies = [], sync = false) {
57
57
  sync
58
58
  );
59
59
  }
60
- function useDeepSignal(target) {
60
+ function useDeepSignal(target, synchronous) {
61
61
  const tracked = useRef(/* @__PURE__ */ new Map());
62
62
  const forceUpdate = useForceUpdate();
63
63
  useIsomorphicLayoutEffect(() => {
@@ -66,7 +66,9 @@ function useDeepSignal(target) {
66
66
  return;
67
67
  }
68
68
  return effect(() => {
69
+ var _a;
69
70
  let stale = false;
71
+ let sync = false;
70
72
  for (const entry of tracked.current) {
71
73
  const [key] = entry;
72
74
  const value = untracked(() => entry[1]);
@@ -74,9 +76,12 @@ function useDeepSignal(target) {
74
76
  if (value !== latestValue) {
75
77
  stale = true;
76
78
  tracked.current.set(key, latestValue);
79
+ sync = (_a = synchronous == null ? void 0 : synchronous(key, value, latestValue)) != null ? _a : false;
77
80
  }
78
81
  }
79
- if (stale) forceUpdate();
82
+ if (stale) {
83
+ sync ? flushSync(forceUpdate) : forceUpdate();
84
+ }
80
85
  });
81
86
  }, [target]);
82
87
  return useMemo(
package/index.cjs CHANGED
@@ -199,7 +199,7 @@ function useDraggable(input) {
199
199
  manager
200
200
  )
201
201
  );
202
- const trackedDraggable = hooks.useDeepSignal(draggable);
202
+ const trackedDraggable = hooks.useDeepSignal(draggable, shouldUpdateSynchronously);
203
203
  hooks.useOnValueChange(id, () => draggable.id = id);
204
204
  hooks.useOnElementChange(handle, (handle2) => draggable.handle = handle2);
205
205
  hooks.useOnElementChange(element, (element2) => draggable.element = element2);
@@ -248,6 +248,10 @@ function useDraggable(input) {
248
248
  )
249
249
  };
250
250
  }
251
+ function shouldUpdateSynchronously(key, oldValue, newValue) {
252
+ if (key === "isDragSource" && !newValue && oldValue) return true;
253
+ return false;
254
+ }
251
255
  function DragOverlay({ children, className }) {
252
256
  const ref = react.useRef(null);
253
257
  const manager = useDragDropManager();
package/index.js CHANGED
@@ -197,7 +197,7 @@ function useDraggable(input) {
197
197
  manager
198
198
  )
199
199
  );
200
- const trackedDraggable = useDeepSignal(draggable);
200
+ const trackedDraggable = useDeepSignal(draggable, shouldUpdateSynchronously);
201
201
  useOnValueChange(id, () => draggable.id = id);
202
202
  useOnElementChange(handle, (handle2) => draggable.handle = handle2);
203
203
  useOnElementChange(element, (element2) => draggable.element = element2);
@@ -246,6 +246,10 @@ function useDraggable(input) {
246
246
  )
247
247
  };
248
248
  }
249
+ function shouldUpdateSynchronously(key, oldValue, newValue) {
250
+ if (key === "isDragSource" && !newValue && oldValue) return true;
251
+ return false;
252
+ }
249
253
  function DragOverlay({ children, className }) {
250
254
  const ref = useRef(null);
251
255
  const manager = useDragDropManager();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnd-kit/react",
3
- "version": "0.0.8",
3
+ "version": "0.0.9-beta-20250205134032",
4
4
  "main": "./index.cjs",
5
5
  "module": "./index.js",
6
6
  "type": "module",
@@ -56,9 +56,9 @@
56
56
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
57
57
  },
58
58
  "dependencies": {
59
- "@dnd-kit/abstract": "^0.0.8",
60
- "@dnd-kit/dom": "^0.0.8",
61
- "@dnd-kit/state": "^0.0.8",
59
+ "@dnd-kit/abstract": "0.0.9-beta-20250205134032",
60
+ "@dnd-kit/dom": "0.0.9-beta-20250205134032",
61
+ "@dnd-kit/state": "0.0.9-beta-20250205134032",
62
62
  "tslib": "^2.6.2"
63
63
  },
64
64
  "peerDependencies": {
package/sortable.cjs CHANGED
@@ -57,7 +57,7 @@ function useSortable(input) {
57
57
  manager
58
58
  );
59
59
  });
60
- const trackedSortable = hooks.useDeepSignal(sortable$1);
60
+ const trackedSortable = hooks.useDeepSignal(sortable$1, shouldUpdateSynchronously);
61
61
  hooks.useOnValueChange(id, () => sortable$1.id = id);
62
62
  hooks.useIsomorphicLayoutEffect(() => {
63
63
  state.batch(() => {
@@ -156,7 +156,15 @@ function useSortable(input) {
156
156
  )
157
157
  };
158
158
  }
159
+ function shouldUpdateSynchronously(key, oldValue, newValue) {
160
+ if (key === "isDragSource" && !newValue && oldValue) return true;
161
+ return false;
162
+ }
159
163
 
164
+ Object.defineProperty(exports, "isSortable", {
165
+ enumerable: true,
166
+ get: function () { return sortable.isSortable; }
167
+ });
160
168
  exports.useSortable = useSortable;
161
169
  //# sourceMappingURL=sortable.cjs.map
162
170
  //# sourceMappingURL=sortable.cjs.map
package/sortable.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Data } from '@dnd-kit/abstract';
2
2
  import { SortableInput, Sortable } from '@dnd-kit/dom/sortable';
3
+ export { isSortable } from '@dnd-kit/dom/sortable';
3
4
  import { RefOrValue } from '@dnd-kit/react/utilities';
4
5
 
5
6
  interface UseSortableInput<T extends Data = Data> extends Omit<SortableInput<T>, 'handle' | 'element' | 'target'> {
package/sortable.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { useCallback } from 'react';
2
2
  import { batch, deepEqual } from '@dnd-kit/state';
3
3
  import { Sortable, defaultSortableTransition } from '@dnd-kit/dom/sortable';
4
+ export { isSortable } from '@dnd-kit/dom/sortable';
4
5
  import { useInstance } from '@dnd-kit/react';
5
6
  import { useDeepSignal, useOnValueChange, useIsomorphicLayoutEffect, useImmediateEffect, useOnElementChange } from '@dnd-kit/react/hooks';
6
7
  import { currentValue } from '@dnd-kit/react/utilities';
@@ -55,7 +56,7 @@ function useSortable(input) {
55
56
  manager
56
57
  );
57
58
  });
58
- const trackedSortable = useDeepSignal(sortable);
59
+ const trackedSortable = useDeepSignal(sortable, shouldUpdateSynchronously);
59
60
  useOnValueChange(id, () => sortable.id = id);
60
61
  useIsomorphicLayoutEffect(() => {
61
62
  batch(() => {
@@ -154,6 +155,10 @@ function useSortable(input) {
154
155
  )
155
156
  };
156
157
  }
158
+ function shouldUpdateSynchronously(key, oldValue, newValue) {
159
+ if (key === "isDragSource" && !newValue && oldValue) return true;
160
+ return false;
161
+ }
157
162
 
158
163
  export { useSortable };
159
164
  //# sourceMappingURL=sortable.js.map