tabulator-tables 6.5.0 → 6.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/dist/js/tabulator.js +1 -1
  2. package/dist/js/tabulator.min.js +1 -1
  3. package/dist/js/tabulator_esm.js +1 -1
  4. package/dist/js/tabulator_esm.min.js +1 -1
  5. package/dist/js/tabulator_esm.min.mjs +1 -1
  6. package/dist/js/tabulator_esm.mjs +1 -1
  7. package/package.json +2 -1
  8. package/src/js/builds/esm.js +16 -0
  9. package/src/js/builds/jquery_wrapper.js +63 -0
  10. package/src/js/builds/usd.js +1 -0
  11. package/src/js/core/ColumnManager.js +789 -0
  12. package/src/js/core/CoreFeature.js +140 -0
  13. package/src/js/core/FooterManager.js +102 -0
  14. package/src/js/core/Module.js +140 -0
  15. package/src/js/core/RowManager.js +1140 -0
  16. package/src/js/core/Tabulator.js +928 -0
  17. package/src/js/core/TabulatorFull.js +21 -0
  18. package/src/js/core/cell/Cell.js +299 -0
  19. package/src/js/core/cell/CellComponent.js +79 -0
  20. package/src/js/core/column/Column.js +978 -0
  21. package/src/js/core/column/ColumnComponent.js +151 -0
  22. package/src/js/core/column/defaults/options.js +18 -0
  23. package/src/js/core/defaults/options.js +66 -0
  24. package/src/js/core/modules/core.js +3 -0
  25. package/src/js/core/modules/optional.js +37 -0
  26. package/src/js/core/rendering/Renderer.js +204 -0
  27. package/src/js/core/rendering/renderers/BasicHorizontal.js +27 -0
  28. package/src/js/core/rendering/renderers/BasicVertical.js +103 -0
  29. package/src/js/core/rendering/renderers/VirtualDomHorizontal.js +587 -0
  30. package/src/js/core/rendering/renderers/VirtualDomVertical.js +642 -0
  31. package/src/js/core/row/PseudoRow.js +47 -0
  32. package/src/js/core/row/Row.js +487 -0
  33. package/src/js/core/row/RowComponent.js +94 -0
  34. package/src/js/core/tools/Alert.js +66 -0
  35. package/src/js/core/tools/ComponentFunctionBinder.js +32 -0
  36. package/src/js/core/tools/DataLoader.js +128 -0
  37. package/src/js/core/tools/DependencyRegistry.js +82 -0
  38. package/src/js/core/tools/DeprecationAdvisor.js +51 -0
  39. package/src/js/core/tools/ExternalEventBus.js +105 -0
  40. package/src/js/core/tools/Helpers.js +66 -0
  41. package/src/js/core/tools/InteractionMonitor.js +329 -0
  42. package/src/js/core/tools/InternalEventBus.js +162 -0
  43. package/src/js/core/tools/ModuleBinder.js +153 -0
  44. package/src/js/core/tools/OptionsList.js +45 -0
  45. package/src/js/core/tools/Popup.js +317 -0
  46. package/src/js/core/tools/TableRegistry.js +65 -0
  47. package/src/js/modules/Accessor/Accessor.js +115 -0
  48. package/src/js/modules/Accessor/defaults/accessors.js +5 -0
  49. package/src/js/modules/Ajax/Ajax.js +142 -0
  50. package/src/js/modules/Ajax/defaults/config.js +3 -0
  51. package/src/js/modules/Ajax/defaults/contentTypeFormatters.js +45 -0
  52. package/src/js/modules/Ajax/defaults/loaderPromise.js +87 -0
  53. package/src/js/modules/Ajax/defaults/urlGenerator.js +44 -0
  54. package/src/js/modules/Clipboard/Clipboard.js +282 -0
  55. package/src/js/modules/Clipboard/defaults/pasteActions.js +11 -0
  56. package/src/js/modules/Clipboard/defaults/pasteParsers.js +75 -0
  57. package/src/js/modules/Clipboard/extensions/extensions.js +9 -0
  58. package/src/js/modules/Clipboard/extensions/keybindings/actions.js +9 -0
  59. package/src/js/modules/Clipboard/extensions/keybindings/bindings.js +3 -0
  60. package/src/js/modules/ColumnCalcs/CalcComponent.js +46 -0
  61. package/src/js/modules/ColumnCalcs/ColumnCalcs.js +586 -0
  62. package/src/js/modules/ColumnCalcs/defaults/calculations.js +93 -0
  63. package/src/js/modules/Comms/Comms.js +49 -0
  64. package/src/js/modules/DataTree/DataTree.js +620 -0
  65. package/src/js/modules/Download/Download.js +146 -0
  66. package/src/js/modules/Download/defaults/downloaders/csv.js +61 -0
  67. package/src/js/modules/Download/defaults/downloaders/html.js +5 -0
  68. package/src/js/modules/Download/defaults/downloaders/json.js +34 -0
  69. package/src/js/modules/Download/defaults/downloaders/jsonLines.js +32 -0
  70. package/src/js/modules/Download/defaults/downloaders/pdf.js +113 -0
  71. package/src/js/modules/Download/defaults/downloaders/xlsx.js +103 -0
  72. package/src/js/modules/Download/defaults/downloaders.js +15 -0
  73. package/src/js/modules/Edit/Edit.js +845 -0
  74. package/src/js/modules/Edit/List.js +1060 -0
  75. package/src/js/modules/Edit/defaults/editors/adaptable.js +37 -0
  76. package/src/js/modules/Edit/defaults/editors/date.js +144 -0
  77. package/src/js/modules/Edit/defaults/editors/datetime.js +131 -0
  78. package/src/js/modules/Edit/defaults/editors/input.js +77 -0
  79. package/src/js/modules/Edit/defaults/editors/list.js +7 -0
  80. package/src/js/modules/Edit/defaults/editors/number.js +110 -0
  81. package/src/js/modules/Edit/defaults/editors/progress.js +127 -0
  82. package/src/js/modules/Edit/defaults/editors/range.js +81 -0
  83. package/src/js/modules/Edit/defaults/editors/star.js +146 -0
  84. package/src/js/modules/Edit/defaults/editors/textarea.js +123 -0
  85. package/src/js/modules/Edit/defaults/editors/tickCross.js +95 -0
  86. package/src/js/modules/Edit/defaults/editors/time.js +132 -0
  87. package/src/js/modules/Edit/defaults/editors.js +27 -0
  88. package/src/js/modules/Edit/inputMask.js +74 -0
  89. package/src/js/modules/Export/Export.js +654 -0
  90. package/src/js/modules/Export/ExportColumn.js +9 -0
  91. package/src/js/modules/Export/ExportRow.js +8 -0
  92. package/src/js/modules/Export/defaults/columnLookups.js +3 -0
  93. package/src/js/modules/Export/defaults/rowLookups.js +18 -0
  94. package/src/js/modules/Filter/Filter.js +902 -0
  95. package/src/js/modules/Filter/defaults/filters.js +215 -0
  96. package/src/js/modules/Format/Format.js +200 -0
  97. package/src/js/modules/Format/defaults/formatters/adaptable.js +32 -0
  98. package/src/js/modules/Format/defaults/formatters/array.js +30 -0
  99. package/src/js/modules/Format/defaults/formatters/buttonCross.js +3 -0
  100. package/src/js/modules/Format/defaults/formatters/buttonTick.js +3 -0
  101. package/src/js/modules/Format/defaults/formatters/color.js +4 -0
  102. package/src/js/modules/Format/defaults/formatters/datetime.js +39 -0
  103. package/src/js/modules/Format/defaults/formatters/datetimediff.js +43 -0
  104. package/src/js/modules/Format/defaults/formatters/handle.js +4 -0
  105. package/src/js/modules/Format/defaults/formatters/html.js +3 -0
  106. package/src/js/modules/Format/defaults/formatters/image.js +40 -0
  107. package/src/js/modules/Format/defaults/formatters/json.js +12 -0
  108. package/src/js/modules/Format/defaults/formatters/link.js +82 -0
  109. package/src/js/modules/Format/defaults/formatters/lookup.js +10 -0
  110. package/src/js/modules/Format/defaults/formatters/money.js +44 -0
  111. package/src/js/modules/Format/defaults/formatters/plaintext.js +3 -0
  112. package/src/js/modules/Format/defaults/formatters/progress.js +133 -0
  113. package/src/js/modules/Format/defaults/formatters/rownum.js +14 -0
  114. package/src/js/modules/Format/defaults/formatters/star.js +38 -0
  115. package/src/js/modules/Format/defaults/formatters/textarea.js +4 -0
  116. package/src/js/modules/Format/defaults/formatters/tickCross.js +22 -0
  117. package/src/js/modules/Format/defaults/formatters/toggle.js +48 -0
  118. package/src/js/modules/Format/defaults/formatters/traffic.js +47 -0
  119. package/src/js/modules/Format/defaults/formatters.js +47 -0
  120. package/src/js/modules/FrozenColumns/FrozenColumns.js +302 -0
  121. package/src/js/modules/FrozenRows/FrozenRows.js +175 -0
  122. package/src/js/modules/GroupRows/Group.js +615 -0
  123. package/src/js/modules/GroupRows/GroupComponent.js +69 -0
  124. package/src/js/modules/GroupRows/GroupRows.js +636 -0
  125. package/src/js/modules/History/History.js +172 -0
  126. package/src/js/modules/History/defaults/redoers.js +31 -0
  127. package/src/js/modules/History/defaults/undoers.js +33 -0
  128. package/src/js/modules/History/extensions/extensions.js +9 -0
  129. package/src/js/modules/History/extensions/keybindings/actions.js +27 -0
  130. package/src/js/modules/History/extensions/keybindings/bindings.js +4 -0
  131. package/src/js/modules/HtmlTableImport/HtmlTableImport.js +180 -0
  132. package/src/js/modules/Import/Import.js +303 -0
  133. package/src/js/modules/Import/defaults/importers/array.js +3 -0
  134. package/src/js/modules/Import/defaults/importers/csv.js +61 -0
  135. package/src/js/modules/Import/defaults/importers/json.js +8 -0
  136. package/src/js/modules/Import/defaults/importers/xlsx.js +7 -0
  137. package/src/js/modules/Import/defaults/importers.js +11 -0
  138. package/src/js/modules/Interaction/Interaction.js +339 -0
  139. package/src/js/modules/Keybindings/Keybindings.js +198 -0
  140. package/src/js/modules/Keybindings/defaults/actions.js +90 -0
  141. package/src/js/modules/Keybindings/defaults/bindings.js +12 -0
  142. package/src/js/modules/Layout/Layout.js +66 -0
  143. package/src/js/modules/Layout/defaults/modes/fitColumns.js +171 -0
  144. package/src/js/modules/Layout/defaults/modes/fitData.js +10 -0
  145. package/src/js/modules/Layout/defaults/modes/fitDataGeneral.js +10 -0
  146. package/src/js/modules/Layout/defaults/modes/fitDataStretch.js +40 -0
  147. package/src/js/modules/Layout/defaults/modes.js +12 -0
  148. package/src/js/modules/Localize/Localize.js +184 -0
  149. package/src/js/modules/Localize/defaults/langs.js +37 -0
  150. package/src/js/modules/Menu/Menu.js +302 -0
  151. package/src/js/modules/MoveColumns/MoveColumns.js +311 -0
  152. package/src/js/modules/MoveRows/MoveRows.js +604 -0
  153. package/src/js/modules/MoveRows/defaults/receivers.js +30 -0
  154. package/src/js/modules/MoveRows/defaults/senders.js +5 -0
  155. package/src/js/modules/Mutator/Mutator.js +164 -0
  156. package/src/js/modules/Mutator/defaults/mutators.js +1 -0
  157. package/src/js/modules/Page/Page.js +891 -0
  158. package/src/js/modules/Page/defaults/pageCounters/pages.js +33 -0
  159. package/src/js/modules/Page/defaults/pageCounters/rows.js +40 -0
  160. package/src/js/modules/Page/defaults/pageCounters.js +8 -0
  161. package/src/js/modules/Persistence/Persistence.js +473 -0
  162. package/src/js/modules/Persistence/defaults/readers.js +29 -0
  163. package/src/js/modules/Persistence/defaults/writers.js +13 -0
  164. package/src/js/modules/Popup/Popup.js +227 -0
  165. package/src/js/modules/Print/Print.js +136 -0
  166. package/src/js/modules/ReactiveData/ReactiveData.js +416 -0
  167. package/src/js/modules/ResizeColumns/ResizeColumns.js +365 -0
  168. package/src/js/modules/ResizeRows/ResizeRows.js +145 -0
  169. package/src/js/modules/ResizeTable/ResizeTable.js +158 -0
  170. package/src/js/modules/ResponsiveLayout/ResponsiveLayout.js +354 -0
  171. package/src/js/modules/ResponsiveLayout/extensions/extensions.js +9 -0
  172. package/src/js/modules/ResponsiveLayout/extensions/formatters/responsiveCollapse.js +44 -0
  173. package/src/js/modules/SelectRange/Range.js +366 -0
  174. package/src/js/modules/SelectRange/RangeComponent.js +91 -0
  175. package/src/js/modules/SelectRange/SelectRange.js +993 -0
  176. package/src/js/modules/SelectRange/extensions/clipboard/pasteActions.js +45 -0
  177. package/src/js/modules/SelectRange/extensions/clipboard/pasteParsers.js +57 -0
  178. package/src/js/modules/SelectRange/extensions/export/columnLookups.js +11 -0
  179. package/src/js/modules/SelectRange/extensions/export/rowLookups.js +5 -0
  180. package/src/js/modules/SelectRange/extensions/extensions.js +21 -0
  181. package/src/js/modules/SelectRange/extensions/keybindings/actions.js +38 -0
  182. package/src/js/modules/SelectRange/extensions/keybindings/bindings.js +14 -0
  183. package/src/js/modules/SelectRow/SelectRow.js +499 -0
  184. package/src/js/modules/SelectRow/extensions/extensions.js +9 -0
  185. package/src/js/modules/SelectRow/extensions/formatters/rowSelection.js +60 -0
  186. package/src/js/modules/Sort/Sort.js +480 -0
  187. package/src/js/modules/Sort/defaults/sorters/alphanum.js +44 -0
  188. package/src/js/modules/Sort/defaults/sorters/array.js +82 -0
  189. package/src/js/modules/Sort/defaults/sorters/boolean.js +7 -0
  190. package/src/js/modules/Sort/defaults/sorters/date.js +10 -0
  191. package/src/js/modules/Sort/defaults/sorters/datetime.js +48 -0
  192. package/src/js/modules/Sort/defaults/sorters/exists.js +7 -0
  193. package/src/js/modules/Sort/defaults/sorters/number.js +40 -0
  194. package/src/js/modules/Sort/defaults/sorters/string.js +34 -0
  195. package/src/js/modules/Sort/defaults/sorters/time.js +10 -0
  196. package/src/js/modules/Sort/defaults/sorters.js +21 -0
  197. package/src/js/modules/Spreadsheet/GridCalculator.js +64 -0
  198. package/src/js/modules/Spreadsheet/Sheet.js +243 -0
  199. package/src/js/modules/Spreadsheet/SheetComponent.js +59 -0
  200. package/src/js/modules/Spreadsheet/Spreadsheet.js +309 -0
  201. package/src/js/modules/Tooltip/Tooltip.js +128 -0
  202. package/src/js/modules/Validate/Validate.js +303 -0
  203. package/src/js/modules/Validate/defaults/validators.js +150 -0
  204. package/src/scss/tabulator.scss +1693 -0
  205. package/src/scss/themes/bootstrap/tabulator_bootstrap3.scss +302 -0
  206. package/src/scss/themes/bootstrap/tabulator_bootstrap4.scss +589 -0
  207. package/src/scss/themes/bootstrap/tabulator_bootstrap5.scss +979 -0
  208. package/src/scss/themes/bootstrap/variables3.scss +872 -0
  209. package/src/scss/themes/bootstrap/variables4.scss +1059 -0
  210. package/src/scss/themes/bootstrap/variables5.scss +1967 -0
  211. package/src/scss/themes/bulma/tabulator_bulma.scss +316 -0
  212. package/src/scss/themes/bulma/variables.scss +198 -0
  213. package/src/scss/themes/materialize/tabulator_materialize.scss +318 -0
  214. package/src/scss/themes/materialize/variables.scss +71 -0
  215. package/src/scss/themes/semanticui/tabulator_semanticui.scss +623 -0
  216. package/src/scss/themes/semanticui/variables.scss +843 -0
  217. package/src/scss/themes/semanticui/variables_table.scss +248 -0
  218. package/src/scss/themes/tabulator_midnight.scss +235 -0
  219. package/src/scss/themes/tabulator_modern.scss +308 -0
  220. package/src/scss/themes/tabulator_simple.scss +143 -0
  221. package/src/scss/themes/tabulator_site.scss +267 -0
  222. package/src/scss/themes/tabulator_site_dark.scss +496 -0
@@ -0,0 +1,620 @@
1
+ import Module from '../../core/Module.js';
2
+
3
+ import Row from '../../core/row/Row.js';
4
+
5
+ import RowComponent from '../../core/row/RowComponent.js';
6
+
7
+ export default class DataTree extends Module{
8
+
9
+ static moduleName = "dataTree";
10
+
11
+ constructor(table){
12
+ super(table);
13
+
14
+ this.indent = 10;
15
+ this.field = "";
16
+ this.collapseEl = null;
17
+ this.expandEl = null;
18
+ this.branchEl = null;
19
+ this.elementField = false;
20
+
21
+ this.startOpen = function(){};
22
+
23
+ this.registerTableOption("dataTree", false); //enable data tree
24
+ this.registerTableOption("dataTreeFilter", true); //filter child rows
25
+ this.registerTableOption("dataTreeSort", true); //sort child rows
26
+ this.registerTableOption("dataTreeElementColumn", false);
27
+ this.registerTableOption("dataTreeBranchElement", true);//show data tree branch element
28
+ this.registerTableOption("dataTreeChildIndent", 9); //data tree child indent in px
29
+ this.registerTableOption("dataTreeChildField", "_children");//data tre column field to look for child rows
30
+ this.registerTableOption("dataTreeCollapseElement", false);//data tree row collapse element
31
+ this.registerTableOption("dataTreeExpandElement", false);//data tree row expand element
32
+ this.registerTableOption("dataTreeStartExpanded", false);
33
+ this.registerTableOption("dataTreeChildColumnCalcs", false);//include visible data tree rows in column calculations
34
+ this.registerTableOption("dataTreeSelectPropagate", false);//selecting a parent row selects its children
35
+
36
+ //register component functions
37
+ this.registerComponentFunction("row", "treeCollapse", this.collapseRow.bind(this));
38
+ this.registerComponentFunction("row", "treeExpand", this.expandRow.bind(this));
39
+ this.registerComponentFunction("row", "treeToggle", this.toggleRow.bind(this));
40
+ this.registerComponentFunction("row", "getTreeParent", this.getTreeParent.bind(this));
41
+ this.registerComponentFunction("row", "getTreeChildren", this.getRowChildren.bind(this));
42
+ this.registerComponentFunction("row", "addTreeChild", this.addTreeChildRow.bind(this));
43
+ this.registerComponentFunction("row", "isTreeExpanded", this.isRowExpanded.bind(this));
44
+ }
45
+
46
+ initialize(){
47
+ if(this.table.options.dataTree){
48
+ var dummyEl = null,
49
+ options = this.table.options;
50
+
51
+ this.field = options.dataTreeChildField;
52
+ this.indent = options.dataTreeChildIndent;
53
+
54
+ if(this.options("movableRows")){
55
+ console.warn("The movableRows option is not available with dataTree enabled, moving of child rows could result in unpredictable behavior");
56
+ }
57
+
58
+ if(options.dataTreeBranchElement){
59
+
60
+ if(options.dataTreeBranchElement === true){
61
+ this.branchEl = document.createElement("div");
62
+ this.branchEl.classList.add("tabulator-data-tree-branch");
63
+ }else{
64
+ if(typeof options.dataTreeBranchElement === "string"){
65
+ dummyEl = document.createElement("div");
66
+ dummyEl.innerHTML = options.dataTreeBranchElement;
67
+ this.branchEl = dummyEl.firstChild;
68
+ }else{
69
+ this.branchEl = options.dataTreeBranchElement;
70
+ }
71
+ }
72
+ }else{
73
+ this.branchEl = document.createElement("div");
74
+ this.branchEl.classList.add("tabulator-data-tree-branch-empty");
75
+ }
76
+
77
+ if(options.dataTreeCollapseElement){
78
+ if(typeof options.dataTreeCollapseElement === "string"){
79
+ dummyEl = document.createElement("div");
80
+ dummyEl.innerHTML = options.dataTreeCollapseElement;
81
+ this.collapseEl = dummyEl.firstChild;
82
+ }else{
83
+ this.collapseEl = options.dataTreeCollapseElement;
84
+ }
85
+ }else{
86
+ this.collapseEl = document.createElement("div");
87
+ this.collapseEl.classList.add("tabulator-data-tree-control");
88
+ this.collapseEl.tabIndex = 0;
89
+ this.collapseEl.innerHTML = "<div class='tabulator-data-tree-control-collapse'></div>";
90
+ }
91
+
92
+ if(options.dataTreeExpandElement){
93
+ if(typeof options.dataTreeExpandElement === "string"){
94
+ dummyEl = document.createElement("div");
95
+ dummyEl.innerHTML = options.dataTreeExpandElement;
96
+ this.expandEl = dummyEl.firstChild;
97
+ }else{
98
+ this.expandEl = options.dataTreeExpandElement;
99
+ }
100
+ }else{
101
+ this.expandEl = document.createElement("div");
102
+ this.expandEl.classList.add("tabulator-data-tree-control");
103
+ this.expandEl.tabIndex = 0;
104
+ this.expandEl.innerHTML = "<div class='tabulator-data-tree-control-expand'></div>";
105
+ }
106
+
107
+
108
+ switch(typeof options.dataTreeStartExpanded){
109
+ case "boolean":
110
+ this.startOpen = function(row, index){
111
+ return options.dataTreeStartExpanded;
112
+ };
113
+ break;
114
+
115
+ case "function":
116
+ this.startOpen = options.dataTreeStartExpanded;
117
+ break;
118
+
119
+ default:
120
+ this.startOpen = function(row, index){
121
+ return options.dataTreeStartExpanded[index];
122
+ };
123
+ break;
124
+ }
125
+
126
+ this.subscribe("row-init", this.initializeRow.bind(this));
127
+ this.subscribe("row-layout-after", this.layoutRow.bind(this));
128
+ this.subscribe("row-deleting", this.rowDeleting.bind(this));
129
+ this.subscribe("row-deleted", this.rowDelete.bind(this),0);
130
+ this.subscribe("row-data-changed", this.rowDataChanged.bind(this), 10);
131
+ this.subscribe("cell-value-updated", this.cellValueChanged.bind(this));
132
+ this.subscribe("edit-cancelled", this.cellValueChanged.bind(this));
133
+ this.subscribe("column-moving-rows", this.columnMoving.bind(this));
134
+ this.subscribe("table-built", this.initializeElementField.bind(this));
135
+ this.subscribe("table-redrawing", this.tableRedrawing.bind(this));
136
+
137
+ this.registerDisplayHandler(this.getRows.bind(this), 30);
138
+ }
139
+ }
140
+
141
+ tableRedrawing(force){
142
+ var rows;
143
+
144
+ if(force){
145
+ rows = this.table.rowManager.getRows();
146
+
147
+ rows.forEach((row) => {
148
+ this.reinitializeRowChildren(row);
149
+ });
150
+ }
151
+ }
152
+
153
+ initializeElementField(){
154
+ var firstCol = this.table.columnManager.getFirstVisibleColumn();
155
+
156
+ this.elementField = this.table.options.dataTreeElementColumn || (firstCol ? firstCol.field : false);
157
+ }
158
+
159
+ getRowChildren(row){
160
+ return this.getTreeChildren(row, true);
161
+ }
162
+
163
+ columnMoving(){
164
+ var rows = [];
165
+
166
+ this.table.rowManager.rows.forEach((row) => {
167
+ rows = rows.concat(this.getTreeChildren(row, false, true));
168
+ });
169
+
170
+ return rows;
171
+ }
172
+
173
+ rowDataChanged(row, visible, updatedData){
174
+ if(this.redrawNeeded(updatedData)){
175
+ this.initializeRow(row);
176
+
177
+ if(visible){
178
+ this.layoutRow(row);
179
+ this.refreshData(true);
180
+ }
181
+ }
182
+ }
183
+
184
+ cellValueChanged(cell){
185
+ var field = cell.column.getField();
186
+
187
+ if(field === this.elementField){
188
+ this.layoutRow(cell.row);
189
+ }
190
+ }
191
+
192
+ initializeRow(row){
193
+ var childArray = row.getData()[this.field];
194
+ var isArray = Array.isArray(childArray);
195
+
196
+ var children = isArray || (!isArray && typeof childArray === "object" && childArray !== null);
197
+
198
+ if(!children && row.modules.dataTree && row.modules.dataTree.branchEl && row.modules.dataTree.branchEl.parentNode){
199
+ row.modules.dataTree.branchEl.parentNode.removeChild(row.modules.dataTree.branchEl);
200
+ }
201
+
202
+ if(!children && row.modules.dataTree && row.modules.dataTree.controlEl && row.modules.dataTree.controlEl.parentNode){
203
+ row.modules.dataTree.controlEl.parentNode.removeChild(row.modules.dataTree.controlEl);
204
+ }
205
+
206
+ row.modules.dataTree = {
207
+ index: row.modules.dataTree ? row.modules.dataTree.index : 0,
208
+ open: children ? (row.modules.dataTree ? row.modules.dataTree.open : this.startOpen(row.getComponent(), 0)) : false,
209
+ controlEl: row.modules.dataTree && children ? row.modules.dataTree.controlEl : false,
210
+ branchEl: row.modules.dataTree && children ? row.modules.dataTree.branchEl : false,
211
+ parent: row.modules.dataTree ? row.modules.dataTree.parent : false,
212
+ children:children,
213
+ };
214
+ }
215
+
216
+ reinitializeRowChildren(row){
217
+ var children = this.getTreeChildren(row, false, true);
218
+
219
+ children.forEach(function(child){
220
+ child.reinitialize(true);
221
+ });
222
+ }
223
+
224
+ layoutRow(row){
225
+ var cell = this.elementField ? row.getCell(this.elementField) : row.getCells()[0],
226
+ el = cell.getElement(),
227
+ config = row.modules.dataTree;
228
+
229
+ if(config.branchEl){
230
+ if(config.branchEl.parentNode){
231
+ config.branchEl.parentNode.removeChild(config.branchEl);
232
+ }
233
+ config.branchEl = false;
234
+ }
235
+
236
+ if(config.controlEl){
237
+ if(config.controlEl.parentNode){
238
+ config.controlEl.parentNode.removeChild(config.controlEl);
239
+ }
240
+ config.controlEl = false;
241
+ }
242
+
243
+ this.generateControlElement(row, el);
244
+
245
+ row.getElement().classList.add("tabulator-tree-level-" + config.index);
246
+
247
+ if(config.index){
248
+ if(this.branchEl){
249
+ config.branchEl = this.branchEl.cloneNode(true);
250
+ el.insertBefore(config.branchEl, el.firstChild);
251
+
252
+ if(this.table.rtl){
253
+ config.branchEl.style.marginRight = (((config.branchEl.offsetWidth + config.branchEl.style.marginLeft) * (config.index - 1)) + (config.index * this.indent)) + "px";
254
+ }else{
255
+ config.branchEl.style.marginLeft = (((config.branchEl.offsetWidth + config.branchEl.style.marginRight) * (config.index - 1)) + (config.index * this.indent)) + "px";
256
+ }
257
+ }else{
258
+
259
+ if(this.table.rtl){
260
+ el.style.paddingRight = parseInt(window.getComputedStyle(el, null).getPropertyValue('padding-right')) + (config.index * this.indent) + "px";
261
+ }else{
262
+ el.style.paddingLeft = parseInt(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + (config.index * this.indent) + "px";
263
+ }
264
+ }
265
+ }
266
+ }
267
+
268
+ generateControlElement(row, el){
269
+ var config = row.modules.dataTree,
270
+ oldControl = config.controlEl;
271
+
272
+ el = el || row.getCells()[0].getElement();
273
+
274
+ if(config.children !== false){
275
+
276
+ if(config.open){
277
+ config.controlEl = this.collapseEl.cloneNode(true);
278
+ config.controlEl.addEventListener("click", (e) => {
279
+ e.stopPropagation();
280
+ this.collapseRow(row);
281
+ });
282
+ }else{
283
+ config.controlEl = this.expandEl.cloneNode(true);
284
+ config.controlEl.addEventListener("click", (e) => {
285
+ e.stopPropagation();
286
+ this.expandRow(row);
287
+ });
288
+ }
289
+
290
+ config.controlEl.addEventListener("mousedown", (e) => {
291
+ e.stopPropagation();
292
+ });
293
+
294
+ if(oldControl && oldControl.parentNode === el){
295
+ oldControl.parentNode.replaceChild(config.controlEl,oldControl);
296
+ }else{
297
+ el.insertBefore(config.controlEl, el.firstChild);
298
+ }
299
+ }
300
+ }
301
+
302
+ getRows(rows){
303
+ var output = [];
304
+
305
+ rows.forEach((row, i) => {
306
+ var config, children;
307
+
308
+ output.push(row);
309
+
310
+ if(row instanceof Row){
311
+
312
+ row.create();
313
+
314
+ config = row.modules.dataTree;
315
+
316
+ if(!config.index && config.children !== false){
317
+ children = this.getChildren(row, false, true);
318
+
319
+ children.forEach((child) => {
320
+ child.create();
321
+ output.push(child);
322
+ });
323
+ }
324
+ }
325
+ });
326
+
327
+ return output;
328
+ }
329
+
330
+ getChildren(row, allChildren, sortOnly){
331
+ var config = row.modules.dataTree,
332
+ children = [],
333
+ output = [];
334
+
335
+ if(config.children !== false && (config.open || allChildren)){
336
+ if(!Array.isArray(config.children)){
337
+ config.children = this.generateChildren(row);
338
+ }
339
+
340
+ if(this.table.modExists("filter") && this.table.options.dataTreeFilter){
341
+ children = this.table.modules.filter.filter(config.children);
342
+ }else{
343
+ children = config.children;
344
+ }
345
+
346
+ if(this.table.modExists("sort") && this.table.options.dataTreeSort){
347
+ this.table.modules.sort.sort(children, sortOnly);
348
+ }
349
+
350
+ children.forEach((child) => {
351
+ output.push(child);
352
+
353
+ var subChildren = this.getChildren(child, false, true);
354
+
355
+ subChildren.forEach((sub) => {
356
+ output.push(sub);
357
+ });
358
+ });
359
+ }
360
+
361
+ return output;
362
+ }
363
+
364
+ generateChildren(row){
365
+ var children = [];
366
+
367
+ var childArray = row.getData()[this.field];
368
+
369
+ if(!Array.isArray(childArray)){
370
+ childArray = [childArray];
371
+ }
372
+
373
+ childArray.forEach((childData) => {
374
+ var childRow = new Row(childData || {}, this.table.rowManager);
375
+
376
+ childRow.create();
377
+
378
+ childRow.modules.dataTree.index = row.modules.dataTree.index + 1;
379
+ childRow.modules.dataTree.parent = row;
380
+
381
+ if(childRow.modules.dataTree.children){
382
+ childRow.modules.dataTree.open = this.startOpen(childRow.getComponent(), childRow.modules.dataTree.index);
383
+ }
384
+ children.push(childRow);
385
+ });
386
+
387
+ return children;
388
+ }
389
+
390
+ expandRow(row, silent){
391
+ var config = row.modules.dataTree;
392
+
393
+ if(config.children !== false){
394
+ config.open = true;
395
+
396
+ row.reinitialize();
397
+
398
+ this.refreshData(true);
399
+
400
+ this.dispatchExternal("dataTreeRowExpanded", row.getComponent(), row.modules.dataTree.index);
401
+ }
402
+ }
403
+
404
+ collapseRow(row){
405
+ var config = row.modules.dataTree;
406
+
407
+ if(config.children !== false){
408
+ config.open = false;
409
+
410
+ row.reinitialize();
411
+
412
+ this.refreshData(true);
413
+
414
+ this.dispatchExternal("dataTreeRowCollapsed", row.getComponent(), row.modules.dataTree.index);
415
+ }
416
+ }
417
+
418
+ toggleRow(row){
419
+ var config = row.modules.dataTree;
420
+
421
+ if(config.children !== false){
422
+ if(config.open){
423
+ this.collapseRow(row);
424
+ }else{
425
+ this.expandRow(row);
426
+ }
427
+ }
428
+ }
429
+
430
+ isRowExpanded(row){
431
+ return row.modules.dataTree.open;
432
+ }
433
+
434
+ getTreeParent(row){
435
+ return row.modules.dataTree.parent ? row.modules.dataTree.parent.getComponent() : false;
436
+ }
437
+
438
+ getTreeParentRoot(row){
439
+ return row.modules.dataTree && row.modules.dataTree.parent ? this.getTreeParentRoot(row.modules.dataTree.parent) : row;
440
+ }
441
+
442
+ getFilteredTreeChildren(row){
443
+ var config = row.modules.dataTree,
444
+ output = [], children;
445
+
446
+ if(config.children){
447
+
448
+ if(!Array.isArray(config.children)){
449
+ config.children = this.generateChildren(row);
450
+ }
451
+
452
+ if(this.table.modExists("filter") && this.table.options.dataTreeFilter){
453
+ children = this.table.modules.filter.filter(config.children);
454
+ }else{
455
+ children = config.children;
456
+ }
457
+
458
+ children.forEach((childRow) => {
459
+ if(childRow instanceof Row){
460
+ output.push(childRow);
461
+ }
462
+ });
463
+ }
464
+
465
+ return output;
466
+ }
467
+
468
+ rowDeleting(row){
469
+ var config = row.modules.dataTree;
470
+
471
+ if (config && config.children && Array.isArray(config.children)){
472
+ config.children.forEach((childRow) => {
473
+ if(childRow instanceof Row){
474
+ childRow.wipe();
475
+ }
476
+ });
477
+ }
478
+ }
479
+
480
+ rowDelete(row){
481
+ var parent = row.modules.dataTree.parent,
482
+ childIndex;
483
+
484
+ if(parent){
485
+ childIndex = this.findChildIndex(row, parent);
486
+
487
+ if(childIndex !== false){
488
+ parent.data[this.field].splice(childIndex, 1);
489
+ }
490
+
491
+ if(!parent.data[this.field].length){
492
+ delete parent.data[this.field];
493
+ }
494
+
495
+ this.initializeRow(parent);
496
+ this.layoutRow(parent);
497
+ }
498
+
499
+ this.refreshData(true);
500
+ }
501
+
502
+ addTreeChildRow(row, data, top, index){
503
+ var childIndex = false;
504
+
505
+ if(typeof data === "string"){
506
+ data = JSON.parse(data);
507
+ }
508
+
509
+ if(!Array.isArray(row.data[this.field])){
510
+ row.data[this.field] = [];
511
+
512
+ row.modules.dataTree.open = this.startOpen(row.getComponent(), row.modules.dataTree.index);
513
+ }
514
+
515
+ if(typeof index !== "undefined"){
516
+ childIndex = this.findChildIndex(index, row);
517
+
518
+ if(childIndex !== false){
519
+ row.data[this.field].splice((top ? childIndex : childIndex + 1), 0, data);
520
+ }
521
+ }
522
+
523
+ if(childIndex === false){
524
+ if(top){
525
+ row.data[this.field].unshift(data);
526
+ }else{
527
+ row.data[this.field].push(data);
528
+ }
529
+ }
530
+
531
+ this.initializeRow(row);
532
+ this.layoutRow(row);
533
+
534
+ this.refreshData(true);
535
+ }
536
+
537
+ findChildIndex(subject, parent){
538
+ var match = false;
539
+
540
+ if(typeof subject == "object"){
541
+
542
+ if(subject instanceof Row){
543
+ //subject is row element
544
+ match = subject.data;
545
+ }else if(subject instanceof RowComponent){
546
+ //subject is public row component
547
+ match = subject._getSelf().data;
548
+ }else if(typeof HTMLElement !== "undefined" && subject instanceof HTMLElement){
549
+ if(parent.modules.dataTree){
550
+ match = parent.modules.dataTree.children.find((childRow) => {
551
+ return childRow instanceof Row ? childRow.element === subject : false;
552
+ });
553
+
554
+ if(match){
555
+ match = match.data;
556
+ }
557
+ }
558
+ }else if(subject === null){
559
+ match = false;
560
+ }
561
+
562
+ }else if(typeof subject == "undefined"){
563
+ match = false;
564
+ }else{
565
+ //subject should be treated as the index of the row
566
+ match = parent.data[this.field].find((row) => {
567
+ return row.data[this.table.options.index] == subject;
568
+ });
569
+ }
570
+
571
+ if(match){
572
+
573
+ if(Array.isArray(parent.data[this.field])){
574
+ match = parent.data[this.field].indexOf(match);
575
+ }
576
+
577
+ if(match == -1){
578
+ match = false;
579
+ }
580
+ }
581
+
582
+ //catch all for any other type of input
583
+
584
+ return match;
585
+ }
586
+
587
+ getTreeChildren(row, component, recurse){
588
+ var config = row.modules.dataTree,
589
+ output = [];
590
+
591
+ if(config && config.children){
592
+
593
+ if(!Array.isArray(config.children)){
594
+ config.children = this.generateChildren(row);
595
+ }
596
+
597
+ config.children.forEach((childRow) => {
598
+ if(childRow instanceof Row){
599
+ output.push(component ? childRow.getComponent() : childRow);
600
+
601
+ if(recurse){
602
+ this.getTreeChildren(childRow, component, recurse).forEach(child => {
603
+ output.push(child);
604
+ });
605
+ }
606
+ }
607
+ });
608
+ }
609
+
610
+ return output;
611
+ }
612
+
613
+ getChildField(){
614
+ return this.field;
615
+ }
616
+
617
+ redrawNeeded(data){
618
+ return (this.field ? typeof data[this.field] !== "undefined" : false) || (this.elementField ? typeof data[this.elementField] !== "undefined" : false);
619
+ }
620
+ }