blowfish/node_modules/@headlessui/react/dist/components/dialog/dialog.js

2 lines
7.1 KiB
JavaScript
Raw Permalink Normal View History

2023-01-29 22:30:24 +00:00
import m,{createContext as le,createRef as ne,useContext as K,useEffect as F,useMemo as v,useReducer as ae,useRef as W,useState as ie}from"react";import{match as I}from'../../utils/match.js';import{forwardRefWithAs as O,render as C,Features as q}from'../../utils/render.js';import{useSyncRefs as S}from'../../hooks/use-sync-refs.js';import{Keys as se}from'../keyboard.js';import{isDisabledReactIssue7711 as de}from'../../utils/bugs.js';import{useId as L}from'../../hooks/use-id.js';import{FocusTrap as M}from'../../components/focus-trap/focus-trap.js';import{useInertOthers as pe}from'../../hooks/use-inert-others.js';import{Portal as B}from'../../components/portal/portal.js';import{ForcePortalRoot as G}from'../../internal/portal-force-root.js';import{Description as ue,useDescriptions as fe}from'../description/description.js';import{useOpenClosed as ce,State as z}from'../../internal/open-closed.js';import{useServerHandoffComplete as ge}from'../../hooks/use-server-handoff-complete.js';import{StackProvider as Te,StackMessage as J}from'../../internal/stack-context.js';import{useOutsideClick as me}from'../../hooks/use-outside-click.js';import{useOwnerDocument as De}from'../../hooks/use-owner.js';import{useEventListener as Pe}from'../../hooks/use-event-listener.js';import{Hidden as ye,Features as Ee}from'../../internal/hidden.js';import{useEvent as A}from'../../hooks/use-event.js';import{disposables as he}from'../../utils/disposables.js';import{isIOS as Re}from'../../utils/platform.js';var be=(r=>(r[r.Open=0]="Open",r[r.Closed=1]="Closed",r))(be||{}),ve=(e=>(e[e.SetTitleId=0]="SetTitleId",e))(ve||{});let Ae={[0](t,e){return t.titleId===e.id?t:{...t,titleId:e.id}}},H=le(null);H.displayName="DialogContext";function k(t){let e=K(H);if(e===null){let r=new Error(`<${t} /> is missing a parent <Dialog /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(r,k),r}return e}function Oe(t,e,r=()=>[document.body]){F(()=>{var c;if(!e||!t)return;let s=he(),d=window.pageYOffset;function a(n,i,l){let P=n.style.getPropertyValue(i);return Object.assign(n.style,{[i]:l}),s.add(()=>{Object.assign(n.style,{[i]:P})})}let o=t.documentElement,f=((c=t.defaultView)!=null?c:window).innerWidth-o.clientWidth;if(a(o,"overflow","hidden"),f>0){let n=o.clientWidth-o.offsetWidth,i=f-n;a(o,"paddingRight",`${i}px`)}if(Re()){a(t.body,"marginTop",`-${d}px`),window.scrollTo(0,0);let n=null;s.addEventListener(t,"click",i=>{if(i.target instanceof HTMLElement)try{let l=i.target.closest("a");if(!l)return;let{hash:P}=new URL(l.href),u=t.querySelector(P);u&&!r().some(_=>_.contains(u))&&(n=u)}catch{}},!0),s.addEventListener(t,"touchmove",i=>{i.target instanceof HTMLElement&&!r().some(l=>l.contains(i.target))&&i.preventDefault()},{passive:!1}),s.add(()=>{window.scrollTo(0,window.pageYOffset+d),n&&n.isConnected&&(n.scrollIntoView({block:"nearest"}),n=null)})}return s.dispose},[t,e])}function Ce(t,e){return I(e.type,Ae,t,e)}let Se="div",Le=q.RenderStrategy|q.Static,Me=O(function(e,r){let s=L(),{id:d=`headlessui-dialog-${s}`,open:a,onClose:o,initialFocus:p,__demoMode:f=!1,...c}=e,[n,i]=ie(0),l=ce();a===void 0&&l!==null&&(a=I(l,{[z.Open]:!0,[z.Closed]:!1}));let P=W(new Set),u=W(null),_=S(u,r),U=W(null),y=De(u),$=e.hasOwnProperty("open")||l!==null,Y=e.hasOwnProperty("onClose");if(!$&&!Y)throw new Error("You have to provide an `open` and an `onClose` prop to the `Dialog` component.");if(!$)throw new Error("You provided an `onClose` prop to the `Dialog`, but forgot an `open` prop.");if(!Y)throw new Error("You provided an `open` prop to the `Dialog`, but forgot an `onClose` prop.");if(typeof a!="boolean")throw new Error(`You provided an \`open\` prop to the \`Dialog\`, but the value is not a boolean. Received: ${a}`);if(typeof o!="function")throw new Error(`You provided an \`onClose\` prop to the \`Dialog\`, but the value is not a function. Received: ${o}`);let g=a?0:1,[h,Q]=ae(Ce,{titleId:null,descriptionId:null,panelRef:ne()}),R=A(()=>o(!1)),j=A(T=>Q({type:0,id:T})),x=ge()?f?!1:g===0:!1,w=n>1,X=K(H)!==null,Z=w?"parent":"leaf";pe(u,w?x:!1);let N=A(()=>{var b,D;return[...