@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.
Files changed (130) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +9 -115
  3. package/declarations/components/yeti-table/body.d.ts +32 -0
  4. package/declarations/components/yeti-table/body.d.ts.map +1 -0
  5. package/declarations/components/yeti-table/header.d.ts +33 -0
  6. package/declarations/components/yeti-table/header.d.ts.map +1 -0
  7. package/declarations/components/yeti-table/pagination.d.ts +40 -0
  8. package/declarations/components/yeti-table/pagination.d.ts.map +1 -0
  9. package/declarations/components/yeti-table/table.d.ts +21 -0
  10. package/declarations/components/yeti-table/table.d.ts.map +1 -0
  11. package/declarations/components/yeti-table/tbody/row/cell.d.ts +44 -0
  12. package/declarations/components/yeti-table/tbody/row/cell.d.ts.map +1 -0
  13. package/declarations/components/yeti-table/tbody/row.d.ts +37 -0
  14. package/declarations/components/yeti-table/tbody/row.d.ts.map +1 -0
  15. package/declarations/components/yeti-table/tbody.d.ts +29 -0
  16. package/declarations/components/yeti-table/tbody.d.ts.map +1 -0
  17. package/declarations/components/yeti-table/tfoot/row/cell.d.ts +40 -0
  18. package/declarations/components/yeti-table/tfoot/row/cell.d.ts.map +1 -0
  19. package/declarations/components/yeti-table/tfoot/row.d.ts +37 -0
  20. package/declarations/components/yeti-table/tfoot/row.d.ts.map +1 -0
  21. package/declarations/components/yeti-table/tfoot.d.ts +27 -0
  22. package/declarations/components/yeti-table/tfoot.d.ts.map +1 -0
  23. package/declarations/components/yeti-table/thead/row/cell.d.ts +54 -0
  24. package/declarations/components/yeti-table/thead/row/cell.d.ts.map +1 -0
  25. package/declarations/components/yeti-table/thead/row/column.d.ts +69 -0
  26. package/declarations/components/yeti-table/thead/row/column.d.ts.map +1 -0
  27. package/declarations/components/yeti-table/thead/row.d.ts +55 -0
  28. package/declarations/components/yeti-table/thead/row.d.ts.map +1 -0
  29. package/declarations/components/yeti-table/thead.d.ts +34 -0
  30. package/declarations/components/yeti-table/thead.d.ts.map +1 -0
  31. package/declarations/components/yeti-table.d.ts +107 -0
  32. package/declarations/components/yeti-table.d.ts.map +1 -0
  33. package/declarations/index.d.ts +1 -0
  34. package/declarations/index.d.ts.map +1 -0
  35. package/declarations/template-registry.d.ts +1 -0
  36. package/declarations/template-registry.d.ts.map +1 -0
  37. package/declarations/themes/default-theme.d.ts +3 -27
  38. package/declarations/themes/default-theme.d.ts.map +1 -1
  39. package/declarations/types.d.ts +82 -0
  40. package/declarations/types.d.ts.map +1 -0
  41. package/declarations/utils/create-regex.d.ts +1 -1
  42. package/declarations/utils/create-regex.d.ts.map +1 -1
  43. package/declarations/utils/filtering-utils.d.ts +2 -4
  44. package/declarations/utils/filtering-utils.d.ts.map +1 -1
  45. package/declarations/utils/sorting-utils.d.ts +6 -15
  46. package/declarations/utils/sorting-utils.d.ts.map +1 -1
  47. package/dist/components/yeti-table/body.js +19 -14
  48. package/dist/components/yeti-table/body.js.map +1 -1
  49. package/dist/components/yeti-table/header.js +10 -10
  50. package/dist/components/yeti-table/header.js.map +1 -1
  51. package/dist/components/yeti-table/pagination.js +14 -44
  52. package/dist/components/yeti-table/pagination.js.map +1 -1
  53. package/dist/components/yeti-table/table.js +1 -23
  54. package/dist/components/yeti-table/table.js.map +1 -1
  55. package/dist/components/yeti-table/tbody/row/cell.js +12 -12
  56. package/dist/components/yeti-table/tbody/row/cell.js.map +1 -1
  57. package/dist/components/yeti-table/tbody/row.js +15 -21
  58. package/dist/components/yeti-table/tbody/row.js.map +1 -1
  59. package/dist/components/yeti-table/tbody.js +1 -0
  60. package/dist/components/yeti-table/tbody.js.map +1 -1
  61. package/dist/components/yeti-table/tfoot/row/cell.js +9 -9
  62. package/dist/components/yeti-table/tfoot/row/cell.js.map +1 -1
  63. package/dist/components/yeti-table/tfoot/row.js +11 -11
  64. package/dist/components/yeti-table/tfoot/row.js.map +1 -1
  65. package/dist/components/yeti-table/tfoot.js +1 -0
  66. package/dist/components/yeti-table/tfoot.js.map +1 -1
  67. package/dist/components/yeti-table/thead/row/cell.js +11 -8
  68. package/dist/components/yeti-table/thead/row/cell.js.map +1 -1
  69. package/dist/components/yeti-table/thead/row/column.js +27 -128
  70. package/dist/components/yeti-table/thead/row/column.js.map +1 -1
  71. package/dist/components/yeti-table/thead/row.js +15 -15
  72. package/dist/components/yeti-table/thead/row.js.map +1 -1
  73. package/dist/components/yeti-table/thead.js +3 -22
  74. package/dist/components/yeti-table/thead.js.map +1 -1
  75. package/dist/components/yeti-table.js +99 -303
  76. package/dist/components/yeti-table.js.map +1 -1
  77. package/dist/index.js +2 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/template-registry.js +2 -0
  80. package/dist/template-registry.js.map +1 -0
  81. package/dist/themes/default-theme.js +3 -2
  82. package/dist/themes/default-theme.js.map +1 -1
  83. package/dist/types.js +2 -0
  84. package/dist/types.js.map +1 -0
  85. package/dist/utils/create-regex.js +6 -6
  86. package/dist/utils/create-regex.js.map +1 -1
  87. package/dist/utils/filtering-utils.js +20 -8
  88. package/dist/utils/filtering-utils.js.map +1 -1
  89. package/dist/utils/sorting-utils.js +13 -18
  90. package/dist/utils/sorting-utils.js.map +1 -1
  91. package/package.json +37 -16
  92. package/src/components/yeti-table/{body.gjs → body.gts} +49 -45
  93. package/src/components/yeti-table/header.gts +67 -0
  94. package/src/components/yeti-table/pagination.gts +118 -0
  95. package/src/components/yeti-table/table.gts +27 -0
  96. package/src/components/yeti-table/tbody/row/{cell.gjs → cell.gts} +38 -19
  97. package/src/components/yeti-table/tbody/row.gts +76 -0
  98. package/src/components/yeti-table/tbody.gts +53 -0
  99. package/src/components/yeti-table/tfoot/row/cell.gts +64 -0
  100. package/src/components/yeti-table/tfoot/row.gts +59 -0
  101. package/src/components/yeti-table/tfoot.gts +41 -0
  102. package/src/components/yeti-table/thead/row/{cell.gjs → cell.gts} +36 -13
  103. package/src/components/yeti-table/thead/row/column.gts +177 -0
  104. package/src/components/yeti-table/thead/row.gts +105 -0
  105. package/src/components/yeti-table/thead.gts +65 -0
  106. package/src/components/yeti-table.gts +629 -0
  107. package/src/template-registry.ts +10 -0
  108. package/src/themes/{default-theme.js → default-theme.ts} +5 -1
  109. package/src/types.ts +94 -0
  110. package/src/utils/{create-regex.js → create-regex.ts} +10 -10
  111. package/src/utils/filtering-utils.ts +91 -0
  112. package/src/utils/{sorting-utils.js → sorting-utils.ts} +35 -26
  113. package/dist/_app_/themes/default-theme.js +0 -1
  114. package/dist/_app_/utils/create-regex.js +0 -1
  115. package/dist/_app_/utils/filtering-utils.js +0 -1
  116. package/dist/_app_/utils/sorting-utils.js +0 -1
  117. package/src/components/yeti-table/header.gjs +0 -54
  118. package/src/components/yeti-table/pagination.gjs +0 -155
  119. package/src/components/yeti-table/table.gjs +0 -34
  120. package/src/components/yeti-table/tbody/row.gjs +0 -89
  121. package/src/components/yeti-table/tbody.gjs +0 -55
  122. package/src/components/yeti-table/tfoot/row/cell.gjs +0 -45
  123. package/src/components/yeti-table/tfoot/row.gjs +0 -44
  124. package/src/components/yeti-table/tfoot.gjs +0 -33
  125. package/src/components/yeti-table/thead/row/column.gjs +0 -260
  126. package/src/components/yeti-table/thead/row.gjs +0 -71
  127. package/src/components/yeti-table/thead.gjs +0 -45
  128. package/src/components/yeti-table.gjs +0 -780
  129. package/src/utils/filtering-utils.js +0 -75
  130. /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 default class THeadCell extends Component {
32
- <template>
33
- {{#if this.column.visible}}
34
- <th class="{{@class}} {{@theme.theadCell}}" ...attributes>
35
- {{yield}}
36
- </th>
37
- {{/if}}
38
- </template>
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(...arguments);
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(...arguments);
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;