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.
- package/lib/{README.md → README.txt} +0 -0
- package/lib/cjs/index.js +39 -103
- package/lib/cjs/index.js.map +7 -0
- package/lib/esm/index.mjs +39 -87
- package/lib/esm/index.mjs.map +7 -0
- package/lib/{license.md → licence.md} +0 -0
- package/lib/src/MIT-license.md +14 -0
- package/lib/{types/action.d.ts → src/action.ts} +64 -33
- package/lib/src/alpha.jpg +0 -0
- package/lib/src/app_sockets.ts +81 -0
- package/lib/src/application.ts +251 -0
- package/lib/src/autocomplete.ts +197 -0
- package/lib/src/base64.ts +166 -0
- package/lib/src/base_component.ts +152 -0
- package/lib/src/button.ts +355 -0
- package/lib/src/calendar.ts +328 -0
- package/lib/src/canvas.ts +505 -0
- package/lib/src/cardview.ts +227 -0
- package/lib/src/checkbox.ts +188 -0
- package/lib/src/color.ts +752 -0
- package/lib/src/colorpicker.ts +1639 -0
- package/lib/src/combobox.ts +465 -0
- package/lib/src/component.ts +2329 -0
- package/lib/{esm/dom_events.js → src/copyright.txt} +27 -29
- package/lib/src/datastore.ts +1322 -0
- package/lib/src/dialog.ts +656 -0
- package/lib/src/dom_events.ts +315 -0
- package/lib/src/drag_manager.ts +199 -0
- package/lib/src/drawtext.ts +355 -0
- package/lib/src/fileupload.ts +213 -0
- package/lib/src/form.ts +375 -0
- package/lib/src/formatters.ts +105 -0
- package/lib/src/gridview.ts +1185 -0
- package/lib/src/i18n.ts +346 -0
- package/lib/src/icon.ts +335 -0
- package/lib/src/image.ts +204 -0
- package/lib/src/index.ts +89 -0
- package/lib/src/input.ts +249 -0
- package/lib/src/label.ts +128 -0
- package/lib/src/layout.ts +430 -0
- package/lib/src/link.ts +86 -0
- package/lib/src/listview.ts +765 -0
- package/lib/{esm/md5.js → src/md5.ts} +438 -403
- package/lib/src/menu.ts +425 -0
- package/lib/src/messagebox.ts +224 -0
- package/lib/src/panel.ts +86 -0
- package/lib/src/popup.ts +494 -0
- package/lib/src/property_editor.ts +337 -0
- package/lib/src/radiobtn.ts +197 -0
- package/lib/src/rating.ts +135 -0
- package/lib/src/request.ts +300 -0
- package/lib/src/router.ts +185 -0
- package/lib/src/settings.ts +77 -0
- package/lib/src/sidebarview.ts +103 -0
- package/lib/src/spreadsheet.ts +1449 -0
- package/lib/src/styles.ts +343 -0
- package/lib/src/svgcomponent.ts +577 -0
- package/lib/src/tabbar.ts +151 -0
- package/lib/src/tabview.ts +110 -0
- package/lib/src/textarea.ts +235 -0
- package/lib/src/textedit.ts +544 -0
- package/lib/src/toaster.ts +80 -0
- package/lib/src/tools.ts +1473 -0
- package/lib/src/tooltips.ts +191 -0
- package/lib/src/treeview.ts +716 -0
- package/lib/{esm/version.js → src/version.ts} +30 -29
- package/lib/{styles → src}/x4.less +0 -0
- package/lib/src/x4dom.ts +57 -0
- package/lib/src/x4events.ts +585 -0
- package/lib/src/x4react.ts +90 -0
- package/package.json +52 -46
- package/lib/cjs/action.js +0 -58
- package/lib/cjs/app_sockets.js +0 -74
- package/lib/cjs/application.js +0 -182
- package/lib/cjs/autocomplete.js +0 -155
- package/lib/cjs/base_component.js +0 -124
- package/lib/cjs/button.js +0 -263
- package/lib/cjs/calendar.js +0 -254
- package/lib/cjs/canvas.js +0 -361
- package/lib/cjs/cardview.js +0 -161
- package/lib/cjs/checkbox.js +0 -139
- package/lib/cjs/color.js +0 -591
- package/lib/cjs/colorpicker.js +0 -1468
- package/lib/cjs/combobox.js +0 -349
- package/lib/cjs/component.js +0 -1719
- package/lib/cjs/datastore.js +0 -985
- package/lib/cjs/dialog.js +0 -478
- package/lib/cjs/dom_events.js +0 -30
- package/lib/cjs/drag_manager.js +0 -145
- package/lib/cjs/drawtext.js +0 -276
- package/lib/cjs/fileupload.js +0 -167
- package/lib/cjs/form.js +0 -304
- package/lib/cjs/formatters.js +0 -90
- package/lib/cjs/gridview.js +0 -881
- package/lib/cjs/i18n.js +0 -266
- package/lib/cjs/icon.js +0 -272
- package/lib/cjs/image.js +0 -157
- package/lib/cjs/input.js +0 -174
- package/lib/cjs/label.js +0 -95
- package/lib/cjs/layout.js +0 -322
- package/lib/cjs/link.js +0 -64
- package/lib/cjs/listview.js +0 -546
- package/lib/cjs/md5.js +0 -403
- package/lib/cjs/menu.js +0 -301
- package/lib/cjs/messagebox.js +0 -177
- package/lib/cjs/panel.js +0 -68
- package/lib/cjs/popup.js +0 -383
- package/lib/cjs/property_editor.js +0 -252
- package/lib/cjs/radiobtn.js +0 -140
- package/lib/cjs/rating.js +0 -102
- package/lib/cjs/request.js +0 -246
- package/lib/cjs/router.js +0 -139
- package/lib/cjs/settings.js +0 -69
- package/lib/cjs/sidebarview.js +0 -82
- package/lib/cjs/spreadsheet.js +0 -1084
- package/lib/cjs/styles.js +0 -275
- package/lib/cjs/svgcomponent.js +0 -447
- package/lib/cjs/tabbar.js +0 -111
- package/lib/cjs/tabview.js +0 -85
- package/lib/cjs/textarea.js +0 -165
- package/lib/cjs/textedit.js +0 -415
- package/lib/cjs/toaster.js +0 -64
- package/lib/cjs/tools.js +0 -1197
- package/lib/cjs/tooltips.js +0 -157
- package/lib/cjs/treeview.js +0 -535
- package/lib/cjs/version.js +0 -32
- package/lib/cjs/x4dom.js +0 -32
- package/lib/cjs/x4events.js +0 -384
- package/lib/cjs/x4react.js +0 -72
- package/lib/esm/action.js +0 -53
- package/lib/esm/app_sockets.js +0 -70
- package/lib/esm/application.js +0 -184
- package/lib/esm/autocomplete.js +0 -155
- package/lib/esm/base_component.js +0 -107
- package/lib/esm/button.js +0 -257
- package/lib/esm/calendar.js +0 -249
- package/lib/esm/canvas.js +0 -358
- package/lib/esm/cardview.js +0 -159
- package/lib/esm/checkbox.js +0 -134
- package/lib/esm/color.js +0 -588
- package/lib/esm/colorpicker.js +0 -1475
- package/lib/esm/combobox.js +0 -351
- package/lib/esm/component.js +0 -1711
- package/lib/esm/datastore.js +0 -990
- package/lib/esm/dialog.js +0 -490
- package/lib/esm/drag_manager.js +0 -147
- package/lib/esm/drawtext.js +0 -271
- package/lib/esm/fileupload.js +0 -163
- package/lib/esm/form.js +0 -304
- package/lib/esm/formatters.js +0 -81
- package/lib/esm/gridview.js +0 -889
- package/lib/esm/i18n.js +0 -257
- package/lib/esm/icon.js +0 -261
- package/lib/esm/image.js +0 -154
- package/lib/esm/input.js +0 -182
- package/lib/esm/label.js +0 -90
- package/lib/esm/layout.js +0 -310
- package/lib/esm/link.js +0 -59
- package/lib/esm/listview.js +0 -534
- package/lib/esm/menu.js +0 -300
- package/lib/esm/messagebox.js +0 -161
- package/lib/esm/panel.js +0 -65
- package/lib/esm/popup.js +0 -379
- package/lib/esm/property_editor.js +0 -251
- package/lib/esm/radiobtn.js +0 -136
- package/lib/esm/rating.js +0 -97
- package/lib/esm/request.js +0 -224
- package/lib/esm/router.js +0 -136
- package/lib/esm/settings.js +0 -66
- package/lib/esm/sidebarview.js +0 -79
- package/lib/esm/spreadsheet.js +0 -1097
- package/lib/esm/styles.js +0 -270
- package/lib/esm/svgcomponent.js +0 -450
- package/lib/esm/tabbar.js +0 -107
- package/lib/esm/tabview.js +0 -83
- package/lib/esm/textarea.js +0 -160
- package/lib/esm/textedit.js +0 -412
- package/lib/esm/toaster.js +0 -62
- package/lib/esm/tools.js +0 -1158
- package/lib/esm/tooltips.js +0 -153
- package/lib/esm/treeview.js +0 -527
- package/lib/esm/x4dom.js +0 -29
- package/lib/esm/x4events.js +0 -376
- package/lib/esm/x4react.js +0 -71
- package/lib/types/app_sockets.d.ts +0 -29
- package/lib/types/application.d.ts +0 -104
- package/lib/types/autocomplete.d.ts +0 -58
- package/lib/types/base_component.d.ts +0 -88
- package/lib/types/button.d.ts +0 -151
- package/lib/types/calendar.d.ts +0 -82
- package/lib/types/canvas.d.ts +0 -92
- package/lib/types/cardview.d.ts +0 -87
- package/lib/types/checkbox.d.ts +0 -77
- package/lib/types/color.d.ts +0 -148
- package/lib/types/colorpicker.d.ts +0 -107
- package/lib/types/combobox.d.ts +0 -107
- package/lib/types/component.d.ts +0 -601
- package/lib/types/datastore.d.ts +0 -396
- package/lib/types/dialog.d.ts +0 -175
- package/lib/types/dom_events.d.ts +0 -302
- package/lib/types/drag_manager.d.ts +0 -54
- package/lib/types/drawtext.d.ts +0 -48
- package/lib/types/fileupload.d.ts +0 -64
- package/lib/types/form.d.ts +0 -133
- package/lib/types/formatters.d.ts +0 -35
- package/lib/types/gridview.d.ts +0 -175
- package/lib/types/i18n.d.ts +0 -73
- package/lib/types/icon.d.ts +0 -64
- package/lib/types/image.d.ts +0 -55
- package/lib/types/index.d.ts +0 -84
- package/lib/types/input.d.ts +0 -91
- package/lib/types/label.d.ts +0 -58
- package/lib/types/layout.d.ts +0 -87
- package/lib/types/link.d.ts +0 -50
- package/lib/types/listview.d.ts +0 -178
- package/lib/types/md5.d.ts +0 -61
- package/lib/types/menu.d.ts +0 -130
- package/lib/types/messagebox.d.ts +0 -69
- package/lib/types/panel.d.ts +0 -47
- package/lib/types/popup.d.ts +0 -75
- package/lib/types/property_editor.d.ts +0 -71
- package/lib/types/radiobtn.d.ts +0 -73
- package/lib/types/rating.d.ts +0 -53
- package/lib/types/request.d.ts +0 -52
- package/lib/types/router.d.ts +0 -42
- package/lib/types/settings.d.ts +0 -37
- package/lib/types/sidebarview.d.ts +0 -49
- package/lib/types/spreadsheet.d.ts +0 -222
- package/lib/types/styles.d.ts +0 -85
- package/lib/types/svgcomponent.d.ts +0 -215
- package/lib/types/tabbar.d.ts +0 -58
- package/lib/types/tabview.d.ts +0 -49
- package/lib/types/textarea.d.ts +0 -77
- package/lib/types/textedit.d.ts +0 -123
- package/lib/types/toaster.d.ts +0 -42
- package/lib/types/tools.d.ts +0 -394
- package/lib/types/tooltips.d.ts +0 -46
- package/lib/types/treeview.d.ts +0 -144
- package/lib/types/version.d.ts +0 -29
- package/lib/types/x4dom.d.ts +0 -49
- package/lib/types/x4events.d.ts +0 -269
- package/lib/types/x4react.d.ts +0 -41
package/lib/esm/tooltips.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file tooltips.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2022 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
import { x4document } from './x4dom';
|
|
30
|
-
import { Component } from './component';
|
|
31
|
-
import { Label } from './label';
|
|
32
|
-
import { Icon } from './icon';
|
|
33
|
-
import { isTouchDevice } from './tools';
|
|
34
|
-
let tipTmo;
|
|
35
|
-
let tooltip;
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
export class Tooltip extends Component {
|
|
40
|
-
m_text;
|
|
41
|
-
set text(text) {
|
|
42
|
-
this.m_text.text = text;
|
|
43
|
-
}
|
|
44
|
-
/** @ignore */
|
|
45
|
-
render() {
|
|
46
|
-
this.setClass('@non-maskable', true);
|
|
47
|
-
this.setContent([
|
|
48
|
-
new Icon({ icon: 'var( --x4-icon-tip )' }),
|
|
49
|
-
this.m_text = new Label({ text: 'help' })
|
|
50
|
-
]);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* display the menu at a specific position
|
|
54
|
-
* @param x
|
|
55
|
-
* @param y
|
|
56
|
-
*/
|
|
57
|
-
displayAt(x, y, align = 'top left') {
|
|
58
|
-
this.show();
|
|
59
|
-
let halign = 'l', valign = 't';
|
|
60
|
-
if (align.indexOf('right') >= 0) {
|
|
61
|
-
halign = 'r';
|
|
62
|
-
}
|
|
63
|
-
if (align.indexOf('bottom') >= 0) {
|
|
64
|
-
valign = 'b';
|
|
65
|
-
}
|
|
66
|
-
// @TODO: this is a minimal overflow problem solution
|
|
67
|
-
let rc = x4document.body.getBoundingClientRect(), rm = this.getBoundingRect();
|
|
68
|
-
if (halign == 'r') {
|
|
69
|
-
x -= rm.width;
|
|
70
|
-
}
|
|
71
|
-
if (valign == 'b') {
|
|
72
|
-
y -= rm.height;
|
|
73
|
-
}
|
|
74
|
-
if ((x + rm.width) > rc.right) {
|
|
75
|
-
x = rc.right - rm.width;
|
|
76
|
-
}
|
|
77
|
-
if ((y + rm.height) > rc.bottom) {
|
|
78
|
-
y = rc.bottom - rm.height - 17; // default cursor height
|
|
79
|
-
}
|
|
80
|
-
this.setStyle({ left: x, top: y });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export function initTooltips(cb) {
|
|
84
|
-
if (isTouchDevice()) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
let tipTarget = {
|
|
88
|
-
target: null,
|
|
89
|
-
x: 0,
|
|
90
|
-
y: 0
|
|
91
|
-
};
|
|
92
|
-
function handle_mpos(event) {
|
|
93
|
-
tipTarget.x = event.pageX;
|
|
94
|
-
tipTarget.y = event.pageY;
|
|
95
|
-
}
|
|
96
|
-
function handle_mouse(event) {
|
|
97
|
-
let target = event.target;
|
|
98
|
-
let tip = null;
|
|
99
|
-
tipTarget.x = event.pageX + 10;
|
|
100
|
-
tipTarget.y = event.pageY + 15;
|
|
101
|
-
while (target) {
|
|
102
|
-
tip = target.getAttribute('tip');
|
|
103
|
-
if (tip) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
target = target.parentElement;
|
|
107
|
-
}
|
|
108
|
-
if (target == tipTarget.target || (tooltip && target == tooltip.dom)) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (!target || !tip) {
|
|
112
|
-
tipTarget.target = null;
|
|
113
|
-
if (cb) {
|
|
114
|
-
cb(null);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
_hideTip();
|
|
118
|
-
}
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
tipTarget.target = target;
|
|
122
|
-
if (cb) {
|
|
123
|
-
cb(null);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
_hideTip();
|
|
127
|
-
}
|
|
128
|
-
if (cb) {
|
|
129
|
-
cb(tip);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
tipTmo = setTimeout(() => {
|
|
133
|
-
if (tooltip === undefined) {
|
|
134
|
-
tooltip = new Tooltip({});
|
|
135
|
-
x4document.body.appendChild(tooltip._build());
|
|
136
|
-
}
|
|
137
|
-
tooltip.text = tip;
|
|
138
|
-
tooltip.displayAt(tipTarget.x + 17, tipTarget.y + 17, 'top left');
|
|
139
|
-
}, 700);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function _hideTip() {
|
|
143
|
-
if (tipTmo) {
|
|
144
|
-
clearTimeout(tipTmo);
|
|
145
|
-
}
|
|
146
|
-
if (tooltip) {
|
|
147
|
-
tooltip.hide();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
x4document.body.addEventListener('mouseover', handle_mouse);
|
|
151
|
-
x4document.body.addEventListener('mouseout', handle_mouse);
|
|
152
|
-
x4document.body.addEventListener('mousemove', handle_mpos);
|
|
153
|
-
}
|
package/lib/esm/treeview.js
DELETED
|
@@ -1,527 +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
|
-
import { Component, Container, EvDblClick } from './component';
|
|
30
|
-
import { Icon } from './icon';
|
|
31
|
-
import { Label } from './label';
|
|
32
|
-
import { HLayout, VLayout } from './layout';
|
|
33
|
-
import { EvClick, BasicEvent, EvDrag, EvSelectionChange, EvContextMenu } from './x4events';
|
|
34
|
-
function EvExpand(node) {
|
|
35
|
-
return BasicEvent({ node });
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
export class TreeView extends VLayout {
|
|
41
|
-
m_view;
|
|
42
|
-
m_container;
|
|
43
|
-
m_selection;
|
|
44
|
-
constructor(props) {
|
|
45
|
-
super(props);
|
|
46
|
-
props.root = props.root;
|
|
47
|
-
props.indent = props.indent ?? 8;
|
|
48
|
-
props.gadgets = props.gadgets;
|
|
49
|
-
props.sort = props.sort ?? false;
|
|
50
|
-
this.m_selection = null;
|
|
51
|
-
this.m_container = new Container({ cls: '@scroll-container' });
|
|
52
|
-
this.m_view = new Container({
|
|
53
|
-
cls: '@scroll-view',
|
|
54
|
-
flex: 1,
|
|
55
|
-
content: this.m_container
|
|
56
|
-
});
|
|
57
|
-
this.setContent([
|
|
58
|
-
this.m_view,
|
|
59
|
-
props.gadgets ? new HLayout({
|
|
60
|
-
cls: 'gadgets',
|
|
61
|
-
content: props.gadgets
|
|
62
|
-
}) : null,
|
|
63
|
-
]);
|
|
64
|
-
this.setDomEvent('click', (e) => this._click(e));
|
|
65
|
-
this.setDomEvent('dblclick', (e) => this._click(e));
|
|
66
|
-
this.setDomEvent('contextmenu', (e) => this._handleCtxMenu(e));
|
|
67
|
-
if (props.canDragItems) {
|
|
68
|
-
this.setDomEvent('dragstart', (ev) => {
|
|
69
|
-
let hit = Component.getElement(ev.target, Component);
|
|
70
|
-
let node = hit?.getData("node");
|
|
71
|
-
if (node) {
|
|
72
|
-
ev.dataTransfer.effectAllowed = 'move';
|
|
73
|
-
ev.dataTransfer.items.add(JSON.stringify({
|
|
74
|
-
type: 'treeview',
|
|
75
|
-
id: node.id
|
|
76
|
-
}), 'string');
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
ev.preventDefault();
|
|
80
|
-
ev.stopPropagation();
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
this.setDomEvent('dragover', ev => this._dragEnter(ev));
|
|
84
|
-
this.setDomEvent('dragenter', ev => this._dragEnter(ev));
|
|
85
|
-
this.setDomEvent('dragend', ev => this._dragLeave(ev));
|
|
86
|
-
this.setDomEvent('dragleave', ev => this._dragLeave(ev));
|
|
87
|
-
this.setDomEvent('drop', ev => this._dragLeave(ev));
|
|
88
|
-
this.setDomEvent('drop', ev => this._drop(ev));
|
|
89
|
-
}
|
|
90
|
-
this.mapPropEvents(props, 'dblclick', 'drag', 'selectionchange', 'contextMenu');
|
|
91
|
-
}
|
|
92
|
-
_dragEnter(ev) {
|
|
93
|
-
ev.preventDefault();
|
|
94
|
-
let hit = Component.getElement(ev.target, Component);
|
|
95
|
-
let node = hit?.getData("node");
|
|
96
|
-
if (node) {
|
|
97
|
-
hit.addClass('@drag-over');
|
|
98
|
-
ev.dataTransfer.dropEffect = 'move';
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
_dragLeave(ev) {
|
|
102
|
-
let hit = Component.getElement(ev.target, Component);
|
|
103
|
-
let node = hit?.getData("node");
|
|
104
|
-
if (node) {
|
|
105
|
-
hit.removeClass('@drag-over');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
_drop(ev) {
|
|
109
|
-
let hit = Component.getElement(ev.target, Component);
|
|
110
|
-
let node = hit?.getData("node");
|
|
111
|
-
if (!node) {
|
|
112
|
-
node = this.m_props.root;
|
|
113
|
-
}
|
|
114
|
-
if (node) {
|
|
115
|
-
let parent;
|
|
116
|
-
// is a folder
|
|
117
|
-
if (node.children) {
|
|
118
|
-
parent = node;
|
|
119
|
-
}
|
|
120
|
-
// in it's parent node
|
|
121
|
-
else {
|
|
122
|
-
parent = hit.getData("parent");
|
|
123
|
-
}
|
|
124
|
-
for (let i = 0; i < ev.dataTransfer.items.length; i++) {
|
|
125
|
-
ev.dataTransfer.items[0].getAsString((value) => {
|
|
126
|
-
let data = JSON.parse(value);
|
|
127
|
-
this.emit('drag', EvDrag(node, data, parent));
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
render() {
|
|
133
|
-
this.__update();
|
|
134
|
-
}
|
|
135
|
-
__update() {
|
|
136
|
-
if (this.m_props.root) {
|
|
137
|
-
let items = [];
|
|
138
|
-
this._buildBranch(this.m_props.root, -1, items, this.m_props.root);
|
|
139
|
-
this.m_container.setContent(items);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
updateElement(id) {
|
|
143
|
-
const { node: child, item } = this._getNode(id);
|
|
144
|
-
if (child) {
|
|
145
|
-
const pn = child.dom.parentNode;
|
|
146
|
-
const newchild = this._makeNode(item, child.dom.classList.value, child.getData('icon'), child.getData('level'));
|
|
147
|
-
const dm = newchild._build();
|
|
148
|
-
pn.replaceChild(dm, child.dom);
|
|
149
|
-
if (this.m_selection?.el === child) {
|
|
150
|
-
this.m_selection.el = newchild;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
set root(root) {
|
|
155
|
-
this.m_props.root = root;
|
|
156
|
-
this.update();
|
|
157
|
-
}
|
|
158
|
-
openAll(open = true) {
|
|
159
|
-
this.forEach((node) => {
|
|
160
|
-
if (node.children) {
|
|
161
|
-
node.open = open;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
this.__update();
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* same as root = xxx but keep elements open
|
|
168
|
-
*/
|
|
169
|
-
refreshRoot(root) {
|
|
170
|
-
let openList = [];
|
|
171
|
-
this.forEach((node) => {
|
|
172
|
-
if (node.open) {
|
|
173
|
-
openList.push(node.id);
|
|
174
|
-
}
|
|
175
|
-
return false;
|
|
176
|
-
});
|
|
177
|
-
let oldSel = this.selection;
|
|
178
|
-
if (root) {
|
|
179
|
-
this.m_props.root = root;
|
|
180
|
-
}
|
|
181
|
-
this.forEach((node) => {
|
|
182
|
-
if (openList.indexOf(node.id) >= 0) {
|
|
183
|
-
node.open = true;
|
|
184
|
-
}
|
|
185
|
-
return false;
|
|
186
|
-
});
|
|
187
|
-
this.__update();
|
|
188
|
-
}
|
|
189
|
-
_buildBranch(node, level, items, parent) {
|
|
190
|
-
let cls = '@tree-item';
|
|
191
|
-
if (node.cls) {
|
|
192
|
-
cls += ' ' + node.cls;
|
|
193
|
-
}
|
|
194
|
-
if (!node.open && node.children) {
|
|
195
|
-
cls += ' collapsed';
|
|
196
|
-
}
|
|
197
|
-
if (node.children) {
|
|
198
|
-
cls += ' folder';
|
|
199
|
-
if (node.children.length == 0) {
|
|
200
|
-
cls += ' empty';
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
let icon = node.icon;
|
|
204
|
-
if (icon === undefined) {
|
|
205
|
-
if (node.children) {
|
|
206
|
-
if (node.open === true) {
|
|
207
|
-
icon = 'var(--x4-icon-chevron-down)';
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
icon = 'var(--x4-icon-chevron-right)';
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (level >= 0) {
|
|
215
|
-
const item = this._makeNode(node, cls, icon, level);
|
|
216
|
-
if (this.m_selection?.id == node.id) {
|
|
217
|
-
this.m_selection.el = item;
|
|
218
|
-
item.addClass('selected');
|
|
219
|
-
}
|
|
220
|
-
items.push(item);
|
|
221
|
-
}
|
|
222
|
-
if (level == -1 || node.open) {
|
|
223
|
-
if (node.children) {
|
|
224
|
-
if (this.m_props.sort) {
|
|
225
|
-
// sort items case insensitive:
|
|
226
|
-
// first folders
|
|
227
|
-
// then items
|
|
228
|
-
node.children = node.children.sort((a, b) => {
|
|
229
|
-
let at = (a.children ? '0' + a.text : a.text)?.toLocaleLowerCase();
|
|
230
|
-
let bt = (b.children ? '0' + b.text : b.text)?.toLocaleLowerCase();
|
|
231
|
-
return at < bt ? -1 : at > bt ? 1 : 0;
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
node.children.forEach((c) => {
|
|
235
|
-
this._buildBranch(c, level + 1, items, node);
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
_renderDef(node) {
|
|
241
|
-
return new Label({ cls: 'tree-label', flex: 1, text: node.text });
|
|
242
|
-
}
|
|
243
|
-
_makeNode(node, cls, icon, level) {
|
|
244
|
-
const item = new HLayout({
|
|
245
|
-
cls,
|
|
246
|
-
content: [
|
|
247
|
-
new Icon({ cls: 'tree-icon', icon }),
|
|
248
|
-
this.m_props.renderItem ? this.m_props.renderItem(node) : this._renderDef(node),
|
|
249
|
-
],
|
|
250
|
-
data: {
|
|
251
|
-
'node': node,
|
|
252
|
-
'level': level,
|
|
253
|
-
'icon': icon,
|
|
254
|
-
},
|
|
255
|
-
style: {
|
|
256
|
-
paddingLeft: 4 + level * this.m_props.indent
|
|
257
|
-
},
|
|
258
|
-
attrs: {
|
|
259
|
-
draggable: this.m_props.canDragItems ? true : undefined
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
return item;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
*
|
|
266
|
-
*/
|
|
267
|
-
forEach(cb) {
|
|
268
|
-
let found = null;
|
|
269
|
-
function scan(node) {
|
|
270
|
-
if (cb(node) == true) {
|
|
271
|
-
return true;
|
|
272
|
-
}
|
|
273
|
-
if (node.children) {
|
|
274
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
275
|
-
if (scan(node.children[i])) {
|
|
276
|
-
return true;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (this.m_props.root) {
|
|
282
|
-
scan(this.m_props.root);
|
|
283
|
-
}
|
|
284
|
-
return found;
|
|
285
|
-
}
|
|
286
|
-
ensureVisible(id) {
|
|
287
|
-
const { node } = this._getNode(id);
|
|
288
|
-
if (node) {
|
|
289
|
-
node.scrollIntoView();
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
set selection(id) {
|
|
293
|
-
this.select(id, false);
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* care, component should have been created, to select an item at startup,
|
|
297
|
-
* use something like
|
|
298
|
-
* componentCreated( ) {
|
|
299
|
-
* mytree.select( id );
|
|
300
|
-
* }
|
|
301
|
-
*/
|
|
302
|
-
select(id, notify = true) {
|
|
303
|
-
if (this.m_selection?.el) {
|
|
304
|
-
this.m_selection.el.removeClass('selected');
|
|
305
|
-
}
|
|
306
|
-
this.m_selection = null;
|
|
307
|
-
if (id !== undefined) {
|
|
308
|
-
const { node: sel } = this._getNode(id);
|
|
309
|
-
if (sel) {
|
|
310
|
-
this.m_selection = {
|
|
311
|
-
id: id,
|
|
312
|
-
el: sel
|
|
313
|
-
};
|
|
314
|
-
sel.addClass('selected');
|
|
315
|
-
sel.scrollIntoView();
|
|
316
|
-
if (notify) {
|
|
317
|
-
let nd = sel.getData('node');
|
|
318
|
-
this.emit('selectionchange', EvSelectionChange(nd));
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
if (notify) {
|
|
324
|
-
this.emit('selectionchange', EvSelectionChange(null));
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
_getNode(id) {
|
|
329
|
-
let found = { node: null, item: null };
|
|
330
|
-
this.m_container.enumChilds((c) => {
|
|
331
|
-
let node = c.getData('node');
|
|
332
|
-
if (node?.id == id) {
|
|
333
|
-
found = { node: c, item: node };
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
return found;
|
|
338
|
-
}
|
|
339
|
-
get selection() {
|
|
340
|
-
return this.m_selection?.id;
|
|
341
|
-
}
|
|
342
|
-
getNodeWithId(id) {
|
|
343
|
-
return this.forEach((node) => node.id == id);
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
*
|
|
347
|
-
*/
|
|
348
|
-
_click(ev) {
|
|
349
|
-
let dom = ev.target;
|
|
350
|
-
let idom = dom;
|
|
351
|
-
let onsub = false;
|
|
352
|
-
// avoid getting click on sub childs
|
|
353
|
-
if (dom.tabIndex !== -1) {
|
|
354
|
-
onsub = true;
|
|
355
|
-
}
|
|
356
|
-
while (dom != this.dom) {
|
|
357
|
-
let el = Component.getElement(dom);
|
|
358
|
-
let nd = el?.getData('node');
|
|
359
|
-
if (nd) {
|
|
360
|
-
if (nd.children && !onsub) {
|
|
361
|
-
// on text or on expando ?
|
|
362
|
-
if (el.hasClass('selected') || idom.classList.contains('tree-icon')) { //expando
|
|
363
|
-
nd.open = nd.open ? false : true;
|
|
364
|
-
}
|
|
365
|
-
this.m_selection = { id: nd.id, el: null };
|
|
366
|
-
let offset = this.m_view?.dom?.scrollTop;
|
|
367
|
-
this.update();
|
|
368
|
-
if (offset) {
|
|
369
|
-
this.m_view.dom.scrollTo(0, offset);
|
|
370
|
-
}
|
|
371
|
-
this.emit('expand', EvExpand(nd));
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
this.selection = nd.id;
|
|
375
|
-
if (!onsub) {
|
|
376
|
-
if (ev.type == 'click') {
|
|
377
|
-
this.emit('click', EvClick(nd));
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
this.emit('dblclick', EvDblClick(nd));
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
this.emit('selectionchange', EvSelectionChange(nd));
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
dom = dom.parentElement;
|
|
388
|
-
}
|
|
389
|
-
if (ev.type == 'click') {
|
|
390
|
-
this.m_selection = null;
|
|
391
|
-
this.update();
|
|
392
|
-
this.emit('selectionchange', EvSelectionChange(null));
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
_handleCtxMenu(ev) {
|
|
396
|
-
ev.preventDefault();
|
|
397
|
-
let dom = ev.target;
|
|
398
|
-
let idom = dom;
|
|
399
|
-
while (dom != this.dom) {
|
|
400
|
-
let el = Component.getElement(dom);
|
|
401
|
-
let nd = el?.getData('node');
|
|
402
|
-
if (nd) {
|
|
403
|
-
if (nd.children) {
|
|
404
|
-
// on text or on expando ?
|
|
405
|
-
if (idom.classList.contains('tree-icon')) { //expando
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
this.selection = nd.id;
|
|
410
|
-
this.emit('click', EvClick(nd));
|
|
411
|
-
this.emit('contextMenu', EvContextMenu(ev, nd));
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
dom = dom.parentElement;
|
|
415
|
-
}
|
|
416
|
-
this.selection = null;
|
|
417
|
-
this.emit('contextMenu', EvContextMenu(ev, null));
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* constructs a tree node from an array of strings
|
|
421
|
-
* elements are organized like folders (separator = /)
|
|
422
|
-
* @example
|
|
423
|
-
* let root = TreeView.buildFromString( [
|
|
424
|
-
* 'this/is/a/final/file'
|
|
425
|
-
* 'this/is/another/file'
|
|
426
|
-
* ] );
|
|
427
|
-
*/
|
|
428
|
-
static buildFromStrings(paths, separator = '/') {
|
|
429
|
-
let root = {
|
|
430
|
-
id: 0,
|
|
431
|
-
text: '<root>',
|
|
432
|
-
children: []
|
|
433
|
-
};
|
|
434
|
-
function insert(elements, path) {
|
|
435
|
-
let pos = path.indexOf(separator);
|
|
436
|
-
let main = path.substr(0, pos < 0 ? undefined : pos);
|
|
437
|
-
let elem;
|
|
438
|
-
if (pos >= 0) {
|
|
439
|
-
elem = elements.find((el) => {
|
|
440
|
-
return el.text == main;
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
if (!elem) {
|
|
444
|
-
elem = {
|
|
445
|
-
id: path,
|
|
446
|
-
text: main,
|
|
447
|
-
};
|
|
448
|
-
elements.push(elem);
|
|
449
|
-
}
|
|
450
|
-
if (pos >= 0) {
|
|
451
|
-
if (!elem.children) {
|
|
452
|
-
elem.children = [];
|
|
453
|
-
}
|
|
454
|
-
insert(elem.children, path.substr(pos + separator.length));
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
paths.forEach((path) => {
|
|
458
|
-
insert(root.children, path);
|
|
459
|
-
});
|
|
460
|
-
return root;
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* constructs a tree node from an array of nodes like
|
|
464
|
-
* node {
|
|
465
|
-
* id: number,
|
|
466
|
-
* parent: number,
|
|
467
|
-
* name: string
|
|
468
|
-
* }
|
|
469
|
-
*/
|
|
470
|
-
static buildFromHierarchy(nodes, cb) {
|
|
471
|
-
let root = {
|
|
472
|
-
id: 0,
|
|
473
|
-
text: '<root>',
|
|
474
|
-
children: []
|
|
475
|
-
};
|
|
476
|
-
let tree_nodes = [];
|
|
477
|
-
function insert(node) {
|
|
478
|
-
let elem;
|
|
479
|
-
let pelem;
|
|
480
|
-
if (node.parent > 0) {
|
|
481
|
-
pelem = tree_nodes.find((tnode) => tnode.id == node.parent);
|
|
482
|
-
if (!pelem) {
|
|
483
|
-
pelem = {
|
|
484
|
-
id: node.parent,
|
|
485
|
-
text: '',
|
|
486
|
-
children: []
|
|
487
|
-
};
|
|
488
|
-
tree_nodes.push(pelem);
|
|
489
|
-
}
|
|
490
|
-
if (!pelem.children) {
|
|
491
|
-
pelem.children = [];
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
else {
|
|
495
|
-
pelem = root;
|
|
496
|
-
}
|
|
497
|
-
elem = tree_nodes.find((tnode) => tnode.id == node.id);
|
|
498
|
-
if (!elem) {
|
|
499
|
-
elem = {
|
|
500
|
-
id: node.id,
|
|
501
|
-
text: node.name,
|
|
502
|
-
parent: node.parent,
|
|
503
|
-
cls: node.cls,
|
|
504
|
-
icon: node.icon,
|
|
505
|
-
data: node.data,
|
|
506
|
-
};
|
|
507
|
-
if (!node.leaf) {
|
|
508
|
-
elem.children = [];
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
elem.icon = null;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
else {
|
|
515
|
-
elem.text = node.name;
|
|
516
|
-
elem.parent = node.parent;
|
|
517
|
-
}
|
|
518
|
-
tree_nodes.push(elem);
|
|
519
|
-
pelem.children.push(elem);
|
|
520
|
-
}
|
|
521
|
-
nodes.forEach(insert);
|
|
522
|
-
if (cb) {
|
|
523
|
-
tree_nodes.forEach(cb);
|
|
524
|
-
}
|
|
525
|
-
return root;
|
|
526
|
-
}
|
|
527
|
-
}
|
package/lib/esm/x4dom.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file x4events.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
|
-
export let x4document = document;
|