@triptyk/ember-yeti-table 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +9 -115
  3. package/declarations/components/yeti-table/body.d.ts +32 -0
  4. package/declarations/components/yeti-table/body.d.ts.map +1 -0
  5. package/declarations/components/yeti-table/header.d.ts +33 -0
  6. package/declarations/components/yeti-table/header.d.ts.map +1 -0
  7. package/declarations/components/yeti-table/pagination.d.ts +40 -0
  8. package/declarations/components/yeti-table/pagination.d.ts.map +1 -0
  9. package/declarations/components/yeti-table/table.d.ts +21 -0
  10. package/declarations/components/yeti-table/table.d.ts.map +1 -0
  11. package/declarations/components/yeti-table/tbody/row/cell.d.ts +44 -0
  12. package/declarations/components/yeti-table/tbody/row/cell.d.ts.map +1 -0
  13. package/declarations/components/yeti-table/tbody/row.d.ts +37 -0
  14. package/declarations/components/yeti-table/tbody/row.d.ts.map +1 -0
  15. package/declarations/components/yeti-table/tbody.d.ts +29 -0
  16. package/declarations/components/yeti-table/tbody.d.ts.map +1 -0
  17. package/declarations/components/yeti-table/tfoot/row/cell.d.ts +40 -0
  18. package/declarations/components/yeti-table/tfoot/row/cell.d.ts.map +1 -0
  19. package/declarations/components/yeti-table/tfoot/row.d.ts +37 -0
  20. package/declarations/components/yeti-table/tfoot/row.d.ts.map +1 -0
  21. package/declarations/components/yeti-table/tfoot.d.ts +27 -0
  22. package/declarations/components/yeti-table/tfoot.d.ts.map +1 -0
  23. package/declarations/components/yeti-table/thead/row/cell.d.ts +54 -0
  24. package/declarations/components/yeti-table/thead/row/cell.d.ts.map +1 -0
  25. package/declarations/components/yeti-table/thead/row/column.d.ts +69 -0
  26. package/declarations/components/yeti-table/thead/row/column.d.ts.map +1 -0
  27. package/declarations/components/yeti-table/thead/row.d.ts +55 -0
  28. package/declarations/components/yeti-table/thead/row.d.ts.map +1 -0
  29. package/declarations/components/yeti-table/thead.d.ts +34 -0
  30. package/declarations/components/yeti-table/thead.d.ts.map +1 -0
  31. package/declarations/components/yeti-table.d.ts +107 -0
  32. package/declarations/components/yeti-table.d.ts.map +1 -0
  33. package/declarations/index.d.ts +1 -0
  34. package/declarations/index.d.ts.map +1 -0
  35. package/declarations/template-registry.d.ts +1 -0
  36. package/declarations/template-registry.d.ts.map +1 -0
  37. package/declarations/themes/default-theme.d.ts +3 -27
  38. package/declarations/themes/default-theme.d.ts.map +1 -1
  39. package/declarations/types.d.ts +82 -0
  40. package/declarations/types.d.ts.map +1 -0
  41. package/declarations/utils/create-regex.d.ts +1 -1
  42. package/declarations/utils/create-regex.d.ts.map +1 -1
  43. package/declarations/utils/filtering-utils.d.ts +2 -4
  44. package/declarations/utils/filtering-utils.d.ts.map +1 -1
  45. package/declarations/utils/sorting-utils.d.ts +6 -15
  46. package/declarations/utils/sorting-utils.d.ts.map +1 -1
  47. package/dist/components/yeti-table/body.js +19 -14
  48. package/dist/components/yeti-table/body.js.map +1 -1
  49. package/dist/components/yeti-table/header.js +10 -10
  50. package/dist/components/yeti-table/header.js.map +1 -1
  51. package/dist/components/yeti-table/pagination.js +14 -44
  52. package/dist/components/yeti-table/pagination.js.map +1 -1
  53. package/dist/components/yeti-table/table.js +1 -23
  54. package/dist/components/yeti-table/table.js.map +1 -1
  55. package/dist/components/yeti-table/tbody/row/cell.js +12 -12
  56. package/dist/components/yeti-table/tbody/row/cell.js.map +1 -1
  57. package/dist/components/yeti-table/tbody/row.js +15 -21
  58. package/dist/components/yeti-table/tbody/row.js.map +1 -1
  59. package/dist/components/yeti-table/tbody.js +1 -0
  60. package/dist/components/yeti-table/tbody.js.map +1 -1
  61. package/dist/components/yeti-table/tfoot/row/cell.js +9 -9
  62. package/dist/components/yeti-table/tfoot/row/cell.js.map +1 -1
  63. package/dist/components/yeti-table/tfoot/row.js +11 -11
  64. package/dist/components/yeti-table/tfoot/row.js.map +1 -1
  65. package/dist/components/yeti-table/tfoot.js +1 -0
  66. package/dist/components/yeti-table/tfoot.js.map +1 -1
  67. package/dist/components/yeti-table/thead/row/cell.js +11 -8
  68. package/dist/components/yeti-table/thead/row/cell.js.map +1 -1
  69. package/dist/components/yeti-table/thead/row/column.js +27 -128
  70. package/dist/components/yeti-table/thead/row/column.js.map +1 -1
  71. package/dist/components/yeti-table/thead/row.js +15 -15
  72. package/dist/components/yeti-table/thead/row.js.map +1 -1
  73. package/dist/components/yeti-table/thead.js +3 -22
  74. package/dist/components/yeti-table/thead.js.map +1 -1
  75. package/dist/components/yeti-table.js +99 -303
  76. package/dist/components/yeti-table.js.map +1 -1
  77. package/dist/index.js +2 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/template-registry.js +2 -0
  80. package/dist/template-registry.js.map +1 -0
  81. package/dist/themes/default-theme.js +3 -2
  82. package/dist/themes/default-theme.js.map +1 -1
  83. package/dist/types.js +2 -0
  84. package/dist/types.js.map +1 -0
  85. package/dist/utils/create-regex.js +6 -6
  86. package/dist/utils/create-regex.js.map +1 -1
  87. package/dist/utils/filtering-utils.js +20 -8
  88. package/dist/utils/filtering-utils.js.map +1 -1
  89. package/dist/utils/sorting-utils.js +13 -18
  90. package/dist/utils/sorting-utils.js.map +1 -1
  91. package/package.json +37 -16
  92. package/src/components/yeti-table/{body.gjs → body.gts} +49 -45
  93. package/src/components/yeti-table/header.gts +67 -0
  94. package/src/components/yeti-table/pagination.gts +118 -0
  95. package/src/components/yeti-table/table.gts +27 -0
  96. package/src/components/yeti-table/tbody/row/{cell.gjs → cell.gts} +38 -19
  97. package/src/components/yeti-table/tbody/row.gts +76 -0
  98. package/src/components/yeti-table/tbody.gts +53 -0
  99. package/src/components/yeti-table/tfoot/row/cell.gts +64 -0
  100. package/src/components/yeti-table/tfoot/row.gts +59 -0
  101. package/src/components/yeti-table/tfoot.gts +41 -0
  102. package/src/components/yeti-table/thead/row/{cell.gjs → cell.gts} +36 -13
  103. package/src/components/yeti-table/thead/row/column.gts +177 -0
  104. package/src/components/yeti-table/thead/row.gts +105 -0
  105. package/src/components/yeti-table/thead.gts +65 -0
  106. package/src/components/yeti-table.gts +629 -0
  107. package/src/template-registry.ts +10 -0
  108. package/src/themes/{default-theme.js → default-theme.ts} +5 -1
  109. package/src/types.ts +94 -0
  110. package/src/utils/{create-regex.js → create-regex.ts} +10 -10
  111. package/src/utils/filtering-utils.ts +91 -0
  112. package/src/utils/{sorting-utils.js → sorting-utils.ts} +35 -26
  113. package/dist/_app_/themes/default-theme.js +0 -1
  114. package/dist/_app_/utils/create-regex.js +0 -1
  115. package/dist/_app_/utils/filtering-utils.js +0 -1
  116. package/dist/_app_/utils/sorting-utils.js +0 -1
  117. package/src/components/yeti-table/header.gjs +0 -54
  118. package/src/components/yeti-table/pagination.gjs +0 -155
  119. package/src/components/yeti-table/table.gjs +0 -34
  120. package/src/components/yeti-table/tbody/row.gjs +0 -89
  121. package/src/components/yeti-table/tbody.gjs +0 -55
  122. package/src/components/yeti-table/tfoot/row/cell.gjs +0 -45
  123. package/src/components/yeti-table/tfoot/row.gjs +0 -44
  124. package/src/components/yeti-table/tfoot.gjs +0 -33
  125. package/src/components/yeti-table/thead/row/column.gjs +0 -260
  126. package/src/components/yeti-table/thead/row.gjs +0 -71
  127. package/src/components/yeti-table/thead.gjs +0 -45
  128. package/src/components/yeti-table.gjs +0 -780
  129. package/src/utils/filtering-utils.js +0 -75
  130. /package/src/{.gitkeep → index.ts} +0 -0
@@ -4,19 +4,19 @@ import { scheduleOnce, later, schedule } from '@ember/runloop';
4
4
  import { isPresent, isEmpty } from '@ember/utils';
5
5
  import Component from '@glimmer/component';
6
6
  import { cached, tracked } from '@glimmer/tracking';
7
+ import Helper from '@ember/component/helper';
7
8
  import merge from 'deepmerge';
8
9
  import { use } from 'ember-resources';
9
10
  import { trackedFunction } from 'reactiveweb/function';
10
11
  import { keepLatest } from 'reactiveweb/keep-latest';
11
12
  import { localCopy, dedupeTracked } from 'tracked-toolbox';
12
- import DEFAULT_THEME from '../themes/default-theme.js';
13
+ import { hash } from '@ember/helper';
14
+ import defaultTheme from '../themes/default-theme.js';
13
15
  import filterData from '../utils/filtering-utils.js';
14
16
  import { sortMultiple, compareValues, mergeSort } from '../utils/sorting-utils.js';
15
- import Helper from '@ember/component/helper';
16
- import { hash } from '@ember/helper';
17
17
  import Table from './yeti-table/table.js';
18
18
  import Header from './yeti-table/header.js';
19
- import THead from './yeti-table/thead.js';
19
+ import THeadComponent from './yeti-table/thead.js';
20
20
  import Body from './yeti-table/body.js';
21
21
  import TBody from './yeti-table/tbody.js';
22
22
  import TFoot from './yeti-table/tfoot.js';
@@ -27,16 +27,13 @@ import { g, i, n } from 'decorator-transforms/runtime-esm';
27
27
 
28
28
  const TASK_CANCELATION_NAME = 'TaskCancelation';
29
29
  const didCancel = function (e) {
30
- return e && e.name === TASK_CANCELATION_NAME;
30
+ return !!e && e.name === TASK_CANCELATION_NAME;
31
31
  };
32
- const getConfigWithDefault = function (key, defaultValue) {
32
+ function getConfigWithDefault(key, defaultValue) {
33
33
  return function () {
34
34
  return this.config[key] ?? defaultValue;
35
35
  };
36
- };
37
- // we keep `totalRows` updated manually in xwaan untracked property
38
- // to allow the user to update it in a loadData call and avoid
39
- // a re-run of the main tracked function
36
+ }
40
37
  class UpdateTotalRows extends Helper {
41
38
  compute(positional, {
42
39
  context
@@ -47,9 +44,6 @@ class UpdateTotalRows extends Helper {
47
44
  return '';
48
45
  }
49
46
  }
50
- // we need some control of how we update the filter property, hence this modifier
51
- // in this case, any falsy value will be considered as en empty string, which will then
52
- // be deduped.
53
47
  class UpdateFilter extends Helper {
54
48
  compute(positional, {
55
49
  context
@@ -59,94 +53,27 @@ class UpdateFilter extends Helper {
59
53
  }
60
54
  }
61
55
  class ProcessedData extends Helper {
62
- compute(positional, {
56
+ compute(_positional, {
63
57
  loadData,
64
58
  context
65
59
  }) {
66
- let data = context.latestData ?? [];
60
+ const data = context.latestData ?? [];
67
61
  if (!loadData) {
68
62
  context.processData(data);
69
63
  } else {
70
- // This is instrumental to ignoreDataChanges working
71
64
  context.processedData = data;
72
65
  }
73
66
  return '';
74
67
  }
75
68
  }
76
69
  class YetiTable extends Component {
77
- static {
78
- setComponentTemplate(precompileTemplate("{{#let (hash table=(component Table theme=this.mergedTheme parent=this) header=(component Header columns=this.columns onColumnClick=this.onColumnSort sortable=this.sortable sortSequence=this.sortSequence parent=this theme=this.mergedTheme) thead=(component THead columns=this.columns onColumnClick=this.onColumnSort sortable=this.sortable sortSequence=this.sortSequence theme=this.mergedTheme parent=this) body=(component Body data=this.processedData columns=this.columns theme=this.mergedTheme parent=this) tbody=(component TBody data=this.processedData columns=this.columns theme=this.mergedTheme parent=this) tfoot=(component TFoot columns=this.columns theme=this.mergedTheme parent=this) pagination=(component Pagination disabled=this.isLoading theme=this.mergedTheme paginationData=this.paginationData paginationActions=(hash previousPage=this.previousPage nextPage=this.nextPage goToPage=this.goToPage changePageSize=this.changePageSize)) actions=this.publicApi paginationData=this.paginationData isLoading=this.resolvedData.isPending columns=this.columns visibleColumns=this.visibleColumns rows=this.normalizedRows totalRows=this.normalizedTotalRows visibleRows=this.processedData theme=this.mergedTheme) as |api|}}\n {{UpdateTotalRows @totalRows context=this}}\n {{UpdateFilter @filter context=this}}\n {{ProcessedData loadData=@loadData context=this}}\n\n {{#if this.renderTableElement}}\n <Table @theme={{this.mergedTheme}} @parent={{this}} ...attributes>\n {{yield api}}\n </Table>\n {{else}}\n {{yield api}}\n {{/if}}\n\n{{/let}}", {
79
- strictMode: true,
80
- scope: () => ({
81
- hash,
82
- Table,
83
- Header,
84
- THead,
85
- Body,
86
- TBody,
87
- TFoot,
88
- Pagination,
89
- UpdateTotalRows,
90
- UpdateFilter,
91
- ProcessedData
92
- })
93
- }), this);
94
- }
95
- /**
96
- * An object that contains classes for yeti table to apply when rendering its various table
97
- * html elements. The theme object your pass in will be deeply merged with yeti-table's default theme
98
- * and with a theme defined in your environment.js at `ENV['ember-yeti-table'].theme`.
99
- *
100
- * @argument theme
101
- * @type {Object}
102
- */ /**
103
- * The data for Yeti Table to render. It can be an array or a promise that resolves with an array.
104
- * The only case when `@data` is optional is if a `@loadData` was passed in.
105
- * @argument data
106
- * @type {Array | Promise<Array>}
107
- */ /**
108
- * The function that will be called when Yeti Table needs data. This argument is used
109
- * when you don't have all the data available or loading all rows at once isn't possible,
110
- * e.g the dataset is too large.
111
- *
112
- * By passing in a function to `@loadData` you assume the responsibility to filter, sort and
113
- * paginate the data (if said features are enabled).
114
- *
115
- * This function must return an array or a promise that resolves with an array.
116
- *
117
- * This function will be called with an argument with the current state of the table.
118
- * Use this object to know what data to fetch, pass it to the server, etc.
119
- * Please check the "Async Data" guide to understand what that object contains and
120
- * an example of its usage.
121
- *
122
- * @argument loadData
123
- * @type {Function}
124
- */
125
70
  publicApi = {
126
- previousPage: this.previousPage,
127
- nextPage: this.nextPage,
128
- goToPage: this.goToPage,
129
- changePageSize: this.changePageSize,
130
- reloadData: this.reloadData
71
+ previousPage: () => this.previousPage(),
72
+ nextPage: () => this.nextPage(),
73
+ goToPage: n => this.goToPage(n),
74
+ changePageSize: n => this.changePageSize(n),
75
+ reloadData: () => this.reloadData()
131
76
  };
132
- /**
133
- * This function will be called when Yeti Table initializes. It will be called with
134
- * an object argument containing the functions for the possible actions you can make
135
- * on a table. This object contains the following actions:
136
- * - previousPage
137
- * - nextPage
138
- * - goToPage
139
- * - changePageSize
140
- * - reloadData
141
- *
142
- * @argument registerApi
143
- * @type {Function}
144
- */ /**
145
- * Use this argument to enable the pagination feature. Default is `false`.
146
- *
147
- * @argument pagination
148
- * @type {Boolean}
149
- */
150
77
  static {
151
78
  g(this.prototype, "pagination", [localCopy('args.pagination', getConfigWithDefault('pagination', false))]);
152
79
  }
@@ -155,49 +82,11 @@ class YetiTable extends Component {
155
82
  g(this.prototype, "pageSize", [localCopy('args.pageSize', getConfigWithDefault('pageSize', 15))]);
156
83
  }
157
84
  #pageSize = (i(this, "pageSize"), void 0);
158
- /**
159
- * Controls the size of each page. Default is `15`.
160
- *
161
- * @argument pageSize
162
- * @type {number}
163
- */
164
85
  static {
165
86
  g(this.prototype, "pageNumber", [localCopy('args.pageNumber', 1)]);
166
87
  }
167
88
  #pageNumber = (i(this, "pageNumber"), void 0);
168
- /**
169
- * Controls the current page to show. Default is `1`.
170
- *
171
- * @argument pageNumber
172
- * @type {number}
173
- */
174
- /**
175
- * Optional argument that informs yeti table of how many rows your data has.
176
- * Only needed when using a `@loadData` function and `@pagination={{true}}`.
177
- * When you use `@data`, Yeti Table uses the size of that array.
178
- * This information is used to calculate the pagination information that is yielded
179
- * and passed to the `@loadData` function.
180
- *
181
- * @argument totalRows
182
- * @type {number}
183
- */
184
89
  totalRows;
185
- // we keep `totalRows` updated manually in an untracked property
186
- // to allow the user to update it in a loadData call and avoid
187
- // a re-run of the main tracked function
188
- // @action
189
- // updateTotalRows(totalRows) {
190
- // this.totalRows = totalRows;
191
- // notifyPropertyChange(this, 'normalizedTotalRows');
192
- // notifyPropertyChange(this, 'paginationData');
193
- // }
194
- /**
195
- * The global filter. If passed in, Yeti Table will search all the rows that contain this
196
- * string and show them. Defaults to `''`.
197
- *
198
- * @argument filter
199
- * @type {String}
200
- */
201
90
  static {
202
91
  g(this.prototype, "filter", [dedupeTracked], function () {
203
92
  return '';
@@ -207,120 +96,31 @@ class YetiTable extends Component {
207
96
  static {
208
97
  g(this.prototype, "sortable", [localCopy('args.sortable', getConfigWithDefault('sortable', true))]);
209
98
  }
210
- #sortable = (i(this, "sortable"), void 0); // we need some control of how we update the filter property, hence this modifier
211
- // in this case, any falsy value will be considered as en empty string, which will then
212
- // be deduped.
213
- // @action
214
- // updateFilter(filter) {
215
- // this.filter = filter || '';
216
- // }
217
- /**
218
- * An optional function to customize the filtering logic. This function should return true
219
- * or false to either include or exclude the row on the resulting set. If this function depends
220
- * on a value, pass that value as the `@filterUsing` argument.
221
- *
222
- * This function will be called with two arguments:
223
- * - `row` - the current data row to use for filtering
224
- * - `filterUsing` - the value you passed in as `@filterUsing`
225
- *
226
- * @argument filterFunction
227
- * @type {Function}
228
- */
229
- /**
230
- * If you `@filterFunction` function depends on a different value (other that `@filter`)
231
- * to show, pass it in this argument. Yeti Table uses this argument to know when to recalculate
232
- * the fitlered rows.
233
- *
234
- * @argument filterUsing
235
- * @type {Object}
236
- */
237
- /**
238
- * Used to enable/disable sorting on all columns. You should use this to avoid passing
239
- * the @sortable argument to all columns. Defaults to `true`.
240
- *
241
- * @argument sortable
242
- * @type {Boolean}
243
- */
99
+ #sortable = (i(this, "sortable"), void 0);
244
100
  static {
245
101
  g(this.prototype, "sortFunction", [localCopy('args.sortFunction', () => sortMultiple)]);
246
102
  }
247
103
  #sortFunction = (i(this, "sortFunction"), void 0);
248
- /**
249
- * Use the `@sortFunction` if you want to completely customize how the row sorting is done.
250
- * It will be invoked with two rows, the current sortings that are applied and the `@compareFunction`.
251
- *
252
- * @argument sortFunction
253
- * @type {Function}
254
- */
255
104
  static {
256
105
  g(this.prototype, "compareFunction", [localCopy('args.compareFunction', () => compareValues)]);
257
106
  }
258
107
  #compareFunction = (i(this, "compareFunction"), void 0);
259
- /**
260
- * Use `@compareFunction` if you just want to customize how two values relate to each other (not the entire row).
261
- * It will be invoked with two values and you just need to return `-1`, `0` or `1` depending on if first value is
262
- * greater than the second or not. The default compare function used is the `compare` function from `@ember/utils`.
263
- *
264
- * @argument compareFunction
265
- * @type {Function}
266
- */
267
108
  static {
268
109
  g(this.prototype, "sortSequence", [localCopy('args.sortSequence', getConfigWithDefault('sortSequence', ['asc', 'desc']))]);
269
110
  }
270
111
  #sortSequence = (i(this, "sortSequence"), void 0);
271
- /**
272
- * Use `@sortSequence` to customize the sequence in which the sorting order will cycle when
273
- * clicking on the table headers. You can either pass in a comma-separated string or an array
274
- * of strings. Accepted values are `'asc'`, `'desc'` and `'unsorted'`. The default value is `['asc', 'desc']`.
275
- *
276
- * @argument sortSequence
277
- * @type {Array<string> | string}
278
- */
279
112
  static {
280
113
  g(this.prototype, "ignoreDataChanges", [localCopy('args.ignoreDataChanges', getConfigWithDefault('ignoreDataChanges', false))]);
281
114
  }
282
115
  #ignoreDataChanges = (i(this, "ignoreDataChanges"), void 0);
283
- /**
284
- * Use `@ignoreDataChanges` to prevent yeti table from observing changes to the underlying data and resorting or
285
- * refiltering. Useful when doing inline editing in a table.
286
- *
287
- * Defaults to `false`.
288
- *
289
- * This is an initial render only value. Changing it after the table has been rendered will not be respected.
290
- *
291
- * @argument ignoreDataChanges
292
- * @type {boolean}
293
- */
294
116
  static {
295
117
  g(this.prototype, "renderTableElement", [localCopy('args.renderTableElement', true)]);
296
118
  }
297
119
  #renderTableElement = (i(this, "renderTableElement"), void 0);
298
- /**
299
- * Use `@renderTableElement` to prevent yeti table from rendering the topmost <table> element.
300
- * Might be useful for styling purposes (e.g if you want to place your pagination controls outside
301
- * of your table element). If you set this to `false`, you should render the table element yourself
302
- * using the yielded `<t.table>` component.
303
- *
304
- * Defaults to `true`.
305
- *
306
- * @argument renderTableElement
307
- * @type {boolean}
308
- */
309
- /**
310
- * The `@isColumnVisible` argument can be used to initialize the column visibility in a programmatic way.
311
- * For example, let's say you store the initial column visibility in local storage, then you can
312
- * use this function to initialize the `visible` column of the specific column. The given function should
313
- * return a boolean which will be assigned to the `visible` property of the column. An object representing
314
- * the column is passed in. Sou can use column.prop and column.name to know which column your computed
315
- * the visibility for.
316
- *
317
- * @argument isColumnVisible
318
- * @type {Function}
319
- */ // If the theme is replaced, this will invalidate, but not if any prop under theme is changed
320
120
  get mergedTheme() {
321
- let configTheme = this.config.theme || {};
322
- let localTheme = this.args.theme || {};
323
- return merge.all([DEFAULT_THEME, configTheme, localTheme]);
121
+ const configTheme = this.config.theme || {};
122
+ const localTheme = this.args.theme || {};
123
+ return merge.all([defaultTheme, configTheme, localTheme]);
324
124
  }
325
125
  static {
326
126
  n(this.prototype, "mergedTheme", [cached]);
@@ -331,43 +131,38 @@ class YetiTable extends Component {
331
131
  static {
332
132
  n(this.prototype, "visibleColumns", [cached]);
333
133
  }
334
- config = getOwner(this).resolveRegistration('config:environment')['ember-yeti-table'] || {};
134
+ config = getOwner(this)?.resolveRegistration?.('config:environment')?.['ember-yeti-table'] || {};
335
135
  get normalizedTotalRows() {
336
136
  if (!this.args.loadData) {
337
- // sync scenario using @data
338
137
  return this.processedDataRows?.length || 0;
339
138
  } else {
340
- // async scenario. @loadData is present.
341
139
  if (this.totalRows === undefined) {
342
- // @totalRows was not passed in. Use the latest returned data set length as a fallback
343
140
  return this.previousResolvedData.length || 0;
344
141
  } else {
345
- // @totalRows was passed in.
346
142
  return this.totalRows;
347
143
  }
348
144
  }
349
145
  }
350
146
  get normalizedRows() {
351
147
  if (!this.args.loadData) {
352
- // sync scenario using @data
353
148
  return this.processedDataRows;
354
149
  } else {
355
- // async scenario. @loadData is present.
356
150
  return this.processedData;
357
151
  }
358
152
  }
359
153
  get paginationData() {
360
- let pageSize = this.pageSize;
154
+ const pageSize = this.pageSize;
361
155
  let pageNumber = this.pageNumber;
362
- let totalRows = this.normalizedTotalRows;
363
- let isLastPage, totalPages;
156
+ const totalRows = this.normalizedTotalRows;
157
+ let isLastPage;
158
+ let totalPages;
364
159
  if (totalRows) {
365
160
  totalPages = Math.ceil(totalRows / pageSize);
366
161
  pageNumber = Math.min(pageNumber, totalPages);
367
162
  isLastPage = pageNumber === totalPages;
368
163
  }
369
- let isFirstPage = pageNumber === 1;
370
- let pageStart = (pageNumber - 1) * pageSize + 1;
164
+ const isFirstPage = pageNumber === 1;
165
+ const pageStart = (pageNumber - 1) * pageSize + 1;
371
166
  let pageEnd = pageStart + pageSize - 1;
372
167
  if (totalRows) {
373
168
  pageEnd = Math.min(pageEnd, totalRows);
@@ -389,44 +184,39 @@ class YetiTable extends Component {
389
184
  });
390
185
  }
391
186
  #columns = (i(this, "columns"), void 0);
392
- constructor(owner, args) {
393
- super(...arguments);
394
- console.log(owner, args);
395
- if (typeof this.args.registerApi === 'function') {
396
- // eslint-disable-next-line ember/no-runloop
397
- scheduleOnce('actions', null, this.args.registerApi, this.publicApi);
398
- }
399
- }
400
187
  previousResolvedData = [];
188
+ static {
189
+ g(this.prototype, "processedData", [tracked]);
190
+ }
191
+ #processedData = (i(this, "processedData"), void 0);
192
+ static {
193
+ g(this.prototype, "processedDataRows", [tracked]);
194
+ }
195
+ #processedDataRows = (i(this, "processedDataRows"), void 0);
401
196
  resolvedData = trackedFunction(this, async () => {
402
197
  let data = this.args.data;
403
198
  if (this.columns.length == 0) {
404
199
  return [];
405
200
  }
406
- // call loadData if exists
407
201
  if (typeof this.args.loadData === 'function') {
408
- let params = this.computeLoadDataParams();
202
+ const params = this.computeLoadDataParams();
409
203
  try {
410
- console.log("loadData", params);
411
204
  data = await this.args.loadData(params);
412
- console.log("loadData end");
413
205
  } catch (e) {
414
206
  console.log(e);
415
207
  if (!didCancel(e)) {
416
- // re-throw the non-cancellation error
417
208
  throw e;
418
209
  }
419
210
  }
420
- } else if (data?.then) {
421
- // resolve the data promise (either from the @loadData call or @data)
211
+ } else if (data && typeof data.then === 'function') {
422
212
  data = await data;
423
213
  }
424
214
  if (this.isDestroyed) {
425
215
  return;
426
216
  }
427
- data = data || [];
428
- this.previousResolvedData = data;
429
- return data;
217
+ const resolved = data || [];
218
+ this.previousResolvedData = resolved;
219
+ return resolved;
430
220
  });
431
221
  static {
432
222
  g(this.prototype, "latestData", [use], function () {
@@ -437,44 +227,39 @@ class YetiTable extends Component {
437
227
  });
438
228
  }
439
229
  #latestData = (i(this, "latestData"), void 0);
440
- static {
441
- g(this.prototype, "processedData", [tracked]);
442
- }
443
- #processedData = (i(this, "processedData"), void 0);
444
- static {
445
- g(this.prototype, "processedDataRows", [tracked]);
230
+ constructor(owner, args) {
231
+ super(owner, args);
232
+ if (typeof this.args.registerApi === 'function') {
233
+ // eslint-disable-next-line ember/no-runloop
234
+ scheduleOnce('actions', null, this.args.registerApi, this.publicApi);
235
+ }
446
236
  }
447
- #processedDataRows = (i(this, "processedDataRows"), void 0);
448
237
  processData(data) {
449
- // only columns that have filterable = true and a prop defined will be considered
450
- let columns = this.columns.filter(c => c.filterable && isPresent(c.prop));
451
- let sortableColumns = this.columns.filter(c => !isEmpty(c.sort));
452
- let sortings = sortableColumns.map(c => ({
238
+ const columns = this.columns.filter(c => c.filterable && isPresent(c.prop));
239
+ const sortableColumns = this.columns.filter(c => !isEmpty(c.sort));
240
+ const sortings = sortableColumns.map(c => ({
453
241
  prop: c.prop,
454
242
  direction: c.sort
455
243
  }));
456
- let filterFunction = this.args.filterFunction;
457
- let filterUsing = this.args.filterUsing;
458
- let filter = this.filter;
459
- let processTheData = () => {
460
- // filter the data
461
- data = filterData(data, columns, filter, filterFunction, filterUsing);
462
- // Sort the data
244
+ const filterFunction = this.args.filterFunction;
245
+ const filterUsing = this.args.filterUsing;
246
+ const filter = this.filter;
247
+ const processTheData = () => {
248
+ let working = filterData(data, columns, filter, filterFunction, filterUsing);
463
249
  if (sortings.length > 0) {
464
- data = mergeSort(data, (itemA, itemB) => {
250
+ working = mergeSort(working, (itemA, itemB) => {
465
251
  return this.sortFunction(itemA, itemB, sortings, this.compareFunction);
466
252
  });
467
253
  }
468
- this.processedDataRows = data;
469
- // Paginate the Data
254
+ this.processedDataRows = working;
470
255
  if (this.pagination) {
471
- let {
256
+ const {
472
257
  pageStart,
473
258
  pageEnd
474
259
  } = this.paginationData;
475
- data = data.slice(pageStart - 1, pageEnd); // slice excludes last element so we don't need to subtract 1
260
+ working = working.slice(pageStart - 1, pageEnd);
476
261
  }
477
- this.processedData = data;
262
+ this.processedData = working;
478
263
  };
479
264
  if (this.ignoreDataChanges) {
480
265
  // eslint-disable-next-line ember/no-runloop
@@ -484,32 +269,33 @@ class YetiTable extends Component {
484
269
  }
485
270
  }
486
271
  computeLoadDataParams() {
487
- let params = {};
272
+ const params = {
273
+ sortData: this.columns.filter(c => !isEmpty(c.sort)).map(c => ({
274
+ prop: c.prop,
275
+ direction: c.sort
276
+ })),
277
+ filterData: {
278
+ filter: this.filter,
279
+ filterUsing: this.args.filterUsing,
280
+ columnFilters: this.columns.map(c => ({
281
+ prop: c.prop,
282
+ filter: c.filter,
283
+ filterUsing: c.filterUsing
284
+ }))
285
+ }
286
+ };
488
287
  if (this.pagination) {
489
288
  params.paginationData = this.paginationData;
490
289
  }
491
- params.sortData = this.columns.filter(c => !isEmpty(c.sort)).map(c => ({
492
- prop: c.prop,
493
- direction: c.sort
494
- }));
495
- params.filterData = {
496
- filter: this.filter,
497
- filterUsing: this.args.filterUsing,
498
- columnFilters: this.columns.map(c => ({
499
- prop: c.prop,
500
- filter: c.filter,
501
- filterUsing: c.filterUsing
502
- }))
503
- };
504
290
  return params;
505
291
  }
506
292
  paginateData(data) {
507
293
  if (this.pagination) {
508
- let {
294
+ const {
509
295
  pageStart,
510
296
  pageEnd
511
297
  } = this.paginationData;
512
- data = data.slice(pageStart - 1, pageEnd); // slice excludes last element so we don't need to subtract 1
298
+ data = data.slice(pageStart - 1, pageEnd);
513
299
  }
514
300
  return data;
515
301
  }
@@ -521,30 +307,22 @@ class YetiTable extends Component {
521
307
  }
522
308
  onColumnSort(column, e) {
523
309
  if (column.isSorted) {
524
- // if this column is already sorted, calculate the next
525
- // sorting on the sequence.
526
310
  let direction = column.sort;
527
- let sortSequence = column.normalizedSortSequence;
311
+ const sortSequence = column.normalizedSortSequence;
528
312
  direction = sortSequence[(sortSequence.indexOf(direction) + 1) % sortSequence.length];
529
313
  if (direction === 'unsorted') {
530
314
  direction = null;
531
315
  }
532
316
  column.sort = direction;
533
317
  if (!e.shiftKey) {
534
- // if not pressed shift, reset other column sorting
535
- let columns = this.columns.filter(c => c !== column);
318
+ const columns = this.columns.filter(c => c !== column);
536
319
  columns.forEach(c => c.sort = null);
537
320
  }
538
321
  } else {
539
- // use first direction from sort sequence
540
- let direction = column.normalizedSortSequence[0];
541
- // create new sorting
322
+ const direction = column.normalizedSortSequence[0];
542
323
  column.sort = direction;
543
- // normal click replaces all sortings with the new one
544
- // shift click adds a new sorting to the existing ones
545
324
  if (!e.shiftKey) {
546
- // if not pressed shift, reset other column sortings
547
- let columns = this.columns.filter(c => c !== column);
325
+ const columns = this.columns.filter(c => c !== column);
548
326
  columns.forEach(c => c.sort = null);
549
327
  }
550
328
  }
@@ -562,7 +340,7 @@ class YetiTable extends Component {
562
340
  }
563
341
  nextPage() {
564
342
  if (this.pagination) {
565
- let {
343
+ const {
566
344
  isLastPage
567
345
  } = this.paginationData;
568
346
  if (!isLastPage) {
@@ -575,7 +353,7 @@ class YetiTable extends Component {
575
353
  }
576
354
  goToPage(pageNumber) {
577
355
  if (this.pagination) {
578
- let {
356
+ const {
579
357
  totalPages
580
358
  } = this.paginationData;
581
359
  pageNumber = Math.max(pageNumber, 1);
@@ -590,7 +368,7 @@ class YetiTable extends Component {
590
368
  }
591
369
  changePageSize(pageSize) {
592
370
  if (this.pagination) {
593
- this.pageSize = parseInt(pageSize);
371
+ this.pageSize = parseInt(String(pageSize));
594
372
  }
595
373
  }
596
374
  static {
@@ -612,6 +390,24 @@ class YetiTable extends Component {
612
390
  this.columns = this.columns.filter(c => c !== column);
613
391
  }
614
392
  }
393
+ static {
394
+ setComponentTemplate(precompileTemplate("{{#let (hash table=(component Table theme=this.mergedTheme parent=this) header=(component HeaderComponent columns=this.columns onColumnClick=this.onColumnSort sortable=this.sortable sortSequence=this.sortSequence parent=this theme=this.mergedTheme) thead=(component THead columns=this.columns onColumnClick=this.onColumnSort sortable=this.sortable sortSequence=this.sortSequence theme=this.mergedTheme parent=this) body=(component Body data=this.processedData columns=this.columns theme=this.mergedTheme parent=this) tbody=(component TBody data=this.processedData columns=this.columns theme=this.mergedTheme parent=this) tfoot=(component TFoot columns=this.columns theme=this.mergedTheme parent=this) pagination=(component Pagination disabled=this.resolvedData.isPending theme=this.mergedTheme paginationData=this.paginationData paginationActions=(hash previousPage=this.previousPage nextPage=this.nextPage goToPage=this.goToPage changePageSize=this.changePageSize)) actions=this.publicApi paginationData=this.paginationData isLoading=this.resolvedData.isPending columns=this.columns visibleColumns=this.visibleColumns rows=this.normalizedRows totalRows=this.normalizedTotalRows visibleRows=this.processedData theme=this.mergedTheme) as |api|}}\n {{UpdateTotalRows @totalRows context=this}}\n {{UpdateFilter @filter context=this}}\n {{ProcessedData loadData=@loadData context=this}}\n\n {{#if this.renderTableElement}}\n <Table @theme={{this.mergedTheme}} @parent={{this}} ...attributes>\n {{yield api}}\n </Table>\n {{else}}\n {{yield api}}\n {{/if}}\n\n{{/let}}", {
395
+ strictMode: true,
396
+ scope: () => ({
397
+ hash,
398
+ Table,
399
+ HeaderComponent: Header,
400
+ THead: THeadComponent,
401
+ Body,
402
+ TBody,
403
+ TFoot,
404
+ Pagination,
405
+ UpdateTotalRows,
406
+ UpdateFilter,
407
+ ProcessedData
408
+ })
409
+ }), this);
410
+ }
615
411
  }
616
412
 
617
413
  export { YetiTable as default };