@netless/telebox-insider 1.0.0-alpha.21 → 1.0.0-alpha.24

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/dist/utils.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export declare function clamp(value: number, min: number, max: number): number;
2
2
  export declare function preventEvent(ev: Event): void;
3
- export declare function flattenEvent(ev: MouseEvent | TouchEvent): MouseEvent | Touch;
4
3
  export declare function getRandomInt(min: number, max: number): number;
5
4
  export declare function getBoxDefaultName(): string;
6
5
  export declare function identity<TValue>(value: TValue): TValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/telebox-insider",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.24",
4
4
  "private": false,
5
5
  "description": "Window widget for Whiteboard",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@ import {
20
20
  import type { TeleTitleBar } from "../TeleTitleBar";
21
21
  import { DefaultTitleBar } from "../TeleTitleBar";
22
22
  import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
23
- import { clamp, flattenEvent, getBoxDefaultName, preventEvent } from "../utils";
23
+ import { clamp, getBoxDefaultName, preventEvent } from "../utils";
24
24
  import {
25
25
  TELE_BOX_EVENT,
26
26
  TELE_BOX_STATE,
@@ -613,6 +613,9 @@ export class TeleBox {
613
613
  /** DOM of the box */
614
614
  public $box: HTMLElement;
615
615
 
616
+ /** DOM of main area of the box. Including $body and $footer. */
617
+ public $main!: HTMLElement;
618
+
616
619
  /** DOM of the box body */
617
620
  public $body!: HTMLElement;
618
621
 
@@ -849,27 +852,29 @@ export class TeleBox {
849
852
 
850
853
  $boxMain.appendChild($titleBar);
851
854
 
852
- if (this.enableShadowDOM) {
853
- const $quarantineWrap = document.createElement("div");
854
- $quarantineWrap.className = this.wrapClassName("quarantine-wrap");
855
- $boxMain.appendChild($quarantineWrap);
855
+ const $main = document.createElement("div");
856
+ $main.className = this.wrapClassName("main");
857
+ this.$main = $main;
858
+ $boxMain.appendChild($main);
856
859
 
857
- const $quarantine = document.createElement("div");
858
- $quarantine.className = this.wrapClassName("quarantine");
859
- bindBoxStates($quarantine, "bind-quarantine-state");
860
+ const $quarantineOuter = document.createElement("div");
861
+ $quarantineOuter.className = this.wrapClassName("quarantine-outer");
862
+ $main.appendChild($quarantineOuter);
860
863
 
864
+ const $quarantine = document.createElement("div");
865
+ $quarantine.className = this.wrapClassName("quarantine");
866
+ $quarantine.appendChild($body);
867
+ $quarantine.appendChild($footer);
868
+
869
+ if (this.enableShadowDOM) {
870
+ bindBoxStates($quarantine, "bind-quarantine-state");
861
871
  const $shadowStyle = document.createElement("style");
862
872
  $shadowStyle.textContent = shadowStyles;
863
-
864
- $quarantine.appendChild($shadowStyle);
865
- $quarantine.appendChild($body);
866
- $quarantine.appendChild($footer);
867
-
868
- const shadow = $quarantineWrap.attachShadow({ mode: "open" });
873
+ $quarantine.insertBefore($shadowStyle, $quarantine.firstChild);
874
+ const shadow = $quarantineOuter.attachShadow({ mode: "open" });
869
875
  shadow.appendChild($quarantine);
870
876
  } else {
871
- $boxMain.appendChild($body);
872
- $boxMain.appendChild($footer);
877
+ $quarantineOuter.appendChild($quarantine);
873
878
  }
874
879
 
875
880
  this._renderResizeHandlers();
@@ -935,9 +940,9 @@ export class TeleBox {
935
940
  return $stage;
936
941
  }
937
942
 
938
- private _handleTrackStart?: (ev: MouseEvent | TouchEvent) => void;
943
+ private _handleTrackStart?: (ev: PointerEvent) => void;
939
944
 
940
- public handleTrackStart: (ev: MouseEvent | TouchEvent) => void = (ev) => {
945
+ public handleTrackStart: (ev: PointerEvent) => void = (ev) => {
941
946
  return this._handleTrackStart?.(ev);
942
947
  };
943
948
 
@@ -974,14 +979,14 @@ export class TeleBox {
974
979
 
975
980
  let trackingHandle: TeleBoxHandleType | undefined;
976
981
 
977
- const handleTracking = (ev: MouseEvent | TouchEvent): void => {
978
- if (this.state !== TELE_BOX_STATE.Normal) {
982
+ const handleTracking = (ev: PointerEvent): void => {
983
+ if (!ev.isPrimary || this.state !== TELE_BOX_STATE.Normal) {
979
984
  return;
980
985
  }
981
986
 
982
987
  preventEvent(ev);
983
988
 
984
- let { pageX, pageY } = flattenEvent(ev);
989
+ let { pageX, pageY } = ev;
985
990
  if (pageY < 0) {
986
991
  pageY = 0;
987
992
  }
@@ -1045,7 +1050,11 @@ export class TeleBox {
1045
1050
  this.transform(newX, newY, newWidth, newHeight);
1046
1051
  };
1047
1052
 
1048
- const handleTrackEnd = (ev: MouseEvent | TouchEvent): void => {
1053
+ const handleTrackEnd = (ev: PointerEvent): void => {
1054
+ if (!ev.isPrimary) {
1055
+ return;
1056
+ }
1057
+
1049
1058
  trackingHandle = void 0;
1050
1059
 
1051
1060
  if (!$trackMask) {
@@ -1061,8 +1070,8 @@ export class TeleBox {
1061
1070
  $trackMask.remove();
1062
1071
  };
1063
1072
 
1064
- const handleTrackStart = (ev: MouseEvent | TouchEvent): void => {
1065
- if (this.readonly) {
1073
+ const handleTrackStart = (ev: PointerEvent): void => {
1074
+ if (!ev.isPrimary || this.readonly) {
1066
1075
  return;
1067
1076
  }
1068
1077
 
@@ -1090,8 +1099,7 @@ export class TeleBox {
1090
1099
  ({ width: trackStartWidth, height: trackStartHeight } =
1091
1100
  this.pxIntrinsicSize);
1092
1101
 
1093
- ({ pageX: trackStartPageX, pageY: trackStartPageY } =
1094
- flattenEvent(ev));
1102
+ ({ pageX: trackStartPageX, pageY: trackStartPageY } = ev);
1095
1103
 
1096
1104
  trackingHandle = target.dataset
1097
1105
  .teleBoxHandle as TELE_BOX_RESIZE_HANDLE;
@@ -1113,25 +1121,24 @@ export class TeleBox {
1113
1121
  this.$box.classList.add(transformingClassName);
1114
1122
 
1115
1123
  this._sideEffect.add(() => {
1116
- window.addEventListener("mousemove", handleTracking);
1117
- window.addEventListener("touchmove", handleTracking, {
1124
+ window.addEventListener("pointermove", handleTracking, {
1118
1125
  passive: false,
1119
1126
  });
1120
- window.addEventListener("mouseup", handleTrackEnd);
1121
- window.addEventListener("touchend", handleTrackEnd, {
1127
+ window.addEventListener("pointerup", handleTrackEnd, {
1122
1128
  passive: false,
1123
1129
  });
1124
- window.addEventListener("touchcancel", handleTrackEnd, {
1130
+ window.addEventListener("pointercancel", handleTrackEnd, {
1125
1131
  passive: false,
1126
1132
  });
1127
1133
 
1128
1134
  return () => {
1129
- window.removeEventListener("mousemove", handleTracking);
1130
- window.removeEventListener("touchmove", handleTracking);
1131
- window.removeEventListener("mouseup", handleTrackEnd);
1132
- window.removeEventListener("touchend", handleTrackEnd);
1133
1135
  window.removeEventListener(
1134
- "touchcancel",
1136
+ "pointermove",
1137
+ handleTracking
1138
+ );
1139
+ window.removeEventListener("pointerup", handleTrackEnd);
1140
+ window.removeEventListener(
1141
+ "pointercancel",
1135
1142
  handleTrackEnd
1136
1143
  );
1137
1144
  };
@@ -1143,18 +1150,10 @@ export class TeleBox {
1143
1150
 
1144
1151
  this._sideEffect.addEventListener(
1145
1152
  $resizeHandles,
1146
- "mousedown",
1153
+ "pointerdown",
1147
1154
  handleTrackStart,
1148
1155
  {},
1149
- "box-resizeHandles-mousedown"
1150
- );
1151
-
1152
- this._sideEffect.addEventListener(
1153
- $resizeHandles,
1154
- "touchstart",
1155
- handleTrackStart,
1156
- { passive: false },
1157
- "box-resizeHandles-touchstart"
1156
+ "box-resizeHandles-pointerdown"
1158
1157
  );
1159
1158
  }
1160
1159
 
@@ -32,10 +32,15 @@
32
32
  z-index: 1;
33
33
  }
34
34
 
35
- .#{$namespace}-quarantine-wrap {
36
- all: initial;
35
+ .#{$namespace}-main {
37
36
  flex: 1;
38
37
  width: 100%;
38
+ }
39
+
40
+ .#{$namespace}-quarantine-outer {
41
+ position: relative;
42
+ width: 100%;
43
+ height: 100%;
39
44
  overflow: hidden;
40
45
  }
41
46
 
@@ -2,6 +2,7 @@
2
2
  @import "../scss/mixins.scss";
3
3
 
4
4
  .#{$namespace}-quarantine {
5
+ all: initial;
5
6
  position: relative;
6
7
  width: 100%;
7
8
  height: 100%;
@@ -91,9 +91,9 @@ export class TeleBoxCollector {
91
91
  el$.subscribe(($collector) => {
92
92
  this._sideEffect.addEventListener(
93
93
  $collector,
94
- "click",
95
- () => {
96
- if (!readonly$.value) {
94
+ "pointerup",
95
+ (ev) => {
96
+ if (ev.isPrimary && !readonly$.value) {
97
97
  minimized$.setValue(false);
98
98
  }
99
99
  },
@@ -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,13 +271,7 @@ 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
  );
@@ -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
  }
@@ -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 {
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);