From 1a74bbb0fbb8949a3aa26b9ccebe4bd3808666af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 18 Mar 2021 13:54:48 +0100 Subject: [PATCH] improve node view handling with inputs, fix #211 --- packages/core/src/NodeView.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/core/src/NodeView.ts b/packages/core/src/NodeView.ts index 9ec74b52..d0308685 100644 --- a/packages/core/src/NodeView.ts +++ b/packages/core/src/NodeView.ts @@ -88,11 +88,18 @@ export class NodeView impleme const target = (event.target as HTMLElement) const isInElement = this.dom.contains(target) && !this.contentDOM?.contains(target) - // ignore all events from child nodes + // any event from child nodes should be handled by ProseMirror if (!isInElement) { return false } + const isInput = ['INPUT', 'BUTTON', 'SELECT', 'TEXTAREA'].includes(target.tagName) + + // any input event within node views should be ignored by ProseMirror + if (isInput) { + return true + } + const { isEditable } = this.editor const { isDragging } = this const isDraggable = !!this.node.type.spec.draggable @@ -123,9 +130,14 @@ export class NodeView impleme if (isValidDragHandle) { this.isDragging = true + document.addEventListener('dragend', () => { this.isDragging = false }, { once: true }) + + document.addEventListener('mouseup', () => { + this.isDragging = false + }, { once: true }) } }