mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-25 15:40:49 +08:00
1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1286],{937:(e,t,r)=>{r.d(t,{Cf:()=>f,L3:()=>h,c7:()=>m,lG:()=>d,rr:()=>g,zM:()=>c});var a=r(95155),n=r(12115),l=r(89511),o=r(91037),i=r(75889),s=r(87350);let d=l.bL,c=l.l9,u=l.ZL;l.bm;let p=n.forwardRef((e,t)=>{let{className:r,...n}=e;return(0,a.jsx)(l.hJ,{ref:t,className:(0,i.QP)("fixed inset-0 z-50 bg-black/30 backdrop-blur-sm data-[state=open]:animate-fd-fade-in data-[state=closed]:animate-fd-fade-out",r),...n})});p.displayName=l.hJ.displayName;let f=n.forwardRef((e,t)=>{let{className:r,children:n,...d}=e;return(0,a.jsxs)(u,{children:[(0,a.jsx)(p,{}),(0,a.jsxs)(l.UC,{ref:t,className:(0,i.QP)("fixed left-1/2 top-1/2 z-50 flex flex-col gap-4 w-full max-w-lg -translate-x-1/2 -translate-y-1/2 border bg-fd-popover p-4 shadow-lg rounded-xl duration-200 data-[state=open]:animate-fd-dialog-in data-[state=closed]:animate-fd-dialog-out focus-visible:outline-none",r),...d,children:[n,(0,a.jsx)(l.bm,{"aria-label":"Close",className:(0,i.QP)((0,s.r)({size:"icon-sm",color:"ghost"}),"absolute end-2 top-2 text-fd-muted-foreground/70"),children:(0,a.jsx)(o.X,{})})]})]})});f.displayName=l.UC.displayName;let m=e=>{let{className:t,...r}=e;return(0,a.jsx)("div",{className:(0,i.QP)("flex flex-col gap-1.5 text-center sm:text-start",t),...r})};m.displayName="DialogHeader";let h=n.forwardRef((e,t)=>{let{className:r,...n}=e;return(0,a.jsx)(l.hE,{ref:t,className:(0,i.QP)("text-lg font-semibold leading-none tracking-tight",r),...n})});h.displayName=l.hE.displayName;let g=n.forwardRef((e,t)=>{let{className:r,...n}=e;return(0,a.jsx)(l.VY,{ref:t,className:(0,i.QP)("text-sm text-fd-muted-foreground",r),...n})});g.displayName=l.VY.displayName},61286:(e,t,r)=>{r.r(t),r.d(t,{OauthDialog:()=>f,OauthDialogTrigger:()=>m});var a=r(95155),n=r(937),l=r(22544),o=r(49559),i=r(81835),s=r(12115),d=r(75889),c=r(87350),u=r(24610);let p={password:{name:"Resource Owner Password Flow",description:"Authenticate using username and password."},clientCredentials:{name:"Client Credentials",description:"Intended for the server-to-server authentication."},authorizationCode:{name:"Authorization code",description:"Authenticate with 3rd party services"},implicit:{name:"Implicit",description:"Retrieve the access token directly."}};function f({scheme:e,scopes:t,setToken:r,children:f,open:m,setOpen:h}){let[g,w]=(0,s.useState)(()=>Object.keys(e.flows)[0]),x=(0,l.mN)({defaultValues:{clientId:"",clientSecret:"",username:"",password:""}}),j=(0,i.I)(async(t,a)=>{let n=e.flows.authorizationCode,l=await fetch(n.tokenUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",code:t,redirect_uri:a.redirect_uri,client_id:a.client_id,client_secret:a.client_secret})});if(!l.ok)throw Error(await l.text());let{access_token:o,token_type:i="Bearer"}=await l.json();r(`${i} ${o}`),h(!1)});(0,s.useEffect)(()=>{if(e.flows.authorizationCode){let e=new URLSearchParams(window.location.search),t=e.get("state"),r=e.get("code");if(t&&r){let e=JSON.parse(t);h(!0),x.setValue("clientId",e.client_id),x.setValue("clientSecret",e.client_secret),j.start(r,e),window.history.replaceState(null,"",window.location.pathname);return}}if(e.flows.implicit&&window.location.hash.length>1){let e=new URLSearchParams(window.location.hash.slice(1)),t=e.get("state"),a=e.get("access_token"),n=e.get("token_type")??"Bearer";if(t&&a){let e=JSON.parse(t);x.setValue("clientId",e.client_id),r(`${n} ${a}`),window.history.replaceState(null,"",window.location.pathname)}}},[]);let y=(0,i.I)(async a=>{let n;if("implicit"===g){let r=e.flows[g],n=new URLSearchParams;n.set("response_type","token"),n.set("client_id",a.clientId),n.set("redirect_uri",window.location.href),n.set("scope",t.join("+")),n.set("state",JSON.stringify({client_id:a.clientId,redirect_uri:window.location.href})),window.location.replace(`${r.authorizationUrl}?${n.toString()}`);return}if("authorizationCode"===g){let r=e.flows[g],n=new URLSearchParams;n.set("response_type","code"),n.set("client_id",a.clientId),n.set("redirect_uri",window.location.href),n.set("scope",t.join("+")),n.set("state",JSON.stringify({client_id:a.clientId,client_secret:a.clientSecret,redirect_uri:window.location.href})),window.location.replace(`${r.authorizationUrl}?${n.toString()}`);return}if("password"===g){let r=e.flows[g];n=await fetch(r.tokenUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"password",username:a.username,password:a.password,scope:t.join("+")})})}if("clientCredentials"===g){let r=e.flows[g];n=await fetch(r.tokenUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials",client_id:a.clientId,client_secret:a.clientSecret,scope:t.join("+")})})}if(n){if(!n.ok)throw Error(await n.text());let{access_token:e,token_type:t="Bearer"}=await n.json();r(`${t} ${e}`),h(!1)}}),b=x.handleSubmit(e=>y.start(e)),C=y.isLoading||j.isLoading,v=j.error??y.error;return(0,a.jsxs)(n.lG,{open:m,onOpenChange:h,children:[f,(0,a.jsxs)(n.Cf,{children:[(0,a.jsxs)(n.c7,{children:[(0,a.jsx)(n.L3,{children:"Authorization"}),(0,a.jsx)(n.rr,{children:"Obtain the access token for API."})]}),(0,a.jsxs)("form",{className:"flex flex-col gap-6",onSubmit:e=>{b(e),e.stopPropagation()},children:[(0,a.jsxs)(u.l6,{value:g,onValueChange:w,children:[(0,a.jsx)(u.bq,{children:(0,a.jsx)(u.yv,{})}),(0,a.jsx)(u.gC,{children:Object.keys(e.flows).map(e=>{let{name:t,description:r}=p[e];return(0,a.jsxs)(u.eb,{value:e,children:[(0,a.jsx)("p",{className:"font-medium",children:t}),(0,a.jsx)("p",{className:"text-fd-muted-foreground",children:r})]},e)})})]}),("authorizationCode"===g||"clientCredentials"===g||"implicit"===g)&&(0,a.jsxs)("fieldset",{className:"flex flex-col gap-1.5",children:[(0,a.jsx)("label",{htmlFor:"client_id",className:(0,d.QP)((0,o.I)()),children:"Client ID"}),(0,a.jsx)("p",{className:"text-fd-muted-foreground text-sm",children:"The client ID of your OAuth application."}),(0,a.jsx)(o.p,{id:"client_id",placeholder:"Enter value",type:"text",autoComplete:"off",disabled:C,...x.register("clientId",{required:!0})})]}),("authorizationCode"===g||"clientCredentials"===g)&&(0,a.jsxs)("fieldset",{className:"flex flex-col gap-1.5",children:[(0,a.jsx)("label",{htmlFor:"client_secret",className:(0,d.QP)((0,o.I)()),children:"Client Secret"}),(0,a.jsx)("p",{className:"text-fd-muted-foreground text-sm",children:"The client secret of your OAuth application."}),(0,a.jsx)(o.p,{id:"client_secret",placeholder:"Enter value",type:"password",autoComplete:"off",disabled:C,...x.register("clientSecret",{required:!0})})]}),"password"===g&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("fieldset",{className:"flex flex-col gap-1.5",children:[(0,a.jsx)("label",{htmlFor:"username",className:(0,d.QP)((0,o.I)()),children:"Username"}),(0,a.jsx)(o.p,{id:"username",placeholder:"Enter value",type:"text",disabled:C,autoComplete:"off",...x.register("username",{required:!0})})]}),(0,a.jsxs)("fieldset",{className:"flex flex-col gap-1.5",children:[(0,a.jsx)("label",{htmlFor:"password",className:(0,d.QP)((0,o.I)()),children:"Client Secret"}),(0,a.jsx)(o.p,{id:"password",placeholder:"Enter value",type:"password",autoComplete:"off",disabled:C,...x.register("password",{required:!0})})]})]}),v?(0,a.jsx)("p",{className:"text-red-400 font-medium text-sm",children:String(v)}):null,(0,a.jsx)("button",{type:"submit",disabled:C,className:(0,d.QP)((0,c.r)({color:"primary"})),children:j.isLoading?"Fetching token...":"Submit"})]})]})]})}let m=n.zM},89511:(e,t,r)=>{r.d(t,{Cf:()=>U,L3:()=>$,LC:()=>k,UC:()=>er,VY:()=>en,ZL:()=>ee,bL:()=>H,bm:()=>el,hE:()=>ea,hJ:()=>et,l9:()=>X,lG:()=>N});var a=r(12115),n=r(92556),l=r(94446),o=r(3468),i=r(68946),s=r(23558),d=r(44831),c=r(69666),u=r(75433),p=r(76842),f=r(97602),m=r(19526),h=r(40101),g=r(97745),w=r(32467),x=r(95155),j="Dialog",[y,b]=(0,o.A)(j),[C,v]=y(j),N=e=>{let{__scopeDialog:t,children:r,open:n,defaultOpen:l,onOpenChange:o,modal:d=!0}=e,c=a.useRef(null),u=a.useRef(null),[p,f]=(0,s.i)({prop:n,defaultProp:null!=l&&l,onChange:o,caller:j});return(0,x.jsx)(C,{scope:t,triggerRef:c,contentRef:u,contentId:(0,i.B)(),titleId:(0,i.B)(),descriptionId:(0,i.B)(),open:p,onOpenChange:f,onOpenToggle:a.useCallback(()=>f(e=>!e),[f]),modal:d,children:r})};N.displayName=j;var _="DialogTrigger",I=a.forwardRef((e,t)=>{let{__scopeDialog:r,...a}=e,o=v(_,r),i=(0,l.s)(t,o.triggerRef);return(0,x.jsx)(f.sG.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":J(o.open),...a,ref:i,onClick:(0,n.mK)(e.onClick,o.onOpenToggle)})});I.displayName=_;var R="DialogPortal",[D,P]=y(R,{forceMount:void 0}),S=e=>{let{__scopeDialog:t,forceMount:r,children:n,container:l}=e,o=v(R,t);return(0,x.jsx)(D,{scope:t,forceMount:r,children:a.Children.map(n,e=>(0,x.jsx)(p.C,{present:r||o.open,children:(0,x.jsx)(u.Z,{asChild:!0,container:l,children:e})}))})};S.displayName=R;var O="DialogOverlay",k=a.forwardRef((e,t)=>{let r=P(O,e.__scopeDialog),{forceMount:a=r.forceMount,...n}=e,l=v(O,e.__scopeDialog);return l.modal?(0,x.jsx)(p.C,{present:a||l.open,children:(0,x.jsx)(F,{...n,ref:t})}):null});k.displayName=O;var E=(0,w.TL)("DialogOverlay.RemoveScroll"),F=a.forwardRef((e,t)=>{let{__scopeDialog:r,...a}=e,n=v(O,r);return(0,x.jsx)(h.A,{as:E,allowPinchZoom:!0,shards:[n.contentRef],children:(0,x.jsx)(f.sG.div,{"data-state":J(n.open),...a,ref:t,style:{pointerEvents:"auto",...a.style}})})}),L="DialogContent",U=a.forwardRef((e,t)=>{let r=P(L,e.__scopeDialog),{forceMount:a=r.forceMount,...n}=e,l=v(L,e.__scopeDialog);return(0,x.jsx)(p.C,{present:a||l.open,children:l.modal?(0,x.jsx)(z,{...n,ref:t}):(0,x.jsx)(A,{...n,ref:t})})});U.displayName=L;var z=a.forwardRef((e,t)=>{let r=v(L,e.__scopeDialog),o=a.useRef(null),i=(0,l.s)(t,r.contentRef,o);return a.useEffect(()=>{let e=o.current;if(e)return(0,g.Eq)(e)},[]),(0,x.jsx)(T,{...e,ref:i,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:(0,n.mK)(e.onCloseAutoFocus,e=>{var t;e.preventDefault(),null==(t=r.triggerRef.current)||t.focus()}),onPointerDownOutside:(0,n.mK)(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,r=0===t.button&&!0===t.ctrlKey;(2===t.button||r)&&e.preventDefault()}),onFocusOutside:(0,n.mK)(e.onFocusOutside,e=>e.preventDefault())})}),A=a.forwardRef((e,t)=>{let r=v(L,e.__scopeDialog),n=a.useRef(!1),l=a.useRef(!1);return(0,x.jsx)(T,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{var a,o;null==(a=e.onCloseAutoFocus)||a.call(e,t),t.defaultPrevented||(n.current||null==(o=r.triggerRef.current)||o.focus(),t.preventDefault()),n.current=!1,l.current=!1},onInteractOutside:t=>{var a,o;null==(a=e.onInteractOutside)||a.call(e,t),t.defaultPrevented||(n.current=!0,"pointerdown"===t.detail.originalEvent.type&&(l.current=!0));let i=t.target;(null==(o=r.triggerRef.current)?void 0:o.contains(i))&&t.preventDefault(),"focusin"===t.detail.originalEvent.type&&l.current&&t.preventDefault()}})}),T=a.forwardRef((e,t)=>{let{__scopeDialog:r,trapFocus:n,onOpenAutoFocus:o,onCloseAutoFocus:i,...s}=e,u=v(L,r),p=a.useRef(null),f=(0,l.s)(t,p);return(0,m.Oh)(),(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(c.n,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:o,onUnmountAutoFocus:i,children:(0,x.jsx)(d.qW,{role:"dialog",id:u.contentId,"aria-describedby":u.descriptionId,"aria-labelledby":u.titleId,"data-state":J(u.open),...s,ref:f,onDismiss:()=>u.onOpenChange(!1)})}),(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(Z,{titleId:u.titleId}),(0,x.jsx)(Y,{contentRef:p,descriptionId:u.descriptionId})]})]})}),Q="DialogTitle",$=a.forwardRef((e,t)=>{let{__scopeDialog:r,...a}=e,n=v(Q,r);return(0,x.jsx)(f.sG.h2,{id:n.titleId,...a,ref:t})});$.displayName=Q;var q="DialogDescription",V=a.forwardRef((e,t)=>{let{__scopeDialog:r,...a}=e,n=v(q,r);return(0,x.jsx)(f.sG.p,{id:n.descriptionId,...a,ref:t})});V.displayName=q;var B="DialogClose",G=a.forwardRef((e,t)=>{let{__scopeDialog:r,...a}=e,l=v(B,r);return(0,x.jsx)(f.sG.button,{type:"button",...a,ref:t,onClick:(0,n.mK)(e.onClick,()=>l.onOpenChange(!1))})});function J(e){return e?"open":"closed"}G.displayName=B;var M="DialogTitleWarning",[K,W]=(0,o.q)(M,{contentName:L,titleName:Q,docsSlug:"dialog"}),Z=e=>{let{titleId:t}=e,r=W(M),n="`".concat(r.contentName,"` requires a `").concat(r.titleName,"` for the component to be accessible for screen reader users.\n\nIf you want to hide the `").concat(r.titleName,"`, you can wrap it with our VisuallyHidden component.\n\nFor more information, see https://radix-ui.com/primitives/docs/components/").concat(r.docsSlug);return a.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},Y=e=>{let{contentRef:t,descriptionId:r}=e,n=W("DialogDescriptionWarning"),l="Warning: Missing `Description` or `aria-describedby={undefined}` for {".concat(n.contentName,"}.");return a.useEffect(()=>{var e;let a=null==(e=t.current)?void 0:e.getAttribute("aria-describedby");r&&a&&(document.getElementById(r)||console.warn(l))},[l,t,r]),null},H=N,X=I,ee=S,et=k,er=U,ea=$,en=V,el=G}}]); |