UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 8.67 kB
this.primevue=this.primevue||{},this.primevue.password=function(e,t,l,n,i){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=s(e),a=s(t),o=s(l),d={name:"Password",emits:["update:modelValue","change","focus","blur","invalid"],props:{modelValue:String,promptLabel:{type:String,default:null},mediumRegex:{type:String,default:"^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"},strongRegex:{type:String,default:"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})"},weakLabel:{type:String,default:null},mediumLabel:{type:String,default:null},strongLabel:{type:String,default:null},feedback:{type:Boolean,default:!0},appendTo:{type:String,default:"body"},toggleMask:{type:Boolean,default:!1},hideIcon:{type:String,default:"pi pi-eye-slash"},showIcon:{type:String,default:"pi pi-eye"},disabled:{type:Boolean,default:!1},placeholder:{type:String,default:null},required:{type:Boolean,default:!1},inputId:{type:String,default:null},inputClass:{type:String,default:null},inputStyle:{type:null,default:null},inputProps:{type:null,default:null},panelId:{type:String,default:null},panelClass:{type:String,default:null},panelStyle:{type:null,default:null},panelProps:{type:null,default:null},"aria-labelledby":{type:String,default:null},"aria-label":{type:String,default:null}},data:()=>({overlayVisible:!1,meter:null,infoText:null,focused:!1,unmasked:!1}),mediumCheckRegExp:null,strongCheckRegExp:null,resizeListener:null,scrollHandler:null,overlay:null,mounted(){this.infoText=this.promptText,this.mediumCheckRegExp=new RegExp(this.mediumRegex),this.strongCheckRegExp=new RegExp(this.strongRegex)},beforeUnmount(){this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.overlay&&(n.ZIndexUtils.clear(this.overlay),this.overlay=null)},methods:{onOverlayEnter(e){n.ZIndexUtils.set("overlay",e,this.$primevue.config.zIndex.overlay),this.alignOverlay(),this.bindScrollListener(),this.bindResizeListener()},onOverlayLeave(){this.unbindScrollListener(),this.unbindResizeListener(),this.overlay=null},onOverlayAfterLeave(e){n.ZIndexUtils.clear(e)},alignOverlay(){"self"===this.appendTo?n.DomHandler.relativePosition(this.overlay,this.$refs.input.$el):(this.overlay.style.minWidth=n.DomHandler.getOuterWidth(this.$refs.input.$el)+"px",n.DomHandler.absolutePosition(this.overlay,this.$refs.input.$el))},testStrength(e){let t=0;return this.strongCheckRegExp.test(e)?t=3:this.mediumCheckRegExp.test(e)?t=2:e.length&&(t=1),t},onInput(e){this.$emit("update:modelValue",e.target.value)},onFocus(e){this.focused=!0,this.feedback&&(this.setPasswordMeter(this.modelValue),this.overlayVisible=!0),this.$emit("focus",e)},onBlur(e){this.focused=!1,this.feedback&&(this.overlayVisible=!1),this.$emit("blur",e)},onKeyUp(e){if(this.feedback){const t=e.target.value,{meter:l,label:n}=this.checkPasswordStrength(t);if(this.meter=l,this.infoText=n,"Escape"===e.code)return void(this.overlayVisible&&(this.overlayVisible=!1));this.overlayVisible||(this.overlayVisible=!0)}},setPasswordMeter(){if(!this.modelValue)return;const{meter:e,label:t}=this.checkPasswordStrength(this.modelValue);this.meter=e,this.infoText=t,this.overlayVisible||(this.overlayVisible=!0)},checkPasswordStrength(e){let t=null,l=null;switch(this.testStrength(e)){case 1:t=this.weakText,l={strength:"weak",width:"33.33%"};break;case 2:t=this.mediumText,l={strength:"medium",width:"66.66%"};break;case 3:t=this.strongText,l={strength:"strong",width:"100%"};break;default:t=this.promptText,l=null}return{label:t,meter:l}},onInvalid(e){this.$emit("invalid",e)},bindScrollListener(){this.scrollHandler||(this.scrollHandler=new n.ConnectedOverlayScrollHandler(this.$refs.input.$el,(()=>{this.overlayVisible&&(this.overlayVisible=!1)}))),this.scrollHandler.bindScrollListener()},unbindScrollListener(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},bindResizeListener(){this.resizeListener||(this.resizeListener=()=>{this.overlayVisible&&!n.DomHandler.isTouchDevice()&&(this.overlayVisible=!1)},window.addEventListener("resize",this.resizeListener))},unbindResizeListener(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},overlayRef(e){this.overlay=e},onMaskToggle(){this.unmasked=!this.unmasked},onOverlayClick(e){a.default.emit("overlay-click",{originalEvent:e,target:this.$el})}},computed:{containerClass(){return["p-password p-component p-inputwrapper",{"p-inputwrapper-filled":this.filled,"p-inputwrapper-focus":this.focused,"p-input-icon-right":this.toggleMask}]},inputFieldClass(){return["p-password-input",this.inputClass,{"p-disabled":this.disabled}]},panelStyleClass(){return["p-password-panel p-component",this.panelClass,{"p-input-filled":"filled"===this.$primevue.config.inputStyle,"p-ripple-disabled":!1===this.$primevue.config.ripple}]},toggleIconClass(){return this.unmasked?this.hideIcon:this.showIcon},strengthClass(){return`p-password-strength ${this.meter?this.meter.strength:""}`},inputType(){return this.unmasked?"text":"password"},filled(){return null!=this.modelValue&&this.modelValue.toString().length>0},weakText(){return this.weakLabel||this.$primevue.config.locale.weak},mediumText(){return this.mediumLabel||this.$primevue.config.locale.medium},strongText(){return this.strongLabel||this.$primevue.config.locale.strong},promptText(){return this.promptLabel||this.$primevue.config.locale.passwordPrompt},panelUniqueId:()=>n.UniqueComponentId()+"_panel"},components:{PInputText:r.default,Portal:o.default}};const p={class:"p-hidden-accessible","aria-live":"polite"},u=["id"],h={class:"p-password-meter"},c={class:"p-password-info"};return function(e,t){void 0===t&&(t={});var l=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===l&&n.firstChild?n.insertBefore(i,n.firstChild):n.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}("\n.p-password {\n position: relative;\n display: inline-flex;\n}\n.p-password-panel {\n position: absolute;\n top: 0;\n left: 0;\n}\n.p-password .p-password-panel {\n min-width: 100%;\n}\n.p-password-meter {\n height: 10px;\n}\n.p-password-strength {\n height: 100%;\n width: 0;\n transition: width 1s ease-in-out;\n}\n.p-fluid .p-password {\n display: flex;\n}\n.p-password-input::-ms-reveal,\n.p-password-input::-ms-clear {\n display: none;\n}\n"),d.render=function(e,t,l,n,s,r){const a=i.resolveComponent("PInputText"),o=i.resolveComponent("Portal");return i.openBlock(),i.createElementBlock("div",{class:i.normalizeClass(r.containerClass)},[i.createVNode(a,i.mergeProps({ref:"input",id:l.inputId,type:r.inputType,class:r.inputFieldClass,style:l.inputStyle,value:l.modelValue,"aria-labelledby":e.ariaLabelledby,"aria-label":e.ariaLabel,"aria-controls":l.panelProps&&l.panelProps.id||l.panelId||r.panelUniqueId,"aria-expanded":s.overlayVisible,"aria-haspopup":!0,placeholder:l.placeholder,required:l.required,onInput:r.onInput,onFocus:r.onFocus,onBlur:r.onBlur,onKeyup:r.onKeyUp,onInvalid:r.onInvalid},l.inputProps),null,16,["id","type","class","style","value","aria-labelledby","aria-label","aria-controls","aria-expanded","placeholder","required","onInput","onFocus","onBlur","onKeyup","onInvalid"]),l.toggleMask?(i.openBlock(),i.createElementBlock("i",{key:0,class:i.normalizeClass(r.toggleIconClass),onClick:t[0]||(t[0]=(...e)=>r.onMaskToggle&&r.onMaskToggle(...e))},null,2)):i.createCommentVNode("",!0),i.createElementVNode("span",p,i.toDisplayString(s.infoText),1),i.createVNode(o,{appendTo:l.appendTo},{default:i.withCtx((()=>[i.createVNode(i.Transition,{name:"p-connected-overlay",onEnter:r.onOverlayEnter,onLeave:r.onOverlayLeave,onAfterLeave:r.onOverlayAfterLeave},{default:i.withCtx((()=>[s.overlayVisible?(i.openBlock(),i.createElementBlock("div",i.mergeProps({key:0,ref:r.overlayRef,id:l.panelId||r.panelUniqueId,class:r.panelStyleClass,style:l.panelStyle,onClick:t[1]||(t[1]=(...e)=>r.onOverlayClick&&r.onOverlayClick(...e))},l.panelProps),[i.renderSlot(e.$slots,"header"),i.renderSlot(e.$slots,"content",{},(()=>[i.createElementVNode("div",h,[i.createElementVNode("div",{class:i.normalizeClass(r.strengthClass),style:i.normalizeStyle({width:s.meter?s.meter.width:""})},null,6)]),i.createElementVNode("div",c,i.toDisplayString(s.infoText),1)])),i.renderSlot(e.$slots,"footer")],16,u)):i.createCommentVNode("",!0)])),_:3},8,["onEnter","onLeave","onAfterLeave"])])),_:3},8,["appendTo"])],2)},d}(primevue.inputtext,primevue.overlayeventbus,primevue.portal,primevue.utils,Vue);