UNPKG

@webuildbots/webuildbots-sdk

Version:
72 lines (71 loc) 3.03 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 __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var block_enums_1 = require("../../const/block-enums"); var text_overflow_enums_1 = require("../../const/text-overflow-enums"); var block_builder_1 = __importDefault(require("./block-builder")); var defaultTextKey = 'default'; function isBlock(arg) { return arg.content !== undefined; } /** * @depreciated - Use {@link BasicBB} instead */ var TextBB = /** @class */ (function (_super) { __extends(TextBB, _super); function TextBB(overflow) { if (overflow === void 0) { overflow = text_overflow_enums_1.TextOverflow.SPLIT; } var _this = _super.call(this) || this; _this.block.type = block_enums_1.BlockTypes.TEXT; _this.block.content.text = {}; _this.block.meta.textOverflow = overflow; return _this; } // {@code textKey} is used to identify when the text should be used e.g. sad, happy TextBB.prototype.addText = function (lang, text, textKey) { if (textKey === void 0) { textKey = defaultTextKey; } if (!this.block.content.text[textKey]) { this.block.content.text[textKey] = {}; } this.block.content.text[textKey][lang] = text; return this; }; TextBB.prototype.setText = function (polylang, textKey) { if (textKey === void 0) { textKey = defaultTextKey; } for (var _i = 0, _a = Object.keys(polylang); _i < _a.length; _i++) { var lang = _a[_i]; this.addText(lang, polylang[lang], textKey); } return this; }; TextBB.prototype.setAllText = function (source) { this.block.content.text = isBlock(source) ? source.content.text : source; return this; }; TextBB.prototype.build = function () { var text = this.block.content.text; var defaultPolylang = text[defaultTextKey] || {}; var firstTranslation = Object.values(defaultPolylang)[0]; if (!firstTranslation) { throw new Error('This block requires at least some default text, you need to call setText(..) or addText(..) with a truthy value for the text'); } return _super.prototype.build.call(this); }; return TextBB; }(block_builder_1.default)); exports.default = TextBB;