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/dialog.ts
ADDED
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file dialog.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 { Popup, PopupProps, PopupEventMap, EvMove } from './popup'
|
|
27
|
+
import { Icon, IconID } from './icon'
|
|
28
|
+
import { HLayout } from './layout'
|
|
29
|
+
import { Label } from './label'
|
|
30
|
+
import { Form, FormButtons } from './form'
|
|
31
|
+
import { Component, ComponentContent, EvSize, flyWrap } from './component'
|
|
32
|
+
import { BasicEvent, EventCallback } from './x4_events'
|
|
33
|
+
import { Rect, getMousePos, isFunction, isTouchDevice, isString, Size } from './tools'
|
|
34
|
+
|
|
35
|
+
interface Geometry {
|
|
36
|
+
left: number;
|
|
37
|
+
top: number;
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
minimized: boolean;
|
|
41
|
+
maximized: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ============================================================================
|
|
45
|
+
// [DIALOG]
|
|
46
|
+
// ============================================================================
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
export interface EvClose extends BasicEvent {
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface EvBtnClick extends BasicEvent {
|
|
53
|
+
button: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function EvBtnClick(button: string) {
|
|
57
|
+
return BasicEvent<EvBtnClick>({ button });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
export interface DialogBoxEventMap extends PopupEventMap {
|
|
62
|
+
close: EvClose;
|
|
63
|
+
btnClick: EvBtnClick;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type InitFormCallback = () => Form;
|
|
67
|
+
|
|
68
|
+
export interface DialogProps<E extends DialogBoxEventMap = DialogBoxEventMap> extends PopupProps<E> {
|
|
69
|
+
title?: string;
|
|
70
|
+
icon?: IconID;
|
|
71
|
+
buttons?: FormButtons;
|
|
72
|
+
|
|
73
|
+
btnClick?: EventCallback<EvBtnClick>;
|
|
74
|
+
|
|
75
|
+
closable?: boolean;
|
|
76
|
+
movable?: boolean;
|
|
77
|
+
maximized?: boolean;
|
|
78
|
+
maximizable?: boolean;
|
|
79
|
+
minimizable?: boolean;
|
|
80
|
+
autoClose?: boolean; // if true, close the dialog when a button is clicked
|
|
81
|
+
|
|
82
|
+
width?: number; // when you specify a width here, this is the minimal FORM content width
|
|
83
|
+
height?: number; // when you specify a width here, this is the minimal FORM content heigt
|
|
84
|
+
dlgWidth?: number; // this is the prefered initial dialog width in percent of screen
|
|
85
|
+
dlgHeight?: number; // this is the prefered initial dialog height in percent of screen
|
|
86
|
+
|
|
87
|
+
form?: Form | InitFormCallback;
|
|
88
|
+
disableSuggestions?: boolean;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Standard dialog class
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
export class Dialog<P extends DialogProps = DialogProps, E extends DialogBoxEventMap = DialogBoxEventMap> extends Popup<P, E>
|
|
96
|
+
{
|
|
97
|
+
protected m_icon: IconID;
|
|
98
|
+
protected m_title: string;
|
|
99
|
+
protected m_form: Form;
|
|
100
|
+
protected m_buttons: FormButtons;
|
|
101
|
+
protected m_closable: boolean;
|
|
102
|
+
protected m_movable: boolean;
|
|
103
|
+
protected m_maximized: boolean;
|
|
104
|
+
protected m_minimized: boolean;
|
|
105
|
+
protected m_maximizable: boolean;
|
|
106
|
+
protected m_minimizable: boolean;
|
|
107
|
+
|
|
108
|
+
protected m_minFormSize: Size;
|
|
109
|
+
|
|
110
|
+
protected m_rc_max: Rect;
|
|
111
|
+
protected m_rc_min: Rect;
|
|
112
|
+
|
|
113
|
+
protected m_el_title: Component;
|
|
114
|
+
protected m_last_down: number;
|
|
115
|
+
protected m_auto_close: boolean;
|
|
116
|
+
|
|
117
|
+
protected m_ui_title: Label;
|
|
118
|
+
protected m_form_cb: InitFormCallback;
|
|
119
|
+
|
|
120
|
+
constructor(props: P) {
|
|
121
|
+
|
|
122
|
+
let content = props.content;
|
|
123
|
+
props.content = null;
|
|
124
|
+
|
|
125
|
+
let width = props.width;
|
|
126
|
+
let height = props.height;
|
|
127
|
+
|
|
128
|
+
props.width = undefined;
|
|
129
|
+
props.height = undefined;
|
|
130
|
+
|
|
131
|
+
super(props);
|
|
132
|
+
|
|
133
|
+
this.m_minFormSize = { width, height };
|
|
134
|
+
|
|
135
|
+
this.enableMask(true);
|
|
136
|
+
|
|
137
|
+
if (props.form) {
|
|
138
|
+
if (!isFunction(props.form)) {
|
|
139
|
+
this.m_form = props.form;
|
|
140
|
+
this.m_form.on('btnClick', (e) => this._handleClick(e));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this.m_form_cb = props.form;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.m_form = new Form({
|
|
148
|
+
content,
|
|
149
|
+
buttons: props.buttons,
|
|
150
|
+
disableSuggestions: props.disableSuggestions,
|
|
151
|
+
btnClick: (e) => this._handleClick(e)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
this.m_movable = props.movable;
|
|
156
|
+
this.m_auto_close = props.autoClose ?? true;
|
|
157
|
+
|
|
158
|
+
this.m_icon = props.icon;
|
|
159
|
+
this.m_title = props.title;
|
|
160
|
+
this.m_buttons = props.buttons ?? null;
|
|
161
|
+
this.m_closable = props.closable ?? false;
|
|
162
|
+
this.m_last_down = 0;
|
|
163
|
+
|
|
164
|
+
this.on('size', (ev: EvSize) => {
|
|
165
|
+
this.addClass('@resized');
|
|
166
|
+
this.m_form.setStyleValue('width', null);
|
|
167
|
+
this.m_form.setStyleValue('height', null);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
this.m_maximized = false;
|
|
171
|
+
this.m_minimized = false;
|
|
172
|
+
this.m_maximizable = false;
|
|
173
|
+
this.m_minimizable = false;
|
|
174
|
+
|
|
175
|
+
if (props.maximizable !== undefined) {
|
|
176
|
+
this.m_maximizable = props.maximizable;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (props.minimizable !== undefined) {
|
|
180
|
+
this.m_minimizable = props.minimizable;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (props.maximized == true) {
|
|
184
|
+
this.m_maximizable = true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if( props.btnClick ) {
|
|
188
|
+
this.on( 'btnClick', props.btnClick );
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
componentCreated() // override
|
|
197
|
+
{
|
|
198
|
+
super.componentCreated();
|
|
199
|
+
|
|
200
|
+
if( this.m_minFormSize.width ) {
|
|
201
|
+
this.m_form.setStyle( {
|
|
202
|
+
minWidth: this.m_minFormSize.width,
|
|
203
|
+
width: this.m_minFormSize.width
|
|
204
|
+
} );
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if( this.m_minFormSize.height ) {
|
|
208
|
+
this.m_form.setStyle( {
|
|
209
|
+
minHeight: this.m_minFormSize.height,
|
|
210
|
+
height: this.m_minFormSize.height
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const rc = this.getBoundingRect( );
|
|
215
|
+
this.setStyleValue( 'min-width', rc.width );
|
|
216
|
+
this.setStyleValue( 'min-height', rc.height );
|
|
217
|
+
|
|
218
|
+
this.setStyleValue( 'width', rc.width );
|
|
219
|
+
this.setStyleValue( 'height', rc.height );
|
|
220
|
+
|
|
221
|
+
if( this.m_props.dlgWidth ) {
|
|
222
|
+
this.setStyleValue( 'width', this.m_props.dlgWidth+'%' );
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if( this.m_props.dlgHeight ) {
|
|
226
|
+
this.setStyleValue( 'height', this.m_props.dlgHeight+'%' );
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
this.addClass('@resized');
|
|
230
|
+
|
|
231
|
+
if (this.m_props.maximized) {
|
|
232
|
+
this._maximize();
|
|
233
|
+
this.emit('size', EvSize(null));
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
this.centerOnScreen( );
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
*
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
private _handleClick(ev: EvBtnClick) {
|
|
245
|
+
this.emit('btnClick', ev);
|
|
246
|
+
if (!ev.defaultPrevented) {
|
|
247
|
+
this.close();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* restore the geometry
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
setGeometry(geom: Geometry) {
|
|
256
|
+
|
|
257
|
+
if (geom.minimized && this.m_minimizable) {
|
|
258
|
+
this._minimize(false);
|
|
259
|
+
this.m_rc_min = new Rect(geom.left, geom.top, geom.width, geom.height);
|
|
260
|
+
this.displayAt(geom.left, geom.top, 'top-left');
|
|
261
|
+
}
|
|
262
|
+
else if (geom.maximized && this.m_maximizable) {
|
|
263
|
+
this._maximize(false);
|
|
264
|
+
this.m_rc_max = new Rect(geom.left, geom.top, geom.width, geom.height);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
this.setSize(geom.width, geom.height);
|
|
268
|
+
this.displayAt(geom.left, geom.top, 'top-left');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* return the geometry (usefull to save state)
|
|
274
|
+
*/
|
|
275
|
+
|
|
276
|
+
getGeometry(): Geometry {
|
|
277
|
+
|
|
278
|
+
if (this.m_minimized) {
|
|
279
|
+
return {
|
|
280
|
+
left: this.m_rc_min.left,
|
|
281
|
+
top: this.m_rc_min.top,
|
|
282
|
+
width: this.m_rc_min.width,
|
|
283
|
+
height: this.m_rc_min.height,
|
|
284
|
+
minimized: true,
|
|
285
|
+
maximized: false
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else if (this.m_maximized) {
|
|
289
|
+
return {
|
|
290
|
+
left: this.m_rc_max.left,
|
|
291
|
+
top: this.m_rc_max.top,
|
|
292
|
+
width: this.m_rc_max.width,
|
|
293
|
+
height: this.m_rc_max.height,
|
|
294
|
+
minimized: false,
|
|
295
|
+
maximized: true
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
let rc = this.getBoundingRect();
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
left: rc.left,
|
|
303
|
+
top: rc.top,
|
|
304
|
+
width: rc.width,
|
|
305
|
+
height: rc.height,
|
|
306
|
+
minimized: false,
|
|
307
|
+
maximized: false
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* resize the dialog
|
|
313
|
+
* @param width
|
|
314
|
+
* @param height
|
|
315
|
+
*/
|
|
316
|
+
setSize(width: number, height: number) {
|
|
317
|
+
this.setStyle({ width, height });
|
|
318
|
+
this.emit('size', EvSize({ width, height }));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** @ignore */
|
|
322
|
+
render() {
|
|
323
|
+
|
|
324
|
+
if (this.m_form_cb) {
|
|
325
|
+
this.m_form = this.m_form_cb();
|
|
326
|
+
this.m_form.on('btnClick', (e) => this._handleClick(e));
|
|
327
|
+
this.m_form_cb = null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
let hasTitle = this.m_icon !== undefined || this.m_closable || this.m_title !== undefined || this.m_movable;
|
|
331
|
+
this.m_el_title = null;
|
|
332
|
+
|
|
333
|
+
if (hasTitle) {
|
|
334
|
+
this.m_el_title = new HLayout({
|
|
335
|
+
cls: 'title',
|
|
336
|
+
content: [
|
|
337
|
+
this.m_icon ? new Icon({ icon: this.m_icon }) : null,
|
|
338
|
+
this.m_ui_title = new Label({ flex: 1, text: this.m_title }),
|
|
339
|
+
this.m_minimizable ? new Icon({ cls: 'min-btn', icon: 'cls(far fa-window-minimize)', dom_events: { click: () => this._toggleMin() } }) : null,
|
|
340
|
+
this.m_maximizable ? new Icon({ cls: 'max-btn', icon: 'cls(far fa-window-maximize)', dom_events: { click: () => this._toggleMax() } }) : null,
|
|
341
|
+
this.m_closable ? new Icon({ icon: 'cls(far fa-rectangle-times)', dom_events: { click: () => this.close() } }) : null,
|
|
342
|
+
]
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
if (this.m_movable) {
|
|
346
|
+
if( isTouchDevice() ) {
|
|
347
|
+
this.m_el_title.setDomEvent('touchstart', (e) => this._mouseDown(e));
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
this.m_el_title.setDomEvent('mousedown', (e) => this._mouseDown(e));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
super.setContent([
|
|
356
|
+
this.m_el_title,
|
|
357
|
+
this.m_form
|
|
358
|
+
]);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* change the dialog content
|
|
363
|
+
* @param els
|
|
364
|
+
* @param refreshAll
|
|
365
|
+
*/
|
|
366
|
+
|
|
367
|
+
setContent( els: ComponentContent, refreshAll = true ) {
|
|
368
|
+
this.m_form.setContent( els, refreshAll );
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* change the dialog buttons
|
|
373
|
+
* @param buttons
|
|
374
|
+
*/
|
|
375
|
+
|
|
376
|
+
setButtons( buttons: FormButtons ) {
|
|
377
|
+
this.m_form.setButtons( buttons );
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* return the dialog form
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
public get form(): Form {
|
|
385
|
+
return this.m_form;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* close the dialog
|
|
390
|
+
*/
|
|
391
|
+
|
|
392
|
+
public close() {
|
|
393
|
+
this.emit( 'close', {} );
|
|
394
|
+
super.close();
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
*
|
|
399
|
+
*/
|
|
400
|
+
private _toggleMax() {
|
|
401
|
+
if (!this.m_maximizable) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (this.m_maximized) {
|
|
406
|
+
this.removeClass('maximized');
|
|
407
|
+
this.setStyle({
|
|
408
|
+
left: this.m_rc_max.left,
|
|
409
|
+
top: this.m_rc_max.top,
|
|
410
|
+
width: this.m_rc_max.width,
|
|
411
|
+
height: this.m_rc_max.height,
|
|
412
|
+
});
|
|
413
|
+
this.m_maximized = false;
|
|
414
|
+
this.emit( 'size', EvSize(null, 'restore'));
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
this._maximize();
|
|
418
|
+
this.emit( 'size', EvSize(null, 'maximize'));
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
*
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
private _toggleMin() {
|
|
427
|
+
if (!this.m_minimizable) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (this.m_minimized) {
|
|
432
|
+
this.removeClass('minimized');
|
|
433
|
+
this.setStyle({
|
|
434
|
+
//left: this.m_rc_min.left,
|
|
435
|
+
//top: this.m_rc_min.top,
|
|
436
|
+
width: this.m_rc_min.width,
|
|
437
|
+
height: this.m_rc_min.height,
|
|
438
|
+
});
|
|
439
|
+
this.m_minimized = false;
|
|
440
|
+
this.emit('size', EvSize(null, 'restore'));
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
this._minimize();
|
|
444
|
+
this.emit('size', EvSize(null, 'minimize'));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
*
|
|
450
|
+
*/
|
|
451
|
+
|
|
452
|
+
private _mouseDown(event: UIEvent) {
|
|
453
|
+
|
|
454
|
+
let { x, y } = getMousePos(event, true);
|
|
455
|
+
|
|
456
|
+
let wrc = flyWrap(document.body).getBoundingRect();
|
|
457
|
+
let rc = this.getBoundingRect(true);
|
|
458
|
+
let trc = this.m_el_title.getBoundingRect();
|
|
459
|
+
|
|
460
|
+
let dx = x - rc.left,
|
|
461
|
+
dy = y - rc.top;
|
|
462
|
+
|
|
463
|
+
let cstyle = this.getComputedStyle();
|
|
464
|
+
|
|
465
|
+
let topw = cstyle.parse('marginTop') + cstyle.parse('paddingTop') + cstyle.parse('borderTopWidth');
|
|
466
|
+
let botw = cstyle.parse('marginBottom') + cstyle.parse('paddingBottom') + cstyle.parse('borderBottomWidth');
|
|
467
|
+
let lftw = cstyle.parse('marginLeft') + cstyle.parse('paddingLeft') + cstyle.parse('borderLeftWidth');
|
|
468
|
+
let rgtw = cstyle.parse('marginRight') + cstyle.parse('paddingRight') + cstyle.parse('borderRightWidth');
|
|
469
|
+
|
|
470
|
+
wrc.top += topw - trc.height;
|
|
471
|
+
wrc.height -= topw + botw - trc.height;
|
|
472
|
+
|
|
473
|
+
wrc.left += lftw;
|
|
474
|
+
wrc.width -= lftw + rgtw;
|
|
475
|
+
|
|
476
|
+
// custom handling double click
|
|
477
|
+
const now = Date.now();
|
|
478
|
+
const delta = now - this.m_last_down;
|
|
479
|
+
|
|
480
|
+
if ( this.m_maximizable && delta < 700) {
|
|
481
|
+
this._toggleMax();
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
this.m_last_down = now;
|
|
486
|
+
if (this.m_maximized) {
|
|
487
|
+
// cannot move in max state
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
let __move = (ex, ey) => {
|
|
492
|
+
let x = ex - dx,
|
|
493
|
+
y = ey - dy;
|
|
494
|
+
|
|
495
|
+
if (x + rc.width < wrc.left) {
|
|
496
|
+
x = wrc.left - rc.width;
|
|
497
|
+
}
|
|
498
|
+
else if (x > wrc.right) {
|
|
499
|
+
x = wrc.right;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (y < wrc.top) { // title grip is on top
|
|
503
|
+
y = wrc.top;
|
|
504
|
+
}
|
|
505
|
+
else if (y > wrc.bottom) {
|
|
506
|
+
y = wrc.bottom;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
this.setStyle({
|
|
510
|
+
left: x,
|
|
511
|
+
top: y
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
Component.setCapture(this, (ev) => {
|
|
516
|
+
|
|
517
|
+
if (ev.type == 'mousemove') {
|
|
518
|
+
let mev = ev as MouseEvent;
|
|
519
|
+
__move(mev.clientX, mev.clientY);
|
|
520
|
+
}
|
|
521
|
+
else if (ev.type == 'touchmove') {
|
|
522
|
+
let tev = ev as TouchEvent;
|
|
523
|
+
|
|
524
|
+
if (tev.touches.length == 1) {
|
|
525
|
+
__move(tev.touches[0].clientX, tev.touches[0].clientY);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else if (ev.type == 'mouseup' || ev.type == 'touchend') {
|
|
529
|
+
Component.releaseCapture();
|
|
530
|
+
this.emit( 'move', EvMove(null));
|
|
531
|
+
}
|
|
532
|
+
else if (ev.type == 'mousedown' || ev.type == 'touchstart') {
|
|
533
|
+
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* maximize the dialog
|
|
540
|
+
*/
|
|
541
|
+
|
|
542
|
+
public maximize() {
|
|
543
|
+
if (!this.m_maximizable || this.m_maximized) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
this._maximize();
|
|
548
|
+
this.emit('size', EvSize(null));
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
*
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
private _maximize(saveRect = true) {
|
|
556
|
+
|
|
557
|
+
if (saveRect) {
|
|
558
|
+
this.m_rc_max = this.getBoundingRect(false);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
this.addClass('maximized');
|
|
562
|
+
this.m_maximized = true;
|
|
563
|
+
|
|
564
|
+
this.setStyle({
|
|
565
|
+
left: undefined,
|
|
566
|
+
top: undefined,
|
|
567
|
+
width: undefined,
|
|
568
|
+
height: undefined,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* minimize the dialog
|
|
574
|
+
*/
|
|
575
|
+
|
|
576
|
+
public minimize() {
|
|
577
|
+
if (!this.m_minimizable || this.m_minimized) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
this._minimize();
|
|
582
|
+
this.emit('size', EvSize(null));
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
*
|
|
587
|
+
*/
|
|
588
|
+
|
|
589
|
+
private _minimize(saveRect = true) {
|
|
590
|
+
|
|
591
|
+
if (saveRect) {
|
|
592
|
+
this.m_rc_min = this.getBoundingRect(false);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
this.addClass('minimized');
|
|
596
|
+
this.m_minimized = true;
|
|
597
|
+
|
|
598
|
+
this.setStyle({
|
|
599
|
+
//left: undefined,
|
|
600
|
+
//top: undefined,
|
|
601
|
+
width: undefined,
|
|
602
|
+
height: undefined,
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* change the dialog title
|
|
610
|
+
*/
|
|
611
|
+
|
|
612
|
+
set title(title: string) {
|
|
613
|
+
this.m_title = title;
|
|
614
|
+
if (this.m_ui_title) {
|
|
615
|
+
this.m_ui_title.text = title;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
itemWithName<T extends Component>( name: string ): T {
|
|
620
|
+
let result = <HTMLElement>this.dom.querySelector( `[name="${name}"]` );
|
|
621
|
+
return result ? Component.getElement<T>(result) : null;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
getValues( ) {
|
|
625
|
+
return this.m_form.getValues( );
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
validate( ) {
|
|
629
|
+
return this.m_form.validate( );
|
|
630
|
+
}
|
|
631
|
+
}
|