{ "version": 3, "sources": ["../ui/app/mn.select.component.js", "../ui/app/mn.select.module.js"], "sourcesContent": ["/*\nCopyright 2021-Present Couchbase, Inc.\n\nUse of this software is governed by the Business Source License included in\nthe file licenses/BSL-Couchbase.txt. As of the Change Date specified in that\nfile, in accordance with the Business Source License, use of this software will\nbe governed by the Apache License, Version 2.0, included in the file\nlicenses/APL2.txt.\n*/\n\nimport {ChangeDetectionStrategy, Component, ViewChild} from '@angular/core';\nimport {BehaviorSubject, Subject} from 'rxjs';\nimport {FormBuilder} from '@angular/forms';\nimport {is} from 'ramda';\nimport {pluck, shareReplay, map, takeUntil, withLatestFrom,\n startWith, distinctUntilChanged} from 'rxjs/operators';\nimport {NgbDropdown} from '@ng-bootstrap/ng-bootstrap';\n\nimport {MnLifeCycleHooksToStream} from \"./mn.core.js\";\nimport {MnHelperService} from './mn.helper.service.js';\nimport template from \"./mn.select.html\";\n\nlet isString = is(String);\n\nexport {MnSelectComponent};\n\nclass MnSelectComponent extends MnLifeCycleHooksToStream {\n static get annotations() { return [\n new Component({\n selector: \"mn-select\",\n template,\n inputs: [\n \"group\",\n \"mnFormControlName\",\n \"values\",\n \"labels\",\n \"valuesMapping\",\n \"capitalize\",\n \"mnPlaceholder\",\n \"placement\",\n \"hasSearch\"\n ],\n changeDetection: ChangeDetectionStrategy.OnPush,\n queries: {\n ngbDropdownView: new ViewChild(NgbDropdown)\n }\n })\n ]}\n\n static get parameters() { return [\n MnHelperService,\n FormBuilder\n ]}\n\n constructor(MnHelperService, FormBuilder) {\n super();\n\n this.mnHelperService = MnHelperService;\n this.hiddenRadioGroup = FormBuilder.group({\n hiddenRadio: null\n });\n\n this.id = this.mnHelperService.generateID();\n\n this.selectOptionClickStream = new Subject();\n this.selectLabelClickStream = new Subject();\n\n this.selectOptionClickStream\n .pipe(takeUntil(this.mnOnDestroy))\n .subscribe(this.optionSelected.bind(this));\n }\n\n ngOnInit() {\n this.placement = this.placement || 'bottom';\n\n if (!this.valuesMapping) {\n this.valuesMapping = this.defaultValuesMapping.bind(this);\n }\n\n if (this.hasSearch) {\n this.prepareSearch();\n }\n\n this.dropdownFormControl = this.group.get(this.mnFormControlName);\n if (this.dropdownFormControl) {\n this.disabled = new BehaviorSubject(this.dropdownFormControl.disabled);\n this.dropdownFormControl.registerOnDisabledChange(disabled => this.disabled.next(disabled));\n\n this.value = this.dropdownFormControl.valueChanges.pipe(startWith(this.dropdownFormControl.value));\n this.value\n .pipe(distinctUntilChanged(),\n takeUntil(this.mnOnDestroy))\n .subscribe(this.setHiddenRadioValue.bind(this));\n }\n }\n\n prepareSearch() {\n let searchMinimumOptionsNumber = 10;\n this.searchFilter = this.mnHelperService.createFilter(this);\n\n var valuesStream = this.mnOnChanges\n .pipe(pluck(\"values\", \"currentValue\"));\n\n this.preparedValues = valuesStream\n .pipe(this.searchFilter.pipe,\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.hasSearchInput = valuesStream\n .pipe(map(values => (this.hasSearch && (values || []).length >= searchMinimumOptionsNumber) || false));\n\n var labelsStream = this.mnOnChanges\n .pipe(pluck(\"labels\", \"currentValue\"));\n\n this.preparedLabels = labelsStream\n .pipe(this.searchFilter.pipe,\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.selectLabelClickStream\n .pipe(withLatestFrom(labelsStream, valuesStream),\n takeUntil(this.mnOnDestroy))\n .subscribe(([selectedLabel, labels, values]) => {\n this.optionSelected(values[labels.indexOf(selectedLabel)]);\n });\n }\n\n setHiddenRadioValue(value) {\n let patchedValue = (this.hasSearch && this.labels) ?\n this.labels[this.values.indexOf(value)] : value;\n\n this.hiddenRadioGroup.patchValue({hiddenRadio: patchedValue});\n }\n\n /**\n * Default values mapping:\n * * if capitalize input flag is true - capitalize the displayed label if it is a string\n * * else leave the label as it is\n * @param option\n * @returns {string}\n */\n defaultValuesMapping(option) {\n if (this.capitalize && isString(option) && option) {\n return option[0].toUpperCase() + option.slice(1);\n }\n\n return option;\n }\n\n optionSelected(value) {\n this.dropdownFormControl.setValue(value);\n if (this.hasSearchInput) {\n this.searchFilter.group.get('value').setValue('');\n }\n\n this.ngbDropdownView.close();\n }\n}\n", "/*\nCopyright 2021-Present Couchbase, Inc.\n\nUse of this software is governed by the Business Source License included in\nthe file licenses/BSL-Couchbase.txt. As of the Change Date specified in that\nfile, in accordance with the Business Source License, use of this software will\nbe governed by the Apache License, Version 2.0, included in the file\nlicenses/APL2.txt.\n*/\n\n\nimport {NgModule} from '@angular/core';\nimport {CommonModule} from '@angular/common';\nimport {NgbModule} from '@ng-bootstrap/ng-bootstrap';\nimport {ReactiveFormsModule} from '@angular/forms';\n\nimport {MnInputFilterModule} from './mn.input.filter.module.js';\nimport {MnSharedModule} from './mn.shared.module.js';\nimport {MnSelectComponent} from './mn.select.component.js';\n\nexport {MnSelectModule}\n\nclass MnSelectModule {\n static get annotations() { return [\n new NgModule({\n imports: [\n CommonModule,\n MnSharedModule,\n NgbModule,\n MnInputFilterModule,\n ReactiveFormsModule\n ],\n declarations: [\n MnSelectComponent\n ],\n exports: [\n MnSelectComponent\n ]\n })\n ]}\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBA,GAAI,UAAW,GAAG,QAIlB,mCAAgC,yBAAyB,WAC5C,cAAc,CAAE,MAAO,CAChC,GAAI,WAAU,CACZ,SAAU,YACV,2BACA,OAAQ,CACN,QACA,oBACA,SACA,SACA,gBACA,aACA,gBACA,YACA,aAEF,gBAAiB,wBAAwB,OACzC,QAAS,CACP,gBAAiB,GAAI,WAAU,2BAK1B,aAAa,CAAE,MAAO,CAC/B,gBACA,aAGF,YAAY,iBAAiB,aAAa,CACxC,QAEA,KAAK,gBAAkB,iBACvB,KAAK,iBAAmB,aAAY,MAAM,CACxC,YAAa,OAGf,KAAK,GAAK,KAAK,gBAAgB,aAE/B,KAAK,wBAA0B,GAAI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