@netless/telebox-insider 0.2.32 → 0.3.0-beta.1
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/dist/index.d.ts +69 -7
- package/dist/telebox-insider.cjs.js +386 -53
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +386 -53
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +1 -1
- package/src/TeleBox/constants.ts +2 -0
- package/src/TeleBox/index.ts +76 -19
- package/src/TeleBox/typings.ts +8 -0
- package/src/TeleBoxManager/MaxTitleBar/index.ts +80 -24
- package/src/TeleBoxManager/constants.ts +2 -0
- package/src/TeleBoxManager/index.ts +264 -21
- package/src/TeleBoxManager/typings.ts +6 -2
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +22 -1
- package/src/TeleTitleBar/typings.ts +4 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EventEmitter from "eventemitter3";
|
|
2
2
|
import shallowequal from "shallowequal";
|
|
3
3
|
import type {
|
|
4
|
+
NotMinimizedBoxState,
|
|
4
5
|
TeleBoxConfig,
|
|
5
6
|
TeleBoxRect,
|
|
6
7
|
TeleBoxState,
|
|
@@ -16,7 +17,7 @@ import type {
|
|
|
16
17
|
TeleBoxManagerQueryConfig,
|
|
17
18
|
TeleBoxManagerUpdateConfig,
|
|
18
19
|
} from "./typings";
|
|
19
|
-
import { MaxTitleBar } from "./MaxTitleBar";
|
|
20
|
+
import { MaxTitleBar, MaxTitleBarTeleBox } from "./MaxTitleBar";
|
|
20
21
|
import {
|
|
21
22
|
TeleBoxColorScheme,
|
|
22
23
|
TELE_BOX_COLOR_SCHEME,
|
|
@@ -46,6 +47,9 @@ type ValConfig = {
|
|
|
46
47
|
export interface TeleBoxManager extends ValEnhancedResult<ValConfig> {}
|
|
47
48
|
|
|
48
49
|
export class TeleBoxManager {
|
|
50
|
+
private boxesStatus$: Map<string, TeleBoxState>;
|
|
51
|
+
private lastNotMinimizedBoxesStatus$: Map<string, NotMinimizedBoxState>;
|
|
52
|
+
|
|
49
53
|
public constructor({
|
|
50
54
|
root = document.body,
|
|
51
55
|
prefersColorScheme = TELE_BOX_COLOR_SCHEME.Light,
|
|
@@ -71,14 +75,18 @@ export class TeleBoxManager {
|
|
|
71
75
|
this.boxes$ = createVal<TeleBox[]>([]);
|
|
72
76
|
this.topBox$ = this.boxes$.derive((boxes) => {
|
|
73
77
|
if (boxes.length > 0) {
|
|
74
|
-
const topBox = boxes.reduce((topBox, box) =>
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
const topBox = boxes.reduce((topBox, box) => {
|
|
79
|
+
if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized) {
|
|
80
|
+
return topBox;
|
|
81
|
+
}
|
|
82
|
+
return topBox.zIndex > box.zIndex ? topBox : box;
|
|
83
|
+
});
|
|
77
84
|
return topBox;
|
|
78
85
|
}
|
|
79
86
|
return;
|
|
80
87
|
});
|
|
81
|
-
|
|
88
|
+
this.boxesStatus$ = new Map<string, TeleBoxState>();
|
|
89
|
+
this.lastNotMinimizedBoxesStatus$ = new Map<string, NotMinimizedBoxState>();
|
|
82
90
|
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
|
|
83
91
|
const prefersDark$ = createVal(false);
|
|
84
92
|
|
|
@@ -184,6 +192,16 @@ export class TeleBoxManager {
|
|
|
184
192
|
this._sideEffect.add(() => {
|
|
185
193
|
collector.onClick = () => {
|
|
186
194
|
if (!readonly$.value) {
|
|
195
|
+
if (this.hasMinimizedBox()) {
|
|
196
|
+
this.getAllMinimizedBoxes().forEach((box) => {
|
|
197
|
+
const lastNotMinimizedBoxStatus = box.lastNotMinimizedBoxStatus;
|
|
198
|
+
if (lastNotMinimizedBoxStatus) {
|
|
199
|
+
this.setBoxStatus(box.id, lastNotMinimizedBoxStatus);
|
|
200
|
+
} else {
|
|
201
|
+
this.setBoxStatus(box.id, TELE_BOX_STATE.Normal);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
187
205
|
minimized$.setValue(false);
|
|
188
206
|
}
|
|
189
207
|
};
|
|
@@ -191,6 +209,7 @@ export class TeleBoxManager {
|
|
|
191
209
|
}, "collect-onClick");
|
|
192
210
|
}
|
|
193
211
|
});
|
|
212
|
+
|
|
194
213
|
readonly$.subscribe((readonly) =>
|
|
195
214
|
collector$.value?.setReadonly(readonly)
|
|
196
215
|
);
|
|
@@ -198,7 +217,7 @@ export class TeleBoxManager {
|
|
|
198
217
|
collector$.value?.setDarkMode(darkMode);
|
|
199
218
|
});
|
|
200
219
|
|
|
201
|
-
|
|
220
|
+
this._calcCollectorRect = (): TeleBoxRect | undefined => {
|
|
202
221
|
if (collector$.value?.$collector) {
|
|
203
222
|
const { x, y, width, height } =
|
|
204
223
|
collector$.value.$collector.getBoundingClientRect();
|
|
@@ -214,7 +233,7 @@ export class TeleBoxManager {
|
|
|
214
233
|
};
|
|
215
234
|
|
|
216
235
|
const collectorRect$ = createVal(
|
|
217
|
-
minimized$.value ?
|
|
236
|
+
minimized$.value ? this._calcCollectorRect() : void 0
|
|
218
237
|
);
|
|
219
238
|
collectorRect$.subscribe((collectorRect, _, skipUpdate) => {
|
|
220
239
|
this.boxes.forEach((box) => {
|
|
@@ -227,7 +246,7 @@ export class TeleBoxManager {
|
|
|
227
246
|
|
|
228
247
|
if (minimized) {
|
|
229
248
|
if (collector$.value?.$collector) {
|
|
230
|
-
collectorRect$.setValue(
|
|
249
|
+
collectorRect$.setValue(this._calcCollectorRect());
|
|
231
250
|
} else if (import.meta.env.DEV) {
|
|
232
251
|
console.warn("No collector for minimized boxes.");
|
|
233
252
|
}
|
|
@@ -267,7 +286,9 @@ export class TeleBoxManager {
|
|
|
267
286
|
const box = this.getBox(id);
|
|
268
287
|
if (box) {
|
|
269
288
|
this.focusBox(box);
|
|
270
|
-
|
|
289
|
+
if ((box.boxStatus && box.boxStatus !== TELE_BOX_STATE.Maximized) || !box.boxStatus) {
|
|
290
|
+
this.makeBoxTop(box);
|
|
291
|
+
}
|
|
271
292
|
return;
|
|
272
293
|
}
|
|
273
294
|
}
|
|
@@ -294,19 +315,35 @@ export class TeleBoxManager {
|
|
|
294
315
|
state: state$.value,
|
|
295
316
|
boxes: this.boxes$.value,
|
|
296
317
|
containerRect: containerRect$.value,
|
|
318
|
+
boxesStatus: this.boxesStatus$,
|
|
297
319
|
onEvent: (event): void => {
|
|
298
320
|
switch (event.type) {
|
|
299
321
|
case TELE_BOX_DELEGATE_EVENT.Maximize: {
|
|
300
|
-
|
|
322
|
+
if (this.hasBoxesStatus() && this.maxTitleBar.focusedBox?.id) {
|
|
323
|
+
this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Normal);
|
|
324
|
+
this.makeMaximizedTopBoxFocus();
|
|
325
|
+
} else {
|
|
326
|
+
maximized$.setValue(!maximized$.value);
|
|
327
|
+
}
|
|
301
328
|
break;
|
|
302
329
|
}
|
|
303
330
|
case TELE_BOX_DELEGATE_EVENT.Minimize: {
|
|
304
|
-
|
|
331
|
+
if (this.hasBoxesStatus() && this.maxTitleBar.focusedBox?.id) {
|
|
332
|
+
this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Minimized);
|
|
333
|
+
this.makeMaximizedTopBoxFocus();
|
|
334
|
+
} else {
|
|
335
|
+
minimized$.setValue(true);
|
|
336
|
+
}
|
|
305
337
|
break;
|
|
306
338
|
}
|
|
307
339
|
case TELE_BOX_EVENT.Close: {
|
|
308
|
-
this.
|
|
309
|
-
|
|
340
|
+
if (this.hasBoxesStatus() && this.maxTitleBar.focusedBox?.id) {
|
|
341
|
+
this.remove(this.maxTitleBar.focusedBox.id);
|
|
342
|
+
this.makeMaximizedTopBoxFocus();
|
|
343
|
+
} else {
|
|
344
|
+
this.removeTopBox();
|
|
345
|
+
this.focusTopBox();
|
|
346
|
+
}
|
|
310
347
|
break;
|
|
311
348
|
}
|
|
312
349
|
default: {
|
|
@@ -361,6 +398,8 @@ export class TeleBoxManager {
|
|
|
361
398
|
|
|
362
399
|
public _darkMode$: Val<boolean, boolean>;
|
|
363
400
|
|
|
401
|
+
public _calcCollectorRect: () => TeleBoxRect | undefined;
|
|
402
|
+
|
|
364
403
|
public get darkMode(): boolean {
|
|
365
404
|
return this._darkMode$.value;
|
|
366
405
|
}
|
|
@@ -393,6 +432,96 @@ export class TeleBoxManager {
|
|
|
393
432
|
return this;
|
|
394
433
|
}
|
|
395
434
|
|
|
435
|
+
public setBoxStatus(boxId: string, boxStatus?: TeleBoxState, skipUpdate = false): void {
|
|
436
|
+
const boxesStatus = this.boxesStatus$;
|
|
437
|
+
if (boxStatus) {
|
|
438
|
+
const oldBoxStatus = boxesStatus.get(boxId);
|
|
439
|
+
boxesStatus.set(boxId, boxStatus);
|
|
440
|
+
if (boxStatus === TELE_BOX_STATE.Minimized && oldBoxStatus !== TELE_BOX_STATE.Minimized) {
|
|
441
|
+
this.setLastNotMinimizedBoxStatus(boxId, oldBoxStatus, skipUpdate);
|
|
442
|
+
} else if (oldBoxStatus === TELE_BOX_STATE.Minimized && boxStatus !== TELE_BOX_STATE.Minimized) {
|
|
443
|
+
this.setLastNotMinimizedBoxStatus(boxId, undefined, skipUpdate);
|
|
444
|
+
}
|
|
445
|
+
} else {
|
|
446
|
+
boxesStatus.delete(boxId);
|
|
447
|
+
this.setLastNotMinimizedBoxStatus(boxId, undefined, skipUpdate);
|
|
448
|
+
}
|
|
449
|
+
this.setBoxesStatus(boxesStatus, skipUpdate);
|
|
450
|
+
if (!skipUpdate) {
|
|
451
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.BoxStatus, { id: boxId, boxStatus});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
private setBoxesStatus(boxesStatus: Map<string, TeleBoxState>, skipUpdate = false): void {
|
|
456
|
+
let topBox:TeleBox | undefined;
|
|
457
|
+
const topBoxId = this.topBox?.id;
|
|
458
|
+
let hasMinimizedBox = false;
|
|
459
|
+
this.boxes.forEach((box) => {
|
|
460
|
+
const boxStatus = boxesStatus.get(box.id);
|
|
461
|
+
if (boxStatus) {
|
|
462
|
+
if (boxStatus !== TELE_BOX_STATE.Minimized && box.zIndex > (topBox?.zIndex ?? 0)) {
|
|
463
|
+
topBox = box;
|
|
464
|
+
}
|
|
465
|
+
box.setBoxStatus(boxStatus, skipUpdate);
|
|
466
|
+
if (boxStatus === TELE_BOX_STATE.Minimized) {
|
|
467
|
+
hasMinimizedBox = true;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
if (hasMinimizedBox) {
|
|
472
|
+
this.collector?.setVisible(true);
|
|
473
|
+
if (this.collector?.$collector) {
|
|
474
|
+
this.setCollectorRect(this._calcCollectorRect());
|
|
475
|
+
} else if (import.meta.env.DEV) {
|
|
476
|
+
console.warn("No collector for minimized boxes.");
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
this.collector?.setVisible(false);
|
|
480
|
+
}
|
|
481
|
+
if (topBox && topBoxId !== topBox.id) {
|
|
482
|
+
this.makeBoxTop(topBox, skipUpdate);
|
|
483
|
+
this.focusTopBox();
|
|
484
|
+
this.topBox$.setValue(topBox);
|
|
485
|
+
}
|
|
486
|
+
if (this.maxTitleBar) {
|
|
487
|
+
this.maxTitleBar.setBoxesStatus(boxesStatus);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
public hasBoxesStatus(): boolean {
|
|
492
|
+
return this.boxesStatus$.size > 0;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
public hasMinimizedBox(): boolean {
|
|
496
|
+
return this.boxes.some((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
public setLastNotMinimizedBoxStatus(boxId: string, lastNotMinimizedBoxStatus?: NotMinimizedBoxState, skipUpdate = false): void {
|
|
500
|
+
const boxesStatus = this.lastNotMinimizedBoxesStatus$;
|
|
501
|
+
if (lastNotMinimizedBoxStatus) {
|
|
502
|
+
boxesStatus.set(boxId, lastNotMinimizedBoxStatus);
|
|
503
|
+
} else {
|
|
504
|
+
boxesStatus.delete(boxId);
|
|
505
|
+
}
|
|
506
|
+
this.setLastNotMinimizedBoxesStatus(boxesStatus, skipUpdate);
|
|
507
|
+
if (!skipUpdate) {
|
|
508
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.LastNotMinimizedBoxStatus, { id: boxId, boxStatus:lastNotMinimizedBoxStatus});
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
private setLastNotMinimizedBoxesStatus(lastNotMinimizedBoxesStatus: Map<string, NotMinimizedBoxState>, skipUpdate = false): void {
|
|
513
|
+
this.boxes.forEach((box) => {
|
|
514
|
+
const boxStatus = lastNotMinimizedBoxesStatus.get(box.id);
|
|
515
|
+
if (boxStatus) {
|
|
516
|
+
box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
private getAllMinimizedBoxes(): ReadonlyArray<TeleBox> {
|
|
522
|
+
return this.boxes.filter((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized);
|
|
523
|
+
}
|
|
524
|
+
|
|
396
525
|
public create(
|
|
397
526
|
config: TeleBoxManagerCreateConfig = {},
|
|
398
527
|
smartPosition = true
|
|
@@ -422,11 +551,41 @@ export class TeleBoxManager {
|
|
|
422
551
|
|
|
423
552
|
this.boxes$.setValue([...this.boxes, box]);
|
|
424
553
|
|
|
554
|
+
if (box.boxStatus) {
|
|
555
|
+
this.setBoxStatus(box.id, box.boxStatus, true);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (box._lastNotMinimizedBoxStatus$.value) {
|
|
559
|
+
this.setLastNotMinimizedBoxStatus(box.id, box._lastNotMinimizedBoxStatus$.value, true);
|
|
560
|
+
}
|
|
561
|
+
|
|
425
562
|
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
|
|
426
|
-
|
|
563
|
+
if (box.boxStatus) {
|
|
564
|
+
if (box.boxStatus === TELE_BOX_STATE.Maximized) {
|
|
565
|
+
this.setBoxStatus(box.id, TELE_BOX_STATE.Normal);
|
|
566
|
+
} else {
|
|
567
|
+
this.boxes.forEach((box) => {
|
|
568
|
+
if (box.boxStatus === TELE_BOX_STATE.Normal) {
|
|
569
|
+
this.setBoxStatus(box.id, TELE_BOX_STATE.Maximized);
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
this.makeMaximizedTopBoxFocus();
|
|
574
|
+
} else {
|
|
575
|
+
this.setMaximized(!this.maximized);
|
|
576
|
+
}
|
|
577
|
+
|
|
427
578
|
});
|
|
428
579
|
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Minimize, () => {
|
|
429
|
-
|
|
580
|
+
if (box.boxStatus) {
|
|
581
|
+
const oldBoxStatus = box.boxStatus;
|
|
582
|
+
this.setBoxStatus(box.id, TELE_BOX_STATE.Minimized);
|
|
583
|
+
if (oldBoxStatus === TELE_BOX_STATE.Maximized) {
|
|
584
|
+
this.makeMaximizedTopBoxFocus();
|
|
585
|
+
}
|
|
586
|
+
} else{
|
|
587
|
+
this.setMinimized(true);
|
|
588
|
+
}
|
|
430
589
|
});
|
|
431
590
|
box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
|
|
432
591
|
this.remove(box);
|
|
@@ -459,9 +618,12 @@ export class TeleBoxManager {
|
|
|
459
618
|
});
|
|
460
619
|
box._zIndex$.reaction((_, __, skipUpdate) => {
|
|
461
620
|
if (this.boxes.length > 0) {
|
|
462
|
-
const topBox = this.boxes.reduce((topBox, box) =>
|
|
463
|
-
|
|
464
|
-
|
|
621
|
+
const topBox = this.boxes.reduce((topBox, box) => {
|
|
622
|
+
if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized) {
|
|
623
|
+
return topBox;
|
|
624
|
+
}
|
|
625
|
+
return topBox.zIndex > box.zIndex ? topBox : box;
|
|
626
|
+
});
|
|
465
627
|
this.topBox$.setValue(topBox);
|
|
466
628
|
}
|
|
467
629
|
if (!skipUpdate) {
|
|
@@ -511,6 +673,11 @@ export class TeleBoxManager {
|
|
|
511
673
|
boxOrID: string | TeleBox,
|
|
512
674
|
skipUpdate = false
|
|
513
675
|
): ReadonlyTeleBox | undefined {
|
|
676
|
+
const box = this.getBox(boxOrID);
|
|
677
|
+
if (box) {
|
|
678
|
+
this.setBoxStatus(box.id, undefined, skipUpdate);
|
|
679
|
+
this.setLastNotMinimizedBoxStatus(box.id, undefined, skipUpdate);
|
|
680
|
+
}
|
|
514
681
|
const index = this.getBoxIndex(boxOrID);
|
|
515
682
|
if (index >= 0) {
|
|
516
683
|
const boxes = this.boxes.slice();
|
|
@@ -540,6 +707,8 @@ export class TeleBoxManager {
|
|
|
540
707
|
const deletedBoxes = this.boxes$.value;
|
|
541
708
|
this.boxes$.setValue([]);
|
|
542
709
|
deletedBoxes.forEach((box) => box.destroy());
|
|
710
|
+
this.boxesStatus$.clear();
|
|
711
|
+
this.lastNotMinimizedBoxesStatus$.clear();
|
|
543
712
|
if (!skipUpdate) {
|
|
544
713
|
if (this.boxes.length <= 0) {
|
|
545
714
|
this.setMaximized(false);
|
|
@@ -587,7 +756,11 @@ export class TeleBoxManager {
|
|
|
587
756
|
this.blurBox(box, skipUpdate);
|
|
588
757
|
}
|
|
589
758
|
});
|
|
590
|
-
this.maxTitleBar.
|
|
759
|
+
if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
|
|
760
|
+
this.makeMaximizedBoxFocus(targetBox);
|
|
761
|
+
} else {
|
|
762
|
+
this.maxTitleBar.focusBox(targetBox);
|
|
763
|
+
}
|
|
591
764
|
}
|
|
592
765
|
}
|
|
593
766
|
|
|
@@ -607,7 +780,11 @@ export class TeleBoxManager {
|
|
|
607
780
|
}
|
|
608
781
|
}
|
|
609
782
|
if (this.maxTitleBar.focusedBox === targetBox) {
|
|
610
|
-
this.maxTitleBar.
|
|
783
|
+
if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
|
|
784
|
+
this.makeMaximizedTopBoxFocus();
|
|
785
|
+
} else {
|
|
786
|
+
this.maxTitleBar.focusBox();
|
|
787
|
+
}
|
|
611
788
|
}
|
|
612
789
|
}
|
|
613
790
|
}
|
|
@@ -622,7 +799,11 @@ export class TeleBoxManager {
|
|
|
622
799
|
}
|
|
623
800
|
});
|
|
624
801
|
if (this.maxTitleBar.focusedBox) {
|
|
625
|
-
this.maxTitleBar.
|
|
802
|
+
if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
|
|
803
|
+
this.makeMaximizedBoxBlur();
|
|
804
|
+
} else {
|
|
805
|
+
this.maxTitleBar.focusBox();
|
|
806
|
+
}
|
|
626
807
|
}
|
|
627
808
|
}
|
|
628
809
|
|
|
@@ -691,6 +872,12 @@ export class TeleBoxManager {
|
|
|
691
872
|
if (config.footer != null) {
|
|
692
873
|
box.mountFooter(config.footer);
|
|
693
874
|
}
|
|
875
|
+
if (config.boxStatus) {
|
|
876
|
+
this.setBoxStatus(box.id, config.boxStatus, skipUpdate);
|
|
877
|
+
}
|
|
878
|
+
if (config.lastNotMinimizedBoxStatus) {
|
|
879
|
+
this.setLastNotMinimizedBoxStatus(box.id, config.lastNotMinimizedBoxStatus, skipUpdate);
|
|
880
|
+
}
|
|
694
881
|
}
|
|
695
882
|
|
|
696
883
|
protected smartPosition(config: TeleBoxConfig = {}): TeleBoxConfig {
|
|
@@ -736,11 +923,67 @@ export class TeleBoxManager {
|
|
|
736
923
|
protected makeBoxTop(box: TeleBox, skipUpdate = false): void {
|
|
737
924
|
if (this.topBox) {
|
|
738
925
|
if (box !== this.topBox) {
|
|
926
|
+
const currentBoxZIndex = box.zIndex;
|
|
927
|
+
const addZIndex = this.topBox.zIndex + 1 - box.zIndex;
|
|
739
928
|
box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
|
|
929
|
+
this.makeTopBoxEffect(box.id, addZIndex, currentBoxZIndex, skipUpdate);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
protected makeMaximizedTopBoxFocus(): void {
|
|
935
|
+
let maximizedBox: MaxTitleBarTeleBox | undefined;
|
|
936
|
+
if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
|
|
937
|
+
maximizedBox = this.maxTitleBar.MaximizedBoxes.reduce((topBox, currentBox) => {
|
|
938
|
+
if (!topBox) {
|
|
939
|
+
return currentBox;
|
|
940
|
+
}
|
|
941
|
+
return topBox.zIndex > currentBox.zIndex ? topBox : currentBox;
|
|
942
|
+
});
|
|
943
|
+
if (maximizedBox) {
|
|
944
|
+
this.maxTitleBar.focusBox(maximizedBox);
|
|
740
945
|
}
|
|
741
946
|
}
|
|
742
947
|
}
|
|
743
948
|
|
|
949
|
+
private makeTopBoxEffect(boxId: string, addZIndex: number, currentZIndex: number, skipUpdate = false): void {
|
|
950
|
+
if (this.hasBoxesStatus() && this.hasMinimizedBox()) {
|
|
951
|
+
this.boxes.forEach((b) => {
|
|
952
|
+
if (b.boxStatus && b.id !== boxId && b.zIndex >= currentZIndex) {
|
|
953
|
+
b.setZIndex(b.zIndex + addZIndex, skipUpdate);
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
protected makeMaximizedBoxFocus(maximizedBox: MaxTitleBarTeleBox, skipUpdate = false): void {
|
|
960
|
+
if (this.maxTitleBar.hasMaximizedBoxInStatus() && this.maxTitleBar.MaximizedBoxes.find((box) => box.id === maximizedBox.id)) {
|
|
961
|
+
const currentZIndex = maximizedBox.zIndex;
|
|
962
|
+
const currentMaximizedTopBox = this.maxTitleBar.MaximizedBoxes.reduce((topBox, box) => {
|
|
963
|
+
if (!topBox) {
|
|
964
|
+
return box;
|
|
965
|
+
}
|
|
966
|
+
return topBox.zIndex > box.zIndex ? topBox : box;
|
|
967
|
+
});
|
|
968
|
+
if (currentMaximizedTopBox !== maximizedBox) {
|
|
969
|
+
const addZIndex = currentMaximizedTopBox.zIndex - currentZIndex + 1;
|
|
970
|
+
this.boxes.forEach((box) => {
|
|
971
|
+
if (this.maxTitleBar.MaximizedBoxes.find((b) => b.id === box.id && b.id !== maximizedBox.id)) {
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
if (box.zIndex >= currentZIndex) {
|
|
975
|
+
box.setZIndex(box.zIndex + addZIndex, skipUpdate);
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
this.maxTitleBar.focusBox(maximizedBox);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
protected makeMaximizedBoxBlur(): void {
|
|
984
|
+
this.maxTitleBar.focusBox();
|
|
985
|
+
}
|
|
986
|
+
|
|
744
987
|
protected getBoxIndex(boxOrID: TeleBox | string): number {
|
|
745
988
|
return typeof boxOrID === "string"
|
|
746
989
|
? this.boxes.findIndex((box) => box.id === boxOrID)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type EventEmitter from "eventemitter3";
|
|
2
2
|
import { TeleBoxColorScheme } from "..";
|
|
3
3
|
import type { ReadonlyTeleBox, TeleBoxState } from "../TeleBox";
|
|
4
|
-
import type { TeleBoxConfig } from "../TeleBox/typings";
|
|
4
|
+
import type { NotMinimizedBoxState, TeleBoxConfig } from "../TeleBox/typings";
|
|
5
5
|
import type { TeleBoxCollector } from "../TeleBoxCollector";
|
|
6
6
|
import type { TELE_BOX_MANAGER_EVENT } from "./constants";
|
|
7
7
|
|
|
@@ -34,7 +34,9 @@ type TeleBoxManagerBoxConfigBaseProps =
|
|
|
34
34
|
| "resizable"
|
|
35
35
|
| "draggable"
|
|
36
36
|
| "fixRatio"
|
|
37
|
-
| "zIndex"
|
|
37
|
+
| "zIndex"
|
|
38
|
+
| "boxStatus"
|
|
39
|
+
| "lastNotMinimizedBoxStatus";
|
|
38
40
|
|
|
39
41
|
export type TeleBoxManagerCreateConfig = Pick<
|
|
40
42
|
TeleBoxConfig,
|
|
@@ -71,6 +73,8 @@ export type TeleBoxManagerEventConfig = CheckTeleBoxManagerConfig<{
|
|
|
71
73
|
z_index: [ReadonlyTeleBox];
|
|
72
74
|
prefers_color_scheme: [TeleBoxColorScheme];
|
|
73
75
|
dark_mode: [boolean];
|
|
76
|
+
box_status: [{ id: string, boxStatus?: TeleBoxState }];
|
|
77
|
+
last_not_minimized_box_status: [{ id: string, boxStatus?: NotMinimizedBoxState }];
|
|
74
78
|
}>;
|
|
75
79
|
|
|
76
80
|
export type TeleBoxManagerEvent = keyof TeleBoxManagerEventConfig;
|
|
@@ -22,9 +22,11 @@ export type DefaultTitleBarButton = TeleTitleBarEvent & {
|
|
|
22
22
|
|
|
23
23
|
export interface DefaultTitleBarConfig extends TeleTitleBarConfig {
|
|
24
24
|
buttons?: ReadonlyArray<DefaultTitleBarButton>;
|
|
25
|
+
boxStatus?: TeleBoxState;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export class DefaultTitleBar implements TeleTitleBar {
|
|
29
|
+
protected boxStatus?: TeleBoxState;
|
|
28
30
|
public constructor({
|
|
29
31
|
readonly = false,
|
|
30
32
|
title,
|
|
@@ -33,6 +35,7 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
33
35
|
onDragStart,
|
|
34
36
|
namespace = "telebox",
|
|
35
37
|
state = TELE_BOX_STATE.Normal,
|
|
38
|
+
boxStatus,
|
|
36
39
|
}: DefaultTitleBarConfig = {}) {
|
|
37
40
|
this.readonly = readonly;
|
|
38
41
|
this.onEvent = onEvent;
|
|
@@ -40,6 +43,7 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
40
43
|
this.namespace = namespace;
|
|
41
44
|
this.title = title;
|
|
42
45
|
this.state = state;
|
|
46
|
+
this.boxStatus = boxStatus;
|
|
43
47
|
|
|
44
48
|
this.buttons = buttons || [
|
|
45
49
|
{
|
|
@@ -91,12 +95,29 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
|
|
98
|
+
public setBoxStatus(boxStatus?: TeleBoxState): void {
|
|
99
|
+
if (this.boxStatus !== boxStatus) {
|
|
100
|
+
this.boxStatus = boxStatus;
|
|
101
|
+
if (boxStatus) {
|
|
102
|
+
this.buttons.forEach((btn, i) => {
|
|
103
|
+
if (btn.isActive) {
|
|
104
|
+
this.$btns[i].classList.toggle(
|
|
105
|
+
"is-active",
|
|
106
|
+
btn.isActive(boxStatus)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
94
114
|
public setReadonly(readonly: boolean): void {
|
|
95
115
|
if (this.readonly !== readonly) {
|
|
96
116
|
this.readonly = readonly;
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
|
|
120
|
+
|
|
100
121
|
public render(): HTMLElement {
|
|
101
122
|
if (!this.$titleBar) {
|
|
102
123
|
this.$titleBar = document.createElement("div");
|
|
@@ -131,7 +152,7 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
131
152
|
$btn.dataset.teleTitleBarNoDblClick = "true";
|
|
132
153
|
|
|
133
154
|
if (isActive) {
|
|
134
|
-
$btn.classList.toggle("is-active", isActive(this.state));
|
|
155
|
+
$btn.classList.toggle("is-active", isActive(this.boxStatus || this.state));
|
|
135
156
|
}
|
|
136
157
|
|
|
137
158
|
this.$btns.push($btn);
|
|
@@ -3,8 +3,8 @@ import type { TeleBoxDelegateEventConfig, TeleBoxState } from "../TeleBox";
|
|
|
3
3
|
export type TeleTitleBarEvent<U = keyof TeleBoxDelegateEventConfig> =
|
|
4
4
|
U extends keyof TeleBoxDelegateEventConfig
|
|
5
5
|
? TeleBoxDelegateEventConfig[U] extends void
|
|
6
|
-
? { type: U; value?: TeleBoxDelegateEventConfig[U] }
|
|
7
|
-
: { type: U; value: TeleBoxDelegateEventConfig[U] }
|
|
6
|
+
? { type: U; value?: TeleBoxDelegateEventConfig[U]; boxId?: string }
|
|
7
|
+
: { type: U; value: TeleBoxDelegateEventConfig[U]; boxId?: string }
|
|
8
8
|
: never;
|
|
9
9
|
|
|
10
10
|
export interface TeleTitleBarConfig {
|
|
@@ -26,4 +26,6 @@ export interface TeleTitleBar {
|
|
|
26
26
|
render(): HTMLElement;
|
|
27
27
|
|
|
28
28
|
destroy(): void;
|
|
29
|
+
|
|
30
|
+
setBoxStatus(boxStatus?: TeleBoxState): void;
|
|
29
31
|
}
|