@data-slot/popover 0.2.123 → 0.2.125
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=[`top`,`right`,`bottom`,`left`],n=[`start`,`center`,`end`]
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=[`top`,`right`,`bottom`,`left`],n=[`start`,`center`,`end`],r=`@data-slot/popover`;function i(i,a={}){let o=(0,e.reuseRootBinding)(i,r,`[@data-slot/popover] createPopover() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(o)return o;let s=(0,e.getPart)(i,`popover-trigger`),c=(0,e.getPart)(i,`popover-content`),l=(0,e.getPart)(i,`popover-close`),u=(0,e.getPart)(i,`popover-positioner`),d=u&&c&&u.contains(c)?u:null,f=(0,e.getPart)(i,`popover-portal`),p=f&&d&&f.contains(d)?f:null;if(!s||!c)throw Error(`Popover requires trigger and content slots`);let m=a.defaultOpen??(0,e.getDataBool)(i,`defaultOpen`)??!1,h=a.onOpenChange,g=a.closeOnClickOutside??(0,e.getDataBool)(i,`closeOnClickOutside`)??!0,_=a.closeOnEscape??(0,e.getDataBool)(i,`closeOnEscape`)??!0,v=a.portal??(0,e.getDataBool)(c,`portal`)??(0,e.getDataBool)(i,`portal`)??!0,y=(t,n)=>(0,e.getDataEnum)(c,t,n)??(d?(0,e.getDataEnum)(d,t,n):void 0)??(0,e.getDataEnum)(i,t,n),b=t=>(0,e.getDataNumber)(c,t)??(d?(0,e.getDataNumber)(d,t):void 0)??(0,e.getDataNumber)(i,t),x=t=>(0,e.getDataBool)(c,t)??(d?(0,e.getDataBool)(d,t):void 0)??(0,e.getDataBool)(i,t),S=a.position??y(`position`,t),C=a.side??y(`side`,t)??S??`bottom`,w=a.align??y(`align`,n)??`center`,T=a.sideOffset??b(`sideOffset`)??4,E=a.alignOffset??b(`alignOffset`)??0,D=a.avoidCollisions??x(`avoidCollisions`)??!0,O=a.collisionPadding??b(`collisionPadding`)??8,k=m,A=[],j=(0,e.createPortalLifecycle)({content:c,root:i,enabled:v,wrapperSlot:d?void 0:`popover-positioner`,container:d??void 0,mountTarget:d?p??d:void 0}),M=!1,N=null,P=!1,F=()=>{P&&=(c.removeAttribute(`tabindex`),!1)},I=()=>{let e=c.querySelector(`[autofocus]`);if(e)return e.focus();let t=c.querySelector(`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`);if(t)return t.focus();c.getAttribute(`tabindex`)||(c.setAttribute(`tabindex`,`-1`),P=!0),c.focus()},L=(0,e.ensureId)(c,`popover-content`);s.setAttribute(`aria-haspopup`,`dialog`),s.setAttribute(`aria-controls`,L),c.setAttribute(`data-side`,C),c.setAttribute(`data-align`,w),c.setAttribute(`data-position`,C);let R=()=>{let t=j.container,n=i.ownerDocument.defaultView??window,r=s.getBoundingClientRect(),a=(0,e.computeFloatingPosition)({anchorRect:r,contentRect:(0,e.measurePopupContentRect)(c),side:C,align:w,sideOffset:T,alignOffset:E,avoidCollisions:D,collisionPadding:O}),o=(0,e.computeFloatingTransformOrigin)({side:a.side,align:a.align,anchorRect:r,popupX:a.x,popupY:a.y});t.style.position=`absolute`,t.style.top=`0px`,t.style.left=`0px`,t.style.transform=`translate3d(${a.x+n.scrollX}px, ${a.y+n.scrollY}px, 0)`,t.style.setProperty(`--transform-origin`,o),t.style.willChange=`transform`,t.style.margin=`0`,c.setAttribute(`data-side`,a.side),c.setAttribute(`data-align`,a.align),t!==c&&(t.setAttribute(`data-side`,a.side),t.setAttribute(`data-align`,a.align)),c.setAttribute(`data-position`,a.side)},z=e=>{let t=j.container;i.setAttribute(`data-state`,e),c.setAttribute(`data-state`,e),t!==c&&t.setAttribute(`data-state`,e),e===`open`?(i.setAttribute(`data-open`,``),c.setAttribute(`data-open`,``),t!==c&&t.setAttribute(`data-open`,``),i.removeAttribute(`data-closed`),c.removeAttribute(`data-closed`),t!==c&&t.removeAttribute(`data-closed`)):(i.setAttribute(`data-closed`,``),c.setAttribute(`data-closed`,``),t!==c&&t.setAttribute(`data-closed`,``),i.removeAttribute(`data-open`),c.removeAttribute(`data-open`),t!==c&&t.removeAttribute(`data-open`))},B=()=>{requestAnimationFrame(()=>{N&&N.isConnected?(0,e.focusElement)(N):(0,e.focusElement)(s),N=null})},V=(0,e.createPresenceLifecycle)({element:c,onExitComplete:()=>{M||(j.restore(),c.hidden=!0,F(),B())}}),H=(0,e.createPositionSync)({observedElements:[s,c],isActive:()=>k,ancestorScroll:!1,onUpdate:R}),U=t=>{k!==t&&(t&&(N=document.activeElement),k=t,(0,e.setAria)(s,`expanded`,k),t?(j.mount(),c.hidden=!1,z(`open`),V.enter(),R(),H.start(),H.update(),requestAnimationFrame(I)):(z(`closed`),V.exit(),H.stop()),(0,e.emit)(i,`popover:change`,{open:k}),h?.(k))};(0,e.setAria)(s,`expanded`,k),z(k?`open`:`closed`),c.hidden=!k,m&&(j.mount(),V.enter(),c.hidden=!1,R(),H.start(),H.update(),requestAnimationFrame(I)),A.push((0,e.on)(s,`click`,()=>U(!k))),l&&A.push((0,e.on)(l,`click`,()=>U(!1))),A.push((0,e.createDismissLayer)({root:i,isOpen:()=>k,onDismiss:()=>U(!1),closeOnClickOutside:g,closeOnEscape:_})),A.push((0,e.on)(i,`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`&&U(n)}));let W={open:()=>U(!0),close:()=>U(!1),toggle:()=>U(!k),get isOpen(){return k},destroy:()=>{M=!0,H.stop(),V.cleanup(),j.cleanup(),A.forEach(e=>e()),A.length=0,F(),(0,e.clearRootBinding)(i,r,W)}};return(0,e.setRootBinding)(i,r,W),W}function a(t=document){let n=[];for(let a of(0,e.getRoots)(t,`popover`))(0,e.hasRootBinding)(a,r)||n.push(i(a));return n}exports.create=a,exports.createPopover=i;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{clearRootBinding as e,computeFloatingPosition as t,computeFloatingTransformOrigin as n,createDismissLayer as r,createPortalLifecycle as i,createPositionSync as a,createPresenceLifecycle as o,emit as s,ensureId as c,focusElement as l,getDataBool as u,getDataEnum as d,getDataNumber as f,getPart as p,getRoots as m,hasRootBinding as h,measurePopupContentRect as ee,on as g,reuseRootBinding as te,setAria as _,setRootBinding as ne}from"@data-slot/core";const v=[`top`,`right`,`bottom`,`left`],y=[`start`,`center`,`end`],b=`@data-slot/popover`;function x(m,h={}){let x=te(m,b,`[@data-slot/popover] createPopover() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(x)return x;let S=p(m,`popover-trigger`),C=p(m,`popover-content`),w=p(m,`popover-close`),T=p(m,`popover-positioner`),E=T&&C&&T.contains(C)?T:null,D=p(m,`popover-portal`),re=D&&E&&D.contains(E)?D:null;if(!S||!C)throw Error(`Popover requires trigger and content slots`);let O=h.defaultOpen??u(m,`defaultOpen`)??!1,ie=h.onOpenChange,k=h.closeOnClickOutside??u(m,`closeOnClickOutside`)??!0,A=h.closeOnEscape??u(m,`closeOnEscape`)??!0,j=h.portal??u(C,`portal`)??u(m,`portal`)??!0,M=(e,t)=>d(C,e,t)??(E?d(E,e,t):void 0)??d(m,e,t),N=e=>f(C,e)??(E?f(E,e):void 0)??f(m,e),P=e=>u(C,e)??(E?u(E,e):void 0)??u(m,e),F=h.position??M(`position`,v),I=h.side??M(`side`,v)??F??`bottom`,L=h.align??M(`align`,y)??`center`,R=h.sideOffset??N(`sideOffset`)??4,z=h.alignOffset??N(`alignOffset`)??0,ae=h.avoidCollisions??P(`avoidCollisions`)??!0,oe=h.collisionPadding??N(`collisionPadding`)??8,B=O,V=[],H=i({content:C,root:m,enabled:j,wrapperSlot:E?void 0:`popover-positioner`,container:E??void 0,mountTarget:E?re??E:void 0}),U=!1,W=null,G=!1,K=()=>{G&&=(C.removeAttribute(`tabindex`),!1)},q=()=>{let e=C.querySelector(`[autofocus]`);if(e)return e.focus();let t=C.querySelector(`a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])`);if(t)return t.focus();C.getAttribute(`tabindex`)||(C.setAttribute(`tabindex`,`-1`),G=!0),C.focus()},se=c(C,`popover-content`);S.setAttribute(`aria-haspopup`,`dialog`),S.setAttribute(`aria-controls`,se),C.setAttribute(`data-side`,I),C.setAttribute(`data-align`,L),C.setAttribute(`data-position`,I);let J=()=>{let e=H.container,r=m.ownerDocument.defaultView??window,i=S.getBoundingClientRect(),a=t({anchorRect:i,contentRect:ee(C),side:I,align:L,sideOffset:R,alignOffset:z,avoidCollisions:ae,collisionPadding:oe}),o=n({side:a.side,align:a.align,anchorRect:i,popupX:a.x,popupY:a.y});e.style.position=`absolute`,e.style.top=`0px`,e.style.left=`0px`,e.style.transform=`translate3d(${a.x+r.scrollX}px, ${a.y+r.scrollY}px, 0)`,e.style.setProperty(`--transform-origin`,o),e.style.willChange=`transform`,e.style.margin=`0`,C.setAttribute(`data-side`,a.side),C.setAttribute(`data-align`,a.align),e!==C&&(e.setAttribute(`data-side`,a.side),e.setAttribute(`data-align`,a.align)),C.setAttribute(`data-position`,a.side)},Y=e=>{let t=H.container;m.setAttribute(`data-state`,e),C.setAttribute(`data-state`,e),t!==C&&t.setAttribute(`data-state`,e),e===`open`?(m.setAttribute(`data-open`,``),C.setAttribute(`data-open`,``),t!==C&&t.setAttribute(`data-open`,``),m.removeAttribute(`data-closed`),C.removeAttribute(`data-closed`),t!==C&&t.removeAttribute(`data-closed`)):(m.setAttribute(`data-closed`,``),C.setAttribute(`data-closed`,``),t!==C&&t.setAttribute(`data-closed`,``),m.removeAttribute(`data-open`),C.removeAttribute(`data-open`),t!==C&&t.removeAttribute(`data-open`))},ce=()=>{requestAnimationFrame(()=>{W&&W.isConnected?l(W):l(S),W=null})},X=o({element:C,onExitComplete:()=>{U||(H.restore(),C.hidden=!0,K(),ce())}}),Z=a({observedElements:[S,C],isActive:()=>B,ancestorScroll:!1,onUpdate:J}),Q=e=>{B!==e&&(e&&(W=document.activeElement),B=e,_(S,`expanded`,B),e?(H.mount(),C.hidden=!1,Y(`open`),X.enter(),J(),Z.start(),Z.update(),requestAnimationFrame(q)):(Y(`closed`),X.exit(),Z.stop()),s(m,`popover:change`,{open:B}),ie?.(B))};_(S,`expanded`,B),Y(B?`open`:`closed`),C.hidden=!B,O&&(H.mount(),X.enter(),C.hidden=!1,J(),Z.start(),Z.update(),requestAnimationFrame(q)),V.push(g(S,`click`,()=>Q(!B))),w&&V.push(g(w,`click`,()=>Q(!1))),V.push(r({root:m,isOpen:()=>B,onDismiss:()=>Q(!1),closeOnClickOutside:k,closeOnEscape:A})),V.push(g(m,`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`&&Q(n)}));let $={open:()=>Q(!0),close:()=>Q(!1),toggle:()=>Q(!B),get isOpen(){return B},destroy:()=>{U=!0,Z.stop(),X.cleanup(),H.cleanup(),V.forEach(e=>e()),V.length=0,K(),e(m,b,$)}};return ne(m,b,$),$}function S(e=document){let t=[];for(let n of m(e,`popover`))h(n,b)||t.push(x(n));return t}export{S 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.
|
|
3
|
+
"version": "0.2.125",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
],
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@data-slot/core": "0.2.
|
|
37
|
+
"@data-slot/core": "0.2.125"
|
|
38
38
|
}
|
|
39
39
|
}
|