@data-slot/dialog 0.1.1 → 0.1.3
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
|
-
|
|
1
|
+
const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)];let n=0;const r=(e,t)=>e.id||=`${t}-${++n}`,i=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},a=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,r(t,`title`)),n&&e.setAttribute(`aria-describedby`,r(n,`desc`))},o=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),s=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n})),c=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,l=[];let u=0,d=``,f=``;function p(t,n={}){let{defaultOpen:p=!1,onOpenChange:m,closeOnClickOutside:h=!0,closeOnEscape:g=!0,lockScroll:_=!0,alertDialog:v=!1}=n,y=e(t,`dialog-trigger`),b=e(t,`dialog-overlay`),x=e(t,`dialog-content`),S=e(t,`dialog-close`),C=e(t,`dialog-title`),w=e(t,`dialog-description`);if(!x)throw Error(`Dialog requires dialog-content slot`);if(!b)throw Error(`Dialog requires dialog-overlay slot`);let T=!1,E=null,D=[];r(x,`dialog-content`),x.setAttribute(`role`,v?`alertdialog`:`dialog`),i(x,`modal`,!0),a(x,C,w),b.setAttribute(`role`,`presentation`),b.setAttribute(`aria-hidden`,`true`),b.tabIndex=-1,y&&(y.setAttribute(`aria-haspopup`,`dialog`),y.setAttribute(`aria-controls`,x.id),i(y,`expanded`,!1));let O=!1,k=()=>{x.hasAttribute(`tabindex`)||(x.tabIndex=-1,O=!0)},A=()=>{O&&(x.removeAttribute(`tabindex`),O=!1)},j=()=>{let e=x.querySelector(`[autofocus]`);if(e)return e.focus();let t=x.querySelector(c);if(t)return t.focus();k(),x.focus()},M=(e,n=!1)=>{if(!(T===e&&!n)){if(e){if(E=document.activeElement,l.push(N),_){if(u===0){let e=window.innerWidth-document.documentElement.clientWidth;d=document.body.style.overflow,f=document.body.style.paddingRight,document.body.style.paddingRight=`${e}px`,document.body.style.overflow=`hidden`}u++}}else{let e=l.indexOf(N);e!==-1&&l.splice(e,1),_&&(u--,u===0&&(document.body.style.overflow=d,document.body.style.paddingRight=f)),A();let t=E;E=null,requestAnimationFrame(()=>{t&&document.contains(t)&&typeof t.focus==`function`&&t.focus()})}T=e,x.hidden=!T,b.hidden=!T,y&&i(y,`expanded`,T),t.setAttribute(`data-state`,T?`open`:`closed`),s(t,`dialog:change`,{open:T}),m?.(T),e&&requestAnimationFrame(j)}};p?(x.hidden=!1,b.hidden=!1,t.setAttribute(`data-state`,`open`),M(!0,!0)):(x.hidden=!0,b.hidden=!0,t.setAttribute(`data-state`,`closed`)),y&&D.push(o(y,`click`,()=>M(!T))),S&&D.push(o(S,`click`,()=>M(!1))),h&&D.push(o(b,`pointerdown`,e=>{e.target===b&&T&&M(!1)})),D.push(o(document,`keydown`,e=>{if(T){if(e.key===`Escape`&&g){let t=l[l.length-1];t===N&&(e.preventDefault(),M(!1));return}if(e.key===`Tab`){let t=x.querySelectorAll(c);if(t.length===0){e.preventDefault(),k(),x.focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;if(!x.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())}}}));let N={open:()=>M(!0),close:()=>M(!1),toggle:()=>M(!T),get isOpen(){return T},destroy:()=>{T&&M(!1,!0),A(),D.forEach(e=>e()),D.length=0}};return N}const m=new WeakSet;function h(e=document){let n=[];for(let r of t(e,`dialog`)){if(m.has(r))continue;m.add(r),n.push(p(r))}return n}exports.create=h,exports.createDialog=p;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=(e,t)=>e.querySelector(`[data-slot="${t}"]`),t=(e,t)=>[...e.querySelectorAll(`[data-slot="${t}"]`)];let n=0;const r=(e,t)=>e.id||=`${t}-${++n}`,i=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},a=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,r(t,`title`)),n&&e.setAttribute(`aria-describedby`,r(n,`desc`))},o=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),s=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n})),c=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,l=[];let u=0,d=``,f=``;function p(t,n={}){let{defaultOpen:p=!1,onOpenChange:m,closeOnClickOutside:h=!0,closeOnEscape:g=!0,lockScroll:_=!0,alertDialog:v=!1}=n,y=e(t,`dialog-trigger`),b=e(t,`dialog-overlay`),x=e(t,`dialog-content`),S=e(t,`dialog-close`),C=e(t,`dialog-title`),w=e(t,`dialog-description`);if(!x)throw Error(`Dialog requires dialog-content slot`);if(!b)throw Error(`Dialog requires dialog-overlay slot`);let T=!1,E=null,D=[];r(x,`dialog-content`),x.setAttribute(`role`,v?`alertdialog`:`dialog`),i(x,`modal`,!0),a(x,C,w),b.setAttribute(`role`,`presentation`),b.setAttribute(`aria-hidden`,`true`),b.tabIndex=-1,y&&(y.setAttribute(`aria-haspopup`,`dialog`),y.setAttribute(`aria-controls`,x.id),i(y,`expanded`,!1));let O=!1,k=()=>{x.hasAttribute(`tabindex`)||(x.tabIndex=-1,O=!0)},A=()=>{O&&(x.removeAttribute(`tabindex`),O=!1)},j=()=>{let e=x.querySelector(`[autofocus]`);if(e)return e.focus();let t=x.querySelector(c);if(t)return t.focus();k(),x.focus()},M=(e,n=!1)=>{if(!(T===e&&!n)){if(e){if(E=document.activeElement,l.push(N),_){if(u===0){let e=window.innerWidth-document.documentElement.clientWidth;d=document.body.style.overflow,f=document.body.style.paddingRight,document.body.style.paddingRight=`${e}px`,document.body.style.overflow=`hidden`}u++}}else{let e=l.indexOf(N);e!==-1&&l.splice(e,1),_&&(u--,u===0&&(document.body.style.overflow=d,document.body.style.paddingRight=f)),A();let t=E;E=null,requestAnimationFrame(()=>{t&&document.contains(t)&&typeof t.focus==`function`&&t.focus()})}T=e,x.hidden=!T,b.hidden=!T,y&&i(y,`expanded`,T),t.setAttribute(`data-state`,T?`open`:`closed`),s(t,`dialog:change`,{open:T}),m?.(T),e&&requestAnimationFrame(j)}};p?(x.hidden=!1,b.hidden=!1,t.setAttribute(`data-state`,`open`),M(!0,!0)):(x.hidden=!0,b.hidden=!0,t.setAttribute(`data-state`,`closed`)),y&&D.push(o(y,`click`,()=>M(!T))),S&&D.push(o(S,`click`,()=>M(!1))),h&&D.push(o(b,`pointerdown`,e=>{e.target===b&&T&&M(!1)})),D.push(o(document,`keydown`,e=>{if(T){if(e.key===`Escape`&&g){let t=l[l.length-1];t===N&&(e.preventDefault(),M(!1));return}if(e.key===`Tab`){let t=x.querySelectorAll(c);if(t.length===0){e.preventDefault(),k(),x.focus();return}let n=t[0],r=t[t.length-1],i=document.activeElement;if(!x.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())}}}));let N={open:()=>M(!0),close:()=>M(!1),toggle:()=>M(!T),get isOpen(){return T},destroy:()=>{T&&M(!1,!0),A(),D.forEach(e=>e()),D.length=0}};return N}const m=new WeakSet;function h(e=document){let n=[];for(let r of t(e,`dialog`)){if(m.has(r))continue;m.add(r),n.push(p(r))}return n}export{h as create,p as createDialog};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-slot/dialog",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsdown"
|
|
26
26
|
},
|
|
27
|
-
"
|
|
27
|
+
"devDependencies": {
|
|
28
28
|
"@data-slot/core": "workspace:*"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|