decocms
Version:
Deco CMS — Self-hostable MCP Gateway for managing AI connections and tools
2 lines (1 loc) • 3.03 kB
JavaScript
import{r as l,c as L,j as g}from"./index-DoEtSiIe.js";import{e as w}from"./backoff-CrEUbyZT.js";const y=1e4,I=1e3,b=3e4;function k({iframeRef:e,src:t,active:n}){const r=l.useRef(0),o=l.useRef(null),u=l.useRef(null),i=l.useRef(t),s=l.useRef(n);i.current=t,s.current=n;const a=()=>{o.current&&clearTimeout(o.current),u.current&&clearTimeout(u.current),o.current=null,u.current=null},f=()=>{o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{o.current=null,d()},y)},d=()=>{if(!s.current||!i.current)return;u.current&&clearTimeout(u.current);const c=w(b,I,r.current,2,.5);r.current+=1,u.current=setTimeout(()=>{u.current=null;const E=e.current,T=i.current;!E||!T||!s.current||(E.src=T,f())},c)},m=()=>{r.current=0,a()},p=()=>{o.current&&(clearTimeout(o.current),o.current=null),d()};return l.useEffect(()=>{if(a(),r.current=0,!(!n||!t))return f(),a},[t,n]),{handleLoad:m,handleError:p}}function C(){const e=L.c(1);let t;return e[0]===Symbol.for("react.memo_cache_sentinel")?(t=g.jsx("div",{"data-testid":"preview-progress",className:"absolute inset-x-0 top-0 z-40 h-1 overflow-hidden",children:g.jsx("div",{className:"absolute inset-y-0 left-0 rounded-r-full bg-brand shadow-[0_0_6px] shadow-brand/60 animate-preview-ramp"})}),e[0]=t):t=e[0],t}const A=3e3,v=new WeakMap,S=5e3,R=new WeakMap;function _(e){const t=R.get(e);if(t)return t;const n={at:Number.NEGATIVE_INFINITY},r=()=>{n.at=performance.now()};return e.addEventListener("keydown",r,!0),e.addEventListener("pointerdown",r,!0),R.set(e,n),n}typeof document<"u"&&_(document);function M(e,t){return e.defaultView?.navigator.userActivation?.isActive?performance.now()-t.at>S:!1}function h(e,t){const n=e.activeElement;return!(n instanceof HTMLElement)||n===t||n===e.body?null:n}function D(e,t=A){const n=v.get(e);if(n){n.extend(t);return}const r=e.ownerDocument,o=r.defaultView;if(!o)return;const u=_(r);let i=h(r,e),s=!1;const a=()=>{const c=h(r,e);c&&(i=c,s=!1)},f=c=>{c.key==="Tab"&&(s=!0)},d=()=>{if(r.activeElement!==e||s||M(r,u))return;const c=i;c?.isConnected&&setTimeout(()=>{r.activeElement===e&&c.focus({preventScroll:!0})},0)};let m=setTimeout(p,t);function p(){clearTimeout(m),r.removeEventListener("focusin",a,!0),r.removeEventListener("keydown",f,!0),o?.removeEventListener("blur",d),v.delete(e)}r.addEventListener("focusin",a,!0),r.addEventListener("keydown",f,!0),o.addEventListener("blur",d),v.set(e,{extend:c=>{clearTimeout(m),m=setTimeout(p,c)}})}const O=15e3;function P(e,t,n){return n?e.src===t||e.loading?e:{src:t,loading:!0}:e.src===t&&!e.loading?e:{src:t,loading:!1}}function U(e,t,n){return!n||!e||!t||x(e,t)?t:e}function V(e){return e.loading?{...e,loading:!1}:e}function x(e,t){try{const n=new URL(e),r=new URL(t);return n.origin===r.origin&&n.pathname===r.pathname}catch{return!1}}function j(e,{base:t,frameSrc:n,loadedSrc:r,wanted:o,canSwap:u}){const i=e?.base===t?e:null,s=i?.src??n,a=i?.shown??n;return!o||!s||!a?null:a===o?i:u&&r===s&&x(a,o)?{base:t,src:s,shown:o}:null}export{O as H,C as P,j as a,V as f,D as g,U as h,P as n,k as u};