@netless/telebox-insider 0.3.0-beta.10 → 0.3.0-beta.12

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.
@@ -1183,6 +1183,8 @@ var TELE_BOX_EVENT = /* @__PURE__ */ ((TELE_BOX_EVENT2) => {
1183
1183
  TELE_BOX_EVENT2["Destroyed"] = "destroyed";
1184
1184
  TELE_BOX_EVENT2["BoxStatus"] = "box_status";
1185
1185
  TELE_BOX_EVENT2["LastNotMinimizedBoxStatus"] = "last_not_minimized_box_status";
1186
+ TELE_BOX_EVENT2["ForceTop"] = "force_top";
1187
+ TELE_BOX_EVENT2["ForceNormal"] = "force_normal";
1186
1188
  return TELE_BOX_EVENT2;
1187
1189
  })(TELE_BOX_EVENT || {});
1188
1190
  var TELE_BOX_DELEGATE_EVENT = /* @__PURE__ */ ((TELE_BOX_DELEGATE_EVENT2) => {
@@ -1237,7 +1239,9 @@ class DefaultTitleBar {
1237
1239
  onDragStart,
1238
1240
  namespace = "telebox",
1239
1241
  state = TELE_BOX_STATE.Normal,
1240
- boxStatus
1242
+ boxStatus,
1243
+ forceTop = false,
1244
+ forceNormal = false
1241
1245
  } = {}) {
1242
1246
  this.$btns = [];
1243
1247
  this.sideEffect = new o();
@@ -1311,7 +1315,14 @@ class DefaultTitleBar {
1311
1315
  this.title = title;
1312
1316
  this.state = state;
1313
1317
  this.boxStatus = boxStatus;
1314
- this.buttons = buttons || [
1318
+ this.forceTop = forceTop;
1319
+ this.forceNormal = forceNormal;
1320
+ this.buttons = buttons || (forceNormal ? [
1321
+ {
1322
+ type: TELE_BOX_DELEGATE_EVENT.Close,
1323
+ iconClassName: this.wrapClassName("titlebar-icon-close")
1324
+ }
1325
+ ] : [
1315
1326
  {
1316
1327
  type: TELE_BOX_DELEGATE_EVENT.Minimize,
1317
1328
  iconClassName: this.wrapClassName("titlebar-icon-minimize")
@@ -1325,7 +1336,7 @@ class DefaultTitleBar {
1325
1336
  type: TELE_BOX_DELEGATE_EVENT.Close,
1326
1337
  iconClassName: this.wrapClassName("titlebar-icon-close")
1327
1338
  }
1328
- ];
1339
+ ]);
1329
1340
  this.$dragArea = this.renderDragArea();
1330
1341
  }
1331
1342
  setTitle(title) {
@@ -1498,7 +1509,10 @@ class TeleBox {
1498
1509
  },
1499
1510
  collectorRect,
1500
1511
  boxStatus,
1501
- lastNotMinimizedBoxStatus
1512
+ lastNotMinimizedBoxStatus,
1513
+ forceTop = false,
1514
+ forceNormal = false,
1515
+ isDragContent = false
1502
1516
  } = {}) {
1503
1517
  this._renderSideEffect = new o();
1504
1518
  this.handleTrackStart = (ev) => {
@@ -1565,6 +1579,19 @@ class TeleBox {
1565
1579
  });
1566
1580
  const containerRect$ = createVal(containerRect, shallowequal);
1567
1581
  const collectorRect$ = createVal(collectorRect, shallowequal);
1582
+ const forceTop$ = createVal(forceTop);
1583
+ forceTop$.reaction((forceTop2, _, skipUpdate) => {
1584
+ if (!skipUpdate) {
1585
+ this.events.emit(TELE_BOX_EVENT.ForceTop, forceTop2 || false);
1586
+ }
1587
+ });
1588
+ const forceNormal$ = createVal(forceNormal);
1589
+ forceNormal$.reaction((forceNormal2, _, skipUpdate) => {
1590
+ if (!skipUpdate) {
1591
+ this.events.emit(TELE_BOX_EVENT.ForceNormal, forceNormal2 || false);
1592
+ }
1593
+ });
1594
+ const isDragContent$ = createVal(isDragContent);
1568
1595
  const title$ = createVal(title);
1569
1596
  title$.reaction((title2, _, skipUpdate) => {
1570
1597
  if (!skipUpdate) {
@@ -1742,6 +1769,8 @@ class TeleBox {
1742
1769
  title: title$.value,
1743
1770
  namespace: this.namespace,
1744
1771
  boxStatus: boxStatus$.value,
1772
+ forceTop: forceTop$.value,
1773
+ forceNormal: forceNormal$.value,
1745
1774
  onDragStart: (event) => {
1746
1775
  var _a;
1747
1776
  return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, event);
@@ -1805,7 +1834,10 @@ class TeleBox {
1805
1834
  maximized: maximized$,
1806
1835
  $userContent: $userContent$,
1807
1836
  $userFooter: $userFooter$,
1808
- $userStyles: $userStyles$
1837
+ $userStyles: $userStyles$,
1838
+ forceTop: forceTop$,
1839
+ forceNormal: forceNormal$,
1840
+ isDragContent: isDragContent$
1809
1841
  };
1810
1842
  i(this, valConfig);
1811
1843
  this._state$ = state$;
@@ -2142,6 +2174,9 @@ class TeleBox {
2142
2174
  const $content = document.createElement("div");
2143
2175
  $content.className = this.wrapClassName("content") + " tele-fancy-scrollbar";
2144
2176
  this.$content = $content;
2177
+ if (this.isDragContent) {
2178
+ this.$content.appendChild(this.titleBar.$dragArea);
2179
+ }
2145
2180
  this._renderSideEffect.add(() => {
2146
2181
  let last$userStyles;
2147
2182
  return this._$userStyles$.subscribe(($userStyles) => {
@@ -2619,7 +2654,7 @@ class MaxTitleBar extends DefaultTitleBar {
2619
2654
  if (this.getBoxesStatus) {
2620
2655
  const boxesStatus = this.getBoxesStatus();
2621
2656
  if (boxesStatus) {
2622
- return this.boxes.filter((box) => boxesStatus && boxesStatus.get(box.id) === TELE_BOX_STATE.Maximized);
2657
+ return this.boxes.filter((box) => boxesStatus && boxesStatus.get(box.id) === TELE_BOX_STATE.Maximized && !box.forceTop);
2623
2658
  }
2624
2659
  }
2625
2660
  return [];
@@ -2961,6 +2996,9 @@ class TeleBoxManager {
2961
2996
  if (boxes.length > 0) {
2962
2997
  let currentTopBox = void 0;
2963
2998
  const topBox = boxes.reduce((topBox2, box) => {
2999
+ if (box.forceTop) {
3000
+ return topBox2;
3001
+ }
2964
3002
  if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized) {
2965
3003
  return topBox2;
2966
3004
  }
@@ -3311,6 +3349,21 @@ class TeleBoxManager {
3311
3349
  get topBox() {
3312
3350
  return this.topBox$.value;
3313
3351
  }
3352
+ get forceTopBoxes() {
3353
+ return this.boxes.find((box) => box.forceTop);
3354
+ }
3355
+ get maxForceTopBox() {
3356
+ return this.boxes.reduce((maxTopBox, box) => {
3357
+ var _a;
3358
+ if (box.forceTop && box.zIndex > ((_a = maxTopBox == null ? void 0 : maxTopBox.zIndex) != null ? _a : 0)) {
3359
+ return box;
3360
+ }
3361
+ return maxTopBox;
3362
+ });
3363
+ }
3364
+ get forceNormalBoxes() {
3365
+ return this.boxes.find((box) => box.forceNormal);
3366
+ }
3314
3367
  get darkMode() {
3315
3368
  return this._darkMode$.value;
3316
3369
  }
@@ -3397,7 +3450,7 @@ class TeleBoxManager {
3397
3450
  var _a;
3398
3451
  const boxStatus = this.boxesStatus$.get(box.id);
3399
3452
  if (boxStatus) {
3400
- if (boxStatus !== TELE_BOX_STATE.Minimized && box.zIndex > ((_a = newTopBox == null ? void 0 : newTopBox.zIndex) != null ? _a : 0)) {
3453
+ if (boxStatus !== TELE_BOX_STATE.Minimized && !this.isForceTop(box) && box.zIndex > ((_a = newTopBox == null ? void 0 : newTopBox.zIndex) != null ? _a : 0)) {
3401
3454
  newTopBox = box;
3402
3455
  }
3403
3456
  box.setBoxStatus(boxStatus, skipUpdate);
@@ -3581,7 +3634,7 @@ class TeleBoxManager {
3581
3634
  return this.getUnabledBoxesStatusZIndex();
3582
3635
  }
3583
3636
  return this.boxes.reduce((maxZIndex, box) => {
3584
- if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Maximized) {
3637
+ if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Maximized && !this.isForceTop(box)) {
3585
3638
  return Math.max(maxZIndex, box.zIndex);
3586
3639
  }
3587
3640
  return maxZIndex;
@@ -3592,15 +3645,32 @@ class TeleBoxManager {
3592
3645
  return this.getUnabledBoxesStatusZIndex();
3593
3646
  }
3594
3647
  return this.boxes.reduce((maxZIndex, box) => {
3595
- if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Normal) {
3648
+ if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Normal && !this.isForceTop(box)) {
3596
3649
  return Math.max(maxZIndex, box.zIndex);
3597
3650
  }
3598
3651
  return maxZIndex;
3599
3652
  }, 299);
3600
3653
  }
3654
+ getMaxForceTopBoxZIndex() {
3655
+ if (!this.useBoxesStatus) {
3656
+ return this.getUnabledBoxesStatusZIndex();
3657
+ }
3658
+ return this.boxes.reduce((maxZIndex, box) => {
3659
+ if (box.boxStatus && this.isForceTop(box)) {
3660
+ return Math.max(maxZIndex, box.zIndex);
3661
+ }
3662
+ return maxZIndex;
3663
+ }, 699);
3664
+ }
3665
+ isForceNormal(box) {
3666
+ return box._forceNormal$.value;
3667
+ }
3668
+ isForceTop(box) {
3669
+ return box._forceTop$.value;
3670
+ }
3601
3671
  create(config = {}, smartPosition = true) {
3602
3672
  const box = new TeleBox({
3603
- zIndex: this.getMaxNormalBoxZIndex() + 1,
3673
+ zIndex: config.forceTop ? this.getMaxForceTopBoxZIndex() + 1 : this.getMaxNormalBoxZIndex() + 1,
3604
3674
  ...smartPosition ? this.smartPosition(config) : config,
3605
3675
  darkMode: this.darkMode,
3606
3676
  prefersColorScheme: this.prefersColorScheme,
@@ -3628,13 +3698,16 @@ class TeleBoxManager {
3628
3698
  }
3629
3699
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
3630
3700
  if (this.useBoxesStatus && box.boxStatus) {
3701
+ if (box._forceNormal$.value) {
3702
+ return;
3703
+ }
3631
3704
  if (box.boxStatus === TELE_BOX_STATE.Maximized) {
3632
3705
  this.setBox(box.id, {
3633
3706
  status: TELE_BOX_STATE.Normal,
3634
3707
  zIndex: this.getMaxNormalBoxZIndex() + 1
3635
3708
  }, false);
3636
3709
  } else {
3637
- [...this.boxes].filter((box2) => box2.boxStatus === TELE_BOX_STATE.Normal).sort((a, b) => a.zIndex - b.zIndex).forEach((box2) => {
3710
+ [...this.boxes].filter((box2) => box2.boxStatus === TELE_BOX_STATE.Normal && !this.isForceNormal(box2)).sort((a, b) => a.zIndex - b.zIndex).forEach((box2) => {
3638
3711
  if (box2.boxStatus === TELE_BOX_STATE.Normal) {
3639
3712
  this.setBox(box2.id, {
3640
3713
  status: TELE_BOX_STATE.Maximized,
@@ -3650,6 +3723,9 @@ class TeleBoxManager {
3650
3723
  });
3651
3724
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Minimize, () => {
3652
3725
  if (box.boxStatus && this.useBoxesStatus) {
3726
+ if (box._forceNormal$.value) {
3727
+ return;
3728
+ }
3653
3729
  if (box.focus) {
3654
3730
  this.blurBox(box);
3655
3731
  }
@@ -3699,6 +3775,9 @@ class TeleBoxManager {
3699
3775
  if (this.boxes.length > 0) {
3700
3776
  let currentTopBox = void 0;
3701
3777
  const topBox = this.boxes.reduce((topBox2, box2) => {
3778
+ if (this.isForceTop(box2)) {
3779
+ return topBox2;
3780
+ }
3702
3781
  if (box2.boxStatus && box2.boxStatus === TELE_BOX_STATE.Minimized) {
3703
3782
  return topBox2;
3704
3783
  }
@@ -3928,13 +4007,27 @@ class TeleBoxManager {
3928
4007
  lastNotMinimizedBoxStatus: config.lastNotMinimizedBoxStatus
3929
4008
  }, skipUpdate);
3930
4009
  }
4010
+ if (config.forceTop != null) {
4011
+ box.setForceTop(config.forceTop, skipUpdate);
4012
+ }
4013
+ if (config.forceNormal != null) {
4014
+ box.setForceNormal(config.forceNormal, skipUpdate);
4015
+ }
3931
4016
  }
3932
4017
  smartPosition(config = {}) {
3933
4018
  let { x, y } = config;
3934
4019
  const { width = 0.5, height = 0.5 } = config;
3935
4020
  if (x == null) {
3936
4021
  let vx = 20;
3937
- if (this.topBox) {
4022
+ if (config.forceTop) {
4023
+ const forceTopBox = this.maxForceTopBox || this.topBox;
4024
+ if (forceTopBox) {
4025
+ vx = forceTopBox.intrinsicX * this.containerRect.width + 20;
4026
+ if (vx > this.containerRect.width - width * this.containerRect.width) {
4027
+ vx = 20;
4028
+ }
4029
+ }
4030
+ } else if (this.topBox) {
3938
4031
  vx = this.topBox.intrinsicX * this.containerRect.width + 20;
3939
4032
  if (vx > this.containerRect.width - width * this.containerRect.width) {
3940
4033
  vx = 20;
@@ -3948,7 +4041,15 @@ class TeleBoxManager {
3948
4041
  }
3949
4042
  if (y == null) {
3950
4043
  let vy = 20;
3951
- if (this.topBox) {
4044
+ if (config.forceTop) {
4045
+ const forceTopBox = this.maxForceTopBox || this.topBox;
4046
+ if (forceTopBox) {
4047
+ vy = forceTopBox.intrinsicY * this.containerRect.height + 20;
4048
+ if (vy > this.containerRect.height - height * this.containerRect.height) {
4049
+ vy = 20;
4050
+ }
4051
+ }
4052
+ } else if (this.topBox) {
3952
4053
  vy = this.topBox.intrinsicY * this.containerRect.height + 20;
3953
4054
  if (vy > this.containerRect.height - height * this.containerRect.height) {
3954
4055
  vy = 20;