Skip to content

Commit

Permalink
Fix modal open
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 committed Mar 15, 2024
1 parent b611eb8 commit 9fbd122
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/tailwindcss-stimulus-components.cjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var T=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var U=(t,e,s)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var _=(t,e)=>{for(var s in e)T(t,s,{get:e[s],enumerable:!0})},P=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M(e))!N.call(t,i)&&i!==s&&T(t,i,{get:()=>e[i],enumerable:!(o=q(e,i))||o.enumerable});return t};var O=t=>P(T({},"__esModule",{value:!0}),t);var a=(t,e,s)=>(U(t,typeof e!="symbol"?e+"":e,s),s),z=(t,e,s)=>{if(!e.has(t))throw TypeError("Cannot "+s)};var V=(t,e,s)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,s)};var C=(t,e,s)=>(z(t,e,"access private method"),s);var Q={};_(Q,{Alert:()=>p,Autosave:()=>u,ColorPreview:()=>h,Dropdown:()=>n,Modal:()=>c,Popover:()=>d,Slideover:()=>f,Tabs:()=>l,Toggle:()=>m});module.exports=O(Q);var I=require("@hotwired/stimulus");async function r(t,e,s={}){e?x(t,s):b(t,s)}async function x(t,e={}){let s=t.dataset.transitionEnter||e.enter||"enter",o=t.dataset.transitionEnterFrom||e.enterFrom||"enter-from",i=t.dataset.transitionEnterTo||e.enterTo||"enter-to",g=t.dataset.toggleClass||e.toggleClass||"hidden";t.classList.add(...s.split(" ")),t.classList.add(...o.split(" ")),t.classList.remove(...i.split(" ")),t.classList.remove(...g.split(" ")),await w(),t.classList.remove(...o.split(" ")),t.classList.add(...i.split(" "));try{await y(t)}finally{t.classList.remove(...s.split(" "))}}async function b(t,e={}){let s=t.dataset.transitionLeave||e.leave||"leave",o=t.dataset.transitionLeaveFrom||e.leaveFrom||"leave-from",i=t.dataset.transitionLeaveTo||e.leaveTo||"leave-to",g=t.dataset.toggleClass||e.toogle||"hidden";t.classList.add(...s.split(" ")),t.classList.add(...o.split(" ")),t.classList.remove(...i.split(" ")),await w(),t.classList.remove(...o.split(" ")),t.classList.add(...i.split(" "));try{await y(t)}finally{t.classList.remove(...s.split(" ")),t.classList.add(...g.split(" "))}}function w(){return new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(t)})})}function y(t){return Promise.all(t.getAnimations().map(e=>e.finished))}var p=class extends I.Controller{connect(){setTimeout(()=>{x(this.element)},this.showDelayValue),this.hasDismissAfterValue&&setTimeout(()=>{this.close()},this.dismissAfterValue)}close(){b(this.element).then(()=>{this.element.remove()})}};a(p,"values",{dismissAfter:Number,showDelay:{type:Number,default:0},removeDelay:{type:Number,default:1100}});var L=require("@hotwired/stimulus");var u=class extends L.Controller{connect(){this.timeout=null}save(){clearTimeout(this.timeout),this.timeout=setTimeout(()=>{this.statusTarget.textContent=this.submittingTextValue,this.formTarget.requestSubmit()},this.submitDurationValue)}success(){this.setStatus(this.successTextValue)}error(){this.setStatus(this.errorTextValue)}setStatus(t){this.statusTarget.textContent=t,this.timeout=setTimeout(()=>{this.statusTarget.textContent=""},this.statusDurationValue)}};a(u,"targets",["form","status"]),a(u,"values",{submitDuration:{type:Number,default:1e3},statusDuration:{type:Number,default:2e3},submittingText:{type:String,default:"Saving..."},successText:{type:String,default:"Saved!"},errorText:{type:String,default:"Unable to save."}});var A=require("@hotwired/stimulus");var h=class extends A.Controller{update(){this.preview=this.colorTarget.value}set preview(t){this.previewTarget.style[this.styleValue]=t;let e=this._getContrastYIQ(t);this.styleValue==="color"?this.previewTarget.style.backgroundColor=e:this.previewTarget.style.color=e}_getContrastYIQ(t){t=t.replace("#","");let e=128,s=parseInt(t.substr(0,2),16),o=parseInt(t.substr(2,2),16),i=parseInt(t.substr(4,2),16);return(s*299+o*587+i*114)/1e3>=e?"#000":"#fff"}};a(h,"targets",["preview","color"]),a(h,"values",{style:{type:String,default:"backgroundColor"}});var D=require("@hotwired/stimulus");var v,E,n=class extends D.Controller{constructor(){super(...arguments);V(this,v)}connect(){document.addEventListener("turbo:before-cache",this.beforeCache.bind(this)),C(this,v,E).call(this)}disconnect(){document.removeEventListener("turbo:before-cache",this.beforeCache.bind(this)),this.hasButtonTarget&&(this.buttonTarget.removeEventListener("keydown",this._onMenuButtonKeydown),this.buttonTarget.removeAttribute("aria-haspopup"))}openValueChanged(){r(this.menuTarget,this.openValue,this.transitionOptions),this.openValue===!0&&this.hasMenuItemTarget&&this.menuItemTargets[0].focus()}show(){this.openValue=!0}close(){this.openValue=!1}hide(e){this.closeOnClickOutsideValue&&e.target.nodeType&&this.element.contains(e.target)===!1&&this.openValue&&(this.openValue=!1),this.closeOnEscapeValue&&e.key==="Escape"&&this.openValue&&(this.openValue=!1)}toggle(){this.openValue=!this.openValue}nextItem(e){e.preventDefault(),this.menuItemTargets[this.nextIndex].focus()}previousItem(e){e.preventDefault(),this.menuItemTargets[this.previousIndex].focus()}get currentItemIndex(){return this.menuItemTargets.indexOf(document.activeElement)}get nextIndex(){return Math.min(this.currentItemIndex+1,this.menuItemTargets.length-1)}get previousIndex(){return Math.max(this.currentItemIndex-1,0)}get transitionOptions(){return{enter:this.hasEnterClass?this.enterClass:"transition ease-out duration-100",enterFrom:this.hasEnterFromClass?this.enterFromClass:"transform opacity-0 scale-95",enterTo:this.hasEnterToClass?this.enterToClass:"transform opacity-100 scale-100",leave:this.hasLeaveClass?this.leaveClass:"transition ease-in duration-75",leaveFrom:this.hasLeaveFromClass?this.leaveFromClass:"transform opacity-100 scale-100",leaveTo:this.hasLeaveToClass?this.leaveToClass:"transform opacity-0 scale-95",toggleClass:this.hasToggleClass?this.toggleClass:"hidden"}}beforeCache(){this.openValue=!1,this.menuTarget.classList.add("hidden")}};v=new WeakSet,E=function(){let e=this.element.dataset.action?this.element.dataset.action.split(" "):[];e.push("click->dropdown#toggle"),e.push("click@window->dropdown#hide"),e.push("keydown.up->dropdown#previousItem"),e.push("keydown.down->dropdown#nextItem"),e.push("keydown.esc->dropdown#hide"),this.element.dataset.action=[...new Set(e)].join(" ")},a(n,"targets",["menu","button","menuItem"]),a(n,"values",{open:{type:Boolean,default:!1},closeOnEscape:{type:Boolean,default:!0},closeOnClickOutside:{type:Boolean,default:!0}}),a(n,"classes",["enter","enterFrom","enterTo","leave","leaveFrom","leaveTo","toggle"]);var S=require("@hotwired/stimulus");var c=class extends S.Controller{connect(){this.openValue&&this.open()}open(){this.showModal()}close(){this.dialogTarget.close()}show(){this.dialogTarget.show()}};a(c,"targets",["dialog"]),a(c,"values",{open:Boolean});var F=require("@hotwired/stimulus");var d=class extends F.Controller{openValueChanged(){r(this.contentTarget,this.openValue),this.shouldAutoDismiss&&this.scheduleDismissal()}show(t){this.shouldAutoDismiss&&this.scheduleDismissal(),this.openValue=!0}hide(){this.openValue=!1}toggle(){this.openValue=!this.openValue}get shouldAutoDismiss(){return this.openValue&&this.hasDismissAfterValue}scheduleDismissal(){this.hasDismissAfterValue&&(this.cancelDismissal(),this.timeoutId=setTimeout(()=>{this.hide(),this.timeoutId=void 0},this.dismissAfterValue))}cancelDismissal(){typeof this.timeoutId=="number"&&(clearTimeout(this.timeoutId),this.timeoutId=void 0)}};a(d,"targets",["content"]),a(d,"values",{dismissAfter:Number,open:{type:Boolean,default:!1}});var f=class extends n{openValueChanged(){r(this.overlayTarget,this.openValue),r(this.menuTarget,this.openValue),this.hasCloseTarget&&r(this.closeTarget,this.openValue)}};a(f,"targets",["overlay","close"]);var k=require("@hotwired/stimulus");var l=class extends k.Controller{initialize(){this.anchor&&(this.indexValue=this.tabTargets.findIndex(t=>t.id===this.anchor))}connect(){this.showTab()}change(t){t.currentTarget.tagName==="SELECT"?this.indexValue=t.currentTarget.selectedIndex:t.currentTarget.dataset.index?this.indexValue=t.currentTarget.dataset.index:t.currentTarget.dataset.id?this.indexValue=this.tabTargets.findIndex(e=>e.id==t.currentTarget.dataset.id):this.indexValue=this.tabTargets.indexOf(t.currentTarget),window.dispatchEvent(new CustomEvent("tsc:tab-change"))}nextTab(){this.indexValue=Math.min(this.indexValue+1,this.tabsCount-1)}previousTab(){this.indexValue=Math.max(this.indexValue-1,0)}firstTab(){this.indexValue=0}lastTab(){this.indexValue=this.tabsCount-1}indexValueChanged(){if(this.showTab(),this.updateAnchorValue){let t=this.tabTargets[this.indexValue].id;if(this.scrollToAnchorValue)location.hash=t;else{let s=window.location.href.split("#")[0]+"#"+t;history.replaceState({},document.title,s)}}}showTab(){this.panelTargets.forEach((t,e)=>{let s=this.tabTargets[e];e===this.indexValue?(t.classList.remove("hidden"),s.ariaSelected="true",this.hasInactiveTabClass&&s?.classList?.remove(...this.inactiveTabClasses),this.hasActiveTabClass&&s?.classList?.add(...this.activeTabClasses)):(t.classList.add("hidden"),s.ariaSelected=null,this.hasActiveTabClass&&s?.classList?.remove(...this.activeTabClasses),this.hasInactiveTabClass&&s?.classList?.add(...this.inactiveTabClasses))}),this.hasSelectTarget&&(this.selectTarget.selectedIndex=this.indexValue),this.scrollActiveTabIntoView()}scrollActiveTabIntoView(){let t=this.element.querySelector("[aria-selected]");t&&t.scrollIntoView({inline:"center"})}get tabsCount(){return this.tabTargets.length}get anchor(){return document.URL.split("#").length>1?document.URL.split("#")[1]:null}};a(l,"classes",["activeTab","inactiveTab"]),a(l,"targets",["tab","panel","select"]),a(l,"values",{index:0,updateAnchor:Boolean,scrollToAnchor:Boolean});var B=require("@hotwired/stimulus");var m=class extends B.Controller{toggle(t){this.openValue=!this.openValue,this.animate()}toggleInput(t){this.openValue=t.target.checked,this.animate()}hide(){this.openValue=!1,this.animate()}show(){this.openValue=!0,this.animate()}animate(){this.toggleableTargets.forEach(t=>{r(t,this.openValue)})}};a(m,"targets",["toggleable"]),a(m,"values",{open:{type:Boolean,default:!1}});
var T=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var U=(t,e,s)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var _=(t,e)=>{for(var s in e)T(t,s,{get:e[s],enumerable:!0})},P=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M(e))!N.call(t,i)&&i!==s&&T(t,i,{get:()=>e[i],enumerable:!(o=q(e,i))||o.enumerable});return t};var O=t=>P(T({},"__esModule",{value:!0}),t);var a=(t,e,s)=>(U(t,typeof e!="symbol"?e+"":e,s),s),z=(t,e,s)=>{if(!e.has(t))throw TypeError("Cannot "+s)};var V=(t,e,s)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,s)};var C=(t,e,s)=>(z(t,e,"access private method"),s);var Q={};_(Q,{Alert:()=>p,Autosave:()=>u,ColorPreview:()=>h,Dropdown:()=>n,Modal:()=>c,Popover:()=>d,Slideover:()=>f,Tabs:()=>l,Toggle:()=>m});module.exports=O(Q);var I=require("@hotwired/stimulus");async function r(t,e,s={}){e?x(t,s):b(t,s)}async function x(t,e={}){let s=t.dataset.transitionEnter||e.enter||"enter",o=t.dataset.transitionEnterFrom||e.enterFrom||"enter-from",i=t.dataset.transitionEnterTo||e.enterTo||"enter-to",g=t.dataset.toggleClass||e.toggleClass||"hidden";t.classList.add(...s.split(" ")),t.classList.add(...o.split(" ")),t.classList.remove(...i.split(" ")),t.classList.remove(...g.split(" ")),await w(),t.classList.remove(...o.split(" ")),t.classList.add(...i.split(" "));try{await y(t)}finally{t.classList.remove(...s.split(" "))}}async function b(t,e={}){let s=t.dataset.transitionLeave||e.leave||"leave",o=t.dataset.transitionLeaveFrom||e.leaveFrom||"leave-from",i=t.dataset.transitionLeaveTo||e.leaveTo||"leave-to",g=t.dataset.toggleClass||e.toogle||"hidden";t.classList.add(...s.split(" ")),t.classList.add(...o.split(" ")),t.classList.remove(...i.split(" ")),await w(),t.classList.remove(...o.split(" ")),t.classList.add(...i.split(" "));try{await y(t)}finally{t.classList.remove(...s.split(" ")),t.classList.add(...g.split(" "))}}function w(){return new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(t)})})}function y(t){return Promise.all(t.getAnimations().map(e=>e.finished))}var p=class extends I.Controller{connect(){setTimeout(()=>{x(this.element)},this.showDelayValue),this.hasDismissAfterValue&&setTimeout(()=>{this.close()},this.dismissAfterValue)}close(){b(this.element).then(()=>{this.element.remove()})}};a(p,"values",{dismissAfter:Number,showDelay:{type:Number,default:0},removeDelay:{type:Number,default:1100}});var L=require("@hotwired/stimulus");var u=class extends L.Controller{connect(){this.timeout=null}save(){clearTimeout(this.timeout),this.timeout=setTimeout(()=>{this.statusTarget.textContent=this.submittingTextValue,this.formTarget.requestSubmit()},this.submitDurationValue)}success(){this.setStatus(this.successTextValue)}error(){this.setStatus(this.errorTextValue)}setStatus(t){this.statusTarget.textContent=t,this.timeout=setTimeout(()=>{this.statusTarget.textContent=""},this.statusDurationValue)}};a(u,"targets",["form","status"]),a(u,"values",{submitDuration:{type:Number,default:1e3},statusDuration:{type:Number,default:2e3},submittingText:{type:String,default:"Saving..."},successText:{type:String,default:"Saved!"},errorText:{type:String,default:"Unable to save."}});var A=require("@hotwired/stimulus");var h=class extends A.Controller{update(){this.preview=this.colorTarget.value}set preview(t){this.previewTarget.style[this.styleValue]=t;let e=this._getContrastYIQ(t);this.styleValue==="color"?this.previewTarget.style.backgroundColor=e:this.previewTarget.style.color=e}_getContrastYIQ(t){t=t.replace("#","");let e=128,s=parseInt(t.substr(0,2),16),o=parseInt(t.substr(2,2),16),i=parseInt(t.substr(4,2),16);return(s*299+o*587+i*114)/1e3>=e?"#000":"#fff"}};a(h,"targets",["preview","color"]),a(h,"values",{style:{type:String,default:"backgroundColor"}});var D=require("@hotwired/stimulus");var v,E,n=class extends D.Controller{constructor(){super(...arguments);V(this,v)}connect(){document.addEventListener("turbo:before-cache",this.beforeCache.bind(this)),C(this,v,E).call(this)}disconnect(){document.removeEventListener("turbo:before-cache",this.beforeCache.bind(this)),this.hasButtonTarget&&(this.buttonTarget.removeEventListener("keydown",this._onMenuButtonKeydown),this.buttonTarget.removeAttribute("aria-haspopup"))}openValueChanged(){r(this.menuTarget,this.openValue,this.transitionOptions),this.openValue===!0&&this.hasMenuItemTarget&&this.menuItemTargets[0].focus()}show(){this.openValue=!0}close(){this.openValue=!1}hide(e){this.closeOnClickOutsideValue&&e.target.nodeType&&this.element.contains(e.target)===!1&&this.openValue&&(this.openValue=!1),this.closeOnEscapeValue&&e.key==="Escape"&&this.openValue&&(this.openValue=!1)}toggle(){this.openValue=!this.openValue}nextItem(e){e.preventDefault(),this.menuItemTargets[this.nextIndex].focus()}previousItem(e){e.preventDefault(),this.menuItemTargets[this.previousIndex].focus()}get currentItemIndex(){return this.menuItemTargets.indexOf(document.activeElement)}get nextIndex(){return Math.min(this.currentItemIndex+1,this.menuItemTargets.length-1)}get previousIndex(){return Math.max(this.currentItemIndex-1,0)}get transitionOptions(){return{enter:this.hasEnterClass?this.enterClass:"transition ease-out duration-100",enterFrom:this.hasEnterFromClass?this.enterFromClass:"transform opacity-0 scale-95",enterTo:this.hasEnterToClass?this.enterToClass:"transform opacity-100 scale-100",leave:this.hasLeaveClass?this.leaveClass:"transition ease-in duration-75",leaveFrom:this.hasLeaveFromClass?this.leaveFromClass:"transform opacity-100 scale-100",leaveTo:this.hasLeaveToClass?this.leaveToClass:"transform opacity-0 scale-95",toggleClass:this.hasToggleClass?this.toggleClass:"hidden"}}beforeCache(){this.openValue=!1,this.menuTarget.classList.add("hidden")}};v=new WeakSet,E=function(){let e=this.element.dataset.action?this.element.dataset.action.split(" "):[];e.push("click->dropdown#toggle"),e.push("click@window->dropdown#hide"),e.push("keydown.up->dropdown#previousItem"),e.push("keydown.down->dropdown#nextItem"),e.push("keydown.esc->dropdown#hide"),this.element.dataset.action=[...new Set(e)].join(" ")},a(n,"targets",["menu","button","menuItem"]),a(n,"values",{open:{type:Boolean,default:!1},closeOnEscape:{type:Boolean,default:!0},closeOnClickOutside:{type:Boolean,default:!0}}),a(n,"classes",["enter","enterFrom","enterTo","leave","leaveFrom","leaveTo","toggle"]);var S=require("@hotwired/stimulus");var c=class extends S.Controller{connect(){this.openValue&&this.open()}open(){this.dialogTarget.showModal()}close(){this.dialogTarget.close()}show(){this.dialogTarget.show()}};a(c,"targets",["dialog"]),a(c,"values",{open:Boolean});var F=require("@hotwired/stimulus");var d=class extends F.Controller{openValueChanged(){r(this.contentTarget,this.openValue),this.shouldAutoDismiss&&this.scheduleDismissal()}show(t){this.shouldAutoDismiss&&this.scheduleDismissal(),this.openValue=!0}hide(){this.openValue=!1}toggle(){this.openValue=!this.openValue}get shouldAutoDismiss(){return this.openValue&&this.hasDismissAfterValue}scheduleDismissal(){this.hasDismissAfterValue&&(this.cancelDismissal(),this.timeoutId=setTimeout(()=>{this.hide(),this.timeoutId=void 0},this.dismissAfterValue))}cancelDismissal(){typeof this.timeoutId=="number"&&(clearTimeout(this.timeoutId),this.timeoutId=void 0)}};a(d,"targets",["content"]),a(d,"values",{dismissAfter:Number,open:{type:Boolean,default:!1}});var f=class extends n{openValueChanged(){r(this.overlayTarget,this.openValue),r(this.menuTarget,this.openValue),this.hasCloseTarget&&r(this.closeTarget,this.openValue)}};a(f,"targets",["overlay","close"]);var k=require("@hotwired/stimulus");var l=class extends k.Controller{initialize(){this.anchor&&(this.indexValue=this.tabTargets.findIndex(t=>t.id===this.anchor))}connect(){this.showTab()}change(t){t.currentTarget.tagName==="SELECT"?this.indexValue=t.currentTarget.selectedIndex:t.currentTarget.dataset.index?this.indexValue=t.currentTarget.dataset.index:t.currentTarget.dataset.id?this.indexValue=this.tabTargets.findIndex(e=>e.id==t.currentTarget.dataset.id):this.indexValue=this.tabTargets.indexOf(t.currentTarget),window.dispatchEvent(new CustomEvent("tsc:tab-change"))}nextTab(){this.indexValue=Math.min(this.indexValue+1,this.tabsCount-1)}previousTab(){this.indexValue=Math.max(this.indexValue-1,0)}firstTab(){this.indexValue=0}lastTab(){this.indexValue=this.tabsCount-1}indexValueChanged(){if(this.showTab(),this.updateAnchorValue){let t=this.tabTargets[this.indexValue].id;if(this.scrollToAnchorValue)location.hash=t;else{let s=window.location.href.split("#")[0]+"#"+t;history.replaceState({},document.title,s)}}}showTab(){this.panelTargets.forEach((t,e)=>{let s=this.tabTargets[e];e===this.indexValue?(t.classList.remove("hidden"),s.ariaSelected="true",this.hasInactiveTabClass&&s?.classList?.remove(...this.inactiveTabClasses),this.hasActiveTabClass&&s?.classList?.add(...this.activeTabClasses)):(t.classList.add("hidden"),s.ariaSelected=null,this.hasActiveTabClass&&s?.classList?.remove(...this.activeTabClasses),this.hasInactiveTabClass&&s?.classList?.add(...this.inactiveTabClasses))}),this.hasSelectTarget&&(this.selectTarget.selectedIndex=this.indexValue),this.scrollActiveTabIntoView()}scrollActiveTabIntoView(){let t=this.element.querySelector("[aria-selected]");t&&t.scrollIntoView({inline:"center"})}get tabsCount(){return this.tabTargets.length}get anchor(){return document.URL.split("#").length>1?document.URL.split("#")[1]:null}};a(l,"classes",["activeTab","inactiveTab"]),a(l,"targets",["tab","panel","select"]),a(l,"values",{index:0,updateAnchor:Boolean,scrollToAnchor:Boolean});var B=require("@hotwired/stimulus");var m=class extends B.Controller{toggle(t){this.openValue=!this.openValue,this.animate()}toggleInput(t){this.openValue=t.target.checked,this.animate()}hide(){this.openValue=!1,this.animate()}show(){this.openValue=!0,this.animate()}animate(){this.toggleableTargets.forEach(t=>{r(t,this.openValue)})}};a(m,"targets",["toggleable"]),a(m,"values",{open:{type:Boolean,default:!1}});
Loading

0 comments on commit 9fbd122

Please sign in to comment.