tabulator-tables 5.4.3 → 5.5.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 (253) hide show
  1. package/.babelrc.json +3 -3
  2. package/.editorconfig +6 -6
  3. package/.eslintignore +3 -3
  4. package/.eslintrc.js +28 -28
  5. package/.github/ISSUE_TEMPLATE/bug_report.md +58 -58
  6. package/.github/ISSUE_TEMPLATE/documentation.md +14 -14
  7. package/.github/ISSUE_TEMPLATE/feature_request.md +24 -24
  8. package/.github/ISSUE_TEMPLATE/question.md +12 -12
  9. package/.github/workflows/bad-files-check.yml +39 -39
  10. package/.github/workflows/lint-and-test.yml +30 -30
  11. package/CODE_OF_CONDUCT.md +46 -46
  12. package/CONTRIBUTING.md +22 -22
  13. package/LICENSE +20 -20
  14. package/README.md +76 -76
  15. package/bower.json +40 -40
  16. package/build/Bundler.js +185 -185
  17. package/build/rollup.js +6 -6
  18. package/dist/css/tabulator.css +80 -53
  19. package/dist/css/tabulator.css.map +1 -1
  20. package/dist/css/tabulator.min.css +1 -1
  21. package/dist/css/tabulator.min.css.map +1 -1
  22. package/dist/css/tabulator_bootstrap3.css +89 -58
  23. package/dist/css/tabulator_bootstrap3.css.map +1 -1
  24. package/dist/css/tabulator_bootstrap3.min.css +1 -1
  25. package/dist/css/tabulator_bootstrap3.min.css.map +1 -1
  26. package/dist/css/tabulator_bootstrap4.css +106 -73
  27. package/dist/css/tabulator_bootstrap4.css.map +1 -1
  28. package/dist/css/tabulator_bootstrap4.min.css +1 -1
  29. package/dist/css/tabulator_bootstrap4.min.css.map +1 -1
  30. package/dist/css/tabulator_bootstrap5.css +110 -75
  31. package/dist/css/tabulator_bootstrap5.css.map +1 -1
  32. package/dist/css/tabulator_bootstrap5.min.css +1 -1
  33. package/dist/css/tabulator_bootstrap5.min.css.map +1 -1
  34. package/dist/css/tabulator_bulma.css +95 -62
  35. package/dist/css/tabulator_bulma.css.map +1 -1
  36. package/dist/css/tabulator_bulma.min.css +1 -1
  37. package/dist/css/tabulator_bulma.min.css.map +1 -1
  38. package/dist/css/tabulator_materialize.css +93 -63
  39. package/dist/css/tabulator_materialize.css.map +1 -1
  40. package/dist/css/tabulator_materialize.min.css +1 -1
  41. package/dist/css/tabulator_materialize.min.css.map +1 -1
  42. package/dist/css/tabulator_midnight.css +90 -59
  43. package/dist/css/tabulator_midnight.css.map +1 -1
  44. package/dist/css/tabulator_midnight.min.css +1 -1
  45. package/dist/css/tabulator_midnight.min.css.map +1 -1
  46. package/dist/css/tabulator_modern.css +96 -62
  47. package/dist/css/tabulator_modern.css.map +1 -1
  48. package/dist/css/tabulator_modern.min.css +1 -1
  49. package/dist/css/tabulator_modern.min.css.map +1 -1
  50. package/dist/css/tabulator_semanticui.css +233 -182
  51. package/dist/css/tabulator_semanticui.css.map +1 -1
  52. package/dist/css/tabulator_semanticui.min.css +1 -1
  53. package/dist/css/tabulator_semanticui.min.css.map +1 -1
  54. package/dist/css/tabulator_simple.css +80 -53
  55. package/dist/css/tabulator_simple.css.map +1 -1
  56. package/dist/css/tabulator_simple.min.css +1 -1
  57. package/dist/css/tabulator_simple.min.css.map +1 -1
  58. package/dist/css/tabulator_site.css +88 -57
  59. package/dist/css/tabulator_site.css.map +1 -1
  60. package/dist/css/tabulator_site.min.css +1 -1
  61. package/dist/css/tabulator_site.min.css.map +1 -1
  62. package/dist/js/jquery_wrapper.js +55 -55
  63. package/dist/js/tabulator.js +26054 -25713
  64. package/dist/js/tabulator.js.map +1 -1
  65. package/dist/js/tabulator.min.js +2 -2
  66. package/dist/js/tabulator.min.js.map +1 -1
  67. package/dist/js/tabulator_esm.js +26131 -25790
  68. package/dist/js/tabulator_esm.js.map +1 -1
  69. package/dist/js/tabulator_esm.min.js +2 -2
  70. package/dist/js/tabulator_esm.min.js.map +1 -1
  71. package/package.json +65 -65
  72. package/src/js/builds/esm.js +14 -14
  73. package/src/js/builds/jquery_wrapper.js +55 -55
  74. package/src/js/core/ColumnManager.js +745 -730
  75. package/src/js/core/CoreFeature.js +138 -138
  76. package/src/js/core/FooterManager.js +101 -101
  77. package/src/js/core/Module.js +141 -141
  78. package/src/js/core/RowManager.js +1128 -1101
  79. package/src/js/core/Tabulator.js +895 -892
  80. package/src/js/core/TabulatorFull.js +10 -10
  81. package/src/js/core/cell/Cell.js +295 -295
  82. package/src/js/core/cell/CellComponent.js +78 -76
  83. package/src/js/core/column/Column.js +949 -949
  84. package/src/js/core/column/ColumnComponent.js +152 -152
  85. package/src/js/core/column/defaults/options.js +17 -17
  86. package/src/js/core/defaults/options.js +65 -65
  87. package/src/js/core/modules/core.js +2 -2
  88. package/src/js/core/modules/optional.js +34 -34
  89. package/src/js/core/rendering/Renderer.js +203 -203
  90. package/src/js/core/rendering/renderers/BasicHorizontal.js +24 -19
  91. package/src/js/core/rendering/renderers/BasicVertical.js +83 -79
  92. package/src/js/core/rendering/renderers/VirtualDomHorizontal.js +582 -577
  93. package/src/js/core/rendering/renderers/VirtualDomVertical.js +634 -580
  94. package/src/js/core/row/PseudoRow.js +44 -44
  95. package/src/js/core/row/Row.js +457 -457
  96. package/src/js/core/row/RowComponent.js +93 -93
  97. package/src/js/core/tools/Alert.js +61 -61
  98. package/src/js/core/tools/ComponentFunctionBinder.js +32 -32
  99. package/src/js/core/tools/DataLoader.js +119 -119
  100. package/src/js/core/tools/DeprecationAdvisor.js +46 -46
  101. package/src/js/core/tools/ExternalEventBus.js +104 -104
  102. package/src/js/core/tools/Helpers.js +46 -46
  103. package/src/js/core/tools/InteractionMonitor.js +321 -321
  104. package/src/js/core/tools/InternalEventBus.js +161 -161
  105. package/src/js/core/tools/ModuleBinder.js +104 -104
  106. package/src/js/core/tools/OptionsList.js +44 -40
  107. package/src/js/core/tools/Popup.js +304 -304
  108. package/src/js/core/tools/TableRegistry.js +61 -61
  109. package/src/js/modules/Accessor/Accessor.js +115 -115
  110. package/src/js/modules/Ajax/Ajax.js +143 -143
  111. package/src/js/modules/Ajax/defaults/config.js +2 -2
  112. package/src/js/modules/Ajax/defaults/contentTypeFormatters.js +44 -44
  113. package/src/js/modules/Ajax/defaults/loaderPromise.js +86 -86
  114. package/src/js/modules/Ajax/defaults/urlGenerator.js +43 -43
  115. package/src/js/modules/Clipboard/Clipboard.js +279 -279
  116. package/src/js/modules/Clipboard/defaults/pasteActions.js +10 -10
  117. package/src/js/modules/Clipboard/defaults/pasteParsers.js +74 -74
  118. package/src/js/modules/ColumnCalcs/CalcComponent.js +47 -47
  119. package/src/js/modules/ColumnCalcs/ColumnCalcs.js +581 -568
  120. package/src/js/modules/ColumnCalcs/defaults/calculations.js +92 -85
  121. package/src/js/modules/Comms/Comms.js +51 -51
  122. package/src/js/modules/DataTree/DataTree.js +603 -603
  123. package/src/js/modules/Download/Download.js +148 -148
  124. package/src/js/modules/Download/defaults/downloaders/csv.js +61 -61
  125. package/src/js/modules/Download/defaults/downloaders/html.js +4 -4
  126. package/src/js/modules/Download/defaults/downloaders/json.js +33 -33
  127. package/src/js/modules/Download/defaults/downloaders/jsonLines.js +31 -31
  128. package/src/js/modules/Download/defaults/downloaders/pdf.js +111 -111
  129. package/src/js/modules/Download/defaults/downloaders/xlsx.js +102 -99
  130. package/src/js/modules/Download/defaults/downloaders.js +14 -14
  131. package/src/js/modules/Edit/Edit.js +734 -736
  132. package/src/js/modules/Edit/List.js +1048 -1033
  133. package/src/js/modules/Edit/defaults/editors/autocomplete.js +11 -11
  134. package/src/js/modules/Edit/defaults/editors/date.js +138 -110
  135. package/src/js/modules/Edit/defaults/editors/datetime.js +125 -97
  136. package/src/js/modules/Edit/defaults/editors/input.js +76 -74
  137. package/src/js/modules/Edit/defaults/editors/list.js +6 -6
  138. package/src/js/modules/Edit/defaults/editors/number.js +109 -107
  139. package/src/js/modules/Edit/defaults/editors/progress.js +126 -126
  140. package/src/js/modules/Edit/defaults/editors/range.js +80 -78
  141. package/src/js/modules/Edit/defaults/editors/select.js +9 -9
  142. package/src/js/modules/Edit/defaults/editors/star.js +145 -145
  143. package/src/js/modules/Edit/defaults/editors/textarea.js +122 -120
  144. package/src/js/modules/Edit/defaults/editors/tickCross.js +94 -96
  145. package/src/js/modules/Edit/defaults/editors/time.js +126 -98
  146. package/src/js/modules/Edit/defaults/editors.js +28 -28
  147. package/src/js/modules/Edit/inputMask.js +73 -73
  148. package/src/js/modules/Export/Export.js +626 -623
  149. package/src/js/modules/Export/ExportColumn.js +10 -10
  150. package/src/js/modules/Export/ExportRow.js +9 -9
  151. package/src/js/modules/Filter/Filter.js +903 -892
  152. package/src/js/modules/Filter/defaults/filters.js +107 -107
  153. package/src/js/modules/Format/Format.js +215 -212
  154. package/src/js/modules/Format/defaults/formatters/buttonCross.js +2 -2
  155. package/src/js/modules/Format/defaults/formatters/buttonTick.js +2 -2
  156. package/src/js/modules/Format/defaults/formatters/color.js +3 -3
  157. package/src/js/modules/Format/defaults/formatters/datetime.js +36 -36
  158. package/src/js/modules/Format/defaults/formatters/datetimediff.js +40 -40
  159. package/src/js/modules/Format/defaults/formatters/handle.js +3 -3
  160. package/src/js/modules/Format/defaults/formatters/html.js +2 -2
  161. package/src/js/modules/Format/defaults/formatters/image.js +39 -39
  162. package/src/js/modules/Format/defaults/formatters/link.js +77 -77
  163. package/src/js/modules/Format/defaults/formatters/lookup.js +9 -9
  164. package/src/js/modules/Format/defaults/formatters/money.js +43 -36
  165. package/src/js/modules/Format/defaults/formatters/plaintext.js +2 -2
  166. package/src/js/modules/Format/defaults/formatters/progress.js +132 -132
  167. package/src/js/modules/Format/defaults/formatters/responsiveCollapse.js +43 -43
  168. package/src/js/modules/Format/defaults/formatters/rowSelection.js +59 -59
  169. package/src/js/modules/Format/defaults/formatters/rownum.js +9 -9
  170. package/src/js/modules/Format/defaults/formatters/star.js +37 -37
  171. package/src/js/modules/Format/defaults/formatters/textarea.js +3 -3
  172. package/src/js/modules/Format/defaults/formatters/tickCross.js +21 -21
  173. package/src/js/modules/Format/defaults/formatters/traffic.js +46 -46
  174. package/src/js/modules/Format/defaults/formatters.js +42 -42
  175. package/src/js/modules/FrozenColumns/FrozenColumns.js +299 -299
  176. package/src/js/modules/FrozenRows/FrozenRows.js +169 -159
  177. package/src/js/modules/GroupRows/Group.js +597 -598
  178. package/src/js/modules/GroupRows/GroupComponent.js +70 -66
  179. package/src/js/modules/GroupRows/GroupRows.js +639 -639
  180. package/src/js/modules/History/History.js +171 -171
  181. package/src/js/modules/History/defaults/redoers.js +24 -24
  182. package/src/js/modules/History/defaults/undoers.js +24 -24
  183. package/src/js/modules/HtmlTableImport/HtmlTableImport.js +181 -181
  184. package/src/js/modules/Import/Import.js +193 -193
  185. package/src/js/modules/Import/defaults/importers/array.js +4 -4
  186. package/src/js/modules/Import/defaults/importers/csv.js +62 -62
  187. package/src/js/modules/Import/defaults/importers/json.js +7 -7
  188. package/src/js/modules/Import/defaults/importers.js +8 -8
  189. package/src/js/modules/Interaction/Interaction.js +337 -325
  190. package/src/js/modules/Keybindings/Keybindings.js +172 -172
  191. package/src/js/modules/Keybindings/defaults/actions.js +118 -118
  192. package/src/js/modules/Keybindings/defaults/bindings.js +12 -12
  193. package/src/js/modules/Layout/Layout.js +49 -49
  194. package/src/js/modules/Layout/defaults/modes/fitColumns.js +171 -171
  195. package/src/js/modules/Layout/defaults/modes/fitData.js +9 -9
  196. package/src/js/modules/Layout/defaults/modes/fitDataGeneral.js +9 -9
  197. package/src/js/modules/Layout/defaults/modes/fitDataStretch.js +39 -39
  198. package/src/js/modules/Layout/defaults/modes.js +11 -11
  199. package/src/js/modules/Localize/Localize.js +185 -185
  200. package/src/js/modules/Localize/defaults/langs.js +36 -36
  201. package/src/js/modules/Menu/Menu.js +302 -302
  202. package/src/js/modules/MoveColumns/MoveColumns.js +299 -299
  203. package/src/js/modules/MoveRows/MoveRows.js +635 -635
  204. package/src/js/modules/Mutator/Mutator.js +161 -161
  205. package/src/js/modules/Page/Page.js +881 -881
  206. package/src/js/modules/Page/defaults/pageCounters/pages.js +32 -32
  207. package/src/js/modules/Page/defaults/pageCounters/rows.js +39 -39
  208. package/src/js/modules/Page/defaults/pageCounters.js +7 -7
  209. package/src/js/modules/Persistence/Persistence.js +472 -458
  210. package/src/js/modules/Persistence/defaults/readers.js +29 -29
  211. package/src/js/modules/Persistence/defaults/writers.js +12 -12
  212. package/src/js/modules/Popup/Popup.js +231 -231
  213. package/src/js/modules/Print/Print.js +137 -137
  214. package/src/js/modules/ReactiveData/ReactiveData.js +408 -408
  215. package/src/js/modules/ResizeColumns/ResizeColumns.js +309 -309
  216. package/src/js/modules/ResizeRows/ResizeRows.js +111 -111
  217. package/src/js/modules/ResizeTable/ResizeTable.js +159 -159
  218. package/src/js/modules/ResponsiveLayout/ResponsiveLayout.js +348 -345
  219. package/src/js/modules/SelectRow/SelectRow.js +474 -444
  220. package/src/js/modules/Sort/Sort.js +470 -470
  221. package/src/js/modules/Sort/defaults/sorters/alphanum.js +43 -43
  222. package/src/js/modules/Sort/defaults/sorters/array.js +53 -53
  223. package/src/js/modules/Sort/defaults/sorters/boolean.js +6 -6
  224. package/src/js/modules/Sort/defaults/sorters/date.js +9 -9
  225. package/src/js/modules/Sort/defaults/sorters/datetime.js +43 -43
  226. package/src/js/modules/Sort/defaults/sorters/exists.js +6 -6
  227. package/src/js/modules/Sort/defaults/sorters/number.js +39 -39
  228. package/src/js/modules/Sort/defaults/sorters/string.js +33 -33
  229. package/src/js/modules/Sort/defaults/sorters/time.js +9 -9
  230. package/src/js/modules/Sort/defaults/sorters.js +20 -20
  231. package/src/js/modules/Tooltip/Tooltip.js +130 -130
  232. package/src/js/modules/Validate/Validate.js +305 -305
  233. package/src/js/modules/Validate/defaults/validators.js +138 -138
  234. package/src/scss/tabulator.scss +1496 -1467
  235. package/src/scss/themes/bootstrap/functions4.scss +118 -118
  236. package/src/scss/themes/bootstrap/functions5.scss +302 -302
  237. package/src/scss/themes/bootstrap/tabulator_bootstrap3.scss +288 -284
  238. package/src/scss/themes/bootstrap/tabulator_bootstrap4.scss +552 -544
  239. package/src/scss/themes/bootstrap/tabulator_bootstrap5.scss +584 -574
  240. package/src/scss/themes/bootstrap/variables3.scss +870 -870
  241. package/src/scss/themes/bootstrap/variables4.scss +930 -930
  242. package/src/scss/themes/bootstrap/variables5.scss +1641 -1641
  243. package/src/scss/themes/bulma/tabulator_bulma.scss +258 -252
  244. package/src/scss/themes/bulma/variables.scss +197 -197
  245. package/src/scss/themes/materialize/tabulator_materialize.scss +269 -265
  246. package/src/scss/themes/materialize/variables.scss +70 -70
  247. package/src/scss/themes/semanticui/tabulator_semanticui.scss +586 -561
  248. package/src/scss/themes/semanticui/variables.scss +839 -839
  249. package/src/scss/themes/semanticui/variables_table.scss +247 -247
  250. package/src/scss/themes/tabulator_midnight.scss +162 -158
  251. package/src/scss/themes/tabulator_modern.scss +239 -231
  252. package/src/scss/themes/tabulator_simple.scss +102 -102
  253. package/src/scss/themes/tabulator_site.scss +193 -189
@@ -1,459 +1,473 @@
1
- import Module from '../../core/Module.js';
2
-
3
- import defaultReaders from './defaults/readers.js';
4
- import defaultWriters from './defaults/writers.js';
5
-
6
- class Persistence extends Module{
7
-
8
- constructor(table){
9
- super(table);
10
-
11
- this.mode = "";
12
- this.id = "";
13
- // this.persistProps = ["field", "width", "visible"];
14
- this.defWatcherBlock = false;
15
- this.config = {};
16
- this.readFunc = false;
17
- this.writeFunc = false;
18
-
19
- this.registerTableOption("persistence", false);
20
- this.registerTableOption("persistenceID", ""); //key for persistent storage
21
- this.registerTableOption("persistenceMode", true); //mode for storing persistence information
22
- this.registerTableOption("persistenceReaderFunc", false); //function for handling persistence data reading
23
- this.registerTableOption("persistenceWriterFunc", false); //function for handling persistence data writing
24
- }
25
-
26
- // Test for whether localStorage is available for use.
27
- localStorageTest() {
28
- var testKey = "_tabulator_test";
29
-
30
- try {
31
- window.localStorage.setItem( testKey, testKey);
32
- window.localStorage.removeItem( testKey );
33
- return true;
34
- } catch(e) {
35
- return false;
36
- }
37
- }
38
-
39
- //setup parameters
40
- initialize(){
41
- if(this.table.options.persistence){
42
- //determine persistent layout storage type
43
- var mode = this.table.options.persistenceMode,
44
- id = this.table.options.persistenceID,
45
- retrievedData;
46
-
47
- this.mode = mode !== true ? mode : (this.localStorageTest() ? "local" : "cookie");
48
-
49
- if(this.table.options.persistenceReaderFunc){
50
- if(typeof this.table.options.persistenceReaderFunc === "function"){
51
- this.readFunc = this.table.options.persistenceReaderFunc;
52
- }else{
53
- if(Persistence.readers[this.table.options.persistenceReaderFunc]){
54
- this.readFunc = Persistence.readers[this.table.options.persistenceReaderFunc];
55
- }else{
56
- console.warn("Persistence Read Error - invalid reader set", this.table.options.persistenceReaderFunc);
57
- }
58
- }
59
- }else{
60
- if(Persistence.readers[this.mode]){
61
- this.readFunc = Persistence.readers[this.mode];
62
- }else{
63
- console.warn("Persistence Read Error - invalid reader set", this.mode);
64
- }
65
- }
66
-
67
- if(this.table.options.persistenceWriterFunc){
68
- if(typeof this.table.options.persistenceWriterFunc === "function"){
69
- this.writeFunc = this.table.options.persistenceWriterFunc;
70
- }else{
71
- if(Persistence.writers[this.table.options.persistenceWriterFunc]){
72
- this.writeFunc = Persistence.writers[this.table.options.persistenceWriterFunc];
73
- }else{
74
- console.warn("Persistence Write Error - invalid reader set", this.table.options.persistenceWriterFunc);
75
- }
76
- }
77
- }else{
78
- if(Persistence.writers[this.mode]){
79
- this.writeFunc = Persistence.writers[this.mode];
80
- }else{
81
- console.warn("Persistence Write Error - invalid writer set", this.mode);
82
- }
83
- }
84
-
85
- //set storage tag
86
- this.id = "tabulator-" + (id || (this.table.element.getAttribute("id") || ""));
87
-
88
- this.config = {
89
- sort:this.table.options.persistence === true || this.table.options.persistence.sort,
90
- filter:this.table.options.persistence === true || this.table.options.persistence.filter,
91
- group:this.table.options.persistence === true || this.table.options.persistence.group,
92
- page:this.table.options.persistence === true || this.table.options.persistence.page,
93
- columns:this.table.options.persistence === true ? ["title", "width", "visible"] : this.table.options.persistence.columns,
94
- };
95
-
96
- //load pagination data if needed
97
- if(this.config.page){
98
- retrievedData = this.retrieveData("page");
99
-
100
- if(retrievedData){
101
- if(typeof retrievedData.paginationSize !== "undefined" && (this.config.page === true || this.config.page.size)){
102
- this.table.options.paginationSize = retrievedData.paginationSize;
103
- }
104
-
105
- if(typeof retrievedData.paginationInitialPage !== "undefined" && (this.config.page === true || this.config.page.page)){
106
- this.table.options.paginationInitialPage = retrievedData.paginationInitialPage;
107
- }
108
- }
109
- }
110
-
111
- //load group data if needed
112
- if(this.config.group){
113
- retrievedData = this.retrieveData("group");
114
-
115
- if(retrievedData){
116
- if(typeof retrievedData.groupBy !== "undefined" && (this.config.group === true || this.config.group.groupBy)){
117
- this.table.options.groupBy = retrievedData.groupBy;
118
- }
119
- if(typeof retrievedData.groupStartOpen !== "undefined" && (this.config.group === true || this.config.group.groupStartOpen)){
120
- this.table.options.groupStartOpen = retrievedData.groupStartOpen;
121
- }
122
- if(typeof retrievedData.groupHeader !== "undefined" && (this.config.group === true || this.config.group.groupHeader)){
123
- this.table.options.groupHeader = retrievedData.groupHeader;
124
- }
125
- }
126
- }
127
-
128
- if(this.config.columns){
129
- this.table.options.columns = this.load("columns", this.table.options.columns);
130
- this.subscribe("column-init", this.initializeColumn.bind(this));
131
- this.subscribe("column-show", this.save.bind(this, "columns"));
132
- this.subscribe("column-hide", this.save.bind(this, "columns"));
133
- this.subscribe("column-moved", this.save.bind(this, "columns"));
134
- }
135
-
136
- this.subscribe("table-built", this.tableBuilt.bind(this), 0);
137
-
138
- this.subscribe("table-redraw", this.tableRedraw.bind(this));
139
-
140
- this.subscribe("filter-changed", this.eventSave.bind(this, "filter"));
141
- this.subscribe("sort-changed", this.eventSave.bind(this, "sort"));
142
- this.subscribe("group-changed", this.eventSave.bind(this, "group"));
143
- this.subscribe("page-changed", this.eventSave.bind(this, "page"));
144
- this.subscribe("column-resized", this.eventSave.bind(this, "columns"));
145
- this.subscribe("column-width", this.eventSave.bind(this, "columns"));
146
- this.subscribe("layout-refreshed", this.eventSave.bind(this, "columns"));
147
- }
148
-
149
- this.registerTableFunction("getColumnLayout", this.getColumnLayout.bind(this));
150
- this.registerTableFunction("setColumnLayout", this.setColumnLayout.bind(this));
151
- }
152
-
153
- eventSave(type){
154
- if(this.config[type]){
155
- this.save(type);
156
- }
157
- }
158
-
159
- tableBuilt(){
160
- var sorters, filters;
161
-
162
- if(this.config.sort){
163
- sorters = this.load("sort");
164
-
165
- if(!sorters === false){
166
- this.table.options.initialSort = sorters;
167
- }
168
- }
169
-
170
- if(this.config.filter){
171
- filters = this.load("filter");
172
-
173
- if(!filters === false){
174
- this.table.options.initialFilter = filters;
175
- }
176
- }
177
- }
178
-
179
- tableRedraw(force){
180
- if(force && this.config.columns){
181
- this.save("columns");
182
- }
183
- }
184
-
185
- ///////////////////////////////////
186
- ///////// Table Functions /////////
187
- ///////////////////////////////////
188
-
189
- getColumnLayout(){
190
- return this.parseColumns(this.table.columnManager.getColumns());
191
- }
192
-
193
- setColumnLayout(layout){
194
- this.table.columnManager.setColumns(this.mergeDefinition(this.table.options.columns, layout));
195
- return true;
196
- }
197
-
198
- ///////////////////////////////////
199
- ///////// Internal Logic //////////
200
- ///////////////////////////////////
201
-
202
- initializeColumn(column){
203
- var def, keys;
204
-
205
- if(this.config.columns){
206
- this.defWatcherBlock = true;
207
-
208
- def = column.getDefinition();
209
-
210
- keys = this.config.columns === true ? Object.keys(def) : this.config.columns;
211
-
212
- keys.forEach((key)=>{
213
- var props = Object.getOwnPropertyDescriptor(def, key);
214
- var value = def[key];
215
-
216
- if(props){
217
- Object.defineProperty(def, key, {
218
- set: (newValue) => {
219
- value = newValue;
220
-
221
- if(!this.defWatcherBlock){
222
- this.save("columns");
223
- }
224
-
225
- if(props.set){
226
- props.set(newValue);
227
- }
228
- },
229
- get:() => {
230
- if(props.get){
231
- props.get();
232
- }
233
- return value;
234
- }
235
- });
236
- }
237
- });
238
-
239
- this.defWatcherBlock = false;
240
- }
241
- }
242
-
243
- //load saved definitions
244
- load(type, current){
245
- var data = this.retrieveData(type);
246
-
247
- if(current){
248
- data = data ? this.mergeDefinition(current, data) : current;
249
- }
250
-
251
- return data;
252
- }
253
-
254
- //retrieve data from memory
255
- retrieveData(type){
256
- return this.readFunc ? this.readFunc(this.id, type) : false;
257
- }
258
-
259
- //merge old and new column definitions
260
- mergeDefinition(oldCols, newCols){
261
- var output = [];
262
-
263
- newCols = newCols || [];
264
-
265
- newCols.forEach((column, to) => {
266
- var from = this._findColumn(oldCols, column),
267
- keys;
268
-
269
- if(from){
270
- if(this.config.columns === true || this.config.columns == undefined){
271
- keys = Object.keys(from);
272
- keys.push("width");
273
- }else{
274
- keys = this.config.columns;
275
- }
276
-
277
- keys.forEach((key)=>{
278
- if(key !== "columns" && typeof column[key] !== "undefined"){
279
- from[key] = column[key];
280
- }
281
- });
282
-
283
- if(from.columns){
284
- from.columns = this.mergeDefinition(from.columns, column.columns);
285
- }
286
-
287
- output.push(from);
288
- }
289
- });
290
-
291
- oldCols.forEach((column, i) => {
292
- var from = this._findColumn(newCols, column);
293
-
294
- if (!from) {
295
- if(output.length>i){
296
- output.splice(i, 0, column);
297
- }else{
298
- output.push(column);
299
- }
300
- }
301
- });
302
-
303
- return output;
304
- }
305
-
306
- //find matching columns
307
- _findColumn(columns, subject){
308
- var type = subject.columns ? "group" : (subject.field ? "field" : "object");
309
-
310
- return columns.find(function(col){
311
- switch(type){
312
- case "group":
313
- return col.title === subject.title && col.columns.length === subject.columns.length;
314
-
315
- case "field":
316
- return col.field === subject.field;
317
-
318
- case "object":
319
- return col === subject;
320
- }
321
- });
322
- }
323
-
324
- //save data
325
- save(type){
326
- var data = {};
327
-
328
- switch(type){
329
- case "columns":
330
- data = this.parseColumns(this.table.columnManager.getColumns());
331
- break;
332
-
333
- case "filter":
334
- data = this.table.modules.filter.getFilters();
335
- break;
336
-
337
- case "sort":
338
- data = this.validateSorters(this.table.modules.sort.getSort());
339
- break;
340
-
341
- case "group":
342
- data = this.getGroupConfig();
343
- break;
344
-
345
- case "page":
346
- data = this.getPageConfig();
347
- break;
348
- }
349
-
350
- if(this.writeFunc){
351
- this.writeFunc(this.id, type, data);
352
- }
353
-
354
- }
355
-
356
- //ensure sorters contain no function data
357
- validateSorters(data){
358
- data.forEach(function(item){
359
- item.column = item.field;
360
- delete item.field;
361
- });
362
-
363
- return data;
364
- }
365
-
366
- getGroupConfig(){
367
- var data = {};
368
-
369
- if(this.config.group){
370
- if(this.config.group === true || this.config.group.groupBy){
371
- data.groupBy = this.table.options.groupBy;
372
- }
373
-
374
- if(this.config.group === true || this.config.group.groupStartOpen){
375
- data.groupStartOpen = this.table.options.groupStartOpen;
376
- }
377
-
378
- if(this.config.group === true || this.config.group.groupHeader){
379
- data.groupHeader = this.table.options.groupHeader;
380
- }
381
- }
382
-
383
- return data;
384
- }
385
-
386
- getPageConfig(){
387
- var data = {};
388
-
389
- if(this.config.page){
390
- if(this.config.page === true || this.config.page.size){
391
- data.paginationSize = this.table.modules.page.getPageSize();
392
- }
393
-
394
- if(this.config.page === true || this.config.page.page){
395
- data.paginationInitialPage = this.table.modules.page.getPage();
396
- }
397
- }
398
-
399
- return data;
400
- }
401
-
402
-
403
- //parse columns for data to store
404
- parseColumns(columns){
405
- var definitions = [],
406
- excludedKeys = ["headerContextMenu", "headerMenu", "contextMenu", "clickMenu"];
407
-
408
- columns.forEach((column) => {
409
- var defStore = {},
410
- colDef = column.getDefinition(),
411
- keys;
412
-
413
- if(column.isGroup){
414
- defStore.title = colDef.title;
415
- defStore.columns = this.parseColumns(column.getColumns());
416
- }else{
417
- defStore.field = column.getField();
418
-
419
- if(this.config.columns === true || this.config.columns == undefined){
420
- keys = Object.keys(colDef);
421
- keys.push("width");
422
- keys.push("visible");
423
- }else{
424
- keys = this.config.columns;
425
- }
426
-
427
- keys.forEach((key)=>{
428
- switch(key){
429
- case "width":
430
- defStore.width = column.getWidth();
431
- break;
432
- case "visible":
433
- defStore.visible = column.visible;
434
- break;
435
-
436
- default:
437
- if(typeof colDef[key] !== "function" && excludedKeys.indexOf(key) === -1){
438
- defStore[key] = colDef[key];
439
- }
440
- }
441
- });
442
- }
443
-
444
- definitions.push(defStore);
445
- });
446
-
447
- return definitions;
448
- }
449
- }
450
-
451
- Persistence.moduleName = "persistence";
452
-
453
- Persistence.moduleInitOrder = -10;
454
-
455
- //load defaults
456
- Persistence.readers = defaultReaders;
457
- Persistence.writers = defaultWriters;
458
-
1
+ import Module from '../../core/Module.js';
2
+
3
+ import defaultReaders from './defaults/readers.js';
4
+ import defaultWriters from './defaults/writers.js';
5
+
6
+ class Persistence extends Module{
7
+
8
+ constructor(table){
9
+ super(table);
10
+
11
+ this.mode = "";
12
+ this.id = "";
13
+ // this.persistProps = ["field", "width", "visible"];
14
+ this.defWatcherBlock = false;
15
+ this.config = {};
16
+ this.readFunc = false;
17
+ this.writeFunc = false;
18
+
19
+ this.registerTableOption("persistence", false);
20
+ this.registerTableOption("persistenceID", ""); //key for persistent storage
21
+ this.registerTableOption("persistenceMode", true); //mode for storing persistence information
22
+ this.registerTableOption("persistenceReaderFunc", false); //function for handling persistence data reading
23
+ this.registerTableOption("persistenceWriterFunc", false); //function for handling persistence data writing
24
+ }
25
+
26
+ // Test for whether localStorage is available for use.
27
+ localStorageTest() {
28
+ var testKey = "_tabulator_test";
29
+
30
+ try {
31
+ window.localStorage.setItem( testKey, testKey);
32
+ window.localStorage.removeItem( testKey );
33
+ return true;
34
+ } catch(e) {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ //setup parameters
40
+ initialize(){
41
+ if(this.table.options.persistence){
42
+ //determine persistent layout storage type
43
+ var mode = this.table.options.persistenceMode,
44
+ id = this.table.options.persistenceID,
45
+ retrievedData;
46
+
47
+ this.mode = mode !== true ? mode : (this.localStorageTest() ? "local" : "cookie");
48
+
49
+ if(this.table.options.persistenceReaderFunc){
50
+ if(typeof this.table.options.persistenceReaderFunc === "function"){
51
+ this.readFunc = this.table.options.persistenceReaderFunc;
52
+ }else{
53
+ if(Persistence.readers[this.table.options.persistenceReaderFunc]){
54
+ this.readFunc = Persistence.readers[this.table.options.persistenceReaderFunc];
55
+ }else{
56
+ console.warn("Persistence Read Error - invalid reader set", this.table.options.persistenceReaderFunc);
57
+ }
58
+ }
59
+ }else{
60
+ if(Persistence.readers[this.mode]){
61
+ this.readFunc = Persistence.readers[this.mode];
62
+ }else{
63
+ console.warn("Persistence Read Error - invalid reader set", this.mode);
64
+ }
65
+ }
66
+
67
+ if(this.table.options.persistenceWriterFunc){
68
+ if(typeof this.table.options.persistenceWriterFunc === "function"){
69
+ this.writeFunc = this.table.options.persistenceWriterFunc;
70
+ }else{
71
+ if(Persistence.writers[this.table.options.persistenceWriterFunc]){
72
+ this.writeFunc = Persistence.writers[this.table.options.persistenceWriterFunc];
73
+ }else{
74
+ console.warn("Persistence Write Error - invalid reader set", this.table.options.persistenceWriterFunc);
75
+ }
76
+ }
77
+ }else{
78
+ if(Persistence.writers[this.mode]){
79
+ this.writeFunc = Persistence.writers[this.mode];
80
+ }else{
81
+ console.warn("Persistence Write Error - invalid writer set", this.mode);
82
+ }
83
+ }
84
+
85
+ //set storage tag
86
+ this.id = "tabulator-" + (id || (this.table.element.getAttribute("id") || ""));
87
+
88
+ this.config = {
89
+ sort:this.table.options.persistence === true || this.table.options.persistence.sort,
90
+ filter:this.table.options.persistence === true || this.table.options.persistence.filter,
91
+ headerFilter:this.table.options.persistence === true || this.table.options.persistence.headerFilter,
92
+ group:this.table.options.persistence === true || this.table.options.persistence.group,
93
+ page:this.table.options.persistence === true || this.table.options.persistence.page,
94
+ columns:this.table.options.persistence === true ? ["title", "width", "visible"] : this.table.options.persistence.columns,
95
+ };
96
+
97
+ //load pagination data if needed
98
+ if(this.config.page){
99
+ retrievedData = this.retrieveData("page");
100
+
101
+ if(retrievedData){
102
+ if(typeof retrievedData.paginationSize !== "undefined" && (this.config.page === true || this.config.page.size)){
103
+ this.table.options.paginationSize = retrievedData.paginationSize;
104
+ }
105
+
106
+ if(typeof retrievedData.paginationInitialPage !== "undefined" && (this.config.page === true || this.config.page.page)){
107
+ this.table.options.paginationInitialPage = retrievedData.paginationInitialPage;
108
+ }
109
+ }
110
+ }
111
+
112
+ //load group data if needed
113
+ if(this.config.group){
114
+ retrievedData = this.retrieveData("group");
115
+
116
+ if(retrievedData){
117
+ if(typeof retrievedData.groupBy !== "undefined" && (this.config.group === true || this.config.group.groupBy)){
118
+ this.table.options.groupBy = retrievedData.groupBy;
119
+ }
120
+ if(typeof retrievedData.groupStartOpen !== "undefined" && (this.config.group === true || this.config.group.groupStartOpen)){
121
+ this.table.options.groupStartOpen = retrievedData.groupStartOpen;
122
+ }
123
+ if(typeof retrievedData.groupHeader !== "undefined" && (this.config.group === true || this.config.group.groupHeader)){
124
+ this.table.options.groupHeader = retrievedData.groupHeader;
125
+ }
126
+ }
127
+ }
128
+
129
+ if(this.config.columns){
130
+ this.table.options.columns = this.load("columns", this.table.options.columns);
131
+ this.subscribe("column-init", this.initializeColumn.bind(this));
132
+ this.subscribe("column-show", this.save.bind(this, "columns"));
133
+ this.subscribe("column-hide", this.save.bind(this, "columns"));
134
+ this.subscribe("column-moved", this.save.bind(this, "columns"));
135
+ }
136
+
137
+ this.subscribe("table-built", this.tableBuilt.bind(this), 0);
138
+
139
+ this.subscribe("table-redraw", this.tableRedraw.bind(this));
140
+
141
+ this.subscribe("filter-changed", this.eventSave.bind(this, "filter"));
142
+ this.subscribe("filter-changed", this.eventSave.bind(this, "headerFilter"));
143
+ this.subscribe("sort-changed", this.eventSave.bind(this, "sort"));
144
+ this.subscribe("group-changed", this.eventSave.bind(this, "group"));
145
+ this.subscribe("page-changed", this.eventSave.bind(this, "page"));
146
+ this.subscribe("column-resized", this.eventSave.bind(this, "columns"));
147
+ this.subscribe("column-width", this.eventSave.bind(this, "columns"));
148
+ this.subscribe("layout-refreshed", this.eventSave.bind(this, "columns"));
149
+ }
150
+
151
+ this.registerTableFunction("getColumnLayout", this.getColumnLayout.bind(this));
152
+ this.registerTableFunction("setColumnLayout", this.setColumnLayout.bind(this));
153
+ }
154
+
155
+ eventSave(type){
156
+ if(this.config[type]){
157
+ this.save(type);
158
+ }
159
+ }
160
+
161
+ tableBuilt(){
162
+ var sorters, filters, headerFilters;
163
+
164
+ if(this.config.sort){
165
+ sorters = this.load("sort");
166
+
167
+ if(!sorters === false){
168
+ this.table.options.initialSort = sorters;
169
+ }
170
+ }
171
+
172
+ if(this.config.filter){
173
+ filters = this.load("filter");
174
+
175
+ if(!filters === false){
176
+ this.table.options.initialFilter = filters;
177
+ }
178
+ }
179
+ if(this.config.headerFilter){
180
+ headerFilters = this.load("headerFilter");
181
+
182
+ if(!headerFilters === false){
183
+ this.table.options.initialHeaderFilter = headerFilters;
184
+ }
185
+ }
186
+
187
+ }
188
+
189
+ tableRedraw(force){
190
+ if(force && this.config.columns){
191
+ this.save("columns");
192
+ }
193
+ }
194
+
195
+ ///////////////////////////////////
196
+ ///////// Table Functions /////////
197
+ ///////////////////////////////////
198
+
199
+ getColumnLayout(){
200
+ return this.parseColumns(this.table.columnManager.getColumns());
201
+ }
202
+
203
+ setColumnLayout(layout){
204
+ this.table.columnManager.setColumns(this.mergeDefinition(this.table.options.columns, layout));
205
+ return true;
206
+ }
207
+
208
+ ///////////////////////////////////
209
+ ///////// Internal Logic //////////
210
+ ///////////////////////////////////
211
+
212
+ initializeColumn(column){
213
+ var def, keys;
214
+
215
+ if(this.config.columns){
216
+ this.defWatcherBlock = true;
217
+
218
+ def = column.getDefinition();
219
+
220
+ keys = this.config.columns === true ? Object.keys(def) : this.config.columns;
221
+
222
+ keys.forEach((key)=>{
223
+ var props = Object.getOwnPropertyDescriptor(def, key);
224
+ var value = def[key];
225
+
226
+ if(props){
227
+ Object.defineProperty(def, key, {
228
+ set: (newValue) => {
229
+ value = newValue;
230
+
231
+ if(!this.defWatcherBlock){
232
+ this.save("columns");
233
+ }
234
+
235
+ if(props.set){
236
+ props.set(newValue);
237
+ }
238
+ },
239
+ get:() => {
240
+ if(props.get){
241
+ props.get();
242
+ }
243
+ return value;
244
+ }
245
+ });
246
+ }
247
+ });
248
+
249
+ this.defWatcherBlock = false;
250
+ }
251
+ }
252
+
253
+ //load saved definitions
254
+ load(type, current){
255
+ var data = this.retrieveData(type);
256
+
257
+ if(current){
258
+ data = data ? this.mergeDefinition(current, data) : current;
259
+ }
260
+
261
+ return data;
262
+ }
263
+
264
+ //retrieve data from memory
265
+ retrieveData(type){
266
+ return this.readFunc ? this.readFunc(this.id, type) : false;
267
+ }
268
+
269
+ //merge old and new column definitions
270
+ mergeDefinition(oldCols, newCols){
271
+ var output = [];
272
+
273
+ newCols = newCols || [];
274
+
275
+ newCols.forEach((column, to) => {
276
+ var from = this._findColumn(oldCols, column),
277
+ keys;
278
+
279
+ if(from){
280
+ if(this.config.columns === true || this.config.columns == undefined){
281
+ keys = Object.keys(from);
282
+ keys.push("width");
283
+ }else{
284
+ keys = this.config.columns;
285
+ }
286
+
287
+ keys.forEach((key)=>{
288
+ if(key !== "columns" && typeof column[key] !== "undefined"){
289
+ from[key] = column[key];
290
+ }
291
+ });
292
+
293
+ if(from.columns){
294
+ from.columns = this.mergeDefinition(from.columns, column.columns);
295
+ }
296
+
297
+ output.push(from);
298
+ }
299
+ });
300
+
301
+ oldCols.forEach((column, i) => {
302
+ var from = this._findColumn(newCols, column);
303
+
304
+ if (!from) {
305
+ if(output.length>i){
306
+ output.splice(i, 0, column);
307
+ }else{
308
+ output.push(column);
309
+ }
310
+ }
311
+ });
312
+
313
+ return output;
314
+ }
315
+
316
+ //find matching columns
317
+ _findColumn(columns, subject){
318
+ var type = subject.columns ? "group" : (subject.field ? "field" : "object");
319
+
320
+ return columns.find(function(col){
321
+ switch(type){
322
+ case "group":
323
+ return col.title === subject.title && col.columns.length === subject.columns.length;
324
+
325
+ case "field":
326
+ return col.field === subject.field;
327
+
328
+ case "object":
329
+ return col === subject;
330
+ }
331
+ });
332
+ }
333
+
334
+ //save data
335
+ save(type){
336
+ var data = {};
337
+
338
+ switch(type){
339
+ case "columns":
340
+ data = this.parseColumns(this.table.columnManager.getColumns());
341
+ break;
342
+
343
+ case "filter":
344
+ data = this.table.modules.filter.getFilters();
345
+ break;
346
+
347
+ case "headerFilter":
348
+ data = this.table.modules.filter.getHeaderFilters();
349
+ break;
350
+
351
+ case "sort":
352
+ data = this.validateSorters(this.table.modules.sort.getSort());
353
+ break;
354
+
355
+ case "group":
356
+ data = this.getGroupConfig();
357
+ break;
358
+
359
+ case "page":
360
+ data = this.getPageConfig();
361
+ break;
362
+ }
363
+
364
+ if(this.writeFunc){
365
+ this.writeFunc(this.id, type, data);
366
+ }
367
+
368
+ }
369
+
370
+ //ensure sorters contain no function data
371
+ validateSorters(data){
372
+ data.forEach(function(item){
373
+ item.column = item.field;
374
+ delete item.field;
375
+ });
376
+
377
+ return data;
378
+ }
379
+
380
+ getGroupConfig(){
381
+ var data = {};
382
+
383
+ if(this.config.group){
384
+ if(this.config.group === true || this.config.group.groupBy){
385
+ data.groupBy = this.table.options.groupBy;
386
+ }
387
+
388
+ if(this.config.group === true || this.config.group.groupStartOpen){
389
+ data.groupStartOpen = this.table.options.groupStartOpen;
390
+ }
391
+
392
+ if(this.config.group === true || this.config.group.groupHeader){
393
+ data.groupHeader = this.table.options.groupHeader;
394
+ }
395
+ }
396
+
397
+ return data;
398
+ }
399
+
400
+ getPageConfig(){
401
+ var data = {};
402
+
403
+ if(this.config.page){
404
+ if(this.config.page === true || this.config.page.size){
405
+ data.paginationSize = this.table.modules.page.getPageSize();
406
+ }
407
+
408
+ if(this.config.page === true || this.config.page.page){
409
+ data.paginationInitialPage = this.table.modules.page.getPage();
410
+ }
411
+ }
412
+
413
+ return data;
414
+ }
415
+
416
+
417
+ //parse columns for data to store
418
+ parseColumns(columns){
419
+ var definitions = [],
420
+ excludedKeys = ["headerContextMenu", "headerMenu", "contextMenu", "clickMenu"];
421
+
422
+ columns.forEach((column) => {
423
+ var defStore = {},
424
+ colDef = column.getDefinition(),
425
+ keys;
426
+
427
+ if(column.isGroup){
428
+ defStore.title = colDef.title;
429
+ defStore.columns = this.parseColumns(column.getColumns());
430
+ }else{
431
+ defStore.field = column.getField();
432
+
433
+ if(this.config.columns === true || this.config.columns == undefined){
434
+ keys = Object.keys(colDef);
435
+ keys.push("width");
436
+ keys.push("visible");
437
+ }else{
438
+ keys = this.config.columns;
439
+ }
440
+
441
+ keys.forEach((key)=>{
442
+ switch(key){
443
+ case "width":
444
+ defStore.width = column.getWidth();
445
+ break;
446
+ case "visible":
447
+ defStore.visible = column.visible;
448
+ break;
449
+
450
+ default:
451
+ if(typeof colDef[key] !== "function" && excludedKeys.indexOf(key) === -1){
452
+ defStore[key] = colDef[key];
453
+ }
454
+ }
455
+ });
456
+ }
457
+
458
+ definitions.push(defStore);
459
+ });
460
+
461
+ return definitions;
462
+ }
463
+ }
464
+
465
+ Persistence.moduleName = "persistence";
466
+
467
+ Persistence.moduleInitOrder = -10;
468
+
469
+ //load defaults
470
+ Persistence.readers = defaultReaders;
471
+ Persistence.writers = defaultWriters;
472
+
459
473
  export default Persistence;