graview 0.1.25 → 0.1.27

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 (113) hide show
  1. package/dist/preview/chunk.4JXWQO6Y.js +1 -0
  2. package/dist/preview/chunk.4R7LDCDO.js +1 -0
  3. package/dist/preview/chunk.4W24TPMR.js +1 -0
  4. package/dist/preview/{chunk.SSOTDXRS.js → chunk.5BN2ARQ2.js} +1 -1
  5. package/dist/preview/chunk.6LJ66MB7.js +1 -0
  6. package/dist/preview/chunk.6R4EI47C.js +1 -0
  7. package/dist/preview/{chunk.JIXW4WIO.js → chunk.7CO6VP6F.js} +1 -1
  8. package/dist/preview/chunk.7QTBDACG.js +1 -0
  9. package/dist/preview/chunk.7SVIRYBB.js +1 -0
  10. package/dist/preview/chunk.7THQFY52.js +1 -0
  11. package/dist/preview/chunk.AS35X6KA.js +1 -0
  12. package/dist/preview/{chunk.UOYH2DFX.js → chunk.ATLUMYAJ.js} +2 -2
  13. package/dist/preview/{chunk.6DU4XN2F.js → chunk.CW7BMVBG.js} +1 -1
  14. package/dist/preview/chunk.DG2UE7PJ.js +1 -0
  15. package/dist/preview/chunk.DG2WKNMX.js +1 -0
  16. package/dist/preview/chunk.DQ5OWYLQ.js +1 -0
  17. package/dist/preview/chunk.DY2FFBWF.js +1 -0
  18. package/dist/preview/chunk.E3SZ7T75.js +1 -0
  19. package/dist/preview/chunk.EVTZE2OZ.js +1 -0
  20. package/dist/preview/chunk.FS5K4AVA.js +8 -0
  21. package/dist/preview/chunk.FTBKJ5RZ.js +16 -0
  22. package/dist/preview/chunk.GHMICJIB.js +1 -0
  23. package/dist/preview/chunk.HO6JR7VY.js +1 -0
  24. package/dist/preview/{chunk.DEZEXD24.js → chunk.HPD3DSTP.js} +1 -1
  25. package/dist/preview/chunk.I5KD54S6.js +1 -0
  26. package/dist/preview/chunk.IXVSJJQH.js +20 -0
  27. package/dist/preview/chunk.IZDKEFPJ.js +1 -0
  28. package/dist/preview/chunk.J36GTQTV.js +1 -0
  29. package/dist/preview/chunk.KAKX5TZN.js +3 -0
  30. package/dist/preview/chunk.LHAAZQNQ.js +19 -0
  31. package/dist/preview/chunk.LQZ2VQWN.js +107 -0
  32. package/dist/preview/chunk.MHJJEGQO.js +1 -0
  33. package/dist/preview/chunk.MNPNW4BQ.js +1 -0
  34. package/dist/preview/chunk.NKIFVPS3.js +1 -0
  35. package/dist/preview/chunk.NQNQPPPM.js +1 -0
  36. package/dist/preview/{chunk.6UL2JUEH.js → chunk.OA5BVKJH.js} +1 -1
  37. package/dist/preview/chunk.OHGJ5BZ4.js +2 -0
  38. package/dist/preview/chunk.OYULDOQP.js +1 -0
  39. package/dist/preview/{chunk.PY42PBMB.js → chunk.PHY3AH3L.js} +1 -1
  40. package/dist/preview/chunk.Q7544RCB.js +1 -0
  41. package/dist/preview/{chunk.JCZH55RX.js → chunk.QZWN46V6.js} +1 -1
  42. package/dist/preview/chunk.RUC4HFVC.js +1 -0
  43. package/dist/preview/chunk.S5JWZIVE.js +1 -0
  44. package/dist/preview/chunk.SHDYLMZE.js +2 -0
  45. package/dist/preview/chunk.T2EZ5MTH.js +1 -0
  46. package/dist/preview/chunk.TMPV4HLQ.js +1 -0
  47. package/dist/preview/{chunk.HQX5FGYT.js → chunk.TX2GOL65.js} +2 -2
  48. package/dist/preview/{chunk.S24R4MRK.js → chunk.U5ZUXGWM.js} +3 -3
  49. package/dist/preview/chunk.UMMN5Z6V.js +1 -0
  50. package/dist/preview/chunk.UPGDSOBY.js +1 -0
  51. package/dist/preview/chunk.V57P4LIZ.js +1 -0
  52. package/dist/preview/{chunk.YZZGD5OY.js → chunk.VD6FJ6KJ.js} +1 -1
  53. package/dist/preview/{chunk.B57EIGTS.js → chunk.VFICMX5G.js} +1 -1
  54. package/dist/preview/chunk.VMD4PDYJ.js +1 -0
  55. package/dist/preview/chunk.VMEX2KZ4.js +8 -0
  56. package/dist/preview/chunk.XDHBV5K5.js +1 -0
  57. package/dist/preview/chunk.YO7UFBJP.js +1 -0
  58. package/dist/preview/chunk.YV2RTNPU.js +6 -0
  59. package/dist/preview/chunk.ZD5HGRPR.js +1 -0
  60. package/dist/preview/chunk.ZKM4P7US.js +1 -0
  61. package/dist/preview/chunk.ZMMMKTAG.js +1 -0
  62. package/dist/preview/chunk.ZNIJONZN.js +1 -0
  63. package/dist/preview/page.js +6 -6
  64. package/package.json +6 -6
  65. package/dist/preview/chunk.2AJMM7JG.js +0 -1
  66. package/dist/preview/chunk.2WFEFZAW.js +0 -1
  67. package/dist/preview/chunk.2YVXTTC2.js +0 -1
  68. package/dist/preview/chunk.6KJSFIO7.js +0 -1
  69. package/dist/preview/chunk.6OBXKKB5.js +0 -20
  70. package/dist/preview/chunk.6WFN4C46.js +0 -107
  71. package/dist/preview/chunk.7BAUPTMY.js +0 -1
  72. package/dist/preview/chunk.A4SJ7EEY.js +0 -1
  73. package/dist/preview/chunk.ACKTGTOT.js +0 -1
  74. package/dist/preview/chunk.BJ2Y5F66.js +0 -1
  75. package/dist/preview/chunk.BYUQOV3O.js +0 -1
  76. package/dist/preview/chunk.C5N4RTPF.js +0 -1
  77. package/dist/preview/chunk.CFL2B2Z5.js +0 -1
  78. package/dist/preview/chunk.DJ72CUS7.js +0 -1
  79. package/dist/preview/chunk.DSZ3I557.js +0 -2
  80. package/dist/preview/chunk.EA4BZKPG.js +0 -1
  81. package/dist/preview/chunk.EKZWX6NG.js +0 -1
  82. package/dist/preview/chunk.F26676IW.js +0 -1
  83. package/dist/preview/chunk.F2KDFGHR.js +0 -1
  84. package/dist/preview/chunk.FWV4XAZA.js +0 -1
  85. package/dist/preview/chunk.G3BOZHKR.js +0 -1
  86. package/dist/preview/chunk.H4LHHT56.js +0 -8
  87. package/dist/preview/chunk.I5ELK6JF.js +0 -1
  88. package/dist/preview/chunk.I6T3FDQS.js +0 -1
  89. package/dist/preview/chunk.IB6PGEU7.js +0 -1
  90. package/dist/preview/chunk.JEMQBV6K.js +0 -1
  91. package/dist/preview/chunk.JW3E4SAC.js +0 -1
  92. package/dist/preview/chunk.KUTTVYOB.js +0 -16
  93. package/dist/preview/chunk.LHFEOEYY.js +0 -1
  94. package/dist/preview/chunk.MJ67MK4R.js +0 -1
  95. package/dist/preview/chunk.ORJ3T4IW.js +0 -2
  96. package/dist/preview/chunk.Q5WEOX3Q.js +0 -1
  97. package/dist/preview/chunk.QOYC424P.js +0 -3
  98. package/dist/preview/chunk.R6F3YMRK.js +0 -6
  99. package/dist/preview/chunk.RAE4M3KQ.js +0 -8
  100. package/dist/preview/chunk.RUFAVEXB.js +0 -1
  101. package/dist/preview/chunk.RVEMN5WU.js +0 -1
  102. package/dist/preview/chunk.S56LSUHV.js +0 -1
  103. package/dist/preview/chunk.T6KID3WO.js +0 -1
  104. package/dist/preview/chunk.TAOT74FR.js +0 -1
  105. package/dist/preview/chunk.TTODVIXW.js +0 -1
  106. package/dist/preview/chunk.U6BWYBPM.js +0 -19
  107. package/dist/preview/chunk.US4KIJSW.js +0 -1
  108. package/dist/preview/chunk.WX5CJ7PI.js +0 -1
  109. package/dist/preview/chunk.WXO3XUNW.js +0 -1
  110. package/dist/preview/chunk.ZJVIH6IF.js +0 -1
  111. package/dist/preview/chunk.ZRVDIVYY.js +0 -1
  112. package/dist/preview/chunk.ZV7ZFH2S.js +0 -1
  113. /package/dist/preview/{chunk.WWRWXFYR.js → chunk.WVUJXDXZ.js} +0 -0
@@ -1,6 +0,0 @@
1
- import{a as k}from"./chunk.G4JJXA63.js";import{a as Q}from"./chunk.WX5CJ7PI.js";import"./chunk.Q5WEOX3Q.js";import"./chunk.I6T3FDQS.js";import"./chunk.DJ72CUS7.js";import{e as P}from"./chunk.A4SJ7EEY.js";import"./chunk.6KJSFIO7.js";import"./chunk.DEZEXD24.js";import{c as G}from"./chunk.YZZGD5OY.js";import"./chunk.DSZ3I557.js";import{Ib as C,Jb as J,Kb as K,Lb as X,Vb as Y,ha as z,ia as H}from"./chunk.RAE4M3KQ.js";import"./chunk.AJZBJBMO.js";var L=e=>"failed"in e;function ue(e,n){let r=e.schema.kinds,t=e.policy?.sees;if(!t?.length||H(n))return{kinds:r};let s=z(n).roles??[],i=new Set(t.filter(o=>o.roles==="*"||s.some(a=>o.roles.includes(a))).flatMap(o=>o.kinds));return{kinds:r.filter(o=>i.has(o))}}function O(e,n){if(!n)return e;let r=new Set(n.kinds.filter(i=>e.tryDefinition(i)!==void 0));if(r.size===e.kinds.length)return e;let t=new Map,s=i=>{if(r.has(i)){if(!t.has(i)){let o=e.tryDefinition(i),a=Object.fromEntries(Object.entries(o?.edges??{}).flatMap(([l,d])=>{if(d.to==="*")return[[l,d]];let c=d.to.filter(u=>r.has(u));return c.length>0?[[l,{...d,to:c}]]:[]}));t.set(i,{...o,edges:a})}return t.get(i)}};return{...e,definitions:e.definitions.filter(i=>r.has(i.kind)),kinds:e.kinds.filter(i=>r.has(i)),tryDefinition:s,definition:i=>{let o=s(i);if(!o)throw new Error(`Unknown node kind "${i}"`);return o}}}var fe=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),y=e=>fe(e).replace(/[-_]+/g," ").trim();function j(e){let n=[];for(let t of e.kinds){let s=e.tryDefinition(t);if(!s)continue;let i=s.display?.labels??{},o=Object.entries(s.fields?.shape??{}).filter(([d])=>d!=="id"&&d!=="kind").map(([d,c])=>{let u=P(c);return{name:d,type:u?.type,...u?.options?{options:u.options}:{},words:(i[d]??y(d)).toLowerCase()}}),a=Object.entries(s.edges??{}).map(([d,c])=>({name:d,from:t,to:c.to==="*"?e.kinds.filter(u=>u!==t):c.to,words:y(d)})),l=(s.plural??`${y(t)}s`).toLowerCase();n.push({kind:t,plural:l,noun:(s.noun??y(t)).toLowerCase(),fields:o,roles:s.fieldRoles??{},edges:a})}let r=new Map(n.map(t=>[t.kind,t]));return{schema:e,kinds:n,info:t=>r.get(t)}}var $=(e,n)=>n===void 0?void 0:e.fields.find(r=>r.name===n),A=e=>e?.type==="date"||e?.type==="datetime",N=e=>e?.type==="number"||e?.type==="integer",re=e=>` ${e.toLowerCase().replace(/[“”"’‘]/g,"'").replace(/[^\p{L}\p{N}' -]+/gu," ").replace(/\s+/g," ").trim()} `,E=(e,n)=>e.includes(` ${n} `),v=e=>e.endsWith("ies")?`${e.slice(0,-3)}y`:e.endsWith("ses")?e.slice(0,-2):e.endsWith("s")?e.slice(0,-1):e;function pe(e,n){let r=[];for(let t of n.kinds){let s=new Set([t.plural,t.noun,`${t.noun}s`,y(t.kind),`${y(t.kind)}s`]),i=-1;for(let o of s){let a=e.indexOf(` ${o} `);a>=0&&(i<0||a<i)&&(i=a)}i>=0&&r.push({info:t,at:i})}return r.sort((t,s)=>t.at-s.at).map(t=>t.info)}function x(e,n,r){let t=n.trim().toLowerCase();if(t.length===0)return;let s=e.fields.filter(i=>!r||r(i));return s.find(i=>i.words===t||y(i.name)===t||i.name.toLowerCase()===t)??s.find(i=>i.words===v(t)||y(i.name)===v(t))??s.find(i=>t.split(" ").some(o=>o.length>2&&(i.words.split(" ").includes(o)||i.words.split(" ").includes(v(o)))))}function se(e,n,r){let t=n.trim().toLowerCase();if(t.length!==0)return e.edges.find(s=>s.words===t||s.name.toLowerCase()===t)??e.edges.find(s=>s.to.some(i=>{let o=r.info(i);return o!==void 0&&(o.noun===v(t)||o.plural===t||y(i)===v(t))}))??e.edges.find(s=>t.split(" ").some(i=>i.length>2&&s.words.split(" ").includes(i)))}function U(e){return/ (?:grouped |group |split |sorted |organi[sz]ed )?by ([\p{L}\p{N}' -]+?)(?= (?:and|with|for|in|on|only|where|from|this|that|as|sorted|grouped) |\s*$)/u.exec(e)?.[1]?.trim()}var ge=/\bwho\b.*\b(covers?|cover|tends?|owns?|handles?|does|works? on|looks? after|is on|is assigned|staffs?|runs?)\b|\bcoverage\b|\bmatrix\b|\bwho covers\b/,me=/\bcalendar\b|\bmonth\b|\bagenda\b|\bschedule\b|\bdue\b|\bdeadlines?\b|\bdates?\b|\bwhen\b/,ye=/\btimeline\b|\bover time\b|\bgantt\b|\bspans?\b|\bweek\b/,he=/\bboard\b|\bkanban\b|\bcolumns?\b|\bpipeline\b|\bstages?\b|\bstatus\b/,be=/\blaid out\b|\blayout\b|\bseating\b|\bwhere (?:they|it|each) (?:sits?|lies?|stands?)\b|\bfloor\b/,we=/\bplan\b|\bmap\b|\bregions?\b/,ke=/\blist\b|\btable\b|\bgroup(?:ed)? by\b|\bsort(?:ed)? by\b|\bonly\b|\bjust the\b/;function $e(e){let n=[];return/\blist\b|\btable\b/.test(e)&&n.push("blocks"),ge.test(e)&&n.push("coverage"),be.test(e)&&n.push("board"),(/\bfloor plan\b/.test(e)||we.test(e))&&n.push("plan"),ye.test(e)&&n.push("timeline"),me.test(e)&&n.push("calendar"),he.test(e)&&n.push("columns"),ke.test(e)&&!n.includes("blocks")&&n.push("blocks"),n.length===0&&U(e)&&n.push("columns"),n}var oe=e=>{let n=r=>r?` and not ${r}`:"";if(/\boverdue\b|\blate\b|\bpast due\b/.test(e))return{cond:(r,t)=>`days(today(), ${r}) < 0${n(t)}`,says:r=>`overdue by ${r.words}`};if(/\btoday\b/.test(e))return{range:"day",cond:r=>`days(today(), ${r}) == 0`,says:r=>`with ${r.words} today`};if(/\bthis week\b|\bnext 7 days\b|\bnext week\b/.test(e))return{range:"week",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 6`,says:r=>`with ${r.words} in the next week`};if(/\bthis month\b|\bnext 30 days\b|\bnext month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 30`,says:r=>`with ${r.words} in the next month`};if(/\blast month\b|\bpast month\b/.test(e))return{range:"month",cond:r=>`days(today(), ${r}) >= -30 and days(today(), ${r}) <= 0`,says:r=>`with ${r.words} in the last month`};if(/\bthis year\b/.test(e))return{range:"year",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 365`,says:r=>`with ${r.words} in the next year`};if(/\bquarter\b/.test(e))return{range:"quarter",cond:r=>`days(today(), ${r}) >= 0 and days(today(), ${r}) <= 91`,says:r=>`with ${r.words} in the next quarter`}},_=e=>{if(/\bagenda\b|\bin order\b/.test(e))return"agenda";if(/\btoday\b|\bday\b/.test(e))return"day";if(/\bweek\b/.test(e))return"week";if(/\bquarter\b/.test(e))return"quarter";if(/\byears\b/.test(e))return"years";if(/\byear\b/.test(e))return"year";if(/\bmonth\b/.test(e))return"month"},Z=/^(user|person|people|member|staff|gardener|volunteer|owner|agent|employee|worker|team|player|customer|client|contact|party|attendee|guest)s?$/,I=class extends Error{},h=e=>{throw new I(e)};function Se(e,n){let r=e.fields.filter(i=>i.type==="enum");if(n){let i=x(e,n);if(i&&i.type==="enum")return i;i&&h(`${e.plural}' ${i.words} is not a choice, so it has no columns`)}let t=$(e,e.roles.status??e.roles.column);if(t?.type==="enum")return t;let s=r.find(i=>/^(status|stage|state|phase)$/.test(i.name));return s||(r[0]?r[0]:h(`${e.plural} have no choice field to put in columns`))}function ee(e,n){let r=e.fields.filter(A),t=l=>{let d=$(e,e.roles[l]);return A(d)?d:void 0},i=r.find(l=>E(n,l.words)||E(n,y(l.name)))??t("start")??r.find(l=>/^(due|date|on|at|start|starts|begins|from|sown|when)/i.test(l.name))??r[0];if(!i)return h(`no date field on ${e.plural}`);let o=t("end")??r.find(l=>l!==i&&/^(end|ends|until|to|finish|finished|harvested|due|closes|through)/i.test(l.name)),a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));return{start:i,...o&&o!==i?{end:o}:{},...a?{done:a}:{}}}function ie(e){let n=$(e,e.roles.start),r=$(e,e.roles.end),t=$(e,e.roles.column??e.roles.day??e.roles.columns);if(N(n)&&N(r)&&t?.type==="enum")return{start:n,end:r,column:t}}function De(e,n,r,t){let s=[];for(let o of e.kinds)for(let a of o.edges)for(let l of a.to){let d=e.info(l);if(!d||d.kind===o.kind)continue;let c=0;n.includes(o)&&(c+=4),n.includes(d)&&(c+=4),(Z.test(d.kind)||Z.test(d.noun))&&(c+=3),t&&(a.words.includes(t)||d.noun===v(t))&&(c+=5),a.words.split(" ").some(u=>u.length>2&&r.includes(` ${u}`))&&(c+=2),s.push({rows:o,across:d,link:a,score:c})}let i=s.sort((o,a)=>a.score-o.score)[0];return i||h(n[0]?`${n[0].plural} are joined to nothing else, so there is no who-covers-what to draw`:"nothing here is joined to anything else, so there is no who-covers-what to draw")}function ae(e,n,r,t,s){let i=U(t);switch(e){case"columns":{if(i){let o=x(n,i);if(!o||o.type!=="enum"){let a=se(n,i,r);if(a){let l=r.info(a.to[0]);return{lens:"coverage",kind:n.kind,across:l.kind,link:a.name}}}}return{lens:"columns",kind:n.kind,column:Se(n,i).name}}case"calendar":{let o=ee(n,t),a=_(t);return{lens:"calendar",kind:n.kind,start:o.start.name,...o.end?{end:o.end.name}:{},...o.done?{done:o.done.name}:{},...a?{range:a}:{}}}case"timeline":{let o=ie(n);if(o&&!/\bdates?\b|\bdue\b|\bdeadlines?\b|\bmonths?\b|\byears?\b/.test(t))return{lens:"timeline",kind:n.kind,start:o.start.name,end:o.end.name,column:o.column.name};let a=ee(n,t);return{lens:"calendar",kind:n.kind,start:a.start.name,...a.end?{end:a.end.name}:{},...a.done?{done:a.done.name}:{},range:_(t)??"quarter"}}case"coverage":{let o=De(r,s,t,i);return{lens:"coverage",kind:o.rows.kind,across:o.across.kind,link:o.link.name}}case"board":{let o=$(n,n.roles.x)??n.fields.find(c=>c.name==="x"),a=$(n,n.roles.y)??n.fields.find(c=>c.name==="y");if(!N(o)||!N(a))return h(`${n.plural} have no x and y to be laid out by`);let d=r.kinds.flatMap(c=>c.edges.filter(u=>u.to.includes(n.kind)&&c.kind!==n.kind))[0]??n.edges[0];return d?{lens:"board",kind:n.kind,x:o.name,y:a.name,fill:d.name,...d.from!==n.kind?{fillFrom:"occupant"}:{}}:h(`nothing is joined to ${n.plural} to fill them`)}case"plan":{let o=$(n,n.roles.outline)??n.fields.find(a=>a.name==="outline");return o?{lens:"plan",kind:n.kind,outline:o.name}:h(`${n.plural} have no outline to draw a plan from`)}case"blocks":{let o={lens:"blocks",kind:n.kind,as:/\bcards?\b/.test(t)?"card":"row"},a=/ group(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|sorted|with)|\s*$)/u.exec(t)?.[1]??(i&&!/ sort(?:ed)? by /.test(t)?i:void 0);if(a){let c=x(n,a);if(!c||c.type!=="enum")return h(c?`${n.plural}' ${c.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${a} to group by`);o.group=c.name}let l=/ sort(?:ed)? by ([\p{L}\p{N} -]+?)(?= (?:and|only|grouped|with)|\s*$)/u.exec(t)?.[1];if(l){let c=x(n,l);if(!c)return h(`${n.plural} have nothing called ${l} to sort by`);o.sort={by:c.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}let d=M(n,t);return d.length>0&&(o.where=d),o}}}function M(e,n){let r=[],t=oe(n);if(t){let s=e.fields.filter(A),i=$(e,e.roles.start),o=s.find(l=>E(n,l.words))??(A(i)?i:void 0)??s[0];(!o||!A(o))&&h(`no date field on ${e.plural}`);let a=e.fields.find(l=>l.type==="boolean"&&/^(done|finished|complete|completed|closed)$/.test(l.name));r.push({expr:t.cond(o.name,/\boverdue\b|\blate\b|\bpast due\b/.test(n)?a?.name:void 0),says:t.says(o)})}if(/\bonly\b|\bjust\b|\bthat are\b|\bwhich are\b/.test(n)){for(let s of e.fields){if(s.type!=="enum")continue;let i=s.options?.find(o=>E(n,o.toLowerCase())||E(n,y(o)));i&&r.push({expr:`${s.name} == '${i.replace(/'/g,"")}'`,says:`that are ${y(i)}`})}if(/\bnot done\b|\bundone\b|\bunfinished\b|\bopen ones\b|\bstill to do\b/.test(n)){let s=e.fields.find(i=>i.type==="boolean"&&/^(done|finished|complete|completed)$/.test(i.name));s&&r.push({expr:`not ${s.name}`,says:`not ${s.words}`})}}return r}var B={columns:"A board",calendar:"A calendar",timeline:"A timeline",coverage:"A grid",board:"A layout",plan:"A plan",blocks:"A list",reach:"A picture"};function Re(e,n){let r=n.info(e.kind),t=s=>s?$(r,s)?.words??y(s):"";switch(e.lens){case"columns":return{title:`${k(r.plural)} by ${t(e.column)}`,detail:`of ${r.plural} by ${t(e.column)}`};case"calendar":{let s=e.range??"month";if(s==="agenda")return{title:`${k(r.plural)} in date order`,detail:`of ${r.plural} in order of ${t(e.start)}`};let i=s==="years"?"year":s;return{title:`${k(r.plural)} by ${i}`,detail:`of ${r.plural} by ${t(e.start)}, a ${i} at a time`}}case"timeline":return{title:`${k(r.plural)} over the ${t(e.column)}`,detail:`of ${r.plural} from ${t(e.start)} to ${t(e.end)}, by ${t(e.column)}`};case"coverage":{let s=n.info(e.across);return{title:`${k(r.plural)} by ${s.noun}`,detail:`of which ${s.noun} covers which ${r.noun}`}}case"board":return{title:`${k(r.plural)} where they stand`,detail:`of ${r.plural} where they stand`};case"plan":return{title:`${k(r.plural)} on a plan`,detail:`of ${r.plural}`};default:{let s=[e.where?.map(i=>i.says).join(" and "),e.group?`by ${t(e.group)}`:void 0,e.sort?`in order of ${t(e.sort.by)}`:void 0].filter(i=>!!i);return{title:[k(r.plural),...s].join(" "),detail:[`of ${r.plural}`,...s].join(" ")}}}}function Ae(e,n){let r={title:n,on:e.kind};switch(e.lens){case"columns":return{name:"columns",...r,bindings:{[e.kind]:{column:e.column}}};case"calendar":return{name:"calendar",...r,bindings:{[e.kind]:{start:e.start,...e.end?{end:e.end}:{},...e.done?{done:e.done}:{}}},...e.range?{options:{range:e.range}}:{}};case"timeline":return{name:"timeline",...r,bindings:{[e.kind]:{start:e.start,end:e.end,column:e.column}}};case"coverage":return{name:"coverage",...r,bindings:{rows:{kind:e.kind},columns:{kind:e.across},link:{edge:e.link}}};case"board":return{name:"board",...r,bindings:{slots:{kind:e.kind},x:{field:e.x,on:"slots"},y:{field:e.y,on:"slots"},fill:{edge:e.fill}},...e.fillFrom?{options:{fillFrom:e.fillFrom}}:{}};case"plan":return{name:"plan",...r,bindings:{regions:{kind:e.kind},outline:{field:e.outline,on:"regions"}}};default:{let t=e.where?.length?` where ${e.where.map(i=>e.where.length>1?`(${i.expr})`:i.expr).join(" and ")}`:"",s={list:`all('${e.kind}')${t}`,as:e.as??"row"};return e.group&&(s.group=e.group),e.sort&&(s.sort=e.sort.direction?{by:e.sort.by,direction:e.sort.direction}:e.sort.by),s.empty="Nothing here yet.",{name:"blocks",...r,options:{blocks:[s]}}}}}function q(e,n){let r=s=>s.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,""),t=new Set(["home","overview",...Y(n).map(s=>s.slug),...(n.lenses??[]).flatMap(s=>s.title?[r(s.title)]:[])]);if(!t.has(r(e)))return e;for(let s=2;;s++)if(!t.has(r(`${e} ${s}`)))return`${e} ${s}`}var ne={title:[],headline:[],text:["tone"],figure:["as","currency","label"],list:["sort","limit","group","empty","as"],progress:["label"],group:["direction"],when:["show"],divider:[]};function Ee(e,n){if(!Array.isArray(n)||n.length===0)return"it has no blocks to draw";if(n.length>40)return"it has more blocks than a place draws";let r=(o,a)=>{if(typeof o!="string"||o.trim()==="")return`its ${a} says nothing`;try{return G(o)}catch(l){return`its ${a} does not read: ${l instanceof Error?l.message.replace(/ \(at character.*$/,""):String(l)}`}},t=o=>{if(o.t==="where")return t(o.set);if(o.t==="call"&&o.fn==="all"){let a=o.args[0];return a?.t==="lit"&&typeof a.value=="string"?e.info(a.value)??null:void 0}},s=(o,a)=>{switch(o.t){case"lit":return;case"ident":return a&&!a.fields.some(l=>l.name===o.name)&&!a.edges.some(l=>l.name===o.name)?`${a.plural} have nothing called ${o.name}`:void 0;case"member":return s(o.object,a);case"list":return o.items.map(l=>s(l,a)).find(Boolean);case"unary":return s(o.operand,a);case"binary":return s(o.left,a)??s(o.right,a);case"where":{let l=t(o.set);return l===null?"Nothing by that name here":s(o.set,a)??s(o.filter,l??void 0)}case"call":return o.fn==="all"?t(o)===null?"Nothing by that name here":void 0:o.args.map(l=>s(l,a)).find(Boolean)}},i=(o,a)=>{if(a>4)return"its blocks nest deeper than a place draws";for(let l of o){if(!w(l))return"a block is not an object";let d=Object.keys(ne).find(p=>p in l);if(!d)return`"${Object.keys(l)[0]??""}" is not a block a place draws`;let c=Object.keys(l).find(p=>p!==d&&p!=="key"&&!ne[d].includes(p));if(c)return`a ${d} block takes no "${c}"`;let u=l[d];if(d==="list"||d==="figure"||d==="when"){if(d==="figure"&&u===!0)continue;let p=r(u,d);if(typeof p=="string")return p;let m=s(p,void 0);if(m)return m;if(d==="list"){let f=t(p);if(f==null)return f===null?"Nothing by that name here":"its list does not say which records it lists, like all('task')";for(let g of["group","sort"]){let b=l[g],S=typeof b=="string"?b:w(b)&&typeof b.by=="string"?b.by:void 0;if(b===void 0)continue;let D=S?f.fields.find(ce=>ce.name===S):void 0;if(!D)return`${f.plural} have nothing called ${String(S??b)} to ${g} by`;if(g==="group"&&D.type!=="enum")return`${f.plural}' ${D.words} is not a choice, so they cannot be grouped by it`}}if(d==="when"){let f=l.show;if(!Array.isArray(f))return"a when block shows a list of blocks";let g=i(f,a+1);if(g)return g}}else if(d==="group"){if(!Array.isArray(u))return"a group block holds a list of blocks";let p=i(u,a+1);if(p)return p}else{if(d!=="divider"&&typeof u!="string")return`a ${d} block says words`;if(typeof u=="string")for(let p of u.matchAll(/\{([^{}]*)\}/g)){let m=p[1].split(/\|(?![|])/)[0],f=r(m,`${d}'s braces`);if(typeof f=="string")return f;let g=s(f,void 0);if(g)return g}}}};return i(n,1)}function T(e,n,r){let t=O(e.schema,r),s=f=>({ok:!1,failed:`Couldn't draw that: ${f.replace(/\.$/,"")}.`});if(!K(n.name)||n.name==="reach")return s(`"${String(n.name)}" is not a picture the seat can draw; it draws ${J.filter(f=>f!=="reach").join(", ")}`);if(typeof n.title!="string"||n.title.trim().length===0||n.title.length>80)return s("it needs a title of a few words");if(typeof n.on!="string"||!t.tryDefinition(n.on))return s("Nothing by that name here");let i=C[n.name],o=n.bindings??{};if(i.binds==="fields")for(let[f,g]of Object.entries(o)){if(!t.tryDefinition(f))return s("Nothing by that name here");let b=Object.keys(t.tryDefinition(f).fields?.shape??{});for(let[S,D]of Object.entries(g??{}))if(typeof D!="string"||!b.includes(D))return s(`${y(f)} has no field "${String(D)}" for its ${S}`);for(let S of i.requiredRoles)if(!(S in(g??{})))return s(`a ${n.name} needs ${y(f)}'s ${S}`)}else if(i.binds==="entities")for(let f of i.requiredRoles){let g=o[f];if(!g)return s(`a ${n.name} needs its ${f}`);if(typeof g.kind=="string"&&!t.tryDefinition(g.kind))return s("Nothing by that name here")}let a={...e,schema:t,lenses:[...e.lenses??[],n]},l=a.lenses.length-1,d=X(a),c=`lenses.${l}`,u=d.findings.find(f=>f.path===c||f.path.startsWith(`${c}.`));if(u)return s(u.message.replace(/^"[^"]*" /,"it "));let p=d.undrawn.find(f=>f.index===l);if(p)return s(p.why);let m=d.drawn.find(f=>f.index===l);if(!m)return s("its bindings name something the app does not have");if(m.as==="overview")return s(`"${n.title}" is the scene's own address; give it another title`);if(n.name==="blocks"){let f=Ee(j(t),n.options?.blocks);if(f)return s(f)}return{ok:!0,drawn:m}}function F(e){return{op:"add-lens",title:e.title,lens:e.name,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}}}function ve(e){return{op:"remove-lens",title:e.title,on:e.on}}var w=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function de(e){let n=w(e)?e:{},r=String(n.lens??n.name??""),t=n.bindings,s=typeof n.on=="string"?n.on:w(t)&&C[r]?.binds==="fields"?Object.keys(t)[0]??"":"";return{name:r,title:typeof n.title=="string"?n.title.trim():"",on:s,...w(t)?{bindings:t}:{},...w(n.options)?{options:n.options}:{}}}function xe(e){let n=s=>w(e.bindings?.[s])?e.bindings[s]:{},r=s=>typeof s=="string"?s:void 0,t=n(e.on);switch(e.name){case"columns":return r(t.column)?{lens:"columns",kind:e.on,column:t.column}:void 0;case"calendar":{let s=r(e.options?.range);return r(t.start)?{lens:"calendar",kind:e.on,start:t.start,...r(t.end)?{end:t.end}:{},...r(t.done)?{done:t.done}:{},...s?{range:s}:{}}:void 0}case"timeline":return r(t.start)&&r(t.end)&&r(t.column)?{lens:"timeline",kind:e.on,start:t.start,end:t.end,column:t.column}:void 0;case"coverage":{let s=w(e.bindings?.columns)?r(e.bindings.columns.kind):void 0,i=w(e.bindings?.link)?r(e.bindings.link.edge):void 0;return s&&i?{lens:"coverage",kind:e.on,across:s,link:i}:void 0}case"blocks":{let s=e.options?.blocks;if(!Array.isArray(s)||s.length!==1||!w(s[0]))return;let i=s[0],o=new RegExp(`^all\\('${e.on}'\\)(?: where (.+))?$`).exec(String(i.list??""));if(!o)return;let a=i.sort;return{lens:"blocks",kind:e.on,as:i.as==="card"?"card":"row",...typeof i.group=="string"?{group:i.group}:{},...typeof a=="string"?{sort:{by:a}}:w(a)&&typeof a.by=="string"?{sort:{by:a.by,...a.direction==="desc"?{direction:"desc"}:{}}}:{},...o[1]?{where:[{expr:o[1],says:"as asked"}]}:{}}}default:return}}function V(e,n,r,t,s){let i=j(O(e.schema,t)).info(n.on),o=xe(n);return{title:n.title,said:`${B[n.name]??"A picture"} of ${i?.plural??y(n.on)}.`,kind:n.on,lens:n,drawn:r,edit:F(n),by:s,asks:[],...o?{recipe:o}:{}}}function te(e){return{title:e.title,said:e.said,lens:{title:e.lens.title,lens:e.lens.name,on:e.lens.on,...e.lens.bindings?{bindings:e.lens.bindings}:{},...e.lens.options?{options:e.lens.options}:{}},edit:e.edit,by:e.by,check:"It draws, and graview check would take it."}}function W(e,n,r,t,s){let i=Re(e,n),o=e.title??s??q(i.title,r.app),a=Ae(e,o),l=T(r.app,a,r.sight);return l.ok?{title:o,said:`${B[e.lens]} ${i.detail}.`,kind:e.kind,lens:a,drawn:l.drawn,edit:F(a),by:"template",asks:t,recipe:e}:{failed:l.failed,...r.lastGood?{lastGood:r.lastGood}:{}}}function Le(e,n,r,t){if(r.length>0)return r;let s=o=>{switch(e){case"columns":return o.fields.some(a=>a.type==="enum");case"calendar":return o.fields.some(A);case"timeline":return ie(o)!==void 0||o.fields.some(A);case"coverage":return o.edges.some(a=>a.to.some(l=>l!==o.kind));case"board":return o.fields.some(a=>a.name==="x")&&o.fields.some(a=>a.name==="y");case"plan":return o.fields.some(a=>a.name==="outline")||o.roles.outline!==void 0;default:return!0}};return[...n.kinds.filter(s)].sort((o,a)=>Number(a.fields.some(l=>E(t,l.words)))-Number(o.fields.some(l=>E(t,l.words))))}function Ie(e,n){let r=j(O(n.app.schema,n.sight)),t=re(e),s=$e(t);if(s.length===0)return;let i=pe(t,r),o;for(let a of s){let l=a==="coverage"?[i[0]??r.kinds[0]].filter(d=>!!d):Le(a,r,i,t);for(let d of l)try{let c=ae(a,d,r,t,i),u=W(c,r,n,[e]);if(!L(u))return u;o??=u.failed}catch(c){if(!(c instanceof I))throw c;o??=`Couldn't draw that: ${c.message}.`}l.length===0&&i.length===0&&(o??=`Couldn't draw that: nothing here has what ${B[a].toLowerCase()} needs.`)}return{failed:o??"Couldn't draw that: Nothing by that name here.",...n.lastGood?{lastGood:n.lastGood}:{}}}async function Oe(e,n){let r=n.lastGood?{lastGood:n.lastGood}:{};if(e.trim().length===0)return{failed:"Say what you would like to see, like \u201Ca board of tasks by status\u201D.",...r};let t=Ie(e,n);if(t&&!L(t))return t;if(!n.complete)return t??{failed:"Couldn't draw that: drawing freely needs AI, which isn't on here. Ask for a board, a calendar, a timeline, a list or who covers what.",...r};let s=await le(e,n,void 0);return L(s)&&t?t:s}async function je(e,n,r){let t={lastGood:e},s={...r,lastGood:e},i=j(O(r.app.schema,r.sight)),o=re(n),a=i.info(e.kind),l=[...e.asks,n];if(!a)return{failed:"Couldn't change that: Nothing by that name here.",...t};let d=e.recipe,c=/^ (?:call|name|title) (?:it|this)? ?(.+?) $/.exec(o)??/ (?:call|name) it (.+?) $/.exec(o);try{if(c){let m=n.replace(/^.*?\b(?:call|name|title)\b\s*(?:it|this)?\s*/i,"").replace(/^["“']|["”']$/g,"").trim();if(m.length===0)return{failed:"Couldn't change that: say what to call it.",...t};let f={...e.lens,title:q(m,r.app)},g=T(r.app,f,r.sight);return g.ok?{...e,title:f.title,lens:f,drawn:g.drawn,edit:F(f),asks:l,...d?{recipe:{...d,title:f.title}}:{}}:{failed:g.failed,...t}}let p=/ as (?:a |an )?(board|kanban|calendar|timeline|list|table|cards|rows|grid|plan|layout)\b/.exec(o);if(p){let m=p[1]==="board"||p[1]==="kanban"?"columns":p[1]==="calendar"?"calendar":p[1]==="timeline"?"timeline":p[1]==="grid"?"coverage":p[1]==="plan"?"plan":p[1]==="layout"?"board":"blocks",f=ae(m,a,i,o,[a]),g=p[1]==="cards"?"card":p[1]==="rows"?"row":void 0,b=m==="blocks"&&d?.lens==="blocks"?{...d,...g?{as:g}:{}}:m==="blocks"&&d?.lens==="columns"?{...f,group:d.column,...g?{as:g}:{}}:f;return W(R(b),i,s,l)}if(d){let m=Te(d,a,i,o);if(m)return W(m,i,s,l)}}catch(p){if(!(p instanceof I))throw p;return{failed:`Couldn't change that: ${p.message}.`,...t}}if(!r.complete)return{failed:"Couldn't change that: changing it freely needs AI, which isn't on here. Try \u201Cgroup by status\u201D, \u201Conly this month\u201D or \u201Cas a calendar\u201D.",...t};let u=await le(n,s,e);return L(u)?u:{...u,asks:l}}var R=e=>{let{title:n,...r}=e;return r};function Te(e,n,r,t){let s=/ (?:group(?:ed)?|split|organi[sz]ed?|put them|columns) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1]??(/^ by /.test(t)?U(t):void 0);if(s){let d=x(n,s);if(d?.type==="enum")return e.lens==="blocks"?{...R(e),group:d.name}:{lens:"columns",kind:e.kind,column:d.name};let c=se(n,s,r);return c?{lens:"coverage",kind:e.kind,across:c.to[0],link:c.name}:h(d?`${n.plural}' ${d.words} is not a choice, so they cannot be grouped by it`:`${n.plural} have nothing called ${s} to group by`)}let i=/ (?:sort(?:ed)?|order(?:ed)?) by ([\p{L}\p{N} -]+?)(?= (?:and|only|with)|\s*$)/u.exec(t)?.[1];if(i){let d=x(n,i);return d?{...e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}},sort:{by:d.name,.../\b(newest|latest|desc|descending|most)\b/.test(t)?{direction:"desc"}:{}}}:h(`${n.plural} have nothing called ${i} to sort by`)}if(/\b(?:all of them|everything|show all|clear the filter|no filter|without the filter)\b/.test(t)){if(e.lens!=="blocks"||!e.where)return h("it already shows all of them");let{where:d,...c}=R(e);return c}let o=oe(t);if(o&&e.lens==="calendar"&&o.range)return{...R(e),range:o.range};if(o&&e.lens==="calendar"&&!o.range)return{lens:"blocks",kind:e.kind,as:"row",sort:{by:e.start},where:M(n,t)};let a=M(n,t);if(a.length>0){let d=e.lens==="blocks"?R(e):{lens:"blocks",kind:e.kind,as:"row",...e.lens==="columns"?{group:e.column}:{}};return{...d,where:[...d.where??[],...a]}}let l=e.lens==="calendar"?_(t):void 0;if(l)return{...R(e),range:l}}function Ne(e){return e.kinds.map(n=>{let r=n.fields.map(i=>`${i.name} (${i.type??"value"}${i.options?`: ${i.options.join(" | ")}`:""})`).join(", "),t=n.edges.map(i=>`${i.name} \u2192 ${i.to.join(" | ")}`).join(", "),s=Object.entries(n.roles).map(([i,o])=>`${i}=${o}`).join(", ");return`- ${n.kind} ("${n.plural}"): ${r}${t?`; relations: ${t}`:""}${s?`; roles: ${s}`:""}`}).join(`
2
- `)}var Fe=['columns \u2014 a board, records in columns by one choice field: {"lens": "columns", "on": K, "bindings": {K: {"column": "<enum field>"}}}','calendar \u2014 records on a calendar by a date: {"lens": "calendar", "on": K, "bindings": {K: {"start": "<date field>", "end"?: "<date field>", "done"?: "<boolean field>"}}, "options": {"range"?: "day" | "week" | "month" | "quarter" | "year" | "agenda"}}','timeline \u2014 minutes of a day in columns: {"lens": "timeline", "on": K, "bindings": {K: {"start": "<number field>", "end": "<number field>", "column": "<enum field>"}}}','coverage \u2014 who covers what, a grid of two kinds joined by a relation: {"lens": "coverage", "on": K, "bindings": {"rows": {"kind": K}, "columns": {"kind": J}, "link": {"edge": "<relation of K to J>"}}}',`blocks \u2014 anything else, as blocks: {"lens": "blocks", "on": K, "options": {"blocks": [{"headline": "words"}, {"list": "all('K') where <condition>", "group"?: "<enum field>", "sort"?: "<field>" | {"by": "<field>", "direction": "desc"}, "as"?: "row" | "card", "empty"?: "words"}, {"figure": "count(all('K'))", "label": "words"}]}}. Conditions read a record's own fields: status == 'open', not done, days(today(), due) <= 7.`].join(`
3
- `);function Ce(e,n,r){return["You draw a view of an app's data as JSON \u2014 never code. The app's kinds, their fields (with types) and relations:",Ne(n),"","The lenses you may use (prefer the first four; use blocks only when none of them fits):",Fe,"",r?`The view on screen now:
4
- ${JSON.stringify(r.lens)}
5
- Change it as asked, and keep everything not asked about.`:"",`Asked: ${JSON.stringify(e)}`,'Answer with ONE JSON object: {"title": "<a few words, like Deliverables by status>", "lens": \u2026, "on": \u2026, "bindings"?: \u2026, "options"?: \u2026}. Name only the kinds, fields and relations listed above. If it cannot be drawn from them, answer {"failed": "<one sentence saying why>"}.'].filter(t=>t!=="").join(`
6
- `)}async function le(e,n,r){let t=n.lastGood?{lastGood:n.lastGood}:{},s=j(O(n.app.schema,n.sight)),i;try{i=await n.complete(Ce(e,s,r))}catch{return{failed:"Couldn't draw that: the model did not answer.",...t}}let o=Q(i);if(typeof o!="object"||o===null||Array.isArray(o))return{failed:"Couldn't draw that: the model's answer was not a view.",...t};let a=o;if(typeof a.failed=="string")return{failed:`Couldn't draw that: ${a.failed.replace(/^Couldn't draw that:\s*/i,"").replace(/\.$/,"")}.`,...t};let l=de(a);if(!K(l.name))return{failed:`Couldn't draw that: "${l.name}" is not a picture the seat can draw.`,...t};let d=l.title?l.title.slice(0,80):r?.title??k(e.trim()).slice(0,80),c={...l,title:r&&r.title===d?d:q(d,n.app)},u=T(n.app,c,n.sight);return u.ok?{...V(n.app,c,u.drawn,n.sight,"model"),asks:[e]}:{failed:u.failed,...t}}function Qe(e,n,r){let t=[...e.lenses??[]];for(let s of n){let i={name:s.lens,title:s.title,on:s.on,...s.bindings?{bindings:s.bindings}:{},...s.options?{options:s.options}:{}};if(t.some(a=>a.title===i.title))continue;T({...e,lenses:t},i,r).ok&&(t=[...t,i])}return t.length===(e.lenses??[]).length?e:{...e,lenses:t}}async function Ze(e,n,r){let{app:t,drafts:s}=r,i=ue(t,r.principal),o=c=>{let u=de(c);return{lens:u,verdict:T(t,u,i)}};if(e==="keep_lens"){let{lens:c,verdict:u}=o(n);if(!u.ok)return{ok:!1,error:u.failed,reason:"invalid"};if(!s?.keep)return{ok:!1,error:"This app's declaration cannot be written from here."};let p=F(c),m=await s.keep(p);return m.ok?{ok:!0,data:{kept:p,said:m.said??`Adds \u201C${p.title}\u201D to the places.`,undo:ve(p)}}:{ok:!1,error:m.error}}if(n.lens!==void 0){let{lens:c,verdict:u}=o(n.lens);return u.ok?{ok:!0,data:te(V(t,c,u.drawn,i,"model"))}:{ok:!1,error:u.failed,reason:"invalid"}}let a={app:t,sight:i,...s?.complete?{complete:s.complete}:{}},l=String(n.ask??""),d;if(n.current!==void 0){let{lens:c,verdict:u}=o(n.current);if(!u.ok)return{ok:!1,error:u.failed,reason:"invalid"};d=await je(V(t,c,u.drawn,i,"model"),l,a)}else d=await Oe(l,a);return L(d)?{ok:!1,error:d.failed,reason:"invalid"}:{ok:!0,data:te(d)}}export{te as draftAnswer,V as draftFromLens,ue as draftSight,Oe as draftView,L as isDraftFailure,T as judgeLens,F as lensEditOf,de as lensFromSpec,xe as recipeOfLens,je as refineDraft,Ze as runDraftTool,ve as takeBackEditOf,Ie as templateDraft,Qe as withReaderLenses};