@everygrid/grid 0.4.7
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.
Potentially problematic release.
This version of @everygrid/grid might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +680 -0
- package/dist/Everygrid.css +3 -0
- package/dist/everygrid-config.json +7 -0
- package/dist/everygrid.standalone.js +401 -0
- package/dist/i18n/en.json.d.ts +86 -0
- package/dist/i18n/ko.json.d.ts +86 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +24227 -0
- package/dist/src/components/ColumnSelectorComponent.d.ts +8 -0
- package/dist/src/components/DiffPopupComponent.d.ts +14 -0
- package/dist/src/components/EmptyGridPlaceholderComponent.d.ts +15 -0
- package/dist/src/components/EverygridComponent.d.ts +5 -0
- package/dist/src/components/ExcelViewComponent.d.ts +20 -0
- package/dist/src/components/GridTableComponent.d.ts +28 -0
- package/dist/src/components/GridToolbarComponent.d.ts +49 -0
- package/dist/src/components/HiddenColumnSelectorComponent.d.ts +7 -0
- package/dist/src/components/InsertedRowsComponent.d.ts +21 -0
- package/dist/src/components/MobileColumnSelectorComponent.d.ts +8 -0
- package/dist/src/components/NestedTableComponent.d.ts +10 -0
- package/dist/src/components/PaginationComponent.d.ts +21 -0
- package/dist/src/components/PinnedTableComponent.d.ts +26 -0
- package/dist/src/components/PopupComponent.d.ts +29 -0
- package/dist/src/components/RowCountComponent.d.ts +18 -0
- package/dist/src/components/RowDetailComponent.d.ts +8 -0
- package/dist/src/components/TableCellComponent.d.ts +18 -0
- package/dist/src/components/TextEditorPopupComponent.d.ts +6 -0
- package/dist/src/core/Everygrid.d.ts +568 -0
- package/dist/src/core/ExcelView.d.ts +28 -0
- package/dist/src/core/GridHandle.d.ts +214 -0
- package/dist/src/core/GridHandle.test.d.ts +1 -0
- package/dist/src/core/ResizeUtils.d.ts +3 -0
- package/dist/src/core/highlightUtils.d.ts +4 -0
- package/dist/src/core/normalizeOptions.d.ts +13 -0
- package/dist/src/core/normalizeOptions.test.d.ts +1 -0
- package/dist/src/core/types.d.ts +361 -0
- package/dist/src/core/useVirtualWindow.d.ts +89 -0
- package/dist/src/core/useVirtualWindow.test.d.ts +1 -0
- package/dist/src/core/utils.d.ts +19 -0
- package/dist/src/i18n/I18n.d.ts +16 -0
- package/dist/src/icons/ChevronDownIcon.d.ts +2 -0
- package/dist/src/icons/ColumnWidthIcon.d.ts +3 -0
- package/dist/src/icons/ColumnsIcon.d.ts +3 -0
- package/dist/src/icons/CommaIcon.d.ts +1 -0
- package/dist/src/icons/ConfigIcon.d.ts +4 -0
- package/dist/src/icons/DiffIcon.d.ts +4 -0
- package/dist/src/icons/DownloadIcon.d.ts +3 -0
- package/dist/src/icons/EditIcon.d.ts +1 -0
- package/dist/src/icons/ExcelIcon.d.ts +3 -0
- package/dist/src/icons/GlobeIcon.d.ts +2 -0
- package/dist/src/icons/HideIcon.d.ts +1 -0
- package/dist/src/icons/InfoIcon.d.ts +2 -0
- package/dist/src/icons/InsertRowIcon.d.ts +4 -0
- package/dist/src/icons/MobileColumnsIcon.d.ts +3 -0
- package/dist/src/icons/PinEmptyIcon.d.ts +1 -0
- package/dist/src/icons/PinFilledIcon.d.ts +1 -0
- package/dist/src/icons/ReloadIcon.d.ts +3 -0
- package/dist/src/icons/RowDetailIcon.d.ts +3 -0
- package/dist/src/icons/SearchIcon.d.ts +3 -0
- package/dist/src/icons/SortDownIcon.d.ts +1 -0
- package/dist/src/icons/SortResetIcon.d.ts +3 -0
- package/dist/src/icons/SortUpIcon.d.ts +1 -0
- package/dist/src/icons/TrashIcon.d.ts +3 -0
- package/dist/src/icons/UndoIcon.d.ts +3 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/react/index.d.ts +20 -0
- package/dist/src/standalone-entry.d.ts +2 -0
- package/dist/src/wasm/ExcelExportClient.d.ts +14 -0
- package/dist/src/wasm/ExportWorker.d.ts +1 -0
- package/dist/src/wasm/GridEngineWasm.d.ts +70 -0
- package/dist/src/wasm/GridEngineWorker.d.ts +102 -0
- package/dist/wasm/everygrid_wasm.js +422 -0
- package/dist/wasm/everygrid_wasm_bg.wasm +0 -0
- package/package.json +61 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { Everygrid } from './Everygrid';
|
|
2
|
+
/**
|
|
3
|
+
* Identifies a row to the outside world: the `rowKey` field's value, else the row's data index.
|
|
4
|
+
* Where a key can be missing — an inserted row whose key field is still empty — it is null.
|
|
5
|
+
*/
|
|
6
|
+
export type RowKey = string | number;
|
|
7
|
+
/** One cell's change, original → current. */
|
|
8
|
+
export interface CellChange {
|
|
9
|
+
field: string;
|
|
10
|
+
from: unknown;
|
|
11
|
+
to: unknown;
|
|
12
|
+
}
|
|
13
|
+
export type RowStatus = 'inserted' | 'updated' | 'deleted';
|
|
14
|
+
/**
|
|
15
|
+
* One row's change. `modified`: the row as it is now and as it was loaded, with the cells that
|
|
16
|
+
* differ. `inserted`: `row` is the new row (`original` is the same object, `cells` empty).
|
|
17
|
+
* `deleted`: `original` is the row as loaded (`cells` empty).
|
|
18
|
+
*/
|
|
19
|
+
export interface RowChange<T = Record<string, unknown>> {
|
|
20
|
+
status: RowStatus;
|
|
21
|
+
index: number;
|
|
22
|
+
/** Null for an inserted row whose key field is still empty. */
|
|
23
|
+
key: RowKey | null;
|
|
24
|
+
row: T;
|
|
25
|
+
original: T;
|
|
26
|
+
cells: CellChange[];
|
|
27
|
+
}
|
|
28
|
+
/** A change seen from a column: which row, and the value before and after. */
|
|
29
|
+
export interface ColumnChange<T = Record<string, unknown>> extends CellChange {
|
|
30
|
+
index: number;
|
|
31
|
+
key: RowKey | null;
|
|
32
|
+
row: T;
|
|
33
|
+
}
|
|
34
|
+
/** One modified row in a patch: its key and only the fields that changed. */
|
|
35
|
+
export interface RowPatch {
|
|
36
|
+
key: RowKey;
|
|
37
|
+
changes: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/** One deleted row in a patch: its key, and the row as it was loaded. */
|
|
40
|
+
export interface RowDeletion<T = Record<string, unknown>> {
|
|
41
|
+
key: RowKey;
|
|
42
|
+
row: T;
|
|
43
|
+
}
|
|
44
|
+
/** The minimal payload for a save: new rows whole, updated rows as key + changed fields, deleted rows as key + row. */
|
|
45
|
+
export interface Patch<T = Record<string, unknown>> {
|
|
46
|
+
inserted: T[];
|
|
47
|
+
updated: RowPatch[];
|
|
48
|
+
deleted: RowDeletion<T>[];
|
|
49
|
+
}
|
|
50
|
+
export type CellChangeEvent<T = Record<string, unknown>> = ColumnChange<T>;
|
|
51
|
+
/** A checkbox-column change: everything checked now, plus what this change toggled. */
|
|
52
|
+
export interface CheckEvent<T = Record<string, unknown>> {
|
|
53
|
+
/** The `checkbox.mapping` values of every checked row. */
|
|
54
|
+
values: unknown[];
|
|
55
|
+
/** The checked rows themselves, in data order. */
|
|
56
|
+
rows: T[];
|
|
57
|
+
/** The mapping values this change toggled. */
|
|
58
|
+
changed: unknown[];
|
|
59
|
+
/** Whether `changed` was checked (true) or unchecked (false). */
|
|
60
|
+
checked: boolean;
|
|
61
|
+
}
|
|
62
|
+
export interface GridEvents<T = Record<string, unknown>> {
|
|
63
|
+
/** One cell was edited (through the grid's UI or `set`). */
|
|
64
|
+
cellChange: (e: CellChangeEvent<T>) => void;
|
|
65
|
+
/** The set of changes moved: an edit, a cancel, or a commit. */
|
|
66
|
+
change: (changes: RowChange<T>[]) => void;
|
|
67
|
+
/** Rows were checked or unchecked, from the UI or the API. */
|
|
68
|
+
check: (e: CheckEvent<T>) => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Coordinates into one grid's data — grid → row → cell — with the same verbs at every level:
|
|
72
|
+
* `get`, `set`, `original`, `changes`, `cancel`. Handles are stateless views over
|
|
73
|
+
* the grid, so they are cheap to make and never go stale; a handle to a row that does not exist
|
|
74
|
+
* reports `exists() === false` and its writes are no-ops, so a chain never has to null-check.
|
|
75
|
+
*
|
|
76
|
+
* Row indices are positions in the loaded data, so they hold still under sort and filter. For
|
|
77
|
+
* "the n-th row on screen" use `visibleRow`.
|
|
78
|
+
*/
|
|
79
|
+
export declare class GridHandle<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
80
|
+
private readonly grid;
|
|
81
|
+
readonly id: string;
|
|
82
|
+
constructor(grid: Everygrid<T>, id: string);
|
|
83
|
+
exists(): boolean;
|
|
84
|
+
/** The loaded rows, in data order. Live objects — read, do not mutate; use `set`. */
|
|
85
|
+
data(): T[];
|
|
86
|
+
row(index: number): RowHandle<T>;
|
|
87
|
+
/** Every loaded row as a handle, in data order — a plain array: index it, filter it, map it. */
|
|
88
|
+
rows(): RowHandle<T>[];
|
|
89
|
+
/** A row of the insert grid, by its position there. */
|
|
90
|
+
insertedRow(index: number): RowHandle<T>;
|
|
91
|
+
rowByKey(key: RowKey): RowHandle<T>;
|
|
92
|
+
find(predicate: (row: T, index: number) => boolean): RowHandle<T>;
|
|
93
|
+
/** The n-th row as currently shown (after filter and sort), by its position on screen. */
|
|
94
|
+
visibleRow(position: number): RowHandle<T>;
|
|
95
|
+
cell(index: number, field: string): CellHandle<T>;
|
|
96
|
+
column(field: string): ColumnHandle<T>;
|
|
97
|
+
hasChanges(): boolean;
|
|
98
|
+
/** Every changed row — inserted, updated (with its changed cells) or deleted — in data order. */
|
|
99
|
+
changes(): RowChange<T>[];
|
|
100
|
+
insertedRows(): RowHandle<T>[];
|
|
101
|
+
updatedRows(): RowHandle<T>[];
|
|
102
|
+
deletedRows(): RowHandle<T>[];
|
|
103
|
+
/** Original vs current, summarised by kind. */
|
|
104
|
+
diff(): {
|
|
105
|
+
inserted: RowChange<T>[];
|
|
106
|
+
updated: RowChange<T>[];
|
|
107
|
+
deleted: RowChange<T>[];
|
|
108
|
+
cells: number;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* What to send to a server: the inserted rows whole, the updated rows as key + changed fields,
|
|
112
|
+
* the deleted rows as key + the row as loaded.
|
|
113
|
+
*/
|
|
114
|
+
patch(): Patch<T>;
|
|
115
|
+
/**
|
|
116
|
+
* Adds a row to the insert grid and returns its handle. The loaded data is untouched until
|
|
117
|
+
* commit, when the new rows join it at the end. Needs `rowActions.insertRow`.
|
|
118
|
+
*/
|
|
119
|
+
insertRow(values?: Partial<T>): RowHandle<T>;
|
|
120
|
+
/** Cancels every change: edits undone, inserted rows dropped, deleted rows back. */
|
|
121
|
+
cancel(): void;
|
|
122
|
+
/**
|
|
123
|
+
* Accepts the current state as the new baseline — after a successful save, typically: deleted
|
|
124
|
+
* rows are removed for good, inserted rows become ordinary rows, edits are no longer marked.
|
|
125
|
+
*/
|
|
126
|
+
commit(): void;
|
|
127
|
+
/** The checked rows, in data order — `g.checkedRows().forEach(r => r.delete())`. */
|
|
128
|
+
checkedRows(): RowHandle<T>[];
|
|
129
|
+
/** The `checkbox.mapping` values of the checked rows. */
|
|
130
|
+
checkedValues(): unknown[];
|
|
131
|
+
/** Checks rows by their mapping values. */
|
|
132
|
+
check(values: unknown[]): void;
|
|
133
|
+
uncheck(values: unknown[]): void;
|
|
134
|
+
checkAll(): void;
|
|
135
|
+
uncheckAll(): void;
|
|
136
|
+
/** Subscribe to grid events; returns the unsubscribe function. */
|
|
137
|
+
on<K extends keyof GridEvents<T>>(event: K, handler: GridEvents<T>[K]): () => void;
|
|
138
|
+
}
|
|
139
|
+
export declare class RowHandle<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
140
|
+
private readonly grid;
|
|
141
|
+
private readonly parent;
|
|
142
|
+
/** Position in the loaded data — or, for a row of the insert grid, in that grid. */
|
|
143
|
+
readonly index: number;
|
|
144
|
+
/** Which list `index` addresses: the loaded data, or the insert grid. */
|
|
145
|
+
readonly kind: 'data' | 'inserted';
|
|
146
|
+
/** The grid this row belongs to. */
|
|
147
|
+
readonly gridId: string;
|
|
148
|
+
constructor(grid: Everygrid<T>, parent: GridHandle<T>, index: number, kind?: 'data' | 'inserted');
|
|
149
|
+
private list;
|
|
150
|
+
exists(): boolean;
|
|
151
|
+
/** The row's key: its `rowKey` field, else its index; null while an inserted row's key is empty. */
|
|
152
|
+
key(): RowKey | null;
|
|
153
|
+
get(): T | undefined;
|
|
154
|
+
/** The row as it was loaded (the row itself when it has not been edited). */
|
|
155
|
+
original(): T | undefined;
|
|
156
|
+
/** Edited so that it differs from its original (and neither inserted nor deleted). */
|
|
157
|
+
updated(): boolean;
|
|
158
|
+
inserted(): boolean;
|
|
159
|
+
deleted(): boolean;
|
|
160
|
+
/** `inserted` / `updated` / `deleted`, or null for a row exactly as loaded. */
|
|
161
|
+
status(): RowStatus | null;
|
|
162
|
+
/** Changed in any way: inserted, updated or deleted. */
|
|
163
|
+
changed(): boolean;
|
|
164
|
+
checked(): boolean;
|
|
165
|
+
/** Checks (or, with false, unchecks) this row's checkbox. */
|
|
166
|
+
check(checked?: boolean): void;
|
|
167
|
+
/** Marks the row deleted (struck through until commit; cancel() brings it back). Needs `rowActions.deleteRow`. */
|
|
168
|
+
delete(): boolean;
|
|
169
|
+
changes(): CellChange[];
|
|
170
|
+
cell(field: string): CellHandle<T>;
|
|
171
|
+
/**
|
|
172
|
+
* Edits several cells at once. Fields the grid's `editableCols` does not allow are skipped (with
|
|
173
|
+
* a warning) unless `force` is set. Returns how many cells were written.
|
|
174
|
+
*/
|
|
175
|
+
set(values: Partial<T>, opts?: {
|
|
176
|
+
force?: boolean;
|
|
177
|
+
}): number;
|
|
178
|
+
/** Cancels this row's change: an inserted row is dropped, a deleted one comes back, edits are undone. */
|
|
179
|
+
cancel(): void;
|
|
180
|
+
}
|
|
181
|
+
export declare class CellHandle<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
182
|
+
private readonly grid;
|
|
183
|
+
readonly row: RowHandle<T>;
|
|
184
|
+
readonly field: string;
|
|
185
|
+
constructor(grid: Everygrid<T>, row: RowHandle<T>, field: string);
|
|
186
|
+
exists(): boolean;
|
|
187
|
+
get(): unknown;
|
|
188
|
+
original(): unknown;
|
|
189
|
+
/** Differs from the loaded value. */
|
|
190
|
+
modified(): boolean;
|
|
191
|
+
/** Whether this cell can be edited: any cell of an inserted row, else what `editableCols` allows. */
|
|
192
|
+
isEditable(): boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Edits the cell exactly as typing into it would: tracked, marked, synced to the engine. Honours
|
|
195
|
+
* `editableCols` like the UI does — a column not listed there is refused (false, with a warning)
|
|
196
|
+
* unless `force` is set, which is for code that knows better than the config.
|
|
197
|
+
*/
|
|
198
|
+
set(value: unknown, opts?: {
|
|
199
|
+
force?: boolean;
|
|
200
|
+
}): boolean;
|
|
201
|
+
/** Puts the loaded value back. */
|
|
202
|
+
cancel(): void;
|
|
203
|
+
}
|
|
204
|
+
export declare class ColumnHandle<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
205
|
+
private readonly parent;
|
|
206
|
+
readonly field: string;
|
|
207
|
+
constructor(parent: GridHandle<T>, field: string);
|
|
208
|
+
/** Current values down the column, in data order. */
|
|
209
|
+
values(): unknown[];
|
|
210
|
+
/** Rows whose value in this column changed. */
|
|
211
|
+
changes(): ColumnChange<T>[];
|
|
212
|
+
/** Cancels every change in this column. */
|
|
213
|
+
cancel(): void;
|
|
214
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { IEverygrid } from './types';
|
|
3
|
+
export declare const createResizeHandler: <T extends Record<string, unknown>>(grid: IEverygrid<T>, containerId: string, container: HTMLElement, requireTableContainer?: boolean) => (e: React.MouseEvent | React.TouchEvent, field: string) => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export declare const highlightText: (text: string, query: string, field?: string) => React.JSX.Element | string;
|
|
3
|
+
export declare const makeElementGate: (rootData: unknown, query: string) => (el: unknown) => string;
|
|
4
|
+
export declare const objectContainsFilter: (val: unknown, query: string, field?: string) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GridOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Folds the options a target carries into the root per-feature lists the runtime reads
|
|
4
|
+
* (`pagination: [{id, …}]` and friends), so the rest of the grid keeps one shape to look at.
|
|
5
|
+
* A target's own entry replaces a root entry with the same id. Targets keep only their identity,
|
|
6
|
+
* `data` and `links` afterwards.
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeOptions<T>(options: GridOptions<T>): GridOptions<T>;
|
|
9
|
+
/**
|
|
10
|
+
* The inverse for one grid: its target entry with every per-grid option folded back in — the
|
|
11
|
+
* shape a config file uses — plus the root-only options. What the toolbar's "config" button shows.
|
|
12
|
+
*/
|
|
13
|
+
export declare function targetConfigOf<T>(options: GridOptions<T>, id: string): Record<string, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface KeyTree {
|
|
3
|
+
[key: string]: KeyTree;
|
|
4
|
+
}
|
|
5
|
+
/** Loading/indexing progress for a mounted target — returned by `Everygrid.getLoadProgress(id)`
|
|
6
|
+
* so a host (tab bar, shell) can show a grid's progress even while that grid's view is hidden. */
|
|
7
|
+
export interface GridLoadProgress {
|
|
8
|
+
/** True while the grid is still streaming/indexing its data. */
|
|
9
|
+
active: boolean;
|
|
10
|
+
/** Indexing percent 0–100, or -1 when indeterminate (streaming with an unknown total). */
|
|
11
|
+
percent: number;
|
|
12
|
+
/** Rows loaded/streamed so far. */
|
|
13
|
+
rowsLoaded: number;
|
|
14
|
+
/** Engine stage, when known. */
|
|
15
|
+
stage?: 'indexing' | 'ready';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One grid. Besides its identity (`id`, `title`) a target carries every per-grid option, so a
|
|
19
|
+
* grid is configured in one place instead of naming its id under each feature. Single-value
|
|
20
|
+
* options take a shorthand (`rowKey: "id"`, `checkbox: "id"`, `editableCols: [...]`).
|
|
21
|
+
*
|
|
22
|
+
* The older per-feature form (`pagination: [{id, …}]` at the root) is still accepted; the two are
|
|
23
|
+
* merged at construction with the target's own entry winning — see `normalizeOptions`.
|
|
24
|
+
*/
|
|
25
|
+
export interface GridTargetConfig {
|
|
26
|
+
id: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
data?: Record<string, unknown>[];
|
|
29
|
+
/** Fields rendered as links. */
|
|
30
|
+
links?: string[];
|
|
31
|
+
/** Field (or fields) that identify a row to the outside world — see `GridRowKeyConfig`. */
|
|
32
|
+
rowKey?: string | string[];
|
|
33
|
+
rowActions?: Omit<GridRowActionsConfig, 'id'>;
|
|
34
|
+
toolbar?: Omit<GridToolbarConfig, 'id'>;
|
|
35
|
+
/** Fields the reader may edit. */
|
|
36
|
+
editableCols?: string[];
|
|
37
|
+
/** Checkbox column: the field whose values `checkedValues()` reports, or the full config. */
|
|
38
|
+
checkbox?: string | Omit<GridCheckboxConfig, 'id'>;
|
|
39
|
+
colors?: Omit<GridColorConfig, 'id'>;
|
|
40
|
+
/** Fields the narrow (mobile) layout shows by default. */
|
|
41
|
+
mobileColumns?: string[];
|
|
42
|
+
pagination?: Omit<GridPaginationConfig, 'id'>;
|
|
43
|
+
virtualScroll?: Omit<GridVirtualScrollConfig, 'id'>;
|
|
44
|
+
dataLimit?: Omit<GridDataLimitConfig, 'id'>;
|
|
45
|
+
/** Column labels for this grid only: `locale → field → label` (the root `columnI18n` also
|
|
46
|
+
* holds `common` entries shared by every grid). */
|
|
47
|
+
columnI18n?: Record<string, Record<string, string>>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Localized column display names: `locale → ('common' | gridId) → field → label`.
|
|
51
|
+
* A grid id's entry overrides `common`; any field with no entry falls back to the raw field key.
|
|
52
|
+
* Only display and the search-suggestion label use this — queries stay in real field keys, so WASM,
|
|
53
|
+
* the JS matcher, and highlight are untouched and locale can switch with no query rewriting.
|
|
54
|
+
*/
|
|
55
|
+
export type ColumnI18n = Record<string, Record<string, Record<string, string>>>;
|
|
56
|
+
export interface GridColumn {
|
|
57
|
+
headerName: string;
|
|
58
|
+
field: string;
|
|
59
|
+
type?: string;
|
|
60
|
+
width?: number;
|
|
61
|
+
options?: string[];
|
|
62
|
+
mapping?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface EditableColConfig {
|
|
65
|
+
id: string;
|
|
66
|
+
cols: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Which field identifies a row to the outside world — what `GridHandle` reports as a row's `key`
|
|
70
|
+
* and what `patch()` sends. Several fields make a composite key, joined with `|`. Without an
|
|
71
|
+
* entry the key is the row's index in the loaded data.
|
|
72
|
+
*/
|
|
73
|
+
export interface GridRowKeyConfig {
|
|
74
|
+
id: string;
|
|
75
|
+
field: string | string[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Row-level editing per grid. `insertRow` puts a "+ row" button in the toolbar that adds an empty
|
|
79
|
+
* row above the data rows — kept apart from the loaded data, so its rows and their indices stay
|
|
80
|
+
* put until commit moves the new rows in (at the end). `deleteRow` puts a delete button on every
|
|
81
|
+
* row; a deleted row stays on screen, struck through, until commit removes it or revert brings it
|
|
82
|
+
* back. An inserted row is simply dropped by revert. Both show up in `GridHandle.changes()` /
|
|
83
|
+
* `patch()`.
|
|
84
|
+
*/
|
|
85
|
+
export interface GridRowActionsConfig {
|
|
86
|
+
id: string;
|
|
87
|
+
insertRow?: boolean;
|
|
88
|
+
deleteRow?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Default columns for the narrow (mobile) layout, where rows scroll horizontally and each carries a
|
|
92
|
+
* detail button opening the whole row. `cols` lists the field keys to show until the user picks
|
|
93
|
+
* their own (the mobile "Columns" action, same whitelist as desktop); with no entry every column
|
|
94
|
+
* shows. Fields that do not exist are skipped.
|
|
95
|
+
*/
|
|
96
|
+
export interface GridMobileColumnsConfig {
|
|
97
|
+
id: string;
|
|
98
|
+
cols: string[];
|
|
99
|
+
}
|
|
100
|
+
export interface GridColorConfig {
|
|
101
|
+
id: string;
|
|
102
|
+
font?: {
|
|
103
|
+
header?: string;
|
|
104
|
+
body?: string;
|
|
105
|
+
};
|
|
106
|
+
bg?: {
|
|
107
|
+
header?: string;
|
|
108
|
+
body?: string;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export interface ServerFetchParams {
|
|
112
|
+
page: number;
|
|
113
|
+
pageSize: number;
|
|
114
|
+
sortField?: string;
|
|
115
|
+
sortAsc?: boolean;
|
|
116
|
+
filterText?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface ServerFetchResult<T = Record<string, unknown>> {
|
|
119
|
+
data: T[];
|
|
120
|
+
total: number;
|
|
121
|
+
}
|
|
122
|
+
export interface GridPaginationConfig {
|
|
123
|
+
id: string;
|
|
124
|
+
pageSize?: number;
|
|
125
|
+
active?: boolean;
|
|
126
|
+
position?: 'top' | 'bottom' | 'all';
|
|
127
|
+
serverSide?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Where the "Showing 1–5 of 10" line goes.
|
|
130
|
+
* - `'strip'` (default) — the band between the toolbar and the table, so it shows even on a
|
|
131
|
+
* grid with a single page or no pagination at all.
|
|
132
|
+
* - `'inline'` — inside the pagination bar, the layout used before that band existed.
|
|
133
|
+
*/
|
|
134
|
+
rowCount?: 'strip' | 'inline';
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Virtual scrolling: renders only the rows in view instead of a whole page.
|
|
138
|
+
* When active for a target, that target's pagination is ignored (the grid becomes one
|
|
139
|
+
* continuous scroll over the full filtered result).
|
|
140
|
+
*
|
|
141
|
+
* Requires a fixed row height — variable-height rows are not supported in this mode.
|
|
142
|
+
*/
|
|
143
|
+
/** Options for a reload the host asks for — see `Everygrid.reload` / `reloadData`. */
|
|
144
|
+
export interface ReloadOptions {
|
|
145
|
+
/**
|
|
146
|
+
* The host asked for this reload, not the reader — leave the toolbar's reload button alone.
|
|
147
|
+
* The data still loads with the usual loading UI.
|
|
148
|
+
*/
|
|
149
|
+
silent?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* The incoming rows replace the previous result rather than refreshing it, so the body drops to
|
|
152
|
+
* the loading state instead of showing rows that answer the old query.
|
|
153
|
+
*/
|
|
154
|
+
discard?: boolean;
|
|
155
|
+
}
|
|
156
|
+
export interface GridVirtualScrollConfig {
|
|
157
|
+
id: string;
|
|
158
|
+
active?: boolean;
|
|
159
|
+
/** Row height in px. Every row is forced to exactly this. Default 36. */
|
|
160
|
+
rowHeight?: number;
|
|
161
|
+
/** Extra rows rendered above and below the viewport. Default 6. */
|
|
162
|
+
overscan?: number;
|
|
163
|
+
/** Rows fetched from the engine per request. Default 200. */
|
|
164
|
+
blockSize?: number;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Caps how many rows a target loads into the browser. Loading a whole large dataset — into JS and
|
|
168
|
+
* again into the WASM worker — can exceed a device's per-tab memory limit and crash the tab
|
|
169
|
+
* (typical on phones). With a cap the grid loads only the first N rows and shows a banner instead.
|
|
170
|
+
*
|
|
171
|
+
* For genuinely large data the right answer is server-side pagination (`pagination.serverSide` +
|
|
172
|
+
* `serverFetcher`); this is a safety net for when a full dataset reaches the client anyway.
|
|
173
|
+
*/
|
|
174
|
+
/**
|
|
175
|
+
* Toolbar (search box + action buttons) per grid; `active: false` hides it. On by default.
|
|
176
|
+
* `showConfig` adds a "config" button that opens the grid's effective configuration — every
|
|
177
|
+
* config entry that names this grid — in the popup viewer. Off by default.
|
|
178
|
+
*/
|
|
179
|
+
export interface GridToolbarConfig {
|
|
180
|
+
id: string;
|
|
181
|
+
active?: boolean;
|
|
182
|
+
showConfig?: boolean;
|
|
183
|
+
}
|
|
184
|
+
export interface GridDataLimitConfig {
|
|
185
|
+
id: string;
|
|
186
|
+
/**
|
|
187
|
+
* Hard cap on rows loaded. A number caps at exactly that; `'auto'` derives a device-appropriate
|
|
188
|
+
* cap from reported RAM and whether the device looks mobile. Omit (or `active: false`) for no cap.
|
|
189
|
+
*/
|
|
190
|
+
maxRows?: number | 'auto';
|
|
191
|
+
active?: boolean;
|
|
192
|
+
}
|
|
193
|
+
export interface GridCheckboxConfig {
|
|
194
|
+
id: string;
|
|
195
|
+
mapping: string;
|
|
196
|
+
active?: boolean;
|
|
197
|
+
}
|
|
198
|
+
export interface GridLinkConfig {
|
|
199
|
+
id: string;
|
|
200
|
+
cols: string[];
|
|
201
|
+
}
|
|
202
|
+
export interface IEverygrid<T extends Record<string, unknown>> {
|
|
203
|
+
options: GridOptions<T>;
|
|
204
|
+
pinnedColumns: Set<string>;
|
|
205
|
+
activeEditFields: Map<string, Set<string>>;
|
|
206
|
+
sortConfig: Map<string, {
|
|
207
|
+
field: string;
|
|
208
|
+
direction: 'asc' | 'desc' | null;
|
|
209
|
+
}>;
|
|
210
|
+
hiddenFieldsMap: Map<string, Set<string>>;
|
|
211
|
+
exportState: Map<string, {
|
|
212
|
+
done: number;
|
|
213
|
+
total: number;
|
|
214
|
+
}>;
|
|
215
|
+
commaSeparatedFields: Set<string>;
|
|
216
|
+
linkFields: Set<string>;
|
|
217
|
+
isExcelViewMode: boolean;
|
|
218
|
+
activePopup: React.ReactElement | null;
|
|
219
|
+
activePopupData: {
|
|
220
|
+
data: unknown;
|
|
221
|
+
} | null;
|
|
222
|
+
/** Title for the active detail popup — the field the cell belongs to, or undefined for a fallback. */
|
|
223
|
+
activePopupTitle: string | null;
|
|
224
|
+
activePopupSubtitle: string | null;
|
|
225
|
+
activePopupSubtitleTitle: string | null;
|
|
226
|
+
activePopupRow: unknown | null;
|
|
227
|
+
activePopupRowKey: string | null;
|
|
228
|
+
wasmReady: boolean;
|
|
229
|
+
filterText: string;
|
|
230
|
+
checkedValues: Map<string, Set<unknown>>;
|
|
231
|
+
_streamRows: Map<string, Record<string, unknown>[]>;
|
|
232
|
+
_streamTotal: Map<string, number>;
|
|
233
|
+
_processing: Map<string, boolean>;
|
|
234
|
+
_wasmRawTotal: Map<string, number>;
|
|
235
|
+
_wasmPageCache: Map<string, {
|
|
236
|
+
rows: unknown[];
|
|
237
|
+
total: number;
|
|
238
|
+
}>;
|
|
239
|
+
_dataSource: Map<string, string | (() => Promise<Record<string, unknown>[]>)>;
|
|
240
|
+
_reloading: Map<string, 'button' | 'silent'>;
|
|
241
|
+
reloadData(containerId: string): Promise<void>;
|
|
242
|
+
_indexingAllRows: Map<string, Record<string, unknown>[]>;
|
|
243
|
+
_indexingStage: Map<string, 'indexing' | 'ready'>;
|
|
244
|
+
_indexingProgress: Map<string, number>;
|
|
245
|
+
_wasStreaming: Set<string>;
|
|
246
|
+
/** Targets with a data load in flight, on any load path. */
|
|
247
|
+
_loading: Set<string>;
|
|
248
|
+
renderGrid(container: HTMLElement, _updatePinned?: boolean): void;
|
|
249
|
+
resetCell(item: T, field: string, container: HTMLElement): void;
|
|
250
|
+
syncRowHeights(container: HTMLElement): void;
|
|
251
|
+
showPopup?(data: unknown, rowData?: unknown, title?: string): void;
|
|
252
|
+
closePopup(): void;
|
|
253
|
+
showTextPopup?(text: string, rowData?: unknown, title?: string): void;
|
|
254
|
+
showEditPopup(rowData: Record<string, unknown>, field: string, data: unknown): void;
|
|
255
|
+
updateData(rowData: Record<string, unknown>, field: string, value: unknown): void;
|
|
256
|
+
updateColumnWidth(containerId: string, field: string, width: number): void;
|
|
257
|
+
getCurrentWidths(containerId: string): Map<string, number>;
|
|
258
|
+
isCellModified(rowData: T, field: string): boolean;
|
|
259
|
+
isColumnNumeric(field: string): boolean;
|
|
260
|
+
isColumnDate(field: string): boolean;
|
|
261
|
+
isColumnObject(field: string): boolean;
|
|
262
|
+
getDisplayItems(containerId: string, items: T[]): T[];
|
|
263
|
+
getColumns(containerId: string, items: T[], isMobile?: boolean): GridColumn[];
|
|
264
|
+
columnLabel(field: string, containerId: string): string;
|
|
265
|
+
getMobileColumns(containerId: string): string[] | undefined;
|
|
266
|
+
isColumnBoolean(field: string): boolean;
|
|
267
|
+
getRowActions(containerId: string): {
|
|
268
|
+
insertRow: boolean;
|
|
269
|
+
deleteRow: boolean;
|
|
270
|
+
};
|
|
271
|
+
hasToolbar(containerId: string): boolean;
|
|
272
|
+
cancelAll(containerId: string): void;
|
|
273
|
+
cancelCell(containerId: string, rowData: Record<string, unknown>, field: string): void;
|
|
274
|
+
showsConfig(containerId: string): boolean;
|
|
275
|
+
getTargetConfig(containerId: string): Record<string, unknown>;
|
|
276
|
+
showConfig(container: HTMLElement): void;
|
|
277
|
+
getCheckboxMapping(containerId: string): string | undefined;
|
|
278
|
+
getCheckedValues(containerId: string): unknown[];
|
|
279
|
+
getCheckedRows(containerId: string): T[];
|
|
280
|
+
setChecked(containerId: string, values: unknown[], checked: boolean): void;
|
|
281
|
+
clearChecked(containerId: string): void;
|
|
282
|
+
insertRow(containerId: string, values?: Partial<T>, at?: number): T;
|
|
283
|
+
getInsertedRows(): T[];
|
|
284
|
+
deleteRow(containerId: string, rowData: T): void;
|
|
285
|
+
restoreRow(containerId: string, rowData: T): void;
|
|
286
|
+
isRowInserted(row: T): boolean;
|
|
287
|
+
isRowDeleted(row: T): boolean;
|
|
288
|
+
showMobileColumnSelector(allFields: string[], container: HTMLElement): void;
|
|
289
|
+
showDiff(container: HTMLElement): void;
|
|
290
|
+
showRowDetail(row: T, container: HTMLElement): void;
|
|
291
|
+
getDataFields(containerId: string): string[];
|
|
292
|
+
getSearchKeys(containerId: string, fallbackSample?: unknown[]): KeyTree;
|
|
293
|
+
exportExcel(containerId: string, scope?: 'filtered' | 'all'): Promise<void>;
|
|
294
|
+
cancelExport(containerId: string): void;
|
|
295
|
+
getEditableFields(containerId: string): string[];
|
|
296
|
+
getPagination(containerId: string): GridPaginationConfig | undefined;
|
|
297
|
+
/** Resolved virtual-scroll config, or undefined when the target scrolls by pages. */
|
|
298
|
+
getVirtualScroll(containerId: string): GridVirtualScrollConfig | undefined;
|
|
299
|
+
/** Resolved row cap for a target (`'auto'` turned into a number), or undefined for no cap. */
|
|
300
|
+
getDataLimit(containerId: string): number | undefined;
|
|
301
|
+
/** Set when a load was capped: how many rows are shown, and the true total if it is known. */
|
|
302
|
+
_dataLimited: Map<string, {
|
|
303
|
+
shown: number;
|
|
304
|
+
total: number | null;
|
|
305
|
+
}>;
|
|
306
|
+
/**
|
|
307
|
+
* Rows for the half-open range [start, end) of the current filtered result.
|
|
308
|
+
* Returns synchronously from the block cache; blocks that are missing come back as `undefined`
|
|
309
|
+
* holes and are fetched in the background, which re-renders the grid when they land.
|
|
310
|
+
*/
|
|
311
|
+
getRowsInRange(containerId: string, start: number, end: number): (T | undefined)[];
|
|
312
|
+
toggleExcelViewMode(container: HTMLElement): void;
|
|
313
|
+
resetColumnWidths(container: HTMLElement): void;
|
|
314
|
+
showColumnSelector(allFields: string[], container: HTMLElement): void;
|
|
315
|
+
showHiddenColumnSelector(container: HTMLElement): void;
|
|
316
|
+
checkHasChanges(): boolean;
|
|
317
|
+
reset(container: HTMLElement): void;
|
|
318
|
+
resetSort(container: HTMLElement): void;
|
|
319
|
+
setFilter(text: string, container?: HTMLElement): void;
|
|
320
|
+
applyWasmState(containerId: string): void;
|
|
321
|
+
applyWasmFilter(containerId: string): Promise<void>;
|
|
322
|
+
invalidateSortCache(containerId?: string): void;
|
|
323
|
+
fetchServerPage(containerId: string): Promise<void>;
|
|
324
|
+
currentPage: Map<string, number>;
|
|
325
|
+
getCurrentPage(containerId: string): number;
|
|
326
|
+
getTotalPages(containerId: string): number;
|
|
327
|
+
getFilteredTotal(containerId: string): number;
|
|
328
|
+
setCurrentPage(containerId: string, page: number, container: HTMLElement): void;
|
|
329
|
+
getGridTitle(containerId: string): string | undefined;
|
|
330
|
+
subscribe(callback: () => void): () => void;
|
|
331
|
+
notify(): void;
|
|
332
|
+
destroy(): void;
|
|
333
|
+
}
|
|
334
|
+
export interface GridOptions<T = Record<string, unknown>> {
|
|
335
|
+
targets: (string | GridTargetConfig)[];
|
|
336
|
+
data?: T[];
|
|
337
|
+
dataUrl?: string;
|
|
338
|
+
columns?: GridColumn[];
|
|
339
|
+
columnI18n?: ColumnI18n;
|
|
340
|
+
mobileColumns?: GridMobileColumnsConfig[];
|
|
341
|
+
editableCols?: EditableColConfig[];
|
|
342
|
+
rowKey?: GridRowKeyConfig[];
|
|
343
|
+
rowActions?: GridRowActionsConfig[];
|
|
344
|
+
toolbar?: GridToolbarConfig[];
|
|
345
|
+
colors?: GridColorConfig[];
|
|
346
|
+
links?: GridLinkConfig[];
|
|
347
|
+
checkbox?: GridCheckboxConfig[];
|
|
348
|
+
pagination?: GridPaginationConfig | GridPaginationConfig[];
|
|
349
|
+
virtualScroll?: GridVirtualScrollConfig | GridVirtualScrollConfig[];
|
|
350
|
+
dataLimit?: GridDataLimitConfig | GridDataLimitConfig[];
|
|
351
|
+
serverFetcher?: (params: ServerFetchParams) => Promise<ServerFetchResult>;
|
|
352
|
+
/**
|
|
353
|
+
* `cache` mode for the fetch that loads a target's data from a URL.
|
|
354
|
+
* Defaults to 'no-store' (always hit the network). Set to 'default' to let the browser
|
|
355
|
+
* cache the response — worth it for large datasets that rarely change, since a reload
|
|
356
|
+
* then costs a revalidation instead of a full re-download.
|
|
357
|
+
*/
|
|
358
|
+
dataCache?: RequestCache;
|
|
359
|
+
onDataChange?: (data: Record<string, unknown>[], originalData: Record<string, unknown>[]) => void;
|
|
360
|
+
onCellClick?: (rowData: Record<string, unknown>, field: string) => void;
|
|
361
|
+
}
|