This commit is contained in:
Anton Lavrenov
2019-05-29 11:36:07 -05:00
parent f6c9ecab69
commit 8698f020cc
6 changed files with 91 additions and 33 deletions

View File

@@ -169,6 +169,19 @@ interface NodeEventMap {
touchstart: TouchEvent;
}
export interface KonvaEventObject<EventType extends keyof NodeEventMap> {
target: Shape | Stage;
evt: NodeEventMap[EventType];
currentTarget: Node;
cancelBubble: boolean;
child?: Node;
}
export type KonvaEventListener<This, EventType extends keyof NodeEventMap> = (
this: This,
ev: KonvaEventObject<EventType>
) => void;
/**
* Node constructor. Nodes are entities that can be transformed, layered,
* and have bound events. The stage, layers, groups, and shapes all extend Node.
@@ -668,23 +681,13 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
* });
*/
on<K extends keyof NodeEventMap>(
type: K,
listener: (
this: this,
ev: {
target: Shape | Stage;
evt: NodeEventMap[K];
currentTarget: Node;
cancelBubble: boolean;
child?: Node;
}
) => any
): void;
on(evtStr: string, handler: (evt: any) => void) {
evtStr: K,
handler: KonvaEventListener<this, K>
) {
if (arguments.length === 3) {
return this._delegate.apply(this, arguments);
}
var events = evtStr.split(SPACE),
var events = (evtStr as string).split(SPACE),
len = events.length,
n,
event,

View File

@@ -1,11 +1,11 @@
import { KonvaEventObject } from './types';
import { KonvaEventObject } from './Node';
import { Shape } from './Shape';
import { Stage } from './Stage';
const Captures = new Map<number, Shape | Stage>();
export interface KonvaPointerEvent extends KonvaEventObject<PointerEvent> {
export interface KonvaPointerEvent extends KonvaEventObject<'touchstart'> {
pointerId: number;
}

11
src/index-types.d.ts vendored
View File

@@ -42,6 +42,15 @@ declare namespace Konva {
export type Node = import('./Node').Node;
export type NodeConfig = import('./Node').NodeConfig;
export type KonvaEventObject<EventType> = import('./Node').KonvaEventObject<
EventType
>;
export type KonvaEventListener<
This,
EventType
> = import('./Node').KonvaEventListener<This, EventType>;
export const Container: typeof import('./Container').Container;
export type Container = import('./Container').Container<Node>;
export type ContainerConfig = import('./Container').ContainerConfig;
@@ -133,8 +142,6 @@ declare namespace Konva {
export type Wedge = import('./shapes/Wedge').Wedge;
export type WedgeConfig = import('./shapes/Wedge').WedgeConfig;
export type KonvaEventObject<E> = import('./types').KonvaEventObject<E>;
export const Filters: {
Blur: typeof Blur;
Brighten: typeof Brighten;

View File

@@ -18,15 +18,6 @@ export interface IRect {
height: number;
}
export interface KonvaEventObject<E> {
target: Shape | Stage;
evt: E;
currentTarget: Node;
cancelBubble: boolean;
}
export type HandlerFunc<E = Event> = (e: KonvaEventObject<E>) => void;
export enum KonvaNodeEvent {
mouseover = 'mouseover',
mouseout = 'mouseout',
@@ -48,7 +39,3 @@ export enum KonvaNodeEvent {
dragmove = 'dragmove',
dragend = 'dragend'
}
type KonvaEvent = KonvaNodeEvent;
type KonvaEventString = KonvaEvent | string;