UNPKG

web-atoms-core

Version:
143 lines • 6.38 kB
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 (b.hasOwnProperty(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 __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "../../App", "../../di/Inject", "./AtomControl", "./AtomItemsControl"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var App_1 = require("../../App"); var Inject_1 = require("../../di/Inject"); var AtomControl_1 = require("./AtomControl"); var AtomItemsControl_1 = require("./AtomItemsControl"); var AtomComboBox = /** @class */ (function (_super) { __extends(AtomComboBox, _super); function AtomComboBox(app, e) { var _this = _super.call(this, app, e || document.createElement("select")) || this; _this.allowMultipleSelection = false; return _this; } AtomComboBox.prototype.onCollectionChanged = function (key, index, item) { _super.prototype.onCollectionChanged.call(this, key, index, item); try { this.isChanging = true; var se = this.element; se.selectedIndex = this.selectedIndex; } finally { this.isChanging = false; } }; // public onCollectionChanged(key: string, index: number, item: any): any { // const element = this.element as HTMLSelectElement; // const dataItems = this.items; // element.options.length = dataItems.length; // const lp = this.labelPath; // const vp = this.valuePath; // let label = null; // let value = null; // const selectedValue = this.value; // let i = 0; // for (const data of dataItems) { // label = data; // value = data; // if (lp) { // label = label[lp]; // } // if (vp) { // value = value[vp]; // } // // tslint:disable-next-line:triple-equals // element.options[i++] = new Option(label, value, false, value == selectedValue); // } // } AtomComboBox.prototype.updateSelectionBindings = function () { _super.prototype.updateSelectionBindings.call(this); try { if (this.isChanging) { return; } this.isChanging = true; var se = this.element; se.selectedIndex = this.selectedIndex; } finally { this.isChanging = false; } }; AtomComboBox.prototype.preCreate = function () { var _this = this; _super.prototype.preCreate.call(this); this.itemTemplate = AtomComboBoxItemTemplate; this.runAfterInit(function () { _this.bindEvent(_this.element, "change", function (s) { if (_this.isChanging) { return; } try { _this.isChanging = true; var index = _this.element.selectedIndex; if (index === -1) { _this.selectedItems.clear(); return; } _this.selectedItem = _this.items[index]; // this.selectedIndex = (this.element as HTMLSelectElement).selectedIndex; } finally { _this.isChanging = false; } }); }); }; AtomComboBox = __decorate([ __param(0, Inject_1.Inject), __metadata("design:paramtypes", [App_1.App, HTMLElement]) ], AtomComboBox); return AtomComboBox; }(AtomItemsControl_1.AtomItemsControl)); exports.AtomComboBox = AtomComboBox; var AtomComboBoxItemTemplate = /** @class */ (function (_super) { __extends(AtomComboBoxItemTemplate, _super); function AtomComboBoxItemTemplate(app, e) { return _super.call(this, app, e || document.createElement("option")) || this; } AtomComboBoxItemTemplate.prototype.create = function () { var _this = this; this.bind(this.element, "text", [["data"]], false, function (v) { var ip = _this.element._templateParent; return v[ip.labelPath]; }); }; return AtomComboBoxItemTemplate; }(AtomControl_1.AtomControl)); }); //# sourceMappingURL=AtomComboBox.js.map