@vuu-ui/vuu-table 0.6.23 → 0.6.24-debug

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -1,2 +1,2762 @@
1
- "use strict";var Wn=Object.create;var Ee=Object.defineProperty;var Gn=Object.getOwnPropertyDescriptor;var On=Object.getOwnPropertyNames;var Bn=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var _n=(e,t)=>{for(var n in t)Ee(e,n,{get:t[n],enumerable:!0})},dt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of On(t))!Un.call(e,r)&&r!==n&&Ee(e,r,{get:()=>t[r],enumerable:!(o=Gn(t,r))||o.enumerable});return e};var j=(e,t,n)=>(n=e!=null?Wn(Bn(e)):{},dt(t||!e||!e.__esModule?Ee(n,"default",{value:e,enumerable:!0}):n,e)),Jn=e=>dt(Ee({},"__esModule",{value:!0}),e);var jo={};_n(jo,{Table:()=>_o,useMeasuredContainer:()=>st});module.exports=Jn(jo);var Mn=require("@vuu-ui/vuu-popups"),Ve=require("@salt-ds/core");var Kt=require("@vuu-ui/vuu-utils"),kt=require("react"),zt=j(require("classnames"));var O=require("@vuu-ui/vuu-utils"),vt=j(require("classnames")),ve=require("react");var Ae=require("@vuu-ui/vuu-utils"),ft=require("@heswell/salt-lab"),gt=j(require("classnames")),Z=require("react");var ye=require("react/jsx-runtime"),{KEY:pt}=Ae.metadataKeys,Oe=(0,Z.memo)(({className:e,column:t,onClick:n,row:o})=>{let r=(0,Z.useRef)(null),{align:l,CellRenderer:s,key:i,pin:a,editable:m,resizing:c,valueFormatter:d}=t,[C,y]=(0,Z.useState)(!1),w=d(o[i]),[u,f]=(0,Z.useState)(w),g=()=>{var z;(z=r.current)==null||z.focus()},p=z=>{z.key==="Enter"&&y(!0)},v=(0,Z.useCallback)(()=>{n==null||n(t)},[t,n]),E=()=>{y(!0)},L=(z="",G="",b=!0,M=!1)=>{var x;y(!1),M?f(z):G!==z&&f(G),b===!1&&((x=r.current)==null||x.focus())},h=(0,gt.default)(e,{vuuAlignRight:l==="right",vuuPinFloating:a==="floating",vuuPinLeft:a==="left",vuuPinRight:a==="right","vuuTableCell-resizing":c})||void 0,R=(0,Ae.getColumnPinStyle)(t);return m?(0,ye.jsx)("td",{className:h,"data-editable":!0,style:R,onKeyDown:p,children:(0,ye.jsx)(ft.EditableLabel,{editing:C,value:u,onChange:f,onMouseDownCapture:g,onEnterEditMode:E,onExitEditMode:L,onKeyDown:p,ref:r,tabIndex:0},"title")}):(0,ye.jsx)("td",{className:h,style:R,onClick:v,children:s?(0,ye.jsx)(s,{column:t,row:o}):w})},Xn);Oe.displayName="TableCell";function Xn(e,t){return e.column===t.column&&e.onClick===t.onClick&&e.row[pt]===t.row[pt]&&e.row[e.column.key]===t.row[t.column.key]}var Ct=require("@vuu-ui/vuu-utils"),bt=require("react");var de=require("react/jsx-runtime"),{DEPTH:Yn,IS_LEAF:ht}=Ct.metadataKeys,Qn=(e,t)=>{let{[Yn]:n,[ht]:o}=t;if(o||n>e.length)return[null,n===null?0:n-1];if(n===0)return["$root",0];{let r=e[n-1];return[t[r.key],n-1]}},yt=({column:e,onClick:t,row:n})=>{let{columns:o}=e,[r,l]=Qn(o,n),s=(0,bt.useCallback)(()=>{t==null||t(e)},[e,t]),i={left:e.pin=="left"?e.pinnedOffset:void 0},a=n[ht],m=Array(l).fill(0).map((c,d)=>(0,de.jsx)("span",{className:"vuuTableGroupCell-spacer"},d));return(0,de.jsxs)("td",{className:"vuuTableGroupCell vuuPinLeft",onClick:a?void 0:s,style:i,children:[m,a?null:(0,de.jsx)("span",{className:"vuuTableGroupCell-toggle","data-icon":"triangle-right"}),(0,de.jsx)("span",{children:r})]})};var we=require("react/jsx-runtime"),{IDX:jn,IS_EXPANDED:Zn,SELECTED:qn}=O.metadataKeys,Le="vuuTableRow",Ke=(0,ve.memo)(function({columns:t,height:n,index:o,onClick:r,onToggleGroup:l,virtualColSpan:s=0,row:i}){let{[jn]:a,[Zn]:m,[qn]:c}=i,d=(0,vt.default)(Le,{[`${Le}-even`]:a%2===0,[`${Le}-expanded`]:m,[`${Le}-preSelected`]:c===2}),C=a-o,y=(0,ve.useCallback)(u=>{let f=u.shiftKey,g=u.ctrlKey||u.metaKey;r==null||r(i,f,g)},[r,i]),w=(0,ve.useCallback)(u=>{((0,O.isGroupColumn)(u)||(0,O.isJsonGroup)(u,i))&&(l==null||l(i,u))},[l,i]);return(0,we.jsxs)("tr",{"aria-selected":c===1?!0:void 0,"aria-rowindex":a,className:d,onClick:y,style:{transform:`translate(0px, ${C*n}px)`},children:[s>0?(0,we.jsx)("td",{colSpan:s}):null,t.filter(O.notHidden).map(u=>{let f=(0,O.isGroupColumn)(u),g=(0,O.isJsonColumn)(u);return(0,we.jsx)(f?yt:Oe,{column:u,onClick:f||g?w:void 0,row:i},u.name)})]})});var Et=j(require("classnames")),ae=require("react");var pe=require("react");var Mt=require("react/jsx-runtime"),wt=()=>{},eo="vuuColumnResizer",ke=({onDrag:e,onDragEnd:t=wt,onDragStart:n=wt})=>{let o=(0,pe.useRef)(0),r=(0,pe.useCallback)(i=>{i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault();let a=Math.round(i.clientX),m=a-o.current;o.current=a,m!==0&&e(i,m)},[e]),l=(0,pe.useCallback)(i=>{window.removeEventListener("mouseup",l),window.removeEventListener("mousemove",r),t(i)},[t,r]),s=(0,pe.useCallback)(i=>{n(i),o.current=Math.round(i.clientX),window.addEventListener("mouseup",l),window.addEventListener("mousemove",r),i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault()},[n,r,l]);return(0,Mt.jsx)("div",{className:eo,onMouseDown:s})};var Be=j(require("classnames"));var le=require("react/jsx-runtime"),Tt="vuuSortIndicator",Dt=({sorted:e})=>{if(!e)return null;let t=typeof e=="number"?e<0?"dsc":"asc":e==="A"?"asc":"dsc";return typeof e=="number"?(0,le.jsxs)("div",{className:(0,Be.default)(Tt,"multi-col",t),children:[(0,le.jsx)("span",{"data-icon":`sorted-${t}`}),(0,le.jsx)("span",{className:"vuuSortPosition",children:Math.abs(e)})]}):(0,le.jsx)("div",{className:(0,Be.default)(Tt,"single-col"),children:(0,le.jsx)("span",{"data-icon":`sorted-${t}`})})};var ie=require("react"),ze=({column:e,onResize:t,rootRef:n})=>{let o=(0,ie.useRef)(0),r=(0,ie.useRef)(!1),{name:l}=e,s=(0,ie.useCallback)(()=>{if(t&&n.current){let{width:m}=n.current.getBoundingClientRect();o.current=Math.round(m),r.current=!0,t==null||t("begin",l)}},[l,t,n]),i=(0,ie.useCallback)((m,c)=>{if(n.current&&t){let{width:d}=n.current.getBoundingClientRect(),C=Math.round(d)+c;C!==o.current&&C>0&&(t("resize",l,C),o.current=C)}},[l,t,n]),a=(0,ie.useCallback)(()=>{t&&(t("end",l,o.current),setTimeout(()=>{r.current=!1},100))},[l,t]);return{isResizing:r.current,onDrag:i,onDragStart:s,onDragEnd:a}};var At=require("@vuu-ui/vuu-popups");var xt=require("@vuu-ui/vuu-popups"),Rt=j(require("classnames")),Ht=require("react");var St=require("react/jsx-runtime");var Pt=({column:e,filter:t})=>{let n=(0,xt.useContextMenu)(),o=(0,Ht.useCallback)(r=>{r.stopPropagation(),n(r,"filter",{column:e,filter:t})},[e,t,n]);return e.filter?(0,St.jsx)("div",{className:(0,Rt.default)("vuuFilterIndicator"),"data-icon":"filter",onClick:o}):null};var ne=require("react/jsx-runtime"),Me="vuuTable-headerCell",Ne=({column:e,className:t,onClick:n,onDragStart:o,onResize:r,...l})=>{let s=(0,ae.useRef)(null),{isResizing:i,...a}=ze({column:e,onResize:r,rootRef:s}),m=(0,At.useContextMenu)(),c=(0,ae.useRef)(null),d=f=>{m(f,"header",{column:e})},C=(0,ae.useCallback)(f=>!i&&(n==null?void 0:n(f)),[i,n]),y=(0,ae.useCallback)(f=>{c.current=window.setTimeout(()=>{o==null||o(f),c.current=null},250)},[o]),w=(0,ae.useCallback)(()=>{c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[]),u=(0,Et.default)(Me,t,{vuuPinFloating:e.pin==="floating",vuuPinLeft:e.pin==="left",vuuPinRight:e.pin==="right",vuuEndPin:e.endPin,[`${Me}-resizing`]:e.resizing,[`${Me}-right`]:e.align==="right"});return(0,ne.jsx)("th",{className:u,...l,onClick:C,onContextMenu:d,onMouseDown:y,onMouseUp:w,ref:s,children:(0,ne.jsxs)("div",{className:`${Me}-inner`,children:[(0,ne.jsx)(Pt,{column:e}),(0,ne.jsx)("div",{className:`${Me}-label`,children:e.label}),(0,ne.jsx)(Dt,{sorted:e.sorted}),e.resizeable!==!1?(0,ne.jsx)(ke,{...a}):null]})})};var B=require("react/jsx-runtime"),Lt="vuuTable",{RENDER_IDX:to}=Kt.metadataKeys,Nt=({columns:e,data:t,headerHeight:n,onHeaderCellDragEnd:o,rowHeight:r})=>{let l=(0,kt.useCallback)(()=>{o==null||o()},[o]);return console.log("ColumnBasedTable render"),(0,B.jsx)(B.Fragment,{children:e.map((s,i)=>(0,B.jsx)("table",{className:(0,zt.default)(`${Lt}-table`,`${Lt}-columnBased`,{vuuPinLeft:s.pin==="left"}),"data-idx":i,id:`col-${i}`,style:{width:s.width,left:s.pinnedOffset,"--vuuTableHeaderHeight":`${n}px`,"--row-height":`${r}px`},children:(0,B.jsxs)("tbody",{children:[(0,B.jsx)("tr",{children:(0,B.jsx)(Ne,{column:s,"data-idx":i,onDragEnd:l},i)},"header"),t.map((a,m)=>(0,B.jsx)(Ke,{columns:[s],height:r,index:m,row:a},a[to])),(0,B.jsx)("tr",{className:"vuuTable-filler"})]})},s.name))})};var It=require("@vuu-ui/vuu-utils"),Vt=e=>(t,n)=>{let o=[];if(e===void 0)return o;if(t==="header")o.push(...no(n,e)),o.push(...so(n,e)),o.push(...oo(n,e)),o.push(...ro(n));else if(t==="filter"){let{column:r,filter:l}=n,s=(l==null?void 0:l.column)===(r==null?void 0:r.name);o.push({label:"Edit filter",action:"filter-edit",options:n}),o.push({label:"Remove filter",action:"filter-remove-column",options:n}),r&&!s&&o.push({label:"Remove all filters",action:"remove-filters",options:n})}return o};function no(e,{sort:{sortDefs:t}}){let{column:n}=e,o=[];if(n===void 0)return o;let r=t.length>0;return n.sorted==="A"?o.push({label:"Reverse Sort (DSC)",action:"sort-dsc",options:e}):n.sorted==="D"?o.push({label:"Reverse Sort (ASC)",action:"sort-asc",options:e}):typeof n.sorted=="number"?(n.sorted>0?o.push({label:"Reverse Sort (DSC)",action:"sort-add-dsc",options:e}):o.push({label:"Reverse Sort (ASC)",action:"sort-add-asc",options:e}),r&&Math.abs(n.sorted)<t.length&&o.push({label:"Remove from sort",action:"sort-remove",options:e}),o.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):r?(o.push({label:"Add to sort",children:[{label:"Ascending",action:"sort-add-asc",options:e},{label:"Descending",action:"sort-add-dsc",options:e}]}),o.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):o.push({label:"Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]}),o}function oo(e,t){let{column:n}=e;if(n===void 0||t.groupBy.length===0)return[];let{name:o,label:r=o}=n;return[{label:`Aggregate ${r}`,children:[{label:"Count",action:"agg-count",options:e}].concat((0,It.isNumericColumn)(n)?[{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 Xe=(e,t)=>({label:`Pin ${t}`,action:`column-pin-${t}`,options:e}),Ue=e=>Xe(e,"left"),_e=e=>Xe(e,"floating"),Je=e=>Xe(e,"right");function ro(e){let{column:t}=e;if(t===void 0)return[];let{pin:n}=t,o=[{label:"Hide column",action:"column-hide",options:e},{label:"Remove column",action:"column-remove",options:e}];return n===void 0?o.push({label:"Pin column",children:[Ue(e),_e(e),Je(e)]}):n==="left"?o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[_e(e),Je(e)]}):n==="right"?o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Ue(e),_e(e)]}):n==="floating"&&o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Ue(e),Je(e)]}),o}function so(e,{groupBy:t}){let{column:n}=e,o=[];if(n===void 0)return o;let{name:r,label:l=r}=n;return t.length===0?o.push({label:`Group by ${l}`,action:"group",options:e}):o.push({label:`Add ${l} to group by`,action:"group-add",options:e}),o}var Ft=require("@vuu-ui/vuu-filters"),I=require("@vuu-ui/vuu-utils"),lo=(e,t)=>{if(e.filterStruct&&t){let[n,o]=(0,Ft.removeColumnFromFilter)(t,e.filterStruct);return{filter:o,filterStruct:n}}else return e},{Average:io,Count:ao,High:co,Low:uo,Sum:mo}=I.AggregationType,$t=({dataSource:e,onPersistentColumnOperation:t})=>(o,r)=>{let l=r;if(l.column&&e){let{column:s}=l;switch(o){case"sort-asc":return e.sort=(0,I.setSortColumn)(e.sort,s,"A"),!0;case"sort-dsc":return e.sort=(0,I.setSortColumn)(e.sort,s,"D"),!0;case"sort-add-asc":return e.sort=(0,I.addSortColumn)(e.sort,s,"A"),!0;case"sort-add-dsc":return e.sort=(0,I.addSortColumn)(e.sort,s,"D"),!0;case"group":return e.groupBy=(0,I.addGroupColumn)(e.groupBy,s),!0;case"group-add":return e.groupBy=(0,I.addGroupColumn)(e.groupBy,s),!0;case"column-hide":return t({type:"hideColumns",columns:[s]}),!0;case"column-remove":return e.columns=e.columns.filter(i=>i!==s.name),!0;case"filter-remove-column":return e.filter=lo(e.filter,s),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=(0,I.setAggregations)(e.aggregations,s,io),!0;case"agg-high":return e.aggregations=(0,I.setAggregations)(e.aggregations,s,co),!0;case"agg-low":return e.aggregations=(0,I.setAggregations)(e.aggregations,s,uo),!0;case"agg-count":return e.aggregations=(0,I.setAggregations)(e.aggregations,s,ao),!0;case"agg-sum":return e.aggregations=(0,I.setAggregations)(e.aggregations,s,mo),!0;case"column-pin-floating":return t({type:"pinColumn",column:s,pin:"floating"}),!0;case"column-pin-left":return t({type:"pinColumn",column:s,pin:"left"}),!0;case"column-pin-right":return t({type:"pinColumn",column:s,pin:"right"}),!0;case"column-unpin":return t({type:"pinColumn",column:s,pin:void 0}),!0;default:}}return!1};var _=require("@vuu-ui/vuu-utils"),Te=require("react");var Ye=j(require("classnames")),Wt=require("react");var q=require("react/jsx-runtime"),oe="vuuTable-groupHeaderCell",po=e=>{let{column:t,className:n,onRemoveColumn:o}=e;return(0,q.jsxs)("div",{className:(0,Ye.default)(`${oe}-col`,n),role:"columnheader",children:[(0,q.jsx)("span",{className:`${oe}-label`,children:t.name}),(0,q.jsx)("span",{className:`${oe}-close`,"data-icon":"close-circle",onClick:()=>o==null?void 0:o(t)})]})},Gt=({column:e,className:t,onRemoveColumn:n,onResize:o,...r})=>{let l=(0,Wt.useRef)(null),{isResizing:s,...i}=ze({column:e,onResize:o,rootRef:l}),a=(0,Ye.default)(oe,t,{vuuPinLeft:e.pin==="left",[`${oe}-right`]:e.align==="right",[`${oe}-resizing`]:e.resizing,[`${oe}-pending`]:e.groupConfirmed===!1}),{columns:m}=e;return(0,q.jsx)("th",{className:a,ref:l,...r,children:(0,q.jsxs)("div",{className:`${oe}-inner`,children:[m.map(c=>(0,q.jsx)(po,{column:c,onRemoveColumn:n},c.key)),e.resizeable!==!1?(0,q.jsx)(ke,{...i}):null]})})};var V=require("react/jsx-runtime"),Ot="vuuTable",{RENDER_IDX:fo}=_.metadataKeys,Bt=({columns:e,columnsWithinViewport:t,data:n,headings:o,onColumnResize:r,onHeaderCellDragStart:l,onContextMenu:s,onRemoveColumnFromGroupBy:i,onRowClick:a,onSort:m,onToggleGroup:c,virtualColSpan:d=0,rowCount:C,rowHeight:y})=>{let w=(0,Te.useCallback)(g=>{l==null||l(g)},[l]),u=(0,Te.useMemo)(()=>e.filter(_.notHidden),[e]),f=(0,Te.useCallback)(g=>{var R;let v=g.target.closest(".vuuTable-headerCell"),E=parseInt((R=v==null?void 0:v.dataset.idx)!=null?R:"-1"),L=(0,_.visibleColumnAtIndex)(e,E),h=g.shiftKey;L&&m(L,h)},[e,m]);return(0,V.jsxs)("table",{"aria-rowcount":C,className:`${Ot}-table`,children:[(0,V.jsx)("colgroup",{children:u.map((g,p)=>(0,V.jsx)("col",{width:`${g.width}px`},p))}),(0,V.jsxs)("thead",{children:[o.map((g,p)=>(0,V.jsx)("tr",{className:"vuuTable-heading",children:g.map(({label:v,span:E},L)=>(0,V.jsx)("th",{colSpan:E,className:"vuuTable-headingCell",children:v},L))},p)),(0,V.jsx)("tr",{children:u.map((g,p)=>{let v=(0,_.getColumnPinStyle)(g);return(0,_.isGroupColumn)(g)?(0,V.jsx)(Gt,{column:g,"data-idx":p,onRemoveColumn:i,onResize:r,style:v},p):(0,V.jsx)(Ne,{column:g,"data-idx":p,onClick:f,onDragStart:w,onResize:r,style:v},p)})})]}),(0,V.jsxs)("tbody",{onContextMenu:s,children:[n==null?void 0:n.map((g,p)=>(0,V.jsx)(Ke,{columns:t,height:y,index:p,onClick:a,virtualColSpan:d,onToggleGroup:c,row:g},g[fo])),(0,V.jsx)("tr",{className:`${Ot}-filler`})]})]})};var vn=require("@vuu-ui/vuu-popups"),J=require("@vuu-ui/vuu-utils"),S=require("react");var Ie=require("@vuu-ui/vuu-data"),re=require("@vuu-ui/vuu-utils"),P=require("react"),{SELECTED:De}=re.metadataKeys;function Ut({dataSource:e,onConfigChange:t,onFeatureEnabled:n,onFeatureInvocation:o,onSizeChange:r,onSubscribed:l,range:s={from:0,to:0},renderBufferSize:i=0,viewportRowCount:a}){let[,m]=(0,P.useState)(null),c=(0,P.useRef)(!0),d=(0,P.useRef)(!1),C=(0,P.useRef)({from:0,to:0}),y=(0,P.useRef)(null),w=(0,P.useRef)([]),u=(0,P.useMemo)(()=>new Qe((0,re.getFullRange)(s)),[]),f=(0,P.useCallback)(h=>{for(let R of h)u.add(R);w.current=u.data,d.current=!0},[u]),g=(0,P.useCallback)(h=>{h.type==="subscribed"?l==null||l(h):h.type==="viewport-update"?(typeof h.size=="number"&&(r==null||r(h.size),u.setRowCount(h.size)),h.rows?f(h.rows):typeof h.size=="number"&&(w.current=u.data,d.current=!0)):(0,Ie.isVuuFeatureAction)(h)?n==null||n(h):(0,Ie.isVuuFeatureInvocation)(h)?o==null||o(h):console.log(`useDataSource unexpected message ${h.type}`)},[u,n,o,r,l,f]);(0,P.useEffect)(()=>()=>{y.current&&(cancelAnimationFrame(y.current),y.current=null),c.current=!1},[]);let p=(0,P.useCallback)(()=>{c.current&&(d.current&&(m({}),d.current=!1),y.current=requestAnimationFrame(p))},[m]);(0,P.useEffect)(()=>{y.current=requestAnimationFrame(p)},[p]);let v=(0,P.useCallback)(h=>{let{from:R}=e.range,z={from:R,to:R+h},G=(0,re.getFullRange)(z,i);e.range=C.current=G,e.emit("range",z),u.setRange(G)},[e,u,i]),E=(0,P.useCallback)(h=>{let R=(0,re.getFullRange)(h,i);e.range=C.current=R,u.setRange(R),e.emit("range",h)},[e,u,i]),L=(0,P.useCallback)(()=>u.getSelectedRows(),[u]);return(0,P.useEffect)(()=>{e==null||e.subscribe({range:C.current},g)},[e,g,t]),(0,P.useEffect)(()=>{v(a)},[v,a]),{data:w.current,getSelectedRows:L,range:C.current,setRange:E,dataSource:e}}var Qe=class{constructor({from:t,to:n}){this.rowCount=0;this.setRowCount=t=>{t<this.data.length&&(this.data.length=t),this.rowCount=t};this.range=new re.WindowRange(t,n),this.data=new Array(n-t),this.rowCount=0}add(t){var o;let[n]=t;if(this.isWithinRange(n)){let r=n-this.range.from;this.data[r]=t;let l=t[De],s=(o=this.data[r-1])==null?void 0:o[De];s===0&&l?this.data[r-1][De]=2:s===2&&!l&&(this.data[r-1][De]=0)}}getAtIndex(t){return this.range.isWithin(t)&&this.data[t-this.range.from]!=null?this.data[t-this.range.from]:void 0}isWithinRange(t){return this.range.isWithin(t)}setRange({from:t,to:n}){if(t!==this.range.from||n!==this.range.to){let[o,r]=this.range.overlap(t,n),l=new Array(n-t);for(let s=o;s<r;s++){let i=this.getAtIndex(s);if(i){let a=s-t;l[a]=i}}this.data=l,this.range.from=t,this.range.to=n}}getSelectedRows(){return this.data.filter(t=>t[De]===1)}};var _t=require("@heswell/salt-lab"),ee=require("react"),Jt=({onDrop:e,tableContainerRef:t,tableLayout:n})=>{let[o,r]=(0,ee.useState)(n),l=(0,ee.useRef)(),s=(0,ee.useCallback)(()=>{console.log("handleDropSettle"),l.current=void 0,r("row")},[]),{draggable:i,draggedItemIndex:a,onMouseDown:m}=(0,_t.useDragDrop)({allowDragDrop:!0,draggableClassName:"table-column",orientation:"horizontal",containerRef:t,itemQuery:".vuuTable-table",onDrop:e,onDropSettle:s}),c=(0,ee.useCallback)(d=>{let{clientX:C,clientY:y}=d;console.log("useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable");let u=d.target.closest(".vuuTable-headerCell"),{dataset:{idx:f="-1"}}=u;l.current={clientX:C,clientY:y,idx:f},r("column")},[]);return(0,ee.useLayoutEffect)(()=>{var d;if(o==="column"&&l.current&&!i){let{clientX:C,clientY:y,idx:w}=l.current,u=(d=t.current)==null?void 0:d.querySelector(`.vuuTable-table[data-idx="${w}"]`);if(u){let f={persist:()=>{},nativeEvent:{clientX:C,clientY:y,target:u}};m==null||m(f)}}},[i,m,t,o]),{draggable:i,draggedItemIndex:a,tableLayout:o,onHeaderCellDragStart:o==="row"?c:void 0}};var Zt=require("@vuu-ui/vuu-utils"),A=require("react");function go(e,...t){let n=new Set(e);for(let o of t)for(let r of o)n.add(r);return n}var je="ArrowUp",Ze="ArrowDown",qe="ArrowLeft",et="ArrowRight";var tt="Home",nt="End",ot="PageUp",rt="PageDown";var Co=new Set(["Enter","Delete"," "]),bo=new Set(["Tab"]),ho=new Set(["ArrowRight","ArrowLeft"]),Xt=new Set([tt,nt,ot,rt,Ze,qe,et,je]),yo=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),ys=go(Co,Xt,ho,yo,bo);var vo=["Home","End","PageUp","PageDown"],Yt=e=>vo.includes(e),Qt=e=>Xt.has(e);var jt=e=>`thead th:nth-child(${e+1})`,wo=(e,t)=>`tbody > tr[aria-rowindex='${e}'] > td:nth-child(${t+1})`,Mo=[-1,-1];function To(e,[t,n],o,r){return e===je?t>-1?[t-1,n]:[t,n]:e===Ze?t===-1?[0,n]:t===r-1?[t,n]:[t+1,n]:e===et?n<o-1?[t,n+1]:[t,n]:e===qe?n>0?[t,n-1]:[t,n]:[t,n]}var qt=({columnCount:e=0,containerRef:t,disableHighlightOnFocus:n,data:o,requestScroll:r,rowCount:l=0,viewportRange:s})=>{var G;let{from:i,to:a}=s,m=(0,A.useRef)([-1,-1]),c=(0,A.useRef)(),d=(0,A.useRef)([-1,0]),C=(0,A.useCallback)(([b,M])=>{var H;let x=b===-1?jt(M):wo(b,M);return(H=t.current)==null?void 0:H.querySelector(x)},[t]),y=b=>b==null?void 0:b.closest("th,td"),w=b=>{var M,x;if(b.tagName==="TH")return[-1,parseInt((M=b.dataset.idx)!=null?M:"-1",10)];{let H=b.closest("tr");if(H){let X=parseInt((x=H.ariaRowIndex)!=null?x:"-1",10),k=Array.from(H.childNodes).indexOf(b);return[X,k]}}return Mo},u=(0,A.useCallback)(b=>{var M;if(t.current){let x=C(b);x?(x!==c.current&&((M=c.current)==null||M.setAttribute("tabindex",""),c.current=x,x.setAttribute("tabindex","0")),x.focus()):(0,Zt.withinRange)(b[0],s)||(c.current=void 0,r==null||r({type:"scroll-page",direction:"up"}))}},[t,C,r,s]),f=(0,A.useCallback)((b,M,x=!1)=>{let H=[b,M];d.current=H,u(H),x&&(m.current=H)},[u]),g=(0,A.useCallback)(()=>{var b;(b=c.current)==null||b.setAttribute("tabindex",""),c.current=void 0},[]),p=(0,A.useCallback)(async(b,M)=>{switch(b){case rt:r==null||r({type:"scroll-page",direction:"down"});break;case ot:r==null||r({type:"scroll-page",direction:"up"});break;case tt:r==null||r({type:"scroll-end",direction:"home"});break;case nt:r==null||r({type:"scroll-end",direction:"end"});break}return M},[r]),v=(0,A.useCallback)(()=>{var b;if(n!==!0&&(b=t.current)!=null&&b.contains(document.activeElement)){let M=y(document.activeElement);M&&(m.current=w(M))}},[n,t]),E=(0,A.useCallback)(async b=>{let[M,x]=Yt(b)?await p(b,d.current):To(b,d.current,e,l),[H,X]=d.current;(M!==H||x!==X)&&f(M,x,!0)},[e,p,l,f]),L=(0,A.useCallback)(b=>{o.length>0&&Qt(b.key)&&(b.preventDefault(),b.stopPropagation(),E(b.key))},[o,E]),h=(0,A.useCallback)(b=>{let M=b.target,x=y(M);if(x){let[H,X]=w(x);f(H,X)}},[f]),R=(0,A.useMemo)(()=>({onClick:h,onFocus:v,onKeyDown:L}),[h,v,L]);(0,A.useLayoutEffect)(()=>{let{current:b}=d,M=b[0]>=i&&b[0]<=a;c.current&&!M?g():!c.current&&M&&u(b)},[u,i,a,g]);let z=((G=t.current)==null?void 0:G.firstChild)!=null;return(0,A.useEffect)(()=>{var b;if(z&&c.current===void 0){let M=(b=t.current)==null?void 0:b.querySelector(jt(0));M&&(M.setAttribute("tabindex","0"),c.current=M)}},[t,z]),R};var fe=require("react");var ue=require("react");var ce=new Map,tn=(e,t,n)=>{switch(n){case"height":return t.height;case"clientHeight":return e.clientHeight;case"clientWidth":return e.clientWidth;case"contentHeight":return t.contentHeight;case"contentWidth":return t.contentWidth;case"scrollHeight":return Math.ceil(e.scrollHeight);case"scrollWidth":return Math.ceil(e.scrollWidth);case"width":return t.width;default:return 0}},en=new ResizeObserver(e=>{for(let t of e){let{target:n,borderBoxSize:o,contentBoxSize:r}=t,l=ce.get(n);if(l){let[{blockSize:s,inlineSize:i}]=o,[{blockSize:a,inlineSize:m}]=r,{onResize:c,measurements:d}=l,C=!1;for(let[y,w]of Object.entries(d)){let u=tn(n,{height:s,width:i,contentHeight:a,contentWidth:m},y);u!==w&&(C=!0,d[y]=u)}C&&c&&c(d)}}});function nn(e,t,n,o=!1){let r=(0,ue.useRef)(t),l=(0,ue.useCallback)(s=>{let{width:i,height:a}=s.getBoundingClientRect(),{clientWidth:m,clientHeight:c}=s;return r.current.reduce((d,C)=>(d[C]=tn(s,{width:i,height:a,contentHeight:c,contentWidth:m},C),d),{})},[]);(0,ue.useEffect)(()=>{let s=e.current;async function i(){ce.set(s,{measurements:{}}),await document.fonts.ready;let a=ce.get(s);if(a){let m=l(s);a.measurements=m,en.observe(s),o&&n(m)}else console.log("%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation","font-weight:bold; color:red;")}if(s){if(ce.has(s))throw Error("useResizeObserver attemping to observe same element twice");i()}return()=>{s&&ce.has(s)&&(en.unobserve(s),ce.delete(s))}},[l,e]),(0,ue.useEffect)(()=>{let s=e.current,i=ce.get(s);if(i){if(r.current!==t){r.current=t;let a=l(s);i.measurements=a}i.onResize=n}},[t,l,e,n])}var Do=["clientHeight","clientWidth"],on=e=>Number.isFinite(e),st=({defaultHeight:e=0,defaultWidth:t=0,height:n,width:o})=>{let r=(0,fe.useRef)(null),[l,s]=(0,fe.useState)({outer:{height:n!=null?n:"100%",width:o!=null?o:"100%"}}),i=(0,fe.useCallback)(({clientWidth:a,clientHeight:m})=>{s(c=>{let{inner:d,outer:C}=c;return on(m)&&on(a)&&(a!==(d==null?void 0:d.width)||m!==(d==null?void 0:d.height))?{outer:C,inner:{width:Math.floor(a)||t,height:Math.floor(m)||e}}:c})},[e,t]);return nn(r,Do,i,!0),{containerRef:r,outerSize:l.outer,innerSize:l.inner}};var ge=require("@vuu-ui/vuu-utils"),xe=require("react"),{IDX:xo,SELECTED:Ro}=ge.metadataKeys,Ho=[],rn=({selectionModel:e,onSelectionChange:t})=>{let n=(0,xe.useRef)(-1),o=(0,xe.useRef)(Ho);return(0,xe.useCallback)((l,s,i)=>{let{[xo]:a,[Ro]:m}=l,{current:c}=n,{current:d}=o,y=(m?ge.deselectItem:ge.selectItem)(e,d,a,s,i,c);o.current=y,n.current=a,t&&t(y)},[t,e])};var sn=require("@heswell/salt-lab"),T=require("@vuu-ui/vuu-utils"),ln=require("react"),{info:lt}=(0,T.logger)("useTableModel"),Po=100,an=T.metadataKeys.count,So=({serverDataType:e})=>e===void 0,Eo=e=>{var t,n;if((0,T.isTypeDescriptor)(e.type))return(0,T.getCellRenderer)((n=(t=e.type)==null?void 0:t.renderer)==null?void 0:n.name)},Ao=(e,t,n)=>{var r;let o=t.indexOf(e.name);return o!==-1&&n[o]?n[o]:(r=e.serverDataType)!=null?r:"string"},Lo=["int","long","double"],cn=e=>e===void 0?void 0:Lo.includes(e)?"right":"left",Ko=(e,t)=>{switch(lt==null||lt(`GridModelReducer ${t.type}`),t.type){case"init":return mn(t);case"moveColumn":return zo(e,t);case"resizeColumn":return Vo(e,t);case"setTypes":return Fo(e,t);case"hideColumns":return No(e,t);case"showColumns":return Io(e,t);case"pinColumn":return $o(e,t);case"updateColumnProp":return Re(e,t);case"tableConfig":return pn(e,t);default:return console.log(`unhandled action ${t.type}`),e}},un=(e,t)=>{let[n,o]=(0,ln.useReducer)(Ko,{tableConfig:e,dataSourceConfig:t},mn);return{columns:n.columns,dispatchColumnAction:o,headings:n.headings}};function mn({dataSourceConfig:e,tableConfig:t}){let n=t.columns.map(dn(t)),o=n.some(T.isPinned)?(0,T.sortPinnedColumns)(n):n,r={columns:o,headings:(0,T.getTableHeadings)(o)};if(e){let{columns:l,...s}=e;return pn(r,{type:"tableConfig",...s})}else return r}var ko=(e,t)=>t==="uppercase"?e.toUpperCase():t==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,dn=e=>(t,n)=>{let{columnDefaultWidth:o=Po,columnFormatHeader:r}=e,{align:l=cn(t.serverDataType),key:s,name:i,label:a=i,width:m=o,...c}=t,d={...c,align:l,CellRenderer:Eo(t),label:ko(a,r),key:s!=null?s:n+an,name:i,originalIdx:n,valueFormatter:(0,T.getValueFormatter)(t),width:m};return(0,T.isGroupColumn)(d)&&(d.columns=d.columns.map(C=>dn(e)(C,C.key))),d};function zo(e,{column:t,moveBy:n,moveTo:o}){let{columns:r}=e;if(typeof n=="number"){let l=r.indexOf(t),s=r.slice(),[i]=s.splice(l,1);return s.splice(l+n,0,i),{...e,columns:s}}else if(typeof o=="number"){let l=r.indexOf(t);return{...e,columns:(0,sn.moveItem)(r,l,o)}}return e}function No(e,{columns:t}){return t.some(n=>n.hidden!==!0)?t.reduce((n,o)=>o.hidden!==!0?Re(n,{type:"updateColumnProp",column:o,hidden:!0}):n,e):e}function Io(e,{columns:t}){return t.some(n=>n.hidden)?t.reduce((n,o)=>o.hidden?Re(n,{type:"updateColumnProp",column:o,hidden:!1}):n,e):e}function Vo(e,{column:t,phase:n,width:o}){let r="updateColumnProp",l=n!=="end";switch(n){case"begin":case"end":return Re(e,{type:r,column:t,resizing:l});case"resize":return Re(e,{type:r,column:t,width:o});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${n}`)}}function Fo(e,{columnNames:t,serverDataTypes:n}){let{columns:o}=e;if(o.some(So)){let r=o.map(l=>{var i;let s=Ao(l,t,n);return{...l,align:(i=l.align)!=null?i:cn(s),serverDataType:s}});return{...e,columns:r}}else return e}function $o(e,t){let{columns:n}=e,{column:o,pin:r}=t,l=n.find(s=>s.name===o.name);return l?(n=Ce(n,{...l,pin:r}),n=(0,T.sortPinnedColumns)(n),{...e,columns:n}):e}function Re(e,t){let{columns:n}=e,{align:o,column:r,hidden:l,label:s,resizing:i,width:a}=t,m=n.find(c=>c.name===r.name);return m&&((o==="left"||o==="right")&&(n=Ce(n,{...m,align:o})),typeof s=="string"&&(n=Ce(n,{...m,label:s})),typeof i=="boolean"&&(n=Ce(n,{...m,resizing:i})),typeof l=="boolean"&&(n=Ce(n,{...m,hidden:l})),typeof a=="number"&&(n=Ce(n,{...m,width:a}))),{...e,columns:n}}function pn(e,{columns:t,confirmed:n,filter:o,groupBy:r,sort:l}){let s=t&&t.length>0,i=r!==void 0,a=typeof(o==null?void 0:o.filter)=="string",m=l&&l.sortDefs.length>0,c=e;return s&&(c={...e,columns:t.map((d,C)=>{let y=(0,T.getColumnName)(d),w=C+an,u=(0,T.findColumn)(c.columns,y);if(u)return u.key===w?u:{...u,key:w};throw Error(`useTableModel column ${d} not found`)})}),i&&(c={...e,columns:(0,T.applyGroupByToColumns)(c.columns,r,n)}),m&&(c={...e,columns:(0,T.applySortToColumns)(c.columns,l)}),a?c={...e,columns:(0,T.applyFilterToColumns)(c.columns,o)}:c.columns.some(T.isFilteredColumn)&&(c={...e,columns:(0,T.stripFilterFromColumns)(c.columns)}),c}function Ce(e,t){return e.map(n=>n.name===t.name?t:n)}var W=require("react"),fn=e=>{let{scrollLeft:t,scrollTop:n}=e,{clientHeight:o,clientWidth:r,scrollHeight:l,scrollWidth:s}=e,i=t/(s-r),a=n/(l-o);return[i,a,t,n]},Wo=e=>{let{clientHeight:t,clientWidth:n,scrollHeight:o,scrollWidth:r}=e;return[r-n,o-t]},gn=({onHorizontalScroll:e,onVerticalScroll:t,viewport:n})=>{let o=(0,W.useRef)({scrollTop:0,scrollLeft:0}),r=(0,W.useRef)(null),l=(0,W.useRef)(null),s=(0,W.useRef)(null),i=(0,W.useRef)(!1),{maxScrollContainerScrollHorizontal:a,maxScrollContainerScrollVertical:m}=n,c=(0,W.useCallback)((u,f)=>{let{current:g}=s;g&&g.scrollTo({top:f,left:u,behavior:"auto"})},[s]),d=(0,W.useCallback)(()=>{let{current:u}=s;if(u){let{current:f}=o,{scrollLeft:g,scrollTop:p}=u;f.scrollTop!==p&&(f.scrollTop=p,t==null||t(p)),f.scrollLeft!==g&&(f.scrollLeft=g,e==null||e(g))}},[e,t]),C=(0,W.useCallback)(()=>{let{current:u}=l,{current:f}=r;if(u&&f){let[g,p,v,E]=fn(u);i.current=!0,f.scrollLeft=Math.round(g*a),f.scrollTop=Math.round(p*m),c(v,E)}},[a,m,l,r,c]),y=(0,W.useCallback)(()=>{let{current:u}=l,{current:f}=r,{current:g}=i;if(g)i.current=!1;else if(u&&f){let[p,v]=fn(f),[E,L]=Wo(u),h=Math.round(p*E),R=Math.round(v*L);u.scrollTo({left:h,top:R,behavior:"auto"}),c(h,R)}},[l,r,c]),w=(0,W.useCallback)(u=>{let{current:f}=r;if(f){if(i.current=!1,u.type==="scroll-page"){let{clientHeight:g,scrollLeft:p,scrollTop:v}=f,{direction:E}=u,L=E==="down"?g:-g,h=Math.min(Math.max(0,v+L),n.maxScrollContainerScrollVertical);f.scrollTo({top:h,left:p,behavior:"auto"})}else if(u.type==="scroll-end"){let{direction:g}=u,p=g==="end"?n.maxScrollContainerScrollVertical:0;f.scrollTo({top:p,left:f.scrollLeft,behavior:"auto"})}}},[n.maxScrollContainerScrollVertical]);return{scrollbarContainerRef:r,onScrollbarContainerScroll:y,contentContainerRef:l,onContentContainerScroll:C,tableContainerRef:s,onTableContainerScroll:d,requestScroll:w}};var it=require("react"),Go={fillerHeight:0,maxScrollContainerScrollHorizontal:0,maxScrollContainerScrollVertical:0,pinnedWidthLeft:0,pinnedWidthRight:0,rowCount:0,scrollContentHeight:0,scrollbarSize:0,scrollContentWidth:0,totalHeaderHeight:0},Oo=e=>{let t=0,n=0,o=0;for(let r of e){let{hidden:l,pin:s,width:i}=r,a=l?0:i;s==="left"?t+=a:s==="right"?n+=a:o+=a}return{pinnedWidthLeft:t,pinnedWidthRight:n,unpinnedWidth:o}},Cn=({columns:e,headerHeight:t,headings:n,rowCount:o,rowHeight:r,size:l})=>{let{pinnedWidthLeft:s,pinnedWidthRight:i,unpinnedWidth:a}=(0,it.useMemo)(()=>Oo(e),[e]);return(0,it.useMemo)(()=>{var c;if(l){let d=n.length,C=15,y=o*r,w=s+a+i,u=y+t-(((c=l==null?void 0:l.height)!=null?c:0)-t-C),f=w-l.width+s,g=(l.height-t)/r,p=Number.isInteger(g)?g+1:Math.ceil(g);return{fillerHeight:(o-p)*r,maxScrollContainerScrollHorizontal:f,maxScrollContainerScrollVertical:u,pinnedWidthLeft:s,pinnedWidthRight:i,rowCount:p,scrollContentHeight:t+y+C,scrollbarSize:C,scrollContentWidth:w,totalHeaderHeight:t*(1+d)}}else return Go},[t,n.length,s,i,o,r,l,a])};var He=require("@vuu-ui/vuu-utils"),$=require("react"),bn=({columns:e,rowHeight:t,setRange:n,viewportMeasurements:o})=>{let r=(0,$.useRef)(-1),{rowCount:l,scrollContentWidth:s,maxScrollContainerScrollHorizontal:i}=o,a=s-i,m=(0,$.useRef)(0),[c,d]=(0,$.useMemo)(()=>(0,He.getColumnsInViewport)(e,m.current,m.current+a),[a,e]),C=(0,$.useRef)(d);(0,$.useEffect)(()=>{w(c)},[c]);let[y,w]=(0,$.useState)(c),u=(0,$.useCallback)(g=>{m.current=g;let[p,v]=(0,He.getColumnsInViewport)(e,g,g+a);(0,He.itemsChanged)(y,p)&&(C.current=v,w(p))},[a,e,y]),f=(0,$.useCallback)(g=>{let p=Math.floor(g/t);p!==r.current&&(r.current=p,n({from:p,to:p+l}))},[t,n,l]);return{columnsWithinViewport:y,onHorizontalScroll:u,onVerticalScroll:f,virtualColSpan:C.current}};var Bo=[],{KEY:Uo,IS_EXPANDED:hn,IS_LEAF:yn}=J.metadataKeys,wn=({config:e,dataSource:t,headerHeight:n,onConfigChange:o,onFeatureEnabled:r,onFeatureInvocation:l,onSelectionChange:s,renderBufferSize:i=0,rowHeight:a,selectionModel:m,tableLayout:c,...d})=>{var ut,mt;let[C,y]=(0,S.useState)(0),w=(0,S.useRef)(!1),u=(0,S.useRef)();if(u.current=t,t===void 0)throw Error("no data source provided to DataTable");let f=st(d),g=(0,S.useCallback)(D=>{y(D)},[]),{columns:p,dispatchColumnAction:v,headings:E}=un(e,t.config),L=(0,S.useCallback)(D=>{w.current=!0,v(D)},[v]),h=$t({dataSource:t,onPersistentColumnOperation:L}),R=Cn({columns:p,headerHeight:n,headings:E,rowCount:C,rowHeight:a,size:f.innerSize}),z=(0,S.useCallback)(D=>{if(D.tableMeta){let{columns:K,dataTypes:F}=D.tableMeta;w.current=!0,v({type:"setTypes",columnNames:K,serverDataTypes:F})}},[v]),G=(0,S.useCallback)(D=>{t.select(D),s==null||s(D)},[t,s]),b=rn({onSelectionChange:G,selectionModel:m}),{data:M,getSelectedRows:x,range:H,setRange:X}=Ut({dataSource:t,onFeatureEnabled:r,onFeatureInvocation:l,onSubscribed:z,onSizeChange:g,renderBufferSize:i,viewportRowCount:R.rowCount}),k=(0,S.useRef)();k.current=M;let Se=(0,S.useCallback)((D,K=!1,F)=>{t&&(t.sort=(0,J.applySort)(t.sort,D,K,F))},[t]),Fe=(0,S.useCallback)((D,K,F)=>{let N=p.find(Y=>Y.name===K);if(N)D==="end"&&(w.current=!0),v({type:"resizeColumn",phase:D,column:N,width:F});else throw Error(`useDataTable.handleColumnResize, column ${K} not found`)},[p,v]),$e=(0,S.useCallback)((D,K)=>{let F=(0,J.isJsonGroup)(K,D),N=D[Uo];if(D[hn]){if(t.closeTreeNode(N,!0),F){let Y=p.indexOf(K);t.getRowsAtDepth(Y+1).some(Q=>Q[hn]||Q[yn])||v({type:"hideColumns",columns:p.slice(Y+2)})}}else if(t.openTreeNode(N),F){let Y=t.getChildRows(N),se=p.indexOf(K)+1,Q=[p[se]];Y.some(me=>me[yn])&&Q.push(p[se+1]),Q.some(me=>me.hidden)&&v({type:"showColumns",columns:Q})}},[p,t,v]),{onVerticalScroll:We,onHorizontalScroll:Ge,columnsWithinViewport:Rn,virtualColSpan:Hn}=bn({columns:p,rowHeight:a,setRange:X,viewportMeasurements:R}),{requestScroll:Pn,...at}=gn({onHorizontalScroll:Ge,onVerticalScroll:We,viewport:R,viewportHeight:((mt=(ut=f.innerSize)==null?void 0:ut.height)!=null?mt:0)-n}),Sn=qt({columnCount:p.length,containerRef:f.containerRef,data:M,requestScroll:Pn,rowCount:t==null?void 0:t.size,viewportRange:H}),En=(0,S.useCallback)(D=>{t&&t.groupBy.includes(D.name)&&(t.groupBy=t.groupBy.filter(K=>K!==D.name))},[t]),An=(0,S.useCallback)((D,K)=>{let F=t.columns[D],N=(0,J.moveItem)(t.columns,F,K);N!==t.columns&&(t.columns=N,v({type:"tableConfig",columns:N}))},[t,v]),Ln=Jt({onDrop:An,tableContainerRef:at.tableContainerRef,tableLayout:c});(0,S.useEffect)(()=>{u.current&&(w.current=!0,v({type:"init",tableConfig:e,dataSourceConfig:u.current.config}))},[e,v]),(0,S.useEffect)(()=>{t.on("config",(D,K)=>{w.current=!0,v({type:"tableConfig",...D,confirmed:K})})},[t,v]),(0,S.useMemo)(()=>{w.current&&(o==null||o({...e,columns:p}),w.current=!1)},[p,e,o]);let ct=(0,vn.useContextMenu)(),Kn=(0,S.useCallback)(D=>{var Q;let{current:K}=k,{current:F}=u,N=D.target,Y=N==null?void 0:N.closest("td"),se=N==null?void 0:N.closest("tr");if(Y&&se&&K&&F){let{columns:me,selectedRowsCount:kn}=F,zn=(0,J.buildColumnMap)(me),Nn=parseInt((Q=se.ariaRowIndex)!=null?Q:"-1"),In=Array.from(se.childNodes).indexOf(Y),Vn=K.find(([$n])=>$n===Nn),Fn=me[In];ct(D,"grid",{columnMap:zn,columnName:Fn,row:Vn,selectedRows:kn===0?Bo:x(),viewport:t==null?void 0:t.viewport})}},[t==null?void 0:t.viewport,x,ct]);return{containerMeasurements:f,containerProps:Sn,columns:p,columnsWithinViewport:Rn,data:M,dispatchColumnAction:v,handleContextMenuAction:h,headings:E,onColumnResize:Fe,onContextMenu:Kn,onRemoveColumnFromGroupBy:En,onRowClick:b,onSort:Se,onToggleGroup:$e,virtualColSpan:Hn,scrollProps:at,rowCount:C,viewportMeasurements:R,...Ln}};var Tn=j(require("classnames"));var Dn=require("@vuu-ui/vuu-utils"),U=require("react/jsx-runtime"),te="vuuTable",_o=({allowConfigEditing:e=!1,className:t,config:n,dataSource:o,headerHeight:r=25,height:l,id:s,onConfigChange:i,onFeatureEnabled:a,onFeatureInvocation:m,onSelectionChange:c,onShowConfigEditor:d,renderBufferSize:C=0,rowHeight:y=20,selectionModel:w="extended",style:u,tableLayout:f="row",width:g,zebraStripes:p=!1,...v})=>{let E=(0,Ve.useIdMemo)(s),{containerMeasurements:{containerRef:L,innerSize:h,outerSize:R},containerProps:z,dispatchColumnAction:G,draggable:b,draggedItemIndex:M,handleContextMenuAction:x,scrollProps:H,tableLayout:X,viewportMeasurements:k,...Se}=wn({config:n,dataSource:o,renderBufferSize:C,headerHeight:r,height:l,onConfigChange:i,onFeatureEnabled:a,onFeatureInvocation:m,onSelectionChange:c,rowHeight:y,selectionModel:w,tableLayout:f,width:g}),Fe={...R,"--content-height":`${k.scrollContentHeight}px`,"--content-width":`${k.scrollContentWidth}px`,"--filler-height":`${k.fillerHeight}px`,"--pinned-width-left":`${k.pinnedWidthLeft}px`,"--pinned-width-right":`${k.pinnedWidthRight}px`,"--header-height":`${r}px`,"--row-height":`${y}px`,"--scrollbar-size":`${k.scrollbarSize}px`,"--table-height":`${h==null?void 0:h.height}px`,"--table-width":`${h==null?void 0:h.width}px`,"--total-header-height":`${k==null?void 0:k.totalHeaderHeight}px`},$e={left:k.pinnedWidthLeft-1,top:(k==null?void 0:k.totalHeaderHeight)-1},We=X==="column"?Nt:Bt,Ge=(0,Tn.default)(te,t,{[`${te}-zebra`]:p,[`${te}-loading`]:(0,Dn.isDataLoading)(Se.columns)});return(0,U.jsx)(Mn.ContextMenuProvider,{menuActionHandler:x,menuBuilder:Vt(o),children:(0,U.jsxs)("div",{...z,className:Ge,id:E,ref:L,style:Fe,tabIndex:-1,children:[h?(0,U.jsx)("div",{className:`${te}-scrollbarContainer`,onScroll:H.onScrollbarContainerScroll,ref:H.scrollbarContainerRef,style:$e,children:(0,U.jsx)("div",{className:`${te}-scrollContent`})}):null,h?(0,U.jsxs)("div",{className:`${te}-contentContainer`,onScroll:H.onContentContainerScroll,ref:H.contentContainerRef,...v,children:[(0,U.jsx)("div",{className:`${te}-scrollContent`}),(0,U.jsx)("div",{className:`${te}-tableContainer`,onScroll:H.onTableContainerScroll,ref:H.tableContainerRef,children:(0,U.jsx)(We,{...Se,headerHeight:r,rowHeight:y})}),b]}):null,e&&h?(0,U.jsx)(Ve.Button,{className:`${te}-settings`,"data-icon":"settings",onClick:d,variant:"secondary"}):null]})})};var xn=j(require("classnames")),he=require("@vuu-ui/vuu-utils");var be=require("react/jsx-runtime"),Pe="vuuJsonCell",{IS_EXPANDED:Jo,KEY:Xo}=he.metadataKeys,Yo=e=>{let t=e.lastIndexOf("|");return t===-1?"":e.slice(t+1)},Qo=({column:e,row:t})=>{let{key:n}=e,o=t[n],r=!1;(0,he.isJsonAttribute)(o)&&(o=o.slice(0,-1),r=!0);let l=Yo(t[Xo]),s=(0,xn.default)({[`${Pe}-name`]:l===o,[`${Pe}-value`]:l!==o,[`${Pe}-group`]:r});if(r){let i=t[Jo]?"minus-box":"plus-box";return(0,be.jsxs)("span",{className:s,children:[(0,be.jsx)("span",{className:`${Pe}-value`,children:o}),(0,be.jsx)("span",{className:`${Pe}-toggle`,"data-icon":i})]})}else return o?(0,be.jsx)("span",{className:s,children:o}):null};(0,he.registerComponent)("json",Qo,"cell-renderer",{});
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
+ Table: () => Table,
34
+ useMeasuredContainer: () => useMeasuredContainer
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/Table.tsx
39
+ var import_vuu_popups4 = require("@vuu-ui/vuu-popups");
40
+ var import_core = require("@salt-ds/core");
41
+
42
+ // src/ColumnBasedTable.tsx
43
+ var import_vuu_utils4 = require("@vuu-ui/vuu-utils");
44
+ var import_react8 = require("react");
45
+ var import_classnames6 = __toESM(require("classnames"));
46
+
47
+ // src/TableRow.tsx
48
+ var import_vuu_utils3 = require("@vuu-ui/vuu-utils");
49
+ var import_classnames2 = __toESM(require("classnames"));
50
+ var import_react3 = require("react");
51
+
52
+ // src/TableCell.tsx
53
+ var import_vuu_utils = require("@vuu-ui/vuu-utils");
54
+ var import_salt_lab = require("@heswell/salt-lab");
55
+ var import_classnames = __toESM(require("classnames"));
56
+ var import_react = require("react");
57
+ var import_jsx_runtime = require("react/jsx-runtime");
58
+ var { KEY } = import_vuu_utils.metadataKeys;
59
+ var TableCell = (0, import_react.memo)(
60
+ ({ className: classNameProp, column, onClick, row }) => {
61
+ const labelFieldRef = (0, import_react.useRef)(null);
62
+ const {
63
+ align,
64
+ CellRenderer,
65
+ key,
66
+ pin,
67
+ editable,
68
+ resizing,
69
+ valueFormatter
70
+ } = column;
71
+ const [editing, setEditing] = (0, import_react.useState)(false);
72
+ const value = valueFormatter(row[key]);
73
+ const [editableValue, setEditableValue] = (0, import_react.useState)(value);
74
+ const handleTitleMouseDown = () => {
75
+ var _a;
76
+ (_a = labelFieldRef.current) == null ? void 0 : _a.focus();
77
+ };
78
+ const handleTitleKeyDown = (evt) => {
79
+ if (evt.key === "Enter") {
80
+ setEditing(true);
81
+ }
82
+ };
83
+ const handleClick = (0, import_react.useCallback)(() => {
84
+ onClick == null ? void 0 : onClick(column);
85
+ }, [column, onClick]);
86
+ const handleEnterEditMode = () => {
87
+ setEditing(true);
88
+ };
89
+ const handleExitEditMode = (originalValue = "", finalValue = "", allowDeactivation = true, editCancelled = false) => {
90
+ var _a;
91
+ setEditing(false);
92
+ if (editCancelled) {
93
+ setEditableValue(originalValue);
94
+ } else if (finalValue !== originalValue) {
95
+ setEditableValue(finalValue);
96
+ }
97
+ if (allowDeactivation === false) {
98
+ (_a = labelFieldRef.current) == null ? void 0 : _a.focus();
99
+ }
100
+ };
101
+ const className = (0, import_classnames.default)(classNameProp, {
102
+ vuuAlignRight: align === "right",
103
+ vuuPinFloating: pin === "floating",
104
+ vuuPinLeft: pin === "left",
105
+ vuuPinRight: pin === "right",
106
+ "vuuTableCell-resizing": resizing
107
+ }) || void 0;
108
+ const pinnedStyle = (0, import_vuu_utils.getColumnPinStyle)(column);
109
+ return editable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
110
+ "td",
111
+ {
112
+ className,
113
+ "data-editable": true,
114
+ style: pinnedStyle,
115
+ onKeyDown: handleTitleKeyDown,
116
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
117
+ import_salt_lab.EditableLabel,
118
+ {
119
+ editing,
120
+ value: editableValue,
121
+ onChange: setEditableValue,
122
+ onMouseDownCapture: handleTitleMouseDown,
123
+ onEnterEditMode: handleEnterEditMode,
124
+ onExitEditMode: handleExitEditMode,
125
+ onKeyDown: handleTitleKeyDown,
126
+ ref: labelFieldRef,
127
+ tabIndex: 0
128
+ },
129
+ "title"
130
+ )
131
+ }
132
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { className, style: pinnedStyle, onClick: handleClick, children: CellRenderer ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CellRenderer, { column, row }) : value });
133
+ },
134
+ cellValuesAreEqual
135
+ );
136
+ TableCell.displayName = "TableCell";
137
+ function cellValuesAreEqual(prev, next) {
138
+ return prev.column === next.column && prev.onClick === next.onClick && prev.row[KEY] === next.row[KEY] && prev.row[prev.column.key] === next.row[next.column.key];
139
+ }
140
+
141
+ // src/TableGroupCell.tsx
142
+ var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
143
+ var import_react2 = require("react");
144
+ var import_jsx_runtime2 = require("react/jsx-runtime");
145
+ var { DEPTH, IS_LEAF } = import_vuu_utils2.metadataKeys;
146
+ var getGroupValueAndOffset = (columns, row) => {
147
+ const { [DEPTH]: depth, [IS_LEAF]: isLeaf } = row;
148
+ if (isLeaf || depth > columns.length) {
149
+ return [null, depth === null ? 0 : depth - 1];
150
+ } else if (depth === 0) {
151
+ return ["$root", 0];
152
+ } else {
153
+ const { key, valueFormatter } = columns[depth - 1];
154
+ const value = valueFormatter(row[key]);
155
+ return [value, depth - 1];
156
+ }
157
+ };
158
+ var TableGroupCell = ({ column, onClick, row }) => {
159
+ const { columns } = column;
160
+ const [value, offset] = getGroupValueAndOffset(columns, row);
161
+ const handleClick = (0, import_react2.useCallback)(() => {
162
+ onClick == null ? void 0 : onClick(column);
163
+ }, [column, onClick]);
164
+ const style = {
165
+ left: column.pin == "left" ? column.pinnedOffset : void 0
166
+ };
167
+ const isLeaf = row[IS_LEAF];
168
+ const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "vuuTableGroupCell-spacer" }, i));
169
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
170
+ "td",
171
+ {
172
+ className: "vuuTableGroupCell vuuPinLeft",
173
+ onClick: isLeaf ? void 0 : handleClick,
174
+ style,
175
+ children: [
176
+ spacers,
177
+ isLeaf ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "vuuTableGroupCell-toggle", "data-icon": "triangle-right" }),
178
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: value })
179
+ ]
180
+ }
181
+ );
182
+ };
183
+
184
+ // src/TableRow.tsx
185
+ var import_jsx_runtime3 = require("react/jsx-runtime");
186
+ var { IDX, IS_EXPANDED, SELECTED } = import_vuu_utils3.metadataKeys;
187
+ var classBase = "vuuTableRow";
188
+ var TableRow = (0, import_react3.memo)(function Row({
189
+ columns,
190
+ height,
191
+ index,
192
+ onClick,
193
+ onToggleGroup,
194
+ virtualColSpan = 0,
195
+ row
196
+ }) {
197
+ const {
198
+ [IDX]: rowIndex,
199
+ [IS_EXPANDED]: isExpanded,
200
+ [SELECTED]: isSelected
201
+ } = row;
202
+ const className = (0, import_classnames2.default)(classBase, {
203
+ [`${classBase}-even`]: rowIndex % 2 === 0,
204
+ [`${classBase}-expanded`]: isExpanded,
205
+ [`${classBase}-preSelected`]: isSelected === 2
206
+ });
207
+ const offset = rowIndex - index;
208
+ const handleRowClick = (0, import_react3.useCallback)(
209
+ (evt) => {
210
+ const rangeSelect = evt.shiftKey;
211
+ const keepExistingSelection = evt.ctrlKey || evt.metaKey;
212
+ onClick == null ? void 0 : onClick(row, rangeSelect, keepExistingSelection);
213
+ },
214
+ [onClick, row]
215
+ );
216
+ const handleGroupCellClick = (0, import_react3.useCallback)(
217
+ (column) => {
218
+ if ((0, import_vuu_utils3.isGroupColumn)(column) || (0, import_vuu_utils3.isJsonGroup)(column, row)) {
219
+ onToggleGroup == null ? void 0 : onToggleGroup(row, column);
220
+ }
221
+ },
222
+ [onToggleGroup, row]
223
+ );
224
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
225
+ "tr",
226
+ {
227
+ "aria-selected": isSelected === 1 ? true : void 0,
228
+ "aria-rowindex": rowIndex,
229
+ className,
230
+ onClick: handleRowClick,
231
+ style: {
232
+ transform: `translate(0px, ${offset * height}px)`
233
+ },
234
+ children: [
235
+ virtualColSpan > 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { colSpan: virtualColSpan }) : null,
236
+ columns.filter(import_vuu_utils3.notHidden).map((column) => {
237
+ const isGroup = (0, import_vuu_utils3.isGroupColumn)(column);
238
+ const isJsonCell = (0, import_vuu_utils3.isJsonColumn)(column);
239
+ const Cell = isGroup ? TableGroupCell : TableCell;
240
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
241
+ Cell,
242
+ {
243
+ column,
244
+ onClick: isGroup || isJsonCell ? handleGroupCellClick : void 0,
245
+ row
246
+ },
247
+ column.name
248
+ );
249
+ })
250
+ ]
251
+ }
252
+ );
253
+ });
254
+
255
+ // src/TableHeaderCell.tsx
256
+ var import_classnames5 = __toESM(require("classnames"));
257
+ var import_react7 = require("react");
258
+
259
+ // src/ColumnResizer.tsx
260
+ var import_react4 = require("react");
261
+ var import_jsx_runtime4 = require("react/jsx-runtime");
262
+ var NOOP = () => void 0;
263
+ var baseClass = "vuuColumnResizer";
264
+ var ColumnResizer = ({
265
+ onDrag,
266
+ onDragEnd = NOOP,
267
+ onDragStart = NOOP
268
+ }) => {
269
+ const position = (0, import_react4.useRef)(0);
270
+ const onMouseMove = (0, import_react4.useCallback)(
271
+ (e) => {
272
+ if (e.stopPropagation) {
273
+ e.stopPropagation();
274
+ }
275
+ if (e.preventDefault) {
276
+ e.preventDefault();
277
+ }
278
+ const x = Math.round(e.clientX);
279
+ const moveBy = x - position.current;
280
+ position.current = x;
281
+ if (moveBy !== 0) {
282
+ onDrag(e, moveBy);
283
+ }
284
+ },
285
+ [onDrag]
286
+ );
287
+ const onMouseUp = (0, import_react4.useCallback)(
288
+ (e) => {
289
+ window.removeEventListener("mouseup", onMouseUp);
290
+ window.removeEventListener("mousemove", onMouseMove);
291
+ onDragEnd(e);
292
+ },
293
+ [onDragEnd, onMouseMove]
294
+ );
295
+ const handleMouseDown = (0, import_react4.useCallback)(
296
+ (e) => {
297
+ onDragStart(e);
298
+ position.current = Math.round(e.clientX);
299
+ window.addEventListener("mouseup", onMouseUp);
300
+ window.addEventListener("mousemove", onMouseMove);
301
+ if (e.stopPropagation) {
302
+ e.stopPropagation();
303
+ }
304
+ if (e.preventDefault) {
305
+ e.preventDefault();
306
+ }
307
+ },
308
+ [onDragStart, onMouseMove, onMouseUp]
309
+ );
310
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: baseClass, onMouseDown: handleMouseDown });
311
+ };
312
+
313
+ // src/SortIndicator.tsx
314
+ var import_classnames3 = __toESM(require("classnames"));
315
+ var import_jsx_runtime5 = require("react/jsx-runtime");
316
+ var classBase2 = "vuuSortIndicator";
317
+ var SortIndicator = ({ sorted }) => {
318
+ if (!sorted) {
319
+ return null;
320
+ }
321
+ const direction = typeof sorted === "number" ? sorted < 0 ? "dsc" : "asc" : sorted === "A" ? "asc" : "dsc";
322
+ return typeof sorted === "number" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: (0, import_classnames3.default)(classBase2, "multi-col", direction), children: [
323
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-icon": `sorted-${direction}` }),
324
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "vuuSortPosition", children: Math.abs(sorted) })
325
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: (0, import_classnames3.default)(classBase2, "single-col"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-icon": `sorted-${direction}` }) });
326
+ };
327
+
328
+ // src/useTableColumnResize.tsx
329
+ var import_react5 = require("react");
330
+ var useTableColumnResize = ({
331
+ column,
332
+ onResize,
333
+ rootRef
334
+ }) => {
335
+ const widthRef = (0, import_react5.useRef)(0);
336
+ const isResizing = (0, import_react5.useRef)(false);
337
+ const { name } = column;
338
+ const handleResizeStart = (0, import_react5.useCallback)(() => {
339
+ if (onResize && rootRef.current) {
340
+ const { width } = rootRef.current.getBoundingClientRect();
341
+ widthRef.current = Math.round(width);
342
+ isResizing.current = true;
343
+ onResize == null ? void 0 : onResize("begin", name);
344
+ }
345
+ }, [name, onResize, rootRef]);
346
+ const handleResize = (0, import_react5.useCallback)(
347
+ (_evt, moveBy) => {
348
+ if (rootRef.current) {
349
+ if (onResize) {
350
+ const { width } = rootRef.current.getBoundingClientRect();
351
+ const newWidth = Math.round(width) + moveBy;
352
+ if (newWidth !== widthRef.current && newWidth > 0) {
353
+ onResize("resize", name, newWidth);
354
+ widthRef.current = newWidth;
355
+ }
356
+ }
357
+ }
358
+ },
359
+ [name, onResize, rootRef]
360
+ );
361
+ const handleResizeEnd = (0, import_react5.useCallback)(() => {
362
+ if (onResize) {
363
+ onResize("end", name, widthRef.current);
364
+ setTimeout(() => {
365
+ isResizing.current = false;
366
+ }, 100);
367
+ }
368
+ }, [name, onResize]);
369
+ return {
370
+ isResizing: isResizing.current,
371
+ onDrag: handleResize,
372
+ onDragStart: handleResizeStart,
373
+ onDragEnd: handleResizeEnd
374
+ };
375
+ };
376
+
377
+ // src/TableHeaderCell.tsx
378
+ var import_vuu_popups2 = require("@vuu-ui/vuu-popups");
379
+
380
+ // src/filter-indicator.tsx
381
+ var import_vuu_popups = require("@vuu-ui/vuu-popups");
382
+ var import_classnames4 = __toESM(require("classnames"));
383
+ var import_react6 = require("react");
384
+ var import_jsx_runtime6 = require("react/jsx-runtime");
385
+ var FilterIndicator = ({ column, filter }) => {
386
+ const showContextMenu = (0, import_vuu_popups.useContextMenu)();
387
+ const handleClick = (0, import_react6.useCallback)(
388
+ (evt) => {
389
+ evt.stopPropagation();
390
+ showContextMenu(evt, "filter", { column, filter });
391
+ },
392
+ [column, filter, showContextMenu]
393
+ );
394
+ if (!column.filter) {
395
+ return null;
396
+ }
397
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
398
+ "div",
399
+ {
400
+ className: (0, import_classnames4.default)("vuuFilterIndicator"),
401
+ "data-icon": "filter",
402
+ onClick: handleClick
403
+ }
404
+ );
405
+ };
406
+
407
+ // src/TableHeaderCell.tsx
408
+ var import_jsx_runtime7 = require("react/jsx-runtime");
409
+ var classBase3 = "vuuTable-headerCell";
410
+ var TableHeaderCell = ({
411
+ column,
412
+ className: classNameProp,
413
+ onClick,
414
+ onDragStart,
415
+ onResize,
416
+ ...props
417
+ }) => {
418
+ const rootRef = (0, import_react7.useRef)(null);
419
+ const { isResizing, ...resizeProps } = useTableColumnResize({
420
+ column,
421
+ onResize,
422
+ rootRef
423
+ });
424
+ const showContextMenu = (0, import_vuu_popups2.useContextMenu)();
425
+ const dragTimerRef = (0, import_react7.useRef)(null);
426
+ const handleContextMenu = (e) => {
427
+ showContextMenu(e, "header", { column });
428
+ };
429
+ const handleClick = (0, import_react7.useCallback)(
430
+ (evt) => !isResizing && (onClick == null ? void 0 : onClick(evt)),
431
+ [isResizing, onClick]
432
+ );
433
+ const handleMouseDown = (0, import_react7.useCallback)(
434
+ (evt) => {
435
+ dragTimerRef.current = window.setTimeout(() => {
436
+ onDragStart == null ? void 0 : onDragStart(evt);
437
+ dragTimerRef.current = null;
438
+ }, 250);
439
+ },
440
+ [onDragStart]
441
+ );
442
+ const handleMouseUp = (0, import_react7.useCallback)(() => {
443
+ if (dragTimerRef.current !== null) {
444
+ window.clearTimeout(dragTimerRef.current);
445
+ dragTimerRef.current = null;
446
+ }
447
+ }, []);
448
+ const className = (0, import_classnames5.default)(classBase3, classNameProp, {
449
+ vuuPinFloating: column.pin === "floating",
450
+ vuuPinLeft: column.pin === "left",
451
+ vuuPinRight: column.pin === "right",
452
+ vuuEndPin: column.endPin,
453
+ [`${classBase3}-resizing`]: column.resizing,
454
+ [`${classBase3}-right`]: column.align === "right"
455
+ });
456
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
457
+ "th",
458
+ {
459
+ className,
460
+ ...props,
461
+ onClick: handleClick,
462
+ onContextMenu: handleContextMenu,
463
+ onMouseDown: handleMouseDown,
464
+ onMouseUp: handleMouseUp,
465
+ ref: rootRef,
466
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: `${classBase3}-inner`, children: [
467
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FilterIndicator, { column }),
468
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `${classBase3}-label`, children: column.label }),
469
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SortIndicator, { sorted: column.sorted }),
470
+ column.resizeable !== false ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ColumnResizer, { ...resizeProps }) : null
471
+ ] })
472
+ }
473
+ );
474
+ };
475
+
476
+ // src/ColumnBasedTable.tsx
477
+ var import_jsx_runtime8 = require("react/jsx-runtime");
478
+ var classBase4 = "vuuTable";
479
+ var { RENDER_IDX } = import_vuu_utils4.metadataKeys;
480
+ var ColumnBasedTable = ({
481
+ columns,
482
+ data,
483
+ headerHeight,
484
+ onHeaderCellDragEnd,
485
+ rowHeight
486
+ }) => {
487
+ const handleDragEnd = (0, import_react8.useCallback)(() => {
488
+ onHeaderCellDragEnd == null ? void 0 : onHeaderCellDragEnd();
489
+ }, [onHeaderCellDragEnd]);
490
+ console.log(`ColumnBasedTable render`);
491
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: columns.map((column, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
492
+ "table",
493
+ {
494
+ className: (0, import_classnames6.default)(`${classBase4}-table`, `${classBase4}-columnBased`, {
495
+ vuuPinLeft: column.pin === "left"
496
+ }),
497
+ "data-idx": i,
498
+ id: `col-${i}`,
499
+ style: {
500
+ width: column.width,
501
+ left: column.pinnedOffset,
502
+ "--vuuTableHeaderHeight": `${headerHeight}px`,
503
+ "--row-height": `${rowHeight}px`
504
+ },
505
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("tbody", { children: [
506
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
507
+ TableHeaderCell,
508
+ {
509
+ column,
510
+ "data-idx": i,
511
+ onDragEnd: handleDragEnd
512
+ },
513
+ i
514
+ ) }, "header"),
515
+ data.map((row, j) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
516
+ TableRow,
517
+ {
518
+ columns: [column],
519
+ height: rowHeight,
520
+ index: j,
521
+ row
522
+ },
523
+ row[RENDER_IDX]
524
+ )),
525
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("tr", { className: "vuuTable-filler" })
526
+ ] })
527
+ },
528
+ column.name
529
+ )) });
530
+ };
531
+
532
+ // src/context-menu/buildContextMenuDescriptors.ts
533
+ var import_vuu_utils5 = require("@vuu-ui/vuu-utils");
534
+ var buildContextMenuDescriptors = (dataSource) => (location, options) => {
535
+ const descriptors = [];
536
+ if (dataSource === void 0) {
537
+ return descriptors;
538
+ }
539
+ if (location === "header") {
540
+ descriptors.push(
541
+ ...buildSortMenuItems(options, dataSource)
542
+ );
543
+ descriptors.push(
544
+ ...buildGroupMenuItems(options, dataSource)
545
+ );
546
+ descriptors.push(
547
+ ...buildAggregationMenuItems(options, dataSource)
548
+ );
549
+ descriptors.push(...buildColumnDisplayMenuItems(options));
550
+ } else if (location === "filter") {
551
+ const { column, filter } = options;
552
+ const colIsOnlyFilter = (filter == null ? void 0 : filter.column) === (column == null ? void 0 : column.name);
553
+ descriptors.push({
554
+ label: "Edit filter",
555
+ action: "filter-edit",
556
+ options
557
+ });
558
+ descriptors.push({
559
+ label: "Remove filter",
560
+ action: "filter-remove-column",
561
+ options
562
+ });
563
+ if (column && !colIsOnlyFilter) {
564
+ descriptors.push({
565
+ label: `Remove all filters`,
566
+ action: "remove-filters",
567
+ options
568
+ });
569
+ }
570
+ }
571
+ return descriptors;
572
+ };
573
+ function buildSortMenuItems(options, { sort: { sortDefs } }) {
574
+ const { column } = options;
575
+ const menuItems = [];
576
+ if (column === void 0) {
577
+ return menuItems;
578
+ }
579
+ const hasSort = sortDefs.length > 0;
580
+ if (column.sorted === "A") {
581
+ menuItems.push({
582
+ label: "Reverse Sort (DSC)",
583
+ action: "sort-dsc",
584
+ options
585
+ });
586
+ } else if (column.sorted === "D") {
587
+ menuItems.push({
588
+ label: "Reverse Sort (ASC)",
589
+ action: "sort-asc",
590
+ options
591
+ });
592
+ } else if (typeof column.sorted === "number") {
593
+ if (column.sorted > 0) {
594
+ menuItems.push({
595
+ label: "Reverse Sort (DSC)",
596
+ action: "sort-add-dsc",
597
+ options
598
+ });
599
+ } else {
600
+ menuItems.push({
601
+ label: "Reverse Sort (ASC)",
602
+ action: "sort-add-asc",
603
+ options
604
+ });
605
+ }
606
+ if (hasSort && Math.abs(column.sorted) < sortDefs.length) {
607
+ menuItems.push({
608
+ label: "Remove from sort",
609
+ action: "sort-remove",
610
+ options
611
+ });
612
+ }
613
+ menuItems.push({
614
+ label: "New Sort",
615
+ children: [
616
+ { label: "Ascending", action: "sort-asc", options },
617
+ { label: "Descending", action: "sort-dsc", options }
618
+ ]
619
+ });
620
+ } else if (hasSort) {
621
+ menuItems.push({
622
+ label: "Add to sort",
623
+ children: [
624
+ { label: "Ascending", action: "sort-add-asc", options },
625
+ { label: "Descending", action: "sort-add-dsc", options }
626
+ ]
627
+ });
628
+ menuItems.push({
629
+ label: "New Sort",
630
+ children: [
631
+ { label: "Ascending", action: "sort-asc", options },
632
+ { label: "Descending", action: "sort-dsc", options }
633
+ ]
634
+ });
635
+ } else {
636
+ menuItems.push({
637
+ label: "Sort",
638
+ children: [
639
+ { label: "Ascending", action: "sort-asc", options },
640
+ { label: "Descending", action: "sort-dsc", options }
641
+ ]
642
+ });
643
+ }
644
+ return menuItems;
645
+ }
646
+ function buildAggregationMenuItems(options, dataSource) {
647
+ const { column } = options;
648
+ if (column === void 0 || dataSource.groupBy.length === 0) {
649
+ return [];
650
+ }
651
+ const { name, label = name } = column;
652
+ return [
653
+ {
654
+ label: `Aggregate ${label}`,
655
+ children: [{ label: "Count", action: "agg-count", options }].concat(
656
+ (0, import_vuu_utils5.isNumericColumn)(column) ? [
657
+ { label: "Sum", action: "agg-sum", options },
658
+ { label: "Avg", action: "agg-avg", options },
659
+ { label: "High", action: "agg-high", options },
660
+ { label: "Low", action: "agg-low", options }
661
+ ] : []
662
+ )
663
+ }
664
+ ];
665
+ }
666
+ var pinColumn = (options, pinLocation) => ({
667
+ label: `Pin ${pinLocation}`,
668
+ action: `column-pin-${pinLocation}`,
669
+ options
670
+ });
671
+ var pinLeft = (options) => pinColumn(options, "left");
672
+ var pinFloating = (options) => pinColumn(options, "floating");
673
+ var pinRight = (options) => pinColumn(options, "right");
674
+ function buildColumnDisplayMenuItems(options) {
675
+ const { column } = options;
676
+ if (column === void 0) {
677
+ return [];
678
+ }
679
+ const { pin } = column;
680
+ const menuItems = [
681
+ {
682
+ label: `Hide column`,
683
+ action: "column-hide",
684
+ options
685
+ },
686
+ {
687
+ label: `Remove column`,
688
+ action: "column-remove",
689
+ options
690
+ }
691
+ ];
692
+ if (pin === void 0) {
693
+ menuItems.push({
694
+ label: `Pin column`,
695
+ children: [pinLeft(options), pinFloating(options), pinRight(options)]
696
+ });
697
+ } else if (pin === "left") {
698
+ menuItems.push(
699
+ { label: "Unpin column", action: "column-unpin", options },
700
+ {
701
+ label: `Pin column`,
702
+ children: [pinFloating(options), pinRight(options)]
703
+ }
704
+ );
705
+ } else if (pin === "right") {
706
+ menuItems.push(
707
+ { label: "Unpin column", action: "column-unpin", options },
708
+ {
709
+ label: `Pin column`,
710
+ children: [pinLeft(options), pinFloating(options)]
711
+ }
712
+ );
713
+ } else if (pin === "floating") {
714
+ menuItems.push(
715
+ { label: "Unpin column", action: "column-unpin", options },
716
+ {
717
+ label: `Pin column`,
718
+ children: [pinLeft(options), pinRight(options)]
719
+ }
720
+ );
721
+ }
722
+ return menuItems;
723
+ }
724
+ function buildGroupMenuItems(options, { groupBy }) {
725
+ const { column } = options;
726
+ const menuItems = [];
727
+ if (column === void 0) {
728
+ return menuItems;
729
+ }
730
+ const { name, label = name } = column;
731
+ if (groupBy.length === 0) {
732
+ menuItems.push({
733
+ label: `Group by ${label}`,
734
+ action: "group",
735
+ options
736
+ });
737
+ } else {
738
+ menuItems.push({
739
+ label: `Add ${label} to group by`,
740
+ action: "group-add",
741
+ options
742
+ });
743
+ }
744
+ return menuItems;
745
+ }
746
+
747
+ // src/context-menu/useContextMenu.ts
748
+ var import_vuu_filters = require("@vuu-ui/vuu-filters");
749
+ var import_vuu_utils6 = require("@vuu-ui/vuu-utils");
750
+ var removeFilterColumn = (dataSourceFilter, column) => {
751
+ if (dataSourceFilter.filterStruct && column) {
752
+ const [filterStruct, filter] = (0, import_vuu_filters.removeColumnFromFilter)(
753
+ column,
754
+ dataSourceFilter.filterStruct
755
+ );
756
+ return {
757
+ filter,
758
+ filterStruct
759
+ };
760
+ } else {
761
+ return dataSourceFilter;
762
+ }
763
+ };
764
+ var { Average, Count, High, Low, Sum } = import_vuu_utils6.AggregationType;
765
+ var useContextMenu3 = ({
766
+ dataSource,
767
+ onPersistentColumnOperation
768
+ }) => {
769
+ const handleContextMenuAction = (type, options) => {
770
+ const gridOptions = options;
771
+ if (gridOptions.column && dataSource) {
772
+ const { column } = gridOptions;
773
+ switch (type) {
774
+ case "sort-asc":
775
+ return dataSource.sort = (0, import_vuu_utils6.setSortColumn)(dataSource.sort, column, "A"), true;
776
+ case "sort-dsc":
777
+ return dataSource.sort = (0, import_vuu_utils6.setSortColumn)(dataSource.sort, column, "D"), true;
778
+ case "sort-add-asc":
779
+ return dataSource.sort = (0, import_vuu_utils6.addSortColumn)(dataSource.sort, column, "A"), true;
780
+ case "sort-add-dsc":
781
+ return dataSource.sort = (0, import_vuu_utils6.addSortColumn)(dataSource.sort, column, "D"), true;
782
+ case "group":
783
+ return dataSource.groupBy = (0, import_vuu_utils6.addGroupColumn)(dataSource.groupBy, column), true;
784
+ case "group-add":
785
+ return dataSource.groupBy = (0, import_vuu_utils6.addGroupColumn)(dataSource.groupBy, column), true;
786
+ case "column-hide":
787
+ return onPersistentColumnOperation({ type: "hideColumns", columns: [column] }), true;
788
+ case "column-remove":
789
+ return dataSource.columns = dataSource.columns.filter((name) => name !== column.name), true;
790
+ case "filter-remove-column":
791
+ return dataSource.filter = removeFilterColumn(dataSource.filter, column), true;
792
+ case "remove-filters":
793
+ return dataSource.filter = { filter: "" }, true;
794
+ case "agg-avg":
795
+ return dataSource.aggregations = (0, import_vuu_utils6.setAggregations)(dataSource.aggregations, column, Average), true;
796
+ case "agg-high":
797
+ return dataSource.aggregations = (0, import_vuu_utils6.setAggregations)(dataSource.aggregations, column, High), true;
798
+ case "agg-low":
799
+ return dataSource.aggregations = (0, import_vuu_utils6.setAggregations)(dataSource.aggregations, column, Low), true;
800
+ case "agg-count":
801
+ return dataSource.aggregations = (0, import_vuu_utils6.setAggregations)(dataSource.aggregations, column, Count), true;
802
+ case "agg-sum":
803
+ return dataSource.aggregations = (0, import_vuu_utils6.setAggregations)(dataSource.aggregations, column, Sum), true;
804
+ case "column-pin-floating":
805
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "floating" }), true;
806
+ case "column-pin-left":
807
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "left" }), true;
808
+ case "column-pin-right":
809
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "right" }), true;
810
+ case "column-unpin":
811
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: void 0 }), true;
812
+ default:
813
+ }
814
+ }
815
+ return false;
816
+ };
817
+ return handleContextMenuAction;
818
+ };
819
+
820
+ // src/RowBasedTable.tsx
821
+ var import_vuu_utils7 = require("@vuu-ui/vuu-utils");
822
+ var import_react10 = require("react");
823
+
824
+ // src/TableGroupHeaderCell.tsx
825
+ var import_classnames7 = __toESM(require("classnames"));
826
+ var import_react9 = require("react");
827
+ var import_jsx_runtime9 = require("react/jsx-runtime");
828
+ var classBase5 = "vuuTable-groupHeaderCell";
829
+ var ColHeader = (props) => {
830
+ const { column, className, onRemoveColumn } = props;
831
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: (0, import_classnames7.default)(`${classBase5}-col`, className), role: "columnheader", children: [
832
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${classBase5}-label`, children: column.name }),
833
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
834
+ "span",
835
+ {
836
+ className: `${classBase5}-close`,
837
+ "data-icon": "close-circle",
838
+ onClick: () => onRemoveColumn == null ? void 0 : onRemoveColumn(column)
839
+ }
840
+ )
841
+ ] });
842
+ };
843
+ var TableGroupHeaderCell = ({
844
+ column: groupColumn,
845
+ className: classNameProp,
846
+ onRemoveColumn,
847
+ onResize,
848
+ ...props
849
+ }) => {
850
+ const rootRef = (0, import_react9.useRef)(null);
851
+ const { isResizing, ...resizeProps } = useTableColumnResize({
852
+ column: groupColumn,
853
+ onResize,
854
+ rootRef
855
+ });
856
+ const className = (0, import_classnames7.default)(classBase5, classNameProp, {
857
+ vuuPinLeft: groupColumn.pin === "left",
858
+ [`${classBase5}-right`]: groupColumn.align === "right",
859
+ [`${classBase5}-resizing`]: groupColumn.resizing,
860
+ [`${classBase5}-pending`]: groupColumn.groupConfirmed === false
861
+ });
862
+ const { columns } = groupColumn;
863
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("th", { className, ref: rootRef, ...props, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: `${classBase5}-inner`, children: [
864
+ columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
865
+ ColHeader,
866
+ {
867
+ column,
868
+ onRemoveColumn
869
+ },
870
+ column.key
871
+ )),
872
+ groupColumn.resizeable !== false ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ColumnResizer, { ...resizeProps }) : null
873
+ ] }) });
874
+ };
875
+
876
+ // src/RowBasedTable.tsx
877
+ var import_jsx_runtime10 = require("react/jsx-runtime");
878
+ var classBase6 = "vuuTable";
879
+ var { RENDER_IDX: RENDER_IDX2 } = import_vuu_utils7.metadataKeys;
880
+ var RowBasedTable = ({
881
+ columns,
882
+ columnsWithinViewport,
883
+ data,
884
+ headings,
885
+ onColumnResize,
886
+ onHeaderCellDragStart,
887
+ onContextMenu,
888
+ onRemoveColumnFromGroupBy,
889
+ onRowClick,
890
+ onSort,
891
+ onToggleGroup,
892
+ virtualColSpan = 0,
893
+ rowCount,
894
+ rowHeight
895
+ }) => {
896
+ const handleDragStart = (0, import_react10.useCallback)(
897
+ (evt) => {
898
+ onHeaderCellDragStart == null ? void 0 : onHeaderCellDragStart(evt);
899
+ },
900
+ [onHeaderCellDragStart]
901
+ );
902
+ const visibleColumns = (0, import_react10.useMemo)(() => {
903
+ return columns.filter(import_vuu_utils7.notHidden);
904
+ }, [columns]);
905
+ const handleHeaderClick = (0, import_react10.useCallback)(
906
+ (evt) => {
907
+ var _a;
908
+ const targetElement = evt.target;
909
+ const headerCell = targetElement.closest(
910
+ ".vuuTable-headerCell"
911
+ );
912
+ const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.idx) != null ? _a : "-1");
913
+ const column = (0, import_vuu_utils7.visibleColumnAtIndex)(columns, colIdx);
914
+ const isAdditive = evt.shiftKey;
915
+ column && onSort(column, isAdditive);
916
+ },
917
+ [columns, onSort]
918
+ );
919
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("table", { "aria-rowcount": rowCount, className: `${classBase6}-table`, children: [
920
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("colgroup", { children: visibleColumns.map((column, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("col", { width: `${column.width}px` }, i)) }),
921
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("thead", { children: [
922
+ headings.map((colHeaders, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("tr", { className: "vuuTable-heading", children: colHeaders.map(({ label, span }, j) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("th", { colSpan: span, className: "vuuTable-headingCell", children: label }, j)) }, i)),
923
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("tr", { children: visibleColumns.map((column, i) => {
924
+ const style = (0, import_vuu_utils7.getColumnPinStyle)(column);
925
+ return (0, import_vuu_utils7.isGroupColumn)(column) ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
926
+ TableGroupHeaderCell,
927
+ {
928
+ column,
929
+ "data-idx": i,
930
+ onRemoveColumn: onRemoveColumnFromGroupBy,
931
+ onResize: onColumnResize,
932
+ style
933
+ },
934
+ i
935
+ ) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
936
+ TableHeaderCell,
937
+ {
938
+ column,
939
+ "data-idx": i,
940
+ onClick: handleHeaderClick,
941
+ onDragStart: handleDragStart,
942
+ onResize: onColumnResize,
943
+ style
944
+ },
945
+ i
946
+ );
947
+ }) })
948
+ ] }),
949
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("tbody", { onContextMenu, children: [
950
+ data == null ? void 0 : data.map((row, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
951
+ TableRow,
952
+ {
953
+ columns: columnsWithinViewport,
954
+ height: rowHeight,
955
+ index: i,
956
+ onClick: onRowClick,
957
+ virtualColSpan,
958
+ onToggleGroup,
959
+ row
960
+ },
961
+ row[RENDER_IDX2]
962
+ )),
963
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("tr", { className: `${classBase6}-filler` })
964
+ ] })
965
+ ] });
966
+ };
967
+
968
+ // src/useDataTable.ts
969
+ var import_vuu_popups3 = require("@vuu-ui/vuu-popups");
970
+ var import_vuu_utils13 = require("@vuu-ui/vuu-utils");
971
+ var import_react21 = require("react");
972
+
973
+ // src/useDataSource.ts
974
+ var import_vuu_data = require("@vuu-ui/vuu-data");
975
+ var import_vuu_utils8 = require("@vuu-ui/vuu-utils");
976
+ var import_react11 = require("react");
977
+ var { SELECTED: SELECTED2 } = import_vuu_utils8.metadataKeys;
978
+ function useDataSource({
979
+ dataSource,
980
+ onConfigChange,
981
+ onFeatureEnabled,
982
+ onFeatureInvocation,
983
+ onSizeChange,
984
+ onSubscribed,
985
+ range = { from: 0, to: 0 },
986
+ renderBufferSize = 0,
987
+ viewportRowCount
988
+ }) {
989
+ const [, forceUpdate] = (0, import_react11.useState)(null);
990
+ const isMounted = (0, import_react11.useRef)(true);
991
+ const hasUpdated = (0, import_react11.useRef)(false);
992
+ const rangeRef = (0, import_react11.useRef)({ from: 0, to: 0 });
993
+ const rafHandle = (0, import_react11.useRef)(null);
994
+ const data = (0, import_react11.useRef)([]);
995
+ const dataWindow = (0, import_react11.useMemo)(
996
+ () => new MovingWindow((0, import_vuu_utils8.getFullRange)(range)),
997
+ // eslint-disable-next-line react-hooks/exhaustive-deps
998
+ []
999
+ );
1000
+ const setData = (0, import_react11.useCallback)(
1001
+ (updates) => {
1002
+ for (const row of updates) {
1003
+ dataWindow.add(row);
1004
+ }
1005
+ data.current = dataWindow.data;
1006
+ hasUpdated.current = true;
1007
+ },
1008
+ [dataWindow]
1009
+ );
1010
+ const datasourceMessageHandler = (0, import_react11.useCallback)(
1011
+ (message) => {
1012
+ if (message.type === "subscribed") {
1013
+ onSubscribed == null ? void 0 : onSubscribed(message);
1014
+ } else if (message.type === "viewport-update") {
1015
+ if (typeof message.size === "number") {
1016
+ onSizeChange == null ? void 0 : onSizeChange(message.size);
1017
+ dataWindow.setRowCount(message.size);
1018
+ }
1019
+ if (message.rows) {
1020
+ setData(message.rows);
1021
+ } else if (typeof message.size === "number") {
1022
+ data.current = dataWindow.data;
1023
+ hasUpdated.current = true;
1024
+ }
1025
+ } else if ((0, import_vuu_data.isVuuFeatureAction)(message)) {
1026
+ onFeatureEnabled == null ? void 0 : onFeatureEnabled(message);
1027
+ } else if ((0, import_vuu_data.isVuuFeatureInvocation)(message)) {
1028
+ onFeatureInvocation == null ? void 0 : onFeatureInvocation(message);
1029
+ } else {
1030
+ console.log(`useDataSource unexpected message ${message.type}`);
1031
+ }
1032
+ },
1033
+ [
1034
+ dataWindow,
1035
+ onFeatureEnabled,
1036
+ onFeatureInvocation,
1037
+ onSizeChange,
1038
+ onSubscribed,
1039
+ setData
1040
+ ]
1041
+ );
1042
+ (0, import_react11.useEffect)(
1043
+ () => () => {
1044
+ if (rafHandle.current) {
1045
+ cancelAnimationFrame(rafHandle.current);
1046
+ rafHandle.current = null;
1047
+ }
1048
+ isMounted.current = false;
1049
+ },
1050
+ []
1051
+ );
1052
+ const refreshIfUpdated = (0, import_react11.useCallback)(() => {
1053
+ if (isMounted.current) {
1054
+ if (hasUpdated.current) {
1055
+ forceUpdate({});
1056
+ hasUpdated.current = false;
1057
+ }
1058
+ rafHandle.current = requestAnimationFrame(refreshIfUpdated);
1059
+ }
1060
+ }, [forceUpdate]);
1061
+ (0, import_react11.useEffect)(() => {
1062
+ rafHandle.current = requestAnimationFrame(refreshIfUpdated);
1063
+ }, [refreshIfUpdated]);
1064
+ const adjustRange = (0, import_react11.useCallback)(
1065
+ (rowCount) => {
1066
+ const { from } = dataSource.range;
1067
+ const rowRange = { from, to: from + rowCount };
1068
+ const fullRange = (0, import_vuu_utils8.getFullRange)(rowRange, renderBufferSize);
1069
+ dataSource.range = rangeRef.current = fullRange;
1070
+ dataSource.emit("range", rowRange);
1071
+ dataWindow.setRange(fullRange);
1072
+ },
1073
+ [dataSource, dataWindow, renderBufferSize]
1074
+ );
1075
+ const setRange = (0, import_react11.useCallback)(
1076
+ (range2) => {
1077
+ const fullRange = (0, import_vuu_utils8.getFullRange)(range2, renderBufferSize);
1078
+ dataSource.range = rangeRef.current = fullRange;
1079
+ dataWindow.setRange(fullRange);
1080
+ dataSource.emit("range", range2);
1081
+ },
1082
+ [dataSource, dataWindow, renderBufferSize]
1083
+ );
1084
+ const getSelectedRows = (0, import_react11.useCallback)(() => {
1085
+ return dataWindow.getSelectedRows();
1086
+ }, [dataWindow]);
1087
+ (0, import_react11.useEffect)(() => {
1088
+ dataSource == null ? void 0 : dataSource.subscribe(
1089
+ {
1090
+ range: rangeRef.current
1091
+ },
1092
+ datasourceMessageHandler
1093
+ );
1094
+ }, [dataSource, datasourceMessageHandler, onConfigChange]);
1095
+ (0, import_react11.useEffect)(() => {
1096
+ adjustRange(viewportRowCount);
1097
+ }, [adjustRange, viewportRowCount]);
1098
+ return {
1099
+ data: data.current,
1100
+ getSelectedRows,
1101
+ range: rangeRef.current,
1102
+ setRange,
1103
+ dataSource
1104
+ };
1105
+ }
1106
+ var MovingWindow = class {
1107
+ constructor({ from, to }) {
1108
+ this.rowCount = 0;
1109
+ this.setRowCount = (rowCount) => {
1110
+ if (rowCount < this.data.length) {
1111
+ this.data.length = rowCount;
1112
+ }
1113
+ this.rowCount = rowCount;
1114
+ };
1115
+ this.range = new import_vuu_utils8.WindowRange(from, to);
1116
+ this.data = new Array(to - from);
1117
+ this.rowCount = 0;
1118
+ }
1119
+ add(data) {
1120
+ var _a;
1121
+ const [index] = data;
1122
+ if (this.isWithinRange(index)) {
1123
+ const internalIndex = index - this.range.from;
1124
+ this.data[internalIndex] = data;
1125
+ const isSelected = data[SELECTED2];
1126
+ const preSelected = (_a = this.data[internalIndex - 1]) == null ? void 0 : _a[SELECTED2];
1127
+ if (preSelected === 0 && isSelected) {
1128
+ this.data[internalIndex - 1][SELECTED2] = 2;
1129
+ } else if (preSelected === 2 && !isSelected) {
1130
+ this.data[internalIndex - 1][SELECTED2] = 0;
1131
+ }
1132
+ }
1133
+ }
1134
+ getAtIndex(index) {
1135
+ return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
1136
+ }
1137
+ isWithinRange(index) {
1138
+ return this.range.isWithin(index);
1139
+ }
1140
+ setRange({ from, to }) {
1141
+ if (from !== this.range.from || to !== this.range.to) {
1142
+ const [overlapFrom, overlapTo] = this.range.overlap(from, to);
1143
+ const newData = new Array(to - from);
1144
+ for (let i = overlapFrom; i < overlapTo; i++) {
1145
+ const data = this.getAtIndex(i);
1146
+ if (data) {
1147
+ const index = i - from;
1148
+ newData[index] = data;
1149
+ }
1150
+ }
1151
+ this.data = newData;
1152
+ this.range.from = from;
1153
+ this.range.to = to;
1154
+ }
1155
+ }
1156
+ getSelectedRows() {
1157
+ return this.data.filter((row) => row[SELECTED2] === 1);
1158
+ }
1159
+ };
1160
+
1161
+ // src/useDraggableColumn.ts
1162
+ var import_salt_lab2 = require("@heswell/salt-lab");
1163
+ var import_react12 = require("react");
1164
+ var useDraggableColumn = ({
1165
+ onDrop,
1166
+ tableContainerRef,
1167
+ tableLayout: tableLayoutProp
1168
+ }) => {
1169
+ const [tableLayout, setTableLayout] = (0, import_react12.useState)(tableLayoutProp);
1170
+ const mousePosRef = (0, import_react12.useRef)();
1171
+ const handleDropSettle = (0, import_react12.useCallback)(() => {
1172
+ console.log(`handleDropSettle`);
1173
+ mousePosRef.current = void 0;
1174
+ setTableLayout("row");
1175
+ }, []);
1176
+ const { draggable, draggedItemIndex, onMouseDown } = (0, import_salt_lab2.useDragDrop)({
1177
+ allowDragDrop: true,
1178
+ draggableClassName: "table-column",
1179
+ orientation: "horizontal",
1180
+ containerRef: tableContainerRef,
1181
+ itemQuery: ".vuuTable-table",
1182
+ onDrop,
1183
+ onDropSettle: handleDropSettle
1184
+ });
1185
+ const handleHeaderCellDragStart = (0, import_react12.useCallback)((evt) => {
1186
+ const { clientX, clientY } = evt;
1187
+ console.log(
1188
+ `useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable`
1189
+ );
1190
+ const sourceElement = evt.target;
1191
+ const thElement = sourceElement.closest(".vuuTable-headerCell");
1192
+ const {
1193
+ dataset: { idx = "-1" }
1194
+ } = thElement;
1195
+ mousePosRef.current = {
1196
+ clientX,
1197
+ clientY,
1198
+ idx
1199
+ };
1200
+ setTableLayout("column");
1201
+ }, []);
1202
+ (0, import_react12.useLayoutEffect)(() => {
1203
+ var _a;
1204
+ if (tableLayout === "column" && mousePosRef.current && !draggable) {
1205
+ const { clientX, clientY, idx } = mousePosRef.current;
1206
+ const target = (_a = tableContainerRef.current) == null ? void 0 : _a.querySelector(
1207
+ `.vuuTable-table[data-idx="${idx}"]`
1208
+ );
1209
+ if (target) {
1210
+ const evt = {
1211
+ persist: () => void 0,
1212
+ nativeEvent: {
1213
+ clientX,
1214
+ clientY,
1215
+ target
1216
+ }
1217
+ };
1218
+ onMouseDown == null ? void 0 : onMouseDown(evt);
1219
+ }
1220
+ }
1221
+ }, [draggable, onMouseDown, tableContainerRef, tableLayout]);
1222
+ return {
1223
+ draggable,
1224
+ draggedItemIndex,
1225
+ tableLayout,
1226
+ onHeaderCellDragStart: tableLayout === "row" ? handleHeaderCellDragStart : void 0
1227
+ };
1228
+ };
1229
+
1230
+ // src/useKeyboardNavigation.ts
1231
+ var import_vuu_utils9 = require("@vuu-ui/vuu-utils");
1232
+ var import_react13 = require("react");
1233
+
1234
+ // src/keyUtils.ts
1235
+ function union(set1, ...sets) {
1236
+ const result = new Set(set1);
1237
+ for (let set of sets) {
1238
+ for (let element of set) {
1239
+ result.add(element);
1240
+ }
1241
+ }
1242
+ return result;
1243
+ }
1244
+ var ArrowUp = "ArrowUp";
1245
+ var ArrowDown = "ArrowDown";
1246
+ var ArrowLeft = "ArrowLeft";
1247
+ var ArrowRight = "ArrowRight";
1248
+ var Home = "Home";
1249
+ var End = "End";
1250
+ var PageUp = "PageUp";
1251
+ var PageDown = "PageDown";
1252
+ var actionKeys = /* @__PURE__ */ new Set(["Enter", "Delete", " "]);
1253
+ var focusKeys = /* @__PURE__ */ new Set(["Tab"]);
1254
+ var arrowLeftRightKeys = /* @__PURE__ */ new Set(["ArrowRight", "ArrowLeft"]);
1255
+ var navigationKeys = /* @__PURE__ */ new Set([
1256
+ Home,
1257
+ End,
1258
+ PageUp,
1259
+ PageDown,
1260
+ ArrowDown,
1261
+ ArrowLeft,
1262
+ ArrowRight,
1263
+ ArrowUp
1264
+ ]);
1265
+ var functionKeys = /* @__PURE__ */ new Set([
1266
+ "F1",
1267
+ "F2",
1268
+ "F3",
1269
+ "F4",
1270
+ "F5",
1271
+ "F6",
1272
+ "F7",
1273
+ "F8",
1274
+ "F9",
1275
+ "F10",
1276
+ "F11",
1277
+ "F12"
1278
+ ]);
1279
+ var specialKeys = union(
1280
+ actionKeys,
1281
+ navigationKeys,
1282
+ arrowLeftRightKeys,
1283
+ functionKeys,
1284
+ focusKeys
1285
+ );
1286
+ var PageKeys = ["Home", "End", "PageUp", "PageDown"];
1287
+ var isPagingKey = (key) => PageKeys.includes(key);
1288
+ var isNavigationKey = (key) => {
1289
+ return navigationKeys.has(key);
1290
+ };
1291
+
1292
+ // src/useKeyboardNavigation.ts
1293
+ var headerCellQuery = (colIdx) => `thead th:nth-child(${colIdx + 1})`;
1294
+ var dataCellQuery = (rowIdx, colIdx) => `tbody > tr[aria-rowindex='${rowIdx}'] > td:nth-child(${colIdx + 1})`;
1295
+ var NULL_CELL_POS = [-1, -1];
1296
+ function nextCellPos(key, [rowIdx, colIdx], columnCount, rowCount) {
1297
+ if (key === ArrowUp) {
1298
+ if (rowIdx > -1) {
1299
+ return [rowIdx - 1, colIdx];
1300
+ } else {
1301
+ return [rowIdx, colIdx];
1302
+ }
1303
+ } else if (key === ArrowDown) {
1304
+ if (rowIdx === -1) {
1305
+ return [0, colIdx];
1306
+ } else if (rowIdx === rowCount - 1) {
1307
+ return [rowIdx, colIdx];
1308
+ } else {
1309
+ return [rowIdx + 1, colIdx];
1310
+ }
1311
+ } else if (key === ArrowRight) {
1312
+ if (colIdx < columnCount - 1) {
1313
+ return [rowIdx, colIdx + 1];
1314
+ } else {
1315
+ return [rowIdx, colIdx];
1316
+ }
1317
+ } else if (key === ArrowLeft) {
1318
+ if (colIdx > 0) {
1319
+ return [rowIdx, colIdx - 1];
1320
+ } else {
1321
+ return [rowIdx, colIdx];
1322
+ }
1323
+ }
1324
+ return [rowIdx, colIdx];
1325
+ }
1326
+ var useKeyboardNavigation = ({
1327
+ columnCount = 0,
1328
+ containerRef,
1329
+ disableHighlightOnFocus,
1330
+ data,
1331
+ requestScroll,
1332
+ rowCount = 0,
1333
+ viewportRange
1334
+ }) => {
1335
+ var _a;
1336
+ const { from: viewportFirstRow, to: viewportLastRow } = viewportRange;
1337
+ const focusedCellPos = (0, import_react13.useRef)([-1, -1]);
1338
+ const focusableCell = (0, import_react13.useRef)();
1339
+ const activeCellPos = (0, import_react13.useRef)([-1, 0]);
1340
+ const getTableCell = (0, import_react13.useCallback)(
1341
+ ([rowIdx, colIdx]) => {
1342
+ var _a2;
1343
+ const cssQuery = rowIdx === -1 ? headerCellQuery(colIdx) : dataCellQuery(rowIdx, colIdx);
1344
+ return (_a2 = containerRef.current) == null ? void 0 : _a2.querySelector(
1345
+ cssQuery
1346
+ );
1347
+ },
1348
+ [containerRef]
1349
+ );
1350
+ const getFocusedCell = (element) => element == null ? void 0 : element.closest("th,td");
1351
+ const getTableCellPos = (tableCell) => {
1352
+ var _a2, _b;
1353
+ if (tableCell.tagName === "TH") {
1354
+ const colIdx = parseInt((_a2 = tableCell.dataset.idx) != null ? _a2 : "-1", 10);
1355
+ return [-1, colIdx];
1356
+ } else {
1357
+ const focusedRow = tableCell.closest("tr");
1358
+ if (focusedRow) {
1359
+ const rowIdx = parseInt((_b = focusedRow.ariaRowIndex) != null ? _b : "-1", 10);
1360
+ const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);
1361
+ return [rowIdx, colIdx];
1362
+ }
1363
+ }
1364
+ return NULL_CELL_POS;
1365
+ };
1366
+ const focusCell = (0, import_react13.useCallback)(
1367
+ (cellPos) => {
1368
+ var _a2;
1369
+ if (containerRef.current) {
1370
+ const activeCell = getTableCell(cellPos);
1371
+ if (activeCell) {
1372
+ if (activeCell !== focusableCell.current) {
1373
+ (_a2 = focusableCell.current) == null ? void 0 : _a2.setAttribute("tabindex", "");
1374
+ focusableCell.current = activeCell;
1375
+ activeCell.setAttribute("tabindex", "0");
1376
+ }
1377
+ activeCell.focus();
1378
+ } else if (!(0, import_vuu_utils9.withinRange)(cellPos[0], viewportRange)) {
1379
+ focusableCell.current = void 0;
1380
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
1381
+ }
1382
+ }
1383
+ },
1384
+ // TODO we recreate this function whenever viewportRange changes, which will
1385
+ // be often whilst scrolling - store range in a a ref ?
1386
+ [containerRef, getTableCell, requestScroll, viewportRange]
1387
+ );
1388
+ const setActiveCell = (0, import_react13.useCallback)(
1389
+ (rowIdx, colIdx, fromKeyboard = false) => {
1390
+ const pos = [rowIdx, colIdx];
1391
+ activeCellPos.current = pos;
1392
+ focusCell(pos);
1393
+ if (fromKeyboard) {
1394
+ focusedCellPos.current = pos;
1395
+ }
1396
+ },
1397
+ [focusCell]
1398
+ );
1399
+ const virtualizeActiveCell = (0, import_react13.useCallback)(() => {
1400
+ var _a2;
1401
+ (_a2 = focusableCell.current) == null ? void 0 : _a2.setAttribute("tabindex", "");
1402
+ focusableCell.current = void 0;
1403
+ }, []);
1404
+ const nextPageItemIdx = (0, import_react13.useCallback)(
1405
+ async (key, cellPos) => {
1406
+ switch (key) {
1407
+ case PageDown:
1408
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "down" });
1409
+ break;
1410
+ case PageUp:
1411
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
1412
+ break;
1413
+ case Home:
1414
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "home" });
1415
+ break;
1416
+ case End:
1417
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "end" });
1418
+ break;
1419
+ }
1420
+ return cellPos;
1421
+ },
1422
+ [requestScroll]
1423
+ );
1424
+ const handleFocus = (0, import_react13.useCallback)(() => {
1425
+ var _a2;
1426
+ if (disableHighlightOnFocus !== true) {
1427
+ if ((_a2 = containerRef.current) == null ? void 0 : _a2.contains(document.activeElement)) {
1428
+ const focusedCell = getFocusedCell(document.activeElement);
1429
+ if (focusedCell) {
1430
+ focusedCellPos.current = getTableCellPos(focusedCell);
1431
+ }
1432
+ }
1433
+ }
1434
+ }, [disableHighlightOnFocus, containerRef]);
1435
+ const navigateChildItems = (0, import_react13.useCallback)(
1436
+ async (key) => {
1437
+ const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
1438
+ const [rowIdx, colIdx] = activeCellPos.current;
1439
+ if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {
1440
+ setActiveCell(nextRowIdx, nextColIdx, true);
1441
+ }
1442
+ },
1443
+ [columnCount, nextPageItemIdx, rowCount, setActiveCell]
1444
+ );
1445
+ const handleKeyDown = (0, import_react13.useCallback)(
1446
+ (e) => {
1447
+ if (data.length > 0 && isNavigationKey(e.key)) {
1448
+ e.preventDefault();
1449
+ e.stopPropagation();
1450
+ void navigateChildItems(e.key);
1451
+ }
1452
+ },
1453
+ [data, navigateChildItems]
1454
+ );
1455
+ const handleClick = (0, import_react13.useCallback)(
1456
+ // Might not be a cell e.g the Settings button
1457
+ (evt) => {
1458
+ const target = evt.target;
1459
+ const focusedCell = getFocusedCell(target);
1460
+ if (focusedCell) {
1461
+ const [rowIdx, colIdx] = getTableCellPos(focusedCell);
1462
+ setActiveCell(rowIdx, colIdx);
1463
+ }
1464
+ },
1465
+ [setActiveCell]
1466
+ );
1467
+ const containerProps = (0, import_react13.useMemo)(() => {
1468
+ return {
1469
+ onClick: handleClick,
1470
+ onFocus: handleFocus,
1471
+ onKeyDown: handleKeyDown
1472
+ };
1473
+ }, [handleClick, handleFocus, handleKeyDown]);
1474
+ (0, import_react13.useLayoutEffect)(() => {
1475
+ const { current: cellPos } = activeCellPos;
1476
+ const withinViewport = cellPos[0] >= viewportFirstRow && cellPos[0] <= viewportLastRow;
1477
+ if (focusableCell.current && !withinViewport) {
1478
+ virtualizeActiveCell();
1479
+ } else if (!focusableCell.current && withinViewport) {
1480
+ focusCell(cellPos);
1481
+ }
1482
+ }, [focusCell, viewportFirstRow, viewportLastRow, virtualizeActiveCell]);
1483
+ const fullyRendered = ((_a = containerRef.current) == null ? void 0 : _a.firstChild) != null;
1484
+ (0, import_react13.useEffect)(() => {
1485
+ var _a2;
1486
+ if (fullyRendered && focusableCell.current === void 0) {
1487
+ const headerCell = (_a2 = containerRef.current) == null ? void 0 : _a2.querySelector(
1488
+ headerCellQuery(0)
1489
+ );
1490
+ if (headerCell) {
1491
+ headerCell.setAttribute("tabindex", "0");
1492
+ focusableCell.current = headerCell;
1493
+ }
1494
+ }
1495
+ }, [containerRef, fullyRendered]);
1496
+ return containerProps;
1497
+ };
1498
+
1499
+ // src/useMeasuredContainer.ts
1500
+ var import_react15 = require("react");
1501
+
1502
+ // src/useResizeObserver.ts
1503
+ var import_react14 = require("react");
1504
+ var observedMap = /* @__PURE__ */ new Map();
1505
+ var getTargetSize = (element, size, dimension) => {
1506
+ switch (dimension) {
1507
+ case "height":
1508
+ return size.height;
1509
+ case "clientHeight":
1510
+ return element.clientHeight;
1511
+ case "clientWidth":
1512
+ return element.clientWidth;
1513
+ case "contentHeight":
1514
+ return size.contentHeight;
1515
+ case "contentWidth":
1516
+ return size.contentWidth;
1517
+ case "scrollHeight":
1518
+ return Math.ceil(element.scrollHeight);
1519
+ case "scrollWidth":
1520
+ return Math.ceil(element.scrollWidth);
1521
+ case "width":
1522
+ return size.width;
1523
+ default:
1524
+ return 0;
1525
+ }
1526
+ };
1527
+ var resizeObserver = new ResizeObserver((entries) => {
1528
+ for (const entry of entries) {
1529
+ const { target, borderBoxSize, contentBoxSize } = entry;
1530
+ const observedTarget = observedMap.get(target);
1531
+ if (observedTarget) {
1532
+ const [{ blockSize: height, inlineSize: width }] = borderBoxSize;
1533
+ const [{ blockSize: contentHeight, inlineSize: contentWidth }] = contentBoxSize;
1534
+ const { onResize, measurements } = observedTarget;
1535
+ let sizeChanged = false;
1536
+ for (const [dimension, size] of Object.entries(measurements)) {
1537
+ const newSize = getTargetSize(
1538
+ target,
1539
+ { height, width, contentHeight, contentWidth },
1540
+ dimension
1541
+ );
1542
+ if (newSize !== size) {
1543
+ sizeChanged = true;
1544
+ measurements[dimension] = newSize;
1545
+ }
1546
+ }
1547
+ if (sizeChanged) {
1548
+ onResize && onResize(measurements);
1549
+ }
1550
+ }
1551
+ }
1552
+ });
1553
+ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false) {
1554
+ const dimensionsRef = (0, import_react14.useRef)(dimensions);
1555
+ const measure = (0, import_react14.useCallback)((target) => {
1556
+ const { width, height } = target.getBoundingClientRect();
1557
+ const { clientWidth: contentWidth, clientHeight: contentHeight } = target;
1558
+ return dimensionsRef.current.reduce(
1559
+ (map, dim) => {
1560
+ map[dim] = getTargetSize(
1561
+ target,
1562
+ { width, height, contentHeight, contentWidth },
1563
+ dim
1564
+ );
1565
+ return map;
1566
+ },
1567
+ {}
1568
+ );
1569
+ }, []);
1570
+ (0, import_react14.useEffect)(() => {
1571
+ const target = ref.current;
1572
+ async function registerObserver() {
1573
+ observedMap.set(target, { measurements: {} });
1574
+ await document.fonts.ready;
1575
+ const observedTarget = observedMap.get(target);
1576
+ if (observedTarget) {
1577
+ const measurements = measure(target);
1578
+ observedTarget.measurements = measurements;
1579
+ resizeObserver.observe(target);
1580
+ if (reportInitialSize) {
1581
+ onResize(measurements);
1582
+ }
1583
+ } else {
1584
+ console.log(
1585
+ `%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation`,
1586
+ "font-weight:bold; color:red;"
1587
+ );
1588
+ }
1589
+ }
1590
+ if (target) {
1591
+ if (observedMap.has(target)) {
1592
+ throw Error(
1593
+ "useResizeObserver attemping to observe same element twice"
1594
+ );
1595
+ }
1596
+ registerObserver();
1597
+ }
1598
+ return () => {
1599
+ if (target && observedMap.has(target)) {
1600
+ resizeObserver.unobserve(target);
1601
+ observedMap.delete(target);
1602
+ }
1603
+ };
1604
+ }, [measure, ref]);
1605
+ (0, import_react14.useEffect)(() => {
1606
+ const target = ref.current;
1607
+ const record = observedMap.get(target);
1608
+ if (record) {
1609
+ if (dimensionsRef.current !== dimensions) {
1610
+ dimensionsRef.current = dimensions;
1611
+ const measurements = measure(target);
1612
+ record.measurements = measurements;
1613
+ }
1614
+ record.onResize = onResize;
1615
+ }
1616
+ }, [dimensions, measure, ref, onResize]);
1617
+ }
1618
+
1619
+ // src/useMeasuredContainer.ts
1620
+ var ClientWidthHeight = ["clientHeight", "clientWidth"];
1621
+ var isNumber = (val) => Number.isFinite(val);
1622
+ var useMeasuredContainer = ({
1623
+ defaultHeight = 0,
1624
+ defaultWidth = 0,
1625
+ height,
1626
+ width
1627
+ }) => {
1628
+ const containerRef = (0, import_react15.useRef)(null);
1629
+ const [size, setSize] = (0, import_react15.useState)({
1630
+ outer: {
1631
+ height: height != null ? height : "100%",
1632
+ width: width != null ? width : "100%"
1633
+ }
1634
+ });
1635
+ const onResize = (0, import_react15.useCallback)(
1636
+ ({ clientWidth, clientHeight }) => {
1637
+ setSize((currentSize) => {
1638
+ const { inner, outer } = currentSize;
1639
+ return isNumber(clientHeight) && isNumber(clientWidth) && (clientWidth !== (inner == null ? void 0 : inner.width) || clientHeight !== (inner == null ? void 0 : inner.height)) ? {
1640
+ outer,
1641
+ inner: {
1642
+ width: Math.floor(clientWidth) || defaultWidth,
1643
+ height: Math.floor(clientHeight) || defaultHeight
1644
+ }
1645
+ } : currentSize;
1646
+ });
1647
+ },
1648
+ [defaultHeight, defaultWidth]
1649
+ );
1650
+ useResizeObserver(containerRef, ClientWidthHeight, onResize, true);
1651
+ return {
1652
+ containerRef,
1653
+ outerSize: size.outer,
1654
+ innerSize: size.inner
1655
+ };
1656
+ };
1657
+
1658
+ // src/useSelection.ts
1659
+ var import_vuu_utils10 = require("@vuu-ui/vuu-utils");
1660
+ var import_react16 = require("react");
1661
+ var { IDX: IDX2, SELECTED: SELECTED3 } = import_vuu_utils10.metadataKeys;
1662
+ var NO_SELECTION = [];
1663
+ var useSelection = ({
1664
+ selectionModel,
1665
+ onSelectionChange
1666
+ }) => {
1667
+ selectionModel === "extended" || selectionModel === "checkbox";
1668
+ const lastActiveRef = (0, import_react16.useRef)(-1);
1669
+ const selectedRef = (0, import_react16.useRef)(NO_SELECTION);
1670
+ const handleSelectionChange = (0, import_react16.useCallback)(
1671
+ (row, rangeSelect, keepExistingSelection) => {
1672
+ const { [IDX2]: idx, [SELECTED3]: isSelected } = row;
1673
+ const { current: active } = lastActiveRef;
1674
+ const { current: selected } = selectedRef;
1675
+ const selectOperation = isSelected ? import_vuu_utils10.deselectItem : import_vuu_utils10.selectItem;
1676
+ const newSelected = selectOperation(
1677
+ selectionModel,
1678
+ selected,
1679
+ idx,
1680
+ rangeSelect,
1681
+ keepExistingSelection,
1682
+ active
1683
+ );
1684
+ selectedRef.current = newSelected;
1685
+ lastActiveRef.current = idx;
1686
+ if (onSelectionChange) {
1687
+ onSelectionChange(newSelected);
1688
+ }
1689
+ },
1690
+ [onSelectionChange, selectionModel]
1691
+ );
1692
+ return handleSelectionChange;
1693
+ };
1694
+
1695
+ // src/useTableModel.ts
1696
+ var import_salt_lab3 = require("@heswell/salt-lab");
1697
+ var import_vuu_utils11 = require("@vuu-ui/vuu-utils");
1698
+ var import_react17 = require("react");
1699
+ var { info } = (0, import_vuu_utils11.logger)("useTableModel");
1700
+ var DEFAULT_COLUMN_WIDTH = 100;
1701
+ var KEY_OFFSET = import_vuu_utils11.metadataKeys.count;
1702
+ var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
1703
+ var getCellRendererForColumn = (column) => {
1704
+ var _a;
1705
+ if ((0, import_vuu_utils11.isTypeDescriptor)(column.type)) {
1706
+ return (0, import_vuu_utils11.getCellRenderer)((_a = column.type) == null ? void 0 : _a.renderer);
1707
+ }
1708
+ };
1709
+ var getDataType = (column, columnNames, dataTypes) => {
1710
+ var _a;
1711
+ const index = columnNames.indexOf(column.name);
1712
+ if (index !== -1 && dataTypes[index]) {
1713
+ return dataTypes[index];
1714
+ } else {
1715
+ return (_a = column.serverDataType) != null ? _a : "string";
1716
+ }
1717
+ };
1718
+ var numericTypes = ["int", "long", "double"];
1719
+ var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
1720
+ var columnReducer = (state, action) => {
1721
+ info == null ? void 0 : info(`GridModelReducer ${action.type}`);
1722
+ switch (action.type) {
1723
+ case "init":
1724
+ return init(action);
1725
+ case "moveColumn":
1726
+ return moveColumn(state, action);
1727
+ case "resizeColumn":
1728
+ return resizeColumn(state, action);
1729
+ case "setTypes":
1730
+ return setTypes(state, action);
1731
+ case "hideColumns":
1732
+ return hideColumns(state, action);
1733
+ case "showColumns":
1734
+ return showColumns(state, action);
1735
+ case "pinColumn":
1736
+ return pinColumn2(state, action);
1737
+ case "updateColumnProp":
1738
+ return updateColumnProp(state, action);
1739
+ case "tableConfig":
1740
+ return updateTableConfig(state, action);
1741
+ default:
1742
+ console.log(`unhandled action ${action.type}`);
1743
+ return state;
1744
+ }
1745
+ };
1746
+ var useTableModel = (tableConfig, dataSourceConfig) => {
1747
+ const [state, dispatchColumnAction] = (0, import_react17.useReducer)(columnReducer, { tableConfig, dataSourceConfig }, init);
1748
+ return {
1749
+ columns: state.columns,
1750
+ dispatchColumnAction,
1751
+ headings: state.headings
1752
+ };
1753
+ };
1754
+ function init({ dataSourceConfig, tableConfig }) {
1755
+ const columns = tableConfig.columns.map(
1756
+ toKeyedColumWithDefaults(tableConfig)
1757
+ );
1758
+ const maybePinnedColumns = columns.some(import_vuu_utils11.isPinned) ? (0, import_vuu_utils11.sortPinnedColumns)(columns) : columns;
1759
+ const state = {
1760
+ columns: maybePinnedColumns,
1761
+ headings: (0, import_vuu_utils11.getTableHeadings)(maybePinnedColumns)
1762
+ };
1763
+ if (dataSourceConfig) {
1764
+ const { columns: columns2, ...rest } = dataSourceConfig;
1765
+ return updateTableConfig(state, {
1766
+ type: "tableConfig",
1767
+ ...rest
1768
+ });
1769
+ } else {
1770
+ return state;
1771
+ }
1772
+ }
1773
+ var getLabel = (label, columnFormatHeader) => {
1774
+ if (columnFormatHeader === "uppercase") {
1775
+ return label.toUpperCase();
1776
+ } else if (columnFormatHeader === "capitalize") {
1777
+ return label[0].toUpperCase() + label.slice(1).toLowerCase();
1778
+ }
1779
+ return label;
1780
+ };
1781
+ var toKeyedColumWithDefaults = (options) => (column, index) => {
1782
+ const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = options;
1783
+ const {
1784
+ align = getDefaultAlignment(column.serverDataType),
1785
+ key,
1786
+ name,
1787
+ label = name,
1788
+ width = columnDefaultWidth,
1789
+ ...rest
1790
+ } = column;
1791
+ const keyedColumnWithDefaults = {
1792
+ ...rest,
1793
+ align,
1794
+ CellRenderer: getCellRendererForColumn(column),
1795
+ label: getLabel(label, columnFormatHeader),
1796
+ key: key != null ? key : index + KEY_OFFSET,
1797
+ name,
1798
+ originalIdx: index,
1799
+ valueFormatter: (0, import_vuu_utils11.getValueFormatter)(column),
1800
+ width
1801
+ };
1802
+ if ((0, import_vuu_utils11.isGroupColumn)(keyedColumnWithDefaults)) {
1803
+ keyedColumnWithDefaults.columns = keyedColumnWithDefaults.columns.map(
1804
+ (col) => toKeyedColumWithDefaults(options)(col, col.key)
1805
+ );
1806
+ }
1807
+ return keyedColumnWithDefaults;
1808
+ };
1809
+ function moveColumn(state, { column, moveBy, moveTo }) {
1810
+ const { columns } = state;
1811
+ if (typeof moveBy === "number") {
1812
+ const idx = columns.indexOf(column);
1813
+ const newColumns = columns.slice();
1814
+ const [movedColumns] = newColumns.splice(idx, 1);
1815
+ newColumns.splice(idx + moveBy, 0, movedColumns);
1816
+ return {
1817
+ ...state,
1818
+ columns: newColumns
1819
+ };
1820
+ } else if (typeof moveTo === "number") {
1821
+ const index = columns.indexOf(column);
1822
+ return {
1823
+ ...state,
1824
+ columns: (0, import_salt_lab3.moveItem)(columns, index, moveTo)
1825
+ };
1826
+ }
1827
+ return state;
1828
+ }
1829
+ function hideColumns(state, { columns }) {
1830
+ if (columns.some((col) => col.hidden !== true)) {
1831
+ return columns.reduce((s, c) => {
1832
+ if (c.hidden !== true) {
1833
+ return updateColumnProp(s, {
1834
+ type: "updateColumnProp",
1835
+ column: c,
1836
+ hidden: true
1837
+ });
1838
+ } else {
1839
+ return s;
1840
+ }
1841
+ }, state);
1842
+ } else {
1843
+ return state;
1844
+ }
1845
+ }
1846
+ function showColumns(state, { columns }) {
1847
+ if (columns.some((col) => col.hidden)) {
1848
+ return columns.reduce((s, c) => {
1849
+ if (c.hidden) {
1850
+ return updateColumnProp(s, {
1851
+ type: "updateColumnProp",
1852
+ column: c,
1853
+ hidden: false
1854
+ });
1855
+ } else {
1856
+ return s;
1857
+ }
1858
+ }, state);
1859
+ } else {
1860
+ return state;
1861
+ }
1862
+ }
1863
+ function resizeColumn(state, { column, phase, width }) {
1864
+ const type = "updateColumnProp";
1865
+ const resizing = phase !== "end";
1866
+ switch (phase) {
1867
+ case "begin":
1868
+ case "end":
1869
+ return updateColumnProp(state, { type, column, resizing });
1870
+ case "resize":
1871
+ return updateColumnProp(state, { type, column, width });
1872
+ default:
1873
+ throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
1874
+ }
1875
+ }
1876
+ function setTypes(state, { columnNames, serverDataTypes }) {
1877
+ const { columns } = state;
1878
+ if (columns.some(columnWithoutDataType)) {
1879
+ const cols = columns.map((column) => {
1880
+ var _a;
1881
+ const serverDataType = getDataType(column, columnNames, serverDataTypes);
1882
+ return {
1883
+ ...column,
1884
+ align: (_a = column.align) != null ? _a : getDefaultAlignment(serverDataType),
1885
+ serverDataType
1886
+ };
1887
+ });
1888
+ return {
1889
+ ...state,
1890
+ columns: cols
1891
+ };
1892
+ } else {
1893
+ return state;
1894
+ }
1895
+ }
1896
+ function pinColumn2(state, action) {
1897
+ let { columns } = state;
1898
+ const { column, pin } = action;
1899
+ const targetColumn = columns.find((col) => col.name === column.name);
1900
+ if (targetColumn) {
1901
+ columns = replaceColumn(columns, { ...targetColumn, pin });
1902
+ columns = (0, import_vuu_utils11.sortPinnedColumns)(columns);
1903
+ return {
1904
+ ...state,
1905
+ columns
1906
+ };
1907
+ } else {
1908
+ return state;
1909
+ }
1910
+ }
1911
+ function updateColumnProp(state, action) {
1912
+ let { columns } = state;
1913
+ const { align, column, hidden, label, resizing, width } = action;
1914
+ const targetColumn = columns.find((col) => col.name === column.name);
1915
+ if (targetColumn) {
1916
+ if (align === "left" || align === "right") {
1917
+ columns = replaceColumn(columns, { ...targetColumn, align });
1918
+ }
1919
+ if (typeof label === "string") {
1920
+ columns = replaceColumn(columns, { ...targetColumn, label });
1921
+ }
1922
+ if (typeof resizing === "boolean") {
1923
+ columns = replaceColumn(columns, { ...targetColumn, resizing });
1924
+ }
1925
+ if (typeof hidden === "boolean") {
1926
+ columns = replaceColumn(columns, { ...targetColumn, hidden });
1927
+ }
1928
+ if (typeof width === "number") {
1929
+ columns = replaceColumn(columns, { ...targetColumn, width });
1930
+ }
1931
+ }
1932
+ return {
1933
+ ...state,
1934
+ columns
1935
+ };
1936
+ }
1937
+ function updateTableConfig(state, { columns, confirmed, filter, groupBy, sort }) {
1938
+ const hasColumns = columns && columns.length > 0;
1939
+ const hasGroupBy = groupBy !== void 0;
1940
+ const hasFilter = typeof (filter == null ? void 0 : filter.filter) === "string";
1941
+ const hasSort = sort && sort.sortDefs.length > 0;
1942
+ let result = state;
1943
+ if (hasColumns) {
1944
+ result = {
1945
+ ...state,
1946
+ columns: columns.map((colName, index) => {
1947
+ const columnName = (0, import_vuu_utils11.getColumnName)(colName);
1948
+ const key = index + KEY_OFFSET;
1949
+ const col = (0, import_vuu_utils11.findColumn)(result.columns, columnName);
1950
+ if (col) {
1951
+ if (col.key === key) {
1952
+ return col;
1953
+ } else {
1954
+ return {
1955
+ ...col,
1956
+ key
1957
+ };
1958
+ }
1959
+ }
1960
+ throw Error(`useTableModel column ${colName} not found`);
1961
+ })
1962
+ };
1963
+ }
1964
+ if (hasGroupBy) {
1965
+ result = {
1966
+ ...state,
1967
+ columns: (0, import_vuu_utils11.applyGroupByToColumns)(result.columns, groupBy, confirmed)
1968
+ };
1969
+ }
1970
+ if (hasSort) {
1971
+ result = {
1972
+ ...state,
1973
+ columns: (0, import_vuu_utils11.applySortToColumns)(result.columns, sort)
1974
+ };
1975
+ }
1976
+ if (hasFilter) {
1977
+ result = {
1978
+ ...state,
1979
+ columns: (0, import_vuu_utils11.applyFilterToColumns)(result.columns, filter)
1980
+ };
1981
+ } else if (result.columns.some(import_vuu_utils11.isFilteredColumn)) {
1982
+ result = {
1983
+ ...state,
1984
+ columns: (0, import_vuu_utils11.stripFilterFromColumns)(result.columns)
1985
+ };
1986
+ }
1987
+ return result;
1988
+ }
1989
+ function replaceColumn(state, column) {
1990
+ return state.map((col) => col.name === column.name ? column : col);
1991
+ }
1992
+
1993
+ // src/useTableScroll.ts
1994
+ var import_react18 = require("react");
1995
+ var getPctScroll = (container) => {
1996
+ const { scrollLeft, scrollTop } = container;
1997
+ const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
1998
+ const pctScrollLeft = scrollLeft / (scrollWidth - clientWidth);
1999
+ const pctScrollTop = scrollTop / (scrollHeight - clientHeight);
2000
+ return [pctScrollLeft, pctScrollTop, scrollLeft, scrollTop];
2001
+ };
2002
+ var getMaxScroll = (container) => {
2003
+ const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
2004
+ return [scrollWidth - clientWidth, scrollHeight - clientHeight];
2005
+ };
2006
+ var useTableScroll = ({
2007
+ onHorizontalScroll,
2008
+ onVerticalScroll,
2009
+ viewport
2010
+ }) => {
2011
+ const scrollPosRef = (0, import_react18.useRef)({ scrollTop: 0, scrollLeft: 0 });
2012
+ const scrollbarContainerRef = (0, import_react18.useRef)(null);
2013
+ const contentContainerRef = (0, import_react18.useRef)(null);
2014
+ const tableContainerRef = (0, import_react18.useRef)(null);
2015
+ const contentContainerScrolledRef = (0, import_react18.useRef)(false);
2016
+ const {
2017
+ maxScrollContainerScrollHorizontal: maxScrollLeft,
2018
+ maxScrollContainerScrollVertical: maxScrollTop
2019
+ } = viewport;
2020
+ const scrollTable = (0, import_react18.useCallback)(
2021
+ (scrollLeft, scrollTop) => {
2022
+ const { current: tableContainer } = tableContainerRef;
2023
+ if (tableContainer) {
2024
+ tableContainer.scrollTo({
2025
+ top: scrollTop,
2026
+ left: scrollLeft,
2027
+ behavior: "auto"
2028
+ });
2029
+ }
2030
+ },
2031
+ [tableContainerRef]
2032
+ );
2033
+ const handleTableContainerScroll = (0, import_react18.useCallback)(() => {
2034
+ const { current: tableContainer } = tableContainerRef;
2035
+ if (tableContainer) {
2036
+ const { current: scrollPos } = scrollPosRef;
2037
+ const { scrollLeft, scrollTop } = tableContainer;
2038
+ if (scrollPos.scrollTop !== scrollTop) {
2039
+ scrollPos.scrollTop = scrollTop;
2040
+ onVerticalScroll == null ? void 0 : onVerticalScroll(scrollTop);
2041
+ }
2042
+ if (scrollPos.scrollLeft !== scrollLeft) {
2043
+ scrollPos.scrollLeft = scrollLeft;
2044
+ onHorizontalScroll == null ? void 0 : onHorizontalScroll(scrollLeft);
2045
+ }
2046
+ }
2047
+ }, [onHorizontalScroll, onVerticalScroll]);
2048
+ const handleContentContainerScroll = (0, import_react18.useCallback)(() => {
2049
+ const { current: rootContainer } = contentContainerRef;
2050
+ const { current: scrollContainer } = scrollbarContainerRef;
2051
+ if (rootContainer && scrollContainer) {
2052
+ const [pctScrollLeft, pctScrollTop, scrollLeft, scrollTop] = getPctScroll(rootContainer);
2053
+ contentContainerScrolledRef.current = true;
2054
+ scrollContainer.scrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
2055
+ scrollContainer.scrollTop = Math.round(pctScrollTop * maxScrollTop);
2056
+ scrollTable(scrollLeft, scrollTop);
2057
+ }
2058
+ }, [
2059
+ maxScrollLeft,
2060
+ maxScrollTop,
2061
+ contentContainerRef,
2062
+ scrollbarContainerRef,
2063
+ scrollTable
2064
+ ]);
2065
+ const handleScrollbarContainerScroll = (0, import_react18.useCallback)(() => {
2066
+ const { current: contentContainer } = contentContainerRef;
2067
+ const { current: scrollbarContainer } = scrollbarContainerRef;
2068
+ const { current: contentContainerScrolled } = contentContainerScrolledRef;
2069
+ if (contentContainerScrolled) {
2070
+ contentContainerScrolledRef.current = false;
2071
+ } else if (contentContainer && scrollbarContainer) {
2072
+ const [pctScrollLeft, pctScrollTop] = getPctScroll(scrollbarContainer);
2073
+ const [maxScrollLeft2, maxScrollTop2] = getMaxScroll(contentContainer);
2074
+ const rootScrollLeft = Math.round(pctScrollLeft * maxScrollLeft2);
2075
+ const rootScrollTop = Math.round(pctScrollTop * maxScrollTop2);
2076
+ contentContainer.scrollTo({
2077
+ left: rootScrollLeft,
2078
+ top: rootScrollTop,
2079
+ behavior: "auto"
2080
+ });
2081
+ scrollTable(rootScrollLeft, rootScrollTop);
2082
+ }
2083
+ }, [contentContainerRef, scrollbarContainerRef, scrollTable]);
2084
+ const requestScroll = (0, import_react18.useCallback)(
2085
+ (scrollRequest) => {
2086
+ const { current: scrollbarContainer } = scrollbarContainerRef;
2087
+ if (scrollbarContainer) {
2088
+ contentContainerScrolledRef.current = false;
2089
+ if (scrollRequest.type === "scroll-page") {
2090
+ const { clientHeight, scrollLeft, scrollTop } = scrollbarContainer;
2091
+ const { direction } = scrollRequest;
2092
+ const scrollBy = direction === "down" ? clientHeight : -clientHeight;
2093
+ const newScrollTop = Math.min(
2094
+ Math.max(0, scrollTop + scrollBy),
2095
+ viewport.maxScrollContainerScrollVertical
2096
+ );
2097
+ scrollbarContainer.scrollTo({
2098
+ top: newScrollTop,
2099
+ left: scrollLeft,
2100
+ behavior: "auto"
2101
+ });
2102
+ } else if (scrollRequest.type === "scroll-end") {
2103
+ const { direction } = scrollRequest;
2104
+ const scrollTo = direction === "end" ? viewport.maxScrollContainerScrollVertical : 0;
2105
+ scrollbarContainer.scrollTo({
2106
+ top: scrollTo,
2107
+ left: scrollbarContainer.scrollLeft,
2108
+ behavior: "auto"
2109
+ });
2110
+ }
2111
+ }
2112
+ },
2113
+ [viewport.maxScrollContainerScrollVertical]
2114
+ );
2115
+ return {
2116
+ /** Ref to be assigned to ScrollbarContainer */
2117
+ scrollbarContainerRef,
2118
+ /** Scroll handler to be attached to ScrollbarContainer */
2119
+ onScrollbarContainerScroll: handleScrollbarContainerScroll,
2120
+ /** Ref to be assigned to ContentContainer */
2121
+ contentContainerRef,
2122
+ /** Scroll handler to be attached to ContentContainer */
2123
+ onContentContainerScroll: handleContentContainerScroll,
2124
+ /** Ref to be assigned to TableContainer */
2125
+ tableContainerRef,
2126
+ /** Scroll handler to be attached to TableContainer */
2127
+ onTableContainerScroll: handleTableContainerScroll,
2128
+ /** Scroll the table */
2129
+ requestScroll
2130
+ };
2131
+ };
2132
+
2133
+ // src/useTableViewport.ts
2134
+ var import_react19 = require("react");
2135
+ var UNMEASURED_VIEWPORT = {
2136
+ fillerHeight: 0,
2137
+ maxScrollContainerScrollHorizontal: 0,
2138
+ maxScrollContainerScrollVertical: 0,
2139
+ pinnedWidthLeft: 0,
2140
+ pinnedWidthRight: 0,
2141
+ rowCount: 0,
2142
+ scrollContentHeight: 0,
2143
+ scrollbarSize: 0,
2144
+ scrollContentWidth: 0,
2145
+ totalHeaderHeight: 0
2146
+ };
2147
+ var measurePinnedColumns = (columns) => {
2148
+ let pinnedWidthLeft = 0;
2149
+ let pinnedWidthRight = 0;
2150
+ let unpinnedWidth = 0;
2151
+ for (const column of columns) {
2152
+ const { hidden, pin, width } = column;
2153
+ const visibleWidth = hidden ? 0 : width;
2154
+ if (pin === "left") {
2155
+ pinnedWidthLeft += visibleWidth;
2156
+ } else if (pin === "right") {
2157
+ pinnedWidthRight += visibleWidth;
2158
+ } else {
2159
+ unpinnedWidth += visibleWidth;
2160
+ }
2161
+ }
2162
+ return { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth };
2163
+ };
2164
+ var useTableViewport = ({
2165
+ columns,
2166
+ headerHeight,
2167
+ headings,
2168
+ rowCount,
2169
+ rowHeight,
2170
+ size
2171
+ }) => {
2172
+ const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = (0, import_react19.useMemo)(
2173
+ () => measurePinnedColumns(columns),
2174
+ [columns]
2175
+ );
2176
+ const viewportMeasurements = (0, import_react19.useMemo)(() => {
2177
+ var _a;
2178
+ if (size) {
2179
+ const headingsDepth = headings.length;
2180
+ const scrollbarSize = 15;
2181
+ const contentHeight = rowCount * rowHeight;
2182
+ const scrollContentWidth = pinnedWidthLeft + unpinnedWidth + pinnedWidthRight;
2183
+ const maxScrollContainerScrollVertical = contentHeight + headerHeight - (((_a = size == null ? void 0 : size.height) != null ? _a : 0) - headerHeight - scrollbarSize);
2184
+ const maxScrollContainerScrollHorizontal = scrollContentWidth - size.width + pinnedWidthLeft;
2185
+ const visibleRows = (size.height - headerHeight) / rowHeight;
2186
+ const count = Number.isInteger(visibleRows) ? visibleRows + 1 : Math.ceil(visibleRows);
2187
+ return {
2188
+ fillerHeight: (rowCount - count) * rowHeight,
2189
+ maxScrollContainerScrollHorizontal,
2190
+ maxScrollContainerScrollVertical,
2191
+ pinnedWidthLeft,
2192
+ pinnedWidthRight,
2193
+ rowCount: count,
2194
+ scrollContentHeight: headerHeight + contentHeight + scrollbarSize,
2195
+ scrollbarSize,
2196
+ scrollContentWidth,
2197
+ totalHeaderHeight: headerHeight * (1 + headingsDepth)
2198
+ };
2199
+ } else {
2200
+ return UNMEASURED_VIEWPORT;
2201
+ }
2202
+ }, [
2203
+ headerHeight,
2204
+ headings.length,
2205
+ pinnedWidthLeft,
2206
+ pinnedWidthRight,
2207
+ rowCount,
2208
+ rowHeight,
2209
+ size,
2210
+ unpinnedWidth
2211
+ ]);
2212
+ return viewportMeasurements;
2213
+ };
2214
+
2215
+ // src/useVirtualViewport.ts
2216
+ var import_vuu_utils12 = require("@vuu-ui/vuu-utils");
2217
+ var import_react20 = require("react");
2218
+ var useVirtualViewport = ({
2219
+ columns,
2220
+ rowHeight,
2221
+ setRange,
2222
+ viewportMeasurements
2223
+ }) => {
2224
+ const firstRowRef = (0, import_react20.useRef)(-1);
2225
+ const {
2226
+ rowCount: viewportRowCount,
2227
+ scrollContentWidth: contentWidth,
2228
+ maxScrollContainerScrollHorizontal
2229
+ } = viewportMeasurements;
2230
+ const availableWidth = contentWidth - maxScrollContainerScrollHorizontal;
2231
+ const scrollLeftRef = (0, import_react20.useRef)(0);
2232
+ const [visibleColumns, preSpan] = (0, import_react20.useMemo)(
2233
+ () => (0, import_vuu_utils12.getColumnsInViewport)(
2234
+ columns,
2235
+ scrollLeftRef.current,
2236
+ scrollLeftRef.current + availableWidth
2237
+ ),
2238
+ [availableWidth, columns]
2239
+ );
2240
+ const preSpanRef = (0, import_react20.useRef)(preSpan);
2241
+ (0, import_react20.useEffect)(() => {
2242
+ setColumnsWithinViewport(visibleColumns);
2243
+ }, [visibleColumns]);
2244
+ const [columnsWithinViewport, setColumnsWithinViewport] = (0, import_react20.useState)(visibleColumns);
2245
+ const handleHorizontalScroll = (0, import_react20.useCallback)(
2246
+ (scrollLeft) => {
2247
+ scrollLeftRef.current = scrollLeft;
2248
+ const [visibleColumns2, pre] = (0, import_vuu_utils12.getColumnsInViewport)(
2249
+ columns,
2250
+ scrollLeft,
2251
+ scrollLeft + availableWidth
2252
+ );
2253
+ if ((0, import_vuu_utils12.itemsChanged)(columnsWithinViewport, visibleColumns2)) {
2254
+ preSpanRef.current = pre;
2255
+ setColumnsWithinViewport(visibleColumns2);
2256
+ }
2257
+ },
2258
+ [availableWidth, columns, columnsWithinViewport]
2259
+ );
2260
+ const handleVerticalScroll = (0, import_react20.useCallback)(
2261
+ (scrollTop) => {
2262
+ const firstRow = Math.floor(scrollTop / rowHeight);
2263
+ if (firstRow !== firstRowRef.current) {
2264
+ firstRowRef.current = firstRow;
2265
+ setRange({ from: firstRow, to: firstRow + viewportRowCount });
2266
+ }
2267
+ },
2268
+ [rowHeight, setRange, viewportRowCount]
2269
+ );
2270
+ return {
2271
+ columnsWithinViewport,
2272
+ onHorizontalScroll: handleHorizontalScroll,
2273
+ onVerticalScroll: handleVerticalScroll,
2274
+ /** number of leading columns not rendered because of virtualization */
2275
+ virtualColSpan: preSpanRef.current
2276
+ };
2277
+ };
2278
+
2279
+ // src/useDataTable.ts
2280
+ var NO_ROWS = [];
2281
+ var { KEY: KEY2, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = import_vuu_utils13.metadataKeys;
2282
+ var useDataTable = ({
2283
+ config,
2284
+ dataSource,
2285
+ headerHeight,
2286
+ onConfigChange,
2287
+ onFeatureEnabled,
2288
+ onFeatureInvocation,
2289
+ onSelectionChange,
2290
+ renderBufferSize = 0,
2291
+ rowHeight,
2292
+ selectionModel,
2293
+ tableLayout,
2294
+ ...measuredProps
2295
+ }) => {
2296
+ var _a, _b;
2297
+ const [rowCount, setRowCount] = (0, import_react21.useState)(0);
2298
+ const expectConfigChangeRef = (0, import_react21.useRef)(false);
2299
+ const dataSourceRef = (0, import_react21.useRef)();
2300
+ dataSourceRef.current = dataSource;
2301
+ if (dataSource === void 0) {
2302
+ throw Error("no data source provided to DataTable");
2303
+ }
2304
+ const containerMeasurements = useMeasuredContainer(measuredProps);
2305
+ const onDataRowcountChange = (0, import_react21.useCallback)((size) => {
2306
+ setRowCount(size);
2307
+ }, []);
2308
+ const { columns, dispatchColumnAction, headings } = useTableModel(
2309
+ config,
2310
+ dataSource.config
2311
+ );
2312
+ const handlePersistentColumnOperation = (0, import_react21.useCallback)(
2313
+ (action) => {
2314
+ expectConfigChangeRef.current = true;
2315
+ dispatchColumnAction(action);
2316
+ },
2317
+ [dispatchColumnAction]
2318
+ );
2319
+ const handleContextMenuAction = useContextMenu3({
2320
+ dataSource,
2321
+ onPersistentColumnOperation: handlePersistentColumnOperation
2322
+ });
2323
+ const viewportMeasurements = useTableViewport({
2324
+ columns,
2325
+ headerHeight,
2326
+ headings,
2327
+ rowCount,
2328
+ rowHeight,
2329
+ size: containerMeasurements.innerSize
2330
+ });
2331
+ const onSubscribed = (0, import_react21.useCallback)(
2332
+ (subscription) => {
2333
+ if (subscription.tableMeta) {
2334
+ const { columns: columnNames, dataTypes: serverDataTypes } = subscription.tableMeta;
2335
+ expectConfigChangeRef.current = true;
2336
+ dispatchColumnAction({
2337
+ type: "setTypes",
2338
+ columnNames,
2339
+ serverDataTypes
2340
+ });
2341
+ }
2342
+ },
2343
+ [dispatchColumnAction]
2344
+ );
2345
+ const handleSelectionChange = (0, import_react21.useCallback)(
2346
+ (selected) => {
2347
+ dataSource.select(selected);
2348
+ onSelectionChange == null ? void 0 : onSelectionChange(selected);
2349
+ },
2350
+ [dataSource, onSelectionChange]
2351
+ );
2352
+ const handleRowClick = useSelection({
2353
+ onSelectionChange: handleSelectionChange,
2354
+ selectionModel
2355
+ });
2356
+ const { data, getSelectedRows, range, setRange } = useDataSource({
2357
+ dataSource,
2358
+ onFeatureEnabled,
2359
+ onFeatureInvocation,
2360
+ onSubscribed,
2361
+ onSizeChange: onDataRowcountChange,
2362
+ renderBufferSize,
2363
+ viewportRowCount: viewportMeasurements.rowCount
2364
+ });
2365
+ const dataRef = (0, import_react21.useRef)();
2366
+ dataRef.current = data;
2367
+ const handleSort = (0, import_react21.useCallback)(
2368
+ (column, extendSort = false, sortType) => {
2369
+ if (dataSource) {
2370
+ dataSource.sort = (0, import_vuu_utils13.applySort)(
2371
+ dataSource.sort,
2372
+ column,
2373
+ extendSort,
2374
+ sortType
2375
+ );
2376
+ }
2377
+ },
2378
+ [dataSource]
2379
+ );
2380
+ const handleColumnResize = (0, import_react21.useCallback)(
2381
+ (phase, columnName, width) => {
2382
+ const column = columns.find((column2) => column2.name === columnName);
2383
+ if (column) {
2384
+ if (phase === "end") {
2385
+ expectConfigChangeRef.current = true;
2386
+ }
2387
+ dispatchColumnAction({
2388
+ type: "resizeColumn",
2389
+ phase,
2390
+ column,
2391
+ width
2392
+ });
2393
+ } else {
2394
+ throw Error(
2395
+ `useDataTable.handleColumnResize, column ${columnName} not found`
2396
+ );
2397
+ }
2398
+ },
2399
+ [columns, dispatchColumnAction]
2400
+ );
2401
+ const handleToggleGroup = (0, import_react21.useCallback)(
2402
+ (row, column) => {
2403
+ const isJson = (0, import_vuu_utils13.isJsonGroup)(column, row);
2404
+ const key = row[KEY2];
2405
+ if (row[IS_EXPANDED2]) {
2406
+ dataSource.closeTreeNode(key, true);
2407
+ if (isJson) {
2408
+ const idx = columns.indexOf(column);
2409
+ const rows = dataSource.getRowsAtDepth(idx + 1);
2410
+ if (!rows.some((row2) => row2[IS_EXPANDED2] || row2[IS_LEAF2])) {
2411
+ dispatchColumnAction({
2412
+ type: "hideColumns",
2413
+ columns: columns.slice(idx + 2)
2414
+ });
2415
+ }
2416
+ }
2417
+ } else {
2418
+ dataSource.openTreeNode(key);
2419
+ if (isJson) {
2420
+ const childRows = dataSource.getChildRows(key);
2421
+ const idx = columns.indexOf(column) + 1;
2422
+ const columnsToShow = [columns[idx]];
2423
+ if (childRows.some((row2) => row2[IS_LEAF2])) {
2424
+ columnsToShow.push(columns[idx + 1]);
2425
+ }
2426
+ if (columnsToShow.some((col) => col.hidden)) {
2427
+ dispatchColumnAction({
2428
+ type: "showColumns",
2429
+ columns: columnsToShow
2430
+ });
2431
+ }
2432
+ }
2433
+ }
2434
+ },
2435
+ [columns, dataSource, dispatchColumnAction]
2436
+ );
2437
+ const {
2438
+ onVerticalScroll,
2439
+ onHorizontalScroll,
2440
+ columnsWithinViewport,
2441
+ virtualColSpan
2442
+ } = useVirtualViewport({
2443
+ columns,
2444
+ rowHeight,
2445
+ setRange,
2446
+ viewportMeasurements
2447
+ });
2448
+ const { requestScroll, ...scrollProps } = useTableScroll({
2449
+ onHorizontalScroll,
2450
+ // onRangeChange: setRange,
2451
+ onVerticalScroll,
2452
+ viewport: viewportMeasurements,
2453
+ viewportHeight: ((_b = (_a = containerMeasurements.innerSize) == null ? void 0 : _a.height) != null ? _b : 0) - headerHeight
2454
+ });
2455
+ const containerProps = useKeyboardNavigation({
2456
+ columnCount: columns.length,
2457
+ containerRef: containerMeasurements.containerRef,
2458
+ data,
2459
+ requestScroll,
2460
+ rowCount: dataSource == null ? void 0 : dataSource.size,
2461
+ viewportRange: range
2462
+ });
2463
+ const handleRemoveColumnFromGroupBy = (0, import_react21.useCallback)(
2464
+ (column) => {
2465
+ if (dataSource && dataSource.groupBy.includes(column.name)) {
2466
+ dataSource.groupBy = dataSource.groupBy.filter(
2467
+ (columnName) => columnName !== column.name
2468
+ );
2469
+ }
2470
+ },
2471
+ [dataSource]
2472
+ );
2473
+ const handleDropColumn = (0, import_react21.useCallback)(
2474
+ (fromIndex, toIndex) => {
2475
+ const column = dataSource.columns[fromIndex];
2476
+ const columns2 = (0, import_vuu_utils13.moveItem)(dataSource.columns, column, toIndex);
2477
+ if (columns2 !== dataSource.columns) {
2478
+ dataSource.columns = columns2;
2479
+ dispatchColumnAction({ type: "tableConfig", columns: columns2 });
2480
+ }
2481
+ },
2482
+ [dataSource, dispatchColumnAction]
2483
+ );
2484
+ const draggableHook = useDraggableColumn({
2485
+ onDrop: handleDropColumn,
2486
+ tableContainerRef: scrollProps.tableContainerRef,
2487
+ tableLayout
2488
+ });
2489
+ (0, import_react21.useEffect)(() => {
2490
+ if (dataSourceRef.current) {
2491
+ expectConfigChangeRef.current = true;
2492
+ dispatchColumnAction({
2493
+ type: "init",
2494
+ tableConfig: config,
2495
+ dataSourceConfig: dataSourceRef.current.config
2496
+ });
2497
+ }
2498
+ }, [config, dispatchColumnAction]);
2499
+ (0, import_react21.useEffect)(() => {
2500
+ dataSource.on("config", (config2, confirmed) => {
2501
+ expectConfigChangeRef.current = true;
2502
+ dispatchColumnAction({
2503
+ type: "tableConfig",
2504
+ ...config2,
2505
+ confirmed
2506
+ });
2507
+ });
2508
+ }, [dataSource, dispatchColumnAction]);
2509
+ (0, import_react21.useMemo)(() => {
2510
+ if (expectConfigChangeRef.current) {
2511
+ onConfigChange == null ? void 0 : onConfigChange({
2512
+ ...config,
2513
+ columns
2514
+ });
2515
+ expectConfigChangeRef.current = false;
2516
+ }
2517
+ }, [columns, config, onConfigChange]);
2518
+ const showContextMenu = (0, import_vuu_popups3.useContextMenu)();
2519
+ const onContextMenu = (0, import_react21.useCallback)(
2520
+ (evt) => {
2521
+ var _a2;
2522
+ const { current: currentData } = dataRef;
2523
+ const { current: currentDataSource } = dataSourceRef;
2524
+ const target = evt.target;
2525
+ const cellEl = target == null ? void 0 : target.closest("td");
2526
+ const rowEl = target == null ? void 0 : target.closest("tr");
2527
+ if (cellEl && rowEl && currentData && currentDataSource) {
2528
+ const { columns: columns2, selectedRowsCount } = currentDataSource;
2529
+ const columnMap = (0, import_vuu_utils13.buildColumnMap)(columns2);
2530
+ const rowIndex = parseInt((_a2 = rowEl.ariaRowIndex) != null ? _a2 : "-1");
2531
+ const cellIndex = Array.from(rowEl.childNodes).indexOf(cellEl);
2532
+ const row = currentData.find(([idx]) => idx === rowIndex);
2533
+ const columnName = columns2[cellIndex];
2534
+ showContextMenu(evt, "grid", {
2535
+ columnMap,
2536
+ columnName,
2537
+ row,
2538
+ selectedRows: selectedRowsCount === 0 ? NO_ROWS : getSelectedRows(),
2539
+ viewport: dataSource == null ? void 0 : dataSource.viewport
2540
+ });
2541
+ }
2542
+ },
2543
+ [dataSource == null ? void 0 : dataSource.viewport, getSelectedRows, showContextMenu]
2544
+ );
2545
+ return {
2546
+ containerMeasurements,
2547
+ containerProps,
2548
+ columns,
2549
+ columnsWithinViewport,
2550
+ data,
2551
+ dispatchColumnAction,
2552
+ handleContextMenuAction,
2553
+ headings,
2554
+ onColumnResize: handleColumnResize,
2555
+ onContextMenu,
2556
+ onRemoveColumnFromGroupBy: handleRemoveColumnFromGroupBy,
2557
+ onRowClick: handleRowClick,
2558
+ onSort: handleSort,
2559
+ onToggleGroup: handleToggleGroup,
2560
+ virtualColSpan,
2561
+ scrollProps,
2562
+ rowCount,
2563
+ viewportMeasurements,
2564
+ ...draggableHook
2565
+ };
2566
+ };
2567
+
2568
+ // src/Table.tsx
2569
+ var import_classnames8 = __toESM(require("classnames"));
2570
+ var import_vuu_utils14 = require("@vuu-ui/vuu-utils");
2571
+ var import_jsx_runtime11 = require("react/jsx-runtime");
2572
+ var classBase7 = "vuuTable";
2573
+ var Table = ({
2574
+ allowConfigEditing: showSettings = false,
2575
+ className: classNameProp,
2576
+ config,
2577
+ dataSource,
2578
+ headerHeight = 25,
2579
+ height,
2580
+ id: idProp,
2581
+ onConfigChange,
2582
+ onFeatureEnabled,
2583
+ onFeatureInvocation,
2584
+ onSelectionChange,
2585
+ onShowConfigEditor: onShowSettings,
2586
+ renderBufferSize = 0,
2587
+ rowHeight = 20,
2588
+ selectionModel = "extended",
2589
+ style: styleProp,
2590
+ tableLayout: tableLayoutProp = "row",
2591
+ width,
2592
+ zebraStripes = false,
2593
+ ...props
2594
+ }) => {
2595
+ const id = (0, import_core.useIdMemo)(idProp);
2596
+ const {
2597
+ containerMeasurements: { containerRef, innerSize, outerSize },
2598
+ containerProps,
2599
+ dispatchColumnAction,
2600
+ draggable,
2601
+ draggedItemIndex,
2602
+ handleContextMenuAction,
2603
+ scrollProps,
2604
+ tableLayout,
2605
+ viewportMeasurements,
2606
+ ...tableProps
2607
+ } = useDataTable({
2608
+ config,
2609
+ dataSource,
2610
+ renderBufferSize,
2611
+ headerHeight,
2612
+ height,
2613
+ onConfigChange,
2614
+ onFeatureEnabled,
2615
+ onFeatureInvocation,
2616
+ onSelectionChange,
2617
+ rowHeight,
2618
+ selectionModel,
2619
+ tableLayout: tableLayoutProp,
2620
+ width
2621
+ });
2622
+ const style = {
2623
+ ...outerSize,
2624
+ "--content-height": `${viewportMeasurements.scrollContentHeight}px`,
2625
+ "--content-width": `${viewportMeasurements.scrollContentWidth}px`,
2626
+ "--filler-height": `${viewportMeasurements.fillerHeight}px`,
2627
+ "--pinned-width-left": `${viewportMeasurements.pinnedWidthLeft}px`,
2628
+ "--pinned-width-right": `${viewportMeasurements.pinnedWidthRight}px`,
2629
+ "--header-height": `${headerHeight}px`,
2630
+ "--row-height": `${rowHeight}px`,
2631
+ "--scrollbar-size": `${viewportMeasurements.scrollbarSize}px`,
2632
+ "--table-height": `${innerSize == null ? void 0 : innerSize.height}px`,
2633
+ "--table-width": `${innerSize == null ? void 0 : innerSize.width}px`,
2634
+ "--total-header-height": `${viewportMeasurements == null ? void 0 : viewportMeasurements.totalHeaderHeight}px`
2635
+ };
2636
+ const scrollbarContainerStyle = {
2637
+ left: viewportMeasurements.pinnedWidthLeft - 1,
2638
+ // The -1 is to align the top border, might cause innaccuracy
2639
+ // It is compensated by a hardcoded adjustment in css
2640
+ // top: measurements.top - 1 + headerHeight,
2641
+ top: (viewportMeasurements == null ? void 0 : viewportMeasurements.totalHeaderHeight) - 1
2642
+ };
2643
+ const Table2 = tableLayout === "column" ? ColumnBasedTable : RowBasedTable;
2644
+ const className = (0, import_classnames8.default)(classBase7, classNameProp, {
2645
+ [`${classBase7}-zebra`]: zebraStripes,
2646
+ [`${classBase7}-loading`]: (0, import_vuu_utils14.isDataLoading)(tableProps.columns)
2647
+ });
2648
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2649
+ import_vuu_popups4.ContextMenuProvider,
2650
+ {
2651
+ menuActionHandler: handleContextMenuAction,
2652
+ menuBuilder: buildContextMenuDescriptors(dataSource),
2653
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2654
+ "div",
2655
+ {
2656
+ ...containerProps,
2657
+ className,
2658
+ id,
2659
+ ref: containerRef,
2660
+ style,
2661
+ tabIndex: -1,
2662
+ children: [
2663
+ innerSize ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2664
+ "div",
2665
+ {
2666
+ className: `${classBase7}-scrollbarContainer`,
2667
+ onScroll: scrollProps.onScrollbarContainerScroll,
2668
+ ref: scrollProps.scrollbarContainerRef,
2669
+ style: scrollbarContainerStyle,
2670
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: `${classBase7}-scrollContent` })
2671
+ }
2672
+ ) : null,
2673
+ innerSize ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2674
+ "div",
2675
+ {
2676
+ className: `${classBase7}-contentContainer`,
2677
+ onScroll: scrollProps.onContentContainerScroll,
2678
+ ref: scrollProps.contentContainerRef,
2679
+ ...props,
2680
+ children: [
2681
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: `${classBase7}-scrollContent` }),
2682
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2683
+ "div",
2684
+ {
2685
+ className: `${classBase7}-tableContainer`,
2686
+ onScroll: scrollProps.onTableContainerScroll,
2687
+ ref: scrollProps.tableContainerRef,
2688
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2689
+ Table2,
2690
+ {
2691
+ ...tableProps,
2692
+ headerHeight,
2693
+ rowHeight
2694
+ }
2695
+ )
2696
+ }
2697
+ ),
2698
+ draggable
2699
+ ]
2700
+ }
2701
+ ) : null,
2702
+ showSettings && innerSize ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2703
+ import_core.Button,
2704
+ {
2705
+ className: `${classBase7}-settings`,
2706
+ "data-icon": "settings",
2707
+ onClick: onShowSettings,
2708
+ variant: "secondary"
2709
+ }
2710
+ ) : null
2711
+ ]
2712
+ }
2713
+ )
2714
+ }
2715
+ );
2716
+ };
2717
+
2718
+ // src/cell-renderers/json-cell/JsonCell.tsx
2719
+ var import_classnames9 = __toESM(require("classnames"));
2720
+ var import_vuu_utils15 = require("@vuu-ui/vuu-utils");
2721
+ var import_jsx_runtime12 = require("react/jsx-runtime");
2722
+ var classBase8 = "vuuJsonCell";
2723
+ var { IS_EXPANDED: IS_EXPANDED3, KEY: KEY3 } = import_vuu_utils15.metadataKeys;
2724
+ var localKey = (key) => {
2725
+ const pos = key.lastIndexOf("|");
2726
+ if (pos === -1) {
2727
+ return "";
2728
+ } else {
2729
+ return key.slice(pos + 1);
2730
+ }
2731
+ };
2732
+ var JsonCell = ({ column, row }) => {
2733
+ const {
2734
+ key: columnKey
2735
+ /*, type, valueFormatter */
2736
+ } = column;
2737
+ let value = row[columnKey];
2738
+ let isToggle = false;
2739
+ if ((0, import_vuu_utils15.isJsonAttribute)(value)) {
2740
+ value = value.slice(0, -1);
2741
+ isToggle = true;
2742
+ }
2743
+ const rowKey = localKey(row[KEY3]);
2744
+ const className = (0, import_classnames9.default)({
2745
+ [`${classBase8}-name`]: rowKey === value,
2746
+ [`${classBase8}-value`]: rowKey !== value,
2747
+ [`${classBase8}-group`]: isToggle
2748
+ });
2749
+ if (isToggle) {
2750
+ const toggleIcon = row[IS_EXPANDED3] ? "minus-box" : "plus-box";
2751
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className, children: [
2752
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: `${classBase8}-value`, children: value }),
2753
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: `${classBase8}-toggle`, "data-icon": toggleIcon })
2754
+ ] });
2755
+ } else if (value) {
2756
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className, children: value });
2757
+ } else {
2758
+ return null;
2759
+ }
2760
+ };
2761
+ (0, import_vuu_utils15.registerComponent)("json", JsonCell, "cell-renderer", {});
2
2762
  //# sourceMappingURL=index.js.map