x4js 1.5.18 → 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 -46
  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,889 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \/ / / _
4
- * \ / /_| |_
5
- * / \____ _|
6
- * /__/\__\ |_|
7
- *
8
- * @file gridview.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
- const T_UPDATE = Symbol('update');
30
- /**
31
- * todo: sizable column
32
- * todo: button in a column
33
- */
34
- import { x4document } from './x4dom';
35
- import { HLayout, VLayout } from './layout';
36
- import { Component, EvDblClick, flyWrap, html, SizerOverlay, Flex } from './component';
37
- import { Label } from './label';
38
- import { _tr } from './i18n';
39
- import { downloadData, isFunction } from './tools';
40
- import { DataStore } from './datastore';
41
- import { EvContextMenu, EvSelectionChange, BasicEvent } from "./x4events";
42
- import { Icon } from './icon.js';
43
- export function EvGridCheck(rec, chk) {
44
- return BasicEvent({ rec, chk });
45
- }
46
- class ColHeader extends Component {
47
- m_sens;
48
- m_sorted;
49
- constructor(props, title) {
50
- super(props);
51
- this.m_sorted = false;
52
- this.m_sens = 'dn';
53
- this.setContent([
54
- new Component({
55
- tag: 'span',
56
- content: title
57
- }),
58
- new Icon({
59
- ref: 'sorter',
60
- cls: '@hidden sort',
61
- icon: 'var( --x4-icon-arrow-down )'
62
- })
63
- ]);
64
- }
65
- get sorted() {
66
- return this.m_sorted;
67
- }
68
- //set sorted( v ) {
69
- // this.m_sorted = v;
70
- // this.m_sens = 'dn';
71
- // this.itemWithRef<Icon>( 'sorter' ).show( v );
72
- //}
73
- sort(v, sens) {
74
- this.m_sorted = v;
75
- this.m_sens = sens;
76
- const ic = this.itemWithRef('sorter');
77
- ic.icon = this.m_sens == 'up' ? 'var( --x4-icon-arrow-down )' : 'var( --x4-icon-arrow-up )';
78
- ic.show(v);
79
- }
80
- get sens() {
81
- return this.m_sens;
82
- }
83
- toggleSens() {
84
- this.m_sens = this.m_sens == 'up' ? 'dn' : 'up';
85
- this.itemWithRef('sorter').icon = this.m_sens == 'up' ? 'var( --x4-icon-arrow-down )' : 'var( --x4-icon-arrow-up )';
86
- }
87
- }
88
- /**
89
- * gridview class
90
- */
91
- export class GridView extends VLayout {
92
- m_dataview;
93
- m_data_cx;
94
- m_columns;
95
- m_view_el;
96
- m_container;
97
- m_header;
98
- m_footer;
99
- m_empty_msg;
100
- m_empty_text;
101
- m_selection;
102
- m_itemHeight;
103
- m_topIndex;
104
- m_visible_rows; // shown elements
105
- m_hasMarks;
106
- m_marks; // checked elements
107
- m_recycler;
108
- m_rowClassifier;
109
- constructor(props) {
110
- super(props);
111
- this.m_columns = props.columns;
112
- this.m_hasMarks = props.hasMarks ?? false;
113
- this.m_marks = new Set();
114
- // prepend the checkable column
115
- if (this.m_hasMarks) {
116
- this.m_columns.unshift({
117
- id: 'id',
118
- title: '',
119
- width: 30,
120
- renderer: (e) => this._renderCheck(e)
121
- });
122
- }
123
- this.setAttribute('tabindex', 0);
124
- this.m_topIndex = 0;
125
- this.m_itemHeight = 0;
126
- this.m_recycler = [];
127
- this.m_rowClassifier = props.calcRowClass;
128
- this.m_empty_text = props.empty_text ?? _tr.global.empty_list;
129
- //this.setDomEvent('create', this._handleCreate, this);
130
- this.setDomEvent('click', (e) => this._itemClick(e));
131
- this.setDomEvent('dblclick', (e) => this._itemDblClick(e));
132
- this.setDomEvent('contextmenu', (e) => this._itemMenu(e));
133
- this.setDomEvent('keydown', (e) => this._handleKey(e));
134
- this.setStore(props.store);
135
- }
136
- componentCreated() {
137
- this._updateScroll(true);
138
- }
139
- /**
140
- *
141
- */
142
- _moveSel(sens, select = true) {
143
- let sel = this.m_selection;
144
- let scrolltype = null;
145
- if (sel === undefined) {
146
- sel = this.m_dataview.getByIndex(0).getID();
147
- }
148
- else {
149
- let index = this.m_dataview.indexOfId(this.m_selection);
150
- if (sens == 1) {
151
- index++;
152
- }
153
- else if (sens == -1) {
154
- index--;
155
- }
156
- else if (sens == 2) {
157
- index += this.m_visible_rows.length - 1;
158
- }
159
- else if (sens == -2) {
160
- index -= this.m_visible_rows.length - 1;
161
- }
162
- if (sens < 0) {
163
- scrolltype = 'start';
164
- }
165
- else {
166
- scrolltype = 'end';
167
- }
168
- if (index < 0) {
169
- index = 0;
170
- }
171
- else if (index >= this.m_dataview.count) {
172
- index = this.m_dataview.count - 1;
173
- }
174
- sel = this.m_dataview.getByIndex(index).getID();
175
- }
176
- if (this.m_selection != sel && select) {
177
- this._selectItem(sel, null, scrolltype);
178
- }
179
- return sel;
180
- }
181
- /**
182
- *
183
- */
184
- _handleKey(event) {
185
- if (!this.m_dataview || this.m_dataview.count == 0) {
186
- return;
187
- }
188
- switch (event.key) {
189
- case 'ArrowDown':
190
- case 'Down': {
191
- this._moveSel(1);
192
- break;
193
- }
194
- case 'ArrowUp':
195
- case 'Up': {
196
- this._moveSel(-1);
197
- break;
198
- }
199
- case 'PageUp': {
200
- this._moveSel(-2);
201
- break;
202
- }
203
- case 'PageDown': {
204
- this._moveSel(2);
205
- break;
206
- }
207
- }
208
- }
209
- /**
210
- *
211
- */
212
- getNextSel(sens) {
213
- return this._moveSel(sens, false);
214
- }
215
- _scrollIntoView(id, sens) {
216
- let itm = this._findItem(id);
217
- if (itm) {
218
- itm.scrollIntoView({
219
- block: 'center' //<ScrollLogicalPosition>sens ?? 'nearest'
220
- });
221
- }
222
- else {
223
- this.m_topIndex = this.m_dataview.indexOfId(id);
224
- this.m_view_el.dom.scrollTop = this.m_topIndex * this.m_itemHeight;
225
- this._buildItems();
226
- this._scrollIntoView(id);
227
- }
228
- }
229
- /**
230
- * change the list of item displayed
231
- * @param items - new array of items
232
- */
233
- setStore(store) {
234
- this.m_selection = undefined;
235
- if (store instanceof DataStore) {
236
- this.m_dataview = store.createView();
237
- }
238
- else {
239
- this.m_dataview = store;
240
- }
241
- if (this.m_hasMarks) {
242
- this.clearMarks();
243
- }
244
- // unlink previous observer
245
- if (this.m_data_cx) {
246
- this.m_data_cx.dispose();
247
- }
248
- if (this.m_dataview) {
249
- this.m_data_cx = this.m_dataview.on('view_change', (ev) => {
250
- if (ev.action == 'change') {
251
- this.m_selection = undefined;
252
- }
253
- this._updateScroll(true);
254
- });
255
- //this.update( );
256
- this._updateScroll(true);
257
- }
258
- }
259
- getView() {
260
- return this.m_dataview;
261
- }
262
- /**
263
- * return the current selection (row id) or null
264
- */
265
- getSelection() {
266
- return this.m_selection;
267
- }
268
- getSelRec() {
269
- if (this.m_selection) {
270
- return this.m_dataview.getById(this.m_selection);
271
- }
272
- return null;
273
- }
274
- setSelection(recId) {
275
- this._selectItem(recId, null, 'center');
276
- }
277
- /** @ignore */
278
- render() {
279
- this.m_recycler = [];
280
- this.m_container = new Component({
281
- cls: 'content',
282
- });
283
- this.m_empty_msg = new Label({
284
- cls: 'empty-msg',
285
- text: ''
286
- });
287
- this.m_view_el = new Component({
288
- cls: '@scroll-view',
289
- flex: 1,
290
- dom_events: {
291
- sizechange: () => this._updateScroll(true),
292
- scroll: () => this._updateScroll(false)
293
- },
294
- content: this.m_container
295
- });
296
- let flex = false;
297
- let cols = this.m_columns.map((col, index) => {
298
- let cls = '@cell';
299
- if (col.cls) {
300
- cls += ' ' + col.cls;
301
- }
302
- let comp = new ColHeader({
303
- cls,
304
- flex: col.flex,
305
- sizable: 'right',
306
- style: {
307
- width: col.width
308
- },
309
- dom_events: {
310
- click: (ev) => {
311
- let t = flyWrap(ev.target);
312
- if (!t.hasClass('@sizer-overlay')) { // avoid sizer click
313
- this._sortCol(col);
314
- ev.preventDefault();
315
- }
316
- }
317
- }
318
- }, col.title);
319
- const resizeCol = (ev) => {
320
- this._on_col_resize(index, ev.size.width);
321
- if (this.m_footer) {
322
- let col = Component.getElement(this.m_footer.dom.childNodes[index]);
323
- if (col) {
324
- col.setStyleValue('width', ev.size.width);
325
- }
326
- }
327
- };
328
- new SizerOverlay({
329
- target: comp,
330
- sens: 'right',
331
- events: { resize: (e) => resizeCol(e) }
332
- });
333
- if (col.flex) {
334
- flex = true;
335
- }
336
- col.$hdr = comp;
337
- return comp;
338
- });
339
- cols.push(new Flex({
340
- ref: 'flex',
341
- cls: flex ? '@hidden' : ''
342
- }));
343
- // compute full width
344
- let full_width = 0;
345
- this.m_columns.forEach((col) => {
346
- full_width += col.width ?? 0;
347
- });
348
- this.m_header = new HLayout({
349
- cls: '@header',
350
- content: cols,
351
- style: {
352
- minWidth: full_width
353
- }
354
- });
355
- if (this.m_props.hasFooter) {
356
- let foots = this.m_columns.map((col, index) => {
357
- let cls = '@cell';
358
- if (col.align) {
359
- cls += ' ' + col.align;
360
- }
361
- if (col.cls) {
362
- cls += ' ' + col.cls;
363
- }
364
- let comp = new Component({
365
- cls,
366
- data: { col: index },
367
- flex: col.flex,
368
- style: {
369
- width: col.width
370
- }
371
- });
372
- col.$ftr = comp;
373
- return comp;
374
- });
375
- foots.push(new Flex({
376
- ref: 'flex',
377
- cls: flex ? '@hidden' : ''
378
- }));
379
- this.m_footer = new HLayout({
380
- cls: '@footer',
381
- content: foots,
382
- style: {
383
- minWidth: full_width
384
- }
385
- });
386
- }
387
- else {
388
- this.m_footer = null;
389
- }
390
- this.setContent([
391
- this.m_header,
392
- this.m_view_el,
393
- this.m_footer,
394
- this.m_empty_msg,
395
- ]);
396
- }
397
- _on_col_resize(col, width) {
398
- const _col = this.m_columns[col];
399
- let updateFlex = false;
400
- if (width >= 0) {
401
- _col.width = width;
402
- if (_col.flex) {
403
- _col.$hdr.removeClass('@flex');
404
- _col.$ftr?.removeClass('@flex');
405
- _col.flex = undefined;
406
- updateFlex = true;
407
- }
408
- }
409
- else if (width < 0 && !_col.flex) {
410
- _col.$hdr.addClass('@flex');
411
- _col.$ftr?.addClass('@flex');
412
- _col.flex = 1;
413
- updateFlex = true;
414
- }
415
- if (updateFlex) {
416
- let flex = false;
417
- this.m_columns.forEach(c => {
418
- if (c.flex) {
419
- flex = true;
420
- }
421
- });
422
- this.m_header.itemWithRef('flex')?.show(flex ? false : true);
423
- if (this.m_footer) {
424
- this.m_footer.itemWithRef('flex')?.show(flex ? false : true);
425
- }
426
- }
427
- this._updateScroll(true);
428
- }
429
- /**
430
- *
431
- */
432
- sortCol(name, asc = true) {
433
- const col = this.m_columns.find(c => c.id == name);
434
- if (col === undefined) {
435
- console.assert(false, "unknown field " + name + " in grid.sortCol");
436
- return;
437
- }
438
- this._sortCol(col, asc ? "dn" : "up");
439
- }
440
- /**
441
- *
442
- */
443
- _sortCol(col, sens = "up") {
444
- if (col.sortable === false) {
445
- return;
446
- }
447
- this.m_columns.forEach((c) => {
448
- if (c !== col) {
449
- c.$hdr.sort(false, "dn");
450
- }
451
- });
452
- const $hdr = col.$hdr;
453
- if ($hdr.sorted) {
454
- $hdr.toggleSens();
455
- }
456
- else {
457
- $hdr.sort(true, sens);
458
- }
459
- if (this.m_dataview) {
460
- this.m_dataview.sort([
461
- { field: col.id, ascending: $hdr.sens == 'dn' ? false : true }
462
- ]);
463
- }
464
- }
465
- /**
466
- *
467
- */
468
- _computeItemHeight() {
469
- let gr = x4document.createElement('div');
470
- gr.classList.add('x-row');
471
- let gv = x4document.createElement('div');
472
- gv.classList.add('x-grid-view');
473
- gv.style.position = 'absolute';
474
- gv.style.top = '-1000px';
475
- gv.appendChild(gr);
476
- this.dom.appendChild(gv);
477
- let rc = gr.getBoundingClientRect();
478
- this.dom.removeChild(gv);
479
- this.m_itemHeight = rc.height;
480
- }
481
- _createRow(props) {
482
- let row;
483
- if (this.m_recycler.length) {
484
- row = this.m_recycler.pop();
485
- row.clearClasses();
486
- row.addClass(props.cls);
487
- row.setContent(props.content);
488
- row.setStyle(props.style);
489
- for (let n in props.data) {
490
- row.setData(n, props.data[n]);
491
- }
492
- }
493
- else {
494
- row = new HLayout(props);
495
- }
496
- if (!row.dom) {
497
- this.m_container.appendChild(row);
498
- }
499
- return row;
500
- }
501
- _buildItems(canOpt = true) {
502
- let rc = this.getBoundingRect();
503
- let rh = this.m_header.getBoundingRect();
504
- let height = rc.height - rh.height + this.m_itemHeight;
505
- if (this.m_itemHeight == 0) {
506
- this._computeItemHeight();
507
- }
508
- let top = this.m_topIndex * this.m_itemHeight;
509
- let y = 0;
510
- let cidx = 0;
511
- let index = this.m_topIndex;
512
- let count = this.m_dataview ? this.m_dataview.count : 0;
513
- let full_width = 0; // todo: +4 pixel of left border
514
- let even = this.m_topIndex & 1 ? true : false;
515
- // compute full width
516
- this.m_columns.forEach((col) => {
517
- full_width += col.width ?? 0;
518
- });
519
- // if items height make scroll visible, update header width
520
- if (((count + 1) * this.m_itemHeight) >= height) {
521
- let w = Component.getScrollbarSize();
522
- this.m_header.setStyleValue("paddingRight", w);
523
- this.m_footer?.setStyleValue("paddingRight", w);
524
- }
525
- else {
526
- this.m_header.setStyleValue("paddingRight", 0);
527
- this.m_footer?.setStyleValue("paddingRight", 0);
528
- }
529
- // passe 0 - all created cells are moved to the recycler
530
- if (this.m_visible_rows) {
531
- this.m_visible_rows.forEach((c) => {
532
- this.m_recycler.push(c);
533
- });
534
- }
535
- this.m_visible_rows = [];
536
- let limit = 100;
537
- while (y < height && index < count && --limit > 0) {
538
- let rec = this.m_dataview.getByIndex(index);
539
- let rowid = rec.getID();
540
- let crow = canOpt ? this.m_recycler.findIndex((r) => r.getData('row-id') == rowid) : -1;
541
- if (crow >= 0) {
542
- let rrow = this.m_recycler.splice(crow, 1)[0];
543
- rrow.setStyle({
544
- top: y + top,
545
- minWidth: full_width,
546
- });
547
- if (this.m_hasMarks) {
548
- rrow.setClass('@marked', this.m_marks.has(rowid));
549
- }
550
- rrow.removeClass('@hidden');
551
- rrow.setClass('@selected', this.m_selection === rowid);
552
- this.m_visible_rows[cidx] = rrow;
553
- }
554
- else {
555
- let cols = this.m_columns.map(col => {
556
- let cls = '@cell';
557
- if (col.align) {
558
- cls += ' ' + col.align;
559
- }
560
- if (col.cls) {
561
- cls += ' ' + col.cls;
562
- }
563
- let cell;
564
- if (col.renderer) {
565
- cell = col.renderer(rec);
566
- if (cell) {
567
- cell.addClass(cls);
568
- cell.setStyleValue('width', col.width);
569
- if (col.flex !== undefined) {
570
- cell.addClass('@flex');
571
- cell.setStyleValue('flex', col.flex);
572
- }
573
- }
574
- }
575
- else {
576
- let fmt = col.formatter;
577
- let text;
578
- if (fmt && fmt instanceof Function) {
579
- text = fmt(rec.getRaw(col.id), rec);
580
- }
581
- else {
582
- text = rec.getField(col.id);
583
- }
584
- cell = new Component({
585
- cls,
586
- width: col.width,
587
- content: html `<span>${text}</span>`,
588
- flex: col.flex
589
- });
590
- }
591
- return cell;
592
- });
593
- let cls = '@row @hlayout center';
594
- if (this.m_hasMarks) {
595
- if (this.m_marks.has(rowid)) {
596
- cls += ' @marked';
597
- }
598
- }
599
- if (this.m_selection === rowid) {
600
- cls += ' @selected';
601
- }
602
- let row = this.m_visible_rows[cidx] = this._createRow({
603
- cls,
604
- content: cols,
605
- style: {
606
- top: y + top,
607
- minWidth: full_width,
608
- },
609
- data: {
610
- 'row-id': rowid,
611
- 'row-idx': index
612
- }
613
- });
614
- row.addClass(even ? 'even' : 'odd');
615
- even = !even;
616
- if (this.m_rowClassifier) {
617
- this.m_rowClassifier(rec, row);
618
- }
619
- }
620
- y += this.m_itemHeight;
621
- index++;
622
- cidx++;
623
- }
624
- // if some cells are still in cache, hide them
625
- this.m_recycler.forEach((c) => {
626
- c.addClass('@hidden');
627
- });
628
- //this.m_container.setContent(<ComponentContent>this.m_visible_rows);
629
- let show = !count;
630
- let msg = (this.m_empty_text instanceof Function) ? this.m_empty_text() : this.m_empty_text;
631
- this.m_empty_msg.text = msg;
632
- if (show && msg.length == 0) {
633
- show = false;
634
- }
635
- this.m_empty_msg.show(show);
636
- if (full_width < rc.width) {
637
- this.m_header.setStyleValue('width', null);
638
- this.m_footer?.setStyleValue('width', null);
639
- this.m_container.setStyle({
640
- height: count * this.m_itemHeight,
641
- width: null
642
- });
643
- }
644
- else {
645
- this.m_header.setStyleValue('width', full_width + 1000);
646
- this.m_footer?.setStyleValue('width', full_width + 1000);
647
- this.m_container.setStyle({
648
- height: count * this.m_itemHeight,
649
- width: full_width
650
- });
651
- }
652
- }
653
- /**
654
- *
655
- */
656
- _updateScroll(forceUpdate) {
657
- if (!this.m_view_el || !this.m_view_el.dom) {
658
- return;
659
- }
660
- const update = () => {
661
- // element destroyed between updateScroll and now
662
- if (!this.dom) {
663
- return;
664
- }
665
- let newTop = Math.floor(this.m_view_el.dom.scrollTop / (this.m_itemHeight || 1));
666
- if (newTop != this.m_topIndex || forceUpdate) {
667
- this.m_topIndex = newTop;
668
- this._buildItems(!forceUpdate);
669
- }
670
- let newLeft = this.m_view_el.dom.scrollLeft;
671
- this.m_header.setStyleValue('left', -newLeft);
672
- this.m_footer?.setStyleValue('left', -newLeft);
673
- };
674
- if (forceUpdate) {
675
- this.singleShot(update, 10);
676
- }
677
- else {
678
- update();
679
- }
680
- }
681
- /** @ignore */
682
- _rowFromTarget(dom) {
683
- let self = this.dom;
684
- while (dom && dom != self) {
685
- let itm = Component.getElement(dom);
686
- if (itm) {
687
- let id = itm.getData('row-id');
688
- if (id !== undefined) {
689
- return { id, itm };
690
- }
691
- }
692
- dom = dom.parentElement;
693
- }
694
- return undefined;
695
- }
696
- _itemClick(e) {
697
- let hit = this._rowFromTarget(e.target);
698
- if (hit) {
699
- this._selectItem(hit.id, hit.itm);
700
- }
701
- else {
702
- this._selectItem(undefined, undefined);
703
- }
704
- }
705
- _itemDblClick(e) {
706
- let hit = this._rowFromTarget(e.target);
707
- if (hit) {
708
- this._selectItem(hit.id, hit.itm);
709
- let rec = this.m_dataview.getById(hit.id);
710
- this.emit('dblClick', EvDblClick(rec));
711
- if (this.m_hasMarks) {
712
- this._toggleMark(rec);
713
- }
714
- }
715
- }
716
- /** @ignore */
717
- _itemMenu(e) {
718
- let dom = e.target, self = this.dom;
719
- while (dom && dom != self) {
720
- let itm = Component.getElement(dom), id = itm?.getData('row-id');
721
- if (id !== undefined) {
722
- this._selectItem(id, itm);
723
- let idx = itm.getData('row-idx');
724
- let rec = this.m_dataview.getByIndex(idx);
725
- this._showItemContextMenu(e, rec);
726
- e.preventDefault();
727
- return;
728
- }
729
- dom = dom.parentElement;
730
- }
731
- }
732
- /**
733
- *
734
- */
735
- _findItem(id) {
736
- for (let i = 0; i < this.m_visible_rows.length; i++) {
737
- let itm = this.m_visible_rows[i];
738
- if (itm.getData('row-id') === id) {
739
- return itm;
740
- }
741
- }
742
- return null;
743
- }
744
- /**
745
- * @ignore
746
- * called when an item is selected by mouse
747
- */
748
- _selectItem(item, dom_item, scrollIntoView) {
749
- if (this.m_selection !== undefined) {
750
- let old = this._findItem(this.m_selection);
751
- if (old) {
752
- old.removeClass('@selected');
753
- }
754
- }
755
- this.m_selection = item;
756
- if (item) {
757
- if (scrollIntoView) {
758
- this._scrollIntoView(item, scrollIntoView);
759
- }
760
- if (!dom_item) {
761
- dom_item = this._findItem(item);
762
- }
763
- if (dom_item) {
764
- dom_item.addClass('@selected');
765
- }
766
- let rec = this.m_dataview.getById(item);
767
- this.emit('selectionChange', EvSelectionChange(rec));
768
- }
769
- else {
770
- this.emit('selectionChange', EvSelectionChange(null));
771
- }
772
- }
773
- /**
774
- *
775
- */
776
- _showItemContextMenu(event, item) {
777
- this.emit('contextMenu', EvContextMenu(event, item));
778
- }
779
- /**
780
- *
781
- */
782
- clearSelection() {
783
- this._selectItem(null, null);
784
- }
785
- /**
786
- * todo: moveto datastore
787
- */
788
- exportData(filename) {
789
- let data = '';
790
- const fsep = '\t';
791
- const lsep = '\r\n';
792
- let rec = '';
793
- this.m_columns.map((col) => {
794
- if (rec.length) {
795
- rec += fsep;
796
- }
797
- rec += col.title;
798
- });
799
- data += rec + lsep;
800
- let count = this.m_dataview.count;
801
- for (let i = 0; i < count; i++) {
802
- let record = this.m_dataview.getByIndex(i);
803
- rec = '';
804
- let cols = this.m_columns.map((col) => {
805
- let text = record.getField(col.id);
806
- let fmt = col.formatter;
807
- if (fmt && fmt instanceof Function) {
808
- text = fmt(text, record);
809
- }
810
- if (rec.length > 0) {
811
- rec += fsep;
812
- }
813
- rec += text;
814
- });
815
- data += rec + lsep;
816
- }
817
- //todo: review that
818
- data = data.replace(/[àâä]/gm, 'a');
819
- data = data.replace(/[éèê]/gm, 'e');
820
- data = data.replace(/[îï]/gm, 'i');
821
- data = data.replace(/[ûüù]/gm, 'u');
822
- data = data.replace(/ /gm, ' '); // non breaking space
823
- downloadData(data, 'text/csv', filename);
824
- }
825
- set empty_text(text) {
826
- this.m_empty_msg.text = text;
827
- }
828
- _renderCheck(rec) {
829
- let icon = '--x4-icon-square';
830
- if (this.m_marks.has(rec.getID())) {
831
- icon = '--x4-icon-square-check';
832
- }
833
- return new Icon({ icon: `var(${icon})` });
834
- }
835
- _toggleMark(rec) {
836
- let id = rec.getID();
837
- let chk = false;
838
- if (this.m_marks.has(id)) {
839
- this.m_marks.delete(id);
840
- }
841
- else {
842
- this.m_marks.add(id);
843
- chk = true;
844
- }
845
- this.emit('gridCheck', EvGridCheck(rec, chk));
846
- this._buildItems(false);
847
- }
848
- getMarks() {
849
- let ids = [];
850
- for (const v of this.m_marks.values()) {
851
- ids.push(v);
852
- }
853
- return ids;
854
- }
855
- clearMarks() {
856
- if (this.m_marks.size) {
857
- this.m_marks = new Set();
858
- this._buildItems(false);
859
- }
860
- }
861
- setFooterData(rec) {
862
- if (!this.m_footer) {
863
- return;
864
- }
865
- this.m_footer.enumChilds((c) => {
866
- let cid = c.getData('col');
867
- if (cid) {
868
- let col = this.m_columns[cid];
869
- let value = rec[col.id];
870
- if (value !== undefined) {
871
- if (isFunction(value)) { // FooterRenderer
872
- value(c);
873
- }
874
- else {
875
- let text;
876
- const fmt = col.formatter;
877
- if (fmt && fmt instanceof Function) {
878
- text = fmt(value, rec);
879
- }
880
- else {
881
- text = value;
882
- }
883
- c.setContent(text, false);
884
- }
885
- }
886
- }
887
- });
888
- }
889
- }