@netless/telebox-insider 0.3.0 → 0.3.1
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 +25 -9
- package/dist/style.css +3 -0
- package/dist/telebox-insider.cjs.js +320 -92
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +320 -92
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +1 -1
- package/src/TeleBox/index.ts +96 -22
- package/src/TeleBox/typings.ts +10 -2
- package/src/TeleBoxManager/index.ts +435 -152
- 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);
|
|
@@ -255,7 +267,11 @@ export class TeleBox {
|
|
|
255
267
|
}
|
|
256
268
|
});
|
|
257
269
|
|
|
258
|
-
const maximized$ = createVal(
|
|
270
|
+
const maximized$ = createVal(
|
|
271
|
+
maximized || forceMaximized,
|
|
272
|
+
(next, previous) =>
|
|
273
|
+
next === previous || (forceMaximized$.value && !next)
|
|
274
|
+
);
|
|
259
275
|
maximized$.reaction((maximized, _, skipUpdate) => {
|
|
260
276
|
if (!skipUpdate) {
|
|
261
277
|
this.events.emit(TELE_BOX_EVENT.Maximized, maximized);
|
|
@@ -269,7 +285,8 @@ export class TeleBox {
|
|
|
269
285
|
? TELE_BOX_STATE.Minimized
|
|
270
286
|
: maximized
|
|
271
287
|
? TELE_BOX_STATE.Maximized
|
|
272
|
-
: !boxStatus
|
|
288
|
+
: !boxStatus
|
|
289
|
+
? TELE_BOX_STATE.Normal
|
|
273
290
|
: boxStatus
|
|
274
291
|
);
|
|
275
292
|
state$.reaction((state, _, skipUpdate) => {
|
|
@@ -327,7 +344,10 @@ export class TeleBox {
|
|
|
327
344
|
const visualSize$ = combine(
|
|
328
345
|
[size$, minimized$, containerRect$, collectorRect$, boxStatus$],
|
|
329
346
|
([size, minimized, containerRect, collectorRect, boxStatus]) => {
|
|
330
|
-
if (
|
|
347
|
+
if (
|
|
348
|
+
(minimized || boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
349
|
+
collectorRect
|
|
350
|
+
) {
|
|
331
351
|
return {
|
|
332
352
|
width:
|
|
333
353
|
collectorRect.width /
|
|
@@ -380,8 +400,14 @@ export class TeleBox {
|
|
|
380
400
|
boxStatus,
|
|
381
401
|
lastNotMinimizedBoxStatus,
|
|
382
402
|
]) => {
|
|
383
|
-
if (
|
|
384
|
-
|
|
403
|
+
if (
|
|
404
|
+
(minimized || boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
405
|
+
collectorRect
|
|
406
|
+
) {
|
|
407
|
+
if (
|
|
408
|
+
maximized ||
|
|
409
|
+
lastNotMinimizedBoxStatus === TELE_BOX_STATE.Maximized
|
|
410
|
+
) {
|
|
385
411
|
return {
|
|
386
412
|
x:
|
|
387
413
|
(collectorRect.x + collectorRect.width / 2) /
|
|
@@ -426,6 +452,7 @@ export class TeleBox {
|
|
|
426
452
|
boxStatus: boxStatus$.value,
|
|
427
453
|
forceTop: forceTop$.value,
|
|
428
454
|
forceNormal: forceNormal$.value,
|
|
455
|
+
forceMaximized: forceMaximized$.value,
|
|
429
456
|
onDragStart: (event) => this._handleTrackStart?.(event),
|
|
430
457
|
onEvent: (event): void => {
|
|
431
458
|
if (this._delegateEvents.listeners.length > 0) {
|
|
@@ -433,7 +460,10 @@ export class TeleBox {
|
|
|
433
460
|
} else {
|
|
434
461
|
switch (event.type) {
|
|
435
462
|
case TELE_BOX_DELEGATE_EVENT.Maximize: {
|
|
436
|
-
if (
|
|
463
|
+
if (
|
|
464
|
+
!boxStatus$.value &&
|
|
465
|
+
!(forceMaximized$.value && maximized$.value)
|
|
466
|
+
) {
|
|
437
467
|
maximized$.setValue(!maximized$.value);
|
|
438
468
|
}
|
|
439
469
|
break;
|
|
@@ -462,6 +492,10 @@ export class TeleBox {
|
|
|
462
492
|
readonly$.reaction((readonly) => {
|
|
463
493
|
this.titleBar.setReadonly(readonly);
|
|
464
494
|
});
|
|
495
|
+
forceMaximized$.reaction((forceMaximized) => {
|
|
496
|
+
if (forceMaximized) maximized$.setValue(true);
|
|
497
|
+
this.titleBar.setForceMaximized?.(forceMaximized);
|
|
498
|
+
});
|
|
465
499
|
boxStatus$.reaction((boxStatus) => {
|
|
466
500
|
this.titleBar.setBoxStatus(boxStatus);
|
|
467
501
|
});
|
|
@@ -491,6 +525,7 @@ export class TeleBox {
|
|
|
491
525
|
$userStyles: $userStyles$,
|
|
492
526
|
forceTop: forceTop$,
|
|
493
527
|
forceNormal: forceNormal$,
|
|
528
|
+
forceMaximized: forceMaximized$,
|
|
494
529
|
isDragContent: isDragContent$,
|
|
495
530
|
};
|
|
496
531
|
|
|
@@ -541,7 +576,10 @@ export class TeleBox {
|
|
|
541
576
|
public _coord$: Val<TeleBoxCoord, boolean>;
|
|
542
577
|
public _intrinsicCoord$: Val<TeleBoxCoord, boolean>;
|
|
543
578
|
public _boxStatus$: Val<TeleBoxState | undefined, boolean>;
|
|
544
|
-
public _lastNotMinimizedBoxStatus$: Val<
|
|
579
|
+
public _lastNotMinimizedBoxStatus$: Val<
|
|
580
|
+
NotMinimizedBoxState | undefined,
|
|
581
|
+
boolean
|
|
582
|
+
>;
|
|
545
583
|
|
|
546
584
|
public get boxStatus(): TeleBoxState | undefined {
|
|
547
585
|
return this._boxStatus$.value;
|
|
@@ -588,23 +626,41 @@ export class TeleBox {
|
|
|
588
626
|
|
|
589
627
|
public setBoxStatus(boxStatus: TeleBoxState, skipUpdate = false): this {
|
|
590
628
|
if (boxStatus === TELE_BOX_STATE.Minimized) {
|
|
591
|
-
if (
|
|
592
|
-
this.
|
|
629
|
+
if (
|
|
630
|
+
this._boxStatus$.value &&
|
|
631
|
+
this._boxStatus$.value !== TELE_BOX_STATE.Minimized
|
|
632
|
+
) {
|
|
633
|
+
this.setLastNotMinimizedBoxStatus(
|
|
634
|
+
this._boxStatus$.value,
|
|
635
|
+
skipUpdate
|
|
636
|
+
);
|
|
593
637
|
}
|
|
594
638
|
} else {
|
|
595
639
|
this.setLastNotMinimizedBoxStatus(undefined, skipUpdate);
|
|
596
640
|
}
|
|
597
641
|
this._boxStatus$.setValue(boxStatus, skipUpdate);
|
|
598
642
|
if (!skipUpdate) {
|
|
599
|
-
this.events.emit(TELE_BOX_EVENT.BoxStatus, {
|
|
643
|
+
this.events.emit(TELE_BOX_EVENT.BoxStatus, {
|
|
644
|
+
id: this.id,
|
|
645
|
+
boxStatus,
|
|
646
|
+
});
|
|
600
647
|
}
|
|
601
648
|
return this;
|
|
602
649
|
}
|
|
603
650
|
|
|
604
|
-
public setLastNotMinimizedBoxStatus(
|
|
605
|
-
|
|
651
|
+
public setLastNotMinimizedBoxStatus(
|
|
652
|
+
lastNotMinimizedBoxStatus?: NotMinimizedBoxState,
|
|
653
|
+
skipUpdate = false
|
|
654
|
+
): this {
|
|
655
|
+
this._lastNotMinimizedBoxStatus$.setValue(
|
|
656
|
+
lastNotMinimizedBoxStatus,
|
|
657
|
+
skipUpdate
|
|
658
|
+
);
|
|
606
659
|
if (!skipUpdate) {
|
|
607
|
-
this.events.emit(TELE_BOX_EVENT.LastNotMinimizedBoxStatus, {
|
|
660
|
+
this.events.emit(TELE_BOX_EVENT.LastNotMinimizedBoxStatus, {
|
|
661
|
+
id: this.id,
|
|
662
|
+
lastNotMinimizedBoxStatus,
|
|
663
|
+
});
|
|
608
664
|
}
|
|
609
665
|
return this;
|
|
610
666
|
}
|
|
@@ -979,24 +1035,43 @@ export class TeleBox {
|
|
|
979
1035
|
this._collectorRect$,
|
|
980
1036
|
this._boxStatus$,
|
|
981
1037
|
],
|
|
982
|
-
([
|
|
1038
|
+
([
|
|
1039
|
+
coord,
|
|
1040
|
+
size,
|
|
1041
|
+
minimized,
|
|
1042
|
+
containerRect,
|
|
1043
|
+
collectorRect,
|
|
1044
|
+
boxStatus,
|
|
1045
|
+
]) => {
|
|
983
1046
|
const absoluteWidth = size.width * containerRect.width;
|
|
984
1047
|
const absoluteHeight = size.height * containerRect.height;
|
|
985
1048
|
return {
|
|
986
1049
|
width:
|
|
987
1050
|
absoluteWidth +
|
|
988
|
-
((minimized ||
|
|
1051
|
+
((minimized ||
|
|
1052
|
+
boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
1053
|
+
collectorRect
|
|
1054
|
+
? 1
|
|
1055
|
+
: 0),
|
|
989
1056
|
height:
|
|
990
1057
|
absoluteHeight +
|
|
991
|
-
((minimized ||
|
|
1058
|
+
((minimized ||
|
|
1059
|
+
boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
1060
|
+
collectorRect
|
|
1061
|
+
? 1
|
|
1062
|
+
: 0),
|
|
992
1063
|
x: coord.x * containerRect.width,
|
|
993
1064
|
y: coord.y * containerRect.height,
|
|
994
1065
|
scaleX:
|
|
995
|
-
(minimized ||
|
|
1066
|
+
(minimized ||
|
|
1067
|
+
boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
1068
|
+
collectorRect
|
|
996
1069
|
? collectorRect.width / absoluteWidth
|
|
997
1070
|
: 1,
|
|
998
1071
|
scaleY:
|
|
999
|
-
(minimized ||
|
|
1072
|
+
(minimized ||
|
|
1073
|
+
boxStatus === TELE_BOX_STATE.Minimized) &&
|
|
1074
|
+
collectorRect
|
|
1000
1075
|
? collectorRect.height / absoluteHeight
|
|
1001
1076
|
: 1,
|
|
1002
1077
|
};
|
|
@@ -1018,7 +1093,6 @@ export class TeleBox {
|
|
|
1018
1093
|
$titleBar.appendChild(this.titleBar.render());
|
|
1019
1094
|
this.$titleBar = $titleBar;
|
|
1020
1095
|
|
|
1021
|
-
|
|
1022
1096
|
const $contentWrap = document.createElement("div");
|
|
1023
1097
|
$contentWrap.className = this.wrapClassName("content-wrap");
|
|
1024
1098
|
|
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
|
|