@gridkitjs/core 0.18.0 → 0.20.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/{chunk-QGKPKQIO.js → chunk-RYMILPCT.js} +337 -175
- package/dist/chunk-RYMILPCT.js.map +1 -0
- package/dist/{filterEditor-B7C_n89V.d.ts → filterEditor-D_bo2a9W.d.ts} +291 -28
- package/dist/index.d.ts +15 -7
- package/dist/index.js +199 -101
- package/dist/index.js.map +1 -1
- package/dist/renderer.d.ts +2 -2
- package/dist/renderer.js +7 -1
- package/dist/renderer.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-QGKPKQIO.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GridControllerOptions, a as GridController, b as GridCommandTarget, c as GridMessages, d as GridCommandHost, e as GridCommandContext, f as GridCommand, M as MenuEntry, R as ResolvedMenuEntry, g as GridToolbarTarget, T as ToolbarItemAttributes, h as ToolbarEntry, i as ResolvedToolbarItem, C as ColumnType, j as ColumnSortState, S as SortDirection, k as ResolvedRow, D as DataColumn, F as FilterState, l as FieldPath, m as ResolvedColumn, n as SelectedCellRef, o as SelectedCell, p as SelectedColumn, P as PaginationUnit, q as DisplayRow, r as PaginationState, A as AggregateState, s as AggregateResults, t as GroupByState, u as GroupAggregateDisplay, v as ColumnVisibilityState, w as ColumnDefinition, x as GridViewInput, y as GridView, z as GridState, B as SerializedGridState, E as ExportTable, H as ExportSource, I as ExportWriter, J as GridExportOptions, K as ExportFile } from './filterEditor-
|
|
2
|
-
export { L as ALL_COLLAPSED, N as ALL_EXPANDED, O as AggregateFn, Q as AggregateSpec, U as Borders, V as BuiltInAggregate, W as BuiltInCommandIcon, X as BuiltInCommandId, Y as CellSelectEvent, Z as CellSelectionChangeEvent, _ as CellSelectionMode, $ as CellSelectionState, a0 as CellTemplateContext, a1 as ColumnAlignment, a2 as ColumnConstraints, a3 as ColumnFilterMenuOptions, a4 as ColumnOrderEvent, a5 as ColumnOrderState, a6 as
|
|
1
|
+
import { G as GridControllerOptions, a as GridController, b as GridCommandTarget, c as GridMessages, d as GridCommandHost, e as GridCommandContext, f as GridCommand, M as MenuEntry, R as ResolvedMenuEntry, g as GridToolbarTarget, T as ToolbarItemAttributes, h as ToolbarEntry, i as ResolvedToolbarItem, C as ColumnType, j as ColumnSortState, S as SortDirection, k as ResolvedRow, D as DataColumn, F as FilterState, l as FieldPath, m as ResolvedColumn, n as SelectedCellRef, o as SelectedCell, p as SelectedColumn, P as PaginationUnit, q as DisplayRow, r as PaginationState, A as AggregateState, s as AggregateResults, t as GroupByState, u as GroupAggregateDisplay, v as ColumnVisibilityState, w as ColumnDefinition, x as GridViewInput, y as GridView, z as GridState, B as SerializedGridState, E as ExportTable, H as ExportSource, I as ExportWriter, J as GridExportOptions, K as ExportFile } from './filterEditor-D_bo2a9W.js';
|
|
2
|
+
export { L as ALL_COLLAPSED, N as ALL_EXPANDED, O as AggregateFn, Q as AggregateSpec, U as Borders, V as BuiltInAggregate, W as BuiltInCommandIcon, X as BuiltInCommandId, Y as CellSelectEvent, Z as CellSelectionChangeEvent, _ as CellSelectionMode, $ as CellSelectionState, a0 as CellTemplateContext, a1 as ColumnAlignment, a2 as ColumnConstraints, a3 as ColumnFilterMenuOptions, a4 as ColumnOrderEvent, a5 as ColumnOrderState, a6 as ColumnPin, a7 as ColumnPinningEvent, a8 as ColumnPinningState, a9 as ColumnResizeEvent, aa as ColumnResolveOptions, ab as ColumnSelectEvent, ac as ColumnSelectionChangeEvent, ad as ColumnSizeDefaults, ae as ColumnSizingState, af as ColumnSortEntry, ag as ColumnSortEvent, ah as ColumnVisibilityEvent, ai as ColumnWrapConfig, aj as ColumnsSelectEvent, ak as ContextMenuOpenChangeEvent, al as CopyContent, am as CsvOptions, an as DEFAULT_COLUMN_SIZES, ao as DEFAULT_FILTER_VALUE_LIMIT, ap as DataMode, aq as ExportCell, ar as ExportColumn, as as ExportDataRow, at as ExportGroupRow, au as ExportGroupSummaryRow, av as ExportOptions, aw as ExportRow, ax as ExportScalar, ay as ExportTotalRow, az as ExportWriteContext, aA as FilterChangeEvent, aB as FilterEntry, aC as FilterMenuUi, aD as FilterOperator, aE as FilterOperatorFamily, aF as FilterPredicate, aG as FilterScalar, aH as FooterTemplateContext, aI as FormatLocale, aJ as GridCommandActions, aK as GridCommandEvent, aL as GridCommandSource, aM as GridContextMenuArea, aN as GridContextMenuEntries, aO as GridContextMenuOptions, aP as GridContextMenuRequest, aQ as GridContextMenuTarget, aR as GridFilterMenuOptions, aS as GridFocus, aT as GridOptions, aU as GridPanelKind, aV as GridToolbarOptions, aW as GridViewOptions, aX as GridViewState, aY as GroupByBarVisibility, aZ as GroupByEntry, a_ as GroupByEvent, a$ as GroupExpansionEvent, b0 as GroupExpansionState, b1 as GroupFilterEntry, b2 as HoverableConfig, b3 as JsonOptions, b4 as MenuItemEntry, b5 as MenuSubmenuEntry, b6 as OperatorFilterEntry, b7 as PaginationChangeEvent, b8 as PredicateFilterEntry, b9 as PrintDocument, ba as PrintOptions, bb as PrintOrientation, bc as PrintPage, bd as PrintSource, be as ResizeMode, bf as ResolvedGroupRow, bg as ResolvedGroupSummaryRow, bh as ResolvedMenuItem, bi as ResolvedMenuSeparator, bj as ResolvedMenuSubmenu, bk as ResolvedToolbarButton, bl as ResolvedToolbarCustom, bm as ResolvedToolbarMenu, bn as ResolvedToolbarSearch, bo as ResolvedToolbarSpacer, bp as RowGroupPosition, bq as RowPointerEvent, br as RowProps, bs as RowSelectEvent, bt as RowSelectionChangeEvent, bu as RowsSelectEvent, bv as SelectIntent, bw as SelectableConfig, bx as SelectionCallbacks, by as SelectionDiff, bz as SelectionDiffEvent, bA as SelectionMode, bB as SelectionState, bC as SerializedFilterEntry, bD as SerializedFilterScalar, bE as SerializedFilterState, bF as SerializedGroupFilterEntry, bG as SerializedOperatorFilterEntry, bH as SerializedValueFilterEntry, bI as TextFilterEntry, bJ as ToolbarCustomEntry, bK as ValueFilterEntry, bL as accessDotted, bM as alignmentForType, bN as applyColumnOrder, bO as applyColumnPinning, bP as applySelectionIntent, bQ as bodyFocus, bR as buildExportTable, bS as builtInCommands, bT as clearSelection, bU as collapseAllGroups, bV as contextMenuEntries, bW as createDefaultMessages, bX as csvWriter, bY as defaultContextMenu, bZ as defaultFilterOperators, b_ as defaultMessages, b$ as defaultToolbar, c0 as defineColumnsFromRows, c1 as expandAllGroups, c2 as exportPrintDocument, c3 as formatAggregateValue, c4 as formatCellValue, c5 as formatGroupValue, c6 as getColumnId, c7 as groupRowId, c8 as groupRows, c9 as headerFocus, ca as isColumnFiltered, cb as isGroupExpanded, cc as isSameCell, cd as jsonWriter, ce as moveColumnBefore, cf as moveGroupByBefore, cg as resolveColumnHeaderText, ch as resolveColumnLabel, ci as resolveColumnPin, cj as resolveColumnWidths, ck as resolveDataColumns, cl as resolveExportWriters, cm as resolveMessages, cn as resolveRowId, co as selectAll, cp as selectCell, cq as selectOnly, cr as selectRange, cs as setColumnPin, ct as toCsv, cu as toJson, cv as toggleCellSelection, cw as toggleGroupExpansion, cx as toggleSelection, cy as toolbarEntries } from './filterEditor-D_bo2a9W.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates the state container for one grid — see `GridController`. Hold one
|
|
@@ -273,6 +273,13 @@ interface PaginateRowsOptions {
|
|
|
273
273
|
* whichever page is showing.
|
|
274
274
|
*/
|
|
275
275
|
declare function paginateRows<Row>(rows: readonly DisplayRow<Row>[], pagination: PaginationState, options?: PaginateRowsOptions): PaginatedRows<Row>;
|
|
276
|
+
/**
|
|
277
|
+
* How many pages `count` rows or units fill at `pageSize` a page — the one
|
|
278
|
+
* rule every page count in the grid follows, for a pager of the app's own
|
|
279
|
+
* to follow too. `pageSize` below `1` reads as `1`, and `count` below `0`
|
|
280
|
+
* as none.
|
|
281
|
+
*/
|
|
282
|
+
declare function countPages(count: number, pageSize: number): number;
|
|
276
283
|
|
|
277
284
|
/**
|
|
278
285
|
* `rows` reduced through every spec in `specs`, keyed by `spec.id ??
|
|
@@ -331,10 +338,11 @@ declare function createGridViewResolver<Row, Node = string>(): (input: GridViewI
|
|
|
331
338
|
/**
|
|
332
339
|
* What the user is looking at, derived from the rows, the columns, the
|
|
333
340
|
* grid's state and its options in one call: rows filtered → sorted →
|
|
334
|
-
* grouped → aggregated → paginated, and columns ordered → hidden →
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
341
|
+
* grouped → aggregated → paginated, and columns ordered → hidden → pinned →
|
|
342
|
+
* sized. Under `dataMode: "server"` the rows skip the filter and the sort,
|
|
343
|
+
* and the page is the rows given. The one function a renderer, an export or
|
|
344
|
+
* a toolbar calls instead of composing the stages itself, so none of them
|
|
345
|
+
* can disagree about what is shown.
|
|
338
346
|
*
|
|
339
347
|
* Unmemoised — a one-off resolver. A renderer that derives the view on every
|
|
340
348
|
* change holds a `createGridViewResolver()` instead.
|
|
@@ -425,4 +433,4 @@ declare const excelFilter: {
|
|
|
425
433
|
};
|
|
426
434
|
};
|
|
427
435
|
|
|
428
|
-
export { AggregateResults, AggregateState, ColumnDefinition, ColumnSortState, ColumnType, ColumnVisibilityState, DataColumn, DisplayRow, ExportFile, type ExportFileSource, ExportSource, ExportTable, ExportWriter, FieldPath, FilterState, GridCommand, GridCommandContext, type GridCommandContextInput, GridCommandHost, GridCommandTarget, GridController, GridControllerOptions, GridExportOptions, GridMessages, GridState, GridToolbarTarget, GridView, GridViewInput, GroupAggregateDisplay, GroupByState, type HtmlTableOptions, MenuEntry, type MenuResolveOptions, type PaginateRowsOptions, type PaginatedRows, PaginationState, PaginationUnit, ResolvedColumn, ResolvedMenuEntry, ResolvedRow, ResolvedToolbarItem, SelectedCell, SelectedCellRef, SelectedColumn, SerializedGridState, SortDirection, ToolbarEntry, ToolbarItemAttributes, type ToolbarResolveOptions, type TsvOptions, applyColumnVisibility, clearAllFilters, compareValues, computeAggregates, createCommandContext, createGridController, createGridViewResolver, excelFilter, exportFile, filterQueryFor, filterRows, isColumnVisible, matchesQuery, paginateRows, resolveCell, resolveColumns, resolveCommands, resolveGridView, resolveMenu, resolveRows, resolveShownRows, resolveToolbar, runCommand, serializeGridState, setColumnFilter, setColumnVisibility, sortDirectionFor, sortPriorityFor, sortRows, toHtmlTable, toTsv, toggleColumnSort, withGroupAggregates };
|
|
436
|
+
export { AggregateResults, AggregateState, ColumnDefinition, ColumnSortState, ColumnType, ColumnVisibilityState, DataColumn, DisplayRow, ExportFile, type ExportFileSource, ExportSource, ExportTable, ExportWriter, FieldPath, FilterState, GridCommand, GridCommandContext, type GridCommandContextInput, GridCommandHost, GridCommandTarget, GridController, GridControllerOptions, GridExportOptions, GridMessages, GridState, GridToolbarTarget, GridView, GridViewInput, GroupAggregateDisplay, GroupByState, type HtmlTableOptions, MenuEntry, type MenuResolveOptions, type PaginateRowsOptions, type PaginatedRows, PaginationState, PaginationUnit, ResolvedColumn, ResolvedMenuEntry, ResolvedRow, ResolvedToolbarItem, SelectedCell, SelectedCellRef, SelectedColumn, SerializedGridState, SortDirection, ToolbarEntry, ToolbarItemAttributes, type ToolbarResolveOptions, type TsvOptions, applyColumnVisibility, clearAllFilters, compareValues, computeAggregates, countPages, createCommandContext, createGridController, createGridViewResolver, excelFilter, exportFile, filterQueryFor, filterRows, isColumnVisible, matchesQuery, paginateRows, resolveCell, resolveColumns, resolveCommands, resolveGridView, resolveMenu, resolveRows, resolveShownRows, resolveToolbar, runCommand, serializeGridState, setColumnFilter, setColumnVisibility, sortDirectionFor, sortPriorityFor, sortRows, toHtmlTable, toTsv, toggleColumnSort, withGroupAggregates };
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
accessDotted,
|
|
8
8
|
alignmentForType,
|
|
9
9
|
applyColumnOrder,
|
|
10
|
+
applyColumnPinning,
|
|
10
11
|
applyColumnVisibility,
|
|
11
12
|
applySelectionIntent,
|
|
12
13
|
bodyFocus,
|
|
@@ -49,11 +50,13 @@ import {
|
|
|
49
50
|
jsonWriter,
|
|
50
51
|
matchesQuery,
|
|
51
52
|
moveColumnBefore,
|
|
53
|
+
moveColumnInPinGroup,
|
|
52
54
|
moveGroupByBefore,
|
|
53
55
|
reportError,
|
|
54
56
|
resolveCell,
|
|
55
57
|
resolveColumnHeaderText,
|
|
56
58
|
resolveColumnLabel,
|
|
59
|
+
resolveColumnPin,
|
|
57
60
|
resolveColumnWidths,
|
|
58
61
|
resolveColumns,
|
|
59
62
|
resolveCommands,
|
|
@@ -72,6 +75,7 @@ import {
|
|
|
72
75
|
selectOnly,
|
|
73
76
|
selectRange,
|
|
74
77
|
setColumnFilter,
|
|
78
|
+
setColumnPin,
|
|
75
79
|
setColumnVisibility,
|
|
76
80
|
sortDirectionFor,
|
|
77
81
|
sortPriorityFor,
|
|
@@ -88,7 +92,7 @@ import {
|
|
|
88
92
|
unknownDisplayRow,
|
|
89
93
|
unknownFilterEntry,
|
|
90
94
|
withGroupAggregates
|
|
91
|
-
} from "./chunk-
|
|
95
|
+
} from "./chunk-RYMILPCT.js";
|
|
92
96
|
|
|
93
97
|
// src/util/memoize.ts
|
|
94
98
|
function memoizeLast(compute) {
|
|
@@ -104,88 +108,6 @@ function memoizeLast(compute) {
|
|
|
104
108
|
};
|
|
105
109
|
}
|
|
106
110
|
|
|
107
|
-
// src/util/paging.ts
|
|
108
|
-
var NO_HEADERS = [];
|
|
109
|
-
function groupUnitsOf(rows) {
|
|
110
|
-
const units = [];
|
|
111
|
-
let start = 0;
|
|
112
|
-
let openedByGroup = false;
|
|
113
|
-
for (let index = 0; index < rows.length; index++) {
|
|
114
|
-
const entry = rows[index];
|
|
115
|
-
if (entry === void 0) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
const isTopLevelHeader = entry.kind === "group" && entry.level === 0;
|
|
119
|
-
const isBoundary = index !== start && (isTopLevelHeader || !openedByGroup);
|
|
120
|
-
if (isBoundary) {
|
|
121
|
-
units.push({ start, end: index, headers: NO_HEADERS });
|
|
122
|
-
start = index;
|
|
123
|
-
openedByGroup = isTopLevelHeader;
|
|
124
|
-
} else if (index === start) {
|
|
125
|
-
openedByGroup = isTopLevelHeader;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (start < rows.length) {
|
|
129
|
-
units.push({ start, end: rows.length, headers: NO_HEADERS });
|
|
130
|
-
}
|
|
131
|
-
return units;
|
|
132
|
-
}
|
|
133
|
-
function rowUnitsOf(rows) {
|
|
134
|
-
const units = [];
|
|
135
|
-
let open = NO_HEADERS;
|
|
136
|
-
for (let index = 0; index < rows.length; index++) {
|
|
137
|
-
const entry = rows[index];
|
|
138
|
-
if (entry === void 0) {
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
switch (entry.kind) {
|
|
142
|
-
case "data":
|
|
143
|
-
units.push({ start: index, end: index + 1, headers: open });
|
|
144
|
-
break;
|
|
145
|
-
case "group": {
|
|
146
|
-
const ancestors = open.slice(0, entry.level);
|
|
147
|
-
open = entry.expanded ? [...ancestors, entry] : ancestors;
|
|
148
|
-
if (!entry.expanded) {
|
|
149
|
-
units.push({ start: index, end: index + 1, headers: ancestors });
|
|
150
|
-
}
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
case "group-summary": {
|
|
154
|
-
const last = units.at(-1);
|
|
155
|
-
if (last !== void 0) {
|
|
156
|
-
units[units.length - 1] = { ...last, end: index + 1 };
|
|
157
|
-
}
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
default:
|
|
161
|
-
unknownDisplayRow(entry);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return units;
|
|
165
|
-
}
|
|
166
|
-
function paginateRows(rows, pagination, options = {}) {
|
|
167
|
-
const pageSize = Math.max(1, pagination.pageSize);
|
|
168
|
-
const units = options.unit === "row" ? rowUnitsOf(rows) : groupUnitsOf(rows);
|
|
169
|
-
const pageCount = Math.ceil(units.length / pageSize);
|
|
170
|
-
if (pageCount === 0) {
|
|
171
|
-
return { rows: [], pageCount: 0, pageIndex: 0 };
|
|
172
|
-
}
|
|
173
|
-
const pageIndex = Math.min(Math.max(pagination.pageIndex, 0), pageCount - 1);
|
|
174
|
-
const firstUnit = units[pageIndex * pageSize];
|
|
175
|
-
const lastUnit = units[Math.min(pageIndex * pageSize + pageSize, units.length) - 1];
|
|
176
|
-
if (firstUnit === void 0 || lastUnit === void 0) {
|
|
177
|
-
return { rows: [], pageCount, pageIndex };
|
|
178
|
-
}
|
|
179
|
-
const page = [
|
|
180
|
-
...firstUnit.headers,
|
|
181
|
-
...rows.slice(firstUnit.start, lastUnit.end)
|
|
182
|
-
];
|
|
183
|
-
const renumbered = page.map(
|
|
184
|
-
(entry, index) => entry.rowIndex === index ? entry : { ...entry, rowIndex: index }
|
|
185
|
-
);
|
|
186
|
-
return { rows: renumbered, pageCount, pageIndex };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
111
|
// src/util/serialize.ts
|
|
190
112
|
function serializeScalar(scalar) {
|
|
191
113
|
return scalar instanceof Date ? scalar.toISOString() : scalar;
|
|
@@ -345,6 +267,105 @@ function reviveGroupExpansion(saved) {
|
|
|
345
267
|
);
|
|
346
268
|
}
|
|
347
269
|
|
|
270
|
+
// src/util/paging.ts
|
|
271
|
+
var NO_HEADERS = [];
|
|
272
|
+
function groupUnitsOf(rows) {
|
|
273
|
+
const units = [];
|
|
274
|
+
let start = 0;
|
|
275
|
+
let openedByGroup = false;
|
|
276
|
+
for (let index = 0; index < rows.length; index++) {
|
|
277
|
+
const entry = rows[index];
|
|
278
|
+
if (entry === void 0) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const isTopLevelHeader = entry.kind === "group" && entry.level === 0;
|
|
282
|
+
const isBoundary = index !== start && (isTopLevelHeader || !openedByGroup);
|
|
283
|
+
if (isBoundary) {
|
|
284
|
+
units.push({ start, end: index, headers: NO_HEADERS });
|
|
285
|
+
start = index;
|
|
286
|
+
openedByGroup = isTopLevelHeader;
|
|
287
|
+
} else if (index === start) {
|
|
288
|
+
openedByGroup = isTopLevelHeader;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (start < rows.length) {
|
|
292
|
+
units.push({ start, end: rows.length, headers: NO_HEADERS });
|
|
293
|
+
}
|
|
294
|
+
return units;
|
|
295
|
+
}
|
|
296
|
+
function rowUnitsOf(rows) {
|
|
297
|
+
const units = [];
|
|
298
|
+
let open = NO_HEADERS;
|
|
299
|
+
for (let index = 0; index < rows.length; index++) {
|
|
300
|
+
const entry = rows[index];
|
|
301
|
+
if (entry === void 0) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
switch (entry.kind) {
|
|
305
|
+
case "data":
|
|
306
|
+
units.push({ start: index, end: index + 1, headers: open });
|
|
307
|
+
break;
|
|
308
|
+
case "group": {
|
|
309
|
+
const ancestors = open.slice(0, entry.level);
|
|
310
|
+
open = entry.expanded ? [...ancestors, entry] : ancestors;
|
|
311
|
+
if (!entry.expanded) {
|
|
312
|
+
units.push({ start: index, end: index + 1, headers: ancestors });
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case "group-summary": {
|
|
317
|
+
const last = units.at(-1);
|
|
318
|
+
if (last !== void 0) {
|
|
319
|
+
units[units.length - 1] = { ...last, end: index + 1 };
|
|
320
|
+
}
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
default:
|
|
324
|
+
unknownDisplayRow(entry);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return units;
|
|
328
|
+
}
|
|
329
|
+
function paginateRows(rows, pagination, options = {}) {
|
|
330
|
+
const pageSize = Math.max(1, pagination.pageSize);
|
|
331
|
+
const units = options.unit === "row" ? rowUnitsOf(rows) : groupUnitsOf(rows);
|
|
332
|
+
const pageCount = countPages(units.length, pageSize);
|
|
333
|
+
if (pageCount === 0) {
|
|
334
|
+
return { rows: [], pageCount: 0, pageIndex: 0 };
|
|
335
|
+
}
|
|
336
|
+
const pageIndex = clampPageIndex(pagination.pageIndex, pageCount);
|
|
337
|
+
const firstUnit = units[pageIndex * pageSize];
|
|
338
|
+
const lastUnit = units[Math.min(pageIndex * pageSize + pageSize, units.length) - 1];
|
|
339
|
+
if (firstUnit === void 0 || lastUnit === void 0) {
|
|
340
|
+
return { rows: [], pageCount, pageIndex };
|
|
341
|
+
}
|
|
342
|
+
const page = [
|
|
343
|
+
...firstUnit.headers,
|
|
344
|
+
...rows.slice(firstUnit.start, lastUnit.end)
|
|
345
|
+
];
|
|
346
|
+
const renumbered = page.map(
|
|
347
|
+
(entry, index) => entry.rowIndex === index ? entry : { ...entry, rowIndex: index }
|
|
348
|
+
);
|
|
349
|
+
return { rows: renumbered, pageCount, pageIndex };
|
|
350
|
+
}
|
|
351
|
+
function paginateServerRows(rows, pagination, rowCount) {
|
|
352
|
+
const pageSize = Math.max(1, pagination.pageSize);
|
|
353
|
+
const pageCount = countPages(rowCount, pageSize);
|
|
354
|
+
const pageIndex = clampPageIndex(pagination.pageIndex, pageCount);
|
|
355
|
+
const offset = pageIndex * pageSize;
|
|
356
|
+
const offsetRows = offset === 0 ? rows : rows.map((entry) => ({
|
|
357
|
+
...entry,
|
|
358
|
+
datasetIndex: entry.datasetIndex + offset
|
|
359
|
+
}));
|
|
360
|
+
return { rows: offsetRows, pageCount, pageIndex };
|
|
361
|
+
}
|
|
362
|
+
function countPages(count, pageSize) {
|
|
363
|
+
return Math.ceil(Math.max(0, count) / Math.max(1, pageSize));
|
|
364
|
+
}
|
|
365
|
+
function clampPageIndex(pageIndex, pageCount) {
|
|
366
|
+
return pageCount === 0 ? 0 : Math.min(Math.max(pageIndex, 0), pageCount - 1);
|
|
367
|
+
}
|
|
368
|
+
|
|
348
369
|
// src/util/view.ts
|
|
349
370
|
var NO_AGGREGATES = [];
|
|
350
371
|
var DEFAULT_PAGE_SIZE = 25;
|
|
@@ -352,6 +373,7 @@ var STARTING_VIEW_STATE = {
|
|
|
352
373
|
columnSizing: {},
|
|
353
374
|
columnOrder: [],
|
|
354
375
|
columnVisibility: {},
|
|
376
|
+
columnPinning: {},
|
|
355
377
|
columnSort: [],
|
|
356
378
|
filter: [],
|
|
357
379
|
groupBy: [],
|
|
@@ -363,6 +385,7 @@ function fillViewState(state) {
|
|
|
363
385
|
columnSizing: state.columnSizing ?? STARTING_VIEW_STATE.columnSizing,
|
|
364
386
|
columnOrder: state.columnOrder ?? STARTING_VIEW_STATE.columnOrder,
|
|
365
387
|
columnVisibility: state.columnVisibility ?? STARTING_VIEW_STATE.columnVisibility,
|
|
388
|
+
columnPinning: state.columnPinning ?? STARTING_VIEW_STATE.columnPinning,
|
|
366
389
|
columnSort: state.columnSort ?? STARTING_VIEW_STATE.columnSort,
|
|
367
390
|
filter: state.filter ?? STARTING_VIEW_STATE.filter,
|
|
368
391
|
groupBy: state.groupBy ?? STARTING_VIEW_STATE.groupBy,
|
|
@@ -379,11 +402,11 @@ function identifyRows(rows, getRowId) {
|
|
|
379
402
|
datasetIndex: rowIndex
|
|
380
403
|
}));
|
|
381
404
|
}
|
|
382
|
-
function sizeColumns(visibleColumns, sizing, sizes, resizable, reorderable, groupByDraggable, resizeMode, viewportWidth) {
|
|
405
|
+
function sizeColumns(visibleColumns, sizing, pinning, sizes, resizable, reorderable, groupByDraggable, resizeMode, viewportWidth) {
|
|
383
406
|
const widths = resolveColumnWidths(
|
|
384
407
|
visibleColumns.map((entry) => entry.column),
|
|
385
408
|
sizing,
|
|
386
|
-
{ sizes, resizable, reorderable, groupByDraggable }
|
|
409
|
+
{ sizes, resizable, reorderable, groupByDraggable, pinning }
|
|
387
410
|
);
|
|
388
411
|
return resizeMode === "fit" && viewportWidth !== null ? fitColumnsToWidth(widths, viewportWidth, sizes) : widths;
|
|
389
412
|
}
|
|
@@ -394,8 +417,25 @@ function totalAggregates(rows, aggregates, dataColumns) {
|
|
|
394
417
|
dataColumns
|
|
395
418
|
);
|
|
396
419
|
}
|
|
397
|
-
function
|
|
398
|
-
return
|
|
420
|
+
function serverRowCount(rowCount, rows) {
|
|
421
|
+
return rowCount ?? rows.length;
|
|
422
|
+
}
|
|
423
|
+
function resolvePage(displayRows, rows, pagination, options) {
|
|
424
|
+
return options.dataMode === "server" ? paginateServerRows(
|
|
425
|
+
displayRows,
|
|
426
|
+
pagination,
|
|
427
|
+
serverRowCount(options.rowCount, rows)
|
|
428
|
+
) : paginateRows(displayRows, pagination, { unit: options.paginationUnit });
|
|
429
|
+
}
|
|
430
|
+
function paginate(displayRows, rows, paginated, pagination, dataMode, paginationUnit, rowCount) {
|
|
431
|
+
return paginated ? resolvePage(displayRows, rows, pagination, {
|
|
432
|
+
dataMode,
|
|
433
|
+
paginationUnit,
|
|
434
|
+
rowCount
|
|
435
|
+
}) : { rows: displayRows, pageCount: 1, pageIndex: 0 };
|
|
436
|
+
}
|
|
437
|
+
function countRows(displayRows, rows, dataMode, rowCount) {
|
|
438
|
+
return dataMode === "server" ? serverRowCount(rowCount, rows) - rows.length + displayRows.length : displayRows.length;
|
|
399
439
|
}
|
|
400
440
|
function narrowToDataRows(pageRows, rows, reshaped) {
|
|
401
441
|
return reshaped ? pageRows.filter(
|
|
@@ -406,6 +446,7 @@ function createGridViewResolver() {
|
|
|
406
446
|
const identify = memoizeLast(identifyRows);
|
|
407
447
|
const orderColumns = memoizeLast(resolveDataColumns);
|
|
408
448
|
const showColumns = memoizeLast(applyColumnVisibility);
|
|
449
|
+
const pinColumns = memoizeLast(applyColumnPinning);
|
|
409
450
|
const size = memoizeLast(sizeColumns);
|
|
410
451
|
const filterAndSort = memoizeLast(resolveShownRows);
|
|
411
452
|
const group = memoizeLast(groupRows);
|
|
@@ -414,7 +455,7 @@ function createGridViewResolver() {
|
|
|
414
455
|
const page = memoizeLast(paginate);
|
|
415
456
|
const narrow = memoizeLast(narrowToDataRows);
|
|
416
457
|
const assemble = memoizeLast(
|
|
417
|
-
(dataColumns, columns, rows, displayRows, pageRows, displayDataRows, pageCount, pageIndex, grandTotal) => ({
|
|
458
|
+
(dataColumns, columns, rows, displayRows, pageRows, displayDataRows, pageCount, pageIndex, rowCount, grandTotal) => ({
|
|
418
459
|
dataColumns,
|
|
419
460
|
columns,
|
|
420
461
|
rows,
|
|
@@ -423,6 +464,7 @@ function createGridViewResolver() {
|
|
|
423
464
|
displayDataRows,
|
|
424
465
|
pageCount,
|
|
425
466
|
pageIndex,
|
|
467
|
+
rowCount,
|
|
426
468
|
grandTotal
|
|
427
469
|
})
|
|
428
470
|
);
|
|
@@ -435,11 +477,16 @@ function createGridViewResolver() {
|
|
|
435
477
|
}) => {
|
|
436
478
|
const state = fillViewState(given);
|
|
437
479
|
const paginated = options.paginated ?? false;
|
|
480
|
+
const dataMode = options.dataMode ?? "client";
|
|
438
481
|
const aggregates = options.aggregates ?? NO_AGGREGATES;
|
|
439
482
|
const dataColumns = orderColumns(definitions, state.columnOrder);
|
|
440
483
|
const columns = size(
|
|
441
|
-
|
|
484
|
+
pinColumns(
|
|
485
|
+
showColumns(dataColumns, state.columnVisibility),
|
|
486
|
+
state.columnPinning
|
|
487
|
+
),
|
|
442
488
|
state.columnSizing,
|
|
489
|
+
state.columnPinning,
|
|
443
490
|
options.columnSizeDefaults,
|
|
444
491
|
options.resizableColumns,
|
|
445
492
|
options.reorderableColumns,
|
|
@@ -447,8 +494,9 @@ function createGridViewResolver() {
|
|
|
447
494
|
options.resizeMode ?? "fit",
|
|
448
495
|
options.viewportWidth ?? null
|
|
449
496
|
);
|
|
450
|
-
const
|
|
451
|
-
|
|
497
|
+
const identified = identify(data, getRowId);
|
|
498
|
+
const rows = dataMode === "server" ? identified : filterAndSort(
|
|
499
|
+
identified,
|
|
452
500
|
state.filter,
|
|
453
501
|
state.columnSort,
|
|
454
502
|
dataColumns
|
|
@@ -467,9 +515,12 @@ function createGridViewResolver() {
|
|
|
467
515
|
pageIndex
|
|
468
516
|
} = page(
|
|
469
517
|
displayRows,
|
|
518
|
+
rows,
|
|
470
519
|
paginated,
|
|
471
520
|
state.pagination,
|
|
472
|
-
|
|
521
|
+
dataMode,
|
|
522
|
+
options.paginationUnit,
|
|
523
|
+
options.rowCount
|
|
473
524
|
);
|
|
474
525
|
return assemble(
|
|
475
526
|
dataColumns,
|
|
@@ -480,6 +531,7 @@ function createGridViewResolver() {
|
|
|
480
531
|
narrow(pageRows, rows, state.groupBy.length > 0 || paginated),
|
|
481
532
|
pageCount,
|
|
482
533
|
pageIndex,
|
|
534
|
+
countRows(displayRows, rows, dataMode, options.rowCount),
|
|
483
535
|
total(rows, aggregates, dataColumns)
|
|
484
536
|
);
|
|
485
537
|
};
|
|
@@ -793,6 +845,7 @@ var SLICE_KEYS = [
|
|
|
793
845
|
"columnSizing",
|
|
794
846
|
"columnOrder",
|
|
795
847
|
"columnVisibility",
|
|
848
|
+
"columnPinning",
|
|
796
849
|
"columnSort",
|
|
797
850
|
"filter",
|
|
798
851
|
"groupBy",
|
|
@@ -806,6 +859,7 @@ var DEFAULT_OPTION = {
|
|
|
806
859
|
columnSizing: "defaultColumnSizing",
|
|
807
860
|
columnOrder: "defaultColumnOrder",
|
|
808
861
|
columnVisibility: "defaultColumnVisibility",
|
|
862
|
+
columnPinning: "defaultColumnPinning",
|
|
809
863
|
columnSort: "defaultColumnSort",
|
|
810
864
|
filter: "defaultFilter",
|
|
811
865
|
groupBy: "defaultGroupBy",
|
|
@@ -820,6 +874,7 @@ function startingState(options) {
|
|
|
820
874
|
columnSizing: options.defaultColumnSizing ?? STARTING_VIEW_STATE.columnSizing,
|
|
821
875
|
columnOrder: options.defaultColumnOrder ?? STARTING_VIEW_STATE.columnOrder,
|
|
822
876
|
columnVisibility: options.defaultColumnVisibility ?? STARTING_VIEW_STATE.columnVisibility,
|
|
877
|
+
columnPinning: options.defaultColumnPinning ?? STARTING_VIEW_STATE.columnPinning,
|
|
823
878
|
columnSort: options.defaultColumnSort ?? STARTING_VIEW_STATE.columnSort,
|
|
824
879
|
filter: options.defaultFilter ?? STARTING_VIEW_STATE.filter,
|
|
825
880
|
groupBy: options.defaultGroupBy ?? STARTING_VIEW_STATE.groupBy,
|
|
@@ -878,6 +933,7 @@ function createGridController(initial) {
|
|
|
878
933
|
columnSizing: resolveSlice("columnSizing"),
|
|
879
934
|
columnOrder: resolveSlice("columnOrder"),
|
|
880
935
|
columnVisibility: resolveSlice("columnVisibility"),
|
|
936
|
+
columnPinning: resolveSlice("columnPinning"),
|
|
881
937
|
columnSort: resolveSlice("columnSort"),
|
|
882
938
|
filter: resolveSlice("filter"),
|
|
883
939
|
groupBy: resolveSlice("groupBy"),
|
|
@@ -986,6 +1042,8 @@ function createGridController(initial) {
|
|
|
986
1042
|
columns: resolveColumns2(options.columns, options.dataSource),
|
|
987
1043
|
state,
|
|
988
1044
|
options: {
|
|
1045
|
+
dataMode: options.dataMode,
|
|
1046
|
+
rowCount: options.rowCount,
|
|
989
1047
|
paginated: options.paginated,
|
|
990
1048
|
paginationUnit: options.paginationUnit,
|
|
991
1049
|
aggregates: options.aggregates,
|
|
@@ -1017,13 +1075,16 @@ function createGridController(initial) {
|
|
|
1017
1075
|
);
|
|
1018
1076
|
return resolved?.width ?? 0;
|
|
1019
1077
|
}
|
|
1078
|
+
function changedColumnIds(previous, next) {
|
|
1079
|
+
const changed = new Set(changedKeys(previous, next));
|
|
1080
|
+
const known = getView().dataColumns.map((entry) => entry.id).filter((id) => changed.delete(id));
|
|
1081
|
+
return [...known, ...changed];
|
|
1082
|
+
}
|
|
1020
1083
|
function commitColumnVisibility(next) {
|
|
1021
1084
|
const previous = state.columnVisibility;
|
|
1022
1085
|
commit("columnVisibility", next, () => {
|
|
1023
|
-
const changed = new Set(changedKeys(previous, next));
|
|
1024
|
-
const shown = getView().dataColumns.map((entry) => entry.id).filter((id) => changed.delete(id));
|
|
1025
1086
|
options.onColumnVisibilityChange?.({
|
|
1026
|
-
columnIds:
|
|
1087
|
+
columnIds: changedColumnIds(previous, next),
|
|
1027
1088
|
visibility: next
|
|
1028
1089
|
});
|
|
1029
1090
|
});
|
|
@@ -1038,6 +1099,15 @@ function createGridController(initial) {
|
|
|
1038
1099
|
)
|
|
1039
1100
|
);
|
|
1040
1101
|
}
|
|
1102
|
+
function commitColumnPinning(next) {
|
|
1103
|
+
const previous = state.columnPinning;
|
|
1104
|
+
commit("columnPinning", next, () => {
|
|
1105
|
+
options.onColumnPinningChange?.({
|
|
1106
|
+
columnIds: changedColumnIds(previous, next),
|
|
1107
|
+
pinning: next
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1041
1111
|
function commitGroupBy(next, columnId) {
|
|
1042
1112
|
commit("groupBy", next, () => {
|
|
1043
1113
|
options.onGroupByChange?.({ columnId, groupBy: next });
|
|
@@ -1067,9 +1137,8 @@ function createGridController(initial) {
|
|
|
1067
1137
|
});
|
|
1068
1138
|
}
|
|
1069
1139
|
function pageOf(pagination) {
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
});
|
|
1140
|
+
const { displayRows, rows } = getView();
|
|
1141
|
+
return resolvePage(displayRows, rows, pagination, options);
|
|
1073
1142
|
}
|
|
1074
1143
|
function goToPage(pageIndex) {
|
|
1075
1144
|
const current = state.pagination;
|
|
@@ -1145,13 +1214,25 @@ function createGridController(initial) {
|
|
|
1145
1214
|
});
|
|
1146
1215
|
},
|
|
1147
1216
|
/**
|
|
1148
|
-
* Applied to every id in
|
|
1217
|
+
* Applied to every id in column order rather than to the stored order,
|
|
1149
1218
|
* which starts empty and may name only some columns, so would have
|
|
1150
1219
|
* nothing to rearrange.
|
|
1151
1220
|
*/
|
|
1152
1221
|
moveColumn(columnId, beforeId) {
|
|
1153
|
-
const
|
|
1154
|
-
const
|
|
1222
|
+
const { dataColumns } = getView();
|
|
1223
|
+
const orderedIds = dataColumns.map((entry) => entry.id);
|
|
1224
|
+
const pins = new Map(
|
|
1225
|
+
dataColumns.map((entry) => [
|
|
1226
|
+
entry.id,
|
|
1227
|
+
resolveColumnPin(entry.column, state.columnPinning)
|
|
1228
|
+
])
|
|
1229
|
+
);
|
|
1230
|
+
const next = moveColumnInPinGroup(
|
|
1231
|
+
orderedIds,
|
|
1232
|
+
(id) => pins.get(id) ?? "none",
|
|
1233
|
+
columnId,
|
|
1234
|
+
beforeId
|
|
1235
|
+
);
|
|
1155
1236
|
if (next === orderedIds) {
|
|
1156
1237
|
return;
|
|
1157
1238
|
}
|
|
@@ -1170,6 +1251,16 @@ function createGridController(initial) {
|
|
|
1170
1251
|
hideColumns(columnIds) {
|
|
1171
1252
|
changeColumnVisibility(columnIds, false);
|
|
1172
1253
|
},
|
|
1254
|
+
setColumnPinning(pinning) {
|
|
1255
|
+
if (changedKeys(state.columnPinning, pinning).length > 0) {
|
|
1256
|
+
commitColumnPinning(pinning);
|
|
1257
|
+
}
|
|
1258
|
+
},
|
|
1259
|
+
pinColumn(columnId, pin) {
|
|
1260
|
+
commitColumnPinning(
|
|
1261
|
+
setColumnPin(getView().dataColumns, state.columnPinning, columnId, pin)
|
|
1262
|
+
);
|
|
1263
|
+
},
|
|
1173
1264
|
setFilter(filter) {
|
|
1174
1265
|
if (sameFilter(state.filter, filter)) {
|
|
1175
1266
|
return;
|
|
@@ -1268,6 +1359,9 @@ function createGridController(initial) {
|
|
|
1268
1359
|
if (saved.columnVisibility !== void 0) {
|
|
1269
1360
|
controller.setColumnVisibility(saved.columnVisibility);
|
|
1270
1361
|
}
|
|
1362
|
+
if (saved.columnPinning !== void 0) {
|
|
1363
|
+
controller.setColumnPinning(saved.columnPinning);
|
|
1364
|
+
}
|
|
1271
1365
|
if (saved.columnSort !== void 0) {
|
|
1272
1366
|
controller.setColumnSort(saved.columnSort);
|
|
1273
1367
|
}
|
|
@@ -1415,6 +1509,7 @@ export {
|
|
|
1415
1509
|
accessDotted,
|
|
1416
1510
|
alignmentForType,
|
|
1417
1511
|
applyColumnOrder,
|
|
1512
|
+
applyColumnPinning,
|
|
1418
1513
|
applyColumnVisibility,
|
|
1419
1514
|
applySelectionIntent,
|
|
1420
1515
|
bodyFocus,
|
|
@@ -1426,6 +1521,7 @@ export {
|
|
|
1426
1521
|
compareValues,
|
|
1427
1522
|
computeAggregates,
|
|
1428
1523
|
contextMenuEntries,
|
|
1524
|
+
countPages,
|
|
1429
1525
|
createCommandContext,
|
|
1430
1526
|
createDefaultMessages,
|
|
1431
1527
|
createGridController,
|
|
@@ -1461,6 +1557,7 @@ export {
|
|
|
1461
1557
|
resolveCell,
|
|
1462
1558
|
resolveColumnHeaderText,
|
|
1463
1559
|
resolveColumnLabel,
|
|
1560
|
+
resolveColumnPin,
|
|
1464
1561
|
resolveColumnWidths,
|
|
1465
1562
|
resolveColumns,
|
|
1466
1563
|
resolveCommands,
|
|
@@ -1480,6 +1577,7 @@ export {
|
|
|
1480
1577
|
selectRange,
|
|
1481
1578
|
serializeGridState,
|
|
1482
1579
|
setColumnFilter,
|
|
1580
|
+
setColumnPin,
|
|
1483
1581
|
setColumnVisibility,
|
|
1484
1582
|
sortDirectionFor,
|
|
1485
1583
|
sortPriorityFor,
|