x4js 1.4.3 → 1.4.4
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/index.d.ts +55 -0
- package/lib/index.js +55 -56
- package/lib/router.d.ts +1 -8
- package/lib/router.js +1 -1
- package/package.json +2 -1
- package/src/index.ts +55 -0
- package/src/router.ts +1 -1
- package/tsconfig.json +2 -1
- package/lib/application.d.ts +0 -95
- package/lib/application.js +0 -137
- package/lib/base64.d.ts +0 -31
- package/lib/base64.js +0 -135
- package/lib/base_component.d.ts +0 -64
- package/lib/base_component.js +0 -77
- package/lib/button.d.ts +0 -145
- package/lib/button.js +0 -235
- package/lib/calendar.d.ts +0 -77
- package/lib/calendar.js +0 -236
- package/lib/canvas.d.ts +0 -88
- package/lib/canvas.js +0 -354
- package/lib/cardview.d.ts +0 -83
- package/lib/cardview.js +0 -152
- package/lib/checkbox.d.ts +0 -72
- package/lib/checkbox.js +0 -126
- package/lib/color.d.ts +0 -144
- package/lib/color.js +0 -584
- package/lib/component.d.ts +0 -572
- package/lib/component.js +0 -1712
- package/lib/dom_events.d.ts +0 -284
- package/lib/dom_events.js +0 -13
- package/lib/hosts/host.d.ts +0 -44
- package/lib/hosts/host.js +0 -69
- package/lib/i18n.d.ts +0 -67
- package/lib/i18n.js +0 -169
- package/lib/icon.d.ts +0 -56
- package/lib/icon.js +0 -173
- package/lib/input.d.ts +0 -86
- package/lib/input.js +0 -172
- package/lib/label.d.ts +0 -54
- package/lib/label.js +0 -86
- package/lib/layout.d.ts +0 -77
- package/lib/layout.js +0 -261
- package/lib/list.txt +0 -56
- package/lib/menu.d.ts +0 -122
- package/lib/menu.js +0 -276
- package/lib/popup.d.ts +0 -71
- package/lib/popup.js +0 -373
- package/lib/settings.d.ts +0 -33
- package/lib/settings.js +0 -63
- package/lib/styles.d.ts +0 -81
- package/lib/styles.js +0 -262
- package/lib/tools.d.ts +0 -382
- package/lib/tools.js +0 -1096
- package/lib/x4_events.d.ts +0 -253
- package/lib/x4_events.js +0 -363
- package/list.txt +0 -0
package/lib/layout.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file layout.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
* @license
|
|
11
|
-
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* This program is free software; you can redistribute it and/or modify
|
|
14
|
-
* it under the terms of the GNU General Public License as published by
|
|
15
|
-
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
-
* (at your option) any later version.
|
|
17
|
-
*
|
|
18
|
-
* This program is distributed in the hope that it will be useful,
|
|
19
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
-
* GNU General Public License for more details.
|
|
22
|
-
*
|
|
23
|
-
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>..
|
|
24
|
-
*/
|
|
25
|
-
import { Component, Container } from './component';
|
|
26
|
-
import { isArray } from './tools';
|
|
27
|
-
// ============================================================================
|
|
28
|
-
// [ABSLAYOUT]
|
|
29
|
-
// ============================================================================
|
|
30
|
-
export class AbsLayout extends Container {
|
|
31
|
-
}
|
|
32
|
-
// ============================================================================
|
|
33
|
-
// [HLAYOUT]
|
|
34
|
-
// ============================================================================
|
|
35
|
-
export class HLayout extends Container {
|
|
36
|
-
}
|
|
37
|
-
// ============================================================================
|
|
38
|
-
// [VLAYOUT]
|
|
39
|
-
// ============================================================================
|
|
40
|
-
export class VLayout extends Container {
|
|
41
|
-
}
|
|
42
|
-
export class AutoLayout extends Container {
|
|
43
|
-
constructor(props) {
|
|
44
|
-
super(props);
|
|
45
|
-
this.setDomEvent('sizechange', () => this._updateLayout());
|
|
46
|
-
}
|
|
47
|
-
componentCreated() {
|
|
48
|
-
super.componentCreated();
|
|
49
|
-
this._updateLayout();
|
|
50
|
-
}
|
|
51
|
-
_updateLayout() {
|
|
52
|
-
let horz = this.m_props.defaultLayout == 'horizontal' ? true : false;
|
|
53
|
-
if (this.m_props.switchSize <= 0 && window.screen.height > window.screen.width) {
|
|
54
|
-
horz = !horz;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
let rc = this.getBoundingRect();
|
|
58
|
-
if ((horz && rc.width < this.m_props.switchSize) || (!horz && rc.height < this.m_props.switchSize)) {
|
|
59
|
-
horz = !horz;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (horz) {
|
|
63
|
-
this.removeClass('@vlayout');
|
|
64
|
-
this.addClass('@hlayout');
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.addClass('@vlayout');
|
|
68
|
-
this.removeClass('@hlayout');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
export class GridLayout extends Container {
|
|
73
|
-
constructor(props) {
|
|
74
|
-
/// @ts-ignore
|
|
75
|
-
// Argument of type 'GridLayoutProps' is not assignable to parameter of type 'P'.
|
|
76
|
-
// 'GridLayoutProps' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'GridLayoutProps'.
|
|
77
|
-
super(props);
|
|
78
|
-
}
|
|
79
|
-
/** @ignore */
|
|
80
|
-
render() {
|
|
81
|
-
if (this.m_props.colSizes) {
|
|
82
|
-
this.setStyleValue('grid-template-columns', this.m_props.colSizes);
|
|
83
|
-
}
|
|
84
|
-
if (this.m_props.rowSizes) {
|
|
85
|
-
this.setStyleValue('grid-template-rows', this.m_props.rowSizes);
|
|
86
|
-
}
|
|
87
|
-
if (this.m_props.colGap) {
|
|
88
|
-
this.setStyleValue('grid-gap', this.m_props.colGap);
|
|
89
|
-
}
|
|
90
|
-
if (this.m_props.template) {
|
|
91
|
-
this.setStyleValue('grid-template-areas', this.m_props.template.join('\n'));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
export class TableLayout extends Container {
|
|
96
|
-
m_cells;
|
|
97
|
-
constructor(props) {
|
|
98
|
-
super(props);
|
|
99
|
-
this.setProp('tag', 'table');
|
|
100
|
-
this.m_cells = new Map();
|
|
101
|
-
}
|
|
102
|
-
_getCell(row, col, create = true) {
|
|
103
|
-
let idx = _mkid(row, col);
|
|
104
|
-
return this.m_cells.get(idx) ?? (create ? { item: undefined } : null);
|
|
105
|
-
}
|
|
106
|
-
_setCell(row, col, cell, update = false) {
|
|
107
|
-
let idx = _mkid(row, col);
|
|
108
|
-
this.m_cells.set(idx, cell);
|
|
109
|
-
if (this.dom && cell.item && update) {
|
|
110
|
-
if (cell.item instanceof Component) {
|
|
111
|
-
cell.item.update();
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
this.enumChilds((c) => {
|
|
115
|
-
let crow = c.getData('row');
|
|
116
|
-
if (crow == row) {
|
|
117
|
-
let ccol = c.getData('col');
|
|
118
|
-
if (ccol == col) {
|
|
119
|
-
c.setContent(cell.item);
|
|
120
|
-
c.update();
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
setCell(row, col, item) {
|
|
129
|
-
let cell = this._getCell(row, col);
|
|
130
|
-
cell.item = item;
|
|
131
|
-
this._setCell(row, col, cell, true);
|
|
132
|
-
}
|
|
133
|
-
merge(row, col, rowCount, colCount) {
|
|
134
|
-
let cell = this._getCell(row, col);
|
|
135
|
-
cell.rowSpan = rowCount;
|
|
136
|
-
cell.colSpan = colCount;
|
|
137
|
-
this._setCell(row, col, cell);
|
|
138
|
-
}
|
|
139
|
-
setCellWidth(row, col, width) {
|
|
140
|
-
let cell = this._getCell(row, col);
|
|
141
|
-
cell.width = width;
|
|
142
|
-
this._setCell(row, col, cell);
|
|
143
|
-
}
|
|
144
|
-
setCellHeight(row, col, height) {
|
|
145
|
-
let cell = this._getCell(row, col);
|
|
146
|
-
cell.height = height;
|
|
147
|
-
this._setCell(row, col, cell);
|
|
148
|
-
}
|
|
149
|
-
setCellClass(row, col, cls) {
|
|
150
|
-
let cell = this._getCell(row, col);
|
|
151
|
-
cell.cls = cls;
|
|
152
|
-
this._setCell(row, col, cell);
|
|
153
|
-
}
|
|
154
|
-
setColClass(col, cls) {
|
|
155
|
-
let cell = this._getCell(-1, col);
|
|
156
|
-
cell.cls = cls;
|
|
157
|
-
this._setCell(-1, col, cell);
|
|
158
|
-
}
|
|
159
|
-
setRowClass(row, cls) {
|
|
160
|
-
let cell = this._getCell(row, 999);
|
|
161
|
-
cell.cls = cls;
|
|
162
|
-
this._setCell(row, 999, cell);
|
|
163
|
-
}
|
|
164
|
-
getCell(row, col) {
|
|
165
|
-
let cell = this._getCell(row, col);
|
|
166
|
-
return cell?.item;
|
|
167
|
-
}
|
|
168
|
-
render() {
|
|
169
|
-
let rows = [];
|
|
170
|
-
let skip = [];
|
|
171
|
-
for (let r = 0; r < this.m_props.rows; r++) {
|
|
172
|
-
let cols = [];
|
|
173
|
-
for (let c = 0; c < this.m_props.columns; c++) {
|
|
174
|
-
let idx = _mkid(r, c);
|
|
175
|
-
if (skip.indexOf(idx) >= 0) {
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
let cell = this.m_cells.get(idx);
|
|
179
|
-
let cdata = this.m_cells.get(_mkid(-1, c));
|
|
180
|
-
let cls = '';
|
|
181
|
-
if (cell && cell.cls) {
|
|
182
|
-
cls = cell.cls;
|
|
183
|
-
}
|
|
184
|
-
if (cdata && cdata.cls) {
|
|
185
|
-
cls += ' ' + cdata.cls;
|
|
186
|
-
}
|
|
187
|
-
let cc = new Component({
|
|
188
|
-
tag: 'td',
|
|
189
|
-
content: cell?.item,
|
|
190
|
-
width: cell?.width,
|
|
191
|
-
height: cell?.height,
|
|
192
|
-
data: { row: r, col: c },
|
|
193
|
-
cls
|
|
194
|
-
});
|
|
195
|
-
if (cell) {
|
|
196
|
-
let rs = cell.rowSpan ?? 0, cs = cell.colSpan ?? 0;
|
|
197
|
-
if (rs > 0) {
|
|
198
|
-
cc.setAttribute('rowspan', rs + 1);
|
|
199
|
-
}
|
|
200
|
-
if (cs > 0) {
|
|
201
|
-
cc.setAttribute('colspan', cs + 1);
|
|
202
|
-
}
|
|
203
|
-
if (rs || cs) {
|
|
204
|
-
for (let sr = 0; sr <= rs; sr++) {
|
|
205
|
-
for (let sc = 0; sc <= cs; sc++) {
|
|
206
|
-
skip.push(_mkid(sr + r, sc + c));
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
cols.push(cc);
|
|
212
|
-
}
|
|
213
|
-
let rdata = this._getCell(r, 999, false);
|
|
214
|
-
let rr = new Component({
|
|
215
|
-
tag: 'tr',
|
|
216
|
-
data: { row: r },
|
|
217
|
-
content: cols,
|
|
218
|
-
cls: rdata?.cls
|
|
219
|
-
});
|
|
220
|
-
rows.push(rr);
|
|
221
|
-
}
|
|
222
|
-
this.setContent(rows);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* @ignore
|
|
227
|
-
*/
|
|
228
|
-
function _mkid(row, col) {
|
|
229
|
-
return row * 1000 + col;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* @ignore
|
|
233
|
-
*/
|
|
234
|
-
function _getid(key) {
|
|
235
|
-
return {
|
|
236
|
-
row: Math.floor(key / 1000) | 0,
|
|
237
|
-
col: (key % 1000) | 0
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
export class ScrollView extends Component {
|
|
241
|
-
constructor(props) {
|
|
242
|
-
super(props);
|
|
243
|
-
this.setContent(props.content);
|
|
244
|
-
}
|
|
245
|
-
setContent(content) {
|
|
246
|
-
if (!content) {
|
|
247
|
-
super.setContent(null);
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
let container;
|
|
251
|
-
if (isArray(content)) {
|
|
252
|
-
container = new VLayout({ content });
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
container = content;
|
|
256
|
-
}
|
|
257
|
-
container.addClass('@scroll-container');
|
|
258
|
-
super.setContent(container);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
package/lib/list.txt
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
application.js
|
|
2
|
-
base_component.js
|
|
3
|
-
base64.js
|
|
4
|
-
button.js
|
|
5
|
-
calendar.js
|
|
6
|
-
canvas.js
|
|
7
|
-
cardview.js
|
|
8
|
-
checkbox.js
|
|
9
|
-
color.js
|
|
10
|
-
colorpicker.js
|
|
11
|
-
combobox.js
|
|
12
|
-
component.js
|
|
13
|
-
datastore.js
|
|
14
|
-
dialog.js
|
|
15
|
-
dom_events.js
|
|
16
|
-
drag_manager.js
|
|
17
|
-
drawtext.js
|
|
18
|
-
fileupload.js
|
|
19
|
-
form.js
|
|
20
|
-
formatters.js
|
|
21
|
-
gridview.js
|
|
22
|
-
i18n.js
|
|
23
|
-
icon.js
|
|
24
|
-
image.js
|
|
25
|
-
index.js
|
|
26
|
-
input.js
|
|
27
|
-
label.js
|
|
28
|
-
layout.js
|
|
29
|
-
link.js
|
|
30
|
-
listview.js
|
|
31
|
-
md5.js
|
|
32
|
-
menu.js
|
|
33
|
-
messagebox.js
|
|
34
|
-
panel.js
|
|
35
|
-
popup.js
|
|
36
|
-
property_editor.js
|
|
37
|
-
radiobtn.js
|
|
38
|
-
rating.js
|
|
39
|
-
request.js
|
|
40
|
-
router.js
|
|
41
|
-
settings.js
|
|
42
|
-
sidebarview.js
|
|
43
|
-
smartedit.js
|
|
44
|
-
spreadsheet.js
|
|
45
|
-
styles.js
|
|
46
|
-
svgcomponent.js
|
|
47
|
-
tabbar.js
|
|
48
|
-
tabview.js
|
|
49
|
-
textarea.js
|
|
50
|
-
textedit.js
|
|
51
|
-
texthiliter.js
|
|
52
|
-
toaster.js
|
|
53
|
-
tools.js
|
|
54
|
-
tooltips.js
|
|
55
|
-
treeview.js
|
|
56
|
-
x4_events.js
|
package/lib/menu.d.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file menu.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
* @license
|
|
11
|
-
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* This program is free software; you can redistribute it and/or modify
|
|
14
|
-
* it under the terms of the GNU General Public License as published by
|
|
15
|
-
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
-
* (at your option) any later version.
|
|
17
|
-
*
|
|
18
|
-
* This program is distributed in the hope that it will be useful,
|
|
19
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
-
* GNU General Public License for more details.
|
|
22
|
-
*
|
|
23
|
-
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
-
**/
|
|
25
|
-
import { CEventMap, Component, CProps } from './component';
|
|
26
|
-
import { EvClick, EventCallback } from './x4_events';
|
|
27
|
-
import { Popup, PopupProps } from './popup';
|
|
28
|
-
import { IconID } from './icon';
|
|
29
|
-
import { Label } from './label';
|
|
30
|
-
import { HLayout } from './layout';
|
|
31
|
-
export declare class MenuSeparator extends Component {
|
|
32
|
-
}
|
|
33
|
-
export declare class MenuTitle extends Label {
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Standard Menu
|
|
37
|
-
*/
|
|
38
|
-
export declare type MenuOrSep = MenuItem | MenuSeparator | MenuTitle;
|
|
39
|
-
export interface MenuProps extends PopupProps {
|
|
40
|
-
items?: MenuOrSep[];
|
|
41
|
-
}
|
|
42
|
-
export declare class Menu extends Popup<MenuProps> {
|
|
43
|
-
private static watchCount;
|
|
44
|
-
private static rootMenu;
|
|
45
|
-
protected m_subMenu: Menu;
|
|
46
|
-
protected m_opener: MenuItem;
|
|
47
|
-
protected m_virtual: boolean;
|
|
48
|
-
protected m_lock: number;
|
|
49
|
-
constructor(props: MenuProps, opener?: MenuItem);
|
|
50
|
-
lock(yes: boolean): void;
|
|
51
|
-
setVirtual(): void;
|
|
52
|
-
setSubMenu(menu: Menu): void;
|
|
53
|
-
hideSubMenu(): void;
|
|
54
|
-
/** @ignore */
|
|
55
|
-
render(props: MenuProps): void;
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*/
|
|
59
|
-
show(): void;
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
*/
|
|
63
|
-
close(): void;
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
clear(): void;
|
|
68
|
-
/**
|
|
69
|
-
* @internal
|
|
70
|
-
*/
|
|
71
|
-
static _addMenu(menu: any): void;
|
|
72
|
-
static _removeMenu(): void;
|
|
73
|
-
private static _mouseWatcher;
|
|
74
|
-
/**
|
|
75
|
-
* hide all the visible menus
|
|
76
|
-
*/
|
|
77
|
-
static _discardAll(): void;
|
|
78
|
-
displayAt(ev: UIEvent): void;
|
|
79
|
-
displayAt(x: number, y?: number, align?: string, offset?: {
|
|
80
|
-
x: any;
|
|
81
|
-
y: any;
|
|
82
|
-
}): void;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* MENU ITEM
|
|
86
|
-
*/
|
|
87
|
-
interface MenuItemEventMap extends CEventMap {
|
|
88
|
-
click: EvClick;
|
|
89
|
-
}
|
|
90
|
-
export interface MenuItemProps extends CProps {
|
|
91
|
-
itemId?: any;
|
|
92
|
-
text?: string;
|
|
93
|
-
icon?: IconID;
|
|
94
|
-
items?: MenuOrSep[];
|
|
95
|
-
checked?: boolean;
|
|
96
|
-
cls?: string;
|
|
97
|
-
click?: EventCallback<EvClick>;
|
|
98
|
-
}
|
|
99
|
-
export declare class MenuItem extends Component<MenuItemProps, MenuItemEventMap> {
|
|
100
|
-
private m_menu;
|
|
101
|
-
private m_isOpen;
|
|
102
|
-
constructor(text: string, click: EventCallback<EvClick>);
|
|
103
|
-
constructor(props: MenuItemProps);
|
|
104
|
-
/** @ignore */
|
|
105
|
-
render(props: MenuItemProps): void;
|
|
106
|
-
get id(): any;
|
|
107
|
-
get text(): string;
|
|
108
|
-
get isPopup(): boolean;
|
|
109
|
-
_close(): void;
|
|
110
|
-
protected _click(ev: MouseEvent): void;
|
|
111
|
-
protected _mousedown(ev: MouseEvent): void;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
*
|
|
115
|
-
*/
|
|
116
|
-
export declare class MenuBar extends HLayout {
|
|
117
|
-
protected m_items: MenuOrSep[];
|
|
118
|
-
constructor(props: MenuProps, opener?: MenuItem);
|
|
119
|
-
/** @ignore */
|
|
120
|
-
render(): void;
|
|
121
|
-
}
|
|
122
|
-
export {};
|
package/lib/menu.js
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file menu.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
* @license
|
|
11
|
-
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* This program is free software; you can redistribute it and/or modify
|
|
14
|
-
* it under the terms of the GNU General Public License as published by
|
|
15
|
-
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
-
* (at your option) any later version.
|
|
17
|
-
*
|
|
18
|
-
* This program is distributed in the hope that it will be useful,
|
|
19
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
-
* GNU General Public License for more details.
|
|
22
|
-
*
|
|
23
|
-
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
-
**/
|
|
25
|
-
import { Component } from './component';
|
|
26
|
-
import { EvClick } from './x4_events';
|
|
27
|
-
import { Popup } from './popup';
|
|
28
|
-
import { Icon } from './icon';
|
|
29
|
-
import { Label } from './label';
|
|
30
|
-
import { HLayout } from './layout';
|
|
31
|
-
import { isString, getMousePos } from './tools';
|
|
32
|
-
// ============================================================================
|
|
33
|
-
// [MENU]
|
|
34
|
-
// ============================================================================
|
|
35
|
-
export class MenuSeparator extends Component {
|
|
36
|
-
}
|
|
37
|
-
export class MenuTitle extends Label {
|
|
38
|
-
}
|
|
39
|
-
export class Menu extends Popup {
|
|
40
|
-
static watchCount = 0;
|
|
41
|
-
static rootMenu = null;
|
|
42
|
-
m_subMenu;
|
|
43
|
-
m_opener;
|
|
44
|
-
m_virtual;
|
|
45
|
-
m_lock;
|
|
46
|
-
constructor(props, opener) {
|
|
47
|
-
super(props);
|
|
48
|
-
this.addClass('@shadow');
|
|
49
|
-
this.m_opener = opener;
|
|
50
|
-
this.m_virtual = false;
|
|
51
|
-
this.m_lock = 0;
|
|
52
|
-
this.enableMask(false);
|
|
53
|
-
}
|
|
54
|
-
lock(yes) {
|
|
55
|
-
this.m_lock += yes ? 1 : -1;
|
|
56
|
-
}
|
|
57
|
-
setVirtual() {
|
|
58
|
-
this.m_virtual = true;
|
|
59
|
-
}
|
|
60
|
-
setSubMenu(menu) {
|
|
61
|
-
this.m_subMenu = menu;
|
|
62
|
-
}
|
|
63
|
-
hideSubMenu() {
|
|
64
|
-
if (this.m_subMenu) {
|
|
65
|
-
this.m_subMenu.m_opener._close();
|
|
66
|
-
this.m_subMenu.hide();
|
|
67
|
-
this.m_subMenu = null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/** @ignore */
|
|
71
|
-
render(props) {
|
|
72
|
-
this.setContent(props.items);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
*/
|
|
77
|
-
show() {
|
|
78
|
-
if (!this.m_virtual) {
|
|
79
|
-
Menu._addMenu(this);
|
|
80
|
-
}
|
|
81
|
-
super.show();
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
close() {
|
|
87
|
-
if (!this.dom && !this.m_virtual) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (this.m_opener) {
|
|
91
|
-
this.m_opener._close();
|
|
92
|
-
}
|
|
93
|
-
if (this.m_subMenu) {
|
|
94
|
-
this.m_subMenu.close();
|
|
95
|
-
this.m_subMenu = null;
|
|
96
|
-
}
|
|
97
|
-
super.close();
|
|
98
|
-
Menu._removeMenu();
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
*/
|
|
103
|
-
clear() {
|
|
104
|
-
this.m_props.items = [];
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* @internal
|
|
108
|
-
*/
|
|
109
|
-
static _addMenu(menu) {
|
|
110
|
-
//console.log( 'addmenu' );
|
|
111
|
-
if (Menu.watchCount == 0) {
|
|
112
|
-
Menu.rootMenu = menu;
|
|
113
|
-
document.addEventListener('mousedown', Menu._mouseWatcher);
|
|
114
|
-
}
|
|
115
|
-
Menu.watchCount++;
|
|
116
|
-
}
|
|
117
|
-
static _removeMenu() {
|
|
118
|
-
//console.log( 'removemenu' );
|
|
119
|
-
console.assert(Menu.watchCount > 0);
|
|
120
|
-
Menu.watchCount--;
|
|
121
|
-
if (Menu.watchCount == 0) {
|
|
122
|
-
document.removeEventListener('mousedown', Menu._mouseWatcher);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
static _mouseWatcher(ev) {
|
|
126
|
-
if (ev.defaultPrevented) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
let elOn = ev.target;
|
|
130
|
-
while (elOn) {
|
|
131
|
-
// is mouse on a menu
|
|
132
|
-
let mouseon = Component.getElement(elOn);
|
|
133
|
-
if (mouseon && (mouseon instanceof Menu /*|| elOn.$el instanceof Menubar*/)) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
elOn = elOn.parentElement;
|
|
137
|
-
}
|
|
138
|
-
Menu._discardAll();
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* hide all the visible menus
|
|
142
|
-
*/
|
|
143
|
-
static _discardAll() {
|
|
144
|
-
if (Menu.rootMenu) {
|
|
145
|
-
Menu.rootMenu.close();
|
|
146
|
-
Menu.rootMenu = null;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
displayAt(...args) {
|
|
150
|
-
if (!this.m_lock) {
|
|
151
|
-
Menu._discardAll();
|
|
152
|
-
}
|
|
153
|
-
let x, y, align, offset;
|
|
154
|
-
if (args.length == 1) {
|
|
155
|
-
({ x, y } = getMousePos(args[0], true));
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
[x, y, align, offset] = args;
|
|
159
|
-
}
|
|
160
|
-
if (!align) {
|
|
161
|
-
align = 'top left';
|
|
162
|
-
}
|
|
163
|
-
super.displayAt(x, y, align, offset);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
export class MenuItem extends Component {
|
|
167
|
-
m_menu;
|
|
168
|
-
m_isOpen;
|
|
169
|
-
constructor(a, b) {
|
|
170
|
-
if (isString(a)) {
|
|
171
|
-
super({
|
|
172
|
-
text: a,
|
|
173
|
-
click: b
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
super(a);
|
|
178
|
-
}
|
|
179
|
-
this.mapPropEvents(this.m_props, 'click');
|
|
180
|
-
this.m_menu = null;
|
|
181
|
-
this.m_isOpen = false;
|
|
182
|
-
this.setDomEvent('mousedown', (e) => this._mousedown(e));
|
|
183
|
-
this.setDomEvent('click', (e) => this._click(e));
|
|
184
|
-
}
|
|
185
|
-
/** @ignore */
|
|
186
|
-
render(props) {
|
|
187
|
-
let icon = props.icon ?? 0x20;
|
|
188
|
-
let text = props.text;
|
|
189
|
-
if (props.checked !== undefined) {
|
|
190
|
-
icon = props.checked ? 'cls(far fa-check)' : 0; //todo: use stylesheet
|
|
191
|
-
}
|
|
192
|
-
if (this.isPopup) {
|
|
193
|
-
this.addClass('@popup-menu-item');
|
|
194
|
-
}
|
|
195
|
-
if (!text && !icon) {
|
|
196
|
-
this.addClass('@separator');
|
|
197
|
-
}
|
|
198
|
-
if (props.cls) {
|
|
199
|
-
this.addClass(props.cls);
|
|
200
|
-
}
|
|
201
|
-
this.setProp('tag', 'a');
|
|
202
|
-
//@bug: do not kill focus on click
|
|
203
|
-
// this.setAttribute( 'tabindex', '0' );
|
|
204
|
-
this.setContent([
|
|
205
|
-
icon < 0 ? null : new Icon({ icon }),
|
|
206
|
-
new Label({ flex: 1, text })
|
|
207
|
-
]);
|
|
208
|
-
}
|
|
209
|
-
get id() {
|
|
210
|
-
return this.m_props.itemId;
|
|
211
|
-
}
|
|
212
|
-
get text() {
|
|
213
|
-
return this.m_props.text;
|
|
214
|
-
}
|
|
215
|
-
get isPopup() {
|
|
216
|
-
return !!this.m_props.items;
|
|
217
|
-
}
|
|
218
|
-
_close() {
|
|
219
|
-
this.removeClass('@opened');
|
|
220
|
-
this.m_isOpen = false;
|
|
221
|
-
}
|
|
222
|
-
_click(ev) {
|
|
223
|
-
if (!this.isPopup) {
|
|
224
|
-
this.emit('click', EvClick());
|
|
225
|
-
Menu._discardAll();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
_mousedown(ev) {
|
|
229
|
-
if (this.isPopup) {
|
|
230
|
-
if (!this.m_menu) {
|
|
231
|
-
this.m_menu = new Menu({ items: this.m_props.items }, this);
|
|
232
|
-
}
|
|
233
|
-
let doClose = this.m_isOpen;
|
|
234
|
-
// if parent menu has an opened sub menu, close it
|
|
235
|
-
let parent_menu = Component.getElement(this.dom, Menu);
|
|
236
|
-
if (parent_menu) {
|
|
237
|
-
parent_menu.hideSubMenu();
|
|
238
|
-
}
|
|
239
|
-
if (!doClose) {
|
|
240
|
-
if (parent_menu) {
|
|
241
|
-
parent_menu.setSubMenu(this.m_menu);
|
|
242
|
-
}
|
|
243
|
-
this.m_isOpen = true;
|
|
244
|
-
let rc = this.getBoundingRect();
|
|
245
|
-
this.m_menu.lock(true);
|
|
246
|
-
if (parent_menu) {
|
|
247
|
-
// standard menu
|
|
248
|
-
this.m_menu.displayAt(rc.right, rc.top);
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
// menubar / menubutton
|
|
252
|
-
this.m_menu.displayAt(rc.left, rc.bottom);
|
|
253
|
-
}
|
|
254
|
-
this.m_menu.lock(false);
|
|
255
|
-
this.addClass('@opened');
|
|
256
|
-
}
|
|
257
|
-
ev.preventDefault();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
*
|
|
263
|
-
*/
|
|
264
|
-
export class MenuBar extends HLayout {
|
|
265
|
-
m_items;
|
|
266
|
-
constructor(props, opener) {
|
|
267
|
-
super(props);
|
|
268
|
-
console.assert(false, 'not imp');
|
|
269
|
-
this.addClass('@shadow');
|
|
270
|
-
this.m_items = props.items;
|
|
271
|
-
}
|
|
272
|
-
/** @ignore */
|
|
273
|
-
render() {
|
|
274
|
-
this.setContent(this.m_items);
|
|
275
|
-
}
|
|
276
|
-
}
|