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,127 @@
1
+ import { Resource } from 'ember-resources/core';
2
+ import { Column } from "./-private/column";
3
+ import { TablePreferences } from "./-private/preferences";
4
+ import { Row } from "./-private/row";
5
+ import { BasePlugin, Plugin } from "./plugins/index";
6
+ import { Class } from "./-private/private-types";
7
+ import { TableConfig } from "./-private/interfaces/index";
8
+ interface Signature<DataType> {
9
+ Named: TableConfig<DataType>;
10
+ }
11
+ /**
12
+ * Because the table is our entry-point object to all the table behaviors,
13
+ * we need a stable way to know which table we have.
14
+ * Normally, this could be done with referential integrity / identity.
15
+ * However, due to how resources are implemented, if the consumer opts to
16
+ * not use the `@use` decorator, then proxies get involved.
17
+ * The proxies don't maintain instanceof checks, which may be a bug in
18
+ * ember-resources.
19
+ */
20
+ declare const TABLE_KEY: unique symbol;
21
+ declare class Table<DataType = unknown> extends Resource<Signature<DataType>> {
22
+ /**
23
+ * @private
24
+ */
25
+ [TABLE_KEY]: string;
26
+ /**
27
+ * @private
28
+ */
29
+ scrollContainerHeight?: number;
30
+ /**
31
+ * @private
32
+ */
33
+ scrollContainerWidth?: number;
34
+ /**
35
+ * @private
36
+ */
37
+ args: {
38
+ named: Signature<DataType>['Named'];
39
+ };
40
+ /**
41
+ * @private
42
+ */
43
+ defaultColumnConfig: {
44
+ isVisible: boolean;
45
+ minWidth: number;
46
+ };
47
+ /**
48
+ * @private
49
+ */
50
+ scrollContainerElement?: HTMLElement;
51
+ /**
52
+ * Interact with, save, modify, etc the preferences for the table,
53
+ * plugins, columns, etc
54
+ */
55
+ preferences: TablePreferences;
56
+ /**
57
+ * @private
58
+ */
59
+ /**
60
+ * @private
61
+ */
62
+ modify(_: [] | undefined, named: Signature<DataType>['Named']): void;
63
+ /**
64
+ * Collection of utility modifiers that are the result of composing modifiers
65
+ * from plugins.
66
+ *
67
+ * Using this is optional, and you can "just" use modifiers from specific plugins
68
+ * in specific places if you wish -- but these exists as a "convenience".
69
+ *
70
+ * These are all no-use, no-cost utilities
71
+ */
72
+ modifiers: {
73
+ container: import("ember-modifier").FunctionBasedModifier<{
74
+ Args: {
75
+ Named: Record<string, unknown>;
76
+ Positional: unknown[];
77
+ };
78
+ Element: HTMLElement;
79
+ }>;
80
+ columnHeader: import("ember-modifier").FunctionBasedModifier<{
81
+ Args: {
82
+ Named: Record<string, unknown>;
83
+ Positional: [Column<DataType>];
84
+ };
85
+ Element: HTMLElement;
86
+ }>;
87
+ row: import("ember-modifier").FunctionBasedModifier<{
88
+ Args: {
89
+ Named: Record<string, unknown>;
90
+ Positional: [Row<DataType>];
91
+ };
92
+ Element: HTMLElement;
93
+ }>;
94
+ };
95
+ /**
96
+ * @private
97
+ *
98
+ * For all configured plugins, instantiates each one.
99
+ * If the plugins argument changes to the Table (either directly or through
100
+ * headlessTable, all state is lost and re-created)
101
+ */
102
+ get plugins(): Plugin[];
103
+ /**
104
+ * Get the active plugin instance for the given plugin class
105
+ */
106
+ /**
107
+ * Get the active plugin instance for the given plugin class
108
+ */
109
+ pluginOf<Instance extends BasePlugin<any>>(klass: Class<Instance>): Instance | undefined;
110
+ /**
111
+ * @private
112
+ *
113
+ * used by other private APIs
114
+ */
115
+ get config(): TableConfig<DataType>;
116
+ rows: import("ember-resources/util/map").MappedArray<Row<DataType>>;
117
+ columns: import("ember-resources/util/map").MappedArray<Column<DataType>>;
118
+ /**
119
+ * @private
120
+ */
121
+ /**
122
+ * @private
123
+ */
124
+ resetScrollContainer(): void;
125
+ resetToDefaults(): void;
126
+ }
127
+ export { TABLE_KEY, Table };
@@ -0,0 +1,249 @@
1
+ import { _ as _defineProperty } from './defineProperty-a0196711.js';
2
+ import { _ as _applyDecoratedDescriptor } from './applyDecoratedDescriptor-e0489e2f.js';
3
+ import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';
4
+ import { tracked } from '@glimmer/tracking';
5
+ import { getOwner, setOwner } from '@ember/application';
6
+ import { assert } from '@ember/debug';
7
+ import { action } from '@ember/object';
8
+ import { guidFor } from '@ember/object/internals';
9
+ import { modifier } from 'ember-modifier';
10
+ import { Resource } from 'ember-resources/core';
11
+ import { map } from 'ember-resources/util/map';
12
+ import { normalizePluginsConfig, verifyPlugins } from './plugins/-private/utils.js';
13
+ import { Column } from './-private/column.js';
14
+ import { TablePreferences } from './-private/preferences.js';
15
+ import { Row } from './-private/row.js';
16
+ import { composeFunctionModifiers } from './-private/utils.js';
17
+
18
+ function _initializerDefineProperty(target, property, descriptor, context) {
19
+ if (!descriptor) return;
20
+ Object.defineProperty(target, property, {
21
+ enumerable: descriptor.enumerable,
22
+ configurable: descriptor.configurable,
23
+ writable: descriptor.writable,
24
+ value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
25
+ });
26
+ }
27
+
28
+ var _class, _descriptor, _descriptor2, _descriptor3;
29
+ let cached = macroCondition(dependencySatisfies('ember-source', '>= 4.1.0-alpha.0')) ? importSync('@glimmer/tracking').cached : importSync('ember-cached-decorator-polyfill').cached;
30
+ const DEFAULT_COLUMN_CONFIG = {
31
+ isVisible: true,
32
+ minWidth: 128
33
+ };
34
+
35
+ /**
36
+ * Because the table is our entry-point object to all the table behaviors,
37
+ * we need a stable way to know which table we have.
38
+ * Normally, this could be done with referential integrity / identity.
39
+ * However, due to how resources are implemented, if the consumer opts to
40
+ * not use the `@use` decorator, then proxies get involved.
41
+ * The proxies don't maintain instanceof checks, which may be a bug in
42
+ * ember-resources.
43
+ */
44
+ const TABLE_KEY = Symbol('__TABLE_KEY__');
45
+
46
+ const attachContainer = (element, table) => {
47
+ assert('Must be installed on an HTMLElement', element instanceof HTMLElement);
48
+ table.scrollContainerElement = element;
49
+ };
50
+
51
+ let Table = (_class = class Table extends Resource {
52
+ constructor(...args) {
53
+ super(...args);
54
+
55
+ _defineProperty(this, TABLE_KEY, guidFor(this));
56
+
57
+ _initializerDefineProperty(this, "scrollContainerHeight", _descriptor, this);
58
+
59
+ _initializerDefineProperty(this, "scrollContainerWidth", _descriptor2, this);
60
+
61
+ _initializerDefineProperty(this, "args", _descriptor3, this);
62
+
63
+ _defineProperty(this, "defaultColumnConfig", DEFAULT_COLUMN_CONFIG);
64
+
65
+ _defineProperty(this, "scrollContainerElement", void 0);
66
+
67
+ _defineProperty(this, "modifiers", {
68
+ container: modifier(element => {
69
+ let modifiers = this.plugins.map(plugin => plugin.containerModifier);
70
+ let composed = composeFunctionModifiers([attachContainer, ...modifiers]);
71
+ return composed(element, this);
72
+ }, {
73
+ eager: false
74
+ }),
75
+ // resize: ResizeModifier,
76
+ // TODO: switch to composing real modifiers once "curry" and "compose"
77
+ // RFCs are accepted and implemented
78
+ //
79
+ // Atm the moment, if _any_ header modifier's tracked data changes,
80
+ // all the functions for all of the plugins run again.
81
+ //
82
+ // With curried+composed modifiers, only the plugin's headerModifier
83
+ // that has tracked changes would run, leaving the other modifiers alone
84
+ columnHeader: modifier((element, [column]) => {
85
+ let modifiers = this.plugins.map(plugin => plugin.headerCellModifier);
86
+ let composed = composeFunctionModifiers(modifiers);
87
+ return composed(element, {
88
+ column,
89
+ table: this
90
+ });
91
+ }, {
92
+ eager: false
93
+ }),
94
+ row: modifier((element, [row]) => {
95
+ let modifiers = this.plugins.map(plugin => plugin.rowModifier);
96
+ let composed = composeFunctionModifiers(modifiers);
97
+ return composed(element, {
98
+ row,
99
+ table: this
100
+ });
101
+ }, {
102
+ eager: false
103
+ })
104
+ });
105
+
106
+ _defineProperty(this, "rows", map(this, {
107
+ data: () => {
108
+ let dataFn = this.args.named?.data;
109
+ if (!dataFn) return [];
110
+ return dataFn() ?? [];
111
+ },
112
+ map: datum => new Row(this, datum)
113
+ }));
114
+
115
+ _defineProperty(this, "columns", map(this, {
116
+ data: () => {
117
+ let configFn = this.args.named?.columns;
118
+ if (!configFn) return [];
119
+ return configFn() ?? [];
120
+ },
121
+ map: config => {
122
+ return new Column(this, { ...this.defaultColumnConfig,
123
+ ...config
124
+ });
125
+ }
126
+ }));
127
+ }
128
+
129
+ /**
130
+ * @private
131
+ */
132
+ modify(_, named) {
133
+ this.args = {
134
+ named
135
+ }; // only set the preferences once
136
+
137
+ if (!this.preferences) {
138
+ let {
139
+ key = guidFor(this),
140
+ adapter
141
+ } = named?.preferences ?? {}; // TODO: when no key is present,
142
+ // use "local-storage" preferences.
143
+ // it does not make sense to use a guid in a user's preferences
144
+
145
+ this.preferences = new TablePreferences(key, adapter);
146
+ } else {
147
+ // subsequent updates to args
148
+ this.resetScrollContainer();
149
+ }
150
+ }
151
+ /**
152
+ * Collection of utility modifiers that are the result of composing modifiers
153
+ * from plugins.
154
+ *
155
+ * Using this is optional, and you can "just" use modifiers from specific plugins
156
+ * in specific places if you wish -- but these exists as a "convenience".
157
+ *
158
+ * These are all no-use, no-cost utilities
159
+ */
160
+
161
+
162
+ /**
163
+ * @private
164
+ *
165
+ * For all configured plugins, instantiates each one.
166
+ * If the plugins argument changes to the Table (either directly or through
167
+ * headlessTable, all state is lost and re-created)
168
+ */
169
+ get plugins() {
170
+ let plugins = normalizePluginsConfig(this.args.named?.plugins);
171
+ verifyPlugins(plugins);
172
+ return plugins.map(tuple => {
173
+ // We don't need the options here
174
+ let [PluginClass] = tuple;
175
+
176
+ if (typeof PluginClass === 'function') {
177
+ let plugin = new PluginClass(this);
178
+ let owner = getOwner(this);
179
+ assert(`The Table does not have an owner. cannot create a plugin without an owner`, owner);
180
+ setOwner(plugin, owner);
181
+ return plugin;
182
+ } // This is a plugin object, rather than a class
183
+ // TODO: add test coverage around using classless plugins
184
+
185
+
186
+ return PluginClass;
187
+ });
188
+ }
189
+ /**
190
+ * Get the active plugin instance for the given plugin class
191
+ */
192
+
193
+
194
+ pluginOf(klass) {
195
+ let result = this.plugins.find(plugin => plugin instanceof klass);
196
+ /**
197
+ * This is an unsafe cast, because Instance could be unrelated to any of the types
198
+ * that matches Plugin[]
199
+ *
200
+ * For example, `table.pluginOf(MyCustomPlugin)`, where MyCustomPlugin isn't in the
201
+ * `plugins` list. This partially a problem with how Array.prototype.find doesn't
202
+ * effectively narrow for what we want (combined with TS being clunky around
203
+ * comparing Instance and Class types).
204
+ */
205
+
206
+ return result;
207
+ }
208
+ /**
209
+ * @private
210
+ *
211
+ * used by other private APIs
212
+ */
213
+
214
+
215
+ get config() {
216
+ return this.args.named;
217
+ }
218
+
219
+ /**
220
+ * @private
221
+ */
222
+ resetScrollContainer() {
223
+ if (!this.scrollContainerElement) return;
224
+ this.scrollContainerElement.scrollTop = 0;
225
+ }
226
+
227
+ resetToDefaults() {
228
+ this.plugins.forEach(plugin => plugin.reset?.());
229
+ }
230
+
231
+ }, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "scrollContainerHeight", [tracked], {
232
+ configurable: true,
233
+ enumerable: true,
234
+ writable: true,
235
+ initializer: null
236
+ }), _descriptor2 = _applyDecoratedDescriptor(_class.prototype, "scrollContainerWidth", [tracked], {
237
+ configurable: true,
238
+ enumerable: true,
239
+ writable: true,
240
+ initializer: null
241
+ }), _descriptor3 = _applyDecoratedDescriptor(_class.prototype, "args", [tracked], {
242
+ configurable: true,
243
+ enumerable: true,
244
+ writable: true,
245
+ initializer: null
246
+ }), _applyDecoratedDescriptor(_class.prototype, "plugins", [cached], Object.getOwnPropertyDescriptor(_class.prototype, "plugins"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "resetScrollContainer", [action], Object.getOwnPropertyDescriptor(_class.prototype, "resetScrollContainer"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "resetToDefaults", [action], Object.getOwnPropertyDescriptor(_class.prototype, "resetToDefaults"), _class.prototype)), _class);
247
+
248
+ export { TABLE_KEY as T, _initializerDefineProperty as _, Table as a };
249
+ //# sourceMappingURL=table-8e46554b.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-8e46554b.js","sources":["../../node_modules/.pnpm/@babel+runtime@7.19.4/node_modules/@babel/runtime/helpers/esm/initializerDefineProperty.js","../src/-private/table.ts"],"sourcesContent":["export default function _initializerDefineProperty(target, property, descriptor, context) {\n if (!descriptor) return;\n Object.defineProperty(target, property, {\n enumerable: descriptor.enumerable,\n configurable: descriptor.configurable,\n writable: descriptor.writable,\n value: descriptor.initializer ? descriptor.initializer.call(context) : void 0\n });\n}","import { cached, tracked } from '@glimmer/tracking';\nimport { getOwner, setOwner } from '@ember/application';\nimport { assert } from '@ember/debug';\nimport { action } from '@ember/object';\nimport { guidFor } from '@ember/object/internals';\n\nimport { modifier } from 'ember-modifier';\nimport { Resource } from 'ember-resources/core';\nimport { map } from 'ember-resources/util/map';\n\nimport { normalizePluginsConfig, verifyPlugins } from '../plugins/-private/utils';\nimport { Column } from './column';\nimport { TablePreferences } from './preferences';\nimport { Row } from './row';\nimport { composeFunctionModifiers } from './utils';\n\nimport type { BasePlugin, Plugin } from '../plugins';\nimport type { Class } from '[private-types]';\nimport type { Destructor, TableConfig } from '#interfaces';\n\nconst DEFAULT_COLUMN_CONFIG = {\n isVisible: true,\n minWidth: 128,\n};\n\ninterface Signature<DataType> {\n Named: TableConfig<DataType>;\n}\n\n/**\n * Because the table is our entry-point object to all the table behaviors,\n * we need a stable way to know which table we have.\n * Normally, this could be done with referential integrity / identity.\n * However, due to how resources are implemented, if the consumer opts to\n * not use the `@use` decorator, then proxies get involved.\n * The proxies don't maintain instanceof checks, which may be a bug in\n * ember-resources.\n */\nexport const TABLE_KEY = Symbol('__TABLE_KEY__');\n\nconst attachContainer = (element: Element, table: Table) => {\n assert('Must be installed on an HTMLElement', element instanceof HTMLElement);\n\n table.scrollContainerElement = element;\n};\n\nexport class Table<DataType = unknown> extends Resource<Signature<DataType>> {\n /**\n * @private\n */\n [TABLE_KEY] = guidFor(this);\n\n /**\n * @private\n */\n @tracked scrollContainerHeight?: number;\n\n /**\n * @private\n */\n @tracked scrollContainerWidth?: number;\n\n /**\n * @private\n */\n @tracked declare args: { named: Signature<DataType>['Named'] };\n\n /**\n * @private\n */\n defaultColumnConfig = DEFAULT_COLUMN_CONFIG;\n\n /**\n * @private\n */\n scrollContainerElement?: HTMLElement;\n\n /**\n * Interact with, save, modify, etc the preferences for the table,\n * plugins, columns, etc\n */\n declare preferences: TablePreferences;\n\n /**\n * @private\n */\n modify(_: [] | undefined, named: Signature<DataType>['Named']) {\n this.args = { named };\n\n // only set the preferences once\n if (!this.preferences) {\n let { key = guidFor(this), adapter } = named?.preferences ?? {};\n\n // TODO: when no key is present,\n // use \"local-storage\" preferences.\n // it does not make sense to use a guid in a user's preferences\n this.preferences = new TablePreferences(key, adapter);\n } else {\n // subsequent updates to args\n this.resetScrollContainer();\n }\n }\n\n /**\n * Collection of utility modifiers that are the result of composing modifiers\n * from plugins.\n *\n * Using this is optional, and you can \"just\" use modifiers from specific plugins\n * in specific places if you wish -- but these exists as a \"convenience\".\n *\n * These are all no-use, no-cost utilities\n */\n modifiers = {\n container: modifier(\n (element: HTMLElement): Destructor => {\n let modifiers = this.plugins.map((plugin) => plugin.containerModifier);\n let composed = composeFunctionModifiers([attachContainer, ...modifiers]);\n\n return composed(element, this);\n },\n { eager: false }\n ),\n\n // resize: ResizeModifier,\n // TODO: switch to composing real modifiers once \"curry\" and \"compose\"\n // RFCs are accepted and implemented\n //\n // Atm the moment, if _any_ header modifier's tracked data changes,\n // all the functions for all of the plugins run again.\n //\n // With curried+composed modifiers, only the plugin's headerModifier\n // that has tracked changes would run, leaving the other modifiers alone\n columnHeader: modifier(\n (element: HTMLElement, [column]: [Column<DataType>]): Destructor => {\n let modifiers = this.plugins.map((plugin) => plugin.headerCellModifier);\n let composed = composeFunctionModifiers(modifiers);\n\n return composed(element, { column, table: this });\n },\n { eager: false }\n ),\n\n row: modifier(\n (element: HTMLElement, [row]: [Row<DataType>]): Destructor => {\n let modifiers = this.plugins.map((plugin) => plugin.rowModifier);\n let composed = composeFunctionModifiers(modifiers);\n\n return composed(element, { row, table: this });\n },\n { eager: false }\n ),\n };\n\n /**\n * @private\n *\n * For all configured plugins, instantiates each one.\n * If the plugins argument changes to the Table (either directly or through\n * headlessTable, all state is lost and re-created)\n */\n @cached\n get plugins(): Plugin[] {\n let plugins = normalizePluginsConfig(this.args.named?.plugins);\n\n verifyPlugins(plugins);\n\n return plugins.map((tuple) => {\n // We don't need the options here\n let [PluginClass] = tuple;\n\n if (typeof PluginClass === 'function') {\n let plugin = new PluginClass(this);\n\n let owner = getOwner(this);\n\n assert(`The Table does not have an owner. cannot create a plugin without an owner`, owner);\n setOwner(plugin, owner);\n\n return plugin;\n }\n\n // This is a plugin object, rather than a class\n // TODO: add test coverage around using classless plugins\n return PluginClass;\n });\n }\n\n /**\n * Get the active plugin instance for the given plugin class\n */\n pluginOf<Instance extends BasePlugin<any>>(klass: Class<Instance>): Instance | undefined {\n let result = this.plugins.find((plugin) => plugin instanceof klass);\n\n /**\n * This is an unsafe cast, because Instance could be unrelated to any of the types\n * that matches Plugin[]\n *\n * For example, `table.pluginOf(MyCustomPlugin)`, where MyCustomPlugin isn't in the\n * `plugins` list. This partially a problem with how Array.prototype.find doesn't\n * effectively narrow for what we want (combined with TS being clunky around\n * comparing Instance and Class types).\n */\n return result as unknown as Instance | undefined;\n }\n\n /**\n * @private\n *\n * used by other private APIs\n */\n get config() {\n return this.args.named;\n }\n\n rows = map(this, {\n data: () => {\n let dataFn = this.args.named?.data;\n\n if (!dataFn) return [];\n\n return dataFn() ?? [];\n },\n map: (datum) => new Row(this, datum),\n });\n\n columns = map(this, {\n data: () => {\n let configFn = this.args.named?.columns;\n\n if (!configFn) return [];\n\n return configFn() ?? [];\n },\n map: (config) => {\n return new Column<DataType>(this, { ...this.defaultColumnConfig, ...config });\n },\n });\n\n /**\n * @private\n */\n @action\n resetScrollContainer() {\n if (!this.scrollContainerElement) return;\n\n this.scrollContainerElement.scrollTop = 0;\n }\n\n @action\n resetToDefaults() {\n this.plugins.forEach((plugin) => plugin.reset?.());\n }\n}\n"],"names":["_initializerDefineProperty","target","property","descriptor","context","Object","defineProperty","enumerable","configurable","writable","value","initializer","call","DEFAULT_COLUMN_CONFIG","isVisible","minWidth","TABLE_KEY","Symbol","attachContainer","element","table","assert","HTMLElement","scrollContainerElement","Table","Resource","guidFor","container","modifier","modifiers","plugins","map","plugin","containerModifier","composed","composeFunctionModifiers","eager","columnHeader","column","headerCellModifier","row","rowModifier","data","dataFn","args","named","datum","Row","configFn","columns","config","Column","defaultColumnConfig","modify","_","preferences","key","adapter","TablePreferences","resetScrollContainer","normalizePluginsConfig","verifyPlugins","tuple","PluginClass","owner","getOwner","setOwner","pluginOf","klass","result","find","scrollTop","resetToDefaults","forEach","reset","tracked","cached","action"],"mappings":";;;;;;;;;;;;;;;;;AAAe,SAASA,0BAAT,CAAoCC,MAApC,EAA4CC,QAA5C,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A,EAAA,IAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,QAAA,EAAA,IAAA;AAAA,EAAA,WAAA,EAAA,IAAA;AAAA,CAAA,CAAA,EAAA,YAAA,GAAA,yBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,MAAA,EAAA,CAmBGA,OAnBH,CAAA,EAAA;AAAA,EAAA,YAAA,EAAA,IAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,QAAA,EAAA,IAAA;AAAA,EAAA,WAAA,EAAA,IAAA;AAAA,CAAA,CAAA,EAAA,yBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,SAAA,EAAA,CAkHGC,MAlHH,CAAA,EAAA,MAAA,CAAA,wBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,SAAA,CAAA,EAAA,MAAA,CAAA,SAAA,CAAA,EAAA,yBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,sBAAA,EAAA,CAmMGC,MAnMH,CAAA,EAAA,MAAA,CAAA,wBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,sBAAA,CAAA,EAAA,MAAA,CAAA,SAAA,CAAA,EAAA,yBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,iBAAA,EAAA,CA0MGA,MA1MH,CAAA,EAAA,MAAA,CAAA,wBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,iBAAA,CAAA,EAAA,MAAA,CAAA,SAAA,CAAA,GAAA,MAAA;;;;"}
@@ -0,0 +1,14 @@
1
+ interface Selectors {
2
+ resizeHandle?: string;
3
+ scrollContainer?: string;
4
+ }
5
+ declare function createHelpers(selectors: Selectors): {
6
+ dragLeft: (column: Element, amount: number) => Promise<void>;
7
+ dragRight: (column: Element, amount: number) => Promise<void>;
8
+ scrollLeft: (distance: number) => Promise<void>;
9
+ scrollRight: (distance: number) => Promise<void>;
10
+ swipeLeft: (distance: number) => Promise<void>;
11
+ swipeRight: (distance: number) => Promise<void>;
12
+ };
13
+ declare function requestAnimationFrameSettled(): Promise<void>;
14
+ export { createHelpers, requestAnimationFrameSettled };
@@ -0,0 +1,72 @@
1
+ import { assert } from '@ember/debug';
2
+ import { settled, triggerEvent, find } from '@ember/test-helpers';
3
+
4
+ function createHelpers(selectors) {
5
+ async function resize(parent, delta) {
6
+ assert(`Can't use the dragLeft/dragRight/resize helpers without a \`resizeHandle\` selector`, selectors.resizeHandle);
7
+ let element = parent.querySelector(selectors.resizeHandle);
8
+ assert(`Can't resize without a handle`, element);
9
+ /**
10
+ * Start the click in exactly the middle of the element.
11
+ * "startX" is the horizontal middle of "element"
12
+ */
13
+
14
+ let rect = element.getBoundingClientRect();
15
+ let startX = (rect.right + rect.left) / 2;
16
+ let targetX = startX + delta;
17
+ triggerEvent(element, 'mousedown', {
18
+ clientX: startX,
19
+ button: 0
20
+ });
21
+ triggerEvent(element, 'mousemove', {
22
+ clientX: targetX,
23
+ button: 0
24
+ });
25
+ triggerEvent(element, 'mouseup', {
26
+ clientX: targetX,
27
+ button: 0
28
+ });
29
+ await settled();
30
+ /**
31
+ * This has been super finnicky... :(
32
+ */
33
+
34
+ await new Promise(resolve => setTimeout(resolve, 100));
35
+ await requestAnimationFrameSettled();
36
+ }
37
+
38
+ function horizontalScrollElement() {
39
+ assert(`Can't use scrollRight/swipeLeft helpers without a \`scrollContainer\` selector`, selectors.scrollContainer);
40
+ let element = find(selectors.scrollContainer);
41
+ assert(`scroll container not found`, element instanceof HTMLElement);
42
+ return element;
43
+ }
44
+
45
+ async function scrollRight(distance) {
46
+ let element = horizontalScrollElement();
47
+ element.scrollLeft += distance;
48
+ await requestAnimationFrameSettled();
49
+ }
50
+
51
+ async function scrollLeft(distance) {
52
+ let element = horizontalScrollElement();
53
+ element.scrollLeft -= distance;
54
+ await requestAnimationFrameSettled();
55
+ }
56
+
57
+ return {
58
+ dragLeft: (column, amount) => resize(column, -amount),
59
+ dragRight: (column, amount) => resize(column, amount),
60
+ scrollLeft,
61
+ scrollRight,
62
+ swipeLeft: scrollRight,
63
+ swipeRight: scrollLeft
64
+ };
65
+ }
66
+ async function requestAnimationFrameSettled() {
67
+ await new Promise(requestAnimationFrame);
68
+ await settled();
69
+ }
70
+
71
+ export { createHelpers, requestAnimationFrameSettled };
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/test-support/index.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { find, settled, triggerEvent } from '@ember/test-helpers';\n\ninterface Selectors {\n resizeHandle?: string;\n scrollContainer?: string;\n}\n\nexport function createHelpers(selectors: Selectors) {\n async function resize(parent: Element, delta: number) {\n assert(\n `Can't use the dragLeft/dragRight/resize helpers without a \\`resizeHandle\\` selector`,\n selectors.resizeHandle\n );\n\n let element = parent.querySelector(selectors.resizeHandle);\n\n assert(`Can't resize without a handle`, element);\n\n /**\n * Start the click in exactly the middle of the element.\n * \"startX\" is the horizontal middle of \"element\"\n */\n let rect = element.getBoundingClientRect();\n let startX = (rect.right + rect.left) / 2;\n\n let targetX = startX + delta;\n\n triggerEvent(element, 'mousedown', { clientX: startX, button: 0 });\n triggerEvent(element, 'mousemove', { clientX: targetX, button: 0 });\n triggerEvent(element, 'mouseup', { clientX: targetX, button: 0 });\n\n await settled();\n\n /**\n * This has been super finnicky... :(\n */\n await new Promise((resolve) => setTimeout(resolve, 100));\n await requestAnimationFrameSettled();\n }\n\n function horizontalScrollElement() {\n assert(\n `Can't use scrollRight/swipeLeft helpers without a \\`scrollContainer\\` selector`,\n selectors.scrollContainer\n );\n\n let element = find(selectors.scrollContainer);\n\n assert(`scroll container not found`, element instanceof HTMLElement);\n\n return element;\n }\n\n async function scrollRight(distance: number) {\n let element = horizontalScrollElement();\n\n element.scrollLeft += distance;\n await requestAnimationFrameSettled();\n }\n\n async function scrollLeft(distance: number) {\n let element = horizontalScrollElement();\n\n element.scrollLeft -= distance;\n await requestAnimationFrameSettled();\n }\n\n return {\n dragLeft: (column: Element, amount: number) => resize(column, -amount),\n dragRight: (column: Element, amount: number) => resize(column, amount),\n scrollLeft,\n scrollRight,\n swipeLeft: scrollRight,\n swipeRight: scrollLeft,\n };\n}\n\nexport async function requestAnimationFrameSettled() {\n await new Promise(requestAnimationFrame);\n await settled();\n}\n"],"names":["createHelpers","selectors","resize","parent","delta","assert","resizeHandle","element","querySelector","rect","getBoundingClientRect","startX","right","left","targetX","triggerEvent","clientX","button","settled","Promise","resolve","setTimeout","requestAnimationFrameSettled","horizontalScrollElement","scrollContainer","find","HTMLElement","scrollRight","distance","scrollLeft","dragLeft","column","amount","dragRight","swipeLeft","swipeRight","requestAnimationFrame"],"mappings":";;;AAQO,SAASA,aAAT,CAAuBC,SAAvB,EAA6C;AAClD,EAAA,eAAeC,MAAf,CAAsBC,MAAtB,EAAuCC,KAAvC,EAAsD;AACpDC,IAAAA,MAAM,CACH,CADG,mFAAA,CAAA,EAEJJ,SAAS,CAACK,YAFN,CAAN,CAAA;IAKA,IAAIC,OAAO,GAAGJ,MAAM,CAACK,aAAP,CAAqBP,SAAS,CAACK,YAA/B,CAAd,CAAA;AAEAD,IAAAA,MAAM,CAAE,CAAA,6BAAA,CAAF,EAAkCE,OAAlC,CAAN,CAAA;AAEA;AACJ;AACA;AACA;;AACI,IAAA,IAAIE,IAAI,GAAGF,OAAO,CAACG,qBAAR,EAAX,CAAA;IACA,IAAIC,MAAM,GAAG,CAACF,IAAI,CAACG,KAAL,GAAaH,IAAI,CAACI,IAAnB,IAA2B,CAAxC,CAAA;AAEA,IAAA,IAAIC,OAAO,GAAGH,MAAM,GAAGP,KAAvB,CAAA;AAEAW,IAAAA,YAAY,CAACR,OAAD,EAAU,WAAV,EAAuB;AAAES,MAAAA,OAAO,EAAEL,MAAX;AAAmBM,MAAAA,MAAM,EAAE,CAAA;AAA3B,KAAvB,CAAZ,CAAA;AACAF,IAAAA,YAAY,CAACR,OAAD,EAAU,WAAV,EAAuB;AAAES,MAAAA,OAAO,EAAEF,OAAX;AAAoBG,MAAAA,MAAM,EAAE,CAAA;A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AD,EAAkBC,MAAlB,KAAqC9B,MAAM,CAAC6B,MAAD,EAASC,MAAT,CAFjD;IAGLH,UAHK;IAILF,WAJK;AAKLO,IAAAA,SAAS,EAAEP,WALN;AAMLQ,IAAAA,UAAU,EAAEN,UAAAA;GANd,CAAA;AAQD,CAAA;AAEM,eAAeP,4BAAf,GAA8C;AACnD,EAAA,MAAM,IAAIH,OAAJ,CAAYiB,qBAAZ,CAAN,CAAA;AACA,EAAA,MAAMlB,OAAO,EAAb,CAAA;AACD;;;;"}
@@ -0,0 +1,26 @@
1
+ import { Sort, SortsOptions } from "./plugins/data-sorting/types";
2
+ /**
3
+ * @example
4
+ *
5
+ * ```ts
6
+ * deserializeSorts('first_name.asc', { separator: '.', transform: 'camelize' });
7
+ * // => [{ property: 'firstName', direction: 'ascending' }]
8
+ *
9
+ * deserializeSorts('last_name.desc', { separator: '.', transform: 'camelize' });
10
+ * // => [{ property: 'lastName', direction: 'descending' }]
11
+ * ```
12
+ */
13
+ declare const deserializeSorts: (sortString: string, options?: SortsOptions) => Sort[];
14
+ /**
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * serializeSorts([{ property: 'firstName', direction: 'ascending' }],{ separator: '.', transform: 'camelize' });
19
+ * // => 'first_name.asc'
20
+ *
21
+ * serializeSorts([{ property: 'lastName', direction: 'descending' }],{ separator: '.', transform: 'camelize' });
22
+ * // => 'last_name.desc'
23
+ * ```
24
+ */
25
+ declare function serializeSorts(sorts: Sort[], options?: SortsOptions): string;
26
+ export { deserializeSorts, serializeSorts };
package/dist/utils.js ADDED
@@ -0,0 +1,77 @@
1
+ import { assert } from '@ember/debug';
2
+ import { camelize, underscore } from '@ember/string';
3
+ import { SortDirection } from './plugins/data-sorting/types.js';
4
+
5
+ /**
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * deserializeSorts('first_name.asc', { separator: '.', transform: 'camelize' });
10
+ * // => [{ property: 'firstName', direction: 'ascending' }]
11
+ *
12
+ * deserializeSorts('last_name.desc', { separator: '.', transform: 'camelize' });
13
+ * // => [{ property: 'lastName', direction: 'descending' }]
14
+ * ```
15
+ */
16
+ const deserializeSorts = (sortString, options = {
17
+ separator: '.',
18
+ transform: 'camelize'
19
+ }) => {
20
+ const {
21
+ transform,
22
+ separator
23
+ } = options;
24
+ let [key, direction] = sortString.split(separator);
25
+ assert(`No key found for input: \`${sortString}\` using \`${separator}\` as a separator`, key);
26
+
27
+ if (transform === 'camelize') {
28
+ key = camelize(key);
29
+ } else if (transform === 'underscore') {
30
+ key = underscore(key);
31
+ }
32
+
33
+ return [{
34
+ property: key,
35
+ direction: direction === 'asc' ? SortDirection.Ascending : SortDirection.Descending
36
+ }];
37
+ };
38
+ /**
39
+ * @example
40
+ *
41
+ * ```ts
42
+ * serializeSorts([{ property: 'firstName', direction: 'ascending' }],{ separator: '.', transform: 'camelize' });
43
+ * // => 'first_name.asc'
44
+ *
45
+ * serializeSorts([{ property: 'lastName', direction: 'descending' }],{ separator: '.', transform: 'camelize' });
46
+ * // => 'last_name.desc'
47
+ * ```
48
+ */
49
+
50
+ function serializeSorts(sorts, options = {
51
+ separator: '.',
52
+ transform: 'underscore'
53
+ }) {
54
+ const {
55
+ transform,
56
+ separator
57
+ } = options;
58
+ let sortParameters = sorts.map(({
59
+ direction,
60
+ property
61
+ }) => {
62
+ let shortDirection = direction === 'ascending' ? 'asc' : 'desc';
63
+ let sortField = property;
64
+
65
+ if (transform === 'underscore') {
66
+ sortField = underscore(property);
67
+ } else if (transform === 'camelize') {
68
+ sortField = camelize(property);
69
+ }
70
+
71
+ return `${sortField}${separator}${shortDirection}`;
72
+ });
73
+ return sortParameters.join('+');
74
+ }
75
+
76
+ export { deserializeSorts, serializeSorts };
77
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { camelize, underscore } from '@ember/string';\n\nimport { SortDirection } from './plugins/data-sorting/types';\n\nimport type { Sort, SortsOptions } from './plugins/data-sorting/types';\n\n/**\n * @example\n *\n * ```ts\n * deserializeSorts('first_name.asc', { separator: '.', transform: 'camelize' });\n * // => [{ property: 'firstName', direction: 'ascending' }]\n *\n * deserializeSorts('last_name.desc', { separator: '.', transform: 'camelize' });\n * // => [{ property: 'lastName', direction: 'descending' }]\n * ```\n */\n\nexport const deserializeSorts = (\n sortString: string,\n options: SortsOptions = { separator: '.', transform: 'camelize' }\n): Sort[] => {\n const { transform, separator } = options;\n let [key, direction] = sortString.split(separator);\n\n assert(`No key found for input: \\`${sortString}\\` using \\`${separator}\\` as a separator`, key);\n\n if (transform === 'camelize') {\n key = camelize(key);\n } else if (transform === 'underscore') {\n key = underscore(key);\n }\n\n return [\n {\n property: key,\n direction: direction === 'asc' ? SortDirection.Ascending : SortDirection.Descending,\n },\n ];\n};\n\n/**\n * @example\n *\n * ```ts\n * serializeSorts([{ property: 'firstName', direction: 'ascending' }],{ separator: '.', transform: 'camelize' });\n * // => 'first_name.asc'\n *\n * serializeSorts([{ property: 'lastName', direction: 'descending' }],{ separator: '.', transform: 'camelize' });\n * // => 'last_name.desc'\n * ```\n */\nexport function serializeSorts(\n sorts: Sort[],\n options: SortsOptions = { separator: '.', transform: 'underscore' }\n): string {\n const { transform, separator } = options;\n\n let sortParameters = sorts.map(({ direction, property }) => {\n let shortDirection = direction === 'ascending' ? 'asc' : 'desc';\n\n let sortField = property;\n\n if (transform === 'underscore') {\n sortField = underscore(property);\n } else if (transform === 'camelize') {\n sortField = camelize(property);\n }\n\n return `${sortField}${separator}${shortDirection}`;\n });\n\n return sortParameters.join('+');\n}\n"],"names":["deserializeSorts","sortString","options","separator","transform","key","direction","split","assert","camelize","underscore","property","SortDirection","Ascending","Descending","serializeSorts","sorts","sortParameters","map","shortDirection","sortField","join"],"mappings":";;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MAEaA,gBAAgB,GAAG,CAC9BC,UAD8B,EAE9BC,OAAqB,G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