@netless/telebox-insider 0.2.32 → 0.3.0-beta.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.
@@ -1227,6 +1227,8 @@ var TELE_BOX_EVENT;
1227
1227
  TELE_BOX_EVENT2["Maximized"] = "maximized";
1228
1228
  TELE_BOX_EVENT2["Readonly"] = "readonly";
1229
1229
  TELE_BOX_EVENT2["Destroyed"] = "destroyed";
1230
+ TELE_BOX_EVENT2["BoxStatus"] = "box_status";
1231
+ TELE_BOX_EVENT2["LastNotMinimizedBoxStatus"] = "last_not_minimized_box_status";
1230
1232
  })(TELE_BOX_EVENT || (TELE_BOX_EVENT = {}));
1231
1233
  var TELE_BOX_DELEGATE_EVENT;
1232
1234
  (function(TELE_BOX_DELEGATE_EVENT2) {
@@ -1279,7 +1281,8 @@ class DefaultTitleBar {
1279
1281
  onEvent,
1280
1282
  onDragStart,
1281
1283
  namespace = "telebox",
1282
- state = TELE_BOX_STATE.Normal
1284
+ state = TELE_BOX_STATE.Normal,
1285
+ boxStatus
1283
1286
  } = {}) {
1284
1287
  this.$btns = [];
1285
1288
  this.sideEffect = new o();
@@ -1352,6 +1355,7 @@ class DefaultTitleBar {
1352
1355
  this.namespace = namespace;
1353
1356
  this.title = title;
1354
1357
  this.state = state;
1358
+ this.boxStatus = boxStatus;
1355
1359
  this.buttons = buttons || [
1356
1360
  {
1357
1361
  type: TELE_BOX_DELEGATE_EVENT.Minimize,
@@ -1386,6 +1390,18 @@ class DefaultTitleBar {
1386
1390
  });
1387
1391
  }
1388
1392
  }
1393
+ setBoxStatus(boxStatus) {
1394
+ if (this.boxStatus !== boxStatus) {
1395
+ this.boxStatus = boxStatus;
1396
+ if (boxStatus) {
1397
+ this.buttons.forEach((btn, i2) => {
1398
+ if (btn.isActive) {
1399
+ this.$btns[i2].classList.toggle("is-active", btn.isActive(boxStatus));
1400
+ }
1401
+ });
1402
+ }
1403
+ }
1404
+ }
1389
1405
  setReadonly(readonly) {
1390
1406
  if (this.readonly !== readonly) {
1391
1407
  this.readonly = readonly;
@@ -1416,7 +1432,7 @@ class DefaultTitleBar {
1416
1432
  $btn.dataset.teleTitleBarBtnIndex = teleTitleBarBtnIndex;
1417
1433
  $btn.dataset.teleTitleBarNoDblClick = "true";
1418
1434
  if (isActive) {
1419
- $btn.classList.toggle("is-active", isActive(this.state));
1435
+ $btn.classList.toggle("is-active", isActive(this.boxStatus || this.state));
1420
1436
  }
1421
1437
  this.$btns.push($btn);
1422
1438
  $buttonsContainer.appendChild($btn);
@@ -1502,7 +1518,9 @@ class TeleBox {
1502
1518
  width: window.innerWidth,
1503
1519
  height: window.innerHeight
1504
1520
  },
1505
- collectorRect
1521
+ collectorRect,
1522
+ boxStatus,
1523
+ lastNotMinimizedBoxStatus
1506
1524
  } = {}) {
1507
1525
  this._renderSideEffect = new o();
1508
1526
  this.handleTrackStart = (ev) => {
@@ -1516,6 +1534,8 @@ class TeleBox {
1516
1534
  this.namespace = namespace;
1517
1535
  this.events = new EventEmitter();
1518
1536
  this._delegateEvents = new EventEmitter();
1537
+ const boxStatus$ = createVal(boxStatus);
1538
+ const lastNotMinimizedBoxStatus$ = createVal(lastNotMinimizedBoxStatus);
1519
1539
  const prefersColorScheme$ = createVal(prefersColorScheme);
1520
1540
  prefersColorScheme$.reaction((prefersColorScheme2, _, skipUpdate) => {
1521
1541
  if (!skipUpdate) {
@@ -1598,7 +1618,7 @@ class TeleBox {
1598
1618
  this.events.emit(TELE_BOX_EVENT.Maximized, maximized2);
1599
1619
  }
1600
1620
  });
1601
- const state$ = combine([minimized$, maximized$], ([minimized2, maximized2]) => minimized2 ? TELE_BOX_STATE.Minimized : maximized2 ? TELE_BOX_STATE.Maximized : TELE_BOX_STATE.Normal);
1621
+ const state$ = combine([minimized$, maximized$, boxStatus$], ([minimized2, maximized2, boxStatus2]) => minimized2 ? TELE_BOX_STATE.Minimized : maximized2 ? TELE_BOX_STATE.Maximized : !boxStatus2 ? TELE_BOX_STATE.Normal : boxStatus2);
1602
1622
  state$.reaction((state, _, skipUpdate) => {
1603
1623
  if (!skipUpdate) {
1604
1624
  this.events.emit(TELE_BOX_EVENT.State, state);
@@ -1623,8 +1643,8 @@ class TeleBox {
1623
1643
  this.events.emit(TELE_BOX_EVENT.IntrinsicResize, size);
1624
1644
  }
1625
1645
  });
1626
- const size$ = combine([intrinsicSize$, maximized$], ([intrinsicSize, maximized2]) => {
1627
- if (maximized2) {
1646
+ const size$ = combine([intrinsicSize$, maximized$, boxStatus$], ([intrinsicSize, maximized2, boxStatus2]) => {
1647
+ if (maximized2 || boxStatus2 === TELE_BOX_STATE.Maximized) {
1628
1648
  return { width: 1, height: 1 };
1629
1649
  }
1630
1650
  return intrinsicSize;
@@ -1634,8 +1654,8 @@ class TeleBox {
1634
1654
  this.events.emit(TELE_BOX_EVENT.Resize, size);
1635
1655
  }
1636
1656
  });
1637
- const visualSize$ = combine([size$, minimized$, containerRect$, collectorRect$], ([size, minimized2, containerRect2, collectorRect2]) => {
1638
- if (minimized2 && collectorRect2) {
1657
+ const visualSize$ = combine([size$, minimized$, containerRect$, collectorRect$, boxStatus$], ([size, minimized2, containerRect2, collectorRect2, boxStatus2]) => {
1658
+ if ((minimized2 || boxStatus2 === TELE_BOX_STATE.Minimized) && collectorRect2) {
1639
1659
  return {
1640
1660
  width: collectorRect2.width / size.width / containerRect2.width,
1641
1661
  height: collectorRect2.height / size.height / containerRect2.height
@@ -1660,17 +1680,21 @@ class TeleBox {
1660
1680
  containerRect$,
1661
1681
  collectorRect$,
1662
1682
  minimized$,
1663
- maximized$
1683
+ maximized$,
1684
+ boxStatus$,
1685
+ lastNotMinimizedBoxStatus$
1664
1686
  ], ([
1665
1687
  intrinsicCoord,
1666
1688
  intrinsicSize,
1667
1689
  containerRect2,
1668
1690
  collectorRect2,
1669
1691
  minimized2,
1670
- maximized2
1692
+ maximized2,
1693
+ boxStatus2,
1694
+ lastNotMinimizedBoxStatus2
1671
1695
  ]) => {
1672
- if (minimized2 && collectorRect2) {
1673
- if (maximized2) {
1696
+ if ((minimized2 || boxStatus2 === TELE_BOX_STATE.Minimized) && collectorRect2) {
1697
+ if (maximized2 || lastNotMinimizedBoxStatus2 === TELE_BOX_STATE.Maximized) {
1674
1698
  return {
1675
1699
  x: (collectorRect2.x + collectorRect2.width / 2) / containerRect2.width - 1 / 2,
1676
1700
  y: (collectorRect2.y + collectorRect2.height / 2) / containerRect2.height - 1 / 2
@@ -1681,7 +1705,7 @@ class TeleBox {
1681
1705
  y: (collectorRect2.y + collectorRect2.height / 2) / containerRect2.height - intrinsicSize.height / 2
1682
1706
  };
1683
1707
  }
1684
- if (maximized2) {
1708
+ if (maximized2 || boxStatus2 === TELE_BOX_STATE.Maximized) {
1685
1709
  return { x: 0, y: 0 };
1686
1710
  }
1687
1711
  return intrinsicCoord;
@@ -1695,6 +1719,7 @@ class TeleBox {
1695
1719
  readonly: readonly$.value,
1696
1720
  title: title$.value,
1697
1721
  namespace: this.namespace,
1722
+ boxStatus: boxStatus$.value,
1698
1723
  onDragStart: (event) => {
1699
1724
  var _a;
1700
1725
  return (_a = this._handleTrackStart) == null ? void 0 : _a.call(this, event);
@@ -1705,11 +1730,15 @@ class TeleBox {
1705
1730
  } else {
1706
1731
  switch (event.type) {
1707
1732
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
1708
- maximized$.setValue(!maximized$.value);
1733
+ if (!boxStatus$.value) {
1734
+ maximized$.setValue(!maximized$.value);
1735
+ }
1709
1736
  break;
1710
1737
  }
1711
1738
  case TELE_BOX_DELEGATE_EVENT.Minimize: {
1712
- minimized$.setValue(true);
1739
+ if (!boxStatus$.value) {
1740
+ minimized$.setValue(true);
1741
+ }
1713
1742
  break;
1714
1743
  }
1715
1744
  case TELE_BOX_DELEGATE_EVENT.Close: {
@@ -1727,6 +1756,9 @@ class TeleBox {
1727
1756
  readonly$.reaction((readonly2) => {
1728
1757
  this.titleBar.setReadonly(readonly2);
1729
1758
  });
1759
+ boxStatus$.reaction((boxStatus2) => {
1760
+ this.titleBar.setBoxStatus(boxStatus2);
1761
+ });
1730
1762
  const $userContent$ = createVal(content);
1731
1763
  const $userFooter$ = createVal(footer);
1732
1764
  const $userStyles$ = createVal(styles);
@@ -1758,11 +1790,22 @@ class TeleBox {
1758
1790
  this._visualSize$ = visualSize$;
1759
1791
  this._coord$ = coord$;
1760
1792
  this._intrinsicCoord$ = intrinsicCoord$;
1793
+ this._boxStatus$ = boxStatus$;
1794
+ this._lastNotMinimizedBoxStatus$ = lastNotMinimizedBoxStatus$;
1761
1795
  if (this.fixRatio) {
1762
1796
  this.transform(coord$.value.x, coord$.value.y, size$.value.width, size$.value.height, true);
1763
1797
  }
1764
1798
  this.$box = this.render();
1765
1799
  }
1800
+ get boxStatus() {
1801
+ return this._boxStatus$.value;
1802
+ }
1803
+ set boxStatus(boxStatus) {
1804
+ this._boxStatus$.setValue(boxStatus);
1805
+ }
1806
+ get lastNotMinimizedBoxStatus() {
1807
+ return this._lastNotMinimizedBoxStatus$.value;
1808
+ }
1766
1809
  get darkMode() {
1767
1810
  return this._darkMode$.value;
1768
1811
  }
@@ -1789,6 +1832,27 @@ class TeleBox {
1789
1832
  }
1790
1833
  return this;
1791
1834
  }
1835
+ setBoxStatus(boxStatus, skipUpdate = false) {
1836
+ if (boxStatus === TELE_BOX_STATE.Minimized) {
1837
+ if (this._boxStatus$.value && this._boxStatus$.value !== TELE_BOX_STATE.Minimized) {
1838
+ this.setLastNotMinimizedBoxStatus(this._boxStatus$.value, skipUpdate);
1839
+ }
1840
+ } else {
1841
+ this.setLastNotMinimizedBoxStatus(void 0, skipUpdate);
1842
+ }
1843
+ this._boxStatus$.setValue(boxStatus, skipUpdate);
1844
+ if (!skipUpdate) {
1845
+ this.events.emit(TELE_BOX_EVENT.BoxStatus, { id: this.id, boxStatus });
1846
+ }
1847
+ return this;
1848
+ }
1849
+ setLastNotMinimizedBoxStatus(lastNotMinimizedBoxStatus, skipUpdate = false) {
1850
+ this._lastNotMinimizedBoxStatus$.setValue(lastNotMinimizedBoxStatus, skipUpdate);
1851
+ if (!skipUpdate) {
1852
+ this.events.emit(TELE_BOX_EVENT.LastNotMinimizedBoxStatus, { id: this.id, lastNotMinimizedBoxStatus });
1853
+ }
1854
+ return this;
1855
+ }
1792
1856
  get minWidth() {
1793
1857
  return this._minSize$.value.width;
1794
1858
  }
@@ -1983,17 +2047,18 @@ class TeleBox {
1983
2047
  this._size$,
1984
2048
  this._minimized$,
1985
2049
  this._containerRect$,
1986
- this._collectorRect$
1987
- ], ([coord, size, minimized, containerRect, collectorRect]) => {
2050
+ this._collectorRect$,
2051
+ this._boxStatus$
2052
+ ], ([coord, size, minimized, containerRect, collectorRect, boxStatus]) => {
1988
2053
  const absoluteWidth = size.width * containerRect.width;
1989
2054
  const absoluteHeight = size.height * containerRect.height;
1990
2055
  return {
1991
- width: absoluteWidth + (minimized && collectorRect ? 1 : 0),
1992
- height: absoluteHeight + (minimized && collectorRect ? 1 : 0),
2056
+ width: absoluteWidth + ((minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect ? 1 : 0),
2057
+ height: absoluteHeight + ((minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect ? 1 : 0),
1993
2058
  x: coord.x * containerRect.width,
1994
2059
  y: coord.y * containerRect.height,
1995
- scaleX: minimized && collectorRect ? collectorRect.width / absoluteWidth : 1,
1996
- scaleY: minimized && collectorRect ? collectorRect.height / absoluteHeight : 1
2060
+ scaleX: (minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect ? collectorRect.width / absoluteWidth : 1,
2061
+ scaleY: (minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect ? collectorRect.height / absoluteHeight : 1
1997
2062
  };
1998
2063
  }, shallowequal).subscribe((styles) => {
1999
2064
  boxStyler.set(styles);
@@ -2340,6 +2405,8 @@ var TELE_BOX_MANAGER_EVENT;
2340
2405
  TELE_BOX_MANAGER_EVENT2["ZIndex"] = "z_index";
2341
2406
  TELE_BOX_MANAGER_EVENT2["PrefersColorScheme"] = "prefers_color_scheme";
2342
2407
  TELE_BOX_MANAGER_EVENT2["DarkMode"] = "dark_mode";
2408
+ TELE_BOX_MANAGER_EVENT2["BoxStatus"] = "box_status";
2409
+ TELE_BOX_MANAGER_EVENT2["LastNotMinimizedBoxStatus"] = "last_not_minimized_box_status";
2343
2410
  })(TELE_BOX_MANAGER_EVENT || (TELE_BOX_MANAGER_EVENT = {}));
2344
2411
  var style = ".telebox-max-titlebar {\n user-select: none;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n display: none;\n position: absolute;\n top: 0;\n left: 0;\n z-index: 50000;\n}\n.telebox-max-titlebar .telebox-title {\n display: none;\n}\n.telebox-max-titlebar.telebox-max-titlebar-single-title .telebox-titles {\n display: none;\n}\n.telebox-max-titlebar.telebox-max-titlebar-single-title .telebox-title {\n display: block;\n}\n.telebox-max-titlebar-maximized {\n display: flex;\n}\n.telebox-titles {\n height: 100%;\n margin: 0;\n overflow-y: hidden;\n overflow-x: scroll;\n overflow-x: overlay;\n -webkit-overflow-scrolling: touch;\n -ms-overflow-style: -ms-autohiding-scrollbar;\n scrollbar-width: auto;\n}\n.telebox-titles::-webkit-scrollbar {\n height: 8px;\n width: 8px;\n}\n.telebox-titles::-webkit-scrollbar-track {\n background-color: transparent;\n}\n.telebox-titles::-webkit-scrollbar-thumb {\n background-color: rgba(238, 238, 247, 0.8);\n background-color: transparent;\n border-radius: 4px;\n transition: background-color 0.4s;\n}\n.telebox-titles:hover::-webkit-scrollbar-thumb {\n background-color: rgba(238, 238, 247, 0.8);\n}\n.telebox-titles::-webkit-scrollbar-thumb:hover {\n background-color: #eeeef7;\n}\n.telebox-titles::-webkit-scrollbar-thumb:active {\n background-color: #eeeef7;\n}\n.telebox-titles::-webkit-scrollbar-thumb:vertical {\n min-height: 50px;\n}\n.telebox-titles::-webkit-scrollbar-thumb:horizontal {\n min-width: 50px;\n}\n.telebox-titles-content {\n height: 100%;\n display: flex;\n flex-wrap: nowrap;\n align-items: center;\n padding: 0;\n}\n.telebox-titles-tab {\n height: 100%;\n overflow: hidden;\n max-width: 182px;\n min-width: 50px;\n padding: 0 26px 0 16px;\n outline: none;\n font-size: 13px;\n font-family: PingFangSC-Regular, PingFang SC;\n font-weight: 400;\n text-overflow: ellipsis;\n white-space: nowrap;\n word-break: keep-all;\n border: none;\n border-right: 1px solid #e5e5f0;\n color: #7b88a0;\n background: transparent;\n cursor: pointer;\n user-select: none;\n}\n.telebox-titles-tab-focus {\n color: #357bf6;\n}\n.telebox-readonly .telebox-titles-tab {\n cursor: not-allowed;\n}\n.telebox-color-scheme-dark {\n color-scheme: dark;\n}\n.telebox-color-scheme-dark.telebox-titlebar {\n color: #e9e9e9;\n background: #43434d;\n border-bottom: none;\n}\n.telebox-color-scheme-dark .telebox-titles-tab {\n border-right-color: #7b88a0;\n}\n.telebox-color-scheme-dark .telebox-title {\n color: #e9e9e9;\n}";
2345
2412
  class MaxTitleBar extends DefaultTitleBar {
@@ -2349,22 +2416,50 @@ class MaxTitleBar extends DefaultTitleBar {
2349
2416
  this.focusedBox = config.focusedBox;
2350
2417
  this.containerRect = config.containerRect;
2351
2418
  this.darkMode = config.darkMode;
2419
+ this.boxesStatus = config.boxesStatus;
2420
+ }
2421
+ hasMaximizedBoxInStatus() {
2422
+ if (!this.boxesStatus || this.boxesStatus.size === 0) {
2423
+ return false;
2424
+ }
2425
+ const hasMaximizedBox = [...this.boxesStatus.values()].find((state) => state === TELE_BOX_STATE.Maximized);
2426
+ return !!hasMaximizedBox;
2427
+ }
2428
+ get MaximizedBoxes() {
2429
+ if (!this.boxesStatus || this.boxesStatus.size === 0) {
2430
+ return [];
2431
+ }
2432
+ return this.boxes.filter((box) => this.boxesStatus && this.boxesStatus.get(box.id) === TELE_BOX_STATE.Maximized);
2352
2433
  }
2353
2434
  focusBox(box) {
2354
- var _a;
2435
+ var _a, _b;
2355
2436
  if (this.focusedBox && this.focusedBox === box) {
2356
2437
  return;
2357
2438
  }
2358
- if (this.$titles && this.state === TELE_BOX_STATE.Maximized) {
2439
+ if (this.$titles) {
2359
2440
  const { children } = this.$titles.firstElementChild;
2360
- for (let i2 = children.length - 1; i2 >= 0; i2 -= 1) {
2361
- const $tab = children[i2];
2362
- const id = (_a = $tab.dataset) == null ? void 0 : _a.teleBoxID;
2363
- if (id) {
2364
- if (box && id === box.id) {
2365
- $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), true);
2366
- } else if (this.focusedBox && id === this.focusedBox.id) {
2367
- $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), false);
2441
+ if (this.state === TELE_BOX_STATE.Maximized && !this.hasMaximizedBoxInStatus()) {
2442
+ for (let i2 = children.length - 1; i2 >= 0; i2 -= 1) {
2443
+ const $tab = children[i2];
2444
+ const id = (_a = $tab.dataset) == null ? void 0 : _a.teleBoxID;
2445
+ if (id) {
2446
+ if (box && id === box.id) {
2447
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), true);
2448
+ } else if (this.focusedBox && id === this.focusedBox.id) {
2449
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), false);
2450
+ }
2451
+ }
2452
+ }
2453
+ } else if (this.hasMaximizedBoxInStatus()) {
2454
+ for (let i2 = children.length - 1; i2 >= 0; i2 -= 1) {
2455
+ const $tab = children[i2];
2456
+ const id = (_b = $tab.dataset) == null ? void 0 : _b.teleBoxID;
2457
+ if (id) {
2458
+ if (box && id === box.id) {
2459
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), true);
2460
+ } else if (this.focusedBox && id === this.focusedBox.id) {
2461
+ $tab.classList.toggle(this.wrapClassName("titles-tab-focus"), false);
2462
+ }
2368
2463
  }
2369
2464
  }
2370
2465
  }
@@ -2379,17 +2474,27 @@ class MaxTitleBar extends DefaultTitleBar {
2379
2474
  this.$titleBar.style.width = width + "px";
2380
2475
  }
2381
2476
  }
2477
+ setBoxesStatus(boxesStatus) {
2478
+ this.boxesStatus = boxesStatus;
2479
+ if (this.hasMaximizedBoxInStatus()) {
2480
+ this.setBoxStatus(TELE_BOX_STATE.Maximized);
2481
+ }
2482
+ if (this.$titleBar) {
2483
+ this.$titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), this.state === TELE_BOX_STATE.Maximized && this.boxes.length > 0 || this.hasMaximizedBoxInStatus());
2484
+ }
2485
+ this.updateTitles();
2486
+ }
2382
2487
  setBoxes(boxes) {
2383
2488
  this.boxes = boxes;
2384
2489
  if (this.$titleBar) {
2385
- this.$titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), this.state === TELE_BOX_STATE.Maximized && boxes.length > 0);
2490
+ this.$titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), this.state === TELE_BOX_STATE.Maximized && boxes.length > 0 || this.hasMaximizedBoxInStatus());
2386
2491
  }
2387
2492
  this.updateTitles();
2388
2493
  }
2389
2494
  setState(state) {
2390
2495
  super.setState(state);
2391
2496
  if (this.$titleBar) {
2392
- this.$titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), state === TELE_BOX_STATE.Maximized && this.boxes.length > 0);
2497
+ this.$titleBar.classList.toggle(this.wrapClassName("max-titlebar-maximized"), state === TELE_BOX_STATE.Maximized && this.boxes.length > 0 || this.hasMaximizedBoxInStatus());
2393
2498
  }
2394
2499
  this.updateTitles();
2395
2500
  }
@@ -2430,9 +2535,9 @@ class MaxTitleBar extends DefaultTitleBar {
2430
2535
  this.focusedBox = void 0;
2431
2536
  }
2432
2537
  updateTitles() {
2433
- if (this.$titleBar && this.state === TELE_BOX_STATE.Maximized) {
2434
- this.$titleBar.classList.toggle(this.wrapClassName("max-titlebar-single-title"), this.boxes.length === 1);
2435
- if (this.boxes.length === 1) {
2538
+ if (this.$titleBar && (this.state === TELE_BOX_STATE.Maximized || this.hasMaximizedBoxInStatus())) {
2539
+ this.$titleBar.classList.toggle(this.wrapClassName("max-titlebar-single-title"), this.boxes.length === 1 || this.hasMaximizedBoxInStatus() && this.MaximizedBoxes.length === 1);
2540
+ if (this.boxes.length === 1 || this.hasMaximizedBoxInStatus() && this.MaximizedBoxes.length === 1) {
2436
2541
  this.setTitle(this.boxes[0].title);
2437
2542
  } else {
2438
2543
  this.$titleBar.replaceChild(this.renderTitles(), this.$titleBar.firstElementChild);
@@ -2451,7 +2556,7 @@ class MaxTitleBar extends DefaultTitleBar {
2451
2556
  const $content = document.createElement("div");
2452
2557
  $content.className = this.wrapClassName("titles-content");
2453
2558
  this.$titles.appendChild($content);
2454
- this.boxes.forEach((box) => {
2559
+ (this.hasMaximizedBoxInStatus() ? this.MaximizedBoxes : this.boxes).forEach((box) => {
2455
2560
  const $tab = document.createElement("button");
2456
2561
  $tab.className = this.wrapClassName("titles-tab");
2457
2562
  $tab.textContent = box.title;
@@ -2490,11 +2595,18 @@ class TeleBoxManager {
2490
2595
  this.boxes$ = createVal([]);
2491
2596
  this.topBox$ = this.boxes$.derive((boxes) => {
2492
2597
  if (boxes.length > 0) {
2493
- const topBox = boxes.reduce((topBox2, box) => topBox2.zIndex > box.zIndex ? topBox2 : box);
2598
+ const topBox = boxes.reduce((topBox2, box) => {
2599
+ if (box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized) {
2600
+ return topBox2;
2601
+ }
2602
+ return topBox2.zIndex > box.zIndex ? topBox2 : box;
2603
+ });
2494
2604
  return topBox;
2495
2605
  }
2496
2606
  return;
2497
2607
  });
2608
+ this.boxesStatus$ = new Map();
2609
+ this.lastNotMinimizedBoxesStatus$ = new Map();
2498
2610
  const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
2499
2611
  const prefersDark$ = createVal(false);
2500
2612
  if (prefersDark) {
@@ -2562,6 +2674,16 @@ class TeleBoxManager {
2562
2674
  this._sideEffect.add(() => {
2563
2675
  collector2.onClick = () => {
2564
2676
  if (!readonly$.value) {
2677
+ if (this.hasMinimizedBox()) {
2678
+ this.getAllMinimizedBoxes().forEach((box) => {
2679
+ const lastNotMinimizedBoxStatus = box.lastNotMinimizedBoxStatus;
2680
+ if (lastNotMinimizedBoxStatus) {
2681
+ this.setBoxStatus(box.id, lastNotMinimizedBoxStatus);
2682
+ } else {
2683
+ this.setBoxStatus(box.id, TELE_BOX_STATE.Normal);
2684
+ }
2685
+ });
2686
+ }
2565
2687
  minimized$.setValue(false);
2566
2688
  }
2567
2689
  };
@@ -2577,7 +2699,7 @@ class TeleBoxManager {
2577
2699
  var _a;
2578
2700
  (_a = collector$.value) == null ? void 0 : _a.setDarkMode(darkMode);
2579
2701
  });
2580
- const calcCollectorRect = () => {
2702
+ this._calcCollectorRect = () => {
2581
2703
  var _a;
2582
2704
  if ((_a = collector$.value) == null ? void 0 : _a.$collector) {
2583
2705
  const { x, y, width, height } = collector$.value.$collector.getBoundingClientRect();
@@ -2591,7 +2713,7 @@ class TeleBoxManager {
2591
2713
  }
2592
2714
  return;
2593
2715
  };
2594
- const collectorRect$ = createVal(minimized$.value ? calcCollectorRect() : void 0);
2716
+ const collectorRect$ = createVal(minimized$.value ? this._calcCollectorRect() : void 0);
2595
2717
  collectorRect$.subscribe((collectorRect, _, skipUpdate) => {
2596
2718
  this.boxes.forEach((box) => {
2597
2719
  box.setCollectorRect(collectorRect, skipUpdate);
@@ -2602,7 +2724,7 @@ class TeleBoxManager {
2602
2724
  (_a = collector$.value) == null ? void 0 : _a.setVisible(minimized2);
2603
2725
  if (minimized2) {
2604
2726
  if ((_b = collector$.value) == null ? void 0 : _b.$collector) {
2605
- collectorRect$.setValue(calcCollectorRect());
2727
+ collectorRect$.setValue(this._calcCollectorRect());
2606
2728
  }
2607
2729
  }
2608
2730
  this.boxes.forEach((box) => box.setMinimized(minimized2, skipUpdate));
@@ -2629,7 +2751,9 @@ class TeleBoxManager {
2629
2751
  const box = this.getBox(id);
2630
2752
  if (box) {
2631
2753
  this.focusBox(box);
2632
- this.makeBoxTop(box);
2754
+ if (box.boxStatus && box.boxStatus !== TELE_BOX_STATE.Maximized || !box.boxStatus) {
2755
+ this.makeBoxTop(box);
2756
+ }
2633
2757
  return;
2634
2758
  }
2635
2759
  }
@@ -2644,19 +2768,36 @@ class TeleBoxManager {
2644
2768
  state: state$.value,
2645
2769
  boxes: this.boxes$.value,
2646
2770
  containerRect: containerRect$.value,
2771
+ boxesStatus: this.boxesStatus$,
2647
2772
  onEvent: (event) => {
2773
+ var _a, _b, _c;
2648
2774
  switch (event.type) {
2649
2775
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
2650
- maximized$.setValue(!maximized$.value);
2776
+ if (this.hasBoxesStatus() && ((_a = this.maxTitleBar.focusedBox) == null ? void 0 : _a.id)) {
2777
+ this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Normal);
2778
+ this.makeMaximizedTopBoxFocus();
2779
+ } else {
2780
+ maximized$.setValue(!maximized$.value);
2781
+ }
2651
2782
  break;
2652
2783
  }
2653
2784
  case TELE_BOX_DELEGATE_EVENT.Minimize: {
2654
- minimized$.setValue(true);
2785
+ if (this.hasBoxesStatus() && ((_b = this.maxTitleBar.focusedBox) == null ? void 0 : _b.id)) {
2786
+ this.setBoxStatus(this.maxTitleBar.focusedBox.id, TELE_BOX_STATE.Minimized);
2787
+ this.makeMaximizedTopBoxFocus();
2788
+ } else {
2789
+ minimized$.setValue(true);
2790
+ }
2655
2791
  break;
2656
2792
  }
2657
2793
  case TELE_BOX_EVENT.Close: {
2658
- this.removeTopBox();
2659
- this.focusTopBox();
2794
+ if (this.hasBoxesStatus() && ((_c = this.maxTitleBar.focusedBox) == null ? void 0 : _c.id)) {
2795
+ this.remove(this.maxTitleBar.focusedBox.id);
2796
+ this.makeMaximizedTopBoxFocus();
2797
+ } else {
2798
+ this.removeTopBox();
2799
+ this.focusTopBox();
2800
+ }
2660
2801
  break;
2661
2802
  }
2662
2803
  }
@@ -2715,6 +2856,89 @@ class TeleBoxManager {
2715
2856
  }
2716
2857
  return this;
2717
2858
  }
2859
+ setBoxStatus(boxId, boxStatus, skipUpdate = false) {
2860
+ const boxesStatus = this.boxesStatus$;
2861
+ if (boxStatus) {
2862
+ const oldBoxStatus = boxesStatus.get(boxId);
2863
+ boxesStatus.set(boxId, boxStatus);
2864
+ if (boxStatus === TELE_BOX_STATE.Minimized && oldBoxStatus !== TELE_BOX_STATE.Minimized) {
2865
+ this.setLastNotMinimizedBoxStatus(boxId, oldBoxStatus, skipUpdate);
2866
+ } else if (oldBoxStatus === TELE_BOX_STATE.Minimized && boxStatus !== TELE_BOX_STATE.Minimized) {
2867
+ this.setLastNotMinimizedBoxStatus(boxId, void 0, skipUpdate);
2868
+ }
2869
+ } else {
2870
+ boxesStatus.delete(boxId);
2871
+ this.setLastNotMinimizedBoxStatus(boxId, void 0, skipUpdate);
2872
+ }
2873
+ this.setBoxesStatus(boxesStatus, skipUpdate);
2874
+ if (!skipUpdate) {
2875
+ this.events.emit(TELE_BOX_MANAGER_EVENT.BoxStatus, { id: boxId, boxStatus });
2876
+ }
2877
+ }
2878
+ setBoxesStatus(boxesStatus, skipUpdate = false) {
2879
+ var _a, _b, _c, _d;
2880
+ let topBox;
2881
+ const topBoxId = (_a = this.topBox) == null ? void 0 : _a.id;
2882
+ let hasMinimizedBox = false;
2883
+ this.boxes.forEach((box) => {
2884
+ var _a2;
2885
+ const boxStatus = boxesStatus.get(box.id);
2886
+ if (boxStatus) {
2887
+ if (boxStatus !== TELE_BOX_STATE.Minimized && box.zIndex > ((_a2 = topBox == null ? void 0 : topBox.zIndex) != null ? _a2 : 0)) {
2888
+ topBox = box;
2889
+ }
2890
+ box.setBoxStatus(boxStatus, skipUpdate);
2891
+ if (boxStatus === TELE_BOX_STATE.Minimized) {
2892
+ hasMinimizedBox = true;
2893
+ }
2894
+ }
2895
+ });
2896
+ if (hasMinimizedBox) {
2897
+ (_b = this.collector) == null ? void 0 : _b.setVisible(true);
2898
+ if ((_c = this.collector) == null ? void 0 : _c.$collector) {
2899
+ this.setCollectorRect(this._calcCollectorRect());
2900
+ }
2901
+ } else {
2902
+ (_d = this.collector) == null ? void 0 : _d.setVisible(false);
2903
+ }
2904
+ if (topBox && topBoxId !== topBox.id) {
2905
+ this.makeBoxTop(topBox, skipUpdate);
2906
+ this.focusTopBox();
2907
+ this.topBox$.setValue(topBox);
2908
+ }
2909
+ if (this.maxTitleBar) {
2910
+ this.maxTitleBar.setBoxesStatus(boxesStatus);
2911
+ }
2912
+ }
2913
+ hasBoxesStatus() {
2914
+ return this.boxesStatus$.size > 0;
2915
+ }
2916
+ hasMinimizedBox() {
2917
+ return this.boxes.some((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized);
2918
+ }
2919
+ setLastNotMinimizedBoxStatus(boxId, lastNotMinimizedBoxStatus, skipUpdate = false) {
2920
+ const boxesStatus = this.lastNotMinimizedBoxesStatus$;
2921
+ if (lastNotMinimizedBoxStatus) {
2922
+ boxesStatus.set(boxId, lastNotMinimizedBoxStatus);
2923
+ } else {
2924
+ boxesStatus.delete(boxId);
2925
+ }
2926
+ this.setLastNotMinimizedBoxesStatus(boxesStatus, skipUpdate);
2927
+ if (!skipUpdate) {
2928
+ this.events.emit(TELE_BOX_MANAGER_EVENT.LastNotMinimizedBoxStatus, { id: boxId, boxStatus: lastNotMinimizedBoxStatus });
2929
+ }
2930
+ }
2931
+ setLastNotMinimizedBoxesStatus(lastNotMinimizedBoxesStatus, skipUpdate = false) {
2932
+ this.boxes.forEach((box) => {
2933
+ const boxStatus = lastNotMinimizedBoxesStatus.get(box.id);
2934
+ if (boxStatus) {
2935
+ box.setLastNotMinimizedBoxStatus(boxStatus, skipUpdate);
2936
+ }
2937
+ });
2938
+ }
2939
+ getAllMinimizedBoxes() {
2940
+ return this.boxes.filter((box) => box.boxStatus && box.boxStatus === TELE_BOX_STATE.Minimized);
2941
+ }
2718
2942
  create(config = {}, smartPosition = true) {
2719
2943
  const box = new TeleBox(__spreadProps(__spreadValues({
2720
2944
  zIndex: this.topBox ? this.topBox.zIndex + 1 : 100
@@ -2737,11 +2961,38 @@ class TeleBoxManager {
2737
2961
  }
2738
2962
  }
2739
2963
  this.boxes$.setValue([...this.boxes, box]);
2964
+ if (box.boxStatus) {
2965
+ this.setBoxStatus(box.id, box.boxStatus, true);
2966
+ }
2967
+ if (box._lastNotMinimizedBoxStatus$.value) {
2968
+ this.setLastNotMinimizedBoxStatus(box.id, box._lastNotMinimizedBoxStatus$.value, true);
2969
+ }
2740
2970
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Maximize, () => {
2741
- this.setMaximized(!this.maximized);
2971
+ if (box.boxStatus) {
2972
+ if (box.boxStatus === TELE_BOX_STATE.Maximized) {
2973
+ this.setBoxStatus(box.id, TELE_BOX_STATE.Normal);
2974
+ } else {
2975
+ this.boxes.forEach((box2) => {
2976
+ if (box2.boxStatus === TELE_BOX_STATE.Normal) {
2977
+ this.setBoxStatus(box2.id, TELE_BOX_STATE.Maximized);
2978
+ }
2979
+ });
2980
+ }
2981
+ this.makeMaximizedTopBoxFocus();
2982
+ } else {
2983
+ this.setMaximized(!this.maximized);
2984
+ }
2742
2985
  });
2743
2986
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Minimize, () => {
2744
- this.setMinimized(true);
2987
+ if (box.boxStatus) {
2988
+ const oldBoxStatus = box.boxStatus;
2989
+ this.setBoxStatus(box.id, TELE_BOX_STATE.Minimized);
2990
+ if (oldBoxStatus === TELE_BOX_STATE.Maximized) {
2991
+ this.makeMaximizedTopBoxFocus();
2992
+ }
2993
+ } else {
2994
+ this.setMinimized(true);
2995
+ }
2745
2996
  });
2746
2997
  box._delegateEvents.on(TELE_BOX_DELEGATE_EVENT.Close, () => {
2747
2998
  this.remove(box);
@@ -2774,7 +3025,12 @@ class TeleBoxManager {
2774
3025
  });
2775
3026
  box._zIndex$.reaction((_, __, skipUpdate) => {
2776
3027
  if (this.boxes.length > 0) {
2777
- const topBox = this.boxes.reduce((topBox2, box2) => topBox2.zIndex > box2.zIndex ? topBox2 : box2);
3028
+ const topBox = this.boxes.reduce((topBox2, box2) => {
3029
+ if (box2.boxStatus && box2.boxStatus === TELE_BOX_STATE.Minimized) {
3030
+ return topBox2;
3031
+ }
3032
+ return topBox2.zIndex > box2.zIndex ? topBox2 : box2;
3033
+ });
2778
3034
  this.topBox$.setValue(topBox);
2779
3035
  }
2780
3036
  if (!skipUpdate) {
@@ -2802,12 +3058,17 @@ class TeleBoxManager {
2802
3058
  });
2803
3059
  }
2804
3060
  remove(boxOrID, skipUpdate = false) {
3061
+ const box = this.getBox(boxOrID);
3062
+ if (box) {
3063
+ this.setBoxStatus(box.id, void 0, skipUpdate);
3064
+ this.setLastNotMinimizedBoxStatus(box.id, void 0, skipUpdate);
3065
+ }
2805
3066
  const index2 = this.getBoxIndex(boxOrID);
2806
3067
  if (index2 >= 0) {
2807
3068
  const boxes = this.boxes.slice();
2808
3069
  const deletedBoxes = boxes.splice(index2, 1);
2809
3070
  this.boxes$.setValue(boxes);
2810
- deletedBoxes.forEach((box) => box.destroy());
3071
+ deletedBoxes.forEach((box2) => box2.destroy());
2811
3072
  if (!skipUpdate) {
2812
3073
  if (this.boxes.length <= 0) {
2813
3074
  this.setMaximized(false);
@@ -2829,6 +3090,8 @@ class TeleBoxManager {
2829
3090
  const deletedBoxes = this.boxes$.value;
2830
3091
  this.boxes$.setValue([]);
2831
3092
  deletedBoxes.forEach((box) => box.destroy());
3093
+ this.boxesStatus$.clear();
3094
+ this.lastNotMinimizedBoxesStatus$.clear();
2832
3095
  if (!skipUpdate) {
2833
3096
  if (this.boxes.length <= 0) {
2834
3097
  this.setMaximized(false);
@@ -2869,7 +3132,11 @@ class TeleBoxManager {
2869
3132
  this.blurBox(box, skipUpdate);
2870
3133
  }
2871
3134
  });
2872
- this.maxTitleBar.focusBox(targetBox);
3135
+ if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
3136
+ this.makeMaximizedBoxFocus(targetBox);
3137
+ } else {
3138
+ this.maxTitleBar.focusBox(targetBox);
3139
+ }
2873
3140
  }
2874
3141
  }
2875
3142
  focusTopBox() {
@@ -2887,7 +3154,11 @@ class TeleBoxManager {
2887
3154
  }
2888
3155
  }
2889
3156
  if (this.maxTitleBar.focusedBox === targetBox) {
2890
- this.maxTitleBar.focusBox();
3157
+ if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
3158
+ this.makeMaximizedTopBoxFocus();
3159
+ } else {
3160
+ this.maxTitleBar.focusBox();
3161
+ }
2891
3162
  }
2892
3163
  }
2893
3164
  }
@@ -2901,7 +3172,11 @@ class TeleBoxManager {
2901
3172
  }
2902
3173
  });
2903
3174
  if (this.maxTitleBar.focusedBox) {
2904
- this.maxTitleBar.focusBox();
3175
+ if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
3176
+ this.makeMaximizedBoxBlur();
3177
+ } else {
3178
+ this.maxTitleBar.focusBox();
3179
+ }
2905
3180
  }
2906
3181
  }
2907
3182
  teleBoxMatcher(config) {
@@ -2946,6 +3221,12 @@ class TeleBoxManager {
2946
3221
  if (config.footer != null) {
2947
3222
  box.mountFooter(config.footer);
2948
3223
  }
3224
+ if (config.boxStatus) {
3225
+ this.setBoxStatus(box.id, config.boxStatus, skipUpdate);
3226
+ }
3227
+ if (config.lastNotMinimizedBoxStatus) {
3228
+ this.setLastNotMinimizedBoxStatus(box.id, config.lastNotMinimizedBoxStatus, skipUpdate);
3229
+ }
2949
3230
  }
2950
3231
  smartPosition(config = {}) {
2951
3232
  let { x, y } = config;
@@ -2975,10 +3256,62 @@ class TeleBoxManager {
2975
3256
  makeBoxTop(box, skipUpdate = false) {
2976
3257
  if (this.topBox) {
2977
3258
  if (box !== this.topBox) {
3259
+ const currentBoxZIndex = box.zIndex;
3260
+ const addZIndex = this.topBox.zIndex + 1 - box.zIndex;
2978
3261
  box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
3262
+ this.makeTopBoxEffect(box.id, addZIndex, currentBoxZIndex, skipUpdate);
3263
+ }
3264
+ }
3265
+ }
3266
+ makeMaximizedTopBoxFocus() {
3267
+ let maximizedBox;
3268
+ if (this.maxTitleBar.hasMaximizedBoxInStatus()) {
3269
+ maximizedBox = this.maxTitleBar.MaximizedBoxes.reduce((topBox, currentBox) => {
3270
+ if (!topBox) {
3271
+ return currentBox;
3272
+ }
3273
+ return topBox.zIndex > currentBox.zIndex ? topBox : currentBox;
3274
+ });
3275
+ if (maximizedBox) {
3276
+ this.maxTitleBar.focusBox(maximizedBox);
3277
+ }
3278
+ }
3279
+ }
3280
+ makeTopBoxEffect(boxId, addZIndex, currentZIndex, skipUpdate = false) {
3281
+ if (this.hasBoxesStatus() && this.hasMinimizedBox()) {
3282
+ this.boxes.forEach((b) => {
3283
+ if (b.boxStatus && b.id !== boxId && b.zIndex >= currentZIndex) {
3284
+ b.setZIndex(b.zIndex + addZIndex, skipUpdate);
3285
+ }
3286
+ });
3287
+ }
3288
+ }
3289
+ makeMaximizedBoxFocus(maximizedBox, skipUpdate = false) {
3290
+ if (this.maxTitleBar.hasMaximizedBoxInStatus() && this.maxTitleBar.MaximizedBoxes.find((box) => box.id === maximizedBox.id)) {
3291
+ const currentZIndex = maximizedBox.zIndex;
3292
+ const currentMaximizedTopBox = this.maxTitleBar.MaximizedBoxes.reduce((topBox, box) => {
3293
+ if (!topBox) {
3294
+ return box;
3295
+ }
3296
+ return topBox.zIndex > box.zIndex ? topBox : box;
3297
+ });
3298
+ if (currentMaximizedTopBox !== maximizedBox) {
3299
+ const addZIndex = currentMaximizedTopBox.zIndex - currentZIndex + 1;
3300
+ this.boxes.forEach((box) => {
3301
+ if (this.maxTitleBar.MaximizedBoxes.find((b) => b.id === box.id && b.id !== maximizedBox.id)) {
3302
+ return;
3303
+ }
3304
+ if (box.zIndex >= currentZIndex) {
3305
+ box.setZIndex(box.zIndex + addZIndex, skipUpdate);
3306
+ }
3307
+ });
2979
3308
  }
3309
+ this.maxTitleBar.focusBox(maximizedBox);
2980
3310
  }
2981
3311
  }
3312
+ makeMaximizedBoxBlur() {
3313
+ this.maxTitleBar.focusBox();
3314
+ }
2982
3315
  getBoxIndex(boxOrID) {
2983
3316
  return typeof boxOrID === "string" ? this.boxes.findIndex((box) => box.id === boxOrID) : this.boxes.findIndex((box) => box === boxOrID);
2984
3317
  }