@botonic/plugin-contentful
Version:
## What Does This Plugin Do?
53 lines • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CarouselDelivery = void 0;
const tslib_1 = require("tslib");
const cms = tslib_1.__importStar(require("../../cms"));
const delivery_utils_1 = require("../delivery-utils");
const reference_1 = require("./reference");
// TODO does not yet load the followU p
class CarouselDelivery extends reference_1.DeliveryWithReference {
constructor(delivery, button, resumeErrors) {
super(cms.ContentType.CAROUSEL, delivery, resumeErrors);
this.button = button;
}
carousel(id, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const entry = yield this.getEntry(id, context);
return this.fromEntry(entry, context);
});
}
fromEntry(entry, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const elements = yield this.asyncMap(context, entry.fields.elements, (entry) => tslib_1.__awaiter(this, void 0, void 0, function* () {
return this.elementFromEntry(entry, context);
}));
const fields = entry.fields;
const followup = yield this.getReference().fromEntry(fields.followup, context);
const common = delivery_utils_1.ContentfulEntryUtils.commonFieldsFromEntry(entry, followup);
const referenceDelivery = {
delivery: this.reference,
context,
};
return (0, delivery_utils_1.addCustomFields)(new cms.Carousel(common, elements), entry.fields, referenceDelivery);
});
}
element(id, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const entry = yield this.delivery.getEntry(id, context);
return this.elementFromEntry(entry, context);
});
}
elementFromEntry(entry, context) {
var _a, _b;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
this.checkEntry(entry);
const fields = entry.fields;
const buttonEntries = fields.buttons || [];
const buttons = yield this.button.fromReferenceSkipErrors(buttonEntries, context);
return new cms.Element(entry.sys.id, buttons, (_a = fields.title) !== null && _a !== void 0 ? _a : '', (_b = fields.subtitle) !== null && _b !== void 0 ? _b : '', this.urlFromAssetOptional(fields.pic, context));
});
}
}
exports.CarouselDelivery = CarouselDelivery;
//# sourceMappingURL=carousel.js.map