@netless/telebox-insider 0.3.1-beta.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.
package/dist/index.d.ts CHANGED
@@ -483,7 +483,7 @@ interface TeleTitleBar {
483
483
  setTitle(title: string): void;
484
484
  setState(state: TeleBoxState): void;
485
485
  setReadonly(readonly: boolean): void;
486
- setForceMaximized(forceMaximized: boolean): void;
486
+ setForceMaximized?(forceMaximized: boolean): void;
487
487
  render(): HTMLElement;
488
488
  destroy(): void;
489
489
  setBoxStatus(boxStatus?: TeleBoxState): void;
@@ -949,6 +949,7 @@ declare class TeleBoxManager {
949
949
  get darkMode(): boolean;
950
950
  _state$: Val<TeleBoxState, boolean>;
951
951
  get state(): TeleBoxState;
952
+ setUseBoxesStatus(useBoxesStatus: boolean): void;
952
953
  /** @deprecated use setMaximized and setMinimized instead */
953
954
  setState(state: TeleBoxState, skipUpdate?: boolean): this;
954
955
  setBoxStatus(boxId: string, boxStatus?: TeleBoxState, skipUpdate?: boolean): void;
@@ -994,7 +995,11 @@ declare class TeleBoxManager {
994
995
  removeAll(skipUpdate?: boolean): ReadonlyTeleBox[];
995
996
  destroy(skipUpdate?: boolean): void;
996
997
  wrapClassName(className: string): string;
998
+ private lazyFocusRequestHandler?;
999
+ private committedFocusDepth;
1000
+ setLazyFocusRequestHandler(handler?: (boxId: string) => boolean): void;
997
1001
  focusBox(boxOrID: string | TeleBox, skipUpdate?: boolean): void;
1002
+ focusBoxCommitted(boxOrID: string | TeleBox, skipUpdate?: boolean): void;
998
1003
  focusTopBox(): void;
999
1004
  blurBox(boxOrID: string | TeleBox, skipUpdate?: boolean): void;
1000
1005
  blurAll(skipUpdate?: boolean): void;
@@ -1674,7 +1674,10 @@ class TeleBox {
1674
1674
  this.events.emit(TELE_BOX_EVENT.Minimized, minimized2);
1675
1675
  }
1676
1676
  });
1677
- const maximized$ = createVal(maximized);
1677
+ const maximized$ = createVal(
1678
+ maximized || forceMaximized,
1679
+ (next, previous) => next === previous || forceMaximized$.value && !next
1680
+ );
1678
1681
  maximized$.reaction((maximized2, _, skipUpdate) => {
1679
1682
  if (!skipUpdate) {
1680
1683
  this.events.emit(TELE_BOX_EVENT.Maximized, maximized2);
@@ -1852,7 +1855,10 @@ class TeleBox {
1852
1855
  this.titleBar.setReadonly(readonly2);
1853
1856
  });
1854
1857
  forceMaximized$.reaction((forceMaximized2) => {
1855
- this.titleBar.setForceMaximized(forceMaximized2);
1858
+ var _a, _b;
1859
+ if (forceMaximized2)
1860
+ maximized$.setValue(true);
1861
+ (_b = (_a = this.titleBar).setForceMaximized) == null ? void 0 : _b.call(_a, forceMaximized2);
1856
1862
  });
1857
1863
  boxStatus$.reaction((boxStatus2) => {
1858
1864
  this.titleBar.setBoxStatus(boxStatus2);
@@ -3052,6 +3058,7 @@ class TeleBoxManager {
3052
3058
  useBoxesStatus = false
3053
3059
  } = {}) {
3054
3060
  this.events = new EventEmitter();
3061
+ this.committedFocusDepth = 0;
3055
3062
  this._sideEffect = new o();
3056
3063
  this.useBoxesStatus = useBoxesStatus;
3057
3064
  const { combine, createVal } = c(this._sideEffect);
@@ -3119,14 +3126,19 @@ class TeleBoxManager {
3119
3126
  this.boxes.forEach((box) => box.setReadonly(readonly2, skipUpdate));
3120
3127
  });
3121
3128
  const minimized$ = createVal(minimized);
3122
- const maximized$ = createVal(maximized);
3123
3129
  const forceMaximized$ = createVal(forceMaximized);
3130
+ const maximized$ = createVal(
3131
+ maximized || forceMaximized,
3132
+ (next, previous) => next === previous || forceMaximized$.value && !next
3133
+ );
3124
3134
  forceMaximized$.reaction((forceMaximized2, _, skipUpdate) => {
3125
- var _a;
3135
+ var _a, _b;
3136
+ if (forceMaximized2)
3137
+ maximized$.setValue(true, skipUpdate);
3126
3138
  this.boxes.forEach(
3127
3139
  (box) => box.setForceMaximized(forceMaximized2, skipUpdate)
3128
3140
  );
3129
- (_a = this.maxTitleBar) == null ? void 0 : _a.setForceMaximized(forceMaximized2);
3141
+ (_b = (_a = this.maxTitleBar) == null ? void 0 : _a.setForceMaximized) == null ? void 0 : _b.call(_a, forceMaximized2);
3130
3142
  });
3131
3143
  maximized$.reaction((maximized2, _, skipUpdate) => {
3132
3144
  this.boxes.forEach(
@@ -3242,7 +3254,7 @@ class TeleBoxManager {
3242
3254
  });
3243
3255
  const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
3244
3256
  const checkFocusBox = (ev) => {
3245
- var _a;
3257
+ var _a, _b;
3246
3258
  if (readonly$.value) {
3247
3259
  return;
3248
3260
  }
@@ -3258,6 +3270,8 @@ class TeleBoxManager {
3258
3270
  if (id) {
3259
3271
  const box = this.getBox(id);
3260
3272
  if (box) {
3273
+ if ((_b = this.lazyFocusRequestHandler) == null ? void 0 : _b.call(this, box.id))
3274
+ return;
3261
3275
  if (!this.useBoxesStatus) {
3262
3276
  this.makeBoxTop(box);
3263
3277
  } else {
@@ -3286,7 +3300,7 @@ class TeleBoxManager {
3286
3300
  this.makeMaximizedTopBoxFocus();
3287
3301
  }
3288
3302
  }
3289
- this.focusBox(box);
3303
+ this.focusBoxCommitted(box);
3290
3304
  return;
3291
3305
  }
3292
3306
  }
@@ -3466,6 +3480,23 @@ class TeleBoxManager {
3466
3480
  get state() {
3467
3481
  return this._state$.value;
3468
3482
  }
3483
+ setUseBoxesStatus(useBoxesStatus) {
3484
+ var _a, _b;
3485
+ if (this.useBoxesStatus === useBoxesStatus)
3486
+ return;
3487
+ this.useBoxesStatus = useBoxesStatus;
3488
+ this.boxes.forEach(
3489
+ (box) => box.setBoxStatus(useBoxesStatus ? this.boxesStatus$.get(box.id) : void 0, true)
3490
+ );
3491
+ this.boxes$.setValue([...this.boxes]);
3492
+ if (useBoxesStatus) {
3493
+ this.appMenu || (this.appMenu = this.createMinimizedAppMenu());
3494
+ this.effectBoxStatusChange();
3495
+ } else {
3496
+ (_a = this.appMenu) == null ? void 0 : _a.render(/* @__PURE__ */ new Map());
3497
+ (_b = this.collector) == null ? void 0 : _b.setVisible(false);
3498
+ }
3499
+ }
3469
3500
  setState(state, skipUpdate = false) {
3470
3501
  if (state === TELE_BOX_STATE.Normal && this.forceMaximized) {
3471
3502
  return this;
@@ -3807,6 +3838,7 @@ class TeleBoxManager {
3807
3838
  const box = new TeleBox({
3808
3839
  zIndex: config.forceTop ? this.getMaxForceTopBoxZIndex() + 1 : this.getMaxNormalBoxZIndex() + 1,
3809
3840
  ...smartPosition ? this.smartPosition(config) : config,
3841
+ ...!this.useBoxesStatus ? { boxStatus: void 0, lastNotMinimizedBoxStatus: void 0 } : {},
3810
3842
  darkMode: this.darkMode,
3811
3843
  prefersColorScheme: this.prefersColorScheme,
3812
3844
  maximized: this.maximized,
@@ -4060,9 +4092,15 @@ class TeleBoxManager {
4060
4092
  wrapClassName(className) {
4061
4093
  return `${this.namespace}-${className}`;
4062
4094
  }
4095
+ setLazyFocusRequestHandler(handler) {
4096
+ this.lazyFocusRequestHandler = handler;
4097
+ }
4063
4098
  focusBox(boxOrID, skipUpdate = false) {
4099
+ var _a;
4064
4100
  const targetBox = this.getBox(boxOrID);
4065
4101
  if (targetBox) {
4102
+ if (!skipUpdate && !this.committedFocusDepth && ((_a = this.lazyFocusRequestHandler) == null ? void 0 : _a.call(this, targetBox.id)))
4103
+ return;
4066
4104
  this.boxes.forEach((box) => {
4067
4105
  if (targetBox === box) {
4068
4106
  let focusChanged = false;
@@ -4087,6 +4125,15 @@ class TeleBoxManager {
4087
4125
  }
4088
4126
  }
4089
4127
  }
4128
+ focusBoxCommitted(boxOrID, skipUpdate = false) {
4129
+ var _a;
4130
+ this.committedFocusDepth = ((_a = this.committedFocusDepth) != null ? _a : 0) + 1;
4131
+ try {
4132
+ this.focusBox(boxOrID, skipUpdate);
4133
+ } finally {
4134
+ this.committedFocusDepth -= 1;
4135
+ }
4136
+ }
4090
4137
  focusTopBox() {
4091
4138
  if (this.topBox && !this.topBox.focus) {
4092
4139
  return this.focusBox(this.topBox);