mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 02:27:53 +08:00
Merge 0a5c510ade
into 066fec0248
This commit is contained in:
commit
8877bf9db5
2
konva.min.js
vendored
2
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -157,13 +157,26 @@ export const DD = {
|
||||
},
|
||||
};
|
||||
|
||||
if (Konva.isBrowser) {
|
||||
window.addEventListener('mouseup', DD._endDragBefore, true);
|
||||
window.addEventListener('touchend', DD._endDragBefore, true);
|
||||
export const registerDragAndDropListenersForWindowGlobal = (windowGlobal: Window) => {
|
||||
if (Konva.isBrowser) {
|
||||
(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);
|
||||
window.addEventListener('touchmove', DD._drag);
|
||||
|
||||
window.addEventListener('mouseup', DD._endDragAfter, false);
|
||||
window.addEventListener('touchend', DD._endDragAfter, false);
|
||||
// Go ahead and actually set up the listeners.
|
||||
windowGlobal.addEventListener('mouseup', DD._endDragBefore, true);
|
||||
windowGlobal.addEventListener('touchend', DD._endDragBefore, true);
|
||||
windowGlobal.addEventListener('mousemove', DD._drag);
|
||||
windowGlobal.addEventListener('touchmove', DD._drag);
|
||||
windowGlobal.addEventListener('mouseup', DD._endDragAfter, false);
|
||||
windowGlobal.addEventListener('touchend', DD._endDragAfter, false);
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,13 @@ import { SceneCanvas, HitCanvas } from './Canvas';
|
||||
import { GetSet, Vector2d } from './types';
|
||||
import { Shape } from './Shape';
|
||||
import { Layer } from './Layer';
|
||||
import { DD } from './DragAndDrop';
|
||||
import { DD, registerDragAndDropListenersForWindowGlobal } from './DragAndDrop';
|
||||
import { _registerNode } from './Global';
|
||||
import * as PointerEvents from './PointerEvents';
|
||||
|
||||
export interface StageConfig extends ContainerConfig {
|
||||
container: HTMLDivElement | string;
|
||||
windowGlobal?: Window;
|
||||
}
|
||||
|
||||
// CONSTANTS
|
||||
@ -188,6 +189,7 @@ export class Stage extends Container<Layer> {
|
||||
}
|
||||
);
|
||||
this._checkVisibility();
|
||||
registerDragAndDropListenersForWindowGlobal(this.getWindowGlobal());
|
||||
}
|
||||
|
||||
_validateAdd(child) {
|
||||
@ -314,6 +316,9 @@ export class Stage extends Container<Layer> {
|
||||
getContent() {
|
||||
return this.content;
|
||||
}
|
||||
getWindowGlobal() {
|
||||
return this.attrs.windowGlobal ?? window;
|
||||
}
|
||||
_toKonvaCanvas(config) {
|
||||
config = config || {};
|
||||
|
||||
|
@ -635,11 +635,12 @@ export class Transformer extends Group {
|
||||
this.sin = Math.abs(height / hypotenuse);
|
||||
this.cos = Math.abs(width / hypotenuse);
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('mousemove', this._handleMouseMove);
|
||||
window.addEventListener('touchmove', this._handleMouseMove);
|
||||
window.addEventListener('mouseup', this._handleMouseUp, true);
|
||||
window.addEventListener('touchend', this._handleMouseUp, true);
|
||||
const windowGlobal = e.target.getStage().getWindowGlobal();
|
||||
if (typeof windowGlobal !== 'undefined') {
|
||||
windowGlobal.addEventListener('mousemove', this._handleMouseMove);
|
||||
windowGlobal.addEventListener('touchmove', this._handleMouseMove);
|
||||
windowGlobal.addEventListener('mouseup', this._handleMouseUp, true);
|
||||
windowGlobal.addEventListener('touchend', this._handleMouseUp, true);
|
||||
}
|
||||
|
||||
this._transforming = true;
|
||||
@ -895,13 +896,14 @@ export class Transformer extends Group {
|
||||
_removeEvents(e?) {
|
||||
if (this._transforming) {
|
||||
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();
|
||||
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 });
|
||||
|
||||
if (node) {
|
||||
@ -1209,8 +1211,8 @@ export class Transformer extends Group {
|
||||
this.getStage().content && (this.getStage().content.style.cursor = '');
|
||||
}
|
||||
Group.prototype.destroy.call(this);
|
||||
this.detach();
|
||||
this._removeEvents();
|
||||
this.detach();
|
||||
return this;
|
||||
}
|
||||
// do not work as a container
|
||||
|
Loading…
Reference in New Issue
Block a user