@data-slot/popover 0.2.27 → 0.2.28

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.`)}function u(e,t,n){let i=a(e,t);if(i!==null){if(n.includes(i))return i;r(e,t,`Invalid value "${i}" for data-${t}. Expected one of: ${n.join(`, `)}.`)}}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))};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})),g=[`top`,`bottom`,`left`,`right`],_=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function v(t,n={}){let r=e(t,`popover-trigger`),i=e(t,`popover-content`),a=e(t,`popover-close`);if(!r||!i)throw Error(`Popover requires trigger and content slots`);let o=n.defaultOpen??l(t,`defaultOpen`)??!1,s=n.onOpenChange,c=n.closeOnClickOutside??l(t,`closeOnClickOutside`)??!0,d=n.closeOnEscape??l(t,`closeOnEscape`)??!0,v=n.position??u(i,`position`,g)??u(t,`position`,g)??`bottom`,y=o,b=[],x=null,S=!1,C=()=>{S&&(i.removeAttribute(`tabindex`),S=!1)},w=()=>{let e=i.querySelector(`[autofocus]`);if(e)return e.focus();let t=i.querySelector(_);if(t)return t.focus();i.getAttribute(`tabindex`)||(i.setAttribute(`tabindex`,`-1`),S=!0),i.focus()},T=f(i,`popover-content`);r.setAttribute(`aria-haspopup`,`dialog`),r.setAttribute(`aria-controls`,T),i.setAttribute(`data-position`,v);let E=e=>{y!==e&&(e&&(x=document.activeElement),y=e,p(r,`expanded`,y),i.hidden=!y,t.setAttribute(`data-state`,y?`open`:`closed`),i.setAttribute(`data-state`,y?`open`:`closed`),h(t,`popover:change`,{open:y}),s?.(y),e?requestAnimationFrame(w):(C(),requestAnimationFrame(()=>{x&&x.isConnected?x.focus():r.focus(),x=null})))};p(r,`expanded`,y),i.hidden=!y,t.setAttribute(`data-state`,y?`open`:`closed`),i.setAttribute(`data-state`,y?`open`:`closed`),o&&requestAnimationFrame(w),b.push(m(r,`click`,()=>E(!y))),a&&b.push(m(a,`click`,()=>E(!1))),c&&b.push(m(document,`pointerdown`,e=>{if(!y)return;let n=e.target;t.contains(n)||E(!1)})),d&&b.push(m(document,`keydown`,e=>{y&&e.key===`Escape`&&(e.preventDefault(),E(!1))})),b.push(m(t,`popover:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&E(n)}));let D={open:()=>E(!0),close:()=>E(!1),toggle:()=>E(!y),get isOpen(){return y},destroy:()=>{b.forEach(e=>e()),b.length=0,C()}};return D}const y=new WeakSet;function b(e=document){let n=[];for(let r of t(e,`popover`)){if(y.has(r))continue;y.add(r),n.push(v(r))}return n}exports.create=b,exports.createPopover=v;
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.`)}function u(e,t,n){let i=a(e,t);if(i!==null){if(n.includes(i))return i;r(e,t,`Invalid value "${i}" for data-${t}. Expected one of: ${n.join(`, `)}.`)}}const d=new WeakMap;function f(e,t){return p(e,t,new Set)}function p(e,t,n){if(!t)return!1;let r=t instanceof Element?t:t.parentElement;if(!r)return!1;if(e.contains(r))return!0;let i=r;for(;i;){let t=d.get(i);if(t&&!n.has(t)&&(n.add(t),p(e,t,n)))return!0;i=i.parentElement}return!1}let m=0;const h=(e,t)=>e.id||=`${t}-${++m}`,g=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))};function _(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const v=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n})),y=[`top`,`bottom`,`left`,`right`],b=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function x(t,n={}){let r=e(t,`popover-trigger`),i=e(t,`popover-content`),a=e(t,`popover-close`);if(!r||!i)throw Error(`Popover requires trigger and content slots`);let o=n.defaultOpen??l(t,`defaultOpen`)??!1,s=n.onOpenChange,c=n.closeOnClickOutside??l(t,`closeOnClickOutside`)??!0,d=n.closeOnEscape??l(t,`closeOnEscape`)??!0,p=n.position??u(i,`position`,y)??u(t,`position`,y)??`bottom`,m=o,x=[],S=null,C=!1,w=()=>{C&&(i.removeAttribute(`tabindex`),C=!1)},T=()=>{let e=i.querySelector(`[autofocus]`);if(e)return e.focus();let t=i.querySelector(b);if(t)return t.focus();i.getAttribute(`tabindex`)||(i.setAttribute(`tabindex`,`-1`),C=!0),i.focus()},E=h(i,`popover-content`);r.setAttribute(`aria-haspopup`,`dialog`),r.setAttribute(`aria-controls`,E),i.setAttribute(`data-position`,p);let D=e=>{m!==e&&(e&&(S=document.activeElement),m=e,g(r,`expanded`,m),i.hidden=!m,t.setAttribute(`data-state`,m?`open`:`closed`),i.setAttribute(`data-state`,m?`open`:`closed`),v(t,`popover:change`,{open:m}),s?.(m),e?requestAnimationFrame(T):(w(),requestAnimationFrame(()=>{S&&S.isConnected?S.focus():r.focus(),S=null})))};g(r,`expanded`,m),i.hidden=!m,t.setAttribute(`data-state`,m?`open`:`closed`),i.setAttribute(`data-state`,m?`open`:`closed`),o&&requestAnimationFrame(T),x.push(_(r,`click`,()=>D(!m))),a&&x.push(_(a,`click`,()=>D(!1))),c&&x.push(_(document,`pointerdown`,e=>{if(!m)return;let n=e.target;f(t,n)||D(!1)})),d&&x.push(_(document,`keydown`,e=>{m&&e.key===`Escape`&&(e.preventDefault(),D(!1))})),x.push(_(t,`popover:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&D(n)}));let O={open:()=>D(!0),close:()=>D(!1),toggle:()=>D(!m),get isOpen(){return m},destroy:()=>{x.forEach(e=>e()),x.length=0,w()}};return O}const S=new WeakSet;function C(e=document){let n=[];for(let r of t(e,`popover`)){if(S.has(r))continue;S.add(r),n.push(x(r))}return n}exports.create=C,exports.createPopover=x;
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.`)}function u(e,t,n){let i=a(e,t);if(i!==null){if(n.includes(i))return i;r(e,t,`Invalid value "${i}" for data-${t}. Expected one of: ${n.join(`, `)}.`)}}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))};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})),g=[`top`,`bottom`,`left`,`right`],_=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function v(t,n={}){let r=e(t,`popover-trigger`),i=e(t,`popover-content`),a=e(t,`popover-close`);if(!r||!i)throw Error(`Popover requires trigger and content slots`);let o=n.defaultOpen??l(t,`defaultOpen`)??!1,s=n.onOpenChange,c=n.closeOnClickOutside??l(t,`closeOnClickOutside`)??!0,d=n.closeOnEscape??l(t,`closeOnEscape`)??!0,v=n.position??u(i,`position`,g)??u(t,`position`,g)??`bottom`,y=o,b=[],x=null,S=!1,C=()=>{S&&(i.removeAttribute(`tabindex`),S=!1)},w=()=>{let e=i.querySelector(`[autofocus]`);if(e)return e.focus();let t=i.querySelector(_);if(t)return t.focus();i.getAttribute(`tabindex`)||(i.setAttribute(`tabindex`,`-1`),S=!0),i.focus()},T=f(i,`popover-content`);r.setAttribute(`aria-haspopup`,`dialog`),r.setAttribute(`aria-controls`,T),i.setAttribute(`data-position`,v);let E=e=>{y!==e&&(e&&(x=document.activeElement),y=e,p(r,`expanded`,y),i.hidden=!y,t.setAttribute(`data-state`,y?`open`:`closed`),i.setAttribute(`data-state`,y?`open`:`closed`),h(t,`popover:change`,{open:y}),s?.(y),e?requestAnimationFrame(w):(C(),requestAnimationFrame(()=>{x&&x.isConnected?x.focus():r.focus(),x=null})))};p(r,`expanded`,y),i.hidden=!y,t.setAttribute(`data-state`,y?`open`:`closed`),i.setAttribute(`data-state`,y?`open`:`closed`),o&&requestAnimationFrame(w),b.push(m(r,`click`,()=>E(!y))),a&&b.push(m(a,`click`,()=>E(!1))),c&&b.push(m(document,`pointerdown`,e=>{if(!y)return;let n=e.target;t.contains(n)||E(!1)})),d&&b.push(m(document,`keydown`,e=>{y&&e.key===`Escape`&&(e.preventDefault(),E(!1))})),b.push(m(t,`popover:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&E(n)}));let D={open:()=>E(!0),close:()=>E(!1),toggle:()=>E(!y),get isOpen(){return y},destroy:()=>{b.forEach(e=>e()),b.length=0,C()}};return D}const y=new WeakSet;function b(e=document){let n=[];for(let r of t(e,`popover`)){if(y.has(r))continue;y.add(r),n.push(v(r))}return n}export{b as create,v as createPopover};
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.`)}function u(e,t,n){let i=a(e,t);if(i!==null){if(n.includes(i))return i;r(e,t,`Invalid value "${i}" for data-${t}. Expected one of: ${n.join(`, `)}.`)}}const d=new WeakMap;function f(e,t){return p(e,t,new Set)}function p(e,t,n){if(!t)return!1;let r=t instanceof Element?t:t.parentElement;if(!r)return!1;if(e.contains(r))return!0;let i=r;for(;i;){let t=d.get(i);if(t&&!n.has(t)&&(n.add(t),p(e,t,n)))return!0;i=i.parentElement}return!1}let m=0;const h=(e,t)=>e.id||=`${t}-${++m}`,g=(e,t,n)=>{n===null?e.removeAttribute(`aria-${t}`):e.setAttribute(`aria-${t}`,String(n))};function _(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}const v=(e,t,n)=>e.dispatchEvent(new CustomEvent(t,{bubbles:!0,detail:n})),y=[`top`,`bottom`,`left`,`right`],b=`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`;function x(t,n={}){let r=e(t,`popover-trigger`),i=e(t,`popover-content`),a=e(t,`popover-close`);if(!r||!i)throw Error(`Popover requires trigger and content slots`);let o=n.defaultOpen??l(t,`defaultOpen`)??!1,s=n.onOpenChange,c=n.closeOnClickOutside??l(t,`closeOnClickOutside`)??!0,d=n.closeOnEscape??l(t,`closeOnEscape`)??!0,p=n.position??u(i,`position`,y)??u(t,`position`,y)??`bottom`,m=o,x=[],S=null,C=!1,w=()=>{C&&(i.removeAttribute(`tabindex`),C=!1)},T=()=>{let e=i.querySelector(`[autofocus]`);if(e)return e.focus();let t=i.querySelector(b);if(t)return t.focus();i.getAttribute(`tabindex`)||(i.setAttribute(`tabindex`,`-1`),C=!0),i.focus()},E=h(i,`popover-content`);r.setAttribute(`aria-haspopup`,`dialog`),r.setAttribute(`aria-controls`,E),i.setAttribute(`data-position`,p);let D=e=>{m!==e&&(e&&(S=document.activeElement),m=e,g(r,`expanded`,m),i.hidden=!m,t.setAttribute(`data-state`,m?`open`:`closed`),i.setAttribute(`data-state`,m?`open`:`closed`),v(t,`popover:change`,{open:m}),s?.(m),e?requestAnimationFrame(T):(w(),requestAnimationFrame(()=>{S&&S.isConnected?S.focus():r.focus(),S=null})))};g(r,`expanded`,m),i.hidden=!m,t.setAttribute(`data-state`,m?`open`:`closed`),i.setAttribute(`data-state`,m?`open`:`closed`),o&&requestAnimationFrame(T),x.push(_(r,`click`,()=>D(!m))),a&&x.push(_(a,`click`,()=>D(!1))),c&&x.push(_(document,`pointerdown`,e=>{if(!m)return;let n=e.target;f(t,n)||D(!1)})),d&&x.push(_(document,`keydown`,e=>{m&&e.key===`Escape`&&(e.preventDefault(),D(!1))})),x.push(_(t,`popover:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&D(n)}));let O={open:()=>D(!0),close:()=>D(!1),toggle:()=>D(!m),get isOpen(){return m},destroy:()=>{x.forEach(e=>e()),x.length=0,w()}};return O}const S=new WeakSet;function C(e=document){let n=[];for(let r of t(e,`popover`)){if(S.has(r))continue;S.add(r),n.push(x(r))}return n}export{C as create,x as createPopover};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-slot/popover",
3
- "version": "0.2.27",
3
+ "version": "0.2.28",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.cjs",