@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,154 @@
1
+ import { expectTypeOf } from 'expect-type';
2
+
3
+ import type {
4
+ ColumnMetaFor,
5
+ ColumnOptionsFor,
6
+ EmptyObject,
7
+ OptionsFor,
8
+ PluginSignature,
9
+ RowMetaFor,
10
+ TableMetaFor,
11
+ } from '../interfaces/plugins';
12
+
13
+ class ATableMeta {
14
+ a = 1;
15
+ }
16
+ class AColumnMeta {
17
+ ac = 1;
18
+ }
19
+ class ARowMeta {
20
+ ar = 1;
21
+ }
22
+ interface AOptions {
23
+ ao: number;
24
+ }
25
+ interface AColumnOptions {
26
+ aco: number;
27
+ }
28
+
29
+ interface FullExtendedSignature extends PluginSignature {
30
+ Meta: {
31
+ Table: ATableMeta;
32
+ Column: AColumnMeta;
33
+ Row: ARowMeta;
34
+ };
35
+ Options: {
36
+ Plugin: AOptions;
37
+ Column: AColumnOptions;
38
+ };
39
+ }
40
+
41
+ expectTypeOf<
42
+ ColumnOptionsFor<FullExtendedSignature>
43
+ >().toEqualTypeOf<AColumnOptions>();
44
+ expectTypeOf<OptionsFor<FullExtendedSignature>>().toEqualTypeOf<AOptions>();
45
+ expectTypeOf<TableMetaFor<FullExtendedSignature>>().toEqualTypeOf<ATableMeta>();
46
+ expectTypeOf<
47
+ ColumnMetaFor<FullExtendedSignature>
48
+ >().toEqualTypeOf<AColumnMeta>();
49
+ expectTypeOf<RowMetaFor<FullExtendedSignature>>().toEqualTypeOf<ARowMeta>();
50
+
51
+ interface FullFreeformSignature {
52
+ Meta: {
53
+ Table: ATableMeta;
54
+ Column: AColumnMeta;
55
+ Row: ARowMeta;
56
+ };
57
+ Options: {
58
+ Plugin: AOptions;
59
+ Column: AColumnOptions;
60
+ };
61
+ }
62
+
63
+ expectTypeOf<
64
+ ColumnOptionsFor<FullFreeformSignature>
65
+ >().toEqualTypeOf<AColumnOptions>();
66
+ expectTypeOf<OptionsFor<FullFreeformSignature>>().toEqualTypeOf<AOptions>();
67
+ expectTypeOf<TableMetaFor<FullFreeformSignature>>().toEqualTypeOf<ATableMeta>();
68
+ expectTypeOf<
69
+ ColumnMetaFor<FullFreeformSignature>
70
+ >().toEqualTypeOf<AColumnMeta>();
71
+ expectTypeOf<RowMetaFor<FullFreeformSignature>>().toEqualTypeOf<ARowMeta>();
72
+
73
+ interface WithoutOptions {
74
+ Meta: {
75
+ Table: ATableMeta;
76
+ Column: AColumnMeta;
77
+ Row: ARowMeta;
78
+ };
79
+ }
80
+
81
+ expectTypeOf<ColumnOptionsFor<WithoutOptions>>().toEqualTypeOf<EmptyObject>();
82
+ expectTypeOf<OptionsFor<WithoutOptions>>().toEqualTypeOf<EmptyObject>();
83
+ expectTypeOf<TableMetaFor<WithoutOptions>>().toEqualTypeOf<ATableMeta>();
84
+ expectTypeOf<ColumnMetaFor<WithoutOptions>>().toEqualTypeOf<AColumnMeta>();
85
+ expectTypeOf<RowMetaFor<WithoutOptions>>().toEqualTypeOf<ARowMeta>();
86
+
87
+ interface WithoutMeta {
88
+ Options: {
89
+ Plugin: AOptions;
90
+ Column: AColumnOptions;
91
+ };
92
+ }
93
+
94
+ expectTypeOf<ColumnOptionsFor<WithoutMeta>>().toEqualTypeOf<AColumnOptions>();
95
+ expectTypeOf<OptionsFor<WithoutMeta>>().toEqualTypeOf<AOptions>();
96
+ expectTypeOf<TableMetaFor<WithoutMeta>>().toEqualTypeOf<never>();
97
+ expectTypeOf<ColumnMetaFor<WithoutMeta>>().toEqualTypeOf<never>();
98
+ expectTypeOf<RowMetaFor<WithoutMeta>>().toEqualTypeOf<never>();
99
+
100
+ expectTypeOf<
101
+ ColumnOptionsFor<{ Options: { Column: AColumnOptions } }>
102
+ >().toEqualTypeOf<AColumnOptions>();
103
+ expectTypeOf<
104
+ ColumnOptionsFor<{ Options: { Plugin: AOptions } }>
105
+ >().toEqualTypeOf<EmptyObject>();
106
+
107
+ expectTypeOf<
108
+ OptionsFor<{ Options: { Plugin: AOptions } }>
109
+ >().toEqualTypeOf<AOptions>();
110
+ expectTypeOf<
111
+ OptionsFor<{ Options: { Column: AColumnOptions } }>
112
+ >().toEqualTypeOf<EmptyObject>();
113
+
114
+ expectTypeOf<
115
+ TableMetaFor<{
116
+ Meta: {
117
+ Table: ATableMeta;
118
+ };
119
+ }>
120
+ >().toEqualTypeOf<ATableMeta>();
121
+ expectTypeOf<
122
+ TableMetaFor<{ Meta: { Column: AColumnMeta } }>
123
+ >().toEqualTypeOf<never>();
124
+ expectTypeOf<
125
+ TableMetaFor<{ Meta: { Row: ARowMeta } }>
126
+ >().toEqualTypeOf<never>();
127
+
128
+ expectTypeOf<
129
+ ColumnMetaFor<{
130
+ Meta: {
131
+ Table: ATableMeta;
132
+ };
133
+ }>
134
+ >().toEqualTypeOf<never>();
135
+ expectTypeOf<
136
+ ColumnMetaFor<{ Meta: { Column: AColumnMeta } }>
137
+ >().toEqualTypeOf<AColumnMeta>();
138
+ expectTypeOf<
139
+ ColumnMetaFor<{ Meta: { Row: ARowMeta } }>
140
+ >().toEqualTypeOf<never>();
141
+
142
+ expectTypeOf<
143
+ RowMetaFor<{
144
+ Meta: {
145
+ Table: ATableMeta;
146
+ };
147
+ }>
148
+ >().toEqualTypeOf<never>();
149
+ expectTypeOf<
150
+ RowMetaFor<{ Meta: { Column: AColumnMeta } }>
151
+ >().toEqualTypeOf<never>();
152
+ expectTypeOf<
153
+ RowMetaFor<{ Meta: { Row: ARowMeta } }>
154
+ >().toEqualTypeOf<ARowMeta>();
@@ -0,0 +1,20 @@
1
+ import { expectTypeOf } from 'expect-type';
2
+
3
+ import { ColumnReordering } from '../../plugins/column-reordering/index.ts';
4
+ import { ColumnResizing } from '../../plugins/column-resizing/index.ts';
5
+ import { DataSorting } from '../../plugins/data-sorting/index.ts';
6
+
7
+ import type { Table } from '../../index.ts';
8
+
9
+ // We're testing types, not behaviors
10
+ const x = 0 as unknown as Table<{ x: number }>;
11
+
12
+ //////////////////////////////
13
+ // <Table>#pluginOf
14
+ expectTypeOf(x.pluginOf(DataSorting)).toEqualTypeOf<DataSorting | undefined>();
15
+ expectTypeOf(x.pluginOf(ColumnReordering)).toEqualTypeOf<
16
+ ColumnReordering | undefined
17
+ >();
18
+ expectTypeOf(x.pluginOf(ColumnResizing)).toEqualTypeOf<
19
+ ColumnResizing | undefined
20
+ >();
@@ -0,0 +1,70 @@
1
+ import { expectTypeOf } from 'expect-type';
2
+
3
+ import { BasePlugin } from '../../plugins/-private/base.ts';
4
+ import { ColumnReordering } from '../../plugins/column-reordering/index.ts';
5
+ import { ColumnResizing } from '../../plugins/column-resizing/index.ts';
6
+ import { ColumnVisibility } from '../../plugins/column-visibility/index.ts';
7
+ import { DataSorting } from '../../plugins/data-sorting/index.ts';
8
+ import { StickyColumns } from '../../plugins/sticky-columns/index.ts';
9
+
10
+ import type { Plugins } from '../../plugins/-private/utils';
11
+ import type { SortItem } from '../../plugins/data-sorting';
12
+ import type { Plugin } from '../../plugins/index.ts';
13
+ import type { TableConfig } from '../../index.ts';
14
+ import type { Constructor } from '../../-private/private-types.ts';
15
+
16
+ type TablePluginConfig = NonNullable<TableConfig<unknown>['plugins']>;
17
+
18
+ /////////////////////////////////////////////
19
+ // Sanity checks
20
+ expectTypeOf<Plugins>().toMatchTypeOf<TablePluginConfig>();
21
+ expectTypeOf<Constructor<Plugin>[]>().toMatchTypeOf<TablePluginConfig>();
22
+ expectTypeOf<[Constructor<Plugin>]>().toMatchTypeOf<TablePluginConfig>();
23
+ expectTypeOf<
24
+ [Constructor<Plugin>, Constructor<Plugin>]
25
+ >().toMatchTypeOf<TablePluginConfig>();
26
+ expectTypeOf<Constructor<BasePlugin>[]>().toMatchTypeOf<TablePluginConfig>();
27
+ expectTypeOf<[Constructor<BasePlugin>]>().toMatchTypeOf<TablePluginConfig>();
28
+ expectTypeOf<
29
+ [Constructor<BasePlugin>, Constructor<BasePlugin>]
30
+ >().toMatchTypeOf<TablePluginConfig>();
31
+
32
+ class SomeClass {
33
+ foo = 'bar';
34
+ }
35
+ class LocalPlugin extends BasePlugin<{ Meta: { Table: SomeClass } }> {
36
+ name = 'local-plugin';
37
+ }
38
+
39
+ expectTypeOf([LocalPlugin]).toMatchTypeOf<TablePluginConfig>();
40
+
41
+ /////////////////////////////////////////////
42
+ // Making sure all plugins are subclassed appropriately
43
+ expectTypeOf(LocalPlugin).toMatchTypeOf<Constructor<BasePlugin<any>>>();
44
+ expectTypeOf(ColumnReordering).toMatchTypeOf<Constructor<BasePlugin<any>>>();
45
+ expectTypeOf(LocalPlugin).toMatchTypeOf<Constructor<Plugin<any>>>();
46
+ expectTypeOf(ColumnReordering).toMatchTypeOf<Constructor<Plugin<any>>>();
47
+
48
+ // Actual plugins match the actual table config
49
+ expectTypeOf([DataSorting]).toMatchTypeOf<TablePluginConfig>();
50
+ expectTypeOf([ColumnReordering]).toMatchTypeOf<TablePluginConfig>();
51
+ expectTypeOf([ColumnResizing]).toMatchTypeOf<TablePluginConfig>();
52
+ expectTypeOf([ColumnVisibility]).toMatchTypeOf<TablePluginConfig>();
53
+ expectTypeOf([StickyColumns]).toMatchTypeOf<TablePluginConfig>();
54
+
55
+ /////////////////////////////////////////////
56
+ // The various ways to define plugins
57
+ expectTypeOf([
58
+ DataSorting,
59
+ ColumnReordering,
60
+ ]).toMatchTypeOf<TablePluginConfig>();
61
+
62
+ const onSort = (_sorts: SortItem<number>[]) => {
63
+ /* intentionally empty */
64
+ };
65
+ const sorts: SortItem<number>[] = [];
66
+
67
+ expectTypeOf([DataSorting.with(() => ({}))]).toMatchTypeOf<TablePluginConfig>();
68
+ expectTypeOf([
69
+ DataSorting.with(() => ({ onSort, sorts })),
70
+ ]).toMatchTypeOf<TablePluginConfig>();
@@ -0,0 +1,67 @@
1
+ import { action, get } from '@ember/object';
2
+ import { isEmpty } from '@ember/utils';
3
+
4
+ import type { Row } from './row';
5
+ import type { Table } from './table';
6
+ import type { ContentValue } from '@glint/template';
7
+ import type { ColumnConfig } from './interfaces';
8
+
9
+ const DEFAULT_VALUE = '--';
10
+ const DEFAULT_VALUE_KEY = 'defaultValue';
11
+ const DEFAULT_OPTIONS = {
12
+ [DEFAULT_VALUE_KEY]: DEFAULT_VALUE,
13
+ };
14
+
15
+ export class Column<T = unknown> {
16
+ get Cell() {
17
+ return this.config.Cell;
18
+ }
19
+
20
+ get key() {
21
+ return this.config.key;
22
+ }
23
+
24
+ get name() {
25
+ return this.config.name;
26
+ }
27
+
28
+ constructor(
29
+ public table: Table<T>,
30
+ public config: ColumnConfig<T>,
31
+ ) {}
32
+
33
+ @action
34
+ getValueForRow(row: Row<T>): ContentValue {
35
+ if (this.config.value) {
36
+ return this.config.value({ column: this, row });
37
+ }
38
+
39
+ // Cast here, because ember get's types do not support nested keys
40
+ // even though the real implementation does
41
+ const value = get(row.data, this.config.key);
42
+
43
+ if (isEmpty(value)) {
44
+ return this.getDefaultValue(row);
45
+ }
46
+
47
+ /**
48
+ * UNSAFE: casting to ContentValue is incorrect, because we have not
49
+ * properly constrained the type of value, (isEmpty doesn't narrow types either)
50
+ */
51
+ return value as ContentValue;
52
+ }
53
+
54
+ private getDefaultValue(row: Row<T>) {
55
+ return this.getOptionsForRow(row)[DEFAULT_VALUE_KEY];
56
+ }
57
+
58
+ @action
59
+ getOptionsForRow(row: Row<T>) {
60
+ const defaults = DEFAULT_OPTIONS;
61
+
62
+ return {
63
+ ...defaults,
64
+ ...this.config.options?.({ column: this, row }),
65
+ };
66
+ }
67
+ }
@@ -0,0 +1,26 @@
1
+ import {
2
+ dependencySatisfies,
3
+ importSync,
4
+ macroCondition,
5
+ } from '@embroider/macros';
6
+
7
+ import type Owner from '@ember/owner';
8
+
9
+ interface CompatOwner {
10
+ getOwner: (context: unknown) => Owner | undefined;
11
+ setOwner: (context: unknown, owner: Owner) => void;
12
+ }
13
+
14
+ export const compatOwner = {} as CompatOwner;
15
+
16
+ if (macroCondition(dependencySatisfies('ember-source', '>=4.12.0'))) {
17
+ // In no version of ember where `@ember/owner` tried to be imported did it exist
18
+ // if (macroCondition(false)) {
19
+ // Using 'any' here because importSync can't lookup types correctly
20
+ compatOwner.getOwner = (importSync('@ember/owner') as any).getOwner;
21
+ compatOwner.setOwner = (importSync('@ember/owner') as any).setOwner;
22
+ } else {
23
+ // Using 'any' here because importSync can't lookup types correctly
24
+ compatOwner.getOwner = (importSync('@ember/application') as any).getOwner;
25
+ compatOwner.setOwner = (importSync('@ember/application') as any).setOwner;
26
+ }
@@ -0,0 +1,73 @@
1
+ import type { BasePlugin, Plugin } from '../../plugins';
2
+ import type { Column } from '../column';
3
+ import type { Row } from '../row';
4
+ import type { ColumnOptionsFor, SignatureFrom } from './plugins';
5
+ import type { Constructor } from '../private-types';
6
+ import type { ComponentLike, ContentValue } from '@glint/template';
7
+
8
+ export interface CellContext<T> {
9
+ column: Column<T>;
10
+ row: Row<T>;
11
+ }
12
+
13
+ type ColumnPluginOption<P = Plugin> = P extends BasePlugin
14
+ ? [Constructor<P>, () => ColumnOptionsFor<SignatureFrom<P>>]
15
+ : [P | Constructor<P>, () => unknown];
16
+
17
+ export type CellOptions = {
18
+ /**
19
+ * when no value is present for a given set of data for the given column config
20
+ */
21
+ defaultValue?: string;
22
+ } & Record<string, unknown>;
23
+
24
+ export interface ColumnConfig<T = unknown> {
25
+ /**
26
+ * the `key` is required for preferences storage, as well as
27
+ * managing uniqueness of the columns in an easy-to-understand way.
28
+ *
29
+ * key may be anything if a `value` is provided, but _should_
30
+ * be a property-path on each data object passed to the table.
31
+ *
32
+ * @example `someObj.property.path`
33
+ * @example `someProperty`
34
+ */
35
+ key: string;
36
+
37
+ /**
38
+ * Optionally provide a function to determine the value of a row at this column
39
+ */
40
+ value?: (context: CellContext<T>) => ContentValue;
41
+
42
+ /**
43
+ * Recommended property to use for custom components for each cell per column.
44
+ * Out-of-the-box, this property isn't used, but the provided type may be
45
+ * a convenience for consumers of the headless table
46
+ */
47
+ Cell?: ComponentLike;
48
+
49
+ /**
50
+ * The name or title of the column, shown in the column heading / th
51
+ */
52
+ name?: string;
53
+
54
+ /**
55
+ * Bag of extra properties to pass to Cell via `@options`, if desired
56
+ */
57
+ options?: (context: CellContext<T>) => CellOptions;
58
+
59
+ /**
60
+ * Each plugin may provide column options, and provides similar syntax to how
61
+ * options for the table are specified in the plugins entry,
62
+ *
63
+ * ```js
64
+ * pluginOptions: [
65
+ * ColumnVisibility.forColumn(() => ({ isVisible: false })),
66
+ * StickyColumns.forColumn(() => ({ sticky: 'right' })),
67
+ * ],
68
+ * ```
69
+ */
70
+ pluginOptions?: ColumnPluginOption[];
71
+ }
72
+
73
+ export type ColumnKey<T> = NonNullable<ColumnConfig<T>['key']>;
@@ -0,0 +1,7 @@
1
+ export * from './column.ts';
2
+ export * from './modifier.ts';
3
+ export * from './pagination.ts';
4
+ export * from './plugins.ts';
5
+ export * from './preferences.ts';
6
+ export * from './selection.ts';
7
+ export * from './table.ts';
@@ -0,0 +1,7 @@
1
+ export interface Destructor {
2
+ (): void;
3
+ }
4
+
5
+ export interface FunctionModifier<Args extends unknown[]> {
6
+ (element: HTMLElement, ...args: Args): void | Destructor;
7
+ }
@@ -0,0 +1,13 @@
1
+ export interface Pagination {
2
+ formatItemSummary?: (data: {
3
+ end: number;
4
+ start: number;
5
+ totalItems: number;
6
+ }) => string;
7
+ onChange: (value: { page: number; pageSize: number }) => Promise<void> | void;
8
+ page: number;
9
+ pageSize: number;
10
+ pageSizeLabel?: string;
11
+ pageSizes?: number[];
12
+ totalItems: number;
13
+ }