@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.
- package/dist/-private/-type-tests/plugin-properties.test.js +27 -0
- package/dist/-private/-type-tests/plugin-properties.test.js.map +1 -0
- package/dist/-private/-type-tests/plugin-with.test.js +20 -0
- package/dist/-private/-type-tests/plugin-with.test.js.map +1 -0
- package/dist/-private/-type-tests/plugins-accessors.test.js +36 -0
- package/dist/-private/-type-tests/plugins-accessors.test.js.map +1 -0
- package/dist/-private/-type-tests/plugins-signature-from.test.js +15 -0
- package/dist/-private/-type-tests/plugins-signature-from.test.js.map +1 -0
- package/dist/-private/-type-tests/plugins-signature-utils.test.js +36 -0
- package/dist/-private/-type-tests/plugins-signature-utils.test.js.map +1 -0
- package/dist/-private/-type-tests/table-api.test.js +17 -0
- package/dist/-private/-type-tests/table-api.test.js.map +1 -0
- package/dist/-private/-type-tests/table-config.test.js +55 -0
- package/dist/-private/-type-tests/table-config.test.js.map +1 -0
- package/dist/-private/column.js +62 -0
- package/dist/-private/column.js.map +1 -0
- package/dist/-private/ember-compat.js +17 -0
- package/dist/-private/ember-compat.js.map +1 -0
- package/dist/-private/interfaces/column.js +2 -0
- package/dist/-private/interfaces/column.js.map +1 -0
- package/dist/-private/interfaces/index.js +2 -0
- package/dist/-private/interfaces/index.js.map +1 -0
- package/dist/-private/interfaces/modifier.js +2 -0
- package/dist/-private/interfaces/modifier.js.map +1 -0
- package/dist/-private/interfaces/pagination.js +2 -0
- package/dist/-private/interfaces/pagination.js.map +1 -0
- package/dist/-private/interfaces/plugins.js +2 -0
- package/dist/-private/interfaces/plugins.js.map +1 -0
- package/dist/-private/interfaces/preferences.js +2 -0
- package/dist/-private/interfaces/preferences.js.map +1 -0
- package/dist/-private/interfaces/selection.js +2 -0
- package/dist/-private/interfaces/selection.js.map +1 -0
- package/dist/-private/interfaces/table.js +2 -0
- package/dist/-private/interfaces/table.js.map +1 -0
- package/dist/-private/js-helper.js +55 -0
- package/dist/-private/js-helper.js.map +1 -0
- package/dist/-private/preferences.js +143 -0
- package/dist/-private/preferences.js.map +1 -0
- package/dist/-private/private-types.js +2 -0
- package/dist/-private/private-types.js.map +1 -0
- package/dist/-private/row.js +51 -0
- package/dist/-private/row.js.map +1 -0
- package/dist/-private/table.js +273 -0
- package/dist/-private/table.js.map +1 -0
- package/dist/-private/utils.js +15 -0
- package/dist/-private/utils.js.map +1 -0
- package/dist/_rollupPluginBabelHelpers-BpiaYhlf.js +63 -0
- package/dist/_rollupPluginBabelHelpers-BpiaYhlf.js.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/-private/base.js +524 -0
- package/dist/plugins/-private/base.js.map +1 -0
- package/dist/plugins/-private/utils.js +103 -0
- package/dist/plugins/-private/utils.js.map +1 -0
- package/dist/plugins/column-reordering/helpers.js +44 -0
- package/dist/plugins/column-reordering/helpers.js.map +1 -0
- package/dist/plugins/column-reordering/index.js +3 -0
- package/dist/plugins/column-reordering/index.js.map +1 -0
- package/dist/plugins/column-reordering/plugin.js +359 -0
- package/dist/plugins/column-reordering/plugin.js.map +1 -0
- package/dist/plugins/column-reordering/utils.js +34 -0
- package/dist/plugins/column-reordering/utils.js.map +1 -0
- package/dist/plugins/column-resizing/handle.js +241 -0
- package/dist/plugins/column-resizing/handle.js.map +1 -0
- package/dist/plugins/column-resizing/helpers.js +71 -0
- package/dist/plugins/column-resizing/helpers.js.map +1 -0
- package/dist/plugins/column-resizing/index.js +4 -0
- package/dist/plugins/column-resizing/index.js.map +1 -0
- package/dist/plugins/column-resizing/plugin.js +328 -0
- package/dist/plugins/column-resizing/plugin.js.map +1 -0
- package/dist/plugins/column-resizing/resize-observer.js +44 -0
- package/dist/plugins/column-resizing/resize-observer.js.map +1 -0
- package/dist/plugins/column-resizing/utils.js +44 -0
- package/dist/plugins/column-resizing/utils.js.map +1 -0
- package/dist/plugins/column-visibility/helpers.js +25 -0
- package/dist/plugins/column-visibility/helpers.js.map +1 -0
- package/dist/plugins/column-visibility/index.js +3 -0
- package/dist/plugins/column-visibility/index.js.map +1 -0
- package/dist/plugins/column-visibility/plugin.js +92 -0
- package/dist/plugins/column-visibility/plugin.js.map +1 -0
- package/dist/plugins/data-sorting/helpers.js +49 -0
- package/dist/plugins/data-sorting/helpers.js.map +1 -0
- package/dist/plugins/data-sorting/index.js +4 -0
- package/dist/plugins/data-sorting/index.js.map +1 -0
- package/dist/plugins/data-sorting/plugin.js +132 -0
- package/dist/plugins/data-sorting/plugin.js.map +1 -0
- package/dist/plugins/data-sorting/types.js +14 -0
- package/dist/plugins/data-sorting/types.js.map +1 -0
- package/dist/plugins/index.js +3 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/metadata/helpers.js +12 -0
- package/dist/plugins/metadata/helpers.js.map +1 -0
- package/dist/plugins/metadata/index.js +3 -0
- package/dist/plugins/metadata/index.js.map +1 -0
- package/dist/plugins/metadata/plugin.js +25 -0
- package/dist/plugins/metadata/plugin.js.map +1 -0
- package/dist/plugins/row-selection/helpers.js +10 -0
- package/dist/plugins/row-selection/helpers.js.map +1 -0
- package/dist/plugins/row-selection/index.js +3 -0
- package/dist/plugins/row-selection/index.js.map +1 -0
- package/dist/plugins/row-selection/plugin.js +118 -0
- package/dist/plugins/row-selection/plugin.js.map +1 -0
- package/dist/plugins/sticky-columns/helpers.js +49 -0
- package/dist/plugins/sticky-columns/helpers.js.map +1 -0
- package/dist/plugins/sticky-columns/index.js +3 -0
- package/dist/plugins/sticky-columns/index.js.map +1 -0
- package/dist/plugins/sticky-columns/plugin.js +139 -0
- package/dist/plugins/sticky-columns/plugin.js.map +1 -0
- package/dist/test-support/index.js +62 -0
- package/dist/test-support/index.js.map +1 -0
- package/dist/utils.js +77 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -2
- package/src/-private/-type-tests/plugin-properties.test.ts +38 -0
- package/src/-private/-type-tests/plugin-with.test.ts +23 -0
- package/src/-private/-type-tests/plugins-accessors.test.ts +86 -0
- package/src/-private/-type-tests/plugins-signature-from.test.ts +66 -0
- package/src/-private/-type-tests/plugins-signature-utils.test.ts +154 -0
- package/src/-private/-type-tests/table-api.test.ts +20 -0
- package/src/-private/-type-tests/table-config.test.ts +70 -0
- package/src/-private/column.ts +67 -0
- package/src/-private/ember-compat.ts +26 -0
- package/src/-private/interfaces/column.ts +73 -0
- package/src/-private/interfaces/index.ts +7 -0
- package/src/-private/interfaces/modifier.ts +7 -0
- package/src/-private/interfaces/pagination.ts +13 -0
- package/src/-private/interfaces/plugins.ts +349 -0
- package/src/-private/interfaces/preferences.ts +82 -0
- package/src/-private/interfaces/selection.ts +38 -0
- package/src/-private/interfaces/table.ts +121 -0
- package/src/-private/js-helper.ts +65 -0
- package/src/-private/preferences.ts +176 -0
- package/src/-private/private-types.ts +8 -0
- package/src/-private/row.ts +66 -0
- package/src/-private/table.ts +310 -0
- package/src/-private/utils.ts +21 -0
- package/src/index.ts +25 -0
- package/src/plugins/-private/base.ts +836 -0
- package/src/plugins/-private/utils.ts +166 -0
- package/src/plugins/column-reordering/helpers.ts +50 -0
- package/src/plugins/column-reordering/index.ts +6 -0
- package/src/plugins/column-reordering/plugin.ts +489 -0
- package/src/plugins/column-reordering/utils.ts +48 -0
- package/src/plugins/column-resizing/handle.ts +280 -0
- package/src/plugins/column-resizing/helpers.ts +79 -0
- package/src/plugins/column-resizing/index.ts +7 -0
- package/src/plugins/column-resizing/plugin.ts +490 -0
- package/src/plugins/column-resizing/resize-observer.ts +48 -0
- package/src/plugins/column-resizing/utils.ts +54 -0
- package/src/plugins/column-visibility/helpers.ts +28 -0
- package/src/plugins/column-visibility/index.ts +6 -0
- package/src/plugins/column-visibility/plugin.ts +155 -0
- package/src/plugins/data-sorting/helpers.ts +56 -0
- package/src/plugins/data-sorting/index.ts +8 -0
- package/src/plugins/data-sorting/plugin.ts +222 -0
- package/src/plugins/data-sorting/types.ts +26 -0
- package/src/plugins/index.ts +20 -0
- package/src/plugins/metadata/helpers.ts +12 -0
- package/src/plugins/metadata/index.ts +7 -0
- package/src/plugins/metadata/plugin.ts +26 -0
- package/src/plugins/row-selection/helpers.ts +13 -0
- package/src/plugins/row-selection/index.ts +7 -0
- package/src/plugins/row-selection/plugin.ts +218 -0
- package/src/plugins/sticky-columns/helpers.ts +59 -0
- package/src/plugins/sticky-columns/index.ts +7 -0
- package/src/plugins/sticky-columns/plugin.ts +201 -0
- package/src/test-support/index.ts +76 -0
- 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,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
|
+
}
|