UNPKG

2.23 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getActionClass = exports.registerAction = exports.Action = exports.Interaction = exports.createInteraction = exports.registerInteraction = exports.getInteraction = void 0;
4var tslib_1 = require("tslib");
5var util_1 = require("@antv/util");
6var grammar_interaction_1 = tslib_1.__importDefault(require("./grammar-interaction"));
7var Interactions = {};
8/**
9 * 根据交互行为名字获取对应的交互类
10 * @param name 交互名字
11 * @returns 交互类
12 */
13function getInteraction(name) {
14 return Interactions[(0, util_1.lowerCase)(name)];
15}
16exports.getInteraction = getInteraction;
17/**
18 * 注册交互行为
19 * @param name 交互行为名字
20 * @param interaction 交互类
21 */
22function registerInteraction(name, interaction) {
23 Interactions[(0, util_1.lowerCase)(name)] = interaction;
24}
25exports.registerInteraction = registerInteraction;
26/**
27 * 创建交互实例
28 * @param name 交互名
29 * @param view 交互应用的 View 实例
30 * @param cfg 交互行为配置
31 */
32function createInteraction(name, view, cfg) {
33 var interaciton = getInteraction(name);
34 if (!interaciton) {
35 return null;
36 }
37 if ((0, util_1.isPlainObject)(interaciton)) {
38 // 如果不 clone 则会多个 interaction 实例共享 step 的定义
39 var steps = (0, util_1.mix)((0, util_1.clone)(interaciton), cfg);
40 return new grammar_interaction_1.default(view, steps);
41 }
42 else {
43 var cls = interaciton;
44 return new cls(view, cfg);
45 }
46}
47exports.createInteraction = createInteraction;
48var interaction_1 = require("./interaction");
49Object.defineProperty(exports, "Interaction", { enumerable: true, get: function () { return tslib_1.__importDefault(interaction_1).default; } });
50var action_1 = require("./action");
51Object.defineProperty(exports, "Action", { enumerable: true, get: function () { return action_1.Action; } });
52Object.defineProperty(exports, "registerAction", { enumerable: true, get: function () { return action_1.registerAction; } });
53Object.defineProperty(exports, "getActionClass", { enumerable: true, get: function () { return action_1.getActionClass; } });
54//# sourceMappingURL=index.js.map
\No newline at end of file