UNPKG

block-obj-builder

Version:

Block object builder

65 lines (64 loc) 2.77 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var action_types_enums_1 = require("../../const/action-types-enums"); var block_obj_enums_1 = require("../../const/block-obj-enums"); var text_overflow_enums_1 = require("../../const/text-overflow-enums"); var item_builder_1 = require("../item-builder"); var text_bb_1 = require("./text-bb"); var SelectBB = /** @class */ (function (_super) { __extends(SelectBB, _super); function SelectBB(choiceType, overflow) { if (choiceType === void 0) { choiceType = block_obj_enums_1.ChoiceTypes.QREPLY; } if (overflow === void 0) { overflow = text_overflow_enums_1.TextOverflow.SPLIT; } var _this = _super.call(this, overflow) || this; _this.obj.type = block_obj_enums_1.BlockTypes.SELECT; _this.itemBuilder = new item_builder_1.default(); _this.obj.meta.choiceType = choiceType; return _this; } SelectBB.prototype.pushChoice = function (cb) { this.itemBuilder.pushChoice(cb); this.updateChoiceType(cb); return this; }; SelectBB.prototype.unshiftChoice = function (cb) { this.itemBuilder.unshiftChoice(cb); this.updateChoiceType(cb); return this; }; SelectBB.prototype.hasChoice = function (cb) { return this.itemBuilder.hasChoice(cb); }; SelectBB.prototype.setChoices = function (choices) { var _this = this; this.itemBuilder.setChoices(choices); choices.forEach(function (cb) { return _this.updateChoiceType(cb); }); return this; }; SelectBB.prototype.updateChoiceType = function (cb) { if (cb.action && [action_types_enums_1.ActionTypes.URL, action_types_enums_1.ActionTypes.PHONE].includes(cb.action.type)) { this.obj.meta.choiceType = block_obj_enums_1.ChoiceTypes.QUESTION; } }; SelectBB.prototype.build = function () { this.obj.content.items = [this.itemBuilder.build()]; return _super.prototype.build.call(this); }; SelectBB.QREPLY_LIMIT = 13; return SelectBB; }(text_bb_1.default)); exports.default = SelectBB;