| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
- "use strict";
- 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);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var core_1 = require("@angular/core");
- var common_1 = require("@angular/common");
- var shared_1 = require("../common/shared");
- var domhandler_1 = require("../dom/domhandler");
- var objectutils_1 = require("../utils/objectutils");
- var forms_1 = require("@angular/forms");
- var filterutils_1 = require("../utils/filterutils");
- exports.LISTBOX_VALUE_ACCESSOR = {
- provide: forms_1.NG_VALUE_ACCESSOR,
- useExisting: core_1.forwardRef(function () { return Listbox; }),
- multi: true
- };
- var Listbox = /** @class */ (function () {
- function Listbox(el, cd) {
- this.el = el;
- this.cd = cd;
- this.checkbox = false;
- this.filter = false;
- this.filterMode = 'contains';
- this.metaKeySelection = true;
- this.showToggleAll = true;
- this.onChange = new core_1.EventEmitter();
- this.onClick = new core_1.EventEmitter();
- this.onDblClick = new core_1.EventEmitter();
- this.onModelChange = function () { };
- this.onModelTouched = function () { };
- this.disabledSelectedOptions = [];
- }
- Object.defineProperty(Listbox.prototype, "options", {
- get: function () {
- return this._options;
- },
- set: function (val) {
- var opts = this.optionLabel ? objectutils_1.ObjectUtils.generateSelectItems(val, this.optionLabel) : val;
- this._options = opts;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Listbox.prototype, "filterValue", {
- get: function () {
- return this._filterValue;
- },
- set: function (val) {
- this._filterValue = val;
- },
- enumerable: true,
- configurable: true
- });
- Listbox.prototype.ngAfterContentInit = function () {
- var _this = this;
- this.templates.forEach(function (item) {
- switch (item.getType()) {
- case 'item':
- _this.itemTemplate = item.template;
- break;
- default:
- _this.itemTemplate = item.template;
- break;
- }
- });
- };
- Listbox.prototype.writeValue = function (value) {
- this.value = value;
- this.setDisabledSelectedOptions();
- this.cd.markForCheck();
- };
- Listbox.prototype.registerOnChange = function (fn) {
- this.onModelChange = fn;
- };
- Listbox.prototype.registerOnTouched = function (fn) {
- this.onModelTouched = fn;
- };
- Listbox.prototype.setDisabledState = function (val) {
- this.disabled = val;
- };
- Listbox.prototype.onOptionClick = function (event, option) {
- if (this.disabled || option.disabled || this.readonly) {
- return;
- }
- if (this.multiple) {
- if (this.checkbox)
- this.onOptionClickCheckbox(event, option);
- else
- this.onOptionClickMultiple(event, option);
- }
- else {
- this.onOptionClickSingle(event, option);
- }
- this.onClick.emit({
- originalEvent: event,
- option: option,
- value: this.value
- });
- this.optionTouched = false;
- };
- Listbox.prototype.onOptionTouchEnd = function (event, option) {
- if (this.disabled || option.disabled || this.readonly) {
- return;
- }
- this.optionTouched = true;
- };
- Listbox.prototype.onOptionDoubleClick = function (event, option) {
- if (this.disabled || option.disabled || this.readonly) {
- return;
- }
- this.onDblClick.emit({
- originalEvent: event,
- option: option,
- value: this.value
- });
- };
- Listbox.prototype.onOptionClickSingle = function (event, option) {
- var selected = this.isSelected(option);
- var valueChanged = false;
- var metaSelection = this.optionTouched ? false : this.metaKeySelection;
- if (metaSelection) {
- var metaKey = (event.metaKey || event.ctrlKey);
- if (selected) {
- if (metaKey) {
- this.value = null;
- valueChanged = true;
- }
- }
- else {
- this.value = option.value;
- valueChanged = true;
- }
- }
- else {
- this.value = selected ? null : option.value;
- valueChanged = true;
- }
- if (valueChanged) {
- this.onModelChange(this.value);
- this.onChange.emit({
- originalEvent: event,
- value: this.value
- });
- }
- };
- Listbox.prototype.onOptionClickMultiple = function (event, option) {
- var selected = this.isSelected(option);
- var valueChanged = false;
- var metaSelection = this.optionTouched ? false : this.metaKeySelection;
- if (metaSelection) {
- var metaKey = (event.metaKey || event.ctrlKey);
- if (selected) {
- if (metaKey) {
- this.removeOption(option);
- }
- else {
- this.value = [option.value];
- }
- valueChanged = true;
- }
- else {
- this.value = (metaKey) ? this.value || [] : [];
- this.value = this.value.concat([option.value]);
- valueChanged = true;
- }
- }
- else {
- if (selected) {
- this.removeOption(option);
- }
- else {
- this.value = (this.value || []).concat([option.value]);
- }
- valueChanged = true;
- }
- if (valueChanged) {
- this.onModelChange(this.value);
- this.onChange.emit({
- originalEvent: event,
- value: this.value
- });
- }
- };
- Listbox.prototype.onOptionClickCheckbox = function (event, option) {
- if (this.disabled || this.readonly) {
- return;
- }
- var selected = this.isSelected(option);
- if (selected) {
- this.removeOption(option);
- }
- else {
- this.value = this.value ? this.value : [];
- this.value = this.value.concat([option.value]);
- }
- this.onModelChange(this.value);
- this.onChange.emit({
- originalEvent: event,
- value: this.value
- });
- };
- Listbox.prototype.removeOption = function (option) {
- var _this = this;
- this.value = this.value.filter(function (val) { return !objectutils_1.ObjectUtils.equals(val, option.value, _this.dataKey); });
- };
- Listbox.prototype.isSelected = function (option) {
- var selected = false;
- if (this.multiple) {
- if (this.value) {
- for (var _i = 0, _a = this.value; _i < _a.length; _i++) {
- var val = _a[_i];
- if (objectutils_1.ObjectUtils.equals(val, option.value, this.dataKey)) {
- selected = true;
- break;
- }
- }
- }
- }
- else {
- selected = objectutils_1.ObjectUtils.equals(this.value, option.value, this.dataKey);
- }
- return selected;
- };
- Object.defineProperty(Listbox.prototype, "allChecked", {
- get: function () {
- if (this.filterValue) {
- return this.allFilteredSelected();
- }
- else {
- var optionCount = this.getEnabledOptionCount();
- var disabledSelectedOptionCount = this.disabledSelectedOptions.length;
- return this.value && this.options && (this.value.length > 0 && this.value.length == optionCount + disabledSelectedOptionCount);
- }
- },
- enumerable: true,
- configurable: true
- });
- Listbox.prototype.getEnabledOptionCount = function () {
- if (this.options) {
- var count = 0;
- for (var _i = 0, _a = this.options; _i < _a.length; _i++) {
- var opt = _a[_i];
- if (!opt.disabled) {
- count++;
- }
- }
- return count;
- }
- else {
- return 0;
- }
- };
- Listbox.prototype.allFilteredSelected = function () {
- var allSelected;
- var options = this.filterValue ? this.getFilteredOptions() : this.options;
- if (this.value && options && options.length) {
- allSelected = true;
- for (var _i = 0, _a = this.options; _i < _a.length; _i++) {
- var opt = _a[_i];
- if (this.isItemVisible(opt)) {
- if (!this.isSelected(opt)) {
- allSelected = false;
- break;
- }
- }
- }
- }
- return allSelected;
- };
- Listbox.prototype.onFilter = function (event) {
- this._filterValue = event.target.value;
- };
- Listbox.prototype.toggleAll = function (event) {
- if (this.disabled || this.readonly || !this.options || this.options.length === 0) {
- return;
- }
- if (this.allChecked) {
- if (this.disabledSelectedOptions && this.disabledSelectedOptions.length > 0) {
- var value = [];
- value = this.disabledSelectedOptions.slice();
- this.value = value;
- }
- else {
- this.value = [];
- }
- }
- else {
- if (this.options) {
- this.value = [];
- if (this.disabledSelectedOptions && this.disabledSelectedOptions.length > 0) {
- this.value = this.disabledSelectedOptions.slice();
- }
- for (var i = 0; i < this.options.length; i++) {
- var opt = this.options[i];
- if (this.isItemVisible(opt) && !opt.disabled) {
- this.value.push(opt.value);
- }
- }
- }
- }
- this.onModelChange(this.value);
- this.onChange.emit({ originalEvent: event, value: this.value });
- event.preventDefault();
- };
- Listbox.prototype.isItemVisible = function (option) {
- if (this.filterValue) {
- var visible = void 0;
- var filterText = objectutils_1.ObjectUtils.removeAccents(this.filterValue).toLowerCase();
- if (this.filterMode) {
- visible = filterutils_1.FilterUtils[this.filterMode](option.label, this.filterValue);
- }
- else {
- visible = true;
- }
- return visible;
- }
- else {
- return true;
- }
- };
- Listbox.prototype.onInputFocus = function (event) {
- this.focus = true;
- };
- Listbox.prototype.onInputBlur = function (event) {
- this.focus = false;
- };
- Listbox.prototype.onOptionKeyDown = function (event, option) {
- if (this.readonly) {
- return;
- }
- var item = event.currentTarget;
- switch (event.which) {
- //down
- case 40:
- var nextItem = this.findNextItem(item);
- if (nextItem) {
- nextItem.focus();
- }
- event.preventDefault();
- break;
- //up
- case 38:
- var prevItem = this.findPrevItem(item);
- if (prevItem) {
- prevItem.focus();
- }
- event.preventDefault();
- break;
- //enter
- case 13:
- this.onOptionClick(event, option);
- event.preventDefault();
- break;
- }
- };
- Listbox.prototype.findNextItem = function (item) {
- var nextItem = item.nextElementSibling;
- if (nextItem)
- return domhandler_1.DomHandler.hasClass(nextItem, 'ui-state-disabled') || domhandler_1.DomHandler.isHidden(nextItem) ? this.findNextItem(nextItem) : nextItem;
- else
- return null;
- };
- Listbox.prototype.findPrevItem = function (item) {
- var prevItem = item.previousElementSibling;
- if (prevItem)
- return domhandler_1.DomHandler.hasClass(prevItem, 'ui-state-disabled') || domhandler_1.DomHandler.isHidden(prevItem) ? this.findPrevItem(prevItem) : prevItem;
- else
- return null;
- };
- Listbox.prototype.getFilteredOptions = function () {
- var filteredOptions = [];
- if (this.filterValue) {
- for (var i = 0; i < this.options.length; i++) {
- var opt = this.options[i];
- if (this.isItemVisible(opt) && !opt.disabled) {
- filteredOptions.push(opt);
- }
- }
- return filteredOptions;
- }
- else {
- return this.options;
- }
- };
- Listbox.prototype.onHeaderCheckboxFocus = function () {
- this.headerCheckboxFocus = true;
- };
- Listbox.prototype.onHeaderCheckboxBlur = function () {
- this.headerCheckboxFocus = false;
- };
- Listbox.prototype.setDisabledSelectedOptions = function () {
- if (this.options) {
- this.disabledSelectedOptions = [];
- if (this.value) {
- for (var _i = 0, _a = this.options; _i < _a.length; _i++) {
- var opt = _a[_i];
- if (opt.disabled && this.isSelected(opt)) {
- this.disabledSelectedOptions.push(opt.value);
- }
- }
- }
- }
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Listbox.prototype, "multiple", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], Listbox.prototype, "style", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Listbox.prototype, "styleClass", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], Listbox.prototype, "listStyle", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Listbox.prototype, "readonly", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Listbox.prototype, "disabled", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Listbox.prototype, "checkbox", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Listbox.prototype, "filter", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Listbox.prototype, "filterMode", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Listbox.prototype, "metaKeySelection", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Listbox.prototype, "dataKey", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Listbox.prototype, "showToggleAll", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Listbox.prototype, "optionLabel", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Listbox.prototype, "ariaFilterLabel", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Listbox.prototype, "onChange", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Listbox.prototype, "onClick", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Listbox.prototype, "onDblClick", void 0);
- __decorate([
- core_1.ViewChild('headerchkbox', { static: false }),
- __metadata("design:type", core_1.ElementRef)
- ], Listbox.prototype, "headerCheckboxViewChild", void 0);
- __decorate([
- core_1.ContentChild(shared_1.Header, { static: false }),
- __metadata("design:type", Object)
- ], Listbox.prototype, "headerFacet", void 0);
- __decorate([
- core_1.ContentChild(shared_1.Footer, { static: false }),
- __metadata("design:type", Object)
- ], Listbox.prototype, "footerFacet", void 0);
- __decorate([
- core_1.ContentChildren(shared_1.PrimeTemplate),
- __metadata("design:type", core_1.QueryList)
- ], Listbox.prototype, "templates", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Array),
- __metadata("design:paramtypes", [Array])
- ], Listbox.prototype, "options", null);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String),
- __metadata("design:paramtypes", [String])
- ], Listbox.prototype, "filterValue", null);
- Listbox = __decorate([
- core_1.Component({
- selector: 'p-listbox',
- template: "\n <div [ngClass]=\"{'ui-listbox ui-inputtext ui-widget ui-widget-content ui-corner-all':true,'ui-state-disabled':disabled,'ui-state-focus':focus}\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <div class=\"ui-helper-hidden-accessible\">\n <input type=\"text\" readonly=\"readonly\" (focus)=\"onInputFocus($event)\" (blur)=\"onInputBlur($event)\">\n </div>\n <div class=\"ui-widget-header ui-corner-all ui-listbox-header ui-helper-clearfix\" *ngIf=\"headerFacet\">\n <ng-content select=\"p-header\"></ng-content>\n </div>\n <div class=\"ui-widget-header ui-corner-all ui-listbox-header ui-helper-clearfix\" *ngIf=\"(checkbox && multiple && showToggleAll) || filter\" [ngClass]=\"{'ui-listbox-header-w-checkbox': checkbox}\">\n <div class=\"ui-chkbox ui-widget\" *ngIf=\"checkbox && multiple && showToggleAll\">\n <div class=\"ui-helper-hidden-accessible\">\n <input type=\"checkbox\" readonly=\"readonly\" [checked]=\"allChecked\" (focus)=\"onHeaderCheckboxFocus()\" (blur)=\"onHeaderCheckboxBlur()\" (keydown.space)=\"toggleAll($event)\">\n </div>\n <div #headerchkbox class=\"ui-chkbox-box ui-widget ui-corner-all ui-state-default\" [ngClass]=\"{'ui-state-active': allChecked, 'ui-state-focus': headerCheckboxFocus}\" (click)=\"toggleAll($event)\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"{'pi pi-check':allChecked}\"></span>\n </div>\n </div>\n <div class=\"ui-listbox-filter-container\" *ngIf=\"filter\">\n <input type=\"text\" role=\"textbox\" [value]=\"filterValue||''\" (input)=\"onFilter($event)\" class=\"ui-inputtext ui-widget ui-state-default ui-corner-all\" [disabled]=\"disabled\" [attr.aria-label]=\"ariaFilterLabel\">\n <span class=\"ui-listbox-filter-icon pi pi-search\"></span>\n </div>\n </div>\n <div class=\"ui-listbox-list-wrapper\" [ngStyle]=\"listStyle\">\n <ul class=\"ui-listbox-list\">\n <li *ngFor=\"let option of options; let i = index;\" [style.display]=\"isItemVisible(option) ? 'block' : 'none'\" [attr.tabindex]=\"option.disabled ? null : '0'\"\n [ngClass]=\"{'ui-listbox-item ui-corner-all':true,'ui-state-highlight':isSelected(option), 'ui-state-disabled': option.disabled}\" [attr.aria-label]=\"option.label\"\n (click)=\"onOptionClick($event,option)\" (dblclick)=\"onOptionDoubleClick($event,option)\" (touchend)=\"onOptionTouchEnd($event,option)\" (keydown)=\"onOptionKeyDown($event,option)\">\n <div class=\"ui-chkbox ui-widget\" *ngIf=\"checkbox && multiple\">\n <div class=\"ui-chkbox-box ui-widget ui-corner-all ui-state-default\" [ngClass]=\"{'ui-state-active':isSelected(option)}\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"{'pi pi-check':isSelected(option)}\"></span>\n </div>\n </div>\n <span *ngIf=\"!itemTemplate\">{{option.label}}</span>\n <ng-container *ngTemplateOutlet=\"itemTemplate; context: {$implicit: option, index: i}\"></ng-container>\n </li>\n </ul>\n </div>\n <div class=\"ui-listbox-footer ui-widget-header ui-corner-all\" *ngIf=\"footerFacet\">\n <ng-content select=\"p-footer\"></ng-content>\n </div>\n </div>\n ",
- providers: [exports.LISTBOX_VALUE_ACCESSOR]
- }),
- __metadata("design:paramtypes", [core_1.ElementRef, core_1.ChangeDetectorRef])
- ], Listbox);
- return Listbox;
- }());
- exports.Listbox = Listbox;
- var ListboxModule = /** @class */ (function () {
- function ListboxModule() {
- }
- ListboxModule = __decorate([
- core_1.NgModule({
- imports: [common_1.CommonModule, shared_1.SharedModule],
- exports: [Listbox, shared_1.SharedModule],
- declarations: [Listbox]
- })
- ], ListboxModule);
- return ListboxModule;
- }());
- exports.ListboxModule = ListboxModule;
- //# sourceMappingURL=listbox.js.map
|