@flexkit/studio 0.2.23 → 0.2.24

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.
Files changed (82) hide show
  1. package/dist/{activity-nav-button-7RLCHOFV.js → activity-nav-button-4VTYGP4T.js} +2 -2
  2. package/dist/{activity-nav-button-7RLCHOFV.js.map → activity-nav-button-4VTYGP4T.js.map} +1 -1
  3. package/dist/chat-page-A7FG7WTN.js +4 -0
  4. package/dist/chat-page-A7FG7WTN.js.map +1 -0
  5. package/dist/{chunk-DAM7JM5J.js → chunk-3COXA5QH.js} +2 -2
  6. package/dist/{chunk-DAM7JM5J.js.map → chunk-3COXA5QH.js.map} +1 -1
  7. package/dist/{chunk-7HBT6L4U.js → chunk-3IUKXOKF.js} +2 -2
  8. package/dist/{chunk-7HBT6L4U.js.map → chunk-3IUKXOKF.js.map} +1 -1
  9. package/dist/{chunk-7ERLYAPR.js → chunk-5OGT6WGZ.js} +2 -2
  10. package/dist/{chunk-7ERLYAPR.js.map → chunk-5OGT6WGZ.js.map} +1 -1
  11. package/dist/{chunk-E2NDJLAI.js → chunk-AKW7EKYI.js} +3 -3
  12. package/dist/{chunk-E2NDJLAI.js.map → chunk-AKW7EKYI.js.map} +1 -1
  13. package/dist/{chunk-CJHMUEOB.js → chunk-HTSMODQB.js} +2 -2
  14. package/dist/{chunk-CJHMUEOB.js.map → chunk-HTSMODQB.js.map} +1 -1
  15. package/dist/chunk-I6Z3WLAX.js +2 -0
  16. package/dist/chunk-I6Z3WLAX.js.map +1 -0
  17. package/dist/{chunk-KQVLLOWJ.js → chunk-IQ2F2FFF.js} +2 -2
  18. package/dist/{chunk-KQVLLOWJ.js.map → chunk-IQ2F2FFF.js.map} +1 -1
  19. package/dist/{chunk-YRPFCYLR.js → chunk-JSJZKPXU.js} +3 -3
  20. package/dist/{chunk-YRPFCYLR.js.map → chunk-JSJZKPXU.js.map} +1 -1
  21. package/dist/{chunk-ZIHC7WWT.js → chunk-L3GBAK54.js} +3 -3
  22. package/dist/{chunk-ZIHC7WWT.js.map → chunk-L3GBAK54.js.map} +1 -1
  23. package/dist/chunk-MNLYE7DK.js +3 -0
  24. package/dist/chunk-MNLYE7DK.js.map +1 -0
  25. package/dist/{chunk-CAMLITJT.js → chunk-NO3AH2M3.js} +3 -3
  26. package/dist/{chunk-CAMLITJT.js.map → chunk-NO3AH2M3.js.map} +1 -1
  27. package/dist/{chunk-EYIV4KVY.js → chunk-NSVX6HEN.js} +3 -3
  28. package/dist/{chunk-EYIV4KVY.js.map → chunk-NSVX6HEN.js.map} +1 -1
  29. package/dist/chunk-SZOEW2TL.js +8 -0
  30. package/dist/chunk-SZOEW2TL.js.map +1 -0
  31. package/dist/chunk-U6E7GNQW.js +2 -0
  32. package/dist/chunk-U6E7GNQW.js.map +1 -0
  33. package/dist/{chunk-YEWTJHKW.js → chunk-UBFBXBPG.js} +2 -2
  34. package/dist/{chunk-YEWTJHKW.js.map → chunk-UBFBXBPG.js.map} +1 -1
  35. package/dist/{chunk-AMUTDCI7.js → chunk-XV2B3W6Z.js} +3 -3
  36. package/dist/{chunk-AMUTDCI7.js.map → chunk-XV2B3W6Z.js.map} +1 -1
  37. package/dist/{entry-O75LJP6A.js → entry-RMRLV3NM.js} +2 -2
  38. package/dist/{entry-O75LJP6A.js.map → entry-RMRLV3NM.js.map} +1 -1
  39. package/dist/index.js +7 -7
  40. package/dist/index.js.map +1 -1
  41. package/dist/{list-R3FH7CYE.js → list-GVATECOW.js} +2 -2
  42. package/dist/{list-R3FH7CYE.js.map → list-GVATECOW.js.map} +1 -1
  43. package/dist/{list-RZROVSNS.js → list-HR55TZQX.js} +3 -3
  44. package/dist/{list-RZROVSNS.js.map → list-HR55TZQX.js.map} +1 -1
  45. package/dist/pages-OJYYLSI3.js +5 -0
  46. package/dist/pages-OJYYLSI3.js.map +1 -0
  47. package/dist/{plugin-pages-IPEYHBKC.js → plugin-pages-BS2IMNRU.js} +2 -2
  48. package/dist/{plugin-pages-IPEYHBKC.js.map → plugin-pages-BS2IMNRU.js.map} +1 -1
  49. package/dist/record-links-2QWJFFZF.js +2 -0
  50. package/dist/{record-links-D5GJWZIK.js.map → record-links-2QWJFFZF.js.map} +1 -1
  51. package/dist/{root-LWFZRWNO.js → root-54BI6S4V.js} +3 -3
  52. package/dist/{root-LWFZRWNO.js.map → root-54BI6S4V.js.map} +1 -1
  53. package/dist/{root-QRSWWD23.js → root-E35GZ7SV.js} +3 -3
  54. package/dist/{root-QRSWWD23.js.map → root-E35GZ7SV.js.map} +1 -1
  55. package/dist/{root-QKNPDDE4.js → root-GAB2SFFF.js} +2 -2
  56. package/dist/{root-QKNPDDE4.js.map → root-GAB2SFFF.js.map} +1 -1
  57. package/dist/{root-XXHLLKQS.js → root-JWXXF653.js} +3 -3
  58. package/dist/{root-XXHLLKQS.js.map → root-JWXXF653.js.map} +1 -1
  59. package/dist/{root-TL5U37VT.js → root-U52KZQSD.js} +2 -2
  60. package/dist/{root-TL5U37VT.js.map → root-U52KZQSD.js.map} +1 -1
  61. package/dist/{root-3J3XAFUX.js → root-ZCXGZCUT.js} +2 -2
  62. package/dist/{root-3J3XAFUX.js.map → root-ZCXGZCUT.js.map} +1 -1
  63. package/dist/{search-KXTZNQCX.js → search-IOYOKT6M.js} +2 -2
  64. package/dist/{search-KXTZNQCX.js.map → search-IOYOKT6M.js.map} +1 -1
  65. package/dist/{skills-pages-CDOGI5ZZ.js → skills-pages-MA6JLBB4.js} +2 -2
  66. package/dist/{skills-pages-CDOGI5ZZ.js.map → skills-pages-MA6JLBB4.js.map} +1 -1
  67. package/dist/{source-HTBEV3UC.js → source-3YZNNITL.js} +2 -2
  68. package/dist/{source-HTBEV3UC.js.map → source-3YZNNITL.js.map} +1 -1
  69. package/package.json +3 -3
  70. package/dist/chat-page-ASH67R6B.js +0 -4
  71. package/dist/chat-page-ASH67R6B.js.map +0 -1
  72. package/dist/chunk-7HEARTFH.js +0 -2
  73. package/dist/chunk-7HEARTFH.js.map +0 -1
  74. package/dist/chunk-FUX7UG36.js +0 -8
  75. package/dist/chunk-FUX7UG36.js.map +0 -1
  76. package/dist/chunk-QCVQJN5O.js +0 -2
  77. package/dist/chunk-QCVQJN5O.js.map +0 -1
  78. package/dist/chunk-SY67F62K.js +0 -3
  79. package/dist/chunk-SY67F62K.js.map +0 -1
  80. package/dist/pages-NBXY5WPW.js +0 -5
  81. package/dist/pages-NBXY5WPW.js.map +0 -1
  82. package/dist/record-links-D5GJWZIK.js +0 -2
@@ -1,4 +1,4 @@
1
- import'./index.css';import {b as b$4,c as c$3}from'./chunk-ELOJGLAR.js';import {a as a$3,b as b$5}from'./chunk-MLHXPTBT.js';import {e}from'./chunk-ZIHC7WWT.js';import {a as a$1}from'./chunk-7HBT6L4U.js';import {f as f$1,i,g as g$1,y,k,b as b$1,e as e$2,l,w,v,d,a,m,h,p,n,o as o$2,s as s$2,c as c$4,q as q$1,r as r$1,j as j$2,u,t}from'./chunk-4PUMSUJL.js';import {c as c$1}from'./chunk-2DXR5NJV.js';import {j,f as f$2}from'./chunk-E2NDJLAI.js';import {c}from'./chunk-XMOSCJOI.js';import'./chunk-HKN6BX5U.js';import'./chunk-YDVO6XWD.js';import {a as a$2}from'./chunk-ERDARDGB.js';import {f}from'./chunk-EYIV4KVY.js';import {g}from'./chunk-WPCPL2TQ.js';import'./chunk-5CVDMZUI.js';import {K,M,Q,O,qa,N,R,S,s,T,V,W,X,o,P,ha,ia,ja,ka,e as e$4,$,aa,da,ea,ba,fa}from'./chunk-DGIY4SKN.js';import {e as e$3,g as g$2,h as h$1,j as j$1,q,r,s as s$1,o as o$1}from'./chunk-SZEGGBOC.js';import {v as v$1}from'./chunk-32ZU4MLE.js';import {b}from'./chunk-U45E5X3H.js';import'./chunk-HDOIOXMP.js';import {b as b$2,c as c$2,e as e$1}from'./chunk-USNXQOMJ.js';import {b as b$3}from'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useEffect,useMemo,useRef,useState,useCallback,useReducer}from'react';import {useLocation}from'react-router-dom';import On from'graphology';import qn from'graphology-layout-forceatlas2';import Qn from'graphology-layout-forceatlas2/worker';import zn,{DEFAULT_STYLES}from'sigma';import {jsxs,jsx}from'react/jsx-runtime';import {gql}from'@apollo/client';import {useApolloClient,useQuery}from'@apollo/client/react';import {formatDistance}from'date-fns';import {SearchIcon,ChevronDownIcon,LoaderCircleIcon,PlayIcon,ScanIcon,ExpandIcon,EyeOffIcon,EraserIcon,XIcon,SquareArrowOutUpRightIcon}from'lucide-react';import {closeBrackets,closeBracketsKeymap}from'@codemirror/autocomplete';import {history,defaultKeymap,historyKeymap,indentWithTab}from'@codemirror/commands';import {foldGutter,indentOnInput,bracketMatching,foldKeymap}from'@codemirror/language';import {Compartment,EditorState,Prec}from'@codemirror/state';import {EditorView,lineNumbers,highlightActiveLineGutter,highlightSpecialChars,drawSelection,dropCursor,highlightActiveLine,keymap,placeholder}from'@codemirror/view';import {graphql,updateSchema}from'cm6-graphql';import {getIntrospectionQuery,buildClientSchema}from'graphql';import {useDebounce}from'use-debounce';function Ae(e){return Math.min(2e4,2e3+e*9)}function Zt({mean:e,max:t,diagonal:n}){let r=Math.max(.05,n*.0015);return e<r&&t<r*20}var Hn=40,jn=400,Bn=1200,Xn=2;function Fn(e){return 5+Math.min(10,Math.sqrt(e)*2)}function nn(e){return Hn*(.8+Math.sqrt(e)*.6)}function rn(e,t,n){let r=Math.random()*Math.PI*2;return Array.from({length:t},(i,s)=>{let o=r+s/t*Math.PI*2+Math.random()*.3,d=n*(.9+Math.random()*.2);return {x:e.x+Math.cos(o)*d,y:e.y+Math.sin(o)*d}})}function on(e,t){return !Number.isNaN(e.getNodeAttribute(t,"x"))}function $n(e,t){if(t.length===0)return {center:{x:0,y:0},reach:0};let n=t.reduce((i,s)=>({x:i.x+e.getNodeAttribute(s,"x"),y:i.y+e.getNodeAttribute(s,"y")}),{x:0,y:0});n.x/=t.length,n.y/=t.length;let r=t.reduce((i,s)=>Math.max(i,Math.hypot(e.getNodeAttribute(s,"x")-n.x,e.getNodeAttribute(s,"y")-n.y)),0);return {center:n,reach:r}}function Jn(e,t){let n=new Map;t.forEach(r=>{let i=e.neighbors(r).find(s=>!t.has(s)&&on(e,s))??null;n.set(i,[...n.get(i)??[],r]);}),n.forEach((r,i)=>{let s;if(i){let o={x:e.getNodeAttribute(i,"x"),y:e.getNodeAttribute(i,"y")};s=rn(o,r.length,nn(r.length));}else {let o=e.nodes().filter(S=>!t.has(S)&&on(e,S)),d=$n(e,o);s=rn(d.center,r.length,d.reach+nn(r.length));}s.forEach((o,d)=>e.mergeNodeAttributes(r[d],o));});}var Ke=class{constructor(t){this.graph=t;this.positions=new Float64Array(t.order*2);let n=0;this.graph.forEachNode((r,i)=>{this.positions[n]=i.x,this.positions[n+1]=i.y,n+=2;});}positions;measure(){let{graph:t,positions:n}=this,r=0,i=0,s=0,o=Number.POSITIVE_INFINITY,d=Number.POSITIVE_INFINITY,S=Number.NEGATIVE_INFINITY,T=Number.NEGATIVE_INFINITY,y=0;return t.forEachNode((c,a)=>{let{x:h,y:g}=a;if(y+1<n.length&&!a.fixed){let N=Math.hypot(h-n[y],g-n[y+1]);r+=N,i=Math.max(i,N),s+=1;}n[y]=h,n[y+1]=g,y+=2,o=Math.min(o,h),d=Math.min(d,g),S=Math.max(S,h),T=Math.max(T,g);}),{mean:s>0?r/s:0,max:i,diagonal:t.order>0?Math.hypot(S-o,T-d):0}}};function Yn(e,t,n){let r=false,i=new Set,s=e.order>0;return e.forEachNode(o=>{t.nodes[o]||(e.dropNode(o),r=true);}),Object.values(t.nodes).forEach(o=>{if(e.hasNode(o.key)){e.getNodeAttribute(o.key,"label")!==o.label&&e.setNodeAttribute(o.key,"label",o.label);return}e.addNode(o.key,{entity:o.entity,label:o.label,color:n[o.entity]??"#71717a",size:5,x:Number.NaN,y:Number.NaN}),i.add(o.key),r=true;}),e.forEachEdge(o=>{t.edges[o]||(e.dropEdge(o),r=true);}),Object.values(t.edges).forEach(o=>{e.hasEdge(o.key)||(e.addEdgeWithKey(o.key,o.source,o.target,{size:1}),r=true);}),Jn(e,i),r&&e.forEachNode(o=>{e.setNodeAttribute(o,"size",Fn(e.degree(o)));}),{changed:r,added:i,hadNodes:s}}function sn({scene:e,colors:t,theme:n,apiRef:r,onSelect:i,onContextMenu:s,onExpand:o,onPin:d,onLayoutChange:S}){let T=useRef(null),y=useRef(null),c=useRef(null),a=useRef(null),h=useRef(null),g=useRef(null),N=useRef(null),f=useRef(null),u=useRef(null),l=useRef(new Set),p=useRef(e.pinned);p.current=e.pinned;let M=useRef({key:null,nodes:[]}),w=useRef({onSelect:i,onContextMenu:s,onExpand:o,onPin:d,onLayoutChange:S}),[F,D]=useState(0);w.current={onSelect:i,onContextMenu:s,onExpand:o,onPin:d,onLayoutChange:S},y.current||(y.current=new On({type:"undirected",multi:true}));let E=useCallback(()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null),f.current!==null&&(window.clearInterval(f.current),f.current=null),a.current&&(a.current.kill(),a.current=null,u.current=null,w.current.onLayoutChange(false));let m=y.current;l.current.forEach(x=>{m?.hasNode(x)&&m.setNodeAttribute(x,"fixed",p.current[x]===true);}),l.current=new Set;},[]),P=useCallback((m,x=[])=>{let v=y.current;if(E(),!v||v.order===0)return;if(l.current=new Set(x.filter(C=>v.hasNode(C))),l.current.forEach(C=>v.setNodeAttribute(C,"fixed",true)),!v.someNode((C,L)=>!L.fixed)){E();return}let A=qn.inferSettings(v),G=new Qn(v,{settings:{...A,adjustSizes:true,gravity:.2,slowDown:(A.slowDown??1)*2},outputReducer:(C,L)=>{let oe=g.current;return oe&&oe.node===C&&(L.x=oe.x,L.y=oe.y),L}}),q=performance.now(),Y=new Ke(v),V=false,K=0;a.current=G,u.current=q+m,G.start(),w.current.onLayoutChange(true);let k=()=>{g.current?(u.current=performance.now()+m,h.current=window.setTimeout(k,m)):E();};h.current=window.setTimeout(k,m),f.current=window.setInterval(()=>{let C=Y.measure();if(g.current){K=0;return}V=V||C.max>0,K=V&&Zt(C)?K+1:0,K>=Xn&&performance.now()-q>=Bn&&E();},jn);},[E]),$=useCallback(m=>{let x=y.current,v=c.current;if(!x||!v)return;let A=M.current;if(v.setNodesState(A.nodes.filter(G=>x.hasNode(G)),{isNeighbour:false}),m&&x.hasNode(m)){let G=x.neighbors(m);v.setNodesState(G,{isNeighbour:true}),M.current={key:m,nodes:G};}else M.current={key:null,nodes:[]};},[]);return useEffect(()=>{let m=T.current,x=y.current;if(!m||!x)return;if(m.clientWidth===0||m.clientHeight===0){let k=new ResizeObserver(()=>{m.clientWidth>0&&m.clientHeight>0&&(k.disconnect(),D(C=>C+1));});return k.observe(m),()=>k.disconnect()}let v=n==="dark",A=new zn(x,m,{customNodeState:{isNeighbour:false},customEdgeState:{},customGraphState:{isDense:x.order>300,isZoomedIn:false},settings:{allowInvalidContainer:true,itemSizesReference:"screen",enableNodeDrag:true,renderEdgeLabels:false,labelRenderedSizeThreshold:7,labelDensity:.1,labelGridCellSize:80},styles:{nodes:[{...DEFAULT_STYLES.nodes,size:{whenState:"isHighlighted",then:k=>k.size+5,else:{whenState:"isHovered",then:k=>k.size+2,else:{attribute:"size"}}},cursor:"pointer",labelColor:v?"#e4e4e7":"#18181b",labelSize:12,labelFont:"ui-sans-serif, system-ui, sans-serif",labelVisibility:(k,C,L)=>C.isHovered||C.isHighlighted?"visible":L.isDense&&!L.isZoomedIn&&!C.isNeighbour?"hidden":"auto",backdropColor:v?"#27272a":"#ffffff",backdropShadowColor:v?"rgba(0, 0, 0, 0.6)":"rgba(0, 0, 0, 0.25)"}],edges:[{...DEFAULT_STYLES.edges,color:v?"#3f3f46":"#d4d4d8",size:1}]}});c.current=A,A.on("clickNode",({node:k})=>{w.current.onSelect(k);}),A.on("clickStage",()=>{w.current.onSelect(null);}),A.on("doubleClickNode",({node:k,event:C})=>{C.preventSigmaDefault(),w.current.onExpand(k);}),A.on("rightClickNode",({node:k,event:C})=>{C.preventSigmaDefault();let L=C.original;L.preventDefault(),w.current.onSelect(k),w.current.onContextMenu(k,{x:L.clientX,y:L.clientY});}),A.on("enterNode",({node:k})=>$(k)),A.on("leaveNode",()=>$(null));let G=k=>{let C=new Set([k,...x.neighbors(k)]);return x.nodes().filter(L=>L===k||!C.has(L))};A.on("nodeDragStart",({node:k})=>{g.current={node:k,x:x.getNodeAttribute(k,"x"),y:x.getNodeAttribute(k,"y")},x.size>0?(P(Ae(x.order),G(k)),N.current=a.current):(E(),x.setNodeAttribute(k,"fixed",true));}),A.on("nodeDrag",({node:k})=>{g.current?.node===k&&(g.current.x=x.getNodeAttribute(k,"x"),g.current.y=x.getNodeAttribute(k,"y"));}),A.on("nodeDragEnd",({node:k})=>{let C=g.current!==null&&a.current!==null&&a.current===N.current;g.current=null,N.current=null,w.current.onPin(k),C&&P(Ae(x.order),G(k));});let q=A.getCamera(),Y=({ratio:k})=>{let C=k<.45;A.getGraphState().isZoomedIn!==C&&A.setGraphState({isZoomedIn:C});};q.on("updated",Y);let V=k=>k.preventDefault();m.addEventListener("contextmenu",V);let K=new ResizeObserver(()=>{m.clientWidth>0&&m.clientHeight>0&&(A.resize(),A.scheduleRefresh());});return K.observe(m),r.current={fit:()=>{q.reset({duration:300});}},()=>{K.disconnect(),q.off("updated",Y),m.removeEventListener("contextmenu",V),r.current=null,c.current=null,M.current={key:null,nodes:[]},A.kill();}},[n,F,r,P,E,$]),useEffect(()=>{let m=y.current;if(!m)return;E();let{changed:x,added:v,hadNodes:A}=Yn(m,e,t);if(!x)return;if(c.current?.setGraphState({isDense:m.order>300}),$(m.hasNode(M.current.key??"")?M.current.key:null),m.size===0){E();return}let G=A&&v.size>0?m.nodes().filter(q=>!v.has(q)):[];P(Ae(G.length>0?v.size:m.order),G);},[e.version]),useEffect(()=>{let m=y.current;m&&m.forEachNode((x,v)=>{m.setNodeAttribute(x,"color",t[v.entity]??"#71717a");});},[t]),useEffect(()=>{let m=y.current,x=c.current;if(!m||!x)return;let v=new Set(e.hiddenEntities),A=false;m.forEachNode((G,q)=>{x.setNodeState(G,{isHidden:v.has(q.entity),isHighlighted:G===e.selected});let Y=e.pinned[G]===true||l.current.has(G);(q.fixed??false)!==Y&&(m.setNodeAttribute(G,"fixed",Y),A=true);}),A&&u.current!==null&&P(Math.max(500,u.current-performance.now()),[...l.current]),m.forEachEdge((G,q,Y,V)=>{x.setEdgeState(G,{isHidden:v.has(m.getNodeAttribute(Y,"entity"))||v.has(m.getNodeAttribute(V,"entity"))});});},[e.hiddenEntities,e.selected,e.pinned,e.version,F,n,P]),useEffect(()=>E,[E]),jsx("div",{className:"fk:h-full fk:w-full fk:min-h-0",ref:T})}function an({menu:e,relationships:t,isPinned:n,onClose:r$1,onExpandAll:i,onExpandAttribute:s,onHide:o,onHideOthers:d,onTogglePin:S,onOpenRecord:T}){let y=e?.key??"";return jsxs(e$3,{onOpenChange:c=>{c||r$1();},open:e!==null,children:[jsx(g$2,{asChild:true,children:jsx("span",{"aria-hidden":"true",className:"fk:fixed fk:size-0",style:{left:e?.x??0,top:e?.y??0}})}),jsxs(h$1,{align:"start",className:"fk:w-52","data-testid":"graph-context-menu",side:"bottom",children:[jsx(j$1,{onSelect:()=>i(y),children:"Expand all"}),t.length>0?jsxs(q,{children:[jsx(r,{children:"Expand"}),jsx(s$1,{className:"fk:max-h-80 fk:overflow-y-auto",children:t.map(c=>jsx(j$1,{onSelect:()=>s(y,c),children:c.label},c.name))})]}):null,jsx(o$1,{}),jsx(j$1,{onSelect:()=>o(y),children:"Hide"}),jsx(j$1,{onSelect:()=>d(y),children:"Hide others"}),jsx(j$1,{onSelect:()=>S(y),children:n?"Unpin position":"Pin position"}),jsx(o$1,{}),jsx(j$1,{onSelect:()=>T(y),children:"Open record"})]})]})}var Ve={nodes:{},edges:{},counts:{},fetched:{},hiddenEntities:[],pinned:{},selected:null,notice:null,version:0};function Un(e,t){if(!t)return e;let n={...e};return Object.entries(t).forEach(([r,i])=>{n[r]={...n[r],...i};}),n}function Vn(e,t){if(!t)return e;let n={...e};return Object.entries(t).forEach(([r,i])=>{let s={...n[r]};Object.entries(i).forEach(([o,d])=>{s[o]=Math.max(s[o]??0,d);}),n[r]=s;}),n}function ln(e,t){let n=Object.fromEntries(Object.entries(e.nodes).filter(([s])=>!t.has(s))),r=Object.fromEntries(Object.entries(e.edges).filter(([,s])=>!t.has(s.source)&&!t.has(s.target))),i=Object.fromEntries(Object.entries(e.pinned).filter(([s])=>!t.has(s)));return {...e,nodes:n,edges:r,pinned:i,selected:e.selected&&t.has(e.selected)?null:e.selected,version:e.version+1}}function un(e,t){switch(t.type){case "merge":{let n={...e.nodes},r=Object.keys(n).length,i=0;t.data.nodes.forEach(o=>{let d=n[o.key];if(d){d.label===d.id&&o.label!==o.id&&(n[o.key]={...d,label:o.label});return}if(r>=c$4){i+=1;return}n[o.key]=o,r+=1;});let s={...e.edges};return t.data.edges.forEach(o=>{n[o.source]&&n[o.target]&&(s[o.key]=o);}),{...e,nodes:n,edges:s,counts:Un(e.counts,t.data.counts),fetched:Vn(e.fetched,t.fetched),notice:i>0?`The canvas holds ${c$4.toLocaleString()} nodes at most; ${i.toLocaleString()} were left out. Hide some nodes to make room.`:e.notice,version:e.version+1}}case "remove":return ln(e,new Set(t.keys));case "keepOnly":{let n=new Set(t.keys);return ln(e,new Set(Object.keys(e.nodes).filter(r=>!n.has(r))))}case "clear":return {...Ve,hiddenEntities:e.hiddenEntities,version:e.version+1};case "toggleEntity":return {...e,hiddenEntities:e.hiddenEntities.includes(t.entity)?e.hiddenEntities.filter(n=>n!==t.entity):[...e.hiddenEntities,t.entity]};case "select":return e.selected===t.key?e:{...e,selected:t.key};case "togglePin":{let n={...e.pinned};return n[t.key]?delete n[t.key]:n[t.key]=true,{...e,pinned:n}}case "notice":return {...e,notice:t.message};default:return e}}function cn(e){return Object.values(e.nodes).reduce((t,n)=>(t[n.entity]=(t[n.entity]??0)+1,t),{})}function dn(e,t){return Object.values(e.edges).reduce((n,r)=>(r.source===t?n[r.sourceAttribute]=(n[r.sourceAttribute]??0)+1:r.target===t&&(n[r.targetAttribute]=(n[r.targetAttribute]??0)+1),n),{})}function fn(e,t){return Object.values(e.edges).flatMap(n=>n.source===t?[n.target]:n.target===t?[n.source]:[])}function or(e){let[t,n,r]=[1,3,5].map(s=>{let o=parseInt(e.slice(s,s+2),16)/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4});return .2126*t+.7152*n+.0722*r>.3?"#0a0a0a":"#ffffff"}function gn({node:e,schema:t,scope:n$1,scene:r,colors:i,isLoading:s,onClose:o,onOpenRecord:d,onExpandAll:S,onExpandAttribute:T,onHide:y}){let c=g$1(t,e.entity),a=useMemo(()=>gql(c?p({entity:c,scope:n$1}):"query GraphDetails { __typename }"),[c,n$1]),h$1=useMemo(()=>gql(c?n({entity:c}):"query GraphCounts { __typename }"),[c]),g=useQuery(a,{variables:{id:e.id},skip:!c}),N=useQuery(h$1,{variables:{id:e.id},skip:!c}),f=c?g.data?.[c.plural]?.[0]:void 0,u=c?N.data?.[c.plural]?.[0]:void 0,l=useMemo(()=>dn(r,e.key),[r,e.key]),p$1=c?e$2(c):[],M=c?o$2(c):[],w=f?._updatedAt?new Date(f._updatedAt):null,F=i[e.entity]??"#71717a";return jsxs("aside",{"aria-label":"Selected record",className:"fk:flex fk:w-72 fk:shrink-0 fk:flex-col fk:gap-5 fk:overflow-y-auto fk:border-l fk:bg-background fk:p-4 fk:text-sm","data-testid":"graph-inspector",children:[jsxs("div",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-2",children:[jsx("span",{className:"fk:inline-flex fk:items-center fk:rounded-full fk:px-2 fk:py-0.5 fk:text-xs fk:font-medium",style:{backgroundColor:F,color:or(F)},children:c?h(c):e.entity}),jsx(b$3,{"aria-label":"Close",className:"fk:size-7",onClick:o,size:"icon",variant:"ghost",children:jsx(XIcon,{className:"fk:size-4"})})]}),jsx("h2",{className:"fk:text-base fk:font-semibold fk:leading-snug fk:break-words",children:e.label}),jsxs("div",{className:"fk:flex fk:gap-1.5",children:[jsxs(b$3,{onClick:()=>d(e.key),size:"xs",children:[jsx(SquareArrowOutUpRightIcon,{}),"Open record"]}),jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsxs(b$3,{"aria-label":"Expand every relationship",disabled:s,onClick:()=>S(e.key),size:"xs",variant:"outline",children:[s?jsx(LoaderCircleIcon,{className:"fk:animate-spin"}):jsx(ExpandIcon,{}),"Expand"]})}),jsx(e$1,{children:"Load the first related records of every relationship"})]}),jsxs(b$3,{"aria-label":"Hide this node",onClick:()=>y(e.key),size:"xs",variant:"outline",children:[jsx(EyeOffIcon,{}),"Hide"]})]})]}),jsxs("section",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx("h3",{className:"fk:text-xs fk:font-medium fk:text-muted-foreground",children:"Attributes"}),g.loading&&!f?jsx("span",{className:"fk:text-muted-foreground",children:"Loading\u2026"}):jsxs("dl",{className:"fk:grid fk:grid-cols-[minmax(0,2fr)_minmax(0,3fr)] fk:gap-x-3 fk:gap-y-1.5",children:[M.map(D=>jsxs("div",{className:"fk:contents",children:[jsx("dt",{className:"fk:truncate fk:text-muted-foreground",title:D.label,children:D.label}),jsx("dd",{className:"fk:min-w-0 fk:break-words",children:f&&s$2(f[D.name],n$1)||"\u2014"})]},D.name)),w?jsxs("div",{className:"fk:contents",children:[jsx("dt",{className:"fk:text-muted-foreground",children:"Updated"}),jsx("dd",{children:formatDistance(w,new Date,{addSuffix:true})})]}):null]})]}),p$1.length>0?jsxs("section",{className:"fk:flex fk:flex-col fk:gap-1",children:[jsx("h3",{className:"fk:mb-1 fk:text-xs fk:font-medium fk:text-muted-foreground",children:"Relationships"}),p$1.map(D=>{let E=g$1(t,D.relationship?.entity??""),P=u?.[`${D.name}Connection`]?.aggregate?.count?.nodes,$=l[D.name]??0,m=r.fetched[e.key]?.[D.name]??0,x=typeof P=="number"&&m>=P;return jsxs("div",{className:"fk:flex fk:h-8 fk:items-center fk:gap-2",children:[jsx("span",{"aria-hidden":"true",className:"fk:size-2 fk:shrink-0 fk:rounded-full",style:{backgroundColor:i[D.relationship?.entity??""]??"#71717a"}}),jsx("span",{className:"fk:min-w-0 fk:flex-1 fk:truncate",title:E?h(E):void 0,children:D.label}),jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:typeof P=="number"?`${$} of ${P.toLocaleString()}`:$}),P===0||x?null:jsx(b$3,{className:"fk:h-6 fk:px-2 fk:text-xs",disabled:s,onClick:()=>T(e.key,D),size:"xs",variant:"outline",children:m>0?"More":"Expand"})]},D.name)})]}):null]})}var kn=EditorView.theme({"&":{fontSize:"13px",height:"100%",minHeight:"0"},"&.cm-focused":{outline:"none"},".cm-scroller":{height:"100%",lineHeight:"1.6",minHeight:"0",overflow:"auto"},".cm-content":{fontSize:"13px",padding:"12px 0"},".cm-gutters":{borderRight:"1px solid transparent"}});function yn({ariaLabel:e,schema:t,theme:n,value:r,onChange:i,onRun:s}){let o=useRef(null),d=useRef(null),S=useRef(new Compartment),T=useRef(i),y=useRef(s),c=useRef(r);return T.current=i,y.current=s,c.current=r,useEffect(()=>{let a=o.current;if(!a)return;let h=new EditorView({parent:a,state:EditorState.create({doc:c.current,extensions:[lineNumbers(),highlightActiveLineGutter(),highlightSpecialChars(),history(),foldGutter(),drawSelection(),dropCursor(),indentOnInput(),bracketMatching(),closeBrackets(),highlightActiveLine(),Prec.highest(keymap.of([{key:"Mod-Enter",run:()=>(y.current(),true)}])),keymap.of([...closeBracketsKeymap,...defaultKeymap,...historyKeymap,...foldKeymap,indentWithTab]),graphql(void 0,{showErrorOnInvalidSchema:false}),EditorView.updateListener.of(g=>{g.docChanged&&T.current(g.state.doc.toString());}),EditorView.contentAttributes.of({"aria-label":e,"aria-multiline":"true",role:"textbox"}),placeholder(`query {
1
+ import'./index.css';import {b as b$4,c as c$3}from'./chunk-ELOJGLAR.js';import {a as a$3,b as b$5}from'./chunk-MLHXPTBT.js';import {e}from'./chunk-L3GBAK54.js';import {a as a$1}from'./chunk-3IUKXOKF.js';import {f as f$1,i,g as g$1,y,k,b as b$1,e as e$2,l,w,v,d,a,m,h,p,n,o as o$2,s as s$2,c as c$4,q as q$1,r as r$1,j as j$2,u,t}from'./chunk-4PUMSUJL.js';import {c as c$1}from'./chunk-2DXR5NJV.js';import {j,f as f$2}from'./chunk-AKW7EKYI.js';import {c}from'./chunk-XMOSCJOI.js';import'./chunk-HKN6BX5U.js';import'./chunk-YDVO6XWD.js';import {a as a$2}from'./chunk-ERDARDGB.js';import {f}from'./chunk-NSVX6HEN.js';import {g}from'./chunk-WPCPL2TQ.js';import'./chunk-5CVDMZUI.js';import {K,M,Q,O,qa,N,R,S,s,T,V,W,X,o,P,ha,ia,ja,ka,e as e$4,$,aa,da,ea,ba,fa}from'./chunk-DGIY4SKN.js';import {e as e$3,g as g$2,h as h$1,j as j$1,q,r,s as s$1,o as o$1}from'./chunk-SZEGGBOC.js';import {v as v$1}from'./chunk-32ZU4MLE.js';import {b}from'./chunk-U45E5X3H.js';import'./chunk-HDOIOXMP.js';import {b as b$2,c as c$2,e as e$1}from'./chunk-USNXQOMJ.js';import {b as b$3}from'./chunk-6NRQMG26.js';import'./chunk-O2QMYUPS.js';import {useEffect,useMemo,useRef,useState,useCallback,useReducer}from'react';import {useLocation}from'react-router-dom';import On from'graphology';import qn from'graphology-layout-forceatlas2';import Qn from'graphology-layout-forceatlas2/worker';import zn,{DEFAULT_STYLES}from'sigma';import {jsxs,jsx}from'react/jsx-runtime';import {gql}from'@apollo/client';import {useApolloClient,useQuery}from'@apollo/client/react';import {formatDistance}from'date-fns';import {SearchIcon,ChevronDownIcon,LoaderCircleIcon,PlayIcon,ScanIcon,ExpandIcon,EyeOffIcon,EraserIcon,XIcon,SquareArrowOutUpRightIcon}from'lucide-react';import {closeBrackets,closeBracketsKeymap}from'@codemirror/autocomplete';import {history,defaultKeymap,historyKeymap,indentWithTab}from'@codemirror/commands';import {foldGutter,indentOnInput,bracketMatching,foldKeymap}from'@codemirror/language';import {Compartment,EditorState,Prec}from'@codemirror/state';import {EditorView,lineNumbers,highlightActiveLineGutter,highlightSpecialChars,drawSelection,dropCursor,highlightActiveLine,keymap,placeholder}from'@codemirror/view';import {graphql,updateSchema}from'cm6-graphql';import {getIntrospectionQuery,buildClientSchema}from'graphql';import {useDebounce}from'use-debounce';function Ae(e){return Math.min(2e4,2e3+e*9)}function Zt({mean:e,max:t,diagonal:n}){let r=Math.max(.05,n*.0015);return e<r&&t<r*20}var Hn=40,jn=400,Bn=1200,Xn=2;function Fn(e){return 5+Math.min(10,Math.sqrt(e)*2)}function nn(e){return Hn*(.8+Math.sqrt(e)*.6)}function rn(e,t,n){let r=Math.random()*Math.PI*2;return Array.from({length:t},(i,s)=>{let o=r+s/t*Math.PI*2+Math.random()*.3,d=n*(.9+Math.random()*.2);return {x:e.x+Math.cos(o)*d,y:e.y+Math.sin(o)*d}})}function on(e,t){return !Number.isNaN(e.getNodeAttribute(t,"x"))}function $n(e,t){if(t.length===0)return {center:{x:0,y:0},reach:0};let n=t.reduce((i,s)=>({x:i.x+e.getNodeAttribute(s,"x"),y:i.y+e.getNodeAttribute(s,"y")}),{x:0,y:0});n.x/=t.length,n.y/=t.length;let r=t.reduce((i,s)=>Math.max(i,Math.hypot(e.getNodeAttribute(s,"x")-n.x,e.getNodeAttribute(s,"y")-n.y)),0);return {center:n,reach:r}}function Jn(e,t){let n=new Map;t.forEach(r=>{let i=e.neighbors(r).find(s=>!t.has(s)&&on(e,s))??null;n.set(i,[...n.get(i)??[],r]);}),n.forEach((r,i)=>{let s;if(i){let o={x:e.getNodeAttribute(i,"x"),y:e.getNodeAttribute(i,"y")};s=rn(o,r.length,nn(r.length));}else {let o=e.nodes().filter(S=>!t.has(S)&&on(e,S)),d=$n(e,o);s=rn(d.center,r.length,d.reach+nn(r.length));}s.forEach((o,d)=>e.mergeNodeAttributes(r[d],o));});}var Ke=class{constructor(t){this.graph=t;this.positions=new Float64Array(t.order*2);let n=0;this.graph.forEachNode((r,i)=>{this.positions[n]=i.x,this.positions[n+1]=i.y,n+=2;});}positions;measure(){let{graph:t,positions:n}=this,r=0,i=0,s=0,o=Number.POSITIVE_INFINITY,d=Number.POSITIVE_INFINITY,S=Number.NEGATIVE_INFINITY,T=Number.NEGATIVE_INFINITY,y=0;return t.forEachNode((c,a)=>{let{x:h,y:g}=a;if(y+1<n.length&&!a.fixed){let N=Math.hypot(h-n[y],g-n[y+1]);r+=N,i=Math.max(i,N),s+=1;}n[y]=h,n[y+1]=g,y+=2,o=Math.min(o,h),d=Math.min(d,g),S=Math.max(S,h),T=Math.max(T,g);}),{mean:s>0?r/s:0,max:i,diagonal:t.order>0?Math.hypot(S-o,T-d):0}}};function Yn(e,t,n){let r=false,i=new Set,s=e.order>0;return e.forEachNode(o=>{t.nodes[o]||(e.dropNode(o),r=true);}),Object.values(t.nodes).forEach(o=>{if(e.hasNode(o.key)){e.getNodeAttribute(o.key,"label")!==o.label&&e.setNodeAttribute(o.key,"label",o.label);return}e.addNode(o.key,{entity:o.entity,label:o.label,color:n[o.entity]??"#71717a",size:5,x:Number.NaN,y:Number.NaN}),i.add(o.key),r=true;}),e.forEachEdge(o=>{t.edges[o]||(e.dropEdge(o),r=true);}),Object.values(t.edges).forEach(o=>{e.hasEdge(o.key)||(e.addEdgeWithKey(o.key,o.source,o.target,{size:1}),r=true);}),Jn(e,i),r&&e.forEachNode(o=>{e.setNodeAttribute(o,"size",Fn(e.degree(o)));}),{changed:r,added:i,hadNodes:s}}function sn({scene:e,colors:t,theme:n,apiRef:r,onSelect:i,onContextMenu:s,onExpand:o,onPin:d,onLayoutChange:S}){let T=useRef(null),y=useRef(null),c=useRef(null),a=useRef(null),h=useRef(null),g=useRef(null),N=useRef(null),f=useRef(null),u=useRef(null),l=useRef(new Set),p=useRef(e.pinned);p.current=e.pinned;let M=useRef({key:null,nodes:[]}),w=useRef({onSelect:i,onContextMenu:s,onExpand:o,onPin:d,onLayoutChange:S}),[F,D]=useState(0);w.current={onSelect:i,onContextMenu:s,onExpand:o,onPin:d,onLayoutChange:S},y.current||(y.current=new On({type:"undirected",multi:true}));let E=useCallback(()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null),f.current!==null&&(window.clearInterval(f.current),f.current=null),a.current&&(a.current.kill(),a.current=null,u.current=null,w.current.onLayoutChange(false));let m=y.current;l.current.forEach(x=>{m?.hasNode(x)&&m.setNodeAttribute(x,"fixed",p.current[x]===true);}),l.current=new Set;},[]),P=useCallback((m,x=[])=>{let v=y.current;if(E(),!v||v.order===0)return;if(l.current=new Set(x.filter(C=>v.hasNode(C))),l.current.forEach(C=>v.setNodeAttribute(C,"fixed",true)),!v.someNode((C,L)=>!L.fixed)){E();return}let A=qn.inferSettings(v),G=new Qn(v,{settings:{...A,adjustSizes:true,gravity:.2,slowDown:(A.slowDown??1)*2},outputReducer:(C,L)=>{let oe=g.current;return oe&&oe.node===C&&(L.x=oe.x,L.y=oe.y),L}}),q=performance.now(),Y=new Ke(v),V=false,K=0;a.current=G,u.current=q+m,G.start(),w.current.onLayoutChange(true);let k=()=>{g.current?(u.current=performance.now()+m,h.current=window.setTimeout(k,m)):E();};h.current=window.setTimeout(k,m),f.current=window.setInterval(()=>{let C=Y.measure();if(g.current){K=0;return}V=V||C.max>0,K=V&&Zt(C)?K+1:0,K>=Xn&&performance.now()-q>=Bn&&E();},jn);},[E]),$=useCallback(m=>{let x=y.current,v=c.current;if(!x||!v)return;let A=M.current;if(v.setNodesState(A.nodes.filter(G=>x.hasNode(G)),{isNeighbour:false}),m&&x.hasNode(m)){let G=x.neighbors(m);v.setNodesState(G,{isNeighbour:true}),M.current={key:m,nodes:G};}else M.current={key:null,nodes:[]};},[]);return useEffect(()=>{let m=T.current,x=y.current;if(!m||!x)return;if(m.clientWidth===0||m.clientHeight===0){let k=new ResizeObserver(()=>{m.clientWidth>0&&m.clientHeight>0&&(k.disconnect(),D(C=>C+1));});return k.observe(m),()=>k.disconnect()}let v=n==="dark",A=new zn(x,m,{customNodeState:{isNeighbour:false},customEdgeState:{},customGraphState:{isDense:x.order>300,isZoomedIn:false},settings:{allowInvalidContainer:true,itemSizesReference:"screen",enableNodeDrag:true,renderEdgeLabels:false,labelRenderedSizeThreshold:7,labelDensity:.1,labelGridCellSize:80},styles:{nodes:[{...DEFAULT_STYLES.nodes,size:{whenState:"isHighlighted",then:k=>k.size+5,else:{whenState:"isHovered",then:k=>k.size+2,else:{attribute:"size"}}},cursor:"pointer",labelColor:v?"#e4e4e7":"#18181b",labelSize:12,labelFont:"ui-sans-serif, system-ui, sans-serif",labelVisibility:(k,C,L)=>C.isHovered||C.isHighlighted?"visible":L.isDense&&!L.isZoomedIn&&!C.isNeighbour?"hidden":"auto",backdropColor:v?"#27272a":"#ffffff",backdropShadowColor:v?"rgba(0, 0, 0, 0.6)":"rgba(0, 0, 0, 0.25)"}],edges:[{...DEFAULT_STYLES.edges,color:v?"#3f3f46":"#d4d4d8",size:1}]}});c.current=A,A.on("clickNode",({node:k})=>{w.current.onSelect(k);}),A.on("clickStage",()=>{w.current.onSelect(null);}),A.on("doubleClickNode",({node:k,event:C})=>{C.preventSigmaDefault(),w.current.onExpand(k);}),A.on("rightClickNode",({node:k,event:C})=>{C.preventSigmaDefault();let L=C.original;L.preventDefault(),w.current.onSelect(k),w.current.onContextMenu(k,{x:L.clientX,y:L.clientY});}),A.on("enterNode",({node:k})=>$(k)),A.on("leaveNode",()=>$(null));let G=k=>{let C=new Set([k,...x.neighbors(k)]);return x.nodes().filter(L=>L===k||!C.has(L))};A.on("nodeDragStart",({node:k})=>{g.current={node:k,x:x.getNodeAttribute(k,"x"),y:x.getNodeAttribute(k,"y")},x.size>0?(P(Ae(x.order),G(k)),N.current=a.current):(E(),x.setNodeAttribute(k,"fixed",true));}),A.on("nodeDrag",({node:k})=>{g.current?.node===k&&(g.current.x=x.getNodeAttribute(k,"x"),g.current.y=x.getNodeAttribute(k,"y"));}),A.on("nodeDragEnd",({node:k})=>{let C=g.current!==null&&a.current!==null&&a.current===N.current;g.current=null,N.current=null,w.current.onPin(k),C&&P(Ae(x.order),G(k));});let q=A.getCamera(),Y=({ratio:k})=>{let C=k<.45;A.getGraphState().isZoomedIn!==C&&A.setGraphState({isZoomedIn:C});};q.on("updated",Y);let V=k=>k.preventDefault();m.addEventListener("contextmenu",V);let K=new ResizeObserver(()=>{m.clientWidth>0&&m.clientHeight>0&&(A.resize(),A.scheduleRefresh());});return K.observe(m),r.current={fit:()=>{q.reset({duration:300});}},()=>{K.disconnect(),q.off("updated",Y),m.removeEventListener("contextmenu",V),r.current=null,c.current=null,M.current={key:null,nodes:[]},A.kill();}},[n,F,r,P,E,$]),useEffect(()=>{let m=y.current;if(!m)return;E();let{changed:x,added:v,hadNodes:A}=Yn(m,e,t);if(!x)return;if(c.current?.setGraphState({isDense:m.order>300}),$(m.hasNode(M.current.key??"")?M.current.key:null),m.size===0){E();return}let G=A&&v.size>0?m.nodes().filter(q=>!v.has(q)):[];P(Ae(G.length>0?v.size:m.order),G);},[e.version]),useEffect(()=>{let m=y.current;m&&m.forEachNode((x,v)=>{m.setNodeAttribute(x,"color",t[v.entity]??"#71717a");});},[t]),useEffect(()=>{let m=y.current,x=c.current;if(!m||!x)return;let v=new Set(e.hiddenEntities),A=false;m.forEachNode((G,q)=>{x.setNodeState(G,{isHidden:v.has(q.entity),isHighlighted:G===e.selected});let Y=e.pinned[G]===true||l.current.has(G);(q.fixed??false)!==Y&&(m.setNodeAttribute(G,"fixed",Y),A=true);}),A&&u.current!==null&&P(Math.max(500,u.current-performance.now()),[...l.current]),m.forEachEdge((G,q,Y,V)=>{x.setEdgeState(G,{isHidden:v.has(m.getNodeAttribute(Y,"entity"))||v.has(m.getNodeAttribute(V,"entity"))});});},[e.hiddenEntities,e.selected,e.pinned,e.version,F,n,P]),useEffect(()=>E,[E]),jsx("div",{className:"fk:h-full fk:w-full fk:min-h-0",ref:T})}function an({menu:e,relationships:t,isPinned:n,onClose:r$1,onExpandAll:i,onExpandAttribute:s,onHide:o,onHideOthers:d,onTogglePin:S,onOpenRecord:T}){let y=e?.key??"";return jsxs(e$3,{onOpenChange:c=>{c||r$1();},open:e!==null,children:[jsx(g$2,{asChild:true,children:jsx("span",{"aria-hidden":"true",className:"fk:fixed fk:size-0",style:{left:e?.x??0,top:e?.y??0}})}),jsxs(h$1,{align:"start",className:"fk:w-52","data-testid":"graph-context-menu",side:"bottom",children:[jsx(j$1,{onSelect:()=>i(y),children:"Expand all"}),t.length>0?jsxs(q,{children:[jsx(r,{children:"Expand"}),jsx(s$1,{className:"fk:max-h-80 fk:overflow-y-auto",children:t.map(c=>jsx(j$1,{onSelect:()=>s(y,c),children:c.label},c.name))})]}):null,jsx(o$1,{}),jsx(j$1,{onSelect:()=>o(y),children:"Hide"}),jsx(j$1,{onSelect:()=>d(y),children:"Hide others"}),jsx(j$1,{onSelect:()=>S(y),children:n?"Unpin position":"Pin position"}),jsx(o$1,{}),jsx(j$1,{onSelect:()=>T(y),children:"Open record"})]})]})}var Ve={nodes:{},edges:{},counts:{},fetched:{},hiddenEntities:[],pinned:{},selected:null,notice:null,version:0};function Un(e,t){if(!t)return e;let n={...e};return Object.entries(t).forEach(([r,i])=>{n[r]={...n[r],...i};}),n}function Vn(e,t){if(!t)return e;let n={...e};return Object.entries(t).forEach(([r,i])=>{let s={...n[r]};Object.entries(i).forEach(([o,d])=>{s[o]=Math.max(s[o]??0,d);}),n[r]=s;}),n}function ln(e,t){let n=Object.fromEntries(Object.entries(e.nodes).filter(([s])=>!t.has(s))),r=Object.fromEntries(Object.entries(e.edges).filter(([,s])=>!t.has(s.source)&&!t.has(s.target))),i=Object.fromEntries(Object.entries(e.pinned).filter(([s])=>!t.has(s)));return {...e,nodes:n,edges:r,pinned:i,selected:e.selected&&t.has(e.selected)?null:e.selected,version:e.version+1}}function un(e,t){switch(t.type){case "merge":{let n={...e.nodes},r=Object.keys(n).length,i=0;t.data.nodes.forEach(o=>{let d=n[o.key];if(d){d.label===d.id&&o.label!==o.id&&(n[o.key]={...d,label:o.label});return}if(r>=c$4){i+=1;return}n[o.key]=o,r+=1;});let s={...e.edges};return t.data.edges.forEach(o=>{n[o.source]&&n[o.target]&&(s[o.key]=o);}),{...e,nodes:n,edges:s,counts:Un(e.counts,t.data.counts),fetched:Vn(e.fetched,t.fetched),notice:i>0?`The canvas holds ${c$4.toLocaleString()} nodes at most; ${i.toLocaleString()} were left out. Hide some nodes to make room.`:e.notice,version:e.version+1}}case "remove":return ln(e,new Set(t.keys));case "keepOnly":{let n=new Set(t.keys);return ln(e,new Set(Object.keys(e.nodes).filter(r=>!n.has(r))))}case "clear":return {...Ve,hiddenEntities:e.hiddenEntities,version:e.version+1};case "toggleEntity":return {...e,hiddenEntities:e.hiddenEntities.includes(t.entity)?e.hiddenEntities.filter(n=>n!==t.entity):[...e.hiddenEntities,t.entity]};case "select":return e.selected===t.key?e:{...e,selected:t.key};case "togglePin":{let n={...e.pinned};return n[t.key]?delete n[t.key]:n[t.key]=true,{...e,pinned:n}}case "notice":return {...e,notice:t.message};default:return e}}function cn(e){return Object.values(e.nodes).reduce((t,n)=>(t[n.entity]=(t[n.entity]??0)+1,t),{})}function dn(e,t){return Object.values(e.edges).reduce((n,r)=>(r.source===t?n[r.sourceAttribute]=(n[r.sourceAttribute]??0)+1:r.target===t&&(n[r.targetAttribute]=(n[r.targetAttribute]??0)+1),n),{})}function fn(e,t){return Object.values(e.edges).flatMap(n=>n.source===t?[n.target]:n.target===t?[n.source]:[])}function or(e){let[t,n,r]=[1,3,5].map(s=>{let o=parseInt(e.slice(s,s+2),16)/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4});return .2126*t+.7152*n+.0722*r>.3?"#0a0a0a":"#ffffff"}function gn({node:e,schema:t,scope:n$1,scene:r,colors:i,isLoading:s,onClose:o,onOpenRecord:d,onExpandAll:S,onExpandAttribute:T,onHide:y}){let c=g$1(t,e.entity),a=useMemo(()=>gql(c?p({entity:c,scope:n$1}):"query GraphDetails { __typename }"),[c,n$1]),h$1=useMemo(()=>gql(c?n({entity:c}):"query GraphCounts { __typename }"),[c]),g=useQuery(a,{variables:{id:e.id},skip:!c}),N=useQuery(h$1,{variables:{id:e.id},skip:!c}),f=c?g.data?.[c.plural]?.[0]:void 0,u=c?N.data?.[c.plural]?.[0]:void 0,l=useMemo(()=>dn(r,e.key),[r,e.key]),p$1=c?e$2(c):[],M=c?o$2(c):[],w=f?._updatedAt?new Date(f._updatedAt):null,F=i[e.entity]??"#71717a";return jsxs("aside",{"aria-label":"Selected record",className:"fk:flex fk:w-72 fk:shrink-0 fk:flex-col fk:gap-5 fk:overflow-y-auto fk:border-l fk:bg-background fk:p-4 fk:text-sm","data-testid":"graph-inspector",children:[jsxs("div",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsxs("div",{className:"fk:flex fk:items-center fk:justify-between fk:gap-2",children:[jsx("span",{className:"fk:inline-flex fk:items-center fk:rounded-full fk:px-2 fk:py-0.5 fk:text-xs fk:font-medium",style:{backgroundColor:F,color:or(F)},children:c?h(c):e.entity}),jsx(b$3,{"aria-label":"Close",className:"fk:size-7",onClick:o,size:"icon",variant:"ghost",children:jsx(XIcon,{className:"fk:size-4"})})]}),jsx("h2",{className:"fk:text-base fk:font-semibold fk:leading-snug fk:break-words",children:e.label}),jsxs("div",{className:"fk:flex fk:gap-1.5",children:[jsxs(b$3,{onClick:()=>d(e.key),size:"xs",children:[jsx(SquareArrowOutUpRightIcon,{}),"Open record"]}),jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsxs(b$3,{"aria-label":"Expand every relationship",disabled:s,onClick:()=>S(e.key),size:"xs",variant:"outline",children:[s?jsx(LoaderCircleIcon,{className:"fk:animate-spin"}):jsx(ExpandIcon,{}),"Expand"]})}),jsx(e$1,{children:"Load the first related records of every relationship"})]}),jsxs(b$3,{"aria-label":"Hide this node",onClick:()=>y(e.key),size:"xs",variant:"outline",children:[jsx(EyeOffIcon,{}),"Hide"]})]})]}),jsxs("section",{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx("h3",{className:"fk:text-xs fk:font-medium fk:text-muted-foreground",children:"Attributes"}),g.loading&&!f?jsx("span",{className:"fk:text-muted-foreground",children:"Loading\u2026"}):jsxs("dl",{className:"fk:grid fk:grid-cols-[minmax(0,2fr)_minmax(0,3fr)] fk:gap-x-3 fk:gap-y-1.5",children:[M.map(D=>jsxs("div",{className:"fk:contents",children:[jsx("dt",{className:"fk:truncate fk:text-muted-foreground",title:D.label,children:D.label}),jsx("dd",{className:"fk:min-w-0 fk:break-words",children:f&&s$2(f[D.name],n$1)||"\u2014"})]},D.name)),w?jsxs("div",{className:"fk:contents",children:[jsx("dt",{className:"fk:text-muted-foreground",children:"Updated"}),jsx("dd",{children:formatDistance(w,new Date,{addSuffix:true})})]}):null]})]}),p$1.length>0?jsxs("section",{className:"fk:flex fk:flex-col fk:gap-1",children:[jsx("h3",{className:"fk:mb-1 fk:text-xs fk:font-medium fk:text-muted-foreground",children:"Relationships"}),p$1.map(D=>{let E=g$1(t,D.relationship?.entity??""),P=u?.[`${D.name}Connection`]?.aggregate?.count?.nodes,$=l[D.name]??0,m=r.fetched[e.key]?.[D.name]??0,x=typeof P=="number"&&m>=P;return jsxs("div",{className:"fk:flex fk:h-8 fk:items-center fk:gap-2",children:[jsx("span",{"aria-hidden":"true",className:"fk:size-2 fk:shrink-0 fk:rounded-full",style:{backgroundColor:i[D.relationship?.entity??""]??"#71717a"}}),jsx("span",{className:"fk:min-w-0 fk:flex-1 fk:truncate",title:E?h(E):void 0,children:D.label}),jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:typeof P=="number"?`${$} of ${P.toLocaleString()}`:$}),P===0||x?null:jsx(b$3,{className:"fk:h-6 fk:px-2 fk:text-xs",disabled:s,onClick:()=>T(e.key,D),size:"xs",variant:"outline",children:m>0?"More":"Expand"})]},D.name)})]}):null]})}var kn=EditorView.theme({"&":{fontSize:"13px",height:"100%",minHeight:"0"},"&.cm-focused":{outline:"none"},".cm-scroller":{height:"100%",lineHeight:"1.6",minHeight:"0",overflow:"auto"},".cm-content":{fontSize:"13px",padding:"12px 0"},".cm-gutters":{borderRight:"1px solid transparent"}});function yn({ariaLabel:e,schema:t,theme:n,value:r,onChange:i,onRun:s}){let o=useRef(null),d=useRef(null),S=useRef(new Compartment),T=useRef(i),y=useRef(s),c=useRef(r);return T.current=i,y.current=s,c.current=r,useEffect(()=>{let a=o.current;if(!a)return;let h=new EditorView({parent:a,state:EditorState.create({doc:c.current,extensions:[lineNumbers(),highlightActiveLineGutter(),highlightSpecialChars(),history(),foldGutter(),drawSelection(),dropCursor(),indentOnInput(),bracketMatching(),closeBrackets(),highlightActiveLine(),Prec.highest(keymap.of([{key:"Mod-Enter",run:()=>(y.current(),true)}])),keymap.of([...closeBracketsKeymap,...defaultKeymap,...historyKeymap,...foldKeymap,indentWithTab]),graphql(void 0,{showErrorOnInvalidSchema:false}),EditorView.updateListener.of(g=>{g.docChanged&&T.current(g.state.doc.toString());}),EditorView.contentAttributes.of({"aria-label":e,"aria-multiline":"true",role:"textbox"}),placeholder(`query {
2
2
  \u2026
3
3
  }`),S.current.of([n==="dark"?a$3:b$5,kn])]})});return d.current=h,()=>{h.destroy(),d.current=null;}},[]),useEffect(()=>{d.current?.dispatch({effects:S.current.reconfigure([n==="dark"?a$3:b$5,kn])});},[n]),useEffect(()=>{d.current&&updateSchema(d.current,t??void 0);},[t]),useEffect(()=>{let a=d.current;!a||a.state.doc.toString()===r||a.dispatch({changes:{from:0,to:a.state.doc.length,insert:r}});},[r]),jsx("div",{className:"fk:h-full fk:min-h-0 fk:w-full","data-testid":"graph-query-editor",ref:o})}var Me=200,Rr=5,Tr=3;function bn(e){return typeof e=="object"&&e!==null&&typeof e._id=="string"}function me(e){if(Array.isArray(e))return e.flatMap(me);if(typeof e!="object"||e===null)return [];if(bn(e))return [e];let{edges:t}=e;return Array.isArray(t)?t.flatMap(n=>me(n?.node)):[]}function Mr(e,t){let n=e.endsWith("Connection")?e.slice(0,-10):e;return t.find(r=>r.plural===n)}function Gr(e,t){let n=e.endsWith("Connection")?e.slice(0,-10):e;return e$2(t).find(r=>r.name===n)}function Lr(e,t){let n=e$2(e).filter(r=>r.relationship?.entity===t);return n.length===1?n[0]:void 0}function Dr(e,t,n){let r=e.__typename;return typeof r=="string"&&g$1(n,r)||t}function Ir(e,t$1,n){let r=t(e,t$1,n);if(r!==e._id)return r;let i=Object.entries(e).find(([s,o])=>!s.startsWith("_")&&typeof o=="string"&&o.trim().length>0);return i?i[1]:e._id}function xn({data:e,schema:t,scope:n}){let r=new Map,i=new Map,s=(o,d$1)=>{let S=Dr(o,d$1,t);if(!S)return null;let T=d(S.name,o._id),y=Ir(o,S,n),c=r.get(T),a=c??{key:T,entity:S.name,id:o._id,label:y};return c?c.label===c.id&&y!==o._id&&(c.label=y):r.set(T,a),Object.entries(o).forEach(([h,g])=>{let N=Gr(h,S),f=N?g$1(t,N.relationship?.entity??""):void 0;me(g).forEach(u$1=>{let l=s(u$1,f),p=N??(l?Lr(S,l.entity):void 0);if(l&&p&&l.key!==a.key){let M=u(a,l,p);i.has(M.key)||i.set(M.key,M);}});}),a};return Object.entries(e??{}).forEach(([o,d])=>{let S=Mr(o,t);me(d).forEach(T=>s(T,S));}),{nodes:[...r.values()],edges:[...i.values()],counts:{}}}function Sn(e,t){return f$1(e).map(n=>{let r=e$2(n).slice(0,Tr).map(s=>{let o=g$1(e,s.relationship?.entity??"");return ` ${s.name}(limit: ${Rr}) {
4
4
  _id
@@ -10,5 +10,5 @@ ${i?` ${i}
10
10
  `:""}${r.join(`
11
11
  `)}
12
12
  }
13
- }`}})}function Pr(e,t){let n=me(e);return n.length>0?`${n.length} ${n.length===1?"record":"records"}`:Array.isArray(e)&&!(typeof e[0]=="object"&&e[0]!==null)?e.map(r=>s$2(r,t)).join(", "):s$2(e,t)}function Ze(e){if(Array.isArray(e))return e.flatMap(Ze);if(typeof e!="object"||e===null)return [];let{edges:t}=e;return !bn(e)&&Array.isArray(t)?t.flatMap(n=>Ze(n?.node)):[e]}function En(e,t){let n=Object.values(e??{}).flatMap(Ze),r=n.slice(0,Me),i=[];return r.forEach(s=>{Object.keys(s).forEach(o=>{o!=="__typename"&&!i.includes(o)&&i.push(o);});}),{columns:i,rows:r.map(s=>Object.fromEntries(i.map(o=>[o,Pr(s[o],t)]))),total:n.length}}function Te(e){return Array.isArray(e)?e.map(Te):typeof e=="object"&&e!==null?Object.fromEntries(Object.entries(e).filter(([t])=>t!=="__typename").map(([t,n])=>[t,Te(n)])):e}function et(e){return `flexkit-graph:query:${e}`}var Ge=new Map;function jr(e,t,n){let r=Ge.get(t);if(r&&r.hash===n)return r.schema;let i=e.query({query:gql(getIntrospectionQuery()),fetchPolicy:"no-cache",context:f$2}).then(s=>{if(!s.data)throw new Error("The schema could not be introspected.");return buildClientSchema(s.data)});return i.catch(()=>{Ge.get(t)?.schema===i&&Ge.delete(t);}),Ge.set(t,{hash:n,schema:i}),i}function Nn(e,t){let n=useApolloClient(),[r,i]=useState(null);return useEffect(()=>{if(!e)return;let s=false;return jr(n,e,t??"").then(o=>{s||i(o);}).catch(()=>{}),()=>{s=true;}},[n,e,t]),r}function vn({projectId:e,schemaHash:t,schema:n,scope:r,theme:i,isRunning:s,hidden:o$1,onRun:d}){let[S,T]=useState(!o$1),y=Nn(S?e:void 0,t),c=useMemo(()=>Sn(n,r),[n,r]),[a,h]=useState(()=>b$4(et(e))||c[0]?.query||""),g=useRef(a!==""),[N,f]=useState(false),[u,l]=useState("graph"),[p,M]=useState(null),w=useMemo(()=>u==="table"&&p?.data?En(p.data,r):null,[u,p,r]),F=useMemo(()=>u==="json"&&p?.data?JSON.stringify(Te(p.data),null,2):null,[u,p]);useEffect(()=>{o$1||T(true);},[o$1]),useEffect(()=>{let[E]=c;!g.current&&E&&(g.current=true,h(P=>P||E.query));},[c]),useEffect(()=>{c$3(et(e),a);},[e,a]);let D=async()=>{!a.trim()||s||M(await d(a,{append:N}));};return jsxs("section",{"aria-label":"Query",className:`fk:w-[26rem] fk:shrink-0 fk:flex-col fk:border-r fk:bg-background ${o$1?"fk:hidden":"fk:flex"}`,"data-testid":"graph-query-pane",hidden:o$1,children:[jsxs("div",{className:"fk:flex fk:h-12 fk:shrink-0 fk:items-center fk:gap-2 fk:border-b fk:pl-4 fk:pr-3",children:[jsx("span",{className:"fk:text-sm fk:font-semibold",children:"Query"}),jsxs("div",{className:"fk:ml-auto fk:flex fk:items-center fk:gap-1.5",children:[c.length>0?jsxs(e$3,{children:[jsx(g$2,{asChild:true,children:jsxs(b$3,{className:"fk:h-8",size:"sm",variant:"outline",children:["Examples",jsx(ChevronDownIcon,{className:"fk:size-3.5"})]})}),jsx(h$1,{align:"end",className:"fk:max-h-80 fk:overflow-y-auto",children:c.map(E=>jsx(j$1,{onSelect:()=>h(E.query),children:E.title},E.entity))})]}):null,jsxs(b$3,{className:"fk:h-8",disabled:s||!a.trim(),onClick:()=>{D();},size:"sm",children:[s?jsx(LoaderCircleIcon,{className:"fk:size-3.5 fk:animate-spin"}):jsx(PlayIcon,{className:"fk:size-3.5"}),"Run"]})]})]}),jsx("div",{className:"fk:min-h-0 fk:flex-1",children:jsx(yn,{ariaLabel:"GraphQL query",onChange:h,onRun:()=>{D();},schema:y,theme:i,value:a})}),jsxs(ha,{className:"fk:flex fk:max-h-[45%] fk:shrink-0 fk:flex-col fk:gap-0 fk:border-t",onValueChange:E=>l(E),value:u,children:[jsxs("div",{className:"fk:flex fk:h-11 fk:shrink-0 fk:items-center fk:gap-3 fk:px-3",children:[jsxs(ia,{children:[jsx(ja,{value:"graph",children:"Graph"}),jsx(ja,{value:"table",children:"Table"}),jsx(ja,{value:"json",children:"JSON"})]}),jsx("span",{className:"fk:ml-auto fk:truncate fk:text-xs fk:text-muted-foreground","data-testid":"graph-query-stats",children:p&&!p.error?`${p.nodes.toLocaleString()} ${p.nodes===1?"node":"nodes"} \xB7 ${p.edges.toLocaleString()} ${p.edges===1?"relationship":"relationships"} \xB7 ${p.elapsedMs.toLocaleString()} ms`:null})]}),p?.error?jsx("pre",{className:"fk:m-3 fk:mt-0 fk:max-h-40 fk:shrink-0 fk:overflow-auto fk:whitespace-pre-wrap fk:rounded-md fk:border fk:border-destructive/40 fk:bg-destructive/5 fk:p-2 fk:text-xs fk:text-destructive","data-testid":"graph-query-error",children:p.error}):null,jsxs("div",{className:"fk:min-h-0 fk:overflow-auto",children:[jsxs(ka,{className:"fk:flex fk:flex-col fk:gap-3 fk:px-3 fk:pb-3 fk:text-xs fk:text-muted-foreground",value:"graph",children:[jsxs("span",{children:["Every object with an ",jsx("code",{className:"fk:font-mono",children:"_id"})," under an entity field becomes a node; a nested relationship selection becomes a line between them."]}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(o,{checked:N,id:"graph-query-append",onCheckedChange:E=>f(E===true)}),jsx(e$4,{className:"fk:text-xs fk:font-normal",htmlFor:"graph-query-append",children:"Add to the current canvas instead of replacing it"})]})]}),jsx(ka,{className:"fk:px-3 fk:pb-3",value:"table",children:w&&w.columns.length>0?jsxs("div",{className:"fk:flex fk:flex-col fk:gap-1",children:[jsx("div",{className:"fk:overflow-x-auto fk:rounded-md fk:border",children:jsxs($,{children:[jsx(aa,{children:jsx(da,{children:w.columns.map(E=>jsx(ea,{className:"fk:h-8 fk:text-xs",children:E},E))})}),jsx(ba,{children:w.rows.map((E,P)=>jsx(da,{children:w.columns.map($=>jsx(fa,{className:"fk:max-w-56 fk:truncate fk:py-1.5 fk:text-xs",title:E[$],children:E[$]},$))},`${E._id??""}-${P}`))})]})}),w.total>Me?jsxs("span",{className:"fk:text-xs fk:text-muted-foreground",children:["First ",Me.toLocaleString()," of ",w.total.toLocaleString()," records."]}):null]}):jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:p?.data?"The response has no rows to show.":"Run a query to see its records."})}),jsx(ka,{className:"fk:px-3 fk:pb-3",value:"json",children:F?jsx("pre",{className:"fk:overflow-auto fk:rounded-md fk:border fk:bg-muted/40 fk:p-2 fk:font-mono fk:text-xs",children:F}):jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Run a query to see its response."})})]})]})]})}var Wr=250,Zr=5;function eo(e,t){let n=t.trim();return !n||e.length===0?null:{searchRequests:{searches:e.map(r=>({collection:r.plural}))},commonParams:{q:n,limit:Zr}}}function to(e){let t=useMemo(()=>q$1(e),[e]),n=useMemo(()=>gql(t.length>0?r$1(t):"query GraphTotals { __typename }"),[t]),{data:r}=useQuery(n,{skip:t.length===0});return useMemo(()=>Object.fromEntries(t.map(i=>[i.plural,r?.[`${i.plural}Total`]]).filter(i=>typeof i[1]=="number")),[t,r])}function wn({projectId:e,entities:t,colors:n,onCanvas:r,hiddenEntities:i,onStart:s$1,onHit:o$1,onToggleEntity:d}){let[S$1,T$1]=useState(""),[y]=useDebounce(S$1,Wr),c=useMemo(()=>t.filter(l=>l.attributes.some(p=>p.searchable)),[t]),a=useMemo(()=>eo(c,y),[c,y]),{results:h$1,isLoading:g}=a$1(e,a),N$1=to(t),f=useMemo(()=>new Map(t.map(l=>[l.name,l])),[t]),u=Object.keys(r).sort();return jsxs(N,{collapsible:"icon",variant:"inset",children:[jsxs(R,{children:[jsxs(S,{className:"fk:group-data-[collapsible=icon]:hidden",children:[jsxs("div",{className:"fk:relative",children:[jsx(SearchIcon,{className:"fk:pointer-events-none fk:absolute fk:left-2 fk:top-1/2 fk:size-4 fk:-translate-y-1/2 fk:text-muted-foreground"}),jsx(s,{"aria-label":"Search records to add to the canvas",className:"fk:h-8 fk:bg-background fk:pl-8 fk:shadow-none",onChange:l=>T$1(l.target.value),placeholder:c.length>0?"Search records\u2026":"No searchable entity",disabled:c.length===0,value:S$1})]}),a?jsxs("ul",{className:"fk:mt-2 fk:flex fk:flex-col fk:gap-0.5","data-testid":"graph-search-results",children:[h$1.map(l=>{let p=f.get(l._entityName),M=l[a$2(p)?.name??""];return jsx("li",{children:jsxs("button",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:rounded-md fk:px-2 fk:py-1.5 fk:text-left fk:text-sm fk:hover:bg-sidebar-accent",onClick:()=>o$1(l._entityName,l._id),type:"button",children:[jsx("span",{"aria-hidden":"true",className:"fk:size-2.5 fk:shrink-0 fk:rounded-full",style:{backgroundColor:n[l._entityName]??"#71717a"}}),jsx("span",{className:"fk:min-w-0 fk:flex-1 fk:truncate",children:String(M??l._id)})]})},`${l._entityName}:${l._id}`)}),!g&&h$1.length===0?jsx("li",{className:"fk:px-2 fk:py-1.5 fk:text-sm fk:text-muted-foreground",children:"Nothing found"}):null]}):null]}),jsxs(S,{children:[jsx(T,{children:"Nodes"}),jsx(V,{children:t.map(l=>jsx(W,{children:jsxs(X,{onClick:()=>s$1(l),tooltip:h(l),children:[jsx("span",{"aria-hidden":"true",className:"fk:size-2.5 fk:shrink-0 fk:rounded-full",style:{backgroundColor:n[l.name]??"#71717a"}}),jsx("span",{className:"fk:truncate",children:h(l)}),N$1[l.plural]!==void 0?jsx("span",{className:"fk:ml-auto fk:text-xs fk:text-muted-foreground",children:N$1[l.plural]?.toLocaleString()}):null]})},l.name))})]}),u.length>0?jsxs(S,{className:"fk:group-data-[collapsible=icon]:hidden",children:[jsx(T,{children:"On canvas"}),jsx("ul",{className:"fk:flex fk:flex-col","data-testid":"graph-legend",children:u.map(l=>{let p=f.get(l),M=!i.includes(l),w=`graph-legend-${l}`;return jsxs("li",{className:"fk:flex fk:h-8 fk:items-center fk:gap-2 fk:px-2 fk:text-sm",children:[jsx("span",{"aria-hidden":"true",className:"fk:size-2.5 fk:shrink-0 fk:rounded-full",style:{backgroundColor:n[l]??"#71717a",opacity:M?1:.35}}),jsx("label",{className:"fk:min-w-0 fk:flex-1 fk:cursor-pointer fk:truncate",htmlFor:w,children:p?h(p):l}),jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:r[l]?.toLocaleString()}),jsx(o,{"aria-label":`Show ${p?h(p):l}`,checked:M,id:w,onCheckedChange:()=>d(l)})]},l)})})]}):null]}),jsx(P,{})]})}function Le({label:e,icon:t,disabled:n,onClick:r}){return jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsxs(b$3,{className:"fk:h-8 fk:gap-1.5 fk:px-2.5",disabled:n,onClick:r,size:"sm",variant:"ghost",children:[t,jsx("span",{className:"fk:text-xs",children:e})]})}),jsx(e$1,{children:e})]})}function An({hasSelection:e,hasNodes:t,isLoading:n,onFit:r,onExpand:i,onHide:s,onClear:o}){return jsxs("div",{className:"fk:flex fk:items-center fk:gap-0.5 fk:rounded-lg fk:border fk:bg-background fk:p-1 fk:shadow-xs","data-testid":"graph-toolbar",children:[jsx(Le,{disabled:!t,icon:jsx(ScanIcon,{className:"fk:size-3.5"}),label:"Fit",onClick:r}),jsx(v$1,{className:"fk:mx-0.5 fk:h-4",orientation:"vertical"}),jsx(Le,{disabled:!e||n,icon:n?jsx(LoaderCircleIcon,{className:"fk:size-3.5 fk:animate-spin"}):jsx(ExpandIcon,{className:"fk:size-3.5"}),label:"Expand",onClick:i}),jsx(Le,{disabled:!e,icon:jsx(EyeOffIcon,{className:"fk:size-3.5"}),label:"Hide",onClick:s}),jsx(v$1,{className:"fk:mx-0.5 fk:h-4",orientation:"vertical"}),jsx(Le,{disabled:!t,icon:jsx(EraserIcon,{className:"fk:size-3.5"}),label:"Clear",onClick:o})]})}function Ie(e,t="The records could not be loaded."){return e instanceof Error?e.message:t}function Cn({schema:e,scope:t}){let n=useApolloClient(),[r,i]=useReducer(un,Ve),[s,o]=useState(0),d$1=useRef(0),S=useCallback(async(a,h)=>{let g="ids"in h?h.ids:void 0,N="ids"in h?h.expand:false,f="limit"in h?h.limit:g?.length;o(u=>u+1);try{let l$1=(await n.query({query:gql(l({entity:a,schema:e,scope:t,expand:N})),variables:{where:g?{_id:{in:g}}:void 0,limit:f},fetchPolicy:"network-only"})).data?.[a.plural]??[];return d$1.current+=1,i({type:"merge",data:v({records:l$1,entity:a,schema:e,scope:t}),fetched:w(l$1,a)}),l$1.map(p=>d(a.name,p._id))}catch(u){return qa.error(Ie(u)),[]}finally{o(u=>u-1);}},[n,e,t]),T=useCallback(async a=>{let h=r.nodes[a],g=h?g$1(e,h.entity):void 0;!h||!g||await S(g,{ids:[h.id],expand:true});},[S,e,r.nodes]),y=useCallback(async(a$1,h)=>{let g=r.nodes[a$1],N=g?g$1(e,g.entity):void 0;if(!g||!N)return;let f=r.fetched[a$1]?.[h.name]??0;o(u=>u+1);try{let l=(await n.query({query:gql(m({entity:N,schema:e,scope:t,attribute:h})),variables:{id:g.id,offset:f,limit:a},fetchPolicy:"network-only"})).data?.[N.plural]??[];d$1.current+=1;let p=l.reduce((M,w)=>{let F=w[h.name];return M+(Array.isArray(F)?F.length:0)},0);i({type:"merge",data:v({records:l,entity:N,schema:e,scope:t}),fetched:{[a$1]:{[h.name]:f+p}}});}catch(u){qa.error(Ie(u));}finally{o(u=>u-1);}},[n,e,t,r.fetched,r.nodes]),c=useCallback(async(a,{append:h})=>{let g=performance.now(),N;try{N=gql(a);}catch(u){return {data:null,error:Ie(u,"The query could not be parsed."),elapsedMs:0,nodes:0,edges:0}}let f=d$1.current;o(u=>u+1);try{let u=await n.query({query:N,fetchPolicy:"no-cache",errorPolicy:"all",context:f$2}),l=u.data??null,p=xn({data:l,schema:e,scope:t});return p.nodes.length>0&&(!h&&!u.error&&d$1.current===f&&i({type:"clear"}),d$1.current+=1,i({type:"merge",data:p})),{data:l,error:u.error?u.error.message:null,elapsedMs:Math.round(performance.now()-g),nodes:p.nodes.length,edges:p.edges.length}}catch(u){return {data:null,error:Ie(u,"The query failed."),elapsedMs:Math.round(performance.now()-g),nodes:0,edges:0}}finally{o(u=>u-1);}},[n,e,t]);return {state:r,dispatch:i,isLoading:s>0,loadRecords:S,expandAll:T,expandAttribute:y,runQuery:c}}function Zi(){let{currentProjectId:e$3,currentProject:t,currentProjectSchema:n}=f();useEffect(()=>{e$3&&t&&e({event:"graph_opened",projectId:e$3});},[e$3,t]);let[,r]=g(),{scope:i$1}=c(),{resolvedTheme:s}=b(),o=useLocation(),d=j(),S=s==="dark"?"dark":"light",T=t?.scopes?.find(b=>b.isDefault)?.name??"default",y$1=i$1||T,c$3=r.user?.spaces,a=useMemo(()=>c$1(n,c$3),[n,c$3]),h=useMemo(()=>f$1(a),[a]),g$2=useMemo(()=>i(a,S),[a,S]),N=Cn({schema:a,scope:y$1}),{state:f$2,dispatch:u,isLoading:l,loadRecords:p,expandAll:M$1,expandAttribute:w,runQuery:F}=N,D=useRef(null),[E,P]=useState(null),[$,m]=useState(false),[x,v]=useState("explore"),A=useRef(null),G=useMemo(()=>cn(f$2),[f$2]),q=f$2.selected?f$2.nodes[f$2.selected]:void 0,Y=E?f$2.nodes[E.key]:void 0,V=Y?g$1(a,Y.entity):void 0,K$1=Object.keys(f$2.nodes).length,k$1=Object.keys(f$2.edges).length,C=K(),L=useCallback(b=>u({type:"select",key:b}),[u]),oe=useCallback(b=>{let O=f$2.nodes[b],ie=O?g$1(a,O.entity):void 0;O&&ie&&d({type:"EditEntity",payload:{entityId:O.id,entityNamePlural:ie.plural}});},[d,a,f$2.nodes]),_e=useCallback(b=>u({type:"remove",keys:[b]}),[u]),Mn=useCallback(b=>u({type:"keepOnly",keys:[b,...fn(f$2,b)]}),[u,f$2]),Gn=useCallback(b=>u({type:"togglePin",key:b}),[u]),Ln=useCallback(b=>{f$2.pinned[b]||u({type:"togglePin",key:b});},[u,f$2.pinned]),Dn=useCallback(async(b,O)=>{let ie=g$1(a,b);if(!ie)return;let[de]=await p(ie,{ids:[O],expand:true});de&&L(de);},[p,a,L]),In=useCallback((b,O)=>{P(null),w(b,O);},[w]);return useEffect(()=>{let b=y(o.search);if(!b||A.current===o.key)return;let O=g$1(a,b.entity);if(!O||a.length===0)return;A.current=o.key;let ie=b.ids.length>0?{ids:b.ids,expand:b.ids.length<=k}:{limit:b$1};p(O,ie).then(de=>{b.ids.length===1&&de[0]&&L(de[0]);});},[o.key,o.search,a,p,L]),e$3?jsxs(M,{className:"fk:h-full",defaultOpen:C,children:[jsx(wn,{colors:g$2,entities:h,hiddenEntities:f$2.hiddenEntities,onCanvas:G,onHit:(b,O)=>{Dn(b,O);},onStart:b=>{p(b,{limit:b$1});},onToggleEntity:b=>u({type:"toggleEntity",entity:b}),projectId:e$3}),jsx(Q,{className:"fk:min-w-0",children:jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0","data-testid":"graph-app",children:[jsx(vn,{hidden:x!=="query",isRunning:l,onRun:F,projectId:e$3,schema:a,schemaHash:t?.schemaHash??null,scope:y$1,theme:S},e$3),jsxs("div",{className:"fk:relative fk:min-w-0 fk:flex-1 fk:overflow-hidden fk:bg-background",children:[jsxs("div",{className:"fk:pointer-events-none fk:absolute fk:left-3 fk:right-3 fk:top-3 fk:z-10 fk:flex fk:flex-wrap fk:items-start fk:justify-between fk:gap-2",children:[jsxs("div",{className:"fk:pointer-events-auto fk:flex fk:items-center fk:gap-2",children:[jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsx(O,{className:"fk:h-8 fk:w-8 fk:rounded-lg fk:hover:bg-transparent fk:dark:hover:bg-transparent"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(An,{hasNodes:K$1>0,hasSelection:q!==void 0,isLoading:l,onClear:()=>u({type:"clear"}),onExpand:()=>{f$2.selected&&M$1(f$2.selected);},onFit:()=>D.current?.fit(),onHide:()=>{f$2.selected&&_e(f$2.selected);}})]}),jsxs("div",{"aria-label":"View",className:"fk:pointer-events-auto fk:flex fk:items-center fk:gap-0.5 fk:rounded-lg fk:border fk:bg-background fk:p-0.5 fk:shadow-xs","data-testid":"graph-mode",role:"group",children:[jsx(b$3,{"aria-pressed":x==="explore",className:"fk:h-7 fk:px-3 fk:text-xs",onClick:()=>v("explore"),size:"sm",variant:x==="explore"?"default":"ghost",children:"Explore"}),jsx(b$3,{"aria-pressed":x==="query",className:"fk:h-7 fk:px-3 fk:text-xs",onClick:()=>v("query"),size:"sm",variant:x==="query"?"default":"ghost",children:"Query"})]})]}),K$1>0?null:jsx("div",{className:"fk:pointer-events-none fk:absolute fk:inset-0 fk:flex fk:items-center fk:justify-center fk:p-8 fk:text-center fk:text-sm fk:text-muted-foreground",children:l?"Loading records\u2026":x==="query"?"Run a query to draw its result.":"Search a record or start from an entity to draw its graph."}),jsx(sn,{apiRef:D,colors:g$2,onContextMenu:(b,O)=>P({key:b,...O}),onExpand:b=>{M$1(b);},onLayoutChange:m,onPin:Ln,onSelect:L,scene:f$2,theme:S}),jsxs("div",{className:"fk:absolute fk:bottom-3 fk:left-3 fk:flex fk:max-w-[calc(100%-1.5rem)] fk:items-center fk:gap-2 fk:rounded-lg fk:border fk:bg-background fk:px-2.5 fk:py-1.5 fk:text-xs fk:text-muted-foreground fk:shadow-xs","data-testid":"graph-status",children:[jsxs("span",{children:[K$1.toLocaleString()," ",K$1===1?"node":"nodes"," \xB7 ",k$1.toLocaleString()," ",k$1===1?"relationship":"relationships"]}),$?jsx("span",{children:"\xB7 laying out\u2026"}):null,f$2.notice?jsxs("span",{className:"fk:truncate fk:text-foreground",children:["\xB7 ",f$2.notice]}):null]}),jsx(an,{isPinned:E?f$2.pinned[E.key]===true:false,menu:E,onClose:()=>P(null),onExpandAll:b=>{M$1(b);},onExpandAttribute:In,onHide:_e,onHideOthers:Mn,onOpenRecord:oe,onTogglePin:Gn,relationships:V?e$2(V):[]})]}),q?jsx(gn,{colors:g$2,isLoading:l,node:q,onClose:()=>L(null),onExpandAll:b=>{M$1(b);},onExpandAttribute:(b,O)=>{w(b,O);},onHide:_e,onOpenRecord:oe,scene:f$2,schema:a,scope:y$1}):null]})})]}):jsx("main",{className:"fk:flex fk:h-full fk:flex-1 fk:items-center fk:justify-center fk:p-8 fk:text-sm fk:text-muted-foreground",children:"Select a project to explore its graph."})}export{Zi as Root};//# sourceMappingURL=root-QRSWWD23.js.map
14
- //# sourceMappingURL=root-QRSWWD23.js.map
13
+ }`}})}function Pr(e,t){let n=me(e);return n.length>0?`${n.length} ${n.length===1?"record":"records"}`:Array.isArray(e)&&!(typeof e[0]=="object"&&e[0]!==null)?e.map(r=>s$2(r,t)).join(", "):s$2(e,t)}function Ze(e){if(Array.isArray(e))return e.flatMap(Ze);if(typeof e!="object"||e===null)return [];let{edges:t}=e;return !bn(e)&&Array.isArray(t)?t.flatMap(n=>Ze(n?.node)):[e]}function En(e,t){let n=Object.values(e??{}).flatMap(Ze),r=n.slice(0,Me),i=[];return r.forEach(s=>{Object.keys(s).forEach(o=>{o!=="__typename"&&!i.includes(o)&&i.push(o);});}),{columns:i,rows:r.map(s=>Object.fromEntries(i.map(o=>[o,Pr(s[o],t)]))),total:n.length}}function Te(e){return Array.isArray(e)?e.map(Te):typeof e=="object"&&e!==null?Object.fromEntries(Object.entries(e).filter(([t])=>t!=="__typename").map(([t,n])=>[t,Te(n)])):e}function et(e){return `flexkit-graph:query:${e}`}var Ge=new Map;function jr(e,t,n){let r=Ge.get(t);if(r&&r.hash===n)return r.schema;let i=e.query({query:gql(getIntrospectionQuery()),fetchPolicy:"no-cache",context:f$2}).then(s=>{if(!s.data)throw new Error("The schema could not be introspected.");return buildClientSchema(s.data)});return i.catch(()=>{Ge.get(t)?.schema===i&&Ge.delete(t);}),Ge.set(t,{hash:n,schema:i}),i}function Nn(e,t){let n=useApolloClient(),[r,i]=useState(null);return useEffect(()=>{if(!e)return;let s=false;return jr(n,e,t??"").then(o=>{s||i(o);}).catch(()=>{}),()=>{s=true;}},[n,e,t]),r}function vn({projectId:e,schemaHash:t,schema:n,scope:r,theme:i,isRunning:s,hidden:o$1,onRun:d}){let[S,T]=useState(!o$1),y=Nn(S?e:void 0,t),c=useMemo(()=>Sn(n,r),[n,r]),[a,h]=useState(()=>b$4(et(e))||c[0]?.query||""),g=useRef(a!==""),[N,f]=useState(false),[u,l]=useState("graph"),[p,M]=useState(null),w=useMemo(()=>u==="table"&&p?.data?En(p.data,r):null,[u,p,r]),F=useMemo(()=>u==="json"&&p?.data?JSON.stringify(Te(p.data),null,2):null,[u,p]);useEffect(()=>{o$1||T(true);},[o$1]),useEffect(()=>{let[E]=c;!g.current&&E&&(g.current=true,h(P=>P||E.query));},[c]),useEffect(()=>{c$3(et(e),a);},[e,a]);let D=async()=>{!a.trim()||s||M(await d(a,{append:N}));};return jsxs("section",{"aria-label":"Query",className:`fk:w-[26rem] fk:shrink-0 fk:flex-col fk:border-r fk:bg-background ${o$1?"fk:hidden":"fk:flex"}`,"data-testid":"graph-query-pane",hidden:o$1,children:[jsxs("div",{className:"fk:flex fk:h-12 fk:shrink-0 fk:items-center fk:gap-2 fk:border-b fk:pl-4 fk:pr-3",children:[jsx("span",{className:"fk:text-sm fk:font-semibold",children:"Query"}),jsxs("div",{className:"fk:ml-auto fk:flex fk:items-center fk:gap-1.5",children:[c.length>0?jsxs(e$3,{children:[jsx(g$2,{asChild:true,children:jsxs(b$3,{className:"fk:h-8",size:"sm",variant:"outline",children:["Examples",jsx(ChevronDownIcon,{className:"fk:size-3.5"})]})}),jsx(h$1,{align:"end",className:"fk:max-h-80 fk:overflow-y-auto",children:c.map(E=>jsx(j$1,{onSelect:()=>h(E.query),children:E.title},E.entity))})]}):null,jsxs(b$3,{className:"fk:h-8",disabled:s||!a.trim(),onClick:()=>{D();},size:"sm",children:[s?jsx(LoaderCircleIcon,{className:"fk:size-3.5 fk:animate-spin"}):jsx(PlayIcon,{className:"fk:size-3.5"}),"Run"]})]})]}),jsx("div",{className:"fk:min-h-0 fk:flex-1",children:jsx(yn,{ariaLabel:"GraphQL query",onChange:h,onRun:()=>{D();},schema:y,theme:i,value:a})}),jsxs(ha,{className:"fk:flex fk:max-h-[45%] fk:shrink-0 fk:flex-col fk:gap-0 fk:border-t",onValueChange:E=>l(E),value:u,children:[jsxs("div",{className:"fk:flex fk:h-11 fk:shrink-0 fk:items-center fk:gap-3 fk:px-3",children:[jsxs(ia,{children:[jsx(ja,{value:"graph",children:"Graph"}),jsx(ja,{value:"table",children:"Table"}),jsx(ja,{value:"json",children:"JSON"})]}),jsx("span",{className:"fk:ml-auto fk:truncate fk:text-xs fk:text-muted-foreground","data-testid":"graph-query-stats",children:p&&!p.error?`${p.nodes.toLocaleString()} ${p.nodes===1?"node":"nodes"} \xB7 ${p.edges.toLocaleString()} ${p.edges===1?"relationship":"relationships"} \xB7 ${p.elapsedMs.toLocaleString()} ms`:null})]}),p?.error?jsx("pre",{className:"fk:m-3 fk:mt-0 fk:max-h-40 fk:shrink-0 fk:overflow-auto fk:whitespace-pre-wrap fk:rounded-md fk:border fk:border-destructive/40 fk:bg-destructive/5 fk:p-2 fk:text-xs fk:text-destructive","data-testid":"graph-query-error",children:p.error}):null,jsxs("div",{className:"fk:min-h-0 fk:overflow-auto",children:[jsxs(ka,{className:"fk:flex fk:flex-col fk:gap-3 fk:px-3 fk:pb-3 fk:text-xs fk:text-muted-foreground",value:"graph",children:[jsxs("span",{children:["Every object with an ",jsx("code",{className:"fk:font-mono",children:"_id"})," under an entity field becomes a node; a nested relationship selection becomes a line between them."]}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx(o,{checked:N,id:"graph-query-append",onCheckedChange:E=>f(E===true)}),jsx(e$4,{className:"fk:text-xs fk:font-normal",htmlFor:"graph-query-append",children:"Add to the current canvas instead of replacing it"})]})]}),jsx(ka,{className:"fk:px-3 fk:pb-3",value:"table",children:w&&w.columns.length>0?jsxs("div",{className:"fk:flex fk:flex-col fk:gap-1",children:[jsx("div",{className:"fk:overflow-x-auto fk:rounded-md fk:border",children:jsxs($,{children:[jsx(aa,{children:jsx(da,{children:w.columns.map(E=>jsx(ea,{className:"fk:h-8 fk:text-xs",children:E},E))})}),jsx(ba,{children:w.rows.map((E,P)=>jsx(da,{children:w.columns.map($=>jsx(fa,{className:"fk:max-w-56 fk:truncate fk:py-1.5 fk:text-xs",title:E[$],children:E[$]},$))},`${E._id??""}-${P}`))})]})}),w.total>Me?jsxs("span",{className:"fk:text-xs fk:text-muted-foreground",children:["First ",Me.toLocaleString()," of ",w.total.toLocaleString()," records."]}):null]}):jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:p?.data?"The response has no rows to show.":"Run a query to see its records."})}),jsx(ka,{className:"fk:px-3 fk:pb-3",value:"json",children:F?jsx("pre",{className:"fk:overflow-auto fk:rounded-md fk:border fk:bg-muted/40 fk:p-2 fk:font-mono fk:text-xs",children:F}):jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:"Run a query to see its response."})})]})]})]})}var Wr=250,Zr=5;function eo(e,t){let n=t.trim();return !n||e.length===0?null:{searchRequests:{searches:e.map(r=>({collection:r.plural}))},commonParams:{q:n,limit:Zr}}}function to(e){let t=useMemo(()=>q$1(e),[e]),n=useMemo(()=>gql(t.length>0?r$1(t):"query GraphTotals { __typename }"),[t]),{data:r}=useQuery(n,{skip:t.length===0});return useMemo(()=>Object.fromEntries(t.map(i=>[i.plural,r?.[`${i.plural}Total`]]).filter(i=>typeof i[1]=="number")),[t,r])}function wn({projectId:e,entities:t,colors:n,onCanvas:r,hiddenEntities:i,onStart:s$1,onHit:o$1,onToggleEntity:d}){let[S$1,T$1]=useState(""),[y]=useDebounce(S$1,Wr),c=useMemo(()=>t.filter(l=>l.attributes.some(p=>p.searchable)),[t]),a=useMemo(()=>eo(c,y),[c,y]),{results:h$1,isLoading:g}=a$1(e,a),N$1=to(t),f=useMemo(()=>new Map(t.map(l=>[l.name,l])),[t]),u=Object.keys(r).sort();return jsxs(N,{collapsible:"icon",variant:"inset",children:[jsxs(R,{children:[jsxs(S,{className:"fk:group-data-[collapsible=icon]:hidden",children:[jsxs("div",{className:"fk:relative",children:[jsx(SearchIcon,{className:"fk:pointer-events-none fk:absolute fk:left-2 fk:top-1/2 fk:size-4 fk:-translate-y-1/2 fk:text-muted-foreground"}),jsx(s,{"aria-label":"Search records to add to the canvas",className:"fk:h-8 fk:bg-background fk:pl-8 fk:shadow-none",onChange:l=>T$1(l.target.value),placeholder:c.length>0?"Search records\u2026":"No searchable entity",disabled:c.length===0,value:S$1})]}),a?jsxs("ul",{className:"fk:mt-2 fk:flex fk:flex-col fk:gap-0.5","data-testid":"graph-search-results",children:[h$1.map(l=>{let p=f.get(l._entityName),M=l[a$2(p)?.name??""];return jsx("li",{children:jsxs("button",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:rounded-md fk:px-2 fk:py-1.5 fk:text-left fk:text-sm fk:hover:bg-sidebar-accent",onClick:()=>o$1(l._entityName,l._id),type:"button",children:[jsx("span",{"aria-hidden":"true",className:"fk:size-2.5 fk:shrink-0 fk:rounded-full",style:{backgroundColor:n[l._entityName]??"#71717a"}}),jsx("span",{className:"fk:min-w-0 fk:flex-1 fk:truncate",children:String(M??l._id)})]})},`${l._entityName}:${l._id}`)}),!g&&h$1.length===0?jsx("li",{className:"fk:px-2 fk:py-1.5 fk:text-sm fk:text-muted-foreground",children:"Nothing found"}):null]}):null]}),jsxs(S,{children:[jsx(T,{children:"Nodes"}),jsx(V,{children:t.map(l=>jsx(W,{children:jsxs(X,{onClick:()=>s$1(l),tooltip:h(l),children:[jsx("span",{"aria-hidden":"true",className:"fk:size-2.5 fk:shrink-0 fk:rounded-full",style:{backgroundColor:n[l.name]??"#71717a"}}),jsx("span",{className:"fk:truncate",children:h(l)}),N$1[l.plural]!==void 0?jsx("span",{className:"fk:ml-auto fk:text-xs fk:text-muted-foreground",children:N$1[l.plural]?.toLocaleString()}):null]})},l.name))})]}),u.length>0?jsxs(S,{className:"fk:group-data-[collapsible=icon]:hidden",children:[jsx(T,{children:"On canvas"}),jsx("ul",{className:"fk:flex fk:flex-col","data-testid":"graph-legend",children:u.map(l=>{let p=f.get(l),M=!i.includes(l),w=`graph-legend-${l}`;return jsxs("li",{className:"fk:flex fk:h-8 fk:items-center fk:gap-2 fk:px-2 fk:text-sm",children:[jsx("span",{"aria-hidden":"true",className:"fk:size-2.5 fk:shrink-0 fk:rounded-full",style:{backgroundColor:n[l]??"#71717a",opacity:M?1:.35}}),jsx("label",{className:"fk:min-w-0 fk:flex-1 fk:cursor-pointer fk:truncate",htmlFor:w,children:p?h(p):l}),jsx("span",{className:"fk:text-xs fk:text-muted-foreground",children:r[l]?.toLocaleString()}),jsx(o,{"aria-label":`Show ${p?h(p):l}`,checked:M,id:w,onCheckedChange:()=>d(l)})]},l)})})]}):null]}),jsx(P,{})]})}function Le({label:e,icon:t,disabled:n,onClick:r}){return jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsxs(b$3,{className:"fk:h-8 fk:gap-1.5 fk:px-2.5",disabled:n,onClick:r,size:"sm",variant:"ghost",children:[t,jsx("span",{className:"fk:text-xs",children:e})]})}),jsx(e$1,{children:e})]})}function An({hasSelection:e,hasNodes:t,isLoading:n,onFit:r,onExpand:i,onHide:s,onClear:o}){return jsxs("div",{className:"fk:flex fk:items-center fk:gap-0.5 fk:rounded-lg fk:border fk:bg-background fk:p-1 fk:shadow-xs","data-testid":"graph-toolbar",children:[jsx(Le,{disabled:!t,icon:jsx(ScanIcon,{className:"fk:size-3.5"}),label:"Fit",onClick:r}),jsx(v$1,{className:"fk:mx-0.5 fk:h-4",orientation:"vertical"}),jsx(Le,{disabled:!e||n,icon:n?jsx(LoaderCircleIcon,{className:"fk:size-3.5 fk:animate-spin"}):jsx(ExpandIcon,{className:"fk:size-3.5"}),label:"Expand",onClick:i}),jsx(Le,{disabled:!e,icon:jsx(EyeOffIcon,{className:"fk:size-3.5"}),label:"Hide",onClick:s}),jsx(v$1,{className:"fk:mx-0.5 fk:h-4",orientation:"vertical"}),jsx(Le,{disabled:!t,icon:jsx(EraserIcon,{className:"fk:size-3.5"}),label:"Clear",onClick:o})]})}function Ie(e,t="The records could not be loaded."){return e instanceof Error?e.message:t}function Cn({schema:e,scope:t}){let n=useApolloClient(),[r,i]=useReducer(un,Ve),[s,o]=useState(0),d$1=useRef(0),S=useCallback(async(a,h)=>{let g="ids"in h?h.ids:void 0,N="ids"in h?h.expand:false,f="limit"in h?h.limit:g?.length;o(u=>u+1);try{let l$1=(await n.query({query:gql(l({entity:a,schema:e,scope:t,expand:N})),variables:{where:g?{_id:{in:g}}:void 0,limit:f},fetchPolicy:"network-only"})).data?.[a.plural]??[];return d$1.current+=1,i({type:"merge",data:v({records:l$1,entity:a,schema:e,scope:t}),fetched:w(l$1,a)}),l$1.map(p=>d(a.name,p._id))}catch(u){return qa.error(Ie(u)),[]}finally{o(u=>u-1);}},[n,e,t]),T=useCallback(async a=>{let h=r.nodes[a],g=h?g$1(e,h.entity):void 0;!h||!g||await S(g,{ids:[h.id],expand:true});},[S,e,r.nodes]),y=useCallback(async(a$1,h)=>{let g=r.nodes[a$1],N=g?g$1(e,g.entity):void 0;if(!g||!N)return;let f=r.fetched[a$1]?.[h.name]??0;o(u=>u+1);try{let l=(await n.query({query:gql(m({entity:N,schema:e,scope:t,attribute:h})),variables:{id:g.id,offset:f,limit:a},fetchPolicy:"network-only"})).data?.[N.plural]??[];d$1.current+=1;let p=l.reduce((M,w)=>{let F=w[h.name];return M+(Array.isArray(F)?F.length:0)},0);i({type:"merge",data:v({records:l,entity:N,schema:e,scope:t}),fetched:{[a$1]:{[h.name]:f+p}}});}catch(u){qa.error(Ie(u));}finally{o(u=>u-1);}},[n,e,t,r.fetched,r.nodes]),c=useCallback(async(a,{append:h})=>{let g=performance.now(),N;try{N=gql(a);}catch(u){return {data:null,error:Ie(u,"The query could not be parsed."),elapsedMs:0,nodes:0,edges:0}}let f=d$1.current;o(u=>u+1);try{let u=await n.query({query:N,fetchPolicy:"no-cache",errorPolicy:"all",context:f$2}),l=u.data??null,p=xn({data:l,schema:e,scope:t});return p.nodes.length>0&&(!h&&!u.error&&d$1.current===f&&i({type:"clear"}),d$1.current+=1,i({type:"merge",data:p})),{data:l,error:u.error?u.error.message:null,elapsedMs:Math.round(performance.now()-g),nodes:p.nodes.length,edges:p.edges.length}}catch(u){return {data:null,error:Ie(u,"The query failed."),elapsedMs:Math.round(performance.now()-g),nodes:0,edges:0}}finally{o(u=>u-1);}},[n,e,t]);return {state:r,dispatch:i,isLoading:s>0,loadRecords:S,expandAll:T,expandAttribute:y,runQuery:c}}function Zi(){let{currentProjectId:e$3,currentProject:t,currentProjectSchema:n}=f();useEffect(()=>{e$3&&t&&e({event:"graph_opened",projectId:e$3});},[e$3,t]);let[,r]=g(),{scope:i$1}=c(),{resolvedTheme:s}=b(),o=useLocation(),d=j(),S=s==="dark"?"dark":"light",T=t?.scopes?.find(b=>b.isDefault)?.name??"default",y$1=i$1||T,c$3=r.user?.spaces,a=useMemo(()=>c$1(n,c$3),[n,c$3]),h=useMemo(()=>f$1(a),[a]),g$2=useMemo(()=>i(a,S),[a,S]),N=Cn({schema:a,scope:y$1}),{state:f$2,dispatch:u,isLoading:l,loadRecords:p,expandAll:M$1,expandAttribute:w,runQuery:F}=N,D=useRef(null),[E,P]=useState(null),[$,m]=useState(false),[x,v]=useState("explore"),A=useRef(null),G=useMemo(()=>cn(f$2),[f$2]),q=f$2.selected?f$2.nodes[f$2.selected]:void 0,Y=E?f$2.nodes[E.key]:void 0,V=Y?g$1(a,Y.entity):void 0,K$1=Object.keys(f$2.nodes).length,k$1=Object.keys(f$2.edges).length,C=K(),L=useCallback(b=>u({type:"select",key:b}),[u]),oe=useCallback(b=>{let O=f$2.nodes[b],ie=O?g$1(a,O.entity):void 0;O&&ie&&d({type:"EditEntity",payload:{entityId:O.id,entityNamePlural:ie.plural}});},[d,a,f$2.nodes]),_e=useCallback(b=>u({type:"remove",keys:[b]}),[u]),Mn=useCallback(b=>u({type:"keepOnly",keys:[b,...fn(f$2,b)]}),[u,f$2]),Gn=useCallback(b=>u({type:"togglePin",key:b}),[u]),Ln=useCallback(b=>{f$2.pinned[b]||u({type:"togglePin",key:b});},[u,f$2.pinned]),Dn=useCallback(async(b,O)=>{let ie=g$1(a,b);if(!ie)return;let[de]=await p(ie,{ids:[O],expand:true});de&&L(de);},[p,a,L]),In=useCallback((b,O)=>{P(null),w(b,O);},[w]);return useEffect(()=>{let b=y(o.search);if(!b||A.current===o.key)return;let O=g$1(a,b.entity);if(!O||a.length===0)return;A.current=o.key;let ie=b.ids.length>0?{ids:b.ids,expand:b.ids.length<=k}:{limit:b$1};p(O,ie).then(de=>{b.ids.length===1&&de[0]&&L(de[0]);});},[o.key,o.search,a,p,L]),e$3?jsxs(M,{className:"fk:h-full",defaultOpen:C,children:[jsx(wn,{colors:g$2,entities:h,hiddenEntities:f$2.hiddenEntities,onCanvas:G,onHit:(b,O)=>{Dn(b,O);},onStart:b=>{p(b,{limit:b$1});},onToggleEntity:b=>u({type:"toggleEntity",entity:b}),projectId:e$3}),jsx(Q,{className:"fk:min-w-0",children:jsxs("div",{className:"fk:flex fk:h-full fk:min-h-0 fk:min-w-0","data-testid":"graph-app",children:[jsx(vn,{hidden:x!=="query",isRunning:l,onRun:F,projectId:e$3,schema:a,schemaHash:t?.schemaHash??null,scope:y$1,theme:S},e$3),jsxs("div",{className:"fk:relative fk:min-w-0 fk:flex-1 fk:overflow-hidden fk:bg-background",children:[jsxs("div",{className:"fk:pointer-events-none fk:absolute fk:left-3 fk:right-3 fk:top-3 fk:z-10 fk:flex fk:flex-wrap fk:items-start fk:justify-between fk:gap-2",children:[jsxs("div",{className:"fk:pointer-events-auto fk:flex fk:items-center fk:gap-2",children:[jsxs(b$2,{children:[jsx(c$2,{asChild:true,children:jsx(O,{className:"fk:h-8 fk:w-8 fk:rounded-lg fk:hover:bg-transparent fk:dark:hover:bg-transparent"})}),jsx(e$1,{children:"Toggle Sidebar"})]}),jsx(An,{hasNodes:K$1>0,hasSelection:q!==void 0,isLoading:l,onClear:()=>u({type:"clear"}),onExpand:()=>{f$2.selected&&M$1(f$2.selected);},onFit:()=>D.current?.fit(),onHide:()=>{f$2.selected&&_e(f$2.selected);}})]}),jsxs("div",{"aria-label":"View",className:"fk:pointer-events-auto fk:flex fk:items-center fk:gap-0.5 fk:rounded-lg fk:border fk:bg-background fk:p-0.5 fk:shadow-xs","data-testid":"graph-mode",role:"group",children:[jsx(b$3,{"aria-pressed":x==="explore",className:"fk:h-7 fk:px-3 fk:text-xs",onClick:()=>v("explore"),size:"sm",variant:x==="explore"?"default":"ghost",children:"Explore"}),jsx(b$3,{"aria-pressed":x==="query",className:"fk:h-7 fk:px-3 fk:text-xs",onClick:()=>v("query"),size:"sm",variant:x==="query"?"default":"ghost",children:"Query"})]})]}),K$1>0?null:jsx("div",{className:"fk:pointer-events-none fk:absolute fk:inset-0 fk:flex fk:items-center fk:justify-center fk:p-8 fk:text-center fk:text-sm fk:text-muted-foreground",children:l?"Loading records\u2026":x==="query"?"Run a query to draw its result.":"Search a record or start from an entity to draw its graph."}),jsx(sn,{apiRef:D,colors:g$2,onContextMenu:(b,O)=>P({key:b,...O}),onExpand:b=>{M$1(b);},onLayoutChange:m,onPin:Ln,onSelect:L,scene:f$2,theme:S}),jsxs("div",{className:"fk:absolute fk:bottom-3 fk:left-3 fk:flex fk:max-w-[calc(100%-1.5rem)] fk:items-center fk:gap-2 fk:rounded-lg fk:border fk:bg-background fk:px-2.5 fk:py-1.5 fk:text-xs fk:text-muted-foreground fk:shadow-xs","data-testid":"graph-status",children:[jsxs("span",{children:[K$1.toLocaleString()," ",K$1===1?"node":"nodes"," \xB7 ",k$1.toLocaleString()," ",k$1===1?"relationship":"relationships"]}),$?jsx("span",{children:"\xB7 laying out\u2026"}):null,f$2.notice?jsxs("span",{className:"fk:truncate fk:text-foreground",children:["\xB7 ",f$2.notice]}):null]}),jsx(an,{isPinned:E?f$2.pinned[E.key]===true:false,menu:E,onClose:()=>P(null),onExpandAll:b=>{M$1(b);},onExpandAttribute:In,onHide:_e,onHideOthers:Mn,onOpenRecord:oe,onTogglePin:Gn,relationships:V?e$2(V):[]})]}),q?jsx(gn,{colors:g$2,isLoading:l,node:q,onClose:()=>L(null),onExpandAll:b=>{M$1(b);},onExpandAttribute:(b,O)=>{w(b,O);},onHide:_e,onOpenRecord:oe,scene:f$2,schema:a,scope:y$1}):null]})})]}):jsx("main",{className:"fk:flex fk:h-full fk:flex-1 fk:items-center fk:justify-center fk:p-8 fk:text-sm fk:text-muted-foreground",children:"Select a project to explore its graph."})}export{Zi as Root};//# sourceMappingURL=root-E35GZ7SV.js.map
14
+ //# sourceMappingURL=root-E35GZ7SV.js.map