{"version":3,"file":"index.mjs","sources":["../../../../../projects/components/widgets/input/caption-position/src/caption-position.directive.ts","../../../../../projects/components/widgets/input/caption-position/src/index.ts"],"sourcesContent":["import {AfterViewInit, Directive, ElementRef, Injector, OnDestroy, OnInit} from '@angular/core';\nimport {App} from '@wm/core';\nimport {forEach} from \"lodash-es\";\n\ndeclare const $;\n@Directive({\n  standalone: true,\n    selector: '[wmCaptionPosition]'\n})\nexport class CaptionPositionDirective implements AfterViewInit, OnInit, OnDestroy {\n    private elementRef: ElementRef;\n    private inputEl;\n    private nativeEl;\n    private compositeEle;\n    private app: App;\n    private labelAnimationSubscription;\n    private placeholder;\n    private _attrObserver;\n    private _isPlaceholderBound;\n\n    // skip floating caption for the below form fields\n    private skipFloatPositionWidgets: string[] = ['radioset', 'checkboxset', 'richtext', 'switch', 'chips', 'checkbox', 'slider', 'rating', 'toggle', 'upload'];\n\n    constructor(inj: Injector, app: App) {\n        this.elementRef = inj.get(ElementRef);\n        this.nativeEl = this.elementRef.nativeElement;\n        this.app = app;\n    }\n\n    private onBlurCb() { // on blur, remove animation and placeholder if there is no value\n        let mobileInputVal;\n        // In case of mobile date / time picker check for input element's value which has 'mobile-input' class\n        if (this.inputEl.length > 1 && this.inputEl.hasClass('mobile-input')) {\n            forEach(this.inputEl, (el) => {\n                if ($(el).hasClass('mobile-input') && el.value) {\n                    mobileInputVal = el.value;\n                }\n            });\n        }\n        if (!this.inputEl.val() && !mobileInputVal) {\n            this.compositeEle.classList.remove('float-active');\n            this.inputEl.removeAttr('placeholder');\n        }\n    }\n\n    private onFocusCb() { //  on focus, add animation class and the place holder\n        this.compositeEle.classList.add('float-active');\n        this.inputEl.attr('placeholder', this.placeholder);\n    }\n\n    // For select widget, display placeholder only on focus else remove the text of the option selected.\n    private checkForSelectPlaceholder() {\n        const selectElPlaceholderOption = this.nativeEl.querySelector('#placeholderOption');\n        if (selectElPlaceholderOption && selectElPlaceholderOption.textContent && !$(this.nativeEl).find('select').is(':focus') &&\n            !$(this.inputEl.closest('[widget-id]')).attr('datavalue')) {\n            selectElPlaceholderOption.textContent = '';\n        }\n    }\n\n    private setDefaultValueAnimation() { // set animation when default values are present\n        // remove placeholder when the input el has placeholder and the placeholder is not bound to any variable\n        if (!this._isPlaceholderBound && this.inputEl.attr('placeholder')) {\n            this.placeholder = this.inputEl.attr('placeholder');\n            this.inputEl.removeAttr('placeholder');\n        }\n\n        // Do not show placeholder as selected by default\n        this.checkForSelectPlaceholder();\n\n        // check for datavalue attribute in composite element and defaultvalue attribute in form field element\n        // check for datavalue.bind attribute to see whether default value is binded via expression or a variable\n        // check for displayformat attribute, as in form fields user can set display format to the field\n        // check for formdata/bindformdata attribute to see if any default value is binded to the form\n        // check for select tag with multiple attribute enabled\n\n        if ((this.inputEl.val() && !this.inputEl.is('select')) || $(this.inputEl.closest('[widget-id]')).attr('datavalue') || $(this.inputEl.parent('[widget-id]')).attr('datavalue.bind') || this.nativeEl.getAttribute('defaultvalue')\n            || this.nativeEl.getAttribute('displayformat') || $(this.nativeEl).find('select option:selected').text() || $(this.nativeEl).find('select').attr('multiple')) {\n            this.compositeEle.classList.add('float-active');\n        }\n    }\n\n    /**\n     * Observing placeholder attribute change on DOM instead of having a propChangeHandler fn\n     * For composite widgets propertychangehandler function is invoked at independent widgets where as the directive is at composite level\n     */\n    private observeForPlaceholderAttrChange() {\n        this._attrObserver = new MutationObserver(mutations => {\n            mutations.forEach((mutation) => {\n                if (mutation.attributeName === 'placeholder' && this.inputEl.attr('placeholder') && !this.compositeEle.classList.contains('float-active')) {\n                    this.placeholder = this.inputEl.attr('placeholder');\n                    this.inputEl.removeAttr('placeholder');\n                }\n            });\n        });\n        const config = { attributes: true, childList: false, characterData: false };\n        this._attrObserver.observe(this.inputEl[0], config);\n    }\n\n    // when a form is right aligned and have input-group-btn's like date picker, time picker etc. adjust the css to not overlap the label on the icon\n    private checkForRightAlignedForm() {\n        const $compositeEle = $(this.compositeEle);\n        if ($compositeEle.closest('.align-right').length && $compositeEle.find('.input-group-btn').length) {\n            const $label = $compositeEle.find('label');\n            if ($compositeEle.find('[wmdatetime]').length) { // for datetime picker, as there will be 2 icons css is different\n                $label.addClass('input-grp-dt-icon');\n            } else {\n                $label.addClass('input-grp-icon');\n            }\n        }\n    }\n\n    ngAfterViewInit() {\n        this.compositeEle = this.nativeEl;\n        const widget = this.nativeEl.widget;\n        let captionPosition: string = widget.$attrs.get('captionposition');\n        if (widget.form) {\n            captionPosition = widget.form.$attrs.get('captionposition');\n            this.compositeEle = this.nativeEl.querySelector('.app-composite-widget');\n            this._isPlaceholderBound = this.nativeEl.getAttribute('placeholder.bind');\n        }\n        if (captionPosition === 'floating') {\n            if (widget.form) { // for form-fields remove caption-floating and replace it with caption-float or caption-top\n                const widgetType: string = this.nativeEl.getAttribute('widgettype'); // fetches the form field type\n                if (this.skipFloatPositionWidgets.indexOf(widgetType) > -1) {\n                    this.compositeEle.classList.remove('caption-floating');\n                    this.compositeEle.classList.add('caption-top');\n                }\n                this.checkForRightAlignedForm();\n            }\n            this.inputEl = $(this.nativeEl).find('input, select, textarea');\n            if (!this._isPlaceholderBound) {\n                this._isPlaceholderBound = this.inputEl.closest('[widget-id]').attr('placeholder.bind');\n            }\n            // call the below function to apply float-active class when there are default values to the fields\n            setTimeout(this.setDefaultValueAnimation.bind(this), 0);\n\n            this.inputEl.focus(this.onFocusCb.bind(this));\n            this.inputEl.blur(this.onBlurCb.bind(this));\n\n            // observe for placeholder attribute change when placeholder is bound via db variable or an expression\n            if (this._isPlaceholderBound) {\n                this.observeForPlaceholderAttrChange();\n            }\n        }\n    }\n\n    // captionPositionAnimate is only notified for date-time, time and search widgets as input el is not updated with value on selection of dropdown/popups\n    ngOnInit() {\n        this.labelAnimationSubscription = this.app.subscribe('captionPositionAnimate', (data) => {\n            // displayVal is true when there is a value entered in the input field\n            // In case of form fields, when the field is in focus, isFocused will be set as true\n            // isSelectMultiple is set to true when for select widget, multiple option is enabled\n            // Checking inputEl focus - when form is represented as dialog and the first field is automatically in focus\n            const isInputElFocused = this.inputEl && this.inputEl.is(':focus');\n            if (data.displayVal || data.isFocused || data.isSelectMultiple || isInputElFocused) {\n                data.nativeEl.addClass('float-active');\n                if (!data.displayVal && isInputElFocused) {\n                    this.inputEl.attr('placeholder', this.placeholder);\n                }\n            } else {\n                data.nativeEl.removeClass('float-active');\n                // Remove placeholder on removing float-active, if not the label and placeholder are collided\n                // before placeholder is removed assign it to the placeholder variable\n                // check for placeholder in inputel and selectel\n                if (this.inputEl) {\n                    const selectElPlaceholderOption = this.nativeEl.querySelector('#placeholderOption');\n                    if (this.inputEl.attr('placeholder') || selectElPlaceholderOption) {\n                        if (selectElPlaceholderOption) {\n                            selectElPlaceholderOption.textContent = '';\n                        } else {\n                            this.placeholder = this.inputEl.attr('placeholder');\n                            this.inputEl.removeAttr('placeholder');\n                        }\n                    }\n                }\n            }\n        });\n    }\n\n    ngOnDestroy() {\n        if (this.labelAnimationSubscription) {\n            this.labelAnimationSubscription();\n        }\n        if (this._attrObserver) {\n            this._attrObserver.disconnect();\n        }\n    }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;MASa,wBAAwB,CAAA;IAcjC,WAAA,CAAY,GAAa,EAAE,GAAQ,EAAA;;QAF3B,IAAA,CAAA,wBAAwB,GAAa,CAAC,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC;QAGvJ,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa;AAC7C,QAAA,IAAI,CAAC,GAAG,GAAG,GAAG;IAClB;IAEQ,QAAQ,GAAA;AACZ,QAAA,IAAI,cAAc;;AAElB,QAAA,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,G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