beautiful-grid 1.0.14 → 1.0.15

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.
Files changed (34) hide show
  1. package/README.md +121 -6
  2. package/cjs/BGrid.js +376 -42
  3. package/cjs/components/CellNavigationDomSync.js +8 -0
  4. package/cjs/components/CellTextEditorGateway.js +13 -9
  5. package/cjs/components/ColResizer.js +13 -7
  6. package/cjs/components/MasterDetailCell.js +145 -0
  7. package/cjs/components/MasterDetailContext.js +42 -0
  8. package/cjs/components/Table.js +154 -50
  9. package/cjs/components/TableBody.js +7 -3
  10. package/cjs/components/TableBodyCell.js +2 -1
  11. package/cjs/utils/cellSelectionGeometry.js +32 -6
  12. package/cjs/utils/rowHeightMetrics.js +47 -6
  13. package/cjs/utils/useRowReorderController.js +5 -1
  14. package/esm/BGrid.js +376 -69
  15. package/esm/components/CellNavigationDomSync.js +8 -0
  16. package/esm/components/CellTextEditorGateway.js +12 -9
  17. package/esm/components/ColResizer.js +8 -2
  18. package/esm/components/MasterDetailCell.js +101 -0
  19. package/esm/components/MasterDetailContext.js +5 -0
  20. package/esm/components/Table.js +143 -40
  21. package/esm/components/TableBody.js +6 -2
  22. package/esm/components/TableBodyCell.js +2 -1
  23. package/esm/utils/cellSelectionGeometry.js +31 -5
  24. package/esm/utils/rowHeightMetrics.js +46 -6
  25. package/esm/utils/useRowReorderController.js +5 -1
  26. package/package.json +1 -1
  27. package/style.css +156 -11
  28. package/types/BGrid.d.ts +1 -1
  29. package/types/components/MasterDetailCell.d.ts +21 -0
  30. package/types/components/MasterDetailContext.d.ts +20 -0
  31. package/types/components/TableBody.d.ts +2 -1
  32. package/types/types.d.ts +52 -0
  33. package/types/utils/cellSelectionGeometry.d.ts +3 -1
  34. package/types/utils/rowHeightMetrics.d.ts +15 -1
package/README.md CHANGED
@@ -65,6 +65,8 @@ Watch 1-million row virtual scrolling, keyboard navigation, and interactive cell
65
65
  - [12. Cell Merging](#12-cell-merging)
66
66
  - [13. Pivot Table](#13-pivot-table)
67
67
  - [14. Column Visibility](#14-column-visibility)
68
+ - [15. Tree Grid](#15-tree-grid)
69
+ - [16. Master-Detail (Nested Grid)](#16-master-detail-nested-grid)
68
70
  - [Props Reference](#props-reference)
69
71
  - [BGridProps](#bgridprops)
70
72
  - [BGridColumn](#bgridcolumn)
@@ -826,8 +828,9 @@ Enable drag-and-drop or keyboard row sorting:
826
828
 
827
829
  ### 11. Summary Row
828
830
 
829
- Add top or bottom summary/aggregation rows:
831
+ Add top or bottom summary/aggregation rows (supports both single-row and multi-row configurations):
830
832
 
833
+ #### Single-Row Summary
831
834
  ```typescript jsx
832
835
  <BGrid
833
836
  width={800}
@@ -840,7 +843,7 @@ Add top or bottom summary/aggregation rows:
840
843
  columns: [
841
844
  { columnIndex: 0, colSpan: 2, itemRender: () => <strong>Total Summary</strong> },
842
845
  {
843
- columnIndex: 3,
846
+ columnIndex: 2,
844
847
  align: 'right',
845
848
  itemRender: ({ data }) => (
846
849
  <strong>${data.reduce((sum, item) => sum + (item.values.amount || 0), 0).toLocaleString()}</strong>
@@ -851,6 +854,48 @@ Add top or bottom summary/aggregation rows:
851
854
  />
852
855
  ```
853
856
 
857
+ #### Multi-Row Summary (e.g. Average & Total)
858
+ ```typescript jsx
859
+ <BGrid
860
+ width={800}
861
+ height={400}
862
+ columns={columns}
863
+ data={data}
864
+ rowKey='id'
865
+ summary={{
866
+ position: 'bottom',
867
+ rows: [
868
+ {
869
+ style: { backgroundColor: '#fffbeb', fontWeight: 600 },
870
+ columns: [
871
+ { columnIndex: 0, colSpan: 2, itemRender: () => <span>Average</span> },
872
+ {
873
+ columnIndex: 2,
874
+ align: 'right',
875
+ itemRender: ({ data }) => (
876
+ <span>${(data.reduce((sum, item) => sum + (item.values.amount || 0), 0) / (data.length || 1)).toFixed(2)}</span>
877
+ ),
878
+ },
879
+ ],
880
+ },
881
+ {
882
+ style: { backgroundColor: '#f1f5f9', fontWeight: 700 },
883
+ columns: [
884
+ { columnIndex: 0, colSpan: 2, itemRender: () => <strong>Total</strong> },
885
+ {
886
+ columnIndex: 2,
887
+ align: 'right',
888
+ itemRender: ({ data }) => (
889
+ <strong>${data.reduce((sum, item) => sum + (item.values.amount || 0), 0).toLocaleString()}</strong>
890
+ ),
891
+ },
892
+ ],
893
+ },
894
+ ],
895
+ }}
896
+ />
897
+ ```
898
+
854
899
  ---
855
900
 
856
901
  ### 12. Cell Merging
@@ -969,6 +1014,45 @@ Rows whose parent is missing are treated as roots. Cycles are contained, the sou
969
1014
 
970
1015
  ---
971
1016
 
1017
+ ### 16. Master-Detail (Nested Grid)
1018
+
1019
+ Expand grid rows to reveal subgrids, nested forms, or detailed child records spanning the full width of the grid with isolated event handling.
1020
+
1021
+ ```typescript jsx
1022
+ const [expandedRowKeys, setExpandedRowKeys] = React.useState(['ORD-001']);
1023
+
1024
+ <BGrid
1025
+ width={800}
1026
+ height={450}
1027
+ columns={columns}
1028
+ data={orders}
1029
+ rowKey='orderId'
1030
+ masterDetail={{
1031
+ expandMode: 'multiple',
1032
+ expandedRowKeys,
1033
+ onExpandedRowKeysChange: setExpandedRowKeys,
1034
+ hasDetail: item => item.values.items.length > 0,
1035
+ detailRowHeight: 180,
1036
+ detailRender: ({ item }) => (
1037
+ <div style={{ padding: 12 }}>
1038
+ <h4>Order Items ({item.values.items.length})</h4>
1039
+ <BGrid
1040
+ width={760}
1041
+ height={130}
1042
+ columns={itemColumns}
1043
+ data={item.values.items.map(it => ({ values: it }))}
1044
+ rowKey='itemCode'
1045
+ />
1046
+ </div>
1047
+ ),
1048
+ }}
1049
+ />;
1050
+ ```
1051
+
1052
+ Even when frozen columns are configured, the detail panel renders in a unified full-width layer while master row cells preserve their natural row height. Pointer events, clicks, and keystrokes inside the detail view are isolated from parent table selections and shortcuts.
1053
+
1054
+ ---
1055
+
972
1056
  ## Props Reference
973
1057
 
974
1058
  ### BGridProps
@@ -990,8 +1074,11 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
990
1074
  | `data` | `BGridDataItem<T>[]` | Array of row data wrapped in `{ values: T }`. |
991
1075
  | `rowKey` | `React.Key \| React.Key[]` | Unique identifier field in `item.values` (string or array path). |
992
1076
  | `selectedRowKey` | `React.Key \| React.Key[]` | Key of the currently focused/highlighted row. |
993
- | `rowChecked` | `BGridRowChecked<T>` | Checkbox / radio row selection configuration. |
994
- | `getRowClassName` | `(ri: number, item: BGridDataItem<T>) => string \| undefined` | Custom row class name generator. |
1077
+ | `rowChecked` | `BGridRowChecked<T>` | Checkbox / radio row selection configuration. |
1078
+ | `getRowClassName` | `(ri: number, item: BGridDataItem<T>) => string \| undefined` | Custom row class name generator. |
1079
+ | `enableLoadMore` | `boolean` | Enables infinite scroll / load-more mechanism. |
1080
+ | `onLoadMore` | `(params: { scrollLeft: number; scrollTop: number }) => void` | Callback fired when scrolling reaches the load-more threshold. |
1081
+ | `endLoadMoreRender` | `() => React.ReactNode` | Custom renderer for the load-more indicator or end-of-list. |
995
1082
 
996
1083
  #### Layout & Sizing
997
1084
 
@@ -999,7 +1086,8 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
999
1086
  | ------------------- | ----------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------ |
1000
1087
  | `headerHeight` | `number` | `30` | Header row height in pixels. |
1001
1088
  | `bottomBarHeight` | `number` | `30` | Bottom bar (pagination / status) height in pixels. |
1002
- | `summaryHeight` | `number` | `30` | Summary row height in pixels. |
1089
+ | `summaryHeight` | `number` | Auto | Total summary height in pixels. Defaults to `summaryRowHeight * number of rows` (or `30` for single-row). |
1090
+ | `summaryRowHeight` | `number` | `30` | Default height in pixels for each individual summary row. |
1003
1091
  | `itemHeight` | `number` | `15` | Body row content height. |
1004
1092
  | `itemPadding` | `number` | `7` | Body row top/bottom padding (total row height = `itemHeight + itemPadding * 2`). |
1005
1093
  | `getRowHeight` | `(row: T, index: number) => number` | — | Complete rendered height for each displayed row. Invalid values fall back to `itemHeight + itemPadding * 2`. |
@@ -1007,6 +1095,11 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
1007
1095
  | `frozenRowCount` | `number` | `0` | Number of leading rows pinned below the top summary row. |
1008
1096
  | `showLineNumber` | `boolean` | `false` | Shows row index numbers and reorder handles on the left. |
1009
1097
  | `variant` | `'default' \| 'vertical-bordered'` | `'default'` | Visual border styling variant. |
1098
+ | `className` | `string` | — | Custom CSS class name for the root grid container. |
1099
+ | `style` | `React.CSSProperties` | — | Inline styles for the root grid container. |
1100
+ | `disabled` | `boolean` | `false` | Disables user interactions while preserving view and scrolling. |
1101
+ | `scrollTop` | `number` | `0` | Controlled vertical scroll position in pixels. |
1102
+ | `scrollLeft` | `number` | `0` | Controlled horizontal scroll position in pixels. |
1010
1103
 
1011
1104
  #### Columns & Headers
1012
1105
 
@@ -1040,11 +1133,14 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
1040
1133
  | `searchOptions` | `BGridSearchOptions<T>` | Grid in-memory search UI, shortcuts (`Cmd+F`), and highlights. |
1041
1134
  | `contextMenuOptions` | `BGridContextMenuOptions<T>` | Right-click and `Shift+F10` cell context menu items. |
1042
1135
  | `reorder` | `BGridReorderInfo<T>` | Drag and keyboard row reordering configuration. |
1043
- | `summary` | `{ position: 'top' \| 'bottom'; columns: BGridSummaryColumn<T>[] }` | Static summary row configuration. |
1136
+ | `reorderingInfo` | `BGridReorderingInfo` | Reorder drop indicator and dragged state callbacks. |
1137
+ | `summary` | `BGridSummaryOptions<T>` | Static summary row(s) configuration. Supports single row (`columns`) or multiple rows (`rows`). |
1044
1138
  | `cellMergeOptions` | `{ columnsMap: Record<number, BGridCellMergeColumn> }` | Vertical cell merge rules. |
1045
1139
  | `pivot` | `BGridPivotOptions<T>` | Pivot table dimensions, aggregation rules, and metrics. |
1046
1140
  | `columnVisibility` | `boolean \| BGridColumnVisibilityOptions<T>` | Enables controlled or uncontrolled column hiding and restore controls (since `1.0.6`). |
1141
+ | `icons` | `BGridToolboxIcons` | Custom SVG / ReactNode icons for column toolbox, filter, and sort buttons. |
1047
1142
  | `tree` | `BGridTreeOptions<T>` | Renders flat parent-key data as collapsible hierarchical rows. |
1143
+ | `masterDetail` | `BGridMasterDetailOptions<T>` | Expands rows to display nested subgrids, forms, or custom detail panels. |
1048
1144
  | `loading` | `boolean` | Displays full-grid loading overlay. |
1049
1145
  | `spinning` | `boolean` | Displays body-area spinner. |
1050
1146
  | `msg` | `{ emptyList?: string }` | Custom empty state text. |
@@ -1120,6 +1216,25 @@ interface BGridDataControl {
1120
1216
  }
1121
1217
  ```
1122
1218
 
1219
+ #### `BGridMasterDetailOptions`
1220
+
1221
+ ```typescript
1222
+ interface BGridMasterDetailOptions<T> {
1223
+ expandMode?: 'multiple' | 'single';
1224
+ expandedRowKeys?: React.Key[];
1225
+ defaultExpandedRowKeys?: React.Key[];
1226
+ onExpandedRowKeysChange?: (
1227
+ expandedRowKeys: React.Key[],
1228
+ event: BGridMasterDetailChangeEvent<T>,
1229
+ ) => void;
1230
+ hasDetail?: (item: BGridDataItem<T>, index: number) => boolean;
1231
+ detailRowHeight?: number;
1232
+ detailRender: (props: BGridMasterDetailRenderProps<T>) => React.ReactNode;
1233
+ expandColumnId?: string;
1234
+ icons?: BGridMasterDetailIcons;
1235
+ }
1236
+ ```
1237
+
1123
1238
  ---
1124
1239
 
1125
1240
  ## Developer Workflows