@netless/telebox-insider 0.3.0 → 0.3.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.
@@ -43,6 +43,7 @@ type ValConfig = {
43
43
  readonly: Val<boolean, boolean>;
44
44
  minimized: Val<boolean, boolean>;
45
45
  maximized: Val<boolean, boolean>;
46
+ forceMaximized: Val<boolean, boolean>;
46
47
  fence: Val<boolean, boolean>;
47
48
  };
48
49
  export interface TeleBoxManager extends ValEnhancedResult<ValConfig> {}
@@ -57,12 +58,12 @@ export class TeleBoxManager {
57
58
  skipUpdate: boolean;
58
59
  timer: number | undefined;
59
60
  resolve?: (skipUpdate: boolean) => void;
60
- }
61
+ };
61
62
  protected effectLastNotMinimizedBoxStatusTimer?: {
62
63
  skipUpdate: boolean;
63
64
  timer: number | undefined;
64
65
  resolve?: (skipUpdate: boolean) => void;
65
- }
66
+ };
66
67
 
67
68
  public constructor({
68
69
  root = document.body,
@@ -79,6 +80,7 @@ export class TeleBoxManager {
79
80
  collector,
80
81
  namespace = "telebox",
81
82
  readonly = false,
83
+ forceMaximized = false,
82
84
  useBoxesStatus = false,
83
85
  }: TeleBoxManagerConfig = {}) {
84
86
  this._sideEffect = new SideEffectManager();
@@ -96,7 +98,10 @@ export class TeleBoxManager {
96
98
  if (box.forceTop) {
97
99
  return topBox;
98
100
  }
99
- if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized) {
101
+ if (
102
+ box.boxStatus &&
103
+ box.boxStatus === TELE_BOX_STATE.Minimized
104
+ ) {
100
105
  return topBox;
101
106
  }
102
107
  if (!topBox) {
@@ -104,13 +109,16 @@ export class TeleBoxManager {
104
109
  return topBox;
105
110
  }
106
111
  return topBox.zIndex > box.zIndex ? topBox : box;
107
- }, currentTopBox as (TeleBox | undefined));
112
+ }, currentTopBox as TeleBox | undefined);
108
113
  return topBox;
109
114
  }
110
115
  return;
111
116
  });
112
117
  this.boxesStatus$ = new Map<string, TeleBoxState>();
113
- this.lastNotMinimizedBoxesStatus$ = new Map<string, NotMinimizedBoxState>();
118
+ this.lastNotMinimizedBoxesStatus$ = new Map<
119
+ string,
120
+ NotMinimizedBoxState
121
+ >();
114
122
  const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
115
123
  const prefersDark$ = createVal(false);
116
124
 
@@ -159,7 +167,19 @@ export class TeleBoxManager {
159
167
 
160
168
  const minimized$ = createVal(minimized);
161
169
 
162
- const maximized$ = createVal(maximized);
170
+ const forceMaximized$ = createVal(forceMaximized);
171
+ const maximized$ = createVal(
172
+ maximized || forceMaximized,
173
+ (next, previous) =>
174
+ next === previous || (forceMaximized$.value && !next)
175
+ );
176
+ forceMaximized$.reaction((forceMaximized, _, skipUpdate) => {
177
+ if (forceMaximized) maximized$.setValue(true, skipUpdate);
178
+ this.boxes.forEach((box) =>
179
+ box.setForceMaximized(forceMaximized, skipUpdate)
180
+ );
181
+ this.maxTitleBar?.setForceMaximized?.(forceMaximized);
182
+ });
163
183
  maximized$.reaction((maximized, _, skipUpdate) => {
164
184
  this.boxes.forEach((box) =>
165
185
  box.setMaximized(maximized, skipUpdate)
@@ -205,7 +225,7 @@ export class TeleBoxManager {
205
225
  new TeleBoxCollector({
206
226
  visible: minimized,
207
227
  readonly: readonly,
208
- namespace
228
+ namespace,
209
229
  }).mount(root)
210
230
  );
211
231
  collector$.subscribe((collector) => {
@@ -313,27 +333,44 @@ export class TeleBoxManager {
313
333
  if (id) {
314
334
  const box = this.getBox(id);
315
335
  if (box) {
336
+ if (this.lazyFocusRequestHandler?.(box.id)) return;
316
337
  if (!this.useBoxesStatus) {
317
338
  this.makeBoxTop(box);
318
339
  } else {
319
- if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Normal) {
320
- const maxNormalBoxZIndex = this.getMaxNormalBoxZIndex();
340
+ if (
341
+ box.boxStatus &&
342
+ box.boxStatus === TELE_BOX_STATE.Normal
343
+ ) {
344
+ const maxNormalBoxZIndex =
345
+ this.getMaxNormalBoxZIndex();
321
346
  if (maxNormalBoxZIndex > box.zIndex) {
322
- this.setBox(box, {
323
- zIndex: maxNormalBoxZIndex + 1
324
- }, false);
347
+ this.setBox(
348
+ box,
349
+ {
350
+ zIndex: maxNormalBoxZIndex + 1,
351
+ },
352
+ false
353
+ );
325
354
  }
326
- } else if(box.boxStatus && box.boxStatus === TELE_BOX_STATE.Maximized){
327
- const maxMaximizedBoxZIndex = this.getMaxMaximizedBoxZIndex();
355
+ } else if (
356
+ box.boxStatus &&
357
+ box.boxStatus === TELE_BOX_STATE.Maximized
358
+ ) {
359
+ const maxMaximizedBoxZIndex =
360
+ this.getMaxMaximizedBoxZIndex();
328
361
  if (maxMaximizedBoxZIndex > box.zIndex) {
329
- this.setBox(box, {
330
- zIndex: maxMaximizedBoxZIndex + 1
331
- }, false);
362
+ this.setBox(
363
+ box,
364
+ {
365
+ zIndex: maxMaximizedBoxZIndex + 1,
366
+ },
367
+ false
368
+ );
332
369
  }
333
370
  this.makeMaximizedTopBoxFocus();
334
371
  }
335
- }
336
- this.focusBox(box);
372
+ }
373
+ this.focusBoxCommitted(box);
337
374
  return;
338
375
  }
339
376
  }
@@ -358,6 +395,7 @@ export class TeleBoxManager {
358
395
  readonly: readonly$.value,
359
396
  namespace: this.namespace,
360
397
  state: state$.value,
398
+ forceMaximized: forceMaximized$.value,
361
399
  boxes: this.boxes$.value,
362
400
  containerRect: containerRect$.value,
363
401
  getBoxesStatus: () => {
@@ -366,20 +404,33 @@ export class TeleBoxManager {
366
404
  onEvent: (event): void => {
367
405
  switch (event.type) {
368
406
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
407
+ if (
408
+ forceMaximized$.value &&
409
+ this.state === TELE_BOX_STATE.Maximized
410
+ ) {
411
+ return;
412
+ }
369
413
  if (this.hasBoxesStatus()) {
370
414
  let targetBox = this.maxTitleBar.focusedBox;
371
415
  if (!targetBox) {
372
- targetBox = this.getMaximizedTopBox();
416
+ targetBox = this.getMaximizedTopBox();
373
417
  }
374
418
  if (targetBox?.id) {
375
419
  const box = this.getBox(targetBox.id);
376
420
  if (box) {
377
- this.setBox(box, {
378
- status: TELE_BOX_STATE.Normal,
379
- zIndex: this.getMaxNormalBoxZIndex() + 1
380
- }, false, ()=>{
381
- this.makeMaximizedTopBoxFocus();
382
- });
421
+ this.setBox(
422
+ box,
423
+ {
424
+ status: TELE_BOX_STATE.Normal,
425
+ zIndex:
426
+ this.getMaxNormalBoxZIndex() +
427
+ 1,
428
+ },
429
+ false,
430
+ () => {
431
+ this.makeMaximizedTopBoxFocus();
432
+ }
433
+ );
383
434
  }
384
435
  }
385
436
  } else {
@@ -391,9 +442,9 @@ export class TeleBoxManager {
391
442
  if (this.hasBoxesStatus()) {
392
443
  let targetBox = this.maxTitleBar.focusedBox;
393
444
  if (!targetBox) {
394
- targetBox = this.getMaximizedTopBox();
445
+ targetBox = this.getMaximizedTopBox();
395
446
  }
396
- if(targetBox?.id){
447
+ if (targetBox?.id) {
397
448
  const box = this.getBox(targetBox.id);
398
449
  if (box) {
399
450
  let isFocusChanged = false;
@@ -401,10 +452,14 @@ export class TeleBoxManager {
401
452
  this.blurBox(box);
402
453
  isFocusChanged = true;
403
454
  }
404
- this.setBox(box, {
405
- status: TELE_BOX_STATE.Minimized,
406
- zIndex: -1
407
- }, false);
455
+ this.setBox(
456
+ box,
457
+ {
458
+ status: TELE_BOX_STATE.Minimized,
459
+ zIndex: -1,
460
+ },
461
+ false
462
+ );
408
463
  if (isFocusChanged) {
409
464
  this.focusTopBox();
410
465
  } else {
@@ -421,7 +476,7 @@ export class TeleBoxManager {
421
476
  if (this.hasBoxesStatus()) {
422
477
  let targetBox = this.maxTitleBar.focusedBox;
423
478
  if (!targetBox) {
424
- targetBox = this.getMaximizedTopBox();
479
+ targetBox = this.getMaximizedTopBox();
425
480
  }
426
481
  if (targetBox?.id) {
427
482
  const box = this.getBox(targetBox.id);
@@ -470,6 +525,7 @@ export class TeleBoxManager {
470
525
  fence: fence$,
471
526
  minimized: minimized$,
472
527
  maximized: maximized$,
528
+ forceMaximized: forceMaximized$,
473
529
  };
474
530
 
475
531
  withValueEnhancer(this, valConfig);
@@ -532,8 +588,27 @@ export class TeleBoxManager {
532
588
  return this._state$.value;
533
589
  }
534
590
 
591
+ public setUseBoxesStatus(useBoxesStatus: boolean): void {
592
+ if (this.useBoxesStatus === useBoxesStatus) return;
593
+ this.useBoxesStatus = useBoxesStatus;
594
+ this.boxes.forEach((box) =>
595
+ box.setBoxStatus(useBoxesStatus ? this.boxesStatus$.get(box.id) : undefined, true)
596
+ );
597
+ this.boxes$.setValue([...this.boxes]);
598
+ if (useBoxesStatus) {
599
+ this.appMenu ||= this.createMinimizedAppMenu();
600
+ this.effectBoxStatusChange();
601
+ } else {
602
+ this.appMenu?.render(new Map());
603
+ this.collector?.setVisible(false);
604
+ }
605
+ }
606
+
535
607
  /** @deprecated use setMaximized and setMinimized instead */
536
608
  public setState(state: TeleBoxState, skipUpdate = false): this {
609
+ if (state === TELE_BOX_STATE.Normal && this.forceMaximized) {
610
+ return this;
611
+ }
537
612
  switch (state) {
538
613
  case TELE_BOX_STATE.Maximized: {
539
614
  this.setMinimized(false, skipUpdate);
@@ -554,13 +629,27 @@ export class TeleBoxManager {
554
629
  return this;
555
630
  }
556
631
 
557
- public setBoxStatus(boxId: string, boxStatus?: TeleBoxState, skipUpdate = false): void {
632
+ public setBoxStatus(
633
+ boxId: string,
634
+ boxStatus?: TeleBoxState,
635
+ skipUpdate = false
636
+ ): void {
558
637
  if (boxStatus) {
559
638
  const oldBoxStatus = this.boxesStatus$.get(boxId);
560
639
  this.boxesStatus$.set(boxId, boxStatus);
561
- if (boxStatus === TELE_BOX_STATE.Minimized && oldBoxStatus !== TELE_BOX_STATE.Minimized) {
562
- this.setLastNotMinimizedBoxStatus(boxId, oldBoxStatus, skipUpdate);
563
- } else if (oldBoxStatus === TELE_BOX_STATE.Minimized && boxStatus !== TELE_BOX_STATE.Minimized) {
640
+ if (
641
+ boxStatus === TELE_BOX_STATE.Minimized &&
642
+ oldBoxStatus !== TELE_BOX_STATE.Minimized
643
+ ) {
644
+ this.setLastNotMinimizedBoxStatus(
645
+ boxId,
646
+ oldBoxStatus,
647
+ skipUpdate
648
+ );
649
+ } else if (
650
+ oldBoxStatus === TELE_BOX_STATE.Minimized &&
651
+ boxStatus !== TELE_BOX_STATE.Minimized
652
+ ) {
564
653
  this.setLastNotMinimizedBoxStatus(boxId, undefined, skipUpdate);
565
654
  }
566
655
  } else {
@@ -568,7 +657,10 @@ export class TeleBoxManager {
568
657
  this.setLastNotMinimizedBoxStatus(boxId, undefined, skipUpdate);
569
658
  }
570
659
  if (!skipUpdate) {
571
- this.events.emit(TELE_BOX_MANAGER_EVENT.BoxStatus, { id: boxId, boxStatus});
660
+ this.events.emit(TELE_BOX_MANAGER_EVENT.BoxStatus, {
661
+ id: boxId,
662
+ boxStatus,
663
+ });
572
664
  }
573
665
  }
574
666
 
@@ -580,11 +672,17 @@ export class TeleBoxManager {
580
672
  return this.boxesStatus$;
581
673
  }
582
674
 
583
- public get lastNotMinimizedBoxesStatus(): ReadonlyMap<string, NotMinimizedBoxState> {
675
+ public get lastNotMinimizedBoxesStatus(): ReadonlyMap<
676
+ string,
677
+ NotMinimizedBoxState
678
+ > {
584
679
  return this.lastNotMinimizedBoxesStatus$;
585
680
  }
586
681
 
587
- public setBoxesStatus(boxesStatus: Map<string, TeleBoxState>, skipUpdate = false) {
682
+ public setBoxesStatus(
683
+ boxesStatus: Map<string, TeleBoxState>,
684
+ skipUpdate = false
685
+ ) {
588
686
  this.boxesStatus$ = boxesStatus;
589
687
  this.effectBoxesStatusChange(skipUpdate);
590
688
  }
@@ -593,13 +691,13 @@ export class TeleBoxManager {
593
691
  return this.boxesStatus$;
594
692
  }
595
693
 
596
- protected effectBoxStatusChange(){
694
+ protected effectBoxStatusChange() {
597
695
  if (!this.useBoxesStatus) {
598
696
  return;
599
697
  }
600
- if(this.collector){
698
+ if (this.collector) {
601
699
  this.collector.updateBoxesStatus();
602
- if(this.hasMinimizedBox()){
700
+ if (this.hasMinimizedBox()) {
603
701
  this._setCollectorRect(this._calcCollectorRect());
604
702
  }
605
703
  }
@@ -611,16 +709,20 @@ export class TeleBoxManager {
611
709
  }
612
710
  }
613
711
 
614
- protected effectBoxesStatusTimerFunc(skipUpdate: boolean){
712
+ protected effectBoxesStatusTimerFunc(skipUpdate: boolean) {
615
713
  if (!this.useBoxesStatus) {
616
714
  return;
617
715
  }
618
- let newTopBox:TeleBox | undefined;
716
+ let newTopBox: TeleBox | undefined;
619
717
  const curTopBox = this.topBox;
620
718
  this.boxes.forEach((box) => {
621
719
  const boxStatus = this.boxesStatus$.get(box.id);
622
720
  if (boxStatus) {
623
- if (boxStatus !== TELE_BOX_STATE.Minimized && !this.isForceTop(box) && box.zIndex > (newTopBox?.zIndex ?? 0)) {
721
+ if (
722
+ boxStatus !== TELE_BOX_STATE.Minimized &&
723
+ !this.isForceTop(box) &&
724
+ box.zIndex > (newTopBox?.zIndex ?? 0)
725
+ ) {
624
726
  newTopBox = box;
625
727
  }
626
728
  box.setBoxStatus(boxStatus, skipUpdate);
@@ -637,20 +739,27 @@ export class TeleBoxManager {
637
739
 
638
740
  public async effectBoxesStatusChange(skipUpdate = false): Promise<void> {
639
741
  if (!this.useBoxesStatus) {
640
- if (this.effectBoxesStatusTimer && this.effectBoxesStatusTimer.timer) {
742
+ if (
743
+ this.effectBoxesStatusTimer &&
744
+ this.effectBoxesStatusTimer.timer
745
+ ) {
641
746
  clearTimeout(this.effectBoxesStatusTimer.timer);
642
747
  if (this.effectBoxesStatusTimer.resolve) {
643
- this.effectBoxesStatusTimer.resolve(!!this.effectBoxesStatusTimer?.skipUpdate);
748
+ this.effectBoxesStatusTimer.resolve(
749
+ !!this.effectBoxesStatusTimer?.skipUpdate
750
+ );
644
751
  }
645
752
  }
646
- this.effectBoxesStatusTimer=undefined;
753
+ this.effectBoxesStatusTimer = undefined;
647
754
  return;
648
755
  }
649
756
  if (this.effectBoxesStatusTimer && this.effectBoxesStatusTimer.timer) {
650
757
  if (this.effectBoxesStatusTimer.skipUpdate !== skipUpdate) {
651
758
  clearTimeout(this.effectBoxesStatusTimer.timer);
652
759
  if (this.effectBoxesStatusTimer.resolve) {
653
- this.effectBoxesStatusTimer.resolve(!!this.effectBoxesStatusTimer?.skipUpdate);
760
+ this.effectBoxesStatusTimer.resolve(
761
+ !!this.effectBoxesStatusTimer?.skipUpdate
762
+ );
654
763
  }
655
764
  this.effectBoxesStatusTimer.skipUpdate = skipUpdate;
656
765
  } else {
@@ -665,22 +774,27 @@ export class TeleBoxManager {
665
774
  } as {
666
775
  skipUpdate: boolean;
667
776
  timer: number | undefined;
668
- }
777
+ };
669
778
  }
670
779
  if (this.effectBoxesStatusTimer) {
671
- const _skipUpdate = await new Promise<boolean>((resolve)=>{
780
+ const _skipUpdate = await new Promise<boolean>((resolve) => {
672
781
  this.effectBoxesStatusTimer!.resolve = resolve;
673
- this.effectBoxesStatusTimer!.timer = setTimeout(()=>{
674
- if (this.effectBoxesStatusTimer && this.effectBoxesStatusTimer.resolve) {
675
- this.effectBoxesStatusTimer.resolve(this.effectBoxesStatusTimer!.skipUpdate);
782
+ this.effectBoxesStatusTimer!.timer = setTimeout(() => {
783
+ if (
784
+ this.effectBoxesStatusTimer &&
785
+ this.effectBoxesStatusTimer.resolve
786
+ ) {
787
+ this.effectBoxesStatusTimer.resolve(
788
+ this.effectBoxesStatusTimer!.skipUpdate
789
+ );
676
790
  }
677
791
  }, 100) as unknown as number;
678
- })
679
- this.effectBoxesStatusTimerFunc(_skipUpdate)
792
+ });
793
+ this.effectBoxesStatusTimerFunc(_skipUpdate);
680
794
  this.effectBoxesStatusTimer = undefined;
681
795
  }
682
796
  }
683
-
797
+
684
798
  public hasBoxesStatus(): boolean {
685
799
  if (!this.useBoxesStatus) {
686
800
  return false;
@@ -692,14 +806,19 @@ export class TeleBoxManager {
692
806
  if (!this.useBoxesStatus) {
693
807
  return false;
694
808
  }
695
- return this.boxes.some((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized);
809
+ return this.boxes.some(
810
+ (box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized
811
+ );
696
812
  }
697
813
 
698
814
  public getMinimizedBoxesStatus(): Map<string, TELE_BOX_STATE.Minimized> {
699
815
  const minimizedBoxes = new Map<string, TELE_BOX_STATE.Minimized>();
700
816
  this.boxesStatus$.forEach((boxStatus, boxId) => {
701
817
  if (boxStatus === TELE_BOX_STATE.Minimized) {
702
- minimizedBoxes.set(boxId, boxStatus as TELE_BOX_STATE.Minimized);
818
+ minimizedBoxes.set(
819
+ boxId,
820
+ boxStatus as TELE_BOX_STATE.Minimized
821
+ );
703
822
  }
704
823
  });
705
824
  return minimizedBoxes;
@@ -719,7 +838,10 @@ export class TeleBoxManager {
719
838
  const maximizedBoxes = new Map<string, TELE_BOX_STATE.Maximized>();
720
839
  this.boxesStatus$.forEach((boxStatus, boxId) => {
721
840
  if (boxStatus === TELE_BOX_STATE.Maximized) {
722
- maximizedBoxes.set(boxId, boxStatus as TELE_BOX_STATE.Maximized);
841
+ maximizedBoxes.set(
842
+ boxId,
843
+ boxStatus as TELE_BOX_STATE.Maximized
844
+ );
723
845
  }
724
846
  });
725
847
  return maximizedBoxes;
@@ -735,45 +857,76 @@ export class TeleBoxManager {
735
857
  return normalBoxes;
736
858
  }
737
859
 
738
- public getLastNotMinimizedBoxStatus(boxId: string): NotMinimizedBoxState | undefined {
860
+ public getLastNotMinimizedBoxStatus(
861
+ boxId: string
862
+ ): NotMinimizedBoxState | undefined {
739
863
  return this.lastNotMinimizedBoxesStatus$.get(boxId);
740
864
  }
741
865
 
742
- public setLastNotMinimizedBoxStatus(boxId: string, lastNotMinimizedBoxStatus?: NotMinimizedBoxState, skipUpdate = false): void {
866
+ public setLastNotMinimizedBoxStatus(
867
+ boxId: string,
868
+ lastNotMinimizedBoxStatus?: NotMinimizedBoxState,
869
+ skipUpdate = false
870
+ ): void {
743
871
  if (lastNotMinimizedBoxStatus) {
744
- this.lastNotMinimizedBoxesStatus$.set(boxId, lastNotMinimizedBoxStatus);
872
+ this.lastNotMinimizedBoxesStatus$.set(
873
+ boxId,
874
+ lastNotMinimizedBoxStatus
875
+ );
745
876
  } else {
746
877
  this.lastNotMinimizedBoxesStatus$.delete(boxId);
747
878
  }
748
879
  if (!skipUpdate) {
749
- this.events.emit(TELE_BOX_MANAGER_EVENT.LastNotMinimizedBoxStatus, { id: boxId, boxStatus:lastNotMinimizedBoxStatus});
880
+ this.events.emit(TELE_BOX_MANAGER_EVENT.LastNotMinimizedBoxStatus, {
881
+ id: boxId,
882
+ boxStatus: lastNotMinimizedBoxStatus,
883
+ });
750
884
  }
751
885
  }
752
886
 
753
- public setLastNotMinimizedBoxesStatus(lastNotMinimizedBoxesStatus: Map<string, NotMinimizedBoxState>, skipUpdate = false): void {
887
+ public setLastNotMinimizedBoxesStatus(
888
+ lastNotMinimizedBoxesStatus: Map<string, NotMinimizedBoxState>,
889
+ skipUpdate = false
890
+ ): void {
754
891
  this.lastNotMinimizedBoxesStatus$ = lastNotMinimizedBoxesStatus;
755
892
  this.effectLastNotMinimizedBoxStatusChange(skipUpdate);
756
893
  }
757
894
 
758
- protected async effectLastNotMinimizedBoxStatusChange(skipUpdate = false): Promise<void> {
895
+ protected async effectLastNotMinimizedBoxStatusChange(
896
+ skipUpdate = false
897
+ ): Promise<void> {
759
898
  if (!this.useBoxesStatus) {
760
- if (this.effectLastNotMinimizedBoxStatusTimer && this.effectLastNotMinimizedBoxStatusTimer.timer) {
899
+ if (
900
+ this.effectLastNotMinimizedBoxStatusTimer &&
901
+ this.effectLastNotMinimizedBoxStatusTimer.timer
902
+ ) {
761
903
  clearTimeout(this.effectLastNotMinimizedBoxStatusTimer.timer);
762
904
  if (this.effectLastNotMinimizedBoxStatusTimer.resolve) {
763
- this.effectLastNotMinimizedBoxStatusTimer.resolve(!!this.effectLastNotMinimizedBoxStatusTimer?.skipUpdate);
905
+ this.effectLastNotMinimizedBoxStatusTimer.resolve(
906
+ !!this.effectLastNotMinimizedBoxStatusTimer?.skipUpdate
907
+ );
764
908
  }
765
909
  }
766
- this.effectLastNotMinimizedBoxStatusTimer=undefined;
910
+ this.effectLastNotMinimizedBoxStatusTimer = undefined;
767
911
  return;
768
912
  }
769
- if (this.effectLastNotMinimizedBoxStatusTimer && this.effectLastNotMinimizedBoxStatusTimer.timer) {
913
+ if (
914
+ this.effectLastNotMinimizedBoxStatusTimer &&
915
+ this.effectLastNotMinimizedBoxStatusTimer.timer
916
+ ) {
770
917
  clearTimeout(this.effectLastNotMinimizedBoxStatusTimer.timer);
771
- if (this.effectLastNotMinimizedBoxStatusTimer.skipUpdate !== skipUpdate) {
918
+ if (
919
+ this.effectLastNotMinimizedBoxStatusTimer.skipUpdate !==
920
+ skipUpdate
921
+ ) {
772
922
  // this.effectLastNotMinimizedBoxStatusFunc(this.effectLastNotMinimizedBoxStatusTimer.skipUpdate)
773
923
  if (this.effectLastNotMinimizedBoxStatusTimer.resolve) {
774
- this.effectLastNotMinimizedBoxStatusTimer.resolve(!!this.effectLastNotMinimizedBoxStatusTimer?.skipUpdate);
924
+ this.effectLastNotMinimizedBoxStatusTimer.resolve(
925
+ !!this.effectLastNotMinimizedBoxStatusTimer?.skipUpdate
926
+ );
775
927
  }
776
- this.effectLastNotMinimizedBoxStatusTimer.skipUpdate = skipUpdate;
928
+ this.effectLastNotMinimizedBoxStatusTimer.skipUpdate =
929
+ skipUpdate;
777
930
  } else {
778
931
  return;
779
932
  }
@@ -786,29 +939,38 @@ export class TeleBoxManager {
786
939
  } as {
787
940
  skipUpdate: boolean;
788
941
  timer: number | undefined;
789
- }
942
+ };
790
943
  }
791
944
  if (this.effectLastNotMinimizedBoxStatusTimer) {
792
- const _skipUpdate = await new Promise<boolean>((resolve)=>{
945
+ const _skipUpdate = await new Promise<boolean>((resolve) => {
793
946
  this.effectLastNotMinimizedBoxStatusTimer!.resolve = resolve;
794
- this.effectLastNotMinimizedBoxStatusTimer!.timer = setTimeout(()=>{
795
- if (this.effectLastNotMinimizedBoxStatusTimer && this.effectLastNotMinimizedBoxStatusTimer.resolve) {
796
- this.effectLastNotMinimizedBoxStatusTimer.resolve(this.effectLastNotMinimizedBoxStatusTimer!.skipUpdate);
797
- }
798
- }, 100) as unknown as number;
799
- })
800
- this.effectLastNotMinimizedBoxStatusFunc(_skipUpdate)
947
+ this.effectLastNotMinimizedBoxStatusTimer!.timer = setTimeout(
948
+ () => {
949
+ if (
950
+ this.effectLastNotMinimizedBoxStatusTimer &&
951
+ this.effectLastNotMinimizedBoxStatusTimer.resolve
952
+ ) {
953
+ this.effectLastNotMinimizedBoxStatusTimer.resolve(
954
+ this.effectLastNotMinimizedBoxStatusTimer!
955
+ .skipUpdate
956
+ );
957
+ }
958
+ },
959
+ 100
960
+ ) as unknown as number;
961
+ });
962
+ this.effectLastNotMinimizedBoxStatusFunc(_skipUpdate);
801
963
  this.effectLastNotMinimizedBoxStatusTimer = undefined;
802
964
  }
803
965
  }
804
966
 
805
- protected effectLastNotMinimizedBoxStatusFunc(skipUpdate = false){
967
+ protected effectLastNotMinimizedBoxStatusFunc(skipUpdate = false) {
806
968
  if (!this.useBoxesStatus) {
807
969
  return;
808
970
  }
809
971
  this.boxes.forEach((box) => {
810
972
  const boxStatus = this.lastNotMinimizedBoxesStatus$.get(box.id);
811
- if(boxStatus){
973
+ if (boxStatus) {
812
974
  box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
813
975
  }
814
976
  });
@@ -824,7 +986,11 @@ export class TeleBoxManager {
824
986
  return this.getUnabledBoxesStatusZIndex();
825
987
  }
826
988
  return this.boxes.reduce((maxZIndex, box) => {
827
- if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Maximized && !this.isForceTop(box)) {
989
+ if (
990
+ box.boxStatus &&
991
+ box.boxStatus === TELE_BOX_STATE.Maximized &&
992
+ !this.isForceTop(box)
993
+ ) {
828
994
  return Math.max(maxZIndex, box.zIndex);
829
995
  }
830
996
  return maxZIndex;
@@ -837,7 +1003,11 @@ export class TeleBoxManager {
837
1003
  return this.getUnabledBoxesStatusZIndex();
838
1004
  }
839
1005
  return this.boxes.reduce((maxZIndex, box) => {
840
- if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Normal && !this.isForceTop(box)) {
1006
+ if (
1007
+ box.boxStatus &&
1008
+ box.boxStatus === TELE_BOX_STATE.Normal &&
1009
+ !this.isForceTop(box)
1010
+ ) {
841
1011
  return Math.max(maxZIndex, box.zIndex);
842
1012
  }
843
1013
  return maxZIndex;
@@ -869,8 +1039,13 @@ export class TeleBoxManager {
869
1039
  smartPosition = true
870
1040
  ): ReadonlyTeleBox {
871
1041
  const box = new TeleBox({
872
- zIndex: config.forceTop ? this.getMaxForceTopBoxZIndex() + 1 : this.getMaxNormalBoxZIndex() + 1,
1042
+ zIndex: config.forceTop
1043
+ ? this.getMaxForceTopBoxZIndex() + 1
1044
+ : this.getMaxNormalBoxZIndex() + 1,
873
1045
  ...(smartPosition ? this.smartPosition(config) : config),
1046
+ ...(!this.useBoxesStatus
1047
+ ? { boxStatus: undefined, lastNotMinimizedBoxStatus: undefined }
1048
+ : {}),
874
1049
  darkMode: this.darkMode,
875
1050
  prefersColorScheme: this.prefersColorScheme,
876
1051
  maximized: this.maximized,
@@ -879,6 +1054,7 @@ export class TeleBoxManager {
879
1054
  namespace: this.namespace,
880
1055
  containerRect: this.containerRect,
881
1056
  readonly: this.readonly,
1057
+ forceMaximized: this.forceMaximized,
882
1058
  collectorRect: this.collectorRect,
883
1059
  });
884
1060
 
@@ -887,10 +1063,15 @@ export class TeleBoxManager {
887
1063
  this.boxes$.setValue([...this.boxes, box]);
888
1064
 
889
1065
  if (box.boxStatus && this.useBoxesStatus) {
890
- this.setBox(box, {
891
- status: box.boxStatus,
892
- lastNotMinimizedBoxStatus: box._lastNotMinimizedBoxStatus$.value
893
- }, true);
1066
+ this.setBox(
1067
+ box,
1068
+ {
1069
+ status: box.boxStatus,
1070
+ lastNotMinimizedBoxStatus:
1071
+ box._lastNotMinimizedBoxStatus$.value,
1072
+ },
1073
+ true
1074
+ );
894
1075
  }
895
1076
 
896
1077
  if (box.focus) {
@@ -906,43 +1087,64 @@ export class TeleBoxManager {
906
1087
  return;
907
1088
  }
908
1089
  if (box.boxStatus === TELE_BOX_STATE.Maximized) {
909
- this.setBox(box.id, {
910
- status: TELE_BOX_STATE.Normal,
911
- zIndex: this.getMaxNormalBoxZIndex() + 1
912
- }, false);
1090
+ this.setBox(
1091
+ box.id,
1092
+ {
1093
+ status: TELE_BOX_STATE.Normal,
1094
+ zIndex: this.getMaxNormalBoxZIndex() + 1,
1095
+ },
1096
+ false
1097
+ );
913
1098
  } else {
914
1099
  // 所有normal box都最大化
915
- [...this.boxes].filter((box) => box.boxStatus === TELE_BOX_STATE.Normal && !this.isForceNormal(box)).sort((a, b) => a.zIndex - b.zIndex).forEach((box) => {
916
- if (box.boxStatus === TELE_BOX_STATE.Normal) {
917
- this.setBox(box.id, {
918
- status: TELE_BOX_STATE.Maximized,
919
- zIndex: this.getMaxMaximizedBoxZIndex() + 1
920
- }, false);
921
- }
922
- });
1100
+ [...this.boxes]
1101
+ .filter(
1102
+ (box) =>
1103
+ box.boxStatus === TELE_BOX_STATE.Normal &&
1104
+ !this.isForceNormal(box)
1105
+ )
1106
+ .sort((a, b) => a.zIndex - b.zIndex)
1107
+ .forEach((box) => {
1108
+ if (box.boxStatus === TELE_BOX_STATE.Normal) {
1109
+ this.setBox(
1110
+ box.id,
1111
+ {
1112
+ status: TELE_BOX_STATE.Maximized,
1113
+ zIndex:
1114
+ this.getMaxMaximizedBoxZIndex() + 1,
1115
+ },
1116
+ false
1117
+ );
1118
+ }
1119
+ });
923
1120
  this.makeMaximizedTopBoxFocus();
924
1121
  }
925
1122
  } else {
926
- this.setMaximized(!this.maximized);
1123
+ if (!(this.forceMaximized && this.maximized)) {
1124
+ this.setMaximized(!this.maximized);
1125
+ }
927
1126
  }
928
-
929
1127
  });
930
1128
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Minimize, () => {
931
1129
  if (box.boxStatus && this.useBoxesStatus) {
932
1130
  if (box._forceNormal$.value) {
933
1131
  return;
934
1132
  }
935
- if(box.focus) {
1133
+ if (box.focus) {
936
1134
  this.blurBox(box);
937
1135
  }
938
- this.setBox(box, {
939
- status: TELE_BOX_STATE.Minimized,
940
- zIndex: -1
941
- }, false, ()=>{
942
- this.focusTopBox();
943
- });
944
-
945
- } else{
1136
+ this.setBox(
1137
+ box,
1138
+ {
1139
+ status: TELE_BOX_STATE.Minimized,
1140
+ zIndex: -1,
1141
+ },
1142
+ false,
1143
+ () => {
1144
+ this.focusTopBox();
1145
+ }
1146
+ );
1147
+ } else {
946
1148
  this.setMinimized(true);
947
1149
  }
948
1150
  });
@@ -985,7 +1187,10 @@ export class TeleBoxManager {
985
1187
  if (this.isForceTop(box)) {
986
1188
  return topBox;
987
1189
  }
988
- if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized) {
1190
+ if (
1191
+ box.boxStatus &&
1192
+ box.boxStatus === TELE_BOX_STATE.Minimized
1193
+ ) {
989
1194
  return topBox;
990
1195
  }
991
1196
  if (!topBox) {
@@ -993,7 +1198,7 @@ export class TeleBoxManager {
993
1198
  return topBox;
994
1199
  }
995
1200
  return topBox.zIndex > box.zIndex ? topBox : box;
996
- }, currentTopBox as (TeleBox | undefined));
1201
+ }, currentTopBox as TeleBox | undefined);
997
1202
  this.topBox$.setValue(topBox);
998
1203
  }
999
1204
  if (!skipUpdate) {
@@ -1039,14 +1244,19 @@ export class TeleBoxManager {
1039
1244
  });
1040
1245
  }
1041
1246
 
1042
- public setBox(boxOrID: string | TeleBox, options: {
1043
- status?: TeleBoxState;
1044
- lastNotMinimizedBoxStatus?: NotMinimizedBoxState;
1045
- zIndex?: number;
1046
- }, skipUpdate = false, effectFunc?: () => void){
1047
- const box = this.getBox(boxOrID)
1247
+ public setBox(
1248
+ boxOrID: string | TeleBox,
1249
+ options: {
1250
+ status?: TeleBoxState;
1251
+ lastNotMinimizedBoxStatus?: NotMinimizedBoxState;
1252
+ zIndex?: number;
1253
+ },
1254
+ skipUpdate = false,
1255
+ effectFunc?: () => void
1256
+ ) {
1257
+ const box = this.getBox(boxOrID);
1048
1258
  if (box) {
1049
- const {status, zIndex, lastNotMinimizedBoxStatus} = options;
1259
+ const { status, zIndex, lastNotMinimizedBoxStatus } = options;
1050
1260
  if (status) {
1051
1261
  this.setBoxStatus(box.id, status, skipUpdate);
1052
1262
  box.setBoxStatus(status, skipUpdate);
@@ -1056,8 +1266,15 @@ export class TeleBoxManager {
1056
1266
  box.setZIndex(zIndex, skipUpdate);
1057
1267
  }
1058
1268
  if (lastNotMinimizedBoxStatus) {
1059
- this.setLastNotMinimizedBoxStatus(box.id, lastNotMinimizedBoxStatus, skipUpdate);
1060
- box.setLastNotMinimizedBoxStatus(lastNotMinimizedBoxStatus, skipUpdate);
1269
+ this.setLastNotMinimizedBoxStatus(
1270
+ box.id,
1271
+ lastNotMinimizedBoxStatus,
1272
+ skipUpdate
1273
+ );
1274
+ box.setLastNotMinimizedBoxStatus(
1275
+ lastNotMinimizedBoxStatus,
1276
+ skipUpdate
1277
+ );
1061
1278
  }
1062
1279
  effectFunc && effectFunc();
1063
1280
  }
@@ -1077,12 +1294,16 @@ export class TeleBoxManager {
1077
1294
  deletedBoxes.forEach((box) => box.destroy());
1078
1295
  if (box && this.useBoxesStatus) {
1079
1296
  this.setBoxStatus(box.id, undefined, skipUpdate);
1080
- this.setLastNotMinimizedBoxStatus(box.id, undefined, skipUpdate);
1297
+ this.setLastNotMinimizedBoxStatus(
1298
+ box.id,
1299
+ undefined,
1300
+ skipUpdate
1301
+ );
1081
1302
  this.effectBoxStatusChange();
1082
1303
  effectFunc && effectFunc();
1083
1304
  }
1084
1305
  if (!skipUpdate) {
1085
- if (this.boxes.length <= 0) {
1306
+ if (this.boxes.length <= 0 && !this.forceMaximized) {
1086
1307
  this.setMaximized(false);
1087
1308
  this.setMinimized(false);
1088
1309
  }
@@ -1107,7 +1328,7 @@ export class TeleBoxManager {
1107
1328
  this.boxesStatus$.clear();
1108
1329
  this.lastNotMinimizedBoxesStatus$.clear();
1109
1330
  if (!skipUpdate) {
1110
- if (this.boxes.length <= 0) {
1331
+ if (this.boxes.length <= 0 && !this.forceMaximized) {
1111
1332
  this.setMaximized(false);
1112
1333
  this.setMinimized(false);
1113
1334
  }
@@ -1133,9 +1354,21 @@ export class TeleBoxManager {
1133
1354
  return `${this.namespace}-${className}`;
1134
1355
  }
1135
1356
 
1357
+ private lazyFocusRequestHandler?: (boxId: string) => boolean;
1358
+ private committedFocusDepth = 0;
1359
+
1360
+ public setLazyFocusRequestHandler(handler?: (boxId: string) => boolean): void {
1361
+ this.lazyFocusRequestHandler = handler;
1362
+ }
1363
+
1136
1364
  public focusBox(boxOrID: string | TeleBox, skipUpdate = false): void {
1137
1365
  const targetBox = this.getBox(boxOrID);
1138
1366
  if (targetBox) {
1367
+ if (
1368
+ !skipUpdate &&
1369
+ !this.committedFocusDepth &&
1370
+ this.lazyFocusRequestHandler?.(targetBox.id)
1371
+ ) return;
1139
1372
  this.boxes.forEach((box) => {
1140
1373
  if (targetBox === box) {
1141
1374
  let focusChanged = false;
@@ -1155,12 +1388,24 @@ export class TeleBoxManager {
1155
1388
  });
1156
1389
  if (!this.useBoxesStatus) {
1157
1390
  this.maxTitleBar.focusBox(targetBox);
1158
- } else if (this.useBoxesStatus && this.maxTitleBar.hasMaximizedBoxInStatus()) {
1391
+ } else if (
1392
+ this.useBoxesStatus &&
1393
+ this.maxTitleBar.hasMaximizedBoxInStatus()
1394
+ ) {
1159
1395
  this.makeMaximizedTopBoxFocus();
1160
1396
  }
1161
1397
  }
1162
1398
  }
1163
1399
 
1400
+ public focusBoxCommitted(boxOrID: string | TeleBox, skipUpdate = false): void {
1401
+ this.committedFocusDepth = (this.committedFocusDepth ?? 0) + 1;
1402
+ try {
1403
+ this.focusBox(boxOrID, skipUpdate);
1404
+ } finally {
1405
+ this.committedFocusDepth -= 1;
1406
+ }
1407
+ }
1408
+
1164
1409
  public focusTopBox(): void {
1165
1410
  if (this.topBox && !this.topBox.focus) {
1166
1411
  return this.focusBox(this.topBox);
@@ -1262,11 +1507,18 @@ export class TeleBoxManager {
1262
1507
  if (config.footer != null) {
1263
1508
  box.mountFooter(config.footer);
1264
1509
  }
1265
- if (this.useBoxesStatus && (config.boxStatus || config.lastNotMinimizedBoxStatus)) {
1266
- this.setBox(box, {
1267
- status: config.boxStatus,
1268
- lastNotMinimizedBoxStatus: config.lastNotMinimizedBoxStatus
1269
- }, skipUpdate);
1510
+ if (
1511
+ this.useBoxesStatus &&
1512
+ (config.boxStatus || config.lastNotMinimizedBoxStatus)
1513
+ ) {
1514
+ this.setBox(
1515
+ box,
1516
+ {
1517
+ status: config.boxStatus,
1518
+ lastNotMinimizedBoxStatus: config.lastNotMinimizedBoxStatus,
1519
+ },
1520
+ skipUpdate
1521
+ );
1270
1522
  }
1271
1523
  if (config.forceTop != null) {
1272
1524
  box.setForceTop(config.forceTop, skipUpdate);
@@ -1288,7 +1540,8 @@ export class TeleBoxManager {
1288
1540
  vx = forceTopBox.intrinsicX * this.containerRect.width + 20;
1289
1541
  if (
1290
1542
  vx >
1291
- this.containerRect.width - width * this.containerRect.width
1543
+ this.containerRect.width -
1544
+ width * this.containerRect.width
1292
1545
  ) {
1293
1546
  vx = 20;
1294
1547
  }
@@ -1303,9 +1556,21 @@ export class TeleBoxManager {
1303
1556
  }
1304
1557
  } else if (this.hasMinimizedBox()) {
1305
1558
  // 如果都最小化,则获取lastNotMinimizedBoxesStatus中normal box的最大x
1306
- vx = [...this.boxes].filter((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized && box.lastNotMinimizedBoxStatus && box.lastNotMinimizedBoxStatus === TELE_BOX_STATE.Normal).reduce((maxX, box) => {
1307
- return Math.max(maxX, box.intrinsicX * this.containerRect.width + 20);
1308
- }, vx);
1559
+ vx = [...this.boxes]
1560
+ .filter(
1561
+ (box) =>
1562
+ box.boxStatus &&
1563
+ box.boxStatus === TELE_BOX_STATE.Minimized &&
1564
+ box.lastNotMinimizedBoxStatus &&
1565
+ box.lastNotMinimizedBoxStatus ===
1566
+ TELE_BOX_STATE.Normal
1567
+ )
1568
+ .reduce((maxX, box) => {
1569
+ return Math.max(
1570
+ maxX,
1571
+ box.intrinsicX * this.containerRect.width + 20
1572
+ );
1573
+ }, vx);
1309
1574
  }
1310
1575
  x = vx / this.containerRect.width;
1311
1576
  }
@@ -1315,7 +1580,8 @@ export class TeleBoxManager {
1315
1580
  if (config.forceTop) {
1316
1581
  const forceTopBox = this.maxForceTopBox || this.topBox;
1317
1582
  if (forceTopBox) {
1318
- vy = forceTopBox.intrinsicY * this.containerRect.height + 20;
1583
+ vy =
1584
+ forceTopBox.intrinsicY * this.containerRect.height + 20;
1319
1585
 
1320
1586
  if (
1321
1587
  vy >
@@ -1337,9 +1603,21 @@ export class TeleBoxManager {
1337
1603
  }
1338
1604
  } else if (this.hasMinimizedBox()) {
1339
1605
  // 如果都最小化,则获取lastNotMinimizedBoxesStatus中normal box的最大y
1340
- vy = [...this.boxes].filter((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized && box.lastNotMinimizedBoxStatus && box.lastNotMinimizedBoxStatus === TELE_BOX_STATE.Normal).reduce((maxY, box) => {
1341
- return Math.max(maxY, box.intrinsicY * this.containerRect.height + 20);
1342
- }, vy);
1606
+ vy = [...this.boxes]
1607
+ .filter(
1608
+ (box) =>
1609
+ box.boxStatus &&
1610
+ box.boxStatus === TELE_BOX_STATE.Minimized &&
1611
+ box.lastNotMinimizedBoxStatus &&
1612
+ box.lastNotMinimizedBoxStatus ===
1613
+ TELE_BOX_STATE.Normal
1614
+ )
1615
+ .reduce((maxY, box) => {
1616
+ return Math.max(
1617
+ maxY,
1618
+ box.intrinsicY * this.containerRect.height + 20
1619
+ );
1620
+ }, vy);
1343
1621
  }
1344
1622
 
1345
1623
  y = vy / this.containerRect.height;
@@ -1364,12 +1642,16 @@ export class TeleBoxManager {
1364
1642
  }
1365
1643
  let maximizedBox: MaxTitleBarTeleBox | undefined;
1366
1644
  if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
1367
- maximizedBox = this.maxTitleBar.MaximizedBoxes.reduce((topBox, currentBox) => {
1368
- if (!topBox) {
1369
- return currentBox;
1645
+ maximizedBox = this.maxTitleBar.MaximizedBoxes.reduce(
1646
+ (topBox, currentBox) => {
1647
+ if (!topBox) {
1648
+ return currentBox;
1649
+ }
1650
+ return topBox.zIndex > currentBox.zIndex
1651
+ ? topBox
1652
+ : currentBox;
1370
1653
  }
1371
- return topBox.zIndex > currentBox.zIndex ? topBox : currentBox;
1372
- }, );
1654
+ );
1373
1655
  }
1374
1656
  return maximizedBox;
1375
1657
  }
@@ -1378,7 +1660,8 @@ export class TeleBoxManager {
1378
1660
  if (!this.useBoxesStatus) {
1379
1661
  return;
1380
1662
  }
1381
- const maximizedBox: MaxTitleBarTeleBox | undefined = this.getMaximizedTopBox();
1663
+ const maximizedBox: MaxTitleBarTeleBox | undefined =
1664
+ this.getMaximizedTopBox();
1382
1665
  this.maxTitleBar.focusBox(maximizedBox);
1383
1666
  }
1384
1667
 
@@ -1394,15 +1677,15 @@ export class TeleBoxManager {
1394
1677
  : boxOrID;
1395
1678
  }
1396
1679
 
1397
- public createMinimizedAppMenu():AppMenu | undefined {
1680
+ public createMinimizedAppMenu(): AppMenu | undefined {
1398
1681
  if (this.collector?.$appMenuContainer) {
1399
1682
  return new AppMenu({
1400
1683
  manager: this,
1401
1684
  container: this.collector?.$appMenuContainer,
1402
- theme: this.prefersColorScheme ? 'dark' : 'light',
1685
+ theme: this.prefersColorScheme ? "dark" : "light",
1403
1686
  getBoxesStatus: () => {
1404
1687
  return this.boxesStatus$;
1405
- }
1688
+ },
1406
1689
  });
1407
1690
  }
1408
1691
  return;