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,546 +0,0 @@
1
- "use strict";
2
- /**
3
- * ___ ___ __
4
- * \ \_/ / / _
5
- * \ / /_| |_
6
- * / _ \____ _|
7
- * /__/ \__\ |_|
8
- *
9
- * @file listview.ts
10
- * @author Etienne Cochard
11
- *
12
- * Copyright (c) 2019-2022 R-libre ingenierie
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18
- * of the Software, and to permit persons to whom the Software is furnished to do so,
19
- * subject to the following conditions:
20
- * The above copyright notice and this permission notice shall be included in all copies
21
- * or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
24
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
25
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
- **/
30
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
31
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
- return new (P || (P = Promise))(function (resolve, reject) {
33
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37
- });
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.PopupListView = exports.EvCancel = exports.ListView = void 0;
41
- const x4dom_1 = require("./x4dom");
42
- const component_1 = require("./component");
43
- const layout_1 = require("./layout");
44
- const popup_1 = require("./popup");
45
- const tools_1 = require("./tools");
46
- const menu_1 = require("./menu");
47
- const x4events_1 = require("./x4events");
48
- ;
49
- /**
50
- * Standard listview class
51
- */
52
- class ListView extends layout_1.VLayout {
53
- constructor(props) {
54
- super(props);
55
- this.setDomEvent('keydown', (e) => this.handleKey(e));
56
- this.setDomEvent('click', (e) => this._handleClick(e));
57
- this.setDomEvent('dblclick', (e) => this._handleClick(e));
58
- this.setDomEvent('contextmenu', (e) => this._handleCtxMenu(e));
59
- this._setTabIndex(props.tabIndex, 0);
60
- this.mapPropEvents(props, 'click', 'dblClick', 'contextMenu', 'selectionChange', 'cancel');
61
- }
62
- componentCreated() {
63
- if (this.m_props.virtual) {
64
- this._buildItems();
65
- }
66
- else if (this.m_props.populate) {
67
- this.items = this.m_props.populate(null);
68
- }
69
- }
70
- render(props) {
71
- var _a;
72
- props.items = props.items || [];
73
- props.gadgets = props.gadgets;
74
- props.renderItem = props.renderItem;
75
- props.virtual = (_a = props.virtual) !== null && _a !== void 0 ? _a : false;
76
- this.m_topIndex = 0;
77
- if (props.virtual) {
78
- console.assert(props.itemHeight !== undefined);
79
- this.m_itemHeight = props.itemHeight;
80
- this.m_cache = new Map();
81
- this.addClass('virtual');
82
- }
83
- else {
84
- this.m_itemHeight = undefined;
85
- this.m_cache = undefined;
86
- }
87
- this._buildContent();
88
- }
89
- /**
90
- * change the list of item displayed
91
- * @param items - new array of items
92
- * @deprecated
93
- */
94
- set items(items) {
95
- this.setItems(items);
96
- }
97
- get items() {
98
- return this.m_props.items;
99
- }
100
- /**
101
- * change the list of item displayed
102
- * @param items - new array of items
103
- */
104
- setItems(items, keepSel = true) {
105
- this.m_props.items = items;
106
- if (!keepSel) {
107
- this.m_selection = null;
108
- }
109
- if (!this.m_container) {
110
- this._buildContent();
111
- }
112
- else {
113
- this._buildItems();
114
- }
115
- }
116
- handleKey(ev) {
117
- let moveSel = (sens) => {
118
- let items;
119
- if ((0, tools_1.isFunction)(this.m_props.items)) {
120
- items = this.m_props.items();
121
- this.m_props.items = items;
122
- }
123
- else {
124
- items = this.m_props.items;
125
- }
126
- let newsel;
127
- if (!this.m_selection) {
128
- if (items) {
129
- newsel = items[0];
130
- }
131
- }
132
- else {
133
- let index = items.findIndex((item) => item === this.m_selection.item);
134
- if (sens > 0 && index < (items.length - 1)) {
135
- newsel = items[index + 1];
136
- }
137
- else if (sens < 0 && index > 0) {
138
- newsel = items[index - 1];
139
- }
140
- else {
141
- newsel = this.selection;
142
- }
143
- }
144
- let citem = this._findItemWithId(newsel === null || newsel === void 0 ? void 0 : newsel.id);
145
- this._selectItem(newsel, citem, true);
146
- };
147
- switch (ev.key) {
148
- case 'ArrowDown': {
149
- moveSel(1);
150
- ev.preventDefault();
151
- ev.stopPropagation();
152
- break;
153
- }
154
- case 'ArrowUp': {
155
- moveSel(-1);
156
- ev.preventDefault();
157
- ev.stopPropagation();
158
- break;
159
- }
160
- }
161
- }
162
- /** @ignore */
163
- _buildContent() {
164
- let props = this.m_props;
165
- if (props.virtual) {
166
- this.m_container = new component_1.Container({
167
- cls: '@scroll-container',
168
- content: []
169
- });
170
- this.m_view = new component_1.Container({
171
- cls: '@scroll-view',
172
- flex: 1,
173
- content: this.m_container,
174
- dom_events: {
175
- sizechange: () => this._updateScroll(true),
176
- scroll: () => this._updateScroll(false),
177
- }
178
- });
179
- this.setContent([
180
- this.m_view,
181
- props.gadgets ? new layout_1.HLayout({
182
- cls: 'gadgets',
183
- content: props.gadgets
184
- }) : null,
185
- ]);
186
- }
187
- else {
188
- this.m_view = undefined;
189
- this.m_container = new layout_1.VLayout({
190
- cls: '@scroll-container',
191
- content: []
192
- });
193
- this.addClass('@scroll-view');
194
- this.setContent(this.m_container, false);
195
- }
196
- if (props.virtual) {
197
- this.m_container.setStyleValue('height', props.items.length * this.m_itemHeight);
198
- }
199
- if (this.dom || !props.virtual) {
200
- this._buildItems();
201
- }
202
- }
203
- /**
204
- *
205
- */
206
- _updateScroll(forceUpdate) {
207
- const update = () => {
208
- let newTop = Math.floor(this.m_view.dom.scrollTop / this.m_itemHeight);
209
- if (newTop != this.m_topIndex || forceUpdate) {
210
- this.m_topIndex = newTop;
211
- this._buildItems();
212
- }
213
- };
214
- if (forceUpdate) {
215
- this.startTimer('scroll', 10, false, update);
216
- }
217
- else {
218
- update();
219
- }
220
- }
221
- _buildItems() {
222
- var _a;
223
- return __awaiter(this, void 0, void 0, function* () {
224
- let props = this.m_props;
225
- let items = [];
226
- let list_items = props.items;
227
- if ((0, tools_1.isFunction)(list_items)) {
228
- list_items = list_items();
229
- }
230
- let selId = (_a = this.m_selection) === null || _a === void 0 ? void 0 : _a.item.id;
231
- let selFnd = false;
232
- if (props.virtual) {
233
- let rc = this.getBoundingRect();
234
- let limit = 100;
235
- let y = 0;
236
- let top = this.m_topIndex * this.m_itemHeight;
237
- let index = this.m_topIndex;
238
- let height = rc.height;
239
- let count = props.items.length;
240
- let newels = [];
241
- let cache = this.m_cache;
242
- this.m_cache = new Map();
243
- while (y < height && index < count && --limit > 0) {
244
- let it = props.items[index];
245
- let itm;
246
- if (cache.has(it.id)) {
247
- itm = cache.get(it.id); // reuse it
248
- cache.delete(it.id); // cache will contain only elements to remove
249
- }
250
- else {
251
- itm = this._renderItem(it);
252
- newels.push(itm);
253
- }
254
- if (selId == it.id) {
255
- itm.addClass('@selected');
256
- selFnd = true;
257
- }
258
- itm.setStyleValue('top', top + y);
259
- items.push(itm);
260
- this.m_cache.set(it.id, itm); // keep it for next time
261
- y += this.m_itemHeight;
262
- index++;
263
- }
264
- // all element remaining here are to remove
265
- cache.forEach((c) => {
266
- c.dispose();
267
- });
268
- // append new elements
269
- this.m_container.appendChild(newels);
270
- this.m_container.setStyleValue('height', count * this.m_itemHeight);
271
- // check that it's still existing
272
- if (!selFnd) {
273
- if (!list_items.some(it => selId == it.id)) {
274
- this.m_selection = null;
275
- }
276
- }
277
- }
278
- else {
279
- list_items.forEach((it) => {
280
- let itm = this._renderItem(it);
281
- if (selId == it.id) {
282
- itm.addClass('@selected');
283
- selFnd = true;
284
- }
285
- items.push(itm);
286
- });
287
- this.m_container.setContent(items, false);
288
- if (!selFnd) {
289
- this.m_selection = null;
290
- }
291
- }
292
- if (this.m_defer_sel) {
293
- let t = this.m_defer_sel;
294
- this.m_defer_sel = undefined;
295
- this.selection = t;
296
- }
297
- });
298
- }
299
- /** @ignore
300
- * default rendering of an item
301
- */
302
- _renderItem(item) {
303
- const newItem = this.onRenderItem(item);
304
- newItem.setAttribute('data-id', item.id);
305
- newItem.addClass('@list-item');
306
- newItem.setData('item-id', item.id);
307
- return newItem;
308
- }
309
- onRenderItem(item) {
310
- if (this.m_props.renderItem) {
311
- return this.m_props.renderItem(item);
312
- }
313
- else {
314
- return new layout_1.HLayout({ content: item.text });
315
- }
316
- }
317
- /** @ignore */
318
- _handleClick(e) {
319
- e.stopImmediatePropagation();
320
- e.preventDefault();
321
- let dom = e.target, self = this.dom, list_items = this.m_props.items; // already created by build
322
- // go up until we find something interesting
323
- while (dom && dom != self) {
324
- let itm = component_1.Component.getElement(dom), id = itm === null || itm === void 0 ? void 0 : itm.getData('item-id');
325
- if (id !== undefined) {
326
- // find the element
327
- let item = list_items.find((item) => item.id == id);
328
- if (item) {
329
- let event;
330
- if (e.type == 'click') {
331
- event = (0, x4events_1.EvClick)(item);
332
- this.emit('click', event);
333
- }
334
- else {
335
- event = (0, component_1.EvDblClick)(item);
336
- this.emit('dblClick', event);
337
- }
338
- if (!event.defaultPrevented) {
339
- this._selectItem(item, itm);
340
- }
341
- }
342
- else {
343
- this._selectItem(null, null);
344
- }
345
- return;
346
- }
347
- dom = dom.parentElement;
348
- }
349
- this._selectItem(null, null);
350
- }
351
- /** @ignore */
352
- _handleCtxMenu(e) {
353
- e.preventDefault();
354
- let dom = e.target, self = this.dom, list_items = this.m_props.items; // already created by build;
355
- while (dom && dom != self) {
356
- let itm = component_1.Component.getElement(dom), id = itm === null || itm === void 0 ? void 0 : itm.getData('item-id');
357
- if (id) {
358
- // find the element
359
- let item = list_items.find((item) => item.id == id);
360
- if (item) {
361
- this._selectItem(item, itm);
362
- this.emit('contextMenu', (0, x4events_1.EvContextMenu)(e, item));
363
- }
364
- return;
365
- }
366
- dom = dom.parentElement;
367
- }
368
- this.emit('contextMenu', (0, x4events_1.EvContextMenu)(e, null));
369
- }
370
- /**
371
- * @ignore
372
- * called when an item is selected by mouse
373
- */
374
- _selectItem(item, citem, notify = true) {
375
- if (this.m_selection && this.m_selection.citem) {
376
- this.m_selection.citem.removeClass('@selected');
377
- }
378
- this.m_selection = item ? {
379
- item: item,
380
- citem: citem
381
- } : null;
382
- if (this.m_selection && this.m_selection.citem) {
383
- this.m_selection.citem.addClass('@selected');
384
- }
385
- if (notify) {
386
- this.emit('selectionChange', (0, x4events_1.EvSelectionChange)(item));
387
- }
388
- }
389
- /**
390
- * return the current selection or null
391
- */
392
- get selection() {
393
- return this.m_selection ? this.m_selection.item : null;
394
- }
395
- set selection(id) {
396
- if (id === null || id === undefined) {
397
- this._selectItem(null, null);
398
- }
399
- else {
400
- if ((0, tools_1.isFunction)(this.m_props.items)) {
401
- this.m_defer_sel = id;
402
- }
403
- else {
404
- let item = this.m_props.items.find((item) => item.id == id);
405
- let citem = this._findItemWithId(item.id);
406
- this._selectItem(item, citem, false);
407
- }
408
- }
409
- }
410
- _findItemWithId(id) {
411
- let citem = null;
412
- if (this.dom) {
413
- // make the element visible to user
414
- // todo: problem with virtual listview
415
- this.m_container.enumChilds((c) => {
416
- if (c.getData('item-id') == id) {
417
- c.scrollIntoView();
418
- citem = c;
419
- return true;
420
- }
421
- });
422
- }
423
- return citem;
424
- }
425
- /**
426
- * append or prepend a new item
427
- * @param item
428
- * @param prepend
429
- * @param select
430
- */
431
- appendItem(item, prepend = false, select = true) {
432
- if (prepend) {
433
- this.m_props.items.unshift(item);
434
- }
435
- else {
436
- this.m_props.items.push(item);
437
- }
438
- if (select) {
439
- this.selection = null;
440
- }
441
- if (!this.m_container) {
442
- this._buildContent();
443
- }
444
- else {
445
- this._buildItems();
446
- }
447
- if (select) {
448
- this.selection = item.id;
449
- }
450
- }
451
- /**
452
- * update an item
453
- */
454
- updateItem(id, item) {
455
- var _a;
456
- // find item
457
- const idx = this.m_props.items.findIndex(itm => itm.id === id);
458
- if (idx < 0) {
459
- return;
460
- }
461
- // take care of selection
462
- let was_sel = false;
463
- if (this.m_selection && this.m_selection.item === this.m_props.items[idx]) {
464
- was_sel = true;
465
- }
466
- // replace it in the list
467
- this.m_props.items[idx] = item;
468
- // rebuild & replace it's line
469
- const oldDOM = (_a = this.queryItem(`[data-id="${item.id}"]`)) === null || _a === void 0 ? void 0 : _a.dom;
470
- if (oldDOM) {
471
- const _new = this._renderItem(item);
472
- if (was_sel) {
473
- _new.addClass('@selected');
474
- this.m_selection.citem = _new;
475
- this.m_selection.item = item;
476
- }
477
- const newDOM = _new._build();
478
- this.m_container.dom.replaceChild(newDOM, oldDOM);
479
- }
480
- }
481
- }
482
- exports.ListView = ListView;
483
- function EvCancel(context = null) {
484
- return (0, x4events_1.BasicEvent)({ context });
485
- }
486
- exports.EvCancel = EvCancel;
487
- /**
488
- *
489
- */
490
- class PopupListView extends popup_1.Popup {
491
- constructor(props) {
492
- super({ tabIndex: false });
493
- // todo: move into popup
494
- this._handleClick = (e) => {
495
- if (!this.dom) {
496
- return;
497
- }
498
- let newfocus = e.target;
499
- // child of this: ok
500
- if (this.dom.contains(newfocus)) {
501
- return;
502
- }
503
- // menu: ok
504
- let dest = component_1.Component.getElement(newfocus, menu_1.MenuItem);
505
- if (dest) {
506
- return;
507
- }
508
- this.signal('cancel', EvCancel());
509
- this.close();
510
- };
511
- this.enableMask(false);
512
- this.addClass("@non-maskable");
513
- props.tabIndex = false;
514
- this.m_list = new ListView(props);
515
- //this.m_list.addClass( '@fit' );
516
- this.setContent(this.m_list);
517
- this.mapPropEvents(props, 'cancel');
518
- }
519
- set items(items) {
520
- this.m_list.items = items;
521
- }
522
- handleKey(ev) {
523
- this.m_list.handleKey(ev);
524
- }
525
- // todo: move into popup
526
- show(modal) {
527
- x4dom_1.x4document.addEventListener('mousedown', this._handleClick);
528
- super.show(modal);
529
- }
530
- hide() {
531
- x4dom_1.x4document.removeEventListener('mousedown', this._handleClick);
532
- super.hide();
533
- }
534
- // todo: move into popup
535
- close() {
536
- x4dom_1.x4document.removeEventListener('mousedown', this._handleClick);
537
- super.close();
538
- }
539
- get selection() {
540
- return this.m_list.selection;
541
- }
542
- set selection(itemId) {
543
- this.m_list.selection = itemId;
544
- }
545
- }
546
- exports.PopupListView = PopupListView;