1
0
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:
Bryan Haakman 2021-12-08 18:56:11 +01:00 committed by GitHub
parent dc2999a1aa
commit 1217021a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 9 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': patch
---
Add origin event type to setFragmentData to be able to distinguish copy, cut and drag

View File

@ -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`.

View File

@ -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) {

View File

@ -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]

View File

@ -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)
},
/**