This commit is contained in:
loc 2022-12-14 18:32:16 -08:00 committed by GitHub
commit 8877bf9db5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1500 additions and 1459 deletions

2895
konva.js

File diff suppressed because it is too large Load Diff

2
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -157,13 +157,26 @@ export const DD = {
}, },
}; };
if (Konva.isBrowser) { export const registerDragAndDropListenersForWindowGlobal = (windowGlobal: Window) => {
window.addEventListener('mouseup', DD._endDragBefore, true); if (Konva.isBrowser) {
window.addEventListener('touchend', DD._endDragBefore, true); (windowGlobal as any).console.log('registering events');
// Remove them all first in case this is a duplicate call with the same
// windowGlobal. If this is the first call, this will be a noop. This is to
// avoid a situation where we're storing multiple Window handles and
// possibly introducing a memory leak.
windowGlobal.removeEventListener('mouseup', DD._endDragBefore, true);
windowGlobal.removeEventListener('touchend', DD._endDragBefore, true);
windowGlobal.removeEventListener('mousemove', DD._drag);
windowGlobal.removeEventListener('touchmove', DD._drag);
windowGlobal.removeEventListener('mouseup', DD._endDragAfter, false);
windowGlobal.removeEventListener('touchend', DD._endDragAfter, false);
window.addEventListener('mousemove', DD._drag); // Go ahead and actually set up the listeners.
window.addEventListener('touchmove', DD._drag); windowGlobal.addEventListener('mouseup', DD._endDragBefore, true);
windowGlobal.addEventListener('touchend', DD._endDragBefore, true);
window.addEventListener('mouseup', DD._endDragAfter, false); windowGlobal.addEventListener('mousemove', DD._drag);
window.addEventListener('touchend', DD._endDragAfter, false); windowGlobal.addEventListener('touchmove', DD._drag);
windowGlobal.addEventListener('mouseup', DD._endDragAfter, false);
windowGlobal.addEventListener('touchend', DD._endDragAfter, false);
}
} }

View File

@ -6,12 +6,13 @@ import { SceneCanvas, HitCanvas } from './Canvas';
import { GetSet, Vector2d } from './types'; import { GetSet, Vector2d } from './types';
import { Shape } from './Shape'; import { Shape } from './Shape';
import { Layer } from './Layer'; import { Layer } from './Layer';
import { DD } from './DragAndDrop'; import { DD, registerDragAndDropListenersForWindowGlobal } from './DragAndDrop';
import { _registerNode } from './Global'; import { _registerNode } from './Global';
import * as PointerEvents from './PointerEvents'; import * as PointerEvents from './PointerEvents';
export interface StageConfig extends ContainerConfig { export interface StageConfig extends ContainerConfig {
container: HTMLDivElement | string; container: HTMLDivElement | string;
windowGlobal?: Window;
} }
// CONSTANTS // CONSTANTS
@ -188,6 +189,7 @@ export class Stage extends Container<Layer> {
} }
); );
this._checkVisibility(); this._checkVisibility();
registerDragAndDropListenersForWindowGlobal(this.getWindowGlobal());
} }
_validateAdd(child) { _validateAdd(child) {
@ -314,6 +316,9 @@ export class Stage extends Container<Layer> {
getContent() { getContent() {
return this.content; return this.content;
} }
getWindowGlobal() {
return this.attrs.windowGlobal ?? window;
}
_toKonvaCanvas(config) { _toKonvaCanvas(config) {
config = config || {}; config = config || {};

View File

@ -635,11 +635,12 @@ export class Transformer extends Group {
this.sin = Math.abs(height / hypotenuse); this.sin = Math.abs(height / hypotenuse);
this.cos = Math.abs(width / hypotenuse); this.cos = Math.abs(width / hypotenuse);
if (typeof window !== 'undefined') { const windowGlobal = e.target.getStage().getWindowGlobal();
window.addEventListener('mousemove', this._handleMouseMove); if (typeof windowGlobal !== 'undefined') {
window.addEventListener('touchmove', this._handleMouseMove); windowGlobal.addEventListener('mousemove', this._handleMouseMove);
window.addEventListener('mouseup', this._handleMouseUp, true); windowGlobal.addEventListener('touchmove', this._handleMouseMove);
window.addEventListener('touchend', this._handleMouseUp, true); windowGlobal.addEventListener('mouseup', this._handleMouseUp, true);
windowGlobal.addEventListener('touchend', this._handleMouseUp, true);
} }
this._transforming = true; this._transforming = true;
@ -895,13 +896,14 @@ export class Transformer extends Group {
_removeEvents(e?) { _removeEvents(e?) {
if (this._transforming) { if (this._transforming) {
this._transforming = false; this._transforming = false;
if (typeof window !== 'undefined') {
window.removeEventListener('mousemove', this._handleMouseMove);
window.removeEventListener('touchmove', this._handleMouseMove);
window.removeEventListener('mouseup', this._handleMouseUp, true);
window.removeEventListener('touchend', this._handleMouseUp, true);
}
var node = this.getNode(); var node = this.getNode();
const windowGlobal = node.getStage().getWindowGlobal();
if (typeof windowGlobal !== 'undefined') {
windowGlobal.removeEventListener('mousemove', this._handleMouseMove);
windowGlobal.removeEventListener('touchmove', this._handleMouseMove);
windowGlobal.removeEventListener('mouseup', this._handleMouseUp, true);
windowGlobal.removeEventListener('touchend', this._handleMouseUp, true);
}
this._fire('transformend', { evt: e, target: node }); this._fire('transformend', { evt: e, target: node });
if (node) { if (node) {
@ -1209,8 +1211,8 @@ export class Transformer extends Group {
this.getStage().content && (this.getStage().content.style.cursor = ''); this.getStage().content && (this.getStage().content.style.cursor = '');
} }
Group.prototype.destroy.call(this); Group.prototype.destroy.call(this);
this.detach();
this._removeEvents(); this._removeEvents();
this.detach();
return this; return this;
} }
// do not work as a container // do not work as a container