@dolusoft/query-table 3.18.0 → 3.20.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.
Files changed (35) hide show
  1. package/dist/cells.js +218 -0
  2. package/dist/cells.js.map +1 -0
  3. package/dist/data-table.js +283 -0
  4. package/dist/data-table.js.map +1 -0
  5. package/dist/local-DDJEp4Nn.js +88 -0
  6. package/dist/local-DDJEp4Nn.js.map +1 -0
  7. package/dist/local.js +1 -87
  8. package/dist/query-table.js +1 -4833
  9. package/dist/src-Cam4kRTd.js +4919 -0
  10. package/dist/src-Cam4kRTd.js.map +1 -0
  11. package/dist/table-context-Duuqp9Jq.js +28 -0
  12. package/dist/table-context-Duuqp9Jq.js.map +1 -0
  13. package/dist/types/cells/cell-action.vue.d.ts +16 -0
  14. package/dist/types/cells/cell-actions.vue.d.ts +13 -0
  15. package/dist/types/cells/cell-badge.vue.d.ts +17 -0
  16. package/dist/types/cells/cell-copy.vue.d.ts +8 -0
  17. package/dist/types/cells/cell-preview.vue.d.ts +8 -0
  18. package/dist/types/cells/cell-stack.vue.d.ts +16 -0
  19. package/dist/types/cells/cell-value.vue.d.ts +4 -0
  20. package/dist/types/cells/contract.d.ts +44 -0
  21. package/dist/types/cells/index.d.ts +8 -0
  22. package/dist/types/contract.d.ts +59 -1
  23. package/dist/types/core/cell-labels.d.ts +10 -0
  24. package/dist/types/core/table-context.d.ts +2 -0
  25. package/dist/types/core/table-labels.d.ts +9 -0
  26. package/dist/types/data-table/contract.d.ts +64 -0
  27. package/dist/types/data-table/data-table.vue.d.ts +31 -0
  28. package/dist/types/data-table/derive-dataset.d.ts +32 -0
  29. package/dist/types/data-table/index.d.ts +4 -0
  30. package/dist/types/query-table.vue.d.ts +2 -1
  31. package/dist/types/use-query-table.d.ts +21 -3
  32. package/dist/types/virtual/use-row-window.d.ts +2 -0
  33. package/package.json +11 -3
  34. package/dist/local.js.map +0 -1
  35. package/dist/query-table.js.map +0 -1
@@ -0,0 +1,28 @@
1
+ import { inject, provide } from "vue";
2
+ //#region src/core/cell-labels.ts
3
+ /**
4
+ * English defaults of the cell labels. This module imports nothing but
5
+ * types, so the `/cells` entry carries these three and not the defaults of
6
+ * the table, whose condition labels come from the protocol (ADR 0022,
7
+ * K320-6).
8
+ */
9
+ var cellLabelDefaults = {
10
+ copyValue: (value) => `Copy ${value}`,
11
+ previewValue: (text) => `Preview ${text}`,
12
+ emptyValue: "-"
13
+ };
14
+ //#endregion
15
+ //#region src/core/table-context.ts
16
+ var tableContextKey = Symbol("query-table");
17
+ var provideTableContext = (context) => {
18
+ provide(tableContextKey, context);
19
+ };
20
+ var useTableContext = () => {
21
+ const context = inject(tableContextKey);
22
+ if (!context) throw new Error("Header parts must be rendered inside a QueryTable");
23
+ return context;
24
+ };
25
+ //#endregion
26
+ export { cellLabelDefaults as i, tableContextKey as n, useTableContext as r, provideTableContext as t };
27
+
28
+ //# sourceMappingURL=table-context-Duuqp9Jq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-context-Duuqp9Jq.js","names":[],"sources":["../src/core/cell-labels.ts","../src/core/table-context.ts"],"sourcesContent":["import type { TableLabels } from '../contract'\n\n/** The texts the cell components write (C-129), every one filled. */\nexport type CellLabels = Required<\n Pick<TableLabels, 'copyValue' | 'previewValue' | 'emptyValue'>\n>\n\n/**\n * English defaults of the cell labels. This module imports nothing but\n * types, so the `/cells` entry carries these three and not the defaults of\n * the table, whose condition labels come from the protocol (ADR 0022,\n * K320-6).\n */\nexport const cellLabelDefaults: CellLabels = {\n copyValue: value => `Copy ${value}`,\n previewValue: text => `Preview ${text}`,\n emptyValue: '-'\n}\n","import { inject, provide, type InjectionKey } from 'vue'\n\nimport type { ResolvedLabels } from './labels'\nimport type { ColumnReorder } from '../reorder/use-column-reorder'\nimport type { ColumnResize } from '../resize/use-column-resize'\nimport type {\n QueryTableFilters,\n QueryTableLayout,\n QueryTableSelection,\n QueryTableSort\n} from '../use-query-table'\n\n/**\n * What the header parts call: the filter inputs, the sort gate and the\n * layout actions of the composable, the resize and reorder actions and the\n * labels. Only actions and getters travel here; data (`columns`, `query`)\n * comes down as props.\n */\nexport interface TableContext {\n filters: QueryTableFilters\n sort: QueryTableSort\n /** The `control` of the header and filter-menu slots (C-70). */\n layout: QueryTableLayout\n resize: ColumnResize\n /** The reorder handles: drag, keys and the drag preview (C-73). */\n reorder: ColumnReorder\n /** The select-all checkbox of the selection column (C-59). */\n selection: Pick<\n QueryTableSelection<object>,\n 'allSelected' | 'someSelected' | 'toggleAll'\n >\n labels: () => ResolvedLabels\n}\n\nexport const tableContextKey: InjectionKey<TableContext> = Symbol('query-table')\n\nexport const provideTableContext = (context: TableContext) => {\n provide(tableContextKey, context)\n}\n\nexport const useTableContext = (): TableContext => {\n const context = inject(tableContextKey)\n if (!context) {\n throw new Error('Header parts must be rendered inside a QueryTable')\n }\n return context\n}\n"],"mappings":";;;;;;;;AAaA,IAAa,oBAAgC;CAC3C,YAAW,UAAS,QAAQ;CAC5B,eAAc,SAAQ,WAAW;CACjC,YAAY;AACd;;;ACiBA,IAAa,kBAA8C,OAAO,aAAa;AAE/E,IAAa,uBAAuB,YAA0B;CAC5D,QAAQ,iBAAiB,OAAO;AAClC;AAEA,IAAa,wBAAsC;CACjD,MAAM,UAAU,OAAO,eAAe;CACtC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,mDAAmD;CAErE,OAAO;AACT"}
@@ -0,0 +1,16 @@
1
+ import type { CellActionProps } from './contract.js';
2
+ type __VLS_Slots = {
3
+ /** The button's text, the consumer's content (C-129). */
4
+ default?(): unknown;
5
+ };
6
+ declare const __VLS_base: import("vue").DefineComponent<CellActionProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CellActionProps> & Readonly<{}>, {
7
+ kind: import("./contract.js").CellActionKind;
8
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
10
+ declare const _default: typeof __VLS_export;
11
+ export default _default;
12
+ type __VLS_WithSlots<T, S> = T & {
13
+ new (): {
14
+ $slots: S;
15
+ };
16
+ };
@@ -0,0 +1,13 @@
1
+ type __VLS_Slots = {
2
+ /** The `CellAction` buttons. */
3
+ default?(): unknown;
4
+ };
5
+ declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
9
+ type __VLS_WithSlots<T, S> = T & {
10
+ new (): {
11
+ $slots: S;
12
+ };
13
+ };
@@ -0,0 +1,17 @@
1
+ import type { CellBadgeProps } from './contract.js';
2
+ type __VLS_Slots = {
3
+ /** Replaces `text`. */
4
+ default?(): unknown;
5
+ };
6
+ declare const __VLS_base: import("vue").DefineComponent<CellBadgeProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CellBadgeProps> & Readonly<{}>, {
7
+ text: string | number;
8
+ tone: import("./contract.js").CellBadgeTone;
9
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
13
+ type __VLS_WithSlots<T, S> = T & {
14
+ new (): {
15
+ $slots: S;
16
+ };
17
+ };
@@ -0,0 +1,8 @@
1
+ import type { CellCopyProps } from './contract.js';
2
+ declare const __VLS_export: import("vue").DefineComponent<CellCopyProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
3
+ copy: (value: string) => any;
4
+ }, string, import("vue").PublicProps, Readonly<CellCopyProps> & Readonly<{
5
+ onCopy?: ((value: string) => any) | undefined;
6
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import type { CellPreviewProps } from './contract.js';
2
+ declare const __VLS_export: import("vue").DefineComponent<CellPreviewProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
3
+ preview: (text: string) => any;
4
+ }, string, import("vue").PublicProps, Readonly<CellPreviewProps> & Readonly<{
5
+ onPreview?: ((text: string) => any) | undefined;
6
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import type { CellStackProps } from './contract.js';
2
+ type __VLS_Slots = {
3
+ /** Replaces `primary`. */
4
+ primary?(): unknown;
5
+ /** Replaces `secondary`. */
6
+ secondary?(): unknown;
7
+ };
8
+ declare const __VLS_base: import("vue").DefineComponent<CellStackProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CellStackProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
10
+ declare const _default: typeof __VLS_export;
11
+ export default _default;
12
+ type __VLS_WithSlots<T, S> = T & {
13
+ new (): {
14
+ $slots: S;
15
+ };
16
+ };
@@ -0,0 +1,4 @@
1
+ import type { CellValueProps } from './contract.js';
2
+ declare const __VLS_export: import("vue").DefineComponent<CellValueProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<CellValueProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
3
+ declare const _default: typeof __VLS_export;
4
+ export default _default;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Public contract of the cell components (`@dolusoft/query-table/cells`,
3
+ * ADR 0022). Unstyled markup for what the product's cells draw; each
4
+ * component's hooks are in `contract/dom.ts` (C-128) and its texts come from
5
+ * the `labels` of the table it sits in (C-129).
6
+ */
7
+ /** What a `CellBadge` says, not how it looks (C-128). */
8
+ export type CellBadgeTone = 'neutral' | 'info' | 'success' | 'warning' | 'danger';
9
+ /** What a `CellAction` does, not how it looks (C-128). */
10
+ export type CellActionKind = 'default' | 'primary' | 'danger';
11
+ /** Props of `CellStack`: two lines, a primary over a secondary. */
12
+ export interface CellStackProps {
13
+ /** The first line. The `primary` slot replaces it. */
14
+ primary?: string | number | null;
15
+ /** The second line, drawn only when given. The `secondary` slot replaces it. */
16
+ secondary?: string | number | null;
17
+ }
18
+ /** Props of `CellCopy`: a value with a button that asks to copy it. */
19
+ export interface CellCopyProps {
20
+ /** The value shown and emitted with `copy`. */
21
+ value: string | number;
22
+ }
23
+ /** Props of `CellPreview`: a text with a button that asks to preview it. */
24
+ export interface CellPreviewProps {
25
+ /** The text shown and emitted with `preview`. */
26
+ text: string | number;
27
+ }
28
+ /** Props of `CellBadge`: a short status. */
29
+ export interface CellBadgeProps {
30
+ /** The text. The default slot replaces it. */
31
+ text?: string | number;
32
+ /** Defaults to `'neutral'`. */
33
+ tone?: CellBadgeTone;
34
+ }
35
+ /** Props of `CellValue`: a value, or the empty-value label when there is none. */
36
+ export interface CellValueProps {
37
+ /** `null`, `undefined` and `''` draw `labels.emptyValue` (C-129). */
38
+ value?: unknown;
39
+ }
40
+ /** Props of `CellAction`: one button of a `CellActions` group. */
41
+ export interface CellActionProps {
42
+ /** Defaults to `'default'`. */
43
+ kind?: CellActionKind;
44
+ }
@@ -0,0 +1,8 @@
1
+ export { default as CellAction } from './cell-action.vue.js';
2
+ export { default as CellActions } from './cell-actions.vue.js';
3
+ export { default as CellBadge } from './cell-badge.vue.js';
4
+ export { default as CellCopy } from './cell-copy.vue.js';
5
+ export { default as CellPreview } from './cell-preview.vue.js';
6
+ export { default as CellStack } from './cell-stack.vue.js';
7
+ export { default as CellValue } from './cell-value.vue.js';
8
+ export type { CellActionKind, CellActionProps, CellBadgeProps, CellBadgeTone, CellCopyProps, CellPreviewProps, CellStackProps, CellValueProps } from './contract.js';
@@ -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`. */
@@ -447,6 +479,22 @@ export interface TableLabels {
447
479
  selectRow: string;
448
480
  /** Name of the checkbox that selects every row of the page. Default `'Select all rows'`. */
449
481
  selectAllRows: string;
482
+ /**
483
+ * Name of the copy button of `CellCopy` (`/cells`, C-129). Default
484
+ * `` value => `Copy ${value}` ``. Optional (3.20), so a complete
485
+ * `TableLabels` of 3.19 still type-checks.
486
+ */
487
+ copyValue?: (value: string) => string;
488
+ /**
489
+ * Name of the preview button of `CellPreview` (`/cells`, C-129). Default
490
+ * `` text => `Preview ${text}` ``. Optional (3.20), like `copyValue`.
491
+ */
492
+ previewValue?: (text: string) => string;
493
+ /**
494
+ * The text `CellValue` (`/cells`, C-129) draws for an empty value. Default
495
+ * `'-'`. Optional (3.20), like `copyValue`.
496
+ */
497
+ emptyValue?: string;
450
498
  }
451
499
  /** Payload of the `cellContextMenu` event. */
452
500
  export interface CellContextMenuPayload<T> {
@@ -547,6 +595,16 @@ export type TableEmits<T, Q extends Query = TableQuery> = {
547
595
  * emit it.
548
596
  */
549
597
  rowFocus: [payload: RowFocusPayload<T>];
598
+ /**
599
+ * With `hasSubtable`: the user opened or closed a row with its expand
600
+ * button (C-122), once per press; with `expandMode: 'single'` a press
601
+ * that closes the open row emits for it first (C-123). The state stays
602
+ * the table's (C-26):
603
+ * `isExpanded`, the pruning when `rows` change, `expandAll()`,
604
+ * `collapseAll()` and a row leaving the window of a `virtual` body emit
605
+ * nothing.
606
+ */
607
+ rowExpansionChange: [payload: RowExpansionPayload<T>];
550
608
  };
551
609
  export interface CellSlotProps<T> {
552
610
  row: T;
@@ -0,0 +1,10 @@
1
+ import type { TableLabels } from '../contract.js';
2
+ /** The texts the cell components write (C-129), every one filled. */
3
+ export type CellLabels = Required<Pick<TableLabels, 'copyValue' | 'previewValue' | 'emptyValue'>>;
4
+ /**
5
+ * English defaults of the cell labels. This module imports nothing but
6
+ * types, so the `/cells` entry carries these three and not the defaults of
7
+ * the table, whose condition labels come from the protocol (ADR 0022,
8
+ * K320-6).
9
+ */
10
+ export declare const cellLabelDefaults: CellLabels;
@@ -1,3 +1,4 @@
1
+ import { type InjectionKey } from 'vue';
1
2
  import type { ResolvedLabels } from './labels.js';
2
3
  import type { ColumnReorder } from '../reorder/use-column-reorder.js';
3
4
  import type { ColumnResize } from '../resize/use-column-resize.js';
@@ -20,5 +21,6 @@ export interface TableContext {
20
21
  selection: Pick<QueryTableSelection<object>, 'allSelected' | 'someSelected' | 'toggleAll'>;
21
22
  labels: () => ResolvedLabels;
22
23
  }
24
+ export declare const tableContextKey: InjectionKey<TableContext>;
23
25
  export declare const provideTableContext: (context: TableContext) => void;
24
26
  export declare const useTableContext: () => TableContext;
@@ -0,0 +1,9 @@
1
+ import { type CellLabels } from './cell-labels.js';
2
+ /**
3
+ * The cell labels of the table a component sits in, read again on every
4
+ * call so they follow the table's `labels` prop. An entry the table leaves
5
+ * out, or gives as `undefined`, is the English default; outside a table
6
+ * every entry is (C-129). The one module of the main part the cell
7
+ * components import (ADR 0022, K320-6).
8
+ */
9
+ export declare const useCellLabels: () => (() => CellLabels);
@@ -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>;
@@ -0,0 +1,4 @@
1
+ import DataTable from './data-table.vue.js';
2
+ export { DataTable };
3
+ export default DataTable;
4
+ export type { DataTableEmits, DataTableOmittedProp, DataTableProps, DataTableSlots, ErrorSlotProps } from './contract.js';
@@ -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
- /** Opens or closes the row; nothing for a row that cannot expand (C-98). */
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
- /** Opens every row given that can expand; nothing is fetched. */
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.18.0",
3
+ "version": "3.20.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,14 @@
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"
25
+ },
26
+ "./cells": {
27
+ "types": "./dist/types/cells/index.d.ts",
28
+ "default": "./dist/cells.js"
21
29
  }
22
30
  },
23
31
  "engines": {
@@ -45,8 +53,8 @@
45
53
  ],
46
54
  "license": "MIT",
47
55
  "dependencies": {
48
- "@dolusoft/query-protocol": "3.18.0",
49
- "@dolusoft/query-table-core": "3.18.0",
56
+ "@dolusoft/query-protocol": "3.20.0",
57
+ "@dolusoft/query-table-core": "3.20.0",
50
58
  "@tanstack/vue-table": "9.2.6"
51
59
  },
52
60
  "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"}