@buildocsdev/sdk 1.1.13 → 1.1.14

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.
@@ -0,0 +1 @@
1
+ import {a,b as b$1}from'./chunk-5VSWNFWW.js';import {a as a$1}from'./chunk-POE6K4NQ.js';import {U,T,k}from'./chunk-KW32CT2P.js';import'./chunk-U4T4ACDE.js';import {b}from'./chunk-LBMVBVXW.js';import {q,a as a$2}from'./chunk-3QKKOFXC.js';import {c,d,p,m,N}from'./chunk-AR42AC7J.js';import'./chunk-5TBO732O.js';import {lazy,memo,useRef,useState,useEffect}from'react';import {withTranslation,useTranslation}from'react-i18next';import {useLocation}from'react-router-dom';import {LocalizationProvider,DateTimePicker,DatePicker}from'@mui/x-date-pickers';import Ft from'@mui/material/TextField';import X from'react-dom/client';import Et from'@mui/material/Tooltip';import Zt from'@mui/material/Box';import te from'@mui/material/Button';import Pt from'@mui/material/MenuList';import Nt from'@mui/material/MenuItem';import At from'@mui/material/Paper';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {nanoid}from'@reduxjs/toolkit';import ne from'react-dom/server';import'react-tabulator/lib/styles.css';import'react-tabulator/css/bootstrap/tabulator_bootstrap.min.css';import'react-tabulator/lib/css/bootstrap/tabulator_bootstrap.min.css';var $t=({cellElement:u,cell:t,actionHandler:o})=>{let {t:e}=useTranslation();t.getRow().getPosition();let i=u.getBoundingClientRect(),m=i.bottom+window.scrollY,a=i.left+window.scrollX;return jsx(At,{style:{position:"absolute",top:m+"px",left:a+"px",zIndex:2e3,minWidth:"150px"},children:jsx(Pt,{children:jsxs(Nt,{onClick:()=>o(t),children:[jsx(N,{style:{fontSize:"1em",marginRight:"0.5em"}})," ",e("Delete")]})})})},Ct=$t;var L=class u{static convertToVariables(t){let o={};for(let e in t)if(t.hasOwnProperty(e)&&(typeof t[e]=="string"||typeof t[e]=="number")){let n=Number(t[e]);isNaN(n)||(o[e]=n);}return o}static formulaHasFieldName(t,o){if(t.operands){for(let e of t.operands)if(typeof e=="string"&&e===o||typeof e=="object"&&u.formulaHasFieldName(e,o))return true}return false}static parseExpression(t){t=t.replace(/\s+/g,"");let o=/\(([^()]+)\)/;for(;o.test(t);)t=t.replace(o,(i,m)=>{let a=u.parseExpression(m.trim());return `@${JSON.stringify(a)}`});let n=u.tokenize(t).map(i=>i.startsWith("@")?JSON.parse(i.substring(1)):i);return u.parseTokens(n)}static tokenize(t){let o=[],e="",n=false,i=0;for(let m=0;m<t.length;m++){let a=t[m];if(a==="@"&&t[m+1]==="{"&&(e&&(o.push(e),e=""),n=true,i=0),n){e+=a,a==="{"?i++:a==="}"&&(i--,i===0&&(o.push(e),e="",n=false));continue}if("+-*/()".includes(a)){e&&(o.push(e),e=""),o.push(a);continue}e+=a;}return e&&o.push(e),o}static parseTokens(t){if(t.length===1){let a=t[0];if(typeof a=="string"){let s=parseFloat(a);return isNaN(s)?{operands:[a]}:{value:s}}if(typeof a=="object")return a}let o={"+":1,"-":1,"*":2,"/":2},e=1/0,n=-1;if(t.forEach((a,s)=>{if(typeof a=="string"&&a in o){let d=a;o[d]<=e&&(e=o[d],n=s);}}),n===-1)throw new Error(`Invalid expression: no operator found in tokens ${JSON.stringify(t)}`);let i=t.slice(0,n),m=t.slice(n+1);if(i.length===0||m.length===0)throw new Error(`Invalid expression: operator without operands in tokens ${JSON.stringify(t)}`);return {operator:t[n],operands:[u.parseTokens(i),u.parseTokens(m)]}}static evaluateFormula(t,o){if(t.value!==void 0)return t.value;let{operator:e,operands:n}=t;if(!e||!n||n.length!==2)throw new Error("Invalid parsed formula");let[i,m]=n.map(a=>{if(typeof a=="object"&&a.operands&&a.operands.length===1&&(a=a.operands[0]),typeof a=="string")return o[a]||0;if(typeof a=="number")return a;if(typeof a=="object")return u.evaluateFormula(a,o);throw new Error(`Unsupported operand type: ${JSON.stringify(a)}`)});switch(e){case "+":return i+m;case "-":return i-m;case "*":return i*m;case "/":return i/m;default:throw new Error(`Unsupported operator: ${e}`)}}static convertValuesToStrings(t){return t.map(o=>{let e={};for(let[n,i]of Object.entries(o))e[n]=i===void 0?"":String(i);return e})}static buildDependencyGraph(t){let o={};for(let e in t)if(Object.prototype.hasOwnProperty.call(t,e)){let n=t[e],i=[],m=a=>{a.forEach(s=>{typeof s=="string"?i.push(s):typeof s=="object"&&"operands"in s&&s.operands&&m(s.operands);});};n.operands&&m(n.operands),o[e]=i;}return o}static topologicalSort(t){let o=new Set,e=[],n=i=>{o.has(i)||(o.add(i),(t[i]||[]).forEach(n),e.push(i));};return Object.keys(t).forEach(n),e}};var re=ne.renderToStaticMarkup(jsx(c,{}));if(typeof window!="undefined"&&window.ResizeObserver){let u=window.ResizeObserver;window.ResizeObserver=class extends u{constructor(t){let o;super((e,n)=>{cancelAnimationFrame(o),o=requestAnimationFrame(()=>t(e,n));});}};}var oe=lazy(()=>import('react-tabulator').then(u=>({default:u.ReactTabulator}))),ae=u=>{var o;if(!u.properties.folders)return null;var t=(o=u.context.params.folderData)==null?void 0:o.captions;return t==null||t.length===0?null:(t=t.slice(1),jsx("span",{style:{display:"flex",alignItems:"center"},children:t.map((e,n)=>jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[e,n<t.length-1&&jsx(d,{style:{margin:"0 8px",fontSize:"0.6rem",color:"#666"}})]},n))}))},ie=(u,t,o,e,n,i,m,a)=>{let s=document.createElement("div"),d=null,f=u.getValue(),D=f?a$1(f):null,w=null,E=false,R=()=>{let r=null;if(E&&w!==null){if(w.trim()===""){e(),d&&d.unmount();return}if(r=a$1(w),!r.isValid()){let h=["DD.MM.YYYY","YYYY-MM-DD","MM/DD/YYYY","DD/MM/YYYY","M/D/YYYY","D/M/YYYY"];for(let F of h)if(r=a$1(w,F),r.isValid())break}(!r||!r.isValid())&&(r=D);}else r=D;r&&r.isValid()?(m.current=a,o(r.format("YYYY-MM-DD"))):f?o(f):e(),d&&d.unmount();},y=r=>{D=r;},b=r=>{D=r,E=false,R();},H=r=>{w=r.target.value,E=true;},x=jsx("div",{onMouseDown:r=>{r.stopPropagation();},children:jsx(LocalizationProvider,{dateAdapter:a$2,adapterLocale:i,children:jsx(DatePicker,{value:a$1(f),onAccept:b,onChange:y,slots:{actionBar:()=>null,textField:r=>jsx(Ft,{...r,onChange:h=>{r.onChange&&r.onChange(h),H(h);},sx:{"& .MuiOutlinedInput-root":{fontSize:"13px",border:"none"},"& .MuiOutlinedInput-notchedOutline":{border:"none"},"& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}}})}})})});return t(()=>{d||(d=X.createRoot(s),d.render(x));}),s.addEventListener("blur",r=>{setTimeout(()=>{s.contains(document.activeElement)||R();},200);}),s.addEventListener("keydown",r=>{if(r.key==="Tab"||r.key==="Enter"){r.preventDefault();let h=s.querySelector('input[type="text"]');h&&E&&(w=h.value),R();}}),s},le=(u,t,o,e,n,i,m,a)=>{let s=document.createElement("div"),d=null,f=u.getValue(),D=f?a$1(f):null,w=null,E=false,R=()=>{let r=null;if(E&&w!==null){if(w.trim()===""){e(),d&&d.unmount();return}if(r=a$1(w),!r.isValid()){let h=["DD.MM.YYYY HH:mm:ss","DD.MM.YYYY HH:mm","YYYY-MM-DD HH:mm:ss","YYYY-MM-DD HH:mm","YYYY-MM-DDTHH:mm:ss","MM/DD/YYYY HH:mm:ss","MM/DD/YYYY HH:mm","DD/MM/YYYY HH:mm:ss","DD/MM/YYYY HH:mm"];for(let F of h)if(r=a$1(w,F),r.isValid())break}if(!r||!r.isValid()){let h=["HH:mm:ss","HH:mm"];for(let F of h){let k=a$1(w,F,true);if(k.isValid()){r=(f?a$1(f):a$1()).hour(k.hour()).minute(k.minute()).second(k.second());break}}}(!r||!r.isValid())&&(r=D);}else r=D;r&&r.isValid()?(m.current=a,o(r.format("YYYY-MM-DDTHH:mm:ss"))):f?o(f):e(),d&&d.unmount();},y=r=>{D=r;},b=r=>{D=r,E=false,R();},H=r=>{w=r.target.value,E=true;},x=jsx("div",{onMouseDown:r=>{r.stopPropagation();},children:jsx(LocalizationProvider,{dateAdapter:a$2,adapterLocale:i,children:jsx(DateTimePicker,{value:f?a$1(f):null,onAccept:b,onChange:y,ampm:false,slots:{actionBar:()=>null,textField:r=>jsx(Ft,{...r,onChange:h=>{r.onChange&&r.onChange(h),H(h);},sx:{"& .MuiOutlinedInput-root":{fontSize:"13px",border:"none"},"& .MuiOutlinedInput-notchedOutline":{border:"none"},"& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}}})}})})});return t(()=>{d||(d=X.createRoot(s),d.render(x));}),s.addEventListener("blur",r=>{setTimeout(()=>{s.contains(document.activeElement)||R();},200);}),s.addEventListener("keydown",r=>{if(r.key==="Tab"||r.key==="Enter"){r.preventDefault();let h=s.querySelector('input[type="text"]');h&&E&&(w=h.value),R();}}),s},se=(u,t,o,e)=>{var m;if(!u.alloweditrow||u.readonly===true)return;let n=(m=t.item_columntype)!=null?m:"freetext";t.item_columntype||(t.item_isdate===true?n="date":t.item_isdatetime===true?n="datetime":t.item_ischeckbox===true?n="checkbox":t.item_isprice===true?n="price":n="freetext");return n==="datetime"?(a,s,d,f,D)=>le(a,s,d,f,D,o.current,e,u.name):n==="date"?(a,s,d,f,D)=>ie(a,s,d,f,D,o.current,e,u.name):t.item_editor==="number"||n==="price"||n==="number"?"number":t.item_editor==="checkbox"||n==="checkbox"?"tickCross":"input"},ue=(u,t,o,e,n)=>{let i=u.getElement();i.style.backgroundColor="#f0f0f0",i.style.color="#555",i.style.pointerEvents="none";},Yt=(u,t,o,e,n,i)=>{var R;let m=(y,b,H)=>{if(!(H==="price"))return `<div class="tabulator-text">${y||""}</div>`;let x=e.item_format==="fixed-locale",h=x&&e.item_fixedlocale||n.current||void 0,F=b!==void 0&&b[e.item_inputfield]?b[e.item_inputfield]:e.item_currency,k$1=e.item_format==="locale"?k(n.current):void 0,A=x?k(e.item_fixedlocale||""):void 0,W=String(F!=null?F:""),K=W&&W.trim()!==""?W.trim():k$1!=null?k$1:A;try{let P,Q=e.item_currencydisplay||(x?"symbol":"");return K&&Q!==""?P=new Intl.NumberFormat(h,{style:"currency",currency:K,currencyDisplay:Q,minimumFractionDigits:2,maximumFractionDigits:2}).format(y||0):P=new Intl.NumberFormat(h,{style:"decimal",minimumFractionDigits:2,maximumFractionDigits:2}).format(y||0),`<div class="tabulator-text">${P}</div>`}catch(P){return `<div class="tabulator-text">${(y||0).toFixed(2)}</div>`}};if(!t.alloweditrow)return;let a=(R=e.item_columntype)!=null?R:"freetext";e.item_columntype||(e.item_isdate===true?a="date":e.item_isdatetime===true?a="datetime":e.item_ischeckbox===true?a="checkbox":e.item_isprice===true||e.item_format==="locale"||e.item_format==="fixed-locale"?a="price":a="freetext");let s=e.item_readonly||i==="totals",d=a==="price",f=a==="number",D=a==="date",w=a==="datetime",E=a==="checkbox";return s?y=>{ue(y,t,e,n.current);let b=y.getValue();return i==="totals"&&(!e.item_bottomcalc||b==="")?"":m(b,o,a)}:w?y=>me(y,n.current)||"":D?y=>ce(y,n.current)||"":E?"tickCross":d?y=>{let b=y.getValue();return m(b,o,a)}:f?y=>{let b=y.getValue();if(b==null||b==="")return '<div class="tabulator-text"></div>';let H=parseFloat(b);return isNaN(H)?`<div class="tabulator-text">${b}</div>`:`<div class="tabulator-text">${H.toLocaleString(n.current||void 0,{minimumFractionDigits:0,maximumFractionDigits:10})}</div>`}:y=>`<div class="tabulator-text">${y.getValue()||""}</div>`},ce=(u,t)=>{let o=u.getValue();if(!o)return "";try{let e=a$1(o);return t&&b$1(t)?e.locale(t).format("L"):(t&&!b$1(t)&&a(t).catch(n=>{}),e.format("L"))}catch(e){return a$1(o).format("YYYY-MM-DD")}},me=(u,t)=>{let o=u.getValue();if(!o)return "";try{let e=a$1(o);return t&&b$1(t)?e.locale(t).format("L LT"):(t&&!b$1(t)&&a(t).catch(n=>{}),e.format("L LT"))}catch(e){return a$1(o).format("YYYY-MM-DD HH:mm")}},de=(u,t)=>{if(u.alloweditrow&&t.item_editor==="checkbox")return {allowEmpty:true,crossElement:false,tickElement:re}},kt=withTranslation()(memo(function(t){var mt;let{runFormEvent:o,viewPort:e}=b(),n=useRef(null),i=useRef(null),m$1=useRef(null),[a$1,s]=useState(false),[d,f]=useState([]),[D,w]=useState([]),[E,R]=useState([]),[y,b$1]=useState(0),{t:H,i18n:z}=useTranslation(),x=(mt=z==null?void 0:z.language)==null?void 0:mt.substring(0,2),r=useRef(x!=null?x:""),h=useLocation(),[F,k]=useState(false),A=useRef(t.context.formData||{});useEffect(()=>{x&&a(x).catch(c=>{});},[x]),useEffect(()=>{if(r.current=x!=null?x:"",n.current)try{n.current.redraw(!0);}catch(c){}},[x]),useEffect(()=>{let c=()=>{n.current&&!e.isMobileDevice&&n.current.redraw();};return window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c);}},[]),useEffect(()=>{A.current=t.context.formData||{};let c=t.context.formData?t.context.formData[t.properties.name]:null;f(c?JSON.parse(c):[]);},[t.context.formData]),useEffect(()=>{var c;if(F&&n.current!=null){let M=(c=n.current)==null?void 0:c.getData();A.current&&(A.current[t.properties.name]=JSON.stringify(M)),k(false);}},[F]),useEffect(()=>((async()=>{var c,M;t.context.enableEventHandlers?await o({pluginCode:t.context.params.pluginCode,formCode:t.context.params.formCode,guid:t.context.params.guid,projectGuid:t.context.params.pGuid,pGuid:t.context.params.pGuid,widgetContext:JSON.stringify({referer:h.pathname,parentWidgetId:It,hasParentForm:T.hasParentForm(),originator:(c=t.context.params)==null?void 0:c.originator,parent:t.context.params,folderData:(M=t.context.params)==null?void 0:M.folderData}),widgetEvent:U.onTableEditDataLoad,widgetName:t.properties.name.toLowerCase(),formData:t.context.formData}).then(C=>{if(C.meta.requestStatus==="fulfilled"){let p={...C.payload};if(Object.keys(p).length===0)return;if(!p.data){s(true);return}let v=p.data[t.properties.name];p.widgetData.length===0&&v!==void 0&&v!==null&&v.length>0?f(JSON.parse(v)):p.widgetData.length>0&&f(Object.values(p.widgetData)),s(true);}}):s(true);})(),()=>{if(n.current){try{typeof n.current.destroy=="function"&&n.current.destroy();}catch(c){}n.current=null;}}),[]);let W=c=>{var M,C;if(n.current){let p=c.getRow().getData()._id,Y=((M=n.current)==null?void 0:M.getData()).filter(_=>_._id!==p);(C=n.current)==null||C.setData(Y),k(true);}},K=(c,M)=>{if(P(t.properties))return;let C=document.querySelector(".menu-container");C&&C.remove();let p=document.createElement("div");p.className="menu-container",document.body.appendChild(p);let v=X.createRoot(p);v.render(jsx(Ct,{cellElement:c,cell:M,actionHandler:_=>{v.unmount(),p.remove(),document.removeEventListener("click",Y),W(_);}}));let Y=_=>{p.contains(_.target)||(v.unmount(),p.remove(),document.removeEventListener("click",Y));};document.addEventListener("click",Y);};useEffect(()=>{let c;(()=>{c=t.methodProvider.findWidgetItem(t.id);let C=[];c.item.properties.datasource.columns&&(c.item.properties.datasource.columns||[]).map(l=>{C[l[1]]=l[0];});let p=[];(c.item._children||[]).map(({properties:l})=>{l.item_name.toString()!==""&&l.item_increment&&p.push(l.item_name);}),R(p);let v=[];v.push({title:"",field:"remove",headerHozAlign:"center",hozAlign:"center",vertAlign:"middle",width:"1",formatter:l=>{let O=document.createElement("div");return O.style.cursor="pointer",O.style.color="#C0C0C0",O.style.fontSize="0.9rem",O.style.textAlign="center",X.createRoot(O).render(jsx(m,{})),O.addEventListener("click",B=>{B.stopPropagation();let $=l.getElement();K($,l);}),O}});let Y={},_={},I={},dt=100,ft=false;c.item._children.forEach(({properties:l})=>{dt+=parseInt(l.item_minsize,10)||0,l.item_bottomcalc&&(ft=true);}),b$1(dt),(c.item._children||[]).map(({properties:l})=>{var O,nt;if(l.item_name.toString()!==""){let B=l.item_title.split("!!!"),$=B.length>1&&B[0]||null,rt=B.length>1?B[1]:l.item_title;l.item_formula!=null&&l.item_formula.trim()!==""&&(_[l.item_name]=l.item_formula,I[l.item_name]=L.parseExpression(_[l.item_name]));let gt={cellEdited:S=>{let G=S.getField();k(true);let ot=(V,N)=>{let Z=L.buildDependencyGraph(I),at=L.topologicalSort(Z);at.forEach(tt=>{let yt=I[tt];if(yt){let jt=N.getData(),zt=L.evaluateFormula(yt,L.convertToVariables(jt));V!==tt&&(N.update({[tt]:parseFloat(zt.toFixed(2)).toFixed(2)}));}});};for(let V in I)if(Object.prototype.hasOwnProperty.call(I,V)){let N=I[V];if(N&&typeof N=="object"&&L.formulaHasFieldName(N,G)){let Z=S.getRow();if(Z){let at=S.getRow().getData(),it=L.evaluateFormula(N,L.convertToVariables(at));Z.update({[V]:parseFloat(it.toFixed(2)).toFixed(2)});}}}ot(G,S.getRow());},editor:se(t.properties,l,r,m$1),editable:!t.properties.readonly&&!l.item_readonly,field:l.item_name,formatter:Yt(n,t.properties,t.context.formData,l,r,"body"),formatterParams:de(t.properties,l),title:rt,titleFormatter:l.item_displaytooltip?()=>{let S=document.createElement("div");return X.createRoot(S).render(jsx(Et,{title:rt,arrow:true,children:jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",display:"block"},children:rt})})),S}:void 0,cssClass:!t.properties.readonly&&!l.item_readonly?"tabulator-ellipsis":"tabulator-readonly",minWidth:parseInt(l.item_minsize,10)||void 0,headerHozAlign:(O=l.style.item_textalign)!=null?O:"center",hozAlign:(nt=l.style.item_ctextalign)!=null?nt:"center",vertAlign:"middle",bottomCalc:S=>l.item_bottomcalc?S.reduce((G,ot)=>{let V=parseFloat(String(ot).replace(",","."));return G+(isNaN(V)?0:V)},0):"",bottomCalcFormatter:ft?Yt(n,t.properties,t.context.formData,l,r,"totals"):void 0,headerSort:l.item_enablesorting};$?(Y[$]||(Y[$]=[]),Y[$].push(gt)):v.push(gt);}}),Object.entries(Y).forEach(([l,O])=>{v.push({title:l,columns:O,cssClass:t.properties.readonly?"tabulator-readonly":"tabulator-ellipsis"});}),w(v),s(true);})();},[t.properties,t.context.params.guid]),useEffect(()=>{n.current&&(n.current.setColumns(D),n.current.redraw());},[D]);let P=c=>!!(c.readonly&&!c.ignorereadonly);function Q(c){let M=C=>C.reduce((p,v)=>{var Y,_;if(v.field&&(p[v.field]="",E.includes(v.field))){let I=(_=(Y=n.current)==null?void 0:Y.getDataCount())!=null?_:0;I!==void 0&&(p[v.field]=String(I+1));}return v.columns&&Array.isArray(v.columns)&&Object.assign(p,M(v.columns)),p},{});return {_id:nanoid(11),...M(c)}}let Ot=()=>jsx(Et,{title:H("Add New"),children:jsx("span",{children:jsx(te,{disabled:P(t.properties),color:"primary",style:{marginRight:"5px"},onClick:()=>{n.current&&n.current.addRow(Q(D));},variant:"outlined",children:jsx(p,{})})})}),{hideaddbutton:_t,folders:Lt,visible:Ht}=t.properties,{tabId:It}=t;if(!Ht)return null;if(!a$1)return jsx(q,{text:"",size:40,textVariant:"body2",variant:void 0});let St={minHeight:t.properties.height,movableRows:false,movableColumns:false,rowHeight:40,layout:"fitColumns"},Vt=()=>{document.querySelectorAll(".tabulator-header-contents > br").forEach(C=>C.remove());document.querySelectorAll(".tabulator-footer");};return jsxs(Fragment,{children:[Lt&&jsx("div",{style:{paddingBottom:"0.8rem",fontSize:"0.85rem",color:"#666",marginLeft:"0.2rem"},children:ae(t)}),jsxs("div",{style:{padding:10,paddingBottom:0,overflowX:"auto"},ref:i,children:[jsx(Zt,{sx:{paddingBottom:1,paddingTop:1,paddingRight:1},children:!_t&&jsx(Ot,{})}),jsx(oe,{onRef:c=>n.current=c==null?void 0:c.current,data:d,columns:D,options:St,events:{tableBuilt:Vt},className:"tabulator",style:{marginBottom:0,minWidth:y+"px"}})]})]})}));kt.displayName="_Tabulator";var Ze=kt;export{Ze as TabulatorTable};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildocsdev/sdk",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/"
6
6
  },
@@ -1 +0,0 @@
1
- import {a,b as b$1}from'./chunk-5VSWNFWW.js';import {a as a$1}from'./chunk-POE6K4NQ.js';import {U,T,k}from'./chunk-KW32CT2P.js';import'./chunk-U4T4ACDE.js';import {b}from'./chunk-LBMVBVXW.js';import {q,a as a$2}from'./chunk-3QKKOFXC.js';import {c,d,p,m,N}from'./chunk-AR42AC7J.js';import'./chunk-5TBO732O.js';import {lazy,memo,useRef,useState,useEffect}from'react';import {withTranslation,useTranslation}from'react-i18next';import {useLocation}from'react-router-dom';import {LocalizationProvider,DateTimePicker,DatePicker}from'@mui/x-date-pickers';import Fe from'@mui/material/TextField';import X from'react-dom/client';import Ee from'@mui/material/Tooltip';import Ze from'@mui/material/Box';import et from'@mui/material/Button';import Pe from'@mui/material/MenuList';import Ne from'@mui/material/MenuItem';import Ae from'@mui/material/Paper';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {nanoid}from'@reduxjs/toolkit';import nt from'react-dom/server';import'react-tabulator/lib/styles.css';import'react-tabulator/css/bootstrap/tabulator_bootstrap.min.css';import'react-tabulator/lib/css/bootstrap/tabulator_bootstrap.min.css';var $e=({cellElement:s,cell:e,actionHandler:o})=>{let {t}=useTranslation();e.getRow().getPosition();let i=s.getBoundingClientRect(),m=i.bottom+window.scrollY,a=i.left+window.scrollX;return jsx(Ae,{style:{position:"absolute",top:m+"px",left:a+"px",zIndex:2e3,minWidth:"150px"},children:jsx(Pe,{children:jsxs(Ne,{onClick:()=>o(e),children:[jsx(N,{style:{fontSize:"1em",marginRight:"0.5em"}})," ",t("Delete")]})})})},Ce=$e;var L=class s{static convertToVariables(e){let o={};for(let t in e)if(e.hasOwnProperty(t)&&(typeof e[t]=="string"||typeof e[t]=="number")){let n=Number(e[t]);isNaN(n)||(o[t]=n);}return o}static formulaHasFieldName(e,o){if(e.operands){for(let t of e.operands)if(typeof t=="string"&&t===o||typeof t=="object"&&s.formulaHasFieldName(t,o))return true}return false}static parseExpression(e){e=e.replace(/\s+/g,"");let o=/\(([^()]+)\)/;for(;o.test(e);)e=e.replace(o,(i,m)=>{let a=s.parseExpression(m.trim());return `@${JSON.stringify(a)}`});let n=s.tokenize(e).map(i=>i.startsWith("@")?JSON.parse(i.substring(1)):i);return s.parseTokens(n)}static tokenize(e){let o=[],t="",n=false,i=0;for(let m=0;m<e.length;m++){let a=e[m];if(a==="@"&&e[m+1]==="{"&&(t&&(o.push(t),t=""),n=true,i=0),n){t+=a,a==="{"?i++:a==="}"&&(i--,i===0&&(o.push(t),t="",n=false));continue}if("+-*/()".includes(a)){t&&(o.push(t),t=""),o.push(a);continue}t+=a;}return t&&o.push(t),o}static parseTokens(e){if(e.length===1){let a=e[0];if(typeof a=="string"){let u=parseFloat(a);return isNaN(u)?{operands:[a]}:{value:u}}if(typeof a=="object")return a}let o={"+":1,"-":1,"*":2,"/":2},t=1/0,n=-1;if(e.forEach((a,u)=>{if(typeof a=="string"&&a in o){let d=a;o[d]<=t&&(t=o[d],n=u);}}),n===-1)throw new Error(`Invalid expression: no operator found in tokens ${JSON.stringify(e)}`);let i=e.slice(0,n),m=e.slice(n+1);if(i.length===0||m.length===0)throw new Error(`Invalid expression: operator without operands in tokens ${JSON.stringify(e)}`);return {operator:e[n],operands:[s.parseTokens(i),s.parseTokens(m)]}}static evaluateFormula(e,o){if(e.value!==void 0)return e.value;let{operator:t,operands:n}=e;if(!t||!n||n.length!==2)throw new Error("Invalid parsed formula");let[i,m]=n.map(a=>{if(typeof a=="object"&&a.operands&&a.operands.length===1&&(a=a.operands[0]),typeof a=="string")return o[a]||0;if(typeof a=="number")return a;if(typeof a=="object")return s.evaluateFormula(a,o);throw new Error(`Unsupported operand type: ${JSON.stringify(a)}`)});switch(t){case "+":return i+m;case "-":return i-m;case "*":return i*m;case "/":return i/m;default:throw new Error(`Unsupported operator: ${t}`)}}static convertValuesToStrings(e){return e.map(o=>{let t={};for(let[n,i]of Object.entries(o))t[n]=i===void 0?"":String(i);return t})}static buildDependencyGraph(e){let o={};for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)){let n=e[t],i=[],m=a=>{a.forEach(u=>{typeof u=="string"?i.push(u):typeof u=="object"&&"operands"in u&&u.operands&&m(u.operands);});};n.operands&&m(n.operands),o[t]=i;}return o}static topologicalSort(e){let o=new Set,t=[],n=i=>{o.has(i)||(o.add(i),(e[i]||[]).forEach(n),t.push(i));};return Object.keys(e).forEach(n),t}};var rt=nt.renderToStaticMarkup(jsx(c,{}));if(typeof window!="undefined"&&window.ResizeObserver){let s=window.ResizeObserver;window.ResizeObserver=class extends s{constructor(e){let o;super((t,n)=>{cancelAnimationFrame(o),o=requestAnimationFrame(()=>e(t,n));});}};}var ot=lazy(()=>import('react-tabulator').then(s=>({default:s.ReactTabulator}))),at=s=>{var o;if(!s.properties.folders)return null;var e=(o=s.context.params.folderData)==null?void 0:o.captions;return e==null||e.length===0?null:(e=e.slice(1),jsx("span",{style:{display:"flex",alignItems:"center"},children:e.map((t,n)=>jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[t,n<e.length-1&&jsx(d,{style:{margin:"0 8px",fontSize:"0.6rem",color:"#666"}})]},n))}))},it=(s,e,o,t,n,i,m,a)=>{let u=document.createElement("div"),d=null,f=s.getValue(),D=f?a$1(f):null,w=null,E=false,R=()=>{let r=null;if(E&&w!==null){if(w.trim()===""){t(),d&&d.unmount();return}if(r=a$1(w),!r.isValid()){let p=["DD.MM.YYYY","YYYY-MM-DD","MM/DD/YYYY","DD/MM/YYYY","M/D/YYYY","D/M/YYYY"];for(let F of p)if(r=a$1(w,F),r.isValid())break}(!r||!r.isValid())&&(r=D);}else r=D;r&&r.isValid()?(m.current=a,o(r.format("YYYY-MM-DD"))):f?o(f):t(),d&&d.unmount();},y=r=>{D=r;},b=r=>{D=r,E=false,R();},H=r=>{w=r.target.value,E=true;},x=jsx("div",{onMouseDown:r=>{r.stopPropagation();},children:jsx(LocalizationProvider,{dateAdapter:a$2,adapterLocale:i,children:jsx(DatePicker,{value:a$1(f),onAccept:b,onChange:y,slots:{actionBar:()=>null,textField:r=>jsx(Fe,{...r,onChange:p=>{r.onChange&&r.onChange(p),H(p);},sx:{"& .MuiOutlinedInput-root":{fontSize:"13px",border:"none"},"& .MuiOutlinedInput-notchedOutline":{border:"none"},"& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}}})}})})});return e(()=>{d||(d=X.createRoot(u),d.render(x));}),u.addEventListener("blur",r=>{setTimeout(()=>{u.contains(document.activeElement)||R();},200);}),u.addEventListener("keydown",r=>{if(r.key==="Tab"||r.key==="Enter"){r.preventDefault();let p=u.querySelector('input[type="text"]');p&&E&&(w=p.value),R();}}),u},lt=(s,e,o,t,n,i,m,a)=>{let u=document.createElement("div"),d=null,f=s.getValue(),D=f?a$1(f):null,w=null,E=false,R=()=>{let r=null;if(E&&w!==null){if(w.trim()===""){t(),d&&d.unmount();return}if(r=a$1(w),!r.isValid()){let p=["DD.MM.YYYY HH:mm:ss","DD.MM.YYYY HH:mm","YYYY-MM-DD HH:mm:ss","YYYY-MM-DD HH:mm","YYYY-MM-DDTHH:mm:ss","MM/DD/YYYY HH:mm:ss","MM/DD/YYYY HH:mm","DD/MM/YYYY HH:mm:ss","DD/MM/YYYY HH:mm"];for(let F of p)if(r=a$1(w,F),r.isValid())break}if(!r||!r.isValid()){let p=["HH:mm:ss","HH:mm"];for(let F of p){let k=a$1(w,F,true);if(k.isValid()){r=(f?a$1(f):a$1()).hour(k.hour()).minute(k.minute()).second(k.second());break}}}(!r||!r.isValid())&&(r=D);}else r=D;r&&r.isValid()?(m.current=a,o(r.format("YYYY-MM-DDTHH:mm:ss"))):f?o(f):t(),d&&d.unmount();},y=r=>{D=r;},b=r=>{D=r,E=false,R();},H=r=>{w=r.target.value,E=true;},x=jsx("div",{onMouseDown:r=>{r.stopPropagation();},children:jsx(LocalizationProvider,{dateAdapter:a$2,adapterLocale:i,children:jsx(DateTimePicker,{value:f?a$1(f):null,onAccept:b,onChange:y,ampm:false,slots:{actionBar:()=>null,textField:r=>jsx(Fe,{...r,onChange:p=>{r.onChange&&r.onChange(p),H(p);},sx:{"& .MuiOutlinedInput-root":{fontSize:"13px",border:"none"},"& .MuiOutlinedInput-notchedOutline":{border:"none"},"& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline":{border:"none"}}})}})})});return e(()=>{d||(d=X.createRoot(u),d.render(x));}),u.addEventListener("blur",r=>{setTimeout(()=>{u.contains(document.activeElement)||R();},200);}),u.addEventListener("keydown",r=>{if(r.key==="Tab"||r.key==="Enter"){r.preventDefault();let p=u.querySelector('input[type="text"]');p&&E&&(w=p.value),R();}}),u},st=(s,e,o,t)=>{var m;if(!s.alloweditrow||s.readonly===true)return;let n=(m=e.item_columntype)!=null?m:"freetext";e.item_columntype||(e.item_isdate===true?n="date":e.item_isdatetime===true?n="datetime":e.item_ischeckbox===true?n="checkbox":e.item_isprice===true?n="price":n="freetext");return n==="datetime"?(a,u,d,f,D)=>lt(a,u,d,f,D,o.current,t,s.name):n==="date"?(a,u,d,f,D)=>it(a,u,d,f,D,o.current,t,s.name):e.item_editor==="number"||n==="price"||n==="number"?"number":e.item_editor==="checkbox"||n==="checkbox"?"tickCross":"input"},ut=(s,e,o,t,n)=>{let i=s.getElement();i.style.backgroundColor="#f0f0f0",i.style.color="#555",i.style.pointerEvents="none";},Ye=(s,e,o,t,n,i)=>{var R;let m=(y,b,H)=>{if(!(H==="price"))return `<div class="tabulator-text">${y||""}</div>`;let x=t.item_format==="fixed-locale",p=x&&t.item_fixedlocale||n.current||void 0,F=b!==void 0&&b[t.item_inputfield]?b[t.item_inputfield]:t.item_currency,k$1=t.item_format==="locale"?k(n.current):void 0,A=x?k(t.item_fixedlocale||""):void 0,W=String(F!=null?F:""),K=W&&W.trim()!==""?W.trim():k$1!=null?k$1:A;try{let P,Q=t.item_currencydisplay||(x?"symbol":"");return K&&Q!==""?P=new Intl.NumberFormat(p,{style:"currency",currency:K,currencyDisplay:Q,minimumFractionDigits:2,maximumFractionDigits:2}).format(y||0):P=new Intl.NumberFormat(p,{style:"decimal",minimumFractionDigits:2,maximumFractionDigits:2}).format(y||0),`<div class="tabulator-text">${P}</div>`}catch(P){return `<div class="tabulator-text">${(y||0).toFixed(2)}</div>`}};if(!e.alloweditrow)return;let a=(R=t.item_columntype)!=null?R:"freetext";t.item_columntype||(t.item_isdate===true?a="date":t.item_isdatetime===true?a="datetime":t.item_ischeckbox===true?a="checkbox":t.item_isprice===true||t.item_format==="locale"||t.item_format==="fixed-locale"?a="price":a="freetext");let u=t.item_readonly||i==="totals",d=a==="price",f=a==="number",D=a==="date",w=a==="datetime",E=a==="checkbox";return u?y=>{ut(y,e,t,n.current);let b=y.getValue();return i==="totals"&&(!t.item_bottomcalc||b==="")?"":m(b,o,a)}:w?y=>mt(y,n.current)||"":D?y=>ct(y,n.current)||"":E?"tickCross":d?y=>{let b=y.getValue();return m(b,o,a)}:f?y=>{let b=y.getValue();if(b==null||b==="")return '<div class="tabulator-text"></div>';let H=parseFloat(b);return isNaN(H)?`<div class="tabulator-text">${b}</div>`:`<div class="tabulator-text">${H.toLocaleString(n.current||void 0,{minimumFractionDigits:0,maximumFractionDigits:10})}</div>`}:y=>`<div class="tabulator-text">${y.getValue()||""}</div>`},ct=(s,e)=>{let o=s.getValue();if(!o)return "";try{let t=a$1(o);return e&&b$1(e)?t.locale(e).format("L"):(e&&!b$1(e)&&a(e).catch(n=>{}),t.format("L"))}catch(t){return a$1(o).format("YYYY-MM-DD")}},mt=(s,e)=>{let o=s.getValue();if(!o)return "";try{let t=a$1(o);return e&&b$1(e)?t.locale(e).format("L LT"):(e&&!b$1(e)&&a(e).catch(n=>{}),t.format("L LT"))}catch(t){return a$1(o).format("YYYY-MM-DD HH:mm")}},dt=(s,e)=>{if(s.alloweditrow&&e.item_editor==="checkbox")return {allowEmpty:true,crossElement:false,tickElement:rt}},ke=withTranslation()(memo(function(e){var me;let{runFormEvent:o,viewPort:t}=b(),n=useRef(null),i=useRef(null),m$1=useRef(null),[a$1,u]=useState(false),[d,f]=useState([]),[D,w]=useState([]),[E,R]=useState([]),[y,b$1]=useState(0),{t:H,i18n:z}=useTranslation(),x=(me=z==null?void 0:z.language)==null?void 0:me.substring(0,2),r=useRef(x!=null?x:""),p$1=useLocation(),[F,k]=useState(false),A=useRef(e.context.formData||{});useEffect(()=>{x&&a(x).catch(c=>{});},[x]),useEffect(()=>{if(r.current=x!=null?x:"",n.current)try{n.current.redraw(!0);}catch(c){}},[x]),useEffect(()=>{let c=()=>{n.current&&!t.isMobileDevice&&n.current.redraw();};return window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c);}},[]),useEffect(()=>{A.current=e.context.formData||{};let c=e.context.formData?e.context.formData[e.properties.name]:null;f(c?JSON.parse(c):[]);},[e.context.formData]),useEffect(()=>{var c;if(F&&n.current!=null){let M=(c=n.current)==null?void 0:c.getData();A.current&&(A.current[e.properties.name]=JSON.stringify(M)),k(false);}},[F]),useEffect(()=>((async()=>{var c,M;e.context.enableEventHandlers?await o({pluginCode:e.context.params.pluginCode,formCode:e.context.params.formCode,guid:e.context.params.guid,projectGuid:e.context.params.pGuid,pGuid:e.context.params.pGuid,widgetContext:JSON.stringify({referer:p$1.pathname,parentWidgetId:Ie,hasParentForm:T.hasParentForm(),originator:(c=e.context.params)==null?void 0:c.originator,parent:e.context.params,folderData:(M=e.context.params)==null?void 0:M.folderData}),widgetEvent:U.onTableEditDataLoad,widgetName:e.properties.name.toLowerCase(),formData:e.context.formData}).then(C=>{if(C.meta.requestStatus==="fulfilled"){let h={...C.payload};if(Object.keys(h).length===0)return;let v=h.data[e.properties.name];h.widgetData.length===0&&v!==void 0&&v!==null&&v.length>0?f(JSON.parse(v)):h.widgetData.length>0&&f(Object.values(h.widgetData)),u(true);}}):u(true);})(),()=>{if(n.current){try{typeof n.current.destroy=="function"&&n.current.destroy();}catch(c){}n.current=null;}}),[]);let W=c=>{var M,C;if(n.current){let h=c.getRow().getData()._id,Y=((M=n.current)==null?void 0:M.getData()).filter(_=>_._id!==h);(C=n.current)==null||C.setData(Y),k(true);}},K=(c,M)=>{if(P(e.properties))return;let C=document.querySelector(".menu-container");C&&C.remove();let h=document.createElement("div");h.className="menu-container",document.body.appendChild(h);let v=X.createRoot(h);v.render(jsx(Ce,{cellElement:c,cell:M,actionHandler:_=>{v.unmount(),h.remove(),document.removeEventListener("click",Y),W(_);}}));let Y=_=>{h.contains(_.target)||(v.unmount(),h.remove(),document.removeEventListener("click",Y));};document.addEventListener("click",Y);};useEffect(()=>{let c;(()=>{c=e.methodProvider.findWidgetItem(e.id);let C=[];c.item.properties.datasource.columns&&(c.item.properties.datasource.columns||[]).map(l=>{C[l[1]]=l[0];});let h=[];(c.item._children||[]).map(({properties:l})=>{l.item_name.toString()!==""&&l.item_increment&&h.push(l.item_name);}),R(h);let v=[];v.push({title:"",field:"remove",headerHozAlign:"center",hozAlign:"center",vertAlign:"middle",width:"1",formatter:l=>{let O=document.createElement("div");return O.style.cursor="pointer",O.style.color="#C0C0C0",O.style.fontSize="0.9rem",O.style.textAlign="center",X.createRoot(O).render(jsx(m,{})),O.addEventListener("click",B=>{B.stopPropagation();let $=l.getElement();K($,l);}),O}});let Y={},_={},I={},de=100,fe=false;c.item._children.forEach(({properties:l})=>{de+=parseInt(l.item_minsize,10)||0,l.item_bottomcalc&&(fe=true);}),b$1(de),(c.item._children||[]).map(({properties:l})=>{var O,ne;if(l.item_name.toString()!==""){let B=l.item_title.split("!!!"),$=B.length>1&&B[0]||null,re=B.length>1?B[1]:l.item_title;l.item_formula!=null&&l.item_formula.trim()!==""&&(_[l.item_name]=l.item_formula,I[l.item_name]=L.parseExpression(_[l.item_name]));let ge={cellEdited:S=>{let G=S.getField();k(true);let oe=(V,N)=>{let Z=L.buildDependencyGraph(I),ae=L.topologicalSort(Z);ae.forEach(ee=>{let ye=I[ee];if(ye){let je=N.getData(),ze=L.evaluateFormula(ye,L.convertToVariables(je));V!==ee&&(N.update({[ee]:parseFloat(ze.toFixed(2)).toFixed(2)}));}});};for(let V in I)if(Object.prototype.hasOwnProperty.call(I,V)){let N=I[V];if(N&&typeof N=="object"&&L.formulaHasFieldName(N,G)){let Z=S.getRow();if(Z){let ae=S.getRow().getData(),ie=L.evaluateFormula(N,L.convertToVariables(ae));Z.update({[V]:parseFloat(ie.toFixed(2)).toFixed(2)});}}}oe(G,S.getRow());},editor:st(e.properties,l,r,m$1),editable:!e.properties.readonly&&!l.item_readonly,field:l.item_name,formatter:Ye(n,e.properties,e.context.formData,l,r,"body"),formatterParams:dt(e.properties,l),title:re,titleFormatter:l.item_displaytooltip?()=>{let S=document.createElement("div");return X.createRoot(S).render(jsx(Ee,{title:re,arrow:true,children:jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",display:"block"},children:re})})),S}:void 0,cssClass:!e.properties.readonly&&!l.item_readonly?"tabulator-ellipsis":"tabulator-readonly",minWidth:parseInt(l.item_minsize,10)||void 0,headerHozAlign:(O=l.style.item_textalign)!=null?O:"center",hozAlign:(ne=l.style.item_ctextalign)!=null?ne:"center",vertAlign:"middle",bottomCalc:S=>l.item_bottomcalc?S.reduce((G,oe)=>{let V=parseFloat(String(oe).replace(",","."));return G+(isNaN(V)?0:V)},0):"",bottomCalcFormatter:fe?Ye(n,e.properties,e.context.formData,l,r,"totals"):void 0,headerSort:l.item_enablesorting};$?(Y[$]||(Y[$]=[]),Y[$].push(ge)):v.push(ge);}}),Object.entries(Y).forEach(([l,O])=>{v.push({title:l,columns:O,cssClass:e.properties.readonly?"tabulator-readonly":"tabulator-ellipsis"});}),w(v),u(true);})();},[e.properties,e.context.params.guid]),useEffect(()=>{n.current&&(n.current.setColumns(D),n.current.redraw());},[D]);let P=c=>!!(c.readonly&&!c.ignorereadonly);function Q(c){let M=C=>C.reduce((h,v)=>{var Y,_;if(v.field&&(h[v.field]="",E.includes(v.field))){let I=(_=(Y=n.current)==null?void 0:Y.getDataCount())!=null?_:0;I!==void 0&&(h[v.field]=String(I+1));}return v.columns&&Array.isArray(v.columns)&&Object.assign(h,M(v.columns)),h},{});return {_id:nanoid(11),...M(c)}}let Oe=()=>jsx(Ee,{title:H("Add New"),children:jsx("span",{children:jsx(et,{disabled:P(e.properties),color:"primary",style:{marginRight:"5px"},onClick:()=>{n.current&&n.current.addRow(Q(D));},variant:"outlined",children:jsx(p,{})})})}),{hideaddbutton:_e,folders:Le,visible:He}=e.properties,{tabId:Ie}=e;if(!He)return null;if(!a$1)return jsx(q,{text:"",size:40,textVariant:"body2",variant:void 0});let Se={minHeight:e.properties.height,movableRows:false,movableColumns:false,rowHeight:40,layout:"fitColumns"},Ve=()=>{document.querySelectorAll(".tabulator-header-contents > br").forEach(C=>C.remove());document.querySelectorAll(".tabulator-footer");};return jsxs(Fragment,{children:[Le&&jsx("div",{style:{paddingBottom:"0.8rem",fontSize:"0.85rem",color:"#666",marginLeft:"0.2rem"},children:at(e)}),jsxs("div",{style:{padding:10,paddingBottom:0,overflowX:"auto"},ref:i,children:[jsx(Ze,{sx:{paddingBottom:1,paddingTop:1,paddingRight:1},children:!_e&&jsx(Oe,{})}),jsx(ot,{onRef:c=>n.current=c==null?void 0:c.current,data:d,columns:D,options:Se,events:{tableBuilt:Ve},className:"tabulator",style:{marginBottom:0,minWidth:y+"px"}})]})]})}));ke.displayName="_Tabulator";var Zt=ke;export{Zt as TabulatorTable};