@stramien/core 0.13.1 → 0.15.0

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/dist/index.d.ts CHANGED
@@ -414,7 +414,11 @@ interface CellValueChangedEvent<TData = Record<string, unknown>, TValue = unknow
414
414
  }
415
415
  interface ColumnStateItem {
416
416
  colId: string;
417
- width: number;
417
+ /**
418
+ * Left out with `fitColumns` for columns the grid sizes itself, so restoring the state
419
+ * keeps only the widths the user chose.
420
+ */
421
+ width?: number;
418
422
  pinned: PinnedDirection;
419
423
  hide: boolean;
420
424
  }
@@ -547,7 +551,11 @@ interface ColDef<TData = Record<string, unknown>, TValue = unknown> {
547
551
  width?: number;
548
552
  minWidth?: number;
549
553
  maxWidth?: number;
550
- /** Distributes remaining horizontal viewport width proportionally. Set `minWidth` when combined with `wrapText`. */
554
+ /**
555
+ * Takes this share of the width the other columns leave (`flex: 2` gets twice what
556
+ * `flex: 1` gets), following the grid's width. Set `minWidth` when combined with `wrapText`.
557
+ * Ignored with `GridOptions.fitColumns`, which sizes every column.
558
+ */
551
559
  flex?: number;
552
560
  resizable?: boolean;
553
561
  movable?: boolean;
@@ -653,7 +661,12 @@ interface RowSelectionConfig<TData = Record<string, unknown>> {
653
661
  enableClickSelection?: boolean;
654
662
  isRowSelectable?: (node: RowNode<TData>) => boolean;
655
663
  }
656
- type GridThemeMode = 'auto' | 'light' | 'dark';
664
+ /**
665
+ * `'auto'` follows the operating system, `'light'` and `'dark'` force one, `'inherit'`
666
+ * follows the `color-scheme` of the page (or a wrapper element), for apps with their own
667
+ * light/dark switch.
668
+ */
669
+ type GridThemeMode = 'auto' | 'light' | 'dark' | 'inherit';
657
670
  type GridDensity = 'default' | 'compact' | 'comfortable';
658
671
  interface GridReadyEvent<TData = Record<string, unknown>> {
659
672
  api: GridApi<TData>;
@@ -717,6 +730,16 @@ interface PaginationChangedEvent<TData = Record<string, unknown>> {
717
730
  totalRows: number;
718
731
  totalPages: number;
719
732
  }
733
+ interface RowsNearEndEvent<TData = Record<string, unknown>> {
734
+ api: GridApi<TData>;
735
+ /**
736
+ * Index of the last row the user can see, among the displayed (filtered, sorted) rows;
737
+ * `-1` when there are no rows.
738
+ */
739
+ lastVisibleRowIndex: number;
740
+ /** Number of displayed rows. */
741
+ rowCount: number;
742
+ }
720
743
  interface GridEventMap<TData = Record<string, unknown>> {
721
744
  gridReady: GridReadyEvent<TData>;
722
745
  rowClicked: RowClickedEvent<TData>;
@@ -735,6 +758,7 @@ interface GridEventMap<TData = Record<string, unknown>> {
735
758
  treeNodeToggled: TreeNodeToggledEvent<TData>;
736
759
  cellSelectionChanged: CellSelectionChangedEvent<TData>;
737
760
  treeExpansionChanged: TreeExpansionChangedEvent<TData>;
761
+ rowsNearEnd: RowsNearEndEvent<TData>;
738
762
  }
739
763
  /** Top-level configuration options for `createGrid()`, `<stramien-grid>`, and `<StramienGrid>`. */
740
764
  interface GridOptions<TData = Record<string, unknown>> {
@@ -862,6 +886,14 @@ interface GridOptions<TData = Record<string, unknown>> {
862
886
  top?: string;
863
887
  };
864
888
  rowHeight?: number;
889
+ /**
890
+ * The columns always fill the grid's width exactly, in proportion to their `width`: on
891
+ * first display, when the grid resizes, and when columns are shown, hidden or pinned. A
892
+ * column the user resizes keeps that width (also in `getState`), and the others fit around
893
+ * it; `resetState()` lets it fit again. Columns never go below their `minWidth`: when they
894
+ * do not fit, the grid scrolls sideways.
895
+ */
896
+ fitColumns?: boolean;
865
897
  /**
866
898
  * Height in px of one body row, from its data, for rows whose height is known before they
867
899
  * render. Return `undefined` for `rowHeight`. With `autoHeight` columns it is the row's
@@ -912,6 +944,17 @@ interface GridOptions<TData = Record<string, unknown>> {
912
944
  onTreeNodeToggled?: (event: TreeNodeToggledEvent<TData>) => void;
913
945
  onTreeExpansionChanged?: (event: TreeExpansionChangedEvent<TData>) => void;
914
946
  onCellSelectionChanged?: (event: CellSelectionChangedEvent<TData>) => void;
947
+ /**
948
+ * Called when the user scrolls to within `rowsNearEndThreshold` rows of the last row, so the
949
+ * app can load the next batch (infinite scroll with client-side row data). It fires once per
950
+ * row count, not on every scroll: again after rows were added or the row data was replaced,
951
+ * or after the user scrolled away from the end and back (to retry a failed load).
952
+ * It also fires when the rows don't fill the grid, including when there are none. Not
953
+ * called while `loading` is set, with pagination or with the server-side row model.
954
+ */
955
+ onRowsNearEnd?: (event: RowsNearEndEvent<TData>) => void;
956
+ /** How many rows before the end `onRowsNearEnd` fires (default `10`). */
957
+ rowsNearEndThreshold?: number;
915
958
  }
916
959
  interface PaginationState {
917
960
  enabled: boolean;
@@ -1078,6 +1121,15 @@ interface HeaderGroupRowZones {
1078
1121
  declare class ColumnController<TData = Record<string, unknown>> {
1079
1122
  private columns;
1080
1123
  private manualWidths;
1124
+ /** `fitColumns`: the columns fill the width, except the ones in `userWidths`. */
1125
+ private fitColumns;
1126
+ /**
1127
+ * Columns the user (or `setColumnWidth`) resized: `fitColumns` keeps their width and fits
1128
+ * the others around them. Cleared by resetUserState().
1129
+ */
1130
+ private userWidths;
1131
+ /** Each column's width as defined, before user changes: the weights of `fitColumns`. */
1132
+ private baseWidths;
1081
1133
  private viewportWidth;
1082
1134
  private responsivePinning;
1083
1135
  private pinningCollapsed;
@@ -1163,6 +1215,13 @@ declare class ColumnController<TData = Record<string, unknown>> {
1163
1215
  widthsChanged: boolean;
1164
1216
  zonesChanged: boolean;
1165
1217
  };
1218
+ setFitColumns(fit: boolean): void;
1219
+ /**
1220
+ * Sizes the columns that follow the width: with `fitColumns` all of them except the ones
1221
+ * the user resized, in proportion to their defined widths; otherwise the `flex` columns,
1222
+ * in proportion to their `flex`. Both fill `availableWidth` exactly where the min and max
1223
+ * widths allow. Returns whether a width changed.
1224
+ */
1166
1225
  applyFlexWidths(availableWidth: number): boolean;
1167
1226
  setColumnWidth(colId: string, requestedWidth: number): number | null;
1168
1227
  setColumnPinned(colId: string, pinned: PinnedDirection): boolean;
@@ -1266,16 +1325,21 @@ interface BadgeStyleConfig {
1266
1325
  bg?: string;
1267
1326
  color?: string;
1268
1327
  }
1269
- interface BadgeColumnOptions {
1270
- /** Maps raw cell values to a semantic tone or custom label/color config. */
1271
- map?: Record<string, BadgeTone | BadgeStyleConfig>;
1328
+ interface BadgeColumnOptions<TData = Record<string, unknown>> {
1329
+ /**
1330
+ * Maps raw cell values to a semantic tone or custom label/color config. Either an object
1331
+ * keyed by value, or a function `(value, data) => tone | config` for open-ended values (for
1332
+ * example `(v) => (v.startsWith('delete') ? 'danger' : undefined)`). Values the map doesn't
1333
+ * cover, and a function returning `undefined`, use `defaultTone`.
1334
+ */
1335
+ map?: Record<string, BadgeTone | BadgeStyleConfig> | ((value: string, data: TData) => BadgeTone | BadgeStyleConfig | null | undefined);
1272
1336
  /** Fallback tone when a value is not present in `map` (default `'neutral'`). */
1273
1337
  defaultTone?: BadgeTone;
1274
1338
  /** Render a subtle status indicator dot before the label (default `false`). */
1275
1339
  dot?: boolean;
1276
1340
  }
1277
1341
  /** Built-in theme-aware pill / status badge column preset. */
1278
- declare function badgeColumn<TData = Record<string, unknown>>(options?: BadgeColumnOptions): Partial<ColDef<TData, string>>;
1342
+ declare function badgeColumn<TData = Record<string, unknown>>(options?: BadgeColumnOptions<TData>): Partial<ColDef<TData, string>>;
1279
1343
  interface BooleanColumnOptions {
1280
1344
  /** Visual presentation: `'icon'` (default), `'pill'`, or `'text'`. */
1281
1345
  style?: 'icon' | 'pill' | 'text';
@@ -1446,6 +1510,8 @@ declare class StramienGridCore<TData = Record<string, unknown>> {
1446
1510
  /** `applyTransactionAsync` queue, and the timer that applies it. */
1447
1511
  private asyncQueue;
1448
1512
  private asyncTimer;
1513
+ /** Row count `onRowsNearEnd` last fired for (-1: not fired since the data was set). */
1514
+ private rowsNearEndFiredCount;
1449
1515
  private readonly onAsyncVisibilityChange;
1450
1516
  private readonly onVisibilityChange;
1451
1517
  readonly api: GridApi<TData>;
@@ -1571,6 +1637,7 @@ declare class StramienGridCore<TData = Record<string, unknown>> {
1571
1637
  */
1572
1638
  private mergeTransactions;
1573
1639
  private scheduleAsyncFlush;
1640
+ private handleVisibleRowsEnd;
1574
1641
  private clearAsyncQueue;
1575
1642
  private flushAsyncTransactions;
1576
1643
  private handleToggleRowSelection;
@@ -1746,7 +1813,8 @@ declare class EventBus<TEventMap extends {
1746
1813
  on<K extends keyof TEventMap>(event: K, listener: EventListener<TEventMap[K]>): () => void;
1747
1814
  off<K extends keyof TEventMap>(event: K, listener: EventListener<TEventMap[K]>): void;
1748
1815
  emit<K extends keyof TEventMap>(event: K, payload: TEventMap[K]): void;
1816
+ hasListeners<K extends keyof TEventMap>(event: K): boolean;
1749
1817
  clear(): void;
1750
1818
  }
1751
1819
 
1752
- export { type ActionButtonDef, type ActionButtonParams, type ActionButtonTone, type ActionButtonVariant, type ActionsColumnOptions, type AggFunc, type AggFuncParams, type BadgeColumnOptions, type BadgeStyleConfig, type BadgeTone, type BarColumnOptions, type BarColumnThresholds, type BooleanColumnOptions, type BuiltInActionIcon, type BuiltInAggFunc, type CellClassParams, type CellClickedEvent, type CellEditorComponentParams, type CellEditorOption, type CellEditorParams, type CellEditorSelectorParams, type CellEditorSpec, type CellEditorType, type CellRange, type CellRangeParams, type CellRenderer, type CellRendererParams, type CellSelectionChangedEvent, type CellSelectionConfig, type CellValidatorParams, type CellValueChangedEvent, type ColDef, type ColGroupDef, ColumnController, type ColumnDefItem, type ColumnFilterModel, type ColumnMovedEvent, type ColumnPinnedEvent, type ColumnResizedEvent, type ColumnStateItem, type ColumnTypeDef, type ColumnVisibilityChangedEvent, type ComponentMountAdapter, type CsvExportParams, type CurrencyColumnOptions, type CustomFilterDef, DETAIL_COL_ID, type DateFilterModel, type DateFilterOperator, type DetailCellRenderer, type DetailCellRendererParams, type EditableParams, EventBus, type FilterChangedEvent, type FilterModel, type FilterType, type GlobalSearchConfig, type GridApi, type GridDensity, type GridEventMap, type GridOptions, type GridReadyEvent, type GridState, type GridThemeMode, type HeaderGroupMeta, LocaleText, type MountedComponentHandle, type NumberFilterModel, type NumberFilterOperator, type PaginationChangedEvent, type PaginationState, type PercentColumnOptions, type PinnedDirection, type PinnedSummaryConfig, type QuickFilterTextParams, type RefreshCellsParams, type RelativeTimeColumnOptions, type ResolvedColDef, type ResponsivePinningConfig, type RowClickedEvent, type RowDataTransaction, type RowDataTransactionResult, type RowDetailToggledEvent, type RowHeightParams, type RowHrefParams, RowModel, type RowModelType, type RowNode, type RowSelectionConfig, SELECTION_COL_ID, type ScrollAlign, type SelectionChangedEvent, SelectionController, type ServerSideDatasource, type ServerSideGetRowsRequest, type ServerSideGetRowsResult, type SetFilterModel, type SortChangedEvent, type SortDirection, type SortModelItem, type SparklineColumnOptions, type StateChangedEvent, StramienGridCore, type TextFilterModel, type TextFilterOperator, type TreeExpandAllControl, type TreeExpansionChangeSource, type TreeExpansionChangedEvent, type TreeNodeToggledEvent, type TreeToggleLabelParams, UndoRedoStack, VANILLA_RENDERER_SYMBOL, type ValueFormatterParams, type ValueGetterParams, type ValueParserParams, type ValueSetterParams, type VanillaCellEditorFn, type VanillaCellEditorInstance, type VanillaCellRendererFn, type VanillaDetailCellRendererFn, type VirtualizationConfig, actionsColumn, badgeColumn, barColumn, booleanColumn, buildCsvString, buildQuickFilterHaystack, buildTsvString, createBuiltInColumnTypes, createGrid, currencyColumn, downloadCsvFile, filterRowNodes, getFormattedCellValue, getRawCellValue, isColGroupDef, markVanillaRenderer, matchesColumnFilter, normalizeSelectionConfig, parseQuickFilterTokens, percentColumn, relativeTimeColumn, resolveColumnFilterType, sortRowNodes, sparklineColumn };
1820
+ export { type ActionButtonDef, type ActionButtonParams, type ActionButtonTone, type ActionButtonVariant, type ActionsColumnOptions, type AggFunc, type AggFuncParams, type BadgeColumnOptions, type BadgeStyleConfig, type BadgeTone, type BarColumnOptions, type BarColumnThresholds, type BooleanColumnOptions, type BuiltInActionIcon, type BuiltInAggFunc, type CellClassParams, type CellClickedEvent, type CellEditorComponentParams, type CellEditorOption, type CellEditorParams, type CellEditorSelectorParams, type CellEditorSpec, type CellEditorType, type CellRange, type CellRangeParams, type CellRenderer, type CellRendererParams, type CellSelectionChangedEvent, type CellSelectionConfig, type CellValidatorParams, type CellValueChangedEvent, type ColDef, type ColGroupDef, ColumnController, type ColumnDefItem, type ColumnFilterModel, type ColumnMovedEvent, type ColumnPinnedEvent, type ColumnResizedEvent, type ColumnStateItem, type ColumnTypeDef, type ColumnVisibilityChangedEvent, type ComponentMountAdapter, type CsvExportParams, type CurrencyColumnOptions, type CustomFilterDef, DETAIL_COL_ID, type DateFilterModel, type DateFilterOperator, type DetailCellRenderer, type DetailCellRendererParams, type EditableParams, EventBus, type FilterChangedEvent, type FilterModel, type FilterType, type GlobalSearchConfig, type GridApi, type GridDensity, type GridEventMap, type GridOptions, type GridReadyEvent, type GridState, type GridThemeMode, type HeaderGroupMeta, LocaleText, type MountedComponentHandle, type NumberFilterModel, type NumberFilterOperator, type PaginationChangedEvent, type PaginationState, type PercentColumnOptions, type PinnedDirection, type PinnedSummaryConfig, type QuickFilterTextParams, type RefreshCellsParams, type RelativeTimeColumnOptions, type ResolvedColDef, type ResponsivePinningConfig, type RowClickedEvent, type RowDataTransaction, type RowDataTransactionResult, type RowDetailToggledEvent, type RowHeightParams, type RowHrefParams, RowModel, type RowModelType, type RowNode, type RowSelectionConfig, type RowsNearEndEvent, SELECTION_COL_ID, type ScrollAlign, type SelectionChangedEvent, SelectionController, type ServerSideDatasource, type ServerSideGetRowsRequest, type ServerSideGetRowsResult, type SetFilterModel, type SortChangedEvent, type SortDirection, type SortModelItem, type SparklineColumnOptions, type StateChangedEvent, StramienGridCore, type TextFilterModel, type TextFilterOperator, type TreeExpandAllControl, type TreeExpansionChangeSource, type TreeExpansionChangedEvent, type TreeNodeToggledEvent, type TreeToggleLabelParams, UndoRedoStack, VANILLA_RENDERER_SYMBOL, type ValueFormatterParams, type ValueGetterParams, type ValueParserParams, type ValueSetterParams, type VanillaCellEditorFn, type VanillaCellEditorInstance, type VanillaCellRendererFn, type VanillaDetailCellRendererFn, type VirtualizationConfig, actionsColumn, badgeColumn, barColumn, booleanColumn, buildCsvString, buildQuickFilterHaystack, buildTsvString, createBuiltInColumnTypes, createGrid, currencyColumn, downloadCsvFile, filterRowNodes, getFormattedCellValue, getRawCellValue, isColGroupDef, markVanillaRenderer, matchesColumnFilter, normalizeSelectionConfig, parseQuickFilterTokens, percentColumn, relativeTimeColumn, resolveColumnFilterType, sortRowNodes, sparklineColumn };
package/dist/index.js CHANGED
@@ -63,6 +63,15 @@ function distributeWidths(cols, total) {
63
63
  var ColumnController = class {
64
64
  columns = [];
65
65
  manualWidths = /* @__PURE__ */ new Set();
66
+ /** `fitColumns`: the columns fill the width, except the ones in `userWidths`. */
67
+ fitColumns = false;
68
+ /**
69
+ * Columns the user (or `setColumnWidth`) resized: `fitColumns` keeps their width and fits
70
+ * the others around them. Cleared by resetUserState().
71
+ */
72
+ userWidths = /* @__PURE__ */ new Set();
73
+ /** Each column's width as defined, before user changes: the weights of `fitColumns`. */
74
+ baseWidths = /* @__PURE__ */ new Map();
66
75
  viewportWidth = 0;
67
76
  responsivePinning = {
68
77
  enabled: true,
@@ -95,6 +104,7 @@ var ColumnController = class {
95
104
  /** Forget user column changes; the next setColumnDefs uses the definitions as written. */
96
105
  resetUserState() {
97
106
  this.userOverrides.clear();
107
+ this.userWidths.clear();
98
108
  this.userOrder = null;
99
109
  this.userRowGroup = null;
100
110
  }
@@ -328,6 +338,7 @@ var ColumnController = class {
328
338
  }
329
339
  this.declaredRowGroup = declared;
330
340
  this.columns = resolved;
341
+ this.baseWidths = new Map(resolved.map((c) => [c.colId, c.width]));
331
342
  this.manualWidths.clear();
332
343
  this.applyUserState();
333
344
  this.refreshRowGroups(false);
@@ -486,25 +497,37 @@ var ColumnController = class {
486
497
  const zonesChanged = this.updatePinningCollapse();
487
498
  return { widthsChanged, zonesChanged };
488
499
  }
500
+ setFitColumns(fit) {
501
+ this.fitColumns = fit;
502
+ }
503
+ /**
504
+ * Sizes the columns that follow the width: with `fitColumns` all of them except the ones
505
+ * the user resized, in proportion to their defined widths; otherwise the `flex` columns,
506
+ * in proportion to their `flex`. Both fill `availableWidth` exactly where the min and max
507
+ * widths allow. Returns whether a width changed.
508
+ */
489
509
  applyFlexWidths(availableWidth) {
510
+ if (availableWidth <= 0) return false;
490
511
  const visible = this.getVisibleColumns();
491
- const flexCols = visible.filter((c) => (c.flex ?? 0) > 0 && !this.manualWidths.has(c.colId));
492
- if (flexCols.length === 0 || availableWidth <= 0) {
493
- return false;
494
- }
495
- const fixedWidth = visible.filter((c) => !flexCols.includes(c)).reduce((sum, c) => sum + c.width, 0);
512
+ const sized = this.fitColumns ? visible.filter((c) => !this.isSystemColumn(c) && !this.userWidths.has(c.colId)) : visible.filter((c) => (c.flex ?? 0) > 0 && !this.manualWidths.has(c.colId));
513
+ if (sized.length === 0) return false;
514
+ const fixedWidth = visible.filter((c) => !sized.includes(c)).reduce((sum, c) => sum + c.width, 0);
496
515
  const remaining = Math.max(0, availableWidth - fixedWidth);
497
- const totalFlex = flexCols.reduce((sum, c) => sum + (c.flex ?? 0), 0);
498
- if (totalFlex <= 0) return false;
516
+ const widths = distributeWidths(
517
+ sized.map((c) => ({
518
+ weight: this.fitColumns ? this.baseWidths.get(c.colId) ?? c.width : c.flex ?? 0,
519
+ min: c.minWidth,
520
+ max: c.maxWidth
521
+ })),
522
+ remaining
523
+ );
499
524
  let changed = false;
500
- for (const col of flexCols) {
501
- const share = Math.floor(remaining * (col.flex ?? 1) / totalFlex);
502
- const clamped = Math.min(col.maxWidth, Math.max(col.minWidth, share));
503
- if (col.width !== clamped) {
504
- col.width = clamped;
525
+ sized.forEach((col, i) => {
526
+ if (col.width !== widths[i]) {
527
+ col.width = widths[i];
505
528
  changed = true;
506
529
  }
507
- }
530
+ });
508
531
  return changed;
509
532
  }
510
533
  setColumnWidth(colId, requestedWidth) {
@@ -513,7 +536,9 @@ var ColumnController = class {
513
536
  const clamped = Math.round(Math.min(col.maxWidth, Math.max(col.minWidth, requestedWidth)));
514
537
  col.width = clamped;
515
538
  this.manualWidths.add(colId);
539
+ this.userWidths.add(colId);
516
540
  this.setOverride(colId, { width: clamped });
541
+ if (this.fitColumns && this.viewportWidth > 0) this.applyFlexWidths(this.viewportWidth);
517
542
  return clamped;
518
543
  }
519
544
  setColumnPinned(colId, pinned) {
@@ -521,6 +546,7 @@ var ColumnController = class {
521
546
  if (!col || this.isSystemColumn(col) || col.pinned === pinned) return false;
522
547
  col.pinned = pinned;
523
548
  this.setOverride(colId, { pinned });
549
+ if (this.viewportWidth > 0) this.applyFlexWidths(this.viewportWidth);
524
550
  this.updatePinningCollapse();
525
551
  return true;
526
552
  }
@@ -589,7 +615,8 @@ var ColumnController = class {
589
615
  getColumnState() {
590
616
  return this.columns.filter((c) => !this.isSystemColumn(c)).map((c) => ({
591
617
  colId: c.colId,
592
- width: c.width,
618
+ // fitColumns sizes the others again; only a width the user chose is state
619
+ ...this.fitColumns && !this.userWidths.has(c.colId) ? {} : { width: c.width },
593
620
  pinned: c.pinned,
594
621
  hide: c.hide
595
622
  }));
@@ -613,6 +640,7 @@ var ColumnController = class {
613
640
  if (typeof item.width === "number" && Number.isFinite(item.width)) {
614
641
  col.width = Math.round(Math.min(col.maxWidth, Math.max(col.minWidth, item.width)));
615
642
  this.manualWidths.add(col.colId);
643
+ if (this.fitColumns) this.userWidths.add(col.colId);
616
644
  this.setOverride(col.colId, { width: col.width });
617
645
  }
618
646
  ordered.push(col);
@@ -793,10 +821,10 @@ function barColumn(options = {}) {
793
821
  function badgeColumn(options = {}) {
794
822
  const { map = {}, defaultTone = "neutral", dot = false } = options;
795
823
  const renderer = markVanillaRenderer(
796
- ({ value, formattedValue }) => {
824
+ ({ value, formattedValue, data }) => {
797
825
  if (value === null || value === void 0 || value === "") return "";
798
826
  const key = String(value);
799
- const entry = map[key];
827
+ const entry = typeof map === "function" ? map(key, data) : Object.hasOwn(map, key) ? map[key] : void 0;
800
828
  const cfg = typeof entry === "string" ? { tone: entry } : entry ?? {};
801
829
  const tone = cfg.tone ?? defaultTone;
802
830
  const text = cfg.label ?? (formattedValue || key);
@@ -2942,6 +2970,7 @@ var DomRenderer = class {
2942
2970
  /** Content height without `maxHeight`: the page (or a scrolling ancestor) scrolls the rows. */
2943
2971
  pageScroll = false;
2944
2972
  pageScrollHandler = null;
2973
+ nearEndRafId = null;
2945
2974
  pageResizeHandler = null;
2946
2975
  headerStackEl;
2947
2976
  rowHeightProbeEl = null;
@@ -3234,7 +3263,10 @@ var DomRenderer = class {
3234
3263
  if (pageScroll === this.pageScroll) return;
3235
3264
  this.pageScroll = pageScroll;
3236
3265
  if (pageScroll) {
3237
- this.pageScrollHandler = () => this.rewindowIfNeeded();
3266
+ this.pageScrollHandler = () => {
3267
+ this.rewindowIfNeeded();
3268
+ this.scheduleVisibleEndCheck();
3269
+ };
3238
3270
  this.pageResizeHandler = () => {
3239
3271
  this.syncStickyInset();
3240
3272
  this.rewindowIfNeeded();
@@ -3744,6 +3776,29 @@ var DomRenderer = class {
3744
3776
  }
3745
3777
  handleVerticalScroll() {
3746
3778
  this.rewindowIfNeeded();
3779
+ this.scheduleVisibleEndCheck();
3780
+ }
3781
+ /** Reports the last visible row once per frame (see `onVisibleRowsEnd`). */
3782
+ scheduleVisibleEndCheck() {
3783
+ if (this.nearEndRafId !== null || !this.callbacks.wantsVisibleRowsEnd()) return;
3784
+ this.nearEndRafId = requestAnimationFrame(() => {
3785
+ this.nearEndRafId = null;
3786
+ this.reportVisibleRowsEnd();
3787
+ });
3788
+ }
3789
+ reportVisibleRowsEnd() {
3790
+ if (this.destroyed || this.callbacks.getLoading()) return;
3791
+ const rowCount = this.callbacks.getDisplayedRows().length;
3792
+ if (rowCount === 0) {
3793
+ this.callbacks.onVisibleRowsEnd(-1, 0);
3794
+ return;
3795
+ }
3796
+ if (this.heightIndex.getCount() !== rowCount) return;
3797
+ const top = this.pageScroll ? this.getPageScrollPastBody() : this.getBodyScrollTop();
3798
+ const bottom = top + this.getBodyViewportHeight();
3799
+ if (bottom <= 0) return;
3800
+ const last = this.heightIndex.findRowAtOffset(Math.max(0, bottom - 1));
3801
+ this.callbacks.onVisibleRowsEnd(last, rowCount);
3747
3802
  }
3748
3803
  /** Re-renders the body when the visible row range changed (scroll or viewport resize). */
3749
3804
  rewindowIfNeeded() {
@@ -4696,6 +4751,7 @@ var DomRenderer = class {
4696
4751
  }
4697
4752
  if (rows.length === 0) {
4698
4753
  const suspended2 = clearToOverlay();
4754
+ this.scheduleVisibleEndCheck();
4699
4755
  this.overlayEl.hidden = false;
4700
4756
  this.overlayEl.innerHTML = "";
4701
4757
  const msg = document.createElement("span");
@@ -4768,6 +4824,7 @@ var DomRenderer = class {
4768
4824
  };
4769
4825
  this.renderedRowIds = visibleRows.map((r) => r.id);
4770
4826
  this.renderedZoneColSig = nextColSig;
4827
+ this.scheduleVisibleEndCheck();
4771
4828
  const leftOffset = 0;
4772
4829
  const centerOffset = zones.left.length;
4773
4830
  const rightOffset = zones.left.length + zones.center.length;
@@ -7171,6 +7228,7 @@ var DomRenderer = class {
7171
7228
  this.destroyed = true;
7172
7229
  this.editingCell?.suspend();
7173
7230
  if (this.scrollRafId !== null) cancelAnimationFrame(this.scrollRafId);
7231
+ if (this.nearEndRafId !== null) cancelAnimationFrame(this.nearEndRafId);
7174
7232
  if (this.hScrollLeaderTimer !== null) clearTimeout(this.hScrollLeaderTimer);
7175
7233
  if (this.searchDebounceTimer) clearTimeout(this.searchDebounceTimer);
7176
7234
  for (const timer of this.floatingDebounceTimers.values()) clearTimeout(timer);
@@ -7410,6 +7468,9 @@ var EventBus = class {
7410
7468
  listener(payload);
7411
7469
  }
7412
7470
  }
7471
+ hasListeners(event) {
7472
+ return (this.listeners.get(event)?.size ?? 0) > 0;
7473
+ }
7413
7474
  clear() {
7414
7475
  this.listeners.clear();
7415
7476
  }
@@ -7544,6 +7605,8 @@ var StramienGridCore = class {
7544
7605
  /** `applyTransactionAsync` queue, and the timer that applies it. */
7545
7606
  asyncQueue = [];
7546
7607
  asyncTimer = null;
7608
+ /** Row count `onRowsNearEnd` last fired for (-1: not fired since the data was set). */
7609
+ rowsNearEndFiredCount = -1;
7547
7610
  onAsyncVisibilityChange = () => {
7548
7611
  if (document.visibilityState === "visible") this.flushAsyncTransactions();
7549
7612
  };
@@ -7569,6 +7632,7 @@ var StramienGridCore = class {
7569
7632
  this.api = this.createApi();
7570
7633
  this.selectionController.setConfig(normalizeSelectionConfig(options.rowSelection));
7571
7634
  this.columnController.setResponsivePinning(options.responsivePinning);
7635
+ this.columnController.setFitColumns(Boolean(options.fitColumns));
7572
7636
  this.columnController.setColumnDefs(
7573
7637
  options.columnDefs,
7574
7638
  options.defaultColDef,
@@ -7731,7 +7795,10 @@ var StramienGridCore = class {
7731
7795
  onSizeColumnsToFit: () => this.api.sizeColumnsToFit(),
7732
7796
  onGoToPage: (page) => this.api.goToPage(page),
7733
7797
  onSetPageSize: (size) => this.api.setPageSize(size),
7734
- onViewportResize: (width) => {
7798
+ onVisibleRowsEnd: (lastVisibleRowIndex, rowCount) => this.handleVisibleRowsEnd(lastVisibleRowIndex, rowCount),
7799
+ wantsVisibleRowsEnd: () => !this.destroyed && !this.options.pagination && this.rowModel.getMode() === "clientSide" && (Boolean(this.options.onRowsNearEnd) || this.eventBus.hasListeners("rowsNearEnd")),
7800
+ onViewportResize: () => {
7801
+ const width = this.renderer.getColumnFitWidth();
7735
7802
  const { widthsChanged, zonesChanged } = this.columnController.setViewportWidth(width);
7736
7803
  if (zonesChanged) {
7737
7804
  this.renderer.renderAll();
@@ -7741,7 +7808,7 @@ var StramienGridCore = class {
7741
7808
  }
7742
7809
  });
7743
7810
  this.applyAppearance();
7744
- const initialWidth = this.renderer.getViewportWidth();
7811
+ const initialWidth = this.renderer.getColumnFitWidth();
7745
7812
  if (initialWidth > 0) {
7746
7813
  this.columnController.setViewportWidth(initialWidth);
7747
7814
  }
@@ -8662,6 +8729,21 @@ var StramienGridCore = class {
8662
8729
  this.flushAsyncTransactions();
8663
8730
  }, wait);
8664
8731
  }
8732
+ handleVisibleRowsEnd(lastVisibleRowIndex, rowCount) {
8733
+ if (this.destroyed || this.options.pagination || this.rowModel.getMode() !== "clientSide") {
8734
+ return;
8735
+ }
8736
+ const threshold = Math.max(0, Math.floor(this.options.rowsNearEndThreshold ?? 10));
8737
+ if (lastVisibleRowIndex < rowCount - 1 - threshold) {
8738
+ this.rowsNearEndFiredCount = -1;
8739
+ return;
8740
+ }
8741
+ if (rowCount === this.rowsNearEndFiredCount) return;
8742
+ this.rowsNearEndFiredCount = rowCount;
8743
+ const payload = { api: this.api, lastVisibleRowIndex, rowCount };
8744
+ this.options.onRowsNearEnd?.(payload);
8745
+ this.eventBus.emit("rowsNearEnd", payload);
8746
+ }
8665
8747
  clearAsyncQueue() {
8666
8748
  if (this.asyncTimer !== null) clearTimeout(this.asyncTimer);
8667
8749
  this.asyncTimer = null;
@@ -8739,6 +8821,8 @@ var StramienGridCore = class {
8739
8821
  return {
8740
8822
  setRowData: (rowData) => {
8741
8823
  this.clearAsyncQueue();
8824
+ this.rowsNearEndFiredCount = -1;
8825
+ this.renderer.scheduleVisibleEndCheck();
8742
8826
  const prevSnapshot = this.snapshotCellValues();
8743
8827
  this.options.rowData = rowData;
8744
8828
  this.rowModel.setRowData(
@@ -8827,7 +8911,7 @@ var StramienGridCore = class {
8827
8911
  Boolean(this.options.masterDetail),
8828
8912
  this.options.columnTypes
8829
8913
  );
8830
- const w = this.renderer.getViewportWidth();
8914
+ const w = this.renderer.getColumnFitWidth();
8831
8915
  if (w > 0) this.columnController.setViewportWidth(w);
8832
8916
  this.recomputeAndRender();
8833
8917
  },
@@ -8844,6 +8928,7 @@ var StramienGridCore = class {
8844
8928
  const prevTheme = this.theme;
8845
8929
  const prevDensity = this.density;
8846
8930
  const prevRowHeight = this.options.rowHeight;
8931
+ const prevFitColumns = Boolean(this.options.fitColumns);
8847
8932
  const prevLoading = this.loading;
8848
8933
  const prevRowModelType = this.rowModel.getMode();
8849
8934
  const prevDatasource = this.serverDatasource;
@@ -8865,6 +8950,9 @@ var StramienGridCore = class {
8865
8950
  ];
8866
8951
  const prevSnapshot = this.rowModel.getMode() === "clientSide" && partial.rowData !== void 0 && partial.rowData !== prevRowData ? this.snapshotCellValues() : null;
8867
8952
  this.options = { ...this.options, ...partial };
8953
+ if ("onRowsNearEnd" in partial || "rowsNearEndThreshold" in partial || "pagination" in partial) {
8954
+ this.renderer.scheduleVisibleEndCheck();
8955
+ }
8868
8956
  let structuralChange = false;
8869
8957
  let needsServerFetch = false;
8870
8958
  let pinnedChanged = false;
@@ -8884,6 +8972,11 @@ var StramienGridCore = class {
8884
8972
  structuralChange = true;
8885
8973
  }
8886
8974
  }
8975
+ if ("fitColumns" in partial && Boolean(partial.fitColumns) !== prevFitColumns) {
8976
+ this.columnController.setFitColumns(Boolean(partial.fitColumns));
8977
+ this.columnController.applyFlexWidths(this.renderer.getColumnFitWidth());
8978
+ structuralChange = true;
8979
+ }
8887
8980
  if (partial.undoRedoCellEditingLimit !== void 0) {
8888
8981
  this.undoRedoStack.setLimit(partial.undoRedoCellEditingLimit);
8889
8982
  }
@@ -8917,7 +9010,7 @@ var StramienGridCore = class {
8917
9010
  Boolean(this.options.masterDetail),
8918
9011
  this.options.columnTypes
8919
9012
  );
8920
- const w = this.renderer.getViewportWidth();
9013
+ const w = this.renderer.getColumnFitWidth();
8921
9014
  if (w > 0) this.columnController.setViewportWidth(w);
8922
9015
  structuralChange = true;
8923
9016
  }
@@ -8960,7 +9053,11 @@ var StramienGridCore = class {
8960
9053
  const getRowIdChanged = "getRowId" in partial && partial.getRowId !== prevGetRowId;
8961
9054
  const rowDataChanged = this.rowModel.getMode() === "clientSide" && (partial.rowData !== void 0 && (partial.rowData !== prevRowData || prevRowModelType !== "clientSide") || getRowIdChanged);
8962
9055
  if (rowDataChanged) {
8963
- if (partial.rowData !== void 0) this.clearAsyncQueue();
9056
+ if (partial.rowData !== void 0) {
9057
+ this.clearAsyncQueue();
9058
+ this.rowsNearEndFiredCount = -1;
9059
+ this.renderer.scheduleVisibleEndCheck();
9060
+ }
8964
9061
  this.rowModel.setRowData(
8965
9062
  this.options.rowData ?? [],
8966
9063
  this.options.getRowId,
@@ -9385,7 +9482,7 @@ var StramienGridCore = class {
9385
9482
  Boolean(this.options.masterDetail),
9386
9483
  this.options.columnTypes
9387
9484
  );
9388
- const w = this.renderer.getViewportWidth();
9485
+ const w = this.renderer.getColumnFitWidth();
9389
9486
  if (w > 0) this.columnController.setViewportWidth(w);
9390
9487
  this.sortModel = [];
9391
9488
  this.filterModel = {};
@@ -9569,7 +9666,11 @@ var StramienGridCore = class {
9569
9666
  params?.columns ? new Set(params.columns) : void 0
9570
9667
  );
9571
9668
  },
9572
- on: (event, listener) => this.eventBus.on(event, listener),
9669
+ on: (event, listener) => {
9670
+ const off = this.eventBus.on(event, listener);
9671
+ if (event === "rowsNearEnd") this.renderer.scheduleVisibleEndCheck();
9672
+ return off;
9673
+ },
9573
9674
  destroy: () => {
9574
9675
  if (this.destroyed) return;
9575
9676
  this.destroyed = true;