@netless/telebox-insider 1.0.0-alpha.22 → 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.
- package/dist/TeleBox/index.d.ts +3 -1
- package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +1 -7
- package/dist/TeleTitleBar/typings.d.ts +1 -1
- package/dist/style.css +643 -1
- package/dist/telebox-insider.cjs.js +1626 -2
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +40 -79
- package/dist/telebox-insider.es.js.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/package.json +1 -1
- package/src/TeleBox/index.ts +41 -46
- package/src/TeleBox/style.scss +2 -2
- package/src/TeleBox/style.shadow.scss +1 -0
- package/src/TeleBoxCollector/index.ts +3 -3
- package/src/TeleBoxManager/index.ts +3 -9
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +45 -51
- package/src/TeleTitleBar/typings.ts +1 -1
- package/src/utils.ts +0 -6
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
package/src/TeleBox/index.ts
CHANGED
|
@@ -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,
|
|
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,25 @@ export class TeleBox {
|
|
|
849
852
|
|
|
850
853
|
$boxMain.appendChild($titleBar);
|
|
851
854
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
855
|
+
const $main = document.createElement("div");
|
|
856
|
+
$main.className = this.wrapClassName("main");
|
|
857
|
+
this.$main = $main;
|
|
858
|
+
$boxMain.appendChild($main);
|
|
856
859
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
+
const $quarantine = document.createElement("div");
|
|
861
|
+
$quarantine.className = this.wrapClassName("quarantine");
|
|
862
|
+
$quarantine.appendChild($body);
|
|
863
|
+
$quarantine.appendChild($footer);
|
|
860
864
|
|
|
865
|
+
if (this.enableShadowDOM) {
|
|
866
|
+
bindBoxStates($quarantine, "bind-quarantine-state");
|
|
861
867
|
const $shadowStyle = document.createElement("style");
|
|
862
868
|
$shadowStyle.textContent = shadowStyles;
|
|
863
|
-
|
|
864
|
-
$
|
|
865
|
-
$quarantine.appendChild($body);
|
|
866
|
-
$quarantine.appendChild($footer);
|
|
867
|
-
|
|
868
|
-
const shadow = $quarantineWrap.attachShadow({ mode: "open" });
|
|
869
|
+
$quarantine.insertBefore($shadowStyle, $quarantine.firstChild);
|
|
870
|
+
const shadow = $main.attachShadow({ mode: "open" });
|
|
869
871
|
shadow.appendChild($quarantine);
|
|
870
872
|
} else {
|
|
871
|
-
$
|
|
872
|
-
$boxMain.appendChild($footer);
|
|
873
|
+
$main.appendChild($quarantine);
|
|
873
874
|
}
|
|
874
875
|
|
|
875
876
|
this._renderResizeHandlers();
|
|
@@ -935,9 +936,9 @@ export class TeleBox {
|
|
|
935
936
|
return $stage;
|
|
936
937
|
}
|
|
937
938
|
|
|
938
|
-
private _handleTrackStart?: (ev:
|
|
939
|
+
private _handleTrackStart?: (ev: PointerEvent) => void;
|
|
939
940
|
|
|
940
|
-
public handleTrackStart: (ev:
|
|
941
|
+
public handleTrackStart: (ev: PointerEvent) => void = (ev) => {
|
|
941
942
|
return this._handleTrackStart?.(ev);
|
|
942
943
|
};
|
|
943
944
|
|
|
@@ -974,14 +975,14 @@ export class TeleBox {
|
|
|
974
975
|
|
|
975
976
|
let trackingHandle: TeleBoxHandleType | undefined;
|
|
976
977
|
|
|
977
|
-
const handleTracking = (ev:
|
|
978
|
-
if (this.state !== TELE_BOX_STATE.Normal) {
|
|
978
|
+
const handleTracking = (ev: PointerEvent): void => {
|
|
979
|
+
if (!ev.isPrimary || this.state !== TELE_BOX_STATE.Normal) {
|
|
979
980
|
return;
|
|
980
981
|
}
|
|
981
982
|
|
|
982
983
|
preventEvent(ev);
|
|
983
984
|
|
|
984
|
-
let { pageX, pageY } =
|
|
985
|
+
let { pageX, pageY } = ev;
|
|
985
986
|
if (pageY < 0) {
|
|
986
987
|
pageY = 0;
|
|
987
988
|
}
|
|
@@ -1045,7 +1046,11 @@ export class TeleBox {
|
|
|
1045
1046
|
this.transform(newX, newY, newWidth, newHeight);
|
|
1046
1047
|
};
|
|
1047
1048
|
|
|
1048
|
-
const handleTrackEnd = (ev:
|
|
1049
|
+
const handleTrackEnd = (ev: PointerEvent): void => {
|
|
1050
|
+
if (!ev.isPrimary) {
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1049
1054
|
trackingHandle = void 0;
|
|
1050
1055
|
|
|
1051
1056
|
if (!$trackMask) {
|
|
@@ -1061,8 +1066,8 @@ export class TeleBox {
|
|
|
1061
1066
|
$trackMask.remove();
|
|
1062
1067
|
};
|
|
1063
1068
|
|
|
1064
|
-
const handleTrackStart = (ev:
|
|
1065
|
-
if (this.readonly) {
|
|
1069
|
+
const handleTrackStart = (ev: PointerEvent): void => {
|
|
1070
|
+
if (!ev.isPrimary || this.readonly) {
|
|
1066
1071
|
return;
|
|
1067
1072
|
}
|
|
1068
1073
|
|
|
@@ -1090,8 +1095,7 @@ export class TeleBox {
|
|
|
1090
1095
|
({ width: trackStartWidth, height: trackStartHeight } =
|
|
1091
1096
|
this.pxIntrinsicSize);
|
|
1092
1097
|
|
|
1093
|
-
({ pageX: trackStartPageX, pageY: trackStartPageY } =
|
|
1094
|
-
flattenEvent(ev));
|
|
1098
|
+
({ pageX: trackStartPageX, pageY: trackStartPageY } = ev);
|
|
1095
1099
|
|
|
1096
1100
|
trackingHandle = target.dataset
|
|
1097
1101
|
.teleBoxHandle as TELE_BOX_RESIZE_HANDLE;
|
|
@@ -1113,25 +1117,24 @@ export class TeleBox {
|
|
|
1113
1117
|
this.$box.classList.add(transformingClassName);
|
|
1114
1118
|
|
|
1115
1119
|
this._sideEffect.add(() => {
|
|
1116
|
-
window.addEventListener("
|
|
1117
|
-
window.addEventListener("touchmove", handleTracking, {
|
|
1120
|
+
window.addEventListener("pointermove", handleTracking, {
|
|
1118
1121
|
passive: false,
|
|
1119
1122
|
});
|
|
1120
|
-
window.addEventListener("
|
|
1121
|
-
window.addEventListener("touchend", handleTrackEnd, {
|
|
1123
|
+
window.addEventListener("pointerup", handleTrackEnd, {
|
|
1122
1124
|
passive: false,
|
|
1123
1125
|
});
|
|
1124
|
-
window.addEventListener("
|
|
1126
|
+
window.addEventListener("pointercancel", handleTrackEnd, {
|
|
1125
1127
|
passive: false,
|
|
1126
1128
|
});
|
|
1127
1129
|
|
|
1128
1130
|
return () => {
|
|
1129
|
-
window.removeEventListener("mousemove", handleTracking);
|
|
1130
|
-
window.removeEventListener("touchmove", handleTracking);
|
|
1131
|
-
window.removeEventListener("mouseup", handleTrackEnd);
|
|
1132
|
-
window.removeEventListener("touchend", handleTrackEnd);
|
|
1133
1131
|
window.removeEventListener(
|
|
1134
|
-
"
|
|
1132
|
+
"pointermove",
|
|
1133
|
+
handleTracking
|
|
1134
|
+
);
|
|
1135
|
+
window.removeEventListener("pointerup", handleTrackEnd);
|
|
1136
|
+
window.removeEventListener(
|
|
1137
|
+
"pointercancel",
|
|
1135
1138
|
handleTrackEnd
|
|
1136
1139
|
);
|
|
1137
1140
|
};
|
|
@@ -1143,18 +1146,10 @@ export class TeleBox {
|
|
|
1143
1146
|
|
|
1144
1147
|
this._sideEffect.addEventListener(
|
|
1145
1148
|
$resizeHandles,
|
|
1146
|
-
"
|
|
1149
|
+
"pointerdown",
|
|
1147
1150
|
handleTrackStart,
|
|
1148
1151
|
{},
|
|
1149
|
-
"box-resizeHandles-
|
|
1150
|
-
);
|
|
1151
|
-
|
|
1152
|
-
this._sideEffect.addEventListener(
|
|
1153
|
-
$resizeHandles,
|
|
1154
|
-
"touchstart",
|
|
1155
|
-
handleTrackStart,
|
|
1156
|
-
{ passive: false },
|
|
1157
|
-
"box-resizeHandles-touchstart"
|
|
1152
|
+
"box-resizeHandles-pointerdown"
|
|
1158
1153
|
);
|
|
1159
1154
|
}
|
|
1160
1155
|
|
package/src/TeleBox/style.scss
CHANGED
|
@@ -91,9 +91,9 @@ export class TeleBoxCollector {
|
|
|
91
91
|
el$.subscribe(($collector) => {
|
|
92
92
|
this._sideEffect.addEventListener(
|
|
93
93
|
$collector,
|
|
94
|
-
"
|
|
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:
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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:
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
protected handleTitleBarTouch = (ev: TouchEvent): void => {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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:
|
|
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);
|