graview 0.1.23 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/preview/chunk.2STFOAXA.js +1 -0
  2. package/dist/preview/chunk.2VX6H2LL.js +1 -0
  3. package/dist/preview/chunk.33C6VZAD.js +1 -0
  4. package/dist/preview/{chunk.L5G5DTFX.js → chunk.3O2QU7LU.js} +1 -1
  5. package/dist/preview/chunk.3TNQPFIK.js +1 -0
  6. package/dist/preview/{chunk.SQD7ZPEJ.js → chunk.42U4UBDE.js} +1 -1
  7. package/dist/preview/{chunk.Q7WQ5UIE.js → chunk.47GRZWQN.js} +1 -1
  8. package/dist/preview/{chunk.HCK6IHGP.js → chunk.53RZI5PM.js} +1 -1
  9. package/dist/preview/{chunk.DO4P2UK4.js → chunk.54NSG7BX.js} +1 -1
  10. package/dist/preview/{chunk.6C7SJJQO.js → chunk.6MCK7K3M.js} +1 -1
  11. package/dist/preview/{chunk.DAKED3WK.js → chunk.6O67NOZR.js} +1 -1
  12. package/dist/preview/{chunk.ENMNLR73.js → chunk.6XBLDV4A.js} +1 -1
  13. package/dist/preview/chunk.7EN53F4Q.js +9 -0
  14. package/dist/preview/chunk.7Q7S7YCA.js +1 -0
  15. package/dist/preview/{chunk.BQV62QEL.js → chunk.7U7Q3HIS.js} +1 -1
  16. package/dist/preview/{chunk.6CLHFNDM.js → chunk.AKOC43TV.js} +14 -14
  17. package/dist/preview/{chunk.7YCQZJGB.js → chunk.AXACXB4D.js} +1 -1
  18. package/dist/preview/{chunk.ZKUXPS44.js → chunk.BLAODPYJ.js} +1 -1
  19. package/dist/preview/chunk.BNSY25SG.js +1 -0
  20. package/dist/preview/{chunk.XYZ7KAMZ.js → chunk.C7KLA2MW.js} +1 -1
  21. package/dist/preview/{chunk.WGNF4E67.js → chunk.D3CYTXNZ.js} +1 -1
  22. package/dist/preview/chunk.DQL3WKR3.js +1 -0
  23. package/dist/preview/chunk.EUCXNNCZ.js +107 -0
  24. package/dist/preview/{chunk.VVZ2Z7OS.js → chunk.FKQTQ3FV.js} +1 -1
  25. package/dist/preview/{chunk.DJ26NOOW.js → chunk.FRNIWOKD.js} +1 -1
  26. package/dist/preview/chunk.GDIRDJF3.js +1 -0
  27. package/dist/preview/chunk.H3HRTEW7.js +1 -0
  28. package/dist/preview/{chunk.SCLIBKLS.js → chunk.HAQ4KHRY.js} +1 -1
  29. package/dist/preview/{chunk.JE4VH767.js → chunk.HDEQXJWX.js} +1 -1
  30. package/dist/preview/chunk.HH6WIUK3.js +8 -0
  31. package/dist/preview/{chunk.ZFUQA3KT.js → chunk.ISAMJ7AK.js} +1 -1
  32. package/dist/preview/{chunk.FLDFRFDH.js → chunk.KKTHQJ6F.js} +2 -2
  33. package/dist/preview/chunk.KWSXL3A2.js +1 -0
  34. package/dist/preview/{chunk.LGUV2J6Q.js → chunk.LW7KV5SL.js} +1 -1
  35. package/dist/preview/{chunk.R5K7NK4U.js → chunk.MYCTNK6D.js} +1 -1
  36. package/dist/preview/chunk.NRWJ6PLU.js +1 -0
  37. package/dist/preview/{chunk.M4XNUM2A.js → chunk.OXODTBOP.js} +1 -1
  38. package/dist/preview/{chunk.ACZGK7LQ.js → chunk.PRXKRG6O.js} +1 -1
  39. package/dist/preview/{chunk.EQOU4POV.js → chunk.RGXNZ7PN.js} +1 -1
  40. package/dist/preview/chunk.RT3XFR6E.js +20 -0
  41. package/dist/preview/{chunk.ELEHYYCN.js → chunk.S4FO7Y2Q.js} +1 -1
  42. package/dist/preview/{chunk.3MLQ3Q5X.js → chunk.TDW6QEG4.js} +1 -1
  43. package/dist/preview/{chunk.VNC6H6IM.js → chunk.TWFYXD3P.js} +1 -1
  44. package/dist/preview/{chunk.AZG6V3PF.js → chunk.TWGB347L.js} +1 -1
  45. package/dist/preview/chunk.UEBBASQW.js +1 -0
  46. package/dist/preview/chunk.UIZWVBJ7.js +1 -0
  47. package/dist/preview/{chunk.FLJP3BGP.js → chunk.UM5IPM22.js} +1 -1
  48. package/dist/preview/{chunk.NOXC454O.js → chunk.VLNI5U6H.js} +1 -1
  49. package/dist/preview/{chunk.CJQL7AHT.js → chunk.VTBAKTFP.js} +2 -2
  50. package/dist/preview/{chunk.UNRYIETM.js → chunk.WEGBBWWK.js} +1 -1
  51. package/dist/preview/{chunk.LZQZP2PD.js → chunk.WOTNMTIY.js} +1 -1
  52. package/dist/preview/{chunk.THBP5EES.js → chunk.XCOPECOJ.js} +1 -1
  53. package/dist/preview/chunk.XDPRWUCJ.js +1 -0
  54. package/dist/preview/{chunk.3HEJZPJM.js → chunk.XDVKD6VX.js} +1 -1
  55. package/dist/preview/{chunk.YAONM74M.js → chunk.XJNXSQT4.js} +1 -1
  56. package/dist/preview/{chunk.ZQZ557VR.js → chunk.XUXCDUKC.js} +1 -1
  57. package/dist/preview/chunk.Y4R77MKX.js +1 -0
  58. package/dist/preview/chunk.ZQ4HFIIS.js +8 -0
  59. package/dist/preview/page.js +2 -2
  60. package/package.json +6 -6
  61. package/dist/preview/chunk.2F7OKRDK.js +0 -9
  62. package/dist/preview/chunk.4CDEIDKB.js +0 -1
  63. package/dist/preview/chunk.4JSMCNF7.js +0 -1
  64. package/dist/preview/chunk.4UQLZ7VW.js +0 -1
  65. package/dist/preview/chunk.5MAMCKVU.js +0 -1
  66. package/dist/preview/chunk.75WDSWXL.js +0 -20
  67. package/dist/preview/chunk.7YC34AIK.js +0 -1
  68. package/dist/preview/chunk.AZYJTNSM.js +0 -107
  69. package/dist/preview/chunk.DN4D4HGX.js +0 -1
  70. package/dist/preview/chunk.K7UJG5II.js +0 -1
  71. package/dist/preview/chunk.KFLY4MAT.js +0 -1
  72. package/dist/preview/chunk.KWYU5NPM.js +0 -1
  73. package/dist/preview/chunk.LSLFKW4M.js +0 -1
  74. package/dist/preview/chunk.OR6ZWN76.js +0 -1
  75. package/dist/preview/chunk.PC6FAJF5.js +0 -1
  76. package/dist/preview/chunk.VRXWNUDR.js +0 -1
  77. package/dist/preview/chunk.WTF3CP76.js +0 -1
  78. package/dist/preview/chunk.XEJS2VS5.js +0 -8
  79. package/dist/preview/chunk.Y235YZSZ.js +0 -8
  80. package/dist/preview/chunk.YU64JSAL.js +0 -1
@@ -1 +1 @@
1
- import{a as U,b as V,c as W,d as q,e as b,f as z,h as J}from"./chunk.6C7SJJQO.js";import{a as L,b as H,c as A,d as X,j as Q,k as Z,l as ee}from"./chunk.DO4P2UK4.js";import{a as M,b as K,c as E,d as Y,e as F,g as R,h as ne}from"./chunk.ENMNLR73.js";import{b as B,g as u,h as I,i as G}from"./chunk.LZQZP2PD.js";var ce={};function te(e,t=ce,i=H){let{document:r,respelled:f}=U(e),l=f.length>0?{respelled:f}:{};if(!r||typeof r!="object"||Array.isArray(r))return{document:r};let p=r;if(p.format!==L||typeof p.formatVersion!="number"||p.formatVersion>=i)return{document:r,...l};let a=p.formatVersion,o=structuredClone(p);for(let s=a;s<i;s++){let c=t[s];if(!c)throw new Error(`there is no upgrade from format ${s} to ${s+1}`);o={...c(o),formatVersion:s+1}}return{document:o,from:a,...l}}function se(e,t,i){let r=Object.keys(e).filter(a=>e[a].edges?.[t]!==void 0);if(r.length===0)return;let f=r.map(a=>e[a].edges[t].to),l=f.some(a=>a==="*")?"*":[...new Set(f.flatMap(a=>a))];if(i.length===0||i.some(a=>r.includes(a)))return{reversed:!1,kinds:l};let p=r.filter(a=>{let o=e[a].edges[t].to;return o==="*"||i.every(s=>o.includes(s))});return p.length>0?{reversed:!0,kinds:p}:{reversed:!1,kinds:l}}function oe(e,t,i=`kinds.${e}.page`){let r=t.page;if(!r)return[];let f=[],l=[...Object.keys(t.fields),...Object.keys(t.computed??{})],p=new Set,a=(s,c)=>{l.includes(s)?p.has(s)&&f.push(u("page-field-twice",c,`"${s}" is on ${e}'s page twice; name each field once`)):f.push(u("page-field",c,`${e}'s page is to show "${s}", and ${e} has no field or computed field called that`,`use one of: ${l.join(", ")}`)),p.add(s)};(r.fields??[]).forEach((s,c)=>a(s,`${i}.fields.${c}`));let o=new Set;return(r.groups??[]).forEach((s,c)=>{let d=s.title.trim().toLowerCase();o.has(d)&&f.push(u("page-group-twice",`${i}.groups.${c}.title`,`${e}'s page has two groups called "${s.title}"; give each its own title`)),o.add(d),s.fields.forEach(($,n)=>a($,`${i}.groups.${c}.fields.${n}`))}),f}var de=new Set(["subject","now","today"]);function fe(e){if(typeof e=="string"){if(e.length>A)return{findings:[u("too-large","",`a document may be at most ${A/1024} KB`)]};try{e=JSON.parse(e)}catch(r){return{findings:[u("not-json","",`this is not JSON: ${r.message}`)]}}}else if(JSON.stringify(e??null).length>A)return{findings:[u("too-large","",`a document may be at most ${A/1024} KB`)]};try{e=te(e).document}catch(r){return{findings:[u("format","formatVersion",r.message)]}}let t=X.safeParse(e);if(!t.success)return{findings:t.error.issues.map(r=>{let f=r.path.map(String).join(".");if(r.code==="unrecognized_keys")return u("unknown-key",f,`${r.keys.map(l=>`"${l}"`).join(", ")} ${r.keys.length===1?"is":"are"} not part of a Graview document here`,"check the spelling against docs/declaration-document.md");if(r.code==="invalid_union"&&/\.effects\.\d+$/.test(f))return u("effect-shape",f,"this effect is not one Graview knows",'an effect is one of {"create": kind, "as"?: name, "set"?: {field: value}}, {"set": {field: value, \u2026}, "target"?: "$ref"}, {"connect"|"sever": relation, "from": "$ref", "to": "$ref"}, {"remove": "$ref"}');if(r.code==="invalid_key"){let l=r.issues?.[0]?.message;return u("shape",f,`the name "${String(r.path.at(-1))}" is not allowed here${l?`: ${l}`:""}`)}return u("shape",f,r.message)})};let i=t.data;return{document:i,findings:le(i)}}var P=e=>e===void 0?[]:Array.isArray(e)?e:[e];function re(e){let t=new Map;for(let[i,r]of Object.entries(e.kinds))for(let[f,l]of Object.entries(r.edges??{})){let p=t.get(f);t.set(f,{name:f,from:[...p?.from??[],i],to:l.to==="*"||p?.to==="*"?"*":[...new Set([...p?.to??[],...l.to])],cardinality:l.cardinality??"many"})}return t}function Ge(e){let t=new Map;for(let[r,f]of Object.entries(e.kinds)){let l=R(f);t.set(r,{fields:new Set(Object.keys(f.fields)),edges:new Map(Object.entries(f.edges??{}).map(([p,a])=>[p,a.cardinality??"many"])),...l?{computed:l}:{}})}let i=R(e);return i&&t.set(B,{computed:i}),t}function ie(e,t){let i=[],r=P(e.on),f=(l,p)=>{let a=se(t.kinds,l,r)?.reversed===!0,[o,s]=a?["$to","$subject"]:["$subject","$to"];return p==="connect"?{connect:l,from:o,to:s}:{sever:l,from:o,to:s}};if(e.creates){let l=t.kinds[e.creates],p={};for(let a of Object.keys(l?.fields??{}))p[a]=`$${a}`;for(let a of e.effects??[])"set"in a&&!("create"in a)&&b(a.target)==="new"&&Object.assign(p,a.set);i.push({create:e.creates,as:"new",set:p})}return e.sets&&i.push({set:e.sets}),e.writes&&!(e.creates&&e.on===void 0)&&i.push({set:Object.fromEntries(e.writes.map(l=>[l,`$${l}`]))}),e.connects&&(e.replaces&&i.push({replace:e.replaces===!0?[e.connects]:[...e.replaces],keep:e.connects}),i.push(f(e.connects,"connect"))),e.severs&&i.push(f(e.severs,"sever")),e.setsOther&&(e.connects||e.severs)&&i.push({set:e.setsOther,target:"$to"}),e.removes&&i.push({remove:"$subject"}),e.effects&&i.push(...e.effects.filter(l=>!(e.creates&&"set"in l&&!("create"in l)&&b(l.target)==="new"))),i}function C(e,t,i){try{let r=E(e),f=M(r);for(let l of f.unknownFunctions)i.push(u("unknown-function",t,`"${l}" is not a function the rule language knows`,"see docs/declaration-document.md#expression-language"));return r}catch(r){if(r instanceof K){i.push(u("expression",t,r.sentence+` (at character ${r.at+1})`));return}throw r}}function N(e,t,i){try{return F(e)}catch(r){if(r instanceof Y||r instanceof K){i.push(u("template",t,(r instanceof K,r.sentence)));return}throw r}}function le(e){let t=[],i=new Set(Object.keys(e.kinds)),r=re(e),f=e.acts??{},l=new Set(e.roles??[]);for(let[a,o]of Object.entries(e.kinds)){let s=`kinds.${a}`;for(let[d,$]of Object.entries(o.edges??{})){if($.to!=="*")for(let n of $.to)i.has(n)||t.push(u("edge-target",`${s}.edges.${d}.to`,`"${n}" is not a kind this document declares`));o.fields[d]&&t.push(u("edge-field-clash",`${s}.edges.${d}`,`"${d}" is both a field and a relation of ${a}`,"rename one of them"))}o.lifecycle&&!o.fields[o.lifecycle.field]&&t.push(u("lifecycle-field",`${s}.lifecycle.field`,`${a} has no field "${o.lifecycle.field}"`));let c=d=>o.computed!==void 0&&Object.hasOwn(o.computed,d);for(let d of o.glance??[])!o.fields[d]&&!c(d)&&t.push(u("glance-field",`${s}.glance`,`a glance at ${a} is to say "${d}", and ${a} has no field or computed field called that`,`use one of: ${[...Object.keys(o.fields),...Object.keys(o.computed??{})].join(", ")}`));t.push(...oe(a,o));for(let d of["label","describe"]){let $=o[d];if(!$)continue;let n=N($,`${s}.${d}`,t);for(let m of n??[])if(m.expr){for(let y of M(m.expr).names)if(!o.fields[y]){if(c(y)){ne(o,y)||t.push(u("template-field",`${s}.${d}`,`${a}'s ${y} is worked out from beyond the record, and a ${d} is said with no graph to read`,`show it in a view instead, or name a computed field worked out from ${a}'s own fields`));continue}t.push(u("template-field",`${s}.${d}`,`${a} has no field "${y}" for its ${d} to show`,d==="label"?"a label can only show the record's own fields and what they work out":void 0))}}}for(let[d,$]of Object.entries(o.fields))$.default!==void 0&&$.type==="enum"&&!$.options?.includes(String($.default))&&t.push(u("default-option",`${s}.fields.${d}.default`,`"${String($.default)}" is not one of ${d}'s options`))}for(let[a,o]of Object.entries(f)){let s=`acts.${a}`;for(let n of P(o.on))i.has(n)||t.push(u("act-kind",`${s}.on`,`"${n}" is not a kind this document declares`));let c=P(o.on),d=ie(o,e);if(o.creates&&o.on===void 0&&o.writes&&i.has(o.creates))for(let n of o.writes)e.kinds[o.creates].fields[n]||(e.kinds[o.creates].computed?.[n]!==void 0?t.push(u("computed-written",`${s}.writes`,`${o.creates}'s ${n} is worked out, not written: no act can set it`,"write the stored fields it is worked out from")):t.push(u("act-field",`${s}.writes`,`${o.creates} has no field "${n}"`)));d.length===0&&t.push(u("act-empty",s,`"${a}" does nothing`,"give it effects or a shorthand such as sets or creates"));let $=new Map;d.forEach((n,m)=>{let y=d.length-(o.effects?.length??0),w=o.effects&&m>=y?`${s}.effects.${m-y}`:s;if("create"in n){if(!i.has(n.create))t.push(u("act-kind",`${w}.create`,`"${n.create}" is not a kind this document declares`));else for(let h of Object.keys(n.set??{}))e.kinds[n.create].fields[h]||(e.kinds[n.create].computed?.[h]!==void 0?t.push(u("computed-written",`${w}.set.${h}`,`${n.create}'s ${h} is worked out, not written: no act can set it`,"set the stored fields it is worked out from")):t.push(u("act-field",`${w}.set.${h}`,`${n.create} has no field "${h}"`)));n.as&&$.set(n.as,n.create)}else if("connect"in n||"sever"in n){let h="connect"in n?n.connect:n.sever;r.has(h)||t.push(u("act-edge",`${w}.${"connect"in n?"connect":"sever"}`,`"${h}" is not a relation any kind declares`)),b(n.from)==="subject"&&c.length===0&&t.push(u("act-subject",`${s}.on`,`"${a}" acts on "$subject" but does not say which kinds it is "on"`))}else if("set"in n){let h=b(n.target??"$subject"),O=h==="subject"?c:$.has(h??"")?[$.get(h)]:[];h==="subject"&&c.length===0&&t.push(u("act-subject",`${s}.on`,`"${a}" changes "$subject" but does not say which kinds it is "on"`));for(let S of Object.keys(n.set))for(let x of O)!i.has(x)||e.kinds[x].fields[S]||(e.kinds[x].computed?.[S]!==void 0?t.push(u("computed-written",`${w}.set.${S}`,`${x}'s ${S} is worked out, not written: no act can set it`,"set the stored fields it is worked out from")):t.push(u("act-field",`${w}.set.${S}`,`${x} has no field "${S}"`)))}else"remove"in n&&b(n.remove)==="subject"&&c.length===0&&t.push(u("act-subject",`${s}.on`,`"${a}" removes "$subject" but does not say which kinds it is "on"`));("set"in n&&n.set?Object.values(n.set):[]).forEach(h=>{h&&typeof h=="object"&&!Array.isArray(h)&&"expr"in h&&C(h.expr,`${w}.set`,t)})}),o.allowedWhen&&C(o.allowedWhen,`${s}.allowedWhen`,t),o.refusal&&N(o.refusal,`${s}.refusal`,t)}for(let[a,o]of Object.entries(e.rules??{})){let s=`rules.${a}`;o.over!=="graph"&&!i.has(o.over)&&t.push(u("rule-kind",`${s}.over`,`"${o.over}" is not a kind this document declares`));let c=o.over==="graph"?void 0:e.kinds[o.over];for(let d of["when","require"]){let $=o[d];if(!$)continue;let n=C($,`${s}.${d}`,t);if(!n)continue;let m=M(n);for(let y of m.names)if(o.over==="graph")t.push(u("rule-name",`${s}.${d}`,`"${y}" means nothing in a rule over the whole graph`,`name a kind in "over", or use all('kind')`));else if(c&&!c.fields[y]&&!c.edges?.[y]&&c.computed?.[y]===void 0){let w=Object.keys(c.edges??{}).find(v=>v.includes("-")&&v.split("-").includes(y));t.push(u("rule-name",`${s}.${d}`,`${o.over} has no field or relation called "${y}"`,w?`"${w}" reads as a subtraction in a rule; rename the relation to one camelCase word, like "${w.replace(/-([a-z0-9])/g,(v,h)=>h.toUpperCase())}"`:void 0))}for(let y of m.edges)r.has(y)||t.push(u("rule-edge",`${s}.${d}`,`"${y}" is not a relation any kind declares`));for(let y of m.sweeps)i.has(y)?o.over!=="graph"&&t.push(I("rule-cost",`${s}.${d}`,`this rule looks at every ${y} for every ${o.over}, which grows slowly as the app grows`,"walk a relation with out()/in() instead of all() where you can")):t.push(u("rule-kind",`${s}.${d}`,`"${y}" is not a kind this document declares`))}o.says&&N(o.says,`${s}.says`,t),(o.repairs??[]).forEach((d,$)=>{!f[d.act]&&!/^(edit|remove)-/.test(d.act)&&t.push(u("repair-act",`${s}.repairs.${$}.act`,`"${d.act}" is not an act this document declares`))})}let p=e.policy;return p&&(p.grants.forEach((a,o)=>{if(a.roles!=="*"&&l.size>0)for(let s of a.roles)l.has(s)||t.push(u("grant-role",`policy.grants.${o}.roles`,`"${s}" is not one of the document's roles`));if(a.mutations!=="*")for(let s of a.mutations)!f[s]&&!/^(edit|remove)-/.test(s)&&t.push(u("grant-act",`policy.grants.${o}.mutations`,`"${s}" is not an act this document declares`))}),(p.sees??[]).forEach((a,o)=>{for(let s of a.kinds)i.has(s)||t.push(u("sight-kind",`policy.sees.${o}.kinds`,`"${s}" is not a kind this document declares`));if(a.roles!=="*"&&l.size>0)for(let s of a.roles)l.has(s)||t.push(u("sight-role",`policy.sees.${o}.roles`,`"${s}" is not one of the document's roles`))})),t.push(...ee(e)),t}function ue(e,t,i,r){let f=new Map,l=P(e.on),p=new Map,a=new Map;(l.length>0||t.some(n=>"remove"in n&&b(n.remove)==="subject"||"from"in n&&(b(n.from)==="subject"||b(n.to)==="subject")||"set"in n&&!("create"in n)&&b(n.target??"$subject")==="subject"))&&f.set(q,{ref:l.length>0?l:"*",required:!0});let s=e.args??{},c=e.writes?.length===1,d=(n,m)=>m&&n.type===m.type&&n.min===void 0&&n.max===void 0&&n.step===void 0?{...n,...m.min===void 0?{}:{min:m.min},...m.max===void 0?{}:{max:m.max},...m.step===void 0?{}:{step:m.step}}:n,$=(n,m,y)=>{if(n===q||de.has(n)||p.has(n)||f.has(n))return;let w=s[n]?d(s[n],y):void 0;f.set(n,w?{field:w,optional:!w.required,required:!!w.required}:m())};for(let n of t)if("create"in n){let m=i.kinds[n.create];for(let[y,w]of Object.entries(n.set??{})){let v=b(w),h=m?.fields[y];if(v&&h){let O=!!h.required&&h.default===void 0;$(v,()=>({field:h,optional:!O,required:O}),h)}}n.as&&p.set(n.as,n.create)}else if("connect"in n||"sever"in n){let m=r.get("connect"in n?n.connect:n.sever);for(let[y,w]of[["from",n.from],["to",n.to]]){let v=b(w);if(!v)continue;let h=y==="to"?m?.to??"*":m?.from??"*";h!=="*"&&!a.has(v)&&a.set(v,h),$(v,()=>({ref:h,required:!0}))}}else if("set"in n){let m=b(n.target??"$subject"),y=m==="subject"?l[0]:p.get(m??"")??a.get(m??"")?.[0];m&&m!=="subject"&&!p.has(m)&&$(m,()=>({ref:"*",required:!0}));for(let[w,v]of Object.entries(n.set)){let h=b(v);if(!h)continue;let O=y?i.kinds[y]?.fields[w]:void 0;$(h,()=>O?{field:O,optional:!c,required:c}:{any:!0,required:!1},O)}}else if("remove"in n){let m=b(n.remove);m&&$(m,()=>({ref:"*",required:!0}))}for(let[n,m]of Object.entries(s))f.has(n)||f.set(n,{field:m,optional:!m.required,required:!!m.required});return f}function qe(e,t={}){let i=fe(e);if(!i.document||G(i.findings))return{ok:!1,findings:i.findings};let r=i.document,f=[...i.findings];t.previous&&f.push(...ge(r,t.previous));let l=pe(r,f);return G(l.findings)?{ok:!1,findings:l.findings}:J(l,t)}function pe(e,t){let i=re(e),r={};for(let[s,c]of Object.entries(e.kinds)){let d=z(c),$=c.label??(d?`{${d}}`:void 0),n=R(c);r[s]={...$?{label:F($)}:{},...c.describe?{describe:F(c.describe)}:{},...n?{computed:[...n]}:{}}}let f={};for(let[s,c]of Object.entries(e.acts??{})){let d=ie(c,e),$=ue(c,d,e,i),n=c.destructive??d.some(g=>"remove"in g||"sever"in g||"replace"in g),m=[...new Set(d.flatMap(g=>"create"in g?[g.create]:[]))],y=[...new Set(d.flatMap(g=>"connect"in g?[g.connect]:[]))],w=[...new Set(d.flatMap(g=>"sever"in g?[g.sever]:"replace"in g?g.replace:[]))],v=[...new Set(d.flatMap(g=>"set"in g&&!("create"in g)&&b(g.target??"$subject")==="subject"?Object.keys(g.set):[]))],h=new Map;for(let g of d){if(!("connect"in g)&&!("sever"in g))continue;let k=i.get("connect"in g?g.connect:g.sever);for(let[j,ae]of[["from",g.from],["to",g.to]]){let D=b(ae),T=j==="to"?k?.to:k?.from;D&&D!=="subject"&&T&&T!=="*"&&h.set(D,[...new Set([...h.get(D)??[],...T])])}}let O={};for(let g of d){if(!("set"in g)||"create"in g)continue;let k=b(g.target??"$subject");for(let j of k&&k!=="subject"&&h.get(k)||[])O[j]=[...new Set([...O[j]??[],...Object.keys(g.set)])]}let S={};for(let g of d)if(!(!("set"in g)||"create"in g||b(g.target??"$subject")!=="subject"))for(let[k,j]of Object.entries(g.set??{}))typeof j=="string"&&b(j)===void 0||typeof j=="number"||typeof j=="boolean"?S[k]=typeof j=="string"&&j.startsWith("$$")?j.slice(1):j:delete S[k];let x=m.length===0&&d.every(g=>!("set"in g)||!g.set||Object.values(g.set).every(k=>!(k&&typeof k=="object"&&!Array.isArray(k)&&"expr"in k))),_=new Map;for(let g of d)if(!(!("set"in g)||!g.set))for(let k of Object.values(g.set))k&&typeof k=="object"&&!Array.isArray(k)&&"expr"in k&&_.set(k.expr,E(k.expr));f[s]={title:c.title??s.replace(/-/g," "),effects:d,args:[...$],...c.allowedWhen?{guard:E(c.allowedWhen)}:{},...c.refusal?{refusal:F(c.refusal)}:{},exprs:[..._],destructive:n,idempotent:x,creates:m,connects:y,severs:w,writes:v,writesOther:O,sets:S}}let l={};for(let[s,c]of Object.entries(e.rules??{}))l[s]={title:c.title??s.replace(/-/g," "),require:E(c.require),...c.when?{when:E(c.when)}:{},...c.says?{says:F(c.says)}:{}};let p=V(e,t),a=Q(e),o=Z(e);return{format:W,document:e,findings:t,kinds:r,...e.computed?{facts:[...R(e)??[]]}:{},edges:[...i].map(([s,{from:c,to:d,cardinality:$}])=>[s,{from:c,to:d,cardinality:$}]),acts:f,rules:l,brand:p,...Object.keys(a).length>0?{viewSpecs:a}:{},...o?{home:o}:{}}}function Ce(e,t){let i=e.split(/[\s:·]/).find(r=>r.length>0)??e;return t.kinds[i]?`kinds.${i}`:t.acts?.[i]?`acts.${i}`:t.rules?.[i]?`rules.${i}`:e}function Ne(e,t,i){let r=/^defineNode\("([^"]+)"\)/.exec(t)?.[1],f=r?i.kinds[r]:void 0;if(!r||!f)return e;let l=Object.keys(f.fields).filter(p=>p!=="label").slice(0,3);return{...e,path:`kinds.${r}.glance`,fix:`Say which: "glance": [${l.map(p=>`"${p}"`).join(", ")}] on kinds.${r} \u2014 the facts a person compares one by, at a glance.`}}function ge(e,t){let i=[],r=new Set(Object.values(t.kinds).flatMap(f=>Object.keys(f.edges??{})));for(let[f,l]of Object.entries(e.kinds)){let p=l.renamedFrom;p&&!t.kinds[p]&&i.push(u("renamed-from-nothing",`kinds.${f}.renamedFrom`,`${f} says it was ${p}, and the previous version has no kind called ${p}`,"name the kind it was, or drop renamedFrom"));let a=t.kinds[p??f];for(let[o,s]of Object.entries(l.fields)){let c=s.renamedFrom;c&&!a?.fields[c]&&i.push(u("renamed-from-nothing",`kinds.${f}.fields.${o}.renamedFrom`,`${o} says it was ${c}, and the previous ${p??f} has no field called ${c}`,"name the field it was, or drop renamedFrom"))}for(let[o,s]of Object.entries(l.edges??{})){let c=s.renamedFrom;c&&!r.has(c)&&i.push(u("renamed-from-nothing",`kinds.${f}.edges.${o}.renamedFrom`,`${o} says it was ${c}, and the previous version has no relation called ${c}`,"name the relation it was, or drop renamedFrom"))}}return i}export{fe as a,Ge as b,ie as c,qe as d,Ce as e,Ne as f};
1
+ import{a as U,b as V,c as W,d as q,e as b,f as z,h as J}from"./chunk.6MCK7K3M.js";import{a as L,b as H,c as A,d as X,j as Q,k as Z,l as ee}from"./chunk.54NSG7BX.js";import{a as M,b as K,c as E,d as Y,e as F,g as R,h as ne}from"./chunk.6XBLDV4A.js";import{b as B,g as u,h as I,i as G}from"./chunk.WOTNMTIY.js";var ce={};function te(e,t=ce,i=H){let{document:r,respelled:f}=U(e),l=f.length>0?{respelled:f}:{};if(!r||typeof r!="object"||Array.isArray(r))return{document:r};let p=r;if(p.format!==L||typeof p.formatVersion!="number"||p.formatVersion>=i)return{document:r,...l};let a=p.formatVersion,o=structuredClone(p);for(let s=a;s<i;s++){let c=t[s];if(!c)throw new Error(`there is no upgrade from format ${s} to ${s+1}`);o={...c(o),formatVersion:s+1}}return{document:o,from:a,...l}}function se(e,t,i){let r=Object.keys(e).filter(a=>e[a].edges?.[t]!==void 0);if(r.length===0)return;let f=r.map(a=>e[a].edges[t].to),l=f.some(a=>a==="*")?"*":[...new Set(f.flatMap(a=>a))];if(i.length===0||i.some(a=>r.includes(a)))return{reversed:!1,kinds:l};let p=r.filter(a=>{let o=e[a].edges[t].to;return o==="*"||i.every(s=>o.includes(s))});return p.length>0?{reversed:!0,kinds:p}:{reversed:!1,kinds:l}}function oe(e,t,i=`kinds.${e}.page`){let r=t.page;if(!r)return[];let f=[],l=[...Object.keys(t.fields),...Object.keys(t.computed??{})],p=new Set,a=(s,c)=>{l.includes(s)?p.has(s)&&f.push(u("page-field-twice",c,`"${s}" is on ${e}'s page twice; name each field once`)):f.push(u("page-field",c,`${e}'s page is to show "${s}", and ${e} has no field or computed field called that`,`use one of: ${l.join(", ")}`)),p.add(s)};(r.fields??[]).forEach((s,c)=>a(s,`${i}.fields.${c}`));let o=new Set;return(r.groups??[]).forEach((s,c)=>{let d=s.title.trim().toLowerCase();o.has(d)&&f.push(u("page-group-twice",`${i}.groups.${c}.title`,`${e}'s page has two groups called "${s.title}"; give each its own title`)),o.add(d),s.fields.forEach(($,n)=>a($,`${i}.groups.${c}.fields.${n}`))}),f}var de=new Set(["subject","now","today"]);function fe(e){if(typeof e=="string"){if(e.length>A)return{findings:[u("too-large","",`a document may be at most ${A/1024} KB`)]};try{e=JSON.parse(e)}catch(r){return{findings:[u("not-json","",`this is not JSON: ${r.message}`)]}}}else if(JSON.stringify(e??null).length>A)return{findings:[u("too-large","",`a document may be at most ${A/1024} KB`)]};try{e=te(e).document}catch(r){return{findings:[u("format","formatVersion",r.message)]}}let t=X.safeParse(e);if(!t.success)return{findings:t.error.issues.map(r=>{let f=r.path.map(String).join(".");if(r.code==="unrecognized_keys")return u("unknown-key",f,`${r.keys.map(l=>`"${l}"`).join(", ")} ${r.keys.length===1?"is":"are"} not part of a Graview document here`,"check the spelling against docs/declaration-document.md");if(r.code==="invalid_union"&&/\.effects\.\d+$/.test(f))return u("effect-shape",f,"this effect is not one Graview knows",'an effect is one of {"create": kind, "as"?: name, "set"?: {field: value}}, {"set": {field: value, \u2026}, "target"?: "$ref"}, {"connect"|"sever": relation, "from": "$ref", "to": "$ref"}, {"remove": "$ref"}');if(r.code==="invalid_key"){let l=r.issues?.[0]?.message;return u("shape",f,`the name "${String(r.path.at(-1))}" is not allowed here${l?`: ${l}`:""}`)}return u("shape",f,r.message)})};let i=t.data;return{document:i,findings:le(i)}}var P=e=>e===void 0?[]:Array.isArray(e)?e:[e];function re(e){let t=new Map;for(let[i,r]of Object.entries(e.kinds))for(let[f,l]of Object.entries(r.edges??{})){let p=t.get(f);t.set(f,{name:f,from:[...p?.from??[],i],to:l.to==="*"||p?.to==="*"?"*":[...new Set([...p?.to??[],...l.to])],cardinality:l.cardinality??"many"})}return t}function Ge(e){let t=new Map;for(let[r,f]of Object.entries(e.kinds)){let l=R(f);t.set(r,{fields:new Set(Object.keys(f.fields)),edges:new Map(Object.entries(f.edges??{}).map(([p,a])=>[p,a.cardinality??"many"])),...l?{computed:l}:{}})}let i=R(e);return i&&t.set(B,{computed:i}),t}function ie(e,t){let i=[],r=P(e.on),f=(l,p)=>{let a=se(t.kinds,l,r)?.reversed===!0,[o,s]=a?["$to","$subject"]:["$subject","$to"];return p==="connect"?{connect:l,from:o,to:s}:{sever:l,from:o,to:s}};if(e.creates){let l=t.kinds[e.creates],p={};for(let a of Object.keys(l?.fields??{}))p[a]=`$${a}`;for(let a of e.effects??[])"set"in a&&!("create"in a)&&b(a.target)==="new"&&Object.assign(p,a.set);i.push({create:e.creates,as:"new",set:p})}return e.sets&&i.push({set:e.sets}),e.writes&&!(e.creates&&e.on===void 0)&&i.push({set:Object.fromEntries(e.writes.map(l=>[l,`$${l}`]))}),e.connects&&(e.replaces&&i.push({replace:e.replaces===!0?[e.connects]:[...e.replaces],keep:e.connects}),i.push(f(e.connects,"connect"))),e.severs&&i.push(f(e.severs,"sever")),e.setsOther&&(e.connects||e.severs)&&i.push({set:e.setsOther,target:"$to"}),e.removes&&i.push({remove:"$subject"}),e.effects&&i.push(...e.effects.filter(l=>!(e.creates&&"set"in l&&!("create"in l)&&b(l.target)==="new"))),i}function C(e,t,i){try{let r=E(e),f=M(r);for(let l of f.unknownFunctions)i.push(u("unknown-function",t,`"${l}" is not a function the rule language knows`,"see docs/declaration-document.md#expression-language"));return r}catch(r){if(r instanceof K){i.push(u("expression",t,r.sentence+` (at character ${r.at+1})`));return}throw r}}function N(e,t,i){try{return F(e)}catch(r){if(r instanceof Y||r instanceof K){i.push(u("template",t,(r instanceof K,r.sentence)));return}throw r}}function le(e){let t=[],i=new Set(Object.keys(e.kinds)),r=re(e),f=e.acts??{},l=new Set(e.roles??[]);for(let[a,o]of Object.entries(e.kinds)){let s=`kinds.${a}`;for(let[d,$]of Object.entries(o.edges??{})){if($.to!=="*")for(let n of $.to)i.has(n)||t.push(u("edge-target",`${s}.edges.${d}.to`,`"${n}" is not a kind this document declares`));o.fields[d]&&t.push(u("edge-field-clash",`${s}.edges.${d}`,`"${d}" is both a field and a relation of ${a}`,"rename one of them"))}o.lifecycle&&!o.fields[o.lifecycle.field]&&t.push(u("lifecycle-field",`${s}.lifecycle.field`,`${a} has no field "${o.lifecycle.field}"`));let c=d=>o.computed!==void 0&&Object.hasOwn(o.computed,d);for(let d of o.glance??[])!o.fields[d]&&!c(d)&&t.push(u("glance-field",`${s}.glance`,`a glance at ${a} is to say "${d}", and ${a} has no field or computed field called that`,`use one of: ${[...Object.keys(o.fields),...Object.keys(o.computed??{})].join(", ")}`));t.push(...oe(a,o));for(let d of["label","describe"]){let $=o[d];if(!$)continue;let n=N($,`${s}.${d}`,t);for(let m of n??[])if(m.expr){for(let y of M(m.expr).names)if(!o.fields[y]){if(c(y)){ne(o,y)||t.push(u("template-field",`${s}.${d}`,`${a}'s ${y} is worked out from beyond the record, and a ${d} is said with no graph to read`,`show it in a view instead, or name a computed field worked out from ${a}'s own fields`));continue}t.push(u("template-field",`${s}.${d}`,`${a} has no field "${y}" for its ${d} to show`,d==="label"?"a label can only show the record's own fields and what they work out":void 0))}}}for(let[d,$]of Object.entries(o.fields))$.default!==void 0&&$.type==="enum"&&!$.options?.includes(String($.default))&&t.push(u("default-option",`${s}.fields.${d}.default`,`"${String($.default)}" is not one of ${d}'s options`))}for(let[a,o]of Object.entries(f)){let s=`acts.${a}`;for(let n of P(o.on))i.has(n)||t.push(u("act-kind",`${s}.on`,`"${n}" is not a kind this document declares`));let c=P(o.on),d=ie(o,e);if(o.creates&&o.on===void 0&&o.writes&&i.has(o.creates))for(let n of o.writes)e.kinds[o.creates].fields[n]||(e.kinds[o.creates].computed?.[n]!==void 0?t.push(u("computed-written",`${s}.writes`,`${o.creates}'s ${n} is worked out, not written: no act can set it`,"write the stored fields it is worked out from")):t.push(u("act-field",`${s}.writes`,`${o.creates} has no field "${n}"`)));d.length===0&&t.push(u("act-empty",s,`"${a}" does nothing`,"give it effects or a shorthand such as sets or creates"));let $=new Map;d.forEach((n,m)=>{let y=d.length-(o.effects?.length??0),w=o.effects&&m>=y?`${s}.effects.${m-y}`:s;if("create"in n){if(!i.has(n.create))t.push(u("act-kind",`${w}.create`,`"${n.create}" is not a kind this document declares`));else for(let h of Object.keys(n.set??{}))e.kinds[n.create].fields[h]||(e.kinds[n.create].computed?.[h]!==void 0?t.push(u("computed-written",`${w}.set.${h}`,`${n.create}'s ${h} is worked out, not written: no act can set it`,"set the stored fields it is worked out from")):t.push(u("act-field",`${w}.set.${h}`,`${n.create} has no field "${h}"`)));n.as&&$.set(n.as,n.create)}else if("connect"in n||"sever"in n){let h="connect"in n?n.connect:n.sever;r.has(h)||t.push(u("act-edge",`${w}.${"connect"in n?"connect":"sever"}`,`"${h}" is not a relation any kind declares`)),b(n.from)==="subject"&&c.length===0&&t.push(u("act-subject",`${s}.on`,`"${a}" acts on "$subject" but does not say which kinds it is "on"`))}else if("set"in n){let h=b(n.target??"$subject"),O=h==="subject"?c:$.has(h??"")?[$.get(h)]:[];h==="subject"&&c.length===0&&t.push(u("act-subject",`${s}.on`,`"${a}" changes "$subject" but does not say which kinds it is "on"`));for(let S of Object.keys(n.set))for(let x of O)!i.has(x)||e.kinds[x].fields[S]||(e.kinds[x].computed?.[S]!==void 0?t.push(u("computed-written",`${w}.set.${S}`,`${x}'s ${S} is worked out, not written: no act can set it`,"set the stored fields it is worked out from")):t.push(u("act-field",`${w}.set.${S}`,`${x} has no field "${S}"`)))}else"remove"in n&&b(n.remove)==="subject"&&c.length===0&&t.push(u("act-subject",`${s}.on`,`"${a}" removes "$subject" but does not say which kinds it is "on"`));("set"in n&&n.set?Object.values(n.set):[]).forEach(h=>{h&&typeof h=="object"&&!Array.isArray(h)&&"expr"in h&&C(h.expr,`${w}.set`,t)})}),o.allowedWhen&&C(o.allowedWhen,`${s}.allowedWhen`,t),o.refusal&&N(o.refusal,`${s}.refusal`,t)}for(let[a,o]of Object.entries(e.rules??{})){let s=`rules.${a}`;o.over!=="graph"&&!i.has(o.over)&&t.push(u("rule-kind",`${s}.over`,`"${o.over}" is not a kind this document declares`));let c=o.over==="graph"?void 0:e.kinds[o.over];for(let d of["when","require"]){let $=o[d];if(!$)continue;let n=C($,`${s}.${d}`,t);if(!n)continue;let m=M(n);for(let y of m.names)if(o.over==="graph")t.push(u("rule-name",`${s}.${d}`,`"${y}" means nothing in a rule over the whole graph`,`name a kind in "over", or use all('kind')`));else if(c&&!c.fields[y]&&!c.edges?.[y]&&c.computed?.[y]===void 0){let w=Object.keys(c.edges??{}).find(v=>v.includes("-")&&v.split("-").includes(y));t.push(u("rule-name",`${s}.${d}`,`${o.over} has no field or relation called "${y}"`,w?`"${w}" reads as a subtraction in a rule; rename the relation to one camelCase word, like "${w.replace(/-([a-z0-9])/g,(v,h)=>h.toUpperCase())}"`:void 0))}for(let y of m.edges)r.has(y)||t.push(u("rule-edge",`${s}.${d}`,`"${y}" is not a relation any kind declares`));for(let y of m.sweeps)i.has(y)?o.over!=="graph"&&t.push(I("rule-cost",`${s}.${d}`,`this rule looks at every ${y} for every ${o.over}, which grows slowly as the app grows`,"walk a relation with out()/in() instead of all() where you can")):t.push(u("rule-kind",`${s}.${d}`,`"${y}" is not a kind this document declares`))}o.says&&N(o.says,`${s}.says`,t),(o.repairs??[]).forEach((d,$)=>{!f[d.act]&&!/^(edit|remove)-/.test(d.act)&&t.push(u("repair-act",`${s}.repairs.${$}.act`,`"${d.act}" is not an act this document declares`))})}let p=e.policy;return p&&(p.grants.forEach((a,o)=>{if(a.roles!=="*"&&l.size>0)for(let s of a.roles)l.has(s)||t.push(u("grant-role",`policy.grants.${o}.roles`,`"${s}" is not one of the document's roles`));if(a.mutations!=="*")for(let s of a.mutations)!f[s]&&!/^(edit|remove)-/.test(s)&&t.push(u("grant-act",`policy.grants.${o}.mutations`,`"${s}" is not an act this document declares`))}),(p.sees??[]).forEach((a,o)=>{for(let s of a.kinds)i.has(s)||t.push(u("sight-kind",`policy.sees.${o}.kinds`,`"${s}" is not a kind this document declares`));if(a.roles!=="*"&&l.size>0)for(let s of a.roles)l.has(s)||t.push(u("sight-role",`policy.sees.${o}.roles`,`"${s}" is not one of the document's roles`))})),t.push(...ee(e)),t}function ue(e,t,i,r){let f=new Map,l=P(e.on),p=new Map,a=new Map;(l.length>0||t.some(n=>"remove"in n&&b(n.remove)==="subject"||"from"in n&&(b(n.from)==="subject"||b(n.to)==="subject")||"set"in n&&!("create"in n)&&b(n.target??"$subject")==="subject"))&&f.set(q,{ref:l.length>0?l:"*",required:!0});let s=e.args??{},c=e.writes?.length===1,d=(n,m)=>m&&n.type===m.type&&n.min===void 0&&n.max===void 0&&n.step===void 0?{...n,...m.min===void 0?{}:{min:m.min},...m.max===void 0?{}:{max:m.max},...m.step===void 0?{}:{step:m.step}}:n,$=(n,m,y)=>{if(n===q||de.has(n)||p.has(n)||f.has(n))return;let w=s[n]?d(s[n],y):void 0;f.set(n,w?{field:w,optional:!w.required,required:!!w.required}:m())};for(let n of t)if("create"in n){let m=i.kinds[n.create];for(let[y,w]of Object.entries(n.set??{})){let v=b(w),h=m?.fields[y];if(v&&h){let O=!!h.required&&h.default===void 0;$(v,()=>({field:h,optional:!O,required:O}),h)}}n.as&&p.set(n.as,n.create)}else if("connect"in n||"sever"in n){let m=r.get("connect"in n?n.connect:n.sever);for(let[y,w]of[["from",n.from],["to",n.to]]){let v=b(w);if(!v)continue;let h=y==="to"?m?.to??"*":m?.from??"*";h!=="*"&&!a.has(v)&&a.set(v,h),$(v,()=>({ref:h,required:!0}))}}else if("set"in n){let m=b(n.target??"$subject"),y=m==="subject"?l[0]:p.get(m??"")??a.get(m??"")?.[0];m&&m!=="subject"&&!p.has(m)&&$(m,()=>({ref:"*",required:!0}));for(let[w,v]of Object.entries(n.set)){let h=b(v);if(!h)continue;let O=y?i.kinds[y]?.fields[w]:void 0;$(h,()=>O?{field:O,optional:!c,required:c}:{any:!0,required:!1},O)}}else if("remove"in n){let m=b(n.remove);m&&$(m,()=>({ref:"*",required:!0}))}for(let[n,m]of Object.entries(s))f.has(n)||f.set(n,{field:m,optional:!m.required,required:!!m.required});return f}function qe(e,t={}){let i=fe(e);if(!i.document||G(i.findings))return{ok:!1,findings:i.findings};let r=i.document,f=[...i.findings];t.previous&&f.push(...ge(r,t.previous));let l=pe(r,f);return G(l.findings)?{ok:!1,findings:l.findings}:J(l,t)}function pe(e,t){let i=re(e),r={};for(let[s,c]of Object.entries(e.kinds)){let d=z(c),$=c.label??(d?`{${d}}`:void 0),n=R(c);r[s]={...$?{label:F($)}:{},...c.describe?{describe:F(c.describe)}:{},...n?{computed:[...n]}:{}}}let f={};for(let[s,c]of Object.entries(e.acts??{})){let d=ie(c,e),$=ue(c,d,e,i),n=c.destructive??d.some(g=>"remove"in g||"sever"in g||"replace"in g),m=[...new Set(d.flatMap(g=>"create"in g?[g.create]:[]))],y=[...new Set(d.flatMap(g=>"connect"in g?[g.connect]:[]))],w=[...new Set(d.flatMap(g=>"sever"in g?[g.sever]:"replace"in g?g.replace:[]))],v=[...new Set(d.flatMap(g=>"set"in g&&!("create"in g)&&b(g.target??"$subject")==="subject"?Object.keys(g.set):[]))],h=new Map;for(let g of d){if(!("connect"in g)&&!("sever"in g))continue;let k=i.get("connect"in g?g.connect:g.sever);for(let[j,ae]of[["from",g.from],["to",g.to]]){let D=b(ae),T=j==="to"?k?.to:k?.from;D&&D!=="subject"&&T&&T!=="*"&&h.set(D,[...new Set([...h.get(D)??[],...T])])}}let O={};for(let g of d){if(!("set"in g)||"create"in g)continue;let k=b(g.target??"$subject");for(let j of k&&k!=="subject"&&h.get(k)||[])O[j]=[...new Set([...O[j]??[],...Object.keys(g.set)])]}let S={};for(let g of d)if(!(!("set"in g)||"create"in g||b(g.target??"$subject")!=="subject"))for(let[k,j]of Object.entries(g.set??{}))typeof j=="string"&&b(j)===void 0||typeof j=="number"||typeof j=="boolean"?S[k]=typeof j=="string"&&j.startsWith("$$")?j.slice(1):j:delete S[k];let x=m.length===0&&d.every(g=>!("set"in g)||!g.set||Object.values(g.set).every(k=>!(k&&typeof k=="object"&&!Array.isArray(k)&&"expr"in k))),_=new Map;for(let g of d)if(!(!("set"in g)||!g.set))for(let k of Object.values(g.set))k&&typeof k=="object"&&!Array.isArray(k)&&"expr"in k&&_.set(k.expr,E(k.expr));f[s]={title:c.title??s.replace(/-/g," "),effects:d,args:[...$],...c.allowedWhen?{guard:E(c.allowedWhen)}:{},...c.refusal?{refusal:F(c.refusal)}:{},exprs:[..._],destructive:n,idempotent:x,creates:m,connects:y,severs:w,writes:v,writesOther:O,sets:S}}let l={};for(let[s,c]of Object.entries(e.rules??{}))l[s]={title:c.title??s.replace(/-/g," "),require:E(c.require),...c.when?{when:E(c.when)}:{},...c.says?{says:F(c.says)}:{}};let p=V(e,t),a=Q(e),o=Z(e);return{format:W,document:e,findings:t,kinds:r,...e.computed?{facts:[...R(e)??[]]}:{},edges:[...i].map(([s,{from:c,to:d,cardinality:$}])=>[s,{from:c,to:d,cardinality:$}]),acts:f,rules:l,brand:p,...Object.keys(a).length>0?{viewSpecs:a}:{},...o?{home:o}:{}}}function Ce(e,t){let i=e.split(/[\s:·]/).find(r=>r.length>0)??e;return t.kinds[i]?`kinds.${i}`:t.acts?.[i]?`acts.${i}`:t.rules?.[i]?`rules.${i}`:e}function Ne(e,t,i){let r=/^defineNode\("([^"]+)"\)/.exec(t)?.[1],f=r?i.kinds[r]:void 0;if(!r||!f)return e;let l=Object.keys(f.fields).filter(p=>p!=="label").slice(0,3);return{...e,path:`kinds.${r}.glance`,fix:`Say which: "glance": [${l.map(p=>`"${p}"`).join(", ")}] on kinds.${r} \u2014 the facts a person compares one by, at a glance.`}}function ge(e,t){let i=[],r=new Set(Object.values(t.kinds).flatMap(f=>Object.keys(f.edges??{})));for(let[f,l]of Object.entries(e.kinds)){let p=l.renamedFrom;p&&!t.kinds[p]&&i.push(u("renamed-from-nothing",`kinds.${f}.renamedFrom`,`${f} says it was ${p}, and the previous version has no kind called ${p}`,"name the kind it was, or drop renamedFrom"));let a=t.kinds[p??f];for(let[o,s]of Object.entries(l.fields)){let c=s.renamedFrom;c&&!a?.fields[c]&&i.push(u("renamed-from-nothing",`kinds.${f}.fields.${o}.renamedFrom`,`${o} says it was ${c}, and the previous ${p??f} has no field called ${c}`,"name the field it was, or drop renamedFrom"))}for(let[o,s]of Object.entries(l.edges??{})){let c=s.renamedFrom;c&&!r.has(c)&&i.push(u("renamed-from-nothing",`kinds.${f}.edges.${o}.renamedFrom`,`${o} says it was ${c}, and the previous version has no relation called ${c}`,"name the relation it was, or drop renamedFrom"))}}return i}export{fe as a,Ge as b,ie as c,qe as d,Ce as e,Ne as f};
@@ -1,2 +1,2 @@
1
- import{C as L,D as T,S as D}from"./chunk.Y235YZSZ.js";var Y=1e4,g=class{constructor(i){this.nodes=i}},B="",c=class extends Error{constructor(f,l){super(f);this.sentence=f;this.at=l}},_=class extends c{},V=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof g)&&typeof t.id=="string",U=t=>{let i=new Set;return new g(t.filter(f=>!i.has(f.id)&&i.add(f.id)))},p=t=>t===null?"nothing":t instanceof g?"a set of records":Array.isArray(t)?"a list":V(t)?"a record":typeof t=="string"?"a word":typeof t;function P(t,i){let f=i.budget??Y,l=(n,s)=>{if(f-=n,f<0)throw new _("this rule looks at too much of the graph to judge in one go",s)},b=i.today??new Date().toISOString().slice(0,10),A=i.now??new Date().toISOString(),w=new Map,F=new Set,G=i.bindings,I=(n,s,e,o)=>{let u=`${n?.id}\0${s}`;if(w.has(u))return w.get(u);if(F.has(u))throw new c(`"${s}"${n?` of ${D(n.kind)}`:""} depends on itself`,o);F.add(u);let r=G;G=void 0;try{let a=h(e,n);return w.set(u,a),a}finally{G=r,F.delete(u)}},M=(n,s,e)=>{l(1,e);let o=i.kinds.get(n.kind),u=o?.computed?.get(s);if(u)return I(n,s,u,e);let r=Object.hasOwn(n,s);if(o?.fields.has(s)||r){let d=r?n[s]:void 0;return d===void 0?null:d}let a=o?.edges.get(s);if(a){let d=i.graph.out(n.id,s);return l(d.length,e),a==="one"?d[0]??null:new g(d)}if(s==="id")return n.id;throw new c(`${D(n.kind)} has no field or relation called "${s}"`,e)},S=(n,s,e)=>{if(n instanceof g)return n;if(n===null)return new g([]);if(V(n))return new g([n]);throw new c(`${e}(\u2026) needs a set of records, and was given ${p(n)}`,s)},k=(n,s,e)=>{if(n===null)return null;if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean")return String(n);throw new c(`${e}(\u2026) needs a word, and was given ${p(n)}`,s)},O=(n,s,e)=>{let o=k(n,s,e);if(o===null)return null;let u=Date.parse(o.length===10?`${o}T00:00:00Z`:o);if(Number.isNaN(u))throw new c(`${e}(\u2026) needs a date, and "${o}" is not one`,s);return u},E=(n,s)=>V(n)&&V(s)?n.id===s.id:V(n)&&typeof s=="string"?n.id===s:typeof n=="string"&&V(s)?n===s.id:Array.isArray(n)&&Array.isArray(s)?n.length===s.length&&n.every((e,o)=>E(e,s[o])):n===s,N=(n,s,e)=>{if(n===null)return!1;if(typeof n=="boolean")return n;throw new c(`${e} must be true or false, and was ${p(n)}`,s)},R=(n,s)=>h(s,n);function h(n,s){switch(l(1,n.at),n.t){case"lit":return n.value;case"list":return n.items.map(e=>h(e,s));case"ident":{let e=G&&Object.hasOwn(G,n.name)?G[n.name]:void 0;if(e!==void 0)return e;if(s)return M(s,n.name,n.at);throw new c(`"${n.name}" means nothing in a rule over the whole graph`,n.at)}case"member":{let e=h(n.object,s);if(e===null)return null;if(V(e))return M(e,n.name,n.at);throw new c(`".${n.name}" needs a record before it, and was given ${p(e)}`,n.at)}case"unary":{let e=h(n.operand,s);if(n.op==="!")return!N(e,n.at,"what follows not");if(e===null)return null;if(typeof e!="number")throw new c(`"-" needs a number, and was given ${p(e)}`,n.at);return-e}case"where":{let e=S(h(n.set,s),n.at,"where");return l(e.nodes.length,n.at),new g(e.nodes.filter(o=>N(R(o,n.filter),n.at,"a where condition")))}case"binary":return z(n,s);case"call":return H(n,s)}}function z(n,s){if(n.op==="&&")return N(h(n.left,s),n.at,"each side of and")&&N(h(n.right,s),n.at,"each side of and");if(n.op==="||")return N(h(n.left,s),n.at,"each side of or")||N(h(n.right,s),n.at,"each side of or");let e=h(n.left,s),o=h(n.right,s);if(n.op==="&"||n.op==="|"||n.op==="-"&&(e instanceof g||o instanceof g)){let u=S(e,n.at,n.op).nodes,r=S(o,n.at,n.op).nodes;l(u.length+r.length,n.at);let a=new Set(r.map(d=>d.id));return U(n.op==="|"?[...u,...r]:u.filter(d=>a.has(d.id)===(n.op==="&")))}switch(n.op){case"==":return E(e,o);case"!=":return!E(e,o);case"in":{if(o===null)return!1;if(o instanceof g)return o.nodes.some(u=>E(e,u));if(Array.isArray(o))return o.some(u=>E(e,u));if(typeof o=="string"&&typeof e=="string")return o.includes(e);throw new c(`"in" needs a list or a set on its right, and was given ${p(o)}`,n.at)}case"<":case"<=":case">":case">=":{if(e===null||o===null)return!1;if(!(typeof e=="number"&&typeof o=="number"||typeof e=="string"&&typeof o=="string"))throw new c(`cannot compare ${p(e)} with ${p(o)}`,n.at);return n.op==="<"?e<o:n.op==="<="?e<=o:n.op===">"?e>o:e>=o}default:{if(e===null||o===null)return null;if(n.op==="+"&&(typeof e=="string"||typeof o=="string")){let u=`${k(e,n.at,"+")}${k(o,n.at,"+")}`;if(u.length>1e4)throw new c("that makes a word too long",n.at);return u}if(typeof e!="number"||typeof o!="number")throw new c(`"${n.op}" needs numbers, and was given ${p(e)} and ${p(o)}`,n.at);return(n.op==="/"||n.op==="%")&&o===0?null:n.op==="+"?e+o:n.op==="-"?e-o:n.op==="*"?e*o:n.op==="/"?e/o:e%o}}}function H(n,s){let e=(r,a=r)=>{if(n.args.length<r||n.args.length>a)throw new c(`${n.fn}(\u2026) takes ${r===a?r:`${r} to ${a}`} argument${a===1?"":"s"}`,n.at)},o=r=>h(n.args[r],s),u=r=>{let a=o(r);if(typeof a!="string")throw new c(`${n.fn}(\u2026) needs a quoted name, like ${n.fn}('name')`,n.at);return a};switch(n.fn){case"out":case"in":{e(1,2);let r=($,m)=>n.fn==="out"?i.graph.out($,m):i.graph.in($,m);if(n.args.length===2){let $=S(o(0),n.at,n.fn).nodes,m=u(1);return U($.flatMap(y=>{let x=r(y.id,m);return l(x.length+1,n.at),x}))}let a=u(0);if(!s)throw new c(`${n.fn}('${a}') needs a record to start from`,n.at);let d=r(s.id,a);return l(d.length,n.at),new g(d)}case"all":{e(1);let r=i.graph.nodesOfKind(u(0));return l(r.length,n.at),new g(r)}case"count":return e(1),S(o(0),n.at,"count").nodes.length;case"exists":return e(1),S(o(0),n.at,"exists").nodes.length>0;case"every":case"some":{e(2);let r=S(o(0),n.at,n.fn);l(r.nodes.length,n.at);let a=d=>N(R(d,n.args[1]),n.at,`the condition in ${n.fn}(\u2026)`);return n.fn==="every"?r.nodes.every(a):r.nodes.some(a)}case"sum":case"min":case"max":{e(2);let r=S(o(0),n.at,n.fn);l(r.nodes.length,n.at);let a=n.args[1],d=a.t==="lit"&&typeof a.value=="string"?a.value:void 0,$=a.t==="ident"?`'${a.name}'`:d!==void 0?`'${d}'`:"\u2026",m=r.nodes.map(y=>a.t==="ident"?M(y,a.name,n.at):d!==void 0?M(y,d,n.at):R(y,a)).filter(y=>{if(y===null)return!1;if(typeof y!="number")throw new c(`${n.fn}(\u2026, ${$}) needs a number for each member, and found ${p(y)}`,n.at);return!0});return n.fn==="sum"?m.reduce((y,x)=>y+x,0):m.length===0?null:n.fn==="min"?Math.min(...m):Math.max(...m)}case"fact":{e(1);let r=u(0),a=i.kinds.get(B)?.computed?.get(r);if(!a)throw new c(`no fact is called "${r}"`,n.at);return I(null,r,a,n.at)}case"first":return e(1),S(o(0),n.at,"first").nodes[0]??null;case"sort":{e(2,3);let r=S(o(0),n.at,"sort"),a=n.args.length===3?o(2):"asc";if(a!=="asc"&&a!=="desc")throw new c("sort(\u2026) goes 'asc' or 'desc'",n.at);let d=r.nodes.length;l(d+d*Math.ceil(Math.log2(d+1)),n.at);let $=r.nodes.map((y,x)=>({node:y,i:x,key:R(y,n.args[1])})),m=a==="desc"?-1:1;return $.sort((y,x)=>K(y.key,x.key,m,n.at)||y.i-x.i),new g($.map(y=>y.node))}case"either":{if(n.args.length<1)throw new c("either(\u2026) takes at least one argument",n.at);for(let r=0;r<n.args.length;r++){let a=o(r);if(a!==null&&!(a instanceof g&&a.nodes.length===0))return a}return null}case"present":{e(1);let r=o(0);return r===null||r===""?!1:Array.isArray(r)?r.length>0:r instanceof g?r.nodes.length>0:!0}case"len":{e(1);let r=o(0);if(r===null)return 0;if(typeof r=="string"||Array.isArray(r))return r.length;if(r instanceof g)return r.nodes.length;throw new c(`len(\u2026) needs a word or a list, and was given ${p(r)}`,n.at)}case"contains":case"startsWith":{e(2);let r=o(0),a=o(1);if(r===null||a===null)return!1;if(n.fn==="contains"&&Array.isArray(r))return r.some(m=>E(m,a));let d=k(r,n.at,n.fn),$=k(a,n.at,n.fn);return n.fn==="contains"?d.toLowerCase().includes($.toLowerCase()):d.startsWith($)}case"lower":{e(1);let r=k(o(0),n.at,"lower");return r===null?null:r.toLowerCase()}case"today":return e(0),b;case"now":return e(0),A;case"date":{e(1);let r=O(o(0),n.at,"date");return r===null?null:new Date(r).toISOString().slice(0,10)}case"days":case"hours":{e(2);let r=O(o(0),n.at,n.fn),a=O(o(1),n.at,n.fn);if(r===null||a===null)return null;let d=(a-r)/(n.fn==="days"?864e5:36e5);return n.fn==="days"?Math.round(d):d}case"if":return e(3),N(o(0),n.at,"the condition in if(\u2026)")?o(1):o(2);default:throw new c(`"${n.fn}" is not a function the rule language knows`,n.at)}}function K(n,s,e,o){if(n===null||s===null)return n===s?0:n===null?1:-1;if(Array.isArray(n)&&Array.isArray(s)){for(let r=0;r<Math.max(n.length,s.length);r++){let a=K(n[r]??null,s[r]??null,e,o);if(a!==0)return a}return 0}let u=r=>typeof r=="number"||typeof r=="string"||typeof r=="boolean"?typeof r:p(r);if(u(n)!==u(s)||typeof n=="object"||typeof s=="object")throw new c(`sort(\u2026) cannot put ${p(n)} and ${p(s)} in order`,o);return typeof n=="string"?e*(n<s?-1:n>s?1:0):e*(Number(n)-Number(s))}return h(t,i.subject)}var tn=["out","in","all","count","exists","every","some","sum","min","max","present","len","contains","startsWith","lower","today","now","date","days","hours","if","first","sort","either","fact"];var rn=(t,i,f,l)=>({severity:"error",code:t,path:i,message:f,...l?{fix:l}:{}}),on=(t,i,f,l)=>({severity:"warning",code:t,path:i,message:f,...l?{fix:l}:{}}),sn=t=>t.some(i=>i.severity==="error");function an(t){return t.map(i=>`${i.severity==="error"?"\u2717":i.severity==="warning"?"!":"\xB7"} ${i.path||"(document)"}: ${i.message}${i.fix?` \u2014 ${i.fix}`:""}`).join(`
1
+ import{C as L,D as T,S as D}from"./chunk.ZQ4HFIIS.js";var Y=1e4,g=class{constructor(i){this.nodes=i}},B="",c=class extends Error{constructor(f,l){super(f);this.sentence=f;this.at=l}},_=class extends c{},V=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&!(t instanceof g)&&typeof t.id=="string",U=t=>{let i=new Set;return new g(t.filter(f=>!i.has(f.id)&&i.add(f.id)))},p=t=>t===null?"nothing":t instanceof g?"a set of records":Array.isArray(t)?"a list":V(t)?"a record":typeof t=="string"?"a word":typeof t;function P(t,i){let f=i.budget??Y,l=(n,s)=>{if(f-=n,f<0)throw new _("this rule looks at too much of the graph to judge in one go",s)},b=i.today??new Date().toISOString().slice(0,10),A=i.now??new Date().toISOString(),w=new Map,F=new Set,G=i.bindings,I=(n,s,e,o)=>{let u=`${n?.id}\0${s}`;if(w.has(u))return w.get(u);if(F.has(u))throw new c(`"${s}"${n?` of ${D(n.kind)}`:""} depends on itself`,o);F.add(u);let r=G;G=void 0;try{let a=h(e,n);return w.set(u,a),a}finally{G=r,F.delete(u)}},M=(n,s,e)=>{l(1,e);let o=i.kinds.get(n.kind),u=o?.computed?.get(s);if(u)return I(n,s,u,e);let r=Object.hasOwn(n,s);if(o?.fields.has(s)||r){let d=r?n[s]:void 0;return d===void 0?null:d}let a=o?.edges.get(s);if(a){let d=i.graph.out(n.id,s);return l(d.length,e),a==="one"?d[0]??null:new g(d)}if(s==="id")return n.id;throw new c(`${D(n.kind)} has no field or relation called "${s}"`,e)},S=(n,s,e)=>{if(n instanceof g)return n;if(n===null)return new g([]);if(V(n))return new g([n]);throw new c(`${e}(\u2026) needs a set of records, and was given ${p(n)}`,s)},k=(n,s,e)=>{if(n===null)return null;if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean")return String(n);throw new c(`${e}(\u2026) needs a word, and was given ${p(n)}`,s)},O=(n,s,e)=>{let o=k(n,s,e);if(o===null)return null;let u=Date.parse(o.length===10?`${o}T00:00:00Z`:o);if(Number.isNaN(u))throw new c(`${e}(\u2026) needs a date, and "${o}" is not one`,s);return u},E=(n,s)=>V(n)&&V(s)?n.id===s.id:V(n)&&typeof s=="string"?n.id===s:typeof n=="string"&&V(s)?n===s.id:Array.isArray(n)&&Array.isArray(s)?n.length===s.length&&n.every((e,o)=>E(e,s[o])):n===s,N=(n,s,e)=>{if(n===null)return!1;if(typeof n=="boolean")return n;throw new c(`${e} must be true or false, and was ${p(n)}`,s)},R=(n,s)=>h(s,n);function h(n,s){switch(l(1,n.at),n.t){case"lit":return n.value;case"list":return n.items.map(e=>h(e,s));case"ident":{let e=G&&Object.hasOwn(G,n.name)?G[n.name]:void 0;if(e!==void 0)return e;if(s)return M(s,n.name,n.at);throw new c(`"${n.name}" means nothing in a rule over the whole graph`,n.at)}case"member":{let e=h(n.object,s);if(e===null)return null;if(V(e))return M(e,n.name,n.at);throw new c(`".${n.name}" needs a record before it, and was given ${p(e)}`,n.at)}case"unary":{let e=h(n.operand,s);if(n.op==="!")return!N(e,n.at,"what follows not");if(e===null)return null;if(typeof e!="number")throw new c(`"-" needs a number, and was given ${p(e)}`,n.at);return-e}case"where":{let e=S(h(n.set,s),n.at,"where");return l(e.nodes.length,n.at),new g(e.nodes.filter(o=>N(R(o,n.filter),n.at,"a where condition")))}case"binary":return z(n,s);case"call":return H(n,s)}}function z(n,s){if(n.op==="&&")return N(h(n.left,s),n.at,"each side of and")&&N(h(n.right,s),n.at,"each side of and");if(n.op==="||")return N(h(n.left,s),n.at,"each side of or")||N(h(n.right,s),n.at,"each side of or");let e=h(n.left,s),o=h(n.right,s);if(n.op==="&"||n.op==="|"||n.op==="-"&&(e instanceof g||o instanceof g)){let u=S(e,n.at,n.op).nodes,r=S(o,n.at,n.op).nodes;l(u.length+r.length,n.at);let a=new Set(r.map(d=>d.id));return U(n.op==="|"?[...u,...r]:u.filter(d=>a.has(d.id)===(n.op==="&")))}switch(n.op){case"==":return E(e,o);case"!=":return!E(e,o);case"in":{if(o===null)return!1;if(o instanceof g)return o.nodes.some(u=>E(e,u));if(Array.isArray(o))return o.some(u=>E(e,u));if(typeof o=="string"&&typeof e=="string")return o.includes(e);throw new c(`"in" needs a list or a set on its right, and was given ${p(o)}`,n.at)}case"<":case"<=":case">":case">=":{if(e===null||o===null)return!1;if(!(typeof e=="number"&&typeof o=="number"||typeof e=="string"&&typeof o=="string"))throw new c(`cannot compare ${p(e)} with ${p(o)}`,n.at);return n.op==="<"?e<o:n.op==="<="?e<=o:n.op===">"?e>o:e>=o}default:{if(e===null||o===null)return null;if(n.op==="+"&&(typeof e=="string"||typeof o=="string")){let u=`${k(e,n.at,"+")}${k(o,n.at,"+")}`;if(u.length>1e4)throw new c("that makes a word too long",n.at);return u}if(typeof e!="number"||typeof o!="number")throw new c(`"${n.op}" needs numbers, and was given ${p(e)} and ${p(o)}`,n.at);return(n.op==="/"||n.op==="%")&&o===0?null:n.op==="+"?e+o:n.op==="-"?e-o:n.op==="*"?e*o:n.op==="/"?e/o:e%o}}}function H(n,s){let e=(r,a=r)=>{if(n.args.length<r||n.args.length>a)throw new c(`${n.fn}(\u2026) takes ${r===a?r:`${r} to ${a}`} argument${a===1?"":"s"}`,n.at)},o=r=>h(n.args[r],s),u=r=>{let a=o(r);if(typeof a!="string")throw new c(`${n.fn}(\u2026) needs a quoted name, like ${n.fn}('name')`,n.at);return a};switch(n.fn){case"out":case"in":{e(1,2);let r=($,m)=>n.fn==="out"?i.graph.out($,m):i.graph.in($,m);if(n.args.length===2){let $=S(o(0),n.at,n.fn).nodes,m=u(1);return U($.flatMap(y=>{let x=r(y.id,m);return l(x.length+1,n.at),x}))}let a=u(0);if(!s)throw new c(`${n.fn}('${a}') needs a record to start from`,n.at);let d=r(s.id,a);return l(d.length,n.at),new g(d)}case"all":{e(1);let r=i.graph.nodesOfKind(u(0));return l(r.length,n.at),new g(r)}case"count":return e(1),S(o(0),n.at,"count").nodes.length;case"exists":return e(1),S(o(0),n.at,"exists").nodes.length>0;case"every":case"some":{e(2);let r=S(o(0),n.at,n.fn);l(r.nodes.length,n.at);let a=d=>N(R(d,n.args[1]),n.at,`the condition in ${n.fn}(\u2026)`);return n.fn==="every"?r.nodes.every(a):r.nodes.some(a)}case"sum":case"min":case"max":{e(2);let r=S(o(0),n.at,n.fn);l(r.nodes.length,n.at);let a=n.args[1],d=a.t==="lit"&&typeof a.value=="string"?a.value:void 0,$=a.t==="ident"?`'${a.name}'`:d!==void 0?`'${d}'`:"\u2026",m=r.nodes.map(y=>a.t==="ident"?M(y,a.name,n.at):d!==void 0?M(y,d,n.at):R(y,a)).filter(y=>{if(y===null)return!1;if(typeof y!="number")throw new c(`${n.fn}(\u2026, ${$}) needs a number for each member, and found ${p(y)}`,n.at);return!0});return n.fn==="sum"?m.reduce((y,x)=>y+x,0):m.length===0?null:n.fn==="min"?Math.min(...m):Math.max(...m)}case"fact":{e(1);let r=u(0),a=i.kinds.get(B)?.computed?.get(r);if(!a)throw new c(`no fact is called "${r}"`,n.at);return I(null,r,a,n.at)}case"first":return e(1),S(o(0),n.at,"first").nodes[0]??null;case"sort":{e(2,3);let r=S(o(0),n.at,"sort"),a=n.args.length===3?o(2):"asc";if(a!=="asc"&&a!=="desc")throw new c("sort(\u2026) goes 'asc' or 'desc'",n.at);let d=r.nodes.length;l(d+d*Math.ceil(Math.log2(d+1)),n.at);let $=r.nodes.map((y,x)=>({node:y,i:x,key:R(y,n.args[1])})),m=a==="desc"?-1:1;return $.sort((y,x)=>K(y.key,x.key,m,n.at)||y.i-x.i),new g($.map(y=>y.node))}case"either":{if(n.args.length<1)throw new c("either(\u2026) takes at least one argument",n.at);for(let r=0;r<n.args.length;r++){let a=o(r);if(a!==null&&!(a instanceof g&&a.nodes.length===0))return a}return null}case"present":{e(1);let r=o(0);return r===null||r===""?!1:Array.isArray(r)?r.length>0:r instanceof g?r.nodes.length>0:!0}case"len":{e(1);let r=o(0);if(r===null)return 0;if(typeof r=="string"||Array.isArray(r))return r.length;if(r instanceof g)return r.nodes.length;throw new c(`len(\u2026) needs a word or a list, and was given ${p(r)}`,n.at)}case"contains":case"startsWith":{e(2);let r=o(0),a=o(1);if(r===null||a===null)return!1;if(n.fn==="contains"&&Array.isArray(r))return r.some(m=>E(m,a));let d=k(r,n.at,n.fn),$=k(a,n.at,n.fn);return n.fn==="contains"?d.toLowerCase().includes($.toLowerCase()):d.startsWith($)}case"lower":{e(1);let r=k(o(0),n.at,"lower");return r===null?null:r.toLowerCase()}case"today":return e(0),b;case"now":return e(0),A;case"date":{e(1);let r=O(o(0),n.at,"date");return r===null?null:new Date(r).toISOString().slice(0,10)}case"days":case"hours":{e(2);let r=O(o(0),n.at,n.fn),a=O(o(1),n.at,n.fn);if(r===null||a===null)return null;let d=(a-r)/(n.fn==="days"?864e5:36e5);return n.fn==="days"?Math.round(d):d}case"if":return e(3),N(o(0),n.at,"the condition in if(\u2026)")?o(1):o(2);default:throw new c(`"${n.fn}" is not a function the rule language knows`,n.at)}}function K(n,s,e,o){if(n===null||s===null)return n===s?0:n===null?1:-1;if(Array.isArray(n)&&Array.isArray(s)){for(let r=0;r<Math.max(n.length,s.length);r++){let a=K(n[r]??null,s[r]??null,e,o);if(a!==0)return a}return 0}let u=r=>typeof r=="number"||typeof r=="string"||typeof r=="boolean"?typeof r:p(r);if(u(n)!==u(s)||typeof n=="object"||typeof s=="object")throw new c(`sort(\u2026) cannot put ${p(n)} and ${p(s)} in order`,o);return typeof n=="string"?e*(n<s?-1:n>s?1:0):e*(Number(n)-Number(s))}return h(t,i.subject)}var tn=["out","in","all","count","exists","every","some","sum","min","max","present","len","contains","startsWith","lower","today","now","date","days","hours","if","first","sort","either","fact"];var rn=(t,i,f,l)=>({severity:"error",code:t,path:i,message:f,...l?{fix:l}:{}}),on=(t,i,f,l)=>({severity:"warning",code:t,path:i,message:f,...l?{fix:l}:{}}),sn=t=>t.some(i=>i.severity==="error");function an(t){return t.map(i=>`${i.severity==="error"?"\u2717":i.severity==="warning"?"!":"\xB7"} ${i.path||"(document)"}: ${i.message}${i.fix?` \u2014 ${i.fix}`:""}`).join(`
2
2
  `)}var cn=["money","percent","date","relative","upper","lower","count","words","and","plural"],J={getNode:()=>{},allNodes:()=>[],allEdges:()=>[],nodesOfKind:()=>[],edgesOfKind:()=>[],out:()=>[],in:()=>[],neighbors:()=>[],has:()=>!1};function fn(t,i,f,l=[],b){return j(t,i,f,l,b)}function Q(t,i={}){let f=Number.isInteger(t),l={maximumFractionDigits:f?0:2,minimumFractionDigits:f?0:2};try{return new Intl.NumberFormat(i.locale??"en-US",i.currency?{style:"currency",currency:i.currency,...l}:l).format(t)}catch{return t.toLocaleString("en-US",l)}}var W=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],q=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"];function X(t){return!Number.isInteger(t)||t<0||t>99?t.toLocaleString("en-US",{maximumFractionDigits:2}):t<20?W[t]:t%10===0?q[t/10]:`${q[Math.floor(t/10)]}-${W[t%10]}`}function Z(t){return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}function v(t){return/[^aeiou]y$/i.test(t)?`${t.slice(0,-1)}ies`:/(s|x|z|ch|sh)$/i.test(t)?`${t}es`:`${t}s`}var C=t=>String(t.name??t.title??t.label??t.id);function j(t,i,f,l=[],b){if(i==="plural"){let A=t instanceof g?t.nodes.length:Array.isArray(t)?t.length:typeof t=="number"?t:null;return A===null||l[0]===void 0?"\u2014":A===1?l[0]:l[1]??v(l[0])}if(t===null)return"\u2014";if(t instanceof g)return i==="count"?String(t.nodes.length):i==="and"?Z(t.nodes.map(C)):t.nodes.map(C).join(", ");if(Array.isArray(t)){if(i==="count")return String(t.length);let A=t.map(w=>j(w,void 0,f,[],b));return i==="and"?Z(A):A.join(", ")}if(typeof t=="object")return C(t);switch(i){case"words":return typeof t=="number"?X(t):String(t);case"money":return typeof t=="number"?Q(t,b):String(t);case"percent":return typeof t=="number"?`${Math.round(t*100)}%`:String(t);case"upper":return String(t).toUpperCase();case"lower":return String(t).toLowerCase();case"date":return T(String(t).slice(0,10));case"relative":{let A=Date.parse(String(t).length===10?`${t}T00:00:00Z`:String(t));if(Number.isNaN(A))return String(t);let w=Math.round((A-Date.parse(`${f}T00:00:00Z`))/864e5);return w===0?"today":w===1?"tomorrow":w===-1?"yesterday":w>0?`in ${w} days`:`${-w} days ago`}default:return typeof t=="string"&&L.test(t)?T(t):String(t)}}function gn(t,i){let f=i.today??new Date().toISOString().slice(0,10);return t.map(l=>{if(l.text!==void 0)return l.text;try{let b=P(l.expr,{graph:i.graph??J,subject:i.node,kinds:i.kinds,today:f,budget:i.budget??500,...i.bindings?{bindings:i.bindings}:{}});return j(b,l.format,f,l.formatArgs,i.money)}catch(b){if(b instanceof c)return"\u2014";throw b}}).join("")}export{g as a,B as b,c,_ as d,P as e,tn as f,rn as g,on as h,sn as i,an as j,cn as k,J as l,fn as m,Q as n,gn as o};
@@ -1 +1 @@
1
- import{a as B}from"./chunk.G4JJXA63.js";import{d as J,e as ee,f as te,g as ne}from"./chunk.K7UJG5II.js";import{j as Q,k as X}from"./chunk.XEJS2VS5.js";import{a as G}from"./chunk.4UQLZ7VW.js";import"./chunk.DN4D4HGX.js";import"./chunk.DJ26NOOW.js";import"./chunk.SQD7ZPEJ.js";import"./chunk.WGNF4E67.js";import"./chunk.R5K7NK4U.js";import{a as Z,d as q}from"./chunk.HCK6IHGP.js";import{a as Y}from"./chunk.VRXWNUDR.js";import"./chunk.DAKED3WK.js";import"./chunk.WWRWXFYR.js";import"./chunk.ZFUQA3KT.js";import"./chunk.DO4P2UK4.js";import"./chunk.6KJSFIO7.js";import"./chunk.FLJP3BGP.js";import"./chunk.ENMNLR73.js";import"./chunk.LZQZP2PD.js";import"./chunk.SCLIBKLS.js";import"./chunk.ACZGK7LQ.js";import"./chunk.AHDOKM4O.js";import"./chunk.LGUV2J6Q.js";import{Aa as V,W as _,ca as x,j as z,m as F,qa as U,r as W}from"./chunk.4JSMCNF7.js";import{I as P,N as O,O as A,S as j,T as N,aa as E}from"./chunk.Y235YZSZ.js";import{a as ge,b as K}from"./chunk.MRK6QJV5.js";import{b as I}from"./chunk.AJZBJBMO.js";var L=3;function se(e,t){return t.id?e.graph.getNode(t.id):void 0}function oe(e){return e?/^(?:kind|aggregate):([^:]+)$/.exec(e)?.[1]:void 0}function re(e,t){if(t)return e.find(n=>n.nodeIds.includes(t)||n.subjectId===t)}var fe=e=>{let t=e.trim();if(!t)return t;let n=t.charAt(0).toUpperCase()+t.slice(1);return/[.!?…]$/.test(n)?n:`${n}.`};function ae({store:e,subject:t,violations:n,place:i}){let o=se(e,t),s=re(n,o?.id??null);if(s)return fe(s.message);if(o){let d=o.kind;return`${P(e.schema.tryDefinition(d),o)}, ${j(N(e.schema.tryDefinition(d),d))}.`}let c=i?.kind??oe(t.id);if(c){let d=e.graph.nodesOfKind(c).length,p=i?.title??t.name,g=A(e.schema,c),f=O(e.schema,c,d);return p.toLowerCase()===g.toLowerCase()?`${d===1?"There is":"There are"} ${f} here.`:`${p}: ${f}.`}let r=e.schema.kinds.map(d=>({kind:d,count:e.graph.nodesOfKind(d).length})).filter(d=>d.count>0).sort((d,p)=>p.count-d.count).slice(0,3);if(r.length===0)return"Nothing here yet.";let a=r.map(d=>O(e.schema,d.kind,d.count));return`The whole thing: ${a.length===1?a[0]:`${a.slice(0,-1).join(", ")} and ${a[a.length-1]}`}.`}function le(e){let{store:t,subject:n,violations:i}=e,o=se(t,n),s=[];o&&re(i,o.id)?s.push({ask:`What's wrong with ${n.name}?`,why:"problem"}):i.length>0&&s.push({ask:"What needs attention?",why:"problem"});let c=o?o.kind:e.place?.kind??oe(n.id),r=me(e,c);if(r)s.push(r);else{let d=Se(e,c);d&&s.push(d)}let a=we(e,c);return a&&s.push(a),s.length<L&&(o?s.push({ask:`Tell me about ${n.name}`,why:"about"}):s.push({ask:"What is here?",why:"here"})),s.slice(0,L)}function de(e,t){return e.schema.tryDefinition(t)?.fields?.shape??{}}function ye(e){let t=e;for(let n=0;n<4&&t;n++){let i=t;if(Array.isArray(i.options)&&i.options.every(o=>typeof o=="string"))return i.options;t=typeof i.unwrap=="function"?i.unwrap():i._def?.innerType}}var ie=/^\d{4}-\d{2}-\d{2}/,he=["due","deadline","date","when"];function me(e,t){let{store:n}=e,i=e.today;if(!i||!ie.test(i))return;let o=new Date(`${i.slice(0,10)}T00:00:00Z`);o.setUTCDate(o.getUTCDate()+6);let s=o.toISOString().slice(0,10),c=[...new Set([...t?[t]:[],...n.schema.kinds])];for(let r of c){let a=he.find(g=>g in de(n,r));if(!a||!n.graph.nodesOfKind(r).some(g=>{let f=g[a],S=g.done;return typeof f=="string"&&ie.test(f)&&f.slice(0,10)>=i.slice(0,10)&&f.slice(0,10)<=s&&S!==!0}))continue;let p=A(n.schema,r);return{ask:`${B(p)} due this week`,why:"due"}}}function Se(e,t){let n=e.place?.title,i=(e.places??[]).find(o=>o.kind!==null&&o.picture===!0&&o.title!==n&&o.kind!==t);return i?{ask:`Go to ${i.title}`,why:"go"}:void 0}function we(e,t){let{store:n}=e,i=[...n.schema.kinds].sort((s,c)=>n.graph.nodesOfKind(c).length-n.graph.nodesOfKind(s).length),o=[...new Set([...t?[t]:[],...i])];for(let s of o){if(n.graph.nodesOfKind(s).length<2)continue;let c=de(n,s),r=Object.keys(c).find(p=>(ye(c[p])?.length??0)>=2);if(!r)continue;let a=A(n.schema,s).toLowerCase(),d=r.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").toLowerCase();return{ask:`Show ${a} as a board by ${d}`,why:"draw"}}}function ce(e,{store:t,subject:n}){let i=r=>n.id!==null&&(r.nodeIds.includes(n.id)||Object.values(r.args).includes(n.id)),o=e.filter(r=>r.provider==="invariant"&&i(r)),s=e.filter(r=>r.pinned==="user"&&!o.includes(r));return[...o,...s].sort((r,a)=>Number(r.destructive??!1)-Number(a.destructive??!1)).slice(0,L).map(r=>({affordance:r,label:ke(r,{store:t,subject:n})}))}var be=e=>/^[a-z0-9]+(?:[-_][a-z0-9]+)+$|^[a-z]+[A-Z][A-Za-z0-9]*$/.test(e);function ke(e,{store:t,subject:n}){let i=e.label,o=be(i)||i===e.mutation;if(o){let a=i.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").toLowerCase();i=a.charAt(0).toUpperCase()+a.slice(1)}let s=n.id?t.graph.getNode(n.id):void 0,c=s!==void 0&&e.nodeIds.length<=1&&(e.nodeIds[0]??s.id)===s.id;if(c&&/\bit\b/.test(i))return i.replace(/\bit\b/,n.name);let r=t.allMutations().find(a=>a.name===e.mutation);if(e.open.length===0&&r?.describe&&(o||c))try{let a=r.describe(e.args,t.graph);if(a.trim())return a.trim()}catch{}return i}var h=I(ge(),1);var u=I(K(),1);function Ne({phone:e,side:t,name:n,onClose:i,respond:o,onCall:s,onPick:c,onMove:r,place:a,onDraft:d}){let{seatTalk:p}=x(),g=_(p),f=ve(c),S=[...g.turns].reverse().find(y=>y.role==="seat"),m=e&&g.draft!==null,b=(0,h.useRef)(null);return(0,h.useLayoutEffect)(()=>{let y=b.current;if(!y)return;let w=m?[...y.querySelectorAll("ol > li")].pop():void 0;if(w){let C=w.getBoundingClientRect().top-y.getBoundingClientRect().top+y.scrollTop;y.style.maxHeight=`min(${Math.ceil(y.scrollHeight-C)}px, ${ue})`}y.scrollTop=y.scrollHeight},[g.turns.length,g.busy,m]),(0,u.jsxs)("div",{"data-testid":"seat-panel",...m?{"data-graview-seat-yields":""}:{},style:{display:"grid",gridTemplateRows:"auto minmax(0, 1fr)",gap:4,minHeight:0},children:[(0,u.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:e?"center":"flex-end",gap:2,position:"relative",minHeight:28},children:[e?(0,u.jsx)("button",{type:"button","data-testid":"seat-grab","aria-label":`Close Ask ${n}`,title:"Close",onClick:i,style:{...M,width:64},children:(0,u.jsx)("span",{"aria-hidden":"true",style:{display:"block",width:36,height:4,margin:"0 auto",borderRadius:2,background:"var(--graview-edge-strong, var(--graview-ink-faint))"}})}):(0,u.jsx)("button",{type:"button","data-testid":"seat-side","aria-label":t==="left"?"Move to the right":"Move to the left",title:t==="left"?"Move to the right":"Move to the left",onClick:()=>p.setSide(t==="left"?"right":"left"),style:M,children:(0,u.jsx)("span",{"aria-hidden":"true",children:"\u21C4"})}),e?null:(0,u.jsx)("button",{type:"button","data-testid":"seat-close","aria-label":`Close Ask ${n}`,title:"Close",onClick:i,style:M,children:(0,u.jsx)("span",{"aria-hidden":"true",children:"\u2715"})})]}),(0,u.jsx)("div",{ref:b,"data-testid":"seat-body",style:{minHeight:0,maxHeight:m?ue:e?"calc(70cqh - 96px)":"min(520px, calc(100cqh - 112px))",overflowY:"auto",overflowX:"hidden",padding:"0 4px"},children:(0,u.jsx)(ee,{shared:!0,composer:!1,testId:"seat",onPick:f,...r?{onMove:r}:{},...a?{place:a}:{},...d?{onDraft:d}:{},empty:(0,u.jsx)(Ae,{...a?{here:a}:{}}),...o?{respond:o}:{},...s?{onCall:s}:{}})}),(0,u.jsx)("p",{"aria-live":"polite","data-testid":"seat-said",style:V,children:g.busy?"":S?.text??""})]})}function ve(e){let{setView:t}=x();return(0,h.useCallback)(n=>e?e(n):t(i=>W(z(F(i,!1),n),[n])),[e,t])}function Ae({here:e}){let{store:t,views:n,view:i,seatTalk:o}=x(),s=J({hover:!1}),c=Z(t,U()),r=(0,h.useMemo)(()=>c.map(l=>l.line?{...l,message:q(l)}:l),[c]),a=s.id?t.graph.getNode(s.id):void 0,d=e??i.within?.view,p=s.because==="place"&&s.id===null?n.places().find(l=>l.title===s.name):d?n.places().find(l=>l.as===d):void 0,g=t.today(),f={store:t,subject:{id:s.id,name:s.name},violations:r,place:p?{title:p.title,kind:p.kind}:null,places:n.places().map(l=>({title:l.title,kind:l.kind,picture:!0})),...g?{today:g}:{}},S=ae(f),m=le(f),b=(0,h.useMemo)(()=>({pins:G(),...a?{focus:a.id,about:[a.id]}:{}}),[a?.id]),{affordances:y}=Q(b),w=a?ce(y,{store:t,subject:{id:s.id,name:s.name}}):[],{apply:C,preview:pe}=X(),[k,$]=(0,h.useState)(null),[D,H]=(0,h.useState)(null),R=(l,v)=>{try{return pe(l,v),C(l,v),H(null),!0}catch(T){return H(E(t.schema,t.allMutations(),T)),!1}};return(0,u.jsxs)("div",{"data-testid":"seat-here",style:{display:"grid",gap:10,padding:"2px 2px 6px"},children:[(0,u.jsx)("p",{"data-testid":"seat-where",style:{margin:0,fontSize:"0.9375rem",lineHeight:1.45,color:"var(--graview-ink)"},children:S}),w.length>0?(0,u.jsx)("ul",{"aria-label":"What you can do",style:{margin:0,padding:0,listStyle:"none",display:"flex",flexWrap:"wrap",gap:6},children:w.map(({affordance:l,label:v})=>(0,u.jsx)("li",{children:(0,u.jsx)("button",{type:"button","data-testid":"seat-act","data-affordance":l.id,"aria-pressed":k?.id===l.id,title:l.why,onClick:()=>l.open.length>0?$(T=>T?.id===l.id?null:l):void R(l),style:{...te,minHeight:30,textAlign:"start",...l.destructive?{color:"var(--graview-warn)"}:{}},children:v})},l.id))}):null,k?(0,u.jsx)(Y,{affordance:k,onApply:l=>{R(k,l)&&$(null)},onCancel:()=>$(null)}):null,D?(0,u.jsx)("p",{"data-testid":"seat-refused",style:{margin:0,fontSize:"0.8125rem",color:"var(--graview-warn)"},children:D}):null,m.length>0?(0,u.jsx)("ul",{"aria-label":"Things to ask",style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:2,justifyItems:"start"},children:m.map(l=>(0,u.jsx)("li",{children:(0,u.jsx)("button",{type:"button","data-testid":"seat-suggestion","data-graview-why":l.why,onClick:()=>o.ask(l.ask),style:ne,children:l.ask})},l.ask))}):null]})}var ue="min(5.5em, 22cqh)",M={display:"inline-grid",placeItems:"center",width:28,height:28,padding:0,font:"inherit",fontSize:"0.875rem",lineHeight:1,color:"var(--graview-ink-muted)",background:"transparent",border:"1px solid transparent",borderRadius:6,boxShadow:"none",cursor:"pointer"};export{Ne as SeatPanel,ve as useSeatGo};
1
+ import{a as B}from"./chunk.G4JJXA63.js";import{d as J,e as ee,f as te,g as ne}from"./chunk.XDPRWUCJ.js";import{j as Q,k as X}from"./chunk.HH6WIUK3.js";import{a as G}from"./chunk.GDIRDJF3.js";import"./chunk.Y4R77MKX.js";import"./chunk.FRNIWOKD.js";import"./chunk.42U4UBDE.js";import"./chunk.D3CYTXNZ.js";import"./chunk.MYCTNK6D.js";import{a as Z,d as q}from"./chunk.53RZI5PM.js";import{a as Y}from"./chunk.NRWJ6PLU.js";import"./chunk.6O67NOZR.js";import"./chunk.WWRWXFYR.js";import"./chunk.ISAMJ7AK.js";import"./chunk.54NSG7BX.js";import"./chunk.6KJSFIO7.js";import"./chunk.UM5IPM22.js";import"./chunk.6XBLDV4A.js";import"./chunk.WOTNMTIY.js";import"./chunk.HAQ4KHRY.js";import"./chunk.PRXKRG6O.js";import"./chunk.AHDOKM4O.js";import"./chunk.LW7KV5SL.js";import{Aa as V,W as _,ca as x,j as z,m as F,qa as U,r as W}from"./chunk.2VX6H2LL.js";import{I as P,N as O,O as A,S as j,T as N,ca as E}from"./chunk.ZQ4HFIIS.js";import{a as ge,b as K}from"./chunk.MRK6QJV5.js";import{b as I}from"./chunk.AJZBJBMO.js";var L=3;function se(e,t){return t.id?e.graph.getNode(t.id):void 0}function oe(e){return e?/^(?:kind|aggregate):([^:]+)$/.exec(e)?.[1]:void 0}function re(e,t){if(t)return e.find(n=>n.nodeIds.includes(t)||n.subjectId===t)}var fe=e=>{let t=e.trim();if(!t)return t;let n=t.charAt(0).toUpperCase()+t.slice(1);return/[.!?…]$/.test(n)?n:`${n}.`};function ae({store:e,subject:t,violations:n,place:i}){let o=se(e,t),s=re(n,o?.id??null);if(s)return fe(s.message);if(o){let d=o.kind;return`${P(e.schema.tryDefinition(d),o)}, ${j(N(e.schema.tryDefinition(d),d))}.`}let c=i?.kind??oe(t.id);if(c){let d=e.graph.nodesOfKind(c).length,p=i?.title??t.name,g=A(e.schema,c),f=O(e.schema,c,d);return p.toLowerCase()===g.toLowerCase()?`${d===1?"There is":"There are"} ${f} here.`:`${p}: ${f}.`}let r=e.schema.kinds.map(d=>({kind:d,count:e.graph.nodesOfKind(d).length})).filter(d=>d.count>0).sort((d,p)=>p.count-d.count).slice(0,3);if(r.length===0)return"Nothing here yet.";let a=r.map(d=>O(e.schema,d.kind,d.count));return`The whole thing: ${a.length===1?a[0]:`${a.slice(0,-1).join(", ")} and ${a[a.length-1]}`}.`}function le(e){let{store:t,subject:n,violations:i}=e,o=se(t,n),s=[];o&&re(i,o.id)?s.push({ask:`What's wrong with ${n.name}?`,why:"problem"}):i.length>0&&s.push({ask:"What needs attention?",why:"problem"});let c=o?o.kind:e.place?.kind??oe(n.id),r=me(e,c);if(r)s.push(r);else{let d=Se(e,c);d&&s.push(d)}let a=we(e,c);return a&&s.push(a),s.length<L&&(o?s.push({ask:`Tell me about ${n.name}`,why:"about"}):s.push({ask:"What is here?",why:"here"})),s.slice(0,L)}function de(e,t){return e.schema.tryDefinition(t)?.fields?.shape??{}}function ye(e){let t=e;for(let n=0;n<4&&t;n++){let i=t;if(Array.isArray(i.options)&&i.options.every(o=>typeof o=="string"))return i.options;t=typeof i.unwrap=="function"?i.unwrap():i._def?.innerType}}var ie=/^\d{4}-\d{2}-\d{2}/,he=["due","deadline","date","when"];function me(e,t){let{store:n}=e,i=e.today;if(!i||!ie.test(i))return;let o=new Date(`${i.slice(0,10)}T00:00:00Z`);o.setUTCDate(o.getUTCDate()+6);let s=o.toISOString().slice(0,10),c=[...new Set([...t?[t]:[],...n.schema.kinds])];for(let r of c){let a=he.find(g=>g in de(n,r));if(!a||!n.graph.nodesOfKind(r).some(g=>{let f=g[a],S=g.done;return typeof f=="string"&&ie.test(f)&&f.slice(0,10)>=i.slice(0,10)&&f.slice(0,10)<=s&&S!==!0}))continue;let p=A(n.schema,r);return{ask:`${B(p)} due this week`,why:"due"}}}function Se(e,t){let n=e.place?.title,i=(e.places??[]).find(o=>o.kind!==null&&o.picture===!0&&o.title!==n&&o.kind!==t);return i?{ask:`Go to ${i.title}`,why:"go"}:void 0}function we(e,t){let{store:n}=e,i=[...n.schema.kinds].sort((s,c)=>n.graph.nodesOfKind(c).length-n.graph.nodesOfKind(s).length),o=[...new Set([...t?[t]:[],...i])];for(let s of o){if(n.graph.nodesOfKind(s).length<2)continue;let c=de(n,s),r=Object.keys(c).find(p=>(ye(c[p])?.length??0)>=2);if(!r)continue;let a=A(n.schema,s).toLowerCase(),d=r.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").toLowerCase();return{ask:`Show ${a} as a board by ${d}`,why:"draw"}}}function ce(e,{store:t,subject:n}){let i=r=>n.id!==null&&(r.nodeIds.includes(n.id)||Object.values(r.args).includes(n.id)),o=e.filter(r=>r.provider==="invariant"&&i(r)),s=e.filter(r=>r.pinned==="user"&&!o.includes(r));return[...o,...s].sort((r,a)=>Number(r.destructive??!1)-Number(a.destructive??!1)).slice(0,L).map(r=>({affordance:r,label:ke(r,{store:t,subject:n})}))}var be=e=>/^[a-z0-9]+(?:[-_][a-z0-9]+)+$|^[a-z]+[A-Z][A-Za-z0-9]*$/.test(e);function ke(e,{store:t,subject:n}){let i=e.label,o=be(i)||i===e.mutation;if(o){let a=i.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").toLowerCase();i=a.charAt(0).toUpperCase()+a.slice(1)}let s=n.id?t.graph.getNode(n.id):void 0,c=s!==void 0&&e.nodeIds.length<=1&&(e.nodeIds[0]??s.id)===s.id;if(c&&/\bit\b/.test(i))return i.replace(/\bit\b/,n.name);let r=t.allMutations().find(a=>a.name===e.mutation);if(e.open.length===0&&r?.describe&&(o||c))try{let a=r.describe(e.args,t.graph);if(a.trim())return a.trim()}catch{}return i}var h=I(ge(),1);var u=I(K(),1);function Ne({phone:e,side:t,name:n,onClose:i,respond:o,onCall:s,onPick:c,onMove:r,place:a,onDraft:d}){let{seatTalk:p}=x(),g=_(p),f=ve(c),S=[...g.turns].reverse().find(y=>y.role==="seat"),m=e&&g.draft!==null,b=(0,h.useRef)(null);return(0,h.useLayoutEffect)(()=>{let y=b.current;if(!y)return;let w=m?[...y.querySelectorAll("ol > li")].pop():void 0;if(w){let C=w.getBoundingClientRect().top-y.getBoundingClientRect().top+y.scrollTop;y.style.maxHeight=`min(${Math.ceil(y.scrollHeight-C)}px, ${ue})`}y.scrollTop=y.scrollHeight},[g.turns.length,g.busy,m]),(0,u.jsxs)("div",{"data-testid":"seat-panel",...m?{"data-graview-seat-yields":""}:{},style:{display:"grid",gridTemplateRows:"auto minmax(0, 1fr)",gap:4,minHeight:0},children:[(0,u.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:e?"center":"flex-end",gap:2,position:"relative",minHeight:28},children:[e?(0,u.jsx)("button",{type:"button","data-testid":"seat-grab","aria-label":`Close Ask ${n}`,title:"Close",onClick:i,style:{...M,width:64},children:(0,u.jsx)("span",{"aria-hidden":"true",style:{display:"block",width:36,height:4,margin:"0 auto",borderRadius:2,background:"var(--graview-edge-strong, var(--graview-ink-faint))"}})}):(0,u.jsx)("button",{type:"button","data-testid":"seat-side","aria-label":t==="left"?"Move to the right":"Move to the left",title:t==="left"?"Move to the right":"Move to the left",onClick:()=>p.setSide(t==="left"?"right":"left"),style:M,children:(0,u.jsx)("span",{"aria-hidden":"true",children:"\u21C4"})}),e?null:(0,u.jsx)("button",{type:"button","data-testid":"seat-close","aria-label":`Close Ask ${n}`,title:"Close",onClick:i,style:M,children:(0,u.jsx)("span",{"aria-hidden":"true",children:"\u2715"})})]}),(0,u.jsx)("div",{ref:b,"data-testid":"seat-body",style:{minHeight:0,maxHeight:m?ue:e?"calc(70cqh - 96px)":"min(520px, calc(100cqh - 112px))",overflowY:"auto",overflowX:"hidden",padding:"0 4px"},children:(0,u.jsx)(ee,{shared:!0,composer:!1,testId:"seat",onPick:f,...r?{onMove:r}:{},...a?{place:a}:{},...d?{onDraft:d}:{},empty:(0,u.jsx)(Ae,{...a?{here:a}:{}}),...o?{respond:o}:{},...s?{onCall:s}:{}})}),(0,u.jsx)("p",{"aria-live":"polite","data-testid":"seat-said",style:V,children:g.busy?"":S?.text??""})]})}function ve(e){let{setView:t}=x();return(0,h.useCallback)(n=>e?e(n):t(i=>W(z(F(i,!1),n),[n])),[e,t])}function Ae({here:e}){let{store:t,views:n,view:i,seatTalk:o}=x(),s=J({hover:!1}),c=Z(t,U()),r=(0,h.useMemo)(()=>c.map(l=>l.line?{...l,message:q(l)}:l),[c]),a=s.id?t.graph.getNode(s.id):void 0,d=e??i.within?.view,p=s.because==="place"&&s.id===null?n.places().find(l=>l.title===s.name):d?n.places().find(l=>l.as===d):void 0,g=t.today(),f={store:t,subject:{id:s.id,name:s.name},violations:r,place:p?{title:p.title,kind:p.kind}:null,places:n.places().map(l=>({title:l.title,kind:l.kind,picture:!0})),...g?{today:g}:{}},S=ae(f),m=le(f),b=(0,h.useMemo)(()=>({pins:G(),...a?{focus:a.id,about:[a.id]}:{}}),[a?.id]),{affordances:y}=Q(b),w=a?ce(y,{store:t,subject:{id:s.id,name:s.name}}):[],{apply:C,preview:pe}=X(),[k,$]=(0,h.useState)(null),[D,H]=(0,h.useState)(null),R=(l,v)=>{try{return pe(l,v),C(l,v),H(null),!0}catch(T){return H(E(t.schema,t.allMutations(),T)),!1}};return(0,u.jsxs)("div",{"data-testid":"seat-here",style:{display:"grid",gap:10,padding:"2px 2px 6px"},children:[(0,u.jsx)("p",{"data-testid":"seat-where",style:{margin:0,fontSize:"0.9375rem",lineHeight:1.45,color:"var(--graview-ink)"},children:S}),w.length>0?(0,u.jsx)("ul",{"aria-label":"What you can do",style:{margin:0,padding:0,listStyle:"none",display:"flex",flexWrap:"wrap",gap:6},children:w.map(({affordance:l,label:v})=>(0,u.jsx)("li",{children:(0,u.jsx)("button",{type:"button","data-testid":"seat-act","data-affordance":l.id,"aria-pressed":k?.id===l.id,title:l.why,onClick:()=>l.open.length>0?$(T=>T?.id===l.id?null:l):void R(l),style:{...te,minHeight:30,textAlign:"start",...l.destructive?{color:"var(--graview-warn)"}:{}},children:v})},l.id))}):null,k?(0,u.jsx)(Y,{affordance:k,onApply:l=>{R(k,l)&&$(null)},onCancel:()=>$(null)}):null,D?(0,u.jsx)("p",{"data-testid":"seat-refused",style:{margin:0,fontSize:"0.8125rem",color:"var(--graview-warn)"},children:D}):null,m.length>0?(0,u.jsx)("ul",{"aria-label":"Things to ask",style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:2,justifyItems:"start"},children:m.map(l=>(0,u.jsx)("li",{children:(0,u.jsx)("button",{type:"button","data-testid":"seat-suggestion","data-graview-why":l.why,onClick:()=>o.ask(l.ask),style:ne,children:l.ask})},l.ask))}):null]})}var ue="min(5.5em, 22cqh)",M={display:"inline-grid",placeItems:"center",width:28,height:28,padding:0,font:"inherit",fontSize:"0.875rem",lineHeight:1,color:"var(--graview-ink-muted)",background:"transparent",border:"1px solid transparent",borderRadius:6,boxShadow:"none",cursor:"pointer"};export{Ne as SeatPanel,ve as useSeatGo};
@@ -0,0 +1 @@
1
+ import{a as je}from"./chunk.HH6WIUK3.js";import{a as Ve,c as Fe,d as Ie}from"./chunk.GDIRDJF3.js";import{d as Be}from"./chunk.FRNIWOKD.js";import{b as Ge,e as G,f as ve}from"./chunk.42U4UBDE.js";import{b as ze}from"./chunk.D3CYTXNZ.js";import{d as ge,e as qe,f as ye,h as _e}from"./chunk.MYCTNK6D.js";import{a as De}from"./chunk.NRWJ6PLU.js";import{b as We}from"./chunk.6O67NOZR.js";import{C as Ee,E as Ne,G as He,T as Ke,U as Oe,W as oe,ca as q,d as Le,j as I,l as W,m as _,pa as re,r as j,s as Re,y as Pe,z as Me}from"./chunk.2VX6H2LL.js";import{I as $e,Na as ne,O as Te,Oa as me,P as te,Qa as Ae,Ra as Ce}from"./chunk.ZQ4HFIIS.js";import{a as U,b as ae}from"./chunk.MRK6QJV5.js";import{b as O}from"./chunk.AJZBJBMO.js";var Je=O(U(),1);function Qe(e,t){try{t.length===0?localStorage.removeItem(ge(e)):localStorage.setItem(ge(e),JSON.stringify(t))}catch{}}function ct(e,t){Qe(e,[...ye(e).filter(r=>r.title!==t.title),t])}function pt(e,t){Qe(e,ye(e).filter(r=>r.title!==t))}function ut(e,t){for(let r of e.places().filter(a=>a.title===t))e.forget?.(r.kind,r.as)}var ft=e=>e===!0?{written:!0}:typeof e=="object"&&e!==null?{written:e.kept===!0,...e.said?{said:e.said}:{}}:{written:!1},Ue=e=>({title:e.title,lens:e.lens,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}});function mt(e,t){let r=a=>t.some(s=>s.title===a||s.as===ne(a));if(!r(e))return e;for(let a=2;;a++)if(!r(`${e} ${a}`))return`${e} ${a}`}function Ye(e){let{store:t,views:r,brand:a,seatTalk:s,onKeepLens:y}=q(),k=(0,Je.useContext)(ze),S=qe(a,t.schema),M=async c=>{let{edit:p}=c;if(c.written&&y)try{await y({op:"remove-lens",title:p.title,on:p.on})}catch{}pt(S,p.title),ut(r,p.title),k?.dismiss(`kept:${p.title}`),s.setTurns(g=>[...g.map(i=>i.kept&&i.kept.edit.title===p.title&&!i.kept.taken?{...i,kept:{...i.kept,taken:!0}}:i),{role:"seat",text:`Took \u201C${p.title}\u201D back out of the places.`}]);let l=te(t.schema,p.on);e({to:"kind",kind:p.on,title:l,address:me(t.schema,p.on),said:`Went to ${l}.`})};return{keep:async c=>{let p=mt(c.edit.title,r.places()),l={...c.edit,title:p},g=!1,i;if(y)try{({written:g,said:i}=ft(await y(l)))}catch{g=!1}g||ct(S,Ue(l)),_e(r,t.schema,[Ue(l)]);let f=r.places(),h=f.find(w=>w.title===p),x=i??(g?`Kept \u201C${p}\u201D as a lens: it is in the places now.`:y?`Kept \u201C${p}\u201D as your own lens. Ask the owner to keep it for everyone.`:`Kept \u201C${p}\u201D as your own lens.`),T={edit:l,written:g};s.setDraft(null),s.setTurns(w=>[...w,{role:"seat",text:x,kept:T}]),s.get().open||k?.notify({kind:"toast",id:`kept:${p}`,sentence:x,timeout:1e4,action:{label:"Take back",onSelect:()=>void M(T)}}),h&&e({to:"picture",kind:h.kind,as:h.as,title:p,address:Ae(h.as,Ce(h,f)?me(t.schema,h.kind).slice(1):void 0),said:`Went to ${p}.`})},takeBack:M}}var Ze=O(U(),1);function gt(e,t){switch(t.to){case"place":return{view:Le("#")};case"picture":return{view:j(He(W(e,"filter",null),t.kind,t.as),[])};case"kind":{let r=Re(_({...I(e,Ee(t.kind)),relation:null},!1),!0);return{view:j(W(W(r,"view",null),"filter",t.filter??null),[])}}case"record":return{view:j(I(_(W(W(e,"view",null),"filter",null),!1),t.id),[t.id])};case"problems":return{pane:"problems"}}}function yt(e){let t=typeof document>"u"?null:document.querySelector('[data-testid="standing"]');t&&t.getAttribute("aria-expanded")==="true"!==e&&t.click()}function Xe(){let{setView:e,seatTalk:t}=q();return(0,Ze.useCallback)(r=>{t.get().draft&&t.setDraft(null),yt(r.to==="problems"),r.to!=="problems"&&e(a=>{let s=gt(a,r);return"view"in s?s.view:a})},[e,t])}var se=O(U(),1),vt=220;function ht(e,t){if(!e||!t||typeof document>"u")return null;let r=e.getBoundingClientRect(),a=document.elementFromPoint(r.left+t.x,r.top+t.y),s=a?.closest("[data-graview-pick]")?.getAttribute("data-graview-pick");return s||(a?.closest("[data-graview-view]")?.getAttribute("data-graview-view")??null)}function et({hover:e=!0}={}){let{store:t,view:r,views:a,pointer:s}=q(),{selection:y}=re(),[k,S]=(0,se.useState)(null);(0,se.useEffect)(()=>{if(!e)return;let l=null,g=!1,i=()=>typeof document<"u"&&document.querySelector("[data-graview-reach]")!==null?document.querySelector("[data-graview-settled]")===null:!1,f=()=>{if(l&&clearTimeout(l),g)return;let w=s.snapshot();if(!w){S(R=>R===null?R:null);return}l=setTimeout(()=>{if(g||i()){f();return}let R=typeof document>"u"?null:document.querySelector("[data-graview-stage]"),C=ht(R,w);S(P=>P===C?P:C)},vt)},h=()=>{g=!0,l&&clearTimeout(l)},x=()=>{g=!1,f()},T=s.subscribe(f);return document.addEventListener("pointerdown",h,!0),document.addEventListener("pointerup",x,!0),document.addEventListener("pointercancel",x,!0),f(),()=>{T(),document.removeEventListener("pointerdown",h,!0),document.removeEventListener("pointerup",x,!0),document.removeEventListener("pointercancel",x,!0),l&&clearTimeout(l)}},[s,e]);let M=l=>{let g=t.graph.getNode(l);if(g)return $e(t.schema.tryDefinition(g.kind),g);let i=je(l,t.schema);if(i)return i;let f=Me(l);if(f)return te(t.schema,f);let h=Ne(l);if(h.length>0){let x=h.map(w=>Te(t.schema,w)),T=x.length===1?x[0]:`${x.slice(0,-1).join(", ")} and ${x.at(-1)}`;return T.charAt(0).toUpperCase()+T.slice(1)}return null},E=y[y.length-1];if(E!==void 0){let l=M(E);if(l)return{id:E,name:y.length>1?`${l} and ${y.length-1} more`:l,because:"selection"}}if(k!=null){let l=M(k);if(l)return{id:k,name:l,because:"hover"}}let c=r.within?.view,p=c?a.places().find(l=>l.as===c||ne(l.title)===c):void 0;if(p)return{id:null,name:p.title,because:"place"};if(r.focusId){let l=M(r.focusId);if(l)return{id:r.focusId,name:l,because:"place"}}return{id:null,name:"the whole thing",because:"place"}}var L=O(U(),1);var D=O(U(),1),$=O(ae(),1),B=(e,t)=>`${e}:${t}`;function tt({answer:e,onReply:t,talk:r}){let[a]=(0,D.useState)(()=>Oe(null)),s=r??a,{turns:y,outcomes:k,busy:S}=oe(s),M=(0,D.useCallback)((c,p)=>s.settle(c,p),[s]);return{turns:y,outcomes:k,busy:S,send:async c=>{let p=c.trim();if(!p||s.get().busy)return;s.setBusy(!0);let l=s.get();s.setTurns(f=>[...f,{role:"person",text:p}]);let g=l.turns.map((f,h)=>{let x=(f.proposals??[]).flatMap((T,w)=>{let R=l.outcomes.get(B(h,w));return R?.state==="applied"?[R.said]:[]});return{role:f.role,text:x.length>0?`${f.text} [applied: ${x.join("; ")}]`:f.text}}),i;try{i=await e(p,{history:g})}catch(f){i={say:`That couldn't be answered: ${f instanceof Error?f.message:String(f)}`,proposals:[]}}s.setTurns(f=>[...f,{role:"seat",text:i.say,proposals:i.proposals,...i.questions?{questions:i.questions}:{},...i.picks?.length?{picks:i.picks}:{},...i.moves?.length?{moves:i.moves}:{},...i.offer?{offer:i.offer}:{},...i.unsure?{unsure:!0}:{},...i.via?{via:i.via}:{}}]),t?.(i),s.setBusy(!1)},settle:M}}var wt=e=>{let t=/^([\s\S]*?)\s*(\((?:[^()]|\([^()]*\))*\))\s*$/.exec(e);return t&&t[1]?{said:t[1],aside:t[2]}:{said:e}};function nt({turns:e,outcomes:t,busy:r,testId:a,empty:s,minHeight:y=64,maxHeight:k="min(46cqh, 400px)",renderProposal:S,renderAfter:M,renderSaid:E,ready:c=()=>!0,onApplyAll:p,applyAllLabel:l="Apply all"}){let g=(0,D.useRef)(null);return(0,D.useEffect)(()=>{g.current?.scrollTo?.({top:g.current.scrollHeight})},[e]),e.length===0&&s===null&&!r?null:(0,$.jsxs)("ol",{ref:g,style:{margin:0,padding:10,listStyle:"none",display:"grid",gap:8,alignContent:"start",maxHeight:k,minHeight:y,overflowY:"auto"},children:[e.length===0?s===null?null:(0,$.jsx)("li",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)",lineHeight:1.5},children:s}):null,e.map((i,f)=>{let h=i.proposals??[],x=h.filter((w,R)=>{let C=B(f,R),P=t.get(C);return P?.state!=="applied"&&P?.state!=="declined"&&c(w,C)}),T=wt(i.text);return(0,$.jsxs)("li",{style:{display:"grid",gap:6,justifyItems:i.role==="person"?"end":"start"},children:[i.role==="person"?(0,$.jsx)("p",{style:{margin:0,maxWidth:"85%",padding:"6px 10px",borderRadius:"12px 12px 4px 12px",fontSize:"0.875rem",lineHeight:1.45,background:"var(--graview-panel-muted)",color:"var(--graview-ink)"},children:i.text}):(0,$.jsxs)("p",{style:{margin:0,fontSize:"0.875rem",lineHeight:1.5,color:"var(--graview-ink)"},children:[E?E(i,T.said):T.said,T.aside?(0,$.jsx)("span",{style:{display:"block",marginTop:2,fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:T.aside}):null,i.via?(0,$.jsx)("span",{"data-testid":`${a}-answered-with-ai`,style:{display:"block",marginTop:2,fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:Ke}):null]}),M?.(i,f),h.map((w,R)=>{let C=B(f,R),P=t.get(C);return P?.state==="applied"||P?.state==="declined"?(0,$.jsx)(ie,{outcome:P,testId:a},C):(0,$.jsxs)("span",{style:{display:"grid",gap:4,justifySelf:"stretch",justifyItems:"start"},children:[S(w,{key:C,turn:f,at:R}),P?(0,$.jsx)(ie,{outcome:P,testId:a}):null]},C)}),p&&x.length>=2?(0,$.jsxs)("button",{type:"button","data-testid":`${a}-apply-all`,onClick:()=>p(f,h),title:"Take these in order; anything still missing is asked for",style:{fontSize:"0.8125rem",justifySelf:"start",fontWeight:600},children:[l," ",x.length]}):null]},f)}),r?(0,$.jsx)("li",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-faint)"},children:"thinking\u2026"}):null]})}function ie({outcome:e,testId:t}){if(e.state==="refused")return(0,$.jsxs)("span",{"data-testid":`${t}-refused`,style:{fontSize:"0.8125rem",color:"var(--graview-warn)"},children:["Refused: ",e.error]});let r=e.state==="applied";return(0,$.jsxs)("span",{"data-testid":`${t}-${e.state}`,style:{fontSize:"0.8125rem",color:r?"var(--graview-ink-muted)":"var(--graview-ink-faint)"},children:[r?(0,$.jsx)("span",{"aria-hidden":"true",style:{color:"var(--graview-accent)"},children:"\u2713 "}):null,r?e.said:(0,$.jsx)("s",{children:e.said})]})}function ot({busy:e,placeholder:t,ariaLabel:r,testId:a,onSend:s}){let[y,k]=(0,D.useState)("");return(0,$.jsxs)("form",{onSubmit:S=>{S.preventDefault(),!(e||y.trim().length===0)&&(s(y),k(""))},style:{display:"flex",gap:6,padding:8,borderTop:"1px solid var(--graview-edge)"},children:[(0,$.jsx)("input",{value:y,onChange:S=>k(S.target.value),placeholder:t,"aria-label":r,"data-testid":`${a}-draft`,style:{flex:1,minWidth:0,font:"inherit",fontSize:"0.875rem",padding:"6px 9px",borderRadius:8,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)"}}),(0,$.jsx)("button",{type:"submit","data-testid":`${a}-send`,disabled:e||y.trim().length===0,style:{fontSize:"0.875rem"},children:"Send"})]})}var v=O(ae(),1),bt=/\b(?:board|kanban|timeline|calendar|gantt|who covers|covers what|coverage|floor plan|layout|draw|chart|(?:list|table) of|as an? (?:list|table|board|calendar|timeline|grid))\b/i,kt=/\b(?:group(?:ed)? by|split by|sort(?:ed)? by|order(?:ed)? by|only|call it|name it|as an? (?:board|kanban|calendar|timeline|list|table|cards|rows|grid|plan|layout)|show all|all of them|clear the filter|no filter)\b/i,St=e=>e.charAt(0).toLowerCase()+e.slice(1),xt=e=>e.to==="record"?e.label:e.to==="problems"?"problems":e.title;function $t(e,t,r){let a=[],s=e;for(let y of t){let k=xt(y),S=k?s.toLowerCase().indexOf(k.toLowerCase()):-1;S<0||(a.push(s.slice(0,S),r(y,s.slice(S,S+k.length))),s=s.slice(S+k.length))}return a.length===0?e:[...a,s]}function Qt({respond:e,onCall:t,onPick:r,testId:a="chat",empty:s,shared:y=!1,composer:k=!0,onMove:S,place:M,onDraft:E}){let{store:c,views:p,view:l,principal:g,setView:i,seatWho:f,noteSeat:h,session:x,ai:T,seatTalk:w,brand:R,app:C}=q(),P=Xe(),le=S??P,{takeBack:rt}=Ye(le),{selection:de}=re(),he=et(),we=f??"chat",z=(0,L.useMemo)(()=>({kind:"agent",id:we,session:x}),[we,x]),ce=(0,L.useRef)(void 0),V=(0,L.useMemo)(()=>Be(c,{author:{...z,...g.roles?{roles:g.roles}:{}},derive:()=>({pins:Ve()}),places:()=>p.places(),via:()=>ce.current,...C?{app:C}:{}}),[c,g,z,p,C]),st=(0,L.useMemo)(()=>e??Ie(T),[e,T]);(0,L.useEffect)(()=>t?V.onCall(t):void 0,[V,t]),We(V);let be=(0,L.useMemo)(()=>({name:R?.name??"app",schema:c.schema,...c.policy?{policy:c.policy}:{}}),[c,R]),it=async o=>{let d=w.get().draft,n=d!==null&&kt.test(o);if(!n&&!bt.test(o))return;let u=await import("./chunk.OXODTBOP.js"),b=e?void 0:Fe(T),m={app:be,sight:u.draftSight(be,Y),...b?{complete:b}:{},...d?{lastGood:d}:{}},A=n&&d?await u.refineDraft(d,o,m):await u.draftView(o,m);if(u.isDraftFailure(A)){let K=A.lastGood??d;return K?(w.setDraft(K,A.failed),E?.(),{say:`${A.failed} The last view stays.`,proposals:[],grounded:!0}):{say:A.failed,proposals:[],grounded:!0}}return w.setDraft(A,null),E?.(),{say:`Here is ${St(A.said)} Ask to change it, or keep it as a lens.`,proposals:[],grounded:!0}},N=tt({...y?{talk:w}:{},answer:async(o,d)=>{let n=await it(o);if(n)return n;let{placesFromViews:u}=await import("./chunk.BNSY25SG.js"),b=M??l.within?.view,m=p.arrangement?.(),A=c.today();return st(c,o,{...d,selection:he.id?[he.id]:de,principal:{...z,...g.roles?{roles:g.roles}:{}},places:u(c.schema,p.places(),m?{pages:m}:{}),...b?{place:b}:{},...A?{today:A}:{},...C?{app:C}:{}})},onReply:o=>{let d=o.moves?.[0];d&&le(d);let n=o.questions?.[0];h(n?{type:"asking",author:z,where:n.nodeId??null,say:`${n.nodeLabel?`${n.nodeLabel}: `:""}${n.asks}`,confidence:n.confidence}:{type:"said",author:z,say:o.say});let u=o.proposals.find(b=>!ue(b));if(u){let b=c.permits({name:u.mutation,args:{...u.args}},Y);b.ok||h({type:"refused",author:z,where:Se(u.mutation),say:b.refusal.message})}}}),{outcomes:Q,settle:pe}=N,ke=oe(w);(0,L.useEffect)(()=>{if(!y||ke.pending===null||N.busy)return;let o=w.takePending();o&&N.send(o)},[y,ke.pending,N.busy]);let Y={...z,...g.roles?{roles:g.roles}:{}},ue=o=>c.permits({name:o.mutation,args:{...o.args}},Y).ok,Se=o=>{let d=c.allMutations().find(n=>n.name===o)?.subject?.kinds;return Array.isArray(d)&&d[0]?Pe(d[0]):null},[H,Z]=(0,L.useState)(null),X=async(o,d)=>{let n=Ge(c,o),u=G(c,n),b=V.definitions.find(A=>A.act===n.mutation)?.name??n.mutation;ce.current=N.turns[Number(d.split(":")[0])]?.via;let m=await V.call(b,{...n.args}).finally(()=>{ce.current=void 0});return m.ok?(pe(d,{state:"applied",said:u}),!0):(pe(d,{state:"refused",error:m.error}),h({type:"refused",author:z,where:Se(n.mutation),say:m.error}),!1)},lt=async(o,d)=>{for(let[n,u]of d.entries()){let b=B(o,n);if(Q.get(b)?.state==="applied"||!ue(u))continue;let m=ve(c,u);if(m.length>0){Z({proposal:u,open:m,key:b});return}if(!await X(u,b))return}},ee=(0,L.useRef)(null),fe=(0,L.useRef)(null);(0,L.useLayoutEffect)(()=>{let o=fe.current;if(!o||o.isConnected||document.activeElement!==document.body)return;fe.current=null,(ee.current?.querySelector(`[data-testid="${a}-apply"]:not([disabled])`)??ee.current?.querySelector(`[data-testid="${a}-draft"]`)??ee.current?.closest("[data-testid='seat']")?.querySelector("[data-testid='seat-field']"))?.focus()});let dt=(o,d,n,u)=>{let b=c.permits({name:n.mutation,args:{...n.args}},Y);if(!b.ok)return(0,v.jsxs)("span",{"data-testid":`${a}-withheld`,style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)"},children:[(0,v.jsx)("s",{children:G(c,n)})," \u2014 ",b.refusal.message]});let m=ve(c,n),A=(N.turns[o]?.proposals??[]).slice(0,d).filter((xe,F)=>Q.get(B(o,F))?.state!=="applied").find(xe=>m.some(F=>F.kinds&&typeof n.args[F.name]=="string"&&xe.args.label===n.args[F.name])),K=G(c,n);return(0,v.jsxs)("span",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"4px 10px"},children:[(0,v.jsxs)("span",{style:{fontSize:"0.875rem",color:"var(--graview-ink)"},title:n.why,children:[K,m.length>0&&!A?" \u2026":""]}),(0,v.jsxs)("span",{style:{display:"inline-flex",gap:6},children:[(0,v.jsx)("button",{type:"button","data-testid":`${a}-apply`,"data-graview-asks":m.length>0?m.length:void 0,disabled:A!==void 0,"aria-label":`Do it: ${K}`,onClick:()=>m.length>0?Z({proposal:n,open:m,key:u}):void X(n,u),title:A?`After \u201C${G(c,A)}\u201D`:m.length>0?`${K} \u2014 it asks for ${m.length===1?"one more thing":`${m.length} more things`}`:K,style:J,children:"Do it"}),(0,v.jsx)("button",{type:"button","data-testid":`${a}-decline`,"aria-label":`Not now: ${K}`,onClick:()=>pe(u,{state:"declined",said:K}),style:{...J,color:"var(--graview-ink-muted)"},children:"Not now"})]})]})};return(0,v.jsxs)("div",{"data-testid":`${a}-panel`,ref:ee,onFocus:o=>{fe.current=o.target},style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",alignContent:"start",gap:8,minWidth:0,minHeight:0},children:[N.turns.length===0?s??null:null,(0,v.jsx)(nt,{turns:N.turns,outcomes:Q,busy:N.busy,testId:a,minHeight:0,maxHeight:"none",empty:s!==void 0?null:(0,v.jsxs)(v.Fragment,{children:["Ask what's wrong, ask about anything by name, or say a change in its own words.",de.length>0?" \u201CThis\u201D means what you have selected.":""]}),renderProposal:(o,{key:d,turn:n,at:u})=>dt(n,u,o,d),ready:o=>ue(o),onApplyAll:(o,d)=>void lt(o,d),applyAllLabel:"Do all",renderSaid:(o,d)=>o.moves?.length?$t(d,o.moves,(n,u)=>(0,v.jsx)("button",{type:"button","data-testid":`${a}-went`,title:`Go to ${u}`,onClick:()=>le(n),style:{...at,fontSize:"inherit"},children:u},`${n.address}:${u}`)):d,renderAfter:(o,d)=>[...o.offer?[(0,v.jsx)("button",{type:"button","data-testid":`${a}-offer`,onClick:()=>w.ask(`a list of ${o.offer.draft}`),style:{...J,justifySelf:"start"},children:o.offer.label},`${d}:offer`)]:[],...o.kept&&!o.kept.taken?[(0,v.jsx)("button",{type:"button","data-testid":`${a}-take-back`,onClick:()=>void rt(o.kept),style:{...J,justifySelf:"start"},children:"Take back"},`${d}:take-back`)]:[],...o.picks?.length?[(0,v.jsx)("p",{"data-testid":`${a}-picks`,style:{margin:0,display:"flex",flexWrap:"wrap",gap:"2px 12px"},children:o.picks.map(n=>(0,v.jsx)("button",{type:"button","data-testid":`${a}-pick`,"data-chat-pick":n.id,title:n.why.field==="label"?`Go to ${n.label}`:`${n.why.reading}: ${n.why.fragment}`,onClick:()=>r?r(n.id):i(u=>j(I(_(u,!1),n.id),[n.id])),style:at,children:n.label},n.id))},`${d}:picks`)]:[],...(o.questions??[]).map(n=>{let u=`${d}:q:${n.id}`,b=Q.get(u);return(0,v.jsxs)("div",{"data-testid":`${a}-question`,"data-chat-question-node":n.nodeId,style:{display:"grid",gap:4,justifySelf:"start"},children:[(0,v.jsxs)("span",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)"},children:[n.nodeLabel?(0,v.jsxs)("strong",{children:[n.nodeLabel,": "]}):null,n.asks,n.because==="split"?" (it could be either)":" (it was not sure)"]}),(0,v.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:n.options.map(m=>(0,v.jsxs)("button",{type:"button","data-testid":`${a}-option`,disabled:!m.call,title:m.call?m.call.why??"Take this answer":"Nothing to do for this answer",onClick:()=>m.call?void X(m.call,u):void 0,style:J,children:[m.value," ",Math.round(m.probability*100),"%"]},m.value))}),b?(0,v.jsx)(ie,{outcome:b,testId:a}):null]},n.id)})]}),H?(0,v.jsx)("div",{"data-testid":`${a}-asking`,children:(0,v.jsx)(De,{affordance:{id:`chat:${H.proposal.mutation}`,mutation:H.proposal.mutation,label:G(c,H.proposal),provider:"llm",why:H.proposal.why??"Suggested in the conversation.",nodeIds:[],args:H.proposal.args,open:H.open,score:0},onApply:o=>{let d={...H.proposal,args:{...H.proposal.args,...o}};Z(null),X(d,H.key)},onCancel:()=>Z(null)})}):null,k?(0,v.jsx)(ot,{busy:N.busy,placeholder:de.length>0?"Ask about this\u2026":"Ask, or say a change\u2026",ariaLabel:"Ask",testId:a,onSend:o=>y?w.ask(o):void N.send(o)}):null]})}var J={font:"inherit",fontSize:"0.8125rem",minHeight:26,padding:"0 9px",borderRadius:6,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",boxShadow:"none",color:"var(--graview-ink)",cursor:"pointer"},at={font:"inherit",fontSize:"0.875rem",minHeight:24,padding:0,border:0,borderRadius:2,background:"transparent",boxShadow:"none",color:"var(--graview-accent)",textDecoration:"underline",textUnderlineOffset:3,textAlign:"start",cursor:"pointer"};export{Ye as a,yt as b,Xe as c,et as d,Qt as e,J as f,at as g};
@@ -1,4 +1,4 @@
1
- import{a as Be,b as Oe,c as qt,d as _t,f as We}from"./chunk.NOXC454O.js";import{h as Pt,i as Dt,j as Wt,k as Ft}from"./chunk.XEJS2VS5.js";import{a as Bt,b as Ot}from"./chunk.4UQLZ7VW.js";import"./chunk.DN4D4HGX.js";import"./chunk.DJ26NOOW.js";import"./chunk.SQD7ZPEJ.js";import{d as Kt}from"./chunk.LSLFKW4M.js";import{a as na}from"./chunk.IKT7JQUW.js";import{b as Lt}from"./chunk.AZG6V3PF.js";import{b as Et,i as Ht}from"./chunk.6CLHFNDM.js";import{b as Mt}from"./chunk.WGNF4E67.js";import"./chunk.R5K7NK4U.js";import{a as It}from"./chunk.L5G5DTFX.js";import{a as Rt,b as Q}from"./chunk.VRXWNUDR.js";import"./chunk.BQV62QEL.js";import{l as Nt}from"./chunk.DAKED3WK.js";import"./chunk.WWRWXFYR.js";import"./chunk.ZFUQA3KT.js";import"./chunk.DO4P2UK4.js";import"./chunk.6KJSFIO7.js";import"./chunk.FLJP3BGP.js";import"./chunk.ENMNLR73.js";import"./chunk.LZQZP2PD.js";import"./chunk.ACZGK7LQ.js";import"./chunk.AHDOKM4O.js";import"./chunk.LGUV2J6Q.js";import{Aa as ze,B as yt,E as kt,F as St,G as $t,K as he,W as zt,a as wt,ba as Ct,ca as T,ea as At,i as ht,j as ye,m as we,n as mt,o as ft,p as ke,pa as De,q as bt,qa as Tt,r as Se,ra as de,s as Ne,ua as $e,v as Pe,xa as Ee,y as xt}from"./chunk.4JSMCNF7.js";import{$ as gt,N as lt,P as xe,Q as dt,S as Me,T as Le,Va as ct,aa as pt,ab as ut,hb as vt,sb as W,ub as F}from"./chunk.Y235YZSZ.js";import{a as ae,b as E}from"./chunk.MRK6QJV5.js";import{b as w}from"./chunk.AJZBJBMO.js";var Ce=t=>`${t.saturation}% ${t.lightness}%`,Ut=t=>`${Ce(t)} / ${t.alpha}`;function la(t){let a=vt(t);return`
1
+ import{a as Be,b as Oe,c as qt,d as _t,f as We}from"./chunk.VLNI5U6H.js";import{h as Pt,i as Dt,j as Wt,k as Ft}from"./chunk.HH6WIUK3.js";import{a as Bt,b as Ot}from"./chunk.GDIRDJF3.js";import"./chunk.Y4R77MKX.js";import"./chunk.FRNIWOKD.js";import"./chunk.42U4UBDE.js";import{d as Kt}from"./chunk.UIZWVBJ7.js";import{a as na}from"./chunk.IKT7JQUW.js";import{b as Lt}from"./chunk.TWGB347L.js";import{b as Et,i as Ht}from"./chunk.AKOC43TV.js";import{b as Mt}from"./chunk.D3CYTXNZ.js";import"./chunk.MYCTNK6D.js";import{a as It}from"./chunk.3O2QU7LU.js";import{a as Rt,b as Q}from"./chunk.NRWJ6PLU.js";import"./chunk.7U7Q3HIS.js";import{l as Nt}from"./chunk.6O67NOZR.js";import"./chunk.WWRWXFYR.js";import"./chunk.ISAMJ7AK.js";import"./chunk.54NSG7BX.js";import"./chunk.6KJSFIO7.js";import"./chunk.UM5IPM22.js";import"./chunk.6XBLDV4A.js";import"./chunk.WOTNMTIY.js";import"./chunk.PRXKRG6O.js";import"./chunk.AHDOKM4O.js";import"./chunk.LW7KV5SL.js";import{Aa as ze,B as yt,E as kt,F as St,G as $t,K as he,W as zt,a as wt,ba as Ct,ca as T,ea as At,i as ht,j as ye,m as we,n as mt,o as ft,p as ke,pa as De,q as bt,qa as Tt,r as Se,ra as de,s as Ne,ua as $e,v as Pe,xa as Ee,y as xt}from"./chunk.2VX6H2LL.js";import{N as lt,P as xe,Q as dt,S as Me,T as Le,Ya as ct,ba as gt,ca as pt,db as ut,kb as vt,vb as W,xb as F}from"./chunk.ZQ4HFIIS.js";import{a as ae,b as E}from"./chunk.MRK6QJV5.js";import{b as w}from"./chunk.AJZBJBMO.js";var Ce=t=>`${t.saturation}% ${t.lightness}%`,Ut=t=>`${Ce(t)} / ${t.alpha}`;function la(t){let a=vt(t);return`
2
2
 
3
3
 
4
4
  .graview-altitude-control {
@@ -1,4 +1,4 @@
1
- import{a as k,b as K}from"./chunk.LGUV2J6Q.js";import{Aa as U,a as z,ua as j,xa as W,ya as _}from"./chunk.4JSMCNF7.js";import{Ca as F,D as M,I as G,M as E}from"./chunk.Y235YZSZ.js";import{a as X,b as B}from"./chunk.MRK6QJV5.js";import{b as L}from"./chunk.AJZBJBMO.js";var S=L(X(),1);var r=L(B(),1),ee=520;function re(e,n,u,a){let o=u.filters.find(d=>d.key===a.key);if(!o)return`${a.key}: ${a.value}`;if(o.about==="is")return a.value.charAt(0).toUpperCase()+a.value.slice(1);if(o.about==="edge"){if(a.value==="*")return`${o.label}: anything`;if(a.value==="none")return`${o.label}: nothing`;let d=n.getNode(a.value);return`${o.label}: ${d?G(e.tryDefinition(d.kind),d):a.value}`}if(o.type==="date"){let[d,g]=a.value.split(":");return`${o.label} ${d} ${g?M(g):""}`.trim()}if(o.type==="boolean")return`${o.label}: ${a.value==="true"?"yes":"no"}`;if(o.type==="number"){let d=a.value.lastIndexOf(":"),g=a.value.slice(0,Math.max(0,d));if(g==="at-most"||g==="at-least")return`${o.label}: ${g==="at-most"?"at most":"at least"} ${E(e.tryDefinition(u.kind),o.key,Number(a.value.slice(d+1)))}`}return o.type==="text"?`${o.label}: ${a.value}`:`${o.label}: ${E(e.tryDefinition(u.kind),o.key,a.value)}`}var I=e=>/^[A-Z][a-z]/.test(e)?e.charAt(0).toLowerCase()+e.slice(1):e;function ne(e){return e?.type==="date"?{asc:"Earliest first",desc:"Latest first"}:e?.type==="number"?{asc:"Lowest first",desc:"Highest first"}:e?.type==="boolean"?{asc:"No first",desc:"Yes first"}:e?.type==="choice"?{asc:"In their order",desc:"In reverse order"}:{asc:"A to Z",desc:"Z to A"}}var $=_(z(()=>import("./chunk.JE4VH767.js"))),x=$.part((e,n)=>(0,r.jsx)(e.ArrangeLists,{...n}),{what:"This list",quiet:!0}),fe=()=>$.load(),O=new Map;function ye(e){let{schema:n,graph:u,kind:a,arrangement:o,onChange:d}=e,g=F(n,a),s=e.testId??"arrange",c=k(e.allow,"sort")&&g.sorts.length>1,f=k(e.allow,"group")&&g.groups.length>0,m=k(e.allow,"filter")&&g.filters.length>0,R=e.query!==!1&&e.allow!==!1,v=te(e.noun,e.kept);if(!c&&!f&&!m&&!R&&!v)return null;let D=t=>JSON.stringify(K(t)),N=`${s}|${a}`,p={current:O.get(N)??{words:new Set,latest:null,at:0}};O.set(N,p.current),p.current.latest&&Date.now()-p.current.at>1500&&!p.current.words.has(D(o))&&(p.current={words:new Set,latest:null,at:0},O.set(N,p.current));let i=p.current.latest??o,h=t=>{let l={...p.current.latest??o,...t};for(let w of Object.keys(l))l[w]===void 0&&delete l[w];p.current.latest=l,p.current.at=Date.now(),p.current.words.add(D(l)),d(l)},y=i.filter??[],P=t=>{let l=y.filter((w,Q)=>Q!==t);h({filter:l.length>0?l:void 0})},T=t=>y.some(l=>l.key===t.key&&l.value===t.value),Y=t=>T(t)?P(y.findIndex(l=>l.key===t.key&&l.value===t.value)):h({filter:[...y,t]}),C=i.sort?g.sorts.find(t=>t.key===i.sort.by):void 0,q=i.group?g.groups.find(t=>t.key===i.group.by):void 0,Z=ne(C),b={schema:n,graph:u,offers:g,arrangement:i,set:h,toggle:Y,has:T,testId:s},V=i.sort?(0,r.jsxs)(r.Fragment,{children:["Sorted by ",I(C?.label??i.sort.by),(0,r.jsx)("span",{"aria-hidden":"true",children:i.sort.direction==="desc"?" \u2193":" \u2191"})]}):"Sort",J=i.group?.bucket&&q?.buckets?`, a ${i.group.bucket} each`:"",H=i.group?`Grouped by ${I(q?.label??i.group.by)}${J}`:"Group";return(0,r.jsxs)("div",{"data-testid":`${s}-bar`,role:"group","aria-label":"Arrange",className:"graview-arrange",style:e.style,onPointerEnter:$.prefetch,onFocus:$.prefetch,children:[(0,r.jsx)("style",{children:ie}),(0,r.jsxs)("div",{className:"graview-arrange-line",children:[v?(0,r.jsxs)("span",{className:"graview-arrange-count","data-testid":`${s}-count`,children:[v.kept?(0,r.jsx)("span",{"data-testid":`${s}-kept`,children:v.kept}):null,v.words]}):null,c?(0,r.jsx)("span",{className:"graview-arrange-part graview-arrange-one",children:(0,r.jsx)(A,{testId:`${s}-sort`,value:i.sort?.by??"",set:i.sort!==void 0,label:"Sort",name:i.sort?`Sorted by ${I(C?.label??i.sort.by)}, ${Z[i.sort.direction].toLowerCase()}`:"Sort",list:t=>(0,r.jsx)(x,{which:"sort",done:t,...b}),children:V})}):null,f?(0,r.jsx)("span",{className:"graview-arrange-part graview-arrange-one",children:(0,r.jsx)(A,{testId:`${s}-group`,value:i.group?.by??"",set:i.group!==void 0,label:"Group",name:H,list:t=>(0,r.jsx)(x,{which:"group",done:t,...b}),children:H})}):null,m?(0,r.jsx)("span",{className:"graview-arrange-part graview-arrange-one",children:(0,r.jsx)(A,{testId:`${s}-add`,value:"",set:!1,label:"Filter",name:y.length>0?`Filter \u2014 ${y.length} on`:"Filter",list:t=>(0,r.jsx)(x,{which:"filter",done:t,...b}),children:"Filter"})}):null,c||f||m?(0,r.jsx)("span",{className:"graview-arrange-part graview-arrange-all",children:(0,r.jsx)(A,{testId:`${s}-all`,value:"",set:!1,label:"Arrange",name:"Arrange: sort, group and filter",list:t=>(0,r.jsx)(x,{which:"all",done:t,parts:{sort:c,group:f,filter:m},...b}),children:"Arrange"})}):null,y.map((t,l)=>{let w=re(n,u,g,t);return(0,r.jsxs)("span",{className:"graview-arrange-token","data-testid":`${s}-condition`,children:[w,(0,r.jsx)("button",{type:"button","aria-label":`Remove: ${w}`,title:"Remove",onClick:()=>P(l),children:"\xD7"})]},`${t.key}:${t.value}`)}),R?(0,r.jsxs)("label",{className:"graview-arrange-words-at",children:[(0,r.jsx)("span",{style:U,children:"Find"}),(0,r.jsx)("input",{type:"search",className:"graview-arrange-words","data-testid":`${s}-query`,value:i.query??"",placeholder:"Find\u2026",onChange:t=>h({query:t.target.value.length>0?t.target.value:void 0})})]}):null]})]})}function te(e,n){if(!n)return null;let u=n.shown!==n.of;if(!e)return u?{words:"",kept:`${n.shown} of ${n.of}`}:null;let a=n.of===1?e.one:e.many;return u?{words:` ${a}`,kept:`${n.shown} of ${n.of}`}:{words:`${n.of} ${a}`}}function A({testId:e,value:n,set:u,label:a,name:o,list:d,children:g}){let s=W("arrange",{align:"start"}),c=(0,S.useRef)(null);return(0,S.useEffect)(()=>{s.open&&c.current?.querySelector('[aria-pressed="true"]')?.focus({preventScroll:!0})},[s.open]),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",className:"graview-arrange-open","data-testid":e,"data-set":u?"":void 0,value:n,"aria-label":o,...s.trigger,onClick:s.toggle,children:[g,(0,r.jsx)(oe,{})]}),s.open?(0,r.jsx)("div",{...s.pane,ref:f=>{s.pane.ref(f),c.current=f},role:"group","aria-label":a,"data-testid":"arrange-list","data-arrange":e,className:"graview-arrange-list",style:j,onKeyDown:ae,children:d(()=>s.setOpen(!1))}):null]})}function ae(e){if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key))return;let n=[...e.currentTarget.querySelectorAll("button:not([disabled]), input")];if(n.length===0)return;let u=n.indexOf(document.activeElement);if(document.activeElement instanceof HTMLInputElement&&(e.key==="ArrowUp"||e.key==="ArrowDown"))return;e.preventDefault();let a=e.key==="Home"?0:e.key==="End"?n.length-1:e.key==="ArrowDown"?(u+1)%n.length:(u-1+n.length)%n.length;n[a].focus()}function oe(){return(0,r.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10","aria-hidden":"true",focusable:"false",style:{flex:"0 0 auto",opacity:.7},children:(0,r.jsx)("path",{d:"M2 3.5 L5 6.5 L8 3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}var ie=`
1
+ import{a as k,b as K}from"./chunk.LW7KV5SL.js";import{Aa as U,a as z,ua as j,xa as W,ya as _}from"./chunk.2VX6H2LL.js";import{D as M,Ea as F,I as G,M as E}from"./chunk.ZQ4HFIIS.js";import{a as X,b as B}from"./chunk.MRK6QJV5.js";import{b as L}from"./chunk.AJZBJBMO.js";var S=L(X(),1);var r=L(B(),1),ee=520;function re(e,n,u,a){let o=u.filters.find(d=>d.key===a.key);if(!o)return`${a.key}: ${a.value}`;if(o.about==="is")return a.value.charAt(0).toUpperCase()+a.value.slice(1);if(o.about==="edge"){if(a.value==="*")return`${o.label}: anything`;if(a.value==="none")return`${o.label}: nothing`;let d=n.getNode(a.value);return`${o.label}: ${d?G(e.tryDefinition(d.kind),d):a.value}`}if(o.type==="date"){let[d,g]=a.value.split(":");return`${o.label} ${d} ${g?M(g):""}`.trim()}if(o.type==="boolean")return`${o.label}: ${a.value==="true"?"yes":"no"}`;if(o.type==="number"){let d=a.value.lastIndexOf(":"),g=a.value.slice(0,Math.max(0,d));if(g==="at-most"||g==="at-least")return`${o.label}: ${g==="at-most"?"at most":"at least"} ${E(e.tryDefinition(u.kind),o.key,Number(a.value.slice(d+1)))}`}return o.type==="text"?`${o.label}: ${a.value}`:`${o.label}: ${E(e.tryDefinition(u.kind),o.key,a.value)}`}var I=e=>/^[A-Z][a-z]/.test(e)?e.charAt(0).toLowerCase()+e.slice(1):e;function ne(e){return e?.type==="date"?{asc:"Earliest first",desc:"Latest first"}:e?.type==="number"?{asc:"Lowest first",desc:"Highest first"}:e?.type==="boolean"?{asc:"No first",desc:"Yes first"}:e?.type==="choice"?{asc:"In their order",desc:"In reverse order"}:{asc:"A to Z",desc:"Z to A"}}var $=_(z(()=>import("./chunk.HDEQXJWX.js"))),x=$.part((e,n)=>(0,r.jsx)(e.ArrangeLists,{...n}),{what:"This list",quiet:!0}),fe=()=>$.load(),O=new Map;function ye(e){let{schema:n,graph:u,kind:a,arrangement:o,onChange:d}=e,g=F(n,a),s=e.testId??"arrange",c=k(e.allow,"sort")&&g.sorts.length>1,f=k(e.allow,"group")&&g.groups.length>0,m=k(e.allow,"filter")&&g.filters.length>0,R=e.query!==!1&&e.allow!==!1,v=te(e.noun,e.kept);if(!c&&!f&&!m&&!R&&!v)return null;let D=t=>JSON.stringify(K(t)),N=`${s}|${a}`,p={current:O.get(N)??{words:new Set,latest:null,at:0}};O.set(N,p.current),p.current.latest&&Date.now()-p.current.at>1500&&!p.current.words.has(D(o))&&(p.current={words:new Set,latest:null,at:0},O.set(N,p.current));let i=p.current.latest??o,h=t=>{let l={...p.current.latest??o,...t};for(let w of Object.keys(l))l[w]===void 0&&delete l[w];p.current.latest=l,p.current.at=Date.now(),p.current.words.add(D(l)),d(l)},y=i.filter??[],P=t=>{let l=y.filter((w,Q)=>Q!==t);h({filter:l.length>0?l:void 0})},T=t=>y.some(l=>l.key===t.key&&l.value===t.value),Y=t=>T(t)?P(y.findIndex(l=>l.key===t.key&&l.value===t.value)):h({filter:[...y,t]}),C=i.sort?g.sorts.find(t=>t.key===i.sort.by):void 0,q=i.group?g.groups.find(t=>t.key===i.group.by):void 0,Z=ne(C),b={schema:n,graph:u,offers:g,arrangement:i,set:h,toggle:Y,has:T,testId:s},V=i.sort?(0,r.jsxs)(r.Fragment,{children:["Sorted by ",I(C?.label??i.sort.by),(0,r.jsx)("span",{"aria-hidden":"true",children:i.sort.direction==="desc"?" \u2193":" \u2191"})]}):"Sort",J=i.group?.bucket&&q?.buckets?`, a ${i.group.bucket} each`:"",H=i.group?`Grouped by ${I(q?.label??i.group.by)}${J}`:"Group";return(0,r.jsxs)("div",{"data-testid":`${s}-bar`,role:"group","aria-label":"Arrange",className:"graview-arrange",style:e.style,onPointerEnter:$.prefetch,onFocus:$.prefetch,children:[(0,r.jsx)("style",{children:ie}),(0,r.jsxs)("div",{className:"graview-arrange-line",children:[v?(0,r.jsxs)("span",{className:"graview-arrange-count","data-testid":`${s}-count`,children:[v.kept?(0,r.jsx)("span",{"data-testid":`${s}-kept`,children:v.kept}):null,v.words]}):null,c?(0,r.jsx)("span",{className:"graview-arrange-part graview-arrange-one",children:(0,r.jsx)(A,{testId:`${s}-sort`,value:i.sort?.by??"",set:i.sort!==void 0,label:"Sort",name:i.sort?`Sorted by ${I(C?.label??i.sort.by)}, ${Z[i.sort.direction].toLowerCase()}`:"Sort",list:t=>(0,r.jsx)(x,{which:"sort",done:t,...b}),children:V})}):null,f?(0,r.jsx)("span",{className:"graview-arrange-part graview-arrange-one",children:(0,r.jsx)(A,{testId:`${s}-group`,value:i.group?.by??"",set:i.group!==void 0,label:"Group",name:H,list:t=>(0,r.jsx)(x,{which:"group",done:t,...b}),children:H})}):null,m?(0,r.jsx)("span",{className:"graview-arrange-part graview-arrange-one",children:(0,r.jsx)(A,{testId:`${s}-add`,value:"",set:!1,label:"Filter",name:y.length>0?`Filter \u2014 ${y.length} on`:"Filter",list:t=>(0,r.jsx)(x,{which:"filter",done:t,...b}),children:"Filter"})}):null,c||f||m?(0,r.jsx)("span",{className:"graview-arrange-part graview-arrange-all",children:(0,r.jsx)(A,{testId:`${s}-all`,value:"",set:!1,label:"Arrange",name:"Arrange: sort, group and filter",list:t=>(0,r.jsx)(x,{which:"all",done:t,parts:{sort:c,group:f,filter:m},...b}),children:"Arrange"})}):null,y.map((t,l)=>{let w=re(n,u,g,t);return(0,r.jsxs)("span",{className:"graview-arrange-token","data-testid":`${s}-condition`,children:[w,(0,r.jsx)("button",{type:"button","aria-label":`Remove: ${w}`,title:"Remove",onClick:()=>P(l),children:"\xD7"})]},`${t.key}:${t.value}`)}),R?(0,r.jsxs)("label",{className:"graview-arrange-words-at",children:[(0,r.jsx)("span",{style:U,children:"Find"}),(0,r.jsx)("input",{type:"search",className:"graview-arrange-words","data-testid":`${s}-query`,value:i.query??"",placeholder:"Find\u2026",onChange:t=>h({query:t.target.value.length>0?t.target.value:void 0})})]}):null]})]})}function te(e,n){if(!n)return null;let u=n.shown!==n.of;if(!e)return u?{words:"",kept:`${n.shown} of ${n.of}`}:null;let a=n.of===1?e.one:e.many;return u?{words:` ${a}`,kept:`${n.shown} of ${n.of}`}:{words:`${n.of} ${a}`}}function A({testId:e,value:n,set:u,label:a,name:o,list:d,children:g}){let s=W("arrange",{align:"start"}),c=(0,S.useRef)(null);return(0,S.useEffect)(()=>{s.open&&c.current?.querySelector('[aria-pressed="true"]')?.focus({preventScroll:!0})},[s.open]),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("button",{type:"button",className:"graview-arrange-open","data-testid":e,"data-set":u?"":void 0,value:n,"aria-label":o,...s.trigger,onClick:s.toggle,children:[g,(0,r.jsx)(oe,{})]}),s.open?(0,r.jsx)("div",{...s.pane,ref:f=>{s.pane.ref(f),c.current=f},role:"group","aria-label":a,"data-testid":"arrange-list","data-arrange":e,className:"graview-arrange-list",style:j,onKeyDown:ae,children:d(()=>s.setOpen(!1))}):null]})}function ae(e){if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key))return;let n=[...e.currentTarget.querySelectorAll("button:not([disabled]), input")];if(n.length===0)return;let u=n.indexOf(document.activeElement);if(document.activeElement instanceof HTMLInputElement&&(e.key==="ArrowUp"||e.key==="ArrowDown"))return;e.preventDefault();let a=e.key==="Home"?0:e.key==="End"?n.length-1:e.key==="ArrowDown"?(u+1)%n.length:(u-1+n.length)%n.length;n[a].focus()}function oe(){return(0,r.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 10 10","aria-hidden":"true",focusable:"false",style:{flex:"0 0 auto",opacity:.7},children:(0,r.jsx)("path",{d:"M2 3.5 L5 6.5 L8 3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}var ie=`
2
2
  .graview-arrange{container-type:inline-size;box-sizing:border-box;width:100%;min-width:0;max-width:100%}
3
3
  .graview-arrange-line{display:flex;flex-wrap:wrap;align-items:center;gap:2px 6px;min-width:0;font-size:.875rem;line-height:1.35;color:var(--graview-ink-muted)}
4
4
  .graview-arrange-count{margin-right:2px;color:var(--graview-ink-muted)}
@@ -1 +1 @@
1
- import{c as L}from"./chunk.EQOU4POV.js";import{a as R,b as O,c as v,d as P}from"./chunk.ONDILMIX.js";import"./chunk.NOXC454O.js";import"./chunk.6CLHFNDM.js";import{a as E,b as T}from"./chunk.R5K7NK4U.js";import"./chunk.HCK6IHGP.js";import"./chunk.YAONM74M.js";import"./chunk.CJQL7AHT.js";import"./chunk.BQV62QEL.js";import"./chunk.DAKED3WK.js";import"./chunk.WWRWXFYR.js";import"./chunk.ZFUQA3KT.js";import"./chunk.DO4P2UK4.js";import"./chunk.6KJSFIO7.js";import"./chunk.FLJP3BGP.js";import"./chunk.ENMNLR73.js";import"./chunk.LZQZP2PD.js";import"./chunk.SCLIBKLS.js";import"./chunk.ACZGK7LQ.js";import"./chunk.AHDOKM4O.js";import"./chunk.3MLQ3Q5X.js";import"./chunk.LGUV2J6Q.js";import{va as x}from"./chunk.4JSMCNF7.js";import{ub as k}from"./chunk.Y235YZSZ.js";import{a as D,b as C}from"./chunk.MRK6QJV5.js";import{b as S}from"./chunk.AJZBJBMO.js";var o=S(D(),1);var i=S(C(),1);function W(c){let e=document.activeElement;if(e!==null&&e!==document.body&&e!==document.documentElement&&e.isConnected)return;let r=c??document,a=r.querySelector("main")??r.querySelector("[data-graview-page]")??null,n=r.querySelector("[data-graview-page-title]")??a?.querySelector("h1, h2")??a;n instanceof HTMLElement&&(n.hasAttribute("tabindex")||n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}))}var H=1500;function z(c,e,r){let{store:a,principal:n}=c,u=L(a),l=(0,o.useMemo)(()=>R(a,n),[a,n,u]),b=(0,o.useRef)(r),[p,m]=(0,o.useState)(),[s,f]=(0,o.useState)("");(0,o.useEffect)(()=>{let t=O(a,n,b.current);b.current=a.batches().length,t&&(m({batch:t.batch,at:e,when:Date.now()}),f(""))},[a,n,u]),(0,o.useEffect)(()=>{m(t=>!t||t.at===e?t:Date.now()-t.when<H?{...t,at:e}:void 0)},[e]);let[g,h]=(0,o.useState)(null),y=(0,o.useCallback)(()=>{m(void 0),h(null)},[]),w=(0,o.useCallback)(()=>{h(null);try{let t=P(a,n);t&&f(`Took back \u201C${t.intent}\u201D`)}catch(t){h(t instanceof Error?t.message:String(t))}},[a,n]),d=l&&p?.batch===l.batch&&p.at===e?l:void 0;return{change:l,offered:d,close:y,takeBack:w,refused:g,said:s}}function Y({context:c,docked:e,at:r,since:a}){let{change:n,offered:u,close:l,takeBack:b,refused:p,said:m}=z(c,r,a),s=e?u:n,f=(0,o.useRef)(null),g=e&&(s!==void 0||p!==null);B(f,g),(0,o.useEffect)(()=>{if(!g)return;let d,t=()=>d=setTimeout(()=>f.current?.matches(":hover, :focus-within")?t():l(),1e4);return t(),()=>clearTimeout(d)},[g,s?.batch,p,l]);let h=m||(e&&s?v(s):""),y=e?{position:"fixed",inset:"auto",margin:0,padding:0,border:"none",background:"none",overflow:"visible",zIndex:k("toast"),width:"max-content",height:"auto",bottom:"calc(16px + env(safe-area-inset-bottom, 0px))",left:16,justifyItems:"start",color:"var(--graview-ink)",...g?{}:{display:"none"}}:{},w=s?(0,i.jsxs)("button",{type:"button","data-testid":"page-undo",title:`${v(s)} \u2014 \u2318Z or Ctrl+Z`,"aria-keyshortcuts":"Meta+Z Control+Z",onClick:d=>{let t=d.currentTarget.closest("[data-graview-face]");b(),requestAnimationFrame(()=>W(t))},style:e?I:A,children:[(0,i.jsx)("span",{"aria-hidden":"true",children:"\u21B6"}),(0,i.jsx)("span",{style:e?j:F,children:v(s)})]}):null;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{role:"status","aria-live":"polite",style:N,children:h}),(0,i.jsxs)("div",{ref:f,...e?{popover:"manual","data-graview-foot":"","data-graview-offstage":""}:{},"data-testid":e?"face-undo-dock":"page-undo-place",style:{display:"grid",justifyItems:"end",gap:4,maxWidth:"100%",minWidth:0,...y},children:[e&&s?(0,i.jsxs)("div",{"data-testid":"page-undo-notice",style:_,children:[w,(0,i.jsx)("button",{type:"button","data-testid":"page-undo-dismiss","aria-label":`Dismiss: ${v(s)}`,title:"Dismiss",onClick:d=>{let t=d.currentTarget.closest("[data-graview-face]");l(),requestAnimationFrame(()=>W(t))},style:q,children:"\xD7"})]}):w,p?(0,i.jsx)("span",{"data-testid":"page-undo-refused",role:"alert",style:{fontSize:"0.8125rem",lineHeight:1.4,color:"var(--graview-warn)",background:e?"var(--graview-float)":void 0,padding:e?"4px 8px":void 0,borderRadius:6},children:p}):null]})]})}function B(c,e){(0,o.useLayoutEffect)(()=>{let r=c.current;if(!r||!e)return;if(typeof r.showPopover=="function"&&!x(r))try{r.showPopover()}catch{}let a=()=>r.parentElement?.closest("[data-embed-content]")??null,n=()=>{T(r,a()),dispatchEvent(new Event(E))};n(),addEventListener("resize",n),addEventListener("scroll",n,!0);let u=typeof ResizeObserver=="function"?new ResizeObserver(n):null;return u?.observe(r),()=>{if(u?.disconnect(),removeEventListener("resize",n),removeEventListener("scroll",n,!0),r.isConnected&&x(r))try{r.hidePopover()}catch{}dispatchEvent(new Event(E))}},[c,e])}var A={display:"inline-flex",alignItems:"center",gap:6,minHeight:36,maxWidth:"100%",minWidth:0,padding:"0 14px",borderRadius:999,border:"1px solid var(--graview-edge)",background:"var(--graview-float)",color:"var(--graview-ink)",font:"inherit",fontSize:"0.875rem",cursor:"pointer"},I={...A,textAlign:"start",lineHeight:1.4,padding:"8px 4px 8px 14px",border:"none",background:"none",color:"inherit"},_={display:"flex",alignItems:"center",gap:2,maxWidth:"100%",minWidth:0,paddingRight:6,borderRadius:"var(--graview-radius, 12px)",border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)"},q={flex:"0 0 auto",minWidth:28,minHeight:28,padding:0,border:"none",background:"none",boxShadow:"none",color:"var(--graview-ink-muted)",font:"inherit",fontSize:"1rem",cursor:"pointer"},F={minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},j={minWidth:0,overflow:"hidden",overflowWrap:"anywhere",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:4},N={position:"absolute",width:1,height:1,margin:-1,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0};export{Y as TakeBack};
1
+ import{c as L}from"./chunk.RGXNZ7PN.js";import{a as R,b as O,c as v,d as P}from"./chunk.ONDILMIX.js";import"./chunk.VLNI5U6H.js";import"./chunk.AKOC43TV.js";import{a as E,b as T}from"./chunk.MYCTNK6D.js";import"./chunk.53RZI5PM.js";import"./chunk.XJNXSQT4.js";import"./chunk.VTBAKTFP.js";import"./chunk.7U7Q3HIS.js";import"./chunk.6O67NOZR.js";import"./chunk.WWRWXFYR.js";import"./chunk.ISAMJ7AK.js";import"./chunk.54NSG7BX.js";import"./chunk.6KJSFIO7.js";import"./chunk.UM5IPM22.js";import"./chunk.6XBLDV4A.js";import"./chunk.WOTNMTIY.js";import"./chunk.HAQ4KHRY.js";import"./chunk.PRXKRG6O.js";import"./chunk.AHDOKM4O.js";import"./chunk.TDW6QEG4.js";import"./chunk.LW7KV5SL.js";import{va as x}from"./chunk.2VX6H2LL.js";import{xb as k}from"./chunk.ZQ4HFIIS.js";import{a as D,b as C}from"./chunk.MRK6QJV5.js";import{b as S}from"./chunk.AJZBJBMO.js";var o=S(D(),1);var i=S(C(),1);function W(c){let e=document.activeElement;if(e!==null&&e!==document.body&&e!==document.documentElement&&e.isConnected)return;let r=c??document,a=r.querySelector("main")??r.querySelector("[data-graview-page]")??null,n=r.querySelector("[data-graview-page-title]")??a?.querySelector("h1, h2")??a;n instanceof HTMLElement&&(n.hasAttribute("tabindex")||n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}))}var H=1500;function z(c,e,r){let{store:a,principal:n}=c,u=L(a),l=(0,o.useMemo)(()=>R(a,n),[a,n,u]),b=(0,o.useRef)(r),[p,m]=(0,o.useState)(),[s,f]=(0,o.useState)("");(0,o.useEffect)(()=>{let t=O(a,n,b.current);b.current=a.batches().length,t&&(m({batch:t.batch,at:e,when:Date.now()}),f(""))},[a,n,u]),(0,o.useEffect)(()=>{m(t=>!t||t.at===e?t:Date.now()-t.when<H?{...t,at:e}:void 0)},[e]);let[g,h]=(0,o.useState)(null),y=(0,o.useCallback)(()=>{m(void 0),h(null)},[]),w=(0,o.useCallback)(()=>{h(null);try{let t=P(a,n);t&&f(`Took back \u201C${t.intent}\u201D`)}catch(t){h(t instanceof Error?t.message:String(t))}},[a,n]),d=l&&p?.batch===l.batch&&p.at===e?l:void 0;return{change:l,offered:d,close:y,takeBack:w,refused:g,said:s}}function Y({context:c,docked:e,at:r,since:a}){let{change:n,offered:u,close:l,takeBack:b,refused:p,said:m}=z(c,r,a),s=e?u:n,f=(0,o.useRef)(null),g=e&&(s!==void 0||p!==null);B(f,g),(0,o.useEffect)(()=>{if(!g)return;let d,t=()=>d=setTimeout(()=>f.current?.matches(":hover, :focus-within")?t():l(),1e4);return t(),()=>clearTimeout(d)},[g,s?.batch,p,l]);let h=m||(e&&s?v(s):""),y=e?{position:"fixed",inset:"auto",margin:0,padding:0,border:"none",background:"none",overflow:"visible",zIndex:k("toast"),width:"max-content",height:"auto",bottom:"calc(16px + env(safe-area-inset-bottom, 0px))",left:16,justifyItems:"start",color:"var(--graview-ink)",...g?{}:{display:"none"}}:{},w=s?(0,i.jsxs)("button",{type:"button","data-testid":"page-undo",title:`${v(s)} \u2014 \u2318Z or Ctrl+Z`,"aria-keyshortcuts":"Meta+Z Control+Z",onClick:d=>{let t=d.currentTarget.closest("[data-graview-face]");b(),requestAnimationFrame(()=>W(t))},style:e?I:A,children:[(0,i.jsx)("span",{"aria-hidden":"true",children:"\u21B6"}),(0,i.jsx)("span",{style:e?j:F,children:v(s)})]}):null;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{role:"status","aria-live":"polite",style:N,children:h}),(0,i.jsxs)("div",{ref:f,...e?{popover:"manual","data-graview-foot":"","data-graview-offstage":""}:{},"data-testid":e?"face-undo-dock":"page-undo-place",style:{display:"grid",justifyItems:"end",gap:4,maxWidth:"100%",minWidth:0,...y},children:[e&&s?(0,i.jsxs)("div",{"data-testid":"page-undo-notice",style:_,children:[w,(0,i.jsx)("button",{type:"button","data-testid":"page-undo-dismiss","aria-label":`Dismiss: ${v(s)}`,title:"Dismiss",onClick:d=>{let t=d.currentTarget.closest("[data-graview-face]");l(),requestAnimationFrame(()=>W(t))},style:q,children:"\xD7"})]}):w,p?(0,i.jsx)("span",{"data-testid":"page-undo-refused",role:"alert",style:{fontSize:"0.8125rem",lineHeight:1.4,color:"var(--graview-warn)",background:e?"var(--graview-float)":void 0,padding:e?"4px 8px":void 0,borderRadius:6},children:p}):null]})]})}function B(c,e){(0,o.useLayoutEffect)(()=>{let r=c.current;if(!r||!e)return;if(typeof r.showPopover=="function"&&!x(r))try{r.showPopover()}catch{}let a=()=>r.parentElement?.closest("[data-embed-content]")??null,n=()=>{T(r,a()),dispatchEvent(new Event(E))};n(),addEventListener("resize",n),addEventListener("scroll",n,!0);let u=typeof ResizeObserver=="function"?new ResizeObserver(n):null;return u?.observe(r),()=>{if(u?.disconnect(),removeEventListener("resize",n),removeEventListener("scroll",n,!0),r.isConnected&&x(r))try{r.hidePopover()}catch{}dispatchEvent(new Event(E))}},[c,e])}var A={display:"inline-flex",alignItems:"center",gap:6,minHeight:36,maxWidth:"100%",minWidth:0,padding:"0 14px",borderRadius:999,border:"1px solid var(--graview-edge)",background:"var(--graview-float)",color:"var(--graview-ink)",font:"inherit",fontSize:"0.875rem",cursor:"pointer"},I={...A,textAlign:"start",lineHeight:1.4,padding:"8px 4px 8px 14px",border:"none",background:"none",color:"inherit"},_={display:"flex",alignItems:"center",gap:2,maxWidth:"100%",minWidth:0,paddingRight:6,borderRadius:"var(--graview-radius, 12px)",border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)"},q={flex:"0 0 auto",minWidth:28,minHeight:28,padding:0,border:"none",background:"none",boxShadow:"none",color:"var(--graview-ink-muted)",font:"inherit",fontSize:"1rem",cursor:"pointer"},F={minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},j={minWidth:0,overflow:"hidden",overflowWrap:"anywhere",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:4},N={position:"absolute",width:1,height:1,margin:-1,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0};export{Y as TakeBack};
@@ -0,0 +1 @@
1
+ import{d as R}from"./chunk.42U4UBDE.js";import{H as Q,I as V,L as z,O as Y,S as A,T as D,U as X,Vb as q,Xa as nn,aa as B,oa as L,pa as Z}from"./chunk.ZQ4HFIIS.js";var E=c=>c.filter(Boolean).join(" "),en=new Set(["tell","me","about","what","how","show","describe","the","a","an","and","please"]),an=new Set([...en,"where","is","are","was","find","any","anything","something","things","called","named","which","who","of","for","with","to","in","on","i","my","do","does","have","has","can","you","it","that","this","there","we","our","got","be"]),dn=c=>c.length<=1?A(c[0]??"something"):`${c.slice(0,-1).map(A).join(", ")} and ${A(c[c.length-1])}`;function wn(c={}){return async(t,u,g={})=>{let w=u.toLowerCase(),h=n=>V(t.schema.tryDefinition(n.kind),n),p=(await import("./chunk.BNSY25SG.js")).goingFrom(t,u,g,c.today);if(p.reply)return p.reply;let v=p.told,S=n=>p.moves?{...n,moves:p.moves}:n,y=[],C=w.split(/[^a-z0-9]+/).filter(Boolean),I=new Set;for(let n=0;n<C.length;n++){let e="";for(let s=n;s<Math.min(C.length,n+6);s++)e+=C[s],I.add(e)}let T=n=>n.toLowerCase().replace(/[^a-z0-9]+/g,""),H=[...t.graph.allNodes()].map(n=>({node:n,label:T(h(n))})).filter(({label:n})=>n.length>=2&&I.has(n)).sort((n,e)=>e.label.length-n.label.length),N=new Map;for(let{label:n}of H)N.set(n,(N.get(n)??0)+1);for(let{node:n,label:e}of H)(N.get(e)??0)>1||y.some(s=>s.id===n.id)||y.push(n);for(let n of g.selection??[]){let e=t.graph.getNode(n);e&&!y.some(s=>s.id===e.id)&&y.push(e)}let M=v&&t.graph.getNode(v);if(M){let n=y.findIndex(e=>e.id===M.id);n>=0&&y.splice(n,1),y.unshift(M)}let b=t.violations(),O=(n=b)=>ln(n);if(p.problems||!v&&/\b(wrong|broken|problem|violat|standing)\b/.test(w)){if(b.length===0)return S({say:"Nothing is wrong: every rule holds.",proposals:[],grounded:!0});let n=R(t,O().slice(0,4)),e=(i,r)=>{let d=t.allMutations().find(l=>l.name===i),a=d?q(d.input).find(l=>l.name===r):void 0;return a?.control==="node"&&!a.kinds.includes("*")?a.kinds.map(l=>D(t.schema.tryDefinition(l),l)).join(" or "):B(t.schema,d,r).label},s=[...new Set(b.flatMap(i=>i.repairs).filter(i=>(i.missing??[]).length>0).map(i=>`\u201C${i.label}\u201D (${(i.missing??[]).map(r=>e(i.mutation,r)).join(", ")})`))];return S({say:E([p.moves?.[0]?.said??"",`${Z(b)}:`,b.slice(0,4).map(i=>i.message).join("; ")+(b.length>4?"\u2026":"."),n.length>0?"The repairs below come from the rules themselves.":s.length>0?`Each way to fix ${b.length===1?"it":"these"} asks something first \u2014 ${s.slice(0,4).join(" or ")} \u2014 select the record and its own actions will ask.`:"No rule here names a way to fix it."]),proposals:n,grounded:!0})}let K=/\?\s*$/.test(u)||/^\s*(what|who|whom|whose|which|when|where|why|how|is|are|was|were|does|do|did|can|could|should|would|will|has|have)\b/.test(w),$=K?void 0:t.allMutations().find(n=>{let e=(n.title??n.name).toLowerCase();return e.length>3&&w.includes(e)});if($){let n={},e=[],s=u.slice(u.toLowerCase().indexOf(($.title??$.name).toLowerCase())+($.title??$.name).length),i=y.reduce((a,l)=>{let f=h(l).toLowerCase(),m=a.toLowerCase().indexOf(f);return m<0?a:`${a.slice(0,m)} it${a.slice(m+f.length)}`},s),r=u.match(/"([^"]+)"/)?.[1]??i.match(/^(?:\s+(?:it|this|that|them))?\s+(?:to|as)\s+(.+?)\s*[.!]?$/i)?.[1],d=[...y];for(let a of q($.input)){let l=un(a,d,r,c.today??g.today,w);if(l!==void 0){n[a.name]=l;let f=d.findIndex(m=>m.id===l);f>=0&&d.splice(f,1)}else a.optional||e.push(B(t.schema,$,a.name).label.toLowerCase())}return e.length===0?{say:"I can do that. Review it below.",proposals:R(t,[{mutation:$.name,args:n,why:"you asked in words"}])}:{say:`\u201C${$.title??z($.name)}\u201D needs ${dn(e)} \u2014 say ${e.length===1?"it":"them"} (or select ${e.length===1?"it":"them"}) and ask again.`,proposals:[]}}let tn={mon:"mon",monday:"mon",tue:"tue",tues:"tue",tuesday:"tue",wed:"wed",wednesday:"wed",thu:"thu",thur:"thu",thurs:"thu",thursday:"thu",fri:"fri",friday:"fri",sat:"sat",saturday:"sat",sun:"sun",sunday:"sun"},x=C.map(n=>tn[n]).find(Boolean),_=(n,e,s)=>{let i=t.schema.tryDefinition(n)?.display?.format?.[e];return i?i(s):String(s)},F=n=>{let e=t.schema.tryDefinition(n.kind)?.fieldRoles;if(!e?.start)return null;let s=n[e.start],i=e.end?n[e.end]:void 0,r=e.day?n[e.day]:e.days?n[e.days]:void 0;return s===void 0&&i===void 0?null:[s!==void 0?_(n.kind,e.start,s):null,i!==void 0&&e.end?`\u2013${_(n.kind,e.end,i)}`:null,Array.isArray(r)?` on ${r.join(", ")}`:r!==void 0?` on ${String(r)}`:null].filter(Boolean).join("")||null},sn=n=>{let e=[];for(let s of t.graph.allEdges()){let i=s.from===n?s.to:s.to===n?s.from:null;if(!i)continue;let r=t.graph.getNode(i);r&&!e.some(d=>d.id===r.id)&&e.push(r)}return e},G=n=>{let e=y[0];if(!e)return[];let s=[];for(let r of sn(e.id)){let d=0,a=T(h(r));for(let l of C)l.length>2&&a.includes(l)&&(d+=1);if(x){let l=t.schema.tryDefinition(r.kind)?.fieldRoles,f=l?.day?r[l.day]:void 0,m=l?.days?r[l.days]:void 0;f===x?d+=4:Array.isArray(m)&&m.includes(x)&&(d+=1)}n&&!F(r)||d>0&&s.push({node:r,score:d})}let i=s.sort((r,d)=>d.score-r.score).map(r=>r.node);return n&&F(e)?i.unshift(e):n||i.push(e),i};if(y.length>0&&/\bwhen\b/.test(w)){let n=G(!0)[0]??null,e=n?F(n):null;if(n&&e)return S({say:`${h(n)} runs ${e}.`,proposals:R(t,O(L(b,[n.id])).slice(0,3)),grounded:!0})}if(y.length>0&&/\bwho(m|se)?\b/.test(w))for(let n of G(!1)){let e=[],s=new Set;for(let i of t.schema.definitions)for(let[r,d]of Object.entries(i.edges)){let a=/\bwho\b/i.test(d.description??""),l=/\bwho\b/i.test(d.inverse??"");if(!a&&!l||s.has(r))continue;s.add(r);let f=[...t.graph.in(n.id,r),...t.graph.out(n.id,r)];if(f.length===0)continue;let m=a?d.description:d.inverse;e.push(`${m}: ${f.map(o=>h(o)).join(", ")}`)}if(e.length>0)return S({say:`${h(n)} \u2014 ${e.join("; ")}.`,proposals:R(t,O(L(b,[n.id])).slice(0,3)),grounded:!0})}if(y.length>0){let n=y[0],e=new Set(h(n).toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)),s=C.every(o=>e.has(o)||en.has(o)),i=K||s,r=t.schema.tryDefinition(n.kind),d=o=>o===o.toUpperCase()?o:o.charAt(0).toLowerCase()+o.slice(1),a=X(n,r,{limit:3}).map(o=>{let k=n[o.key];return typeof k=="boolean"&&!/\s/.test(o.label)?k?d(o.label):`not ${d(o.label)}`:typeof k=="string"&&hn.test(k)?`${d(o.label)} ${yn(k)}`:o.alone.startsWith(o.label)?d(o.label)+o.alone.slice(o.label.length):`${d(o.label)} ${o.alone}`}).join(", "),l=L(b,[n.id]),f=new Map;for(let o of[...t.graph.allEdges()]){let k=o.from===n.id?"out":o.to===n.id?"in":null;if(!k)continue;let J=t.graph.getNode(k==="out"?o.to:o.from);if(!J)continue;let P=`${o.kind}|${k}`;if(!f.has(P)){let W;for(let rn of t.schema.definitions){let j=rn.edges[o.kind];if(j&&(W=k==="out"?j.description:j.inverse??j.description,W))break}f.set(P,{sentence:W??z(o.kind).toLowerCase(),names:[]})}let U=f.get(P);U.names.length<6&&U.names.push(h(J))}let m=[...f.values()].slice(0,4).map(o=>`${o.sentence.charAt(0).toUpperCase()}${o.sentence.slice(1)}: ${o.names.join(", ")}`).join(". ");return S({say:E([p.moves?.[0]?.said??"",`${h(n)} \u2014 ${A(D(t.schema.tryDefinition(n.kind),n.kind))}${a?` (${a})`:""}.`,m?`${m}.`:"Connected to nothing yet.",l.length>0?`Trouble: ${l.map(o=>o.message).join("; ")}.`:"Nothing about it is broken."]),proposals:R(t,O(l).slice(0,3)),...i||v?{grounded:!0}:{}})}{let n=w.split(/[^\p{L}\p{N}]+/u).filter(e=>e.length>0&&!an.has(e));if(n.length>0){let e=nn(t,n.join(" "),{...g.principal?{principal:g.principal}:{},...g.selection?{from:g.selection}:{},...c.today??g.today?{today:c.today??g.today}:{},limit:6}),s=e.hits.filter(i=>i.about==="node");if(s.length>0){let i=Q(s.flatMap(a=>{let l=t.graph.getNode(a.id);return l?[l]:[]}),a=>t.schema.tryDefinition(a)),r=s.map(a=>`${a.label}${i.has(a.id)?` \xB7 ${i.get(a.id)}`:""} (${D(t.schema.tryDefinition(a.kind),a.kind)}${a.why.field==="label"?"":`, ${a.why.reading.toLowerCase()}: ${a.why.fragment}`})`);return{say:`${e.total===1?"One thing is":`${gn(e.total)} things are`} called \u201C${e.words}\u201D \u2014 ${r.join("; ")}${e.total>s.length?`; and ${e.total-s.length} more`:""}.`,proposals:[],picks:s}}}}let on=t.schema.kinds.filter(n=>!t.modules.disabledKinds.has(n)).map(n=>{let e=Y(t.schema,n);return`${t.graph.nodesOfKind(n).length} ${e}`}).join(", ");return{say:E([`This graph holds ${on}.`,"Ask about anything by name, ask what's wrong, or say a change in its own words \u2014",`like "${t.allMutations()[0]?.title??"an action"}".`]),proposals:[],unsure:!0}}}function ln(c){return c.flatMap(t=>{let u=t.repairs.find(g=>!g.missing?.length);return u?[{mutation:u.mutation,args:{...u.args},why:t.message}]:[]})}var cn=["No","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"],gn=c=>cn[c]??String(c);function un(c,t,u,g,w=""){switch(c.control){case"node":return t.find(p=>c.kinds.includes("*")||c.kinds.includes(p.kind))?.id;case"text":return u;case"date":{let h=g??new Date().toISOString().slice(0,10);return c.time?`${h}T09:00`:h}case"choice":{let h=new Set(w.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)),p=(c.options??[]).filter(v=>v.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).every(S=>h.has(S)));return p.length===1?p[0]:void 0}default:return}}function bn(c){return async(t,u,g={})=>(await import("./chunk.RT3XFR6E.js")).answerWithModel(c,t,u,g)}var hn=/^\d{4}-\d{2}-\d{2}$/,fn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function yn(c){let[t,u,g]=c.split("-").map(Number);return`${g} ${fn[u-1]??""} ${t}`}export{wn as a,ln as b,bn as c};