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