UNPKG

block-obj-builder

Version:

Block object builder

71 lines (70 loc) 2.48 kB
"use strict"; var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; Object.defineProperty(exports, "__esModule", { value: true }); var deep_equal_1 = require("deep-equal"); var helpers_1 = require("../helpers/helpers"); var ItemBuilder = /** @class */ (function () { function ItemBuilder() { this.item = { choices: [] }; } ItemBuilder.prototype.addTitle = function (lang, text) { this.item.title = this.item.title || {}; this.item.title[lang] = text; return this; }; ItemBuilder.prototype.setTitle = function (polylang) { this.item.title = polylang; return this; }; ItemBuilder.prototype.addSubtitle = function (lang, text) { this.item.subtitle = this.item.subtitle || {}; this.item.subtitle[lang] = text; return this; }; ItemBuilder.prototype.setSubtitle = function (polylang) { this.item.subtitle = polylang; return this; }; ItemBuilder.prototype.image = function (media) { this.item.image = helpers_1.resolveMediaId(media); return this; }; ItemBuilder.prototype.build = function () { return this.item; }; ItemBuilder.prototype.pushChoice = function (cb) { this.item.choices.push(cb.build()); return this; }; ItemBuilder.prototype.unshiftChoice = function (cb) { this.item.choices.unshift(cb.build()); return this; }; ItemBuilder.prototype.setChoices = function (choices) { this.item.choices = choices.map(function (cb) { return cb.build(); }); return this; }; ItemBuilder.prototype.defaultChoice = function (cb) { this.item.defaultChoice = cb.build(); return this; }; ItemBuilder.prototype.hasChoice = function (cb) { var myChoice = cb.build(); var choices = __spreadArrays(this.item.choices); var defaultChoice = this.item.defaultChoice; if (defaultChoice) { choices.push(defaultChoice); } return choices.some(function (choice) { return deep_equal_1.default(choice, myChoice); }); }; return ItemBuilder; }()); exports.default = ItemBuilder;