@netless/telebox-insider 0.2.8 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/telebox-insider",
3
- "version": "0.2.8",
3
+ "version": "0.2.12",
4
4
  "private": false,
5
5
  "description": "Window widget for Whiteboard",
6
6
  "license": "MIT",
@@ -21,6 +21,7 @@ export enum TELE_BOX_EVENT {
21
21
  IntrinsicMove = "intrinsic_move",
22
22
  IntrinsicResize = "intrinsic_resize",
23
23
  VisualResize = "visual_resize",
24
+ ZIndex = "z_index",
24
25
  State = "state",
25
26
  Minimized = "minimized",
26
27
  Maximized = "maximized",
@@ -140,24 +140,28 @@ export class TeleBox {
140
140
  const prefersDark = window.matchMedia(
141
141
  "(prefers-color-scheme: dark)"
142
142
  );
143
- darkMode$.setValue(prefersDark.matches, skipUpdate);
144
- const handler = (
145
- evt: MediaQueryListEvent
146
- ): void => {
147
- darkMode$.setValue(evt.matches, skipUpdate);
148
- };
149
- prefersDark.addEventListener("change", handler);
150
- return () =>
151
- prefersDark.removeEventListener(
152
- "change",
153
- handler
143
+ if (prefersDark) {
144
+ darkMode$.setValue(
145
+ prefersDark.matches,
146
+ skipUpdate
154
147
  );
148
+ const handler = (
149
+ evt: MediaQueryListEvent
150
+ ): void => {
151
+ darkMode$.setValue(evt.matches, skipUpdate);
152
+ };
153
+ prefersDark.addListener(handler);
154
+ return () =>
155
+ prefersDark.removeListener(handler);
156
+ } else {
157
+ return noop;
158
+ }
155
159
  } else {
156
160
  darkMode$.setValue(
157
161
  prefersColorScheme === "dark",
158
162
  skipUpdate
159
163
  );
160
- return () => {};
164
+ return noop;
161
165
  }
162
166
  }, "prefers-color-scheme");
163
167
  }
@@ -193,7 +197,13 @@ export class TeleBox {
193
197
  const draggable$ = createVal(draggable);
194
198
  const fence$ = createVal(fence);
195
199
  const fixRatio$ = createVal(fixRatio);
200
+
196
201
  const zIndex$ = createVal(zIndex);
202
+ zIndex$.reaction((zIndex, _, skipUpdate) => {
203
+ if (!skipUpdate) {
204
+ this.events.emit(TELE_BOX_EVENT.ZIndex, zIndex);
205
+ }
206
+ });
197
207
 
198
208
  const focus$ = createVal(focus);
199
209
  focus$.reaction((focus, _, skipUpdate) => {
@@ -1255,6 +1265,10 @@ export class TeleBox {
1255
1265
  }
1256
1266
  }
1257
1267
 
1268
+ function noop(): void {
1269
+ return;
1270
+ }
1271
+
1258
1272
  type PropKeys<K = keyof TeleBox> = K extends keyof TeleBox
1259
1273
  ? TeleBox[K] extends Function
1260
1274
  ? never
@@ -204,6 +204,8 @@
204
204
  }
205
205
 
206
206
  .#{$namespace}-color-scheme-dark {
207
+ color-scheme: dark;
208
+
207
209
  .#{$namespace}-box-main {
208
210
  color: #e9e9e9;
209
211
  background: #212126;
@@ -96,6 +96,7 @@ export type TeleBoxEventConfig = CheckTeleBoxConfig<{
96
96
  intrinsic_move: { x: number; y: number };
97
97
  intrinsic_resize: { width: number; height: number };
98
98
  visual_resize: { width: number; height: number };
99
+ z_index: number;
99
100
  state: TeleBoxState;
100
101
  minimized: boolean;
101
102
  maximized: boolean;
@@ -5,6 +5,7 @@ import { TeleStyles } from "../typings";
5
5
  export interface TeleBoxCollectorConfig {
6
6
  visible?: boolean;
7
7
  readonly?: boolean;
8
+ darkMode?: boolean;
8
9
  namespace?: string;
9
10
  styles?: TeleStyles;
10
11
  onClick?: () => void;
@@ -14,12 +15,14 @@ export class TeleBoxCollector {
14
15
  public constructor({
15
16
  visible = true,
16
17
  readonly = false,
18
+ darkMode = false,
17
19
  namespace = "telebox",
18
20
  styles = {},
19
21
  onClick,
20
22
  }: TeleBoxCollectorConfig = {}) {
21
- this._visible = Boolean(visible);
22
- this._readonly = Boolean(readonly);
23
+ this._visible = visible;
24
+ this._readonly = readonly;
25
+ this._darkMode = darkMode;
23
26
  this.namespace = namespace;
24
27
  this.styles = styles;
25
28
  this.onClick = onClick;
@@ -37,6 +40,10 @@ export class TeleBoxCollector {
37
40
  return this._readonly;
38
41
  }
39
42
 
43
+ public get darkMode(): boolean {
44
+ return this._darkMode;
45
+ }
46
+
40
47
  public onClick: (() => void) | undefined;
41
48
 
42
49
  public $collector: HTMLElement | undefined;
@@ -85,6 +92,23 @@ export class TeleBoxCollector {
85
92
  return this;
86
93
  }
87
94
 
95
+ public setDarkMode(darkMode: boolean): this {
96
+ if (this._darkMode !== darkMode) {
97
+ this._darkMode = darkMode;
98
+ if (this.$collector) {
99
+ this.$collector.classList.toggle(
100
+ this.wrapClassName("color-scheme-dark"),
101
+ darkMode
102
+ );
103
+ this.$collector.classList.toggle(
104
+ this.wrapClassName("color-scheme-light"),
105
+ !darkMode
106
+ );
107
+ }
108
+ }
109
+ return this;
110
+ }
111
+
88
112
  public setStyles(styles: TeleStyles): this {
89
113
  Object.assign(this.styles, styles);
90
114
  if (this.$collector) {
@@ -103,6 +127,7 @@ export class TeleBoxCollector {
103
127
  if (!this.$collector) {
104
128
  this.$collector = document.createElement("button");
105
129
  this.$collector.className = this.wrapClassName("collector");
130
+ this.$collector.style.backgroundImage = `url('${collectorSVG}')`;
106
131
  this.$collector.addEventListener(
107
132
  "click",
108
133
  this.handleCollectorClick
@@ -120,12 +145,11 @@ export class TeleBoxCollector {
120
145
  );
121
146
  }
122
147
 
123
- const $icon = document.createElement("img");
124
- $icon.draggable = false;
125
- $icon.className = this.wrapClassName("collector-icon");
126
- $icon.src = collectorSVG;
127
-
128
- this.$collector.appendChild($icon);
148
+ this.$collector.classList.add(
149
+ this.wrapClassName(
150
+ this._darkMode ? "color-scheme-dark" : "color-scheme-light"
151
+ )
152
+ );
129
153
 
130
154
  this.setStyles(this.styles);
131
155
  }
@@ -153,6 +177,8 @@ export class TeleBoxCollector {
153
177
 
154
178
  protected _readonly: boolean;
155
179
 
180
+ protected _darkMode: boolean;
181
+
156
182
  protected handleCollectorClick = (): void => {
157
183
  if (!this._readonly && this.onClick) {
158
184
  this.onClick();
@@ -18,11 +18,9 @@
18
18
  cursor: pointer;
19
19
  user-select: none;
20
20
  pointer-events: none;
21
- }
22
-
23
- .#{$namespace}-collector-icon {
24
- width: 18px;
25
- height: 16px;
21
+ background-repeat: no-repeat;
22
+ background-size: 18px 16px;
23
+ background-position: center;
26
24
  }
27
25
 
28
26
  .#{$namespace}-collector-visible {
@@ -33,3 +31,11 @@
33
31
  .#{$namespace}-collector-readonly {
34
32
  cursor: not-allowed;
35
33
  }
34
+
35
+ .#{$namespace}-color-scheme-dark {
36
+ color-scheme: dark;
37
+
38
+ &.#{$namespace}-collector {
39
+ background-color: #43434d;
40
+ }
41
+ }
@@ -8,6 +8,7 @@ import { TeleBoxRect, TeleBoxState } from "../../TeleBox/typings";
8
8
  export type MaxTitleBarTeleBox = Pick<TeleBox, "id" | "title" | "readonly">;
9
9
 
10
10
  export interface MaxTitleBarConfig extends DefaultTitleBarConfig {
11
+ darkMode: boolean;
11
12
  boxes: MaxTitleBarTeleBox[];
12
13
  containerRect: TeleBoxRect;
13
14
  focusedBox?: MaxTitleBarTeleBox;
@@ -20,13 +21,10 @@ export class MaxTitleBar extends DefaultTitleBar {
20
21
  this.boxes = config.boxes;
21
22
  this.focusedBox = config.focusedBox;
22
23
  this.containerRect = config.containerRect;
24
+ this.darkMode = config.darkMode;
23
25
  }
24
26
 
25
27
  public focusBox(box?: MaxTitleBarTeleBox): void {
26
- if (!box) {
27
- box = this.boxes[this.boxes.length - 1];
28
- }
29
-
30
28
  if (this.focusedBox && this.focusedBox === box) {
31
29
  return;
32
30
  }
@@ -89,6 +87,22 @@ export class MaxTitleBar extends DefaultTitleBar {
89
87
  }
90
88
  }
91
89
 
90
+ public setDarkMode(darkMode: boolean): void {
91
+ if (darkMode !== this.darkMode) {
92
+ this.darkMode = darkMode;
93
+ if (this.$titleBar) {
94
+ this.$titleBar.classList.toggle(
95
+ this.wrapClassName("color-scheme-dark"),
96
+ darkMode
97
+ );
98
+ this.$titleBar.classList.toggle(
99
+ this.wrapClassName("color-scheme-light"),
100
+ !darkMode
101
+ );
102
+ }
103
+ }
104
+ }
105
+
92
106
  public render(): HTMLElement {
93
107
  const $titleBar = super.render();
94
108
  const { x, y, width } = this.containerRect;
@@ -104,6 +118,11 @@ export class MaxTitleBar extends DefaultTitleBar {
104
118
  this.wrapClassName("readonly"),
105
119
  this.readonly
106
120
  );
121
+ $titleBar.classList.add(
122
+ this.wrapClassName(
123
+ this.darkMode ? "color-scheme-dark" : "color-scheme-light"
124
+ )
125
+ );
107
126
 
108
127
  this.updateTitles();
109
128
 
@@ -171,11 +190,13 @@ export class MaxTitleBar extends DefaultTitleBar {
171
190
  return this.$titles;
172
191
  }
173
192
 
193
+ protected darkMode: boolean;
194
+
174
195
  protected $titles: HTMLElement | undefined;
175
196
 
176
197
  protected boxes: MaxTitleBarTeleBox[];
177
198
 
178
- protected focusedBox: MaxTitleBarTeleBox | undefined;
199
+ public focusedBox: MaxTitleBarTeleBox | undefined;
179
200
 
180
201
  protected containerRect: TeleBoxRect;
181
202
  }
@@ -123,3 +123,21 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
123
123
  cursor: not-allowed;
124
124
  }
125
125
  }
126
+
127
+ .#{$namespace}-color-scheme-dark {
128
+ color-scheme: dark;
129
+
130
+ &.#{$namespace}-titlebar {
131
+ color: #e9e9e9;
132
+ background: #43434d;
133
+ border-bottom: none;
134
+ }
135
+
136
+ .#{$namespace}-titles-tab {
137
+ border-right-color: #7b88a0;
138
+ }
139
+
140
+ .#{$namespace}-title {
141
+ color: #e9e9e9;
142
+ }
143
+ }
@@ -1,5 +1,6 @@
1
1
  export enum TELE_BOX_MANAGER_EVENT {
2
2
  Focused = "focused",
3
+ Blurred = "blurred",
3
4
  Created = "created",
4
5
  Removed = "removed",
5
6
  State = "state",
@@ -10,6 +11,7 @@ export enum TELE_BOX_MANAGER_EVENT {
10
11
  IntrinsicMove = "intrinsic_move",
11
12
  IntrinsicResize = "intrinsic_resize",
12
13
  VisualResize = "visual_resize",
14
+ ZIndex = "z_index",
13
15
  PrefersColorScheme = "prefers_color_scheme",
14
16
  DarkMode = "dark_mode",
15
17
  }