@netless/telebox-insider 0.3.0 → 0.3.1-beta.0
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/index.d.ts +20 -9
- package/dist/style.css +3 -0
- package/dist/telebox-insider.cjs.js +269 -88
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +269 -88
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +1 -1
- package/src/TeleBox/index.ts +90 -21
- package/src/TeleBox/typings.ts +10 -2
- package/src/TeleBoxManager/index.ts +387 -150
- package/src/TeleBoxManager/typings.ts +6 -2
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +66 -25
- package/src/TeleTitleBar/DefaultTitleBar/style.scss +5 -0
- package/src/TeleTitleBar/typings.ts +3 -0
package/package.json
CHANGED
package/src/TeleBox/index.ts
CHANGED
|
@@ -76,6 +76,8 @@ type ValConfig = {
|
|
|
76
76
|
forceTop: Val<boolean, boolean>;
|
|
77
77
|
/** Force normal. */
|
|
78
78
|
forceNormal: Val<boolean, boolean>;
|
|
79
|
+
/** Force maximized room policy. */
|
|
80
|
+
forceMaximized: Val<boolean, boolean>;
|
|
79
81
|
/** Drag content. */
|
|
80
82
|
isDragContent: Val<boolean, boolean>;
|
|
81
83
|
};
|
|
@@ -119,6 +121,7 @@ export class TeleBox {
|
|
|
119
121
|
lastNotMinimizedBoxStatus,
|
|
120
122
|
forceTop = false,
|
|
121
123
|
forceNormal = false,
|
|
124
|
+
forceMaximized = false,
|
|
122
125
|
isDragContent = false,
|
|
123
126
|
}: TeleBoxConfig = {}) {
|
|
124
127
|
this._sideEffect = new SideEffectManager();
|
|
@@ -129,8 +132,13 @@ export class TeleBox {
|
|
|
129
132
|
this.namespace = namespace;
|
|
130
133
|
this.events = new EventEmitter();
|
|
131
134
|
this._delegateEvents = new EventEmitter();
|
|
132
|
-
const boxStatus$ = createVal<TeleBoxState | undefined, boolean>(
|
|
133
|
-
|
|
135
|
+
const boxStatus$ = createVal<TeleBoxState | undefined, boolean>(
|
|
136
|
+
boxStatus
|
|
137
|
+
);
|
|
138
|
+
const lastNotMinimizedBoxStatus$ = createVal<
|
|
139
|
+
NotMinimizedBoxState | undefined,
|
|
140
|
+
boolean
|
|
141
|
+
>(lastNotMinimizedBoxStatus);
|
|
134
142
|
|
|
135
143
|
const prefersColorScheme$ = createVal<TeleBoxColorScheme, boolean>(
|
|
136
144
|
prefersColorScheme
|
|
@@ -199,9 +207,13 @@ export class TeleBox {
|
|
|
199
207
|
});
|
|
200
208
|
|
|
201
209
|
const forceNormal$ = createVal(forceNormal);
|
|
210
|
+
const forceMaximized$ = createVal(forceMaximized);
|
|
202
211
|
forceNormal$.reaction((forceNormal, _, skipUpdate) => {
|
|
203
212
|
if (!skipUpdate) {
|
|
204
|
-
this.events.emit(
|
|
213
|
+
this.events.emit(
|
|
214
|
+
TELE_BOX_EVENT.ForceNormal,
|
|
215
|
+
forceNormal || false
|
|
216
|
+
);
|
|
205
217
|
}
|
|
206
218
|
});
|
|
207
219
|
const isDragContent$ = createVal(isDragContent);
|
|
@@ -269,7 +281,8 @@ export class TeleBox {
|
|
|
269
281
|
? TELE_BOX_STATE.Minimized
|
|
270
282
|
: maximized
|
|
271
283
|
? TELE_BOX_STATE.Maximized
|
|
272
|
-
: !boxStatus
|
|
284
|
+
: !boxStatus
|
|
285
|
+
? TELE_BOX_STATE.Normal
|
|
273
286
|
: boxStatus
|
|
274
287
|
);
|
|
275
288
|
state$.reaction((state, _, skipUpdate) => {
|
|
@@ -327,7 +340,10 @@ export class TeleBox {
|
|
|
327
340
|
const visualSize$ = combine(
|
|
328
341
|
[size$, minimized$, containerRect$, collectorRect$, boxStatus$],
|
|
329
342
|
([size, minimized, containerRect, collectorRect, boxStatus]) => {
|
|
330
|
-
if (
|
|
343
|
+
if (
|
|
344
|
+
(minimized || boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
345
|
+
collectorRect
|
|
346
|
+
) {
|
|
331
347
|
return {
|
|
332
348
|
width:
|
|
333
349
|
collectorRect.width /
|
|
@@ -380,8 +396,14 @@ export class TeleBox {
|
|
|
380
396
|
boxStatus,
|
|
381
397
|
lastNotMinimizedBoxStatus,
|
|
382
398
|
]) => {
|
|
383
|
-
if (
|
|
384
|
-
|
|
399
|
+
if (
|
|
400
|
+
(minimized || boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
401
|
+
collectorRect
|
|
402
|
+
) {
|
|
403
|
+
if (
|
|
404
|
+
maximized ||
|
|
405
|
+
lastNotMinimizedBoxStatus === TELE_BOX_STATE.Maximized
|
|
406
|
+
) {
|
|
385
407
|
return {
|
|
386
408
|
x:
|
|
387
409
|
(collectorRect.x + collectorRect.width / 2) /
|
|
@@ -426,6 +448,7 @@ export class TeleBox {
|
|
|
426
448
|
boxStatus: boxStatus$.value,
|
|
427
449
|
forceTop: forceTop$.value,
|
|
428
450
|
forceNormal: forceNormal$.value,
|
|
451
|
+
forceMaximized: forceMaximized$.value,
|
|
429
452
|
onDragStart: (event) => this._handleTrackStart?.(event),
|
|
430
453
|
onEvent: (event): void => {
|
|
431
454
|
if (this._delegateEvents.listeners.length > 0) {
|
|
@@ -433,7 +456,10 @@ export class TeleBox {
|
|
|
433
456
|
} else {
|
|
434
457
|
switch (event.type) {
|
|
435
458
|
case TELE_BOX_DELEGATE_EVENT.Maximize: {
|
|
436
|
-
if (
|
|
459
|
+
if (
|
|
460
|
+
!boxStatus$.value &&
|
|
461
|
+
!(forceMaximized$.value && maximized$.value)
|
|
462
|
+
) {
|
|
437
463
|
maximized$.setValue(!maximized$.value);
|
|
438
464
|
}
|
|
439
465
|
break;
|
|
@@ -462,6 +488,9 @@ export class TeleBox {
|
|
|
462
488
|
readonly$.reaction((readonly) => {
|
|
463
489
|
this.titleBar.setReadonly(readonly);
|
|
464
490
|
});
|
|
491
|
+
forceMaximized$.reaction((forceMaximized) => {
|
|
492
|
+
this.titleBar.setForceMaximized(forceMaximized);
|
|
493
|
+
});
|
|
465
494
|
boxStatus$.reaction((boxStatus) => {
|
|
466
495
|
this.titleBar.setBoxStatus(boxStatus);
|
|
467
496
|
});
|
|
@@ -491,6 +520,7 @@ export class TeleBox {
|
|
|
491
520
|
$userStyles: $userStyles$,
|
|
492
521
|
forceTop: forceTop$,
|
|
493
522
|
forceNormal: forceNormal$,
|
|
523
|
+
forceMaximized: forceMaximized$,
|
|
494
524
|
isDragContent: isDragContent$,
|
|
495
525
|
};
|
|
496
526
|
|
|
@@ -541,7 +571,10 @@ export class TeleBox {
|
|
|
541
571
|
public _coord$: Val<TeleBoxCoord, boolean>;
|
|
542
572
|
public _intrinsicCoord$: Val<TeleBoxCoord, boolean>;
|
|
543
573
|
public _boxStatus$: Val<TeleBoxState | undefined, boolean>;
|
|
544
|
-
public _lastNotMinimizedBoxStatus$: Val<
|
|
574
|
+
public _lastNotMinimizedBoxStatus$: Val<
|
|
575
|
+
NotMinimizedBoxState | undefined,
|
|
576
|
+
boolean
|
|
577
|
+
>;
|
|
545
578
|
|
|
546
579
|
public get boxStatus(): TeleBoxState | undefined {
|
|
547
580
|
return this._boxStatus$.value;
|
|
@@ -588,23 +621,41 @@ export class TeleBox {
|
|
|
588
621
|
|
|
589
622
|
public setBoxStatus(boxStatus: TeleBoxState, skipUpdate = false): this {
|
|
590
623
|
if (boxStatus === TELE_BOX_STATE.Minimized) {
|
|
591
|
-
if (
|
|
592
|
-
this.
|
|
624
|
+
if (
|
|
625
|
+
this._boxStatus$.value &&
|
|
626
|
+
this._boxStatus$.value !== TELE_BOX_STATE.Minimized
|
|
627
|
+
) {
|
|
628
|
+
this.setLastNotMinimizedBoxStatus(
|
|
629
|
+
this._boxStatus$.value,
|
|
630
|
+
skipUpdate
|
|
631
|
+
);
|
|
593
632
|
}
|
|
594
633
|
} else {
|
|
595
634
|
this.setLastNotMinimizedBoxStatus(undefined, skipUpdate);
|
|
596
635
|
}
|
|
597
636
|
this._boxStatus$.setValue(boxStatus, skipUpdate);
|
|
598
637
|
if (!skipUpdate) {
|
|
599
|
-
this.events.emit(TELE_BOX_EVENT.BoxStatus, {
|
|
638
|
+
this.events.emit(TELE_BOX_EVENT.BoxStatus, {
|
|
639
|
+
id: this.id,
|
|
640
|
+
boxStatus,
|
|
641
|
+
});
|
|
600
642
|
}
|
|
601
643
|
return this;
|
|
602
644
|
}
|
|
603
645
|
|
|
604
|
-
public setLastNotMinimizedBoxStatus(
|
|
605
|
-
|
|
646
|
+
public setLastNotMinimizedBoxStatus(
|
|
647
|
+
lastNotMinimizedBoxStatus?: NotMinimizedBoxState,
|
|
648
|
+
skipUpdate = false
|
|
649
|
+
): this {
|
|
650
|
+
this._lastNotMinimizedBoxStatus$.setValue(
|
|
651
|
+
lastNotMinimizedBoxStatus,
|
|
652
|
+
skipUpdate
|
|
653
|
+
);
|
|
606
654
|
if (!skipUpdate) {
|
|
607
|
-
this.events.emit(TELE_BOX_EVENT.LastNotMinimizedBoxStatus, {
|
|
655
|
+
this.events.emit(TELE_BOX_EVENT.LastNotMinimizedBoxStatus, {
|
|
656
|
+
id: this.id,
|
|
657
|
+
lastNotMinimizedBoxStatus,
|
|
658
|
+
});
|
|
608
659
|
}
|
|
609
660
|
return this;
|
|
610
661
|
}
|
|
@@ -979,24 +1030,43 @@ export class TeleBox {
|
|
|
979
1030
|
this._collectorRect$,
|
|
980
1031
|
this._boxStatus$,
|
|
981
1032
|
],
|
|
982
|
-
([
|
|
1033
|
+
([
|
|
1034
|
+
coord,
|
|
1035
|
+
size,
|
|
1036
|
+
minimized,
|
|
1037
|
+
containerRect,
|
|
1038
|
+
collectorRect,
|
|
1039
|
+
boxStatus,
|
|
1040
|
+
]) => {
|
|
983
1041
|
const absoluteWidth = size.width * containerRect.width;
|
|
984
1042
|
const absoluteHeight = size.height * containerRect.height;
|
|
985
1043
|
return {
|
|
986
1044
|
width:
|
|
987
1045
|
absoluteWidth +
|
|
988
|
-
((minimized ||
|
|
1046
|
+
((minimized ||
|
|
1047
|
+
boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
1048
|
+
collectorRect
|
|
1049
|
+
? 1
|
|
1050
|
+
: 0),
|
|
989
1051
|
height:
|
|
990
1052
|
absoluteHeight +
|
|
991
|
-
((minimized ||
|
|
1053
|
+
((minimized ||
|
|
1054
|
+
boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
1055
|
+
collectorRect
|
|
1056
|
+
? 1
|
|
1057
|
+
: 0),
|
|
992
1058
|
x: coord.x * containerRect.width,
|
|
993
1059
|
y: coord.y * containerRect.height,
|
|
994
1060
|
scaleX:
|
|
995
|
-
(minimized ||
|
|
1061
|
+
(minimized ||
|
|
1062
|
+
boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
1063
|
+
collectorRect
|
|
996
1064
|
? collectorRect.width / absoluteWidth
|
|
997
1065
|
: 1,
|
|
998
1066
|
scaleY:
|
|
999
|
-
(minimized ||
|
|
1067
|
+
(minimized ||
|
|
1068
|
+
boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
1069
|
+
collectorRect
|
|
1000
1070
|
? collectorRect.height / absoluteHeight
|
|
1001
1071
|
: 1,
|
|
1002
1072
|
};
|
|
@@ -1018,7 +1088,6 @@ export class TeleBox {
|
|
|
1018
1088
|
$titleBar.appendChild(this.titleBar.render());
|
|
1019
1089
|
this.$titleBar = $titleBar;
|
|
1020
1090
|
|
|
1021
|
-
|
|
1022
1091
|
const $contentWrap = document.createElement("div");
|
|
1023
1092
|
$contentWrap.className = this.wrapClassName("content-wrap");
|
|
1024
1093
|
|
package/src/TeleBox/typings.ts
CHANGED
|
@@ -17,7 +17,10 @@ export type TeleBoxSize = { width: number; height: number };
|
|
|
17
17
|
|
|
18
18
|
export type TeleBoxState = `${TELE_BOX_STATE}`;
|
|
19
19
|
|
|
20
|
-
export type NotMinimizedBoxState = `${Exclude<
|
|
20
|
+
export type NotMinimizedBoxState = `${Exclude<
|
|
21
|
+
TELE_BOX_STATE,
|
|
22
|
+
TELE_BOX_STATE.Minimized
|
|
23
|
+
>}`;
|
|
21
24
|
|
|
22
25
|
export interface TeleBoxRect {
|
|
23
26
|
readonly x: number;
|
|
@@ -91,6 +94,7 @@ export interface TeleBoxConfig {
|
|
|
91
94
|
readonly forceTop?: boolean;
|
|
92
95
|
/** Force normal. */
|
|
93
96
|
readonly forceNormal?: boolean;
|
|
97
|
+
readonly forceMaximized?: boolean;
|
|
94
98
|
/** Is drag content. */
|
|
95
99
|
readonly isDragContent?: boolean;
|
|
96
100
|
}
|
|
@@ -115,8 +119,12 @@ export type TeleBoxEventConfig = CheckTeleBoxConfig<{
|
|
|
115
119
|
readonly: boolean;
|
|
116
120
|
destroyed: void;
|
|
117
121
|
box_status: { id: string; boxStatus: TeleBoxState };
|
|
118
|
-
last_not_minimized_box_status: {
|
|
122
|
+
last_not_minimized_box_status: {
|
|
123
|
+
id: string;
|
|
124
|
+
lastNotMinimizedBoxStatus?: NotMinimizedBoxState;
|
|
125
|
+
};
|
|
119
126
|
force_normal: boolean;
|
|
127
|
+
force_maximized: boolean;
|
|
120
128
|
force_top: boolean;
|
|
121
129
|
}>;
|
|
122
130
|
|