@surfaces-ui/components 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +48 -2
- package/dist/appComponents.d.ts +86 -0
- package/dist/appComponents.js +555 -0
- package/dist/appComponents.js.map +1 -0
- package/dist/chart/BulletGraph.d.ts +44 -0
- package/dist/chart/BulletGraph.js +40 -0
- package/dist/chart/BulletGraph.js.map +1 -0
- package/dist/chart/Chart.d.ts +177 -0
- package/dist/chart/Chart.js +279 -0
- package/dist/chart/Chart.js.map +1 -0
- package/dist/chart/Sparkline.d.ts +35 -0
- package/dist/chart/Sparkline.js +37 -0
- package/dist/chart/Sparkline.js.map +1 -0
- package/dist/chart/advice.d.ts +28 -0
- package/dist/chart/advice.js +39 -0
- package/dist/chart/advice.js.map +1 -0
- package/dist/chart/option.d.ts +90 -0
- package/dist/chart/option.js +252 -0
- package/dist/chart/option.js.map +1 -0
- package/dist/controls/Combobox.d.ts +39 -0
- package/dist/controls/Combobox.js +75 -0
- package/dist/controls/Combobox.js.map +1 -0
- package/dist/controls/ConfirmDialog.d.ts +35 -0
- package/dist/controls/ConfirmDialog.js +84 -0
- package/dist/controls/ConfirmDialog.js.map +1 -0
- package/dist/controls/ItemControls.d.ts +115 -0
- package/dist/controls/ItemControls.js +109 -0
- package/dist/controls/ItemControls.js.map +1 -0
- package/dist/controls/Popover.d.ts +31 -0
- package/dist/controls/Popover.js +114 -0
- package/dist/controls/Popover.js.map +1 -0
- package/dist/controls/ResizeHandle.d.ts +48 -0
- package/dist/controls/ResizeHandle.js +91 -0
- package/dist/controls/ResizeHandle.js.map +1 -0
- package/dist/controls/SegmentedControl.d.ts +27 -0
- package/dist/controls/SegmentedControl.js +17 -0
- package/dist/controls/SegmentedControl.js.map +1 -0
- package/dist/controls/StatusBadge.d.ts +17 -0
- package/dist/controls/StatusBadge.js +10 -0
- package/dist/controls/StatusBadge.js.map +1 -0
- package/dist/controls/context.d.ts +17 -0
- package/dist/controls/context.js +2 -0
- package/dist/controls/context.js.map +1 -0
- package/dist/controls/placement.d.ts +43 -0
- package/dist/controls/placement.js +19 -0
- package/dist/controls/placement.js.map +1 -0
- package/dist/controls/resize.d.ts +23 -0
- package/dist/controls/resize.js +49 -0
- package/dist/controls/resize.js.map +1 -0
- package/dist/data/DataSourceProvider.d.ts +11 -0
- package/dist/data/DataSourceProvider.js +21 -0
- package/dist/data/DataSourceProvider.js.map +1 -0
- package/dist/data/export.d.ts +33 -0
- package/dist/data/export.js +77 -0
- package/dist/data/export.js.map +1 -0
- package/dist/data/format.d.ts +44 -0
- package/dist/data/format.js +127 -0
- package/dist/data/format.js.map +1 -0
- package/dist/data/messages.d.ts +13 -0
- package/dist/data/messages.js +2 -0
- package/dist/data/messages.js.map +1 -0
- package/dist/data/useRowWindow.d.ts +70 -0
- package/dist/data/useRowWindow.js +175 -0
- package/dist/data/useRowWindow.js.map +1 -0
- package/dist/discovery/AskData.d.ts +22 -0
- package/dist/discovery/AskData.js +48 -0
- package/dist/discovery/AskData.js.map +1 -0
- package/dist/discovery/ContextBuilder.d.ts +49 -0
- package/dist/discovery/ContextBuilder.js +167 -0
- package/dist/discovery/ContextBuilder.js.map +1 -0
- package/dist/discovery/DataSearch.d.ts +27 -0
- package/dist/discovery/DataSearch.js +73 -0
- package/dist/discovery/DataSearch.js.map +1 -0
- package/dist/discovery/ObjectDetail.d.ts +38 -0
- package/dist/discovery/ObjectDetail.js +129 -0
- package/dist/discovery/ObjectDetail.js.map +1 -0
- package/dist/discovery/RelationshipGraph.d.ts +19 -0
- package/dist/discovery/RelationshipGraph.js +64 -0
- package/dist/discovery/RelationshipGraph.js.map +1 -0
- package/dist/discovery/shared.d.ts +38 -0
- package/dist/discovery/shared.js +64 -0
- package/dist/discovery/shared.js.map +1 -0
- package/dist/editor/SqlEditor.d.ts +41 -0
- package/dist/editor/SqlEditor.js +181 -0
- package/dist/editor/SqlEditor.js.map +1 -0
- package/dist/explore/Explorer.d.ts +110 -0
- package/dist/explore/Explorer.js +471 -0
- package/dist/explore/Explorer.js.map +1 -0
- package/dist/explore/ModelLineage.d.ts +22 -0
- package/dist/explore/ModelLineage.js +70 -0
- package/dist/explore/ModelLineage.js.map +1 -0
- package/dist/explore/ReportBuilder.d.ts +39 -0
- package/dist/explore/ReportBuilder.js +98 -0
- package/dist/explore/ReportBuilder.js.map +1 -0
- package/dist/explore/SemanticModelEditor.d.ts +60 -0
- package/dist/explore/SemanticModelEditor.js +220 -0
- package/dist/explore/SemanticModelEditor.js.map +1 -0
- package/dist/explore/SemanticRows.d.ts +42 -0
- package/dist/explore/SemanticRows.js +117 -0
- package/dist/explore/SemanticRows.js.map +1 -0
- package/dist/explore/SemanticsProvider.d.ts +31 -0
- package/dist/explore/SemanticsProvider.js +72 -0
- package/dist/explore/SemanticsProvider.js.map +1 -0
- package/dist/explore/model.d.ts +151 -0
- package/dist/explore/model.js +344 -0
- package/dist/explore/model.js.map +1 -0
- package/dist/explore/report.d.ts +60 -0
- package/dist/explore/report.js +92 -0
- package/dist/explore/report.js.map +1 -0
- package/dist/explore/semantic-proposal.d.ts +44 -0
- package/dist/explore/semantic-proposal.js +67 -0
- package/dist/explore/semantic-proposal.js.map +1 -0
- package/dist/explore/semantic.d.ts +44 -0
- package/dist/explore/semantic.js +154 -0
- package/dist/explore/semantic.js.map +1 -0
- package/dist/files/FileBrowser.d.ts +42 -0
- package/dist/files/FileBrowser.js +314 -0
- package/dist/files/FileBrowser.js.map +1 -0
- package/dist/files/files.d.ts +65 -0
- package/dist/files/files.js +165 -0
- package/dist/files/files.js.map +1 -0
- package/dist/filter/FilterBar.d.ts +49 -0
- package/dist/filter/FilterBar.js +153 -0
- package/dist/filter/FilterBar.js.map +1 -0
- package/dist/filter/QueryFilters.d.ts +25 -0
- package/dist/filter/QueryFilters.js +58 -0
- package/dist/filter/QueryFilters.js.map +1 -0
- package/dist/form/Form.d.ts +76 -0
- package/dist/form/Form.js +131 -0
- package/dist/form/Form.js.map +1 -0
- package/dist/graph/NodeGraph.d.ts +30 -0
- package/dist/graph/NodeGraph.js +86 -0
- package/dist/graph/NodeGraph.js.map +1 -0
- package/dist/graph/model.d.ts +68 -0
- package/dist/graph/model.js +122 -0
- package/dist/graph/model.js.map +1 -0
- package/dist/grid/DataGrid.d.ts +98 -0
- package/dist/grid/DataGrid.js +399 -0
- package/dist/grid/DataGrid.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/locale/SurfacesText.d.ts +17 -0
- package/dist/locale/SurfacesText.js +17 -0
- package/dist/locale/SurfacesText.js.map +1 -0
- package/dist/locale/locale.d.ts +305 -0
- package/dist/locale/locale.js +359 -0
- package/dist/locale/locale.js.map +1 -0
- package/dist/menu/ContextMenu.d.ts +31 -0
- package/dist/menu/ContextMenu.js +95 -0
- package/dist/menu/ContextMenu.js.map +1 -0
- package/dist/metric/Metric.d.ts +33 -0
- package/dist/metric/Metric.js +63 -0
- package/dist/metric/Metric.js.map +1 -0
- package/dist/metric/useMeasure.d.ts +23 -0
- package/dist/metric/useMeasure.js +43 -0
- package/dist/metric/useMeasure.js.map +1 -0
- package/dist/model/ModelDiagram.d.ts +142 -0
- package/dist/model/ModelDiagram.js +699 -0
- package/dist/model/ModelDiagram.js.map +1 -0
- package/dist/panzoom/usePanZoom.d.ts +117 -0
- package/dist/panzoom/usePanZoom.js +313 -0
- package/dist/panzoom/usePanZoom.js.map +1 -0
- package/dist/pipeline/DatasetReview.d.ts +48 -0
- package/dist/pipeline/DatasetReview.js +157 -0
- package/dist/pipeline/DatasetReview.js.map +1 -0
- package/dist/pipeline/IngestWizard.d.ts +51 -0
- package/dist/pipeline/IngestWizard.js +79 -0
- package/dist/pipeline/IngestWizard.js.map +1 -0
- package/dist/pipeline/Pipeline.d.ts +171 -0
- package/dist/pipeline/Pipeline.js +203 -0
- package/dist/pipeline/Pipeline.js.map +1 -0
- package/dist/pipeline/PipelineView.d.ts +63 -0
- package/dist/pipeline/PipelineView.js +239 -0
- package/dist/pipeline/PipelineView.js.map +1 -0
- package/dist/pivot/PivotTable.d.ts +94 -0
- package/dist/pivot/PivotTable.js +171 -0
- package/dist/pivot/PivotTable.js.map +1 -0
- package/dist/plan/QueryPlan.d.ts +29 -0
- package/dist/plan/QueryPlan.js +79 -0
- package/dist/plan/QueryPlan.js.map +1 -0
- package/dist/result/QueryResult.d.ts +51 -0
- package/dist/result/QueryResult.js +255 -0
- package/dist/result/QueryResult.js.map +1 -0
- package/dist/review/ActionReceipt.d.ts +52 -0
- package/dist/review/ActionReceipt.js +32 -0
- package/dist/review/ActionReceipt.js.map +1 -0
- package/dist/review/PiiReview.d.ts +37 -0
- package/dist/review/PiiReview.js +29 -0
- package/dist/review/PiiReview.js.map +1 -0
- package/dist/review/PlanReview.d.ts +42 -0
- package/dist/review/PlanReview.js +37 -0
- package/dist/review/PlanReview.js.map +1 -0
- package/dist/review/StepFlow.d.ts +25 -0
- package/dist/review/StepFlow.js +21 -0
- package/dist/review/StepFlow.js.map +1 -0
- package/dist/review/pii.d.ts +21 -0
- package/dist/review/pii.js +67 -0
- package/dist/review/pii.js.map +1 -0
- package/dist/rows/RowList.d.ts +41 -0
- package/dist/rows/RowList.js +71 -0
- package/dist/rows/RowList.js.map +1 -0
- package/dist/schema/ObjectBrowser.d.ts +78 -0
- package/dist/schema/ObjectBrowser.js +467 -0
- package/dist/schema/ObjectBrowser.js.map +1 -0
- package/dist/schema/ObjectInfo.d.ts +25 -0
- package/dist/schema/ObjectInfo.js +69 -0
- package/dist/schema/ObjectInfo.js.map +1 -0
- package/dist/schema/SchemaExplorer.d.ts +32 -0
- package/dist/schema/SchemaExplorer.js +175 -0
- package/dist/schema/SchemaExplorer.js.map +1 -0
- package/dist/schema/refs.d.ts +32 -0
- package/dist/schema/refs.js +65 -0
- package/dist/schema/refs.js.map +1 -0
- package/dist/site/Site.d.ts +191 -0
- package/dist/site/Site.js +138 -0
- package/dist/site/Site.js.map +1 -0
- package/dist/source/ConnectionBuilder.d.ts +54 -0
- package/dist/source/ConnectionBuilder.js +115 -0
- package/dist/source/ConnectionBuilder.js.map +1 -0
- package/dist/source/SourceList.d.ts +17 -0
- package/dist/source/SourceList.js +71 -0
- package/dist/source/SourceList.js.map +1 -0
- package/dist/styles.css +9882 -0
- package/dist/styles.layer.css +9886 -0
- package/dist/table/DataTable.d.ts +72 -0
- package/dist/table/DataTable.js +68 -0
- package/dist/table/DataTable.js.map +1 -0
- package/dist/table/Pagination.d.ts +20 -0
- package/dist/table/Pagination.js +16 -0
- package/dist/table/Pagination.js.map +1 -0
- package/dist/table/SelectionBar.d.ts +43 -0
- package/dist/table/SelectionBar.js +18 -0
- package/dist/table/SelectionBar.js.map +1 -0
- package/dist/text/Markdown.d.ts +71 -0
- package/dist/text/Markdown.js +187 -0
- package/dist/text/Markdown.js.map +1 -0
- package/dist/text/highlight.d.ts +23 -0
- package/dist/text/highlight.js +196 -0
- package/dist/text/highlight.js.map +1 -0
- package/dist/theme/ThemePicker.d.ts +16 -0
- package/dist/theme/ThemePicker.js +49 -0
- package/dist/theme/ThemePicker.js.map +1 -0
- package/dist/theme/ThemeProvider.d.ts +43 -0
- package/dist/theme/ThemeProvider.js +107 -0
- package/dist/theme/ThemeProvider.js.map +1 -0
- package/dist/workspace/NavBar.d.ts +23 -0
- package/dist/workspace/NavBar.js +171 -0
- package/dist/workspace/NavBar.js.map +1 -0
- package/dist/workspace/SideNav.d.ts +61 -0
- package/dist/workspace/SideNav.js +149 -0
- package/dist/workspace/SideNav.js.map +1 -0
- package/dist/workspace/Workspace.d.ts +50 -0
- package/dist/workspace/Workspace.js +243 -0
- package/dist/workspace/Workspace.js.map +1 -0
- package/dist/workspace/icons.d.ts +34 -0
- package/dist/workspace/icons.js +37 -0
- package/dist/workspace/icons.js.map +1 -0
- package/dist/workspace/layout.d.ts +74 -0
- package/dist/workspace/layout.js +276 -0
- package/dist/workspace/layout.js.map +1 -0
- package/package.json +85 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { DataSource, QueryErrorInfo } from "@surfaces-ui/data";
|
|
2
|
+
import { type Notice } from "@surfaces-ui/proto";
|
|
3
|
+
import { type Field } from "apache-arrow";
|
|
4
|
+
import type { DataMessages } from "../data/messages.js";
|
|
5
|
+
import { type ColumnFormat } from "../data/format.js";
|
|
6
|
+
import { type FilterInit, type StoredInfo, type TimeTravelInit, type ValueInit } from "../data/useRowWindow.js";
|
|
7
|
+
export interface GridSort {
|
|
8
|
+
column: string;
|
|
9
|
+
desc: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** How a grid's columns are laid out. Every part is optional, so `{}` is the default layout. */
|
|
12
|
+
export interface GridColumns {
|
|
13
|
+
/** Column names in display order. Columns not named follow in the query's order. */
|
|
14
|
+
order?: string[];
|
|
15
|
+
/** Columns not shown. They are still fetched, so showing one again is instant. */
|
|
16
|
+
hidden?: string[];
|
|
17
|
+
/** Widths in px, by column name. */
|
|
18
|
+
widths?: Record<string, number>;
|
|
19
|
+
/** Headers to show in place of column names, by column name ("Starts" for `starts_at`). Sorting, filters and the layout keep the names. */
|
|
20
|
+
labels?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
/** The names to show, in order, for the columns a query returned. */
|
|
23
|
+
export declare function arrangeColumns(names: string[], layout?: GridColumns): string[];
|
|
24
|
+
/** A layout with `name` moved to sit before `before` (or to the end), among the shown columns. */
|
|
25
|
+
export declare function moveColumn(names: string[], layout: GridColumns, name: string, before: string | undefined): GridColumns;
|
|
26
|
+
/** What the grid knows about its query, for surrounding UI such as "show SQL". */
|
|
27
|
+
export interface DataGridInfo {
|
|
28
|
+
total: number | undefined;
|
|
29
|
+
executedSql: string;
|
|
30
|
+
notices: Notice[];
|
|
31
|
+
fields: Field[];
|
|
32
|
+
error: string | undefined;
|
|
33
|
+
/** Code and position of the error in the SQL, when the backend reports them. */
|
|
34
|
+
errorInfo: QueryErrorInfo | undefined;
|
|
35
|
+
/** Set when the rows come from a result the backend kept; the data is as of `createdAt`. */
|
|
36
|
+
stored: StoredInfo | undefined;
|
|
37
|
+
/** Runs the query again, discarding any kept result. */
|
|
38
|
+
refresh(): void;
|
|
39
|
+
/** True while the first rows are on their way. */
|
|
40
|
+
loading: boolean;
|
|
41
|
+
/** Stops a query that is still running. */
|
|
42
|
+
cancel(): void;
|
|
43
|
+
}
|
|
44
|
+
export interface DataGridProps extends DataMessages {
|
|
45
|
+
/** Which source to query. */
|
|
46
|
+
sourceId: string;
|
|
47
|
+
/** The base SQL. Sorting, filtering and paging are applied around it by the backend. */
|
|
48
|
+
sql: string;
|
|
49
|
+
filters?: FilterInit[];
|
|
50
|
+
parameters?: ValueInit[];
|
|
51
|
+
timeTravel?: TimeTravelInit;
|
|
52
|
+
/** ISO 8601 time of the run this grid belongs to; see `RowWindowQuery.notBefore`. */
|
|
53
|
+
notBefore?: string;
|
|
54
|
+
/** How to write particular columns, by name: currency, percent, compact numbers, dates. */
|
|
55
|
+
formats?: Record<string, ColumnFormat>;
|
|
56
|
+
/** Controlled sort. Omit to let the grid keep its own. */
|
|
57
|
+
sorts?: GridSort[];
|
|
58
|
+
onSortsChange?(sorts: GridSort[]): void;
|
|
59
|
+
/** Controlled column order, hidden columns and widths. Omit to let the grid keep its own. */
|
|
60
|
+
columns?: GridColumns;
|
|
61
|
+
onColumnsChange?(columns: GridColumns): void;
|
|
62
|
+
/** Adds "Filter to this value" and "Leave this value out" to a cell's menu. */
|
|
63
|
+
onCellFilter?(column: string, value: unknown, exclude: boolean): void;
|
|
64
|
+
/** Adds SQL items to the column menu, called with the generated statement. */
|
|
65
|
+
onUseSql?(sql: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* "scroll" (default) scrolls through every row, loading blocks as needed.
|
|
68
|
+
* "pages" shows one page at a time with Previous and Next.
|
|
69
|
+
*/
|
|
70
|
+
mode?: "scroll" | "pages";
|
|
71
|
+
/** Rows per page in "pages" mode. Defaults to 50. */
|
|
72
|
+
pageSize?: number;
|
|
73
|
+
/** Height of the grid. A number is px. Defaults to 420. */
|
|
74
|
+
height?: number | string;
|
|
75
|
+
/**
|
|
76
|
+
* The line under the rows: the row count, the time the query took, "as of" with Run again for a kept result,
|
|
77
|
+
* and Show hidden columns. `false` leaves it out, for a small look at a few rows inside something else; the
|
|
78
|
+
* row count is still announced. In "pages" mode the footer stays, since it holds Previous and Next.
|
|
79
|
+
*/
|
|
80
|
+
footer?: boolean;
|
|
81
|
+
/** Row height in px. Defaults to the theme's density. */
|
|
82
|
+
rowHeight?: number;
|
|
83
|
+
/** Called when the row count, executed SQL, notices, columns or error change. */
|
|
84
|
+
onInfo?(info: DataGridInfo): void;
|
|
85
|
+
/** Called with the row's values when a row is clicked. */
|
|
86
|
+
onRowClick?(row: Record<string, unknown>, index: number): void;
|
|
87
|
+
/** Uses this DataSource instead of the one from DataSourceProvider. */
|
|
88
|
+
dataSource?: DataSource;
|
|
89
|
+
/** Accessible name for the grid. */
|
|
90
|
+
label?: string;
|
|
91
|
+
className?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A table that scales with the data, not the browser: rows are fetched in
|
|
95
|
+
* blocks as they scroll into view, only visible rows and columns are in the
|
|
96
|
+
* DOM, and sorting sends a new query instead of sorting loaded rows.
|
|
97
|
+
*/
|
|
98
|
+
export declare function DataGrid(props: DataGridProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { SortDirection } from "@surfaces-ui/proto";
|
|
3
|
+
import { DENSITY_SCALE } from "@surfaces-ui/tokens";
|
|
4
|
+
import { DataType } from "apache-arrow";
|
|
5
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
6
|
+
import { useDataSource } from "../data/DataSourceProvider.js";
|
|
7
|
+
import { displayCell, formatCellAs, isNumeric } from "../data/format.js";
|
|
8
|
+
import { dateFormat, label as text, numberFormat } from "../locale/locale.js";
|
|
9
|
+
import { useRowWindow } from "../data/useRowWindow.js";
|
|
10
|
+
import { copyText, useContextMenu } from "../menu/ContextMenu.js";
|
|
11
|
+
import { useOptionalTheme } from "../theme/ThemeProvider.js";
|
|
12
|
+
/** The names to show, in order, for the columns a query returned. */
|
|
13
|
+
export function arrangeColumns(names, layout = {}) {
|
|
14
|
+
const hidden = new Set(layout.hidden ?? []);
|
|
15
|
+
const first = (layout.order ?? []).filter((name, i, all) => names.includes(name) && all.indexOf(name) === i);
|
|
16
|
+
return [...first, ...names.filter((name) => !first.includes(name))].filter((name) => !hidden.has(name));
|
|
17
|
+
}
|
|
18
|
+
/** A layout with `name` moved to sit before `before` (or to the end), among the shown columns. */
|
|
19
|
+
export function moveColumn(names, layout, name, before) {
|
|
20
|
+
const shown = arrangeColumns(names, layout).filter((n) => n !== name);
|
|
21
|
+
const at = before === undefined ? shown.length : shown.indexOf(before);
|
|
22
|
+
shown.splice(at < 0 ? shown.length : at, 0, name);
|
|
23
|
+
return { ...layout, order: shown };
|
|
24
|
+
}
|
|
25
|
+
const COLUMN_MIME = "application/x-surfaces-grid-column";
|
|
26
|
+
const RESIZE_STEP = 16;
|
|
27
|
+
/** Browsers stop laying out elements taller than a few tens of millions of px. */
|
|
28
|
+
const MAX_BODY_HEIGHT = 10_000_000;
|
|
29
|
+
const OVERSCAN_ROWS = 6;
|
|
30
|
+
const OVERSCAN_PX = 240;
|
|
31
|
+
const MIN_COLUMN = 60;
|
|
32
|
+
const MAX_COLUMN = 1200;
|
|
33
|
+
const count = { format: (n) => numberFormat().format(n) };
|
|
34
|
+
function defaultWidth(field) {
|
|
35
|
+
const type = field.type;
|
|
36
|
+
const base = DataType.isBool(type)
|
|
37
|
+
? 90
|
|
38
|
+
: DataType.isTimestamp(type)
|
|
39
|
+
? 190
|
|
40
|
+
: DataType.isDate(type)
|
|
41
|
+
? 120
|
|
42
|
+
: isNumeric(type)
|
|
43
|
+
? 120
|
|
44
|
+
: 180;
|
|
45
|
+
return Math.max(base, Math.min(320, field.name.length * 9 + 48));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A table that scales with the data, not the browser: rows are fetched in
|
|
49
|
+
* blocks as they scroll into view, only visible rows and columns are in the
|
|
50
|
+
* DOM, and sorting sends a new query instead of sorting loaded rows.
|
|
51
|
+
*/
|
|
52
|
+
export function DataGrid(props) {
|
|
53
|
+
const { sourceId, sql, filters, parameters, timeTravel, mode = "scroll", pageSize = 50, height = 420, label } = props;
|
|
54
|
+
const dataSource = useDataSource(props.dataSource);
|
|
55
|
+
const theme = useOptionalTheme();
|
|
56
|
+
const rowHeight = props.rowHeight ?? DENSITY_SCALE[theme?.theme.density ?? "comfortable"].rowHeight;
|
|
57
|
+
const [ownSorts, setOwnSorts] = useState([]);
|
|
58
|
+
const sorts = props.sorts ?? ownSorts;
|
|
59
|
+
const setSorts = (next) => {
|
|
60
|
+
if (props.sorts === undefined)
|
|
61
|
+
setOwnSorts(next);
|
|
62
|
+
props.onSortsChange?.(next);
|
|
63
|
+
};
|
|
64
|
+
const window = useRowWindow(dataSource, {
|
|
65
|
+
sourceId,
|
|
66
|
+
sql,
|
|
67
|
+
filters,
|
|
68
|
+
parameters,
|
|
69
|
+
timeTravel,
|
|
70
|
+
notBefore: props.notBefore,
|
|
71
|
+
sorts: sorts.map((s) => ({ column: s.column, direction: s.desc ? SortDirection.DESC : SortDirection.ASC })),
|
|
72
|
+
}, { blockSize: mode === "pages" ? pageSize : 200 });
|
|
73
|
+
const { fields, total } = window;
|
|
74
|
+
const onInfo = useRef(props.onInfo);
|
|
75
|
+
onInfo.current = props.onInfo;
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
onInfo.current?.({
|
|
78
|
+
total: window.total,
|
|
79
|
+
executedSql: window.executedSql,
|
|
80
|
+
notices: window.notices,
|
|
81
|
+
fields: window.fields,
|
|
82
|
+
error: window.status === "error" ? window.error : undefined,
|
|
83
|
+
errorInfo: window.status === "error" ? window.errorInfo : undefined,
|
|
84
|
+
stored: window.stored,
|
|
85
|
+
refresh: window.refresh,
|
|
86
|
+
loading: window.status === "loading",
|
|
87
|
+
cancel: window.cancel,
|
|
88
|
+
});
|
|
89
|
+
}, [window.total, window.executedSql, window.notices, window.fields, window.status, window.error, window.errorInfo, window.stored, window.refresh, window.cancel]);
|
|
90
|
+
// Reset position when the query changes.
|
|
91
|
+
const [page, setPage] = useState(0);
|
|
92
|
+
const scroller = useRef(null);
|
|
93
|
+
const queryKey = `${sourceId}\n${sql}\n${JSON.stringify(sorts)}`;
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
setPage(0);
|
|
96
|
+
if (scroller.current)
|
|
97
|
+
scroller.current.scrollTop = 0;
|
|
98
|
+
}, [queryKey]);
|
|
99
|
+
// Column layout: order, hidden columns and widths, the grid's own unless the host controls it.
|
|
100
|
+
const [ownColumns, setOwnColumns] = useState({});
|
|
101
|
+
const layout = props.columns ?? ownColumns;
|
|
102
|
+
const layoutRef = useRef(layout);
|
|
103
|
+
layoutRef.current = layout;
|
|
104
|
+
const setColumns = (next) => {
|
|
105
|
+
layoutRef.current = next;
|
|
106
|
+
if (props.columns === undefined)
|
|
107
|
+
setOwnColumns(next);
|
|
108
|
+
props.onColumnsChange?.(next);
|
|
109
|
+
};
|
|
110
|
+
const names = fields.map((f) => f.name);
|
|
111
|
+
const shown = arrangeColumns(names, layout).map((name) => ({ field: fields[names.indexOf(name)], source: names.indexOf(name) }));
|
|
112
|
+
const sizes = layout.widths ?? {};
|
|
113
|
+
const headerOf = (name) => layout.labels?.[name] || name;
|
|
114
|
+
const setSize = (name, width) => {
|
|
115
|
+
const { [name]: _, ...rest } = layoutRef.current.widths ?? {};
|
|
116
|
+
setColumns({ ...layoutRef.current, widths: width === undefined ? rest : { ...rest, [name]: Math.max(MIN_COLUMN, Math.min(MAX_COLUMN, Math.round(width))) } });
|
|
117
|
+
};
|
|
118
|
+
const [resizing, setResizing] = useState();
|
|
119
|
+
const [dropBefore, setDropBefore] = useState();
|
|
120
|
+
const [note, setNote] = useState("");
|
|
121
|
+
const menu = useContextMenu();
|
|
122
|
+
const gridId = useId();
|
|
123
|
+
const widths = shown.map(({ field }) => sizes[field.name] ?? defaultWidth(field));
|
|
124
|
+
const offsets = [];
|
|
125
|
+
let totalWidth = 0;
|
|
126
|
+
for (const width of widths) {
|
|
127
|
+
offsets.push(totalWidth);
|
|
128
|
+
totalWidth += width;
|
|
129
|
+
}
|
|
130
|
+
const startResize = (name, startWidth) => (event) => {
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
const handle = event.currentTarget;
|
|
133
|
+
const startX = event.clientX;
|
|
134
|
+
handle.setPointerCapture?.(event.pointerId);
|
|
135
|
+
setResizing(name);
|
|
136
|
+
const move = (e) => setSize(name, startWidth + e.clientX - startX);
|
|
137
|
+
const stop = () => {
|
|
138
|
+
handle.removeEventListener("pointermove", move);
|
|
139
|
+
handle.removeEventListener("pointerup", stop);
|
|
140
|
+
handle.removeEventListener("pointercancel", stop);
|
|
141
|
+
setResizing(undefined);
|
|
142
|
+
};
|
|
143
|
+
handle.addEventListener("pointermove", move);
|
|
144
|
+
handle.addEventListener("pointerup", stop);
|
|
145
|
+
handle.addEventListener("pointercancel", stop);
|
|
146
|
+
};
|
|
147
|
+
// Viewport. jsdom and hidden containers report 0, so fall back to the props.
|
|
148
|
+
const [viewport, setViewport] = useState({ width: 0, height: 0 });
|
|
149
|
+
const [scroll, setScroll] = useState({ top: 0, left: 0 });
|
|
150
|
+
useLayoutEffect(() => {
|
|
151
|
+
const element = scroller.current;
|
|
152
|
+
if (!element)
|
|
153
|
+
return;
|
|
154
|
+
const measure = () => setViewport({ width: element.clientWidth, height: element.clientHeight });
|
|
155
|
+
measure();
|
|
156
|
+
if (typeof ResizeObserver === "undefined")
|
|
157
|
+
return;
|
|
158
|
+
const observer = new ResizeObserver(measure);
|
|
159
|
+
observer.observe(element);
|
|
160
|
+
return () => observer.disconnect();
|
|
161
|
+
}, []);
|
|
162
|
+
const viewHeight = Math.max(0, (viewport.height || (typeof height === "number" ? height - 40 : 380)) - rowHeight);
|
|
163
|
+
const viewWidth = viewport.width || 960;
|
|
164
|
+
// Rows in play: everything in scroll mode, one page in pages mode.
|
|
165
|
+
const pages = total === undefined ? 1 : Math.max(1, Math.ceil(total / pageSize));
|
|
166
|
+
const rowBase = mode === "pages" ? page * pageSize : 0;
|
|
167
|
+
const rowCount = total === undefined ? 0 : mode === "pages" ? Math.max(0, Math.min(pageSize, total - rowBase)) : total;
|
|
168
|
+
// Past the browser's height limit the scrollbar becomes proportional: its
|
|
169
|
+
// position maps onto the row range instead of onto pixels.
|
|
170
|
+
const fullHeight = rowCount * rowHeight;
|
|
171
|
+
const bodyHeight = Math.min(fullHeight, MAX_BODY_HEIGHT);
|
|
172
|
+
const scaled = fullHeight > MAX_BODY_HEIGHT;
|
|
173
|
+
const visibleRows = Math.ceil(viewHeight / rowHeight) + 1;
|
|
174
|
+
let firstRow;
|
|
175
|
+
let rowTop;
|
|
176
|
+
if (scaled) {
|
|
177
|
+
const range = Math.max(1, bodyHeight - viewHeight);
|
|
178
|
+
const lead = Math.round((Math.min(scroll.top, range) / range) * Math.max(0, rowCount - visibleRows + 1));
|
|
179
|
+
firstRow = lead;
|
|
180
|
+
rowTop = (index) => scroll.top + (index - lead) * rowHeight;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
firstRow = Math.max(0, Math.floor(scroll.top / rowHeight) - OVERSCAN_ROWS);
|
|
184
|
+
rowTop = (index) => index * rowHeight;
|
|
185
|
+
}
|
|
186
|
+
const lastRow = Math.min(rowCount, firstRow + visibleRows + (scaled ? 0 : OVERSCAN_ROWS * 2));
|
|
187
|
+
const { ensure } = window;
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (rowCount > 0)
|
|
190
|
+
ensure(rowBase + firstRow, rowBase + lastRow);
|
|
191
|
+
}, [ensure, rowBase, firstRow, lastRow, rowCount]);
|
|
192
|
+
// Columns in view.
|
|
193
|
+
let firstColumn = 0;
|
|
194
|
+
while (firstColumn < widths.length - 1 && offsets[firstColumn] + widths[firstColumn] < scroll.left - OVERSCAN_PX)
|
|
195
|
+
firstColumn++;
|
|
196
|
+
let lastColumn = firstColumn;
|
|
197
|
+
while (lastColumn < widths.length && offsets[lastColumn] < scroll.left + viewWidth + OVERSCAN_PX)
|
|
198
|
+
lastColumn++;
|
|
199
|
+
const visibleColumns = shown.slice(firstColumn, lastColumn).map(({ field, source }, i) => ({ field, source, index: firstColumn + i }));
|
|
200
|
+
// The active cell, for the keyboard. `row` counts within the rows in play (a page, or everything).
|
|
201
|
+
const [active, setActive] = useState();
|
|
202
|
+
const activeCell = active && active.row < rowCount && active.column < shown.length ? active : undefined;
|
|
203
|
+
const reveal = (row, column) => {
|
|
204
|
+
const element = scroller.current;
|
|
205
|
+
if (!element)
|
|
206
|
+
return;
|
|
207
|
+
if (!scaled) {
|
|
208
|
+
const top = row * rowHeight;
|
|
209
|
+
if (top < element.scrollTop)
|
|
210
|
+
element.scrollTop = top;
|
|
211
|
+
else if (top + rowHeight > element.scrollTop + viewHeight)
|
|
212
|
+
element.scrollTop = top + rowHeight - viewHeight;
|
|
213
|
+
}
|
|
214
|
+
const left = offsets[column] ?? 0;
|
|
215
|
+
const width = widths[column] ?? 0;
|
|
216
|
+
if (left < element.scrollLeft)
|
|
217
|
+
element.scrollLeft = left;
|
|
218
|
+
else if (left + width > element.scrollLeft + viewWidth)
|
|
219
|
+
element.scrollLeft = left + width - viewWidth;
|
|
220
|
+
};
|
|
221
|
+
const goTo = (row, column) => {
|
|
222
|
+
if (rowCount === 0 || shown.length === 0)
|
|
223
|
+
return;
|
|
224
|
+
const next = { row: Math.max(0, Math.min(rowCount - 1, row)), column: Math.max(0, Math.min(shown.length - 1, column)) };
|
|
225
|
+
setActive(next);
|
|
226
|
+
reveal(next.row, next.column);
|
|
227
|
+
};
|
|
228
|
+
const say = (message) => setNote(message);
|
|
229
|
+
const copy = (value, what) => void copyText(value).then((ok) => say(ok ? text("grid.copied", { what }) : text("grid.copyFailed")));
|
|
230
|
+
const cellText = (row, column) => {
|
|
231
|
+
const at = shown[column];
|
|
232
|
+
if (!at || !window.isLoaded(rowBase + row))
|
|
233
|
+
return "";
|
|
234
|
+
const value = window.getCell(rowBase + row, at.source);
|
|
235
|
+
return value == null ? "" : formatCellAs(value, at.field.type, undefined).text;
|
|
236
|
+
};
|
|
237
|
+
const onGridKeyDown = (event) => {
|
|
238
|
+
// Keys pressed in the header (sort buttons) are theirs.
|
|
239
|
+
if (event.target !== event.currentTarget)
|
|
240
|
+
return;
|
|
241
|
+
const at = activeCell ?? { row: 0, column: 0 };
|
|
242
|
+
const page = Math.max(1, Math.floor(viewHeight / rowHeight) - 1);
|
|
243
|
+
const mod = event.ctrlKey || event.metaKey;
|
|
244
|
+
const done = (row, column) => {
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
goTo(row, column);
|
|
247
|
+
};
|
|
248
|
+
if (event.key === "ArrowDown")
|
|
249
|
+
return done(activeCell ? at.row + 1 : 0, at.column);
|
|
250
|
+
if (event.key === "ArrowUp")
|
|
251
|
+
return done(at.row - 1, at.column);
|
|
252
|
+
if (event.key === "ArrowRight")
|
|
253
|
+
return done(at.row, activeCell ? at.column + 1 : 0);
|
|
254
|
+
if (event.key === "ArrowLeft")
|
|
255
|
+
return done(at.row, at.column - 1);
|
|
256
|
+
if (event.key === "PageDown")
|
|
257
|
+
return done(at.row + page, at.column);
|
|
258
|
+
if (event.key === "PageUp")
|
|
259
|
+
return done(at.row - page, at.column);
|
|
260
|
+
if (event.key === "Home")
|
|
261
|
+
return done(mod ? 0 : at.row, 0);
|
|
262
|
+
if (event.key === "End")
|
|
263
|
+
return done(mod ? rowCount - 1 : at.row, shown.length - 1);
|
|
264
|
+
if (!activeCell)
|
|
265
|
+
return;
|
|
266
|
+
if (mod && event.key.toLowerCase() === "c") {
|
|
267
|
+
event.preventDefault();
|
|
268
|
+
return copy(cellText(at.row, at.column), text("grid.copiedCell"));
|
|
269
|
+
}
|
|
270
|
+
if (event.key === "Enter" && props.onRowClick && window.isLoaded(rowBase + at.row)) {
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
props.onRowClick(rowObject(rowBase + at.row), rowBase + at.row);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
const quoted = (name) => (/^[A-Za-z_]\w*$/.test(name) ? name : `"${name.replace(/"/g, '""')}"`);
|
|
276
|
+
const useSql = (statement) => (props.onUseSql ? props.onUseSql(statement) : copy(statement, text("grid.copiedSql")));
|
|
277
|
+
const headerMenu = (name, index) => {
|
|
278
|
+
const all = arrangeColumns(names, { ...layout, hidden: [] });
|
|
279
|
+
const hidden = layout.hidden ?? [];
|
|
280
|
+
const from = `(${sql.trim().replace(/;\s*$/, "")}) AS t`;
|
|
281
|
+
return [
|
|
282
|
+
{ label: text("grid.sortAscending"), onSelect: () => setSorts([{ column: name, desc: false }]) },
|
|
283
|
+
{ label: text("grid.sortDescending"), onSelect: () => setSorts([{ column: name, desc: true }]) },
|
|
284
|
+
{ label: text("grid.clearSorting"), disabled: sorts.length === 0, onSelect: () => setSorts([]) },
|
|
285
|
+
{ separator: true },
|
|
286
|
+
{ label: text("grid.moveLeft"), hint: "Alt ←", disabled: index === 0, onSelect: () => setColumns(moveColumn(names, layout, name, shown[index - 1]?.field.name)) },
|
|
287
|
+
{ label: text("grid.moveRight"), hint: "Alt →", disabled: index >= shown.length - 1, onSelect: () => setColumns(moveColumn(names, layout, name, shown[index + 2]?.field.name)) },
|
|
288
|
+
{ label: text("grid.hideColumn"), disabled: shown.length <= 1, onSelect: () => setColumns({ ...layout, hidden: [...hidden, name] }) },
|
|
289
|
+
{ label: hidden.length ? text("grid.showAllColumnsHidden", { count: count.format(hidden.length) }) : text("grid.showAllColumns"), disabled: hidden.length === 0, onSelect: () => setColumns({ ...layout, hidden: [] }) },
|
|
290
|
+
{ label: text("grid.resetWidth"), hint: text("grid.resetWidthHint"), disabled: sizes[name] === undefined, onSelect: () => setSize(name, undefined) },
|
|
291
|
+
{ label: text("grid.resetLayout"), disabled: all.join() === names.join() && hidden.length === 0 && Object.keys(sizes).length === 0, onSelect: () => setColumns({}) },
|
|
292
|
+
{ separator: true },
|
|
293
|
+
{ label: text("grid.copyColumnName"), onSelect: () => copy(name, text("grid.copiedColumnName")) },
|
|
294
|
+
{ label: text("grid.sqlCountValues"), onSelect: () => useSql(`SELECT ${quoted(name)}, COUNT(*) AS row_count\nFROM ${from}\nGROUP BY ${quoted(name)}\nORDER BY row_count DESC`) },
|
|
295
|
+
{ label: text("grid.sqlRange"), onSelect: () => useSql(`SELECT MIN(${quoted(name)}) AS lowest, MAX(${quoted(name)}) AS highest, COUNT(*) - COUNT(${quoted(name)}) AS missing\nFROM ${from}`) },
|
|
296
|
+
];
|
|
297
|
+
};
|
|
298
|
+
const cellMenu = (row, column) => {
|
|
299
|
+
const at = shown[column];
|
|
300
|
+
if (!at || !window.isLoaded(rowBase + row))
|
|
301
|
+
return [];
|
|
302
|
+
const value = window.getCell(rowBase + row, at.source);
|
|
303
|
+
const json = () => JSON.stringify(rowObject(rowBase + row), (_, v) => (typeof v === "bigint" ? v.toString() : v), 2);
|
|
304
|
+
return [
|
|
305
|
+
{ label: text("grid.copyValue"), hint: "Ctrl/⌘ C", onSelect: () => copy(cellText(row, column), text("grid.copiedCell")) },
|
|
306
|
+
{ label: text("grid.copyRowJson"), onSelect: () => copy(json(), text("grid.copiedRow")) },
|
|
307
|
+
...(props.onCellFilter
|
|
308
|
+
? [
|
|
309
|
+
{ separator: true },
|
|
310
|
+
{ label: text("grid.filterToValue"), onSelect: () => props.onCellFilter?.(at.field.name, value, false) },
|
|
311
|
+
{ label: text("grid.leaveValueOut"), onSelect: () => props.onCellFilter?.(at.field.name, value, true) },
|
|
312
|
+
]
|
|
313
|
+
: []),
|
|
314
|
+
];
|
|
315
|
+
};
|
|
316
|
+
const onHeaderKeyDown = (name, index) => (event) => {
|
|
317
|
+
const step = event.key === "ArrowLeft" ? -1 : event.key === "ArrowRight" ? 1 : 0;
|
|
318
|
+
if (step === 0)
|
|
319
|
+
return;
|
|
320
|
+
if (event.altKey) {
|
|
321
|
+
event.preventDefault();
|
|
322
|
+
const target = index + step;
|
|
323
|
+
if (target < 0 || target >= shown.length)
|
|
324
|
+
return;
|
|
325
|
+
setColumns(moveColumn(names, layout, name, shown[step < 0 ? target : target + 1]?.field.name));
|
|
326
|
+
say(text(step < 0 ? "grid.movedLeft" : "grid.movedRight", { name }));
|
|
327
|
+
}
|
|
328
|
+
else if (event.shiftKey) {
|
|
329
|
+
event.preventDefault();
|
|
330
|
+
setSize(name, (widths[index] ?? MIN_COLUMN) + step * RESIZE_STEP);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const onHeaderDrop = (target, index) => (event) => {
|
|
334
|
+
const name = event.dataTransfer.getData(COLUMN_MIME);
|
|
335
|
+
setDropBefore(undefined);
|
|
336
|
+
if (!name || name === target)
|
|
337
|
+
return;
|
|
338
|
+
event.preventDefault();
|
|
339
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
340
|
+
const after = event.clientX > box.left + box.width / 2;
|
|
341
|
+
setColumns(moveColumn(names, layout, name, after ? shown[index + 1]?.field.name : target));
|
|
342
|
+
say(text("grid.moved", { name }));
|
|
343
|
+
};
|
|
344
|
+
const toggleSort = (column, event) => {
|
|
345
|
+
const current = sorts.find((s) => s.column === column);
|
|
346
|
+
const next = !current ? { column, desc: false } : current.desc ? undefined : { column, desc: true };
|
|
347
|
+
if (event.shiftKey) {
|
|
348
|
+
const others = sorts.filter((s) => s.column !== column);
|
|
349
|
+
setSorts(next ? [...others, next] : others);
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
setSorts(next ? [next] : []);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const cellStyle = (index) => ({ left: offsets[index], width: widths[index] });
|
|
356
|
+
const rowObject = (row) => Object.fromEntries(fields.map((f, c) => [f.name, window.getCell(row, c)]));
|
|
357
|
+
const rows = [];
|
|
358
|
+
for (let index = firstRow; index < lastRow; index++) {
|
|
359
|
+
const absolute = rowBase + index;
|
|
360
|
+
const loaded = window.isLoaded(absolute);
|
|
361
|
+
rows.push(_jsx("div", { role: "row", "aria-rowindex": absolute + 2, className: "sf-grid-row", "data-odd": absolute % 2 === 1 || undefined, "data-clickable": props.onRowClick ? true : undefined, style: { top: rowTop(index), height: rowHeight, width: totalWidth }, onClick: props.onRowClick && loaded ? () => props.onRowClick?.(rowObject(absolute), absolute) : undefined, children: visibleColumns.map(({ field, source, index: column }) => {
|
|
362
|
+
if (!loaded) {
|
|
363
|
+
return (_jsx("div", { role: "gridcell", "aria-colindex": column + 1, className: "sf-grid-cell", style: cellStyle(column), children: _jsx("span", { className: "sf-grid-skeleton" }) }, field.name));
|
|
364
|
+
}
|
|
365
|
+
const cell = displayCell(window.getCell(absolute, source), field.type, props.formats?.[field.name]);
|
|
366
|
+
const isActive = activeCell?.row === index && activeCell.column === column;
|
|
367
|
+
return (_jsx("div", { role: "gridcell", "aria-colindex": column + 1, className: "sf-grid-cell", "data-numeric": cell.numeric || undefined, "data-null": cell.isNull || undefined, "data-active": isActive || undefined, id: isActive ? `${gridId}-active` : undefined, "aria-selected": isActive || undefined, style: cellStyle(column), onMouseDown: () => setActive({ row: index, column }), onContextMenu: (event) => {
|
|
368
|
+
setActive({ row: index, column });
|
|
369
|
+
menu.open(event, text("grid.cellMenu", { name: headerOf(field.name) }), cellMenu(index, column));
|
|
370
|
+
}, children: cell.text }, field.name));
|
|
371
|
+
}) }, absolute));
|
|
372
|
+
}
|
|
373
|
+
const status = window.status === "error"
|
|
374
|
+
? text("grid.failed")
|
|
375
|
+
: total === undefined
|
|
376
|
+
? text("grid.loading")
|
|
377
|
+
: text(total === 1 ? "grid.rowsOne" : "grid.rows", { count: count.format(total) });
|
|
378
|
+
return (_jsxs("div", { className: ["sf-grid", props.className].filter(Boolean).join(" "), style: { height: typeof height === "number" ? `${height}px` : height }, children: [_jsxs("div", { ref: scroller, className: "sf-grid-scroll", role: "grid", "aria-label": label ?? text("grid.label"), "aria-rowcount": total === undefined ? -1 : total + 1, "aria-colcount": shown.length, "aria-activedescendant": activeCell ? `${gridId}-active` : undefined, onKeyDown: onGridKeyDown, onContextMenu: (event) => {
|
|
379
|
+
// The Menu key and Shift+F10 on the grid itself open the active cell's menu.
|
|
380
|
+
if (event.target === event.currentTarget && activeCell)
|
|
381
|
+
menu.open(event, text("grid.activeCellMenu"), cellMenu(activeCell.row, activeCell.column));
|
|
382
|
+
}, "aria-busy": window.status === "loading", tabIndex: 0, onScroll: (event) => setScroll({ top: event.currentTarget.scrollTop, left: event.currentTarget.scrollLeft }), children: [_jsx("div", { role: "row", "aria-rowindex": 1, className: "sf-grid-header", style: { width: totalWidth, height: rowHeight }, children: visibleColumns.map(({ field, index }) => {
|
|
383
|
+
const sort = sorts.find((s) => s.column === field.name);
|
|
384
|
+
const order = sorts.length > 1 && sort ? sorts.indexOf(sort) + 1 : undefined;
|
|
385
|
+
return (_jsxs("div", { role: "columnheader", "aria-colindex": index + 1, "aria-sort": sort ? (sort.desc ? "descending" : "ascending") : "none", className: "sf-grid-head", "data-numeric": isNumeric(field.type) || undefined, "data-drop": dropBefore === field.name || undefined, style: cellStyle(index), draggable: true, onDragStart: (event) => {
|
|
386
|
+
// Dragging the edge resizes; it must not also pick the column up.
|
|
387
|
+
if (resizing)
|
|
388
|
+
return event.preventDefault();
|
|
389
|
+
event.dataTransfer.setData(COLUMN_MIME, field.name);
|
|
390
|
+
event.dataTransfer.effectAllowed = "move";
|
|
391
|
+
}, onDragOver: (event) => {
|
|
392
|
+
if (!event.dataTransfer.types.includes(COLUMN_MIME))
|
|
393
|
+
return;
|
|
394
|
+
event.preventDefault();
|
|
395
|
+
setDropBefore(field.name);
|
|
396
|
+
}, onDragLeave: () => setDropBefore(undefined), onDragEnd: () => setDropBefore(undefined), onDrop: onHeaderDrop(field.name, index), onContextMenu: (event) => menu.open(event, text("grid.columnMenu", { name: headerOf(field.name) }), headerMenu(field.name, index)), children: [_jsxs("button", { type: "button", className: "sf-grid-sort", title: `${headerOf(field.name) === field.name ? "" : `${field.name} · `}${String(field.type)}`, "aria-keyshortcuts": "Alt+ArrowLeft Alt+ArrowRight Shift+ArrowLeft Shift+ArrowRight Shift+F10", onClick: (event) => toggleSort(field.name, event), onKeyDown: onHeaderKeyDown(field.name, index), children: [_jsx("span", { className: "sf-grid-name", children: headerOf(field.name) }), sort && (_jsxs("span", { className: "sf-grid-arrow", "aria-hidden": "true", children: [sort.desc ? "↓" : "↑", order] }))] }), _jsx("span", { className: "sf-grid-resize", "data-resizing": resizing === field.name || undefined, onPointerDown: startResize(field.name, widths[index]), onDoubleClick: () => setSize(field.name, undefined), "aria-hidden": "true" })] }, field.name));
|
|
397
|
+
}) }), _jsx("div", { className: "sf-grid-body", style: { height: bodyHeight, width: totalWidth }, children: rows }), window.status === "error" && (_jsx("p", { className: "sf-grid-message", role: "alert", "data-error": window.error, children: props.errorMessage ?? window.error })), window.status === "ready" && total === 0 && _jsx("p", { className: "sf-grid-message", children: props.emptyMessage ?? text("grid.noRows") })] }), props.footer === false && mode !== "pages" ? (_jsx("span", { className: "sf-visually-hidden", "aria-live": "polite", children: status })) : (_jsxs("div", { className: "sf-grid-footer", children: [_jsx("span", { "aria-live": "polite", children: status }), (layout.hidden?.length ?? 0) > 0 && (_jsx("button", { type: "button", className: "sf-button", onClick: () => setColumns({ ...layout, hidden: [] }), children: text(layout.hidden.length === 1 ? "grid.showHiddenOne" : "grid.showHidden", { count: count.format(layout.hidden.length) }) })), _jsx("span", { className: "sf-grid-note", role: "status", children: note }), window.elapsedMs !== undefined && window.status === "ready" && _jsx("span", { children: text("grid.elapsed", { ms: window.elapsedMs }) }), window.stored && window.status === "ready" && (_jsxs("span", { className: "sf-grid-asof", children: [text("grid.asOf", { time: dateFormat({ hour: "numeric", minute: "2-digit", second: "2-digit" }).format(new Date(window.stored.createdAt)) }), _jsx("button", { type: "button", className: "sf-button", onClick: window.refresh, children: text("grid.runAgain") })] })), mode === "pages" && total !== undefined && (_jsxs("span", { className: "sf-grid-pager", children: [_jsx("button", { type: "button", className: "sf-button", disabled: page === 0, onClick: () => setPage(page - 1), children: text("grid.previous") }), _jsx("span", { children: text("grid.page", { page: count.format(page + 1), pages: count.format(pages) }) }), _jsx("button", { type: "button", className: "sf-button", disabled: page + 1 >= pages, onClick: () => setPage(page + 1), children: text("grid.next") })] }))] })), menu.element] }));
|
|
398
|
+
}
|
|
399
|
+
//# sourceMappingURL=DataGrid.js.map
|