@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.
@@ -2688,6 +2688,7 @@ class TeleBoxManager {
2688
2688
  this.setBoxStatus(box.id, TELE_BOX_STATE.Normal);
2689
2689
  }
2690
2690
  });
2691
+ this.effectBoxStatusChange();
2691
2692
  }
2692
2693
  minimized$.setValue(false);
2693
2694
  }
@@ -2782,6 +2783,7 @@ class TeleBoxManager {
2782
2783
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
2783
2784
  if (this.hasBoxesStatus() && ((_a = this.maxTitleBar.focusedBox) == null ? void 0 : _a.id)) {
2784
2785
  this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Normal);
2786
+ this.effectBoxStatusChange();
2785
2787
  this.makeMaximizedTopBoxFocus();
2786
2788
  } else {
2787
2789
  maximized$.setValue(!maximized$.value);
@@ -2791,6 +2793,7 @@ class TeleBoxManager {
2791
2793
  case TELE_BOX_DELEGATE_EVENT.Minimize: {
2792
2794
  if (this.hasBoxesStatus() && ((_b = this.maxTitleBar.focusedBox) == null ? void 0 : _b.id)) {
2793
2795
  this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Minimized);
2796
+ this.effectBoxStatusChange();
2794
2797
  this.makeMaximizedTopBoxFocus();
2795
2798
  } else {
2796
2799
  minimized$.setValue(true);
@@ -2864,33 +2867,50 @@ class TeleBoxManager {
2864
2867
  return this;
2865
2868
  }
2866
2869
  setBoxStatus(boxId, boxStatus, skipUpdate = false) {
2867
- const boxesStatus = this.boxesStatus$;
2868
2870
  if (boxStatus) {
2869
- const oldBoxStatus = boxesStatus.get(boxId);
2870
- boxesStatus.set(boxId, boxStatus);
2871
+ const oldBoxStatus = this.boxesStatus$.get(boxId);
2872
+ this.boxesStatus$.set(boxId, boxStatus);
2871
2873
  if (boxStatus === TELE_BOX_STATE.Minimized && oldBoxStatus !== TELE_BOX_STATE.Minimized) {
2872
2874
  this.setLastNotMinimizedBoxStatus(boxId, oldBoxStatus, skipUpdate);
2875
+ this.effectLastNotMinimizedBoxStatusChange();
2873
2876
  } else if (oldBoxStatus === TELE_BOX_STATE.Minimized && boxStatus !== TELE_BOX_STATE.Minimized) {
2874
2877
  this.setLastNotMinimizedBoxStatus(boxId, void 0, skipUpdate);
2878
+ this.effectLastNotMinimizedBoxStatusChange();
2875
2879
  }
2876
2880
  } else {
2877
- boxesStatus.delete(boxId);
2881
+ this.boxesStatus$.delete(boxId);
2878
2882
  this.setLastNotMinimizedBoxStatus(boxId, void 0, skipUpdate);
2883
+ this.effectLastNotMinimizedBoxStatusChange();
2879
2884
  }
2880
- this.setBoxesStatus(boxesStatus, skipUpdate);
2881
2885
  if (!skipUpdate) {
2882
2886
  this.events.emit(TELE_BOX_MANAGER_EVENT.BoxStatus, { id: boxId, boxStatus });
2883
2887
  }
2884
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
+ }
2885
2901
  setBoxesStatus(boxesStatus, skipUpdate = false) {
2886
- var _a, _b, _c, _d;
2887
2902
  this.boxesStatus$ = boxesStatus;
2903
+ this.effectBoxStatusChange(skipUpdate);
2904
+ }
2905
+ effectBoxStatusTimerFunc(skipUpdate) {
2906
+ var _a, _b, _c, _d;
2907
+ this.effectBoxStatusTimer = void 0;
2888
2908
  let topBox;
2889
2909
  const topBoxId = (_a = this.topBox) == null ? void 0 : _a.id;
2890
2910
  let hasMinimizedBox = false;
2891
2911
  this.boxes.forEach((box) => {
2892
2912
  var _a2;
2893
- const boxStatus = boxesStatus.get(box.id);
2913
+ const boxStatus = this.boxesStatus$.get(box.id);
2894
2914
  if (boxStatus) {
2895
2915
  if (boxStatus !== TELE_BOX_STATE.Minimized && box.zIndex > ((_a2 = topBox == null ? void 0 : topBox.zIndex) != null ? _a2 : 0)) {
2896
2916
  topBox = box;
@@ -2917,6 +2937,28 @@ class TeleBoxManager {
2917
2937
  if (this.maxTitleBar) {
2918
2938
  this.maxTitleBar.updateBoxesStatus();
2919
2939
  }
2940
+ console.log("effectBoxStatusTimerFunc===>end", skipUpdate, this.boxes$.value.map((b) => ({ id: b.id, focus: b.focus, boxStatus: b.boxStatus, zIndex: b.zIndex })));
2941
+ }
2942
+ effectBoxStatusChange(skipUpdate = false) {
2943
+ var _a, _b;
2944
+ if (this.effectBoxStatusTimer && this.effectBoxStatusTimer.timer) {
2945
+ clearTimeout(this.effectBoxStatusTimer.timer);
2946
+ if (this.effectBoxStatusTimer.skipUpdate !== skipUpdate) {
2947
+ this.effectBoxStatusTimer.skipUpdate = skipUpdate;
2948
+ console.log("effectBoxStatusTimerFunc===>1111", skipUpdate);
2949
+ this.effectBoxStatusTimerFunc(this.effectBoxStatusTimer.skipUpdate);
2950
+ }
2951
+ }
2952
+ if (!this.effectBoxStatusTimer) {
2953
+ this.effectBoxStatusTimer = {
2954
+ skipUpdate,
2955
+ timer: void 0
2956
+ };
2957
+ }
2958
+ console.log("effectBoxStatusTimerFunc===>000", skipUpdate, { id: (_a = this.topBox$.value) == null ? void 0 : _a.id, zIndex: (_b = this.topBox$.value) == null ? void 0 : _b.zIndex }, this.boxes$.value.map((b) => ({ id: b.id, focus: b.focus, boxStatus: b.boxStatus, zIndex: b.zIndex })));
2959
+ this.effectBoxStatusTimer.timer = setTimeout(() => {
2960
+ this.effectBoxStatusTimerFunc(skipUpdate);
2961
+ }, 100);
2920
2962
  }
2921
2963
  hasBoxesStatus() {
2922
2964
  return this.boxesStatus$.size > 0;
@@ -2925,24 +2967,23 @@ class TeleBoxManager {
2925
2967
  return this.boxes.some((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized);
2926
2968
  }
2927
2969
  setLastNotMinimizedBoxStatus(boxId, lastNotMinimizedBoxStatus, skipUpdate = false) {
2928
- const boxesStatus = this.lastNotMinimizedBoxesStatus$;
2929
2970
  if (lastNotMinimizedBoxStatus) {
2930
- boxesStatus.set(boxId, lastNotMinimizedBoxStatus);
2971
+ this.lastNotMinimizedBoxesStatus$.set(boxId, lastNotMinimizedBoxStatus);
2931
2972
  } else {
2932
- boxesStatus.delete(boxId);
2973
+ this.lastNotMinimizedBoxesStatus$.delete(boxId);
2933
2974
  }
2934
- this.setLastNotMinimizedBoxesStatus(boxesStatus, skipUpdate);
2935
2975
  if (!skipUpdate) {
2936
2976
  this.events.emit(TELE_BOX_MANAGER_EVENT.LastNotMinimizedBoxStatus, { id: boxId, boxStatus: lastNotMinimizedBoxStatus });
2937
2977
  }
2938
2978
  }
2939
2979
  setLastNotMinimizedBoxesStatus(lastNotMinimizedBoxesStatus, skipUpdate = false) {
2940
2980
  this.lastNotMinimizedBoxesStatus$ = lastNotMinimizedBoxesStatus;
2981
+ this.effectLastNotMinimizedBoxStatusChange(skipUpdate);
2982
+ }
2983
+ effectLastNotMinimizedBoxStatusChange(skipUpdate = false) {
2941
2984
  this.boxes.forEach((box) => {
2942
- const boxStatus = lastNotMinimizedBoxesStatus.get(box.id);
2943
- if (boxStatus) {
2944
- box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
2945
- }
2985
+ const boxStatus = this.lastNotMinimizedBoxesStatus$.get(box.id);
2986
+ box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
2946
2987
  });
2947
2988
  }
2948
2989
  getAllMinimizedBoxes() {
@@ -2972,9 +3013,11 @@ class TeleBoxManager {
2972
3013
  this.boxes$.setValue([...this.boxes, box]);
2973
3014
  if (box.boxStatus) {
2974
3015
  this.setBoxStatus(box.id, box.boxStatus, true);
3016
+ this.effectBoxStatusChange(true);
2975
3017
  }
2976
3018
  if (box._lastNotMinimizedBoxStatus$.value) {
2977
3019
  this.setLastNotMinimizedBoxStatus(box.id, box._lastNotMinimizedBoxStatus$.value, true);
3020
+ this.effectLastNotMinimizedBoxStatusChange();
2978
3021
  }
2979
3022
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
2980
3023
  if (box.boxStatus) {
@@ -2987,6 +3030,7 @@ class TeleBoxManager {
2987
3030
  }
2988
3031
  });
2989
3032
  }
3033
+ this.effectBoxStatusChange();
2990
3034
  this.makeMaximizedTopBoxFocus();
2991
3035
  } else {
2992
3036
  this.setMaximized(!this.maximized);
@@ -2996,6 +3040,7 @@ class TeleBoxManager {
2996
3040
  if (box.boxStatus) {
2997
3041
  const oldBoxStatus = box.boxStatus;
2998
3042
  this.setBoxStatus(box.id, TELE_BOX_STATE.Minimized);
3043
+ this.effectBoxStatusChange();
2999
3044
  if (oldBoxStatus === TELE_BOX_STATE.Maximized) {
3000
3045
  this.makeMaximizedTopBoxFocus();
3001
3046
  }
@@ -3068,10 +3113,6 @@ class TeleBoxManager {
3068
3113
  }
3069
3114
  remove(boxOrID, skipUpdate = false) {
3070
3115
  const box = this.getBox(boxOrID);
3071
- if (box) {
3072
- this.setBoxStatus(box.id, void 0, skipUpdate);
3073
- this.setLastNotMinimizedBoxStatus(box.id, void 0, skipUpdate);
3074
- }
3075
3116
  const index2 = this.getBoxIndex(boxOrID);
3076
3117
  if (index2 >= 0) {
3077
3118
  const boxes = this.boxes.slice();
@@ -3079,8 +3120,12 @@ class TeleBoxManager {
3079
3120
  this.boxes$.setValue(boxes);
3080
3121
  deletedBoxes.forEach((box2) => box2.destroy());
3081
3122
  if (box) {
3123
+ this.setBoxStatus(box.id, void 0, skipUpdate);
3082
3124
  this.boxesStatus$.delete(box.id);
3125
+ this.effectBoxStatusChange(skipUpdate);
3126
+ this.setLastNotMinimizedBoxStatus(box.id, void 0, skipUpdate);
3083
3127
  this.lastNotMinimizedBoxesStatus$.delete(box.id);
3128
+ this.effectLastNotMinimizedBoxStatusChange();
3084
3129
  }
3085
3130
  if (!skipUpdate) {
3086
3131
  if (this.boxes.length <= 0) {
@@ -3236,9 +3281,11 @@ class TeleBoxManager {
3236
3281
  }
3237
3282
  if (config.boxStatus) {
3238
3283
  this.setBoxStatus(box.id, config.boxStatus, skipUpdate);
3284
+ this.effectBoxStatusChange(skipUpdate);
3239
3285
  }
3240
3286
  if (config.lastNotMinimizedBoxStatus) {
3241
3287
  this.setLastNotMinimizedBoxStatus(box.id, config.lastNotMinimizedBoxStatus, skipUpdate);
3288
+ this.effectLastNotMinimizedBoxStatusChange();
3242
3289
  }
3243
3290
  }
3244
3291
  smartPosition(config = {}) {
@@ -3269,10 +3316,25 @@ class TeleBoxManager {
3269
3316
  makeBoxTop(box, skipUpdate = false) {
3270
3317
  if (this.topBox) {
3271
3318
  if (box !== this.topBox) {
3272
- const currentBoxZIndex = box.zIndex;
3273
- const addZIndex = this.topBox.zIndex + 1 - box.zIndex;
3274
- box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
3275
- this.makeTopBoxEffect(box.id, addZIndex, currentBoxZIndex, skipUpdate);
3319
+ if (!this.hasBoxesStatus()) {
3320
+ box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
3321
+ return;
3322
+ }
3323
+ const maxZIndex = this.boxes.reduce((maxZIndex2, box2) => {
3324
+ return Math.max(maxZIndex2, box2.zIndex);
3325
+ }, 0);
3326
+ const currentTopBoxZIndex = Math.min(this.topBox.zIndex, box.zIndex);
3327
+ const addZIndex = maxZIndex + 1 - currentTopBoxZIndex;
3328
+ box.setZIndex(maxZIndex + 1, skipUpdate);
3329
+ console.log("makeBoxTop===>", box.id, maxZIndex + 1, addZIndex, this.topBox.id, currentTopBoxZIndex);
3330
+ if (box.boxStatus !== TELE_BOX_STATE.Minimized) {
3331
+ this.boxes.forEach((b) => {
3332
+ if (b.boxStatus === TELE_BOX_STATE.Minimized && b.zIndex >= currentTopBoxZIndex) {
3333
+ console.log("makeBoxTop===>111", b.id, b.zIndex + addZIndex);
3334
+ b.setZIndex(b.zIndex + addZIndex, skipUpdate);
3335
+ }
3336
+ });
3337
+ }
3276
3338
  }
3277
3339
  }
3278
3340
  }
@@ -3290,15 +3352,6 @@ class TeleBoxManager {
3290
3352
  }
3291
3353
  }
3292
3354
  }
3293
- makeTopBoxEffect(boxId, addZIndex, currentZIndex, skipUpdate = false) {
3294
- if (this.hasBoxesStatus() && this.hasMinimizedBox()) {
3295
- this.boxes.forEach((b) => {
3296
- if (b.boxStatus && b.id !== boxId && b.zIndex >= currentZIndex) {
3297
- b.setZIndex(b.zIndex + addZIndex, skipUpdate);
3298
- }
3299
- });
3300
- }
3301
- }
3302
3355
  makeMaximizedBoxFocus(maximizedBox, skipUpdate = false) {
3303
3356
  if (this.maxTitleBar.hasMaximizedBoxInStatus() && this.maxTitleBar.MaximizedBoxes.find((box) => box.id === maximizedBox.id)) {
3304
3357
  const currentZIndex = maximizedBox.zIndex;