@netless/telebox-insider 0.3.0-beta.3 → 0.3.0-beta.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/telebox-insider",
3
- "version": "0.3.0-beta.3",
3
+ "version": "0.3.0-beta.5",
4
4
  "private": false,
5
5
  "description": "Window widget for Whiteboard",
6
6
  "author": "CRIMX <straybugs@gmail.com> (https://github.com/crimx/)",
@@ -49,6 +49,14 @@ export interface TeleBoxManager extends ValEnhancedResult<ValConfig> {}
49
49
  export class TeleBoxManager {
50
50
  private boxesStatus$: Map<string, TeleBoxState>;
51
51
  private lastNotMinimizedBoxesStatus$: Map<string, NotMinimizedBoxState>;
52
+ private effectBoxStatusTimer?: {
53
+ skipUpdate: boolean;
54
+ timer: number | undefined;
55
+ }
56
+ private effectLastNotMinimizedBoxStatusTimer?: {
57
+ skipUpdate: boolean;
58
+ timer: number | undefined;
59
+ }
52
60
 
53
61
  public constructor({
54
62
  root = document.body,
@@ -201,6 +209,7 @@ export class TeleBoxManager {
201
209
  this.setBoxStatus(box.id, TELE_BOX_STATE.Normal);
202
210
  }
203
211
  });
212
+ this.effectBoxStatusChange();
204
213
  }
205
214
  minimized$.setValue(false);
206
215
  }
@@ -323,6 +332,7 @@ export class TeleBoxManager {
323
332
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
324
333
  if (this.hasBoxesStatus() && this.maxTitleBar.focusedBox?.id) {
325
334
  this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Normal);
335
+ this.effectBoxStatusChange();
326
336
  this.makeMaximizedTopBoxFocus();
327
337
  } else {
328
338
  maximized$.setValue(!maximized$.value);
@@ -332,6 +342,7 @@ export class TeleBoxManager {
332
342
  case TELE_BOX_DELEGATE_EVENT.Minimize: {
333
343
  if (this.hasBoxesStatus() && this.maxTitleBar.focusedBox?.id) {
334
344
  this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Minimized);
345
+ this.effectBoxStatusChange();
335
346
  this.makeMaximizedTopBoxFocus();
336
347
  } else {
337
348
  minimized$.setValue(true);
@@ -435,32 +446,55 @@ export class TeleBoxManager {
435
446
  }
436
447
 
437
448
  public setBoxStatus(boxId: string, boxStatus?: TeleBoxState, skipUpdate = false): void {
438
- const boxesStatus = this.boxesStatus$;
439
449
  if (boxStatus) {
440
- const oldBoxStatus = boxesStatus.get(boxId);
441
- boxesStatus.set(boxId, boxStatus);
450
+ const oldBoxStatus = this.boxesStatus$.get(boxId);
451
+ this.boxesStatus$.set(boxId, boxStatus);
442
452
  if (boxStatus === TELE_BOX_STATE.Minimized && oldBoxStatus !== TELE_BOX_STATE.Minimized) {
443
453
  this.setLastNotMinimizedBoxStatus(boxId, oldBoxStatus, skipUpdate);
454
+ this.effectLastNotMinimizedBoxStatusChange();
444
455
  } else if (oldBoxStatus === TELE_BOX_STATE.Minimized && boxStatus !== TELE_BOX_STATE.Minimized) {
445
456
  this.setLastNotMinimizedBoxStatus(boxId, undefined, skipUpdate);
457
+ this.effectLastNotMinimizedBoxStatusChange();
446
458
  }
447
459
  } else {
448
- boxesStatus.delete(boxId);
460
+ this.boxesStatus$.delete(boxId);
449
461
  this.setLastNotMinimizedBoxStatus(boxId, undefined, skipUpdate);
462
+ this.effectLastNotMinimizedBoxStatusChange();
450
463
  }
451
- this.setBoxesStatus(boxesStatus, skipUpdate);
452
464
  if (!skipUpdate) {
453
465
  this.events.emit(TELE_BOX_MANAGER_EVENT.BoxStatus, { id: boxId, boxStatus});
454
466
  }
455
467
  }
456
468
 
469
+ public getBoxStatus(boxId: string): TeleBoxState | undefined {
470
+ return this.boxesStatus$.get(boxId);
471
+ }
472
+
473
+ public getLastNotMinimizedBoxStatus(boxId: string): NotMinimizedBoxState | undefined {
474
+ return this.lastNotMinimizedBoxesStatus$.get(boxId);
475
+ }
476
+
477
+ public get boxesStatus(): ReadonlyMap<string, TeleBoxState> {
478
+ return this.boxesStatus$;
479
+ }
480
+
481
+ public get lastNotMinimizedBoxesStatus(): ReadonlyMap<string, NotMinimizedBoxState> {
482
+ return this.lastNotMinimizedBoxesStatus$;
483
+ }
484
+
457
485
  public setBoxesStatus(boxesStatus: Map<string, TeleBoxState>, skipUpdate = false): void {
458
486
  this.boxesStatus$ = boxesStatus;
487
+ this.effectBoxStatusChange(skipUpdate);
488
+ }
489
+
490
+
491
+ private effectBoxStatusTimerFunc(skipUpdate: boolean){
492
+ this.effectBoxStatusTimer = undefined;
459
493
  let topBox:TeleBox | undefined;
460
494
  const topBoxId = this.topBox?.id;
461
495
  let hasMinimizedBox = false;
462
496
  this.boxes.forEach((box) => {
463
- const boxStatus = boxesStatus.get(box.id);
497
+ const boxStatus = this.boxesStatus$.get(box.id);
464
498
  if (boxStatus) {
465
499
  if (boxStatus !== TELE_BOX_STATE.Minimized && box.zIndex > (topBox?.zIndex ?? 0)) {
466
500
  topBox = box;
@@ -489,6 +523,31 @@ export class TeleBoxManager {
489
523
  if (this.maxTitleBar) {
490
524
  this.maxTitleBar.updateBoxesStatus();
491
525
  }
526
+ console.log("effectBoxStatusTimerFunc===>end", skipUpdate, this.boxes$.value.map((b)=>({id:b.id,focus:b.focus, boxStatus:b.boxStatus,zIndex:b.zIndex})));
527
+ }
528
+
529
+ private effectBoxStatusChange(skipUpdate = false){
530
+ if (this.effectBoxStatusTimer && this.effectBoxStatusTimer.timer) {
531
+ clearTimeout(this.effectBoxStatusTimer.timer);
532
+ if (this.effectBoxStatusTimer.skipUpdate !== skipUpdate) {
533
+ this.effectBoxStatusTimer.skipUpdate = skipUpdate;
534
+ console.log("effectBoxStatusTimerFunc===>1111", skipUpdate);
535
+ this.effectBoxStatusTimerFunc(this.effectBoxStatusTimer.skipUpdate)
536
+ }
537
+ }
538
+ if (!this.effectBoxStatusTimer) {
539
+ this.effectBoxStatusTimer = {
540
+ skipUpdate,
541
+ timer: undefined,
542
+ } as {
543
+ skipUpdate: boolean;
544
+ timer: number | undefined;
545
+ }
546
+ }
547
+ console.log("effectBoxStatusTimerFunc===>000", skipUpdate, {id:this.topBox$.value?.id, zIndex:this.topBox$.value?.zIndex}, this.boxes$.value.map((b)=>({id:b.id,focus:b.focus, boxStatus:b.boxStatus,zIndex:b.zIndex})));
548
+ this.effectBoxStatusTimer.timer = setTimeout(()=>{
549
+ this.effectBoxStatusTimerFunc(skipUpdate)
550
+ }, 100) as unknown as number;
492
551
  }
493
552
 
494
553
  public hasBoxesStatus(): boolean {
@@ -500,13 +559,11 @@ export class TeleBoxManager {
500
559
  }
501
560
 
502
561
  public setLastNotMinimizedBoxStatus(boxId: string, lastNotMinimizedBoxStatus?: NotMinimizedBoxState, skipUpdate = false): void {
503
- const boxesStatus = this.lastNotMinimizedBoxesStatus$;
504
562
  if (lastNotMinimizedBoxStatus) {
505
- boxesStatus.set(boxId, lastNotMinimizedBoxStatus);
563
+ this.lastNotMinimizedBoxesStatus$.set(boxId, lastNotMinimizedBoxStatus);
506
564
  } else {
507
- boxesStatus.delete(boxId);
565
+ this.lastNotMinimizedBoxesStatus$.delete(boxId);
508
566
  }
509
- this.setLastNotMinimizedBoxesStatus(boxesStatus, skipUpdate);
510
567
  if (!skipUpdate) {
511
568
  this.events.emit(TELE_BOX_MANAGER_EVENT.LastNotMinimizedBoxStatus, { id: boxId, boxStatus:lastNotMinimizedBoxStatus});
512
569
  }
@@ -514,11 +571,13 @@ export class TeleBoxManager {
514
571
 
515
572
  public setLastNotMinimizedBoxesStatus(lastNotMinimizedBoxesStatus: Map<string, NotMinimizedBoxState>, skipUpdate = false): void {
516
573
  this.lastNotMinimizedBoxesStatus$ = lastNotMinimizedBoxesStatus;
574
+ this.effectLastNotMinimizedBoxStatusChange(skipUpdate);
575
+ }
576
+
577
+ private effectLastNotMinimizedBoxStatusChange(skipUpdate = false){
517
578
  this.boxes.forEach((box) => {
518
- const boxStatus = lastNotMinimizedBoxesStatus.get(box.id);
519
- if (boxStatus) {
520
- box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
521
- }
579
+ const boxStatus = this.lastNotMinimizedBoxesStatus$.get(box.id);
580
+ box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
522
581
  });
523
582
  }
524
583
 
@@ -557,10 +616,12 @@ export class TeleBoxManager {
557
616
 
558
617
  if (box.boxStatus) {
559
618
  this.setBoxStatus(box.id, box.boxStatus, true);
619
+ this.effectBoxStatusChange(true);
560
620
  }
561
621
 
562
622
  if (box._lastNotMinimizedBoxStatus$.value) {
563
623
  this.setLastNotMinimizedBoxStatus(box.id, box._lastNotMinimizedBoxStatus$.value, true);
624
+ this.effectLastNotMinimizedBoxStatusChange();
564
625
  }
565
626
 
566
627
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
@@ -574,6 +635,7 @@ export class TeleBoxManager {
574
635
  }
575
636
  });
576
637
  }
638
+ this.effectBoxStatusChange();
577
639
  this.makeMaximizedTopBoxFocus();
578
640
  } else {
579
641
  this.setMaximized(!this.maximized);
@@ -584,6 +646,7 @@ export class TeleBoxManager {
584
646
  if (box.boxStatus) {
585
647
  const oldBoxStatus = box.boxStatus;
586
648
  this.setBoxStatus(box.id, TELE_BOX_STATE.Minimized);
649
+ this.effectBoxStatusChange();
587
650
  if (oldBoxStatus === TELE_BOX_STATE.Maximized) {
588
651
  this.makeMaximizedTopBoxFocus();
589
652
  }
@@ -678,10 +741,6 @@ export class TeleBoxManager {
678
741
  skipUpdate = false
679
742
  ): ReadonlyTeleBox | undefined {
680
743
  const box = this.getBox(boxOrID);
681
- if (box) {
682
- this.setBoxStatus(box.id, undefined, skipUpdate);
683
- this.setLastNotMinimizedBoxStatus(box.id, undefined, skipUpdate);
684
- }
685
744
  const index = this.getBoxIndex(boxOrID);
686
745
  if (index >= 0) {
687
746
  const boxes = this.boxes.slice();
@@ -689,8 +748,12 @@ export class TeleBoxManager {
689
748
  this.boxes$.setValue(boxes);
690
749
  deletedBoxes.forEach((box) => box.destroy());
691
750
  if (box) {
751
+ this.setBoxStatus(box.id, undefined, skipUpdate);
692
752
  this.boxesStatus$.delete(box.id);
753
+ this.effectBoxStatusChange(skipUpdate);
754
+ this.setLastNotMinimizedBoxStatus(box.id, undefined, skipUpdate);
693
755
  this.lastNotMinimizedBoxesStatus$.delete(box.id);
756
+ this.effectLastNotMinimizedBoxStatusChange();
694
757
  }
695
758
  if (!skipUpdate) {
696
759
  if (this.boxes.length <= 0) {
@@ -882,9 +945,11 @@ export class TeleBoxManager {
882
945
  }
883
946
  if (config.boxStatus) {
884
947
  this.setBoxStatus(box.id, config.boxStatus, skipUpdate);
948
+ this.effectBoxStatusChange(skipUpdate);
885
949
  }
886
950
  if (config.lastNotMinimizedBoxStatus) {
887
951
  this.setLastNotMinimizedBoxStatus(box.id, config.lastNotMinimizedBoxStatus, skipUpdate);
952
+ this.effectLastNotMinimizedBoxStatusChange();
888
953
  }
889
954
  }
890
955
 
@@ -931,10 +996,25 @@ export class TeleBoxManager {
931
996
  protected makeBoxTop(box: TeleBox, skipUpdate = false): void {
932
997
  if (this.topBox) {
933
998
  if (box !== this.topBox) {
934
- const currentBoxZIndex = box.zIndex;
935
- const addZIndex = this.topBox.zIndex + 1 - box.zIndex;
936
- box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
937
- this.makeTopBoxEffect(box.id, addZIndex, currentBoxZIndex, skipUpdate);
999
+ if (!this.hasBoxesStatus()) {
1000
+ box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
1001
+ return;
1002
+ }
1003
+ const maxZIndex = this.boxes.reduce((maxZIndex, box) => {
1004
+ return Math.max(maxZIndex, box.zIndex);
1005
+ }, 0);
1006
+ const currentTopBoxZIndex = Math.min(this.topBox.zIndex, box.zIndex);
1007
+ const addZIndex = maxZIndex + 1 - currentTopBoxZIndex;
1008
+ box.setZIndex(maxZIndex + 1, skipUpdate);
1009
+ console.log("makeBoxTop===>", box.id, maxZIndex + 1, addZIndex, this.topBox.id, currentTopBoxZIndex);
1010
+ if (box.boxStatus !== TELE_BOX_STATE.Minimized) {
1011
+ this.boxes.forEach((b) => {
1012
+ if (b.boxStatus === TELE_BOX_STATE.Minimized && b.zIndex >= currentTopBoxZIndex) {
1013
+ console.log("makeBoxTop===>111", b.id, b.zIndex + addZIndex);
1014
+ b.setZIndex(b.zIndex + addZIndex, skipUpdate);
1015
+ }
1016
+ });
1017
+ }
938
1018
  }
939
1019
  }
940
1020
  }
@@ -954,16 +1034,6 @@ export class TeleBoxManager {
954
1034
  }
955
1035
  }
956
1036
 
957
- private makeTopBoxEffect(boxId: string, addZIndex: number, currentZIndex: number, skipUpdate = false): void {
958
- if (this.hasBoxesStatus() && this.hasMinimizedBox()) {
959
- this.boxes.forEach((b) => {
960
- if (b.boxStatus && b.id !== boxId && b.zIndex >= currentZIndex) {
961
- b.setZIndex(b.zIndex + addZIndex, skipUpdate);
962
- }
963
- });
964
- }
965
- }
966
-
967
1037
  protected makeMaximizedBoxFocus(maximizedBox: MaxTitleBarTeleBox, skipUpdate = false): void {
968
1038
  if (this.maxTitleBar.hasMaximizedBoxInStatus() && this.maxTitleBar.MaximizedBoxes.find((box) => box.id === maximizedBox.id)) {
969
1039
  const currentZIndex = maximizedBox.zIndex;