Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/dialog

Package Overview
Dependencies
Maintainers
1
Versions
1017
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/dialog - npm Package Compare versions

Comparing version 0.0.0-dev-20220407084218 to 0.0.0-dev-20220408111010

2

dist/index.js

@@ -1,2 +0,2 @@

var ie=Object.create;var C=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var O=e=>C(e,"__esModule",{value:!0});var ce=(e,t)=>{for(var n in t)C(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of ae(t))!ue.call(e,l)&&(n||l!=="default")&&C(e,l,{get:()=>t[l],enumerable:!(r=le(t,l))||r.enumerable});return e},de=(e,t)=>F(O(C(e!=null?ie(se(e)):{},"default",!t&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),pe=(e=>(t,n)=>e&&e.get(t)||(n=F(O({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var Pe={};ce(Pe,{connect:()=>$,machine:()=>J,store:()=>v});var A=de(require("scroll-into-view-if-needed"),1);var R=e=>e?!0:void 0,N=new WeakMap;function fe(e){var t;if(!e)return{};let n=N.get(e);return n||(n=((t=e==null?void 0:e.ownerDocument.defaultView)!=null?t:window).getComputedStyle(e),N.set(e,n)),n}function L(e){let t=new Set;function n(r){let l=globalThis.requestAnimationFrame(r);t.add(()=>globalThis.cancelAnimationFrame(l))}return n(()=>n(e)),function(){t.forEach(function(r){r()})}}var B=()=>{},S=(...e)=>t=>e.reduce((n,r)=>r(n),t),xe=(()=>{let e=0;return()=>(e++,e.toString(36))})(),x=e=>V()&&e.test(navigator.platform),V=()=>typeof window!="undefined",ge=()=>x(/^Mac/),me=()=>x(/^iPhone/),ve=()=>x(/^iPad/)||ge()&&navigator.maxTouchPoints>1,he=()=>me()||ve();var w=new Map,f=new Map;function ye(e,t,n,r){var l;if(!e)return B;let o=JSON.stringify({type:t,options:r}),a=w.get(e);if(w.has(e))(a==null?void 0:a.has(o))?(l=a==null?void 0:a.get(o))==null||l.add(n):a==null||a.set(o,new Set([n]));else{let s=new Map([[o,new Set([n])]]);w.set(e,s)}function E(s){var h,y;function u(d){var b;let T=w.get(s);(b=T==null?void 0:T.get(o))==null||b.forEach(P=>P(d))}if(!(f==null?void 0:f.has(s))){f.set(s,new Map([[o,u]])),s.addEventListener(t,u,r);return}((h=f==null?void 0:f.get(s))==null?void 0:h.has(o))||((y=f.get(s))==null||y.set(o,u),s.addEventListener(t,u,r))}return E(e),function(){var s,h,y,u;if(!w.has(e))return;let d=w.get(e);if((s=d==null?void 0:d.get(o))==null||s.delete(n),((h=d==null?void 0:d.get(o))==null?void 0:h.size)===0){let b=(y=f.get(e))==null?void 0:y.get(o);e.removeEventListener(t,b,r),d==null||d.delete(o),(u=f.get(e))==null||u.delete(o),(d==null?void 0:d.size)===0&&(w.delete(e),f.delete(e))}}}var H=e=>Object.prototype.toString.call(e).slice(8,-1),we=e=>H(e)==="Object"&&"current"in e,be=e=>H(e)==="Function"?e():e;function g(e,t,n,r){let l=we(e)?e.current:be(e);return ye(l,t,n,r)}function K(e){var t;return U(e)?e.document:(t=e==null?void 0:e.ownerDocument)!=null?t:document}function _(e){return U(e)?"":e&&e.localName||""}function Ee(e){let t=K(e);return _(e)==="html"?e:e.assignedSlot||e.parentElement||t.documentElement}function ke(e){return typeof e=="object"&&(e==null?void 0:e.nodeType)===Node.ELEMENT_NODE&&typeof(e==null?void 0:e.nodeName)=="string"}function U(e){return(e==null?void 0:e.toString())==="[object Window]"}function Te(e){let{overflow:t,overflowX:n,overflowY:r}=fe(e);return/auto|scroll|overlay|hidden/.test(t+r+n)}function j(e){return["html","body","#document"].includes(_(e))?K(e).body:ke(e)&&Te(e)?e:j(Ee(e))}var q=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function z(e){var t;let{document:n,disabled:r=!1,allowPinchZoom:l}=e!=null?e:{},o=n!=null?n:document,a=(t=o==null?void 0:o.defaultView)!=null?t:window,E=V()?a.visualViewport:null,s=o.documentElement;function h(){let u=S(k(s,"paddingRight",`${a.innerWidth-s.clientWidth}px`),k(s,"overflow","hidden"));return()=>u==null?void 0:u()}function y(){let u,d=0,b=p=>{u=j(p.target),!(u===s&&u===o.body)&&(d=p.changedTouches[0].pageY)},T=p=>{if(p.touches.length===2&&l)return;if(!u||u===s||u===o.body){p.preventDefault();return}let c=p.changedTouches[0].pageY,D=u.scrollTop,re=u.scrollHeight-u.clientHeight;(D<=0&&c>d||D>=re&&c<d)&&p.preventDefault(),d=c},P=p=>{let c=p.target;c instanceof a.HTMLInputElement&&!q.has(c.type)&&(p.preventDefault(),c.style.transform="translateY(-2000px)",c.focus(),a.requestAnimationFrame(()=>{c.style.transform=""}))},Q=p=>{let c=p.target;c instanceof a.HTMLInputElement&&!q.has(c.type)&&(c.style.transform="translateY(-2000px)",a.requestAnimationFrame(()=>{c.style.transform="",!!E&&(E.height<a.innerHeight?a.requestAnimationFrame(function(){(0,A.default)(c,{scrollMode:"if-needed"})}):g(E,"resize",()=>{(0,A.default)(c,{scrollMode:"if-needed"})},{once:!0}))}))},ee=()=>{a.scrollTo(0,0)},te=a.scrollX,I=a.scrollY,ne=S(k(s,"paddingRight",`${a.innerWidth-s.clientWidth}px`),k(s,"overflow","hidden"),k(o.body,"marginTop",`-${I}px`));a.scrollTo(0,0);let oe=S(g(o,"touchstart",b,{passive:!1,capture:!0}),g(o,"touchmove",T,{passive:!1,capture:!0}),g(o,"touchend",P,{passive:!1,capture:!0}),g(o,"focus",Q,!0),g(a,"scroll",ee));return()=>{ne(),oe(),a.scrollTo(te,I)}}return r?B:he()?y():h()}function k(e,t,n){let r=e.style[t];return e.style[t]=n,()=>{e.style[t]=r}}var Ae=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");function W(e,t){var n;let r=(n=e.defaultView)!=null?n:window;return g(e,"pointerdown",l=>{l.target instanceof r.HTMLElement&&t(l.target)})}function Ce(e){return{button:e,label:e,input:e,output:e,element:e}}var Y=Ce(e=>e);var i={getDoc:e=>{var t;return(t=e.doc)!=null?t:document},getWin:e=>{var t;return(t=i.getDoc(e).defaultView)!=null?t:window},getUnderlayId:e=>`dialog-underlay-${e.uid}`,getBackdropId:e=>`dialog-backdrop-${e.uid}`,getContentId:e=>`dialog-content-${e.uid}`,getTriggerId:e=>`dialog-trigger-${e.uid}`,getTitleId:e=>`dialog-title-${e.uid}`,getDescriptionId:e=>`dialog-desc-${e.uid}`,getCloseButtonId:e=>`dialog-close-btn-${e.uid}`,getContentEl:e=>i.getDoc(e).getElementById(i.getContentId(e)),getUnderlayEl:e=>i.getDoc(e).getElementById(i.getUnderlayId(e)),getTitleEl:e=>i.getDoc(e).getElementById(i.getTitleId(e)),getDescriptionEl:e=>i.getDoc(e).getElementById(i.getDescriptionId(e))};function $(e,t,n=Y){let r=e.context["aria-label"],l=e.matches("open");return{isOpen:l,open(){t("OPEN")},close(){t("CLOSE")},triggerProps:n.button({"data-part":"trigger",id:i.getTriggerId(e.context),"aria-haspopup":"dialog",type:"button","aria-expanded":l,"aria-controls":i.getContentId(e.context),onClick(){t("TRIGGER_CLICK")}}),backdropProps:n.element({"data-part":"backdrop",id:i.getBackdropId(e.context)}),underlayProps:n.element({"data-part":"underlay",id:i.getUnderlayId(e.context),onPointerDown(o){o.target===o.currentTarget&&o.preventDefault()},onClick(o){t({type:"UNDERLAY_CLICK",target:o.currentTarget}),o.stopPropagation()}}),contentProps:n.element({"data-part":"content",role:e.context.role,id:i.getContentId(e.context),tabIndex:-1,"aria-modal":R(e.context.isTopMostDialog),"aria-label":r||void 0,"aria-labelledby":r||!e.context.isTitleRendered?void 0:i.getTitleId(e.context),"aria-describedby":e.context.isDescriptionRendered?i.getDescriptionId(e.context):void 0,onClick(o){o.stopPropagation()}}),titleProps:n.element({"data-part":"title",id:i.getTitleId(e.context)}),descriptionProps:n.element({"data-part":"description",id:i.getDescriptionId(e.context)}),closeButtonProps:n.button({"data-part":"close-button",id:i.getCloseButtonId(e.context),type:"button",onClick(o){o.stopPropagation(),t("CLOSE")}})}}var m=require("@zag-js/core");var M=(e,...t)=>{let n=typeof e=="function"?e(...t):e;return n!=null?n:void 0};var He=(()=>{let e=0;return()=>(e++,e.toString(36))})();var G=require("aria-hidden"),Z=require("focus-trap");var X=require("@zag-js/core"),v=(0,X.proxy)({value:[],isTopMost(e){let t=this.value[this.value.length-1];return(t==null?void 0:t.id)===e},add(e){this.value.push(e)},remove(e){let t=this.value.findIndex(n=>n.id===e);t<this.value.length-1?this.value.splice(t).forEach(n=>n.close()):this.value=this.value.filter(n=>n.id!==e)},closeAll(){this.value.forEach(e=>{e.close(),this.remove(e.id)})}});var{and:Le}=m.guards,J=(0,m.createMachine)({id:"dialog",initial:"unknown",context:{pointerdownNode:null,role:"dialog",isTitleRendered:!0,isDescriptionRendered:!0,uid:"234",trapFocus:!0,preventScroll:!0,isTopMostDialog:!0,closeOnOutsideClick:!0,closeOnEsc:!0,restoreFocus:!0},states:{unknown:{on:{SETUP:{target:"closed",actions:"setupDocument"}}},open:{entry:["checkRenderedElements"],activities:["trapFocus","preventScroll","hideContentBelow","subscribeToStore","trackEscKey","trackPointerDown"],on:{CLOSE:"closed",TRIGGER_CLICK:"closed",UNDERLAY_CLICK:{guard:Le("isTopMostDialog","closeOnOutsideClick","isValidUnderlayClick"),target:"closed",actions:["invokeOnOutsideClick"]}}},closed:{entry:["invokeOnClose","clearPointerdownNode"],on:{OPEN:"open",TRIGGER_CLICK:"open"}}}},{guards:{isTopMostDialog:e=>e.isTopMostDialog,closeOnOutsideClick:e=>e.closeOnOutsideClick,isValidUnderlayClick:(e,t)=>t.target===e.pointerdownNode},activities:{trackPointerDown(e,t){return W(i.getDoc(e),n=>{e.pointerdownNode=(0,m.ref)(n)})},trackEscKey(e,t,{send:n}){return g(i.getWin(e),"keydown",r=>{var l;e.closeOnEsc&&r.key==="Escape"&&e.isTopMostDialog&&((l=e.onEsc)==null||l.call(e),n("CLOSE"))})},preventScroll(e){return z({allowPinchZoom:!0,disabled:!e.preventScroll,document:i.getDoc(e)})},trapFocus(e){let t;return L(()=>{if(!e.isTopMostDialog||!e.trapFocus)return;let n=i.getContentEl(e);t=(0,Z.createFocusTrap)(n,{document:i.getDoc(e),escapeDeactivates:!1,fallbackFocus:i.getContentEl(e),allowOutsideClick:!0,returnFocusOnDeactivate:e.restoreFocus,initialFocus:M(e.initialFocusEl),setReturnFocus:M(e.finalFocusEl)});try{t.activate()}catch(r){}}),()=>t==null?void 0:t.deactivate()},subscribeToStore(e,t,{send:n}){let r={id:e.uid,close:()=>n("CLOSE")};v.add(r),e.isTopMostDialog=v.isTopMost(e.uid);let l=(0,m.subscribe)(v,()=>{e.isTopMostDialog=v.isTopMost(e.uid)});return()=>{l(),v.remove(e.uid)}},hideContentBelow(e){let t;return L(()=>{let n=i.getUnderlayEl(e);try{t=(0,G.hideOthers)(n)}catch(r){}}),()=>t==null?void 0:t()}},actions:{setupDocument(e,t){t.doc&&(e.doc=(0,m.ref)(t.doc)),e.uid=t.id},checkRenderedElements(e){L(()=>{e.isTitleRendered=!!i.getTitleEl(e),e.isDescriptionRendered=!!i.getDescriptionEl(e)})},invokeOnOutsideClick(e){var t;(t=e.onOutsideClick)==null||t.call(e)},invokeOnClose(e){var t;(t=e.onClose)==null||t.call(e)},clearPointerdownNode(e){e.pointerdownNode=null}}});module.exports=pe(Pe);
var ie=Object.create;var C=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var O=e=>C(e,"__esModule",{value:!0});var ce=(e,t)=>{for(var n in t)C(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of ae(t))!ue.call(e,l)&&(n||l!=="default")&&C(e,l,{get:()=>t[l],enumerable:!(r=le(t,l))||r.enumerable});return e},de=(e,t)=>F(O(C(e!=null?ie(se(e)):{},"default",!t&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),pe=(e=>(t,n)=>e&&e.get(t)||(n=F(O({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var Pe={};ce(Pe,{connect:()=>$,machine:()=>J,store:()=>v});var I=de(require("scroll-into-view-if-needed"),1);var R=e=>e?!0:void 0,N=new WeakMap;function fe(e){var t;if(!e)return{};let n=N.get(e);return n||(n=((t=e==null?void 0:e.ownerDocument.defaultView)!=null?t:window).getComputedStyle(e),N.set(e,n)),n}function L(e){let t=new Set;function n(r){let l=globalThis.requestAnimationFrame(r);t.add(()=>globalThis.cancelAnimationFrame(l))}return n(()=>n(e)),function(){t.forEach(function(r){r()})}}var H=()=>{},S=(...e)=>t=>e.reduce((n,r)=>r(n),t),xe=(()=>{let e=0;return()=>(e++,e.toString(36))})(),x=e=>V()&&e.test(navigator.platform),V=()=>typeof window!="undefined",ge=()=>x(/^Mac/),me=()=>x(/^iPhone/),ve=()=>x(/^iPad/)||ge()&&navigator.maxTouchPoints>1,he=()=>me()||ve();var b=new Map,f=new Map;function ye(e,t,n,r){var l;if(!e)return H;let o=JSON.stringify({type:t,options:r}),a=b.get(e);if(b.has(e))(a==null?void 0:a.has(o))?(l=a==null?void 0:a.get(o))==null||l.add(n):a==null||a.set(o,new Set([n]));else{let s=new Map([[o,new Set([n])]]);b.set(e,s)}function E(s){var h,y;function u(d){var w;let T=b.get(s);(w=T==null?void 0:T.get(o))==null||w.forEach(P=>P(d))}if(!(f==null?void 0:f.has(s))){f.set(s,new Map([[o,u]])),s.addEventListener(t,u,r);return}((h=f==null?void 0:f.get(s))==null?void 0:h.has(o))||((y=f.get(s))==null||y.set(o,u),s.addEventListener(t,u,r))}return E(e),function(){var s,h,y,u;if(!b.has(e))return;let d=b.get(e);if((s=d==null?void 0:d.get(o))==null||s.delete(n),((h=d==null?void 0:d.get(o))==null?void 0:h.size)===0){let w=(y=f.get(e))==null?void 0:y.get(o);e.removeEventListener(t,w,r),d==null||d.delete(o),(u=f.get(e))==null||u.delete(o),(d==null?void 0:d.size)===0&&(b.delete(e),f.delete(e))}}}var B=e=>Object.prototype.toString.call(e).slice(8,-1),be=e=>B(e)==="Object"&&"current"in e,we=e=>B(e)==="Function"?e():e;function g(e,t,n,r){let l=be(e)?e.current:we(e);return ye(l,t,n,r)}function _(e){var t;return U(e)?e.document:(t=e==null?void 0:e.ownerDocument)!=null?t:document}function K(e){return U(e)?"":e&&e.localName||""}function Ee(e){let t=_(e);return K(e)==="html"?e:e.assignedSlot||e.parentElement||t.documentElement}function ke(e){return typeof e=="object"&&(e==null?void 0:e.nodeType)===Node.ELEMENT_NODE&&typeof(e==null?void 0:e.nodeName)=="string"}function U(e){return(e==null?void 0:e.toString())==="[object Window]"}function Te(e){let{overflow:t,overflowX:n,overflowY:r}=fe(e);return/auto|scroll|overlay|hidden/.test(t+r+n)}function j(e){return["html","body","#document"].includes(K(e))?_(e).body:ke(e)&&Te(e)?e:j(Ee(e))}var q=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function W(e){var t;let{document:n,disabled:r=!1,allowPinchZoom:l}=e!=null?e:{},o=n!=null?n:document,a=(t=o==null?void 0:o.defaultView)!=null?t:window,E=V()?a.visualViewport:null,s=o.documentElement;function h(){let u=S(k(s,"paddingRight",`${a.innerWidth-s.clientWidth}px`),k(s,"overflow","hidden"));return()=>u==null?void 0:u()}function y(){let u,d=0,w=p=>{u=j(p.target),!(u===s&&u===o.body)&&(d=p.changedTouches[0].pageY)},T=p=>{if(p.touches.length===2&&l)return;if(!u||u===s||u===o.body){p.preventDefault();return}let c=p.changedTouches[0].pageY,D=u.scrollTop,re=u.scrollHeight-u.clientHeight;(D<=0&&c>d||D>=re&&c<d)&&p.preventDefault(),d=c},P=p=>{let c=p.target;c instanceof a.HTMLInputElement&&!q.has(c.type)&&(p.preventDefault(),c.style.transform="translateY(-2000px)",c.focus(),a.requestAnimationFrame(()=>{c.style.transform=""}))},Q=p=>{let c=p.target;c instanceof a.HTMLInputElement&&!q.has(c.type)&&(c.style.transform="translateY(-2000px)",a.requestAnimationFrame(()=>{c.style.transform="",!!E&&(E.height<a.innerHeight?a.requestAnimationFrame(function(){(0,I.default)(c,{scrollMode:"if-needed"})}):g(E,"resize",()=>{(0,I.default)(c,{scrollMode:"if-needed"})},{once:!0}))}))},ee=()=>{a.scrollTo(0,0)},te=a.scrollX,A=a.scrollY,ne=S(k(s,"paddingRight",`${a.innerWidth-s.clientWidth}px`),k(s,"overflow","hidden"),k(o.body,"marginTop",`-${A}px`));a.scrollTo(0,0);let oe=S(g(o,"touchstart",w,{passive:!1,capture:!0}),g(o,"touchmove",T,{passive:!1,capture:!0}),g(o,"touchend",P,{passive:!1,capture:!0}),g(o,"focus",Q,!0),g(a,"scroll",ee));return()=>{ne(),oe(),a.scrollTo(te,A)}}return r?H:he()?y():h()}function k(e,t,n){let r=e.style[t];return e.style[t]=n,()=>{e.style[t]=r}}var Ie=["input:not([disabled]):not([type=hidden])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","embed","iframe","object","a[href]","area[href]","[tabindex]","audio[controls]","video[controls]","*[tabindex]:not([aria-disabled])","[contenteditable]:not([contenteditable=false])","details > summary:first-of-type"].join(",");function z(e,t){var n;let r=(n=e.defaultView)!=null?n:window;return g(e,"pointerdown",l=>{l.target instanceof r.HTMLElement&&t(l.target)})}function Ce(e){return{button:e,label:e,input:e,output:e,element:e}}var Y=Ce(e=>e);var i={getDoc:e=>{var t;return(t=e.doc)!=null?t:document},getWin:e=>{var t;return(t=i.getDoc(e).defaultView)!=null?t:window},getUnderlayId:e=>`dialog-underlay-${e.uid}`,getBackdropId:e=>`dialog-backdrop-${e.uid}`,getContentId:e=>`dialog-content-${e.uid}`,getTriggerId:e=>`dialog-trigger-${e.uid}`,getTitleId:e=>`dialog-title-${e.uid}`,getDescriptionId:e=>`dialog-desc-${e.uid}`,getCloseButtonId:e=>`dialog-close-btn-${e.uid}`,getContentEl:e=>i.getDoc(e).getElementById(i.getContentId(e)),getUnderlayEl:e=>i.getDoc(e).getElementById(i.getUnderlayId(e)),getTitleEl:e=>i.getDoc(e).getElementById(i.getTitleId(e)),getDescriptionEl:e=>i.getDoc(e).getElementById(i.getDescriptionId(e))};function $(e,t,n=Y){let r=e.context["aria-label"],l=e.matches("open");return{isOpen:l,open(){t("OPEN")},close(){t("CLOSE")},triggerProps:n.button({"data-part":"trigger",id:i.getTriggerId(e.context),"aria-haspopup":"dialog",type:"button","aria-expanded":l,"aria-controls":i.getContentId(e.context),onClick(){t("TRIGGER_CLICK")}}),backdropProps:n.element({"data-part":"backdrop",id:i.getBackdropId(e.context)}),underlayProps:n.element({"data-part":"underlay",id:i.getUnderlayId(e.context),onPointerDown(o){o.target===o.currentTarget&&o.preventDefault()},onClick(o){t({type:"UNDERLAY_CLICK",target:o.currentTarget}),o.stopPropagation()}}),contentProps:n.element({"data-part":"content",role:e.context.role,id:i.getContentId(e.context),tabIndex:-1,"aria-modal":R(e.context.isTopMostDialog),"aria-label":r||void 0,"aria-labelledby":r||!e.context.isTitleRendered?void 0:i.getTitleId(e.context),"aria-describedby":e.context.isDescriptionRendered?i.getDescriptionId(e.context):void 0,onClick(o){o.stopPropagation()}}),titleProps:n.element({"data-part":"title",id:i.getTitleId(e.context)}),descriptionProps:n.element({"data-part":"description",id:i.getDescriptionId(e.context)}),closeButtonProps:n.button({"data-part":"close-button",id:i.getCloseButtonId(e.context),type:"button",onClick(o){o.stopPropagation(),t("CLOSE")}})}}var m=require("@zag-js/core");var M=(e,...t)=>{let n=typeof e=="function"?e(...t):e;return n!=null?n:void 0};var Be=(()=>{let e=0;return()=>(e++,e.toString(36))})();var G=require("aria-hidden"),Z=require("focus-trap");var X=require("@zag-js/core"),v=(0,X.proxy)({value:[],isTopMost(e){let t=this.value[this.value.length-1];return(t==null?void 0:t.id)===e},add(e){this.value.push(e)},remove(e){let t=this.value.findIndex(n=>n.id===e);t<this.value.length-1?this.value.splice(t).forEach(n=>n.close()):this.value=this.value.filter(n=>n.id!==e)},closeAll(){this.value.forEach(e=>{e.close(),this.remove(e.id)})}});var{and:Le}=m.guards,J=(0,m.createMachine)({id:"dialog",initial:"unknown",context:{pointerdownNode:null,role:"dialog",isTitleRendered:!0,isDescriptionRendered:!0,uid:"234",trapFocus:!0,preventScroll:!0,isTopMostDialog:!0,closeOnOutsideClick:!0,closeOnEsc:!0,restoreFocus:!0},states:{unknown:{on:{SETUP:{target:"closed",actions:"setupDocument"}}},open:{entry:["checkRenderedElements"],activities:["trapFocus","preventScroll","hideContentBelow","subscribeToStore","trackEscKey","trackPointerDown"],on:{CLOSE:"closed",TRIGGER_CLICK:"closed",UNDERLAY_CLICK:{guard:Le("isTopMostDialog","closeOnOutsideClick","isValidUnderlayClick"),target:"closed",actions:["invokeOnOutsideClick"]}}},closed:{entry:["invokeOnClose","clearPointerdownNode"],on:{OPEN:"open",TRIGGER_CLICK:"open"}}}},{guards:{isTopMostDialog:e=>e.isTopMostDialog,closeOnOutsideClick:e=>e.closeOnOutsideClick,isValidUnderlayClick:(e,t)=>t.target===e.pointerdownNode},activities:{trackPointerDown(e,t){return z(i.getDoc(e),n=>{e.pointerdownNode=(0,m.ref)(n)})},trackEscKey(e,t,{send:n}){return g(i.getWin(e),"keydown",r=>{var l;e.closeOnEsc&&r.key==="Escape"&&e.isTopMostDialog&&((l=e.onEsc)==null||l.call(e),n("CLOSE"))})},preventScroll(e){return W({allowPinchZoom:!0,disabled:!e.preventScroll,document:i.getDoc(e)})},trapFocus(e){let t;return L(()=>{if(!e.isTopMostDialog||!e.trapFocus)return;let n=i.getContentEl(e);t=(0,Z.createFocusTrap)(n,{document:i.getDoc(e),escapeDeactivates:!1,fallbackFocus:i.getContentEl(e),allowOutsideClick:!0,returnFocusOnDeactivate:e.restoreFocus,initialFocus:M(e.initialFocusEl),setReturnFocus:M(e.finalFocusEl)});try{t.activate()}catch(r){}}),()=>t==null?void 0:t.deactivate()},subscribeToStore(e,t,{send:n}){let r={id:e.uid,close:()=>n("CLOSE")};v.add(r),e.isTopMostDialog=v.isTopMost(e.uid);let l=(0,m.subscribe)(v,()=>{e.isTopMostDialog=v.isTopMost(e.uid)});return()=>{l(),v.remove(e.uid)}},hideContentBelow(e){let t;return L(()=>{let n=i.getUnderlayEl(e);try{t=(0,G.hideOthers)(n)}catch(r){}}),()=>t==null?void 0:t()}},actions:{setupDocument(e,t){t.doc&&(e.doc=(0,m.ref)(t.doc)),e.uid=t.id},checkRenderedElements(e){L(()=>{e.isTitleRendered=!!i.getTitleEl(e),e.isDescriptionRendered=!!i.getDescriptionEl(e)})},invokeOnOutsideClick(e){var t;(t=e.onOutsideClick)==null||t.call(e)},invokeOnClose(e){var t;(t=e.onClose)==null||t.call(e)},clearPointerdownNode(e){e.pointerdownNode=null}}});module.exports=pe(Pe);
//# sourceMappingURL=index.js.map
{
"name": "@zag-js/dialog",
"version": "0.0.0-dev-20220407084218",
"version": "0.0.0-dev-20220408111010",
"description": "Core logic for the dialog widget implemented as a state machine",

@@ -32,5 +32,5 @@ "keywords": [

"dependencies": {
"@zag-js/core": "^0.0.0-dev-20220407084218",
"@zag-js/dom-utils": "^0.0.0-dev-20220407084218",
"@zag-js/types": "^0.0.0-dev-20220407084218",
"@zag-js/core": "^0.0.0-dev-20220408111010",
"@zag-js/dom-utils": "^0.0.0-dev-20220408111010",
"@zag-js/types": "^0.0.0-dev-20220408111010",
"aria-hidden": "^1.1.3",

@@ -37,0 +37,0 @@ "focus-trap": "^6.7.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc