mirror of
https://github.com/konvajs/konva.git
synced 2026-01-23 13:26:07 +08:00
transformer warning, typescript fixes
This commit is contained in:
@@ -5,6 +5,7 @@ import { DD } from './DragAndDrop';
|
||||
import { getNumberValidator } from './Validators';
|
||||
|
||||
import { GetSet, IRect } from './types';
|
||||
import { Shape } from './Shape';
|
||||
|
||||
export interface ContainerConfig extends NodeConfig {
|
||||
clearBeforeDraw?: boolean;
|
||||
@@ -112,7 +113,7 @@ export abstract class Container extends Node<ContainerConfig> {
|
||||
* // remember to redraw layer if you changed something
|
||||
* layer.draw();
|
||||
*/
|
||||
add(child) {
|
||||
add(child: Node) {
|
||||
if (arguments.length > 1) {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
this.add(arguments[i]);
|
||||
@@ -300,7 +301,7 @@ export abstract class Container extends Node<ContainerConfig> {
|
||||
|
||||
return false;
|
||||
}
|
||||
clone(obj) {
|
||||
clone(obj?) {
|
||||
// call super method
|
||||
var node = Node.prototype.clone.call(this, obj);
|
||||
|
||||
@@ -324,7 +325,7 @@ export abstract class Container extends Node<ContainerConfig> {
|
||||
getAllIntersections(pos) {
|
||||
var arr = [];
|
||||
|
||||
this.find('Shape').each(function(shape) {
|
||||
this.find('Shape').each(function(shape: Shape) {
|
||||
if (shape.isVisible() && shape.intersects(pos)) {
|
||||
arr.push(shape);
|
||||
}
|
||||
@@ -447,7 +448,7 @@ export abstract class Container extends Node<ContainerConfig> {
|
||||
(layer && layer.hitGraphEnabled() && this.isVisible() && !layerUnderDrag)
|
||||
);
|
||||
}
|
||||
getClientRect(attrs) {
|
||||
getClientRect(attrs): IRect {
|
||||
attrs = attrs || {};
|
||||
var skipTransform = attrs.skipTransform;
|
||||
var relativeTo = attrs.relativeTo;
|
||||
@@ -462,7 +463,7 @@ export abstract class Container extends Node<ContainerConfig> {
|
||||
var that = this;
|
||||
this.children.each(function(child) {
|
||||
// skip invisible children
|
||||
if (!child.getVisible()) {
|
||||
if (!child.visible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Util, Collection } from './Util';
|
||||
import { Container } from './Container';
|
||||
import { _registerNode } from './Global';
|
||||
import { Node } from './Node';
|
||||
|
||||
/**
|
||||
* Group constructor. Groups are used to contain shapes or other groups.
|
||||
|
||||
14
src/Node.ts
14
src/Node.ts
@@ -11,10 +11,10 @@ import {
|
||||
getBooleanValidator
|
||||
} from './Validators';
|
||||
|
||||
export const ids = {};
|
||||
export const names = {};
|
||||
export const ids: any = {};
|
||||
export const names: any = {};
|
||||
|
||||
const _addId = function(node: Node, id) {
|
||||
const _addId = function(node: Node, id: string | undefined) {
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
eventListeners = {};
|
||||
attrs: any = {};
|
||||
index = 0;
|
||||
parent: Container = null;
|
||||
parent: Container | null = null;
|
||||
_cache: Map<string, any> = new Map<string, any>();
|
||||
_lastPos = null;
|
||||
_attrsAffectingSize: string[];
|
||||
@@ -1305,7 +1305,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
setZIndex(zIndex) {
|
||||
if (!this.parent) {
|
||||
Util.warn('Node has no parent. zIndex parameter is ignored.');
|
||||
return false;
|
||||
return this;
|
||||
}
|
||||
if (zIndex < 0 || zIndex >= this.parent.children.length) {
|
||||
Util.warn(
|
||||
@@ -1428,7 +1428,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* var parentGroups = node.findAncestors('Group');
|
||||
*/
|
||||
findAncestors(selector, includeSelf, stopNode) {
|
||||
var res = [];
|
||||
var res: Array<Node> = [];
|
||||
|
||||
if (includeSelf && this._isMatch(selector)) {
|
||||
res.push(this);
|
||||
@@ -1697,7 +1697,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
* x: 5
|
||||
* });
|
||||
*/
|
||||
clone(obj) {
|
||||
clone(obj?) {
|
||||
// instantiate new node
|
||||
var attrs = Util.cloneObject(this.attrs),
|
||||
key,
|
||||
|
||||
@@ -33,7 +33,7 @@ export class Collection<Child extends Node> {
|
||||
// @ts-ignore
|
||||
length: number;
|
||||
// @ts-ignore
|
||||
each: (f: Function) => void;
|
||||
each: (f: (child: Child, index: number) => void) => void;
|
||||
// @ts-ignore
|
||||
toArray: () => Array<any>;
|
||||
// @ts-ignore
|
||||
|
||||
@@ -274,6 +274,12 @@ export class Transformer extends Group {
|
||||
rotation: 0
|
||||
};
|
||||
}
|
||||
|
||||
if (node.parent && this.parent && node.parent !== this.parent) {
|
||||
Util.warn(
|
||||
'Transformer and attached node have different parents. Konva does not support such case right now. Please move Transformer to the parent of attaching node.'
|
||||
);
|
||||
}
|
||||
var rect = node.getClientRect({
|
||||
skipTransform: true,
|
||||
skipShadow: true,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { Shape } from './Shape';
|
||||
import { Stage } from './Stage';
|
||||
|
||||
export interface GetSet<Type, This> {
|
||||
(this: This): Type;
|
||||
(this: This, v: Type): This;
|
||||
(): Type;
|
||||
(v: Type): This;
|
||||
}
|
||||
|
||||
export interface Vector2d {
|
||||
|
||||
Reference in New Issue
Block a user