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) 9.32 kB
this.primevue=this.primevue||{},this.primevue.password=function(e,t,l,n,i,s,r,o){"use strict";function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=a(e),d=a(t),u=a(l),h=a(n),c=a(i),m=a(s),y={name:"Password",extends:p.default,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:void 0},showIcon:{type:String,default:void 0},disabled:{type:Boolean,default:!1},placeholder:{type:String,default:null},required:{type:Boolean,default:!1},inputId:{type:String,default:null},inputClass:{type:[String,Object],default:null},inputStyle:{type:Object,default:null},inputProps:{type:null,default:null},panelId:{type:String,default:null},panelClass:{type:[String,Object],default:null},panelStyle:{type:Object,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&&(r.ZIndexUtils.clear(this.overlay),this.overlay=null)},methods:{onOverlayEnter(e){r.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){r.ZIndexUtils.clear(e)},alignOverlay(){"self"===this.appendTo?r.DomHandler.relativePosition(this.overlay,this.$refs.input.$el):(this.overlay.style.minWidth=r.DomHandler.getOuterWidth(this.$refs.input.$el)+"px",r.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 r.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&&!r.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){c.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}]},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:()=>r.UniqueComponentId()+"_panel"},components:{PInputText:h.default,Portal:m.default,EyeSlashIcon:u.default,EyeIcon:d.default}};const g=["id"];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"),y.render=function(e,t,l,n,i,s){const r=o.resolveComponent("PInputText"),a=o.resolveComponent("Portal");return o.openBlock(),o.createElementBlock("div",o.mergeProps({class:s.containerClass},e.ptm("root")),[o.createVNode(r,o.mergeProps({ref:"input",id:l.inputId,type:s.inputType,class:s.inputFieldClass,style:l.inputStyle,value:l.modelValue,"aria-labelledby":e.ariaLabelledby,"aria-label":e.ariaLabel,"aria-controls":l.panelProps&&l.panelProps.id||l.panelId||s.panelUniqueId,"aria-expanded":i.overlayVisible,"aria-haspopup":!0,placeholder:l.placeholder,required:l.required,onInput:s.onInput,onFocus:s.onFocus,onBlur:s.onBlur,onKeyup:s.onKeyUp,onInvalid:s.onInvalid},{...l.inputProps,...e.ptm("input")}),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.unmasked?o.renderSlot(e.$slots,"hideicon",{key:0,onClick:s.onMaskToggle},(()=>[(o.openBlock(),o.createBlock(o.resolveDynamicComponent(l.hideIcon?"i":"EyeSlashIcon"),o.mergeProps({class:l.hideIcon,onClick:s.onMaskToggle},e.ptm("hideIcon")),null,16,["class","onClick"]))])):o.createCommentVNode("",!0),l.toggleMask&&!i.unmasked?o.renderSlot(e.$slots,"showicon",{key:1,onClick:s.onMaskToggle},(()=>[(o.openBlock(),o.createBlock(o.resolveDynamicComponent(l.showIcon?"i":"EyeIcon"),o.mergeProps({class:l.showIcon,onClick:s.onMaskToggle},e.ptm("showIcon")),null,16,["class","onClick"]))])):o.createCommentVNode("",!0),o.createElementVNode("span",o.mergeProps({class:"p-hidden-accessible","aria-live":"polite"},e.ptm("hiddenAccesible")),o.toDisplayString(i.infoText),17),o.createVNode(a,{appendTo:l.appendTo},{default:o.withCtx((()=>[o.createVNode(o.Transition,{name:"p-connected-overlay",onEnter:s.onOverlayEnter,onLeave:s.onOverlayLeave,onAfterLeave:s.onOverlayAfterLeave},{default:o.withCtx((()=>[i.overlayVisible?(o.openBlock(),o.createElementBlock("div",o.mergeProps({key:0,ref:s.overlayRef,id:l.panelId||s.panelUniqueId,class:s.panelStyleClass,style:l.panelStyle,onClick:t[0]||(t[0]=(...e)=>s.onOverlayClick&&s.onOverlayClick(...e))},{...l.panelProps,...e.ptm("panel")}),[o.renderSlot(e.$slots,"header"),o.renderSlot(e.$slots,"content",{},(()=>[o.createElementVNode("div",o.mergeProps({class:"p-password-meter"},e.ptm("meter")),[o.createElementVNode("div",o.mergeProps({class:s.strengthClass,style:{width:i.meter?i.meter.width:""}},e.ptm("meterLabel")),null,16)],16),o.createElementVNode("div",o.mergeProps({class:"p-password-info"},e.ptm("info")),o.toDisplayString(i.infoText),17)])),o.renderSlot(e.$slots,"footer")],16,g)):o.createCommentVNode("",!0)])),_:3},8,["onEnter","onLeave","onAfterLeave"])])),_:3},8,["appendTo"])],16)},y}(primevue.basecomponent,primevue.icons.eye,primevue.icons.eyeslash,primevue.inputtext,primevue.overlayeventbus,primevue.portal,primevue.utils,Vue);