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