block-obj-builder
Version:
Block object builder
56 lines (55 loc) • 2.33 kB
JavaScript
;
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 block_obj_enums_1 = require("../../const/block-obj-enums");
var text_overflow_enums_1 = require("../../const/text-overflow-enums");
var block_obj_builder_1 = require("./block-obj-builder");
function isBlockObj(arg) {
return arg.content !== undefined;
}
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.obj.type = block_obj_enums_1.BlockTypes.TEXT;
_this.obj.content.text = {};
_this.obj.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 = 'default'; }
if (!this.obj.content.text[textKey]) {
this.obj.content.text[textKey] = {};
}
this.obj.content.text[textKey][lang] = text;
return this;
};
TextBB.prototype.setText = function (polylang, textKey) {
if (textKey === void 0) { textKey = 'default'; }
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.obj.content.text = isBlockObj(source) ? source.content.text : source;
return this;
};
return TextBB;
}(block_obj_builder_1.default));
exports.default = TextBB;