@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/dist/index.d.ts CHANGED
@@ -846,6 +846,8 @@ interface TeleBoxManager extends ValEnhancedResult<ValConfig> {
846
846
  declare class TeleBoxManager {
847
847
  private boxesStatus$;
848
848
  private lastNotMinimizedBoxesStatus$;
849
+ private effectBoxStatusTimer?;
850
+ private effectLastNotMinimizedBoxStatusTimer?;
849
851
  constructor({ root, prefersColorScheme, minimized, maximized, fence, containerRect, collector, namespace, readonly, }?: TeleBoxManagerConfig);
850
852
  get boxes(): ReadonlyArray<TeleBox>;
851
853
  get topBox(): TeleBox | undefined;
@@ -861,11 +863,18 @@ declare class TeleBoxManager {
861
863
  /** @deprecated use setMaximized and setMinimized instead */
862
864
  setState(state: TeleBoxState, skipUpdate?: boolean): this;
863
865
  setBoxStatus(boxId: string, boxStatus?: TeleBoxState, skipUpdate?: boolean): void;
866
+ getBoxStatus(boxId: string): TeleBoxState | undefined;
867
+ getLastNotMinimizedBoxStatus(boxId: string): NotMinimizedBoxState | undefined;
868
+ get boxesStatus(): ReadonlyMap<string, TeleBoxState>;
869
+ get lastNotMinimizedBoxesStatus(): ReadonlyMap<string, NotMinimizedBoxState>;
864
870
  setBoxesStatus(boxesStatus: Map<string, TeleBoxState>, skipUpdate?: boolean): void;
871
+ private effectBoxStatusTimerFunc;
872
+ private effectBoxStatusChange;
865
873
  hasBoxesStatus(): boolean;
866
874
  hasMinimizedBox(): boolean;
867
875
  setLastNotMinimizedBoxStatus(boxId: string, lastNotMinimizedBoxStatus?: NotMinimizedBoxState, skipUpdate?: boolean): void;
868
876
  setLastNotMinimizedBoxesStatus(lastNotMinimizedBoxesStatus: Map<string, NotMinimizedBoxState>, skipUpdate?: boolean): void;
877
+ private effectLastNotMinimizedBoxStatusChange;
869
878
  private getAllMinimizedBoxes;
870
879
  create(config?: TeleBoxManagerCreateConfig, smartPosition?: boolean): ReadonlyTeleBox;
871
880
  query(config?: TeleBoxManagerQueryConfig): ReadonlyTeleBox[];
@@ -889,7 +898,6 @@ declare class TeleBoxManager {
889
898
  protected smartPosition(config?: TeleBoxConfig): TeleBoxConfig;
890
899
  protected makeBoxTop(box: TeleBox, skipUpdate?: boolean): void;
891
900
  protected makeMaximizedTopBoxFocus(): void;
892
- private makeTopBoxEffect;
893
901
  protected makeMaximizedBoxFocus(maximizedBox: MaxTitleBarTeleBox, skipUpdate?: boolean): void;
894
902
  protected makeMaximizedBoxBlur(): void;
895
903
  protected getBoxIndex(boxOrID: TeleBox | string): number;
@@ -2691,6 +2691,7 @@ class TeleBoxManager {
2691
2691
  this.setBoxStatus(box.id, exports.TELE_BOX_STATE.Normal);
2692
2692
  }
2693
2693
  });
2694
+ this.effectBoxStatusChange();
2694
2695
  }
2695
2696
  minimized$.setValue(false);
2696
2697
  }
@@ -2785,6 +2786,7 @@ class TeleBoxManager {
2785
2786
  case exports.TELE_BOX_DELEGATE_EVENT.Maximize: {
2786
2787
  if (this.hasBoxesStatus() && ((_a = this.maxTitleBar.focusedBox) == null ? void 0 : _a.id)) {
2787
2788
  this.setBoxStatus(this.maxTitleBar.focusedBox.id, exports.TELE_BOX_STATE.Normal);
2789
+ this.effectBoxStatusChange();
2788
2790
  this.makeMaximizedTopBoxFocus();
2789
2791
  } else {
2790
2792
  maximized$.setValue(!maximized$.value);
@@ -2794,6 +2796,7 @@ class TeleBoxManager {
2794
2796
  case exports.TELE_BOX_DELEGATE_EVENT.Minimize: {
2795
2797
  if (this.hasBoxesStatus() && ((_b = this.maxTitleBar.focusedBox) == null ? void 0 : _b.id)) {
2796
2798
  this.setBoxStatus(this.maxTitleBar.focusedBox.id, exports.TELE_BOX_STATE.Minimized);
2799
+ this.effectBoxStatusChange();
2797
2800
  this.makeMaximizedTopBoxFocus();
2798
2801
  } else {
2799
2802
  minimized$.setValue(true);
@@ -2867,33 +2870,50 @@ class TeleBoxManager {
2867
2870
  return this;
2868
2871
  }
2869
2872
  setBoxStatus(boxId, boxStatus, skipUpdate = false) {
2870
- const boxesStatus = this.boxesStatus$;
2871
2873
  if (boxStatus) {
2872
- const oldBoxStatus = boxesStatus.get(boxId);
2873
- boxesStatus.set(boxId, boxStatus);
2874
+ const oldBoxStatus = this.boxesStatus$.get(boxId);
2875
+ this.boxesStatus$.set(boxId, boxStatus);
2874
2876
  if (boxStatus === exports.TELE_BOX_STATE.Minimized && oldBoxStatus !== exports.TELE_BOX_STATE.Minimized) {
2875
2877
  this.setLastNotMinimizedBoxStatus(boxId, oldBoxStatus, skipUpdate);
2878
+ this.effectLastNotMinimizedBoxStatusChange();
2876
2879
  } else if (oldBoxStatus === exports.TELE_BOX_STATE.Minimized && boxStatus !== exports.TELE_BOX_STATE.Minimized) {
2877
2880
  this.setLastNotMinimizedBoxStatus(boxId, void 0, skipUpdate);
2881
+ this.effectLastNotMinimizedBoxStatusChange();
2878
2882
  }
2879
2883
  } else {
2880
- boxesStatus.delete(boxId);
2884
+ this.boxesStatus$.delete(boxId);
2881
2885
  this.setLastNotMinimizedBoxStatus(boxId, void 0, skipUpdate);
2886
+ this.effectLastNotMinimizedBoxStatusChange();
2882
2887
  }
2883
- this.setBoxesStatus(boxesStatus, skipUpdate);
2884
2888
  if (!skipUpdate) {
2885
2889
  this.events.emit(exports.TELE_BOX_MANAGER_EVENT.BoxStatus, { id: boxId, boxStatus });
2886
2890
  }
2887
2891
  }
2892
+ getBoxStatus(boxId) {
2893
+ return this.boxesStatus$.get(boxId);
2894
+ }
2895
+ getLastNotMinimizedBoxStatus(boxId) {
2896
+ return this.lastNotMinimizedBoxesStatus$.get(boxId);
2897
+ }
2898
+ get boxesStatus() {
2899
+ return this.boxesStatus$;
2900
+ }
2901
+ get lastNotMinimizedBoxesStatus() {
2902
+ return this.lastNotMinimizedBoxesStatus$;
2903
+ }
2888
2904
  setBoxesStatus(boxesStatus, skipUpdate = false) {
2889
- var _a, _b, _c, _d;
2890
2905
  this.boxesStatus$ = boxesStatus;
2906
+ this.effectBoxStatusChange(skipUpdate);
2907
+ }
2908
+ effectBoxStatusTimerFunc(skipUpdate) {
2909
+ var _a, _b, _c, _d;
2910
+ this.effectBoxStatusTimer = void 0;
2891
2911
  let topBox;
2892
2912
  const topBoxId = (_a = this.topBox) == null ? void 0 : _a.id;
2893
2913
  let hasMinimizedBox = false;
2894
2914
  this.boxes.forEach((box) => {
2895
2915
  var _a2;
2896
- const boxStatus = boxesStatus.get(box.id);
2916
+ const boxStatus = this.boxesStatus$.get(box.id);
2897
2917
  if (boxStatus) {
2898
2918
  if (boxStatus !== exports.TELE_BOX_STATE.Minimized && box.zIndex > ((_a2 = topBox == null ? void 0 : topBox.zIndex) != null ? _a2 : 0)) {
2899
2919
  topBox = box;
@@ -2920,6 +2940,28 @@ class TeleBoxManager {
2920
2940
  if (this.maxTitleBar) {
2921
2941
  this.maxTitleBar.updateBoxesStatus();
2922
2942
  }
2943
+ console.log("effectBoxStatusTimerFunc===>end", skipUpdate, this.boxes$.value.map((b) => ({ id: b.id, focus: b.focus, boxStatus: b.boxStatus, zIndex: b.zIndex })));
2944
+ }
2945
+ effectBoxStatusChange(skipUpdate = false) {
2946
+ var _a, _b;
2947
+ if (this.effectBoxStatusTimer && this.effectBoxStatusTimer.timer) {
2948
+ clearTimeout(this.effectBoxStatusTimer.timer);
2949
+ if (this.effectBoxStatusTimer.skipUpdate !== skipUpdate) {
2950
+ this.effectBoxStatusTimer.skipUpdate = skipUpdate;
2951
+ console.log("effectBoxStatusTimerFunc===>1111", skipUpdate);
2952
+ this.effectBoxStatusTimerFunc(this.effectBoxStatusTimer.skipUpdate);
2953
+ }
2954
+ }
2955
+ if (!this.effectBoxStatusTimer) {
2956
+ this.effectBoxStatusTimer = {
2957
+ skipUpdate,
2958
+ timer: void 0
2959
+ };
2960
+ }
2961
+ 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 })));
2962
+ this.effectBoxStatusTimer.timer = setTimeout(() => {
2963
+ this.effectBoxStatusTimerFunc(skipUpdate);
2964
+ }, 100);
2923
2965
  }
2924
2966
  hasBoxesStatus() {
2925
2967
  return this.boxesStatus$.size > 0;
@@ -2928,24 +2970,23 @@ class TeleBoxManager {
2928
2970
  return this.boxes.some((box) => box.boxStatus && box.boxStatus === exports.TELE_BOX_STATE.Minimized);
2929
2971
  }
2930
2972
  setLastNotMinimizedBoxStatus(boxId, lastNotMinimizedBoxStatus, skipUpdate = false) {
2931
- const boxesStatus = this.lastNotMinimizedBoxesStatus$;
2932
2973
  if (lastNotMinimizedBoxStatus) {
2933
- boxesStatus.set(boxId, lastNotMinimizedBoxStatus);
2974
+ this.lastNotMinimizedBoxesStatus$.set(boxId, lastNotMinimizedBoxStatus);
2934
2975
  } else {
2935
- boxesStatus.delete(boxId);
2976
+ this.lastNotMinimizedBoxesStatus$.delete(boxId);
2936
2977
  }
2937
- this.setLastNotMinimizedBoxesStatus(boxesStatus, skipUpdate);
2938
2978
  if (!skipUpdate) {
2939
2979
  this.events.emit(exports.TELE_BOX_MANAGER_EVENT.LastNotMinimizedBoxStatus, { id: boxId, boxStatus: lastNotMinimizedBoxStatus });
2940
2980
  }
2941
2981
  }
2942
2982
  setLastNotMinimizedBoxesStatus(lastNotMinimizedBoxesStatus, skipUpdate = false) {
2943
2983
  this.lastNotMinimizedBoxesStatus$ = lastNotMinimizedBoxesStatus;
2984
+ this.effectLastNotMinimizedBoxStatusChange(skipUpdate);
2985
+ }
2986
+ effectLastNotMinimizedBoxStatusChange(skipUpdate = false) {
2944
2987
  this.boxes.forEach((box) => {
2945
- const boxStatus = lastNotMinimizedBoxesStatus.get(box.id);
2946
- if (boxStatus) {
2947
- box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
2948
- }
2988
+ const boxStatus = this.lastNotMinimizedBoxesStatus$.get(box.id);
2989
+ box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
2949
2990
  });
2950
2991
  }
2951
2992
  getAllMinimizedBoxes() {
@@ -2975,9 +3016,11 @@ class TeleBoxManager {
2975
3016
  this.boxes$.setValue([...this.boxes, box]);
2976
3017
  if (box.boxStatus) {
2977
3018
  this.setBoxStatus(box.id, box.boxStatus, true);
3019
+ this.effectBoxStatusChange(true);
2978
3020
  }
2979
3021
  if (box._lastNotMinimizedBoxStatus$.value) {
2980
3022
  this.setLastNotMinimizedBoxStatus(box.id, box._lastNotMinimizedBoxStatus$.value, true);
3023
+ this.effectLastNotMinimizedBoxStatusChange();
2981
3024
  }
2982
3025
  box._delegateEvents.on(exports.TELE_BOX_DELEGATE_EVENT.Maximize, () => {
2983
3026
  if (box.boxStatus) {
@@ -2990,6 +3033,7 @@ class TeleBoxManager {
2990
3033
  }
2991
3034
  });
2992
3035
  }
3036
+ this.effectBoxStatusChange();
2993
3037
  this.makeMaximizedTopBoxFocus();
2994
3038
  } else {
2995
3039
  this.setMaximized(!this.maximized);
@@ -2999,6 +3043,7 @@ class TeleBoxManager {
2999
3043
  if (box.boxStatus) {
3000
3044
  const oldBoxStatus = box.boxStatus;
3001
3045
  this.setBoxStatus(box.id, exports.TELE_BOX_STATE.Minimized);
3046
+ this.effectBoxStatusChange();
3002
3047
  if (oldBoxStatus === exports.TELE_BOX_STATE.Maximized) {
3003
3048
  this.makeMaximizedTopBoxFocus();
3004
3049
  }
@@ -3071,10 +3116,6 @@ class TeleBoxManager {
3071
3116
  }
3072
3117
  remove(boxOrID, skipUpdate = false) {
3073
3118
  const box = this.getBox(boxOrID);
3074
- if (box) {
3075
- this.setBoxStatus(box.id, void 0, skipUpdate);
3076
- this.setLastNotMinimizedBoxStatus(box.id, void 0, skipUpdate);
3077
- }
3078
3119
  const index2 = this.getBoxIndex(boxOrID);
3079
3120
  if (index2 >= 0) {
3080
3121
  const boxes = this.boxes.slice();
@@ -3082,8 +3123,12 @@ class TeleBoxManager {
3082
3123
  this.boxes$.setValue(boxes);
3083
3124
  deletedBoxes.forEach((box2) => box2.destroy());
3084
3125
  if (box) {
3126
+ this.setBoxStatus(box.id, void 0, skipUpdate);
3085
3127
  this.boxesStatus$.delete(box.id);
3128
+ this.effectBoxStatusChange(skipUpdate);
3129
+ this.setLastNotMinimizedBoxStatus(box.id, void 0, skipUpdate);
3086
3130
  this.lastNotMinimizedBoxesStatus$.delete(box.id);
3131
+ this.effectLastNotMinimizedBoxStatusChange();
3087
3132
  }
3088
3133
  if (!skipUpdate) {
3089
3134
  if (this.boxes.length <= 0) {
@@ -3239,9 +3284,11 @@ class TeleBoxManager {
3239
3284
  }
3240
3285
  if (config.boxStatus) {
3241
3286
  this.setBoxStatus(box.id, config.boxStatus, skipUpdate);
3287
+ this.effectBoxStatusChange(skipUpdate);
3242
3288
  }
3243
3289
  if (config.lastNotMinimizedBoxStatus) {
3244
3290
  this.setLastNotMinimizedBoxStatus(box.id, config.lastNotMinimizedBoxStatus, skipUpdate);
3291
+ this.effectLastNotMinimizedBoxStatusChange();
3245
3292
  }
3246
3293
  }
3247
3294
  smartPosition(config = {}) {
@@ -3272,10 +3319,25 @@ class TeleBoxManager {
3272
3319
  makeBoxTop(box, skipUpdate = false) {
3273
3320
  if (this.topBox) {
3274
3321
  if (box !== this.topBox) {
3275
- const currentBoxZIndex = box.zIndex;
3276
- const addZIndex = this.topBox.zIndex + 1 - box.zIndex;
3277
- box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
3278
- this.makeTopBoxEffect(box.id, addZIndex, currentBoxZIndex, skipUpdate);
3322
+ if (!this.hasBoxesStatus()) {
3323
+ box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
3324
+ return;
3325
+ }
3326
+ const maxZIndex = this.boxes.reduce((maxZIndex2, box2) => {
3327
+ return Math.max(maxZIndex2, box2.zIndex);
3328
+ }, 0);
3329
+ const currentTopBoxZIndex = Math.min(this.topBox.zIndex, box.zIndex);
3330
+ const addZIndex = maxZIndex + 1 - currentTopBoxZIndex;
3331
+ box.setZIndex(maxZIndex + 1, skipUpdate);
3332
+ console.log("makeBoxTop===>", box.id, maxZIndex + 1, addZIndex, this.topBox.id, currentTopBoxZIndex);
3333
+ if (box.boxStatus !== exports.TELE_BOX_STATE.Minimized) {
3334
+ this.boxes.forEach((b) => {
3335
+ if (b.boxStatus === exports.TELE_BOX_STATE.Minimized && b.zIndex >= currentTopBoxZIndex) {
3336
+ console.log("makeBoxTop===>111", b.id, b.zIndex + addZIndex);
3337
+ b.setZIndex(b.zIndex + addZIndex, skipUpdate);
3338
+ }
3339
+ });
3340
+ }
3279
3341
  }
3280
3342
  }
3281
3343
  }
@@ -3293,15 +3355,6 @@ class TeleBoxManager {
3293
3355
  }
3294
3356
  }
3295
3357
  }
3296
- makeTopBoxEffect(boxId, addZIndex, currentZIndex, skipUpdate = false) {
3297
- if (this.hasBoxesStatus() && this.hasMinimizedBox()) {
3298
- this.boxes.forEach((b) => {
3299
- if (b.boxStatus && b.id !== boxId && b.zIndex >= currentZIndex) {
3300
- b.setZIndex(b.zIndex + addZIndex, skipUpdate);
3301
- }
3302
- });
3303
- }
3304
- }
3305
3358
  makeMaximizedBoxFocus(maximizedBox, skipUpdate = false) {
3306
3359
  if (this.maxTitleBar.hasMaximizedBoxInStatus() && this.maxTitleBar.MaximizedBoxes.find((box) => box.id === maximizedBox.id)) {
3307
3360
  const currentZIndex = maximizedBox.zIndex;