@dolusoft/query-table 3.0.1

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.
@@ -0,0 +1,30 @@
1
+ import { type ShallowRef } from 'vue';
2
+ /** A drawn header cell, in order: its key (`field`, or the utility) and pin. */
3
+ interface HeaderCellKey {
4
+ key: string;
5
+ pinned: boolean;
6
+ }
7
+ export interface HeaderGeometryOptions {
8
+ /** The `table` element once it is mounted. */
9
+ table: ShallowRef<HTMLTableElement | null>;
10
+ /** The header cells as drawn: utilities first, then the columns. */
11
+ cells: () => HeaderCellKey[];
12
+ /** Some column is pinned (C-46) or has a resize handle (C-48). */
13
+ active: () => boolean;
14
+ }
15
+ /**
16
+ * Measured header geometry (C-47, C-48): the rendered width of every header
17
+ * cell and, for the pinned cells, the cumulative left offset written as
18
+ * `--qt-pin-left`. One `ResizeObserver` watches the header cells and the
19
+ * table; it reports width changes from any cause (a resize, a font that
20
+ * loads, a container that narrows) in one batched callback, after layout, so
21
+ * reading the cells there forces no extra layout. The observer is rebuilt
22
+ * only when the drawn cells change, not when a width does. Nothing is
23
+ * measured while inactive, and the observer is disconnected on unmount.
24
+ */
25
+ export declare const useHeaderGeometry: (options: HeaderGeometryOptions) => {
26
+ widths: ShallowRef<Readonly<Record<string, number>>, Readonly<Record<string, number>>>;
27
+ tableWidth: ShallowRef<number, number>;
28
+ offsets: ShallowRef<Readonly<Record<string, number>>, Readonly<Record<string, number>>>;
29
+ };
30
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { Query, QueryTableExpose, TableProps, TableQuery, TableSlots } from './contract.js';
2
+ declare const __VLS_export: <T extends object, Q extends Query = TableQuery>(__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<{
3
+ props: import("vue").PublicProps & __VLS_PrettifyLocal<TableProps<T, Q> & {
4
+ onRowRightPanelClick?: ((row: T) => any) | undefined;
5
+ onCellContextMenu?: ((payload: import("./contract.js").CellContextMenuPayload<T>) => any) | undefined;
6
+ "onUpdate:query"?: ((query: Q, reason: "page" | "pageSize" | "sort" | "filter" | "reset" | "search") => any) | undefined;
7
+ "onUpdate:selection"?: ((selection: import("./contract.js").RowSelection) => any) | undefined;
8
+ onColumnResize?: ((payload: import("./contract.js").ColumnResizePayload) => any) | undefined;
9
+ }> & (typeof globalThis extends {
10
+ __VLS_PROPS_FALLBACK: infer P;
11
+ } ? P : {});
12
+ expose: (exposed: import("vue").ShallowUnwrapRef<QueryTableExpose>) => void;
13
+ attrs: any;
14
+ slots: TableSlots<T>;
15
+ emit: ((evt: "rowRightPanelClick", row: T) => void) & ((evt: "cellContextMenu", payload: import("./contract.js").CellContextMenuPayload<T>) => void) & ((evt: "update:query", query: Q, reason: "page" | "pageSize" | "sort" | "filter" | "reset" | "search") => void) & ((evt: "update:selection", selection: import("./contract.js").RowSelection) => void) & ((evt: "columnResize", payload: import("./contract.js").ColumnResizePayload) => void);
16
+ }>) => import("vue").VNode & {
17
+ __ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
18
+ };
19
+ declare const _default: typeof __VLS_export;
20
+ export default _default;
21
+ type __VLS_PrettifyLocal<T> = (T extends any ? {
22
+ [K in keyof T]: T[K];
23
+ } : {
24
+ [K in keyof T as K]: T[K];
25
+ }) & {};
@@ -0,0 +1,46 @@
1
+ import type { Column, ColumnResizePayload } from '../contract.js';
2
+ export interface ColumnResizeOptions {
3
+ /** The `resizable` prop: whether the table draws resize handles. */
4
+ resizable: () => boolean;
5
+ /** Measured width of a header cell, by `field`. */
6
+ measuredWidth: (field: string) => number | undefined;
7
+ /** Measured width of the table. */
8
+ tableWidth: () => number;
9
+ emit: (payload: ColumnResizePayload) => void;
10
+ }
11
+ /**
12
+ * The smallest width: `Column.minWidth`, else the default 40 (which gives way
13
+ * to a smaller `Column.maxWidth`, so a maximum alone keeps working).
14
+ */
15
+ export declare const minWidthOf: (column: Column) => number;
16
+ export declare const clampWidth: (column: Column, width: number) => number;
17
+ /**
18
+ * Resizing a column (C-48 to C-50). The table holds a width only while a
19
+ * drag is under way (the preview, P2); every committed width goes out as a
20
+ * `columnResize` event and comes back, if the consumer wants it, as
21
+ * `Column.width`. The handle captures the pointer, so all drag events arrive
22
+ * at the handle itself, and it has the focus, so Escape does too.
23
+ */
24
+ export declare const useColumnResize: (options: ColumnResizeOptions) => {
25
+ preview: import("vue").ShallowRef<{
26
+ field: string;
27
+ width: number;
28
+ } | null, {
29
+ field: string;
30
+ width: number;
31
+ } | null>;
32
+ isResizable: (column: Column) => boolean;
33
+ widthOf: (column: Column) => number;
34
+ maxOf: (column: Column) => number;
35
+ listeners: (column: () => Column) => {
36
+ pointerdown: (event: PointerEvent) => void;
37
+ pointermove: (event: PointerEvent) => void;
38
+ pointerup: (event: PointerEvent) => void;
39
+ pointercancel: (event: PointerEvent) => void;
40
+ lostpointercapture: (event: PointerEvent) => void;
41
+ keydown: (event: Event) => void;
42
+ dblclick: (event: Event) => void;
43
+ click: (event: Event) => void;
44
+ };
45
+ };
46
+ export type ColumnResize = ReturnType<typeof useColumnResize>;
@@ -0,0 +1,3 @@
1
+ import type { SortDirection } from '../contract.js';
2
+ /** Value of the `aria-sort` attribute for a direction. */
3
+ export declare const ariaSort: (direction: SortDirection | null) => "ascending" | "descending" | undefined;
@@ -0,0 +1,146 @@
1
+ import { type FilterDraft, type Query } from '@dolusoft/query-protocol';
2
+ import { type FilterLabel } from '@dolusoft/query-table-core';
3
+ import { type VueTable } from '@tanstack/vue-table';
4
+ import { type ComputedRef, type MaybeRefOrGetter } from 'vue';
5
+ import type { Column, FilterCondition, PageCursors, PaginationSlotProps, QueryChangeReason, RowSelection, SortDirection, TableProps, TableQuery } from './contract.js';
6
+ /** The TanStack features of a Query Table, the two plugins included. */
7
+ declare const features: {
8
+ rowSortingFeature: import("@tanstack/table-core").TableFeature;
9
+ rowPaginationFeature: import("@tanstack/table-core").TableFeature;
10
+ columnFilteringFeature: import("@tanstack/table-core").TableFeature;
11
+ globalFilteringFeature: import("@tanstack/table-core").TableFeature;
12
+ rowSelectionFeature: import("@tanstack/table-core").TableFeature;
13
+ rowExpandingFeature: import("@tanstack/table-core").TableFeature;
14
+ columnPinningFeature: import("@tanstack/table-core").TableFeature;
15
+ serverQueryFeature: import("@tanstack/table-core").TableFeature;
16
+ filterInputFeature: import("@tanstack/table-core").TableFeature;
17
+ };
18
+ export type QueryTableFeatures = typeof features;
19
+ /** Identity of a row: a property name or a function (see `TableProps.rowKey`). */
20
+ export type RowKey<T extends object> = TableProps<T>['rowKey'];
21
+ export interface UseQueryTableOptions<T extends object, Q extends Query = TableQuery> {
22
+ /** The query the table shows. The consumer owns it. */
23
+ query: MaybeRefOrGetter<Q>;
24
+ /** Column definitions, hidden ones included. Never mutated. */
25
+ columns: MaybeRefOrGetter<Column[]>;
26
+ /** Rows of the current page. Defaults to none. */
27
+ rows?: MaybeRefOrGetter<T[] | undefined>;
28
+ /** Rows on the server, `null` when unknown. */
29
+ totalRows?: MaybeRefOrGetter<number | null | undefined>;
30
+ /** Cursor mode: the cursors of the page shown (C-56). */
31
+ cursors?: MaybeRefOrGetter<PageCursors | null | undefined>;
32
+ /** Allow sorting (needs column `sortable`). Defaults to `false`. */
33
+ sortable?: MaybeRefOrGetter<boolean | undefined>;
34
+ /** Milliseconds before typed filter text is applied. Defaults to `100`. */
35
+ filterDebounce?: MaybeRefOrGetter<number | undefined>;
36
+ /** Milliseconds before typed search text is applied. Defaults to `300`. */
37
+ searchDebounce?: MaybeRefOrGetter<number | undefined>;
38
+ /** The selected rows; `undefined` turns selection off. */
39
+ selection?: MaybeRefOrGetter<RowSelection | undefined>;
40
+ /** Identity of a row. Without it the row index is the identity. */
41
+ rowKey?: MaybeRefOrGetter<RowKey<T>>;
42
+ /** Rows can expand (the `subtable` column). Defaults to `false`. */
43
+ hasSubtable?: MaybeRefOrGetter<boolean | undefined>;
44
+ /** Page sizes offered. Defaults to `[10, 20, 30, 50, 100]`. */
45
+ pageSizeOptions?: MaybeRefOrGetter<number[] | undefined>;
46
+ /** Called once per user action that changes the query, with a new object. */
47
+ onQueryChange: (query: Q, reason: QueryChangeReason) => void;
48
+ /** Called with the new selection (its `true` entries) when the user changes it. */
49
+ onSelectionChange?: (selection: RowSelection) => void;
50
+ }
51
+ /** A column the table draws and its position in `columns`, hidden ones included. */
52
+ export interface ColumnEntry {
53
+ column: Column;
54
+ index: number;
55
+ }
56
+ /** The filter input of each column (C-08 to C-22). */
57
+ export interface QueryTableFilters {
58
+ /** The column's typed text and picked condition; blank when nothing is typed. */
59
+ draftOf: (field: string) => Readonly<FilterDraft>;
60
+ /** The input's text changed: applied after the debounce (C-09). */
61
+ setInput: (field: string, text: string) => void;
62
+ /** Enter: applies the column's pending text now (C-12). */
63
+ apply: (field: string) => void;
64
+ /** Applies every pending text in one update; `true` when it changed the filters. */
65
+ flushAll: () => boolean;
66
+ /** Picks a condition; `null` clears the column (C-20). */
67
+ setCondition: (field: string, condition: FilterCondition | null) => void;
68
+ /** Removes the column's rules and text (C-21). */
69
+ clear: (field: string) => void;
70
+ /** Removes every rule and discards every text (C-22). */
71
+ clearAll: () => void;
72
+ /** There is a rule or typed text to clear (C-22). */
73
+ canClearAll: () => boolean;
74
+ /** The condition label under an input, `null` when there is none. */
75
+ labelOf: (field: string) => FilterLabel | null;
76
+ /** How many rules a read-only input stands for; `0` when it is editable. */
77
+ multiOf: (field: string) => number;
78
+ }
79
+ /** Sorting by the headers and the filter menu (C-07). */
80
+ export interface QueryTableSort {
81
+ /** The table and the column allow sorting by it. */
82
+ isSortable: (column: Column) => boolean;
83
+ /** The direction the query sorts `column` in, `null` when it sorts another. */
84
+ sortOf: (column: Column) => SortDirection | null;
85
+ /**
86
+ * Without a direction, the header click: ascending, descending, none.
87
+ * Does nothing for a column that cannot sort.
88
+ */
89
+ sortBy: (column: Column, direction?: SortDirection) => void;
90
+ }
91
+ /** The global search (C-58). */
92
+ export interface QueryTableSearch {
93
+ /** Text being typed, else `query.search`, else `''`. */
94
+ text: ComputedRef<string>;
95
+ /** The input changed: applied after `searchDebounce`, at once when it is `0` or blank. */
96
+ set: (text: string) => void;
97
+ /** Applies a pending text now; `true` when it emitted an update. */
98
+ apply: () => boolean;
99
+ }
100
+ /** Expanded rows (C-26, C-55), held in TanStack's `expanded` slice. */
101
+ export interface QueryTableExpansion<T extends object> {
102
+ /** Identity of a row: `rowKey`, else its index. */
103
+ keyOf: (row: T, index: number) => string | number;
104
+ isExpanded: (row: T, index: number) => boolean;
105
+ toggle: (row: T, index: number) => void;
106
+ collapseAll: () => void;
107
+ /** Opens every row given; nothing is fetched. */
108
+ expandAll: () => void;
109
+ }
110
+ /** Row selection (C-59), owned by the consumer. */
111
+ export interface QueryTableSelection<T extends object> {
112
+ /** A `selection` was given: the table offers selection. */
113
+ enabled: ComputedRef<boolean>;
114
+ isSelected: (row: T, index: number) => boolean;
115
+ toggle: (row: T, index: number) => void;
116
+ /** Every row of the page is selected (and there is one). */
117
+ allSelected: ComputedRef<boolean>;
118
+ /** Some but not every row of the page is selected. */
119
+ someSelected: ComputedRef<boolean>;
120
+ /** Select or deselect every row of the page. */
121
+ toggleAll: (value: boolean) => void;
122
+ }
123
+ export interface QueryTable<T extends object, Q extends Query = TableQuery> {
124
+ /** The TanStack table, for the advanced path (headless markup). */
125
+ table: VueTable<QueryTableFeatures, T>;
126
+ /** The columns to draw: hidden ones dropped, pinned ones first. */
127
+ columns: ComputedRef<ColumnEntry[]>;
128
+ /** Some drawn column is pinned. */
129
+ hasPinned: ComputedRef<boolean>;
130
+ sort: QueryTableSort;
131
+ filters: QueryTableFilters;
132
+ search: QueryTableSearch;
133
+ /** What the `pagination` slot receives (C-05, C-06, C-23, C-56). */
134
+ pagination: ComputedRef<PaginationSlotProps>;
135
+ expansion: QueryTableExpansion<T>;
136
+ selection: QueryTableSelection<T>;
137
+ /** The query a new action builds on (an update not yet answered included). */
138
+ baseQuery: () => Q;
139
+ }
140
+ /**
141
+ * The state and actions of a server-side table: TanStack Table with
142
+ * `serverQueryFeature` and `filterInputFeature`, in a Vue scope. Disposed
143
+ * with the scope (C-62).
144
+ */
145
+ export declare function useQueryTable<T extends object, Q extends Query = TableQuery>(options: UseQueryTableOptions<T, Q>): QueryTable<T, Q>;
146
+ export {};
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@dolusoft/query-table",
3
+ "version": "3.0.1",
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
+ "private": false,
6
+ "type": "module",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "sideEffects": false,
11
+ "main": "./dist/query-table.js",
12
+ "types": "./dist/types/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/types/index.d.ts",
16
+ "default": "./dist/query-table.js"
17
+ }
18
+ },
19
+ "engines": {
20
+ "node": ">=22.12"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/dolusoft/query-table.git",
25
+ "directory": "packages/vue"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/dolusoft/query-table/issues"
29
+ },
30
+ "homepage": "https://github.com/dolusoft/query-table#readme",
31
+ "keywords": [
32
+ "vue",
33
+ "vue3",
34
+ "table",
35
+ "datatable",
36
+ "server-side",
37
+ "pagination",
38
+ "sorting",
39
+ "filter",
40
+ "tanstack"
41
+ ],
42
+ "license": "MIT",
43
+ "dependencies": {
44
+ "@dolusoft/query-protocol": "3.0.1",
45
+ "@dolusoft/query-table-core": "3.0.1",
46
+ "@tanstack/vue-table": "9.2.6"
47
+ },
48
+ "devDependencies": {
49
+ "vue": "^3.5.43"
50
+ },
51
+ "peerDependencies": {
52
+ "vue": "^3.5.0"
53
+ },
54
+ "scripts": {
55
+ "build": "vite build && vue-tsc -p tsconfig.build.json && node ../../scripts/emit-type-extensions.mjs dist/types"
56
+ }
57
+ }