x4js 1.4.2
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/application.d.ts +95 -0
- package/lib/application.js +137 -0
- package/lib/base64.d.ts +31 -0
- package/lib/base64.js +135 -0
- package/lib/base_component.d.ts +64 -0
- package/lib/base_component.js +77 -0
- package/lib/button.d.ts +145 -0
- package/lib/button.js +235 -0
- package/lib/calendar.d.ts +77 -0
- package/lib/calendar.js +236 -0
- package/lib/canvas.d.ts +88 -0
- package/lib/canvas.js +354 -0
- package/lib/cardview.d.ts +83 -0
- package/lib/cardview.js +152 -0
- package/lib/checkbox.d.ts +72 -0
- package/lib/checkbox.js +126 -0
- package/lib/color.d.ts +144 -0
- package/lib/color.js +584 -0
- package/lib/colorpicker.d.ts +98 -0
- package/lib/colorpicker.js +1457 -0
- package/lib/combobox.d.ts +97 -0
- package/lib/combobox.js +246 -0
- package/lib/component.d.ts +572 -0
- package/lib/component.js +1712 -0
- package/lib/datastore.d.ts +392 -0
- package/lib/datastore.js +986 -0
- package/lib/dialog.d.ts +171 -0
- package/lib/dialog.js +468 -0
- package/lib/dom_events.d.ts +284 -0
- package/lib/dom_events.js +13 -0
- package/lib/drag_manager.d.ts +26 -0
- package/lib/drag_manager.js +118 -0
- package/lib/drawtext.d.ts +43 -0
- package/lib/drawtext.js +261 -0
- package/lib/fileupload.d.ts +60 -0
- package/lib/fileupload.js +158 -0
- package/lib/form.d.ts +122 -0
- package/lib/form.js +293 -0
- package/lib/formatters.d.ts +31 -0
- package/lib/formatters.js +75 -0
- package/lib/gridview.d.ts +171 -0
- package/lib/gridview.js +786 -0
- package/lib/hosts/host.d.ts +44 -0
- package/lib/hosts/host.js +69 -0
- package/lib/i18n.d.ts +67 -0
- package/lib/i18n.js +169 -0
- package/lib/icon.d.ts +56 -0
- package/lib/icon.js +173 -0
- package/lib/image.d.ts +51 -0
- package/lib/image.js +149 -0
- package/lib/index.js +1 -0
- package/lib/input.d.ts +86 -0
- package/lib/input.js +172 -0
- package/lib/label.d.ts +54 -0
- package/lib/label.js +86 -0
- package/lib/layout.d.ts +77 -0
- package/lib/layout.js +261 -0
- package/lib/link.d.ts +46 -0
- package/lib/link.js +55 -0
- package/lib/listview.d.ts +173 -0
- package/lib/listview.js +532 -0
- package/lib/md5.d.ts +56 -0
- package/lib/md5.js +397 -0
- package/lib/menu.d.ts +122 -0
- package/lib/menu.js +276 -0
- package/lib/messagebox.d.ts +64 -0
- package/lib/messagebox.js +141 -0
- package/lib/panel.d.ts +42 -0
- package/lib/panel.js +61 -0
- package/lib/popup.d.ts +71 -0
- package/lib/popup.js +373 -0
- package/lib/property_editor.d.ts +67 -0
- package/lib/property_editor.js +247 -0
- package/lib/radiobtn.d.ts +68 -0
- package/lib/radiobtn.js +131 -0
- package/lib/rating.d.ts +49 -0
- package/lib/rating.js +93 -0
- package/lib/request.d.ts +48 -0
- package/lib/request.js +220 -0
- package/lib/router.d.ts +13 -0
- package/lib/router.js +27 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.js +63 -0
- package/lib/sidebarview.d.ts +44 -0
- package/lib/sidebarview.js +73 -0
- package/lib/smartedit.d.ts +103 -0
- package/lib/smartedit.js +381 -0
- package/lib/spreadsheet.d.ts +214 -0
- package/lib/spreadsheet.js +1073 -0
- package/lib/styles.d.ts +81 -0
- package/lib/styles.js +262 -0
- package/lib/svgcomponent.d.ts +165 -0
- package/lib/svgcomponent.js +350 -0
- package/lib/tabbar.d.ts +41 -0
- package/lib/tabbar.js +66 -0
- package/lib/tabview.d.ts +45 -0
- package/lib/tabview.js +79 -0
- package/lib/textarea.d.ts +59 -0
- package/lib/textarea.js +119 -0
- package/lib/textedit.d.ts +118 -0
- package/lib/textedit.js +406 -0
- package/lib/texthiliter.d.ts +56 -0
- package/lib/texthiliter.js +219 -0
- package/lib/toaster.d.ts +38 -0
- package/lib/toaster.js +58 -0
- package/lib/tools.d.ts +382 -0
- package/lib/tools.js +1096 -0
- package/lib/tooltips.d.ts +42 -0
- package/lib/tooltips.js +148 -0
- package/lib/treeview.d.ts +128 -0
- package/lib/treeview.js +490 -0
- package/lib/x4_events.d.ts +253 -0
- package/lib/x4_events.js +363 -0
- package/package.json +21 -0
- package/src/README.md +2 -0
- package/src/application.ts +191 -0
- package/src/base64.ts +162 -0
- package/src/base_component.ts +118 -0
- package/src/button.ts +327 -0
- package/src/calendar.ts +312 -0
- package/src/canvas.ts +501 -0
- package/src/cardview.ts +220 -0
- package/src/checkbox.ts +178 -0
- package/src/color.ts +748 -0
- package/src/colorpicker.ts +1618 -0
- package/src/combobox.ts +348 -0
- package/src/component.ts +2330 -0
- package/src/datastore.ts +1318 -0
- package/src/dialog.ts +631 -0
- package/src/dom_events.ts +297 -0
- package/src/drag_manager.ts +168 -0
- package/src/drawtext.ts +342 -0
- package/src/fileupload.ts +208 -0
- package/src/form.ts +362 -0
- package/src/formatters.ts +96 -0
- package/src/gridview.ts +1051 -0
- package/src/hosts/electron.ts +161 -0
- package/src/hosts/host.ts +100 -0
- package/src/hosts/nwjs.ts +141 -0
- package/src/hosts/nwjs_types.ts +339 -0
- package/src/i18n.ts +205 -0
- package/src/icon.ts +237 -0
- package/src/image.ts +198 -0
- package/src/input.ts +236 -0
- package/src/label.ts +124 -0
- package/src/layout.ts +366 -0
- package/src/link.ts +82 -0
- package/src/listview.ts +749 -0
- package/src/md5.ts +432 -0
- package/src/menu.ts +394 -0
- package/src/messagebox.ts +199 -0
- package/src/panel.ts +81 -0
- package/src/popup.ts +488 -0
- package/src/property_editor.ts +333 -0
- package/src/radiobtn.ts +190 -0
- package/src/rating.ts +131 -0
- package/src/request.ts +296 -0
- package/src/router.ts +43 -0
- package/src/settings.ts +75 -0
- package/src/sidebarview.ts +97 -0
- package/src/smartedit.ts +532 -0
- package/src/spreadsheet.ts +1423 -0
- package/src/styles.ts +332 -0
- package/src/svgcomponent.ts +440 -0
- package/src/tabbar.ts +105 -0
- package/src/tabview.ts +106 -0
- package/src/textarea.ts +183 -0
- package/src/textedit.ts +535 -0
- package/src/texthiliter.ts +284 -0
- package/src/toaster.ts +76 -0
- package/src/tools.ts +1391 -0
- package/src/tooltips.ts +185 -0
- package/src/treeview.ts +670 -0
- package/src/x4.less +1940 -0
- package/src/x4_events.ts +558 -0
- package/tsconfig.json +14 -0
package/src/popup.ts
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file popup.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
|
+
|
|
26
|
+
import { Container, CProps, flyWrap, SizerOverlay, EvOverlayResize, Component, ContainerEventMap, EvSize } from './component'
|
|
27
|
+
import { Point, Size, getMousePos, asap } from './tools'
|
|
28
|
+
import { BasicEvent } from './x4_events';
|
|
29
|
+
import { Application } from './application';
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export interface EvMove extends BasicEvent {
|
|
33
|
+
pos: Point;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function EvMove(pos: Point): EvMove {
|
|
37
|
+
return BasicEvent<EvMove>({ pos });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export interface PopupEventMap extends ContainerEventMap {
|
|
42
|
+
size: EvSize;
|
|
43
|
+
move: EvMove;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface PopupProps<E extends PopupEventMap = PopupEventMap> extends CProps<E> {
|
|
47
|
+
sizable?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* base class for all popup elements
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
export class Popup<P extends PopupProps = PopupProps, E extends PopupEventMap = PopupEventMap> extends Container<P, E>
|
|
56
|
+
{
|
|
57
|
+
protected m_ui_mask: HTMLElement;
|
|
58
|
+
private m_hasMask: boolean = true;
|
|
59
|
+
|
|
60
|
+
static modal_stack: HTMLElement[] = [];
|
|
61
|
+
|
|
62
|
+
constructor(props: P) {
|
|
63
|
+
super(props);
|
|
64
|
+
|
|
65
|
+
this.addClass('@hidden');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
enableMask(enable = true) {
|
|
69
|
+
this.m_hasMask = enable;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* display the popup on screen
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
public show(modal?: boolean) {
|
|
77
|
+
|
|
78
|
+
if (modal !== undefined) {
|
|
79
|
+
this.m_hasMask = modal ? true : false;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
modal = this.m_hasMask;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.m_hasMask) {
|
|
86
|
+
|
|
87
|
+
// remove the focus
|
|
88
|
+
const focus = document.activeElement as HTMLElement;
|
|
89
|
+
if (focus) {
|
|
90
|
+
focus.blur()
|
|
91
|
+
}
|
|
92
|
+
this.m_ui_mask = <HTMLElement>document.body.lastChild;
|
|
93
|
+
|
|
94
|
+
while (this.m_ui_mask) {
|
|
95
|
+
|
|
96
|
+
if (this.m_ui_mask.nodeType == 1) { // only element nodes
|
|
97
|
+
|
|
98
|
+
let elUI = flyWrap(this.m_ui_mask);
|
|
99
|
+
|
|
100
|
+
if (elUI.hasClass('@menu') || elUI.hasClass('@non-maskable') ) {
|
|
101
|
+
/* avoid circular dependencies instanceof Menu*/
|
|
102
|
+
/* avoid nonmaskable elements tobe masked */
|
|
103
|
+
}
|
|
104
|
+
else if (elUI.getStyleValue('display') == 'none' || !elUI.isUserVisible()) {
|
|
105
|
+
/* avoid masking hidden elements */
|
|
106
|
+
}
|
|
107
|
+
else if( !elUI.hasClass('@comp') ) {
|
|
108
|
+
/* avoid masking element that are not to us */
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.m_ui_mask = <HTMLElement>this.m_ui_mask.previousSibling;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (this.m_ui_mask) {
|
|
119
|
+
flyWrap(this.m_ui_mask).addClass('@mask');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (modal) {
|
|
124
|
+
Application.instance().enterModal(true);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// to avoid body growing because of appendChild
|
|
128
|
+
this.setStyle({
|
|
129
|
+
left: 0,
|
|
130
|
+
top: 0
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
document.body.appendChild(this._build());
|
|
134
|
+
|
|
135
|
+
this.removeClass('@hidden');
|
|
136
|
+
this.centerOnScreen( );
|
|
137
|
+
|
|
138
|
+
if (modal) {
|
|
139
|
+
let focus = document.activeElement;
|
|
140
|
+
if (!this.dom.contains(focus)) {
|
|
141
|
+
|
|
142
|
+
const autofocus = this.queryItem('[autofocus]');
|
|
143
|
+
if( autofocus ) {
|
|
144
|
+
autofocus.focus( )
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
let tabbable = this.queryItem('[tabindex]');
|
|
148
|
+
|
|
149
|
+
if( tabbable ) {
|
|
150
|
+
let tab_indexes: HTMLElement[] = [].map.call(tabbable, (e) => { return e; });
|
|
151
|
+
|
|
152
|
+
// remove hidden elements
|
|
153
|
+
tab_indexes = tab_indexes.filter((el) => el.offsetParent !== null);
|
|
154
|
+
if (tab_indexes.length) {
|
|
155
|
+
tab_indexes[0].focus( );
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
Popup.modal_stack.push(this.dom);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
centerOnScreen( ) {
|
|
166
|
+
let rc = this.getBoundingRect();
|
|
167
|
+
|
|
168
|
+
let x = (document.body.clientWidth - rc.width) / 2,
|
|
169
|
+
y = (document.body.clientHeight - rc.height) / 2;
|
|
170
|
+
|
|
171
|
+
this.setStyleValue('left', x);
|
|
172
|
+
this.setStyleValue('top', y);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* display the popup at a specific position
|
|
177
|
+
* @param x
|
|
178
|
+
* @param y
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
public displayAt(x: number, y: number, align: string = 'top left', offset?: { x, y }) {
|
|
182
|
+
|
|
183
|
+
this.show();
|
|
184
|
+
|
|
185
|
+
let halign = 'l',
|
|
186
|
+
valign = 't';
|
|
187
|
+
|
|
188
|
+
if (align.indexOf('right') >= 0) {
|
|
189
|
+
halign = 'r';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (align.indexOf('bottom') >= 0) {
|
|
193
|
+
valign = 'b';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// @TODO: this is a minimal overflow problem solution
|
|
197
|
+
let rc = document.body.getBoundingClientRect(),
|
|
198
|
+
rm = this.getBoundingRect();
|
|
199
|
+
|
|
200
|
+
if (halign == 'r') {
|
|
201
|
+
x -= rm.width;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (valign == 'b') {
|
|
205
|
+
y -= rm.height;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (offset) {
|
|
209
|
+
x += offset.x;
|
|
210
|
+
y += offset.y;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (x < 4) {
|
|
214
|
+
x = 4;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if ((x + rm.width) > rc.right - 4) {
|
|
218
|
+
x = rc.right - 4 - rm.width;
|
|
219
|
+
if (offset?.x < 0) {
|
|
220
|
+
x += offset.x;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (y < 4) {
|
|
225
|
+
y = 4;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if ((y + rm.height) > rc.bottom - 4) {
|
|
229
|
+
y = rc.bottom - 4 - rm.height;
|
|
230
|
+
|
|
231
|
+
if (offset?.y < 0) {
|
|
232
|
+
y += offset.y;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
this.setStyle({ left: x, top: y });
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* close the popup
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
public close() {
|
|
244
|
+
this.hide();
|
|
245
|
+
|
|
246
|
+
if (this.m_hasMask && this.m_ui_mask) {
|
|
247
|
+
flyWrap(this.m_ui_mask).removeClass('@mask');
|
|
248
|
+
const app = Application.instance();
|
|
249
|
+
app.enterModal(false);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let index = Popup.modal_stack.indexOf(this.dom);
|
|
253
|
+
if (index >= 0) {
|
|
254
|
+
Popup.modal_stack.splice(index);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
this.dispose();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
componentCreated() {
|
|
261
|
+
|
|
262
|
+
if (this.m_props.sizable) {
|
|
263
|
+
|
|
264
|
+
this.addClass('@size-all');
|
|
265
|
+
|
|
266
|
+
let els = ['top', 'right', 'bottom', 'left', 'topleft', 'topright', 'bottomleft', 'bottomright'];
|
|
267
|
+
|
|
268
|
+
for (let sens of els) {
|
|
269
|
+
new SizerOverlay({
|
|
270
|
+
target: this,
|
|
271
|
+
sens: sens as any,
|
|
272
|
+
events: { rawresize: (e) => this._mouseResize(e) }
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* resize for 'all' resize attribute
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
private _mouseResize(event: EvOverlayResize) {
|
|
283
|
+
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
|
|
286
|
+
let irc = this.getBoundingRect();
|
|
287
|
+
let st = this.getComputedStyle();
|
|
288
|
+
let ev = event.ui_event;
|
|
289
|
+
|
|
290
|
+
let tm = st.parse('marginTop'),
|
|
291
|
+
lm = st.parse('marginLeft'),
|
|
292
|
+
rm = st.parse('marginRight'),
|
|
293
|
+
bm = st.parse('marginBottom');
|
|
294
|
+
|
|
295
|
+
let ix = 0,
|
|
296
|
+
iy = 0;
|
|
297
|
+
|
|
298
|
+
let mp = getMousePos(ev, true);
|
|
299
|
+
|
|
300
|
+
// horz
|
|
301
|
+
switch (event.sens) {
|
|
302
|
+
case 'topright':
|
|
303
|
+
case 'bottomright':
|
|
304
|
+
case 'right': ix = (irc.right - rm) - mp.x; break;
|
|
305
|
+
|
|
306
|
+
case 'topleft':
|
|
307
|
+
case 'bottomleft':
|
|
308
|
+
case 'left': ix = (irc.left - lm) - mp.x; break;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// vert
|
|
312
|
+
switch (event.sens) {
|
|
313
|
+
case 'bottomleft':
|
|
314
|
+
case 'bottomright':
|
|
315
|
+
case 'bottom': iy = (irc.bottom - bm) - mp.y; break;
|
|
316
|
+
|
|
317
|
+
case 'topleft':
|
|
318
|
+
case 'topright':
|
|
319
|
+
case 'top': iy = (irc.top - tm) - mp.y; break;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// left & top are with margin
|
|
323
|
+
// width & height not
|
|
324
|
+
irc.left -= lm;
|
|
325
|
+
irc.top -= tm;
|
|
326
|
+
|
|
327
|
+
//console.log( 'capture' );
|
|
328
|
+
|
|
329
|
+
let sens = event.sens;
|
|
330
|
+
|
|
331
|
+
Component.setCapture(this, (ne: UIEvent) => {
|
|
332
|
+
|
|
333
|
+
//console.log( ne );
|
|
334
|
+
|
|
335
|
+
let __move = (ex, ey) => {
|
|
336
|
+
|
|
337
|
+
let left = irc.left,
|
|
338
|
+
top = irc.top,
|
|
339
|
+
width = irc.width,
|
|
340
|
+
height = irc.height;
|
|
341
|
+
|
|
342
|
+
let dx, dy;
|
|
343
|
+
let px = ex + ix,
|
|
344
|
+
py = ey + iy;
|
|
345
|
+
|
|
346
|
+
if (px < 0) {
|
|
347
|
+
px = 0;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (py < 0) {
|
|
351
|
+
py = 0;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// horz
|
|
355
|
+
switch (sens) {
|
|
356
|
+
case 'topright':
|
|
357
|
+
case 'bottomright':
|
|
358
|
+
case 'right': width = px - left; break;
|
|
359
|
+
|
|
360
|
+
case 'topleft':
|
|
361
|
+
case 'bottomleft':
|
|
362
|
+
case 'left': dx = left - px; width += dx; left -= dx; break;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// vert
|
|
366
|
+
switch (sens) {
|
|
367
|
+
case 'bottomleft':
|
|
368
|
+
case 'bottomright':
|
|
369
|
+
case 'bottom': height = py - top; break;
|
|
370
|
+
|
|
371
|
+
case 'topleft':
|
|
372
|
+
case 'topright':
|
|
373
|
+
case 'top': dy = top - py; height += dy; top -= dy; break;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
let newsize = new Size(width, height);
|
|
377
|
+
this.setStyle({ left, top, width: newsize.width, height: newsize.height });
|
|
378
|
+
|
|
379
|
+
this.emit('size', EvSize(newsize));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (ne.type == 'mouseup' || ne.type == 'touchend') {
|
|
383
|
+
Component.releaseCapture();
|
|
384
|
+
}
|
|
385
|
+
else if (ne.type == 'mousemove') {
|
|
386
|
+
let me = ne as MouseEvent;
|
|
387
|
+
__move(me.pageX, me.pageY);
|
|
388
|
+
}
|
|
389
|
+
else if (ne.type == 'touchmove') {
|
|
390
|
+
let tev = ne as TouchEvent;
|
|
391
|
+
__move(tev.touches[0].pageX, tev.touches[0].pageY);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* handle tab key
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
function x4handleKeyDown(e: KeyboardEvent) {
|
|
406
|
+
|
|
407
|
+
if (e.key == 'Tab' || e.key == 'Enter') {
|
|
408
|
+
|
|
409
|
+
const target = e.target as HTMLElement;
|
|
410
|
+
if (target.tagName == 'TEXTAREA') {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const el = Component.getElement( target );
|
|
415
|
+
if( el && (el.hasAttribute('wants-tab') || el.hasAttribute('wants-enter')) ) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
let topStack = document.body;
|
|
420
|
+
if (Popup.modal_stack.length) {
|
|
421
|
+
topStack = Popup.modal_stack[Popup.modal_stack.length - 1];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
_nextTab(topStack, e.target as HTMLElement, e.shiftKey);
|
|
425
|
+
e.stopPropagation();
|
|
426
|
+
e.preventDefault();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* cycle through tabs
|
|
432
|
+
*/
|
|
433
|
+
|
|
434
|
+
function _nextTab(root: HTMLElement, el: HTMLElement, prev: boolean) {
|
|
435
|
+
|
|
436
|
+
// first check if the focus is one of our child (disabled...)
|
|
437
|
+
let focusEl = document.activeElement;
|
|
438
|
+
if (!root.contains(focusEl)) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
let comp = Component.getElement(el);
|
|
443
|
+
|
|
444
|
+
// get a list of elements with tab index, this way we should abble to
|
|
445
|
+
// cycle on them (not on browser address nor under dialog elements)
|
|
446
|
+
let tabbable = root.querySelectorAll('[tabindex]');
|
|
447
|
+
let tab_indexes: HTMLElement[] = [].map.call(tabbable, (e) => { return e; });
|
|
448
|
+
|
|
449
|
+
// remove hidden elements
|
|
450
|
+
tab_indexes = tab_indexes.filter((el) => el.offsetParent !== null);
|
|
451
|
+
if (!tab_indexes.length) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
let ct = tab_indexes.indexOf(el);
|
|
456
|
+
|
|
457
|
+
if (ct < 0) {
|
|
458
|
+
ct = 0;
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
if (prev) {
|
|
462
|
+
if (ct > 0) {
|
|
463
|
+
ct--;
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
ct = tab_indexes.length - 1;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
if (ct < tab_indexes.length - 1) {
|
|
471
|
+
ct++;
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
ct = 0;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
tab_indexes[ct].focus();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function installKBHandler( ) {
|
|
483
|
+
// set on body to be called after document (where all component domevent go)
|
|
484
|
+
document.body.addEventListener('keydown', x4handleKeyDown, true);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// too early ?
|
|
488
|
+
document.body ? installKBHandler( ) : window.addEventListener( 'load', installKBHandler );
|