Automatic validations for many attributes. close #436

This commit is contained in:
Anton Lavrenov
2018-08-21 15:56:04 +07:00
parent 973e7932e4
commit 738cc8b79c
41 changed files with 1289 additions and 226 deletions

View File

@@ -2049,7 +2049,12 @@
* });
*/
Konva.Factory.addGetterSetter(Konva.Node, 'x', 0);
Konva.Factory.addGetterSetter(
Konva.Node,
'x',
0,
Konva.Validators.getNumberValidator()
);
/**
* get/set x position
@@ -2066,7 +2071,12 @@
* node.x(5);
*/
Konva.Factory.addGetterSetter(Konva.Node, 'y', 0);
Konva.Factory.addGetterSetter(
Konva.Node,
'y',
0,
Konva.Validators.getNumberValidator()
);
/**
* get/set y position
@@ -2086,7 +2096,8 @@
Konva.Factory.addGetterSetter(
Konva.Node,
'globalCompositeOperation',
'source-over'
'source-over',
Konva.Validators.getStringValidator()
);
/**
@@ -2103,7 +2114,12 @@
* // set globalCompositeOperation
* shape.globalCompositeOperation('source-in');
*/
Konva.Factory.addGetterSetter(Konva.Node, 'opacity', 1);
Konva.Factory.addGetterSetter(
Konva.Node,
'opacity',
1,
Konva.Validators.getNumberValidator()
);
/**
* get/set opacity. Opacity values range from 0 to 1.
@@ -2161,7 +2177,12 @@
* node.id('foo');
*/
Konva.Factory.addGetterSetter(Konva.Node, 'rotation', 0);
Konva.Factory.addGetterSetter(
Konva.Node,
'rotation',
0,
Konva.Validators.getNumberValidator()
);
/**
* get/set rotation in degrees
@@ -2200,7 +2221,12 @@
* });
*/
Konva.Factory.addGetterSetter(Konva.Node, 'scaleX', 1);
Konva.Factory.addGetterSetter(
Konva.Node,
'scaleX',
1,
Konva.Validators.getNumberValidator()
);
/**
* get/set scale x
@@ -2217,7 +2243,12 @@
* node.scaleX(2);
*/
Konva.Factory.addGetterSetter(Konva.Node, 'scaleY', 1);
Konva.Factory.addGetterSetter(
Konva.Node,
'scaleY',
1,
Konva.Validators.getNumberValidator()
);
/**
* get/set scale y
@@ -2256,7 +2287,12 @@
* });
*/
Konva.Factory.addGetterSetter(Konva.Node, 'skewX', 0);
Konva.Factory.addGetterSetter(
Konva.Node,
'skewX',
0,
Konva.Validators.getNumberValidator()
);
/**
* get/set skew x
@@ -2273,7 +2309,12 @@
* node.skewX(3);
*/
Konva.Factory.addGetterSetter(Konva.Node, 'skewY', 0);
Konva.Factory.addGetterSetter(
Konva.Node,
'skewY',
0,
Konva.Validators.getNumberValidator()
);
/**
* get/set skew y
@@ -2311,7 +2352,12 @@
* });
*/
Konva.Factory.addGetterSetter(Konva.Node, 'offsetX', 0);
Konva.Factory.addGetterSetter(
Konva.Node,
'offsetX',
0,
Konva.Validators.getNumberValidator()
);
/**
* get/set offset x
@@ -2328,7 +2374,12 @@
* node.offsetX(3);
*/
Konva.Factory.addGetterSetter(Konva.Node, 'offsetY', 0);
Konva.Factory.addGetterSetter(
Konva.Node,
'offsetY',
0,
Konva.Validators.getNumberValidator()
);
/**
* get/set offset y
@@ -2345,7 +2396,11 @@
* node.offsetY(3);
*/
Konva.Factory.addSetter(Konva.Node, 'dragDistance');
Konva.Factory.addSetter(
Konva.Node,
'dragDistance',
Konva.Validators.getNumberValidator()
);
Konva.Factory.addOverloadedGetterSetter(Konva.Node, 'dragDistance');
/**
@@ -2366,7 +2421,11 @@
* Konva.dragDistance = 3;
*/
Konva.Factory.addSetter(Konva.Node, 'width', 0);
Konva.Factory.addSetter(
Konva.Node,
'width',
Konva.Validators.getNumberValidator()
);
Konva.Factory.addOverloadedGetterSetter(Konva.Node, 'width');
/**
* get/set width
@@ -2383,7 +2442,11 @@
* node.width(100);
*/
Konva.Factory.addSetter(Konva.Node, 'height', 0);
Konva.Factory.addSetter(
Konva.Node,
'height',
Konva.Validators.getNumberValidator()
);
Konva.Factory.addOverloadedGetterSetter(Konva.Node, 'height');
/**
* get/set height
@@ -2400,7 +2463,18 @@
* node.height(100);
*/
Konva.Factory.addGetterSetter(Konva.Node, 'listening', 'inherit');
Konva.Factory.addGetterSetter(Konva.Node, 'listening', 'inherit', function(
val
) {
var isValid = val === true || val === false || val === 'inherit';
if (!isValid) {
Konva.Util.warn(
val +
' is a not valid value for "listening" attribute. The value may be true, false or "inherit".'
);
}
return val;
});
/**
* get/set listenig attr. If you need to determine if a node is listening or not
* by taking into account its parents, use the isListening() method
@@ -2443,11 +2517,14 @@
* shape.preventDefault(false);
*/
Konva.Factory.addGetterSetter(Konva.Node, 'preventDefault', true);
Konva.Factory.addGetterSetter(
Konva.Node,
'preventDefault',
true,
Konva.Validators.getBooleanValidator()
);
Konva.Factory.addGetterSetter(Konva.Node, 'filters', undefined, function(
val
) {
Konva.Factory.addGetterSetter(Konva.Node, 'filters', null, function(val) {
this._filterUpToDate = false;
return val;
});
@@ -2475,7 +2552,18 @@
* ]);
*/
Konva.Factory.addGetterSetter(Konva.Node, 'visible', 'inherit');
Konva.Factory.addGetterSetter(Konva.Node, 'visible', 'inherit', function(
val
) {
var isValid = val === true || val === false || val === 'inherit';
if (!isValid) {
Konva.Util.warn(
val +
' is a not valid value for "visible" attribute. The value may be true, false or "inherit".'
);
}
return val;
});
/**
* get/set visible attr. Can be "inherit", true, or false. The default is "inherit".
* If you need to determine if a node is visible or not
@@ -2499,7 +2587,12 @@
* node.visible('inherit');
*/
Konva.Factory.addGetterSetter(Konva.Node, 'transformsEnabled', 'all');
Konva.Factory.addGetterSetter(
Konva.Node,
'transformsEnabled',
'all',
Konva.Validators.getStringValidator()
);
/**
* get/set transforms that are enabled. Can be "all", "none", or "position". The default