ember-headless-table 0.0.0 → 1.0.0

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 (169) hide show
  1. package/addon-main.js +5 -0
  2. package/dist/-private/-type-tests/plugin-properties.test.d.ts +2 -0
  3. package/dist/-private/-type-tests/plugin-properties.test.d.ts.map +1 -0
  4. package/dist/-private/-type-tests/plugin-properties.test.js +31 -0
  5. package/dist/-private/-type-tests/plugin-properties.test.js.map +1 -0
  6. package/dist/-private/-type-tests/plugin-with.test.d.ts +1 -0
  7. package/dist/-private/-type-tests/plugin-with.test.js +21 -0
  8. package/dist/-private/-type-tests/plugin-with.test.js.map +1 -0
  9. package/dist/-private/-type-tests/plugins-accessors.test.d.ts +1 -0
  10. package/dist/-private/-type-tests/plugins-accessors.test.js +36 -0
  11. package/dist/-private/-type-tests/plugins-accessors.test.js.map +1 -0
  12. package/dist/-private/-type-tests/plugins-signature-from.test.d.ts +1 -0
  13. package/dist/-private/-type-tests/plugins-signature-from.test.js +14 -0
  14. package/dist/-private/-type-tests/plugins-signature-from.test.js.map +1 -0
  15. package/dist/-private/-type-tests/plugins-signature-utils.test.d.ts +1 -0
  16. package/dist/-private/-type-tests/plugins-signature-utils.test.js +36 -0
  17. package/dist/-private/-type-tests/plugins-signature-utils.test.js.map +1 -0
  18. package/dist/-private/-type-tests/table-api.test.d.ts +1 -0
  19. package/dist/-private/-type-tests/table-api.test.js +16 -0
  20. package/dist/-private/-type-tests/table-api.test.js.map +1 -0
  21. package/dist/-private/-type-tests/table-config.test.d.ts +1 -0
  22. package/dist/-private/-type-tests/table-config.test.js +58 -0
  23. package/dist/-private/-type-tests/table-config.test.js.map +1 -0
  24. package/dist/-private/column.d.ts +18 -0
  25. package/dist/-private/column.js +70 -0
  26. package/dist/-private/column.js.map +1 -0
  27. package/dist/-private/interfaces/column.d.ts +57 -0
  28. package/dist/-private/interfaces/column.js +2 -0
  29. package/dist/-private/interfaces/column.js.map +1 -0
  30. package/dist/-private/interfaces/index.d.ts +7 -0
  31. package/dist/-private/interfaces/index.js +2 -0
  32. package/dist/-private/interfaces/index.js.map +1 -0
  33. package/dist/-private/interfaces/modifier.d.ts +7 -0
  34. package/dist/-private/interfaces/modifier.js +2 -0
  35. package/dist/-private/interfaces/modifier.js.map +1 -0
  36. package/dist/-private/interfaces/pagination.d.ts +17 -0
  37. package/dist/-private/interfaces/pagination.js +2 -0
  38. package/dist/-private/interfaces/pagination.js.map +1 -0
  39. package/dist/-private/interfaces/plugins.d.ts +314 -0
  40. package/dist/-private/interfaces/plugins.js +2 -0
  41. package/dist/-private/interfaces/plugins.js.map +1 -0
  42. package/dist/-private/interfaces/preferences.d.ts +74 -0
  43. package/dist/-private/interfaces/preferences.js +2 -0
  44. package/dist/-private/interfaces/preferences.js.map +1 -0
  45. package/dist/-private/interfaces/selection.d.ts +35 -0
  46. package/dist/-private/interfaces/selection.js +2 -0
  47. package/dist/-private/interfaces/selection.js.map +1 -0
  48. package/dist/-private/interfaces/table.d.ts +109 -0
  49. package/dist/-private/interfaces/table.js +2 -0
  50. package/dist/-private/interfaces/table.js.map +1 -0
  51. package/dist/-private/js-helper.d.ts +39 -0
  52. package/dist/-private/js-helper.js +20 -0
  53. package/dist/-private/js-helper.js.map +1 -0
  54. package/dist/-private/preferences.d.ts +56 -0
  55. package/dist/-private/preferences.js +175 -0
  56. package/dist/-private/preferences.js.map +1 -0
  57. package/dist/-private/private-types.d.ts +6 -0
  58. package/dist/-private/private-types.js +2 -0
  59. package/dist/-private/private-types.js.map +1 -0
  60. package/dist/-private/row.d.ts +12 -0
  61. package/dist/-private/row.js +63 -0
  62. package/dist/-private/row.js.map +1 -0
  63. package/dist/-private/table.d.ts +0 -0
  64. package/dist/-private/table.js +18 -0
  65. package/dist/-private/table.js.map +1 -0
  66. package/dist/-private/utils.d.ts +3 -0
  67. package/dist/-private/utils.js +17 -0
  68. package/dist/-private/utils.js.map +1 -0
  69. package/dist/applyDecoratedDescriptor-e0489e2f.js +31 -0
  70. package/dist/applyDecoratedDescriptor-e0489e2f.js.map +1 -0
  71. package/dist/classPrivateFieldGet-af59a8ea.js +23 -0
  72. package/dist/classPrivateFieldGet-af59a8ea.js.map +1 -0
  73. package/dist/defineProperty-a0196711.js +17 -0
  74. package/dist/defineProperty-a0196711.js.map +1 -0
  75. package/dist/index.d.ts +13 -0
  76. package/dist/index.js +4 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/plugins/-private/base.d.ts +267 -0
  79. package/dist/plugins/-private/base.js +486 -0
  80. package/dist/plugins/-private/base.js.map +1 -0
  81. package/dist/plugins/-private/utils.d.ts +21 -0
  82. package/dist/plugins/-private/utils.js +118 -0
  83. package/dist/plugins/-private/utils.js.map +1 -0
  84. package/dist/plugins/column-reordering/helpers.d.ts +28 -0
  85. package/dist/plugins/column-reordering/helpers.js +37 -0
  86. package/dist/plugins/column-reordering/helpers.js.map +1 -0
  87. package/dist/plugins/column-reordering/index.d.ts +3 -0
  88. package/dist/plugins/column-reordering/index.js +3 -0
  89. package/dist/plugins/column-reordering/index.js.map +1 -0
  90. package/dist/plugins/column-reordering/plugin.d.ts +133 -0
  91. package/dist/plugins/column-reordering/plugin.js +392 -0
  92. package/dist/plugins/column-reordering/plugin.js.map +1 -0
  93. package/dist/plugins/column-reordering/utils.d.ts +7 -0
  94. package/dist/plugins/column-reordering/utils.js +41 -0
  95. package/dist/plugins/column-reordering/utils.js.map +1 -0
  96. package/dist/plugins/column-resizing/handle.d.ts +116 -0
  97. package/dist/plugins/column-resizing/handle.js +251 -0
  98. package/dist/plugins/column-resizing/handle.js.map +1 -0
  99. package/dist/plugins/column-resizing/helpers.d.ts +17 -0
  100. package/dist/plugins/column-resizing/helpers.js +22 -0
  101. package/dist/plugins/column-resizing/helpers.js.map +1 -0
  102. package/dist/plugins/column-resizing/index.d.ts +4 -0
  103. package/dist/plugins/column-resizing/index.js +4 -0
  104. package/dist/plugins/column-resizing/index.js.map +1 -0
  105. package/dist/plugins/column-resizing/plugin.d.ts +144 -0
  106. package/dist/plugins/column-resizing/plugin.js +352 -0
  107. package/dist/plugins/column-resizing/plugin.js.map +1 -0
  108. package/dist/plugins/column-resizing/resize-observer.d.ts +14 -0
  109. package/dist/plugins/column-resizing/resize-observer.js +46 -0
  110. package/dist/plugins/column-resizing/resize-observer.js.map +1 -0
  111. package/dist/plugins/column-resizing/utils.d.ts +22 -0
  112. package/dist/plugins/column-resizing/utils.js +46 -0
  113. package/dist/plugins/column-resizing/utils.js.map +1 -0
  114. package/dist/plugins/column-visibility/helpers.d.ts +18 -0
  115. package/dist/plugins/column-visibility/helpers.js +25 -0
  116. package/dist/plugins/column-visibility/helpers.js.map +1 -0
  117. package/dist/plugins/column-visibility/index.d.ts +3 -0
  118. package/dist/plugins/column-visibility/index.js +3 -0
  119. package/dist/plugins/column-visibility/index.js.map +1 -0
  120. package/dist/plugins/column-visibility/plugin.d.ts +62 -0
  121. package/dist/plugins/column-visibility/plugin.js +124 -0
  122. package/dist/plugins/column-visibility/plugin.js.map +1 -0
  123. package/dist/plugins/data-sorting/helpers.d.ts +38 -0
  124. package/dist/plugins/data-sorting/helpers.js +49 -0
  125. package/dist/plugins/data-sorting/helpers.js.map +1 -0
  126. package/dist/plugins/data-sorting/index.d.ts +5 -0
  127. package/dist/plugins/data-sorting/index.js +4 -0
  128. package/dist/plugins/data-sorting/index.js.map +1 -0
  129. package/dist/plugins/data-sorting/plugin.d.ts +99 -0
  130. package/dist/plugins/data-sorting/plugin.js +165 -0
  131. package/dist/plugins/data-sorting/plugin.js.map +1 -0
  132. package/dist/plugins/data-sorting/types.d.ts +23 -0
  133. package/dist/plugins/data-sorting/types.js +17 -0
  134. package/dist/plugins/data-sorting/types.js.map +1 -0
  135. package/dist/plugins/index.d.ts +5 -0
  136. package/dist/plugins/index.js +3 -0
  137. package/dist/plugins/index.js.map +1 -0
  138. package/dist/plugins/row-selection/helpers.d.ts +6 -0
  139. package/dist/plugins/row-selection/helpers.js +10 -0
  140. package/dist/plugins/row-selection/helpers.js.map +1 -0
  141. package/dist/plugins/row-selection/index.d.ts +3 -0
  142. package/dist/plugins/row-selection/index.js +3 -0
  143. package/dist/plugins/row-selection/index.js.map +1 -0
  144. package/dist/plugins/row-selection/plugin.d.ts +79 -0
  145. package/dist/plugins/row-selection/plugin.js +187 -0
  146. package/dist/plugins/row-selection/plugin.js.map +1 -0
  147. package/dist/plugins/sticky-columns/helpers.d.ts +4 -0
  148. package/dist/plugins/sticky-columns/helpers.js +8 -0
  149. package/dist/plugins/sticky-columns/helpers.js.map +1 -0
  150. package/dist/plugins/sticky-columns/index.d.ts +3 -0
  151. package/dist/plugins/sticky-columns/index.js +3 -0
  152. package/dist/plugins/sticky-columns/index.js.map +1 -0
  153. package/dist/plugins/sticky-columns/plugin.d.ts +53 -0
  154. package/dist/plugins/sticky-columns/plugin.js +132 -0
  155. package/dist/plugins/sticky-columns/plugin.js.map +1 -0
  156. package/dist/table-8e46554b.d.ts +127 -0
  157. package/dist/table-8e46554b.js +249 -0
  158. package/dist/table-8e46554b.js.map +1 -0
  159. package/dist/test-support/index.d.ts +14 -0
  160. package/dist/test-support/index.js +72 -0
  161. package/dist/test-support/index.js.map +1 -0
  162. package/dist/utils.d.ts +26 -0
  163. package/dist/utils.js +77 -0
  164. package/dist/utils.js.map +1 -0
  165. package/package.json +147 -51
  166. package/LICENSE.md +0 -9
  167. package/README.md +0 -38
  168. package/config/environment.js +0 -5
  169. package/index.js +0 -5
@@ -0,0 +1,314 @@
1
+ /**
2
+ * NOTE:
3
+ * Empty, EmptyObject, and GetOrElse are copied from @glimmer/component
4
+ */
5
+ import { Constructor } from "../private-types";
6
+ import { Column, Row, Table } from "../../index";
7
+ import { Destructor } from "./index";
8
+ type DataTypeOf<T> = T extends Table<infer DataType> ? DataType : T;
9
+ /**
10
+ * @private utility class
11
+ *
12
+ * This class exists because there isn't a way to, in TS,
13
+ * get access to static properties from an instance type
14
+ */
15
+ type PluginClass<PluginType> = PluginType & {
16
+ new: (...args: unknown[]) => PluginType;
17
+ features?: string[];
18
+ requires?: string[];
19
+ };
20
+ type PluginSubclassInstance<PluginType> = PluginType & {
21
+ constructor: PluginClass<PluginType>;
22
+ };
23
+ /**
24
+ * @public
25
+ *
26
+ * The data passed to a plugin's column APIs
27
+ */
28
+ interface ColumnApi<T extends Table = Table> {
29
+ column: Column<DataTypeOf<T>>;
30
+ table: T;
31
+ }
32
+ /**
33
+ * @public
34
+ *
35
+ * The data passed to a plugin's row APIs
36
+ */
37
+ interface RowApi<T extends Table = Table> {
38
+ row: Row<DataTypeOf<T>>;
39
+ table: T;
40
+ }
41
+ /**
42
+ * @private utility type
43
+ *
44
+ * Note that this exists here, and the Plugin interface exists in general
45
+ * because we need to derive types in a static context on BasePlugin,
46
+ * and the source of types need to exist somewhere other than BasePlugin,
47
+ * so that:
48
+ * - inference will work
49
+ * - we avoid infinite recursive type definitions
50
+ */
51
+ type SignatureFrom<Klass extends Plugin<any>> = Klass extends Plugin<infer Signature> ? Signature : never;
52
+ /**
53
+ * @public
54
+ *
55
+ * Table plugins are stateless objects that optionally provide hooks based on what
56
+ * the plugin wishes to modify.
57
+ *
58
+ * If state is desired, Metadata classes may be provided to manage that state.
59
+ * As a convenience, when the meta classes are instantiated, they'll be given the same
60
+ * `owner` as everything else in the application, so service injection will be available
61
+ * within the meta class instances.
62
+ *
63
+ * A plugin can provide components that the consuming Table can opt in to rendering.
64
+ * (though, often these components will be required to be rendered for the plugin to work)
65
+ *
66
+ * a `Plugin` has one type argument:
67
+ * - Signature - which can provide optional information about the Meta/State and Options the plugin can take
68
+ *
69
+ * Any particular plugin instantiation will have at most 1 instance of their TableMeta
70
+ * and `n` instances of their ColumnMeta, where `n` is at most the number of columns.
71
+ */
72
+ interface Plugin<Signature = unknown> {
73
+ /**
74
+ * Unique name for the plugin.
75
+ * - only one plugin of the same name is allowed
76
+ * - the name is used for storing preferences / serializable information
77
+ */
78
+ name: string;
79
+ /**
80
+ * Some plugins may require that other plugins be present.
81
+ * and because plugins can be interchangeable, the features implemented
82
+ * by those plugins must be declared via strings so that we can have
83
+ * a semi-stable reference that isn't tied to object equality or anything like that.
84
+ *
85
+ * This enables, for example, the StickyColumns plugin to work with different implementations of the ColumnResizing plugin (such as one
86
+ * might have between an aria-grid and a data table)
87
+ */
88
+ features?: string[];
89
+ /**
90
+ * List of features to lookup "somewhere" in the list of plugins
91
+ * order does not matter.
92
+ */
93
+ requires?: string[];
94
+ /**
95
+ * Optional state that this plugin may or may not choose to use
96
+ *
97
+ * columns will each have an instance of meta.column.
98
+ * the table will have only one instance of meta.table.
99
+ */
100
+ meta?: {
101
+ /**
102
+ * @public
103
+ *
104
+ * Specifies the class definition to use for storing column-related state / behavior for this plugin
105
+ */
106
+ column?: Constructor<ColumnMetaFor<Signature>>;
107
+ /**
108
+ * @public
109
+ *
110
+ * Specifies the class definition to use for storing table-related state / behavior for this plugin
111
+ */
112
+ table?: Constructor<TableMetaFor<Signature>>;
113
+ /**
114
+ * @public
115
+ *
116
+ * Specifies the class definition to use for storing the row-related state / behavior for this plugin
117
+ */
118
+ row?: Constructor<RowMetaFor<Signature>>;
119
+ };
120
+ /**
121
+ * @public
122
+ * @kind Column property
123
+ *
124
+ * Specify a modifier setup/teardown function to attach to each of the header cells
125
+ *
126
+ * Can be used to add / remove attributes, event listeners, etc
127
+ */
128
+ headerCellModifier?: (element: HTMLElement, ...args: [ColumnApi<Table<any>>]) => void | Destructor;
129
+ /**
130
+ * @public
131
+ * @kind Row property
132
+ *
133
+ * Specify a modifier setup/teardown function to attach to each of the rows
134
+ *
135
+ * Can be used to add / remove attributes, event listeners, etc
136
+ */
137
+ rowModifier?: (element: HTMLElement, ...args: [RowApi<Table<any>>]) => void | Destructor;
138
+ /**
139
+ * @public
140
+ * @kind Table hook
141
+ *
142
+ * Specify a modifier setup/teardown function to attach to the table's containing element
143
+ */
144
+ containerModifier?: (element: HTMLElement, ...args: [Table<any>]) => void | Destructor;
145
+ /**
146
+ * @public
147
+ * @kind Table Hook
148
+ *
149
+ * If the plugin has state, this should be used to reset that state
150
+ */
151
+ reset?: () => void;
152
+ /**
153
+ * @public
154
+ * @kind Table Hook
155
+ *
156
+ * A plugin may change the columns order, visibility, etc.
157
+ * By implementing this getter, this plugin's
158
+ * `columns` property will be used by other plugins via
159
+ * the `columns.for(table, RequestingPlugin)` api.
160
+ *
161
+ * For the end-consumer, they may choose to do
162
+ * `columns.for(table)`, which will aggregate all column modifications
163
+ * from all plugins.
164
+ *
165
+ * As always, `table.columns` is the way to get the unmodified list of columns.
166
+ */
167
+ columns?: Column<any>[];
168
+ }
169
+ /**
170
+ * @private utility type
171
+ */
172
+ type GetOrElse<Obj, K, Fallback> = K extends keyof Obj ? Obj[K] : Fallback;
173
+ /**
174
+ * @public
175
+ *
176
+ * utility class to help with autocompletion / documentation
177
+ * in the editor while while defining the signature of custom plugins.
178
+ */
179
+ interface PluginSignature {
180
+ /**
181
+ * Meta is how plugins can manage per-{table,columns,rows}
182
+ * state, event listeners, and general public API
183
+ */
184
+ Meta?: {
185
+ /**
186
+ * If a plugin has Table meta/state,
187
+ * the shape of that state can be described here
188
+ */
189
+ Table?: unknown;
190
+ /**
191
+ * If a plugin has Column meta/state,
192
+ * the shape of that state can be described here
193
+ */
194
+ Column?: unknown;
195
+ /**
196
+ * If a plugin has Row meta/state,
197
+ * the shape of that state can be described here
198
+ */
199
+ Row?: unknown;
200
+ };
201
+ Options?: {
202
+ /**
203
+ * If a plugin has options configurable for the whole table,
204
+ * those can be specified here.
205
+ *
206
+ * These are passed via the the `withOptions` API
207
+ *
208
+ * ```js
209
+ * headlessTable(this?, {
210
+ * // ...
211
+ * plugins: [
212
+ * MyPlugin.withOptions(() => {
213
+ * // the return value here is this is Signature['Options']['Plugin']
214
+ * return {};
215
+ * })
216
+ * ]
217
+ * })
218
+ * ```
219
+ */
220
+ Plugin?: unknown;
221
+ /**
222
+ * If a plugin has options configurable per column,
223
+ * those can be specified here
224
+ *
225
+ * These are passed via the the `forColumn` API
226
+ *
227
+ * ```js
228
+ * headlessTable(this?, {
229
+ * // ...
230
+ * columns: () => [
231
+ * MyPlugin.forColumn(() => {
232
+ * // the return value here is this is Signature['Options']['Column']
233
+ * return {};
234
+ * })
235
+ * ]
236
+ * })
237
+ * ```
238
+ */
239
+ Column?: unknown;
240
+ };
241
+ }
242
+ /**
243
+ * @private default type
244
+ *
245
+ * Describes the shape of all the dynamic parts of a Plugin.
246
+ *
247
+ * There are no row options, because rows are not statically configurable.
248
+ */
249
+ interface DefaultPluginSignature {
250
+ Meta: {
251
+ Row: unknown;
252
+ Column: unknown;
253
+ Table: unknown;
254
+ };
255
+ Options: {
256
+ Plugin: unknown;
257
+ Column: unknown;
258
+ };
259
+ }
260
+ /**
261
+ * @private utility type
262
+ */
263
+ type TableMetaFor<Signature> = Signature extends {
264
+ Meta: {
265
+ Table: unknown;
266
+ };
267
+ } ? GetOrElse<Signature['Meta'], 'Table', never> : never;
268
+ /**
269
+ * @private utility type
270
+ */
271
+ type ColumnMetaFor<Signature> = Signature extends {
272
+ Meta: {
273
+ Column: unknown;
274
+ };
275
+ } ? GetOrElse<Signature['Meta'], 'Column', never> : never;
276
+ /**
277
+ * @private utility type
278
+ */
279
+ type RowMetaFor<Signature> = Signature extends {
280
+ Meta: {
281
+ Row: unknown;
282
+ };
283
+ } ? GetOrElse<Signature['Meta'], 'Row', never> : never;
284
+ /**
285
+ * @private utility type
286
+ */
287
+ type OptionsFor<Signature> = Signature extends {
288
+ Options: object;
289
+ } ? GetOrElse<Signature['Options'], 'Plugin', EmptyObject> : EmptyObject;
290
+ /**
291
+ * @private utility type
292
+ */
293
+ type ColumnOptionsFor<Signature> = Signature extends {
294
+ Options: object;
295
+ } ? GetOrElse<Signature['Options'], 'Column', EmptyObject> : EmptyObject;
296
+ declare const Empty: unique symbol;
297
+ /**
298
+ * This provides us a way to have a "fallback" which represents an empty object,
299
+ * without the downsides of how TS treats `{}`. Specifically: this will
300
+ * correctly leverage "excess property checking" so that, given a component
301
+ * which has no named args, if someone invokes it with any named args, they will
302
+ * get a type error.
303
+ *
304
+ * @internal This is exported so declaration emit works (if it were not emitted,
305
+ * declarations which fall back to it would not work). It is *not* intended for
306
+ * public usage, and the specific mechanics it uses may change at any time.
307
+ * The location of this export *is* part of the public API, because moving it
308
+ * will break existing declarations, but is not legal for end users to import
309
+ * themselves, so ***DO NOT RELY ON IT***.
310
+ */
311
+ type EmptyObject = {
312
+ [Empty]?: true;
313
+ };
314
+ export { PluginClass, PluginSubclassInstance, ColumnApi, RowApi, SignatureFrom, Plugin, PluginSignature, DefaultPluginSignature, TableMetaFor, ColumnMetaFor, RowMetaFor, OptionsFor, ColumnOptionsFor, EmptyObject };
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,74 @@
1
+ interface PreferencesAdapter {
2
+ persist?(key: string, data?: TablePreferencesData): void;
3
+ restore?(key: string): TablePreferencesData | undefined;
4
+ }
5
+ /**
6
+ * The root preferences object
7
+ *
8
+ * This object is serialized to JSON for your `PreferencesAdapter` to consume.
9
+ * This could allow for saving the data off to an API or local storage.
10
+ */
11
+ interface TablePreferencesData {
12
+ /**
13
+ * Every plugin has its own namespace for preferences storage.
14
+ *
15
+ * This is so that plugins can not worry about colliding with other plugins'
16
+ * keys within the preferences. For example: multiple plugins may use "enabled"
17
+ */
18
+ plugins?: Registry;
19
+ }
20
+ /**
21
+ * A type registry for ember-headless-table Plugin's Preferences.
22
+ * Meant to be declaration-merged so string lookups resolve to the correct type.
23
+ *
24
+ * And so that accessing the full "preferences" object from "persist"
25
+ * and within "restore" can be fully typed.
26
+ * This also helps out with Glint, as `unknown` types are not allowed to be rendered
27
+ *
28
+ * As a plugin author, to help define what your preferences shape is, you may
29
+ * ```ts
30
+ * import { type PluginPreferences } from 'ember-headless-table/plugins';
31
+ *
32
+ * interface SortingPreferences extends PluginPreferences {
33
+ *
34
+ * }
35
+ *
36
+ * declare module 'ember-headless-table/plugins' {
37
+ * interface Registry {
38
+ * // The key *must* match the same of the class
39
+ * Sorting: SortingPreferences;
40
+ * }
41
+ * }
42
+ * ```
43
+ */
44
+ interface Registry {
45
+ }
46
+ type PluginPreferenceFor<PluginName> = PluginName extends keyof Registry ? Registry[PluginName] & PluginPreferences : PluginPreferences;
47
+ type PreferencesTableKey<PluginName> = keyof PluginPreferenceFor<PluginName>['table'];
48
+ type PreferencesTableValues<PluginName> = PluginPreferenceFor<PluginName>['table'][PreferencesTableKey<PluginName>];
49
+ type PreferencesColumnValues<PluginName> = PluginPreferenceFor<PluginName>['columns'][keyof PluginPreferenceFor<PluginName>['columns']];
50
+ /**
51
+ * Preferences for a column may store a map of key-value pairs
52
+ * for each of
53
+ * - the table
54
+ * - each column
55
+ */
56
+ interface PluginPreferences {
57
+ /**
58
+ * A plugin's preferences for the table can be any
59
+ * string -> stringifyable mapping
60
+ */
61
+ table: Record<string, unknown>;
62
+ /**
63
+ * preferences for a plugin's columns-of-interest are mapped out by
64
+ * the column's key
65
+ */
66
+ columns: {
67
+ /**
68
+ * For any particular column that a plugin may desire to store preferences on,
69
+ * the data can be any string -> stringifyable mapping
70
+ */
71
+ [columnKey: string]: Record<string, unknown>;
72
+ };
73
+ }
74
+ export { PreferencesAdapter, TablePreferencesData, Registry, PluginPreferenceFor, PreferencesTableKey, PreferencesTableValues, PreferencesColumnValues, PluginPreferences };
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=preferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preferences.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Types minimally replicated here so we don't need to depend on the package that
3
+ * actually defines these types
4
+ *
5
+ * This also enables a much broader variety of implementations as these interfaces
6
+ * describe only what's needed by the headless table, and not the concrete implementation
7
+ */
8
+ type CurrentState<T> = {
9
+ state: 'ALL' | 'NONE';
10
+ } | {
11
+ state: 'SOME';
12
+ includeItems: T[];
13
+ } | {
14
+ state: 'ALL_EXCEPT';
15
+ excludeItems: T[];
16
+ };
17
+ /**
18
+ * A table can provide a `Selection` object that matches this API
19
+ */
20
+ interface Selection<Item = object> {
21
+ get selected(): Item[];
22
+ get currentState(): CurrentState<Item>;
23
+ get isIndeterminate(): boolean;
24
+ get isAllSelected(): boolean;
25
+ get numSelected(): number;
26
+ get numTotal(): number;
27
+ isSelected(item: Item): boolean;
28
+ selectItem(item: Item): void;
29
+ toggleItem(item: Item): void;
30
+ toggleAll(): void;
31
+ selectAll(): void;
32
+ deselectAll(): void;
33
+ deselectItem(item: Item): void;
34
+ }
35
+ export { Selection };
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,109 @@
1
+ import { Plugins } from "../../plugins/-private/utils";
2
+ import { ColumnConfig } from "./column";
3
+ import { Pagination } from "./pagination";
4
+ import { PreferencesAdapter } from "./preferences";
5
+ import { Selection } from "./selection";
6
+ interface TableMeta {
7
+ totalRowCount?: number;
8
+ totalRowsSelectedCount?: number;
9
+ }
10
+ interface TableConfig<DataType> {
11
+ /**
12
+ * Configuration describing how the table will crawl through `data`
13
+ * and render it. Within this `columns` config, there will also be opportunities
14
+ * to set the behavior of columns when rendered
15
+ */
16
+ columns: () => ColumnConfig<DataType>[];
17
+ /**
18
+ * The data to render, as described via the `columns` option.
19
+ *
20
+ * This data may or may not match the shape requested by the columns configuration.
21
+ * When a key-value pair matches what a column config requests, the data will be rendered.
22
+ * When a key-value pair is misisng, a fallback or empty representation of a value will be
23
+ * shown instead.
24
+ */
25
+ data: () => DataType[];
26
+ /**
27
+ * A collection of plugins for use in extending table behavior.
28
+ * plugins have a collection of hooks and properties to use, but for anything
29
+ * requiring user interaction there will be manual connecting.
30
+ *
31
+ * The instance for each plugin can be accessed via HeadlessTable's `pluginOf(<Plugin>)`
32
+ * method, where it takes the plugin constructor/class/object for lookup purposes.
33
+ *
34
+ * Some plugins may require setting options for hooking into behavior
35
+ * provided by the plugin (for example sorting).
36
+ *
37
+ * Example:
38
+ * ```js
39
+ * import { DataSorting } from '@crowdstrike/ember-headless-table/plugins/data-sorting';
40
+ * import { ColumnResizing } from '@crowdstrike/ember-headless-table/plugins/column-resizing';
41
+ *
42
+ * ...
43
+ *
44
+ * plugins: [
45
+ * DataSorting.with(() => {
46
+ * return {
47
+ * sorts: [array of sorts],
48
+ * onSort: this.doThingWhenSortsChange,
49
+ * };
50
+ * }),
51
+ * ColumnResizing.with(() => {
52
+ * return {
53
+ * enabled: true,
54
+ * }
55
+ * }),
56
+ * ]
57
+ * ```
58
+ *
59
+ * However, for plugins with no needed options, the list can be simplified:
60
+ * ```js
61
+ * import { ColumnResizing } from '@crowdstrike/ember-headless-table/plugins/column-resizing';
62
+ * import { StickyColumns } from '@crowdstrike/ember-headless-table/plugins/sticky-columns';
63
+ *
64
+ * ...
65
+ *
66
+ * plugins: [
67
+ * ColumnResizing,
68
+ * StickyColumns,
69
+ * ]
70
+ * ```
71
+ */
72
+ plugins?: Plugins;
73
+ bulkSelection?: Selection;
74
+ isCheckboxSelectable?: boolean;
75
+ isRowSelectable?: boolean;
76
+ rowSelection?: () => DataType;
77
+ onRowSelectionChange?: (selection: DataType | undefined) => void;
78
+ meta?: TableMeta;
79
+ pagination?: Pagination;
80
+ /**
81
+ * Foundational to tables is how to store settings within them.
82
+ * The `key` is meant to identify a particular kind of table. For example, if
83
+ * you have a table representing "blog posts", your table key may be "blog-posts".
84
+ *
85
+ * And most importantly, the `adapter` is how you load and save the preferences.
86
+ * This may bo to local storage, or some API.
87
+ */
88
+ preferences?: {
89
+ /**
90
+ * What to name the table in the preferences storage of your choice.
91
+ * Any string is valid provided that the storage adapter of your choice supports
92
+ * the format.
93
+ *
94
+ * For example, if you have a table of "blog posts", the preferences key might be
95
+ * `"all-blog-posts"`
96
+ */
97
+ key: string;
98
+ /**
99
+ * Configuration for how you wish to `persist` and `restore` the configuration for your table.
100
+ *
101
+ * `persist` may be async as it is a fire-and-forget type of action.
102
+ *
103
+ * However, `restore` must be synchronous, as this is a blocking operation for rendering the table.
104
+ * So it's best to load up the table preferences before rendering a table.
105
+ */
106
+ adapter?: PreferencesAdapter;
107
+ };
108
+ }
109
+ export { TableMeta, TableConfig };
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import { Table } from "../table-8e46554b";
2
+ import { TableConfig } from "./interfaces/index";
3
+ /**
4
+ * Represents a UI-less version of a table
5
+ *
6
+ * _For use for building tables in ui frameworks_.
7
+ *
8
+ * @example
9
+ * ```js
10
+ * import { use } from 'ember-resources';
11
+ * import { headlessTable } '@crowdstrike/ember-headless-table';
12
+ *
13
+ * class MyImplementation {
14
+ * @use table = headlessTable({
15
+ * // your config here
16
+ * })
17
+ * }
18
+ * ```
19
+ */
20
+ declare function headlessTable<T = unknown>(options: TableConfig<T>): Table<T>;
21
+ /**
22
+ * Represents a UI-less version of a table
23
+ *
24
+ * _For use for building tables in ui frameworks_.
25
+ *
26
+ * @example
27
+ * ```js
28
+ * import { headlessTable } '@crowdstrike/ember-headless-table';
29
+ *
30
+ * class MyImplementation {
31
+ * table = headlessTable(this, {
32
+ * // your config here
33
+ * })
34
+ * }
35
+ * ```
36
+ *
37
+ */
38
+ declare function headlessTable<T = unknown>(destroyable: object, options: TableConfig<T>): Table<T>;
39
+ export { headlessTable };
@@ -0,0 +1,20 @@
1
+ import { a as Table } from '../table-8e46554b.js';
2
+
3
+ function headlessTable(...args) {
4
+ if (args.length === 2) {
5
+ let [destroyable, options] = args;
6
+ /**
7
+ * If any "root level" config changes, we need to throw-away everything.
8
+ * otherwise individual-property reactivity can be managed on a per-property
9
+ * "thunk"-basis
10
+ */
11
+
12
+ return Table.from(destroyable, () => options);
13
+ }
14
+
15
+ let [options] = args;
16
+ return Table.from(() => options);
17
+ }
18
+
19
+ export { headlessTable };
20
+ //# sourceMappingURL=js-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js-helper.js","sources":["../../src/-private/js-helper.ts"],"sourcesContent":["import { Table } from './table';\n\nimport type { TableConfig } from '#interfaces';\n\ntype Args<T> = [destroyable: object, options: TableConfig<T>] | [options: TableConfig<T>];\n\n/**\n * Represents a UI-less version of a table\n *\n * _For use for building tables in ui frameworks_.\n *\n * @example\n * ```js\n * import { use } from 'ember-resources';\n * import { headlessTable } '@crowdstrike/ember-headless-table';\n *\n * class MyImplementation {\n * @use table = headlessTable({\n * // your config here\n * })\n * }\n * ```\n */\nexport function headlessTable<T = unknown>(options: TableConfig<T>): Table<T>;\n\n/**\n * Represents a UI-less version of a table\n *\n * _For use for building tables in ui frameworks_.\n *\n * @example\n * ```js\n * import { headlessTable } '@crowdstrike/ember-headless-table';\n *\n * class MyImplementation {\n * table = headlessTable(this, {\n * // your config here\n * })\n * }\n * ```\n *\n */\nexport function headlessTable<T = unknown>(destroyable: object, options: TableConfig<T>): Table<T>;\n\nexport function headlessTable<T = unknown>(...args: Args<T>): Table<T> {\n if (args.length === 2) {\n let [destroyable, options] = args;\n\n /**\n * If any \"root level\" config changes, we need to throw-away everything.\n * otherwise individual-property reactivity can be managed on a per-property\n * \"thunk\"-basis\n */\n return Table.from<Table<T>>(destroyable, () => options);\n }\n\n let [options] = args;\n\n return Table.from<Table<T>>(() => options);\n}\n"],"names":["headlessTable","args","length","destroyable","options","Table","from"],"mappings":";;AA4CO,SAASA,aAAT,CAAoC,GAAGC,IAAvC,EAAgE;AACrE,EAAA,IAAIA,IAAI,CAACC,MAAL,KAAgB,CAApB,EAAuB;AACrB,IAAA,IAAI,CAACC,WAAD,EAAcC,OAAd,IAAyBH,IAA7B,CAAA;AAEA;AACJ;AACA;AACA;AACA;;IACI,OAAOI,KAAK,CAACC,IAAN,CAAqBH,WAArB,EAAkC,MAAMC,OAAxC,CAAP,CAAA;AACD,GAAA;;EAED,IAAI,CAACA,OAAD,CAAA,GAAYH,IAAhB,CAAA;AAEA,EAAA,OAAOI,KAAK,CAACC,IAAN,CAAqB,MAAMF,OAA3B,CAAP,CAAA;AACD;;;;"}
@@ -0,0 +1,56 @@
1
+ import { TrackedMap } from 'tracked-built-ins';
2
+ import { PluginPreferenceFor, PluginPreferences, TablePreferencesData } from "./interfaces/index";
3
+ import { PreferencesAdapter as Adapter } from "./interfaces/index";
4
+ declare class TablePreferences {
5
+ private key;
6
+ private adapter?;
7
+ storage: TrackedPreferences;
8
+ constructor(key: string, adapter?: Adapter | undefined);
9
+ hasAdapter(): boolean;
10
+ getIsAtDefault(): boolean;
11
+ /**
12
+ * Passes a JSON-compatible structure to `adapter.persist`
13
+ *
14
+ * This structure could be stored in a remote database or
15
+ * local storage. The `adpater.restore` method can be used to restore
16
+ * this structure back in to the {@link TrackedPreferences }
17
+ */
18
+ /**
19
+ * Passes a JSON-compatible structure to `adapter.persist`
20
+ *
21
+ * This structure could be stored in a remote database or
22
+ * local storage. The `adpater.restore` method can be used to restore
23
+ * this structure back in to the {@link TrackedPreferences }
24
+ */
25
+ persist(): void | undefined;
26
+ /**
27
+ * Using the `adapter.restore` method, convert the JSON structure
28
+ * to {@link TrackedPreferences }
29
+ */
30
+ /**
31
+ * Using the `adapter.restore` method, convert the JSON structure
32
+ * to {@link TrackedPreferences }
33
+ */
34
+ restore(adapter: Adapter): void;
35
+ }
36
+ /**
37
+ * @public
38
+ *
39
+ * The API for reactively interacting with preferences
40
+ */
41
+ declare class TrackedPreferences {
42
+ plugins: Map<string, TrackedPluginPrefs<unknown>>;
43
+ get isAtDefault(): boolean;
44
+ forPlugin(name: string): TrackedPluginPrefs<unknown>;
45
+ serialize(): TablePreferencesData;
46
+ restore(data: TablePreferencesData): void;
47
+ }
48
+ declare class TrackedPluginPrefs<PluginName = unknown> {
49
+ table: TrackedMap<string, unknown>;
50
+ columns: Map<string, TrackedMap<string, unknown>>;
51
+ get isAtDefault(): boolean;
52
+ forColumn: (key: string) => TrackedMap<string, unknown>;
53
+ serialize(): PluginPreferenceFor<PluginName>;
54
+ restore(data: PluginPreferences): void;
55
+ }
56
+ export { TablePreferences };