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