mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 06:31:15 +08:00
Merge 0a5c510ade
into 066fec0248
This commit is contained in:
commit
8877bf9db5
57
konva.js
57
konva.js
@ -2435,14 +2435,28 @@
|
||||
});
|
||||
},
|
||||
};
|
||||
const registerDragAndDropListenersForWindowGlobal = (windowGlobal) => {
|
||||
if (Konva$2.isBrowser) {
|
||||
window.addEventListener('mouseup', DD._endDragBefore, true);
|
||||
window.addEventListener('touchend', DD._endDragBefore, true);
|
||||
window.addEventListener('mousemove', DD._drag);
|
||||
window.addEventListener('touchmove', DD._drag);
|
||||
window.addEventListener('mouseup', DD._endDragAfter, false);
|
||||
window.addEventListener('touchend', DD._endDragAfter, false);
|
||||
windowGlobal.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);
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
|
||||
// CONSTANTS
|
||||
var ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER$1 = 'mouseenter', MOUSELEAVE$1 = 'mouseleave', SET = 'set', SHAPE = 'Shape', SPACE$1 = ' ', STAGE$1 = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR$1 = [
|
||||
@ -5938,6 +5952,7 @@
|
||||
checkNoClip(this.attrs);
|
||||
});
|
||||
this._checkVisibility();
|
||||
registerDragAndDropListenersForWindowGlobal(this.getWindowGlobal());
|
||||
}
|
||||
_validateAdd(child) {
|
||||
const isLayer = child.getType() === 'Layer';
|
||||
@ -6056,6 +6071,10 @@
|
||||
getContent() {
|
||||
return this.content;
|
||||
}
|
||||
getWindowGlobal() {
|
||||
var _a;
|
||||
return (_a = this.attrs.windowGlobal) !== null && _a !== void 0 ? _a : window;
|
||||
}
|
||||
_toKonvaCanvas(config) {
|
||||
config = config || {};
|
||||
config.x = config.x || 0;
|
||||
@ -15134,11 +15153,12 @@
|
||||
var hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
|
||||
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;
|
||||
var ap = e.target.getAbsolutePosition();
|
||||
@ -15338,13 +15358,14 @@
|
||||
_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) {
|
||||
this._nodes.forEach((target) => {
|
||||
@ -15627,8 +15648,8 @@
|
||||
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
|
||||
|
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 = {
|
||||
},
|
||||
};
|
||||
|
||||
export const registerDragAndDropListenersForWindowGlobal = (windowGlobal: Window) => {
|
||||
if (Konva.isBrowser) {
|
||||
window.addEventListener('mouseup', DD._endDragBefore, true);
|
||||
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);
|
||||
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