@netless/telebox-insider 1.0.0-alpha.1 → 1.0.0-alpha.12
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 +14 -11
- package/dist/TeleBox/typings.d.ts +9 -3
- package/dist/TeleBoxCollector/index.d.ts +8 -6
- package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +1 -0
- package/dist/TeleBoxManager/index.d.ts +9 -1
- package/dist/TeleBoxManager/typings.d.ts +5 -5
- package/dist/TeleStage/index.d.ts +2 -6
- package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +3 -5
- package/dist/TeleTitleBar/typings.d.ts +1 -1
- package/dist/style.css +1 -1
- package/dist/telebox-insider.cjs.js +1 -15
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +1 -15
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +3 -2
- package/src/TeleBox/index.ts +148 -77
- package/src/TeleBox/style.scss +4 -0
- package/src/TeleBox/typings.ts +9 -3
- package/src/TeleBoxCollector/index.ts +30 -16
- package/src/TeleBoxCollector/style.scss +1 -1
- package/src/TeleBoxManager/MaxTitleBar/index.ts +16 -8
- package/src/TeleBoxManager/MaxTitleBar/style.scss +5 -2
- package/src/TeleBoxManager/index.ts +59 -36
- package/src/TeleBoxManager/typings.ts +11 -4
- package/src/TeleStage/index.ts +5 -20
- package/src/TeleStage/style.scss +1 -1
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +4 -12
- package/src/TeleTitleBar/typings.ts +1 -1
- package/src/scss/variables.scss +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/telebox-insider",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Window widget for Whiteboard",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"minimist": "^1.2.5",
|
|
51
51
|
"prettier": "^2.0.5",
|
|
52
52
|
"rimraf": "^3.0.0",
|
|
53
|
+
"rollup-plugin-exclude-dependencies-from-bundle": "^1.1.22",
|
|
53
54
|
"sass": "^1.36.0",
|
|
54
55
|
"sass-loader": "^10.1.1",
|
|
55
56
|
"typescript": "^4.1.2",
|
|
@@ -62,6 +63,6 @@
|
|
|
62
63
|
"shallowequal": "^1.1.0",
|
|
63
64
|
"side-effect-manager": "^1.1.0",
|
|
64
65
|
"stylefire": "^7.0.3",
|
|
65
|
-
"value-enhancer": "^1.
|
|
66
|
+
"value-enhancer": "^1.3.0"
|
|
66
67
|
}
|
|
67
68
|
}
|
package/src/TeleBox/index.ts
CHANGED
|
@@ -9,8 +9,13 @@ import type {
|
|
|
9
9
|
ReadonlyValEnhancedResult,
|
|
10
10
|
ValEnhancedResult,
|
|
11
11
|
} from "value-enhancer";
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
combine,
|
|
14
|
+
Val,
|
|
15
|
+
withReadonlyValueEnhancer,
|
|
16
|
+
withValueEnhancer,
|
|
17
|
+
ValManager,
|
|
18
|
+
} from "value-enhancer";
|
|
14
19
|
import type { TeleTitleBar } from "../TeleTitleBar";
|
|
15
20
|
import { DefaultTitleBar } from "../TeleTitleBar";
|
|
16
21
|
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
|
|
@@ -53,9 +58,10 @@ type ValConfig = {
|
|
|
53
58
|
resizable: Val<RequiredTeleBoxConfig["resizable"], boolean>;
|
|
54
59
|
draggable: Val<RequiredTeleBoxConfig["draggable"], boolean>;
|
|
55
60
|
ratio: Val<RequiredTeleBoxConfig["ratio"], boolean>;
|
|
61
|
+
stageRatio: Val<number | null>;
|
|
56
62
|
};
|
|
57
63
|
|
|
58
|
-
type
|
|
64
|
+
type PropsValConfig = {
|
|
59
65
|
darkMode: RequiredTeleBoxConfig["darkMode$"];
|
|
60
66
|
fence: RequiredTeleBoxConfig["fence$"];
|
|
61
67
|
minimized: RequiredTeleBoxConfig["minimized$"];
|
|
@@ -64,11 +70,14 @@ type ReadonlyValConfig = {
|
|
|
64
70
|
rootRect: RequiredTeleBoxConfig["rootRect$"];
|
|
65
71
|
managerStageRect: RequiredTeleBoxConfig["managerStageRect$"];
|
|
66
72
|
collectorRect: RequiredTeleBoxConfig["collectorRect$"];
|
|
73
|
+
};
|
|
67
74
|
|
|
75
|
+
type MyReadonlyValConfig = {
|
|
68
76
|
zIndex: Val<RequiredTeleBoxConfig["zIndex"], boolean>;
|
|
69
77
|
focus: Val<RequiredTeleBoxConfig["focus"], boolean>;
|
|
70
78
|
|
|
71
79
|
$userContent: Val<TeleBoxConfig["content"], boolean>;
|
|
80
|
+
$userStage: Val<TeleBoxConfig["content"], boolean>;
|
|
72
81
|
$userFooter: Val<TeleBoxConfig["footer"], boolean>;
|
|
73
82
|
$userStyles: Val<TeleBoxConfig["styles"], boolean>;
|
|
74
83
|
|
|
@@ -85,7 +94,9 @@ type ReadonlyValConfig = {
|
|
|
85
94
|
contentStageRect: ReadonlyVal<TeleBoxRect | null>;
|
|
86
95
|
};
|
|
87
96
|
|
|
88
|
-
type CombinedValEnhancedResult = ReadonlyValEnhancedResult<
|
|
97
|
+
type CombinedValEnhancedResult = ReadonlyValEnhancedResult<
|
|
98
|
+
PropsValConfig & MyReadonlyValConfig
|
|
99
|
+
> &
|
|
89
100
|
ValEnhancedResult<ValConfig>;
|
|
90
101
|
|
|
91
102
|
export interface TeleBox extends CombinedValEnhancedResult {}
|
|
@@ -107,8 +118,10 @@ export class TeleBox {
|
|
|
107
118
|
ratio = -1,
|
|
108
119
|
focus = false,
|
|
109
120
|
zIndex = 100,
|
|
121
|
+
stageRatio = null,
|
|
110
122
|
titleBar,
|
|
111
123
|
content,
|
|
124
|
+
stage,
|
|
112
125
|
footer,
|
|
113
126
|
styles,
|
|
114
127
|
highlightStage = null,
|
|
@@ -117,9 +130,10 @@ export class TeleBox {
|
|
|
117
130
|
minimized$,
|
|
118
131
|
maximized$,
|
|
119
132
|
readonly$,
|
|
133
|
+
root$,
|
|
120
134
|
rootRect$,
|
|
121
135
|
managerStageRect$,
|
|
122
|
-
|
|
136
|
+
managerStageRatio$,
|
|
123
137
|
collectorRect$,
|
|
124
138
|
managerHighlightStage$,
|
|
125
139
|
}: TeleBoxConfig) {
|
|
@@ -128,6 +142,9 @@ export class TeleBox {
|
|
|
128
142
|
this.id = id;
|
|
129
143
|
this.namespace = namespace;
|
|
130
144
|
|
|
145
|
+
const valManager = new ValManager();
|
|
146
|
+
this._sideEffect.addDisposer(() => valManager.destroy());
|
|
147
|
+
|
|
131
148
|
const title$ = new Val(title);
|
|
132
149
|
const visible$ = new Val(visible);
|
|
133
150
|
const resizable$ = new Val(resizable);
|
|
@@ -136,6 +153,7 @@ export class TeleBox {
|
|
|
136
153
|
const zIndex$ = new Val(zIndex);
|
|
137
154
|
const focus$ = new Val(focus);
|
|
138
155
|
const $userContent$ = new Val(content);
|
|
156
|
+
const $userStage$ = new Val(stage);
|
|
139
157
|
const $userFooter$ = new Val(footer);
|
|
140
158
|
const $userStyles$ = new Val(styles);
|
|
141
159
|
|
|
@@ -213,26 +231,33 @@ export class TeleBox {
|
|
|
213
231
|
);
|
|
214
232
|
|
|
215
233
|
const highlightStage$ = combine(
|
|
216
|
-
[
|
|
217
|
-
([
|
|
218
|
-
boxHighlightStage
|
|
219
|
-
? managerHighlightStage && maximized
|
|
220
|
-
: boxHighlightStage
|
|
234
|
+
[boxHighlightStage$, managerHighlightStage$],
|
|
235
|
+
([boxHighlightStage, managerHighlightStage]) =>
|
|
236
|
+
boxHighlightStage ?? managerHighlightStage
|
|
221
237
|
);
|
|
222
238
|
|
|
239
|
+
const contentRoot$ = new Val<HTMLElement | null>(null);
|
|
240
|
+
|
|
223
241
|
const contentRect$ = new Val<TeleBoxRect>(rootRect$.value, {
|
|
224
242
|
compare: shallowequal,
|
|
225
243
|
});
|
|
226
244
|
|
|
245
|
+
const stageRatio$ = new Val(stageRatio);
|
|
246
|
+
|
|
227
247
|
const teleStage = new TeleStage({
|
|
228
248
|
namespace,
|
|
249
|
+
root$: contentRoot$,
|
|
229
250
|
rootRect$: contentRect$,
|
|
230
|
-
ratio$:
|
|
251
|
+
ratio$: combine(
|
|
252
|
+
[stageRatio$, managerStageRatio$],
|
|
253
|
+
([stageRatio, managerStageRatio]) =>
|
|
254
|
+
stageRatio ?? managerStageRatio
|
|
255
|
+
),
|
|
231
256
|
highlightStage$,
|
|
232
257
|
});
|
|
233
258
|
this._sideEffect.addDisposer(() => teleStage.destroy());
|
|
234
259
|
|
|
235
|
-
const
|
|
260
|
+
const propsValConfig: PropsValConfig = {
|
|
236
261
|
darkMode: darkMode$,
|
|
237
262
|
fence: fence$,
|
|
238
263
|
minimized: minimized$,
|
|
@@ -241,11 +266,16 @@ export class TeleBox {
|
|
|
241
266
|
rootRect: rootRect$,
|
|
242
267
|
managerStageRect: managerStageRect$,
|
|
243
268
|
collectorRect: collectorRect$,
|
|
269
|
+
};
|
|
244
270
|
|
|
271
|
+
withReadonlyValueEnhancer(this, propsValConfig);
|
|
272
|
+
|
|
273
|
+
const myReadonlyValConfig: MyReadonlyValConfig = {
|
|
245
274
|
zIndex: zIndex$,
|
|
246
275
|
focus: focus$,
|
|
247
276
|
|
|
248
277
|
$userContent: $userContent$,
|
|
278
|
+
$userStage: $userStage$,
|
|
249
279
|
$userFooter: $userFooter$,
|
|
250
280
|
$userStyles: $userStyles$,
|
|
251
281
|
|
|
@@ -262,7 +292,7 @@ export class TeleBox {
|
|
|
262
292
|
contentStageRect: teleStage.stageRect$,
|
|
263
293
|
};
|
|
264
294
|
|
|
265
|
-
withReadonlyValueEnhancer(this,
|
|
295
|
+
withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
|
|
266
296
|
|
|
267
297
|
const valConfig: ValConfig = {
|
|
268
298
|
title: title$,
|
|
@@ -270,16 +300,17 @@ export class TeleBox {
|
|
|
270
300
|
resizable: resizable$,
|
|
271
301
|
draggable: draggable$,
|
|
272
302
|
ratio: ratio$,
|
|
303
|
+
stageRatio: stageRatio$,
|
|
273
304
|
};
|
|
274
305
|
|
|
275
|
-
withValueEnhancer(this, valConfig);
|
|
306
|
+
withValueEnhancer(this, valConfig, valManager);
|
|
276
307
|
|
|
277
308
|
this.titleBar =
|
|
278
309
|
titleBar ||
|
|
279
310
|
new DefaultTitleBar({
|
|
280
311
|
readonly$: readonly$,
|
|
281
312
|
state$: state$,
|
|
282
|
-
title
|
|
313
|
+
title$: title$,
|
|
283
314
|
namespace: this.namespace,
|
|
284
315
|
onDragStart: (event) => this._handleTrackStart?.(event),
|
|
285
316
|
onEvent: (event) => this._delegateEvents.emit(event.type),
|
|
@@ -312,7 +343,7 @@ export class TeleBox {
|
|
|
312
343
|
);
|
|
313
344
|
|
|
314
345
|
this.$box = this.render();
|
|
315
|
-
|
|
346
|
+
contentRoot$.setValue(this.$content.parentElement);
|
|
316
347
|
|
|
317
348
|
const watchValEvent = <E extends TeleBoxEvent>(
|
|
318
349
|
val: ReadonlyVal<TeleBoxEventConfig[E], boolean>,
|
|
@@ -336,23 +367,27 @@ export class TeleBox {
|
|
|
336
367
|
watchValEvent(intrinsicSize$, TELE_BOX_EVENT.IntrinsicResize);
|
|
337
368
|
watchValEvent(intrinsicCoord$, TELE_BOX_EVENT.IntrinsicMove);
|
|
338
369
|
|
|
339
|
-
this._sideEffect.addDisposer(
|
|
370
|
+
this._sideEffect.addDisposer([
|
|
340
371
|
visible$.reaction((visible, skipUpdate) => {
|
|
341
372
|
if (!skipUpdate && !visible) {
|
|
342
373
|
this.events.emit(TELE_BOX_EVENT.Close);
|
|
343
374
|
}
|
|
344
|
-
})
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
this._sideEffect.addDisposer(
|
|
375
|
+
}),
|
|
348
376
|
focus$.reaction((focus, skipUpdate) => {
|
|
349
377
|
if (!skipUpdate) {
|
|
350
378
|
this.events.emit(
|
|
351
379
|
focus ? TELE_BOX_EVENT.Focus : TELE_BOX_EVENT.Blur
|
|
352
380
|
);
|
|
353
381
|
}
|
|
354
|
-
})
|
|
355
|
-
|
|
382
|
+
}),
|
|
383
|
+
root$.subscribe((root) => {
|
|
384
|
+
if (root) {
|
|
385
|
+
root.appendChild(this.$box);
|
|
386
|
+
} else if (this.$box.parentNode) {
|
|
387
|
+
this.$box.remove();
|
|
388
|
+
}
|
|
389
|
+
}),
|
|
390
|
+
]);
|
|
356
391
|
}
|
|
357
392
|
|
|
358
393
|
public readonly id: string;
|
|
@@ -475,10 +510,10 @@ export class TeleBox {
|
|
|
475
510
|
const rootRect = this.rootRect;
|
|
476
511
|
safeX = clamp(
|
|
477
512
|
x,
|
|
478
|
-
|
|
479
|
-
|
|
513
|
+
0 - pxIntrinsicSize.width + 20,
|
|
514
|
+
0 + rootRect.width - 20
|
|
480
515
|
);
|
|
481
|
-
safeY = clamp(y,
|
|
516
|
+
safeY = clamp(y, 0, 0 + rootRect.height - 20);
|
|
482
517
|
}
|
|
483
518
|
|
|
484
519
|
this._intrinsicCoord$.setValue(
|
|
@@ -536,33 +571,28 @@ export class TeleBox {
|
|
|
536
571
|
}
|
|
537
572
|
|
|
538
573
|
/**
|
|
539
|
-
* Mount
|
|
574
|
+
* Mount dom to box content.
|
|
540
575
|
*/
|
|
541
|
-
public
|
|
542
|
-
|
|
576
|
+
public mountContent(content: HTMLElement): void {
|
|
577
|
+
this._$userContent$.setValue(content);
|
|
543
578
|
}
|
|
544
579
|
|
|
545
580
|
/**
|
|
546
|
-
* Unmount
|
|
581
|
+
* Unmount content from the box.
|
|
547
582
|
*/
|
|
548
|
-
public
|
|
549
|
-
|
|
550
|
-
this.$box.remove();
|
|
551
|
-
}
|
|
583
|
+
public unmountContent(): void {
|
|
584
|
+
this._$userContent$.setValue(undefined);
|
|
552
585
|
}
|
|
553
586
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
*/
|
|
557
|
-
public mountContent(content: HTMLElement): void {
|
|
558
|
-
this._$userContent$.setValue(content);
|
|
587
|
+
public mountStage(stage: HTMLElement): void {
|
|
588
|
+
this._$userStage$.setValue(stage);
|
|
559
589
|
}
|
|
560
590
|
|
|
561
591
|
/**
|
|
562
592
|
* Unmount content from the box.
|
|
563
593
|
*/
|
|
564
|
-
public
|
|
565
|
-
this._$
|
|
594
|
+
public unmountStage(): void {
|
|
595
|
+
this._$userStage$.setValue(undefined);
|
|
566
596
|
}
|
|
567
597
|
|
|
568
598
|
/**
|
|
@@ -609,6 +639,9 @@ export class TeleBox {
|
|
|
609
639
|
/** DOM of the box content */
|
|
610
640
|
public $content!: HTMLElement;
|
|
611
641
|
|
|
642
|
+
/** DOM of the box stage area */
|
|
643
|
+
public $stage?: HTMLElement;
|
|
644
|
+
|
|
612
645
|
/** DOM of the box title bar */
|
|
613
646
|
public $titleBar!: HTMLElement;
|
|
614
647
|
|
|
@@ -711,34 +744,39 @@ export class TeleBox {
|
|
|
711
744
|
pxIntrinsicCoord,
|
|
712
745
|
collectorRect,
|
|
713
746
|
]) => {
|
|
747
|
+
const styles = maximized
|
|
748
|
+
? {
|
|
749
|
+
x: 0,
|
|
750
|
+
y: 0,
|
|
751
|
+
width: "100%",
|
|
752
|
+
height: "100%",
|
|
753
|
+
scaleX: 1,
|
|
754
|
+
scaleY: 1,
|
|
755
|
+
}
|
|
756
|
+
: {
|
|
757
|
+
x: pxIntrinsicCoord.x,
|
|
758
|
+
y: pxIntrinsicCoord.y,
|
|
759
|
+
width: pxIntrinsicSize.width + "px",
|
|
760
|
+
height: pxIntrinsicSize.height + "px",
|
|
761
|
+
scaleX: 1,
|
|
762
|
+
scaleY: 1,
|
|
763
|
+
};
|
|
714
764
|
if (minimized && collectorRect) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
width: "100%",
|
|
729
|
-
height: "100%",
|
|
730
|
-
scaleX: 1,
|
|
731
|
-
scaleY: 1,
|
|
732
|
-
};
|
|
765
|
+
const { width: boxWidth, height: boxHeight } = maximized
|
|
766
|
+
? this.rootRect
|
|
767
|
+
: pxIntrinsicSize;
|
|
768
|
+
styles.x =
|
|
769
|
+
collectorRect.x -
|
|
770
|
+
boxWidth / 2 +
|
|
771
|
+
collectorRect.width / 2;
|
|
772
|
+
styles.y =
|
|
773
|
+
collectorRect.y -
|
|
774
|
+
boxHeight / 2 +
|
|
775
|
+
collectorRect.height / 2;
|
|
776
|
+
styles.scaleX = collectorRect.width / boxWidth;
|
|
777
|
+
styles.scaleY = collectorRect.height / boxHeight;
|
|
733
778
|
}
|
|
734
|
-
return
|
|
735
|
-
x: pxIntrinsicCoord.x,
|
|
736
|
-
y: pxIntrinsicCoord.y,
|
|
737
|
-
width: pxIntrinsicSize.width + "px",
|
|
738
|
-
height: pxIntrinsicSize.height + "px",
|
|
739
|
-
scaleX: 1,
|
|
740
|
-
scaleY: 1,
|
|
741
|
-
};
|
|
779
|
+
return styles;
|
|
742
780
|
},
|
|
743
781
|
{ compare: shallowequal }
|
|
744
782
|
);
|
|
@@ -776,16 +814,14 @@ export class TeleBox {
|
|
|
776
814
|
this.$content = $content;
|
|
777
815
|
|
|
778
816
|
this._sideEffect.add(() => {
|
|
779
|
-
const observer = new ResizeObserver((
|
|
780
|
-
const rect =
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
});
|
|
788
|
-
}
|
|
817
|
+
const observer = new ResizeObserver(() => {
|
|
818
|
+
const rect = $content.getBoundingClientRect();
|
|
819
|
+
this._contentRect$.setValue({
|
|
820
|
+
x: rect.x,
|
|
821
|
+
y: rect.y,
|
|
822
|
+
width: rect.width,
|
|
823
|
+
height: rect.height,
|
|
824
|
+
});
|
|
789
825
|
});
|
|
790
826
|
observer.observe($content);
|
|
791
827
|
return () => observer.disconnect();
|
|
@@ -817,6 +853,41 @@ export class TeleBox {
|
|
|
817
853
|
});
|
|
818
854
|
});
|
|
819
855
|
|
|
856
|
+
this._sideEffect.add(() => {
|
|
857
|
+
let last$userStage: HTMLElement | undefined;
|
|
858
|
+
return this._$userStage$.subscribe(($userStage) => {
|
|
859
|
+
if (last$userStage) {
|
|
860
|
+
last$userStage.remove();
|
|
861
|
+
}
|
|
862
|
+
last$userStage = $userStage;
|
|
863
|
+
if ($userStage) {
|
|
864
|
+
if (!this.$stage) {
|
|
865
|
+
const $stage = document.createElement("div");
|
|
866
|
+
this.$stage = $stage;
|
|
867
|
+
$stage.className = this.wrapClassName("content-stage");
|
|
868
|
+
this._sideEffect.addDisposer(
|
|
869
|
+
this._contentStageRect$.subscribe((rect) => {
|
|
870
|
+
if (rect) {
|
|
871
|
+
$stage.style.top = rect.y + "px";
|
|
872
|
+
$stage.style.left = rect.x + "px";
|
|
873
|
+
$stage.style.width = rect.width + "px";
|
|
874
|
+
$stage.style.height = rect.height + "px";
|
|
875
|
+
}
|
|
876
|
+
}),
|
|
877
|
+
"content-stage-rect"
|
|
878
|
+
);
|
|
879
|
+
$content.appendChild($stage);
|
|
880
|
+
}
|
|
881
|
+
if (!this.$stage.parentElement) {
|
|
882
|
+
$content.appendChild(this.$stage);
|
|
883
|
+
}
|
|
884
|
+
this.$stage.appendChild($userStage);
|
|
885
|
+
} else if (this.$stage?.parentElement) {
|
|
886
|
+
this.$stage.remove();
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
|
|
820
891
|
$contentWrap.appendChild($content);
|
|
821
892
|
|
|
822
893
|
const $footer = document.createElement("div");
|
package/src/TeleBox/style.scss
CHANGED
package/src/TeleBox/typings.ts
CHANGED
|
@@ -56,13 +56,17 @@ export interface TeleBoxConfig {
|
|
|
56
56
|
readonly focus?: boolean;
|
|
57
57
|
/** Base z-index for box. */
|
|
58
58
|
readonly zIndex?: number;
|
|
59
|
+
/** Box stage ratio. Follow manager stage ratio if null. Default null. */
|
|
60
|
+
readonly stageRatio?: number | null;
|
|
59
61
|
/** Classname Prefix. For CSS styling. Default "telebox". */
|
|
60
62
|
readonly namespace?: string;
|
|
61
63
|
/** TeleTitleBar Instance. */
|
|
62
64
|
readonly titleBar?: TeleTitleBar;
|
|
63
|
-
/** Box content. */
|
|
65
|
+
/** Box content element. */
|
|
64
66
|
readonly content?: HTMLElement;
|
|
65
|
-
/**
|
|
67
|
+
/** Stage element. */
|
|
68
|
+
readonly stage?: HTMLElement;
|
|
69
|
+
/** Box footer element. */
|
|
66
70
|
readonly footer?: HTMLElement;
|
|
67
71
|
/** Box content styles. */
|
|
68
72
|
readonly styles?: HTMLStyleElement;
|
|
@@ -78,12 +82,14 @@ export interface TeleBoxConfig {
|
|
|
78
82
|
readonly minimized$: ReadonlyVal<boolean, boolean>;
|
|
79
83
|
/** Is box readonly */
|
|
80
84
|
readonly readonly$: ReadonlyVal<boolean, boolean>;
|
|
85
|
+
/** Root element to mount boxes */
|
|
86
|
+
readonly root$: ReadonlyVal<HTMLElement | null>;
|
|
81
87
|
/** Position and dimension of root element */
|
|
82
88
|
readonly rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
83
89
|
/** Position and dimension of stage area */
|
|
84
90
|
readonly managerStageRect$: ReadonlyVal<TeleBoxRect>;
|
|
85
91
|
/** Stage area height/with ratio. No ratio if <= 0. */
|
|
86
|
-
readonly
|
|
92
|
+
readonly managerStageRatio$: ReadonlyVal<number, boolean>;
|
|
87
93
|
/** Position and dimension of collector */
|
|
88
94
|
readonly collectorRect$: ReadonlyVal<TeleBoxRect | undefined>;
|
|
89
95
|
/** highlight stage settings from manager */
|
|
@@ -6,17 +6,21 @@ import type {
|
|
|
6
6
|
ReadonlyValEnhancedResult,
|
|
7
7
|
ValEnhancedResult,
|
|
8
8
|
} from "value-enhancer";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
import { derive } from "value-enhancer";
|
|
10
|
+
import {
|
|
11
|
+
withValueEnhancer,
|
|
12
|
+
combine,
|
|
13
|
+
Val,
|
|
14
|
+
withReadonlyValueEnhancer,
|
|
15
|
+
ValManager,
|
|
16
|
+
} from "value-enhancer";
|
|
13
17
|
import { SideEffectManager } from "side-effect-manager";
|
|
14
18
|
import type { TeleBoxRect } from "../TeleBox/typings";
|
|
15
19
|
|
|
16
20
|
export interface TeleBoxCollectorConfig {
|
|
17
21
|
namespace?: string;
|
|
18
22
|
styles?: TeleStyles;
|
|
19
|
-
root
|
|
23
|
+
root$: ReadonlyVal<HTMLElement | null>;
|
|
20
24
|
minimized$: Val<boolean>;
|
|
21
25
|
readonly$: ReadonlyVal<boolean>;
|
|
22
26
|
darkMode$: ReadonlyVal<boolean>;
|
|
@@ -25,17 +29,20 @@ export interface TeleBoxCollectorConfig {
|
|
|
25
29
|
|
|
26
30
|
type ValConfig = {
|
|
27
31
|
styles: Val<TeleStyles>;
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
$collector: Val<HTMLElement>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type PropsValConfig = {
|
|
36
|
+
root: TeleBoxCollectorConfig["root$"];
|
|
30
37
|
};
|
|
31
38
|
|
|
32
|
-
type
|
|
39
|
+
type MyReadonlyValConfig = {
|
|
33
40
|
rect: ReadonlyVal<TeleBoxRect | undefined>;
|
|
34
41
|
visible: ReadonlyVal<boolean>;
|
|
35
42
|
};
|
|
36
43
|
|
|
37
44
|
type CombinedValEnhancedResult = ValEnhancedResult<ValConfig> &
|
|
38
|
-
ReadonlyValEnhancedResult<
|
|
45
|
+
ReadonlyValEnhancedResult<PropsValConfig & MyReadonlyValConfig>;
|
|
39
46
|
|
|
40
47
|
export interface TeleBoxCollector extends CombinedValEnhancedResult {}
|
|
41
48
|
|
|
@@ -47,30 +54,37 @@ export class TeleBoxCollector {
|
|
|
47
54
|
rootRect$,
|
|
48
55
|
namespace = "telebox",
|
|
49
56
|
styles = {},
|
|
50
|
-
root
|
|
57
|
+
root$,
|
|
51
58
|
}: TeleBoxCollectorConfig) {
|
|
52
59
|
this.namespace = namespace;
|
|
53
60
|
|
|
61
|
+
const valManager = new ValManager();
|
|
62
|
+
this._sideEffect.addDisposer(() => valManager.destroy());
|
|
63
|
+
|
|
54
64
|
const rect$ = new Val<TeleBoxRect | undefined>(void 0);
|
|
55
|
-
const visible$ = minimized
|
|
65
|
+
const visible$ = derive(minimized$);
|
|
56
66
|
const styles$ = new Val(styles);
|
|
57
|
-
const root$ = new Val(root);
|
|
58
67
|
const el$ = new Val<HTMLElement>(document.createElement("button"));
|
|
59
68
|
|
|
60
69
|
const valConfig: ValConfig = {
|
|
61
70
|
styles: styles$,
|
|
71
|
+
$collector: el$,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
withValueEnhancer(this, valConfig, valManager);
|
|
75
|
+
|
|
76
|
+
const propsValConfig: PropsValConfig = {
|
|
62
77
|
root: root$,
|
|
63
|
-
el: el$,
|
|
64
78
|
};
|
|
65
79
|
|
|
66
|
-
|
|
80
|
+
withReadonlyValueEnhancer(this, propsValConfig);
|
|
67
81
|
|
|
68
|
-
const
|
|
82
|
+
const myReadonlyValConfig: MyReadonlyValConfig = {
|
|
69
83
|
rect: rect$,
|
|
70
84
|
visible: visible$,
|
|
71
85
|
};
|
|
72
86
|
|
|
73
|
-
withReadonlyValueEnhancer(this,
|
|
87
|
+
withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
|
|
74
88
|
|
|
75
89
|
el$.value.className = this.wrapClassName("collector");
|
|
76
90
|
el$.value.style.backgroundImage = `url('${collectorSVG}')`;
|
|
@@ -14,6 +14,7 @@ export interface MaxTitleBarConfig extends DefaultTitleBarConfig {
|
|
|
14
14
|
darkMode$: ReadonlyVal<boolean>;
|
|
15
15
|
boxes$: ReadonlyVal<TeleBox[]>;
|
|
16
16
|
rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
17
|
+
root$: ReadonlyVal<HTMLElement | null>;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export class MaxTitleBar extends DefaultTitleBar {
|
|
@@ -23,6 +24,16 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
23
24
|
this.boxes$ = config.boxes$;
|
|
24
25
|
this.rootRect$ = config.rootRect$;
|
|
25
26
|
this.darkMode$ = config.darkMode$;
|
|
27
|
+
|
|
28
|
+
this.sideEffect.addDisposer(
|
|
29
|
+
config.root$.subscribe((root) => {
|
|
30
|
+
if (root) {
|
|
31
|
+
root.appendChild(this.render());
|
|
32
|
+
} else if (this.$titleBar?.parentNode) {
|
|
33
|
+
this.$titleBar.remove();
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
);
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
public focusBox(box?: TeleBox): void {
|
|
@@ -54,17 +65,16 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
public render(): HTMLElement {
|
|
68
|
+
if (this.$titleBar) {
|
|
69
|
+
return this.$titleBar;
|
|
70
|
+
}
|
|
71
|
+
|
|
57
72
|
const $titleBar = super.render();
|
|
58
73
|
|
|
59
74
|
$titleBar.classList.add(this.wrapClassName("max-titlebar"));
|
|
60
75
|
|
|
61
76
|
this.sideEffect.addDisposer(
|
|
62
77
|
[
|
|
63
|
-
this.rootRect$.subscribe((rootRect) => {
|
|
64
|
-
const { x, y, width } = rootRect;
|
|
65
|
-
$titleBar.style.transform = `translate(${x}px, ${y}px)`;
|
|
66
|
-
$titleBar.style.width = width + "px";
|
|
67
|
-
}),
|
|
68
78
|
this.state$.subscribe((state) => {
|
|
69
79
|
$titleBar.classList.toggle(
|
|
70
80
|
this.wrapClassName("max-titlebar-maximized"),
|
|
@@ -94,9 +104,7 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
94
104
|
this.wrapClassName("max-titlebar-single-title"),
|
|
95
105
|
titles.length === 1
|
|
96
106
|
);
|
|
97
|
-
if (titles.length
|
|
98
|
-
this.setTitle(titles[0].title);
|
|
99
|
-
} else {
|
|
107
|
+
if (titles.length !== 1) {
|
|
100
108
|
$titleBar.replaceChild(
|
|
101
109
|
this.renderTitles(),
|
|
102
110
|
$titleBar.firstElementChild as HTMLElement
|
|
@@ -16,7 +16,10 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
|
|
|
16
16
|
position: absolute;
|
|
17
17
|
top: 0;
|
|
18
18
|
left: 0;
|
|
19
|
-
|
|
19
|
+
width: 100%;
|
|
20
|
+
z-index: $max-titlebar-z-index;
|
|
21
|
+
border-top-left-radius: 6px;
|
|
22
|
+
border-top-right-radius: 6px;
|
|
20
23
|
|
|
21
24
|
.#{$namespace}-title {
|
|
22
25
|
display: none;
|
|
@@ -95,7 +98,7 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
|
|
|
95
98
|
height: 100%;
|
|
96
99
|
overflow: hidden;
|
|
97
100
|
max-width: 182px;
|
|
98
|
-
min-width:
|
|
101
|
+
min-width: 150px;
|
|
99
102
|
padding: 0 26px 0 16px;
|
|
100
103
|
outline: none;
|
|
101
104
|
font-size: 13px;
|