- 将所有图片路径从绝对路径改为使用 process.env.PUBLIC_URL - 修复 HomePage.tsx 中所有图片引用 - 修复 CoursePage.tsx 中所有图片引用 - 确保图片在 GitHub Pages 上正确加载 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
40 KiB
@dnd-kit/sortable
10.0.0
Patch Changes
- Updated dependencies [
0c6a28d]:- @dnd-kit/core@6.3.0
9.0.0
Patch Changes
-
#1542
f629ec6Thanks @clauderic! - Fix bug with draggable and sortable elements with anidequal to0. -
Updated dependencies [
00ec286,995dc23,f629ec6,99643f6,6bbe39b,545a41c,bcaf7c4]:- @dnd-kit/core@6.2.0
8.0.0
Patch Changes
7.0.2
Patch Changes
-
#788
da94c02Thanks @clauderic! - Bug fixes for React 18 Strict Mode -
Updated dependencies [
da94c02]:- @dnd-kit/core@6.0.7
7.0.1
Patch Changes
-
#792
b6970e7Thanks @clauderic! - ThehasSortableDatatype-guard that is exported by @dnd-kit/sortable has been updated to also accept theActiveandOverinterfaces so it can be used in events such asonDragStart,onDragOver, andonDragEnd. -
Updated dependencies [
eaa6e12]:- @dnd-kit/core@6.0.4
7.0.0
Major Changes
-
#755
33e6dd2Thanks @clauderic! - TheUniqueIdentifiertype has been updated to now accept eitherstringornumberidentifiers. As a result, theidproperty ofuseDraggable,useDroppableanduseSortableand theitemsprop of<SortableContext>now all accept eitherstringornumberidentifiers.Migration steps
For consumers that are using TypeScript, import the
UniqueIdentifiertype to have strongly typed local state:+ import type {UniqueIdentifier} from '@dnd-kit/core'; function MyComponent() { - const [items, setItems] = useState(['A', 'B', 'C']); + const [items, setItems] = useState<UniqueIdentifier>(['A', 'B', 'C']); }Alternatively, consumers can cast or convert the
idproperty to astringwhen reading theidproperty of interfaces such asActive,Over,DroppableContainerandDraggableNode.The
draggableNodesobject has also been converted to a map. Consumers that were reading from thedraggableNodesproperty that is available on the public context of<DndContext>should follow these migration steps:- draggableNodes[someId]; + draggableNodes.get(someId); -
#660
30bbd12Thanks @clauderic! - Changes to the defaultsortableKeyboardCoordinatesKeyboardSensor coordinate getter.Better handling of variable sizes
The default
sortableKeyboardCoordinatesfunction now has better handling of lists that have items of variable sizes. We recommend that consumers re-order listsonDragOverinstead ofonDragEndwhen sorting lists of variable sizes via the keyboard for optimal compatibility.Better handling of overlapping droppables
The default
sortableKeyboardCoordinatesfunction that is exported from the@dnd-kit/sortablepackage has been updated to better handle cases where the collision rectangle is overlapping droppable rectangles. For example, fordownarrow key, the default function had logic that would only consider collisions against droppables that were below thebottomedge of the collision rect. This was problematic when the collision rect was overlapping droppable rects, because it meant that it's bottom edge was below the top edge of the droppable, and that resulted in that droppable being skipped.- collisionRect.bottom > droppableRect.top + collisionRect.top > droppableRect.topThis change should be backwards compatible for most consumers, but may introduce regressions in some use-cases, especially for consumers that may have copied the multiple containers examples. There is now a custom sortable keyboard coordinate getter optimized for multiple containers that you can refer to.
Minor Changes
-
#748
59ca82bThanks @clauderic! - Automatic focus management and activator node refs.Introducing activator node refs
Introducing the concept of activator node refs for
useDraggableanduseSortable. This allows @dnd-kit to handle common use-cases such as restoring focus on the activator node after dragging via the keyboard or only allowing the activator node to instantiate the keyboard sensor.Consumers of
useDraggableanduseSortablemay now optionally set the activator node ref on the element that receives listeners:import {useDraggable} from '@dnd-kit/core'; function Draggable(props) { const { listeners, setNodeRef, + setActivatorNodeRef, } = useDraggable({id: props.id}); return ( <div ref={setNodeRef}> Draggable element <button {...listeners} + ref={setActivatorNodeRef} > :: Drag Handle </button> </div> ) }It's common for the activator element (the element that receives the sensor listeners) to differ from the draggable node. When this happens, @dnd-kit has no reliable way to get a reference to the activator node after dragging ends, as the original
event.targetthat instantiated the sensor may no longer be mounted in the DOM or associated with the draggable node that was previously active.Automatically restoring focus
Focus management is now automatically handled by @dnd-kit. When the activator event is a Keyboard event, @dnd-kit will now attempt to automatically restore focus back to the first focusable node of the activator node or draggable node.
If no activator node is specified via the
setActivatorNodeRefsetter function ofuseDraggbleanduseSortable, @dnd-kit will automatically restore focus on the first focusable node of the draggable node set via thesetNodeRefsetter function ofuseDraggableanduseSortable.If you were previously managing focus manually and would like to opt-out of automatic focus management, use the newly introduced
restoreFocusproperty of theaccessibilityprop of<DndContext>:<DndContext accessibility={{ + restoreFocus: false }} -
#672
10f6836Thanks @clauderic! -SortableContextnow always requests measuring of droppable containers when itsitemsprop changes, regardless of whether or not dragging is in progress. Measuring will occur if the measuring configuration allows for it. -
#754
224201aThanks @clauderic! - The<SortableContext>component now optionally accepts adisabledprop to globally disableuseSortablehooks rendered within it.The
disabledprop accepts either a boolean or an object with the following shape:interface Disabled { draggable?: boolean; droppable?: boolean; }The
useSortablehook has now been updated to also optionally accept thedisabledconfiguration object to conditionally disable theuseDraggableand/oruseDroppablehooks used internally.Like the
strategyprop, thedisabledprop defined on theuseSortablehook takes precedence over thedisabledprop defined on the parent<SortableContext>.
Patch Changes
-
#757
e6d544fThanks @clauderic! - ThewasDraggingproperty ofanimateLayoutChangesnow remains true for longer than a single re-render. Before this change, it was possible for the component whereuseSortableis used to re-render before @dnd-kit is ready to perform the layout animation, causing the animation to be skipped entirely. -
#749
188a450Thanks @clauderic! - Faster (and safer) equal implementation. -
Updated dependencies [
4173087,59ca82b,7161f70,a52fba1,40707ce,a41e5b8,bf30718,a41e5b8,a41e5b8,035021a,77e3d44,5811986,e302bd4,188a450,59ca82b,750d726,5f3c700,035021a,e6e242c,035021a,33e6dd2,10f6836,c1b3b5a,035021a]:- @dnd-kit/core@6.0.0
- @dnd-kit/utilities@3.2.0
6.0.1
Patch Changes
-
#642
15a6017Thanks @vosatom! - Fixed an issue that affectedSortableContextperformance. ThesortedRectsproperty of theSortableContextprovider were being recomputed whenever coordinates changed rather than only when the order of the items changed. -
Updated dependencies [
b3b185d]:- @dnd-kit/core@5.0.2
6.0.0
Major Changes
-
#518
6310227Thanks @clauderic! - Major internal refactor of measuring and collision detection.Summary of changes
Previously, all collision detection algorithms were relative to the top and left points of the document. While this approach worked in most situations, it broke down in a number of different use-cases, such as fixed position droppable containers and trying to drag between containers that had different scroll positions.
This new approach changes the frame of comparison to be relative to the viewport. This is a major breaking change, and will need to be released under a new major version bump.
Breaking changes:
- By default,
@dnd-kitnow ignores only the transforms applied to the draggable / droppable node itself, but considers all the transforms applied to its ancestors. This should provide the right balance of flexibility for most consumers.- Transforms applied to the droppable and draggable nodes are ignored by default, because the recommended approach for moving items on the screen is to use the transform property, which can interfere with the calculation of collisions.
- Consumers can choose an alternate approach that does consider transforms for specific use-cases if needed by configuring the measuring prop of . Refer to the example.
- Reduced the number of concepts related to measuring from
ViewRect,LayoutRectto just a single concept ofClientRect.- The
ClientRectinterface no longer holds theoffsetTopandoffsetLeftproperties. For most use-cases, you can replaceoffsetTopwithtopandoffsetLeftwithleft. - Replaced the following exports from the
@dnd-kit/corepackage withgetClientRect:getBoundingClientRectgetViewRectgetLayoutRectgetViewportLayoutRect
- The
- Removed
translatedRectfrom theSensorContextinterface. Replace usage withcollisionRect. - Removed
activeNodeClientRecton theDndContextinterface. Replace withactiveNodeRect.
- By default,
-
#569
e7ac3d4Thanks @clauderic! - Separated context into public and internal context providers. Certain properties that used to be available on the publicDndContextDescriptorinterface have been moved to the internal context provider and are no longer exposed to consumers:interface DndContextDescriptor { - dispatch: React.Dispatch<Actions>; - activators: SyntheticListeners; - ariaDescribedById: { - draggable: UniqueIdentifier; - }; }Having two distinct context providers will allow to keep certain internals such as
dispatchhidden from consumers.It also serves as an optimization until context selectors are implemented in React, properties that change often, such as the droppable containers and droppable rects, the transform value and array of collisions should be stored on a different context provider to limit un-necessary re-renders in
useDraggable,useDroppableanduseSortable.The
<InternalContext.Provider>is also reset to its default values within<DragOverlay>. This paves the way towards being able to seamlessly use components that use hooks such asuseDraggableanduseDroppableas children of<DragOverlay>without causing interference or namespace collisions.Consumers can still make calls to
useDndContext()to get theactiveoroverproperties if they wish to re-render the component rendered withinDragOverlayin response to user interaction, since those use thePublicContext
Minor Changes
-
#558
f3ad20dThanks @clauderic! - Refactor of theCollisionDetectioninterface to return an array ofCollisions:+export interface Collision { + id: UniqueIdentifier; + data?: Record<string, any>; +} export type CollisionDetection = (args: { active: Active; collisionRect: ClientRect; droppableContainers: DroppableContainer[]; pointerCoordinates: Coordinates | null; -}) => UniqueIdentifier; +}) => Collision[];This is a breaking change that requires all collision detection strategies to be updated to return an array of
Collisionrather than a singleUniqueIdentifierThe
overproperty remains a singleUniqueIdentifier, and is set to the first item in returned in the collisions array.Consumers can also access the
collisionsproperty which can be used to implement use-cases such as combining droppables in user-land.The
onDragMove,onDragOverandonDragEndcallbacks are also updated to receive the collisions array property.Built-in collision detections such as rectIntersection, closestCenter, closestCorners and pointerWithin adhere to the CollisionDescriptor interface, which extends the Collision interface:
export interface CollisionDescriptor extends Collision { data: { droppableContainer: DroppableContainer; value: number; [key: string]: any; }; }Consumers can also access the array of collisions in components wrapped by
<DndContext>via theuseDndContext()hook:import {useDndContext} from '@dnd-kit/core'; function MyComponent() { const {collisions} = useDndContext(); } -
#561
02edd26Thanks @clauderic! - Droppable containers now observe the node they are attached to viasetNodeRefusingResizeObserverwhile dragging.This behaviour can be configured using the newly introduced
resizeObserverConfigproperty.interface ResizeObserverConfig { /** Whether the ResizeObserver should be disabled entirely */ disabled?: boolean; /** Resize events may affect the layout and position of other droppable containers. * Specify an array of `UniqueIdentifier` of droppable containers that should also be re-measured * when this droppable container resizes. Specifying an empty array re-measures all droppable containers. */ updateMeasurementsFor?: UniqueIdentifier[]; /** Represents the debounce timeout between when resize events are observed and when elements are re-measured */ timeout?: number; }By default, only the current droppable is scheduled to be re-measured when a resize event is observed. However, this may not be suitable for all use-cases. When an element resizes, it can affect the layout and position of other elements, such that it may be necessary to re-measure other droppable nodes in response to that single resize event. The
recomputeIdsproperty can be used to specify which droppableids should be re-measured in response to resize events being observed.For example, the
useSortablepreset re-computes the measurements of all sortable elements after the element that resizes, so long as they are within the sameSortableContextas the element that resizes, since it's highly likely that their layout will also shift.Specifying an empty array for
recomputeIdsforces all droppable containers to be re-measured.For consumers that were relyings on the internals of
DndContextusinguseDndContext(), thewillRecomputeLayoutsproperty has been renamed tomeasuringScheduled, and therecomputeLayoutsmethod has been renamed tomeasureDroppableContainers, and now optionally accepts an array of droppableUniqueIdentifierthat should be scheduled to be re-measured. -
#570
1ade2f3Thanks @clauderic! - Usetransitionfor the active draggable node when keyboard sorting without a<DragOverlay />.
Patch Changes
-
#566
d315df0Thanks @clauderic! - Fixed a bug where sortable item position was not updated when quickly dragging different sortable items. -
Updated dependencies [
f3ad20d,02edd26,c6c67cb,6310227,e7ac3d4,528c67e,02edd26]:- @dnd-kit/core@5.0.0
- @dnd-kit/utilities@3.1.0
5.1.0
Minor Changes
-
#486
d86529cThanks @clauderic! - Improvements to better support swappable strategies:- Now exporting an
arraySwaphelper to be used instead ofarrayMoveonDragEnd. - Added the
getNewIndexprop onuseSortable. By default,useSortableassumes that items will be moved to their new index usingarrayMove(), but this isn't always the case, especially when using strategies likerectSwappingStrategy. For those scenarios, consumers can now define custom logic that should be used to get the new index for an item on drop, for example, by computing the new order of items usingarraySwap.
- Now exporting an
Patch Changes
- Updated dependencies [
d973cc6]:- @dnd-kit/core@4.0.2
5.0.0
Major Changes
-
#427
f96cb5dThanks @clauderic! - - Using transform-agnostic measurements for the DragOverlay node.- Renamed the
overlayNodeproperty todragOverlayon theDndContextDescriptorinterface.
- Renamed the
-
9cfac05Thanks @clauderic! - Renamed thewasSortingproperty towasDraggingon theSortableContextandAnimateLayoutChangesinterfaces.
Minor Changes
- #433
c447880Thanks @clauderic! - Fix unwanted animations when items in sortable context change
Patch Changes
-
#372
dbc9601Thanks @clauderic! - RefactoredDroppableContainerstype fromRecord<UniqueIdentifier, DroppableContainerto a custom instance that extends theMapconstructor and adds a few other methods such astoArray(),getEnabled()andgetNodeFor(id).A unique
keyproperty was also added to theDraggableNodeandDroppableContainerinterfaces. This prevents potential race conditions in the mount and cleanup effects ofuseDraggableanduseDroppable. It's possible for the clean-up effect to run after another React component usinguseDraggableoruseDroppablemounts, which causes the newly mounted element to accidentally be un-registered. -
#350
a13dbb6Thanks @wmain! - Breaking change: TheCollisionDetectioninterface has been refactored. It now receives an object that contains theactivedraggable node, along with thecollisionRectand an array ofdroppableContainers.If you've built custom collision detection algorithms, you'll need to update them. Refer to this PR for examples of how to refactor collision detection functions to the new
CollisionDetectioninterface.The
sortableKeyboardCoordinatesmethod has also been updated since it relies on theclosestCornerscollision detection algorithm. If you were using collision detection strategies in a customsortableKeyboardCoordinatesmethod, you'll need to update those as well. -
86d1f27Thanks @clauderic! - Fixed a bug in thehorizontalListSortingStrategywhere it did not check if thecurrentRectwas undefined. -
e42a711Thanks @clauderic! - Fixed a bug with the default layout animation function where it could returntrueinitially even if the list had not been sorted yet. Now checking thewasDraggingproperty to ensure no layout animation occurs ifwasDraggingis false. -
#341
e02b737Thanks @clauderic! - Returnundefinedinstead ofnullfortransitioninuseSortable -
Updated dependencies [
13be602,aede2cc,05d6a78,a32a4c5,f96cb5d,dea715c,dbc9601,46ec5e4,7006464,0e628bc,c447880,2ba6dfe,8d70540,13be602,422d083,c4b21b4,5a41340,a13dbb6,e2ee0dc,1fe9b5c,1fe9b5c,1f5ca27]:- @dnd-kit/core@4.0.0
- @dnd-kit/utilities@3.0.0
4.0.0
Patch Changes
- Updated dependencies [
d39ab11]:- @dnd-kit/core@3.1.0
3.1.0
Minor Changes
68960c4#295 Thanks @akhmadullin! -@dnd-kit/coreis now apeerDependencyrather than adependencyfor other@dnd-kitpackages that depend on it, such as@dnd-kit/sortableand@dnd-kit/modifiers. This is done to avoid issues with multiple versions of@dnd-kit/corebeing installed by some package managers such as Yarn 2.
Patch Changes
3.0.1
Patch Changes
-
a178857#214 Thanks @clauderic! - Ensure that consumer defined data passed touseSortableis passed down to bothuseDraggableanduseDroppable.The
dataobject that is passed touseDraggableanduseDroppablewithinuseSortablealso contains thesortableproperty, which holds a reference to the index of the item, along with thecontainerIdand theitemsof its parentSortableContext.
3.0.0
Major Changes
-
a9d92cf#174 Thanks @clauderic! - Distributed assets now only target modern browsers. Browserlist config:defaults last 2 version not IE 11 not deadIf you need to support older browsers, include the appropriate polyfills in your project's build process.
Minor Changes
-
b7355d1#207 Thanks @clauderic! - Thedataargument foruseDraggableanduseDroppableis now exposed in event handlers and on theactiveandoverobjects.Example usage:
import {DndContext, useDraggable, useDroppable} from '@dnd-kit/core'; function Draggable() { const {attributes, listeners, setNodeRef, transform} = useDraggable({ id: 'draggable', data: { type: 'type1', }, }); /* ... */ } function Droppable() { const {setNodeRef} = useDroppable({ id: 'droppable', data: { accepts: ['type1', 'type2'], }, }); /* ... */ } function App() { return ( <DndContext onDragEnd={({active, over}) => { if (over?.data.current.accepts.includes(active.data.current.type)) { // do stuff } }} /> ); }
Patch Changes
-
fb2db94#212 Thanks @clauderic! - Allow consumers ofSortableContextto provide items of shape{id: string}[]orstring[] -
Updated dependencies [
b7355d1,a9d92cf,b406cb9]:- @dnd-kit/core@3.0.0
- @dnd-kit/utilities@2.0.0
2.0.1
Patch Changes
-
92afb0f#168 Thanks @clauderic! - Make sure that thewasSortingargument of theanimateLayoutChangesprop ofuseSortablealways receives the latest value. -
Updated dependencies [
bdb1aa2]:- @dnd-kit/core@2.1.0
2.0.0
Major Changes
-
8583825#140 Thanks @clauderic! - Auto-scrolling defaults have been updated, which should generally lead to improved user experience for most consumers.The auto-scroller now bases its calculations based on the position of the pointer rather than the edges of the draggable element's rect by default. This change is aligned with how the native HTML 5 Drag & Drop auto-scrolling behaves.
This behaviour can be customized using the
activatoroption of theautoScrollprop:import {AutoScrollActivator, DndContext} from '@dnd-kit/core'; <DndContext autoScroll={{activator: AutoScrollActivator.DraggableRect}} />;The auto-scroller now also looks at scrollable ancestors in order of appearance in the DOM tree, meaning it will first attempt to scroll the window, and narrow its focus down rather than the old behaviour of looking at scrollable ancestors in order of closeness to the draggable element in the DOM tree (reversed tree order).
This generally leads to an improved user experience, but can be customized by passing a configuration object to the
autoScrollprop that sets theorderoption toTraversalOrder.ReversedTreeOrderinstead of the new default value ofTraversalOrder.TreeOrder:import {DndContext, TraversalOrder} from '@dnd-kit/core'; <DndContext autoScroll={{order: TraversalOrder.ReversedTreeOrder}} />;The autoscrolling
thresholds,accelerationandintervalcan now also be customized using theautoScrollprop:import {DndContext} from '@dnd-kit/core'; <DndContext autoScroll={{ thresholds: { // Left and right 10% of the scroll container activate scrolling x: 0.1, // Top and bottom 25% of the scroll container activate scrolling y: 0.25, }, // Accelerate slower than the default value (10) acceleration: 5, // Auto-scroll every 10ms instead of the default value of 5ms interval: 10, }} />;Finally, consumers can now conditionally opt out of scrolling certain scrollable ancestors using the
canScrolloption of theautoScrollprop:import {DndContext} from '@dnd-kit/core'; <DndContext autoScroll={{ canScroll(element) { if (element === document.scrollingElement) { return false; } return true; }, }} />;
Patch Changes
- Updated dependencies [
8583825]:- @dnd-kit/core@2.0.0
1.1.0
Minor Changes
79f6088#144 Thanks @clauderic! - Allow consumers to determine whether to animate layout changes and when to measure nodes. Consumers can now use theanimateLayoutChangesprop ofuseSortableto determine whether layout animations should occur. Consumers can now also decide when to measure layouts, and at what frequency using thelayoutMeasuringprop ofDndContext. By default,DndContextwill measure layouts just-in-time after sorting has begun. Consumers can override this behaviour to either only measure before dragging begins (on mount and after dragging), or always (on mount, before dragging, after dragging). Pairing thelayoutMeasuringprop onDndContextand theanimateLayoutChangesprop ofuseSortableopens up a number of new possibilities for consumers, such as animating insertion and removal of items in a sortable list.
Patch Changes
1.0.2
Patch Changes
-
423610c#56 Thanks @clauderic! - Add MIT license to package.json and distributed files -
Updated dependencies [
423610c,594a24e,fd25eaf]:- @dnd-kit/core@1.0.2
- @dnd-kit/utilities@1.0.2
1.0.1
Patch Changes
-
0b343c7#52 Thanks @clauderic! - Add repository entry to package.json files -
78a7b67Thanks @clauderic! - Fix an issue with the sortable keyboard coordinate getter not excluding disabled droppables. -
Updated dependencies [
0b343c7,5194696,310bbd6]:- @dnd-kit/utilities@1.0.1
- @dnd-kit/core@1.0.1
1.0.0
Major Changes
2912350Thanks @clauderic! - Initial public release.
Patch Changes
- Updated dependencies [
2912350]:- @dnd-kit/core@1.0.0
- @dnd-kit/utilities@1.0.0
0.1.0
Minor Changes
7bd4568#30 - Initial beta release, authored by @clauderic.
Patch Changes
- Updated dependencies [
7bd4568]:- @dnd-kit/core@0.1.0
- @dnd-kit/utilities@0.1.0