x4js 2.0.11 → 2.0.13
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.
- package/README.md +15 -15
- package/lib/README.txt +15 -15
- package/lib/cjs/x4.css +1 -1
- package/lib/cjs/x4.js +1 -1
- package/lib/esm/x4.css +1 -1
- package/lib/esm/x4.mjs +1 -1
- package/lib/src/components/base.scss +25 -26
- package/lib/src/components/boxes/boxes.module.scss +37 -37
- package/lib/src/components/boxes/boxes.ts +129 -125
- package/lib/src/components/breadcrumb/breadcrumb.scss +28 -0
- package/lib/src/components/breadcrumb/breadcrumb.ts +84 -0
- package/lib/src/components/breadcrumb/chevron-right.svg +1 -0
- package/lib/src/components/btngroup/btngroup.module.scss +28 -28
- package/lib/src/components/btngroup/btngroup.ts +119 -101
- package/lib/src/components/button/button.module.scss +154 -153
- package/lib/src/components/button/button.ts +117 -117
- package/lib/src/components/calendar/calendar.module.scss +162 -162
- package/lib/src/components/calendar/calendar.ts +326 -325
- package/lib/src/components/checkbox/check.svg +3 -3
- package/lib/src/components/checkbox/checkbox.module.scss +141 -141
- package/lib/src/components/checkbox/checkbox.ts +125 -124
- package/lib/src/components/colorinput/colorinput.module.scss +64 -64
- package/lib/src/components/colorinput/colorinput.ts +90 -87
- package/lib/src/components/colorpicker/colorpicker.module.scss +132 -132
- package/lib/src/components/colorpicker/colorpicker.ts +481 -476
- package/lib/src/components/combobox/combobox.module.scss +123 -120
- package/lib/src/components/combobox/combobox.ts +192 -190
- package/lib/src/components/combobox/updown.svg +3 -3
- package/lib/src/components/components.ts +34 -0
- package/lib/src/components/dialog/dialog.module.scss +71 -71
- package/lib/src/components/dialog/dialog.ts +94 -92
- package/lib/src/components/form/form.module.scss +34 -34
- package/lib/src/components/form/form.ts +41 -36
- package/lib/src/components/grid/datastore.ts +1298 -0
- package/lib/src/components/grid/gridview.ts +1108 -0
- package/lib/src/components/grid/memdb.ts +325 -0
- package/lib/src/components/header/header.module.scss +39 -39
- package/lib/src/components/header/header.ts +129 -123
- package/lib/src/components/icon/icon.module.scss +29 -29
- package/lib/src/components/icon/icon.ts +136 -134
- package/lib/src/components/image/image.module.scss +20 -20
- package/lib/src/components/image/image.ts +68 -66
- package/lib/src/components/input/input.module.scss +69 -69
- package/lib/src/components/input/input.ts +275 -274
- package/lib/src/components/label/label.module.scss +58 -52
- package/lib/src/components/label/label.ts +64 -55
- package/lib/src/components/link/link.ts +78 -0
- package/lib/src/components/listbox/listbox.module.scss +103 -103
- package/lib/src/components/listbox/listbox.ts +431 -427
- package/lib/src/components/menu/menu.module.scss +107 -107
- package/lib/src/components/menu/menu.ts +171 -168
- package/lib/src/components/messages/messages.module.scss +48 -47
- package/lib/src/components/messages/messages.ts +68 -63
- package/lib/src/components/normalize.scss +386 -386
- package/lib/src/components/notification/notification.module.scss +81 -81
- package/lib/src/components/notification/notification.ts +109 -108
- package/lib/src/components/panel/panel.module.scss +47 -47
- package/lib/src/components/panel/panel.ts +57 -56
- package/lib/src/components/popup/popup.module.scss +43 -43
- package/lib/src/components/popup/popup.ts +396 -395
- package/lib/src/components/progress/progress.module.scss +56 -56
- package/lib/src/components/progress/progress.ts +43 -42
- package/lib/src/components/rating/rating.module.scss +22 -22
- package/lib/src/components/rating/rating.ts +131 -125
- package/lib/src/components/shared.scss +90 -76
- package/lib/src/components/sizers/sizer.module.scss +89 -89
- package/lib/src/components/sizers/sizer.ts +123 -119
- package/lib/src/components/slider/slider.module.scss +70 -70
- package/lib/src/components/slider/slider.ts +147 -142
- package/lib/src/components/switch/switch.module.scss +126 -126
- package/lib/src/components/switch/switch.ts +61 -55
- package/lib/src/components/tabs/tabs.module.scss +46 -46
- package/lib/src/components/tabs/tabs.ts +168 -157
- package/lib/src/components/textarea/textarea.module.scss +59 -59
- package/lib/src/components/textarea/textarea.ts +60 -54
- package/lib/src/components/textedit/textedit.module.scss +113 -113
- package/lib/src/components/textedit/textedit.ts +83 -82
- package/lib/src/components/themes.scss +81 -77
- package/lib/src/components/tooltips/tooltips.scss +50 -50
- package/lib/src/components/tooltips/tooltips.ts +103 -102
- package/lib/src/components/treeview/treeview.module.scss +115 -115
- package/lib/src/components/treeview/treeview.ts +410 -403
- package/lib/src/components/viewport/viewport.module.scss +24 -24
- package/lib/src/components/viewport/viewport.ts +41 -38
- package/lib/src/core/component.ts +1002 -979
- package/lib/src/core/core_application.ts +44 -0
- package/lib/src/core/core_colors.ts +249 -249
- package/lib/src/core/core_dom.ts +471 -471
- package/lib/src/core/core_dragdrop.ts +200 -200
- package/lib/src/core/core_element.ts +97 -97
- package/lib/src/core/core_events.ts +149 -149
- package/lib/src/core/core_i18n.ts +377 -377
- package/lib/src/core/core_router.ts +221 -221
- package/lib/src/core/core_styles.ts +214 -214
- package/lib/src/core/core_svg.ts +550 -550
- package/lib/src/core/core_tools.ts +688 -673
- package/lib/src/demo/assets/radio.svg +3 -3
- package/lib/src/demo/index.html +11 -11
- package/lib/src/demo/main.scss +21 -21
- package/lib/src/demo/main.tsx +323 -323
- package/lib/src/types/scss.d.ts +4 -4
- package/lib/src/types/x4react.d.ts +8 -8
- package/lib/src/x4.scss +18 -18
- package/lib/src/x4.ts +31 -60
- package/lib/styles/x4.css +1 -1
- package/lib/types/x4js.d.ts +100 -49
- package/package.json +2 -3
- package/src/x4.ts +31 -60
- package/lib/output.d.ts +0 -1472
|
@@ -1,427 +1,431 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file listbox.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Use of this source code is governed by an MIT-style license
|
|
14
|
-
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
-
**/
|
|
16
|
-
|
|
17
|
-
import { Component, ComponentEvent, ComponentEvents, componentFromDOM, ComponentProps, EvChange, EvClick, EvContextMenu, EvDblClick, EvSelectionChange } from '../../core/component';
|
|
18
|
-
|
|
19
|
-
import { ScrollView, Viewport } from '../viewport/viewport';
|
|
20
|
-
import { HBox } from '../boxes/boxes.js';
|
|
21
|
-
import { Label } from '../label/label.js';
|
|
22
|
-
|
|
23
|
-
import "./listbox.module.scss"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
this.
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
this._items.
|
|
387
|
-
this._view.
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
this.
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file listbox.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
*
|
|
11
|
+
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* Use of this source code is governed by an MIT-style license
|
|
14
|
+
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
+
**/
|
|
16
|
+
|
|
17
|
+
import { Component, ComponentEvent, ComponentEvents, componentFromDOM, ComponentProps, EvChange, EvClick, EvContextMenu, EvDblClick, EvSelectionChange } from '../../core/component';
|
|
18
|
+
|
|
19
|
+
import { ScrollView, Viewport } from '../viewport/viewport';
|
|
20
|
+
import { HBox } from '../boxes/boxes.js';
|
|
21
|
+
import { Label } from '../label/label.js';
|
|
22
|
+
|
|
23
|
+
import "./listbox.module.scss"
|
|
24
|
+
import { class_ns } from '@core/core_tools.js';
|
|
25
|
+
|
|
26
|
+
export enum kbNav {
|
|
27
|
+
first,
|
|
28
|
+
prev,
|
|
29
|
+
next,
|
|
30
|
+
last,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ListboxID = number | string;
|
|
34
|
+
|
|
35
|
+
export interface ListItem {
|
|
36
|
+
id: ListboxID;
|
|
37
|
+
text: string;
|
|
38
|
+
|
|
39
|
+
iconId?: string;
|
|
40
|
+
data?: any;
|
|
41
|
+
cls?: string;
|
|
42
|
+
checked?: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
interface ListboxEvents extends ComponentEvents {
|
|
51
|
+
//change: EvChange;
|
|
52
|
+
click?: EvClick;
|
|
53
|
+
dblClick?: EvDblClick;
|
|
54
|
+
contextMenu?: EvContextMenu;
|
|
55
|
+
selectionChange?: EvSelectionChange;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
interface ListboxProps extends Omit<ComponentProps,'content'> {
|
|
63
|
+
items?: ListItem[];
|
|
64
|
+
renderer?: ( item: ListItem ) => Component;
|
|
65
|
+
//header?: Header;
|
|
66
|
+
checkable?: true,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
@class_ns( "x4" )
|
|
74
|
+
export class Listbox extends Component<ListboxProps,ListboxEvents> {
|
|
75
|
+
|
|
76
|
+
private _view: Viewport;
|
|
77
|
+
private _selection: ListboxID;
|
|
78
|
+
private _selitem: Component;
|
|
79
|
+
private _items: ListItem[];
|
|
80
|
+
|
|
81
|
+
preventFocus = false;
|
|
82
|
+
|
|
83
|
+
constructor( props: ListboxProps ) {
|
|
84
|
+
super( { ...props } );
|
|
85
|
+
|
|
86
|
+
this.setAttribute( "tabindex", 0 );
|
|
87
|
+
|
|
88
|
+
const scroller = new ScrollView( { cls: "body" } );
|
|
89
|
+
this._view = scroller.getViewport( );
|
|
90
|
+
|
|
91
|
+
this.setContent( [
|
|
92
|
+
//props.header ? props.header : null,
|
|
93
|
+
scroller,
|
|
94
|
+
] );
|
|
95
|
+
|
|
96
|
+
this.setDOMEvents( {
|
|
97
|
+
click: (ev) => this._on_click( ev ),
|
|
98
|
+
keydown: ( ev ) => this._on_key( ev ),
|
|
99
|
+
dblclick: (e) => this._on_click(e),
|
|
100
|
+
contextmenu: (e) => this._on_ctx_menu(e),
|
|
101
|
+
} );
|
|
102
|
+
|
|
103
|
+
if( props.items ) {
|
|
104
|
+
this.setItems( props.items );
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
private _on_key( ev: KeyboardEvent ) {
|
|
113
|
+
if( this.isDisabled() ) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
switch( ev.key ) {
|
|
118
|
+
case "ArrowDown": {
|
|
119
|
+
this.navigate( kbNav.next );
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
case "ArrowUp": {
|
|
124
|
+
this.navigate( kbNav.prev );
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case "Home": {
|
|
129
|
+
this.navigate( kbNav.first );
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case "End": {
|
|
134
|
+
this.navigate( kbNav.last );
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
default:
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
ev.preventDefault( );
|
|
143
|
+
ev.stopPropagation( );
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
*
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
navigate( sens: kbNav ) {
|
|
151
|
+
|
|
152
|
+
if( !this._selitem ) {
|
|
153
|
+
if( sens==kbNav.next ) sens = kbNav.first;
|
|
154
|
+
else sens = kbNav.last;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const next_visible = ( el: Component, down: boolean ) => {
|
|
158
|
+
|
|
159
|
+
while( el && !el.isVisible() ) {
|
|
160
|
+
el = down ? el.nextElement() : el.prevElement();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return el;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if( sens==kbNav.first || sens==kbNav.last ) {
|
|
167
|
+
let fel = sens==kbNav.first ? this._view.firstChild() : this._view.lastChild( );
|
|
168
|
+
fel = next_visible( fel, sens==kbNav.first );
|
|
169
|
+
|
|
170
|
+
if( fel ) {
|
|
171
|
+
const id = fel.getData( "id" );
|
|
172
|
+
this._selectItem( id, fel );
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
let nel = sens==kbNav.next ? this._selitem.nextElement() : this._selitem.prevElement();
|
|
178
|
+
nel = next_visible( nel, sens==kbNav.next );
|
|
179
|
+
|
|
180
|
+
if( nel ) {
|
|
181
|
+
const id = nel.getData( "id" );
|
|
182
|
+
this._selectItem( id, nel );
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
*
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
private _on_click( ev: UIEvent ) {
|
|
195
|
+
ev.stopImmediatePropagation();
|
|
196
|
+
ev.preventDefault( );
|
|
197
|
+
|
|
198
|
+
let target = ev.target as HTMLElement;
|
|
199
|
+
while( target && target!=this.dom ) {
|
|
200
|
+
const c = componentFromDOM( target );
|
|
201
|
+
if( c && c.hasClass("x4item") ) {
|
|
202
|
+
const id = c.getData( "id" );
|
|
203
|
+
const fev: ComponentEvent = { context:id };
|
|
204
|
+
|
|
205
|
+
if (ev.type == 'click') {
|
|
206
|
+
this.fire('click', fev );
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
this.fire('dblClick', fev );
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!fev.defaultPrevented) {
|
|
213
|
+
this._selectItem( id, c );
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
target = target.parentElement;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.clearSelection( );
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
*
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
private _on_ctx_menu(ev: MouseEvent) {
|
|
230
|
+
|
|
231
|
+
ev.preventDefault();
|
|
232
|
+
|
|
233
|
+
let target = ev.target as HTMLElement;
|
|
234
|
+
while( target && target!=this.dom ) {
|
|
235
|
+
const c = componentFromDOM( target );
|
|
236
|
+
if( c && c.hasClass("x4item") ) {
|
|
237
|
+
const id = c.getData( "id" );
|
|
238
|
+
|
|
239
|
+
this._selectItem(id, c);
|
|
240
|
+
this.fire('contextMenu', {uievent: ev, context: id } );
|
|
241
|
+
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
target = target.parentElement;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
this.fire('contextMenu', { uievent:ev, context: null } );
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
*
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
private _selectItem( id: ListboxID, item: Component ) {
|
|
256
|
+
if( this._selitem ) {
|
|
257
|
+
this._selitem.removeClass( "selected" );
|
|
258
|
+
this._selitem = undefined;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this._selitem = item;
|
|
262
|
+
this._selection = id;
|
|
263
|
+
|
|
264
|
+
if( item ) {
|
|
265
|
+
item.addClass( "selected" );
|
|
266
|
+
item.scrollIntoView( {
|
|
267
|
+
behavior: "smooth",
|
|
268
|
+
block: "nearest"
|
|
269
|
+
} );
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const itm = this._findItem( id );
|
|
273
|
+
this.fire( "selectionChange", { selection: itm } );
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
private _findItem( id: ListboxID ) {
|
|
281
|
+
return this._items.find( x => x.id==id );
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
*
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
private _findItemIndex( id: ListboxID ) {
|
|
289
|
+
return this._items.findIndex( x => x.id==id );
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
*
|
|
294
|
+
*/
|
|
295
|
+
|
|
296
|
+
clearSelection( ) {
|
|
297
|
+
if( this._selitem ) {
|
|
298
|
+
this._selitem.removeClass( "selected" );
|
|
299
|
+
this._selitem = undefined;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
this._selection = undefined;
|
|
303
|
+
this.fire( "selectionChange", { selection: undefined } );
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
*
|
|
308
|
+
*/
|
|
309
|
+
|
|
310
|
+
setItems( items: ListItem[] ) {
|
|
311
|
+
this.clearSelection( );
|
|
312
|
+
|
|
313
|
+
this._view.clearContent( );
|
|
314
|
+
this._items = items;
|
|
315
|
+
|
|
316
|
+
if( items ) {
|
|
317
|
+
const content = items.map( x => this.renderItem(x) );
|
|
318
|
+
this._view.setContent( content );
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
*
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
renderItem( item: ListItem ) {
|
|
327
|
+
const renderer = this.props.renderer ?? this.defaultRenderer;
|
|
328
|
+
const line = renderer( item );
|
|
329
|
+
|
|
330
|
+
line.addClass( "x4item" );
|
|
331
|
+
line.setData( "id", item.id+"" );
|
|
332
|
+
|
|
333
|
+
return line;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
*
|
|
338
|
+
*/
|
|
339
|
+
|
|
340
|
+
defaultRenderer( item: ListItem ): Component {
|
|
341
|
+
return new HBox( {
|
|
342
|
+
cls: item.cls,
|
|
343
|
+
content: new Label( { icon: item.iconId, text: item.text })
|
|
344
|
+
} )
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
*
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
filter( filter: string ) {
|
|
352
|
+
const childs = this._view.enumChildComponents( false );
|
|
353
|
+
|
|
354
|
+
if( !filter ) {
|
|
355
|
+
childs.forEach( x => x.show( true ) );
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
// get list of visible items
|
|
359
|
+
const filtred = this._items
|
|
360
|
+
.filter( x => x.text.includes(filter) )
|
|
361
|
+
.map( x => x.id+'' );
|
|
362
|
+
|
|
363
|
+
// now hide all elements not in list
|
|
364
|
+
childs.forEach( x => {
|
|
365
|
+
x.show( filtred.includes( x.getData( "id" ) ) );
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* append or prepend a new item
|
|
372
|
+
* @param item
|
|
373
|
+
* @param prepend
|
|
374
|
+
* @param select
|
|
375
|
+
*/
|
|
376
|
+
|
|
377
|
+
appendItem( item: ListItem, prepend = false, select = true ) {
|
|
378
|
+
|
|
379
|
+
if( select ) {
|
|
380
|
+
this.clearSelection( );
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
let el = this.renderItem( item );
|
|
384
|
+
|
|
385
|
+
if( prepend ) {
|
|
386
|
+
this._items.unshift( item );
|
|
387
|
+
this._view.prependContent( el );
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
this._items.push( item );
|
|
391
|
+
this._view.appendContent( el );
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if( select ) {
|
|
395
|
+
this._selectItem( item.id, el );
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* update an item
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
updateItem( id: any, item: ListItem ) {
|
|
404
|
+
|
|
405
|
+
// find item
|
|
406
|
+
const idx = this._findItemIndex( id );
|
|
407
|
+
if( idx<0 ) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// take care of selection
|
|
412
|
+
let was_sel = false;
|
|
413
|
+
if( this._selection && this._selection===id ) {
|
|
414
|
+
was_sel = true;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// replace it in the list
|
|
418
|
+
this._items[idx] = item;
|
|
419
|
+
|
|
420
|
+
// rebuild & replace it's line
|
|
421
|
+
const oldDOM = this.query( `[data-id="${item.id}"]` )?.dom;
|
|
422
|
+
if( oldDOM ) {
|
|
423
|
+
const _new = this.renderItem( item );
|
|
424
|
+
this._view.dom.replaceChild( _new.dom, oldDOM );
|
|
425
|
+
|
|
426
|
+
if( was_sel ) {
|
|
427
|
+
this._selectItem( item.id, _new );
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|