1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | var __assign = (this && this.__assign) || function () {
|
16 | __assign = Object.assign || function(t) {
|
17 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
18 | s = arguments[i];
|
19 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
20 | t[p] = s[p];
|
21 | }
|
22 | return t;
|
23 | };
|
24 | return __assign.apply(this, arguments);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | var helper_1 = require("../helper");
|
28 | var types_1 = require("../types");
|
29 | var types_2 = require("./types");
|
30 | function clickButton(group, component, payload) {
|
31 | var id = component.id;
|
32 | var action = helper_1.getEventNameSpace(group, types_2.Action.CLICK, component);
|
33 | var buttonPayload = {
|
34 | id: id,
|
35 | payload: payload,
|
36 | };
|
37 | return helper_1.actionWrapper({ type: action, group: group, payload: buttonPayload });
|
38 | }
|
39 | exports.clickButton = clickButton;
|
40 | function update(group, component, props) {
|
41 | var id = component.id;
|
42 | var label = props.label;
|
43 | var action = helper_1.getEventNameSpace(group, types_2.Action.UPDATE, component);
|
44 | var buttonPayload = __assign({ id: id,
|
45 | label: label }, props);
|
46 | return helper_1.actionWrapper({ type: action, group: group, payload: buttonPayload });
|
47 | }
|
48 | exports.update = update;
|
49 | function isValidButtonProps(button) {
|
50 | return typeof button.id === 'string' && typeof button.label === 'string';
|
51 | }
|
52 | exports.isValidButtonProps = isValidButtonProps;
|
53 | var Button = (function (_super) {
|
54 | __extends(Button, _super);
|
55 | function Button(app, options) {
|
56 | var _this = _super.call(this, app, types_1.ComponentType.Button, types_1.Group.Button) || this;
|
57 | _this.disabled = false;
|
58 | _this.set(options, false);
|
59 | return _this;
|
60 | }
|
61 | Object.defineProperty(Button.prototype, "options", {
|
62 | get: function () {
|
63 | return {
|
64 | disabled: this.disabled,
|
65 | icon: this.icon,
|
66 | label: this.label,
|
67 | style: this.style,
|
68 | };
|
69 | },
|
70 | enumerable: true,
|
71 | configurable: true
|
72 | });
|
73 | Object.defineProperty(Button.prototype, "payload", {
|
74 | get: function () {
|
75 | return __assign({ id: this.id }, this.options);
|
76 | },
|
77 | enumerable: true,
|
78 | configurable: true
|
79 | });
|
80 | Button.prototype.set = function (options, shouldUpdate) {
|
81 | if (shouldUpdate === void 0) { shouldUpdate = true; }
|
82 | var mergedOptions = helper_1.getMergedProps(this.options, options);
|
83 | var label = mergedOptions.label, disabled = mergedOptions.disabled, icon = mergedOptions.icon, style = mergedOptions.style;
|
84 | this.label = label;
|
85 | this.disabled = !!disabled;
|
86 | this.icon = icon;
|
87 | this.style = style;
|
88 | if (shouldUpdate) {
|
89 | this.dispatch(types_2.Action.UPDATE);
|
90 | }
|
91 | return this;
|
92 | };
|
93 | Button.prototype.dispatch = function (action, payload) {
|
94 | switch (action) {
|
95 | case types_2.Action.CLICK:
|
96 | this.app.dispatch(clickButton(this.group, this.component, payload));
|
97 | break;
|
98 | case types_2.Action.UPDATE:
|
99 | var updateAction = update(this.group, this.component, this.payload);
|
100 | this.app.dispatch(updateAction);
|
101 | break;
|
102 | }
|
103 | return this;
|
104 | };
|
105 | return Button;
|
106 | }(helper_1.ActionSet));
|
107 | exports.Button = Button;
|
108 | function create(app, options) {
|
109 | return new Button(app, options);
|
110 | }
|
111 | exports.create = create;
|