UNPKG

44.6 kBJavaScriptView Raw
1(function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory(require("@angular/core"), require("@angular/common"), require("@angular/forms"), require("@angular/platform-browser"));
4 else if(typeof define === 'function' && define.amd)
5 define(["@angular/core", "@angular/common", "@angular/forms", "@angular/platform-browser"], factory);
6 else if(typeof exports === 'object')
7 exports["ng2-select.umd"] = factory(require("@angular/core"), require("@angular/common"), require("@angular/forms"), require("@angular/platform-browser"));
8 else
9 root["ng2-select.umd"] = factory(root["@angular/core"], root["@angular/common"], root["@angular/forms"], root["@angular/platform-browser"]);
10})(this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_10__) {
11return /******/ (function(modules) { // webpackBootstrap
12/******/ // The module cache
13/******/ var installedModules = {};
14/******/
15/******/ // The require function
16/******/ function __webpack_require__(moduleId) {
17/******/
18/******/ // Check if module is in cache
19/******/ if(installedModules[moduleId]) {
20/******/ return installedModules[moduleId].exports;
21/******/ }
22/******/ // Create a new module (and put it into the cache)
23/******/ var module = installedModules[moduleId] = {
24/******/ i: moduleId,
25/******/ l: false,
26/******/ exports: {}
27/******/ };
28/******/
29/******/ // Execute the module function
30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31/******/
32/******/ // Flag the module as loaded
33/******/ module.l = true;
34/******/
35/******/ // Return the exports of the module
36/******/ return module.exports;
37/******/ }
38/******/
39/******/
40/******/ // expose the modules object (__webpack_modules__)
41/******/ __webpack_require__.m = modules;
42/******/
43/******/ // expose the module cache
44/******/ __webpack_require__.c = installedModules;
45/******/
46/******/ // define getter function for harmony exports
47/******/ __webpack_require__.d = function(exports, name, getter) {
48/******/ if(!__webpack_require__.o(exports, name)) {
49/******/ Object.defineProperty(exports, name, {
50/******/ configurable: false,
51/******/ enumerable: true,
52/******/ get: getter
53/******/ });
54/******/ }
55/******/ };
56/******/
57/******/ // getDefaultExport function for compatibility with non-harmony modules
58/******/ __webpack_require__.n = function(module) {
59/******/ var getter = module && module.__esModule ?
60/******/ function getDefault() { return module['default']; } :
61/******/ function getModuleExports() { return module; };
62/******/ __webpack_require__.d(getter, 'a', getter);
63/******/ return getter;
64/******/ };
65/******/
66/******/ // Object.prototype.hasOwnProperty.call
67/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
68/******/
69/******/ // __webpack_public_path__
70/******/ __webpack_require__.p = "/";
71/******/
72/******/ // Load entry module and return exports
73/******/ return __webpack_require__(__webpack_require__.s = 6);
74/******/ })
75/************************************************************************/
76/******/ ([
77/* 0 */
78/***/ (function(module, exports) {
79
80module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
81
82/***/ }),
83/* 1 */
84/***/ (function(module, exports, __webpack_require__) {
85
86"use strict";
87
88Object.defineProperty(exports, "__esModule", { value: true });
89function escapeRegexp(queryToEscape) {
90 return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
91}
92exports.escapeRegexp = escapeRegexp;
93
94
95/***/ }),
96/* 2 */
97/***/ (function(module, exports, __webpack_require__) {
98
99"use strict";
100
101var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
102 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
103 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
104 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;
105 return c > 3 && r && Object.defineProperty(target, key, r), r;
106};
107Object.defineProperty(exports, "__esModule", { value: true });
108var core_1 = __webpack_require__(0);
109var common_1 = __webpack_require__(1);
110var HighlightPipe = (function () {
111 function HighlightPipe() {
112 }
113 HighlightPipe.prototype.transform = function (value, query) {
114 if (query.length < 1) {
115 return value;
116 }
117 if (query) {
118 var tagRE = new RegExp('<[^<>]*>', 'ig');
119 // get ist of tags
120 var tagList = value.match(tagRE);
121 // Replace tags with token
122 var tmpValue = value.replace(tagRE, '$!$');
123 // Replace search words
124 value = tmpValue.replace(new RegExp(common_1.escapeRegexp(query), 'gi'), '<strong>$&</strong>');
125 // Reinsert HTML
126 for (var i = 0; value.indexOf('$!$') > -1; i++) {
127 value = value.replace('$!$', tagList[i]);
128 }
129 }
130 return value;
131 };
132 HighlightPipe = __decorate([
133 core_1.Pipe({ name: 'highlight' })
134 ], HighlightPipe);
135 return HighlightPipe;
136}());
137exports.HighlightPipe = HighlightPipe;
138function stripTags(input) {
139 var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
140 var commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
141 return input.replace(commentsAndPhpTags, '').replace(tags, '');
142}
143exports.stripTags = stripTags;
144
145
146/***/ }),
147/* 3 */
148/***/ (function(module, exports, __webpack_require__) {
149
150"use strict";
151
152var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
153 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
154 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
155 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;
156 return c > 3 && r && Object.defineProperty(target, key, r), r;
157};
158var __metadata = (this && this.__metadata) || function (k, v) {
159 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
160};
161Object.defineProperty(exports, "__esModule", { value: true });
162var core_1 = __webpack_require__(0);
163var OffClickDirective = (function () {
164 function OffClickDirective() {
165 }
166 /* tslint:enable */
167 OffClickDirective.prototype.onClick = function ($event) {
168 $event.stopPropagation();
169 };
170 OffClickDirective.prototype.ngOnInit = function () {
171 var _this = this;
172 setTimeout(function () { if (typeof document !== 'undefined') {
173 document.addEventListener('click', _this.offClickHandler);
174 } }, 0);
175 };
176 OffClickDirective.prototype.ngOnDestroy = function () {
177 if (typeof document !== 'undefined') {
178 document.removeEventListener('click', this.offClickHandler);
179 }
180 };
181 __decorate([
182 core_1.Input('offClick'),
183 __metadata("design:type", Object)
184 ], OffClickDirective.prototype, "offClickHandler", void 0);
185 __decorate([
186 core_1.HostListener('click', ['$event']),
187 __metadata("design:type", Function),
188 __metadata("design:paramtypes", [Object]),
189 __metadata("design:returntype", void 0)
190 ], OffClickDirective.prototype, "onClick", null);
191 OffClickDirective = __decorate([
192 core_1.Directive({
193 selector: '[offClick]'
194 })
195 ], OffClickDirective);
196 return OffClickDirective;
197}());
198exports.OffClickDirective = OffClickDirective;
199
200
201/***/ }),
202/* 4 */
203/***/ (function(module, exports, __webpack_require__) {
204
205"use strict";
206
207var __extends = (this && this.__extends) || (function () {
208 var extendStatics = Object.setPrototypeOf ||
209 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
210 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
211 return function (d, b) {
212 extendStatics(d, b);
213 function __() { this.constructor = d; }
214 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
215 };
216})();
217var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
218 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
219 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
220 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;
221 return c > 3 && r && Object.defineProperty(target, key, r), r;
222};
223var __metadata = (this && this.__metadata) || function (k, v) {
224 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
225};
226Object.defineProperty(exports, "__esModule", { value: true });
227var core_1 = __webpack_require__(0);
228var forms_1 = __webpack_require__(9);
229var platform_browser_1 = __webpack_require__(10);
230var select_item_1 = __webpack_require__(5);
231var select_pipes_1 = __webpack_require__(2);
232var common_1 = __webpack_require__(1);
233var styles = "\n .ui-select-toggle {\n position: relative;\n }\n\n /* Fix caret going into new line in Firefox */\n .ui-select-placeholder {\n float: left;\n }\n \n /* Fix Bootstrap dropdown position when inside a input-group */\n .input-group > .dropdown {\n /* Instead of relative */\n position: static;\n }\n \n .ui-select-match > .btn {\n /* Instead of center because of .btn */\n text-align: left !important;\n }\n \n .ui-select-match > .caret {\n position: absolute;\n top: 45%;\n right: 15px;\n }\n \n .ui-disabled {\n background-color: #eceeef;\n border-radius: 4px;\n position: absolute;\n width: 100%;\n height: 100%;\n z-index: 5;\n opacity: 0.6;\n top: 0;\n left: 0;\n cursor: not-allowed;\n }\n \n .ui-select-choices {\n width: 100%;\n height: auto;\n max-height: 200px;\n overflow-x: hidden;\n margin-top: 0;\n }\n \n .ui-select-multiple .ui-select-choices {\n margin-top: 1px;\n }\n .ui-select-choices-row>a {\n display: block;\n padding: 3px 20px;\n clear: both;\n font-weight: 400;\n line-height: 1.42857143;\n color: #333;\n white-space: nowrap;\n }\n .ui-select-choices-row.active>a {\n color: #fff;\n text-decoration: none;\n outline: 0;\n background-color: #428bca;\n }\n \n .ui-select-multiple {\n height: auto;\n padding:3px 3px 0 3px;\n }\n \n .ui-select-multiple input.ui-select-search {\n background-color: transparent !important; /* To prevent double background when disabled */\n border: none;\n outline: none;\n box-shadow: none;\n height: 1.6666em;\n padding: 0;\n margin-bottom: 3px;\n \n }\n .ui-select-match .close {\n font-size: 1.6em;\n line-height: 0.75;\n }\n \n .ui-select-multiple .ui-select-match-item {\n outline: 0;\n margin: 0 3px 3px 0;\n }\n .ui-select-toggle > .caret {\n position: absolute;\n height: 10px;\n top: 50%;\n right: 10px;\n margin-top: -2px;\n }\n";
234var SelectComponent = (function () {
235 function SelectComponent(element, sanitizer) {
236 this.sanitizer = sanitizer;
237 this.allowClear = false;
238 this.placeholder = '';
239 this.idField = 'id';
240 this.textField = 'text';
241 this.childrenField = 'children';
242 this.multiple = false;
243 this.data = new core_1.EventEmitter();
244 this.selected = new core_1.EventEmitter();
245 this.removed = new core_1.EventEmitter();
246 this.typed = new core_1.EventEmitter();
247 this.opened = new core_1.EventEmitter();
248 this.options = [];
249 this.itemObjects = [];
250 this.onChange = Function.prototype;
251 this.onTouched = Function.prototype;
252 this.inputMode = false;
253 this._optionsOpened = false;
254 this.inputValue = '';
255 this._items = [];
256 this._disabled = false;
257 this._active = [];
258 this.element = element;
259 this.clickedOutside = this.clickedOutside.bind(this);
260 }
261 SelectComponent_1 = SelectComponent;
262 Object.defineProperty(SelectComponent.prototype, "items", {
263 set: function (value) {
264 var _this = this;
265 if (!value) {
266 this._items = this.itemObjects = [];
267 }
268 else {
269 this._items = value.filter(function (item) {
270 if ((typeof item === 'string') || (typeof item === 'object' && item && item[_this.textField] && item[_this.idField])) {
271 return item;
272 }
273 });
274 this.itemObjects = this._items.map(function (item) { return (typeof item === 'string' ? new select_item_1.SelectItem(item) : new select_item_1.SelectItem({ id: item[_this.idField], text: item[_this.textField], children: item[_this.childrenField] })); });
275 }
276 },
277 enumerable: true,
278 configurable: true
279 });
280 Object.defineProperty(SelectComponent.prototype, "disabled", {
281 get: function () {
282 return this._disabled;
283 },
284 set: function (value) {
285 this._disabled = value;
286 if (this._disabled === true) {
287 this.hideOptions();
288 }
289 },
290 enumerable: true,
291 configurable: true
292 });
293 Object.defineProperty(SelectComponent.prototype, "active", {
294 get: function () {
295 return this._active;
296 },
297 set: function (selectedItems) {
298 var _this = this;
299 if (!selectedItems || selectedItems.length === 0) {
300 this._active = [];
301 }
302 else {
303 var areItemsStrings_1 = typeof selectedItems[0] === 'string';
304 this._active = selectedItems.map(function (item) {
305 var data = areItemsStrings_1
306 ? item
307 : { id: item[_this.idField], text: item[_this.textField] };
308 return new select_item_1.SelectItem(data);
309 });
310 }
311 },
312 enumerable: true,
313 configurable: true
314 });
315 Object.defineProperty(SelectComponent.prototype, "optionsOpened", {
316 get: function () {
317 return this._optionsOpened;
318 },
319 set: function (value) {
320 this._optionsOpened = value;
321 this.opened.emit(value);
322 },
323 enumerable: true,
324 configurable: true
325 });
326 SelectComponent.prototype.sanitize = function (html) {
327 return this.sanitizer.bypassSecurityTrustHtml(html);
328 };
329 SelectComponent.prototype.inputEvent = function (e, isUpMode) {
330 if (isUpMode === void 0) { isUpMode = false; }
331 // tab
332 if (e.keyCode === 9) {
333 return;
334 }
335 if (isUpMode && (e.keyCode === 37 || e.keyCode === 39 || e.keyCode === 38 ||
336 e.keyCode === 40 || e.keyCode === 13)) {
337 e.preventDefault();
338 return;
339 }
340 // backspace
341 if (!isUpMode && e.keyCode === 8) {
342 var el = this.element.nativeElement
343 .querySelector('div.ui-select-container > input');
344 if (!el.value || el.value.length <= 0) {
345 if (this.active.length > 0) {
346 this.remove(this.active[this.active.length - 1]);
347 }
348 e.preventDefault();
349 }
350 }
351 // esc
352 if (!isUpMode && e.keyCode === 27) {
353 this.hideOptions();
354 this.element.nativeElement.children[0].focus();
355 e.preventDefault();
356 return;
357 }
358 // del
359 if (!isUpMode && e.keyCode === 46) {
360 if (this.active.length > 0) {
361 this.remove(this.active[this.active.length - 1]);
362 }
363 e.preventDefault();
364 }
365 // left
366 if (!isUpMode && e.keyCode === 37 && this._items.length > 0) {
367 this.behavior.first();
368 e.preventDefault();
369 return;
370 }
371 // right
372 if (!isUpMode && e.keyCode === 39 && this._items.length > 0) {
373 this.behavior.last();
374 e.preventDefault();
375 return;
376 }
377 // up
378 if (!isUpMode && e.keyCode === 38) {
379 this.behavior.prev();
380 e.preventDefault();
381 return;
382 }
383 // down
384 if (!isUpMode && e.keyCode === 40) {
385 this.behavior.next();
386 e.preventDefault();
387 return;
388 }
389 // enter
390 if (!isUpMode && e.keyCode === 13) {
391 if (this.active.indexOf(this.activeOption) === -1) {
392 this.selectActiveMatch();
393 this.behavior.next();
394 }
395 e.preventDefault();
396 return;
397 }
398 var target = e.target || e.srcElement;
399 if (target && target.value) {
400 this.inputValue = target.value;
401 this.behavior.filter(new RegExp(common_1.escapeRegexp(this.inputValue), 'ig'));
402 this.doEvent('typed', this.inputValue);
403 }
404 else {
405 this.open();
406 }
407 };
408 SelectComponent.prototype.ngOnInit = function () {
409 this.behavior = (this.firstItemHasChildren) ?
410 new ChildrenBehavior(this) : new GenericBehavior(this);
411 };
412 SelectComponent.prototype.remove = function (item) {
413 if (this._disabled === true) {
414 return;
415 }
416 if (this.multiple === true && this.active) {
417 var index = this.active.indexOf(item);
418 this.active.splice(index, 1);
419 this.data.next(this.active);
420 this.doEvent('removed', item);
421 }
422 if (this.multiple === false) {
423 this.active = [];
424 this.data.next(this.active);
425 this.doEvent('removed', item);
426 }
427 };
428 SelectComponent.prototype.doEvent = function (type, value) {
429 if (this[type] && value) {
430 this[type].next(value);
431 }
432 this.onTouched();
433 if (type === 'selected' || type === 'removed') {
434 this.onChange(this.active);
435 }
436 };
437 SelectComponent.prototype.clickedOutside = function () {
438 this.inputMode = false;
439 this.optionsOpened = false;
440 };
441 Object.defineProperty(SelectComponent.prototype, "firstItemHasChildren", {
442 get: function () {
443 return this.itemObjects[0] && this.itemObjects[0].hasChildren();
444 },
445 enumerable: true,
446 configurable: true
447 });
448 SelectComponent.prototype.writeValue = function (val) {
449 this.active = val;
450 this.data.emit(this.active);
451 };
452 SelectComponent.prototype.validate = function (c) {
453 var controlValue = c ? c.value : [];
454 if (!controlValue) {
455 controlValue = [];
456 }
457 return (controlValue.length > 0) ? null : {
458 ng2SelectEmptyError: {
459 valid: false
460 }
461 };
462 };
463 SelectComponent.prototype.registerOnChange = function (fn) { this.onChange = fn; };
464 SelectComponent.prototype.registerOnTouched = function (fn) { this.onTouched = fn; };
465 SelectComponent.prototype.matchClick = function (e) {
466 if (this._disabled === true) {
467 return;
468 }
469 this.inputMode = !this.inputMode;
470 if (this.inputMode === true && ((this.multiple === true && e) || this.multiple === false)) {
471 this.focusToInput();
472 this.open();
473 }
474 };
475 SelectComponent.prototype.mainClick = function (event) {
476 if (this.inputMode === true || this._disabled === true) {
477 return;
478 }
479 if (event.keyCode === 46) {
480 event.preventDefault();
481 this.inputEvent(event);
482 return;
483 }
484 if (event.keyCode === 8) {
485 event.preventDefault();
486 this.inputEvent(event, true);
487 return;
488 }
489 if (event.keyCode === 9 || event.keyCode === 13 ||
490 event.keyCode === 27 || (event.keyCode >= 37 && event.keyCode <= 40)) {
491 event.preventDefault();
492 return;
493 }
494 this.inputMode = true;
495 var value = String
496 .fromCharCode(96 <= event.keyCode && event.keyCode <= 105 ? event.keyCode - 48 : event.keyCode)
497 .toLowerCase();
498 this.focusToInput(value);
499 this.open();
500 var target = event.target || event.srcElement;
501 target.value = value;
502 this.inputEvent(event);
503 };
504 SelectComponent.prototype.selectActive = function (value) {
505 this.activeOption = value;
506 };
507 SelectComponent.prototype.isActive = function (value) {
508 return this.activeOption.id === value.id;
509 };
510 SelectComponent.prototype.removeClick = function (value, event) {
511 event.stopPropagation();
512 this.remove(value);
513 };
514 SelectComponent.prototype.focusToInput = function (value) {
515 var _this = this;
516 if (value === void 0) { value = ''; }
517 setTimeout(function () {
518 var el = _this.element.nativeElement.querySelector('div.ui-select-container > input');
519 if (el) {
520 el.focus();
521 el.value = value;
522 }
523 }, 0);
524 };
525 SelectComponent.prototype.open = function () {
526 var _this = this;
527 this.options = this.itemObjects
528 .filter(function (option) { return (_this.multiple === false ||
529 _this.multiple === true && !_this.active.find(function (o) { return option.text === o.text; })); });
530 if (this.options.length > 0) {
531 this.behavior.first();
532 }
533 this.optionsOpened = true;
534 };
535 SelectComponent.prototype.hideOptions = function () {
536 this.inputMode = false;
537 this.optionsOpened = false;
538 };
539 SelectComponent.prototype.selectActiveMatch = function () {
540 this.selectMatch(this.activeOption);
541 };
542 SelectComponent.prototype.selectMatch = function (value, e) {
543 if (e === void 0) { e = void 0; }
544 if (e) {
545 e.stopPropagation();
546 e.preventDefault();
547 }
548 if (this.options.length <= 0) {
549 return;
550 }
551 if (this.multiple === true) {
552 this.active.push(value);
553 this.data.next(this.active);
554 }
555 if (this.multiple === false) {
556 this.active[0] = value;
557 this.data.next(this.active[0]);
558 }
559 this.doEvent('selected', value);
560 this.hideOptions();
561 if (this.multiple === true) {
562 this.focusToInput('');
563 }
564 else {
565 this.focusToInput(select_pipes_1.stripTags(value.text));
566 this.element.nativeElement.querySelector('.ui-select-container').focus();
567 }
568 };
569 __decorate([
570 core_1.Input(),
571 __metadata("design:type", Boolean)
572 ], SelectComponent.prototype, "allowClear", void 0);
573 __decorate([
574 core_1.Input(),
575 __metadata("design:type", String)
576 ], SelectComponent.prototype, "placeholder", void 0);
577 __decorate([
578 core_1.Input(),
579 __metadata("design:type", String)
580 ], SelectComponent.prototype, "idField", void 0);
581 __decorate([
582 core_1.Input(),
583 __metadata("design:type", String)
584 ], SelectComponent.prototype, "textField", void 0);
585 __decorate([
586 core_1.Input(),
587 __metadata("design:type", String)
588 ], SelectComponent.prototype, "childrenField", void 0);
589 __decorate([
590 core_1.Input(),
591 __metadata("design:type", Boolean)
592 ], SelectComponent.prototype, "multiple", void 0);
593 __decorate([
594 core_1.Input(),
595 __metadata("design:type", Object),
596 __metadata("design:paramtypes", [Object])
597 ], SelectComponent.prototype, "items", null);
598 __decorate([
599 core_1.Input(),
600 __metadata("design:type", Boolean),
601 __metadata("design:paramtypes", [Boolean])
602 ], SelectComponent.prototype, "disabled", null);
603 __decorate([
604 core_1.Input(),
605 __metadata("design:type", Object),
606 __metadata("design:paramtypes", [Object])
607 ], SelectComponent.prototype, "active", null);
608 __decorate([
609 core_1.Output(),
610 __metadata("design:type", typeof (_a = typeof core_1.EventEmitter !== "undefined" && core_1.EventEmitter) === "function" && _a || Object)
611 ], SelectComponent.prototype, "data", void 0);
612 __decorate([
613 core_1.Output(),
614 __metadata("design:type", typeof (_b = typeof core_1.EventEmitter !== "undefined" && core_1.EventEmitter) === "function" && _b || Object)
615 ], SelectComponent.prototype, "selected", void 0);
616 __decorate([
617 core_1.Output(),
618 __metadata("design:type", typeof (_c = typeof core_1.EventEmitter !== "undefined" && core_1.EventEmitter) === "function" && _c || Object)
619 ], SelectComponent.prototype, "removed", void 0);
620 __decorate([
621 core_1.Output(),
622 __metadata("design:type", typeof (_d = typeof core_1.EventEmitter !== "undefined" && core_1.EventEmitter) === "function" && _d || Object)
623 ], SelectComponent.prototype, "typed", void 0);
624 __decorate([
625 core_1.Output(),
626 __metadata("design:type", typeof (_e = typeof core_1.EventEmitter !== "undefined" && core_1.EventEmitter) === "function" && _e || Object)
627 ], SelectComponent.prototype, "opened", void 0);
628 SelectComponent = SelectComponent_1 = __decorate([
629 core_1.Component({
630 selector: 'ng-select',
631 styles: [styles],
632 providers: [
633 {
634 provide: forms_1.NG_VALUE_ACCESSOR,
635 /* tslint:disable */
636 useExisting: core_1.forwardRef(function () { return SelectComponent_1; }),
637 /* tslint:enable */
638 multi: true
639 },
640 {
641 provide: forms_1.NG_VALIDATORS,
642 useExisting: core_1.forwardRef(function () { return SelectComponent_1; }),
643 multi: true,
644 }
645 ],
646 template: "\n <div tabindex=\"0\"\n *ngIf=\"multiple === false\"\n (keyup)=\"mainClick($event)\"\n [offClick]=\"clickedOutside\"\n class=\"ui-select-container dropdown open\">\n <div [ngClass]=\"{'ui-disabled': disabled}\"></div>\n <div class=\"ui-select-match\"\n *ngIf=\"!inputMode\">\n <span tabindex=\"-1\"\n class=\"btn btn-default btn-secondary form-control ui-select-toggle\"\n (click)=\"matchClick($event)\"\n style=\"outline: 0;\">\n <span *ngIf=\"active.length <= 0\" class=\"ui-select-placeholder text-muted\">{{placeholder}}</span>\n <span *ngIf=\"active.length > 0\" class=\"ui-select-match-text pull-left\"\n [ngClass]=\"{'ui-select-allow-clear': allowClear && active.length > 0}\"\n [innerHTML]=\"sanitize(active[0].text)\"></span>\n <i class=\"dropdown-toggle pull-right\"></i>\n <i class=\"caret pull-right\"></i>\n <a *ngIf=\"allowClear && active.length>0\" class=\"btn btn-xs btn-link pull-right\" style=\"margin-right: 10px; padding: 0;\" (click)=\"removeClick(active[0], $event)\">\n <i class=\"glyphicon glyphicon-remove\"></i>\n </a>\n </span>\n </div>\n <input type=\"text\" autocomplete=\"false\" tabindex=\"-1\"\n (keydown)=\"inputEvent($event)\"\n (keyup)=\"inputEvent($event, true)\"\n [disabled]=\"disabled\"\n class=\"form-control ui-select-search\"\n *ngIf=\"inputMode\"\n placeholder=\"{{active.length <= 0 ? placeholder : ''}}\">\n <!-- options template -->\n <ul *ngIf=\"optionsOpened && options && options.length > 0 && !firstItemHasChildren\"\n class=\"ui-select-choices dropdown-menu\" role=\"menu\">\n <li *ngFor=\"let o of options\" role=\"menuitem\">\n <div class=\"ui-select-choices-row\"\n [class.active]=\"isActive(o)\"\n (mouseenter)=\"selectActive(o)\"\n (click)=\"selectMatch(o, $event)\">\n <a href=\"javascript:void(0)\" class=\"dropdown-item\">\n <div [innerHtml]=\"sanitize(o.text | highlight:inputValue)\"></div>\n </a>\n </div>\n </li>\n </ul>\n \n <ul *ngIf=\"optionsOpened && options && options.length > 0 && firstItemHasChildren\"\n class=\"ui-select-choices dropdown-menu\" role=\"menu\">\n <li *ngFor=\"let c of options; let index=index\" role=\"menuitem\">\n <div class=\"divider dropdown-divider\" *ngIf=\"index > 0\"></div>\n <div class=\"dropdown-header\">{{c.text}}</div>\n \n <div *ngFor=\"let o of c.children\"\n class=\"ui-select-choices-row\"\n [class.active]=\"isActive(o)\"\n (mouseenter)=\"selectActive(o)\"\n (click)=\"selectMatch(o, $event)\"\n [ngClass]=\"{'active': isActive(o)}\">\n <a href=\"javascript:void(0)\" class=\"dropdown-item\">\n <div [innerHtml]=\"sanitize(o.text | highlight:inputValue)\"></div>\n </a>\n </div>\n </li>\n </ul>\n </div>\n\n <div tabindex=\"0\"\n *ngIf=\"multiple === true\"\n (keyup)=\"mainClick($event)\"\n (focus)=\"focusToInput('')\"\n [offClick]=\"clickedOutside\"\n class=\"ui-select-container ui-select-multiple dropdown form-control open\">\n <div [ngClass]=\"{'ui-disabled': disabled}\"></div>\n <span class=\"ui-select-match\">\n <span *ngFor=\"let a of active\">\n <span class=\"ui-select-match-item btn btn-default btn-secondary btn-xs\"\n tabindex=\"-1\"\n type=\"button\"\n [ngClass]=\"{'btn-default': true}\">\n <a class=\"close\"\n style=\"margin-left: 5px; padding: 0;\"\n (click)=\"removeClick(a, $event)\">&times;</a>\n <span [innerHtml]=\"sanitize(a.text)\"></span>\n </span>\n </span>\n </span>\n <input type=\"text\"\n (keydown)=\"inputEvent($event)\"\n (keyup)=\"inputEvent($event, true)\"\n (click)=\"matchClick($event)\"\n [disabled]=\"disabled\"\n autocomplete=\"false\"\n autocorrect=\"off\"\n autocapitalize=\"off\"\n spellcheck=\"false\"\n class=\"form-control ui-select-search\"\n placeholder=\"{{active.length <= 0 ? placeholder : ''}}\"\n role=\"combobox\">\n <!-- options template -->\n <ul *ngIf=\"optionsOpened && options && options.length > 0 && !firstItemHasChildren\"\n class=\"ui-select-choices dropdown-menu\" role=\"menu\">\n <li *ngFor=\"let o of options\" role=\"menuitem\">\n <div class=\"ui-select-choices-row\"\n [class.active]=\"isActive(o)\"\n (mouseenter)=\"selectActive(o)\"\n (click)=\"selectMatch(o, $event)\">\n <a href=\"javascript:void(0)\" class=\"dropdown-item\">\n <div [innerHtml]=\"sanitize(o.text | highlight:inputValue)\"></div>\n </a>\n </div>\n </li>\n </ul>\n \n <ul *ngIf=\"optionsOpened && options && options.length > 0 && firstItemHasChildren\"\n class=\"ui-select-choices dropdown-menu\" role=\"menu\">\n <li *ngFor=\"let c of options; let index=index\" role=\"menuitem\">\n <div class=\"divider dropdown-divider\" *ngIf=\"index > 0\"></div>\n <div class=\"dropdown-header\">{{c.text}}</div>\n \n <div *ngFor=\"let o of c.children\"\n class=\"ui-select-choices-row\"\n [class.active]=\"isActive(o)\"\n (mouseenter)=\"selectActive(o)\"\n (click)=\"selectMatch(o, $event)\"\n [ngClass]=\"{'active': isActive(o)}\">\n <a href=\"javascript:void(0)\" class=\"dropdown-item\">\n <div [innerHtml]=\"sanitize(o.text | highlight:inputValue)\"></div>\n </a>\n </div>\n </li>\n </ul>\n </div>\n "
647 }),
648 __metadata("design:paramtypes", [typeof (_f = typeof core_1.ElementRef !== "undefined" && core_1.ElementRef) === "function" && _f || Object, typeof (_g = typeof platform_browser_1.DomSanitizer !== "undefined" && platform_browser_1.DomSanitizer) === "function" && _g || Object])
649 ], SelectComponent);
650 return SelectComponent;
651 var SelectComponent_1, _a, _b, _c, _d, _e, _f, _g;
652}());
653exports.SelectComponent = SelectComponent;
654var Behavior = (function () {
655 function Behavior(actor) {
656 this.optionsMap = new Map();
657 this.actor = actor;
658 }
659 Behavior.prototype.fillOptionsMap = function () {
660 var _this = this;
661 this.optionsMap.clear();
662 var startPos = 0;
663 this.actor.itemObjects
664 .map(function (item) {
665 startPos = item.fillChildrenHash(_this.optionsMap, startPos);
666 });
667 };
668 Behavior.prototype.ensureHighlightVisible = function (optionsMap) {
669 if (optionsMap === void 0) { optionsMap = void 0; }
670 var container = this.actor.element.nativeElement.querySelector('.ui-select-choices-content');
671 if (!container) {
672 return;
673 }
674 var choices = container.querySelectorAll('.ui-select-choices-row');
675 if (choices.length < 1) {
676 return;
677 }
678 var activeIndex = this.getActiveIndex(optionsMap);
679 if (activeIndex < 0) {
680 return;
681 }
682 var highlighted = choices[activeIndex];
683 if (!highlighted) {
684 return;
685 }
686 var posY = highlighted.offsetTop + highlighted.clientHeight - container.scrollTop;
687 var height = container.offsetHeight;
688 if (posY > height) {
689 container.scrollTop += posY - height;
690 }
691 else if (posY < highlighted.clientHeight) {
692 container.scrollTop -= highlighted.clientHeight - posY;
693 }
694 };
695 Behavior.prototype.getActiveIndex = function (optionsMap) {
696 if (optionsMap === void 0) { optionsMap = void 0; }
697 var ai = this.actor.options.indexOf(this.actor.activeOption);
698 if (ai < 0 && optionsMap !== void 0) {
699 ai = optionsMap.get(this.actor.activeOption.id);
700 }
701 return ai;
702 };
703 return Behavior;
704}());
705exports.Behavior = Behavior;
706var GenericBehavior = (function (_super) {
707 __extends(GenericBehavior, _super);
708 function GenericBehavior(actor) {
709 return _super.call(this, actor) || this;
710 }
711 GenericBehavior.prototype.first = function () {
712 this.actor.activeOption = this.actor.options[0];
713 _super.prototype.ensureHighlightVisible.call(this);
714 };
715 GenericBehavior.prototype.last = function () {
716 this.actor.activeOption = this.actor.options[this.actor.options.length - 1];
717 _super.prototype.ensureHighlightVisible.call(this);
718 };
719 GenericBehavior.prototype.prev = function () {
720 var index = this.actor.options.indexOf(this.actor.activeOption);
721 this.actor.activeOption = this.actor
722 .options[index - 1 < 0 ? this.actor.options.length - 1 : index - 1];
723 _super.prototype.ensureHighlightVisible.call(this);
724 };
725 GenericBehavior.prototype.next = function () {
726 var index = this.actor.options.indexOf(this.actor.activeOption);
727 this.actor.activeOption = this.actor
728 .options[index + 1 > this.actor.options.length - 1 ? 0 : index + 1];
729 _super.prototype.ensureHighlightVisible.call(this);
730 };
731 GenericBehavior.prototype.filter = function (query) {
732 var _this = this;
733 var options = this.actor.itemObjects
734 .filter(function (option) {
735 return select_pipes_1.stripTags(option.text).match(query) &&
736 (_this.actor.multiple === false ||
737 (_this.actor.multiple === true && _this.actor.active.map(function (item) { return item.id; }).indexOf(option.id) < 0));
738 });
739 this.actor.options = options;
740 if (this.actor.options.length > 0) {
741 this.actor.activeOption = this.actor.options[0];
742 _super.prototype.ensureHighlightVisible.call(this);
743 }
744 };
745 return GenericBehavior;
746}(Behavior));
747exports.GenericBehavior = GenericBehavior;
748var ChildrenBehavior = (function (_super) {
749 __extends(ChildrenBehavior, _super);
750 function ChildrenBehavior(actor) {
751 return _super.call(this, actor) || this;
752 }
753 ChildrenBehavior.prototype.first = function () {
754 this.actor.activeOption = this.actor.options[0].children[0];
755 this.fillOptionsMap();
756 this.ensureHighlightVisible(this.optionsMap);
757 };
758 ChildrenBehavior.prototype.last = function () {
759 this.actor.activeOption =
760 this.actor
761 .options[this.actor.options.length - 1]
762 .children[this.actor.options[this.actor.options.length - 1].children.length - 1];
763 this.fillOptionsMap();
764 this.ensureHighlightVisible(this.optionsMap);
765 };
766 ChildrenBehavior.prototype.prev = function () {
767 var _this = this;
768 var indexParent = this.actor.options
769 .findIndex(function (option) { return _this.actor.activeOption.parent && _this.actor.activeOption.parent.id === option.id; });
770 var index = this.actor.options[indexParent].children
771 .findIndex(function (option) { return _this.actor.activeOption && _this.actor.activeOption.id === option.id; });
772 this.actor.activeOption = this.actor.options[indexParent].children[index - 1];
773 if (!this.actor.activeOption) {
774 if (this.actor.options[indexParent - 1]) {
775 this.actor.activeOption = this.actor
776 .options[indexParent - 1]
777 .children[this.actor.options[indexParent - 1].children.length - 1];
778 }
779 }
780 if (!this.actor.activeOption) {
781 this.last();
782 }
783 this.fillOptionsMap();
784 this.ensureHighlightVisible(this.optionsMap);
785 };
786 ChildrenBehavior.prototype.next = function () {
787 var _this = this;
788 var indexParent = this.actor.options
789 .findIndex(function (option) { return _this.actor.activeOption.parent && _this.actor.activeOption.parent.id === option.id; });
790 var index = this.actor.options[indexParent].children
791 .findIndex(function (option) { return _this.actor.activeOption && _this.actor.activeOption.id === option.id; });
792 this.actor.activeOption = this.actor.options[indexParent].children[index + 1];
793 if (!this.actor.activeOption) {
794 if (this.actor.options[indexParent + 1]) {
795 this.actor.activeOption = this.actor.options[indexParent + 1].children[0];
796 }
797 }
798 if (!this.actor.activeOption) {
799 this.first();
800 }
801 this.fillOptionsMap();
802 this.ensureHighlightVisible(this.optionsMap);
803 };
804 ChildrenBehavior.prototype.filter = function (query) {
805 var options = [];
806 var optionsMap = new Map();
807 var startPos = 0;
808 for (var _i = 0, _a = this.actor.itemObjects; _i < _a.length; _i++) {
809 var si = _a[_i];
810 var children = si.children.filter(function (option) { return query.test(option.text); });
811 startPos = si.fillChildrenHash(optionsMap, startPos);
812 if (children.length > 0) {
813 var newSi = si.getSimilar();
814 newSi.children = children;
815 options.push(newSi);
816 }
817 }
818 this.actor.options = options;
819 if (this.actor.options.length > 0) {
820 this.actor.activeOption = this.actor.options[0].children[0];
821 _super.prototype.ensureHighlightVisible.call(this, optionsMap);
822 }
823 };
824 return ChildrenBehavior;
825}(Behavior));
826exports.ChildrenBehavior = ChildrenBehavior;
827
828
829/***/ }),
830/* 5 */
831/***/ (function(module, exports, __webpack_require__) {
832
833"use strict";
834
835Object.defineProperty(exports, "__esModule", { value: true });
836var SelectItem = (function () {
837 function SelectItem(source) {
838 var _this = this;
839 if (typeof source === 'string') {
840 this.id = this.text = source;
841 }
842 if (typeof source === 'object') {
843 this.id = source.id || source.text;
844 this.text = source.text;
845 if (source.children && source.text) {
846 this.children = source.children.map(function (c) {
847 var r = new SelectItem(c);
848 r.parent = _this;
849 return r;
850 });
851 this.text = source.text;
852 }
853 }
854 }
855 SelectItem.prototype.fillChildrenHash = function (optionsMap, startIndex) {
856 var i = startIndex;
857 this.children.map(function (child) {
858 optionsMap.set(child.id, i++);
859 });
860 return i;
861 };
862 SelectItem.prototype.hasChildren = function () {
863 return this.children && this.children.length > 0;
864 };
865 SelectItem.prototype.getSimilar = function () {
866 var r = new SelectItem(false);
867 r.id = this.id;
868 r.text = this.text;
869 r.parent = this.parent;
870 return r;
871 };
872 return SelectItem;
873}());
874exports.SelectItem = SelectItem;
875
876
877/***/ }),
878/* 6 */
879/***/ (function(module, exports, __webpack_require__) {
880
881"use strict";
882
883function __export(m) {
884 for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
885}
886Object.defineProperty(exports, "__esModule", { value: true });
887__export(__webpack_require__(1));
888__export(__webpack_require__(3));
889__export(__webpack_require__(7));
890__export(__webpack_require__(4));
891__export(__webpack_require__(11));
892__export(__webpack_require__(5));
893__export(__webpack_require__(2));
894
895
896/***/ }),
897/* 7 */
898/***/ (function(module, exports, __webpack_require__) {
899
900"use strict";
901
902var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
903 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
904 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
905 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;
906 return c > 3 && r && Object.defineProperty(target, key, r), r;
907};
908Object.defineProperty(exports, "__esModule", { value: true });
909var core_1 = __webpack_require__(0);
910var common_1 = __webpack_require__(8);
911var select_1 = __webpack_require__(4);
912var select_pipes_1 = __webpack_require__(2);
913var off_click_1 = __webpack_require__(3);
914var SelectModule = (function () {
915 function SelectModule() {
916 }
917 SelectModule = __decorate([
918 core_1.NgModule({
919 imports: [common_1.CommonModule],
920 declarations: [select_1.SelectComponent, select_pipes_1.HighlightPipe, off_click_1.OffClickDirective],
921 exports: [select_1.SelectComponent, select_pipes_1.HighlightPipe, off_click_1.OffClickDirective]
922 })
923 ], SelectModule);
924 return SelectModule;
925}());
926exports.SelectModule = SelectModule;
927
928
929/***/ }),
930/* 8 */
931/***/ (function(module, exports) {
932
933module.exports = __WEBPACK_EXTERNAL_MODULE_8__;
934
935/***/ }),
936/* 9 */
937/***/ (function(module, exports) {
938
939module.exports = __WEBPACK_EXTERNAL_MODULE_9__;
940
941/***/ }),
942/* 10 */
943/***/ (function(module, exports) {
944
945module.exports = __WEBPACK_EXTERNAL_MODULE_10__;
946
947/***/ }),
948/* 11 */
949/***/ (function(module, exports, __webpack_require__) {
950
951"use strict";
952
953Object.defineProperty(exports, "__esModule", { value: true });
954
955
956/***/ })
957/******/ ]);
958});
959//# sourceMappingURL=ng2-select.umd.js.map
\No newline at end of file