@netless/telebox-insider 0.3.0-beta.2 → 0.3.0-beta.4

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.
@@ -2416,20 +2416,26 @@ class MaxTitleBar extends DefaultTitleBar {
2416
2416
  this.focusedBox = config.focusedBox;
2417
2417
  this.containerRect = config.containerRect;
2418
2418
  this.darkMode = config.darkMode;
2419
- this.boxesStatus = config.boxesStatus;
2419
+ this.getBoxesStatus = config.getBoxesStatus;
2420
2420
  }
2421
2421
  hasMaximizedBoxInStatus() {
2422
- if (!this.boxesStatus || this.boxesStatus.size === 0) {
2423
- return false;
2422
+ if (this.getBoxesStatus) {
2423
+ const boxesStatus = this.getBoxesStatus();
2424
+ if (boxesStatus.size) {
2425
+ const hasMaximizedBox = [...boxesStatus.values()].find((state) => state === TELE_BOX_STATE.Maximized);
2426
+ return !!hasMaximizedBox;
2427
+ }
2424
2428
  }
2425
- const hasMaximizedBox = [...this.boxesStatus.values()].find((state) => state === TELE_BOX_STATE.Maximized);
2426
- return !!hasMaximizedBox;
2429
+ return false;
2427
2430
  }
2428
2431
  get MaximizedBoxes() {
2429
- if (!this.boxesStatus || this.boxesStatus.size === 0) {
2430
- return [];
2432
+ if (this.getBoxesStatus) {
2433
+ const boxesStatus = this.getBoxesStatus();
2434
+ if (boxesStatus) {
2435
+ return this.boxes.filter((box) => boxesStatus && boxesStatus.get(box.id) === TELE_BOX_STATE.Maximized);
2436
+ }
2431
2437
  }
2432
- return this.boxes.filter((box) => this.boxesStatus && this.boxesStatus.get(box.id) === TELE_BOX_STATE.Maximized);
2438
+ return [];
2433
2439
  }
2434
2440
  focusBox(box) {
2435
2441
  var _a, _b;
@@ -2474,8 +2480,7 @@ class MaxTitleBar extends DefaultTitleBar {
2474
2480
  this.$titleBar.style.width = width + "px";
2475
2481
  }
2476
2482
  }
2477
- setBoxesStatus(boxesStatus) {
2478
- this.boxesStatus = boxesStatus;
2483
+ updateBoxesStatus() {
2479
2484
  if (this.hasMaximizedBoxInStatus()) {
2480
2485
  this.setBoxStatus(TELE_BOX_STATE.Maximized);
2481
2486
  }
@@ -2683,6 +2688,7 @@ class TeleBoxManager {
2683
2688
  this.setBoxStatus(box.id, TELE_BOX_STATE.Normal);
2684
2689
  }
2685
2690
  });
2691
+ this.effectBoxStatusChange();
2686
2692
  }
2687
2693
  minimized$.setValue(false);
2688
2694
  }
@@ -2768,13 +2774,16 @@ class TeleBoxManager {
2768
2774
  state: state$.value,
2769
2775
  boxes: this.boxes$.value,
2770
2776
  containerRect: containerRect$.value,
2771
- boxesStatus: this.boxesStatus$,
2777
+ getBoxesStatus: () => {
2778
+ return this.boxesStatus$;
2779
+ },
2772
2780
  onEvent: (event) => {
2773
2781
  var _a, _b, _c;
2774
2782
  switch (event.type) {
2775
2783
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
2776
2784
  if (this.hasBoxesStatus() && ((_a = this.maxTitleBar.focusedBox) == null ? void 0 : _a.id)) {
2777
2785
  this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Normal);
2786
+ this.effectBoxStatusChange();
2778
2787
  this.makeMaximizedTopBoxFocus();
2779
2788
  } else {
2780
2789
  maximized$.setValue(!maximized$.value);
@@ -2784,6 +2793,7 @@ class TeleBoxManager {
2784
2793
  case TELE_BOX_DELEGATE_EVENT.Minimize: {
2785
2794
  if (this.hasBoxesStatus() && ((_b = this.maxTitleBar.focusedBox) == null ? void 0 : _b.id)) {
2786
2795
  this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Minimized);
2796
+ this.effectBoxStatusChange();
2787
2797
  this.makeMaximizedTopBoxFocus();
2788
2798
  } else {
2789
2799
  minimized$.setValue(true);
@@ -2857,32 +2867,49 @@ class TeleBoxManager {
2857
2867
  return this;
2858
2868
  }
2859
2869
  setBoxStatus(boxId, boxStatus, skipUpdate = false) {
2860
- const boxesStatus = this.boxesStatus$;
2861
2870
  if (boxStatus) {
2862
- const oldBoxStatus = boxesStatus.get(boxId);
2863
- boxesStatus.set(boxId, boxStatus);
2871
+ const oldBoxStatus = this.boxesStatus$.get(boxId);
2872
+ this.boxesStatus$.set(boxId, boxStatus);
2864
2873
  if (boxStatus === TELE_BOX_STATE.Minimized && oldBoxStatus !== TELE_BOX_STATE.Minimized) {
2865
2874
  this.setLastNotMinimizedBoxStatus(boxId, oldBoxStatus, skipUpdate);
2875
+ this.effectLastNotMinimizedBoxStatusChange();
2866
2876
  } else if (oldBoxStatus === TELE_BOX_STATE.Minimized && boxStatus !== TELE_BOX_STATE.Minimized) {
2867
2877
  this.setLastNotMinimizedBoxStatus(boxId, void 0, skipUpdate);
2878
+ this.effectLastNotMinimizedBoxStatusChange();
2868
2879
  }
2869
2880
  } else {
2870
- boxesStatus.delete(boxId);
2881
+ this.boxesStatus$.delete(boxId);
2871
2882
  this.setLastNotMinimizedBoxStatus(boxId, void 0, skipUpdate);
2883
+ this.effectLastNotMinimizedBoxStatusChange();
2872
2884
  }
2873
- this.setBoxesStatus(boxesStatus, skipUpdate);
2874
2885
  if (!skipUpdate) {
2875
2886
  this.events.emit(TELE_BOX_MANAGER_EVENT.BoxStatus, { id: boxId, boxStatus });
2876
2887
  }
2877
2888
  }
2889
+ getBoxStatus(boxId) {
2890
+ return this.boxesStatus$.get(boxId);
2891
+ }
2892
+ getLastNotMinimizedBoxStatus(boxId) {
2893
+ return this.lastNotMinimizedBoxesStatus$.get(boxId);
2894
+ }
2895
+ get boxesStatus() {
2896
+ return this.boxesStatus$;
2897
+ }
2898
+ get lastNotMinimizedBoxesStatus() {
2899
+ return this.lastNotMinimizedBoxesStatus$;
2900
+ }
2878
2901
  setBoxesStatus(boxesStatus, skipUpdate = false) {
2902
+ this.boxesStatus$ = boxesStatus;
2903
+ this.effectBoxStatusChange(skipUpdate);
2904
+ }
2905
+ effectBoxStatusChange(skipUpdate = false) {
2879
2906
  var _a, _b, _c, _d;
2880
2907
  let topBox;
2881
2908
  const topBoxId = (_a = this.topBox) == null ? void 0 : _a.id;
2882
2909
  let hasMinimizedBox = false;
2883
2910
  this.boxes.forEach((box) => {
2884
2911
  var _a2;
2885
- const boxStatus = boxesStatus.get(box.id);
2912
+ const boxStatus = this.boxesStatus$.get(box.id);
2886
2913
  if (boxStatus) {
2887
2914
  if (boxStatus !== TELE_BOX_STATE.Minimized && box.zIndex > ((_a2 = topBox == null ? void 0 : topBox.zIndex) != null ? _a2 : 0)) {
2888
2915
  topBox = box;
@@ -2907,7 +2934,7 @@ class TeleBoxManager {
2907
2934
  this.focusTopBox();
2908
2935
  }
2909
2936
  if (this.maxTitleBar) {
2910
- this.maxTitleBar.setBoxesStatus(boxesStatus);
2937
+ this.maxTitleBar.updateBoxesStatus();
2911
2938
  }
2912
2939
  }
2913
2940
  hasBoxesStatus() {
@@ -2917,23 +2944,23 @@ class TeleBoxManager {
2917
2944
  return this.boxes.some((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized);
2918
2945
  }
2919
2946
  setLastNotMinimizedBoxStatus(boxId, lastNotMinimizedBoxStatus, skipUpdate = false) {
2920
- const boxesStatus = this.lastNotMinimizedBoxesStatus$;
2921
2947
  if (lastNotMinimizedBoxStatus) {
2922
- boxesStatus.set(boxId, lastNotMinimizedBoxStatus);
2948
+ this.lastNotMinimizedBoxesStatus$.set(boxId, lastNotMinimizedBoxStatus);
2923
2949
  } else {
2924
- boxesStatus.delete(boxId);
2950
+ this.lastNotMinimizedBoxesStatus$.delete(boxId);
2925
2951
  }
2926
- this.setLastNotMinimizedBoxesStatus(boxesStatus, skipUpdate);
2927
2952
  if (!skipUpdate) {
2928
2953
  this.events.emit(TELE_BOX_MANAGER_EVENT.LastNotMinimizedBoxStatus, { id: boxId, boxStatus: lastNotMinimizedBoxStatus });
2929
2954
  }
2930
2955
  }
2931
2956
  setLastNotMinimizedBoxesStatus(lastNotMinimizedBoxesStatus, skipUpdate = false) {
2957
+ this.lastNotMinimizedBoxesStatus$ = lastNotMinimizedBoxesStatus;
2958
+ this.effectLastNotMinimizedBoxStatusChange(skipUpdate);
2959
+ }
2960
+ effectLastNotMinimizedBoxStatusChange(skipUpdate = false) {
2932
2961
  this.boxes.forEach((box) => {
2933
- const boxStatus = lastNotMinimizedBoxesStatus.get(box.id);
2934
- if (boxStatus) {
2935
- box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
2936
- }
2962
+ const boxStatus = this.lastNotMinimizedBoxesStatus$.get(box.id);
2963
+ box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
2937
2964
  });
2938
2965
  }
2939
2966
  getAllMinimizedBoxes() {
@@ -2963,9 +2990,11 @@ class TeleBoxManager {
2963
2990
  this.boxes$.setValue([...this.boxes, box]);
2964
2991
  if (box.boxStatus) {
2965
2992
  this.setBoxStatus(box.id, box.boxStatus, true);
2993
+ this.effectBoxStatusChange(true);
2966
2994
  }
2967
2995
  if (box._lastNotMinimizedBoxStatus$.value) {
2968
2996
  this.setLastNotMinimizedBoxStatus(box.id, box._lastNotMinimizedBoxStatus$.value, true);
2997
+ this.effectLastNotMinimizedBoxStatusChange();
2969
2998
  }
2970
2999
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
2971
3000
  if (box.boxStatus) {
@@ -2978,6 +3007,7 @@ class TeleBoxManager {
2978
3007
  }
2979
3008
  });
2980
3009
  }
3010
+ this.effectBoxStatusChange();
2981
3011
  this.makeMaximizedTopBoxFocus();
2982
3012
  } else {
2983
3013
  this.setMaximized(!this.maximized);
@@ -2987,6 +3017,7 @@ class TeleBoxManager {
2987
3017
  if (box.boxStatus) {
2988
3018
  const oldBoxStatus = box.boxStatus;
2989
3019
  this.setBoxStatus(box.id, TELE_BOX_STATE.Minimized);
3020
+ this.effectBoxStatusChange();
2990
3021
  if (oldBoxStatus === TELE_BOX_STATE.Maximized) {
2991
3022
  this.makeMaximizedTopBoxFocus();
2992
3023
  }
@@ -3059,16 +3090,20 @@ class TeleBoxManager {
3059
3090
  }
3060
3091
  remove(boxOrID, skipUpdate = false) {
3061
3092
  const box = this.getBox(boxOrID);
3062
- if (box) {
3063
- this.setBoxStatus(box.id, void 0, skipUpdate);
3064
- this.setLastNotMinimizedBoxStatus(box.id, void 0, skipUpdate);
3065
- }
3066
3093
  const index2 = this.getBoxIndex(boxOrID);
3067
3094
  if (index2 >= 0) {
3068
3095
  const boxes = this.boxes.slice();
3069
3096
  const deletedBoxes = boxes.splice(index2, 1);
3070
3097
  this.boxes$.setValue(boxes);
3071
3098
  deletedBoxes.forEach((box2) => box2.destroy());
3099
+ if (box) {
3100
+ this.setBoxStatus(box.id, void 0, skipUpdate);
3101
+ this.boxesStatus$.delete(box.id);
3102
+ this.effectBoxStatusChange(skipUpdate);
3103
+ this.setLastNotMinimizedBoxStatus(box.id, void 0, skipUpdate);
3104
+ this.lastNotMinimizedBoxesStatus$.delete(box.id);
3105
+ this.effectLastNotMinimizedBoxStatusChange();
3106
+ }
3072
3107
  if (!skipUpdate) {
3073
3108
  if (this.boxes.length <= 0) {
3074
3109
  this.setMaximized(false);
@@ -3223,9 +3258,11 @@ class TeleBoxManager {
3223
3258
  }
3224
3259
  if (config.boxStatus) {
3225
3260
  this.setBoxStatus(box.id, config.boxStatus, skipUpdate);
3261
+ this.effectBoxStatusChange(skipUpdate);
3226
3262
  }
3227
3263
  if (config.lastNotMinimizedBoxStatus) {
3228
3264
  this.setLastNotMinimizedBoxStatus(box.id, config.lastNotMinimizedBoxStatus, skipUpdate);
3265
+ this.effectLastNotMinimizedBoxStatusChange();
3229
3266
  }
3230
3267
  }
3231
3268
  smartPosition(config = {}) {