sp-combo
Version:
# Angular sp-combo - Multiselect, Multiline and Autocomplete
1,069 lines (1,058 loc) • 158 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@angular/common'), require('rxjs'), require('rxjs/operators')) :
typeof define === 'function' && define.amd ? define('sp-combo', ['exports', '@angular/core', '@angular/forms', '@angular/common', 'rxjs', 'rxjs/operators'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['sp-combo'] = {}, global.ng.core, global.ng.forms, global.ng.common, global.rxjs, global.rxjs.operators));
}(this, (function (exports, i0, forms, common, rxjs, operators) { 'use strict';
var SpComboService = /** @class */ (function () {
function SpComboService() {
}
return SpComboService;
}());
SpComboService.ɵprov = i0.ɵɵdefineInjectable({ factory: function SpComboService_Factory() { return new SpComboService(); }, token: SpComboService, providedIn: "root" });
SpComboService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
SpComboService.ctorParameters = function () { return []; };
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
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 (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(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;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
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;
}
;
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
var noop = function () { };
var ɵ0 = noop;
var SpComboComponent = /** @class */ (function () {
function SpComboComponent() {
this.isDisabled = false;
this.isMultiSelect = false;
this.isLoading = false;
this.closeOnSelect = true;
this.isSelectByGroup = false;
this.isSelectByGroupAsModel = false;
this.selectedRow = new i0.EventEmitter();
this.changeFn = new i0.EventEmitter();
this.blurFn = new i0.EventEmitter();
this.focusFn = new i0.EventEmitter();
this.extraLbl = [];
this.extraVal = [];
this.searchFild = [];
//The internal data model
this.innerValue = "";
//Placeholders for the callbacks which are later provided
//by the Control Value Accessor
this.onTouchedCallback = noop;
this.onChangeCallback = noop;
}
Object.defineProperty(SpComboComponent.prototype, "value", {
//get accessor
get: function () { return this.innerValue; },
//set accessor including call the onchange callback
set: function (v) {
if (v !== this.innerValue) {
this.innerValue = v;
this.onChangeCallback(v);
}
},
enumerable: false,
configurable: true
});
//Set touched on blur
SpComboComponent.prototype.onBlur = function () {
this.onTouchedCallback();
if (this.blurFn != null)
this.blurFn.emit();
};
//From ControlValueAccessor interface
SpComboComponent.prototype.writeValue = function (value) {
if (value !== this.innerValue) {
this.innerValue = value;
}
};
//From ControlValueAccessor interface
SpComboComponent.prototype.registerOnChange = function (fn) {
this.onChangeCallback = fn;
};
//From ControlValueAccessor interface
SpComboComponent.prototype.registerOnTouched = function (fn) {
this.onTouchedCallback = fn;
};
SpComboComponent.prototype.onChange = function ($event) {
// this.selectedRow.emit($event);
this.selectedRow.emit($event);
if (this.changeFn != null)
this.changeFn.emit();
};
SpComboComponent.prototype.findExtra = function (term, lst) {
this.searchFild.forEach(function (itm) {
return lst[itm].toLowerCase().indexOf(term) > -1;
});
};
SpComboComponent.prototype.onSearch = function (trm, lst, a) {
// var term = trm.term.toLowerCase();
// return (
// this.displayList[this.displayField].toLowerCase().indexOf(term) > -1 ||
// this.findExtra(term)
// );
// this.ab = this.searchFild[0];
// return this.displayList[this.displayField].toLowerCase().indexOf(term) > -1 || this.displayList[this.ab].toLowerCase().indexOf(term) > -1 ;
// var ac = this.displayList[this.displayField];
// var vd = this.displayList[this.ab];
// return this.displayList[this.displayField].toLowerCase().indexOf(term) > -1 ;
// return this.displayList[this.ab].toLowerCase().indexOf(term) > -1 ;
// this.displayList.forEach(lst => {
// var m = lst[this.ab].toLowerCase().indexOf(term);
// return lst[this.ab].toLowerCase().indexOf(term) > -1;
// });
var term = trm.toLowerCase();
// return ( lst[this.displayField].toLowerCase().indexOf(term) > -1 || this.findExtra(term, lst) );
// return (
// lst[this.displayField].toLowerCase().indexOf(term) > -1 ||
// lst[this.searchFields].toLowerCase().indexOf(term) > -1
// );
};
SpComboComponent.prototype.onFocus = function (fn) {
if (this.focusFn != null)
this.focusFn.emit();
};
SpComboComponent.prototype.selectAll = function () {
var _this = this;
this.value = this.displayList.map(function (x) { return x[_this.selectedValue]; });
};
SpComboComponent.prototype.unselectAll = function () {
this.value = [];
};
SpComboComponent.prototype.ngOnInit = function () {
if (this.extraValues)
this.extraVal = this.extraValues.split(",");
if (this.extraLables)
this.extraLbl = this.extraLables.split(",");
};
SpComboComponent.prototype.ngOnChanges = function (changes) {
if (!this.placeHolder)
this.placeHolder = "";
if (this.extraValues)
this.extraVal = this.extraValues.split(",");
if (this.extraLables)
this.extraLbl = this.extraLables.split(",");
};
SpComboComponent.prototype.getExtraValue = function (item, idx) {
var e_1, _a;
if (this.extraVal.length > idx) {
var ef = this.extraVal[idx].split(".");
var val = item;
var id = 0;
try {
for (var ef_1 = __values(ef), ef_1_1 = ef_1.next(); !ef_1_1.done; ef_1_1 = ef_1.next()) {
var a = ef_1_1.value;
val = val[a];
id += 1;
if (id == ef.length) {
return val;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (ef_1_1 && !ef_1_1.done && (_a = ef_1.return)) _a.call(ef_1);
}
finally { if (e_1) throw e_1.error; }
}
}
else {
return item;
}
};
return SpComboComponent;
}());
SpComboComponent.decorators = [
{ type: i0.Component, args: [{
selector: 'sp-combo',
template: "<sp-select [placeholder]=\"placeHolder\" [items]=\"displayList\" [bindLabel]=\"displayField\" [bindValue]=\"selectedValue\"\r\n [(ngModel)]=\"value\" (change)=\"onChange($event)\" (blur)=\"onBlur()\" [multiple]=\"isMultiSelect\" [loading]=\"isLoading\"\r\n [groupBy]=\"groupBy\" [closeOnSelect]=\"closeOnSelect\" [selectableGroup]=\"isSelectByGroup\" [disabled]=\"isDisabled\"\r\n [selectableGroupAsModel]=\"isSelectByGroupAsModel\" (focus)=\"onFocus($event)\">\r\n\r\n <ng-template ng-optgroup-tmp let-item=\"item\" *ngIf=\"groupBy!=null && groupBy!=undefined\">\r\n {{item[groupBy] | uppercase}}\r\n <!-- {{item[groupBy] }} -->\r\n </ng-template>\r\n\r\n <ng-template ng-option-tmp let-item=\"item\">\r\n {{item[displayField]}} <br />\r\n\r\n <small *ngFor=\"let lbl of extraLbl; let i = index; let last = last;\">\r\n\r\n {{lbl}} :{{ getExtraValue(item,i) }}\r\n\r\n <span *ngIf=\"!last\">, </span>\r\n </small>\r\n\r\n <ng-template ng-header-tmp *ngIf=\"isMultiSelect==true\">\r\n <button (click)=\"selectAll()\" class=\"btn btn-sm btn-secondary\">Select all</button>\r\n <button (click)=\"unselectAll()\" class=\"btn btn-sm btn-secondary\">Unselect all</button>\r\n </ng-template>\r\n\r\n <ng-template ng-footer-tmp *ngIf=\"isMultiSelect && value!=undefined\">\r\n Selected Count: {{value.length}}\r\n </ng-template>\r\n\r\n </ng-template>\r\n\r\n</sp-select>\r\n\r\n",
providers: [
{
provide: forms.NG_VALUE_ACCESSOR,
useExisting: i0.forwardRef(function () { return SpComboComponent; }),
multi: true
}
]
},] }
];
SpComboComponent.ctorParameters = function () { return []; };
SpComboComponent.propDecorators = {
placeHolder: [{ type: i0.Input }],
displayList: [{ type: i0.Input }],
displayField: [{ type: i0.Input }],
selectedValue: [{ type: i0.Input }],
extraLables: [{ type: i0.Input }],
extraValues: [{ type: i0.Input }],
isDisabled: [{ type: i0.Input }],
isMultiSelect: [{ type: i0.Input }],
isLoading: [{ type: i0.Input }],
groupBy: [{ type: i0.Input }],
closeOnSelect: [{ type: i0.Input }],
isSelectByGroup: [{ type: i0.Input }],
isSelectByGroupAsModel: [{ type: i0.Input }],
selectedRow: [{ type: i0.Output }],
changeFn: [{ type: i0.Output }],
blurFn: [{ type: i0.Output }],
focusFn: [{ type: i0.Output }]
};
var NgDropdownPanelService = /** @class */ (function () {
function NgDropdownPanelService() {
this._dimensions = {
itemHeight: 0,
panelHeight: 0,
itemsPerViewport: 0
};
}
Object.defineProperty(NgDropdownPanelService.prototype, "dimensions", {
get: function () {
return this._dimensions;
},
enumerable: false,
configurable: true
});
NgDropdownPanelService.prototype.calculateItems = function (scrollPos, itemsLength, buffer) {
var d = this._dimensions;
var scrollHeight = d.itemHeight * itemsLength;
var scrollTop = Math.max(0, scrollPos);
var indexByScrollTop = scrollTop / scrollHeight * itemsLength;
var end = Math.min(itemsLength, Math.ceil(indexByScrollTop) + (d.itemsPerViewport + 1));
var maxStartEnd = end;
var maxStart = Math.max(0, maxStartEnd - d.itemsPerViewport);
var start = Math.min(maxStart, Math.floor(indexByScrollTop));
var topPadding = d.itemHeight * Math.ceil(start) - (d.itemHeight * Math.min(start, buffer));
topPadding = !isNaN(topPadding) ? topPadding : 0;
start = !isNaN(start) ? start : -1;
end = !isNaN(end) ? end : -1;
start -= buffer;
start = Math.max(0, start);
end += buffer;
end = Math.min(itemsLength, end);
return {
topPadding: topPadding,
scrollHeight: scrollHeight,
start: start,
end: end
};
};
NgDropdownPanelService.prototype.setDimensions = function (itemHeight, panelHeight) {
var itemsPerViewport = Math.max(1, Math.floor(panelHeight / itemHeight));
this._dimensions = {
itemHeight: itemHeight,
panelHeight: panelHeight,
itemsPerViewport: itemsPerViewport
};
};
NgDropdownPanelService.prototype.getScrollTo = function (itemTop, itemHeight, lastScroll) {
var panelHeight = this.dimensions.panelHeight;
var itemBottom = itemTop + itemHeight;
var top = lastScroll;
var bottom = top + panelHeight;
if (panelHeight >= itemBottom && lastScroll === itemTop) {
return null;
}
if (itemBottom > bottom) {
return top + itemBottom - bottom;
}
else if (itemTop <= top) {
return itemTop;
}
return null;
};
return NgDropdownPanelService;
}());
NgDropdownPanelService.decorators = [
{ type: i0.Injectable }
];
var unescapedHTMLExp = /[&<>"']/g;
var hasUnescapedHTMLExp = RegExp(unescapedHTMLExp.source);
var htmlEscapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
'\'': '''
};
function escapeHTML(string) {
return (string && hasUnescapedHTMLExp.test(string)) ?
string.replace(unescapedHTMLExp, function (chr) { return htmlEscapes[chr]; }) :
string;
}
function isDefined(value) {
return value !== undefined && value !== null;
}
function isObject(value) {
return typeof value === 'object' && isDefined(value);
}
function isPromise(value) {
return value instanceof Promise;
}
function isFunction(value) {
return value instanceof Function;
}
var TOP_CSS_CLASS = 'ng-select-top';
var BOTTOM_CSS_CLASS = 'ng-select-bottom';
var SCROLL_SCHEDULER = typeof requestAnimationFrame !== 'undefined' ? rxjs.animationFrameScheduler : rxjs.asapScheduler;
var NgDropdownPanelComponent = /** @class */ (function () {
function NgDropdownPanelComponent(_renderer, _zone, _panelService, _elementRef, _document) {
this._renderer = _renderer;
this._zone = _zone;
this._panelService = _panelService;
this._document = _document;
this.items = [];
this.position = 'auto';
this.virtualScroll = false;
this.filterValue = null;
this.update = new i0.EventEmitter();
this.scroll = new i0.EventEmitter();
this.scrollToEnd = new i0.EventEmitter();
this.outsideClick = new i0.EventEmitter();
this._destroy$ = new rxjs.Subject();
this._scrollToEndFired = false;
this._updateScrollHeight = false;
this._lastScrollPosition = 0;
this._dropdown = _elementRef.nativeElement;
}
Object.defineProperty(NgDropdownPanelComponent.prototype, "currentPosition", {
get: function () {
return this._currentPosition;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NgDropdownPanelComponent.prototype, "itemsLength", {
get: function () {
return this._itemsLength;
},
set: function (value) {
if (value !== this._itemsLength) {
this._itemsLength = value;
this._onItemsLengthChanged();
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(NgDropdownPanelComponent.prototype, "_startOffset", {
get: function () {
if (this.markedItem) {
var _a = this._panelService.dimensions, itemHeight = _a.itemHeight, panelHeight = _a.panelHeight;
var offset = this.markedItem.index * itemHeight;
return panelHeight > offset ? 0 : offset;
}
return 0;
},
enumerable: false,
configurable: true
});
NgDropdownPanelComponent.prototype.handleMousedown = function ($event) {
var target = $event.target;
if (target.tagName === 'INPUT') {
return;
}
$event.preventDefault();
};
NgDropdownPanelComponent.prototype.ngOnInit = function () {
this._select = this._dropdown.parentElement;
this._virtualPadding = this.paddingElementRef.nativeElement;
this._scrollablePanel = this.scrollElementRef.nativeElement;
this._contentPanel = this.contentElementRef.nativeElement;
this._handleScroll();
this._handleOutsideClick();
this._appendDropdown();
};
NgDropdownPanelComponent.prototype.ngOnChanges = function (changes) {
if (changes.items) {
var change = changes.items;
this._onItemsChange(change.currentValue, change.firstChange);
}
};
NgDropdownPanelComponent.prototype.ngOnDestroy = function () {
this._destroy$.next();
this._destroy$.complete();
this._destroy$.unsubscribe();
if (this.appendTo) {
this._renderer.removeChild(this._dropdown.parentNode, this._dropdown);
}
};
NgDropdownPanelComponent.prototype.scrollTo = function (option, startFromOption) {
if (startFromOption === void 0) { startFromOption = false; }
if (!option) {
return;
}
var index = this.items.indexOf(option);
if (index < 0 || index >= this.itemsLength) {
return;
}
var scrollTo;
if (this.virtualScroll) {
var itemHeight = this._panelService.dimensions.itemHeight;
scrollTo = this._panelService.getScrollTo(index * itemHeight, itemHeight, this._lastScrollPosition);
}
else {
var item = this._dropdown.querySelector("#" + option.htmlId);
var lastScroll = startFromOption ? item.offsetTop : this._lastScrollPosition;
scrollTo = this._panelService.getScrollTo(item.offsetTop, item.clientHeight, lastScroll);
}
if (isDefined(scrollTo)) {
this._scrollablePanel.scrollTop = scrollTo;
}
};
NgDropdownPanelComponent.prototype.scrollToTag = function () {
var panel = this._scrollablePanel;
panel.scrollTop = panel.scrollHeight - panel.clientHeight;
};
NgDropdownPanelComponent.prototype.adjustPosition = function () {
var parent = this._parent.getBoundingClientRect();
var select = this._select.getBoundingClientRect();
this._setOffset(parent, select);
};
NgDropdownPanelComponent.prototype._handleDropdownPosition = function () {
this._currentPosition = this._calculateCurrentPosition(this._dropdown);
if (this._currentPosition === 'top') {
this._renderer.addClass(this._dropdown, TOP_CSS_CLASS);
this._renderer.removeClass(this._dropdown, BOTTOM_CSS_CLASS);
this._renderer.addClass(this._select, TOP_CSS_CLASS);
this._renderer.removeClass(this._select, BOTTOM_CSS_CLASS);
}
else {
this._renderer.addClass(this._dropdown, BOTTOM_CSS_CLASS);
this._renderer.removeClass(this._dropdown, TOP_CSS_CLASS);
this._renderer.addClass(this._select, BOTTOM_CSS_CLASS);
this._renderer.removeClass(this._select, TOP_CSS_CLASS);
}
if (this.appendTo) {
this._updatePosition();
}
this._dropdown.style.opacity = '1';
};
NgDropdownPanelComponent.prototype._handleScroll = function () {
var _this = this;
this._zone.runOutsideAngular(function () {
rxjs.fromEvent(_this.scrollElementRef.nativeElement, 'scroll')
.pipe(operators.takeUntil(_this._destroy$), operators.auditTime(0, SCROLL_SCHEDULER))
.subscribe(function (e) { return _this._onContentScrolled(e.target.scrollTop); });
});
};
NgDropdownPanelComponent.prototype._handleOutsideClick = function () {
var _this = this;
if (!this._document) {
return;
}
this._zone.runOutsideAngular(function () {
rxjs.merge(rxjs.fromEvent(_this._document, 'touchstart', { capture: true }), rxjs.fromEvent(_this._document, 'mousedown', { capture: true })).pipe(operators.takeUntil(_this._destroy$))
.subscribe(function ($event) { return _this._checkToClose($event); });
});
};
NgDropdownPanelComponent.prototype._checkToClose = function ($event) {
var _this = this;
if (this._select.contains($event.target) || this._dropdown.contains($event.target)) {
return;
}
var path = $event.path || ($event.composedPath && $event.composedPath());
if ($event.target && $event.target.shadowRoot && path && path[0] && this._select.contains(path[0])) {
return;
}
this._zone.run(function () { return _this.outsideClick.emit(); });
};
NgDropdownPanelComponent.prototype._onItemsChange = function (items, firstChange) {
this.items = items || [];
this._scrollToEndFired = false;
this.itemsLength = items.length;
if (this.virtualScroll) {
this._updateItemsRange(firstChange);
}
else {
this._updateItems(firstChange);
}
};
NgDropdownPanelComponent.prototype._updateItems = function (firstChange) {
var _this = this;
this.update.emit(this.items);
if (firstChange === false) {
return;
}
this._zone.runOutsideAngular(function () {
Promise.resolve().then(function () {
var panelHeight = _this._scrollablePanel.clientHeight;
_this._panelService.setDimensions(0, panelHeight);
_this._handleDropdownPosition();
_this.scrollTo(_this.markedItem, firstChange);
});
});
};
NgDropdownPanelComponent.prototype._updateItemsRange = function (firstChange) {
var _this = this;
this._zone.runOutsideAngular(function () {
_this._measureDimensions().then(function () {
if (firstChange) {
_this._renderItemsRange(_this._startOffset);
_this._handleDropdownPosition();
}
else {
_this._renderItemsRange();
}
});
});
};
NgDropdownPanelComponent.prototype._onContentScrolled = function (scrollTop) {
if (this.virtualScroll) {
this._renderItemsRange(scrollTop);
}
this._lastScrollPosition = scrollTop;
this._fireScrollToEnd(scrollTop);
};
NgDropdownPanelComponent.prototype._updateVirtualHeight = function (height) {
if (this._updateScrollHeight) {
this._virtualPadding.style.height = height + "px";
this._updateScrollHeight = false;
}
};
NgDropdownPanelComponent.prototype._onItemsLengthChanged = function () {
this._updateScrollHeight = true;
};
NgDropdownPanelComponent.prototype._renderItemsRange = function (scrollTop) {
var _this = this;
if (scrollTop === void 0) { scrollTop = null; }
if (scrollTop && this._lastScrollPosition === scrollTop) {
return;
}
scrollTop = scrollTop || this._scrollablePanel.scrollTop;
var range = this._panelService.calculateItems(scrollTop, this.itemsLength, this.bufferAmount);
this._updateVirtualHeight(range.scrollHeight);
this._contentPanel.style.transform = "translateY(" + range.topPadding + "px)";
this._zone.run(function () {
_this.update.emit(_this.items.slice(range.start, range.end));
_this.scroll.emit({ start: range.start, end: range.end });
});
if (isDefined(scrollTop) && this._lastScrollPosition === 0) {
this._scrollablePanel.scrollTop = scrollTop;
this._lastScrollPosition = scrollTop;
}
};
NgDropdownPanelComponent.prototype._measureDimensions = function () {
var _this = this;
if (this._panelService.dimensions.itemHeight > 0 || this.itemsLength === 0) {
return Promise.resolve(this._panelService.dimensions);
}
var _a = __read(this.items, 1), first = _a[0];
this.update.emit([first]);
return Promise.resolve().then(function () {
var option = _this._dropdown.querySelector("#" + first.htmlId);
var optionHeight = option.clientHeight;
_this._virtualPadding.style.height = optionHeight * _this.itemsLength + "px";
var panelHeight = _this._scrollablePanel.clientHeight;
_this._panelService.setDimensions(optionHeight, panelHeight);
return _this._panelService.dimensions;
});
};
NgDropdownPanelComponent.prototype._fireScrollToEnd = function (scrollTop) {
var _this = this;
if (this._scrollToEndFired || scrollTop === 0) {
return;
}
var padding = this.virtualScroll ?
this._virtualPadding :
this._contentPanel;
if (scrollTop + this._dropdown.clientHeight >= padding.clientHeight) {
this._zone.run(function () { return _this.scrollToEnd.emit(); });
this._scrollToEndFired = true;
}
};
NgDropdownPanelComponent.prototype._calculateCurrentPosition = function (dropdownEl) {
if (this.position !== 'auto') {
return this.position;
}
var selectRect = this._select.getBoundingClientRect();
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var offsetTop = selectRect.top + window.pageYOffset;
var height = selectRect.height;
var dropdownHeight = dropdownEl.getBoundingClientRect().height;
if (offsetTop + height + dropdownHeight > scrollTop + document.documentElement.clientHeight) {
return 'top';
}
else {
return 'bottom';
}
};
NgDropdownPanelComponent.prototype._appendDropdown = function () {
if (!this.appendTo) {
return;
}
this._parent = document.querySelector(this.appendTo);
if (!parent) {
throw new Error("appendTo selector " + this.appendTo + " did not found any parent element");
}
this._parent.appendChild(this._dropdown);
};
NgDropdownPanelComponent.prototype._updatePosition = function () {
var select = this._select.getBoundingClientRect();
var parent = this._parent.getBoundingClientRect();
var offsetLeft = select.left - parent.left;
this._setOffset(parent, select);
this._dropdown.style.left = offsetLeft + 'px';
this._dropdown.style.width = select.width + 'px';
this._dropdown.style.minWidth = select.width + 'px';
};
NgDropdownPanelComponent.prototype._setOffset = function (parent, select) {
var delta = select.height;
if (this._currentPosition === 'top') {
var offsetBottom = parent.bottom - select.bottom;
this._dropdown.style.bottom = offsetBottom + delta + 'px';
this._dropdown.style.top = 'auto';
}
else if (this._currentPosition === 'bottom') {
var offsetTop = select.top - parent.top;
this._dropdown.style.top = offsetTop + delta + 'px';
this._dropdown.style.bottom = 'auto';
}
};
return NgDropdownPanelComponent;
}());
NgDropdownPanelComponent.decorators = [
{ type: i0.Component, args: [{
changeDetection: i0.ChangeDetectionStrategy.OnPush,
encapsulation: i0.ViewEncapsulation.None,
selector: 'ng-dropdown-panel',
template: "\n <div *ngIf=\"headerTemplate\" class=\"ng-dropdown-header\">\n <ng-container [ngTemplateOutlet]=\"headerTemplate\" [ngTemplateOutletContext]=\"{ searchTerm: filterValue }\"></ng-container>\n </div>\n <div #scroll class=\"ng-dropdown-panel-items scroll-host\">\n <div #padding [class.total-padding]=\"virtualScroll\"></div>\n <div #content [class.scrollable-content]=\"virtualScroll && items.length\">\n <ng-content></ng-content>\n </div>\n </div>\n <div *ngIf=\"footerTemplate\" class=\"ng-dropdown-footer\">\n <ng-container [ngTemplateOutlet]=\"footerTemplate\" [ngTemplateOutletContext]=\"{ searchTerm: filterValue }\"></ng-container>\n </div>\n "
},] }
];
NgDropdownPanelComponent.ctorParameters = function () { return [
{ type: i0.Renderer2 },
{ type: i0.NgZone },
{ type: NgDropdownPanelService },
{ type: i0.ElementRef },
{ type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [common.DOCUMENT,] }] }
]; };
NgDropdownPanelComponent.propDecorators = {
items: [{ type: i0.Input }],
markedItem: [{ type: i0.Input }],
position: [{ type: i0.Input }],
appendTo: [{ type: i0.Input }],
bufferAmount: [{ type: i0.Input }],
virtualScroll: [{ type: i0.Input }],
headerTemplate: [{ type: i0.Input }],
footerTemplate: [{ type: i0.Input }],
filterValue: [{ type: i0.Input }],
update: [{ type: i0.Output }],
scroll: [{ type: i0.Output }],
scrollToEnd: [{ type: i0.Output }],
outsideClick: [{ type: i0.Output }],
contentElementRef: [{ type: i0.ViewChild, args: ['content', { read: i0.ElementRef, static: true },] }],
scrollElementRef: [{ type: i0.ViewChild, args: ['scroll', { read: i0.ElementRef, static: true },] }],
paddingElementRef: [{ type: i0.ViewChild, args: ['padding', { read: i0.ElementRef, static: true },] }],
handleMousedown: [{ type: i0.HostListener, args: ['mousedown', ['$event'],] }]
};
var NgOptionComponent = /** @class */ (function () {
function NgOptionComponent(elementRef) {
this.elementRef = elementRef;
this.stateChange$ = new rxjs.Subject();
this._disabled = false;
}
Object.defineProperty(NgOptionComponent.prototype, "disabled", {
get: function () { return this._disabled; },
set: function (value) { this._disabled = this._isDisabled(value); },
enumerable: false,
configurable: true
});
Object.defineProperty(NgOptionComponent.prototype, "label", {
get: function () {
return (this.elementRef.nativeElement.textContent || '').trim();
},
enumerable: false,
configurable: true
});
NgOptionComponent.prototype.ngOnChanges = function (changes) {
if (changes.disabled) {
this.stateChange$.next({
value: this.value,
disabled: this._disabled
});
}
};
NgOptionComponent.prototype.ngAfterViewChecked = function () {
if (this.label !== this._previousLabel) {
this._previousLabel = this.label;
this.stateChange$.next({
value: this.value,
disabled: this._disabled,
label: this.elementRef.nativeElement.innerHTML
});
}
};
NgOptionComponent.prototype.ngOnDestroy = function () {
this.stateChange$.complete();
};
NgOptionComponent.prototype._isDisabled = function (value) {
return value != null && "" + value !== 'false';
};
return NgOptionComponent;
}());
NgOptionComponent.decorators = [
{ type: i0.Component, args: [{
selector: 'ng-option',
changeDetection: i0.ChangeDetectionStrategy.OnPush,
template: "<ng-content></ng-content>"
},] }
];
NgOptionComponent.ctorParameters = function () { return [
{ type: i0.ElementRef }
]; };
NgOptionComponent.propDecorators = {
value: [{ type: i0.Input }],
disabled: [{ type: i0.Input }]
};
var NgItemLabelDirective = /** @class */ (function () {
function NgItemLabelDirective(element) {
this.element = element;
this.escape = true;
}
NgItemLabelDirective.prototype.ngOnChanges = function (changes) {
this.element.nativeElement.innerHTML = this.escape ?
escapeHTML(this.ngItemLabel) :
this.ngItemLabel;
};
return NgItemLabelDirective;
}());
NgItemLabelDirective.decorators = [
{ type: i0.Directive, args: [{ selector: '[ngItemLabel]' },] }
];
NgItemLabelDirective.ctorParameters = function () { return [
{ type: i0.ElementRef }
]; };
NgItemLabelDirective.propDecorators = {
ngItemLabel: [{ type: i0.Input }],
escape: [{ type: i0.Input }]
};
var NgOptionTemplateDirective = /** @class */ (function () {
function NgOptionTemplateDirective(template) {
this.template = template;
}
return NgOptionTemplateDirective;
}());
NgOptionTemplateDirective.decorators = [
{ type: i0.Directive, args: [{ selector: '[ng-option-tmp]' },] }
];
NgOptionTemplateDirective.ctorParameters = function () { return [
{ type: i0.TemplateRef }
]; };
var NgOptgroupTemplateDirective = /** @class */ (function () {
function NgOptgroupTemplateDirective(template) {
this.template = template;
}
return NgOptgroupTemplateDirective;
}());
NgOptgroupTemplateDirective.decorators = [
{ type: i0.Directive, args: [{ selector: '[ng-optgroup-tmp]' },] }
];
NgOptgroupTemplateDirective.ctorParameters = function () { return [
{ type: i0.TemplateRef }
]; };
var NgLabelTemplateDirective = /** @class */ (function () {
function NgLabelTemplateDirective(template) {
this.template = template;
}
return NgLabelTemplateDirective;
}());
NgLabelTemplateDirective.decorators = [
{ type: i0.Directive, args: [{ selector: '[ng-label-tmp]' },] }
];
NgLabelTemplateDirective.ctorParameters = function () { return [
{ type: i0.TemplateRef }
]; };