@dolusoft/query-table 3.18.0 → 3.19.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/dist/data-table.js +283 -0
- package/dist/data-table.js.map +1 -0
- package/dist/local-DDJEp4Nn.js +88 -0
- package/dist/local-DDJEp4Nn.js.map +1 -0
- package/dist/local.js +1 -87
- package/dist/query-table.js +1 -4833
- package/dist/src-BTIXBmwM.js +4928 -0
- package/dist/src-BTIXBmwM.js.map +1 -0
- package/dist/types/contract.d.ts +43 -1
- package/dist/types/data-table/contract.d.ts +64 -0
- package/dist/types/data-table/data-table.vue.d.ts +31 -0
- package/dist/types/data-table/derive-dataset.d.ts +32 -0
- package/dist/types/data-table/index.d.ts +4 -0
- package/dist/types/query-table.vue.d.ts +2 -1
- package/dist/types/use-query-table.d.ts +21 -3
- package/dist/types/virtual/use-row-window.d.ts +2 -0
- package/package.json +7 -3
- package/dist/local.js.map +0 -1
- package/dist/query-table.js.map +0 -1
package/dist/types/contract.d.ts
CHANGED
|
@@ -88,7 +88,8 @@ export interface Column {
|
|
|
88
88
|
* `IsNull`, `IsNotNull` and `Between`, which the list of a type leaves
|
|
89
89
|
* out. A condition the column type does not take is left out (`Between`
|
|
90
90
|
* on `string`, `Contains` on `number`). Unset, the menu offers the list
|
|
91
|
-
* of the type, as in 3.12.
|
|
91
|
+
* of the type, as in 3.12. A `bool` column has no menu: it adds `IsNull`
|
|
92
|
+
* and `IsNotNull` of the list to its select (C-120).
|
|
92
93
|
*/
|
|
93
94
|
filterConditions?: FilterCondition[];
|
|
94
95
|
/**
|
|
@@ -224,6 +225,13 @@ export interface TableProps<T extends object = Record<string, unknown>, Q extend
|
|
|
224
225
|
* expand.
|
|
225
226
|
*/
|
|
226
227
|
rowExpandable?: (row: T, index: number) => boolean;
|
|
228
|
+
/**
|
|
229
|
+
* How many rows may be open, with `hasSubtable` (C-123). `'single'` is an
|
|
230
|
+
* accordion: opening a row closes the open one (`rowExpansionChange` tells
|
|
231
|
+
* the closed row first), the `isExpanded` seed opens only the first row
|
|
232
|
+
* that asks, and `expandAll()` does nothing. Defaults to `'multiple'`.
|
|
233
|
+
*/
|
|
234
|
+
expandMode?: ExpandMode;
|
|
227
235
|
/**
|
|
228
236
|
* A kind for a row, written as `data-row-kind` on its `tr` (C-97): called
|
|
229
237
|
* with the row and its index in `rows`. Data, not styling: the table draws
|
|
@@ -286,6 +294,17 @@ export interface TableProps<T extends object = Record<string, unknown>, Q extend
|
|
|
286
294
|
* the body and footer tables `table-layout: fixed`. Defaults to `false`.
|
|
287
295
|
*/
|
|
288
296
|
scrollBody?: boolean;
|
|
297
|
+
/**
|
|
298
|
+
* Draw the header row (C-121). With `false` the table draws no `thead`, so
|
|
299
|
+
* nothing of it either: no sort by a click, no filter row, no resize or
|
|
300
|
+
* reorder handle, no clear-all button, no `headerContextMenu`. The sort
|
|
301
|
+
* and the filters of `query` still apply, and the `toolbar` slot still
|
|
302
|
+
* clears filters. What is measured from the header cells is off:
|
|
303
|
+
* `pinned` (columns are drawn unpinned, in `columns` order),
|
|
304
|
+
* `scrollBody` (one table) and `autoWidth`; `Column.width` applies
|
|
305
|
+
* through a `col`. Defaults to `true`.
|
|
306
|
+
*/
|
|
307
|
+
header?: boolean;
|
|
289
308
|
/**
|
|
290
309
|
* Ask for the next page (`update:query`, reason `page`) when the end of
|
|
291
310
|
* `rows` comes into view (C-88); append the rows of a `page` answer and
|
|
@@ -367,6 +386,19 @@ export interface RowFocusPayload<T> {
|
|
|
367
386
|
/** The key that moved the focus. */
|
|
368
387
|
key: 'ArrowUp' | 'ArrowDown' | 'Home' | 'End';
|
|
369
388
|
}
|
|
389
|
+
/** How many rows may be open at once (C-123). */
|
|
390
|
+
export type ExpandMode = 'multiple' | 'single';
|
|
391
|
+
/** Payload of the `rowExpansionChange` event (C-122). */
|
|
392
|
+
export interface RowExpansionPayload<T> {
|
|
393
|
+
/** The row the user opened or closed. */
|
|
394
|
+
row: T;
|
|
395
|
+
/** The row's index in `rows`. */
|
|
396
|
+
rowIndex: number;
|
|
397
|
+
/** The row's identity in the expansion state: `rowKey`, else its index (C-26). */
|
|
398
|
+
rowKey: string | number;
|
|
399
|
+
/** The row is open now. */
|
|
400
|
+
expanded: boolean;
|
|
401
|
+
}
|
|
370
402
|
/** Options of `infinite` (C-88). */
|
|
371
403
|
export interface InfiniteOptions {
|
|
372
404
|
/** Ask for the next page when the last this many rows come near. Defaults to `5`. */
|
|
@@ -547,6 +579,16 @@ export type TableEmits<T, Q extends Query = TableQuery> = {
|
|
|
547
579
|
* emit it.
|
|
548
580
|
*/
|
|
549
581
|
rowFocus: [payload: RowFocusPayload<T>];
|
|
582
|
+
/**
|
|
583
|
+
* With `hasSubtable`: the user opened or closed a row with its expand
|
|
584
|
+
* button (C-122), once per press; with `expandMode: 'single'` a press
|
|
585
|
+
* that closes the open row emits for it first (C-123). The state stays
|
|
586
|
+
* the table's (C-26):
|
|
587
|
+
* `isExpanded`, the pruning when `rows` change, `expandAll()`,
|
|
588
|
+
* `collapseAll()` and a row leaving the window of a `virtual` body emit
|
|
589
|
+
* nothing.
|
|
590
|
+
*/
|
|
591
|
+
rowExpansionChange: [payload: RowExpansionPayload<T>];
|
|
550
592
|
};
|
|
551
593
|
export interface CellSlotProps<T> {
|
|
552
594
|
row: T;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Dataset, LocalQueryError, SemanticsProfile } from '@dolusoft/query-protocol/local';
|
|
2
|
+
import type { TableEmits, TableProps, TableQuery, TableSlots } from '../contract.js';
|
|
3
|
+
/**
|
|
4
|
+
* Public contract of `DataTable` (`@dolusoft/query-table/data-table`,
|
|
5
|
+
* ADR 0021). Its surface is the one of `QueryTable` with the difference
|
|
6
|
+
* listed here (C-124); everything it shares with `QueryTable` is described in
|
|
7
|
+
* `../contract.ts`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The props of `QueryTable` that `DataTable` does not take (C-124): it knows
|
|
11
|
+
* the total, pages by `page` and `pageSize` only, has no next page to ask a
|
|
12
|
+
* server for and gives the flash its own hint.
|
|
13
|
+
*/
|
|
14
|
+
export type DataTableOmittedProp = 'totalRows' | 'cursors' | 'infinite' | 'rowsUpdate';
|
|
15
|
+
/** Props of `DataTable`: those of `QueryTable`, with its rows held in the page (C-124). */
|
|
16
|
+
export interface DataTableProps<T extends object = Record<string, unknown>> extends Omit<TableProps<T, TableQuery>, 'query' | 'rows' | 'rowKey' | DataTableOmittedProp> {
|
|
17
|
+
/**
|
|
18
|
+
* The query, used with `v-model:query`. Optional: without it the table
|
|
19
|
+
* holds the query for as long as it lives (C-125).
|
|
20
|
+
*/
|
|
21
|
+
query?: TableQuery;
|
|
22
|
+
/**
|
|
23
|
+
* Every row of the source, not one page. Changes inside a deeply reactive
|
|
24
|
+
* array are seen; replace a shallowRef's array to have them seen.
|
|
25
|
+
*/
|
|
26
|
+
rows: readonly T[];
|
|
27
|
+
/**
|
|
28
|
+
* The field that identifies a row: a top-level field, a column of type
|
|
29
|
+
* `string` or `integer` (it may be `hide: true`). It breaks sort ties and
|
|
30
|
+
* keys selection and expansion across pages.
|
|
31
|
+
*/
|
|
32
|
+
rowKey: keyof T & string;
|
|
33
|
+
/** The semantics profile of the evaluation. Defaults to `'tr-2'`, and that default never moves. */
|
|
34
|
+
profile?: SemanticsProfile;
|
|
35
|
+
/** The fields of the global search: `string` columns (C-126). Defaults to none. */
|
|
36
|
+
search?: string[];
|
|
37
|
+
/**
|
|
38
|
+
* `false` draws every matching row and passes no `pagination` slot, so no
|
|
39
|
+
* pagination block is drawn. Defaults to `true`.
|
|
40
|
+
*/
|
|
41
|
+
paginate?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Replaces the dataset built from the columns, whole (C-126): for a field
|
|
44
|
+
* that needs `get` or `offset`, or a queryable field with no column. Keep
|
|
45
|
+
* the same object: a new one evaluates every row again and is a new
|
|
46
|
+
* context for the flash.
|
|
47
|
+
*/
|
|
48
|
+
dataset?: Dataset<T>;
|
|
49
|
+
}
|
|
50
|
+
/** Events of `DataTable`: those of `QueryTable`. */
|
|
51
|
+
export type DataTableEmits<T> = TableEmits<T, TableQuery>;
|
|
52
|
+
/** Props of the `error` slot. */
|
|
53
|
+
export interface ErrorSlotProps {
|
|
54
|
+
/** What the evaluator reported: an invalid query is not an empty result. */
|
|
55
|
+
error: LocalQueryError;
|
|
56
|
+
}
|
|
57
|
+
/** Slots of `DataTable`: those of `QueryTable`, and `error`. */
|
|
58
|
+
export interface DataTableSlots<T> extends TableSlots<T> {
|
|
59
|
+
/**
|
|
60
|
+
* Drawn in the empty row while the evaluator reports an error. Without it
|
|
61
|
+
* the `empty` slot is drawn.
|
|
62
|
+
*/
|
|
63
|
+
error?(props: ErrorSlotProps): unknown;
|
|
64
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DataTableProps, DataTableSlots } from './contract.js';
|
|
2
|
+
import type { Column, ColumnChangeReason, QueryTableExpose } from '../contract.js';
|
|
3
|
+
declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
4
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<DataTableProps<T> & {
|
|
5
|
+
onRowRightPanelClick?: ((row: T) => any) | undefined;
|
|
6
|
+
onCellContextMenu?: ((payload: import("../contract.js").CellContextMenuPayload<T>) => any) | undefined;
|
|
7
|
+
"onUpdate:query"?: ((query: import("@dolusoft/query-protocol").PageQuery, reason: "reset" | "page" | "pageSize" | "sort" | "filter" | "search") => any) | undefined;
|
|
8
|
+
"onUpdate:selection"?: ((selection: import("../contract.js").RowSelection) => any) | undefined;
|
|
9
|
+
onHeaderContextMenu?: ((payload: import("../contract.js").HeaderContextMenuPayload) => any) | undefined;
|
|
10
|
+
onColumnResize?: ((payload: import("../contract.js").ColumnResizePayload) => any) | undefined;
|
|
11
|
+
"onUpdate:columns"?: ((columns: Column[], reason: ColumnChangeReason) => any) | undefined;
|
|
12
|
+
"onUpdate:rowPinning"?: ((rowPinning: import("../contract.js").RowPinning) => any) | undefined;
|
|
13
|
+
onRowFocus?: ((payload: import("../contract.js").RowFocusPayload<T>) => any) | undefined;
|
|
14
|
+
onRowExpansionChange?: ((payload: import("../contract.js").RowExpansionPayload<T>) => any) | undefined;
|
|
15
|
+
}> & (typeof globalThis extends {
|
|
16
|
+
__VLS_PROPS_FALLBACK: infer P;
|
|
17
|
+
} ? P : {});
|
|
18
|
+
expose: (exposed: import("vue").ShallowUnwrapRef<QueryTableExpose>) => void;
|
|
19
|
+
attrs: any;
|
|
20
|
+
slots: DataTableSlots<T>;
|
|
21
|
+
emit: ((evt: "rowRightPanelClick", row: T) => void) & ((evt: "cellContextMenu", payload: import("../contract.js").CellContextMenuPayload<T>) => void) & ((evt: "update:query", query: import("@dolusoft/query-protocol").PageQuery, reason: "reset" | "page" | "pageSize" | "sort" | "filter" | "search") => void) & ((evt: "update:selection", selection: import("../contract.js").RowSelection) => void) & ((evt: "headerContextMenu", payload: import("../contract.js").HeaderContextMenuPayload) => void) & ((evt: "columnResize", payload: import("../contract.js").ColumnResizePayload) => void) & ((evt: "update:columns", columns: Column[], reason: ColumnChangeReason) => void) & ((evt: "update:rowPinning", rowPinning: import("../contract.js").RowPinning) => void) & ((evt: "rowFocus", payload: import("../contract.js").RowFocusPayload<T>) => void) & ((evt: "rowExpansionChange", payload: import("../contract.js").RowExpansionPayload<T>) => void);
|
|
22
|
+
}>) => import("vue").VNode & {
|
|
23
|
+
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
24
|
+
};
|
|
25
|
+
declare const _default: typeof __VLS_export;
|
|
26
|
+
export default _default;
|
|
27
|
+
type __VLS_PrettifyLocal<T> = (T extends any ? {
|
|
28
|
+
[K in keyof T]: T[K];
|
|
29
|
+
} : {
|
|
30
|
+
[K in keyof T as K]: T[K];
|
|
31
|
+
}) & {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ColumnType } from '@dolusoft/query-protocol';
|
|
2
|
+
import { type Dataset } from '@dolusoft/query-protocol/local';
|
|
3
|
+
import type { Column } from '../contract.js';
|
|
4
|
+
/** What the dataset of a `DataTable` is built from, and nothing else (C-126). */
|
|
5
|
+
export interface DatasetSpec {
|
|
6
|
+
key: string;
|
|
7
|
+
search: string[];
|
|
8
|
+
fields: Array<{
|
|
9
|
+
name: string;
|
|
10
|
+
type: ColumnType;
|
|
11
|
+
sortable: boolean;
|
|
12
|
+
filterable: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
/** The `ip` columns, left out of the fields (C-118). */
|
|
15
|
+
ip: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface DatasetSource {
|
|
18
|
+
rowKey: string;
|
|
19
|
+
columns: readonly Column[];
|
|
20
|
+
search: readonly string[] | undefined;
|
|
21
|
+
sortable: boolean;
|
|
22
|
+
filterable: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The spec of the columns: one field per column `field` (the first column of
|
|
26
|
+
* a name wins), hidden ones included, `ip` columns left out (C-118).
|
|
27
|
+
*/
|
|
28
|
+
export declare const datasetSpecOf: (source: DatasetSource) => DatasetSpec;
|
|
29
|
+
/** Equal specs build the same dataset. */
|
|
30
|
+
export declare const sameSpec: (a: DatasetSpec, b: DatasetSpec) => boolean;
|
|
31
|
+
/** The dataset of a spec. Throws a `TypeError` for a malformed one (C-126). */
|
|
32
|
+
export declare const datasetOf: <T>(spec: DatasetSpec) => Dataset<T>;
|
|
@@ -10,13 +10,14 @@ declare const __VLS_export: <T extends object, Q extends Query = TableQuery>(__V
|
|
|
10
10
|
"onUpdate:columns"?: ((columns: import("./contract.js").Column[], reason: import("./contract.js").ColumnChangeReason) => any) | undefined;
|
|
11
11
|
"onUpdate:rowPinning"?: ((rowPinning: import("./contract.js").RowPinning) => any) | undefined;
|
|
12
12
|
onRowFocus?: ((payload: import("./contract.js").RowFocusPayload<T>) => any) | undefined;
|
|
13
|
+
onRowExpansionChange?: ((payload: import("./contract.js").RowExpansionPayload<T>) => any) | undefined;
|
|
13
14
|
}> & (typeof globalThis extends {
|
|
14
15
|
__VLS_PROPS_FALLBACK: infer P;
|
|
15
16
|
} ? P : {});
|
|
16
17
|
expose: (exposed: import("vue").ShallowUnwrapRef<QueryTableExpose>) => void;
|
|
17
18
|
attrs: any;
|
|
18
19
|
slots: TableSlots<T>;
|
|
19
|
-
emit: ((evt: "rowRightPanelClick", row: T) => void) & ((evt: "cellContextMenu", payload: import("./contract.js").CellContextMenuPayload<T>) => void) & ((evt: "update:query", query: Q, reason: "reset" | "page" | "pageSize" | "sort" | "filter" | "search") => void) & ((evt: "update:selection", selection: import("./contract.js").RowSelection) => void) & ((evt: "headerContextMenu", payload: import("./contract.js").HeaderContextMenuPayload) => void) & ((evt: "columnResize", payload: import("./contract.js").ColumnResizePayload) => void) & ((evt: "update:columns", columns: import("./contract.js").Column[], reason: import("./contract.js").ColumnChangeReason) => void) & ((evt: "update:rowPinning", rowPinning: import("./contract.js").RowPinning) => void) & ((evt: "rowFocus", payload: import("./contract.js").RowFocusPayload<T>) => void);
|
|
20
|
+
emit: ((evt: "rowRightPanelClick", row: T) => void) & ((evt: "cellContextMenu", payload: import("./contract.js").CellContextMenuPayload<T>) => void) & ((evt: "update:query", query: Q, reason: "reset" | "page" | "pageSize" | "sort" | "filter" | "search") => void) & ((evt: "update:selection", selection: import("./contract.js").RowSelection) => void) & ((evt: "headerContextMenu", payload: import("./contract.js").HeaderContextMenuPayload) => void) & ((evt: "columnResize", payload: import("./contract.js").ColumnResizePayload) => void) & ((evt: "update:columns", columns: import("./contract.js").Column[], reason: import("./contract.js").ColumnChangeReason) => void) & ((evt: "update:rowPinning", rowPinning: import("./contract.js").RowPinning) => void) & ((evt: "rowFocus", payload: import("./contract.js").RowFocusPayload<T>) => void) & ((evt: "rowExpansionChange", payload: import("./contract.js").RowExpansionPayload<T>) => void);
|
|
20
21
|
}>) => import("vue").VNode & {
|
|
21
22
|
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
22
23
|
};
|
|
@@ -2,7 +2,7 @@ import { type FilterDraft, type Query } from '@dolusoft/query-protocol';
|
|
|
2
2
|
import { type FilterBound, type FilterLabel } from '@dolusoft/query-table-core';
|
|
3
3
|
import { type VueTable } from '@tanstack/vue-table';
|
|
4
4
|
import { type ComputedRef, type MaybeRefOrGetter } from 'vue';
|
|
5
|
-
import type { Column, ColumnChangeReason, ColumnControl, FilterCondition, PageCursors, PaginationSlotProps, QueryChangeReason, RowPinning, RowSelection, SortDirection, TableProps, TableQuery } from './contract.js';
|
|
5
|
+
import type { Column, ColumnChangeReason, ColumnControl, ExpandMode, FilterCondition, PageCursors, PaginationSlotProps, QueryChangeReason, RowExpansionPayload, RowPinning, RowSelection, SortDirection, TableProps, TableQuery } from './contract.js';
|
|
6
6
|
/** The TanStack features of a Query Table, the two plugins included. */
|
|
7
7
|
declare const features: {
|
|
8
8
|
rowSortingFeature: import("@tanstack/table-core").TableFeature;
|
|
@@ -55,6 +55,11 @@ export interface UseQueryTableOptions<T extends object, Q extends Query = TableQ
|
|
|
55
55
|
* function is read as a getter.
|
|
56
56
|
*/
|
|
57
57
|
rowExpandable?: MaybeRefOrGetter<TableProps<T>['rowExpandable']>;
|
|
58
|
+
/**
|
|
59
|
+
* `'single'` keeps at most one row open: opening a row closes the open one
|
|
60
|
+
* (C-123). Defaults to `'multiple'`.
|
|
61
|
+
*/
|
|
62
|
+
expandMode?: MaybeRefOrGetter<ExpandMode | undefined>;
|
|
58
63
|
/** Page sizes offered. Defaults to `[10, 20, 30, 50, 100]`. */
|
|
59
64
|
pageSizeOptions?: MaybeRefOrGetter<number[] | undefined>;
|
|
60
65
|
/** Called once per user action that changes the query, with a new object. */
|
|
@@ -68,6 +73,12 @@ export interface UseQueryTableOptions<T extends object, Q extends Query = TableQ
|
|
|
68
73
|
onColumnsChange?: (columns: Column[], reason: ColumnChangeReason) => void;
|
|
69
74
|
/** Called with the new map when the user pins or unpins a row (C-74). */
|
|
70
75
|
onRowPinningChange?: (rowPinning: RowPinning) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Called once per `expansion.toggle` that opened or closed a row (C-122):
|
|
78
|
+
* the expand button of `QueryTable`, or yours. The seed, the pruning,
|
|
79
|
+
* `expandAll` and `collapseAll` do not call it.
|
|
80
|
+
*/
|
|
81
|
+
onRowExpansionChange?: (payload: RowExpansionPayload<T>) => void;
|
|
71
82
|
}
|
|
72
83
|
/** A row of the body in drawing order (C-74). */
|
|
73
84
|
export interface BodyRow<T> {
|
|
@@ -147,10 +158,17 @@ export interface QueryTableExpansion<T extends object> {
|
|
|
147
158
|
/** `hasSubtable` is on and `rowExpandable` lets the row expand (C-98). */
|
|
148
159
|
canExpand: (row: T, index: number) => boolean;
|
|
149
160
|
isExpanded: (row: T, index: number) => boolean;
|
|
150
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Opens or closes the row and calls `onRowExpansionChange` (C-122);
|
|
163
|
+
* nothing for a row that cannot expand (C-98). With `expandMode: 'single'`
|
|
164
|
+
* opening a row closes the open one, which is told first (C-123).
|
|
165
|
+
*/
|
|
151
166
|
toggle: (row: T, index: number) => void;
|
|
152
167
|
collapseAll: () => void;
|
|
153
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Opens every row given that can expand; nothing is fetched. Does nothing
|
|
170
|
+
* with `expandMode: 'single'` (C-123).
|
|
171
|
+
*/
|
|
154
172
|
expandAll: () => void;
|
|
155
173
|
}
|
|
156
174
|
/** Row selection (C-59), owned by the consumer. */
|
|
@@ -31,6 +31,8 @@ export interface RowWindowOptions<T> {
|
|
|
31
31
|
isExpanded: (row: T, index: number) => boolean;
|
|
32
32
|
/** The `groupBy` prop (C-103); absent, no group is drawn. */
|
|
33
33
|
groupBy?: () => ((row: T, index: number) => GroupKey | null | undefined) | undefined;
|
|
34
|
+
/** Rows of the header before the body rows: `0` without it (C-121). */
|
|
35
|
+
headerRows?: () => number;
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
38
|
* The virtual body (C-83 to C-87): which rows are drawn, the spacers that
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolusoft/query-table",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.0",
|
|
4
4
|
"description": "A thin Vue 3 table for server-side data: it renders rows and emits sort, filter, search and paging changes. Built on TanStack Table.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"./local": {
|
|
19
19
|
"types": "./dist/types/local/index.d.ts",
|
|
20
20
|
"default": "./dist/local.js"
|
|
21
|
+
},
|
|
22
|
+
"./data-table": {
|
|
23
|
+
"types": "./dist/types/data-table/index.d.ts",
|
|
24
|
+
"default": "./dist/data-table.js"
|
|
21
25
|
}
|
|
22
26
|
},
|
|
23
27
|
"engines": {
|
|
@@ -45,8 +49,8 @@
|
|
|
45
49
|
],
|
|
46
50
|
"license": "MIT",
|
|
47
51
|
"dependencies": {
|
|
48
|
-
"@dolusoft/query-protocol": "3.
|
|
49
|
-
"@dolusoft/query-table-core": "3.
|
|
52
|
+
"@dolusoft/query-protocol": "3.19.0",
|
|
53
|
+
"@dolusoft/query-table-core": "3.19.0",
|
|
50
54
|
"@tanstack/vue-table": "9.2.6"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
package/dist/local.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local.js","names":[],"sources":["../src/local/use-local-query.ts"],"sourcesContent":["import {\n cloneQuery,\n sameRules,\n searchOf,\n type FilterRule,\n type Query,\n type SortState\n} from '@dolusoft/query-protocol'\nimport {\n applyQuery,\n slicePage,\n type Dataset,\n type LocalQueryError,\n type LocalQueryResult,\n type SemanticsProfile\n} from '@dolusoft/query-protocol/local'\nimport {\n computed,\n toValue,\n watch,\n type ComputedRef,\n type MaybeRefOrGetter\n} from 'vue'\n\n// Replaced by the consumer's bundler, just as in Vue's esm-bundler build.\ndeclare const process: { env: { NODE_ENV?: string } }\n\nexport interface UseLocalQueryOptions<T> {\n /** Every row of the source context. In-place changes in a deeply reactive array are seen; replace a shallowRef's array to trigger evaluation. */\n allRows: MaybeRefOrGetter<readonly T[]>\n /** The consumer's query, read without writing or correcting it. */\n query: MaybeRefOrGetter<Query>\n /** Replace together with allRows when the schema changes. */\n dataset: MaybeRefOrGetter<Dataset<T>>\n profile: SemanticsProfile\n /** false returns every matching row for print or export. Defaults to true. */\n paginate?: MaybeRefOrGetter<boolean>\n}\n\nexport interface LocalQuery<T> {\n /** The supplied row objects; empty while error is set. */\n rows: ComputedRef<T[]>\n /** The matching count; zero while error is set. */\n totalRows: ComputedRef<number>\n /** Render this separately from an empty result. */\n error: ComputedRef<LocalQueryError | null>\n}\n\n// A try/catch preserves constant replacement in production browser builds.\n// A typeof guard would stay true when the browser has no process global.\nconst isDevelopment = (): boolean => {\n try {\n return process.env.NODE_ENV !== 'production'\n } catch {\n return true\n }\n}\n\ninterface Semantic {\n filters: FilterRule[]\n sort: SortState | null\n search: string\n}\n\n/** Evaluates locally without rerunning filtering, search or sorting for a page-only change. */\nexport function useLocalQuery<T>(\n options: UseLocalQueryOptions<T>\n): LocalQuery<T> {\n const semantic = computed<Semantic>(previous => {\n const query = toValue(options.query)\n // Include nested extra rule properties: sameRules compares them by value.\n const copy = cloneQuery({\n page: 1,\n pageSize: 1,\n filters: query.filters,\n sort: query.sort,\n search: searchOf(query)\n })\n const next = {\n filters: copy.filters,\n sort: copy.sort,\n search: searchOf(copy)\n }\n return previous &&\n sameRules(previous.filters, next.filters) &&\n previous.sort?.field === next.sort?.field &&\n previous.sort?.direction === next.sort?.direction &&\n (previous.sort === null) === (next.sort === null) &&\n previous.search === next.search\n ? previous\n : next\n })\n const evaluated = computed(() =>\n applyQuery(\n toValue(options.allRows),\n { page: 1, pageSize: 1, ...semantic.value },\n toValue(options.dataset),\n { profile: options.profile, paginate: false }\n )\n )\n const result = computed<LocalQueryResult<T>>(() => {\n const query = toValue(options.query)\n const paginate = toValue(options.paginate) ?? true\n const check = applyQuery([], query, toValue(options.dataset), {\n profile: options.profile,\n paginate\n })\n if (!check.ok) {\n return check\n }\n const all = evaluated.value\n if (!all.ok) {\n return all\n }\n if (!paginate) {\n return { ok: true, rows: [...all.rows], totalRows: all.totalRows }\n }\n // The precheck already validated paging.\n const page = slicePage(all.rows, query)\n return page.ok\n ? { ok: true, rows: page.rows, totalRows: all.totalRows }\n : page\n })\n const rows = computed(() => (result.value.ok ? result.value.rows : []))\n const totalRows = computed(() =>\n result.value.ok ? result.value.totalRows : 0\n )\n const error = computed(() => (result.value.ok ? null : result.value.error))\n let last = ''\n watch(\n error,\n value => {\n if (!value) {\n last = ''\n return\n }\n const key = JSON.stringify([value.code, value.path, value.field])\n if (isDevelopment() && key !== last) {\n last = key\n console.error('[useLocalQuery]', value)\n }\n },\n { immediate: true }\n )\n return { rows, totalRows, error }\n}\n"],"mappings":";;;;AAkDA,IAAM,sBAA+B;CACnC,IAAI;EACF,OAAA,QAAA,IAAA,aAAgC;CAClC,QAAQ;EACN,OAAO;CACT;AACF;;AASA,SAAgB,cACd,SACe;CACf,MAAM,WAAW,UAAmB,aAAY;EAC9C,MAAM,QAAQ,QAAQ,QAAQ,KAAK;EAEnC,MAAM,OAAO,WAAW;GACtB,MAAM;GACN,UAAU;GACV,SAAS,MAAM;GACf,MAAM,MAAM;GACZ,QAAQ,SAAS,KAAK;EACxB,CAAC;EACD,MAAM,OAAO;GACX,SAAS,KAAK;GACd,MAAM,KAAK;GACX,QAAQ,SAAS,IAAI;EACvB;EACA,OAAO,YACL,UAAU,SAAS,SAAS,KAAK,OAAO,KACxC,SAAS,MAAM,UAAU,KAAK,MAAM,SACpC,SAAS,MAAM,cAAc,KAAK,MAAM,aACvC,SAAS,SAAS,UAAW,KAAK,SAAS,SAC5C,SAAS,WAAW,KAAK,SACvB,WACA;CACN,CAAC;CACD,MAAM,YAAY,eAChB,WACE,QAAQ,QAAQ,OAAO,GACvB;EAAE,MAAM;EAAG,UAAU;EAAG,GAAG,SAAS;CAAM,GAC1C,QAAQ,QAAQ,OAAO,GACvB;EAAE,SAAS,QAAQ;EAAS,UAAU;CAAM,CAC9C,CACF;CACA,MAAM,SAAS,eAAoC;EACjD,MAAM,QAAQ,QAAQ,QAAQ,KAAK;EACnC,MAAM,WAAW,QAAQ,QAAQ,QAAQ,KAAK;EAC9C,MAAM,QAAQ,WAAW,CAAC,GAAG,OAAO,QAAQ,QAAQ,OAAO,GAAG;GAC5D,SAAS,QAAQ;GACjB;EACF,CAAC;EACD,IAAI,CAAC,MAAM,IACT,OAAO;EAET,MAAM,MAAM,UAAU;EACtB,IAAI,CAAC,IAAI,IACP,OAAO;EAET,IAAI,CAAC,UACH,OAAO;GAAE,IAAI;GAAM,MAAM,CAAC,GAAG,IAAI,IAAI;GAAG,WAAW,IAAI;EAAU;EAGnE,MAAM,OAAO,UAAU,IAAI,MAAM,KAAK;EACtC,OAAO,KAAK,KACR;GAAE,IAAI;GAAM,MAAM,KAAK;GAAM,WAAW,IAAI;EAAU,IACtD;CACN,CAAC;CACD,MAAM,OAAO,eAAgB,OAAO,MAAM,KAAK,OAAO,MAAM,OAAO,CAAC,CAAE;CACtE,MAAM,YAAY,eAChB,OAAO,MAAM,KAAK,OAAO,MAAM,YAAY,CAC7C;CACA,MAAM,QAAQ,eAAgB,OAAO,MAAM,KAAK,OAAO,OAAO,MAAM,KAAM;CAC1E,IAAI,OAAO;CACX,MACE,QACA,UAAS;EACP,IAAI,CAAC,OAAO;GACV,OAAO;GACP;EACF;EACA,MAAM,MAAM,KAAK,UAAU;GAAC,MAAM;GAAM,MAAM;GAAM,MAAM;EAAK,CAAC;EAChE,IAAI,cAAc,KAAK,QAAQ,MAAM;GACnC,OAAO;GACP,QAAQ,MAAM,mBAAmB,KAAK;EACxC;CACF,GACA,EAAE,WAAW,KAAK,CACpB;CACA,OAAO;EAAE;EAAM;EAAW;CAAM;AAClC"}
|