1 | {"version":3,"file":"typeahead-container.component.js","sourceRoot":"","sources":["../../src/typeahead/typeahead-container.component.ts"],"names":[],"mappings":"OAAO,EACL,SAAS,EAAE,UAAU,EAAe,iBAAiB,EAAE,YAAY,EACpE,MAAM,eAAe;OACf,EAAE,KAAK,EAAE,MAAM,+BAA+B;OAC9C,EAAE,cAAc,EAAE,MAAM,mBAAmB;AAKlD;IAiBE,qCAAmB,OAAmB;QAb/B,cAAS,GAAY,KAAK,CAAC;QAWxB,aAAQ,GAAqB,EAAE,CAAC;QAGxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IATD,sBAAW,8CAAK;aAAhB;YACE,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;;;OAAA;IASD,sBAAW,+CAAM;aAAjB;YACE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;;;OAAA;IAED,sBAAW,gDAAO;aAAlB;YACE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;aAED,UAAmB,KAAuB;YACxC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YAEtB,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAChC,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;oBAC5B,IAAI,CAAC,eAAe,EAAE,CAAC;gBACzB,CAAC;YACH,CAAC;QACH,CAAC;;;OAXA;IAaD,sBAAW,4DAAmB;aAA9B;YACE,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,mBAAmB,GAAG,SAAS,CAAC;QACnE,CAAC;;;OAAA;IAED,sBAAW,qDAAY;aAAvB;YACE,MAAM,CAAC,IAAI,CAAC,MAAM,G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AAqB;oBAC/B,2BAA2B;oBAC3B,QAAQ,EAAE,otDAuCX;oBACC,iBAAiB;oBACjB,IAAI,EAAE;wBACJ,OAAO,EAAE,eAAe;wBACxB,uBAAuB,EAAC,OAAO;wBAC/B,KAAK,EAAE,oCAAoC;qBAC5C;oBACD,iBAAiB;oBACjB,aAAa,EAAE,iBAAiB,CAAC,IAAI;iBACtC,EAAG,EAAE;KACL,CAAC;IACF,kBAAkB;IACX,0CAAc,GAAmE,cAAM,OAAA;QAC9F,EAAC,IAAI,EAAE,UAAU,GAAG;KACnB,EAF6F,CAE7F,CAAC;IACK,0CAAc,GAA2C;QAChE,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,YAAY,EAAG,EAAE,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,MAAM,EAAG,EAAE,EAAE;KACtG,CAAC;IACF,kCAAC;AAAD,CAAC,AA9LD,IA8LC","sourcesContent":["import {\n Component, ElementRef, TemplateRef, ViewEncapsulation, HostListener\n} from '@angular/core';\nimport { isBs3 } from '../utils/ng2-bootstrap-config';\nimport { TypeaheadUtils } from './typeahead-utils';\nimport { TypeaheadDirective } from './typeahead.directive';\nimport { TypeaheadMatch } from './typeahead-match.class';\n\n\nexport class TypeaheadContainerComponent {\n public parent: TypeaheadDirective;\n public query: any;\n public element: ElementRef;\n public isFocused: boolean = false;\n public top: string;\n public left: string;\n public display: string;\n public placement: string;\n\n public get isBs4():boolean {\n return !isBs3();\n }\n\n protected _active: TypeaheadMatch;\n protected _matches: TypeaheadMatch[] = [];\n\n public constructor(element: ElementRef) {\n this.element = element;\n }\n\n public get active(): TypeaheadMatch {\n return this._active;\n }\n\n public get matches(): TypeaheadMatch[] {\n return this._matches;\n }\n\n public set matches(value: TypeaheadMatch[]) {\n this._matches = value;\n\n if (this._matches.length > 0) {\n this._active = this._matches[0];\n if (this._active.isHeader()) {\n this.nextActiveMatch();\n }\n }\n }\n\n public get optionsListTemplate(): TemplateRef<any> {\n return this.parent ? this.parent.optionsListTemplate : undefined;\n }\n\n public get itemTemplate(): TemplateRef<any> {\n return this.parent ? this.parent.typeaheadItemTemplate : undefined;\n }\n\n public selectActiveMatch(): void {\n this.selectMatch(this._active);\n }\n\n public prevActiveMatch(): void {\n let index = this.matches.indexOf(this._active);\n this._active = this.matches[index - 1 < 0\n ? this.matches.length - 1\n : index - 1];\n if (this._active.isHeader()) {\n this.prevActiveMatch();\n }\n\n }\n\n public nextActiveMatch(): void {\n let index = this.matches.indexOf(this._active);\n this._active = this.matches[index + 1 > this.matches.length - 1\n ? 0\n : index + 1];\n if (this._active.isHeader()) {\n this.nextActiveMatch();\n }\n }\n\n public selectActive(value: TypeaheadMatch): void {\n this.isFocused = true;\n this._active = value;\n }\n\n public hightlight(match: TypeaheadMatch, query: any): string {\n let itemStr: string = match.value;\n let itemStrHelper: string = (this.parent && this.parent.typeaheadLatinize\n ? TypeaheadUtils.latinize(itemStr)\n : itemStr).toLowerCase();\n let startIdx: number;\n let tokenLen: number;\n // Replaces the capture string with the same string inside of a \"strong\" tag\n if (typeof query === 'object') {\n let queryLen: number = query.length;\n for (let i = 0; i < queryLen; i += 1) {\n // query[i] is already latinized and lower case\n startIdx = itemStrHelper.indexOf(query[i]);\n tokenLen = query[i].length;\n if (startIdx >= 0 && tokenLen > 0) {\n itemStr = itemStr.substring(0, startIdx) + '<strong>' + itemStr.substring(startIdx, startIdx + tokenLen) + '</strong>' + itemStr.substring(startIdx + tokenLen);\n itemStrHelper = itemStrHelper.substring(0, startIdx) + ' ' + ' '.repeat(tokenLen) + ' ' + itemStrHelper.substring(startIdx + tokenLen);\n }\n }\n } else if (query) {\n // query is already latinized and lower case\n startIdx = itemStrHelper.indexOf(query);\n tokenLen = query.length;\n if (startIdx >= 0 && tokenLen > 0) {\n itemStr = itemStr.substring(0, startIdx) + '<strong>' + itemStr.substring(startIdx, startIdx + tokenLen) + '</strong>' + itemStr.substring(startIdx + tokenLen);\n }\n }\n return itemStr;\n }\n\n \n \n public focusLost(): void {\n this.isFocused = false;\n }\n\n public isActive(value: TypeaheadMatch): boolean {\n return this._active === value;\n }\n\n public selectMatch(value: TypeaheadMatch, e: Event = void 0): boolean {\n if (e) {\n e.stopPropagation();\n e.preventDefault();\n }\n this.parent.changeModel(value);\n setTimeout(() =>\n this.parent.typeaheadOnSelect.emit(value), 0\n );\n return false;\n }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Component, args: [{\n selector: 'typeahead-container',\n // tslint:disable-next-line\n template: `\n<!-- inject options list template -->\n<template [ngTemplateOutlet]=\"optionsListTemplate || (isBs4 ? bs4Template : bs3Template)\"\n [ngOutletContext]=\"{matches:matches, itemTemplate:itemTemplate, query:query}\"></template>\n\n<!-- default options item template -->\n<template #bsItemTemplate let-match=\"match\" let-query=\"query\"><span [innerHtml]=\"hightlight(match, query)\"></span></template>\n\n<!-- Bootstrap 3 options list template -->\n<template #bs3Template>\n<ul class=\"dropdown-menu\">\n <template ngFor let-match let-i=\"index\" [ngForOf]=\"matches\">\n <li *ngIf=\"match.isHeader()\" class=\"dropdown-header\">{{match}}</li>\n <li *ngIf=\"!match.isHeader()\" [class.active]=\"isActive(match)\" (mouseenter)=\"selectActive(match)\">\n <a href=\"#\" (click)=\"selectMatch(match, $event)\" tabindex=\"-1\">\n <template [ngTemplateOutlet]=\"itemTemplate || bsItemTemplate\" \n [ngOutletContext]=\"{item:match.item, index:i, match:match, query:query}\"></template>\n </a>\n </li>\n </template>\n</ul>\n</template>\n\n<!-- Bootstrap 4 options list template -->\n<template #bs4Template >\n<template ngFor let-match let-i=\"index\" [ngForOf]=\"matches\">\n <h6 *ngIf=\"match.isHeader()\" class=\"dropdown-header\">{{match}}</h6>\n <template [ngIf]=\"!match.isHeader()\">\n <button\n class=\"dropdown-item\"\n (click)=\"selectMatch(match, $event)\"\n (mouseenter)=\"selectActive(match)\"\n [class.active]=\"isActive(match)\">\n <template [ngTemplateOutlet]=\"itemTemplate || bsItemTemplate\" \n [ngOutletContext]=\"{item:match.item, index:i, match:match, query:query}\"></template>\n </button>\n </template>\n</template>\n</template>\n`,\n // tslint:disable\n host: {\n 'class': 'dropdown open',\n '[class.dropdown-menu]':'isBs4',\n style: 'position: absolute;display: block;'\n },\n // tslint: enable\n encapsulation: ViewEncapsulation.None\n}, ] },\n];\n/** @nocollapse */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n{type: ElementRef, },\n];\nstatic propDecorators: {[key: string]: DecoratorInvocation[]} = {\n'focusLost': [{ type: HostListener, args: ['mouseleave', ] },{ type: HostListener, args: ['blur', ] },],\n};\n}\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]} |