x4js 2.0.35 → 2.1.0-manual
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/README.md +21 -21
- package/package.json +39 -26
- package/src/components/base.scss +25 -89
- package/src/components/boxes/boxes.module.scss +54 -54
- package/src/components/boxes/boxes.ts +513 -513
- package/src/components/breadcrumb/breadcrumb.scss +56 -56
- package/src/components/breadcrumb/breadcrumb.ts +93 -93
- package/src/components/btngroup/btngroup.module.scss +40 -40
- package/src/components/btngroup/btngroup.ts +152 -152
- package/src/components/button/button.module.scss +172 -172
- package/src/components/button/button.ts +232 -232
- package/src/components/calendar/calendar.module.scss +162 -162
- package/src/components/calendar/calendar.ts +326 -326
- package/src/components/canvas/canvas.module.scss +24 -24
- package/src/components/canvas/canvas.ts +195 -195
- package/src/components/canvas/canvas_ex.ts +275 -275
- package/src/components/checkbox/check.svg +3 -3
- package/src/components/checkbox/checkbox.module.scss +141 -141
- package/src/components/checkbox/checkbox.ts +139 -139
- package/src/components/colorinput/colorinput.module.scss +64 -64
- package/src/components/colorinput/colorinput.ts +90 -90
- package/src/components/colorpicker/colorpicker.module.scss +132 -132
- package/src/components/colorpicker/colorpicker.ts +481 -481
- package/src/components/combobox/combobox.module.scss +145 -145
- package/src/components/combobox/combobox.ts +282 -282
- package/src/components/combobox/updown.svg +3 -3
- package/src/components/components.ts +45 -44
- package/src/components/dialog/dialog.module.scss +103 -105
- package/src/components/dialog/dialog.ts +233 -233
- package/src/components/filedrop/filedrop.module.scss +69 -69
- package/src/components/filedrop/filedrop.ts +130 -130
- package/src/components/form/form.module.scss +38 -38
- package/src/components/form/form.ts +172 -172
- package/src/components/gridview/gridview.module.scss +323 -337
- package/src/components/gridview/gridview.ts +1276 -1316
- package/src/components/header/header.module.scss +40 -40
- package/src/components/header/header.ts +141 -141
- package/src/components/icon/icon.module.scss +32 -32
- package/src/components/icon/icon.ts +165 -165
- package/src/components/image/image.module.scss +27 -27
- package/src/components/image/image.ts +168 -168
- package/src/components/input/input.module.scss +74 -74
- package/src/components/input/input.ts +537 -537
- package/src/components/keyboard/keyboard.module.scss +136 -136
- package/src/components/keyboard/keyboard.ts +549 -549
- package/src/components/label/label.module.scss +90 -91
- package/src/components/label/label.ts +101 -101
- package/src/components/link/link.module.scss +44 -44
- package/src/components/link/link.ts +87 -87
- package/src/components/listbox/listbox.module.scss +179 -179
- package/src/components/listbox/listbox.ts +596 -596
- package/src/components/menu/menu.module.scss +128 -128
- package/src/components/menu/menu.ts +174 -174
- package/src/components/messages/messages.module.scss +92 -146
- package/src/components/messages/messages.ts +237 -303
- package/src/components/normalize.scss +391 -391
- package/src/components/notification/notification.module.scss +83 -83
- package/src/components/notification/notification.ts +107 -107
- package/src/components/panel/panel.module.scss +66 -71
- package/src/components/panel/panel.ts +57 -57
- package/src/components/popup/popup.module.scss +51 -51
- package/src/components/popup/popup.ts +457 -457
- package/src/components/progress/progress.module.scss +56 -56
- package/src/components/progress/progress.ts +43 -43
- package/src/components/propgrid/progrid.module.scss +111 -111
- package/src/components/propgrid/propgrid.ts +300 -300
- package/src/components/propgrid/updown.svg +3 -3
- package/src/components/radio/radio.module.scss +163 -163
- package/src/components/radio/radio.svg +3 -3
- package/src/components/radio/radio.ts +141 -141
- package/src/components/rating/rating.module.scss +22 -22
- package/src/components/rating/rating.ts +131 -131
- package/src/components/select/select.module.scss +8 -8
- package/src/components/select/select.ts +134 -134
- package/src/components/shared.scss +141 -71
- package/src/components/sizers/sizer.module.scss +90 -112
- package/src/components/sizers/sizer.ts +131 -155
- package/src/components/slider/slider.module.scss +117 -117
- package/src/components/slider/slider.ts +197 -197
- package/src/components/spreadsheet/spreadsheet.module.scss +307 -307
- package/src/components/spreadsheet/spreadsheet.ts +1223 -1223
- package/src/components/switch/switch.module.scss +126 -126
- package/src/components/switch/switch.ts +61 -61
- package/src/components/tabs/tabs.module.scss +46 -67
- package/src/components/tabs/tabs.ts +229 -234
- package/src/components/textarea/textarea.module.scss +63 -63
- package/src/components/textarea/textarea.ts +131 -131
- package/src/components/textedit/textedit.module.scss +115 -115
- package/src/components/textedit/textedit.ts +122 -122
- package/src/components/themes.scss +90 -90
- package/src/components/tickline/tickline.module.scss +25 -25
- package/src/components/tickline/tickline.ts +81 -81
- package/src/components/tooltips/tooltips.scss +71 -71
- package/src/components/tooltips/tooltips.ts +120 -120
- package/src/components/treeview/treeview.module.scss +192 -192
- package/src/components/treeview/treeview.ts +484 -484
- package/src/components/viewport/viewport.module.scss +31 -31
- package/src/components/viewport/viewport.ts +41 -41
- package/src/core/component.ts +1299 -1299
- package/src/core/core_application.ts +361 -361
- package/src/core/core_colors.ts +512 -512
- package/src/core/core_data.ts +1297 -1310
- package/src/core/core_dom.ts +481 -481
- package/src/core/core_dragdrop.ts +225 -225
- package/src/core/core_element.ts +221 -221
- package/src/core/core_events.ts +214 -214
- package/src/core/core_i18n.ts +395 -395
- package/src/core/core_pdf.ts +454 -454
- package/src/core/core_react.ts +78 -78
- package/src/core/core_router.ts +296 -296
- package/src/core/core_state.ts +62 -62
- package/src/core/core_styles.ts +213 -213
- package/src/core/core_svg.ts +1042 -1042
- package/src/core/core_tools.ts +996 -996
- package/src/types/scss.d.ts +4 -4
- package/src/types/x4react.d.ts +8 -8
- package/src/x4.scss +19 -19
- package/src/x4.ts +36 -36
- package/src/x4tsx.d.ts +26 -26
- package/.vscode/launch.json +0 -14
- package/.vscode/settings.json +0 -2
- package/demo/assets/house-light.svg +0 -1
- package/demo/assets/radio.svg +0 -4
- package/demo/index.html +0 -12
- package/demo/main.scss +0 -23
- package/demo/main.ts +0 -324
- package/demo/package.json +0 -26
- package/demo/scss.d.ts +0 -4
- package/demo/svg.d.ts +0 -1
- package/demo/tsconfig.json +0 -14
- package/src/components/gridview/folder-open.svg +0 -1
- package/src/components/messages/spinner.svg +0 -1
- package/src/x4.d.ts +0 -10
- package/tsconfig.json +0 -11
|
@@ -1,457 +1,457 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / \____ _|
|
|
6
|
-
* /__/\__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file popup.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Use of this source code is governed by an MIT-style license
|
|
14
|
-
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
-
**/
|
|
16
|
-
|
|
17
|
-
import { Component, ComponentEvent, ComponentEvents, ComponentProps, componentFromDOM, makeUniqueComponentId } from "../../core/component"
|
|
18
|
-
|
|
19
|
-
import { CSizer } from '../sizers/sizer';
|
|
20
|
-
import { Rect, Point, class_ns, asap } from '../../core/core_tools';
|
|
21
|
-
import { Box } from '../boxes/boxes'
|
|
22
|
-
|
|
23
|
-
import "./popup.module.scss"
|
|
24
|
-
import { getGlobalZoom, getScrollbarSize } from '../../core/core_tools.js';
|
|
25
|
-
|
|
26
|
-
export interface PopupEvents extends ComponentEvents {
|
|
27
|
-
closed: ComponentEvent;
|
|
28
|
-
opened: ComponentEvent;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface PopupProps extends ComponentProps {
|
|
32
|
-
autoClose?: boolean | string;
|
|
33
|
-
sizable?: boolean;
|
|
34
|
-
movable?: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let autoclose_list: Popup[] = [];
|
|
38
|
-
let popup_list: Popup[] = [];
|
|
39
|
-
|
|
40
|
-
let modal_stack: Popup[] = [];
|
|
41
|
-
let modal_mask: Component;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function getRoot( ) {
|
|
45
|
-
return document.body;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
@class_ns( "x4" )
|
|
53
|
-
export class Popup<P extends PopupProps = PopupProps, E extends PopupEvents = PopupEvents> extends Box<P,E> {
|
|
54
|
-
|
|
55
|
-
private _isshown = false;
|
|
56
|
-
protected _ismodal = false;
|
|
57
|
-
|
|
58
|
-
constructor( props: P ) {
|
|
59
|
-
super( props );
|
|
60
|
-
|
|
61
|
-
if( this.props.sizable ) {
|
|
62
|
-
this._createSizers( );
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// wait for element to create it's childs
|
|
66
|
-
asap( ( ) => {
|
|
67
|
-
if( this.props.movable===true || (this.props.sizable && this.props.movable===undefined) ) {
|
|
68
|
-
const movers = this.queryAll( ".caption-element" );
|
|
69
|
-
movers.forEach( m => new CMover(m,this) );
|
|
70
|
-
|
|
71
|
-
if( this.hasClass("popup-caption") ) {
|
|
72
|
-
new CMover(this,this);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
} );
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
displayNear( rc: Rect, dst = "top left", src = "top left", offset = {x:0,y:0} ) {
|
|
83
|
-
|
|
84
|
-
this.setStyle( { left: "0px", top: "0px" } ); // avoid scrollbar
|
|
85
|
-
this._do_show( ); // to compute size
|
|
86
|
-
|
|
87
|
-
let rm = this.getBoundingRect();
|
|
88
|
-
|
|
89
|
-
let xref = rc.left;
|
|
90
|
-
let yref = rc.top;
|
|
91
|
-
|
|
92
|
-
if( src.indexOf('right')>=0 ) {
|
|
93
|
-
xref = (rc.left+rc.width);
|
|
94
|
-
}
|
|
95
|
-
else if( src.indexOf('center')>=0 ) {
|
|
96
|
-
xref = rc.left + rc.width/2;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if( src.indexOf('bottom')>=0 ) {
|
|
100
|
-
yref = rc.bottom;
|
|
101
|
-
}
|
|
102
|
-
else if( src.indexOf('middle')>=0 ) {
|
|
103
|
-
yref = rc.top + rc.height/2;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (dst.indexOf('right') >= 0) {
|
|
107
|
-
xref -= rm.width;
|
|
108
|
-
}
|
|
109
|
-
else if( dst.indexOf('center')>=0 ) {
|
|
110
|
-
xref -= rm.width/2;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (dst.indexOf('bottom') >= 0) {
|
|
114
|
-
yref -= rm.height;
|
|
115
|
-
}
|
|
116
|
-
else if( dst.indexOf('middle')>=0 ) {
|
|
117
|
-
yref -= rm.height/2;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (offset) {
|
|
121
|
-
xref += offset.x;
|
|
122
|
-
yref += offset.y;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// our parent is body, so take care of the scroll position
|
|
126
|
-
xref += document.scrollingElement.scrollLeft;
|
|
127
|
-
yref += document.scrollingElement.scrollTop;
|
|
128
|
-
|
|
129
|
-
this.displayAt( xref, yref );
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* s
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
displayCenter( center = true ) {
|
|
137
|
-
//this.displayNear( new Rect( window.innerWidth/2, window.innerHeight/2, 0, 0 ), "center middle" );
|
|
138
|
-
this.setClass( 'center', center );
|
|
139
|
-
this._do_show( ); // to compute size
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
*
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
displayAt( x: number, y: number ) {
|
|
147
|
-
const zm = getGlobalZoom( );
|
|
148
|
-
|
|
149
|
-
//TODO: check is already visible
|
|
150
|
-
this.setStyle( {
|
|
151
|
-
left: (x/zm)+"px",
|
|
152
|
-
top: (y/zm)+"px",
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
this._do_show( ); // to compute size
|
|
156
|
-
|
|
157
|
-
const rc = this.getBoundingRect( ).scale( 1/zm );
|
|
158
|
-
const sbw = getScrollbarSize( );
|
|
159
|
-
|
|
160
|
-
const screen_width = window.innerWidth - sbw;
|
|
161
|
-
if( rc.right>screen_width ) {
|
|
162
|
-
this.setStyleValue( "left", screen_width-rc.width );
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const screen_height = window.innerHeight - sbw;
|
|
166
|
-
if( rc.bottom>screen_height ) {
|
|
167
|
-
this.setStyleValue( "top", screen_height-rc.height );
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
isOpen( ) {
|
|
172
|
-
return this._isshown;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
protected _do_hide( ) {
|
|
176
|
-
|
|
177
|
-
if( !this._isshown ) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
this.__hide( );
|
|
182
|
-
this.__remove( );
|
|
183
|
-
|
|
184
|
-
if( this._ismodal ) {
|
|
185
|
-
// modal1.show()
|
|
186
|
-
// modal2.show()
|
|
187
|
-
// modal1.hide()
|
|
188
|
-
if( modal_stack[modal_stack.length-1]!=this ) {
|
|
189
|
-
const idx = modal_stack.findIndex( x => x===this );
|
|
190
|
-
if( idx>=0 ) {
|
|
191
|
-
modal_stack.splice( idx, 1 );
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
modal_stack.pop( );
|
|
196
|
-
this._hideModalMask( );
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// remove from popup list
|
|
201
|
-
const idx = popup_list.indexOf( this );
|
|
202
|
-
console.assert( idx>=0 );
|
|
203
|
-
popup_list.splice( idx, 1 );
|
|
204
|
-
|
|
205
|
-
// remove from auto close list
|
|
206
|
-
if( this.props.autoClose ) {
|
|
207
|
-
const idx = autoclose_list.indexOf( this );
|
|
208
|
-
if( idx>=0 ) {
|
|
209
|
-
autoclose_list.splice( idx, 1 );
|
|
210
|
-
if( autoclose_list.length==0 ) {
|
|
211
|
-
document.removeEventListener( "pointerdown", this._dismiss );
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
this._isshown = false;
|
|
217
|
-
this.fire( "closed", {} );
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
*
|
|
222
|
-
*/
|
|
223
|
-
|
|
224
|
-
protected _do_show( ) {
|
|
225
|
-
if( this._isshown ) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
this._isshown = true;
|
|
230
|
-
this.__append( );
|
|
231
|
-
|
|
232
|
-
if( this._ismodal ) {
|
|
233
|
-
modal_stack.push( this );
|
|
234
|
-
this._showModalMask( );
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
this.__show( );
|
|
238
|
-
|
|
239
|
-
if( this.props.autoClose ) {
|
|
240
|
-
if( autoclose_list.length==0 ) {
|
|
241
|
-
document.addEventListener( "pointerdown", this._dismiss );
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
autoclose_list.push( this );
|
|
245
|
-
this.setData( "close", this.props.autoClose===true ? makeUniqueComponentId() : this.props.autoClose );
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
popup_list.push( this );
|
|
249
|
-
|
|
250
|
-
this.fire( "opened", {} );
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
*
|
|
255
|
-
*/
|
|
256
|
-
|
|
257
|
-
protected __show( ) {
|
|
258
|
-
super.show( true );
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
protected __hide( ) {
|
|
262
|
-
super.show( false );
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
protected __append( ) {
|
|
266
|
-
const root = getRoot( );
|
|
267
|
-
root.appendChild( this.dom );
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
protected __remove( ) {
|
|
271
|
-
const root = getRoot( );
|
|
272
|
-
root.removeChild( this.dom );
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
*
|
|
277
|
-
*/
|
|
278
|
-
|
|
279
|
-
override show( show = true ) : this {
|
|
280
|
-
if( show ) {
|
|
281
|
-
this.displayCenter( );
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
this._do_hide( );
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return this;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
*
|
|
292
|
-
*/
|
|
293
|
-
|
|
294
|
-
close( ) {
|
|
295
|
-
this._do_hide( );
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* binded
|
|
300
|
-
*/
|
|
301
|
-
|
|
302
|
-
private _dismiss = ( e: UIEvent ) => {
|
|
303
|
-
const onac = autoclose_list.some( x=> x.dom.contains(e.target as Node) )
|
|
304
|
-
if( onac ) {
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
e.preventDefault( );
|
|
309
|
-
e.stopPropagation( );
|
|
310
|
-
|
|
311
|
-
this.dismiss( );
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* dismiss all popup belonging to the same group as 'this'
|
|
316
|
-
*/
|
|
317
|
-
|
|
318
|
-
dismiss( after = false ) {
|
|
319
|
-
|
|
320
|
-
if( autoclose_list.length==0 ) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const cgroup = this.getData( "close" );
|
|
325
|
-
const inc_group: Popup[] = [];
|
|
326
|
-
const excl_group: Popup[] = [];
|
|
327
|
-
|
|
328
|
-
let aidx = -1;
|
|
329
|
-
if( after ) {
|
|
330
|
-
aidx = autoclose_list.indexOf( this );
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
autoclose_list.forEach( (x,idx) => {
|
|
334
|
-
const group = x.getData( "close" );
|
|
335
|
-
if( group==cgroup && idx>aidx) {
|
|
336
|
-
inc_group.push( x );
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
excl_group.push( x );
|
|
340
|
-
}
|
|
341
|
-
})
|
|
342
|
-
|
|
343
|
-
const list = inc_group.reverse( );
|
|
344
|
-
autoclose_list = excl_group;
|
|
345
|
-
if( autoclose_list.length==0 ) {
|
|
346
|
-
document.removeEventListener( "pointerdown", this._dismiss );
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
list.forEach( x => x.close() );
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
*
|
|
354
|
-
*/
|
|
355
|
-
|
|
356
|
-
private _createSizers( ) {
|
|
357
|
-
this.appendContent( [
|
|
358
|
-
new CSizer( "top" ),
|
|
359
|
-
new CSizer( "bottom" ),
|
|
360
|
-
new CSizer( "left" ),
|
|
361
|
-
new CSizer( "right" ),
|
|
362
|
-
new CSizer( "top-left" ),
|
|
363
|
-
new CSizer( "bottom-left" ),
|
|
364
|
-
new CSizer( "top-right" ),
|
|
365
|
-
new CSizer( "bottom-right" ),
|
|
366
|
-
])
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
private _showModalMask( ) {
|
|
370
|
-
if( !modal_mask ) {
|
|
371
|
-
modal_mask = new Component( { cls: 'x4modal-mask' } )
|
|
372
|
-
//document.body.appendChild( modal_mask.dom );
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const root = getRoot( );
|
|
376
|
-
root.insertBefore( modal_mask.dom, this.dom );
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
private _hideModalMask( ) {
|
|
380
|
-
if( modal_mask ) {
|
|
381
|
-
const root = getRoot( );
|
|
382
|
-
if( modal_stack.length ) {
|
|
383
|
-
const top = modal_stack[ modal_stack.length-1 ];
|
|
384
|
-
root.insertBefore( modal_mask.dom, top.dom );
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
root.removeChild( modal_mask.dom );
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
*
|
|
396
|
-
*/
|
|
397
|
-
|
|
398
|
-
export
|
|
399
|
-
class CMover {
|
|
400
|
-
private ref: Component;
|
|
401
|
-
private delta: Point;
|
|
402
|
-
private self: boolean;
|
|
403
|
-
|
|
404
|
-
constructor( x: Component, ref?: Component ) {
|
|
405
|
-
|
|
406
|
-
this.self = ref ? true : false;
|
|
407
|
-
|
|
408
|
-
x.addDOMEvent( "pointerdown", ( e: PointerEvent ) => {
|
|
409
|
-
if( this.self && e.target!=x.dom ) {
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
x.setCapture( e.pointerId );
|
|
414
|
-
|
|
415
|
-
this.ref = ref ?? componentFromDOM( x.dom.parentElement );
|
|
416
|
-
|
|
417
|
-
this.delta = {x:0,y:0};
|
|
418
|
-
const rc = this.ref.getBoundingRect();
|
|
419
|
-
|
|
420
|
-
this.delta.x = e.pageX-rc.left;
|
|
421
|
-
this.delta.y = e.pageY-rc.top;
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
x.addDOMEvent( "pointerup", ( e: PointerEvent ) => {
|
|
425
|
-
x.releaseCapture( e.pointerId );
|
|
426
|
-
this.ref = null;
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
x.addDOMEvent( "pointermove", ( e: PointerEvent ) => {
|
|
430
|
-
this._onMouseMove( e );
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
private _onMouseMove( e: PointerEvent ) {
|
|
435
|
-
if( !this.ref ) {
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
const pt = { x: e.pageX-this.delta.x, y: e.pageY-this.delta.y };
|
|
440
|
-
const rc = this.ref.getBoundingRect( );
|
|
441
|
-
|
|
442
|
-
let nr: any = {
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
this.ref.setStyle( {
|
|
446
|
-
top: pt.y+"",
|
|
447
|
-
left: pt.x+"",
|
|
448
|
-
} );
|
|
449
|
-
|
|
450
|
-
e.preventDefault( );
|
|
451
|
-
e.stopPropagation( );
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file popup.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
*
|
|
11
|
+
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* Use of this source code is governed by an MIT-style license
|
|
14
|
+
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
+
**/
|
|
16
|
+
|
|
17
|
+
import { Component, ComponentEvent, ComponentEvents, ComponentProps, componentFromDOM, makeUniqueComponentId } from "../../core/component"
|
|
18
|
+
|
|
19
|
+
import { CSizer } from '../sizers/sizer';
|
|
20
|
+
import { Rect, Point, class_ns, asap } from '../../core/core_tools';
|
|
21
|
+
import { Box } from '../boxes/boxes'
|
|
22
|
+
|
|
23
|
+
import "./popup.module.scss"
|
|
24
|
+
import { getGlobalZoom, getScrollbarSize } from '../../core/core_tools.js';
|
|
25
|
+
|
|
26
|
+
export interface PopupEvents extends ComponentEvents {
|
|
27
|
+
closed: ComponentEvent;
|
|
28
|
+
opened: ComponentEvent;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface PopupProps extends ComponentProps {
|
|
32
|
+
autoClose?: boolean | string;
|
|
33
|
+
sizable?: boolean;
|
|
34
|
+
movable?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let autoclose_list: Popup[] = [];
|
|
38
|
+
let popup_list: Popup[] = [];
|
|
39
|
+
|
|
40
|
+
let modal_stack: Popup[] = [];
|
|
41
|
+
let modal_mask: Component;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function getRoot( ) {
|
|
45
|
+
return document.body;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
@class_ns( "x4" )
|
|
53
|
+
export class Popup<P extends PopupProps = PopupProps, E extends PopupEvents = PopupEvents> extends Box<P,E> {
|
|
54
|
+
|
|
55
|
+
private _isshown = false;
|
|
56
|
+
protected _ismodal = false;
|
|
57
|
+
|
|
58
|
+
constructor( props: P ) {
|
|
59
|
+
super( props );
|
|
60
|
+
|
|
61
|
+
if( this.props.sizable ) {
|
|
62
|
+
this._createSizers( );
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// wait for element to create it's childs
|
|
66
|
+
asap( ( ) => {
|
|
67
|
+
if( this.props.movable===true || (this.props.sizable && this.props.movable===undefined) ) {
|
|
68
|
+
const movers = this.queryAll( ".caption-element" );
|
|
69
|
+
movers.forEach( m => new CMover(m,this) );
|
|
70
|
+
|
|
71
|
+
if( this.hasClass("popup-caption") ) {
|
|
72
|
+
new CMover(this,this);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} );
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
displayNear( rc: Rect, dst = "top left", src = "top left", offset = {x:0,y:0} ) {
|
|
83
|
+
|
|
84
|
+
this.setStyle( { left: "0px", top: "0px" } ); // avoid scrollbar
|
|
85
|
+
this._do_show( ); // to compute size
|
|
86
|
+
|
|
87
|
+
let rm = this.getBoundingRect();
|
|
88
|
+
|
|
89
|
+
let xref = rc.left;
|
|
90
|
+
let yref = rc.top;
|
|
91
|
+
|
|
92
|
+
if( src.indexOf('right')>=0 ) {
|
|
93
|
+
xref = (rc.left+rc.width);
|
|
94
|
+
}
|
|
95
|
+
else if( src.indexOf('center')>=0 ) {
|
|
96
|
+
xref = rc.left + rc.width/2;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if( src.indexOf('bottom')>=0 ) {
|
|
100
|
+
yref = rc.bottom;
|
|
101
|
+
}
|
|
102
|
+
else if( src.indexOf('middle')>=0 ) {
|
|
103
|
+
yref = rc.top + rc.height/2;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (dst.indexOf('right') >= 0) {
|
|
107
|
+
xref -= rm.width;
|
|
108
|
+
}
|
|
109
|
+
else if( dst.indexOf('center')>=0 ) {
|
|
110
|
+
xref -= rm.width/2;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (dst.indexOf('bottom') >= 0) {
|
|
114
|
+
yref -= rm.height;
|
|
115
|
+
}
|
|
116
|
+
else if( dst.indexOf('middle')>=0 ) {
|
|
117
|
+
yref -= rm.height/2;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (offset) {
|
|
121
|
+
xref += offset.x;
|
|
122
|
+
yref += offset.y;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// our parent is body, so take care of the scroll position
|
|
126
|
+
xref += document.scrollingElement.scrollLeft;
|
|
127
|
+
yref += document.scrollingElement.scrollTop;
|
|
128
|
+
|
|
129
|
+
this.displayAt( xref, yref );
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* s
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
displayCenter( center = true ) {
|
|
137
|
+
//this.displayNear( new Rect( window.innerWidth/2, window.innerHeight/2, 0, 0 ), "center middle" );
|
|
138
|
+
this.setClass( 'center', center );
|
|
139
|
+
this._do_show( ); // to compute size
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
displayAt( x: number, y: number ) {
|
|
147
|
+
const zm = getGlobalZoom( );
|
|
148
|
+
|
|
149
|
+
//TODO: check is already visible
|
|
150
|
+
this.setStyle( {
|
|
151
|
+
left: (x/zm)+"px",
|
|
152
|
+
top: (y/zm)+"px",
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
this._do_show( ); // to compute size
|
|
156
|
+
|
|
157
|
+
const rc = this.getBoundingRect( ).scale( 1/zm );
|
|
158
|
+
const sbw = getScrollbarSize( );
|
|
159
|
+
|
|
160
|
+
const screen_width = window.innerWidth - sbw;
|
|
161
|
+
if( rc.right>screen_width ) {
|
|
162
|
+
this.setStyleValue( "left", screen_width-rc.width );
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const screen_height = window.innerHeight - sbw;
|
|
166
|
+
if( rc.bottom>screen_height ) {
|
|
167
|
+
this.setStyleValue( "top", screen_height-rc.height );
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
isOpen( ) {
|
|
172
|
+
return this._isshown;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
protected _do_hide( ) {
|
|
176
|
+
|
|
177
|
+
if( !this._isshown ) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.__hide( );
|
|
182
|
+
this.__remove( );
|
|
183
|
+
|
|
184
|
+
if( this._ismodal ) {
|
|
185
|
+
// modal1.show()
|
|
186
|
+
// modal2.show()
|
|
187
|
+
// modal1.hide()
|
|
188
|
+
if( modal_stack[modal_stack.length-1]!=this ) {
|
|
189
|
+
const idx = modal_stack.findIndex( x => x===this );
|
|
190
|
+
if( idx>=0 ) {
|
|
191
|
+
modal_stack.splice( idx, 1 );
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
modal_stack.pop( );
|
|
196
|
+
this._hideModalMask( );
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// remove from popup list
|
|
201
|
+
const idx = popup_list.indexOf( this );
|
|
202
|
+
console.assert( idx>=0 );
|
|
203
|
+
popup_list.splice( idx, 1 );
|
|
204
|
+
|
|
205
|
+
// remove from auto close list
|
|
206
|
+
if( this.props.autoClose ) {
|
|
207
|
+
const idx = autoclose_list.indexOf( this );
|
|
208
|
+
if( idx>=0 ) {
|
|
209
|
+
autoclose_list.splice( idx, 1 );
|
|
210
|
+
if( autoclose_list.length==0 ) {
|
|
211
|
+
document.removeEventListener( "pointerdown", this._dismiss );
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
this._isshown = false;
|
|
217
|
+
this.fire( "closed", {} );
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
*
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
protected _do_show( ) {
|
|
225
|
+
if( this._isshown ) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
this._isshown = true;
|
|
230
|
+
this.__append( );
|
|
231
|
+
|
|
232
|
+
if( this._ismodal ) {
|
|
233
|
+
modal_stack.push( this );
|
|
234
|
+
this._showModalMask( );
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
this.__show( );
|
|
238
|
+
|
|
239
|
+
if( this.props.autoClose ) {
|
|
240
|
+
if( autoclose_list.length==0 ) {
|
|
241
|
+
document.addEventListener( "pointerdown", this._dismiss );
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
autoclose_list.push( this );
|
|
245
|
+
this.setData( "close", this.props.autoClose===true ? makeUniqueComponentId() : this.props.autoClose );
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
popup_list.push( this );
|
|
249
|
+
|
|
250
|
+
this.fire( "opened", {} );
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
*
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
protected __show( ) {
|
|
258
|
+
super.show( true );
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
protected __hide( ) {
|
|
262
|
+
super.show( false );
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
protected __append( ) {
|
|
266
|
+
const root = getRoot( );
|
|
267
|
+
root.appendChild( this.dom );
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
protected __remove( ) {
|
|
271
|
+
const root = getRoot( );
|
|
272
|
+
root.removeChild( this.dom );
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
*/
|
|
278
|
+
|
|
279
|
+
override show( show = true ) : this {
|
|
280
|
+
if( show ) {
|
|
281
|
+
this.displayCenter( );
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
this._do_hide( );
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
*
|
|
292
|
+
*/
|
|
293
|
+
|
|
294
|
+
close( ) {
|
|
295
|
+
this._do_hide( );
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* binded
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
private _dismiss = ( e: UIEvent ) => {
|
|
303
|
+
const onac = autoclose_list.some( x=> x.dom.contains(e.target as Node) )
|
|
304
|
+
if( onac ) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
e.preventDefault( );
|
|
309
|
+
e.stopPropagation( );
|
|
310
|
+
|
|
311
|
+
this.dismiss( );
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* dismiss all popup belonging to the same group as 'this'
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
dismiss( after = false ) {
|
|
319
|
+
|
|
320
|
+
if( autoclose_list.length==0 ) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const cgroup = this.getData( "close" );
|
|
325
|
+
const inc_group: Popup[] = [];
|
|
326
|
+
const excl_group: Popup[] = [];
|
|
327
|
+
|
|
328
|
+
let aidx = -1;
|
|
329
|
+
if( after ) {
|
|
330
|
+
aidx = autoclose_list.indexOf( this );
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
autoclose_list.forEach( (x,idx) => {
|
|
334
|
+
const group = x.getData( "close" );
|
|
335
|
+
if( group==cgroup && idx>aidx) {
|
|
336
|
+
inc_group.push( x );
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
excl_group.push( x );
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
const list = inc_group.reverse( );
|
|
344
|
+
autoclose_list = excl_group;
|
|
345
|
+
if( autoclose_list.length==0 ) {
|
|
346
|
+
document.removeEventListener( "pointerdown", this._dismiss );
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
list.forEach( x => x.close() );
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
*
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
private _createSizers( ) {
|
|
357
|
+
this.appendContent( [
|
|
358
|
+
new CSizer( "top" ),
|
|
359
|
+
new CSizer( "bottom" ),
|
|
360
|
+
new CSizer( "left" ),
|
|
361
|
+
new CSizer( "right" ),
|
|
362
|
+
new CSizer( "top-left" ),
|
|
363
|
+
new CSizer( "bottom-left" ),
|
|
364
|
+
new CSizer( "top-right" ),
|
|
365
|
+
new CSizer( "bottom-right" ),
|
|
366
|
+
])
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
private _showModalMask( ) {
|
|
370
|
+
if( !modal_mask ) {
|
|
371
|
+
modal_mask = new Component( { cls: 'x4modal-mask' } )
|
|
372
|
+
//document.body.appendChild( modal_mask.dom );
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const root = getRoot( );
|
|
376
|
+
root.insertBefore( modal_mask.dom, this.dom );
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private _hideModalMask( ) {
|
|
380
|
+
if( modal_mask ) {
|
|
381
|
+
const root = getRoot( );
|
|
382
|
+
if( modal_stack.length ) {
|
|
383
|
+
const top = modal_stack[ modal_stack.length-1 ];
|
|
384
|
+
root.insertBefore( modal_mask.dom, top.dom );
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
root.removeChild( modal_mask.dom );
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
*
|
|
396
|
+
*/
|
|
397
|
+
|
|
398
|
+
export
|
|
399
|
+
class CMover {
|
|
400
|
+
private ref: Component;
|
|
401
|
+
private delta: Point;
|
|
402
|
+
private self: boolean;
|
|
403
|
+
|
|
404
|
+
constructor( x: Component, ref?: Component ) {
|
|
405
|
+
|
|
406
|
+
this.self = ref ? true : false;
|
|
407
|
+
|
|
408
|
+
x.addDOMEvent( "pointerdown", ( e: PointerEvent ) => {
|
|
409
|
+
if( this.self && e.target!=x.dom ) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
x.setCapture( e.pointerId );
|
|
414
|
+
|
|
415
|
+
this.ref = ref ?? componentFromDOM( x.dom.parentElement );
|
|
416
|
+
|
|
417
|
+
this.delta = {x:0,y:0};
|
|
418
|
+
const rc = this.ref.getBoundingRect();
|
|
419
|
+
|
|
420
|
+
this.delta.x = e.pageX-rc.left;
|
|
421
|
+
this.delta.y = e.pageY-rc.top;
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
x.addDOMEvent( "pointerup", ( e: PointerEvent ) => {
|
|
425
|
+
x.releaseCapture( e.pointerId );
|
|
426
|
+
this.ref = null;
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
x.addDOMEvent( "pointermove", ( e: PointerEvent ) => {
|
|
430
|
+
this._onMouseMove( e );
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
private _onMouseMove( e: PointerEvent ) {
|
|
435
|
+
if( !this.ref ) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const pt = { x: e.pageX-this.delta.x, y: e.pageY-this.delta.y };
|
|
440
|
+
const rc = this.ref.getBoundingRect( );
|
|
441
|
+
|
|
442
|
+
let nr: any = {
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
this.ref.setStyle( {
|
|
446
|
+
top: pt.y+"",
|
|
447
|
+
left: pt.x+"",
|
|
448
|
+
} );
|
|
449
|
+
|
|
450
|
+
e.preventDefault( );
|
|
451
|
+
e.stopPropagation( );
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|