x4js 1.4.51 → 1.4.53

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 (305) hide show
  1. package/lib/{action.js → cjs/action.js} +0 -0
  2. package/lib/{application.js → cjs/application.js} +13 -19
  3. package/lib/{autocomplete.js → cjs/autocomplete.js} +0 -4
  4. package/lib/cjs/base_component.js +124 -0
  5. package/lib/{button.js → cjs/button.js} +4 -4
  6. package/lib/{calendar.js → cjs/calendar.js} +22 -22
  7. package/lib/{canvas.js → cjs/canvas.js} +7 -8
  8. package/lib/{cardview.js → cjs/cardview.js} +3 -5
  9. package/lib/{checkbox.js → cjs/checkbox.js} +6 -5
  10. package/lib/cjs/color.js +591 -0
  11. package/lib/{colorpicker.js → cjs/colorpicker.js} +1 -14
  12. package/lib/{combobox.js → cjs/combobox.js} +2 -6
  13. package/lib/{component.js → cjs/component.js} +20 -41
  14. package/lib/{datastore.js → cjs/datastore.js} +18 -32
  15. package/lib/{dialog.js → cjs/dialog.js} +4 -21
  16. package/lib/{dom_events.js → cjs/dom_events.js} +0 -0
  17. package/lib/{drag_manager.js → cjs/drag_manager.js} +0 -5
  18. package/lib/{drawtext.js → cjs/drawtext.js} +5 -4
  19. package/lib/{fileupload.js → cjs/fileupload.js} +0 -3
  20. package/lib/{form.js → cjs/form.js} +2 -6
  21. package/lib/{formatters.js → cjs/formatters.js} +0 -0
  22. package/lib/{gridview.js → cjs/gridview.js} +20 -33
  23. package/lib/{i18n.js → cjs/i18n.js} +0 -0
  24. package/lib/{icon.js → cjs/icon.js} +17 -11
  25. package/lib/{image.js → cjs/image.js} +4 -5
  26. package/lib/{index.js → cjs/index.js} +0 -0
  27. package/lib/cjs/input.js +174 -0
  28. package/lib/{label.js → cjs/label.js} +2 -1
  29. package/lib/{layout.js → cjs/layout.js} +9 -8
  30. package/lib/{link.js → cjs/link.js} +3 -2
  31. package/lib/cjs/listview.js +544 -0
  32. package/{src/md5.ts → lib/cjs/md5.js} +403 -438
  33. package/lib/{menu.js → cjs/menu.js} +4 -11
  34. package/lib/{messagebox.js → cjs/messagebox.js} +4 -4
  35. package/lib/{panel.js → cjs/panel.js} +3 -4
  36. package/lib/{popup.js → cjs/popup.js} +4 -5
  37. package/lib/{property_editor.js → cjs/property_editor.js} +2 -5
  38. package/lib/{radiobtn.js → cjs/radiobtn.js} +6 -6
  39. package/lib/{rating.js → cjs/rating.js} +7 -6
  40. package/lib/cjs/request.js +246 -0
  41. package/lib/{router.js → cjs/router.js} +0 -1
  42. package/lib/cjs/settings.js +69 -0
  43. package/lib/{sidebarview.js → cjs/sidebarview.js} +2 -3
  44. package/lib/{spreadsheet.js → cjs/spreadsheet.js} +10 -27
  45. package/lib/{styles.js → cjs/styles.js} +5 -6
  46. package/lib/{svgcomponent.js → cjs/svgcomponent.js} +3 -11
  47. package/lib/{tabbar.js → cjs/tabbar.js} +5 -5
  48. package/lib/{tabview.js → cjs/tabview.js} +0 -2
  49. package/lib/{textarea.js → cjs/textarea.js} +4 -3
  50. package/lib/{textedit.js → cjs/textedit.js} +7 -8
  51. package/lib/{toaster.js → cjs/toaster.js} +0 -2
  52. package/lib/{tools.js → cjs/tools.js} +7 -16
  53. package/lib/{tooltips.js → cjs/tooltips.js} +0 -1
  54. package/lib/{treeview.js → cjs/treeview.js} +23 -19
  55. package/lib/{action.d.ts → cjs/types/action.d.ts} +0 -0
  56. package/lib/{application.d.ts → cjs/types/application.d.ts} +0 -0
  57. package/lib/{autocomplete.d.ts → cjs/types/autocomplete.d.ts} +0 -0
  58. package/lib/{base_component.d.ts → cjs/types/base_component.d.ts} +0 -0
  59. package/lib/{button.d.ts → cjs/types/button.d.ts} +0 -0
  60. package/lib/{calendar.d.ts → cjs/types/calendar.d.ts} +0 -0
  61. package/lib/{canvas.d.ts → cjs/types/canvas.d.ts} +0 -0
  62. package/lib/{cardview.d.ts → cjs/types/cardview.d.ts} +0 -0
  63. package/lib/{checkbox.d.ts → cjs/types/checkbox.d.ts} +0 -0
  64. package/lib/{color.d.ts → cjs/types/color.d.ts} +0 -0
  65. package/lib/{colorpicker.d.ts → cjs/types/colorpicker.d.ts} +0 -0
  66. package/lib/{combobox.d.ts → cjs/types/combobox.d.ts} +0 -0
  67. package/lib/{component.d.ts → cjs/types/component.d.ts} +1 -7
  68. package/lib/{datastore.d.ts → cjs/types/datastore.d.ts} +0 -0
  69. package/lib/{dialog.d.ts → cjs/types/dialog.d.ts} +0 -0
  70. package/lib/{dom_events.d.ts → cjs/types/dom_events.d.ts} +0 -0
  71. package/lib/{drag_manager.d.ts → cjs/types/drag_manager.d.ts} +0 -0
  72. package/lib/{drawtext.d.ts → cjs/types/drawtext.d.ts} +0 -0
  73. package/lib/{fileupload.d.ts → cjs/types/fileupload.d.ts} +0 -0
  74. package/lib/{form.d.ts → cjs/types/form.d.ts} +0 -0
  75. package/lib/{formatters.d.ts → cjs/types/formatters.d.ts} +0 -0
  76. package/lib/{gridview.d.ts → cjs/types/gridview.d.ts} +0 -0
  77. package/lib/{i18n.d.ts → cjs/types/i18n.d.ts} +0 -0
  78. package/lib/{icon.d.ts → cjs/types/icon.d.ts} +0 -0
  79. package/lib/{image.d.ts → cjs/types/image.d.ts} +0 -0
  80. package/lib/{index.d.ts → cjs/types/index.d.ts} +0 -0
  81. package/lib/{input.d.ts → cjs/types/input.d.ts} +0 -0
  82. package/lib/{label.d.ts → cjs/types/label.d.ts} +0 -0
  83. package/lib/{layout.d.ts → cjs/types/layout.d.ts} +0 -0
  84. package/lib/{link.d.ts → cjs/types/link.d.ts} +0 -0
  85. package/lib/{listview.d.ts → cjs/types/listview.d.ts} +0 -0
  86. package/lib/{md5.d.ts → cjs/types/md5.d.ts} +0 -0
  87. package/lib/{menu.d.ts → cjs/types/menu.d.ts} +0 -0
  88. package/lib/{messagebox.d.ts → cjs/types/messagebox.d.ts} +0 -0
  89. package/lib/{panel.d.ts → cjs/types/panel.d.ts} +0 -0
  90. package/lib/{popup.d.ts → cjs/types/popup.d.ts} +0 -0
  91. package/lib/{property_editor.d.ts → cjs/types/property_editor.d.ts} +0 -0
  92. package/lib/{radiobtn.d.ts → cjs/types/radiobtn.d.ts} +0 -0
  93. package/lib/{rating.d.ts → cjs/types/rating.d.ts} +0 -0
  94. package/lib/{request.d.ts → cjs/types/request.d.ts} +0 -0
  95. package/lib/{router.d.ts → cjs/types/router.d.ts} +0 -0
  96. package/lib/{settings.d.ts → cjs/types/settings.d.ts} +0 -0
  97. package/lib/{sidebarview.d.ts → cjs/types/sidebarview.d.ts} +0 -0
  98. package/lib/{spreadsheet.d.ts → cjs/types/spreadsheet.d.ts} +0 -0
  99. package/lib/{styles.d.ts → cjs/types/styles.d.ts} +0 -0
  100. package/lib/{svgcomponent.d.ts → cjs/types/svgcomponent.d.ts} +0 -0
  101. package/lib/{tabbar.d.ts → cjs/types/tabbar.d.ts} +0 -0
  102. package/lib/{tabview.d.ts → cjs/types/tabview.d.ts} +0 -0
  103. package/lib/{textarea.d.ts → cjs/types/textarea.d.ts} +0 -0
  104. package/lib/{textedit.d.ts → cjs/types/textedit.d.ts} +0 -0
  105. package/lib/{toaster.d.ts → cjs/types/toaster.d.ts} +0 -0
  106. package/lib/{tools.d.ts → cjs/types/tools.d.ts} +0 -0
  107. package/lib/{tooltips.d.ts → cjs/types/tooltips.d.ts} +0 -0
  108. package/lib/{treeview.d.ts → cjs/types/treeview.d.ts} +0 -0
  109. package/lib/{version.d.ts → cjs/types/version.d.ts} +0 -0
  110. package/lib/{x4dom.d.ts → cjs/types/x4dom.d.ts} +0 -0
  111. package/lib/{x4events.d.ts → cjs/types/x4events.d.ts} +0 -0
  112. package/lib/cjs/types/x4react.d.ts +41 -0
  113. package/lib/{version.js → cjs/version.js} +0 -0
  114. package/lib/{x4dom.js → cjs/x4dom.js} +0 -0
  115. package/lib/{x4events.js → cjs/x4events.js} +6 -11
  116. package/lib/cjs/x4react.js +72 -0
  117. package/lib/esm/action.js +53 -0
  118. package/lib/esm/application.js +184 -0
  119. package/lib/esm/autocomplete.js +155 -0
  120. package/lib/{base_component.js → esm/base_component.js} +3 -7
  121. package/lib/esm/button.js +257 -0
  122. package/lib/esm/calendar.js +244 -0
  123. package/lib/esm/canvas.js +358 -0
  124. package/lib/esm/cardview.js +159 -0
  125. package/lib/esm/checkbox.js +133 -0
  126. package/lib/{color.js → esm/color.js} +3 -7
  127. package/lib/esm/colorpicker.js +1475 -0
  128. package/lib/esm/combobox.js +259 -0
  129. package/lib/esm/component.js +1711 -0
  130. package/lib/esm/datastore.js +990 -0
  131. package/lib/esm/dialog.js +490 -0
  132. package/lib/{base64.d.ts → esm/dom_events.js} +2 -8
  133. package/lib/esm/drag_manager.js +147 -0
  134. package/lib/esm/drawtext.js +271 -0
  135. package/lib/esm/fileupload.js +163 -0
  136. package/lib/esm/form.js +297 -0
  137. package/lib/esm/formatters.js +81 -0
  138. package/lib/esm/gridview.js +889 -0
  139. package/lib/esm/i18n.js +257 -0
  140. package/lib/esm/icon.js +256 -0
  141. package/lib/esm/image.js +154 -0
  142. package/lib/esm/index.mjs +86 -0
  143. package/lib/{input.js → esm/input.js} +2 -6
  144. package/lib/esm/label.js +90 -0
  145. package/lib/esm/layout.js +310 -0
  146. package/lib/esm/link.js +59 -0
  147. package/lib/{listview.js → esm/listview.js} +30 -36
  148. package/lib/{md5.js → esm/md5.js} +1 -5
  149. package/lib/esm/menu.js +300 -0
  150. package/lib/esm/messagebox.js +145 -0
  151. package/lib/esm/panel.js +65 -0
  152. package/lib/esm/popup.js +379 -0
  153. package/lib/esm/property_editor.js +251 -0
  154. package/lib/esm/radiobtn.js +136 -0
  155. package/lib/esm/rating.js +97 -0
  156. package/lib/{request.js → esm/request.js} +9 -16
  157. package/lib/esm/router.js +136 -0
  158. package/lib/{settings.js → esm/settings.js} +1 -5
  159. package/lib/esm/sidebarview.js +79 -0
  160. package/lib/esm/spreadsheet.js +1091 -0
  161. package/lib/esm/styles.js +270 -0
  162. package/lib/esm/svgcomponent.js +422 -0
  163. package/lib/esm/tabbar.js +107 -0
  164. package/lib/esm/tabview.js +83 -0
  165. package/lib/esm/textarea.js +123 -0
  166. package/lib/esm/textedit.js +412 -0
  167. package/lib/esm/toaster.js +62 -0
  168. package/lib/esm/tools.js +1155 -0
  169. package/lib/esm/tooltips.js +153 -0
  170. package/lib/esm/treeview.js +495 -0
  171. package/lib/esm/types/action.d.ts +57 -0
  172. package/lib/esm/types/application.d.ts +104 -0
  173. package/lib/esm/types/autocomplete.d.ts +58 -0
  174. package/lib/esm/types/base_component.d.ts +88 -0
  175. package/lib/esm/types/button.d.ts +151 -0
  176. package/lib/esm/types/calendar.d.ts +81 -0
  177. package/lib/esm/types/canvas.d.ts +92 -0
  178. package/lib/esm/types/cardview.d.ts +87 -0
  179. package/lib/esm/types/checkbox.d.ts +77 -0
  180. package/lib/esm/types/color.d.ts +148 -0
  181. package/lib/esm/types/colorpicker.d.ts +107 -0
  182. package/lib/esm/types/combobox.d.ts +101 -0
  183. package/lib/esm/types/component.d.ts +601 -0
  184. package/lib/esm/types/datastore.d.ts +396 -0
  185. package/lib/esm/types/dialog.d.ts +175 -0
  186. package/lib/esm/types/dom_events.d.ts +302 -0
  187. package/lib/esm/types/drag_manager.d.ts +54 -0
  188. package/lib/esm/types/drawtext.d.ts +48 -0
  189. package/lib/esm/types/fileupload.d.ts +64 -0
  190. package/lib/esm/types/form.d.ts +126 -0
  191. package/lib/esm/types/formatters.d.ts +35 -0
  192. package/lib/esm/types/gridview.d.ts +175 -0
  193. package/lib/esm/types/i18n.d.ts +73 -0
  194. package/lib/esm/types/icon.d.ts +64 -0
  195. package/lib/esm/types/image.d.ts +55 -0
  196. package/lib/esm/types/index.d.ts +83 -0
  197. package/lib/esm/types/input.d.ts +91 -0
  198. package/lib/esm/types/label.d.ts +58 -0
  199. package/lib/esm/types/layout.d.ts +87 -0
  200. package/lib/esm/types/link.d.ts +50 -0
  201. package/lib/esm/types/listview.d.ts +178 -0
  202. package/lib/esm/types/md5.d.ts +61 -0
  203. package/lib/esm/types/menu.d.ts +130 -0
  204. package/lib/esm/types/messagebox.d.ts +68 -0
  205. package/lib/esm/types/panel.d.ts +47 -0
  206. package/lib/esm/types/popup.d.ts +75 -0
  207. package/lib/esm/types/property_editor.d.ts +71 -0
  208. package/lib/esm/types/radiobtn.d.ts +72 -0
  209. package/lib/esm/types/rating.d.ts +53 -0
  210. package/lib/esm/types/request.d.ts +52 -0
  211. package/lib/esm/types/router.d.ts +42 -0
  212. package/lib/esm/types/settings.d.ts +37 -0
  213. package/lib/esm/types/sidebarview.d.ts +49 -0
  214. package/lib/esm/types/spreadsheet.d.ts +218 -0
  215. package/lib/esm/types/styles.d.ts +85 -0
  216. package/lib/esm/types/svgcomponent.d.ts +191 -0
  217. package/lib/esm/types/tabbar.d.ts +58 -0
  218. package/lib/esm/types/tabview.d.ts +49 -0
  219. package/lib/{texthiliter.d.ts → esm/types/textarea.d.ts} +26 -23
  220. package/lib/esm/types/textedit.d.ts +123 -0
  221. package/lib/esm/types/toaster.d.ts +42 -0
  222. package/lib/esm/types/tools.d.ts +394 -0
  223. package/lib/esm/types/tooltips.d.ts +46 -0
  224. package/lib/esm/types/treeview.d.ts +132 -0
  225. package/lib/esm/types/version.d.ts +29 -0
  226. package/lib/esm/types/x4dom.d.ts +49 -0
  227. package/lib/{x4_events.d.ts → esm/types/x4events.d.ts} +6 -3
  228. package/lib/esm/types/x4react.d.ts +41 -0
  229. package/lib/esm/version.js +29 -0
  230. package/lib/esm/x4dom.js +29 -0
  231. package/lib/{x4_events.js → esm/x4events.js} +11 -24
  232. package/lib/esm/x4react.js +71 -0
  233. package/lib/{x4.css → styles/x4.css} +11 -0
  234. package/{src → lib/styles}/x4.less +14 -0
  235. package/package.json +35 -14
  236. package/build.sh +0 -5
  237. package/lib/base64.js +0 -143
  238. package/lib/hosts/host.d.ts +0 -44
  239. package/lib/hosts/host.js +0 -73
  240. package/lib/smartedit.d.ts +0 -107
  241. package/lib/smartedit.js +0 -390
  242. package/lib/texthiliter.js +0 -227
  243. package/lib/x4react.d.ts +0 -6
  244. package/lib/x4react.js +0 -35
  245. package/src/MIT-license.md +0 -14
  246. package/src/action.ts +0 -88
  247. package/src/alpha.jpg +0 -0
  248. package/src/application.ts +0 -251
  249. package/src/autocomplete.ts +0 -197
  250. package/src/base64.ts +0 -166
  251. package/src/base_component.ts +0 -152
  252. package/src/button.ts +0 -355
  253. package/src/calendar.ts +0 -322
  254. package/src/canvas.ts +0 -505
  255. package/src/cardview.ts +0 -227
  256. package/src/checkbox.ts +0 -187
  257. package/src/color.ts +0 -752
  258. package/src/colorpicker.ts +0 -1639
  259. package/src/combobox.ts +0 -362
  260. package/src/component.ts +0 -2344
  261. package/src/datastore.ts +0 -1322
  262. package/src/dialog.ts +0 -656
  263. package/src/dom_events.ts +0 -315
  264. package/src/drag_manager.ts +0 -199
  265. package/src/drawtext.ts +0 -355
  266. package/src/fileupload.ts +0 -213
  267. package/src/form.ts +0 -366
  268. package/src/formatters.ts +0 -105
  269. package/src/gridview.ts +0 -1185
  270. package/src/i18n.ts +0 -346
  271. package/src/icon.ts +0 -329
  272. package/src/image.ts +0 -204
  273. package/src/index.ts +0 -88
  274. package/src/input.ts +0 -249
  275. package/src/label.ts +0 -128
  276. package/src/layout.ts +0 -430
  277. package/src/link.ts +0 -86
  278. package/src/listview.ts +0 -762
  279. package/src/menu.ts +0 -425
  280. package/src/messagebox.ts +0 -203
  281. package/src/panel.ts +0 -86
  282. package/src/popup.ts +0 -494
  283. package/src/property_editor.ts +0 -337
  284. package/src/radiobtn.ts +0 -196
  285. package/src/rating.ts +0 -135
  286. package/src/request.ts +0 -300
  287. package/src/router.ts +0 -185
  288. package/src/settings.ts +0 -77
  289. package/src/sidebarview.ts +0 -103
  290. package/src/spreadsheet.ts +0 -1442
  291. package/src/styles.ts +0 -343
  292. package/src/svgcomponent.ts +0 -537
  293. package/src/tabbar.ts +0 -151
  294. package/src/tabview.ts +0 -110
  295. package/src/textarea.ts +0 -187
  296. package/src/textedit.ts +0 -544
  297. package/src/toaster.ts +0 -80
  298. package/src/tools.ts +0 -1468
  299. package/src/tooltips.ts +0 -191
  300. package/src/treeview.ts +0 -675
  301. package/src/version.ts +0 -30
  302. package/src/x4dom.ts +0 -57
  303. package/src/x4events.ts +0 -585
  304. package/src/x4react.ts +0 -42
  305. package/tsconfig.json +0 -21
@@ -0,0 +1,1091 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file spreadsheet.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * Copyright (c) 2019-2022 R-libre ingenierie
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ * The above copyright notice and this permission notice shall be included in all copies
20
+ * or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ **/
29
+ import { x4document } from './x4dom';
30
+ import { Component, SizerOverlay, EvDblClick } from './component';
31
+ import { HLayout, VLayout } from './layout';
32
+ import { TextEdit } from './textedit';
33
+ import { asap, parseIntlFloat } from './tools';
34
+ import { deferCall } from './tools';
35
+ import { EvContextMenu, EvChange, EvSelectionChange } from './x4events';
36
+ import { ComboBox } from './combobox';
37
+ class CellData {
38
+ text;
39
+ cls;
40
+ static empty_cell = {
41
+ text: ''
42
+ };
43
+ }
44
+ /**
45
+ *
46
+ */
47
+ export class Spreadsheet extends VLayout {
48
+ m_columns;
49
+ m_row_limit;
50
+ m_cells_data;
51
+ m_rows_data;
52
+ m_view;
53
+ m_container;
54
+ m_header;
55
+ m_itemHeight;
56
+ m_topIndex;
57
+ m_visible_cells;
58
+ m_row_count; // visible row count
59
+ m_selection;
60
+ m_editor;
61
+ m_autoedit;
62
+ m_lockupdate;
63
+ m_auto_row_count;
64
+ m_recycler;
65
+ m_used_cells;
66
+ constructor(props) {
67
+ super(props);
68
+ this.m_columns = props.columns;
69
+ this.m_autoedit = props.autoedit;
70
+ this.m_lockupdate = 0;
71
+ this.m_cells_data = new Map();
72
+ this.m_rows_data = new Map();
73
+ this.m_itemHeight = 0;
74
+ this.m_selection = { row: 0, col: 0 };
75
+ this.m_row_count = 0;
76
+ this.m_auto_row_count = false;
77
+ this.m_recycler = [];
78
+ this.m_used_cells = [];
79
+ if (props.maxrows === undefined) {
80
+ this.m_row_limit = 0;
81
+ this.m_auto_row_count = true;
82
+ }
83
+ else if (props.maxrows < 0) {
84
+ this.m_row_limit = 0;
85
+ this.m_auto_row_count = true;
86
+ }
87
+ else {
88
+ this.m_row_limit = props.maxrows;
89
+ }
90
+ this.setAttribute('tabindex', 0);
91
+ this.setDomEvent('click', (e) => this._itemClick(e));
92
+ this.setDomEvent('dblclick', (e) => this._itemDblClick(e));
93
+ this.setDomEvent('keydown', (e) => this._handleKey(e));
94
+ this.setDomEvent('keypress', (e) => this._keyPress(e));
95
+ this.setDomEvent('focus', () => this._focus(true));
96
+ this.setDomEvent('focusout', () => this._focus(false));
97
+ this.setDomEvent('contextmenu', (e) => this._ctxMenu(e));
98
+ this.mapPropEvents(props, 'dblClick', 'selectionChange', 'contextMenu', 'change');
99
+ }
100
+ componentCreated() {
101
+ super.componentCreated();
102
+ this._updateScroll(true);
103
+ }
104
+ setColWidth(col, width) {
105
+ this._on_col_resize(col, width);
106
+ this.update(10);
107
+ }
108
+ getColWidth(col) {
109
+ if (!this.m_columns[col]) {
110
+ return;
111
+ }
112
+ return this.m_columns[col].width;
113
+ }
114
+ setColTitle(col, title) {
115
+ console.assert(this.m_columns[col] !== undefined); // what ?
116
+ this.m_columns[col].title = title;
117
+ this.update(10);
118
+ }
119
+ reset(columns) {
120
+ this.m_columns = columns;
121
+ this.m_cells_data = new Map();
122
+ this.m_rows_data = new Map();
123
+ this.update(10);
124
+ }
125
+ /**
126
+ * insert a row
127
+ * @param before row number before wich insert the new row
128
+ */
129
+ insertRow(before) {
130
+ let new_cells_data = new Map();
131
+ this.m_cells_data.forEach((celldata, key) => {
132
+ let { row, col } = _getid(key);
133
+ if (row >= before) {
134
+ new_cells_data.set(_mkid(row + 1, col), celldata);
135
+ }
136
+ else {
137
+ new_cells_data.set(key, celldata);
138
+ }
139
+ });
140
+ let new_rows_data = new Map();
141
+ this.m_rows_data.forEach((rowdata, row) => {
142
+ if (row >= before) {
143
+ new_rows_data.set(row + 1, rowdata);
144
+ }
145
+ else {
146
+ new_rows_data.set(row, rowdata);
147
+ }
148
+ });
149
+ this.m_cells_data = new_cells_data;
150
+ this.m_rows_data = new_rows_data;
151
+ this._buildItems();
152
+ }
153
+ /**
154
+ * remove a row
155
+ * @param rowtodel row number to remove
156
+ */
157
+ deleteRow(rowtodel) {
158
+ let new_cells_data = new Map();
159
+ let new_rows_data = new Map();
160
+ this.m_cells_data.forEach((celldata, key) => {
161
+ let { row, col } = _getid(key);
162
+ if (row > rowtodel) {
163
+ new_cells_data.set(_mkid(row - 1, col), celldata);
164
+ }
165
+ else if (row < rowtodel) {
166
+ new_cells_data.set(key, celldata);
167
+ }
168
+ });
169
+ this.m_rows_data.forEach((rowdata, row) => {
170
+ if (row > rowtodel) {
171
+ new_rows_data.set(row - 1, rowdata);
172
+ }
173
+ else if (row < rowtodel) {
174
+ new_rows_data.set(row, rowdata);
175
+ }
176
+ });
177
+ this.m_cells_data = new_cells_data;
178
+ this.m_rows_data = new_rows_data;
179
+ this._buildItems();
180
+ }
181
+ /**
182
+ * insert a new column
183
+ * @param before column index before to insert the new column or <0 to append
184
+ */
185
+ insertCol(before, column) {
186
+ let inspos = before;
187
+ if (inspos < 0) {
188
+ inspos = this.m_columns.length + 1;
189
+ }
190
+ // insert the col at the right place
191
+ this.m_columns.splice(inspos, 0, column);
192
+ if (before >= 0) {
193
+ let new_cells_data = new Map();
194
+ this.m_cells_data.forEach((celldata, key) => {
195
+ let { row, col } = _getid(key);
196
+ if (col >= before) {
197
+ new_cells_data.set(_mkid(row, col + 1), celldata);
198
+ }
199
+ else {
200
+ new_cells_data.set(key, celldata);
201
+ }
202
+ });
203
+ this.m_cells_data = new_cells_data;
204
+ }
205
+ this.update();
206
+ }
207
+ /**
208
+ * remove a column
209
+ * @param coltodel
210
+ */
211
+ deleteCol(coltodel) {
212
+ // insert the col at the right place
213
+ this.m_columns.splice(coltodel, 1);
214
+ let new_cells_data = new Map();
215
+ this.m_cells_data.forEach((celldata, key) => {
216
+ let { row, col } = _getid(key);
217
+ if (col > coltodel) {
218
+ new_cells_data.set(_mkid(row, col - 1), celldata);
219
+ }
220
+ else if (col < coltodel) {
221
+ new_cells_data.set(key, celldata);
222
+ }
223
+ });
224
+ this.m_cells_data = new_cells_data;
225
+ this.update();
226
+ }
227
+ /**
228
+ *
229
+ * @param row
230
+ * @param col
231
+ */
232
+ _getCellData(row, col, raw = false) {
233
+ let value = this.m_cells_data.get(_mkid(row, col));
234
+ if (value === undefined) {
235
+ return raw ? null : CellData.empty_cell;
236
+ }
237
+ return value;
238
+ }
239
+ _focus(focus) {
240
+ this.setClass('@focus', focus);
241
+ }
242
+ _ctxMenu(e) {
243
+ let dom = e.target, self = this.dom;
244
+ while (dom && dom != self) {
245
+ let itm = Component.getElement(dom), row = itm.getData('row-id'), col = itm.getData('col-id');
246
+ if (row !== undefined) {
247
+ this._selectItem(row, col);
248
+ this.emit('contextMenu', EvContextMenu(e, { row, col, item: itm }));
249
+ e.preventDefault();
250
+ return;
251
+ }
252
+ dom = dom.parentElement;
253
+ }
254
+ }
255
+ /** @ignore */
256
+ render() {
257
+ this.m_recycler = [];
258
+ this.m_container = new Component({
259
+ cls: 'content',
260
+ });
261
+ this.m_view = new Component({
262
+ cls: '@scroll-view',
263
+ flex: 1,
264
+ dom_events: {
265
+ sizechange: () => this._updateScroll(true),
266
+ scroll: () => this._updateScroll(false)
267
+ },
268
+ content: this.m_container
269
+ });
270
+ let cols = this.m_columns.map((col, index) => {
271
+ let comp = new Component({
272
+ cls: '@cell c' + index,
273
+ content: col.title ? col.title : '&nbsp',
274
+ flex: col.width < 0 ? -col.width : undefined,
275
+ attrs: {
276
+ title: col.title
277
+ },
278
+ style: {
279
+ width: col.width >= 0 ? col.width : undefined,
280
+ minWidth: col.min_width
281
+ },
282
+ });
283
+ new SizerOverlay({
284
+ target: comp,
285
+ sens: 'right',
286
+ resize: (ev) => {
287
+ this._on_col_resize(index, ev.size.width);
288
+ }
289
+ });
290
+ col.$col = comp;
291
+ return comp;
292
+ });
293
+ this.m_header = new HLayout({
294
+ cls: '@header',
295
+ content: cols,
296
+ });
297
+ this.setContent([
298
+ this.m_header,
299
+ this.m_view
300
+ ]);
301
+ }
302
+ /**
303
+ *
304
+ */
305
+ _on_col_resize(col, width) {
306
+ if (!this.m_columns[col]) {
307
+ return;
308
+ }
309
+ // -> flex
310
+ if (width <= 0) {
311
+ this.m_columns[col].width = -1; // flex default
312
+ }
313
+ else {
314
+ this.m_columns[col].width = width;
315
+ }
316
+ this._updateScroll(true);
317
+ }
318
+ /**
319
+ * compute misc dimensions
320
+ * - item height
321
+ * - scroll width
322
+ */
323
+ _computeItemHeight() {
324
+ let g1 = x4document.createElement('div');
325
+ g1.classList.add('x-spreadsheet');
326
+ let g2 = x4document.createElement('div');
327
+ g2.classList.add('content');
328
+ let g3 = x4document.createElement('div');
329
+ g3.classList.add('x-cell');
330
+ g3.append('&nbsp;');
331
+ g2.appendChild(g3);
332
+ g1.appendChild(g2);
333
+ this.dom.appendChild(g1);
334
+ let rc = g3.getBoundingClientRect();
335
+ this.dom.removeChild(g1);
336
+ this.m_itemHeight = rc.height;
337
+ }
338
+ /**
339
+ * compute columns widths
340
+ * use col.width for fixed size columns
341
+ * if col.width < 0 that mean that this is a proportion of the remaining space
342
+ */
343
+ _calcColWidths(width) {
344
+ let fullw = 0;
345
+ let nwide = 0;
346
+ let calcw = new Int32Array(this.m_columns.length);
347
+ let calcz = new Int32Array(this.m_columns.length);
348
+ let calcm = new Int32Array(this.m_columns.length);
349
+ this.m_columns.forEach((col, colIdx) => {
350
+ let minw = Math.max(10, col.min_width ?? 0);
351
+ if (col.width > 0) {
352
+ let cw = Math.max(col.width, minw);
353
+ fullw += cw;
354
+ calcw[colIdx] = cw;
355
+ }
356
+ else {
357
+ let z = -col.width;
358
+ calcz[colIdx] = z;
359
+ nwide += z;
360
+ }
361
+ calcm[colIdx] = minw;
362
+ });
363
+ if (nwide) {
364
+ let restw = width - fullw;
365
+ for (let i = 0; i < this.m_columns.length && nwide; i++) {
366
+ if (!calcw[i]) {
367
+ let rest = Math.round(restw / nwide) * calcz[i];
368
+ if (rest < calcm[i]) {
369
+ rest = calcm[i];
370
+ }
371
+ calcw[i] = rest;
372
+ restw -= rest;
373
+ nwide -= calcz[i];
374
+ }
375
+ }
376
+ }
377
+ return calcw;
378
+ }
379
+ /**
380
+ * create a cell (component)
381
+ * and append it to the parent view
382
+ * if a cell was reviously recyled, use it
383
+ */
384
+ _createCell() {
385
+ let cell;
386
+ if (this.m_recycler.length) {
387
+ cell = this.m_recycler.pop();
388
+ cell.clearClasses();
389
+ cell.addClass('@comp'); // todo: find better to reset to default
390
+ }
391
+ else {
392
+ cell = new Component({
393
+ cls: '@cell'
394
+ });
395
+ }
396
+ if (!cell.dom) {
397
+ this.m_container.appendChild(cell);
398
+ }
399
+ return cell;
400
+ }
401
+ /**
402
+ * build cells of the spreadsheet
403
+ * cells are recycled when scrolling,
404
+ * only visibles cells exists
405
+ */
406
+ _buildItems() {
407
+ let rc = this.getBoundingRect();
408
+ let rh = this.m_header.getBoundingRect();
409
+ let height = rc.height - rh.height;
410
+ if (this.m_itemHeight == 0) {
411
+ this._computeItemHeight();
412
+ }
413
+ let top = this.m_topIndex * this.m_itemHeight;
414
+ let y = 0;
415
+ let cidx = 0;
416
+ let rowIdx = this.m_topIndex;
417
+ let count = this.m_row_limit;
418
+ if (this.m_auto_row_count) {
419
+ //@review should be evaluated only when row count change
420
+ this.m_row_limit = count = this.getMaxRowCount();
421
+ }
422
+ let right_pos = 0;
423
+ if ((count * this.m_itemHeight) > height) {
424
+ let w = Component.getScrollbarSize();
425
+ rc.width -= w;
426
+ right_pos = w;
427
+ }
428
+ let even = this.m_topIndex & 1 ? true : false;
429
+ this.m_visible_cells = new Map();
430
+ // passe 0 - all created cells are moved to the recycler
431
+ this.m_used_cells.forEach((c) => {
432
+ this.m_recycler.push(c);
433
+ });
434
+ this.m_used_cells = [];
435
+ // pass 1 - compute column widths
436
+ let calcw = this._calcColWidths(rc.width);
437
+ //
438
+ let full_width = 0;
439
+ for (let i = 0; i < calcw.length; i++) {
440
+ full_width += calcw[i];
441
+ }
442
+ if (full_width <= rc.width) {
443
+ this.m_view.setStyleValue('overflow-x', 'hidden');
444
+ this.m_header.setStyleValue('width', rc.width);
445
+ this.m_container.setStyleValue('width', rc.width);
446
+ this.m_container.setStyle({
447
+ height: count * this.m_itemHeight,
448
+ });
449
+ }
450
+ else {
451
+ this.m_header.setStyleValue('width', full_width);
452
+ this.m_container.setStyleValue('width', full_width);
453
+ this.m_view.setStyleValue('overflow-x', 'visible');
454
+ this.m_container.setStyle({
455
+ height: count * this.m_itemHeight,
456
+ width: full_width
457
+ });
458
+ }
459
+ this.m_view.addClass('@hidden');
460
+ // pass 2 - build cells
461
+ let limit = 100;
462
+ while (y < height && rowIdx < count && --limit > 0) {
463
+ let rowdata = this.m_rows_data.get(rowIdx);
464
+ let x = 0;
465
+ let cols = this.m_columns.map((col, colIdx) => {
466
+ let cls = '@cell c' + colIdx;
467
+ if (col.align) {
468
+ cls += ' ' + col.align;
469
+ }
470
+ if (col.cls) {
471
+ cls += ' ' + col.cls;
472
+ }
473
+ let cell;
474
+ let celldata = this._getCellData(rowIdx, colIdx);
475
+ let text = celldata.text;
476
+ if (col.renderer && text.length) {
477
+ text = col.renderer(text, { row: rowIdx, col: colIdx });
478
+ }
479
+ //if( text.length==0 ) {
480
+ // text = '&nbsp;'
481
+ //}
482
+ cls += (even ? ' even' : ' odd');
483
+ if (rowdata) {
484
+ cls += ' ' + rowdata;
485
+ }
486
+ cell = this._createCell();
487
+ this.m_used_cells.push(cell);
488
+ cell.setContent(text); // always because cell reuse
489
+ cell.addClass(cls);
490
+ cell.setStyle({
491
+ left: x,
492
+ top: top + y,
493
+ width: calcw[colIdx],
494
+ height: this.m_itemHeight
495
+ });
496
+ if (this.m_selection.row == rowIdx && this.m_selection.col == colIdx) {
497
+ cell.addClass('@selected');
498
+ }
499
+ cell.setData('row-id', rowIdx);
500
+ cell.setData('col-id', colIdx);
501
+ if (celldata.cls) {
502
+ cell.addClass(celldata.cls);
503
+ }
504
+ this.m_visible_cells.set(_mkid(rowIdx, colIdx), cell);
505
+ x += calcw[colIdx];
506
+ return cell;
507
+ });
508
+ even = !even;
509
+ y += this.m_itemHeight;
510
+ rowIdx++;
511
+ cidx++;
512
+ //rows.splice( rows.length, 0, ...cols );
513
+ }
514
+ // if some cells are still in cache, hide them
515
+ this.m_recycler.forEach((c) => {
516
+ c.addClass('@hidden');
517
+ });
518
+ this.m_row_count = cidx;
519
+ //this.m_container.setContent( <ComponentContent>rows);
520
+ this.m_view.removeClass('@hidden');
521
+ this.setClass('empty', count == 0);
522
+ }
523
+ /** @ignore */
524
+ _itemClick(e) {
525
+ let dom = e.target;
526
+ if (this.m_editor && this.m_editor.dom.contains(dom)) {
527
+ return;
528
+ }
529
+ let itm = Component.getElement(dom, Component);
530
+ if (!itm) {
531
+ return;
532
+ }
533
+ let rowIdx = itm.getData('row-id'), colIdx = itm.getData('col-id');
534
+ if (rowIdx === undefined || colIdx === undefined) {
535
+ return;
536
+ }
537
+ this._selectItem(rowIdx, colIdx);
538
+ }
539
+ _itemDblClick(e) {
540
+ let dom = e.target;
541
+ if (this.m_editor && this.m_editor.dom.contains(dom)) {
542
+ return;
543
+ }
544
+ let itm = Component.getElement(dom), rowIdx = itm.getData('row-id'), colIdx = itm.getData('col-id');
545
+ if (rowIdx === undefined || colIdx === undefined) {
546
+ return;
547
+ }
548
+ this.emit('dblClick', EvDblClick({ row: rowIdx, col: colIdx }));
549
+ this.editCell(rowIdx, colIdx);
550
+ }
551
+ /**
552
+ *
553
+ * @param rowIdx
554
+ * @param colIdx
555
+ * @param scrollIntoView
556
+ */
557
+ _selectItem(rowIdx, colIdx, scrollIntoView) {
558
+ if (rowIdx < 0) {
559
+ rowIdx = 0;
560
+ }
561
+ if (rowIdx > this.m_row_limit - 1) {
562
+ rowIdx = this.m_row_limit - 1;
563
+ }
564
+ if (colIdx < 0) {
565
+ colIdx = 0;
566
+ }
567
+ let lastcol = this.m_columns.length - 1;
568
+ if (colIdx > lastcol) {
569
+ colIdx = lastcol;
570
+ }
571
+ if (this.m_selection.row == rowIdx && this.m_selection.col == colIdx) {
572
+ return;
573
+ }
574
+ this.select(rowIdx, colIdx, scrollIntoView);
575
+ }
576
+ _scrollIntoView(row, col) {
577
+ let doscroll = (itm, mode = 'nearest') => {
578
+ itm.scrollIntoView({
579
+ block: mode //<ScrollLogicalPosition>sens ?? 'nearest'
580
+ });
581
+ };
582
+ let last = this.m_topIndex + this.m_row_count - 1;
583
+ if (row < this.m_topIndex) {
584
+ this.m_topIndex = row;
585
+ this.m_view.dom.scrollTop = this.m_topIndex * this.m_itemHeight;
586
+ this._buildItems();
587
+ doscroll(this._findItem(row, col), 'start');
588
+ }
589
+ else if (row > last) {
590
+ this.m_topIndex = row - this.m_row_count + 1;
591
+ this.m_view.dom.scrollTop = this.m_topIndex * this.m_itemHeight;
592
+ this._buildItems();
593
+ doscroll(this._findItem(row, col), 'end');
594
+ }
595
+ else {
596
+ doscroll(this._findItem(row, col));
597
+ }
598
+ }
599
+ /**
600
+ *
601
+ * @param row
602
+ * @param col
603
+ */
604
+ _findItem(row, col) {
605
+ if (!this.m_visible_cells) {
606
+ return null;
607
+ }
608
+ return this.m_visible_cells.get(_mkid(row, col));
609
+ }
610
+ /**
611
+ *
612
+ */
613
+ _updateScroll(forceUpdate) {
614
+ if (!this?.m_view?.dom) {
615
+ return;
616
+ }
617
+ let newTop = Math.floor(this.m_view.dom.scrollTop / (this.m_itemHeight || 1));
618
+ if (newTop != this.m_topIndex || forceUpdate) {
619
+ this.m_topIndex = newTop;
620
+ this._buildItems();
621
+ }
622
+ let newLeft = this.m_view.dom.scrollLeft;
623
+ this.m_header.setStyleValue('left', -newLeft);
624
+ }
625
+ /**
626
+ *
627
+ * @param event
628
+ * @param t
629
+ */
630
+ _moveSel(sensy, sensx) {
631
+ let sel = this.m_selection;
632
+ let newRow = sel.row ?? 0;
633
+ let newCol = sel.col ?? 0;
634
+ if (sensy == 1) {
635
+ newRow++;
636
+ }
637
+ else if (sensy == -1) {
638
+ newRow--;
639
+ }
640
+ else if (sensy == 2) {
641
+ newRow += this.m_row_count - 1;
642
+ }
643
+ else if (sensy == -2) {
644
+ newRow -= this.m_row_count - 1;
645
+ }
646
+ else if (sensy == 3) {
647
+ newRow = this.m_row_limit - 1;
648
+ }
649
+ else if (sensy == -3) {
650
+ newRow = 0;
651
+ }
652
+ if (sensx == 1) {
653
+ newCol++;
654
+ }
655
+ else if (sensx == -1) {
656
+ newCol--;
657
+ }
658
+ else if (sensx == 2) {
659
+ newCol = this.m_columns.length - 1;
660
+ }
661
+ else if (sensx == -2) {
662
+ newCol = 0;
663
+ }
664
+ else if (sensx == 3) { // new editable cell skip line if needed
665
+ newCol++;
666
+ let lastcol = this.m_columns.length - 1;
667
+ l1: for (let trys = 0; trys < 2; trys++) {
668
+ while (newCol < lastcol) {
669
+ if (this.m_columns[newCol].createEditor !== null) {
670
+ break l1;
671
+ }
672
+ newCol++;
673
+ }
674
+ if (newCol > lastcol) {
675
+ newRow++;
676
+ newCol = 0;
677
+ }
678
+ }
679
+ }
680
+ else if (sensx == -3) {
681
+ newCol--;
682
+ let lastcol = this.m_columns.length - 1;
683
+ l2: for (let trys = 0; trys < 2; trys++) {
684
+ while (newCol >= 0) {
685
+ if (this.m_columns[newCol].createEditor !== null) {
686
+ break l2;
687
+ }
688
+ newCol--;
689
+ }
690
+ if (newCol < 0) {
691
+ newRow--;
692
+ newCol = lastcol;
693
+ }
694
+ }
695
+ }
696
+ this._selectItem(newRow, newCol, true);
697
+ }
698
+ _handleKey(event) {
699
+ let dom = event.target;
700
+ if (this.m_editor && this.m_editor.dom.contains(dom)) {
701
+ return;
702
+ }
703
+ switch (event.key) {
704
+ case 'ArrowDown':
705
+ case 'Down': {
706
+ this._moveSel(1, 0);
707
+ break;
708
+ }
709
+ case 'ArrowUp':
710
+ case 'Up': {
711
+ this._moveSel(-1, 0);
712
+ break;
713
+ }
714
+ case 'PageUp': {
715
+ this._moveSel(-2, 0);
716
+ break;
717
+ }
718
+ case 'PageDown': {
719
+ this._moveSel(2, 0);
720
+ break;
721
+ }
722
+ case 'ArrowLeft':
723
+ case 'Left': {
724
+ this._moveSel(0, -1);
725
+ break;
726
+ }
727
+ case 'ArrowRight':
728
+ case 'Right': {
729
+ this._moveSel(0, 1);
730
+ break;
731
+ }
732
+ case 'Home': {
733
+ if (event.ctrlKey) {
734
+ this._moveSel(-3, 0);
735
+ }
736
+ else {
737
+ this._moveSel(0, -2);
738
+ }
739
+ break;
740
+ }
741
+ case 'End': {
742
+ if (event.ctrlKey) {
743
+ this._moveSel(3, 0);
744
+ }
745
+ else {
746
+ this._moveSel(0, 2);
747
+ }
748
+ break;
749
+ }
750
+ case 'Enter': {
751
+ this.editCurCell();
752
+ event.stopPropagation();
753
+ event.preventDefault();
754
+ break;
755
+ }
756
+ case 'Delete': {
757
+ this.clearCell(this.m_selection.row, this.m_selection.col);
758
+ break;
759
+ }
760
+ default: {
761
+ //console.log( "unknown key: ", event.key);
762
+ break;
763
+ }
764
+ }
765
+ }
766
+ _keyPress(event) {
767
+ let dom = event.target;
768
+ if (this.m_editor && this.m_editor.dom.contains(dom)) {
769
+ return;
770
+ }
771
+ if (event.ctrlKey || event.altKey) {
772
+ return;
773
+ }
774
+ this.editCurCell(event.key);
775
+ }
776
+ /**
777
+ * return the selection
778
+ * { row, col }
779
+ */
780
+ getSelection() {
781
+ return this.m_selection;
782
+ }
783
+ select(row, col, scrollIntoView = true) {
784
+ if (this.m_selection.row == row && this.m_selection.col == col) {
785
+ return;
786
+ }
787
+ let oldSel = this._findItem(this.m_selection.row, this.m_selection.col);
788
+ if (oldSel) {
789
+ oldSel.removeClass('@selected');
790
+ }
791
+ this.m_selection = { row, col };
792
+ if (scrollIntoView) {
793
+ this._scrollIntoView(row, col);
794
+ }
795
+ let newSel = this._findItem(row, col);
796
+ if (newSel) {
797
+ newSel.addClass('@selected');
798
+ }
799
+ this.emit('selectionChange', EvSelectionChange({ row, col }));
800
+ }
801
+ /**
802
+ * return the row count
803
+ */
804
+ rowCount() {
805
+ return this.m_row_limit;
806
+ }
807
+ /**
808
+ * return the maximum row index filled with something
809
+ */
810
+ getMaxRowCount() {
811
+ let max_row = 0;
812
+ this.m_cells_data.forEach((c, uid) => {
813
+ let row = Math.round(uid / 1000) + 1;
814
+ if (max_row < row) {
815
+ max_row = row;
816
+ }
817
+ });
818
+ return max_row;
819
+ }
820
+ getColCount() {
821
+ return this.m_columns.length;
822
+ }
823
+ setRowStyle(row, cls) {
824
+ this.m_rows_data.set(row, cls);
825
+ if (this.m_lockupdate == 0) {
826
+ this._buildItems();
827
+ }
828
+ }
829
+ getRowStyle(row) {
830
+ return this.m_rows_data.get(row);
831
+ }
832
+ setCellStyle(row, col, cls) {
833
+ let cell = this._getCellData(row, col, true);
834
+ if (!cell) {
835
+ cell = { text: '' };
836
+ this.m_cells_data.set(_mkid(row, col), cell);
837
+ }
838
+ cell.cls = cls;
839
+ if (this.m_lockupdate == 0 && this.m_visible_cells) {
840
+ let itm = this._findItem(row, col);
841
+ if (itm) {
842
+ itm.setClass(cls, true); //todo: pb when changing classes
843
+ }
844
+ else {
845
+ this._buildItems();
846
+ }
847
+ }
848
+ }
849
+ getCellText(row, col) {
850
+ return this._getCellData(row, col).text;
851
+ }
852
+ getCellNumber(row, col) {
853
+ let text = this._getCellData(row, col).text;
854
+ return parseIntlFloat(text);
855
+ }
856
+ clearRow(row) {
857
+ for (let c = 0; c < this.m_columns.length; c++) {
858
+ this.clearCell(row, c);
859
+ }
860
+ this.update(10);
861
+ }
862
+ clearCell(row, col) {
863
+ this.setCellText(row, col, null);
864
+ }
865
+ editCurCell(forceText) {
866
+ this.editCell(this.m_selection.row, this.m_selection.col, forceText);
867
+ }
868
+ editCell(row, col, forcedText) {
869
+ if (!this.m_autoedit) {
870
+ return;
871
+ }
872
+ // disable edition
873
+ if (this.m_columns[col].createEditor === null) {
874
+ return;
875
+ }
876
+ this._scrollIntoView(row, col);
877
+ let item = this._findItem(row, col);
878
+ let place = item.dom;
879
+ let parent = place.parentElement;
880
+ let rc = place.getBoundingClientRect();
881
+ let prc = parent.getBoundingClientRect();
882
+ let cell = this._getCellData(row, col, true);
883
+ let edtBuilder = (props, col, row) => {
884
+ return new TextEdit(props);
885
+ };
886
+ if (this.m_columns[col].createEditor) {
887
+ edtBuilder = this.m_columns[col].createEditor;
888
+ }
889
+ let cellvalue = forcedText ? forcedText : (cell ? cell.text : '');
890
+ this.m_editor = edtBuilder({
891
+ cls: '@editor',
892
+ style: {
893
+ left: rc.left - prc.left,
894
+ top: rc.top - prc.top,
895
+ width: rc.width - 1,
896
+ height: rc.height - 1
897
+ },
898
+ tabIndex: false,
899
+ value: cellvalue,
900
+ data: {
901
+ row,
902
+ col
903
+ },
904
+ }, row, col);
905
+ if (!this.m_editor) {
906
+ return;
907
+ }
908
+ parent.appendChild(this.m_editor._build());
909
+ this._setupEditor();
910
+ this.m_editor.setData('old-value', cellvalue);
911
+ this.m_editor.focus();
912
+ if (this.m_editor instanceof TextEdit) {
913
+ this.m_editor.selectAll();
914
+ }
915
+ }
916
+ _setupEditor() {
917
+ let movesel = (sensy, sensx) => {
918
+ deferCall(() => {
919
+ this.killEditor(true);
920
+ this._moveSel(sensy, sensx);
921
+ this.editCurCell();
922
+ });
923
+ };
924
+ // todo: better
925
+ if (this.m_editor instanceof TextEdit) {
926
+ let editor = this.m_editor;
927
+ let input = editor.input;
928
+ input.setDomEvent('blur', () => {
929
+ this.killEditor(true);
930
+ });
931
+ input.setDomEvent('keydown', (e) => {
932
+ // prevented by edit...
933
+ if (e.defaultPrevented) {
934
+ return;
935
+ }
936
+ switch (e.key) {
937
+ case 'Escape': {
938
+ this.killEditor(false);
939
+ e.stopPropagation();
940
+ e.preventDefault();
941
+ break;
942
+ }
943
+ case 'Enter':
944
+ case 'Tab': {
945
+ let sens = 3;
946
+ if (e.shiftKey) {
947
+ sens = -3;
948
+ }
949
+ movesel(0, sens);
950
+ e.stopPropagation();
951
+ e.preventDefault();
952
+ break;
953
+ }
954
+ case 'ArrowUp':
955
+ case 'Up': {
956
+ movesel(-1, 0);
957
+ e.stopPropagation();
958
+ e.preventDefault();
959
+ break;
960
+ }
961
+ case 'ArrowDown':
962
+ case 'Down': {
963
+ movesel(1, 0);
964
+ e.stopPropagation();
965
+ e.preventDefault();
966
+ break;
967
+ }
968
+ }
969
+ });
970
+ }
971
+ else if (this.m_editor instanceof ComboBox) {
972
+ let input = this.m_editor.input;
973
+ input.setDomEvent('blur', () => {
974
+ this.killEditor(true);
975
+ });
976
+ input.setDomEvent('keydown', (e) => {
977
+ switch (e.key) {
978
+ case 'Escape': {
979
+ this.killEditor(false);
980
+ e.stopPropagation();
981
+ e.preventDefault();
982
+ break;
983
+ }
984
+ case 'Enter':
985
+ case 'Tab': {
986
+ let sens = 3;
987
+ if (e.shiftKey) {
988
+ sens = -3;
989
+ }
990
+ movesel(0, sens);
991
+ e.stopPropagation();
992
+ e.preventDefault();
993
+ break;
994
+ }
995
+ }
996
+ });
997
+ this.m_editor.showPopup();
998
+ this.m_editor.on('change', (ev) => {
999
+ this.killEditor(true);
1000
+ });
1001
+ this.m_editor.on('cancel', (ev) => {
1002
+ this.killEditor(false);
1003
+ });
1004
+ }
1005
+ }
1006
+ killEditor(save) {
1007
+ if (this.m_editor) {
1008
+ if (save) {
1009
+ let text, id;
1010
+ if (this.m_editor instanceof TextEdit) {
1011
+ text = this.m_editor.value;
1012
+ }
1013
+ else if (this.m_editor instanceof ComboBox) {
1014
+ id = this.m_editor.value;
1015
+ text = this.m_editor.valueText;
1016
+ }
1017
+ let row = this.m_editor.getData('row');
1018
+ let col = this.m_editor.getData('col');
1019
+ let old = this.m_editor.getData('old-value');
1020
+ this.setCellText(row, col, text);
1021
+ const ev = EvChange(text, { row, col, oldValue: old, id });
1022
+ this.emit('change', ev);
1023
+ if (ev.defaultPrevented) {
1024
+ this.setCellText(row, col, old);
1025
+ }
1026
+ }
1027
+ // cannot dipose while handling blur event, so we defer...
1028
+ let t = this.m_editor;
1029
+ asap(() => {
1030
+ t.dispose();
1031
+ });
1032
+ this.m_editor = null;
1033
+ this.focus();
1034
+ }
1035
+ }
1036
+ clearData() {
1037
+ this.m_cells_data = new Map();
1038
+ this.m_rows_data = new Map();
1039
+ }
1040
+ setCellText(row, col, value) {
1041
+ if (value == null || value.length == 0) {
1042
+ this.m_cells_data.delete(_mkid(row, col));
1043
+ value = ''; //'&nbsp';
1044
+ }
1045
+ else {
1046
+ let cell = this._getCellData(row, col, true);
1047
+ if (!cell) {
1048
+ cell = {};
1049
+ }
1050
+ cell.text = value;
1051
+ this.m_cells_data.set(_mkid(row, col), cell);
1052
+ }
1053
+ if (this.m_lockupdate == 0 && this.m_visible_cells) {
1054
+ let itm = this._findItem(row, col);
1055
+ if (itm) {
1056
+ if (this.m_columns[col].renderer) {
1057
+ value = this.m_columns[col].renderer(value, { row, col });
1058
+ }
1059
+ itm.setContent(value);
1060
+ }
1061
+ else {
1062
+ this._buildItems();
1063
+ }
1064
+ }
1065
+ }
1066
+ lockUpdate(start) {
1067
+ if (start) {
1068
+ this.m_lockupdate++;
1069
+ }
1070
+ else {
1071
+ if (--this.m_lockupdate == 0) {
1072
+ this._updateScroll(true);
1073
+ }
1074
+ }
1075
+ }
1076
+ }
1077
+ /**
1078
+ * @ignore
1079
+ */
1080
+ function _mkid(row, col) {
1081
+ return row * 1000 + col;
1082
+ }
1083
+ /**
1084
+ * @ignore
1085
+ */
1086
+ function _getid(key) {
1087
+ return {
1088
+ row: Math.floor(key / 1000) | 0,
1089
+ col: (key % 1000) | 0
1090
+ };
1091
+ }