cx 26.3.1 → 26.3.3
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/build/widgets/overlay/Overlay.d.ts +1 -1
- package/build/widgets/overlay/Overlay.d.ts.map +1 -1
- package/build/widgets/overlay/Overlay.js +10 -19
- package/build/widgets/overlay/Window.d.ts.map +1 -1
- package/build/widgets/overlay/Window.js +5 -11
- package/dist/manifest.js +896 -896
- package/dist/widgets.js +11 -11
- package/package.json +1 -1
- package/src/widgets/overlay/Overlay.tsx +1028 -1096
- package/src/widgets/overlay/Window.tsx +320 -354
- package/src/widgets/variables.scss +62 -63
|
@@ -1,1096 +1,1028 @@
|
|
|
1
|
-
/** @jsxImportSource react */
|
|
2
|
-
import type { Root } from "cx-react";
|
|
3
|
-
import { isBinding, isBindingObject } from "../../data/Binding";
|
|
4
|
-
import { Store } from "../../data/Store";
|
|
5
|
-
import { View } from "../../data/View";
|
|
6
|
-
import { startAppLoop } from "../../ui/app/startAppLoop";
|
|
7
|
-
import { ContainerBase, StyledContainerConfig } from "../../ui/Container";
|
|
8
|
-
import { FocusManager, offFocusOut, oneFocusOut } from "../../ui/FocusManager";
|
|
9
|
-
import { Instance } from "../../ui/Instance";
|
|
10
|
-
import { BooleanProp, NumberProp } from "../../ui/Prop";
|
|
11
|
-
import { RenderingContext } from "../../ui/RenderingContext";
|
|
12
|
-
import { VDOM, Widget } from "../../ui/Widget";
|
|
13
|
-
import { ZIndexManager } from "../../ui/ZIndexManager";
|
|
14
|
-
import { addEventListenerWithOptions } from "../../util/addEventListenerWithOptions";
|
|
15
|
-
import { closest, isSelfOrDescendant } from "../../util/DOM";
|
|
16
|
-
import { getActiveElement } from "../../util/getActiveElement";
|
|
17
|
-
import { getTopLevelBoundingClientRect } from "../../util/getTopLevelBoundingClientRect";
|
|
18
|
-
import { isDataRecord } from "../../util/isDataRecord";
|
|
19
|
-
import { isNumber } from "../../util/isNumber";
|
|
20
|
-
import { KeyCode } from "../../util/KeyCode";
|
|
21
|
-
import { parseStyle } from "../../util/parseStyle";
|
|
22
|
-
import { SubscriberList } from "../../util/SubscriberList";
|
|
23
|
-
import { ddDetect, ddMouseDown, ddMouseUp } from "../drag-drop/ops";
|
|
24
|
-
import { captureMouseOrTouch, getCursorPos } from "./captureMouse";
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
Features:
|
|
28
|
-
- renders itself on top of other elements
|
|
29
|
-
- provide resizing capabilities
|
|
30
|
-
- adds positioning hook and ability to position itself in the center of the page
|
|
31
|
-
- provides header, body, and footer elements and updates body's height on resize (move this to Window)
|
|
32
|
-
- stop mouse events from bubbling to parents, but allow keystrokes
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
export interface OverlayConfig extends StyledContainerConfig {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface OverlayOpenOptions {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface ConfigureOverlayContainerContext {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export class OverlayInstance<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
let
|
|
832
|
-
let
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
);
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
this.
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
this.setState({
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
getOverlayCssClass() {
|
|
1032
|
-
let { data, widget } = this.props.instance;
|
|
1033
|
-
let { CSS } = widget;
|
|
1034
|
-
|
|
1035
|
-
return (
|
|
1036
|
-
CSS.expand(
|
|
1037
|
-
data.classNames,
|
|
1038
|
-
CSS.state({
|
|
1039
|
-
...this.state.mods,
|
|
1040
|
-
animated: this.state.animated && !this.unmounting && !this.dismissed,
|
|
1041
|
-
"animate-enter": this.state.animated && !this.dismissed,
|
|
1042
|
-
"animate-leave": widget.animate && this.dismissed,
|
|
1043
|
-
}),
|
|
1044
|
-
) ?? ""
|
|
1045
|
-
);
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
overlayDidUpdate() {
|
|
1049
|
-
if (this.el && !this.dismissed) {
|
|
1050
|
-
let { widget } = this.props.instance;
|
|
1051
|
-
widget.overlayDidUpdate(this.props.instance, this);
|
|
1052
|
-
this.el.className = this.getOverlayCssClass();
|
|
1053
|
-
Object.assign(this.el.style, this.getOverlayStyle());
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
componentDidUpdate() {
|
|
1058
|
-
if (this.containerEl && !VDOM.DOM.createPortal) {
|
|
1059
|
-
this.root = VDOM.DOM.createRoot(this.containerEl);
|
|
1060
|
-
this.root.render(this.renderOverlay());
|
|
1061
|
-
}
|
|
1062
|
-
this.overlayDidUpdate();
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
interface OverlayBeaconProps {
|
|
1067
|
-
childrenFactory: (beacon: HTMLElement) => React.ReactNode;
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
export interface OverlayBeaconState {
|
|
1071
|
-
children?: React.ReactNode;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
export class OverlayBeacon extends VDOM.Component<
|
|
1075
|
-
OverlayBeaconProps,
|
|
1076
|
-
OverlayBeaconState
|
|
1077
|
-
> {
|
|
1078
|
-
el: HTMLElement | null;
|
|
1079
|
-
render() {
|
|
1080
|
-
return (
|
|
1081
|
-
<>
|
|
1082
|
-
<div
|
|
1083
|
-
ref={(el) => {
|
|
1084
|
-
this.el = el;
|
|
1085
|
-
}}
|
|
1086
|
-
style={{ position: "absolute", display: "none" }}
|
|
1087
|
-
/>
|
|
1088
|
-
{this.state?.children}
|
|
1089
|
-
</>
|
|
1090
|
-
);
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
componentDidMount(): void {
|
|
1094
|
-
this.setState({ children: this.props.childrenFactory(this.el!) });
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1
|
+
/** @jsxImportSource react */
|
|
2
|
+
import type { Root } from "cx-react";
|
|
3
|
+
import { isBinding, isBindingObject } from "../../data/Binding";
|
|
4
|
+
import { Store } from "../../data/Store";
|
|
5
|
+
import { View } from "../../data/View";
|
|
6
|
+
import { startAppLoop } from "../../ui/app/startAppLoop";
|
|
7
|
+
import { ContainerBase, StyledContainerConfig } from "../../ui/Container";
|
|
8
|
+
import { FocusManager, offFocusOut, oneFocusOut } from "../../ui/FocusManager";
|
|
9
|
+
import { Instance } from "../../ui/Instance";
|
|
10
|
+
import { BooleanProp, NumberProp } from "../../ui/Prop";
|
|
11
|
+
import { RenderingContext } from "../../ui/RenderingContext";
|
|
12
|
+
import { VDOM, Widget } from "../../ui/Widget";
|
|
13
|
+
import { ZIndexManager } from "../../ui/ZIndexManager";
|
|
14
|
+
import { addEventListenerWithOptions } from "../../util/addEventListenerWithOptions";
|
|
15
|
+
import { closest, isSelfOrDescendant } from "../../util/DOM";
|
|
16
|
+
import { getActiveElement } from "../../util/getActiveElement";
|
|
17
|
+
import { getTopLevelBoundingClientRect } from "../../util/getTopLevelBoundingClientRect";
|
|
18
|
+
import { isDataRecord } from "../../util/isDataRecord";
|
|
19
|
+
import { isNumber } from "../../util/isNumber";
|
|
20
|
+
import { KeyCode } from "../../util/KeyCode";
|
|
21
|
+
import { parseStyle } from "../../util/parseStyle";
|
|
22
|
+
import { SubscriberList } from "../../util/SubscriberList";
|
|
23
|
+
import { ddDetect, ddMouseDown, ddMouseUp } from "../drag-drop/ops";
|
|
24
|
+
import { captureMouseOrTouch, getCursorPos } from "./captureMouse";
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
Features:
|
|
28
|
+
- renders itself on top of other elements
|
|
29
|
+
- provide resizing capabilities
|
|
30
|
+
- adds positioning hook and ability to position itself in the center of the page
|
|
31
|
+
- provides header, body, and footer elements and updates body's height on resize (move this to Window)
|
|
32
|
+
- stop mouse events from bubbling to parents, but allow keystrokes
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export interface OverlayConfig extends StyledContainerConfig {
|
|
36
|
+
/** Set to `true` to enable resizing. */
|
|
37
|
+
resizable?: BooleanProp;
|
|
38
|
+
|
|
39
|
+
/** Set to `true` to enable dragging the overlay. */
|
|
40
|
+
draggable?: BooleanProp;
|
|
41
|
+
|
|
42
|
+
/** Base CSS class to be applied to the field. Defaults to `overlay`. */
|
|
43
|
+
baseClass?: string;
|
|
44
|
+
|
|
45
|
+
/** Width of resize handle area. */
|
|
46
|
+
resizeWidth?: number;
|
|
47
|
+
|
|
48
|
+
/** Set to `true` to initially place the overlay in the center of the page. */
|
|
49
|
+
center?: boolean;
|
|
50
|
+
|
|
51
|
+
/** Set to `true` to initially place the overlay in the center of the page horizontally. */
|
|
52
|
+
centerX?: boolean;
|
|
53
|
+
|
|
54
|
+
/** Set to `true` to initially place the overlay in the center of the page vertically. */
|
|
55
|
+
centerY?: boolean;
|
|
56
|
+
|
|
57
|
+
/** Set to `true` to add a modal backdrop which masks mouse events for the rest of the page. */
|
|
58
|
+
modal?: boolean;
|
|
59
|
+
|
|
60
|
+
/** Set to `true` to add a modal backdrop which will dismiss the window when clicked. */
|
|
61
|
+
backdrop?: boolean;
|
|
62
|
+
|
|
63
|
+
/** Set to `true` to force the element to be rendered inline, instead of being appended to the body element.
|
|
64
|
+
* Inline overlays have z-index set to a very high value, to ensure they are displayed on top of the other content. */
|
|
65
|
+
inline?: boolean;
|
|
66
|
+
|
|
67
|
+
/** Set to `true` to automatically focus the top level overlay element. */
|
|
68
|
+
autoFocus?: boolean;
|
|
69
|
+
|
|
70
|
+
/** Set to `true` to automatically focus the first focusable child in the overlay. */
|
|
71
|
+
autoFocusFirstChild?: boolean;
|
|
72
|
+
|
|
73
|
+
/** Set to `true` to append the set animate state after the initial render. Appended CSS class may be used to add show/hide animations. */
|
|
74
|
+
animate?: boolean;
|
|
75
|
+
|
|
76
|
+
/** Number of milliseconds to wait, before removing the element from the DOM. Used in combination with the animate property. */
|
|
77
|
+
destroyDelay?: number;
|
|
78
|
+
|
|
79
|
+
/** Automatically dismiss overlay if it loses focus. */
|
|
80
|
+
dismissOnFocusOut?: boolean;
|
|
81
|
+
|
|
82
|
+
/** Set to true to make the top level overlay element focusable. */
|
|
83
|
+
focusable?: boolean;
|
|
84
|
+
|
|
85
|
+
/** Set to `true` to dismiss the window if the user presses the back button in the browser. */
|
|
86
|
+
dismissOnPopState?: boolean;
|
|
87
|
+
|
|
88
|
+
/** A callback function which fires while the overlay is being moved around. */
|
|
89
|
+
onMove?: string | ((e: Event, instance: Instance, component: any) => void);
|
|
90
|
+
|
|
91
|
+
/** A callback function which fires while the overlay is being resized. */
|
|
92
|
+
onResize?: string | ((e: Event, instance: Instance, component: any) => void);
|
|
93
|
+
|
|
94
|
+
/** zIndex */
|
|
95
|
+
zIndex?: NumberProp;
|
|
96
|
+
|
|
97
|
+
/** Set to `true` to make the window automatically close if Esc is pressed on the keyboard. Default value is false.*/
|
|
98
|
+
closeOnEscape?: boolean;
|
|
99
|
+
|
|
100
|
+
/** Custom CSS styling for the container element. */
|
|
101
|
+
containerStyle?: string;
|
|
102
|
+
|
|
103
|
+
/** Callback for focus out event. */
|
|
104
|
+
onFocusOut?: string;
|
|
105
|
+
|
|
106
|
+
/** Callback for mouse enter event. */
|
|
107
|
+
onMouseEnter?: string;
|
|
108
|
+
|
|
109
|
+
/** Callback for mouse leave event. */
|
|
110
|
+
onMouseLeave?: string;
|
|
111
|
+
|
|
112
|
+
/** Callback for backdrop click. */
|
|
113
|
+
onBackdropClick?: string;
|
|
114
|
+
|
|
115
|
+
/** Callback for mouse down event. */
|
|
116
|
+
onMouseDown?: string;
|
|
117
|
+
|
|
118
|
+
/** Callback for key down event. */
|
|
119
|
+
onKeyDown?: string;
|
|
120
|
+
|
|
121
|
+
/** Callback fired before dismiss. */
|
|
122
|
+
onBeforeDismiss?: string | (() => boolean);
|
|
123
|
+
|
|
124
|
+
/** Callback fired when overlay will dismiss. */
|
|
125
|
+
overlayWillDismiss?: (instance: Instance, component: any) => boolean;
|
|
126
|
+
|
|
127
|
+
/** Callback for click event. */
|
|
128
|
+
onClick?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface OverlayOpenOptions {
|
|
132
|
+
initiatingEvent?: React.SyntheticEvent;
|
|
133
|
+
name?: string;
|
|
134
|
+
dismiss?: () => void;
|
|
135
|
+
parentEl?: Element;
|
|
136
|
+
subscribeToBeforeDismiss?: (callback: () => boolean) => void;
|
|
137
|
+
destroyDelay?: number;
|
|
138
|
+
removeParentDOMElement?: boolean;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface ConfigureOverlayContainerContext {
|
|
142
|
+
relatedElement?: HTMLElement | null;
|
|
143
|
+
initiatingEvent?: React.SyntheticEvent;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export class OverlayInstance<WidgetType extends OverlayBase<any, any> = Overlay> extends Instance<WidgetType> {
|
|
147
|
+
declare positionChangeSubscribers: SubscriberList;
|
|
148
|
+
declare dismiss?: () => void;
|
|
149
|
+
onBeforeDismiss?: () => boolean;
|
|
150
|
+
declare beaconEl?: HTMLElement | null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export class OverlayBase<
|
|
154
|
+
Config extends OverlayConfig = OverlayConfig,
|
|
155
|
+
InstanceType extends OverlayInstance<any> = OverlayInstance<any>,
|
|
156
|
+
> extends ContainerBase<Config, InstanceType> {
|
|
157
|
+
static configureOverlayContainer?: (containerEl: HTMLElement, context: ConfigureOverlayContainerContext) => void;
|
|
158
|
+
|
|
159
|
+
// Properties declared here to support prototype assignments
|
|
160
|
+
declare styled: true;
|
|
161
|
+
declare baseClass: string;
|
|
162
|
+
declare resizable?: BooleanProp;
|
|
163
|
+
declare resizeWidth: number;
|
|
164
|
+
declare center?: boolean;
|
|
165
|
+
declare centerX?: boolean;
|
|
166
|
+
declare centerY?: boolean;
|
|
167
|
+
declare modal?: boolean;
|
|
168
|
+
declare backdrop?: boolean;
|
|
169
|
+
declare inline?: boolean;
|
|
170
|
+
declare autoFocus?: boolean;
|
|
171
|
+
declare autoFocusFirstChild?: boolean;
|
|
172
|
+
declare animate?: boolean;
|
|
173
|
+
declare draggable?: BooleanProp;
|
|
174
|
+
declare destroyDelay?: number;
|
|
175
|
+
declare dismissOnFocusOut?: boolean;
|
|
176
|
+
declare focusable?: boolean;
|
|
177
|
+
declare containerStyle?: string;
|
|
178
|
+
declare dismissOnPopState?: boolean;
|
|
179
|
+
declare closeOnEscape?: boolean;
|
|
180
|
+
declare onFocusOut?: string;
|
|
181
|
+
declare onMouseLeave?: string;
|
|
182
|
+
declare onMouseEnter?: string;
|
|
183
|
+
declare onKeyDown?: string;
|
|
184
|
+
declare onMove?: string | ((e: Event, instance: Instance, component: any) => void);
|
|
185
|
+
declare onResize?: string | ((e: Event, instance: Instance, component: any) => void);
|
|
186
|
+
declare onClick?: string;
|
|
187
|
+
declare onMouseDown?: string;
|
|
188
|
+
declare onBackdropClick?: string;
|
|
189
|
+
declare overlayWillDismiss?: (instance: Instance, component: any) => boolean;
|
|
190
|
+
declare style?: any;
|
|
191
|
+
declare pad?: boolean;
|
|
192
|
+
declare needsBeacon: boolean;
|
|
193
|
+
|
|
194
|
+
init() {
|
|
195
|
+
if (this.center) this.centerX = this.centerY = this.center;
|
|
196
|
+
|
|
197
|
+
super.init();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declareData(...args: any[]) {
|
|
201
|
+
super.declareData(...args, {
|
|
202
|
+
shadowStyle: {
|
|
203
|
+
structured: true,
|
|
204
|
+
},
|
|
205
|
+
resizable: undefined,
|
|
206
|
+
draggable: undefined,
|
|
207
|
+
zIndex: undefined,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
prepareData(context: RenderingContext, instance: InstanceType): void {
|
|
212
|
+
let { data } = instance;
|
|
213
|
+
data.stateMods = {
|
|
214
|
+
...data.stateMods,
|
|
215
|
+
inline: this.inline,
|
|
216
|
+
modal: this.modal,
|
|
217
|
+
pad: this.pad,
|
|
218
|
+
resizable: data.resizable,
|
|
219
|
+
draggable: data.draggable,
|
|
220
|
+
animate: this.animate,
|
|
221
|
+
shadow: this.modal || this.backdrop,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
super.prepareData(context, instance);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
initInstance(context: RenderingContext, instance: InstanceType): void {
|
|
228
|
+
instance.positionChangeSubscribers = new SubscriberList();
|
|
229
|
+
super.initInstance(context, instance);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
explore(context: RenderingContext, instance: InstanceType): void {
|
|
233
|
+
if (isBinding(this.visible)) {
|
|
234
|
+
if (!instance.dismiss) {
|
|
235
|
+
instance.dismiss = () => {
|
|
236
|
+
if (instance.onBeforeDismiss && instance.onBeforeDismiss() === false) return;
|
|
237
|
+
instance.set("visible", false);
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
} else if (context.options.dismiss) instance.dismiss = context.options.dismiss;
|
|
241
|
+
|
|
242
|
+
if (instance.dismiss) {
|
|
243
|
+
context.push("parentOptions", {
|
|
244
|
+
...context.parentOptions,
|
|
245
|
+
dismiss: instance.dismiss,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (instance.cache("dismiss", instance.dismiss)) instance.markShouldUpdate(context);
|
|
250
|
+
|
|
251
|
+
context.push("parentPositionChangeEvent", instance.positionChangeSubscribers);
|
|
252
|
+
|
|
253
|
+
super.explore(context, instance);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
exploreCleanup(context: RenderingContext, instance: InstanceType): void {
|
|
257
|
+
if (instance.dismiss) context.pop("parentOptions");
|
|
258
|
+
context.pop("parentPositionChangeEvent");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
render(context: RenderingContext, instance: InstanceType, key: string): any {
|
|
262
|
+
if (this.needsBeacon)
|
|
263
|
+
return (
|
|
264
|
+
<OverlayBeacon
|
|
265
|
+
key={key}
|
|
266
|
+
childrenFactory={(beaconEl) => (
|
|
267
|
+
<OverlayComponent
|
|
268
|
+
beaconEl={beaconEl}
|
|
269
|
+
instance={instance}
|
|
270
|
+
subscribeToBeforeDismiss={context.options.subscribeToBeforeDismiss}
|
|
271
|
+
parentEl={context.options.parentEl}
|
|
272
|
+
>
|
|
273
|
+
{this.renderContents(context, instance)}
|
|
274
|
+
</OverlayComponent>
|
|
275
|
+
)}
|
|
276
|
+
/>
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
return (
|
|
280
|
+
<OverlayComponent
|
|
281
|
+
beaconEl={null}
|
|
282
|
+
instance={instance}
|
|
283
|
+
subscribeToBeforeDismiss={context.options.subscribeToBeforeDismiss}
|
|
284
|
+
parentEl={context.options.parentEl}
|
|
285
|
+
>
|
|
286
|
+
{this.renderContents(context, instance)}
|
|
287
|
+
</OverlayComponent>
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
renderContents(context: RenderingContext, instance: InstanceType): any {
|
|
292
|
+
return this.renderChildren(context, instance);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
getConfigureOverlayContainerContext(
|
|
296
|
+
instance?: InstanceType,
|
|
297
|
+
initiatingEvent?: React.SyntheticEvent,
|
|
298
|
+
): ConfigureOverlayContainerContext {
|
|
299
|
+
return {
|
|
300
|
+
initiatingEvent,
|
|
301
|
+
relatedElement: instance?.beaconEl,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
overlayDidMount(instance: InstanceType, component: any): void {
|
|
306
|
+
let { el } = component;
|
|
307
|
+
if (this.centerX) if (!el.style.left) el.style.left = `${(window.innerWidth - el.offsetWidth) / 2}px`;
|
|
308
|
+
if (this.centerY)
|
|
309
|
+
if (!el.style.top) el.style.top = `${Math.max(0, (window.innerHeight - el.offsetHeight) / 2)}px`;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
overlayDidUpdate(instance: InstanceType, component: any): void {}
|
|
313
|
+
|
|
314
|
+
overlayWillUnmount(instance: InstanceType, component: any): void {}
|
|
315
|
+
|
|
316
|
+
handleFocusOut(instance: InstanceType, component: any): void {
|
|
317
|
+
if (this.onFocusOut) instance.invoke("onFocusOut", instance, component);
|
|
318
|
+
|
|
319
|
+
if (this.dismissOnFocusOut && instance.dismiss) instance.dismiss();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
handleKeyDown(e: any, instance: InstanceType, component?: any): void | false {
|
|
323
|
+
if (this.onKeyDown && instance.invoke("onKeyDown", e, instance, component) === false) return false;
|
|
324
|
+
|
|
325
|
+
if (this.closeOnEscape && e.keyCode == KeyCode.esc && instance.dismiss) {
|
|
326
|
+
instance.dismiss();
|
|
327
|
+
e.stopPropagation();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
handleMouseLeave(instance: InstanceType, component: any): void {
|
|
332
|
+
if (this.onMouseLeave) instance.invoke("onMouseLeave", instance, component);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
handleMouseEnter(instance: InstanceType, component: any): void {
|
|
336
|
+
if (this.onMouseEnter) instance.invoke("onMouseEnter", instance, component);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
getOverlayContainer(): HTMLElement {
|
|
340
|
+
return document.body;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
containerFactory(instance?: InstanceType, initiatingEvent?: React.SyntheticEvent): HTMLElement {
|
|
344
|
+
let el = document.createElement("div");
|
|
345
|
+
let container = this.getOverlayContainer();
|
|
346
|
+
container.appendChild(el);
|
|
347
|
+
el.style.position = "absolute";
|
|
348
|
+
if (this.containerStyle) Object.assign(el.style, parseStyle(this.containerStyle));
|
|
349
|
+
|
|
350
|
+
if (OverlayBase.configureOverlayContainer)
|
|
351
|
+
OverlayBase.configureOverlayContainer(el, this.getConfigureOverlayContainerContext(instance, initiatingEvent));
|
|
352
|
+
|
|
353
|
+
return el;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
open(storeOrInstance?: View | Instance, options?: OverlayOpenOptions): () => void {
|
|
357
|
+
if (!this.initialized) this.init();
|
|
358
|
+
|
|
359
|
+
let el = this.containerFactory(undefined, options?.initiatingEvent);
|
|
360
|
+
el.style.display = "hidden";
|
|
361
|
+
|
|
362
|
+
let beforeDismiss: (() => boolean) | null = null;
|
|
363
|
+
let stop: any;
|
|
364
|
+
|
|
365
|
+
options = {
|
|
366
|
+
destroyDelay: this.destroyDelay,
|
|
367
|
+
removeParentDOMElement: true,
|
|
368
|
+
...options,
|
|
369
|
+
parentEl: el,
|
|
370
|
+
dismiss: () => {
|
|
371
|
+
if (beforeDismiss && beforeDismiss() === false) return;
|
|
372
|
+
stop();
|
|
373
|
+
beforeDismiss = null;
|
|
374
|
+
},
|
|
375
|
+
subscribeToBeforeDismiss: (cb: () => boolean) => {
|
|
376
|
+
beforeDismiss = cb;
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
options.name = options.name || "overlay";
|
|
380
|
+
stop = startAppLoop(el, storeOrInstance, this, options);
|
|
381
|
+
return options.dismiss!;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
handleMove(e: any, instance: InstanceType, component: any): void {
|
|
385
|
+
let { widget } = instance;
|
|
386
|
+
if (!widget.onMove || instance.invoke("onMove", e, instance, component) !== false) {
|
|
387
|
+
instance.store.silently(() => {
|
|
388
|
+
if (isDataRecord(this.style) && isBindingObject(this.style.top)) {
|
|
389
|
+
instance.store.set(this.style.top.bind, component.el.style.top);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (isDataRecord(this.style) && isBindingObject(this.style.left)) {
|
|
393
|
+
instance.store.set(this.style.left.bind, component.el.style.left);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
instance.positionChangeSubscribers.notify();
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
handleResize(e: any, instance: InstanceType, component: any): void {
|
|
401
|
+
let { widget } = instance;
|
|
402
|
+
if (!widget.onResize || instance.invoke("onResize", e, instance, component) !== false) {
|
|
403
|
+
instance.store.silently(() => {
|
|
404
|
+
if (isDataRecord(this.style) && isBindingObject(this.style.width)) {
|
|
405
|
+
instance.store.set(this.style.width.bind, component.el.style.width);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (isDataRecord(this.style) && isBindingObject(this.style.height)) {
|
|
409
|
+
instance.store.set(this.style.height.bind, component.el.style.height);
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
instance.positionChangeSubscribers.notify();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
OverlayBase.prototype.styled = true;
|
|
418
|
+
OverlayBase.prototype.baseClass = "overlay";
|
|
419
|
+
OverlayBase.prototype.resizable = false;
|
|
420
|
+
OverlayBase.prototype.resizeWidth = 7;
|
|
421
|
+
OverlayBase.prototype.center = false;
|
|
422
|
+
OverlayBase.prototype.centerX = false;
|
|
423
|
+
OverlayBase.prototype.centerY = false;
|
|
424
|
+
OverlayBase.prototype.modal = false;
|
|
425
|
+
OverlayBase.prototype.backdrop = false;
|
|
426
|
+
OverlayBase.prototype.inline = false;
|
|
427
|
+
OverlayBase.prototype.autoFocus = false;
|
|
428
|
+
OverlayBase.prototype.autoFocusFirstChild = false;
|
|
429
|
+
OverlayBase.prototype.animate = false;
|
|
430
|
+
OverlayBase.prototype.draggable = false;
|
|
431
|
+
OverlayBase.prototype.destroyDelay = 0;
|
|
432
|
+
OverlayBase.prototype.dismissOnFocusOut = false;
|
|
433
|
+
OverlayBase.prototype.focusable = false;
|
|
434
|
+
OverlayBase.prototype.containerStyle = undefined;
|
|
435
|
+
OverlayBase.prototype.dismissOnPopState = false;
|
|
436
|
+
OverlayBase.prototype.closeOnEscape = false;
|
|
437
|
+
OverlayBase.prototype.needsBeacon = false;
|
|
438
|
+
|
|
439
|
+
export class Overlay extends OverlayBase<OverlayConfig, OverlayInstance> {}
|
|
440
|
+
|
|
441
|
+
Widget.alias("overlay", Overlay);
|
|
442
|
+
|
|
443
|
+
interface OverlayContentProps {
|
|
444
|
+
onRef: (el: HTMLDivElement | null) => void;
|
|
445
|
+
className: string;
|
|
446
|
+
style: any;
|
|
447
|
+
tabIndex: number | undefined;
|
|
448
|
+
onFocus: () => void;
|
|
449
|
+
onBlur: () => void;
|
|
450
|
+
onKeyDown: (e: any) => void;
|
|
451
|
+
onMouseMove: (e: any, captureData?: any) => void;
|
|
452
|
+
onMouseUp: (e: any) => void;
|
|
453
|
+
onMouseDown: (e: any) => void;
|
|
454
|
+
onTouchStart: (e: any) => void;
|
|
455
|
+
onTouchEnd: (e: any) => void;
|
|
456
|
+
onTouchMove: (e: any, captureData?: any) => void;
|
|
457
|
+
onMouseEnter: (e: any) => void;
|
|
458
|
+
onMouseLeave: (e: any) => void;
|
|
459
|
+
onClick: (e: any) => void;
|
|
460
|
+
onDidUpdate: () => void;
|
|
461
|
+
focusableOverlayContainer?: boolean;
|
|
462
|
+
children: any;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
//TODO: all el related logic should be moved here
|
|
466
|
+
class OverlayContent extends VDOM.Component<OverlayContentProps, {}> {
|
|
467
|
+
render() {
|
|
468
|
+
return (
|
|
469
|
+
<div
|
|
470
|
+
ref={this.props.onRef}
|
|
471
|
+
className={this.props.className}
|
|
472
|
+
style={this.props.style}
|
|
473
|
+
tabIndex={this.props.tabIndex}
|
|
474
|
+
onFocus={this.props.onFocus}
|
|
475
|
+
onBlur={this.props.onBlur}
|
|
476
|
+
onKeyDown={this.props.onKeyDown}
|
|
477
|
+
onMouseMove={this.props.onMouseMove}
|
|
478
|
+
onMouseUp={this.props.onMouseUp}
|
|
479
|
+
onMouseDown={this.props.onMouseDown}
|
|
480
|
+
onTouchStart={this.props.onTouchStart}
|
|
481
|
+
onTouchEnd={this.props.onTouchEnd}
|
|
482
|
+
onTouchMove={this.props.onTouchMove}
|
|
483
|
+
onMouseEnter={this.props.onMouseEnter}
|
|
484
|
+
onMouseLeave={this.props.onMouseLeave}
|
|
485
|
+
onClick={this.props.onClick}
|
|
486
|
+
data-focusable-overlay-container={this.props.focusableOverlayContainer}
|
|
487
|
+
>
|
|
488
|
+
{this.props.children}
|
|
489
|
+
</div>
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
componentDidUpdate() {
|
|
494
|
+
this.props.onDidUpdate();
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export interface OverlayComponentProps {
|
|
499
|
+
instance: OverlayInstance;
|
|
500
|
+
parentEl?: HTMLElement;
|
|
501
|
+
subscribeToBeforeDismiss?: (cb: () => boolean) => void;
|
|
502
|
+
children: any;
|
|
503
|
+
beaconEl: HTMLElement | null;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export interface OverlayComponentState {
|
|
507
|
+
animated?: boolean;
|
|
508
|
+
mods?: Record<string, boolean>;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
//TODO: This should be called OverlayPortal
|
|
512
|
+
export class OverlayComponent<
|
|
513
|
+
Props extends OverlayComponentProps = OverlayComponentProps,
|
|
514
|
+
State extends OverlayComponentState = OverlayComponentState,
|
|
515
|
+
> extends VDOM.Component<Props, State> {
|
|
516
|
+
declare el?: HTMLElement | null;
|
|
517
|
+
declare containerEl?: HTMLElement | null;
|
|
518
|
+
declare ownedEl?: HTMLElement | null;
|
|
519
|
+
onOverlayRef?: (el: HTMLElement | null) => void;
|
|
520
|
+
declare shadowEl?: HTMLElement | null;
|
|
521
|
+
declare dismissed?: boolean;
|
|
522
|
+
declare unmounting?: boolean;
|
|
523
|
+
onPopState?: () => void;
|
|
524
|
+
unsubscribeWheelBlock?: () => void;
|
|
525
|
+
declare customStyle: any;
|
|
526
|
+
declare root: Root;
|
|
527
|
+
|
|
528
|
+
constructor(props: Props) {
|
|
529
|
+
super(props);
|
|
530
|
+
this.state = {} as State;
|
|
531
|
+
this.customStyle = {};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
render() {
|
|
535
|
+
let { instance, parentEl } = this.props;
|
|
536
|
+
let { widget } = instance;
|
|
537
|
+
|
|
538
|
+
if (widget.inline || parentEl) return this.renderOverlay();
|
|
539
|
+
|
|
540
|
+
if (!this.containerEl) {
|
|
541
|
+
instance.beaconEl = this.props.beaconEl;
|
|
542
|
+
this.ownedEl = widget.containerFactory(instance);
|
|
543
|
+
this.ownedEl.style.display = "hidden";
|
|
544
|
+
this.containerEl = this.ownedEl;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// content is rendered in componentDidUpdate if portals are not supported
|
|
548
|
+
return VDOM.DOM.createPortal ? VDOM.DOM.createPortal!(this.renderOverlay(), this.containerEl) : null;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
renderOverlay() {
|
|
552
|
+
let { widget, data } = this.props.instance;
|
|
553
|
+
let { CSS, baseClass } = widget;
|
|
554
|
+
|
|
555
|
+
if (!this.onOverlayRef)
|
|
556
|
+
this.onOverlayRef = (el) => {
|
|
557
|
+
this.el = el;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
let content = (
|
|
561
|
+
<OverlayContent
|
|
562
|
+
onRef={this.onOverlayRef}
|
|
563
|
+
className={data.classNames}
|
|
564
|
+
style={data.style}
|
|
565
|
+
tabIndex={widget.focusable ? 0 : undefined}
|
|
566
|
+
onFocus={this.onFocus.bind(this)}
|
|
567
|
+
onBlur={this.onBlur.bind(this)}
|
|
568
|
+
onKeyDown={this.onKeyDown.bind(this)}
|
|
569
|
+
onMouseDown={this.onMouseDown.bind(this)}
|
|
570
|
+
onMouseUp={this.onMouseUp.bind(this)}
|
|
571
|
+
onMouseMove={this.onMouseMove.bind(this)}
|
|
572
|
+
onTouchStart={this.onMouseDown.bind(this)}
|
|
573
|
+
onTouchEnd={this.onMouseUp.bind(this)}
|
|
574
|
+
onTouchMove={this.onMouseMove.bind(this)}
|
|
575
|
+
onMouseLeave={this.onMouseLeave.bind(this)}
|
|
576
|
+
onMouseEnter={this.onMouseEnter.bind(this)}
|
|
577
|
+
onClick={this.onClick.bind(this)}
|
|
578
|
+
onDidUpdate={this.overlayDidUpdate.bind(this)}
|
|
579
|
+
focusableOverlayContainer={widget.dismissOnFocusOut}
|
|
580
|
+
>
|
|
581
|
+
{this.renderOverlayBody()}
|
|
582
|
+
</OverlayContent>
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
let result = content;
|
|
586
|
+
|
|
587
|
+
if (widget.modal || widget.backdrop) {
|
|
588
|
+
result = (
|
|
589
|
+
<div
|
|
590
|
+
key="shadow"
|
|
591
|
+
ref={(el) => {
|
|
592
|
+
this.shadowEl = el;
|
|
593
|
+
}}
|
|
594
|
+
className={CSS.element(baseClass, "shadow", {
|
|
595
|
+
animated: this.state.animated,
|
|
596
|
+
"animate-enter": this.state.animated && !this.dismissed,
|
|
597
|
+
animate: widget.animate,
|
|
598
|
+
})}
|
|
599
|
+
style={parseStyle(data.shadowStyle)}
|
|
600
|
+
>
|
|
601
|
+
<div
|
|
602
|
+
key="backdrop"
|
|
603
|
+
className={CSS.element("overlay", "modal-backdrop")}
|
|
604
|
+
onClick={this.onBackdropClick.bind(this)}
|
|
605
|
+
/>
|
|
606
|
+
{content}
|
|
607
|
+
</div>
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
return result;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
renderOverlayBody() {
|
|
615
|
+
return this.props.children;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
onFocus() {
|
|
619
|
+
FocusManager.nudge();
|
|
620
|
+
this.onFocusIn();
|
|
621
|
+
if (this.el) oneFocusOut(this, this.el, this.onFocusOut.bind(this));
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
onBlur() {
|
|
625
|
+
FocusManager.nudge();
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
onFocusIn() {}
|
|
629
|
+
|
|
630
|
+
onFocusOut() {
|
|
631
|
+
let { widget } = this.props.instance;
|
|
632
|
+
widget.handleFocusOut(this.props.instance, this);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
onMouseEnter(e: React.MouseEvent) {
|
|
636
|
+
let { widget } = this.props.instance;
|
|
637
|
+
widget.handleMouseEnter(this.props.instance, this);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
onMouseLeave(e: React.MouseEvent) {
|
|
641
|
+
let { widget } = this.props.instance;
|
|
642
|
+
widget.handleMouseLeave(this.props.instance, this);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
onClick(e: React.MouseEvent) {
|
|
646
|
+
let { instance } = this.props;
|
|
647
|
+
let { widget } = instance;
|
|
648
|
+
if (widget.onClick) instance.invoke("onClick", e, instance, this);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
onKeyDown(e: React.KeyboardEvent) {
|
|
652
|
+
let { widget } = this.props.instance;
|
|
653
|
+
widget.handleKeyDown(e, this.props.instance, this);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
getResizePrefix(e: MouseEvent | React.MouseEvent | React.TouchEvent) {
|
|
657
|
+
let { widget, data } = this.props.instance;
|
|
658
|
+
if (!data.resizable) return "";
|
|
659
|
+
let cursor = getCursorPos(e);
|
|
660
|
+
let bounds = getTopLevelBoundingClientRect(this.el!);
|
|
661
|
+
let leftMargin = cursor.clientX - bounds.left;
|
|
662
|
+
let rightMargin = bounds.right - cursor.clientX;
|
|
663
|
+
let topMargin = cursor.clientY - bounds.top;
|
|
664
|
+
let bottomMargin = bounds.bottom - cursor.clientY;
|
|
665
|
+
let prefix = "";
|
|
666
|
+
|
|
667
|
+
if (topMargin >= 0 && topMargin < widget.resizeWidth) prefix += "n";
|
|
668
|
+
else if (bottomMargin >= 0 && bottomMargin < widget.resizeWidth) prefix += "s";
|
|
669
|
+
|
|
670
|
+
if (leftMargin >= 0 && leftMargin < widget.resizeWidth) prefix += "w";
|
|
671
|
+
else if (rightMargin >= 0 && rightMargin < widget.resizeWidth) prefix += "e";
|
|
672
|
+
return prefix;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
onMouseDown(e: React.MouseEvent | React.TouchEvent) {
|
|
676
|
+
let { instance } = this.props;
|
|
677
|
+
let { widget, data } = instance;
|
|
678
|
+
|
|
679
|
+
if (widget.onMouseDown && instance.invoke("onMouseDown", e, instance) === false) return;
|
|
680
|
+
|
|
681
|
+
let prefix = this.getResizePrefix(e);
|
|
682
|
+
if (prefix) {
|
|
683
|
+
//e.preventDefault();
|
|
684
|
+
let rect = getTopLevelBoundingClientRect(this.el!);
|
|
685
|
+
let cursor = getCursorPos(e);
|
|
686
|
+
let captureData = {
|
|
687
|
+
prefix: prefix,
|
|
688
|
+
dl: cursor.clientX - rect.left,
|
|
689
|
+
dt: cursor.clientY - rect.top,
|
|
690
|
+
dr: cursor.clientX - rect.right,
|
|
691
|
+
db: cursor.clientY - rect.bottom,
|
|
692
|
+
rect: rect,
|
|
693
|
+
};
|
|
694
|
+
captureMouseOrTouch(e, this.onMouseMove.bind(this), undefined, captureData, prefix + "-resize");
|
|
695
|
+
} else if (data.draggable) {
|
|
696
|
+
ddMouseDown(e);
|
|
697
|
+
}
|
|
698
|
+
//e.stopPropagation();
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
onBackdropClick(e: React.MouseEvent) {
|
|
702
|
+
e.stopPropagation();
|
|
703
|
+
let { instance } = this.props;
|
|
704
|
+
let { widget } = instance;
|
|
705
|
+
|
|
706
|
+
if (widget.onBackdropClick) instance.invoke("onBackdropClick", e, instance);
|
|
707
|
+
|
|
708
|
+
if (widget.backdrop) {
|
|
709
|
+
if (instance.dismiss) instance.dismiss();
|
|
710
|
+
} else if (widget.modal) {
|
|
711
|
+
FocusManager.focus(this.el!);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
onMouseUp(e: React.MouseEvent | React.TouchEvent) {
|
|
716
|
+
ddMouseUp();
|
|
717
|
+
e.stopPropagation();
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
onMouseMove(e: MouseEvent, captureData: any) {
|
|
721
|
+
// handle dragging
|
|
722
|
+
let { instance } = this.props;
|
|
723
|
+
let { data, widget } = instance;
|
|
724
|
+
let detect = ddDetect(e);
|
|
725
|
+
if (data.draggable && detect) {
|
|
726
|
+
this.startMoveOperation(e);
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
if (captureData && captureData.prefix) {
|
|
731
|
+
let { prefix, rect, dl, dt, dr, db } = captureData;
|
|
732
|
+
let cursor = getCursorPos(e);
|
|
733
|
+
|
|
734
|
+
if (prefix.indexOf("w") != -1)
|
|
735
|
+
this.setCustomStyle({
|
|
736
|
+
left: cursor.clientX - dl + "px",
|
|
737
|
+
width: rect.right - cursor.clientX + dl + "px",
|
|
738
|
+
right: "auto",
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
if (prefix.indexOf("n") != -1)
|
|
742
|
+
this.setCustomStyle({
|
|
743
|
+
top: cursor.clientY - dt + "px",
|
|
744
|
+
height: rect.bottom - cursor.clientY + dt + "px",
|
|
745
|
+
bottom: "auto",
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
if (prefix.indexOf("e") != -1)
|
|
749
|
+
this.setCustomStyle({
|
|
750
|
+
width: cursor.clientX - dr - rect.left + "px",
|
|
751
|
+
left: `${rect.left}px`,
|
|
752
|
+
right: "auto",
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
if (prefix.indexOf("s") != -1)
|
|
756
|
+
this.setCustomStyle({
|
|
757
|
+
height: cursor.clientY - db - rect.top + "px",
|
|
758
|
+
top: `${rect.top}px`,
|
|
759
|
+
bottom: "auto",
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
if (prefix.indexOf("w") >= 0 || prefix.indexOf("n") >= 0) widget.handleMove(e, instance, this);
|
|
763
|
+
|
|
764
|
+
widget.handleResize(e, instance, this);
|
|
765
|
+
} else {
|
|
766
|
+
let prefix = this.getResizePrefix(e);
|
|
767
|
+
this.setCustomStyle({
|
|
768
|
+
cursor: prefix ? prefix + "-resize" : undefined,
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
startMoveOperation(e: MouseEvent | React.MouseEvent | React.TouchEvent) {
|
|
774
|
+
if (this.el && !this.getResizePrefix(e)) {
|
|
775
|
+
e.stopPropagation();
|
|
776
|
+
let rect = getTopLevelBoundingClientRect(this.el);
|
|
777
|
+
let cursor = getCursorPos(e);
|
|
778
|
+
let data = {
|
|
779
|
+
dx: cursor.clientX - rect.left,
|
|
780
|
+
dy: cursor.clientY - rect.top,
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
captureMouseOrTouch(
|
|
784
|
+
e,
|
|
785
|
+
this.onMove.bind(this),
|
|
786
|
+
undefined,
|
|
787
|
+
data,
|
|
788
|
+
getComputedStyle(e.target as HTMLElement).cursor,
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
onMove(e: MouseEvent, data: any) {
|
|
794
|
+
if (data) {
|
|
795
|
+
let cursor = getCursorPos(e);
|
|
796
|
+
e.preventDefault();
|
|
797
|
+
this.setCustomStyle({
|
|
798
|
+
left: cursor.clientX - data.dx + "px",
|
|
799
|
+
top: cursor.clientY - data.dy + "px",
|
|
800
|
+
right: "auto",
|
|
801
|
+
bottom: "auto",
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
let { instance } = this.props;
|
|
805
|
+
let { widget } = instance;
|
|
806
|
+
widget.handleMove(e, instance, this);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
onBeforeDismiss() {
|
|
811
|
+
let { instance } = this.props;
|
|
812
|
+
let { widget } = instance;
|
|
813
|
+
|
|
814
|
+
if (widget.overlayWillDismiss && widget.overlayWillDismiss(instance, this) === false) return false;
|
|
815
|
+
|
|
816
|
+
this.dismissed = true;
|
|
817
|
+
|
|
818
|
+
//this.el might be null if visible is set to false
|
|
819
|
+
if (this.el) {
|
|
820
|
+
this.el.className = this.getOverlayCssClass();
|
|
821
|
+
|
|
822
|
+
// if (widget.animate)
|
|
823
|
+
// this.setState({
|
|
824
|
+
// animated: false
|
|
825
|
+
// });
|
|
826
|
+
}
|
|
827
|
+
return true;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
componentDidMount() {
|
|
831
|
+
let { instance, subscribeToBeforeDismiss, parentEl } = this.props;
|
|
832
|
+
let { widget, data } = instance;
|
|
833
|
+
|
|
834
|
+
this.setZIndex(isNumber(data.zIndex) ? data.zIndex : ZIndexManager.next());
|
|
835
|
+
|
|
836
|
+
this.componentDidUpdate();
|
|
837
|
+
widget.overlayDidMount(instance, this);
|
|
838
|
+
|
|
839
|
+
if (this.containerEl) this.containerEl.style.removeProperty("display");
|
|
840
|
+
else if (parentEl) parentEl.style.removeProperty("display");
|
|
841
|
+
|
|
842
|
+
let childHasFocus = isSelfOrDescendant(this.el!, getActiveElement());
|
|
843
|
+
|
|
844
|
+
if (childHasFocus) oneFocusOut(this, this.el, this.onFocusOut.bind(this));
|
|
845
|
+
else {
|
|
846
|
+
if (!widget.autoFocusFirstChild || !FocusManager.focusFirstChild(this.el!))
|
|
847
|
+
if (widget.focusable && widget.autoFocus) FocusManager.focus(this.el!);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
instance.onBeforeDismiss = this.onBeforeDismiss.bind(this);
|
|
851
|
+
|
|
852
|
+
if (subscribeToBeforeDismiss) {
|
|
853
|
+
subscribeToBeforeDismiss(instance.onBeforeDismiss);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
if (widget.animate) {
|
|
857
|
+
setTimeout(() => {
|
|
858
|
+
if (!this.unmounting)
|
|
859
|
+
this.setState({
|
|
860
|
+
animated: true,
|
|
861
|
+
});
|
|
862
|
+
}, 0);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
if (widget.dismissOnPopState) {
|
|
866
|
+
this.onPopState = () => {
|
|
867
|
+
this.props.instance.dismiss?.();
|
|
868
|
+
};
|
|
869
|
+
window.addEventListener("popstate", this.onPopState);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
if (this.shadowEl)
|
|
873
|
+
this.unsubscribeWheelBlock = addEventListenerWithOptions(
|
|
874
|
+
this.shadowEl,
|
|
875
|
+
"wheel",
|
|
876
|
+
(e) => {
|
|
877
|
+
if (e.shiftKey || e.ctrlKey) return;
|
|
878
|
+
//check if there is a scrollable element within the shadow or overlay contents
|
|
879
|
+
//such that its scrollbar is not at the very end
|
|
880
|
+
let scrollAllowed = false;
|
|
881
|
+
closest(e.target as Element, (el) => {
|
|
882
|
+
if (
|
|
883
|
+
(e.deltaY > 0 && el.scrollTop < el.scrollHeight - el.clientHeight) ||
|
|
884
|
+
(e.deltaY < 0 && el.scrollTop > 0)
|
|
885
|
+
) {
|
|
886
|
+
scrollAllowed = true;
|
|
887
|
+
return true;
|
|
888
|
+
}
|
|
889
|
+
return el == e.currentTarget;
|
|
890
|
+
});
|
|
891
|
+
if (!scrollAllowed) e.preventDefault();
|
|
892
|
+
},
|
|
893
|
+
{ passive: false },
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
componentWillUnmount() {
|
|
898
|
+
if (this.onPopState) window.removeEventListener("popstate", this.onPopState);
|
|
899
|
+
|
|
900
|
+
if (this.unsubscribeWheelBlock) this.unsubscribeWheelBlock();
|
|
901
|
+
|
|
902
|
+
offFocusOut(this);
|
|
903
|
+
this.unmounting = true;
|
|
904
|
+
|
|
905
|
+
let { widget } = this.props.instance;
|
|
906
|
+
let { baseClass, CSS } = widget;
|
|
907
|
+
|
|
908
|
+
// //we didn't have a chance to call onBeforeDismiss
|
|
909
|
+
if (this.state.animated && this.el) {
|
|
910
|
+
this.el.className = this.getOverlayCssClass();
|
|
911
|
+
if (this.shadowEl)
|
|
912
|
+
this.shadowEl.className = CSS.element(baseClass, "shadow", {
|
|
913
|
+
animate: widget.animate,
|
|
914
|
+
"animate-leave": true,
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
widget.overlayWillUnmount(this.props.instance, this);
|
|
919
|
+
|
|
920
|
+
if (this.ownedEl) {
|
|
921
|
+
setTimeout(() => {
|
|
922
|
+
this.root?.unmount();
|
|
923
|
+
if (this.ownedEl?.parentNode) this.ownedEl.parentNode.removeChild(this.ownedEl);
|
|
924
|
+
this.ownedEl = null;
|
|
925
|
+
}, widget.destroyDelay);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
delete this.containerEl;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
setZIndex(zIndex: number) {
|
|
932
|
+
if (this.shadowEl) this.shadowEl.style.zIndex = zIndex.toString();
|
|
933
|
+
this.setCustomStyle({
|
|
934
|
+
zIndex: zIndex.toString(),
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
setCustomStyle(style: Partial<CSSStyleDeclaration>) {
|
|
939
|
+
Object.assign(this.customStyle, style);
|
|
940
|
+
if (this.el) Object.assign(this.el.style, this.customStyle);
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
getOverlayStyle() {
|
|
944
|
+
let { data } = this.props.instance;
|
|
945
|
+
return {
|
|
946
|
+
...data.style,
|
|
947
|
+
...this.customStyle,
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
setCSSState(mods: Record<string, boolean>) {
|
|
952
|
+
let m: Record<string, boolean> = { ...this.state.mods };
|
|
953
|
+
let changed = false;
|
|
954
|
+
for (let k in mods)
|
|
955
|
+
if (m[k] !== mods[k]) {
|
|
956
|
+
m[k] = mods[k];
|
|
957
|
+
changed = true;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
if (changed)
|
|
961
|
+
this.setState({
|
|
962
|
+
mods: mods,
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
getOverlayCssClass() {
|
|
967
|
+
let { data, widget } = this.props.instance;
|
|
968
|
+
let { CSS } = widget;
|
|
969
|
+
|
|
970
|
+
return (
|
|
971
|
+
CSS.expand(
|
|
972
|
+
data.classNames,
|
|
973
|
+
CSS.state({
|
|
974
|
+
...this.state.mods,
|
|
975
|
+
animated: this.state.animated && !this.unmounting && !this.dismissed,
|
|
976
|
+
"animate-enter": this.state.animated && !this.dismissed,
|
|
977
|
+
"animate-leave": widget.animate && this.dismissed,
|
|
978
|
+
}),
|
|
979
|
+
) ?? ""
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
overlayDidUpdate() {
|
|
984
|
+
if (this.el && !this.dismissed) {
|
|
985
|
+
let { widget } = this.props.instance;
|
|
986
|
+
widget.overlayDidUpdate(this.props.instance, this);
|
|
987
|
+
this.el.className = this.getOverlayCssClass();
|
|
988
|
+
Object.assign(this.el.style, this.getOverlayStyle());
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
componentDidUpdate() {
|
|
993
|
+
if (this.containerEl && !VDOM.DOM.createPortal) {
|
|
994
|
+
this.root = VDOM.DOM.createRoot(this.containerEl);
|
|
995
|
+
this.root.render(this.renderOverlay());
|
|
996
|
+
}
|
|
997
|
+
this.overlayDidUpdate();
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
interface OverlayBeaconProps {
|
|
1002
|
+
childrenFactory: (beacon: HTMLElement) => React.ReactNode;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
export interface OverlayBeaconState {
|
|
1006
|
+
beaconRendered?: boolean;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
export class OverlayBeacon extends VDOM.Component<OverlayBeaconProps, OverlayBeaconState> {
|
|
1010
|
+
el: HTMLElement | null;
|
|
1011
|
+
render() {
|
|
1012
|
+
return (
|
|
1013
|
+
<>
|
|
1014
|
+
<div
|
|
1015
|
+
ref={(el) => {
|
|
1016
|
+
this.el = el;
|
|
1017
|
+
}}
|
|
1018
|
+
style={{ position: "absolute", display: "none" }}
|
|
1019
|
+
/>
|
|
1020
|
+
{this.el && this.props.childrenFactory(this.el)}
|
|
1021
|
+
</>
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
componentDidMount(): void {
|
|
1026
|
+
this.setState({ beaconRendered: true });
|
|
1027
|
+
}
|
|
1028
|
+
}
|