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,62 @@
1
+ import { BasePlugin } from "../-private/base";
2
+ import { Plugin, PluginPreferences } from "../index";
3
+ import { Column, Table } from "../../index";
4
+ interface ColumnVisibilityPreferences extends PluginPreferences {
5
+ columns: {
6
+ [columnKey: string]: {
7
+ isVisible?: boolean;
8
+ };
9
+ };
10
+ }
11
+ declare module "plugins/index" {
12
+ interface Registry {
13
+ ColumnVisibility?: ColumnVisibilityPreferences;
14
+ }
15
+ }
16
+ interface Signature {
17
+ Meta: {
18
+ Table: TableMeta;
19
+ Column: ColumnMeta;
20
+ };
21
+ Options: {
22
+ Plugin: {
23
+ enabled?: boolean;
24
+ };
25
+ Column: {
26
+ /**
27
+ * The default visibilty of the column, when rendered.
28
+ * The column can still be toggled on and off.
29
+ *
30
+ * When interacting with preferences, the value stored in preferenced
31
+ * will be the inverse of this value (to save space in storage).
32
+ */
33
+ isVisible?: boolean;
34
+ };
35
+ };
36
+ }
37
+ declare class ColumnVisibility extends BasePlugin<Signature> implements Plugin<Signature> {
38
+ name: string;
39
+ static features: string[];
40
+ meta: {
41
+ column: typeof ColumnMeta;
42
+ table: typeof TableMeta;
43
+ };
44
+ reset(): void;
45
+ get columns(): Column<unknown>[];
46
+ }
47
+ declare class ColumnMeta<Data = unknown> {
48
+ private column;
49
+ constructor(column: Column<Data>);
50
+ get isVisible(): boolean;
51
+ get isHidden(): boolean;
52
+ hide: () => void;
53
+ show: () => void;
54
+ toggle: () => void;
55
+ }
56
+ declare class TableMeta<Data = unknown> {
57
+ private table;
58
+ constructor(table: Table<Data>);
59
+ get visibleColumns(): Column<Data>[];
60
+ toggleColumnVisibility(column: Column<Data>): void;
61
+ }
62
+ export { Signature, ColumnVisibility, ColumnMeta, TableMeta };
@@ -0,0 +1,124 @@
1
+ import { _ as _applyDecoratedDescriptor } from '../../applyDecoratedDescriptor-e0489e2f.js';
2
+ import { _ as _defineProperty } from '../../defineProperty-a0196711.js';
3
+ import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';
4
+ import '@glimmer/tracking';
5
+ import { action } from '@ember/object';
6
+ import { BasePlugin, options, meta, preferences } from '../-private/base.js';
7
+
8
+ var _class;
9
+ let cached = macroCondition(dependencySatisfies('ember-source', '>= 4.1.0-alpha.0')) ? importSync('@glimmer/tracking').cached : importSync('ember-cached-decorator-polyfill').cached;
10
+ class ColumnVisibility extends BasePlugin {
11
+ constructor(...args) {
12
+ super(...args);
13
+
14
+ _defineProperty(this, "name", 'column-visibility');
15
+
16
+ _defineProperty(this, "meta", {
17
+ column: ColumnMeta,
18
+ table: TableMeta
19
+ });
20
+ }
21
+
22
+ reset() {
23
+ /**
24
+ * Global preference, not scoped to plugin
25
+ */
26
+ for (let column of this.table.columns) {
27
+ let defaultValue = options.forColumn(column, ColumnVisibility)?.isVisible;
28
+ let current = meta.forColumn(column, ColumnVisibility).isVisible;
29
+
30
+ if (defaultValue !== current) {
31
+ preferences.forColumn(column, ColumnVisibility).delete('isVisible');
32
+ }
33
+ }
34
+ }
35
+
36
+ get columns() {
37
+ return meta.forTable(this.table, ColumnVisibility).visibleColumns;
38
+ }
39
+
40
+ }
41
+
42
+ _defineProperty(ColumnVisibility, "features", ['columnVisibility']);
43
+
44
+ class ColumnMeta {
45
+ constructor(column) {
46
+ _defineProperty(this, "hide", () => {
47
+ if (!this.isVisible) return;
48
+ let myPreferences = preferences.forColumn(this.column, ColumnVisibility);
49
+ let myOptions = options.forColumn(this.column, ColumnVisibility);
50
+ let currentSaved = myPreferences.get('isVisible');
51
+ let willBeDefault = Boolean(currentSaved) === !myOptions?.isVisible;
52
+
53
+ if (willBeDefault) {
54
+ myPreferences.set('isVisible', false); // TODO: open an issue about tracked-built-ins' delete not being reactive
55
+ // myPreferences.delete('isVisible');
56
+
57
+ return;
58
+ }
59
+
60
+ myPreferences.set('isVisible', false);
61
+ });
62
+
63
+ _defineProperty(this, "show", () => {
64
+ if (this.isVisible) return;
65
+ let myPreferences = preferences.forColumn(this.column, ColumnVisibility);
66
+ let myOptions = options.forColumn(this.column, ColumnVisibility);
67
+ let currentSaved = myPreferences.get('isVisible');
68
+ let willBeDefault = currentSaved === !myOptions?.isVisible;
69
+
70
+ if (willBeDefault) {
71
+ myPreferences.set('isVisible', true); // TODO: open an issue about tracked-built-ins' delete not being reactive
72
+ // myPreferences.delete('isVisible');
73
+
74
+ return;
75
+ }
76
+
77
+ myPreferences.set('isVisible', true);
78
+ });
79
+
80
+ _defineProperty(this, "toggle", () => {
81
+ if (this.isVisible) {
82
+ this.hide();
83
+ return;
84
+ }
85
+
86
+ this.show();
87
+ });
88
+
89
+ this.column = column;
90
+ }
91
+
92
+ get isVisible() {
93
+ let columnPreferences = preferences.forColumn(this.column, ColumnVisibility);
94
+ let columnOptions = options.forColumn(this.column, ColumnVisibility);
95
+ return Boolean(columnPreferences.get('isVisible') ?? columnOptions?.isVisible ?? true);
96
+ }
97
+
98
+ get isHidden() {
99
+ return !this.isVisible;
100
+ }
101
+
102
+ }
103
+ let TableMeta = (_class = class TableMeta {
104
+ constructor(table) {
105
+ this.table = table;
106
+ }
107
+
108
+ get visibleColumns() {
109
+ let allColumns = this.table.columns.values();
110
+ return allColumns.filter(column => {
111
+ let columnMeta = meta.forColumn(column, ColumnVisibility);
112
+ return columnMeta.isVisible;
113
+ });
114
+ }
115
+
116
+ toggleColumnVisibility(column) {
117
+ let columnMeta = meta.forColumn(column, ColumnVisibility);
118
+ columnMeta.toggle();
119
+ }
120
+
121
+ }, (_applyDecoratedDescriptor(_class.prototype, "visibleColumns", [cached], Object.getOwnPropertyDescriptor(_class.prototype, "visibleColumns"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "toggleColumnVisibility", [action], Object.getOwnPropertyDescriptor(_class.prototype, "toggleColumnVisibility"), _class.prototype)), _class);
122
+
123
+ export { ColumnMeta, ColumnVisibility, TableMeta };
124
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/plugins/column-visibility/plugin.ts"],"sourcesContent":["import { cached } from '@glimmer/tracking';\nimport { action } from '@ember/object';\n\nimport { BasePlugin, meta, options, preferences } from '../-private/base';\n\nimport type { Plugin, PluginPreferences } from '[public-plugin-types]';\nimport type { Column, Table } from '[public-types]';\n\ninterface ColumnVisibilityPreferences extends PluginPreferences {\n columns: {\n [columnKey: string]: {\n isVisible?: boolean;\n };\n };\n}\n\ndeclare module 'ember-headless-table/plugins' {\n interface Registry {\n ColumnVisibility?: ColumnVisibilityPreferences;\n }\n}\n\nexport interface Signature {\n Meta: {\n Table: TableMeta;\n Column: ColumnMeta;\n };\n Options: {\n Plugin: {\n enabled?: boolean;\n };\n Column: {\n /**\n * The default visibilty of the column, when rendered.\n * The column can still be toggled on and off.\n *\n * When interacting with preferences, the value stored in preferenced\n * will be the inverse of this value (to save space in storage).\n */\n isVisible?: boolean;\n };\n };\n}\n\nexport class ColumnVisibility extends BasePlugin<Signature> implements Plugin<Signature> {\n name = 'column-visibility';\n static features = ['columnVisibility'];\n\n meta = {\n column: ColumnMeta,\n table: TableMeta,\n };\n\n reset() {\n /**\n * Global preference, not scoped to plugin\n */\n for (let column of this.table.columns) {\n let defaultValue = options.forColumn(column, ColumnVisibility)?.isVisible;\n let current = meta.forColumn(column, ColumnVisibility).isVisible;\n\n if (defaultValue !== current) {\n preferences.forColumn(column, ColumnVisibility).delete('isVisible');\n }\n }\n }\n\n get columns() {\n return meta.forTable(this.table, ColumnVisibility).visibleColumns;\n }\n}\n\nexport class ColumnMeta<Data = unknown> {\n constructor(private column: Column<Data>) {}\n\n get isVisible(): boolean {\n let columnPreferences = preferences.forColumn(this.column, ColumnVisibility);\n let columnOptions = options.forColumn(this.column, ColumnVisibility);\n\n return Boolean(columnPreferences.get('isVisible') ?? columnOptions?.isVisible ?? true);\n }\n\n get isHidden(): boolean {\n return !this.isVisible;\n }\n\n hide = () => {\n if (!this.isVisible) return;\n\n let myPreferences = preferences.forColumn(this.column, ColumnVisibility);\n let myOptions = options.forColumn(this.column, ColumnVisibility);\n let currentSaved = myPreferences.get('isVisible');\n let willBeDefault = Boolean(currentSaved) === !myOptions?.isVisible;\n\n if (willBeDefault) {\n myPreferences.set('isVisible', false);\n // TODO: open an issue about tracked-built-ins' delete not being reactive\n // myPreferences.delete('isVisible');\n\n return;\n }\n\n myPreferences.set('isVisible', false);\n };\n\n show = () => {\n if (this.isVisible) return;\n\n let myPreferences = preferences.forColumn(this.column, ColumnVisibility);\n let myOptions = options.forColumn(this.column, ColumnVisibility);\n let currentSaved = myPreferences.get('isVisible');\n let willBeDefault = currentSaved === !myOptions?.isVisible;\n\n if (willBeDefault) {\n myPreferences.set('isVisible', true);\n // TODO: open an issue about tracked-built-ins' delete not being reactive\n // myPreferences.delete('isVisible');\n\n return;\n }\n\n myPreferences.set('isVisible', true);\n };\n\n toggle = () => {\n if (this.isVisible) {\n this.hide();\n\n return;\n }\n\n this.show();\n };\n}\n\nexport class TableMeta<Data = unknown> {\n constructor(private table: Table<Data>) {}\n\n @cached\n get visibleColumns(): Column<Data>[] {\n let allColumns = this.table.columns.values();\n\n return allColumns.filter((column) => {\n let columnMeta = meta.forColumn(column, ColumnVisibility);\n\n return columnMeta.isVisible;\n });\n }\n\n @action\n toggleColumnVisibility(column: Column<Data>) {\n let columnMeta = meta.forColumn(column, ColumnVisibility);\n\n columnMeta.toggle();\n }\n}\n"],"names":["ColumnVisibility","BasePlugin","column","ColumnMeta","table","TableMeta","reset","columns","defaultValue","options","forColumn","isVisible","current","meta","preferences","delete","forTable","visibleColumns","constructor","myPreferences","myOptions","currentSaved","get","willBeDefault","Boolean","set","hide","show","columnPreferences","columnOptions","isHidden","allColumns","values","filter","columnMeta","toggleColumnVisibility","toggle","cached","action"],"mappings":";;;;;;;;;AA4CO,MAAMA,gBAAN,SAA+BC,UAA/B,CAAkF;AAAA,EAAA,WAAA,CAAA,GAAA,IAAA,EAAA;AAAA,IAAA,KAAA,CAAA,GAAA,IAAA,CAAA,CAAA;;AAAA,IAAA,eAAA,CAAA,IAAA,EAAA,MAAA,EAChF,mBADgF,CAAA,CAAA;;IAAA,eAIhF,CAAA,IAAA,EAAA,MAAA,EAAA;AACLC,MAAAA,MAAM,EAAEC,UADH;AAELC,MAAAA,KAAK,EAAEC,SAAAA;KAN8E,CAAA,CAAA;AAAA,GAAA;;AASvFC,EAAAA,KAAK,GAAG;AACN;AACJ;AACA;AACI,IAAA,KAAK,IAAIJ,MAAT,IAAmB,KAAKE,KAAL,CAAWG,OAA9B,EAAuC;MACrC,IAAIC,YAAY,GAAGC,OAAO,C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CAAA,MAAA,CAAA,SAAA,EAAA,wBAAA,EAAA,CAcGC,MAdH,CAAA,EAAA,MAAA,CAAA,wBAAA,CAAA,MAAA,CAAA,SAAA,EAAA,wBAAA,CAAA,EAAA,MAAA,CAAA,SAAA,CAAA,GAAA,MAAA;;;;"}
@@ -0,0 +1,38 @@
1
+ import { Column } from "../../index";
2
+ /**
3
+ * Query a specific column's current sort direction
4
+ */
5
+ declare const sortDirection: (column: Column) => import("./index").SortDirection;
6
+ /**
7
+ * Ask if a column is sortable
8
+ */
9
+ declare const isSortable: (column: Column) => boolean;
10
+ /**
11
+ * Ask if a column is ascending
12
+ */
13
+ declare const isAscending: (column: Column) => boolean;
14
+ /**
15
+ * Ask if a column is sorted descending
16
+ */
17
+ declare const isDescending: (column: Column) => boolean;
18
+ /**
19
+ * Ask if a column is not sorted
20
+ */
21
+ declare const isUnsorted: (column: Column) => boolean;
22
+ /**
23
+ * Sort the specified column's data using a tri-toggle.
24
+ *
25
+ * States go in this order:
26
+ * Ascending => None => Descending
27
+ * ⬑ ---------- <= ---------- ↲
28
+ */
29
+ declare const sort: (column: Column) => void;
30
+ /**
31
+ * Toggle a column between descending and not unsorted states
32
+ */
33
+ declare const sortDescending: (column: Column) => void;
34
+ /**
35
+ * Toggle a column between ascending and not unsorted states
36
+ */
37
+ declare const sortAscending: (column: Column) => void;
38
+ export { sortDirection, isSortable, isAscending, isDescending, isUnsorted, sort, sortDescending, sortAscending };
@@ -0,0 +1,49 @@
1
+ import { meta } from '../-private/base.js';
2
+ import { Sorting } from './plugin.js';
3
+
4
+ /**
5
+ * Query a specific column's current sort direction
6
+ */
7
+ const sortDirection = column => meta.forColumn(column, Sorting).sortDirection;
8
+ /**
9
+ * Ask if a column is sortable
10
+ */
11
+
12
+ const isSortable = column => meta.forColumn(column, Sorting).isSortable;
13
+ /**
14
+ * Ask if a column is ascending
15
+ */
16
+
17
+ const isAscending = column => meta.forColumn(column, Sorting).isAscending;
18
+ /**
19
+ * Ask if a column is sorted descending
20
+ */
21
+
22
+ const isDescending = column => meta.forColumn(column, Sorting).isDescending;
23
+ /**
24
+ * Ask if a column is not sorted
25
+ */
26
+
27
+ const isUnsorted = column => meta.forColumn(column, Sorting).isUnsorted;
28
+ /**
29
+ * Sort the specified column's data using a tri-toggle.
30
+ *
31
+ * States go in this order:
32
+ * Ascending => None => Descending
33
+ * ⬑ ---------- <= ---------- ↲
34
+ */
35
+
36
+ const sort = column => meta.forTable(column.table, Sorting).handleSort(column);
37
+ /**
38
+ * Toggle a column between descending and not unsorted states
39
+ */
40
+
41
+ const sortDescending = column => meta.forTable(column.table, Sorting).toggleDescending(column);
42
+ /**
43
+ * Toggle a column between ascending and not unsorted states
44
+ */
45
+
46
+ const sortAscending = column => meta.forTable(column.table, Sorting).toggleAscending(column);
47
+
48
+ export { isAscending, isDescending, isSortable, isUnsorted, sort, sortAscending, sortDescending, sortDirection };
49
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sources":["../../../src/plugins/data-sorting/helpers.ts"],"sourcesContent":["import { meta } from '../-private/base';\nimport { Sorting } from './plugin';\n\nimport type { Column } from '[public-types]';\n\n/**\n * Query a specific column's current sort direction\n */\nexport const sortDirection = (column: Column) => meta.forColumn(column, Sorting).sortDirection;\n\n/**\n * Ask if a column is sortable\n */\nexport const isSortable = (column: Column) => meta.forColumn(column, Sorting).isSortable;\n\n/**\n * Ask if a column is ascending\n */\nexport const isAscending = (column: Column) => meta.forColumn(column, Sorting).isAscending;\n\n/**\n * Ask if a column is sorted descending\n */\nexport const isDescending = (column: Column) => meta.forColumn(column, Sorting).isDescending;\n\n/**\n * Ask if a column is not sorted\n */\nexport const isUnsorted = (column: Column) => meta.forColumn(column, Sorting).isUnsorted;\n\n/**\n * Sort the specified column's data using a tri-toggle.\n *\n * States go in this order:\n * Ascending => None => Descending\n * ⬑ ---------- <= ---------- ↲\n */\nexport const sort = (column: Column) => meta.forTable(column.table, Sorting).handleSort(column);\n\n/**\n * Toggle a column between descending and not unsorted states\n */\nexport const sortDescending = (column: Column) =>\n meta.forTable(column.table, Sorting).toggleDescending(column);\n\n/**\n * Toggle a column between ascending and not unsorted states\n */\nexport const sortAscending = (column: Column) =>\n meta.forTable(column.table, Sorting).toggleAscending(column);\n"],"names":["sortDirection","column","meta","forColumn","Sorting","isSortable","isAscending","isDescending","isUnsorted","sort","forTable","table","handleSort","sortDescending","toggleDescending","sortAscending","toggleAscending"],"mappings":";;;AAKA;AACA;AACA;AACaA,MAAAA,aAAa,GAAIC,MAAD,IAAoBC,IAAI,CAACC,SAAL,CAAeF,MAAf,EAAuBG,OAAvB,EAAgCJ,cAA1E;AAEP;AACA;AACA;;AACaK,MAAAA,UAAU,GAAIJ,MAAD,IAAoBC,IAAI,CAACC,SAAL,CAAeF,MAAf,EAAuBG,OAAvB,EAAgCC,WAAvE;AAEP;AACA;AACA;;AACaC,MAAAA,WAAW,GAAIL,MAAD,IAAoBC,IAAI,CAACC,SAAL,CAAeF,MAAf,EAAuBG,OAAvB,EAAgCE,YAAxE;AAEP;AACA;AACA;;AACaC,MAAAA,YAAY,GAAIN,MAAD,IAAoBC,IAAI,CAACC,SAAL,CAAeF,MAAf,EAAuBG,OAAvB,EAAgCG,aAAzE;AAEP;AACA;AACA;;AACaC,MAAAA,UAAU,GAAIP,MAAD,IAAoBC,IAAI,CAACC,SAAL,CAAeF,MAAf,EAAuBG,OAAvB,EAAgCI,WAAvE;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;MACaC,IAAI,GAAIR,MAAD,IAAoBC,IAAI,CAACQ,QAAL,CAAcT,MAAM,CAACU,KAArB,EAA4BP,OAA5B,EAAqCQ,UAArC,CAAgDX,MAAhD,EAAjC;AAEP;AACA;AACA;;MACaY,cAAc,GAAIZ,MAAD,IAC5BC,IAAI,CAACQ,QAAL,CAAcT,MAAM,CAACU,KAArB,EAA4BP,OAA5B,EAAqCU,gBAArC,CAAsDb,MAAtD,EADK;AAGP;AACA;AACA;;MACac,aAAa,GAAId,MAAD,IAC3BC,IAAI,CAACQ,QAAL,CAAcT,MAAM,CAACU,KAArB,EAA4BP,OAA5B,EAAqCY,eAArC,CAAqDf,MAArD;;;;"}
@@ -0,0 +1,5 @@
1
+ export * from "./helpers";
2
+ export { Sorting as Plugin, Sorting as DataSorting } from "./plugin";
3
+ export { SortDirection } from "./types";
4
+ export type { Signature } from "./plugin";
5
+ export type { Sort, SortItem } from "./types";
@@ -0,0 +1,4 @@
1
+ export { isAscending, isDescending, isSortable, isUnsorted, sort, sortAscending, sortDescending, sortDirection } from './helpers.js';
2
+ export { Sorting as DataSorting, Sorting as Plugin } from './plugin.js';
3
+ export { SortDirection } from './types.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,99 @@
1
+ import { BasePlugin } from "../-private/base";
2
+ import { SortDirection, Sort, SortItem } from "./types";
3
+ import { ColumnApi, PluginPreferences } from "../index";
4
+ import { Column, Table } from "../../index";
5
+ interface SortingPreferences extends PluginPreferences {
6
+ table: {
7
+ sorts?: Sort[];
8
+ };
9
+ }
10
+ declare module "plugins/index" {
11
+ interface Registry {
12
+ Sorting?: SortingPreferences;
13
+ }
14
+ }
15
+ interface Signature<DataType = unknown> {
16
+ Meta: {
17
+ Column: ColumnMeta;
18
+ Table: TableMeta;
19
+ };
20
+ Options: {
21
+ Plugin: Options<DataType>;
22
+ Column: ColumnOptions;
23
+ };
24
+ }
25
+ interface Options<DataType = unknown> {
26
+ /**
27
+ * Handler for interpreting sort requests from the headless table.
28
+ *
29
+ * Does not actually do the sorting.
30
+ *
31
+ * if omitted, the DataSorting plugin will disable itself
32
+ */
33
+ onSort?: (sorts: SortItem<DataType>[]) => void;
34
+ /**
35
+ * Provided sorts that the table should assume are true.
36
+ *
37
+ * if omitted, the DataSorting plugin will disable itself
38
+ */
39
+ sorts?: SortItem<DataType>[];
40
+ }
41
+ interface ColumnOptions {
42
+ /**
43
+ * Opt in or out of sorting for a particular column.
44
+ * Default is true.
45
+ */
46
+ isSortable?: boolean;
47
+ /**
48
+ * Use this key instead of the `key` on the column config.
49
+ * This has no bearing on any behavior in the plugin, *other than*,
50
+ * swapping out the `property`'s value on the `SortItem`s passed to
51
+ * the table plugin config's `onSort` callback
52
+ */
53
+ sortProperty?: string;
54
+ }
55
+ /**
56
+ * Manages basic data-sorting behaviors. Ascending -> Descending -> None
57
+ *
58
+ * This plugin requires a table plugin configuration, `onSort` for handling *how* sorting happens.
59
+ * communicating back to the table that sorting has succeeded can be done by setting the `sorts`
60
+ * property in the table plugin configuration.
61
+ *
62
+ * Note that this plugin doesn't actually sort the data, as data management is not the responsibility
63
+ * of the table, but of the surrounding context providing the data to the table. So sorting can happen
64
+ * client-side still, just in a component -- much the same way you'd handel sorting via API requests.
65
+ *
66
+ * This plugin is for *conveying* what the current sorts are, rather than _doing_ the sorting.
67
+ */
68
+ declare class Sorting<DataType = unknown> extends BasePlugin<Signature<DataType>> {
69
+ name: string;
70
+ meta: {
71
+ column: typeof ColumnMeta;
72
+ table: typeof TableMeta;
73
+ };
74
+ headerCellModifier: (element: HTMLElement, { column }: ColumnApi) => void;
75
+ }
76
+ declare class ColumnMeta {
77
+ private column;
78
+ constructor(column: Column);
79
+ get options(): Partial<ColumnOptions>;
80
+ get isSortable(): boolean;
81
+ get tableMeta(): TableMeta;
82
+ get sortDirection(): SortDirection;
83
+ get isAscending(): boolean;
84
+ get isDescending(): boolean;
85
+ get isUnsorted(): boolean;
86
+ get sortProperty(): string;
87
+ }
88
+ declare class TableMeta {
89
+ private table;
90
+ constructor(table: Table);
91
+ get options(): Partial<Options<unknown>>;
92
+ get sorts(): SortItem<unknown>[];
93
+ get isSortable(): boolean;
94
+ get onSort(): ((sorts: SortItem<unknown>[]) => void) | undefined;
95
+ handleSort(column: Column): void;
96
+ toggleAscending(column: Column): void;
97
+ toggleDescending(column: Column): void;
98
+ }
99
+ export { Signature, Sorting, ColumnMeta, TableMeta };
@@ -0,0 +1,165 @@
1
+ import { _ as _applyDecoratedDescriptor } from '../../applyDecoratedDescriptor-e0489e2f.js';
2
+ import { _ as _defineProperty } from '../../defineProperty-a0196711.js';
3
+ import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';
4
+ import '@glimmer/tracking';
5
+ import { action } from '@ember/object';
6
+ import { BasePlugin, meta, options } from '../-private/base.js';
7
+ import { SortDirection } from './types.js';
8
+
9
+ var _class, _class2;
10
+ let cached = macroCondition(dependencySatisfies('ember-source', '>= 4.1.0-alpha.0')) ? importSync('@glimmer/tracking').cached : importSync('ember-cached-decorator-polyfill').cached;
11
+
12
+ /**
13
+ * Manages basic data-sorting behaviors. Ascending -> Descending -> None
14
+ *
15
+ * This plugin requires a table plugin configuration, `onSort` for handling *how* sorting happens.
16
+ * communicating back to the table that sorting has succeeded can be done by setting the `sorts`
17
+ * property in the table plugin configuration.
18
+ *
19
+ * Note that this plugin doesn't actually sort the data, as data management is not the responsibility
20
+ * of the table, but of the surrounding context providing the data to the table. So sorting can happen
21
+ * client-side still, just in a component -- much the same way you'd handel sorting via API requests.
22
+ *
23
+ * This plugin is for *conveying* what the current sorts are, rather than _doing_ the sorting.
24
+ */
25
+ class Sorting extends BasePlugin {
26
+ constructor(...args) {
27
+ super(...args);
28
+
29
+ _defineProperty(this, "name", 'data-sorting');
30
+
31
+ _defineProperty(this, "meta", {
32
+ column: ColumnMeta,
33
+ table: TableMeta
34
+ });
35
+
36
+ _defineProperty(this, "headerCellModifier", (element, {
37
+ column
38
+ }) => {
39
+ let columnMeta = meta.forColumn(column, Sorting);
40
+ element.setAttribute('data-test-is-sortable', `${columnMeta.isSortable}`);
41
+ element.setAttribute('aria-sort', `${columnMeta.sortDirection}`);
42
+ });
43
+ }
44
+
45
+ }
46
+ let ColumnMeta = (_class = class ColumnMeta {
47
+ constructor(column) {
48
+ this.column = column;
49
+ }
50
+
51
+ get options() {
52
+ return options.forColumn(this.column, Sorting);
53
+ }
54
+
55
+ get isSortable() {
56
+ return this.options?.isSortable ?? this.tableMeta.isSortable;
57
+ }
58
+
59
+ get tableMeta() {
60
+ return meta.forTable(this.column.table, Sorting);
61
+ }
62
+
63
+ get sortDirection() {
64
+ let sort = this.tableMeta.sorts.find(sort => sort.property === this.sortProperty);
65
+ return sort?.direction ?? SortDirection.None;
66
+ }
67
+
68
+ get isAscending() {
69
+ return this.sortDirection === SortDirection.Ascending;
70
+ }
71
+
72
+ get isDescending() {
73
+ return this.sortDirection === SortDirection.Descending;
74
+ }
75
+
76
+ get isUnsorted() {
77
+ return this.sortDirection === SortDirection.None;
78
+ }
79
+
80
+ get sortProperty() {
81
+ return this.options?.sortProperty ?? this.column.config.key;
82
+ }
83
+
84
+ }, (_applyDecoratedDescriptor(_class.prototype, "options", [cached], Object.getOwnPropertyDescriptor(_class.prototype, "options"), _class.prototype)), _class);
85
+ let TableMeta = (_class2 = class TableMeta {
86
+ constructor(table) {
87
+ this.table = table;
88
+ }
89
+
90
+ get options() {
91
+ return options.forTable(this.table, Sorting);
92
+ }
93
+
94
+ get sorts() {
95
+ return this.options?.sorts ?? [];
96
+ }
97
+
98
+ get isSortable() {
99
+ return Boolean(this.options?.onSort) && Boolean(this.options?.sorts);
100
+ }
101
+
102
+ get onSort() {
103
+ return this.options?.onSort;
104
+ }
105
+
106
+ handleSort(column) {
107
+ let columnMeta = meta.forColumn(column, Sorting);
108
+
109
+ if (!columnMeta.sortProperty) {
110
+ return;
111
+ }
112
+
113
+ if (columnMeta.sortDirection === SortDirection.Ascending) {
114
+ this.onSort?.([]);
115
+ } else if (columnMeta.sortDirection === SortDirection.Descending) {
116
+ this.onSort?.([{
117
+ direction: SortDirection.Ascending,
118
+ property: columnMeta.sortProperty
119
+ }]);
120
+ } else {
121
+ this.onSort?.([{
122
+ direction: SortDirection.Descending,
123
+ property: columnMeta.sortProperty
124
+ }]);
125
+ }
126
+ }
127
+
128
+ toggleAscending(column) {
129
+ let columnMeta = meta.forColumn(column, Sorting);
130
+
131
+ if (!columnMeta.sortProperty) {
132
+ return;
133
+ }
134
+
135
+ if (columnMeta.sortDirection === SortDirection.Ascending) {
136
+ return this.onSort?.([]);
137
+ }
138
+
139
+ this.onSort?.([{
140
+ direction: SortDirection.Ascending,
141
+ property: columnMeta.sortProperty
142
+ }]);
143
+ }
144
+
145
+ toggleDescending(column) {
146
+ let columnMeta = meta.forColumn(column, Sorting);
147
+
148
+ if (!columnMeta.sortProperty) {
149
+ return;
150
+ }
151
+
152
+ if (columnMeta.sortDirection === SortDirection.Descending) {
153
+ return this.onSort?.([]);
154
+ }
155
+
156
+ this.onSort?.([{
157
+ direction: SortDirection.Descending,
158
+ property: columnMeta.sortProperty
159
+ }]);
160
+ }
161
+
162
+ }, (_applyDecoratedDescriptor(_class2.prototype, "options", [cached], Object.getOwnPropertyDescriptor(_class2.prototype, "options"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleSort", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSort"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "toggleAscending", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleAscending"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "toggleDescending", [action], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleDescending"), _class2.prototype)), _class2);
163
+
164
+ export { ColumnMeta, Sorting, TableMeta };
165
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/plugins/data-sorting/plugin.ts"],"sourcesContent":["import { cached } from '@glimmer/tracking';\nimport { action } from '@ember/object';\n\nimport { BasePlugin, meta, options } from '../-private/base';\nimport { SortDirection } from './types';\n\nimport type { Sort, SortItem } from './types';\nimport type { ColumnApi, PluginPreferences } from '[public-plugin-types]';\nimport type { Column, Table } from '[public-types]';\n\ninterface SortingPreferences extends PluginPreferences {\n table: {\n sorts?: Sort[];\n };\n}\n\ndeclare module 'ember-headless-table/plugins' {\n interface Registry {\n Sorting?: SortingPreferences;\n }\n}\n\nexport interface Signature<DataType = unknown> {\n Meta: {\n Column: ColumnMeta;\n Table: TableMeta;\n };\n Options: {\n Plugin: Options<DataType>;\n Column: ColumnOptions;\n };\n}\n\ninterface Options<DataType = unknown> {\n /**\n * Handler for interpreting sort requests from the headless table.\n *\n * Does not actually do the sorting.\n *\n * if omitted, the DataSorting plugin will disable itself\n */\n onSort?: (sorts: SortItem<DataType>[]) => void;\n /**\n * Provided sorts that the table should assume are true.\n *\n * if omitted, the DataSorting plugin will disable itself\n */\n sorts?: SortItem<DataType>[];\n}\n\ninterface ColumnOptions {\n /**\n * Opt in or out of sorting for a particular column.\n * Default is true.\n */\n isSortable?: boolean;\n /**\n * Use this key instead of the `key` on the column config.\n * This has no bearing on any behavior in the plugin, *other than*,\n * swapping out the `property`'s value on the `SortItem`s passed to\n * the table plugin config's `onSort` callback\n */\n sortProperty?: string;\n}\n\n/**\n * Manages basic data-sorting behaviors. Ascending -> Descending -> None\n *\n * This plugin requires a table plugin configuration, `onSort` for handling *how* sorting happens.\n * communicating back to the table that sorting has succeeded can be done by setting the `sorts`\n * property in the table plugin configuration.\n *\n * Note that this plugin doesn't actually sort the data, as data management is not the responsibility\n * of the table, but of the surrounding context providing the data to the table. So sorting can happen\n * client-side still, just in a component -- much the same way you'd handel sorting via API requests.\n *\n * This plugin is for *conveying* what the current sorts are, rather than _doing_ the sorting.\n */\nexport class Sorting<DataType = unknown> extends BasePlugin<Signature<DataType>> {\n name = 'data-sorting';\n\n meta = {\n column: ColumnMeta,\n table: TableMeta,\n };\n\n headerCellModifier = (element: HTMLElement, { column }: ColumnApi) => {\n let columnMeta = meta.forColumn(column, Sorting);\n\n element.setAttribute('data-test-is-sortable', `${columnMeta.isSortable}`);\n element.setAttribute('aria-sort', `${columnMeta.sortDirection}`);\n };\n}\n\nexport class ColumnMeta {\n constructor(private column: Column) {}\n\n @cached\n get options() {\n return options.forColumn(this.column, Sorting);\n }\n\n get isSortable() {\n return this.options?.isSortable ?? this.tableMeta.isSortable;\n }\n\n get tableMeta() {\n return meta.forTable(this.column.table, Sorting);\n }\n\n get sortDirection() {\n let sort = this.tableMeta.sorts.find((sort) => sort.property === this.sortProperty);\n\n return sort?.direction ?? SortDirection.None;\n }\n\n get isAscending() {\n return this.sortDirection === SortDirection.Ascending;\n }\n\n get isDescending() {\n return this.sortDirection === SortDirection.Descending;\n }\n\n get isUnsorted() {\n return this.sortDirection === SortDirection.None;\n }\n\n get sortProperty() {\n return this.options?.sortProperty ?? this.column.config.key;\n }\n}\n\nexport class TableMeta {\n constructor(private table: Table) {}\n\n @cached\n get options() {\n return options.forTable(this.table, Sorting);\n }\n\n get sorts() {\n return this.options?.sorts ?? [];\n }\n\n get isSortable() {\n return Boolean(this.options?.onSort) && Boolean(this.options?.sorts);\n }\n\n get onSort() {\n return this.options?.onSort;\n }\n\n @action\n handleSort(column: Column) {\n let columnMeta = meta.forColumn(column, Sorting);\n\n if (!columnMeta.sortProperty) {\n return;\n }\n\n if (columnMeta.sortDirection === SortDirection.Ascending) {\n this.onSort?.([]);\n } else if (columnMeta.sortDirection === SortDirection.Descending) {\n this.onSort?.([{ direction: SortDirection.Ascending, property: columnMeta.sortProperty }]);\n } else {\n this.onSort?.([{ direction: SortDirection.Descending, property: columnMeta.sortProperty }]);\n }\n }\n\n @action\n toggleAscending(column: Column) {\n let columnMeta = meta.forColumn(column, Sorting);\n\n if (!columnMeta.sortProperty) {\n return;\n }\n\n if (columnMeta.sortDirection === SortDirection.Ascending) {\n return this.onSort?.([]);\n }\n\n this.onSort?.([{ direction: SortDirection.Ascending, property: columnMeta.sortProperty }]);\n }\n\n @action\n toggleDescending(column: Column) {\n let columnMeta = meta.forColumn(column, Sorting);\n\n if (!columnMeta.sortProperty) {\n return;\n }\n\n if (columnMeta.sortDirection === SortDirection.Descending) {\n return this.onSort?.([]);\n }\n\n this.onSort?.([{ direction: SortDirection.Descending, property: columnMeta.sortProperty }]);\n }\n}\n"],"names":["Sorting","BasePlugin","column","ColumnMeta","table","TableMeta","element","columnMeta","meta","forColumn","setAttribute","isSortable","sortDirection","constructor","options","tableMeta","forTable","sort","sorts","find","property","sortProperty","direction","SortDirection","None","isAscending","Ascending","isDescending","Descending","isUnsorted","config","key","cached","Boolean","onSort","handleSort","toggleAscending","toggleDescending","action"],"mappings":";;;;;;;;;;;AAiEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,OAAN,SAA0CC,UAA1C,CAA0E;AAAA,EAAA,WAAA,CAAA,GAAA,IAAA,EAAA;AAAA,IAAA,KAAA,CAAA,GAAA,IAAA,CAAA,CAAA;;AAAA,IAAA,eAAA,CAAA,IAAA,EAAA,MAAA,EACxE,cADwE,CAAA,CAAA;;IAAA,eAGxE,CAAA,IAAA,EAAA,MAAA,EAAA;AACLC,MAAAA,MAAM,EAAEC,UADH;AAELC,MAAAA,KAAK,EAAEC,SAAAA;KALsE,CAAA,CAAA;;IAAA,eAQ1D,CAAA,IAAA,EAAA,oBAAA,EAAA,CAACC,OAAD,EAAuB;AAAEJ,MAAAA,MAAAA;AAAF,KAAvB,KAAiD;MACpE,IAAIK,UAAU,GAAGC,IAAI,CAACC,SAAL,CAAeP,MAAf,EAAuBF,OAAvB,CAAjB,CAAA;MAEAM,OAAO,CAACI,YAAR,CAAqB,uBAArB,EAA+C,CAAEH,EAAAA,UAAU,CAACI,UAAW,CAAvE,CAAA,CAAA,CAAA;MACAL,OAAO,CAACI,YAAR,CAAqB,WAArB,EAAmC,CAAEH,EAAAA,UAAU,CAACK,aAAc,CAA9D,CAAA,CAAA,CAAA;KAZ6E,CAAA,CAAA;AAAA,GAAA;;AAAA,CAAA;AAgBjF,IAAaT,UAAb,IAAA,MAAA,GAAO,MAAMA,UAAN,CAAiB;EACtBU,WAAW,CAASX,MAAT,EAAyB;IAAA,IAAhBA,CAAAA,MAAgB,GAAhBA,MAAgB,CAAA;AAAE,GAA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AAQ,EAAEb,UAAU,CAACc,YAAAA;AAA5D,KAAD,CAAd,CAAA,CAAA;AACD,GAAA;;AAjEoB,CAAvB,4DAGGW,MAHH,CAAA,EAAA,MAAA,CAAA,wBAAA,CAAA,OAAA,CAAA,SAAA,EAAA,SAAA,CAAA,EAAA,OAAA,CAAA,SAAA,CAAA,EAAA,yBAAA,CAAA,OAAA,CAAA,SAAA,EAAA,YAAA,EAAA,CAoBGM,MApBH,CAqCGA,EAAAA,MAAAA,CAAAA,wBAAAA,CAAAA,OAAAA,CAAAA,SAAAA,EAAAA,YAAAA,CAAAA,EAAAA,OAAAA,CAAAA,SAAAA,CAAAA,EAAAA,yBAAAA,CAAAA,OAAAA,CAAAA,SAAAA,EAAAA,iBAAAA,EAAAA,CAAAA,MArCH,gKAoDGA,MApDH,CAAA,EAAA,MAAA,CAAA,wBAAA,CAAA,OAAA,CAAA,SAAA,EAAA,kBAAA,CAAA,EAAA,OAAA,CAAA,SAAA,CAAA,GAAA,OAAA;;;;"}
@@ -0,0 +1,23 @@
1
+ import { ColumnKey } from "../../-private/interfaces/index";
2
+ declare enum SortDirection {
3
+ Ascending = "ascending",
4
+ Descending = "descending",
5
+ None = "none"
6
+ }
7
+ interface Sort {
8
+ property: string;
9
+ direction: SortDirection;
10
+ }
11
+ declare enum SortTransform {
12
+ Underscore = "underscore",
13
+ Camelize = "camelize"
14
+ }
15
+ interface SortsOptions {
16
+ separator: string;
17
+ transform: string | null;
18
+ }
19
+ interface SortItem<T> {
20
+ direction: SortDirection;
21
+ property: ColumnKey<T>;
22
+ }
23
+ export { SortDirection, Sort, SortTransform, SortsOptions, SortItem };
@@ -0,0 +1,17 @@
1
+ let SortDirection;
2
+
3
+ (function (SortDirection) {
4
+ SortDirection["Ascending"] = "ascending";
5
+ SortDirection["Descending"] = "descending";
6
+ SortDirection["None"] = "none";
7
+ })(SortDirection || (SortDirection = {}));
8
+
9
+ let SortTransform;
10
+
11
+ (function (SortTransform) {
12
+ SortTransform["Underscore"] = "underscore";
13
+ SortTransform["Camelize"] = "camelize";
14
+ })(SortTransform || (SortTransform = {}));
15
+
16
+ export { SortDirection, SortTransform };
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":["../../../src/plugins/data-sorting/types.ts"],"sourcesContent":["import type { ColumnKey } from '#/interfaces';\n\nexport enum SortDirection {\n Ascending = 'ascending',\n Descending = 'descending',\n None = 'none',\n}\n\nexport interface Sort {\n property: string;\n direction: SortDirection;\n}\n\nexport enum SortTransform {\n Underscore = 'underscore',\n Camelize = 'camelize',\n}\nexport interface SortsOptions {\n separator: string;\n transform: string | null;\n}\n\nexport interface SortItem<T> {\n direction: SortDirection;\n property: ColumnKey<T>;\n}\n"],"names":["SortDirection","SortTransform"],"mappings":"AAEA,IAAYA,cAAZ;;WAAYA;EAAAA;EAAAA;EAAAA;AAAAA,CAAAA,EAAAA,kBAAAA;;AAWZ,IAAYC,cAAZ;;WAAYA;EAAAA;EAAAA;AAAAA,CAAAA,EAAAA,kBAAAA;;;;"}
@@ -0,0 +1,5 @@
1
+ export { BasePlugin, columns, meta, options, preferences } from "./-private/base";
2
+ export { applyStyles, removeStyles } from "./-private/utils";
3
+ export type { ColumnFeatures, TableFeatures } from "./-private/base";
4
+ export type { ColumnApi, Plugin, PluginPreferences, Registry } from "../-private/interfaces/index";
5
+ export type { PluginSignature } from "../-private/interfaces/plugins";
@@ -0,0 +1,3 @@
1
+ export { BasePlugin, columns, meta, options, preferences } from './-private/base.js';
2
+ export { applyStyles, removeStyles } from './-private/utils.js';
3
+ //# sourceMappingURL=index.js.map