@vuu-ui/vuu-table-extras 0.8.23 → 0.8.24-debug

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,3559 @@
1
- var vt=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var f=(o,e,t)=>(vt(o,e,"read from private field"),t?t.call(o):e.get(o)),L=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)},M=(o,e,t,n)=>(vt(o,e,"write to private field"),n?n.call(o,t):e.set(o,t),t);import{registerComponent as ho}from"@vuu-ui/vuu-utils";var bo=o=>typeof o=="string",yo=(o,e)=>bo(e)?e===""?!0:o.value==="lower"&&e.toLowerCase()!==e?"value must be all lowercase":o.value==="upper"&&e.toUpperCase()!==e?"value must be all uppercase":!0:"value must be a string";ho("vuu-case",yo,"data-edit-validator",{});import{registerComponent as Eo}from"@vuu-ui/vuu-utils";var wo=o=>typeof o=="string",Oo="value does not match expected pattern",So=(o,e)=>{if(typeof o.value!="string")throw Error("Pattern validation rule must provide pattern");if(wo(e)){if(e==="")return!0;{let{message:t=Oo}=o;return new RegExp(o.value).test(e)||t}}else return"value must be a string"};Eo("vuu-pattern",So,"data-edit-validator",{});import{dataAndColumnUnchanged as Bo,DOWN1 as Do,DOWN2 as No,isTypeDescriptor as Ro,metadataKeys as Ho,registerComponent as Vo,UP1 as Io,UP2 as Qo}from"@vuu-ui/vuu-utils";import Mo from"clsx";import{memo as Ao}from"react";import{getMovingValueDirection as ko,isTypeDescriptor as To,isValidNumber as xt}from"@vuu-ui/vuu-utils";import{useEffect as Fo,useRef as Po}from"react";var Lo=[void 0,void 0,void 0,void 0];function ht(o,e,t){var g;let n=Po(),[i,r,a,u]=n.current||Lo,{type:l}=t,c=To(l)?(g=l.formatting)==null?void 0:g.decimals:void 0,d=o===i&&xt(e)&&xt(r)&&t===a?ko(e,u,r,c):"";return Fo(()=>{n.current=[o,e,t,d]}),d}import{jsx as Go,jsxs as Wo}from"react/jsx-runtime";var $o="\u2B06",Zo="\u2B07",{KEY:Xo}=Ho,pe="vuuBackgroundCell",Y={ArrowOnly:"arrow",BackgroundOnly:"bg-only",ArrowBackground:"arrow-bg"},zo=o=>Ro(o)&&o.renderer&&"flashStyle"in o.renderer?o.renderer.flashStyle:Y.BackgroundOnly,Uo=Ao(function({column:e,columnMap:t,row:n}){let{name:i,type:r,valueFormatter:a}=e,u=t[i],l=n[u],c=zo(r),d=ht(n[Xo],l,e),g=c===Y.ArrowOnly||c===Y.ArrowBackground?d===Io||d===Qo?$o:d===Do||d===No?Zo:null:null,p=d?" "+d:"",s=Mo(pe,p,{[`${pe}-backgroundOnly`]:c===Y.BackgroundOnly,[`${pe}-arrowOnly`]:c===Y.ArrowOnly,[`${pe}-arrowBackground`]:c===Y.ArrowBackground});return Wo("div",{className:s,tabIndex:-1,children:[Go("div",{className:`${pe}-arrow`,children:g}),a(n[u])]})},Bo);Vo("vuu.price-move-background",Uo,"cell-renderer",{description:"Change background color of cell when value changes",configEditor:"BackgroundCellConfigurationEditor",label:"Background Flash",serverDataType:["long","int","double"]});import{Dropdown as Yo}from"@vuu-ui/vuu-ui-controls";import{registerConfigurationEditor as qo}from"@vuu-ui/vuu-utils";import{FormField as _o,FormFieldLabel as Jo}from"@salt-ds/core";import{useCallback as Ko,useState as jo}from"react";import{jsx as bt,jsxs as nn}from"react/jsx-runtime";var en="vuuBackgroundCellConfiguration",Qe=[{label:"Background Only",value:"bg-only"},{label:"Background and Arrow",value:"arrow-bg"},{label:"Arrow Only",value:"arrow"}],[yt]=Qe,tn=o=>{let{flashStyle:e}=o.type.renderer;return Qe.find(t=>t.value===e)||yt},on=({column:o,onChangeRendering:e})=>{let[t,n]=jo(tn(o)),i=Ko((r,a)=>{var l;n(a);let u=o.type.renderer;e({...u,flashStyle:(l=a==null?void 0:a.value)!=null?l:yt.value})},[o.type,e]);return nn(_o,{children:[bt(Jo,{children:"Flash Style"}),bt(Yo,{className:`${en}-flashStyle`,onSelectionChange:i,selected:t,source:Qe,width:"100%"})]})};qo("BackgroundCellConfigurationEditor",on);import{useLookupValues as rn}from"@vuu-ui/vuu-data-react";import{Dropdown as sn,WarnCommit as an}from"@vuu-ui/vuu-ui-controls";import{dataAndColumnUnchanged as ln,dispatchCustomEvent as un,registerComponent as pn}from"@vuu-ui/vuu-utils";import{memo as cn,useCallback as mn,useState as dn}from"react";import{jsx as vn}from"react/jsx-runtime";var gn="vuuTableDropdownCell",fn=["Enter"," "],Cn=cn(function({column:e,columnMap:t,onCommit:n=an,row:i}){let r=t[e.name],{initialValue:a,values:u}=rn(e,i[r]),[l,c]=dn(null),d=mn((g,p)=>{p&&(c(p),n(p.value).then(s=>{s===!0&&g&&un(g.target,"vuu-commit")}))},[n]);return vn(sn,{className:gn,onSelectionChange:d,openKeys:fn,selected:l!=null?l:a,source:u,width:e.width-17})},ln);pn("dropdown-cell",Cn,"cell-renderer",{});import{useLookupValues as xn}from"@vuu-ui/vuu-data-react";import{dataAndColumnUnchanged as hn,registerComponent as bn}from"@vuu-ui/vuu-utils";import{memo as yn}from"react";import{jsx as wn}from"react/jsx-runtime";var En=yn(function({column:e,columnMap:t,row:n}){let i=t[e.name],{initialValue:r}=xn(e,n[i]);return wn("span",{children:r==null?void 0:r.label})},hn);bn("lookup-cell",En,"cell-renderer",{});import{isColumnTypeRenderer as On,isTypeDescriptor as Sn,isValidNumber as Et,registerComponent as kn}from"@vuu-ui/vuu-utils";import Tn from"clsx";import{jsx as Me,jsxs as wt}from"react/jsx-runtime";var ce="vuuProgressCell",Fn=({column:o,columnMap:e,row:t})=>{let{name:n,type:i}=o,r=t[e[n]],a=!1,u=0;if(Sn(i)&&On(i.renderer)){let{associatedField:c}=i.renderer;if(c){let d=t[e[c]];if(typeof Et(r)&&Et(d))u=Math.min(Math.round(r/d*100),100),u=Math.min(Math.round(r/d*100),100),a=isFinite(u);else{let g=parseFloat(r);if(Number.isFinite(g)){let p=parseFloat(d);Number.isFinite(p)&&(u=Math.min(Math.round(g/p*100),100),a=isFinite(u))}}}else throw Error("ProgressCell associatedField is required to render")}let l=Tn(ce,{});return wt("div",{className:l,tabIndex:-1,children:[a?wt("span",{className:`${ce}-track`,children:[Me("span",{className:`${ce}-bg`}),Me("span",{className:`${ce}-bar`,style:{"--progress-bar-pct":`-${100-u}%`}})]}):null,Me("span",{className:`${ce}-text`,children:`${u} %`})]})};kn("vuu.progress",Fn,"cell-renderer",{description:"Progress formatter",label:"Progress formatter",serverDataType:["long","int","double"]});import{List as Pn,ListItem as Ln}from"@vuu-ui/vuu-ui-controls";import{Checkbox as Bn,Switch as Dn}from"@salt-ds/core";import Nn from"clsx";import{useCallback as Ot}from"react";import{getColumnLabel as Rn}from"@vuu-ui/vuu-utils";import{jsx as N,jsxs as Ae}from"react/jsx-runtime";var D="vuuColumnList",St="vuuColumnListItem",Hn=({className:o,item:e,...t})=>Ae(Ln,{...t,className:Nn(o,St),"data-name":e==null?void 0:e.name,children:[N("span",{className:`${D}-icon`,"data-icon":"draggable"}),e!=null&&e.isCalculated?N("span",{className:`${D}-icon`,"data-icon":"function"}):N(Dn,{className:`${D}-switch`,checked:e==null?void 0:e.subscribed}),N("span",{className:`${D}-text`,children:Rn(e)}),N(Bn,{className:`${D}-checkBox`,checked:(e==null?void 0:e.hidden)!==!0,disabled:(e==null?void 0:e.subscribed)!==!0})]}),kt=({columnItems:o,onChange:e,onMoveListItem:t,onNavigateToColumn:n,...i})=>{let r=Ot(u=>{let l=u.target,c=l.closest(`.${St}`),{dataset:{name:d}}=c;if(d){let g=l.closest(`.${D}-switch`),p=l.closest(`.${D}-checkBox`);g?e(d,"subscribed",l.checked):p&&e(d,"hidden",l.checked===!1)}},[e]),a=Ot(u=>{let l=u.target;if(l.classList.contains("vuuColumnList-text")){let c=l.closest(".vuuListItem");c!=null&&c.dataset.name&&(n==null||n(c.dataset.name))}},[]);return Ae("div",{...i,className:D,children:[N("div",{className:`${D}-header`,children:N("span",{children:"Column Selection"})}),Ae("div",{className:`${D}-colHeadings`,children:[N("span",{children:"Column subscription"}),N("span",{children:"Visibility"})]}),N(Pn,{ListItem:Hn,allowDragDrop:!0,height:"auto",onChange:r,onClick:a,onMoveListItem:t,selectionStrategy:"none",source:o,itemHeight:33})]})};import{VuuInput as fo}from"@vuu-ui/vuu-ui-controls";import{getCalculatedColumnName as zs,getDefaultAlignment as Us,isCalculatedColumn as Gs}from"@vuu-ui/vuu-utils";import{Button as Be,FormField as De,FormFieldLabel as Ne,ToggleButton as ae,ToggleButtonGroup as Co}from"@salt-ds/core";import Ws from"clsx";import{Dropdown as Ar}from"@vuu-ui/vuu-ui-controls";import{getCalculatedColumnExpression as $r,getCalculatedColumnName as Zr,getCalculatedColumnType as Xr}from"@vuu-ui/vuu-utils";import{FormField as rt,FormFieldLabel as st,Input as zr}from"@salt-ds/core";import{useCallback as Ur,useRef as _t}from"react";import{memo as mr}from"react";import{autocompletion as tr,defaultKeymap as or,EditorState as At,EditorView as $t,ensureSyntaxTree as nr,keymap as Zt,minimalSetup as rr,startCompletion as Xt}from"@vuu-ui/vuu-codemirror";import{createEl as zt}from"@vuu-ui/vuu-utils";import{useCallback as sr,useEffect as ir,useMemo as ar,useRef as je}from"react";import{LanguageSupport as In,LRLanguage as Qn,styleTags as Mn,tags as me}from"@vuu-ui/vuu-codemirror";import{LRParser as Vn}from"@lezer/lr";var ye=Vn.deserialize({version:14,states:"&xOVQPOOO!fQPO'#C^OVQPO'#CcQ!pQPOOO#bQPO'#CkO#gQPO'#CrOOQO'#Cy'#CyO#lQPO,58}OVQPO,59QOVQPO,59QOOQO'#Cn'#CnOVQPO,59XOVQPO,59VOVQPO'#CtOOQO,59^,59^OOQO1G.i1G.iOOQO1G.l1G.lO$bQPO1G.lO%ZQPO1G.sO!pQPO'#CmO%qQQO1G.qO%|QQO'#C{OOQO'#C{'#C{O&wQPO,59`OVQPO,59ZOVQPO,59[OVQPO7+$]OVQPO'#CuO'RQPO1G.zOOQO1G.z1G.zO'ZQQO'#C^O'eQQO1G.sO'{QQO1G.uOOQO1G.v1G.vO(WQPO<<GwO(_QPO,59aOOQO-E6s-E6sOOQO7+$f7+$fOVQPOAN=cO(iQQO1G.lO(yQPOG22}OOQOLD(iLD(iO)QQPO,59QO)QQPO,59QO)QQPO,59X",stateData:")n~OlOS~ORUOSUOTUOUUOWQO`SOnPO~OWgXZQX[QX]QX^QXpQXqQXrQXsQXtQXuQXeQX~OjQXXQX~PnOZWO[WO]XO^XOpYOqYOrYOsYOtYOuYO~OW[O~OW]O~OX_O~P!pO]Yi^YipYiqYirYisYitYiuYieYi~OZWO[WOjYiXYi~P#sOpaiqairaisaitaiuaieai~OZWO[WO]XO^XOjaiXai~P$rOejOvhOwiO~OZmX[mX]mX^mXeoXpmXqmXrmXsmXtmXumXvoXwoX~OXmOekO~P!pOXuOekO~OvQXwQX~PnOZzO[zO]{O^{Ovaiwai~P$rOwiOecivci~OevO~P!pOXiaeia~P!pOZzO[zOvYiwYi~P#sOXyO~P!pORUOSUOTUOUUOWQO`SOnnO~O`UTn~",goto:"$epPPqPPPPqPPqPPPPqP!S!g!r!rPq!w#Y#]PPP#cP$[oUOQWXZ[]hijkvz{|hUOQWXZ]jkvz{|Ve[hi[ZRVgrsxR|cVf[hioTOQWXZ[]hijkvz{|R^TQlgRtlQROQVQS`WzQaXQbZUc[hiQg]Qo|QrjQskQw{RxvQd[QphRqi",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:393});var An=Qn.define({name:"VuuColumnExpression",parser:ye.configure({props:[Mn({Column:me.attributeValue,Function:me.variableName,String:me.string,Or:me.emphasis,Operator:me.operator})]})}),Tt=()=>new In(An);var $e=class{constructor(e){switch(this.value=e,typeof e){case"boolean":this.type="booleanLiteralExpression";break;case"number":this.type="numericLiteralExpression";break;default:this.type="stringLiteralExpression"}}toJSON(){return{type:this.type,value:this.value}}},Ze=class{constructor(e){this.type="colExpression";this.column=e}toJSON(){return{type:this.type,column:this.column}}},ge,X,Xe=class{constructor(e="unknown"){L(this,ge,[{type:"unknown"},{type:"unknown"}]);L(this,X,void 0);this.type="arithmeticExpression";M(this,X,e)}get op(){return f(this,X)}set op(e){M(this,X,e)}get expressions(){return f(this,ge)}toJSON(){return{type:this.type,op:f(this,X),expressions:f(this,ge)}}};ge=new WeakMap,X=new WeakMap;var K,ze=class{constructor(e){L(this,K,[]);this.type="callExpression";this.functionName=e}get expressions(){return f(this,K)}get arguments(){return f(this,K)}toJSON(){return{type:this.type,functionName:this.functionName,arguments:f(this,K).map(e=>{var t;return(t=e.toJSON)==null?void 0:t.call(e)})}}};K=new WeakMap;var fe,j,_=class{constructor(){L(this,fe,[{type:"unknown"},{type:"unknown"}]);L(this,j,"unknown");this.type="relationalExpression"}get op(){return f(this,j)}set op(e){M(this,j,e)}get expressions(){return f(this,fe)}toJSON(){return{type:this.type,op:f(this,j),expressions:f(this,fe)}}};fe=new WeakMap,j=new WeakMap;var Ce,ee,J=class{constructor(e){L(this,Ce,[{type:"unknown"},{type:"unknown"}]);L(this,ee,void 0);this.type="booleanCondition";M(this,ee,e)}get op(){return f(this,ee)}get expressions(){return f(this,Ce)}toJSON(){return{type:this.type,op:f(this,ee),expressions:f(this,Ce).map(e=>{var t;return(t=e.toJSON)==null?void 0:t.call(e)})}}};Ce=new WeakMap,ee=new WeakMap;var R,de=class{constructor(e){L(this,R,void 0);this.type="conditionalExpression";M(this,R,[e?new J(e):new _,{type:"unknown"},{type:"unknown"}])}get expressions(){return f(this,R)}get condition(){return f(this,R)[0]}get truthyExpression(){return f(this,R)[1]}set truthyExpression(e){f(this,R)[1]=e}get falsyExpression(){return f(this,R)[2]}set falsyExpression(e){f(this,R)[2]=e}toJSON(){var e,t,n,i,r;return{type:this.type,condition:(t=(e=this.condition).toJSON)==null?void 0:t.call(e),truthyExpression:this.truthyExpression,falsyExpression:(r=(i=(n=this.falsyExpression)==null?void 0:n.toJSON)==null?void 0:i.call(n))!=null?r:this.falsyExpression}}};R=new WeakMap;var Z=o=>o.type==="unknown",Ee=o=>o.type==="arithmeticExpression",$n=o=>o.type==="callExpression",q=o=>o.type==="conditionalExpression",Zn=o=>o.type==="relationalExpression"||o.type==="booleanCondition";var Xn=o=>o.type==="booleanCondition",Ge=o=>(o==null?void 0:o.type)==="relationalExpression";var T=o=>{if(Z(o))return o;if(Ge(o)){let[e,t]=o.expressions;if(S(e))return T(e);if(o.op==="unknown")return o;if(S(t))return T(t)}else if(Zn(o)){let{expressions:e=[]}=o;for(let t of e)if(S(t))return T(t)}else if(q(o)){let{condition:e,truthyExpression:t,falsyExpression:n}=o;if(S(e))return T(e);if(S(t))return T(t);if(S(n))return T(n)}else if(Ee(o)){let{expressions:e=[]}=o;for(let t of e)if(S(t))return T(t)}},we=(o,e,t)=>{let{expressions:n=[]}=o;if(n.includes(e)){let i=n.indexOf(e);return n.splice(i,1,t),!0}else for(let i of n)if(we(i,e,t))return!0;return!1},S=o=>Z(o)?!0:q(o)?S(o.condition)||S(o.truthyExpression)||S(o.falsyExpression):Ge(o)||Xn(o)?o.op===void 0||o.expressions.some(e=>S(e)):!1,Ft=(o,e)=>{let t=T(o);t?t.expressions?t.expressions.push(e):console.warn("don't know how to treat targetExpression"):console.error("no target expression found")},h,z,Ue=class{constructor(){L(this,h,void 0);L(this,z,[])}setCondition(e){if(f(this,h)===void 0)this.addExpression(new de(e));else if(q(f(this,h))){if(S(f(this,h).condition)){let t=e?new J(e):new _;this.addExpression(t)}else if(Z(f(this,h).truthyExpression))f(this,h).truthyExpression=new de(e);else if(S(f(this,h).truthyExpression)){let t=e?new J(e):new _;this.addExpression(t)}else if(Z(f(this,h).falsyExpression))f(this,h).falsyExpression=new de(e);else if(S(f(this,h).falsyExpression)){let t=e?new J(e):new _;this.addExpression(t)}}else console.error("setCondition called unexpectedly")}addExpression(e){if(f(this,z).length>0){let t=f(this,z).at(-1);t==null||t.arguments.push(e)}else if(f(this,h)===void 0)M(this,h,e);else if(Ee(f(this,h))){let t=T(f(this,h));t&&Z(t)&&we(f(this,h),t,e)}else if(q(f(this,h))&&S(f(this,h))){let t=T(f(this,h));t&&Z(t)?we(f(this,h),t,e):t&&Ft(t,e)}}setFunction(e){let t=new ze(e);this.addExpression(t),f(this,z).push(t)}setColumn(e){this.addExpression(new Ze(e))}setArithmeticOp(e){let t=e,n=f(this,h);Ee(n)&&(n.op=t)}setRelationalOperator(e){let t=e;if(f(this,h)&&q(f(this,h))){let n=T(f(this,h));Ge(n)?n.op=t:console.error(`no target expression found (op = ${e})`)}}setValue(e){let t=new $e(e);if(f(this,h)===void 0)M(this,h,t);else if(Ee(f(this,h)))this.addExpression(t);else if($n(f(this,h)))f(this,h).arguments.push(t);else if(q(f(this,h)))if(S(f(this,h))){let n=T(f(this,h));n&&Z(n)?we(f(this,h),n,t):n&&Ft(n,t)}else console.log("what do we do with value, in a complete expression")}closeBrace(){f(this,z).pop()}get expression(){return f(this,h)}toJSON(){var e;return(e=f(this,h))==null?void 0:e.toJSON()}};h=new WeakMap,z=new WeakMap;var Pt=(o,e)=>{let t=new Ue,n=o.cursor();do{let{name:i,from:r,to:a}=n;switch(i){case"AndCondition":t.setCondition("and");break;case"OrCondition":t.setCondition("or");break;case"RelationalExpression":t.setCondition();break;case"ArithmeticExpression":t.addExpression(new Xe);break;case"Column":{let u=e.substring(r,a);t.setColumn(u)}break;case"Function":{let u=e.substring(r,a);t.setFunction(u)}break;case"Times":case"Divide":case"Plus":case"Minus":{let u=e.substring(r,a);t.setArithmeticOp(u)}break;case"RelationalOperator":{let u=e.substring(r,a);t.setRelationalOperator(u)}break;case"False":case"True":{let u=e.substring(r,a);t.setValue(u==="true")}break;case"String":t.setValue(e.substring(r+1,a-1));break;case"Number":t.setValue(parseFloat(e.substring(r,a)));break;case"CloseBrace":t.closeBrace();break;default:}}while(n.next());return t.toJSON()};var zn=ye.configure({strict:!0}),Lt=["Number","String"],We=[...Lt,"AndCondition","ArithmeticExpression","BooleanOperator","RelationalOperatorOperator","CallExpression","CloseBrace","Column","Comma","ConditionalExpression","Divide","Equal","If","Minus","OpenBrace","OrCondition","ParenthesizedExpression","Plus","RelationalExpression","RelationalOperator","Times"],Bt=o=>{try{return zn.parse(o),!0}catch{return!1}},Ye=o=>{let{lastChild:e}=o;for(;e&&!We.includes(e.name);)e=e.prevSibling,console.log(e==null?void 0:e.name);return e},Dt=o=>{if((o==null?void 0:o.name)==="RelationalExpression"){let{firstChild:e}=o,t=Ye(o);if((e==null?void 0:e.name)==="Column"&&typeof(t==null?void 0:t.name)=="string"&&Lt.includes(t.name))return!0}return!1};import{HighlightStyle as Un,syntaxHighlighting as Gn,tags as qe}from"@vuu-ui/vuu-codemirror";var Wn=Un.define([{tag:qe.attributeValue,color:"var(--vuuFilterEditor-variableColor);font-weight: bold"},{tag:qe.variableName,color:"var(--vuuFilterEditor-variableColor)"},{tag:qe.comment,color:"green",fontStyle:"italic"}]),Nt=Gn(Wn);import{EditorView as Yn}from"@vuu-ui/vuu-codemirror";var Rt=Yn.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-completionLabel":{color:"var(--vuu-color-gray-50)"},".cm-completionMatchedText":{color:"var(--vuu-color-gray-80)",fontWeight:700,textDecoration:"none"},".cm-tooltip":{background:"var(--vuuFilterEditor-tooltipBackground)",border:"var(--vuuFilterEditor-tooltipBorder)",borderRadius:"4px",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 qn,getNamedParentNode as Ht,getPreviousNode as _n,getValue as H,syntaxTree as Jn}from"@vuu-ui/vuu-codemirror";import{useCallback as Vt}from"react";var Kn=(o,e)=>e?o.map(t=>{var n;return{...t,apply:typeof t.apply=="function"?t.apply:`${e}${(n=t.apply)!=null?n:t.label}`}}):o,jn=o=>o===void 0?!1:["Times","Divide","Plus","Minus"].includes(o.name),ve=o=>({apply:()=>{o==null||o()},label:"Done",boost:10}),te=(o,e)=>{var i;let{lastChild:t}=o,{pos:n}=e;for(;t;)if(t.from<n&&We.includes(t.name)){if(t.name==="ParenthesizedExpression"){let a=(i=t.firstChild)==null?void 0:i.nextSibling;a&&(t=a)}return t}else t=t.prevSibling},It=(o,e)=>{var t;if(o.name==="ArgList"){let n=o.prevSibling;if(n)return H(n,e)}else if(o.name==="OpenBrace"){let n=(t=o.parent)==null?void 0:t.prevSibling;if((n==null?void 0:n.name)==="Function")return H(n,e)}},Qt=(o,e)=>{if(o.name==="RelationalExpression"){let t=Ye(o);if((t==null?void 0:t.name)==="RelationalOperator")return H(t,e)}else{let t=o.prevSibling;if((t==null?void 0:t.name)==="RelationalOperator")return H(t,e)}},Ke=(o,e)=>{var t;if(o.name==="RelationalExpression"){if(((t=o.firstChild)==null?void 0:t.name)==="Column")return H(o.firstChild,e)}else{let n=o.prevSibling;if((n==null?void 0:n.name)==="Column")return H(n,e);if((n==null?void 0:n.name)==="RelationalOperator")return Ke(n,e)}},_e=async(o,e,t,n={})=>{let i=await e.getSuggestions(t,n),{startsWith:r=""}=n;return{from:o.pos-r.length,options:i}},Je=(o,e,t,n,i)=>{let r=te(o,e);switch(r==null?void 0:r.name){case"If":return _e(e,t,"expression",{prefix:"( "});case"OpenBrace":return _e(e,t,"expression");case"Condition":return _e(e,t,"expression",{prefix:", "});case"CloseBrace":if(n){let a=[ve(i)];return{from:e.pos,options:a}}}},er=(o,e)=>{let t=[ve(e)];return{from:o.pos,options:t}},Mt=(o,e)=>{let t=Vt(async(n,i,r={})=>{let a=await o.getSuggestions(i,r),{startsWith:u=""}=r;return{from:n.pos-u.length,options:a}},[o]);return Vt(async n=>{var g,p;let{state:i,pos:r}=n,a=(g=n.matchBefore(/\w*/))!=null?g:{from:0,to:0,text:void 0},l=Jn(i).resolveInner(r,-1),c=i.doc.toString(),d=Bt(c);switch(l.name){case"If":return t(n,"expression",{prefix:"( "});case"Condition":{let s=te(l,n);if((s==null?void 0:s.name)==="Column"){let m=_n(s);if((m==null?void 0:m.name)!=="RelationalOperator")return t(n,"condition-operator",{columnName:H(s,i)})}else if((s==null?void 0:s.name)==="RelationalOperator")return t(n,"expression")}break;case"ConditionalExpression":return Je(l,n,o);case"RelationalExpression":{if(Dt(l))return{from:n.pos,options:qn.concat({label:", <truthy expression>, <falsy expression>",apply:", "})};{let s=Qt(l,i),m=Ke(l,i);if(s)return t(n,"expression");{let v=await o.getSuggestions("condition-operator",{columnName:m});return{from:n.pos,options:v}}}}break;case"RelationalOperator":return t(n,"expression");case"String":{let s=Qt(l,i),m=Ke(l,i),{from:v,to:C}=l;if(C-v===2&&n.pos===v+1){if(m&&s)return t(n,"columnValue",{columnName:m,operator:s,startsWith:a.text})}else if(C-v>2&&n.pos===C)return t(n,"expression",{prefix:", "})}break;case"ArithmeticExpression":{let s=te(l,n);if((s==null?void 0:s.name)==="Column")return t(n,"expression");if(jn(s)){let m=s.name;return t(n,"column",{operator:m})}}break;case"OpenBrace":{let s=It(l,i);return t(n,"expression",{functionName:s})}break;case"ArgList":{let s=It(l,i),m=te(l,n),v=(m==null?void 0:m.name)==="OpenBrace"||(m==null?void 0:m.name)==="Comma"?void 0:",",C=await o.getSuggestions("expression",{functionName:s});return C=v?Kn(C,", "):C,(m==null?void 0:m.name)!=="OpenBrace"&&(m==null?void 0:m.name)!=="Comma"&&(C=[{apply:") ",boost:10,label:"Done - no more arguments"}].concat(C)),{from:n.pos,options:C}}case"Equal":if(c.trim()==="=")return t(n,"expression");break;case"ParenthesizedExpression":case"ColumnDefinitionExpression":if(n.pos===0)return t(n,"expression");{let s=te(l,n);if((s==null?void 0:s.name)==="Column"){if(d){let m=[ve(e.current)],v=H(s,i),C=await o.getSuggestions("operator",{columnName:v});return{from:n.pos,options:m.concat(C)}}}else if((s==null?void 0:s.name)==="CallExpression"){if(d)return{from:n.pos,options:[ve(e.current)]}}else if((s==null?void 0:s.name)==="ArithmeticExpression"){if(d){let m=[ve(e.current)],v=te(s,n);if((v==null?void 0:v.name)==="Column"){let C=H(v,i),x=await o.getSuggestions("operator",{columnName:C});m=m.concat(x)}return{from:n.pos,options:m}}}else if((s==null?void 0:s.name)==="ConditionalExpression")return Je(s,n,o,d,e.current);break}case"Column":if(await o.isPartialMatch("expression",void 0,a.text))return t(n,"expression",{startsWith:a.text});break;case"Comma":{let s=Ht(l);if((s==null?void 0:s.name)==="ConditionalExpression")return t(n,"expression")}break;case"CloseBrace":{let s=Ht(l);if((s==null?void 0:s.name)==="ConditionalExpression")return Je(s,n,o,d,e.current);if((s==null?void 0:s.name)==="ArgList"&&d)return er(n,e.current)}break;default:((p=l==null?void 0:l.prevSibling)==null?void 0:p.name)==="FilterClause"&&console.log("looks like we ight be a or|and operator")}},[t,e,o])};var Oe=o=>{if(o.current==null)throw Error("EditorView not defined");return o.current},lr=()=>"vuuSuggestion",ur=()=>console.log("noooop"),pr=o=>"expressionType"in o,cr=o=>{if(pr(o)){let e=zt("div","expression-type-container"),t=zt("span","expression-type",o.expressionType);return e.appendChild(t),e}else return null},Ut=({onChange:o,onSubmitExpression:e,source:t,suggestionProvider:n})=>{let i=je(null),r=je(ur),a=je(),u=Mt(n,r),[l,c,d]=ar(()=>{let p=()=>{let x=Oe(a),b=x.state.doc.toString(),w=nr(x.state,x.state.doc.length,5e3);if(w){let Q=Pt(w,b);return[b,Q]}else return["",void 0]},s=()=>{Oe(a).setState(C())},m=()=>{let[x,b]=p();e==null||e(x,b)},v=x=>Zt.of([{key:x,run(){return Xt(Oe(a)),!0}}]),C=()=>At.create({doc:t,extensions:[rr,tr({addToOptions:[{render:cr,position:70}],override:[u],optionClass:lr}),Tt(),Zt.of(or),v("ArrowDown"),$t.updateListener.of(x=>{let b=Oe(a);if(x.docChanged){Xt(b);let w=b.state.doc.toString();o==null||o(w)}}),At.transactionFilter.of(x=>x.newDoc.lines>1?[]:x),Rt,Nt]});return r.current=()=>{m()},[C,s,m]},[u,o,e,t]);ir(()=>{if(!i.current)throw Error("editor not in dom");return a.current=new $t({state:l(),parent:i.current}),()=>{var p;(p=a.current)==null||p.destroy()}},[u,l]);let g=sr(()=>{d()},[d]);return{editorRef:i,clearInput:c,onBlur:g}};import{jsx as gr}from"react/jsx-runtime";var dr="vuuColumnExpressionInput",et=mr(({onChange:o,onSubmitExpression:e,source:t="",suggestionProvider:n})=>{let{editorRef:i,onBlur:r}=Ut({onChange:o,onSubmitExpression:e,source:t,suggestionProvider:n});return gr("div",{className:`${dr}`,onBlur:r,ref:i})},(o,e)=>o.source===e.source);et.displayName="ColumnExpressionInput";import{AnnotationType as fr,getRelationalOperators as Cr,numericOperators as vr,stringOperators as xr,toSuggestions as hr}from"@vuu-ui/vuu-codemirror";import{getTypeaheadParams as br,useTypeaheadSuggestions as yr}from"@vuu-ui/vuu-data-react";import{isNumericColumn as ot,isTextColumn as Er}from"@vuu-ui/vuu-utils";import{useCallback as tt,useRef as wr}from"react";var oe=[{accepts:["boolean"],description:"Applies boolean and operator across supplied parameters to returns a single boolean result",example:{expression:'and(ccy="EUR",quantity=0)',result:"true | false"},name:"and",params:{description:"( boolean, [ boolean* ] )"},type:"boolean"},{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:["boolean"],description:"Applies boolean or operator across supplied parameters to returns a single boolean result",example:{expression:'or(status="cancelled",quantity=0)',result:"true | false"},name:"or",params:{description:"( boolean, [ boolean* ] )"},type:"boolean"},{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 V}from"@vuu-ui/vuu-utils";var Gt=({name:o,description:e,example:t,params:n,type:i})=>{let r=V("div","vuuFunctionDoc"),a=V("div","function-heading"),u=V("span","function-name",o),l=V("span","param-list",n.description),c=V("span","function-type",i);a.appendChild(u),a.appendChild(l),a.appendChild(c);let d=V("p",void 0,e);if(r.appendChild(a),r.appendChild(d),t){let g=V("div","example-container"),p=V("div","example-expression",t.expression),s=V("div","example-result",t.result);g.appendChild(p),r.appendChild(g),r.appendChild(s)}return r};var Or=[],U=o=>o.map(e=>{var t;return{...e,apply:((t=e.apply)!=null?t:e.label)+" "}}),Sr=(o,{functionName:e,operator:t})=>{if(t)return o.filter(ot);if(e){let n=oe.find(i=>i.name===e);if(n)switch(n.accepts){case"string":return o.filter(Er);case"number":return o.filter(ot);default:return o}}return o},Wt=(o,e)=>Sr(o,e).map(n=>{var r;let i=(r=n.label)!=null?r:n.name;return{apply:e.prefix?`${e.prefix}${n.name}`:n.name,label:i,boost:5,type:"column",expressionType:n.serverDataType}}),kr=[{apply:"* ",boost:2,label:"*",type:"operator"},{apply:"/ ",boost:2,label:"/",type:"operator"},{apply:"+ ",boost:2,label:"+",type:"operator"},{apply:"- ",boost:2,label:"-",type:"operator"}],Tr=o=>o===void 0||ot(o)?kr:Or,Fr=o=>{switch(o.serverDataType){case"string":case"char":return U(xr);case"int":case"long":case"double":return U(vr)}},nt=o=>({apply:`${o.name}( `,boost:2,expressionType:o.type,info:()=>Gt(o),label:o.name,type:"function"}),Pr=o=>{if(o){if(typeof o.accepts=="string")return o.accepts;if(Array.isArray(o.accepts))return o.accepts.every(e=>e==="string")?"string":"any"}return"any"},Lr=oe.map(nt),Br=({functionName:o})=>{if(o){let e=oe.find(n=>n.name===o),t=Pr(e);if(e)switch(t){case"string":return oe.filter(n=>n.type==="string"||n.type==="variable").map(nt);case"number":return oe.filter(n=>n.type==="number"||n.type==="variable").map(nt);default:}}return Lr},Dr={},Yt=({columns:o,table:e})=>{let t=tt(u=>u?o.find(l=>l.name===u):void 0,[o]),n=wr(),i=yr(),r=tt(async(u,l=Dr)=>{let{columnName:c,functionName:d,operator:g,prefix:p}=l;switch(u){case"expression":{let s=await U(Wt(o,{functionName:d,prefix:p})).concat(Br(l));return n.current=s}case"column":{let s=await Wt(o,l);return n.current=U(s)}case"operator":{let s=await Tr(t(c));return n.current=U(s)}case"relational-operator":{let s=await Cr(t(c));return n.current=U(s)}case"condition-operator":{let s=t(c);if(s){let m=await Fr(s);if(m)return n.current=U(m)}}break;case"columnValue":if(c&&g){let s=br(e,c),m=await i(s);return n.current=hr(m,{suffix:""}),n.current.forEach(v=>{v.apply=(C,x,b)=>{let w=new fr,Q=b+x.label.length+1;C.dispatch({changes:{from:b,insert:x.label},selection:{anchor:Q,head:Q},annotations:w.of(x)})}}),n.current}break}return[]},[o,t,i,e]),a=tt(async(u,l,c)=>{let{current:d}=n,g=!1,p=d||await r(u,{columnName:l});if(c&&p)for(let s of p){if(s.label===c)return!1;s.label.startsWith(c)&&(g=!0)}return g},[r]);return{getSuggestions:r,isPartialMatch:a}};import{getCalculatedColumnDetails as Nr,setCalculatedColumnExpression as Rr,setCalculatedColumnName as Hr,setCalculatedColumnType as Vr}from"@vuu-ui/vuu-utils";import{useCallback as Se,useRef as Ir,useState as Qr}from"react";var Mr=o=>{let[e,t,n]=Nr(o);return n===""?{...o,name:`${e}:string:${t}`}:o},qt=({column:o,onChangeName:e})=>{let[t,n]=Qr(Mr(o)),i=Ir(o),r=Se(c=>{i.current=c,n(c)},[]),a=Se(c=>{let{value:d}=c.target,g=Hr(t,d);r(g),e==null||e(g.name)},[t,e,r]),u=Se(c=>{let d=c.trim(),{current:g}=i,p=Rr(g,d);r(p),e==null||e(p.name)},[e,r]),l=Se((c,d)=>{if(typeof d=="string"){let g=Vr(t,d);r(g),e==null||e(g.name)}},[t,e,r]);return{column:t,onChangeExpression:u,onChangeName:a,onChangeType:l}};import{jsx as A,jsxs as ke}from"react/jsx-runtime";var Jt="vuuColumnExpressionPanel",Kt=({column:o,onChangeName:e,tableConfig:t,vuuTable:n})=>{let i=_t(null),{column:r,onChangeExpression:a,onChangeName:u,onChangeType:l}=qt({column:o,onChangeName:e}),c=_t($r(r)),d=Yt({columns:t.columns,table:n}),g=Ur(()=>{var p,s;i.current&&((s=(p=i.current)==null?void 0:p.querySelector("button"))==null||s.focus())},[]);return ke("div",{className:Jt,children:[A("div",{className:"vuuColumnSettingsPanel-header",children:A("span",{children:"Calculation"})}),ke(rt,{"data-field":"column-name",children:[A(st,{children:"Column Name"}),A(zr,{className:"vuuInput",onChange:u,value:Zr(r)})]}),ke(rt,{"data-field":"column-expression",children:[A(st,{children:"Expression"}),A(et,{onChange:a,onSubmitExpression:g,source:c.current,suggestionProvider:d})]}),ke(rt,{"data-field":"type",children:[A(st,{children:"Column type"}),A(Ar,{className:`${Jt}-type`,onSelectionChange:l,ref:i,selected:Xr(r)||null,source:["double","long","string"],width:"100%"})]})]})};import{Dropdown as vs}from"@vuu-ui/vuu-ui-controls";import{getCellRendererOptions as xs,getConfigurationEditor as hs,isColumnTypeRenderer as io,isTypeDescriptor as ao}from"@vuu-ui/vuu-utils";import{FormField as bs,FormFieldLabel as ys}from"@salt-ds/core";import lo from"clsx";import{useCallback as Es,useMemo as pt}from"react";import{FormField as it,FormFieldLabel as at,Input as Gr,Switch as jt}from"@salt-ds/core";import{getTypeFormattingFromColumn as Wr}from"@vuu-ui/vuu-utils";import{useCallback as Te,useState as Yr}from"react";import{jsx as ne,jsxs as Fe}from"react/jsx-runtime";var qr="vuuFormattingSettings",Pe=({column:o,onChangeFormatting:e})=>{var l,c,d;let[t,n]=Yr(Wr(o)),i=Te(g=>{(g.key==="Enter"||g.key==="Tab")&&e(t)},[t,e]),r=Te(g=>{let{value:p}=g.target,s=p===""||isNaN(parseInt(p))?void 0:parseInt(p),m={...t,decimals:s};n(m)},[t]),a=Te(g=>{let{checked:p}=g.target,s={...t,alignOnDecimals:p};n(s),e(s)},[t,e]),u=Te(g=>{let{checked:p}=g.target,s={...t,zeroPad:p};n(s),e(s)},[t,e]);return Fe("div",{className:qr,children:[Fe(it,{"data-field":"decimals",children:[ne(at,{children:"Number of decimals"}),ne(Gr,{className:"vuuInput",onChange:r,onKeyDown:i,value:(l=t.decimals)!=null?l:""})]}),Fe(it,{labelPlacement:"left",children:[ne(at,{children:"Align on decimals"}),ne(jt,{checked:(c=t.alignOnDecimals)!=null?c:!1,onChange:a,value:"align-decimals"})]}),Fe(it,{labelPlacement:"left",children:[ne(at,{children:"Zero pad decimals"}),ne(jt,{checked:(d=t.zeroPad)!=null?d:!1,onChange:u,value:"zero-pad"})]})]})};import{useCallback as ls}from"react";import{FormField as us,FormFieldLabel as ps,ToggleButton as cs,ToggleButtonGroup as ms}from"@salt-ds/core";import{isDateTimeColumn as ds,isTypeDescriptor as gs}from"@vuu-ui/vuu-utils";import{useCallback as lt,useMemo as _r,useState as Jr}from"react";import{Dropdown as Kr}from"@vuu-ui/vuu-ui-controls";import{defaultPatternsByType as eo,fallbackDateTimePattern as jr,getTypeFormattingFromColumn as es,supportedDateTimePatterns as ts}from"@vuu-ui/vuu-utils";import{FormField as to,FormFieldLabel as oo,ToggleButton as os,ToggleButtonGroup as ns}from"@salt-ds/core";import{Fragment as as,jsx as xe,jsxs as ut}from"react/jsx-runtime";var no=({column:o,onChangeFormatting:e})=>{var d,g;let t=es(o),{pattern:n=jr}=t,i=_r(()=>is(n),[n]),[r,a]=Jr({time:(d=n.time)!=null?d:eo.time,date:(g=n.date)!=null?g:eo.date}),u=lt(p=>e({...t,pattern:p}),[e,t]),l=lt(p=>(s,m)=>{let v={...n!=null?n:{},[p]:m};a(C=>{var x,b;return{time:(x=v.time)!=null?x:C.time,date:(b=v.date)!=null?b:C.date}}),u(v)},[u,n]),c=lt(p=>{var m,v,C,x;let s=p.currentTarget.value;switch(s){case"time":return u({[s]:(m=n[s])!=null?m:r[s]});case"date":return u({[s]:(v=n[s])!=null?v:r[s]});case"both":return u({time:(C=n.time)!=null?C:r.time,date:(x=n.date)!=null?x:r.date})}},[u,n,r]);return ut(as,{children:[ut(to,{labelPlacement:"left",children:[xe(oo,{children:"Display"}),xe(ns,{className:"vuuToggleButtonGroup",onChange:c,value:i,children:ss.map(p=>xe(os,{value:p,children:p.toUpperCase()},p))})]}),["date","time"].filter(p=>!!n[p]).map(p=>ut(to,{labelPlacement:"left",children:[xe(oo,{children:`${rs[p]} pattern`}),xe(Kr,{onSelectionChange:l(p),selected:n[p],source:ts[p],width:"100%"})]},p))]})},rs={date:"Date",time:"Time"},ss=["date","time","both"];function is(o){return o.time?o.date?"both":"time":"date"}import{jsx as he,jsxs as ro}from"react/jsx-runtime";var fs="vuuLongColumnFormattingSettings",so=o=>{let{column:e,onChangeType:t}=o,n=gs(e.type)?e.type.name:e.type,i=ls(r=>{let a=r.currentTarget.value;t(a)},[t]);return ro("div",{className:fs,children:[ro(us,{children:[he(ps,{children:"Type inferred as"}),he(ms,{className:"vuuToggleButtonGroup",onChange:i,value:n!=null?n:"number",children:Cs.map(r=>he(cs,{value:r,children:r.toUpperCase()},r))})]}),ds(e)?he(no,{...o,column:e}):he(Pe,{...o})]})},Cs=["number","date/time"];import{jsx as re,jsxs as mt}from"react/jsx-runtime";var ct="vuuColumnFormattingPanel",ws=o=>{var e;return(e=o.label)!=null?e:o.name},uo=({availableRenderers:o,className:e,column:t,onChangeFormatting:n,onChangeType:i,onChangeRendering:r,...a})=>{let u=pt(()=>Os({column:t,onChangeFormatting:n,onChangeType:i}),[t,n,i]),l=pt(()=>{let{type:p}=t;if(ao(p)&&io(p.renderer)){let s=xs(p.renderer.name);return hs(s==null?void 0:s.configEditor)}},[t]),c=pt(()=>{let{type:p}=t,[s]=o,m=ao(p)&&io(p.renderer)?p.renderer.name:void 0,v=o.find(C=>C.name===m);return v!=null?v:s},[o,t]),d=Es((p,s)=>{let m={name:s.name};r==null||r(m)},[r]),{serverDataType:g="string"}=t;return mt("div",{...a,className:"vuuColumnSettingsPanel-header",children:[re("div",{children:"Formatting"}),mt(bs,{children:[re(ys,{children:`Renderer (data type ${t.serverDataType})`}),re(vs,{className:lo(`${ct}-renderer`),itemToString:ws,onSelectionChange:d,selected:c,source:o,width:"100%"})]}),mt("div",{className:lo(ct,e,`${ct}-${g}`),children:[u,l?re(l,{column:t,onChangeRendering:r}):null]})]})};function Os(o){let{column:e}=o;switch(e.serverDataType){case"double":case"int":return re(Pe,{...o});case"long":return re(so,{...o});default:return null}}import Ss from"clsx";import{getCalculatedColumnDetails as ks,isCalculatedColumn as Ts}from"@vuu-ui/vuu-utils";import{jsx as G,jsxs as Fs}from"react/jsx-runtime";var se="vuuColumnNameLabel",po=({column:o,onClick:e})=>{if(Ts(o.name)){let[t,n,i]=ks(o),r=t||"name",a="=expression",u=r==="name"?`${se}-placeholder`:void 0,l=i===""?`${se}-placeholder`:void 0;return Fs("div",{className:Ss(se,`${se}-calculated`),onClick:e,children:[G("span",{className:u,children:r}),G("span",{children:":"}),G("span",{children:n||"string"}),G("span",{children:":"}),G("span",{className:l,children:a}),G("span",{className:`${se}-edit`,"data-icon":"edit"})]})}else return G("div",{className:se,children:o.name})};import{getRegisteredCellRenderers as Le,isValidColumnAlignment as Ps,isValidPinLocation as Ls,setCalculatedColumnName as Bs,updateColumnRenderProps as Ds,updateColumnFormatting as Ns,updateColumnType as Rs}from"@vuu-ui/vuu-utils";import{useCallback as F,useEffect as Hs,useMemo as Vs,useRef as Is,useState as co}from"react";var Qs=[{description:"Default formatter for columns with data type integer",label:"Default Renderer (int, long)",name:"default-int"},...Le("int")],Ms=[{description:"Default formatter for columns with data type double",label:"Default Renderer (double)",name:"default-double"},...Le("double")],mo=[{description:"Default formatter for columns with data type string",label:"Default Renderer (string)",name:"default-string"},...Le("string")],As=[...Le("boolean")],$s=o=>{switch(o.serverDataType){case"char":case"string":return mo;case"int":case"long":return Qs;case"double":return Ms;case"boolean":return As;default:return mo}},Zs=o=>{let e=o.closest(".saltFormField");if(e&&e.dataset.field){let{dataset:{field:t}}=e;return t}else throw Error("named form field not found")},Xs=(o,e)=>{if(e.name==="::")return e;{let t=o.find(n=>n.name===e.name);if(t)return t;throw Error(`columns does not contain column ${name}`)}},ie=(o,e)=>({...o,columns:o.columns.map(t=>t.name===e.name?e:t)}),go=({column:o,onCancelCreateColumn:e,onConfigChange:t,onCreateCalculatedColumn:n,tableConfig:i})=>{let[r,a]=co(Xs(i.columns,o)),u=Is(r),[l,c]=co(r.name==="::"),d=F(()=>{u.current=r,c(!0)},[r]);Hs(()=>{a(o),c(o.name==="::")},[o]);let g=Vs(()=>$s(r),[r]),p=F(()=>{t(ie(i,r))},[r,t,i]),s=F(O=>{let E=O.target,Ie=Zs(E),{value:B}=E;switch(Ie){case"column-label":a(P=>({...P,label:B}));break;case"column-name":a(P=>Bs(P,B));break;case"column-width":a(P=>({...P,width:parseInt(B)}));break;case"column-alignment":if(Ps(B)){let P={...r,align:B||void 0};a(P),t(ie(i,P))}break;case"column-pin":if(Ls(B)){let P={...r,pin:B||void 0};a(P),t(ie(i,P));break}}},[r,t,i]),m=F(O=>{a(E=>({...E,name:O}))},[]),v=F(O=>{let E=Ns(r,O);a(E),t(ie(i,E))},[r,t,i]),C=F(O=>{let E=Rs(r,O);a(E),t(ie(i,E))},[r,t,i]),x=F(O=>{if(O){let E=Ds(r,O);a(E),t(ie(i,E))}},[r,t,i]),b=F(({moveBy:O})=>{let{columns:E}=i,Ie=E.indexOf(r)+O,B=E[Ie];B&&a(B)},[r,i]),w=F(()=>{b({moveBy:1})},[b]),Q=F(()=>{b({moveBy:-1})},[b]),He=F(()=>{n(r)},[r,n]),Ve=F(()=>{o.name==="::"?e():(u.current!==void 0&&u.current!==r&&a(u.current),c(!1))},[r,o.name,e]);return{availableRenderers:g,editCalculatedColumn:l,column:r,navigateNextColumn:w,navigatePrevColumn:Q,onCancel:Ve,onChange:s,onChangeCalculatedColumnName:m,onChangeFormatting:v,onChangeRendering:x,onChangeType:C,onEditCalculatedColumn:d,onInputCommit:p,onSave:He}};import{jsx as y,jsxs as I}from"react/jsx-runtime";var $="vuuColumnSettingsPanel",Ys=o=>{let{name:e,label:t}=o;return Gs(e)?t!=null?t:zs(o):t!=null?t:e},Mp=({column:o,onCancelCreateColumn:e,onConfigChange:t,onCreateCalculatedColumn:n,tableConfig:i,vuuTable:r})=>{let a=o.name==="::",{availableRenderers:u,editCalculatedColumn:l,column:c,navigateNextColumn:d,navigatePrevColumn:g,onCancel:p,onChange:s,onChangeCalculatedColumnName:m,onChangeFormatting:v,onChangeRendering:C,onChangeType:x,onEditCalculatedColumn:b,onInputCommit:w,onSave:Q}=go({column:o,onCancelCreateColumn:e,onConfigChange:t,onCreateCalculatedColumn:n,tableConfig:i}),{serverDataType:He,align:Ve=Us(He),pin:O,width:E}=c;return I("div",{className:Ws($,{[`${$}-editing`]:l}),children:[y("div",{className:`${$}-header`,children:y(po,{column:c,onClick:b})}),l?y(Kt,{column:c,onChangeName:m,tableConfig:i,vuuTable:r}):null,I(De,{"data-field":"column-label",children:[y(Ne,{children:"Column Label"}),y(fo,{className:"vuuInput",onChange:s,onCommit:w,value:Ys(c)})]}),I(De,{"data-field":"column-width",children:[y(Ne,{children:"Column Width"}),y(fo,{className:"vuuInput",onChange:s,value:E,onCommit:w})]}),I(De,{"data-field":"column-alignment",children:[y(Ne,{children:"Alignment"}),I(Co,{className:"vuuToggleButtonGroup",onChange:s,value:Ve,children:[y(ae,{"data-icon":"align-left",className:"vuuIconToggleButton",value:"left"}),y(ae,{"data-icon":"align-right",className:"vuuIconToggleButton",value:"right"})]})]}),I(De,{"data-field":"column-pin",children:[y(Ne,{children:"Pin Column"}),I(Co,{className:"vuuToggleButtonGroup",onChange:s,value:O!=null?O:"",children:[y(ae,{className:"vuuIconToggleButton","data-icon":"cross-circle",value:""}),y(ae,{className:"vuuIconToggleButton","data-icon":"pin-left",value:"left"}),y(ae,{className:"vuuIconToggleButton","data-icon":"pin-float",value:"floating"}),y(ae,{className:"vuuIconToggleButton","data-icon":"pin-right",value:"right"})]})]}),y(uo,{availableRenderers:u,column:c,onChangeFormatting:v,onChangeRendering:C,onChangeType:x}),l?I("div",{className:"vuuColumnSettingsPanel-buttonBar","data-align":"right",children:[y(Be,{className:`${$}-buttonCancel`,onClick:p,tabIndex:-1,children:"cancel"}),y(Be,{className:`${$}-buttonSave`,onClick:Q,variant:"cta",children:"save"})]}):I("div",{className:`${$}-buttonBar`,"data-align":a?"right":void 0,children:[y(Be,{className:`${$}-buttonNavPrev`,variant:"secondary","data-icon":"arrow-left",onClick:g,children:"PREVIOUS"}),y(Be,{className:`${$}-buttonNavNext`,variant:"secondary","data-icon":"arrow-right",onClick:d,children:"NEXT"})]})]})};import qs from"clsx";import{useEffect as _s,useState as vo}from"react";import{jsx as le,jsxs as Js}from"react/jsx-runtime";var be="vuuDatasourceStats",dt=new Intl.NumberFormat,_p=({className:o,dataSource:e})=>{let[t,n]=vo(e.range),[i,r]=vo(e.size);_s(()=>{r(e.size),e.on("resize",r),e.on("range",n)},[e]);let a=qs(be,o),u=dt.format(t.from+1),l=dt.format(Math.min(t.to,i)),c=dt.format(i);return Js("div",{className:a,children:[le("span",{className:`${be}-label`,children:"Row count"}),le("span",{className:`${be}-range`,children:u}),le("span",{children:"-"}),le("span",{className:`${be}-range`,children:l}),le("span",{children:"of"}),le("span",{className:`${be}-size`,children:c})]})};import{Button as li,FormField as gt,FormFieldLabel as ft,Input as ui,ToggleButton as ue,ToggleButtonGroup as pi}from"@salt-ds/core";import{updateTableConfig as Ks}from"@vuu-ui/vuu-table";import{addColumnToSubscribedColumns as js,isCalculatedColumn as ei,moveItem as ti,subscribedOnly as oi,useLayoutEffectSkipFirst as ni}from"@vuu-ui/vuu-utils";import{useCallback as Re,useMemo as ri,useState as si}from"react";var ii=(o,e)=>{let t=[];for(let{name:n}of o){let i=e.find(r=>r.name===n);i&&t.push(i)}return t},ai=(o,e)=>o.map(({name:t,serverDataType:n})=>{let i=e.find(r=>r.name===t);return{hidden:i==null?void 0:i.hidden,isCalculated:ei(t),label:i==null?void 0:i.label,name:t,serverDataType:n,subscribed:i!==void 0}}),xo=({availableColumns:o,onConfigChange:e,onDataSourceConfigChange:t,tableConfig:n})=>{let[{availableColumns:i,tableConfig:r},a]=si({availableColumns:o,tableConfig:n}),u=ri(()=>ai(i,r.columns),[i,r.columns]),l=Re((s,m)=>{a(v=>{let C=ti(v.availableColumns,s,m),x=ii(C,r.columns);return{availableColumns:C,tableConfig:{...v.tableConfig,columns:x}}})},[r.columns]),c=Re((s,m,v)=>{let C=u.find(x=>x.name===s);if(m==="subscribed")if(C!=null&&C.subscribed){let x=r.columns.filter(b=>b.name!==s).map(b=>b.name);a(b=>({...b,tableConfig:{...r,columns:r.columns.filter(oi(x))}})),t({columns:x})}else{let x={...r,columns:js(r.columns,i,s)};a(w=>({...w,tableConfig:x}));let b=x.columns.map(w=>w.name);t({columns:b})}else if(C!=null&&C.subscribed){let x=r.columns.find(b=>b.name===s);if(x){let b=Ks(r,{type:"column-prop",property:m,column:x,value:v});a(w=>({...w,tableConfig:b}))}}},[i,u,t,r]),d=Re(s=>{let{value:m}=s.target,v=m==="0"?void 0:m==="1"?"capitalize":"uppercase";a(C=>({...C,tableConfig:{...C.tableConfig,columnFormatHeader:v}}))},[]),g=Re(s=>{let{ariaChecked:m,value:v}=s.target;a(C=>({...C,tableConfig:{...C.tableConfig,[v]:m!=="true"}}))},[]);ni(()=>{e==null||e(r)},[e,r]);let p=r.columnFormatHeader===void 0?0:r.columnFormatHeader==="capitalize"?1:2;return{columnItems:u,columnLabelsValue:p,onChangeColumnLabels:d,onChangeTableAttribute:g,onColumnChange:c,onMoveListItem:l,tableConfig:r}};import{jsx as k,jsxs as W}from"react/jsx-runtime";var Ct="vuuTableSettingsPanel",dc=({availableColumns:o,onAddCalculatedColumn:e,onConfigChange:t,onDataSourceConfigChange:n,onNavigateToColumn:i,tableConfig:r})=>{var s,m,v;let{columnItems:a,columnLabelsValue:u,onChangeColumnLabels:l,onChangeTableAttribute:c,onColumnChange:d,onMoveListItem:g,tableConfig:p}=xo({availableColumns:o,onConfigChange:t,onDataSourceConfigChange:n,tableConfig:r});return W("div",{className:Ct,children:[W(gt,{children:[k(ft,{children:"Column Labels"}),W(pi,{className:"vuuToggleButtonGroup",onChange:l,value:u,children:[k(ue,{className:"vuuIconToggleButton","data-icon":"text-strikethrough",value:0}),k(ue,{className:"vuuIconToggleButton","data-icon":"text-Tt",value:1}),k(ue,{className:"vuuIconToggleButton","data-icon":"text-T",value:2})]})]}),W(gt,{children:[k(ft,{children:"Grid separators"}),W("div",{className:"saltToggleButtonGroup vuuToggleButtonGroup saltToggleButtonGroup-horizontal vuuGridSeparators",children:[k(ue,{className:"vuuIconToggleButton","data-icon":"row-striping",selected:(s=p.zebraStripes)!=null?s:!1,onChange:c,value:"zebraStripes"}),k(ue,{className:"vuuIconToggleButton","data-icon":"row-lines",selected:(m=p.rowSeparators)!=null?m:!1,onChange:c,value:"rowSeparators"}),k(ue,{className:"vuuIconToggleButton","data-icon":"col-lines",selected:(v=p.columnSeparators)!=null?v:!1,onChange:c,value:"columnSeparators"})]})]}),W(gt,{children:[k(ft,{children:"Default Column Width"}),k(ui,{className:"vuuInput"})]}),k(kt,{columnItems:a,onChange:d,onMoveListItem:g,onNavigateToColumn:i}),W("div",{className:`${Ct}-calculatedButtonbar`,children:[k(li,{"data-icon":"plus",onClick:e}),k("span",{className:`${Ct}-calculatedLabel`,children:"Add calculated column"})]})]})};export{Uo as BackgroundCell,on as BackgroundCellConfigurationEditor,Pe as BaseNumericFormattingSettings,yo as CaseValidator,et as ColumnExpressionInput,Kt as ColumnExpressionPanel,uo as ColumnFormattingPanel,kt as ColumnList,We as ColumnNamedTerms,Mp as ColumnSettingsPanel,_p as DataSourceStats,no as DateTimeFormattingSettings,Cn as DropdownCell,En as LookupCell,So as PatternValidator,dc as TableSettingsPanel,Tt as columnExpressionLanguageSupport,Bt as isCompleteExpression,Dt as isCompleteRelationalExpression,Ye as lastNamedChild,Ut as useColumnExpressionEditor,Yt as useColumnExpressionSuggestionProvider,xo as useTableSettings,Pt as walkTree};
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+
20
+ // src/cell-edit-validators/CaseValidator.ts
21
+ import { registerComponent } from "@vuu-ui/vuu-utils";
22
+ var isString = (value) => typeof value === "string";
23
+ var CaseValidator = (rule, value) => {
24
+ if (isString(value)) {
25
+ if (value === "") {
26
+ return true;
27
+ } else if (rule.value === "lower" && value.toLowerCase() !== value) {
28
+ return "value must be all lowercase";
29
+ } else if (rule.value === "upper" && value.toUpperCase() !== value) {
30
+ return "value must be all uppercase";
31
+ } else {
32
+ return true;
33
+ }
34
+ } else {
35
+ return "value must be a string";
36
+ }
37
+ };
38
+ registerComponent("vuu-case", CaseValidator, "data-edit-validator", {});
39
+
40
+ // src/cell-edit-validators/PatternValidator.ts
41
+ import { registerComponent as registerComponent2 } from "@vuu-ui/vuu-utils";
42
+ var isString2 = (value) => typeof value === "string";
43
+ var defaultMessage = "value does not match expected pattern";
44
+ var PatternValidator = (rule, value) => {
45
+ if (typeof rule.value !== "string") {
46
+ throw Error("Pattern validation rule must provide pattern");
47
+ }
48
+ if (isString2(value)) {
49
+ if (value === "") {
50
+ return true;
51
+ } else {
52
+ const { message = defaultMessage } = rule;
53
+ const pattern = new RegExp(rule.value);
54
+ return pattern.test(value) || message;
55
+ }
56
+ } else {
57
+ return "value must be a string";
58
+ }
59
+ };
60
+ registerComponent2("vuu-pattern", PatternValidator, "data-edit-validator", {});
61
+
62
+ // src/cell-renderers/background-cell/BackgroundCell.tsx
63
+ import {
64
+ dataAndColumnUnchanged,
65
+ DOWN1,
66
+ DOWN2,
67
+ isTypeDescriptor as isTypeDescriptor2,
68
+ metadataKeys,
69
+ registerComponent as registerComponent3,
70
+ UP1,
71
+ UP2
72
+ } from "@vuu-ui/vuu-utils";
73
+ import cx from "clsx";
74
+ import { memo } from "react";
75
+
76
+ // src/cell-renderers/background-cell/useDirection.ts
77
+ import {
78
+ getMovingValueDirection,
79
+ isTypeDescriptor,
80
+ isValidNumber
81
+ } from "@vuu-ui/vuu-utils";
82
+ import { useEffect, useRef } from "react";
83
+ var INITIAL_VALUE = [void 0, void 0, void 0, void 0];
84
+ function useDirection(key, value, column) {
85
+ var _a;
86
+ const ref = useRef();
87
+ const [prevKey, prevValue, prevColumn, prevDirection] = ref.current || INITIAL_VALUE;
88
+ const { type: dataType } = column;
89
+ const decimals = isTypeDescriptor(dataType) ? (_a = dataType.formatting) == null ? void 0 : _a.decimals : void 0;
90
+ const direction = key === prevKey && isValidNumber(value) && isValidNumber(prevValue) && column === prevColumn ? getMovingValueDirection(value, prevDirection, prevValue, decimals) : "";
91
+ useEffect(() => {
92
+ ref.current = [key, value, column, direction];
93
+ });
94
+ return direction;
95
+ }
96
+
97
+ // src/cell-renderers/background-cell/BackgroundCell.tsx
98
+ import { jsx, jsxs } from "react/jsx-runtime";
99
+ var CHAR_ARROW_UP = String.fromCharCode(11014);
100
+ var CHAR_ARROW_DOWN = String.fromCharCode(11015);
101
+ var { KEY } = metadataKeys;
102
+ var classBase = "vuuBackgroundCell";
103
+ var FlashStyle = {
104
+ ArrowOnly: "arrow",
105
+ BackgroundOnly: "bg-only",
106
+ ArrowBackground: "arrow-bg"
107
+ };
108
+ var getFlashStyle = (colType) => {
109
+ if (isTypeDescriptor2(colType) && colType.renderer) {
110
+ if ("flashStyle" in colType.renderer) {
111
+ return colType.renderer["flashStyle"];
112
+ }
113
+ }
114
+ return FlashStyle.BackgroundOnly;
115
+ };
116
+ var BackgroundCell = memo(
117
+ function BackgroundCell2({
118
+ column,
119
+ columnMap,
120
+ row
121
+ }) {
122
+ const { name: name2, type, valueFormatter } = column;
123
+ const dataIdx = columnMap[name2];
124
+ const value = row[dataIdx];
125
+ const flashStyle = getFlashStyle(type);
126
+ const direction = useDirection(row[KEY], value, column);
127
+ const arrow = flashStyle === FlashStyle.ArrowOnly || flashStyle === FlashStyle.ArrowBackground ? direction === UP1 || direction === UP2 ? CHAR_ARROW_UP : direction === DOWN1 || direction === DOWN2 ? CHAR_ARROW_DOWN : null : null;
128
+ const dirClass = direction ? ` ` + direction : "";
129
+ const className = cx(classBase, dirClass, {
130
+ [`${classBase}-backgroundOnly`]: flashStyle === FlashStyle.BackgroundOnly,
131
+ [`${classBase}-arrowOnly`]: flashStyle === FlashStyle.ArrowOnly,
132
+ [`${classBase}-arrowBackground`]: flashStyle === FlashStyle.ArrowBackground
133
+ });
134
+ return /* @__PURE__ */ jsxs("div", { className, tabIndex: -1, children: [
135
+ /* @__PURE__ */ jsx("div", { className: `${classBase}-arrow`, children: arrow }),
136
+ valueFormatter(row[dataIdx])
137
+ ] });
138
+ },
139
+ dataAndColumnUnchanged
140
+ );
141
+ registerComponent3(
142
+ "vuu.price-move-background",
143
+ BackgroundCell,
144
+ "cell-renderer",
145
+ {
146
+ description: "Change background color of cell when value changes",
147
+ configEditor: "BackgroundCellConfigurationEditor",
148
+ label: "Background Flash",
149
+ serverDataType: ["long", "int", "double"]
150
+ }
151
+ );
152
+
153
+ // src/cell-renderers/background-cell/BackgroundCellConfigurationEditor.tsx
154
+ import { Dropdown } from "@vuu-ui/vuu-ui-controls";
155
+ import {
156
+ registerConfigurationEditor
157
+ } from "@vuu-ui/vuu-utils";
158
+ import { FormField, FormFieldLabel } from "@salt-ds/core";
159
+ import { useCallback, useState } from "react";
160
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
161
+ var classBase2 = "vuuBackgroundCellConfiguration";
162
+ var flashOptions = [
163
+ { label: "Background Only", value: "bg-only" },
164
+ { label: "Background and Arrow", value: "arrow-bg" },
165
+ { label: "Arrow Only", value: "arrow" }
166
+ ];
167
+ var [defaultFlashOption] = flashOptions;
168
+ var valueFromColumn = (column) => {
169
+ const { flashStyle } = column.type.renderer;
170
+ return flashOptions.find((o) => o.value === flashStyle) || defaultFlashOption;
171
+ };
172
+ var BackgroundCellConfigurationEditor = ({
173
+ column,
174
+ onChangeRendering
175
+ }) => {
176
+ const [flashStyle, setFlashStyle] = useState(
177
+ valueFromColumn(column)
178
+ );
179
+ const handleSelectionChange = useCallback(
180
+ (_, flashOption) => {
181
+ var _a;
182
+ setFlashStyle(flashOption);
183
+ const renderProps = column.type.renderer;
184
+ onChangeRendering({
185
+ ...renderProps,
186
+ flashStyle: (_a = flashOption == null ? void 0 : flashOption.value) != null ? _a : defaultFlashOption.value
187
+ });
188
+ },
189
+ [column.type, onChangeRendering]
190
+ );
191
+ return /* @__PURE__ */ jsxs2(FormField, { children: [
192
+ /* @__PURE__ */ jsx2(FormFieldLabel, { children: "Flash Style" }),
193
+ /* @__PURE__ */ jsx2(
194
+ Dropdown,
195
+ {
196
+ className: `${classBase2}-flashStyle`,
197
+ onSelectionChange: handleSelectionChange,
198
+ selected: flashStyle,
199
+ source: flashOptions,
200
+ width: "100%"
201
+ }
202
+ )
203
+ ] });
204
+ };
205
+ registerConfigurationEditor(
206
+ "BackgroundCellConfigurationEditor",
207
+ BackgroundCellConfigurationEditor
208
+ );
209
+
210
+ // src/cell-renderers/dropdown-cell/DropdownCell.tsx
211
+ import { getSelectedOption, useLookupValues } from "@vuu-ui/vuu-data-react";
212
+ import {
213
+ Dropdown as Dropdown2,
214
+ WarnCommit
215
+ } from "@vuu-ui/vuu-ui-controls";
216
+ import {
217
+ dataColumnAndKeyUnchanged,
218
+ dispatchCustomEvent,
219
+ registerComponent as registerComponent4
220
+ } from "@vuu-ui/vuu-utils";
221
+ import { memo as memo2, useCallback as useCallback2, useMemo, useRef as useRef2 } from "react";
222
+ import { jsx as jsx3 } from "react/jsx-runtime";
223
+ var classBase3 = "vuuTableDropdownCell";
224
+ var openKeys = ["Enter", " "];
225
+ var DropdownCell = memo2(
226
+ function DropdownCell2({
227
+ column,
228
+ columnMap,
229
+ onCommit = WarnCommit,
230
+ row
231
+ }) {
232
+ const dataIdx = columnMap[column.name];
233
+ const dataValue = row[dataIdx];
234
+ const { values } = useLookupValues(column, dataValue);
235
+ const valueRef = useRef2(null);
236
+ useMemo(() => {
237
+ valueRef.current = getSelectedOption(values, dataValue);
238
+ }, [dataValue, values]);
239
+ const handleSelectionChange = useCallback2(
240
+ (evt, selectedOption) => {
241
+ if (selectedOption) {
242
+ onCommit(selectedOption.value).then((response) => {
243
+ if (response === true && evt) {
244
+ dispatchCustomEvent(evt.target, "vuu-commit");
245
+ }
246
+ });
247
+ }
248
+ },
249
+ [onCommit]
250
+ );
251
+ return /* @__PURE__ */ jsx3(
252
+ Dropdown2,
253
+ {
254
+ className: classBase3,
255
+ onSelectionChange: handleSelectionChange,
256
+ openKeys,
257
+ selected: valueRef.current,
258
+ source: values,
259
+ width: column.width - 17
260
+ }
261
+ );
262
+ },
263
+ dataColumnAndKeyUnchanged
264
+ );
265
+ registerComponent4("dropdown-cell", DropdownCell, "cell-renderer", {
266
+ userCanAssign: false
267
+ });
268
+
269
+ // src/cell-renderers/lookup-cell/LookupCell.tsx
270
+ import { useLookupValues as useLookupValues2 } from "@vuu-ui/vuu-data-react";
271
+ import { dataAndColumnUnchanged as dataAndColumnUnchanged2, registerComponent as registerComponent5 } from "@vuu-ui/vuu-utils";
272
+ import { memo as memo3 } from "react";
273
+ import { jsx as jsx4 } from "react/jsx-runtime";
274
+ var LookupCell = memo3(
275
+ function LookupCell2({
276
+ column,
277
+ columnMap,
278
+ row
279
+ }) {
280
+ const dataIdx = columnMap[column.name];
281
+ const dataValue = row[dataIdx];
282
+ const { initialValue: value } = useLookupValues2(column, dataValue);
283
+ return /* @__PURE__ */ jsx4("span", { children: value == null ? void 0 : value.label });
284
+ },
285
+ dataAndColumnUnchanged2
286
+ );
287
+ registerComponent5("lookup-cell", LookupCell, "cell-renderer", {
288
+ userCanAssign: false
289
+ });
290
+
291
+ // src/cell-renderers/pct-progress-cell/PctProgressCell.tsx
292
+ import { registerComponent as registerComponent6 } from "@vuu-ui/vuu-utils";
293
+ import cx2 from "clsx";
294
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
295
+ var classBase4 = "vuuPctProgressCell";
296
+ var getPercentageValue = (value) => {
297
+ if (value >= 0 && value <= 1) {
298
+ return value * 100;
299
+ } else if (value > 2) {
300
+ return 0;
301
+ } else if (value > 1) {
302
+ return 100;
303
+ } else {
304
+ return 0;
305
+ }
306
+ };
307
+ var PctProgressCell = ({ column, columnMap, row }) => {
308
+ const value = row[columnMap[column.name]];
309
+ const percentageValue = getPercentageValue(value);
310
+ const className = cx2(classBase4, {});
311
+ return /* @__PURE__ */ jsxs3(
312
+ "div",
313
+ {
314
+ className: cx2(className, {
315
+ [`${classBase4}-zero`]: percentageValue === 0,
316
+ [`${classBase4}-complete`]: percentageValue >= 100
317
+ }),
318
+ tabIndex: -1,
319
+ children: [
320
+ /* @__PURE__ */ jsx5(
321
+ "span",
322
+ {
323
+ className: `${classBase4}-progressBar`,
324
+ style: { "--progress-bar-pct": `${percentageValue}%` }
325
+ }
326
+ ),
327
+ /* @__PURE__ */ jsx5("span", { className: `${classBase4}-text`, children: `${percentageValue.toFixed(
328
+ 2
329
+ )} %` })
330
+ ]
331
+ }
332
+ );
333
+ };
334
+ registerComponent6("vuu.pct-progress", PctProgressCell, "cell-renderer", {
335
+ description: "Percentage formatter",
336
+ label: "Percentage formatter",
337
+ serverDataType: "double"
338
+ });
339
+
340
+ // src/cell-renderers/progress-cell/ProgressCell.tsx
341
+ import {
342
+ isColumnTypeRenderer,
343
+ isTypeDescriptor as isTypeDescriptor3,
344
+ isValidNumber as isValidNumber2,
345
+ registerComponent as registerComponent7
346
+ } from "@vuu-ui/vuu-utils";
347
+ import cx3 from "clsx";
348
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
349
+ var classBase5 = "vuuProgressCell";
350
+ var ProgressCell = ({ column, columnMap, row }) => {
351
+ const { name: name2, type } = column;
352
+ const value = row[columnMap[name2]];
353
+ let showProgress = false;
354
+ let percentage = 0;
355
+ if (isTypeDescriptor3(type) && isColumnTypeRenderer(type.renderer)) {
356
+ const { associatedField } = type.renderer;
357
+ if (associatedField) {
358
+ const associatedValue = row[columnMap[associatedField]];
359
+ if (isValidNumber2(value) && isValidNumber2(associatedValue)) {
360
+ percentage = Math.min(Math.round(value / associatedValue * 100), 100);
361
+ percentage = Math.min(Math.round(value / associatedValue * 100), 100);
362
+ showProgress = isFinite(percentage);
363
+ } else {
364
+ const floatValue = parseFloat(value);
365
+ if (Number.isFinite(floatValue)) {
366
+ const floatOtherValue = parseFloat(associatedValue);
367
+ if (Number.isFinite(floatOtherValue)) {
368
+ percentage = Math.min(
369
+ Math.round(floatValue / floatOtherValue * 100),
370
+ 100
371
+ );
372
+ showProgress = isFinite(percentage);
373
+ }
374
+ }
375
+ }
376
+ } else {
377
+ throw Error("ProgressCell associatedField is required to render");
378
+ }
379
+ }
380
+ const className = cx3(classBase5, {});
381
+ return /* @__PURE__ */ jsxs4("div", { className, tabIndex: -1, children: [
382
+ showProgress ? /* @__PURE__ */ jsxs4("span", { className: `${classBase5}-track`, children: [
383
+ /* @__PURE__ */ jsx6("span", { className: `${classBase5}-bg` }),
384
+ /* @__PURE__ */ jsx6(
385
+ "span",
386
+ {
387
+ className: `${classBase5}-bar`,
388
+ style: { "--progress-bar-pct": `-${100 - percentage}%` }
389
+ }
390
+ )
391
+ ] }) : null,
392
+ /* @__PURE__ */ jsx6("span", { className: `${classBase5}-text`, children: `${percentage} %` })
393
+ ] });
394
+ };
395
+ registerComponent7("vuu.progress", ProgressCell, "cell-renderer", {
396
+ description: "Progress formatter",
397
+ label: "Progress formatter",
398
+ serverDataType: ["long", "int", "double"],
399
+ // Not until we provide settings for associaetd field
400
+ userCanAssign: false
401
+ });
402
+
403
+ // src/column-list/ColumnList.tsx
404
+ import {
405
+ List,
406
+ ListItem
407
+ } from "@vuu-ui/vuu-ui-controls";
408
+ import { Checkbox, Switch } from "@salt-ds/core";
409
+ import cx4 from "clsx";
410
+ import {
411
+ useCallback as useCallback3
412
+ } from "react";
413
+ import { getColumnLabel } from "@vuu-ui/vuu-utils";
414
+ import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
415
+ var classBase6 = "vuuColumnList";
416
+ var classBaseListItem = "vuuColumnListItem";
417
+ var ColumnListItem = ({
418
+ className: classNameProp,
419
+ item,
420
+ ...listItemProps
421
+ }) => {
422
+ return /* @__PURE__ */ jsxs5(
423
+ ListItem,
424
+ {
425
+ ...listItemProps,
426
+ className: cx4(classNameProp, classBaseListItem),
427
+ "data-name": item == null ? void 0 : item.name,
428
+ children: [
429
+ /* @__PURE__ */ jsx7("span", { className: `${classBase6}-icon`, "data-icon": "draggable" }),
430
+ (item == null ? void 0 : item.isCalculated) ? /* @__PURE__ */ jsx7("span", { className: `${classBase6}-icon`, "data-icon": "function" }) : /* @__PURE__ */ jsx7(Switch, { className: `${classBase6}-switch`, checked: item == null ? void 0 : item.subscribed }),
431
+ /* @__PURE__ */ jsx7("span", { className: `${classBase6}-text`, children: getColumnLabel(item) }),
432
+ /* @__PURE__ */ jsx7(
433
+ Checkbox,
434
+ {
435
+ className: `${classBase6}-checkBox`,
436
+ checked: (item == null ? void 0 : item.hidden) !== true,
437
+ disabled: (item == null ? void 0 : item.subscribed) !== true
438
+ }
439
+ )
440
+ ]
441
+ }
442
+ );
443
+ };
444
+ var ColumnList = ({
445
+ columnItems,
446
+ onChange,
447
+ onMoveListItem,
448
+ onNavigateToColumn,
449
+ ...htmlAttributes
450
+ }) => {
451
+ const handleChange = useCallback3(
452
+ (evt) => {
453
+ const input = evt.target;
454
+ const listItem = input.closest(`.${classBaseListItem}`);
455
+ const {
456
+ dataset: { name: name2 }
457
+ } = listItem;
458
+ if (name2) {
459
+ const saltSwitch = input.closest(`.${classBase6}-switch`);
460
+ const saltCheckbox = input.closest(
461
+ `.${classBase6}-checkBox`
462
+ );
463
+ if (saltSwitch) {
464
+ onChange(name2, "subscribed", input.checked);
465
+ } else if (saltCheckbox) {
466
+ onChange(name2, "hidden", input.checked === false);
467
+ }
468
+ }
469
+ },
470
+ [onChange]
471
+ );
472
+ const handleClick = useCallback3((evt) => {
473
+ const targetEl = evt.target;
474
+ if (targetEl.classList.contains("vuuColumnList-text")) {
475
+ const listItemEl = targetEl.closest(".vuuListItem");
476
+ if (listItemEl == null ? void 0 : listItemEl.dataset.name) {
477
+ onNavigateToColumn == null ? void 0 : onNavigateToColumn(listItemEl.dataset.name);
478
+ }
479
+ }
480
+ }, []);
481
+ return /* @__PURE__ */ jsxs5("div", { ...htmlAttributes, className: classBase6, children: [
482
+ /* @__PURE__ */ jsx7("div", { className: `${classBase6}-header`, children: /* @__PURE__ */ jsx7("span", { children: "Column Selection" }) }),
483
+ /* @__PURE__ */ jsxs5("div", { className: `${classBase6}-colHeadings`, children: [
484
+ /* @__PURE__ */ jsx7("span", { children: "Column subscription" }),
485
+ /* @__PURE__ */ jsx7("span", { children: "Visibility" })
486
+ ] }),
487
+ /* @__PURE__ */ jsx7(
488
+ List,
489
+ {
490
+ ListItem: ColumnListItem,
491
+ allowDragDrop: true,
492
+ height: "auto",
493
+ onChange: handleChange,
494
+ onClick: handleClick,
495
+ onMoveListItem,
496
+ selectionStrategy: "none",
497
+ source: columnItems,
498
+ itemHeight: 33
499
+ }
500
+ )
501
+ ] });
502
+ };
503
+
504
+ // src/column-settings/ColumnSettingsPanel.tsx
505
+ import { Icon, VuuInput } from "@vuu-ui/vuu-ui-controls";
506
+ import {
507
+ getCalculatedColumnName as getCalculatedColumnName2,
508
+ getDefaultAlignment,
509
+ isCalculatedColumn as isCalculatedColumn2
510
+ } from "@vuu-ui/vuu-utils";
511
+ import {
512
+ Button,
513
+ FormField as FormField7,
514
+ FormFieldLabel as FormFieldLabel7,
515
+ ToggleButton as ToggleButton3,
516
+ ToggleButtonGroup as ToggleButtonGroup3
517
+ } from "@salt-ds/core";
518
+ import cx7 from "clsx";
519
+
520
+ // src/column-expression-panel/ColumnExpressionPanel.tsx
521
+ import { Dropdown as Dropdown3 } from "@vuu-ui/vuu-ui-controls";
522
+ import {
523
+ getCalculatedColumnExpression,
524
+ getCalculatedColumnName,
525
+ getCalculatedColumnType
526
+ } from "@vuu-ui/vuu-utils";
527
+ import { FormField as FormField2, FormFieldLabel as FormFieldLabel2, Input } from "@salt-ds/core";
528
+ import { useCallback as useCallback8, useRef as useRef6 } from "react";
529
+
530
+ // src/column-expression-input/ColumnExpressionInput.tsx
531
+ import { memo as memo4 } from "react";
532
+
533
+ // src/column-expression-input/useColumnExpressionEditor.ts
534
+ import {
535
+ autocompletion,
536
+ defaultKeymap,
537
+ EditorState as EditorState2,
538
+ EditorView as EditorView2,
539
+ ensureSyntaxTree,
540
+ keymap,
541
+ minimalSetup,
542
+ startCompletion
543
+ } from "@vuu-ui/vuu-codemirror";
544
+ import { createEl } from "@vuu-ui/vuu-utils";
545
+ import {
546
+ useCallback as useCallback5,
547
+ useEffect as useEffect2,
548
+ useMemo as useMemo2,
549
+ useRef as useRef3
550
+ } from "react";
551
+
552
+ // src/column-expression-input/column-language-parser/ColumnExpressionLanguage.ts
553
+ import {
554
+ LanguageSupport,
555
+ LRLanguage,
556
+ styleTags,
557
+ tags as tag
558
+ } from "@vuu-ui/vuu-codemirror";
559
+
560
+ // src/column-expression-input/column-language-parser/generated/column-parser.js
561
+ import { LRParser } from "@lezer/lr";
562
+ var parser = LRParser.deserialize({
563
+ version: 14,
564
+ states: "&xOVQPOOO!fQPO'#C^OVQPO'#CcQ!pQPOOO#bQPO'#CkO#gQPO'#CrOOQO'#Cy'#CyO#lQPO,58}OVQPO,59QOVQPO,59QOOQO'#Cn'#CnOVQPO,59XOVQPO,59VOVQPO'#CtOOQO,59^,59^OOQO1G.i1G.iOOQO1G.l1G.lO$bQPO1G.lO%ZQPO1G.sO!pQPO'#CmO%qQQO1G.qO%|QQO'#C{OOQO'#C{'#C{O&wQPO,59`OVQPO,59ZOVQPO,59[OVQPO7+$]OVQPO'#CuO'RQPO1G.zOOQO1G.z1G.zO'ZQQO'#C^O'eQQO1G.sO'{QQO1G.uOOQO1G.v1G.vO(WQPO<<GwO(_QPO,59aOOQO-E6s-E6sOOQO7+$f7+$fOVQPOAN=cO(iQQO1G.lO(yQPOG22}OOQOLD(iLD(iO)QQPO,59QO)QQPO,59QO)QQPO,59X",
565
+ stateData: ")n~OlOS~ORUOSUOTUOUUOWQO`SOnPO~OWgXZQX[QX]QX^QXpQXqQXrQXsQXtQXuQXeQX~OjQXXQX~PnOZWO[WO]XO^XOpYOqYOrYOsYOtYOuYO~OW[O~OW]O~OX_O~P!pO]Yi^YipYiqYirYisYitYiuYieYi~OZWO[WOjYiXYi~P#sOpaiqairaisaitaiuaieai~OZWO[WO]XO^XOjaiXai~P$rOejOvhOwiO~OZmX[mX]mX^mXeoXpmXqmXrmXsmXtmXumXvoXwoX~OXmOekO~P!pOXuOekO~OvQXwQX~PnOZzO[zO]{O^{Ovaiwai~P$rOwiOecivci~OevO~P!pOXiaeia~P!pOZzO[zOvYiwYi~P#sOXyO~P!pORUOSUOTUOUUOWQO`SOnnO~O`UTn~",
566
+ goto: "$epPPqPPPPqPPqPPPPqP!S!g!r!rPq!w#Y#]PPP#cP$[oUOQWXZ[]hijkvz{|hUOQWXZ]jkvz{|Ve[hi[ZRVgrsxR|cVf[hioTOQWXZ[]hijkvz{|R^TQlgRtlQROQVQS`WzQaXQbZUc[hiQg]Qo|QrjQskQw{RxvQd[QphRqi",
567
+ 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",
568
+ maxTerm: 39,
569
+ skippedNodes: [0],
570
+ repeatNodeCount: 1,
571
+ 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",
572
+ tokenizers: [0, 1],
573
+ topRules: { "ColumnDefinitionExpression": [0, 1] },
574
+ tokenPrec: 393
575
+ });
576
+
577
+ // src/column-expression-input/column-language-parser/ColumnExpressionLanguage.ts
578
+ var columnExpressionLanguage = LRLanguage.define({
579
+ name: "VuuColumnExpression",
580
+ parser: parser.configure({
581
+ props: [
582
+ styleTags({
583
+ Column: tag.attributeValue,
584
+ Function: tag.variableName,
585
+ String: tag.string,
586
+ Or: tag.emphasis,
587
+ Operator: tag.operator
588
+ })
589
+ ]
590
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
591
+ })
592
+ });
593
+ var columnExpressionLanguageSupport = () => {
594
+ return new LanguageSupport(
595
+ columnExpressionLanguage
596
+ /*, [exampleCompletion]*/
597
+ );
598
+ };
599
+
600
+ // src/column-expression-input/column-language-parser/ColumnExpressionTreeWalker.ts
601
+ var LiteralExpressionImpl = class {
602
+ constructor(value) {
603
+ this.value = value;
604
+ switch (typeof value) {
605
+ case "boolean":
606
+ this.type = "booleanLiteralExpression";
607
+ break;
608
+ case "number":
609
+ this.type = "numericLiteralExpression";
610
+ break;
611
+ default:
612
+ this.type = "stringLiteralExpression";
613
+ }
614
+ }
615
+ toJSON() {
616
+ return {
617
+ type: this.type,
618
+ value: this.value
619
+ };
620
+ }
621
+ };
622
+ var ColumnExpressionImpl = class {
623
+ constructor(columnName) {
624
+ this.type = "colExpression";
625
+ this.column = columnName;
626
+ }
627
+ toJSON() {
628
+ return {
629
+ type: this.type,
630
+ column: this.column
631
+ };
632
+ }
633
+ };
634
+ var _expressions, _op;
635
+ var ArithmeticExpressionImpl = class {
636
+ constructor(op = "unknown") {
637
+ __privateAdd(this, _expressions, [
638
+ { type: "unknown" },
639
+ { type: "unknown" }
640
+ ]);
641
+ __privateAdd(this, _op, void 0);
642
+ this.type = "arithmeticExpression";
643
+ __privateSet(this, _op, op);
644
+ }
645
+ get op() {
646
+ return __privateGet(this, _op);
647
+ }
648
+ set op(op) {
649
+ __privateSet(this, _op, op);
650
+ }
651
+ get expressions() {
652
+ return __privateGet(this, _expressions);
653
+ }
654
+ toJSON() {
655
+ return {
656
+ type: this.type,
657
+ op: __privateGet(this, _op),
658
+ expressions: __privateGet(this, _expressions)
659
+ };
660
+ }
661
+ };
662
+ _expressions = new WeakMap();
663
+ _op = new WeakMap();
664
+ var _expressions2;
665
+ var CallExpressionImpl = class {
666
+ constructor(functionName) {
667
+ __privateAdd(this, _expressions2, []);
668
+ this.type = "callExpression";
669
+ this.functionName = functionName;
670
+ }
671
+ get expressions() {
672
+ return __privateGet(this, _expressions2);
673
+ }
674
+ get arguments() {
675
+ return __privateGet(this, _expressions2);
676
+ }
677
+ toJSON() {
678
+ return {
679
+ type: this.type,
680
+ functionName: this.functionName,
681
+ arguments: __privateGet(this, _expressions2).map((e) => {
682
+ var _a;
683
+ return (_a = e.toJSON) == null ? void 0 : _a.call(e);
684
+ })
685
+ };
686
+ }
687
+ };
688
+ _expressions2 = new WeakMap();
689
+ var _expressions3, _op2;
690
+ var RelationalExpressionImpl = class {
691
+ constructor() {
692
+ __privateAdd(this, _expressions3, [
693
+ { type: "unknown" },
694
+ { type: "unknown" }
695
+ ]);
696
+ __privateAdd(this, _op2, "unknown");
697
+ this.type = "relationalExpression";
698
+ }
699
+ get op() {
700
+ return __privateGet(this, _op2);
701
+ }
702
+ set op(op) {
703
+ __privateSet(this, _op2, op);
704
+ }
705
+ get expressions() {
706
+ return __privateGet(this, _expressions3);
707
+ }
708
+ toJSON() {
709
+ return {
710
+ type: this.type,
711
+ op: __privateGet(this, _op2),
712
+ expressions: __privateGet(this, _expressions3)
713
+ };
714
+ }
715
+ };
716
+ _expressions3 = new WeakMap();
717
+ _op2 = new WeakMap();
718
+ var _expressions4, _op3;
719
+ var BooleanConditionImp = class {
720
+ constructor(booleanOperator) {
721
+ __privateAdd(this, _expressions4, [
722
+ { type: "unknown" },
723
+ { type: "unknown" }
724
+ ]);
725
+ __privateAdd(this, _op3, void 0);
726
+ this.type = "booleanCondition";
727
+ __privateSet(this, _op3, booleanOperator);
728
+ }
729
+ get op() {
730
+ return __privateGet(this, _op3);
731
+ }
732
+ get expressions() {
733
+ return __privateGet(this, _expressions4);
734
+ }
735
+ toJSON() {
736
+ return {
737
+ type: this.type,
738
+ op: __privateGet(this, _op3),
739
+ expressions: __privateGet(this, _expressions4).map((e) => {
740
+ var _a;
741
+ return (_a = e.toJSON) == null ? void 0 : _a.call(e);
742
+ })
743
+ };
744
+ }
745
+ };
746
+ _expressions4 = new WeakMap();
747
+ _op3 = new WeakMap();
748
+ var _expressions5;
749
+ var ConditionalExpressionImpl = class {
750
+ constructor(booleanOperator) {
751
+ __privateAdd(this, _expressions5, void 0);
752
+ this.type = "conditionalExpression";
753
+ __privateSet(this, _expressions5, [
754
+ booleanOperator ? new BooleanConditionImp(booleanOperator) : new RelationalExpressionImpl(),
755
+ { type: "unknown" },
756
+ { type: "unknown" }
757
+ ]);
758
+ }
759
+ get expressions() {
760
+ return __privateGet(this, _expressions5);
761
+ }
762
+ get condition() {
763
+ return __privateGet(this, _expressions5)[0];
764
+ }
765
+ get truthyExpression() {
766
+ return __privateGet(this, _expressions5)[1];
767
+ }
768
+ set truthyExpression(expression) {
769
+ __privateGet(this, _expressions5)[1] = expression;
770
+ }
771
+ get falsyExpression() {
772
+ return __privateGet(this, _expressions5)[2];
773
+ }
774
+ set falsyExpression(expression) {
775
+ __privateGet(this, _expressions5)[2] = expression;
776
+ }
777
+ toJSON() {
778
+ var _a, _b, _c, _d, _e;
779
+ return {
780
+ type: this.type,
781
+ condition: (_b = (_a = this.condition).toJSON) == null ? void 0 : _b.call(_a),
782
+ truthyExpression: this.truthyExpression,
783
+ falsyExpression: (_e = (_d = (_c = this.falsyExpression) == null ? void 0 : _c.toJSON) == null ? void 0 : _d.call(_c)) != null ? _e : this.falsyExpression
784
+ };
785
+ }
786
+ };
787
+ _expressions5 = new WeakMap();
788
+ var isUnknown = (e) => e.type === "unknown";
789
+ var isArithmeticExpression = (expression) => expression.type === "arithmeticExpression";
790
+ var isCallExpression = (expression) => expression.type === "callExpression";
791
+ var isConditionalExpression = (expression) => expression.type === "conditionalExpression";
792
+ var isCondition = (expression) => expression.type === "relationalExpression" || expression.type === "booleanCondition";
793
+ var isBooleanCondition = (expression) => expression.type === "booleanCondition";
794
+ var isRelationalExpression = (expression) => (expression == null ? void 0 : expression.type) === "relationalExpression";
795
+ var firstIncompleteExpression = (expression) => {
796
+ if (isUnknown(expression)) {
797
+ return expression;
798
+ } else if (isRelationalExpression(expression)) {
799
+ const [operand1, operand2] = expression.expressions;
800
+ if (expressionIsIncomplete(operand1)) {
801
+ return firstIncompleteExpression(operand1);
802
+ } else if (expression.op === "unknown") {
803
+ return expression;
804
+ } else if (expressionIsIncomplete(operand2)) {
805
+ return firstIncompleteExpression(operand2);
806
+ }
807
+ } else if (isCondition(expression)) {
808
+ const { expressions = [] } = expression;
809
+ for (const e of expressions) {
810
+ if (expressionIsIncomplete(e)) {
811
+ return firstIncompleteExpression(e);
812
+ }
813
+ }
814
+ } else if (isConditionalExpression(expression)) {
815
+ const { condition, truthyExpression, falsyExpression } = expression;
816
+ if (expressionIsIncomplete(condition)) {
817
+ return firstIncompleteExpression(condition);
818
+ } else if (expressionIsIncomplete(truthyExpression)) {
819
+ return firstIncompleteExpression(truthyExpression);
820
+ } else if (expressionIsIncomplete(falsyExpression)) {
821
+ return firstIncompleteExpression(falsyExpression);
822
+ }
823
+ } else if (isArithmeticExpression(expression)) {
824
+ const { expressions = [] } = expression;
825
+ for (const e of expressions) {
826
+ if (expressionIsIncomplete(e)) {
827
+ return firstIncompleteExpression(e);
828
+ }
829
+ }
830
+ }
831
+ };
832
+ var replaceUnknownExpression = (incompleteExpression, unknownExpression, expression) => {
833
+ const { expressions = [] } = incompleteExpression;
834
+ if (expressions.includes(unknownExpression)) {
835
+ const pos = expressions.indexOf(unknownExpression);
836
+ expressions.splice(pos, 1, expression);
837
+ return true;
838
+ } else {
839
+ for (const e of expressions) {
840
+ if (replaceUnknownExpression(e, unknownExpression, expression)) {
841
+ return true;
842
+ }
843
+ }
844
+ }
845
+ return false;
846
+ };
847
+ var expressionIsIncomplete = (expression) => {
848
+ if (isUnknown(expression)) {
849
+ return true;
850
+ } else if (isConditionalExpression(expression)) {
851
+ return expressionIsIncomplete(expression.condition) || expressionIsIncomplete(expression.truthyExpression) || expressionIsIncomplete(expression.falsyExpression);
852
+ } else if (isRelationalExpression(expression) || isBooleanCondition(expression)) {
853
+ return expression.op === void 0 || expression.expressions.some((e) => expressionIsIncomplete(e));
854
+ }
855
+ return false;
856
+ };
857
+ var addExpression = (expression, subExpression) => {
858
+ const targetExpression = firstIncompleteExpression(expression);
859
+ if (targetExpression) {
860
+ if (targetExpression.expressions) {
861
+ targetExpression.expressions.push(subExpression);
862
+ } else {
863
+ console.warn("don't know how to treat targetExpression");
864
+ }
865
+ } else {
866
+ console.error("no target expression found");
867
+ }
868
+ };
869
+ var _expression, _callStack;
870
+ var ColumnExpression = class {
871
+ constructor() {
872
+ __privateAdd(this, _expression, void 0);
873
+ __privateAdd(this, _callStack, []);
874
+ }
875
+ setCondition(booleanOperator) {
876
+ if (__privateGet(this, _expression) === void 0) {
877
+ this.addExpression(new ConditionalExpressionImpl(booleanOperator));
878
+ } else if (isConditionalExpression(__privateGet(this, _expression))) {
879
+ if (expressionIsIncomplete(__privateGet(this, _expression).condition)) {
880
+ const condition = booleanOperator ? new BooleanConditionImp(booleanOperator) : new RelationalExpressionImpl();
881
+ this.addExpression(condition);
882
+ } else if (isUnknown(__privateGet(this, _expression).truthyExpression)) {
883
+ __privateGet(this, _expression).truthyExpression = new ConditionalExpressionImpl(
884
+ booleanOperator
885
+ );
886
+ } else if (expressionIsIncomplete(__privateGet(this, _expression).truthyExpression)) {
887
+ const condition = booleanOperator ? new BooleanConditionImp(booleanOperator) : new RelationalExpressionImpl();
888
+ this.addExpression(condition);
889
+ } else if (isUnknown(__privateGet(this, _expression).falsyExpression)) {
890
+ __privateGet(this, _expression).falsyExpression = new ConditionalExpressionImpl(
891
+ booleanOperator
892
+ );
893
+ } else if (expressionIsIncomplete(__privateGet(this, _expression).falsyExpression)) {
894
+ const condition = booleanOperator ? new BooleanConditionImp(booleanOperator) : new RelationalExpressionImpl();
895
+ this.addExpression(condition);
896
+ }
897
+ } else {
898
+ console.error("setCondition called unexpectedly");
899
+ }
900
+ }
901
+ addExpression(expression) {
902
+ if (__privateGet(this, _callStack).length > 0) {
903
+ const currentCallExpression = __privateGet(this, _callStack).at(-1);
904
+ currentCallExpression == null ? void 0 : currentCallExpression.arguments.push(expression);
905
+ } else if (__privateGet(this, _expression) === void 0) {
906
+ __privateSet(this, _expression, expression);
907
+ } else if (isArithmeticExpression(__privateGet(this, _expression))) {
908
+ const targetExpression = firstIncompleteExpression(__privateGet(this, _expression));
909
+ if (targetExpression && isUnknown(targetExpression)) {
910
+ replaceUnknownExpression(
911
+ __privateGet(this, _expression),
912
+ targetExpression,
913
+ expression
914
+ );
915
+ }
916
+ } else if (isConditionalExpression(__privateGet(this, _expression))) {
917
+ if (expressionIsIncomplete(__privateGet(this, _expression))) {
918
+ const targetExpression = firstIncompleteExpression(__privateGet(this, _expression));
919
+ if (targetExpression && isUnknown(targetExpression)) {
920
+ replaceUnknownExpression(
921
+ __privateGet(this, _expression),
922
+ targetExpression,
923
+ expression
924
+ );
925
+ } else if (targetExpression) {
926
+ addExpression(targetExpression, expression);
927
+ }
928
+ }
929
+ }
930
+ }
931
+ setFunction(functionName) {
932
+ const callExpression = new CallExpressionImpl(functionName);
933
+ this.addExpression(callExpression);
934
+ __privateGet(this, _callStack).push(callExpression);
935
+ }
936
+ setColumn(columnName) {
937
+ this.addExpression(new ColumnExpressionImpl(columnName));
938
+ }
939
+ setArithmeticOp(value) {
940
+ const op = value;
941
+ const expression = __privateGet(this, _expression);
942
+ if (isArithmeticExpression(expression)) {
943
+ expression.op = op;
944
+ }
945
+ }
946
+ setRelationalOperator(value) {
947
+ const op = value;
948
+ if (__privateGet(this, _expression) && isConditionalExpression(__privateGet(this, _expression))) {
949
+ const targetExpression = firstIncompleteExpression(__privateGet(this, _expression));
950
+ if (isRelationalExpression(targetExpression)) {
951
+ targetExpression.op = op;
952
+ } else {
953
+ console.error(`no target expression found (op = ${value})`);
954
+ }
955
+ }
956
+ }
957
+ setValue(value) {
958
+ const literalExpression = new LiteralExpressionImpl(value);
959
+ if (__privateGet(this, _expression) === void 0) {
960
+ __privateSet(this, _expression, literalExpression);
961
+ } else if (isArithmeticExpression(__privateGet(this, _expression))) {
962
+ this.addExpression(literalExpression);
963
+ } else if (isCallExpression(__privateGet(this, _expression))) {
964
+ __privateGet(this, _expression).arguments.push(literalExpression);
965
+ } else if (isConditionalExpression(__privateGet(this, _expression))) {
966
+ if (expressionIsIncomplete(__privateGet(this, _expression))) {
967
+ const targetExpression = firstIncompleteExpression(__privateGet(this, _expression));
968
+ if (targetExpression && isUnknown(targetExpression)) {
969
+ replaceUnknownExpression(
970
+ __privateGet(this, _expression),
971
+ targetExpression,
972
+ literalExpression
973
+ );
974
+ } else if (targetExpression) {
975
+ addExpression(targetExpression, literalExpression);
976
+ }
977
+ } else {
978
+ console.log("what do we do with value, in a complete expression");
979
+ }
980
+ }
981
+ }
982
+ closeBrace() {
983
+ __privateGet(this, _callStack).pop();
984
+ }
985
+ get expression() {
986
+ return __privateGet(this, _expression);
987
+ }
988
+ toJSON() {
989
+ var _a;
990
+ return (_a = __privateGet(this, _expression)) == null ? void 0 : _a.toJSON();
991
+ }
992
+ };
993
+ _expression = new WeakMap();
994
+ _callStack = new WeakMap();
995
+ var walkTree = (tree, source) => {
996
+ const columnExpression = new ColumnExpression();
997
+ const cursor = tree.cursor();
998
+ do {
999
+ const { name: name2, from, to } = cursor;
1000
+ switch (name2) {
1001
+ case "AndCondition":
1002
+ columnExpression.setCondition("and");
1003
+ break;
1004
+ case "OrCondition":
1005
+ columnExpression.setCondition("or");
1006
+ break;
1007
+ case "RelationalExpression":
1008
+ columnExpression.setCondition();
1009
+ break;
1010
+ case "ArithmeticExpression":
1011
+ columnExpression.addExpression(new ArithmeticExpressionImpl());
1012
+ break;
1013
+ case "Column":
1014
+ {
1015
+ const columnName = source.substring(from, to);
1016
+ columnExpression.setColumn(columnName);
1017
+ }
1018
+ break;
1019
+ case "Function":
1020
+ {
1021
+ const functionName = source.substring(from, to);
1022
+ columnExpression.setFunction(functionName);
1023
+ }
1024
+ break;
1025
+ case "Times":
1026
+ case "Divide":
1027
+ case "Plus":
1028
+ case "Minus":
1029
+ {
1030
+ const op = source.substring(from, to);
1031
+ columnExpression.setArithmeticOp(op);
1032
+ }
1033
+ break;
1034
+ case "RelationalOperator":
1035
+ {
1036
+ const op = source.substring(from, to);
1037
+ columnExpression.setRelationalOperator(op);
1038
+ }
1039
+ break;
1040
+ case "False":
1041
+ case "True":
1042
+ {
1043
+ const value = source.substring(from, to);
1044
+ columnExpression.setValue(value === "true" ? true : false);
1045
+ }
1046
+ break;
1047
+ case "String":
1048
+ columnExpression.setValue(source.substring(from + 1, to - 1));
1049
+ break;
1050
+ case "Number":
1051
+ columnExpression.setValue(parseFloat(source.substring(from, to)));
1052
+ break;
1053
+ case "CloseBrace":
1054
+ columnExpression.closeBrace();
1055
+ break;
1056
+ default:
1057
+ }
1058
+ } while (cursor.next());
1059
+ return columnExpression.toJSON();
1060
+ };
1061
+
1062
+ // src/column-expression-input/column-language-parser/column-expression-parse-utils.ts
1063
+ var strictParser = parser.configure({ strict: true });
1064
+ var RelationalOperands = ["Number", "String"];
1065
+ var ColumnNamedTerms = [
1066
+ ...RelationalOperands,
1067
+ "AndCondition",
1068
+ "ArithmeticExpression",
1069
+ "BooleanOperator",
1070
+ "RelationalOperatorOperator",
1071
+ "CallExpression",
1072
+ "CloseBrace",
1073
+ "Column",
1074
+ "Comma",
1075
+ "ConditionalExpression",
1076
+ "Divide",
1077
+ "Equal",
1078
+ "If",
1079
+ "Minus",
1080
+ "OpenBrace",
1081
+ "OrCondition",
1082
+ "ParenthesizedExpression",
1083
+ "Plus",
1084
+ "RelationalExpression",
1085
+ "RelationalOperator",
1086
+ "Times"
1087
+ ];
1088
+ var isCompleteExpression = (src) => {
1089
+ try {
1090
+ strictParser.parse(src);
1091
+ return true;
1092
+ } catch (err) {
1093
+ return false;
1094
+ }
1095
+ };
1096
+ var lastNamedChild = (node) => {
1097
+ let { lastChild } = node;
1098
+ while (lastChild && !ColumnNamedTerms.includes(lastChild.name)) {
1099
+ lastChild = lastChild.prevSibling;
1100
+ console.log(lastChild == null ? void 0 : lastChild.name);
1101
+ }
1102
+ return lastChild;
1103
+ };
1104
+ var isCompleteRelationalExpression = (node) => {
1105
+ if ((node == null ? void 0 : node.name) === "RelationalExpression") {
1106
+ const { firstChild } = node;
1107
+ const lastChild = lastNamedChild(node);
1108
+ if ((firstChild == null ? void 0 : firstChild.name) === "Column" && typeof (lastChild == null ? void 0 : lastChild.name) === "string" && RelationalOperands.includes(lastChild.name)) {
1109
+ return true;
1110
+ }
1111
+ }
1112
+ return false;
1113
+ };
1114
+
1115
+ // src/column-expression-input/highlighting.ts
1116
+ import {
1117
+ HighlightStyle,
1118
+ syntaxHighlighting,
1119
+ tags
1120
+ } from "@vuu-ui/vuu-codemirror";
1121
+ var myHighlightStyle = HighlightStyle.define([
1122
+ {
1123
+ tag: tags.attributeValue,
1124
+ color: "var(--vuuFilterEditor-variableColor);font-weight: bold"
1125
+ },
1126
+ { tag: tags.variableName, color: "var(--vuuFilterEditor-variableColor)" },
1127
+ { tag: tags.comment, color: "green", fontStyle: "italic" }
1128
+ ]);
1129
+ var vuuHighlighting = syntaxHighlighting(myHighlightStyle);
1130
+
1131
+ // src/column-expression-input/theme.ts
1132
+ import { EditorView } from "@vuu-ui/vuu-codemirror";
1133
+ var vuuTheme = EditorView.theme(
1134
+ {
1135
+ "&": {
1136
+ border: "solid 1px var(--salt-container-primary-borderColor)",
1137
+ color: "var(--vuuFilterEditor-color)",
1138
+ backgroundColor: "var(--vuuFilterEditor-background)"
1139
+ },
1140
+ ".cm-content": {
1141
+ caretColor: "var(--vuuFilterEditor-cursorColor)"
1142
+ },
1143
+ "&.cm-focused .cm-cursor": {
1144
+ borderLeftColor: "var(--vuuFilterEditor-cursorColor)"
1145
+ },
1146
+ "&.cm-focused .cm-selectionBackground, ::selection": {
1147
+ backgroundColor: "var(--vuuFilterEditor-selectionBackground)"
1148
+ },
1149
+ ".cm-selectionBackground, ::selection": {
1150
+ backgroundColor: "var(--vuuFilterEditor-selectionBackground)"
1151
+ },
1152
+ ".cm-scroller": {
1153
+ fontFamily: "var(--vuuFilterEditor-fontFamily)"
1154
+ },
1155
+ ".cm-completionLabel": {
1156
+ color: "var(--vuu-color-gray-50)"
1157
+ },
1158
+ ".cm-completionMatchedText": {
1159
+ color: "var(--vuu-color-gray-80)",
1160
+ fontWeight: 700,
1161
+ textDecoration: "none"
1162
+ },
1163
+ ".cm-tooltip": {
1164
+ background: "var(--vuuFilterEditor-tooltipBackground)",
1165
+ border: "var(--vuuFilterEditor-tooltipBorder)",
1166
+ borderRadius: "4px",
1167
+ boxShadow: "var(--vuuFilterEditor-tooltipElevation)",
1168
+ "&.cm-tooltip-autocomplete > ul": {
1169
+ fontFamily: "var(--vuuFilterEditor-fontFamily)",
1170
+ fontSize: "var(--vuuFilterEditor-fontSize)",
1171
+ maxHeight: "240px"
1172
+ },
1173
+ "&.cm-tooltip-autocomplete > ul > li": {
1174
+ height: "var(--vuuFilterEditor-suggestion-height)",
1175
+ padding: "0 3px",
1176
+ lineHeight: "var(--vuuFilterEditor-suggestion-height)"
1177
+ },
1178
+ "&.cm-tooltip-autocomplete li[aria-selected]": {
1179
+ background: "var(--vuuFilterEditor-suggestion-selectedBackground)",
1180
+ color: "var(--vuuFilterEditor-suggestion-selectedColor)"
1181
+ },
1182
+ "&.cm-tooltip-autocomplete li .cm-completionDetail": {
1183
+ color: "var(--vuuFilterEditor-suggestion-detailColor)"
1184
+ }
1185
+ }
1186
+ },
1187
+ { dark: false }
1188
+ );
1189
+
1190
+ // src/column-expression-input/useColumnAutoComplete.ts
1191
+ import {
1192
+ booleanJoinSuggestions,
1193
+ getNamedParentNode,
1194
+ getPreviousNode,
1195
+ getValue,
1196
+ syntaxTree
1197
+ } from "@vuu-ui/vuu-codemirror";
1198
+ import { useCallback as useCallback4 } from "react";
1199
+ var applyPrefix = (completions, prefix) => prefix ? completions.map((completion) => {
1200
+ var _a;
1201
+ return {
1202
+ ...completion,
1203
+ apply: typeof completion.apply === "function" ? completion.apply : `${prefix}${(_a = completion.apply) != null ? _a : completion.label}`
1204
+ };
1205
+ }) : completions;
1206
+ var isOperator = (node) => node === void 0 ? false : ["Times", "Divide", "Plus", "Minus"].includes(node.name);
1207
+ var completionDone = (onSubmit) => ({
1208
+ apply: () => {
1209
+ onSubmit == null ? void 0 : onSubmit();
1210
+ },
1211
+ label: "Done",
1212
+ boost: 10
1213
+ });
1214
+ var getLastChild = (node, context) => {
1215
+ var _a;
1216
+ let { lastChild: childNode } = node;
1217
+ const { pos } = context;
1218
+ while (childNode) {
1219
+ const isBeforeCursor = childNode.from < pos;
1220
+ if (isBeforeCursor && ColumnNamedTerms.includes(childNode.name)) {
1221
+ if (childNode.name === "ParenthesizedExpression") {
1222
+ const expression = (_a = childNode.firstChild) == null ? void 0 : _a.nextSibling;
1223
+ if (expression) {
1224
+ childNode = expression;
1225
+ }
1226
+ }
1227
+ return childNode;
1228
+ } else {
1229
+ childNode = childNode.prevSibling;
1230
+ }
1231
+ }
1232
+ };
1233
+ var getFunctionName = (node, state) => {
1234
+ var _a;
1235
+ if (node.name === "ArgList") {
1236
+ const functionNode = node.prevSibling;
1237
+ if (functionNode) {
1238
+ return getValue(functionNode, state);
1239
+ }
1240
+ } else if (node.name === "OpenBrace") {
1241
+ const maybeFunction = (_a = node.parent) == null ? void 0 : _a.prevSibling;
1242
+ if ((maybeFunction == null ? void 0 : maybeFunction.name) === "Function") {
1243
+ return getValue(maybeFunction, state);
1244
+ }
1245
+ }
1246
+ };
1247
+ var getRelationalOperator = (node, state) => {
1248
+ if (node.name === "RelationalExpression") {
1249
+ const lastNode = lastNamedChild(node);
1250
+ if ((lastNode == null ? void 0 : lastNode.name) === "RelationalOperator") {
1251
+ return getValue(lastNode, state);
1252
+ }
1253
+ } else {
1254
+ const prevNode = node.prevSibling;
1255
+ if ((prevNode == null ? void 0 : prevNode.name) === "RelationalOperator") {
1256
+ return getValue(prevNode, state);
1257
+ }
1258
+ }
1259
+ };
1260
+ var getColumnName = (node, state) => {
1261
+ var _a;
1262
+ if (node.name === "RelationalExpression") {
1263
+ if (((_a = node.firstChild) == null ? void 0 : _a.name) === "Column") {
1264
+ return getValue(node.firstChild, state);
1265
+ }
1266
+ } else {
1267
+ const prevNode = node.prevSibling;
1268
+ if ((prevNode == null ? void 0 : prevNode.name) === "Column") {
1269
+ return getValue(prevNode, state);
1270
+ } else if ((prevNode == null ? void 0 : prevNode.name) === "RelationalOperator") {
1271
+ return getColumnName(prevNode, state);
1272
+ }
1273
+ }
1274
+ };
1275
+ var makeSuggestions = async (context, suggestionProvider, suggestionType, optionalArgs = {}) => {
1276
+ const options = await suggestionProvider.getSuggestions(
1277
+ suggestionType,
1278
+ optionalArgs
1279
+ );
1280
+ const { startsWith = "" } = optionalArgs;
1281
+ return { from: context.pos - startsWith.length, options };
1282
+ };
1283
+ var handleConditionalExpression = (node, context, suggestionProvider, maybeComplete, onSubmit) => {
1284
+ const lastChild = getLastChild(node, context);
1285
+ switch (lastChild == null ? void 0 : lastChild.name) {
1286
+ case "If":
1287
+ return makeSuggestions(context, suggestionProvider, "expression", {
1288
+ prefix: "( "
1289
+ });
1290
+ case "OpenBrace":
1291
+ return makeSuggestions(context, suggestionProvider, "expression");
1292
+ case "Condition":
1293
+ return makeSuggestions(context, suggestionProvider, "expression", {
1294
+ prefix: ", "
1295
+ });
1296
+ case "CloseBrace":
1297
+ if (maybeComplete) {
1298
+ const options = [completionDone(onSubmit)];
1299
+ return { from: context.pos, options };
1300
+ }
1301
+ }
1302
+ };
1303
+ var promptToSave = (context, onSubmit) => {
1304
+ const options = [completionDone(onSubmit)];
1305
+ return { from: context.pos, options };
1306
+ };
1307
+ var useColumnAutoComplete = (suggestionProvider, onSubmit) => {
1308
+ const makeSuggestions2 = useCallback4(
1309
+ async (context, suggestionType, optionalArgs = {}) => {
1310
+ const options = await suggestionProvider.getSuggestions(
1311
+ suggestionType,
1312
+ optionalArgs
1313
+ );
1314
+ const { startsWith = "" } = optionalArgs;
1315
+ return { from: context.pos - startsWith.length, options };
1316
+ },
1317
+ [suggestionProvider]
1318
+ );
1319
+ return useCallback4(
1320
+ async (context) => {
1321
+ var _a, _b;
1322
+ const { state, pos } = context;
1323
+ const word = (_a = context.matchBefore(/\w*/)) != null ? _a : {
1324
+ from: 0,
1325
+ to: 0,
1326
+ text: void 0
1327
+ };
1328
+ const tree = syntaxTree(state);
1329
+ const nodeBefore = tree.resolveInner(pos, -1);
1330
+ const text = state.doc.toString();
1331
+ const maybeComplete = isCompleteExpression(text);
1332
+ switch (nodeBefore.name) {
1333
+ case "If": {
1334
+ return makeSuggestions2(context, "expression", { prefix: "( " });
1335
+ }
1336
+ case "Condition":
1337
+ {
1338
+ const lastChild = getLastChild(nodeBefore, context);
1339
+ if ((lastChild == null ? void 0 : lastChild.name) === "Column") {
1340
+ const prevChild = getPreviousNode(lastChild);
1341
+ if ((prevChild == null ? void 0 : prevChild.name) !== "RelationalOperator") {
1342
+ return makeSuggestions2(context, "condition-operator", {
1343
+ columnName: getValue(lastChild, state)
1344
+ });
1345
+ }
1346
+ } else if ((lastChild == null ? void 0 : lastChild.name) === "RelationalOperator") {
1347
+ return makeSuggestions2(context, "expression");
1348
+ }
1349
+ }
1350
+ break;
1351
+ case "ConditionalExpression":
1352
+ return handleConditionalExpression(
1353
+ nodeBefore,
1354
+ context,
1355
+ suggestionProvider
1356
+ );
1357
+ case "RelationalExpression":
1358
+ {
1359
+ if (isCompleteRelationalExpression(nodeBefore)) {
1360
+ return {
1361
+ from: context.pos,
1362
+ options: booleanJoinSuggestions.concat({
1363
+ label: ", <truthy expression>, <falsy expression>",
1364
+ apply: ", "
1365
+ })
1366
+ };
1367
+ } else {
1368
+ const operator = getRelationalOperator(nodeBefore, state);
1369
+ const columnName = getColumnName(nodeBefore, state);
1370
+ if (!operator) {
1371
+ const options = await suggestionProvider.getSuggestions(
1372
+ "condition-operator",
1373
+ {
1374
+ columnName
1375
+ }
1376
+ );
1377
+ return { from: context.pos, options };
1378
+ } else {
1379
+ return makeSuggestions2(context, "expression");
1380
+ }
1381
+ }
1382
+ }
1383
+ break;
1384
+ case "RelationalOperator":
1385
+ return makeSuggestions2(context, "expression");
1386
+ case "String":
1387
+ {
1388
+ const operator = getRelationalOperator(
1389
+ nodeBefore,
1390
+ state
1391
+ );
1392
+ const columnName = getColumnName(nodeBefore, state);
1393
+ const { from, to } = nodeBefore;
1394
+ if (to - from === 2 && context.pos === from + 1) {
1395
+ if (columnName && operator) {
1396
+ return makeSuggestions2(context, "columnValue", {
1397
+ columnName,
1398
+ operator,
1399
+ startsWith: word.text
1400
+ });
1401
+ }
1402
+ } else if (to - from > 2 && context.pos === to) {
1403
+ return makeSuggestions2(context, "expression", {
1404
+ prefix: ", "
1405
+ });
1406
+ }
1407
+ }
1408
+ break;
1409
+ case "ArithmeticExpression":
1410
+ {
1411
+ const lastChild = getLastChild(nodeBefore, context);
1412
+ if ((lastChild == null ? void 0 : lastChild.name) === "Column") {
1413
+ return makeSuggestions2(context, "expression");
1414
+ } else if (isOperator(lastChild)) {
1415
+ const operator = lastChild.name;
1416
+ return makeSuggestions2(context, "column", { operator });
1417
+ }
1418
+ }
1419
+ break;
1420
+ case "OpenBrace":
1421
+ {
1422
+ const functionName = getFunctionName(nodeBefore, state);
1423
+ return makeSuggestions2(context, "expression", { functionName });
1424
+ }
1425
+ break;
1426
+ case "ArgList": {
1427
+ const functionName = getFunctionName(nodeBefore, state);
1428
+ const lastArgument = getLastChild(nodeBefore, context);
1429
+ const prefix = (lastArgument == null ? void 0 : lastArgument.name) === "OpenBrace" || (lastArgument == null ? void 0 : lastArgument.name) === "Comma" ? void 0 : ",";
1430
+ let options = await suggestionProvider.getSuggestions("expression", {
1431
+ functionName
1432
+ });
1433
+ options = prefix ? applyPrefix(options, ", ") : options;
1434
+ if ((lastArgument == null ? void 0 : lastArgument.name) !== "OpenBrace" && (lastArgument == null ? void 0 : lastArgument.name) !== "Comma") {
1435
+ options = [
1436
+ {
1437
+ apply: ") ",
1438
+ boost: 10,
1439
+ label: "Done - no more arguments"
1440
+ }
1441
+ ].concat(options);
1442
+ }
1443
+ return { from: context.pos, options };
1444
+ }
1445
+ case "Equal":
1446
+ if (text.trim() === "=") {
1447
+ return makeSuggestions2(context, "expression");
1448
+ }
1449
+ break;
1450
+ case "ParenthesizedExpression":
1451
+ case "ColumnDefinitionExpression":
1452
+ if (context.pos === 0) {
1453
+ return makeSuggestions2(context, "expression");
1454
+ } else {
1455
+ const lastChild = getLastChild(nodeBefore, context);
1456
+ if ((lastChild == null ? void 0 : lastChild.name) === "Column") {
1457
+ if (maybeComplete) {
1458
+ const options = [
1459
+ completionDone(onSubmit.current)
1460
+ ];
1461
+ const columnName = getValue(lastChild, state);
1462
+ const columnOptions = await suggestionProvider.getSuggestions("operator", {
1463
+ columnName
1464
+ });
1465
+ return {
1466
+ from: context.pos,
1467
+ options: options.concat(columnOptions)
1468
+ };
1469
+ }
1470
+ } else if ((lastChild == null ? void 0 : lastChild.name) === "CallExpression") {
1471
+ if (maybeComplete) {
1472
+ return {
1473
+ from: context.pos,
1474
+ options: [completionDone(onSubmit.current)]
1475
+ };
1476
+ }
1477
+ } else if ((lastChild == null ? void 0 : lastChild.name) === "ArithmeticExpression") {
1478
+ if (maybeComplete) {
1479
+ let options = [completionDone(onSubmit.current)];
1480
+ const lastExpressionChild = getLastChild(lastChild, context);
1481
+ if ((lastExpressionChild == null ? void 0 : lastExpressionChild.name) === "Column") {
1482
+ const columnName = getValue(lastExpressionChild, state);
1483
+ const suggestions = await suggestionProvider.getSuggestions(
1484
+ "operator",
1485
+ { columnName }
1486
+ );
1487
+ options = options.concat(suggestions);
1488
+ }
1489
+ return {
1490
+ from: context.pos,
1491
+ options
1492
+ };
1493
+ }
1494
+ } else if ((lastChild == null ? void 0 : lastChild.name) === "ConditionalExpression") {
1495
+ return handleConditionalExpression(
1496
+ lastChild,
1497
+ context,
1498
+ suggestionProvider,
1499
+ maybeComplete,
1500
+ onSubmit.current
1501
+ );
1502
+ }
1503
+ break;
1504
+ }
1505
+ case "Column":
1506
+ {
1507
+ const isPartialMatch = await suggestionProvider.isPartialMatch(
1508
+ "expression",
1509
+ void 0,
1510
+ word.text
1511
+ );
1512
+ if (isPartialMatch) {
1513
+ return makeSuggestions2(context, "expression", {
1514
+ startsWith: word.text
1515
+ });
1516
+ }
1517
+ }
1518
+ break;
1519
+ case "Comma":
1520
+ {
1521
+ const parentNode = getNamedParentNode(nodeBefore);
1522
+ if ((parentNode == null ? void 0 : parentNode.name) === "ConditionalExpression") {
1523
+ return makeSuggestions2(context, "expression");
1524
+ }
1525
+ }
1526
+ break;
1527
+ case "CloseBrace":
1528
+ {
1529
+ const parentNode = getNamedParentNode(nodeBefore);
1530
+ if ((parentNode == null ? void 0 : parentNode.name) === "ConditionalExpression") {
1531
+ return handleConditionalExpression(
1532
+ parentNode,
1533
+ context,
1534
+ suggestionProvider,
1535
+ maybeComplete,
1536
+ onSubmit.current
1537
+ );
1538
+ } else if ((parentNode == null ? void 0 : parentNode.name) === "ArgList") {
1539
+ if (maybeComplete) {
1540
+ return promptToSave(context, onSubmit.current);
1541
+ }
1542
+ }
1543
+ }
1544
+ break;
1545
+ default: {
1546
+ if (((_b = nodeBefore == null ? void 0 : nodeBefore.prevSibling) == null ? void 0 : _b.name) === "FilterClause") {
1547
+ console.log("looks like we ight be a or|and operator");
1548
+ }
1549
+ }
1550
+ }
1551
+ },
1552
+ [makeSuggestions2, onSubmit, suggestionProvider]
1553
+ );
1554
+ };
1555
+
1556
+ // src/column-expression-input/useColumnExpressionEditor.ts
1557
+ var getView = (ref) => {
1558
+ if (ref.current == void 0) {
1559
+ throw Error("EditorView not defined");
1560
+ }
1561
+ return ref.current;
1562
+ };
1563
+ var getOptionClass = () => {
1564
+ return "vuuSuggestion";
1565
+ };
1566
+ var noop = () => console.log("noooop");
1567
+ var hasExpressionType = (completion) => "expressionType" in completion;
1568
+ var injectOptionContent = (completion) => {
1569
+ if (hasExpressionType(completion)) {
1570
+ const div = createEl("div", "expression-type-container");
1571
+ const span = createEl("span", "expression-type", completion.expressionType);
1572
+ div.appendChild(span);
1573
+ return div;
1574
+ } else {
1575
+ return null;
1576
+ }
1577
+ };
1578
+ var useColumnExpressionEditor = ({
1579
+ onChange,
1580
+ onSubmitExpression,
1581
+ source,
1582
+ suggestionProvider
1583
+ }) => {
1584
+ const editorRef = useRef3(null);
1585
+ const onSubmitRef = useRef3(noop);
1586
+ const viewRef = useRef3();
1587
+ const completionFn = useColumnAutoComplete(suggestionProvider, onSubmitRef);
1588
+ const [createState, clearInput, submit] = useMemo2(() => {
1589
+ const parseExpression = () => {
1590
+ const view = getView(viewRef);
1591
+ const source2 = view.state.doc.toString();
1592
+ const tree = ensureSyntaxTree(view.state, view.state.doc.length, 5e3);
1593
+ if (tree) {
1594
+ const expression = walkTree(tree, source2);
1595
+ return [source2, expression];
1596
+ } else {
1597
+ return ["", void 0];
1598
+ }
1599
+ };
1600
+ const clearInput2 = () => {
1601
+ getView(viewRef).setState(createState2());
1602
+ };
1603
+ const submitExpression = () => {
1604
+ const [source2, expression] = parseExpression();
1605
+ onSubmitExpression == null ? void 0 : onSubmitExpression(source2, expression);
1606
+ };
1607
+ const showSuggestions = (key) => {
1608
+ return keymap.of([
1609
+ {
1610
+ key,
1611
+ run() {
1612
+ startCompletion(getView(viewRef));
1613
+ return true;
1614
+ }
1615
+ }
1616
+ ]);
1617
+ };
1618
+ const createState2 = () => EditorState2.create({
1619
+ doc: source,
1620
+ extensions: [
1621
+ minimalSetup,
1622
+ autocompletion({
1623
+ addToOptions: [
1624
+ {
1625
+ render: injectOptionContent,
1626
+ position: 70
1627
+ }
1628
+ ],
1629
+ override: [completionFn],
1630
+ optionClass: getOptionClass
1631
+ }),
1632
+ columnExpressionLanguageSupport(),
1633
+ keymap.of(defaultKeymap),
1634
+ showSuggestions("ArrowDown"),
1635
+ EditorView2.updateListener.of((v) => {
1636
+ const view = getView(viewRef);
1637
+ if (v.docChanged) {
1638
+ startCompletion(view);
1639
+ const source2 = view.state.doc.toString();
1640
+ onChange == null ? void 0 : onChange(source2);
1641
+ }
1642
+ }),
1643
+ // Enforces single line view
1644
+ EditorState2.transactionFilter.of(
1645
+ (tr) => tr.newDoc.lines > 1 ? [] : tr
1646
+ ),
1647
+ vuuTheme,
1648
+ vuuHighlighting
1649
+ ]
1650
+ });
1651
+ onSubmitRef.current = () => {
1652
+ submitExpression();
1653
+ };
1654
+ return [createState2, clearInput2, submitExpression];
1655
+ }, [completionFn, onChange, onSubmitExpression, source]);
1656
+ useEffect2(() => {
1657
+ if (!editorRef.current) {
1658
+ throw Error("editor not in dom");
1659
+ }
1660
+ viewRef.current = new EditorView2({
1661
+ state: createState(),
1662
+ parent: editorRef.current
1663
+ });
1664
+ return () => {
1665
+ var _a;
1666
+ (_a = viewRef.current) == null ? void 0 : _a.destroy();
1667
+ };
1668
+ }, [completionFn, createState]);
1669
+ const handleBlur = useCallback5(() => {
1670
+ submit();
1671
+ }, [submit]);
1672
+ return { editorRef, clearInput, onBlur: handleBlur };
1673
+ };
1674
+
1675
+ // src/column-expression-input/ColumnExpressionInput.tsx
1676
+ import { jsx as jsx8 } from "react/jsx-runtime";
1677
+ var classBase7 = "vuuColumnExpressionInput";
1678
+ var ColumnExpressionInput = memo4(
1679
+ ({
1680
+ onChange,
1681
+ onSubmitExpression,
1682
+ source = "",
1683
+ suggestionProvider
1684
+ }) => {
1685
+ const { editorRef, onBlur } = useColumnExpressionEditor({
1686
+ onChange,
1687
+ onSubmitExpression,
1688
+ source,
1689
+ suggestionProvider
1690
+ });
1691
+ return /* @__PURE__ */ jsx8("div", { className: `${classBase7}`, onBlur, ref: editorRef });
1692
+ },
1693
+ (prevProps, newProps) => {
1694
+ return prevProps.source === newProps.source;
1695
+ }
1696
+ );
1697
+ ColumnExpressionInput.displayName = "ColumnExpressionInput";
1698
+
1699
+ // src/column-expression-input/useColumnExpressionSuggestionProvider.ts
1700
+ import {
1701
+ AnnotationType,
1702
+ getRelationalOperators,
1703
+ numericOperators,
1704
+ stringOperators,
1705
+ toSuggestions
1706
+ } from "@vuu-ui/vuu-codemirror";
1707
+ import {
1708
+ getTypeaheadParams,
1709
+ useTypeaheadSuggestions
1710
+ } from "@vuu-ui/vuu-data-react";
1711
+ import { isNumericColumn, isTextColumn } from "@vuu-ui/vuu-utils";
1712
+ import { useCallback as useCallback6, useRef as useRef4 } from "react";
1713
+
1714
+ // src/column-expression-input/column-function-descriptors.ts
1715
+ var columnFunctionDescriptors = [
1716
+ /**
1717
+ * and
1718
+ */
1719
+ {
1720
+ accepts: ["boolean"],
1721
+ description: "Applies boolean and operator across supplied parameters to returns a single boolean result",
1722
+ example: {
1723
+ expression: 'and(ccy="EUR",quantity=0)',
1724
+ result: "true | false"
1725
+ },
1726
+ name: "and",
1727
+ params: {
1728
+ description: "( boolean, [ boolean* ] )"
1729
+ },
1730
+ type: "boolean"
1731
+ },
1732
+ /**
1733
+ * concatenate()
1734
+ */
1735
+ {
1736
+ accepts: "string",
1737
+ 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.",
1738
+ example: {
1739
+ expression: 'concatenate("example", "-test")',
1740
+ result: '"example-test"'
1741
+ },
1742
+ name: "concatenate",
1743
+ params: {
1744
+ description: "( string, string, [ string* ] )"
1745
+ },
1746
+ type: "string"
1747
+ },
1748
+ /**
1749
+ * contains()
1750
+ */
1751
+ {
1752
+ accepts: ["string", "string"],
1753
+ 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>",
1754
+ example: {
1755
+ expression: 'contains("Royal Bank of Scotland", "bank")',
1756
+ result: "true"
1757
+ },
1758
+ name: "contains",
1759
+ params: {
1760
+ description: "( string )"
1761
+ },
1762
+ type: "boolean"
1763
+ },
1764
+ /**
1765
+ * left()
1766
+ */
1767
+ {
1768
+ accepts: ["string", "number"],
1769
+ description: "Returns the leftmost <number> characters from <string>. First argument may be a string literal, string column or other string expression.",
1770
+ example: {
1771
+ expression: 'left("USD Benchmark Report", 3)',
1772
+ result: '"USD"'
1773
+ },
1774
+ name: "left",
1775
+ params: {
1776
+ count: 2,
1777
+ description: "( string, number )"
1778
+ },
1779
+ type: "string"
1780
+ },
1781
+ /**
1782
+ * len()
1783
+ */
1784
+ {
1785
+ accepts: "string",
1786
+ description: "Returns the number of characters in <string>. Argument may be a string literal, string column or other string expression.",
1787
+ example: {
1788
+ expression: 'len("example")',
1789
+ result: "7"
1790
+ },
1791
+ name: "len",
1792
+ params: {
1793
+ description: "(string)"
1794
+ },
1795
+ type: "number"
1796
+ },
1797
+ /**
1798
+ * lower()
1799
+ */
1800
+ {
1801
+ accepts: "string",
1802
+ description: "Convert a string value to lowercase. Argument may be a string column or other string expression.",
1803
+ example: {
1804
+ expression: 'lower("examPLE")',
1805
+ result: '"example"'
1806
+ },
1807
+ name: "lower",
1808
+ params: {
1809
+ description: "( string )"
1810
+ },
1811
+ type: "string"
1812
+ },
1813
+ /**
1814
+ * or
1815
+ */
1816
+ {
1817
+ accepts: ["boolean"],
1818
+ description: "Applies boolean or operator across supplied parameters to returns a single boolean result",
1819
+ example: {
1820
+ expression: 'or(status="cancelled",quantity=0)',
1821
+ result: "true | false"
1822
+ },
1823
+ name: "or",
1824
+ params: {
1825
+ description: "( boolean, [ boolean* ] )"
1826
+ },
1827
+ type: "boolean"
1828
+ },
1829
+ /**
1830
+ * upper()
1831
+ */
1832
+ {
1833
+ accepts: "string",
1834
+ description: "Convert a string value to uppercase. Argument may be a string column or other string expression.",
1835
+ example: {
1836
+ expression: 'upper("example")',
1837
+ result: '"EXAMPLE"'
1838
+ },
1839
+ name: "upper",
1840
+ params: {
1841
+ description: "( string )"
1842
+ },
1843
+ type: "string"
1844
+ },
1845
+ /**
1846
+ * right()
1847
+ */
1848
+ {
1849
+ accepts: ["string", "number"],
1850
+ description: "Returns the rightmost <number> characters from <string>. First argument may be a string literal, string column or other string expression.",
1851
+ example: {
1852
+ expression: "blah",
1853
+ result: "blah"
1854
+ },
1855
+ name: "right",
1856
+ params: {
1857
+ description: "( string )"
1858
+ },
1859
+ type: "string"
1860
+ },
1861
+ /**
1862
+ * replace()
1863
+ */
1864
+ {
1865
+ accepts: ["string", "string", "string"],
1866
+ 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>",
1867
+ example: {
1868
+ expression: "blah",
1869
+ result: "blah"
1870
+ },
1871
+ name: "replace",
1872
+ params: {
1873
+ description: "( string )"
1874
+ },
1875
+ type: "string"
1876
+ },
1877
+ /**
1878
+ * text()
1879
+ */
1880
+ {
1881
+ accepts: "number",
1882
+ description: "Converts a number to a string.",
1883
+ example: {
1884
+ expression: "blah",
1885
+ result: "blah"
1886
+ },
1887
+ name: "text",
1888
+ params: {
1889
+ description: "( string )"
1890
+ },
1891
+ type: "string"
1892
+ },
1893
+ /**
1894
+ * starts()
1895
+ */
1896
+ {
1897
+ accepts: "string",
1898
+ 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>.",
1899
+ example: {
1900
+ expression: "blah",
1901
+ result: "blah"
1902
+ },
1903
+ name: "starts",
1904
+ params: {
1905
+ description: "( string )"
1906
+ },
1907
+ type: "boolean"
1908
+ },
1909
+ /**
1910
+ * starts()
1911
+ */
1912
+ {
1913
+ accepts: "string",
1914
+ 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>.",
1915
+ example: {
1916
+ expression: "blah",
1917
+ result: "blah"
1918
+ },
1919
+ name: "ends",
1920
+ params: {
1921
+ description: "( string )"
1922
+ },
1923
+ type: "boolean"
1924
+ },
1925
+ {
1926
+ accepts: "number",
1927
+ description: "blah",
1928
+ example: {
1929
+ expression: "blah",
1930
+ result: "blah"
1931
+ },
1932
+ name: "min",
1933
+ params: {
1934
+ description: "( string )"
1935
+ },
1936
+ type: "number"
1937
+ },
1938
+ {
1939
+ accepts: "number",
1940
+ description: "blah",
1941
+ example: {
1942
+ expression: "blah",
1943
+ result: "blah"
1944
+ },
1945
+ name: "max",
1946
+ params: {
1947
+ description: "( string )"
1948
+ },
1949
+ type: "number"
1950
+ },
1951
+ {
1952
+ accepts: "number",
1953
+ description: "blah",
1954
+ example: {
1955
+ expression: "blah",
1956
+ result: "blah"
1957
+ },
1958
+ name: "sum",
1959
+ params: {
1960
+ description: "( string )"
1961
+ },
1962
+ type: "number"
1963
+ },
1964
+ {
1965
+ accepts: "number",
1966
+ description: "blah",
1967
+ example: {
1968
+ expression: "blah",
1969
+ result: "blah"
1970
+ },
1971
+ name: "round",
1972
+ params: {
1973
+ description: "( string )"
1974
+ },
1975
+ type: "number"
1976
+ },
1977
+ {
1978
+ accepts: "any",
1979
+ description: "blah",
1980
+ example: {
1981
+ expression: "blah",
1982
+ result: "blah"
1983
+ },
1984
+ name: "or",
1985
+ params: {
1986
+ description: "( string )"
1987
+ },
1988
+ type: "boolean"
1989
+ },
1990
+ {
1991
+ accepts: "any",
1992
+ description: "blah",
1993
+ example: {
1994
+ expression: "blah",
1995
+ result: "blah"
1996
+ },
1997
+ name: "and",
1998
+ params: {
1999
+ description: "( string )"
2000
+ },
2001
+ type: "boolean"
2002
+ },
2003
+ {
2004
+ accepts: "any",
2005
+ 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>. ",
2006
+ example: {
2007
+ expression: "blah",
2008
+ result: "blah"
2009
+ },
2010
+ name: "if",
2011
+ params: {
2012
+ description: "( filterExpression, expression1, expression 2)"
2013
+ },
2014
+ type: "variable"
2015
+ }
2016
+ ];
2017
+
2018
+ // src/column-expression-input/functionDocInfo.ts
2019
+ import { createEl as createEl2 } from "@vuu-ui/vuu-utils";
2020
+ var functionDocInfo = ({
2021
+ name: name2,
2022
+ description,
2023
+ example,
2024
+ params,
2025
+ type
2026
+ }) => {
2027
+ const rootElement = createEl2("div", "vuuFunctionDoc");
2028
+ const headingElement = createEl2("div", "function-heading");
2029
+ const nameElement = createEl2("span", "function-name", name2);
2030
+ const paramElement = createEl2("span", "param-list", params.description);
2031
+ const typeElement = createEl2("span", "function-type", type);
2032
+ headingElement.appendChild(nameElement);
2033
+ headingElement.appendChild(paramElement);
2034
+ headingElement.appendChild(typeElement);
2035
+ const child2 = createEl2("p", void 0, description);
2036
+ rootElement.appendChild(headingElement);
2037
+ rootElement.appendChild(child2);
2038
+ if (example) {
2039
+ const exampleElement = createEl2("div", "example-container");
2040
+ const expressionElement = createEl2(
2041
+ "div",
2042
+ "example-expression",
2043
+ example.expression
2044
+ );
2045
+ const resultElement = createEl2("div", "example-result", example.result);
2046
+ exampleElement.appendChild(expressionElement);
2047
+ rootElement.appendChild(exampleElement);
2048
+ rootElement.appendChild(resultElement);
2049
+ }
2050
+ return rootElement;
2051
+ };
2052
+
2053
+ // src/column-expression-input/useColumnExpressionSuggestionProvider.ts
2054
+ var NO_OPERATORS = [];
2055
+ var withApplySpace = (suggestions) => suggestions.map((suggestion) => {
2056
+ var _a;
2057
+ return {
2058
+ ...suggestion,
2059
+ apply: ((_a = suggestion.apply) != null ? _a : suggestion.label) + " "
2060
+ };
2061
+ });
2062
+ var getValidColumns = (columns, { functionName, operator }) => {
2063
+ if (operator) {
2064
+ return columns.filter(isNumericColumn);
2065
+ } else if (functionName) {
2066
+ const fn = columnFunctionDescriptors.find((f) => f.name === functionName);
2067
+ if (fn) {
2068
+ switch (fn.accepts) {
2069
+ case "string":
2070
+ return columns.filter(isTextColumn);
2071
+ case "number":
2072
+ return columns.filter(isNumericColumn);
2073
+ default:
2074
+ return columns;
2075
+ }
2076
+ }
2077
+ }
2078
+ return columns;
2079
+ };
2080
+ var getColumns = (columns, options) => {
2081
+ const validColumns = getValidColumns(columns, options);
2082
+ return validColumns.map((column) => {
2083
+ var _a;
2084
+ const label = (_a = column.label) != null ? _a : column.name;
2085
+ return {
2086
+ apply: options.prefix ? `${options.prefix}${column.name}` : column.name,
2087
+ label,
2088
+ boost: 5,
2089
+ type: "column",
2090
+ expressionType: column.serverDataType
2091
+ };
2092
+ });
2093
+ };
2094
+ var arithmeticOperators = [
2095
+ { apply: "* ", boost: 2, label: "*", type: "operator" },
2096
+ { apply: "/ ", boost: 2, label: "/", type: "operator" },
2097
+ { apply: "+ ", boost: 2, label: "+", type: "operator" },
2098
+ { apply: "- ", boost: 2, label: "-", type: "operator" }
2099
+ ];
2100
+ var getOperators = (column) => {
2101
+ if (column === void 0 || isNumericColumn(column)) {
2102
+ return arithmeticOperators;
2103
+ } else {
2104
+ return NO_OPERATORS;
2105
+ }
2106
+ };
2107
+ var getConditionOperators = (column) => {
2108
+ switch (column.serverDataType) {
2109
+ case "string":
2110
+ case "char":
2111
+ return withApplySpace(
2112
+ stringOperators
2113
+ /*, startsWith*/
2114
+ );
2115
+ case "int":
2116
+ case "long":
2117
+ case "double":
2118
+ return withApplySpace(numericOperators);
2119
+ }
2120
+ };
2121
+ var toFunctionCompletion = (functionDescriptor) => ({
2122
+ apply: `${functionDescriptor.name}( `,
2123
+ boost: 2,
2124
+ expressionType: functionDescriptor.type,
2125
+ info: () => functionDocInfo(functionDescriptor),
2126
+ label: functionDescriptor.name,
2127
+ type: "function"
2128
+ });
2129
+ var getAcceptedTypes = (fn) => {
2130
+ if (fn) {
2131
+ if (typeof fn.accepts === "string") {
2132
+ return fn.accepts;
2133
+ } else if (Array.isArray(fn.accepts)) {
2134
+ if (fn.accepts.every((s) => s === "string")) {
2135
+ return "string";
2136
+ } else {
2137
+ return "any";
2138
+ }
2139
+ }
2140
+ }
2141
+ return "any";
2142
+ };
2143
+ var functions = columnFunctionDescriptors.map(toFunctionCompletion);
2144
+ var getFunctions = ({ functionName }) => {
2145
+ if (functionName) {
2146
+ const fn = columnFunctionDescriptors.find((f) => f.name === functionName);
2147
+ const acceptedTypes = getAcceptedTypes(fn);
2148
+ if (fn) {
2149
+ switch (acceptedTypes) {
2150
+ case "string":
2151
+ return columnFunctionDescriptors.filter((f) => f.type === "string" || f.type === "variable").map(toFunctionCompletion);
2152
+ case "number":
2153
+ return columnFunctionDescriptors.filter((f) => f.type === "number" || f.type === "variable").map(toFunctionCompletion);
2154
+ default:
2155
+ }
2156
+ }
2157
+ }
2158
+ return functions;
2159
+ };
2160
+ var NONE = {};
2161
+ var useColumnExpressionSuggestionProvider = ({
2162
+ columns,
2163
+ table
2164
+ }) => {
2165
+ const findColumn = useCallback6(
2166
+ (name2) => name2 ? columns.find((col) => col.name === name2) : void 0,
2167
+ [columns]
2168
+ );
2169
+ const latestSuggestionsRef = useRef4();
2170
+ const getTypeaheadSuggestions = useTypeaheadSuggestions();
2171
+ const getSuggestions = useCallback6(
2172
+ async (suggestionType, options = NONE) => {
2173
+ const { columnName, functionName, operator, prefix } = options;
2174
+ switch (suggestionType) {
2175
+ case "expression": {
2176
+ const suggestions = await withApplySpace(
2177
+ getColumns(columns, { functionName, prefix })
2178
+ ).concat(getFunctions(options));
2179
+ return latestSuggestionsRef.current = suggestions;
2180
+ }
2181
+ case "column": {
2182
+ const suggestions = await getColumns(columns, options);
2183
+ return latestSuggestionsRef.current = withApplySpace(suggestions);
2184
+ }
2185
+ case "operator": {
2186
+ const suggestions = await getOperators(findColumn(columnName));
2187
+ return latestSuggestionsRef.current = withApplySpace(suggestions);
2188
+ }
2189
+ case "relational-operator": {
2190
+ const suggestions = await getRelationalOperators(
2191
+ findColumn(columnName)
2192
+ );
2193
+ return latestSuggestionsRef.current = withApplySpace(suggestions);
2194
+ }
2195
+ case "condition-operator":
2196
+ {
2197
+ const column = findColumn(columnName);
2198
+ if (column) {
2199
+ const suggestions = await getConditionOperators(column);
2200
+ if (suggestions) {
2201
+ return latestSuggestionsRef.current = withApplySpace(suggestions);
2202
+ }
2203
+ }
2204
+ }
2205
+ break;
2206
+ case "columnValue":
2207
+ if (columnName && operator) {
2208
+ const params = getTypeaheadParams(
2209
+ table,
2210
+ columnName
2211
+ /*, startsWith*/
2212
+ );
2213
+ const suggestions = await getTypeaheadSuggestions(params);
2214
+ latestSuggestionsRef.current = toSuggestions(suggestions, {
2215
+ suffix: ""
2216
+ });
2217
+ latestSuggestionsRef.current.forEach((suggestion) => {
2218
+ suggestion.apply = (view, completion, from) => {
2219
+ const annotation = new AnnotationType();
2220
+ const cursorPos = from + completion.label.length + 1;
2221
+ view.dispatch({
2222
+ changes: { from, insert: completion.label },
2223
+ selection: { anchor: cursorPos, head: cursorPos },
2224
+ annotations: annotation.of(completion)
2225
+ });
2226
+ };
2227
+ });
2228
+ return latestSuggestionsRef.current;
2229
+ }
2230
+ break;
2231
+ }
2232
+ return [];
2233
+ },
2234
+ [columns, findColumn, getTypeaheadSuggestions, table]
2235
+ );
2236
+ const isPartialMatch = useCallback6(
2237
+ async (valueType, columnName, pattern) => {
2238
+ const { current: latestSuggestions } = latestSuggestionsRef;
2239
+ let maybe = false;
2240
+ const suggestions = latestSuggestions || await getSuggestions(valueType, { columnName });
2241
+ if (pattern && suggestions) {
2242
+ for (const option of suggestions) {
2243
+ if (option.label === pattern) {
2244
+ return false;
2245
+ } else if (option.label.startsWith(pattern)) {
2246
+ maybe = true;
2247
+ }
2248
+ }
2249
+ }
2250
+ return maybe;
2251
+ },
2252
+ [getSuggestions]
2253
+ );
2254
+ return {
2255
+ getSuggestions,
2256
+ isPartialMatch
2257
+ };
2258
+ };
2259
+
2260
+ // src/column-expression-panel/useColumnExpression.ts
2261
+ import {
2262
+ getCalculatedColumnDetails,
2263
+ isVuuColumnDataType,
2264
+ setCalculatedColumnExpression,
2265
+ setCalculatedColumnName,
2266
+ setCalculatedColumnType
2267
+ } from "@vuu-ui/vuu-utils";
2268
+ import { useCallback as useCallback7, useRef as useRef5, useState as useState2 } from "react";
2269
+ var applyDefaults = (column) => {
2270
+ const [name2, expression, type] = getCalculatedColumnDetails(column);
2271
+ if (type === "") {
2272
+ return {
2273
+ ...column,
2274
+ name: `${name2}:string:${expression}`
2275
+ };
2276
+ } else {
2277
+ return column;
2278
+ }
2279
+ };
2280
+ var useColumnExpression = ({
2281
+ column: columnProp,
2282
+ onChangeName: onChangeNameProp,
2283
+ onChangeServerDataType: onChangeServerDataTypeProp
2284
+ }) => {
2285
+ const [column, _setColumn] = useState2(
2286
+ applyDefaults(columnProp)
2287
+ );
2288
+ const columnRef = useRef5(columnProp);
2289
+ const setColumn = useCallback7((column2) => {
2290
+ columnRef.current = column2;
2291
+ _setColumn(column2);
2292
+ }, []);
2293
+ const onChangeName = useCallback7(
2294
+ (evt) => {
2295
+ const { value } = evt.target;
2296
+ const newColumn = setCalculatedColumnName(column, value);
2297
+ setColumn(newColumn);
2298
+ onChangeNameProp == null ? void 0 : onChangeNameProp(newColumn.name);
2299
+ },
2300
+ [column, onChangeNameProp, setColumn]
2301
+ );
2302
+ const onChangeExpression = useCallback7(
2303
+ (value) => {
2304
+ const expression = value.trim();
2305
+ const { current: column2 } = columnRef;
2306
+ const newColumn = setCalculatedColumnExpression(column2, expression);
2307
+ setColumn(newColumn);
2308
+ onChangeNameProp == null ? void 0 : onChangeNameProp(newColumn.name);
2309
+ },
2310
+ [onChangeNameProp, setColumn]
2311
+ );
2312
+ const onChangeServerDataType = useCallback7(
2313
+ (evt, value) => {
2314
+ if (isVuuColumnDataType(value)) {
2315
+ const newColumn = setCalculatedColumnType(column, value);
2316
+ setColumn(newColumn);
2317
+ onChangeNameProp == null ? void 0 : onChangeNameProp(newColumn.name);
2318
+ onChangeServerDataTypeProp == null ? void 0 : onChangeServerDataTypeProp(value);
2319
+ }
2320
+ },
2321
+ [column, onChangeNameProp, onChangeServerDataTypeProp, setColumn]
2322
+ );
2323
+ return {
2324
+ column,
2325
+ onChangeExpression,
2326
+ onChangeName,
2327
+ onChangeServerDataType
2328
+ };
2329
+ };
2330
+
2331
+ // src/column-expression-panel/ColumnExpressionPanel.tsx
2332
+ import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
2333
+ var classBase8 = "vuuColumnExpressionPanel";
2334
+ var ColumnExpressionPanel = ({
2335
+ column: columnProp,
2336
+ onChangeName: onChangeNameProp,
2337
+ onChangeServerDataType: onChangeServerDataTypeProp,
2338
+ tableConfig,
2339
+ vuuTable
2340
+ }) => {
2341
+ const typeRef = useRef6(null);
2342
+ const { column, onChangeExpression, onChangeName, onChangeServerDataType } = useColumnExpression({
2343
+ column: columnProp,
2344
+ onChangeName: onChangeNameProp,
2345
+ onChangeServerDataType: onChangeServerDataTypeProp
2346
+ });
2347
+ const initialExpressionRef = useRef6(
2348
+ getCalculatedColumnExpression(column)
2349
+ );
2350
+ const suggestionProvider = useColumnExpressionSuggestionProvider({
2351
+ columns: tableConfig.columns,
2352
+ table: vuuTable
2353
+ });
2354
+ const handleSubmitExpression = useCallback8(() => {
2355
+ var _a, _b;
2356
+ if (typeRef.current) {
2357
+ (_b = (_a = typeRef.current) == null ? void 0 : _a.querySelector("button")) == null ? void 0 : _b.focus();
2358
+ }
2359
+ }, []);
2360
+ return /* @__PURE__ */ jsxs6("div", { className: classBase8, children: [
2361
+ /* @__PURE__ */ jsx9("div", { className: "vuuColumnSettingsPanel-header", children: /* @__PURE__ */ jsx9("span", { children: "Calculation" }) }),
2362
+ /* @__PURE__ */ jsxs6(FormField2, { "data-field": "column-name", children: [
2363
+ /* @__PURE__ */ jsx9(FormFieldLabel2, { children: "Column Name" }),
2364
+ /* @__PURE__ */ jsx9(
2365
+ Input,
2366
+ {
2367
+ className: "vuuInput",
2368
+ onChange: onChangeName,
2369
+ value: getCalculatedColumnName(column)
2370
+ }
2371
+ )
2372
+ ] }),
2373
+ /* @__PURE__ */ jsxs6(FormField2, { "data-field": "column-expression", children: [
2374
+ /* @__PURE__ */ jsx9(FormFieldLabel2, { children: "Expression" }),
2375
+ /* @__PURE__ */ jsx9(
2376
+ ColumnExpressionInput,
2377
+ {
2378
+ onChange: onChangeExpression,
2379
+ onSubmitExpression: handleSubmitExpression,
2380
+ source: initialExpressionRef.current,
2381
+ suggestionProvider
2382
+ }
2383
+ )
2384
+ ] }),
2385
+ /* @__PURE__ */ jsxs6(FormField2, { "data-field": "type", children: [
2386
+ /* @__PURE__ */ jsx9(FormFieldLabel2, { children: "Column type" }),
2387
+ /* @__PURE__ */ jsx9(
2388
+ Dropdown3,
2389
+ {
2390
+ className: `${classBase8}-type`,
2391
+ onSelectionChange: onChangeServerDataType,
2392
+ ref: typeRef,
2393
+ selected: getCalculatedColumnType(column) || null,
2394
+ source: ["double", "long", "string", "boolean"],
2395
+ width: "100%"
2396
+ }
2397
+ )
2398
+ ] })
2399
+ ] });
2400
+ };
2401
+
2402
+ // src/column-formatting-settings/ColumnFormattingPanel.tsx
2403
+ import { Dropdown as Dropdown5 } from "@vuu-ui/vuu-ui-controls";
2404
+ import {
2405
+ getCellRendererOptions,
2406
+ getConfigurationEditor,
2407
+ isColumnTypeRenderer as isColumnTypeRenderer2,
2408
+ isTypeDescriptor as isTypeDescriptor5
2409
+ } from "@vuu-ui/vuu-utils";
2410
+ import { FormField as FormField6, FormFieldLabel as FormFieldLabel6 } from "@salt-ds/core";
2411
+ import cx5 from "clsx";
2412
+ import { useCallback as useCallback12, useMemo as useMemo4 } from "react";
2413
+
2414
+ // src/column-formatting-settings/BaseNumericFormattingSettings.tsx
2415
+ import { FormField as FormField3, FormFieldLabel as FormFieldLabel3, Input as Input2, Switch as Switch2 } from "@salt-ds/core";
2416
+ import { getTypeFormattingFromColumn } from "@vuu-ui/vuu-utils";
2417
+ import {
2418
+ useCallback as useCallback9,
2419
+ useState as useState3
2420
+ } from "react";
2421
+ import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
2422
+ var classBase9 = "vuuFormattingSettings";
2423
+ var BaseNumericFormattingSettings = ({
2424
+ column,
2425
+ onChangeFormatting: onChange
2426
+ }) => {
2427
+ var _a, _b, _c;
2428
+ const [formattingSettings, setFormattingSettings] = useState3(getTypeFormattingFromColumn(column));
2429
+ const handleInputKeyDown = useCallback9(
2430
+ (evt) => {
2431
+ if (evt.key === "Enter" || evt.key === "Tab") {
2432
+ onChange(formattingSettings);
2433
+ }
2434
+ },
2435
+ [formattingSettings, onChange]
2436
+ );
2437
+ const handleChangeDecimals = useCallback9(
2438
+ (evt) => {
2439
+ const { value } = evt.target;
2440
+ const numericValue = value === "" ? void 0 : isNaN(parseInt(value)) ? void 0 : parseInt(value);
2441
+ const newFormattingSettings = {
2442
+ ...formattingSettings,
2443
+ decimals: numericValue
2444
+ };
2445
+ setFormattingSettings(newFormattingSettings);
2446
+ },
2447
+ [formattingSettings]
2448
+ );
2449
+ const handleChangeAlignDecimals = useCallback9(
2450
+ (evt) => {
2451
+ const { checked } = evt.target;
2452
+ const newFormattingSettings = {
2453
+ ...formattingSettings,
2454
+ alignOnDecimals: checked
2455
+ };
2456
+ setFormattingSettings(newFormattingSettings);
2457
+ onChange(newFormattingSettings);
2458
+ },
2459
+ [formattingSettings, onChange]
2460
+ );
2461
+ const handleChangeZeroPad = useCallback9(
2462
+ (evt) => {
2463
+ const { checked } = evt.target;
2464
+ const newFormattingSettings = {
2465
+ ...formattingSettings,
2466
+ zeroPad: checked
2467
+ };
2468
+ setFormattingSettings(newFormattingSettings);
2469
+ onChange(newFormattingSettings);
2470
+ },
2471
+ [formattingSettings, onChange]
2472
+ );
2473
+ return /* @__PURE__ */ jsxs7("div", { className: classBase9, children: [
2474
+ /* @__PURE__ */ jsxs7(FormField3, { "data-field": "decimals", children: [
2475
+ /* @__PURE__ */ jsx10(FormFieldLabel3, { children: "Number of decimals" }),
2476
+ /* @__PURE__ */ jsx10(
2477
+ Input2,
2478
+ {
2479
+ className: "vuuInput",
2480
+ onChange: handleChangeDecimals,
2481
+ onKeyDown: handleInputKeyDown,
2482
+ value: (_a = formattingSettings.decimals) != null ? _a : ""
2483
+ }
2484
+ )
2485
+ ] }),
2486
+ /* @__PURE__ */ jsxs7(FormField3, { labelPlacement: "left", children: [
2487
+ /* @__PURE__ */ jsx10(FormFieldLabel3, { children: "Align on decimals" }),
2488
+ /* @__PURE__ */ jsx10(
2489
+ Switch2,
2490
+ {
2491
+ checked: (_b = formattingSettings.alignOnDecimals) != null ? _b : false,
2492
+ onChange: handleChangeAlignDecimals,
2493
+ value: "align-decimals"
2494
+ }
2495
+ )
2496
+ ] }),
2497
+ /* @__PURE__ */ jsxs7(FormField3, { labelPlacement: "left", children: [
2498
+ /* @__PURE__ */ jsx10(FormFieldLabel3, { children: "Zero pad decimals" }),
2499
+ /* @__PURE__ */ jsx10(
2500
+ Switch2,
2501
+ {
2502
+ checked: (_c = formattingSettings.zeroPad) != null ? _c : false,
2503
+ onChange: handleChangeZeroPad,
2504
+ value: "zero-pad"
2505
+ }
2506
+ )
2507
+ ] })
2508
+ ] });
2509
+ };
2510
+
2511
+ // src/column-formatting-settings/LongTypeFormattingSettings.tsx
2512
+ import { useCallback as useCallback11 } from "react";
2513
+ import {
2514
+ FormField as FormField5,
2515
+ FormFieldLabel as FormFieldLabel5,
2516
+ ToggleButton as ToggleButton2,
2517
+ ToggleButtonGroup as ToggleButtonGroup2
2518
+ } from "@salt-ds/core";
2519
+ import { isDateTimeColumn, isTypeDescriptor as isTypeDescriptor4 } from "@vuu-ui/vuu-utils";
2520
+
2521
+ // src/column-formatting-settings/DateTimeFormattingSettings.tsx
2522
+ import { useCallback as useCallback10, useMemo as useMemo3, useState as useState4 } from "react";
2523
+ import { Dropdown as Dropdown4 } from "@vuu-ui/vuu-ui-controls";
2524
+ import {
2525
+ defaultPatternsByType,
2526
+ fallbackDateTimePattern,
2527
+ getTypeFormattingFromColumn as getTypeFormattingFromColumn2,
2528
+ supportedDateTimePatterns
2529
+ } from "@vuu-ui/vuu-utils";
2530
+ import {
2531
+ FormField as FormField4,
2532
+ FormFieldLabel as FormFieldLabel4,
2533
+ ToggleButton,
2534
+ ToggleButtonGroup
2535
+ } from "@salt-ds/core";
2536
+ import { Fragment, jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
2537
+ var DateTimeFormattingSettings = ({ column, onChangeFormatting: onChange }) => {
2538
+ var _a, _b;
2539
+ const formatting = getTypeFormattingFromColumn2(column);
2540
+ const { pattern = fallbackDateTimePattern } = formatting;
2541
+ const toggleValue = useMemo3(() => getToggleValue(pattern), [pattern]);
2542
+ const [fallbackState, setFallbackState] = useState4(
2543
+ {
2544
+ time: (_a = pattern.time) != null ? _a : defaultPatternsByType.time,
2545
+ date: (_b = pattern.date) != null ? _b : defaultPatternsByType.date
2546
+ }
2547
+ );
2548
+ const onPatternChange = useCallback10(
2549
+ (pattern2) => onChange({ ...formatting, pattern: pattern2 }),
2550
+ [onChange, formatting]
2551
+ );
2552
+ const onDropdownChange = useCallback10(
2553
+ (key) => (_, p) => {
2554
+ const updatedPattern = { ...pattern != null ? pattern : {}, [key]: p };
2555
+ setFallbackState((s) => {
2556
+ var _a2, _b2;
2557
+ return {
2558
+ time: (_a2 = updatedPattern.time) != null ? _a2 : s.time,
2559
+ date: (_b2 = updatedPattern.date) != null ? _b2 : s.date
2560
+ };
2561
+ });
2562
+ onPatternChange(updatedPattern);
2563
+ },
2564
+ [onPatternChange, pattern]
2565
+ );
2566
+ const onToggleChange = useCallback10(
2567
+ (evnt) => {
2568
+ var _a2, _b2, _c, _d;
2569
+ const value = evnt.currentTarget.value;
2570
+ switch (value) {
2571
+ case "time":
2572
+ return onPatternChange({
2573
+ [value]: (_a2 = pattern[value]) != null ? _a2 : fallbackState[value]
2574
+ });
2575
+ case "date":
2576
+ return onPatternChange({
2577
+ [value]: (_b2 = pattern[value]) != null ? _b2 : fallbackState[value]
2578
+ });
2579
+ case "both":
2580
+ return onPatternChange({
2581
+ time: (_c = pattern.time) != null ? _c : fallbackState.time,
2582
+ date: (_d = pattern.date) != null ? _d : fallbackState.date
2583
+ });
2584
+ }
2585
+ },
2586
+ [onPatternChange, pattern, fallbackState]
2587
+ );
2588
+ return /* @__PURE__ */ jsxs8(Fragment, { children: [
2589
+ /* @__PURE__ */ jsxs8(FormField4, { labelPlacement: "top", children: [
2590
+ /* @__PURE__ */ jsx11(FormFieldLabel4, { children: "Display" }),
2591
+ /* @__PURE__ */ jsx11(
2592
+ ToggleButtonGroup,
2593
+ {
2594
+ className: "vuuToggleButtonGroup",
2595
+ onChange: onToggleChange,
2596
+ value: toggleValue,
2597
+ "data-variant": "primary",
2598
+ children: toggleValues.map((v) => /* @__PURE__ */ jsx11(ToggleButton, { value: v, children: v.toUpperCase() }, v))
2599
+ }
2600
+ )
2601
+ ] }),
2602
+ ["date", "time"].filter((v) => !!pattern[v]).map((v) => /* @__PURE__ */ jsxs8(FormField4, { labelPlacement: "top", children: [
2603
+ /* @__PURE__ */ jsx11(FormFieldLabel4, { children: `${labelByType[v]} pattern` }),
2604
+ /* @__PURE__ */ jsx11(
2605
+ Dropdown4,
2606
+ {
2607
+ onSelectionChange: onDropdownChange(v),
2608
+ selected: pattern[v],
2609
+ source: supportedDateTimePatterns[v],
2610
+ width: "100%"
2611
+ }
2612
+ )
2613
+ ] }, v))
2614
+ ] });
2615
+ };
2616
+ var labelByType = { date: "Date", time: "Time" };
2617
+ var toggleValues = ["date", "time", "both"];
2618
+ function getToggleValue(pattern) {
2619
+ return !pattern.time ? "date" : !pattern.date ? "time" : "both";
2620
+ }
2621
+
2622
+ // src/column-formatting-settings/LongTypeFormattingSettings.tsx
2623
+ import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
2624
+ var classBase10 = "vuuLongColumnFormattingSettings";
2625
+ var LongTypeFormattingSettings = (props) => {
2626
+ const { column, onChangeColumnType: onChangeType } = props;
2627
+ const type = isTypeDescriptor4(column.type) ? column.type.name : column.type;
2628
+ const handleToggleChange = useCallback11(
2629
+ (event) => {
2630
+ const value = event.currentTarget.value;
2631
+ onChangeType(value);
2632
+ },
2633
+ [onChangeType]
2634
+ );
2635
+ return /* @__PURE__ */ jsxs9("div", { className: classBase10, children: [
2636
+ /* @__PURE__ */ jsxs9(FormField5, { children: [
2637
+ /* @__PURE__ */ jsx12(FormFieldLabel5, { children: "Type inferred as" }),
2638
+ /* @__PURE__ */ jsx12(
2639
+ ToggleButtonGroup2,
2640
+ {
2641
+ className: "vuuToggleButtonGroup",
2642
+ onChange: handleToggleChange,
2643
+ value: type != null ? type : "number",
2644
+ children: toggleValues2.map((v) => /* @__PURE__ */ jsx12(ToggleButton2, { value: v, children: v.toUpperCase() }, v))
2645
+ }
2646
+ )
2647
+ ] }),
2648
+ isDateTimeColumn(column) ? /* @__PURE__ */ jsx12(DateTimeFormattingSettings, { ...props, column }) : /* @__PURE__ */ jsx12(BaseNumericFormattingSettings, { ...props })
2649
+ ] });
2650
+ };
2651
+ var toggleValues2 = ["number", "date/time"];
2652
+
2653
+ // src/column-formatting-settings/ColumnFormattingPanel.tsx
2654
+ import { jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
2655
+ var classBase11 = "vuuColumnFormattingPanel";
2656
+ var itemToString = (item) => {
2657
+ var _a;
2658
+ return (_a = item.label) != null ? _a : item.name;
2659
+ };
2660
+ var ColumnFormattingPanel = ({
2661
+ availableRenderers,
2662
+ className,
2663
+ column,
2664
+ onChangeFormatting,
2665
+ onChangeColumnType,
2666
+ onChangeRendering,
2667
+ ...htmlAttributes
2668
+ }) => {
2669
+ const formattingSettingsComponent = useMemo4(
2670
+ () => getFormattingSettingsComponent({
2671
+ column,
2672
+ onChangeFormatting,
2673
+ onChangeColumnType
2674
+ }),
2675
+ [column, onChangeColumnType, onChangeFormatting]
2676
+ );
2677
+ console.log({ formattingSettingsComponent });
2678
+ const ConfigEditor = useMemo4(() => {
2679
+ const { type } = column;
2680
+ if (isTypeDescriptor5(type) && isColumnTypeRenderer2(type.renderer)) {
2681
+ const cellRendererOptions = getCellRendererOptions(type.renderer.name);
2682
+ return getConfigurationEditor(cellRendererOptions == null ? void 0 : cellRendererOptions.configEditor);
2683
+ }
2684
+ return void 0;
2685
+ }, [column]);
2686
+ const selectedCellRenderer = useMemo4(() => {
2687
+ const { type } = column;
2688
+ const [defaultRenderer] = availableRenderers;
2689
+ const rendererName = isTypeDescriptor5(type) && isColumnTypeRenderer2(type.renderer) ? type.renderer.name : void 0;
2690
+ const configuredRenderer = availableRenderers.find(
2691
+ (renderer) => renderer.name === rendererName
2692
+ );
2693
+ return configuredRenderer != null ? configuredRenderer : defaultRenderer;
2694
+ }, [availableRenderers, column]);
2695
+ const handleChangeRenderer = useCallback12(
2696
+ (_, cellRendererDescriptor) => {
2697
+ const renderProps = {
2698
+ name: cellRendererDescriptor.name
2699
+ };
2700
+ onChangeRendering == null ? void 0 : onChangeRendering(renderProps);
2701
+ },
2702
+ [onChangeRendering]
2703
+ );
2704
+ const { serverDataType = "string" } = column;
2705
+ return /* @__PURE__ */ jsxs10("div", { ...htmlAttributes, className: `vuuColumnSettingsPanel-header`, children: [
2706
+ /* @__PURE__ */ jsx13("div", { children: "Formatting" }),
2707
+ /* @__PURE__ */ jsxs10(FormField6, { children: [
2708
+ /* @__PURE__ */ jsx13(FormFieldLabel6, { children: `Renderer (data type ${column.serverDataType})` }),
2709
+ /* @__PURE__ */ jsx13(
2710
+ Dropdown5,
2711
+ {
2712
+ className: cx5(`${classBase11}-renderer`),
2713
+ itemToString,
2714
+ onSelectionChange: handleChangeRenderer,
2715
+ selected: selectedCellRenderer,
2716
+ source: availableRenderers,
2717
+ width: "100%"
2718
+ }
2719
+ )
2720
+ ] }),
2721
+ /* @__PURE__ */ jsxs10(
2722
+ "div",
2723
+ {
2724
+ className: cx5(classBase11, className, `${classBase11}-${serverDataType}`),
2725
+ children: [
2726
+ formattingSettingsComponent,
2727
+ ConfigEditor ? /* @__PURE__ */ jsx13(
2728
+ ConfigEditor,
2729
+ {
2730
+ column,
2731
+ onChangeRendering
2732
+ }
2733
+ ) : null
2734
+ ]
2735
+ }
2736
+ )
2737
+ ] });
2738
+ };
2739
+ function getFormattingSettingsComponent(props) {
2740
+ const { column } = props;
2741
+ switch (column.serverDataType) {
2742
+ case "double":
2743
+ case "int":
2744
+ return /* @__PURE__ */ jsx13(BaseNumericFormattingSettings, { ...props });
2745
+ case "long":
2746
+ return /* @__PURE__ */ jsx13(LongTypeFormattingSettings, { ...props });
2747
+ default:
2748
+ return null;
2749
+ }
2750
+ }
2751
+
2752
+ // src/column-settings/ColumnNameLabel.tsx
2753
+ import cx6 from "clsx";
2754
+ import {
2755
+ getCalculatedColumnDetails as getCalculatedColumnDetails2,
2756
+ isCalculatedColumn
2757
+ } from "@vuu-ui/vuu-utils";
2758
+ import { jsx as jsx14, jsxs as jsxs11 } from "react/jsx-runtime";
2759
+ var classBase12 = "vuuColumnNameLabel";
2760
+ var ColumnNameLabel = ({ column, onClick }) => {
2761
+ if (isCalculatedColumn(column.name)) {
2762
+ const [name2, type, expression] = getCalculatedColumnDetails2(column);
2763
+ const displayName = name2 || "name";
2764
+ const displayExpression = "=expression";
2765
+ const nameClass = displayName === "name" ? `${classBase12}-placeholder` : void 0;
2766
+ const expressionClass = expression === "" ? `${classBase12}-placeholder` : void 0;
2767
+ return /* @__PURE__ */ jsxs11(
2768
+ "div",
2769
+ {
2770
+ className: cx6(classBase12, `${classBase12}-calculated`),
2771
+ onClick,
2772
+ children: [
2773
+ /* @__PURE__ */ jsx14("span", { className: nameClass, children: displayName }),
2774
+ /* @__PURE__ */ jsx14("span", { children: ":" }),
2775
+ /* @__PURE__ */ jsx14("span", { children: type || "string" }),
2776
+ /* @__PURE__ */ jsx14("span", { children: ":" }),
2777
+ /* @__PURE__ */ jsx14("span", { className: expressionClass, children: displayExpression }),
2778
+ /* @__PURE__ */ jsx14("span", { className: `${classBase12}-edit`, "data-icon": "edit" })
2779
+ ]
2780
+ }
2781
+ );
2782
+ } else {
2783
+ return /* @__PURE__ */ jsx14("div", { className: classBase12, children: column.name });
2784
+ }
2785
+ };
2786
+
2787
+ // src/column-settings/useColumnSettings.ts
2788
+ import {
2789
+ getRegisteredCellRenderers,
2790
+ isValidColumnAlignment,
2791
+ isValidPinLocation,
2792
+ setCalculatedColumnName as setCalculatedColumnName2,
2793
+ updateColumnRenderProps,
2794
+ updateColumnFormatting,
2795
+ updateColumnType,
2796
+ queryClosest
2797
+ } from "@vuu-ui/vuu-utils";
2798
+ import {
2799
+ useCallback as useCallback13,
2800
+ useEffect as useEffect3,
2801
+ useMemo as useMemo5,
2802
+ useRef as useRef7,
2803
+ useState as useState5
2804
+ } from "react";
2805
+ var integerCellRenderers = [
2806
+ {
2807
+ description: "Default formatter for columns with data type integer",
2808
+ label: "Default Renderer (int, long)",
2809
+ name: "default-int"
2810
+ }
2811
+ ];
2812
+ var doubleCellRenderers = [
2813
+ {
2814
+ description: "Default formatter for columns with data type double",
2815
+ label: "Default Renderer (double)",
2816
+ name: "default-double"
2817
+ }
2818
+ ];
2819
+ var stringCellRenderers = [
2820
+ {
2821
+ description: "Default formatter for columns with data type string",
2822
+ label: "Default Renderer (string)",
2823
+ name: "default-string"
2824
+ }
2825
+ ];
2826
+ var booleanCellRenderers = [];
2827
+ var getAvailableCellRenderers = (column) => {
2828
+ switch (column.serverDataType) {
2829
+ case "char":
2830
+ case "string":
2831
+ return stringCellRenderers.concat(getRegisteredCellRenderers("string"));
2832
+ case "int":
2833
+ case "long":
2834
+ return integerCellRenderers.concat(getRegisteredCellRenderers("int"));
2835
+ case "double":
2836
+ return doubleCellRenderers.concat(getRegisteredCellRenderers("double"));
2837
+ case "boolean":
2838
+ return booleanCellRenderers.concat(getRegisteredCellRenderers("boolean"));
2839
+ default:
2840
+ return stringCellRenderers;
2841
+ }
2842
+ };
2843
+ var getFieldName = (input) => {
2844
+ const saltFormField = input.closest(".saltFormField");
2845
+ if (saltFormField && saltFormField.dataset.field) {
2846
+ const {
2847
+ dataset: { field }
2848
+ } = saltFormField;
2849
+ return field;
2850
+ } else {
2851
+ throw Error("named form field not found");
2852
+ }
2853
+ };
2854
+ var getColumn = (columns, column) => {
2855
+ if (column.name === "::") {
2856
+ return column;
2857
+ } else {
2858
+ const col = columns.find((col2) => col2.name === column.name);
2859
+ if (col) {
2860
+ return col;
2861
+ }
2862
+ throw Error(`columns does not contain column ${name}`);
2863
+ }
2864
+ };
2865
+ var replaceColumn = (tableConfig, column) => ({
2866
+ ...tableConfig,
2867
+ columns: tableConfig.columns.map(
2868
+ (col) => col.name === column.name ? column : col
2869
+ )
2870
+ });
2871
+ var useColumnSettings = ({
2872
+ column: columnProp,
2873
+ onCancelCreateColumn,
2874
+ onConfigChange,
2875
+ onCreateCalculatedColumn,
2876
+ tableConfig
2877
+ }) => {
2878
+ const [column, setColumn] = useState5(
2879
+ getColumn(tableConfig.columns, columnProp)
2880
+ );
2881
+ const columnRef = useRef7(column);
2882
+ const [inEditMode, setEditMode] = useState5(column.name === "::");
2883
+ const handleEditCalculatedcolumn = useCallback13(() => {
2884
+ columnRef.current = column;
2885
+ setEditMode(true);
2886
+ }, [column]);
2887
+ useEffect3(() => {
2888
+ setColumn(columnProp);
2889
+ setEditMode(columnProp.name === "::");
2890
+ }, [columnProp]);
2891
+ const availableRenderers = useMemo5(() => {
2892
+ return getAvailableCellRenderers(column);
2893
+ }, [column]);
2894
+ const handleInputCommit = useCallback13(() => {
2895
+ onConfigChange(replaceColumn(tableConfig, column));
2896
+ }, [column, onConfigChange, tableConfig]);
2897
+ const handleChangeToggleButton = useCallback13(
2898
+ (evt) => {
2899
+ const button = queryClosest(evt.target, "button");
2900
+ if (button) {
2901
+ const fieldName = getFieldName(button);
2902
+ const { value } = button;
2903
+ switch (fieldName) {
2904
+ case "column-alignment":
2905
+ if (isValidColumnAlignment(value)) {
2906
+ const newColumn = {
2907
+ ...column,
2908
+ align: value || void 0
2909
+ };
2910
+ setColumn(newColumn);
2911
+ onConfigChange(replaceColumn(tableConfig, newColumn));
2912
+ }
2913
+ break;
2914
+ case "column-pin":
2915
+ if (isValidPinLocation(value)) {
2916
+ const newColumn = {
2917
+ ...column,
2918
+ pin: value || void 0
2919
+ };
2920
+ setColumn(newColumn);
2921
+ onConfigChange(replaceColumn(tableConfig, newColumn));
2922
+ break;
2923
+ }
2924
+ }
2925
+ }
2926
+ },
2927
+ [column, onConfigChange, tableConfig]
2928
+ );
2929
+ const handleChange = useCallback13((evt) => {
2930
+ const input = evt.target;
2931
+ const fieldName = getFieldName(input);
2932
+ const { value } = input;
2933
+ switch (fieldName) {
2934
+ case "column-label":
2935
+ setColumn((state) => ({ ...state, label: value }));
2936
+ break;
2937
+ case "column-name":
2938
+ setColumn((state) => setCalculatedColumnName2(state, value));
2939
+ break;
2940
+ case "column-width":
2941
+ setColumn((state) => ({ ...state, width: parseInt(value) }));
2942
+ break;
2943
+ }
2944
+ }, []);
2945
+ const handleChangeCalculatedColumnName = useCallback13((name2) => {
2946
+ setColumn((state) => ({ ...state, name: name2 }));
2947
+ }, []);
2948
+ const handleChangeFormatting = useCallback13(
2949
+ (formatting) => {
2950
+ const newColumn = updateColumnFormatting(column, formatting);
2951
+ setColumn(newColumn);
2952
+ onConfigChange(replaceColumn(tableConfig, newColumn));
2953
+ },
2954
+ [column, onConfigChange, tableConfig]
2955
+ );
2956
+ const handleChangeType = useCallback13(
2957
+ (type) => {
2958
+ const updatedColumn = updateColumnType(column, type);
2959
+ setColumn(updatedColumn);
2960
+ onConfigChange(replaceColumn(tableConfig, updatedColumn));
2961
+ },
2962
+ [column, onConfigChange, tableConfig]
2963
+ );
2964
+ const handleChangeServerDataType = useCallback13(
2965
+ (serverDataType) => {
2966
+ setColumn((col) => ({ ...col, serverDataType }));
2967
+ },
2968
+ []
2969
+ );
2970
+ const handleChangeRendering = useCallback13(
2971
+ (renderProps) => {
2972
+ if (renderProps) {
2973
+ const newColumn = updateColumnRenderProps(
2974
+ column,
2975
+ renderProps
2976
+ );
2977
+ setColumn(newColumn);
2978
+ onConfigChange(replaceColumn(tableConfig, newColumn));
2979
+ }
2980
+ },
2981
+ [column, onConfigChange, tableConfig]
2982
+ );
2983
+ const navigateColumn = useCallback13(
2984
+ ({ moveBy }) => {
2985
+ const { columns } = tableConfig;
2986
+ const index = columns.indexOf(column) + moveBy;
2987
+ const newColumn = columns[index];
2988
+ if (newColumn) {
2989
+ setColumn(newColumn);
2990
+ }
2991
+ },
2992
+ [column, tableConfig]
2993
+ );
2994
+ const navigateNextColumn = useCallback13(() => {
2995
+ navigateColumn({ moveBy: 1 });
2996
+ }, [navigateColumn]);
2997
+ const navigatePrevColumn = useCallback13(() => {
2998
+ navigateColumn({ moveBy: -1 });
2999
+ }, [navigateColumn]);
3000
+ const handleSaveCalculatedColumn = useCallback13(() => {
3001
+ onCreateCalculatedColumn(column);
3002
+ }, [column, onCreateCalculatedColumn]);
3003
+ const handleCancelEdit = useCallback13(() => {
3004
+ if (columnProp.name === "::") {
3005
+ onCancelCreateColumn();
3006
+ } else {
3007
+ if (columnRef.current !== void 0 && columnRef.current !== column) {
3008
+ setColumn(columnRef.current);
3009
+ }
3010
+ setEditMode(false);
3011
+ }
3012
+ }, [column, columnProp.name, onCancelCreateColumn]);
3013
+ return {
3014
+ availableRenderers,
3015
+ editCalculatedColumn: inEditMode,
3016
+ column,
3017
+ navigateNextColumn,
3018
+ navigatePrevColumn,
3019
+ onCancel: handleCancelEdit,
3020
+ onChange: handleChange,
3021
+ onChangeCalculatedColumnName: handleChangeCalculatedColumnName,
3022
+ onChangeFormatting: handleChangeFormatting,
3023
+ onChangeRendering: handleChangeRendering,
3024
+ onChangeServerDataType: handleChangeServerDataType,
3025
+ onChangeToggleButton: handleChangeToggleButton,
3026
+ onChangeType: handleChangeType,
3027
+ onEditCalculatedColumn: handleEditCalculatedcolumn,
3028
+ onInputCommit: handleInputCommit,
3029
+ onSave: handleSaveCalculatedColumn
3030
+ };
3031
+ };
3032
+
3033
+ // src/column-settings/ColumnSettingsPanel.tsx
3034
+ import { jsx as jsx15, jsxs as jsxs12 } from "react/jsx-runtime";
3035
+ var classBase13 = "vuuColumnSettingsPanel";
3036
+ var getColumnLabel2 = (column) => {
3037
+ const { name: name2, label } = column;
3038
+ if (isCalculatedColumn2(name2)) {
3039
+ return label != null ? label : getCalculatedColumnName2(column);
3040
+ } else {
3041
+ return label != null ? label : name2;
3042
+ }
3043
+ };
3044
+ var ColumnSettingsPanel = ({
3045
+ column: columnProp,
3046
+ onCancelCreateColumn,
3047
+ onConfigChange,
3048
+ onCreateCalculatedColumn,
3049
+ tableConfig,
3050
+ vuuTable
3051
+ }) => {
3052
+ const isNewCalculatedColumn = columnProp.name === "::";
3053
+ const {
3054
+ availableRenderers,
3055
+ editCalculatedColumn,
3056
+ column,
3057
+ navigateNextColumn,
3058
+ navigatePrevColumn,
3059
+ onCancel,
3060
+ onChange,
3061
+ onChangeCalculatedColumnName,
3062
+ onChangeFormatting,
3063
+ onChangeRendering,
3064
+ onChangeServerDataType,
3065
+ onChangeToggleButton,
3066
+ onChangeType,
3067
+ onEditCalculatedColumn,
3068
+ onInputCommit,
3069
+ onSave
3070
+ } = useColumnSettings({
3071
+ column: columnProp,
3072
+ onCancelCreateColumn,
3073
+ onConfigChange,
3074
+ onCreateCalculatedColumn,
3075
+ tableConfig
3076
+ });
3077
+ const {
3078
+ serverDataType,
3079
+ align = getDefaultAlignment(serverDataType),
3080
+ pin,
3081
+ width
3082
+ } = column;
3083
+ return /* @__PURE__ */ jsxs12(
3084
+ "div",
3085
+ {
3086
+ className: cx7(classBase13, {
3087
+ [`${classBase13}-editing`]: editCalculatedColumn
3088
+ }),
3089
+ children: [
3090
+ /* @__PURE__ */ jsx15("div", { className: `${classBase13}-header`, children: /* @__PURE__ */ jsx15(ColumnNameLabel, { column, onClick: onEditCalculatedColumn }) }),
3091
+ editCalculatedColumn ? /* @__PURE__ */ jsx15(
3092
+ ColumnExpressionPanel,
3093
+ {
3094
+ column,
3095
+ onChangeName: onChangeCalculatedColumnName,
3096
+ onChangeServerDataType,
3097
+ tableConfig,
3098
+ vuuTable
3099
+ }
3100
+ ) : null,
3101
+ /* @__PURE__ */ jsxs12(FormField7, { "data-field": "column-label", children: [
3102
+ /* @__PURE__ */ jsx15(FormFieldLabel7, { children: "Column Label" }),
3103
+ /* @__PURE__ */ jsx15(
3104
+ VuuInput,
3105
+ {
3106
+ className: "vuuInput",
3107
+ onChange,
3108
+ onCommit: onInputCommit,
3109
+ value: getColumnLabel2(column)
3110
+ }
3111
+ )
3112
+ ] }),
3113
+ /* @__PURE__ */ jsxs12(FormField7, { "data-field": "column-width", children: [
3114
+ /* @__PURE__ */ jsx15(FormFieldLabel7, { children: "Column Width" }),
3115
+ /* @__PURE__ */ jsx15(
3116
+ VuuInput,
3117
+ {
3118
+ className: "vuuInput",
3119
+ onChange,
3120
+ value: width,
3121
+ onCommit: onInputCommit
3122
+ }
3123
+ )
3124
+ ] }),
3125
+ /* @__PURE__ */ jsxs12(FormField7, { "data-field": "column-alignment", children: [
3126
+ /* @__PURE__ */ jsx15(FormFieldLabel7, { children: "Alignment" }),
3127
+ /* @__PURE__ */ jsxs12(ToggleButtonGroup3, { onChange: onChangeToggleButton, value: align, children: [
3128
+ /* @__PURE__ */ jsx15(ToggleButton3, { value: "left", children: /* @__PURE__ */ jsx15(Icon, { name: "align-left", size: 16 }) }),
3129
+ /* @__PURE__ */ jsx15(ToggleButton3, { value: "right", children: /* @__PURE__ */ jsx15(Icon, { name: "align-right", size: 16 }) })
3130
+ ] })
3131
+ ] }),
3132
+ /* @__PURE__ */ jsxs12(FormField7, { "data-field": "column-pin", children: [
3133
+ /* @__PURE__ */ jsx15(FormFieldLabel7, { children: "Pin Column" }),
3134
+ /* @__PURE__ */ jsxs12(ToggleButtonGroup3, { onChange: onChangeToggleButton, value: pin != null ? pin : "", children: [
3135
+ /* @__PURE__ */ jsx15(ToggleButton3, { value: "", children: /* @__PURE__ */ jsx15(Icon, { name: "cross-circle", size: 16 }) }),
3136
+ /* @__PURE__ */ jsx15(ToggleButton3, { value: "left", children: /* @__PURE__ */ jsx15(Icon, { name: "pin-left", size: 16 }) }),
3137
+ /* @__PURE__ */ jsx15(ToggleButton3, { value: "floating", children: /* @__PURE__ */ jsx15(Icon, { name: "pin-float", size: 16 }) }),
3138
+ /* @__PURE__ */ jsx15(ToggleButton3, { value: "right", children: /* @__PURE__ */ jsx15(Icon, { name: "pin-right", size: 16 }) })
3139
+ ] })
3140
+ ] }),
3141
+ /* @__PURE__ */ jsx15(
3142
+ ColumnFormattingPanel,
3143
+ {
3144
+ availableRenderers,
3145
+ column,
3146
+ onChangeFormatting,
3147
+ onChangeRendering,
3148
+ onChangeColumnType: onChangeType
3149
+ }
3150
+ ),
3151
+ editCalculatedColumn ? /* @__PURE__ */ jsxs12("div", { className: "vuuColumnSettingsPanel-buttonBar", "data-align": "right", children: [
3152
+ /* @__PURE__ */ jsx15(
3153
+ Button,
3154
+ {
3155
+ className: `${classBase13}-buttonCancel`,
3156
+ onClick: onCancel,
3157
+ tabIndex: -1,
3158
+ children: "cancel"
3159
+ }
3160
+ ),
3161
+ /* @__PURE__ */ jsx15(
3162
+ Button,
3163
+ {
3164
+ className: `${classBase13}-buttonSave`,
3165
+ onClick: onSave,
3166
+ variant: "cta",
3167
+ children: "save"
3168
+ }
3169
+ )
3170
+ ] }) : /* @__PURE__ */ jsxs12(
3171
+ "div",
3172
+ {
3173
+ className: `${classBase13}-buttonBar`,
3174
+ "data-align": isNewCalculatedColumn ? "right" : void 0,
3175
+ children: [
3176
+ /* @__PURE__ */ jsx15(
3177
+ Button,
3178
+ {
3179
+ className: `${classBase13}-buttonNavPrev`,
3180
+ variant: "secondary",
3181
+ "data-icon": "arrow-left",
3182
+ onClick: navigatePrevColumn,
3183
+ children: "PREVIOUS"
3184
+ }
3185
+ ),
3186
+ /* @__PURE__ */ jsx15(
3187
+ Button,
3188
+ {
3189
+ className: `${classBase13}-buttonNavNext`,
3190
+ variant: "secondary",
3191
+ "data-icon": "arrow-right",
3192
+ onClick: navigateNextColumn,
3193
+ children: "NEXT"
3194
+ }
3195
+ )
3196
+ ]
3197
+ }
3198
+ )
3199
+ ]
3200
+ }
3201
+ );
3202
+ };
3203
+
3204
+ // src/datasource-stats/DatasourceStats.tsx
3205
+ import cx8 from "clsx";
3206
+ import { useEffect as useEffect4, useState as useState6 } from "react";
3207
+ import { jsx as jsx16, jsxs as jsxs13 } from "react/jsx-runtime";
3208
+ var classBase14 = "vuuDatasourceStats";
3209
+ var numberFormatter = new Intl.NumberFormat();
3210
+ var DataSourceStats = ({
3211
+ className: classNameProp,
3212
+ dataSource
3213
+ }) => {
3214
+ const [range, setRange] = useState6(dataSource.range);
3215
+ const [size, setSize] = useState6(dataSource.size);
3216
+ useEffect4(() => {
3217
+ setSize(dataSource.size);
3218
+ dataSource.on("resize", setSize);
3219
+ dataSource.on("range", setRange);
3220
+ return () => {
3221
+ dataSource.removeListener("resize", setSize);
3222
+ dataSource.removeListener("range", setRange);
3223
+ };
3224
+ }, [dataSource]);
3225
+ const className = cx8(classBase14, classNameProp);
3226
+ const from = numberFormatter.format(range.from + 1);
3227
+ const to = numberFormatter.format(Math.min(range.to, size));
3228
+ const value = numberFormatter.format(size);
3229
+ return /* @__PURE__ */ jsxs13("div", { className, children: [
3230
+ /* @__PURE__ */ jsx16("span", { className: `${classBase14}-label`, children: "Row count" }),
3231
+ /* @__PURE__ */ jsx16("span", { className: `${classBase14}-range`, children: from }),
3232
+ /* @__PURE__ */ jsx16("span", { children: "-" }),
3233
+ /* @__PURE__ */ jsx16("span", { className: `${classBase14}-range`, children: to }),
3234
+ /* @__PURE__ */ jsx16("span", { children: "of" }),
3235
+ /* @__PURE__ */ jsx16("span", { className: `${classBase14}-size`, children: value })
3236
+ ] });
3237
+ };
3238
+
3239
+ // src/table-settings/TableSettingsPanel.tsx
3240
+ import {
3241
+ Button as Button2,
3242
+ FormField as FormField8,
3243
+ FormFieldLabel as FormFieldLabel8,
3244
+ ToggleButton as ToggleButton4,
3245
+ ToggleButtonGroup as ToggleButtonGroup4
3246
+ } from "@salt-ds/core";
3247
+
3248
+ // src/table-settings/useTableSettings.ts
3249
+ import { updateTableConfig } from "@vuu-ui/vuu-table";
3250
+ import {
3251
+ addColumnToSubscribedColumns,
3252
+ queryClosest as queryClosest2,
3253
+ isCalculatedColumn as isCalculatedColumn3,
3254
+ moveItem,
3255
+ subscribedOnly,
3256
+ useLayoutEffectSkipFirst
3257
+ } from "@vuu-ui/vuu-utils";
3258
+ import {
3259
+ useCallback as useCallback14,
3260
+ useMemo as useMemo6,
3261
+ useState as useState7
3262
+ } from "react";
3263
+ var sortOrderFromAvailableColumns = (availableColumns, columns) => {
3264
+ const sortedColumns = [];
3265
+ for (const { name: name2 } of availableColumns) {
3266
+ const column = columns.find((col) => col.name === name2);
3267
+ if (column) {
3268
+ sortedColumns.push(column);
3269
+ }
3270
+ }
3271
+ return sortedColumns;
3272
+ };
3273
+ var buildColumnItems = (availableColumns, configuredColumns) => {
3274
+ return availableColumns.map(({ name: name2, serverDataType }) => {
3275
+ const configuredColumn = configuredColumns.find((col) => col.name === name2);
3276
+ return {
3277
+ hidden: configuredColumn == null ? void 0 : configuredColumn.hidden,
3278
+ isCalculated: isCalculatedColumn3(name2),
3279
+ label: configuredColumn == null ? void 0 : configuredColumn.label,
3280
+ name: name2,
3281
+ serverDataType,
3282
+ subscribed: configuredColumn !== void 0
3283
+ };
3284
+ });
3285
+ };
3286
+ var useTableSettings = ({
3287
+ availableColumns: availableColumnsProp,
3288
+ onConfigChange,
3289
+ onDataSourceConfigChange,
3290
+ tableConfig: tableConfigProp
3291
+ }) => {
3292
+ const [{ availableColumns, tableConfig }, setColumnState] = useState7({
3293
+ availableColumns: availableColumnsProp,
3294
+ tableConfig: tableConfigProp
3295
+ });
3296
+ const columnItems = useMemo6(
3297
+ () => buildColumnItems(availableColumns, tableConfig.columns),
3298
+ [availableColumns, tableConfig.columns]
3299
+ );
3300
+ const handleMoveListItem = useCallback14(
3301
+ (fromIndex, toIndex) => {
3302
+ setColumnState((state) => {
3303
+ const newAvailableColumns = moveItem(
3304
+ state.availableColumns,
3305
+ fromIndex,
3306
+ toIndex
3307
+ );
3308
+ const newColumns = sortOrderFromAvailableColumns(
3309
+ newAvailableColumns,
3310
+ tableConfig.columns
3311
+ );
3312
+ return {
3313
+ availableColumns: newAvailableColumns,
3314
+ tableConfig: {
3315
+ ...state.tableConfig,
3316
+ columns: newColumns
3317
+ }
3318
+ };
3319
+ });
3320
+ },
3321
+ [tableConfig.columns]
3322
+ );
3323
+ const handleColumnChange = useCallback14(
3324
+ (name2, property, value) => {
3325
+ const columnItem = columnItems.find((col) => col.name === name2);
3326
+ if (property === "subscribed") {
3327
+ if (columnItem == null ? void 0 : columnItem.subscribed) {
3328
+ const subscribedColumns = tableConfig.columns.filter((col) => col.name !== name2).map((col) => col.name);
3329
+ setColumnState((state) => ({
3330
+ ...state,
3331
+ tableConfig: {
3332
+ ...tableConfig,
3333
+ columns: tableConfig.columns.filter(
3334
+ subscribedOnly(subscribedColumns)
3335
+ )
3336
+ }
3337
+ }));
3338
+ onDataSourceConfigChange({
3339
+ columns: subscribedColumns
3340
+ });
3341
+ } else {
3342
+ const newConfig = {
3343
+ ...tableConfig,
3344
+ columns: addColumnToSubscribedColumns(
3345
+ tableConfig.columns,
3346
+ availableColumns,
3347
+ name2
3348
+ )
3349
+ };
3350
+ setColumnState((state) => ({
3351
+ ...state,
3352
+ tableConfig: newConfig
3353
+ }));
3354
+ const subscribedColumns = newConfig.columns.map((col) => col.name);
3355
+ onDataSourceConfigChange({
3356
+ columns: subscribedColumns
3357
+ });
3358
+ }
3359
+ } else if (columnItem == null ? void 0 : columnItem.subscribed) {
3360
+ const column = tableConfig.columns.find((col) => col.name === name2);
3361
+ if (column) {
3362
+ const newConfig = updateTableConfig(tableConfig, {
3363
+ type: "column-prop",
3364
+ property,
3365
+ column,
3366
+ value
3367
+ });
3368
+ setColumnState((state) => ({
3369
+ ...state,
3370
+ tableConfig: newConfig
3371
+ }));
3372
+ }
3373
+ }
3374
+ },
3375
+ [availableColumns, columnItems, onDataSourceConfigChange, tableConfig]
3376
+ );
3377
+ const handleChangeColumnLabels = useCallback14((evt) => {
3378
+ const button = queryClosest2(evt.target, "button");
3379
+ if (button) {
3380
+ const value = parseInt(button.value);
3381
+ const columnFormatHeader = value === 0 ? void 0 : value === 1 ? "capitalize" : "uppercase";
3382
+ setColumnState((state) => ({
3383
+ ...state,
3384
+ tableConfig: {
3385
+ ...state.tableConfig,
3386
+ columnFormatHeader
3387
+ }
3388
+ }));
3389
+ }
3390
+ }, []);
3391
+ const handleChangeTableAttribute = useCallback14(
3392
+ (evt) => {
3393
+ const button = queryClosest2(evt.target, "button");
3394
+ const { ariaPressed, value } = button;
3395
+ console.log({ ariaPressed, value, button });
3396
+ setColumnState((state) => ({
3397
+ ...state,
3398
+ tableConfig: {
3399
+ ...state.tableConfig,
3400
+ [value]: ariaPressed !== "true"
3401
+ }
3402
+ }));
3403
+ },
3404
+ []
3405
+ );
3406
+ const handleCommitColumnWidth = useCallback14((_, value) => {
3407
+ const columnDefaultWidth = parseInt(value);
3408
+ if (!isNaN(columnDefaultWidth)) {
3409
+ setColumnState((state) => ({
3410
+ ...state,
3411
+ tableConfig: {
3412
+ ...state.tableConfig,
3413
+ columnDefaultWidth
3414
+ }
3415
+ }));
3416
+ }
3417
+ console.log({ value });
3418
+ }, []);
3419
+ useLayoutEffectSkipFirst(() => {
3420
+ onConfigChange == null ? void 0 : onConfigChange(tableConfig);
3421
+ }, [onConfigChange, tableConfig]);
3422
+ const columnLabelsValue = tableConfig.columnFormatHeader === void 0 ? 0 : tableConfig.columnFormatHeader === "capitalize" ? 1 : 2;
3423
+ return {
3424
+ columnItems,
3425
+ columnLabelsValue,
3426
+ onChangeColumnLabels: handleChangeColumnLabels,
3427
+ onChangeTableAttribute: handleChangeTableAttribute,
3428
+ onColumnChange: handleColumnChange,
3429
+ onCommitColumnWidth: handleCommitColumnWidth,
3430
+ onMoveListItem: handleMoveListItem,
3431
+ tableConfig
3432
+ };
3433
+ };
3434
+
3435
+ // src/table-settings/TableSettingsPanel.tsx
3436
+ import { Icon as Icon2 } from "@vuu-ui/vuu-ui-controls";
3437
+ import { VuuInput as VuuInput2 } from "@vuu-ui/vuu-ui-controls";
3438
+ import { jsx as jsx17, jsxs as jsxs14 } from "react/jsx-runtime";
3439
+ var classBase15 = "vuuTableSettingsPanel";
3440
+ var TableSettingsPanel = ({
3441
+ availableColumns,
3442
+ onAddCalculatedColumn,
3443
+ onConfigChange,
3444
+ onDataSourceConfigChange,
3445
+ onNavigateToColumn,
3446
+ tableConfig: tableConfigProp
3447
+ }) => {
3448
+ var _a, _b, _c;
3449
+ const {
3450
+ columnItems,
3451
+ columnLabelsValue,
3452
+ onChangeColumnLabels,
3453
+ onChangeTableAttribute,
3454
+ onColumnChange,
3455
+ onCommitColumnWidth,
3456
+ onMoveListItem,
3457
+ tableConfig
3458
+ } = useTableSettings({
3459
+ availableColumns,
3460
+ onConfigChange,
3461
+ onDataSourceConfigChange,
3462
+ tableConfig: tableConfigProp
3463
+ });
3464
+ return /* @__PURE__ */ jsxs14("div", { className: classBase15, children: [
3465
+ /* @__PURE__ */ jsxs14(FormField8, { children: [
3466
+ /* @__PURE__ */ jsx17(FormFieldLabel8, { children: "Column Labels" }),
3467
+ /* @__PURE__ */ jsxs14(
3468
+ ToggleButtonGroup4,
3469
+ {
3470
+ className: "vuuToggleButtonGroup",
3471
+ onChange: onChangeColumnLabels,
3472
+ value: columnLabelsValue,
3473
+ children: [
3474
+ /* @__PURE__ */ jsx17(ToggleButton4, { className: "vuuIconToggleButton", value: 0, children: /* @__PURE__ */ jsx17(Icon2, { name: "text-strikethrough", size: 48 }) }),
3475
+ /* @__PURE__ */ jsx17(ToggleButton4, { className: "vuuIconToggleButton", value: 1, children: /* @__PURE__ */ jsx17(Icon2, { name: "text-Tt", size: 48 }) }),
3476
+ /* @__PURE__ */ jsx17(ToggleButton4, { className: "vuuIconToggleButton", value: 2, children: /* @__PURE__ */ jsx17(Icon2, { name: "text-T", size: 48 }) })
3477
+ ]
3478
+ }
3479
+ )
3480
+ ] }),
3481
+ /* @__PURE__ */ jsxs14(FormField8, { children: [
3482
+ /* @__PURE__ */ jsx17(FormFieldLabel8, { children: "Grid separators" }),
3483
+ /* @__PURE__ */ jsxs14("div", { className: "saltToggleButtonGroup vuuStateButtonGroup saltToggleButtonGroup-horizontal", children: [
3484
+ /* @__PURE__ */ jsx17(
3485
+ ToggleButton4,
3486
+ {
3487
+ selected: (_a = tableConfig.zebraStripes) != null ? _a : false,
3488
+ onChange: onChangeTableAttribute,
3489
+ value: "zebraStripes",
3490
+ children: /* @__PURE__ */ jsx17(Icon2, { name: "row-striping", size: 16 })
3491
+ }
3492
+ ),
3493
+ /* @__PURE__ */ jsx17(
3494
+ ToggleButton4,
3495
+ {
3496
+ selected: (_b = tableConfig.rowSeparators) != null ? _b : false,
3497
+ onChange: onChangeTableAttribute,
3498
+ value: "rowSeparators",
3499
+ children: /* @__PURE__ */ jsx17(Icon2, { name: "row-lines", size: 16 })
3500
+ }
3501
+ ),
3502
+ /* @__PURE__ */ jsx17(
3503
+ ToggleButton4,
3504
+ {
3505
+ selected: (_c = tableConfig.columnSeparators) != null ? _c : false,
3506
+ onChange: onChangeTableAttribute,
3507
+ value: "columnSeparators",
3508
+ children: /* @__PURE__ */ jsx17(Icon2, { name: "col-lines", size: 16 })
3509
+ }
3510
+ )
3511
+ ] })
3512
+ ] }),
3513
+ /* @__PURE__ */ jsxs14(FormField8, { children: [
3514
+ /* @__PURE__ */ jsx17(FormFieldLabel8, { children: "Default Column Width" }),
3515
+ /* @__PURE__ */ jsx17(VuuInput2, { className: "vuuInput", onCommit: onCommitColumnWidth })
3516
+ ] }),
3517
+ /* @__PURE__ */ jsx17(
3518
+ ColumnList,
3519
+ {
3520
+ columnItems,
3521
+ onChange: onColumnChange,
3522
+ onMoveListItem,
3523
+ onNavigateToColumn
3524
+ }
3525
+ ),
3526
+ /* @__PURE__ */ jsxs14("div", { className: `${classBase15}-calculatedButtonbar`, children: [
3527
+ /* @__PURE__ */ jsx17(Button2, { "data-icon": "plus", onClick: onAddCalculatedColumn }),
3528
+ /* @__PURE__ */ jsx17("span", { className: `${classBase15}-calculatedLabel`, children: "Add calculated column" })
3529
+ ] })
3530
+ ] });
3531
+ };
3532
+ export {
3533
+ BackgroundCell,
3534
+ BackgroundCellConfigurationEditor,
3535
+ BaseNumericFormattingSettings,
3536
+ CaseValidator,
3537
+ ColumnExpressionInput,
3538
+ ColumnExpressionPanel,
3539
+ ColumnFormattingPanel,
3540
+ ColumnList,
3541
+ ColumnNamedTerms,
3542
+ ColumnSettingsPanel,
3543
+ DataSourceStats,
3544
+ DateTimeFormattingSettings,
3545
+ DropdownCell,
3546
+ LookupCell,
3547
+ PatternValidator,
3548
+ PctProgressCell,
3549
+ TableSettingsPanel,
3550
+ columnExpressionLanguageSupport,
3551
+ isCompleteExpression,
3552
+ isCompleteRelationalExpression,
3553
+ lastNamedChild,
3554
+ useColumnExpressionEditor,
3555
+ useColumnExpressionSuggestionProvider,
3556
+ useTableSettings,
3557
+ walkTree
3558
+ };
2
3559
  //# sourceMappingURL=index.js.map