UNPKG

kentico-cloud-delivery

Version:

Official Kentico Cloud Delivery SDK

219 lines 7.82 kB
import { FieldModels } from './field-models'; import { FieldType } from './field-type'; export var Fields; (function (Fields) { var TextField = /** @class */ (function () { /** * Represents text field of Kentico Cloud item * @constructor * @param {string} name - Name of the field * @param {string} value - Value of the field */ function TextField(name, value) { this.name = name; this.value = value; /** * Type of the field */ this.type = FieldType.Text; this.text = this.value; } return TextField; }()); Fields.TextField = TextField; var MultipleChoiceField = /** @class */ (function () { /** * Represents multiple choice field of Kentico Cloud item * @constructor * @param {string} name - Name of the field * @param {string} value - Value of the field */ function MultipleChoiceField(name, value) { var _this = this; this.name = name; this.value = value; /** * Multiple choice options */ this.options = []; /** * Type of the field */ this.type = FieldType.MultipleChoice; if (this.value && Array.isArray(this.value)) { this.value.forEach(function (option) { var optionTemp = option; _this.options.push(new FieldModels.MultipleChoiceOption(optionTemp.name, optionTemp.codename)); }); } } return MultipleChoiceField; }()); Fields.MultipleChoiceField = MultipleChoiceField; var DateTimeField = /** @class */ (function () { /** * Represents date time field of Kentico Cloud item * @constructor * @param {string} name - Name of the field * @param {string} value - Value of the field */ function DateTimeField(name, value) { this.name = name; this.value = value; /** * Type of the field */ this.type = FieldType.DateTime; this.datetime = new Date(value); } return DateTimeField; }()); Fields.DateTimeField = DateTimeField; var RichTextField = /** @class */ (function () { /** * Represents rich text field of Kentico Cloud item * @constructor * @param {string} name - Name of the field * @param {string} value - Value of the field * @param {() => string} resolveHtml - Function that resolves HTML * @param {Link[]} links - Links for this rich text field */ function RichTextField(name, value, data) { this.name = name; this.value = value; /** * Type of the field */ this.type = FieldType.RichText; /** * Links */ this.links = []; Object.assign(this, data); } RichTextField.prototype.getHtml = function () { // check if html was already resolved if (this.resolvedHtml) { return this.resolvedHtml; } this.resolvedHtml = this.resolveHtml(); return this.resolvedHtml; }; return RichTextField; }()); Fields.RichTextField = RichTextField; var NumberField = /** @class */ (function () { /** * Represents number field of Kentico Cloud item * @constructor * @param {string} name - Name of the field * @param {string} value - Value of the field */ function NumberField(name, value) { this.name = name; this.value = value; /** * Type of the field */ this.type = FieldType.Number; this.number = value; } return NumberField; }()); Fields.NumberField = NumberField; var AssetsField = /** @class */ (function () { /** * Represents asset field of Kentico Cloud item * @constructor * @param {string} name - Name of the field * @param {any} value - Value of the field */ function AssetsField(name, value) { var _this = this; this.name = name; this.value = value; /** * Type of the field */ this.type = FieldType.Asset; /** * List of assets used in this field */ this.assets = []; if (!value) { throw Error("Cannot bind assets field because no value was provided"); } if (!Array.isArray(value)) { throw Error("Cannot bind assets because the provided value is not an array"); } this.value.forEach(function (asset) { _this.assets.push(new FieldModels.AssetModel(asset.name, asset.type, asset.size, asset.description, asset.url)); }); } return AssetsField; }()); Fields.AssetsField = AssetsField; var UrlSlugField = /** @class */ (function () { /** * Represents URL slug field of Kentico Cloud item * @constructor * @param {string} name - Name of the field * @param {string} value - Value of the field * @param {() => string | undefined} resolveUrl - Function to get url of the link */ function UrlSlugField(name, value, data) { this.name = name; this.value = value; /** * Type of the field */ this.type = FieldType.UrlSlug; Object.assign(this, data); } UrlSlugField.prototype.getUrl = function () { if (this.resolvedUrl) { return this.resolvedUrl; } this.resolvedUrl = this.resolveUrl(); return this.resolvedUrl; }; return UrlSlugField; }()); Fields.UrlSlugField = UrlSlugField; var TaxonomyField = /** @class */ (function () { /** * Represents number field of Kentico Cloud item * @constructor * @param {string} name - Name of the field * @param {string} value - Value of the field * @param {string | undefined} taxonomyGroup - Codename of the taxonomy group */ function TaxonomyField(name, value, taxonomyGroup) { var _this = this; this.name = name; this.value = value; this.taxonomyGroup = taxonomyGroup; /** * Type of the field */ this.type = FieldType.Taxonomy; /** * List of assigned taxonomy terms */ this.taxonomyTerms = []; if (!value) { throw Error("Cannot map taxonomy field because no value was provided"); } if (!Array.isArray(value)) { throw Error("Cannot get taxonomy field because the provided value is not an array"); } var taxonomyList = value; taxonomyList.forEach(function (term) { _this.taxonomyTerms.push(new FieldModels.TaxonomyTerm(term.name, term.codename)); }); } return TaxonomyField; }()); Fields.TaxonomyField = TaxonomyField; })(Fields || (Fields = {})); //# sourceMappingURL=field-types.js.map