@dolusoft/query-table 3.1.0 → 3.2.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.
@@ -1,4 +1,4 @@
1
- import type { Slots } from 'vue';
1
+ import { type Slots } from 'vue';
2
2
  import type { CellContextMenuPayload, CellSlotProps, Column } from '../contract.js';
3
3
  import type { ColumnEntry } from '../use-query-table.js';
4
4
  export interface CellViewOptions<T extends object> {
@@ -24,6 +24,7 @@ export declare const useCellView: <T extends object>(options: CellViewOptions<T>
24
24
  cellText: (row: T, column: Column) => string;
25
25
  cellAttrs: (entry: ColumnEntry) => {
26
26
  'data-field': string;
27
+ 'data-type': "string" | "number" | "integer" | "date" | "datetime" | "bool" | undefined;
27
28
  };
28
29
  hasCellSlot: (column: Column) => boolean;
29
30
  slotProps: (row: T, column: Column, rowIndex: number, rowPinned: CellSlotProps<T>["rowPinned"]) => CellSlotProps<T>;
@@ -197,6 +197,51 @@ export interface TableProps<T extends object = Record<string, unknown>, Q extend
197
197
  * their English defaults.
198
198
  */
199
199
  labels?: Partial<TableLabels>;
200
+ /**
201
+ * Draw only the rows in view of the scroll container, between two spacer
202
+ * rows (C-83). `true` takes the defaults. Give the table
203
+ * `table-layout: fixed` (C-85). Defaults to `false`.
204
+ */
205
+ virtual?: boolean | VirtualOptions;
206
+ /**
207
+ * Ask for the next page (`update:query`, reason `page`) when the end of
208
+ * `rows` comes into view (C-88); append the rows of a `page` answer and
209
+ * replace them for any other reason. Needs `rowKey`. `true` takes the
210
+ * defaults. Defaults to `false`.
211
+ */
212
+ infinite?: boolean | InfiniteOptions;
213
+ }
214
+ /** Options of `virtual` (C-83 to C-87). */
215
+ export interface VirtualOptions {
216
+ /** Height of every row in pixels: nothing is measured (C-84). */
217
+ rowHeight?: number;
218
+ /** Height counted for a row not measured yet. Defaults to the first measured row, else `32`. */
219
+ estimateRowHeight?: number;
220
+ /** Rows drawn beyond each edge of the view. Defaults to `10`. */
221
+ overscan?: number;
222
+ /**
223
+ * The scroll container. Defaults to the nearest scrolling ancestor of the
224
+ * table, else the window (C-85).
225
+ */
226
+ scrollElement?: () => HTMLElement | null;
227
+ }
228
+ /** Options of `infinite` (C-88). */
229
+ export interface InfiniteOptions {
230
+ /** Ask for the next page when the last this many rows come near. Defaults to `5`. */
231
+ threshold?: number;
232
+ }
233
+ /** Options of `scrollToIndex` (C-87). */
234
+ export interface ScrollToIndexOptions {
235
+ /** Where the row ends up in the container. Defaults to `'auto'`: the nearest edge, nothing when in view. */
236
+ align?: 'start' | 'center' | 'end' | 'auto';
237
+ }
238
+ /** What the `load-more` slot receives (C-89). */
239
+ export interface LoadMoreSlotProps {
240
+ /** Ask for the next page now; nothing while `loading` or when `canLoadMore` is false. */
241
+ loadMore: () => void;
242
+ /** There is a next page (C-90). */
243
+ canLoadMore: boolean;
244
+ loading: boolean;
200
245
  }
201
246
  /**
202
247
  * Every human-readable text the table renders itself. A function receives
@@ -217,6 +262,14 @@ export interface TableLabels {
217
262
  resizeColumn: (column: string) => string;
218
263
  /** Name of a column's reorder handle. Default `` name => `Move ${name}` ``. */
219
264
  moveColumn: (column: string) => string;
265
+ /**
266
+ * The condition label under a filter input, and the `label` of each entry of
267
+ * `conditions` in the `filter-menu` slot. Receives the condition and the
268
+ * column type: one condition can read differently by type (`GreaterThan` is
269
+ * `'After (>)'` on a date). Default: the label in the protocol's
270
+ * `conditionOptions`, such as `'Contains'` or `'Greater Than (>)'`.
271
+ */
272
+ filterCondition: (condition: FilterCondition, type: ColumnType) => string;
220
273
  /** Bool filter option that removes the filter. Default `'All'`. */
221
274
  boolAll: string;
222
275
  /** Bool filter option for `true`. Default `'True'`. */
@@ -356,7 +409,7 @@ export interface FilterMenuSlotProps {
356
409
  rules: FilterRule[];
357
410
  /** Condition shown for the column: the first rule's, else the one picked, else `null`. */
358
411
  condition: FilterCondition | null;
359
- /** Conditions that make sense for the column type. */
412
+ /** Conditions that make sense for the column type, labelled by `labels.filterCondition`. */
360
413
  conditions: FilterConditionOption[];
361
414
  /**
362
415
  * Pick a condition. With a value typed the filter is applied; otherwise the
@@ -441,6 +494,11 @@ export interface TableSlots<T> {
441
494
  loading?(): unknown;
442
495
  /** Paging controls. The block is drawn only when this slot is given. */
443
496
  pagination?(props: PaginationSlotProps): unknown;
497
+ /**
498
+ * With `infinite`: the last row of the body while `loading` is off, in a
499
+ * `tr.qt-load-more-row`, for a "load more" or "try again" control (C-89).
500
+ */
501
+ 'load-more'?(props: LoadMoreSlotProps): unknown;
444
502
  /**
445
503
  * Header content of one column: `header-${column.field}`. It replaces the
446
504
  * sort button or the title only; the header cell, its filter row and its
@@ -470,4 +528,14 @@ export interface QueryTableExpose {
470
528
  * that has been emitted when the call returns.
471
529
  */
472
530
  flushPendingFilters(): void;
531
+ /**
532
+ * Scroll the row with this index in `rows` into view (C-87). Emits
533
+ * nothing; an index outside `rows` does nothing.
534
+ */
535
+ scrollToIndex(index: number, options?: ScrollToIndexOptions): void;
536
+ /**
537
+ * With `infinite`: ask for the next page now (C-89), as a retry after an
538
+ * error. Nothing while `loading` or when there is no next page.
539
+ */
540
+ loadMore(): void;
473
541
  }
@@ -4,3 +4,8 @@
4
4
  * Returns whether the element took focus.
5
5
  */
6
6
  export declare const focusFilterOf: (table: HTMLTableElement | null, field: string) => boolean;
7
+ /**
8
+ * Focuses the first filter of this table's header that takes the focus, in
9
+ * column order (C-22). Returns whether one did.
10
+ */
11
+ export declare const focusFirstFilter: (table: HTMLTableElement | null) => boolean;
@@ -1,10 +1,14 @@
1
- import type { CellContextMenuPayload, TableLabels, TableSlots } from '../contract.js';
2
- import type { BodyRow, ColumnEntry } from '../use-query-table.js';
1
+ import type { CellContextMenuPayload, LoadMoreSlotProps, TableLabels, TableSlots } from '../contract.js';
2
+ import type { ColumnEntry } from '../use-query-table.js';
3
+ import type { DrawnRow, SpacerRow } from '../virtual/use-row-window.js';
3
4
  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
5
  props: import("vue").PublicProps & __VLS_PrettifyLocal<{
5
6
  rows: T[];
6
- /** The rows in drawing order: pinned top, the others, pinned bottom (C-74). */
7
- bodyRows: BodyRow<T>[];
7
+ /**
8
+ * The rows in drawing order: pinned top, the others, pinned bottom (C-74);
9
+ * with `virtual` only the drawn ones, between spacers (C-83).
10
+ */
11
+ bodyRows: Array<DrawnRow<T> | SpacerRow>;
8
12
  /** Pin a row or unpin it (C-74). */
9
13
  pinRow: (row: T, index: number, position: "top" | "bottom" | false) => void;
10
14
  /** The consumer is fetching: no empty row, the `loading` row instead (C-52). */
@@ -29,6 +33,8 @@ declare const __VLS_export: <T extends object>(__VLS_props: NonNullable<Awaited<
29
33
  labels: TableLabels;
30
34
  /** The consumer listens to `cellContextMenu` (C-28); read at event time. */
31
35
  hasContextMenuListener: () => boolean;
36
+ /** With `infinite`: what the `load-more` slot receives, else `null` (C-89). */
37
+ loadMore: LoadMoreSlotProps | null;
32
38
  } & {
33
39
  onRowRightPanelClick?: ((row: T) => any) | undefined;
34
40
  onCellContextMenu?: ((payload: CellContextMenuPayload<T>) => any) | undefined;
@@ -9,6 +9,8 @@ type __VLS_Props = {
9
9
  hasPinned: boolean;
10
10
  /** `--qt-pin-left` or `--qt-pin-right` of each pinned cell, by key (C-47, C-71). */
11
11
  offsets: Readonly<Record<string, number>>;
12
+ /** With `virtual`: `aria-rowindex` of the first footer row (C-86). */
13
+ firstRowIndex?: number;
12
14
  };
13
15
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
14
16
  declare const _default: typeof __VLS_export;
@@ -0,0 +1,46 @@
1
+ /** A half-open range of item positions: `start` drawn, `end` not. */
2
+ export interface WindowRange {
3
+ start: number;
4
+ end: number;
5
+ }
6
+ export interface WindowInput {
7
+ /**
8
+ * The top of every item from the top of the first one, and last the total
9
+ * height: `count + 1` numbers, never decreasing.
10
+ */
11
+ offsets: ArrayLike<number>;
12
+ /** The top of the view, from the top of the first item. May be negative. */
13
+ scrollTop: number;
14
+ viewportHeight: number;
15
+ /** Items drawn beyond each edge of the view. */
16
+ overscan: number;
17
+ }
18
+ /**
19
+ * Fills `offsets` from `heights`, starting at position `from` (the offsets
20
+ * before it are kept): `offsets[i + 1] = offsets[i] + heights[i]`.
21
+ */
22
+ export declare const fillOffsets: (heights: ArrayLike<number>, offsets: Float64Array, from?: number) => void;
23
+ /**
24
+ * The item that holds the point `y`: the last position whose top is at most
25
+ * `y`, clamped to the items (0 for a point above them, the last item for a
26
+ * point below them). `-1` when there is no item.
27
+ */
28
+ export declare const indexAt: (offsets: ArrayLike<number>, y: number) => number;
29
+ /** The items to draw: the ones in view and `overscan` more on each side. */
30
+ export declare const computeWindow: ({ offsets, scrollTop, viewportHeight, overscan }: WindowInput) => WindowRange;
31
+ /** A run of drawn items, or a spacer that stands for the items left out. */
32
+ export type Segment = {
33
+ from: number;
34
+ to: number;
35
+ } | {
36
+ spacer: number;
37
+ slot: 0 | 1 | 2;
38
+ };
39
+ /**
40
+ * The body between the pinned rows: an upper spacer, the drawn items and a
41
+ * lower spacer. A `kept` item outside the range (it holds the focus, C-86)
42
+ * is drawn on its own, with a spacer of its own between it and the range.
43
+ * Spacers of height 0 are left out. `slot` names a spacer's place, so a
44
+ * spacer keeps its identity while its height changes.
45
+ */
46
+ export declare const segmentsOf: (offsets: ArrayLike<number>, range: WindowRange, kept: number | null) => Segment[];
@@ -0,0 +1,35 @@
1
+ import { type PageCursors, type Query } from '@dolusoft/query-protocol';
2
+ import { type ShallowRef } from 'vue';
3
+ import type { InfiniteOptions } from '../contract.js';
4
+ export interface LoadMoreOptions {
5
+ infinite: () => boolean | InfiniteOptions | undefined;
6
+ rowKey: () => unknown;
7
+ rows: () => readonly unknown[];
8
+ query: () => Query;
9
+ totalRows: () => number | null;
10
+ cursors: () => PageCursors | null;
11
+ loading: () => boolean;
12
+ /** The next page action (C-05, C-56). */
13
+ nextPage: () => void;
14
+ table: ShallowRef<HTMLTableElement | null>;
15
+ /** The body is virtual (C-83). */
16
+ virtual: () => boolean;
17
+ /**
18
+ * With `virtual`: the end of the drawn window among the center rows, and
19
+ * their number; `null` until the window was laid out (C-83).
20
+ */
21
+ window: () => {
22
+ end: number;
23
+ count: number;
24
+ } | null;
25
+ }
26
+ /**
27
+ * Infinite scroll (C-88 to C-90): whether there is more to load, the
28
+ * automatic request near the end of `rows` and `loadMore`. The rows are
29
+ * the consumer's; the table only emits the next page action.
30
+ */
31
+ export declare const useLoadMore: (o: LoadMoreOptions) => {
32
+ enabled: import("vue").ComputedRef<boolean>;
33
+ canLoadMore: import("vue").ComputedRef<boolean>;
34
+ loadMore: () => void;
35
+ };
@@ -0,0 +1,38 @@
1
+ import { type ShallowRef } from 'vue';
2
+ import type { ScrollToIndexOptions, VirtualOptions } from '../contract.js';
3
+ import type { BodyRow } from '../use-query-table.js';
4
+ import { type WindowRange } from './compute-window.js';
5
+ /** A row the body draws, with its `aria-rowindex` when the body is virtual. */
6
+ export type DrawnRow<T> = BodyRow<T> & {
7
+ aria?: number;
8
+ };
9
+ /** A spacer row: the height of the items it stands for (C-83). */
10
+ export interface SpacerRow {
11
+ spacer: number;
12
+ key: symbol;
13
+ }
14
+ export interface RowWindowOptions<T> {
15
+ virtual: () => boolean | VirtualOptions | undefined;
16
+ table: ShallowRef<HTMLTableElement | null>;
17
+ /** The rows in drawing order: pinned top, the others, pinned bottom (C-74). */
18
+ bodyRows: () => BodyRow<T>[];
19
+ keyOf: (row: T, index: number) => string | number;
20
+ isExpanded: (row: T, index: number) => boolean;
21
+ }
22
+ /**
23
+ * The virtual body (C-83 to C-87): which rows are drawn, the spacers that
24
+ * stand for the others, the measured heights, the focused row kept drawn,
25
+ * printing and `scrollToIndex`. Without `virtual` it draws `bodyRows` as
26
+ * they are and touches no DOM.
27
+ */
28
+ export declare const useRowWindow: <T extends object>(o: RowWindowOptions<T>) => {
29
+ enabled: () => boolean;
30
+ drawn: import("vue").ComputedRef<(SpacerRow | DrawnRow<T>)[]>;
31
+ range: ShallowRef<WindowRange, WindowRange>;
32
+ ready: ShallowRef<boolean, boolean>;
33
+ centerCount: () => number;
34
+ expandedCount: () => number;
35
+ scrollToIndex: (index: number, options?: ScrollToIndexOptions) => void;
36
+ onFocusIn: (event: FocusEvent) => void;
37
+ onFocusOut: (event: FocusEvent) => void;
38
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolusoft/query-table",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
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",
@@ -45,8 +45,8 @@
45
45
  ],
46
46
  "license": "MIT",
47
47
  "dependencies": {
48
- "@dolusoft/query-protocol": "3.1.0",
49
- "@dolusoft/query-table-core": "3.1.0",
48
+ "@dolusoft/query-protocol": "3.2.1",
49
+ "@dolusoft/query-table-core": "3.2.1",
50
50
  "@tanstack/vue-table": "9.2.6"
51
51
  },
52
52
  "devDependencies": {