@netless/telebox-insider 0.3.0-beta.9 → 0.3.1-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/telebox-insider",
3
- "version": "0.3.0-beta.9",
3
+ "version": "0.3.1-beta.0",
4
4
  "private": false,
5
5
  "description": "Window widget for Whiteboard",
6
6
  "author": "CRIMX <straybugs@gmail.com> (https://github.com/crimx/)",
@@ -111,7 +111,6 @@ export class AppMenu {
111
111
  private createMinimizedItem(appId: AppId){
112
112
  const appItem = document.createElement('div');
113
113
  appItem.classList.add(this.c('app-menu-item'));
114
- console.log("appId=====>", appId);
115
114
  appItem.setAttribute(`data-${this.c('app-id')}`, appId);
116
115
  const titleDiv = document.createElement('div');
117
116
  titleDiv.classList.add(this.c('app-menu-item-title'));
@@ -29,6 +29,8 @@ export enum TELE_BOX_EVENT {
29
29
  Destroyed = "destroyed",
30
30
  BoxStatus = "box_status",
31
31
  LastNotMinimizedBoxStatus = "last_not_minimized_box_status",
32
+ ForceTop = "force_top",
33
+ ForceNormal = "force_normal",
32
34
  }
33
35
 
34
36
  export enum TELE_BOX_DELEGATE_EVENT {
@@ -72,6 +72,14 @@ type ValConfig = {
72
72
  $userContent: Val<HTMLElement | undefined>;
73
73
  $userFooter: Val<HTMLElement | undefined>;
74
74
  $userStyles: Val<HTMLStyleElement | undefined>;
75
+ /** Force top. */
76
+ forceTop: Val<boolean, boolean>;
77
+ /** Force normal. */
78
+ forceNormal: Val<boolean, boolean>;
79
+ /** Force maximized room policy. */
80
+ forceMaximized: Val<boolean, boolean>;
81
+ /** Drag content. */
82
+ isDragContent: Val<boolean, boolean>;
75
83
  };
76
84
  export interface TeleBox extends ValEnhancedResult<ValConfig> {}
77
85
 
@@ -110,7 +118,11 @@ export class TeleBox {
110
118
  },
111
119
  collectorRect,
112
120
  boxStatus,
113
- lastNotMinimizedBoxStatus
121
+ lastNotMinimizedBoxStatus,
122
+ forceTop = false,
123
+ forceNormal = false,
124
+ forceMaximized = false,
125
+ isDragContent = false,
114
126
  }: TeleBoxConfig = {}) {
115
127
  this._sideEffect = new SideEffectManager();
116
128
  this._valSideEffectBinder = createSideEffectBinder(this._sideEffect);
@@ -120,8 +132,13 @@ export class TeleBox {
120
132
  this.namespace = namespace;
121
133
  this.events = new EventEmitter();
122
134
  this._delegateEvents = new EventEmitter();
123
- const boxStatus$ = createVal<TeleBoxState | undefined, boolean>(boxStatus);
124
- const lastNotMinimizedBoxStatus$ = createVal<NotMinimizedBoxState | undefined, boolean>(lastNotMinimizedBoxStatus);
135
+ const boxStatus$ = createVal<TeleBoxState | undefined, boolean>(
136
+ boxStatus
137
+ );
138
+ const lastNotMinimizedBoxStatus$ = createVal<
139
+ NotMinimizedBoxState | undefined,
140
+ boolean
141
+ >(lastNotMinimizedBoxStatus);
125
142
 
126
143
  const prefersColorScheme$ = createVal<TeleBoxColorScheme, boolean>(
127
144
  prefersColorScheme
@@ -182,6 +199,25 @@ export class TeleBox {
182
199
  const containerRect$ = createVal(containerRect, shallowequal);
183
200
  const collectorRect$ = createVal(collectorRect, shallowequal);
184
201
 
202
+ const forceTop$ = createVal(forceTop);
203
+ forceTop$.reaction((forceTop, _, skipUpdate) => {
204
+ if (!skipUpdate) {
205
+ this.events.emit(TELE_BOX_EVENT.ForceTop, forceTop || false);
206
+ }
207
+ });
208
+
209
+ const forceNormal$ = createVal(forceNormal);
210
+ const forceMaximized$ = createVal(forceMaximized);
211
+ forceNormal$.reaction((forceNormal, _, skipUpdate) => {
212
+ if (!skipUpdate) {
213
+ this.events.emit(
214
+ TELE_BOX_EVENT.ForceNormal,
215
+ forceNormal || false
216
+ );
217
+ }
218
+ });
219
+ const isDragContent$ = createVal(isDragContent);
220
+
185
221
  const title$ = createVal(title);
186
222
  title$.reaction((title, _, skipUpdate) => {
187
223
  if (!skipUpdate) {
@@ -245,7 +281,8 @@ export class TeleBox {
245
281
  ? TELE_BOX_STATE.Minimized
246
282
  : maximized
247
283
  ? TELE_BOX_STATE.Maximized
248
- : !boxStatus ? TELE_BOX_STATE.Normal
284
+ : !boxStatus
285
+ ? TELE_BOX_STATE.Normal
249
286
  : boxStatus
250
287
  );
251
288
  state$.reaction((state, _, skipUpdate) => {
@@ -303,7 +340,10 @@ export class TeleBox {
303
340
  const visualSize$ = combine(
304
341
  [size$, minimized$, containerRect$, collectorRect$, boxStatus$],
305
342
  ([size, minimized, containerRect, collectorRect, boxStatus]) => {
306
- if ((minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect) {
343
+ if (
344
+ (minimized || boxStatus === TELE_BOX_STATE.Minimized) &&
345
+ collectorRect
346
+ ) {
307
347
  return {
308
348
  width:
309
349
  collectorRect.width /
@@ -356,8 +396,14 @@ export class TeleBox {
356
396
  boxStatus,
357
397
  lastNotMinimizedBoxStatus,
358
398
  ]) => {
359
- if ((minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect) {
360
- if (maximized || lastNotMinimizedBoxStatus === TELE_BOX_STATE.Maximized) {
399
+ if (
400
+ (minimized || boxStatus === TELE_BOX_STATE.Minimized) &&
401
+ collectorRect
402
+ ) {
403
+ if (
404
+ maximized ||
405
+ lastNotMinimizedBoxStatus === TELE_BOX_STATE.Maximized
406
+ ) {
361
407
  return {
362
408
  x:
363
409
  (collectorRect.x + collectorRect.width / 2) /
@@ -400,6 +446,9 @@ export class TeleBox {
400
446
  title: title$.value,
401
447
  namespace: this.namespace,
402
448
  boxStatus: boxStatus$.value,
449
+ forceTop: forceTop$.value,
450
+ forceNormal: forceNormal$.value,
451
+ forceMaximized: forceMaximized$.value,
403
452
  onDragStart: (event) => this._handleTrackStart?.(event),
404
453
  onEvent: (event): void => {
405
454
  if (this._delegateEvents.listeners.length > 0) {
@@ -407,7 +456,10 @@ export class TeleBox {
407
456
  } else {
408
457
  switch (event.type) {
409
458
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
410
- if (!boxStatus$.value) {
459
+ if (
460
+ !boxStatus$.value &&
461
+ !(forceMaximized$.value && maximized$.value)
462
+ ) {
411
463
  maximized$.setValue(!maximized$.value);
412
464
  }
413
465
  break;
@@ -436,6 +488,9 @@ export class TeleBox {
436
488
  readonly$.reaction((readonly) => {
437
489
  this.titleBar.setReadonly(readonly);
438
490
  });
491
+ forceMaximized$.reaction((forceMaximized) => {
492
+ this.titleBar.setForceMaximized(forceMaximized);
493
+ });
439
494
  boxStatus$.reaction((boxStatus) => {
440
495
  this.titleBar.setBoxStatus(boxStatus);
441
496
  });
@@ -463,6 +518,10 @@ export class TeleBox {
463
518
  $userContent: $userContent$,
464
519
  $userFooter: $userFooter$,
465
520
  $userStyles: $userStyles$,
521
+ forceTop: forceTop$,
522
+ forceNormal: forceNormal$,
523
+ forceMaximized: forceMaximized$,
524
+ isDragContent: isDragContent$,
466
525
  };
467
526
 
468
527
  withValueEnhancer(this, valConfig);
@@ -512,7 +571,10 @@ export class TeleBox {
512
571
  public _coord$: Val<TeleBoxCoord, boolean>;
513
572
  public _intrinsicCoord$: Val<TeleBoxCoord, boolean>;
514
573
  public _boxStatus$: Val<TeleBoxState | undefined, boolean>;
515
- public _lastNotMinimizedBoxStatus$: Val<NotMinimizedBoxState | undefined, boolean>;
574
+ public _lastNotMinimizedBoxStatus$: Val<
575
+ NotMinimizedBoxState | undefined,
576
+ boolean
577
+ >;
516
578
 
517
579
  public get boxStatus(): TeleBoxState | undefined {
518
580
  return this._boxStatus$.value;
@@ -559,23 +621,41 @@ export class TeleBox {
559
621
 
560
622
  public setBoxStatus(boxStatus: TeleBoxState, skipUpdate = false): this {
561
623
  if (boxStatus === TELE_BOX_STATE.Minimized) {
562
- if (this._boxStatus$.value && this._boxStatus$.value !== TELE_BOX_STATE.Minimized) {
563
- this.setLastNotMinimizedBoxStatus(this._boxStatus$.value, skipUpdate);
624
+ if (
625
+ this._boxStatus$.value &&
626
+ this._boxStatus$.value !== TELE_BOX_STATE.Minimized
627
+ ) {
628
+ this.setLastNotMinimizedBoxStatus(
629
+ this._boxStatus$.value,
630
+ skipUpdate
631
+ );
564
632
  }
565
633
  } else {
566
634
  this.setLastNotMinimizedBoxStatus(undefined, skipUpdate);
567
635
  }
568
636
  this._boxStatus$.setValue(boxStatus, skipUpdate);
569
637
  if (!skipUpdate) {
570
- this.events.emit(TELE_BOX_EVENT.BoxStatus, {id: this.id, boxStatus});
638
+ this.events.emit(TELE_BOX_EVENT.BoxStatus, {
639
+ id: this.id,
640
+ boxStatus,
641
+ });
571
642
  }
572
643
  return this;
573
644
  }
574
645
 
575
- public setLastNotMinimizedBoxStatus(lastNotMinimizedBoxStatus?: NotMinimizedBoxState, skipUpdate = false): this {
576
- this._lastNotMinimizedBoxStatus$.setValue(lastNotMinimizedBoxStatus, skipUpdate);
646
+ public setLastNotMinimizedBoxStatus(
647
+ lastNotMinimizedBoxStatus?: NotMinimizedBoxState,
648
+ skipUpdate = false
649
+ ): this {
650
+ this._lastNotMinimizedBoxStatus$.setValue(
651
+ lastNotMinimizedBoxStatus,
652
+ skipUpdate
653
+ );
577
654
  if (!skipUpdate) {
578
- this.events.emit(TELE_BOX_EVENT.LastNotMinimizedBoxStatus, {id: this.id, lastNotMinimizedBoxStatus});
655
+ this.events.emit(TELE_BOX_EVENT.LastNotMinimizedBoxStatus, {
656
+ id: this.id,
657
+ lastNotMinimizedBoxStatus,
658
+ });
579
659
  }
580
660
  return this;
581
661
  }
@@ -950,24 +1030,43 @@ export class TeleBox {
950
1030
  this._collectorRect$,
951
1031
  this._boxStatus$,
952
1032
  ],
953
- ([coord, size, minimized, containerRect, collectorRect, boxStatus]) => {
1033
+ ([
1034
+ coord,
1035
+ size,
1036
+ minimized,
1037
+ containerRect,
1038
+ collectorRect,
1039
+ boxStatus,
1040
+ ]) => {
954
1041
  const absoluteWidth = size.width * containerRect.width;
955
1042
  const absoluteHeight = size.height * containerRect.height;
956
1043
  return {
957
1044
  width:
958
1045
  absoluteWidth +
959
- ((minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect ? 1 : 0),
1046
+ ((minimized ||
1047
+ boxStatus === TELE_BOX_STATE.Minimized) &&
1048
+ collectorRect
1049
+ ? 1
1050
+ : 0),
960
1051
  height:
961
1052
  absoluteHeight +
962
- ((minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect ? 1 : 0),
1053
+ ((minimized ||
1054
+ boxStatus === TELE_BOX_STATE.Minimized) &&
1055
+ collectorRect
1056
+ ? 1
1057
+ : 0),
963
1058
  x: coord.x * containerRect.width,
964
1059
  y: coord.y * containerRect.height,
965
1060
  scaleX:
966
- (minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect
1061
+ (minimized ||
1062
+ boxStatus === TELE_BOX_STATE.Minimized) &&
1063
+ collectorRect
967
1064
  ? collectorRect.width / absoluteWidth
968
1065
  : 1,
969
1066
  scaleY:
970
- (minimized || boxStatus === TELE_BOX_STATE.Minimized) && collectorRect
1067
+ (minimized ||
1068
+ boxStatus === TELE_BOX_STATE.Minimized) &&
1069
+ collectorRect
971
1070
  ? collectorRect.height / absoluteHeight
972
1071
  : 1,
973
1072
  };
@@ -996,6 +1095,9 @@ export class TeleBox {
996
1095
  $content.className =
997
1096
  this.wrapClassName("content") + " tele-fancy-scrollbar";
998
1097
  this.$content = $content;
1098
+ if (this.isDragContent) {
1099
+ this.$content.appendChild(this.titleBar.$dragArea);
1100
+ }
999
1101
 
1000
1102
  this._renderSideEffect.add(() => {
1001
1103
  let last$userStyles: HTMLStyleElement | undefined;
@@ -17,7 +17,10 @@ export type TeleBoxSize = { width: number; height: number };
17
17
 
18
18
  export type TeleBoxState = `${TELE_BOX_STATE}`;
19
19
 
20
- export type NotMinimizedBoxState = `${Exclude<TELE_BOX_STATE, TELE_BOX_STATE.Minimized>}`;
20
+ export type NotMinimizedBoxState = `${Exclude<
21
+ TELE_BOX_STATE,
22
+ TELE_BOX_STATE.Minimized
23
+ >}`;
21
24
 
22
25
  export interface TeleBoxRect {
23
26
  readonly x: number;
@@ -87,6 +90,13 @@ export interface TeleBoxConfig {
87
90
  readonly boxStatus?: TeleBoxState;
88
91
  /** Last not minimized box status. */
89
92
  readonly lastNotMinimizedBoxStatus?: NotMinimizedBoxState;
93
+ /** Force top. */
94
+ readonly forceTop?: boolean;
95
+ /** Force normal. */
96
+ readonly forceNormal?: boolean;
97
+ readonly forceMaximized?: boolean;
98
+ /** Is drag content. */
99
+ readonly isDragContent?: boolean;
90
100
  }
91
101
 
92
102
  type CheckTeleBoxConfig<T extends Record<`${TELE_BOX_EVENT}`, any>> = T;
@@ -109,7 +119,13 @@ export type TeleBoxEventConfig = CheckTeleBoxConfig<{
109
119
  readonly: boolean;
110
120
  destroyed: void;
111
121
  box_status: { id: string; boxStatus: TeleBoxState };
112
- last_not_minimized_box_status: { id: string; lastNotMinimizedBoxStatus?: NotMinimizedBoxState };
122
+ last_not_minimized_box_status: {
123
+ id: string;
124
+ lastNotMinimizedBoxStatus?: NotMinimizedBoxState;
125
+ };
126
+ force_normal: boolean;
127
+ force_maximized: boolean;
128
+ force_top: boolean;
113
129
  }>;
114
130
 
115
131
  export type TeleBoxEvent = keyof TeleBoxEventConfig;
@@ -15,6 +15,7 @@ export interface TeleBoxCollectorConfig {
15
15
  }
16
16
 
17
17
  export class TeleBoxCollector {
18
+ static readonly kind = "TeleBoxCollector";
18
19
  public getBoxesStatus?: () => Map<string, TeleBoxState>;
19
20
  public constructor({
20
21
  visible = true,
@@ -79,7 +80,7 @@ export class TeleBoxCollector {
79
80
  return this;
80
81
  }
81
82
 
82
- private hasMinimizedBox(): boolean {
83
+ protected hasMinimizedBox(): boolean {
83
84
  const boxesStatus = this.boxesStatus;
84
85
  if (boxesStatus) {
85
86
  for (const status of boxesStatus.values()) {
@@ -5,7 +5,7 @@ import { DefaultTitleBar, DefaultTitleBarConfig } from "../../TeleTitleBar";
5
5
  import { TELE_BOX_STATE } from "../../TeleBox/constants";
6
6
  import { TeleBoxRect, TeleBoxState } from "../../TeleBox/typings";
7
7
 
8
- export type MaxTitleBarTeleBox = Pick<TeleBox, "id" | "title" | "readonly" | "zIndex" | "$box">;
8
+ export type MaxTitleBarTeleBox = Pick<TeleBox, "id" | "title" | "readonly" | "zIndex" | "$box" | "forceTop" | "forceNormal">;
9
9
 
10
10
  export interface MaxTitleBarConfig extends DefaultTitleBarConfig {
11
11
  darkMode: boolean;
@@ -45,7 +45,7 @@ export class MaxTitleBar extends DefaultTitleBar {
45
45
  if (this.getBoxesStatus) {
46
46
  const boxesStatus = this.getBoxesStatus();
47
47
  if (boxesStatus) {
48
- return this.boxes.filter((box) => boxesStatus && boxesStatus.get(box.id) === TELE_BOX_STATE.Maximized);
48
+ return this.boxes.filter((box) => boxesStatus && boxesStatus.get(box.id) === TELE_BOX_STATE.Maximized && !box.forceTop);
49
49
  }
50
50
  }
51
51
  return [];
@@ -16,7 +16,7 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
16
16
  position: absolute;
17
17
  top: 0;
18
18
  left: 0;
19
- z-index: $base-z-index * 10;
19
+ z-index: $base-z-index * 3 - 1;
20
20
 
21
21
  .#{$namespace}-title {
22
22
  display: none;