@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.
@@ -1672,7 +1672,10 @@ class TeleBox {
1672
1672
  this.events.emit(TELE_BOX_EVENT.Minimized, minimized2);
1673
1673
  }
1674
1674
  });
1675
- const maximized$ = createVal(maximized);
1675
+ const maximized$ = createVal(
1676
+ maximized || forceMaximized,
1677
+ (next, previous) => next === previous || forceMaximized$.value && !next
1678
+ );
1676
1679
  maximized$.reaction((maximized2, _, skipUpdate) => {
1677
1680
  if (!skipUpdate) {
1678
1681
  this.events.emit(TELE_BOX_EVENT.Maximized, maximized2);
@@ -1850,7 +1853,10 @@ class TeleBox {
1850
1853
  this.titleBar.setReadonly(readonly2);
1851
1854
  });
1852
1855
  forceMaximized$.reaction((forceMaximized2) => {
1853
- this.titleBar.setForceMaximized(forceMaximized2);
1856
+ var _a, _b;
1857
+ if (forceMaximized2)
1858
+ maximized$.setValue(true);
1859
+ (_b = (_a = this.titleBar).setForceMaximized) == null ? void 0 : _b.call(_a, forceMaximized2);
1854
1860
  });
1855
1861
  boxStatus$.reaction((boxStatus2) => {
1856
1862
  this.titleBar.setBoxStatus(boxStatus2);
@@ -3050,6 +3056,7 @@ class TeleBoxManager {
3050
3056
  useBoxesStatus = false
3051
3057
  } = {}) {
3052
3058
  this.events = new EventEmitter();
3059
+ this.committedFocusDepth = 0;
3053
3060
  this._sideEffect = new o();
3054
3061
  this.useBoxesStatus = useBoxesStatus;
3055
3062
  const { combine, createVal } = c(this._sideEffect);
@@ -3117,14 +3124,19 @@ class TeleBoxManager {
3117
3124
  this.boxes.forEach((box) => box.setReadonly(readonly2, skipUpdate));
3118
3125
  });
3119
3126
  const minimized$ = createVal(minimized);
3120
- const maximized$ = createVal(maximized);
3121
3127
  const forceMaximized$ = createVal(forceMaximized);
3128
+ const maximized$ = createVal(
3129
+ maximized || forceMaximized,
3130
+ (next, previous) => next === previous || forceMaximized$.value && !next
3131
+ );
3122
3132
  forceMaximized$.reaction((forceMaximized2, _, skipUpdate) => {
3123
- var _a;
3133
+ var _a, _b;
3134
+ if (forceMaximized2)
3135
+ maximized$.setValue(true, skipUpdate);
3124
3136
  this.boxes.forEach(
3125
3137
  (box) => box.setForceMaximized(forceMaximized2, skipUpdate)
3126
3138
  );
3127
- (_a = this.maxTitleBar) == null ? void 0 : _a.setForceMaximized(forceMaximized2);
3139
+ (_b = (_a = this.maxTitleBar) == null ? void 0 : _a.setForceMaximized) == null ? void 0 : _b.call(_a, forceMaximized2);
3128
3140
  });
3129
3141
  maximized$.reaction((maximized2, _, skipUpdate) => {
3130
3142
  this.boxes.forEach(
@@ -3240,7 +3252,7 @@ class TeleBoxManager {
3240
3252
  });
3241
3253
  const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
3242
3254
  const checkFocusBox = (ev) => {
3243
- var _a;
3255
+ var _a, _b;
3244
3256
  if (readonly$.value) {
3245
3257
  return;
3246
3258
  }
@@ -3256,6 +3268,8 @@ class TeleBoxManager {
3256
3268
  if (id) {
3257
3269
  const box = this.getBox(id);
3258
3270
  if (box) {
3271
+ if ((_b = this.lazyFocusRequestHandler) == null ? void 0 : _b.call(this, box.id))
3272
+ return;
3259
3273
  if (!this.useBoxesStatus) {
3260
3274
  this.makeBoxTop(box);
3261
3275
  } else {
@@ -3284,7 +3298,7 @@ class TeleBoxManager {
3284
3298
  this.makeMaximizedTopBoxFocus();
3285
3299
  }
3286
3300
  }
3287
- this.focusBox(box);
3301
+ this.focusBoxCommitted(box);
3288
3302
  return;
3289
3303
  }
3290
3304
  }
@@ -3314,6 +3328,7 @@ class TeleBoxManager {
3314
3328
  return this.boxesStatus$;
3315
3329
  },
3316
3330
  onEvent: (event) => {
3331
+ var _a;
3317
3332
  switch (event.type) {
3318
3333
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
3319
3334
  if (forceMaximized$.value && this.state === TELE_BOX_STATE.Maximized) {
@@ -3380,13 +3395,16 @@ class TeleBoxManager {
3380
3395
  break;
3381
3396
  }
3382
3397
  case TELE_BOX_EVENT.Close: {
3398
+ const targetBox = this.hasBoxesStatus() ? this.maxTitleBar.focusedBox || this.getMaximizedTopBox() : this.topBox;
3399
+ if (targetBox && ((_a = this.closeRequestHandler) == null ? void 0 : _a.call(this, targetBox.id)))
3400
+ break;
3383
3401
  if (this.hasBoxesStatus()) {
3384
- let targetBox = this.maxTitleBar.focusedBox;
3385
- if (!targetBox) {
3386
- targetBox = this.getMaximizedTopBox();
3402
+ let targetBox2 = this.maxTitleBar.focusedBox;
3403
+ if (!targetBox2) {
3404
+ targetBox2 = this.getMaximizedTopBox();
3387
3405
  }
3388
- if (targetBox == null ? void 0 : targetBox.id) {
3389
- const box = this.getBox(targetBox.id);
3406
+ if (targetBox2 == null ? void 0 : targetBox2.id) {
3407
+ const box = this.getBox(targetBox2.id);
3390
3408
  if (box) {
3391
3409
  let isFocusChanged = false;
3392
3410
  if (box.focus) {
@@ -3464,6 +3482,23 @@ class TeleBoxManager {
3464
3482
  get state() {
3465
3483
  return this._state$.value;
3466
3484
  }
3485
+ setUseBoxesStatus(useBoxesStatus) {
3486
+ var _a, _b;
3487
+ if (this.useBoxesStatus === useBoxesStatus)
3488
+ return;
3489
+ this.useBoxesStatus = useBoxesStatus;
3490
+ this.boxes.forEach(
3491
+ (box) => box.setBoxStatus(useBoxesStatus ? this.boxesStatus$.get(box.id) : void 0, true)
3492
+ );
3493
+ this.boxes$.setValue([...this.boxes]);
3494
+ if (useBoxesStatus) {
3495
+ this.appMenu || (this.appMenu = this.createMinimizedAppMenu());
3496
+ this.effectBoxStatusChange();
3497
+ } else {
3498
+ (_a = this.appMenu) == null ? void 0 : _a.render(/* @__PURE__ */ new Map());
3499
+ (_b = this.collector) == null ? void 0 : _b.setVisible(false);
3500
+ }
3501
+ }
3467
3502
  setState(state, skipUpdate = false) {
3468
3503
  if (state === TELE_BOX_STATE.Normal && this.forceMaximized) {
3469
3504
  return this;
@@ -3805,6 +3840,7 @@ class TeleBoxManager {
3805
3840
  const box = new TeleBox({
3806
3841
  zIndex: config.forceTop ? this.getMaxForceTopBoxZIndex() + 1 : this.getMaxNormalBoxZIndex() + 1,
3807
3842
  ...smartPosition ? this.smartPosition(config) : config,
3843
+ ...!this.useBoxesStatus ? { boxStatus: void 0, lastNotMinimizedBoxStatus: void 0 } : {},
3808
3844
  darkMode: this.darkMode,
3809
3845
  prefersColorScheme: this.prefersColorScheme,
3810
3846
  maximized: this.maximized,
@@ -3895,6 +3931,9 @@ class TeleBoxManager {
3895
3931
  }
3896
3932
  });
3897
3933
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
3934
+ var _a;
3935
+ if ((_a = this.closeRequestHandler) == null ? void 0 : _a.call(this, box.id))
3936
+ return;
3898
3937
  if (this.useBoxesStatus && box.focus) {
3899
3938
  this.blurBox(box);
3900
3939
  }
@@ -4058,9 +4097,18 @@ class TeleBoxManager {
4058
4097
  wrapClassName(className) {
4059
4098
  return `${this.namespace}-${className}`;
4060
4099
  }
4100
+ setLazyFocusRequestHandler(handler) {
4101
+ this.lazyFocusRequestHandler = handler;
4102
+ }
4103
+ setCloseRequestHandler(handler) {
4104
+ this.closeRequestHandler = handler;
4105
+ }
4061
4106
  focusBox(boxOrID, skipUpdate = false) {
4107
+ var _a;
4062
4108
  const targetBox = this.getBox(boxOrID);
4063
4109
  if (targetBox) {
4110
+ if (!skipUpdate && !this.committedFocusDepth && ((_a = this.lazyFocusRequestHandler) == null ? void 0 : _a.call(this, targetBox.id)))
4111
+ return;
4064
4112
  this.boxes.forEach((box) => {
4065
4113
  if (targetBox === box) {
4066
4114
  let focusChanged = false;
@@ -4085,6 +4133,15 @@ class TeleBoxManager {
4085
4133
  }
4086
4134
  }
4087
4135
  }
4136
+ focusBoxCommitted(boxOrID, skipUpdate = false) {
4137
+ var _a;
4138
+ this.committedFocusDepth = ((_a = this.committedFocusDepth) != null ? _a : 0) + 1;
4139
+ try {
4140
+ this.focusBox(boxOrID, skipUpdate);
4141
+ } finally {
4142
+ this.committedFocusDepth -= 1;
4143
+ }
4144
+ }
4088
4145
  focusTopBox() {
4089
4146
  if (this.topBox && !this.topBox.focus) {
4090
4147
  return this.focusBox(this.topBox);