@ember-joinery/data-table 0.0.0-stage → 1.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.
- package/CHANGELOG.md +140 -0
- package/LICENSE.md +9 -0
- package/NOTICE +532 -0
- package/README.md +79 -2
- package/addon-main.cjs +4 -0
- package/declarations/-private/bound-methods.d.ts +23 -0
- package/declarations/-private/bound-methods.d.ts.map +1 -0
- package/declarations/-private/reactivity.d.ts +9 -0
- package/declarations/-private/reactivity.d.ts.map +1 -0
- package/declarations/components/data-table.d.ts +77 -0
- package/declarations/components/data-table.d.ts.map +1 -0
- package/declarations/components/flex-render.d.ts +103 -0
- package/declarations/components/flex-render.d.ts.map +1 -0
- package/declarations/index.d.ts +7 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/table-core.d.ts +7 -0
- package/declarations/table-core.d.ts.map +1 -0
- package/declarations/table.d.ts +65 -0
- package/declarations/table.d.ts.map +1 -0
- package/declarations/test-support/data-table.d.ts +111 -0
- package/declarations/test-support/data-table.d.ts.map +1 -0
- package/declarations/test-support/index.d.ts +2 -0
- package/declarations/test-support/index.d.ts.map +1 -0
- package/declarations/test-support.d.ts +2 -0
- package/dist/components/data-table.js +107 -0
- package/dist/components/data-table.js.map +1 -0
- package/dist/components/flex-render.js +104 -0
- package/dist/components/flex-render.js.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/table-core.js +2 -0
- package/dist/table-core.js.map +1 -0
- package/dist/table.js +300 -0
- package/dist/table.js.map +1 -0
- package/dist/test-support.js +304 -0
- package/dist/test-support.js.map +1 -0
- package/package.json +116 -3
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { type TagName } from '@ember-joinery/primitives/as';
|
|
3
|
+
import { type PartModifier } from '@ember-joinery/primitives/part';
|
|
4
|
+
import type { RowData, Table, TableFeatures } from '@tanstack/table-core';
|
|
5
|
+
import FlexRender from './flex-render';
|
|
6
|
+
/** What `dt.head` reads of a header, whatever its table's features. */
|
|
7
|
+
export interface DataTableHeader {
|
|
8
|
+
isPlaceholder: boolean;
|
|
9
|
+
colSpan: number;
|
|
10
|
+
column: {
|
|
11
|
+
id: string;
|
|
12
|
+
/** From the sorting feature: `asc`, `desc`, or `false`. */
|
|
13
|
+
getIsSorted?: () => false | 'asc' | 'desc';
|
|
14
|
+
/** From the sorting feature: the column's place among the sorts. */
|
|
15
|
+
getSortIndex?: () => number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** What `dt.row` reads of a row. */
|
|
19
|
+
export interface DataTableRow {
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
22
|
+
/** What the column's sort is, as `aria-sort` says it: only the first sort, as ARIA asks. */
|
|
23
|
+
export declare function ariaSort(header: DataTableHeader): 'ascending' | 'descending' | undefined;
|
|
24
|
+
/** What a `<DataTable>` yields: its table, `FlexRender`, and a modifier for each part. */
|
|
25
|
+
export interface DataTableParts<TFeatures extends TableFeatures, TData extends RowData> {
|
|
26
|
+
/** The table it was given. */
|
|
27
|
+
table: Table<TFeatures, TData>;
|
|
28
|
+
/** Renders a header, cell or footer from its column definition. */
|
|
29
|
+
FlexRender: typeof FlexRender;
|
|
30
|
+
/** On each header cell (`<t.Head {{dt.head header}}>`): its `aria-sort` and `colspan`. */
|
|
31
|
+
head: PartModifier<HTMLTableCellElement, Record<string, never>, [DataTableHeader]>;
|
|
32
|
+
/** On each body row (`<t.Row {{dt.row row}}>`). */
|
|
33
|
+
row: PartModifier<HTMLElement, Record<string, never>, [DataTableRow]>;
|
|
34
|
+
/** On a column's filter input (`<Input {{dt.filter "email"}}>`). */
|
|
35
|
+
filter: PartModifier<HTMLElement, Record<string, never>, [string?]>;
|
|
36
|
+
/** On the button that goes back a page. */
|
|
37
|
+
previousPage: PartModifier<HTMLElement>;
|
|
38
|
+
/** On the button that goes on a page. */
|
|
39
|
+
nextPage: PartModifier<HTMLElement>;
|
|
40
|
+
/** On the dropdown menu that shows and hides columns (`<DropdownMenu {{dt.viewOptions}}>`). */
|
|
41
|
+
viewOptions: PartModifier<HTMLElement>;
|
|
42
|
+
}
|
|
43
|
+
export interface DataTableSignature<TFeatures extends TableFeatures, TData extends RowData> {
|
|
44
|
+
Args: {
|
|
45
|
+
/** The table, from `createTable()`. */
|
|
46
|
+
table: Table<TFeatures, TData>;
|
|
47
|
+
/** Its name, for its harness (`data-test-jn-name`). */
|
|
48
|
+
name?: string;
|
|
49
|
+
/** The tag to render. Default `div`. */
|
|
50
|
+
as?: TagName;
|
|
51
|
+
};
|
|
52
|
+
Blocks: {
|
|
53
|
+
/** What goes around the table (a filter, the column menu, pagination) and the table. */
|
|
54
|
+
default: [DataTableParts<TFeatures, TData>];
|
|
55
|
+
};
|
|
56
|
+
Element: HTMLElement;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The element around a data table and the controls that work it: upstream's
|
|
60
|
+
* `<div className="w-full">`, which `DataTableHarness` scopes to. It renders nothing of its
|
|
61
|
+
* own, but it yields the modifiers that mark each part for the harness, and that give the
|
|
62
|
+
* header cells their `aria-sort`, which upstream's leave out:
|
|
63
|
+
*
|
|
64
|
+
* <DataTable @table={{this.table}} class="w-full" as |dt|>
|
|
65
|
+
* <Input placeholder="Filter emails..." {{dt.filter "email"}} … />
|
|
66
|
+
* <Table as |t|>
|
|
67
|
+
* …<t.Head {{dt.head header}}><dt.FlexRender @header={{header}} /></t.Head>
|
|
68
|
+
* …<t.Row {{dt.row row}}>…</t.Row>
|
|
69
|
+
* </Table>
|
|
70
|
+
* <Button {{dt.previousPage}} …>Previous</Button>
|
|
71
|
+
* <Button {{dt.nextPage}} …>Next</Button>
|
|
72
|
+
* </DataTable>
|
|
73
|
+
*/
|
|
74
|
+
export default class DataTable<TFeatures extends TableFeatures, TData extends RowData> extends Component<DataTableSignature<TFeatures, TData>> {
|
|
75
|
+
get id(): string;
|
|
76
|
+
}
|
|
77
|
+
//# sourceM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AClF,mDAAmD;IACnD,GAAG,EAAE,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IACrE,oEAAoE;IACpE,MAAM,EAAE,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACnE,2CAA2C;IAC3C,YAAY,EAAE,YAAY,CAAC,WAAW,CAAC,CAAA;IACvC,yCAAyC;IACzC,QAAQ,EAAE,YAAY,CAAC,WAAW,CAAC,CAAA;IACnC,+FAA+F;IAC/F,WAAW,EAAE,YAAY,CAAC,WAAW,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,kBAAkB,CAAC,SAAS,SAAS,aAAa,EAAE,KAAK,SAAS,OAAO;IACxF,IAAI,EAAE;QACJ,uCAAuC;QACvC,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QAC9B,uDAAuD;QACvD,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,wCAAwC;QACxC,EAAE,CAAC,EAAE,OAAO,CAAA;KACb,CAAA;IACD,MAAM,EAAE;QACN,wFAAwF;QACxF,OAAO,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;KAC5C,CAAA;IACD,OAAO,EAAE,WAAW,CAAA;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS,CAC5B,SAAS,SAAS,aAAa,EAC/B,KAAK,SAAS,OAAO,CACrB,SAAQ,SAAS,CAAC,kBAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACvD,IAAI,EAAE,IAAI,MAAM,CAEf;CAiCF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { type SafeString } from '@ember/template';
|
|
3
|
+
import type { ComponentLike } from '@glint/template';
|
|
4
|
+
import type { CellContext, CellData, HeaderContext, RowData, TableFeatures } from '@tanstack/table-core';
|
|
5
|
+
/**
|
|
6
|
+
* What a FlexRender reads of a cell, whatever its table's features: its column's definition and
|
|
7
|
+
* its context (and, with column grouping, whether it is aggregated or a placeholder).
|
|
8
|
+
*/
|
|
9
|
+
export interface FlexCell {
|
|
10
|
+
column: {
|
|
11
|
+
columnDef: object;
|
|
12
|
+
};
|
|
13
|
+
getContext(): object;
|
|
14
|
+
getIsAggregated?: () => boolean;
|
|
15
|
+
getIsPlaceholder?: () => boolean;
|
|
16
|
+
}
|
|
17
|
+
/** What a FlexRender reads of a header or footer: its column's definition and its context. */
|
|
18
|
+
export interface FlexHeader {
|
|
19
|
+
column: {
|
|
20
|
+
columnDef: object;
|
|
21
|
+
};
|
|
22
|
+
getContext(): object;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The arguments a component in a column's `cell` gets: the cell's context, and each of its
|
|
26
|
+
* members on its own, as a React cell function destructures them (`({ row }) => …`).
|
|
27
|
+
*/
|
|
28
|
+
export interface CellComponentArgs<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> {
|
|
29
|
+
/** The whole context, as table-core's `cell.getContext()` makes it. */
|
|
30
|
+
context: CellContext<TFeatures, TData, TValue>;
|
|
31
|
+
table: CellContext<TFeatures, TData, TValue>['table'];
|
|
32
|
+
column: CellContext<TFeatures, TData, TValue>['column'];
|
|
33
|
+
row: CellContext<TFeatures, TData, TValue>['row'];
|
|
34
|
+
cell: CellContext<TFeatures, TData, TValue>['cell'];
|
|
35
|
+
/** The cell's value. */
|
|
36
|
+
getValue: CellContext<TFeatures, TData, TValue>['getValue'];
|
|
37
|
+
/** The cell's value, or the table's `renderFallbackValue` where it has none. */
|
|
38
|
+
renderValue: CellContext<TFeatures, TData, TValue>['renderValue'];
|
|
39
|
+
}
|
|
40
|
+
/** The arguments a component in a column's `header` or `footer` gets. */
|
|
41
|
+
export interface HeaderComponentArgs<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> {
|
|
42
|
+
/** The whole context, as table-core's `header.getContext()` makes it. */
|
|
43
|
+
context: HeaderContext<TFeatures, TData, TValue>;
|
|
44
|
+
table: HeaderContext<TFeatures, TData, TValue>['table'];
|
|
45
|
+
column: HeaderContext<TFeatures, TData, TValue>['column'];
|
|
46
|
+
header: HeaderContext<TFeatures, TData, TValue>['header'];
|
|
47
|
+
}
|
|
48
|
+
/** A component for a column's `cell`: `cell: flexComponent(StatusCell)`. */
|
|
49
|
+
export interface CellComponentSignature<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> {
|
|
50
|
+
Args: CellComponentArgs<TFeatures, TData, TValue>;
|
|
51
|
+
}
|
|
52
|
+
/** A component for a column's `header` or `footer`: `header: flexComponent(SelectAll)`. */
|
|
53
|
+
export interface HeaderComponentSignature<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> {
|
|
54
|
+
Args: HeaderComponentArgs<TFeatures, TData, TValue>;
|
|
55
|
+
}
|
|
56
|
+
type AnyContext = Record<string, unknown>;
|
|
57
|
+
type Rendered = ComponentLike<{
|
|
58
|
+
Args: Record<string, unknown>;
|
|
59
|
+
}>;
|
|
60
|
+
/** Whether a value is a component: one with a template, or a class (whose template it inherits). */
|
|
61
|
+
export declare function isComponent(value: unknown): value is Rendered;
|
|
62
|
+
/**
|
|
63
|
+
* A column's `header`, `cell` or `footer` as a component: `cell: flexComponent(StatusCell)`.
|
|
64
|
+
* The component gets the context and each of its members as arguments (`@row`, `@column`,
|
|
65
|
+
* `@table`… see `CellComponentArgs` and `HeaderComponentArgs`). table-core's types take a
|
|
66
|
+
* string or a function there, so this hands it a function that returns the component, which
|
|
67
|
+
* `FlexRender` renders. It takes any context, since table-core checks a column's template
|
|
68
|
+
* against the column's own value type.
|
|
69
|
+
*/
|
|
70
|
+
export declare function flexComponent(component: object): (context: any) => unknown;
|
|
71
|
+
/** What a FlexRender draws: a component with its arguments, or a value as text. */
|
|
72
|
+
interface Resolved {
|
|
73
|
+
component?: Rendered;
|
|
74
|
+
args?: AnyContext;
|
|
75
|
+
text?: string | number | SafeString;
|
|
76
|
+
}
|
|
77
|
+
export interface FlexRenderSignature {
|
|
78
|
+
Args: {
|
|
79
|
+
/** A body cell: renders its column's `cell` (or `aggregatedCell`) with the cell's context. */
|
|
80
|
+
cell?: FlexCell;
|
|
81
|
+
/** A header: renders its column's `header` with the header's context. */
|
|
82
|
+
header?: FlexHeader;
|
|
83
|
+
/** A footer: renders its column's `footer` with the header's context. */
|
|
84
|
+
footer?: FlexHeader;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Renders a header, cell or footer from its column definition, as TanStack's `FlexRender`
|
|
89
|
+
* does in React: give it one of `@cell`, `@header` or `@footer`. The column's template may be a
|
|
90
|
+
* string, a function of the context (returning a string, a number, or a component), or a
|
|
91
|
+
* component, which gets the context's members as arguments.
|
|
92
|
+
*
|
|
93
|
+
* <t.Head><FlexRender @header={{header}} /></t.Head>
|
|
94
|
+
* <t.Cell><FlexRender @cell={{cell}} /></t.Cell>
|
|
95
|
+
*
|
|
96
|
+
* Every table `createTable()` makes carries it too, as `table.FlexRender`, as upstream's does.
|
|
97
|
+
* A placeholder cell (from column grouping) renders nothing.
|
|
98
|
+
*/
|
|
99
|
+
export default class FlexRender extends Component<FlexRenderSignature> {
|
|
100
|
+
get resolved(): Resolved;
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=flex-render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flex-render.d.ts","sourceRoot":"","sources":["../../src/components/flex-render.gts"],"names":[],"mappings":"AAsMA,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAE1C,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA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wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAE1E;AAED,mFAAmF;AACnF,UAAU,QAAQ;IAChB,SAAS,CAAC,EAAE,QAAQ,CAAA;IACpB,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAAA;CACpC;AAuBD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE;QACJ,8FAA8F;QAC9F,IAAI,CAAC,EAAE,QAAQ,CAAA;QACf,yEAAyE;QACzE,MAAM,CAAC,EAAE,UAAU,CAAA;QACnB,yEAAyE;QACzE,MAAM,CAAC,EAAE,UAAU,CAAA;KACpB,CAAA;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,SAAS,CAAC,mBAAmB,CAAC;IACpE,IAAI,QAAQ,IAAI,QAAQ,CAiBvB;CA4BF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as DataTable } from './components/data-table';
|
|
2
|
+
export * from './components/data-table';
|
|
3
|
+
export { default as FlexRender } from './components/flex-render';
|
|
4
|
+
export * from './components/flex-render';
|
|
5
|
+
export * from './table-core.ts';
|
|
6
|
+
export * from './table.ts';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAClE,cAAc,6BAA6B,CAAA;AAC3C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACpE,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything TanStack Table's framework-agnostic core exports (`tableFeatures`, the features
|
|
3
|
+
* and row models, `createColumnHelper`, the filter and sort functions, and their types), so a
|
|
4
|
+
* table imports from one place, as upstream's examples import from `@tanstack/react-table`.
|
|
5
|
+
*/
|
|
6
|
+
export * from '@tanstack/table-core';
|
|
7
|
+
//# sourceMappingURL=table-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-core.d.ts","sourceRoot":"","sources":["../src/table-core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type RowData, type Table, type TableFeatures, type TableOptions, type TableState, type Updater } from '@tanstack/table-core';
|
|
2
|
+
import FlexRender from './components/flex-render';
|
|
3
|
+
export { emberReactivity } from './-private/reactivity.ts';
|
|
4
|
+
/**
|
|
5
|
+
* A TanStack table made by `createTable()`: table-core's table, whose state is tracked, with
|
|
6
|
+
* `FlexRender` on it (`<this.table.FlexRender @cell={{cell}} />`, as upstream's
|
|
7
|
+
* `<table.FlexRender cell={cell} />`) and its whole state as `state`.
|
|
8
|
+
*/
|
|
9
|
+
export type EmberTable<TFeatures extends TableFeatures, TData extends RowData> = Table<TFeatures, TData> & {
|
|
10
|
+
/** `FlexRender`, so a template that has the table needs no import of its own. */
|
|
11
|
+
FlexRender: typeof FlexRender;
|
|
12
|
+
/** The table's whole state, every slice its features hold (`table.store.state`). Tracked. */
|
|
13
|
+
readonly state: TableState<TFeatures>;
|
|
14
|
+
};
|
|
15
|
+
/** The table options `createTable()` takes, or a function that returns them. */
|
|
16
|
+
export type EmberTableOptions<TFeatures extends TableFeatures, TData extends RowData> = TableOptions<TFeatures, TData> | (() => TableOptions<TFeatures, TData>);
|
|
17
|
+
/**
|
|
18
|
+
* Makes a TanStack table that Ember tracks: shadcn's `useTable`, in Ember. Its state (sorting,
|
|
19
|
+
* filters, pagination, selection, visibility…) is tracked, so a template or getter that reads
|
|
20
|
+
* the table re-renders when what it read changes, and nothing else does.
|
|
21
|
+
*
|
|
22
|
+
* import { createTable, tableFeatures, rowSortingFeature, createSortedRowModel, … } from
|
|
23
|
+
* '@ember-joinery/data-table'
|
|
24
|
+
*
|
|
25
|
+
* const features = tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel() })
|
|
26
|
+
*
|
|
27
|
+
* class Payments extends Component {
|
|
28
|
+
* table = createTable(() => ({ features, columns, data: this.args.payments }))
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* Give it a function, as above, and it reads the options again whenever something the function
|
|
32
|
+
* read changes (`this.args.payments`, a `tableState()` value): that is how `data` and controlled
|
|
33
|
+
* `state` follow your component. Give it an object for options that never change. `features`
|
|
34
|
+
* is read once, when the table is made.
|
|
35
|
+
*
|
|
36
|
+
* Without `state`, the table keeps its own (`initialState` sets where it starts). To own a slice
|
|
37
|
+
* yourself, as upstream's examples own theirs with `useState`, pass it in `state` with its
|
|
38
|
+
* `on<Slice>Change`, from a `tableState()`.
|
|
39
|
+
*
|
|
40
|
+
* Templates can call the table's methods (`{{#each (this.table.getHeaderGroups) …}}`), and the
|
|
41
|
+
* methods of its rows, cells, columns and headers too (`{{(row.getIsSelected)}}`,
|
|
42
|
+
* `@onCheckedChange={{row.toggleSelected}}`): they come bound to their own object.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createTable<TFeatures extends TableFeatures, TData extends RowData>(options: EmberTableOptions<TFeatures, TData>): EmberTable<TFeatures, TData>;
|
|
45
|
+
/**
|
|
46
|
+
* A slice of table state you own, tracked: upstream's `React.useState` for a table. Pass its
|
|
47
|
+
* `value` in the table's `state` and its `set` as the slice's `on<Slice>Change`; `set` takes a
|
|
48
|
+
* value or an updater function, as table-core hands it either.
|
|
49
|
+
*
|
|
50
|
+
* sorting = tableState<SortingState>([])
|
|
51
|
+
* table = createTable(() => ({
|
|
52
|
+
* features, columns, data,
|
|
53
|
+
* onSortingChange: this.sorting.set,
|
|
54
|
+
* state: { sorting: this.sorting.value },
|
|
55
|
+
* }))
|
|
56
|
+
*/
|
|
57
|
+
export declare class TrackedState<T> {
|
|
58
|
+
value: T;
|
|
59
|
+
constructor(initial: T);
|
|
60
|
+
/** Sets it to a value, or to what an updater makes of the current one. */
|
|
61
|
+
set: (updater: Updater<T>) => void;
|
|
62
|
+
}
|
|
63
|
+
/** A `TrackedState` that starts at `initial`. */
|
|
64
|
+
export declare function tableState<T>(initial: T): TrackedState<T>;
|
|
65
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,OAAO,EACb,MAAM,sBAAsB,CAAA;AAC7B,OAAO,UAAU,MAAM,8BAA8B,CAAA;AAIrD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,SAAS,SAAS,aAAa,EAAE,KAAK,SAAS,OAAO,IAAI,KAAK,CACpF,SAAS,EACT,KAAK,CACN,GAAG;IACF,iFAAiF;IACjF,UAAU,EAAE,OAAO,UAAU,CAAA;IAC7B,6FAA6F;IAC7F,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;CACtC,CAAA;AAED,gFAAgF;AAChF,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,aAAa,EAAE,KAAK,SAAS,OAAO,IAClF,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;AAYzE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CAAC,SAAS,SAAS,aAAa,EAAE,KAAK,SAAS,OAAO,EAChF,OAAO,EAAE,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,GAC3C,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAwD9B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,YAAY,CAAC,CAAC;IAChB,KAAK,EAAE,CAAC,CAAA;gBAEL,OAAO,EAAE,CAAC;IAItB,0EAA0E;IAC1E,GAAG,GAAI,SAAS,OAAO,CAAC,CAAC,CAAC,KAAG,IAAI,CAEhC;CACF;AAED,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEzD"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { CheckboxHarness, DropdownMenuHarness, Harness, TableHarness } from '@ember-joinery/test-support';
|
|
2
|
+
/** A column, as the harness's members take it: its id, its header's text, or its position. */
|
|
3
|
+
export type DataTableColumn = string | number;
|
|
4
|
+
/** A column's sort, as its header cell's `aria-sort` says it. */
|
|
5
|
+
export type DataTableSort = 'ascending' | 'descending' | 'none';
|
|
6
|
+
/**
|
|
7
|
+
* Drives a data table: the parts inside a `<DataTable>` from `@ember-joinery/data-table`, which
|
|
8
|
+
* its modifiers mark. It reads the rows and columns the table shows, each column's sort (from
|
|
9
|
+
* the header cell's `aria-sort`), which rows are selected (from each row's checkbox), and the
|
|
10
|
+
* filter and pages, and works them as a user does: with the sort buttons in the headers, the
|
|
11
|
+
* filter input, the row checkboxes, the page buttons and the column menu.
|
|
12
|
+
*
|
|
13
|
+
* const payments = new DataTableHarness('payments') // <DataTable @name="payments">
|
|
14
|
+
* await payments.filter('ken')
|
|
15
|
+
* assert.deepEqual(payments.column('email'), ['ken99@example.com'])
|
|
16
|
+
* await payments.sort('email')
|
|
17
|
+
* assert.strictEqual(payments.sortOf('email'), 'ascending')
|
|
18
|
+
* await payments.toggleRow(0)
|
|
19
|
+
* assert.deepEqual(payments.selectedRows, [0])
|
|
20
|
+
* await payments.nextPage()
|
|
21
|
+
*
|
|
22
|
+
* A column is its id (the header cell's `data-test-jn-value`), its header's text, or its
|
|
23
|
+
* position among the columns shown.
|
|
24
|
+
*/
|
|
25
|
+
export declare class DataTableHarness extends Harness {
|
|
26
|
+
#private;
|
|
27
|
+
static component: string;
|
|
28
|
+
/** The table inside it. */
|
|
29
|
+
get table(): TableHarness;
|
|
30
|
+
/** Every header cell (`dt.head`), in every header row. */
|
|
31
|
+
get headElements(): HTMLTableCellElement[];
|
|
32
|
+
/** The header cells of the columns shown: those in the header's last row. */
|
|
33
|
+
get columnHeads(): HTMLTableCellElement[];
|
|
34
|
+
/** The ids of the columns shown, in order. */
|
|
35
|
+
get columnIds(): string[];
|
|
36
|
+
/** The text of each column's header, in order (`''` for one with no text, as a checkbox's). */
|
|
37
|
+
get columns(): string[];
|
|
38
|
+
/** Whether the column is shown, by its id. */
|
|
39
|
+
isColumnShown(id: string): boolean;
|
|
40
|
+
/** The header cell of a column. Throws when the table doesn't show it. */
|
|
41
|
+
head(column: DataTableColumn): HTMLTableCellElement;
|
|
42
|
+
/** The body's rows (`dt.row`), as the table shows them: this page, filtered and sorted. */
|
|
43
|
+
get rowElements(): HTMLTableRowElement[];
|
|
44
|
+
/** Each row's id (table-core's `row.id`), in order. */
|
|
45
|
+
get rowIds(): string[];
|
|
46
|
+
/** How many rows it shows. */
|
|
47
|
+
get rowCount(): number;
|
|
48
|
+
/** The text of each row's cells, row by row. */
|
|
49
|
+
get rows(): string[][];
|
|
50
|
+
/** Whether it shows no rows (its body shows `emptyText` instead). */
|
|
51
|
+
get isEmpty(): boolean;
|
|
52
|
+
/** The body's text while it shows no rows (upstream's `No results.`), or `null`. */
|
|
53
|
+
get emptyText(): string | null;
|
|
54
|
+
/** The row at `index`, counting from 0. Throws when there is none. */
|
|
55
|
+
row(index: number): HTMLTableRowElement;
|
|
56
|
+
/** The cell of row `index` in a column. */
|
|
57
|
+
cell(index: number, column: DataTableColumn): HTMLTableCellElement;
|
|
58
|
+
/** The text of every row's cell in a column. */
|
|
59
|
+
column(column: DataTableColumn): string[];
|
|
60
|
+
/** A column's sort, from its header cell's `aria-sort` (`none` without one). */
|
|
61
|
+
sortOf(column: DataTableColumn): DataTableSort;
|
|
62
|
+
/** The column the rows are sorted by, and which way, or `null` while they aren't. */
|
|
63
|
+
get sortedBy(): {
|
|
64
|
+
column: string;
|
|
65
|
+
direction: 'ascending' | 'descending';
|
|
66
|
+
} | null;
|
|
67
|
+
/** The button in a column's header that sorts by it. Throws when it has none. */
|
|
68
|
+
sortButton(column: DataTableColumn): HTMLButtonElement;
|
|
69
|
+
/** Clicks the sort button in a column's header. */
|
|
70
|
+
sort(column: DataTableColumn): Promise<void>;
|
|
71
|
+
/** The input that filters a column (`dt.filter`), or the first filter without a column. */
|
|
72
|
+
filterInput(column?: string): HTMLInputElement;
|
|
73
|
+
/** What a filter holds. */
|
|
74
|
+
filterValue(column?: string): string;
|
|
75
|
+
/** Types `value` into a filter, as a user does, replacing what it held. */
|
|
76
|
+
filter(value: string, column?: string): Promise<void>;
|
|
77
|
+
/** The button that goes back a page (`dt.previousPage`), or `null`. */
|
|
78
|
+
get previousPageButton(): HTMLElement | null;
|
|
79
|
+
/** The button that goes on a page (`dt.nextPage`), or `null`. */
|
|
80
|
+
get nextPageButton(): HTMLElement | null;
|
|
81
|
+
/** Whether there is a page before this one: the previous button can be used. */
|
|
82
|
+
get canPreviousPage(): boolean;
|
|
83
|
+
/** Whether there is a page after this one: the next button can be used. */
|
|
84
|
+
get canNextPage(): boolean;
|
|
85
|
+
/** Clicks the previous page button. */
|
|
86
|
+
previousPage(): Promise<void>;
|
|
87
|
+
/** Clicks the next page button. */
|
|
88
|
+
nextPage(): Promise<void>;
|
|
89
|
+
/** The checkbox that selects a row, or `null` when the row has none. */
|
|
90
|
+
rowCheckbox(index: number): CheckboxHarness | null;
|
|
91
|
+
/** The checkbox in a header cell that selects every row on the page, or `null`. */
|
|
92
|
+
get selectAll(): CheckboxHarness | null;
|
|
93
|
+
/**
|
|
94
|
+
* Whether row `index` is selected: its checkbox is checked, or, in a table without them, the
|
|
95
|
+
* row is marked `data-state="selected"`.
|
|
96
|
+
*/
|
|
97
|
+
isSelected(index: number): boolean;
|
|
98
|
+
/** The rows selected, by index on this page. */
|
|
99
|
+
get selectedRows(): number[];
|
|
100
|
+
/** Clicks row `index`'s checkbox, which selects or deselects it. */
|
|
101
|
+
toggleRow(index: number): Promise<void>;
|
|
102
|
+
/** Clicks the header's checkbox, which selects (or deselects) every row on the page. */
|
|
103
|
+
toggleAll(): Promise<void>;
|
|
104
|
+
/** The menu that shows and hides columns (`dt.viewOptions`). Throws when there is none. */
|
|
105
|
+
get viewOptions(): DropdownMenuHarness;
|
|
106
|
+
/** The columns the menu offers, by their items' text (it opens the menu to read them). */
|
|
107
|
+
columnOptions(): Promise<string[]>;
|
|
108
|
+
/** Opens the column menu and toggles the column whose item reads `label`. */
|
|
109
|
+
toggleColumn(label: string): Promise<void>;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=data-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table.d.ts","sourceRoot":"","sources":["../../src/test-support/data-table.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,OAAO,EACP,YAAY,EACb,MAAM,6BAA6B,CAAA;AAWpC,8FAA8F;AAC9F,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAA;AAE7C,iEAAiE;AACjE,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,CAAA;AAE/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,gBAAiB,SAAQ,OAAO;;IAC3C,OAAgB,SAAS,SAAe;IAExC,2BAA2B;IAC3B,IAAI,KAAK,IAAI,YAAY,CAExB;IAID,0DAA0D;IAC1D,IAAI,YAAY,IAAI,oBAAoB,EAAE,CAEzC;IAED,6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"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-support/index.ts"],"names":[],"mappings":"AAGA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { hash } from '@ember/helper';
|
|
3
|
+
import { As } from '@ember-joinery/primitives/as';
|
|
4
|
+
import { idFor } from '@ember-joinery/primitives/id';
|
|
5
|
+
import { part } from '@ember-joinery/primitives/part';
|
|
6
|
+
import FlexRender from './flex-render.js';
|
|
7
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
8
|
+
import { setComponentTemplate } from '@ember/component';
|
|
9
|
+
|
|
10
|
+
/** What `dt.row` reads of a row. */
|
|
11
|
+
/** The parts' `data-test-jn-owner`: the data table around them, by the `id` it has. */function ownedByDataTable(element) {
|
|
12
|
+
const root = element.parentElement?.closest('[data-test-jn="data-table"]');
|
|
13
|
+
if (root?.id) element.setAttribute('data-test-jn-owner', root.id);
|
|
14
|
+
}
|
|
15
|
+
/** What the column's sort is, as `aria-sort` says it: only the first sort, as ARIA asks. */
|
|
16
|
+
function ariaSort(header) {
|
|
17
|
+
if (header.isPlaceholder) return undefined;
|
|
18
|
+
const column = header.column;
|
|
19
|
+
const sorted = column.getIsSorted?.();
|
|
20
|
+
if (!sorted) return undefined;
|
|
21
|
+
if ((column.getSortIndex?.() ?? 0) > 0) return undefined;
|
|
22
|
+
return sorted === 'asc' ? 'ascending' : 'descending';
|
|
23
|
+
}
|
|
24
|
+
const marker = (name, value) => ({
|
|
25
|
+
'data-test-jn-part': name,
|
|
26
|
+
'data-test-jn-value': value
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* `<t.Head {{dt.head header}}>`: a header cell's sort, in `aria-sort` (`ascending` or
|
|
30
|
+
* `descending` on the column the rows are sorted by, as the APG's sortable table has it), its
|
|
31
|
+
* `colspan` over grouped columns, and the column's id for the harness.
|
|
32
|
+
*/
|
|
33
|
+
const head = part((_, [header]) => ({
|
|
34
|
+
attributes: {
|
|
35
|
+
'aria-sort': ariaSort(header),
|
|
36
|
+
colspan: header.colSpan > 1 ? header.colSpan : undefined,
|
|
37
|
+
...marker('head', header.column.id)
|
|
38
|
+
},
|
|
39
|
+
element: ownedByDataTable
|
|
40
|
+
}));
|
|
41
|
+
/** `<t.Row {{dt.row row}}>`: a body row, with its row's id, for the harness. */
|
|
42
|
+
const row = part((_, [tableRow]) => ({
|
|
43
|
+
attributes: marker('row', tableRow.id),
|
|
44
|
+
element: ownedByDataTable
|
|
45
|
+
}));
|
|
46
|
+
/** `<Input {{dt.filter "email"}}>`: the input that filters a column, by the column's id. */
|
|
47
|
+
const filter = part((_, [columnId]) => ({
|
|
48
|
+
attributes: marker('filter', columnId),
|
|
49
|
+
element: ownedByDataTable
|
|
50
|
+
}));
|
|
51
|
+
/** `<Button {{dt.previousPage}}>`: the button that goes back a page. */
|
|
52
|
+
const previousPage = part(() => ({
|
|
53
|
+
attributes: marker('previous-page'),
|
|
54
|
+
element: ownedByDataTable
|
|
55
|
+
}));
|
|
56
|
+
/** `<Button {{dt.nextPage}}>`: the button that goes on a page. */
|
|
57
|
+
const nextPage = part(() => ({
|
|
58
|
+
attributes: marker('next-page'),
|
|
59
|
+
element: ownedByDataTable
|
|
60
|
+
}));
|
|
61
|
+
/** `<DropdownMenu {{dt.viewOptions}}>`: the menu of columns to show and hide. */
|
|
62
|
+
const viewOptions = part(() => ({
|
|
63
|
+
attributes: marker('view-options'),
|
|
64
|
+
element: ownedByDataTable
|
|
65
|
+
}));
|
|
66
|
+
/** What a `<DataTable>` yields: its table, `FlexRender`, and a modifier for each part. */
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The element around a data table and the controls that work it: upstream's
|
|
70
|
+
* `<div className="w-full">`, which `DataTableHarness` scopes to. It renders nothing of its
|
|
71
|
+
* own, but it yields the modifiers that mark each part for the harness, and that give the
|
|
72
|
+
* header cells their `aria-sort`, which upstream's leave out:
|
|
73
|
+
*
|
|
74
|
+
* <DataTable @table={{this.table}} class="w-full" as |dt|>
|
|
75
|
+
* <Input placeholder="Filter emails..." {{dt.filter "email"}} … />
|
|
76
|
+
* <Table as |t|>
|
|
77
|
+
* …<t.Head {{dt.head header}}><dt.FlexRender @header={{header}} /></t.Head>
|
|
78
|
+
* …<t.Row {{dt.row row}}>…</t.Row>
|
|
79
|
+
* </Table>
|
|
80
|
+
* <Button {{dt.previousPage}} …>Previous</Button>
|
|
81
|
+
* <Button {{dt.nextPage}} …>Next</Button>
|
|
82
|
+
* </DataTable>
|
|
83
|
+
*/
|
|
84
|
+
class DataTable extends Component {
|
|
85
|
+
get id() {
|
|
86
|
+
return idFor(this);
|
|
87
|
+
}
|
|
88
|
+
static {
|
|
89
|
+
setComponentTemplate(precompileTemplate("<As @as={{@as}} @tag=\"div\" id={{this.id}} data-test-jn=\"data-table\" data-test-jn-name={{@name}} ...attributes>\n {{yield (hash table=@table FlexRender=FlexRender head=head row=row filter=filter previousPage=previousPage nextPage=nextPage viewOptions=viewOptions)}}\n</As>", {
|
|
90
|
+
strictMode: true,
|
|
91
|
+
scope: () => ({
|
|
92
|
+
As,
|
|
93
|
+
hash,
|
|
94
|
+
FlexRender,
|
|
95
|
+
head,
|
|
96
|
+
row,
|
|
97
|
+
filter,
|
|
98
|
+
previousPage,
|
|
99
|
+
nextPage,
|
|
100
|
+
viewOptions
|
|
101
|
+
})
|
|
102
|
+
}), this);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { ariaSort, DataTable as default };
|
|
107
|
+
//# sourceMappingURL=data-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table.js","sources":["../../src/components/data-table.gts"],"sourcesContent":["import Component from '@glimmer/component'\nimport { hash } from '@ember/helper'\nimport { As, type TagName } from '@ember-joinery/primitives/as'\nimport { idFor } from '@ember-joinery/primitives/id'\nimport { part, type PartModifier } from '@ember-joinery/primitives/part'\nimport type { RowData, Table, TableFeatures } from '@tanstack/table-core'\nimport FlexRender from './flex-render.gts'\n\n/** What `dt.head` reads of a header, whatever its table's features. */\nexport interface DataTableHeader {\n isPlaceholder: boolean\n colSpan: number\n column: {\n id: string\n /** From the sorting feature: `asc`, `desc`, or `false`. */\n getIsSorted?: () => false | 'asc' | 'desc'\n /** From the sorting feature: the column's place among the sorts. */\n getSortIndex?: () => number\n }\n}\n\n/** What `dt.row` reads of a row. */\nexport interface DataTableRow {\n id: string\n}\n\n/** The parts' `data-test-jn-owner`: the data table around them, by the `id` it has. */\nfunction ownedByDataTable(element: Element): void {\n const root = element.parentElement?.closest('[data-test-jn=\"data-table\"]')\n if (root?.id) element.setAttribute('data-test-jn-owner', root.id)\n}\n\n/** What the column's sort is, as `aria-sort` says it: only the first sort, as ARIA asks. */\nexport function ariaSort(header: DataTableHeader): 'ascending' | 'descending' | undefined {\n if (header.isPlaceholder) return undefined\n const column = header.column\n const sorted = column.getIsSorted?.()\n if (!sorted) return undefined\n if ((column.getSortIndex?.() ?? 0) > 0) return undefined\n return sorted === 'asc' ? 'ascending' : 'descending'\n}\n\nconst marker = (name: string, value?: string) => ({\n 'data-test-jn-part': name,\n 'data-test-jn-value': value,\n})\n\n/**\n * `<t.Head {{dt.head header}}>`: a header cell's sort, in `aria-sort` (`ascending` or\n * `descending` on the column the rows are sorted by, as the APG's sortable table has it), its\n * `colspan` over grouped columns, and the column's id for the harness.\n */\nconst head = part<HTMLTableCellElement, Record<string, never>, [DataTableHeader]>(\n (_, [header]) => ({\n attributes: {\n 'aria-sort': ariaSort(header),\n colspan: header.colSpan > 1 ? header.colSpan : undefined,\n ...marker('head', header.column.id),\n },\n element: ownedByDataTable,\n }),\n)\n\n/** `<t.Row {{dt.row row}}>`: a body row, with its row's id, for the harness. */\nconst row = part<HTMLElement, Record<string, never>, [DataTableRow]>((_, [tableRow]) => ({\n attributes: marker('row', tableRow.id),\n element: ownedByDataTable,\n}))\n\n/** `<Input {{dt.filter \"email\"}}>`: the input that filters a column, by the column's id. */\nconst filter = part<HTMLElement, Record<string, never>, [string?]>((_, [columnId]) => ({\n attributes: marker('filter', columnId),\n element: ownedByDataTable,\n}))\n\n/** `<Button {{dt.previousPage}}>`: the button that goes back a page. */\nconst previousPage = part<HTMLElement>(() => ({\n attributes: marker('previous-page'),\n element: ownedByDataTable,\n}))\n\n/** `<Button {{dt.nextPage}}>`: the button that goes on a page. */\nconst nextPage = part<HTMLElement>(() => ({\n attributes: marker('next-page'),\n element: ownedByDataTable,\n}))\n\n/** `<DropdownMenu {{dt.viewOptions}}>`: the menu of columns to show and hide. */\nconst viewOptions = part<HTMLElement>(() => ({\n attributes: marker('view-options'),\n element: ownedByDataTable,\n}))\n\n/** What a `<DataTable>` yields: its table, `FlexRender`, and a modifier for each part. */\nexport interface DataTableParts<TFeatures extends TableFeatures, TData extends RowData> {\n /** The table it was given. */\n table: Table<TFeatures, TData>\n /** Renders a header, cell or footer from its column definition. */\n FlexRender: typeof FlexRender\n /** On each header cell (`<t.Head {{dt.head header}}>`): its `aria-sort` and `colspan`. */\n head: PartModifier<HTMLTableCellElement, Record<string, never>, [DataTableHeader]>\n /** On each body row (`<t.Row {{dt.row row}}>`). */\n row: PartModifier<HTMLElement, Record<string, never>, [DataTableRow]>\n /** On a column's filter input (`<Input {{dt.filter \"email\"}}>`). */\n filter: PartModifier<HTMLElement, Record<string, never>, [string?]>\n /** On the button that goes back a page. */\n previousPage: PartModifier<HTMLElement>\n /** On the button that goes on a page. */\n nextPage: PartModifier<HTMLElement>\n /** On the dropdown menu that shows and hides columns (`<DropdownMenu {{dt.viewOptions}}>`). */\n viewOptions: PartModifier<HTMLElement>\n}\n\nexport interface DataTableSignature<TFeatures extends TableFeatures, TData extends RowData> {\n Args: {\n /** The table, from `createTable()`. */\n table: Table<TFeatures, TData>\n /** Its name, for its harness (`data-test-jn-name`). */\n name?: string\n /** The tag to render. Default `div`. */\n as?: TagName\n }\n Blocks: {\n /** What goes around the table (a filter, the column menu, pagination) and the table. */\n default: [DataTableParts<TFeatures, TData>]\n }\n Element: HTMLElement\n}\n\n/**\n * The element around a data table and the controls that work it: upstream's\n * `<div className=\"w-full\">`, which `DataTableHarness` scopes to. It renders nothing of its\n * own, but it yields the modifiers that mark each part for the harness, and that give the\n * header cells their `aria-sort`, which upstream's leave out:\n *\n * <DataTable @table={{this.table}} class=\"w-full\" as |dt|>\n * <Input placeholder=\"Filter emails...\" {{dt.filter \"email\"}} … />\n * <Table as |t|>\n * …<t.Head {{dt.head header}}><dt.FlexRender @header={{header}} /></t.Head>\n * …<t.Row {{dt.row row}}>…</t.Row>\n * </Table>\n * <Button {{dt.previousPage}} …>Previous</Button>\n * <Button {{dt.nextPage}} …>Next</Button>\n * </DataTable>\n */\nexport default class DataTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> extends Component<DataTableSignature<TFeatures, TData>> {\n get id(): string {\n return idFor(this)\n }\n\n <template>\n <As\n @as={{@as}}\n @tag=\"div\"\n id={{this.id}}\n data-test-jn=\"data-table\"\n data-test-jn-name={{@name}}\n ...attributes\n >\n {{yield\n (hash\n table=@table\n FlexRender=FlexRender\n head=head\n row=row\n filter=filter\n previousPage=previousPage\n nextPage=nextPage\n viewOptions=viewOptions\n )\n }}\n </As>\n </template>\n}\n"],"names":["ownedByDataTable","element","root","parentElement","closest","id","setAttribute","ariaSort","header","isPlaceholder","undefined","column","sorted","getIsSorted","getSortIndex","marker","name","value","head","part","_","attributes","colspan","colSpan","row","tableRow","filter","columnId","previousPage","nextPage","viewOptions","DataTable","Component","idFor","setComponentTemplate","precompileTemplate","strictMode","scope","As","hash","FlexRender"],"mappings":";;;;;;;;;AAqBA;AAKA,uFACA,SAASA,gBAAAA,CAAiBC,OAAgB,EAAO;EAC/C,MAAMC,IAAA,GAAOD,OAAA,CAAQE,aAAa,EAAEC,OAAA,CAAQ,6BAAA,CAAA;AAC5C,EAAA,IAAIF,MAAMG,EAAA,EAAIJ,OAAA,CAAQK,YAAY,CAAC,oBAAA,EAA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