@stramien/core 0.13.1 → 0.14.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 +40 -3
- package/dist/index.js +55 -19
- package/dist/index.js.map +1 -1
- package/dist/styles.css +6 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
|
|
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>;
|
|
@@ -862,6 +875,14 @@ interface GridOptions<TData = Record<string, unknown>> {
|
|
|
862
875
|
top?: string;
|
|
863
876
|
};
|
|
864
877
|
rowHeight?: number;
|
|
878
|
+
/**
|
|
879
|
+
* The columns always fill the grid's width exactly, in proportion to their `width`: on
|
|
880
|
+
* first display, when the grid resizes, and when columns are shown, hidden or pinned. A
|
|
881
|
+
* column the user resizes keeps that width (also in `getState`), and the others fit around
|
|
882
|
+
* it; `resetState()` lets it fit again. Columns never go below their `minWidth`: when they
|
|
883
|
+
* do not fit, the grid scrolls sideways.
|
|
884
|
+
*/
|
|
885
|
+
fitColumns?: boolean;
|
|
865
886
|
/**
|
|
866
887
|
* Height in px of one body row, from its data, for rows whose height is known before they
|
|
867
888
|
* render. Return `undefined` for `rowHeight`. With `autoHeight` columns it is the row's
|
|
@@ -1078,6 +1099,15 @@ interface HeaderGroupRowZones {
|
|
|
1078
1099
|
declare class ColumnController<TData = Record<string, unknown>> {
|
|
1079
1100
|
private columns;
|
|
1080
1101
|
private manualWidths;
|
|
1102
|
+
/** `fitColumns`: the columns fill the width, except the ones in `userWidths`. */
|
|
1103
|
+
private fitColumns;
|
|
1104
|
+
/**
|
|
1105
|
+
* Columns the user (or `setColumnWidth`) resized: `fitColumns` keeps their width and fits
|
|
1106
|
+
* the others around them. Cleared by resetUserState().
|
|
1107
|
+
*/
|
|
1108
|
+
private userWidths;
|
|
1109
|
+
/** Each column's width as defined, before user changes: the weights of `fitColumns`. */
|
|
1110
|
+
private baseWidths;
|
|
1081
1111
|
private viewportWidth;
|
|
1082
1112
|
private responsivePinning;
|
|
1083
1113
|
private pinningCollapsed;
|
|
@@ -1163,6 +1193,13 @@ declare class ColumnController<TData = Record<string, unknown>> {
|
|
|
1163
1193
|
widthsChanged: boolean;
|
|
1164
1194
|
zonesChanged: boolean;
|
|
1165
1195
|
};
|
|
1196
|
+
setFitColumns(fit: boolean): void;
|
|
1197
|
+
/**
|
|
1198
|
+
* Sizes the columns that follow the width: with `fitColumns` all of them except the ones
|
|
1199
|
+
* the user resized, in proportion to their defined widths; otherwise the `flex` columns,
|
|
1200
|
+
* in proportion to their `flex`. Both fill `availableWidth` exactly where the min and max
|
|
1201
|
+
* widths allow. Returns whether a width changed.
|
|
1202
|
+
*/
|
|
1166
1203
|
applyFlexWidths(availableWidth: number): boolean;
|
|
1167
1204
|
setColumnWidth(colId: string, requestedWidth: number): number | null;
|
|
1168
1205
|
setColumnPinned(colId: string, pinned: PinnedDirection): boolean;
|
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
|
|
492
|
-
if (
|
|
493
|
-
|
|
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
|
|
498
|
-
|
|
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
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
|
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);
|
|
@@ -7569,6 +7597,7 @@ var StramienGridCore = class {
|
|
|
7569
7597
|
this.api = this.createApi();
|
|
7570
7598
|
this.selectionController.setConfig(normalizeSelectionConfig(options.rowSelection));
|
|
7571
7599
|
this.columnController.setResponsivePinning(options.responsivePinning);
|
|
7600
|
+
this.columnController.setFitColumns(Boolean(options.fitColumns));
|
|
7572
7601
|
this.columnController.setColumnDefs(
|
|
7573
7602
|
options.columnDefs,
|
|
7574
7603
|
options.defaultColDef,
|
|
@@ -7731,7 +7760,8 @@ var StramienGridCore = class {
|
|
|
7731
7760
|
onSizeColumnsToFit: () => this.api.sizeColumnsToFit(),
|
|
7732
7761
|
onGoToPage: (page) => this.api.goToPage(page),
|
|
7733
7762
|
onSetPageSize: (size) => this.api.setPageSize(size),
|
|
7734
|
-
onViewportResize: (
|
|
7763
|
+
onViewportResize: () => {
|
|
7764
|
+
const width = this.renderer.getColumnFitWidth();
|
|
7735
7765
|
const { widthsChanged, zonesChanged } = this.columnController.setViewportWidth(width);
|
|
7736
7766
|
if (zonesChanged) {
|
|
7737
7767
|
this.renderer.renderAll();
|
|
@@ -7741,7 +7771,7 @@ var StramienGridCore = class {
|
|
|
7741
7771
|
}
|
|
7742
7772
|
});
|
|
7743
7773
|
this.applyAppearance();
|
|
7744
|
-
const initialWidth = this.renderer.
|
|
7774
|
+
const initialWidth = this.renderer.getColumnFitWidth();
|
|
7745
7775
|
if (initialWidth > 0) {
|
|
7746
7776
|
this.columnController.setViewportWidth(initialWidth);
|
|
7747
7777
|
}
|
|
@@ -8827,7 +8857,7 @@ var StramienGridCore = class {
|
|
|
8827
8857
|
Boolean(this.options.masterDetail),
|
|
8828
8858
|
this.options.columnTypes
|
|
8829
8859
|
);
|
|
8830
|
-
const w = this.renderer.
|
|
8860
|
+
const w = this.renderer.getColumnFitWidth();
|
|
8831
8861
|
if (w > 0) this.columnController.setViewportWidth(w);
|
|
8832
8862
|
this.recomputeAndRender();
|
|
8833
8863
|
},
|
|
@@ -8844,6 +8874,7 @@ var StramienGridCore = class {
|
|
|
8844
8874
|
const prevTheme = this.theme;
|
|
8845
8875
|
const prevDensity = this.density;
|
|
8846
8876
|
const prevRowHeight = this.options.rowHeight;
|
|
8877
|
+
const prevFitColumns = Boolean(this.options.fitColumns);
|
|
8847
8878
|
const prevLoading = this.loading;
|
|
8848
8879
|
const prevRowModelType = this.rowModel.getMode();
|
|
8849
8880
|
const prevDatasource = this.serverDatasource;
|
|
@@ -8884,6 +8915,11 @@ var StramienGridCore = class {
|
|
|
8884
8915
|
structuralChange = true;
|
|
8885
8916
|
}
|
|
8886
8917
|
}
|
|
8918
|
+
if ("fitColumns" in partial && Boolean(partial.fitColumns) !== prevFitColumns) {
|
|
8919
|
+
this.columnController.setFitColumns(Boolean(partial.fitColumns));
|
|
8920
|
+
this.columnController.applyFlexWidths(this.renderer.getColumnFitWidth());
|
|
8921
|
+
structuralChange = true;
|
|
8922
|
+
}
|
|
8887
8923
|
if (partial.undoRedoCellEditingLimit !== void 0) {
|
|
8888
8924
|
this.undoRedoStack.setLimit(partial.undoRedoCellEditingLimit);
|
|
8889
8925
|
}
|
|
@@ -8917,7 +8953,7 @@ var StramienGridCore = class {
|
|
|
8917
8953
|
Boolean(this.options.masterDetail),
|
|
8918
8954
|
this.options.columnTypes
|
|
8919
8955
|
);
|
|
8920
|
-
const w = this.renderer.
|
|
8956
|
+
const w = this.renderer.getColumnFitWidth();
|
|
8921
8957
|
if (w > 0) this.columnController.setViewportWidth(w);
|
|
8922
8958
|
structuralChange = true;
|
|
8923
8959
|
}
|
|
@@ -9385,7 +9421,7 @@ var StramienGridCore = class {
|
|
|
9385
9421
|
Boolean(this.options.masterDetail),
|
|
9386
9422
|
this.options.columnTypes
|
|
9387
9423
|
);
|
|
9388
|
-
const w = this.renderer.
|
|
9424
|
+
const w = this.renderer.getColumnFitWidth();
|
|
9389
9425
|
if (w > 0) this.columnController.setViewportWidth(w);
|
|
9390
9426
|
this.sortModel = [];
|
|
9391
9427
|
this.filterModel = {};
|