@vuu-ui/vuu-table 0.8.20 → 0.8.21-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/cjs/index.js +3529 -1
- package/cjs/index.js.map +4 -4
- package/esm/index.js +3589 -1
- package/esm/index.js.map +4 -4
- package/index.css +589 -1
- package/index.css.map +3 -3
- package/package.json +9 -8
- package/types/Table.d.ts +6 -1
- package/types/index.d.ts +1 -0
- package/types/table-dom-utils.d.ts +3 -0
- package/types/useKeyboardNavigation.d.ts +1 -1
- package/types/useTable.d.ts +5 -2
- package/types/useTableScroll.d.ts +23 -10
- package/types/useTableViewport.d.ts +2 -0
- package/LICENSE +0 -201
- package/types/useVirtualViewport.d.ts +0 -13
package/cjs/index.js
CHANGED
|
@@ -1,2 +1,3530 @@
|
|
|
1
|
-
"use strict";var ir=Object.create;var Ge=Object.defineProperty;var ar=Object.getOwnPropertyDescriptor;var sr=Object.getOwnPropertyNames;var ur=Object.getPrototypeOf,cr=Object.prototype.hasOwnProperty;var mr=(e,o)=>{for(var t in o)Ge(e,t,{get:o[t],enumerable:!0})},qo=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of sr(o))!cr.call(e,n)&&n!==t&&Ge(e,n,{get:()=>o[n],enumerable:!(r=ar(o,n))||r.enumerable});return e};var j=(e,o,t)=>(t=e!=null?ir(ur(e)):{},qo(o||!e||!e.__esModule?Ge(t,"default",{value:e,enumerable:!0}):t,e)),dr=e=>qo(Ge({},"__esModule",{value:!0}),e);var fl={};mr(fl,{CheckboxCell:()=>Vo,GroupHeaderCellNext:()=>We,HeaderCell:()=>po,InputCell:()=>Rn,Table:()=>ml,TableCell:()=>go,TableGroupCell:()=>vo,ToggleCell:()=>Pn,dataAndColumnUnchanged:()=>Ne,isShowColumnSettings:()=>ko,isShowTableSettings:()=>Lo,updateTableConfig:()=>yo,useControlledTableNavigation:()=>bl,useTableModel:()=>Ao,useTableViewport:()=>Io});module.exports=dr(fl);var ct=require("@vuu-ui/vuu-layout"),mt=require("@vuu-ui/vuu-utils"),dt=j(require("clsx")),we=require("react");var ot=j(require("clsx")),tt=require("react");var $e=require("react/jsx-runtime"),et="vuuColumnHeaderPill",ve=({children:e,className:o,column:t,onRemove:r,removable:n,...l})=>{if(n&&typeof r!="function")throw Error("ColumnHeaderPill onRemove prop must be provided if Pill is removable");let a=(0,tt.useCallback)(i=>{i.preventDefault(),i.stopPropagation(),r==null||r(t)},[t,r]);return(0,$e.jsxs)("div",{...l,className:(0,ot.default)(et,o),children:[e,n?(0,$e.jsx)("span",{className:`${et}-removeButton`,role:"button","data-icon":"cross",onClick:a}):null]})};var he=require("react/jsx-runtime"),nt=({column:e,...o})=>{let{name:t,sorted:r}=e,n=typeof r=="number"?r<0?"arrow-down":"arrow-up":r==="A"?"arrow-up":r==="D"?"arrow-down":void 0;return(0,he.jsxs)(ve,{...o,column:e,children:[(0,he.jsx)("span",{className:"vuuGroupColumnPill-label",children:t}),n!==void 0?(0,he.jsx)("span",{"data-icon":n}):null,typeof r=="number"?(0,he.jsx)("span",{className:"vuuSortPosition",children:Math.abs(r)}):null]})};var Ae=require("react/jsx-runtime"),rt=({column:e})=>{if(!e.sorted)return null;let o=typeof e.sorted=="number"?e.sorted<0?"arrow-down":"arrow-up":e.sorted==="A"?"arrow-up":"arrow-down";return(0,Ae.jsxs)(ve,{column:e,children:[(0,Ae.jsx)("span",{"data-icon":o}),typeof e.sorted=="number"?(0,Ae.jsx)("span",{className:"vuuSortPosition",children:Math.abs(e.sorted)}):null]})};var xe=require("react");var it=require("react/jsx-runtime"),lt=()=>{},pr="vuuColumnResizerNext",Be=({onDrag:e,onDragEnd:o=lt,onDragStart:t=lt})=>{let r=(0,xe.useRef)(0),n=(0,xe.useCallback)(i=>{i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault();let s=Math.round(i.clientX),u=s-r.current;r.current=s,u!==0&&e(i,u)},[e]),l=(0,xe.useCallback)(i=>{window.removeEventListener("mouseup",l),window.removeEventListener("mousemove",n),o(i)},[o,n]),a=(0,xe.useCallback)(i=>{t(i),r.current=Math.round(i.clientX),window.addEventListener("mouseup",l),window.addEventListener("mousemove",n),i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault()},[t,n,l]);return(0,it.jsx)("div",{className:pr,onMouseDown:a})};var ae=require("react"),Oe=({column:e,onResize:o,rootRef:t})=>{let r=(0,ae.useRef)(0),[n,l]=(0,ae.useState)(!1),{name:a}=e,i=(0,ae.useCallback)(()=>{if(o&&t.current){let{width:c}=t.current.getBoundingClientRect();r.current=Math.round(c),l(!0),o==null||o("begin",a)}},[a,o,t]),s=(0,ae.useCallback)((c,m)=>{if(t.current&&o){let{width:f}=t.current.getBoundingClientRect(),b=Math.round(f)+m;b!==r.current&&b>0&&(o("resize",a,b),r.current=b)}},[a,o,t]),u=(0,ae.useCallback)(()=>{o&&(o("end",a,r.current),setTimeout(()=>{l(!1)},80))},[a,o]);return{isResizing:n,onDrag:s,onDragStart:i,onDragEnd:u}};var at=require("@vuu-ui/vuu-utils"),st=j(require("clsx")),ut=require("react"),se=(e,o,t)=>(0,ut.useMemo)(()=>{let r=(0,st.default)(o,{vuuPinFloating:e.pin==="floating",vuuPinLeft:e.pin==="left",vuuPinRight:e.pin==="right",vuuEndPin:t&&e.endPin,[`${o}-editable`]:e.editable,[`${o}-right`]:e.align==="right"}),n=(0,at.getColumnStyle)(e);return{className:r,style:n}},[e,o,t]);var Te=require("react/jsx-runtime"),pt=require("react"),mo="vuuTableGroupHeaderCell",br=(e,o)=>e===o?e:o,We=({column:e,className:o,onMoveColumn:t,onRemoveColumn:r,onResize:n,...l})=>{let a=(0,we.useRef)(null),{isResizing:i,...s}=Oe({column:e,onResize:n,rootRef:a}),[u,c]=(0,we.useState)(e.columns),{className:m,style:f}=se(e,mo,!0),b=u.length>1?{removable:!0,onRemove:r}:void 0,x=(0,we.useCallback)((T,d)=>{c(v=>{let y=v.slice(),[C]=y.splice(T,1);if(d===-1){let P=y.concat(C);return t==null||t(P),P}else return y.splice(d,0,C),t==null||t(y),y})},[t]);return(0,mt.useLayoutEffectSkipFirst)(()=>{c(T=>br(T,e.columns))},[e.columns]),(0,Te.jsxs)("div",{...l,className:(0,dt.default)(m,o,{[`${mo}-pending`]:e.groupConfirmed===!1}),ref:a,role:"columnheader",style:f,children:[(0,Te.jsx)(ct.OverflowContainer,{allowDragDrop:!0,className:`${mo}-inner`,height:24,onMoveItem:x,overflowPosition:"start",children:u.map(T=>(0,pt.createElement)(nt,{...b,column:T,key:T.key}))}),(0,Te.jsx)(ve,{column:e,removable:!0,onRemove:r}),e.resizeable!==!1?(0,Te.jsx)(Be,{...s}):null]})};var vt=j(require("clsx")),_e=require("react");var bt=require("@vuu-ui/vuu-popups"),ft=j(require("clsx")),de=require("react");var Ct=require("react/jsx-runtime"),fr=e=>{if(e){let{bottom:o,left:t}=e.getBoundingClientRect();return{x:t,y:o+6}}},gt=({className:e,column:o,...t})=>{let r=(0,de.useRef)(null),[n,l]=(0,de.useState)(!1),[a]=(0,bt.useContextMenu)(),i=(0,de.useCallback)(()=>{l(!1)},[]),s=(0,de.useCallback)(u=>{l(!0),a(u,"column-menu",{column:o,ContextMenuProps:{onClose:i,position:fr(r.current)}})},[o,i,a]);return(0,Ct.jsx)("span",{...t,className:(0,ft.default)("vuuTable-columnMenu",e,{"vuuTable-columnMenu-open":n}),"data-icon":"more-vert",onClick:s,ref:r})};var ne=require("react/jsx-runtime"),Ue="vuuTableHeaderCell",po=({className:e,column:o,onClick:t,onResize:r,...n})=>{var y;let{HeaderCellContentRenderer:l,HeaderCellLabelRenderer:a}=o,i=(0,_e.useRef)(null),{isResizing:s,...u}=Oe({column:o,onResize:r,rootRef:i}),c=(0,_e.useCallback)(C=>{!s&&(t==null||t(C))},[s,t]),{className:m,style:f}=se(o,Ue,!0),b=(0,ne.jsx)(gt,{column:o}),x=a?(0,ne.jsx)(a,{className:`${Ue}-label`,column:o}):(0,ne.jsx)("div",{className:`${Ue}-label`,children:(y=o.label)!=null?y:o.name}),T=l?[(0,ne.jsx)(l,{column:o},"content")]:[],d=(0,ne.jsx)(rt,{column:o}),v=o.align==="right"?[d,x].concat(T).concat(b):[b,x,d].concat(T);return(0,ne.jsxs)("div",{...n,className:(0,vt.default)(m,e,{[`${Ue}-resizing`]:s}),onClick:c,ref:i,role:"columnheader",style:f,children:[...v,o.resizeable!==!1?(0,ne.jsx)(Be,{...u}):null]})};var fn=require("@vuu-ui/vuu-layout"),gn=require("@vuu-ui/vuu-popups"),oo=require("@vuu-ui/vuu-utils"),Cn=require("@salt-ds/core"),zo=j(require("clsx")),Pe=require("react");var W=require("@vuu-ui/vuu-utils"),wt=j(require("clsx")),Ie=require("react");var ht=require("@vuu-ui/vuu-utils"),bo=require("react");var fo=require("react/jsx-runtime"),gr="vuuTableCell",go=({column:e,columnMap:o,onClick:t,onDataEdited:r,row:n})=>{let{className:l,style:a}=se(e,gr),{CellRenderer:i,name:s,valueFormatter:u}=e,c=o[s],m=(0,bo.useCallback)(b=>{if(r){let x=b;return(0,ht.isNumericColumn)(e)&&typeof b=="string"&&(x=e.serverDataType==="double"?parseFloat(b):parseInt(b)),r==null?void 0:r(n,s,x)}else throw Error("TableCell onDataEdited prop not supplied for an editable cell")},[e,s,r,n]),f=(0,bo.useCallback)(b=>{t==null||t(b,e)},[e,t]);return(0,fo.jsx)("div",{className:l,onClick:t?f:void 0,role:"cell",style:a,children:i?(0,fo.jsx)(i,{column:e,columnMap:o,onCommit:m,row:n}):u(n[c])})};var Xe=require("@vuu-ui/vuu-utils"),xt=require("react");var Tt=j(require("clsx"));var Re=require("react/jsx-runtime"),{IS_LEAF:Cr}=Xe.metadataKeys,Co="vuuTableGroupCell",vo=({column:e,onClick:o,row:t})=>{let{columns:r}=e,[n,l]=(0,Xe.getGroupValueAndOffset)(r,t),{className:a,style:i}=se(e,Co),s=(0,xt.useCallback)(m=>{o==null||o(m,e)},[e,o]),u=t[Cr],c=Array(l).fill(0).map((m,f)=>(0,Re.jsx)("span",{className:`${Co}-spacer`},f));return(0,Re.jsxs)("div",{className:(0,Tt.default)(a,"vuuTableCell"),role:"cell",style:i,onClick:u?void 0:s,children:[c,u?null:(0,Re.jsx)("span",{className:`${Co}-toggle`,"data-icon":"triangle-right"}),(0,Re.jsx)("span",{children:n})]})};var Qe=require("react/jsx-runtime"),Rt=require("react"),{IDX:vr,IS_EXPANDED:hr,SELECTED:xr}=W.metadataKeys,re="vuuTableRow",ho=(0,Ie.memo)(({className:e,columnMap:o,columns:t,highlighted:r,row:n,offset:l,onClick:a,onDataEdited:i,onToggleGroup:s,zebraStripes:u=!1,...c})=>{let{[vr]:m,[hr]:f,[xr]:b}=n,x=(0,Ie.useCallback)(D=>{let M=D.shiftKey,k=D.ctrlKey||D.metaKey;a==null||a(n,M,k)},[a,n]),{True:T,First:d,Last:v}=W.RowSelected,y=(0,wt.default)(re,e,{[`${re}-even`]:u&&m%2===0,[`${re}-expanded`]:f,[`${re}-highlighted`]:r,[`${re}-selected`]:b&T,[`${re}-selectedStart`]:b&d,[`${re}-selectedEnd`]:b&v}),C={transform:`translate3d(0px, ${l}px, 0px)`},P=(0,Ie.useCallback)((D,M)=>{((0,W.isGroupColumn)(M)||(0,W.isJsonGroup)(M,n))&&(D.stopPropagation(),s==null||s(n,M))},[s,n]);return(0,Rt.createElement)("div",{...c,"aria-rowindex":n[0]+1,key:`row-${n[0]}`,role:"row",className:y,onClick:x,style:C},(0,Qe.jsx)("span",{className:`${re}-selectionDecorator vuuStickyLeft`}),t.filter(W.isNotHidden).map(D=>{let M=(0,W.isGroupColumn)(D),k=(0,W.isJsonColumn)(D);return(0,Qe.jsx)(M?vo:go,{column:D,columnMap:o,onClick:M||k?P:void 0,onDataEdited:i,row:n},D.key)}),(0,Qe.jsx)("span",{className:`${re}-selectionDecorator vuuStickyRight`}))});ho.displayName="Row";var sn=require("@vuu-ui/vuu-ui-controls"),F=require("@vuu-ui/vuu-utils"),H=require("react");var yt=require("@vuu-ui/vuu-utils"),Dt=e=>(o,t)=>{let r=[];return e===void 0||(o==="header"||o==="column-menu")&&(r.push(...Tr(t,e)),r.push(...yr(t,e)),r.push(...wr(t,e)),r.push(...Rr(t)),r.push({action:"column-settings",icon:"cog",label:"Column Settings",options:t}),r.push({action:"table-settings",icon:"cog",label:"DataGrid Settings",options:t})),r};function Tr(e,{sort:{sortDefs:o}}){let{column:t}=e,r=[];if(t===void 0)return r;let n=o.length>0;return t.sorted==="A"?r.push({label:"Reverse Sort (DSC)",action:"sort-dsc",options:e}):t.sorted==="D"?r.push({label:"Reverse Sort (ASC)",action:"sort-asc",options:e}):typeof t.sorted=="number"?(t.sorted>0?r.push({label:"Reverse Sort (DSC)",action:"sort-add-dsc",options:e}):r.push({label:"Reverse Sort (ASC)",action:"sort-add-asc",options:e}),n&&Math.abs(t.sorted)<o.length&&r.push({label:"Remove from sort",action:"sort-remove",options:e}),r.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):n?(r.push({label:"Add to sort",children:[{label:"Ascending",action:"sort-add-asc",options:e},{label:"Descending",action:"sort-add-dsc",options:e}]}),r.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):r.push({label:"Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]}),r}function wr(e,o){let{column:t}=e;if(t===void 0||o.groupBy.length===0)return[];let{name:r,label:n=r}=t;return[{label:`Aggregate ${n}`,children:[{label:"Count",action:"agg-count",options:e},{label:"Distinct",action:"agg-distinct",options:e}].concat((0,yt.isNumericColumn)(t)?[{label:"Sum",action:"agg-sum",options:e},{label:"Avg",action:"agg-avg",options:e},{label:"High",action:"agg-high",options:e},{label:"Low",action:"agg-low",options:e}]:[])}]}var Ro=(e,o)=>({label:`Pin ${o}`,action:`column-pin-${o}`,options:e}),xo=e=>Ro(e,"left"),To=e=>Ro(e,"floating"),wo=e=>Ro(e,"right");function Rr(e){let{column:o}=e;if(o===void 0)return[];let{pin:t}=o,r=[{label:"Hide column",action:"column-hide",options:e},{label:"Remove column",action:"column-remove",options:e}];return t===void 0?r.push({label:"Pin column",children:[xo(e),To(e),wo(e)]}):t==="left"?r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[To(e),wo(e)]}):t==="right"?r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[xo(e),To(e)]}):t==="floating"&&r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[xo(e),wo(e)]}),r}function yr(e,{groupBy:o}){let{column:t}=e,r=[];if(t===void 0)return r;let{name:n,label:l=n}=t;return o.length===0?r.push({label:`Group by ${l}`,action:"group",options:e}):r.push({label:`Add ${l} to group by`,action:"group-add",options:e}),r}var Mt=require("@vuu-ui/vuu-utils"),G=require("@vuu-ui/vuu-utils"),Dr=(e,o)=>{if(e.filterStruct&&o){let[t,r]=(0,Mt.removeColumnFromFilter)(o,e.filterStruct);return{filter:r,filterStruct:t}}else return e},{Average:Mr,Count:Hr,Distinct:Pr,High:Er,Low:Sr,Sum:kr}=G.AggregationType,Ht=({dataSource:e,onPersistentColumnOperation:o})=>r=>{let n=r.options;if(n.column&&e){let{column:l}=n;switch(r.menuId){case"sort-asc":return e.sort=(0,G.setSortColumn)(e.sort,l,"A"),!0;case"sort-dsc":return e.sort=(0,G.setSortColumn)(e.sort,l,"D"),!0;case"sort-add-asc":return e.sort=(0,G.addSortColumn)(e.sort,l,"A"),!0;case"sort-add-dsc":return e.sort=(0,G.addSortColumn)(e.sort,l,"D"),!0;case"group":return e.groupBy=(0,G.addGroupColumn)(e.groupBy,l),!0;case"group-add":return e.groupBy=(0,G.addGroupColumn)(e.groupBy,l),!0;case"column-hide":return o({type:"hideColumns",columns:[l]}),!0;case"column-remove":return e.columns=e.columns.filter(a=>a!==l.name),!0;case"filter-remove-column":return e.filter=Dr(e.filter,l),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=(0,G.setAggregations)(e.aggregations,l,Mr),!0;case"agg-high":return e.aggregations=(0,G.setAggregations)(e.aggregations,l,Er),!0;case"agg-low":return e.aggregations=(0,G.setAggregations)(e.aggregations,l,Sr),!0;case"agg-count":return e.aggregations=(0,G.setAggregations)(e.aggregations,l,Hr),!0;case"agg-distinct":return e.aggregations=(0,G.setAggregations)(e.aggregations,l,Pr),!0;case"agg-sum":return e.aggregations=(0,G.setAggregations)(e.aggregations,l,kr),!0;case"column-pin-floating":return o({type:"pinColumn",column:l,pin:"floating"}),!0;case"column-pin-left":return o({type:"pinColumn",column:l,pin:"left"}),!0;case"column-pin-right":return o({type:"pinColumn",column:l,pin:"right"}),!0;case"column-unpin":return o({type:"pinColumn",column:l,pin:void 0}),!0;case"column-settings":return o({type:"columnSettings",column:l}),!0;case"table-settings":return o({type:"tableSettings"}),!0;default:}}return!1};var yo=(e,o)=>{switch(o.type){case"col-size":return{...e,columns:e.columns.map(t=>t.name===o.column.name?{...t,width:o.width}:t)};case"column-prop":return{...e,columns:e.columns.map(t=>t.name===o.column.name?{...t,[o.property]:o.value}:t)};default:return e}};var kt=require("@vuu-ui/vuu-utils"),ue=require("react");var Do=e=>`.vuuTable-col-headers .vuuTableHeaderCell:nth-child(${e})`,Mo=(e,o)=>`.vuuTable-body > [aria-rowindex='${e}'] > [role='cell']:nth-child(${o+1})`,Pt=(e,[o,t])=>{var l;let r=o===-1?Do(t):Mo(o,t),n=(l=e.current)==null?void 0:l.querySelector(r);return Lr(n)&&n.querySelector("button")||n},Lr=e=>e.classList.contains("vuuTableCell-editable"),Et=e=>e.querySelector(".vuuTableInputCell")!==null;function Ar(e){if(e){let o=e.ariaRowIndex;if(o!==null)return parseInt(o,10)-1}return-1}var Ir=e=>e.closest('[role="row"]'),St=e=>Ar(Ir(e));var Lt=({navigate:e})=>{let o=(0,ue.useCallback)(()=>{e()},[e]),t=(0,ue.useCallback)(s=>{let u=s.target,c=u.matches("input")?u:u.querySelector("input");c&&(c.focus(),c.select())},[]),r=(0,ue.useCallback)(s=>{let c=s.target.querySelector("input");c&&(c.focus(),c.select())},[]),n=(0,ue.useCallback)(s=>{let u=s.target;Et(u)&&((0,kt.isCharacterKey)(s.key)?t(s):s.key==="Enter"&&r(s))},[t,r]),l=(0,ue.useCallback)(s=>{let u=s.target;(u.matches("input")||u.querySelector("input"))&&(t(s),s.stopPropagation())},[t]),a=(0,ue.useCallback)(s=>{s.target.removeEventListener("vuu-commit",o,!0)},[o]),i=(0,ue.useCallback)(s=>{s.target.addEventListener("vuu-commit",o,!0)},[o]);return{onBlur:a,onDoubleClick:l,onFocus:i,onKeyDown:n}};var pe=require("@vuu-ui/vuu-utils"),$=require("react");var ye=require("@vuu-ui/vuu-utils"),{SELECTED:Ho}=ye.metadataKeys,Je=class{constructor({from:o,to:t}){this.rowCount=0;this.setRowCount=o=>{o<this.data.length&&(this.data.length=o),this.rowCount=o};this.range=new ye.WindowRange(o,t),this.data=new Array(Math.max(0,t-o)),this.rowCount=0}add(o){let[t]=o;if(this.isWithinRange(t)){let r=t-this.range.from;if(this.data[r]=o,o[Ho]){let n=this.data[r-1];(0,ye.isRowSelectedLast)(n)&&(this.data[r-1]=n.slice(),this.data[r-1][Ho]-=4)}}}getAtIndex(o){return this.range.isWithin(o)&&this.data[o-this.range.from]!=null?this.data[o-this.range.from]:void 0}isWithinRange(o){return this.range.isWithin(o)}setRange({from:o,to:t}){if(o!==this.range.from||t!==this.range.to){let[r,n]=this.range.overlap(o,t),l=new Array(Math.max(0,t-o));for(let a=r;a<n;a++){let i=this.getAtIndex(a);if(i){let s=a-o;l[s]=i}}this.data=l,this.range.from=o,this.range.to=t}}getSelectedRows(){return this.data.filter(o=>o[Ho]!==0)}};var zr=e=>e.type==="vuu-link-created"||e.type==="vuu-link-removed",At=({dataSource:e,onFeatureInvocation:o,onSizeChange:t,onSubscribed:r,range:n=pe.NULL_RANGE,renderBufferSize:l=0})=>{let[,a]=(0,$.useState)(null),i=(0,$.useRef)([]),s=(0,$.useRef)(!0),u=(0,$.useRef)(!1),c=(0,$.useRef)(pe.NULL_RANGE),m=(0,$.useMemo)(()=>new Je((0,pe.getFullRange)(n,l)),[]),f=(0,$.useCallback)(d=>{for(let v of d)m.add(v);i.current=m.data,s.current?a({}):console.log("ignore update as we're not mounted")},[m]),b=(0,$.useCallback)(d=>{d.type==="subscribed"?r==null||r(d):d.type==="viewport-update"?(typeof d.size=="number"&&(t==null||t(d.size),m.setRowCount(d.size)),d.rows?f(d.rows):typeof d.size=="number"&&(i.current=m.data,u.current=!0)):zr(d)?o==null||o(d):console.log(`useDataSource unexpected message ${d.type}`)},[m,o,t,r,f]),x=(0,$.useCallback)(()=>m.getSelectedRows(),[m]);(0,$.useEffect)(()=>{var d;return s.current=!0,(d=e.resume)==null||d.call(e),()=>{var v;s.current=!1,(v=e.suspend)==null||v.call(e)}},[e]),(0,$.useEffect)(()=>{var d;e.status==="disabled"?(d=e.enable)==null||d.call(e,b):e==null||e.subscribe({range:(0,pe.getFullRange)(n,l)},b)},[e,b,n,l]);let T=(0,$.useCallback)(d=>{let v=(0,pe.getFullRange)(d,l);m.setRange(v),e.range=c.current=v,e.emit("range",d)},[e,m,l]);return{data:i.current,dataRef:i,getSelectedRows:x,range:c.current,setRange:T}};var Ye=require("react"),It=e=>{let o=(0,Ye.useRef)(e);return(0,Ye.useMemo)(()=>o.current,[])};var Vt=require("@salt-ds/core"),z=require("react");var Ft=new Set(["Home","End","PageUp","PageDown","ArrowDown","ArrowUp"]),Eo=new Set(Ft);Eo.add("ArrowLeft");Eo.add("ArrowRight");var Nr=(e,o)=>{switch(o){case"cell":return Eo.has(e);case"row":return Ft.has(e);default:return!1}},Vr=["Home","End","PageUp","PageDown"],zt=e=>Vr.includes(e),Fr=[-1,-1],Po=[void 0,void 0],Kt=(e,o=e.closest(".vuuTable-contentContainer"))=>{if(o){let t=o==null?void 0:o.getBoundingClientRect(),r=e.getBoundingClientRect();if(r)return r.bottom>t.bottom?["down",r.bottom-t.bottom]:r.top<t.top?["up",r.top-t.top]:Po;throw Error("Whats going on, row not found")}else throw Error("Whats going on, scrollbar container not found")},Kr=e=>{var t;let o=e.closest(".vuuTable-contentContainer");if(o){let r=e.closest(".vuuTableRow");if(r){let n=Kt(r,o);if(n!==Po)return n;let l=o==null?void 0:o.getBoundingClientRect(),a=(t=e.closest(".vuuTableCell"))==null?void 0:t.getBoundingClientRect();if(a){if(a.right>l.right)return["right",a.right+6-l.right];if(a.left<l.left)return["left",a.left-l.left]}else throw Error("Whats going on, cell not found")}}return Po};function Nt(e,[o,t],r,n){return e==="ArrowUp"?o>-1?[o-1,t]:[o,t]:e==="ArrowDown"?o===-1?[0,t]:o===n-1?[o,t]:[o+1,t]:e==="ArrowRight"?t<r?[o,t+1]:[o,t]:e==="ArrowLeft"?t>1?[o,t-1]:[o,t]:[o,t]}var Gt=({columnCount:e=0,containerRef:o,disableFocus:t=!1,defaultHighlightedIndex:r,disableHighlightOnFocus:n,highlightedIndex:l,navigationStyle:a,requestScroll:i,onHighlight:s,rowCount:u=0,viewportRowCount:c})=>{var Z;let m=(0,z.useRef)([-1,-1]),f=(0,z.useRef)(),b=(0,z.useRef)([-1,0]),x=(0,z.useRef)(),[T,d]=(0,Vt.useControlled)({controlled:l,default:r,name:"UseKeyboardNavigation"});x.current=T;let v=(0,z.useCallback)((g,h=!1)=>{s==null||s(g),d(g)},[s,d]),y=g=>g==null?void 0:g.closest("[role='columnHeader'],[role='cell']"),C=g=>{var h,R;if(g.role==="columnHeader")return[-1,parseInt((h=g.dataset.idx)!=null?h:"-1",10)];{let A=g.closest("[role='row']");if(A){let N=parseInt((R=A.ariaRowIndex)!=null?R:"-1",10),Se=Array.from(A.childNodes).indexOf(g);return[N,Se]}}return Fr},P=(0,z.useCallback)(g=>{var h;if(o.current){let R=Pt(o,g);if(R){R!==f.current&&((h=f.current)==null||h.removeAttribute("tabindex"),f.current=R,R.setAttribute("tabindex","0"));let[A,N]=Kr(R);A&&N&&(i==null||i({type:"scroll-distance",distance:N,direction:A})),console.log("activeCell focus"),R.focus({preventScroll:!0})}}},[o,i]),D=(0,z.useCallback)((g,h,R=!1)=>{let A=[g,h];b.current=A,a==="row"?d(g):P(A),R&&(m.current=A)},[P,a,d]),M=(0,z.useCallback)((g,[h,R])=>new Promise(A=>{let N=h;switch(g){case"PageDown":N=Math.min(u-1,h+c),i==null||i({type:"scroll-page",direction:"down"});break;case"PageUp":N=Math.max(0,h-c),i==null||i({type:"scroll-page",direction:"up"});break;case"Home":N=0,i==null||i({type:"scroll-end",direction:"home"});break;case"End":N=u-1,i==null||i({type:"scroll-end",direction:"end"});break}setTimeout(()=>{A([N,R])},90)}),[i,u,c]),k=(0,z.useCallback)(()=>{var g;if(n!==!0&&(g=o.current)!=null&&g.contains(document.activeElement)){let h=y(document.activeElement);h&&(m.current=C(h),a==="row"&&d(m.current[0]))}},[n,o,a,d]),L=(0,z.useCallback)(async g=>{let[h,R]=zt(g)?await M(g,b.current):Nt(g,b.current,e,u),[A,N]=b.current;(h!==A||R!==N)&&D(h,R,!0)},[e,M,u,D]),K=(0,z.useCallback)(g=>{let{current:h}=o,R=h==null?void 0:h.querySelector(`[aria-rowindex="${g}"]`);if(R){let[A,N]=Kt(R);A&&N&&(i==null||i({type:"scroll-distance",distance:N,direction:A}))}},[o,i]),q=(0,z.useCallback)(async g=>{let{current:h}=x,[R]=zt(g)?await M(g,[h!=null?h:-1,0]):Nt(g,[h!=null?h:-1,0],e,u);R!==h&&(v(R),K(R))},[e,M,u,K,v]);(0,z.useEffect)(()=>{l!==void 0&&l!==-1&&K(l)},[l,K]);let U=(0,z.useCallback)(g=>{u>0&&Nr(g.key,a)&&(g.preventDefault(),g.stopPropagation(),a==="row"?q(g.key):L(g.key))},[u,a,q,L]),_=(0,z.useCallback)(g=>{let h=g.target,R=y(h);if(R){let[A,N]=C(R);D(A,N)}},[D]),E=(0,z.useCallback)(()=>{v(-1)},[v]),ee=(0,z.useCallback)(g=>{let h=St(g.target);h!==-1&&h!==x.current&&v(h)},[v]),Ee=(0,z.useCallback)(()=>{L("ArrowDown")},[L]),I=((Z=o.current)==null?void 0:Z.firstChild)!=null;return(0,z.useEffect)(()=>{if(I&&f.current===void 0&&!t){let{current:g}=o,h=(g==null?void 0:g.querySelector(Do(0)))||(g==null?void 0:g.querySelector(Mo(0,0)));h&&(h.setAttribute("tabindex","0"),f.current=h)}},[o,t,I]),{highlightedIndexRef:x,navigate:Ee,onClick:_,onFocus:k,onKeyDown:U,onMouseLeave:a==="row"?E:void 0,onMouseMove:a==="row"?ee:void 0}};var te=require("@vuu-ui/vuu-utils"),be=require("react"),{IDX:Gr}=te.metadataKeys,$r=[],Br=["Enter"," "],$t=({highlightedIndexRef:e,selectionKeys:o=Br,selectionModel:t,onSelect:r,onSelectionChange:n})=>{let l=(0,be.useRef)(-1),a=(0,be.useRef)($r),i=(0,be.useCallback)(c=>o.includes(c.key),[o]),s=(0,be.useCallback)((c,m,f)=>{let{[Gr]:b}=c,{current:x}=l,{current:T}=a,v=((0,te.isRowSelected)(c)?te.deselectItem:te.selectItem)(t,T,b,m,f,x);a.current=v,l.current=b,r==null||r(c),n==null||n(v)},[r,n,t]);return{onKeyDown:(0,be.useCallback)(c=>{if(i(c)){let{current:m}=e;if(m!==void 0&&m!==-1){let f=c.target.querySelector(`[aria-rowindex="${m}"]`);f&&(0,te.dispatchMouseEvent)(f,"click")}}},[e,i]),onRowClick:s}};var Bt=require("@vuu-ui/vuu-popups"),Ze=require("@vuu-ui/vuu-utils"),Ot=require("react"),Or=[],Wt=({columns:e,data:o,dataSource:t,getSelectedRows:r})=>{let[n]=(0,Bt.useContextMenu)();return(0,Ot.useCallback)(a=>{let i=a.target,s=i==null?void 0:i.closest("div[role='cell']"),u=i==null?void 0:i.closest("div[role='row']");if(s&&u){let{selectedRowsCount:c}=t,m=(0,Ze.buildColumnMap)(e),f=(0,Ze.getIndexFromRowElement)(u),b=Array.from(u.childNodes).indexOf(s),x=o.find(([d])=>d===f),T=e[b];n(a,"grid",{columnMap:m,columnName:T,row:x,selectedRows:c===0?Or:r(),viewport:t.viewport})}},[e,o,t,r,n])};var w=require("@vuu-ui/vuu-utils"),Ut=require("@vuu-ui/vuu-ui-controls"),_t=require("react"),{info:So}=(0,w.logger)("useTableModel"),Wr=100,Ur=w.metadataKeys.count,_r=({serverDataType:e})=>e===void 0,Xt=(e,o)=>{let t=o==null?void 0:o.columns.find(({name:r})=>r===e.name);return t?t.serverDataType:e.serverDataType},Xr=["int","long","double"],Qt=e=>e===void 0?void 0:Xr.includes(e)?"right":"left",ko=e=>e.type==="columnSettings",Lo=e=>e.type==="tableSettings",Qr=(e,o)=>{switch(So==null||So(`TableModelReducer ${o.type}`),o.type){case"init":return Jt(o);case"moveColumn":return Yr(e,o);case"resizeColumn":return qr(e,o);case"setTableSchema":return el(e,o);case"hideColumns":return Zr(e,o);case"showColumns":return jr(e,o);case"pinColumn":return ol(e,o);case"updateColumnProp":return De(e,o);case"tableConfig":return Zt(e,o);default:return console.log(`unhandled action ${o.type}`),e}},Ao=(e,o)=>{let[t,r]=(0,_t.useReducer)(Qr,{tableConfig:e,dataSource:o},Jt),{columns:n,headings:l,tableConfig:a,...i}=t;return{columns:n,dispatchColumnAction:r,headings:l,tableAttributes:i,tableConfig:a}};function Jt({dataSource:e,tableConfig:o}){let{columns:t,...r}=o,{config:n,tableSchema:l}=e,a=t.filter((0,w.subscribedOnly)(n==null?void 0:n.columns)).map(Yt(r,l)),i=a.some(w.isPinned)?(0,w.sortPinnedColumns)(a):a,s={columns:i,headings:(0,w.getTableHeadings)(i),tableConfig:o,...r};if(n){let{columns:u,...c}=n;s=Zt(s,{type:"tableConfig",...c})}return s}var Jr=(e,o)=>o==="uppercase"?e.toUpperCase():o==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,Yt=(e,o)=>(t,r)=>{let{columnDefaultWidth:n=Wr,columnFormatHeader:l}=e,a=Xt(t,o),{align:i=Qt(a),key:s,name:u,label:c=(0,w.getColumnLabel)(t),width:m=n,...f}=t,b={...f,align:i,CellRenderer:(0,w.getCellRenderer)(t),HeaderCellContentRenderer:(0,w.getColumnHeaderContentRenderer)(t),HeaderCellLabelRenderer:(0,w.getColumnHeaderLabelRenderer)(t),clientSideEditValidationCheck:(0,w.hasValidationRules)(t.type)?(0,Ut.buildValidationChecker)(t.type.renderer.rules):void 0,label:Jr(c,l),key:s!=null?s:r+Ur,name:u,originalIdx:r,serverDataType:a,valueFormatter:(0,w.getValueFormatter)(t,a),width:m};return(0,w.isGroupColumn)(b)&&(b.columns=b.columns.map(x=>Yt(e)(x,x.key))),b};function Yr(e,{column:o,moveBy:t}){let{columns:r}=e;if(typeof t=="number"){let n=r.indexOf(o),l=r.slice(),[a]=l.splice(n,1);return l.splice(n+t,0,a),{...e,columns:l}}return e}function Zr(e,{columns:o}){return o.some(t=>t.hidden!==!0)?o.reduce((t,r)=>r.hidden!==!0?De(t,{type:"updateColumnProp",column:r,hidden:!0}):t,e):e}function jr(e,{columns:o}){return o.some(t=>t.hidden)?o.reduce((t,r)=>r.hidden?De(t,{type:"updateColumnProp",column:r,hidden:!1}):t,e):e}function qr(e,{column:o,phase:t,width:r}){let n="updateColumnProp",l=t!=="end";switch(t){case"begin":return De(e,{type:n,column:o,resizing:l});case"end":return De(e,{type:n,column:o,resizing:l,width:r});case"resize":return De(e,{type:n,column:o,width:r});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${t}`)}}function el(e,{tableSchema:o}){let{columns:t}=e;if(t.some(_r)){let r=t.map(n=>{var a;let l=Xt(n,o);return{...n,align:(a=n.align)!=null?a:Qt(l),serverDataType:l}});return{...e,columns:r}}else return e}function ol(e,o){let{columns:t}=e,{column:r,pin:n}=o,l=t.find(a=>a.name===r.name);return l?(t=(0,w.replaceColumn)(t,{...l,pin:n}),t=(0,w.sortPinnedColumns)(t),{...e,columns:t}):e}function De(e,o){let{columns:t,tableConfig:r}=e,{align:n,column:l,hidden:a,label:i,resizing:s,width:u}=o,c=t.find(m=>m.name===l.name);if(c&&((n==="left"||n==="right")&&(t=(0,w.replaceColumn)(t,{...c,align:n})),typeof i=="string"&&(t=(0,w.replaceColumn)(t,{...c,label:i})),typeof s=="boolean"&&(t=(0,w.replaceColumn)(t,{...c,resizing:s})),typeof a=="boolean"&&(t=(0,w.replaceColumn)(t,{...c,hidden:a})),typeof u=="number")){t=(0,w.replaceColumn)(t,{...c,width:u});let m=r.columns.find(f=>f.name===l.name);m&&(r={...r,columns:(0,w.replaceColumn)(r.columns,{...m,width:u})})}return{...e,columns:t,tableConfig:r}}function Zt(e,{confirmed:o,filter:t,groupBy:r,sort:n}){let l=r!==void 0,a=typeof(t==null?void 0:t.filter)=="string",i=n&&n.sortDefs.length>0,s=e;return l&&(s={...e,columns:(0,w.applyGroupByToColumns)(s.columns,r,o)}),i&&(s={...e,columns:(0,w.applySortToColumns)(s.columns,n)}),a?s={...e,columns:(0,w.applyFilterToColumns)(s.columns,t)}:s.columns.some(w.isFilteredColumn)&&(s={...e,columns:(0,w.stripFilterFromColumns)(s.columns)}),s}var O=require("react"),jt=e=>{let{scrollLeft:o,scrollTop:t}=e,{clientHeight:r,clientWidth:n,scrollHeight:l,scrollWidth:a}=e,i=o/(a-n),s=t/(l-r);return[i,s]},qt=({onAttach:e,onDetach:o})=>{let t=(0,O.useRef)(null);return(0,O.useCallback)(n=>{if(n)t.current=n,e==null||e(n);else if(t.current){let{current:l}=t;t.current=n,o==null||o(l)}},[e,o])},en=({maxScrollLeft:e,maxScrollTop:o,onHorizontalScroll:t,onVerticalScroll:r,rowHeight:n,viewportRowCount:l})=>{let a=(0,O.useRef)(!1),i=(0,O.useRef)({scrollTop:0,scrollLeft:0}),s=(0,O.useRef)(null),u=(0,O.useRef)(null),c=(0,O.useCallback)(()=>{let{current:C}=u,{current:P}=s,{current:D}=a;if(D)a.current=!1;else if(C&&P){let[M,k]=jt(P),L=Math.round(M*e),K=Math.round(k*o);C.scrollTo({left:L,top:K,behavior:"auto"})}},[e,o]),m=(0,O.useCallback)(()=>{let{current:C}=u,{current:P}=s,{current:D}=i;if(C&&P){let{scrollLeft:M,scrollTop:k}=C,[L,K]=jt(C);a.current=!0,P.scrollLeft=Math.round(L*e),P.scrollTop=Math.round(K*o),D.scrollTop!==k&&(D.scrollTop=k,r==null||r(k,K)),D.scrollLeft!==M&&(D.scrollLeft=M,t==null||t(M))}},[e,o,t,r]),f=(0,O.useCallback)(C=>{s.current=C,C.addEventListener("scroll",c,{passive:!0})},[c]),b=(0,O.useCallback)(C=>{s.current=null,C.removeEventListener("scroll",c)},[c]),x=(0,O.useCallback)(C=>{u.current=C,C.addEventListener("scroll",m,{passive:!0})},[m]),T=(0,O.useCallback)(C=>{u.current=null,C.removeEventListener("scroll",m)},[m]),d=qt({onAttach:x,onDetach:T}),v=qt({onAttach:f,onDetach:b}),y=(0,O.useCallback)(C=>{let{current:P}=u;if(P){let{scrollLeft:D,scrollTop:M}=P;if(a.current=!1,C.type==="scroll-distance"){let k=D,L=M;C.direction==="up"||C.direction==="down"?L=Math.min(Math.max(0,M+C.distance),o):k=Math.min(Math.max(0,D+C.distance),e),P.scrollTo({top:L,left:k,behavior:"smooth"})}else if(C.type==="scroll-page"){let{direction:k}=C,L=l*(k==="down"?n:-n),K=Math.min(Math.max(0,M+L),o);P.scrollTo({top:K,left:D,behavior:"auto"})}else if(C.type==="scroll-end"){let{direction:k}=C,L=k==="end"?o:0;P.scrollTo({top:L,left:P.scrollLeft,behavior:"auto"})}}},[e,o,n,l]);return{scrollbarContainerRef:v,contentContainerRef:d,requestScroll:y}};var le=require("react"),je=require("@vuu-ui/vuu-utils"),tl=15e5,nl={contentHeight:0,contentWidth:0,getRowAtPosition:()=>-1,getRowOffset:()=>-1,horizontalScrollbarHeight:0,maxScrollContainerScrollHorizontal:0,maxScrollContainerScrollVertical:0,pinnedWidthLeft:0,pinnedWidthRight:0,rowCount:0,setPctScrollTop:()=>{},totalHeaderHeight:0,verticalScrollbarWidth:0,viewportBodyHeight:0},rl=e=>{let o=0,t=0,r=0;for(let n of e){let{hidden:l,pin:a,width:i}=n,s=l?0:i;a==="left"?o+=s:a==="right"?t+=s:r+=s}return{pinnedWidthLeft:o+4,pinnedWidthRight:t+4,unpinnedWidth:r}},Io=({columns:e,headerHeight:o,headings:t,rowCount:r,rowHeight:n,size:l})=>{let a=(0,le.useRef)(0),s=Math.min(r,tl)*n,c=r*n-s,{pinnedWidthLeft:m,pinnedWidthRight:f,unpinnedWidth:b}=(0,le.useMemo)(()=>rl(e),[e]),[x,T]=(0,le.useMemo)(()=>(0,je.actualRowPositioning)(n),[n]),[d,v]=(0,le.useMemo)(()=>c?(0,je.virtualRowPositioning)(n,c,a):[x,T],[T,x,c,n]),y=(0,le.useCallback)(C=>{a.current=C},[]);return(0,le.useMemo)(()=>{var C;if(l){let P=t.length,D=15,M=m+b+f,k=M>l.width?D:0,L=o*(1+P),K=s-(((C=l==null?void 0:l.height)!=null?C:0)-k)+L,q=M-l.width+m,U=(l.height-o)/n,_=Number.isInteger(U)?U+1:Math.ceil(U),E=l.height-L,ee=s>E?D:0;return{contentHeight:s,getRowAtPosition:v,getRowOffset:d,horizontalScrollbarHeight:k,maxScrollContainerScrollHorizontal:q,maxScrollContainerScrollVertical:K,pinnedWidthLeft:m,pinnedWidthRight:f,rowCount:_,contentWidth:M,setPctScrollTop:y,totalHeaderHeight:L,verticalScrollbarWidth:ee,viewportBodyHeight:E}}else return nl},[l,t.length,m,b,f,s,o,n,v,d,y])};var Me=require("react"),on=({getRowAtPosition:e,setRange:o,viewportMeasurements:t})=>{let r=(0,Me.useRef)(0),{rowCount:n}=t,l=(0,Me.useCallback)(a=>{let i=e(a);i!==r.current&&(r.current=i,o({from:i,to:i+n}))},[e,o,n]);return(0,Me.useEffect)(()=>{let{current:a}=r,i={from:a,to:a+n};o(i)},[o,n]),{onVerticalScroll:l}};var tn=require("@vuu-ui/vuu-layout"),nn=require("@vuu-ui/vuu-utils"),J=require("react"),rn=({availableColumns:e,onAvailableColumnsChange:o,onConfigChange:t,onCreateCalculatedColumn:r,onDataSourceConfigChange:n,tableConfig:l})=>{let a=(0,tn.useLayoutProviderDispatch)(),i=(0,J.useRef)(),[s,u]=(0,J.useState)(e),c=(0,J.useCallback)((d,v,y)=>{a({type:"set-props",path:"#context-panel",props:{expanded:!0,content:{type:d,props:y},title:v}})},[a]),m=(0,J.useCallback)(()=>{requestAnimationFrame(()=>{var d;(d=i.current)==null||d.call(i)})},[]),f=(0,J.useCallback)(d=>{let v=s.concat({name:d.name,serverDataType:(0,nn.getCalculatedColumnType)(d)});u(v),o==null||o(v),requestAnimationFrame(()=>{var y;(y=i.current)==null||y.call(i)}),r(d)},[s,o,r]),b=(0,J.useCallback)(d=>{c("ColumnSettings","Column Settings",{column:d.column,onCancelCreateColumn:m,onConfigChange:t,onCreateCalculatedColumn:f,tableConfig:l,vuuTable:d.vuuTable})},[m,f,t,c,l]),x=(0,J.useCallback)(()=>{b({column:{name:"::",serverDataType:"string"},type:"columnSettings",vuuTable:{module:"SIMUL",table:"instruments"}})},[b]),T=(0,J.useCallback)(d=>{let v=l.columns.find(y=>y.name===d);v&&b({type:"columnSettings",column:v,vuuTable:{module:"SIMUL",table:"instruments"}})},[b,l.columns]);return i.current=(0,J.useCallback)(()=>{c("TableSettings","DataGrid Settings",{availableColumns:s!=null?s:l.columns.map(({name:d,serverDataType:v})=>({name:d,serverDataType:v})),onAddCalculatedColumn:x,onConfigChange:t,onDataSourceConfigChange:n,onNavigateToColumn:T,tableConfig:l})},[s,x,T,t,n,c,l]),{showColumnSettingsPanel:b,showTableSettingsPanel:i.current}};var qe=e=>e,{KEY:ll,IS_EXPANDED:ln,IS_LEAF:an}=F.metadataKeys,il={draggable:void 0,onMouseDown:void 0},al=()=>il,sl=(e,o)=>({...e,columns:e.columns.concat(o)}),un=({allowDragDrop:e=!1,availableColumns:o,config:t,containerRef:r,dataSource:n,disableFocus:l,headerHeight:a=25,highlightedIndex:i,id:s,navigationStyle:u="cell",onAvailableColumnsChange:c,onConfigChange:m,onDragStart:f,onDrop:b,onFeatureInvocation:x,onHighlight:T,onRowClick:d,onSelect:v,onSelectionChange:y,renderBufferSize:C=0,rowHeight:P=20,selectionModel:D,size:M})=>{let[k,L]=(0,H.useState)(n.size);if(n===void 0)throw Error("no data source provided to Vuu Table");let K=e?sn.useDragDropNext:al,q=(0,H.useMemo)(()=>Dt(n),[n]),U=(0,H.useCallback)(p=>{L(p)},[]),{columns:_,dispatchColumnAction:E,headings:ee,tableAttributes:Ee,tableConfig:I}=Ao(t,n);(0,F.useLayoutEffectSkipFirst)(()=>{E({type:"init",dataSource:n,tableConfig:I})},[I,n,E]);let Z=(0,H.useCallback)(p=>{E({type:"init",tableConfig:p,dataSource:n}),m==null||m(qe(p))},[n,E,m]),[g,h]=(0,H.useState)(),[R,A]=(0,H.useMemo)(()=>{let p=(S,V)=>{let B=(0,F.updateColumn)(_,S,{width:V});h(B)};return[g!=null?g:_,p]},[_,g]),N=(0,H.useMemo)(()=>(0,F.buildColumnMap)(n.columns),[n.columns]),{getRowAtPosition:Se,getRowOffset:Fo,setPctScrollTop:Ko,...oe}=Io({columns:R,headerHeight:a,headings:ee,rowCount:k,rowHeight:P,size:M}),fe=It({from:0,to:oe.rowCount}),so=(0,H.useCallback)(({tableSchema:p})=>{p?E({type:"setTableSchema",tableSchema:p}):console.log("subscription message with no schema")},[E]),{data:X,dataRef:Fe,getSelectedRows:uo,range:Ke,setRange:ge}=At({dataSource:n,onFeatureInvocation:x,renderBufferSize:C,onSizeChange:U,onSubscribed:so,range:fe}),Ln=(0,H.useCallback)(p=>{console.log("settings changed"),E({type:"init",tableConfig:p,dataSource:n}),m==null||m(qe(p))},[n,E,m]),An=(0,H.useCallback)(p=>{n.config={...n.config,...p}},[n]);(0,H.useEffect)(()=>{n.on("config",(p,S)=>{E({type:"tableConfig",...p,confirmed:S})})},[n,E]);let In=(0,H.useCallback)(p=>{n.columns=n.columns.concat(p.name),Z(sl(I,p))},[n,I,Z]),Go=(0,H.useCallback)(p=>{let{columns:S}=p,V=S.map(Q=>Q.name),B={...I,columns:I.columns.map(Q=>V.includes(Q.name)?{...Q,hidden:!0}:Q)};Z(B)},[I,Z]),$o=(0,H.useCallback)(p=>{Z({...I,columns:(0,F.updateColumn)(I.columns,{...p.column,pin:p.pin})})},[I,Z]),{showColumnSettingsPanel:Bo,showTableSettingsPanel:Oo}=rn({availableColumns:o!=null?o:I.columns.map(({name:p,serverDataType:S="string"})=>({name:p,serverDataType:S})),onAvailableColumnsChange:c,onConfigChange:Ln,onCreateCalculatedColumn:In,onDataSourceConfigChange:An,tableConfig:I}),zn=(0,H.useCallback)(p=>{if(ko(p))Bo(p);else if(Lo(p))Oo();else switch(p.type){case"hideColumns":return Go(p);case"pinColumn":return $o(p);default:E(p)}},[E,Go,$o,Bo,Oo]),Nn=Ht({dataSource:n,onPersistentColumnOperation:zn}),Vn=(0,H.useCallback)((p,S=!1,V)=>{n&&(n.sort=(0,F.applySort)(n.sort,p,S,V))},[n]),Fn=(0,H.useCallback)((p,S,V)=>{let B=R.find(Q=>Q.name===S);if(B)p==="resize"?(0,F.isValidNumber)(V)&&A(S,V):p==="end"?(0,F.isValidNumber)(V)&&(E({type:"resizeColumn",phase:p,column:B,width:V}),h(void 0),m==null||m(qe(yo(I,{type:"col-size",column:B,width:V})))):(h(void 0),E({type:"resizeColumn",phase:p,column:B,width:V}));else throw Error(`useDataTable.handleColumnResize, column ${S} not found`)},[R,I,E,m,A]),Kn=(0,H.useCallback)((p,S)=>{var Q,jo;let V=(0,F.isJsonGroup)(S,p),B=p[ll];if(p[ln]){if(n.closeTreeNode(B,!0),V){let ke=R.indexOf(S),Le=(Q=n.getRowsAtDepth)==null?void 0:Q.call(n,ke+1);Le&&!Le.some(Ce=>Ce[ln]||Ce[an])&&E({type:"hideColumns",columns:R.slice(ke+2)})}}else if(n.openTreeNode(B),V){let ke=(jo=n.getChildRows)==null?void 0:jo.call(n,B),Le=R.indexOf(S)+1,Ce=[R[Le]];ke&&ke.some(co=>co[an])&&Ce.push(R[Le+1]),Ce.some(co=>co.hidden)&&E({type:"showColumns",columns:Ce})}},[R,n,E]),{onVerticalScroll:Wo}=on({columns:R,getRowAtPosition:Se,setRange:ge,viewportMeasurements:oe}),Gn=(0,H.useCallback)(p=>{Wo(p)},[Wo]),{requestScroll:$n,...Bn}=en({maxScrollLeft:oe.maxScrollContainerScrollHorizontal,maxScrollTop:oe.maxScrollContainerScrollVertical,rowHeight:P,onVerticalScroll:Gn,viewportRowCount:oe.rowCount}),{highlightedIndexRef:Uo,navigate:On,onFocus:_o,onKeyDown:Xo,...Wn}=Gt({columnCount:R.filter(p=>p.hidden!==!0).length,containerRef:r,disableFocus:l,highlightedIndex:i,navigationStyle:u,requestScroll:$n,rowCount:n==null?void 0:n.size,onHighlight:T,viewportRange:Ke,viewportRowCount:oe.rowCount}),{onBlur:Un,onDoubleClick:_n,onKeyDown:Qo,onFocus:Jo}=Lt({navigate:On}),Xn=(0,H.useCallback)(p=>{_o(),p.defaultPrevented||Jo(p)},[Jo,_o]),Qn=Wt({columns:R,data:X,dataSource:n,getSelectedRows:uo}),Jn=(0,H.useCallback)(p=>{n.groupBy=p.map(S=>S.name)},[n]),Yn=(0,H.useCallback)(p=>{(0,F.isGroupColumn)(p)?n.groupBy=[]:n&&n.groupBy.includes(p.name)&&(n.groupBy=n.groupBy.filter(S=>S!==p.name))},[n]),Zn=(0,H.useCallback)(p=>{n.select(p),y==null||y(p)},[n,y]),{onKeyDown:Yo,onRowClick:Zo}=$t({highlightedIndexRef:Uo,onSelect:v,onSelectionChange:Zn,selectionModel:D}),jn=(0,H.useCallback)(p=>{Xo(p),p.defaultPrevented||Qo(p),p.defaultPrevented||Yo(p)},[Xo,Qo,Yo]),qn=(0,H.useCallback)((p,S,V)=>{Zo(p,S,V),d==null||d(p)},[d,Zo]);(0,F.useLayoutEffectSkipFirst)(()=>{E({type:"init",tableConfig:t,dataSource:n})},[t,n,E]);let er=(0,H.useCallback)(p=>{console.log("useTable onMoveColumn",{columns:p});let S={...I,columns:p};E({type:"init",tableConfig:S,dataSource:n}),m==null||m(qe(S))},[n,E,m,I]),or=(0,H.useCallback)(p=>{b==null||b(p)},[b]),tr=(0,H.useCallback)(async(p,S,V)=>n.applyEdit(p,S,V),[n]),nr=(0,H.useCallback)(p=>{let{initialDragElement:S}=p,V=(0,F.getIndexFromRowElement)(S),B=Fe.current.find(Q=>Q[0]===V);B&&p.setPayload(B),f==null||f(p)},[Fe,f]),{onMouseDown:rr,draggable:lr}=K({allowDragDrop:e,containerRef:r,draggableClassName:"vuuTable",id:s,onDragStart:nr,onDrop:or,orientation:"vertical",itemQuery:".vuuTableRow"});return{...Wn,"aria-rowcount":n.size,draggableRow:lr,onBlur:Un,onDoubleClick:_n,onFocus:Xn,onKeyDown:jn,onMouseDown:rr,columnMap:N,columns:R,data:X,handleContextMenuAction:Nn,headings:ee,highlightedIndex:Uo.current,menuBuilder:q,onContextMenu:Qn,onDataEdited:tr,onMoveColumn:er,onMoveGroupColumn:Jn,onRemoveGroupColumn:Yn,onRowClick:qn,onSortColumn:Vn,onResizeColumn:Fn,onToggleGroup:Kn,scrollProps:Bn,tableAttributes:Ee,tableConfig:I,viewportMeasurements:oe}};var eo=require("@vuu-ui/vuu-utils"),dn=j(require("clsx"));var cn=require("@vuu-ui/vuu-ui-controls"),He=require("@vuu-ui/vuu-utils"),ze=require("react"),mn=({columns:e,onMoveColumn:o,onSortColumn:t,tableConfig:r})=>{let n=(0,ze.useRef)(null),l=(0,ze.useCallback)((c,m)=>{let f=e[c],b=(0,He.moveColumnTo)(e,f,m),x=({name:y})=>C=>C.name===y,T=b.findIndex(x(f)),d=b[T+1],v=d?r.columns.findIndex(x(d)):-1;m>c&&v!==-1?o((0,He.moveColumnTo)(r.columns,f,v-1)):o((0,He.moveColumnTo)(r.columns,f,v))},[e,o,r.columns]),a=(0,ze.useCallback)(c=>{var d;let f=c.target.closest(".vuuTableHeaderCell"),b=parseInt((d=f==null?void 0:f.dataset.index)!=null?d:"-1"),x=(0,He.visibleColumnAtIndex)(e,b),T=c.shiftKey;x&&t(x,T)},[e,t]),{onMouseDown:i,draggable:s,...u}=(0,cn.useDragDropNext)({allowDragDrop:!0,containerRef:n,draggableClassName:"vuuTable",onDrop:l,orientation:"horizontal",itemQuery:".vuuTableHeaderCell"});return{containerRef:n,draggableColumn:s,draggedColumnIndex:u.draggedItemIndex,onClick:a,onMouseDown:i}};var ce=require("react/jsx-runtime"),pn=({classBase:e="vuuTable",columns:o,headings:t,onMoveColumn:r,onMoveGroupColumn:n,onRemoveGroupColumn:l,onResizeColumn:a,onSortColumn:i,tableConfig:s,tableId:u})=>{let{containerRef:c,draggableColumn:m,draggedColumnIndex:f,onClick:b,onMouseDown:x}=mn({columns:o,onMoveColumn:r,onSortColumn:i,tableConfig:s});return(0,ce.jsxs)("div",{className:`${e}-col-headings`,ref:c,children:[t.map((T,d)=>(0,ce.jsx)("div",{className:"vuuTable-heading",children:T.map(({label:v,width:y},C)=>(0,ce.jsx)("div",{className:"vuuTable-headingCell",style:{width:y},children:v},C))},d)),(0,ce.jsxs)("div",{className:`${e}-col-headers`,role:"row",children:[o.filter(eo.isNotHidden).map((T,d)=>(0,eo.isGroupColumn)(T)?(0,ce.jsx)(We,{column:T,"data-index":d,onMoveColumn:n,onRemoveColumn:l,onResize:a},T.name):(0,ce.jsx)(po,{className:(0,dn.default)({"vuuDraggable-dragAway":d===f}),column:T,"data-index":d,id:`${u}-col-${d}`,onClick:b,onMouseDown:x,onResize:a},T.name)),m]})]})};var Y=require("react/jsx-runtime"),ie="vuuTable",{IDX:bn,RENDER_IDX:ul}=oo.metadataKeys,cl=({Row:e=ho,allowDragDrop:o,availableColumns:t,config:r,containerRef:n,dataSource:l,disableFocus:a=!1,highlightedIndex:i,id:s,navigationStyle:u="cell",onAvailableColumnsChange:c,onConfigChange:m,onDragStart:f,onDrop:b,onFeatureInvocation:x,onHighlight:T,onRowClick:d,onSelect:v,onSelectionChange:y,renderBufferSize:C=0,rowHeight:P=20,selectionModel:D="extended",showColumnHeaders:M=!0,headerHeight:k=M?25:0,size:L})=>{let K=(0,oo.useId)(s),{columnMap:q,columns:U,data:_,draggableRow:E,handleContextMenuAction:ee,headings:Ee,highlightedIndex:I,onDataEdited:Z,onMoveColumn:g,onMoveGroupColumn:h,onRemoveGroupColumn:R,onResizeColumn:A,onRowClick:N,onSortColumn:Se,onToggleGroup:Fo,menuBuilder:Ko,scrollProps:oe,tableAttributes:fe,tableConfig:so,viewportMeasurements:X,...Fe}=un({allowDragDrop:o,availableColumns:t,config:r,containerRef:n,dataSource:l,disableFocus:a,headerHeight:k,highlightedIndex:i,id:K,navigationStyle:u,onAvailableColumnsChange:c,onConfigChange:m,onDragStart:f,onDrop:b,onFeatureInvocation:x,onHighlight:T,onRowClick:d,onSelect:v,onSelectionChange:y,renderBufferSize:C,rowHeight:P,selectionModel:D,size:L}),uo=(0,zo.default)(`${ie}-contentContainer`,{[`${ie}-colLines`]:fe.columnSeparators,[`${ie}-rowLines`]:fe.rowSeparators,[`${ie}-zebra`]:fe.zebraStripes}),Ke={"--content-height":`${X.contentHeight}px`,"--content-width":`${X.contentWidth}px`,"--horizontal-scrollbar-height":`${X.horizontalScrollbarHeight}px`,"--pinned-width-left":`${X.pinnedWidthLeft}px`,"--pinned-width-right":`${X.pinnedWidthRight}px`,"--header-height":`${k}px`,"--row-height":`${P}px`,"--total-header-height":`${X.totalHeaderHeight}px`,"--vertical-scrollbar-width":`${X.verticalScrollbarWidth}px`,"--viewport-body-height":`${X.viewportBodyHeight}px`};return(0,Y.jsxs)(gn.ContextMenuProvider,{menuActionHandler:ee,menuBuilder:Ko,children:[(0,Y.jsx)("div",{className:`${ie}-scrollbarContainer`,ref:oe.scrollbarContainerRef,style:Ke,children:(0,Y.jsx)("div",{className:`${ie}-scrollbarContent`})}),(0,Y.jsx)("div",{className:uo,ref:oe.contentContainerRef,style:Ke,children:(0,Y.jsxs)("div",{...Fe,className:`${ie}-table`,role:"table",tabIndex:a?void 0:-1,children:[M?(0,Y.jsx)(pn,{columns:U,headings:Ee,onMoveColumn:g,onMoveGroupColumn:h,onRemoveGroupColumn:R,onResizeColumn:A,onSortColumn:Se,tableConfig:so,tableId:K}):null,(0,Y.jsx)("div",{className:`${ie}-body`,children:_.map(ge=>(0,Y.jsx)(e,{columnMap:q,columns:U,highlighted:I===ge[bn],onClick:N,onDataEdited:Z,row:ge,offset:P*ge[bn]+X.totalHeaderHeight,onToggleGroup:Fo,zebraStripes:fe.zebraStripes},ge[ul]))})]})}),E]})},ml=(0,Pe.forwardRef)(function({Row:o,allowDragDrop:t,availableColumns:r,className:n,config:l,dataSource:a,disableFocus:i,highlightedIndex:s,id:u,navigationStyle:c,onAvailableColumnsChange:m,onConfigChange:f,onDragStart:b,onDrop:x,onFeatureInvocation:T,onHighlight:d,onRowClick:v,onSelect:y,onSelectionChange:C,renderBufferSize:P,rowHeight:D,selectionModel:M,showColumnHeaders:k,headerHeight:L,style:K,...q},U){let _=(0,Pe.useRef)(null),[E,ee]=(0,Pe.useState)();if(l===void 0)throw Error("vuu Table requires config prop. Minimum config is list of Column Descriptors");if(a===void 0)throw Error("vuu Table requires dataSource prop");return(0,Y.jsx)(fn.MeasuredContainer,{...q,className:(0,zo.default)(ie,n),id:u,onResize:ee,ref:(0,Cn.useForkRef)(_,U),children:E?(0,Y.jsx)(cl,{Row:o,allowDragDrop:t,availableColumns:r,config:l,containerRef:_,dataSource:a,disableFocus:i,headerHeight:L,highlightedIndex:s,id:u,navigationStyle:c,onAvailableColumnsChange:m,onConfigChange:f,onDragStart:b,onDrop:x,onFeatureInvocation:T,onHighlight:d,onRowClick:v,onSelect:y,onSelectionChange:C,renderBufferSize:P,rowHeight:D,selectionModel:M,showColumnHeaders:k,size:E}):null})});var to=require("react"),no=require("@vuu-ui/vuu-ui-controls"),vn=require("@salt-ds/core");var Ne=(e,o)=>e.column===o.column&&e.column.valueFormatter(e.row[e.columnMap[e.column.name]])===o.column.valueFormatter(o.row[o.columnMap[o.column.name]]);var ro=require("@vuu-ui/vuu-utils"),No=require("react/jsx-runtime"),Vo=(0,to.memo)(({column:e,columnMap:o,onCommit:t=no.WarnCommit,row:r})=>{let n=o[e.name],l=r[n],a=(0,to.useCallback)(i=>async s=>{let u=await t(i);return u===!0&&(0,ro.dispatchCustomEvent)(s.target,"vuu-commit"),u},[t]);return e.editable?(0,No.jsx)(vn.Checkbox,{checked:l,onClick:a(!l)}):(0,No.jsx)(no.CheckboxIcon,{checked:l,disabled:!0})},Ne);Vo.displayName="CheckboxCell";(0,ro.registerComponent)("checkbox-cell",Vo,"cell-renderer",{serverDataType:"boolean"});var hn=require("@vuu-ui/vuu-utils"),xn=require("@salt-ds/core"),Tn=require("@vuu-ui/vuu-ui-controls"),wn=j(require("clsx"));var io=require("react/jsx-runtime"),lo="vuuTableInputCell",dl=()=>(console.warn("onCommit handler has not been provided to InputCell cell renderer"),Promise.resolve(!0)),Rn=({column:e,columnMap:o,onCommit:t=dl,row:r})=>{let n=o[e.name],{align:l="left",clientSideEditValidationCheck:a}=e,{warningMessage:i,...s}=(0,Tn.useEditableText)({initialValue:r[n],onCommit:t,clientSideEditValidationCheck:a}),u=i&&l==="left"?(0,io.jsx)("span",{className:`${lo}-icon`,"data-icon":"error"}):void 0,c=i&&l==="right"?(0,io.jsx)("span",{className:`${lo}-icon`,"data-icon":"error"}):void 0;return(0,io.jsx)(xn.Input,{...s,className:(0,wn.default)(lo,{[`${lo}-error`]:i!==void 0}),endAdornment:u,startAdornment:c})};(0,hn.registerComponent)("input-cell",Rn,"cell-renderer",{});var Dn=require("@vuu-ui/vuu-ui-controls"),me=require("@vuu-ui/vuu-utils"),Mn=j(require("clsx")),ao=require("react");var Hn=require("@vuu-ui/vuu-ui-controls");var En=require("react/jsx-runtime"),yn="vuuTableToggleCell",pl=({name:e,type:o})=>{if((0,me.isTypeDescriptor)(o)&&(0,me.isValueListRenderer)(o.renderer))return o.renderer.values;throw Error(`useLookupValues column ${e} has not been configured with a values list`)},Pn=(0,ao.memo)(function({column:o,columnMap:t,onCommit:r=Dn.WarnCommit,row:n}){let l=pl(o),a=t[o.name],i=n[a],s=(0,ao.useCallback)((u,c)=>r(c).then(m=>(m===!0&&(0,me.dispatchCustomEvent)(u.target,"vuu-commit"),m)),[r]);return(0,En.jsx)(Hn.CycleStateButton,{className:(0,Mn.default)(yn,`${yn}-${o.name}`),onCommit:s,value:i,values:l,variant:"cta",children:i})},Ne);(0,me.registerComponent)("toggle-cell",Pn,"cell-renderer",{});var Sn=require("@vuu-ui/vuu-ui-controls"),kn=require("@vuu-ui/vuu-utils"),Ve=require("react"),bl=(e,o)=>{let t=(0,Ve.useRef)(null),[r,n]=(0,Sn.useStateRef)(e),l=(0,Ve.useCallback)(i=>{var s;if(i.key==="ArrowDown")n((u=-1)=>Math.min(o-1,u+1));else if(i.key==="ArrowUp")n((u=-1)=>Math.max(0,u-1));else if(i.key==="Enter"||i.key===" "){let{current:u}=r,c=(s=t.current)==null?void 0:s.querySelector(`[aria-rowindex="${u}"]`);c&&(0,kn.dispatchMouseEvent)(c,"click")}},[r,o,n]),a=(0,Ve.useCallback)(i=>{n(i)},[n]);return{highlightedIndexRef:r,onHighlight:a,onKeyDown:l,tableRef:t}};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
CheckboxCell: () => CheckboxCell,
|
|
34
|
+
GroupHeaderCellNext: () => GroupHeaderCellNext,
|
|
35
|
+
HeaderCell: () => HeaderCell,
|
|
36
|
+
InputCell: () => InputCell,
|
|
37
|
+
Table: () => Table,
|
|
38
|
+
TableCell: () => TableCell,
|
|
39
|
+
TableGroupCell: () => TableGroupCell,
|
|
40
|
+
ToggleCell: () => ToggleCell,
|
|
41
|
+
dataAndColumnUnchanged: () => dataAndColumnUnchanged,
|
|
42
|
+
howFarIsRowOutsideViewport: () => howFarIsRowOutsideViewport,
|
|
43
|
+
isShowColumnSettings: () => isShowColumnSettings,
|
|
44
|
+
isShowTableSettings: () => isShowTableSettings,
|
|
45
|
+
noScrolling: () => noScrolling,
|
|
46
|
+
updateTableConfig: () => updateTableConfig,
|
|
47
|
+
useControlledTableNavigation: () => useControlledTableNavigation,
|
|
48
|
+
useTableModel: () => useTableModel,
|
|
49
|
+
useTableScroll: () => useTableScroll,
|
|
50
|
+
useTableViewport: () => useTableViewport
|
|
51
|
+
});
|
|
52
|
+
module.exports = __toCommonJS(src_exports);
|
|
53
|
+
|
|
54
|
+
// src/header-cell/GroupHeaderCellNext.tsx
|
|
55
|
+
var import_vuu_layout = require("@vuu-ui/vuu-layout");
|
|
56
|
+
var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
|
|
57
|
+
var import_clsx3 = __toESM(require("clsx"));
|
|
58
|
+
var import_react5 = require("react");
|
|
59
|
+
|
|
60
|
+
// src/column-header-pill/ColumnHeaderPill.tsx
|
|
61
|
+
var import_clsx = __toESM(require("clsx"));
|
|
62
|
+
var import_react = require("react");
|
|
63
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
64
|
+
var classBase = "vuuColumnHeaderPill";
|
|
65
|
+
var ColumnHeaderPill = ({
|
|
66
|
+
children,
|
|
67
|
+
className,
|
|
68
|
+
column,
|
|
69
|
+
onRemove,
|
|
70
|
+
removable,
|
|
71
|
+
...htmlAttributes
|
|
72
|
+
}) => {
|
|
73
|
+
if (removable && typeof onRemove !== "function") {
|
|
74
|
+
throw Error(
|
|
75
|
+
"ColumnHeaderPill onRemove prop must be provided if Pill is removable"
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const handleClickRemove = (0, import_react.useCallback)(
|
|
79
|
+
(evt) => {
|
|
80
|
+
evt.preventDefault();
|
|
81
|
+
evt.stopPropagation();
|
|
82
|
+
onRemove == null ? void 0 : onRemove(column);
|
|
83
|
+
},
|
|
84
|
+
[column, onRemove]
|
|
85
|
+
);
|
|
86
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...htmlAttributes, className: (0, import_clsx.default)(classBase, className), children: [
|
|
87
|
+
children,
|
|
88
|
+
removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
89
|
+
"span",
|
|
90
|
+
{
|
|
91
|
+
className: `${classBase}-removeButton`,
|
|
92
|
+
role: "button",
|
|
93
|
+
"data-icon": "cross",
|
|
94
|
+
onClick: handleClickRemove
|
|
95
|
+
}
|
|
96
|
+
) : null
|
|
97
|
+
] });
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/column-header-pill/GroupColumnPill.tsx
|
|
101
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
102
|
+
var GroupColumnPill = ({
|
|
103
|
+
column,
|
|
104
|
+
...columnHeaderProps
|
|
105
|
+
}) => {
|
|
106
|
+
const { name, sorted } = column;
|
|
107
|
+
const icon = typeof sorted === "number" ? sorted < 0 ? "arrow-down" : "arrow-up" : sorted === "A" ? "arrow-up" : sorted === "D" ? "arrow-down" : void 0;
|
|
108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ColumnHeaderPill, { ...columnHeaderProps, column, children: [
|
|
109
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "vuuGroupColumnPill-label", children: name }),
|
|
110
|
+
icon !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-icon": icon }) : null,
|
|
111
|
+
typeof sorted === "number" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "vuuSortPosition", children: Math.abs(sorted) }) : null
|
|
112
|
+
] });
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/column-header-pill/SortIndicator.tsx
|
|
116
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
117
|
+
var SortIndicator = ({ column }) => {
|
|
118
|
+
if (!column.sorted) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const icon = typeof column.sorted === "number" ? column.sorted < 0 ? "arrow-down" : "arrow-up" : column.sorted === "A" ? "arrow-up" : "arrow-down";
|
|
122
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ColumnHeaderPill, { column, children: [
|
|
123
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-icon": icon }),
|
|
124
|
+
typeof column.sorted === "number" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vuuSortPosition", children: Math.abs(column.sorted) }) : null
|
|
125
|
+
] });
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/column-resizing/ColumnResizer.tsx
|
|
129
|
+
var import_react2 = require("react");
|
|
130
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
131
|
+
var NOOP = () => void 0;
|
|
132
|
+
var baseClass = "vuuColumnResizerNext";
|
|
133
|
+
var ColumnResizer = ({
|
|
134
|
+
onDrag,
|
|
135
|
+
onDragEnd = NOOP,
|
|
136
|
+
onDragStart = NOOP
|
|
137
|
+
}) => {
|
|
138
|
+
const position = (0, import_react2.useRef)(0);
|
|
139
|
+
const onMouseMove = (0, import_react2.useCallback)(
|
|
140
|
+
(e) => {
|
|
141
|
+
if (e.stopPropagation) {
|
|
142
|
+
e.stopPropagation();
|
|
143
|
+
}
|
|
144
|
+
if (e.preventDefault) {
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
}
|
|
147
|
+
const x = Math.round(e.clientX);
|
|
148
|
+
const moveBy = x - position.current;
|
|
149
|
+
position.current = x;
|
|
150
|
+
if (moveBy !== 0) {
|
|
151
|
+
onDrag(e, moveBy);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
[onDrag]
|
|
155
|
+
);
|
|
156
|
+
const onMouseUp = (0, import_react2.useCallback)(
|
|
157
|
+
(e) => {
|
|
158
|
+
window.removeEventListener("mouseup", onMouseUp);
|
|
159
|
+
window.removeEventListener("mousemove", onMouseMove);
|
|
160
|
+
onDragEnd(e);
|
|
161
|
+
},
|
|
162
|
+
[onDragEnd, onMouseMove]
|
|
163
|
+
);
|
|
164
|
+
const handleMouseDown = (0, import_react2.useCallback)(
|
|
165
|
+
(e) => {
|
|
166
|
+
onDragStart(e);
|
|
167
|
+
position.current = Math.round(e.clientX);
|
|
168
|
+
window.addEventListener("mouseup", onMouseUp);
|
|
169
|
+
window.addEventListener("mousemove", onMouseMove);
|
|
170
|
+
if (e.stopPropagation) {
|
|
171
|
+
e.stopPropagation();
|
|
172
|
+
}
|
|
173
|
+
if (e.preventDefault) {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
[onDragStart, onMouseMove, onMouseUp]
|
|
178
|
+
);
|
|
179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: baseClass, onMouseDown: handleMouseDown });
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/column-resizing/useTableColumnResize.tsx
|
|
183
|
+
var import_react3 = require("react");
|
|
184
|
+
var useTableColumnResize = ({
|
|
185
|
+
column,
|
|
186
|
+
onResize,
|
|
187
|
+
rootRef
|
|
188
|
+
}) => {
|
|
189
|
+
const widthRef = (0, import_react3.useRef)(0);
|
|
190
|
+
const [isResizing, setResizing] = (0, import_react3.useState)(false);
|
|
191
|
+
const { name } = column;
|
|
192
|
+
const handleResizeStart = (0, import_react3.useCallback)(() => {
|
|
193
|
+
if (onResize && rootRef.current) {
|
|
194
|
+
const { width } = rootRef.current.getBoundingClientRect();
|
|
195
|
+
widthRef.current = Math.round(width);
|
|
196
|
+
setResizing(true);
|
|
197
|
+
onResize == null ? void 0 : onResize("begin", name);
|
|
198
|
+
}
|
|
199
|
+
}, [name, onResize, rootRef]);
|
|
200
|
+
const handleResize = (0, import_react3.useCallback)(
|
|
201
|
+
(_evt, moveBy) => {
|
|
202
|
+
if (rootRef.current) {
|
|
203
|
+
if (onResize) {
|
|
204
|
+
const { width } = rootRef.current.getBoundingClientRect();
|
|
205
|
+
const newWidth = Math.round(width) + moveBy;
|
|
206
|
+
if (newWidth !== widthRef.current && newWidth > 0) {
|
|
207
|
+
onResize("resize", name, newWidth);
|
|
208
|
+
widthRef.current = newWidth;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
[name, onResize, rootRef]
|
|
214
|
+
);
|
|
215
|
+
const handleResizeEnd = (0, import_react3.useCallback)(() => {
|
|
216
|
+
if (onResize) {
|
|
217
|
+
onResize("end", name, widthRef.current);
|
|
218
|
+
setTimeout(() => {
|
|
219
|
+
setResizing(false);
|
|
220
|
+
}, 80);
|
|
221
|
+
}
|
|
222
|
+
}, [name, onResize]);
|
|
223
|
+
return {
|
|
224
|
+
isResizing,
|
|
225
|
+
onDrag: handleResize,
|
|
226
|
+
onDragStart: handleResizeStart,
|
|
227
|
+
onDragEnd: handleResizeEnd
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// src/useCell.ts
|
|
232
|
+
var import_vuu_utils = require("@vuu-ui/vuu-utils");
|
|
233
|
+
var import_clsx2 = __toESM(require("clsx"));
|
|
234
|
+
var import_react4 = require("react");
|
|
235
|
+
var useCell = (column, classBase10, isHeader) => (
|
|
236
|
+
// TODO measure perf without the memo, might not be worth the cost
|
|
237
|
+
(0, import_react4.useMemo)(() => {
|
|
238
|
+
const className = (0, import_clsx2.default)(classBase10, {
|
|
239
|
+
vuuPinFloating: column.pin === "floating",
|
|
240
|
+
vuuPinLeft: column.pin === "left",
|
|
241
|
+
vuuPinRight: column.pin === "right",
|
|
242
|
+
vuuEndPin: isHeader && column.endPin,
|
|
243
|
+
// [`${classBase}-resizing`]: column.resizing,
|
|
244
|
+
[`${classBase10}-editable`]: column.editable,
|
|
245
|
+
[`${classBase10}-right`]: column.align === "right"
|
|
246
|
+
});
|
|
247
|
+
const style = (0, import_vuu_utils.getColumnStyle)(column);
|
|
248
|
+
return {
|
|
249
|
+
className,
|
|
250
|
+
style
|
|
251
|
+
};
|
|
252
|
+
}, [column, classBase10, isHeader])
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// src/header-cell/GroupHeaderCellNext.tsx
|
|
256
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
257
|
+
var import_react6 = require("react");
|
|
258
|
+
var classBase2 = "vuuTableGroupHeaderCell";
|
|
259
|
+
var switchIfChanged = (columns, newColumns) => {
|
|
260
|
+
if (columns === newColumns) {
|
|
261
|
+
return columns;
|
|
262
|
+
} else {
|
|
263
|
+
return newColumns;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
var GroupHeaderCellNext = ({
|
|
267
|
+
column: groupColumn,
|
|
268
|
+
className: classNameProp,
|
|
269
|
+
onMoveColumn,
|
|
270
|
+
onRemoveColumn,
|
|
271
|
+
onResize,
|
|
272
|
+
...htmlAttributes
|
|
273
|
+
}) => {
|
|
274
|
+
const rootRef = (0, import_react5.useRef)(null);
|
|
275
|
+
const { isResizing, ...resizeProps } = useTableColumnResize({
|
|
276
|
+
column: groupColumn,
|
|
277
|
+
onResize,
|
|
278
|
+
rootRef
|
|
279
|
+
});
|
|
280
|
+
const [columns, setColumns] = (0, import_react5.useState)(groupColumn.columns);
|
|
281
|
+
const { className, style } = useCell(groupColumn, classBase2, true);
|
|
282
|
+
const columnPillProps = columns.length > 1 ? {
|
|
283
|
+
removable: true,
|
|
284
|
+
onRemove: onRemoveColumn
|
|
285
|
+
} : void 0;
|
|
286
|
+
const handleMoveItem = (0, import_react5.useCallback)(
|
|
287
|
+
(fromIndex, toIndex) => {
|
|
288
|
+
setColumns((cols) => {
|
|
289
|
+
const newCols = cols.slice();
|
|
290
|
+
const [tab] = newCols.splice(fromIndex, 1);
|
|
291
|
+
if (toIndex === -1) {
|
|
292
|
+
const result = newCols.concat(tab);
|
|
293
|
+
onMoveColumn == null ? void 0 : onMoveColumn(result);
|
|
294
|
+
return result;
|
|
295
|
+
} else {
|
|
296
|
+
newCols.splice(toIndex, 0, tab);
|
|
297
|
+
onMoveColumn == null ? void 0 : onMoveColumn(newCols);
|
|
298
|
+
return newCols;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
[onMoveColumn]
|
|
303
|
+
);
|
|
304
|
+
(0, import_vuu_utils2.useLayoutEffectSkipFirst)(() => {
|
|
305
|
+
setColumns((cols) => switchIfChanged(cols, groupColumn.columns));
|
|
306
|
+
}, [groupColumn.columns]);
|
|
307
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
308
|
+
"div",
|
|
309
|
+
{
|
|
310
|
+
...htmlAttributes,
|
|
311
|
+
className: (0, import_clsx3.default)(className, classNameProp, {
|
|
312
|
+
[`${classBase2}-pending`]: groupColumn.groupConfirmed === false
|
|
313
|
+
}),
|
|
314
|
+
ref: rootRef,
|
|
315
|
+
role: "columnheader",
|
|
316
|
+
style,
|
|
317
|
+
children: [
|
|
318
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
319
|
+
import_vuu_layout.OverflowContainer,
|
|
320
|
+
{
|
|
321
|
+
allowDragDrop: true,
|
|
322
|
+
className: `${classBase2}-inner`,
|
|
323
|
+
height: 24,
|
|
324
|
+
onMoveItem: handleMoveItem,
|
|
325
|
+
overflowPosition: "start",
|
|
326
|
+
children: columns.map((column) => {
|
|
327
|
+
return /* @__PURE__ */ (0, import_react6.createElement)(
|
|
328
|
+
GroupColumnPill,
|
|
329
|
+
{
|
|
330
|
+
...columnPillProps,
|
|
331
|
+
column,
|
|
332
|
+
key: column.key
|
|
333
|
+
}
|
|
334
|
+
);
|
|
335
|
+
})
|
|
336
|
+
}
|
|
337
|
+
),
|
|
338
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
339
|
+
ColumnHeaderPill,
|
|
340
|
+
{
|
|
341
|
+
column: groupColumn,
|
|
342
|
+
removable: true,
|
|
343
|
+
onRemove: onRemoveColumn
|
|
344
|
+
}
|
|
345
|
+
),
|
|
346
|
+
groupColumn.resizeable !== false ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ColumnResizer, { ...resizeProps }) : null
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// src/header-cell/HeaderCell.tsx
|
|
353
|
+
var import_clsx5 = __toESM(require("clsx"));
|
|
354
|
+
var import_react8 = require("react");
|
|
355
|
+
|
|
356
|
+
// src/column-menu/ColumnMenu.tsx
|
|
357
|
+
var import_vuu_popups = require("@vuu-ui/vuu-popups");
|
|
358
|
+
var import_clsx4 = __toESM(require("clsx"));
|
|
359
|
+
var import_react7 = require("react");
|
|
360
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
361
|
+
var getPosition = (element) => {
|
|
362
|
+
if (element) {
|
|
363
|
+
const { bottom, left } = element.getBoundingClientRect();
|
|
364
|
+
return { x: left, y: bottom + 6 };
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
var ColumnMenu = ({
|
|
368
|
+
className,
|
|
369
|
+
column,
|
|
370
|
+
...props
|
|
371
|
+
}) => {
|
|
372
|
+
const rootRef = (0, import_react7.useRef)(null);
|
|
373
|
+
const [menuOpen, setMenuOpen] = (0, import_react7.useState)(false);
|
|
374
|
+
const [showContextMenu] = (0, import_vuu_popups.useContextMenu)();
|
|
375
|
+
const handleMenuClose = (0, import_react7.useCallback)(() => {
|
|
376
|
+
setMenuOpen(false);
|
|
377
|
+
}, []);
|
|
378
|
+
const showColumnMenu = (0, import_react7.useCallback)(
|
|
379
|
+
(e) => {
|
|
380
|
+
setMenuOpen(true);
|
|
381
|
+
showContextMenu(e, "column-menu", {
|
|
382
|
+
column,
|
|
383
|
+
ContextMenuProps: {
|
|
384
|
+
onClose: handleMenuClose,
|
|
385
|
+
position: getPosition(rootRef.current)
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
},
|
|
389
|
+
[column, handleMenuClose, showContextMenu]
|
|
390
|
+
);
|
|
391
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
392
|
+
"span",
|
|
393
|
+
{
|
|
394
|
+
...props,
|
|
395
|
+
className: (0, import_clsx4.default)("vuuTable-columnMenu", className, {
|
|
396
|
+
"vuuTable-columnMenu-open": menuOpen
|
|
397
|
+
}),
|
|
398
|
+
"data-icon": "more-vert",
|
|
399
|
+
onClick: showColumnMenu,
|
|
400
|
+
ref: rootRef
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// src/header-cell/HeaderCell.tsx
|
|
406
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
407
|
+
var classBase3 = "vuuTableHeaderCell";
|
|
408
|
+
var HeaderCell = ({
|
|
409
|
+
className: classNameProp,
|
|
410
|
+
column,
|
|
411
|
+
onClick,
|
|
412
|
+
onResize,
|
|
413
|
+
...htmlAttributes
|
|
414
|
+
}) => {
|
|
415
|
+
var _a;
|
|
416
|
+
const { HeaderCellContentRenderer, HeaderCellLabelRenderer } = column;
|
|
417
|
+
const rootRef = (0, import_react8.useRef)(null);
|
|
418
|
+
const { isResizing, ...resizeProps } = useTableColumnResize({
|
|
419
|
+
column,
|
|
420
|
+
onResize,
|
|
421
|
+
rootRef
|
|
422
|
+
});
|
|
423
|
+
const handleClick = (0, import_react8.useCallback)(
|
|
424
|
+
(evt) => {
|
|
425
|
+
!isResizing && (onClick == null ? void 0 : onClick(evt));
|
|
426
|
+
},
|
|
427
|
+
[isResizing, onClick]
|
|
428
|
+
);
|
|
429
|
+
const { className, style } = useCell(column, classBase3, true);
|
|
430
|
+
const columnMenu = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ColumnMenu, { column });
|
|
431
|
+
const columnLabel = HeaderCellLabelRenderer ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderCellLabelRenderer, { className: `${classBase3}-label`, column }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `${classBase3}-label`, children: (_a = column.label) != null ? _a : column.name });
|
|
432
|
+
const columnContent = HeaderCellContentRenderer ? [/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderCellContentRenderer, { column }, "content")] : [];
|
|
433
|
+
const sortIndicator = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SortIndicator, { column });
|
|
434
|
+
const headerItems = column.align === "right" ? [sortIndicator, columnLabel].concat(columnContent).concat(columnMenu) : [columnMenu, columnLabel, sortIndicator].concat(columnContent);
|
|
435
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
436
|
+
"div",
|
|
437
|
+
{
|
|
438
|
+
...htmlAttributes,
|
|
439
|
+
className: (0, import_clsx5.default)(className, classNameProp, {
|
|
440
|
+
[`${classBase3}-resizing`]: isResizing
|
|
441
|
+
}),
|
|
442
|
+
onClick: handleClick,
|
|
443
|
+
ref: rootRef,
|
|
444
|
+
role: "columnheader",
|
|
445
|
+
style,
|
|
446
|
+
children: [
|
|
447
|
+
...headerItems,
|
|
448
|
+
column.resizeable !== false ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ColumnResizer, { ...resizeProps }) : null
|
|
449
|
+
]
|
|
450
|
+
}
|
|
451
|
+
);
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// src/Table.tsx
|
|
455
|
+
var import_vuu_layout3 = require("@vuu-ui/vuu-layout");
|
|
456
|
+
var import_vuu_popups3 = require("@vuu-ui/vuu-popups");
|
|
457
|
+
var import_vuu_utils22 = require("@vuu-ui/vuu-utils");
|
|
458
|
+
var import_core2 = require("@salt-ds/core");
|
|
459
|
+
var import_clsx9 = __toESM(require("clsx"));
|
|
460
|
+
var import_react25 = require("react");
|
|
461
|
+
|
|
462
|
+
// src/Row.tsx
|
|
463
|
+
var import_vuu_utils5 = require("@vuu-ui/vuu-utils");
|
|
464
|
+
var import_clsx7 = __toESM(require("clsx"));
|
|
465
|
+
var import_react11 = require("react");
|
|
466
|
+
|
|
467
|
+
// src/table-cell/TableCell.tsx
|
|
468
|
+
var import_vuu_utils3 = require("@vuu-ui/vuu-utils");
|
|
469
|
+
var import_react9 = require("react");
|
|
470
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
471
|
+
var classBase4 = "vuuTableCell";
|
|
472
|
+
var TableCell = ({
|
|
473
|
+
column,
|
|
474
|
+
columnMap,
|
|
475
|
+
onClick,
|
|
476
|
+
onDataEdited,
|
|
477
|
+
row
|
|
478
|
+
}) => {
|
|
479
|
+
const { className, style } = useCell(column, classBase4);
|
|
480
|
+
const { CellRenderer, name, valueFormatter } = column;
|
|
481
|
+
const dataIdx = columnMap[name];
|
|
482
|
+
const handleDataItemEdited = (0, import_react9.useCallback)(
|
|
483
|
+
(value) => {
|
|
484
|
+
if (onDataEdited) {
|
|
485
|
+
let typedValue = value;
|
|
486
|
+
if ((0, import_vuu_utils3.isNumericColumn)(column) && typeof value === "string") {
|
|
487
|
+
typedValue = column.serverDataType === "double" ? parseFloat(value) : parseInt(value);
|
|
488
|
+
}
|
|
489
|
+
return onDataEdited == null ? void 0 : onDataEdited(row, name, typedValue);
|
|
490
|
+
} else {
|
|
491
|
+
throw Error(
|
|
492
|
+
"TableCell onDataEdited prop not supplied for an editable cell"
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
[column, name, onDataEdited, row]
|
|
497
|
+
);
|
|
498
|
+
const handleClick = (0, import_react9.useCallback)(
|
|
499
|
+
(evt) => {
|
|
500
|
+
onClick == null ? void 0 : onClick(evt, column);
|
|
501
|
+
},
|
|
502
|
+
[column, onClick]
|
|
503
|
+
);
|
|
504
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
505
|
+
"div",
|
|
506
|
+
{
|
|
507
|
+
className,
|
|
508
|
+
onClick: onClick ? handleClick : void 0,
|
|
509
|
+
role: "cell",
|
|
510
|
+
style,
|
|
511
|
+
children: CellRenderer ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
512
|
+
CellRenderer,
|
|
513
|
+
{
|
|
514
|
+
column,
|
|
515
|
+
columnMap,
|
|
516
|
+
onCommit: handleDataItemEdited,
|
|
517
|
+
row
|
|
518
|
+
}
|
|
519
|
+
) : valueFormatter(row[dataIdx])
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
// src/table-cell/TableGroupCell.tsx
|
|
525
|
+
var import_vuu_utils4 = require("@vuu-ui/vuu-utils");
|
|
526
|
+
var import_react10 = require("react");
|
|
527
|
+
var import_clsx6 = __toESM(require("clsx"));
|
|
528
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
529
|
+
var { IS_LEAF } = import_vuu_utils4.metadataKeys;
|
|
530
|
+
var classBase5 = "vuuTableGroupCell";
|
|
531
|
+
var TableGroupCell = ({ column, onClick, row }) => {
|
|
532
|
+
const { columns } = column;
|
|
533
|
+
const [value, offset] = (0, import_vuu_utils4.getGroupValueAndOffset)(columns, row);
|
|
534
|
+
const { className, style } = useCell(column, classBase5);
|
|
535
|
+
const handleClick = (0, import_react10.useCallback)(
|
|
536
|
+
(evt) => {
|
|
537
|
+
onClick == null ? void 0 : onClick(evt, column);
|
|
538
|
+
},
|
|
539
|
+
[column, onClick]
|
|
540
|
+
);
|
|
541
|
+
const isLeaf = row[IS_LEAF];
|
|
542
|
+
const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${classBase5}-spacer` }, i));
|
|
543
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
544
|
+
"div",
|
|
545
|
+
{
|
|
546
|
+
className: (0, import_clsx6.default)(className, "vuuTableCell"),
|
|
547
|
+
role: "cell",
|
|
548
|
+
style,
|
|
549
|
+
onClick: isLeaf ? void 0 : handleClick,
|
|
550
|
+
children: [
|
|
551
|
+
spacers,
|
|
552
|
+
isLeaf ? null : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${classBase5}-toggle`, "data-icon": "triangle-right" }),
|
|
553
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: value })
|
|
554
|
+
]
|
|
555
|
+
}
|
|
556
|
+
);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// src/Row.tsx
|
|
560
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
561
|
+
var import_react12 = require("react");
|
|
562
|
+
var { IDX, IS_EXPANDED, SELECTED } = import_vuu_utils5.metadataKeys;
|
|
563
|
+
var classBase6 = "vuuTableRow";
|
|
564
|
+
var Row = (0, import_react11.memo)(
|
|
565
|
+
({
|
|
566
|
+
className: classNameProp,
|
|
567
|
+
columnMap,
|
|
568
|
+
columns,
|
|
569
|
+
highlighted,
|
|
570
|
+
row,
|
|
571
|
+
offset,
|
|
572
|
+
onClick,
|
|
573
|
+
onDataEdited,
|
|
574
|
+
onToggleGroup,
|
|
575
|
+
zebraStripes = false,
|
|
576
|
+
...htmlAttributes
|
|
577
|
+
}) => {
|
|
578
|
+
const {
|
|
579
|
+
[IDX]: rowIndex,
|
|
580
|
+
[IS_EXPANDED]: isExpanded,
|
|
581
|
+
[SELECTED]: selectionStatus
|
|
582
|
+
} = row;
|
|
583
|
+
const handleRowClick = (0, import_react11.useCallback)(
|
|
584
|
+
(evt) => {
|
|
585
|
+
const rangeSelect = evt.shiftKey;
|
|
586
|
+
const keepExistingSelection = evt.ctrlKey || evt.metaKey;
|
|
587
|
+
onClick == null ? void 0 : onClick(row, rangeSelect, keepExistingSelection);
|
|
588
|
+
},
|
|
589
|
+
[onClick, row]
|
|
590
|
+
);
|
|
591
|
+
const { True, First, Last } = import_vuu_utils5.RowSelected;
|
|
592
|
+
const className = (0, import_clsx7.default)(classBase6, classNameProp, {
|
|
593
|
+
[`${classBase6}-even`]: zebraStripes && rowIndex % 2 === 0,
|
|
594
|
+
[`${classBase6}-expanded`]: isExpanded,
|
|
595
|
+
[`${classBase6}-highlighted`]: highlighted,
|
|
596
|
+
[`${classBase6}-selected`]: selectionStatus & True,
|
|
597
|
+
[`${classBase6}-selectedStart`]: selectionStatus & First,
|
|
598
|
+
[`${classBase6}-selectedEnd`]: selectionStatus & Last
|
|
599
|
+
});
|
|
600
|
+
const style = { transform: `translate3d(0px, ${offset}px, 0px)` };
|
|
601
|
+
const handleGroupCellClick = (0, import_react11.useCallback)(
|
|
602
|
+
(evt, column) => {
|
|
603
|
+
if ((0, import_vuu_utils5.isGroupColumn)(column) || (0, import_vuu_utils5.isJsonGroup)(column, row)) {
|
|
604
|
+
evt.stopPropagation();
|
|
605
|
+
onToggleGroup == null ? void 0 : onToggleGroup(row, column);
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
[onToggleGroup, row]
|
|
609
|
+
);
|
|
610
|
+
return /* @__PURE__ */ (0, import_react12.createElement)(
|
|
611
|
+
"div",
|
|
612
|
+
{
|
|
613
|
+
...htmlAttributes,
|
|
614
|
+
key: `row-${row[0]}`,
|
|
615
|
+
role: "row",
|
|
616
|
+
className,
|
|
617
|
+
onClick: handleRowClick,
|
|
618
|
+
style
|
|
619
|
+
},
|
|
620
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: `${classBase6}-selectionDecorator vuuStickyLeft` }),
|
|
621
|
+
columns.filter(import_vuu_utils5.isNotHidden).map((column) => {
|
|
622
|
+
const isGroup = (0, import_vuu_utils5.isGroupColumn)(column);
|
|
623
|
+
const isJsonCell = (0, import_vuu_utils5.isJsonColumn)(column);
|
|
624
|
+
const Cell = isGroup ? TableGroupCell : TableCell;
|
|
625
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
626
|
+
Cell,
|
|
627
|
+
{
|
|
628
|
+
column,
|
|
629
|
+
columnMap,
|
|
630
|
+
onClick: isGroup || isJsonCell ? handleGroupCellClick : void 0,
|
|
631
|
+
onDataEdited,
|
|
632
|
+
row
|
|
633
|
+
},
|
|
634
|
+
column.key
|
|
635
|
+
);
|
|
636
|
+
}),
|
|
637
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: `${classBase6}-selectionDecorator vuuStickyRight` })
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
);
|
|
641
|
+
Row.displayName = "Row";
|
|
642
|
+
|
|
643
|
+
// src/useTable.ts
|
|
644
|
+
var import_vuu_ui_controls2 = require("@vuu-ui/vuu-ui-controls");
|
|
645
|
+
var import_vuu_utils19 = require("@vuu-ui/vuu-utils");
|
|
646
|
+
var import_react23 = require("react");
|
|
647
|
+
|
|
648
|
+
// src/context-menu/buildContextMenuDescriptors.ts
|
|
649
|
+
var import_vuu_utils6 = require("@vuu-ui/vuu-utils");
|
|
650
|
+
var buildContextMenuDescriptors = (dataSource) => (location, options) => {
|
|
651
|
+
const descriptors = [];
|
|
652
|
+
if (dataSource === void 0) {
|
|
653
|
+
return descriptors;
|
|
654
|
+
}
|
|
655
|
+
if (location === "header" || location === "column-menu") {
|
|
656
|
+
descriptors.push(
|
|
657
|
+
...buildSortMenuItems(options, dataSource)
|
|
658
|
+
);
|
|
659
|
+
descriptors.push(
|
|
660
|
+
...buildGroupMenuItems(options, dataSource)
|
|
661
|
+
);
|
|
662
|
+
descriptors.push(
|
|
663
|
+
...buildAggregationMenuItems(options, dataSource)
|
|
664
|
+
);
|
|
665
|
+
descriptors.push(...buildColumnDisplayMenuItems(options));
|
|
666
|
+
descriptors.push({
|
|
667
|
+
action: "column-settings",
|
|
668
|
+
icon: "cog",
|
|
669
|
+
label: `Column Settings`,
|
|
670
|
+
options
|
|
671
|
+
});
|
|
672
|
+
descriptors.push({
|
|
673
|
+
action: "table-settings",
|
|
674
|
+
icon: "cog",
|
|
675
|
+
label: `DataGrid Settings`,
|
|
676
|
+
options
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
return descriptors;
|
|
680
|
+
};
|
|
681
|
+
function buildSortMenuItems(options, { sort: { sortDefs } }) {
|
|
682
|
+
const { column } = options;
|
|
683
|
+
const menuItems = [];
|
|
684
|
+
if (column === void 0) {
|
|
685
|
+
return menuItems;
|
|
686
|
+
}
|
|
687
|
+
const hasSort = sortDefs.length > 0;
|
|
688
|
+
if (column.sorted === "A") {
|
|
689
|
+
menuItems.push({
|
|
690
|
+
label: "Reverse Sort (DSC)",
|
|
691
|
+
action: "sort-dsc",
|
|
692
|
+
options
|
|
693
|
+
});
|
|
694
|
+
} else if (column.sorted === "D") {
|
|
695
|
+
menuItems.push({
|
|
696
|
+
label: "Reverse Sort (ASC)",
|
|
697
|
+
action: "sort-asc",
|
|
698
|
+
options
|
|
699
|
+
});
|
|
700
|
+
} else if (typeof column.sorted === "number") {
|
|
701
|
+
if (column.sorted > 0) {
|
|
702
|
+
menuItems.push({
|
|
703
|
+
label: "Reverse Sort (DSC)",
|
|
704
|
+
action: "sort-add-dsc",
|
|
705
|
+
options
|
|
706
|
+
});
|
|
707
|
+
} else {
|
|
708
|
+
menuItems.push({
|
|
709
|
+
label: "Reverse Sort (ASC)",
|
|
710
|
+
action: "sort-add-asc",
|
|
711
|
+
options
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
if (hasSort && Math.abs(column.sorted) < sortDefs.length) {
|
|
715
|
+
menuItems.push({
|
|
716
|
+
label: "Remove from sort",
|
|
717
|
+
action: "sort-remove",
|
|
718
|
+
options
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
menuItems.push({
|
|
722
|
+
label: "New Sort",
|
|
723
|
+
children: [
|
|
724
|
+
{ label: "Ascending", action: "sort-asc", options },
|
|
725
|
+
{ label: "Descending", action: "sort-dsc", options }
|
|
726
|
+
]
|
|
727
|
+
});
|
|
728
|
+
} else if (hasSort) {
|
|
729
|
+
menuItems.push({
|
|
730
|
+
label: "Add to sort",
|
|
731
|
+
children: [
|
|
732
|
+
{ label: "Ascending", action: "sort-add-asc", options },
|
|
733
|
+
{ label: "Descending", action: "sort-add-dsc", options }
|
|
734
|
+
]
|
|
735
|
+
});
|
|
736
|
+
menuItems.push({
|
|
737
|
+
label: "New Sort",
|
|
738
|
+
children: [
|
|
739
|
+
{ label: "Ascending", action: "sort-asc", options },
|
|
740
|
+
{ label: "Descending", action: "sort-dsc", options }
|
|
741
|
+
]
|
|
742
|
+
});
|
|
743
|
+
} else {
|
|
744
|
+
menuItems.push({
|
|
745
|
+
label: "Sort",
|
|
746
|
+
children: [
|
|
747
|
+
{ label: "Ascending", action: "sort-asc", options },
|
|
748
|
+
{ label: "Descending", action: "sort-dsc", options }
|
|
749
|
+
]
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
return menuItems;
|
|
753
|
+
}
|
|
754
|
+
function buildAggregationMenuItems(options, dataSource) {
|
|
755
|
+
const { column } = options;
|
|
756
|
+
if (column === void 0 || dataSource.groupBy.length === 0) {
|
|
757
|
+
return [];
|
|
758
|
+
}
|
|
759
|
+
const { name, label = name } = column;
|
|
760
|
+
return [
|
|
761
|
+
{
|
|
762
|
+
label: `Aggregate ${label}`,
|
|
763
|
+
children: [
|
|
764
|
+
{ label: "Count", action: "agg-count", options },
|
|
765
|
+
{ label: "Distinct", action: "agg-distinct", options }
|
|
766
|
+
].concat(
|
|
767
|
+
(0, import_vuu_utils6.isNumericColumn)(column) ? [
|
|
768
|
+
{ label: "Sum", action: "agg-sum", options },
|
|
769
|
+
{ label: "Avg", action: "agg-avg", options },
|
|
770
|
+
{ label: "High", action: "agg-high", options },
|
|
771
|
+
{ label: "Low", action: "agg-low", options }
|
|
772
|
+
] : []
|
|
773
|
+
)
|
|
774
|
+
}
|
|
775
|
+
];
|
|
776
|
+
}
|
|
777
|
+
var pinColumn = (options, pinLocation) => ({
|
|
778
|
+
label: `Pin ${pinLocation}`,
|
|
779
|
+
action: `column-pin-${pinLocation}`,
|
|
780
|
+
options
|
|
781
|
+
});
|
|
782
|
+
var pinLeft = (options) => pinColumn(options, "left");
|
|
783
|
+
var pinFloating = (options) => pinColumn(options, "floating");
|
|
784
|
+
var pinRight = (options) => pinColumn(options, "right");
|
|
785
|
+
function buildColumnDisplayMenuItems(options) {
|
|
786
|
+
const { column } = options;
|
|
787
|
+
if (column === void 0) {
|
|
788
|
+
return [];
|
|
789
|
+
}
|
|
790
|
+
const { pin } = column;
|
|
791
|
+
const menuItems = [
|
|
792
|
+
{
|
|
793
|
+
label: `Hide column`,
|
|
794
|
+
action: "column-hide",
|
|
795
|
+
options
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
label: `Remove column`,
|
|
799
|
+
action: "column-remove",
|
|
800
|
+
options
|
|
801
|
+
}
|
|
802
|
+
];
|
|
803
|
+
if (pin === void 0) {
|
|
804
|
+
menuItems.push({
|
|
805
|
+
label: `Pin column`,
|
|
806
|
+
children: [pinLeft(options), pinFloating(options), pinRight(options)]
|
|
807
|
+
});
|
|
808
|
+
} else if (pin === "left") {
|
|
809
|
+
menuItems.push(
|
|
810
|
+
{ label: "Unpin column", action: "column-unpin", options },
|
|
811
|
+
{
|
|
812
|
+
label: `Pin column`,
|
|
813
|
+
children: [pinFloating(options), pinRight(options)]
|
|
814
|
+
}
|
|
815
|
+
);
|
|
816
|
+
} else if (pin === "right") {
|
|
817
|
+
menuItems.push(
|
|
818
|
+
{ label: "Unpin column", action: "column-unpin", options },
|
|
819
|
+
{
|
|
820
|
+
label: `Pin column`,
|
|
821
|
+
children: [pinLeft(options), pinFloating(options)]
|
|
822
|
+
}
|
|
823
|
+
);
|
|
824
|
+
} else if (pin === "floating") {
|
|
825
|
+
menuItems.push(
|
|
826
|
+
{ label: "Unpin column", action: "column-unpin", options },
|
|
827
|
+
{
|
|
828
|
+
label: `Pin column`,
|
|
829
|
+
children: [pinLeft(options), pinRight(options)]
|
|
830
|
+
}
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
return menuItems;
|
|
834
|
+
}
|
|
835
|
+
function buildGroupMenuItems(options, { groupBy }) {
|
|
836
|
+
const { column } = options;
|
|
837
|
+
const menuItems = [];
|
|
838
|
+
if (column === void 0) {
|
|
839
|
+
return menuItems;
|
|
840
|
+
}
|
|
841
|
+
const { name, label = name } = column;
|
|
842
|
+
if (groupBy.length === 0) {
|
|
843
|
+
menuItems.push({
|
|
844
|
+
label: `Group by ${label}`,
|
|
845
|
+
action: "group",
|
|
846
|
+
options
|
|
847
|
+
});
|
|
848
|
+
} else {
|
|
849
|
+
menuItems.push({
|
|
850
|
+
label: `Add ${label} to group by`,
|
|
851
|
+
action: "group-add",
|
|
852
|
+
options
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
return menuItems;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/context-menu/useHandleTableContextMenu.ts
|
|
859
|
+
var import_vuu_utils7 = require("@vuu-ui/vuu-utils");
|
|
860
|
+
var import_vuu_utils8 = require("@vuu-ui/vuu-utils");
|
|
861
|
+
var removeFilterColumn = (dataSourceFilter, column) => {
|
|
862
|
+
if (dataSourceFilter.filterStruct && column) {
|
|
863
|
+
const [filterStruct, filter] = (0, import_vuu_utils7.removeColumnFromFilter)(
|
|
864
|
+
column,
|
|
865
|
+
dataSourceFilter.filterStruct
|
|
866
|
+
);
|
|
867
|
+
return {
|
|
868
|
+
filter,
|
|
869
|
+
filterStruct
|
|
870
|
+
};
|
|
871
|
+
} else {
|
|
872
|
+
return dataSourceFilter;
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
var { Average, Count, Distinct, High, Low, Sum } = import_vuu_utils8.AggregationType;
|
|
876
|
+
var useHandleTableContextMenu = ({
|
|
877
|
+
dataSource,
|
|
878
|
+
onPersistentColumnOperation
|
|
879
|
+
}) => {
|
|
880
|
+
const handleContextMenuAction = (action) => {
|
|
881
|
+
const gridOptions = action.options;
|
|
882
|
+
if (gridOptions.column && dataSource) {
|
|
883
|
+
const { column } = gridOptions;
|
|
884
|
+
switch (action.menuId) {
|
|
885
|
+
case "sort-asc":
|
|
886
|
+
return dataSource.sort = (0, import_vuu_utils8.setSortColumn)(dataSource.sort, column, "A"), true;
|
|
887
|
+
case "sort-dsc":
|
|
888
|
+
return dataSource.sort = (0, import_vuu_utils8.setSortColumn)(dataSource.sort, column, "D"), true;
|
|
889
|
+
case "sort-add-asc":
|
|
890
|
+
return dataSource.sort = (0, import_vuu_utils8.addSortColumn)(dataSource.sort, column, "A"), true;
|
|
891
|
+
case "sort-add-dsc":
|
|
892
|
+
return dataSource.sort = (0, import_vuu_utils8.addSortColumn)(dataSource.sort, column, "D"), true;
|
|
893
|
+
case "group":
|
|
894
|
+
return dataSource.groupBy = (0, import_vuu_utils8.addGroupColumn)(dataSource.groupBy, column), true;
|
|
895
|
+
case "group-add":
|
|
896
|
+
return dataSource.groupBy = (0, import_vuu_utils8.addGroupColumn)(dataSource.groupBy, column), true;
|
|
897
|
+
case "column-hide":
|
|
898
|
+
return onPersistentColumnOperation({ type: "hideColumns", columns: [column] }), true;
|
|
899
|
+
case "column-remove":
|
|
900
|
+
return dataSource.columns = dataSource.columns.filter((name) => name !== column.name), true;
|
|
901
|
+
case "filter-remove-column":
|
|
902
|
+
return dataSource.filter = removeFilterColumn(dataSource.filter, column), true;
|
|
903
|
+
case "remove-filters":
|
|
904
|
+
return dataSource.filter = { filter: "" }, true;
|
|
905
|
+
case "agg-avg":
|
|
906
|
+
return dataSource.aggregations = (0, import_vuu_utils8.setAggregations)(dataSource.aggregations, column, Average), true;
|
|
907
|
+
case "agg-high":
|
|
908
|
+
return dataSource.aggregations = (0, import_vuu_utils8.setAggregations)(dataSource.aggregations, column, High), true;
|
|
909
|
+
case "agg-low":
|
|
910
|
+
return dataSource.aggregations = (0, import_vuu_utils8.setAggregations)(dataSource.aggregations, column, Low), true;
|
|
911
|
+
case "agg-count":
|
|
912
|
+
return dataSource.aggregations = (0, import_vuu_utils8.setAggregations)(dataSource.aggregations, column, Count), true;
|
|
913
|
+
case "agg-distinct":
|
|
914
|
+
return dataSource.aggregations = (0, import_vuu_utils8.setAggregations)(dataSource.aggregations, column, Distinct), true;
|
|
915
|
+
case "agg-sum":
|
|
916
|
+
return dataSource.aggregations = (0, import_vuu_utils8.setAggregations)(dataSource.aggregations, column, Sum), true;
|
|
917
|
+
case "column-pin-floating":
|
|
918
|
+
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "floating" }), true;
|
|
919
|
+
case "column-pin-left":
|
|
920
|
+
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "left" }), true;
|
|
921
|
+
case "column-pin-right":
|
|
922
|
+
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "right" }), true;
|
|
923
|
+
case "column-unpin":
|
|
924
|
+
return onPersistentColumnOperation({ type: "pinColumn", column, pin: void 0 }), true;
|
|
925
|
+
case "column-settings":
|
|
926
|
+
return onPersistentColumnOperation({ type: "columnSettings", column }), true;
|
|
927
|
+
case "table-settings":
|
|
928
|
+
return onPersistentColumnOperation({ type: "tableSettings" }), true;
|
|
929
|
+
default:
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return false;
|
|
933
|
+
};
|
|
934
|
+
return handleContextMenuAction;
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
// src/table-config.ts
|
|
938
|
+
var updateTableConfig = (config, action) => {
|
|
939
|
+
switch (action.type) {
|
|
940
|
+
case "col-size":
|
|
941
|
+
return {
|
|
942
|
+
...config,
|
|
943
|
+
columns: config.columns.map(
|
|
944
|
+
(col) => col.name === action.column.name ? { ...col, width: action.width } : col
|
|
945
|
+
)
|
|
946
|
+
};
|
|
947
|
+
case "column-prop":
|
|
948
|
+
return {
|
|
949
|
+
...config,
|
|
950
|
+
columns: config.columns.map(
|
|
951
|
+
(col) => col.name === action.column.name ? { ...col, [action.property]: action.value } : col
|
|
952
|
+
)
|
|
953
|
+
};
|
|
954
|
+
default:
|
|
955
|
+
return config;
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
// src/useCellEditing.ts
|
|
960
|
+
var import_vuu_utils9 = require("@vuu-ui/vuu-utils");
|
|
961
|
+
var import_react13 = require("react");
|
|
962
|
+
|
|
963
|
+
// src/table-dom-utils.ts
|
|
964
|
+
var headerCellQuery = (colIdx) => `.vuuTable-col-headers .vuuTableHeaderCell:nth-child(${colIdx})`;
|
|
965
|
+
var dataCellQuery = (rowIdx, colIdx) => `.vuuTable-body > [aria-rowindex='${rowIdx + 1}'] > [role='cell']:nth-child(${colIdx + 1})`;
|
|
966
|
+
var getTableCell = (containerRef, [rowIdx, colIdx]) => {
|
|
967
|
+
var _a;
|
|
968
|
+
const cssQuery = rowIdx === -1 ? headerCellQuery(colIdx) : dataCellQuery(rowIdx, colIdx);
|
|
969
|
+
const cell = (_a = containerRef.current) == null ? void 0 : _a.querySelector(
|
|
970
|
+
cssQuery
|
|
971
|
+
);
|
|
972
|
+
if (cellIsEditable(cell)) {
|
|
973
|
+
const focusableContent = cell.querySelector("button");
|
|
974
|
+
return focusableContent || cell;
|
|
975
|
+
} else {
|
|
976
|
+
return cell;
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
var cellIsEditable = (cell) => cell.classList.contains("vuuTableCell-editable");
|
|
980
|
+
var cellIsTextInput = (cell) => cell.querySelector(".vuuTableInputCell") !== null;
|
|
981
|
+
function getRowIndex(rowEl) {
|
|
982
|
+
if (rowEl) {
|
|
983
|
+
const idx = rowEl.ariaRowIndex;
|
|
984
|
+
if (idx !== null) {
|
|
985
|
+
return parseInt(idx, 10) - 1;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
return -1;
|
|
989
|
+
}
|
|
990
|
+
var closestRow = (el) => el.closest('[role="row"]');
|
|
991
|
+
var closestRowIndex = (el) => getRowIndex(closestRow(el));
|
|
992
|
+
|
|
993
|
+
// src/useCellEditing.ts
|
|
994
|
+
var useCellEditing = ({ navigate }) => {
|
|
995
|
+
const commitHandler = (0, import_react13.useCallback)(() => {
|
|
996
|
+
navigate();
|
|
997
|
+
}, [navigate]);
|
|
998
|
+
const editInput = (0, import_react13.useCallback)(
|
|
999
|
+
(evt) => {
|
|
1000
|
+
const cellEl = evt.target;
|
|
1001
|
+
const input = cellEl.matches("input") ? cellEl : cellEl.querySelector("input");
|
|
1002
|
+
if (input) {
|
|
1003
|
+
input.focus();
|
|
1004
|
+
input.select();
|
|
1005
|
+
}
|
|
1006
|
+
},
|
|
1007
|
+
[]
|
|
1008
|
+
);
|
|
1009
|
+
const focusInput = (0, import_react13.useCallback)(
|
|
1010
|
+
(evt) => {
|
|
1011
|
+
const cellEl = evt.target;
|
|
1012
|
+
const input = cellEl.querySelector("input");
|
|
1013
|
+
if (input) {
|
|
1014
|
+
input.focus();
|
|
1015
|
+
input.select();
|
|
1016
|
+
}
|
|
1017
|
+
},
|
|
1018
|
+
[]
|
|
1019
|
+
);
|
|
1020
|
+
const handleKeyDown = (0, import_react13.useCallback)(
|
|
1021
|
+
(e) => {
|
|
1022
|
+
const el = e.target;
|
|
1023
|
+
if (cellIsTextInput(el)) {
|
|
1024
|
+
if ((0, import_vuu_utils9.isCharacterKey)(e.key)) {
|
|
1025
|
+
editInput(e);
|
|
1026
|
+
} else if (e.key === "Enter") {
|
|
1027
|
+
focusInput(e);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
[editInput, focusInput]
|
|
1032
|
+
);
|
|
1033
|
+
const handleDoubleClick = (0, import_react13.useCallback)(
|
|
1034
|
+
(e) => {
|
|
1035
|
+
const el = e.target;
|
|
1036
|
+
if (el.matches("input") || el.querySelector("input")) {
|
|
1037
|
+
editInput(e);
|
|
1038
|
+
e.stopPropagation();
|
|
1039
|
+
}
|
|
1040
|
+
},
|
|
1041
|
+
[editInput]
|
|
1042
|
+
);
|
|
1043
|
+
const handleBlur = (0, import_react13.useCallback)(
|
|
1044
|
+
(e) => {
|
|
1045
|
+
const el = e.target;
|
|
1046
|
+
el.removeEventListener("vuu-commit", commitHandler, true);
|
|
1047
|
+
},
|
|
1048
|
+
[commitHandler]
|
|
1049
|
+
);
|
|
1050
|
+
const handleFocus = (0, import_react13.useCallback)(
|
|
1051
|
+
(e) => {
|
|
1052
|
+
const el = e.target;
|
|
1053
|
+
el.addEventListener("vuu-commit", commitHandler, true);
|
|
1054
|
+
},
|
|
1055
|
+
[commitHandler]
|
|
1056
|
+
);
|
|
1057
|
+
return {
|
|
1058
|
+
onBlur: handleBlur,
|
|
1059
|
+
onDoubleClick: handleDoubleClick,
|
|
1060
|
+
onFocus: handleFocus,
|
|
1061
|
+
onKeyDown: handleKeyDown
|
|
1062
|
+
};
|
|
1063
|
+
};
|
|
1064
|
+
|
|
1065
|
+
// src/useDataSource.ts
|
|
1066
|
+
var import_vuu_utils11 = require("@vuu-ui/vuu-utils");
|
|
1067
|
+
var import_react14 = require("react");
|
|
1068
|
+
|
|
1069
|
+
// src/moving-window.ts
|
|
1070
|
+
var import_vuu_utils10 = require("@vuu-ui/vuu-utils");
|
|
1071
|
+
var { SELECTED: SELECTED2 } = import_vuu_utils10.metadataKeys;
|
|
1072
|
+
var MovingWindow = class {
|
|
1073
|
+
constructor({ from, to }) {
|
|
1074
|
+
this.rowCount = 0;
|
|
1075
|
+
this.setRowCount = (rowCount) => {
|
|
1076
|
+
if (rowCount < this.data.length) {
|
|
1077
|
+
this.data.length = rowCount;
|
|
1078
|
+
}
|
|
1079
|
+
this.rowCount = rowCount;
|
|
1080
|
+
};
|
|
1081
|
+
this.range = new import_vuu_utils10.WindowRange(from, to);
|
|
1082
|
+
this.data = new Array(Math.max(0, to - from));
|
|
1083
|
+
this.rowCount = 0;
|
|
1084
|
+
}
|
|
1085
|
+
add(data) {
|
|
1086
|
+
const [index] = data;
|
|
1087
|
+
if (this.isWithinRange(index)) {
|
|
1088
|
+
const internalIndex = index - this.range.from;
|
|
1089
|
+
this.data[internalIndex] = data;
|
|
1090
|
+
if (data[SELECTED2]) {
|
|
1091
|
+
const previousRow = this.data[internalIndex - 1];
|
|
1092
|
+
if ((0, import_vuu_utils10.isRowSelectedLast)(previousRow)) {
|
|
1093
|
+
this.data[internalIndex - 1] = previousRow.slice();
|
|
1094
|
+
this.data[internalIndex - 1][SELECTED2] -= 4;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
getAtIndex(index) {
|
|
1100
|
+
return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
|
|
1101
|
+
}
|
|
1102
|
+
isWithinRange(index) {
|
|
1103
|
+
return this.range.isWithin(index);
|
|
1104
|
+
}
|
|
1105
|
+
setRange({ from, to }) {
|
|
1106
|
+
if (from !== this.range.from || to !== this.range.to) {
|
|
1107
|
+
const [overlapFrom, overlapTo] = this.range.overlap(from, to);
|
|
1108
|
+
const newData = new Array(Math.max(0, to - from));
|
|
1109
|
+
for (let i = overlapFrom; i < overlapTo; i++) {
|
|
1110
|
+
const data = this.getAtIndex(i);
|
|
1111
|
+
if (data) {
|
|
1112
|
+
const index = i - from;
|
|
1113
|
+
newData[index] = data;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
this.data = newData;
|
|
1117
|
+
this.range.from = from;
|
|
1118
|
+
this.range.to = to;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
getSelectedRows() {
|
|
1122
|
+
return this.data.filter((row) => row[SELECTED2] !== 0);
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
|
|
1126
|
+
// src/useDataSource.ts
|
|
1127
|
+
var isVuuFeatureInvocation = (action) => action.type === "vuu-link-created" || action.type === "vuu-link-removed";
|
|
1128
|
+
var useDataSource = ({
|
|
1129
|
+
dataSource,
|
|
1130
|
+
onFeatureInvocation,
|
|
1131
|
+
onSizeChange,
|
|
1132
|
+
onSubscribed,
|
|
1133
|
+
range = import_vuu_utils11.NULL_RANGE,
|
|
1134
|
+
renderBufferSize = 0
|
|
1135
|
+
}) => {
|
|
1136
|
+
const [, forceUpdate] = (0, import_react14.useState)(null);
|
|
1137
|
+
const data = (0, import_react14.useRef)([]);
|
|
1138
|
+
const isMounted = (0, import_react14.useRef)(true);
|
|
1139
|
+
const hasUpdated = (0, import_react14.useRef)(false);
|
|
1140
|
+
const rangeRef = (0, import_react14.useRef)(import_vuu_utils11.NULL_RANGE);
|
|
1141
|
+
const dataWindow = (0, import_react14.useMemo)(
|
|
1142
|
+
() => new MovingWindow((0, import_vuu_utils11.getFullRange)(range, renderBufferSize)),
|
|
1143
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1144
|
+
[]
|
|
1145
|
+
);
|
|
1146
|
+
const setData = (0, import_react14.useCallback)(
|
|
1147
|
+
(updates) => {
|
|
1148
|
+
for (const row of updates) {
|
|
1149
|
+
dataWindow.add(row);
|
|
1150
|
+
}
|
|
1151
|
+
data.current = dataWindow.data;
|
|
1152
|
+
if (isMounted.current) {
|
|
1153
|
+
forceUpdate({});
|
|
1154
|
+
} else {
|
|
1155
|
+
console.log(`ignore update as we're not mounted`);
|
|
1156
|
+
}
|
|
1157
|
+
},
|
|
1158
|
+
[dataWindow]
|
|
1159
|
+
);
|
|
1160
|
+
const datasourceMessageHandler = (0, import_react14.useCallback)(
|
|
1161
|
+
(message) => {
|
|
1162
|
+
if (message.type === "subscribed") {
|
|
1163
|
+
onSubscribed == null ? void 0 : onSubscribed(message);
|
|
1164
|
+
} else if (message.type === "viewport-update") {
|
|
1165
|
+
if (typeof message.size === "number") {
|
|
1166
|
+
onSizeChange == null ? void 0 : onSizeChange(message.size);
|
|
1167
|
+
dataWindow.setRowCount(message.size);
|
|
1168
|
+
}
|
|
1169
|
+
if (message.rows) {
|
|
1170
|
+
setData(message.rows);
|
|
1171
|
+
} else if (typeof message.size === "number") {
|
|
1172
|
+
data.current = dataWindow.data;
|
|
1173
|
+
hasUpdated.current = true;
|
|
1174
|
+
}
|
|
1175
|
+
} else if (isVuuFeatureInvocation(message)) {
|
|
1176
|
+
onFeatureInvocation == null ? void 0 : onFeatureInvocation(message);
|
|
1177
|
+
} else {
|
|
1178
|
+
console.log(`useDataSource unexpected message ${message.type}`);
|
|
1179
|
+
}
|
|
1180
|
+
},
|
|
1181
|
+
[dataWindow, onFeatureInvocation, onSizeChange, onSubscribed, setData]
|
|
1182
|
+
);
|
|
1183
|
+
const getSelectedRows = (0, import_react14.useCallback)(() => {
|
|
1184
|
+
return dataWindow.getSelectedRows();
|
|
1185
|
+
}, [dataWindow]);
|
|
1186
|
+
(0, import_react14.useEffect)(() => {
|
|
1187
|
+
var _a;
|
|
1188
|
+
isMounted.current = true;
|
|
1189
|
+
(_a = dataSource.resume) == null ? void 0 : _a.call(dataSource);
|
|
1190
|
+
return () => {
|
|
1191
|
+
var _a2;
|
|
1192
|
+
isMounted.current = false;
|
|
1193
|
+
(_a2 = dataSource.suspend) == null ? void 0 : _a2.call(dataSource);
|
|
1194
|
+
};
|
|
1195
|
+
}, [dataSource]);
|
|
1196
|
+
(0, import_react14.useEffect)(() => {
|
|
1197
|
+
var _a;
|
|
1198
|
+
if (dataSource.status === "disabled") {
|
|
1199
|
+
(_a = dataSource.enable) == null ? void 0 : _a.call(dataSource, datasourceMessageHandler);
|
|
1200
|
+
} else {
|
|
1201
|
+
dataSource == null ? void 0 : dataSource.subscribe(
|
|
1202
|
+
{ range: (0, import_vuu_utils11.getFullRange)(range, renderBufferSize) },
|
|
1203
|
+
datasourceMessageHandler
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
}, [dataSource, datasourceMessageHandler, range, renderBufferSize]);
|
|
1207
|
+
const setRange = (0, import_react14.useCallback)(
|
|
1208
|
+
(range2) => {
|
|
1209
|
+
const fullRange = (0, import_vuu_utils11.getFullRange)(range2, renderBufferSize);
|
|
1210
|
+
dataWindow.setRange(fullRange);
|
|
1211
|
+
dataSource.range = rangeRef.current = fullRange;
|
|
1212
|
+
dataSource.emit("range", range2);
|
|
1213
|
+
},
|
|
1214
|
+
[dataSource, dataWindow, renderBufferSize]
|
|
1215
|
+
);
|
|
1216
|
+
return {
|
|
1217
|
+
data: data.current,
|
|
1218
|
+
dataRef: data,
|
|
1219
|
+
getSelectedRows,
|
|
1220
|
+
range: rangeRef.current,
|
|
1221
|
+
setRange
|
|
1222
|
+
};
|
|
1223
|
+
};
|
|
1224
|
+
|
|
1225
|
+
// src/useInitialValue.ts
|
|
1226
|
+
var import_react15 = require("react");
|
|
1227
|
+
var useInitialValue = (value) => {
|
|
1228
|
+
const ref = (0, import_react15.useRef)(value);
|
|
1229
|
+
return (0, import_react15.useMemo)(() => ref.current, []);
|
|
1230
|
+
};
|
|
1231
|
+
|
|
1232
|
+
// src/useKeyboardNavigation.ts
|
|
1233
|
+
var import_vuu_utils12 = require("@vuu-ui/vuu-utils");
|
|
1234
|
+
var import_core = require("@salt-ds/core");
|
|
1235
|
+
var import_react16 = require("react");
|
|
1236
|
+
var rowNavigationKeys = /* @__PURE__ */ new Set([
|
|
1237
|
+
"Home",
|
|
1238
|
+
"End",
|
|
1239
|
+
"PageUp",
|
|
1240
|
+
"PageDown",
|
|
1241
|
+
"ArrowDown",
|
|
1242
|
+
"ArrowUp"
|
|
1243
|
+
]);
|
|
1244
|
+
var cellNavigationKeys = new Set(rowNavigationKeys);
|
|
1245
|
+
cellNavigationKeys.add("ArrowLeft");
|
|
1246
|
+
cellNavigationKeys.add("ArrowRight");
|
|
1247
|
+
var isNavigationKey = (key, navigationStyle) => {
|
|
1248
|
+
switch (navigationStyle) {
|
|
1249
|
+
case "cell":
|
|
1250
|
+
return cellNavigationKeys.has(key);
|
|
1251
|
+
case "row":
|
|
1252
|
+
return rowNavigationKeys.has(key);
|
|
1253
|
+
default:
|
|
1254
|
+
return false;
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
var PageKeys = ["Home", "End", "PageUp", "PageDown"];
|
|
1258
|
+
var isPagingKey = (key) => PageKeys.includes(key);
|
|
1259
|
+
var NULL_CELL_POS = [-1, -1];
|
|
1260
|
+
function nextCellPos(key, [rowIdx, colIdx], columnCount, rowCount) {
|
|
1261
|
+
if (key === "ArrowUp") {
|
|
1262
|
+
if (rowIdx > -1) {
|
|
1263
|
+
return [rowIdx - 1, colIdx];
|
|
1264
|
+
} else {
|
|
1265
|
+
return [rowIdx, colIdx];
|
|
1266
|
+
}
|
|
1267
|
+
} else if (key === "ArrowDown") {
|
|
1268
|
+
if (rowIdx === -1) {
|
|
1269
|
+
return [0, colIdx];
|
|
1270
|
+
} else if (rowIdx === rowCount - 1) {
|
|
1271
|
+
return [rowIdx, colIdx];
|
|
1272
|
+
} else {
|
|
1273
|
+
return [rowIdx + 1, colIdx];
|
|
1274
|
+
}
|
|
1275
|
+
} else if (key === "ArrowRight") {
|
|
1276
|
+
if (colIdx < columnCount) {
|
|
1277
|
+
return [rowIdx, colIdx + 1];
|
|
1278
|
+
} else {
|
|
1279
|
+
return [rowIdx, colIdx];
|
|
1280
|
+
}
|
|
1281
|
+
} else if (key === "ArrowLeft") {
|
|
1282
|
+
if (colIdx > 1) {
|
|
1283
|
+
return [rowIdx, colIdx - 1];
|
|
1284
|
+
} else {
|
|
1285
|
+
return [rowIdx, colIdx];
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
return [rowIdx, colIdx];
|
|
1289
|
+
}
|
|
1290
|
+
var useKeyboardNavigation = ({
|
|
1291
|
+
columnCount = 0,
|
|
1292
|
+
containerRef,
|
|
1293
|
+
disableFocus = false,
|
|
1294
|
+
defaultHighlightedIndex,
|
|
1295
|
+
disableHighlightOnFocus,
|
|
1296
|
+
highlightedIndex: highlightedIndexProp,
|
|
1297
|
+
navigationStyle,
|
|
1298
|
+
requestScroll,
|
|
1299
|
+
onHighlight,
|
|
1300
|
+
rowCount = 0,
|
|
1301
|
+
viewportRowCount
|
|
1302
|
+
}) => {
|
|
1303
|
+
var _a;
|
|
1304
|
+
const focusedCellPos = (0, import_react16.useRef)([-1, -1]);
|
|
1305
|
+
const focusableCell = (0, import_react16.useRef)();
|
|
1306
|
+
const activeCellPos = (0, import_react16.useRef)([-1, 0]);
|
|
1307
|
+
const highlightedIndexRef = (0, import_react16.useRef)();
|
|
1308
|
+
const [highlightedIndex, setHighlightedIdx] = (0, import_core.useControlled)({
|
|
1309
|
+
controlled: highlightedIndexProp,
|
|
1310
|
+
default: defaultHighlightedIndex,
|
|
1311
|
+
name: "UseKeyboardNavigation"
|
|
1312
|
+
});
|
|
1313
|
+
highlightedIndexRef.current = highlightedIndex;
|
|
1314
|
+
const setHighlightedIndex = (0, import_react16.useCallback)(
|
|
1315
|
+
(idx, fromKeyboard = false) => {
|
|
1316
|
+
onHighlight == null ? void 0 : onHighlight(idx);
|
|
1317
|
+
setHighlightedIdx(idx);
|
|
1318
|
+
if (fromKeyboard) {
|
|
1319
|
+
}
|
|
1320
|
+
},
|
|
1321
|
+
[onHighlight, setHighlightedIdx]
|
|
1322
|
+
);
|
|
1323
|
+
const getFocusedCell = (element) => element == null ? void 0 : element.closest(
|
|
1324
|
+
"[role='columnHeader'],[role='cell']"
|
|
1325
|
+
);
|
|
1326
|
+
const getTableCellPos = (tableCell) => {
|
|
1327
|
+
var _a2;
|
|
1328
|
+
if (tableCell.role === "columnHeader") {
|
|
1329
|
+
const colIdx = parseInt((_a2 = tableCell.dataset.idx) != null ? _a2 : "-1", 10);
|
|
1330
|
+
return [-1, colIdx];
|
|
1331
|
+
} else {
|
|
1332
|
+
const focusedRow = tableCell.closest("[role='row']");
|
|
1333
|
+
if (focusedRow) {
|
|
1334
|
+
const rowIdx = (0, import_vuu_utils12.getIndexFromRowElement)(focusedRow);
|
|
1335
|
+
const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);
|
|
1336
|
+
return [rowIdx, colIdx];
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
return NULL_CELL_POS;
|
|
1340
|
+
};
|
|
1341
|
+
const focusCell = (0, import_react16.useCallback)(
|
|
1342
|
+
(cellPos) => {
|
|
1343
|
+
var _a2;
|
|
1344
|
+
if (containerRef.current) {
|
|
1345
|
+
const activeCell = getTableCell(containerRef, cellPos);
|
|
1346
|
+
if (activeCell) {
|
|
1347
|
+
if (activeCell !== focusableCell.current) {
|
|
1348
|
+
(_a2 = focusableCell.current) == null ? void 0 : _a2.removeAttribute("tabindex");
|
|
1349
|
+
focusableCell.current = activeCell;
|
|
1350
|
+
activeCell.setAttribute("tabindex", "0");
|
|
1351
|
+
}
|
|
1352
|
+
console.log(`scroll row ${cellPos[0]}`);
|
|
1353
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-row", rowIndex: cellPos[0] });
|
|
1354
|
+
activeCell.focus({ preventScroll: true });
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
},
|
|
1358
|
+
// TODO we recreate this function whenever viewportRange changes, which will
|
|
1359
|
+
// be often whilst scrolling - store range in a a ref ?
|
|
1360
|
+
[containerRef, requestScroll]
|
|
1361
|
+
);
|
|
1362
|
+
const setActiveCell = (0, import_react16.useCallback)(
|
|
1363
|
+
(rowIdx, colIdx, fromKeyboard = false) => {
|
|
1364
|
+
const pos = [rowIdx, colIdx];
|
|
1365
|
+
activeCellPos.current = pos;
|
|
1366
|
+
if (navigationStyle === "row") {
|
|
1367
|
+
setHighlightedIdx(rowIdx);
|
|
1368
|
+
} else {
|
|
1369
|
+
focusCell(pos);
|
|
1370
|
+
}
|
|
1371
|
+
if (fromKeyboard) {
|
|
1372
|
+
focusedCellPos.current = pos;
|
|
1373
|
+
}
|
|
1374
|
+
},
|
|
1375
|
+
[focusCell, navigationStyle, setHighlightedIdx]
|
|
1376
|
+
);
|
|
1377
|
+
const nextPageItemIdx = (0, import_react16.useCallback)(
|
|
1378
|
+
(key, [rowIdx, colIdx]) => new Promise((resolve) => {
|
|
1379
|
+
let newRowIdx = rowIdx;
|
|
1380
|
+
switch (key) {
|
|
1381
|
+
case "PageDown":
|
|
1382
|
+
newRowIdx = Math.min(rowCount - 1, rowIdx + viewportRowCount);
|
|
1383
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "down" });
|
|
1384
|
+
break;
|
|
1385
|
+
case "PageUp":
|
|
1386
|
+
newRowIdx = Math.max(0, rowIdx - viewportRowCount);
|
|
1387
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
|
|
1388
|
+
break;
|
|
1389
|
+
case "Home":
|
|
1390
|
+
newRowIdx = 0;
|
|
1391
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "home" });
|
|
1392
|
+
break;
|
|
1393
|
+
case "End":
|
|
1394
|
+
newRowIdx = rowCount - 1;
|
|
1395
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "end" });
|
|
1396
|
+
break;
|
|
1397
|
+
}
|
|
1398
|
+
setTimeout(() => {
|
|
1399
|
+
resolve([newRowIdx, colIdx]);
|
|
1400
|
+
}, 90);
|
|
1401
|
+
}),
|
|
1402
|
+
[requestScroll, rowCount, viewportRowCount]
|
|
1403
|
+
);
|
|
1404
|
+
const handleFocus = (0, import_react16.useCallback)(() => {
|
|
1405
|
+
var _a2;
|
|
1406
|
+
if (disableHighlightOnFocus !== true) {
|
|
1407
|
+
if ((_a2 = containerRef.current) == null ? void 0 : _a2.contains(document.activeElement)) {
|
|
1408
|
+
const focusedCell = getFocusedCell(document.activeElement);
|
|
1409
|
+
if (focusedCell) {
|
|
1410
|
+
focusedCellPos.current = getTableCellPos(focusedCell);
|
|
1411
|
+
if (navigationStyle === "row") {
|
|
1412
|
+
setHighlightedIdx(focusedCellPos.current[0]);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
}, [
|
|
1418
|
+
disableHighlightOnFocus,
|
|
1419
|
+
containerRef,
|
|
1420
|
+
navigationStyle,
|
|
1421
|
+
setHighlightedIdx
|
|
1422
|
+
]);
|
|
1423
|
+
const navigateChildItems = (0, import_react16.useCallback)(
|
|
1424
|
+
async (key) => {
|
|
1425
|
+
const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
|
|
1426
|
+
const [rowIdx, colIdx] = activeCellPos.current;
|
|
1427
|
+
if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {
|
|
1428
|
+
setActiveCell(nextRowIdx, nextColIdx, true);
|
|
1429
|
+
}
|
|
1430
|
+
},
|
|
1431
|
+
[columnCount, nextPageItemIdx, rowCount, setActiveCell]
|
|
1432
|
+
);
|
|
1433
|
+
const scrollRowIntoViewIfNecessary = (0, import_react16.useCallback)(
|
|
1434
|
+
(rowIndex) => {
|
|
1435
|
+
requestScroll == null ? void 0 : requestScroll({ type: "scroll-row", rowIndex });
|
|
1436
|
+
},
|
|
1437
|
+
[requestScroll]
|
|
1438
|
+
);
|
|
1439
|
+
const moveHighlightedRow = (0, import_react16.useCallback)(
|
|
1440
|
+
async (key) => {
|
|
1441
|
+
const { current: highlighted } = highlightedIndexRef;
|
|
1442
|
+
const [nextRowIdx] = isPagingKey(key) ? await nextPageItemIdx(key, [highlighted != null ? highlighted : -1, 0]) : nextCellPos(key, [highlighted != null ? highlighted : -1, 0], columnCount, rowCount);
|
|
1443
|
+
if (nextRowIdx !== highlighted) {
|
|
1444
|
+
setHighlightedIndex(nextRowIdx);
|
|
1445
|
+
scrollRowIntoViewIfNecessary(nextRowIdx);
|
|
1446
|
+
}
|
|
1447
|
+
},
|
|
1448
|
+
[
|
|
1449
|
+
columnCount,
|
|
1450
|
+
nextPageItemIdx,
|
|
1451
|
+
rowCount,
|
|
1452
|
+
scrollRowIntoViewIfNecessary,
|
|
1453
|
+
setHighlightedIndex
|
|
1454
|
+
]
|
|
1455
|
+
);
|
|
1456
|
+
(0, import_react16.useEffect)(() => {
|
|
1457
|
+
if (highlightedIndexProp !== void 0 && highlightedIndexProp !== -1) {
|
|
1458
|
+
scrollRowIntoViewIfNecessary(highlightedIndexProp);
|
|
1459
|
+
}
|
|
1460
|
+
}, [highlightedIndexProp, scrollRowIntoViewIfNecessary]);
|
|
1461
|
+
const handleKeyDown = (0, import_react16.useCallback)(
|
|
1462
|
+
(e) => {
|
|
1463
|
+
if (rowCount > 0 && isNavigationKey(e.key, navigationStyle)) {
|
|
1464
|
+
e.preventDefault();
|
|
1465
|
+
e.stopPropagation();
|
|
1466
|
+
if (navigationStyle === "row") {
|
|
1467
|
+
moveHighlightedRow(e.key);
|
|
1468
|
+
} else {
|
|
1469
|
+
void navigateChildItems(e.key);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
},
|
|
1473
|
+
[rowCount, navigationStyle, moveHighlightedRow, navigateChildItems]
|
|
1474
|
+
);
|
|
1475
|
+
const handleClick = (0, import_react16.useCallback)(
|
|
1476
|
+
// Might not be a cell e.g the Settings button
|
|
1477
|
+
(evt) => {
|
|
1478
|
+
const target = evt.target;
|
|
1479
|
+
const focusedCell = getFocusedCell(target);
|
|
1480
|
+
if (focusedCell) {
|
|
1481
|
+
const [rowIdx, colIdx] = getTableCellPos(focusedCell);
|
|
1482
|
+
setActiveCell(rowIdx, colIdx);
|
|
1483
|
+
}
|
|
1484
|
+
},
|
|
1485
|
+
[setActiveCell]
|
|
1486
|
+
);
|
|
1487
|
+
const handleMouseLeave = (0, import_react16.useCallback)(() => {
|
|
1488
|
+
setHighlightedIndex(-1);
|
|
1489
|
+
}, [setHighlightedIndex]);
|
|
1490
|
+
const handleMouseMove = (0, import_react16.useCallback)(
|
|
1491
|
+
(evt) => {
|
|
1492
|
+
const idx = closestRowIndex(evt.target);
|
|
1493
|
+
if (idx !== -1 && idx !== highlightedIndexRef.current) {
|
|
1494
|
+
setHighlightedIndex(idx);
|
|
1495
|
+
}
|
|
1496
|
+
},
|
|
1497
|
+
[setHighlightedIndex]
|
|
1498
|
+
);
|
|
1499
|
+
const navigate = (0, import_react16.useCallback)(() => {
|
|
1500
|
+
navigateChildItems("ArrowDown");
|
|
1501
|
+
}, [navigateChildItems]);
|
|
1502
|
+
const fullyRendered = ((_a = containerRef.current) == null ? void 0 : _a.firstChild) != null;
|
|
1503
|
+
(0, import_react16.useEffect)(() => {
|
|
1504
|
+
if (fullyRendered && focusableCell.current === void 0 && !disableFocus) {
|
|
1505
|
+
const { current: container } = containerRef;
|
|
1506
|
+
const cell = (container == null ? void 0 : container.querySelector(headerCellQuery(0))) || (container == null ? void 0 : container.querySelector(dataCellQuery(0, 0)));
|
|
1507
|
+
if (cell) {
|
|
1508
|
+
cell.setAttribute("tabindex", "0");
|
|
1509
|
+
focusableCell.current = cell;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
}, [containerRef, disableFocus, fullyRendered]);
|
|
1513
|
+
return {
|
|
1514
|
+
highlightedIndexRef,
|
|
1515
|
+
navigate,
|
|
1516
|
+
onClick: handleClick,
|
|
1517
|
+
onFocus: handleFocus,
|
|
1518
|
+
onKeyDown: handleKeyDown,
|
|
1519
|
+
onMouseLeave: navigationStyle === "row" ? handleMouseLeave : void 0,
|
|
1520
|
+
onMouseMove: navigationStyle === "row" ? handleMouseMove : void 0
|
|
1521
|
+
};
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
// src/useSelection.ts
|
|
1525
|
+
var import_vuu_utils13 = require("@vuu-ui/vuu-utils");
|
|
1526
|
+
var import_react17 = require("react");
|
|
1527
|
+
var { IDX: IDX2 } = import_vuu_utils13.metadataKeys;
|
|
1528
|
+
var NO_SELECTION = [];
|
|
1529
|
+
var defaultSelectionKeys = ["Enter", " "];
|
|
1530
|
+
var useSelection = ({
|
|
1531
|
+
highlightedIndexRef,
|
|
1532
|
+
selectionKeys = defaultSelectionKeys,
|
|
1533
|
+
selectionModel,
|
|
1534
|
+
onSelect,
|
|
1535
|
+
onSelectionChange
|
|
1536
|
+
}) => {
|
|
1537
|
+
selectionModel === "extended" || selectionModel === "checkbox";
|
|
1538
|
+
const lastActiveRef = (0, import_react17.useRef)(-1);
|
|
1539
|
+
const selectedRef = (0, import_react17.useRef)(NO_SELECTION);
|
|
1540
|
+
const isSelectionEvent = (0, import_react17.useCallback)(
|
|
1541
|
+
(evt) => selectionKeys.includes(evt.key),
|
|
1542
|
+
[selectionKeys]
|
|
1543
|
+
);
|
|
1544
|
+
const handleRowClick = (0, import_react17.useCallback)(
|
|
1545
|
+
(row, rangeSelect, keepExistingSelection) => {
|
|
1546
|
+
const { [IDX2]: idx } = row;
|
|
1547
|
+
const { current: active } = lastActiveRef;
|
|
1548
|
+
const { current: selected } = selectedRef;
|
|
1549
|
+
const selectOperation = (0, import_vuu_utils13.isRowSelected)(row) ? import_vuu_utils13.deselectItem : import_vuu_utils13.selectItem;
|
|
1550
|
+
const newSelected = selectOperation(
|
|
1551
|
+
selectionModel,
|
|
1552
|
+
selected,
|
|
1553
|
+
idx,
|
|
1554
|
+
rangeSelect,
|
|
1555
|
+
keepExistingSelection,
|
|
1556
|
+
active
|
|
1557
|
+
);
|
|
1558
|
+
selectedRef.current = newSelected;
|
|
1559
|
+
lastActiveRef.current = idx;
|
|
1560
|
+
onSelect == null ? void 0 : onSelect(row);
|
|
1561
|
+
onSelectionChange == null ? void 0 : onSelectionChange(newSelected);
|
|
1562
|
+
},
|
|
1563
|
+
[onSelect, onSelectionChange, selectionModel]
|
|
1564
|
+
);
|
|
1565
|
+
const handleKeyDown = (0, import_react17.useCallback)(
|
|
1566
|
+
(e) => {
|
|
1567
|
+
if (isSelectionEvent(e)) {
|
|
1568
|
+
const { current: rowIndex } = highlightedIndexRef;
|
|
1569
|
+
if (rowIndex !== void 0 && rowIndex !== -1) {
|
|
1570
|
+
const rowEl = e.target.querySelector(
|
|
1571
|
+
`[aria-rowindex="${rowIndex}"]`
|
|
1572
|
+
);
|
|
1573
|
+
if (rowEl) {
|
|
1574
|
+
(0, import_vuu_utils13.dispatchMouseEvent)(rowEl, "click");
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
},
|
|
1579
|
+
[highlightedIndexRef, isSelectionEvent]
|
|
1580
|
+
);
|
|
1581
|
+
return {
|
|
1582
|
+
onKeyDown: handleKeyDown,
|
|
1583
|
+
onRowClick: handleRowClick
|
|
1584
|
+
};
|
|
1585
|
+
};
|
|
1586
|
+
|
|
1587
|
+
// src/useTableContextMenu.ts
|
|
1588
|
+
var import_vuu_popups2 = require("@vuu-ui/vuu-popups");
|
|
1589
|
+
var import_vuu_utils14 = require("@vuu-ui/vuu-utils");
|
|
1590
|
+
var import_react18 = require("react");
|
|
1591
|
+
var NO_ROWS = [];
|
|
1592
|
+
var useTableContextMenu = ({
|
|
1593
|
+
columns,
|
|
1594
|
+
data,
|
|
1595
|
+
dataSource,
|
|
1596
|
+
getSelectedRows
|
|
1597
|
+
}) => {
|
|
1598
|
+
const [showContextMenu] = (0, import_vuu_popups2.useContextMenu)();
|
|
1599
|
+
const onContextMenu = (0, import_react18.useCallback)(
|
|
1600
|
+
(evt) => {
|
|
1601
|
+
const target = evt.target;
|
|
1602
|
+
const cellEl = target == null ? void 0 : target.closest("div[role='cell']");
|
|
1603
|
+
const rowEl = target == null ? void 0 : target.closest("div[role='row']");
|
|
1604
|
+
if (cellEl && rowEl) {
|
|
1605
|
+
const { selectedRowsCount } = dataSource;
|
|
1606
|
+
const columnMap = (0, import_vuu_utils14.buildColumnMap)(columns);
|
|
1607
|
+
const rowIndex = (0, import_vuu_utils14.getIndexFromRowElement)(rowEl);
|
|
1608
|
+
const cellIndex = Array.from(rowEl.childNodes).indexOf(cellEl);
|
|
1609
|
+
const row = data.find(([idx]) => idx === rowIndex);
|
|
1610
|
+
const columnName = columns[cellIndex];
|
|
1611
|
+
showContextMenu(evt, "grid", {
|
|
1612
|
+
columnMap,
|
|
1613
|
+
columnName,
|
|
1614
|
+
row,
|
|
1615
|
+
selectedRows: selectedRowsCount === 0 ? NO_ROWS : getSelectedRows(),
|
|
1616
|
+
viewport: dataSource.viewport
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
},
|
|
1620
|
+
[columns, data, dataSource, getSelectedRows, showContextMenu]
|
|
1621
|
+
);
|
|
1622
|
+
return onContextMenu;
|
|
1623
|
+
};
|
|
1624
|
+
|
|
1625
|
+
// src/useTableModel.ts
|
|
1626
|
+
var import_vuu_utils15 = require("@vuu-ui/vuu-utils");
|
|
1627
|
+
var import_vuu_ui_controls = require("@vuu-ui/vuu-ui-controls");
|
|
1628
|
+
var import_react19 = require("react");
|
|
1629
|
+
var { info } = (0, import_vuu_utils15.logger)("useTableModel");
|
|
1630
|
+
var DEFAULT_COLUMN_WIDTH = 100;
|
|
1631
|
+
var KEY_OFFSET = import_vuu_utils15.metadataKeys.count;
|
|
1632
|
+
var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
|
|
1633
|
+
var getDataType = (column, tableSchema) => {
|
|
1634
|
+
const schemaColumn = tableSchema == null ? void 0 : tableSchema.columns.find(
|
|
1635
|
+
({ name }) => name === column.name
|
|
1636
|
+
);
|
|
1637
|
+
if (schemaColumn) {
|
|
1638
|
+
return schemaColumn.serverDataType;
|
|
1639
|
+
} else {
|
|
1640
|
+
return column.serverDataType;
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
var numericTypes = ["int", "long", "double"];
|
|
1644
|
+
var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
|
|
1645
|
+
var isShowColumnSettings = (action) => action.type === "columnSettings";
|
|
1646
|
+
var isShowTableSettings = (action) => action.type === "tableSettings";
|
|
1647
|
+
var columnReducer = (state, action) => {
|
|
1648
|
+
info == null ? void 0 : info(`TableModelReducer ${action.type}`);
|
|
1649
|
+
switch (action.type) {
|
|
1650
|
+
case "init":
|
|
1651
|
+
return init(action);
|
|
1652
|
+
case "moveColumn":
|
|
1653
|
+
return moveColumn(state, action);
|
|
1654
|
+
case "resizeColumn":
|
|
1655
|
+
return resizeColumn(state, action);
|
|
1656
|
+
case "setTableSchema":
|
|
1657
|
+
return setTableSchema(state, action);
|
|
1658
|
+
case "hideColumns":
|
|
1659
|
+
return hideColumns(state, action);
|
|
1660
|
+
case "showColumns":
|
|
1661
|
+
return showColumns(state, action);
|
|
1662
|
+
case "pinColumn":
|
|
1663
|
+
return pinColumn2(state, action);
|
|
1664
|
+
case "updateColumnProp":
|
|
1665
|
+
return updateColumnProp(state, action);
|
|
1666
|
+
case "tableConfig":
|
|
1667
|
+
return updateTableConfig2(state, action);
|
|
1668
|
+
default:
|
|
1669
|
+
console.log(`unhandled action ${action.type}`);
|
|
1670
|
+
return state;
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
var useTableModel = (tableConfigProp, dataSource) => {
|
|
1674
|
+
const [state, dispatchColumnAction] = (0, import_react19.useReducer)(columnReducer, { tableConfig: tableConfigProp, dataSource }, init);
|
|
1675
|
+
const { columns, headings, tableConfig, ...tableAttributes } = state;
|
|
1676
|
+
return {
|
|
1677
|
+
columns,
|
|
1678
|
+
dispatchColumnAction,
|
|
1679
|
+
headings,
|
|
1680
|
+
tableAttributes,
|
|
1681
|
+
tableConfig
|
|
1682
|
+
};
|
|
1683
|
+
};
|
|
1684
|
+
function init({ dataSource, tableConfig }) {
|
|
1685
|
+
const { columns, ...tableAttributes } = tableConfig;
|
|
1686
|
+
const { config: dataSourceConfig, tableSchema } = dataSource;
|
|
1687
|
+
const runtimeColumns = columns.filter((0, import_vuu_utils15.subscribedOnly)(dataSourceConfig == null ? void 0 : dataSourceConfig.columns)).map(
|
|
1688
|
+
columnDescriptorToRuntimeColumDescriptor(tableAttributes, tableSchema)
|
|
1689
|
+
);
|
|
1690
|
+
const maybePinnedColumns = runtimeColumns.some(import_vuu_utils15.isPinned) ? (0, import_vuu_utils15.sortPinnedColumns)(runtimeColumns) : runtimeColumns;
|
|
1691
|
+
let state = {
|
|
1692
|
+
columns: maybePinnedColumns,
|
|
1693
|
+
headings: (0, import_vuu_utils15.getTableHeadings)(maybePinnedColumns),
|
|
1694
|
+
tableConfig,
|
|
1695
|
+
...tableAttributes
|
|
1696
|
+
};
|
|
1697
|
+
if (dataSourceConfig) {
|
|
1698
|
+
const { columns: _, ...rest } = dataSourceConfig;
|
|
1699
|
+
state = updateTableConfig2(state, {
|
|
1700
|
+
type: "tableConfig",
|
|
1701
|
+
...rest
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
return state;
|
|
1705
|
+
}
|
|
1706
|
+
var getLabel = (label, columnFormatHeader) => {
|
|
1707
|
+
if (columnFormatHeader === "uppercase") {
|
|
1708
|
+
return label.toUpperCase();
|
|
1709
|
+
} else if (columnFormatHeader === "capitalize") {
|
|
1710
|
+
return label[0].toUpperCase() + label.slice(1).toLowerCase();
|
|
1711
|
+
}
|
|
1712
|
+
return label;
|
|
1713
|
+
};
|
|
1714
|
+
var columnDescriptorToRuntimeColumDescriptor = (tableAttributes, tableSchema) => (column, index) => {
|
|
1715
|
+
const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = tableAttributes;
|
|
1716
|
+
const serverDataType = getDataType(column, tableSchema);
|
|
1717
|
+
const {
|
|
1718
|
+
align = getDefaultAlignment(serverDataType),
|
|
1719
|
+
key,
|
|
1720
|
+
name,
|
|
1721
|
+
label = (0, import_vuu_utils15.getColumnLabel)(column),
|
|
1722
|
+
width = columnDefaultWidth,
|
|
1723
|
+
...rest
|
|
1724
|
+
} = column;
|
|
1725
|
+
const runtimeColumnWithDefaults = {
|
|
1726
|
+
...rest,
|
|
1727
|
+
align,
|
|
1728
|
+
CellRenderer: (0, import_vuu_utils15.getCellRenderer)(column),
|
|
1729
|
+
HeaderCellContentRenderer: (0, import_vuu_utils15.getColumnHeaderContentRenderer)(column),
|
|
1730
|
+
HeaderCellLabelRenderer: (0, import_vuu_utils15.getColumnHeaderLabelRenderer)(column),
|
|
1731
|
+
clientSideEditValidationCheck: (0, import_vuu_utils15.hasValidationRules)(column.type) ? (0, import_vuu_ui_controls.buildValidationChecker)(column.type.renderer.rules) : void 0,
|
|
1732
|
+
label: getLabel(label, columnFormatHeader),
|
|
1733
|
+
key: key != null ? key : index + KEY_OFFSET,
|
|
1734
|
+
name,
|
|
1735
|
+
originalIdx: index,
|
|
1736
|
+
serverDataType,
|
|
1737
|
+
valueFormatter: (0, import_vuu_utils15.getValueFormatter)(column, serverDataType),
|
|
1738
|
+
width
|
|
1739
|
+
};
|
|
1740
|
+
if ((0, import_vuu_utils15.isGroupColumn)(runtimeColumnWithDefaults)) {
|
|
1741
|
+
runtimeColumnWithDefaults.columns = runtimeColumnWithDefaults.columns.map(
|
|
1742
|
+
(col) => columnDescriptorToRuntimeColumDescriptor(tableAttributes)(
|
|
1743
|
+
col,
|
|
1744
|
+
col.key
|
|
1745
|
+
)
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
return runtimeColumnWithDefaults;
|
|
1749
|
+
};
|
|
1750
|
+
function moveColumn(state, { column, moveBy }) {
|
|
1751
|
+
const { columns } = state;
|
|
1752
|
+
if (typeof moveBy === "number") {
|
|
1753
|
+
const idx = columns.indexOf(column);
|
|
1754
|
+
const newColumns = columns.slice();
|
|
1755
|
+
const [movedColumns] = newColumns.splice(idx, 1);
|
|
1756
|
+
newColumns.splice(idx + moveBy, 0, movedColumns);
|
|
1757
|
+
return {
|
|
1758
|
+
...state,
|
|
1759
|
+
columns: newColumns
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
return state;
|
|
1763
|
+
}
|
|
1764
|
+
function hideColumns(state, { columns }) {
|
|
1765
|
+
if (columns.some((col) => col.hidden !== true)) {
|
|
1766
|
+
return columns.reduce((s, c) => {
|
|
1767
|
+
if (c.hidden !== true) {
|
|
1768
|
+
return updateColumnProp(s, {
|
|
1769
|
+
type: "updateColumnProp",
|
|
1770
|
+
column: c,
|
|
1771
|
+
hidden: true
|
|
1772
|
+
});
|
|
1773
|
+
} else {
|
|
1774
|
+
return s;
|
|
1775
|
+
}
|
|
1776
|
+
}, state);
|
|
1777
|
+
} else {
|
|
1778
|
+
return state;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
function showColumns(state, { columns }) {
|
|
1782
|
+
if (columns.some((col) => col.hidden)) {
|
|
1783
|
+
return columns.reduce((s, c) => {
|
|
1784
|
+
if (c.hidden) {
|
|
1785
|
+
return updateColumnProp(s, {
|
|
1786
|
+
type: "updateColumnProp",
|
|
1787
|
+
column: c,
|
|
1788
|
+
hidden: false
|
|
1789
|
+
});
|
|
1790
|
+
} else {
|
|
1791
|
+
return s;
|
|
1792
|
+
}
|
|
1793
|
+
}, state);
|
|
1794
|
+
} else {
|
|
1795
|
+
return state;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
function resizeColumn(state, { column, phase, width }) {
|
|
1799
|
+
const type = "updateColumnProp";
|
|
1800
|
+
const resizing = phase !== "end";
|
|
1801
|
+
switch (phase) {
|
|
1802
|
+
case "begin":
|
|
1803
|
+
return updateColumnProp(state, { type, column, resizing });
|
|
1804
|
+
case "end":
|
|
1805
|
+
return updateColumnProp(state, { type, column, resizing, width });
|
|
1806
|
+
case "resize":
|
|
1807
|
+
return updateColumnProp(state, { type, column, width });
|
|
1808
|
+
default:
|
|
1809
|
+
throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
function setTableSchema(state, { tableSchema }) {
|
|
1813
|
+
const { columns } = state;
|
|
1814
|
+
if (columns.some(columnWithoutDataType)) {
|
|
1815
|
+
const cols = columns.map((column) => {
|
|
1816
|
+
var _a;
|
|
1817
|
+
const serverDataType = getDataType(column, tableSchema);
|
|
1818
|
+
return {
|
|
1819
|
+
...column,
|
|
1820
|
+
align: (_a = column.align) != null ? _a : getDefaultAlignment(serverDataType),
|
|
1821
|
+
serverDataType
|
|
1822
|
+
};
|
|
1823
|
+
});
|
|
1824
|
+
return {
|
|
1825
|
+
...state,
|
|
1826
|
+
columns: cols
|
|
1827
|
+
};
|
|
1828
|
+
} else {
|
|
1829
|
+
return state;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
function pinColumn2(state, action) {
|
|
1833
|
+
let { columns } = state;
|
|
1834
|
+
const { column, pin } = action;
|
|
1835
|
+
const targetColumn = columns.find((col) => col.name === column.name);
|
|
1836
|
+
if (targetColumn) {
|
|
1837
|
+
columns = (0, import_vuu_utils15.replaceColumn)(columns, { ...targetColumn, pin });
|
|
1838
|
+
columns = (0, import_vuu_utils15.sortPinnedColumns)(columns);
|
|
1839
|
+
return {
|
|
1840
|
+
...state,
|
|
1841
|
+
columns
|
|
1842
|
+
};
|
|
1843
|
+
} else {
|
|
1844
|
+
return state;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
function updateColumnProp(state, action) {
|
|
1848
|
+
let { columns, tableConfig } = state;
|
|
1849
|
+
const { align, column, hidden, label, resizing, width } = action;
|
|
1850
|
+
const targetColumn = columns.find((col) => col.name === column.name);
|
|
1851
|
+
if (targetColumn) {
|
|
1852
|
+
if (align === "left" || align === "right") {
|
|
1853
|
+
columns = (0, import_vuu_utils15.replaceColumn)(columns, { ...targetColumn, align });
|
|
1854
|
+
}
|
|
1855
|
+
if (typeof label === "string") {
|
|
1856
|
+
columns = (0, import_vuu_utils15.replaceColumn)(columns, { ...targetColumn, label });
|
|
1857
|
+
}
|
|
1858
|
+
if (typeof resizing === "boolean") {
|
|
1859
|
+
columns = (0, import_vuu_utils15.replaceColumn)(columns, { ...targetColumn, resizing });
|
|
1860
|
+
}
|
|
1861
|
+
if (typeof hidden === "boolean") {
|
|
1862
|
+
columns = (0, import_vuu_utils15.replaceColumn)(columns, { ...targetColumn, hidden });
|
|
1863
|
+
}
|
|
1864
|
+
if (typeof width === "number") {
|
|
1865
|
+
columns = (0, import_vuu_utils15.replaceColumn)(columns, { ...targetColumn, width });
|
|
1866
|
+
const targetConfigColumn = tableConfig.columns.find(
|
|
1867
|
+
(col) => col.name === column.name
|
|
1868
|
+
);
|
|
1869
|
+
if (targetConfigColumn) {
|
|
1870
|
+
tableConfig = {
|
|
1871
|
+
...tableConfig,
|
|
1872
|
+
columns: (0, import_vuu_utils15.replaceColumn)(tableConfig.columns, {
|
|
1873
|
+
...targetConfigColumn,
|
|
1874
|
+
width
|
|
1875
|
+
})
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
return {
|
|
1881
|
+
...state,
|
|
1882
|
+
columns,
|
|
1883
|
+
tableConfig
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
function updateTableConfig2(state, { confirmed, filter, groupBy, sort }) {
|
|
1887
|
+
const hasGroupBy = groupBy !== void 0;
|
|
1888
|
+
const hasFilter = typeof (filter == null ? void 0 : filter.filter) === "string";
|
|
1889
|
+
const hasSort = sort && sort.sortDefs.length > 0;
|
|
1890
|
+
let result = state;
|
|
1891
|
+
if (hasGroupBy) {
|
|
1892
|
+
result = {
|
|
1893
|
+
...state,
|
|
1894
|
+
columns: (0, import_vuu_utils15.applyGroupByToColumns)(result.columns, groupBy, confirmed)
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1897
|
+
if (hasSort) {
|
|
1898
|
+
result = {
|
|
1899
|
+
...state,
|
|
1900
|
+
columns: (0, import_vuu_utils15.applySortToColumns)(result.columns, sort)
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
if (hasFilter) {
|
|
1904
|
+
result = {
|
|
1905
|
+
...state,
|
|
1906
|
+
columns: (0, import_vuu_utils15.applyFilterToColumns)(result.columns, filter)
|
|
1907
|
+
};
|
|
1908
|
+
} else if (result.columns.some(import_vuu_utils15.isFilteredColumn)) {
|
|
1909
|
+
result = {
|
|
1910
|
+
...state,
|
|
1911
|
+
columns: (0, import_vuu_utils15.stripFilterFromColumns)(result.columns)
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
return result;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
// src/useTableScroll.ts
|
|
1918
|
+
var import_vuu_utils16 = require("@vuu-ui/vuu-utils");
|
|
1919
|
+
var import_react20 = require("react");
|
|
1920
|
+
var getPctScroll = (container) => {
|
|
1921
|
+
const { scrollLeft, scrollTop } = container;
|
|
1922
|
+
const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
|
|
1923
|
+
const pctScrollLeft = scrollLeft / (scrollWidth - clientWidth);
|
|
1924
|
+
const pctScrollTop = scrollTop / (scrollHeight - clientHeight);
|
|
1925
|
+
return [pctScrollLeft, pctScrollTop];
|
|
1926
|
+
};
|
|
1927
|
+
var noScrolling = {
|
|
1928
|
+
scrollToIndex: () => void 0,
|
|
1929
|
+
scrollToKey: () => void 0
|
|
1930
|
+
};
|
|
1931
|
+
var NO_SCROLL_NECESSARY = [void 0, void 0];
|
|
1932
|
+
var howFarIsRowOutsideViewport = (rowEl, totalHeaderHeight, contentContainer = rowEl.closest(".vuuTable-contentContainer")) => {
|
|
1933
|
+
if (contentContainer) {
|
|
1934
|
+
const viewport = contentContainer == null ? void 0 : contentContainer.getBoundingClientRect();
|
|
1935
|
+
const upperBoundary = viewport.top + totalHeaderHeight;
|
|
1936
|
+
const row = rowEl.getBoundingClientRect();
|
|
1937
|
+
if (row) {
|
|
1938
|
+
if (row.bottom > viewport.bottom) {
|
|
1939
|
+
return ["down", row.bottom - viewport.bottom];
|
|
1940
|
+
} else if (row.top < upperBoundary) {
|
|
1941
|
+
return ["up", row.top - upperBoundary];
|
|
1942
|
+
} else {
|
|
1943
|
+
return NO_SCROLL_NECESSARY;
|
|
1944
|
+
}
|
|
1945
|
+
} else {
|
|
1946
|
+
throw Error("Whats going on, row not found");
|
|
1947
|
+
}
|
|
1948
|
+
} else {
|
|
1949
|
+
throw Error("Whats going on, scrollbar container not found");
|
|
1950
|
+
}
|
|
1951
|
+
};
|
|
1952
|
+
var useCallbackRef = ({
|
|
1953
|
+
onAttach,
|
|
1954
|
+
onDetach
|
|
1955
|
+
}) => {
|
|
1956
|
+
const ref = (0, import_react20.useRef)(null);
|
|
1957
|
+
const callbackRef = (0, import_react20.useCallback)(
|
|
1958
|
+
(el) => {
|
|
1959
|
+
if (el) {
|
|
1960
|
+
ref.current = el;
|
|
1961
|
+
onAttach == null ? void 0 : onAttach(el);
|
|
1962
|
+
} else if (ref.current) {
|
|
1963
|
+
const { current: originalRef } = ref;
|
|
1964
|
+
ref.current = el;
|
|
1965
|
+
onDetach == null ? void 0 : onDetach(originalRef);
|
|
1966
|
+
}
|
|
1967
|
+
},
|
|
1968
|
+
[onAttach, onDetach]
|
|
1969
|
+
);
|
|
1970
|
+
return callbackRef;
|
|
1971
|
+
};
|
|
1972
|
+
var useTableScroll = ({
|
|
1973
|
+
getRowAtPosition,
|
|
1974
|
+
onHorizontalScroll,
|
|
1975
|
+
onVerticalScroll,
|
|
1976
|
+
scrollingApiRef,
|
|
1977
|
+
setRange,
|
|
1978
|
+
viewportMeasurements
|
|
1979
|
+
}) => {
|
|
1980
|
+
const firstRowRef = (0, import_react20.useRef)(0);
|
|
1981
|
+
const contentContainerScrolledRef = (0, import_react20.useRef)(false);
|
|
1982
|
+
const scrollPosRef = (0, import_react20.useRef)({ scrollTop: 0, scrollLeft: 0 });
|
|
1983
|
+
const scrollbarContainerRef = (0, import_react20.useRef)(null);
|
|
1984
|
+
const contentContainerRef = (0, import_react20.useRef)(null);
|
|
1985
|
+
const {
|
|
1986
|
+
appliedPageSize,
|
|
1987
|
+
isVirtualScroll,
|
|
1988
|
+
maxScrollContainerScrollHorizontal: maxScrollLeft,
|
|
1989
|
+
maxScrollContainerScrollVertical: maxScrollTop,
|
|
1990
|
+
rowCount: viewportRowCount,
|
|
1991
|
+
totalHeaderHeight
|
|
1992
|
+
} = viewportMeasurements;
|
|
1993
|
+
const handleVerticalScroll = (0, import_react20.useCallback)(
|
|
1994
|
+
(scrollTop, pctScrollTop) => {
|
|
1995
|
+
onVerticalScroll == null ? void 0 : onVerticalScroll(scrollTop, pctScrollTop);
|
|
1996
|
+
const firstRow = getRowAtPosition(scrollTop);
|
|
1997
|
+
if (firstRow !== firstRowRef.current) {
|
|
1998
|
+
firstRowRef.current = firstRow;
|
|
1999
|
+
setRange({ from: firstRow, to: firstRow + viewportRowCount + 1 });
|
|
2000
|
+
}
|
|
2001
|
+
},
|
|
2002
|
+
[getRowAtPosition, onVerticalScroll, setRange, viewportRowCount]
|
|
2003
|
+
);
|
|
2004
|
+
const handleScrollbarContainerScroll = (0, import_react20.useCallback)(() => {
|
|
2005
|
+
const { current: contentContainer } = contentContainerRef;
|
|
2006
|
+
const { current: scrollbarContainer } = scrollbarContainerRef;
|
|
2007
|
+
const { current: contentContainerScrolled } = contentContainerScrolledRef;
|
|
2008
|
+
if (contentContainerScrolled) {
|
|
2009
|
+
contentContainerScrolledRef.current = false;
|
|
2010
|
+
} else if (contentContainer && scrollbarContainer) {
|
|
2011
|
+
const [pctScrollLeft, pctScrollTop] = getPctScroll(scrollbarContainer);
|
|
2012
|
+
const rootScrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
|
|
2013
|
+
const rootScrollTop = pctScrollTop * maxScrollTop;
|
|
2014
|
+
contentContainer.scrollTo({
|
|
2015
|
+
left: rootScrollLeft,
|
|
2016
|
+
top: rootScrollTop,
|
|
2017
|
+
behavior: "auto"
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
}, [maxScrollLeft, maxScrollTop]);
|
|
2021
|
+
const handleContentContainerScroll = (0, import_react20.useCallback)(() => {
|
|
2022
|
+
const { current: contentContainer } = contentContainerRef;
|
|
2023
|
+
const { current: scrollbarContainer } = scrollbarContainerRef;
|
|
2024
|
+
const { current: scrollPos } = scrollPosRef;
|
|
2025
|
+
if (contentContainer && scrollbarContainer) {
|
|
2026
|
+
const { scrollLeft, scrollTop } = contentContainer;
|
|
2027
|
+
const [pctScrollLeft, pctScrollTop] = getPctScroll(contentContainer);
|
|
2028
|
+
contentContainerScrolledRef.current = true;
|
|
2029
|
+
scrollbarContainer.scrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
|
|
2030
|
+
scrollbarContainer.scrollTop = pctScrollTop * maxScrollTop;
|
|
2031
|
+
if (scrollPos.scrollTop !== scrollTop) {
|
|
2032
|
+
scrollPos.scrollTop = scrollTop;
|
|
2033
|
+
handleVerticalScroll(scrollTop, pctScrollTop);
|
|
2034
|
+
}
|
|
2035
|
+
if (scrollPos.scrollLeft !== scrollLeft) {
|
|
2036
|
+
scrollPos.scrollLeft = scrollLeft;
|
|
2037
|
+
onHorizontalScroll == null ? void 0 : onHorizontalScroll(scrollLeft);
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
}, [handleVerticalScroll, maxScrollLeft, maxScrollTop, onHorizontalScroll]);
|
|
2041
|
+
const handleAttachScrollbarContainer = (0, import_react20.useCallback)(
|
|
2042
|
+
(el) => {
|
|
2043
|
+
scrollbarContainerRef.current = el;
|
|
2044
|
+
el.addEventListener("scroll", handleScrollbarContainerScroll, {
|
|
2045
|
+
passive: true
|
|
2046
|
+
});
|
|
2047
|
+
},
|
|
2048
|
+
[handleScrollbarContainerScroll]
|
|
2049
|
+
);
|
|
2050
|
+
const handleDetachScrollbarContainer = (0, import_react20.useCallback)(
|
|
2051
|
+
(el) => {
|
|
2052
|
+
scrollbarContainerRef.current = null;
|
|
2053
|
+
el.removeEventListener("scroll", handleScrollbarContainerScroll);
|
|
2054
|
+
},
|
|
2055
|
+
[handleScrollbarContainerScroll]
|
|
2056
|
+
);
|
|
2057
|
+
const handleAttachContentContainer = (0, import_react20.useCallback)(
|
|
2058
|
+
(el) => {
|
|
2059
|
+
contentContainerRef.current = el;
|
|
2060
|
+
el.addEventListener("scroll", handleContentContainerScroll, {
|
|
2061
|
+
passive: true
|
|
2062
|
+
});
|
|
2063
|
+
},
|
|
2064
|
+
[handleContentContainerScroll]
|
|
2065
|
+
);
|
|
2066
|
+
const handleDetachContentContainer = (0, import_react20.useCallback)(
|
|
2067
|
+
(el) => {
|
|
2068
|
+
contentContainerRef.current = null;
|
|
2069
|
+
el.removeEventListener("scroll", handleContentContainerScroll);
|
|
2070
|
+
},
|
|
2071
|
+
[handleContentContainerScroll]
|
|
2072
|
+
);
|
|
2073
|
+
const contentContainerCallbackRef = useCallbackRef({
|
|
2074
|
+
onAttach: handleAttachContentContainer,
|
|
2075
|
+
onDetach: handleDetachContentContainer
|
|
2076
|
+
});
|
|
2077
|
+
const scrollbarContainerCallbackRef = useCallbackRef({
|
|
2078
|
+
onAttach: handleAttachScrollbarContainer,
|
|
2079
|
+
onDetach: handleDetachScrollbarContainer
|
|
2080
|
+
});
|
|
2081
|
+
const requestScroll = (0, import_react20.useCallback)(
|
|
2082
|
+
(scrollRequest) => {
|
|
2083
|
+
const { current: scrollbarContainer } = contentContainerRef;
|
|
2084
|
+
if (scrollbarContainer) {
|
|
2085
|
+
const { scrollLeft, scrollTop } = scrollbarContainer;
|
|
2086
|
+
contentContainerScrolledRef.current = false;
|
|
2087
|
+
if (scrollRequest.type === "scroll-row") {
|
|
2088
|
+
const activeRow = (0, import_vuu_utils16.getRowElementAtIndex)(
|
|
2089
|
+
scrollbarContainer,
|
|
2090
|
+
scrollRequest.rowIndex
|
|
2091
|
+
);
|
|
2092
|
+
if (activeRow !== null) {
|
|
2093
|
+
const [direction, distance] = howFarIsRowOutsideViewport(
|
|
2094
|
+
activeRow,
|
|
2095
|
+
totalHeaderHeight
|
|
2096
|
+
);
|
|
2097
|
+
if (direction && distance) {
|
|
2098
|
+
if (isVirtualScroll) {
|
|
2099
|
+
console.log(
|
|
2100
|
+
`virtual scroll row required ${direction} ${distance}
|
|
2101
|
+
first Row ${firstRowRef.current}`
|
|
2102
|
+
);
|
|
2103
|
+
} else {
|
|
2104
|
+
let newScrollLeft = scrollLeft;
|
|
2105
|
+
let newScrollTop = scrollTop;
|
|
2106
|
+
if (direction === "up" || direction === "down") {
|
|
2107
|
+
newScrollTop = Math.min(
|
|
2108
|
+
Math.max(0, scrollTop + distance),
|
|
2109
|
+
maxScrollTop
|
|
2110
|
+
);
|
|
2111
|
+
} else {
|
|
2112
|
+
newScrollLeft = Math.min(
|
|
2113
|
+
Math.max(0, scrollLeft + distance),
|
|
2114
|
+
maxScrollLeft
|
|
2115
|
+
);
|
|
2116
|
+
}
|
|
2117
|
+
scrollbarContainer.scrollTo({
|
|
2118
|
+
top: newScrollTop,
|
|
2119
|
+
left: newScrollLeft,
|
|
2120
|
+
behavior: "smooth"
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
} else if (scrollRequest.type === "scroll-page") {
|
|
2126
|
+
const { direction } = scrollRequest;
|
|
2127
|
+
if (isVirtualScroll) {
|
|
2128
|
+
console.log(`need a virtual page scroll`);
|
|
2129
|
+
} else {
|
|
2130
|
+
const scrollBy = direction === "down" ? appliedPageSize : -appliedPageSize;
|
|
2131
|
+
const newScrollTop = Math.min(
|
|
2132
|
+
Math.max(0, scrollTop + scrollBy),
|
|
2133
|
+
maxScrollTop
|
|
2134
|
+
);
|
|
2135
|
+
scrollbarContainer.scrollTo({
|
|
2136
|
+
top: newScrollTop,
|
|
2137
|
+
left: scrollLeft,
|
|
2138
|
+
behavior: "auto"
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
} else if (scrollRequest.type === "scroll-end") {
|
|
2142
|
+
const { direction } = scrollRequest;
|
|
2143
|
+
const scrollTo = direction === "end" ? maxScrollTop : 0;
|
|
2144
|
+
scrollbarContainer.scrollTo({
|
|
2145
|
+
top: scrollTo,
|
|
2146
|
+
left: scrollbarContainer.scrollLeft,
|
|
2147
|
+
behavior: "auto"
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
},
|
|
2152
|
+
[
|
|
2153
|
+
appliedPageSize,
|
|
2154
|
+
isVirtualScroll,
|
|
2155
|
+
maxScrollLeft,
|
|
2156
|
+
maxScrollTop,
|
|
2157
|
+
setRange,
|
|
2158
|
+
totalHeaderHeight,
|
|
2159
|
+
viewportRowCount
|
|
2160
|
+
]
|
|
2161
|
+
);
|
|
2162
|
+
const scrollHandles = (0, import_react20.useMemo)(
|
|
2163
|
+
() => ({
|
|
2164
|
+
scrollToIndex: (rowIndex) => {
|
|
2165
|
+
if (scrollbarContainerRef.current) {
|
|
2166
|
+
const scrollPos = (rowIndex - 30) * 20;
|
|
2167
|
+
scrollbarContainerRef.current.scrollTop = scrollPos;
|
|
2168
|
+
}
|
|
2169
|
+
},
|
|
2170
|
+
scrollToKey: (rowKey) => {
|
|
2171
|
+
console.log(`scrollToKey ${rowKey}`);
|
|
2172
|
+
}
|
|
2173
|
+
}),
|
|
2174
|
+
[]
|
|
2175
|
+
);
|
|
2176
|
+
(0, import_react20.useImperativeHandle)(
|
|
2177
|
+
scrollingApiRef,
|
|
2178
|
+
() => {
|
|
2179
|
+
if (scrollbarContainerRef.current) {
|
|
2180
|
+
return scrollHandles;
|
|
2181
|
+
} else {
|
|
2182
|
+
return noScrolling;
|
|
2183
|
+
}
|
|
2184
|
+
},
|
|
2185
|
+
[scrollHandles]
|
|
2186
|
+
);
|
|
2187
|
+
(0, import_react20.useEffect)(() => {
|
|
2188
|
+
const { current: from } = firstRowRef;
|
|
2189
|
+
const rowRange = { from, to: from + viewportRowCount + 1 };
|
|
2190
|
+
setRange(rowRange);
|
|
2191
|
+
}, [setRange, viewportRowCount]);
|
|
2192
|
+
return {
|
|
2193
|
+
/** Ref to be assigned to ScrollbarContainer */
|
|
2194
|
+
scrollbarContainerRef: scrollbarContainerCallbackRef,
|
|
2195
|
+
/** Ref to be assigned to ContentContainer */
|
|
2196
|
+
contentContainerRef: contentContainerCallbackRef,
|
|
2197
|
+
/** Scroll the table */
|
|
2198
|
+
requestScroll
|
|
2199
|
+
};
|
|
2200
|
+
};
|
|
2201
|
+
|
|
2202
|
+
// src/useTableViewport.ts
|
|
2203
|
+
var import_react21 = require("react");
|
|
2204
|
+
var import_vuu_utils17 = require("@vuu-ui/vuu-utils");
|
|
2205
|
+
var MAX_RAW_ROWS = 1e5;
|
|
2206
|
+
var UNMEASURED_VIEWPORT = {
|
|
2207
|
+
appliedPageSize: 0,
|
|
2208
|
+
contentHeight: 0,
|
|
2209
|
+
contentWidth: 0,
|
|
2210
|
+
getRowAtPosition: () => -1,
|
|
2211
|
+
getRowOffset: () => -1,
|
|
2212
|
+
horizontalScrollbarHeight: 0,
|
|
2213
|
+
isVirtualScroll: false,
|
|
2214
|
+
maxScrollContainerScrollHorizontal: 0,
|
|
2215
|
+
maxScrollContainerScrollVertical: 0,
|
|
2216
|
+
pinnedWidthLeft: 0,
|
|
2217
|
+
pinnedWidthRight: 0,
|
|
2218
|
+
rowCount: 0,
|
|
2219
|
+
setPctScrollTop: () => void 0,
|
|
2220
|
+
totalHeaderHeight: 0,
|
|
2221
|
+
verticalScrollbarWidth: 0,
|
|
2222
|
+
viewportBodyHeight: 0
|
|
2223
|
+
};
|
|
2224
|
+
var measurePinnedColumns = (columns) => {
|
|
2225
|
+
let pinnedWidthLeft = 0;
|
|
2226
|
+
let pinnedWidthRight = 0;
|
|
2227
|
+
let unpinnedWidth = 0;
|
|
2228
|
+
for (const column of columns) {
|
|
2229
|
+
const { hidden, pin, width } = column;
|
|
2230
|
+
const visibleWidth = hidden ? 0 : width;
|
|
2231
|
+
if (pin === "left") {
|
|
2232
|
+
pinnedWidthLeft += visibleWidth;
|
|
2233
|
+
} else if (pin === "right") {
|
|
2234
|
+
pinnedWidthRight += visibleWidth;
|
|
2235
|
+
} else {
|
|
2236
|
+
unpinnedWidth += visibleWidth;
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
return {
|
|
2240
|
+
pinnedWidthLeft: pinnedWidthLeft + 4,
|
|
2241
|
+
pinnedWidthRight: pinnedWidthRight + 4,
|
|
2242
|
+
unpinnedWidth
|
|
2243
|
+
};
|
|
2244
|
+
};
|
|
2245
|
+
var useTableViewport = ({
|
|
2246
|
+
columns,
|
|
2247
|
+
headerHeight,
|
|
2248
|
+
headings,
|
|
2249
|
+
rowCount,
|
|
2250
|
+
rowHeight,
|
|
2251
|
+
size
|
|
2252
|
+
}) => {
|
|
2253
|
+
const pctScrollTopRef = (0, import_react21.useRef)(0);
|
|
2254
|
+
const pixelContentHeight = rowHeight * Math.min(rowCount, MAX_RAW_ROWS);
|
|
2255
|
+
const virtualContentHeight = rowCount * rowHeight;
|
|
2256
|
+
const virtualisedExtent = virtualContentHeight - pixelContentHeight;
|
|
2257
|
+
const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = (0, import_react21.useMemo)(
|
|
2258
|
+
() => measurePinnedColumns(columns),
|
|
2259
|
+
[columns]
|
|
2260
|
+
);
|
|
2261
|
+
const totalHeaderHeightRef = (0, import_react21.useRef)(headerHeight);
|
|
2262
|
+
(0, import_react21.useMemo)(() => {
|
|
2263
|
+
totalHeaderHeightRef.current = headerHeight * (1 + headings.length);
|
|
2264
|
+
}, [headerHeight, headings.length]);
|
|
2265
|
+
const [getRowOffset, getRowAtPosition, isVirtualScroll] = (0, import_react21.useMemo)(() => {
|
|
2266
|
+
if (virtualisedExtent) {
|
|
2267
|
+
return (0, import_vuu_utils17.virtualRowPositioning)(
|
|
2268
|
+
rowHeight,
|
|
2269
|
+
virtualisedExtent,
|
|
2270
|
+
pctScrollTopRef
|
|
2271
|
+
);
|
|
2272
|
+
} else {
|
|
2273
|
+
return (0, import_vuu_utils17.actualRowPositioning)(rowHeight);
|
|
2274
|
+
}
|
|
2275
|
+
}, [virtualisedExtent, rowHeight]);
|
|
2276
|
+
const setPctScrollTop = (0, import_react21.useCallback)((scrollPct) => {
|
|
2277
|
+
pctScrollTopRef.current = scrollPct;
|
|
2278
|
+
}, []);
|
|
2279
|
+
return (0, import_react21.useMemo)(() => {
|
|
2280
|
+
var _a;
|
|
2281
|
+
if (size) {
|
|
2282
|
+
const { current: totalHeaderHeight } = totalHeaderHeightRef;
|
|
2283
|
+
const scrollbarSize = 15;
|
|
2284
|
+
const contentWidth = pinnedWidthLeft + unpinnedWidth + pinnedWidthRight;
|
|
2285
|
+
const horizontalScrollbarHeight = contentWidth > size.width ? scrollbarSize : 0;
|
|
2286
|
+
const maxScrollContainerScrollVertical = pixelContentHeight - (((_a = size == null ? void 0 : size.height) != null ? _a : 0) - horizontalScrollbarHeight) + totalHeaderHeight;
|
|
2287
|
+
const maxScrollContainerScrollHorizontal = contentWidth - size.width + pinnedWidthLeft;
|
|
2288
|
+
const visibleRows = (size.height - headerHeight) / rowHeight;
|
|
2289
|
+
const count = Number.isInteger(visibleRows) ? visibleRows : Math.ceil(visibleRows);
|
|
2290
|
+
const viewportBodyHeight = size.height - totalHeaderHeight;
|
|
2291
|
+
const verticalScrollbarWidth = pixelContentHeight > viewportBodyHeight ? scrollbarSize : 0;
|
|
2292
|
+
const appliedPageSize = count * rowHeight * (pixelContentHeight / virtualContentHeight);
|
|
2293
|
+
return {
|
|
2294
|
+
appliedPageSize,
|
|
2295
|
+
contentHeight: pixelContentHeight,
|
|
2296
|
+
contentWidth,
|
|
2297
|
+
getRowAtPosition,
|
|
2298
|
+
getRowOffset,
|
|
2299
|
+
isVirtualScroll,
|
|
2300
|
+
horizontalScrollbarHeight,
|
|
2301
|
+
maxScrollContainerScrollHorizontal,
|
|
2302
|
+
maxScrollContainerScrollVertical,
|
|
2303
|
+
pinnedWidthLeft,
|
|
2304
|
+
pinnedWidthRight,
|
|
2305
|
+
rowCount: count,
|
|
2306
|
+
setPctScrollTop,
|
|
2307
|
+
totalHeaderHeight,
|
|
2308
|
+
verticalScrollbarWidth,
|
|
2309
|
+
viewportBodyHeight
|
|
2310
|
+
};
|
|
2311
|
+
} else {
|
|
2312
|
+
return UNMEASURED_VIEWPORT;
|
|
2313
|
+
}
|
|
2314
|
+
}, [
|
|
2315
|
+
getRowAtPosition,
|
|
2316
|
+
getRowOffset,
|
|
2317
|
+
headerHeight,
|
|
2318
|
+
isVirtualScroll,
|
|
2319
|
+
pinnedWidthLeft,
|
|
2320
|
+
unpinnedWidth,
|
|
2321
|
+
pinnedWidthRight,
|
|
2322
|
+
pixelContentHeight,
|
|
2323
|
+
rowHeight,
|
|
2324
|
+
setPctScrollTop,
|
|
2325
|
+
size,
|
|
2326
|
+
virtualContentHeight
|
|
2327
|
+
]);
|
|
2328
|
+
};
|
|
2329
|
+
|
|
2330
|
+
// src/useTableAndColumnSettings.ts
|
|
2331
|
+
var import_vuu_layout2 = require("@vuu-ui/vuu-layout");
|
|
2332
|
+
var import_vuu_utils18 = require("@vuu-ui/vuu-utils");
|
|
2333
|
+
var import_react22 = require("react");
|
|
2334
|
+
var useTableAndColumnSettings = ({
|
|
2335
|
+
availableColumns: availableColumnsProps,
|
|
2336
|
+
onAvailableColumnsChange,
|
|
2337
|
+
onConfigChange,
|
|
2338
|
+
onCreateCalculatedColumn,
|
|
2339
|
+
onDataSourceConfigChange,
|
|
2340
|
+
tableConfig
|
|
2341
|
+
}) => {
|
|
2342
|
+
const dispatchLayoutAction = (0, import_vuu_layout2.useLayoutProviderDispatch)();
|
|
2343
|
+
const showTableSettingsRef = (0, import_react22.useRef)();
|
|
2344
|
+
const [availableColumns, setAvailableColumns] = (0, import_react22.useState)(
|
|
2345
|
+
availableColumnsProps
|
|
2346
|
+
);
|
|
2347
|
+
const showContextPanel = (0, import_react22.useCallback)(
|
|
2348
|
+
(componentType, title, props) => {
|
|
2349
|
+
dispatchLayoutAction({
|
|
2350
|
+
type: "set-props",
|
|
2351
|
+
path: "#context-panel",
|
|
2352
|
+
props: {
|
|
2353
|
+
expanded: true,
|
|
2354
|
+
content: {
|
|
2355
|
+
type: componentType,
|
|
2356
|
+
props
|
|
2357
|
+
},
|
|
2358
|
+
title
|
|
2359
|
+
}
|
|
2360
|
+
});
|
|
2361
|
+
},
|
|
2362
|
+
[dispatchLayoutAction]
|
|
2363
|
+
);
|
|
2364
|
+
const handleCancelCreateColumn = (0, import_react22.useCallback)(() => {
|
|
2365
|
+
requestAnimationFrame(() => {
|
|
2366
|
+
var _a;
|
|
2367
|
+
(_a = showTableSettingsRef.current) == null ? void 0 : _a.call(showTableSettingsRef);
|
|
2368
|
+
});
|
|
2369
|
+
}, []);
|
|
2370
|
+
const handleCreateCalculatedColumn = (0, import_react22.useCallback)(
|
|
2371
|
+
(column) => {
|
|
2372
|
+
const newAvailableColumns = availableColumns.concat({
|
|
2373
|
+
name: column.name,
|
|
2374
|
+
serverDataType: (0, import_vuu_utils18.getCalculatedColumnType)(column)
|
|
2375
|
+
});
|
|
2376
|
+
setAvailableColumns(newAvailableColumns);
|
|
2377
|
+
onAvailableColumnsChange == null ? void 0 : onAvailableColumnsChange(newAvailableColumns);
|
|
2378
|
+
requestAnimationFrame(() => {
|
|
2379
|
+
var _a;
|
|
2380
|
+
(_a = showTableSettingsRef.current) == null ? void 0 : _a.call(showTableSettingsRef);
|
|
2381
|
+
});
|
|
2382
|
+
onCreateCalculatedColumn(column);
|
|
2383
|
+
},
|
|
2384
|
+
[availableColumns, onAvailableColumnsChange, onCreateCalculatedColumn]
|
|
2385
|
+
);
|
|
2386
|
+
const showColumnSettingsPanel = (0, import_react22.useCallback)(
|
|
2387
|
+
(action) => {
|
|
2388
|
+
showContextPanel("ColumnSettings", "Column Settings", {
|
|
2389
|
+
column: action.column,
|
|
2390
|
+
onCancelCreateColumn: handleCancelCreateColumn,
|
|
2391
|
+
onConfigChange,
|
|
2392
|
+
onCreateCalculatedColumn: handleCreateCalculatedColumn,
|
|
2393
|
+
tableConfig,
|
|
2394
|
+
vuuTable: action.vuuTable
|
|
2395
|
+
});
|
|
2396
|
+
},
|
|
2397
|
+
[
|
|
2398
|
+
handleCancelCreateColumn,
|
|
2399
|
+
handleCreateCalculatedColumn,
|
|
2400
|
+
onConfigChange,
|
|
2401
|
+
showContextPanel,
|
|
2402
|
+
tableConfig
|
|
2403
|
+
]
|
|
2404
|
+
);
|
|
2405
|
+
const handleAddCalculatedColumn = (0, import_react22.useCallback)(() => {
|
|
2406
|
+
showColumnSettingsPanel({
|
|
2407
|
+
column: {
|
|
2408
|
+
name: "::",
|
|
2409
|
+
serverDataType: "string"
|
|
2410
|
+
},
|
|
2411
|
+
type: "columnSettings",
|
|
2412
|
+
vuuTable: { module: "SIMUL", table: "instruments" }
|
|
2413
|
+
});
|
|
2414
|
+
}, [showColumnSettingsPanel]);
|
|
2415
|
+
const handleNavigateToColumn = (0, import_react22.useCallback)(
|
|
2416
|
+
(columnName) => {
|
|
2417
|
+
const column = tableConfig.columns.find((c) => c.name === columnName);
|
|
2418
|
+
if (column) {
|
|
2419
|
+
showColumnSettingsPanel({
|
|
2420
|
+
type: "columnSettings",
|
|
2421
|
+
column,
|
|
2422
|
+
//TODO where do we get this from
|
|
2423
|
+
vuuTable: { module: "SIMUL", table: "instruments" }
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
},
|
|
2427
|
+
[showColumnSettingsPanel, tableConfig.columns]
|
|
2428
|
+
);
|
|
2429
|
+
showTableSettingsRef.current = (0, import_react22.useCallback)(() => {
|
|
2430
|
+
showContextPanel("TableSettings", "DataGrid Settings", {
|
|
2431
|
+
availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name, serverDataType }) => ({
|
|
2432
|
+
name,
|
|
2433
|
+
serverDataType
|
|
2434
|
+
})),
|
|
2435
|
+
onAddCalculatedColumn: handleAddCalculatedColumn,
|
|
2436
|
+
onConfigChange,
|
|
2437
|
+
onDataSourceConfigChange,
|
|
2438
|
+
onNavigateToColumn: handleNavigateToColumn,
|
|
2439
|
+
tableConfig
|
|
2440
|
+
});
|
|
2441
|
+
}, [
|
|
2442
|
+
availableColumns,
|
|
2443
|
+
handleAddCalculatedColumn,
|
|
2444
|
+
handleNavigateToColumn,
|
|
2445
|
+
onConfigChange,
|
|
2446
|
+
onDataSourceConfigChange,
|
|
2447
|
+
showContextPanel,
|
|
2448
|
+
tableConfig
|
|
2449
|
+
]);
|
|
2450
|
+
return {
|
|
2451
|
+
showColumnSettingsPanel,
|
|
2452
|
+
showTableSettingsPanel: showTableSettingsRef.current
|
|
2453
|
+
};
|
|
2454
|
+
};
|
|
2455
|
+
|
|
2456
|
+
// src/useTable.ts
|
|
2457
|
+
var stripInternalProperties = (tableConfig) => {
|
|
2458
|
+
return tableConfig;
|
|
2459
|
+
};
|
|
2460
|
+
var { KEY, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = import_vuu_utils19.metadataKeys;
|
|
2461
|
+
var NULL_DRAG_DROP = {
|
|
2462
|
+
draggable: void 0,
|
|
2463
|
+
onMouseDown: void 0
|
|
2464
|
+
};
|
|
2465
|
+
var useNullDragDrop = () => NULL_DRAG_DROP;
|
|
2466
|
+
var addColumn = (tableConfig, column) => ({
|
|
2467
|
+
...tableConfig,
|
|
2468
|
+
columns: tableConfig.columns.concat(column)
|
|
2469
|
+
});
|
|
2470
|
+
var useTable = ({
|
|
2471
|
+
allowDragDrop = false,
|
|
2472
|
+
availableColumns,
|
|
2473
|
+
config,
|
|
2474
|
+
containerRef,
|
|
2475
|
+
dataSource,
|
|
2476
|
+
disableFocus,
|
|
2477
|
+
headerHeight = 25,
|
|
2478
|
+
highlightedIndex: highlightedIndexProp,
|
|
2479
|
+
id,
|
|
2480
|
+
navigationStyle = "cell",
|
|
2481
|
+
onAvailableColumnsChange,
|
|
2482
|
+
onConfigChange,
|
|
2483
|
+
onDragStart,
|
|
2484
|
+
onDrop,
|
|
2485
|
+
onFeatureInvocation,
|
|
2486
|
+
onHighlight,
|
|
2487
|
+
onRowClick: onRowClickProp,
|
|
2488
|
+
onSelect,
|
|
2489
|
+
onSelectionChange,
|
|
2490
|
+
renderBufferSize = 0,
|
|
2491
|
+
rowHeight = 20,
|
|
2492
|
+
scrollingApiRef,
|
|
2493
|
+
selectionModel,
|
|
2494
|
+
size
|
|
2495
|
+
}) => {
|
|
2496
|
+
const [rowCount, setRowCount] = (0, import_react23.useState)(dataSource.size);
|
|
2497
|
+
if (dataSource === void 0) {
|
|
2498
|
+
throw Error("no data source provided to Vuu Table");
|
|
2499
|
+
}
|
|
2500
|
+
const useRowDragDrop = allowDragDrop ? import_vuu_ui_controls2.useDragDrop : useNullDragDrop;
|
|
2501
|
+
const menuBuilder = (0, import_react23.useMemo)(
|
|
2502
|
+
() => buildContextMenuDescriptors(dataSource),
|
|
2503
|
+
[dataSource]
|
|
2504
|
+
);
|
|
2505
|
+
const onDataRowcountChange = (0, import_react23.useCallback)((size2) => {
|
|
2506
|
+
setRowCount(size2);
|
|
2507
|
+
}, []);
|
|
2508
|
+
const {
|
|
2509
|
+
columns: runtimeColumns,
|
|
2510
|
+
dispatchColumnAction,
|
|
2511
|
+
headings,
|
|
2512
|
+
tableAttributes,
|
|
2513
|
+
tableConfig
|
|
2514
|
+
} = useTableModel(config, dataSource);
|
|
2515
|
+
(0, import_vuu_utils19.useLayoutEffectSkipFirst)(() => {
|
|
2516
|
+
dispatchColumnAction({
|
|
2517
|
+
type: "init",
|
|
2518
|
+
dataSource,
|
|
2519
|
+
tableConfig
|
|
2520
|
+
});
|
|
2521
|
+
}, [tableConfig, dataSource, dispatchColumnAction]);
|
|
2522
|
+
const applyTableConfigChange = (0, import_react23.useCallback)(
|
|
2523
|
+
(config2) => {
|
|
2524
|
+
dispatchColumnAction({
|
|
2525
|
+
type: "init",
|
|
2526
|
+
tableConfig: config2,
|
|
2527
|
+
dataSource
|
|
2528
|
+
});
|
|
2529
|
+
onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(config2));
|
|
2530
|
+
},
|
|
2531
|
+
[dataSource, dispatchColumnAction, onConfigChange]
|
|
2532
|
+
);
|
|
2533
|
+
const [stateColumns, setStateColumns] = (0, import_react23.useState)();
|
|
2534
|
+
const [columns, setColumnSize] = (0, import_react23.useMemo)(() => {
|
|
2535
|
+
const setSize = (columnName, width) => {
|
|
2536
|
+
const cols = (0, import_vuu_utils19.updateColumn)(runtimeColumns, columnName, { width });
|
|
2537
|
+
setStateColumns(cols);
|
|
2538
|
+
};
|
|
2539
|
+
return [stateColumns != null ? stateColumns : runtimeColumns, setSize];
|
|
2540
|
+
}, [runtimeColumns, stateColumns]);
|
|
2541
|
+
const columnMap = (0, import_react23.useMemo)(
|
|
2542
|
+
() => (0, import_vuu_utils19.buildColumnMap)(dataSource.columns),
|
|
2543
|
+
[dataSource.columns]
|
|
2544
|
+
);
|
|
2545
|
+
const {
|
|
2546
|
+
getRowAtPosition,
|
|
2547
|
+
getRowOffset,
|
|
2548
|
+
setPctScrollTop,
|
|
2549
|
+
...viewportMeasurements
|
|
2550
|
+
} = useTableViewport({
|
|
2551
|
+
columns,
|
|
2552
|
+
headerHeight,
|
|
2553
|
+
headings,
|
|
2554
|
+
rowCount,
|
|
2555
|
+
rowHeight,
|
|
2556
|
+
size
|
|
2557
|
+
});
|
|
2558
|
+
const initialRange = useInitialValue({
|
|
2559
|
+
from: 0,
|
|
2560
|
+
to: viewportMeasurements.rowCount === 0 ? 0 : viewportMeasurements.rowCount + 1
|
|
2561
|
+
});
|
|
2562
|
+
const onSubscribed = (0, import_react23.useCallback)(
|
|
2563
|
+
({ tableSchema }) => {
|
|
2564
|
+
if (tableSchema) {
|
|
2565
|
+
dispatchColumnAction({
|
|
2566
|
+
type: "setTableSchema",
|
|
2567
|
+
tableSchema
|
|
2568
|
+
});
|
|
2569
|
+
} else {
|
|
2570
|
+
console.log("subscription message with no schema");
|
|
2571
|
+
}
|
|
2572
|
+
},
|
|
2573
|
+
[dispatchColumnAction]
|
|
2574
|
+
);
|
|
2575
|
+
const { data, dataRef, getSelectedRows, range, setRange } = useDataSource({
|
|
2576
|
+
dataSource,
|
|
2577
|
+
// We need to factor this out of Table
|
|
2578
|
+
onFeatureInvocation,
|
|
2579
|
+
renderBufferSize,
|
|
2580
|
+
onSizeChange: onDataRowcountChange,
|
|
2581
|
+
onSubscribed,
|
|
2582
|
+
range: initialRange
|
|
2583
|
+
});
|
|
2584
|
+
const handleConfigEditedInSettingsPanel = (0, import_react23.useCallback)(
|
|
2585
|
+
(tableConfig2) => {
|
|
2586
|
+
dispatchColumnAction({
|
|
2587
|
+
type: "init",
|
|
2588
|
+
tableConfig: tableConfig2,
|
|
2589
|
+
dataSource
|
|
2590
|
+
});
|
|
2591
|
+
onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(tableConfig2));
|
|
2592
|
+
},
|
|
2593
|
+
[dataSource, dispatchColumnAction, onConfigChange]
|
|
2594
|
+
);
|
|
2595
|
+
const handleDataSourceConfigChanged = (0, import_react23.useCallback)(
|
|
2596
|
+
(dataSourceConfig) => {
|
|
2597
|
+
dataSource.config = {
|
|
2598
|
+
...dataSource.config,
|
|
2599
|
+
...dataSourceConfig
|
|
2600
|
+
};
|
|
2601
|
+
},
|
|
2602
|
+
[dataSource]
|
|
2603
|
+
);
|
|
2604
|
+
(0, import_react23.useEffect)(() => {
|
|
2605
|
+
dataSource.on("config", (config2, confirmed) => {
|
|
2606
|
+
dispatchColumnAction({
|
|
2607
|
+
type: "tableConfig",
|
|
2608
|
+
...config2,
|
|
2609
|
+
confirmed
|
|
2610
|
+
});
|
|
2611
|
+
});
|
|
2612
|
+
}, [dataSource, dispatchColumnAction]);
|
|
2613
|
+
const handleCreateCalculatedColumn = (0, import_react23.useCallback)(
|
|
2614
|
+
(column) => {
|
|
2615
|
+
dataSource.columns = dataSource.columns.concat(column.name);
|
|
2616
|
+
applyTableConfigChange(addColumn(tableConfig, column));
|
|
2617
|
+
},
|
|
2618
|
+
[dataSource, tableConfig, applyTableConfigChange]
|
|
2619
|
+
);
|
|
2620
|
+
const hideColumns2 = (0, import_react23.useCallback)(
|
|
2621
|
+
(action) => {
|
|
2622
|
+
const { columns: columns2 } = action;
|
|
2623
|
+
const hiddenColumns = columns2.map((c) => c.name);
|
|
2624
|
+
const newTableConfig = {
|
|
2625
|
+
...tableConfig,
|
|
2626
|
+
columns: tableConfig.columns.map(
|
|
2627
|
+
(col) => hiddenColumns.includes(col.name) ? { ...col, hidden: true } : col
|
|
2628
|
+
)
|
|
2629
|
+
};
|
|
2630
|
+
applyTableConfigChange(newTableConfig);
|
|
2631
|
+
},
|
|
2632
|
+
[tableConfig, applyTableConfigChange]
|
|
2633
|
+
);
|
|
2634
|
+
const pinColumn3 = (0, import_react23.useCallback)(
|
|
2635
|
+
(action) => {
|
|
2636
|
+
applyTableConfigChange({
|
|
2637
|
+
...tableConfig,
|
|
2638
|
+
columns: (0, import_vuu_utils19.updateColumn)(tableConfig.columns, {
|
|
2639
|
+
...action.column,
|
|
2640
|
+
pin: action.pin
|
|
2641
|
+
})
|
|
2642
|
+
});
|
|
2643
|
+
},
|
|
2644
|
+
[tableConfig, applyTableConfigChange]
|
|
2645
|
+
);
|
|
2646
|
+
const { showColumnSettingsPanel, showTableSettingsPanel } = useTableAndColumnSettings({
|
|
2647
|
+
availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name, serverDataType = "string" }) => ({
|
|
2648
|
+
name,
|
|
2649
|
+
serverDataType
|
|
2650
|
+
})),
|
|
2651
|
+
onAvailableColumnsChange,
|
|
2652
|
+
onConfigChange: handleConfigEditedInSettingsPanel,
|
|
2653
|
+
onCreateCalculatedColumn: handleCreateCalculatedColumn,
|
|
2654
|
+
onDataSourceConfigChange: handleDataSourceConfigChanged,
|
|
2655
|
+
tableConfig
|
|
2656
|
+
});
|
|
2657
|
+
const onPersistentColumnOperation = (0, import_react23.useCallback)(
|
|
2658
|
+
(action) => {
|
|
2659
|
+
if (isShowColumnSettings(action)) {
|
|
2660
|
+
showColumnSettingsPanel(action);
|
|
2661
|
+
} else if (isShowTableSettings(action)) {
|
|
2662
|
+
showTableSettingsPanel();
|
|
2663
|
+
} else {
|
|
2664
|
+
switch (action.type) {
|
|
2665
|
+
case "hideColumns":
|
|
2666
|
+
return hideColumns2(action);
|
|
2667
|
+
case "pinColumn":
|
|
2668
|
+
return pinColumn3(action);
|
|
2669
|
+
default:
|
|
2670
|
+
dispatchColumnAction(action);
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
},
|
|
2674
|
+
[
|
|
2675
|
+
dispatchColumnAction,
|
|
2676
|
+
hideColumns2,
|
|
2677
|
+
pinColumn3,
|
|
2678
|
+
showColumnSettingsPanel,
|
|
2679
|
+
showTableSettingsPanel
|
|
2680
|
+
]
|
|
2681
|
+
);
|
|
2682
|
+
const handleContextMenuAction = useHandleTableContextMenu({
|
|
2683
|
+
dataSource,
|
|
2684
|
+
onPersistentColumnOperation
|
|
2685
|
+
});
|
|
2686
|
+
const handleSort = (0, import_react23.useCallback)(
|
|
2687
|
+
(column, extendSort = false, sortType) => {
|
|
2688
|
+
if (dataSource) {
|
|
2689
|
+
dataSource.sort = (0, import_vuu_utils19.applySort)(
|
|
2690
|
+
dataSource.sort,
|
|
2691
|
+
column,
|
|
2692
|
+
extendSort,
|
|
2693
|
+
sortType
|
|
2694
|
+
);
|
|
2695
|
+
}
|
|
2696
|
+
},
|
|
2697
|
+
[dataSource]
|
|
2698
|
+
);
|
|
2699
|
+
const onResizeColumn = (0, import_react23.useCallback)(
|
|
2700
|
+
(phase, columnName, width) => {
|
|
2701
|
+
const column = columns.find((column2) => column2.name === columnName);
|
|
2702
|
+
if (column) {
|
|
2703
|
+
if (phase === "resize") {
|
|
2704
|
+
if ((0, import_vuu_utils19.isValidNumber)(width)) {
|
|
2705
|
+
setColumnSize(columnName, width);
|
|
2706
|
+
}
|
|
2707
|
+
} else if (phase === "end") {
|
|
2708
|
+
if ((0, import_vuu_utils19.isValidNumber)(width)) {
|
|
2709
|
+
dispatchColumnAction({
|
|
2710
|
+
type: "resizeColumn",
|
|
2711
|
+
phase,
|
|
2712
|
+
column,
|
|
2713
|
+
width
|
|
2714
|
+
});
|
|
2715
|
+
setStateColumns(void 0);
|
|
2716
|
+
onConfigChange == null ? void 0 : onConfigChange(
|
|
2717
|
+
stripInternalProperties(
|
|
2718
|
+
updateTableConfig(tableConfig, {
|
|
2719
|
+
type: "col-size",
|
|
2720
|
+
column,
|
|
2721
|
+
width
|
|
2722
|
+
})
|
|
2723
|
+
)
|
|
2724
|
+
);
|
|
2725
|
+
}
|
|
2726
|
+
} else {
|
|
2727
|
+
setStateColumns(void 0);
|
|
2728
|
+
dispatchColumnAction({
|
|
2729
|
+
type: "resizeColumn",
|
|
2730
|
+
phase,
|
|
2731
|
+
column,
|
|
2732
|
+
width
|
|
2733
|
+
});
|
|
2734
|
+
}
|
|
2735
|
+
} else {
|
|
2736
|
+
throw Error(
|
|
2737
|
+
`useDataTable.handleColumnResize, column ${columnName} not found`
|
|
2738
|
+
);
|
|
2739
|
+
}
|
|
2740
|
+
},
|
|
2741
|
+
[columns, tableConfig, dispatchColumnAction, onConfigChange, setColumnSize]
|
|
2742
|
+
);
|
|
2743
|
+
const onToggleGroup = (0, import_react23.useCallback)(
|
|
2744
|
+
(row, column) => {
|
|
2745
|
+
var _a, _b;
|
|
2746
|
+
const isJson = (0, import_vuu_utils19.isJsonGroup)(column, row);
|
|
2747
|
+
const key = row[KEY];
|
|
2748
|
+
if (row[IS_EXPANDED2]) {
|
|
2749
|
+
dataSource.closeTreeNode(key, true);
|
|
2750
|
+
if (isJson) {
|
|
2751
|
+
const idx = columns.indexOf(column);
|
|
2752
|
+
const rows = (_a = dataSource.getRowsAtDepth) == null ? void 0 : _a.call(dataSource, idx + 1);
|
|
2753
|
+
if (rows && !rows.some((row2) => row2[IS_EXPANDED2] || row2[IS_LEAF2])) {
|
|
2754
|
+
dispatchColumnAction({
|
|
2755
|
+
type: "hideColumns",
|
|
2756
|
+
columns: columns.slice(idx + 2)
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
} else {
|
|
2761
|
+
dataSource.openTreeNode(key);
|
|
2762
|
+
if (isJson) {
|
|
2763
|
+
const childRows = (_b = dataSource.getChildRows) == null ? void 0 : _b.call(dataSource, key);
|
|
2764
|
+
const idx = columns.indexOf(column) + 1;
|
|
2765
|
+
const columnsToShow = [columns[idx]];
|
|
2766
|
+
if (childRows && childRows.some((row2) => row2[IS_LEAF2])) {
|
|
2767
|
+
columnsToShow.push(columns[idx + 1]);
|
|
2768
|
+
}
|
|
2769
|
+
if (columnsToShow.some((col) => col.hidden)) {
|
|
2770
|
+
dispatchColumnAction({
|
|
2771
|
+
type: "showColumns",
|
|
2772
|
+
columns: columnsToShow
|
|
2773
|
+
});
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
},
|
|
2778
|
+
[columns, dataSource, dispatchColumnAction]
|
|
2779
|
+
);
|
|
2780
|
+
const handleVerticalScroll = (0, import_react23.useCallback)(
|
|
2781
|
+
(_, pctScrollTop) => {
|
|
2782
|
+
setPctScrollTop(pctScrollTop);
|
|
2783
|
+
},
|
|
2784
|
+
[setPctScrollTop]
|
|
2785
|
+
);
|
|
2786
|
+
const { requestScroll, ...scrollProps } = useTableScroll({
|
|
2787
|
+
getRowAtPosition,
|
|
2788
|
+
rowHeight,
|
|
2789
|
+
scrollingApiRef,
|
|
2790
|
+
setRange,
|
|
2791
|
+
onVerticalScroll: handleVerticalScroll,
|
|
2792
|
+
viewportMeasurements
|
|
2793
|
+
});
|
|
2794
|
+
const {
|
|
2795
|
+
highlightedIndexRef,
|
|
2796
|
+
navigate,
|
|
2797
|
+
onFocus: navigationFocus,
|
|
2798
|
+
onKeyDown: navigationKeyDown,
|
|
2799
|
+
...containerProps
|
|
2800
|
+
} = useKeyboardNavigation({
|
|
2801
|
+
columnCount: columns.filter((c) => c.hidden !== true).length,
|
|
2802
|
+
containerRef,
|
|
2803
|
+
disableFocus,
|
|
2804
|
+
highlightedIndex: highlightedIndexProp,
|
|
2805
|
+
navigationStyle,
|
|
2806
|
+
requestScroll,
|
|
2807
|
+
rowCount: dataSource == null ? void 0 : dataSource.size,
|
|
2808
|
+
onHighlight,
|
|
2809
|
+
viewportRange: range,
|
|
2810
|
+
viewportRowCount: viewportMeasurements.rowCount
|
|
2811
|
+
});
|
|
2812
|
+
const {
|
|
2813
|
+
onBlur: editingBlur,
|
|
2814
|
+
onDoubleClick: editingDoubleClick,
|
|
2815
|
+
onKeyDown: editingKeyDown,
|
|
2816
|
+
onFocus: editingFocus
|
|
2817
|
+
} = useCellEditing({
|
|
2818
|
+
navigate
|
|
2819
|
+
});
|
|
2820
|
+
const handleFocus = (0, import_react23.useCallback)(
|
|
2821
|
+
(e) => {
|
|
2822
|
+
navigationFocus();
|
|
2823
|
+
if (!e.defaultPrevented) {
|
|
2824
|
+
editingFocus(e);
|
|
2825
|
+
}
|
|
2826
|
+
},
|
|
2827
|
+
[editingFocus, navigationFocus]
|
|
2828
|
+
);
|
|
2829
|
+
const onContextMenu = useTableContextMenu({
|
|
2830
|
+
columns,
|
|
2831
|
+
data,
|
|
2832
|
+
dataSource,
|
|
2833
|
+
getSelectedRows
|
|
2834
|
+
});
|
|
2835
|
+
const onMoveGroupColumn = (0, import_react23.useCallback)(
|
|
2836
|
+
(columns2) => {
|
|
2837
|
+
dataSource.groupBy = columns2.map((col) => col.name);
|
|
2838
|
+
},
|
|
2839
|
+
[dataSource]
|
|
2840
|
+
);
|
|
2841
|
+
const onRemoveGroupColumn = (0, import_react23.useCallback)(
|
|
2842
|
+
(column) => {
|
|
2843
|
+
if ((0, import_vuu_utils19.isGroupColumn)(column)) {
|
|
2844
|
+
dataSource.groupBy = [];
|
|
2845
|
+
} else {
|
|
2846
|
+
if (dataSource && dataSource.groupBy.includes(column.name)) {
|
|
2847
|
+
dataSource.groupBy = dataSource.groupBy.filter(
|
|
2848
|
+
(columnName) => columnName !== column.name
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
},
|
|
2853
|
+
[dataSource]
|
|
2854
|
+
);
|
|
2855
|
+
const handleSelectionChange = (0, import_react23.useCallback)(
|
|
2856
|
+
(selected) => {
|
|
2857
|
+
dataSource.select(selected);
|
|
2858
|
+
onSelectionChange == null ? void 0 : onSelectionChange(selected);
|
|
2859
|
+
},
|
|
2860
|
+
[dataSource, onSelectionChange]
|
|
2861
|
+
);
|
|
2862
|
+
const {
|
|
2863
|
+
onKeyDown: selectionHookKeyDown,
|
|
2864
|
+
onRowClick: selectionHookOnRowClick
|
|
2865
|
+
} = useSelection({
|
|
2866
|
+
highlightedIndexRef,
|
|
2867
|
+
onSelect,
|
|
2868
|
+
onSelectionChange: handleSelectionChange,
|
|
2869
|
+
selectionModel
|
|
2870
|
+
});
|
|
2871
|
+
const handleKeyDown = (0, import_react23.useCallback)(
|
|
2872
|
+
(e) => {
|
|
2873
|
+
navigationKeyDown(e);
|
|
2874
|
+
if (!e.defaultPrevented) {
|
|
2875
|
+
editingKeyDown(e);
|
|
2876
|
+
}
|
|
2877
|
+
if (!e.defaultPrevented) {
|
|
2878
|
+
selectionHookKeyDown(e);
|
|
2879
|
+
}
|
|
2880
|
+
},
|
|
2881
|
+
[navigationKeyDown, editingKeyDown, selectionHookKeyDown]
|
|
2882
|
+
);
|
|
2883
|
+
const handleRowClick = (0, import_react23.useCallback)(
|
|
2884
|
+
(row, rangeSelect, keepExistingSelection) => {
|
|
2885
|
+
selectionHookOnRowClick(row, rangeSelect, keepExistingSelection);
|
|
2886
|
+
onRowClickProp == null ? void 0 : onRowClickProp(row);
|
|
2887
|
+
},
|
|
2888
|
+
[onRowClickProp, selectionHookOnRowClick]
|
|
2889
|
+
);
|
|
2890
|
+
(0, import_vuu_utils19.useLayoutEffectSkipFirst)(() => {
|
|
2891
|
+
dispatchColumnAction({
|
|
2892
|
+
type: "init",
|
|
2893
|
+
tableConfig: config,
|
|
2894
|
+
dataSource
|
|
2895
|
+
});
|
|
2896
|
+
}, [config, dataSource, dispatchColumnAction]);
|
|
2897
|
+
const onMoveColumn = (0, import_react23.useCallback)(
|
|
2898
|
+
(columns2) => {
|
|
2899
|
+
console.log(`useTable onMoveColumn`, {
|
|
2900
|
+
columns: columns2
|
|
2901
|
+
});
|
|
2902
|
+
const newTableConfig = {
|
|
2903
|
+
...tableConfig,
|
|
2904
|
+
columns: columns2
|
|
2905
|
+
};
|
|
2906
|
+
dispatchColumnAction({
|
|
2907
|
+
type: "init",
|
|
2908
|
+
tableConfig: newTableConfig,
|
|
2909
|
+
dataSource
|
|
2910
|
+
});
|
|
2911
|
+
onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(newTableConfig));
|
|
2912
|
+
},
|
|
2913
|
+
[dataSource, dispatchColumnAction, onConfigChange, tableConfig]
|
|
2914
|
+
);
|
|
2915
|
+
const handleDropRow = (0, import_react23.useCallback)(
|
|
2916
|
+
(dragDropState) => {
|
|
2917
|
+
onDrop == null ? void 0 : onDrop(dragDropState);
|
|
2918
|
+
},
|
|
2919
|
+
[onDrop]
|
|
2920
|
+
);
|
|
2921
|
+
const handleDataEdited = (0, import_react23.useCallback)(
|
|
2922
|
+
async (row, columnName, value) => dataSource.applyEdit(row, columnName, value),
|
|
2923
|
+
[dataSource]
|
|
2924
|
+
);
|
|
2925
|
+
const handleDragStartRow = (0, import_react23.useCallback)(
|
|
2926
|
+
(dragDropState) => {
|
|
2927
|
+
const { initialDragElement } = dragDropState;
|
|
2928
|
+
const rowIndex = (0, import_vuu_utils19.getIndexFromRowElement)(initialDragElement);
|
|
2929
|
+
const row = dataRef.current.find((row2) => row2[0] === rowIndex);
|
|
2930
|
+
if (row) {
|
|
2931
|
+
dragDropState.setPayload(row);
|
|
2932
|
+
} else {
|
|
2933
|
+
}
|
|
2934
|
+
onDragStart == null ? void 0 : onDragStart(dragDropState);
|
|
2935
|
+
},
|
|
2936
|
+
[dataRef, onDragStart]
|
|
2937
|
+
);
|
|
2938
|
+
const { onMouseDown: rowDragMouseDown, draggable: draggableRow } = useRowDragDrop({
|
|
2939
|
+
allowDragDrop,
|
|
2940
|
+
containerRef,
|
|
2941
|
+
draggableClassName: `vuuTable`,
|
|
2942
|
+
id,
|
|
2943
|
+
onDragStart: handleDragStartRow,
|
|
2944
|
+
onDrop: handleDropRow,
|
|
2945
|
+
orientation: "vertical",
|
|
2946
|
+
itemQuery: ".vuuTableRow"
|
|
2947
|
+
});
|
|
2948
|
+
return {
|
|
2949
|
+
...containerProps,
|
|
2950
|
+
"aria-rowcount": dataSource.size,
|
|
2951
|
+
draggableRow,
|
|
2952
|
+
onBlur: editingBlur,
|
|
2953
|
+
onDoubleClick: editingDoubleClick,
|
|
2954
|
+
onFocus: handleFocus,
|
|
2955
|
+
onKeyDown: handleKeyDown,
|
|
2956
|
+
onMouseDown: rowDragMouseDown,
|
|
2957
|
+
columnMap,
|
|
2958
|
+
columns,
|
|
2959
|
+
data,
|
|
2960
|
+
getRowOffset,
|
|
2961
|
+
handleContextMenuAction,
|
|
2962
|
+
headings,
|
|
2963
|
+
highlightedIndex: highlightedIndexRef.current,
|
|
2964
|
+
menuBuilder,
|
|
2965
|
+
onContextMenu,
|
|
2966
|
+
onDataEdited: handleDataEdited,
|
|
2967
|
+
onMoveColumn,
|
|
2968
|
+
onMoveGroupColumn,
|
|
2969
|
+
onRemoveGroupColumn,
|
|
2970
|
+
onRowClick: handleRowClick,
|
|
2971
|
+
onSortColumn: handleSort,
|
|
2972
|
+
onResizeColumn,
|
|
2973
|
+
onToggleGroup,
|
|
2974
|
+
scrollProps,
|
|
2975
|
+
// TODO don't think we need these ...
|
|
2976
|
+
tableAttributes,
|
|
2977
|
+
tableConfig,
|
|
2978
|
+
viewportMeasurements
|
|
2979
|
+
};
|
|
2980
|
+
};
|
|
2981
|
+
|
|
2982
|
+
// src/table-header/TableHeader.tsx
|
|
2983
|
+
var import_vuu_utils21 = require("@vuu-ui/vuu-utils");
|
|
2984
|
+
var import_clsx8 = __toESM(require("clsx"));
|
|
2985
|
+
|
|
2986
|
+
// src/table-header/useTableHeader.ts
|
|
2987
|
+
var import_vuu_ui_controls3 = require("@vuu-ui/vuu-ui-controls");
|
|
2988
|
+
var import_vuu_utils20 = require("@vuu-ui/vuu-utils");
|
|
2989
|
+
var import_react24 = require("react");
|
|
2990
|
+
var useTableHeader = ({
|
|
2991
|
+
columns,
|
|
2992
|
+
onMoveColumn,
|
|
2993
|
+
onSortColumn,
|
|
2994
|
+
tableConfig
|
|
2995
|
+
}) => {
|
|
2996
|
+
const containerRef = (0, import_react24.useRef)(null);
|
|
2997
|
+
const handleDropColumnHeader = (0, import_react24.useCallback)(
|
|
2998
|
+
(moveFrom, moveTo) => {
|
|
2999
|
+
const column = columns[moveFrom];
|
|
3000
|
+
const orderedColumns = (0, import_vuu_utils20.moveColumnTo)(columns, column, moveTo);
|
|
3001
|
+
const ofColumn = ({ name }) => (col) => col.name === name;
|
|
3002
|
+
const targetIndex = orderedColumns.findIndex(ofColumn(column));
|
|
3003
|
+
const nextColumn = orderedColumns[targetIndex + 1];
|
|
3004
|
+
const insertPos = nextColumn ? tableConfig.columns.findIndex(ofColumn(nextColumn)) : -1;
|
|
3005
|
+
if (moveTo > moveFrom && insertPos !== -1) {
|
|
3006
|
+
onMoveColumn((0, import_vuu_utils20.moveColumnTo)(tableConfig.columns, column, insertPos - 1));
|
|
3007
|
+
} else {
|
|
3008
|
+
onMoveColumn((0, import_vuu_utils20.moveColumnTo)(tableConfig.columns, column, insertPos));
|
|
3009
|
+
}
|
|
3010
|
+
},
|
|
3011
|
+
[columns, onMoveColumn, tableConfig.columns]
|
|
3012
|
+
);
|
|
3013
|
+
const handleColumnHeaderClick = (0, import_react24.useCallback)(
|
|
3014
|
+
(evt) => {
|
|
3015
|
+
var _a;
|
|
3016
|
+
const targetElement = evt.target;
|
|
3017
|
+
const headerCell = targetElement.closest(
|
|
3018
|
+
".vuuTableHeaderCell"
|
|
3019
|
+
);
|
|
3020
|
+
const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.index) != null ? _a : "-1");
|
|
3021
|
+
const column = (0, import_vuu_utils20.visibleColumnAtIndex)(columns, colIdx);
|
|
3022
|
+
const isAdditive = evt.shiftKey;
|
|
3023
|
+
column && onSortColumn(column, isAdditive);
|
|
3024
|
+
},
|
|
3025
|
+
[columns, onSortColumn]
|
|
3026
|
+
);
|
|
3027
|
+
const {
|
|
3028
|
+
onMouseDown: columnHeaderDragMouseDown,
|
|
3029
|
+
draggable: draggableColumn,
|
|
3030
|
+
...dragDropHook
|
|
3031
|
+
} = (0, import_vuu_ui_controls3.useDragDrop)({
|
|
3032
|
+
allowDragDrop: true,
|
|
3033
|
+
containerRef,
|
|
3034
|
+
draggableClassName: `vuuTable`,
|
|
3035
|
+
onDrop: handleDropColumnHeader,
|
|
3036
|
+
orientation: "horizontal",
|
|
3037
|
+
itemQuery: ".vuuTableHeaderCell"
|
|
3038
|
+
});
|
|
3039
|
+
return {
|
|
3040
|
+
containerRef,
|
|
3041
|
+
draggableColumn,
|
|
3042
|
+
draggedColumnIndex: dragDropHook.draggedItemIndex,
|
|
3043
|
+
onClick: handleColumnHeaderClick,
|
|
3044
|
+
onMouseDown: columnHeaderDragMouseDown
|
|
3045
|
+
};
|
|
3046
|
+
};
|
|
3047
|
+
|
|
3048
|
+
// src/table-header/TableHeader.tsx
|
|
3049
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
3050
|
+
var TableHeader = ({
|
|
3051
|
+
classBase: classBase10 = "vuuTable",
|
|
3052
|
+
columns,
|
|
3053
|
+
headings,
|
|
3054
|
+
onMoveColumn,
|
|
3055
|
+
onMoveGroupColumn,
|
|
3056
|
+
onRemoveGroupColumn,
|
|
3057
|
+
onResizeColumn,
|
|
3058
|
+
onSortColumn,
|
|
3059
|
+
tableConfig,
|
|
3060
|
+
tableId
|
|
3061
|
+
}) => {
|
|
3062
|
+
const {
|
|
3063
|
+
containerRef,
|
|
3064
|
+
draggableColumn,
|
|
3065
|
+
draggedColumnIndex,
|
|
3066
|
+
onClick,
|
|
3067
|
+
onMouseDown
|
|
3068
|
+
} = useTableHeader({
|
|
3069
|
+
columns,
|
|
3070
|
+
onMoveColumn,
|
|
3071
|
+
onSortColumn,
|
|
3072
|
+
tableConfig
|
|
3073
|
+
});
|
|
3074
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: `${classBase10}-col-headings`, ref: containerRef, children: [
|
|
3075
|
+
headings.map((colHeaders, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "vuuTable-heading", children: colHeaders.map(({ label, width }, j) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "vuuTable-headingCell", style: { width }, children: label }, j)) }, i)),
|
|
3076
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: `${classBase10}-col-headers`, role: "row", children: [
|
|
3077
|
+
columns.filter(import_vuu_utils21.isNotHidden).map(
|
|
3078
|
+
(col, i) => (0, import_vuu_utils21.isGroupColumn)(col) ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3079
|
+
GroupHeaderCellNext,
|
|
3080
|
+
{
|
|
3081
|
+
column: col,
|
|
3082
|
+
"data-index": i,
|
|
3083
|
+
onMoveColumn: onMoveGroupColumn,
|
|
3084
|
+
onRemoveColumn: onRemoveGroupColumn,
|
|
3085
|
+
onResize: onResizeColumn
|
|
3086
|
+
},
|
|
3087
|
+
col.name
|
|
3088
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3089
|
+
HeaderCell,
|
|
3090
|
+
{
|
|
3091
|
+
className: (0, import_clsx8.default)({
|
|
3092
|
+
"vuuDraggable-dragAway": i === draggedColumnIndex
|
|
3093
|
+
}),
|
|
3094
|
+
column: col,
|
|
3095
|
+
"data-index": i,
|
|
3096
|
+
id: `${tableId}-col-${i}`,
|
|
3097
|
+
onClick,
|
|
3098
|
+
onMouseDown,
|
|
3099
|
+
onResize: onResizeColumn
|
|
3100
|
+
},
|
|
3101
|
+
col.name
|
|
3102
|
+
)
|
|
3103
|
+
),
|
|
3104
|
+
draggableColumn
|
|
3105
|
+
] })
|
|
3106
|
+
] });
|
|
3107
|
+
};
|
|
3108
|
+
|
|
3109
|
+
// src/Table.tsx
|
|
3110
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
3111
|
+
var classBase7 = "vuuTable";
|
|
3112
|
+
var { IDX: IDX3, RENDER_IDX } = import_vuu_utils22.metadataKeys;
|
|
3113
|
+
var TableCore = ({
|
|
3114
|
+
Row: Row2 = Row,
|
|
3115
|
+
allowDragDrop,
|
|
3116
|
+
availableColumns,
|
|
3117
|
+
config,
|
|
3118
|
+
containerRef,
|
|
3119
|
+
dataSource,
|
|
3120
|
+
disableFocus = false,
|
|
3121
|
+
highlightedIndex: highlightedIndexProp,
|
|
3122
|
+
id: idProp,
|
|
3123
|
+
navigationStyle = "cell",
|
|
3124
|
+
onAvailableColumnsChange,
|
|
3125
|
+
onConfigChange,
|
|
3126
|
+
onDragStart,
|
|
3127
|
+
onDrop,
|
|
3128
|
+
onFeatureInvocation,
|
|
3129
|
+
onHighlight,
|
|
3130
|
+
onRowClick: onRowClickProp,
|
|
3131
|
+
onSelect,
|
|
3132
|
+
onSelectionChange,
|
|
3133
|
+
renderBufferSize = 5,
|
|
3134
|
+
rowHeight = 20,
|
|
3135
|
+
scrollingApiRef,
|
|
3136
|
+
selectionModel = "extended",
|
|
3137
|
+
showColumnHeaders = true,
|
|
3138
|
+
headerHeight = showColumnHeaders ? 25 : 0,
|
|
3139
|
+
size
|
|
3140
|
+
}) => {
|
|
3141
|
+
const id = (0, import_vuu_utils22.useId)(idProp);
|
|
3142
|
+
const {
|
|
3143
|
+
columnMap,
|
|
3144
|
+
columns,
|
|
3145
|
+
data,
|
|
3146
|
+
draggableRow,
|
|
3147
|
+
getRowOffset,
|
|
3148
|
+
handleContextMenuAction,
|
|
3149
|
+
headings,
|
|
3150
|
+
highlightedIndex,
|
|
3151
|
+
onDataEdited,
|
|
3152
|
+
onMoveColumn,
|
|
3153
|
+
onMoveGroupColumn,
|
|
3154
|
+
onRemoveGroupColumn,
|
|
3155
|
+
onResizeColumn,
|
|
3156
|
+
onRowClick,
|
|
3157
|
+
onSortColumn,
|
|
3158
|
+
onToggleGroup,
|
|
3159
|
+
menuBuilder,
|
|
3160
|
+
scrollProps,
|
|
3161
|
+
tableAttributes,
|
|
3162
|
+
tableConfig,
|
|
3163
|
+
viewportMeasurements,
|
|
3164
|
+
...tableProps
|
|
3165
|
+
} = useTable({
|
|
3166
|
+
allowDragDrop,
|
|
3167
|
+
availableColumns,
|
|
3168
|
+
config,
|
|
3169
|
+
containerRef,
|
|
3170
|
+
dataSource,
|
|
3171
|
+
disableFocus,
|
|
3172
|
+
headerHeight,
|
|
3173
|
+
highlightedIndex: highlightedIndexProp,
|
|
3174
|
+
id,
|
|
3175
|
+
navigationStyle,
|
|
3176
|
+
onAvailableColumnsChange,
|
|
3177
|
+
onConfigChange,
|
|
3178
|
+
onDragStart,
|
|
3179
|
+
onDrop,
|
|
3180
|
+
onFeatureInvocation,
|
|
3181
|
+
onHighlight,
|
|
3182
|
+
onRowClick: onRowClickProp,
|
|
3183
|
+
onSelect,
|
|
3184
|
+
onSelectionChange,
|
|
3185
|
+
renderBufferSize,
|
|
3186
|
+
rowHeight,
|
|
3187
|
+
scrollingApiRef,
|
|
3188
|
+
selectionModel,
|
|
3189
|
+
size
|
|
3190
|
+
});
|
|
3191
|
+
const contentContainerClassName = (0, import_clsx9.default)(`${classBase7}-contentContainer`, {
|
|
3192
|
+
[`${classBase7}-colLines`]: tableAttributes.columnSeparators,
|
|
3193
|
+
[`${classBase7}-rowLines`]: tableAttributes.rowSeparators,
|
|
3194
|
+
// [`${classBase}-highlight`]: tableAttributes.showHighlightedRow,
|
|
3195
|
+
[`${classBase7}-zebra`]: tableAttributes.zebraStripes
|
|
3196
|
+
// [`${classBase}-loading`]: isDataLoading(tableProps.columns),
|
|
3197
|
+
});
|
|
3198
|
+
const cssVariables = {
|
|
3199
|
+
"--content-height": `${viewportMeasurements.contentHeight}px`,
|
|
3200
|
+
"--content-width": `${viewportMeasurements.contentWidth}px`,
|
|
3201
|
+
"--horizontal-scrollbar-height": `${viewportMeasurements.horizontalScrollbarHeight}px`,
|
|
3202
|
+
"--pinned-width-left": `${viewportMeasurements.pinnedWidthLeft}px`,
|
|
3203
|
+
"--pinned-width-right": `${viewportMeasurements.pinnedWidthRight}px`,
|
|
3204
|
+
"--header-height": `${headerHeight}px`,
|
|
3205
|
+
"--row-height": `${rowHeight}px`,
|
|
3206
|
+
"--total-header-height": `${viewportMeasurements.totalHeaderHeight}px`,
|
|
3207
|
+
"--vertical-scrollbar-width": `${viewportMeasurements.verticalScrollbarWidth}px`,
|
|
3208
|
+
"--viewport-body-height": `${viewportMeasurements.viewportBodyHeight}px`
|
|
3209
|
+
};
|
|
3210
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
3211
|
+
import_vuu_popups3.ContextMenuProvider,
|
|
3212
|
+
{
|
|
3213
|
+
menuActionHandler: handleContextMenuAction,
|
|
3214
|
+
menuBuilder,
|
|
3215
|
+
children: [
|
|
3216
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3217
|
+
"div",
|
|
3218
|
+
{
|
|
3219
|
+
className: `${classBase7}-scrollbarContainer`,
|
|
3220
|
+
ref: scrollProps.scrollbarContainerRef,
|
|
3221
|
+
style: cssVariables,
|
|
3222
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `${classBase7}-scrollbarContent` })
|
|
3223
|
+
}
|
|
3224
|
+
),
|
|
3225
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3226
|
+
"div",
|
|
3227
|
+
{
|
|
3228
|
+
className: contentContainerClassName,
|
|
3229
|
+
ref: scrollProps.contentContainerRef,
|
|
3230
|
+
style: cssVariables,
|
|
3231
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
3232
|
+
"div",
|
|
3233
|
+
{
|
|
3234
|
+
...tableProps,
|
|
3235
|
+
className: `${classBase7}-table`,
|
|
3236
|
+
role: "table",
|
|
3237
|
+
tabIndex: disableFocus ? void 0 : -1,
|
|
3238
|
+
children: [
|
|
3239
|
+
showColumnHeaders ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3240
|
+
TableHeader,
|
|
3241
|
+
{
|
|
3242
|
+
columns,
|
|
3243
|
+
headings,
|
|
3244
|
+
onMoveColumn,
|
|
3245
|
+
onMoveGroupColumn,
|
|
3246
|
+
onRemoveGroupColumn,
|
|
3247
|
+
onResizeColumn,
|
|
3248
|
+
onSortColumn,
|
|
3249
|
+
tableConfig,
|
|
3250
|
+
tableId: id
|
|
3251
|
+
}
|
|
3252
|
+
) : null,
|
|
3253
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `${classBase7}-body`, children: data.map((data2) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3254
|
+
Row2,
|
|
3255
|
+
{
|
|
3256
|
+
"aria-rowindex": data2[0] + 1,
|
|
3257
|
+
columnMap,
|
|
3258
|
+
columns,
|
|
3259
|
+
highlighted: highlightedIndex === data2[IDX3],
|
|
3260
|
+
onClick: onRowClick,
|
|
3261
|
+
onDataEdited,
|
|
3262
|
+
row: data2,
|
|
3263
|
+
offset: getRowOffset(data2),
|
|
3264
|
+
onToggleGroup,
|
|
3265
|
+
zebraStripes: tableAttributes.zebraStripes
|
|
3266
|
+
},
|
|
3267
|
+
data2[RENDER_IDX]
|
|
3268
|
+
)) })
|
|
3269
|
+
]
|
|
3270
|
+
}
|
|
3271
|
+
)
|
|
3272
|
+
}
|
|
3273
|
+
),
|
|
3274
|
+
draggableRow
|
|
3275
|
+
]
|
|
3276
|
+
}
|
|
3277
|
+
);
|
|
3278
|
+
};
|
|
3279
|
+
var Table = (0, import_react25.forwardRef)(function TableNext({
|
|
3280
|
+
Row: Row2,
|
|
3281
|
+
allowDragDrop,
|
|
3282
|
+
availableColumns,
|
|
3283
|
+
className: classNameProp,
|
|
3284
|
+
config,
|
|
3285
|
+
dataSource,
|
|
3286
|
+
disableFocus,
|
|
3287
|
+
highlightedIndex,
|
|
3288
|
+
id,
|
|
3289
|
+
navigationStyle,
|
|
3290
|
+
onAvailableColumnsChange,
|
|
3291
|
+
onConfigChange,
|
|
3292
|
+
onDragStart,
|
|
3293
|
+
onDrop,
|
|
3294
|
+
onFeatureInvocation,
|
|
3295
|
+
onHighlight,
|
|
3296
|
+
onRowClick,
|
|
3297
|
+
onSelect,
|
|
3298
|
+
onSelectionChange,
|
|
3299
|
+
renderBufferSize,
|
|
3300
|
+
rowHeight,
|
|
3301
|
+
scrollingApiRef,
|
|
3302
|
+
selectionModel,
|
|
3303
|
+
showColumnHeaders,
|
|
3304
|
+
headerHeight,
|
|
3305
|
+
style: styleProp,
|
|
3306
|
+
...htmlAttributes
|
|
3307
|
+
}, forwardedRef) {
|
|
3308
|
+
const containerRef = (0, import_react25.useRef)(null);
|
|
3309
|
+
const [size, setSize] = (0, import_react25.useState)();
|
|
3310
|
+
if (config === void 0) {
|
|
3311
|
+
throw Error(
|
|
3312
|
+
"vuu Table requires config prop. Minimum config is list of Column Descriptors"
|
|
3313
|
+
);
|
|
3314
|
+
}
|
|
3315
|
+
if (dataSource === void 0) {
|
|
3316
|
+
throw Error("vuu Table requires dataSource prop");
|
|
3317
|
+
}
|
|
3318
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3319
|
+
import_vuu_layout3.MeasuredContainer,
|
|
3320
|
+
{
|
|
3321
|
+
...htmlAttributes,
|
|
3322
|
+
className: (0, import_clsx9.default)(classBase7, classNameProp),
|
|
3323
|
+
id,
|
|
3324
|
+
onResize: setSize,
|
|
3325
|
+
ref: (0, import_core2.useForkRef)(containerRef, forwardedRef),
|
|
3326
|
+
children: size ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3327
|
+
TableCore,
|
|
3328
|
+
{
|
|
3329
|
+
Row: Row2,
|
|
3330
|
+
allowDragDrop,
|
|
3331
|
+
availableColumns,
|
|
3332
|
+
config,
|
|
3333
|
+
containerRef,
|
|
3334
|
+
dataSource,
|
|
3335
|
+
disableFocus,
|
|
3336
|
+
headerHeight,
|
|
3337
|
+
highlightedIndex,
|
|
3338
|
+
id,
|
|
3339
|
+
navigationStyle,
|
|
3340
|
+
onAvailableColumnsChange,
|
|
3341
|
+
onConfigChange,
|
|
3342
|
+
onDragStart,
|
|
3343
|
+
onDrop,
|
|
3344
|
+
onFeatureInvocation,
|
|
3345
|
+
onHighlight,
|
|
3346
|
+
onRowClick,
|
|
3347
|
+
onSelect,
|
|
3348
|
+
onSelectionChange,
|
|
3349
|
+
renderBufferSize,
|
|
3350
|
+
rowHeight,
|
|
3351
|
+
scrollingApiRef,
|
|
3352
|
+
selectionModel,
|
|
3353
|
+
showColumnHeaders,
|
|
3354
|
+
size
|
|
3355
|
+
}
|
|
3356
|
+
) : null
|
|
3357
|
+
}
|
|
3358
|
+
);
|
|
3359
|
+
});
|
|
3360
|
+
|
|
3361
|
+
// src/cell-renderers/checkbox-cell/CheckboxCell.tsx
|
|
3362
|
+
var import_react26 = require("react");
|
|
3363
|
+
var import_vuu_ui_controls4 = require("@vuu-ui/vuu-ui-controls");
|
|
3364
|
+
var import_core3 = require("@salt-ds/core");
|
|
3365
|
+
|
|
3366
|
+
// src/cell-renderers/cell-utils.ts
|
|
3367
|
+
var dataAndColumnUnchanged = (p, p1) => p.column === p1.column && p.column.valueFormatter(p.row[p.columnMap[p.column.name]]) === p1.column.valueFormatter(p1.row[p1.columnMap[p1.column.name]]);
|
|
3368
|
+
|
|
3369
|
+
// src/cell-renderers/checkbox-cell/CheckboxCell.tsx
|
|
3370
|
+
var import_vuu_utils23 = require("@vuu-ui/vuu-utils");
|
|
3371
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
3372
|
+
var CheckboxCell = (0, import_react26.memo)(
|
|
3373
|
+
({ column, columnMap, onCommit = import_vuu_ui_controls4.WarnCommit, row }) => {
|
|
3374
|
+
const dataIdx = columnMap[column.name];
|
|
3375
|
+
const isChecked = row[dataIdx];
|
|
3376
|
+
const handleCommit = (0, import_react26.useCallback)(
|
|
3377
|
+
(value) => async (evt) => {
|
|
3378
|
+
const res = await onCommit(value);
|
|
3379
|
+
if (res === true) {
|
|
3380
|
+
(0, import_vuu_utils23.dispatchCustomEvent)(evt.target, "vuu-commit");
|
|
3381
|
+
}
|
|
3382
|
+
return res;
|
|
3383
|
+
},
|
|
3384
|
+
[onCommit]
|
|
3385
|
+
);
|
|
3386
|
+
return column.editable ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core3.Checkbox, { checked: isChecked, onClick: handleCommit(!isChecked) }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_vuu_ui_controls4.CheckboxIcon, { checked: isChecked, disabled: true });
|
|
3387
|
+
},
|
|
3388
|
+
dataAndColumnUnchanged
|
|
3389
|
+
);
|
|
3390
|
+
CheckboxCell.displayName = "CheckboxCell";
|
|
3391
|
+
(0, import_vuu_utils23.registerComponent)("checkbox-cell", CheckboxCell, "cell-renderer", {
|
|
3392
|
+
serverDataType: "boolean"
|
|
3393
|
+
});
|
|
3394
|
+
|
|
3395
|
+
// src/cell-renderers/input-cell/InputCell.tsx
|
|
3396
|
+
var import_vuu_utils24 = require("@vuu-ui/vuu-utils");
|
|
3397
|
+
var import_core4 = require("@salt-ds/core");
|
|
3398
|
+
var import_vuu_ui_controls5 = require("@vuu-ui/vuu-ui-controls");
|
|
3399
|
+
var import_clsx10 = __toESM(require("clsx"));
|
|
3400
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
3401
|
+
var classBase8 = "vuuTableInputCell";
|
|
3402
|
+
var WarnCommit2 = () => {
|
|
3403
|
+
console.warn(
|
|
3404
|
+
"onCommit handler has not been provided to InputCell cell renderer"
|
|
3405
|
+
);
|
|
3406
|
+
return Promise.resolve(true);
|
|
3407
|
+
};
|
|
3408
|
+
var InputCell = ({
|
|
3409
|
+
column,
|
|
3410
|
+
columnMap,
|
|
3411
|
+
onCommit = WarnCommit2,
|
|
3412
|
+
row
|
|
3413
|
+
}) => {
|
|
3414
|
+
const dataIdx = columnMap[column.name];
|
|
3415
|
+
const { align = "left", clientSideEditValidationCheck } = column;
|
|
3416
|
+
const { warningMessage, ...editProps } = (0, import_vuu_ui_controls5.useEditableText)({
|
|
3417
|
+
initialValue: row[dataIdx],
|
|
3418
|
+
onCommit,
|
|
3419
|
+
clientSideEditValidationCheck
|
|
3420
|
+
});
|
|
3421
|
+
const endAdornment = warningMessage && align === "left" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: `${classBase8}-icon`, "data-icon": "error" }) : void 0;
|
|
3422
|
+
const startAdornment = warningMessage && align === "right" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: `${classBase8}-icon`, "data-icon": "error" }) : void 0;
|
|
3423
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3424
|
+
import_core4.Input,
|
|
3425
|
+
{
|
|
3426
|
+
...editProps,
|
|
3427
|
+
className: (0, import_clsx10.default)(classBase8, {
|
|
3428
|
+
[`${classBase8}-error`]: warningMessage !== void 0
|
|
3429
|
+
}),
|
|
3430
|
+
endAdornment,
|
|
3431
|
+
startAdornment
|
|
3432
|
+
}
|
|
3433
|
+
);
|
|
3434
|
+
};
|
|
3435
|
+
(0, import_vuu_utils24.registerComponent)("input-cell", InputCell, "cell-renderer", {});
|
|
3436
|
+
|
|
3437
|
+
// src/cell-renderers/toggle-cell/ToggleCell.tsx
|
|
3438
|
+
var import_vuu_ui_controls6 = require("@vuu-ui/vuu-ui-controls");
|
|
3439
|
+
var import_vuu_utils25 = require("@vuu-ui/vuu-utils");
|
|
3440
|
+
var import_clsx11 = __toESM(require("clsx"));
|
|
3441
|
+
var import_react27 = require("react");
|
|
3442
|
+
var import_vuu_ui_controls7 = require("@vuu-ui/vuu-ui-controls");
|
|
3443
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
3444
|
+
var classBase9 = "vuuTableToggleCell";
|
|
3445
|
+
var getValueList = ({ name, type }) => {
|
|
3446
|
+
if ((0, import_vuu_utils25.isTypeDescriptor)(type) && (0, import_vuu_utils25.isValueListRenderer)(type.renderer)) {
|
|
3447
|
+
return type.renderer.values;
|
|
3448
|
+
} else {
|
|
3449
|
+
throw Error(
|
|
3450
|
+
`useLookupValues column ${name} has not been configured with a values list`
|
|
3451
|
+
);
|
|
3452
|
+
}
|
|
3453
|
+
};
|
|
3454
|
+
var ToggleCell = (0, import_react27.memo)(
|
|
3455
|
+
function ToggleCell2({
|
|
3456
|
+
column,
|
|
3457
|
+
columnMap,
|
|
3458
|
+
onCommit = import_vuu_ui_controls6.WarnCommit,
|
|
3459
|
+
row
|
|
3460
|
+
}) {
|
|
3461
|
+
const values = getValueList(column);
|
|
3462
|
+
const dataIdx = columnMap[column.name];
|
|
3463
|
+
const value = row[dataIdx];
|
|
3464
|
+
const handleCommit = (0, import_react27.useCallback)(
|
|
3465
|
+
(evt, value2) => {
|
|
3466
|
+
return onCommit(value2).then((response) => {
|
|
3467
|
+
if (response === true) {
|
|
3468
|
+
(0, import_vuu_utils25.dispatchCustomEvent)(evt.target, "vuu-commit");
|
|
3469
|
+
}
|
|
3470
|
+
return response;
|
|
3471
|
+
});
|
|
3472
|
+
},
|
|
3473
|
+
[onCommit]
|
|
3474
|
+
);
|
|
3475
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
|
|
3476
|
+
import_vuu_ui_controls7.CycleStateButton,
|
|
3477
|
+
{
|
|
3478
|
+
className: (0, import_clsx11.default)(classBase9, `${classBase9}-${column.name}`),
|
|
3479
|
+
onCommit: handleCommit,
|
|
3480
|
+
value,
|
|
3481
|
+
values,
|
|
3482
|
+
variant: "cta",
|
|
3483
|
+
children: value
|
|
3484
|
+
}
|
|
3485
|
+
);
|
|
3486
|
+
},
|
|
3487
|
+
dataAndColumnUnchanged
|
|
3488
|
+
);
|
|
3489
|
+
(0, import_vuu_utils25.registerComponent)("toggle-cell", ToggleCell, "cell-renderer", {});
|
|
3490
|
+
|
|
3491
|
+
// src/useControlledTableNavigation.ts
|
|
3492
|
+
var import_vuu_ui_controls8 = require("@vuu-ui/vuu-ui-controls");
|
|
3493
|
+
var import_vuu_utils26 = require("@vuu-ui/vuu-utils");
|
|
3494
|
+
var import_react28 = require("react");
|
|
3495
|
+
var useControlledTableNavigation = (initialValue, rowCount) => {
|
|
3496
|
+
const tableRef = (0, import_react28.useRef)(null);
|
|
3497
|
+
const [highlightedIndexRef, setHighlightedIndex] = (0, import_vuu_ui_controls8.useStateRef)(initialValue);
|
|
3498
|
+
const handleKeyDown = (0, import_react28.useCallback)(
|
|
3499
|
+
(e) => {
|
|
3500
|
+
var _a;
|
|
3501
|
+
if (e.key === "ArrowDown") {
|
|
3502
|
+
setHighlightedIndex((index = -1) => Math.min(rowCount - 1, index + 1));
|
|
3503
|
+
} else if (e.key === "ArrowUp") {
|
|
3504
|
+
setHighlightedIndex((index = -1) => Math.max(0, index - 1));
|
|
3505
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
3506
|
+
const { current: rowIdx } = highlightedIndexRef;
|
|
3507
|
+
const rowEl = (_a = tableRef.current) == null ? void 0 : _a.querySelector(
|
|
3508
|
+
`[aria-rowindex="${rowIdx}"]`
|
|
3509
|
+
);
|
|
3510
|
+
if (rowEl) {
|
|
3511
|
+
(0, import_vuu_utils26.dispatchMouseEvent)(rowEl, "click");
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
},
|
|
3515
|
+
[highlightedIndexRef, rowCount, setHighlightedIndex]
|
|
3516
|
+
);
|
|
3517
|
+
const handleHighlight = (0, import_react28.useCallback)(
|
|
3518
|
+
(idx) => {
|
|
3519
|
+
setHighlightedIndex(idx);
|
|
3520
|
+
},
|
|
3521
|
+
[setHighlightedIndex]
|
|
3522
|
+
);
|
|
3523
|
+
return {
|
|
3524
|
+
highlightedIndexRef,
|
|
3525
|
+
onHighlight: handleHighlight,
|
|
3526
|
+
onKeyDown: handleKeyDown,
|
|
3527
|
+
tableRef
|
|
3528
|
+
};
|
|
3529
|
+
};
|
|
2
3530
|
//# sourceMappingURL=index.js.map
|