@8sheets/data-grid 1.0.1 → 1.1.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/README.md +1 -1
- package/api/theme-core.js +2 -0
- package/calc/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/dbcs.js +1 -0
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/index.js +7 -1
- package/calc/functions/info.js +1 -1
- package/calc/functions/logical.js +1 -1
- package/calc/functions/lookup.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/functions/stat.js +1 -1
- package/calc/functions/text.js +1 -1
- package/calc/parser.js +3 -3
- package/calc/values.js +1 -1
- package/calcx/culture/custom.js +1 -0
- package/calcx/culture/format-locale.js +1 -1
- package/calcx/culture/separators.js +1 -0
- package/calcx/functions/text.js +1 -1
- package/calcx/lang/convert.js +1 -0
- package/cells/axis-ops.js +1 -1
- package/cells/block.js +1 -0
- package/cells/book-css.js +2 -2
- package/cells/cell-defaults.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/consolidate-links.js +1 -1
- package/cells/find-engine.js +2 -2
- package/cells/format-panes.js +3 -3
- package/cells/format-tabs.js +5 -5
- package/cells/name-box.js +1 -1
- package/cells/outline-column.js +1 -1
- package/cells/panes.js +1 -1
- package/cells/selection-modes.js +1 -1
- package/cells/shift-check.js +1 -0
- package/cells/table-rows.js +1 -0
- package/cells/text-layout.js +9 -8
- package/cells/ui-kit.js +15 -0
- package/cells/view-options.js +1 -1
- package/celltypes/diagonal.js +1 -1
- package/celltypes/dropdowns.js +2 -2
- package/core/address.js +1 -1
- package/core/autofill.js +1 -0
- package/core/axis-styles.js +1 -0
- package/core/axis.js +1 -1
- package/core/cond-format.js +1 -1
- package/core/culture.js +1 -0
- package/core/default-names.js +1 -1
- package/core/formula-refs.js +1 -1
- package/core/input.js +1 -1
- package/core/merge.js +1 -0
- package/core/numfmt.js +1 -1
- package/core/region-input.js +1 -0
- package/core/row-fit.js +1 -0
- package/core/sheet.js +1 -1
- package/core/structure.js +1 -0
- package/core/styles.js +1 -1
- package/core/tables.js +2 -2
- package/core/whatif.js +1 -1
- package/core/workbook.js +1 -1
- package/datasheets/data-core.js +1 -1
- package/datasheets/gantt-paint.js +1 -1
- package/datasheets/path-binding.js +2 -2
- package/datasheets/rules.js +1 -1
- package/datasheets/view.js +2 -2
- package/i18n/dom.js +1 -1
- package/i18n/en/cells.js +1 -1
- package/i18n/en/common.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/shell.js +2 -1
- package/i18n/pl/cells.js +1 -1
- package/i18n/pl/common.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/shell.js +2 -1
- package/io/csv.js +8 -8
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -3
- package/io/xlsx-write.js +2 -2
- package/objects/chart-model.js +1 -1
- package/package.json +1 -1
- package/pivot/engine.js +1 -1
- package/print/paginate.js +1 -1
- package/print/render-page.js +3 -3
- package/table-view/api.js +1 -1
- package/table-view/cell-editor.js +2 -1
- package/table-view/chart.js +1 -0
- package/table-view/column-drag.js +1 -1
- package/table-view/context-menu.js +1 -0
- package/table-view/editors.js +1 -0
- package/table-view/events.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/fill-handle.js +1 -0
- package/table-view/filter-builder.js +1 -0
- package/table-view/find.js +1 -0
- package/table-view/grid-keys.js +2 -2
- package/table-view/labels-de.js +1 -0
- package/table-view/labels-es.js +1 -0
- package/table-view/labels-fr.js +1 -0
- package/table-view/labels-ja.js +1 -0
- package/table-view/labels.js +1 -1
- package/table-view/model.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/panel.js +1 -1
- package/table-view/pivot-spec.js +1 -0
- package/table-view/pivot.js +1 -1
- package/table-view/public.d.ts +277 -28
- package/table-view/reader.worker.js +1 -1
- package/table-view/remote.js +1 -1
- package/table-view/row-drag.js +1 -0
- package/table-view/sparkline.js +1 -0
- package/table-view/state-check.js +1 -0
- package/table-view/table-css.js +380 -0
- package/table-view/version.js +1 -1
- package/ui/dialogs.js +3 -3
- package/ui/icons.js +1 -1
- package/ui/menu-base.js +1 -1
package/table-view/public.d.ts
CHANGED
|
@@ -13,8 +13,20 @@ export interface TableField {
|
|
|
13
13
|
required?: boolean;
|
|
14
14
|
/** A field rule checked on every edit and added record, e.g. `{ type: 'whole', operator: 'between', min: 1, max: 500, message }`. */
|
|
15
15
|
validator?: Record<string, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* The control that edits the field. Default: 'select' with `options`, 'checkbox' for a boolean, 'date' for a
|
|
18
|
+
* date, 'number' for a number, otherwise 'text'. 'multiselect' stores the chosen options joined by ", ".
|
|
19
|
+
*/
|
|
20
|
+
editor?: TableEditor;
|
|
21
|
+
/** The values the field takes. A select suggests them and refuses others; a multiselect lists them. */
|
|
22
|
+
options?: (string | number)[];
|
|
23
|
+
/** The band over the field's heading; neighbouring columns of one band share it. See also `columnGroups`. */
|
|
24
|
+
group?: string;
|
|
16
25
|
}
|
|
17
26
|
|
|
27
|
+
/** The controls of the cell editor and the record dialogs. */
|
|
28
|
+
export type TableEditor = 'text' | 'number' | 'date' | 'checkbox' | 'select' | 'multiselect' | 'textarea';
|
|
29
|
+
|
|
18
30
|
/** A field as the grid reports it (getFields(), the sourceLoad event). `editable` says whether edits are accepted now. */
|
|
19
31
|
export interface TableFieldInfo {
|
|
20
32
|
name: string;
|
|
@@ -22,6 +34,11 @@ export interface TableFieldInfo {
|
|
|
22
34
|
type?: 'any' | 'number' | 'string' | 'date' | 'boolean';
|
|
23
35
|
format?: string;
|
|
24
36
|
editable?: boolean;
|
|
37
|
+
/** The values of a list rule or the host's `options`. */
|
|
38
|
+
options?: string[];
|
|
39
|
+
required?: boolean;
|
|
40
|
+
editor?: TableEditor;
|
|
41
|
+
group?: string;
|
|
25
42
|
}
|
|
26
43
|
|
|
27
44
|
/** An aggregate of the totals row, over every matching record. */
|
|
@@ -56,18 +73,32 @@ export interface TableColumnState {
|
|
|
56
73
|
/** This column's aggregate in the totals row. */
|
|
57
74
|
total?: TableTotal | null;
|
|
58
75
|
rules?: TableColumnRule[];
|
|
76
|
+
/** The heading in this view, in place of the field's caption. Renaming a heading sets it; exports use it. */
|
|
77
|
+
caption?: string | null;
|
|
78
|
+
/**
|
|
79
|
+
* Draws the cell as a small chart: of the numbers in its text ("3, 5, 2", as an array of numbers reads), or of
|
|
80
|
+
* the values of `fields` in each record.
|
|
81
|
+
*/
|
|
82
|
+
sparkline?: { type?: 'line' | 'column' | 'winloss'; fields?: string[] } | null;
|
|
59
83
|
}
|
|
60
84
|
|
|
61
85
|
/**
|
|
62
|
-
* A filter. `op` is one of `contains`, `equal`, `notEqual`, `beginsWith`, `
|
|
63
|
-
* `between` (with `value2`), `blank`, `notBlank`, `in` and `notIn`
|
|
86
|
+
* A filter. `op` is one of `contains`, `notContains`, `equal`, `notEqual`, `beginsWith`, `endsWith`, `gt`,
|
|
87
|
+
* `lt`, `gte`, `lte`, `between` and `notBetween` (with `value2`), `blank`, `notBlank`, `in` and `notIn`
|
|
88
|
+
* (with `values`), `top` and `bottom` (`value` records, or percent with `percent: true`), `aboveAverage`,
|
|
89
|
+
* `belowAverage` and the date periods `today`, `yesterday`, `tomorrow`, `thisWeek`, `thisMonth`,
|
|
90
|
+
* `lastMonth`, `thisYear` and `lastYear`. A group `{ any: [...] }` keeps a record that meets one of its
|
|
91
|
+
* parts, `{ all: [...] }` one that meets every part; groups nest.
|
|
64
92
|
*/
|
|
93
|
+
export type TableFilterEntry = TableFilter | { any: TableFilterEntry[] } | { all: TableFilterEntry[] };
|
|
65
94
|
export interface TableFilter {
|
|
66
95
|
field: string;
|
|
67
96
|
op: string;
|
|
68
97
|
value?: unknown;
|
|
69
98
|
value2?: unknown;
|
|
70
99
|
values?: unknown[];
|
|
100
|
+
/** With `top` and `bottom`: `value` is a percentage of the records. */
|
|
101
|
+
percent?: boolean;
|
|
71
102
|
/** Set on a filter typed in the filter row, together with the typed `text`. */
|
|
72
103
|
quick?: boolean;
|
|
73
104
|
text?: string;
|
|
@@ -92,7 +123,7 @@ export interface TableState {
|
|
|
92
123
|
/** Display order; pinned columns show first. */
|
|
93
124
|
columns: TableColumnState[];
|
|
94
125
|
search: string;
|
|
95
|
-
filters:
|
|
126
|
+
filters: TableFilterEntry[];
|
|
96
127
|
/** Sort keys, the first one first. Sorting a grouped field also orders its groups. */
|
|
97
128
|
sort: TableSortKey[];
|
|
98
129
|
groups: TableGroup[];
|
|
@@ -108,7 +139,21 @@ export interface TableState {
|
|
|
108
139
|
totalsRow?: boolean;
|
|
109
140
|
/** Shows an input under each heading that filters its column. */
|
|
110
141
|
filterRow?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Shows the records as a tree: `{ parent, key }` puts each record under the record whose `key` field holds
|
|
144
|
+
* its `parent` value; `{ level }` reads an outline level per record. `rollups` sum (or average, min, max,
|
|
145
|
+
* count) a field over each parent's descendants. A tree replaces the groups.
|
|
146
|
+
*/
|
|
147
|
+
tree?: TableTree | null;
|
|
148
|
+
/** IDs of tree parents shown collapsed. */
|
|
149
|
+
treeCollapsed?: TableRecordId[];
|
|
150
|
+
/** Records kept above (`top`) or below (`bottom`) the scrolling records, whatever the search, filters and sort. */
|
|
151
|
+
pinnedRows?: { top?: TableRecordId[]; bottom?: TableRecordId[] };
|
|
111
152
|
}
|
|
153
|
+
/** `key` may be left out only when the table has a key field of its own (a server table's key). */
|
|
154
|
+
export type TableTree =
|
|
155
|
+
| { parent: string; key?: string; rollups?: { field: string; agg?: TableTotal }[] }
|
|
156
|
+
| { level: string; rollups?: { field: string; agg?: TableTotal }[] };
|
|
112
157
|
|
|
113
158
|
export type TableFormat = 'xlsx' | 'csv' | 'pdf';
|
|
114
159
|
export interface TableQuery {
|
|
@@ -143,9 +188,25 @@ export interface TablePage {
|
|
|
143
188
|
columnCount?: number;
|
|
144
189
|
collapsed?: string[];
|
|
145
190
|
rows: (
|
|
146
|
-
| {
|
|
191
|
+
| {
|
|
192
|
+
id: string | number;
|
|
193
|
+
values: string[];
|
|
194
|
+
raw?: unknown[];
|
|
195
|
+
/** For a tree: the record's depth, and whether it has children and they are collapsed. */
|
|
196
|
+
level?: number;
|
|
197
|
+
hasChildren?: boolean;
|
|
198
|
+
collapsed?: boolean;
|
|
199
|
+
/** The record's place among the matching records, for row numbers. */
|
|
200
|
+
number?: number;
|
|
201
|
+
/** Values of sparkline columns that draw other fields, by column field. */
|
|
202
|
+
series?: Record<string, number[]>;
|
|
203
|
+
}
|
|
147
204
|
| { group: string; path: string; level: number; collapsed: boolean; summary: string }
|
|
148
205
|
)[];
|
|
206
|
+
/** For a tree: the collapsed parents. */
|
|
207
|
+
treeCollapsed?: (string | number)[];
|
|
208
|
+
/** The pinned records of `state.pinnedRows`, as rows of this page's columns. */
|
|
209
|
+
pinned?: { top: { id: string | number; values: string[]; raw?: unknown[] }[]; bottom: { id: string | number; values: string[]; raw?: unknown[] }[] };
|
|
149
210
|
}
|
|
150
211
|
export interface TableDataSource {
|
|
151
212
|
update?(request: {
|
|
@@ -160,6 +221,13 @@ export interface TableDataSource {
|
|
|
160
221
|
formats?: TableFormat[];
|
|
161
222
|
/** Set when exportResults honours `selection`; the export dialog then offers "Selected records". */
|
|
162
223
|
selectionExport?: boolean;
|
|
224
|
+
/** Set when pages answer `state.pinnedRows` with `pinned`; the grid then offers pinning rows. */
|
|
225
|
+
pinnedRows?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Builds a pivot of the matching records on the server. The grid shows the answer as local, read-only records.
|
|
228
|
+
* `rows` hold the values of each pivot line in the order of `fields`.
|
|
229
|
+
*/
|
|
230
|
+
pivot?(request: { state: TableState; spec: TablePivot; signal: AbortSignal }): Promise<{ fields: TableField[]; rows: unknown[][] }>;
|
|
163
231
|
}
|
|
164
232
|
|
|
165
233
|
/**
|
|
@@ -190,7 +258,7 @@ export interface TableOptions {
|
|
|
190
258
|
title?: string;
|
|
191
259
|
/** Turns on saved views for `data` and `dataSource` records, stored in localStorage under this key. Live. */
|
|
192
260
|
storageKey?: string;
|
|
193
|
-
/** Interface language
|
|
261
|
+
/** Interface language: 'en', 'pl', 'de', 'fr', 'es' or 'ja'. Default: the browser's, when the grid has it. Live. */
|
|
194
262
|
language?: string;
|
|
195
263
|
/** Makes `data` records editable (with `dataSource`, needs its `update`). Default false. */
|
|
196
264
|
editable?: boolean;
|
|
@@ -209,15 +277,41 @@ export interface TableOptions {
|
|
|
209
277
|
/** Adds a checkbox to each record. 'multiple' also adds a header checkbox that selects every matching record. Live. */
|
|
210
278
|
rowSelection?: 'multiple' | 'single';
|
|
211
279
|
/**
|
|
212
|
-
* Builds the panel shown under a record when its row is expanded. One record is expanded at a time
|
|
213
|
-
* panel is built once per expansion, kept while it is open and scrolls with the
|
|
280
|
+
* Builds the panel shown under a record when its row is expanded. One record is expanded at a time unless
|
|
281
|
+
* `detailMode` is 'multiple'; a panel is built once per expansion, kept while it is open and scrolls with the
|
|
282
|
+
* records (up to 360 px tall). Live.
|
|
214
283
|
*/
|
|
215
284
|
detailRenderer?: (record: TableDetailRecord) => Node | string;
|
|
285
|
+
/** 'single' (default) keeps one detail panel open; 'multiple' lets several stay open. Live. */
|
|
286
|
+
detailMode?: 'single' | 'multiple';
|
|
287
|
+
/** Row height: 'compact' (28 px), 'normal' (34 px, default) or 'comfortable' (40 px). Live. */
|
|
288
|
+
density?: 'compact' | 'normal' | 'comfortable';
|
|
289
|
+
/** Bands over the headings: each names the fields under it. Fields can also carry `group`. Live. */
|
|
290
|
+
columnGroups?: { caption: string; fields: string[] }[];
|
|
291
|
+
/**
|
|
292
|
+
* The cells' context menu (right-click, the Menu key, Shift+F10). false turns it off; a function gets the
|
|
293
|
+
* grid's items and the place it opened, and returns the items to show. Live.
|
|
294
|
+
*/
|
|
295
|
+
contextMenu?: boolean | ((items: TableMenuItem[], context: TableMenuContext) => TableMenuItem[]);
|
|
296
|
+
/** Shows each record's number among the matching records in its row. Live. */
|
|
297
|
+
rowNumbers?: boolean;
|
|
298
|
+
/** Shows a grip in each row to move records by dragging, within the grid or onto a grid with `rowDrop`. Live. */
|
|
299
|
+
rowDrag?: boolean;
|
|
300
|
+
/** Takes records dragged from another grid: the rowDrop event gets them, and an editable grid adds them. Live. */
|
|
301
|
+
rowDrop?: boolean;
|
|
302
|
+
/** Flashes the cells applyTransaction() changes. Live. */
|
|
303
|
+
flashChanges?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Adds Ask to the toolbar: the user describes a view in words and this function answers with a state for it,
|
|
306
|
+
* for example by calling a language model on your server. The answer's state is checked against the fields
|
|
307
|
+
* before it applies. Live.
|
|
308
|
+
*/
|
|
309
|
+
assistant?: (request: TableAssistantRequest) => Promise<{ state?: Partial<TableState>; message?: string }>;
|
|
216
310
|
|
|
217
311
|
// Event handlers: the same events as grid.on(name, handler). Each is live (setOptions({ onX })).
|
|
218
312
|
/** After the view state changed: sort, filters, search, groups, columns, totals. */
|
|
219
313
|
onStateChange?: (event: TableStateChangeEvent) => void;
|
|
220
|
-
/** After a data change: an edit, paste, fill down, added or removed records, undo, redo
|
|
314
|
+
/** After a data change: an edit, paste, fill down, added or removed records, undo, redo, a calculated field, moved records or a transaction. */
|
|
221
315
|
onChange?: (change: TableChange) => void;
|
|
222
316
|
/** After each row selection change. `count` is the number of selected records among the matching ones, when known. */
|
|
223
317
|
onSelectionChange?: (selection: TableSelection & { count?: number }) => void;
|
|
@@ -247,9 +341,50 @@ export interface TableOptions {
|
|
|
247
341
|
onLoadProgress?: (event: TableLoadProgressEvent) => void;
|
|
248
342
|
/** The load ended: done, cancelled (Cancel, cancelLoad() or a newer load) or failed. */
|
|
249
343
|
onLoadEnd?: (event: TableLoadEndEvent) => void;
|
|
344
|
+
/** Cancellable: records are about to move (a drag of their grips, or moveRecords()). A server source moves them itself. */
|
|
345
|
+
onRowMove?: (event: TableRowMoveEvent) => void | boolean;
|
|
346
|
+
/** Cancellable: records were dropped on this grid from another one. An editable local grid then adds them. */
|
|
347
|
+
onRowDrop?: (event: TableRowDropEvent) => void | boolean;
|
|
250
348
|
/** An action of the interface or a remote block request failed. The grid also shows the message in its status line. */
|
|
251
349
|
onError?: (error: Error) => void;
|
|
252
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* An item of the context menu, or a separator. The grid's own items carry an `id`: copy, copyWithHeaders, paste,
|
|
353
|
+
* fillDown, filterByValue, excludeValue, sortAscending, sortDescending, groupBy, chart, find, pinRowTop,
|
|
354
|
+
* pinRowBottom, unpinRow, moveUp, moveDown, expand, details, removeRecord, export.
|
|
355
|
+
*/
|
|
356
|
+
export type TableMenuItem =
|
|
357
|
+
| { id?: string; label: string; action: () => unknown; icon?: string; disabled?: boolean; checked?: boolean; shortcut?: string }
|
|
358
|
+
| { separator: true };
|
|
359
|
+
/** Where the context menu opened. */
|
|
360
|
+
export interface TableMenuContext {
|
|
361
|
+
id: TableRecordId;
|
|
362
|
+
field: string;
|
|
363
|
+
value: unknown;
|
|
364
|
+
text: string;
|
|
365
|
+
range: TableRange | null;
|
|
366
|
+
}
|
|
367
|
+
export interface TableAssistantRequest {
|
|
368
|
+
/** What the user wrote. */
|
|
369
|
+
prompt: string;
|
|
370
|
+
state: TableState;
|
|
371
|
+
fields: { name: string; caption?: string; type?: string; format?: string }[];
|
|
372
|
+
/** A JSON Schema of the state keys an answer may set, with the field names spelled out. */
|
|
373
|
+
schema: Record<string, unknown>;
|
|
374
|
+
language: string;
|
|
375
|
+
}
|
|
376
|
+
export interface TableRowMoveEvent extends TableCancellable {
|
|
377
|
+
ids: TableRecordId[];
|
|
378
|
+
/** The record they go before; null for the end. */
|
|
379
|
+
before: TableRecordId | null;
|
|
380
|
+
source: TableChangeSource;
|
|
381
|
+
}
|
|
382
|
+
export interface TableRowDropEvent extends TableCancellable {
|
|
383
|
+
/** The dropped records with every field. */
|
|
384
|
+
records: TableRecord[];
|
|
385
|
+
/** The grid they came from. */
|
|
386
|
+
source: MountedTable;
|
|
387
|
+
}
|
|
253
388
|
export type TableRecordId = string | number;
|
|
254
389
|
export type TableCellChange = { id: TableRecordId; field: string; value: unknown };
|
|
255
390
|
/** Who made a change: the user in the grid, or the host through the API. */
|
|
@@ -266,6 +401,8 @@ export type TableChange = (
|
|
|
266
401
|
| { action: 'remove'; ids: TableRecordId[] }
|
|
267
402
|
| { action: 'undo' | 'redo' }
|
|
268
403
|
| { action: 'formula'; name: string; formula: string }
|
|
404
|
+
| { action: 'move'; ids: TableRecordId[]; before: TableRecordId | null }
|
|
405
|
+
| { action: 'transaction'; add?: Record<string, unknown>[]; update?: { id: TableRecordId; values: Record<string, unknown> }[]; remove?: TableRecordId[]; ids: TableRecordId[] }
|
|
269
406
|
) & { source: TableChangeSource };
|
|
270
407
|
|
|
271
408
|
/** What a cancellable event payload carries. A handler can also return false. */
|
|
@@ -405,6 +542,8 @@ export interface TableEventMap {
|
|
|
405
542
|
loadStart: TableLoadStartEvent;
|
|
406
543
|
loadProgress: TableLoadProgressEvent;
|
|
407
544
|
loadEnd: TableLoadEndEvent;
|
|
545
|
+
rowMove: TableRowMoveEvent;
|
|
546
|
+
rowDrop: TableRowDropEvent;
|
|
408
547
|
error: Error;
|
|
409
548
|
}
|
|
410
549
|
export type TableEventName = keyof TableEventMap;
|
|
@@ -453,13 +592,27 @@ export interface TableTotals {
|
|
|
453
592
|
/** The totals row's display text per field, for the columns on the drawn column page. */
|
|
454
593
|
totals: Record<string, string>;
|
|
455
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* A pivot: `rows` and `columns` list fields, `values` the measures. The short form names one of each with
|
|
597
|
+
* `rowField`, `columnField`, `valueField` and `agg`.
|
|
598
|
+
*/
|
|
456
599
|
export interface TablePivot {
|
|
457
|
-
|
|
600
|
+
rows?: string[];
|
|
601
|
+
columns?: string[];
|
|
602
|
+
values?: TablePivotValue[];
|
|
603
|
+
rowField?: string;
|
|
458
604
|
/** A field whose values become columns. Default none. */
|
|
459
605
|
columnField?: string;
|
|
460
|
-
valueField
|
|
606
|
+
valueField?: string;
|
|
607
|
+
/** Default 'sum'. */
|
|
608
|
+
agg?: 'sum' | 'average' | 'min' | 'max' | 'count';
|
|
609
|
+
}
|
|
610
|
+
export interface TablePivotValue {
|
|
611
|
+
field: string;
|
|
461
612
|
/** Default 'sum'. */
|
|
462
613
|
agg?: 'sum' | 'average' | 'min' | 'max' | 'count';
|
|
614
|
+
/** Shows each value against a total, as a running total or as a rank. Default 'normal'. */
|
|
615
|
+
showAs?: 'normal' | 'percentOfTotal' | 'percentOfCol' | 'percentOfRow' | 'runTotal' | 'rankDescending' | 'rankAscending' | 'index';
|
|
463
616
|
}
|
|
464
617
|
export type TableDialog =
|
|
465
618
|
| 'filter'
|
|
@@ -475,12 +628,20 @@ export type TableDialog =
|
|
|
475
628
|
| 'calculatedField'
|
|
476
629
|
| 'addRecord'
|
|
477
630
|
| 'source'
|
|
478
|
-
| 'conditionalFormatting'
|
|
631
|
+
| 'conditionalFormatting'
|
|
632
|
+
| 'sparkline'
|
|
633
|
+
| 'tree'
|
|
634
|
+
| 'find'
|
|
635
|
+
| 'assistant';
|
|
479
636
|
/** A group, by its values from the top level down (`['East', 'Widget']`), or by the path a state lists. */
|
|
480
637
|
export type TableGroupRef = unknown[] | string;
|
|
481
638
|
/** Options setOptions() can change after mount, and `on…` handlers (null removes one). */
|
|
482
639
|
export type TableLiveOptions = Partial<
|
|
483
|
-
Pick<
|
|
640
|
+
Pick<
|
|
641
|
+
TableOptions,
|
|
642
|
+
| 'chrome' | 'language' | 'title' | 'scrolling' | 'rowSelection' | 'renderers' | 'detailRenderer' | 'allowEdit' | 'sharing' | 'storageKey'
|
|
643
|
+
| 'density' | 'columnGroups' | 'contextMenu' | 'rowNumbers' | 'rowDrag' | 'rowDrop' | 'detailMode' | 'flashChanges' | 'assistant'
|
|
644
|
+
>
|
|
484
645
|
> & { [handler: `on${string}`]: ((...args: any[]) => any) | null | undefined };
|
|
485
646
|
|
|
486
647
|
/**
|
|
@@ -545,10 +706,13 @@ export interface MountedTable {
|
|
|
545
706
|
resetState(): Promise<void>;
|
|
546
707
|
/** Searches every visible field. '' clears it. @example await grid.setSearch('east'); */
|
|
547
708
|
setSearch(text: string): Promise<void>;
|
|
548
|
-
/**
|
|
549
|
-
|
|
709
|
+
/**
|
|
710
|
+
* Replaces the filters. Entries combine with AND; a group `{ any: [...] }` meets one of its parts.
|
|
711
|
+
* @example await grid.setFilters([{ any: [{ field: 'Region', op: 'equal', value: 'East' }, { field: 'Units', op: 'gt', value: 10 }] }]);
|
|
712
|
+
*/
|
|
713
|
+
setFilters(filters: TableFilterEntry[]): Promise<void>;
|
|
550
714
|
/** Adds a filter; filters combine with AND. @example await grid.addFilter({ field: 'Region', op: 'in', values: ['East', 'West'] }); */
|
|
551
|
-
addFilter(filter:
|
|
715
|
+
addFilter(filter: TableFilterEntry): Promise<void>;
|
|
552
716
|
/** Removes every filter, or those of one field. The search stays. @example await grid.clearFilters('Region'); */
|
|
553
717
|
clearFilters(field?: string): Promise<void>;
|
|
554
718
|
/**
|
|
@@ -583,10 +747,11 @@ export interface MountedTable {
|
|
|
583
747
|
expandGroup(group: TableGroupRef): Promise<void>;
|
|
584
748
|
/** Collapses a group. @example await grid.collapseGroup(['East']); */
|
|
585
749
|
collapseGroup(group: TableGroupRef): Promise<void>;
|
|
586
|
-
/** Expands every group. @example await grid.expandAll(); */
|
|
750
|
+
/** Expands every group, or every branch of a tree. @example await grid.expandAll(); */
|
|
587
751
|
expandAll(): Promise<void>;
|
|
588
|
-
/** Collapses every group
|
|
752
|
+
/** Collapses every group at every level, or every branch of a tree. @example await grid.collapseAll(); */
|
|
589
753
|
collapseAll(): Promise<void>;
|
|
754
|
+
|
|
590
755
|
/** Sets the summary under the records and in each group row, or null for none. @example await grid.setSummary({ field: 'Revenue', agg: 'sum' }); */
|
|
591
756
|
setSummary(summary: TableSummary | null): Promise<void>;
|
|
592
757
|
/** Shows or hides the totals row. Turning it on sums each number column that has no total yet. @example await grid.setTotalsRow(true); */
|
|
@@ -594,6 +759,41 @@ export interface MountedTable {
|
|
|
594
759
|
/** Shows or hides the filter row under the headings. Its filters stay either way. @example await grid.setFilterRow(true); */
|
|
595
760
|
setFilterRow(on: boolean): Promise<void>;
|
|
596
761
|
|
|
762
|
+
// ---- Tree ----
|
|
763
|
+
/** Shows the records as a tree, or with null as a list again. @example await grid.setTree({ parent: 'ManagerId', key: 'Id' }); */
|
|
764
|
+
setTree(tree: TableTree | null): Promise<void>;
|
|
765
|
+
/** Expands a tree parent. @example await grid.expandTreeNode(7); */
|
|
766
|
+
expandTreeNode(id: TableRecordId): Promise<void>;
|
|
767
|
+
/** Collapses a tree parent. @example await grid.collapseTreeNode(7); */
|
|
768
|
+
collapseTreeNode(id: TableRecordId): Promise<void>;
|
|
769
|
+
|
|
770
|
+
// ---- Pinned rows and moving records ----
|
|
771
|
+
/** The pinned records. @example grid.getPinnedRows().top */
|
|
772
|
+
getPinnedRows(): { top: TableRecordId[]; bottom: TableRecordId[] };
|
|
773
|
+
/** Pins records above (default) or below the scrolling ones. A server source needs `pinnedRows`. @example await grid.pinRows([42], 'bottom'); */
|
|
774
|
+
pinRows(ids: TableRecordId[], where?: 'top' | 'bottom'): Promise<void>;
|
|
775
|
+
/** Unpins records, or every pinned record. @example await grid.unpinRows(); */
|
|
776
|
+
unpinRows(ids?: TableRecordId[]): Promise<void>;
|
|
777
|
+
/**
|
|
778
|
+
* Moves records before another record, or to the end with null; needs no sort, groups or tree. Fires rowMove;
|
|
779
|
+
* a server source only fires it. Resolves with false when a handler cancelled.
|
|
780
|
+
* @example await grid.moveRecords([42], 7);
|
|
781
|
+
*/
|
|
782
|
+
moveRecords(ids: TableRecordId[], before?: TableRecordId | null): Promise<boolean>;
|
|
783
|
+
|
|
784
|
+
// ---- Live data ----
|
|
785
|
+
/**
|
|
786
|
+
* Applies the application's own changes to local records: updates, added and removed records. It works on
|
|
787
|
+
* read-only records and fields, skips undo, and flashes the changed cells with `flashChanges`. `updated`
|
|
788
|
+
* counts the cells whose value changed.
|
|
789
|
+
* @example await grid.applyTransaction({ update: [{ id: 3, values: { Price: 101.5 } }] });
|
|
790
|
+
*/
|
|
791
|
+
applyTransaction(tx: TableTransaction): Promise<{ added: TableRecordId[]; updated: number; removed: number }>;
|
|
792
|
+
/** Collects transactions for 50 ms and applies them as one; each call resolves with the combined result. @example grid.applyTransactionAsync({ update }); */
|
|
793
|
+
applyTransactionAsync(tx: TableTransaction): Promise<{ added: TableRecordId[]; updated: number; removed: number }>;
|
|
794
|
+
/** Flashes cells, as a changed value does with flashChanges; for remote data the host changed. @example grid.flashCells([{ id: 'A-1', field: 'Price' }]); */
|
|
795
|
+
flashCells(cells: { id: TableRecordId; field: string }[]): void;
|
|
796
|
+
|
|
597
797
|
// ---- Columns ----
|
|
598
798
|
/** The fields of the records. @example grid.getFields().map((f) => f.name) */
|
|
599
799
|
getFields(): TableFieldInfo[];
|
|
@@ -603,7 +803,8 @@ export interface MountedTable {
|
|
|
603
803
|
setColumns(columns: TableColumnState[]): Promise<void>;
|
|
604
804
|
/**
|
|
605
805
|
* Changes some settings of a column: hide or show, pin, width (48 to 800 px, null for automatic), number
|
|
606
|
-
* format, totals-row aggregate (null for none)
|
|
806
|
+
* format, totals-row aggregate (null for none), conditional rules, caption and sparkline (null removes
|
|
807
|
+
* either). The scroll position stays.
|
|
607
808
|
* @example await grid.setColumn('Revenue', { pinned: true, width: 140, format: '#,##0.00', total: 'sum' });
|
|
608
809
|
*/
|
|
609
810
|
setColumn(field: string, patch: Partial<Omit<TableColumnState, 'field'>>): Promise<void>;
|
|
@@ -633,6 +834,12 @@ export interface MountedTable {
|
|
|
633
834
|
* @example await grid.openPivot({ rowField: 'Region', columnField: 'Product', valueField: 'Revenue' });
|
|
634
835
|
*/
|
|
635
836
|
openPivot(pivot: TablePivot): Promise<void>;
|
|
837
|
+
/**
|
|
838
|
+
* Charts the selected cells in a dialog (column, bar, line or pie): categories from the first text column,
|
|
839
|
+
* a series per number column.
|
|
840
|
+
* @example await grid.chartRange();
|
|
841
|
+
*/
|
|
842
|
+
chartRange(): Promise<void>;
|
|
636
843
|
/** Leaves a pivot for the records. Nothing happens outside a pivot. @example await grid.closePivot(); */
|
|
637
844
|
closePivot(): Promise<void>;
|
|
638
845
|
/** The pivot's top 20 values of a field by absolute value, as the Chart dialog draws them. @example await grid.getChartData('Total'); */
|
|
@@ -671,8 +878,22 @@ export interface MountedTable {
|
|
|
671
878
|
* @example await grid.setRange({ anchor: { id: 0, field: 'Units' }, focus: { id: 4, field: 'Price' } });
|
|
672
879
|
*/
|
|
673
880
|
setRange(range: { anchor: { id: TableRecordId; field: string }; focus?: { id: TableRecordId; field: string } }): Promise<void>;
|
|
674
|
-
/** Copies the range as tab-separated text (as Ctrl+C) and resolves with it. Needs clipboard permission. @example await grid.copyRange(); */
|
|
675
|
-
copyRange(): Promise<string>;
|
|
881
|
+
/** Copies the range as tab-separated text (as Ctrl+C), with the headings first with `headers`, and resolves with it. Needs clipboard permission. @example await grid.copyRange({ headers: true }); */
|
|
882
|
+
copyRange(options?: { headers?: boolean }): Promise<string>;
|
|
883
|
+
|
|
884
|
+
// ---- Find and the context menu ----
|
|
885
|
+
/** Opens the Find bar, with `text` in it. Local records. @example await grid.openFind('Acme'); */
|
|
886
|
+
openFind(text?: string): Promise<void>;
|
|
887
|
+
/** Closes the Find bar. @example grid.closeFind(); */
|
|
888
|
+
closeFind(): void;
|
|
889
|
+
/**
|
|
890
|
+
* Moves to the next cell holding `text` (the previous one with `back`), across every matching record, and
|
|
891
|
+
* focuses it. Resolves with its record and field, or null when no cell holds it.
|
|
892
|
+
* @example const hit = await grid.findNext('Acme');
|
|
893
|
+
*/
|
|
894
|
+
findNext(text?: string, options?: { back?: boolean }): Promise<{ id: TableRecordId; field: string } | null>;
|
|
895
|
+
/** Opens a cell's context menu; false when it is turned off. @example await grid.openContextMenu(42, 'Units'); */
|
|
896
|
+
openContextMenu(id: TableRecordId, field: string): Promise<boolean>;
|
|
676
897
|
|
|
677
898
|
// ---- Row selection (needs rowSelection) ----
|
|
678
899
|
/** The selected records. @example const sel = grid.getSelection(); */
|
|
@@ -703,12 +924,14 @@ export interface MountedTable {
|
|
|
703
924
|
openDialog(name: TableDialog, options?: { field?: string }): Promise<void>;
|
|
704
925
|
/** Closes the open dialog or menu; false when none was open. @example grid.closeDialog(); */
|
|
705
926
|
closeDialog(): boolean;
|
|
706
|
-
/** Expands a record's detail panel (needs detailRenderer), closing any other; false as scrollToRecord. @example await grid.expandRecord(42); */
|
|
927
|
+
/** Expands a record's detail panel (needs detailRenderer), closing any other unless detailMode is 'multiple'; false as scrollToRecord. @example await grid.expandRecord(42); */
|
|
707
928
|
expandRecord(id: TableRecordId): Promise<boolean>;
|
|
708
|
-
/** Closes
|
|
709
|
-
collapseRecord(): boolean;
|
|
710
|
-
/** The record whose detail panel
|
|
929
|
+
/** Closes a record's detail panel, or every panel; false when none was open. @example grid.collapseRecord(); */
|
|
930
|
+
collapseRecord(id?: TableRecordId): boolean;
|
|
931
|
+
/** The record whose detail panel opened last, or null. @example grid.getExpandedRecord() */
|
|
711
932
|
getExpandedRecord(): TableRecordId | null;
|
|
933
|
+
/** The records whose detail panels are open, in the order they opened. @example grid.getExpandedRecords() */
|
|
934
|
+
getExpandedRecords(): TableRecordId[];
|
|
712
935
|
|
|
713
936
|
// ---- Editing ----
|
|
714
937
|
/** Whether edits are accepted now. @example grid.isEditable() */
|
|
@@ -768,9 +991,9 @@ export interface MountedTable {
|
|
|
768
991
|
|
|
769
992
|
// ---- Export and sharing ----
|
|
770
993
|
/** The matching records and visible columns as a file, or with `selected: true` only the selected ones among them. @example const blob = await grid.exportResults('xlsx'); */
|
|
771
|
-
exportResults(format: TableFormat, options?: { selected?: boolean }): Promise<Blob>;
|
|
994
|
+
exportResults(format: TableFormat, options?: { selected?: boolean; layout?: boolean }): Promise<Blob>;
|
|
772
995
|
/** Exports and saves the file through the browser. `fileName` default: the title and record count. @example await grid.download('csv', { fileName: 'orders.csv' }); */
|
|
773
|
-
download(format: TableFormat, options?: { selected?: boolean; fileName?: string }): Promise<void>;
|
|
996
|
+
download(format: TableFormat, options?: { selected?: boolean; fileName?: string; layout?: boolean }): Promise<void>;
|
|
774
997
|
/** Publishes the matching records as an XLSX copy through the `sharing` option. @example const { url } = await grid.createShareLink(); */
|
|
775
998
|
createShareLink(): Promise<{ id: string; url: string }>;
|
|
776
999
|
/** Revokes the last link createShareLink() made; false when there was none. @example await grid.revokeShareLink(); */
|
|
@@ -791,8 +1014,12 @@ export interface MountedTable {
|
|
|
791
1014
|
setChrome(chrome: TableChrome): void;
|
|
792
1015
|
/** The theme in use. @example grid.getChrome() === 'dark' */
|
|
793
1016
|
getChrome(): TableChrome;
|
|
794
|
-
/** Changes the
|
|
795
|
-
|
|
1017
|
+
/** Changes the row height: 'compact', 'normal' or 'comfortable'. @example await grid.setDensity('compact'); */
|
|
1018
|
+
setDensity(density: 'compact' | 'normal' | 'comfortable'): Promise<void>;
|
|
1019
|
+
/** The row height in use. @example grid.getDensity() */
|
|
1020
|
+
getDensity(): 'compact' | 'normal' | 'comfortable';
|
|
1021
|
+
/** Changes the interface language: 'en', 'pl', 'de', 'fr', 'es' or 'ja'. @example await grid.setLanguage('de'); */
|
|
1022
|
+
setLanguage(language: string): Promise<void>;
|
|
796
1023
|
/** The interface language in use. @example grid.getLanguage() */
|
|
797
1024
|
getLanguage(): string;
|
|
798
1025
|
/**
|
|
@@ -802,6 +1029,18 @@ export interface MountedTable {
|
|
|
802
1029
|
*/
|
|
803
1030
|
setOptions(options: TableLiveOptions): Promise<void>;
|
|
804
1031
|
|
|
1032
|
+
// ---- Assistant and state checks ----
|
|
1033
|
+
/**
|
|
1034
|
+
* Sends words to the `assistant` option and applies the state it answers with, once checked. Resolves with
|
|
1035
|
+
* the state applied (or null) and the assistant's message.
|
|
1036
|
+
* @example await grid.askAssistant('revenue by region, largest first');
|
|
1037
|
+
*/
|
|
1038
|
+
askAssistant(prompt: string): Promise<{ state: Partial<TableState> | null; message: string }>;
|
|
1039
|
+
/** A JSON Schema of the view state with this grid's field names, for a language model. @example grid.getStateSchema() */
|
|
1040
|
+
getStateSchema(): Record<string, unknown>;
|
|
1041
|
+
/** The problems of a state (or some keys of one) against the fields: unknown keys, fields and conditions. Empty when sound. @example grid.validateState(saved) */
|
|
1042
|
+
validateState(state: Partial<TableState>): string[];
|
|
1043
|
+
|
|
805
1044
|
// ---- Reading records ----
|
|
806
1045
|
/**
|
|
807
1046
|
* Matching records in display order (groups don't count, collapsed ones included), from `offset` (default
|
|
@@ -838,4 +1077,14 @@ export function remoteTableSource(options: {
|
|
|
838
1077
|
formats?: TableFormat[];
|
|
839
1078
|
/** The export endpoint accepts a `selection` and exports only those records. */
|
|
840
1079
|
selectionExport?: boolean;
|
|
1080
|
+
/** Pivots run on the server: it answers `{ state, spec }` with `{ fields, rows }`. */
|
|
1081
|
+
pivotUrl?: string;
|
|
1082
|
+
/** Pages answer `state.pinnedRows` with `pinned`. */
|
|
1083
|
+
pinnedRows?: boolean;
|
|
841
1084
|
}): TableDataSource;
|
|
1085
|
+
/** A batch of the application's own changes for applyTransaction(). */
|
|
1086
|
+
export interface TableTransaction {
|
|
1087
|
+
add?: Record<string, unknown>[];
|
|
1088
|
+
update?: { id: TableRecordId; values: Record<string, unknown> }[];
|
|
1089
|
+
remove?: TableRecordId[];
|
|
1090
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{STR as S}from"../core/sheet.js";import{DataManager as x}from"../datasheets/data-core.js";import{Reader as h,display as w}from"./model.js";import{MAX_COLS as
|
|
1
|
+
import{STR as S}from"../core/sheet.js";import{DataManager as x}from"../datasheets/data-core.js";import{Reader as h,display as w}from"./model.js";import{MAX_COLS as M,MAX_ROWS as O,parseRangeRef as T}from"../core/address.js";import{STAGE as F}from"../datasheets/view.js";import{countSelected as A,selectedRecords as m,selectionTest as q}from"./row-selection.js";import{findCells as N,countCells as P}from"./find.js";const L=new Set(["page","toggle","distinct","detail","chart","records","selectionCount","selectedIds","rows","record","rowOf","find","findCount","treeParents","neighbour"]),V=e=>e.formula==null&&e.trigger==null&&e.validator==null&&!(typeof e.defaultValue=="string"&&e.defaultValue.startsWith("="));function W(e){return e.op==="data"?!(e.fields??[]).every(V):e.op==="page"?e.state?.filters?.some(t=>t.formula!=null)??!1:!L.has(e.op)}let v=null;function j(){return v??=import("../datasheets/data.js").catch(e=>{throw v=null,e}),v}const U={file:()=>[import("./files.js"),import("./worksheet-table.js")],selectionStart:()=>[import("../core/workbook.js"),import("./worksheet-table.js")]};let n,u,k,f,d;const p=new Map;let b;function y(e,t){return n?.view.dispose(),n=new h(e,t),n.fields}let R=()=>{};function X(e){let t=0;return r=>{const o=performance.now();o-t<100||(t=o,self.postMessage({requestId:e,progress:r}))}}async function _(e){switch(e.op){case"selectionStart":{const{Workbook:t}=await import("../core/workbook.js");d=new t;return}case"selectionBatch":{const t=e.codes.map(r=>d.styles.derive(0,{numFmt:r}));for(let r=0;r<e.kinds.length;r++){if(!e.kinds[r])continue;const o=Math.floor((e.from+r)/e.cols),i=(e.from+r)%e.cols,l=e.kinds[r]===S?d.strings.add(e.texts[e.values[r]]):e.values[r];d.sheet.setCell(o,i,e.kinds[r],l),t[e.styles[r]]&&d.sheet.setStyle(o,i,t[e.styles[r]])}return}case"selectionEnd":{const{worksheetTable:t}=await import("./worksheet-table.js"),r=t(d,d.sheet,{r0:0,c0:0,r1:e.rows-1,c1:e.cols-1},e.headers,e.headerRows);return d=null,y(r,!1)}case"enableEdit":return n.editable=!0,n.fields;case"paste":{const t=n.view,r=t.perm.subarray(0,t.filteredCount),o=r.indexOf(e.id),i=t.columnIndex(e.field),l=e.lines.length*e.repeat;if(o<0||i<0||!Number.isSafeInteger(e.repeat)||e.repeat<1||o+l>r.length||e.lines.some(c=>i+c.length>t.columns.length))throw new Error("Paste exceeds the available records or columns.");const a=[];for(let c=0;c<l;c++)e.lines[c%e.lines.length].forEach((E,I)=>a.push({id:r[o+c],field:t.columns[i+I].field,value:E}));const s=n.edit(a);s.length&&(n.undo.push(s),n.redo.length=0);return}case"file":{const{openFile:t,sourcesOf:r}=await import("./files.js"),o=await t(e.file,e.csv,R),i=r(o);if(!i.length)throw new Error("This file contains no visible data.");return u=o,k=i,p.clear(),f=null,i}case"source":{const t=k[e.index],r=e.range?T(e.range.replaceAll("$","")):t.range;if(!r||r.r0<0||r.c0<0||r.r1>=O||r.c1>=M||r.r0<t.range.r0||r.c0<t.range.c0||r.r1>t.range.r1||r.c1>t.range.c1)throw new Error("Choose a range inside the source.");const o=t.whole?+(e.header!==!1):t.headerRows,i=JSON.stringify([e.index,t.native?null:[r.r0,r.c0,r.r1,r.c1],o]);if(f&&n.editable&&(p.set(f,n),n=null),f=i,p.has(i))return n?.view.dispose(),n=p.get(i),n.editable=e.editable,n.fields;const{worksheetTable:l}=await import("./worksheet-table.js"),a=t.native?u.book.sheets[t.sheet].table:l(u.book,u.book.sheets[t.sheet],r,t.headers,o,t.name);return y(a,e.editable)}case"data":{const t=new x;for(const[o,i]of Object.entries(e.strings??{})){const l=i.map(s=>t.strings.add(s)),a=e.data[o];for(let s=0;s<a.length;s++)a[s]>=0&&(a[s]=l[a[s]])}const r=t.addTable("Records",{fields:e.fields,data:e.data});return y(r,e.editable)}case"pivot":{const{pivotTable:t}=await import("./pivot.js"),r=t(n,e);return b=n,n=new h(r),n.fields}case"records":return n.view.dispose(),n=b,b=null,n.fields;case"chart":{const t=n.view,r=n.table.column(e.field);if(!r||!t.columns.some(l=>l.field===e.field))throw new Error("Field unavailable.");const o=n.table.column(t.columns[0].field),i=[];for(const l of t.perm){const a=r.get(l);l===n.table.rowCount-1||typeof a!="number"||!Number.isFinite(a)||i.length===20&&Math.abs(a)<=Math.abs(i[19].value)||(i.push({label:w(o.get(l),o.format),value:a,text:w(a,r.format)}),i.sort((s,c)=>Math.abs(c.value)-Math.abs(s.value)),i.length>20&&i.pop())}return i}case"distinct":return n.view.distinctValues(e.field,{limit:500});case"detail":return n.view.columns.map(t=>({field:t.field,value:w(t.col.get(e.id),t.format)}));case"page":return e.state&&n.apply(e.state),n.page(e.offset,e.limit,e.columnOffset,e.columnLimit);case"toggle":return n.view.toggleRow(e.index),n.page(e.offset,e.limit,e.columnOffset,e.columnLimit);case"edit":{const t=n.edit(e.cells);t.length&&(n.undo.push(t),n.redo.length=0);break}case"add":case"remove":{const t=e.op==="add"?(e.records??[e.values]).map(o=>({kind:"add",values:o??{}})):(e.ids??[e.record]).map(o=>({kind:"remove",id:o}));if(!t.length)return[];const r=n.rowActions(t);return n.undo.push(r),n.redo.length=0,e.op==="add"?r.kind==="batch"?r.actions.map(o=>o.id).reverse():[r.id]:t.map(o=>o.id)}case"rows":return n.records(e.offset,e.limit);case"record":return n.record(e.id);case"rowOf":{const t=n.view;return t.refresh(),Number.isInteger(e.id)&&e.id>=0?t.rowOfRecord(e.id):-1}case"find":return N(n,e);case"findCount":return P(n,e);case"treeParents":{const t=n.view;if(t.refresh(),!t.treeParent)return[];const r=new Set;for(let o=0;o<t.filteredCount;o++){const i=t.treeParent[t.perm[o]];i>=0&&r.add(i)}return[...r]}case"move":{const t=n.view;if(t.refresh(),t.spec.sort.length||t.spec.groups.length)throw new Error("Clear the sort and the groups to move records.");const r=e.ids.filter(o=>Number.isInteger(o)&&n.table.alive[o]);return r.length?(t.moveRecords(r,Number.isInteger(e.before)?e.before:-1),!0):!1}case"neighbour":{const t=n.view;t.refresh();const r=[];for(let i=0;i<t.count;i++)t.map[i]>=0&&r.push(t.map[i]);const o=r.indexOf(e.id);return o<0?void 0:e.after?r[o+1]??null:e.by<0?o>0?r[o-1]:void 0:o<r.length-1?r[o+2]??null:void 0}case"transaction":return n.transaction(e);case"undo":case"redo":{const t=n[e.op],r=e.op==="undo"?n.redo:n.undo;if(t.length){const o=t.at(-1);r.push(Array.isArray(o)?n.edit(o,!0):n.rowAction(o)),t.pop()}break}case"formula":{if(!n.editable)throw new Error("This view is read-only.");if(!e.name.trim()||!e.formula.trim()||n.table.column(e.name))throw new Error("Choose an unused column name and a formula.");return n.table.addField({name:e.name,type:"any",formula:e.formula.replace(/^=/,"")}),n.fields}case"export":{const{exportResults:t}=await import("./files.js"),r=new h(n.table);try{r.apply(e.layout?{...e.state,collapsed:[],collapseLevel:void 0,treeCollapsed:[],pinnedRows:void 0}:e.state);const o=e.selection&&q(e.selection);return o&&(r.view.spec.filters=[...r.view.spec.filters,{fn:o}],r.view.invalidate(F.FILTER)),await t(r,e.format,{layout:e.layout??null})}finally{r.view.dispose()}}case"selectionCount":{const t=n.view;return t.refresh(),A(e.selection,t.filtered,t.filteredCount)}case"selectedIds":{const t=n.view;return t.refresh(),m(e.selection,t.perm,t.filteredCount)}default:throw new Error("Unknown table action.")}}let C=Promise.resolve();self.onmessage=({data:e})=>{C=C.then(async()=>{try{W(e)&&await Promise.all([j(),...U[e.op]?.()??[]]),R=X(e.requestId),self.postMessage({requestId:e.requestId,value:await _(e)})}catch(t){self.postMessage({requestId:e.requestId,error:t.message})}})};
|
package/table-view/remote.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function m({queryUrl:l,exportUrl:w,detailUrl:y,updateUrl:p,headers:f,credentials:b="same-origin",pivotUrl:d,formats:h=["xlsx","csv"],selectionExport:g=!1,pinnedRows:T=!1}){async function a(s,t,e){const i=typeof f=="function"?await f():f,c=new Headers(i);c.set("Content-Type","application/json");const r=await fetch(s,{method:"POST",credentials:b,headers:c,body:JSON.stringify(t),signal:e});if(r.status===409)throw new Error("The data changed. Reopen the record before editing.");if(!r.ok)throw new Error(`Table request failed (HTTP ${r.status}).`);return r}const o={formats:h,pinnedRows:T===!0,async query({state:s,offset:t,limit:e,columnOffset:i,columnLimit:c,signal:r}){const n=await(await a(l,{state:s,offset:t,limit:e,columnOffset:i,columnLimit:c},r)).json();if(!Array.isArray(n.rows)||n.rows.length>e||!Array.isArray(n.columns)||!Number.isSafeInteger(n.offset)||n.offset<0||![n.count,n.matches,n.sourceCount].every(u=>u===void 0||Number.isSafeInteger(u)&&u>=0))throw new Error("Invalid table response.");return n}};return p&&(o.update=async({state:s,revision:t,cells:e})=>(await a(p,{state:s,revision:t,cells:e})).json()),d&&(o.pivot=async({state:s,spec:t,signal:e})=>(await a(d,{state:s,spec:t},e)).json()),y&&(o.detail=async({id:s,state:t,signal:e})=>(await a(y,{id:s,state:t},e)).json()),w&&(o.selectionExport=g,o.exportResults=async({state:s,format:t,selection:e,signal:i})=>(await a(w,e?{state:s,format:t,selection:e}:{state:s,format:t},i)).blob()),o}export{m as remoteTableSource};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{el as m,icon as g}from"./panel.js";import{cancellable as f}from"./events.js";const v=new WeakMap,E=t=>v.set(t.root,t);function D(t,i){const e=m("span",null,{className:"tv-row-grip"});return e.append(g("grip")),e.recordId=i.id,e.title=t.t("Drag to move"),e.setAttribute("aria-hidden","true"),e}function h(t,i){const e=n=>t(n),o=n=>{document.removeEventListener("pointermove",e),document.removeEventListener("pointerup",o),document.removeEventListener("pointercancel",o),i(n,n.type==="pointercancel")};document.addEventListener("pointermove",e),document.addEventListener("pointerup",o),document.addEventListener("pointercancel",o)}function w(t,i,e){const n=document.elementFromPoint(i,e)?.closest?.("tbody tr[data-record-index]");if(!n||!t.root.contains(n))return null;const l=t.grid?.records[Number(n.dataset.recordIndex)];if(!l)return null;const r=n.getBoundingClientRect();return{record:l,tr:n,after:e>r.top+r.height/2}}function A(t,i){i.addEventListener("pointerdown",e=>{const o=e.target.closest?.(".tv-row-grip");!o||e.button!==0||(e.preventDefault(),e.stopPropagation(),b(t,o.recordId,e))})}function b(t,i,e){const o=t.selection?.has(i)&&!t.selection.all?[...t.selection.ids]:[i];let n=null,l=null,r=null;h(d=>{if(!n){if(Math.abs(d.clientY-e.clientY)<4&&Math.abs(d.clientX-e.clientX)<4)return;n=m("div",o.length>1?o.length+" "+t.t("records"):t.t("Move record"),{className:"tv-drag-ghost tv-row-ghost"}),l=m("div",null,{className:"tv-row-marker"}),n.setAttribute("aria-hidden","true"),l.setAttribute("aria-hidden","true"),t.root.append(n,l),t.root.classList.add("tv-moving")}n.style.left=d.clientX+10+"px",n.style.top=d.clientY+10+"px";const s=document.elementFromPoint(d.clientX,d.clientY)?.closest?.(".tv-root"),a=s&&s!==t.root?v.get(s):null;if(r=null,l.hidden=!0,a){r=a.options.rowDrop?{other:a}:null,s.classList.toggle("tv-drop-target",!!r);return}const u=w(t,d.clientX,d.clientY);if(!u||o.includes(u.record.id))return;r=u;const p=u.tr.getBoundingClientRect();l.hidden=!1,l.style.left=p.left+"px",l.style.width=p.width+"px",l.style.top=(u.after?p.bottom:p.top)-1+"px"},(d,s)=>{if(!n)return;n.remove(),l.remove(),t.root.classList.remove("tv-moving");for(const c of document.querySelectorAll(".tv-drop-target"))c.classList.remove("tv-drop-target");if(s||!r)return;if(r.other)return t.perform(()=>x(t,r.other,o));const a=t.grid.records,u=a.findIndex(c=>c.id===r.record.id),p=r.after?a.slice(u+1).find(c=>!o.includes(c.id)):r.record;t.perform(async()=>{let c=p?p.id:null;return!p&&r.after&&!t.remote&&(c=await t.client.call("neighbour",{id:r.record.id,after:!0}),o.includes(c)&&(c=null)),t.moveRecords(o,c)})})}async function x(t,i,e){const o=[];for(const d of e)o.push(await t.api.getRecord(d));const n=f({records:o,source:t.api});if(!i.emit("rowDrop",n)||!i.editable||i.remote)return;const l=new Set(i.fields.map(d=>d.name)),r=o.map(d=>Object.fromEntries(Object.entries(d.raw).filter(([s,a])=>l.has(s)&&a!=null)));await i.change("add",{records:r},"user")}export{A as enableRowDrag,E as registerSurface,D as rowGrip};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const k=["line","column","winloss"],p="http://www.w3.org/2000/svg";function y(c){return Array.isArray(c)?c.map(Number).filter(Number.isFinite):String(c??"").split(/[\s,;|]+/).filter(Boolean).map(Number).filter(Number.isFinite)}function M(c,s,u,m,r=2){const t=s.length;if(!t)return null;const i=m-2*r;if(c==="line"){const o=Math.min(...s),a=Math.max(...s),x=a-o||1,N=b=>r+(t===1?(u-2*r)/2:b*(u-2*r)/(t-1)),F=b=>r+i-(b-o)/x*i,S=s.map((b,l)=>[N(l),a===o?m/2:F(b)]);return{path:S.map(([b,l],d)=>(d?"L":"M")+b.toFixed(1)+" "+l.toFixed(1)).join(""),last:S[t-1]}}const n=(u-2*r)/t,e=Math.max(1,n*.72);if(c==="winloss"){const o=m/2;return{bars:s.map((a,x)=>({x:r+x*n+(n-e)/2,y:a>=0?r:o+1,w:e,h:a===0?0:o-r-1,negative:a<0}))}}const g=Math.min(0,...s),A=Math.max(0,...s),h=A-g||1,f=r+A/h*i;return{bars:s.map((o,a)=>{const x=Math.abs(o)/h*i;return{x:r+a*n+(n-e)/2,y:o>=0?f-x:f,w:e,h:Math.max(o===0?0:1,x),negative:o<0}})}}function E(c,s,{width:u=96,height:m=20,label:r=""}={}){const t=document.createElementNS(p,"svg");t.setAttribute("viewBox",`0 0 ${u} ${m}`),t.setAttribute("width",String(u)),t.setAttribute("height",String(m)),t.setAttribute("class","tv-spark"),t.setAttribute("role","img"),t.setAttribute("aria-label",(r?r+": ":"")+s.join(", "));const i=M(k.includes(c)?c:"line",s,u,m);if(!i)return t;if(i.path){const n=document.createElementNS(p,"path");n.setAttribute("d",i.path),n.setAttribute("class","tv-spark-line");const e=document.createElementNS(p,"circle");return e.setAttribute("cx",i.last[0].toFixed(1)),e.setAttribute("cy",i.last[1].toFixed(1)),e.setAttribute("r","2"),e.setAttribute("class","tv-spark-dot"),t.append(n,e),t}for(const n of i.bars){if(!n.h)continue;const e=document.createElementNS(p,"rect");e.setAttribute("x",n.x.toFixed(1)),e.setAttribute("y",n.y.toFixed(1)),e.setAttribute("width",n.w.toFixed(1)),e.setAttribute("height",n.h.toFixed(1)),e.setAttribute("class",n.negative?"tv-spark-bar tv-spark-negative":"tv-spark-bar"),t.append(e)}return t}export{k as SPARKLINE_TYPES,y as parseSeries,E as sparklineNode,M as sparklineShapes};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const d=["sum","average","min","max","count","distinct"],y=["sum","average","min","max","count"],m=["contains","notContains","equal","notEqual","beginsWith","endsWith","gt","gte","lt","lte","between","notBetween","blank","notBlank","top","bottom","aboveAverage","belowAverage","today","yesterday","tomorrow","thisWeek","thisMonth","lastMonth","thisYear","lastYear","in","notIn"],g=["gt","gte","lt","lte","between","equal","notEqual","contains"],b=["field","hidden","pinned","width","format","total","rules","caption","sparkline"],$=["columns","search","filters","sort","groups","collapsed","collapseLevel","total","totalsRow","filterRow","tree","treeCollapsed","pinnedRows"],l=t=>t!==null&&typeof t=="object"&&!Array.isArray(t);function v(t,f){const a=new Set(f.map(e=>typeof e=="string"?e:e.name)),s=[],i=(e,n)=>{a.has(e)||s.push(`${n}: unknown field "${e}".`)};if(!l(t))return["A state is an object."];for(const e of Object.keys(t))$.includes(e)||s.push(`Unknown state key "${e}".`);const r=(e,n)=>{if(t[e]!==void 0){if(!Array.isArray(t[e]))return s.push(`${e} is a list.`);t[e].forEach((o,p)=>n(o,`${e}[${p}]`))}};r("columns",(e,n)=>{if(!l(e))return s.push(`${n} is an object.`);i(e.field,n);for(const o of Object.keys(e))b.includes(o)||s.push(`${n}: unknown column setting "${o}".`);e.width!=null&&!(Number.isFinite(e.width)&&e.width>=48&&e.width<=800)&&s.push(`${n}: a width is 48 to 800.`),e.total!=null&&!y.includes(e.total)&&s.push(`${n}: a total is one of ${y.join(", ")}.`),e.rules!=null&&!Array.isArray(e.rules)&&s.push(`${n}: rules are a list.`);for(const o of e.rules??[])(!l(o)||!["bar","scale","value"].includes(o.type)||o.type==="value"&&!g.includes(o.op))&&s.push(`${n}: an invalid formatting rule.`);e.sparkline!=null&&(!l(e.sparkline)||e.sparkline.fields!=null&&!Array.isArray(e.sparkline.fields))&&s.push(`${n}: a sparkline is { type, fields }.`);for(const o of e.sparkline?.fields??[])i(o,n+".sparkline")}),t.search!=null&&typeof t.search!="string"&&s.push("search is text.");const u=(e,n,o=0)=>{if(!l(e))return s.push(`${n} is an object.`);if(Array.isArray(e.any)||Array.isArray(e.all))return o>3?s.push(`${n}: groups nest at most four deep.`):(e.any??e.all).forEach((p,c)=>u(p,`${n}.${e.any?"any":"all"}[${c}]`,o+1));i(e.field,n),m.includes(e.op)||s.push(`${n}: unknown condition "${e.op}".`),(e.op==="in"||e.op==="notIn")&&!Array.isArray(e.values)&&s.push(`${n}: "${e.op}" lists its values.`)};r("filters",(e,n)=>u(e,n)),r("sort",(e,n)=>l(e)?i(e.field,n):s.push(`${n} is { field, desc }.`)),r("groups",(e,n)=>l(e)?i(e.field,n):s.push(`${n} is { field, desc }.`)),t.total!=null&&(l(t.total)?(i(t.total.field,"total"),d.includes(t.total.agg)||s.push(`total: agg is one of ${d.join(", ")}.`)):s.push("total is { field, agg } or null."));for(const e of["totalsRow","filterRow"])t[e]!=null&&typeof t[e]!="boolean"&&s.push(`${e} is true or false.`);return t.collapseLevel!=null&&!(Number.isInteger(t.collapseLevel)&&t.collapseLevel>=0)&&s.push("collapseLevel is a whole number from 0."),t.tree!=null&&(l(t.tree)?t.tree.level!=null?i(t.tree.level,"tree.level"):(i(t.tree.parent,"tree.parent"),t.tree.key!=null&&i(t.tree.key,"tree.key")):s.push("tree is { parent, key } or { level }.")),t.pinnedRows!=null&&(!l(t.pinnedRows)||["top","bottom"].some(e=>t.pinnedRows[e]!=null&&!Array.isArray(t.pinnedRows[e])))&&s.push("pinnedRows is { top, bottom } with lists of record IDs."),s}function k(t){const a={type:"string",enum:t.map(u=>typeof u=="string"?u:u.name)},s={type:"object",properties:{field:a,op:{type:"string",enum:m},value:{type:["string","number","boolean"]},value2:{type:["string","number","boolean"]},values:{type:"array",items:{type:["string","number","boolean"]}}},required:["field","op"],additionalProperties:!1},i={type:"object",properties:{any:{type:"array",items:s},all:{type:"array",items:s}},additionalProperties:!1},r={type:"object",properties:{field:a,desc:{type:"boolean"}},required:["field"],additionalProperties:!1};return{$schema:"https://json-schema.org/draft/2020-12/schema",title:"Data Grid view state (any subset of keys)",type:"object",properties:{search:{type:"string",description:"Text a record must contain in a visible column."},filters:{type:"array",items:{anyOf:[s,i]},description:'Every entry must hold; a group with "any" holds when one part does.'},sort:{type:"array",items:r},groups:{type:"array",items:r},total:{type:["object","null"],properties:{field:a,agg:{type:"string",enum:d}},required:["field","agg"],additionalProperties:!1},totalsRow:{type:"boolean"},columns:{type:"array",description:"Every column in display order. Leave it out to keep the columns as they are.",items:{type:"object",properties:{field:a,hidden:{type:"boolean"},pinned:{type:"boolean"},format:{type:"string",description:"An Excel number format, such as #,##0.00."},total:{type:"string",enum:y},caption:{type:"string"}},required:["field"],additionalProperties:!1}}},additionalProperties:!1}}export{v as stateProblems,k as stateSchema};
|