@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.
@@ -15,6 +15,7 @@ export interface TeleBoxManagerConfig
15
15
  | "minimized"
16
16
  | "namespace"
17
17
  | "readonly"
18
+ | "forceMaximized"
18
19
  > {
19
20
  /** Element to mount boxes. */
20
21
  root?: HTMLElement;
@@ -38,7 +39,11 @@ type TeleBoxManagerBoxConfigBaseProps =
38
39
  | "fixRatio"
39
40
  | "zIndex"
40
41
  | "boxStatus"
41
- | "lastNotMinimizedBoxStatus";
42
+ | "lastNotMinimizedBoxStatus"
43
+ | "forceTop"
44
+ | "forceNormal"
45
+ | "forceMaximized"
46
+ | "isDragContent";
42
47
 
43
48
  export type TeleBoxManagerCreateConfig = Pick<
44
49
  TeleBoxConfig,
@@ -75,8 +80,10 @@ export type TeleBoxManagerEventConfig = CheckTeleBoxManagerConfig<{
75
80
  z_index: [ReadonlyTeleBox];
76
81
  prefers_color_scheme: [TeleBoxColorScheme];
77
82
  dark_mode: [boolean];
78
- box_status: [{ id: string, boxStatus?: TeleBoxState }];
79
- last_not_minimized_box_status: [{ id: string, boxStatus?: NotMinimizedBoxState }];
83
+ box_status: [{ id: string; boxStatus?: TeleBoxState }];
84
+ last_not_minimized_box_status: [
85
+ { id: string; boxStatus?: NotMinimizedBoxState }
86
+ ];
80
87
  }>;
81
88
 
82
89
  export type TeleBoxManagerEvent = keyof TeleBoxManagerEventConfig;
@@ -27,6 +27,9 @@ export interface DefaultTitleBarConfig extends TeleTitleBarConfig {
27
27
 
28
28
  export class DefaultTitleBar implements TeleTitleBar {
29
29
  protected boxStatus?: TeleBoxState;
30
+ protected forceTop?: boolean;
31
+ protected forceNormal?: boolean;
32
+ protected forceMaximized?: boolean;
30
33
  public constructor({
31
34
  readonly = false,
32
35
  title,
@@ -36,6 +39,9 @@ export class DefaultTitleBar implements TeleTitleBar {
36
39
  namespace = "telebox",
37
40
  state = TELE_BOX_STATE.Normal,
38
41
  boxStatus,
42
+ forceTop = false,
43
+ forceNormal = false,
44
+ forceMaximized = false,
39
45
  }: DefaultTitleBarConfig = {}) {
40
46
  this.readonly = readonly;
41
47
  this.onEvent = onEvent;
@@ -44,23 +50,43 @@ export class DefaultTitleBar implements TeleTitleBar {
44
50
  this.title = title;
45
51
  this.state = state;
46
52
  this.boxStatus = boxStatus;
47
-
48
- this.buttons = buttons || [
49
- {
50
- type: TELE_BOX_DELEGATE_EVENT.Minimize,
51
- iconClassName: this.wrapClassName("titlebar-icon-minimize"),
52
- },
53
- {
54
- type: TELE_BOX_DELEGATE_EVENT.Maximize,
55
- iconClassName: this.wrapClassName("titlebar-icon-maximize"),
56
- isActive: (state) => state === TELE_BOX_STATE.Maximized,
57
- },
58
- {
59
- type: TELE_BOX_DELEGATE_EVENT.Close,
60
- iconClassName: this.wrapClassName("titlebar-icon-close"),
61
- },
62
- ];
63
-
53
+ this.forceTop = forceTop;
54
+ this.forceNormal = forceNormal;
55
+ this.forceMaximized = forceMaximized;
56
+
57
+ this.buttons =
58
+ buttons ||
59
+ (forceNormal
60
+ ? [
61
+ {
62
+ type: TELE_BOX_DELEGATE_EVENT.Close,
63
+ iconClassName: this.wrapClassName(
64
+ "titlebar-icon-close"
65
+ ),
66
+ },
67
+ ]
68
+ : [
69
+ {
70
+ type: TELE_BOX_DELEGATE_EVENT.Minimize,
71
+ iconClassName: this.wrapClassName(
72
+ "titlebar-icon-minimize"
73
+ ),
74
+ },
75
+ {
76
+ type: TELE_BOX_DELEGATE_EVENT.Maximize,
77
+ iconClassName: this.wrapClassName(
78
+ "titlebar-icon-maximize"
79
+ ),
80
+ isActive: (state) =>
81
+ state === TELE_BOX_STATE.Maximized,
82
+ },
83
+ {
84
+ type: TELE_BOX_DELEGATE_EVENT.Close,
85
+ iconClassName: this.wrapClassName(
86
+ "titlebar-icon-close"
87
+ ),
88
+ },
89
+ ]);
64
90
  this.$dragArea = this.renderDragArea();
65
91
  }
66
92
 
@@ -70,7 +96,7 @@ export class DefaultTitleBar implements TeleTitleBar {
70
96
 
71
97
  public $title: HTMLElement | undefined;
72
98
 
73
- public $dragArea: HTMLElement;
99
+ public readonly $dragArea: HTMLElement;
74
100
 
75
101
  public setTitle(title: string): void {
76
102
  this.title = title;
@@ -117,6 +143,21 @@ export class DefaultTitleBar implements TeleTitleBar {
117
143
  }
118
144
  }
119
145
 
146
+ public setForceMaximized(forceMaximized: boolean): void {
147
+ this.forceMaximized = forceMaximized;
148
+ this.$btns.forEach((button, index) => {
149
+ if (
150
+ this.buttons[index]?.type === TELE_BOX_DELEGATE_EVENT.Maximize
151
+ ) {
152
+ button.disabled = forceMaximized;
153
+ button.setAttribute("aria-disabled", String(forceMaximized));
154
+ button.classList.toggle(
155
+ this.wrapClassName("disabled"),
156
+ forceMaximized
157
+ );
158
+ }
159
+ });
160
+ }
120
161
 
121
162
  public render(): HTMLElement {
122
163
  if (!this.$titleBar) {
@@ -137,7 +178,6 @@ export class DefaultTitleBar implements TeleTitleBar {
137
178
 
138
179
  $titleArea.appendChild(this.$title);
139
180
  $titleArea.appendChild(this.$dragArea);
140
-
141
181
  const $buttonsContainer = document.createElement("div");
142
182
  $buttonsContainer.className = this.wrapClassName("titlebar-btns");
143
183
 
@@ -152,7 +192,10 @@ export class DefaultTitleBar implements TeleTitleBar {
152
192
  $btn.dataset.teleTitleBarNoDblClick = "true";
153
193
 
154
194
  if (isActive) {
155
- $btn.classList.toggle("is-active", isActive(this.boxStatus || this.state));
195
+ $btn.classList.toggle(
196
+ "is-active",
197
+ isActive(this.boxStatus || this.state)
198
+ );
156
199
  }
157
200
 
158
201
  this.$btns.push($btn);
@@ -177,6 +220,12 @@ export class DefaultTitleBar implements TeleTitleBar {
177
220
  ) {
178
221
  preventEvent(ev);
179
222
  const btn = this.buttons[teleTitleBarBtnIndex];
223
+ if (
224
+ this.forceMaximized &&
225
+ btn.type === TELE_BOX_DELEGATE_EVENT.Maximize
226
+ ) {
227
+ return;
228
+ }
180
229
  if (this.onEvent) {
181
230
  this.onEvent({
182
231
  type: btn.type,
@@ -189,6 +238,7 @@ export class DefaultTitleBar implements TeleTitleBar {
189
238
 
190
239
  this.$titleBar.appendChild($titleArea);
191
240
  this.$titleBar.appendChild($buttonsContainer);
241
+ this.setForceMaximized(Boolean(this.forceMaximized));
192
242
  }
193
243
 
194
244
  return this.$titleBar;
@@ -275,7 +325,7 @@ export class DefaultTitleBar implements TeleTitleBar {
275
325
  Math.abs(ev.clientY - this.lastTitleBarClick.clientY) <= 5
276
326
  ) {
277
327
  // double click
278
- if (this.onEvent) {
328
+ if (this.onEvent && !this.forceMaximized) {
279
329
  this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
280
330
  }
281
331
  }
@@ -316,7 +366,7 @@ export class DefaultTitleBar implements TeleTitleBar {
316
366
  Math.abs(clientY - this.lastTitleBarTouch.clientY) <= 10
317
367
  ) {
318
368
  // double click
319
- if (this.onEvent) {
369
+ if (this.onEvent && !this.forceMaximized) {
320
370
  this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
321
371
  }
322
372
  }
@@ -70,6 +70,11 @@
70
70
  background: transparent;
71
71
  cursor: pointer;
72
72
 
73
+ &:disabled,
74
+ &.#{$namespace}-disabled {
75
+ cursor: not-allowed;
76
+ }
77
+
73
78
  & ~ & {
74
79
  margin-left: 10px;
75
80
  }
@@ -12,17 +12,23 @@ export interface TeleTitleBarConfig {
12
12
  title?: string;
13
13
  state?: TeleBoxState;
14
14
  namespace?: string;
15
+ forceTop?: boolean;
16
+ forceNormal?: boolean;
17
+ forceMaximized?: boolean;
15
18
  onEvent?: (event: TeleTitleBarEvent) => void;
16
19
  onDragStart?: (event: MouseEvent | TouchEvent) => void;
17
20
  }
18
21
 
19
22
  export interface TeleTitleBar {
23
+ readonly $dragArea: HTMLElement;
20
24
  setTitle(title: string): void;
21
25
 
22
26
  setState(state: TeleBoxState): void;
23
27
 
24
28
  setReadonly(readonly: boolean): void;
25
29
 
30
+ setForceMaximized(forceMaximized: boolean): void;
31
+
26
32
  render(): HTMLElement;
27
33
 
28
34
  destroy(): void;