@data-slot/dialog 0.2.24 → 0.2.26
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 +1 -1
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.`)}let u=0;const d=(e,t)=>e.id||=`${t}-${++u}`,f=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},p=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,d(t,`title`)),n&&e.setAttribute(`aria-describedby`,d(n,`desc`))};function m(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const h=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let g=0,_=``,v=``;function y(){if(g===0){let e=
|
|
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.`)}let u=0;const d=(e,t)=>e.id||=`${t}-${++u}`,f=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},p=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,d(t,`title`)),n&&e.setAttribute(`aria-describedby`,d(n,`desc`))};function m(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const h=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let g=0,_=``,v=``;function y(){if(g===0){let e=document.documentElement;_=e.style.overflow,v=e.style.scrollbarGutter,e.style.overflow=`hidden`,e.style.scrollbarGutter=`stable`}g++}function b(){if(g=Math.max(0,g-1),g===0){let e=document.documentElement;e.style.overflow=_,e.style.scrollbarGutter=v}}const x=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,S=[];let C=null;function w(){let e=1e3;S.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 T(){if(C)return;let e=e=>{if(S.length===0)return;let t=S[S.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=m(document,`keydown`,e);C=()=>{t(),C=null}}function E(){S.length===0&&C&&C()}function D(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`),g=e(t,`dialog-portal`),_=e(t,`dialog-overlay`),v=e(t,`dialog-content`),C=e(t,`dialog-title`),D=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;d(v,`dialog-content`),v.setAttribute(`role`,c?`alertdialog`:`dialog`),f(v,`modal`,!0),p(v,C,D),_.setAttribute(`role`,`presentation`),_.setAttribute(`aria-hidden`,`true`),_.tabIndex=-1,u&&(u.setAttribute(`aria-haspopup`,`dialog`),u.setAttribute(`aria-controls`,v.id),f(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(x);if(t)return t.focus();I(),v.focus()},z=()=>{g&&!N&&(j=g.parentNode,M=g.nextSibling,document.body.appendChild(g),N=!0)},B=e=>{t.setAttribute(`data-state`,e),g&&g.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,S.push(W),T(),w(),s&&!P&&(y(),P=!0);else{let e=S.indexOf(W);e!==-1&&S.splice(e,1),E(),V(),w(),P&&(b(),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&&f(u,`expanded`,O),B(O?`open`:`closed`),h(t,`dialog:change`,{open:O}),i?.(O),e&&requestAnimationFrame(R)}},U=e=>{if(e.key!==`Tab`)return;let t=v.querySelectorAll(x);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&&f(u,`expanded`,!0)):(v.hidden=!0,_.hidden=!0,B(`closed`)),u&&A.push(m(u,`click`,()=>H(!O))),A.push(m(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(m(_,`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=S.indexOf(W);e!==-1&&(S.splice(e,1),w(),E())}L(),A.forEach(e=>e()),A.length=0,g&&N&&(j&&document.contains(j)?j.insertBefore(g,M):g.remove(),N=!1)},_handleKeydown:U,_closeOnEscape:o,_content:v,_overlay:_};return A.push(m(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,S.push(W),T(),w(),s&&!P&&(y(),P=!0),h(t,`dialog:change`,{open:!0}),i?.(!0),requestAnimationFrame(R)),W}const O=new WeakSet;function k(e=document){let n=[];for(let r of t(e,`dialog`)){if(O.has(r))continue;O.add(r),n.push(D(r))}return n}exports.create=k,exports.createDialog=D;
|
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.`)}let u=0;const d=(e,t)=>e.id||=`${t}-${++u}`,f=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},p=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,d(t,`title`)),n&&e.setAttribute(`aria-describedby`,d(n,`desc`))};function m(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const h=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let g=0,_=``,v=``;function y(){if(g===0){let e=
|
|
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.`)}let u=0;const d=(e,t)=>e.id||=`${t}-${++u}`,f=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))},p=(e,t,n)=>{t&&e.setAttribute(`aria-labelledby`,d(t,`title`)),n&&e.setAttribute(`aria-describedby`,d(n,`desc`))};function m(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const h=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n}));let g=0,_=``,v=``;function y(){if(g===0){let e=document.documentElement;_=e.style.overflow,v=e.style.scrollbarGutter,e.style.overflow=`hidden`,e.style.scrollbarGutter=`stable`}g++}function b(){if(g=Math.max(0,g-1),g===0){let e=document.documentElement;e.style.overflow=_,e.style.scrollbarGutter=v}}const x=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`,S=[];let C=null;function w(){let e=1e3;S.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 T(){if(C)return;let e=e=>{if(S.length===0)return;let t=S[S.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=m(document,`keydown`,e);C=()=>{t(),C=null}}function E(){S.length===0&&C&&C()}function D(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`),g=e(t,`dialog-portal`),_=e(t,`dialog-overlay`),v=e(t,`dialog-content`),C=e(t,`dialog-title`),D=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;d(v,`dialog-content`),v.setAttribute(`role`,c?`alertdialog`:`dialog`),f(v,`modal`,!0),p(v,C,D),_.setAttribute(`role`,`presentation`),_.setAttribute(`aria-hidden`,`true`),_.tabIndex=-1,u&&(u.setAttribute(`aria-haspopup`,`dialog`),u.setAttribute(`aria-controls`,v.id),f(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(x);if(t)return t.focus();I(),v.focus()},z=()=>{g&&!N&&(j=g.parentNode,M=g.nextSibling,document.body.appendChild(g),N=!0)},B=e=>{t.setAttribute(`data-state`,e),g&&g.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,S.push(W),T(),w(),s&&!P&&(y(),P=!0);else{let e=S.indexOf(W);e!==-1&&S.splice(e,1),E(),V(),w(),P&&(b(),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&&f(u,`expanded`,O),B(O?`open`:`closed`),h(t,`dialog:change`,{open:O}),i?.(O),e&&requestAnimationFrame(R)}},U=e=>{if(e.key!==`Tab`)return;let t=v.querySelectorAll(x);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&&f(u,`expanded`,!0)):(v.hidden=!0,_.hidden=!0,B(`closed`)),u&&A.push(m(u,`click`,()=>H(!O))),A.push(m(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(m(_,`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=S.indexOf(W);e!==-1&&(S.splice(e,1),w(),E())}L(),A.forEach(e=>e()),A.length=0,g&&N&&(j&&document.contains(j)?j.insertBefore(g,M):g.remove(),N=!1)},_handleKeydown:U,_closeOnEscape:o,_content:v,_overlay:_};return A.push(m(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,S.push(W),T(),w(),s&&!P&&(y(),P=!0),h(t,`dialog:change`,{open:!0}),i?.(!0),requestAnimationFrame(R)),W}const O=new WeakSet;function k(e=document){let n=[];for(let r of t(e,`dialog`)){if(O.has(r))continue;O.add(r),n.push(D(r))}return n}export{k as create,D as createDialog};
|