Skip to content

Commit

Permalink
feat: add override internal drop function api #643
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Jun 8, 2024
1 parent 3f5ddbb commit ec7e076
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/en/guide/override.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ Usage:
```javascript
instance.override.copy = () => void
```

## drop

Feature: Override internal drop function

Usage:

```javascript
instance.override.drop = (evt: DragEvent) => void
```
10 changes: 10 additions & 0 deletions docs/guide/override.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ instance.override.paste = (evt?: ClipboardEvent) => void
```javascript
instance.override.copy = () => void
```

## drop

功能:重写拖放方法

用法:

```javascript
instance.override.drop = (evt: DragEvent) => void
```
7 changes: 7 additions & 0 deletions src/editor/core/event/handlers/drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { CanvasEvent } from '../CanvasEvent'
import { pasteImage } from './paste'

export function drop(evt: DragEvent, host: CanvasEvent) {
const draw = host.getDraw()
// 自定义拖放事件
const { drop } = draw.getOverride()
if (drop) {
drop(evt)
return
}
evt.preventDefault()
const data = evt.dataTransfer?.getData('text')
if (data) {
Expand Down
1 change: 1 addition & 0 deletions src/editor/core/override/Override.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class Override {
public paste: ((evt?: ClipboardEvent) => void) | undefined
public copy: (() => void) | undefined
public drop: ((evt: DragEvent) => void) | undefined
}

0 comments on commit ec7e076

Please sign in to comment.