@data-slot/popover 0.2.28 → 0.2.29

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