UNPKG

3.54 kBTypeScriptView Raw
1import { View } from '../chart';
2import { ActionCallback, IAction, IInteractionContext } from '../interface';
3import Interaction from './interaction';
4export declare function parseAction(actionStr: string, context: IInteractionContext, arg?: any): ActionObject;
5/** 交互环节的定义 */
6export interface InteractionStep {
7 /**
8 * 触发事件,支持 view,chart 的各种事件,也支持 document、window 的事件
9 */
10 trigger: string;
11 /**
12 * 是否可以触发 action
13 * @param context - 交互的上下文
14 */
15 isEnable?: (context: IInteractionContext) => boolean;
16 /**
17 * 反馈,支持三种方式:
18 * - action:method : action 的名字和方法的组合
19 * - [’action1:method1‘, ’action2:method‘]
20 * - ActionCallback: 回调函数
21 */
22 action: string | string[] | ActionCallback;
23 /**
24 * 反馈,具体 action method 的参数:
25 * - 当传递多个 action 时,args 必须是一个数组
26 */
27 arg?: any | any[];
28 /**
29 * 回调函数,action 执行后执行
30 */
31 callback?: (context: IInteractionContext) => void;
32 /**
33 * @private
34 * 不需要用户传入,通过上面的属性计算出来的属性
35 */
36 actionObject?: ActionObject | ActionObject[];
37 /**
38 * 在一个环节内是否只允许执行一次
39 */
40 once?: boolean;
41 /**
42 * 是否增加节流
43 */
44 throttle?: ThrottleOption;
45 /**
46 * 是否延迟
47 */
48 debounce?: DebounceOption;
49}
50/**
51 * debounce 的配置
52 */
53export interface DebounceOption {
54 /**
55 * 等待时间
56 */
57 wait: number;
58 /**
59 * 是否马上执行
60 */
61 immediate?: boolean;
62}
63/**
64 * throttle 的配置
65 */
66export interface ThrottleOption {
67 /**
68 * 等待时间
69 */
70 wait: number;
71 /**
72 * 马上就执行
73 */
74 leading?: boolean;
75 /**
76 * 执行完毕后再执行一次
77 */
78 trailing?: boolean;
79}
80/** 缓存 action 对象,仅用于当前文件 */
81interface ActionObject {
82 /**
83 * 缓存的 action
84 */
85 action: IAction;
86 /**
87 * action 的方法
88 */
89 methodName: string;
90 /**
91 * 用户传递的 action 方法的参数
92 */
93 arg?: any;
94}
95/** 交互的所有环节 */
96export interface InteractionSteps {
97 /**
98 * 显示交互可以进行
99 */
100 showEnable?: InteractionStep[];
101 /**
102 * 交互开始
103 */
104 start?: InteractionStep[];
105 /**
106 * 交互持续
107 */
108 processing?: InteractionStep[];
109 /**
110 * 交互结束
111 */
112 end?: InteractionStep[];
113 /**
114 * 交互回滚
115 */
116 rollback?: InteractionStep[];
117}
118/**
119 * 支持语法的交互类
120 */
121export default class GrammarInteraction extends Interaction {
122 private steps;
123 /** 当前执行到的阶段 */
124 currentStepName: string;
125 /**
126 * 当前交互的上下文
127 */
128 context: IInteractionContext;
129 private callbackCaches;
130 private emitCaches;
131 constructor(view: View, steps: InteractionSteps);
132 /**
133 * 初始化
134 */
135 init(): void;
136 /**
137 * 清理资源
138 */
139 destroy(): void;
140 /**
141 * 绑定事件
142 */
143 protected initEvents(): void;
144 /**
145 * 清理绑定的事件
146 */
147 protected clearEvents(): void;
148 private initContext;
149 private isAllowStep;
150 private isAllowExecute;
151 private enterStep;
152 private afterExecute;
153 private getKey;
154 private getActionCallback;
155 private bindEvent;
156 private offEvent;
157}
158export {};