@netless/telebox-insider 0.3.1-beta.0 → 0.3.2-beta.0

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,13 @@ 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 closeRequestHandler?;
1000
+ private committedFocusDepth;
1001
+ setLazyFocusRequestHandler(handler?: (boxId: string) => boolean): void;
1002
+ setCloseRequestHandler(handler?: (boxId: string) => boolean): void;
997
1003
  focusBox(boxOrID: string | TeleBox, skipUpdate?: boolean): void;
1004
+ focusBoxCommitted(boxOrID: string | TeleBox, skipUpdate?: boolean): void;
998
1005
  focusTopBox(): void;
999
1006
  blurBox(boxOrID: string | TeleBox, skipUpdate?: boolean): void;
1000
1007
  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
  }
@@ -3316,6 +3330,7 @@ class TeleBoxManager {
3316
3330
  return this.boxesStatus$;
3317
3331
  },
3318
3332
  onEvent: (event) => {
3333
+ var _a;
3319
3334
  switch (event.type) {
3320
3335
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
3321
3336
  if (forceMaximized$.value && this.state === TELE_BOX_STATE.Maximized) {
@@ -3382,13 +3397,16 @@ class TeleBoxManager {
3382
3397
  break;
3383
3398
  }
3384
3399
  case TELE_BOX_EVENT.Close: {
3400
+ const targetBox = this.hasBoxesStatus() ? this.maxTitleBar.focusedBox || this.getMaximizedTopBox() : this.topBox;
3401
+ if (targetBox && ((_a = this.closeRequestHandler) == null ? void 0 : _a.call(this, targetBox.id)))
3402
+ break;
3385
3403
  if (this.hasBoxesStatus()) {
3386
- let targetBox = this.maxTitleBar.focusedBox;
3387
- if (!targetBox) {
3388
- targetBox = this.getMaximizedTopBox();
3404
+ let targetBox2 = this.maxTitleBar.focusedBox;
3405
+ if (!targetBox2) {
3406
+ targetBox2 = this.getMaximizedTopBox();
3389
3407
  }
3390
- if (targetBox == null ? void 0 : targetBox.id) {
3391
- const box = this.getBox(targetBox.id);
3408
+ if (targetBox2 == null ? void 0 : targetBox2.id) {
3409
+ const box = this.getBox(targetBox2.id);
3392
3410
  if (box) {
3393
3411
  let isFocusChanged = false;
3394
3412
  if (box.focus) {
@@ -3466,6 +3484,23 @@ class TeleBoxManager {
3466
3484
  get state() {
3467
3485
  return this._state$.value;
3468
3486
  }
3487
+ setUseBoxesStatus(useBoxesStatus) {
3488
+ var _a, _b;
3489
+ if (this.useBoxesStatus === useBoxesStatus)
3490
+ return;
3491
+ this.useBoxesStatus = useBoxesStatus;
3492
+ this.boxes.forEach(
3493
+ (box) => box.setBoxStatus(useBoxesStatus ? this.boxesStatus$.get(box.id) : void 0, true)
3494
+ );
3495
+ this.boxes$.setValue([...this.boxes]);
3496
+ if (useBoxesStatus) {
3497
+ this.appMenu || (this.appMenu = this.createMinimizedAppMenu());
3498
+ this.effectBoxStatusChange();
3499
+ } else {
3500
+ (_a = this.appMenu) == null ? void 0 : _a.render(/* @__PURE__ */ new Map());
3501
+ (_b = this.collector) == null ? void 0 : _b.setVisible(false);
3502
+ }
3503
+ }
3469
3504
  setState(state, skipUpdate = false) {
3470
3505
  if (state === TELE_BOX_STATE.Normal && this.forceMaximized) {
3471
3506
  return this;
@@ -3807,6 +3842,7 @@ class TeleBoxManager {
3807
3842
  const box = new TeleBox({
3808
3843
  zIndex: config.forceTop ? this.getMaxForceTopBoxZIndex() + 1 : this.getMaxNormalBoxZIndex() + 1,
3809
3844
  ...smartPosition ? this.smartPosition(config) : config,
3845
+ ...!this.useBoxesStatus ? { boxStatus: void 0, lastNotMinimizedBoxStatus: void 0 } : {},
3810
3846
  darkMode: this.darkMode,
3811
3847
  prefersColorScheme: this.prefersColorScheme,
3812
3848
  maximized: this.maximized,
@@ -3897,6 +3933,9 @@ class TeleBoxManager {
3897
3933
  }
3898
3934
  });
3899
3935
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
3936
+ var _a;
3937
+ if ((_a = this.closeRequestHandler) == null ? void 0 : _a.call(this, box.id))
3938
+ return;
3900
3939
  if (this.useBoxesStatus && box.focus) {
3901
3940
  this.blurBox(box);
3902
3941
  }
@@ -4060,9 +4099,18 @@ class TeleBoxManager {
4060
4099
  wrapClassName(className) {
4061
4100
  return `${this.namespace}-${className}`;
4062
4101
  }
4102
+ setLazyFocusRequestHandler(handler) {
4103
+ this.lazyFocusRequestHandler = handler;
4104
+ }
4105
+ setCloseRequestHandler(handler) {
4106
+ this.closeRequestHandler = handler;
4107
+ }
4063
4108
  focusBox(boxOrID, skipUpdate = false) {
4109
+ var _a;
4064
4110
  const targetBox = this.getBox(boxOrID);
4065
4111
  if (targetBox) {
4112
+ if (!skipUpdate && !this.committedFocusDepth && ((_a = this.lazyFocusRequestHandler) == null ? void 0 : _a.call(this, targetBox.id)))
4113
+ return;
4066
4114
  this.boxes.forEach((box) => {
4067
4115
  if (targetBox === box) {
4068
4116
  let focusChanged = false;
@@ -4087,6 +4135,15 @@ class TeleBoxManager {
4087
4135
  }
4088
4136
  }
4089
4137
  }
4138
+ focusBoxCommitted(boxOrID, skipUpdate = false) {
4139
+ var _a;
4140
+ this.committedFocusDepth = ((_a = this.committedFocusDepth) != null ? _a : 0) + 1;
4141
+ try {
4142
+ this.focusBox(boxOrID, skipUpdate);
4143
+ } finally {
4144
+ this.committedFocusDepth -= 1;
4145
+ }
4146
+ }
4090
4147
  focusTopBox() {
4091
4148
  if (this.topBox && !this.topBox.focus) {
4092
4149
  return this.focusBox(this.topBox);