UNPKG

block-obj-builder

Version:

Block object builder

62 lines (61 loc) 2.59 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 block_obj_enums_1 = require("../../const/block-obj-enums"); var block_obj_builder_1 = require("./block-obj-builder"); var ComplexBB = /** @class */ (function (_super) { __extends(ComplexBB, _super); function ComplexBB(complexBlockType, topElementStyle, imageAspectRatio) { if (complexBlockType === void 0) { complexBlockType = block_obj_enums_1.ComplexBlockTypes.GENERIC; } var _this = _super.call(this) || this; _this.obj.type = block_obj_enums_1.BlockTypes.COMPLEX; _this.obj.content.items = []; _this.obj.meta.complexBlockType = complexBlockType; if (topElementStyle) { _this.obj.meta.topElementStyle = topElementStyle; } if (imageAspectRatio) { _this.obj.meta.imageAspectRatio = imageAspectRatio; } return _this; } ComplexBB.prototype.pushItem = function (ib) { // Add the item var item = ib.build(); this.obj.content.items.push(item); // Check if we need to set the topElementStyle. var isFirstItem = this.obj.content.items.length === 1; var isList = this.obj.meta.complexBlockType === block_obj_enums_1.ComplexBlockTypes.LIST; var styleIsSet = this.obj.meta.topElementStyle != null; if (!isFirstItem || !isList || styleIsSet) { return this; } // Set topElementStyle if (item.image) { this.obj.meta.topElementStyle = block_obj_enums_1.TopElementStyles.LARGE; } else { this.obj.meta.topElementStyle = block_obj_enums_1.TopElementStyles.COMPACT; } return this; }; ComplexBB.prototype.defaultChoice = function (cb) { this.obj.content.defaultChoice = cb.build(); return this; }; ComplexBB.ITEM_LIMIT = 10; return ComplexBB; }(block_obj_builder_1.default)); exports.default = ComplexBB;