@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,72 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type ItemControl } from "../controls/ItemControls.js";
|
|
3
|
+
import { type MenuItem } from "../menu/ContextMenu.js";
|
|
4
|
+
/** Which way a `DataTable` is sorted: a column's id, and whether largest or latest comes first. */
|
|
5
|
+
export interface DataTableSort {
|
|
6
|
+
column: string;
|
|
7
|
+
desc: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** One column of a `DataTable`. */
|
|
10
|
+
export interface DataTableColumn<Row> {
|
|
11
|
+
/** Tells columns apart, and names the sort the table reports. */
|
|
12
|
+
id: string;
|
|
13
|
+
/** The heading. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** Draws the cell. Without it the cell is the row's value under `id`, as text. */
|
|
16
|
+
cell?(row: Row): ReactNode;
|
|
17
|
+
/** Whether a press on the heading asks the host to sort by this column. The table never sorts rows itself. */
|
|
18
|
+
sortable?: boolean;
|
|
19
|
+
/** "end" for numbers, so their digits line up. */
|
|
20
|
+
align?: "start" | "end";
|
|
21
|
+
/**
|
|
22
|
+
* When the column is shown. "always" (the default) at every width; "medium" from 36rem of the table's own width;
|
|
23
|
+
* "wide" from 52rem. Keep the column that names a row, and anything a person must see to act, at "always".
|
|
24
|
+
*/
|
|
25
|
+
show?: "always" | "medium" | "wide";
|
|
26
|
+
}
|
|
27
|
+
export interface DataTableProps<Row> {
|
|
28
|
+
/** What the rows are, for assistive technology: "People". */
|
|
29
|
+
label: string;
|
|
30
|
+
columns: readonly DataTableColumn<Row>[];
|
|
31
|
+
/** The rows to show, already sorted, filtered and paged by the host. The table shows them in the order given. */
|
|
32
|
+
rows: readonly Row[];
|
|
33
|
+
/** A value that tells rows apart and stays the same when the rows change: an id. */
|
|
34
|
+
rowKey(row: Row): string;
|
|
35
|
+
/** The row's name, for its check box and its controls: "Ana Admin". Defaults to the first column's text. */
|
|
36
|
+
rowName?(row: Row): string;
|
|
37
|
+
/** The column that names each row, drawn as the row's header. Defaults to the first. */
|
|
38
|
+
rowHeader?: string;
|
|
39
|
+
/** How the host has sorted `rows`. */
|
|
40
|
+
sort?: DataTableSort;
|
|
41
|
+
/** Asked for when a sortable heading is pressed: the column, ascending first, then the other way. */
|
|
42
|
+
onSortChange?(sort: DataTableSort): void;
|
|
43
|
+
/** The keys of the rows ticked. Giving it, with `onSelectedChange`, adds a check box to each row and the heading. */
|
|
44
|
+
selected?: ReadonlySet<string>;
|
|
45
|
+
onSelectedChange?(selected: Set<string>): void;
|
|
46
|
+
/** Whether a row can be ticked. One that cannot shows no check box: the person's own account, say. */
|
|
47
|
+
selectable?(row: Row): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Every row that matches is selected, past this page too (see `SelectionBar`). Each box is shown ticked; changing
|
|
50
|
+
* any box reports the rows on this page as ticked or not, so the host goes back to choosing row by row.
|
|
51
|
+
*/
|
|
52
|
+
allSelected?: boolean;
|
|
53
|
+
/** The actions on one row, drawn with `ItemControls`: the everyday ones only, with the rest a press further on. */
|
|
54
|
+
rowControls?(row: Row): ItemControl[];
|
|
55
|
+
/** "hover" shows a row's controls when it is pointed at or has focus (always on touch); "always" (the default) keeps them shown. */
|
|
56
|
+
controlsShow?: "hover" | "always";
|
|
57
|
+
/** A menu for a row, opened by a right click, a long press, the Menu key or Shift+F10 on it. Offer nothing here that is not also on the page. */
|
|
58
|
+
rowMenu?(row: Row): MenuItem[];
|
|
59
|
+
/** A word put on the row as `data-state`, for the host's own styling: "off". */
|
|
60
|
+
rowState?(row: Row): string | undefined;
|
|
61
|
+
/** The rows are being fetched: the table is marked busy and keeps what it shows. */
|
|
62
|
+
loading?: boolean;
|
|
63
|
+
/** Shown in place of rows when there are none. */
|
|
64
|
+
empty?: ReactNode;
|
|
65
|
+
className?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The rows an app holds, as a table: people, invitations, jobs. Headings ask the host to sort; check boxes say which
|
|
69
|
+
* rows are chosen; each row can carry its everyday actions and a menu. It sorts, filters and pages nothing itself:
|
|
70
|
+
* the host asks its own server and hands over one page. For the rows of a query use `DataGrid`, which asks the engine.
|
|
71
|
+
*/
|
|
72
|
+
export declare function DataTable<Row>(props: DataTableProps<Row>): import("react").JSX.Element;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { CONTROLS_HOST, ItemControls } from "../controls/ItemControls.js";
|
|
4
|
+
import { label as text } from "../locale/locale.js";
|
|
5
|
+
import { useContextMenu } from "../menu/ContextMenu.js";
|
|
6
|
+
const cellText = (value) => (value === null || value === undefined ? "" : String(value));
|
|
7
|
+
/**
|
|
8
|
+
* The rows an app holds, as a table: people, invitations, jobs. Headings ask the host to sort; check boxes say which
|
|
9
|
+
* rows are chosen; each row can carry its everyday actions and a menu. It sorts, filters and pages nothing itself:
|
|
10
|
+
* the host asks its own server and hands over one page. For the rows of a query use `DataGrid`, which asks the engine.
|
|
11
|
+
*/
|
|
12
|
+
export function DataTable(props) {
|
|
13
|
+
const { label, columns, rows, rowKey, sort, onSortChange, selected, onSelectedChange, selectable, allSelected, rowControls, rowMenu, rowState, loading, empty, className } = props;
|
|
14
|
+
const controlsShow = props.controlsShow ?? "always";
|
|
15
|
+
const header = props.rowHeader ?? columns[0]?.id;
|
|
16
|
+
const nameOf = (row) => props.rowName?.(row) ?? cellText(row[columns[0]?.id ?? ""]);
|
|
17
|
+
const menu = useContextMenu();
|
|
18
|
+
const selecting = selected !== undefined && onSelectedChange !== undefined;
|
|
19
|
+
const choosable = selecting ? rows.filter((row) => selectable?.(row) ?? true) : [];
|
|
20
|
+
const ticked = (row) => allSelected || (selected?.has(rowKey(row)) ?? false);
|
|
21
|
+
const tickedOnPage = choosable.filter(ticked).length;
|
|
22
|
+
const pageAll = choosable.length > 0 && tickedOnPage === choosable.length;
|
|
23
|
+
const pageSome = tickedOnPage > 0 && !pageAll;
|
|
24
|
+
const headBox = useRef(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (headBox.current)
|
|
27
|
+
headBox.current.indeterminate = pageSome;
|
|
28
|
+
}, [pageSome]);
|
|
29
|
+
const tickPage = (on) => {
|
|
30
|
+
if (!onSelectedChange)
|
|
31
|
+
return;
|
|
32
|
+
const next = new Set(allSelected ? [] : selected);
|
|
33
|
+
for (const row of choosable) {
|
|
34
|
+
if (on)
|
|
35
|
+
next.add(rowKey(row));
|
|
36
|
+
else
|
|
37
|
+
next.delete(rowKey(row));
|
|
38
|
+
}
|
|
39
|
+
onSelectedChange(next);
|
|
40
|
+
};
|
|
41
|
+
const tickRow = (row, on) => {
|
|
42
|
+
if (!onSelectedChange)
|
|
43
|
+
return;
|
|
44
|
+
// Leaving "all that match" for row by row: what was ticked on this page stays ticked.
|
|
45
|
+
const next = new Set(allSelected ? choosable.map(rowKey) : selected);
|
|
46
|
+
if (on)
|
|
47
|
+
next.add(rowKey(row));
|
|
48
|
+
else
|
|
49
|
+
next.delete(rowKey(row));
|
|
50
|
+
onSelectedChange(next);
|
|
51
|
+
};
|
|
52
|
+
const sortBy = (column) => onSortChange?.({ column, desc: sort?.column === column ? !sort.desc : false });
|
|
53
|
+
const span = columns.length + (selecting ? 1 : 0) + (rowControls ? 1 : 0);
|
|
54
|
+
return (_jsxs("div", { className: ["sf-data-table", className].filter(Boolean).join(" "), children: [_jsx("div", { className: "sf-data-table-scroll", children: _jsxs("table", { "aria-label": label, "aria-busy": loading || undefined, children: [_jsx("thead", { children: _jsxs("tr", { children: [selecting && (_jsx("th", { scope: "col", className: "sf-data-table-check", children: choosable.length > 0 ? (_jsx("input", { ref: headBox, type: "checkbox", "aria-label": text("table.selectPage"), checked: pageAll, onChange: (event) => tickPage(event.target.checked) })) : (_jsx("span", { className: "sf-visually-hidden", children: text("table.select") })) })), columns.map((column) => {
|
|
55
|
+
const sorted = sort?.column === column.id;
|
|
56
|
+
return (_jsx("th", { scope: "col", "data-align": column.align, "data-show": column.show && column.show !== "always" ? column.show : undefined, "aria-sort": sorted ? (sort.desc ? "descending" : "ascending") : undefined, children: column.sortable && onSortChange ? (_jsxs("button", { type: "button", className: "sf-data-table-sort", "data-sorted": sorted ? (sort.desc ? "desc" : "asc") : undefined, onClick: () => sortBy(column.id), children: [column.label, _jsx("span", { className: "sf-data-table-arrow", "aria-hidden": "true", children: sorted ? (sort.desc ? "↓" : "↑") : "↕" })] })) : (column.label) }, column.id));
|
|
57
|
+
}), rowControls && (_jsx("th", { scope: "col", className: "sf-data-table-actions", children: _jsx("span", { className: "sf-visually-hidden", children: text("table.actions") }) }))] }) }), _jsxs("tbody", { children: [rows.length === 0 && (_jsx("tr", { className: "sf-data-table-empty", children: _jsx("td", { colSpan: span, children: loading ? text("table.loading") : (empty ?? text("table.empty")) }) })), rows.map((row) => {
|
|
58
|
+
const key = rowKey(row);
|
|
59
|
+
const name = nameOf(row);
|
|
60
|
+
const canTick = selecting && (selectable?.(row) ?? true);
|
|
61
|
+
const onContextMenu = rowMenu ? (event) => menu.open(event, name, rowMenu(row)) : undefined;
|
|
62
|
+
return (_jsxs("tr", { className: rowControls && controlsShow === "hover" ? CONTROLS_HOST : undefined, "data-state": rowState?.(row), "data-selected": (canTick && ticked(row)) || undefined, onContextMenu: onContextMenu, children: [selecting && (_jsx("td", { className: "sf-data-table-check", children: canTick && _jsx("input", { type: "checkbox", "aria-label": text("table.selectRow", { name }), checked: ticked(row), onChange: (event) => tickRow(row, event.target.checked) }) })), columns.map((column) => {
|
|
63
|
+
const Cell = column.id === header ? "th" : "td";
|
|
64
|
+
return (_jsx(Cell, { scope: Cell === "th" ? "row" : undefined, "data-align": column.align, "data-show": column.show && column.show !== "always" ? column.show : undefined, children: column.cell ? column.cell(row) : cellText(row[column.id]) }, column.id));
|
|
65
|
+
}), rowControls && (_jsx("td", { className: "sf-data-table-actions", children: _jsx(ItemControls, { label: text("table.rowControls", { name }), controls: rowControls(row), show: controlsShow, quietable: false }) }))] }, key));
|
|
66
|
+
})] })] }) }), menu.element] }));
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=DataTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataTable.js","sourceRoot":"","sources":["../../src/table/DataTable.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAmC,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAoB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAiB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAoEvE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE1G;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAM,KAA0B;IACvD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACnL,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,IAAI,QAAQ,CAAC;IACpD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACjD,MAAM,MAAM,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAE,GAA+B,CAAC,OAAO,CAAC,CAAC,CAAC,EAA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S,EAAC,uBAAuB,YACnC,KAAC,YAAY,IAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,GAAI,GAC3H,CACN,KAvBI,GAAG,CAwBL,CACN,CAAC;gCACJ,CAAC,CAAC,IACI,IACF,GACJ,EACL,IAAI,CAAC,OAAO,IACT,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { type MouseEvent, type ReactNode, useEffect, useRef } from \"react\";\nimport { CONTROLS_HOST, type ItemControl, ItemControls } from \"../controls/ItemControls.js\";\nimport { label as text } from \"../locale/locale.js\";\nimport { type MenuItem, useContextMenu } from \"../menu/ContextMenu.js\";\n\n/** Which way a `DataTable` is sorted: a column's id, and whether largest or latest comes first. */\nexport interface DataTableSort {\n column: string;\n desc: boolean;\n}\n\n/** One column of a `DataTable`. */\nexport interface DataTableColumn<Row> {\n /** Tells columns apart, and names the sort the table reports. */\n id: string;\n /** The heading. */\n label: string;\n /** Draws the cell. Without it the cell is the row's value under `id`, as text. */\n cell?(row: Row): ReactNode;\n /** Whether a press on the heading asks the host to sort by this column. The table never sorts rows itself. */\n sortable?: boolean;\n /** \"end\" for numbers, so their digits line up. */\n align?: \"start\" | \"end\";\n /**\n * When the column is shown. \"always\" (the default) at every width; \"medium\" from 36rem of the table's own width;\n * \"wide\" from 52rem. Keep the column that names a row, and anything a person must see to act, at \"always\".\n */\n show?: \"always\" | \"medium\" | \"wide\";\n}\n\nexport interface DataTableProps<Row> {\n /** What the rows are, for assistive technology: \"People\". */\n label: string;\n columns: readonly DataTableColumn<Row>[];\n /** The rows to show, already sorted, filtered and paged by the host. The table shows them in the order given. */\n rows: readonly Row[];\n /** A value that tells rows apart and stays the same when the rows change: an id. */\n rowKey(row: Row): string;\n /** The row's name, for its check box and its controls: \"Ana Admin\". Defaults to the first column's text. */\n rowName?(row: Row): string;\n /** The column that names each row, drawn as the row's header. Defaults to the first. */\n rowHeader?: string;\n /** How the host has sorted `rows`. */\n sort?: DataTableSort;\n /** Asked for when a sortable heading is pressed: the column, ascending first, then the other way. */\n onSortChange?(sort: DataTableSort): void;\n /** The keys of the rows ticked. Giving it, with `onSelectedChange`, adds a check box to each row and the heading. */\n selected?: ReadonlySet<string>;\n onSelectedChange?(selected: Set<string>): void;\n /** Whether a row can be ticked. One that cannot shows no check box: the person's own account, say. */\n selectable?(row: Row): boolean;\n /**\n * Every row that matches is selected, past this page too (see `SelectionBar`). Each box is shown ticked; changing\n * any box reports the rows on this page as ticked or not, so the host goes back to choosing row by row.\n */\n allSelected?: boolean;\n /** The actions on one row, drawn with `ItemControls`: the everyday ones only, with the rest a press further on. */\n rowControls?(row: Row): ItemControl[];\n /** \"hover\" shows a row's controls when it is pointed at or has focus (always on touch); \"always\" (the default) keeps them shown. */\n controlsShow?: \"hover\" | \"always\";\n /** A menu for a row, opened by a right click, a long press, the Menu key or Shift+F10 on it. Offer nothing here that is not also on the page. */\n rowMenu?(row: Row): MenuItem[];\n /** A word put on the row as `data-state`, for the host's own styling: \"off\". */\n rowState?(row: Row): string | undefined;\n /** The rows are being fetched: the table is marked busy and keeps what it shows. */\n loading?: boolean;\n /** Shown in place of rows when there are none. */\n empty?: ReactNode;\n className?: string;\n}\n\nconst cellText = (value: unknown): string => (value === null || value === undefined ? \"\" : String(value));\n\n/**\n * The rows an app holds, as a table: people, invitations, jobs. Headings ask the host to sort; check boxes say which\n * rows are chosen; each row can carry its everyday actions and a menu. It sorts, filters and pages nothing itself:\n * the host asks its own server and hands over one page. For the rows of a query use `DataGrid`, which asks the engine.\n */\nexport function DataTable<Row>(props: DataTableProps<Row>) {\n const { label, columns, rows, rowKey, sort, onSortChange, selected, onSelectedChange, selectable, allSelected, rowControls, rowMenu, rowState, loading, empty, className } = props;\n const controlsShow = props.controlsShow ?? \"always\";\n const header = props.rowHeader ?? columns[0]?.id;\n const nameOf = (row: Row) => props.rowName?.(row) ?? cellText((row as Record<string, unknown>)[columns[0]?.id ?? \"\"]);\n const menu = useContextMenu();\n const selecting = selected !== undefined && onSelectedChange !== undefined;\n const choosable = selecting ? rows.filter((row) => selectable?.(row) ?? true) : [];\n const ticked = (row: Row) => allSelected || (selected?.has(rowKey(row)) ?? false);\n const tickedOnPage = choosable.filter(ticked).length;\n const pageAll = choosable.length > 0 && tickedOnPage === choosable.length;\n const pageSome = tickedOnPage > 0 && !pageAll;\n const headBox = useRef<HTMLInputElement>(null);\n useEffect(() => {\n if (headBox.current) headBox.current.indeterminate = pageSome;\n }, [pageSome]);\n\n const tickPage = (on: boolean) => {\n if (!onSelectedChange) return;\n const next = new Set(allSelected ? [] : selected);\n for (const row of choosable) {\n if (on) next.add(rowKey(row));\n else next.delete(rowKey(row));\n }\n onSelectedChange(next);\n };\n const tickRow = (row: Row, on: boolean) => {\n if (!onSelectedChange) return;\n // Leaving \"all that match\" for row by row: what was ticked on this page stays ticked.\n const next = new Set(allSelected ? choosable.map(rowKey) : selected);\n if (on) next.add(rowKey(row));\n else next.delete(rowKey(row));\n onSelectedChange(next);\n };\n const sortBy = (column: string) => onSortChange?.({ column, desc: sort?.column === column ? !sort.desc : false });\n const span = columns.length + (selecting ? 1 : 0) + (rowControls ? 1 : 0);\n\n return (\n <div className={[\"sf-data-table\", className].filter(Boolean).join(\" \")}>\n <div className=\"sf-data-table-scroll\">\n <table aria-label={label} aria-busy={loading || undefined}>\n <thead>\n <tr>\n {selecting && (\n <th scope=\"col\" className=\"sf-data-table-check\">\n {choosable.length > 0 ? (\n <input ref={headBox} type=\"checkbox\" aria-label={text(\"table.selectPage\")} checked={pageAll} onChange={(event) => tickPage(event.target.checked)} />\n ) : (\n <span className=\"sf-visually-hidden\">{text(\"table.select\")}</span>\n )}\n </th>\n )}\n {columns.map((column) => {\n const sorted = sort?.column === column.id;\n return (\n <th\n key={column.id}\n scope=\"col\"\n data-align={column.align}\n data-show={column.show && column.show !== \"always\" ? column.show : undefined}\n aria-sort={sorted ? (sort.desc ? \"descending\" : \"ascending\") : undefined}\n >\n {column.sortable && onSortChange ? (\n <button type=\"button\" className=\"sf-data-table-sort\" data-sorted={sorted ? (sort.desc ? \"desc\" : \"asc\") : undefined} onClick={() => sortBy(column.id)}>\n {column.label}\n <span className=\"sf-data-table-arrow\" aria-hidden=\"true\">\n {sorted ? (sort.desc ? \"↓\" : \"↑\") : \"↕\"}\n </span>\n </button>\n ) : (\n column.label\n )}\n </th>\n );\n })}\n {rowControls && (\n <th scope=\"col\" className=\"sf-data-table-actions\">\n <span className=\"sf-visually-hidden\">{text(\"table.actions\")}</span>\n </th>\n )}\n </tr>\n </thead>\n <tbody>\n {rows.length === 0 && (\n <tr className=\"sf-data-table-empty\">\n <td colSpan={span}>{loading ? text(\"table.loading\") : (empty ?? text(\"table.empty\"))}</td>\n </tr>\n )}\n {rows.map((row) => {\n const key = rowKey(row);\n const name = nameOf(row);\n const canTick = selecting && (selectable?.(row) ?? true);\n const onContextMenu = rowMenu ? (event: MouseEvent<HTMLElement>) => menu.open(event, name, rowMenu(row)) : undefined;\n return (\n <tr\n key={key}\n className={rowControls && controlsShow === \"hover\" ? CONTROLS_HOST : undefined}\n data-state={rowState?.(row)}\n data-selected={(canTick && ticked(row)) || undefined}\n onContextMenu={onContextMenu}\n >\n {selecting && (\n <td className=\"sf-data-table-check\">\n {canTick && <input type=\"checkbox\" aria-label={text(\"table.selectRow\", { name })} checked={ticked(row)} onChange={(event) => tickRow(row, event.target.checked)} />}\n </td>\n )}\n {columns.map((column) => {\n const Cell = column.id === header ? \"th\" : \"td\";\n return (\n <Cell key={column.id} scope={Cell === \"th\" ? \"row\" : undefined} data-align={column.align} data-show={column.show && column.show !== \"always\" ? column.show : undefined}>\n {column.cell ? column.cell(row) : cellText((row as Record<string, unknown>)[column.id])}\n </Cell>\n );\n })}\n {rowControls && (\n <td className=\"sf-data-table-actions\">\n <ItemControls label={text(\"table.rowControls\", { name })} controls={rowControls(row)} show={controlsShow} quietable={false} />\n </td>\n )}\n </tr>\n );\n })}\n </tbody>\n </table>\n </div>\n {menu.element}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface PaginationProps {
|
|
2
|
+
/** Where this page starts, counting from 0. */
|
|
3
|
+
offset: number;
|
|
4
|
+
/** How many rows a page holds. */
|
|
5
|
+
pageSize: number;
|
|
6
|
+
/** How many rows there are in all. */
|
|
7
|
+
total: number;
|
|
8
|
+
/** Asked for with the offset of the page a person moves to. The host fetches it. */
|
|
9
|
+
onChange(offset: number): void;
|
|
10
|
+
/** Names the navigation for assistive technology. Defaults to "Pages". */
|
|
11
|
+
label?: string;
|
|
12
|
+
/** A page is being fetched: Previous and Next wait. */
|
|
13
|
+
busy?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Which rows are shown, "51–100 of 126", with Previous and Next. For a list a host pages on its server; it holds no
|
|
18
|
+
* page of its own. Nothing is drawn when every row fits on one page.
|
|
19
|
+
*/
|
|
20
|
+
export declare function Pagination({ offset, pageSize, total, onChange, label, busy, className }: PaginationProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { numberFormat, label as text } from "../locale/locale.js";
|
|
3
|
+
/**
|
|
4
|
+
* Which rows are shown, "51–100 of 126", with Previous and Next. For a list a host pages on its server; it holds no
|
|
5
|
+
* page of its own. Nothing is drawn when every row fits on one page.
|
|
6
|
+
*/
|
|
7
|
+
export function Pagination({ offset, pageSize, total, onChange, label, busy, className }) {
|
|
8
|
+
if (total <= pageSize && offset === 0)
|
|
9
|
+
return null;
|
|
10
|
+
const size = Math.max(1, Math.trunc(pageSize));
|
|
11
|
+
const number = (n) => numberFormat().format(n);
|
|
12
|
+
const from = total === 0 ? 0 : Math.min(offset + 1, total);
|
|
13
|
+
const to = Math.min(offset + size, total);
|
|
14
|
+
return (_jsxs("nav", { className: ["sf-pagination", className].filter(Boolean).join(" "), "aria-label": label ?? text("pages.label"), children: [_jsx("span", { className: "sf-pagination-range", "aria-live": "polite", children: text("pages.range", { from: number(from), to: number(to), total: number(total) }) }), _jsx("button", { type: "button", className: "sf-button", disabled: busy || offset <= 0, onClick: () => onChange(Math.max(0, offset - size)), children: text("pages.previous") }), _jsx("button", { type: "button", className: "sf-button", disabled: busy || offset + size >= total, onClick: () => onChange(offset + size), children: text("pages.next") })] }));
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=Pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pagination.js","sourceRoot":"","sources":["../../src/table/Pagination.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAkBlE;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAmB;IACvG,IAAI,KAAK,IAAI,QAAQ,IAAI,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3D,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,OAAO,CACL,eAAK,SAAS,EAAE,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,gBAAc,KAAK,IAAI,IAAI,CAAC,aAAa,CAAC,aAC9G,eAAM,SAAS,EAAC,qBAAqB,eAAW,QAAQ,YACrD,IAAI,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,GAC7E,EACP,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,WAAW,EAAC,QAAQ,EAAE,IAAI,IAAI,MAAM,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,YAC3H,IAAI,CAAC,gBAAgB,CAAC,GAChB,EACT,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,WAAW,EAAC,QAAQ,EAAE,IAAI,IAAI,MAAM,GAAG,IAAI,IAAI,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,YACzH,IAAI,CAAC,YAAY,CAAC,GACZ,IACL,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { numberFormat, label as text } from \"../locale/locale.js\";\n\nexport interface PaginationProps {\n /** Where this page starts, counting from 0. */\n offset: number;\n /** How many rows a page holds. */\n pageSize: number;\n /** How many rows there are in all. */\n total: number;\n /** Asked for with the offset of the page a person moves to. The host fetches it. */\n onChange(offset: number): void;\n /** Names the navigation for assistive technology. Defaults to \"Pages\". */\n label?: string;\n /** A page is being fetched: Previous and Next wait. */\n busy?: boolean;\n className?: string;\n}\n\n/**\n * Which rows are shown, \"51–100 of 126\", with Previous and Next. For a list a host pages on its server; it holds no\n * page of its own. Nothing is drawn when every row fits on one page.\n */\nexport function Pagination({ offset, pageSize, total, onChange, label, busy, className }: PaginationProps) {\n if (total <= pageSize && offset === 0) return null;\n const size = Math.max(1, Math.trunc(pageSize));\n const number = (n: number) => numberFormat().format(n);\n const from = total === 0 ? 0 : Math.min(offset + 1, total);\n const to = Math.min(offset + size, total);\n return (\n <nav className={[\"sf-pagination\", className].filter(Boolean).join(\" \")} aria-label={label ?? text(\"pages.label\")}>\n <span className=\"sf-pagination-range\" aria-live=\"polite\">\n {text(\"pages.range\", { from: number(from), to: number(to), total: number(total) })}\n </span>\n <button type=\"button\" className=\"sf-button\" disabled={busy || offset <= 0} onClick={() => onChange(Math.max(0, offset - size))}>\n {text(\"pages.previous\")}\n </button>\n <button type=\"button\" className=\"sf-button\" disabled={busy || offset + size >= total} onClick={() => onChange(offset + size)}>\n {text(\"pages.next\")}\n </button>\n </nav>\n );\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/** One thing a `SelectionBar` can do to the rows chosen. */
|
|
3
|
+
export interface SelectionAction {
|
|
4
|
+
/** Tells actions apart; put on the button as `data-action`. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The button's words: "Turn off", "Make admins". */
|
|
7
|
+
label: string;
|
|
8
|
+
onSelect(): void;
|
|
9
|
+
/** For an action that takes something away. Marked by more than colour: it comes last, after a gap. */
|
|
10
|
+
danger?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** For an action that opens more below the bar (a form): whether it is open now. */
|
|
13
|
+
expanded?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface SelectionBarProps {
|
|
16
|
+
/** How many rows are chosen: those ticked, or every row that matches when `allMatching`. Nothing is drawn at 0. */
|
|
17
|
+
count: number;
|
|
18
|
+
actions: readonly SelectionAction[];
|
|
19
|
+
/** Untick everything. */
|
|
20
|
+
onClear(): void;
|
|
21
|
+
/** Names the bar for assistive technology. Defaults to "With the selected rows". */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** Every row on this page is ticked: the bar offers to choose every row that matches, past this page. */
|
|
24
|
+
pageSelected?: boolean;
|
|
25
|
+
/** How many rows match the search and filters in all, across every page. */
|
|
26
|
+
total?: number;
|
|
27
|
+
/** Every row that matches is chosen, not only those ticked. */
|
|
28
|
+
allMatching?: boolean;
|
|
29
|
+
/** Asked for when a person chooses every row that matches, or goes back to this page only. Without it, nothing is offered past the page. */
|
|
30
|
+
onAllMatchingChange?(all: boolean): void;
|
|
31
|
+
/** An action is running: every button waits. */
|
|
32
|
+
busy?: boolean;
|
|
33
|
+
/** Drawn under the actions: a form an action opened, such as who to hand the rows to. */
|
|
34
|
+
children?: ReactNode;
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What to do with the rows a person chose in a `DataTable`: how many, the actions, and Clear. When the whole page is
|
|
39
|
+
* ticked and more rows match, it offers to take every one that matches, so an action can reach rows on pages never
|
|
40
|
+
* opened; the host then acts on the search and filters, not on a list of keys. It runs nothing itself: each action
|
|
41
|
+
* calls back, and the host asks first for anything hard to undo (`useConfirm`).
|
|
42
|
+
*/
|
|
43
|
+
export declare function SelectionBar(props: SelectionBarProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { numberFormat, label as text } from "../locale/locale.js";
|
|
3
|
+
/**
|
|
4
|
+
* What to do with the rows a person chose in a `DataTable`: how many, the actions, and Clear. When the whole page is
|
|
5
|
+
* ticked and more rows match, it offers to take every one that matches, so an action can reach rows on pages never
|
|
6
|
+
* opened; the host then acts on the search and filters, not on a list of keys. It runs nothing itself: each action
|
|
7
|
+
* calls back, and the host asks first for anything hard to undo (`useConfirm`).
|
|
8
|
+
*/
|
|
9
|
+
export function SelectionBar(props) {
|
|
10
|
+
const { count, actions, onClear, pageSelected, total, allMatching, onAllMatchingChange, busy, children, className } = props;
|
|
11
|
+
if (count <= 0)
|
|
12
|
+
return null;
|
|
13
|
+
const number = (n) => numberFormat().format(n);
|
|
14
|
+
const more = onAllMatchingChange !== undefined && total !== undefined && total > count;
|
|
15
|
+
const ordered = [...actions.filter((a) => !a.danger), ...actions.filter((a) => a.danger)];
|
|
16
|
+
return (_jsxs("div", { className: ["sf-selection-bar", className].filter(Boolean).join(" "), role: "group", "aria-label": props.label ?? text("selection.label"), children: [_jsxs("div", { className: "sf-selection-bar-row", children: [_jsx("strong", { className: "sf-selection-bar-count", "aria-live": "polite", children: text("selection.count", { count: number(count) }) }), _jsx("div", { className: "sf-selection-bar-actions", children: ordered.map((action) => (_jsx("button", { type: "button", className: "sf-button", "data-action": action.id, "data-variant": action.danger ? "danger" : undefined, "aria-expanded": action.expanded, disabled: busy || action.disabled, onClick: action.onSelect, children: action.label }, action.id))) }), _jsx("button", { type: "button", className: "sf-selection-bar-link", disabled: busy, onClick: onClear, children: text("selection.clear") })] }), allMatching && onAllMatchingChange && total !== undefined ? (_jsxs("p", { className: "sf-selection-bar-all", children: [text("selection.allMatching", { total: number(total) }), " ", _jsx("button", { type: "button", className: "sf-selection-bar-link", disabled: busy, onClick: () => onAllMatchingChange(false), children: text("selection.onlyPage") })] })) : pageSelected && more ? (_jsxs("p", { className: "sf-selection-bar-all", children: [text("selection.pageSelected", { count: number(count) }), " ", _jsx("button", { type: "button", className: "sf-selection-bar-link", disabled: busy, onClick: () => onAllMatchingChange(true), children: text("selection.selectAllMatching", { total: number(total) }) })] })) : null, children && _jsx("div", { className: "sf-selection-bar-more", children: children })] }));
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=SelectionBar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionBar.js","sourceRoot":"","sources":["../../src/table/SelectionBar.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,KAAK,I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,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,GACvD,IACP,CACL,CAAC,CAAC,CAAC,IAAI,EACP,QAAQ,IAAI,cAAK,SAAS,EAAC,uBAAuB,YAAE,QAAQ,GAAO,IAChE,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { numberFormat, label as text } from \"../locale/locale.js\";\n\n/** One thing a `SelectionBar` can do to the rows chosen. */\nexport interface SelectionAction {\n /** Tells actions apart; put on the button as `data-action`. */\n id: string;\n /** The button's words: \"Turn off\", \"Make admins\". */\n label: string;\n onSelect(): void;\n /** For an action that takes something away. Marked by more than colour: it comes last, after a gap. */\n danger?: boolean;\n disabled?: boolean;\n /** For an action that opens more below the bar (a form): whether it is open now. */\n expanded?: boolean;\n}\n\nexport interface SelectionBarProps {\n /** How many rows are chosen: those ticked, or every row that matches when `allMatching`. Nothing is drawn at 0. */\n count: number;\n actions: readonly SelectionAction[];\n /** Untick everything. */\n onClear(): void;\n /** Names the bar for assistive technology. Defaults to \"With the selected rows\". */\n label?: string;\n /** Every row on this page is ticked: the bar offers to choose every row that matches, past this page. */\n pageSelected?: boolean;\n /** How many rows match the search and filters in all, across every page. */\n total?: number;\n /** Every row that matches is chosen, not only those ticked. */\n allMatching?: boolean;\n /** Asked for when a person chooses every row that matches, or goes back to this page only. Without it, nothing is offered past the page. */\n onAllMatchingChange?(all: boolean): void;\n /** An action is running: every button waits. */\n busy?: boolean;\n /** Drawn under the actions: a form an action opened, such as who to hand the rows to. */\n children?: ReactNode;\n className?: string;\n}\n\n/**\n * What to do with the rows a person chose in a `DataTable`: how many, the actions, and Clear. When the whole page is\n * ticked and more rows match, it offers to take every one that matches, so an action can reach rows on pages never\n * opened; the host then acts on the search and filters, not on a list of keys. It runs nothing itself: each action\n * calls back, and the host asks first for anything hard to undo (`useConfirm`).\n */\nexport function SelectionBar(props: SelectionBarProps) {\n const { count, actions, onClear, pageSelected, total, allMatching, onAllMatchingChange, busy, children, className } = props;\n if (count <= 0) return null;\n const number = (n: number) => numberFormat().format(n);\n const more = onAllMatchingChange !== undefined && total !== undefined && total > count;\n const ordered = [...actions.filter((a) => !a.danger), ...actions.filter((a) => a.danger)];\n return (\n <div className={[\"sf-selection-bar\", className].filter(Boolean).join(\" \")} role=\"group\" aria-label={props.label ?? text(\"selection.label\")}>\n <div className=\"sf-selection-bar-row\">\n <strong className=\"sf-selection-bar-count\" aria-live=\"polite\">\n {text(\"selection.count\", { count: number(count) })}\n </strong>\n <div className=\"sf-selection-bar-actions\">\n {ordered.map((action) => (\n <button\n key={action.id}\n type=\"button\"\n className=\"sf-button\"\n data-action={action.id}\n data-variant={action.danger ? \"danger\" : undefined}\n aria-expanded={action.expanded}\n disabled={busy || action.disabled}\n onClick={action.onSelect}\n >\n {action.label}\n </button>\n ))}\n </div>\n <button type=\"button\" className=\"sf-selection-bar-link\" disabled={busy} onClick={onClear}>\n {text(\"selection.clear\")}\n </button>\n </div>\n {allMatching && onAllMatchingChange && total !== undefined ? (\n <p className=\"sf-selection-bar-all\">\n {text(\"selection.allMatching\", { total: number(total) })}{\" \"}\n <button type=\"button\" className=\"sf-selection-bar-link\" disabled={busy} onClick={() => onAllMatchingChange(false)}>\n {text(\"selection.onlyPage\")}\n </button>\n </p>\n ) : pageSelected && more ? (\n <p className=\"sf-selection-bar-all\">\n {text(\"selection.pageSelected\", { count: number(count) })}{\" \"}\n <button type=\"button\" className=\"sf-selection-bar-link\" disabled={busy} onClick={() => onAllMatchingChange(true)}>\n {text(\"selection.selectAllMatching\", { total: number(total) })}\n </button>\n </p>\n ) : null}\n {children && <div className=\"sf-selection-bar-more\">{children}</div>}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
type Block = {
|
|
2
|
+
kind: "heading";
|
|
3
|
+
level: number;
|
|
4
|
+
text: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "paragraph";
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "code";
|
|
10
|
+
language: string;
|
|
11
|
+
code: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "list";
|
|
14
|
+
ordered: boolean;
|
|
15
|
+
items: string[];
|
|
16
|
+
start?: number;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "quote";
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "table";
|
|
22
|
+
head: string[];
|
|
23
|
+
rows: string[][];
|
|
24
|
+
} | {
|
|
25
|
+
kind: "rule";
|
|
26
|
+
};
|
|
27
|
+
/** Splits Markdown into blocks. Text still arriving (an unclosed code fence, a half table) is handled. */
|
|
28
|
+
export declare function parseMarkdown(source: string): Block[];
|
|
29
|
+
export interface CodeBlockProps {
|
|
30
|
+
code: string;
|
|
31
|
+
/** Shown as a label, e.g. "sql". */
|
|
32
|
+
language?: string;
|
|
33
|
+
/** Shows a Run button for SQL and is called with the code. Nothing runs unless a person presses it. */
|
|
34
|
+
onRun?(code: string): void;
|
|
35
|
+
/** Accessible name for the block; defaults to the language. */
|
|
36
|
+
label?: string;
|
|
37
|
+
/** Hide the bar with the language and the Copy button, for code shown as part of a larger view. */
|
|
38
|
+
bare?: boolean;
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Code as coloured tokens. Colours come from `--sf-code-*`, so they follow the theme. */
|
|
42
|
+
export declare function HighlightedCode({ code, language }: {
|
|
43
|
+
code: string;
|
|
44
|
+
language?: string;
|
|
45
|
+
}): import("react").JSX.Element;
|
|
46
|
+
/** A block of code with a copy button. */
|
|
47
|
+
export declare function CodeBlock({ code, language, onRun, label, bare, className }: CodeBlockProps): import("react").JSX.Element;
|
|
48
|
+
export interface MarkdownProps {
|
|
49
|
+
/** Markdown text. May be incomplete while it streams in. */
|
|
50
|
+
text: string;
|
|
51
|
+
/** Called when a person presses Run on a SQL code block. Omit to show no Run button. */
|
|
52
|
+
onRunSql?(sql: string): void;
|
|
53
|
+
/** Render one line of inline Markdown (code, emphasis, links) in a span, for labels and descriptions. */
|
|
54
|
+
inline?: boolean;
|
|
55
|
+
/** The heading level a `#` becomes. Defaults to 3, so a reply never outranks the page's own headings. */
|
|
56
|
+
headingStart?: number;
|
|
57
|
+
/** Turns a link the text gives (such as a relative path) into a full http(s) address, or undefined to leave it as text. */
|
|
58
|
+
resolveLink?(href: string): string | undefined;
|
|
59
|
+
/** Turns an image the text gives (``) into a full http(s) address. Without it, or when it returns undefined, the image's description is shown instead. */
|
|
60
|
+
resolveImage?(src: string): string | undefined;
|
|
61
|
+
/** Called on a plain click on a link, with its full address; return true to handle it in the app, so it does not open a new tab. */
|
|
62
|
+
openLink?(href: string): boolean;
|
|
63
|
+
className?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Renders Markdown as React elements: headings, paragraphs, lists, quotes,
|
|
67
|
+
* tables, code blocks, and inline code, emphasis and links. The text is never
|
|
68
|
+
* inserted as HTML, so model output cannot add markup or scripts.
|
|
69
|
+
*/
|
|
70
|
+
export declare function Markdown({ text, onRunSql, inline: oneLine, headingStart, resolveLink, resolveImage, openLink, className }: MarkdownProps): import("react").JSX.Element;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useMemo, useState } from "react";
|
|
3
|
+
import { highlight } from "./highlight.js";
|
|
4
|
+
/** Only http(s) and mailto links are rendered as links; anything else stays text. */
|
|
5
|
+
function safeHref(value) {
|
|
6
|
+
try {
|
|
7
|
+
const url = new URL(value);
|
|
8
|
+
return url.protocol === "https:" || url.protocol === "http:" || url.protocol === "mailto:" ? url.href : undefined;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const INLINE = /(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\n]+\*|_[^_\n]+_)|(!\[[^\]\n]*\]\([^)\s]+\)|\[[^\]\n]+\]\([^)\s]+\))/g;
|
|
15
|
+
/** Inline Markdown as React nodes: code, bold, italic and links. Never produces HTML from the text. */
|
|
16
|
+
function inline(text, links = {}) {
|
|
17
|
+
const out = [];
|
|
18
|
+
let last = 0;
|
|
19
|
+
let key = 0;
|
|
20
|
+
for (const match of text.matchAll(INLINE)) {
|
|
21
|
+
if (match.index > last)
|
|
22
|
+
out.push(text.slice(last, match.index));
|
|
23
|
+
const token = match[0];
|
|
24
|
+
if (match[1])
|
|
25
|
+
out.push(_jsx("code", { children: token.slice(1, -1) }, key++));
|
|
26
|
+
else if (match[2])
|
|
27
|
+
out.push(_jsx("strong", { children: inline(token.slice(2, -2), links) }, key++));
|
|
28
|
+
else if (match[3])
|
|
29
|
+
out.push(_jsx("em", { children: inline(token.slice(1, -1), links) }, key++));
|
|
30
|
+
else if (token.startsWith("!")) {
|
|
31
|
+
// An image is drawn only when the host gives its address (`resolveImage`); otherwise its description stands in,
|
|
32
|
+
// so text from a model cannot load an image from anywhere it likes.
|
|
33
|
+
const split = token.indexOf("](");
|
|
34
|
+
const alt = token.slice(2, split);
|
|
35
|
+
const src = links.image ? safeHref(links.image(token.slice(split + 2, -1)) ?? "") : undefined;
|
|
36
|
+
out.push(src ? _jsx("img", { className: "sf-markdown-image", src: src, alt: alt, loading: "lazy", decoding: "async" }, key++) : alt);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const split = token.indexOf("](");
|
|
40
|
+
const label = token.slice(1, split);
|
|
41
|
+
const target = token.slice(split + 2, -1);
|
|
42
|
+
// A host may turn its own links (a relative docs path, an anchor) into safe ones; the result is checked again.
|
|
43
|
+
const href = safeHref(target) ?? (links.resolve ? safeHref(links.resolve(target) ?? "") : undefined);
|
|
44
|
+
const open = links.open;
|
|
45
|
+
out.push(href ? (_jsx("a", { href: href, target: "_blank", rel: "noreferrer noopener", onClick: open &&
|
|
46
|
+
((event) => {
|
|
47
|
+
// A plain click on a link the host keeps (a page of its own) stays in the app; any modifier opens a tab.
|
|
48
|
+
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
49
|
+
return;
|
|
50
|
+
if (open(href))
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
}), children: inline(label, links) }, key++)) : (label));
|
|
53
|
+
}
|
|
54
|
+
last = match.index + token.length;
|
|
55
|
+
}
|
|
56
|
+
if (last < text.length)
|
|
57
|
+
out.push(text.slice(last));
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
const cells = (line) => line
|
|
61
|
+
.trim()
|
|
62
|
+
.replace(/^\||\|$/g, "")
|
|
63
|
+
.split("|")
|
|
64
|
+
.map((cell) => cell.trim());
|
|
65
|
+
/** Splits Markdown into blocks. Text still arriving (an unclosed code fence, a half table) is handled. */
|
|
66
|
+
export function parseMarkdown(source) {
|
|
67
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
68
|
+
const blocks = [];
|
|
69
|
+
for (let i = 0; i < lines.length;) {
|
|
70
|
+
const line = lines[i];
|
|
71
|
+
const fence = /^\s*```(\S*)\s*$/.exec(line);
|
|
72
|
+
if (fence) {
|
|
73
|
+
const body = [];
|
|
74
|
+
for (i++; i < lines.length && !/^\s*```\s*$/.test(lines[i]); i++)
|
|
75
|
+
body.push(lines[i]);
|
|
76
|
+
i++;
|
|
77
|
+
blocks.push({ kind: "code", language: fence[1] ?? "", code: body.join("\n") });
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (line.trim() === "") {
|
|
81
|
+
i++;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const heading = /^(#{1,6})\s+(.*)$/.exec(line);
|
|
85
|
+
if (heading) {
|
|
86
|
+
blocks.push({ kind: "heading", level: heading[1].length, text: heading[2] });
|
|
87
|
+
i++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (/^\s*([-*_])\s*\1\s*\1[\s\-*_]*$/.test(line)) {
|
|
91
|
+
blocks.push({ kind: "rule" });
|
|
92
|
+
i++;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (line.includes("|") && /^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/.test(lines[i + 1] ?? "")) {
|
|
96
|
+
const head = cells(line);
|
|
97
|
+
const rows = [];
|
|
98
|
+
for (i += 2; i < lines.length && lines[i].includes("|") && lines[i].trim() !== ""; i++)
|
|
99
|
+
rows.push(cells(lines[i]));
|
|
100
|
+
blocks.push({ kind: "table", head, rows });
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const bullet = /^\s*(?:[-*+]|(\d+)[.)])\s+(.*)$/.exec(line);
|
|
104
|
+
if (bullet) {
|
|
105
|
+
const ordered = bullet[1] !== undefined;
|
|
106
|
+
const items = [];
|
|
107
|
+
for (; i < lines.length; i++) {
|
|
108
|
+
const item = /^\s*(?:[-*+]|(\d+)[.)])\s+(.*)$/.exec(lines[i]);
|
|
109
|
+
if (item && (item[1] !== undefined) === ordered)
|
|
110
|
+
items.push(item[2]);
|
|
111
|
+
else if (items.length > 0 && /^\s{2,}\S/.test(lines[i]))
|
|
112
|
+
items[items.length - 1] += ` ${lines[i].trim()}`;
|
|
113
|
+
else
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
// A numbered list broken by a code block carries on from its own number ("2." after the code).
|
|
117
|
+
const start = ordered ? Number(bullet[1]) : undefined;
|
|
118
|
+
blocks.push(start !== undefined && start !== 1 ? { kind: "list", ordered, items, start } : { kind: "list", ordered, items });
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (/^\s*>/.test(line)) {
|
|
122
|
+
const body = [];
|
|
123
|
+
for (; i < lines.length && /^\s*>/.test(lines[i]); i++)
|
|
124
|
+
body.push(lines[i].replace(/^\s*>\s?/, ""));
|
|
125
|
+
blocks.push({ kind: "quote", text: body.join(" ") });
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const body = [];
|
|
129
|
+
for (; i < lines.length && lines[i].trim() !== "" && !/^\s*(```|#{1,6}\s|>|[-*+]\s|\d+[.)]\s)/.test(lines[i]); i++)
|
|
130
|
+
body.push(lines[i].trim());
|
|
131
|
+
if (body.length === 0)
|
|
132
|
+
body.push(lines[i++].trim());
|
|
133
|
+
blocks.push({ kind: "paragraph", text: body.join(" ") });
|
|
134
|
+
}
|
|
135
|
+
return blocks;
|
|
136
|
+
}
|
|
137
|
+
/** Code as coloured tokens. Colours come from `--sf-code-*`, so they follow the theme. */
|
|
138
|
+
export function HighlightedCode({ code, language }) {
|
|
139
|
+
const tokens = useMemo(() => highlight(code, language), [code, language]);
|
|
140
|
+
return (_jsx("code", { "data-language": language || undefined, children: tokens.map((token, i) => token.kind ? (_jsx("span", { className: `sf-tok-${token.kind}`, children: token.text }, i)) : (_jsx(Fragment, { children: token.text }, i))) }));
|
|
141
|
+
}
|
|
142
|
+
/** A block of code with a copy button. */
|
|
143
|
+
export function CodeBlock({ code, language, onRun, label, bare, className }) {
|
|
144
|
+
const [copied, setCopied] = useState(false);
|
|
145
|
+
const copy = () => {
|
|
146
|
+
void navigator.clipboard?.writeText(code).then(() => {
|
|
147
|
+
setCopied(true);
|
|
148
|
+
setTimeout(() => setCopied(false), 1500);
|
|
149
|
+
}, () => { });
|
|
150
|
+
};
|
|
151
|
+
return (_jsxs("div", { className: ["sf-code", bare && "sf-code-bare", className].filter(Boolean).join(" "), children: [!bare && (_jsxs("div", { className: "sf-code-bar", children: [_jsx("span", { children: language || "text" }), _jsxs("span", { className: "sf-code-actions", children: [onRun && (_jsx("button", { type: "button", className: "sf-button", onClick: () => onRun(code), children: "Run" })), _jsx("button", { type: "button", className: "sf-button", onClick: copy, "aria-live": "polite", children: copied ? "Copied" : "Copy" })] })] })), _jsx("pre", { tabIndex: 0, "aria-label": label ?? (language ? `${language} code` : "Code"), children: _jsx(HighlightedCode, { code: code, language: language }) })] }));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Renders Markdown as React elements: headings, paragraphs, lists, quotes,
|
|
155
|
+
* tables, code blocks, and inline code, emphasis and links. The text is never
|
|
156
|
+
* inserted as HTML, so model output cannot add markup or scripts.
|
|
157
|
+
*/
|
|
158
|
+
export function Markdown({ text, onRunSql, inline: oneLine, headingStart = 3, resolveLink, resolveImage, openLink, className }) {
|
|
159
|
+
const links = { resolve: resolveLink, image: resolveImage, open: openLink };
|
|
160
|
+
const line = (value) => inline(value, links);
|
|
161
|
+
if (oneLine)
|
|
162
|
+
return _jsx("span", { className: ["sf-markdown-inline", className].filter(Boolean).join(" "), children: line(text) });
|
|
163
|
+
return (_jsxs("div", { className: ["sf-markdown", className].filter(Boolean).join(" "), children: [parseMarkdown(text).map((block, index) => {
|
|
164
|
+
switch (block.kind) {
|
|
165
|
+
case "heading": {
|
|
166
|
+
// Headings start at h3 so a reply never outranks the page's own headings.
|
|
167
|
+
const Tag = `h${Math.min(6, block.level + Math.max(0, Math.min(5, headingStart - 1)))}`;
|
|
168
|
+
return _jsx(Tag, { children: line(block.text) }, index);
|
|
169
|
+
}
|
|
170
|
+
case "code":
|
|
171
|
+
return _jsx(CodeBlock, { code: block.code, language: block.language, onRun: onRunSql && /^sql$/i.test(block.language) ? onRunSql : undefined }, index);
|
|
172
|
+
case "list": {
|
|
173
|
+
const Tag = block.ordered ? "ol" : "ul";
|
|
174
|
+
return (_jsx(Tag, { start: block.start, children: block.items.map((item, i) => (_jsx("li", { children: line(item) }, i))) }, index));
|
|
175
|
+
}
|
|
176
|
+
case "quote":
|
|
177
|
+
return _jsx("blockquote", { children: line(block.text) }, index);
|
|
178
|
+
case "rule":
|
|
179
|
+
return _jsx("hr", {}, index);
|
|
180
|
+
case "table":
|
|
181
|
+
return (_jsx("div", { className: "sf-markdown-table", tabIndex: 0, role: "region", "aria-label": `Table: ${block.head.slice(0, 3).join(", ")}`, children: _jsxs("table", { children: [_jsx("thead", { children: _jsx("tr", { children: block.head.map((cell, i) => (_jsx("th", { scope: "col", children: line(cell) }, i))) }) }), _jsx("tbody", { children: block.rows.map((row, r) => (_jsx("tr", { children: block.head.map((_, c) => (_jsx("td", { children: line(row[c] ?? "") }, c))) }, r))) })] }) }, index));
|
|
182
|
+
default:
|
|
183
|
+
return _jsx("p", { children: line(block.text) }, index);
|
|
184
|
+
}
|
|
185
|
+
}), _jsx(Fragment, {})] }));
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=Markdown.js.map
|