@vuu-ui/vuu-table-extras 0.6.18 → 0.6.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var qt=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var m=(n,e,t)=>(qt(n,e,"read from private field"),t?t.call(n):e.get(n)),U=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},te=(n,e,t,s)=>(qt(n,e,"write to private field"),s?s.call(n,t):e.set(n,t),t);import{DOWN1 as pn,DOWN2 as hn,metadataKeys as cn,registerComponent as fn,UP1 as dn,UP2 as mn}from"@vuu-ui/vuu-utils";import gn from"classnames";import{useEffect as rn,useRef as on}from"react";import{isTypeDescriptor as ln}from"@vuu-ui/vuu-utils";import{getMovingValueDirection as an,isValidNumber as Kt}from"@vuu-ui/vuu-utils";var un=[void 0,void 0,void 0,void 0];function es(n,e,t){var h;let s=on(),[i,o,r,l]=s.current||un,{type:a}=t,u=ln(a)?(h=a.formatting)==null?void 0:h.decimals:void 0,c=n===i&&Kt(e)&&Kt(o)&&t===r?an(e,l,o,u):"";return rn(()=>{s.current=[n,e,t,c]}),c}import{jsx as kn,jsxs as En}from"react/jsx-runtime";var xn=String.fromCharCode(11014),Cn=String.fromCharCode(11015),{KEY:bn}=cn,Je="vuuBackgroundCell",de={ArrowOnly:"arrow",BackgroundOnly:"bg-only",ArrowBackground:"arrow-bg"},yn=n=>{if(typeof n=="string")return de.BackgroundOnly;if(n){let{renderer:e}=n;return e&&e.flashStyle||de.BackgroundOnly}},vn=({column:n,row:e})=>{let{key:t,type:s,valueFormatter:i}=n,o=e[t],r=yn(s),l=es(e[bn],o,n),a=r===de.ArrowOnly||r===de.ArrowBackground?l===dn||l===mn?xn:l===pn||l===hn?Cn:null:null,u=l?" "+l:"",c=gn(Je,u,{[`${Je}-arrowOnly`]:r===de.ArrowOnly,[`${Je}-arrowBackground`]:r===de.ArrowBackground});return En("div",{className:c,tabIndex:-1,children:[kn("div",{className:`${Je}-flasher`,children:a}),i(e[n.key])]})};fn("background",vn,"cell-renderer",{serverDataType:["long","int","double"]});import{autocompletion as Yn,defaultKeymap as Zn,EditorState as jn,EditorView as As,ensureSyntaxTree as Jn,keymap as Lt,minimalSetup as qn,startCompletion as Ts}from"@vuu-ui/vuu-codemirror";import{createEl as Ds}from"@vuu-ui/vuu-utils";import{useEffect as Kn,useMemo as ei,useRef as Qt}from"react";import{LanguageSupport as Dn,LRLanguage as Nn,styleTags as Rn,tags as rt}from"@vuu-ui/vuu-codemirror";var On=0,Qe=class{constructor(e,t){this.from=e,this.to=t}},S=class{constructor(e={}){this.id=On++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Q.match(e)),t=>{let s=e(t);return s===void 0?null:[this,s]}}};S.closedBy=new S({deserialize:n=>n.split(" ")});S.openedBy=new S({deserialize:n=>n.split(" ")});S.group=new S({deserialize:n=>n.split(" ")});S.contextHash=new S({perNode:!0});S.lookAhead=new S({perNode:!0});S.mounted=new S({perNode:!0});var Sn=Object.create(null),Q=class{constructor(e,t,s,i=0){this.name=e,this.props=t,this.id=s,this.flags=i}static define(e){let t=e.props&&e.props.length?Object.create(null):Sn,s=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),i=new Q(e.name||"",t,e.id,s);if(e.props){for(let o of e.props)if(Array.isArray(o)||(o=o(i)),o){if(o[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[o[0].id]=o[1]}}return i}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(S.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let s in e)for(let i of s.split(" "))t[i]=e[s];return s=>{for(let i=s.prop(S.group),o=-1;o<(i?i.length:0);o++){let r=t[o<0?s.name:i[o]];if(r)return r}}}};Q.none=new Q("",Object.create(null),0,8);var me=class{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let s of this.types){let i=null;for(let o of e){let r=o(s);r&&(i||(i=Object.assign({},s.props)),i[r[0].id]=r[1])}t.push(i?new Q(s.name,i,s.id,s.flags):s)}return new me(t)}},qe=new WeakMap,ts=new WeakMap,R;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays"})(R||(R={}));var I=class{constructor(e,t,s,i,o){if(this.type=e,this.children=t,this.positions=s,this.length=i,this.props=null,o&&o.length){this.props=Object.create(null);for(let[r,l]of o)this.props[typeof r=="number"?r:r.id]=l}}toString(){let e=this.prop(S.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let s of this.children){let i=s.toString();i&&(t&&(t+=","),t+=i)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new xe(this.topNode,e)}cursorAt(e,t=0,s=0){let i=qe.get(this)||this.topNode,o=new xe(i);return o.moveTo(e,t),qe.set(this,o._tree),o}get topNode(){return new G(this,0,0,null)}resolve(e,t=0){let s=ge(qe.get(this)||this.topNode,e,t,!1);return qe.set(this,s),s}resolveInner(e,t=0){let s=ge(ts.get(this)||this.topNode,e,t,!0);return ts.set(this,s),s}iterate(e){let{enter:t,leave:s,from:i=0,to:o=this.length}=e;for(let r=this.cursor((e.mode||0)|R.IncludeAnonymous);;){let l=!1;if(r.from<=o&&r.to>=i&&(r.type.isAnonymous||t(r)!==!1)){if(r.firstChild())continue;l=!0}for(;l&&s&&!r.type.isAnonymous&&s(r),!r.nextSibling();){if(!r.parent())return;l=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:gt(Q.none,this.children,this.positions,0,this.children.length,0,this.length,(t,s,i)=>new I(this.type,t,s,i,this.propValues),e.makeTree||((t,s,i)=>new I(Q.none,t,s,i)))}static build(e){return Pn(e)}};I.empty=new I(Q.none,[],[],0);var ze=class{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new ze(this.buffer,this.index)}},Y=class{constructor(e,t,s){this.buffer=e,this.length=t,this.set=s}get type(){return Q.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],s=this.buffer[e+3],i=this.set.types[t],o=i.name;if(/\W/.test(o)&&!i.isError&&(o=JSON.stringify(o)),e+=4,s==e)return o;let r=[];for(;e<s;)r.push(this.childString(e)),e=this.buffer[e+3];return o+"("+r.join(",")+")"}findChild(e,t,s,i,o){let{buffer:r}=this,l=-1;for(let a=e;a!=t&&!(ns(o,i,r[a+1],r[a+2])&&(l=a,s>0));a=r[a+3]);return l}slice(e,t,s){let i=this.buffer,o=new Uint16Array(t-e),r=0;for(let l=e,a=0;l<t;){o[a++]=i[l++],o[a++]=i[l++]-s;let u=o[a++]=i[l++]-s;o[a++]=i[l++]-e,r=Math.max(r,u)}return new Y(o,r,this.set)}};function ns(n,e,t,s){switch(n){case-2:return t<e;case-1:return s>=e&&t<e;case 0:return t<e&&s>e;case 1:return t<=e&&s>e;case 2:return s>e;case 4:return!0}}function is(n,e){let t=n.childBefore(e);for(;t;){let s=t.lastChild;if(!s||s.to!=t.to)break;s.type.isError&&s.from==s.to?(n=t,t=s.prevSibling):t=s}return n}function ge(n,e,t,s){for(var i;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let r=!s&&n instanceof G&&n.index<0?null:n.parent;if(!r)return n;n=r}let o=s?0:R.IgnoreOverlays;if(s)for(let r=n,l=r.parent;l;r=l,l=r.parent)r instanceof G&&r.index<0&&((i=l.enter(e,t,o))===null||i===void 0?void 0:i.from)!=r.from&&(n=l);for(;;){let r=n.enter(e,t,o);if(!r)return n;n=r}}var G=class{constructor(e,t,s,i){this._tree=e,this.from=t,this.index=s,this._parent=i}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,s,i,o=0){for(let r=this;;){for(let{children:l,positions:a}=r._tree,u=t>0?l.length:-1;e!=u;e+=t){let c=l[e],h=a[e]+r.from;if(ns(i,s,h,h+c.length)){if(c instanceof Y){if(o&R.ExcludeBuffers)continue;let d=c.findChild(0,c.buffer.length,t,s-h,i);if(d>-1)return new W(new ft(r,c,e,h),null,d)}else if(o&R.IncludeAnonymous||!c.type.isAnonymous||mt(c)){let d;if(!(o&R.IgnoreMounts)&&c.props&&(d=c.prop(S.mounted))&&!d.overlay)return new G(d.tree,h,e,r);let p=new G(c,h,e,r);return o&R.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,s,i)}}}if(o&R.IncludeAnonymous||!r.type.isAnonymous||(r.index>=0?e=r.index+t:e=t<0?-1:r._parent._tree.children.length,r=r._parent,!r))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,s=0){let i;if(!(s&R.IgnoreOverlays)&&(i=this._tree.prop(S.mounted))&&i.overlay){let o=e-this.from;for(let{from:r,to:l}of i.overlay)if((t>0?r<=o:r<o)&&(t<0?l>=o:l>o))return new G(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,s)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(e=0){return new xe(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return ge(this,e,t,!1)}resolveInner(e,t=0){return ge(this,e,t,!0)}enterUnfinishedNodesBefore(e){return is(this,e)}getChild(e,t=null,s=null){let i=et(this,e,t,s);return i.length?i[0]:null}getChildren(e,t=null,s=null){return et(this,e,t,s)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return tt(this,e)}};function et(n,e,t,s){let i=n.cursor(),o=[];if(!i.firstChild())return o;if(t!=null){for(;!i.type.is(t);)if(!i.nextSibling())return o}for(;;){if(s!=null&&i.type.is(s))return o;if(i.type.is(e)&&o.push(i.node),!i.nextSibling())return s==null?o:[]}}function tt(n,e,t=e.length-1){for(let s=n.parent;t>=0;s=s.parent){if(!s)return!1;if(!s.type.isAnonymous){if(e[t]&&e[t]!=s.name)return!1;t--}}return!0}var ft=class{constructor(e,t,s,i){this.parent=e,this.buffer=t,this.index=s,this.start=i}},W=class{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,s){this.context=e,this._parent=t,this.index=s,this.type=e.buffer.set.types[e.buffer.buffer[s]]}child(e,t,s){let{buffer:i}=this.context,o=i.findChild(this.index+4,i.buffer[this.index+3],e,t-this.context.start,s);return o<0?null:new W(this.context,this,o)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,s=0){if(s&R.ExcludeBuffers)return null;let{buffer:i}=this.context,o=i.findChild(this.index+4,i.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return o<0?null:new W(this.context,this,o)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new W(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new W(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new xe(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:s}=this.context,i=this.index+4,o=s.buffer[this.index+3];if(o>i){let r=s.buffer[this.index+1];e.push(s.slice(i,o,r)),t.push(0)}return new I(this.type,e,t,this.to-this.from)}resolve(e,t=0){return ge(this,e,t,!1)}resolveInner(e,t=0){return ge(this,e,t,!0)}enterUnfinishedNodesBefore(e){return is(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,s=null){let i=et(this,e,t,s);return i.length?i[0]:null}getChildren(e,t=null,s=null){return et(this,e,t,s)}get node(){return this}matchContext(e){return tt(this,e)}},xe=class{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof G)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let s=e._parent;s;s=s._parent)this.stack.unshift(s.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:s,buffer:i}=this.buffer;return this.type=t||i.set.types[i.buffer[e]],this.from=s+i.buffer[e+1],this.to=s+i.buffer[e+2],!0}yield(e){return e?e instanceof G?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,s){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,s,this.mode));let{buffer:i}=this.buffer,o=i.findChild(this.index+4,i.buffer[this.index+3],e,t-this.buffer.start,s);return o<0?!1:(this.stack.push(this.index),this.yieldBuf(o))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,s=this.mode){return this.buffer?s&R.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,s))}parent(){if(!this.buffer)return this.yieldNode(this.mode&R.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&R.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,s=this.stack.length-1;if(e<0){let i=s<0?0:this.stack[s]+4;if(this.index!=i)return this.yieldBuf(t.findChild(i,this.index,-1,0,4))}else{let i=t.buffer[this.index+3];if(i<(s<0?t.buffer.length:t.buffer[this.stack[s]+3]))return this.yieldBuf(i)}return s<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,s,{buffer:i}=this;if(i){if(e>0){if(this.index<i.buffer.buffer.length)return!1}else for(let o=0;o<this.index;o++)if(i.buffer.buffer[o+3]<this.index)return!1;({index:t,parent:s}=i)}else({index:t,_parent:s}=this._tree);for(;s;{index:t,_parent:s}=s)if(t>-1)for(let o=t+e,r=e<0?-1:s._tree.children.length;o!=r;o+=e){let l=s._tree.children[o];if(this.mode&R.IncludeAnonymous||l instanceof Y||!l.type.isAnonymous||mt(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,s=0;if(e&&e.context==this.buffer)e:for(let i=this.index,o=this.stack.length;o>=0;){for(let r=e;r;r=r._parent)if(r.index==i){if(i==this.index)return r;t=r,s=o+1;break e}i=this.stack[--o]}for(let i=s;i<this.stack.length;i++)t=new W(this.buffer,t,this.stack[i]);return this.bufferNode=new W(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let s=0;;){let i=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){s++;continue}this.type.isAnonymous||(i=!0)}for(;i&&t&&t(this),i=this.type.isAnonymous,!this.nextSibling();){if(!s)return;this.parent(),s--,i=!0}}}matchContext(e){if(!this.buffer)return tt(this.node,e);let{buffer:t}=this.buffer,{types:s}=t.set;for(let i=e.length-1,o=this.stack.length-1;i>=0;o--){if(o<0)return tt(this.node,e,i);let r=s[t.buffer[this.stack[o]]];if(!r.isAnonymous){if(e[i]&&e[i]!=r.name)return!1;i--}}return!0}};function mt(n){return n.children.some(e=>e instanceof Y||!e.type.isAnonymous||mt(e))}function Pn(n){var e;let{buffer:t,nodeSet:s,maxBufferLength:i=1024,reused:o=[],minRepeatType:r=s.types.length}=n,l=Array.isArray(t)?new ze(t,t.length):t,a=s.types,u=0,c=0;function h(k,y,C,E,N){let{id:O,start:v,end:A,size:L}=l,M=c;for(;L<0;)if(l.next(),L==-1){let ee=o[O];C.push(ee),E.push(v-k);return}else if(L==-3){u=O;return}else if(L==-4){c=O;return}else throw new RangeError(`Unrecognized record size: ${L}`);let ce=a[O],K,X,jt=v-k;if(A-v<=i&&(X=x(l.pos-y,N))){let ee=new Uint16Array(X.size-X.skip),$=l.pos-X.size,V=ee.length;for(;l.pos>$;)V=g(X.start,ee,V);K=new Y(ee,A-X.start,s),jt=X.start-k}else{let ee=l.pos-L;l.next();let $=[],V=[],ne=O>=r?O:-1,fe=0,je=A;for(;l.pos>ee;)ne>=0&&l.id==ne&&l.size>=0?(l.end<=je-i&&(p($,V,v,fe,l.end,je,ne,M),fe=$.length,je=l.end),l.next()):h(v,ee,$,V,ne);if(ne>=0&&fe>0&&fe<$.length&&p($,V,v,fe,v,je,ne,M),$.reverse(),V.reverse(),ne>-1&&fe>0){let Jt=d(ce);K=gt(ce,$,V,0,$.length,0,A-v,Jt,Jt)}else K=f(ce,$,V,A-v,M-A)}C.push(K),E.push(jt)}function d(k){return(y,C,E)=>{let N=0,O=y.length-1,v,A;if(O>=0&&(v=y[O])instanceof I){if(!O&&v.type==k&&v.length==E)return v;(A=v.prop(S.lookAhead))&&(N=C[O]+v.length+A)}return f(k,y,C,E,N)}}function p(k,y,C,E,N,O,v,A){let L=[],M=[];for(;k.length>E;)L.push(k.pop()),M.push(y.pop()+C-N);k.push(f(s.types[v],L,M,O-N,A-O)),y.push(N-C)}function f(k,y,C,E,N=0,O){if(u){let v=[S.contextHash,u];O=O?[v].concat(O):[v]}if(N>25){let v=[S.lookAhead,N];O=O?[v].concat(O):[v]}return new I(k,y,C,E,O)}function x(k,y){let C=l.fork(),E=0,N=0,O=0,v=C.end-i,A={size:0,start:0,skip:0};e:for(let L=C.pos-k;C.pos>L;){let M=C.size;if(C.id==y&&M>=0){A.size=E,A.start=N,A.skip=O,O+=4,E+=4,C.next();continue}let ce=C.pos-M;if(M<0||ce<L||C.start<v)break;let K=C.id>=r?4:0,X=C.start;for(C.next();C.pos>ce;){if(C.size<0)if(C.size==-3)K+=4;else break e;else C.id>=r&&(K+=4);C.next()}N=X,E+=M,O+=K}return(y<0||E==k)&&(A.size=E,A.start=N,A.skip=O),A.size>4?A:void 0}function g(k,y,C){let{id:E,start:N,end:O,size:v}=l;if(l.next(),v>=0&&E<r){let A=C;if(v>4){let L=l.pos-(v-4);for(;l.pos>L;)C=g(k,y,C)}y[--C]=A,y[--C]=O-k,y[--C]=N-k,y[--C]=E}else v==-3?u=E:v==-4&&(c=E);return C}let P=[],T=[];for(;l.pos>0;)h(n.start||0,n.bufferStart||0,P,T,-1);let w=(e=n.length)!==null&&e!==void 0?e:P.length?T[0]+P[0].length:0;return new I(a[n.topID],P.reverse(),T.reverse(),w)}var ss=new WeakMap;function Ke(n,e){if(!n.isAnonymous||e instanceof Y||e.type!=n)return 1;let t=ss.get(e);if(t==null){t=1;for(let s of e.children){if(s.type!=n||!(s instanceof I)){t=1;break}t+=Ke(n,s)}ss.set(e,t)}return t}function gt(n,e,t,s,i,o,r,l,a){let u=0;for(let f=s;f<i;f++)u+=Ke(n,e[f]);let c=Math.ceil(u*1.5/8),h=[],d=[];function p(f,x,g,P,T){for(let w=g;w<P;){let k=w,y=x[w],C=Ke(n,f[w]);for(w++;w<P;w++){let E=Ke(n,f[w]);if(C+E>=c)break;C+=E}if(w==k+1){if(C>c){let E=f[k];p(E.children,E.positions,0,E.children.length,x[k]+T);continue}h.push(f[k])}else{let E=x[w-1]+f[w-1].length-y;h.push(gt(n,f,x,k,w,y,E,null,a))}d.push(y+T-o)}}return p(e,t,s,i,0),(l||a)(h,d,r)}var st=class{startParse(e,t,s){return typeof e=="string"&&(e=new dt(e)),s=s?s.length?s.map(i=>new Qe(i.from,i.to)):[new Qe(0,0)]:[new Qe(0,e.length)],this.createParse(e,t||[],s)}parse(e,t,s){let i=this.startParse(e,t,s);for(;;){let o=i.advance();if(o)return o}}},dt=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};var qr=new S({perNode:!0});var be=class{constructor(e,t,s,i,o,r,l,a,u,c=0,h){this.p=e,this.stack=t,this.state=s,this.reducePos=i,this.pos=o,this.score=r,this.buffer=l,this.bufferBase=a,this.curContext=u,this.lookAhead=c,this.parent=h}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,s=0){let i=e.parser.context;return new be(e,[],t,s,s,0,[],0,i?new nt(i,i.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let s=e>>19,i=e&65535,{parser:o}=this.p,r=o.dynamicPrecedence(i);if(r&&(this.score+=r),s==0){this.pushState(o.getGoto(this.state,i,!0),this.reducePos),i<o.minRepeatTerm&&this.storeNode(i,this.reducePos,this.reducePos,4,!0),this.reduceContext(i,this.reducePos);return}let l=this.stack.length-(s-1)*3-(e&262144?6:0),a=l?this.stack[l-2]:this.p.ranges[0].from,u=this.reducePos-a;u>=2e3&&!(!((t=this.p.parser.nodeSet.types[i])===null||t===void 0)&&t.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=u):this.p.lastBigReductionSize<u&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=u));let c=l?this.stack[l-1]:0,h=this.bufferBase+this.buffer.length-c;if(i<o.minRepeatTerm||e&131072){let d=o.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(i,a,d,h+4,!0)}if(e&262144)this.state=this.stack[l];else{let d=this.stack[l-3];this.state=o.getGoto(d,i,!0)}for(;this.stack.length>l;)this.stack.pop();this.reduceContext(i,a)}storeNode(e,t,s,i=4,o=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let r=this,l=this.buffer.length;if(l==0&&r.parent&&(l=r.bufferBase-r.parent.bufferBase,r=r.parent),l>0&&r.buffer[l-4]==0&&r.buffer[l-1]>-1){if(t==s)return;if(r.buffer[l-2]>=t){r.buffer[l-2]=s;return}}}if(!o||this.pos==s)this.buffer.push(e,t,s,i);else{let r=this.buffer.length;if(r>0&&this.buffer[r-4]!=0)for(;r>0&&this.buffer[r-2]>s;)this.buffer[r]=this.buffer[r-4],this.buffer[r+1]=this.buffer[r-3],this.buffer[r+2]=this.buffer[r-2],this.buffer[r+3]=this.buffer[r-1],r-=4,i>4&&(i-=4);this.buffer[r]=e,this.buffer[r+1]=t,this.buffer[r+2]=s,this.buffer[r+3]=i}}shift(e,t,s){let i=this.pos;if(e&131072)this.pushState(e&65535,this.pos);else if(e&262144)this.pos=s,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,s,4);else{let o=e,{parser:r}=this.p;(s>this.pos||t<=r.maxNode)&&(this.pos=s,r.stateFlag(o,1)||(this.reducePos=s)),this.pushState(o,i),this.shiftContext(t,i),t<=r.maxNode&&this.buffer.push(t,i,s,4)}}apply(e,t,s){e&65536?this.reduce(e):this.shift(e,t,s)}useNode(e,t){let s=this.p.reused.length-1;(s<0||this.p.reused[s]!=e)&&(this.p.reused.push(e),s++);let i=this.pos;this.reducePos=this.pos=i+e.length,this.pushState(t,i),this.buffer.push(s,i,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(;t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let s=e.buffer.slice(t),i=e.bufferBase+t;for(;e&&i==e.bufferBase;)e=e.parent;return new be(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,s,i,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let s=e<=this.p.parser.maxNode;s&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,s?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new Ct(this);;){let s=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(s==0)return!1;if(!(s&65536))return!0;t.reduce(s)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>4<<1||this.stack.length>=120){let i=[];for(let o=0,r;o<t.length;o+=2)(r=t[o+1])!=this.state&&this.p.parser.hasAction(r,e)&&i.push(t[o],r);if(this.stack.length<120)for(let o=0;i.length<4<<1&&o<t.length;o+=2){let r=t[o+1];i.some((l,a)=>a&1&&l==r)||i.push(t[o],r)}t=i}let s=[];for(let i=0;i<t.length&&s.length<4;i+=2){let o=t[i+1];if(o==this.state)continue;let r=this.split();r.pushState(o,this.pos),r.storeNode(0,r.pos,r.pos,4,!0),r.shiftContext(t[i],this.pos),r.score-=200,s.push(r)}return s}forceReduce(){let e=this.p.parser.stateSlot(this.state,5);if(!(e&65536))return!1;let{parser:t}=this.p;if(!t.validAction(this.state,e)){let s=e>>19,i=e&65535,o=this.stack.length-s*3;if(o<0||t.getGoto(this.stack[o],i,!1)<0)return!1;this.storeNode(0,this.reducePos,this.reducePos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.reducePos,this.reducePos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.reducePos,this.reducePos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new nt(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){e>this.lookAhead&&(this.emitLookAhead(),this.lookAhead=e)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},nt=class{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}},rs;(function(n){n[n.Insert=200]="Insert",n[n.Delete=190]="Delete",n[n.Reduce=100]="Reduce",n[n.MaxNext=4]="MaxNext",n[n.MaxInsertStackDepth=300]="MaxInsertStackDepth",n[n.DampenInsertStackDepth=120]="DampenInsertStackDepth",n[n.MinBigReduction=2e3]="MinBigReduction"})(rs||(rs={}));var Ct=class{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,s=e>>19;s==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(s-1)*3;let i=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=i}},ye=class{constructor(e,t,s){this.stack=e,this.pos=t,this.index=s,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new ye(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new ye(this.stack,this.pos,this.index)}};function Me(n,e=Uint16Array){if(typeof n!="string")return n;let t=null;for(let s=0,i=0;s<n.length;){let o=0;for(;;){let r=n.charCodeAt(s++),l=!1;if(r==126){o=65535;break}r>=92&&r--,r>=34&&r--;let a=r-32;if(a>=46&&(a-=46,l=!0),o+=a,l)break;o*=46}t?t[i++]=o:t=new e(o)}return t}var Ce=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},os=new Ce,bt=class{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=os,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let s=this.range,i=this.rangeIndex,o=this.pos+e;for(;o<s.from;){if(!i)return null;let r=this.ranges[--i];o-=s.from-r.to,s=r}for(;t<0?o>s.to:o>=s.to;){if(i==this.ranges.length-1)return null;let r=this.ranges[++i];o+=r.from-s.to,s=r}return o}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,s,i;if(t>=0&&t<this.chunk.length)s=this.pos+e,i=this.chunk.charCodeAt(t);else{let o=this.resolveOffset(e,1);if(o==null)return-1;if(s=o,s>=this.chunk2Pos&&s<this.chunk2Pos+this.chunk2.length)i=this.chunk2.charCodeAt(s-this.chunk2Pos);else{let r=this.rangeIndex,l=this.range;for(;l.to<=s;)l=this.ranges[++r];this.chunk2=this.input.chunk(this.chunk2Pos=s),s+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-s)),i=this.chunk2.charCodeAt(0)}}return s>=this.token.lookAhead&&(this.token.lookAhead=s+1),i}acceptToken(e,t=0){let s=t?this.resolveOffset(t,-1):this.pos;if(s==null||s<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=s}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=os,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let s="";for(let i of this.ranges){if(i.from>=t)break;i.to>e&&(s+=this.input.read(Math.max(i.from,e),Math.min(i.to,t)))}return s}},se=class{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:s}=t.p;fs(this.data,e,t,this.id,s.data,s.tokenPrecTable)}};se.prototype.contextual=se.prototype.fallback=se.prototype.extend=!1;var yt=class{constructor(e,t,s){this.precTable=t,this.elseToken=s,this.data=typeof e=="string"?Me(e):e}token(e,t){let s=e.pos,i;for(;i=e.pos,fs(this.data,e,t,0,this.data,this.precTable),!(e.token.value>-1);){if(this.elseToken==null)return;if(e.next<0)break;e.advance(),e.reset(i+1,e.token)}i>s&&(e.reset(s,e.token),e.acceptToken(this.elseToken,i-s))}};yt.prototype.contextual=se.prototype.fallback=se.prototype.extend=!1;function fs(n,e,t,s,i,o){let r=0,l=1<<s,{dialect:a}=t.p.parser;e:for(;l&n[r];){let u=n[r+1];for(let p=r+3;p<u;p+=2)if((n[p+1]&l)>0){let f=n[p];if(a.allows(f)&&(e.token.value==-1||e.token.value==f||An(f,e.token.value,i,o))){e.acceptToken(f);break}}let c=e.next,h=0,d=n[r+2];if(e.next<0&&d>h&&n[u+d*3-3]==65535&&n[u+d*3-3]==65535){r=n[u+d*3-1];continue e}for(;h<d;){let p=h+d>>1,f=u+p+(p<<1),x=n[f],g=n[f+1]||65536;if(c<x)d=p;else if(c>=g)h=p+1;else{r=n[f+2],e.advance();continue e}}break}}function ls(n,e,t){for(let s=e,i;(i=n[s])!=65535;s++)if(i==t)return s-e;return-1}function An(n,e,t,s){let i=ls(t,s,e);return i<0||ls(t,s,n)<i}var _=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),xt=null,as;(function(n){n[n.Margin=25]="Margin"})(as||(as={}));function us(n,e,t){let s=n.cursor(R.IncludeAnonymous);for(s.moveTo(e);;)if(!(t<0?s.childBefore(e):s.childAfter(e)))for(;;){if((t<0?s.to<e:s.from>e)&&!s.type.isError)return t<0?Math.max(0,Math.min(s.to-1,e-25)):Math.min(n.length,Math.max(s.from+1,e+25));if(t<0?s.prevSibling():s.nextSibling())break;if(!s.parent())return t<0?0:n.length}}var vt=class{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?us(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?us(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let s=this.trees[t],i=this.index[t];if(i==s.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let o=s.children[i],r=this.start[t]+s.positions[i];if(r>e)return this.nextStart=r,null;if(o instanceof I){if(r==e){if(r<this.safeFrom)return null;let l=r+o.length;if(l<=this.safeTo){let a=o.prop(S.lookAhead);if(!a||l+a<this.fragment.to)return o}}this.index[t]++,r+o.length>=Math.max(this.safeFrom,e)&&(this.trees.push(o),this.start.push(r),this.index.push(0))}else this.index[t]++,this.nextStart=r+o.length}}},kt=class{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(s=>new Ce)}getActions(e){let t=0,s=null,{parser:i}=e.p,{tokenizers:o}=i,r=i.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,a=0;for(let u=0;u<o.length;u++){if(!(1<<u&r))continue;let c=o[u],h=this.tokens[u];if(!(s&&!c.fallback)&&((c.contextual||h.start!=e.pos||h.mask!=r||h.context!=l)&&(this.updateCachedToken(h,c,e),h.mask=r,h.context=l),h.lookAhead>h.end+25&&(a=Math.max(h.lookAhead,a)),h.value!=0)){let d=t;if(h.extended>-1&&(t=this.addActions(e,h.extended,h.end,t)),t=this.addActions(e,h.value,h.end,t),!c.extend&&(s=h,t>d))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!s&&e.pos==this.stream.end&&(s=new Ce,s.value=e.p.parser.eofTerm,s.start=s.end=e.pos,t=this.addActions(e,s.value,s.end,t)),this.mainToken=s,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new Ce,{pos:s,p:i}=e;return t.start=s,t.end=Math.min(s+1,i.stream.end),t.value=s==i.stream.end?i.parser.eofTerm:0,t}updateCachedToken(e,t,s){let i=this.stream.clipPos(s.pos);if(t.token(this.stream.reset(i,e),s),e.value>-1){let{parser:o}=s.p;for(let r=0;r<o.specialized.length;r++)if(o.specialized[r]==e.value){let l=o.specializers[r](this.stream.read(e.start,e.end),s);if(l>=0&&s.p.parser.dialect.allows(l>>1)){l&1?e.extended=l>>1:e.value=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(i+1)}putAction(e,t,s,i){for(let o=0;o<i;o+=3)if(this.actions[o]==e)return i;return this.actions[i++]=e,this.actions[i++]=t,this.actions[i++]=s,i}addActions(e,t,s,i){let{state:o}=e,{parser:r}=e.p,{data:l}=r;for(let a=0;a<2;a++)for(let u=r.stateSlot(o,a?2:1);;u+=3){if(l[u]==65535)if(l[u+1]==1)u=Z(l,u+2);else{i==0&&l[u+1]==2&&(i=this.putAction(Z(l,u+2),t,s,i));break}l[u]==t&&(i=this.putAction(Z(l,u+1),t,s,i))}return i}},ps;(function(n){n[n.Distance=5]="Distance",n[n.MaxRemainingPerStep=3]="MaxRemainingPerStep",n[n.MinBufferLengthPrune=500]="MinBufferLengthPrune",n[n.ForceReduceLimit=10]="ForceReduceLimit",n[n.CutDepth=15e3]="CutDepth",n[n.CutTo=9e3]="CutTo",n[n.MaxLeftAssociativeReductionCount=300]="MaxLeftAssociativeReductionCount",n[n.MaxStackCount=12]="MaxStackCount"})(ps||(ps={}));var Et=class{constructor(e,t,s,i){this.parser=e,this.input=t,this.ranges=i,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new bt(t,i),this.tokens=new kt(e,this.stream),this.topTerm=e.top[1];let{from:o}=i[0];this.stacks=[be.start(this,e.top[0],o)],this.fragments=s.length&&this.stream.end-o>e.bufferLength*4?new vt(s,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,s=this.stacks=[],i,o;if(this.bigReductionCount>300&&e.length==1){let[r]=e;for(;r.forceReduce()&&r.stack.length&&r.stack[r.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let r=0;r<e.length;r++){let l=e[r];for(;;){if(this.tokens.mainToken=null,l.pos>t)s.push(l);else{if(this.advanceStack(l,s,e))continue;{i||(i=[],o=[]),i.push(l);let a=this.tokens.getMainToken(l);o.push(a.value,a.end)}}break}}if(!s.length){let r=i&&Tn(i);if(r)return this.stackToTree(r);if(this.parser.strict)throw _&&i&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&i){let r=this.stoppedAt!=null&&i[0].pos>this.stoppedAt?i[0]:this.runRecovery(i,o,s);if(r)return this.stackToTree(r.forceAll())}if(this.recovering){let r=this.recovering==1?1:this.recovering*3;if(s.length>r)for(s.sort((l,a)=>a.score-l.score);s.length>r;)s.pop();s.some(l=>l.reducePos>t)&&this.recovering--}else if(s.length>1){e:for(let r=0;r<s.length-1;r++){let l=s[r];for(let a=r+1;a<s.length;a++){let u=s[a];if(l.sameState(u)||l.buffer.length>500&&u.buffer.length>500)if((l.score-u.score||l.buffer.length-u.buffer.length)>0)s.splice(a--,1);else{s.splice(r--,1);continue e}}}s.length>12&&s.splice(12,s.length-12)}this.minStackPos=s[0].pos;for(let r=1;r<s.length;r++)s[r].pos<this.minStackPos&&(this.minStackPos=s[r].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,s){let i=e.pos,{parser:o}=this,r=_?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&i>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let u=e.curContext&&e.curContext.tracker.strict,c=u?e.curContext.hash:0;for(let h=this.fragments.nodeAt(i);h;){let d=this.parser.nodeSet.types[h.type.id]==h.type?o.getGoto(e.state,h.type.id):-1;if(d>-1&&h.length&&(!u||(h.prop(S.contextHash)||0)==c))return e.useNode(h,d),_&&console.log(r+this.stackID(e)+` (via reuse of ${o.getName(h.type.id)})`),!0;if(!(h instanceof I)||h.children.length==0||h.positions[0]>0)break;let p=h.children[0];if(p instanceof I&&h.positions[0]==0)h=p;else break}}let l=o.stateSlot(e.state,4);if(l>0)return e.reduce(l),_&&console.log(r+this.stackID(e)+` (via always-reduce ${o.getName(l&65535)})`),!0;if(e.stack.length>=15e3)for(;e.stack.length>9e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let u=0;u<a.length;){let c=a[u++],h=a[u++],d=a[u++],p=u==a.length||!s,f=p?e:e.split();if(f.apply(c,h,d),_&&console.log(r+this.stackID(f)+` (via ${c&65536?`reduce of ${o.getName(c&65535)}`:"shift"} for ${o.getName(h)} @ ${i}${f==e?"":", split"})`),p)return!0;f.pos>i?t.push(f):s.push(f)}return!1}advanceFully(e,t){let s=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>s)return hs(e,t),!0}}runRecovery(e,t,s){let i=null,o=!1;for(let r=0;r<e.length;r++){let l=e[r],a=t[r<<1],u=t[(r<<1)+1],c=_?this.stackID(l)+" -> ":"";if(l.deadEnd&&(o||(o=!0,l.restart(),_&&console.log(c+this.stackID(l)+" (restarted)"),this.advanceFully(l,s))))continue;let h=l.split(),d=c;for(let p=0;h.forceReduce()&&p<10&&(_&&console.log(d+this.stackID(h)+" (via force-reduce)"),!this.advanceFully(h,s));p++)_&&(d=this.stackID(h)+" -> ");for(let p of l.recoverByInsert(a))_&&console.log(c+this.stackID(p)+" (via recover-insert)"),this.advanceFully(p,s);this.stream.end>l.pos?(u==l.pos&&(u++,a=0),l.recoverByDelete(a,u),_&&console.log(c+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),hs(l,s)):(!i||i.score<l.score)&&(i=l)}return i}stackToTree(e){return e.close(),I.build({buffer:ye.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(xt||(xt=new WeakMap)).get(e);return t||xt.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}};function hs(n,e){for(let t=0;t<e.length;t++){let s=e[t];if(s.pos==n.pos&&s.sameState(n)){e[t].score<n.score&&(e[t]=n);return}}e.push(n)}var Ot=class{constructor(e,t,s){this.source=e,this.flags=t,this.disabled=s}allows(e){return!this.disabled||this.disabled[e]==0}};var ie=class extends st{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let s=Object.keys(e.topRules).map(l=>e.topRules[l][1]),i=[];for(let l=0;l<t.length;l++)i.push([]);function o(l,a,u){i[l].push([a,a.deserialize(String(u))])}if(e.nodeProps)for(let l of e.nodeProps){let a=l[0];typeof a=="string"&&(a=S[a]);for(let u=1;u<l.length;){let c=l[u++];if(c>=0)o(c,a,l[u++]);else{let h=l[u+-c];for(let d=-c;d>0;d--)o(l[u++],a,h);u++}}}this.nodeSet=new me(t.map((l,a)=>Q.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:i[a],top:s.indexOf(a)>-1,error:a==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(a)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=1024;let r=Me(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(cs),this.states=Me(e.states,Uint32Array),this.data=Me(e.stateData),this.goto=Me(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new se(r,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,s){let i=new Et(this,e,t,s);for(let o of this.wrappers)i=o(i,e,t,s);return i}getGoto(e,t,s=!1){let i=this.goto;if(t>=i[0])return-1;for(let o=i[t+1];;){let r=i[o++],l=r&1,a=i[o++];if(l&&s)return a;for(let u=o+(r>>1);o<u;o++)if(i[o]==e)return a;if(l)return-1}}hasAction(e,t){let s=this.data;for(let i=0;i<2;i++)for(let o=this.stateSlot(e,i?2:1),r;;o+=3){if((r=s[o])==65535)if(s[o+1]==1)r=s[o=Z(s,o+2)];else{if(s[o+1]==2)return Z(s,o+2);break}if(r==t||r==0)return Z(s,o+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){if(t==this.stateSlot(e,4))return!0;for(let s=this.stateSlot(e,1);;s+=3){if(this.data[s]==65535)if(this.data[s+1]==1)s=Z(this.data,s+2);else return!1;if(t==Z(this.data,s+1))return!0}}nextStates(e){let t=[];for(let s=this.stateSlot(e,1);;s+=3){if(this.data[s]==65535)if(this.data[s+1]==1)s=Z(this.data,s+2);else break;if(!(this.data[s+2]&1)){let i=this.data[s+1];t.some((o,r)=>r&1&&o==i)||t.push(this.data[s],i)}}return t}configure(e){let t=Object.assign(Object.create(ie.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let s=this.topRules[e.top];if(!s)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=s}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(s=>{let i=e.tokenizers.find(o=>o.from==s);return i?i.to:s})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((s,i)=>{let o=e.specializers.find(l=>l.from==s.external);if(!o)return s;let r=Object.assign(Object.assign({},s),{external:o.to});return t.specializers[i]=cs(r),r})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),s=t.map(()=>!1);if(e)for(let o of e.split(" ")){let r=t.indexOf(o);r>=0&&(s[r]=!0)}let i=null;for(let o=0;o<t.length;o++)if(!s[o])for(let r=this.dialects[t[o]],l;(l=this.data[r++])!=65535;)(i||(i=new Uint8Array(this.maxTerm+1)))[l]=1;return new Ot(e,s,i)}static deserialize(e){return new ie(e)}};function Z(n,e){return n[e]|n[e+1]<<16}function Tn(n){let e=null;for(let t of n){let s=t.p.stoppedAt;(t.pos==t.p.stream.end||s!=null&&t.pos>s)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function cs(n){if(n.external){let e=n.extend?1:0;return(t,s)=>n.external(t,s)<<1|e}return n.get}var it=ie.deserialize({version:14,states:"&fOVQPOOO!SQPO'#C^OVQPO'#CcQ!pQPOOO#OQPO'#CkO#TQPO'#CrOOQO'#Cy'#CyO#YQPO,58}OVQPO,59QOVQPO,59QOVQPO,59VOVQPO'#CtOOQO,59^,59^OOQO1G.i1G.iOOQO1G.l1G.lO#kQPO1G.lO$fQPO'#CmO%WQQO1G.qOOQO'#C{'#C{O%cQPO,59`OOQO'#Cn'#CnO%wQPO,59XOVQPO,59ZOVQPO,59[OVQPO7+$]OVQPO'#CuO&`QPO1G.zOOQO1G.z1G.zO&hQQO'#C^O&rQQO1G.sO'ZQQO1G.uOOQO1G.v1G.vO'fQPO<<GwO'wQPO,59aOOQO-E6s-E6sOOQO7+$f7+$fOVQPOAN=cO(]QQO1G.lO(tQPOG22}OOQOLD(iLD(iO%wQPO,59QO%wQPO,59Q",stateData:")[~OlOS~ORUOSUOTUOUUOWQO`SOnPO~OWgXZQX[QX]QX^QXeQX~OjQXXQXpQXqQXrQXsQXtQXuQX~PnOZWO[WO]XO^XO~OWYO~OWZO~OX]OZWO[WO]XO^XO~OZWO[WO]Yi^YijYiXYipYiqYirYisYitYiuYieYi~OZWO[WO]XO^XOpdOqdOrdOsdOtdOudO~OehOvfOwgO~OXkOZWO[WO]XO^XOeiO~ORUOSUOTUOUUOWQO`SOnlO~OXsOeiO~OvQXwQX~PnOZxO[xO]yO^yOeaivaiwai~OwgOecivci~OZWO[WO]XO^XOetO~OZWO[WO]XO^XOXiaeia~OZxO[xO]Yi^YieYivYiwYi~OXwOZWO[WO]XO^XO~O`UTn~",goto:"#spPPqPPPPqPPqPPPPqP!R!W!R!RPq!Z!k!nPPP!tP#jmUOQWXYZefghitxyVbYfgRe`mTOQWXYZefghitxyR[TQjcRrjQROQVQS^WxQ_XU`YfgQcZQmeQphQqiQuyRvtQaYQnfRog",nodeNames:"\u26A0 ColumnDefinitionExpression Column Number String True False ParenthesizedExpression OpenBrace CloseBrace ArithmeticExpression Divide Times Plus Minus ConditionalExpression If RelationalExpression RelationalOperator AndCondition OrCondition Comma CallExpression Function ArgList",maxTerm:39,skippedNodes:[0],repeatNodeCount:1,tokenData:".^~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$jz{$o{|$t|}$y}!O%O!O!P%T!P!Q%c!Q![%h!^!_%s!_!`&Q!`!a&V!c!}&d#R#S&d#T#U&u#U#Y&d#Y#Z(Y#Z#]&d#]#^*j#^#c&d#c#d+f#d#h&d#h#i,b#i#o&d~#USl~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOu~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_OS~~$bP;=`<%l#m~$jOW~~$oOX~~$tO[~~$yO]~~%OOe~~%TO^~~%WP!Q![%Z~%`PR~!Q![%Z~%hOZ~~%mQR~!O!P%Z!Q![%h~%xPr~!_!`%{~&QOt~~&VOp~~&[Pq~!_!`&_~&dOs~P&iSnP!Q![&d!c!}&d#R#S&d#T#o&dR&zUnP!Q![&d!c!}&d#R#S&d#T#b&d#b#c'^#c#o&dR'cUnP!Q![&d!c!}&d#R#S&d#T#W&d#W#X'u#X#o&dR'|SvQnP!Q![&d!c!}&d#R#S&d#T#o&d~(_TnP!Q![&d!c!}&d#R#S&d#T#U(n#U#o&d~(sUnP!Q![&d!c!}&d#R#S&d#T#`&d#`#a)V#a#o&d~)[UnP!Q![&d!c!}&d#R#S&d#T#g&d#g#h)n#h#o&d~)sUnP!Q![&d!c!}&d#R#S&d#T#X&d#X#Y*V#Y#o&d~*^SU~nP!Q![&d!c!}&d#R#S&d#T#o&d~*oUnP!Q![&d!c!}&d#R#S&d#T#Y&d#Y#Z+R#Z#o&d~+YS`~nP!Q![&d!c!}&d#R#S&d#T#o&dR+kUnP!Q![&d!c!}&d#R#S&d#T#f&d#f#g+}#g#o&dR,USwQnP!Q![&d!c!}&d#R#S&d#T#o&d~,gUnP!Q![&d!c!}&d#R#S&d#T#f&d#f#g,y#g#o&d~-OUnP!Q![&d!c!}&d#R#S&d#T#i&d#i#j-b#j#o&d~-gUnP!Q![&d!c!}&d#R#S&d#T#X&d#X#Y-y#Y#o&d~.QST~nP!Q![&d!c!}&d#R#S&d#T#o&d",tokenizers:[0,1],topRules:{ColumnDefinitionExpression:[0,1]},tokenPrec:375});var In=Nn.define({name:"VuuColumnExpression",parser:it.configure({props:[Rn({Function:rt.variableName,String:rt.string,Or:rt.emphasis,Operator:rt.operator})]})}),ds=()=>new Dn(In);var St=class{constructor(e){switch(this.value=e,typeof e){case"boolean":this.type="booleanLiteralExpression";break;case"number":this.type="numberLiteralExpression";break;default:this.type="stringLiteralExpression"}}toJSON(){return{type:this.type,value:this.value}}},Pt=class{constructor(e){this.type="colExpression";this.column=e}toJSON(){return{type:this.type,column:this.column}}},Ue,oe,wt=class{constructor(e="unknown"){U(this,Ue,[{type:"unknown"},{type:"unknown"}]);U(this,oe,void 0);this.type="arithmeticExpression";te(this,oe,e)}get op(){return m(this,oe)}set op(e){te(this,oe,e)}get expressions(){return m(this,Ue)}toJSON(){return{type:this.type,op:m(this,oe),expressions:m(this,Ue)}}};Ue=new WeakMap,oe=new WeakMap;var Oe,At=class{constructor(e){U(this,Oe,[]);this.type="callExpression";this.functionName=e}get expressions(){return m(this,Oe)}get arguments(){return m(this,Oe)}toJSON(){return{type:this.type,functionName:this.functionName,arguments:m(this,Oe).map(e=>{var t;return(t=e.toJSON)==null?void 0:t.call(e)})}}};Oe=new WeakMap;var Ge,Se,ke=class{constructor(){U(this,Ge,[{type:"unknown"},{type:"unknown"}]);U(this,Se,"unknown");this.type="relationalExpression"}get op(){return m(this,Se)}set op(e){te(this,Se,e)}get expressions(){return m(this,Ge)}toJSON(){return{type:this.type,op:m(this,Se),expressions:m(this,Ge)}}};Ge=new WeakMap,Se=new WeakMap;var _e,Pe,Ee=class{constructor(e){U(this,_e,[{type:"unknown"},{type:"unknown"}]);U(this,Pe,void 0);this.type="booleanCondition";te(this,Pe,e)}get op(){return m(this,Pe)}get expressions(){return m(this,_e)}toJSON(){return{type:this.type,op:m(this,Pe),expressions:m(this,_e).map(e=>{var t;return(t=e.toJSON)==null?void 0:t.call(e)})}}};_e=new WeakMap,Pe=new WeakMap;var H,$e=class{constructor(e){U(this,H,void 0);this.type="conditionalExpression";te(this,H,[e?new Ee(e):new ke,{type:"unknown"},{type:"unknown"}])}get expressions(){return m(this,H)}get condition(){return m(this,H)[0]}get truthyExpression(){return m(this,H)[1]}set truthyExpression(e){m(this,H)[1]=e}get falsyExpression(){return m(this,H)[2]}set falsyExpression(e){m(this,H)[2]=e}toJSON(){var e,t,s,i,o;return{type:this.type,condition:(t=(e=this.condition).toJSON)==null?void 0:t.call(e),truthyExpression:this.truthyExpression,falsyExpression:(o=(i=(s=this.falsyExpression)==null?void 0:s.toJSON)==null?void 0:i.call(s))!=null?o:this.falsyExpression}}};H=new WeakMap;var re=n=>n.type==="unknown",ot=n=>n.type==="arithmeticExpression",Bn=n=>n.type==="callExpression",ve=n=>n.type==="conditionalExpression",Fn=n=>n.type==="relationalExpression"||n.type==="booleanCondition";var Ln=n=>n.type==="booleanCondition",Dt=n=>(n==null?void 0:n.type)==="relationalExpression";var z=n=>{if(re(n))return n;if(Dt(n)){let[e,t]=n.expressions;if(F(e))return z(e);if(n.op==="unknown")return n;if(F(t))return z(t)}else if(Fn(n)){let{expressions:e=[]}=n;for(let t of e)if(F(t))return z(t)}else if(ve(n)){let{condition:e,truthyExpression:t,falsyExpression:s}=n;if(F(e))return z(e);if(F(t))return z(t);if(F(s))return z(s)}else if(ot(n)){let{expressions:e=[]}=n;for(let t of e)if(F(t))return z(t)}},lt=(n,e,t)=>{let{expressions:s=[]}=n;if(s.includes(e)){let i=s.indexOf(e);return s.splice(i,1,t),!0}else for(let i of s)if(lt(i,e,t))return!0;return!1},F=n=>re(n)?!0:ve(n)?F(n.condition)||F(n.truthyExpression)||F(n.falsyExpression):Dt(n)||Ln(n)?n.op===void 0||n.expressions.some(e=>F(e)):!1,ms=(n,e)=>{let t=z(n);t?t.expressions?t.expressions.push(e):console.warn("don't know how to treat targetExpression"):console.error("no target expression found")},b,le,Tt=class{constructor(){U(this,b,void 0);U(this,le,[])}setCondition(e){if(m(this,b)===void 0)this.addExpression(new $e(e));else if(ve(m(this,b))){if(F(m(this,b).condition)){let t=e?new Ee(e):new ke;this.addExpression(t)}else if(re(m(this,b).truthyExpression))m(this,b).truthyExpression=new $e(e);else if(F(m(this,b).truthyExpression)){let t=e?new Ee(e):new ke;this.addExpression(t)}else if(re(m(this,b).falsyExpression))m(this,b).falsyExpression=new $e(e);else if(F(m(this,b).falsyExpression)){let t=e?new Ee(e):new ke;this.addExpression(t)}}else console.error("setCondition called unexpectedly")}addExpression(e){if(m(this,le).length>0){let t=m(this,le).at(-1);t==null||t.arguments.push(e)}else if(m(this,b)===void 0)te(this,b,e);else if(ot(m(this,b))){let t=z(m(this,b));t&&re(t)&&lt(m(this,b),t,e)}else if(ve(m(this,b))&&F(m(this,b))){let t=z(m(this,b));t&&re(t)?lt(m(this,b),t,e):t&&ms(t,e)}}setFunction(e){let t=new At(e);this.addExpression(t),m(this,le).push(t)}setColumn(e){this.addExpression(new Pt(e))}setArithmeticOp(e){let t=e,s=m(this,b);ot(s)&&(s.op=t)}setRelationalOperator(e){let t=e;if(m(this,b)&&ve(m(this,b))){let s=z(m(this,b));Dt(s)?s.op=t:console.error(`no target expression found (op = ${e})`)}}setValue(e){let t=new St(e);if(m(this,b)===void 0)te(this,b,t);else if(ot(m(this,b)))this.addExpression(t);else if(Bn(m(this,b)))m(this,b).arguments.push(t);else if(ve(m(this,b)))if(F(m(this,b))){let s=z(m(this,b));s&&re(s)?lt(m(this,b),s,t):s&&ms(s,t)}else console.log("what do we do with value, in a complete expression")}closeBrace(){m(this,le).pop()}get expression(){return m(this,b)}toJSON(){var e;return(e=m(this,b))==null?void 0:e.toJSON()}};b=new WeakMap,le=new WeakMap;var gs=(n,e)=>{let t=new Tt,s=n.cursor();do{let{name:i,from:o,to:r}=s;switch(i){case"AndCondition":t.setCondition("and");break;case"OrCondition":t.setCondition("or");break;case"RelationalExpression":t.setCondition();break;case"ArithmeticExpression":t.addExpression(new wt);break;case"Column":{let l=e.substring(o,r);t.setColumn(l)}break;case"Function":{let l=e.substring(o,r);t.setFunction(l)}break;case"Times":case"Divide":case"Plus":case"Minus":{let l=e.substring(o,r);t.setArithmeticOp(l)}break;case"RelationalOperator":{let l=e.substring(o,r);t.setRelationalOperator(l)}break;case"False":case"True":{let l=e.substring(o,r);t.setValue(l==="true")}break;case"String":t.setValue(e.substring(o+1,r-1));break;case"Number":t.setValue(parseFloat(e.substring(o,r)));break;case"CloseBrace":t.closeBrace();break;default:}}while(s.next());return t.toJSON()};var Qn=it.configure({strict:!0}),xs=["Number","String"],Nt=[...xs,"AndCondition","ArithmeticExpression","BooleanOperator","RelationalOperatorOperator","CallExpression","CloseBrace","Column","Comma","ConditionalExpression","Divide","Equal","If","Minus","OpenBrace","OrCondition","ParenthesizedExpression","Plus","RelationalExpression","RelationalOperator","Times"],Cs=n=>{try{return Qn.parse(n),!0}catch{return!1}},Rt=n=>{let{lastChild:e}=n;for(;e&&!Nt.includes(e.name);)e=e.prevSibling,console.log(e==null?void 0:e.name);return e},bs=n=>{if((n==null?void 0:n.name)==="RelationalExpression"){let{firstChild:e}=n,t=Rt(n);if((e==null?void 0:e.name)==="Column"&&typeof(t==null?void 0:t.name)=="string"&&xs.includes(t.name))return!0}return!1};import{HighlightStyle as zn,syntaxHighlighting as Mn,tags as ys}from"@vuu-ui/vuu-codemirror";var $n=zn.define([{tag:ys.variableName,color:"var(--vuuFilterEditor-variableColor)"},{tag:ys.comment,color:"green",fontStyle:"italic"}]),vs=Mn($n);import{EditorView as Un}from"@vuu-ui/vuu-codemirror";var ks=Un.theme({"&":{border:"solid 1px var(--salt-container-primary-borderColor)",color:"var(--vuuFilterEditor-color)",backgroundColor:"var(--vuuFilterEditor-background)"},".cm-content":{caretColor:"var(--vuuFilterEditor-cursorColor)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--vuuFilterEditor-cursorColor)"},"&.cm-focused .cm-selectionBackground, ::selection":{backgroundColor:"var(--vuuFilterEditor-selectionBackground)"},".cm-selectionBackground, ::selection":{backgroundColor:"var(--vuuFilterEditor-selectionBackground)"},".cm-scroller":{fontFamily:"var(--vuuFilterEditor-fontFamily)"},".cm-tooltip":{background:"var(--vuuFilterEditor-tooltipBackground)",border:"var(--vuuFilterEditor-tooltipBorder)",boxShadow:"var(--vuuFilterEditor-tooltipElevation)","&.cm-tooltip-autocomplete > ul":{fontFamily:"var(--vuuFilterEditor-fontFamily)",fontSize:"var(--vuuFilterEditor-fontSize)",maxHeight:"240px"},"&.cm-tooltip-autocomplete > ul > li":{height:"var(--vuuFilterEditor-suggestion-height)",padding:"0 3px",lineHeight:"var(--vuuFilterEditor-suggestion-height)"},"&.cm-tooltip-autocomplete li[aria-selected]":{background:"var(--vuuFilterEditor-suggestion-selectedBackground)",color:"var(--vuuFilterEditor-suggestion-selectedColor)"},"&.cm-tooltip-autocomplete li .cm-completionDetail":{color:"var(--vuuFilterEditor-suggestion-detailColor)"}}},{dark:!1});import{booleanJoinSuggestions as Gn,getNamedParentNode as Es,getPreviousNode as _n,getValue as j,syntaxTree as Wn}from"@vuu-ui/vuu-codemirror";import{useCallback as Os}from"react";var Hn=(n,e)=>e?n.map(t=>{var s;return{...t,apply:typeof t.apply=="function"?t.apply:`${e}${(s=t.apply)!=null?s:t.label}`}}):n,Xn=n=>n===void 0?!1:["Times","Divide","Plus","Minus"].includes(n.name),we=(n,e)=>{var i;let{lastChild:t}=n,{pos:s}=e;for(;t;)if(t.from<s&&Nt.includes(t.name)){if(t.name==="ParenthesizedExpression"){let r=(i=t.firstChild)==null?void 0:i.nextSibling;r&&(t=r)}return t}else t=t.prevSibling},Ss=(n,e)=>{var t;if(n.name==="ArgList"){let s=n.prevSibling;if(s)return j(s,e)}else if(n.name==="OpenBrace"){let s=(t=n.parent)==null?void 0:t.prevSibling;if((s==null?void 0:s.name)==="Function")return j(s,e)}},Ps=(n,e)=>{if(n.name==="RelationalExpression"){let t=Rt(n);if((t==null?void 0:t.name)==="RelationalOperator")return j(t,e)}else{let t=n.prevSibling;if((t==null?void 0:t.name)==="RelationalOperator")return j(t,e)}},Ft=(n,e)=>{var t;if(n.name==="RelationalExpression"){if(((t=n.firstChild)==null?void 0:t.name)==="Column")return j(n.firstChild,e)}else{let s=n.prevSibling;if((s==null?void 0:s.name)==="Column")return j(s,e);if((s==null?void 0:s.name)==="RelationalOperator")return Ft(s,e)}},It=async(n,e,t,s={})=>{let i=await e.getSuggestions(t,s),{startsWith:o=""}=s;return{from:n.pos-o.length,options:i}},Bt=(n,e,t,s,i)=>{let o=we(n,e);switch(console.log(`conditional expression last child ${o==null?void 0:o.name}`),o==null?void 0:o.name){case"If":return It(e,t,"expression",{prefix:"( "});case"OpenBrace":return It(e,t,"expression");case"Condition":return It(e,t,"expression",{prefix:", "});case"CloseBrace":if(s){let r=[{apply:()=>{i==null||i()},label:"Save Expression",boost:10}];return{from:e.pos,options:r}}}},Vn=(n,e)=>{let t=[{apply:()=>{e==null||e()},label:"Save Expression",boost:10}];return{from:n.pos,options:t}},ws=(n,e)=>{let t=Os(async(s,i,o={})=>{let r=await n.getSuggestions(i,o),{startsWith:l=""}=o;return{from:s.pos-l.length,options:r}},[n]);return Os(async s=>{var h,d;let{state:i,pos:o}=s,r=(h=s.matchBefore(/\w*/))!=null?h:{from:0,to:0,text:void 0},a=Wn(i).resolveInner(o,-1),u=i.doc.toString(),c=Cs(u);switch(console.log({nodeBeforeName:a.name}),a.name){case"If":return console.log("conditional expression If"),t(s,"expression",{prefix:"( "});case"Condition":{let p=we(a,s);if((p==null?void 0:p.name)==="Column"){let f=_n(p);if((f==null?void 0:f.name)!=="RelationalOperator")return t(s,"condition-operator",{columnName:j(p,i)});console.log(`Condition last child Column, prev child ${f==null?void 0:f.name}`)}else if((p==null?void 0:p.name)==="RelationalOperator")return t(s,"expression");console.log(`condition last child ${p==null?void 0:p.name}`)}break;case"ConditionalExpression":return Bt(a,s,n);case"RelationalExpression":{if(bs(a))return{from:s.pos,options:Gn.concat({label:", <truthy expression>, <falsy expression>",apply:", "})};{let p=Ps(a,i),f=Ft(a,i);if(p)return t(s,"expression");{let x=await n.getSuggestions("condition-operator",{columnName:f});return{from:s.pos,options:x}}}}break;case"RelationalOperator":return t(s,"expression");case"String":{let p=Ps(a,i),f=Ft(a,i),{from:x,to:g}=a;if(g-x===2&&s.pos===x+1){if(f&&p)return t(s,"columnValue",{columnName:f,operator:p,startsWith:r.text})}else if(g-x>2&&s.pos===g)return t(s,"expression",{prefix:", "});console.log(`we have a string, column is ${f} ${x} ${g}`)}break;case"ArithmeticExpression":{let p=we(a,s);if((p==null?void 0:p.name)==="Column")return t(s,"expression");if(Xn(p)){let f=p.name;return t(s,"column",{operator:f})}}break;case"OpenBrace":{let p=Ss(a,i);return t(s,"expression",{functionName:p})}break;case"ArgList":{let p=Ss(a,i),f=we(a,s),x=(f==null?void 0:f.name)==="OpenBrace"?void 0:",",g=await n.getSuggestions("expression",{functionName:p});return g=x?Hn(g,", "):g,(f==null?void 0:f.name)!=="OpenBrace"&&(f==null?void 0:f.name)!=="Comma"&&(g=[{apply:") ",boost:10,label:"Done - no more arguments"}].concat(g)),{from:s.pos,options:g}}case"Equal":if(u.trim()==="=")return t(s,"expression");break;case"ParenthesizedExpression":case"ColumnDefinitionExpression":if(s.pos===0)return t(s,"expression");{let p=we(a,s);if((p==null?void 0:p.name)==="Column"){if(c){let f=[{apply:()=>{e.current()},label:"Save Expression",boost:10}],x=j(p,i),g=await n.getSuggestions("operator",{columnName:x});return{from:s.pos,options:f.concat(g)}}}else if((p==null?void 0:p.name)==="CallExpression"){if(c){let f=[{apply:()=>{e.current()},label:"Save Expression",boost:10}];return{from:s.pos,options:f}}}else if((p==null?void 0:p.name)==="ArithmeticExpression"){if(c){let f=[{apply:()=>{e.current()},label:"Save Expression",boost:10}],x=we(p,s);if((x==null?void 0:x.name)==="Column"){let g=j(x,i),P=await n.getSuggestions("operator",{columnName:g});f=f.concat(P)}return{from:s.pos,options:f}}}else if((p==null?void 0:p.name)==="ConditionalExpression")return Bt(p,s,n,c,e.current);break}case"Column":if(await n.isPartialMatch("expression",void 0,r.text))return t(s,"expression",{startsWith:r.text});break;case"Comma":{let p=Es(a);if((p==null?void 0:p.name)==="ConditionalExpression")return t(s,"expression")}break;case"CloseBrace":{let p=Es(a);if((p==null?void 0:p.name)==="ConditionalExpression")return Bt(p,s,n,c,e.current);if((p==null?void 0:p.name)==="ArgList"&&c)return Vn(s,e.current);console.log(`does closebrace denote an ARgList or a parenthetised expression ? ${p}`)}break;default:((d=a==null?void 0:a.prevSibling)==null?void 0:d.name)==="FilterClause"&&console.log("looks like we ight be a or|and operator")}},[t,e,n])};var We=n=>{if(n.current==null)throw Error("EditorView not defined");return n.current},ti=()=>"vuuSuggestion",si=()=>console.log("noooop"),ni=n=>"expressionType"in n,ii=n=>{if(ni(n)){let e=Ds("div","expression-type-container"),t=Ds("span","expression-type",n.expressionType);return e.appendChild(t),e}else return null},Ns=({onChange:n,onSubmitExpression:e,suggestionProvider:t})=>{let s=Qt(null),i=Qt(si),o=Qt(),r=ws(t,i),[l,a]=ei(()=>{let u=()=>{let x=We(o),g=x.state.doc.toString(),P=Jn(x.state,x.state.doc.length,5e3);if(P){let T=gs(P,g);return[g,T]}else return["",void 0]},c=()=>{We(o).setState(f())},h=()=>{let[x,g]=u();e==null||e(x,g),c()},d=x=>Lt.of([{key:x,run(){return h(),!0}}]),p=x=>Lt.of([{key:x,run(){return Ts(We(o)),!0}}]),f=()=>jn.create({doc:"",extensions:[qn,Yn({addToOptions:[{render:ii,position:70}],override:[r],optionClass:ti}),ds(),Lt.of(Zn),d("Ctrl-Enter"),p("ArrowDown"),As.updateListener.of(x=>{let g=We(o);if(x.docChanged){Ts(g);let P=g.state.doc.toString();n==null||n(P,void 0)}}),ks,vs]});return i.current=()=>{h(),setTimeout(()=>{We(o).focus()},100)},[f,c]},[r,n,e]);return Kn(()=>{if(!s.current)throw Error("editor not in dom");return o.current=new As({state:l(),parent:s.current}),()=>{var u;(u=o.current)==null||u.destroy()}},[r,l]),{editorRef:s,clearInput:a}};import{jsx as oi}from"react/jsx-runtime";var ri="vuuColumnExpressionInput",Rs=({onChange:n,onSubmitExpression:e,suggestionProvider:t})=>{let{editorRef:s}=Ns({onChange:n,onSubmitExpression:e,suggestionProvider:t});return oi("div",{className:`${ri}`,ref:s})};import{AnnotationType as li,getRelationalOperators as ai,numericOperators as ui,stringOperators as pi,toSuggestions as hi}from"@vuu-ui/vuu-codemirror";import{getTypeaheadParams as ci,useTypeaheadSuggestions as fi}from"@vuu-ui/vuu-data";import{isNumericColumn as Mt,isTextColumn as di}from"@vuu-ui/vuu-utils";import{useCallback as zt,useRef as mi}from"react";var Ae=[{accepts:"string",description:"Returns multiple string values as a single joined string. Arguments may be string literal values, string columns or other string expressions. Non string arguments may also be included, these will be converted to strings.",example:{expression:'concatenate("example", "-test")',result:'"example-test"'},name:"concatenate",params:{description:"( string, string, [ string* ] )"},type:"string"},{accepts:["string","string"],description:"Tests a string value to determine whether it contains a given substring. Accepts two arguments: source text and target substring. Returns true if <source text> contains one or more occurrences of <target subscring>",example:{expression:'contains("Royal Bank of Scotland", "bank")',result:"true"},name:"contains",params:{description:"( string )"},type:"boolean"},{accepts:["string","number"],description:"Returns the leftmost <number> characters from <string>. First argument may be a string literal, string column or other string expression.",example:{expression:'left("USD Benchmark Report", 3)',result:'"USD"'},name:"left",params:{count:2,description:"( string, number )"},type:"string"},{accepts:"string",description:"Returns the number of characters in <string>. Argument may be a string literal, string column or other string expression.",example:{expression:'len("example")',result:"7"},name:"len",params:{description:"(string)"},type:"number"},{accepts:"string",description:"Convert a string value to lowercase. Argument may be a string column or other string expression.",example:{expression:'lower("examPLE")',result:'"example"'},name:"lower",params:{description:"( string )"},type:"string"},{accepts:"string",description:"Convert a string value to uppercase. Argument may be a string column or other string expression.",example:{expression:'upper("example")',result:'"EXAMPLE"'},name:"upper",params:{description:"( string )"},type:"string"},{accepts:["string","number"],description:"Returns the rightmost <number> characters from <string>. First argument may be a string literal, string column or other string expression.",example:{expression:"blah",result:"blah"},name:"right",params:{description:"( string )"},type:"string"},{accepts:["string","string","string"],description:"Replace characters within a string. Accepts three arguments: source text, text to replace and replacement text. Returns a copy of <source text> with any occurrences of <text to replace> replaced by <replacement text>",example:{expression:"blah",result:"blah"},name:"replace",params:{description:"( string )"},type:"string"},{accepts:"number",description:"Converts a number to a string.",example:{expression:"blah",result:"blah"},name:"text",params:{description:"( string )"},type:"string"},{accepts:"string",description:"Tests a string value to determine whether it starts with a given substring. Accepts two arguments: source text and target substring. Returns true if <source text> starts with <target subscring>.",example:{expression:"blah",result:"blah"},name:"starts",params:{description:"( string )"},type:"boolean"},{accepts:"string",description:"Tests a string value to determine whether it ends with a given substring. Accepts two arguments: source text and target substring. Returns true if <source text> ends with <target subscring>.",example:{expression:"blah",result:"blah"},name:"ends",params:{description:"( string )"},type:"boolean"},{accepts:"number",description:"blah",example:{expression:"blah",result:"blah"},name:"min",params:{description:"( string )"},type:"number"},{accepts:"number",description:"blah",example:{expression:"blah",result:"blah"},name:"max",params:{description:"( string )"},type:"number"},{accepts:"number",description:"blah",example:{expression:"blah",result:"blah"},name:"sum",params:{description:"( string )"},type:"number"},{accepts:"number",description:"blah",example:{expression:"blah",result:"blah"},name:"round",params:{description:"( string )"},type:"number"},{accepts:"any",description:"blah",example:{expression:"blah",result:"blah"},name:"or",params:{description:"( string )"},type:"boolean"},{accepts:"any",description:"blah",example:{expression:"blah",result:"blah"},name:"and",params:{description:"( string )"},type:"boolean"},{accepts:"any",description:"Return one of two possible result values, depending on the evaluation of a filter expression. If <filterExpression> resolves to true, result is <expression1>, otherwise <expression2>. ",example:{expression:"blah",result:"blah"},name:"if",params:{description:"( filterExpression, expression1, expression 2)"},type:"variable"}];import{createEl as J}from"@vuu-ui/vuu-utils";var Is=({name:n,description:e,example:t,params:s,type:i})=>{let o=J("div","vuuFunctionDoc"),r=J("div","function-heading"),l=J("span","function-name",n),a=J("span","param-list",s.description),u=J("span","function-type",i);r.appendChild(l),r.appendChild(a),r.appendChild(u);let c=J("p",void 0,e);if(o.appendChild(r),o.appendChild(c),t){let h=J("div","example-container","Example:"),d=J("div","example-expression",t.expression),p=J("div","example-result",t.result);h.appendChild(d),h.appendChild(p),o.appendChild(h)}return o};var gi=[],ae=n=>n.map(e=>{var t;return{...e,apply:((t=e.apply)!=null?t:e.label)+" "}}),xi=(n,{functionName:e,operator:t})=>{if(t)return n.filter(Mt);if(e){let s=Ae.find(i=>i.name===e);if(s)switch(s.accepts){case"string":return n.filter(di);case"number":return n.filter(Mt);default:return n}}return n},Bs=(n,e)=>xi(n,e).map(s=>{var o;let i=(o=s.label)!=null?o:s.name;return{apply:e.prefix?`${e.prefix}${i}`:i,label:i,boost:5,type:"column",expressionType:s.serverDataType}}),Ci=[{apply:"* ",boost:2,label:"*",type:"operator"},{apply:"/ ",boost:2,label:"/",type:"operator"},{apply:"+ ",boost:2,label:"+",type:"operator"},{apply:"- ",boost:2,label:"-",type:"operator"}],bi=n=>n===void 0||Mt(n)?Ci:gi,yi=n=>{switch(n.serverDataType){case"string":case"char":return ae(pi);case"int":case"long":case"double":return ae(ui)}},$t=n=>({apply:`${n.name}( `,boost:2,expressionType:n.type,info:()=>Is(n),label:n.name,type:"function"}),vi=n=>{if(n){if(typeof n.accepts=="string")return n.accepts;if(Array.isArray(n.accepts))return n.accepts.every(e=>e==="string")?"string":"any"}return"any"},ki=Ae.map($t),Ei=({functionName:n})=>{if(n){let e=Ae.find(s=>s.name===n),t=vi(e);if(e)switch(t){case"string":return Ae.filter(s=>s.type==="string"||s.type==="variable").map($t);case"number":return Ae.filter(s=>s.type==="number"||s.type==="variable").map($t);default:}}return ki},Oi={},Fs=({columns:n,table:e})=>{let t=zt(l=>l?n.find(a=>a.name===l):void 0,[n]),s=mi(),i=fi(),o=zt(async(l,a=Oi)=>{let{columnName:u,functionName:c,operator:h,prefix:d}=a;switch(l){case"expression":{let p=await ae(Bs(n,{functionName:c,prefix:d})).concat(Ei(a));return s.current=p}case"column":{let p=await Bs(n,a);return s.current=ae(p)}case"operator":{let p=await bi(t(u));return s.current=ae(p)}case"relational-operator":{let p=await ai(t(u));return s.current=ae(p)}case"condition-operator":{let p=t(u);if(p){let f=await yi(p);if(f)return s.current=ae(f)}}break;case"columnValue":if(u&&h){let p=ci(e,u),f=await i(p);return s.current=hi(f,{suffix:""}),s.current.forEach(x=>{x.apply=(g,P,T)=>{let w=new li,k=T+P.label.length+1;g.dispatch({changes:{from:T,insert:P.label},selection:{anchor:k,head:k},annotations:w.of(P)})}}),s.current}break}return[]},[n,t,i,e]),r=zt(async(l,a,u)=>{let{current:c}=s,h=!1,d=c||await o(l,{columnName:a});if(u&&d)for(let p of d){if(p.label===u)return!1;p.label.startsWith(u)&&(h=!0)}return h},[o]);return{getSuggestions:o,isPartialMatch:r}};import{Button as Vt,Panel as Sr}from"@salt-ds/core";import Pr from"classnames";import{useCallback as Ye,useState as nn}from"react";import{List as Qs}from"@heswell/salt-lab";import{Button as He,Text as zs,useIdMemo as Ai}from"@salt-ds/core";import{useCallback as ue,useState as Ti}from"react";import{ListItem as Si}from"@heswell/salt-lab";import Pi from"classnames";import{jsx as Ut,jsxs as wi}from"react/jsx-runtime";var Te="vuuColumnListItem",Ls=({className:n,item:e,label:t,style:s,...i})=>{let o=Pi(Te,n,{[`${Te}-calculated`]:e==null?void 0:e.expression,[`${Te}-hidden`]:e==null?void 0:e.hidden});return wi(Si,{className:o,...i,children:[Ut("span",{className:`${Te}-iconType`}),Ut("label",{className:`${Te}-label`,children:t}),Ut("span",{className:`${Te}-iconHidden`})]})};import{jsx as B,jsxs as Ne}from"react/jsx-runtime";var De="vuuColumnPicker",Di=(n,e)=>n.filter(t=>e.find(s=>s.name===t.name)==null),Ms=({availableColumns:n,id:e,dispatchColumnAction:t,onAddCalculatedColumnClick:s,onSelectionChange:i,chosenColumns:o,selectedColumn:r})=>{let[l,a]=Ti([]),u=Ai(e),c=Di(n,o),h=ue(()=>{l.length>0&&(a([]),t({type:"addColumn",columns:l}))},[t,l]),d=ue(()=>r&&t({type:"removeColumn",column:r}),[r,t]),p=ue(()=>r&&t({type:"moveColumn",column:r,moveBy:-1}),[t,r]),f=ue(()=>r&&t({type:"moveColumn",column:r,moveBy:1}),[t,r]),x=ue((T,w)=>a(w),[]),g=ue((T,w)=>i==null?void 0:i(w),[i]),P=ue((T,w)=>{t({type:"moveColumn",moveFrom:T,moveTo:w})},[t]);return Ne("div",{className:De,id:u,children:[Ne("div",{className:`${De}-listColumn`,children:[B("label",{htmlFor:`available-${u}`,children:B(zs,{as:"h4",children:"Available Columns"})}),B("div",{className:`${De}-listContainer`,style:{flex:1,overflow:"hidden"},children:B(Qs,{borderless:!0,checkable:!1,height:"100%",id:`available-${u}`,itemHeight:24,itemToString:T=>T.name,onSelectionChange:x,selected:l,selectionStrategy:"extended",source:c})}),B("div",{style:{display:"flex",alignItems:"center",flex:"0 0 32px",marginTop:"var(--salt-size-basis-unit)"},children:Ne(He,{onClick:h,disabled:l.length===0,children:["Show",B("span",{"data-icon":"arrow-thin-right",style:{marginLeft:8}})]})})]}),Ne("div",{className:`${De}-listColumn`,children:[B("label",{htmlFor:`selected-${u}`,children:B(zs,{as:"h4",children:"Included Columns"})}),B("div",{className:`${De}-listContainer`,style:{flex:1,overflow:"hidden"},children:B(Qs,{ListItem:Ls,allowDragDrop:!0,borderless:!0,height:"100%",id:`selected-${u}`,itemHeight:24,itemToString:T=>T.name,onMoveListItem:P,onSelectionChange:g,selected:r,style:{flex:1},source:o})}),Ne("div",{style:{alignItems:"center",flex:"0 0 32px",display:"flex",gap:6,marginTop:"var(--salt-size-basis-unit)"},children:[Ne(He,{onClick:d,disabled:r===null,children:[B("span",{"data-icon":"arrow-thin-left",style:{marginRight:8}}),"Hide"]}),B(He,{"aria-label":"Move column up",onClick:p,disabled:r===null||(o==null?void 0:o.indexOf(r))===0,style:{width:28},children:B("span",{"data-icon":"arrow-thin-up"})}),B(He,{"aria-label":"Move column down",onClick:f,disabled:r===null||o.indexOf(r)===o.length-1,style:{width:28},children:B("span",{"data-icon":"arrow-thin-down"})}),B(He,{"aria-label":"Add calculated column",className:`${De}-addCalculatedColumn`,onClick:s,variant:"primary",children:B("span",{"data-icon":"add"})})]})]})]})};import{Stack as Yi}from"@vuu-ui/vuu-layout";import{Checkbox as Zi,FormField as pe,Input as _t,RadioButton as Xe,RadioButtonGroup as Vs,StepperInput as ji}from"@heswell/salt-lab";import{Panel as Ys,Text as Ji}from"@salt-ds/core";import qi from"classnames";import{useCallback as Ie,useState as Ki}from"react";import{getRegisteredCellRenderers as Mi}from"@vuu-ui/vuu-utils";import{Dropdown as $i}from"@heswell/salt-lab";import{Panel as Ui}from"@salt-ds/core";import Ws from"classnames";import{useMemo as Gi}from"react";import{FormField as Ni,StepperInput as Ri,Switch as $s}from"@heswell/salt-lab";import{Text as Ii}from"@salt-ds/core";import{useCallback as at}from"react";import{Fragment as Us,jsx as Re,jsxs as Li}from"react/jsx-runtime";var Bi={alignOnDecimals:!1,decimals:4,zeroPad:!1},Fi=(n,e)=>{let t=typeof n=="object"&&n.formatting?n.formatting:{};return["alignOnDecimals","decimals","zeroPad"].reduce((i,o)=>t[o]!==void 0?{...i,[o]:t[o]}:(e==null?void 0:e[o])!==void 0?{...i,[o]:e[o]}:i,Bi)},Gs=({column:n,dispatchColumnAction:e})=>{let{decimals:t,alignOnDecimals:s,zeroPad:i}=Fi(n==null?void 0:n.type),o=at(u=>e({type:"updateColumnTypeFormatting",column:n,...u}),[n,e]),r=at(u=>o({decimals:parseInt(u.toString(),10)}),[o]),l=at((u,c)=>o({alignOnDecimals:c}),[o]),a=at((u,c)=>o({zeroPad:c}),[o]);switch(n.serverDataType){case"double":return Li(Us,{children:[Re(Ni,{label:"No of Decimals",labelPlacement:"top",children:Re(Ri,{value:t,onChange:r})}),Re($s,{checked:s,label:"Align on decimals",LabelProps:{className:"vuuColumnPanelSwitch"},onChange:l}),Re($s,{checked:i,label:"Zero pad",LabelProps:{className:"vuuColumnPanelSwitch"},onChange:a})]});case"long":case"int":return Re(Us,{children:Re(Ii,{children:"Work in progress"})});default:return null}};import{Fragment as Qi,jsx as zi}from"react/jsx-runtime";var _s=({column:n,dispatchColumnAction:e})=>zi(Qi,{children:"String"});import{Fragment as Xi,jsx as ut,jsxs as Vi}from"react/jsx-runtime";var Gt="vuuColumnTypePanel",_i=["Default Renderer (int, long)"],Wi=["Default Renderer (double)"],Hs=["Default Renderer (string)"],Hi=n=>{let t=Mi(n.serverDataType).map(s=>s.name);switch(console.log({customRendererNames:t}),n.serverDataType){case"char":case"string":return Hs;case"int":case"long":return _i;case"double":return Wi.concat(t);default:return Hs}},Xs=({className:n,column:e,dispatchColumnAction:t,...s})=>{let i=Gi(()=>{switch(e.serverDataType){case"double":case"int":case"long":return ut(Gs,{column:e,dispatchColumnAction:t});default:return ut(_s,{column:e,dispatchColumnAction:t})}},[e,t]),{serverDataType:o="string"}=e,r=Hi(e);return Vi(Xi,{children:[ut($i,{className:Ws(`${Gt}-renderer`),fullWidth:!0,selected:r[0],source:r}),ut(Ui,{...s,className:Ws(Gt,n,`${Gt}-${o}`),children:i})]})};import{jsx as D,jsxs as Be}from"react/jsx-runtime";var Zs="vuuColumnSettingsPanel",er={className:"salt-density-high"},js=()=>null,Js=({column:n,dispatchColumnAction:e,style:t,...s})=>{var d,p,f,x;let[i,o]=Ki(0),r=Ie(g=>e({type:"updateColumnProp",column:n,...g}),[n,e]),l=Ie(g=>r({align:g.target.value}),[r]),a=Ie(g=>r({pin:g.target.value}),[r]),u=Ie((g,P)=>r({hidden:P}),[r]),c=Ie((g,P)=>r({label:P}),[r]),h=Ie(g=>r({width:parseInt(g.toString(),10)}),[r]);return Be("div",{className:Zs,...s,style:{...t},children:[D(Ji,{as:"h4",children:"Column Settings"}),Be(Yi,{active:i,showTabs:!0,className:qi(`${Zs}-columnTabs`),onTabSelectionChanged:o,TabstripProps:er,children:[Be(Ys,{title:"Column",children:[D(pe,{label:"Hidden",labelPlacement:"left",children:D(Zi,{checked:n.hidden===!0,onChange:u})}),D(pe,{label:"Label",labelPlacement:"left",children:D(_t,{value:(d=n.label)!=null?d:n.name,onChange:c})}),D(pe,{label:"Width",labelPlacement:"left",children:D(ji,{value:(p=n.width)!=null?p:100,onChange:h})}),D(pe,{label:"Align",labelPlacement:"left",ActivationIndicatorComponent:js,children:Be(Vs,{"aria-label":"Column Align",value:(f=n.align)!=null?f:"left",legend:"Align",onChange:l,children:[D(Xe,{label:"Left",value:"left"}),D(Xe,{label:"Right",value:"right"})]})}),D(pe,{label:"Pin Column",labelPlacement:"left",ActivationIndicatorComponent:js,children:Be(Vs,{"aria-label":"Pin Column",value:(x=n.pin)!=null?x:"",legend:"Pin Column",onChange:a,children:[D(Xe,{label:"Do not pin",value:""}),D(Xe,{label:"Left",value:"left"}),D(Xe,{label:"Right",value:"right"})]})})]}),D(Xs,{column:n,dispatchColumnAction:e,title:"Data Cell"}),Be(Ys,{title:"Vuu",variant:"secondary",children:[D(pe,{label:"Name",labelPlacement:"top",readOnly:!0,variant:"secondary",children:D(_t,{value:n.name})}),D(pe,{label:"Vuu type",labelPlacement:"top",readOnly:!0,variant:"secondary",children:D(_t,{value:n.serverDataType})})]})]})]})};import{FormField as qs,RadioButton as Wt,RadioButtonGroup as tr,StepperInput as sr}from"@heswell/salt-lab";import{Panel as nr,Text as ir}from"@salt-ds/core";import{useCallback as Ht}from"react";import{jsx as he,jsxs as Xt}from"react/jsx-runtime";var rr="vuuGridSettingsPanel",or=()=>null,Ks=({config:n,dispatchColumnAction:e,style:t,...s})=>{var l;let i=Ht(a=>e({type:"updateGridSettings",...a}),[e]),o=Ht(a=>i({columnFormatHeader:a.target.value}),[i]),r=Ht(a=>i({columnDefaultWidth:parseInt(a.toString(),10)}),[i]);return console.log(`GridSettingsPanel ${JSON.stringify(n.columns,null,2)}`),Xt("div",{className:rr,...s,style:{...t},children:[he(ir,{as:"h4",children:"Grid Settings"}),Xt(nr,{children:[he(qs,{label:"Format column labels",labelPlacement:"left",ActivationIndicatorComponent:or,children:Xt(tr,{"aria-label":"Format column labels",value:n.columnFormatHeader,legend:"Format column labels",onChange:o,children:[he(Wt,{label:"No Formatting",value:void 0}),he(Wt,{label:"Capitalize",value:"capitalize"}),he(Wt,{label:"Uppercase",value:"uppercase"})]})}),he(qs,{label:"Default Column Width",labelPlacement:"left",children:he(sr,{value:(l=n.columnDefaultWidth)!=null?l:100,onChange:r})})]})]})};import{useReducer as lr}from"react";import{moveItem as ar}from"@heswell/salt-lab";import{fromServerDataType as ur}from"@vuu-ui/vuu-utils";var pr=(n,e)=>{switch(console.log(`gridSettingsReducer ${e.type}`),e.type){case"addColumn":return hr(n,e);case"addCalculatedColumn":return cr(n,e);case"moveColumn":return dr(n,e);case"removeColumn":return fr(n,e);case"updateColumn":return n;case"updateColumnProp":return mr(n,e);case"updateGridSettings":return gr(n,e);case"updateColumnTypeFormatting":return xr(n,e);default:return n}},en=n=>{let[e,t]=lr(pr,n);return{gridSettings:e,dispatchColumnAction:t}};function hr(n,{column:e,columns:t,index:s=-1}){let{columns:i}=n;if(s===-1){if(Array.isArray(t))return{...n,columns:i.concat(t)};if(e)return{...n,columns:i.concat(e)}}return n}function cr(n,{columnName:e,columnType:t,expression:s}){let{columns:i}=n,o={name:e,expression:s,serverDataType:t};return{...n,columns:i.concat(o)}}function fr(n,{column:e}){let{columns:t}=n;return{...n,columns:t.filter(s=>s.name!==e.name)}}function dr(n,{column:e,moveBy:t,moveFrom:s,moveTo:i}){let{columns:o}=n;if(e&&typeof t=="number"){let r=o.indexOf(e),l=o.slice(),[a]=l.splice(r,1);return l.splice(r+t,0,a),{...n,columns:l}}else return typeof s=="number"&&typeof i=="number"?{...n,columns:ar(o,s,i)}:n}function mr(n,{align:e,column:t,hidden:s,label:i,width:o}){let{columns:r}=n;return(e==="left"||e==="right")&&(r=Ve(r,{...t,align:e})),typeof s=="boolean"&&(r=Ve(r,{...t,hidden:s})),typeof i=="string"&&(r=Ve(r,{...t,label:i})),typeof o=="number"&&(r=Ve(r,{...t,width:o})),{...n,columns:r}}function gr(n,{columnFormatHeader:e}){return{...n,columnFormatHeader:e!=null?e:n.columnFormatHeader}}function xr(n,{alignOnDecimals:e,column:t,decimals:s,zeroPad:i}){let{columns:o}=n;if(o.find(l=>l.name===t.name)){let{serverDataType:l="string",type:a=ur(l)}=t,u=typeof a=="string"?{name:a}:{...a};return typeof e=="boolean"&&(u.formatting={...u.formatting,alignOnDecimals:e}),typeof s=="number"&&(u.formatting={...u.formatting,decimals:s}),typeof i=="boolean"&&(u.formatting={...u.formatting,zeroPad:i}),{...n,columns:Ve(o,{...t,type:u})}}else return n}function Ve(n,e){return n.map(t=>t.name===e.name?e:t)}import{Stack as wr}from"@vuu-ui/vuu-layout";import{FormField as Cr,Input as br}from"@heswell/salt-lab";import{Button as yr,Panel as vr,Text as kr}from"@salt-ds/core";import{useCallback as pt,useRef as Er,useState as tn}from"react";import{jsx as Fe,jsxs as Or}from"react/jsx-runtime";var sn=({columns:n,dispatchColumnAction:e,table:t})=>{let[s,i]=tn(""),[,o]=tn(),r=Er(""),l=Fs({columns:n,table:t}),a=pt(d=>{let{value:p}=d.target;i(p)},[]),u=pt(d=>{r.current=d},[]),c=pt((d,p)=>{console.log({source:d}),o(p)},[]),h=pt(()=>{r.current&&(console.log(`save expression ${JSON.stringify(r.current,null,2)}`),e({type:"addCalculatedColumn",columnName:s,expression:r.current,columnType:"string"}))},[s,e]);return Or(vr,{className:"vuuCalculatedColumnPanel",title:"Define Computed Column",children:[Fe(kr,{styleAs:"h4",children:"Define Computed Column"}),Fe(Cr,{label:"Column Name",labelPlacement:"left",children:Fe(br,{value:s,onChange:a})}),Fe(Rs,{onChange:u,onSubmitExpression:c,suggestionProvider:l}),Fe("div",{style:{marginTop:12},children:Fe(yr,{onClick:h,children:"Add Column"})})]})};import{jsx as q,jsxs as ct}from"react/jsx-runtime";var ht="vuuDatagridSettingsPanel",Ar=()=>{},Tr=["table-settings","column-chooser","column-settings","define-column"],Dr=(n,e)=>Tr[e],mu=({availableColumns:n,className:e,gridConfig:t,onCancel:s,onConfigChange:i,...o})=>{var k;console.log("DatagridSettingsPanel render");let[r,l]=nn(0),{gridSettings:a,dispatchColumnAction:u}=en(t),[c,h]=nn(null),d=Ye(y=>{h(y?y.name:null)},[]),p=Ye((y,C=!1)=>{console.log("1) DataGridSettingsPanel fire onConfigChange"),i==null||i(a,C)},[a,i]),f=Ye(y=>{l(y)},[]),x=Ye(y=>p(y,!0),[p]),g=c===null?null:(k=a.columns.find(y=>y.name===c))!=null?k:null,P={activeTabIndex:r,enableRenameTab:!1,orientation:"vertical"},T=Ye(()=>l(3),[]),w=r===2?"right":void 0;return ct("div",{...o,className:Pr(ht,e),children:[ct(wr,{TabstripProps:P,className:`${ht}-stack`,getTabIcon:Dr,getTabLabel:Ar,active:r===2?1:r,onTabSelectionChanged:f,showTabs:!0,children:[q(Ks,{config:a,dispatchColumnAction:u}),ct("div",{className:`${ht}-columnPanels`,"data-align":w,children:[q(Ms,{availableColumns:n,chosenColumns:a.columns,dispatchColumnAction:u,onSelectionChange:d,onAddCalculatedColumnClick:T,selectedColumn:g}),g===null?q(Sr,{className:"vuuColumnSettingsPanel",children:"Select a column"}):q(Js,{column:g,dispatchColumnAction:u,style:{background:"white",flex:"1 0 150px"}})]}),q("div",{title:"Column Settings",children:"Column Settings"}),q(sn,{columns:a.columns,dispatchColumnAction:u,table:{module:"SIMUL",table:"instruments"}})]}),ct("div",{className:`${ht}-buttonBar`,children:[q(Vt,{onClick:s,children:"Cancel"}),q(Vt,{onClick:p,children:"Apply"}),q(Vt,{onClick:x,children:"Save"})]})]})};import{useEffect as Nr,useState as Yt}from"react";import Rr from"classnames";import{jsx as Le,jsxs as Ir}from"react/jsx-runtime";var Ze="vuuDatasourceStats",Zt=new Intl.NumberFormat,Au=({className:n,dataSource:e})=>{let[t,s]=Yt(e.optimize),[i,o]=Yt(e.range),[r,l]=Yt(e.size);Nr(()=>{s(e.optimize),l(e.size),e.on("optimize",s),e.on("resize",l),e.on("range",o)},[e]);let a=Rr(Ze,n),u=Zt.format(i.from),c=Zt.format(i.to-1),h=Zt.format(r);return Ir("div",{className:a,children:[Le("span",{children:"Showing rows"}),Le("span",{className:`${Ze}-range`,children:u}),Le("span",{className:`${Ze}-range`,children:c}),Le("span",{children:"of"}),Le("span",{className:`${Ze}-size`,children:h}),Le("span",{className:`${Ze}-optimize`,children:t})]})};export{Rs as ColumnExpressionInput,Nt as ColumnNamedTerms,Au as DataSourceStats,mu as DatagridSettingsPanel,ds as columnExpressionLanguageSupport,Cs as isCompleteExpression,bs as isCompleteRelationalExpression,Rt as lastNamedChild,Ns as useColumnExpressionEditor,Fs as useColumnExpressionSuggestionProvider,gs as walkTree};
1
+ var Je=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var u=(n,e,t)=>(Je(n,e,"read from private field"),t?t.call(n):e.get(n)),S=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},N=(n,e,t,o)=>(Je(n,e,"write to private field"),o?o.call(n,t):e.set(n,t),t);import{DOWN1 as Jn,DOWN2 as qn,metadataKeys as _n,registerComponent as Kn,UP1 as jn,UP2 as et}from"@vuu-ui/vuu-utils";import nt from"classnames";import{useEffect as Hn,useRef as Vn}from"react";import{isTypeDescriptor as zn}from"@vuu-ui/vuu-utils";import{getMovingValueDirection as Yn,isValidNumber as qe}from"@vuu-ui/vuu-utils";var Zn=[void 0,void 0,void 0,void 0];function _e(n,e,t){var x;let o=Vn(),[i,r,s,p]=o.current||Zn,{type:l}=t,c=zn(l)?(x=l.formatting)==null?void 0:x.decimals:void 0,C=n===i&&qe(e)&&qe(r)&&t===s?Yn(e,p,r,c):"";return Hn(()=>{o.current=[n,e,t,C]}),C}import{jsx as at,jsxs as lt}from"react/jsx-runtime";var tt=String.fromCharCode(11014),ot=String.fromCharCode(11015),{KEY:rt}=_n,ge="vuuBackgroundCell",G={ArrowOnly:"arrow",BackgroundOnly:"bg-only",ArrowBackground:"arrow-bg"},st=n=>{if(typeof n=="string")return G.BackgroundOnly;if(n){let{renderer:e}=n;return e&&e.flashStyle||G.BackgroundOnly}},it=({column:n,row:e})=>{let{key:t,type:o,valueFormatter:i}=n,r=e[t],s=st(o),p=_e(e[rt],r,n),l=s===G.ArrowOnly||s===G.ArrowBackground?p===jn||p===et?tt:p===Jn||p===qn?ot:null:null,c=p?" "+p:"",C=nt(ge,c,{[`${ge}-arrowOnly`]:s===G.ArrowOnly,[`${ge}-arrowBackground`]:s===G.ArrowBackground});return lt("div",{className:C,tabIndex:-1,children:[at("div",{className:`${ge}-flasher`,children:l}),i(e[n.key])]})};Kn("background",it,"cell-renderer",{serverDataType:["long","int","double"]});import{autocompletion as Dt,defaultKeymap as Rt,EditorState as At,EditorView as dn,ensureSyntaxTree as kt,keymap as Le,minimalSetup as Nt,startCompletion as gn}from"@vuu-ui/vuu-codemirror";import{createEl as fn}from"@vuu-ui/vuu-utils";import{useEffect as Qt,useMemo as Ft,useRef as Ie}from"react";import{LanguageSupport as ut,LRLanguage as ct,styleTags as mt,tags as Ce}from"@vuu-ui/vuu-codemirror";import{LRParser as pt}from"@lezer/lr";var fe=pt.deserialize({version:14,states:"&fOVQPOOO!SQPO'#C^OVQPO'#CcQ!pQPOOO#OQPO'#CkO#TQPO'#CrOOQO'#Cy'#CyO#YQPO,58}OVQPO,59QOVQPO,59QOVQPO,59VOVQPO'#CtOOQO,59^,59^OOQO1G.i1G.iOOQO1G.l1G.lO#kQPO1G.lO$fQPO'#CmO%WQQO1G.qOOQO'#C{'#C{O%cQPO,59`OOQO'#Cn'#CnO%wQPO,59XOVQPO,59ZOVQPO,59[OVQPO7+$]OVQPO'#CuO&`QPO1G.zOOQO1G.z1G.zO&hQQO'#C^O&rQQO1G.sO'ZQQO1G.uOOQO1G.v1G.vO'fQPO<<GwO'wQPO,59aOOQO-E6s-E6sOOQO7+$f7+$fOVQPOAN=cO(]QQO1G.lO(tQPOG22}OOQOLD(iLD(iO%wQPO,59QO%wQPO,59Q",stateData:")[~OlOS~ORUOSUOTUOUUOWQO`SOnPO~OWgXZQX[QX]QX^QXeQX~OjQXXQXpQXqQXrQXsQXtQXuQX~PnOZWO[WO]XO^XO~OWYO~OWZO~OX]OZWO[WO]XO^XO~OZWO[WO]Yi^YijYiXYipYiqYirYisYitYiuYieYi~OZWO[WO]XO^XOpdOqdOrdOsdOtdOudO~OehOvfOwgO~OXkOZWO[WO]XO^XOeiO~ORUOSUOTUOUUOWQO`SOnlO~OXsOeiO~OvQXwQX~PnOZxO[xO]yO^yOeaivaiwai~OwgOecivci~OZWO[WO]XO^XOetO~OZWO[WO]XO^XOXiaeia~OZxO[xO]Yi^YieYivYiwYi~OXwOZWO[WO]XO^XO~O`UTn~",goto:"#spPPqPPPPqPPqPPPPqP!R!W!R!RPq!Z!k!nPPP!tP#jmUOQWXYZefghitxyVbYfgRe`mTOQWXYZefghitxyR[TQjcRrjQROQVQS^WxQ_XU`YfgQcZQmeQphQqiQuyRvtQaYQnfRog",nodeNames:"\u26A0 ColumnDefinitionExpression Column Number String True False ParenthesizedExpression OpenBrace CloseBrace ArithmeticExpression Divide Times Plus Minus ConditionalExpression If RelationalExpression RelationalOperator AndCondition OrCondition Comma CallExpression Function ArgList",maxTerm:39,skippedNodes:[0],repeatNodeCount:1,tokenData:".^~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$jz{$o{|$t|}$y}!O%O!O!P%T!P!Q%c!Q![%h!^!_%s!_!`&Q!`!a&V!c!}&d#R#S&d#T#U&u#U#Y&d#Y#Z(Y#Z#]&d#]#^*j#^#c&d#c#d+f#d#h&d#h#i,b#i#o&d~#USl~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOu~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_OS~~$bP;=`<%l#m~$jOW~~$oOX~~$tO[~~$yO]~~%OOe~~%TO^~~%WP!Q![%Z~%`PR~!Q![%Z~%hOZ~~%mQR~!O!P%Z!Q![%h~%xPr~!_!`%{~&QOt~~&VOp~~&[Pq~!_!`&_~&dOs~P&iSnP!Q![&d!c!}&d#R#S&d#T#o&dR&zUnP!Q![&d!c!}&d#R#S&d#T#b&d#b#c'^#c#o&dR'cUnP!Q![&d!c!}&d#R#S&d#T#W&d#W#X'u#X#o&dR'|SvQnP!Q![&d!c!}&d#R#S&d#T#o&d~(_TnP!Q![&d!c!}&d#R#S&d#T#U(n#U#o&d~(sUnP!Q![&d!c!}&d#R#S&d#T#`&d#`#a)V#a#o&d~)[UnP!Q![&d!c!}&d#R#S&d#T#g&d#g#h)n#h#o&d~)sUnP!Q![&d!c!}&d#R#S&d#T#X&d#X#Y*V#Y#o&d~*^SU~nP!Q![&d!c!}&d#R#S&d#T#o&d~*oUnP!Q![&d!c!}&d#R#S&d#T#Y&d#Y#Z+R#Z#o&d~+YS`~nP!Q![&d!c!}&d#R#S&d#T#o&dR+kUnP!Q![&d!c!}&d#R#S&d#T#f&d#f#g+}#g#o&dR,USwQnP!Q![&d!c!}&d#R#S&d#T#o&d~,gUnP!Q![&d!c!}&d#R#S&d#T#f&d#f#g,y#g#o&d~-OUnP!Q![&d!c!}&d#R#S&d#T#i&d#i#j-b#j#o&d~-gUnP!Q![&d!c!}&d#R#S&d#T#X&d#X#Y-y#Y#o&d~.QST~nP!Q![&d!c!}&d#R#S&d#T#o&d",tokenizers:[0,1],topRules:{ColumnDefinitionExpression:[0,1]},tokenPrec:375});var dt=ct.define({name:"VuuColumnExpression",parser:fe.configure({props:[mt({Function:Ce.variableName,String:Ce.string,Or:Ce.emphasis,Operator:Ce.operator})]})}),Ke=()=>new ut(dt);var Pe=class{constructor(e){switch(this.value=e,typeof e){case"boolean":this.type="booleanLiteralExpression";break;case"number":this.type="numberLiteralExpression";break;default:this.type="stringLiteralExpression"}}toJSON(){return{type:this.type,value:this.value}}},Se=class{constructor(e){this.type="colExpression";this.column=e}toJSON(){return{type:this.type,column:this.column}}},se,F,Te=class{constructor(e="unknown"){S(this,se,[{type:"unknown"},{type:"unknown"}]);S(this,F,void 0);this.type="arithmeticExpression";N(this,F,e)}get op(){return u(this,F)}set op(e){N(this,F,e)}get expressions(){return u(this,se)}toJSON(){return{type:this.type,op:u(this,F),expressions:u(this,se)}}};se=new WeakMap,F=new WeakMap;var H,we=class{constructor(e){S(this,H,[]);this.type="callExpression";this.functionName=e}get expressions(){return u(this,H)}get arguments(){return u(this,H)}toJSON(){return{type:this.type,functionName:this.functionName,arguments:u(this,H).map(e=>{var t;return(t=e.toJSON)==null?void 0:t.call(e)})}}};H=new WeakMap;var ie,V,W=class{constructor(){S(this,ie,[{type:"unknown"},{type:"unknown"}]);S(this,V,"unknown");this.type="relationalExpression"}get op(){return u(this,V)}set op(e){N(this,V,e)}get expressions(){return u(this,ie)}toJSON(){return{type:this.type,op:u(this,V),expressions:u(this,ie)}}};ie=new WeakMap,V=new WeakMap;var ae,z,X=class{constructor(e){S(this,ae,[{type:"unknown"},{type:"unknown"}]);S(this,z,void 0);this.type="booleanCondition";N(this,z,e)}get op(){return u(this,z)}get expressions(){return u(this,ae)}toJSON(){return{type:this.type,op:u(this,z),expressions:u(this,ae).map(e=>{var t;return(t=e.toJSON)==null?void 0:t.call(e)})}}};ae=new WeakMap,z=new WeakMap;var T,re=class{constructor(e){S(this,T,void 0);this.type="conditionalExpression";N(this,T,[e?new X(e):new W,{type:"unknown"},{type:"unknown"}])}get expressions(){return u(this,T)}get condition(){return u(this,T)[0]}get truthyExpression(){return u(this,T)[1]}set truthyExpression(e){u(this,T)[1]=e}get falsyExpression(){return u(this,T)[2]}set falsyExpression(e){u(this,T)[2]=e}toJSON(){var e,t,o,i,r;return{type:this.type,condition:(t=(e=this.condition).toJSON)==null?void 0:t.call(e),truthyExpression:this.truthyExpression,falsyExpression:(r=(i=(o=this.falsyExpression)==null?void 0:o.toJSON)==null?void 0:i.call(o))!=null?r:this.falsyExpression}}};T=new WeakMap;var Q=n=>n.type==="unknown",xe=n=>n.type==="arithmeticExpression",gt=n=>n.type==="callExpression",M=n=>n.type==="conditionalExpression",ft=n=>n.type==="relationalExpression"||n.type==="booleanCondition";var Ct=n=>n.type==="booleanCondition",Re=n=>(n==null?void 0:n.type)==="relationalExpression";var P=n=>{if(Q(n))return n;if(Re(n)){let[e,t]=n.expressions;if(O(e))return P(e);if(n.op==="unknown")return n;if(O(t))return P(t)}else if(ft(n)){let{expressions:e=[]}=n;for(let t of e)if(O(t))return P(t)}else if(M(n)){let{condition:e,truthyExpression:t,falsyExpression:o}=n;if(O(e))return P(e);if(O(t))return P(t);if(O(o))return P(o)}else if(xe(n)){let{expressions:e=[]}=n;for(let t of e)if(O(t))return P(t)}},he=(n,e,t)=>{let{expressions:o=[]}=n;if(o.includes(e)){let i=o.indexOf(e);return o.splice(i,1,t),!0}else for(let i of o)if(he(i,e,t))return!0;return!1},O=n=>Q(n)?!0:M(n)?O(n.condition)||O(n.truthyExpression)||O(n.falsyExpression):Re(n)||Ct(n)?n.op===void 0||n.expressions.some(e=>O(e)):!1,je=(n,e)=>{let t=P(n);t?t.expressions?t.expressions.push(e):console.warn("don't know how to treat targetExpression"):console.error("no target expression found")},f,L,De=class{constructor(){S(this,f,void 0);S(this,L,[])}setCondition(e){if(u(this,f)===void 0)this.addExpression(new re(e));else if(M(u(this,f))){if(O(u(this,f).condition)){let t=e?new X(e):new W;this.addExpression(t)}else if(Q(u(this,f).truthyExpression))u(this,f).truthyExpression=new re(e);else if(O(u(this,f).truthyExpression)){let t=e?new X(e):new W;this.addExpression(t)}else if(Q(u(this,f).falsyExpression))u(this,f).falsyExpression=new re(e);else if(O(u(this,f).falsyExpression)){let t=e?new X(e):new W;this.addExpression(t)}}else console.error("setCondition called unexpectedly")}addExpression(e){if(u(this,L).length>0){let t=u(this,L).at(-1);t==null||t.arguments.push(e)}else if(u(this,f)===void 0)N(this,f,e);else if(xe(u(this,f))){let t=P(u(this,f));t&&Q(t)&&he(u(this,f),t,e)}else if(M(u(this,f))&&O(u(this,f))){let t=P(u(this,f));t&&Q(t)?he(u(this,f),t,e):t&&je(t,e)}}setFunction(e){let t=new we(e);this.addExpression(t),u(this,L).push(t)}setColumn(e){this.addExpression(new Se(e))}setArithmeticOp(e){let t=e,o=u(this,f);xe(o)&&(o.op=t)}setRelationalOperator(e){let t=e;if(u(this,f)&&M(u(this,f))){let o=P(u(this,f));Re(o)?o.op=t:console.error(`no target expression found (op = ${e})`)}}setValue(e){let t=new Pe(e);if(u(this,f)===void 0)N(this,f,t);else if(xe(u(this,f)))this.addExpression(t);else if(gt(u(this,f)))u(this,f).arguments.push(t);else if(M(u(this,f)))if(O(u(this,f))){let o=P(u(this,f));o&&Q(o)?he(u(this,f),o,t):o&&je(o,t)}else console.log("what do we do with value, in a complete expression")}closeBrace(){u(this,L).pop()}get expression(){return u(this,f)}toJSON(){var e;return(e=u(this,f))==null?void 0:e.toJSON()}};f=new WeakMap,L=new WeakMap;var en=(n,e)=>{let t=new De,o=n.cursor();do{let{name:i,from:r,to:s}=o;switch(i){case"AndCondition":t.setCondition("and");break;case"OrCondition":t.setCondition("or");break;case"RelationalExpression":t.setCondition();break;case"ArithmeticExpression":t.addExpression(new Te);break;case"Column":{let p=e.substring(r,s);t.setColumn(p)}break;case"Function":{let p=e.substring(r,s);t.setFunction(p)}break;case"Times":case"Divide":case"Plus":case"Minus":{let p=e.substring(r,s);t.setArithmeticOp(p)}break;case"RelationalOperator":{let p=e.substring(r,s);t.setRelationalOperator(p)}break;case"False":case"True":{let p=e.substring(r,s);t.setValue(p==="true")}break;case"String":t.setValue(e.substring(r+1,s-1));break;case"Number":t.setValue(parseFloat(e.substring(r,s)));break;case"CloseBrace":t.closeBrace();break;default:}}while(o.next());return t.toJSON()};var xt=fe.configure({strict:!0}),nn=["Number","String"],Ae=[...nn,"AndCondition","ArithmeticExpression","BooleanOperator","RelationalOperatorOperator","CallExpression","CloseBrace","Column","Comma","ConditionalExpression","Divide","Equal","If","Minus","OpenBrace","OrCondition","ParenthesizedExpression","Plus","RelationalExpression","RelationalOperator","Times"],tn=n=>{try{return xt.parse(n),!0}catch{return!1}},ke=n=>{let{lastChild:e}=n;for(;e&&!Ae.includes(e.name);)e=e.prevSibling,console.log(e==null?void 0:e.name);return e},on=n=>{if((n==null?void 0:n.name)==="RelationalExpression"){let{firstChild:e}=n,t=ke(n);if((e==null?void 0:e.name)==="Column"&&typeof(t==null?void 0:t.name)=="string"&&nn.includes(t.name))return!0}return!1};import{HighlightStyle as ht,syntaxHighlighting as yt,tags as rn}from"@vuu-ui/vuu-codemirror";var bt=ht.define([{tag:rn.variableName,color:"var(--vuuFilterEditor-variableColor)"},{tag:rn.comment,color:"green",fontStyle:"italic"}]),sn=yt(bt);import{EditorView as Et}from"@vuu-ui/vuu-codemirror";var an=Et.theme({"&":{border:"solid 1px var(--salt-container-primary-borderColor)",color:"var(--vuuFilterEditor-color)",backgroundColor:"var(--vuuFilterEditor-background)"},".cm-content":{caretColor:"var(--vuuFilterEditor-cursorColor)"},"&.cm-focused .cm-cursor":{borderLeftColor:"var(--vuuFilterEditor-cursorColor)"},"&.cm-focused .cm-selectionBackground, ::selection":{backgroundColor:"var(--vuuFilterEditor-selectionBackground)"},".cm-selectionBackground, ::selection":{backgroundColor:"var(--vuuFilterEditor-selectionBackground)"},".cm-scroller":{fontFamily:"var(--vuuFilterEditor-fontFamily)"},".cm-tooltip":{background:"var(--vuuFilterEditor-tooltipBackground)",border:"var(--vuuFilterEditor-tooltipBorder)",boxShadow:"var(--vuuFilterEditor-tooltipElevation)","&.cm-tooltip-autocomplete > ul":{fontFamily:"var(--vuuFilterEditor-fontFamily)",fontSize:"var(--vuuFilterEditor-fontSize)",maxHeight:"240px"},"&.cm-tooltip-autocomplete > ul > li":{height:"var(--vuuFilterEditor-suggestion-height)",padding:"0 3px",lineHeight:"var(--vuuFilterEditor-suggestion-height)"},"&.cm-tooltip-autocomplete li[aria-selected]":{background:"var(--vuuFilterEditor-suggestion-selectedBackground)",color:"var(--vuuFilterEditor-suggestion-selectedColor)"},"&.cm-tooltip-autocomplete li .cm-completionDetail":{color:"var(--vuuFilterEditor-suggestion-detailColor)"}}},{dark:!1});import{booleanJoinSuggestions as Ot,getNamedParentNode as ln,getPreviousNode as vt,getValue as R,syntaxTree as Pt}from"@vuu-ui/vuu-codemirror";import{useCallback as pn}from"react";var St=(n,e)=>e?n.map(t=>{var o;return{...t,apply:typeof t.apply=="function"?t.apply:`${e}${(o=t.apply)!=null?o:t.label}`}}):n,Tt=n=>n===void 0?!1:["Times","Divide","Plus","Minus"].includes(n.name),Y=(n,e)=>{var i;let{lastChild:t}=n,{pos:o}=e;for(;t;)if(t.from<o&&Ae.includes(t.name)){if(t.name==="ParenthesizedExpression"){let s=(i=t.firstChild)==null?void 0:i.nextSibling;s&&(t=s)}return t}else t=t.prevSibling},un=(n,e)=>{var t;if(n.name==="ArgList"){let o=n.prevSibling;if(o)return R(o,e)}else if(n.name==="OpenBrace"){let o=(t=n.parent)==null?void 0:t.prevSibling;if((o==null?void 0:o.name)==="Function")return R(o,e)}},cn=(n,e)=>{if(n.name==="RelationalExpression"){let t=ke(n);if((t==null?void 0:t.name)==="RelationalOperator")return R(t,e)}else{let t=n.prevSibling;if((t==null?void 0:t.name)==="RelationalOperator")return R(t,e)}},Fe=(n,e)=>{var t;if(n.name==="RelationalExpression"){if(((t=n.firstChild)==null?void 0:t.name)==="Column")return R(n.firstChild,e)}else{let o=n.prevSibling;if((o==null?void 0:o.name)==="Column")return R(o,e);if((o==null?void 0:o.name)==="RelationalOperator")return Fe(o,e)}},Ne=async(n,e,t,o={})=>{let i=await e.getSuggestions(t,o),{startsWith:r=""}=o;return{from:n.pos-r.length,options:i}},Qe=(n,e,t,o,i)=>{let r=Y(n,e);switch(console.log(`conditional expression last child ${r==null?void 0:r.name}`),r==null?void 0:r.name){case"If":return Ne(e,t,"expression",{prefix:"( "});case"OpenBrace":return Ne(e,t,"expression");case"Condition":return Ne(e,t,"expression",{prefix:", "});case"CloseBrace":if(o){let s=[{apply:()=>{i==null||i()},label:"Save Expression",boost:10}];return{from:e.pos,options:s}}}},wt=(n,e)=>{let t=[{apply:()=>{e==null||e()},label:"Save Expression",boost:10}];return{from:n.pos,options:t}},mn=(n,e)=>{let t=pn(async(o,i,r={})=>{let s=await n.getSuggestions(i,r),{startsWith:p=""}=r;return{from:o.pos-p.length,options:s}},[n]);return pn(async o=>{var x,h;let{state:i,pos:r}=o,s=(x=o.matchBefore(/\w*/))!=null?x:{from:0,to:0,text:void 0},l=Pt(i).resolveInner(r,-1),c=i.doc.toString(),C=tn(c);switch(console.log({nodeBeforeName:l.name}),l.name){case"If":return console.log("conditional expression If"),t(o,"expression",{prefix:"( "});case"Condition":{let a=Y(l,o);if((a==null?void 0:a.name)==="Column"){let m=vt(a);if((m==null?void 0:m.name)!=="RelationalOperator")return t(o,"condition-operator",{columnName:R(a,i)});console.log(`Condition last child Column, prev child ${m==null?void 0:m.name}`)}else if((a==null?void 0:a.name)==="RelationalOperator")return t(o,"expression");console.log(`condition last child ${a==null?void 0:a.name}`)}break;case"ConditionalExpression":return Qe(l,o,n);case"RelationalExpression":{if(on(l))return{from:o.pos,options:Ot.concat({label:", <truthy expression>, <falsy expression>",apply:", "})};{let a=cn(l,i),m=Fe(l,i);if(a)return t(o,"expression");{let g=await n.getSuggestions("condition-operator",{columnName:m});return{from:o.pos,options:g}}}}break;case"RelationalOperator":return t(o,"expression");case"String":{let a=cn(l,i),m=Fe(l,i),{from:g,to:d}=l;if(d-g===2&&o.pos===g+1){if(m&&a)return t(o,"columnValue",{columnName:m,operator:a,startsWith:s.text})}else if(d-g>2&&o.pos===d)return t(o,"expression",{prefix:", "});console.log(`we have a string, column is ${m} ${g} ${d}`)}break;case"ArithmeticExpression":{let a=Y(l,o);if((a==null?void 0:a.name)==="Column")return t(o,"expression");if(Tt(a)){let m=a.name;return t(o,"column",{operator:m})}}break;case"OpenBrace":{let a=un(l,i);return t(o,"expression",{functionName:a})}break;case"ArgList":{let a=un(l,i),m=Y(l,o),g=(m==null?void 0:m.name)==="OpenBrace"?void 0:",",d=await n.getSuggestions("expression",{functionName:a});return d=g?St(d,", "):d,(m==null?void 0:m.name)!=="OpenBrace"&&(m==null?void 0:m.name)!=="Comma"&&(d=[{apply:") ",boost:10,label:"Done - no more arguments"}].concat(d)),{from:o.pos,options:d}}case"Equal":if(c.trim()==="=")return t(o,"expression");break;case"ParenthesizedExpression":case"ColumnDefinitionExpression":if(o.pos===0)return t(o,"expression");{let a=Y(l,o);if((a==null?void 0:a.name)==="Column"){if(C){let m=[{apply:()=>{e.current()},label:"Save Expression",boost:10}],g=R(a,i),d=await n.getSuggestions("operator",{columnName:g});return{from:o.pos,options:m.concat(d)}}}else if((a==null?void 0:a.name)==="CallExpression"){if(C){let m=[{apply:()=>{e.current()},label:"Save Expression",boost:10}];return{from:o.pos,options:m}}}else if((a==null?void 0:a.name)==="ArithmeticExpression"){if(C){let m=[{apply:()=>{e.current()},label:"Save Expression",boost:10}],g=Y(a,o);if((g==null?void 0:g.name)==="Column"){let d=R(g,i),b=await n.getSuggestions("operator",{columnName:d});m=m.concat(b)}return{from:o.pos,options:m}}}else if((a==null?void 0:a.name)==="ConditionalExpression")return Qe(a,o,n,C,e.current);break}case"Column":if(await n.isPartialMatch("expression",void 0,s.text))return t(o,"expression",{startsWith:s.text});break;case"Comma":{let a=ln(l);if((a==null?void 0:a.name)==="ConditionalExpression")return t(o,"expression")}break;case"CloseBrace":{let a=ln(l);if((a==null?void 0:a.name)==="ConditionalExpression")return Qe(a,o,n,C,e.current);if((a==null?void 0:a.name)==="ArgList"&&C)return wt(o,e.current);console.log(`does closebrace denote an ARgList or a parenthetised expression ? ${a}`)}break;default:((h=l==null?void 0:l.prevSibling)==null?void 0:h.name)==="FilterClause"&&console.log("looks like we ight be a or|and operator")}},[t,e,n])};var le=n=>{if(n.current==null)throw Error("EditorView not defined");return n.current},Lt=()=>"vuuSuggestion",It=()=>console.log("noooop"),Bt=n=>"expressionType"in n,Ut=n=>{if(Bt(n)){let e=fn("div","expression-type-container"),t=fn("span","expression-type",n.expressionType);return e.appendChild(t),e}else return null},Cn=({onChange:n,onSubmitExpression:e,suggestionProvider:t})=>{let o=Ie(null),i=Ie(It),r=Ie(),s=mn(t,i),[p,l]=Ft(()=>{let c=()=>{let g=le(r),d=g.state.doc.toString(),b=kt(g.state,g.state.doc.length,5e3);if(b){let v=en(b,d);return[d,v]}else return["",void 0]},C=()=>{le(r).setState(m())},x=()=>{let[g,d]=c();e==null||e(g,d),C()},h=g=>Le.of([{key:g,run(){return x(),!0}}]),a=g=>Le.of([{key:g,run(){return gn(le(r)),!0}}]),m=()=>At.create({doc:"",extensions:[Nt,Dt({addToOptions:[{render:Ut,position:70}],override:[s],optionClass:Lt}),Ke(),Le.of(Rt),h("Ctrl-Enter"),a("ArrowDown"),dn.updateListener.of(g=>{let d=le(r);if(g.docChanged){gn(d);let b=d.state.doc.toString();n==null||n(b,void 0)}}),an,sn]});return i.current=()=>{x(),setTimeout(()=>{le(r).focus()},100)},[m,C]},[s,n,e]);return Qt(()=>{if(!o.current)throw Error("editor not in dom");return r.current=new dn({state:p(),parent:o.current}),()=>{var c;(c=r.current)==null||c.destroy()}},[s,p]),{editorRef:o,clearInput:l}};import{jsx as Gt}from"react/jsx-runtime";var $t="vuuColumnExpressionInput",xn=({onChange:n,onSubmitExpression:e,suggestionProvider:t})=>{let{editorRef:o}=Cn({onChange:n,onSubmitExpression:e,suggestionProvider:t});return Gt("div",{className:`${$t}`,ref:o})};import{AnnotationType as Mt,getRelationalOperators as Wt,numericOperators as Xt,stringOperators as Ht,toSuggestions as Vt}from"@vuu-ui/vuu-codemirror";import{getTypeaheadParams as zt,useTypeaheadSuggestions as Yt}from"@vuu-ui/vuu-data";import{isNumericColumn as Ue,isTextColumn as Zt}from"@vuu-ui/vuu-utils";import{useCallback as Be,useRef as Jt}from"react";var Z=[{accepts:"string",description:"Returns multiple string values as a single joined string. Arguments may be string literal values, string columns or other string expressions. Non string arguments may also be included, these will be converted to strings.",example:{expression:'concatenate("example", "-test")',result:'"example-test"'},name:"concatenate",params:{description:"( string, string, [ string* ] )"},type:"string"},{accepts:["string","string"],description:"Tests a string value to determine whether it contains a given substring. Accepts two arguments: source text and target substring. Returns true if <source text> contains one or more occurrences of <target subscring>",example:{expression:'contains("Royal Bank of Scotland", "bank")',result:"true"},name:"contains",params:{description:"( string )"},type:"boolean"},{accepts:["string","number"],description:"Returns the leftmost <number> characters from <string>. First argument may be a string literal, string column or other string expression.",example:{expression:'left("USD Benchmark Report", 3)',result:'"USD"'},name:"left",params:{count:2,description:"( string, number )"},type:"string"},{accepts:"string",description:"Returns the number of characters in <string>. Argument may be a string literal, string column or other string expression.",example:{expression:'len("example")',result:"7"},name:"len",params:{description:"(string)"},type:"number"},{accepts:"string",description:"Convert a string value to lowercase. Argument may be a string column or other string expression.",example:{expression:'lower("examPLE")',result:'"example"'},name:"lower",params:{description:"( string )"},type:"string"},{accepts:"string",description:"Convert a string value to uppercase. Argument may be a string column or other string expression.",example:{expression:'upper("example")',result:'"EXAMPLE"'},name:"upper",params:{description:"( string )"},type:"string"},{accepts:["string","number"],description:"Returns the rightmost <number> characters from <string>. First argument may be a string literal, string column or other string expression.",example:{expression:"blah",result:"blah"},name:"right",params:{description:"( string )"},type:"string"},{accepts:["string","string","string"],description:"Replace characters within a string. Accepts three arguments: source text, text to replace and replacement text. Returns a copy of <source text> with any occurrences of <text to replace> replaced by <replacement text>",example:{expression:"blah",result:"blah"},name:"replace",params:{description:"( string )"},type:"string"},{accepts:"number",description:"Converts a number to a string.",example:{expression:"blah",result:"blah"},name:"text",params:{description:"( string )"},type:"string"},{accepts:"string",description:"Tests a string value to determine whether it starts with a given substring. Accepts two arguments: source text and target substring. Returns true if <source text> starts with <target subscring>.",example:{expression:"blah",result:"blah"},name:"starts",params:{description:"( string )"},type:"boolean"},{accepts:"string",description:"Tests a string value to determine whether it ends with a given substring. Accepts two arguments: source text and target substring. Returns true if <source text> ends with <target subscring>.",example:{expression:"blah",result:"blah"},name:"ends",params:{description:"( string )"},type:"boolean"},{accepts:"number",description:"blah",example:{expression:"blah",result:"blah"},name:"min",params:{description:"( string )"},type:"number"},{accepts:"number",description:"blah",example:{expression:"blah",result:"blah"},name:"max",params:{description:"( string )"},type:"number"},{accepts:"number",description:"blah",example:{expression:"blah",result:"blah"},name:"sum",params:{description:"( string )"},type:"number"},{accepts:"number",description:"blah",example:{expression:"blah",result:"blah"},name:"round",params:{description:"( string )"},type:"number"},{accepts:"any",description:"blah",example:{expression:"blah",result:"blah"},name:"or",params:{description:"( string )"},type:"boolean"},{accepts:"any",description:"blah",example:{expression:"blah",result:"blah"},name:"and",params:{description:"( string )"},type:"boolean"},{accepts:"any",description:"Return one of two possible result values, depending on the evaluation of a filter expression. If <filterExpression> resolves to true, result is <expression1>, otherwise <expression2>. ",example:{expression:"blah",result:"blah"},name:"if",params:{description:"( filterExpression, expression1, expression 2)"},type:"variable"}];import{createEl as A}from"@vuu-ui/vuu-utils";var hn=({name:n,description:e,example:t,params:o,type:i})=>{let r=A("div","vuuFunctionDoc"),s=A("div","function-heading"),p=A("span","function-name",n),l=A("span","param-list",o.description),c=A("span","function-type",i);s.appendChild(p),s.appendChild(l),s.appendChild(c);let C=A("p",void 0,e);if(r.appendChild(s),r.appendChild(C),t){let x=A("div","example-container","Example:"),h=A("div","example-expression",t.expression),a=A("div","example-result",t.result);x.appendChild(h),x.appendChild(a),r.appendChild(x)}return r};var qt=[],I=n=>n.map(e=>{var t;return{...e,apply:((t=e.apply)!=null?t:e.label)+" "}}),_t=(n,{functionName:e,operator:t})=>{if(t)return n.filter(Ue);if(e){let o=Z.find(i=>i.name===e);if(o)switch(o.accepts){case"string":return n.filter(Zt);case"number":return n.filter(Ue);default:return n}}return n},yn=(n,e)=>_t(n,e).map(o=>{var r;let i=(r=o.label)!=null?r:o.name;return{apply:e.prefix?`${e.prefix}${i}`:i,label:i,boost:5,type:"column",expressionType:o.serverDataType}}),Kt=[{apply:"* ",boost:2,label:"*",type:"operator"},{apply:"/ ",boost:2,label:"/",type:"operator"},{apply:"+ ",boost:2,label:"+",type:"operator"},{apply:"- ",boost:2,label:"-",type:"operator"}],jt=n=>n===void 0||Ue(n)?Kt:qt,eo=n=>{switch(n.serverDataType){case"string":case"char":return I(Ht);case"int":case"long":case"double":return I(Xt)}},$e=n=>({apply:`${n.name}( `,boost:2,expressionType:n.type,info:()=>hn(n),label:n.name,type:"function"}),no=n=>{if(n){if(typeof n.accepts=="string")return n.accepts;if(Array.isArray(n.accepts))return n.accepts.every(e=>e==="string")?"string":"any"}return"any"},to=Z.map($e),oo=({functionName:n})=>{if(n){let e=Z.find(o=>o.name===n),t=no(e);if(e)switch(t){case"string":return Z.filter(o=>o.type==="string"||o.type==="variable").map($e);case"number":return Z.filter(o=>o.type==="number"||o.type==="variable").map($e);default:}}return to},ro={},bn=({columns:n,table:e})=>{let t=Be(p=>p?n.find(l=>l.name===p):void 0,[n]),o=Jt(),i=Yt(),r=Be(async(p,l=ro)=>{let{columnName:c,functionName:C,operator:x,prefix:h}=l;switch(p){case"expression":{let a=await I(yn(n,{functionName:C,prefix:h})).concat(oo(l));return o.current=a}case"column":{let a=await yn(n,l);return o.current=I(a)}case"operator":{let a=await jt(t(c));return o.current=I(a)}case"relational-operator":{let a=await Wt(t(c));return o.current=I(a)}case"condition-operator":{let a=t(c);if(a){let m=await eo(a);if(m)return o.current=I(m)}}break;case"columnValue":if(c&&x){let a=zt(e,c),m=await i(a);return o.current=Vt(m,{suffix:""}),o.current.forEach(g=>{g.apply=(d,b,v)=>{let w=new Mt,oe=v+b.label.length+1;d.dispatch({changes:{from:v,insert:b.label},selection:{anchor:oe,head:oe},annotations:w.of(b)})}}),o.current}break}return[]},[n,t,i,e]),s=Be(async(p,l,c)=>{let{current:C}=o,x=!1,h=C||await r(p,{columnName:l});if(c&&h)for(let a of h){if(a.label===c)return!1;a.label.startsWith(c)&&(x=!0)}return x},[r]);return{getSuggestions:r,isPartialMatch:s}};import{Button as ze,Panel as ir}from"@salt-ds/core";import ar from"classnames";import{useCallback as me,useState as Wn}from"react";import{List as On}from"@heswell/salt-lab";import{Button as pe,Text as vn,useIdMemo as lo}from"@salt-ds/core";import{useCallback as B,useState as po}from"react";import{ListItem as so}from"@heswell/salt-lab";import io from"classnames";import{jsx as Ge,jsxs as ao}from"react/jsx-runtime";var J="vuuColumnListItem",En=({className:n,item:e,label:t,style:o,...i})=>{let r=io(J,n,{[`${J}-calculated`]:e==null?void 0:e.expression,[`${J}-hidden`]:e==null?void 0:e.hidden});return ao(so,{className:r,...i,children:[Ge("span",{className:`${J}-iconType`}),Ge("label",{className:`${J}-label`,children:t}),Ge("span",{className:`${J}-iconHidden`})]})};import{jsx as E,jsxs as _}from"react/jsx-runtime";var q="vuuColumnPicker",uo=(n,e)=>n.filter(t=>e.find(o=>o.name===t.name)==null),Pn=({availableColumns:n,id:e,dispatchColumnAction:t,onAddCalculatedColumnClick:o,onSelectionChange:i,chosenColumns:r,selectedColumn:s})=>{let[p,l]=po([]),c=lo(e),C=uo(n,r),x=B(()=>{p.length>0&&(l([]),t({type:"addColumn",columns:p}))},[t,p]),h=B(()=>s&&t({type:"removeColumn",column:s}),[s,t]),a=B(()=>s&&t({type:"moveColumn",column:s,moveBy:-1}),[t,s]),m=B(()=>s&&t({type:"moveColumn",column:s,moveBy:1}),[t,s]),g=B((v,w)=>l(w),[]),d=B((v,w)=>i==null?void 0:i(w),[i]),b=B((v,w)=>{t({type:"moveColumn",moveFrom:v,moveTo:w})},[t]);return _("div",{className:q,id:c,children:[_("div",{className:`${q}-listColumn`,children:[E("label",{htmlFor:`available-${c}`,children:E(vn,{as:"h4",children:"Available Columns"})}),E("div",{className:`${q}-listContainer`,style:{flex:1,overflow:"hidden"},children:E(On,{borderless:!0,checkable:!1,height:"100%",id:`available-${c}`,itemHeight:24,itemToString:v=>v.name,onSelectionChange:g,selected:p,selectionStrategy:"extended",source:C})}),E("div",{style:{display:"flex",alignItems:"center",flex:"0 0 32px",marginTop:"var(--salt-size-basis-unit)"},children:_(pe,{onClick:x,disabled:p.length===0,children:["Show",E("span",{"data-icon":"arrow-thin-right",style:{marginLeft:8}})]})})]}),_("div",{className:`${q}-listColumn`,children:[E("label",{htmlFor:`selected-${c}`,children:E(vn,{as:"h4",children:"Included Columns"})}),E("div",{className:`${q}-listContainer`,style:{flex:1,overflow:"hidden"},children:E(On,{ListItem:En,allowDragDrop:!0,borderless:!0,height:"100%",id:`selected-${c}`,itemHeight:24,itemToString:v=>v.name,onMoveListItem:b,onSelectionChange:d,selected:s,style:{flex:1},source:r})}),_("div",{style:{alignItems:"center",flex:"0 0 32px",display:"flex",gap:6,marginTop:"var(--salt-size-basis-unit)"},children:[_(pe,{onClick:h,disabled:s===null,children:[E("span",{"data-icon":"arrow-thin-left",style:{marginRight:8}}),"Hide"]}),E(pe,{"aria-label":"Move column up",onClick:a,disabled:s===null||(r==null?void 0:r.indexOf(s))===0,style:{width:28},children:E("span",{"data-icon":"arrow-thin-up"})}),E(pe,{"aria-label":"Move column down",onClick:m,disabled:s===null||r.indexOf(s)===r.length-1,style:{width:28},children:E("span",{"data-icon":"arrow-thin-down"})}),E(pe,{"aria-label":"Add calculated column",className:`${q}-addCalculatedColumn`,onClick:o,variant:"primary",children:E("span",{"data-icon":"add"})})]})]})]})};import{Stack as Ro}from"@vuu-ui/vuu-layout";import{Checkbox as Ao,FormField as U,Input as We,RadioButton as ue,RadioButtonGroup as Nn,StepperInput as ko}from"@heswell/salt-lab";import{Panel as Qn,Text as No}from"@salt-ds/core";import Qo from"classnames";import{useCallback as j,useState as Fo}from"react";import{getRegisteredCellRenderers as bo}from"@vuu-ui/vuu-utils";import{Dropdown as Eo}from"@heswell/salt-lab";import{Panel as Oo}from"@salt-ds/core";import Rn from"classnames";import{useMemo as vo}from"react";import{FormField as co,StepperInput as mo,Switch as Sn}from"@heswell/salt-lab";import{Text as go}from"@salt-ds/core";import{useCallback as ye}from"react";import{Fragment as Tn,jsx as K,jsxs as xo}from"react/jsx-runtime";var fo={alignOnDecimals:!1,decimals:4,zeroPad:!1},Co=(n,e)=>{let t=typeof n=="object"&&n.formatting?n.formatting:{};return["alignOnDecimals","decimals","zeroPad"].reduce((i,r)=>t[r]!==void 0?{...i,[r]:t[r]}:(e==null?void 0:e[r])!==void 0?{...i,[r]:e[r]}:i,fo)},wn=({column:n,dispatchColumnAction:e})=>{let{decimals:t,alignOnDecimals:o,zeroPad:i}=Co(n==null?void 0:n.type),r=ye(c=>e({type:"updateColumnTypeFormatting",column:n,...c}),[n,e]),s=ye(c=>r({decimals:parseInt(c.toString(),10)}),[r]),p=ye((c,C)=>r({alignOnDecimals:C}),[r]),l=ye((c,C)=>r({zeroPad:C}),[r]);switch(n.serverDataType){case"double":return xo(Tn,{children:[K(co,{label:"No of Decimals",labelPlacement:"top",children:K(mo,{value:t,onChange:s})}),K(Sn,{checked:o,label:"Align on decimals",LabelProps:{className:"vuuColumnPanelSwitch"},onChange:p}),K(Sn,{checked:i,label:"Zero pad",LabelProps:{className:"vuuColumnPanelSwitch"},onChange:l})]});case"long":case"int":return K(Tn,{children:K(go,{children:"Work in progress"})});default:return null}};import{Fragment as ho,jsx as yo}from"react/jsx-runtime";var Dn=({column:n,dispatchColumnAction:e})=>yo(ho,{children:"String"});import{Fragment as wo,jsx as be,jsxs as Do}from"react/jsx-runtime";var Me="vuuColumnTypePanel",Po=["Default Renderer (int, long)"],So=["Default Renderer (double)"],An=["Default Renderer (string)"],To=n=>{let t=bo(n.serverDataType).map(o=>o.name);switch(console.log({customRendererNames:t}),n.serverDataType){case"char":case"string":return An;case"int":case"long":return Po;case"double":return So.concat(t);default:return An}},kn=({className:n,column:e,dispatchColumnAction:t,...o})=>{let i=vo(()=>{switch(e.serverDataType){case"double":case"int":case"long":return be(wn,{column:e,dispatchColumnAction:t});default:return be(Dn,{column:e,dispatchColumnAction:t})}},[e,t]),{serverDataType:r="string"}=e,s=To(e);return Do(wo,{children:[be(Eo,{className:Rn(`${Me}-renderer`),fullWidth:!0,selected:s[0],source:s}),be(Oo,{...o,className:Rn(Me,n,`${Me}-${r}`),children:i})]})};import{jsx as y,jsxs as ee}from"react/jsx-runtime";var Fn="vuuColumnSettingsPanel",Lo={className:"salt-density-high"},Ln=()=>null,In=({column:n,dispatchColumnAction:e,style:t,...o})=>{var h,a,m,g;let[i,r]=Fo(0),s=j(d=>e({type:"updateColumnProp",column:n,...d}),[n,e]),p=j(d=>s({align:d.target.value}),[s]),l=j(d=>s({pin:d.target.value}),[s]),c=j((d,b)=>s({hidden:b}),[s]),C=j((d,b)=>s({label:b}),[s]),x=j(d=>s({width:parseInt(d.toString(),10)}),[s]);return ee("div",{className:Fn,...o,style:{...t},children:[y(No,{as:"h4",children:"Column Settings"}),ee(Ro,{active:i,showTabs:!0,className:Qo(`${Fn}-columnTabs`),onTabSelectionChanged:r,TabstripProps:Lo,children:[ee(Qn,{title:"Column",children:[y(U,{label:"Hidden",labelPlacement:"left",children:y(Ao,{checked:n.hidden===!0,onChange:c})}),y(U,{label:"Label",labelPlacement:"left",children:y(We,{value:(h=n.label)!=null?h:n.name,onChange:C})}),y(U,{label:"Width",labelPlacement:"left",children:y(ko,{value:(a=n.width)!=null?a:100,onChange:x})}),y(U,{label:"Align",labelPlacement:"left",ActivationIndicatorComponent:Ln,children:ee(Nn,{"aria-label":"Column Align",value:(m=n.align)!=null?m:"left",legend:"Align",onChange:p,children:[y(ue,{label:"Left",value:"left"}),y(ue,{label:"Right",value:"right"})]})}),y(U,{label:"Pin Column",labelPlacement:"left",ActivationIndicatorComponent:Ln,children:ee(Nn,{"aria-label":"Pin Column",value:(g=n.pin)!=null?g:"",legend:"Pin Column",onChange:l,children:[y(ue,{label:"Do not pin",value:""}),y(ue,{label:"Left",value:"left"}),y(ue,{label:"Right",value:"right"})]})})]}),y(kn,{column:n,dispatchColumnAction:e,title:"Data Cell"}),ee(Qn,{title:"Vuu",variant:"secondary",children:[y(U,{label:"Name",labelPlacement:"top",readOnly:!0,variant:"secondary",children:y(We,{value:n.name})}),y(U,{label:"Vuu type",labelPlacement:"top",readOnly:!0,variant:"secondary",children:y(We,{value:n.serverDataType})})]})]})]})};import{FormField as Bn,RadioButton as Xe,RadioButtonGroup as Io,StepperInput as Bo}from"@heswell/salt-lab";import{Panel as Uo,Text as $o}from"@salt-ds/core";import{useCallback as He}from"react";import{jsx as $,jsxs as Ve}from"react/jsx-runtime";var Go="vuuGridSettingsPanel",Mo=()=>null,Un=({config:n,dispatchColumnAction:e,style:t,...o})=>{var p;let i=He(l=>e({type:"updateGridSettings",...l}),[e]),r=He(l=>i({columnFormatHeader:l.target.value}),[i]),s=He(l=>i({columnDefaultWidth:parseInt(l.toString(),10)}),[i]);return console.log(`GridSettingsPanel ${JSON.stringify(n.columns,null,2)}`),Ve("div",{className:Go,...o,style:{...t},children:[$($o,{as:"h4",children:"Grid Settings"}),Ve(Uo,{children:[$(Bn,{label:"Format column labels",labelPlacement:"left",ActivationIndicatorComponent:Mo,children:Ve(Io,{"aria-label":"Format column labels",value:n.columnFormatHeader,legend:"Format column labels",onChange:r,children:[$(Xe,{label:"No Formatting",value:void 0}),$(Xe,{label:"Capitalize",value:"capitalize"}),$(Xe,{label:"Uppercase",value:"uppercase"})]})}),$(Bn,{label:"Default Column Width",labelPlacement:"left",children:$(Bo,{value:(p=n.columnDefaultWidth)!=null?p:100,onChange:s})})]})]})};import{useReducer as Wo}from"react";import{moveItem as Xo}from"@heswell/salt-lab";import{fromServerDataType as Ho}from"@vuu-ui/vuu-utils";var Vo=(n,e)=>{switch(console.log(`gridSettingsReducer ${e.type}`),e.type){case"addColumn":return zo(n,e);case"addCalculatedColumn":return Yo(n,e);case"moveColumn":return Jo(n,e);case"removeColumn":return Zo(n,e);case"updateColumn":return n;case"updateColumnProp":return qo(n,e);case"updateGridSettings":return _o(n,e);case"updateColumnTypeFormatting":return Ko(n,e);default:return n}},$n=n=>{let[e,t]=Wo(Vo,n);return{gridSettings:e,dispatchColumnAction:t}};function zo(n,{column:e,columns:t,index:o=-1}){let{columns:i}=n;if(o===-1){if(Array.isArray(t))return{...n,columns:i.concat(t)};if(e)return{...n,columns:i.concat(e)}}return n}function Yo(n,{columnName:e,columnType:t,expression:o}){let{columns:i}=n,r={name:e,expression:o,serverDataType:t};return{...n,columns:i.concat(r)}}function Zo(n,{column:e}){let{columns:t}=n;return{...n,columns:t.filter(o=>o.name!==e.name)}}function Jo(n,{column:e,moveBy:t,moveFrom:o,moveTo:i}){let{columns:r}=n;if(e&&typeof t=="number"){let s=r.indexOf(e),p=r.slice(),[l]=p.splice(s,1);return p.splice(s+t,0,l),{...n,columns:p}}else return typeof o=="number"&&typeof i=="number"?{...n,columns:Xo(r,o,i)}:n}function qo(n,{align:e,column:t,hidden:o,label:i,width:r}){let{columns:s}=n;return(e==="left"||e==="right")&&(s=ce(s,{...t,align:e})),typeof o=="boolean"&&(s=ce(s,{...t,hidden:o})),typeof i=="string"&&(s=ce(s,{...t,label:i})),typeof r=="number"&&(s=ce(s,{...t,width:r})),{...n,columns:s}}function _o(n,{columnFormatHeader:e}){return{...n,columnFormatHeader:e!=null?e:n.columnFormatHeader}}function Ko(n,{alignOnDecimals:e,column:t,decimals:o,zeroPad:i}){let{columns:r}=n;if(r.find(p=>p.name===t.name)){let{serverDataType:p="string",type:l=Ho(p)}=t,c=typeof l=="string"?{name:l}:{...l};return typeof e=="boolean"&&(c.formatting={...c.formatting,alignOnDecimals:e}),typeof o=="number"&&(c.formatting={...c.formatting,decimals:o}),typeof i=="boolean"&&(c.formatting={...c.formatting,zeroPad:i}),{...n,columns:ce(r,{...t,type:c})}}else return n}function ce(n,e){return n.map(t=>t.name===e.name?e:t)}import{Stack as lr}from"@vuu-ui/vuu-layout";import{FormField as jo,Input as er}from"@heswell/salt-lab";import{Button as nr,Panel as tr,Text as or}from"@salt-ds/core";import{useCallback as Ee,useRef as rr,useState as Gn}from"react";import{jsx as ne,jsxs as sr}from"react/jsx-runtime";var Mn=({columns:n,dispatchColumnAction:e,table:t})=>{let[o,i]=Gn(""),[,r]=Gn(),s=rr(""),p=bn({columns:n,table:t}),l=Ee(h=>{let{value:a}=h.target;i(a)},[]),c=Ee(h=>{s.current=h},[]),C=Ee((h,a)=>{console.log({source:h}),r(a)},[]),x=Ee(()=>{s.current&&(console.log(`save expression ${JSON.stringify(s.current,null,2)}`),e({type:"addCalculatedColumn",columnName:o,expression:s.current,columnType:"string"}))},[o,e]);return sr(tr,{className:"vuuCalculatedColumnPanel",title:"Define Computed Column",children:[ne(or,{styleAs:"h4",children:"Define Computed Column"}),ne(jo,{label:"Column Name",labelPlacement:"left",children:ne(er,{value:o,onChange:l})}),ne(xn,{onChange:c,onSubmitExpression:C,suggestionProvider:p}),ne("div",{style:{marginTop:12},children:ne(nr,{onClick:x,children:"Add Column"})})]})};import{jsx as k,jsxs as ve}from"react/jsx-runtime";var Oe="vuuDatagridSettingsPanel",pr=()=>{},ur=["table-settings","column-chooser","column-settings","define-column"],cr=(n,e)=>ur[e],Va=({availableColumns:n,className:e,gridConfig:t,onCancel:o,onConfigChange:i,...r})=>{var oe;console.log("DatagridSettingsPanel render");let[s,p]=Wn(0),{gridSettings:l,dispatchColumnAction:c}=$n(t),[C,x]=Wn(null),h=me(D=>{x(D?D.name:null)},[]),a=me((D,Xn=!1)=>{console.log("1) DataGridSettingsPanel fire onConfigChange"),i==null||i(l,Xn)},[l,i]),m=me(D=>{p(D)},[]),g=me(D=>a(D,!0),[a]),d=C===null?null:(oe=l.columns.find(D=>D.name===C))!=null?oe:null,b={activeTabIndex:s,enableRenameTab:!1,orientation:"vertical"},v=me(()=>p(3),[]),w=s===2?"right":void 0;return ve("div",{...r,className:ar(Oe,e),children:[ve(lr,{TabstripProps:b,className:`${Oe}-stack`,getTabIcon:cr,getTabLabel:pr,active:s===2?1:s,onTabSelectionChanged:m,showTabs:!0,children:[k(Un,{config:l,dispatchColumnAction:c}),ve("div",{className:`${Oe}-columnPanels`,"data-align":w,children:[k(Pn,{availableColumns:n,chosenColumns:l.columns,dispatchColumnAction:c,onSelectionChange:h,onAddCalculatedColumnClick:v,selectedColumn:d}),d===null?k(ir,{className:"vuuColumnSettingsPanel",children:"Select a column"}):k(In,{column:d,dispatchColumnAction:c,style:{background:"white",flex:"1 0 150px"}})]}),k("div",{title:"Column Settings",children:"Column Settings"}),k(Mn,{columns:l.columns,dispatchColumnAction:c,table:{module:"SIMUL",table:"instruments"}})]}),ve("div",{className:`${Oe}-buttonBar`,children:[k(ze,{onClick:o,children:"Cancel"}),k(ze,{onClick:a,children:"Apply"}),k(ze,{onClick:g,children:"Save"})]})]})};import{useEffect as mr,useState as Ye}from"react";import dr from"classnames";import{jsx as te,jsxs as gr}from"react/jsx-runtime";var de="vuuDatasourceStats",Ze=new Intl.NumberFormat,rl=({className:n,dataSource:e})=>{let[t,o]=Ye(e.optimize),[i,r]=Ye(e.range),[s,p]=Ye(e.size);mr(()=>{o(e.optimize),p(e.size),e.on("optimize",o),e.on("resize",p),e.on("range",r)},[e]);let l=dr(de,n),c=Ze.format(i.from),C=Ze.format(i.to-1),x=Ze.format(s);return gr("div",{className:l,children:[te("span",{children:"Showing rows"}),te("span",{className:`${de}-range`,children:c}),te("span",{className:`${de}-range`,children:C}),te("span",{children:"of"}),te("span",{className:`${de}-size`,children:x}),te("span",{className:`${de}-optimize`,children:t})]})};export{xn as ColumnExpressionInput,Ae as ColumnNamedTerms,rl as DataSourceStats,Va as DatagridSettingsPanel,Ke as columnExpressionLanguageSupport,tn as isCompleteExpression,on as isCompleteRelationalExpression,ke as lastNamedChild,Cn as useColumnExpressionEditor,bn as useColumnExpressionSuggestionProvider,en as walkTree};
2
2
  //# sourceMappingURL=index.js.map