@netless/telebox-insider 0.2.17 → 0.2.21
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/TeleTitleBar/DefaultTitleBar/index.d.ts +14 -2
- package/dist/style.css +1 -1
- package/dist/telebox-insider.cjs.js +2 -2
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +2 -2
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +1 -1
- package/src/TeleBox/index.ts +1 -1
- package/src/TeleBox/style.scss +0 -2
- package/src/TeleBoxManager/MaxTitleBar/index.ts +7 -0
- package/src/TeleBoxManager/MaxTitleBar/style.scss +12 -6
- package/src/TeleBoxManager/index.ts +27 -17
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +90 -24
- package/src/TeleTitleBar/DefaultTitleBar/style.scss +21 -1
package/package.json
CHANGED
package/src/TeleBox/index.ts
CHANGED
package/src/TeleBox/style.scss
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
top: 0;
|
|
6
6
|
left: 0;
|
|
7
7
|
z-index: $base-z-index;
|
|
8
|
-
will-change: transform;
|
|
9
8
|
transition: width 0.4s cubic-bezier(0.4, 0.9, 0.71, 1.02),
|
|
10
9
|
height 0.4s cubic-bezier(0.55, 0.82, 0.63, 0.95),
|
|
11
10
|
opacity 0.6s cubic-bezier(0.7, 0, 0.84, 0), transform 0.4s ease;
|
|
@@ -182,7 +181,6 @@
|
|
|
182
181
|
}
|
|
183
182
|
|
|
184
183
|
.#{$namespace}-minimized {
|
|
185
|
-
will-change: transform;
|
|
186
184
|
transition: width 0.05s cubic-bezier(0.4, 0.9, 0.71, 1.02),
|
|
187
185
|
height 0.05s cubic-bezier(0.55, 0.82, 0.63, 0.95),
|
|
188
186
|
opacity 0.6s cubic-bezier(0.7, 0, 0.84, 0), transform 0.6s ease;
|
|
@@ -105,6 +105,13 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
105
105
|
|
|
106
106
|
public render(): HTMLElement {
|
|
107
107
|
const $titleBar = super.render();
|
|
108
|
+
if ($titleBar.firstElementChild?.nextElementSibling) {
|
|
109
|
+
$titleBar.insertBefore(
|
|
110
|
+
this.$dragArea,
|
|
111
|
+
$titleBar.firstElementChild.nextElementSibling
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
108
115
|
const { x, y, width } = this.containerRect;
|
|
109
116
|
$titleBar.style.transform = `translate(${x}px, ${y}px)`;
|
|
110
117
|
$titleBar.style.width = width + "px";
|
|
@@ -15,6 +15,15 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
|
|
|
15
15
|
left: 0;
|
|
16
16
|
z-index: $base-z-index * 500;
|
|
17
17
|
user-select: none;
|
|
18
|
+
|
|
19
|
+
.#{$namespace}-drag-area {
|
|
20
|
+
height: 100%;
|
|
21
|
+
min-width: 16px;
|
|
22
|
+
position: static;
|
|
23
|
+
margin: 0;
|
|
24
|
+
flex-grow: 1;
|
|
25
|
+
flex-shrink: 0;
|
|
26
|
+
}
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
.#{$namespace}-max-titlebar-maximized {
|
|
@@ -36,9 +45,8 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
|
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
.#{$namespace}-titles {
|
|
39
|
-
flex: 1;
|
|
40
48
|
height: 100%;
|
|
41
|
-
margin: 0
|
|
49
|
+
margin: 0;
|
|
42
50
|
overflow-y: hidden;
|
|
43
51
|
overflow-x: scroll;
|
|
44
52
|
overflow-x: overlay; // for webkit
|
|
@@ -92,6 +100,7 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
|
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
.#{$namespace}-titles-tab {
|
|
103
|
+
height: 100%;
|
|
95
104
|
overflow: hidden;
|
|
96
105
|
max-width: 182px;
|
|
97
106
|
min-width: 50px;
|
|
@@ -108,10 +117,7 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
|
|
|
108
117
|
color: #7b88a0;
|
|
109
118
|
background: transparent;
|
|
110
119
|
cursor: pointer;
|
|
111
|
-
|
|
112
|
-
& ~ & {
|
|
113
|
-
margin-left: 2px;
|
|
114
|
-
}
|
|
120
|
+
user-select: none;
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
.#{$namespace}-titles-tab-focus {
|
|
@@ -432,25 +432,38 @@ export class TeleBoxManager {
|
|
|
432
432
|
this.remove(box);
|
|
433
433
|
this.focusTopBox();
|
|
434
434
|
});
|
|
435
|
-
box.
|
|
436
|
-
|
|
435
|
+
box._coord$.reaction((_, __, skipUpdate) => {
|
|
436
|
+
if (!skipUpdate) {
|
|
437
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Move, box);
|
|
438
|
+
}
|
|
437
439
|
});
|
|
438
|
-
box.
|
|
439
|
-
|
|
440
|
+
box._size$.reaction((_, __, skipUpdate) => {
|
|
441
|
+
if (!skipUpdate) {
|
|
442
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.Resize, box);
|
|
443
|
+
}
|
|
440
444
|
});
|
|
441
|
-
box.
|
|
442
|
-
|
|
445
|
+
box._intrinsicCoord$.reaction((_, __, skipUpdate) => {
|
|
446
|
+
if (!skipUpdate) {
|
|
447
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicMove, box);
|
|
448
|
+
}
|
|
443
449
|
});
|
|
444
|
-
box.
|
|
445
|
-
|
|
450
|
+
box._intrinsicSize$.reaction((_, __, skipUpdate) => {
|
|
451
|
+
if (!skipUpdate) {
|
|
452
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.IntrinsicResize, box);
|
|
453
|
+
}
|
|
446
454
|
});
|
|
447
|
-
box.
|
|
448
|
-
|
|
455
|
+
box._visualSize$.reaction((_, __, skipUpdate) => {
|
|
456
|
+
if (!skipUpdate) {
|
|
457
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.VisualResize, box);
|
|
458
|
+
}
|
|
449
459
|
});
|
|
450
|
-
box.
|
|
460
|
+
box._zIndex$.reaction((_, __, skipUpdate) => {
|
|
451
461
|
if (this.topBox && box.zIndex > this.topBox.zIndex) {
|
|
452
462
|
this.topBox$.setValue(box);
|
|
453
463
|
}
|
|
464
|
+
if (!skipUpdate) {
|
|
465
|
+
this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
|
|
466
|
+
}
|
|
454
467
|
});
|
|
455
468
|
this.events.emit(TELE_BOX_MANAGER_EVENT.Created, box);
|
|
456
469
|
|
|
@@ -658,16 +671,16 @@ export class TeleBoxManager {
|
|
|
658
671
|
box.setMinWidth(config.minWidth, skipUpdate);
|
|
659
672
|
}
|
|
660
673
|
if (config.resizable != null) {
|
|
661
|
-
box.setResizable(config.resizable);
|
|
674
|
+
box.setResizable(config.resizable, skipUpdate);
|
|
662
675
|
}
|
|
663
676
|
if (config.draggable != null) {
|
|
664
|
-
box.setDraggable(config.draggable);
|
|
677
|
+
box.setDraggable(config.draggable, skipUpdate);
|
|
665
678
|
}
|
|
666
679
|
if (config.fixRatio != null) {
|
|
667
680
|
box.setFixRatio(config.fixRatio, skipUpdate);
|
|
668
681
|
}
|
|
669
682
|
if (config.zIndex != null) {
|
|
670
|
-
box.setZIndex(config.zIndex);
|
|
683
|
+
box.setZIndex(config.zIndex, skipUpdate);
|
|
671
684
|
}
|
|
672
685
|
if (config.content != null) {
|
|
673
686
|
box.mountContent(config.content);
|
|
@@ -722,9 +735,6 @@ export class TeleBoxManager {
|
|
|
722
735
|
if (box !== this.topBox) {
|
|
723
736
|
box.setZIndex(this.topBox.zIndex + 1, skipUpdate);
|
|
724
737
|
this.topBox$.setValue(box);
|
|
725
|
-
if (!skipUpdate) {
|
|
726
|
-
this.events.emit(TELE_BOX_MANAGER_EVENT.ZIndex, box);
|
|
727
|
-
}
|
|
728
738
|
}
|
|
729
739
|
}
|
|
730
740
|
}
|
|
@@ -56,6 +56,8 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
56
56
|
iconClassName: this.wrapClassName("titlebar-icon-close"),
|
|
57
57
|
},
|
|
58
58
|
];
|
|
59
|
+
|
|
60
|
+
this.$dragArea = this.renderDragArea();
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
public readonly namespace: string;
|
|
@@ -64,6 +66,8 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
64
66
|
|
|
65
67
|
public $title: HTMLElement | undefined;
|
|
66
68
|
|
|
69
|
+
public $dragArea: HTMLElement;
|
|
70
|
+
|
|
67
71
|
public setTitle(title: string): void {
|
|
68
72
|
this.title = title;
|
|
69
73
|
if (this.$title) {
|
|
@@ -97,18 +101,10 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
97
101
|
if (!this.$titleBar) {
|
|
98
102
|
this.$titleBar = document.createElement("div");
|
|
99
103
|
this.$titleBar.className = this.wrapClassName("titlebar");
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this.handleTitleBarClick
|
|
105
|
-
);
|
|
106
|
-
this.sideEffect.addEventListener(
|
|
107
|
-
this.$titleBar,
|
|
108
|
-
"touchstart",
|
|
109
|
-
this.handleTitleBarClick,
|
|
110
|
-
{ passive: true }
|
|
111
|
-
);
|
|
104
|
+
|
|
105
|
+
const $titleArea = document.createElement("div");
|
|
106
|
+
$titleArea.className = this.wrapClassName("title-area");
|
|
107
|
+
$titleArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
|
|
112
108
|
|
|
113
109
|
this.$title = document.createElement("h1");
|
|
114
110
|
this.$title.className = this.wrapClassName("title");
|
|
@@ -118,6 +114,9 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
118
114
|
this.$title.title = this.title;
|
|
119
115
|
}
|
|
120
116
|
|
|
117
|
+
$titleArea.appendChild(this.$title);
|
|
118
|
+
$titleArea.appendChild(this.$dragArea);
|
|
119
|
+
|
|
121
120
|
const $buttonsContainer = document.createElement("div");
|
|
122
121
|
$buttonsContainer.className = this.wrapClassName("titlebar-btns");
|
|
123
122
|
|
|
@@ -167,13 +166,31 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
167
166
|
}
|
|
168
167
|
);
|
|
169
168
|
|
|
170
|
-
this.$titleBar.appendChild(
|
|
169
|
+
this.$titleBar.appendChild($titleArea);
|
|
171
170
|
this.$titleBar.appendChild($buttonsContainer);
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
return this.$titleBar;
|
|
175
174
|
}
|
|
176
175
|
|
|
176
|
+
public renderDragArea(): HTMLElement {
|
|
177
|
+
const $dragArea = document.createElement("div");
|
|
178
|
+
$dragArea.className = this.wrapClassName("drag-area");
|
|
179
|
+
$dragArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
|
|
180
|
+
this.sideEffect.addEventListener(
|
|
181
|
+
$dragArea,
|
|
182
|
+
"mousedown",
|
|
183
|
+
this.handleTitleBarClick
|
|
184
|
+
);
|
|
185
|
+
this.sideEffect.addEventListener(
|
|
186
|
+
$dragArea,
|
|
187
|
+
"touchstart",
|
|
188
|
+
this.handleTitleBarTouch,
|
|
189
|
+
{ passive: true }
|
|
190
|
+
);
|
|
191
|
+
return $dragArea;
|
|
192
|
+
}
|
|
193
|
+
|
|
177
194
|
public dragHandle(): HTMLElement | undefined {
|
|
178
195
|
return this.$titleBar;
|
|
179
196
|
}
|
|
@@ -209,17 +226,18 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
209
226
|
|
|
210
227
|
protected sideEffect = new SideEffectManager();
|
|
211
228
|
|
|
212
|
-
protected lastTitleBarClick =
|
|
229
|
+
protected lastTitleBarClick = {
|
|
230
|
+
timestamp: 0,
|
|
231
|
+
clientX: -100,
|
|
232
|
+
clientY: -100,
|
|
233
|
+
};
|
|
213
234
|
|
|
214
|
-
protected handleTitleBarClick = (ev: MouseEvent
|
|
235
|
+
protected handleTitleBarClick = (ev: MouseEvent): void => {
|
|
215
236
|
if (this.readonly) {
|
|
216
237
|
return;
|
|
217
238
|
}
|
|
218
239
|
|
|
219
|
-
if (
|
|
220
|
-
(ev as MouseEvent).button != null &&
|
|
221
|
-
(ev as MouseEvent).button !== 0
|
|
222
|
-
) {
|
|
240
|
+
if (ev.button !== 0) {
|
|
223
241
|
return; // Not left mouse
|
|
224
242
|
}
|
|
225
243
|
|
|
@@ -230,14 +248,62 @@ export class DefaultTitleBar implements TeleTitleBar {
|
|
|
230
248
|
preventEvent(ev);
|
|
231
249
|
|
|
232
250
|
const now = Date.now();
|
|
233
|
-
if (now - this.lastTitleBarClick <= 500) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
251
|
+
if (now - this.lastTitleBarClick.timestamp <= 500) {
|
|
252
|
+
if (
|
|
253
|
+
Math.abs(ev.clientX - this.lastTitleBarClick.clientX) <= 3 &&
|
|
254
|
+
Math.abs(ev.clientY - this.lastTitleBarClick.clientY) <= 3
|
|
255
|
+
) {
|
|
256
|
+
// double click
|
|
257
|
+
if (this.onEvent) {
|
|
258
|
+
this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
} else if (this.onDragStart) {
|
|
262
|
+
this.onDragStart(ev);
|
|
263
|
+
}
|
|
264
|
+
this.lastTitleBarClick.timestamp = now;
|
|
265
|
+
this.lastTitleBarClick.clientX = ev.clientX;
|
|
266
|
+
this.lastTitleBarClick.clientY = ev.clientY;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
protected lastTitleBarTouch = {
|
|
270
|
+
timestamp: 0,
|
|
271
|
+
clientX: -100,
|
|
272
|
+
clientY: -100,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
protected handleTitleBarTouch = (ev: TouchEvent): void => {
|
|
276
|
+
if (this.readonly) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if ((ev.target as HTMLElement).dataset?.teleTitleBarNoDblClick) {
|
|
281
|
+
return; // btns
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
preventEvent(ev);
|
|
285
|
+
|
|
286
|
+
const now = Date.now();
|
|
287
|
+
const {
|
|
288
|
+
clientX = this.lastTitleBarTouch.clientX + 100,
|
|
289
|
+
clientY = this.lastTitleBarTouch.clientY + 100,
|
|
290
|
+
} = ev.touches[0] || {};
|
|
291
|
+
|
|
292
|
+
if (now - this.lastTitleBarTouch.timestamp <= 500) {
|
|
293
|
+
if (
|
|
294
|
+
Math.abs(clientX - this.lastTitleBarTouch.clientX) <= 3 &&
|
|
295
|
+
Math.abs(clientY - this.lastTitleBarTouch.clientY) <= 3
|
|
296
|
+
) {
|
|
297
|
+
// double click
|
|
298
|
+
if (this.onEvent) {
|
|
299
|
+
this.onEvent({ type: TELE_BOX_DELEGATE_EVENT.Maximize });
|
|
300
|
+
}
|
|
237
301
|
}
|
|
238
302
|
} else if (this.onDragStart) {
|
|
239
303
|
this.onDragStart(ev);
|
|
240
304
|
}
|
|
241
|
-
this.
|
|
305
|
+
this.lastTitleBarTouch.timestamp = now;
|
|
306
|
+
this.lastTitleBarTouch.clientX = clientX;
|
|
307
|
+
this.lastTitleBarTouch.clientY = clientY;
|
|
242
308
|
};
|
|
243
309
|
}
|
|
@@ -9,11 +9,21 @@
|
|
|
9
9
|
background: #fff;
|
|
10
10
|
user-select: none;
|
|
11
11
|
border-bottom: 1px solid #eeeef7;
|
|
12
|
+
touch-action: manipulation;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.#{$namespace}-title-area {
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
position: relative;
|
|
18
|
+
height: 100%;
|
|
19
|
+
flex: 1;
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
12
22
|
}
|
|
13
23
|
|
|
14
24
|
.#{$namespace}-title {
|
|
15
25
|
overflow: hidden;
|
|
16
|
-
margin: 0
|
|
26
|
+
margin: 0;
|
|
17
27
|
padding: 0;
|
|
18
28
|
font-size: 14px;
|
|
19
29
|
font-weight: 400;
|
|
@@ -24,6 +34,16 @@
|
|
|
24
34
|
color: #191919;
|
|
25
35
|
}
|
|
26
36
|
|
|
37
|
+
.#{$namespace}-drag-area {
|
|
38
|
+
position: absolute;
|
|
39
|
+
top: 0;
|
|
40
|
+
left: 0;
|
|
41
|
+
right: 0;
|
|
42
|
+
bottom: 0;
|
|
43
|
+
margin: auto;
|
|
44
|
+
z-index: 10;
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
.#{$namespace}-titlebar-btns {
|
|
28
48
|
white-space: nowrap;
|
|
29
49
|
word-break: keep-all;
|