forked from SparkDevNetwork/Rock
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdragdrop.ts
More file actions
59 lines (51 loc) · 1.71 KB
/
dragdrop.ts
File metadata and controls
59 lines (51 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import EditorDragDrop from "editorjs-drag-drop";
import EditorJS from "@editorjs/editorjs";
/**
* Custom subclass that fixes a bug with drag/drop when only one block.
*/
export class DragDrop extends EditorDragDrop {
constructor(editor: EditorJS) {
super(editor);
this.setDragEndListener();
}
/**
* Sets the drag end events listener. This clears our drag operation
* so we don't fire during an external drag even (like an image being
* dragged into the editor).
*/
protected setDragEndListener() {
if (!this.readOnly) {
const settingsButton = this.holder.querySelector('.ce-toolbar__settings-btn');
settingsButton!.setAttribute('draggable', 'true');
settingsButton!.addEventListener('dragend', () => {
this.startBlock = null;
});
}
}
/**
* Gets the real drop target element.
*
* @param target The target of the drop operation.
* @returns The real drop target or null if invalid.
*/
protected getDropTarget(target: HTMLElement) {
const block = super.getDropTarget(target);
/* Bug in editor.js when trying to move block when there is only one
* block. */
if (block !== null && super.getTargetPosition(block) === this.startBlock) {
return null;
}
return block;
}
/**
* Moves the dragged element to the drop position.
*
* @see {@link https://editorjs.io/blocks#move}
*/
protected moveBlocks() {
/* Ensure this drop operation is happening for our drag operation. */
if (this.startBlock != null && this.endBlock != null) {
super.moveBlocks();
}
}
}