@data-slot/dialog 0.2.122 → 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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
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"])`,
|
|
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{
|
|
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.
|
|
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.
|
|
38
|
+
"@data-slot/core": "0.2.124"
|
|
39
39
|
}
|
|
40
40
|
}
|