x4js 1.5.17 → 1.5.20

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