@triptyk/ember-yeti-table 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +9 -115
- package/declarations/components/yeti-table/body.d.ts +32 -0
- package/declarations/components/yeti-table/body.d.ts.map +1 -0
- package/declarations/components/yeti-table/header.d.ts +33 -0
- package/declarations/components/yeti-table/header.d.ts.map +1 -0
- package/declarations/components/yeti-table/pagination.d.ts +40 -0
- package/declarations/components/yeti-table/pagination.d.ts.map +1 -0
- package/declarations/components/yeti-table/table.d.ts +21 -0
- package/declarations/components/yeti-table/table.d.ts.map +1 -0
- package/declarations/components/yeti-table/tbody/row/cell.d.ts +44 -0
- package/declarations/components/yeti-table/tbody/row/cell.d.ts.map +1 -0
- package/declarations/components/yeti-table/tbody/row.d.ts +37 -0
- package/declarations/components/yeti-table/tbody/row.d.ts.map +1 -0
- package/declarations/components/yeti-table/tbody.d.ts +29 -0
- package/declarations/components/yeti-table/tbody.d.ts.map +1 -0
- package/declarations/components/yeti-table/tfoot/row/cell.d.ts +40 -0
- package/declarations/components/yeti-table/tfoot/row/cell.d.ts.map +1 -0
- package/declarations/components/yeti-table/tfoot/row.d.ts +37 -0
- package/declarations/components/yeti-table/tfoot/row.d.ts.map +1 -0
- package/declarations/components/yeti-table/tfoot.d.ts +27 -0
- package/declarations/components/yeti-table/tfoot.d.ts.map +1 -0
- package/declarations/components/yeti-table/thead/row/cell.d.ts +54 -0
- package/declarations/components/yeti-table/thead/row/cell.d.ts.map +1 -0
- package/declarations/components/yeti-table/thead/row/column.d.ts +69 -0
- package/declarations/components/yeti-table/thead/row/column.d.ts.map +1 -0
- package/declarations/components/yeti-table/thead/row.d.ts +55 -0
- package/declarations/components/yeti-table/thead/row.d.ts.map +1 -0
- package/declarations/components/yeti-table/thead.d.ts +34 -0
- package/declarations/components/yeti-table/thead.d.ts.map +1 -0
- package/declarations/components/yeti-table.d.ts +107 -0
- package/declarations/components/yeti-table.d.ts.map +1 -0
- package/declarations/index.d.ts +1 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/template-registry.d.ts +1 -0
- package/declarations/template-registry.d.ts.map +1 -0
- package/declarations/themes/default-theme.d.ts +3 -27
- package/declarations/themes/default-theme.d.ts.map +1 -1
- package/declarations/types.d.ts +82 -0
- package/declarations/types.d.ts.map +1 -0
- package/declarations/utils/create-regex.d.ts +1 -1
- package/declarations/utils/create-regex.d.ts.map +1 -1
- package/declarations/utils/filtering-utils.d.ts +2 -4
- package/declarations/utils/filtering-utils.d.ts.map +1 -1
- package/declarations/utils/sorting-utils.d.ts +6 -15
- package/declarations/utils/sorting-utils.d.ts.map +1 -1
- package/dist/components/yeti-table/body.js +19 -14
- package/dist/components/yeti-table/body.js.map +1 -1
- package/dist/components/yeti-table/header.js +10 -10
- package/dist/components/yeti-table/header.js.map +1 -1
- package/dist/components/yeti-table/pagination.js +14 -44
- package/dist/components/yeti-table/pagination.js.map +1 -1
- package/dist/components/yeti-table/table.js +1 -23
- package/dist/components/yeti-table/table.js.map +1 -1
- package/dist/components/yeti-table/tbody/row/cell.js +12 -12
- package/dist/components/yeti-table/tbody/row/cell.js.map +1 -1
- package/dist/components/yeti-table/tbody/row.js +15 -21
- package/dist/components/yeti-table/tbody/row.js.map +1 -1
- package/dist/components/yeti-table/tbody.js +1 -0
- package/dist/components/yeti-table/tbody.js.map +1 -1
- package/dist/components/yeti-table/tfoot/row/cell.js +9 -9
- package/dist/components/yeti-table/tfoot/row/cell.js.map +1 -1
- package/dist/components/yeti-table/tfoot/row.js +11 -11
- package/dist/components/yeti-table/tfoot/row.js.map +1 -1
- package/dist/components/yeti-table/tfoot.js +1 -0
- package/dist/components/yeti-table/tfoot.js.map +1 -1
- package/dist/components/yeti-table/thead/row/cell.js +11 -8
- package/dist/components/yeti-table/thead/row/cell.js.map +1 -1
- package/dist/components/yeti-table/thead/row/column.js +27 -128
- package/dist/components/yeti-table/thead/row/column.js.map +1 -1
- package/dist/components/yeti-table/thead/row.js +15 -15
- package/dist/components/yeti-table/thead/row.js.map +1 -1
- package/dist/components/yeti-table/thead.js +3 -22
- package/dist/components/yeti-table/thead.js.map +1 -1
- package/dist/components/yeti-table.js +99 -303
- package/dist/components/yeti-table.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/template-registry.js +2 -0
- package/dist/template-registry.js.map +1 -0
- package/dist/themes/default-theme.js +3 -2
- package/dist/themes/default-theme.js.map +1 -1
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/create-regex.js +6 -6
- package/dist/utils/create-regex.js.map +1 -1
- package/dist/utils/filtering-utils.js +20 -8
- package/dist/utils/filtering-utils.js.map +1 -1
- package/dist/utils/sorting-utils.js +13 -18
- package/dist/utils/sorting-utils.js.map +1 -1
- package/package.json +37 -16
- package/src/components/yeti-table/{body.gjs → body.gts} +49 -45
- package/src/components/yeti-table/header.gts +67 -0
- package/src/components/yeti-table/pagination.gts +118 -0
- package/src/components/yeti-table/table.gts +27 -0
- package/src/components/yeti-table/tbody/row/{cell.gjs → cell.gts} +38 -19
- package/src/components/yeti-table/tbody/row.gts +76 -0
- package/src/components/yeti-table/tbody.gts +53 -0
- package/src/components/yeti-table/tfoot/row/cell.gts +64 -0
- package/src/components/yeti-table/tfoot/row.gts +59 -0
- package/src/components/yeti-table/tfoot.gts +41 -0
- package/src/components/yeti-table/thead/row/{cell.gjs → cell.gts} +36 -13
- package/src/components/yeti-table/thead/row/column.gts +177 -0
- package/src/components/yeti-table/thead/row.gts +105 -0
- package/src/components/yeti-table/thead.gts +65 -0
- package/src/components/yeti-table.gts +629 -0
- package/src/template-registry.ts +10 -0
- package/src/themes/{default-theme.js → default-theme.ts} +5 -1
- package/src/types.ts +94 -0
- package/src/utils/{create-regex.js → create-regex.ts} +10 -10
- package/src/utils/filtering-utils.ts +91 -0
- package/src/utils/{sorting-utils.js → sorting-utils.ts} +35 -26
- package/dist/_app_/themes/default-theme.js +0 -1
- package/dist/_app_/utils/create-regex.js +0 -1
- package/dist/_app_/utils/filtering-utils.js +0 -1
- package/dist/_app_/utils/sorting-utils.js +0 -1
- package/src/components/yeti-table/header.gjs +0 -54
- package/src/components/yeti-table/pagination.gjs +0 -155
- package/src/components/yeti-table/table.gjs +0 -34
- package/src/components/yeti-table/tbody/row.gjs +0 -89
- package/src/components/yeti-table/tbody.gjs +0 -55
- package/src/components/yeti-table/tfoot/row/cell.gjs +0 -45
- package/src/components/yeti-table/tfoot/row.gjs +0 -44
- package/src/components/yeti-table/tfoot.gjs +0 -33
- package/src/components/yeti-table/thead/row/column.gjs +0 -260
- package/src/components/yeti-table/thead/row.gjs +0 -71
- package/src/components/yeti-table/thead.gjs +0 -45
- package/src/components/yeti-table.gjs +0 -780
- package/src/utils/filtering-utils.js +0 -75
- /package/src/{.gitkeep → index.ts} +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
|
|
3
|
+
import { hash } from '@ember/helper';
|
|
4
|
+
|
|
5
|
+
import type { WithBoundArgs } from '@glint/template';
|
|
6
|
+
|
|
7
|
+
import TFootRow from './tfoot/row.gts';
|
|
8
|
+
import type { ColumnDefinition, Theme } from '../../types.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
Renders a `<tfoot>` element and yields the row component.
|
|
12
|
+
|
|
13
|
+
@class TTFoot
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export interface TFootSignature {
|
|
17
|
+
Element: HTMLTableSectionElement;
|
|
18
|
+
Args: {
|
|
19
|
+
theme?: Theme;
|
|
20
|
+
columns?: ColumnDefinition[];
|
|
21
|
+
parent?: unknown;
|
|
22
|
+
};
|
|
23
|
+
Blocks: {
|
|
24
|
+
default: [
|
|
25
|
+
{ row: WithBoundArgs<typeof TFootRow, 'columns' | 'theme' | 'parent'> },
|
|
26
|
+
];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line ember/no-empty-glimmer-component-classes
|
|
31
|
+
export default class TFoot extends Component<TFootSignature> {
|
|
32
|
+
<template>
|
|
33
|
+
<tfoot class={{@theme.tfoot}} ...attributes>
|
|
34
|
+
{{yield
|
|
35
|
+
(hash
|
|
36
|
+
row=(component TFootRow columns=@columns theme=@theme parent=@parent)
|
|
37
|
+
)
|
|
38
|
+
}}
|
|
39
|
+
</tfoot>
|
|
40
|
+
</template>
|
|
41
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
|
+
import type Owner from '@ember/owner';
|
|
3
|
+
|
|
4
|
+
import type { ColumnDefinition, Theme } from '../../../../types.ts';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
An component yielded from the head.row component that is used to define
|
|
@@ -28,25 +31,45 @@ import Component from '@glimmer/component';
|
|
|
28
31
|
@yield {object} cell
|
|
29
32
|
|
|
30
33
|
*/
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
export interface THeadCellParent {
|
|
35
|
+
registerCell(cell: THeadCell): ColumnDefinition | undefined;
|
|
36
|
+
unregisterCell(cell: THeadCell): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface THeadCellSignature {
|
|
40
|
+
Element: HTMLTableCellElement;
|
|
41
|
+
Args: {
|
|
42
|
+
class?: string;
|
|
43
|
+
theme?: Theme;
|
|
44
|
+
parent?: THeadCellParent;
|
|
45
|
+
prop?: string;
|
|
46
|
+
};
|
|
47
|
+
Blocks: { default: [] };
|
|
48
|
+
}
|
|
39
49
|
|
|
50
|
+
export default class THeadCell extends Component<THeadCellSignature> {
|
|
40
51
|
// Assigned when the cell is registered
|
|
41
|
-
column = undefined;
|
|
52
|
+
column: ColumnDefinition | undefined = undefined;
|
|
42
53
|
|
|
43
|
-
constructor() {
|
|
44
|
-
super(
|
|
54
|
+
constructor(owner: Owner, args: THeadCellSignature['Args']) {
|
|
55
|
+
super(owner, args);
|
|
45
56
|
this.column = this.args.parent?.registerCell(this);
|
|
46
57
|
}
|
|
47
58
|
|
|
48
|
-
willDestroy() {
|
|
49
|
-
super.willDestroy(
|
|
59
|
+
willDestroy(): void {
|
|
60
|
+
super.willDestroy();
|
|
50
61
|
this.args.parent?.unregisterCell(this);
|
|
51
62
|
}
|
|
63
|
+
|
|
64
|
+
get prop(): string | undefined {
|
|
65
|
+
return this.args.prop;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
{{#if this.column.visible}}
|
|
70
|
+
<th class="{{@class}} {{@theme.theadCell}}" ...attributes>
|
|
71
|
+
{{yield}}
|
|
72
|
+
</th>
|
|
73
|
+
{{/if}}
|
|
74
|
+
</template>
|
|
52
75
|
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { action } from '@ember/object';
|
|
2
|
+
import { assert } from '@ember/debug';
|
|
3
|
+
|
|
4
|
+
import Component from '@glimmer/component';
|
|
5
|
+
import { modifier } from 'ember-modifier';
|
|
6
|
+
import { localCopy } from 'tracked-toolbox';
|
|
7
|
+
import type Owner from '@ember/owner';
|
|
8
|
+
|
|
9
|
+
import { on } from '@ember/modifier';
|
|
10
|
+
import { hash } from '@ember/helper';
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
ColumnDefinition,
|
|
14
|
+
FilterFunction,
|
|
15
|
+
SortDirection,
|
|
16
|
+
Theme,
|
|
17
|
+
} from '../../../../types.ts';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
An important component yielded from the header or head.row component that is used to define
|
|
21
|
+
a column of the table.
|
|
22
|
+
|
|
23
|
+
@class Column
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export interface ColumnParent {
|
|
27
|
+
registerColumn(column: Column): void;
|
|
28
|
+
unregisterColumn(column: Column): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ColumnSignature {
|
|
32
|
+
Element: HTMLTableCellElement;
|
|
33
|
+
Args: {
|
|
34
|
+
class?: string;
|
|
35
|
+
theme?: Theme;
|
|
36
|
+
prop?: string;
|
|
37
|
+
visible?: boolean;
|
|
38
|
+
sortable?: boolean;
|
|
39
|
+
sort?: SortDirection | null;
|
|
40
|
+
sortSequence?: SortDirection[] | string;
|
|
41
|
+
filterable?: boolean;
|
|
42
|
+
filter?: string;
|
|
43
|
+
filterFunction?: FilterFunction;
|
|
44
|
+
filterUsing?: unknown;
|
|
45
|
+
columnClass?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
onClick?: (column: Column, e: MouseEvent) => void;
|
|
48
|
+
parent?: ColumnParent;
|
|
49
|
+
};
|
|
50
|
+
Blocks: {
|
|
51
|
+
default: [
|
|
52
|
+
{
|
|
53
|
+
isSorted: boolean;
|
|
54
|
+
isAscSorted: boolean;
|
|
55
|
+
isDescSorted: boolean;
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default class Column
|
|
62
|
+
extends Component<ColumnSignature>
|
|
63
|
+
implements ColumnDefinition
|
|
64
|
+
{
|
|
65
|
+
get prop(): string | undefined {
|
|
66
|
+
return this.args.prop;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@localCopy('args.visible', true)
|
|
70
|
+
visible!: boolean;
|
|
71
|
+
|
|
72
|
+
@localCopy('args.sortable', true)
|
|
73
|
+
sortable!: boolean;
|
|
74
|
+
|
|
75
|
+
@localCopy('args.sort')
|
|
76
|
+
sort: SortDirection | null | undefined;
|
|
77
|
+
|
|
78
|
+
@localCopy('args.filterable', true)
|
|
79
|
+
filterable!: boolean;
|
|
80
|
+
|
|
81
|
+
get filter(): string | undefined {
|
|
82
|
+
return this.args.filter;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get filterFunction(): FilterFunction | undefined {
|
|
86
|
+
return this.args.filterFunction;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get filterUsing(): unknown {
|
|
90
|
+
return this.args.filterUsing;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get columnClass(): string | undefined {
|
|
94
|
+
return this.args.columnClass;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@localCopy('args.name')
|
|
98
|
+
name: string | undefined;
|
|
99
|
+
|
|
100
|
+
get isAscSorted(): boolean {
|
|
101
|
+
return this.sort === 'asc';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get isDescSorted(): boolean {
|
|
105
|
+
return this.sort === 'desc';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get isSorted(): boolean {
|
|
109
|
+
return this.isAscSorted || this.isDescSorted;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get normalizedSortSequence(): string[] {
|
|
113
|
+
const sortSequence = this.args.sortSequence;
|
|
114
|
+
assert(
|
|
115
|
+
'@sortSequence must be either a comma-separated string or an array. Got `${sortSequence}.`',
|
|
116
|
+
Array.isArray(sortSequence) || typeof sortSequence === 'string',
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (Array.isArray(sortSequence)) {
|
|
120
|
+
return sortSequence;
|
|
121
|
+
} else if (typeof sortSequence === 'string') {
|
|
122
|
+
return sortSequence.split(',').map((s: string) => s.trim());
|
|
123
|
+
} else {
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
constructor(owner: Owner, args: ColumnSignature['Args']) {
|
|
129
|
+
super(owner, args);
|
|
130
|
+
|
|
131
|
+
this.args.parent?.registerColumn(this);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
willDestroy(): void {
|
|
135
|
+
super.willDestroy();
|
|
136
|
+
this.args.parent?.unregisterColumn(this);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
updateName = modifier((element: Element) => {
|
|
140
|
+
if (!this.args.name) {
|
|
141
|
+
this.name = element.textContent?.trim();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
@action
|
|
146
|
+
handleClick(e: MouseEvent): void {
|
|
147
|
+
if (this.sortable && this.args.onClick) {
|
|
148
|
+
this.args.onClick(this, e);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
<template>
|
|
153
|
+
{{! template-lint-disable no-invalid-interactive }}
|
|
154
|
+
{{#if this.visible}}
|
|
155
|
+
<th
|
|
156
|
+
role={{if this.sortable "button"}}
|
|
157
|
+
class="{{@class}}
|
|
158
|
+
{{@theme.theadCell}}
|
|
159
|
+
{{if this.sortable @theme.sorting.columnSortable}}
|
|
160
|
+
{{if this.isSorted @theme.sorting.columnSorted}}
|
|
161
|
+
{{if this.isAscSorted @theme.sorting.columnSortedAsc}}
|
|
162
|
+
{{if this.isDescSorted @theme.sorting.columnSortedDesc}}"
|
|
163
|
+
{{on "click" this.handleClick}}
|
|
164
|
+
{{this.updateName}}
|
|
165
|
+
...attributes
|
|
166
|
+
>
|
|
167
|
+
{{yield
|
|
168
|
+
(hash
|
|
169
|
+
isSorted=this.isSorted
|
|
170
|
+
isAscSorted=this.isAscSorted
|
|
171
|
+
isDescSorted=this.isDescSorted
|
|
172
|
+
)
|
|
173
|
+
}}
|
|
174
|
+
</th>
|
|
175
|
+
{{/if}}
|
|
176
|
+
</template>
|
|
177
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
|
|
3
|
+
import { hash } from '@ember/helper';
|
|
4
|
+
|
|
5
|
+
import type { WithBoundArgs } from '@glint/template';
|
|
6
|
+
|
|
7
|
+
import Column from './row/column.gts';
|
|
8
|
+
import type { ColumnParent } from './row/column.gts';
|
|
9
|
+
import Cell from './row/cell.gts';
|
|
10
|
+
import type { ColumnDefinition, SortDirection, Theme } from '../../../types.ts';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
Renders a `<tr>` element and yields the column and cell component.
|
|
14
|
+
```hbs
|
|
15
|
+
<table.thead as |head|>
|
|
16
|
+
<head.row as |row|>
|
|
17
|
+
<row.column @prop="firstName" as |column|>
|
|
18
|
+
First name
|
|
19
|
+
{{if column.isAscSorted "(sorted asc)"}}
|
|
20
|
+
{{if column.isDescSorted "(sorted desc)"}}
|
|
21
|
+
</row.column>
|
|
22
|
+
</head.row>
|
|
23
|
+
</table.thead>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
@class THeadRow
|
|
27
|
+
@yield {Component} column
|
|
28
|
+
@yield {Component} cell
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
interface THeadCellLike {
|
|
32
|
+
prop?: string;
|
|
33
|
+
column?: ColumnDefinition;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface THeadRowSignature {
|
|
37
|
+
Element: HTMLTableRowElement;
|
|
38
|
+
Args: {
|
|
39
|
+
trClass?: string;
|
|
40
|
+
theme?: Theme;
|
|
41
|
+
sortable?: boolean;
|
|
42
|
+
sortSequence?: SortDirection[] | string;
|
|
43
|
+
onColumnClick?: (column: Column, e: MouseEvent) => void;
|
|
44
|
+
columns: ColumnDefinition[];
|
|
45
|
+
parent?: ColumnParent;
|
|
46
|
+
};
|
|
47
|
+
Blocks: {
|
|
48
|
+
default: [
|
|
49
|
+
{
|
|
50
|
+
column: WithBoundArgs<
|
|
51
|
+
typeof Column,
|
|
52
|
+
'sortable' | 'sortSequence' | 'onClick' | 'theme' | 'parent'
|
|
53
|
+
>;
|
|
54
|
+
cell: WithBoundArgs<typeof Cell, 'theme' | 'parent'>;
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default class THeadRow extends Component<THeadRowSignature> {
|
|
61
|
+
cells: THeadCellLike[] = [];
|
|
62
|
+
|
|
63
|
+
registerCell(cell: THeadCellLike): ColumnDefinition | undefined {
|
|
64
|
+
let column: ColumnDefinition | undefined;
|
|
65
|
+
|
|
66
|
+
if (cell.prop) {
|
|
67
|
+
column = this.args.columns.find((c) => c.prop === cell.prop);
|
|
68
|
+
cell.column = column;
|
|
69
|
+
} else {
|
|
70
|
+
const index = this.cells.length;
|
|
71
|
+
column = this.args.columns[index];
|
|
72
|
+
|
|
73
|
+
return column;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.cells.push(cell);
|
|
77
|
+
|
|
78
|
+
return column;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
unregisterCell(cell: THeadCellLike): void {
|
|
82
|
+
const cells = this.cells;
|
|
83
|
+
const index = cells.indexOf(cell);
|
|
84
|
+
|
|
85
|
+
cells.splice(index, 1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
<template>
|
|
89
|
+
<tr class="{{@trClass}} {{@theme.theadRow}} {{@theme.row}}" ...attributes>
|
|
90
|
+
{{yield
|
|
91
|
+
(hash
|
|
92
|
+
column=(component
|
|
93
|
+
Column
|
|
94
|
+
sortable=@sortable
|
|
95
|
+
sortSequence=@sortSequence
|
|
96
|
+
onClick=@onColumnClick
|
|
97
|
+
theme=@theme
|
|
98
|
+
parent=@parent
|
|
99
|
+
)
|
|
100
|
+
cell=(component Cell theme=@theme parent=this)
|
|
101
|
+
)
|
|
102
|
+
}}
|
|
103
|
+
</tr>
|
|
104
|
+
</template>
|
|
105
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { TemplateOnlyComponent } from '@ember/component/template-only';
|
|
2
|
+
|
|
3
|
+
import { hash } from '@ember/helper';
|
|
4
|
+
|
|
5
|
+
import type { WithBoundArgs } from '@glint/template';
|
|
6
|
+
|
|
7
|
+
import THeadRow from './thead/row.gts';
|
|
8
|
+
import type Column from './thead/row/column.gts';
|
|
9
|
+
import type { ColumnParent } from './thead/row/column.gts';
|
|
10
|
+
import type { ColumnDefinition, SortDirection, Theme } from '../../types.ts';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
Renders a `<thead>` element and yields the row component.
|
|
14
|
+
|
|
15
|
+
@class THead
|
|
16
|
+
@yield {object} head
|
|
17
|
+
@yield {Component} head.row
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface THeadSignature {
|
|
21
|
+
Element: HTMLTableSectionElement;
|
|
22
|
+
Args: {
|
|
23
|
+
theme?: Theme;
|
|
24
|
+
sortable?: boolean;
|
|
25
|
+
sortSequence?: SortDirection[] | string;
|
|
26
|
+
onColumnClick?: (column: Column, e: MouseEvent) => void;
|
|
27
|
+
columns: ColumnDefinition[];
|
|
28
|
+
parent?: ColumnParent;
|
|
29
|
+
};
|
|
30
|
+
Blocks: {
|
|
31
|
+
default: [
|
|
32
|
+
{
|
|
33
|
+
row: WithBoundArgs<
|
|
34
|
+
typeof THeadRow,
|
|
35
|
+
| 'sortable'
|
|
36
|
+
| 'sortSequence'
|
|
37
|
+
| 'onColumnClick'
|
|
38
|
+
| 'columns'
|
|
39
|
+
| 'theme'
|
|
40
|
+
| 'parent'
|
|
41
|
+
>;
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const THeadComponent: TemplateOnlyComponent<THeadSignature> = <template>
|
|
48
|
+
<thead class={{@theme.thead}} ...attributes>
|
|
49
|
+
{{yield
|
|
50
|
+
(hash
|
|
51
|
+
row=(component
|
|
52
|
+
THeadRow
|
|
53
|
+
sortable=@sortable
|
|
54
|
+
sortSequence=@sortSequence
|
|
55
|
+
onColumnClick=@onColumnClick
|
|
56
|
+
columns=@columns
|
|
57
|
+
theme=@theme
|
|
58
|
+
parent=@parent
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
}}
|
|
62
|
+
</thead>
|
|
63
|
+
</template>;
|
|
64
|
+
|
|
65
|
+
export default THeadComponent;
|