@netless/telebox-insider 1.0.0-alpha.20 → 1.0.0-alpha.23

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.
@@ -239,8 +239,8 @@ export class TeleBoxManager {
239
239
 
240
240
  const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
241
241
 
242
- const checkFocusBox = (ev: MouseEvent | TouchEvent): void => {
243
- if (readonly$.value) {
242
+ const checkFocusBox = (ev: PointerEvent): void => {
243
+ if (!ev.isPrimary || readonly$.value) {
244
244
  return;
245
245
  }
246
246
 
@@ -271,17 +271,56 @@ export class TeleBoxManager {
271
271
 
272
272
  this._sideEffect.addEventListener(
273
273
  window,
274
- "mousedown",
275
- checkFocusBox,
276
- true
277
- );
278
- this._sideEffect.addEventListener(
279
- window,
280
- "touchstart",
274
+ "pointerdown",
281
275
  checkFocusBox,
282
276
  true
283
277
  );
284
278
 
279
+ this.$container = document.createElement("div");
280
+ this.$container.className = this.wrapClassName("manager-container");
281
+
282
+ this.$stage = document.createElement("div");
283
+ this.$stage.className = this.wrapClassName("manager-stage");
284
+ this.$container.appendChild(this.$stage);
285
+
286
+ this._sideEffect.addDisposer([
287
+ darkMode$.subscribe((darkMode) => {
288
+ this.$container.classList.toggle(
289
+ this.wrapClassName("color-scheme-dark"),
290
+ darkMode
291
+ );
292
+ this.$container.classList.toggle(
293
+ this.wrapClassName("color-scheme-light"),
294
+ !darkMode
295
+ );
296
+ }),
297
+ maximized$.subscribe((maximized) => {
298
+ this.$container.classList.toggle("is-maximized", maximized);
299
+ }),
300
+ minimized$.subscribe((minimized) => {
301
+ this.$container.classList.toggle("is-minimized", minimized);
302
+ }),
303
+ containerStyle$.subscribe((containerStyle) => {
304
+ this.$container.style.cssText = containerStyle;
305
+ }),
306
+ stageStyle$.subscribe((stageStyle) => {
307
+ this.$stage.style.cssText = stageStyle;
308
+ this.$stage.style.width = stageRect$.value.width + "px";
309
+ this.$stage.style.height = stageRect$.value.height + "px";
310
+ }),
311
+ stageRect$.subscribe((stageRect) => {
312
+ this.$stage.style.width = stageRect.width + "px";
313
+ this.$stage.style.height = stageRect.height + "px";
314
+ }),
315
+ root$.subscribe((root) => {
316
+ if (root) {
317
+ root.appendChild(this.$container);
318
+ } else if (this.$container.parentElement) {
319
+ this.$container.remove();
320
+ }
321
+ }),
322
+ ]);
323
+
285
324
  this.titleBar = new MaxTitleBar({
286
325
  namespace: this.namespace,
287
326
  title$: derive(this.topBox$, (topBox) => topBox?.title || ""),
@@ -289,8 +328,8 @@ export class TeleBoxManager {
289
328
  darkMode$: darkMode$,
290
329
  readonly$: readonly$,
291
330
  state$: state$,
292
- root$,
293
331
  rootRect$: rootRect$,
332
+ root: this.$container,
294
333
  onEvent: (event): void => {
295
334
  switch (event.type) {
296
335
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
@@ -341,51 +380,6 @@ export class TeleBoxManager {
341
380
  }
342
381
  }),
343
382
  ]);
344
-
345
- this.$container = document.createElement("div");
346
- this.$container.className = this.wrapClassName("manager-container");
347
-
348
- this.$stage = document.createElement("div");
349
- this.$stage.className = this.wrapClassName("manager-stage");
350
- this.$container.appendChild(this.$stage);
351
-
352
- this._sideEffect.addDisposer([
353
- darkMode$.subscribe((darkMode) => {
354
- this.$container.classList.toggle(
355
- this.wrapClassName("color-scheme-dark"),
356
- darkMode
357
- );
358
- this.$container.classList.toggle(
359
- this.wrapClassName("color-scheme-light"),
360
- !darkMode
361
- );
362
- }),
363
- maximized$.subscribe((maximized) => {
364
- this.$container.classList.toggle("is-maximized", maximized);
365
- }),
366
- minimized$.subscribe((minimized) => {
367
- this.$container.classList.toggle("is-minimized", minimized);
368
- }),
369
- containerStyle$.subscribe((containerStyle) => {
370
- this.$container.style.cssText = containerStyle;
371
- }),
372
- stageStyle$.subscribe((stageStyle) => {
373
- this.$stage.style.cssText = stageStyle;
374
- this.$stage.style.width = stageRect$.value.width + "px";
375
- this.$stage.style.height = stageRect$.value.height + "px";
376
- }),
377
- stageRect$.subscribe((stageRect) => {
378
- this.$stage.style.width = stageRect.width + "px";
379
- this.$stage.style.height = stageRect.height + "px";
380
- }),
381
- root$.subscribe((root) => {
382
- if (root) {
383
- root.appendChild(this.$container);
384
- } else if (this.$container.parentElement) {
385
- this.$container.remove();
386
- }
387
- }),
388
- ]);
389
383
  }
390
384
 
391
385
  public readonly $container: HTMLDivElement;
@@ -1,4 +1,5 @@
1
1
  @import "../scss/variables.scss";
2
+ @import "../scss/mixins.scss";
2
3
 
3
4
  .#{$namespace}-manager-container {
4
5
  position: relative;
@@ -8,7 +9,11 @@
8
9
  display: flex;
9
10
  justify-content: center;
10
11
  align-items: center;
11
- background: $color-container-background;
12
+ @include v(
13
+ background,
14
+ manager-container-background,
15
+ $manager-container-background
16
+ );
12
17
 
13
18
  &.is-maximized,
14
19
  &.is-minimized {
@@ -21,19 +26,31 @@
21
26
  .#{$namespace}-manager-stage {
22
27
  position: relative;
23
28
  overflow: hidden;
24
- background: $color-stage-background;
25
- box-shadow: $color-stage-shadow;
29
+ @include v(background, manager-stage-background, $manager-stage-background);
30
+ @include v(box-shadow, manager-stage-shadow, $manager-stage-shadow);
26
31
  }
27
32
 
28
33
  .#{$namespace}-color-scheme-dark {
29
34
  color-scheme: dark;
30
35
 
31
36
  &.#{$namespace}-manager-container {
32
- background: $color-container-background-dark;
37
+ @include v(
38
+ background,
39
+ manager-container-background-dark,
40
+ $manager-container-background-dark
41
+ );
33
42
 
34
43
  & > .#{$namespace}-manager-stage {
35
- background: $color-stage-background-dark;
36
- box-shadow: $color-stage-shadow-dark;
44
+ @include v(
45
+ background,
46
+ manager-stage-background-dark,
47
+ $manager-stage-background-dark
48
+ );
49
+ @include v(
50
+ box-shadow,
51
+ manager-stage-shadow-dark,
52
+ $manager-stage-shadow-dark
53
+ );
37
54
  }
38
55
  }
39
56
  }
@@ -52,8 +52,12 @@ export type TeleBoxManagerCreateConfig = Pick<
52
52
  | "content"
53
53
  | "stage"
54
54
  | "footer"
55
+ | "styles"
56
+ | "bodyStyle"
57
+ | "stageStyle"
55
58
  | "id"
56
59
  | "focus"
60
+ | "enableShadowDOM"
57
61
  >;
58
62
 
59
63
  export type TeleBoxManagerQueryConfig = Pick<
@@ -122,9 +122,9 @@ export class DefaultTitleBar implements TeleTitleBar {
122
122
 
123
123
  this.sideEffect.addEventListener(
124
124
  $buttonsContainer,
125
- "click",
125
+ "pointerup",
126
126
  (ev) => {
127
- if (this.readonly$.value) {
127
+ if (!ev.isPrimary || this.readonly$.value) {
128
128
  return;
129
129
  }
130
130
  const target = ev.target as HTMLElement;
@@ -162,15 +162,9 @@ export class DefaultTitleBar implements TeleTitleBar {
162
162
  $dragArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
163
163
  this.sideEffect.addEventListener(
164
164
  $dragArea,
165
- "mousedown",
165
+ "pointerdown",
166
166
  this.handleTitleBarClick
167
167
  );
168
- this.sideEffect.addEventListener(
169
- $dragArea,
170
- "touchstart",
171
- this.handleTitleBarTouch,
172
- { passive: true }
173
- );
174
168
  return $dragArea;
175
169
  }
176
170
 
@@ -211,8 +205,8 @@ export class DefaultTitleBar implements TeleTitleBar {
211
205
  clientY: -100,
212
206
  };
213
207
 
214
- protected handleTitleBarClick = (ev: MouseEvent): void => {
215
- if (this.readonly$.value) {
208
+ protected handleTitleBarClick = (ev: PointerEvent): void => {
209
+ if (!ev.isPrimary || this.readonly$.value) {
216
210
  return;
217
211
  }
218
212
 
@@ -245,44 +239,44 @@ export class DefaultTitleBar implements TeleTitleBar {
245
239
  this.lastTitleBarClick.clientY = ev.clientY;
246
240
  };
247
241
 
248
- protected lastTitleBarTouch = {
249
- timestamp: 0,
250
- clientX: -100,
251
- clientY: -100,
252
- };
253
-
254
- protected handleTitleBarTouch = (ev: TouchEvent): void => {
255
- if (this.readonly$.value) {
256
- return;
257
- }
258
-
259
- if ((ev.target as HTMLElement).dataset?.teleTitleBarNoDblClick) {
260
- return; // btns
261
- }
262
-
263
- preventEvent(ev);
264
-
265
- const now = Date.now();
266
- const {
267
- clientX = this.lastTitleBarTouch.clientX + 100,
268
- clientY = this.lastTitleBarTouch.clientY + 100,
269
- } = ev.touches[0] || {};
270
-
271
- if (now - this.lastTitleBarTouch.timestamp <= 500) {
272
- if (
273
- Math.abs(clientX - this.lastTitleBarTouch.clientX) <= 10 &&
274
- Math.abs(clientY - this.lastTitleBarTouch.clientY) <= 10
275
- ) {
276
- // double click
277
- if (this.onEvent) {
278
- this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
279
- }
280
- }
281
- } else if (this.onDragStart) {
282
- this.onDragStart(ev);
283
- }
284
- this.lastTitleBarTouch.timestamp = now;
285
- this.lastTitleBarTouch.clientX = clientX;
286
- this.lastTitleBarTouch.clientY = clientY;
287
- };
242
+ // protected lastTitleBarTouch = {
243
+ // timestamp: 0,
244
+ // clientX: -100,
245
+ // clientY: -100,
246
+ // };
247
+
248
+ // protected handleTitleBarTouch = (ev: TouchEvent): void => {
249
+ // if (this.readonly$.value) {
250
+ // return;
251
+ // }
252
+
253
+ // if ((ev.target as HTMLElement).dataset?.teleTitleBarNoDblClick) {
254
+ // return; // btns
255
+ // }
256
+
257
+ // preventEvent(ev);
258
+
259
+ // const now = Date.now();
260
+ // const {
261
+ // clientX = this.lastTitleBarTouch.clientX + 100,
262
+ // clientY = this.lastTitleBarTouch.clientY + 100,
263
+ // } = ev.touches[0] || {};
264
+
265
+ // if (now - this.lastTitleBarTouch.timestamp <= 500) {
266
+ // if (
267
+ // Math.abs(clientX - this.lastTitleBarTouch.clientX) <= 10 &&
268
+ // Math.abs(clientY - this.lastTitleBarTouch.clientY) <= 10
269
+ // ) {
270
+ // // double click
271
+ // if (this.onEvent) {
272
+ // this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
273
+ // }
274
+ // }
275
+ // } else if (this.onDragStart) {
276
+ // this.onDragStart(ev);
277
+ // }
278
+ // this.lastTitleBarTouch.timestamp = now;
279
+ // this.lastTitleBarTouch.clientX = clientX;
280
+ // this.lastTitleBarTouch.clientY = clientY;
281
+ // };
288
282
  }
@@ -8,10 +8,12 @@
8
8
  height: 26px;
9
9
  display: flex;
10
10
  align-items: center;
11
- background: #fff;
12
11
  user-select: none;
13
- border-bottom: 1px solid #eeeef7;
14
12
  touch-action: manipulation;
13
+
14
+ @include v(color, titlebar-color, $titlebar-color);
15
+ @include v(background-color, titlebar-background, $titlebar-background);
16
+ @include v(border-bottom, titlebar-border-bottom, $titlebar-border-bottom);
15
17
  }
16
18
 
17
19
  .#{$namespace}-title-area {
@@ -26,6 +28,7 @@
26
28
 
27
29
  .#{$namespace}-title {
28
30
  @include no-user-select;
31
+ @include v(color, titlebar-color, $titlebar-color);
29
32
 
30
33
  overflow: hidden;
31
34
  margin: 0;
@@ -36,7 +39,6 @@
36
39
  white-space: nowrap;
37
40
  word-break: keep-all;
38
41
  text-overflow: ellipsis;
39
- color: #191919;
40
42
  }
41
43
 
42
44
  .#{$namespace}-drag-area {
@@ -85,31 +87,86 @@
85
87
  }
86
88
 
87
89
  .#{$namespace}-titlebar-icon-minimize {
88
- background: center / cover no-repeat url("./icons/minimize.svg");
90
+ background: center / cover no-repeat;
91
+ @include v(
92
+ background-image,
93
+ titlebar-icon-minimize,
94
+ url("./icons/minimize.svg")
95
+ );
89
96
  }
90
97
 
91
98
  .#{$namespace}-titlebar-icon-maximize {
92
- background: center / cover no-repeat url("./icons/maximize.svg");
99
+ background: center / cover no-repeat;
100
+ @include v(
101
+ background-image,
102
+ titlebar-icon-maximize,
103
+ url("./icons/maximize.svg")
104
+ );
93
105
 
94
106
  &.is-active {
95
- background-image: url("./icons/maximize-active.svg");
107
+ @include v(
108
+ background-image,
109
+ titlebar-icon-maximize-active,
110
+ url("./icons/maximize-active.svg")
111
+ );
96
112
  }
97
113
  }
98
114
 
99
115
  .#{$namespace}-titlebar-icon-close {
100
- background: center / cover no-repeat url("./icons/close.svg");
116
+ background: center / cover no-repeat;
117
+ @include v(background-image, titlebar-icon-close, url("./icons/close.svg"));
101
118
  }
102
119
 
103
120
  .#{$namespace}-color-scheme-dark {
104
121
  color-scheme: dark;
105
122
 
106
123
  .#{$namespace}-title {
107
- color: #e9e9e9;
124
+ @include v(color, titlebar-color-dark, $titlebar-color-dark);
108
125
  }
109
126
 
110
127
  .#{$namespace}-titlebar {
111
- color: #e9e9e9;
112
- background: #43434d;
113
- border-bottom: none;
128
+ @include v(color, titlebar-color-dark, $titlebar-color-dark);
129
+ @include v(
130
+ background-color,
131
+ titlebar-background-dark,
132
+ $titlebar-background-dark
133
+ );
134
+ @include v(
135
+ border-bottom,
136
+ titlebar-border-bottom-dark,
137
+ $titlebar-border-bottom-dark
138
+ );
139
+ }
140
+
141
+ .#{$namespace}-titlebar-icon-minimize {
142
+ @include v(
143
+ background-image,
144
+ titlebar-icon-minimize-dark,
145
+ url("./icons/minimize.svg")
146
+ );
147
+ }
148
+
149
+ .#{$namespace}-titlebar-icon-maximize {
150
+ @include v(
151
+ background-image,
152
+ titlebar-icon-maximize-dark,
153
+ url("./icons/maximize.svg")
154
+ );
155
+
156
+ &.is-active {
157
+ @include v(
158
+ background-image,
159
+ titlebar-icon-maximize-active-dark,
160
+ url("./icons/maximize-active.svg")
161
+ );
162
+ }
163
+ }
164
+
165
+ .#{$namespace}-titlebar-icon-close {
166
+ @include v(
167
+ background-image,
168
+ titlebar-icon-close-dark,
169
+ url("./icons/close.svg")
170
+ );
114
171
  }
115
172
  }
@@ -14,7 +14,7 @@ export interface TeleTitleBarConfig {
14
14
  state$: ReadonlyVal<TeleBoxState, boolean>;
15
15
  namespace?: string;
16
16
  onEvent?: (event: TeleTitleBarEvent) => void;
17
- onDragStart?: (event: MouseEvent | TouchEvent) => void;
17
+ onDragStart?: (event: PointerEvent) => void;
18
18
  }
19
19
 
20
20
  export interface TeleTitleBar {
@@ -5,3 +5,8 @@
5
5
  // iOS Safari
6
6
  -webkit-user-select: none;
7
7
  }
8
+
9
+ @mixin v($property, $varName, $val) {
10
+ #{$property}: $val;
11
+ #{$property}: var(--tele-#{$varName}, $val);
12
+ }
@@ -5,10 +5,44 @@ $max-titlebar-z-index: $base-z-index + 5000;
5
5
  $stage-z-index: $max-titlebar-z-index + 10;
6
6
  $collector-z-index: $stage-z-index + 10;
7
7
 
8
- $color-container-background: #f9f9f9;
9
- $color-stage-background: #fff;
10
- $color-stage-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);
8
+ $manager-container-background: #f9f9f9;
9
+ $manager-container-background-dark: #25282e;
10
+ $manager-stage-background: #fff;
11
+ $manager-stage-background-dark: #272a30;
12
+ $manager-stage-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);
13
+ $manager-stage-shadow-dark: 0px 0px 16px rgba(0, 0, 0, 0.24);
11
14
 
12
- $color-container-background-dark: #25282e;
13
- $color-stage-background-dark: #272a30;
14
- $color-stage-shadow-dark: 0px 0px 16px rgba(0, 0, 0, 0.24);
15
+ $box-container-background: $manager-container-background;
16
+ $box-container-background-dark: $manager-container-background-dark;
17
+ $box-stage-background: $manager-stage-background;
18
+ $box-stage-background-dark: $manager-stage-background-dark;
19
+ $box-stage-shadow: $manager-stage-shadow;
20
+ $box-stage-shadow-dark: $manager-stage-shadow-dark;
21
+
22
+ $box-color: #191919;
23
+ $box-color-dark: #e9e9e9;
24
+ $box-border: 1px solid #e3e3ec;
25
+ $box-border-dark: 1px solid #383b42;
26
+ $box-shadow: 0px 4px 10px 0px rgba(47, 65, 146, 0.15);
27
+ $box-shadow-dark: 0px 4px 10px 0px rgba(56, 59, 66, 0.15);
28
+
29
+ $titlebar-color: #191919;
30
+ $titlebar-color-dark: #e9e9e9;
31
+ $titlebar-background: #fff;
32
+ $titlebar-background-dark: #383b42;
33
+ $titlebar-border-bottom: 1px solid #eeeef7;
34
+ $titlebar-border-bottom-dark: none;
35
+
36
+ $titlebar-tab-color: #7b88a0;
37
+ $titlebar-tab-color-dark: #e9e9e9;
38
+ $titlebar-tab-focus-color: #357bf6;
39
+ $titlebar-tab-focus-color-dark: #357bf6;
40
+ $titlebar-tab-background: transparent;
41
+ $titlebar-tab-background-dark: transparent;
42
+ $titlebar-tab-divider-color: #e5e5f0;
43
+ $titlebar-tab-divider-color-dark: #7b88a0;
44
+
45
+ $collector-background: #fff;
46
+ $collector-background-dark: #383b42;
47
+ $collector-shadow: 0px 2px 6px 0px rgba(47, 65, 146, 0.15);
48
+ $collector-shadow-dark: $collector-shadow;
package/src/utils.ts CHANGED
@@ -9,12 +9,6 @@ export function preventEvent(ev: Event): void {
9
9
  }
10
10
  }
11
11
 
12
- export function flattenEvent(ev: MouseEvent | TouchEvent): MouseEvent | Touch {
13
- return (ev as TouchEvent).touches
14
- ? (ev as TouchEvent).touches[0]
15
- : (ev as MouseEvent);
16
- }
17
-
18
12
  export function getRandomInt(min: number, max: number): number {
19
13
  min = Math.ceil(min);
20
14
  max = Math.floor(max);