several fixes

This commit is contained in:
Anton Lavrenov
2019-01-21 17:42:02 -05:00
parent 199bbbbff1
commit 7aa3c3238d
13 changed files with 229 additions and 145 deletions

View File

@@ -71,8 +71,8 @@ export const _addId = function(node: any, id) {
return;
}
// do we need this warning?
// if (this.ids[id]) {
// Util.warn(
// if (ids[id]) {
// console.warn(
// 'Duplicate id "' +
// id +
// '". Please don not use same id several times. It may break find() method look up.'
@@ -81,11 +81,16 @@ export const _addId = function(node: any, id) {
ids[id] = node;
};
// TODO: check node on remove
export const _removeId = function(id: string) {
if (id !== undefined) {
delete ids[id];
export const _removeId = function(id: string, node: any) {
// node has no id
if (!id) {
return;
}
// another node is registered (possible for duplicate ids)
if (ids[id] !== node) {
return;
}
delete ids[id];
};
export const _addName = function(node: any, name) {

View File

@@ -710,7 +710,7 @@ export abstract class Node {
*/
destroy() {
// remove from ids and names hashes
_removeId(this.id());
_removeId(this.id(), this);
// remove all names
var names = (this.name() || '').split(/\s/g);
@@ -1277,12 +1277,19 @@ export abstract class Node {
key,
val,
getter,
defaultValue;
defaultValue,
nonPlainObject;
obj.attrs = {};
for (key in attrs) {
val = attrs[key];
// if value is object and object is not plain
// like class instance, we should skip it and to not inclide
nonPlainObject = Util.isObject(val) && !Util._isPlainObject(val);
if (nonPlainObject) {
continue;
}
getter = typeof this[key] === 'function' && this[key];
// remove attr value so that we can extract the default value from the getter
delete attrs[key];
@@ -1823,7 +1830,7 @@ export abstract class Node {
setId(id) {
var oldId = this.id();
_removeId(oldId);
_removeId(oldId, this);
_addId(this, id);
this._setAttr('id', id);
return this;

View File

@@ -688,8 +688,8 @@ Factory.addGetterSetter(
/**
* get/set shadowForStrokeEnabled. Useful for performance optimization.
* You may set `shape.shadowForStrokeEnabled(false)`. In this case stroke will be no draw shadow for stroke.
* Remember if you set `shadowForStrokeEnabled = false` for non closed line - that line with have no shadow!.
* You may set `shape.shadowForStrokeEnabled(false)`. In this case stroke will no effect shadow.
* Remember if you set `shadowForStrokeEnabled = false` for non closed line - that line will have no shadow!.
* Default value is true
* @name Konva.Shape#shadowForStrokeEnabled
* @method

View File

@@ -501,7 +501,7 @@ export const Util = {
_isFunction(obj) {
return !!(obj && obj.constructor && obj.call && obj.apply);
},
_isObject(obj) {
_isPlainObject(obj) {
return !!obj && obj.constructor === Object;
},
_isArray(obj) {
@@ -782,7 +782,7 @@ export const Util = {
_merge(o1, o2) {
var retObj = this._clone(o2);
for (var key in o1) {
if (this._isObject(o1[key])) {
if (this._isPlainObject(o1[key])) {
retObj[key] = this._merge(o1[key], retObj[key]);
} else {
retObj[key] = o1[key];
@@ -810,7 +810,7 @@ export const Util = {
cloneObject<Any>(obj: Any): Any {
var retObj: any = {};
for (var key in obj) {
if (this._isObject(obj[key])) {
if (this._isPlainObject(obj[key])) {
retObj[key] = this.cloneObject(obj[key]);
} else if (this._isArray(obj[key])) {
retObj[key] = this.cloneArray(obj[key]);

View File

@@ -1,53 +1,3 @@
import * as KonvaInternals from './internals';
import * as Konva from './internals';
const Konva: any = KonvaInternals;
Konva.enableTrace = false;
Konva.traceArrMax = 100;
Konva.listenClickTap = false;
Konva.inDblClickWindow = false;
/**
* Global pixel ratio configuration. KonvaJS automatically detect pixel ratio of current device.
* But you may override such property, if you want to use your value.
* @property pixelRatio
* @default undefined
* @name pixelRatio
* @memberof Konva
* @example
* Konva.pixelRatio = 1;
*/
Konva.pixelRatio = undefined;
/**
* Drag distance property. If you start to drag a node you may want to wait until pointer is moved to some distance from start point,
* only then start dragging. Default is 3px.
* @property dragDistance
* @default 0
* @memberof Konva
* @example
* Konva.dragDistance = 10;
*/
Konva.dragDistance = 3;
/**
* Use degree values for angle properties. You may set this property to false if you want to use radiant values.
* @property angleDeg
* @default true
* @memberof Konva
* @example
* node.rotation(45); // 45 degrees
* Konva.angleDeg = false;
* node.rotation(Math.PI / 2); // PI/2 radian
*/
Konva.angleDeg = true;
/**
* Show different warnings about errors or wrong API usage
* @property showWarnings
* @default true
* @memberof Konva
* @example
* Konva.showWarnings = false;
*/
Konva.showWarnings = true;
export default KonvaInternals;
export default Konva;

View File

@@ -17,6 +17,56 @@ export { Shape } from './Shape';
export { Animation } from './Animation';
export { Tween, Easings } from './Tween';
export const enableTrace = false;
export const traceArrMax = 100;
export const listenClickTap = false;
export const inDblClickWindow = false;
/**
* Global pixel ratio configuration. KonvaJS automatically detect pixel ratio of current device.
* But you may override such property, if you want to use your value.
* @property pixelRatio
* @default undefined
* @name pixelRatio
* @memberof Konva
* @example
* Konva.pixelRatio = 1;
*/
export const pixelRatio = undefined;
/**
* Drag distance property. If you start to drag a node you may want to wait until pointer is moved to some distance from start point,
* only then start dragging. Default is 3px.
* @property dragDistance
* @default 0
* @memberof Konva
* @example
* Konva.dragDistance = 10;
*/
export const dragDistance = 3;
/**
* Use degree values for angle properties. You may set this property to false if you want to use radiant values.
* @property angleDeg
* @default true
* @memberof Konva
* @example
* node.rotation(45); // 45 degrees
* Konva.angleDeg = false;
* node.rotation(Math.PI / 2); // PI/2 radian
*/
export const angleDeg = true;
/**
* Show different warnings about errors or wrong API usage
* @property showWarnings
* @default true
* @memberof Konva
* @example
* Konva.showWarnings = false;
*/
export const showWarnings = true;
// export default KonvaInternals;
// shapes
export { Arc } from './shapes/Arc';
export { Arrow } from './shapes/Arrow';