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