@netless/telebox-insider 0.3.0 → 0.3.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.
@@ -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;
@@ -41,6 +42,7 @@ type TeleBoxManagerBoxConfigBaseProps =
41
42
  | "lastNotMinimizedBoxStatus"
42
43
  | "forceTop"
43
44
  | "forceNormal"
45
+ | "forceMaximized"
44
46
  | "isDragContent";
45
47
 
46
48
  export type TeleBoxManagerCreateConfig = Pick<
@@ -78,8 +80,10 @@ export type TeleBoxManagerEventConfig = CheckTeleBoxManagerConfig<{
78
80
  z_index: [ReadonlyTeleBox];
79
81
  prefers_color_scheme: [TeleBoxColorScheme];
80
82
  dark_mode: [boolean];
81
- box_status: [{ id: string, boxStatus?: TeleBoxState }];
82
- 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
+ ];
83
87
  }>;
84
88
 
85
89
  export type TeleBoxManagerEvent = keyof TeleBoxManagerEventConfig;
@@ -29,6 +29,7 @@ export class DefaultTitleBar implements TeleTitleBar {
29
29
  protected boxStatus?: TeleBoxState;
30
30
  protected forceTop?: boolean;
31
31
  protected forceNormal?: boolean;
32
+ protected forceMaximized?: boolean;
32
33
  public constructor({
33
34
  readonly = false,
34
35
  title,
@@ -40,7 +41,8 @@ export class DefaultTitleBar implements TeleTitleBar {
40
41
  boxStatus,
41
42
  forceTop = false,
42
43
  forceNormal = false,
43
- }: DefaultTitleBarConfig = {}) {
44
+ forceMaximized = false,
45
+ }: DefaultTitleBarConfig = {}) {
44
46
  this.readonly = readonly;
45
47
  this.onEvent = onEvent;
46
48
  this.onDragStart = onDragStart;
@@ -50,27 +52,41 @@ export class DefaultTitleBar implements TeleTitleBar {
50
52
  this.boxStatus = boxStatus;
51
53
  this.forceTop = forceTop;
52
54
  this.forceNormal = forceNormal;
53
-
54
- this.buttons = buttons || (
55
- forceNormal ? [
56
- {
57
- type: TELE_BOX_DELEGATE_EVENT.Close,
58
- iconClassName: this.wrapClassName("titlebar-icon-close"),
59
- }] : [
60
- {
61
- type: TELE_BOX_DELEGATE_EVENT.Minimize,
62
- iconClassName: this.wrapClassName("titlebar-icon-minimize"),
63
- },
64
- {
65
- type: TELE_BOX_DELEGATE_EVENT.Maximize,
66
- iconClassName: this.wrapClassName("titlebar-icon-maximize"),
67
- isActive: (state) => state === TELE_BOX_STATE.Maximized,
68
- },
69
- {
70
- type: TELE_BOX_DELEGATE_EVENT.Close,
71
- iconClassName: this.wrapClassName("titlebar-icon-close"),
72
- },
73
- ]);
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
+ ]);
74
90
  this.$dragArea = this.renderDragArea();
75
91
  }
76
92
 
@@ -127,6 +143,21 @@ export class DefaultTitleBar implements TeleTitleBar {
127
143
  }
128
144
  }
129
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
+ }
130
161
 
131
162
  public render(): HTMLElement {
132
163
  if (!this.$titleBar) {
@@ -161,7 +192,10 @@ export class DefaultTitleBar implements TeleTitleBar {
161
192
  $btn.dataset.teleTitleBarNoDblClick = "true";
162
193
 
163
194
  if (isActive) {
164
- $btn.classList.toggle("is-active", isActive(this.boxStatus || this.state));
195
+ $btn.classList.toggle(
196
+ "is-active",
197
+ isActive(this.boxStatus || this.state)
198
+ );
165
199
  }
166
200
 
167
201
  this.$btns.push($btn);
@@ -186,6 +220,12 @@ export class DefaultTitleBar implements TeleTitleBar {
186
220
  ) {
187
221
  preventEvent(ev);
188
222
  const btn = this.buttons[teleTitleBarBtnIndex];
223
+ if (
224
+ this.forceMaximized &&
225
+ btn.type === TELE_BOX_DELEGATE_EVENT.Maximize
226
+ ) {
227
+ return;
228
+ }
189
229
  if (this.onEvent) {
190
230
  this.onEvent({
191
231
  type: btn.type,
@@ -198,6 +238,7 @@ export class DefaultTitleBar implements TeleTitleBar {
198
238
 
199
239
  this.$titleBar.appendChild($titleArea);
200
240
  this.$titleBar.appendChild($buttonsContainer);
241
+ this.setForceMaximized(Boolean(this.forceMaximized));
201
242
  }
202
243
 
203
244
  return this.$titleBar;
@@ -284,7 +325,7 @@ export class DefaultTitleBar implements TeleTitleBar {
284
325
  Math.abs(ev.clientY - this.lastTitleBarClick.clientY) <= 5
285
326
  ) {
286
327
  // double click
287
- if (this.onEvent) {
328
+ if (this.onEvent && !this.forceMaximized) {
288
329
  this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
289
330
  }
290
331
  }
@@ -325,7 +366,7 @@ export class DefaultTitleBar implements TeleTitleBar {
325
366
  Math.abs(clientY - this.lastTitleBarTouch.clientY) <= 10
326
367
  ) {
327
368
  // double click
328
- if (this.onEvent) {
369
+ if (this.onEvent && !this.forceMaximized) {
329
370
  this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
330
371
  }
331
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
  }
@@ -14,6 +14,7 @@ export interface TeleTitleBarConfig {
14
14
  namespace?: string;
15
15
  forceTop?: boolean;
16
16
  forceNormal?: boolean;
17
+ forceMaximized?: boolean;
17
18
  onEvent?: (event: TeleTitleBarEvent) => void;
18
19
  onDragStart?: (event: MouseEvent | TouchEvent) => void;
19
20
  }
@@ -26,6 +27,8 @@ export interface TeleTitleBar {
26
27
 
27
28
  setReadonly(readonly: boolean): void;
28
29
 
30
+ setForceMaximized?(forceMaximized: boolean): void;
31
+
29
32
  render(): HTMLElement;
30
33
 
31
34
  destroy(): void;