@universal-ember/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 (168) hide show
  1. package/dist/-private/-type-tests/plugin-properties.test.js +27 -0
  2. package/dist/-private/-type-tests/plugin-properties.test.js.map +1 -0
  3. package/dist/-private/-type-tests/plugin-with.test.js +20 -0
  4. package/dist/-private/-type-tests/plugin-with.test.js.map +1 -0
  5. package/dist/-private/-type-tests/plugins-accessors.test.js +36 -0
  6. package/dist/-private/-type-tests/plugins-accessors.test.js.map +1 -0
  7. package/dist/-private/-type-tests/plugins-signature-from.test.js +15 -0
  8. package/dist/-private/-type-tests/plugins-signature-from.test.js.map +1 -0
  9. package/dist/-private/-type-tests/plugins-signature-utils.test.js +36 -0
  10. package/dist/-private/-type-tests/plugins-signature-utils.test.js.map +1 -0
  11. package/dist/-private/-type-tests/table-api.test.js +17 -0
  12. package/dist/-private/-type-tests/table-api.test.js.map +1 -0
  13. package/dist/-private/-type-tests/table-config.test.js +55 -0
  14. package/dist/-private/-type-tests/table-config.test.js.map +1 -0
  15. package/dist/-private/column.js +62 -0
  16. package/dist/-private/column.js.map +1 -0
  17. package/dist/-private/ember-compat.js +17 -0
  18. package/dist/-private/ember-compat.js.map +1 -0
  19. package/dist/-private/interfaces/column.js +2 -0
  20. package/dist/-private/interfaces/column.js.map +1 -0
  21. package/dist/-private/interfaces/index.js +2 -0
  22. package/dist/-private/interfaces/index.js.map +1 -0
  23. package/dist/-private/interfaces/modifier.js +2 -0
  24. package/dist/-private/interfaces/modifier.js.map +1 -0
  25. package/dist/-private/interfaces/pagination.js +2 -0
  26. package/dist/-private/interfaces/pagination.js.map +1 -0
  27. package/dist/-private/interfaces/plugins.js +2 -0
  28. package/dist/-private/interfaces/plugins.js.map +1 -0
  29. package/dist/-private/interfaces/preferences.js +2 -0
  30. package/dist/-private/interfaces/preferences.js.map +1 -0
  31. package/dist/-private/interfaces/selection.js +2 -0
  32. package/dist/-private/interfaces/selection.js.map +1 -0
  33. package/dist/-private/interfaces/table.js +2 -0
  34. package/dist/-private/interfaces/table.js.map +1 -0
  35. package/dist/-private/js-helper.js +55 -0
  36. package/dist/-private/js-helper.js.map +1 -0
  37. package/dist/-private/preferences.js +143 -0
  38. package/dist/-private/preferences.js.map +1 -0
  39. package/dist/-private/private-types.js +2 -0
  40. package/dist/-private/private-types.js.map +1 -0
  41. package/dist/-private/row.js +51 -0
  42. package/dist/-private/row.js.map +1 -0
  43. package/dist/-private/table.js +273 -0
  44. package/dist/-private/table.js.map +1 -0
  45. package/dist/-private/utils.js +15 -0
  46. package/dist/-private/utils.js.map +1 -0
  47. package/dist/_rollupPluginBabelHelpers-BpiaYhlf.js +63 -0
  48. package/dist/_rollupPluginBabelHelpers-BpiaYhlf.js.map +1 -0
  49. package/dist/index.js +4 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/plugins/-private/base.js +524 -0
  52. package/dist/plugins/-private/base.js.map +1 -0
  53. package/dist/plugins/-private/utils.js +103 -0
  54. package/dist/plugins/-private/utils.js.map +1 -0
  55. package/dist/plugins/column-reordering/helpers.js +44 -0
  56. package/dist/plugins/column-reordering/helpers.js.map +1 -0
  57. package/dist/plugins/column-reordering/index.js +3 -0
  58. package/dist/plugins/column-reordering/index.js.map +1 -0
  59. package/dist/plugins/column-reordering/plugin.js +359 -0
  60. package/dist/plugins/column-reordering/plugin.js.map +1 -0
  61. package/dist/plugins/column-reordering/utils.js +34 -0
  62. package/dist/plugins/column-reordering/utils.js.map +1 -0
  63. package/dist/plugins/column-resizing/handle.js +241 -0
  64. package/dist/plugins/column-resizing/handle.js.map +1 -0
  65. package/dist/plugins/column-resizing/helpers.js +71 -0
  66. package/dist/plugins/column-resizing/helpers.js.map +1 -0
  67. package/dist/plugins/column-resizing/index.js +4 -0
  68. package/dist/plugins/column-resizing/index.js.map +1 -0
  69. package/dist/plugins/column-resizing/plugin.js +328 -0
  70. package/dist/plugins/column-resizing/plugin.js.map +1 -0
  71. package/dist/plugins/column-resizing/resize-observer.js +44 -0
  72. package/dist/plugins/column-resizing/resize-observer.js.map +1 -0
  73. package/dist/plugins/column-resizing/utils.js +44 -0
  74. package/dist/plugins/column-resizing/utils.js.map +1 -0
  75. package/dist/plugins/column-visibility/helpers.js +25 -0
  76. package/dist/plugins/column-visibility/helpers.js.map +1 -0
  77. package/dist/plugins/column-visibility/index.js +3 -0
  78. package/dist/plugins/column-visibility/index.js.map +1 -0
  79. package/dist/plugins/column-visibility/plugin.js +92 -0
  80. package/dist/plugins/column-visibility/plugin.js.map +1 -0
  81. package/dist/plugins/data-sorting/helpers.js +49 -0
  82. package/dist/plugins/data-sorting/helpers.js.map +1 -0
  83. package/dist/plugins/data-sorting/index.js +4 -0
  84. package/dist/plugins/data-sorting/index.js.map +1 -0
  85. package/dist/plugins/data-sorting/plugin.js +132 -0
  86. package/dist/plugins/data-sorting/plugin.js.map +1 -0
  87. package/dist/plugins/data-sorting/types.js +14 -0
  88. package/dist/plugins/data-sorting/types.js.map +1 -0
  89. package/dist/plugins/index.js +3 -0
  90. package/dist/plugins/index.js.map +1 -0
  91. package/dist/plugins/metadata/helpers.js +12 -0
  92. package/dist/plugins/metadata/helpers.js.map +1 -0
  93. package/dist/plugins/metadata/index.js +3 -0
  94. package/dist/plugins/metadata/index.js.map +1 -0
  95. package/dist/plugins/metadata/plugin.js +25 -0
  96. package/dist/plugins/metadata/plugin.js.map +1 -0
  97. package/dist/plugins/row-selection/helpers.js +10 -0
  98. package/dist/plugins/row-selection/helpers.js.map +1 -0
  99. package/dist/plugins/row-selection/index.js +3 -0
  100. package/dist/plugins/row-selection/index.js.map +1 -0
  101. package/dist/plugins/row-selection/plugin.js +118 -0
  102. package/dist/plugins/row-selection/plugin.js.map +1 -0
  103. package/dist/plugins/sticky-columns/helpers.js +49 -0
  104. package/dist/plugins/sticky-columns/helpers.js.map +1 -0
  105. package/dist/plugins/sticky-columns/index.js +3 -0
  106. package/dist/plugins/sticky-columns/index.js.map +1 -0
  107. package/dist/plugins/sticky-columns/plugin.js +139 -0
  108. package/dist/plugins/sticky-columns/plugin.js.map +1 -0
  109. package/dist/test-support/index.js +62 -0
  110. package/dist/test-support/index.js.map +1 -0
  111. package/dist/utils.js +77 -0
  112. package/dist/utils.js.map +1 -0
  113. package/package.json +3 -2
  114. package/src/-private/-type-tests/plugin-properties.test.ts +38 -0
  115. package/src/-private/-type-tests/plugin-with.test.ts +23 -0
  116. package/src/-private/-type-tests/plugins-accessors.test.ts +86 -0
  117. package/src/-private/-type-tests/plugins-signature-from.test.ts +66 -0
  118. package/src/-private/-type-tests/plugins-signature-utils.test.ts +154 -0
  119. package/src/-private/-type-tests/table-api.test.ts +20 -0
  120. package/src/-private/-type-tests/table-config.test.ts +70 -0
  121. package/src/-private/column.ts +67 -0
  122. package/src/-private/ember-compat.ts +26 -0
  123. package/src/-private/interfaces/column.ts +73 -0
  124. package/src/-private/interfaces/index.ts +7 -0
  125. package/src/-private/interfaces/modifier.ts +7 -0
  126. package/src/-private/interfaces/pagination.ts +13 -0
  127. package/src/-private/interfaces/plugins.ts +349 -0
  128. package/src/-private/interfaces/preferences.ts +82 -0
  129. package/src/-private/interfaces/selection.ts +38 -0
  130. package/src/-private/interfaces/table.ts +121 -0
  131. package/src/-private/js-helper.ts +65 -0
  132. package/src/-private/preferences.ts +176 -0
  133. package/src/-private/private-types.ts +8 -0
  134. package/src/-private/row.ts +66 -0
  135. package/src/-private/table.ts +310 -0
  136. package/src/-private/utils.ts +21 -0
  137. package/src/index.ts +25 -0
  138. package/src/plugins/-private/base.ts +836 -0
  139. package/src/plugins/-private/utils.ts +166 -0
  140. package/src/plugins/column-reordering/helpers.ts +50 -0
  141. package/src/plugins/column-reordering/index.ts +6 -0
  142. package/src/plugins/column-reordering/plugin.ts +489 -0
  143. package/src/plugins/column-reordering/utils.ts +48 -0
  144. package/src/plugins/column-resizing/handle.ts +280 -0
  145. package/src/plugins/column-resizing/helpers.ts +79 -0
  146. package/src/plugins/column-resizing/index.ts +7 -0
  147. package/src/plugins/column-resizing/plugin.ts +490 -0
  148. package/src/plugins/column-resizing/resize-observer.ts +48 -0
  149. package/src/plugins/column-resizing/utils.ts +54 -0
  150. package/src/plugins/column-visibility/helpers.ts +28 -0
  151. package/src/plugins/column-visibility/index.ts +6 -0
  152. package/src/plugins/column-visibility/plugin.ts +155 -0
  153. package/src/plugins/data-sorting/helpers.ts +56 -0
  154. package/src/plugins/data-sorting/index.ts +8 -0
  155. package/src/plugins/data-sorting/plugin.ts +222 -0
  156. package/src/plugins/data-sorting/types.ts +26 -0
  157. package/src/plugins/index.ts +20 -0
  158. package/src/plugins/metadata/helpers.ts +12 -0
  159. package/src/plugins/metadata/index.ts +7 -0
  160. package/src/plugins/metadata/plugin.ts +26 -0
  161. package/src/plugins/row-selection/helpers.ts +13 -0
  162. package/src/plugins/row-selection/index.ts +7 -0
  163. package/src/plugins/row-selection/plugin.ts +218 -0
  164. package/src/plugins/sticky-columns/helpers.ts +59 -0
  165. package/src/plugins/sticky-columns/index.ts +7 -0
  166. package/src/plugins/sticky-columns/plugin.ts +201 -0
  167. package/src/test-support/index.ts +76 -0
  168. package/src/utils.ts +85 -0
@@ -0,0 +1,155 @@
1
+ import { cached } from '@glimmer/tracking';
2
+ import { action } from '@ember/object';
3
+
4
+ import { BasePlugin, meta, options, preferences } from '../-private/base.ts';
5
+
6
+ import type { Plugin, PluginPreferences } from '../../plugins/index.ts';
7
+ import type { Column, Table } from '../../index.ts';
8
+
9
+ interface ColumnVisibilityPreferences extends PluginPreferences {
10
+ columns: {
11
+ [columnKey: string]: {
12
+ isVisible?: boolean;
13
+ };
14
+ };
15
+ }
16
+
17
+ declare module '@universal-ember/table/plugins' {
18
+ interface Registry {
19
+ ColumnVisibility?: ColumnVisibilityPreferences;
20
+ 'column-visibility'?: ColumnVisibilityPreferences;
21
+ }
22
+ }
23
+
24
+ export interface Signature {
25
+ Meta: {
26
+ Table: TableMeta;
27
+ Column: ColumnMeta;
28
+ };
29
+ Options: {
30
+ Plugin: {
31
+ enabled?: boolean;
32
+ };
33
+ Column: {
34
+ /**
35
+ * The default visibilty of the column, when rendered.
36
+ * The column can still be toggled on and off.
37
+ *
38
+ * When interacting with preferences, the value stored in preferenced
39
+ * will be the inverse of this value (to save space in storage).
40
+ */
41
+ isVisible?: boolean;
42
+ };
43
+ };
44
+ }
45
+
46
+ export class ColumnVisibility
47
+ extends BasePlugin<Signature>
48
+ implements Plugin<Signature>
49
+ {
50
+ name = 'column-visibility';
51
+ static features = ['columnVisibility'];
52
+
53
+ meta = {
54
+ column: ColumnMeta,
55
+ table: TableMeta,
56
+ };
57
+
58
+ reset() {
59
+ preferences.forAllColumns(this.table, ColumnVisibility).delete('isVisible');
60
+ }
61
+
62
+ get columns() {
63
+ return meta.forTable(this.table, ColumnVisibility).visibleColumns;
64
+ }
65
+ }
66
+
67
+ export class ColumnMeta<Data = unknown> {
68
+ constructor(private column: Column<Data>) {}
69
+
70
+ get isVisible(): boolean {
71
+ const columnPreferences = preferences.forColumn(
72
+ this.column,
73
+ ColumnVisibility,
74
+ );
75
+ const columnOptions = options.forColumn(this.column, ColumnVisibility);
76
+
77
+ return Boolean(
78
+ columnPreferences.get('isVisible') ?? columnOptions?.isVisible ?? true,
79
+ );
80
+ }
81
+
82
+ get isHidden(): boolean {
83
+ return !this.isVisible;
84
+ }
85
+
86
+ hide = () => {
87
+ if (!this.isVisible) return;
88
+
89
+ const myPreferences = preferences.forColumn(this.column, ColumnVisibility);
90
+ const myOptions = options.forColumn(this.column, ColumnVisibility);
91
+ const currentSaved = myPreferences.get('isVisible');
92
+ const willBeDefault = Boolean(currentSaved) === !myOptions?.isVisible;
93
+
94
+ if (willBeDefault) {
95
+ myPreferences.set('isVisible', false);
96
+ // TODO: open an issue about tracked-built-ins' delete not being reactive
97
+ // myPreferences.delete('isVisible');
98
+
99
+ return;
100
+ }
101
+
102
+ myPreferences.set('isVisible', false);
103
+ };
104
+
105
+ show = () => {
106
+ if (this.isVisible) return;
107
+
108
+ const myPreferences = preferences.forColumn(this.column, ColumnVisibility);
109
+ const myOptions = options.forColumn(this.column, ColumnVisibility);
110
+ const currentSaved = myPreferences.get('isVisible');
111
+ const willBeDefault = currentSaved === !myOptions?.isVisible;
112
+
113
+ if (willBeDefault) {
114
+ myPreferences.set('isVisible', true);
115
+ // TODO: open an issue about tracked-built-ins' delete not being reactive
116
+ // myPreferences.delete('isVisible');
117
+
118
+ return;
119
+ }
120
+
121
+ myPreferences.set('isVisible', true);
122
+ };
123
+
124
+ toggle = () => {
125
+ if (this.isVisible) {
126
+ this.hide();
127
+
128
+ return;
129
+ }
130
+
131
+ this.show();
132
+ };
133
+ }
134
+
135
+ export class TableMeta<Data = unknown> {
136
+ constructor(private table: Table<Data>) {}
137
+
138
+ @cached
139
+ get visibleColumns(): Column<Data>[] {
140
+ const allColumns = this.table.columns.values();
141
+
142
+ return allColumns.filter((column) => {
143
+ const columnMeta = meta.forColumn(column, ColumnVisibility);
144
+
145
+ return columnMeta.isVisible;
146
+ });
147
+ }
148
+
149
+ @action
150
+ toggleColumnVisibility(column: Column<Data>) {
151
+ const columnMeta = meta.forColumn(column, ColumnVisibility);
152
+
153
+ columnMeta.toggle();
154
+ }
155
+ }
@@ -0,0 +1,56 @@
1
+ import { meta } from '../-private/base.ts';
2
+ import { Sorting } from './plugin.ts';
3
+
4
+ import type { Column } from '../../index.ts';
5
+
6
+ /**
7
+ * Query a specific column's current sort direction
8
+ */
9
+ export const sortDirection = (column: Column) =>
10
+ meta.forColumn(column, Sorting).sortDirection;
11
+
12
+ /**
13
+ * Ask if a column is sortable
14
+ */
15
+ export const isSortable = (column: Column) =>
16
+ meta.forColumn(column, Sorting).isSortable;
17
+
18
+ /**
19
+ * Ask if a column is ascending
20
+ */
21
+ export const isAscending = (column: Column) =>
22
+ meta.forColumn(column, Sorting).isAscending;
23
+
24
+ /**
25
+ * Ask if a column is sorted descending
26
+ */
27
+ export const isDescending = (column: Column) =>
28
+ meta.forColumn(column, Sorting).isDescending;
29
+
30
+ /**
31
+ * Ask if a column is not sorted
32
+ */
33
+ export const isUnsorted = (column: Column) =>
34
+ meta.forColumn(column, Sorting).isUnsorted;
35
+
36
+ /**
37
+ * Sort the specified column's data using a tri-toggle.
38
+ *
39
+ * States go in this order:
40
+ * Ascending => None => Descending
41
+ * ⬑ ---------- <= ---------- ↲
42
+ */
43
+ export const sort = (column: Column) =>
44
+ meta.forTable(column.table, Sorting).handleSort(column);
45
+
46
+ /**
47
+ * Toggle a column between descending and not unsorted states
48
+ */
49
+ export const sortDescending = (column: Column) =>
50
+ meta.forTable(column.table, Sorting).toggleDescending(column);
51
+
52
+ /**
53
+ * Toggle a column between ascending and not unsorted states
54
+ */
55
+ export const sortAscending = (column: Column) =>
56
+ meta.forTable(column.table, Sorting).toggleAscending(column);
@@ -0,0 +1,8 @@
1
+ export * from './helpers.ts';
2
+ export { Sorting as Plugin } from './plugin.ts';
3
+ export { Sorting as DataSorting } from './plugin.ts';
4
+ export { SortDirection } from './types.ts';
5
+
6
+ // Public Types
7
+ export type { Signature } from './plugin.ts';
8
+ export type { Sort, SortItem } from './types.ts';
@@ -0,0 +1,222 @@
1
+ import { cached } from '@glimmer/tracking';
2
+ import { action } from '@ember/object';
3
+
4
+ import { BasePlugin, meta, options } from '../-private/base.ts';
5
+ import { SortDirection } from './types.ts';
6
+
7
+ import type { Sort, SortItem } from './types.ts';
8
+ import type { ColumnApi, PluginPreferences } from '../../plugins/index.ts';
9
+ import type { Column, Table } from '../../index.ts';
10
+
11
+ interface SortingPreferences extends PluginPreferences {
12
+ table: {
13
+ sorts?: Sort[];
14
+ };
15
+ }
16
+
17
+ declare module '@universal-ember/table/plugins' {
18
+ interface Registry {
19
+ Sorting?: SortingPreferences;
20
+ sorting?: SortingPreferences;
21
+ }
22
+ }
23
+
24
+ export interface Signature<DataType = unknown> {
25
+ Meta: {
26
+ Column: ColumnMeta;
27
+ Table: TableMeta;
28
+ };
29
+ Options: {
30
+ Plugin: Options<DataType>;
31
+ Column: ColumnOptions;
32
+ };
33
+ }
34
+
35
+ interface Options<DataType = unknown> {
36
+ /**
37
+ * Handler for interpreting sort requests from the headless table.
38
+ *
39
+ * Does not actually do the sorting.
40
+ *
41
+ * if omitted, the DataSorting plugin will disable itself
42
+ */
43
+ onSort?: (sorts: SortItem<DataType>[]) => void;
44
+ /**
45
+ * Provided sorts that the table should assume are true.
46
+ *
47
+ * if omitted, the DataSorting plugin will disable itself
48
+ */
49
+ sorts?: SortItem<DataType>[];
50
+ }
51
+
52
+ interface ColumnOptions {
53
+ /**
54
+ * Opt in or out of sorting for a particular column.
55
+ * Default is true.
56
+ */
57
+ isSortable?: boolean;
58
+ /**
59
+ * Use this key instead of the `key` on the column config.
60
+ * This has no bearing on any behavior in the plugin, *other than*,
61
+ * swapping out the `property`'s value on the `SortItem`s passed to
62
+ * the table plugin config's `onSort` callback
63
+ */
64
+ sortProperty?: string;
65
+ }
66
+
67
+ /**
68
+ * Manages basic data-sorting behaviors. Ascending -> Descending -> None
69
+ *
70
+ * This plugin requires a table plugin configuration, `onSort` for handling *how* sorting happens.
71
+ * communicating back to the table that sorting has succeeded can be done by setting the `sorts`
72
+ * property in the table plugin configuration.
73
+ *
74
+ * Note that this plugin doesn't actually sort the data, as data management is not the responsibility
75
+ * of the table, but of the surrounding context providing the data to the table. So sorting can happen
76
+ * client-side still, just in a component -- much the same way you'd handel sorting via API requests.
77
+ *
78
+ * This plugin is for *conveying* what the current sorts are, rather than _doing_ the sorting.
79
+ */
80
+ export class Sorting<DataType = unknown> extends BasePlugin<
81
+ Signature<DataType>
82
+ > {
83
+ name = 'data-sorting';
84
+
85
+ meta = {
86
+ column: ColumnMeta,
87
+ table: TableMeta,
88
+ };
89
+
90
+ headerCellModifier = (element: HTMLElement, { column }: ColumnApi) => {
91
+ const columnMeta = meta.forColumn(column, Sorting);
92
+
93
+ element.setAttribute('data-test-is-sortable', `${columnMeta.isSortable}`);
94
+ element.setAttribute('aria-sort', `${columnMeta.sortDirection}`);
95
+ };
96
+ }
97
+
98
+ export class ColumnMeta {
99
+ constructor(private column: Column) {}
100
+
101
+ @cached
102
+ get options() {
103
+ return options.forColumn(this.column, Sorting);
104
+ }
105
+
106
+ get isSortable() {
107
+ return this.options?.isSortable ?? this.tableMeta.isSortable;
108
+ }
109
+
110
+ get tableMeta() {
111
+ return meta.forTable(this.column.table, Sorting);
112
+ }
113
+
114
+ get sortDirection() {
115
+ const sort = this.tableMeta.sorts.find(
116
+ (sort) => sort.property === this.sortProperty,
117
+ );
118
+
119
+ return sort?.direction ?? SortDirection.None;
120
+ }
121
+
122
+ get isAscending() {
123
+ return this.sortDirection === SortDirection.Ascending;
124
+ }
125
+
126
+ get isDescending() {
127
+ return this.sortDirection === SortDirection.Descending;
128
+ }
129
+
130
+ get isUnsorted() {
131
+ return this.sortDirection === SortDirection.None;
132
+ }
133
+
134
+ get sortProperty() {
135
+ return this.options?.sortProperty ?? this.column.config.key;
136
+ }
137
+ }
138
+
139
+ export class TableMeta {
140
+ constructor(private table: Table) {}
141
+
142
+ @cached
143
+ get options() {
144
+ return options.forTable(this.table, Sorting);
145
+ }
146
+
147
+ get sorts() {
148
+ return this.options?.sorts ?? [];
149
+ }
150
+
151
+ get isSortable() {
152
+ return Boolean(this.options?.onSort) && Boolean(this.options?.sorts);
153
+ }
154
+
155
+ get onSort() {
156
+ return this.options?.onSort;
157
+ }
158
+
159
+ @action
160
+ handleSort(column: Column) {
161
+ const columnMeta = meta.forColumn(column, Sorting);
162
+
163
+ if (!columnMeta.sortProperty) {
164
+ return;
165
+ }
166
+
167
+ if (columnMeta.sortDirection === SortDirection.Ascending) {
168
+ this.onSort?.([]);
169
+ } else if (columnMeta.sortDirection === SortDirection.Descending) {
170
+ this.onSort?.([
171
+ {
172
+ direction: SortDirection.Ascending,
173
+ property: columnMeta.sortProperty,
174
+ },
175
+ ]);
176
+ } else {
177
+ this.onSort?.([
178
+ {
179
+ direction: SortDirection.Descending,
180
+ property: columnMeta.sortProperty,
181
+ },
182
+ ]);
183
+ }
184
+ }
185
+
186
+ @action
187
+ toggleAscending(column: Column) {
188
+ const columnMeta = meta.forColumn(column, Sorting);
189
+
190
+ if (!columnMeta.sortProperty) {
191
+ return;
192
+ }
193
+
194
+ if (columnMeta.sortDirection === SortDirection.Ascending) {
195
+ return this.onSort?.([]);
196
+ }
197
+
198
+ this.onSort?.([
199
+ { direction: SortDirection.Ascending, property: columnMeta.sortProperty },
200
+ ]);
201
+ }
202
+
203
+ @action
204
+ toggleDescending(column: Column) {
205
+ const columnMeta = meta.forColumn(column, Sorting);
206
+
207
+ if (!columnMeta.sortProperty) {
208
+ return;
209
+ }
210
+
211
+ if (columnMeta.sortDirection === SortDirection.Descending) {
212
+ return this.onSort?.([]);
213
+ }
214
+
215
+ this.onSort?.([
216
+ {
217
+ direction: SortDirection.Descending,
218
+ property: columnMeta.sortProperty,
219
+ },
220
+ ]);
221
+ }
222
+ }
@@ -0,0 +1,26 @@
1
+ import type { ColumnKey } from '../../-private/interfaces';
2
+
3
+ export enum SortDirection {
4
+ Ascending = 'ascending',
5
+ Descending = 'descending',
6
+ None = 'none',
7
+ }
8
+
9
+ export interface Sort {
10
+ property: string;
11
+ direction: SortDirection;
12
+ }
13
+
14
+ export enum SortTransform {
15
+ Underscore = 'underscore',
16
+ Camelize = 'camelize',
17
+ }
18
+ export interface SortsOptions {
19
+ separator: string;
20
+ transform: string | null;
21
+ }
22
+
23
+ export interface SortItem<T> {
24
+ direction: SortDirection;
25
+ property: ColumnKey<T>;
26
+ }
@@ -0,0 +1,20 @@
1
+ // Public API
2
+ export {
3
+ BasePlugin,
4
+ columns,
5
+ hasPlugin,
6
+ meta,
7
+ options,
8
+ preferences,
9
+ } from './-private/base.ts';
10
+ export { applyStyles, removeStyles } from './-private/utils.ts';
11
+
12
+ // Public Types
13
+ export type { ColumnFeatures, TableFeatures } from './-private/base.ts';
14
+ export type {
15
+ ColumnApi,
16
+ Plugin,
17
+ PluginPreferences,
18
+ Registry,
19
+ } from '../-private/interfaces';
20
+ export type { PluginSignature } from '../-private/interfaces/plugins';
@@ -0,0 +1,12 @@
1
+ import { options } from '../-private/base.ts';
2
+ import { Metadata } from './plugin.ts';
3
+
4
+ import type { Column, Table } from '../../index.ts';
5
+
6
+ export const forColumn = (column: Column<any>, key: string) => {
7
+ return options.forColumn(column, Metadata)[key];
8
+ };
9
+
10
+ export const forTable = (table: Table<any>, key: string) => {
11
+ return options.forTable(table, Metadata)[key];
12
+ };
@@ -0,0 +1,7 @@
1
+ // Public API
2
+ export * from './helpers.ts';
3
+ export { Metadata } from './plugin.ts';
4
+ export { Metadata as Plugin } from './plugin.ts';
5
+
6
+ // Public types
7
+ export type { Signature } from './plugin.ts';
@@ -0,0 +1,26 @@
1
+ import { BasePlugin } from '../-private/base.ts';
2
+
3
+ /**
4
+ * Data stored per column or table can be arbitrary
5
+ *
6
+ */
7
+ type ArbitraryData = Record<string, any>;
8
+
9
+ export interface Signature<Data = ArbitraryData> {
10
+ Options: {
11
+ Column: Data;
12
+ Plugin: Data;
13
+ };
14
+ }
15
+
16
+ /**
17
+ * This plugin does noting,
18
+ * but gives consumer of it a safe way to store and associate "any" data with columns
19
+ * (and have a generic top-level bucket of data as well)
20
+ *
21
+ * This "metadata" stored per column per table is managed via the "options" part of the Signature, as
22
+ * "meta" is a term used for plugins for plugin authors.
23
+ */
24
+ export class Metadata<S extends Signature> extends BasePlugin<S> {
25
+ name = 'metadata';
26
+ }
@@ -0,0 +1,13 @@
1
+ import { meta } from '../-private/base.ts';
2
+ import { RowSelection } from './plugin.ts';
3
+
4
+ import type { Row } from '../../-private/row.ts';
5
+
6
+ export const isSelected = (row: Row<any>) =>
7
+ meta.forRow(row, RowSelection).isSelected;
8
+ export const select = (row: Row<any>) =>
9
+ meta.forRow(row, RowSelection).select();
10
+ export const deselect = (row: Row<any>) =>
11
+ meta.forRow(row, RowSelection).deselect();
12
+ export const toggle = (row: Row<any>) =>
13
+ meta.forRow(row, RowSelection).toggle();
@@ -0,0 +1,7 @@
1
+ // Public API
2
+ export * from './helpers.ts';
3
+ export { RowSelection as Plugin } from './plugin.ts';
4
+ export { RowSelection } from './plugin.ts';
5
+
6
+ // Public types
7
+ export type { Signature } from './plugin.ts';