graview 0.1.51 → 0.1.52
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.
- package/dist/preview/chunk.2EB7COX5.js +1 -0
- package/dist/preview/{chunk.K7ECYKZL.js → chunk.2K3YQJW3.js} +1 -1
- package/dist/preview/{chunk.PPZ2TOB5.js → chunk.2X3UZJWI.js} +1 -1
- package/dist/preview/{chunk.KRODTMGR.js → chunk.337JMOTL.js} +1 -1
- package/dist/preview/{chunk.5ZAK57JA.js → chunk.3FKP32RG.js} +2 -2
- package/dist/preview/{chunk.ACB4TD4W.js → chunk.3TME4BG3.js} +1 -1
- package/dist/preview/chunk.3ZQAPPJ5.js +18 -0
- package/dist/preview/{chunk.EA2NMVRE.js → chunk.4LI73QOY.js} +1 -1
- package/dist/preview/{chunk.UIWI4GKW.js → chunk.4VI3EYDL.js} +1 -1
- package/dist/preview/{chunk.OHDJYGH7.js → chunk.4ZLCMATU.js} +1 -1
- package/dist/preview/{chunk.GJQF7I22.js → chunk.52J42KR5.js} +1 -1
- package/dist/preview/{chunk.4EZFOZBA.js → chunk.5DDHFNZM.js} +1 -1
- package/dist/preview/chunk.5LWPNOJA.js +1 -0
- package/dist/preview/{chunk.FKJ3HIA5.js → chunk.5WU2UTP7.js} +1 -1
- package/dist/preview/{chunk.OPCBZNKF.js → chunk.63SRVTG2.js} +2 -2
- package/dist/preview/{chunk.CV55N3Y6.js → chunk.6BA6RUK7.js} +1 -1
- package/dist/preview/{chunk.WFHFWJ6E.js → chunk.6CY3EA6U.js} +1 -1
- package/dist/preview/{chunk.IBJBCZKG.js → chunk.6JERQFZI.js} +1 -1
- package/dist/preview/{chunk.IFL2MYTQ.js → chunk.6NIE3ILA.js} +1 -1
- package/dist/preview/{chunk.JMDKAP23.js → chunk.6QNBUBGD.js} +1 -1
- package/dist/preview/chunk.6YGRRXJB.js +2 -0
- package/dist/preview/{chunk.JX2C3HVD.js → chunk.7354O67H.js} +1 -1
- package/dist/preview/{chunk.MY5OXSS7.js → chunk.73EKJ4JN.js} +1 -1
- package/dist/preview/{chunk.CQPNDJAC.js → chunk.7EA7THSM.js} +1 -1
- package/dist/preview/{chunk.IUIDDNN3.js → chunk.7FMS57QO.js} +1 -1
- package/dist/preview/{chunk.3TVAE7LE.js → chunk.7FZY5E2U.js} +1 -1
- package/dist/preview/{chunk.R5R7CLOU.js → chunk.7IOC6U3C.js} +1 -1
- package/dist/preview/{chunk.JI2UVZUU.js → chunk.7KZ44FEU.js} +1 -1
- package/dist/preview/chunk.7OAXW7QF.js +1 -0
- package/dist/preview/chunk.7SNIX56B.js +1 -0
- package/dist/preview/{chunk.OJ64WTLW.js → chunk.7UJZP3YK.js} +2 -2
- package/dist/preview/{chunk.353CGK6C.js → chunk.7UXDIEPK.js} +1 -1
- package/dist/preview/{chunk.NQ26KMSQ.js → chunk.7XJ3XQZD.js} +1 -1
- package/dist/preview/chunk.AI2HBKVP.js +359 -0
- package/dist/preview/{chunk.KOBCLWPC.js → chunk.BDQ4FUKO.js} +1 -1
- package/dist/preview/{chunk.ESSENNHM.js → chunk.BHPZK4WJ.js} +2 -2
- package/dist/preview/{chunk.W2DKFQ6R.js → chunk.BJL6EL6B.js} +1 -1
- package/dist/preview/{chunk.UK5F3S2N.js → chunk.C4EPMV7O.js} +1 -1
- package/dist/preview/{chunk.DQNN5FE5.js → chunk.C4UNAJWC.js} +1 -1
- package/dist/preview/{chunk.Z7N3MJ36.js → chunk.C7EEYSAM.js} +1 -1
- package/dist/preview/{chunk.7RIFDWDF.js → chunk.CBGKWYGI.js} +1 -1
- package/dist/preview/chunk.CC7E6NUQ.js +1 -0
- package/dist/preview/chunk.CHMUL36A.js +1 -0
- package/dist/preview/{chunk.VICCAWAN.js → chunk.CV4QA4ZF.js} +1 -1
- package/dist/preview/{chunk.5ON3JSAK.js → chunk.D2T563AA.js} +1 -1
- package/dist/preview/{chunk.B7LBG4UP.js → chunk.D62V3TBW.js} +1 -1
- package/dist/preview/{chunk.2W45NM7Q.js → chunk.DC7M56NM.js} +2 -2
- package/dist/preview/{chunk.6KYWJXZR.js → chunk.DGWNVDZB.js} +1 -1
- package/dist/preview/{chunk.TBSPEO2L.js → chunk.DIS7JS7X.js} +1 -1
- package/dist/preview/{chunk.FYDDFOSD.js → chunk.DVLWSCIC.js} +1 -1
- package/dist/preview/{chunk.FU4YSVWX.js → chunk.DXZ5VYCQ.js} +1 -1
- package/dist/preview/{chunk.PMV6XVVZ.js → chunk.EHOEMVQP.js} +1 -1
- package/dist/preview/{chunk.B4PUI3GO.js → chunk.EIWTZC4A.js} +1 -1
- package/dist/preview/chunk.EME5HQ3H.js +1 -0
- package/dist/preview/{chunk.HVX7LFWR.js → chunk.FEBCIEI3.js} +1 -1
- package/dist/preview/{chunk.IE4ZJQV3.js → chunk.FJC6PMOG.js} +1 -1
- package/dist/preview/{chunk.2W2YVB6X.js → chunk.FJEXINFF.js} +1 -1
- package/dist/preview/{chunk.APFRPN5S.js → chunk.FLNYLE6S.js} +1 -1
- package/dist/preview/{chunk.2VJ52LGS.js → chunk.G7XKQNOL.js} +1 -1
- package/dist/preview/{chunk.SSAY4ITS.js → chunk.GL3YVGAP.js} +2 -2
- package/dist/preview/{chunk.K7RKWB2K.js → chunk.GZHEGKPF.js} +1 -1
- package/dist/preview/{chunk.KK46XLGU.js → chunk.HSGUXMAO.js} +1 -1
- package/dist/preview/{chunk.AZOW57MT.js → chunk.HST7BYFW.js} +1 -1
- package/dist/preview/{chunk.T3RTFTOZ.js → chunk.I2W7HSBU.js} +1 -1
- package/dist/preview/{chunk.XCQ7ZPR5.js → chunk.I43ONAEL.js} +1 -1
- package/dist/preview/{chunk.NVRK6A7T.js → chunk.INL4OZI7.js} +1 -1
- package/dist/preview/{chunk.ALCH5H7U.js → chunk.IVI3HRSF.js} +1 -1
- package/dist/preview/{chunk.XCCBUWMC.js → chunk.J263VQF5.js} +1 -1
- package/dist/preview/{chunk.TNL2BVCH.js → chunk.J2R55TM7.js} +1 -1
- package/dist/preview/{chunk.U7SNDY3F.js → chunk.J6IB2HUZ.js} +1 -1
- package/dist/preview/{chunk.Y5AMZBHA.js → chunk.JOWJNIWH.js} +2 -2
- package/dist/preview/{chunk.7GAC7U34.js → chunk.JQBP6QWQ.js} +1 -1
- package/dist/preview/chunk.JV7FLVUV.js +1 -0
- package/dist/preview/{chunk.SJKHVIHA.js → chunk.KFTZLNHY.js} +2 -2
- package/dist/preview/{chunk.NZDHXREL.js → chunk.KPUX27ZT.js} +1 -1
- package/dist/preview/chunk.KSJ3J5UN.js +1 -0
- package/dist/preview/chunk.LESRQN3Y.js +32 -0
- package/dist/preview/{chunk.CTOBNZLM.js → chunk.LSL25VXW.js} +1 -1
- package/dist/preview/{chunk.SRFZKDQ6.js → chunk.LTJYKQJG.js} +1 -1
- package/dist/preview/{chunk.32BOL7OL.js → chunk.LXJW2Z2M.js} +1 -1
- package/dist/preview/{chunk.WQLAIEWJ.js → chunk.M33LUF3Q.js} +1 -1
- package/dist/preview/{chunk.B6LKLV32.js → chunk.MBNZ2HK7.js} +1 -1
- package/dist/preview/{chunk.SJYQ72EC.js → chunk.MYKRJ4SV.js} +1 -1
- package/dist/preview/{chunk.UWFEXEY3.js → chunk.N7D5LKBI.js} +1 -1
- package/dist/preview/{chunk.AL7LFNOS.js → chunk.NAPTE3S6.js} +1 -1
- package/dist/preview/{chunk.MX3Y3LPH.js → chunk.NB6WN4DO.js} +1 -1
- package/dist/preview/{chunk.MN6WHE4B.js → chunk.NHIPVAGR.js} +1 -1
- package/dist/preview/chunk.NICCIJV4.js +1 -0
- package/dist/preview/{chunk.MRXQBEPQ.js → chunk.NQPNK6I5.js} +1 -1
- package/dist/preview/{chunk.MG3DMURZ.js → chunk.NVNQSZ43.js} +1 -1
- package/dist/preview/{chunk.CI4DEKPX.js → chunk.NWK4E7TJ.js} +1 -1
- package/dist/preview/{chunk.HASVT7IC.js → chunk.NZB5S5UO.js} +1 -1
- package/dist/preview/{chunk.WESWDXRW.js → chunk.OS3WZV6C.js} +1 -1
- package/dist/preview/{chunk.OU5TRY4N.js → chunk.OYRZ2DEI.js} +1 -1
- package/dist/preview/{chunk.4T67XS2D.js → chunk.P5PXWOHI.js} +1 -1
- package/dist/preview/{chunk.KYKHZZT7.js → chunk.PRCWGE7A.js} +1 -1
- package/dist/preview/{chunk.DUY27OJV.js → chunk.PXHBPLTQ.js} +1 -1
- package/dist/preview/chunk.PXVJBL2C.js +1 -0
- package/dist/preview/{chunk.V4GAOZAW.js → chunk.Q3XKNZQW.js} +1 -1
- package/dist/preview/chunk.Q5IAXTF5.js +25 -0
- package/dist/preview/{chunk.2534FLZZ.js → chunk.QPP3OJVR.js} +1 -1
- package/dist/preview/{chunk.GLTWLQ6L.js → chunk.QRCTTDDQ.js} +1 -1
- package/dist/preview/{chunk.CMEETACI.js → chunk.QWQBPJ4U.js} +1 -1
- package/dist/preview/chunk.QXCYAFRT.js +1 -0
- package/dist/preview/{chunk.ESK3UZRC.js → chunk.R6FHEEJ7.js} +1 -1
- package/dist/preview/{chunk.GMAXA5GV.js → chunk.R77TACXU.js} +1 -1
- package/dist/preview/{chunk.HFKGND5Q.js → chunk.R7CRV2FE.js} +1 -1
- package/dist/preview/{chunk.XWXYC3BJ.js → chunk.R7ZZJOJW.js} +1 -1
- package/dist/preview/{chunk.S32AGJ3W.js → chunk.RBWYXVUW.js} +1 -1
- package/dist/preview/{chunk.N5XONWU2.js → chunk.RMRO5JZX.js} +1 -1
- package/dist/preview/{chunk.FFCUZPTC.js → chunk.RWCWRJJC.js} +1 -1
- package/dist/preview/{chunk.CXC5FOIO.js → chunk.S4ZWBCYC.js} +1 -1
- package/dist/preview/{chunk.UVAWWCFW.js → chunk.SELLAVIQ.js} +1 -1
- package/dist/preview/{chunk.7NQROWHU.js → chunk.SM6HTPYF.js} +1 -1
- package/dist/preview/chunk.SZCZD2GM.js +1 -0
- package/dist/preview/{chunk.SPU3BVAO.js → chunk.T2Q3AAQI.js} +1 -1
- package/dist/preview/{chunk.BV6HKTHK.js → chunk.T6KKNWZT.js} +1 -1
- package/dist/preview/{chunk.76QSPWSJ.js → chunk.U6PCKJ26.js} +1 -1
- package/dist/preview/{chunk.FEIJ7ETK.js → chunk.UEPVA6IS.js} +1 -1
- package/dist/preview/{chunk.PYRJDTVS.js → chunk.ULAMIQ52.js} +1 -1
- package/dist/preview/chunk.UMS7XRPO.js +1 -0
- package/dist/preview/{chunk.RNOBACJ6.js → chunk.VGIWQNJB.js} +1 -1
- package/dist/preview/{chunk.3H7YIKKC.js → chunk.VGTEEANA.js} +1 -1
- package/dist/preview/{chunk.ZZODDJYK.js → chunk.VKOCD5CL.js} +1 -1
- package/dist/preview/{chunk.P4CLT32V.js → chunk.VOHRQXCF.js} +5 -5
- package/dist/preview/chunk.W5UJLKIT.js +1 -0
- package/dist/preview/{chunk.E2R6VFZX.js → chunk.WUEU3QBL.js} +1 -1
- package/dist/preview/{chunk.34HGT7HQ.js → chunk.WWUMSCYC.js} +1 -1
- package/dist/preview/{chunk.3MU37W5D.js → chunk.XLM4ONUB.js} +1 -1
- package/dist/preview/{chunk.TVWN5I4M.js → chunk.XPR3QFF4.js} +1 -1
- package/dist/preview/{chunk.BYY7YXBI.js → chunk.XZLKTOJE.js} +1 -1
- package/dist/preview/{chunk.LYIHPVDZ.js → chunk.Y37DXEHG.js} +1 -1
- package/dist/preview/{chunk.OW72XZF4.js → chunk.YKACMLLU.js} +1 -1
- package/dist/preview/{chunk.DEH6O3K4.js → chunk.YKXUDACI.js} +1 -1
- package/dist/preview/{chunk.7G4M2PX3.js → chunk.YUEOUV7G.js} +2 -2
- package/dist/preview/chunk.YYWLYVAW.js +1 -0
- package/dist/preview/chunk.Z2JMTRF4.js +1 -0
- package/dist/preview/{chunk.SKG4IHT5.js → chunk.Z2UFPOAN.js} +1 -1
- package/dist/preview/chunk.ZEKKIMKI.js +1 -0
- package/dist/preview/{chunk.RMMJQYJJ.js → chunk.ZK42LPF5.js} +1 -1
- package/dist/preview/{chunk.GRYS6VSF.js → chunk.ZZGXVYW2.js} +1 -1
- package/dist/preview/index.html +50 -50
- package/dist/preview/page.js +2 -2
- package/package.json +6 -6
- package/dist/preview/chunk.3SBTQ66X.js +0 -1
- package/dist/preview/chunk.4N5R4K6O.js +0 -1
- package/dist/preview/chunk.AJAMTRZ3.js +0 -1
- package/dist/preview/chunk.AL45OI4A.js +0 -1
- package/dist/preview/chunk.CUB4IAUJ.js +0 -1
- package/dist/preview/chunk.CUN4VN42.js +0 -1
- package/dist/preview/chunk.ET3XJDPX.js +0 -1
- package/dist/preview/chunk.FG5ZFYYL.js +0 -1
- package/dist/preview/chunk.FTBH7CPZ.js +0 -1
- package/dist/preview/chunk.GYTVL6GR.js +0 -359
- package/dist/preview/chunk.JBR66TUP.js +0 -1
- package/dist/preview/chunk.JG2FGZF2.js +0 -18
- package/dist/preview/chunk.MMVCZOEX.js +0 -32
- package/dist/preview/chunk.NNUUD26E.js +0 -1
- package/dist/preview/chunk.QEQQXWYU.js +0 -1
- package/dist/preview/chunk.QPAJCRFB.js +0 -1
- package/dist/preview/chunk.S4CKKT3C.js +0 -1
- package/dist/preview/chunk.TMYGLXR6.js +0 -25
- package/dist/preview/chunk.UCUWEYKM.js +0 -1
- package/dist/preview/chunk.XZVPVAIS.js +0 -1
- package/dist/preview/chunk.Y2ZBVWII.js +0 -1
- package/dist/preview/chunk.Y3LTHEN7.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{a as Ue}from"./chunk.3TVAE7LE.js";import{a as Be}from"./chunk.3MU37W5D.js";import{a as We}from"./chunk.6KYWJXZR.js";import{a as X}from"./chunk.TI4OSTQV.js";import{a as fe}from"./chunk.ACB4TD4W.js";import{e as ce}from"./chunk.GYTVL6GR.js";import{E as we,G as ln,J as He,P as Le,T as Fe,aa as Je}from"./chunk.TMYGLXR6.js";import{Ob as Ne,Oc as De,Yb as le,_b as je,da as ae,fa as U,ha as q,ka as Ee,ma as de,wb as Me}from"./chunk.P4CLT32V.js";import{b as Se}from"./chunk.AJZBJBMO.js";var cn=e=>/^(?:aggregate|kind):([^,]+)$/.exec(e)?.[1];function Ge(e,n){let t=e.about??[];if(e.field!==void 0&&e.on!==void 0&&n(e.on))return{on:"field",id:e.on,field:e.field};let i=t.filter(n);if(i.length>1)return{on:"selection",ids:i};if(e.on!==void 0&&n(e.on))return{on:"record",id:e.on};if(i.length===1)return{on:"record",id:i[0]};let o=[e.on,...t].map(s=>s===void 0?void 0:cn(s)).find(s=>s!==void 0);return e.place!==void 0?{on:"lens",place:e.place,...o?{kind:o}:{}}:o!==void 0?{on:"list",kind:o}:{on:"place",place:"home"}}var V=e=>e.on==="record"||e.on==="field"?[e.id]:e.on==="selection"?e.ids:e.on==="act"&&e.id!==void 0?[e.id]:[],ue=(e,n)=>e.tryDefinition(n)?.fields?.shape??{},K=(e,n)=>e.tryDefinition(n)?.edges??{},pe=(e,n)=>new Set(e.tryDefinition(n)?.display?.hide??[]),H=(e,n)=>ae(e.tryDefinition(n.kind),n),xe=(e,n,t)=>Ee(e.tryDefinition(n),t)||U(t),Oe=e=>typeof e=="boolean"?e?"yes":"no":String(e);function ge(e,n){let t=e.kindsKeptFrom(n);return new Set(e.schema.kinds.filter(i=>!t.has(i)))}function Ce(e,n,t,i){if(!e.permits(n,t).ok)return!1;if(!i)return!0;try{return e.previewAll([n],{author:t}).ops.length>0}catch{return!1}}function ye(e,n,t){let i=e,{principal:o}=t,s=t.each??8,c=X(i)?.store??i,d=c.seenBy(o),l=c.schema,p=ge(c,o),a=r=>{let y=d.graph.getNode(r);return y&&p.has(y.kind)?y:void 0},f=c.allMutations(),h=new Map(f.map(r=>[r.name,r])),b=[],P=new Set,S=r=>{P.has(r.id)||(P.add(r.id),b.push(r))},m=r=>r.slice(0,s),C=V(n).filter(r=>a(r)!==void 0);if(V(n).length>0&&C.length===0)return{target:n,candidates:[]};let k=C.length===1?a(C[0]):void 0,g=k?.kind??(n.on==="list"?n.kind:n.on==="lens"?n.kind??t.places?.find(r=>r.as===n.place)?.kind:void 0)??(n.on==="selection"?a(C[0])?.kind:void 0);if(g!==void 0&&!p.has(g))return{target:n,candidates:[]};let A=(r,y)=>`act:${r}${Object.keys(y).length>0?`:${Object.values(y).map(T=>String(T)).join(",")}`:""}`,w=(r,y,T,v,$)=>{r.destructive||Object.values(y).some(u=>typeof u=="string"&&c.graph.has(u)&&a(u)===void 0)||Ce(c,{name:r.name,args:{...y}},o,v.length===0)&&S({type:"act",id:A(r.name,y),label:T,description:$??r.description??T,mutation:r.name,args:y,asks:v})};if(n.on!=="place"||t.acts)if(t.acts)for(let r of t.acts){let y=h.get(r.mutation);!y||r.destructive||n.on==="act"&&r.mutation!==n.act||w(y,r.args,r.label,(r.open??[]).filter(T=>!T.optional).map(T=>T.name),r.why)}else{let r=k?[k]:[];for(let y of f){if(n.on==="act"&&y.name!==n.act)continue;let T=y.input.shape??{},v=$=>Object.entries(T).filter(([u,O])=>u!==$&&O.safeParse?.(void 0).success===!1).map(([u])=>u);if(y.subject)for(let $ of r)le(l,y).includes($.kind)&&w(y,{[y.subject.arg]:$.id},`${y.title??U(y.name)}: ${H(l,$)}`,v(y.subject.arg));else g!==void 0&&(y.creates??[]).includes(g)&&w(y,{},y.title??U(y.name),v(void 0))}}let M=b.filter(r=>r.type==="act");b.splice(0,b.length,...m(M));let L=(r,y)=>{let T=je(l,f).get(r.kind),v=ue(l,r.kind),$=pe(l,r.kind),u=[];for(let[O,j]of Object.entries(v)){if(y!==void 0?O!==y:$.has(O)||r[O]!==void 0)continue;let D=fe(j),z=D?.type==="enum"?D.options??[]:D?.type==="boolean"?[!0,!1]:[];if(z.length===0)continue;let W=(T?.get(O)??[]).map(N=>h.get(N)).find(N=>N?.subject!==void 0&&Ce(c,{name:N.name,args:{[N.subject.arg]:r.id,[O]:z.find(Ae=>Ae!==r[O])??z[0]}},o,!0));if(W?.subject)for(let N of z)r[O]!==N&&u.push({type:"fill",id:`fill:${r.id}:${O}:${Oe(N)}`,label:`${xe(l,r.kind,O)}: ${Oe(N)}`,description:`Set ${xe(l,r.kind,O).toLowerCase()} of ${H(l,r)} to ${Oe(N)}`,record:r.id,field:O,value:N,call:{name:W.name,args:{[W.subject.arg]:r.id,[O]:N}}})}for(let[O,j]of Object.entries(K(l,r.kind))){if(y!==void 0&&O!==y)continue;let D=j.to==="*"?[...p]:j.to.filter(R=>p.has(R)),z=new Set(d.graph.out(r.id,O).map(R=>R.id)),W=f.find(R=>(R.connects??[]).includes(O)&&R.subject!==void 0&&le(l,R).includes(r.kind));if(!W?.subject)continue;let N=Ne(W.input).find(R=>R.name!==W.subject.arg);if(!N)continue;let Ae=D.flatMap(R=>N.kinds.length===0||N.kinds.includes(R)?d.graph.nodesOfKind(R):[]).filter(R=>R.id!==r.id&&!z.has(R.id)&&a(R.id)!==void 0);for(let R of m(Ae)){let Re={name:W.name,args:{[W.subject.arg]:r.id,[N.name]:R.id}};Ce(c,Re,o,!0)&&u.push({type:"fill",id:`fill:${r.id}:${O}:${R.id}`,label:`${U(O)}: ${H(l,R)}`,description:`Link ${H(l,r)} to ${H(l,R)}${j.description?` as ${j.description}`:""}`,record:r.id,field:O,value:R.id,call:Re})}}return u};if(n.on==="field"&&k)for(let r of L(k,n.field))S(r);else if(k&&n.on==="record")for(let r of m(L(k)))S(r);let J=r=>{let y=q(l,r).toLowerCase(),T=[{type:"panel",id:`panel:${r}:list`,label:`A list of ${y}`,description:`Every ${de(l.tryDefinition(r),r).toLowerCase()} this viewer may see, as a list`,panel:{lens:"blocks",kind:r}}],v=pe(l,r);for(let[$,u]of Object.entries(ue(l,r))){if(v.has($))continue;let O=fe(u),j=xe(l,r,$).toLowerCase();if(O?.type==="enum")T.push({type:"panel",id:`panel:${r}:group:${$}`,label:`${_(y)} by ${j}`,description:`A list of ${y} grouped by ${j}`,panel:{lens:"blocks",kind:r,group:$}}),T.push({type:"panel",id:`panel:${r}:columns:${$}`,label:`Columns of ${y} by ${j}`,description:`${_(y)} in a column for each ${j}`,panel:{lens:"columns",kind:r,column:$}});else if(O?.type==="number"||O?.type==="integer"||O?.type==="date"||O?.type==="datetime"){let D=O.type==="date"||O.type==="datetime";T.push({type:"panel",id:`panel:${r}:sort:${$}`,label:`${_(y)} by ${j}`,description:`A list of ${y}, the ${D?"latest":"highest"} ${j} first`,panel:{lens:"blocks",kind:r,sort:{by:$,direction:"desc"}}}),D&&T.push({type:"panel",id:`panel:${r}:calendar:${$}`,label:`A calendar of ${y}`,description:`${_(y)} on a calendar by ${j}`,panel:{lens:"calendar",kind:r,start:$}})}}return T},F=n.on==="place"?[...p]:g!==void 0?[g]:[];for(let r of F)for(let y of m(J(r)))S(y);for(let r of m((t.places??[]).filter(y=>y.kind===void 0?n.on==="place":p.has(y.kind)&&(n.on==="place"||y.kind===g))))n.on==="lens"&&r.as===n.place||S({type:"place",id:`place:${r.as}`,label:r.title,description:`Go to ${r.title}`,place:r.as});if(k){let r=[];for(let[y,T]of Object.entries(K(l,k.kind)))for(let v of d.graph.out(k.id,y))a(v.id)&&r.push({type:"record",id:`record:${v.id}`,label:H(l,v),description:`${_(T.description??U(y))}: ${H(l,v)}`,record:v.id,relation:y});for(let y of l.kinds)for(let[T,v]of Object.entries(K(l,y)))if(!(v.to!=="*"&&!v.to.includes(k.kind)))for(let $ of d.graph.in(k.id,T))$.kind===y&&a($.id)&&r.push({type:"record",id:`record:${$.id}`,label:H(l,$),description:`${_(v.inverse??U(T))}: ${H(l,$)}`,record:$.id,relation:T});for(let y of m(r))S(y)}else if(n.on==="list"||n.on==="lens")for(let r of m(g!==void 0?d.graph.nodesOfKind(g):[]))a(r.id)&&S({type:"record",id:`record:${r.id}`,label:H(l,r),description:`Open ${H(l,r)}`,record:r.id});else if(n.on==="selection")for(let r of C){let y=a(r);S({type:"record",id:`record:${r}`,label:H(l,y),description:`Open ${H(l,y)}`,record:r})}return{target:n,candidates:b}}var _=e=>e&&`${e[0].toUpperCase()}${e.slice(1)}`,fn={columns:["board","kanban","column","lane","pipeline","stage","funnel"],board:["board","map","floor","layout","seat","slot"],calendar:["calendar","schedule","date","due","month","week","agenda","deadline","day"],timeline:["timeline","gantt","schedule","roadmap","span"],coverage:["coverage","matrix","grid","gap"],plan:["plan","floor","map","region","area"],blocks:["list","table","summary","overview","dashboard","card"]},un=new Set(["a","an","the","of","for","my","our","me","us","to","with","and","in","on","by","that","which","i","we","want","need","show","open","go","draw","make","new","view","views","panel","panels","page","lens","please","all","every","some","see","can","could","would","like","one","what","is","are","do","does","here","there","how","it","this","these","those"]),Z=e=>e.length>3&&e.endsWith("ies")?`${e.slice(0,-3)}y`:e.length>3&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):e,$e=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").split(/[^a-z0-9]+/).filter(Boolean);function ze(e,n,t){let i=e,o=X(i)?.store??i,s=o.schema,c=ge(o,t.principal),d=o.seenBy(t.principal),l=V(n),p=new Set;for(let A of l){let w=d.graph.getNode(A)?.kind;w!==void 0&&c.has(w)&&p.add(w)}if(l.length>0&&p.size===0)return[];if(n.on==="list"&&p.add(n.kind),n.on==="lens"){let A=n.kind??t.places.find(w=>w.as===n.place)?.kind;A!==void 0&&p.add(A)}let a=new Map;for(let A of s.kinds){if(!c.has(A))continue;let w=s.tryDefinition(A);for(let M of[A,de(w,A),q(s,A)])for(let L of $e(M))a.set(Z(L),A)}let f=$e(t.said??"").filter(A=>!un.has(A)),h=new Set,b=[];for(let A of f){let w=a.get(Z(A));w!==void 0?h.add(w):b.push(Z(A))}let P=h.size>0?h:p;if((t.said??"").trim()!==""&&f.length===0)return[];if(P.size===0&&f.length===0)return[];let S=[];t.places.forEach((A,w)=>{if(A.hidden||n.on==="lens"&&A.as===n.place)return;let M=A.over??(A.kind!==void 0?[A.kind]:[]);if(M.length>0&&!M.some(F=>c.has(F)))return;let L=M.some(F=>P.has(F)),J=!L&&(A.reads??[]).some(F=>P.has(F));P.size>0&&!L&&!J||S.push({place:A,own:L,reads:J,at:w})});let m=A=>new Set($e(A.title).map(Z)),C=new Set(b.filter(A=>S.some(({place:w})=>m(w).has(A)))),k=[];for(let{place:A,own:w,reads:M,at:L}of S){let J=m(A),F=new Set((fn[A.lens??""]??[]).map(Z)),r=b.filter($=>J.has($)||F.has($)&&!C.has($)).length,y=b.length-r;if(b.length>0&&r===0)continue;let T=!M&&y===0?"full":"partial",v=(w?4:M?2:1)+r*2-y+(T==="full"?1:0);k.push({view:{place:A.as,title:A.title,...A.kind!==void 0?{kind:A.kind}:{},fit:T},score:v,at:L})}return k.filter((A,w)=>!k.slice(0,w).some(M=>M.view.place===A.view.place&&M.view.title===A.view.title)).sort((A,w)=>w.score-A.score||A.at-w.at).slice(0,t.most??3).map(A=>A.view)}var Pe=new WeakMap;function pn(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619)>>>0;return n.toString(36)}function gn(e,n){let t=e,i=X(t)?.store??t,o=i.schema,s=ge(i,n),d=i.allMutations().filter(S=>!S.destructive&&i.permits({name:S.name,args:{}},n).ok!==!1),l=`${[...s].join(",")}|${d.map(S=>S.name).join(",")}`,p=Pe.get(o)?.get(l);if(p)return p;let a=[...s].map(S=>{let m=pe(o,S),C={};for(let[g,A]of Object.entries(ue(o,S))){if(m.has(g))continue;let w=fe(A);w&&(C[g]=w.type==="enum"?`enum:${(w.options??[]).join("|")}`:w.type)}let k={};for(let[g,A]of Object.entries(K(o,S)))k[g]=A.to==="*"?[...s]:A.to.filter(w=>s.has(w));return{kind:S,noun:de(o.tryDefinition(S),S),plural:q(o,S),fields:C,relations:k}}),f=d.map(S=>({name:S.name,title:S.title??U(S.name),...S.subject?{on:le(o,S).filter(m=>s.has(m))}:{}})),h={kinds:a,acts:f},b={version:pn(JSON.stringify(h)),...h},P=Pe.get(o)??new Map;return P.set(l,b),Pe.set(o,P),b}var yn=e=>e.name??e.id??e.kind;function qe(e,n,t){let i=e,{principal:o}=t,s=X(i)?.store??i,c=s.seenBy(o),d=s.schema,l=ge(s,o),p=k=>{let g=c.graph.getNode(k);return g&&l.has(g.kind)?g:void 0},a=k=>({id:k.id,kind:k.kind,label:H(d,k)}),f=V(n),h=f.length===1?p(f[0]):void 0,b=h?Object.fromEntries(Object.keys(ue(d,h.kind)).filter(k=>!pe(d,h.kind).has(k)&&h[k]!==void 0&&k!=="label").map(k=>[k,h[k]])):{},P={on:n.on,...h?{record:{...a(h),fields:b}}:{},...n.on==="field"&&h?{field:n.field}:{},...n.on==="list"&&l.has(n.kind)?{kind:n.kind}:{},...n.on==="lens"?{place:n.place,...n.kind&&l.has(n.kind)?{kind:n.kind}:{}}:{},...n.on==="place"?{place:n.place}:{},...n.on==="act"?{act:n.act}:{}},S=[...new Set([...n.on==="selection"?n.ids:[],...t.selection??[]])].flatMap(k=>{let g=p(k);return g?[a(g)]:[]}),m=[];if(h){for(let k of Object.keys(K(d,h.kind)))for(let g of c.graph.out(h.id,k))p(g.id)&&m.push({...a(g),relation:k,direction:"out"});for(let k of d.kinds)for(let g of Object.keys(K(d,k)))for(let A of c.graph.in(h.id,g))A.kind===k&&p(A.id)&&m.push({...a(A),relation:g,direction:"in"})}let C=c.batches().filter(k=>!k.ops.every(Me)).slice(-(t.recent??6)).reverse().map(k=>({intent:k.intent,at:k.at,by:yn(k.author)}));return{...t.place!==void 0?{place:t.place}:{},target:P,selection:S,neighbors:m.slice(0,24),recent:C,schema:gn(s,o)}}function ee(e){if(!e.off)return e.fast??(e.decide?{model:e.name??"decide",decide:e.decide}:void 0)}function B(e){if(e.off)return;if(e.thinking)return e.thinking;let n=e.name??"model";if(e.complete){let t=e.complete;return{model:n,think:({system:i,prompt:o})=>t({prompt:o,system:i})}}if(e.turn){let t=e.turn;return{model:n,think:async({system:i,prompt:o})=>({text:await t({system:i,messages:[{role:"user",content:o}],tools:[],call:async()=>({error:"No tools here."})})})}}}var Te=(e,n,t)=>e?n/1e6*(e.inputPerMillion??0)+t/1e6*(e.outputPerMillion??0):void 0,ve=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function hn(e,n,t=[]){let i=o=>{let s=e.graph.getNode(o);return s?ae(e.schema.tryDefinition(s.kind),s):"a record"};switch(n.on){case"record":return i(n.id);case"field":return`${i(n.id)} \xB7 ${n.field}`;case"selection":return`${n.ids.length} records`;case"list":return e.schema.tryDefinition(n.kind)?q(e.schema,n.kind):n.kind;case"lens":case"place":return t.find(o=>o.as===n.place)?.title??(n.place==="home"?"Home":n.place);case"act":return n.act}}var _e=e=>e.type!=="act"||e.asks.length===0,me=(e,n)=>({id:e.id,type:e.type,label:e.label,...n!==void 0?{confidence:n}:{}});function Q(e,n){let t=n.interaction??ve(),i=ye(n.store,n.target,{principal:n.principal,...n.acts?{acts:n.acts}:{},...n.places?{places:n.places}:{}}),o=qe(n.store,n.target,{principal:n.principal,...n.place?{place:n.place}:{},...n.selection?{selection:n.selection}:{}}),s=[];return{id:t,catalog:i,state:o,entry:{id:t,at:new Date().toISOString(),by:n.by??n.principal,target:n.target,targetLabel:hn(n.store,n.target,n.places)},usage:s,meter:c=>{s.push(c),e.meter?.({...c,interaction:t})}}}async function ne(e,n,t,i){let o=await e.decide(n,t),{inputTokens:s,outputTokens:c}=o.usage,d=Te(e.price,s,c);return i({tier:"fast",model:e.model,inputTokens:s,outputTokens:c,...d!==void 0?{costUsd:d}:{}}),o.answers}async function te(e,n,t,i,o){let s=await e.think({system:n,prompt:t,state:i.state,catalog:i.catalog}),c=s.usage?.inputTokens,d=s.usage?.outputTokens,l=s.usage?.costUsd??(c!==void 0?Te(e.price,c,d??0):void 0);return o({tier:"thinking",model:e.model,...c!==void 0?{inputTokens:c}:{},...d!==void 0?{outputTokens:d}:{},...l!==void 0?{costUsd:l}:{}}),Be(s.text)}function ie(e,n){let t=new Map(e.map((i,o)=>[`c${o+1}`,i]));return{question:{type:"choice",instructions:n,criteria:Object.fromEntries([...t].map(([i,o])=>[i,`${o.label} \u2014 ${o.description}`]))},of:i=>t.get(i)}}function oe(e,n,t){if(e?.type!=="choice")return[];let i=e,o=Object.entries(i.probabilities).sort((s,c)=>c[1]-s[1]);return o.some(([s])=>s===i.choice)||o.unshift([i.choice,i.confidence]),o.flatMap(([s,c])=>{let d=n(s);return d?[{candidate:d,confidence:c}]:[]}).slice(0,t)}var E=(e,n,t,i)=>({interaction:{...e.entry,ask:{kind:t,said:n??""},offered:[],outcome:"failed",failed:i,usage:[...e.usage]},offers:[]}),Y="AI isn't on here.";async function Ke(e,n,t=3){let i=Q(e,n),o=n.said??"Suggest",s=i.catalog.candidates.filter(_e).slice(0,24);if(s.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let c=ee(e),d=B(e),l=[];try{if(c){let{question:p,of:a}=ie(s,"Which of these would the person most likely want to do next, here?"),f=await ne(c,{...i.state,candidates:s.map(h=>({id:h.id,type:h.type,says:h.description}))},{next:p},i.meter);l=oe(f.next,a,t)}else if(d){let p=await te(d,'You suggest what a person most likely wants to do next in an app. Answer only JSON: {"pick": [candidate ids, best first]}. Pick only ids from the candidates.',JSON.stringify({state:i.state,candidates:s.map(f=>({id:f.id,says:f.description}))}),i,i.meter);l=(Array.isArray(p?.pick)?p.pick.filter(f=>typeof f=="string"):[]).flatMap(f=>s.filter(h=>h.id===f)).slice(0,t).map(f=>({candidate:f}))}else return E(i,o,"suggest",Y)}catch(p){return E(i,o,"suggest",p instanceof Error?p.message:String(p))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:l.map(({candidate:p,confidence:a})=>me(p,a)),outcome:"offered",usage:[...i.usage]},offers:l.map(({candidate:p})=>p)}}var mn=e=>`several:${e}`;async function Fn(e,n,t=2){let i=Q(e,{...n,acts:[]}),o=n.said??"Suggest for the chosen",s=n.target.on==="selection"?n.target.ids.length:1,d=[...n.shared.map(a=>({type:"act",id:mn(a.id),label:a.label,description:`${a.label}, for all ${s} chosen`,mutation:a.mutation,args:a.args,asks:[]})),...i.catalog.candidates.filter(a=>a.type==="panel"||a.type==="place")].slice(0,24),l=ee(e);if(!l)return E(i,o,"suggest",Y);if(d.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let p;try{let{question:a,of:f}=ie(d,`Which of these would the person most likely want to do next with the ${s} records they chose together?`),h=await ne(l,{...i.state,candidates:d.map(b=>({id:b.id,type:b.type,says:b.description}))},{next:a},i.meter);p=oe(h.next,f,t).filter((b,P)=>P===0||b.confidence>=kn)}catch(a){return E(i,o,"suggest",a instanceof Error?a.message:String(a))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:p.map(({candidate:a,confidence:f})=>me(a,f)),outcome:"offered",usage:[...i.usage]},offers:p.map(({candidate:a})=>a)}}var kn=.25;async function Ve(e,n){let t=Q(e,n),i=n.said??"Fill in",o=t.catalog.candidates.filter(f=>f.type==="fill"),s=new Map;for(let f of o)s.set(f.field,[...s.get(f.field)??[],f]);if(s.size===0)return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let c=ee(e),d=B(e),l=[];try{if(c){let f=[...s].map(([b,P],S)=>({key:`f${S+1}`,field:b,...ie(P,`Which value fits "${b}" best for this record?`)})),h=await ne(c,t.state,Object.fromEntries(f.map(b=>[b.key,b.question])),t.meter);for(let b of f){let P=!bn(n.store,n.target,b.field)&&An(n.store,n.target,b.field)!=="one";l.push(...oe(h[b.key],b.of,P?3:1).filter((S,m)=>m===0||S.confidence>=.4))}}else if(d){let f=await te(d,`You fill in a record's fields in an app. Answer only JSON: {"fills": [candidate ids]}, at most one per field, only ids from the candidates.`,JSON.stringify({state:t.state,candidates:o.map(P=>({id:P.id,says:P.description}))}),t,t.meter),h=Array.isArray(f?.fills)?f.fills.filter(P=>typeof P=="string"):[],b=new Set;for(let P of h){let S=o.find(m=>m.id===P);S?.type==="fill"&&!b.has(S.field)&&(b.add(S.field),l.push({candidate:S}))}}else return E(t,i,"fill",Y)}catch(f){return E(t,i,"fill",f instanceof Error?f.message:String(f))}let p=t.usage.at(-1)?.model,a=se(n.store,{interaction:t.id,target:n.target,basis:i,...p?{model:p}:{},proposals:l.flatMap(({candidate:f,confidence:h})=>f.type==="fill"?[{id:f.id,label:f.label,said:f.description,call:f.call,record:f.record,field:f.field,...h!==void 0?{confidence:h}:{}}]:[])},n.principal);return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:a.proposals.map(f=>({id:f.id,type:"fill",label:f.label,...f.confidence!==void 0?{confidence:f.confidence}:{}})),outcome:"offered",usage:[...t.usage]},offers:[],...a.proposals.length>0?{ghost:a}:{}}}function bn(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0,s=(o?e.schema.tryDefinition(o)?.fields?.shape:void 0)??{};return t in s}function An(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0;return o?e.schema.tryDefinition(o)?.edges?.[t]?.cardinality:void 0}async function Qe(e,n){let t=Q(e,n),i=n.said??"Add one",o=new Set(n.store.allMutations().filter(a=>(a.creates??[]).length>0).map(a=>a.name)),s=t.catalog.candidates.filter(a=>a.type==="act"&&a.asks.length>0&&o.has(a.mutation));if(s.length===0)return E(t,i,"record","Nothing here makes a record.");let c=B(e);if(!c)return E(t,i,"record",Y);let d;try{let a=await te(c,'You propose one new record for an app by filling in an act. Answer only JSON: {"act": a candidate id, "args": {argument: value}}. Use only the candidates, and fill every argument the act asks for with a value that fits the state.',JSON.stringify({ask:i,state:t.state,candidates:s.map(b=>({id:b.id,says:b.description,asks:b.asks}))}),t,t.meter),f=s.find(b=>b.id===a?.act),h=typeof a?.args=="object"&&a.args!==null?a.args:{};f&&(d={act:f,args:Object.fromEntries(Object.entries(h).filter(([b])=>f.asks.includes(b)))})}catch(a){return E(t,i,"record",a instanceof Error?a.message:String(a))}if(!d)return E(t,i,"record","The model named no act this app has here.");let l=t.usage.at(-1)?.model,p=se(n.store,{interaction:t.id,target:n.target,basis:i,...l?{model:l}:{},proposals:[{id:d.act.id,label:d.act.label,said:d.act.description,call:{name:d.act.mutation,args:{...d.act.args,...d.args}}}]},n.principal);return p.proposals.length===0?E(t,i,"record","What the model proposed could not be made here."):{interaction:{...t.entry,ask:{kind:"record",said:i},offered:p.proposals.map(a=>({id:a.id,type:"act",label:a.said})),outcome:"offered",usage:[...t.usage]},offers:[d.act],ghost:p}}async function Ye(e,n){let t=Q(e,n),i=n.said??"Make a panel",o=t.catalog.candidates.filter(a=>a.type==="panel");if(o.length===0)return E(t,i,"panel","Nothing here can be drawn as a panel.");let s=ee(e),c=B(e),d;try{if(c){let a=await te(c,'You choose a panel to draw in an app. Answer only JSON: {"panel": a candidate id, "title": a short title}. Choose only among the candidates.',JSON.stringify({ask:i,state:t.state,candidates:o.map(h=>({id:h.id,says:h.description}))}),t,t.meter),f=o.find(h=>h.id===a?.panel);f&&(d={panel:f,...typeof a?.title=="string"&&a.title.trim()?{title:a.title.trim().slice(0,60)}:{}})}else if(s){let{question:a,of:f}=ie(o,`Which panel answers this best: ${i}`),h=oe((await ne(s,t.state,{panel:a},t.meter)).panel,f,1)[0];h?.candidate.type==="panel"&&(d={panel:h.candidate,confidence:h.confidence})}else return E(t,i,"panel",Y)}catch(a){return E(t,i,"panel",a instanceof Error?a.message:String(a))}if(!d)return E(t,i,"panel","The model named no panel this app can draw.");let l=d.title??d.panel.label,p={title:l,recipe:{...d.panel.panel,title:l}};return{interaction:{...t.entry,ask:{kind:"panel",said:i},offered:[me(d.panel,d.confidence)],outcome:"drawn",panel:p,usage:[...t.usage]},offers:[d.panel],panel:p}}function Sn(e){return e.off?void 0:e.answer}var wn=`You answer a person's question about what they are looking at in an app, from the state given and nothing else. Answer only JSON: {"answer": one to three short sentences, "pick": [candidate ids that act on the answer, best first, at most three]}. Pick only ids from the candidates, and none when nothing fits. Never say an id to the person.`;async function Jn(e,n){let t=Q(e,n),i=n.said.trim(),o=t.catalog.candidates.filter(m=>_e(m)||m.type==="panel"||m.type==="place"||m.type==="record").slice(0,32),s=Sn(e),c=B(e),d=ee(e),l="",p=[],a=m=>m.flatMap(C=>o.filter(k=>k.id===C)).slice(0,3).map(C=>({candidate:C}));try{if(s){let m=await s.answer({said:i,target:n.target,targetLabel:t.entry.targetLabel,state:t.state,catalog:{target:t.catalog.target,candidates:o},...n.follows?{follows:n.follows}:{}}),C=m.usage?.inputTokens,k=m.usage?.outputTokens,g=m.usage?.costUsd??(C!==void 0?Te(s.price,C,k??0):void 0);t.meter({tier:"thinking",model:s.model,...C!==void 0?{inputTokens:C}:{},...k!==void 0?{outputTokens:k}:{},...g!==void 0?{costUsd:g}:{}}),l=typeof m.text=="string"?m.text.trim():"",p=a(m.pick??[])}else if(c){let m=await te(c,wn,JSON.stringify({ask:i,about:t.entry.targetLabel,...n.follows?{follows:n.follows}:{},state:t.state,candidates:o.map(C=>({id:C.id,says:C.description}))}),t,t.meter);l=typeof m?.answer=="string"?m.answer.trim():"",p=a(Array.isArray(m?.pick)?m.pick:[])}else if(d&&o.length>0){let{question:m,of:C}=ie(o,`Which of these best answers, or acts on: ${i}`),k=await ne(d,{...t.state,asked:i,candidates:o.map(g=>({id:g.id,type:g.type,says:g.description}))},{answer:m},t.meter);p=oe(k.answer,C,3),l=p.length>0?`These fit \u201C${i}\u201D.`:""}else return E(t,i,"ask",Y)}catch(m){return E(t,i,"ask",m instanceof Error?m.message:String(m))}if(!l&&p.length===0)return E(t,i,"ask","The AI had no answer to that here.");let f=t.usage.at(-1)?.model,h=p.flatMap(({candidate:m,confidence:C})=>{let k=he(m);return k?[{...k,...C!==void 0?{confidence:C}:{}}]:[]}),b=h.length>0?se(n.store,{interaction:t.id,target:n.target,basis:i,...f?{model:f}:{},proposals:h},n.principal):void 0,P=p.map(({candidate:m})=>m).filter(m=>he(m)===void 0),S=[...P.map(m=>me(m,p.find(C=>C.candidate===m)?.confidence)),...(b?.proposals??[]).map(m=>({id:m.id,type:m.field!==void 0?"fill":"act",label:m.label,...m.confidence!==void 0?{confidence:m.confidence}:{}}))];return{interaction:{...t.entry,ask:{kind:"ask",said:i},offered:S,outcome:"offered",...l?{answer:l}:{},usage:[...t.usage]},offers:P,...b&&b.proposals.length>0?{ghost:b}:{},...l?{answer:l}:{}}}function se(e,n,t){let i=n.proposals.flatMap(o=>{try{let s=e.previewAll([o.call],{author:t}),c=s.ops.map(d=>d.intent).join("; ");return s.ops.length>0?[{...o,said:c||o.said}]:[]}catch{return[]}});return{...n,proposals:i}}function he(e){if(e.type==="fill")return{id:e.id,label:e.label,said:e.description,call:e.call,record:e.record,field:e.field};if(e.type==="act"&&e.asks.length===0)return{id:e.id,label:e.label,said:e.description,call:{name:e.mutation,args:{...e.args}}}}function Xe(e,n,t){let i=n.proposals.filter(s=>t.ids===void 0||t.ids.includes(s.id));if(i.length===0)return{ok:!1,refused:"Nothing was chosen."};let o=i.flatMap(s=>s.confidence===void 0?[]:[s.confidence]);try{let c=e.applyAll(i.map(d=>d.call),{author:t.author,via:`ai:${n.interaction}`,intent:n.basis,lineage:{basis:`Asked \u201C${n.basis}\u201D`,...n.model?{model:n.model}:{},...o.length>0?{confidence:Math.min(...o)}:{},interaction:n.interaction}}).ops[0]?.batch;return c?{ok:!0,batch:c,accepted:i.map(d=>d.id)}:{ok:!1,refused:"That changes nothing now."}}catch(s){return{ok:!1,refused:s instanceof Error?s.message:String(s)}}}function Ze(e,n,t){let i=e.ask.kind==="suggest"?n.length>0:e.offered.length>0&&e.offered.every(o=>n.includes(o.id));return{...e,outcome:i?"accepted":"partly",accepted:n,batches:[...e.batches??[],t]}}var en=e=>({...e,outcome:"dismissed"});var I=Se(ln(),1);var x=Se(Fe(),1);function tn(e,n,t){let i=n.on==="selection"?n.ids:n.on==="record"||n.on==="field"?[n.id]:[],o=i.length>0?Ue(e.store,i,{principal:e.principal,...i.length===1?{focus:i[0]}:{}}).affordances.map(s=>({mutation:s.mutation,label:s.label,args:s.args,open:s.open,why:s.why,...s.destructive?{destructive:!0}:{}})):void 0;return{store:e.store,target:n,principal:e.principal,interaction:ve(),places:e.places,selection:e.selection,...o?{acts:o}:{},...e.place?{place:e.place}:{},...t?{said:t}:{}}}async function on(e,n,t){let i=await (__graviewPreload(import.meta.url,["./chunk.EA2NMVRE.js","./chunk.G4JJXA63.js","./chunk.3H7YIKKC.js","./chunk.ET3XJDPX.js","./chunk.3MU37W5D.js","./chunk.XOZU4OFA.js","./chunk.Z7N3MJ36.js","./chunk.Q5WEOX3Q.js","./chunk.JBR66TUP.js","./chunk.76QSPWSJ.js","./chunk.HVX7LFWR.js","./chunk.WVUJXDXZ.js","./chunk.GLTWLQ6L.js","./chunk.ACB4TD4W.js","./chunk.XCQ7ZPR5.js","./chunk.MY5OXSS7.js","./chunk.NVRK6A7T.js","./chunk.FKJ3HIA5.js","./chunk.VICCAWAN.js","./chunk.OU5TRY4N.js","./chunk.CQPNDJAC.js","./chunk.P4CLT32V.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.UCUWEYKM.js")),o=i.recipeDraft(n.recipe,{app:e.app,sight:i.draftSight(e.app,e.principal)});if(i.isDraftFailure(o))return o.failed;t?.(),e.seatTalk.setDraft(o,null),e.goTo.draft?.(),sn()}function sn(e=180){if(typeof document>"u")return;let n=document.querySelector('[data-testid="draft-keep"]'),t=document.activeElement,i=!t||t===document.body||t.closest?.("[inert]")!==null;if(n){i&&n.focus();return}e>0&&requestAnimationFrame(()=>sn(e-1))}async function re(e,n,t,i,o){let s=tn(e,t,i),c=n==="suggest"?await Ke(e.ai,s):n==="fill"?await Ve(e.ai,s):n==="record"?await Qe(e.ai,s):await Ye(e.ai,s);if(c.interaction.outcome==="failed")return n!=="suggest"&&e.desk.record(c.interaction),c;let d=l=>{let p={...c.interaction,outcome:"failed",failed:l};return e.desk.record(p),{...c,interaction:p}};if(n==="fill"||n==="record"){if(!c.ghost||c.ghost.proposals.length===0)return d("Nothing here could be filled in.");o?.(),e.desk.setGhost({ghost:c.ghost}),e.desk.record(c.interaction)}if(n==="panel"&&c.panel){let l=await on(e,c.panel,o);if(l)return d(l);e.desk.record(c.interaction)}return c}var Ie=new WeakMap,xn=64,nn=new WeakMap;function On(e){let n=nn.get(e);if(!n){let t=n={n:0};nn.set(e,t),e.subscribe(()=>void(t.n+=1))}return n.n}var rn=(e,n)=>{let t=V(n);return t.length>0?t.map(i=>e.graph.getNode(i)):[On(e)]},an=(e,n,t)=>JSON.stringify({target:n,seat:e.principal,by:t}),dn=(e,n,t)=>{let i=rn(e.store,n);return t.schema===e.store.schema&&t.ai===e.ai&&i.length===t.depends.length&&i.every((o,s)=>o===t.depends[s])};function Cn(e,n,t="menu"){let i=Ie.get(e.store)?.get(an(e,n,t));return i?.result!==void 0&&dn(e,n,i)?i.result:void 0}function $n(e,n,t){let i=Ie.get(e.store);i||Ie.set(e.store,i=new Map);let o=an(e,n,t?.by??"menu"),s=i.get(o);if(s&&dn(e,n,s))return s.result?Promise.resolve(s.result):s.asked;let c=t?t.ask():re(e,"suggest",n),d={schema:e.store.schema,ai:e.ai,depends:rn(e.store,n),asked:c};i.delete(o),i.set(o,d),i.size>xn&&i.delete(i.keys().next().value);let l=i;return c.then(p=>{p.interaction.outcome!=="failed"?d.result=p:l.get(o)===d&&l.delete(o)}),c}async function Pn(e,n,t,i){let o=n.interaction,s=he(t);if(s){let c=o.usage?.at(-1)?.model,d=o.offered.find(p=>p.id===t.id)?.confidence,l=se(e.store,{interaction:o.id,target:o.target,basis:`${o.ask.said}: ${t.label}`,...c?{model:c}:{},proposals:[{...s,...d!==void 0?{confidence:d}:{}}]},e.principal);if(l.proposals.length===0){let p="That can't be done now.";return e.desk.record({...o,outcome:"failed",failed:p}),p}i?.(),e.desk.setGhost({ghost:l}),e.desk.record(o);return}if(t.type==="panel"){let c=t.label,d={title:c,recipe:{...t.panel,title:c}},l=await on(e,d,i);return e.desk.record(l?{...o,outcome:"failed",failed:l}:{...o,outcome:"drawn",accepted:[t.id],panel:d}),l}i?.(),t.type==="place"?e.goTo.place(t.place):t.type==="record"&&e.goTo.record(t.record),e.desk.record({...o,outcome:"accepted",accepted:[t.id]})}async function Yn(e,n){if(n.ask.kind==="ask")return ce(e.desk,{target:n.target,asked:n.ask.said}),null;let t=n.ask.kind==="panel"||n.ask.kind==="record"?n.ask.kind:"fill";return re(e,t,n.target,n.ask.said)}var G={padding:"5px 10px",fontSize:"0.875rem",borderRadius:8,width:"100%",textAlign:"left",borderWidth:1,borderStyle:"solid",borderColor:"transparent",background:"none",boxShadow:"none"},ke={margin:0,padding:"4px 10px",fontSize:"0.8125rem",color:"var(--graview-ink-muted)"};function Xn({target:e,close:n}){let t=We(),i=(0,I.useMemo)(()=>Ge(e,u=>t.store.graph.has(u)),[e,t.store]),o=(0,I.useMemo)(()=>{let u=tn(t,i);return ye(t.store,i,{principal:t.principal,places:t.places,...u.acts?{acts:u.acts}:{}})},[t,i]),s=o.candidates.some(u=>u.type==="fill"),c=o.candidates.some(u=>u.type==="panel"),d=(0,I.useMemo)(()=>c?ze(t.store,i,{principal:t.principal,places:t.places,most:1}):[],[c,t,i]),l=(0,I.useMemo)(()=>new Set(t.store.allMutations().filter(u=>(u.creates??[]).length>0).map(u=>u.name)),[t.store]),p=B(t.ai)!==void 0&&o.candidates.some(u=>u.type==="act"&&u.asks.length>0&&l.has(u.mutation)),a=we(t.ai),f=Cn(t,i),h=JSON.stringify(i),[b,P]=(0,I.useState)(!1),[S,m]=(0,I.useState)(null),[C,k]=(0,I.useState)(a&&f===void 0);(0,I.useEffect)(()=>{if(f!==void 0||!(a||b))return;let u=!0;return k(!0),$n(t,i).then(O=>{u&&(m(O),k(!1))}),()=>{u=!1}},[h,b]);let g=f??S,A=(g?.offers??[]).filter(u=>!(u.type==="place"&&d.some(O=>O.place===u.place))).slice(0,Math.max(0,3-d.length)),w=g?.interaction.outcome==="failed"?g.interaction.failed??"The AI could not suggest anything here.":null,M=(0,I.useRef)(!1),L=(0,I.useRef)(null);(0,I.useLayoutEffect)(()=>{g===null||!M.current||(M.current=!1,L.current?.querySelector("button")?.focus())},[g]);let J=(0,I.useRef)(!0);(0,I.useEffect)(()=>()=>{J.current=!1},[]);let[F,r]=(0,I.useState)(!1),[y,T]=(0,I.useState)(null),v=u=>{if(F)return;r(!0),T(null);let O=!1;u(()=>{O=!0,n()}).then(D=>{J.current&&(r(!1),D?T(D):O||n())},D=>{J.current&&(r(!1),T(D instanceof Error?D.message:String(D)))})},$=u=>u.interaction.outcome==="failed"?u.interaction.failed??"The AI could not do that here.":void 0;return(0,x.jsxs)("div",{ref:L,"data-testid":"inline-ai",style:{display:"grid",gap:2},children:[C&&!b?(0,x.jsx)("p",{role:"status","data-testid":"inline-ai-thinking",style:ke,children:"Thinking\u2026"}):F?(0,x.jsx)("p",{role:"status","data-testid":"inline-ai-asking",style:ke,children:"Asking\u2026"}):y?(0,x.jsx)("p",{role:"alert","data-testid":"inline-ai-failed",style:{...ke,color:"var(--graview-warn)"},children:y}):w?(0,x.jsx)("p",{role:"status",style:ke,children:w}):null,(0,x.jsxs)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:2},children:[A.map(u=>(0,x.jsx)("li",{children:(0,x.jsxs)("button",{type:"button","data-menu-item":`ai-offer:${u.id}`,"data-ai-offer":u.id,"data-ai-offer-type":u.type,onClick:()=>v(O=>Pn(t,g,u,O)),style:G,children:[u.label,(0,x.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[" \xB7 ",u.type==="panel"?"a panel":u.type==="place"?"go there":u.type==="record"?"open it":"suggested"]})]})},u.id)),!a&&g===null?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-suggest","aria-disabled":b||void 0,onClick:u=>{b||(M.current=document.activeElement===u.currentTarget,P(!0))},style:G,children:b?"Thinking\u2026":"Suggest\u2026"})}):null,s?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-fill",onClick:()=>v(async u=>$(await re(t,"fill",i,"Fill in",u))),style:G,children:"Fill in with AI"})}):null,p?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-record",onClick:()=>v(async u=>$(await re(t,"record",i,"Add one",u))),style:G,children:"Add one with AI"})}):null,d.map(u=>(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":`ai-open:${u.place}`,"data-ai-existing":u.fit,onClick:()=>{n(),t.goTo.place(u.place),u.fit==="partial"&&ce(t.desk,{target:{on:"lens",place:u.place,...u.kind?{kind:u.kind}:{}}})},style:G,children:u.fit==="full"?`Open ${u.title}`:`Open and adjust ${u.title}`})},u.place)),c?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-panel",onClick:()=>v(async u=>$(await re(t,"panel",i,"Draw a panel",u))),style:G,children:d.length>0?"Draw a new view":"Draw a panel"})}):null,(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-ask",onClick:()=>{let u=document.activeElement;n(),ce(t.desk,{target:i,returnTo:u instanceof HTMLElement&&u!==document.body?u:null})},style:G,children:"Ask about this\u2026"})})]})]})}var be={display:"inline-flex",alignItems:"center",minHeight:28,padding:"2px 10px",fontSize:"0.8125rem",borderRadius:8};function Zn({placement:e="picture"}){let{store:n,principal:t,aiDesk:i}=Je(),o=Le(n,t),{ghost:s,entries:c}=He(i),[d,l]=(0,I.useState)(new Set);(0,I.useEffect)(()=>l(new Set),[s?.ghost.interaction]);let p=(0,I.useRef)(null),a=(0,I.useRef)(null),f=s?.batch;if((0,I.useEffect)(()=>{f!==void 0&&a.current?.focus()},[f]),!s)return null;let{ghost:h}=s,b=c.find(g=>g.id===h.interaction),P=()=>{let g=h.target.on==="record"||h.target.on==="field"?h.target.id:void 0,A=p.current?.closest("[data-graview-face], main")?.parentElement??document,w=(g?A.querySelector(`[data-graview-view="${CSS.escape(g)}"][tabindex]`):null)??document.querySelector("[data-graview-page-title]")??p.current?.closest("main")??document.querySelector("main");w&&!w.hasAttribute("tabindex")&&w.setAttribute("tabindex","-1"),w?.focus({preventScroll:!0}),i.setGhost(null)},S=h.proposals.filter(g=>!d.has(g.id)).map(g=>g.id),m=()=>{let g=Xe(o,h,{author:t,ids:S});if(!g.ok){i.setGhost({...s,refused:g.refused});return}b&&i.record(Ze(b,g.accepted,g.batch)),i.setGhost({ghost:h,batch:g.batch,took:g.accepted.length,...s.onCard?{onCard:!0}:{}})},C=()=>{b&&s.batch===void 0&&i.record(en(b)),P()},k=()=>{if(s.batch!==void 0)try{o.undo(s.batch,{author:t}),P()}catch(g){i.setGhost({...s,refused:g instanceof Error?g.message:String(g)})}};return(0,x.jsxs)("section",{ref:p,"data-testid":"ai-ghost","data-interaction":h.interaction,"aria-label":"Proposed by AI",style:{...e==="card"?{position:"static"}:{position:e==="page"?"fixed":"absolute",insetInline:"max(12px, calc(50% - 220px))",bottom:"calc(var(--graview-foot-room, 0px) + 72px)",zIndex:De("toast"),boxShadow:"var(--graview-lift-high)"},display:"grid",gap:8,padding:12,borderRadius:12,border:"1px dashed var(--graview-accent)",background:"var(--graview-float)",fontSize:"0.875rem"},children:[(0,x.jsx)("p",{style:{margin:0,color:"var(--graview-ink-muted)"},children:s.batch!==void 0?`Done: ${s.took===1?"one change":`${s.took} changes`}, as one.`:`Proposed by AI \xB7 ${h.basis}`}),s.batch===void 0?(0,x.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:4},children:h.proposals.map(g=>(0,x.jsx)("li",{"data-ghost-proposal":g.id,children:(0,x.jsxs)("label",{style:{display:"flex",alignItems:"baseline",gap:8,cursor:"pointer"},children:[(0,x.jsx)("input",{type:"checkbox",checked:!d.has(g.id),onChange:A=>{let w=new Set(d);A.target.checked?w.delete(g.id):w.add(g.id),l(w)}}),(0,x.jsx)("span",{style:{fontStyle:"italic",color:"var(--graview-ink)"},children:g.said}),g.confidence!==void 0?(0,x.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[Math.round(g.confidence*100),"% sure"]}):null]})},g.id))}):null,s.refused?(0,x.jsx)("p",{role:"alert",style:{margin:0,color:"var(--graview-warn)"},children:s.refused}):null,(0,x.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:s.batch===void 0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("button",{type:"button","data-testid":"ghost-accept",disabled:S.length===0,onClick:m,style:be,children:S.length===h.proposals.length?"Accept":`Accept ${S.length} of ${h.proposals.length}`}),(0,x.jsx)("button",{type:"button","data-testid":"ghost-dismiss",onClick:C,style:be,children:"Dismiss"})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("button",{type:"button",ref:a,"data-testid":"ghost-undo",onClick:k,style:be,children:"Undo"}),(0,x.jsx)("button",{type:"button","data-testid":"ghost-close",onClick:P,style:be,children:"Close"})]})})]})}export{Ge as a,V as b,ye as c,ze as d,ee as e,ve as f,hn as g,mn as h,Fn as i,Jn as j,tn as k,on as l,re as m,Cn as n,$n as o,Pn as p,Yn as q,Xn as r,Zn as s};
|
|
1
|
+
var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{a as Ue}from"./chunk.7FZY5E2U.js";import{a as Be}from"./chunk.XLM4ONUB.js";import{a as We}from"./chunk.DGWNVDZB.js";import{a as X}from"./chunk.TI4OSTQV.js";import{a as fe}from"./chunk.3TME4BG3.js";import{e as ce}from"./chunk.AI2HBKVP.js";import{E as we,G as ln,J as He,P as Le,T as Fe,aa as Je}from"./chunk.Q5IAXTF5.js";import{Ob as Ne,Oc as De,Yb as le,_b as je,da as ae,fa as U,ha as q,ka as Ee,ma as de,wb as Me}from"./chunk.VOHRQXCF.js";import{b as Se}from"./chunk.AJZBJBMO.js";var cn=e=>/^(?:aggregate|kind):([^,]+)$/.exec(e)?.[1];function Ge(e,n){let t=e.about??[];if(e.field!==void 0&&e.on!==void 0&&n(e.on))return{on:"field",id:e.on,field:e.field};let i=t.filter(n);if(i.length>1)return{on:"selection",ids:i};if(e.on!==void 0&&n(e.on))return{on:"record",id:e.on};if(i.length===1)return{on:"record",id:i[0]};let o=[e.on,...t].map(s=>s===void 0?void 0:cn(s)).find(s=>s!==void 0);return e.place!==void 0?{on:"lens",place:e.place,...o?{kind:o}:{}}:o!==void 0?{on:"list",kind:o}:{on:"place",place:"home"}}var V=e=>e.on==="record"||e.on==="field"?[e.id]:e.on==="selection"?e.ids:e.on==="act"&&e.id!==void 0?[e.id]:[],ue=(e,n)=>e.tryDefinition(n)?.fields?.shape??{},K=(e,n)=>e.tryDefinition(n)?.edges??{},pe=(e,n)=>new Set(e.tryDefinition(n)?.display?.hide??[]),H=(e,n)=>ae(e.tryDefinition(n.kind),n),xe=(e,n,t)=>Ee(e.tryDefinition(n),t)||U(t),Oe=e=>typeof e=="boolean"?e?"yes":"no":String(e);function ge(e,n){let t=e.kindsKeptFrom(n);return new Set(e.schema.kinds.filter(i=>!t.has(i)))}function Ce(e,n,t,i){if(!e.permits(n,t).ok)return!1;if(!i)return!0;try{return e.previewAll([n],{author:t}).ops.length>0}catch{return!1}}function ye(e,n,t){let i=e,{principal:o}=t,s=t.each??8,c=X(i)?.store??i,d=c.seenBy(o),l=c.schema,p=ge(c,o),a=r=>{let y=d.graph.getNode(r);return y&&p.has(y.kind)?y:void 0},f=c.allMutations(),h=new Map(f.map(r=>[r.name,r])),b=[],P=new Set,S=r=>{P.has(r.id)||(P.add(r.id),b.push(r))},m=r=>r.slice(0,s),C=V(n).filter(r=>a(r)!==void 0);if(V(n).length>0&&C.length===0)return{target:n,candidates:[]};let k=C.length===1?a(C[0]):void 0,g=k?.kind??(n.on==="list"?n.kind:n.on==="lens"?n.kind??t.places?.find(r=>r.as===n.place)?.kind:void 0)??(n.on==="selection"?a(C[0])?.kind:void 0);if(g!==void 0&&!p.has(g))return{target:n,candidates:[]};let A=(r,y)=>`act:${r}${Object.keys(y).length>0?`:${Object.values(y).map(T=>String(T)).join(",")}`:""}`,w=(r,y,T,v,$)=>{r.destructive||Object.values(y).some(u=>typeof u=="string"&&c.graph.has(u)&&a(u)===void 0)||Ce(c,{name:r.name,args:{...y}},o,v.length===0)&&S({type:"act",id:A(r.name,y),label:T,description:$??r.description??T,mutation:r.name,args:y,asks:v})};if(n.on!=="place"||t.acts)if(t.acts)for(let r of t.acts){let y=h.get(r.mutation);!y||r.destructive||n.on==="act"&&r.mutation!==n.act||w(y,r.args,r.label,(r.open??[]).filter(T=>!T.optional).map(T=>T.name),r.why)}else{let r=k?[k]:[];for(let y of f){if(n.on==="act"&&y.name!==n.act)continue;let T=y.input.shape??{},v=$=>Object.entries(T).filter(([u,O])=>u!==$&&O.safeParse?.(void 0).success===!1).map(([u])=>u);if(y.subject)for(let $ of r)le(l,y).includes($.kind)&&w(y,{[y.subject.arg]:$.id},`${y.title??U(y.name)}: ${H(l,$)}`,v(y.subject.arg));else g!==void 0&&(y.creates??[]).includes(g)&&w(y,{},y.title??U(y.name),v(void 0))}}let M=b.filter(r=>r.type==="act");b.splice(0,b.length,...m(M));let L=(r,y)=>{let T=je(l,f).get(r.kind),v=ue(l,r.kind),$=pe(l,r.kind),u=[];for(let[O,j]of Object.entries(v)){if(y!==void 0?O!==y:$.has(O)||r[O]!==void 0)continue;let D=fe(j),z=D?.type==="enum"?D.options??[]:D?.type==="boolean"?[!0,!1]:[];if(z.length===0)continue;let W=(T?.get(O)??[]).map(N=>h.get(N)).find(N=>N?.subject!==void 0&&Ce(c,{name:N.name,args:{[N.subject.arg]:r.id,[O]:z.find(Ae=>Ae!==r[O])??z[0]}},o,!0));if(W?.subject)for(let N of z)r[O]!==N&&u.push({type:"fill",id:`fill:${r.id}:${O}:${Oe(N)}`,label:`${xe(l,r.kind,O)}: ${Oe(N)}`,description:`Set ${xe(l,r.kind,O).toLowerCase()} of ${H(l,r)} to ${Oe(N)}`,record:r.id,field:O,value:N,call:{name:W.name,args:{[W.subject.arg]:r.id,[O]:N}}})}for(let[O,j]of Object.entries(K(l,r.kind))){if(y!==void 0&&O!==y)continue;let D=j.to==="*"?[...p]:j.to.filter(R=>p.has(R)),z=new Set(d.graph.out(r.id,O).map(R=>R.id)),W=f.find(R=>(R.connects??[]).includes(O)&&R.subject!==void 0&&le(l,R).includes(r.kind));if(!W?.subject)continue;let N=Ne(W.input).find(R=>R.name!==W.subject.arg);if(!N)continue;let Ae=D.flatMap(R=>N.kinds.length===0||N.kinds.includes(R)?d.graph.nodesOfKind(R):[]).filter(R=>R.id!==r.id&&!z.has(R.id)&&a(R.id)!==void 0);for(let R of m(Ae)){let Re={name:W.name,args:{[W.subject.arg]:r.id,[N.name]:R.id}};Ce(c,Re,o,!0)&&u.push({type:"fill",id:`fill:${r.id}:${O}:${R.id}`,label:`${U(O)}: ${H(l,R)}`,description:`Link ${H(l,r)} to ${H(l,R)}${j.description?` as ${j.description}`:""}`,record:r.id,field:O,value:R.id,call:Re})}}return u};if(n.on==="field"&&k)for(let r of L(k,n.field))S(r);else if(k&&n.on==="record")for(let r of m(L(k)))S(r);let J=r=>{let y=q(l,r).toLowerCase(),T=[{type:"panel",id:`panel:${r}:list`,label:`A list of ${y}`,description:`Every ${de(l.tryDefinition(r),r).toLowerCase()} this viewer may see, as a list`,panel:{lens:"blocks",kind:r}}],v=pe(l,r);for(let[$,u]of Object.entries(ue(l,r))){if(v.has($))continue;let O=fe(u),j=xe(l,r,$).toLowerCase();if(O?.type==="enum")T.push({type:"panel",id:`panel:${r}:group:${$}`,label:`${_(y)} by ${j}`,description:`A list of ${y} grouped by ${j}`,panel:{lens:"blocks",kind:r,group:$}}),T.push({type:"panel",id:`panel:${r}:columns:${$}`,label:`Columns of ${y} by ${j}`,description:`${_(y)} in a column for each ${j}`,panel:{lens:"columns",kind:r,column:$}});else if(O?.type==="number"||O?.type==="integer"||O?.type==="date"||O?.type==="datetime"){let D=O.type==="date"||O.type==="datetime";T.push({type:"panel",id:`panel:${r}:sort:${$}`,label:`${_(y)} by ${j}`,description:`A list of ${y}, the ${D?"latest":"highest"} ${j} first`,panel:{lens:"blocks",kind:r,sort:{by:$,direction:"desc"}}}),D&&T.push({type:"panel",id:`panel:${r}:calendar:${$}`,label:`A calendar of ${y}`,description:`${_(y)} on a calendar by ${j}`,panel:{lens:"calendar",kind:r,start:$}})}}return T},F=n.on==="place"?[...p]:g!==void 0?[g]:[];for(let r of F)for(let y of m(J(r)))S(y);for(let r of m((t.places??[]).filter(y=>y.kind===void 0?n.on==="place":p.has(y.kind)&&(n.on==="place"||y.kind===g))))n.on==="lens"&&r.as===n.place||S({type:"place",id:`place:${r.as}`,label:r.title,description:`Go to ${r.title}`,place:r.as});if(k){let r=[];for(let[y,T]of Object.entries(K(l,k.kind)))for(let v of d.graph.out(k.id,y))a(v.id)&&r.push({type:"record",id:`record:${v.id}`,label:H(l,v),description:`${_(T.description??U(y))}: ${H(l,v)}`,record:v.id,relation:y});for(let y of l.kinds)for(let[T,v]of Object.entries(K(l,y)))if(!(v.to!=="*"&&!v.to.includes(k.kind)))for(let $ of d.graph.in(k.id,T))$.kind===y&&a($.id)&&r.push({type:"record",id:`record:${$.id}`,label:H(l,$),description:`${_(v.inverse??U(T))}: ${H(l,$)}`,record:$.id,relation:T});for(let y of m(r))S(y)}else if(n.on==="list"||n.on==="lens")for(let r of m(g!==void 0?d.graph.nodesOfKind(g):[]))a(r.id)&&S({type:"record",id:`record:${r.id}`,label:H(l,r),description:`Open ${H(l,r)}`,record:r.id});else if(n.on==="selection")for(let r of C){let y=a(r);S({type:"record",id:`record:${r}`,label:H(l,y),description:`Open ${H(l,y)}`,record:r})}return{target:n,candidates:b}}var _=e=>e&&`${e[0].toUpperCase()}${e.slice(1)}`,fn={columns:["board","kanban","column","lane","pipeline","stage","funnel"],board:["board","map","floor","layout","seat","slot"],calendar:["calendar","schedule","date","due","month","week","agenda","deadline","day"],timeline:["timeline","gantt","schedule","roadmap","span"],coverage:["coverage","matrix","grid","gap"],plan:["plan","floor","map","region","area"],blocks:["list","table","summary","overview","dashboard","card"]},un=new Set(["a","an","the","of","for","my","our","me","us","to","with","and","in","on","by","that","which","i","we","want","need","show","open","go","draw","make","new","view","views","panel","panels","page","lens","please","all","every","some","see","can","could","would","like","one","what","is","are","do","does","here","there","how","it","this","these","those"]),Z=e=>e.length>3&&e.endsWith("ies")?`${e.slice(0,-3)}y`:e.length>3&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):e,$e=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").split(/[^a-z0-9]+/).filter(Boolean);function ze(e,n,t){let i=e,o=X(i)?.store??i,s=o.schema,c=ge(o,t.principal),d=o.seenBy(t.principal),l=V(n),p=new Set;for(let A of l){let w=d.graph.getNode(A)?.kind;w!==void 0&&c.has(w)&&p.add(w)}if(l.length>0&&p.size===0)return[];if(n.on==="list"&&p.add(n.kind),n.on==="lens"){let A=n.kind??t.places.find(w=>w.as===n.place)?.kind;A!==void 0&&p.add(A)}let a=new Map;for(let A of s.kinds){if(!c.has(A))continue;let w=s.tryDefinition(A);for(let M of[A,de(w,A),q(s,A)])for(let L of $e(M))a.set(Z(L),A)}let f=$e(t.said??"").filter(A=>!un.has(A)),h=new Set,b=[];for(let A of f){let w=a.get(Z(A));w!==void 0?h.add(w):b.push(Z(A))}let P=h.size>0?h:p;if((t.said??"").trim()!==""&&f.length===0)return[];if(P.size===0&&f.length===0)return[];let S=[];t.places.forEach((A,w)=>{if(A.hidden||n.on==="lens"&&A.as===n.place)return;let M=A.over??(A.kind!==void 0?[A.kind]:[]);if(M.length>0&&!M.some(F=>c.has(F)))return;let L=M.some(F=>P.has(F)),J=!L&&(A.reads??[]).some(F=>P.has(F));P.size>0&&!L&&!J||S.push({place:A,own:L,reads:J,at:w})});let m=A=>new Set($e(A.title).map(Z)),C=new Set(b.filter(A=>S.some(({place:w})=>m(w).has(A)))),k=[];for(let{place:A,own:w,reads:M,at:L}of S){let J=m(A),F=new Set((fn[A.lens??""]??[]).map(Z)),r=b.filter($=>J.has($)||F.has($)&&!C.has($)).length,y=b.length-r;if(b.length>0&&r===0)continue;let T=!M&&y===0?"full":"partial",v=(w?4:M?2:1)+r*2-y+(T==="full"?1:0);k.push({view:{place:A.as,title:A.title,...A.kind!==void 0?{kind:A.kind}:{},fit:T},score:v,at:L})}return k.filter((A,w)=>!k.slice(0,w).some(M=>M.view.place===A.view.place&&M.view.title===A.view.title)).sort((A,w)=>w.score-A.score||A.at-w.at).slice(0,t.most??3).map(A=>A.view)}var Pe=new WeakMap;function pn(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619)>>>0;return n.toString(36)}function gn(e,n){let t=e,i=X(t)?.store??t,o=i.schema,s=ge(i,n),d=i.allMutations().filter(S=>!S.destructive&&i.permits({name:S.name,args:{}},n).ok!==!1),l=`${[...s].join(",")}|${d.map(S=>S.name).join(",")}`,p=Pe.get(o)?.get(l);if(p)return p;let a=[...s].map(S=>{let m=pe(o,S),C={};for(let[g,A]of Object.entries(ue(o,S))){if(m.has(g))continue;let w=fe(A);w&&(C[g]=w.type==="enum"?`enum:${(w.options??[]).join("|")}`:w.type)}let k={};for(let[g,A]of Object.entries(K(o,S)))k[g]=A.to==="*"?[...s]:A.to.filter(w=>s.has(w));return{kind:S,noun:de(o.tryDefinition(S),S),plural:q(o,S),fields:C,relations:k}}),f=d.map(S=>({name:S.name,title:S.title??U(S.name),...S.subject?{on:le(o,S).filter(m=>s.has(m))}:{}})),h={kinds:a,acts:f},b={version:pn(JSON.stringify(h)),...h},P=Pe.get(o)??new Map;return P.set(l,b),Pe.set(o,P),b}var yn=e=>e.name??e.id??e.kind;function qe(e,n,t){let i=e,{principal:o}=t,s=X(i)?.store??i,c=s.seenBy(o),d=s.schema,l=ge(s,o),p=k=>{let g=c.graph.getNode(k);return g&&l.has(g.kind)?g:void 0},a=k=>({id:k.id,kind:k.kind,label:H(d,k)}),f=V(n),h=f.length===1?p(f[0]):void 0,b=h?Object.fromEntries(Object.keys(ue(d,h.kind)).filter(k=>!pe(d,h.kind).has(k)&&h[k]!==void 0&&k!=="label").map(k=>[k,h[k]])):{},P={on:n.on,...h?{record:{...a(h),fields:b}}:{},...n.on==="field"&&h?{field:n.field}:{},...n.on==="list"&&l.has(n.kind)?{kind:n.kind}:{},...n.on==="lens"?{place:n.place,...n.kind&&l.has(n.kind)?{kind:n.kind}:{}}:{},...n.on==="place"?{place:n.place}:{},...n.on==="act"?{act:n.act}:{}},S=[...new Set([...n.on==="selection"?n.ids:[],...t.selection??[]])].flatMap(k=>{let g=p(k);return g?[a(g)]:[]}),m=[];if(h){for(let k of Object.keys(K(d,h.kind)))for(let g of c.graph.out(h.id,k))p(g.id)&&m.push({...a(g),relation:k,direction:"out"});for(let k of d.kinds)for(let g of Object.keys(K(d,k)))for(let A of c.graph.in(h.id,g))A.kind===k&&p(A.id)&&m.push({...a(A),relation:g,direction:"in"})}let C=c.batches().filter(k=>!k.ops.every(Me)).slice(-(t.recent??6)).reverse().map(k=>({intent:k.intent,at:k.at,by:yn(k.author)}));return{...t.place!==void 0?{place:t.place}:{},target:P,selection:S,neighbors:m.slice(0,24),recent:C,schema:gn(s,o)}}function ee(e){if(!e.off)return e.fast??(e.decide?{model:e.name??"decide",decide:e.decide}:void 0)}function B(e){if(e.off)return;if(e.thinking)return e.thinking;let n=e.name??"model";if(e.complete){let t=e.complete;return{model:n,think:({system:i,prompt:o})=>t({prompt:o,system:i})}}if(e.turn){let t=e.turn;return{model:n,think:async({system:i,prompt:o})=>({text:await t({system:i,messages:[{role:"user",content:o}],tools:[],call:async()=>({error:"No tools here."})})})}}}var Te=(e,n,t)=>e?n/1e6*(e.inputPerMillion??0)+t/1e6*(e.outputPerMillion??0):void 0,ve=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function hn(e,n,t=[]){let i=o=>{let s=e.graph.getNode(o);return s?ae(e.schema.tryDefinition(s.kind),s):"a record"};switch(n.on){case"record":return i(n.id);case"field":return`${i(n.id)} \xB7 ${n.field}`;case"selection":return`${n.ids.length} records`;case"list":return e.schema.tryDefinition(n.kind)?q(e.schema,n.kind):n.kind;case"lens":case"place":return t.find(o=>o.as===n.place)?.title??(n.place==="home"?"Home":n.place);case"act":return n.act}}var _e=e=>e.type!=="act"||e.asks.length===0,me=(e,n)=>({id:e.id,type:e.type,label:e.label,...n!==void 0?{confidence:n}:{}});function Q(e,n){let t=n.interaction??ve(),i=ye(n.store,n.target,{principal:n.principal,...n.acts?{acts:n.acts}:{},...n.places?{places:n.places}:{}}),o=qe(n.store,n.target,{principal:n.principal,...n.place?{place:n.place}:{},...n.selection?{selection:n.selection}:{}}),s=[];return{id:t,catalog:i,state:o,entry:{id:t,at:new Date().toISOString(),by:n.by??n.principal,target:n.target,targetLabel:hn(n.store,n.target,n.places)},usage:s,meter:c=>{s.push(c),e.meter?.({...c,interaction:t})}}}async function ne(e,n,t,i){let o=await e.decide(n,t),{inputTokens:s,outputTokens:c}=o.usage,d=Te(e.price,s,c);return i({tier:"fast",model:e.model,inputTokens:s,outputTokens:c,...d!==void 0?{costUsd:d}:{}}),o.answers}async function te(e,n,t,i,o){let s=await e.think({system:n,prompt:t,state:i.state,catalog:i.catalog}),c=s.usage?.inputTokens,d=s.usage?.outputTokens,l=s.usage?.costUsd??(c!==void 0?Te(e.price,c,d??0):void 0);return o({tier:"thinking",model:e.model,...c!==void 0?{inputTokens:c}:{},...d!==void 0?{outputTokens:d}:{},...l!==void 0?{costUsd:l}:{}}),Be(s.text)}function ie(e,n){let t=new Map(e.map((i,o)=>[`c${o+1}`,i]));return{question:{type:"choice",instructions:n,criteria:Object.fromEntries([...t].map(([i,o])=>[i,`${o.label} \u2014 ${o.description}`]))},of:i=>t.get(i)}}function oe(e,n,t){if(e?.type!=="choice")return[];let i=e,o=Object.entries(i.probabilities).sort((s,c)=>c[1]-s[1]);return o.some(([s])=>s===i.choice)||o.unshift([i.choice,i.confidence]),o.flatMap(([s,c])=>{let d=n(s);return d?[{candidate:d,confidence:c}]:[]}).slice(0,t)}var E=(e,n,t,i)=>({interaction:{...e.entry,ask:{kind:t,said:n??""},offered:[],outcome:"failed",failed:i,usage:[...e.usage]},offers:[]}),Y="AI isn't on here.";async function Ke(e,n,t=3){let i=Q(e,n),o=n.said??"Suggest",s=i.catalog.candidates.filter(_e).slice(0,24);if(s.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let c=ee(e),d=B(e),l=[];try{if(c){let{question:p,of:a}=ie(s,"Which of these would the person most likely want to do next, here?"),f=await ne(c,{...i.state,candidates:s.map(h=>({id:h.id,type:h.type,says:h.description}))},{next:p},i.meter);l=oe(f.next,a,t)}else if(d){let p=await te(d,'You suggest what a person most likely wants to do next in an app. Answer only JSON: {"pick": [candidate ids, best first]}. Pick only ids from the candidates.',JSON.stringify({state:i.state,candidates:s.map(f=>({id:f.id,says:f.description}))}),i,i.meter);l=(Array.isArray(p?.pick)?p.pick.filter(f=>typeof f=="string"):[]).flatMap(f=>s.filter(h=>h.id===f)).slice(0,t).map(f=>({candidate:f}))}else return E(i,o,"suggest",Y)}catch(p){return E(i,o,"suggest",p instanceof Error?p.message:String(p))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:l.map(({candidate:p,confidence:a})=>me(p,a)),outcome:"offered",usage:[...i.usage]},offers:l.map(({candidate:p})=>p)}}var mn=e=>`several:${e}`;async function Fn(e,n,t=2){let i=Q(e,{...n,acts:[]}),o=n.said??"Suggest for the chosen",s=n.target.on==="selection"?n.target.ids.length:1,d=[...n.shared.map(a=>({type:"act",id:mn(a.id),label:a.label,description:`${a.label}, for all ${s} chosen`,mutation:a.mutation,args:a.args,asks:[]})),...i.catalog.candidates.filter(a=>a.type==="panel"||a.type==="place")].slice(0,24),l=ee(e);if(!l)return E(i,o,"suggest",Y);if(d.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let p;try{let{question:a,of:f}=ie(d,`Which of these would the person most likely want to do next with the ${s} records they chose together?`),h=await ne(l,{...i.state,candidates:d.map(b=>({id:b.id,type:b.type,says:b.description}))},{next:a},i.meter);p=oe(h.next,f,t).filter((b,P)=>P===0||b.confidence>=kn)}catch(a){return E(i,o,"suggest",a instanceof Error?a.message:String(a))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:p.map(({candidate:a,confidence:f})=>me(a,f)),outcome:"offered",usage:[...i.usage]},offers:p.map(({candidate:a})=>a)}}var kn=.25;async function Ve(e,n){let t=Q(e,n),i=n.said??"Fill in",o=t.catalog.candidates.filter(f=>f.type==="fill"),s=new Map;for(let f of o)s.set(f.field,[...s.get(f.field)??[],f]);if(s.size===0)return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let c=ee(e),d=B(e),l=[];try{if(c){let f=[...s].map(([b,P],S)=>({key:`f${S+1}`,field:b,...ie(P,`Which value fits "${b}" best for this record?`)})),h=await ne(c,t.state,Object.fromEntries(f.map(b=>[b.key,b.question])),t.meter);for(let b of f){let P=!bn(n.store,n.target,b.field)&&An(n.store,n.target,b.field)!=="one";l.push(...oe(h[b.key],b.of,P?3:1).filter((S,m)=>m===0||S.confidence>=.4))}}else if(d){let f=await te(d,`You fill in a record's fields in an app. Answer only JSON: {"fills": [candidate ids]}, at most one per field, only ids from the candidates.`,JSON.stringify({state:t.state,candidates:o.map(P=>({id:P.id,says:P.description}))}),t,t.meter),h=Array.isArray(f?.fills)?f.fills.filter(P=>typeof P=="string"):[],b=new Set;for(let P of h){let S=o.find(m=>m.id===P);S?.type==="fill"&&!b.has(S.field)&&(b.add(S.field),l.push({candidate:S}))}}else return E(t,i,"fill",Y)}catch(f){return E(t,i,"fill",f instanceof Error?f.message:String(f))}let p=t.usage.at(-1)?.model,a=se(n.store,{interaction:t.id,target:n.target,basis:i,...p?{model:p}:{},proposals:l.flatMap(({candidate:f,confidence:h})=>f.type==="fill"?[{id:f.id,label:f.label,said:f.description,call:f.call,record:f.record,field:f.field,...h!==void 0?{confidence:h}:{}}]:[])},n.principal);return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:a.proposals.map(f=>({id:f.id,type:"fill",label:f.label,...f.confidence!==void 0?{confidence:f.confidence}:{}})),outcome:"offered",usage:[...t.usage]},offers:[],...a.proposals.length>0?{ghost:a}:{}}}function bn(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0,s=(o?e.schema.tryDefinition(o)?.fields?.shape:void 0)??{};return t in s}function An(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0;return o?e.schema.tryDefinition(o)?.edges?.[t]?.cardinality:void 0}async function Qe(e,n){let t=Q(e,n),i=n.said??"Add one",o=new Set(n.store.allMutations().filter(a=>(a.creates??[]).length>0).map(a=>a.name)),s=t.catalog.candidates.filter(a=>a.type==="act"&&a.asks.length>0&&o.has(a.mutation));if(s.length===0)return E(t,i,"record","Nothing here makes a record.");let c=B(e);if(!c)return E(t,i,"record",Y);let d;try{let a=await te(c,'You propose one new record for an app by filling in an act. Answer only JSON: {"act": a candidate id, "args": {argument: value}}. Use only the candidates, and fill every argument the act asks for with a value that fits the state.',JSON.stringify({ask:i,state:t.state,candidates:s.map(b=>({id:b.id,says:b.description,asks:b.asks}))}),t,t.meter),f=s.find(b=>b.id===a?.act),h=typeof a?.args=="object"&&a.args!==null?a.args:{};f&&(d={act:f,args:Object.fromEntries(Object.entries(h).filter(([b])=>f.asks.includes(b)))})}catch(a){return E(t,i,"record",a instanceof Error?a.message:String(a))}if(!d)return E(t,i,"record","The model named no act this app has here.");let l=t.usage.at(-1)?.model,p=se(n.store,{interaction:t.id,target:n.target,basis:i,...l?{model:l}:{},proposals:[{id:d.act.id,label:d.act.label,said:d.act.description,call:{name:d.act.mutation,args:{...d.act.args,...d.args}}}]},n.principal);return p.proposals.length===0?E(t,i,"record","What the model proposed could not be made here."):{interaction:{...t.entry,ask:{kind:"record",said:i},offered:p.proposals.map(a=>({id:a.id,type:"act",label:a.said})),outcome:"offered",usage:[...t.usage]},offers:[d.act],ghost:p}}async function Ye(e,n){let t=Q(e,n),i=n.said??"Make a panel",o=t.catalog.candidates.filter(a=>a.type==="panel");if(o.length===0)return E(t,i,"panel","Nothing here can be drawn as a panel.");let s=ee(e),c=B(e),d;try{if(c){let a=await te(c,'You choose a panel to draw in an app. Answer only JSON: {"panel": a candidate id, "title": a short title}. Choose only among the candidates.',JSON.stringify({ask:i,state:t.state,candidates:o.map(h=>({id:h.id,says:h.description}))}),t,t.meter),f=o.find(h=>h.id===a?.panel);f&&(d={panel:f,...typeof a?.title=="string"&&a.title.trim()?{title:a.title.trim().slice(0,60)}:{}})}else if(s){let{question:a,of:f}=ie(o,`Which panel answers this best: ${i}`),h=oe((await ne(s,t.state,{panel:a},t.meter)).panel,f,1)[0];h?.candidate.type==="panel"&&(d={panel:h.candidate,confidence:h.confidence})}else return E(t,i,"panel",Y)}catch(a){return E(t,i,"panel",a instanceof Error?a.message:String(a))}if(!d)return E(t,i,"panel","The model named no panel this app can draw.");let l=d.title??d.panel.label,p={title:l,recipe:{...d.panel.panel,title:l}};return{interaction:{...t.entry,ask:{kind:"panel",said:i},offered:[me(d.panel,d.confidence)],outcome:"drawn",panel:p,usage:[...t.usage]},offers:[d.panel],panel:p}}function Sn(e){return e.off?void 0:e.answer}var wn=`You answer a person's question about what they are looking at in an app, from the state given and nothing else. Answer only JSON: {"answer": one to three short sentences, "pick": [candidate ids that act on the answer, best first, at most three]}. Pick only ids from the candidates, and none when nothing fits. Never say an id to the person.`;async function Jn(e,n){let t=Q(e,n),i=n.said.trim(),o=t.catalog.candidates.filter(m=>_e(m)||m.type==="panel"||m.type==="place"||m.type==="record").slice(0,32),s=Sn(e),c=B(e),d=ee(e),l="",p=[],a=m=>m.flatMap(C=>o.filter(k=>k.id===C)).slice(0,3).map(C=>({candidate:C}));try{if(s){let m=await s.answer({said:i,target:n.target,targetLabel:t.entry.targetLabel,state:t.state,catalog:{target:t.catalog.target,candidates:o},...n.follows?{follows:n.follows}:{}}),C=m.usage?.inputTokens,k=m.usage?.outputTokens,g=m.usage?.costUsd??(C!==void 0?Te(s.price,C,k??0):void 0);t.meter({tier:"thinking",model:s.model,...C!==void 0?{inputTokens:C}:{},...k!==void 0?{outputTokens:k}:{},...g!==void 0?{costUsd:g}:{}}),l=typeof m.text=="string"?m.text.trim():"",p=a(m.pick??[])}else if(c){let m=await te(c,wn,JSON.stringify({ask:i,about:t.entry.targetLabel,...n.follows?{follows:n.follows}:{},state:t.state,candidates:o.map(C=>({id:C.id,says:C.description}))}),t,t.meter);l=typeof m?.answer=="string"?m.answer.trim():"",p=a(Array.isArray(m?.pick)?m.pick:[])}else if(d&&o.length>0){let{question:m,of:C}=ie(o,`Which of these best answers, or acts on: ${i}`),k=await ne(d,{...t.state,asked:i,candidates:o.map(g=>({id:g.id,type:g.type,says:g.description}))},{answer:m},t.meter);p=oe(k.answer,C,3),l=p.length>0?`These fit \u201C${i}\u201D.`:""}else return E(t,i,"ask",Y)}catch(m){return E(t,i,"ask",m instanceof Error?m.message:String(m))}if(!l&&p.length===0)return E(t,i,"ask","The AI had no answer to that here.");let f=t.usage.at(-1)?.model,h=p.flatMap(({candidate:m,confidence:C})=>{let k=he(m);return k?[{...k,...C!==void 0?{confidence:C}:{}}]:[]}),b=h.length>0?se(n.store,{interaction:t.id,target:n.target,basis:i,...f?{model:f}:{},proposals:h},n.principal):void 0,P=p.map(({candidate:m})=>m).filter(m=>he(m)===void 0),S=[...P.map(m=>me(m,p.find(C=>C.candidate===m)?.confidence)),...(b?.proposals??[]).map(m=>({id:m.id,type:m.field!==void 0?"fill":"act",label:m.label,...m.confidence!==void 0?{confidence:m.confidence}:{}}))];return{interaction:{...t.entry,ask:{kind:"ask",said:i},offered:S,outcome:"offered",...l?{answer:l}:{},usage:[...t.usage]},offers:P,...b&&b.proposals.length>0?{ghost:b}:{},...l?{answer:l}:{}}}function se(e,n,t){let i=n.proposals.flatMap(o=>{try{let s=e.previewAll([o.call],{author:t}),c=s.ops.map(d=>d.intent).join("; ");return s.ops.length>0?[{...o,said:c||o.said}]:[]}catch{return[]}});return{...n,proposals:i}}function he(e){if(e.type==="fill")return{id:e.id,label:e.label,said:e.description,call:e.call,record:e.record,field:e.field};if(e.type==="act"&&e.asks.length===0)return{id:e.id,label:e.label,said:e.description,call:{name:e.mutation,args:{...e.args}}}}function Xe(e,n,t){let i=n.proposals.filter(s=>t.ids===void 0||t.ids.includes(s.id));if(i.length===0)return{ok:!1,refused:"Nothing was chosen."};let o=i.flatMap(s=>s.confidence===void 0?[]:[s.confidence]);try{let c=e.applyAll(i.map(d=>d.call),{author:t.author,via:`ai:${n.interaction}`,intent:n.basis,lineage:{basis:`Asked \u201C${n.basis}\u201D`,...n.model?{model:n.model}:{},...o.length>0?{confidence:Math.min(...o)}:{},interaction:n.interaction}}).ops[0]?.batch;return c?{ok:!0,batch:c,accepted:i.map(d=>d.id)}:{ok:!1,refused:"That changes nothing now."}}catch(s){return{ok:!1,refused:s instanceof Error?s.message:String(s)}}}function Ze(e,n,t){let i=e.ask.kind==="suggest"?n.length>0:e.offered.length>0&&e.offered.every(o=>n.includes(o.id));return{...e,outcome:i?"accepted":"partly",accepted:n,batches:[...e.batches??[],t]}}var en=e=>({...e,outcome:"dismissed"});var I=Se(ln(),1);var x=Se(Fe(),1);function tn(e,n,t){let i=n.on==="selection"?n.ids:n.on==="record"||n.on==="field"?[n.id]:[],o=i.length>0?Ue(e.store,i,{principal:e.principal,...i.length===1?{focus:i[0]}:{}}).affordances.map(s=>({mutation:s.mutation,label:s.label,args:s.args,open:s.open,why:s.why,...s.destructive?{destructive:!0}:{}})):void 0;return{store:e.store,target:n,principal:e.principal,interaction:ve(),places:e.places,selection:e.selection,...o?{acts:o}:{},...e.place?{place:e.place}:{},...t?{said:t}:{}}}async function on(e,n,t){let i=await (__graviewPreload(import.meta.url,["./chunk.4LI73QOY.js","./chunk.G4JJXA63.js","./chunk.VGTEEANA.js","./chunk.SZCZD2GM.js","./chunk.XLM4ONUB.js","./chunk.XOZU4OFA.js","./chunk.C7EEYSAM.js","./chunk.Q5WEOX3Q.js","./chunk.CHMUL36A.js","./chunk.U6PCKJ26.js","./chunk.FEBCIEI3.js","./chunk.WVUJXDXZ.js","./chunk.QRCTTDDQ.js","./chunk.3TME4BG3.js","./chunk.I43ONAEL.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.CV4QA4ZF.js","./chunk.OYRZ2DEI.js","./chunk.7EA7THSM.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.NICCIJV4.js")),o=i.recipeDraft(n.recipe,{app:e.app,sight:i.draftSight(e.app,e.principal)});if(i.isDraftFailure(o))return o.failed;t?.(),e.seatTalk.setDraft(o,null),e.goTo.draft?.(),sn()}function sn(e=180){if(typeof document>"u")return;let n=document.querySelector('[data-testid="draft-keep"]'),t=document.activeElement,i=!t||t===document.body||t.closest?.("[inert]")!==null;if(n){i&&n.focus();return}e>0&&requestAnimationFrame(()=>sn(e-1))}async function re(e,n,t,i,o){let s=tn(e,t,i),c=n==="suggest"?await Ke(e.ai,s):n==="fill"?await Ve(e.ai,s):n==="record"?await Qe(e.ai,s):await Ye(e.ai,s);if(c.interaction.outcome==="failed")return n!=="suggest"&&e.desk.record(c.interaction),c;let d=l=>{let p={...c.interaction,outcome:"failed",failed:l};return e.desk.record(p),{...c,interaction:p}};if(n==="fill"||n==="record"){if(!c.ghost||c.ghost.proposals.length===0)return d("Nothing here could be filled in.");o?.(),e.desk.setGhost({ghost:c.ghost}),e.desk.record(c.interaction)}if(n==="panel"&&c.panel){let l=await on(e,c.panel,o);if(l)return d(l);e.desk.record(c.interaction)}return c}var Ie=new WeakMap,xn=64,nn=new WeakMap;function On(e){let n=nn.get(e);if(!n){let t=n={n:0};nn.set(e,t),e.subscribe(()=>void(t.n+=1))}return n.n}var rn=(e,n)=>{let t=V(n);return t.length>0?t.map(i=>e.graph.getNode(i)):[On(e)]},an=(e,n,t)=>JSON.stringify({target:n,seat:e.principal,by:t}),dn=(e,n,t)=>{let i=rn(e.store,n);return t.schema===e.store.schema&&t.ai===e.ai&&i.length===t.depends.length&&i.every((o,s)=>o===t.depends[s])};function Cn(e,n,t="menu"){let i=Ie.get(e.store)?.get(an(e,n,t));return i?.result!==void 0&&dn(e,n,i)?i.result:void 0}function $n(e,n,t){let i=Ie.get(e.store);i||Ie.set(e.store,i=new Map);let o=an(e,n,t?.by??"menu"),s=i.get(o);if(s&&dn(e,n,s))return s.result?Promise.resolve(s.result):s.asked;let c=t?t.ask():re(e,"suggest",n),d={schema:e.store.schema,ai:e.ai,depends:rn(e.store,n),asked:c};i.delete(o),i.set(o,d),i.size>xn&&i.delete(i.keys().next().value);let l=i;return c.then(p=>{p.interaction.outcome!=="failed"?d.result=p:l.get(o)===d&&l.delete(o)}),c}async function Pn(e,n,t,i){let o=n.interaction,s=he(t);if(s){let c=o.usage?.at(-1)?.model,d=o.offered.find(p=>p.id===t.id)?.confidence,l=se(e.store,{interaction:o.id,target:o.target,basis:`${o.ask.said}: ${t.label}`,...c?{model:c}:{},proposals:[{...s,...d!==void 0?{confidence:d}:{}}]},e.principal);if(l.proposals.length===0){let p="That can't be done now.";return e.desk.record({...o,outcome:"failed",failed:p}),p}i?.(),e.desk.setGhost({ghost:l}),e.desk.record(o);return}if(t.type==="panel"){let c=t.label,d={title:c,recipe:{...t.panel,title:c}},l=await on(e,d,i);return e.desk.record(l?{...o,outcome:"failed",failed:l}:{...o,outcome:"drawn",accepted:[t.id],panel:d}),l}i?.(),t.type==="place"?e.goTo.place(t.place):t.type==="record"&&e.goTo.record(t.record),e.desk.record({...o,outcome:"accepted",accepted:[t.id]})}async function Yn(e,n){if(n.ask.kind==="ask")return ce(e.desk,{target:n.target,asked:n.ask.said}),null;let t=n.ask.kind==="panel"||n.ask.kind==="record"?n.ask.kind:"fill";return re(e,t,n.target,n.ask.said)}var G={padding:"5px 10px",fontSize:"0.875rem",borderRadius:8,width:"100%",textAlign:"left",borderWidth:1,borderStyle:"solid",borderColor:"transparent",background:"none",boxShadow:"none"},ke={margin:0,padding:"4px 10px",fontSize:"0.8125rem",color:"var(--graview-ink-muted)"};function Xn({target:e,close:n}){let t=We(),i=(0,I.useMemo)(()=>Ge(e,u=>t.store.graph.has(u)),[e,t.store]),o=(0,I.useMemo)(()=>{let u=tn(t,i);return ye(t.store,i,{principal:t.principal,places:t.places,...u.acts?{acts:u.acts}:{}})},[t,i]),s=o.candidates.some(u=>u.type==="fill"),c=o.candidates.some(u=>u.type==="panel"),d=(0,I.useMemo)(()=>c?ze(t.store,i,{principal:t.principal,places:t.places,most:1}):[],[c,t,i]),l=(0,I.useMemo)(()=>new Set(t.store.allMutations().filter(u=>(u.creates??[]).length>0).map(u=>u.name)),[t.store]),p=B(t.ai)!==void 0&&o.candidates.some(u=>u.type==="act"&&u.asks.length>0&&l.has(u.mutation)),a=we(t.ai),f=Cn(t,i),h=JSON.stringify(i),[b,P]=(0,I.useState)(!1),[S,m]=(0,I.useState)(null),[C,k]=(0,I.useState)(a&&f===void 0);(0,I.useEffect)(()=>{if(f!==void 0||!(a||b))return;let u=!0;return k(!0),$n(t,i).then(O=>{u&&(m(O),k(!1))}),()=>{u=!1}},[h,b]);let g=f??S,A=(g?.offers??[]).filter(u=>!(u.type==="place"&&d.some(O=>O.place===u.place))).slice(0,Math.max(0,3-d.length)),w=g?.interaction.outcome==="failed"?g.interaction.failed??"The AI could not suggest anything here.":null,M=(0,I.useRef)(!1),L=(0,I.useRef)(null);(0,I.useLayoutEffect)(()=>{g===null||!M.current||(M.current=!1,L.current?.querySelector("button")?.focus())},[g]);let J=(0,I.useRef)(!0);(0,I.useEffect)(()=>()=>{J.current=!1},[]);let[F,r]=(0,I.useState)(!1),[y,T]=(0,I.useState)(null),v=u=>{if(F)return;r(!0),T(null);let O=!1;u(()=>{O=!0,n()}).then(D=>{J.current&&(r(!1),D?T(D):O||n())},D=>{J.current&&(r(!1),T(D instanceof Error?D.message:String(D)))})},$=u=>u.interaction.outcome==="failed"?u.interaction.failed??"The AI could not do that here.":void 0;return(0,x.jsxs)("div",{ref:L,"data-testid":"inline-ai",style:{display:"grid",gap:2},children:[C&&!b?(0,x.jsx)("p",{role:"status","data-testid":"inline-ai-thinking",style:ke,children:"Thinking\u2026"}):F?(0,x.jsx)("p",{role:"status","data-testid":"inline-ai-asking",style:ke,children:"Asking\u2026"}):y?(0,x.jsx)("p",{role:"alert","data-testid":"inline-ai-failed",style:{...ke,color:"var(--graview-warn)"},children:y}):w?(0,x.jsx)("p",{role:"status",style:ke,children:w}):null,(0,x.jsxs)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:2},children:[A.map(u=>(0,x.jsx)("li",{children:(0,x.jsxs)("button",{type:"button","data-menu-item":`ai-offer:${u.id}`,"data-ai-offer":u.id,"data-ai-offer-type":u.type,onClick:()=>v(O=>Pn(t,g,u,O)),style:G,children:[u.label,(0,x.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[" \xB7 ",u.type==="panel"?"a panel":u.type==="place"?"go there":u.type==="record"?"open it":"suggested"]})]})},u.id)),!a&&g===null?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-suggest","aria-disabled":b||void 0,onClick:u=>{b||(M.current=document.activeElement===u.currentTarget,P(!0))},style:G,children:b?"Thinking\u2026":"Suggest\u2026"})}):null,s?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-fill",onClick:()=>v(async u=>$(await re(t,"fill",i,"Fill in",u))),style:G,children:"Fill in with AI"})}):null,p?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-record",onClick:()=>v(async u=>$(await re(t,"record",i,"Add one",u))),style:G,children:"Add one with AI"})}):null,d.map(u=>(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":`ai-open:${u.place}`,"data-ai-existing":u.fit,onClick:()=>{n(),t.goTo.place(u.place),u.fit==="partial"&&ce(t.desk,{target:{on:"lens",place:u.place,...u.kind?{kind:u.kind}:{}}})},style:G,children:u.fit==="full"?`Open ${u.title}`:`Open and adjust ${u.title}`})},u.place)),c?(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-panel",onClick:()=>v(async u=>$(await re(t,"panel",i,"Draw a panel",u))),style:G,children:d.length>0?"Draw a new view":"Draw a panel"})}):null,(0,x.jsx)("li",{children:(0,x.jsx)("button",{type:"button","data-menu-item":"ai-ask",onClick:()=>{let u=document.activeElement;n(),ce(t.desk,{target:i,returnTo:u instanceof HTMLElement&&u!==document.body?u:null})},style:G,children:"Ask about this\u2026"})})]})]})}var be={display:"inline-flex",alignItems:"center",minHeight:28,padding:"2px 10px",fontSize:"0.8125rem",borderRadius:8};function Zn({placement:e="picture"}){let{store:n,principal:t,aiDesk:i}=Je(),o=Le(n,t),{ghost:s,entries:c}=He(i),[d,l]=(0,I.useState)(new Set);(0,I.useEffect)(()=>l(new Set),[s?.ghost.interaction]);let p=(0,I.useRef)(null),a=(0,I.useRef)(null),f=s?.batch;if((0,I.useEffect)(()=>{f!==void 0&&a.current?.focus()},[f]),!s)return null;let{ghost:h}=s,b=c.find(g=>g.id===h.interaction),P=()=>{let g=h.target.on==="record"||h.target.on==="field"?h.target.id:void 0,A=p.current?.closest("[data-graview-face], main")?.parentElement??document,w=(g?A.querySelector(`[data-graview-view="${CSS.escape(g)}"][tabindex]`):null)??document.querySelector("[data-graview-page-title]")??p.current?.closest("main")??document.querySelector("main");w&&!w.hasAttribute("tabindex")&&w.setAttribute("tabindex","-1"),w?.focus({preventScroll:!0}),i.setGhost(null)},S=h.proposals.filter(g=>!d.has(g.id)).map(g=>g.id),m=()=>{let g=Xe(o,h,{author:t,ids:S});if(!g.ok){i.setGhost({...s,refused:g.refused});return}b&&i.record(Ze(b,g.accepted,g.batch)),i.setGhost({ghost:h,batch:g.batch,took:g.accepted.length,...s.onCard?{onCard:!0}:{}})},C=()=>{b&&s.batch===void 0&&i.record(en(b)),P()},k=()=>{if(s.batch!==void 0)try{o.undo(s.batch,{author:t}),P()}catch(g){i.setGhost({...s,refused:g instanceof Error?g.message:String(g)})}};return(0,x.jsxs)("section",{ref:p,"data-testid":"ai-ghost","data-interaction":h.interaction,"aria-label":"Proposed by AI",style:{...e==="card"?{position:"static"}:{position:e==="page"?"fixed":"absolute",insetInline:"max(12px, calc(50% - 220px))",bottom:"calc(var(--graview-foot-room, 0px) + 72px)",zIndex:De("toast"),boxShadow:"var(--graview-lift-high)"},display:"grid",gap:8,padding:12,borderRadius:12,border:"1px dashed var(--graview-accent)",background:"var(--graview-float)",fontSize:"0.875rem"},children:[(0,x.jsx)("p",{style:{margin:0,color:"var(--graview-ink-muted)"},children:s.batch!==void 0?`Done: ${s.took===1?"one change":`${s.took} changes`}, as one.`:`Proposed by AI \xB7 ${h.basis}`}),s.batch===void 0?(0,x.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:4},children:h.proposals.map(g=>(0,x.jsx)("li",{"data-ghost-proposal":g.id,children:(0,x.jsxs)("label",{style:{display:"flex",alignItems:"baseline",gap:8,cursor:"pointer"},children:[(0,x.jsx)("input",{type:"checkbox",checked:!d.has(g.id),onChange:A=>{let w=new Set(d);A.target.checked?w.delete(g.id):w.add(g.id),l(w)}}),(0,x.jsx)("span",{style:{fontStyle:"italic",color:"var(--graview-ink)"},children:g.said}),g.confidence!==void 0?(0,x.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[Math.round(g.confidence*100),"% sure"]}):null]})},g.id))}):null,s.refused?(0,x.jsx)("p",{role:"alert",style:{margin:0,color:"var(--graview-warn)"},children:s.refused}):null,(0,x.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:s.batch===void 0?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("button",{type:"button","data-testid":"ghost-accept",disabled:S.length===0,onClick:m,style:be,children:S.length===h.proposals.length?"Accept":`Accept ${S.length} of ${h.proposals.length}`}),(0,x.jsx)("button",{type:"button","data-testid":"ghost-dismiss",onClick:C,style:be,children:"Dismiss"})]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("button",{type:"button",ref:a,"data-testid":"ghost-undo",onClick:k,style:be,children:"Undo"}),(0,x.jsx)("button",{type:"button","data-testid":"ghost-close",onClick:P,style:be,children:"Close"})]})})]})}export{Ge as a,V as b,ye as c,ze as d,ee as e,ve as f,hn as g,mn as h,Fn as i,Jn as j,tn as k,on as l,re as m,Cn as n,$n as o,Pn as p,Yn as q,Xn as r,Zn as s};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as Ce,d as $e,i as ae}from"./chunk.OU5TRY4N.js";import{e as Te}from"./chunk.CQPNDJAC.js";import{I as ke,Ld as je,Qc as oe,Uc as ve,Vc as Oe,Wa as Se,Za as G,_ as M,aa as xe,ca as _,da as z,ea as Ae,fa as W,ha as we,ia as Ne,md as Re,nc as ie,od as De,qd as We,rd as Me}from"./chunk.P4CLT32V.js";function se(n,e){return n.display?.labels?.[e]??W(e)}function de(n){let e=ae(n);switch(e.type){case"text":case"date":case"number":case"boolean":case"choice":return e.type;default:return}}function Je(n,e){let t=new Map,o=n.tryDefinition(e);for(let[r,a]of Object.entries(o?.edges??{}))t.set(r,{key:r,label:a.description?M(a.description):W(r),about:"edge",far:a.to==="*"?[...n.kinds]:[...a.to]});for(let r of n.definitions)if(r.kind!==e)for(let[a,d]of Object.entries(r.edges??{}))t.has(a)||d.to!=="*"&&!d.to.includes(e)||t.set(a,{key:a,label:d.inverse?M(d.inverse):W(a),about:"edge",far:[r.kind]});return[...t.values()]}var Ze=["current","past","any","flagged","clear"];function Fe(n,e){let t=n?.lifecycle;if(!t||t.retired==="date")return!1;let o=t.retired.map(String);return e.some(r=>r.key===t.field&&o.includes(r.value))}function Be(n,e){let t=n.tryDefinition(e);if(!t)return{kind:e,sorts:[],filters:[],groups:[]};let o=new Set(t.display?.hide??[]),r=t.fields.shape??{},a=[{key:"label",label:"Name",about:"label",type:"text"}],d=[],f=[];for(let[y,x]of Object.entries(r)){if(y==="id"||y==="kind"||y==="label"||o.has(y))continue;let p=de(x);if(!p)continue;let O=se(t,y),w=p==="choice"?Le(x):p==="boolean"?["true","false"]:void 0,N={key:y,label:O,about:"field",type:p,...w?{options:w}:{}};a.push(N),d.push(N),(p==="boolean"||p==="choice")&&f.push(N),p==="date"&&f.push({...N,buckets:["day","week","month","year","decade"]})}for(let y of Je(n,e))a.push(y),d.push(y),f.push(y);let l={key:"is",label:t.lifecycle?"Standing and currency":"Standing",about:"is",type:"choice",options:t.lifecycle?[...Ze]:["flagged","clear"]};d.push(l);let u=t.fieldRoles?.order,g=u&&(u in r||u==="label")?{by:u,direction:"asc"}:void 0;return{kind:e,sorts:a,filters:d,groups:f,...g?{natural:g}:{}}}function vn(n,e){let t=[];for(let r of e.filters){let a=r.about==="edge"&&r.far?.length===1?n.tryDefinition(r.far[0]):void 0;if(!(!a||a.kind===e.kind))for(let[d,f]of Object.entries(a.fields.shape??{}))de(f)!=="choice"||a.display?.hide?.includes(d)||t.push({key:`${r.key}.${d}`,label:`${r.label} \xB7 ${se(a,d)}`,about:"via",type:"choice",options:Le(f),far:[a.kind]})}if(t.length===0)return e;let o=e.filters.filter(r=>r.about!=="is");return{...e,filters:[...o,...t,...e.filters.filter(r=>r.about==="is")]}}function On(n,e){let t=n.tryDefinition(e.kind),o=Object.entries(t?.computed??{});if(!t||o.length===0)return e;let r=o.filter(([a])=>!e.sorts.some(d=>d.key===a)).map(([a,d])=>({key:a,label:(typeof d=="object"?d.label:void 0)??se(t,a),about:"field",type:"number"}));return{...e,sorts:[...e.sorts,...r]}}function Le(n){let e=ae(n);return e.type==="choice"?e.options:[]}var Ie=n=>n,Pe=n=>n;function en(n,e,t){let o=new Map;for(let r of[...n.out(e,t),...n.in(e,t)])o.set(r.id,r);return[...o.values()]}function le(n,e,t){let o=n.schema.tryDefinition(e.kind);if(t.key==="is")switch(t.value){case"current":return _(o,Pe(e),n.today);case"past":return!_(o,Pe(e),n.today);case"any":return!0;case"flagged":return n.flagged?.has(e.id)??!1;case"clear":return!(n.flagged?.has(e.id)??!1);default:return!0}let r=o?.fields.shape??{};if(t.key in r){let l=Se(Ie(e),t.key,n.today??ke()),u=de(r[t.key]);if(u==="date"){let[g,y]=t.value.split(":");if(typeof l!="string"||!y)return!1;let x=l.slice(0,10);return g==="before"?x<y:g==="after"?x>y:x===y}if(u==="boolean")return String(l)===t.value;if(u==="number"){let g=t.value.lastIndexOf(":"),y=g>0?t.value.slice(0,g):"",x=Number(t.value.slice(g+1));if(y==="at-most"||y==="at-least")return typeof l!="number"||!Number.isFinite(x)?!1:y==="at-most"?l<=x:l>=x}return String(l)===t.value}let[a,d]=t.key.split("."),f=en(n.graph,e.id,a);return d?f.some(l=>String(Ie(l)[d])===t.value):t.value==="*"?f.length>0:t.value==="none"?f.length===0:f.some(l=>l.id===t.value)}var nn=5;function ze(n){return n.normalize("NFD").replace(/\p{M}+/gu,"").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim()}function ce(n){return ze(n).replace(/ /g,"")}var U=new Map,tn=5e4;function $(n){let e=U.get(n);if(e===void 0){U.size>=tn&&U.clear();let t=ze(n);e={tokens:t.split(" ").filter(Boolean),whole:t.replace(/ /g,"")},U.set(n,e)}return e}var T=n=>[...$(n).tokens];function j(n,e){if(e.length===0)return;let{whole:t,tokens:o}=$(n),r=e.join("");if(t.length===0)return;if(t===r)return"exact";if(e.every(d=>o.some(f=>f.startsWith(d))))return t.startsWith(r)?"prefix":e.every(d=>o.includes(d))?"word":"part"}function q(n,e,t=48){let o=n.replace(/\s+/g," ").trim();if(o.length<=t)return o;let r=e[0],a=o.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase(),d=r?a.search(new RegExp(`(^|[^\\p{L}\\p{N}])${rn(r)}`,"u")):-1,f=d<0?0:d+(a[d]&&/[\p{L}\p{N}]/u.test(a[d])?0:1),l=Math.max(0,f-Math.floor(t/3));if(l>0){let g=o.lastIndexOf(" ",l);l=g<0?0:g+1}let u=Math.min(o.length,l+t);if(u<o.length){let g=o.indexOf(" ",u);u=g<0||g-u>16?u:g}return`${l>0?"\u2026":""}${o.slice(l,u).trim()}${u<o.length?"\u2026":""}`}var rn=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),on=/^([\p{L}][\p{L}\p{N}_-]*):(\S+)$/u;function an(n){let e=[],t=[];for(let o of n.trim().split(/\s+/).filter(Boolean)){let r=on.exec(o);r?t.push({key:r[1],value:r[2]}):e.push(o)}return{words:e.join(" "),conditions:t}}var Ee=new WeakMap;function Q(n,e){let t=Ee.get(e);if(t&&t.definition===n)return t.texts;let o=sn(n,e);return Ee.set(e,{definition:n,texts:o}),o}function sn(n,e){let t=z(n,e),o=[{field:"label",reading:"Name",text:t}];for(let r of $e(e,n,{limit:Number.POSITIVE_INFINITY}))r.key==="label"||r.value===t||typeof e[r.key]!="boolean"&&o.push({field:r.key,reading:r.label,text:r.markdown?Te(r.value):r.value});return o}var I={exact:0,prefix:1,word:2,part:3,field:4,near:5},Ge=new Set(["a","an","the","of","and","or","for","to","in","on","at","by","with","my","our","is"]);function Ke(n){let e=n;e.length>4&&e.endsWith("ies")?e=`${e.slice(0,-3)}y`:e.length>4&&/(ss|x|ch|sh|z)es$/.test(e)?e=e.slice(0,-2):e.length>3&&e.endsWith("s")&&!/(ss|us|is)$/.test(e)&&(e=e.slice(0,-1));for(let t of["ing","ed"])if(e.length>t.length+2&&e.endsWith(t)){e=e.slice(0,-t.length),/([b-df-hj-km-np-rtv-z])\1$/.test(e)&&(e=e.slice(0,-1));break}return e.length>3&&e.endsWith("e")?e.slice(0,-1):e}function He(n,e,t){if(Math.abs(n.length-e.length)>t)return t+1;let o=[],r=Array.from({length:e.length+1},(a,d)=>d);for(let a=1;a<=n.length;a++){let d=[a],f=a;for(let l=1;l<=e.length;l++){let u=Math.min(r[l]+1,d[l-1]+1,r[l-1]+(n[a-1]===e[l-1]?0:1));a>1&&l>1&&n[a-1]===e[l-2]&&n[a-2]===e[l-1]&&(u=Math.min(u,o[l-2]+1)),d[l]=u,u<f&&(f=u)}if(f>t)return t+1;o=r,r=d}return r[e.length]}var V=new Map;function dn(n,e){let t=V.get(n);t||(V.size>=64&&V.clear(),V.set(n,t=new Map));let o=t.get(e);return o===void 0&&(o=ln(n,e)??null,t.set(e,o)),o??void 0}function ln(n,e){if(/\d/.test(n))return;let t=Ke(n);if(t.length>=3&&(Ke(e)===t||t.length>=4&&e.startsWith(t)))return"stem";let o=n.length<4?0:n.length<=7?1:2;if(o!==0){if(He(n,e,o)<=o)return"spelling";if(n.length>=5){for(let r=n.length-o;r<=n.length+o;r++)if(r<e.length&&He(n,e.slice(0,r),o)<=o)return"spelling"}}}function cn(n,e){let t=e.length>1?e.filter(r=>!Ge.has(r)):e;if(t.length===0)return;let o;for(let r of t){let a;for(let d of n){for(let f of $(d.text).tokens){if(f.startsWith(r)){a={text:d,matched:f};break}let l=a?void 0:dn(r,f);l&&(a={text:d,matched:f,by:l})}if(a&&!a.by)break}if(!a)return;a.by&&!o&&(o={text:a.text,asked:r,matched:a.matched,by:a.by})}if(o)return{field:o.text.field,reading:o.text.reading,fragment:q(o.text.text,[o.matched]),strength:"near",asked:o.asked,matched:o.matched,by:o.by}}var fn=80;function gn(n,e,t){let o=T(e).filter(d=>!Ge.has(d)).join(" ")||e,r=t===void 0?[]:T(t),a=r.length>0&&n.find(d=>r.every(f=>$(d.text).tokens.some(l=>l.startsWith(f))))||n[0];return{field:a.field,reading:a.reading,fragment:q(a.text,r),strength:"near",asked:o,matched:(t??a.text).slice(0,fn),by:"meaning"}}function _e(n,e,t,o){let r=T(t);if(r.length===0)return;if(o){let p=Q(n,e),O=o.includes("label")||o.some(v=>typeof e[v]=="string"&&e[v]===p[0].text),w=p.filter((v,D)=>D===0?O:o.includes(v.field)),N=v=>D=>$(D.text).tokens.some(P=>P.startsWith(v));if(!r.every(v=>w.some(N(v))))return;let S=w.find(N(r[0]));return{field:S.field,reading:S.reading,fragment:q(S.text,r),strength:S.field==="label"?j(S.text,r)??"field":"field"}}let a=Q(n,e),[d,...f]=a,l=j(d.text,r);if(l)return{field:"label",reading:d.reading,fragment:q(d.text,r),strength:l};let u=p=>O=>$(O.text).tokens.some(w=>w.startsWith(p));if(!r.every(p=>a.some(u(p))))return;let g=T(d.text),y=r.find(p=>!g.some(O=>O.startsWith(p)))??r[0],x=f.find(u(y));return{field:x.field,reading:x.reading,fragment:q(x.text,[y]),strength:"field"}}var un=512,yn=64;function hn(n){let e=new Map;if(n.length===0)return e;let t=n.slice(-un),o=n[n.length-1].seq;for(let r of t){let a=Math.pow(.5,(o-r.seq)/yn);for(let d of r.writes)e.set(d,(e.get(d)??0)+a)}return e}var ge=(n,e)=>we({tryDefinition:()=>n},e),fe=(n,e)=>De({tryDefinition:()=>n},e);function pn(n,e,t){let o=n.tryDefinition(e),r=[{field:"plural",text:ge(o,e)},{field:"kind",text:W(e)},...o?.noun?[{field:"noun",text:o.noun}]:[]],a;for(let d of r){let f=j(d.text,t);f&&(!a||I[f]<I[a.strength])&&(a={strength:f,...d})}return a}var mn,bn=(n,e)=>(mn??=new Intl.Collator(void 0,{sensitivity:"base",numeric:!0})).compare(n,e),qe=(n,e)=>(n.nearly??0)-(e.nearly??0)||(n.archived??0)-(e.archived??0)||n.tier-e.tier||n.inKind-e.inKind||n.near-e.near||n.past-e.past||n.touched-e.touched||n.flagged-e.flagged||bn(n.name,e.name)||(n.id<e.id?-1:n.id>e.id?1:0);function Ln(n,e,t={}){let o=n.schema,r=an(e),a=T(r.words),d=t.principal??{kind:"human"},f=n.kindsKeptFrom(d),l=n.modules.disabledKinds,u=r.conditions.filter(i=>i.key==="kind").map(i=>i.value),g=r.conditions.filter(i=>i.key==="is").map(i=>i.value),y=g.includes("any")||g.includes("past"),x=g.includes("past")&&!g.includes("any")&&!g.includes("current"),p=g.includes("archived")?!0:t.archived??"all",O=(i,s)=>{let c=ce(s),h=o.tryDefinition(i);return ce(i)===c||ce(ge(h,i))===c},w=o.kinds.filter(i=>!f.has(i)&&!l.has(i)&&(t.kinds===void 0||t.kinds.includes(i))&&(u.length===0||u.some(s=>O(i,s)))),S=r.conditions.filter(i=>i.key!=="kind").map(i=>({...i,admittedBy:w.filter(s=>Be(o,s).filters.some(c=>c.key===i.key))})),v=S.filter(i=>i.key!=="is"),D=g.filter(i=>i==="flagged"||i==="clear"||i==="past"||i==="archived"),P={kinds:w,past:y},Qe={hits:[],words:r.words,conditions:S,searched:P,byKind:{},total:0,matched:[]};if(a.length===0&&v.length===0&&D.length===0)return Qe;let X=t.today,F=t.flagged??new Set(n.violations().flatMap(i=>i.nodeIds)),Ue=t.touched??hn(n.log.all()),Y=new Set;for(let i of t.from??[]){Y.add(i);for(let s of n.graph.neighbors(i))Y.add(s.id)}let ue=ve(n,d)?Oe(n,d):void 0,J=oe.keptFrom?.(n,d)&&n.seenBy(d).graph,Z=i=>je(i,t.basePath===void 0?{}:{basePath:t.basePath}),ye={schema:o,graph:n.graph,flagged:F,...X?{today:X}:{}},R=[],B={},L=[],E=[],K=(i,s,c,h,m,b)=>{let A=z(c,i);B[s]=(B[s]??0)+1,R.push({hit:{about:"node",id:i.id,kind:s,label:A,why:m,current:h,flagged:F.has(i.id),address:Z(`${fe(c,s)}/${encodeURIComponent(i.id)}`),...b===void 0?{}:{near:!0},...G(i)?{archived:!0}:{}},...b===void 0?{}:{nearly:2-b},tier:I[m.strength],inKind:s===t.inKind?0:1,near:Y.has(i.id)?0:1,past:h?0:1,archived:G(i)?1:0,touched:-(Ue.get(i.id)??0),flagged:F.has(i.id)?0:1,name:A,id:i.id})};for(let i of w){let s=o.tryDefinition(i),c=S.filter(m=>m.key!=="is"&&m.admittedBy.includes(i));if(a.length===0&&c.length===0&&D.length===0)continue;let h=Fe(s,c);for(let m of n.graph.nodesOfKind(i,{archived:p})){if(ue&&!ue(m.id))continue;let b=J?J.getNode(m.id):m;if(!b)continue;let A=_(s,b,X);if(!y&&!h&&!A){if(a.length>0&&g.length===0&&c.every(k=>le(ye,b,k))){let k=_e(s,b,r.words);k&&E.push({node:b,kind:i,definition:s,why:k})}continue}if(x&&A||!c.every(k=>le(ye,b,k))||g.includes("flagged")&&!F.has(b.id)||g.includes("clear")&&F.has(b.id))continue;let C=a.length>0?_e(s,b,r.words):c[0]?{field:c[0].key,reading:W(c[0].key),fragment:`${c[0].key}:${c[0].value}`,strength:"field"}:{field:"is",reading:"Is",fragment:`is:${D[0]}`,strength:"field"};C?K(b,i,s,A,C):a.length>0&&L.push({node:b,kind:i,definition:s,current:A})}}let ee=i=>i.strength!=="field",ne=!1;if(E.length>0&&R.length===0){ne=!0;for(let i of E)K(i.node,i.kind,i.definition,!1,i.why)}else if(E.some(i=>ee(i.why))&&!R.some(i=>ee(i.hit.why))){ne=!0;for(let i of E)ee(i.why)&&K(i.node,i.kind,i.definition,!1,i.why)}let he=t.near!==!1&&a.length>0&&R.length<nn&&L.length>0,te=new Set;if(he)for(let i of L){let s=cn(Q(i.definition,i.node),a);s&&(te.add(i.node.id),K(i.node,i.kind,i.definition,i.current,s,s.by==="stem"?.9:.8))}let Ve=i=>i==="exact"||i==="prefix"?-1:I[i],re=(i,s,c,h)=>({hit:i,tier:Ve(s),inKind:1,near:1,past:0,touched:0,flagged:1,name:c,id:h});if(a.length>0){for(let s of w){let c=pn(o,s,a);if(!c)continue;let h=Ne(o,s),m={field:c.field,reading:c.field==="plural"?"Plural":"Kind",fragment:c.text,strength:c.strength};R.push(re({about:"kind",kind:s,label:h,why:m,count:B[s]??0,address:Z(fe(o.tryDefinition(s),s))},c.strength,h,`kind:${s}`))}let i=t.places??[];for(let s of Re(i.filter(c=>w.includes(c.kind)))){if(s.across&&f.has(s.across))continue;let c=j(s.title,a);if(!c)continue;let h={field:"title",reading:"Title",fragment:s.title,strength:c},m=Me(s,i)?fe(o.tryDefinition(s.kind),s.kind).slice(1):void 0,b=Z(We(s.as,m));R.push(re({about:"place",kind:s.kind,title:s.title,as:s.as,why:h,address:b},c,s.title,`place:${s.kind}:${s.as}`))}for(let s of n.allInvariants()){let c=s.scope==="graph"?void 0:s.scope.kind;if(c&&!w.includes(c))continue;let h=s.label??W(s.name),m=j(h,a),b=m?void 0:j(W(s.name),a),A=m??b;if(!A)continue;let C={field:m?"label":"name",reading:m?"Rule":"Name",fragment:m?h:s.name,strength:A};R.push(re({about:"rule",name:s.name,label:h,...c?{kind:c}:{},why:C},A,h,`rule:${s.name}`))}}let pe=()=>{R.sort(qe);let i=t.limit??50,s=R.slice(0,i).map(k=>k.hit),c=s.flatMap(k=>k.about==="node"?[(J||n.graph).getNode(k.id)]:[]).filter(Boolean),h=Ce(c,k=>o.tryDefinition(k)),m=s.map(k=>k.about==="node"&&h.has(k.id)?{...k,apart:h.get(k.id)}:k),b=Object.values(B).reduce((k,Ye)=>k+Ye,0),A=R.flatMap(k=>k.hit.about==="node"?[k.hit.id]:[]),C=t.subject&&w.includes(String(n.graph.getNode(t.subject)?.kind))?kn(n,t.subject,r.words,{principal:d}):[];return{hits:[...m,...C],words:r.words,conditions:S,searched:ne?{...P,past:!0}:P,byKind:{...B},total:b,matched:A}},H=pe(),me=t.rank;if(!he||!me)return H;let be=L.filter(i=>!te.has(i.node.id)).map(({node:i,kind:s,definition:c})=>({id:i.id,kind:s,label:z(c,i),texts:Q(c,i)}));if(be.length===0)return H;let Xe=(async()=>{let i;try{i=await me(r.words,be)}catch{return H}let s=new Map(L.filter(h=>!te.has(h.node.id)).map(h=>[h.node.id,h])),c=!1;for(let{id:h,score:m,matched:b}of Array.isArray(i)?i:[]){let A=s.get(h);!A||!(m>0)||(s.delete(h),c=!0,K(A.node,A.kind,A.definition,A.current,gn(Q(A.definition,A.node),r.words,typeof b=="string"?b:void 0),Math.min(1,m)))}return c?pe():H})();return{...H,later:Xe}}function kn(n,e,t,o={}){let r=o.principal??{kind:"human"},a=(oe.keptFrom?.(n,r)?n.seenBy(r):n).graph.getNode(e);if(!a)return[];if(n.kindsKeptFrom(r).has(a.kind))return[];let d=T(t),f=z(n.schema.tryDefinition(a.kind),a),l=[];for(let g of n.allMutations()){let y=g.subject;if(!y||y.kinds!=="*"&&!y.kinds.includes(a.kind))continue;let x=g.derived?.act;if((x==="archive"||x==="merge")&&G(a)||x==="unarchive"&&!G(a)||x==="leave-alone"&&ie(a)||x==="allow-tidying"&&!ie(a)||!n.permits({name:g.name,args:{[y.arg]:a.id}},r).ok)continue;let p=Ae(g),O=T(p),w=d.filter(v=>O.some(D=>D.startsWith(v))),N=w.length>0?j(p,w):void 0,S=N?{field:"title",reading:"Act",fragment:p,strength:N}:{field:"subject",reading:"On",fragment:f,strength:"field"};l.push({hit:{about:"act",name:g.name,title:p,subject:a.id,why:S,destructive:g.destructive===!0},tier:N?I[N]:I.field+1,inKind:0,near:0,past:g.destructive?1:0,touched:0,flagged:g.pinned?0:1,name:p,id:`act:${g.name}`})}l.sort(qe);let u=l.map(g=>g.hit);return o.limit===void 0?u:u.slice(0,o.limit)}function En(n,e){let t=e.kinds.map((a,d)=>{let f=ge(n.tryDefinition(a),a);return d===0?f:f.toLowerCase()}),o=xe(t)||"Nothing";return e.kinds.some(a=>n.tryDefinition(a)?.lifecycle)?e.past?`${M(o)}, past ones included.`:`${M(o)}, current ones; add is:any for past ones.`:`${M(o)}.`}export{se as a,de as b,Je as c,Fe as d,Be as e,vn as f,On as g,Le as h,Ie as i,Pe as j,en as k,le as l,ce as m,an as n,_e as o,hn as p,Ln as q,kn as r,En as s};
|
|
1
|
+
import{b as Ce,d as $e,i as ae}from"./chunk.OYRZ2DEI.js";import{e as Te}from"./chunk.7EA7THSM.js";import{I as ke,Md as je,Qc as oe,Uc as ve,Vc as Oe,Wa as Se,Za as G,_ as M,aa as xe,ca as _,da as z,ea as Ae,fa as W,ha as we,ia as Ne,md as Re,nc as ie,pd as De,rd as We,sd as Me}from"./chunk.VOHRQXCF.js";function se(n,e){return n.display?.labels?.[e]??W(e)}function de(n){let e=ae(n);switch(e.type){case"text":case"date":case"number":case"boolean":case"choice":return e.type;default:return}}function Je(n,e){let t=new Map,o=n.tryDefinition(e);for(let[r,a]of Object.entries(o?.edges??{}))t.set(r,{key:r,label:a.description?M(a.description):W(r),about:"edge",far:a.to==="*"?[...n.kinds]:[...a.to]});for(let r of n.definitions)if(r.kind!==e)for(let[a,d]of Object.entries(r.edges??{}))t.has(a)||d.to!=="*"&&!d.to.includes(e)||t.set(a,{key:a,label:d.inverse?M(d.inverse):W(a),about:"edge",far:[r.kind]});return[...t.values()]}var Ze=["current","past","any","flagged","clear"];function Fe(n,e){let t=n?.lifecycle;if(!t||t.retired==="date")return!1;let o=t.retired.map(String);return e.some(r=>r.key===t.field&&o.includes(r.value))}function Be(n,e){let t=n.tryDefinition(e);if(!t)return{kind:e,sorts:[],filters:[],groups:[]};let o=new Set(t.display?.hide??[]),r=t.fields.shape??{},a=[{key:"label",label:"Name",about:"label",type:"text"}],d=[],f=[];for(let[y,x]of Object.entries(r)){if(y==="id"||y==="kind"||y==="label"||o.has(y))continue;let p=de(x);if(!p)continue;let O=se(t,y),w=p==="choice"?Le(x):p==="boolean"?["true","false"]:void 0,N={key:y,label:O,about:"field",type:p,...w?{options:w}:{}};a.push(N),d.push(N),(p==="boolean"||p==="choice")&&f.push(N),p==="date"&&f.push({...N,buckets:["day","week","month","year","decade"]})}for(let y of Je(n,e))a.push(y),d.push(y),f.push(y);let l={key:"is",label:t.lifecycle?"Standing and currency":"Standing",about:"is",type:"choice",options:t.lifecycle?[...Ze]:["flagged","clear"]};d.push(l);let u=t.fieldRoles?.order,g=u&&(u in r||u==="label")?{by:u,direction:"asc"}:void 0;return{kind:e,sorts:a,filters:d,groups:f,...g?{natural:g}:{}}}function vn(n,e){let t=[];for(let r of e.filters){let a=r.about==="edge"&&r.far?.length===1?n.tryDefinition(r.far[0]):void 0;if(!(!a||a.kind===e.kind))for(let[d,f]of Object.entries(a.fields.shape??{}))de(f)!=="choice"||a.display?.hide?.includes(d)||t.push({key:`${r.key}.${d}`,label:`${r.label} \xB7 ${se(a,d)}`,about:"via",type:"choice",options:Le(f),far:[a.kind]})}if(t.length===0)return e;let o=e.filters.filter(r=>r.about!=="is");return{...e,filters:[...o,...t,...e.filters.filter(r=>r.about==="is")]}}function On(n,e){let t=n.tryDefinition(e.kind),o=Object.entries(t?.computed??{});if(!t||o.length===0)return e;let r=o.filter(([a])=>!e.sorts.some(d=>d.key===a)).map(([a,d])=>({key:a,label:(typeof d=="object"?d.label:void 0)??se(t,a),about:"field",type:"number"}));return{...e,sorts:[...e.sorts,...r]}}function Le(n){let e=ae(n);return e.type==="choice"?e.options:[]}var Ie=n=>n,Pe=n=>n;function en(n,e,t){let o=new Map;for(let r of[...n.out(e,t),...n.in(e,t)])o.set(r.id,r);return[...o.values()]}function le(n,e,t){let o=n.schema.tryDefinition(e.kind);if(t.key==="is")switch(t.value){case"current":return _(o,Pe(e),n.today);case"past":return!_(o,Pe(e),n.today);case"any":return!0;case"flagged":return n.flagged?.has(e.id)??!1;case"clear":return!(n.flagged?.has(e.id)??!1);default:return!0}let r=o?.fields.shape??{};if(t.key in r){let l=Se(Ie(e),t.key,n.today??ke()),u=de(r[t.key]);if(u==="date"){let[g,y]=t.value.split(":");if(typeof l!="string"||!y)return!1;let x=l.slice(0,10);return g==="before"?x<y:g==="after"?x>y:x===y}if(u==="boolean")return String(l)===t.value;if(u==="number"){let g=t.value.lastIndexOf(":"),y=g>0?t.value.slice(0,g):"",x=Number(t.value.slice(g+1));if(y==="at-most"||y==="at-least")return typeof l!="number"||!Number.isFinite(x)?!1:y==="at-most"?l<=x:l>=x}return String(l)===t.value}let[a,d]=t.key.split("."),f=en(n.graph,e.id,a);return d?f.some(l=>String(Ie(l)[d])===t.value):t.value==="*"?f.length>0:t.value==="none"?f.length===0:f.some(l=>l.id===t.value)}var nn=5;function ze(n){return n.normalize("NFD").replace(/\p{M}+/gu,"").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim()}function ce(n){return ze(n).replace(/ /g,"")}var U=new Map,tn=5e4;function $(n){let e=U.get(n);if(e===void 0){U.size>=tn&&U.clear();let t=ze(n);e={tokens:t.split(" ").filter(Boolean),whole:t.replace(/ /g,"")},U.set(n,e)}return e}var T=n=>[...$(n).tokens];function j(n,e){if(e.length===0)return;let{whole:t,tokens:o}=$(n),r=e.join("");if(t.length===0)return;if(t===r)return"exact";if(e.every(d=>o.some(f=>f.startsWith(d))))return t.startsWith(r)?"prefix":e.every(d=>o.includes(d))?"word":"part"}function q(n,e,t=48){let o=n.replace(/\s+/g," ").trim();if(o.length<=t)return o;let r=e[0],a=o.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase(),d=r?a.search(new RegExp(`(^|[^\\p{L}\\p{N}])${rn(r)}`,"u")):-1,f=d<0?0:d+(a[d]&&/[\p{L}\p{N}]/u.test(a[d])?0:1),l=Math.max(0,f-Math.floor(t/3));if(l>0){let g=o.lastIndexOf(" ",l);l=g<0?0:g+1}let u=Math.min(o.length,l+t);if(u<o.length){let g=o.indexOf(" ",u);u=g<0||g-u>16?u:g}return`${l>0?"\u2026":""}${o.slice(l,u).trim()}${u<o.length?"\u2026":""}`}var rn=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),on=/^([\p{L}][\p{L}\p{N}_-]*):(\S+)$/u;function an(n){let e=[],t=[];for(let o of n.trim().split(/\s+/).filter(Boolean)){let r=on.exec(o);r?t.push({key:r[1],value:r[2]}):e.push(o)}return{words:e.join(" "),conditions:t}}var Ee=new WeakMap;function Q(n,e){let t=Ee.get(e);if(t&&t.definition===n)return t.texts;let o=sn(n,e);return Ee.set(e,{definition:n,texts:o}),o}function sn(n,e){let t=z(n,e),o=[{field:"label",reading:"Name",text:t}];for(let r of $e(e,n,{limit:Number.POSITIVE_INFINITY}))r.key==="label"||r.value===t||typeof e[r.key]!="boolean"&&o.push({field:r.key,reading:r.label,text:r.markdown?Te(r.value):r.value});return o}var I={exact:0,prefix:1,word:2,part:3,field:4,near:5},Ge=new Set(["a","an","the","of","and","or","for","to","in","on","at","by","with","my","our","is"]);function Ke(n){let e=n;e.length>4&&e.endsWith("ies")?e=`${e.slice(0,-3)}y`:e.length>4&&/(ss|x|ch|sh|z)es$/.test(e)?e=e.slice(0,-2):e.length>3&&e.endsWith("s")&&!/(ss|us|is)$/.test(e)&&(e=e.slice(0,-1));for(let t of["ing","ed"])if(e.length>t.length+2&&e.endsWith(t)){e=e.slice(0,-t.length),/([b-df-hj-km-np-rtv-z])\1$/.test(e)&&(e=e.slice(0,-1));break}return e.length>3&&e.endsWith("e")?e.slice(0,-1):e}function He(n,e,t){if(Math.abs(n.length-e.length)>t)return t+1;let o=[],r=Array.from({length:e.length+1},(a,d)=>d);for(let a=1;a<=n.length;a++){let d=[a],f=a;for(let l=1;l<=e.length;l++){let u=Math.min(r[l]+1,d[l-1]+1,r[l-1]+(n[a-1]===e[l-1]?0:1));a>1&&l>1&&n[a-1]===e[l-2]&&n[a-2]===e[l-1]&&(u=Math.min(u,o[l-2]+1)),d[l]=u,u<f&&(f=u)}if(f>t)return t+1;o=r,r=d}return r[e.length]}var V=new Map;function dn(n,e){let t=V.get(n);t||(V.size>=64&&V.clear(),V.set(n,t=new Map));let o=t.get(e);return o===void 0&&(o=ln(n,e)??null,t.set(e,o)),o??void 0}function ln(n,e){if(/\d/.test(n))return;let t=Ke(n);if(t.length>=3&&(Ke(e)===t||t.length>=4&&e.startsWith(t)))return"stem";let o=n.length<4?0:n.length<=7?1:2;if(o!==0){if(He(n,e,o)<=o)return"spelling";if(n.length>=5){for(let r=n.length-o;r<=n.length+o;r++)if(r<e.length&&He(n,e.slice(0,r),o)<=o)return"spelling"}}}function cn(n,e){let t=e.length>1?e.filter(r=>!Ge.has(r)):e;if(t.length===0)return;let o;for(let r of t){let a;for(let d of n){for(let f of $(d.text).tokens){if(f.startsWith(r)){a={text:d,matched:f};break}let l=a?void 0:dn(r,f);l&&(a={text:d,matched:f,by:l})}if(a&&!a.by)break}if(!a)return;a.by&&!o&&(o={text:a.text,asked:r,matched:a.matched,by:a.by})}if(o)return{field:o.text.field,reading:o.text.reading,fragment:q(o.text.text,[o.matched]),strength:"near",asked:o.asked,matched:o.matched,by:o.by}}var fn=80;function gn(n,e,t){let o=T(e).filter(d=>!Ge.has(d)).join(" ")||e,r=t===void 0?[]:T(t),a=r.length>0&&n.find(d=>r.every(f=>$(d.text).tokens.some(l=>l.startsWith(f))))||n[0];return{field:a.field,reading:a.reading,fragment:q(a.text,r),strength:"near",asked:o,matched:(t??a.text).slice(0,fn),by:"meaning"}}function _e(n,e,t,o){let r=T(t);if(r.length===0)return;if(o){let p=Q(n,e),O=o.includes("label")||o.some(v=>typeof e[v]=="string"&&e[v]===p[0].text),w=p.filter((v,D)=>D===0?O:o.includes(v.field)),N=v=>D=>$(D.text).tokens.some(P=>P.startsWith(v));if(!r.every(v=>w.some(N(v))))return;let S=w.find(N(r[0]));return{field:S.field,reading:S.reading,fragment:q(S.text,r),strength:S.field==="label"?j(S.text,r)??"field":"field"}}let a=Q(n,e),[d,...f]=a,l=j(d.text,r);if(l)return{field:"label",reading:d.reading,fragment:q(d.text,r),strength:l};let u=p=>O=>$(O.text).tokens.some(w=>w.startsWith(p));if(!r.every(p=>a.some(u(p))))return;let g=T(d.text),y=r.find(p=>!g.some(O=>O.startsWith(p)))??r[0],x=f.find(u(y));return{field:x.field,reading:x.reading,fragment:q(x.text,[y]),strength:"field"}}var un=512,yn=64;function hn(n){let e=new Map;if(n.length===0)return e;let t=n.slice(-un),o=n[n.length-1].seq;for(let r of t){let a=Math.pow(.5,(o-r.seq)/yn);for(let d of r.writes)e.set(d,(e.get(d)??0)+a)}return e}var ge=(n,e)=>we({tryDefinition:()=>n},e),fe=(n,e)=>De({tryDefinition:()=>n},e);function pn(n,e,t){let o=n.tryDefinition(e),r=[{field:"plural",text:ge(o,e)},{field:"kind",text:W(e)},...o?.noun?[{field:"noun",text:o.noun}]:[]],a;for(let d of r){let f=j(d.text,t);f&&(!a||I[f]<I[a.strength])&&(a={strength:f,...d})}return a}var mn,bn=(n,e)=>(mn??=new Intl.Collator(void 0,{sensitivity:"base",numeric:!0})).compare(n,e),qe=(n,e)=>(n.nearly??0)-(e.nearly??0)||(n.archived??0)-(e.archived??0)||n.tier-e.tier||n.inKind-e.inKind||n.near-e.near||n.past-e.past||n.touched-e.touched||n.flagged-e.flagged||bn(n.name,e.name)||(n.id<e.id?-1:n.id>e.id?1:0);function Ln(n,e,t={}){let o=n.schema,r=an(e),a=T(r.words),d=t.principal??{kind:"human"},f=n.kindsKeptFrom(d),l=n.modules.disabledKinds,u=r.conditions.filter(i=>i.key==="kind").map(i=>i.value),g=r.conditions.filter(i=>i.key==="is").map(i=>i.value),y=g.includes("any")||g.includes("past"),x=g.includes("past")&&!g.includes("any")&&!g.includes("current"),p=g.includes("archived")?!0:t.archived??"all",O=(i,s)=>{let c=ce(s),h=o.tryDefinition(i);return ce(i)===c||ce(ge(h,i))===c},w=o.kinds.filter(i=>!f.has(i)&&!l.has(i)&&(t.kinds===void 0||t.kinds.includes(i))&&(u.length===0||u.some(s=>O(i,s)))),S=r.conditions.filter(i=>i.key!=="kind").map(i=>({...i,admittedBy:w.filter(s=>Be(o,s).filters.some(c=>c.key===i.key))})),v=S.filter(i=>i.key!=="is"),D=g.filter(i=>i==="flagged"||i==="clear"||i==="past"||i==="archived"),P={kinds:w,past:y},Qe={hits:[],words:r.words,conditions:S,searched:P,byKind:{},total:0,matched:[]};if(a.length===0&&v.length===0&&D.length===0)return Qe;let X=t.today,F=t.flagged??new Set(n.violations().flatMap(i=>i.nodeIds)),Ue=t.touched??hn(n.log.all()),Y=new Set;for(let i of t.from??[]){Y.add(i);for(let s of n.graph.neighbors(i))Y.add(s.id)}let ue=ve(n,d)?Oe(n,d):void 0,J=oe.keptFrom?.(n,d)&&n.seenBy(d).graph,Z=i=>je(i,t.basePath===void 0?{}:{basePath:t.basePath}),ye={schema:o,graph:n.graph,flagged:F,...X?{today:X}:{}},R=[],B={},L=[],E=[],K=(i,s,c,h,m,b)=>{let A=z(c,i);B[s]=(B[s]??0)+1,R.push({hit:{about:"node",id:i.id,kind:s,label:A,why:m,current:h,flagged:F.has(i.id),address:Z(`${fe(c,s)}/${encodeURIComponent(i.id)}`),...b===void 0?{}:{near:!0},...G(i)?{archived:!0}:{}},...b===void 0?{}:{nearly:2-b},tier:I[m.strength],inKind:s===t.inKind?0:1,near:Y.has(i.id)?0:1,past:h?0:1,archived:G(i)?1:0,touched:-(Ue.get(i.id)??0),flagged:F.has(i.id)?0:1,name:A,id:i.id})};for(let i of w){let s=o.tryDefinition(i),c=S.filter(m=>m.key!=="is"&&m.admittedBy.includes(i));if(a.length===0&&c.length===0&&D.length===0)continue;let h=Fe(s,c);for(let m of n.graph.nodesOfKind(i,{archived:p})){if(ue&&!ue(m.id))continue;let b=J?J.getNode(m.id):m;if(!b)continue;let A=_(s,b,X);if(!y&&!h&&!A){if(a.length>0&&g.length===0&&c.every(k=>le(ye,b,k))){let k=_e(s,b,r.words);k&&E.push({node:b,kind:i,definition:s,why:k})}continue}if(x&&A||!c.every(k=>le(ye,b,k))||g.includes("flagged")&&!F.has(b.id)||g.includes("clear")&&F.has(b.id))continue;let C=a.length>0?_e(s,b,r.words):c[0]?{field:c[0].key,reading:W(c[0].key),fragment:`${c[0].key}:${c[0].value}`,strength:"field"}:{field:"is",reading:"Is",fragment:`is:${D[0]}`,strength:"field"};C?K(b,i,s,A,C):a.length>0&&L.push({node:b,kind:i,definition:s,current:A})}}let ee=i=>i.strength!=="field",ne=!1;if(E.length>0&&R.length===0){ne=!0;for(let i of E)K(i.node,i.kind,i.definition,!1,i.why)}else if(E.some(i=>ee(i.why))&&!R.some(i=>ee(i.hit.why))){ne=!0;for(let i of E)ee(i.why)&&K(i.node,i.kind,i.definition,!1,i.why)}let he=t.near!==!1&&a.length>0&&R.length<nn&&L.length>0,te=new Set;if(he)for(let i of L){let s=cn(Q(i.definition,i.node),a);s&&(te.add(i.node.id),K(i.node,i.kind,i.definition,i.current,s,s.by==="stem"?.9:.8))}let Ve=i=>i==="exact"||i==="prefix"?-1:I[i],re=(i,s,c,h)=>({hit:i,tier:Ve(s),inKind:1,near:1,past:0,touched:0,flagged:1,name:c,id:h});if(a.length>0){for(let s of w){let c=pn(o,s,a);if(!c)continue;let h=Ne(o,s),m={field:c.field,reading:c.field==="plural"?"Plural":"Kind",fragment:c.text,strength:c.strength};R.push(re({about:"kind",kind:s,label:h,why:m,count:B[s]??0,address:Z(fe(o.tryDefinition(s),s))},c.strength,h,`kind:${s}`))}let i=t.places??[];for(let s of Re(i.filter(c=>w.includes(c.kind)))){if(s.across&&f.has(s.across))continue;let c=j(s.title,a);if(!c)continue;let h={field:"title",reading:"Title",fragment:s.title,strength:c},m=Me(s,i)?fe(o.tryDefinition(s.kind),s.kind).slice(1):void 0,b=Z(We(s.as,m));R.push(re({about:"place",kind:s.kind,title:s.title,as:s.as,why:h,address:b},c,s.title,`place:${s.kind}:${s.as}`))}for(let s of n.allInvariants()){let c=s.scope==="graph"?void 0:s.scope.kind;if(c&&!w.includes(c))continue;let h=s.label??W(s.name),m=j(h,a),b=m?void 0:j(W(s.name),a),A=m??b;if(!A)continue;let C={field:m?"label":"name",reading:m?"Rule":"Name",fragment:m?h:s.name,strength:A};R.push(re({about:"rule",name:s.name,label:h,...c?{kind:c}:{},why:C},A,h,`rule:${s.name}`))}}let pe=()=>{R.sort(qe);let i=t.limit??50,s=R.slice(0,i).map(k=>k.hit),c=s.flatMap(k=>k.about==="node"?[(J||n.graph).getNode(k.id)]:[]).filter(Boolean),h=Ce(c,k=>o.tryDefinition(k)),m=s.map(k=>k.about==="node"&&h.has(k.id)?{...k,apart:h.get(k.id)}:k),b=Object.values(B).reduce((k,Ye)=>k+Ye,0),A=R.flatMap(k=>k.hit.about==="node"?[k.hit.id]:[]),C=t.subject&&w.includes(String(n.graph.getNode(t.subject)?.kind))?kn(n,t.subject,r.words,{principal:d}):[];return{hits:[...m,...C],words:r.words,conditions:S,searched:ne?{...P,past:!0}:P,byKind:{...B},total:b,matched:A}},H=pe(),me=t.rank;if(!he||!me)return H;let be=L.filter(i=>!te.has(i.node.id)).map(({node:i,kind:s,definition:c})=>({id:i.id,kind:s,label:z(c,i),texts:Q(c,i)}));if(be.length===0)return H;let Xe=(async()=>{let i;try{i=await me(r.words,be)}catch{return H}let s=new Map(L.filter(h=>!te.has(h.node.id)).map(h=>[h.node.id,h])),c=!1;for(let{id:h,score:m,matched:b}of Array.isArray(i)?i:[]){let A=s.get(h);!A||!(m>0)||(s.delete(h),c=!0,K(A.node,A.kind,A.definition,A.current,gn(Q(A.definition,A.node),r.words,typeof b=="string"?b:void 0),Math.min(1,m)))}return c?pe():H})();return{...H,later:Xe}}function kn(n,e,t,o={}){let r=o.principal??{kind:"human"},a=(oe.keptFrom?.(n,r)?n.seenBy(r):n).graph.getNode(e);if(!a)return[];if(n.kindsKeptFrom(r).has(a.kind))return[];let d=T(t),f=z(n.schema.tryDefinition(a.kind),a),l=[];for(let g of n.allMutations()){let y=g.subject;if(!y||y.kinds!=="*"&&!y.kinds.includes(a.kind))continue;let x=g.derived?.act;if((x==="archive"||x==="merge")&&G(a)||x==="unarchive"&&!G(a)||x==="leave-alone"&&ie(a)||x==="allow-tidying"&&!ie(a)||!n.permits({name:g.name,args:{[y.arg]:a.id}},r).ok)continue;let p=Ae(g),O=T(p),w=d.filter(v=>O.some(D=>D.startsWith(v))),N=w.length>0?j(p,w):void 0,S=N?{field:"title",reading:"Act",fragment:p,strength:N}:{field:"subject",reading:"On",fragment:f,strength:"field"};l.push({hit:{about:"act",name:g.name,title:p,subject:a.id,why:S,destructive:g.destructive===!0},tier:N?I[N]:I.field+1,inKind:0,near:0,past:g.destructive?1:0,touched:0,flagged:g.pinned?0:1,name:p,id:`act:${g.name}`})}l.sort(qe);let u=l.map(g=>g.hit);return o.limit===void 0?u:u.slice(0,o.limit)}function En(n,e){let t=e.kinds.map((a,d)=>{let f=ge(n.tryDefinition(a),a);return d===0?f:f.toLowerCase()}),o=xe(t)||"Nothing";return e.kinds.some(a=>n.tryDefinition(a)?.lifecycle)?e.past?`${M(o)}, past ones included.`:`${M(o)}, current ones; add is:any for past ones.`:`${M(o)}.`}export{se as a,de as b,Je as c,Fe as d,Be as e,vn as f,On as g,Le as h,Ie as i,Pe as j,en as k,le as l,ce as m,an as n,_e as o,hn as p,Ln as q,kn as r,En as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{k as a,l as o}from"./chunk.6JERQFZI.js";import"./chunk.7XJ3XQZD.js";import"./chunk.52J42KR5.js";import"./chunk.T2Q3AAQI.js";import"./chunk.C4EPMV7O.js";import"./chunk.G7XKQNOL.js";import"./chunk.7KZ44FEU.js";import"./chunk.KPUX27ZT.js";import"./chunk.DIS7JS7X.js";import"./chunk.D2T563AA.js";import"./chunk.JV7FLVUV.js";import"./chunk.GL3YVGAP.js";import"./chunk.WVUJXDXZ.js";import"./chunk.QRCTTDDQ.js";import"./chunk.3TME4BG3.js";import"./chunk.I43ONAEL.js";import"./chunk.73EKJ4JN.js";import"./chunk.INL4OZI7.js";import"./chunk.5WU2UTP7.js";import"./chunk.GZHZLJBF.js";import"./chunk.YKACMLLU.js";import"./chunk.OJGHDWI6.js";import"./chunk.337JMOTL.js";import"./chunk.CV4QA4ZF.js";import"./chunk.OYRZ2DEI.js";import"./chunk.7EA7THSM.js";import"./chunk.AI2HBKVP.js";import{sa as n}from"./chunk.Q5IAXTF5.js";import"./chunk.SDO3U72B.js";import"./chunk.VOHRQXCF.js";import"./chunk.SLBWPVIY.js";import"./chunk.AJZBJBMO.js";var w=new WeakMap;function s(e,i){let t=w.get(e);t||w.set(e,t=new Map);let r=t.get(i);return r||t.set(i,r=a(o(e,n(e)),e,i)),r}export{s as frameworkViews};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk.UEPVA6IS.js";import"./chunk.WWUMSCYC.js";import"./chunk.Y37DXEHG.js";import"./chunk.DXZ5VYCQ.js";import"./chunk.J2R55TM7.js";import"./chunk.DIS7JS7X.js";import"./chunk.JV7FLVUV.js";import"./chunk.7354O67H.js";import{b as n}from"./chunk.PRCWGE7A.js";import"./chunk.DGWNVDZB.js";import"./chunk.TI4OSTQV.js";import"./chunk.GZHZLJBF.js";import"./chunk.YKACMLLU.js";import"./chunk.OJGHDWI6.js";import"./chunk.337JMOTL.js";import"./chunk.CV4QA4ZF.js";import"./chunk.OYRZ2DEI.js";import"./chunk.7EA7THSM.js";import"./chunk.AI2HBKVP.js";import{T as i}from"./chunk.Q5IAXTF5.js";import"./chunk.SDO3U72B.js";import"./chunk.VOHRQXCF.js";import"./chunk.SLBWPVIY.js";import{b as o}from"./chunk.AJZBJBMO.js";var e=o(i(),1);function g({entries:d,style:l,headingStyle:p,className:r}){return(0,e.jsxs)("section",{...r?{className:r}:{},"data-testid":"record-ai","aria-label":"What AI did here",style:{display:"grid",gap:10,...l},children:[(0,e.jsx)("h2",{style:p??{margin:0,fontSize:"1rem"},children:"What AI did here"}),(0,e.jsx)("ol",{style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:8,fontSize:"0.875rem"},children:d.slice(0,8).map(t=>(0,e.jsx)(n,{entry:t,undo:s=>(0,e.jsx)(a,{batch:s})},t.id))})]})}export{g as RecordInteractions};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{Fa as K,G as C,T as k}from"./chunk.
|
|
1
|
+
var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{Fa as K,G as C,T as k}from"./chunk.Q5IAXTF5.js";import{a as H}from"./chunk.SDO3U72B.js";import{b}from"./chunk.AJZBJBMO.js";var n=b(C(),1),N=450,_=10,O=t=>t instanceof HTMLInputElement?t.dataset.graviewChooseBox??void 0:void 0,q={ArrowDown:1,ArrowRight:1,ArrowUp:-1,ArrowLeft:-1,Home:-1/0,End:1/0},S=t=>t instanceof Element?t.closest("[data-graview-choose]"):null,G=t=>t instanceof HTMLElement&&(t.isContentEditable||t instanceof HTMLInputElement&&t.type!=="checkbox"||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement);function Y(t){let[i,d]=(0,n.useState)(()=>new Set),l=(0,n.useRef)(null),x=(0,n.useRef)(null),[E,P]=(0,n.useState)(null),R=E!==null&&t.includes(E)?E:t[0],L=(0,n.useMemo)(()=>t.filter(e=>i.has(e)),[t,i]),M=(0,n.useMemo)(()=>new Set(t),[t]);(0,n.useEffect)(()=>{[...i].some(e=>!M.has(e))&&d(e=>new Set([...e].filter(o=>M.has(o))))},[M,i]);let u=(0,n.useCallback)((e,o=!1)=>{let a=l.current;d(s=>{let r=new Set(s),f=a===null?-1:t.indexOf(a),y=t.indexOf(e);if(o&&f>=0&&y>=0){let T=s.has(a);for(let p of t.slice(Math.min(f,y),Math.max(f,y)+1))T?r.add(p):r.delete(p)}else r.has(e)?r.delete(e):r.add(e);return r}),l.current=e},[t]),v=(0,n.useCallback)(e=>d(new Set(e)),[]),A=(0,n.useCallback)(()=>{l.current=null,d(new Set)},[]),c=(0,n.useRef)(null),g=(0,n.useRef)(!1),m=L.length>0,h=()=>{c.current&&clearTimeout(c.current.timer),c.current=null};(0,n.useEffect)(()=>h,[]);let B={ref:x,onKeyDown:e=>{if(G(e.target))return;let o=O(e.target);if(e.key==="Tab"&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&o!==void 0&&m){let s=document.querySelector('[data-testid="several-bar"]'),r=s?.querySelector("[data-mutation]:not([disabled])")??s?.querySelector("button:not([disabled])");if(r){e.preventDefault(),e.stopPropagation(),r.focus();return}}let a=q[e.key];if(o!==void 0&&a!==void 0&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let s=t.indexOf(o),r=t[Math.max(0,Math.min(t.length-1,s+(Number.isFinite(a)?a:a>0?t.length:-t.length)))];if(e.preventDefault(),e.stopPropagation(),r===void 0||r===o)return;if(e.shiftKey){let f=l.current!==null&&t.includes(l.current)?l.current:o,[y,T]=[t.indexOf(f),t.indexOf(r)].sort((p,F)=>p-F);d(p=>new Set([...p,...t.slice(y,T+1)])),l.current=f}P(r),x.current?.querySelector(`[data-graview-choose-box="${CSS.escape(r)}"]`)?.focus();return}if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="a"){e.preventDefault(),e.stopPropagation(),v(t);return}if(e.key===" "&&!e.metaKey&&!e.ctrlKey){let s=S(e.target),r=e.target instanceof HTMLButtonElement||e.target instanceof HTMLInputElement&&e.target.type==="checkbox";if(!s||r)return;e.preventDefault(),u(s.dataset.graviewChoose,e.shiftKey)}},onFocus:e=>{let o=O(e.target);o!==void 0&&P(o)},onPointerDown:e=>{if(g.current=!1,e.pointerType==="mouse"||e.button>0)return;let o=S(e.target);if(!o||e.target instanceof HTMLInputElement&&e.target.type==="checkbox")return;let a=o.dataset.graviewChoose;h(),c.current={id:a,x:e.clientX,y:e.clientY,timer:setTimeout(()=>{c.current=null,g.current=!0,u(a)},N)}},onPointerMove:e=>{let o=c.current;o&&Math.hypot(e.clientX-o.x,e.clientY-o.y)>_&&h()},onPointerUp:h,onPointerCancel:h,onClickCapture:e=>{let o=S(e.target);if(!o||e.target instanceof HTMLInputElement&&e.target.type==="checkbox"&&e.target.hasAttribute("data-graview-choose-box"))return;if(g.current){g.current=!1,e.preventDefault(),e.stopPropagation();return}let s=o.dataset.graviewChoose;if(e.shiftKey&&(m||l.current!==null)){e.preventDefault(),e.stopPropagation(),u(s,!0);return}m&&matchMedia?.("(pointer: coarse)").matches&&(e.preventDefault(),e.stopPropagation(),u(s))},onContextMenu:e=>{(g.current||c.current)&&(e.preventDefault(),e.stopPropagation())},...m?{"data-graview-choosing":""}:{}},j=(0,n.useCallback)(e=>i.has(e),[i]);return{chosen:L,has:j,toggle:u,choose:v,clear:A,listProps:B,boxProps:(e,o)=>({type:"checkbox",className:"graview-choose-box","data-graview-choose-box":e,"aria-label":`Choose ${o}`,tabIndex:e===R?0:-1,checked:i.has(e),onChange:()=>{},onClick:a=>{a.stopPropagation(),u(e,a.shiftKey)}}),list:x}}var $=`
|
|
2
2
|
.graview-choose-box{width:24px;height:24px;margin:0;accent-color:var(--graview-accent);cursor:pointer;opacity:0}
|
|
3
3
|
[data-graview-choose]:hover .graview-choose-box,[data-graview-choose]:focus-within .graview-choose-box,.graview-choose-box:focus-visible,.graview-choose-box:checked,[data-graview-choosing] .graview-choose-box{opacity:1}
|
|
4
4
|
[data-graview-choose]{-webkit-touch-callout:none}
|
|
5
5
|
[data-graview-choosing] [data-graview-choose]{-webkit-user-select:none;user-select:none}
|
|
6
|
-
`;var D=b(C(),1),w=b(k(),1),I=K(H(()=>(__graviewPreload(import.meta.url,["./chunk.
|
|
6
|
+
`;var D=b(C(),1),w=b(k(),1),I=K(H(()=>(__graviewPreload(import.meta.url,["./chunk.NHIPVAGR.js","./chunk.BJL6EL6B.js","./chunk.DXZ5VYCQ.js","./chunk.J2R55TM7.js","./chunk.JV7FLVUV.js","./chunk.SZCZD2GM.js","./chunk.7FZY5E2U.js","./chunk.7354O67H.js","./chunk.C7EEYSAM.js","./chunk.MB7LKKUD.js","./chunk.QRCTTDDQ.js","./chunk.3TME4BG3.js","./chunk.I43ONAEL.js","./chunk.73EKJ4JN.js","./chunk.INL4OZI7.js","./chunk.5WU2UTP7.js","./chunk.CV4QA4ZF.js","./chunk.OYRZ2DEI.js","./chunk.7EA7THSM.js","./chunk.AI2HBKVP.js","./chunk.Q5IAXTF5.js","./chunk.SDO3U72B.js","./chunk.VOHRQXCF.js","./chunk.SLBWPVIY.js","./chunk.AJZBJBMO.js"]),import("./chunk.CBGKWYGI.js")))),U=I.part((t,i)=>(0,w.jsx)(t.SeveralBar,{...i}),{what:"The selection bar"});function Q(t){return t.chosen.length===0?null:(0,w.jsx)(D.Suspense,{fallback:null,children:(0,w.jsx)(U,{...t})})}var W=()=>I.prefetch();export{Y as a,$ as b,Q as c,W as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{H as $}from"./chunk.
|
|
1
|
+
import{H as $}from"./chunk.AI2HBKVP.js";import{G as L,Na as U,a as I,b as R,c as E,d as f,e as k,j as W,m as F,v as j}from"./chunk.Q5IAXTF5.js";import{Fd as s,Md as b,Nd as r}from"./chunk.VOHRQXCF.js";import{b as H}from"./chunk.AJZBJBMO.js";var u=H(L(),1),_=e=>typeof e=="object"&&e!==null&&"idx"in e;function S(e){let n=r(window.location.pathname,e);return n===null?null:n!==s&&n!=="/"?"pages":n===s||window.location.href.includes("#")?f(window.location.hash).overview?"graview":"scene":_(window.history.state)?"pages":null}function K(e){let n=e.face??(e.stop&&E(e.stop).overview?"graview":"scene");return e.routing!=="address"||typeof window>"u"?n:S(e.basePath)??n}function Q(e){return e.routing!=="address"||typeof window>"u"?!1:r(window.location.pathname,e.basePath)==="/"&&S(e.basePath)===null}function X(e){if(typeof window>"u")return;let n=r(window.location.pathname,e);return n===s||n==="/"&&window.location.href.includes("#")?R(f(window.location.hash)):void 0}function Z({basePath:e,pagesWere:n,shown:t,onFace:i,toggle:l,kinds:N,places:w,opens:B,landed:V}){let{view:O,go:p}=U(),g=(0,u.useRef)({shown:t,view:O,onFace:i,landed:V});g.current={shown:t,view:O,onFace:i,landed:V};let m=(0,u.useRef)(n??"/"),P=()=>{m.current=`${r(window.location.pathname,e)??"/"}${window.location.search}`};return l.current=(o,c,a)=>{let{shown:d,view:h,onFace:A}=g.current;if(o==="pages"&&d!=="pages")window.history.pushState(null,"",b(c??m.current,{basePath:e}));else if(o!=="pages"&&d==="pages"){P();let y=a===void 0?h:M(E(a),w),v=q(y)?z(B):y,T=v!==y&&v.overview?"graview":o,x=Y(T,v,N);p(x),window.history.pushState(null,"",`${b(s,{basePath:e})}${k(x)}`),A?.(T);return}A?.(o)},(0,u.useEffect)(()=>{let o=()=>{if(r(window.location.pathname,e)===null)return;let c=S(e)??"pages",{shown:a,onFace:d,landed:h}=g.current;if(c==="pages"){P(),h?.(m.current),a!=="pages"&&d?.("pages");return}a==="pages"&&(p(M(f(window.location.hash),w)),d?.(c))};return window.addEventListener("popstate",o),()=>window.removeEventListener("popstate",o)},[e,p,w]),null}function M(e,n){let t=e.within?.view,i=t!==void 0&&!e.focusId?n.find(l=>l.as===t):void 0;return i?{...e,focusId:j(i.kind)}:e}function Y(e,n,t){return e==="graview"?F(n,!0):n.overview?W(F(n,!1),$(n,t)):n}function q(e){return e.focusId===null&&e.overview!==!0}function z(e){return e??{...I,overview:!0}}export{K as a,Q as b,X as c,Z as d,M as e,Y as f,q as g,z as h};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{La as y,Na as k,T as w,j as c,l as h,m as b,r as f}from"./chunk.
|
|
1
|
+
import{La as y,Na as k,T as w,j as c,l as h,m as b,r as f}from"./chunk.Q5IAXTF5.js";import{U as i}from"./chunk.VOHRQXCF.js";import{b as g}from"./chunk.AJZBJBMO.js";var s=null,a=new Set,v=e=>{s={kind:e,n:(s?.n??0)+1};for(let t of a)t()},A=()=>s,C=e=>(a.add(e),()=>a.delete(e)),V=()=>{s=null};var d=g(w(),1);function T(e,t){if(e.length===0||t.length===0)return[];let o=new Set(t.map(n=>n.id));return e.filter(n=>n.nodeIds.some(l=>o.has(l)))}var x=(e,t)=>`${i(e)} ${e===1?"problem":"problems"} in ${t}`;function q({kind:e,plural:t,problems:o,flag:n,listed:l=!1}){let{view:p,go:P}=k(),{set:$}=y();if(o.length===0)return null;let u=x(o.length,t),m=o.length===1?"it":"them";return(0,d.jsx)("button",{type:"button",className:"graview-district-problems","data-testid":`district-problems-${e}`,"data-graview-problems":o.length,"aria-expanded":l,"aria-label":u,title:`${u} \u2014 ${o[0].message}${o.length>1?` (and ${i(o.length-1)} more)`:""}. Press to see ${m} and how to fix ${m}.`,onClick:r=>{r.stopPropagation(),p.overview||P(h(c(b(p,!0),null),"view",null)),$([f(e)]),v(e)},onDoubleClick:r=>r.stopPropagation(),onPointerDown:r=>r.stopPropagation(),children:(0,d.jsx)("span",{"aria-hidden":"true",children:`${n} ${i(o.length)}`})})}export{A as a,C as b,V as c,T as d,x as e,q as f};
|