beautiful-grid 1.0.14 → 1.0.16

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 (50) hide show
  1. package/README.md +124 -7
  2. package/cjs/BGrid.js +376 -42
  3. package/cjs/components/CellNavigationDomSync.js +8 -0
  4. package/cjs/components/CellTextEditorGateway.js +14 -10
  5. package/cjs/components/ColResizer.js +13 -8
  6. package/cjs/components/MasterDetailCell.js +145 -0
  7. package/cjs/components/MasterDetailContext.js +42 -0
  8. package/cjs/components/Pagination.js +1 -1
  9. package/cjs/components/Table.js +219 -107
  10. package/cjs/components/TableBody.js +7 -25
  11. package/cjs/components/TableBodyCell.js +2 -1
  12. package/cjs/components/TableBodyRow.js +3 -3
  13. package/cjs/components/TableColGroupFrozen.js +1 -1
  14. package/cjs/store/createAppStore.js +1 -1
  15. package/cjs/utils/cellSelectionGeometry.js +32 -6
  16. package/cjs/utils/createPivotData.js +1 -1
  17. package/cjs/utils/rowHeightMetrics.js +47 -6
  18. package/cjs/utils/useForceUpdate.js +1 -1
  19. package/cjs/utils/useRowReorderController.js +5 -1
  20. package/esm/BGrid.js +376 -69
  21. package/esm/components/CellNavigationDomSync.js +8 -0
  22. package/esm/components/CellTextEditorGateway.js +13 -10
  23. package/esm/components/ColResizer.js +8 -3
  24. package/esm/components/MasterDetailCell.js +101 -0
  25. package/esm/components/MasterDetailContext.js +5 -0
  26. package/esm/components/Pagination.js +1 -1
  27. package/esm/components/Table.js +154 -44
  28. package/esm/components/TableBody.js +9 -24
  29. package/esm/components/TableBodyCell.js +2 -1
  30. package/esm/components/TableBodyRow.js +3 -3
  31. package/esm/components/TableColGroupFrozen.js +1 -1
  32. package/esm/store/createAppStore.js +1 -1
  33. package/esm/utils/cellSelectionGeometry.js +31 -5
  34. package/esm/utils/createPivotData.js +1 -1
  35. package/esm/utils/rowHeightMetrics.js +46 -6
  36. package/esm/utils/useForceUpdate.js +1 -1
  37. package/esm/utils/useRowReorderController.js +5 -1
  38. package/package.json +1 -1
  39. package/style.css +154 -11
  40. package/types/BGrid.d.ts +1 -1
  41. package/types/components/MasterDetailCell.d.ts +21 -0
  42. package/types/components/MasterDetailContext.d.ts +20 -0
  43. package/types/components/Pagination.d.ts +1 -3
  44. package/types/components/TableBody.d.ts +3 -27
  45. package/types/components/TableBodyRow.d.ts +1 -1
  46. package/types/components/TableColGroupFrozen.d.ts +1 -3
  47. package/types/components/TableSummary.d.ts +1 -1
  48. package/types/types.d.ts +54 -0
  49. package/types/utils/cellSelectionGeometry.d.ts +3 -1
  50. 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)
@@ -660,6 +662,7 @@ Cell range selection and clipboard copy/paste are enabled by default.
660
662
  rowKey='id'
661
663
  cellSelectionOptions={{
662
664
  enabled: true,
665
+ multiSelectFocusMode: 'first',
663
666
  clearOnEscape: true,
664
667
  clearOnOutsideClick: true,
665
668
  maxClipboardCells: 100000,
@@ -675,6 +678,7 @@ Cell range selection and clipboard copy/paste are enabled by default.
675
678
 
676
679
  - `Ctrl+C` / `Cmd+C`: Copies selected cells as Tab-separated (`\t`) values and CRLF (`\r\n`) lines, directly pasteable into Excel or Google Sheets.
677
680
  - `Ctrl+V` / `Cmd+V`: Pastes clipboard matrix starting from the focused cell across editable columns.
681
+ - `multiSelectFocusMode: 'last'` makes the last cell selected by a drag the active cell and the paste starting point. The default is `'first'` for backward compatibility.
678
682
  - Customize copied text on a per-column basis with `getClipboardText: ({ value, values }) => string`.
679
683
 
680
684
  ---
@@ -826,8 +830,9 @@ Enable drag-and-drop or keyboard row sorting:
826
830
 
827
831
  ### 11. Summary Row
828
832
 
829
- Add top or bottom summary/aggregation rows:
833
+ Add top or bottom summary/aggregation rows (supports both single-row and multi-row configurations):
830
834
 
835
+ #### Single-Row Summary
831
836
  ```typescript jsx
832
837
  <BGrid
833
838
  width={800}
@@ -840,7 +845,7 @@ Add top or bottom summary/aggregation rows:
840
845
  columns: [
841
846
  { columnIndex: 0, colSpan: 2, itemRender: () => <strong>Total Summary</strong> },
842
847
  {
843
- columnIndex: 3,
848
+ columnIndex: 2,
844
849
  align: 'right',
845
850
  itemRender: ({ data }) => (
846
851
  <strong>${data.reduce((sum, item) => sum + (item.values.amount || 0), 0).toLocaleString()}</strong>
@@ -851,6 +856,48 @@ Add top or bottom summary/aggregation rows:
851
856
  />
852
857
  ```
853
858
 
859
+ #### Multi-Row Summary (e.g. Average & Total)
860
+ ```typescript jsx
861
+ <BGrid
862
+ width={800}
863
+ height={400}
864
+ columns={columns}
865
+ data={data}
866
+ rowKey='id'
867
+ summary={{
868
+ position: 'bottom',
869
+ rows: [
870
+ {
871
+ style: { backgroundColor: '#fffbeb', fontWeight: 600 },
872
+ columns: [
873
+ { columnIndex: 0, colSpan: 2, itemRender: () => <span>Average</span> },
874
+ {
875
+ columnIndex: 2,
876
+ align: 'right',
877
+ itemRender: ({ data }) => (
878
+ <span>${(data.reduce((sum, item) => sum + (item.values.amount || 0), 0) / (data.length || 1)).toFixed(2)}</span>
879
+ ),
880
+ },
881
+ ],
882
+ },
883
+ {
884
+ style: { backgroundColor: '#f1f5f9', fontWeight: 700 },
885
+ columns: [
886
+ { columnIndex: 0, colSpan: 2, itemRender: () => <strong>Total</strong> },
887
+ {
888
+ columnIndex: 2,
889
+ align: 'right',
890
+ itemRender: ({ data }) => (
891
+ <strong>${data.reduce((sum, item) => sum + (item.values.amount || 0), 0).toLocaleString()}</strong>
892
+ ),
893
+ },
894
+ ],
895
+ },
896
+ ],
897
+ }}
898
+ />
899
+ ```
900
+
854
901
  ---
855
902
 
856
903
  ### 12. Cell Merging
@@ -969,6 +1016,45 @@ Rows whose parent is missing are treated as roots. Cycles are contained, the sou
969
1016
 
970
1017
  ---
971
1018
 
1019
+ ### 16. Master-Detail (Nested Grid)
1020
+
1021
+ Expand grid rows to reveal subgrids, nested forms, or detailed child records spanning the full width of the grid with isolated event handling.
1022
+
1023
+ ```typescript jsx
1024
+ const [expandedRowKeys, setExpandedRowKeys] = React.useState(['ORD-001']);
1025
+
1026
+ <BGrid
1027
+ width={800}
1028
+ height={450}
1029
+ columns={columns}
1030
+ data={orders}
1031
+ rowKey='orderId'
1032
+ masterDetail={{
1033
+ expandMode: 'multiple',
1034
+ expandedRowKeys,
1035
+ onExpandedRowKeysChange: setExpandedRowKeys,
1036
+ hasDetail: item => item.values.items.length > 0,
1037
+ detailRowHeight: 180,
1038
+ detailRender: ({ item }) => (
1039
+ <div style={{ padding: 12 }}>
1040
+ <h4>Order Items ({item.values.items.length})</h4>
1041
+ <BGrid
1042
+ width={760}
1043
+ height={130}
1044
+ columns={itemColumns}
1045
+ data={item.values.items.map(it => ({ values: it }))}
1046
+ rowKey='itemCode'
1047
+ />
1048
+ </div>
1049
+ ),
1050
+ }}
1051
+ />;
1052
+ ```
1053
+
1054
+ 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.
1055
+
1056
+ ---
1057
+
972
1058
  ## Props Reference
973
1059
 
974
1060
  ### BGridProps
@@ -990,8 +1076,11 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
990
1076
  | `data` | `BGridDataItem<T>[]` | Array of row data wrapped in `{ values: T }`. |
991
1077
  | `rowKey` | `React.Key \| React.Key[]` | Unique identifier field in `item.values` (string or array path). |
992
1078
  | `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. |
1079
+ | `rowChecked` | `BGridRowChecked<T>` | Checkbox / radio row selection configuration. |
1080
+ | `getRowClassName` | `(ri: number, item: BGridDataItem<T>) => string \| undefined` | Custom row class name generator. |
1081
+ | `enableLoadMore` | `boolean` | Enables infinite scroll / load-more mechanism. |
1082
+ | `onLoadMore` | `(params: { scrollLeft: number; scrollTop: number }) => void` | Callback fired when scrolling reaches the load-more threshold. |
1083
+ | `endLoadMoreRender` | `() => React.ReactNode` | Custom renderer for the load-more indicator or end-of-list. |
995
1084
 
996
1085
  #### Layout & Sizing
997
1086
 
@@ -999,7 +1088,8 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
999
1088
  | ------------------- | ----------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------ |
1000
1089
  | `headerHeight` | `number` | `30` | Header row height in pixels. |
1001
1090
  | `bottomBarHeight` | `number` | `30` | Bottom bar (pagination / status) height in pixels. |
1002
- | `summaryHeight` | `number` | `30` | Summary row height in pixels. |
1091
+ | `summaryHeight` | `number` | Auto | Total summary height in pixels. Defaults to `summaryRowHeight * number of rows` (or `30` for single-row). |
1092
+ | `summaryRowHeight` | `number` | `30` | Default height in pixels for each individual summary row. |
1003
1093
  | `itemHeight` | `number` | `15` | Body row content height. |
1004
1094
  | `itemPadding` | `number` | `7` | Body row top/bottom padding (total row height = `itemHeight + itemPadding * 2`). |
1005
1095
  | `getRowHeight` | `(row: T, index: number) => number` | — | Complete rendered height for each displayed row. Invalid values fall back to `itemHeight + itemPadding * 2`. |
@@ -1007,6 +1097,11 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
1007
1097
  | `frozenRowCount` | `number` | `0` | Number of leading rows pinned below the top summary row. |
1008
1098
  | `showLineNumber` | `boolean` | `false` | Shows row index numbers and reorder handles on the left. |
1009
1099
  | `variant` | `'default' \| 'vertical-bordered'` | `'default'` | Visual border styling variant. |
1100
+ | `className` | `string` | — | Custom CSS class name for the root grid container. |
1101
+ | `style` | `React.CSSProperties` | — | Inline styles for the root grid container. |
1102
+ | `disabled` | `boolean` | `false` | Disables user interactions while preserving view and scrolling. |
1103
+ | `scrollTop` | `number` | `0` | Controlled vertical scroll position in pixels. |
1104
+ | `scrollLeft` | `number` | `0` | Controlled horizontal scroll position in pixels. |
1010
1105
 
1011
1106
  #### Columns & Headers
1012
1107
 
@@ -1025,7 +1120,7 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
1025
1120
  | `onChangeData` | `(index, columnIndex, item, column, meta) => void` | - | Callback fired after a cell edit commits. |
1026
1121
  | `onClick` | `(params: BGridClickParams<T>) => void` | - | Cell click callback. |
1027
1122
  | `cellNavigationOptions` | `BGridCellNavigationOptions` | - | Active cell focus, arrow key navigation, and repeat options. |
1028
- | `cellSelectionOptions` | `BGridCellSelectionOptions` | - | Range drag selection and clipboard copy/paste options. |
1123
+ | `cellSelectionOptions` | `BGridCellSelectionOptions` | - | Range drag selection, active-cell focus, and clipboard copy/paste options. |
1029
1124
 
1030
1125
  #### Additional Features & Overlays
1031
1126
 
@@ -1040,11 +1135,14 @@ Below is a categorized reference of `<BGrid>` props. For exact TypeScript types,
1040
1135
  | `searchOptions` | `BGridSearchOptions<T>` | Grid in-memory search UI, shortcuts (`Cmd+F`), and highlights. |
1041
1136
  | `contextMenuOptions` | `BGridContextMenuOptions<T>` | Right-click and `Shift+F10` cell context menu items. |
1042
1137
  | `reorder` | `BGridReorderInfo<T>` | Drag and keyboard row reordering configuration. |
1043
- | `summary` | `{ position: 'top' \| 'bottom'; columns: BGridSummaryColumn<T>[] }` | Static summary row configuration. |
1138
+ | `reorderingInfo` | `BGridReorderingInfo` | Reorder drop indicator and dragged state callbacks. |
1139
+ | `summary` | `BGridSummaryOptions<T>` | Static summary row(s) configuration. Supports single row (`columns`) or multiple rows (`rows`). |
1044
1140
  | `cellMergeOptions` | `{ columnsMap: Record<number, BGridCellMergeColumn> }` | Vertical cell merge rules. |
1045
1141
  | `pivot` | `BGridPivotOptions<T>` | Pivot table dimensions, aggregation rules, and metrics. |
1046
1142
  | `columnVisibility` | `boolean \| BGridColumnVisibilityOptions<T>` | Enables controlled or uncontrolled column hiding and restore controls (since `1.0.6`). |
1143
+ | `icons` | `BGridToolboxIcons` | Custom SVG / ReactNode icons for column toolbox, filter, and sort buttons. |
1047
1144
  | `tree` | `BGridTreeOptions<T>` | Renders flat parent-key data as collapsible hierarchical rows. |
1145
+ | `masterDetail` | `BGridMasterDetailOptions<T>` | Expands rows to display nested subgrids, forms, or custom detail panels. |
1048
1146
  | `loading` | `boolean` | Displays full-grid loading overlay. |
1049
1147
  | `spinning` | `boolean` | Displays body-area spinner. |
1050
1148
  | `msg` | `{ emptyList?: string }` | Custom empty state text. |
@@ -1120,6 +1218,25 @@ interface BGridDataControl {
1120
1218
  }
1121
1219
  ```
1122
1220
 
1221
+ #### `BGridMasterDetailOptions`
1222
+
1223
+ ```typescript
1224
+ interface BGridMasterDetailOptions<T> {
1225
+ expandMode?: 'multiple' | 'single';
1226
+ expandedRowKeys?: React.Key[];
1227
+ defaultExpandedRowKeys?: React.Key[];
1228
+ onExpandedRowKeysChange?: (
1229
+ expandedRowKeys: React.Key[],
1230
+ event: BGridMasterDetailChangeEvent<T>,
1231
+ ) => void;
1232
+ hasDetail?: (item: BGridDataItem<T>, index: number) => boolean;
1233
+ detailRowHeight?: number;
1234
+ detailRender: (props: BGridMasterDetailRenderProps<T>) => React.ReactNode;
1235
+ expandColumnId?: string;
1236
+ icons?: BGridMasterDetailIcons;
1237
+ }
1238
+ ```
1239
+
1123
1240
  ---
1124
1241
 
1125
1242
  ## Developer Workflows