mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-01-18 05:59:13 +01:00
Add origin event type to setFragmentData to be able to distinguish copy, cut and drag (#4720)
* Add origin event to setFragmentData to be able to distinguish copy, cut, drag * fix lint * add changeset * Make originEvent optional
This commit is contained in:
parent
dc2999a1aa
commit
1217021a9a
5
.changeset/brave-emus-refuse.md
Normal file
5
.changeset/brave-emus-refuse.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate-react': patch
|
||||
---
|
||||
|
||||
Add origin event type to setFragmentData to be able to distinguish copy, cut and drag
|
@ -148,7 +148,7 @@ Insert fragment data from a `DataTransfer` into the editor. Returns true if some
|
||||
|
||||
Insert text data from a `DataTransfer` into the editor. Returns true if some content has been effectively inserted.
|
||||
|
||||
### `setFragmentData(editor: ReactEditor, data: DataTransfer)`
|
||||
### `setFragmentData(editor: ReactEditor, data: DataTransfer, originEvent?: 'drag' | 'copy' | 'cut')`
|
||||
|
||||
Sets data from the currently selected fragment on a `DataTransfer`.
|
||||
|
||||
|
@ -340,7 +340,7 @@ export const AndroidEditable = (props: EditableProps): JSX.Element => {
|
||||
!isEventHandled(event, attributes.onCopy)
|
||||
) {
|
||||
event.preventDefault()
|
||||
ReactEditor.setFragmentData(editor, event.clipboardData)
|
||||
ReactEditor.setFragmentData(editor, event.clipboardData, 'copy')
|
||||
}
|
||||
},
|
||||
[attributes.onCopy]
|
||||
@ -353,7 +353,7 @@ export const AndroidEditable = (props: EditableProps): JSX.Element => {
|
||||
!isEventHandled(event, attributes.onCut)
|
||||
) {
|
||||
event.preventDefault()
|
||||
ReactEditor.setFragmentData(editor, event.clipboardData)
|
||||
ReactEditor.setFragmentData(editor, event.clipboardData, 'cut')
|
||||
const { selection } = editor
|
||||
|
||||
if (selection) {
|
||||
|
@ -867,7 +867,7 @@ export const Editable = (props: EditableProps) => {
|
||||
!isEventHandled(event, attributes.onCopy)
|
||||
) {
|
||||
event.preventDefault()
|
||||
ReactEditor.setFragmentData(editor, event.clipboardData)
|
||||
ReactEditor.setFragmentData(editor, event.clipboardData, 'copy')
|
||||
}
|
||||
},
|
||||
[attributes.onCopy]
|
||||
@ -880,7 +880,7 @@ export const Editable = (props: EditableProps) => {
|
||||
!isEventHandled(event, attributes.onCut)
|
||||
) {
|
||||
event.preventDefault()
|
||||
ReactEditor.setFragmentData(editor, event.clipboardData)
|
||||
ReactEditor.setFragmentData(editor, event.clipboardData, 'cut')
|
||||
const { selection } = editor
|
||||
|
||||
if (selection) {
|
||||
@ -937,7 +937,7 @@ export const Editable = (props: EditableProps) => {
|
||||
|
||||
state.isDraggingInternally = true
|
||||
|
||||
ReactEditor.setFragmentData(editor, event.dataTransfer)
|
||||
ReactEditor.setFragmentData(editor, event.dataTransfer, 'drag')
|
||||
}
|
||||
},
|
||||
[readOnly, attributes.onDragStart]
|
||||
|
@ -34,7 +34,10 @@ export interface ReactEditor extends BaseEditor {
|
||||
insertData: (data: DataTransfer) => void
|
||||
insertFragmentData: (data: DataTransfer) => boolean
|
||||
insertTextData: (data: DataTransfer) => boolean
|
||||
setFragmentData: (data: DataTransfer) => void
|
||||
setFragmentData: (
|
||||
data: DataTransfer,
|
||||
originEvent?: 'drag' | 'copy' | 'cut'
|
||||
) => void
|
||||
hasRange: (editor: ReactEditor, range: Range) => boolean
|
||||
}
|
||||
|
||||
@ -253,8 +256,12 @@ export const ReactEditor = {
|
||||
* Sets data from the currently selected fragment on a `DataTransfer`.
|
||||
*/
|
||||
|
||||
setFragmentData(editor: ReactEditor, data: DataTransfer): void {
|
||||
editor.setFragmentData(data)
|
||||
setFragmentData(
|
||||
editor: ReactEditor,
|
||||
data: DataTransfer,
|
||||
originEvent?: 'drag' | 'copy' | 'cut'
|
||||
): void {
|
||||
editor.setFragmentData(data, originEvent)
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user