@pythia-software/query-table-ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 query-table contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @pythia-software/query-table-ui
2
+
3
+ Opinionated, themeable React components for query-table, including the data
4
+ table, query builder, field picker, metrics panel, saved queries, cell menus,
5
+ and selection toolbar.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @pythia-software/query-table-core @pythia-software/query-table-react @pythia-software/query-table-ui react
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```tsx
16
+ import { DataTable, QueryBuilder, defaultRenderers } from "@pythia-software/query-table-ui";
17
+ import "@pythia-software/query-table-ui/theme.css";
18
+
19
+ export function OrdersTable({ table, schema }) {
20
+ return (
21
+ <>
22
+ <QueryBuilder
23
+ api={table}
24
+ fields={schema.fields}
25
+ total={table.total}
26
+ running={table.loading}
27
+ />
28
+ <DataTable
29
+ fields={table.visibleFields}
30
+ rows={table.rows}
31
+ query={table.query}
32
+ onQueryChange={table.setQuery}
33
+ renderers={defaultRenderers}
34
+ rowId={table.rowId}
35
+ total={table.total}
36
+ loading={table.loading}
37
+ />
38
+ </>
39
+ );
40
+ }
41
+ ```
42
+
43
+ The bundled `link` renderer allows only HTTP(S), email, telephone, relative,
44
+ and fragment URLs. Applications remain responsible for validating URLs emitted
45
+ by custom renderers.
46
+
47
+ See the [repository README](https://github.com/Pythia-Software/query-table#readme)
48
+ for customization and backend integration details.
@@ -0,0 +1,165 @@
1
+ import { ReactNode, SetStateAction } from 'react';
2
+ import { FieldDef, QueryState, RowId, FieldStats, WhereClause } from '@pythia-software/query-table-core';
3
+ import { SelectionApi, ColumnDragApi, QueryTableApi, AggregationsApi, SavedQueriesApi } from '@pythia-software/query-table-react';
4
+
5
+ interface CellContext<Row = any, V = unknown> {
6
+ value: V;
7
+ row: Row;
8
+ field: FieldDef<Row, V>;
9
+ /** Current query — lets renderers reflect active state (e.g. highlight matches). */
10
+ query: QueryState;
11
+ }
12
+ type CellRenderer<Row = any, V = unknown> = (ctx: CellContext<Row, V>) => ReactNode;
13
+ type RenderRegistry<Row = any> = Record<string, CellRenderer<Row>>;
14
+ /** Resolve a user-controlled link against a harmless HTTPS base and allow only
15
+ * navigation protocols. This catches obfuscated forms such as `java\nscript:`
16
+ * that simple prefix checks miss while preserving relative and fragment URLs. */
17
+ declare function safeLinkHref(value: unknown): string | null;
18
+ /** Generic, domain-free renderers shipped with the package. Keys are stable and
19
+ * referenced from FieldDef.render. Consumers spread these and add their own. */
20
+ declare const defaultRenderers: RenderRegistry;
21
+ /** Resolve a FieldDef's renderer: inline fn wins, else registry lookup, else
22
+ * the `text` fallback. */
23
+ declare function resolveRenderer<Row>(field: FieldDef<Row>, registry: RenderRegistry<Row>): CellRenderer<Row>;
24
+
25
+ interface TableClassNames {
26
+ wrap?: string;
27
+ table?: string;
28
+ thead?: string;
29
+ headerRow?: string;
30
+ th?: string;
31
+ resizeHandle?: string;
32
+ tbody?: string;
33
+ row?: string;
34
+ rowSelected?: string;
35
+ cell?: string;
36
+ checkboxCell?: string;
37
+ loadingBar?: string;
38
+ empty?: string;
39
+ summaryRow?: string;
40
+ summaryCell?: string;
41
+ summaryControls?: string;
42
+ summaryHint?: string;
43
+ summaryButton?: string;
44
+ }
45
+ interface QueryBuilderClassNames {
46
+ root?: string;
47
+ chip?: string;
48
+ columnChip?: string;
49
+ button?: string;
50
+ input?: string;
51
+ select?: string;
52
+ }
53
+ interface MenuClassNames {
54
+ popover?: string;
55
+ item?: string;
56
+ separator?: string;
57
+ }
58
+
59
+ interface DataTableProps<Row> {
60
+ /** Ordered visible fields (widths already resolved), from `api.visibleFields`. */
61
+ fields: FieldDef<Row>[];
62
+ rows: Row[];
63
+ query: QueryState;
64
+ onQueryChange: (q: SetStateAction<QueryState>) => void;
65
+ /** Resolves FieldDef.render keys. Pass `{ ...defaultRenderers, ...yours }`. */
66
+ renderers: RenderRegistry<Row>;
67
+ /** Row → stable id (defaults to reading the schema's idField). */
68
+ rowId: (row: Row) => RowId | null;
69
+ /** Optional checkbox column + selection behavior (from `api.selection`). */
70
+ selection?: SelectionApi;
71
+ /** Shared column-reorder drag state (`api.columnDrag`). Pass it so dragging a
72
+ * table header also live-previews/dims the matching QueryBuilder select chip
73
+ * (and vice versa). Omit for a self-contained, table-only drag. */
74
+ columnDrag?: ColumnDragApi;
75
+ /** Always-visible trailing column (row actions, links). */
76
+ trailing?: (row: Row) => ReactNode;
77
+ trailingLabel?: string;
78
+ /** Total matching rows before pagination, when known. */
79
+ total?: number | null;
80
+ loading?: boolean;
81
+ emptyMessage?: string;
82
+ /** Tailwind / bespoke styling slots (Mode B). */
83
+ classNames?: TableClassNames;
84
+ }
85
+ declare function DataTable<Row>(props: DataTableProps<Row>): ReactNode;
86
+
87
+ interface QueryBuilderProps<Row> {
88
+ /** The controller; QueryBuilder drives it through the intent helpers. */
89
+ api: QueryTableApi<Row>;
90
+ /** All schema fields (for the field picker / sort picker). */
91
+ fields: FieldDef<Row>[];
92
+ /** Total matching rows, for the "N of M" paging hint. */
93
+ total: number | null;
94
+ /** Disable inputs while a fetch is in flight. */
95
+ running?: boolean;
96
+ classNames?: QueryBuilderClassNames;
97
+ /** Use this to control collapse state from a parent UI. */
98
+ collapsed?: boolean;
99
+ /** Controlled collapse callback (use when `collapsed` is provided). */
100
+ onCollapsedChange?: (collapsed: boolean) => void;
101
+ /** Initial collapse state for uncontrolled mode. */
102
+ defaultCollapsed?: boolean;
103
+ }
104
+ declare function QueryBuilder<Row>({ api, fields, total, running, classNames, collapsed, onCollapsedChange, defaultCollapsed, }: QueryBuilderProps<Row>): ReactNode;
105
+
106
+ interface MetricsPanelProps<Row> {
107
+ /** The aggregation API from useQueryTable (clauses + results + status). */
108
+ aggregations: AggregationsApi;
109
+ /** All schema fields, to resolve labels + the measure field's renderer. */
110
+ fields: FieldDef<Row>[];
111
+ /** Cell renderers (same registry as the table) for formatting measure values. */
112
+ renderers?: RenderRegistry<Row>;
113
+ /** Hidden entirely when there are no metrics unless this is set. */
114
+ emptyMessage?: string;
115
+ classNames?: {
116
+ root?: string;
117
+ metric?: string;
118
+ };
119
+ }
120
+ declare function MetricsPanel<Row>({ aggregations, fields, renderers, emptyMessage, classNames, }: MetricsPanelProps<Row>): ReactNode;
121
+
122
+ interface FieldPickerProps<Row> {
123
+ fields: FieldDef<Row>[];
124
+ /** Already-shown field names, so the picker can mark/hide them. */
125
+ excluded?: string[];
126
+ /** Stats keyed by field name (optional). */
127
+ stats?: Record<string, FieldStats>;
128
+ /** When true, dim/disable fields with ≤1 distinct value ("gate on distinct"). */
129
+ gateOnDistinct?: boolean;
130
+ onPick: (field: FieldDef<Row>) => void;
131
+ onClose?: () => void;
132
+ }
133
+ declare function FieldPicker<Row>({ fields, excluded, stats, gateOnDistinct, onPick, onClose, }: FieldPickerProps<Row>): ReactNode;
134
+
135
+ interface CellMenuProps<Row> {
136
+ field: FieldDef<Row>;
137
+ value: unknown;
138
+ /** Viewport coordinates of the click. */
139
+ x: number;
140
+ y: number;
141
+ onAddFilter: (clause: WhereClause) => void;
142
+ onClose: () => void;
143
+ classNames?: MenuClassNames;
144
+ }
145
+ declare function CellMenu<Row>({ field, value, x, y, onAddFilter, onClose, classNames }: CellMenuProps<Row>): ReactNode;
146
+
147
+ interface SelectionToolbarProps {
148
+ selection: SelectionApi;
149
+ /** Consumer-rendered action buttons. Receives the selected ids so the consumer
150
+ * can gate/enable actions (e.g. mixed-state rules). */
151
+ actions: (selectedIds: RowId[]) => ReactNode;
152
+ /** Hidden when nothing is selected unless `alwaysShow`. */
153
+ alwaysShow?: boolean;
154
+ className?: string;
155
+ }
156
+ declare function SelectionToolbar({ selection, actions, alwaysShow, className }: SelectionToolbarProps): ReactNode;
157
+
158
+ interface SavedQueriesModalProps {
159
+ saved: SavedQueriesApi;
160
+ onClose: () => void;
161
+ onLoad?: (savedId: string) => void;
162
+ }
163
+ declare function SavedQueriesModal({ saved, onClose, onLoad }: SavedQueriesModalProps): ReactNode;
164
+
165
+ export { type CellContext, CellMenu, type CellMenuProps, type CellRenderer, DataTable, type DataTableProps, FieldPicker, type FieldPickerProps, type MenuClassNames, MetricsPanel, type MetricsPanelProps, QueryBuilder, type QueryBuilderClassNames, type QueryBuilderProps, type RenderRegistry, SavedQueriesModal, type SavedQueriesModalProps, SelectionToolbar, type SelectionToolbarProps, type TableClassNames, defaultRenderers, resolveRenderer, safeLinkHref };