Repository navigation
v1.4.0
Minor Changes
-
298e972: Drag-and-drop through the paste pipeline.
-
New: drops are pastes. A dropped file or text selection goes through the same
acceptlist,maxBytes/maxItemslimits and image byte-checks as a paste, and resolves withresult.source === 'drop'. Dropped image files arrive inresult.imageFileswith their names. -
New:
PasteField.Zoneaccepts drops by default. It setsdata-drag-overwhile an accepted drag is over it and announcesmessages.dropped("Dropped content added"). If you override onlypasted, for example to translate it, that message is used for drops too. Passdroppable={false}to keep the 1.3 behaviour. Your ownonDragEnter/onDragOver/onDragLeave/onDrophandlers run first, and callingpreventDefault()in one takes over. -
New in
usePaste:dropTargetProps: spread it onto one element.isDragOver.dropEvent.
Drops are kept separate from
targetProps, so a textarea that only spreadstargetPropskeeps its native text drop. -
New in core:
machine.dropEvent(event).canAcceptDrag(dataTransfer, options): decides from the item kinds and types a browser exposes while dragging. A file whose type is hidden until the drop counts as a maybe.- The
PasteDropEventLike,DataTransferItemLikeandPasteDropTargetPropstypes.
-
Safe in real browsers:
- Every
dragoveron the target is claimed. Drags the field doesn't accept getdropEffect: 'none', so a rejected file is cancelled instead of being opened in place of your page. - Drags aimed at an
<input>,<textarea>or editable region nested inside the target keep their native behaviour. Inside a target that is itself editable, every drop is still checked againstacceptand the limits. - The drop effect respects the source's
effectAllowed. - The drag-over state clears on any drop or
dragend, and when the pointer leaves for an element outside the target, so it can't get stuck.
- Every
-
New:
describePasteError(error, source?). Passstate.sourceto word drop failures as drops ("The dropped content is too large.").messages.errorreceives the source as its second argument. -
Changed: the developer-facing
no-contentmessage now says "content" instead of "clipboard", since it covers drops too. -
Docs: the README already said
PasteField.Zoneaccepts drops, which wasn't true until this release. -
Tests: 459 at 100% coverage, with drag behaviour also checked in Chromium against the docs site.
-
Size (brotli):
Bundle 1.4.0 1.3.0 usePaste4.29 kB 3.79 kB PasteField7.03 kB 6.37 kB core 6.05 kB 5.86 kB useCopy,CopyField+CopyGroup, captureunchanged
Heads-up for TypeScript users. Everything is additive, but:
- Exhaustive switches on the source.
PasteSourcegains'drop', so an exhaustiveswitchoverresult.sourceorstate.sourceneeds the new case. - Hand-built objects. If you build these types by hand, for example in test mocks, add the new members:
UsePasteResult(and soPasteFieldContextValue) gainsdropEvent,dropTargetPropsandisDragOver.PasteMachinegainsdropEvent.
- Messages.
PasteFieldMessagesgains an optionaldropped.errormay receive a secondsourceargument, and existing one-argument functions still fit.
-