x4js 1.5.16 → 1.5.18

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 (75) hide show
  1. package/lib/cjs/app_sockets.js +74 -0
  2. package/lib/cjs/index.js +1 -0
  3. package/lib/cjs/treeview.js +27 -12
  4. package/lib/cjs/version.js +1 -1
  5. package/lib/esm/app_sockets.js +70 -0
  6. package/lib/esm/index.mjs +1 -0
  7. package/lib/esm/treeview.js +26 -12
  8. package/lib/esm/version.js +1 -1
  9. package/lib/{src/version.ts → types/app_sockets.d.ts} +29 -30
  10. package/lib/types/index.d.ts +1 -0
  11. package/lib/types/treeview.d.ts +5 -2
  12. package/lib/types/version.d.ts +1 -1
  13. package/package.json +1 -4
  14. package/lib/src/MIT-license.md +0 -14
  15. package/lib/src/action.ts +0 -88
  16. package/lib/src/alpha.jpg +0 -0
  17. package/lib/src/application.ts +0 -251
  18. package/lib/src/autocomplete.ts +0 -197
  19. package/lib/src/base64.ts +0 -166
  20. package/lib/src/base_component.ts +0 -152
  21. package/lib/src/button.ts +0 -355
  22. package/lib/src/calendar.ts +0 -328
  23. package/lib/src/canvas.ts +0 -505
  24. package/lib/src/cardview.ts +0 -227
  25. package/lib/src/checkbox.ts +0 -188
  26. package/lib/src/color.ts +0 -752
  27. package/lib/src/colorpicker.ts +0 -1639
  28. package/lib/src/combobox.ts +0 -465
  29. package/lib/src/component.ts +0 -2329
  30. package/lib/src/datastore.ts +0 -1322
  31. package/lib/src/dialog.ts +0 -656
  32. package/lib/src/dom_events.ts +0 -315
  33. package/lib/src/drag_manager.ts +0 -199
  34. package/lib/src/drawtext.ts +0 -355
  35. package/lib/src/fileupload.ts +0 -213
  36. package/lib/src/form.ts +0 -375
  37. package/lib/src/formatters.ts +0 -105
  38. package/lib/src/gridview.ts +0 -1185
  39. package/lib/src/i18n.ts +0 -346
  40. package/lib/src/icon.ts +0 -335
  41. package/lib/src/image.ts +0 -204
  42. package/lib/src/index.ts +0 -88
  43. package/lib/src/input.ts +0 -249
  44. package/lib/src/label.ts +0 -128
  45. package/lib/src/layout.ts +0 -430
  46. package/lib/src/link.ts +0 -86
  47. package/lib/src/listview.ts +0 -765
  48. package/lib/src/md5.ts +0 -438
  49. package/lib/src/menu.ts +0 -425
  50. package/lib/src/messagebox.ts +0 -224
  51. package/lib/src/panel.ts +0 -86
  52. package/lib/src/popup.ts +0 -494
  53. package/lib/src/property_editor.ts +0 -337
  54. package/lib/src/radiobtn.ts +0 -197
  55. package/lib/src/rating.ts +0 -135
  56. package/lib/src/request.ts +0 -300
  57. package/lib/src/router.ts +0 -185
  58. package/lib/src/settings.ts +0 -77
  59. package/lib/src/sidebarview.ts +0 -103
  60. package/lib/src/spreadsheet.ts +0 -1449
  61. package/lib/src/styles.ts +0 -343
  62. package/lib/src/svgcomponent.ts +0 -577
  63. package/lib/src/tabbar.ts +0 -151
  64. package/lib/src/tabview.ts +0 -110
  65. package/lib/src/textarea.ts +0 -235
  66. package/lib/src/textedit.ts +0 -544
  67. package/lib/src/toaster.ts +0 -80
  68. package/lib/src/tools.ts +0 -1473
  69. package/lib/src/tooltips.ts +0 -191
  70. package/lib/src/treeview.ts +0 -696
  71. package/lib/src/x4.less +0 -2243
  72. package/lib/src/x4dom.ts +0 -57
  73. package/lib/src/x4events.ts +0 -585
  74. package/lib/src/x4react.ts +0 -90
  75. package/lib/x4.css +0 -1780
@@ -1,696 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file treeview.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
-
30
- import { Component, Container, ContainerEventMap, ContainerProps, EvDblClick, EventHandler } from './component';
31
- import { HtmlString, Rect } from './tools';
32
- import { Icon, IconID } from './icon';
33
- import { Label } from './label';
34
- import { HLayout, VLayout } from './layout';
35
- import { EvClick, BasicEvent, EvDrag, EvSelectionChange, EvContextMenu } from './x4events';
36
-
37
- export interface EvExpand extends BasicEvent {
38
- node: TreeNode;
39
- }
40
-
41
- function EvExpand(node: TreeNode) {
42
- return BasicEvent<EvExpand>({ node });
43
- }
44
-
45
- export interface HierarchicalNode {
46
- id: number;
47
- name: string;
48
- parent?: number;
49
- cls?: string;
50
- leaf?: boolean
51
- icon?: string;
52
- data?: any;
53
- }
54
-
55
- export interface TreeNode {
56
- id: any;
57
- text?: string | HtmlString;
58
- icon?: IconID;
59
- children?: TreeNode[];
60
- open?: boolean;
61
- data?: any;
62
- parent?: number;
63
- cls?: string;
64
- }
65
-
66
- interface TreeViewEventMap extends ContainerEventMap {
67
- click: EvClick;
68
- dblclick: EvDblClick;
69
- expand: EvExpand;
70
- drag: EvDrag;
71
- selectionchange: EvSelectionChange;
72
- contextMenu: EvContextMenu;
73
- }
74
-
75
- export interface TreeViewProps extends ContainerProps<TreeViewEventMap> {
76
- root: TreeNode; // root node
77
- indent?: number; // items indentation
78
- gadgets?: Component[];
79
- sort?: boolean; // sort items
80
- canDragItems?: boolean;
81
- renderItem?: ( itm: TreeNode ) => Component;
82
-
83
- dblclick?: EventHandler<EvDblClick>;
84
- selectionchange?: EventHandler<EvSelectionChange>;
85
- drag?: EventHandler<EvDrag>;
86
- contextMenu?: EventHandler<EvContextMenu>;
87
- }
88
-
89
-
90
- /**
91
- *
92
- */
93
-
94
- export class TreeView extends VLayout<TreeViewProps, TreeViewEventMap> {
95
-
96
- m_view: Container;
97
- m_container: Container;
98
- m_selection: {
99
- id: any;
100
- el: Component
101
- };
102
-
103
- constructor(props: TreeViewProps) {
104
- super(props);
105
-
106
- props.root = props.root;
107
- props.indent = props.indent ?? 8;
108
- props.gadgets = props.gadgets;
109
- props.sort = props.sort ?? false;
110
-
111
- this.m_selection = null;
112
-
113
- this.m_container = new Container({ cls: '@scroll-container' });
114
- this.m_view = new Container({
115
- cls: '@scroll-view',
116
- flex: 1,
117
- content: this.m_container
118
- });
119
-
120
- this.setContent([
121
- this.m_view,
122
- props.gadgets ? new HLayout({
123
- cls: 'gadgets',
124
- content: props.gadgets
125
- }) : null,
126
- ])
127
-
128
- this.setDomEvent( 'click', (e) => this._click(e) );
129
- this.setDomEvent( 'dblclick', (e) => this._click(e) );
130
- this.setDomEvent('contextmenu', (e) => this._handleCtxMenu(e));
131
-
132
- if (props.canDragItems) {
133
- this.setDomEvent('dragstart', (ev: DragEvent) => {
134
- let hit = Component.getElement(ev.target as HTMLElement, Component);
135
- let node = hit?.getData("node");
136
-
137
- if (node) {
138
- ev.dataTransfer.effectAllowed = 'move';
139
- ev.dataTransfer.items.add(JSON.stringify({
140
- type: 'treeview',
141
- id: node.id
142
- }), 'string');
143
- }
144
- else {
145
- ev.preventDefault();
146
- ev.stopPropagation();
147
- }
148
- });
149
-
150
- this.setDomEvent('dragover', ev => this._dragEnter(ev));
151
- this.setDomEvent('dragenter', ev => this._dragEnter(ev));
152
-
153
- this.setDomEvent('dragend', ev => this._dragLeave(ev));
154
- this.setDomEvent('dragleave', ev => this._dragLeave(ev));
155
- this.setDomEvent('drop', ev => this._dragLeave(ev));
156
-
157
- this.setDomEvent('drop', ev => this._drop(ev) );
158
- }
159
-
160
- this.mapPropEvents(props, 'dblclick', 'drag', 'selectionchange', 'contextMenu' );
161
- }
162
-
163
- private _dragEnter(ev: DragEvent) {
164
- ev.preventDefault();
165
-
166
- let hit = Component.getElement(ev.target as HTMLElement, Component);
167
- let node = hit?.getData("node");
168
-
169
- if (node) {
170
- hit.addClass('@drag-over');
171
- ev.dataTransfer.dropEffect = 'move';
172
- }
173
- }
174
-
175
- private _dragLeave(ev: Event) {
176
-
177
- let hit = Component.getElement(ev.target as HTMLElement, Component);
178
- let node = hit?.getData("node");
179
-
180
- if (node) {
181
- hit.removeClass('@drag-over');
182
- }
183
- }
184
-
185
- private _drop(ev: DragEvent) {
186
- let hit = Component.getElement(ev.target as HTMLElement, Component);
187
- let node = hit?.getData("node");
188
-
189
- if (!node) {
190
- node = this.m_props.root;
191
- }
192
-
193
- if (node) {
194
- let parent: TreeNode;
195
-
196
- // is a folder
197
- if (node.children) {
198
- parent = node;
199
- }
200
- // in it's parent node
201
- else {
202
- parent = hit.getData("parent");
203
- }
204
-
205
- for (let i = 0; i < ev.dataTransfer.items.length; i++) {
206
- ev.dataTransfer.items[0].getAsString((value) => {
207
- let data = JSON.parse(value);
208
- this.emit('drag', EvDrag( node, data, parent) );
209
- });
210
- }
211
- }
212
- }
213
-
214
- render() {
215
- this.__update( );
216
- }
217
-
218
- private __update( ) {
219
- if (this.m_props.root) {
220
- let items = [];
221
- this._buildBranch(this.m_props.root, -1, items, this.m_props.root);
222
- this.m_container.setContent(items);
223
- }
224
- }
225
-
226
- updateElement( id: any ) {
227
- const { node: child, item } = this._getNode( id );
228
- if( child ) {
229
- const pn = child.dom.parentNode;
230
- const newchild = this._makeNode( item, child.dom.classList.value, child.getData('icon'), child.getData('level') );
231
- const dm = newchild._build( );
232
- pn.replaceChild( dm, child.dom );
233
-
234
- if( this.m_selection?.el===child ) {
235
- this.m_selection.el = newchild;
236
- }
237
- }
238
- }
239
-
240
- set root(root: TreeNode) {
241
- this.m_props.root = root;
242
- this.update();
243
- }
244
-
245
- openAll( open = true) {
246
- this.forEach((node: TreeNode) => {
247
- if( node.children ) {
248
- node.open = open;
249
- }
250
- });
251
-
252
- this.__update( )
253
- }
254
-
255
- /**
256
- * same as root = xxx but keep elements open
257
- */
258
-
259
- refreshRoot(root: TreeNode) {
260
-
261
- let openList = [];
262
-
263
- this.forEach((node: TreeNode): boolean => {
264
- if (node.open) {
265
- openList.push(node.id);
266
- }
267
- return false;
268
- });
269
-
270
- let oldSel = this.selection;
271
- if( root ) {
272
- this.m_props.root = root;
273
- }
274
-
275
- this.forEach((node: TreeNode): boolean => {
276
-
277
- if (openList.indexOf(node.id) >= 0) {
278
- node.open = true;
279
- }
280
-
281
- return false;
282
- });
283
-
284
- this.__update( );
285
- }
286
-
287
- private _buildBranch(node: TreeNode, level: number, items: Component[], parent: TreeNode) {
288
-
289
- let cls = '@tree-item';
290
-
291
- if( node.cls ) {
292
- cls += ' '+node.cls;
293
- }
294
-
295
- if (!node.open && node.children) {
296
- cls += ' collapsed';
297
- }
298
-
299
- if (node.children) {
300
- cls += ' folder';
301
- if (node.children.length == 0) {
302
- cls += ' empty';
303
- }
304
- }
305
-
306
- let icon: IconID = node.icon;
307
- if (icon === undefined ) {
308
- if (node.children) {
309
- if( node.open===true ) {
310
- icon = 'var(--x4-icon-chevron-down)';
311
- }
312
- else {
313
- icon = 'var(--x4-icon-chevron-right)';
314
- }
315
- }
316
- }
317
-
318
- if (level >= 0) {
319
-
320
- const item = this._makeNode( node, cls, icon, level );
321
-
322
- if (this.m_selection?.id == node.id) {
323
- this.m_selection.el = item;
324
- item.addClass('selected');
325
- }
326
-
327
- items.push(item);
328
- }
329
-
330
- if (level == -1 || node.open) {
331
- if (node.children) {
332
-
333
- if (this.m_props.sort) {
334
- // sort items case insensitive:
335
- // first folders
336
- // then items
337
- node.children = node.children.sort((a, b) => {
338
- let at = (a.children ? '0' + a.text : a.text)?.toLocaleLowerCase();
339
- let bt = (b.children ? '0' + b.text : b.text)?.toLocaleLowerCase();
340
- return at < bt ? -1 : at > bt ? 1 : 0;
341
- });
342
- }
343
-
344
- node.children.forEach((c) => {
345
- this._buildBranch(c, level + 1, items, node)
346
- });
347
- }
348
- }
349
- }
350
-
351
- private _renderDef( node: TreeNode ) {
352
- return new Label({ cls: 'tree-label', flex:1, text: node.text });
353
- }
354
-
355
- private _makeNode( node: TreeNode, cls: string, icon: IconID, level: number ): Component {
356
-
357
- const item = new HLayout({
358
- cls,
359
- content: [
360
- new Icon({ cls: 'tree-icon', icon }),
361
- this.m_props.renderItem ? this.m_props.renderItem( node ) : this._renderDef( node ),
362
- ],
363
- data: {
364
- 'node': node,
365
- 'level': level,
366
- 'icon': icon,
367
- },
368
- style: {
369
- paddingLeft: 4 + level * this.m_props.indent
370
- },
371
- attrs: {
372
- draggable: this.m_props.canDragItems ? true : undefined
373
- },
374
- });
375
-
376
-
377
- return item;
378
- }
379
-
380
- /**
381
- *
382
- */
383
-
384
- forEach(cb: (node: TreeNode) => boolean | void ) {
385
- let found = null;
386
-
387
- function scan(node) {
388
- if (cb(node) == true) {
389
- return true;
390
- }
391
-
392
- if (node.children) {
393
- for (let i = 0; i < node.children.length; i++) {
394
- if (scan(node.children[i])) {
395
- return true;
396
- }
397
- }
398
- }
399
- }
400
-
401
- if (this.m_props.root) {
402
- scan(this.m_props.root);
403
- }
404
-
405
- return found;
406
- }
407
-
408
- ensureVisible( id: any ) {
409
- const { node } = this._getNode( id );
410
- if( node ) {
411
- node.scrollIntoView( );
412
- }
413
- }
414
-
415
- set selection(id: any) {
416
- this.select( id, false );
417
- }
418
-
419
- /**
420
- * idem selection = xx but with a notification
421
- * @param id
422
- */
423
-
424
- public select( id: any, notify = false ) {
425
- if (id === null || id === undefined) {
426
- this._selectItem(null, null);
427
- }
428
- else {
429
- if (isFunction(this.m_props.items)) {
430
- this.m_defer_sel = id;
431
- }
432
- else {
433
- let item = this.m_props.items.find((item) => item.id == id);
434
- let citem = this._findItemWithId(item.id);
435
- this._selectItem(item, citem, notify );
436
- }
437
- }
438
- }
439
-
440
- private _getNode( id ): {node:Component,item:TreeNode} {
441
- let found = { node: null, item: null };
442
-
443
- this.m_container.enumChilds((c) => {
444
- let node = c.getData('node');
445
- if (node?.id == id) {
446
- found = {node:c,item:node};
447
- return true;
448
- }
449
- });
450
-
451
- return found;
452
- }
453
-
454
- get selection() {
455
- return this.m_selection?.id;
456
- }
457
-
458
- getNodeWithId(id: any): TreeNode {
459
- return this.forEach((node) => node.id == id);
460
- }
461
-
462
- /**
463
- *
464
- */
465
-
466
- private _click(ev: MouseEvent) {
467
-
468
- let dom = ev.target as HTMLElement;
469
- let idom = dom;
470
- let onsub = false;
471
-
472
- // avoid getting click on sub childs
473
- if( dom.tabIndex!==-1 ) {
474
- onsub = true;
475
- }
476
-
477
- while (dom != this.dom) {
478
-
479
- let el = Component.getElement(dom);
480
- let nd = el?.getData('node') as TreeNode;
481
- if (nd) {
482
-
483
- if (nd.children && !onsub ) {
484
- // on text or on expando ?
485
- if (el.hasClass('selected') || idom.classList.contains('tree-icon') ) { //expando
486
- nd.open = nd.open ? false : true;
487
- }
488
-
489
- this.m_selection = { id: nd.id, el: null };
490
-
491
- let offset = this.m_view?.dom?.scrollTop;
492
- this.update( );
493
- if (offset) {
494
- this.m_view.dom.scrollTo(0, offset);
495
- }
496
-
497
- this.emit('expand', EvExpand(nd));
498
- }
499
- else {
500
- this.selection = nd.id;
501
-
502
- if( !onsub ) {
503
- if (ev.type == 'click') {
504
- this.emit('click', EvClick(nd));
505
- }
506
- else {
507
- this.emit('dblclick', EvDblClick(nd));
508
- }
509
- }
510
- }
511
-
512
- this.emit('selectionchange', EvSelectionChange(nd));
513
- return;
514
- }
515
-
516
- dom = dom.parentElement;
517
- }
518
-
519
- if (ev.type == 'click') {
520
- this.m_selection = null;
521
- this.update( );
522
- this.emit('selectionchange', EvSelectionChange(null) );
523
- }
524
- }
525
-
526
- private _handleCtxMenu(ev: MouseEvent) {
527
- ev.preventDefault();
528
-
529
- let dom = ev.target as HTMLElement;
530
- let idom = dom;
531
-
532
- while (dom != this.dom) {
533
-
534
- let el = Component.getElement(dom);
535
- let nd = el?.getData('node') as TreeNode;
536
- if (nd) {
537
- if (nd.children) {
538
- // on text or on expando ?
539
- if ( idom.classList.contains('tree-icon') ) { //expando
540
- return;
541
- }
542
- }
543
-
544
- this.selection = nd.id;
545
-
546
- this.emit('click', EvClick(nd) );
547
- this.emit('contextMenu', EvContextMenu(ev, nd));
548
-
549
- return;
550
- }
551
-
552
- dom = dom.parentElement;
553
- }
554
-
555
- this.selection = null;
556
- this.emit('contextMenu', EvContextMenu(ev, null));
557
- }
558
-
559
- /**
560
- * constructs a tree node from an array of strings
561
- * elements are organized like folders (separator = /)
562
- * @example
563
- * let root = TreeView.buildFromString( [
564
- * 'this/is/a/final/file'
565
- * 'this/is/another/file'
566
- * ] );
567
- */
568
-
569
- static buildFromStrings(paths: string[], separator = '/'): TreeNode {
570
-
571
- let root: TreeNode = {
572
- id: 0,
573
- text: '<root>',
574
- children: []
575
- };
576
-
577
- function insert(elements: TreeNode[], path: string) {
578
-
579
- let pos = path.indexOf(separator);
580
- let main = path.substr(0, pos < 0 ? undefined : pos);
581
-
582
- let elem: TreeNode;
583
-
584
- if (pos >= 0) {
585
- elem = elements.find((el) => {
586
- return el.text == main;
587
- });
588
- }
589
-
590
- if (!elem) {
591
- elem = {
592
- id: path,
593
- text: main,
594
- };
595
-
596
- elements.push(elem);
597
- }
598
-
599
- if (pos >= 0) {
600
- if (!elem.children) {
601
- elem.children = [];
602
- }
603
-
604
- insert(elem.children, path.substr(pos + separator.length));
605
- }
606
- }
607
-
608
- paths.forEach((path) => {
609
- insert(root.children, path);
610
- });
611
-
612
- return root;
613
- }
614
-
615
- /**
616
- * constructs a tree node from an array of nodes like
617
- * node {
618
- * id: number,
619
- * parent: number,
620
- * name: string
621
- * }
622
- */
623
-
624
- static buildFromHierarchy(nodes: HierarchicalNode[], cb?: (node: TreeNode) => void): TreeNode {
625
-
626
- let root: TreeNode = {
627
- id: 0,
628
- text: '<root>',
629
- children: []
630
- };
631
-
632
- let tree_nodes: TreeNode[] = [];
633
-
634
- function insert(node: HierarchicalNode) {
635
-
636
- let elem: TreeNode;
637
- let pelem: TreeNode;
638
-
639
- if (node.parent > 0) {
640
- pelem = tree_nodes.find((tnode: TreeNode) => tnode.id == node.parent);
641
-
642
- if (!pelem) {
643
- pelem = {
644
- id: node.parent,
645
- text: '',
646
- children: []
647
- };
648
-
649
- tree_nodes.push(pelem);
650
- }
651
-
652
- if (!pelem.children) {
653
- pelem.children = [];
654
- }
655
- }
656
- else {
657
- pelem = root;
658
- }
659
-
660
- elem = tree_nodes.find((tnode: TreeNode) => tnode.id == node.id);
661
- if (!elem) {
662
- elem = {
663
- id: node.id,
664
- text: node.name,
665
- parent: node.parent,
666
- cls: node.cls,
667
- icon: node.icon,
668
- data: node.data,
669
- };
670
-
671
- if (!node.leaf) {
672
- elem.children = [];
673
- }
674
- else {
675
- elem.icon = null;
676
- }
677
- }
678
- else {
679
- elem.text = node.name;
680
- elem.parent = node.parent;
681
- }
682
-
683
- tree_nodes.push(elem);
684
- pelem.children.push(elem)
685
- }
686
-
687
- nodes.forEach(insert);
688
- if (cb) {
689
- tree_nodes.forEach(cb);
690
- }
691
-
692
- return root;
693
- }
694
- }
695
-
696
-