@data-slot/dialog 0.2.123 → 0.2.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,n=[];let r=null;function i(){n.forEach((e,t)=>{let n=String(t);e._overlay&&(e._overlay.setAttribute(`data-stack-index`,n),e._overlay.style.setProperty(`--dialog-stack-index`,n),e._overlay.style.setProperty(`--dialog-overlay-stack-index`,n)),e._content&&(e._content.setAttribute(`data-stack-index`,n),e._content.style.setProperty(`--dialog-stack-index`,n),e._content.style.setProperty(`--dialog-content-stack-index`,n))})}function a(){if(r)return;let t=(0,e.on)(document,`keydown`,e=>{if(n.length===0)return;let t=n[n.length-1];!t||!t.isOpen||e.key===`Tab`&&t._handleKeydown&&t._handleKeydown(e)});r=()=>{t(),r=null}}function o(){n.length===0&&r&&r()}function s(r,s={}){let c=s.defaultOpen??(0,e.getDataBool)(r,`defaultOpen`)??!1,l=s.onOpenChange,u=s.closeOnClickOutside??(0,e.getDataBool)(r,`closeOnClickOutside`)??!0,d=s.closeOnEscape??(0,e.getDataBool)(r,`closeOnEscape`)??!0,f=s.lockScroll??(0,e.getDataBool)(r,`lockScroll`)??!0,p=s.alertDialog??(0,e.getDataBool)(r,`alertDialog`)??!1,m=(0,e.getPart)(r,`dialog-trigger`),h=(0,e.getPart)(r,`dialog-portal`),g=(0,e.getPart)(r,`dialog-overlay`),_=(0,e.getPart)(r,`dialog-content`),v=(0,e.getPart)(r,`dialog-title`),y=(0,e.getPart)(r,`dialog-description`);if(!_)throw Error(`Dialog requires dialog-content slot`);if(!g)throw Error(`Dialog requires dialog-overlay slot`);let b=!1,x=null,S=[],C=h?(0,e.createPortalLifecycle)({content:h,root:r}):null,w=!1;(0,e.ensureId)(_,`dialog-content`),_.setAttribute(`role`,p?`alertdialog`:`dialog`),(0,e.setAria)(_,`modal`,!0),(0,e.linkLabelledBy)(_,v,y),g.setAttribute(`role`,`presentation`),g.setAttribute(`aria-hidden`,`true`),g.tabIndex=-1,m&&(m.setAttribute(`aria-haspopup`,`dialog`),m.setAttribute(`aria-controls`,_.id),(0,e.setAria)(m,`expanded`,!1));let T=!1,E=()=>{_.hasAttribute(`tabindex`)||(_.tabIndex=-1,T=!0)},D=()=>{T&&=(_.removeAttribute(`tabindex`),!1)},O=()=>{let e=_.querySelector(`[autofocus]`);if(e)return e.focus();let n=_.querySelector(t);if(n)return n.focus();E(),_.focus()},k=()=>{C?.mount()},A=e=>{r.setAttribute(`data-state`,e),h&&h.setAttribute(`data-state`,e),g.setAttribute(`data-state`,e),_.setAttribute(`data-state`,e)},j=()=>{g.removeAttribute(`data-stack-index`),_.removeAttribute(`data-stack-index`),g.style.removeProperty(`--dialog-stack-index`),g.style.removeProperty(`--dialog-overlay-stack-index`),_.style.removeProperty(`--dialog-stack-index`),_.style.removeProperty(`--dialog-content-stack-index`)},M=(t,s=!1)=>{if(!(b===t&&!s)){if(t)k(),x=document.activeElement,n.push(P),a(),i(),f&&!w&&((0,e.lockScroll)(),w=!0);else{let t=n.indexOf(P);t!==-1&&n.splice(t,1),o(),j(),i(),w&&=((0,e.unlockScroll)(),!1),D();let r=x;x=null,requestAnimationFrame(()=>{r&&document.contains(r)&&typeof r.focus==`function`?(0,e.focusElement)(r):m&&document.contains(m)&&(0,e.focusElement)(m)})}b=t,_.hidden=!b,g.hidden=!b,m&&(0,e.setAria)(m,`expanded`,b),A(b?`open`:`closed`),(0,e.emit)(r,`dialog:change`,{open:b}),l?.(b),t&&requestAnimationFrame(O)}},N=e=>{if(e.key!==`Tab`)return;let n=_.querySelectorAll(t);if(n.length===0){e.preventDefault(),E(),_.focus();return}let r=n[0],i=n[n.length-1],a=document.activeElement;if(!_.contains(a)){e.preventDefault(),r.focus();return}if(r===i){e.preventDefault();return}e.shiftKey?a===r&&(e.preventDefault(),i.focus()):a===i&&(e.preventDefault(),r.focus())};c?(k(),_.hidden=!1,g.hidden=!1,A(`open`),b=!0,m&&(0,e.setAria)(m,`expanded`,!0)):(_.hidden=!0,g.hidden=!0,A(`closed`)),m&&S.push((0,e.on)(m,`click`,()=>M(!b))),S.push((0,e.on)(_,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&_.contains(n)&&M(!1)})),u&&S.push((0,e.on)(g,`click`,e=>{e.button===0&&e.target===g&&b&&M(!1)})),S.push((0,e.createDismissLayer)({root:r,isOpen:()=>b,onDismiss:()=>M(!1),closeOnClickOutside:!1,closeOnEscape:d}));let P={open:()=>M(!0),close:()=>M(!1),toggle:()=>M(!b),get isOpen(){return b},destroy:()=>{if(b)M(!1,!0);else{let e=n.indexOf(P);e!==-1&&(n.splice(e,1),i(),o())}D(),S.forEach(e=>e()),S.length=0,C?.cleanup()},_handleKeydown:N,_content:_,_overlay:g};return S.push((0,e.on)(r,`dialog:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&M(n)})),c&&(x=document.activeElement,n.push(P),a(),i(),f&&!w&&((0,e.lockScroll)(),w=!0),(0,e.emit)(r,`dialog:change`,{open:!0}),l?.(!0),requestAnimationFrame(O)),P}const c=new WeakSet;function l(t=document){let n=[];for(let r of(0,e.getRoots)(t,`dialog`))c.has(r)||(c.add(r),n.push(s(r)));return n}exports.create=l,exports.createDialog=s;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=`@data-slot/dialog`,n=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,r=[];let i=null;function a(){r.forEach((e,t)=>{let n=String(t);e._overlay&&(e._overlay.setAttribute(`data-stack-index`,n),e._overlay.style.setProperty(`--dialog-stack-index`,n),e._overlay.style.setProperty(`--dialog-overlay-stack-index`,n)),e._content&&(e._content.setAttribute(`data-stack-index`,n),e._content.style.setProperty(`--dialog-stack-index`,n),e._content.style.setProperty(`--dialog-content-stack-index`,n))})}function o(){if(i)return;let t=(0,e.on)(document,`keydown`,e=>{if(r.length===0)return;let t=r[r.length-1];!t||!t.isOpen||e.key===`Tab`&&t._handleKeydown&&t._handleKeydown(e)});i=()=>{t(),i=null}}function s(){r.length===0&&i&&i()}function c(i,c={}){let l=(0,e.reuseRootBinding)(i,t,`[@data-slot/dialog] createDialog() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(l)return l;let u=c.defaultOpen??(0,e.getDataBool)(i,`defaultOpen`)??!1,d=c.onOpenChange,f=c.closeOnClickOutside??(0,e.getDataBool)(i,`closeOnClickOutside`)??!0,p=c.closeOnEscape??(0,e.getDataBool)(i,`closeOnEscape`)??!0,m=c.lockScroll??(0,e.getDataBool)(i,`lockScroll`)??!0,h=c.alertDialog??(0,e.getDataBool)(i,`alertDialog`)??!1,g=(0,e.getPart)(i,`dialog-trigger`),_=(0,e.getPart)(i,`dialog-portal`),v=(0,e.getPart)(i,`dialog-overlay`),y=(0,e.getPart)(i,`dialog-content`),b=(0,e.getPart)(i,`dialog-title`),x=(0,e.getPart)(i,`dialog-description`);if(!y)throw Error(`Dialog requires dialog-content slot`);if(!v)throw Error(`Dialog requires dialog-overlay slot`);let S=!1,C=null,w=[],T=_?(0,e.createPortalLifecycle)({content:_,root:i}):null,E=!1;(0,e.ensureId)(y,`dialog-content`),y.setAttribute(`role`,h?`alertdialog`:`dialog`),(0,e.setAria)(y,`modal`,!0),(0,e.linkLabelledBy)(y,b,x),v.setAttribute(`role`,`presentation`),v.setAttribute(`aria-hidden`,`true`),v.tabIndex=-1,g&&(g.setAttribute(`aria-haspopup`,`dialog`),g.setAttribute(`aria-controls`,y.id),(0,e.setAria)(g,`expanded`,!1));let D=!1,O=()=>{y.hasAttribute(`tabindex`)||(y.tabIndex=-1,D=!0)},k=()=>{D&&=(y.removeAttribute(`tabindex`),!1)},A=()=>{let e=y.querySelector(`[autofocus]`);if(e)return e.focus();let t=y.querySelector(n);if(t)return t.focus();O(),y.focus()},j=()=>{T?.mount()},M=e=>{i.setAttribute(`data-state`,e),_&&_.setAttribute(`data-state`,e),v.setAttribute(`data-state`,e),y.setAttribute(`data-state`,e)},N=()=>{v.removeAttribute(`data-stack-index`),y.removeAttribute(`data-stack-index`),v.style.removeProperty(`--dialog-stack-index`),v.style.removeProperty(`--dialog-overlay-stack-index`),y.style.removeProperty(`--dialog-stack-index`),y.style.removeProperty(`--dialog-content-stack-index`)},P=(t,n=!1)=>{if(!(S===t&&!n)){if(t)j(),C=document.activeElement,r.push(I),o(),a(),m&&!E&&((0,e.lockScroll)(),E=!0);else{let t=r.indexOf(I);t!==-1&&r.splice(t,1),s(),N(),a(),E&&=((0,e.unlockScroll)(),!1),k();let n=C;C=null,requestAnimationFrame(()=>{n&&document.contains(n)&&typeof n.focus==`function`?(0,e.focusElement)(n):g&&document.contains(g)&&(0,e.focusElement)(g)})}S=t,y.hidden=!S,v.hidden=!S,g&&(0,e.setAria)(g,`expanded`,S),M(S?`open`:`closed`),(0,e.emit)(i,`dialog:change`,{open:S}),d?.(S),t&&requestAnimationFrame(A)}},F=e=>{if(e.key!==`Tab`)return;let t=y.querySelectorAll(n);if(t.length===0){e.preventDefault(),O(),y.focus();return}let r=t[0],i=t[t.length-1],a=document.activeElement;if(!y.contains(a)){e.preventDefault(),r.focus();return}if(r===i){e.preventDefault();return}e.shiftKey?a===r&&(e.preventDefault(),i.focus()):a===i&&(e.preventDefault(),r.focus())};u?(j(),y.hidden=!1,v.hidden=!1,M(`open`),S=!0,g&&(0,e.setAria)(g,`expanded`,!0)):(y.hidden=!0,v.hidden=!0,M(`closed`)),g&&w.push((0,e.on)(g,`click`,()=>P(!S))),w.push((0,e.on)(y,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&y.contains(n)&&P(!1)})),f&&w.push((0,e.on)(v,`click`,e=>{e.button===0&&e.target===v&&S&&P(!1)})),w.push((0,e.createDismissLayer)({root:i,isOpen:()=>S,onDismiss:()=>P(!1),closeOnClickOutside:!1,closeOnEscape:p}));let I={open:()=>P(!0),close:()=>P(!1),toggle:()=>P(!S),get isOpen(){return S},destroy:()=>{if(S)P(!1,!0);else{let e=r.indexOf(I);e!==-1&&(r.splice(e,1),a(),s())}k(),w.forEach(e=>e()),w.length=0,T?.cleanup(),(0,e.clearRootBinding)(i,t,I)},_handleKeydown:F,_content:y,_overlay:v};return w.push((0,e.on)(i,`dialog:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&P(n)})),(0,e.setRootBinding)(i,t,I),u&&(C=document.activeElement,r.push(I),o(),a(),m&&!E&&((0,e.lockScroll)(),E=!0),(0,e.emit)(i,`dialog:change`,{open:!0}),d?.(!0),requestAnimationFrame(A)),I}function l(n=document){let r=[];for(let i of(0,e.getRoots)(n,`dialog`))(0,e.hasRootBinding)(i,t)||r.push(c(i));return r}exports.create=l,exports.createDialog=c;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{createDismissLayer as e,createPortalLifecycle as t,emit as n,ensureId as r,focusElement as i,getDataBool as a,getPart as o,getRoots as s,linkLabelledBy as c,lockScroll as l,on as u,setAria as d,unlockScroll as f}from"@data-slot/core";const p=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,m=[];let h=null;function g(){m.forEach((e,t)=>{let n=String(t);e._overlay&&(e._overlay.setAttribute(`data-stack-index`,n),e._overlay.style.setProperty(`--dialog-stack-index`,n),e._overlay.style.setProperty(`--dialog-overlay-stack-index`,n)),e._content&&(e._content.setAttribute(`data-stack-index`,n),e._content.style.setProperty(`--dialog-stack-index`,n),e._content.style.setProperty(`--dialog-content-stack-index`,n))})}function _(){if(h)return;let e=u(document,`keydown`,e=>{if(m.length===0)return;let t=m[m.length-1];!t||!t.isOpen||e.key===`Tab`&&t._handleKeydown&&t._handleKeydown(e)});h=()=>{e(),h=null}}function v(){m.length===0&&h&&h()}function y(s,h={}){let y=h.defaultOpen??a(s,`defaultOpen`)??!1,b=h.onOpenChange,x=h.closeOnClickOutside??a(s,`closeOnClickOutside`)??!0,S=h.closeOnEscape??a(s,`closeOnEscape`)??!0,C=h.lockScroll??a(s,`lockScroll`)??!0,w=h.alertDialog??a(s,`alertDialog`)??!1,T=o(s,`dialog-trigger`),E=o(s,`dialog-portal`),D=o(s,`dialog-overlay`),O=o(s,`dialog-content`),k=o(s,`dialog-title`),A=o(s,`dialog-description`);if(!O)throw Error(`Dialog requires dialog-content slot`);if(!D)throw Error(`Dialog requires dialog-overlay slot`);let j=!1,M=null,N=[],P=E?t({content:E,root:s}):null,F=!1;r(O,`dialog-content`),O.setAttribute(`role`,w?`alertdialog`:`dialog`),d(O,`modal`,!0),c(O,k,A),D.setAttribute(`role`,`presentation`),D.setAttribute(`aria-hidden`,`true`),D.tabIndex=-1,T&&(T.setAttribute(`aria-haspopup`,`dialog`),T.setAttribute(`aria-controls`,O.id),d(T,`expanded`,!1));let I=!1,L=()=>{O.hasAttribute(`tabindex`)||(O.tabIndex=-1,I=!0)},R=()=>{I&&=(O.removeAttribute(`tabindex`),!1)},z=()=>{let e=O.querySelector(`[autofocus]`);if(e)return e.focus();let t=O.querySelector(p);if(t)return t.focus();L(),O.focus()},B=()=>{P?.mount()},V=e=>{s.setAttribute(`data-state`,e),E&&E.setAttribute(`data-state`,e),D.setAttribute(`data-state`,e),O.setAttribute(`data-state`,e)},H=()=>{D.removeAttribute(`data-stack-index`),O.removeAttribute(`data-stack-index`),D.style.removeProperty(`--dialog-stack-index`),D.style.removeProperty(`--dialog-overlay-stack-index`),O.style.removeProperty(`--dialog-stack-index`),O.style.removeProperty(`--dialog-content-stack-index`)},U=(e,t=!1)=>{if(!(j===e&&!t)){if(e)B(),M=document.activeElement,m.push(G),_(),g(),C&&!F&&(l(),F=!0);else{let e=m.indexOf(G);e!==-1&&m.splice(e,1),v(),H(),g(),F&&=(f(),!1),R();let t=M;M=null,requestAnimationFrame(()=>{t&&document.contains(t)&&typeof t.focus==`function`?i(t):T&&document.contains(T)&&i(T)})}j=e,O.hidden=!j,D.hidden=!j,T&&d(T,`expanded`,j),V(j?`open`:`closed`),n(s,`dialog:change`,{open:j}),b?.(j),e&&requestAnimationFrame(z)}},W=e=>{if(e.key!==`Tab`)return;let t=O.querySelectorAll(p);if(t.length===0){e.preventDefault(),L(),O.focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;if(!O.contains(i)){e.preventDefault(),n.focus();return}if(n===r){e.preventDefault();return}e.shiftKey?i===n&&(e.preventDefault(),r.focus()):i===r&&(e.preventDefault(),n.focus())};y?(B(),O.hidden=!1,D.hidden=!1,V(`open`),j=!0,T&&d(T,`expanded`,!0)):(O.hidden=!0,D.hidden=!0,V(`closed`)),T&&N.push(u(T,`click`,()=>U(!j))),N.push(u(O,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&O.contains(n)&&U(!1)})),x&&N.push(u(D,`click`,e=>{e.button===0&&e.target===D&&j&&U(!1)})),N.push(e({root:s,isOpen:()=>j,onDismiss:()=>U(!1),closeOnClickOutside:!1,closeOnEscape:S}));let G={open:()=>U(!0),close:()=>U(!1),toggle:()=>U(!j),get isOpen(){return j},destroy:()=>{if(j)U(!1,!0);else{let e=m.indexOf(G);e!==-1&&(m.splice(e,1),g(),v())}R(),N.forEach(e=>e()),N.length=0,P?.cleanup()},_handleKeydown:W,_content:O,_overlay:D};return N.push(u(s,`dialog:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&U(n)})),y&&(M=document.activeElement,m.push(G),_(),g(),C&&!F&&(l(),F=!0),n(s,`dialog:change`,{open:!0}),b?.(!0),requestAnimationFrame(z)),G}const b=new WeakSet;function x(e=document){let t=[];for(let n of s(e,`dialog`))b.has(n)||(b.add(n),t.push(y(n)));return t}export{x as create,y as createDialog};
1
+ import{clearRootBinding as e,createDismissLayer as t,createPortalLifecycle as n,emit as r,ensureId as i,focusElement as a,getDataBool as o,getPart as s,getRoots as c,hasRootBinding as l,linkLabelledBy as u,lockScroll as d,on as f,reuseRootBinding as p,setAria as m,setRootBinding as h,unlockScroll as g}from"@data-slot/core";const _=`@data-slot/dialog`,v=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,y=[];let b=null;function x(){y.forEach((e,t)=>{let n=String(t);e._overlay&&(e._overlay.setAttribute(`data-stack-index`,n),e._overlay.style.setProperty(`--dialog-stack-index`,n),e._overlay.style.setProperty(`--dialog-overlay-stack-index`,n)),e._content&&(e._content.setAttribute(`data-stack-index`,n),e._content.style.setProperty(`--dialog-stack-index`,n),e._content.style.setProperty(`--dialog-content-stack-index`,n))})}function S(){if(b)return;let e=f(document,`keydown`,e=>{if(y.length===0)return;let t=y[y.length-1];!t||!t.isOpen||e.key===`Tab`&&t._handleKeydown&&t._handleKeydown(e)});b=()=>{e(),b=null}}function C(){y.length===0&&b&&b()}function w(c,l={}){let b=p(c,_,`[@data-slot/dialog] createDialog() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(b)return b;let w=l.defaultOpen??o(c,`defaultOpen`)??!1,T=l.onOpenChange,E=l.closeOnClickOutside??o(c,`closeOnClickOutside`)??!0,D=l.closeOnEscape??o(c,`closeOnEscape`)??!0,O=l.lockScroll??o(c,`lockScroll`)??!0,k=l.alertDialog??o(c,`alertDialog`)??!1,A=s(c,`dialog-trigger`),j=s(c,`dialog-portal`),M=s(c,`dialog-overlay`),N=s(c,`dialog-content`),P=s(c,`dialog-title`),F=s(c,`dialog-description`);if(!N)throw Error(`Dialog requires dialog-content slot`);if(!M)throw Error(`Dialog requires dialog-overlay slot`);let I=!1,L=null,R=[],z=j?n({content:j,root:c}):null,B=!1;i(N,`dialog-content`),N.setAttribute(`role`,k?`alertdialog`:`dialog`),m(N,`modal`,!0),u(N,P,F),M.setAttribute(`role`,`presentation`),M.setAttribute(`aria-hidden`,`true`),M.tabIndex=-1,A&&(A.setAttribute(`aria-haspopup`,`dialog`),A.setAttribute(`aria-controls`,N.id),m(A,`expanded`,!1));let V=!1,H=()=>{N.hasAttribute(`tabindex`)||(N.tabIndex=-1,V=!0)},U=()=>{V&&=(N.removeAttribute(`tabindex`),!1)},W=()=>{let e=N.querySelector(`[autofocus]`);if(e)return e.focus();let t=N.querySelector(v);if(t)return t.focus();H(),N.focus()},G=()=>{z?.mount()},K=e=>{c.setAttribute(`data-state`,e),j&&j.setAttribute(`data-state`,e),M.setAttribute(`data-state`,e),N.setAttribute(`data-state`,e)},q=()=>{M.removeAttribute(`data-stack-index`),N.removeAttribute(`data-stack-index`),M.style.removeProperty(`--dialog-stack-index`),M.style.removeProperty(`--dialog-overlay-stack-index`),N.style.removeProperty(`--dialog-stack-index`),N.style.removeProperty(`--dialog-content-stack-index`)},J=(e,t=!1)=>{if(!(I===e&&!t)){if(e)G(),L=document.activeElement,y.push(X),S(),x(),O&&!B&&(d(),B=!0);else{let e=y.indexOf(X);e!==-1&&y.splice(e,1),C(),q(),x(),B&&=(g(),!1),U();let t=L;L=null,requestAnimationFrame(()=>{t&&document.contains(t)&&typeof t.focus==`function`?a(t):A&&document.contains(A)&&a(A)})}I=e,N.hidden=!I,M.hidden=!I,A&&m(A,`expanded`,I),K(I?`open`:`closed`),r(c,`dialog:change`,{open:I}),T?.(I),e&&requestAnimationFrame(W)}},Y=e=>{if(e.key!==`Tab`)return;let t=N.querySelectorAll(v);if(t.length===0){e.preventDefault(),H(),N.focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;if(!N.contains(i)){e.preventDefault(),n.focus();return}if(n===r){e.preventDefault();return}e.shiftKey?i===n&&(e.preventDefault(),r.focus()):i===r&&(e.preventDefault(),n.focus())};w?(G(),N.hidden=!1,M.hidden=!1,K(`open`),I=!0,A&&m(A,`expanded`,!0)):(N.hidden=!0,M.hidden=!0,K(`closed`)),A&&R.push(f(A,`click`,()=>J(!I))),R.push(f(N,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&N.contains(n)&&J(!1)})),E&&R.push(f(M,`click`,e=>{e.button===0&&e.target===M&&I&&J(!1)})),R.push(t({root:c,isOpen:()=>I,onDismiss:()=>J(!1),closeOnClickOutside:!1,closeOnEscape:D}));let X={open:()=>J(!0),close:()=>J(!1),toggle:()=>J(!I),get isOpen(){return I},destroy:()=>{if(I)J(!1,!0);else{let e=y.indexOf(X);e!==-1&&(y.splice(e,1),x(),C())}U(),R.forEach(e=>e()),R.length=0,z?.cleanup(),e(c,_,X)},_handleKeydown:Y,_content:N,_overlay:M};return R.push(f(c,`dialog:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&J(n)})),h(c,_,X),w&&(L=document.activeElement,y.push(X),S(),x(),O&&!B&&(d(),B=!0),r(c,`dialog:change`,{open:!0}),T?.(!0),requestAnimationFrame(W)),X}function T(e=document){let t=[];for(let n of c(e,`dialog`))l(n,_)||t.push(w(n));return t}export{T as create,w as createDialog};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/dialog",
3
- "version": "0.2.123",
3
+ "version": "0.2.124",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -35,6 +35,6 @@
35
35
  ],
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@data-slot/core": "0.2.123"
38
+ "@data-slot/core": "0.2.124"
39
39
  }
40
40
  }