@vuu-ui/vuu-table-extras 0.8.10-debug → 0.8.11-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/esm/index.js CHANGED
@@ -2800,6 +2800,233 @@ import { jsx as jsx11 } from "react/jsx-runtime";
2800
2800
 
2801
2801
  // ../vuu-table/src/table/context-menu/buildContextMenuDescriptors.ts
2802
2802
  import { isNumericColumn as isNumericColumn2 } from "@vuu-ui/vuu-utils";
2803
+ var buildContextMenuDescriptors = (dataSource) => (location, options) => {
2804
+ const descriptors = [];
2805
+ if (dataSource === void 0) {
2806
+ return descriptors;
2807
+ }
2808
+ if (location === "header" || location === "column-menu") {
2809
+ descriptors.push(
2810
+ ...buildSortMenuItems(options, dataSource)
2811
+ );
2812
+ descriptors.push(
2813
+ ...buildGroupMenuItems(options, dataSource)
2814
+ );
2815
+ descriptors.push(
2816
+ ...buildAggregationMenuItems(options, dataSource)
2817
+ );
2818
+ descriptors.push(...buildColumnDisplayMenuItems(options));
2819
+ descriptors.push({
2820
+ action: "column-settings",
2821
+ icon: "cog",
2822
+ label: `Column Settings`,
2823
+ options
2824
+ });
2825
+ descriptors.push({
2826
+ action: "table-settings",
2827
+ icon: "cog",
2828
+ label: `DataGrid Settings`,
2829
+ options
2830
+ });
2831
+ } else if (location === "filter") {
2832
+ const { column, filter } = options;
2833
+ const colIsOnlyFilter = (filter == null ? void 0 : filter.column) === (column == null ? void 0 : column.name);
2834
+ descriptors.push({
2835
+ label: "Edit filter",
2836
+ action: "filter-edit",
2837
+ options
2838
+ });
2839
+ descriptors.push({
2840
+ label: "Remove filter",
2841
+ action: "filter-remove-column",
2842
+ options
2843
+ });
2844
+ if (column && !colIsOnlyFilter) {
2845
+ descriptors.push({
2846
+ label: `Remove all filters`,
2847
+ action: "remove-filters",
2848
+ options
2849
+ });
2850
+ }
2851
+ }
2852
+ return descriptors;
2853
+ };
2854
+ function buildSortMenuItems(options, { sort: { sortDefs } }) {
2855
+ const { column } = options;
2856
+ const menuItems = [];
2857
+ if (column === void 0) {
2858
+ return menuItems;
2859
+ }
2860
+ const hasSort = sortDefs.length > 0;
2861
+ if (column.sorted === "A") {
2862
+ menuItems.push({
2863
+ label: "Reverse Sort (DSC)",
2864
+ action: "sort-dsc",
2865
+ options
2866
+ });
2867
+ } else if (column.sorted === "D") {
2868
+ menuItems.push({
2869
+ label: "Reverse Sort (ASC)",
2870
+ action: "sort-asc",
2871
+ options
2872
+ });
2873
+ } else if (typeof column.sorted === "number") {
2874
+ if (column.sorted > 0) {
2875
+ menuItems.push({
2876
+ label: "Reverse Sort (DSC)",
2877
+ action: "sort-add-dsc",
2878
+ options
2879
+ });
2880
+ } else {
2881
+ menuItems.push({
2882
+ label: "Reverse Sort (ASC)",
2883
+ action: "sort-add-asc",
2884
+ options
2885
+ });
2886
+ }
2887
+ if (hasSort && Math.abs(column.sorted) < sortDefs.length) {
2888
+ menuItems.push({
2889
+ label: "Remove from sort",
2890
+ action: "sort-remove",
2891
+ options
2892
+ });
2893
+ }
2894
+ menuItems.push({
2895
+ label: "New Sort",
2896
+ children: [
2897
+ { label: "Ascending", action: "sort-asc", options },
2898
+ { label: "Descending", action: "sort-dsc", options }
2899
+ ]
2900
+ });
2901
+ } else if (hasSort) {
2902
+ menuItems.push({
2903
+ label: "Add to sort",
2904
+ children: [
2905
+ { label: "Ascending", action: "sort-add-asc", options },
2906
+ { label: "Descending", action: "sort-add-dsc", options }
2907
+ ]
2908
+ });
2909
+ menuItems.push({
2910
+ label: "New Sort",
2911
+ children: [
2912
+ { label: "Ascending", action: "sort-asc", options },
2913
+ { label: "Descending", action: "sort-dsc", options }
2914
+ ]
2915
+ });
2916
+ } else {
2917
+ menuItems.push({
2918
+ label: "Sort",
2919
+ children: [
2920
+ { label: "Ascending", action: "sort-asc", options },
2921
+ { label: "Descending", action: "sort-dsc", options }
2922
+ ]
2923
+ });
2924
+ }
2925
+ return menuItems;
2926
+ }
2927
+ function buildAggregationMenuItems(options, dataSource) {
2928
+ const { column } = options;
2929
+ if (column === void 0 || dataSource.groupBy.length === 0) {
2930
+ return [];
2931
+ }
2932
+ const { name: name2, label = name2 } = column;
2933
+ return [
2934
+ {
2935
+ label: `Aggregate ${label}`,
2936
+ children: [
2937
+ { label: "Count", action: "agg-count", options },
2938
+ { label: "Distinct", action: "agg-distinct", options }
2939
+ ].concat(
2940
+ isNumericColumn2(column) ? [
2941
+ { label: "Sum", action: "agg-sum", options },
2942
+ { label: "Avg", action: "agg-avg", options },
2943
+ { label: "High", action: "agg-high", options },
2944
+ { label: "Low", action: "agg-low", options }
2945
+ ] : []
2946
+ )
2947
+ }
2948
+ ];
2949
+ }
2950
+ var pinColumn = (options, pinLocation) => ({
2951
+ label: `Pin ${pinLocation}`,
2952
+ action: `column-pin-${pinLocation}`,
2953
+ options
2954
+ });
2955
+ var pinLeft = (options) => pinColumn(options, "left");
2956
+ var pinFloating = (options) => pinColumn(options, "floating");
2957
+ var pinRight = (options) => pinColumn(options, "right");
2958
+ function buildColumnDisplayMenuItems(options) {
2959
+ const { column } = options;
2960
+ if (column === void 0) {
2961
+ return [];
2962
+ }
2963
+ const { pin } = column;
2964
+ const menuItems = [
2965
+ {
2966
+ label: `Hide column`,
2967
+ action: "column-hide",
2968
+ options
2969
+ },
2970
+ {
2971
+ label: `Remove column`,
2972
+ action: "column-remove",
2973
+ options
2974
+ }
2975
+ ];
2976
+ if (pin === void 0) {
2977
+ menuItems.push({
2978
+ label: `Pin column`,
2979
+ children: [pinLeft(options), pinFloating(options), pinRight(options)]
2980
+ });
2981
+ } else if (pin === "left") {
2982
+ menuItems.push(
2983
+ { label: "Unpin column", action: "column-unpin", options },
2984
+ {
2985
+ label: `Pin column`,
2986
+ children: [pinFloating(options), pinRight(options)]
2987
+ }
2988
+ );
2989
+ } else if (pin === "right") {
2990
+ menuItems.push(
2991
+ { label: "Unpin column", action: "column-unpin", options },
2992
+ {
2993
+ label: `Pin column`,
2994
+ children: [pinLeft(options), pinFloating(options)]
2995
+ }
2996
+ );
2997
+ } else if (pin === "floating") {
2998
+ menuItems.push(
2999
+ { label: "Unpin column", action: "column-unpin", options },
3000
+ {
3001
+ label: `Pin column`,
3002
+ children: [pinLeft(options), pinRight(options)]
3003
+ }
3004
+ );
3005
+ }
3006
+ return menuItems;
3007
+ }
3008
+ function buildGroupMenuItems(options, { groupBy }) {
3009
+ const { column } = options;
3010
+ const menuItems = [];
3011
+ if (column === void 0) {
3012
+ return menuItems;
3013
+ }
3014
+ const { name: name2, label = name2 } = column;
3015
+ if (groupBy.length === 0) {
3016
+ menuItems.push({
3017
+ label: `Group by ${label}`,
3018
+ action: "group",
3019
+ options
3020
+ });
3021
+ } else {
3022
+ menuItems.push({
3023
+ label: `Add ${label} to group by`,
3024
+ action: "group-add",
3025
+ options
3026
+ });
3027
+ }
3028
+ return menuItems;
3029
+ }
2803
3030
 
2804
3031
  // ../vuu-table/src/table/context-menu/useTableContextMenu.ts
2805
3032
  import { removeColumnFromFilter } from "@vuu-ui/vuu-utils";
@@ -2810,7 +3037,81 @@ import {
2810
3037
  setAggregations,
2811
3038
  setSortColumn
2812
3039
  } from "@vuu-ui/vuu-utils";
3040
+ var removeFilterColumn = (dataSourceFilter, column) => {
3041
+ if (dataSourceFilter.filterStruct && column) {
3042
+ const [filterStruct, filter] = removeColumnFromFilter(
3043
+ column,
3044
+ dataSourceFilter.filterStruct
3045
+ );
3046
+ return {
3047
+ filter,
3048
+ filterStruct
3049
+ };
3050
+ } else {
3051
+ return dataSourceFilter;
3052
+ }
3053
+ };
2813
3054
  var { Average, Count, Distinct, High, Low, Sum } = AggregationType;
3055
+ var useTableContextMenu = ({
3056
+ dataSource,
3057
+ onPersistentColumnOperation
3058
+ }) => {
3059
+ const handleContextMenuAction = (action) => {
3060
+ const gridOptions = action.options;
3061
+ if (gridOptions.column && dataSource) {
3062
+ const { column } = gridOptions;
3063
+ switch (action.menuId) {
3064
+ case "sort-asc":
3065
+ return dataSource.sort = setSortColumn(dataSource.sort, column, "A"), true;
3066
+ case "sort-dsc":
3067
+ return dataSource.sort = setSortColumn(dataSource.sort, column, "D"), true;
3068
+ case "sort-add-asc":
3069
+ return dataSource.sort = addSortColumn(dataSource.sort, column, "A"), true;
3070
+ case "sort-add-dsc":
3071
+ return dataSource.sort = addSortColumn(dataSource.sort, column, "D"), true;
3072
+ case "group":
3073
+ return dataSource.groupBy = addGroupColumn(dataSource.groupBy, column), true;
3074
+ case "group-add":
3075
+ return dataSource.groupBy = addGroupColumn(dataSource.groupBy, column), true;
3076
+ case "column-hide":
3077
+ return onPersistentColumnOperation({ type: "hideColumns", columns: [column] }), true;
3078
+ case "column-remove":
3079
+ return dataSource.columns = dataSource.columns.filter((name2) => name2 !== column.name), true;
3080
+ case "filter-remove-column":
3081
+ return dataSource.filter = removeFilterColumn(dataSource.filter, column), true;
3082
+ case "remove-filters":
3083
+ return dataSource.filter = { filter: "" }, true;
3084
+ case "agg-avg":
3085
+ return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Average), true;
3086
+ case "agg-high":
3087
+ return dataSource.aggregations = setAggregations(dataSource.aggregations, column, High), true;
3088
+ case "agg-low":
3089
+ return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Low), true;
3090
+ case "agg-count":
3091
+ return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Count), true;
3092
+ case "agg-distinct":
3093
+ return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Distinct), true;
3094
+ case "agg-sum":
3095
+ return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Sum), true;
3096
+ case "column-pin-floating":
3097
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "floating" }), true;
3098
+ case "column-pin-left":
3099
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "left" }), true;
3100
+ case "column-pin-right":
3101
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "right" }), true;
3102
+ case "column-unpin":
3103
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: void 0 }), true;
3104
+ case "column-settings":
3105
+ return onPersistentColumnOperation({ type: "columnSettings", column }), true;
3106
+ case "table-settings":
3107
+ return onPersistentColumnOperation({ type: "tableSettings" }), true;
3108
+ default:
3109
+ }
3110
+ }
3111
+ return false;
3112
+ };
3113
+ return handleContextMenuAction;
3114
+ };
2814
3115
 
2815
3116
  // ../vuu-table/src/table/Table.tsx
2816
3117
  import { ContextMenuProvider } from "@vuu-ui/vuu-popups";
@@ -3257,6 +3558,38 @@ import {
3257
3558
  } from "@vuu-ui/vuu-utils";
3258
3559
  import { useCallback as useCallback21, useRef as useRef18 } from "react";
3259
3560
  var { IDX: IDX2 } = metadataKeys8;
3561
+ var NO_SELECTION = [];
3562
+ var useSelection = ({
3563
+ selectionModel,
3564
+ onSelect,
3565
+ onSelectionChange
3566
+ }) => {
3567
+ selectionModel === "extended" || selectionModel === "checkbox";
3568
+ const lastActiveRef = useRef18(-1);
3569
+ const selectedRef = useRef18(NO_SELECTION);
3570
+ const handleSelectionChange = useCallback21(
3571
+ (row, rangeSelect, keepExistingSelection) => {
3572
+ const { [IDX2]: idx } = row;
3573
+ const { current: active } = lastActiveRef;
3574
+ const { current: selected } = selectedRef;
3575
+ const selectOperation = isRowSelected(row) ? deselectItem : selectItem;
3576
+ const newSelected = selectOperation(
3577
+ selectionModel,
3578
+ selected,
3579
+ idx,
3580
+ rangeSelect,
3581
+ keepExistingSelection,
3582
+ active
3583
+ );
3584
+ selectedRef.current = newSelected;
3585
+ lastActiveRef.current = idx;
3586
+ onSelect == null ? void 0 : onSelect(row);
3587
+ onSelectionChange == null ? void 0 : onSelectionChange(newSelected);
3588
+ },
3589
+ [onSelect, onSelectionChange, selectionModel]
3590
+ );
3591
+ return handleSelectionChange;
3592
+ };
3260
3593
 
3261
3594
  // ../vuu-table/src/table/useTableModel.ts
3262
3595
  import {
@@ -3291,6 +3624,126 @@ import {
3291
3624
  actualRowPositioning,
3292
3625
  virtualRowPositioning
3293
3626
  } from "@vuu-ui/vuu-utils";
3627
+ var MAX_RAW_ROWS = 15e5;
3628
+ var UNMEASURED_VIEWPORT = {
3629
+ contentHeight: 0,
3630
+ contentWidth: 0,
3631
+ getRowAtPosition: () => -1,
3632
+ getRowOffset: () => -1,
3633
+ horizontalScrollbarHeight: 0,
3634
+ maxScrollContainerScrollHorizontal: 0,
3635
+ maxScrollContainerScrollVertical: 0,
3636
+ pinnedWidthLeft: 0,
3637
+ pinnedWidthRight: 0,
3638
+ rowCount: 0,
3639
+ setPctScrollTop: () => void 0,
3640
+ totalHeaderHeight: 0,
3641
+ verticalScrollbarWidth: 0,
3642
+ viewportBodyHeight: 0
3643
+ };
3644
+ var measurePinnedColumns = (columns) => {
3645
+ let pinnedWidthLeft = 0;
3646
+ let pinnedWidthRight = 0;
3647
+ let unpinnedWidth = 0;
3648
+ for (const column of columns) {
3649
+ const { hidden, pin, width } = column;
3650
+ const visibleWidth = hidden ? 0 : width;
3651
+ if (pin === "left") {
3652
+ pinnedWidthLeft += visibleWidth;
3653
+ } else if (pin === "right") {
3654
+ pinnedWidthRight += visibleWidth;
3655
+ } else {
3656
+ unpinnedWidth += visibleWidth;
3657
+ }
3658
+ }
3659
+ return {
3660
+ pinnedWidthLeft: pinnedWidthLeft + 4,
3661
+ pinnedWidthRight: pinnedWidthRight + 4,
3662
+ unpinnedWidth
3663
+ };
3664
+ };
3665
+ var useTableViewport = ({
3666
+ columns,
3667
+ headerHeight,
3668
+ headings,
3669
+ rowCount,
3670
+ rowHeight,
3671
+ size
3672
+ }) => {
3673
+ const pctScrollTopRef = useRef20(0);
3674
+ const appliedRowCount = Math.min(rowCount, MAX_RAW_ROWS);
3675
+ const appliedContentHeight = appliedRowCount * rowHeight;
3676
+ const virtualContentHeight = rowCount * rowHeight;
3677
+ const virtualisedExtent = virtualContentHeight - appliedContentHeight;
3678
+ const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = useMemo8(
3679
+ () => measurePinnedColumns(columns),
3680
+ [columns]
3681
+ );
3682
+ const [actualRowOffset, actualRowAtPosition] = useMemo8(
3683
+ () => actualRowPositioning(rowHeight),
3684
+ [rowHeight]
3685
+ );
3686
+ const [getRowOffset, getRowAtPosition] = useMemo8(() => {
3687
+ if (virtualisedExtent) {
3688
+ return virtualRowPositioning(
3689
+ rowHeight,
3690
+ virtualisedExtent,
3691
+ pctScrollTopRef
3692
+ );
3693
+ } else {
3694
+ return [actualRowOffset, actualRowAtPosition];
3695
+ }
3696
+ }, [actualRowAtPosition, actualRowOffset, virtualisedExtent, rowHeight]);
3697
+ const setPctScrollTop = useCallback23((scrollPct) => {
3698
+ pctScrollTopRef.current = scrollPct;
3699
+ }, []);
3700
+ return useMemo8(() => {
3701
+ var _a;
3702
+ if (size) {
3703
+ const headingsDepth = headings.length;
3704
+ const scrollbarSize = 15;
3705
+ const contentWidth = pinnedWidthLeft + unpinnedWidth + pinnedWidthRight;
3706
+ const horizontalScrollbarHeight = contentWidth > size.width ? scrollbarSize : 0;
3707
+ const totalHeaderHeight = headerHeight * (1 + headingsDepth);
3708
+ const maxScrollContainerScrollVertical = appliedContentHeight - (((_a = size == null ? void 0 : size.height) != null ? _a : 0) - horizontalScrollbarHeight) + totalHeaderHeight;
3709
+ const maxScrollContainerScrollHorizontal = contentWidth - size.width + pinnedWidthLeft;
3710
+ const visibleRows = (size.height - headerHeight) / rowHeight;
3711
+ const count = Number.isInteger(visibleRows) ? visibleRows + 1 : Math.ceil(visibleRows);
3712
+ const viewportBodyHeight = size.height - totalHeaderHeight;
3713
+ const verticalScrollbarWidth = appliedContentHeight > viewportBodyHeight ? scrollbarSize : 0;
3714
+ return {
3715
+ contentHeight: appliedContentHeight,
3716
+ getRowAtPosition,
3717
+ getRowOffset,
3718
+ horizontalScrollbarHeight,
3719
+ maxScrollContainerScrollHorizontal,
3720
+ maxScrollContainerScrollVertical,
3721
+ pinnedWidthLeft,
3722
+ pinnedWidthRight,
3723
+ rowCount: count,
3724
+ contentWidth,
3725
+ setPctScrollTop,
3726
+ totalHeaderHeight,
3727
+ verticalScrollbarWidth,
3728
+ viewportBodyHeight
3729
+ };
3730
+ } else {
3731
+ return UNMEASURED_VIEWPORT;
3732
+ }
3733
+ }, [
3734
+ size,
3735
+ headings.length,
3736
+ pinnedWidthLeft,
3737
+ unpinnedWidth,
3738
+ pinnedWidthRight,
3739
+ appliedContentHeight,
3740
+ headerHeight,
3741
+ rowHeight,
3742
+ getRowAtPosition,
3743
+ getRowOffset,
3744
+ setPctScrollTop
3745
+ ]);
3746
+ };
3294
3747
 
3295
3748
  // ../vuu-table/src/table/useVirtualViewport.ts
3296
3749
  import {
@@ -3354,6 +3807,7 @@ var JsonCell = ({ column, row }) => {
3354
3807
  return null;
3355
3808
  }
3356
3809
  };
3810
+ console.log("register JsonCell");
3357
3811
  registerComponent6("json", JsonCell, "cell-renderer", {
3358
3812
  description: "JSON formatter",
3359
3813
  label: "JSON formatter",
@@ -3367,44 +3821,199 @@ import { useRef as useRef25 } from "react";
3367
3821
  // ../vuu-table/src/table-next/column-resizing/ColumnResizer.tsx
3368
3822
  import { useCallback as useCallback26, useRef as useRef23 } from "react";
3369
3823
  import { jsx as jsx22 } from "react/jsx-runtime";
3824
+ var NOOP = () => void 0;
3825
+ var baseClass = "vuuColumnResizerNext";
3826
+ var ColumnResizer2 = ({
3827
+ onDrag,
3828
+ onDragEnd = NOOP,
3829
+ onDragStart = NOOP
3830
+ }) => {
3831
+ const position = useRef23(0);
3832
+ const onMouseMove = useCallback26(
3833
+ (e) => {
3834
+ if (e.stopPropagation) {
3835
+ e.stopPropagation();
3836
+ }
3837
+ if (e.preventDefault) {
3838
+ e.preventDefault();
3839
+ }
3840
+ const x = Math.round(e.clientX);
3841
+ const moveBy = x - position.current;
3842
+ position.current = x;
3843
+ if (moveBy !== 0) {
3844
+ onDrag(e, moveBy);
3845
+ }
3846
+ },
3847
+ [onDrag]
3848
+ );
3849
+ const onMouseUp = useCallback26(
3850
+ (e) => {
3851
+ window.removeEventListener("mouseup", onMouseUp);
3852
+ window.removeEventListener("mousemove", onMouseMove);
3853
+ onDragEnd(e);
3854
+ },
3855
+ [onDragEnd, onMouseMove]
3856
+ );
3857
+ const handleMouseDown = useCallback26(
3858
+ (e) => {
3859
+ onDragStart(e);
3860
+ position.current = Math.round(e.clientX);
3861
+ window.addEventListener("mouseup", onMouseUp);
3862
+ window.addEventListener("mousemove", onMouseMove);
3863
+ if (e.stopPropagation) {
3864
+ e.stopPropagation();
3865
+ }
3866
+ if (e.preventDefault) {
3867
+ e.preventDefault();
3868
+ }
3869
+ },
3870
+ [onDragStart, onMouseMove, onMouseUp]
3871
+ );
3872
+ return /* @__PURE__ */ jsx22("div", { className: baseClass, onMouseDown: handleMouseDown });
3873
+ };
3370
3874
 
3371
3875
  // ../vuu-table/src/table-next/column-resizing/useTableColumnResize.tsx
3372
3876
  import { useCallback as useCallback27, useRef as useRef24, useState as useState10 } from "react";
3877
+ var useTableColumnResize2 = ({
3878
+ column,
3879
+ onResize,
3880
+ rootRef
3881
+ }) => {
3882
+ const widthRef = useRef24(0);
3883
+ const [isResizing, setResizing] = useState10(false);
3884
+ const { name: name2 } = column;
3885
+ const handleResizeStart = useCallback27(() => {
3886
+ console.log("onResizeStart");
3887
+ if (onResize && rootRef.current) {
3888
+ console.log("handleResizeStart");
3889
+ const { width } = rootRef.current.getBoundingClientRect();
3890
+ widthRef.current = Math.round(width);
3891
+ setResizing(true);
3892
+ onResize == null ? void 0 : onResize("begin", name2);
3893
+ }
3894
+ }, [name2, onResize, rootRef]);
3895
+ const handleResize = useCallback27(
3896
+ (_evt, moveBy) => {
3897
+ if (rootRef.current) {
3898
+ if (onResize) {
3899
+ const { width } = rootRef.current.getBoundingClientRect();
3900
+ const newWidth = Math.round(width) + moveBy;
3901
+ if (newWidth !== widthRef.current && newWidth > 0) {
3902
+ onResize("resize", name2, newWidth);
3903
+ widthRef.current = newWidth;
3904
+ }
3905
+ }
3906
+ }
3907
+ },
3908
+ [name2, onResize, rootRef]
3909
+ );
3910
+ const handleResizeEnd = useCallback27(() => {
3911
+ if (onResize) {
3912
+ onResize("end", name2, widthRef.current);
3913
+ setTimeout(() => {
3914
+ setResizing(false);
3915
+ }, 80);
3916
+ }
3917
+ }, [name2, onResize]);
3918
+ return {
3919
+ isResizing,
3920
+ onDrag: handleResize,
3921
+ onDragStart: handleResizeStart,
3922
+ onDragEnd: handleResizeEnd
3923
+ };
3924
+ };
3373
3925
 
3374
3926
  // ../vuu-table/src/table-next/useCell.ts
3375
3927
  import { getColumnStyle as getColumnStyle4 } from "@vuu-ui/vuu-utils";
3376
3928
  import cx15 from "classnames";
3377
3929
  import { useMemo as useMemo11 } from "react";
3378
- var useCell = (column, classBase19, isHeader) => (
3930
+ var useCell = (column, classBase23, isHeader) => (
3379
3931
  // TODO measure perf without the memo, might not be worth the cost
3380
3932
  useMemo11(() => {
3381
- const className = cx15(classBase19, {
3933
+ const className = cx15(classBase23, {
3382
3934
  vuuPinFloating: column.pin === "floating",
3383
3935
  vuuPinLeft: column.pin === "left",
3384
3936
  vuuPinRight: column.pin === "right",
3385
3937
  vuuEndPin: isHeader && column.endPin,
3386
3938
  // [`${classBase}-resizing`]: column.resizing,
3387
- [`${classBase19}-editable`]: column.editable,
3388
- [`${classBase19}-right`]: column.align === "right"
3939
+ [`${classBase23}-editable`]: column.editable,
3940
+ [`${classBase23}-right`]: column.align === "right"
3389
3941
  });
3390
3942
  const style = getColumnStyle4(column);
3391
3943
  return {
3392
3944
  className,
3393
3945
  style
3394
3946
  };
3395
- }, [column, classBase19, isHeader])
3947
+ }, [column, classBase23, isHeader])
3396
3948
  );
3397
3949
 
3398
3950
  // ../vuu-table/src/table-next/column-header-pill/ColumnHeaderPill.tsx
3399
3951
  import cx16 from "classnames";
3400
3952
  import { useCallback as useCallback28 } from "react";
3401
3953
  import { jsx as jsx23, jsxs as jsxs18 } from "react/jsx-runtime";
3954
+ var classBase13 = "vuuColumnHeaderPill";
3955
+ var ColumnHeaderPill = ({
3956
+ children,
3957
+ className,
3958
+ column,
3959
+ onRemove,
3960
+ removable,
3961
+ ...htmlAttributes
3962
+ }) => {
3963
+ if (removable && typeof onRemove !== "function") {
3964
+ throw Error(
3965
+ "ColumnHeaderPill onRemove prop must be provided if Pill is removable"
3966
+ );
3967
+ }
3968
+ const handleClickRemove = useCallback28(
3969
+ (evt) => {
3970
+ evt.preventDefault();
3971
+ evt.stopPropagation();
3972
+ onRemove == null ? void 0 : onRemove(column);
3973
+ },
3974
+ [column, onRemove]
3975
+ );
3976
+ return /* @__PURE__ */ jsxs18("div", { ...htmlAttributes, className: cx16(classBase13, className), children: [
3977
+ children,
3978
+ removable ? /* @__PURE__ */ jsx23(
3979
+ "span",
3980
+ {
3981
+ className: `${classBase13}-removeButton`,
3982
+ role: "button",
3983
+ "data-icon": "cross",
3984
+ onClick: handleClickRemove
3985
+ }
3986
+ ) : null
3987
+ ] });
3988
+ };
3402
3989
 
3403
3990
  // ../vuu-table/src/table-next/column-header-pill/GroupColumnPill.tsx
3404
3991
  import { jsx as jsx24, jsxs as jsxs19 } from "react/jsx-runtime";
3992
+ var GroupColumnPill = ({
3993
+ column,
3994
+ ...columnHeaderProps
3995
+ }) => {
3996
+ const { name: name2, sorted } = column;
3997
+ const icon = typeof sorted === "number" ? sorted < 0 ? "arrow-down" : "arrow-up" : sorted === "A" ? "arrow-up" : sorted === "D" ? "arrow-down" : void 0;
3998
+ return /* @__PURE__ */ jsxs19(ColumnHeaderPill, { ...columnHeaderProps, column, children: [
3999
+ /* @__PURE__ */ jsx24("span", { className: "vuuGroupColumnPill-label", children: name2 }),
4000
+ icon !== void 0 ? /* @__PURE__ */ jsx24("span", { "data-icon": icon }) : null,
4001
+ typeof sorted === "number" ? /* @__PURE__ */ jsx24("span", { className: "vuuSortPosition", children: Math.abs(sorted) }) : null
4002
+ ] });
4003
+ };
3405
4004
 
3406
4005
  // ../vuu-table/src/table-next/column-header-pill/SortIndicator.tsx
3407
4006
  import { jsx as jsx25, jsxs as jsxs20 } from "react/jsx-runtime";
4007
+ var SortIndicator2 = ({ column }) => {
4008
+ if (!column.sorted) {
4009
+ return null;
4010
+ }
4011
+ const icon = typeof column.sorted === "number" ? column.sorted < 0 ? "arrow-down" : "arrow-up" : column.sorted === "A" ? "arrow-up" : "arrow-down";
4012
+ return /* @__PURE__ */ jsxs20(ColumnHeaderPill, { column, children: [
4013
+ /* @__PURE__ */ jsx25("span", { "data-icon": icon }),
4014
+ typeof column.sorted === "number" ? /* @__PURE__ */ jsx25("span", { className: "vuuSortPosition", children: Math.abs(column.sorted) }) : null
4015
+ ] });
4016
+ };
3408
4017
 
3409
4018
  // ../vuu-table/src/table-next/header-cell/GroupHeaderCell.tsx
3410
4019
  import { jsx as jsx26, jsxs as jsxs21 } from "react/jsx-runtime";
@@ -3419,6 +4028,92 @@ import {
3419
4028
  } from "@vuu-ui/vuu-layout";
3420
4029
  import { jsx as jsx27, jsxs as jsxs22 } from "react/jsx-runtime";
3421
4030
  import { createElement as createElement2 } from "react";
4031
+ var classBase14 = "vuuTableNextGroupHeaderCell";
4032
+ var switchIfChanged = (columns, newColumns) => {
4033
+ if (columns === newColumns) {
4034
+ return columns;
4035
+ } else {
4036
+ return newColumns;
4037
+ }
4038
+ };
4039
+ var GroupHeaderCellNext = ({
4040
+ column: groupColumn,
4041
+ className: classNameProp,
4042
+ onRemoveColumn,
4043
+ onResize,
4044
+ ...htmlAttributes
4045
+ }) => {
4046
+ const rootRef = useRef26(null);
4047
+ const { isResizing, ...resizeProps } = useTableColumnResize2({
4048
+ column: groupColumn,
4049
+ onResize,
4050
+ rootRef
4051
+ });
4052
+ const [columns, setColumns] = useState11(groupColumn.columns);
4053
+ const { className, style } = useCell(groupColumn, classBase14, true);
4054
+ const columnPillProps = columns.length > 1 ? {
4055
+ removable: true,
4056
+ onRemove: onRemoveColumn
4057
+ } : void 0;
4058
+ const handleMoveItem = useCallback29((fromIndex, toIndex) => {
4059
+ setColumns((cols) => {
4060
+ const newCols = cols.slice();
4061
+ const [tab] = newCols.splice(fromIndex, 1);
4062
+ if (toIndex === -1) {
4063
+ return newCols.concat(tab);
4064
+ } else {
4065
+ newCols.splice(toIndex, 0, tab);
4066
+ return newCols;
4067
+ }
4068
+ });
4069
+ }, []);
4070
+ useLayoutEffectSkipFirst(() => {
4071
+ setColumns((cols) => switchIfChanged(cols, groupColumn.columns));
4072
+ }, [groupColumn.columns]);
4073
+ return /* @__PURE__ */ jsxs22(
4074
+ "div",
4075
+ {
4076
+ ...htmlAttributes,
4077
+ className: cx18(className, "vuuTableNextHeaderCell", classNameProp, {
4078
+ [`${classBase14}-pending`]: groupColumn.groupConfirmed === false
4079
+ }),
4080
+ ref: rootRef,
4081
+ role: "columnheader",
4082
+ style,
4083
+ children: [
4084
+ /* @__PURE__ */ jsx27(
4085
+ OverflowContainer,
4086
+ {
4087
+ allowDragDrop: true,
4088
+ className: `${classBase14}-inner`,
4089
+ height: 24,
4090
+ onMoveItem: handleMoveItem,
4091
+ overflowPosition: "start",
4092
+ children: columns.map((column) => {
4093
+ return /* @__PURE__ */ createElement2(
4094
+ GroupColumnPill,
4095
+ {
4096
+ ...columnPillProps,
4097
+ column,
4098
+ key: column.key
4099
+ }
4100
+ );
4101
+ })
4102
+ }
4103
+ ),
4104
+ /* @__PURE__ */ jsx27(
4105
+ ColumnHeaderPill,
4106
+ {
4107
+ column: groupColumn,
4108
+ removable: true,
4109
+ onRemove: onRemoveColumn
4110
+ }
4111
+ ),
4112
+ groupColumn.resizeable !== false ? /* @__PURE__ */ jsx27(ColumnResizer2, { ...resizeProps }) : null
4113
+ ]
4114
+ }
4115
+ );
4116
+ };
3422
4117
 
3423
4118
  // ../vuu-table/src/table-next/header-cell/HeaderCell.tsx
3424
4119
  import { useCallback as useCallback31, useRef as useRef28 } from "react";
@@ -3432,16 +4127,104 @@ import {
3432
4127
  useState as useState12
3433
4128
  } from "react";
3434
4129
  import { jsx as jsx28 } from "react/jsx-runtime";
4130
+ var getPosition = (element) => {
4131
+ if (element) {
4132
+ const { bottom, left } = element.getBoundingClientRect();
4133
+ return { x: left, y: bottom + 6 };
4134
+ }
4135
+ };
4136
+ var ColumnMenu = ({
4137
+ className,
4138
+ column,
4139
+ ...props
4140
+ }) => {
4141
+ const rootRef = useRef27(null);
4142
+ const [menuOpen, setMenuOpen] = useState12(false);
4143
+ const [showContextMenu] = useContextMenu3();
4144
+ const handleMenuClose = useCallback30(() => {
4145
+ setMenuOpen(false);
4146
+ }, []);
4147
+ const showColumnMenu = useCallback30(
4148
+ (e) => {
4149
+ setMenuOpen(true);
4150
+ showContextMenu(e, "column-menu", {
4151
+ column,
4152
+ ContextMenuProps: {
4153
+ onClose: handleMenuClose,
4154
+ position: getPosition(rootRef.current)
4155
+ }
4156
+ });
4157
+ },
4158
+ [column, handleMenuClose, showContextMenu]
4159
+ );
4160
+ return /* @__PURE__ */ jsx28(
4161
+ "span",
4162
+ {
4163
+ ...props,
4164
+ className: cx19("vuuTable-columnMenu", className, {
4165
+ "vuuTable-columnMenu-open": menuOpen
4166
+ }),
4167
+ "data-icon": "more-vert",
4168
+ onClick: showColumnMenu,
4169
+ ref: rootRef
4170
+ }
4171
+ );
4172
+ };
3435
4173
 
3436
4174
  // ../vuu-table/src/table-next/header-cell/HeaderCell.tsx
3437
4175
  import cx20 from "classnames";
3438
4176
  import { jsx as jsx29, jsxs as jsxs23 } from "react/jsx-runtime";
4177
+ var classBase15 = "vuuTableNextHeaderCell";
4178
+ var HeaderCell = ({
4179
+ className: classNameProp,
4180
+ column,
4181
+ onClick,
4182
+ onResize,
4183
+ ...htmlAttributes
4184
+ }) => {
4185
+ var _a;
4186
+ const rootRef = useRef28(null);
4187
+ const { isResizing, ...resizeProps } = useTableColumnResize2({
4188
+ column,
4189
+ onResize,
4190
+ rootRef
4191
+ });
4192
+ const handleClick = useCallback31(
4193
+ (evt) => {
4194
+ console.log(`click isResizing ${isResizing}`);
4195
+ !isResizing && (onClick == null ? void 0 : onClick(evt));
4196
+ },
4197
+ [isResizing, onClick]
4198
+ );
4199
+ const { className, style } = useCell(column, classBase15, true);
4200
+ const columnMenu = /* @__PURE__ */ jsx29(ColumnMenu, { column });
4201
+ const columnLabel = /* @__PURE__ */ jsx29("div", { className: `${classBase15}-label`, children: (_a = column.label) != null ? _a : column.name });
4202
+ const sortIndicator = /* @__PURE__ */ jsx29(SortIndicator2, { column });
4203
+ const headerItems = column.align === "right" ? [sortIndicator, columnLabel, columnMenu] : [columnMenu, columnLabel, sortIndicator];
4204
+ return /* @__PURE__ */ jsxs23(
4205
+ "div",
4206
+ {
4207
+ ...htmlAttributes,
4208
+ className: cx20(className, classNameProp, {
4209
+ [`${classBase15}-resizing`]: isResizing
4210
+ }),
4211
+ onClick: handleClick,
4212
+ ref: rootRef,
4213
+ role: "columnheader",
4214
+ style,
4215
+ children: [
4216
+ ...headerItems,
4217
+ column.resizeable !== false ? /* @__PURE__ */ jsx29(ColumnResizer2, { ...resizeProps }) : null
4218
+ ]
4219
+ }
4220
+ );
4221
+ };
3439
4222
 
3440
4223
  // ../vuu-table/src/table-next/TableNext.tsx
3441
4224
  import { ContextMenuProvider as ContextMenuProvider2 } from "@vuu-ui/vuu-popups";
3442
4225
  import { isGroupColumn as isGroupColumn7, metadataKeys as metadataKeys18, notHidden as notHidden4 } from "@vuu-ui/vuu-utils";
3443
4226
  import cx23 from "classnames";
3444
- import { useRef as useRef34 } from "react";
4227
+ import { forwardRef, useRef as useRef34 } from "react";
3445
4228
 
3446
4229
  // ../vuu-table/src/table-next/Row.tsx
3447
4230
  import {
@@ -3460,14 +4243,15 @@ import { metadataKeys as metadataKeys12 } from "@vuu-ui/vuu-utils";
3460
4243
  import { useCallback as useCallback32 } from "react";
3461
4244
  import { jsx as jsx30 } from "react/jsx-runtime";
3462
4245
  var { IDX: IDX3 } = metadataKeys12;
3463
- var classBase13 = "vuuTableNextCell";
4246
+ var classBase16 = "vuuTableNextCell";
3464
4247
  var TableCell2 = ({
3465
4248
  column,
3466
4249
  columnMap,
4250
+ onClick,
3467
4251
  onDataEdited,
3468
4252
  row
3469
4253
  }) => {
3470
- const { className, style } = useCell(column, classBase13);
4254
+ const { className, style } = useCell(column, classBase16);
3471
4255
  const { CellRenderer, name: name2, valueFormatter } = column;
3472
4256
  const dataIdx = columnMap[name2];
3473
4257
  const handleDataItemEdited = useCallback32(
@@ -3477,15 +4261,30 @@ var TableCell2 = ({
3477
4261
  },
3478
4262
  [name2, onDataEdited, row]
3479
4263
  );
3480
- return /* @__PURE__ */ jsx30("div", { className, role: "cell", style, children: CellRenderer ? /* @__PURE__ */ jsx30(
3481
- CellRenderer,
4264
+ const handleClick = useCallback32(
4265
+ (evt) => {
4266
+ onClick == null ? void 0 : onClick(evt, column);
4267
+ },
4268
+ [column, onClick]
4269
+ );
4270
+ return /* @__PURE__ */ jsx30(
4271
+ "div",
3482
4272
  {
3483
- column,
3484
- columnMap,
3485
- onCommit: handleDataItemEdited,
3486
- row
4273
+ className,
4274
+ onClick: onClick ? handleClick : void 0,
4275
+ role: "cell",
4276
+ style,
4277
+ children: CellRenderer ? /* @__PURE__ */ jsx30(
4278
+ CellRenderer,
4279
+ {
4280
+ column,
4281
+ columnMap,
4282
+ onCommit: handleDataItemEdited,
4283
+ row
4284
+ }
4285
+ ) : valueFormatter(row[dataIdx])
3487
4286
  }
3488
- ) : valueFormatter(row[dataIdx]) });
4287
+ );
3489
4288
  };
3490
4289
 
3491
4290
  // ../vuu-table/src/table-next/table-cell/TableGroupCell.tsx
@@ -3494,11 +4293,11 @@ import { useCallback as useCallback33 } from "react";
3494
4293
  import cx21 from "classnames";
3495
4294
  import { jsx as jsx31, jsxs as jsxs24 } from "react/jsx-runtime";
3496
4295
  var { IS_LEAF: IS_LEAF3 } = metadataKeys13;
3497
- var classBase14 = "vuuTableNextGroupCell";
4296
+ var classBase17 = "vuuTableNextGroupCell";
3498
4297
  var TableGroupCell2 = ({ column, onClick, row }) => {
3499
4298
  const { columns } = column;
3500
4299
  const [value, offset] = getGroupValueAndOffset2(columns, row);
3501
- const { className, style } = useCell(column, classBase14);
4300
+ const { className, style } = useCell(column, classBase17);
3502
4301
  const handleClick = useCallback33(
3503
4302
  (evt) => {
3504
4303
  onClick == null ? void 0 : onClick(evt, column);
@@ -3506,7 +4305,7 @@ var TableGroupCell2 = ({ column, onClick, row }) => {
3506
4305
  [column, onClick]
3507
4306
  );
3508
4307
  const isLeaf = row[IS_LEAF3];
3509
- const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ jsx31("span", { className: `${classBase14}-spacer` }, i));
4308
+ const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ jsx31("span", { className: `${classBase17}-spacer` }, i));
3510
4309
  return /* @__PURE__ */ jsxs24(
3511
4310
  "div",
3512
4311
  {
@@ -3516,7 +4315,7 @@ var TableGroupCell2 = ({ column, onClick, row }) => {
3516
4315
  onClick: isLeaf ? void 0 : handleClick,
3517
4316
  children: [
3518
4317
  spacers,
3519
- isLeaf ? null : /* @__PURE__ */ jsx31("span", { className: `${classBase14}-toggle`, "data-icon": "triangle-right" }),
4318
+ isLeaf ? null : /* @__PURE__ */ jsx31("span", { className: `${classBase17}-toggle`, "data-icon": "triangle-right" }),
3520
4319
  /* @__PURE__ */ jsx31("span", { children: value })
3521
4320
  ]
3522
4321
  }
@@ -3527,7 +4326,7 @@ var TableGroupCell2 = ({ column, onClick, row }) => {
3527
4326
  import { jsx as jsx32 } from "react/jsx-runtime";
3528
4327
  import { createElement as createElement3 } from "react";
3529
4328
  var { IDX: IDX4, IS_EXPANDED: IS_EXPANDED4, SELECTED: SELECTED3 } = metadataKeys14;
3530
- var classBase15 = "vuuTableNextRow";
4329
+ var classBase18 = "vuuTableNextRow";
3531
4330
  var Row2 = memo3(
3532
4331
  ({
3533
4332
  className: classNameProp,
@@ -3555,12 +4354,12 @@ var Row2 = memo3(
3555
4354
  [onClick, row]
3556
4355
  );
3557
4356
  const { True: True2, First: First2, Last: Last2 } = RowSelected2;
3558
- const className = cx22(classBase15, classNameProp, {
3559
- [`${classBase15}-even`]: zebraStripes && rowIndex % 2 === 0,
3560
- [`${classBase15}-expanded`]: isExpanded,
3561
- [`${classBase15}-selected`]: selectionStatus & True2,
3562
- [`${classBase15}-selectedStart`]: selectionStatus & First2,
3563
- [`${classBase15}-selectedEnd`]: selectionStatus & Last2
4357
+ const className = cx22(classBase18, classNameProp, {
4358
+ [`${classBase18}-even`]: zebraStripes && rowIndex % 2 === 0,
4359
+ [`${classBase18}-expanded`]: isExpanded,
4360
+ [`${classBase18}-selected`]: selectionStatus & True2,
4361
+ [`${classBase18}-selectedStart`]: selectionStatus & First2,
4362
+ [`${classBase18}-selectedEnd`]: selectionStatus & Last2
3564
4363
  });
3565
4364
  const style = { transform: `translate3d(0px, ${offset}px, 0px)` };
3566
4365
  const handleGroupCellClick = useCallback34(
@@ -3583,7 +4382,7 @@ var Row2 = memo3(
3583
4382
  onClick: handleRowClick,
3584
4383
  style
3585
4384
  },
3586
- /* @__PURE__ */ jsx32("span", { className: `${classBase15}-selectionDecorator vuuStickyLeft` }),
4385
+ /* @__PURE__ */ jsx32("span", { className: `${classBase18}-selectionDecorator vuuStickyLeft` }),
3587
4386
  columns.filter(notHidden3).map((column) => {
3588
4387
  const isGroup = isGroupColumn4(column);
3589
4388
  const isJsonCell = isJsonColumn2(column);
@@ -3600,7 +4399,7 @@ var Row2 = memo3(
3600
4399
  column.key
3601
4400
  );
3602
4401
  }),
3603
- /* @__PURE__ */ jsx32("span", { className: `${classBase15}-selectionDecorator vuuStickyRight` })
4402
+ /* @__PURE__ */ jsx32("span", { className: `${classBase18}-selectionDecorator vuuStickyRight` })
3604
4403
  );
3605
4404
  }
3606
4405
  );
@@ -3618,23 +4417,277 @@ import {
3618
4417
  useRef as useRef29
3619
4418
  } from "react";
3620
4419
 
3621
- // ../vuu-table/src/table-next/useTableNext.ts
3622
- import {
3623
- applySort as applySort2,
3624
- buildColumnMap as buildColumnMap4,
3625
- isGroupColumn as isGroupColumn6,
3626
- isJsonGroup as isJsonGroup4,
3627
- isValidNumber as isValidNumber5,
3628
- metadataKeys as metadataKeys17,
3629
- updateColumn as updateColumn2,
3630
- visibleColumnAtIndex as visibleColumnAtIndex2
3631
- } from "@vuu-ui/vuu-utils";
3632
- import {
3633
- useCallback as useCallback41,
3634
- useEffect as useEffect13,
3635
- useMemo as useMemo15,
3636
- useState as useState14
3637
- } from "react";
4420
+ // ../vuu-table/src/table-next/table-dom-utils.ts
4421
+ var headerCellQuery = (colIdx) => `.vuuTableNext-col-headers .vuuTableNextHeaderCell:nth-child(${colIdx})`;
4422
+ var dataCellQuery = (rowIdx, colIdx) => `.vuuTableNext-body > [aria-rowindex='${rowIdx}'] > [role='cell']:nth-child(${colIdx + 1})`;
4423
+ var getTableCell = (containerRef, [rowIdx, colIdx]) => {
4424
+ var _a;
4425
+ const cssQuery = rowIdx === -1 ? headerCellQuery(colIdx) : dataCellQuery(rowIdx, colIdx);
4426
+ const cell = (_a = containerRef.current) == null ? void 0 : _a.querySelector(
4427
+ cssQuery
4428
+ );
4429
+ if (cellIsEditable(cell)) {
4430
+ const focusableContent = cell.querySelector("button");
4431
+ return focusableContent || cell;
4432
+ } else {
4433
+ return cell;
4434
+ }
4435
+ };
4436
+ var cellIsEditable = (cell) => cell.classList.contains("vuuTableNextCell-editable");
4437
+ var cellIsTextInput = (cell) => cell.querySelector(".vuuTableInputCell") !== null;
4438
+
4439
+ // ../vuu-table/src/table-next/useKeyboardNavigation.ts
4440
+ var navigationKeys2 = /* @__PURE__ */ new Set([
4441
+ "Home",
4442
+ "End",
4443
+ "PageUp",
4444
+ "PageDown",
4445
+ "ArrowDown",
4446
+ "ArrowLeft",
4447
+ "ArrowRight",
4448
+ "ArrowUp"
4449
+ ]);
4450
+ var isNavigationKey2 = (key) => {
4451
+ return navigationKeys2.has(key);
4452
+ };
4453
+ var PageKeys = ["Home", "End", "PageUp", "PageDown"];
4454
+ var isPagingKey2 = (key) => PageKeys.includes(key);
4455
+ var NULL_CELL_POS = [-1, -1];
4456
+ var NO_SCROLL_NECESSARY = [void 0, void 0];
4457
+ var howFarIsCellOutsideViewport = (cellEl) => {
4458
+ var _a, _b;
4459
+ const scrollbarContainer = (_a = cellEl.closest(".vuuTableNext")) == null ? void 0 : _a.querySelector(".vuuTableNext-scrollbarContainer");
4460
+ if (scrollbarContainer) {
4461
+ const viewport = scrollbarContainer == null ? void 0 : scrollbarContainer.getBoundingClientRect();
4462
+ const cell = (_b = cellEl.closest(".vuuTableNextCell")) == null ? void 0 : _b.getBoundingClientRect();
4463
+ if (cell) {
4464
+ if (cell.bottom > viewport.bottom) {
4465
+ return ["down", cell.bottom - viewport.bottom];
4466
+ } else if (cell.top < viewport.top) {
4467
+ return ["up", cell.top - viewport.top];
4468
+ } else if (cell.right < viewport.right) {
4469
+ return ["right", cell.right - viewport.right];
4470
+ } else if (cell.left < viewport.left) {
4471
+ return ["left", cell.left - viewport.left];
4472
+ } else {
4473
+ return NO_SCROLL_NECESSARY;
4474
+ }
4475
+ } else {
4476
+ throw Error("Whats going on, cell not found");
4477
+ }
4478
+ } else {
4479
+ throw Error("Whats going on, scrollbar container not found");
4480
+ }
4481
+ };
4482
+ function nextCellPos(key, [rowIdx, colIdx], columnCount, rowCount) {
4483
+ if (key === "ArrowUp") {
4484
+ if (rowIdx > -1) {
4485
+ return [rowIdx - 1, colIdx];
4486
+ } else {
4487
+ return [rowIdx, colIdx];
4488
+ }
4489
+ } else if (key === "ArrowDown") {
4490
+ if (rowIdx === -1) {
4491
+ return [0, colIdx];
4492
+ } else if (rowIdx === rowCount - 1) {
4493
+ return [rowIdx, colIdx];
4494
+ } else {
4495
+ return [rowIdx + 1, colIdx];
4496
+ }
4497
+ } else if (key === "ArrowRight") {
4498
+ if (colIdx < columnCount - 1) {
4499
+ return [rowIdx, colIdx + 1];
4500
+ } else {
4501
+ return [rowIdx, colIdx];
4502
+ }
4503
+ } else if (key === "ArrowLeft") {
4504
+ if (colIdx > 1) {
4505
+ return [rowIdx, colIdx - 1];
4506
+ } else {
4507
+ return [rowIdx, colIdx];
4508
+ }
4509
+ }
4510
+ return [rowIdx, colIdx];
4511
+ }
4512
+ var useKeyboardNavigation2 = ({
4513
+ columnCount = 0,
4514
+ containerRef,
4515
+ disableHighlightOnFocus,
4516
+ requestScroll,
4517
+ rowCount = 0,
4518
+ viewportRowCount
4519
+ }) => {
4520
+ var _a;
4521
+ const focusedCellPos = useRef29([-1, -1]);
4522
+ const focusableCell = useRef29();
4523
+ const activeCellPos = useRef29([-1, 0]);
4524
+ const getFocusedCell = (element) => element == null ? void 0 : element.closest(
4525
+ "[role='columnHeader'],[role='cell']"
4526
+ );
4527
+ const getTableCellPos = (tableCell) => {
4528
+ var _a2, _b;
4529
+ if (tableCell.role === "columnHeader") {
4530
+ const colIdx = parseInt((_a2 = tableCell.dataset.idx) != null ? _a2 : "-1", 10);
4531
+ return [-1, colIdx];
4532
+ } else {
4533
+ const focusedRow = tableCell.closest("[role='row']");
4534
+ if (focusedRow) {
4535
+ const rowIdx = parseInt((_b = focusedRow.ariaRowIndex) != null ? _b : "-1", 10);
4536
+ const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);
4537
+ return [rowIdx, colIdx];
4538
+ }
4539
+ }
4540
+ return NULL_CELL_POS;
4541
+ };
4542
+ const focusCell = useCallback35(
4543
+ (cellPos) => {
4544
+ var _a2;
4545
+ if (containerRef.current) {
4546
+ const activeCell = getTableCell(containerRef, cellPos);
4547
+ if (activeCell) {
4548
+ if (activeCell !== focusableCell.current) {
4549
+ (_a2 = focusableCell.current) == null ? void 0 : _a2.removeAttribute("tabindex");
4550
+ focusableCell.current = activeCell;
4551
+ activeCell.setAttribute("tabindex", "0");
4552
+ }
4553
+ const [direction, distance] = howFarIsCellOutsideViewport(activeCell);
4554
+ if (direction && distance) {
4555
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-distance", distance, direction });
4556
+ }
4557
+ activeCell.focus();
4558
+ }
4559
+ }
4560
+ },
4561
+ // TODO we recreate this function whenever viewportRange changes, which will
4562
+ // be often whilst scrolling - store range in a a ref ?
4563
+ [containerRef, requestScroll]
4564
+ );
4565
+ const setActiveCell = useCallback35(
4566
+ (rowIdx, colIdx, fromKeyboard = false) => {
4567
+ const pos = [rowIdx, colIdx];
4568
+ activeCellPos.current = pos;
4569
+ focusCell(pos);
4570
+ if (fromKeyboard) {
4571
+ focusedCellPos.current = pos;
4572
+ }
4573
+ },
4574
+ [focusCell]
4575
+ );
4576
+ const nextPageItemIdx = useCallback35(
4577
+ (key, [rowIdx, colIdx]) => new Promise((resolve) => {
4578
+ let newRowIdx = rowIdx;
4579
+ switch (key) {
4580
+ case "PageDown":
4581
+ newRowIdx = Math.min(rowCount - 1, rowIdx + viewportRowCount);
4582
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "down" });
4583
+ break;
4584
+ case "PageUp":
4585
+ newRowIdx = Math.max(0, rowIdx - viewportRowCount);
4586
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
4587
+ break;
4588
+ case "Home":
4589
+ newRowIdx = 0;
4590
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "home" });
4591
+ break;
4592
+ case "End":
4593
+ newRowIdx = rowCount - 1;
4594
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "end" });
4595
+ break;
4596
+ }
4597
+ setTimeout(() => {
4598
+ resolve([newRowIdx, colIdx]);
4599
+ }, 90);
4600
+ }),
4601
+ [requestScroll, rowCount, viewportRowCount]
4602
+ );
4603
+ const handleFocus = useCallback35(() => {
4604
+ var _a2;
4605
+ if (disableHighlightOnFocus !== true) {
4606
+ if ((_a2 = containerRef.current) == null ? void 0 : _a2.contains(document.activeElement)) {
4607
+ const focusedCell = getFocusedCell(document.activeElement);
4608
+ if (focusedCell) {
4609
+ console.log({ focusedCell });
4610
+ focusedCellPos.current = getTableCellPos(focusedCell);
4611
+ }
4612
+ }
4613
+ }
4614
+ }, [disableHighlightOnFocus, containerRef]);
4615
+ const navigateChildItems = useCallback35(
4616
+ async (key) => {
4617
+ console.log(`navigate child items ${key}`);
4618
+ const [nextRowIdx, nextColIdx] = isPagingKey2(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
4619
+ console.log(`nextRowIdx ${nextRowIdx} nextColIdx ${nextColIdx}`);
4620
+ const [rowIdx, colIdx] = activeCellPos.current;
4621
+ if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {
4622
+ setActiveCell(nextRowIdx, nextColIdx, true);
4623
+ }
4624
+ },
4625
+ [columnCount, nextPageItemIdx, rowCount, setActiveCell]
4626
+ );
4627
+ const handleKeyDown = useCallback35(
4628
+ (e) => {
4629
+ if (rowCount > 0 && isNavigationKey2(e.key)) {
4630
+ e.preventDefault();
4631
+ e.stopPropagation();
4632
+ void navigateChildItems(e.key);
4633
+ }
4634
+ },
4635
+ [rowCount, navigateChildItems]
4636
+ );
4637
+ const handleClick = useCallback35(
4638
+ // Might not be a cell e.g the Settings button
4639
+ (evt) => {
4640
+ const target = evt.target;
4641
+ const focusedCell = getFocusedCell(target);
4642
+ if (focusedCell) {
4643
+ const [rowIdx, colIdx] = getTableCellPos(focusedCell);
4644
+ setActiveCell(rowIdx, colIdx);
4645
+ }
4646
+ },
4647
+ [setActiveCell]
4648
+ );
4649
+ const navigate = useCallback35(() => {
4650
+ navigateChildItems("ArrowDown");
4651
+ }, [navigateChildItems]);
4652
+ const containerProps = useMemo12(() => {
4653
+ return {
4654
+ navigate,
4655
+ onClick: handleClick,
4656
+ onFocus: handleFocus,
4657
+ onKeyDown: handleKeyDown
4658
+ };
4659
+ }, [handleClick, handleFocus, handleKeyDown, navigate]);
4660
+ const fullyRendered = ((_a = containerRef.current) == null ? void 0 : _a.firstChild) != null;
4661
+ useEffect10(() => {
4662
+ if (fullyRendered && focusableCell.current === void 0) {
4663
+ const { current: container } = containerRef;
4664
+ const cell = (container == null ? void 0 : container.querySelector(headerCellQuery(0))) || (container == null ? void 0 : container.querySelector(dataCellQuery(0, 0)));
4665
+ if (cell) {
4666
+ cell.setAttribute("tabindex", "0");
4667
+ focusableCell.current = cell;
4668
+ }
4669
+ }
4670
+ }, [containerRef, fullyRendered]);
4671
+ return containerProps;
4672
+ };
4673
+
4674
+ // ../vuu-table/src/table-next/useTableNext.ts
4675
+ import {
4676
+ applySort as applySort2,
4677
+ buildColumnMap as buildColumnMap4,
4678
+ isGroupColumn as isGroupColumn6,
4679
+ isJsonGroup as isJsonGroup4,
4680
+ isValidNumber as isValidNumber5,
4681
+ metadataKeys as metadataKeys17,
4682
+ updateColumn as updateColumn2,
4683
+ visibleColumnAtIndex as visibleColumnAtIndex2
4684
+ } from "@vuu-ui/vuu-utils";
4685
+ import {
4686
+ useCallback as useCallback41,
4687
+ useEffect as useEffect13,
4688
+ useMemo as useMemo15,
4689
+ useState as useState14
4690
+ } from "react";
3638
4691
 
3639
4692
  // ../vuu-table/src/table-next/table-config.ts
3640
4693
  var updateTableConfig = (config, action) => {
@@ -3669,18 +4722,235 @@ import { useCallback as useCallback36, useEffect as useEffect11, useMemo as useM
3669
4722
  // ../vuu-table/src/table-next/moving-window.ts
3670
4723
  import { metadataKeys as metadataKeys15, WindowRange as WindowRange2 } from "@vuu-ui/vuu-utils";
3671
4724
  var { SELECTED: SELECTED4 } = metadataKeys15;
4725
+ var MovingWindow = class {
4726
+ constructor({ from, to }) {
4727
+ this.rowCount = 0;
4728
+ this.setRowCount = (rowCount) => {
4729
+ if (rowCount < this.data.length) {
4730
+ this.data.length = rowCount;
4731
+ }
4732
+ this.rowCount = rowCount;
4733
+ };
4734
+ this.range = new WindowRange2(from, to);
4735
+ this.data = new Array(to - from);
4736
+ this.rowCount = 0;
4737
+ }
4738
+ add(data) {
4739
+ const [index] = data;
4740
+ if (this.isWithinRange(index)) {
4741
+ const internalIndex = index - this.range.from;
4742
+ this.data[internalIndex] = data;
4743
+ }
4744
+ }
4745
+ getAtIndex(index) {
4746
+ return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
4747
+ }
4748
+ isWithinRange(index) {
4749
+ return this.range.isWithin(index);
4750
+ }
4751
+ setRange({ from, to }) {
4752
+ if (from !== this.range.from || to !== this.range.to) {
4753
+ const [overlapFrom, overlapTo] = this.range.overlap(from, to);
4754
+ const newData = new Array(Math.max(0, to - from));
4755
+ for (let i = overlapFrom; i < overlapTo; i++) {
4756
+ const data = this.getAtIndex(i);
4757
+ if (data) {
4758
+ const index = i - from;
4759
+ newData[index] = data;
4760
+ }
4761
+ }
4762
+ this.data = newData;
4763
+ this.range.from = from;
4764
+ this.range.to = to;
4765
+ }
4766
+ }
4767
+ getSelectedRows() {
4768
+ return this.data.filter((row) => row[SELECTED4] !== 0);
4769
+ }
4770
+ };
4771
+
4772
+ // ../vuu-table/src/table-next/useDataSource.ts
4773
+ var useDataSource2 = ({
4774
+ dataSource,
4775
+ onFeatureEnabled,
4776
+ onFeatureInvocation,
4777
+ onSizeChange,
4778
+ onSubscribed,
4779
+ range = NULL_RANGE,
4780
+ renderBufferSize = 0
4781
+ }) => {
4782
+ const [, forceUpdate] = useState13(null);
4783
+ const data = useRef30([]);
4784
+ const isMounted = useRef30(true);
4785
+ const hasUpdated = useRef30(false);
4786
+ const rangeRef = useRef30(NULL_RANGE);
4787
+ const dataWindow = useMemo13(
4788
+ () => new MovingWindow(getFullRange2(range, renderBufferSize)),
4789
+ // eslint-disable-next-line react-hooks/exhaustive-deps
4790
+ []
4791
+ );
4792
+ const setData = useCallback36(
4793
+ (updates) => {
4794
+ for (const row of updates) {
4795
+ dataWindow.add(row);
4796
+ }
4797
+ data.current = dataWindow.data;
4798
+ if (isMounted.current) {
4799
+ forceUpdate({});
4800
+ }
4801
+ },
4802
+ [dataWindow]
4803
+ );
4804
+ const datasourceMessageHandler = useCallback36(
4805
+ (message) => {
4806
+ if (message.type === "subscribed") {
4807
+ onSubscribed == null ? void 0 : onSubscribed(message);
4808
+ } else if (message.type === "viewport-update") {
4809
+ if (typeof message.size === "number") {
4810
+ onSizeChange == null ? void 0 : onSizeChange(message.size);
4811
+ dataWindow.setRowCount(message.size);
4812
+ }
4813
+ if (message.rows) {
4814
+ setData(message.rows);
4815
+ } else if (typeof message.size === "number") {
4816
+ data.current = dataWindow.data;
4817
+ hasUpdated.current = true;
4818
+ }
4819
+ } else if (isVuuFeatureAction2(message)) {
4820
+ onFeatureEnabled == null ? void 0 : onFeatureEnabled(message);
4821
+ } else if (isVuuFeatureInvocation2(message)) {
4822
+ onFeatureInvocation == null ? void 0 : onFeatureInvocation(message);
4823
+ } else {
4824
+ console.log(`useDataSource unexpected message ${message.type}`);
4825
+ }
4826
+ },
4827
+ [
4828
+ dataWindow,
4829
+ onFeatureEnabled,
4830
+ onFeatureInvocation,
4831
+ onSizeChange,
4832
+ onSubscribed,
4833
+ setData
4834
+ ]
4835
+ );
4836
+ useEffect11(
4837
+ () => () => {
4838
+ isMounted.current = true;
4839
+ isMounted.current = false;
4840
+ },
4841
+ []
4842
+ );
4843
+ useEffect11(() => {
4844
+ dataSource == null ? void 0 : dataSource.subscribe(
4845
+ { range: getFullRange2(range, renderBufferSize) },
4846
+ datasourceMessageHandler
4847
+ );
4848
+ }, [dataSource, datasourceMessageHandler, range, renderBufferSize]);
4849
+ const setRange = useCallback36(
4850
+ (range2) => {
4851
+ const fullRange = getFullRange2(range2, renderBufferSize);
4852
+ dataWindow.setRange(fullRange);
4853
+ dataSource.range = rangeRef.current = fullRange;
4854
+ dataSource.emit("range", range2);
4855
+ },
4856
+ [dataSource, dataWindow, renderBufferSize]
4857
+ );
4858
+ return {
4859
+ data: data.current,
4860
+ range: rangeRef.current,
4861
+ setRange
4862
+ };
4863
+ };
3672
4864
 
3673
4865
  // ../vuu-table/src/table-next/useInitialValue.ts
3674
4866
  import { useMemo as useMemo14, useRef as useRef31 } from "react";
4867
+ var useInitialValue = (value) => {
4868
+ const ref = useRef31(value);
4869
+ return useMemo14(() => ref.current, []);
4870
+ };
3675
4871
 
3676
4872
  // ../vuu-table/src/table-next/useTableContextMenu.ts
3677
4873
  import { buildColumnMap as buildColumnMap3 } from "@vuu-ui/vuu-utils";
3678
4874
  import { useCallback as useCallback37 } from "react";
3679
4875
  import { useContextMenu as usePopupContextMenu2 } from "@vuu-ui/vuu-popups";
4876
+ var useTableContextMenu2 = ({
4877
+ columns,
4878
+ data
4879
+ }) => {
4880
+ const [showContextMenu] = usePopupContextMenu2();
4881
+ const onContextMenu = useCallback37(
4882
+ (evt) => {
4883
+ var _a;
4884
+ const target = evt.target;
4885
+ const cellEl = target == null ? void 0 : target.closest("div[role='cell']");
4886
+ const rowEl = target == null ? void 0 : target.closest("div[role='row']");
4887
+ if (cellEl && rowEl) {
4888
+ const columnMap = buildColumnMap3(columns);
4889
+ const rowIndex = parseInt((_a = rowEl.ariaRowIndex) != null ? _a : "-1");
4890
+ const cellIndex = Array.from(rowEl.childNodes).indexOf(cellEl);
4891
+ const row = data.find(([idx]) => idx === rowIndex);
4892
+ const columnName = columns[cellIndex];
4893
+ showContextMenu(evt, "grid", {
4894
+ columnMap,
4895
+ columnName,
4896
+ row
4897
+ // selectedRows: selectedRowsCount === 0 ? NO_ROWS : getSelectedRows(),
4898
+ // viewport: dataSource?.viewport,
4899
+ });
4900
+ }
4901
+ },
4902
+ [columns, data, showContextMenu]
4903
+ );
4904
+ return onContextMenu;
4905
+ };
3680
4906
 
3681
4907
  // ../vuu-table/src/table-next/useCellEditing.ts
3682
4908
  import { isCharacterKey } from "@vuu-ui/vuu-utils";
3683
4909
  import { useCallback as useCallback38 } from "react";
4910
+ var useCellEditing = ({ navigate }) => {
4911
+ const commitHandler = useCallback38(() => {
4912
+ navigate();
4913
+ }, [navigate]);
4914
+ const editInput = useCallback38(
4915
+ (evt) => {
4916
+ const cellEl = evt.target;
4917
+ const input = cellEl.querySelector("input");
4918
+ if (input) {
4919
+ input.focus();
4920
+ input.select();
4921
+ }
4922
+ cellEl.addEventListener("vuu-commit", commitHandler, true);
4923
+ },
4924
+ [commitHandler]
4925
+ );
4926
+ const focusInput = useCallback38(
4927
+ (evt) => {
4928
+ const cellEl = evt.target;
4929
+ const input = cellEl.querySelector("input");
4930
+ if (input) {
4931
+ input.focus();
4932
+ input.select();
4933
+ }
4934
+ cellEl.addEventListener("vuu-commit", commitHandler, true);
4935
+ },
4936
+ [commitHandler]
4937
+ );
4938
+ const handleKeyDown = useCallback38(
4939
+ (e) => {
4940
+ if (cellIsTextInput(e.target)) {
4941
+ if (isCharacterKey(e.key)) {
4942
+ editInput(e);
4943
+ } else if (e.key === "Enter") {
4944
+ focusInput(e);
4945
+ }
4946
+ }
4947
+ },
4948
+ [editInput, focusInput]
4949
+ );
4950
+ return {
4951
+ onKeyDown: handleKeyDown
4952
+ };
4953
+ };
3684
4954
 
3685
4955
  // ../vuu-table/src/table-next/useTableModel.ts
3686
4956
  import {
@@ -3705,22 +4975,1074 @@ import {
3705
4975
  import { buildValidationChecker } from "@vuu-ui/vuu-ui-controls";
3706
4976
  import { useReducer as useReducer2 } from "react";
3707
4977
  var { info } = logger("useTableModel");
4978
+ var DEFAULT_COLUMN_WIDTH = 100;
3708
4979
  var KEY_OFFSET2 = metadataKeys16.count;
4980
+ var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
4981
+ var getCellRendererForColumn = (column) => {
4982
+ var _a;
4983
+ if (isTypeDescriptor8(column.type)) {
4984
+ return getCellRenderer2((_a = column.type) == null ? void 0 : _a.renderer);
4985
+ }
4986
+ };
4987
+ var getDataType = (column, tableSchema) => {
4988
+ var _a;
4989
+ const schemaColumn = tableSchema.columns.find(
4990
+ ({ name: name2 }) => name2 === column.name
4991
+ );
4992
+ if (schemaColumn) {
4993
+ return schemaColumn.serverDataType;
4994
+ } else {
4995
+ return (_a = column.serverDataType) != null ? _a : "string";
4996
+ }
4997
+ };
4998
+ var numericTypes = ["int", "long", "double"];
4999
+ var getDefaultAlignment3 = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
5000
+ var isShowColumnSettings = (action) => action.type === "columnSettings";
5001
+ var isShowTableSettings = (action) => action.type === "tableSettings";
5002
+ var columnReducer = (state, action) => {
5003
+ info == null ? void 0 : info(`TableModelReducer ${action.type}`);
5004
+ console.log(`TableModelReducer ${action.type}`);
5005
+ switch (action.type) {
5006
+ case "init":
5007
+ console.log({ init: action });
5008
+ return init(action);
5009
+ case "moveColumn":
5010
+ return moveColumn(state, action);
5011
+ case "resizeColumn":
5012
+ return resizeColumn(state, action);
5013
+ case "setTableSchema":
5014
+ return setTableSchema(state, action);
5015
+ case "hideColumns":
5016
+ return hideColumns(state, action);
5017
+ case "showColumns":
5018
+ return showColumns(state, action);
5019
+ case "pinColumn":
5020
+ return pinColumn2(state, action);
5021
+ case "updateColumnProp":
5022
+ return updateColumnProp(state, action);
5023
+ case "tableConfig":
5024
+ return updateTableConfig2(state, action);
5025
+ default:
5026
+ console.log(`unhandled action ${action.type}`);
5027
+ return state;
5028
+ }
5029
+ };
5030
+ var useTableModel2 = (tableConfigProp, dataSourceConfig) => {
5031
+ const [state, dispatchColumnAction] = useReducer2(columnReducer, { tableConfig: tableConfigProp, dataSourceConfig }, init);
5032
+ const { columns, headings, tableConfig, ...tableAttributes } = state;
5033
+ return {
5034
+ columns,
5035
+ dispatchColumnAction,
5036
+ headings,
5037
+ tableAttributes,
5038
+ tableConfig
5039
+ };
5040
+ };
5041
+ function init({
5042
+ dataSourceConfig,
5043
+ tableConfig
5044
+ }) {
5045
+ const { columns, ...tableAttributes } = tableConfig;
5046
+ const keyedColumns = columns.filter(subscribedOnly(dataSourceConfig == null ? void 0 : dataSourceConfig.columns)).map(columnDescriptorToKeyedColumDescriptor(tableAttributes));
5047
+ const maybePinnedColumns = keyedColumns.some(isPinned2) ? sortPinnedColumns2(keyedColumns) : keyedColumns;
5048
+ let state = {
5049
+ columns: maybePinnedColumns,
5050
+ headings: getTableHeadings2(maybePinnedColumns),
5051
+ tableConfig,
5052
+ ...tableAttributes
5053
+ };
5054
+ if (dataSourceConfig) {
5055
+ const { columns: _, ...rest } = dataSourceConfig;
5056
+ state = updateTableConfig2(state, {
5057
+ type: "tableConfig",
5058
+ ...rest
5059
+ });
5060
+ }
5061
+ return state;
5062
+ }
5063
+ var getLabel = (label, columnFormatHeader) => {
5064
+ if (columnFormatHeader === "uppercase") {
5065
+ return label.toUpperCase();
5066
+ } else if (columnFormatHeader === "capitalize") {
5067
+ return label[0].toUpperCase() + label.slice(1).toLowerCase();
5068
+ }
5069
+ return label;
5070
+ };
5071
+ var columnDescriptorToKeyedColumDescriptor = (tableAttributes) => (column, index) => {
5072
+ const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = tableAttributes;
5073
+ const {
5074
+ align = getDefaultAlignment3(column.serverDataType),
5075
+ key,
5076
+ name: name2,
5077
+ label = name2,
5078
+ width = columnDefaultWidth,
5079
+ ...rest
5080
+ } = column;
5081
+ const keyedColumnWithDefaults = {
5082
+ ...rest,
5083
+ align,
5084
+ CellRenderer: getCellRendererForColumn(column),
5085
+ clientSideEditValidationCheck: hasValidationRules(column.type) ? buildValidationChecker(column.type.renderer.rules) : void 0,
5086
+ label: getLabel(label, columnFormatHeader),
5087
+ key: key != null ? key : index + KEY_OFFSET2,
5088
+ name: name2,
5089
+ originalIdx: index,
5090
+ valueFormatter: getValueFormatter2(column),
5091
+ width
5092
+ };
5093
+ if (isGroupColumn5(keyedColumnWithDefaults)) {
5094
+ keyedColumnWithDefaults.columns = keyedColumnWithDefaults.columns.map(
5095
+ (col) => columnDescriptorToKeyedColumDescriptor(tableAttributes)(col, col.key)
5096
+ );
5097
+ }
5098
+ return keyedColumnWithDefaults;
5099
+ };
5100
+ function moveColumn(state, { column, moveBy, moveTo }) {
5101
+ const { columns } = state;
5102
+ if (typeof moveBy === "number") {
5103
+ const idx = columns.indexOf(column);
5104
+ const newColumns = columns.slice();
5105
+ const [movedColumns] = newColumns.splice(idx, 1);
5106
+ newColumns.splice(idx + moveBy, 0, movedColumns);
5107
+ return {
5108
+ ...state,
5109
+ columns: newColumns
5110
+ };
5111
+ } else if (typeof moveTo === "number") {
5112
+ const index = columns.indexOf(column);
5113
+ return {
5114
+ ...state,
5115
+ columns: moveItem(columns, index, moveTo)
5116
+ };
5117
+ }
5118
+ return state;
5119
+ }
5120
+ function hideColumns(state, { columns }) {
5121
+ if (columns.some((col) => col.hidden !== true)) {
5122
+ return columns.reduce((s, c) => {
5123
+ if (c.hidden !== true) {
5124
+ return updateColumnProp(s, {
5125
+ type: "updateColumnProp",
5126
+ column: c,
5127
+ hidden: true
5128
+ });
5129
+ } else {
5130
+ return s;
5131
+ }
5132
+ }, state);
5133
+ } else {
5134
+ return state;
5135
+ }
5136
+ }
5137
+ function showColumns(state, { columns }) {
5138
+ if (columns.some((col) => col.hidden)) {
5139
+ return columns.reduce((s, c) => {
5140
+ if (c.hidden) {
5141
+ return updateColumnProp(s, {
5142
+ type: "updateColumnProp",
5143
+ column: c,
5144
+ hidden: false
5145
+ });
5146
+ } else {
5147
+ return s;
5148
+ }
5149
+ }, state);
5150
+ } else {
5151
+ return state;
5152
+ }
5153
+ }
5154
+ function resizeColumn(state, { column, phase, width }) {
5155
+ const type = "updateColumnProp";
5156
+ const resizing = phase !== "end";
5157
+ switch (phase) {
5158
+ case "begin":
5159
+ return updateColumnProp(state, { type, column, resizing });
5160
+ case "end":
5161
+ return updateColumnProp(state, { type, column, resizing, width });
5162
+ case "resize":
5163
+ return updateColumnProp(state, { type, column, width });
5164
+ default:
5165
+ throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
5166
+ }
5167
+ }
5168
+ function setTableSchema(state, { tableSchema }) {
5169
+ const { columns } = state;
5170
+ if (columns.some(columnWithoutDataType)) {
5171
+ const cols = columns.map((column) => {
5172
+ var _a;
5173
+ const serverDataType = getDataType(column, tableSchema);
5174
+ return {
5175
+ ...column,
5176
+ align: (_a = column.align) != null ? _a : getDefaultAlignment3(serverDataType),
5177
+ serverDataType
5178
+ };
5179
+ });
5180
+ return {
5181
+ ...state,
5182
+ columns: cols
5183
+ };
5184
+ } else {
5185
+ return state;
5186
+ }
5187
+ }
5188
+ function pinColumn2(state, action) {
5189
+ let { columns } = state;
5190
+ const { column, pin } = action;
5191
+ const targetColumn = columns.find((col) => col.name === column.name);
5192
+ if (targetColumn) {
5193
+ columns = replaceColumn2(columns, { ...targetColumn, pin });
5194
+ columns = sortPinnedColumns2(columns);
5195
+ return {
5196
+ ...state,
5197
+ columns
5198
+ };
5199
+ } else {
5200
+ return state;
5201
+ }
5202
+ }
5203
+ function updateColumnProp(state, action) {
5204
+ let { columns } = state;
5205
+ const { align, column, hidden, label, resizing, width } = action;
5206
+ const targetColumn = columns.find((col) => col.name === column.name);
5207
+ if (targetColumn) {
5208
+ if (align === "left" || align === "right") {
5209
+ columns = replaceColumn2(columns, { ...targetColumn, align });
5210
+ }
5211
+ if (typeof label === "string") {
5212
+ columns = replaceColumn2(columns, { ...targetColumn, label });
5213
+ }
5214
+ if (typeof resizing === "boolean") {
5215
+ columns = replaceColumn2(columns, { ...targetColumn, resizing });
5216
+ }
5217
+ if (typeof hidden === "boolean") {
5218
+ columns = replaceColumn2(columns, { ...targetColumn, hidden });
5219
+ }
5220
+ if (typeof width === "number") {
5221
+ columns = replaceColumn2(columns, { ...targetColumn, width });
5222
+ }
5223
+ }
5224
+ return {
5225
+ ...state,
5226
+ columns
5227
+ };
5228
+ }
5229
+ function updateTableConfig2(state, { confirmed, filter, groupBy, sort }) {
5230
+ const hasGroupBy = groupBy !== void 0;
5231
+ const hasFilter = typeof (filter == null ? void 0 : filter.filter) === "string";
5232
+ const hasSort = sort && sort.sortDefs.length > 0;
5233
+ let result = state;
5234
+ if (hasGroupBy) {
5235
+ result = {
5236
+ ...state,
5237
+ columns: applyGroupByToColumns2(result.columns, groupBy, confirmed)
5238
+ };
5239
+ }
5240
+ if (hasSort) {
5241
+ result = {
5242
+ ...state,
5243
+ columns: applySortToColumns2(result.columns, sort)
5244
+ };
5245
+ }
5246
+ if (hasFilter) {
5247
+ result = {
5248
+ ...state,
5249
+ columns: applyFilterToColumns2(result.columns, filter)
5250
+ };
5251
+ } else if (result.columns.some(isFilteredColumn2)) {
5252
+ result = {
5253
+ ...state,
5254
+ columns: stripFilterFromColumns2(result.columns)
5255
+ };
5256
+ }
5257
+ return result;
5258
+ }
5259
+ function replaceColumn2(state, column) {
5260
+ return state.map((col) => col.name === column.name ? column : col);
5261
+ }
3709
5262
 
3710
5263
  // ../vuu-table/src/table-next/useTableScroll.ts
3711
5264
  import { useCallback as useCallback39, useRef as useRef32 } from "react";
5265
+ var getPctScroll = (container) => {
5266
+ const { scrollLeft, scrollTop } = container;
5267
+ const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
5268
+ const pctScrollLeft = scrollLeft / (scrollWidth - clientWidth);
5269
+ const pctScrollTop = scrollTop / (scrollHeight - clientHeight);
5270
+ return [pctScrollLeft, pctScrollTop];
5271
+ };
5272
+ var useCallbackRef = ({
5273
+ onAttach,
5274
+ onDetach
5275
+ }) => {
5276
+ const ref = useRef32(null);
5277
+ const callbackRef = useCallback39(
5278
+ (el) => {
5279
+ if (el) {
5280
+ ref.current = el;
5281
+ onAttach == null ? void 0 : onAttach(el);
5282
+ } else if (ref.current) {
5283
+ const { current: originalRef } = ref;
5284
+ ref.current = el;
5285
+ onDetach == null ? void 0 : onDetach(originalRef);
5286
+ }
5287
+ },
5288
+ [onAttach, onDetach]
5289
+ );
5290
+ return callbackRef;
5291
+ };
5292
+ var useTableScroll2 = ({
5293
+ maxScrollLeft,
5294
+ maxScrollTop,
5295
+ onHorizontalScroll,
5296
+ onVerticalScroll,
5297
+ rowHeight,
5298
+ viewportRowCount
5299
+ }) => {
5300
+ const contentContainerScrolledRef = useRef32(false);
5301
+ const scrollPosRef = useRef32({ scrollTop: 0, scrollLeft: 0 });
5302
+ const scrollbarContainerRef = useRef32(null);
5303
+ const contentContainerRef = useRef32(null);
5304
+ const handleScrollbarContainerScroll = useCallback39(() => {
5305
+ const { current: contentContainer } = contentContainerRef;
5306
+ const { current: scrollbarContainer } = scrollbarContainerRef;
5307
+ const { current: contentContainerScrolled } = contentContainerScrolledRef;
5308
+ if (contentContainerScrolled) {
5309
+ contentContainerScrolledRef.current = false;
5310
+ } else if (contentContainer && scrollbarContainer) {
5311
+ const [pctScrollLeft, pctScrollTop] = getPctScroll(scrollbarContainer);
5312
+ const rootScrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
5313
+ const rootScrollTop = Math.round(pctScrollTop * maxScrollTop);
5314
+ contentContainer.scrollTo({
5315
+ left: rootScrollLeft,
5316
+ top: rootScrollTop,
5317
+ behavior: "auto"
5318
+ });
5319
+ }
5320
+ }, [maxScrollLeft, maxScrollTop]);
5321
+ const handleContentContainerScroll = useCallback39(() => {
5322
+ const { current: contentContainer } = contentContainerRef;
5323
+ const { current: scrollbarContainer } = scrollbarContainerRef;
5324
+ const { current: scrollPos } = scrollPosRef;
5325
+ if (contentContainer && scrollbarContainer) {
5326
+ const { scrollLeft, scrollTop } = contentContainer;
5327
+ const [pctScrollLeft, pctScrollTop] = getPctScroll(contentContainer);
5328
+ contentContainerScrolledRef.current = true;
5329
+ scrollbarContainer.scrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
5330
+ scrollbarContainer.scrollTop = Math.round(pctScrollTop * maxScrollTop);
5331
+ if (scrollPos.scrollTop !== scrollTop) {
5332
+ scrollPos.scrollTop = scrollTop;
5333
+ onVerticalScroll == null ? void 0 : onVerticalScroll(scrollTop, pctScrollTop);
5334
+ }
5335
+ if (scrollPos.scrollLeft !== scrollLeft) {
5336
+ scrollPos.scrollLeft = scrollLeft;
5337
+ onHorizontalScroll == null ? void 0 : onHorizontalScroll(scrollLeft);
5338
+ }
5339
+ }
5340
+ }, [maxScrollLeft, maxScrollTop, onHorizontalScroll, onVerticalScroll]);
5341
+ const handleAttachScrollbarContainer = useCallback39(
5342
+ (el) => {
5343
+ scrollbarContainerRef.current = el;
5344
+ el.addEventListener("scroll", handleScrollbarContainerScroll, {
5345
+ passive: true
5346
+ });
5347
+ },
5348
+ [handleScrollbarContainerScroll]
5349
+ );
5350
+ const handleDetachScrollbarContainer = useCallback39(
5351
+ (el) => {
5352
+ scrollbarContainerRef.current = null;
5353
+ el.removeEventListener("scroll", handleScrollbarContainerScroll);
5354
+ },
5355
+ [handleScrollbarContainerScroll]
5356
+ );
5357
+ const handleAttachContentContainer = useCallback39(
5358
+ (el) => {
5359
+ contentContainerRef.current = el;
5360
+ el.addEventListener("scroll", handleContentContainerScroll, {
5361
+ passive: true
5362
+ });
5363
+ },
5364
+ [handleContentContainerScroll]
5365
+ );
5366
+ const handleDetachContentContainer = useCallback39(
5367
+ (el) => {
5368
+ contentContainerRef.current = null;
5369
+ el.removeEventListener("scroll", handleContentContainerScroll);
5370
+ },
5371
+ [handleContentContainerScroll]
5372
+ );
5373
+ const contentContainerCallbackRef = useCallbackRef({
5374
+ onAttach: handleAttachContentContainer,
5375
+ onDetach: handleDetachContentContainer
5376
+ });
5377
+ const scrollbarContainerCallbackRef = useCallbackRef({
5378
+ onAttach: handleAttachScrollbarContainer,
5379
+ onDetach: handleDetachScrollbarContainer
5380
+ });
5381
+ const requestScroll = useCallback39(
5382
+ (scrollRequest) => {
5383
+ const { current: scrollbarContainer } = contentContainerRef;
5384
+ if (scrollbarContainer) {
5385
+ const { scrollLeft, scrollTop } = scrollbarContainer;
5386
+ contentContainerScrolledRef.current = false;
5387
+ if (scrollRequest.type === "scroll-distance") {
5388
+ let newScrollLeft = scrollLeft;
5389
+ let newScrollTop = scrollTop;
5390
+ if (scrollRequest.direction === "up" || scrollRequest.direction === "down") {
5391
+ newScrollTop = Math.min(
5392
+ Math.max(0, scrollTop + scrollRequest.distance),
5393
+ maxScrollTop
5394
+ );
5395
+ } else {
5396
+ newScrollLeft = Math.min(
5397
+ Math.max(0, scrollLeft + scrollRequest.distance),
5398
+ maxScrollLeft
5399
+ );
5400
+ }
5401
+ scrollbarContainer.scrollTo({
5402
+ top: newScrollTop,
5403
+ left: newScrollLeft,
5404
+ behavior: "auto"
5405
+ });
5406
+ } else if (scrollRequest.type === "scroll-page") {
5407
+ const { direction } = scrollRequest;
5408
+ const scrollBy = viewportRowCount * (direction === "down" ? rowHeight : -rowHeight);
5409
+ const newScrollTop = Math.min(
5410
+ Math.max(0, scrollTop + scrollBy),
5411
+ maxScrollTop
5412
+ );
5413
+ scrollbarContainer.scrollTo({
5414
+ top: newScrollTop,
5415
+ left: scrollLeft,
5416
+ behavior: "auto"
5417
+ });
5418
+ } else if (scrollRequest.type === "scroll-end") {
5419
+ const { direction } = scrollRequest;
5420
+ const scrollTo = direction === "end" ? maxScrollTop : 0;
5421
+ scrollbarContainer.scrollTo({
5422
+ top: scrollTo,
5423
+ left: scrollbarContainer.scrollLeft,
5424
+ behavior: "auto"
5425
+ });
5426
+ }
5427
+ }
5428
+ },
5429
+ [maxScrollLeft, maxScrollTop, rowHeight, viewportRowCount]
5430
+ );
5431
+ return {
5432
+ /** Ref to be assigned to ScrollbarContainer */
5433
+ scrollbarContainerRef: scrollbarContainerCallbackRef,
5434
+ /** Ref to be assigned to ContentContainer */
5435
+ contentContainerRef: contentContainerCallbackRef,
5436
+ /** Scroll the table */
5437
+ requestScroll
5438
+ };
5439
+ };
3712
5440
 
3713
5441
  // ../vuu-table/src/table-next/useVirtualViewport.ts
3714
5442
  import { useCallback as useCallback40, useEffect as useEffect12, useRef as useRef33 } from "react";
5443
+ var useVirtualViewport2 = ({
5444
+ columns,
5445
+ getRowAtPosition,
5446
+ setRange,
5447
+ viewportMeasurements
5448
+ }) => {
5449
+ const firstRowRef = useRef33(0);
5450
+ const { contentWidth, rowCount: viewportRowCount } = viewportMeasurements;
5451
+ const handleVerticalScroll = useCallback40(
5452
+ (scrollTop) => {
5453
+ const firstRow = getRowAtPosition(scrollTop);
5454
+ if (firstRow !== firstRowRef.current) {
5455
+ firstRowRef.current = firstRow;
5456
+ setRange({ from: firstRow, to: firstRow + viewportRowCount });
5457
+ }
5458
+ },
5459
+ [getRowAtPosition, setRange, viewportRowCount]
5460
+ );
5461
+ useEffect12(() => {
5462
+ const { current: from } = firstRowRef;
5463
+ const rowRange = { from, to: from + viewportRowCount };
5464
+ setRange(rowRange);
5465
+ }, [setRange, viewportRowCount]);
5466
+ return {
5467
+ onVerticalScroll: handleVerticalScroll
5468
+ };
5469
+ };
3715
5470
 
3716
5471
  // ../vuu-table/src/table-next/useTableNext.ts
3717
5472
  var { KEY: KEY6, IS_EXPANDED: IS_EXPANDED5, IS_LEAF: IS_LEAF4 } = metadataKeys17;
5473
+ var addColumn = (tableConfig, column) => ({
5474
+ ...tableConfig,
5475
+ columns: tableConfig.columns.concat(column)
5476
+ });
5477
+ var useTable2 = ({
5478
+ availableColumns,
5479
+ config,
5480
+ containerRef,
5481
+ dataSource,
5482
+ headerHeight = 25,
5483
+ onAvailableColumnsChange,
5484
+ onConfigChange,
5485
+ onFeatureEnabled,
5486
+ onFeatureInvocation,
5487
+ onRowClick: onRowClickProp,
5488
+ onSelect,
5489
+ onSelectionChange,
5490
+ renderBufferSize = 0,
5491
+ rowHeight = 20,
5492
+ selectionModel
5493
+ }) => {
5494
+ const [rowCount, setRowCount] = useState14(dataSource.size);
5495
+ if (dataSource === void 0) {
5496
+ throw Error("no data source provided to Vuu Table");
5497
+ }
5498
+ const [size, setSize] = useState14();
5499
+ const handleResize = useCallback41((size2) => {
5500
+ setSize(size2);
5501
+ }, []);
5502
+ const menuBuilder = useMemo15(
5503
+ () => buildContextMenuDescriptors(dataSource),
5504
+ [dataSource]
5505
+ );
5506
+ const onDataRowcountChange = useCallback41((size2) => {
5507
+ setRowCount(size2);
5508
+ }, []);
5509
+ const {
5510
+ columns: modelColumns,
5511
+ dispatchColumnAction,
5512
+ headings,
5513
+ tableAttributes,
5514
+ tableConfig
5515
+ } = useTableModel2(config, dataSource.config);
5516
+ useLayoutEffectSkipFirst2(() => {
5517
+ dispatchColumnAction({
5518
+ type: "init",
5519
+ dataSourceConfig: dataSource.config,
5520
+ tableConfig
5521
+ });
5522
+ }, [tableConfig, dataSource.config, dispatchColumnAction]);
5523
+ const [stateColumns, setStateColumns] = useState14();
5524
+ const [columns, setColumnSize] = useMemo15(() => {
5525
+ const setSize2 = (columnName, width) => {
5526
+ const cols = updateColumn2(modelColumns, columnName, { width });
5527
+ setStateColumns(cols);
5528
+ };
5529
+ return [stateColumns != null ? stateColumns : modelColumns, setSize2];
5530
+ }, [modelColumns, stateColumns]);
5531
+ const columnMap = useMemo15(
5532
+ () => buildColumnMap4(dataSource.columns),
5533
+ [dataSource.columns]
5534
+ );
5535
+ const {
5536
+ getRowAtPosition,
5537
+ getRowOffset,
5538
+ setPctScrollTop,
5539
+ ...viewportMeasurements
5540
+ } = useTableViewport({
5541
+ columns,
5542
+ headerHeight,
5543
+ headings,
5544
+ rowCount,
5545
+ rowHeight,
5546
+ size
5547
+ });
5548
+ const initialRange = useInitialValue({
5549
+ from: 0,
5550
+ to: viewportMeasurements.rowCount
5551
+ });
5552
+ const onSubscribed = useCallback41(
5553
+ ({ tableSchema }) => {
5554
+ if (tableSchema) {
5555
+ } else {
5556
+ console.log("usbscription message with no schema");
5557
+ }
5558
+ },
5559
+ []
5560
+ );
5561
+ const { data, range, setRange } = useDataSource2({
5562
+ dataSource,
5563
+ onFeatureEnabled,
5564
+ onFeatureInvocation,
5565
+ renderBufferSize,
5566
+ onSizeChange: onDataRowcountChange,
5567
+ onSubscribed,
5568
+ range: initialRange
5569
+ });
5570
+ const handleConfigChanged = useCallback41(
5571
+ (tableConfig2) => {
5572
+ dispatchColumnAction({
5573
+ type: "init",
5574
+ tableConfig: tableConfig2,
5575
+ dataSourceConfig: dataSource.config
5576
+ });
5577
+ onConfigChange == null ? void 0 : onConfigChange(tableConfig2);
5578
+ },
5579
+ [dataSource.config, dispatchColumnAction, onConfigChange]
5580
+ );
5581
+ const handleDataSourceConfigChanged = useCallback41(
5582
+ (dataSourceConfig) => {
5583
+ dataSource.config = {
5584
+ ...dataSource.config,
5585
+ ...dataSourceConfig
5586
+ };
5587
+ },
5588
+ [dataSource]
5589
+ );
5590
+ const handleCreateCalculatedColumn = useCallback41(
5591
+ (column) => {
5592
+ dataSource.columns = dataSource.columns.concat(column.name);
5593
+ const newTableConfig = addColumn(tableConfig, column);
5594
+ dispatchColumnAction({
5595
+ type: "init",
5596
+ tableConfig: newTableConfig,
5597
+ dataSourceConfig: dataSource.config
5598
+ });
5599
+ onConfigChange == null ? void 0 : onConfigChange(newTableConfig);
5600
+ },
5601
+ [dataSource, dispatchColumnAction, onConfigChange, tableConfig]
5602
+ );
5603
+ useEffect13(() => {
5604
+ dataSource.on("config", (config2, confirmed) => {
5605
+ dispatchColumnAction({
5606
+ type: "tableConfig",
5607
+ ...config2,
5608
+ confirmed
5609
+ });
5610
+ });
5611
+ }, [dataSource, dispatchColumnAction]);
5612
+ const { showColumnSettingsPanel, showTableSettingsPanel } = useTableAndColumnSettings({
5613
+ availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name: name2, serverDataType = "string" }) => ({
5614
+ name: name2,
5615
+ serverDataType
5616
+ })),
5617
+ onAvailableColumnsChange,
5618
+ onConfigChange: handleConfigChanged,
5619
+ onCreateCalculatedColumn: handleCreateCalculatedColumn,
5620
+ onDataSourceConfigChange: handleDataSourceConfigChanged,
5621
+ tableConfig
5622
+ });
5623
+ const onPersistentColumnOperation = useCallback41(
5624
+ (action) => {
5625
+ if (isShowColumnSettings(action)) {
5626
+ showColumnSettingsPanel(action);
5627
+ } else if (isShowTableSettings(action)) {
5628
+ showTableSettingsPanel();
5629
+ } else {
5630
+ dispatchColumnAction(action);
5631
+ }
5632
+ },
5633
+ [dispatchColumnAction, showColumnSettingsPanel, showTableSettingsPanel]
5634
+ );
5635
+ const handleContextMenuAction = useTableContextMenu({
5636
+ dataSource,
5637
+ onPersistentColumnOperation
5638
+ });
5639
+ const handleSort = useCallback41(
5640
+ (column, extendSort = false, sortType) => {
5641
+ if (dataSource) {
5642
+ dataSource.sort = applySort2(
5643
+ dataSource.sort,
5644
+ column,
5645
+ extendSort,
5646
+ sortType
5647
+ );
5648
+ }
5649
+ },
5650
+ [dataSource]
5651
+ );
5652
+ const onHeaderResize = useCallback41(
5653
+ (phase, columnName, width) => {
5654
+ const column = columns.find((column2) => column2.name === columnName);
5655
+ if (column) {
5656
+ if (phase === "resize") {
5657
+ if (isValidNumber5(width)) {
5658
+ setColumnSize(columnName, width);
5659
+ }
5660
+ } else if (phase === "end") {
5661
+ if (isValidNumber5(width)) {
5662
+ dispatchColumnAction({
5663
+ type: "resizeColumn",
5664
+ phase,
5665
+ column,
5666
+ width
5667
+ });
5668
+ onConfigChange == null ? void 0 : onConfigChange(
5669
+ updateTableConfig(tableConfig, {
5670
+ type: "col-size",
5671
+ column,
5672
+ width
5673
+ })
5674
+ );
5675
+ }
5676
+ } else {
5677
+ setStateColumns(void 0);
5678
+ dispatchColumnAction({
5679
+ type: "resizeColumn",
5680
+ phase,
5681
+ column,
5682
+ width
5683
+ });
5684
+ }
5685
+ } else {
5686
+ throw Error(
5687
+ `useDataTable.handleColumnResize, column ${columnName} not found`
5688
+ );
5689
+ }
5690
+ },
5691
+ [columns, tableConfig, dispatchColumnAction, onConfigChange, setColumnSize]
5692
+ );
5693
+ const onToggleGroup = useCallback41(
5694
+ (row, column) => {
5695
+ const isJson = isJsonGroup4(column, row);
5696
+ const key = row[KEY6];
5697
+ if (row[IS_EXPANDED5]) {
5698
+ dataSource.closeTreeNode(key, true);
5699
+ if (isJson) {
5700
+ const idx = columns.indexOf(column);
5701
+ const rows = dataSource.getRowsAtDepth(idx + 1);
5702
+ if (!rows.some((row2) => row2[IS_EXPANDED5] || row2[IS_LEAF4])) {
5703
+ dispatchColumnAction({
5704
+ type: "hideColumns",
5705
+ columns: columns.slice(idx + 2)
5706
+ });
5707
+ }
5708
+ }
5709
+ } else {
5710
+ dataSource.openTreeNode(key);
5711
+ if (isJson) {
5712
+ const childRows = dataSource.getChildRows(key);
5713
+ const idx = columns.indexOf(column) + 1;
5714
+ const columnsToShow = [columns[idx]];
5715
+ if (childRows.some((row2) => row2[IS_LEAF4])) {
5716
+ columnsToShow.push(columns[idx + 1]);
5717
+ }
5718
+ if (columnsToShow.some((col) => col.hidden)) {
5719
+ dispatchColumnAction({
5720
+ type: "showColumns",
5721
+ columns: columnsToShow
5722
+ });
5723
+ }
5724
+ }
5725
+ }
5726
+ },
5727
+ [columns, dataSource, dispatchColumnAction]
5728
+ );
5729
+ const { onVerticalScroll } = useVirtualViewport2({
5730
+ columns,
5731
+ getRowAtPosition,
5732
+ setRange,
5733
+ viewportMeasurements
5734
+ });
5735
+ const handleVerticalScroll = useCallback41(
5736
+ (scrollTop) => {
5737
+ onVerticalScroll(scrollTop);
5738
+ },
5739
+ [onVerticalScroll]
5740
+ );
5741
+ const { requestScroll, ...scrollProps } = useTableScroll2({
5742
+ maxScrollLeft: viewportMeasurements.maxScrollContainerScrollHorizontal,
5743
+ maxScrollTop: viewportMeasurements.maxScrollContainerScrollVertical,
5744
+ rowHeight,
5745
+ onVerticalScroll: handleVerticalScroll,
5746
+ viewportRowCount: viewportMeasurements.rowCount
5747
+ });
5748
+ const {
5749
+ navigate,
5750
+ onKeyDown: navigationKeyDown,
5751
+ ...containerProps
5752
+ } = useKeyboardNavigation2({
5753
+ columnCount: columns.filter((c) => c.hidden !== true).length,
5754
+ containerRef,
5755
+ requestScroll,
5756
+ rowCount: dataSource == null ? void 0 : dataSource.size,
5757
+ viewportRange: range,
5758
+ viewportRowCount: viewportMeasurements.rowCount
5759
+ });
5760
+ const { onKeyDown: editingKeyDown } = useCellEditing({ navigate });
5761
+ const handleKeyDown = useCallback41(
5762
+ (e) => {
5763
+ navigationKeyDown(e);
5764
+ if (!e.defaultPrevented) {
5765
+ editingKeyDown(e);
5766
+ }
5767
+ },
5768
+ [navigationKeyDown, editingKeyDown]
5769
+ );
5770
+ const onContextMenu = useTableContextMenu2({ columns, data });
5771
+ const onHeaderClick = useCallback41(
5772
+ (evt) => {
5773
+ var _a;
5774
+ const targetElement = evt.target;
5775
+ const headerCell = targetElement.closest(
5776
+ ".vuuTableNextHeaderCell"
5777
+ );
5778
+ const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.index) != null ? _a : "-1");
5779
+ const column = visibleColumnAtIndex2(columns, colIdx);
5780
+ const isAdditive = evt.shiftKey;
5781
+ column && handleSort(column, isAdditive);
5782
+ },
5783
+ [columns, handleSort]
5784
+ );
5785
+ const onRemoveGroupColumn = useCallback41(
5786
+ (column) => {
5787
+ if (isGroupColumn6(column)) {
5788
+ dataSource.groupBy = [];
5789
+ } else {
5790
+ if (dataSource && dataSource.groupBy.includes(column.name)) {
5791
+ dataSource.groupBy = dataSource.groupBy.filter(
5792
+ (columnName) => columnName !== column.name
5793
+ );
5794
+ }
5795
+ }
5796
+ },
5797
+ [dataSource]
5798
+ );
5799
+ const handleSelectionChange = useCallback41(
5800
+ (selected) => {
5801
+ dataSource.select(selected);
5802
+ onSelectionChange == null ? void 0 : onSelectionChange(selected);
5803
+ },
5804
+ [dataSource, onSelectionChange]
5805
+ );
5806
+ const selectionHookOnRowClick = useSelection({
5807
+ onSelect,
5808
+ onSelectionChange: handleSelectionChange,
5809
+ selectionModel
5810
+ });
5811
+ const handleRowClick = useCallback41(
5812
+ (row, rangeSelect, keepExistingSelection) => {
5813
+ selectionHookOnRowClick(row, rangeSelect, keepExistingSelection);
5814
+ onRowClickProp == null ? void 0 : onRowClickProp(row);
5815
+ },
5816
+ [onRowClickProp, selectionHookOnRowClick]
5817
+ );
5818
+ useEffect13(() => {
5819
+ dataSource.on("config", (config2, confirmed) => {
5820
+ dispatchColumnAction({
5821
+ type: "tableConfig",
5822
+ ...config2,
5823
+ confirmed
5824
+ });
5825
+ });
5826
+ }, [dataSource, dispatchColumnAction]);
5827
+ const handleDrop = useCallback41(
5828
+ (moveFrom, moveTo) => {
5829
+ const column = columns[moveFrom];
5830
+ dispatchColumnAction({
5831
+ type: "moveColumn",
5832
+ column,
5833
+ moveTo
5834
+ });
5835
+ },
5836
+ [columns, dispatchColumnAction]
5837
+ );
5838
+ const handleDataEdited = useCallback41(
5839
+ (rowIndex, columnName, value) => {
5840
+ return dataSource.applyEdit(rowIndex, columnName, value);
5841
+ },
5842
+ [dataSource]
5843
+ );
5844
+ const { onMouseDown: dragDropHookHandleMouseDown, ...dragDropHook } = useDragDrop2({
5845
+ allowDragDrop: true,
5846
+ containerRef,
5847
+ // this is for useDragDropNext
5848
+ draggableClassName: `vuuTableNext`,
5849
+ // extendedDropZone: overflowedItems.length > 0,
5850
+ onDrop: handleDrop,
5851
+ orientation: "horizontal",
5852
+ itemQuery: ".vuuTableNextHeaderCell"
5853
+ });
5854
+ const headerProps = {
5855
+ onClick: onHeaderClick,
5856
+ onMouseDown: dragDropHookHandleMouseDown,
5857
+ onResize: onHeaderResize
5858
+ };
5859
+ return {
5860
+ ...containerProps,
5861
+ onKeyDown: handleKeyDown,
5862
+ columnMap,
5863
+ columns,
5864
+ data,
5865
+ handleContextMenuAction,
5866
+ headerProps,
5867
+ menuBuilder,
5868
+ onContextMenu,
5869
+ onDataEdited: handleDataEdited,
5870
+ onRemoveGroupColumn,
5871
+ onResize: handleResize,
5872
+ onRowClick: handleRowClick,
5873
+ onToggleGroup,
5874
+ scrollProps,
5875
+ tableAttributes,
5876
+ viewportMeasurements,
5877
+ dragDropHook
5878
+ };
5879
+ };
3718
5880
 
3719
5881
  // ../vuu-table/src/table-next/TableNext.tsx
3720
5882
  import { MeasuredContainer, useId } from "@vuu-ui/vuu-layout";
5883
+ import { useForkRef } from "@salt-ds/core";
3721
5884
  import { jsx as jsx33, jsxs as jsxs25 } from "react/jsx-runtime";
3722
5885
  import { createElement as createElement4 } from "react";
5886
+ var classBase19 = "vuuTableNext";
3723
5887
  var { IDX: IDX5, RENDER_IDX: RENDER_IDX2 } = metadataKeys18;
5888
+ var TableNext = forwardRef(function TableNext2({
5889
+ Row: Row3 = Row2,
5890
+ availableColumns,
5891
+ className: classNameProp,
5892
+ config,
5893
+ dataSource,
5894
+ id: idProp,
5895
+ onAvailableColumnsChange,
5896
+ onConfigChange,
5897
+ onFeatureEnabled,
5898
+ onFeatureInvocation,
5899
+ onRowClick: onRowClickProp,
5900
+ onSelect,
5901
+ onSelectionChange,
5902
+ onShowConfigEditor: onShowSettings,
5903
+ renderBufferSize = 0,
5904
+ rowHeight = 20,
5905
+ selectionModel = "extended",
5906
+ showColumnHeaders = true,
5907
+ headerHeight = showColumnHeaders ? 25 : 0,
5908
+ style: styleProp,
5909
+ ...htmlAttributes
5910
+ }, forwardedRef) {
5911
+ const id = useId(idProp);
5912
+ const containerRef = useRef34(null);
5913
+ const {
5914
+ columnMap,
5915
+ columns,
5916
+ data,
5917
+ dragDropHook,
5918
+ handleContextMenuAction,
5919
+ headerProps,
5920
+ onDataEdited,
5921
+ onRemoveGroupColumn,
5922
+ onResize,
5923
+ onRowClick,
5924
+ onToggleGroup,
5925
+ menuBuilder,
5926
+ scrollProps,
5927
+ tableAttributes,
5928
+ viewportMeasurements,
5929
+ ...tableProps
5930
+ } = useTable2({
5931
+ availableColumns,
5932
+ config,
5933
+ containerRef,
5934
+ dataSource,
5935
+ headerHeight,
5936
+ onAvailableColumnsChange,
5937
+ onConfigChange,
5938
+ onFeatureEnabled,
5939
+ onFeatureInvocation,
5940
+ onRowClick: onRowClickProp,
5941
+ onSelect,
5942
+ onSelectionChange,
5943
+ renderBufferSize,
5944
+ rowHeight,
5945
+ selectionModel
5946
+ });
5947
+ const getStyle = () => {
5948
+ return {
5949
+ ...styleProp,
5950
+ "--content-height": `${viewportMeasurements.contentHeight}px`,
5951
+ "--horizontal-scrollbar-height": `${viewportMeasurements.horizontalScrollbarHeight}px`,
5952
+ "--content-width": `${viewportMeasurements.contentWidth}px`,
5953
+ "--pinned-width-left": `${viewportMeasurements.pinnedWidthLeft}px`,
5954
+ "--pinned-width-right": `${viewportMeasurements.pinnedWidthRight}px`,
5955
+ "--header-height": `${headerHeight}px`,
5956
+ "--row-height": `${rowHeight}px`,
5957
+ "--total-header-height": `${viewportMeasurements.totalHeaderHeight}px`,
5958
+ "--vertical-scrollbar-width": `${viewportMeasurements.verticalScrollbarWidth}px`,
5959
+ "--viewport-body-height": `${viewportMeasurements.viewportBodyHeight}px`
5960
+ };
5961
+ };
5962
+ const className = cx23(classBase19, classNameProp, {
5963
+ [`${classBase19}-colLines`]: tableAttributes.columnSeparators,
5964
+ [`${classBase19}-rowLines`]: tableAttributes.rowSeparators,
5965
+ [`${classBase19}-zebra`]: tableAttributes.zebraStripes
5966
+ // [`${classBase}-loading`]: isDataLoading(tableProps.columns),
5967
+ });
5968
+ return /* @__PURE__ */ jsx33(
5969
+ ContextMenuProvider2,
5970
+ {
5971
+ menuActionHandler: handleContextMenuAction,
5972
+ menuBuilder,
5973
+ children: /* @__PURE__ */ jsxs25(
5974
+ MeasuredContainer,
5975
+ {
5976
+ ...htmlAttributes,
5977
+ className,
5978
+ onResize,
5979
+ ref: useForkRef(containerRef, forwardedRef),
5980
+ style: getStyle(),
5981
+ children: [
5982
+ /* @__PURE__ */ jsx33(
5983
+ "div",
5984
+ {
5985
+ className: `${classBase19}-scrollbarContainer`,
5986
+ ref: scrollProps.scrollbarContainerRef,
5987
+ children: /* @__PURE__ */ jsx33("div", { className: `${classBase19}-scrollbarContent` })
5988
+ }
5989
+ ),
5990
+ /* @__PURE__ */ jsx33(
5991
+ "div",
5992
+ {
5993
+ className: `${classBase19}-contentContainer`,
5994
+ ref: scrollProps.contentContainerRef,
5995
+ children: /* @__PURE__ */ jsxs25("div", { ...tableProps, className: `${classBase19}-table`, tabIndex: -1, children: [
5996
+ showColumnHeaders ? /* @__PURE__ */ jsx33("div", { className: `${classBase19}-col-headings`, children: /* @__PURE__ */ jsxs25("div", { className: `${classBase19}-col-headers`, role: "row", children: [
5997
+ columns.filter(notHidden4).map(
5998
+ (col, i) => isGroupColumn7(col) ? /* @__PURE__ */ createElement4(
5999
+ GroupHeaderCellNext,
6000
+ {
6001
+ ...headerProps,
6002
+ column: col,
6003
+ "data-index": i,
6004
+ key: col.name,
6005
+ onRemoveColumn: onRemoveGroupColumn
6006
+ }
6007
+ ) : /* @__PURE__ */ createElement4(
6008
+ HeaderCell,
6009
+ {
6010
+ ...headerProps,
6011
+ className: cx23({
6012
+ "vuuDraggable-dragAway": i === dragDropHook.draggedItemIndex
6013
+ }),
6014
+ column: col,
6015
+ "data-index": i,
6016
+ id: `${id}-col-${i}`,
6017
+ key: col.name
6018
+ }
6019
+ )
6020
+ ),
6021
+ dragDropHook.draggable
6022
+ ] }) }) : null,
6023
+ /* @__PURE__ */ jsx33("div", { className: `${classBase19}-body`, children: data.map((data2) => /* @__PURE__ */ jsx33(
6024
+ Row3,
6025
+ {
6026
+ columnMap,
6027
+ columns,
6028
+ onClick: onRowClick,
6029
+ onDataEdited,
6030
+ row: data2,
6031
+ offset: rowHeight * data2[IDX5] + headerHeight,
6032
+ onToggleGroup,
6033
+ zebraStripes: tableAttributes.zebraStripes
6034
+ },
6035
+ data2[RENDER_IDX2]
6036
+ )) })
6037
+ ] })
6038
+ }
6039
+ )
6040
+ ]
6041
+ }
6042
+ )
6043
+ }
6044
+ );
6045
+ });
3724
6046
 
3725
6047
  // ../vuu-table/src/table-next/cell-renderers/dropdown-cell/DropdownCell.tsx
3726
6048
  import {
@@ -3733,7 +6055,7 @@ import {
3733
6055
  } from "@vuu-ui/vuu-utils";
3734
6056
  import { useCallback as useCallback42, useState as useState15 } from "react";
3735
6057
  import { jsx as jsx34 } from "react/jsx-runtime";
3736
- var classBase16 = "vuuTableDropdownCell";
6058
+ var classBase20 = "vuuTableDropdownCell";
3737
6059
  var openKeys = ["Enter", " "];
3738
6060
  var DropdownCell = ({ column, columnMap, row }) => {
3739
6061
  var _a, _b, _c;
@@ -3751,7 +6073,7 @@ var DropdownCell = ({ column, columnMap, row }) => {
3751
6073
  return /* @__PURE__ */ jsx34(
3752
6074
  Dropdown3,
3753
6075
  {
3754
- className: classBase16,
6076
+ className: classBase20,
3755
6077
  onSelectionChange: handleSelectionChange,
3756
6078
  openKeys,
3757
6079
  selected: value,
@@ -3768,7 +6090,7 @@ import { Input as Input3 } from "@salt-ds/core";
3768
6090
  import { useEditableText } from "@vuu-ui/vuu-ui-controls";
3769
6091
  import cx24 from "classnames";
3770
6092
  import { jsx as jsx35 } from "react/jsx-runtime";
3771
- var classBase17 = "vuuTableInputCell";
6093
+ var classBase21 = "vuuTableInputCell";
3772
6094
  var WarnCommit = () => {
3773
6095
  console.warn(
3774
6096
  "onCommit handler has not been provided to InputCell cell renderer"
@@ -3792,14 +6114,14 @@ var InputCell = ({
3792
6114
  onCommit,
3793
6115
  clientSideEditValidationCheck
3794
6116
  });
3795
- const endAdornment = warningMessage && align === "left" ? /* @__PURE__ */ jsx35("span", { className: `${classBase17}-icon`, "data-icon": "error" }) : void 0;
3796
- const startAdornment = warningMessage && align === "right" ? /* @__PURE__ */ jsx35("span", { className: `${classBase17}-icon`, "data-icon": "error" }) : void 0;
6117
+ const endAdornment = warningMessage && align === "left" ? /* @__PURE__ */ jsx35("span", { className: `${classBase21}-icon`, "data-icon": "error" }) : void 0;
6118
+ const startAdornment = warningMessage && align === "right" ? /* @__PURE__ */ jsx35("span", { className: `${classBase21}-icon`, "data-icon": "error" }) : void 0;
3797
6119
  return /* @__PURE__ */ jsx35(
3798
6120
  Input3,
3799
6121
  {
3800
6122
  ...editProps,
3801
- className: cx24(classBase17, {
3802
- [`${classBase17}-error`]: warningMessage !== void 0
6123
+ className: cx24(classBase21, {
6124
+ [`${classBase21}-error`]: warningMessage !== void 0
3803
6125
  }),
3804
6126
  endAdornment,
3805
6127
  startAdornment
@@ -3975,7 +6297,7 @@ var useTableSettings = ({
3975
6297
 
3976
6298
  // src/table-settings/TableSettingsPanel.tsx
3977
6299
  import { jsx as jsx36, jsxs as jsxs26 } from "react/jsx-runtime";
3978
- var classBase18 = "vuuTableSettingsPanel";
6300
+ var classBase22 = "vuuTableSettingsPanel";
3979
6301
  var TableSettingsPanel = ({
3980
6302
  availableColumns,
3981
6303
  onAddCalculatedColumn,
@@ -3998,7 +6320,7 @@ var TableSettingsPanel = ({
3998
6320
  onDataSourceConfigChange,
3999
6321
  tableConfig: tableConfigProp
4000
6322
  });
4001
- return /* @__PURE__ */ jsxs26("div", { ...htmlAttributes, className: classBase18, children: [
6323
+ return /* @__PURE__ */ jsxs26("div", { ...htmlAttributes, className: classBase22, children: [
4002
6324
  /* @__PURE__ */ jsxs26(FormField5, { children: [
4003
6325
  /* @__PURE__ */ jsx36(FormFieldLabel5, { children: "Column Labels" }),
4004
6326
  /* @__PURE__ */ jsxs26(
@@ -4083,9 +6405,9 @@ var TableSettingsPanel = ({
4083
6405
  onMoveListItem
4084
6406
  }
4085
6407
  ),
4086
- /* @__PURE__ */ jsxs26("div", { className: `${classBase18}-calculatedButtonbar`, children: [
6408
+ /* @__PURE__ */ jsxs26("div", { className: `${classBase22}-calculatedButtonbar`, children: [
4087
6409
  /* @__PURE__ */ jsx36(Button4, { "data-icon": "plus", onClick: onAddCalculatedColumn }),
4088
- /* @__PURE__ */ jsx36("span", { className: `${classBase18}-calculatedLabel`, children: "Add calculated column" })
6410
+ /* @__PURE__ */ jsx36("span", { className: `${classBase22}-calculatedLabel`, children: "Add calculated column" })
4089
6411
  ] })
4090
6412
  ] });
4091
6413
  };