From 8a14cb881703822edd9e1210f83b65fbe22f8d91 Mon Sep 17 00:00:00 2001 From: raj Date: Fri, 10 Oct 2025 23:29:24 -0400 Subject: [PATCH] add setWindow method to Stage objects to facilitate popout window compatibility --- src/DragAndDrop.ts | 24 +++++++++++++----------- src/Stage.ts | 6 ++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/DragAndDrop.ts b/src/DragAndDrop.ts index 3eeb9a129..7f02b4b85 100644 --- a/src/DragAndDrop.ts +++ b/src/DragAndDrop.ts @@ -156,18 +156,20 @@ export const DD = { } }); }, -}; + _attachListeners: function (targetWindow: Window) { + targetWindow.addEventListener('mouseup', DD._endDragBefore, true); + targetWindow.addEventListener('touchend', DD._endDragBefore, true); + targetWindow.addEventListener('touchcancel', DD._endDragBefore, true); -if (Konva.isBrowser) { - window.addEventListener('mouseup', DD._endDragBefore, true); - window.addEventListener('touchend', DD._endDragBefore, true); - // add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843 - window.addEventListener('touchcancel', DD._endDragBefore, true); + targetWindow.addEventListener('mousemove', DD._drag); + targetWindow.addEventListener('touchmove', DD._drag); - window.addEventListener('mousemove', DD._drag); - window.addEventListener('touchmove', DD._drag); + targetWindow.addEventListener('mouseup', DD._endDragAfter, false); + targetWindow.addEventListener('touchend', DD._endDragAfter, false); + targetWindow.addEventListener('touchcancel', DD._endDragAfter, false); + }, +}; - window.addEventListener('mouseup', DD._endDragAfter, false); - window.addEventListener('touchend', DD._endDragAfter, false); - window.addEventListener('touchcancel', DD._endDragAfter, false); +if (Konva.isBrowser) { + DD._attachListeners(window); } diff --git a/src/Stage.ts b/src/Stage.ts index 9ba1d87ed..89328121a 100644 --- a/src/Stage.ts +++ b/src/Stage.ts @@ -241,6 +241,12 @@ export class Stage extends Container { } return this; } + setWindow(win){ + if (win) { + DD._attachListeners(win); + } + return this; + } shouldDrawHit() { return true; }