some type fixes. close #869

This commit is contained in:
Anton Lavrenov 2020-03-29 07:45:24 -05:00
parent fe9501a5f0
commit 010729dc19
5 changed files with 31 additions and 53 deletions

View File

@ -8,7 +8,7 @@
* Konva JavaScript Framework v4.2.2 * Konva JavaScript Framework v4.2.2
* http://konvajs.org/ * http://konvajs.org/
* Licensed under the MIT * Licensed under the MIT
* Date: Thu Mar 26 2020 * Date: Sun Mar 29 2020
* *
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@ -5371,17 +5371,6 @@
} }
return obj; return obj;
}; };
Container.prototype._getDescendants = function (arr) {
var retArr = [];
var len = arr.length;
for (var n = 0; n < len; n++) {
var node = arr[n];
if (this.isAncestorOf(node)) {
retArr.push(node);
}
}
return retArr;
};
/** /**
* determine if node is an ancestor * determine if node is an ancestor
* of descendant * of descendant
@ -5524,10 +5513,10 @@
var dragSkip = !Konva.hitOnDragEnabled && layerUnderDrag; var dragSkip = !Konva.hitOnDragEnabled && layerUnderDrag;
return layer && layer.hitGraphEnabled() && this.isVisible() && !dragSkip; return layer && layer.hitGraphEnabled() && this.isVisible() && !dragSkip;
}; };
Container.prototype.getClientRect = function (attrs) { Container.prototype.getClientRect = function (config) {
attrs = attrs || {}; config = config || {};
var skipTransform = attrs.skipTransform; var skipTransform = config.skipTransform;
var relativeTo = attrs.relativeTo; var relativeTo = config.relativeTo;
var minX, minY, maxX, maxY; var minX, minY, maxX, maxY;
var selfRect = { var selfRect = {
x: Infinity, x: Infinity,
@ -5543,8 +5532,8 @@
} }
var rect = child.getClientRect({ var rect = child.getClientRect({
relativeTo: that, relativeTo: that,
skipShadow: attrs.skipShadow, skipShadow: config.skipShadow,
skipStroke: attrs.skipStroke skipStroke: config.skipStroke
}); });
// skip invisible children (like empty groups) // skip invisible children (like empty groups)
if (rect.width === 0 && rect.height === 0) { if (rect.width === 0 && rect.height === 0) {

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -187,7 +187,7 @@ export abstract class Container<ChildType extends Node> extends Node<
* return node.getType() === 'Node' && node.getAbsoluteOpacity() < 1; * return node.getType() === 'Node' && node.getAbsoluteOpacity() < 1;
* }); * });
*/ */
find<ChildNode extends Node = Node>(selector): Collection<ChildNode> { find<ChildNode extends Node = Node>(selector): Collection<Node> {
// protecting _generalFind to prevent user from accidentally adding // protecting _generalFind to prevent user from accidentally adding
// second argument and getting unexpected `findOne` result // second argument and getting unexpected `findOne` result
return this._generalFind<ChildNode>(selector, false); return this._generalFind<ChildNode>(selector, false);
@ -217,12 +217,15 @@ export abstract class Container<ChildType extends Node> extends Node<
* return node.getType() === 'Shape' * return node.getType() === 'Shape'
* }) * })
*/ */
findOne<ChildNode extends Node = Node>(selector): ChildNode { findOne<ChildNode extends Node = Node>(selector: string | Function): Node {
var result = this._generalFind<ChildNode>(selector, true); var result = this._generalFind<ChildNode>(selector, true);
return result.length > 0 ? result[0] : undefined; return result.length > 0 ? result[0] : undefined;
} }
_generalFind<ChildNode extends Node = Node>(selector, findOne) { _generalFind<ChildNode extends Node = Node>(
var retArr: Array<ChildNode> = []; selector: string | Function,
findOne: boolean
) {
var retArr: Array<Node> = [];
this._descendants(node => { this._descendants(node => {
const valid = node._isMatch(selector); const valid = node._isMatch(selector);
@ -237,7 +240,7 @@ export abstract class Container<ChildType extends Node> extends Node<
return Collection.toCollection(retArr); return Collection.toCollection(retArr);
} }
private _descendants(fn) { private _descendants(fn: (n: Node) => boolean) {
let shouldStop = false; let shouldStop = false;
for (var i = 0; i < this.children.length; i++) { for (var i = 0; i < this.children.length; i++) {
const child = this.children[i]; const child = this.children[i];
@ -270,18 +273,6 @@ export abstract class Container<ChildType extends Node> extends Node<
return obj; return obj;
} }
_getDescendants(arr) {
var retArr = [];
var len = arr.length;
for (var n = 0; n < len; n++) {
var node = arr[n];
if (this.isAncestorOf(node)) {
retArr.push(node);
}
}
return retArr;
}
/** /**
* determine if node is an ancestor * determine if node is an ancestor
* of descendant * of descendant
@ -289,7 +280,7 @@ export abstract class Container<ChildType extends Node> extends Node<
* @name Konva.Container#isAncestorOf * @name Konva.Container#isAncestorOf
* @param {Konva.Node} node * @param {Konva.Node} node
*/ */
isAncestorOf(node) { isAncestorOf(node: Node) {
var parent = node.getParent(); var parent = node.getParent();
while (parent) { while (parent) {
if (parent._id === this._id) { if (parent._id === this._id) {
@ -300,7 +291,7 @@ export abstract class Container<ChildType extends Node> extends Node<
return false; return false;
} }
clone(obj?) { clone(obj?: any) {
// call super method // call super method
var node = Node.prototype.clone.call(this, obj); var node = Node.prototype.clone.call(this, obj);
@ -455,10 +446,15 @@ export abstract class Container<ChildType extends Node> extends Node<
var dragSkip = !Konva.hitOnDragEnabled && layerUnderDrag; var dragSkip = !Konva.hitOnDragEnabled && layerUnderDrag;
return layer && layer.hitGraphEnabled() && this.isVisible() && !dragSkip; return layer && layer.hitGraphEnabled() && this.isVisible() && !dragSkip;
} }
getClientRect(attrs): IRect { getClientRect(config?: {
attrs = attrs || {}; skipTransform?: boolean;
var skipTransform = attrs.skipTransform; skipShadow?: boolean;
var relativeTo = attrs.relativeTo; skipStroke?: boolean;
relativeTo?: Container<Node>;
}): IRect {
config = config || {};
var skipTransform = config.skipTransform;
var relativeTo = config.relativeTo;
var minX, minY, maxX, maxY; var minX, minY, maxX, maxY;
var selfRect = { var selfRect = {
@ -476,8 +472,8 @@ export abstract class Container<ChildType extends Node> extends Node<
var rect = child.getClientRect({ var rect = child.getClientRect({
relativeTo: that, relativeTo: that,
skipShadow: attrs.skipShadow, skipShadow: config.skipShadow,
skipStroke: attrs.skipStroke skipStroke: config.skipStroke
}); });
// skip invisible children (like empty groups) // skip invisible children (like empty groups)

View File

@ -2247,12 +2247,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
!stopBubble !stopBubble
) { ) {
if (compareShape && compareShape.parent) { if (compareShape && compareShape.parent) {
this._fireAndBubble.call( this._fireAndBubble.call(this.parent, eventType, evt, compareShape);
this.parent,
eventType,
evt,
compareShape
);
} else { } else {
this._fireAndBubble.call(this.parent, eventType, evt); this._fireAndBubble.call(this.parent, eventType, evt);
} }

View File

@ -1,6 +1,4 @@
suite('Collection', function() { suite('Collection', function() {
var util;
test('test collection method mapping', function() { test('test collection method mapping', function() {
// Node method // Node method
assert.notEqual(Konva.Collection.prototype.on, undefined); assert.notEqual(Konva.Collection.prototype.on, undefined);