ag-charts-community
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
221 lines (220 loc) • 9.14 kB
TypeScript
import type { CollapseWidgetEvent, ExpandControlledWidgetEvent, ExpandWidgetEvent } from './expandableWidget';
type FocusWidgetEventType = 'blur' | 'focus';
type KeyboardWidgetEventType = 'keyup' | 'keydown';
type MouseWidgetEventType = 'contextmenu' | 'click' | 'dblclick' | 'mouseenter' | 'mousemove' | 'mouseleave';
type TouchWidgetEventType = 'touchstart' | 'touchmove' | 'touchend' | 'touchcancel';
type DragWidgetEventType = 'drag-start' | 'drag-move' | 'drag-end';
type WidgetEventType = 'change' | 'wheel' | FocusWidgetEventType | KeyboardWidgetEventType | MouseWidgetEventType | TouchWidgetEventType | DragWidgetEventType | (CollapseWidgetEvent | ExpandControlledWidgetEvent | ExpandWidgetEvent)['type'];
type KeyboardSyntheticMouseWidgetEventType = 'click';
type TouchSyntheticMouseWidgetEventType = 'click' | 'dblclick';
export type WidgetEvent<T extends WidgetEventType = WidgetEventType> = {
readonly type: T;
readonly sourceEvent: Event;
};
export type FocusWidgetEvent<T extends FocusWidgetEventType = FocusWidgetEventType> = {
readonly type: T;
readonly sourceEvent: FocusEvent;
};
export type KeyboardWidgetEvent<T extends KeyboardWidgetEventType = KeyboardWidgetEventType> = {
readonly type: T;
readonly sourceEvent: KeyboardEvent;
};
export type KeyboardSyntheticMouseWidgetEvent<T extends MouseWidgetEventType & KeyboardSyntheticMouseWidgetEventType = KeyboardSyntheticMouseWidgetEventType> = {
readonly type: T;
readonly device: 'keyboard';
readonly sourceEvent: KeyboardEvent;
};
export type TouchWidgetEvent<T extends TouchWidgetEventType = TouchWidgetEventType> = {
readonly type: T;
readonly sourceEvent: TouchEvent;
};
export type TouchSyntheticMouseWidgetEvent<T extends MouseWidgetEventType & TouchSyntheticMouseWidgetEventType = TouchSyntheticMouseWidgetEventType> = {
readonly type: T;
readonly device: 'touch';
readonly offsetX: number;
readonly offsetY: number;
readonly clientX: number;
readonly clientY: number;
readonly currentX: number;
readonly currentY: number;
readonly sourceEvent: TouchEvent;
};
export type NativeMouseWidgetEvent<T extends MouseWidgetEventType = MouseWidgetEventType> = {
readonly type: T;
readonly device: 'mouse';
readonly offsetX: number;
readonly offsetY: number;
readonly clientX: number;
readonly clientY: number;
readonly currentX: number;
readonly currentY: number;
readonly sourceEvent: MouseEvent;
};
export type MouseWidgetEvent<T extends MouseWidgetEventType = MouseWidgetEventType> = NativeMouseWidgetEvent<T> | (T extends TouchSyntheticMouseWidgetEventType ? TouchSyntheticMouseWidgetEvent<T> : never) | (T extends KeyboardSyntheticMouseWidgetEventType ? KeyboardSyntheticMouseWidgetEvent<T> : never);
export type WheelWidgetEvent = {
readonly type: 'wheel';
readonly offsetX: number;
readonly offsetY: number;
readonly clientX: number;
readonly clientY: number;
readonly deltaX: number;
readonly deltaY: number;
readonly sourceEvent: WheelEvent;
};
export type ClickLikeEvent = MouseWidgetEvent<'click' | 'dblclick'> & {
device: 'mouse' | 'touch';
};
export type HoverLikeEvent = ClickLikeEvent | MouseWidgetEvent<'mousemove'> | DragWidgetEvent<'drag-move'>;
export type DragWidgetEvent<T extends DragWidgetEventType = DragWidgetEventType> = {
readonly type: T;
readonly device: 'mouse';
readonly offsetX: number;
readonly offsetY: number;
readonly clientX: number;
readonly clientY: number;
readonly currentX: number;
readonly currentY: number;
readonly originDeltaX: number;
readonly originDeltaY: number;
readonly sourceEvent: MouseEvent;
} | {
readonly type: T;
readonly device: 'touch';
readonly offsetX: number;
readonly offsetY: number;
readonly clientX: number;
readonly clientY: number;
readonly currentX: number;
readonly currentY: number;
readonly originDeltaX: number;
readonly originDeltaY: number;
readonly sourceEvent: TouchEvent;
};
export type WidgetEventMap = DerivedWidgetEvents;
export type WidgetEventMap_HTML = DerivedWidgetEventsWhereIsNative;
export type WidgetEventMap_Internal = DerivedWidgetEventsWhereIsInternal;
export type WidgetSourceEventMap_HTML = DerivedSourceEventsWhereIsNative;
declare const WIDGET_META: {
readonly change: {
readonly isNative: true;
readonly allocator: (sourceEvent: Event, _current: HTMLElement) => WidgetEvent<'change'>;
};
readonly blur: {
readonly isNative: true;
readonly allocator: (sourceEvent: FocusEvent, _current: HTMLElement) => FocusWidgetEvent<'blur'>;
};
readonly focus: {
readonly isNative: true;
readonly allocator: (sourceEvent: FocusEvent, _current: HTMLElement) => FocusWidgetEvent<'focus'>;
};
readonly keydown: {
readonly isNative: true;
readonly allocator: (sourceEvent: KeyboardEvent) => KeyboardWidgetEvent<'keydown'>;
};
readonly keyup: {
readonly isNative: true;
readonly allocator: (sourceEvent: KeyboardEvent) => KeyboardWidgetEvent<'keyup'>;
};
readonly contextmenu: {
readonly isNative: true;
readonly allocator: (sourceEvent: MouseEvent, current: HTMLElement) => MouseWidgetEvent<'contextmenu'>;
};
readonly click: {
readonly isNative: true;
readonly allocator: (sourceEvent: MouseEvent, current: HTMLElement) => MouseWidgetEvent<'click'>;
};
readonly dblclick: {
readonly isNative: true;
readonly allocator: (sourceEvent: MouseEvent, current: HTMLElement) => MouseWidgetEvent<'dblclick'>;
};
readonly mouseenter: {
readonly isNative: true;
readonly allocator: (sourceEvent: MouseEvent, current: HTMLElement) => MouseWidgetEvent<'mouseenter'>;
};
readonly mousemove: {
readonly isNative: true;
readonly allocator: (sourceEvent: MouseEvent, current: HTMLElement) => MouseWidgetEvent<'mousemove'>;
};
readonly mouseleave: {
readonly isNative: true;
readonly allocator: (sourceEvent: MouseEvent, current: HTMLElement) => MouseWidgetEvent<'mouseleave'>;
};
readonly wheel: {
readonly isNative: true;
readonly allocator: (sourceEvent: WheelEvent, _current: HTMLElement) => WheelWidgetEvent;
};
readonly touchstart: {
readonly isNative: true;
readonly allocator: (sourceEvent: TouchEvent, current: HTMLElement) => TouchWidgetEvent<'touchstart'>;
};
readonly touchmove: {
readonly isNative: true;
readonly allocator: (sourceEvent: TouchEvent, current: HTMLElement) => TouchWidgetEvent<'touchmove'>;
};
readonly touchend: {
readonly isNative: true;
readonly allocator: (sourceEvent: TouchEvent, current: HTMLElement) => TouchWidgetEvent<'touchend'>;
};
readonly touchcancel: {
readonly isNative: true;
readonly allocator: (sourceEvent: TouchEvent, current: HTMLElement) => TouchWidgetEvent<'touchcancel'>;
};
readonly 'drag-start': {
isInternal: true;
typeDerivation: DragWidgetEvent<"drag-start">;
};
readonly 'drag-move': {
isInternal: true;
typeDerivation: DragWidgetEvent<"drag-move">;
};
readonly 'drag-end': {
isInternal: true;
typeDerivation: DragWidgetEvent<"drag-end">;
};
readonly 'collapse-widget': {
isInternal: true;
typeDerivation: CollapseWidgetEvent;
};
readonly 'expand-widget': {
isInternal: true;
typeDerivation: ExpandWidgetEvent;
};
readonly 'expand-controlled-widget': {
isInternal: true;
typeDerivation: ExpandControlledWidgetEvent;
};
};
type WidgetMeta = typeof WIDGET_META;
type WidgetMetaKeys = keyof WidgetMeta;
type DerivedKeysWhereIsNative = {
[K in WidgetMetaKeys]: WidgetMeta[K] extends {
readonly isNative: true;
} ? K : never;
}[WidgetMetaKeys];
type DerivedKeysWhereIsInternal = {
[K in WidgetMetaKeys]: WidgetMeta[K] extends {
readonly isInternal: true;
} ? K : never;
}[WidgetMetaKeys];
type DerivedSourceEventsWhereIsNative = {
[K in DerivedKeysWhereIsNative]: Parameters<WidgetMeta[K]['allocator']>[0];
};
type DerivedWidgetEventsWhereIsNative = {
[K in DerivedKeysWhereIsNative]: ReturnType<WidgetMeta[K]['allocator']>;
};
type DerivedWidgetEventsWhereIsInternal = {
[K in DerivedKeysWhereIsInternal]: WidgetMeta[K]['typeDerivation'];
};
type DerivedWidgetEvents = DerivedWidgetEventsWhereIsNative & DerivedWidgetEventsWhereIsInternal;
export declare class WidgetEventUtil {
static alloc<K extends DerivedKeysWhereIsNative>(type: K, sourceEvent: DerivedSourceEventsWhereIsNative[K], current: HTMLElement): DerivedWidgetEventsWhereIsNative[K];
static isHTMLEvent(type: WidgetMetaKeys): type is WidgetMetaKeys & keyof HTMLElementEventMap;
static calcCurrentXY(current: HTMLElement, event: {
clientX: number;
clientY: number;
}): {
currentX: number;
currentY: number;
};
}
export {};