@gridkitjs/core 0.16.0 → 0.18.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.
@@ -0,0 +1,344 @@
1
+ import { R as ResolvedMenuEntry, i as ResolvedToolbarItem, F as FilterState, D as DataColumn, v as ColumnVisibilityState, cr as SelectAllState, az as FilterOperator, b2 as OperatorFilterEntry, cs as ColumnFilterShape, C as ColumnType, ct as ColumnValueQuery, cu as ColumnValueOptions, aC as FilterScalar, cv as ValuesDraft } from './filterEditor-B7C_n89V.js';
2
+ export { cw as ColumnResizeSession, cx as ColumnValueOption, cy as ConditionsDraft, cz as CopyRequest, cA as CopySource, cB as DropSide, cC as FilterEditorAction, cD as FilterEditorDraft, cE as FilterEditorDraftBase, cF as KEYBOARD_STEP, cG as KeyShortcutCapabilities, cH as NavigationModifiers, cI as ResolvedColumnFilterMenu, cJ as applyColumnResize, cK as beginColumnResize, cL as buildKeyShortcuts, cM as buildPrintDocument, cN as clampColumnWidth, cO as clampFocus, cP as columnValueOptions, cQ as copyContent, cR as describeColumnFilter, cS as diffSelection, cT as draftToFilter, cU as filterDraftChanged, cV as filterEditorReducer, cW as filterOperandArity, cX as filterOperatorFamily, cY as fitColumnsToWidth, cZ as formatFilterOperand, c_ as hasContextMenu, c$ as initialFilterEditorDraft, d0 as intentOf, d1 as movesColumn, d2 as movesGroupBy, d3 as nextFocusForKey, d4 as parseFilterOperand, d5 as resolveColumnConstraints, d6 as resolveColumnFilterMenu, d7 as resolveDropBefore, d8 as resolveKeyboardDropTarget, d9 as revertColumnSize, da as selectAllState, db as sizeColumnToContent, dc as toConditionsDraft, dd as toValuesDraft, de as totalColumnWidth, df as visibleFilterOptions } from './filterEditor-B7C_n89V.js';
3
+
4
+ /** Where an arrow, Home or End key moves a menu's focus. */
5
+ type MenuMove = "next" | "previous" | "first" | "last";
6
+ /**
7
+ * The index of the item focus moves to from `from` — `-1` when nothing is
8
+ * focused yet, so `"next"` lands on the first item and `"previous"` on the
9
+ * last. Separators are skipped and `"next"`/`"previous"` wrap round the
10
+ * ends; disabled items count, since they stay focusable for a screen reader
11
+ * to find. `-1` when there is no item at all.
12
+ *
13
+ * Takes anything with a `type`, so a behaviour that reads its items off the
14
+ * page can pass `{ type: "item" }` for each.
15
+ */
16
+ declare function nextMenuIndex(entries: readonly Pick<ResolvedMenuEntry, "type">[], from: number, move: MenuMove): number;
17
+ /**
18
+ * The index of the item `query` — what was typed, buffered for a moment —
19
+ * picks, matched case-insensitively against the start of each label and
20
+ * wrapping round the end; `-1` when none matches.
21
+ *
22
+ * `from` is the item focused now. A single letter, or the same letter
23
+ * typed again and again, searches from the item after it, so repeating a
24
+ * letter steps through every item it starts. A longer query searches from
25
+ * `from` itself, so the item already found stays put while what is typed
26
+ * still matches it.
27
+ */
28
+ declare function typeaheadIndex(labels: readonly string[], from: number, query: string): number;
29
+
30
+ /** What `fitToolbarItems` fits: a toolbar's entries, by width, into its space. */
31
+ interface ToolbarFitInput {
32
+ /** Each entry's width, in order — `0` for a spacer, whose width is only the space left over. */
33
+ readonly widths: readonly number[];
34
+ /** The width the entries share. */
35
+ readonly available: number;
36
+ /** The width of the "More" button the entries that do not fit go into. */
37
+ readonly moreWidth: number;
38
+ /** Whether each entry, in order, stays however little room there is. */
39
+ readonly pinned: readonly boolean[];
40
+ }
41
+ /**
42
+ * How many of a toolbar's entries fit, from the start: the first `count`
43
+ * stay in the toolbar, with every pinned entry after them, and the rest go
44
+ * into a "More" menu.
45
+ *
46
+ * Pinned entries take their room first, wherever they are. Room for "More"
47
+ * is kept only when something does not fit — when everything does, the
48
+ * result is every entry and no "More" is drawn. Entries are taken in order
49
+ * and the first that does not fit ends the count, so the toolbar keeps its
50
+ * order rather than filling gaps with later, narrower entries; one with no
51
+ * width, a spacer, fits wherever the entries before it did.
52
+ */
53
+ declare function fitToolbarItems({ widths, available, moreWidth, pinned, }: ToolbarFitInput): number;
54
+ /**
55
+ * Whether a toolbar entry stays in the toolbar however narrow it gets: the
56
+ * search box and custom entries, which have no menu item to become.
57
+ */
58
+ declare function isPinnedToolbarItem(item: Pick<ResolvedToolbarItem, "type">): boolean;
59
+ /** A toolbar split at the count `fitToolbarItems` gave — see `splitToolbarItems`. */
60
+ interface ToolbarSplit {
61
+ /** What stays in the toolbar. */
62
+ readonly shown: readonly ResolvedToolbarItem[];
63
+ /** The "More" menu's entries, empty when everything fits. */
64
+ readonly overflow: readonly ResolvedMenuEntry[];
65
+ }
66
+ /**
67
+ * `items` split at the first `fit`: those before it, and every pinned item,
68
+ * stay in the toolbar; the rest become the "More" menu's entries — a button
69
+ * an item, checked where it was pressed, and a dropdown a submenu. Neither
70
+ * side keeps a separator at its ends, doubled, or beside a spacer.
71
+ */
72
+ declare function splitToolbarItems(items: readonly ResolvedToolbarItem[], fit: number): ToolbarSplit;
73
+
74
+ /**
75
+ * What a search box shows for `filter`: the global text entry's query — the
76
+ * one naming no column — without the `%` anchors that make it a "contains"
77
+ * match, or `""` when there is none. A `%` the user typed inside the text
78
+ * stays: only the first and last characters are anchors.
79
+ */
80
+ declare function searchTextOf<Row>(filter: FilterState<Row>): string;
81
+ /**
82
+ * `filter` with its global text entry set to search for `text` anywhere in
83
+ * any column — the query `%text%` — or removed for an empty `text`. Every
84
+ * entry naming a column stays as it was. `filter` itself, unchanged, when
85
+ * it already searches for `text`.
86
+ *
87
+ * `text` is written as typed, spaces and all: a search box reads its text
88
+ * back from the filter, and trimming here would take a space away from
89
+ * under the caret as the user types it.
90
+ */
91
+ declare function setSearchText<Row>(filter: FilterState<Row>, text: string): FilterState<Row>;
92
+
93
+ type PaginationWindowEntry = number | "ellipsis";
94
+ /**
95
+ * Which page numbers a numbered pager should show for `currentPage` of
96
+ * `pageCount` — the boundary + sibling windowing MUI's `usePagination` uses.
97
+ * Always includes the first/last `boundaryCount` pages and a run of
98
+ * `2 * siblingCount + 1` pages around `currentPage`, slid inwards rather than
99
+ * cut short near either end, with one slot between each boundary and that
100
+ * run holding either the single page it skips or an `"ellipsis"`.
101
+ *
102
+ * So once `pageCount` exceeds `2 * boundaryCount + 2 * siblingCount + 3`,
103
+ * every window is exactly that many entries long, wherever `currentPage`
104
+ * sits: a pager drawing one fixed-width slot per entry keeps its trailing
105
+ * controls in place as the user pages through. Below that, every page shows.
106
+ */
107
+ declare function paginationWindow(currentPage: number, pageCount: number, options?: {
108
+ boundaryCount?: number | undefined;
109
+ siblingCount?: number | undefined;
110
+ }): readonly PaginationWindowEntry[];
111
+
112
+ /** What a column chooser is drawn from: every column, the visibility, and the search typed. */
113
+ interface ColumnChooserInput<Row> {
114
+ /** Every column in its current order, hidden ones included — a view's `dataColumns`. */
115
+ readonly columns: readonly DataColumn<Row, unknown>[];
116
+ readonly visibility: ColumnVisibilityState;
117
+ /** Narrows the list to the columns whose header text contains it, ignoring case. */
118
+ readonly search?: string | undefined;
119
+ }
120
+ /** One column's checkbox in a column chooser. */
121
+ interface ColumnChooserEntry {
122
+ readonly columnId: string;
123
+ /** The column's header text — what the search matches, and the checkbox's label. */
124
+ readonly label: string;
125
+ /** Whether the column is shown — whether its checkbox is checked. */
126
+ readonly visible: boolean;
127
+ /**
128
+ * Whether the checkbox cannot be unchecked: the column is shown and is
129
+ * either not `hideable` or the last column shown. A hidden column can
130
+ * always be shown, `hideable` or not.
131
+ */
132
+ readonly disabled: boolean;
133
+ }
134
+ /** What toggling a chooser's "Show all" checkbox does: shows these columns, or hides them. */
135
+ interface ColumnChooserToggle {
136
+ readonly visible: boolean;
137
+ readonly columnIds: readonly string[];
138
+ }
139
+ interface ColumnChooserModel {
140
+ /** The columns the search matches, in column order. */
141
+ readonly entries: readonly ColumnChooserEntry[];
142
+ /**
143
+ * The "Show all" checkbox's state over the entries whose columns are
144
+ * `hideable` — the ones it acts on. A column the user cannot hide is
145
+ * always on, so counting it would leave "Show all" stuck at mixed.
146
+ */
147
+ readonly selectAll: SelectAllState;
148
+ /** What toggling "Show all" does, or `null` when it can do nothing — a disabled checkbox. */
149
+ readonly toggleAll: ColumnChooserToggle | null;
150
+ }
151
+ /**
152
+ * A column chooser's list for a search, and what its "Show all" checkbox
153
+ * says and does — the same tri-state over what the search shows that a
154
+ * filter editor's select-all is (`selectAllState`).
155
+ *
156
+ * "Show all" shows every hidden column the search shows once any is hidden,
157
+ * and hides those it shows once none is. It never touches a column that is
158
+ * not `hideable`, and never hides the last column shown: when that is all
159
+ * that would be left, the first of them in column order stays, since a grid
160
+ * with no column shown has no header to bring one back from.
161
+ */
162
+ declare function resolveColumnChooser<Row>({ columns, visibility, search, }: ColumnChooserInput<Row>): ColumnChooserModel;
163
+
164
+ /**
165
+ * One condition row of a simple filter editor as the user types it: text,
166
+ * not yet a value, so a half-typed number or date stays in its input until
167
+ * the editor is applied and `conditionsFromRows` reads it.
168
+ */
169
+ interface ConditionRowDraft {
170
+ readonly operator: FilterOperator;
171
+ /** The operand as typed — `between`'s lower end. */
172
+ readonly text: string;
173
+ /**
174
+ * `between`'s upper end, as typed. Kept under any other operator, unread,
175
+ * so switching back to `between` finds it still there.
176
+ */
177
+ readonly textTo: string;
178
+ }
179
+ /** What `conditionsFromRows` reads off an editor's rows. */
180
+ interface ParsedConditionRows<Row> {
181
+ /** A condition for each row that reads as one, in row order. */
182
+ readonly conditions: readonly OperatorFilterEntry<Row>[];
183
+ /**
184
+ * The indexes of the rows that don't, for the editor to mark. Apply the
185
+ * conditions only once this is empty.
186
+ */
187
+ readonly invalid: readonly number[];
188
+ }
189
+ /**
190
+ * The rows a simple editor opens with over a column's filter `shape`, its
191
+ * operands written as the column's `type` reads them: two, holding the
192
+ * column's conditions when its filter is conditions, and each row they
193
+ * don't fill starting at the first of `operators`, empty. With no operator
194
+ * to start one at, only the rows the filter fills.
195
+ */
196
+ declare function conditionRowsFrom<Row>(shape: ColumnFilterShape<Row>, operators: readonly FilterOperator[], type: ColumnType | undefined): readonly ConditionRowDraft[];
197
+ /**
198
+ * The conditions a simple editor's rows stand for on `columnId`, each
199
+ * operand read as the column's `type` filters (`parseFilterOperand`) — for
200
+ * `filterEditorReducer`'s `setConditions`, with the combinator the editor
201
+ * shows.
202
+ *
203
+ * A row needs every operand its operator takes, or it is `invalid`; the
204
+ * blanks operators take none. A row after the first left empty is dropped
205
+ * rather than invalid, since the second condition is optional; an empty
206
+ * first row is invalid — clearing the filter is the editor's clear action,
207
+ * not an apply with nothing typed.
208
+ */
209
+ declare function conditionsFromRows<Row>(rows: readonly ConditionRowDraft[], columnId: string, type: ColumnType | undefined): ParsedConditionRows<Row>;
210
+
211
+ /**
212
+ * What a cached list is labelled by: `columnValueOptions`' query without
213
+ * `search` and `limit`, which a draft applies over the whole list.
214
+ */
215
+ type ColumnValueCacheQuery = Pick<ColumnValueQuery, "locale" | "messages">;
216
+ /** `columnValueOptions`, remembered per column. */
217
+ interface ColumnValueOptionsCache<Row> {
218
+ /**
219
+ * `columnId`'s whole value list — `columnValueOptions` with no `search`
220
+ * or `limit` — or the very list it returned last time, when nothing the
221
+ * list is counted from or labelled by has changed since.
222
+ */
223
+ readonly get: (rows: readonly Row[], dataColumns: readonly DataColumn<Row, unknown>[], filter: FilterState<Row>, columnId: string, query?: ColumnValueCacheQuery) => ColumnValueOptions;
224
+ }
225
+ /**
226
+ * A memo of each column's checklist values, for a renderer to hold one of
227
+ * per grid: reopening a column's checklist hands back the list it was given
228
+ * last time — the same object — rather than counting `rows` again, until
229
+ * something the list depends on changes.
230
+ *
231
+ * That is the `rows` and `dataColumns`, the `locale` and `messages` it is
232
+ * labelled in, and the filter's entries not about the column — all compared
233
+ * by identity, the entries one by one. Identity holds across an apply:
234
+ * `draftToFilter` keeps every entry it doesn't replace as it was, so
235
+ * filtering one column leaves the lists of the others to recount and its
236
+ * own cached, since a column's list never depends on its own entries.
237
+ *
238
+ * Each column keeps its latest list. New rows, columns, locale or messages
239
+ * drop every list, so the cache never holds on to rows the grid has let go
240
+ * of — pass the grid's own, which keep their identity between renders.
241
+ */
242
+ declare function createColumnValueOptionsCache<Row>(): ColumnValueOptionsCache<Row>;
243
+
244
+ /** One row of a checklist: a value the column holds, or its blank cells. */
245
+ type FilterChecklistItem = {
246
+ /**
247
+ * Tells the item apart from every other in the list: a value's key is the
248
+ * one `draft.checked` holds it under, and the blanks have their own.
249
+ */
250
+ readonly key: string;
251
+ /** The value as its cells print it, or the blanks' label. */
252
+ readonly label: string;
253
+ /** How many rows hold it, among those the other columns' filters keep. */
254
+ readonly count: number;
255
+ readonly checked: boolean;
256
+ } & ({
257
+ /** Toggled with `filterEditorReducer`'s `toggleValue`. */
258
+ readonly kind: "value";
259
+ readonly value: Exclude<FilterScalar, null>;
260
+ } | {
261
+ /** Toggled with `filterEditorReducer`'s `setIncludeBlanks`. */
262
+ readonly kind: "blanks";
263
+ });
264
+ interface FilterChecklistOptions {
265
+ /** How many values the list shows at most: the column's resolved `valueLimit`. */
266
+ readonly valueLimit: number;
267
+ /** The blanks item's label: the grid's `filterBlanks` message. */
268
+ readonly blanksLabel: string;
269
+ }
270
+ /** What a checklist editor draws below its search box and select-all. */
271
+ interface FilterChecklist {
272
+ /**
273
+ * The rows to draw, in order: the values the search shows, cut to
274
+ * `valueLimit`, then the blanks while nothing is searched and some cells
275
+ * are blank. Empty while `needsSearch`.
276
+ */
277
+ readonly items: readonly FilterChecklistItem[];
278
+ /**
279
+ * Whether the list waits for a search: the column holds more values than
280
+ * `valueLimit` and nothing is searched yet — `filterSearchFirst(total)`.
281
+ */
282
+ readonly needsSearch: boolean;
283
+ /**
284
+ * How many of the values the search matches `valueLimit` left out of
285
+ * `items` — `filterMoreValues(hiddenCount)`. `0` while `needsSearch`, so
286
+ * the two notes never show together.
287
+ */
288
+ readonly hiddenCount: number;
289
+ /** How many values the search matches — every value while nothing is searched. Blanks aside. */
290
+ readonly total: number;
291
+ }
292
+ /**
293
+ * The list a checklist editor draws for `draft`: the window of values its
294
+ * search shows, as items carrying what each row says and whether it is
295
+ * checked. A draft on its conditions draws through `toValuesDraft`.
296
+ *
297
+ * A column can hold far more values than a list is worth scrolling, so the
298
+ * list shows at most `valueLimit` of them. Past that, it shows nothing until
299
+ * something is searched (`needsSearch`) — every value is still in the draft,
300
+ * and select-all still covers them all — and a search matching more shows
301
+ * the first `valueLimit` of its matches in sort order, with the rest counted
302
+ * in `hiddenCount`.
303
+ *
304
+ * The blanks item comes last, as in Excel's, and only while nothing is
305
+ * searched: exactly when select-all counts the blanks, so the checkbox acts
306
+ * on what the list shows.
307
+ */
308
+ declare function filterChecklist<Row>(draft: ValuesDraft<Row>, { valueLimit, blanksLabel }: FilterChecklistOptions): FilterChecklist;
309
+
310
+ /**
311
+ * One entry per row: its measured height once known, `undefined` until then.
312
+ * A row never yet rendered (or rendered but not yet observed) falls back to
313
+ * `visibleRange`'s own `estimatedHeight` argument.
314
+ */
315
+ type RowHeights = readonly (number | undefined)[];
316
+ interface VisibleRange {
317
+ readonly startIndex: number;
318
+ readonly endIndex: number;
319
+ /** Total height of every row before `startIndex` — the leading spacer's height. */
320
+ readonly offsetBefore: number;
321
+ /** Total height of every row after `endIndex` — the trailing spacer's height. */
322
+ readonly offsetAfter: number;
323
+ }
324
+ /**
325
+ * Which rows of a dynamic-height, virtualized list fall within
326
+ * `[scrollTop, scrollTop + viewportHeight)`, padded by `overscan` rows on
327
+ * each side and clamped to the array's own bounds.
328
+ *
329
+ * Walks a cumulative-offset prefix sum built from `heights` (measured height
330
+ * where known, `estimatedHeight` otherwise) rather than assuming a uniform
331
+ * row height — this codebase's rows are not uniform (`.is-wrapped` cells,
332
+ * group header/summary rows), so a fixed-height virtualizer would either
333
+ * break wrapping or force it out of scope.
334
+ *
335
+ * `O(n)` in `heights.length`. Deliberately not a Fenwick tree or a
336
+ * binary-searchable prefix-sum structure — that optimization belongs in the
337
+ * mutable height cache that already owns mutability (`createRowVirtualizer`
338
+ * in `@gridkitjs/dom`), not in this pure function's contract, and is not
339
+ * worth taking on until a profiled scenario actually shows it matters at
340
+ * realistic row counts.
341
+ */
342
+ declare function visibleRange(heights: RowHeights, estimatedHeight: number, scrollTop: number, viewportHeight: number, overscan: number): VisibleRange;
343
+
344
+ export { type ColumnChooserEntry, type ColumnChooserInput, type ColumnChooserModel, type ColumnChooserToggle, ColumnFilterShape, type ColumnValueCacheQuery, ColumnValueOptions, type ColumnValueOptionsCache, ColumnValueQuery, type ConditionRowDraft, type FilterChecklist, type FilterChecklistItem, type FilterChecklistOptions, type MenuMove, type PaginationWindowEntry, type ParsedConditionRows, type RowHeights, SelectAllState, type ToolbarFitInput, type ToolbarSplit, ValuesDraft, type VisibleRange, conditionRowsFrom, conditionsFromRows, createColumnValueOptionsCache, filterChecklist, fitToolbarItems, isPinnedToolbarItem, nextMenuIndex, paginationWindow, resolveColumnChooser, searchTextOf, setSearchText, splitToolbarItems, typeaheadIndex, visibleRange };