@data-slot/dialog 0.2.29 → 0.2.31

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
- const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],n=new WeakMap;function r(e,t,r){if(typeof process<`u`&&process.env?.NODE_ENV===`production`)return;let i=n.get(e);i||(i=new Set,n.set(e,i)),!i.has(t)&&(i.add(t),console.warn(`[@data-slot] ${r}`))}function i(e){let t=`data-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}`,n=`data-${e}`;return t===n?[t]:[t,n]}function a(e,t){for(let n of i(t))if(e.hasAttribute(n))return e.getAttribute(n);return null}function o(e,t){return i(t).some(t=>e.hasAttribute(t))}const s=new Set([``,`true`,`1`,`yes`]),c=new Set([`false`,`0`,`no`]);function l(e,t){if(!o(e,t))return;let n=a(e,t);if(n===null)return;let i=n.toLowerCase();if(s.has(i))return!0;if(c.has(i))return!1;r(e,t,`Invalid boolean value "${n}" for data-${t}. Expected: true/false/1/0/yes/no or empty.`)}const u=Symbol.for(`data-slot.portal-owner`);let d=0;const f=(e,t)=>e.id||=`${t}-${++d}`,p=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},m=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,f(t,`title`)),n&&e.setAttribute(`aria-describedby`,f(n,`desc`))};function h(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const g=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let _=0,v=``,y=``;function b(){if(_===0){let e=document.documentElement;v=e.style.overflow,y=e.style.scrollbarGutter,e.style.overflow=`hidden`,e.style.scrollbarGutter=`stable`}_++}function x(){if(_=Math.max(0,_-1),_===0){let e=document.documentElement;e.style.overflow=v,e.style.scrollbarGutter=y}}const S=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,C=[];let w=null;function T(){let e=1e3;C.forEach((t,n)=>{let r=e+n*10;t._overlay&&(t._overlay.style.zIndex=String(r)),t._content&&(t._content.style.zIndex=String(r+1))})}function E(){if(w)return;let e=e=>{if(C.length===0)return;let t=C[C.length-1];if(!(!t||!t.isOpen)){if(e.key===`Escape`&&t._closeOnEscape){e.preventDefault(),t.close();return}e.key===`Tab`&&t._handleKeydown&&t._handleKeydown(e)}},t=h(document,`keydown`,e);w=()=>{t(),w=null}}function D(){C.length===0&&w&&w()}function O(t,n={}){let r=n.defaultOpen??l(t,`defaultOpen`)??!1,i=n.onOpenChange,a=n.closeOnClickOutside??l(t,`closeOnClickOutside`)??!0,o=n.closeOnEscape??l(t,`closeOnEscape`)??!0,s=n.lockScroll??l(t,`lockScroll`)??!0,c=n.alertDialog??l(t,`alertDialog`)??!1,u=e(t,`dialog-trigger`),d=e(t,`dialog-portal`),_=e(t,`dialog-overlay`),v=e(t,`dialog-content`),y=e(t,`dialog-title`),w=e(t,`dialog-description`);if(!v)throw Error(`Dialog requires dialog-content slot`);if(!_)throw Error(`Dialog requires dialog-overlay slot`);let O=!1,k=null,A=[],j=null,M=null,N=!1,P=!1;f(v,`dialog-content`),v.setAttribute(`role`,c?`alertdialog`:`dialog`),p(v,`modal`,!0),m(v,y,w),_.setAttribute(`role`,`presentation`),_.setAttribute(`aria-hidden`,`true`),_.tabIndex=-1,u&&(u.setAttribute(`aria-haspopup`,`dialog`),u.setAttribute(`aria-controls`,v.id),p(u,`expanded`,!1));let F=!1,I=()=>{v.hasAttribute(`tabindex`)||(v.tabIndex=-1,F=!0)},L=()=>{F&&(v.removeAttribute(`tabindex`),F=!1)},R=()=>{let e=v.querySelector(`[autofocus]`);if(e)return e.focus();let t=v.querySelector(S);if(t)return t.focus();I(),v.focus()},z=()=>{d&&!N&&(j=d.parentNode,M=d.nextSibling,document.body.appendChild(d),N=!0)},B=e=>{t.setAttribute(`data-state`,e),d&&d.setAttribute(`data-state`,e),_.setAttribute(`data-state`,e),v.setAttribute(`data-state`,e)},V=()=>{_.style.zIndex=``,v.style.zIndex=``},H=(e,n=!1)=>{if(!(O===e&&!n)){if(e)z(),k=document.activeElement,C.push(W),E(),T(),s&&!P&&(b(),P=!0);else{let e=C.indexOf(W);e!==-1&&C.splice(e,1),D(),V(),T(),P&&(x(),P=!1),L();let t=k;k=null,requestAnimationFrame(()=>{t&&document.contains(t)&&typeof t.focus==`function`?t.focus():u&&document.contains(u)&&u.focus()})}O=e,v.hidden=!O,_.hidden=!O,u&&p(u,`expanded`,O),B(O?`open`:`closed`),g(t,`dialog:change`,{open:O}),i?.(O),e&&requestAnimationFrame(R)}},U=e=>{if(e.key!==`Tab`)return;let t=v.querySelectorAll(S);if(t.length===0){e.preventDefault(),I(),v.focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;if(!v.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())};r?(z(),v.hidden=!1,_.hidden=!1,B(`open`),O=!0,u&&p(u,`expanded`,!0)):(v.hidden=!0,_.hidden=!0,B(`closed`)),u&&A.push(h(u,`click`,()=>H(!O))),A.push(h(v,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&v.contains(n)&&H(!1)})),a&&A.push(h(_,`pointerdown`,e=>{e.target===_&&O&&H(!1)}));let W={open:()=>H(!0),close:()=>H(!1),toggle:()=>H(!O),get isOpen(){return O},destroy:()=>{if(O)H(!1,!0);else{let e=C.indexOf(W);e!==-1&&(C.splice(e,1),T(),D())}L(),A.forEach(e=>e()),A.length=0,d&&N&&(j&&document.contains(j)?j.insertBefore(d,M):d.remove(),N=!1)},_handleKeydown:U,_closeOnEscape:o,_content:v,_overlay:_};return A.push(h(t,`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`&&H(n)})),r&&(k=document.activeElement,C.push(W),E(),T(),s&&!P&&(b(),P=!0),g(t,`dialog:change`,{open:!0}),i?.(!0),requestAnimationFrame(R)),W}const k=new WeakSet;function A(e=document){let n=[];for(let r of t(e,`dialog`)){if(k.has(r))continue;k.add(r),n.push(O(r))}return n}exports.create=A,exports.createDialog=O;
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=s(require(`@data-slot/core`)),l=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,u=[];let d=null;function f(){let e=1e3;u.forEach((t,n)=>{let r=e+n*10;t._overlay&&(t._overlay.style.zIndex=String(r)),t._content&&(t._content.style.zIndex=String(r+1))})}function p(){if(d)return;let e=e=>{if(u.length===0)return;let t=u[u.length-1];if(!(!t||!t.isOpen)){if(e.key===`Escape`&&t._closeOnEscape){e.preventDefault(),t.close();return}e.key===`Tab`&&t._handleKeydown&&t._handleKeydown(e)}},t=(0,c.on)(document,`keydown`,e);d=()=>{t(),d=null}}function m(){u.length===0&&d&&d()}function h(e,t={}){let n=t.defaultOpen??(0,c.getDataBool)(e,`defaultOpen`)??!1,r=t.onOpenChange,i=t.closeOnClickOutside??(0,c.getDataBool)(e,`closeOnClickOutside`)??!0,a=t.closeOnEscape??(0,c.getDataBool)(e,`closeOnEscape`)??!0,o=t.lockScroll??(0,c.getDataBool)(e,`lockScroll`)??!0,s=t.alertDialog??(0,c.getDataBool)(e,`alertDialog`)??!1,d=(0,c.getPart)(e,`dialog-trigger`),h=(0,c.getPart)(e,`dialog-portal`),g=(0,c.getPart)(e,`dialog-overlay`),_=(0,c.getPart)(e,`dialog-content`),v=(0,c.getPart)(e,`dialog-title`),y=(0,c.getPart)(e,`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,c.createPortalLifecycle)({content:h,root:e}):null,w=!1;(0,c.ensureId)(_,`dialog-content`),_.setAttribute(`role`,s?`alertdialog`:`dialog`),(0,c.setAria)(_,`modal`,!0),(0,c.linkLabelledBy)(_,v,y),g.setAttribute(`role`,`presentation`),g.setAttribute(`aria-hidden`,`true`),g.tabIndex=-1,d&&(d.setAttribute(`aria-haspopup`,`dialog`),d.setAttribute(`aria-controls`,_.id),(0,c.setAria)(d,`expanded`,!1));let T=!1,E=()=>{_.hasAttribute(`tabindex`)||(_.tabIndex=-1,T=!0)},D=()=>{T&&(_.removeAttribute(`tabindex`),T=!1)},O=()=>{let e=_.querySelector(`[autofocus]`);if(e)return e.focus();let t=_.querySelector(l);if(t)return t.focus();E(),_.focus()},k=()=>{C?.mount()},A=t=>{e.setAttribute(`data-state`,t),h&&h.setAttribute(`data-state`,t),g.setAttribute(`data-state`,t),_.setAttribute(`data-state`,t)},j=()=>{g.style.zIndex=``,_.style.zIndex=``},M=(t,n=!1)=>{if(!(b===t&&!n)){if(t)k(),x=document.activeElement,u.push(P),p(),f(),o&&!w&&((0,c.lockScroll)(),w=!0);else{let e=u.indexOf(P);e!==-1&&u.splice(e,1),m(),j(),f(),w&&((0,c.unlockScroll)(),w=!1),D();let t=x;x=null,requestAnimationFrame(()=>{t&&document.contains(t)&&typeof t.focus==`function`?t.focus():d&&document.contains(d)&&d.focus()})}b=t,_.hidden=!b,g.hidden=!b,d&&(0,c.setAria)(d,`expanded`,b),A(b?`open`:`closed`),(0,c.emit)(e,`dialog:change`,{open:b}),r?.(b),t&&requestAnimationFrame(O)}},N=e=>{if(e.key!==`Tab`)return;let t=_.querySelectorAll(l);if(t.length===0){e.preventDefault(),E(),_.focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;if(!_.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())};n?(k(),_.hidden=!1,g.hidden=!1,A(`open`),b=!0,d&&(0,c.setAria)(d,`expanded`,!0)):(_.hidden=!0,g.hidden=!0,A(`closed`)),d&&S.push((0,c.on)(d,`click`,()=>M(!b))),S.push((0,c.on)(_,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&_.contains(n)&&M(!1)})),i&&S.push((0,c.on)(g,`pointerdown`,e=>{e.target===g&&b&&M(!1)}));let P={open:()=>M(!0),close:()=>M(!1),toggle:()=>M(!b),get isOpen(){return b},destroy:()=>{if(b)M(!1,!0);else{let e=u.indexOf(P);e!==-1&&(u.splice(e,1),f(),m())}D(),S.forEach(e=>e()),S.length=0,C?.cleanup()},_handleKeydown:N,_closeOnEscape:a,_content:_,_overlay:g};return S.push((0,c.on)(e,`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)})),n&&(x=document.activeElement,u.push(P),p(),f(),o&&!w&&((0,c.lockScroll)(),w=!0),(0,c.emit)(e,`dialog:change`,{open:!0}),r?.(!0),requestAnimationFrame(O)),P}const g=new WeakSet;function _(e=document){let t=[];for(let n of(0,c.getRoots)(e,`dialog`)){if(g.has(n))continue;g.add(n),t.push(h(n))}return t}exports.create=_,exports.createDialog=h;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)],n=new WeakMap;function r(e,t,r){if(typeof process<`u`&&process.env?.NODE_ENV===`production`)return;let i=n.get(e);i||(i=new Set,n.set(e,i)),!i.has(t)&&(i.add(t),console.warn(`[@data-slot] ${r}`))}function i(e){let t=`data-${e.replace(/([A-Z])/g,`-$1`).toLowerCase()}`,n=`data-${e}`;return t===n?[t]:[t,n]}function a(e,t){for(let n of i(t))if(e.hasAttribute(n))return e.getAttribute(n);return null}function o(e,t){return i(t).some(t=>e.hasAttribute(t))}const s=new Set([``,`true`,`1`,`yes`]),c=new Set([`false`,`0`,`no`]);function l(e,t){if(!o(e,t))return;let n=a(e,t);if(n===null)return;let i=n.toLowerCase();if(s.has(i))return!0;if(c.has(i))return!1;r(e,t,`Invalid boolean value "${n}" for data-${t}. Expected: true/false/1/0/yes/no or empty.`)}const u=Symbol.for(`data-slot.portal-owner`);let d=0;const f=(e,t)=>e.id||=`${t}-${++d}`,p=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},m=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,f(t,`title`)),n&&e.setAttribute(`aria-describedby`,f(n,`desc`))};function h(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const g=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let _=0,v=``,y=``;function b(){if(_===0){let e=document.documentElement;v=e.style.overflow,y=e.style.scrollbarGutter,e.style.overflow=`hidden`,e.style.scrollbarGutter=`stable`}_++}function x(){if(_=Math.max(0,_-1),_===0){let e=document.documentElement;e.style.overflow=v,e.style.scrollbarGutter=y}}const S=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,C=[];let w=null;function T(){let e=1e3;C.forEach((t,n)=>{let r=e+n*10;t._overlay&&(t._overlay.style.zIndex=String(r)),t._content&&(t._content.style.zIndex=String(r+1))})}function E(){if(w)return;let e=e=>{if(C.length===0)return;let t=C[C.length-1];if(!(!t||!t.isOpen)){if(e.key===`Escape`&&t._closeOnEscape){e.preventDefault(),t.close();return}e.key===`Tab`&&t._handleKeydown&&t._handleKeydown(e)}},t=h(document,`keydown`,e);w=()=>{t(),w=null}}function D(){C.length===0&&w&&w()}function O(t,n={}){let r=n.defaultOpen??l(t,`defaultOpen`)??!1,i=n.onOpenChange,a=n.closeOnClickOutside??l(t,`closeOnClickOutside`)??!0,o=n.closeOnEscape??l(t,`closeOnEscape`)??!0,s=n.lockScroll??l(t,`lockScroll`)??!0,c=n.alertDialog??l(t,`alertDialog`)??!1,u=e(t,`dialog-trigger`),d=e(t,`dialog-portal`),_=e(t,`dialog-overlay`),v=e(t,`dialog-content`),y=e(t,`dialog-title`),w=e(t,`dialog-description`);if(!v)throw Error(`Dialog requires dialog-content slot`);if(!_)throw Error(`Dialog requires dialog-overlay slot`);let O=!1,k=null,A=[],j=null,M=null,N=!1,P=!1;f(v,`dialog-content`),v.setAttribute(`role`,c?`alertdialog`:`dialog`),p(v,`modal`,!0),m(v,y,w),_.setAttribute(`role`,`presentation`),_.setAttribute(`aria-hidden`,`true`),_.tabIndex=-1,u&&(u.setAttribute(`aria-haspopup`,`dialog`),u.setAttribute(`aria-controls`,v.id),p(u,`expanded`,!1));let F=!1,I=()=>{v.hasAttribute(`tabindex`)||(v.tabIndex=-1,F=!0)},L=()=>{F&&(v.removeAttribute(`tabindex`),F=!1)},R=()=>{let e=v.querySelector(`[autofocus]`);if(e)return e.focus();let t=v.querySelector(S);if(t)return t.focus();I(),v.focus()},z=()=>{d&&!N&&(j=d.parentNode,M=d.nextSibling,document.body.appendChild(d),N=!0)},B=e=>{t.setAttribute(`data-state`,e),d&&d.setAttribute(`data-state`,e),_.setAttribute(`data-state`,e),v.setAttribute(`data-state`,e)},V=()=>{_.style.zIndex=``,v.style.zIndex=``},H=(e,n=!1)=>{if(!(O===e&&!n)){if(e)z(),k=document.activeElement,C.push(W),E(),T(),s&&!P&&(b(),P=!0);else{let e=C.indexOf(W);e!==-1&&C.splice(e,1),D(),V(),T(),P&&(x(),P=!1),L();let t=k;k=null,requestAnimationFrame(()=>{t&&document.contains(t)&&typeof t.focus==`function`?t.focus():u&&document.contains(u)&&u.focus()})}O=e,v.hidden=!O,_.hidden=!O,u&&p(u,`expanded`,O),B(O?`open`:`closed`),g(t,`dialog:change`,{open:O}),i?.(O),e&&requestAnimationFrame(R)}},U=e=>{if(e.key!==`Tab`)return;let t=v.querySelectorAll(S);if(t.length===0){e.preventDefault(),I(),v.focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;if(!v.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())};r?(z(),v.hidden=!1,_.hidden=!1,B(`open`),O=!0,u&&p(u,`expanded`,!0)):(v.hidden=!0,_.hidden=!0,B(`closed`)),u&&A.push(h(u,`click`,()=>H(!O))),A.push(h(v,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&v.contains(n)&&H(!1)})),a&&A.push(h(_,`pointerdown`,e=>{e.target===_&&O&&H(!1)}));let W={open:()=>H(!0),close:()=>H(!1),toggle:()=>H(!O),get isOpen(){return O},destroy:()=>{if(O)H(!1,!0);else{let e=C.indexOf(W);e!==-1&&(C.splice(e,1),T(),D())}L(),A.forEach(e=>e()),A.length=0,d&&N&&(j&&document.contains(j)?j.insertBefore(d,M):d.remove(),N=!1)},_handleKeydown:U,_closeOnEscape:o,_content:v,_overlay:_};return A.push(h(t,`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`&&H(n)})),r&&(k=document.activeElement,C.push(W),E(),T(),s&&!P&&(b(),P=!0),g(t,`dialog:change`,{open:!0}),i?.(!0),requestAnimationFrame(R)),W}const k=new WeakSet;function A(e=document){let n=[];for(let r of t(e,`dialog`)){if(k.has(r))continue;k.add(r),n.push(O(r))}return n}export{A as create,O as createDialog};
1
+ import{createPortalLifecycle as e,emit as t,ensureId as n,getDataBool as r,getPart as i,getRoots as a,linkLabelledBy as o,lockScroll as s,on as c,setAria as l,unlockScroll as u}from"@data-slot/core";const d=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,f=[];let p=null;function m(){let e=1e3;f.forEach((t,n)=>{let r=e+n*10;t._overlay&&(t._overlay.style.zIndex=String(r)),t._content&&(t._content.style.zIndex=String(r+1))})}function h(){if(p)return;let e=e=>{if(f.length===0)return;let t=f[f.length-1];if(!(!t||!t.isOpen)){if(e.key===`Escape`&&t._closeOnEscape){e.preventDefault(),t.close();return}e.key===`Tab`&&t._handleKeydown&&t._handleKeydown(e)}},t=c(document,`keydown`,e);p=()=>{t(),p=null}}function g(){f.length===0&&p&&p()}function _(a,p={}){let _=p.defaultOpen??r(a,`defaultOpen`)??!1,v=p.onOpenChange,y=p.closeOnClickOutside??r(a,`closeOnClickOutside`)??!0,b=p.closeOnEscape??r(a,`closeOnEscape`)??!0,x=p.lockScroll??r(a,`lockScroll`)??!0,S=p.alertDialog??r(a,`alertDialog`)??!1,C=i(a,`dialog-trigger`),w=i(a,`dialog-portal`),T=i(a,`dialog-overlay`),E=i(a,`dialog-content`),D=i(a,`dialog-title`),O=i(a,`dialog-description`);if(!E)throw Error(`Dialog requires dialog-content slot`);if(!T)throw Error(`Dialog requires dialog-overlay slot`);let k=!1,A=null,j=[],M=w?e({content:w,root:a}):null,N=!1;n(E,`dialog-content`),E.setAttribute(`role`,S?`alertdialog`:`dialog`),l(E,`modal`,!0),o(E,D,O),T.setAttribute(`role`,`presentation`),T.setAttribute(`aria-hidden`,`true`),T.tabIndex=-1,C&&(C.setAttribute(`aria-haspopup`,`dialog`),C.setAttribute(`aria-controls`,E.id),l(C,`expanded`,!1));let P=!1,F=()=>{E.hasAttribute(`tabindex`)||(E.tabIndex=-1,P=!0)},I=()=>{P&&(E.removeAttribute(`tabindex`),P=!1)},L=()=>{let e=E.querySelector(`[autofocus]`);if(e)return e.focus();let t=E.querySelector(d);if(t)return t.focus();F(),E.focus()},R=()=>{M?.mount()},z=e=>{a.setAttribute(`data-state`,e),w&&w.setAttribute(`data-state`,e),T.setAttribute(`data-state`,e),E.setAttribute(`data-state`,e)},B=()=>{T.style.zIndex=``,E.style.zIndex=``},V=(e,n=!1)=>{if(!(k===e&&!n)){if(e)R(),A=document.activeElement,f.push(U),h(),m(),x&&!N&&(s(),N=!0);else{let e=f.indexOf(U);e!==-1&&f.splice(e,1),g(),B(),m(),N&&(u(),N=!1),I();let t=A;A=null,requestAnimationFrame(()=>{t&&document.contains(t)&&typeof t.focus==`function`?t.focus():C&&document.contains(C)&&C.focus()})}k=e,E.hidden=!k,T.hidden=!k,C&&l(C,`expanded`,k),z(k?`open`:`closed`),t(a,`dialog:change`,{open:k}),v?.(k),e&&requestAnimationFrame(L)}},H=e=>{if(e.key!==`Tab`)return;let t=E.querySelectorAll(d);if(t.length===0){e.preventDefault(),F(),E.focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;if(!E.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())};_?(R(),E.hidden=!1,T.hidden=!1,z(`open`),k=!0,C&&l(C,`expanded`,!0)):(E.hidden=!0,T.hidden=!0,z(`closed`)),C&&j.push(c(C,`click`,()=>V(!k))),j.push(c(E,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&E.contains(n)&&V(!1)})),y&&j.push(c(T,`pointerdown`,e=>{e.target===T&&k&&V(!1)}));let U={open:()=>V(!0),close:()=>V(!1),toggle:()=>V(!k),get isOpen(){return k},destroy:()=>{if(k)V(!1,!0);else{let e=f.indexOf(U);e!==-1&&(f.splice(e,1),m(),g())}I(),j.forEach(e=>e()),j.length=0,M?.cleanup()},_handleKeydown:H,_closeOnEscape:b,_content:E,_overlay:T};return j.push(c(a,`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`&&V(n)})),_&&(A=document.activeElement,f.push(U),h(),m(),x&&!N&&(s(),N=!0),t(a,`dialog:change`,{open:!0}),v?.(!0),requestAnimationFrame(L)),U}const v=new WeakSet;function y(e=document){let t=[];for(let n of a(e,`dialog`)){if(v.has(n))continue;v.add(n),t.push(_(n))}return t}export{y as create,_ as createDialog};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/dialog",
3
- "version": "0.2.29",
3
+ "version": "0.2.31",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",
@@ -24,9 +24,6 @@
24
24
  "scripts": {
25
25
  "build": "tsdown"
26
26
  },
27
- "devDependencies": {
28
- "@data-slot/core": "workspace:*"
29
- },
30
27
  "repository": {
31
28
  "type": "git",
32
29
  "url": "https://github.com/bejamas/data-slot",
@@ -40,5 +37,8 @@
40
37
  "vanilla",
41
38
  "data-slot"
42
39
  ],
43
- "license": "MIT"
40
+ "license": "MIT",
41
+ "dependencies": {
42
+ "@data-slot/core": "workspace:*"
43
+ }
44
44
  }