@netless/telebox-insider 1.0.0-alpha.19 → 1.0.0-alpha.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/TeleBox/index.d.ts +37 -34
- package/dist/TeleBox/typings.d.ts +12 -8
- package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +1 -1
- package/dist/TeleBoxManager/index.d.ts +3 -1
- package/dist/TeleBoxManager/typings.d.ts +9 -5
- package/dist/style.css +1 -1
- package/dist/telebox-insider.cjs.js +2 -1
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +1647 -1
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +67 -67
- package/src/TeleBox/index.ts +219 -220
- package/src/TeleBox/style.scss +9 -45
- package/src/TeleBox/style.shadow.scss +87 -0
- package/src/TeleBox/typings.ts +12 -8
- package/src/TeleBoxCollector/style.scss +9 -3
- package/src/TeleBoxManager/MaxTitleBar/index.ts +2 -20
- package/src/TeleBoxManager/MaxTitleBar/style.scss +33 -14
- package/src/TeleBoxManager/index.ts +58 -50
- package/src/TeleBoxManager/style.scss +23 -6
- package/src/TeleBoxManager/typings.ts +12 -4
- package/src/TeleTitleBar/DefaultTitleBar/style.scss +68 -11
- package/src/scss/mixins.scss +5 -0
- package/src/scss/variables.scss +40 -6
package/src/TeleBox/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "./style.scss";
|
|
2
|
+
import shadowStyles from "./style.shadow.scss?inline";
|
|
2
3
|
|
|
3
4
|
import Emittery from "emittery";
|
|
4
5
|
import styler from "stylefire";
|
|
@@ -19,14 +20,7 @@ import {
|
|
|
19
20
|
import type { TeleTitleBar } from "../TeleTitleBar";
|
|
20
21
|
import { DefaultTitleBar } from "../TeleTitleBar";
|
|
21
22
|
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
|
|
22
|
-
import {
|
|
23
|
-
clamp,
|
|
24
|
-
flattenEvent,
|
|
25
|
-
getBoxDefaultName,
|
|
26
|
-
isFalsy,
|
|
27
|
-
isTruthy,
|
|
28
|
-
preventEvent,
|
|
29
|
-
} from "../utils";
|
|
23
|
+
import { clamp, flattenEvent, getBoxDefaultName, preventEvent } from "../utils";
|
|
30
24
|
import {
|
|
31
25
|
TELE_BOX_EVENT,
|
|
32
26
|
TELE_BOX_STATE,
|
|
@@ -58,9 +52,9 @@ type ValConfig = {
|
|
|
58
52
|
resizable: Val<RequiredTeleBoxConfig["resizable"], boolean>;
|
|
59
53
|
draggable: Val<RequiredTeleBoxConfig["draggable"], boolean>;
|
|
60
54
|
boxRatio: Val<RequiredTeleBoxConfig["boxRatio"], boolean>;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
stageRatio: Val<RequiredTeleBoxConfig["stageRatio"], boolean>;
|
|
56
|
+
stageStyle: Val<RequiredTeleBoxConfig["stageStyle"], boolean>;
|
|
57
|
+
bodyStyle: Val<RequiredTeleBoxConfig["bodyStyle"], boolean>;
|
|
64
58
|
};
|
|
65
59
|
|
|
66
60
|
type PropsValConfig = {
|
|
@@ -71,8 +65,8 @@ type PropsValConfig = {
|
|
|
71
65
|
readonly: RequiredTeleBoxConfig["readonly$"];
|
|
72
66
|
rootRect: RequiredTeleBoxConfig["rootRect$"];
|
|
73
67
|
managerStageRect: RequiredTeleBoxConfig["managerStageRect$"];
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
defaultBoxStageStyle: RequiredTeleBoxConfig["defaultBoxStageStyle$"];
|
|
69
|
+
defaultBoxBodyStyle: RequiredTeleBoxConfig["defaultBoxBodyStyle$"];
|
|
76
70
|
collectorRect: RequiredTeleBoxConfig["collectorRect$"];
|
|
77
71
|
};
|
|
78
72
|
|
|
@@ -80,11 +74,6 @@ type MyReadonlyValConfig = {
|
|
|
80
74
|
zIndex: Val<RequiredTeleBoxConfig["zIndex"], boolean>;
|
|
81
75
|
focus: Val<RequiredTeleBoxConfig["focus"], boolean>;
|
|
82
76
|
|
|
83
|
-
$userContent: Val<TeleBoxConfig["content"], boolean>;
|
|
84
|
-
$userStage: Val<TeleBoxConfig["stage"], boolean>;
|
|
85
|
-
$userFooter: Val<TeleBoxConfig["footer"], boolean>;
|
|
86
|
-
$userStyles: Val<TeleBoxConfig["styles"], boolean>;
|
|
87
|
-
|
|
88
77
|
minSize: Val<TeleBoxSize, boolean>;
|
|
89
78
|
intrinsicSize: Val<TeleBoxSize, boolean>;
|
|
90
79
|
intrinsicCoord: Val<TeleBoxCoord, boolean>;
|
|
@@ -92,8 +81,8 @@ type MyReadonlyValConfig = {
|
|
|
92
81
|
pxIntrinsicSize: ReadonlyVal<TeleBoxSize, boolean>;
|
|
93
82
|
pxIntrinsicCoord: ReadonlyVal<TeleBoxCoord, boolean>;
|
|
94
83
|
state: ReadonlyVal<TeleBoxState, boolean>;
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
bodyRect: Val<TeleBoxRect>;
|
|
85
|
+
stageRect: ReadonlyVal<TeleBoxRect>;
|
|
97
86
|
};
|
|
98
87
|
|
|
99
88
|
type CombinedValEnhancedResult = ReadonlyValEnhancedResult<
|
|
@@ -120,14 +109,16 @@ export class TeleBox {
|
|
|
120
109
|
boxRatio = -1,
|
|
121
110
|
focus = false,
|
|
122
111
|
zIndex = 100,
|
|
123
|
-
|
|
112
|
+
stageRatio = null,
|
|
113
|
+
enableShadowDOM = true,
|
|
124
114
|
titleBar,
|
|
125
115
|
content,
|
|
126
116
|
stage,
|
|
127
117
|
footer,
|
|
128
118
|
styles,
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
userStyles,
|
|
120
|
+
bodyStyle = null,
|
|
121
|
+
stageStyle = null,
|
|
131
122
|
darkMode$,
|
|
132
123
|
fence$,
|
|
133
124
|
minimized$,
|
|
@@ -137,14 +128,15 @@ export class TeleBox {
|
|
|
137
128
|
rootRect$,
|
|
138
129
|
managerStageRect$,
|
|
139
130
|
managerStageRatio$,
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
defaultBoxBodyStyle$,
|
|
132
|
+
defaultBoxStageStyle$,
|
|
142
133
|
collectorRect$,
|
|
143
134
|
}: TeleBoxConfig) {
|
|
144
135
|
this._sideEffect = new SideEffectManager();
|
|
145
136
|
|
|
146
137
|
this.id = id;
|
|
147
138
|
this.namespace = namespace;
|
|
139
|
+
this.enableShadowDOM = enableShadowDOM;
|
|
148
140
|
|
|
149
141
|
const valManager = new ValManager();
|
|
150
142
|
this._sideEffect.addDisposer(() => valManager.destroy());
|
|
@@ -156,10 +148,6 @@ export class TeleBox {
|
|
|
156
148
|
const boxRatio$ = new Val(boxRatio);
|
|
157
149
|
const zIndex$ = new Val(zIndex);
|
|
158
150
|
const focus$ = new Val(focus);
|
|
159
|
-
const $userContent$ = new Val(content);
|
|
160
|
-
const $userStage$ = new Val(stage);
|
|
161
|
-
const $userFooter$ = new Val(footer);
|
|
162
|
-
const $userStyles$ = new Val(styles);
|
|
163
151
|
|
|
164
152
|
const state$ = combine(
|
|
165
153
|
[minimized$, maximized$],
|
|
@@ -226,21 +214,20 @@ export class TeleBox {
|
|
|
226
214
|
{ compare: shallowequal }
|
|
227
215
|
);
|
|
228
216
|
|
|
229
|
-
const
|
|
230
|
-
const
|
|
217
|
+
const bodyStyle$ = new Val<string | null>(bodyStyle);
|
|
218
|
+
const stageStyle$ = new Val<string | null>(stageStyle);
|
|
231
219
|
|
|
232
220
|
const contentRoot$ = new Val<HTMLElement | null>(null);
|
|
233
|
-
const
|
|
221
|
+
const bodyRect$ = new Val<TeleBoxRect>(managerStageRect$.value, {
|
|
234
222
|
compare: shallowequal,
|
|
235
223
|
});
|
|
236
|
-
const
|
|
224
|
+
const stageRatio$ = new Val(stageRatio);
|
|
237
225
|
const finalStageRatio$ = combine(
|
|
238
|
-
[
|
|
239
|
-
([
|
|
240
|
-
contentStageRatio ?? managerStageRatio
|
|
226
|
+
[stageRatio$, managerStageRatio$],
|
|
227
|
+
([stageRatio, managerStageRatio]) => stageRatio ?? managerStageRatio
|
|
241
228
|
);
|
|
242
|
-
const
|
|
243
|
-
[
|
|
229
|
+
const stageRect$ = combine(
|
|
230
|
+
[bodyRect$, finalStageRatio$],
|
|
244
231
|
calcStageRect,
|
|
245
232
|
{ compare: shallowequal }
|
|
246
233
|
);
|
|
@@ -253,8 +240,8 @@ export class TeleBox {
|
|
|
253
240
|
readonly: readonly$,
|
|
254
241
|
rootRect: rootRect$,
|
|
255
242
|
managerStageRect: managerStageRect$,
|
|
256
|
-
|
|
257
|
-
|
|
243
|
+
defaultBoxBodyStyle: defaultBoxBodyStyle$,
|
|
244
|
+
defaultBoxStageStyle: defaultBoxStageStyle$,
|
|
258
245
|
collectorRect: collectorRect$,
|
|
259
246
|
};
|
|
260
247
|
|
|
@@ -264,11 +251,6 @@ export class TeleBox {
|
|
|
264
251
|
zIndex: zIndex$,
|
|
265
252
|
focus: focus$,
|
|
266
253
|
|
|
267
|
-
$userContent: $userContent$,
|
|
268
|
-
$userStage: $userStage$,
|
|
269
|
-
$userFooter: $userFooter$,
|
|
270
|
-
$userStyles: $userStyles$,
|
|
271
|
-
|
|
272
254
|
state: state$,
|
|
273
255
|
minSize: minSize$,
|
|
274
256
|
pxMinSize: pxMinSize$,
|
|
@@ -276,8 +258,8 @@ export class TeleBox {
|
|
|
276
258
|
intrinsicCoord: intrinsicCoord$,
|
|
277
259
|
pxIntrinsicSize: pxIntrinsicSize$,
|
|
278
260
|
pxIntrinsicCoord: pxIntrinsicCoord$,
|
|
279
|
-
|
|
280
|
-
|
|
261
|
+
bodyRect: bodyRect$,
|
|
262
|
+
stageRect: stageRect$,
|
|
281
263
|
};
|
|
282
264
|
|
|
283
265
|
withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
|
|
@@ -288,9 +270,9 @@ export class TeleBox {
|
|
|
288
270
|
resizable: resizable$,
|
|
289
271
|
draggable: draggable$,
|
|
290
272
|
boxRatio: boxRatio$,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
273
|
+
stageRatio: stageRatio$,
|
|
274
|
+
bodyStyle: bodyStyle$,
|
|
275
|
+
stageStyle: stageStyle$,
|
|
294
276
|
};
|
|
295
277
|
|
|
296
278
|
withValueEnhancer(this, valConfig, valManager);
|
|
@@ -332,6 +314,11 @@ export class TeleBox {
|
|
|
332
314
|
|
|
333
315
|
this.$box = this._render();
|
|
334
316
|
contentRoot$.setValue(this.$content.parentElement);
|
|
317
|
+
content && this.mountContent(content);
|
|
318
|
+
stage && this.mountStage(stage);
|
|
319
|
+
footer && this.mountFooter(footer);
|
|
320
|
+
styles && this.mountStyles(styles);
|
|
321
|
+
userStyles && this.mountUserStyles(userStyles);
|
|
335
322
|
root.appendChild(this.$box);
|
|
336
323
|
|
|
337
324
|
const watchValEvent = <E extends TeleBoxEvent>(
|
|
@@ -377,6 +364,9 @@ export class TeleBox {
|
|
|
377
364
|
/** ClassName Prefix. For CSS styling. Default "telebox" */
|
|
378
365
|
public readonly namespace: string;
|
|
379
366
|
|
|
367
|
+
/** Enable shadow DOM for box content. Default true. */
|
|
368
|
+
public readonly enableShadowDOM: boolean;
|
|
369
|
+
|
|
380
370
|
public readonly events = new Emittery<
|
|
381
371
|
TeleBoxEventConfig,
|
|
382
372
|
TeleBoxEventConfig
|
|
@@ -542,77 +532,106 @@ export class TeleBox {
|
|
|
542
532
|
);
|
|
543
533
|
}
|
|
544
534
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
535
|
+
private $authorContent?: HTMLElement;
|
|
536
|
+
|
|
537
|
+
/** Mount dom to box content. */
|
|
548
538
|
public mountContent(content: HTMLElement): void {
|
|
549
|
-
this
|
|
539
|
+
this.$authorContent?.remove();
|
|
540
|
+
this.$authorContent = content;
|
|
541
|
+
this.$content.appendChild(content);
|
|
550
542
|
}
|
|
551
543
|
|
|
552
|
-
/**
|
|
553
|
-
* Unmount content from the box.
|
|
554
|
-
*/
|
|
544
|
+
/** Unmount content from the box. */
|
|
555
545
|
public unmountContent(): void {
|
|
556
|
-
this
|
|
546
|
+
if (this.$authorContent) {
|
|
547
|
+
this.$authorContent.remove();
|
|
548
|
+
this.$authorContent = undefined;
|
|
549
|
+
}
|
|
557
550
|
}
|
|
558
551
|
|
|
552
|
+
private $authorStage?: HTMLElement;
|
|
553
|
+
|
|
554
|
+
/** Mount dom to box stage. */
|
|
559
555
|
public mountStage(stage: HTMLElement): void {
|
|
560
|
-
this
|
|
556
|
+
this.$authorStage?.remove();
|
|
557
|
+
this.$authorStage = stage;
|
|
558
|
+
if (!this.$stage) {
|
|
559
|
+
this.$stage = this._renderStage();
|
|
560
|
+
}
|
|
561
|
+
this.$stage.appendChild(stage);
|
|
562
|
+
if (!this.$stage.parentElement) {
|
|
563
|
+
this.$body.appendChild(this.$stage);
|
|
564
|
+
}
|
|
561
565
|
}
|
|
562
566
|
|
|
563
|
-
/**
|
|
564
|
-
* Unmount content from the box.
|
|
565
|
-
*/
|
|
567
|
+
/** Unmount content from the box. */
|
|
566
568
|
public unmountStage(): void {
|
|
567
|
-
this
|
|
569
|
+
if (this.$authorStage) {
|
|
570
|
+
this.$authorStage.remove();
|
|
571
|
+
this.$authorStage = undefined;
|
|
572
|
+
}
|
|
573
|
+
this.$stage?.remove();
|
|
568
574
|
}
|
|
569
575
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
576
|
+
private $authorFooter?: HTMLElement;
|
|
577
|
+
|
|
578
|
+
/** Mount dom to box Footer. */
|
|
573
579
|
public mountFooter(footer: HTMLElement): void {
|
|
574
|
-
this
|
|
580
|
+
this.$authorFooter?.remove();
|
|
581
|
+
this.$authorFooter = footer;
|
|
582
|
+
this.$footer.appendChild(footer);
|
|
575
583
|
}
|
|
576
584
|
|
|
577
|
-
/**
|
|
578
|
-
* Unmount Footer from the box.
|
|
579
|
-
*/
|
|
585
|
+
/** Unmount Footer from the box. */
|
|
580
586
|
public unmountFooter(): void {
|
|
581
|
-
this
|
|
587
|
+
if (this.$authorFooter) {
|
|
588
|
+
this.$authorFooter.remove();
|
|
589
|
+
this.$authorFooter = undefined;
|
|
590
|
+
}
|
|
582
591
|
}
|
|
583
592
|
|
|
584
|
-
|
|
585
|
-
|
|
593
|
+
/** Mount styles for box content */
|
|
594
|
+
public mountStyles(styles: string): void {
|
|
595
|
+
this.$styles.textContent = styles;
|
|
586
596
|
}
|
|
587
597
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
$styles = document.createElement("style");
|
|
592
|
-
$styles.textContent = styles;
|
|
593
|
-
} else {
|
|
594
|
-
$styles = styles;
|
|
595
|
-
}
|
|
596
|
-
this._$userStyles$.setValue($styles);
|
|
598
|
+
/** Umount styles for box content */
|
|
599
|
+
public unmountStyles(): void {
|
|
600
|
+
this.$styles.textContent = "";
|
|
597
601
|
}
|
|
598
602
|
|
|
599
|
-
|
|
600
|
-
|
|
603
|
+
/** Mount user styles for box content */
|
|
604
|
+
public mountUserStyles(styles: string): void {
|
|
605
|
+
this.$userStyles.textContent = styles;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** Umount user styles for box content */
|
|
609
|
+
public unmountUserStyles(): void {
|
|
610
|
+
this.$userStyles.textContent = "";
|
|
601
611
|
}
|
|
602
612
|
|
|
603
613
|
/** DOM of the box */
|
|
604
614
|
public $box: HTMLElement;
|
|
605
615
|
|
|
606
|
-
/** DOM of the box
|
|
616
|
+
/** DOM of the box body */
|
|
617
|
+
public $body!: HTMLElement;
|
|
618
|
+
|
|
619
|
+
/** DOM of the box content container inside box body */
|
|
607
620
|
public $content!: HTMLElement;
|
|
608
621
|
|
|
609
|
-
/** DOM of the box stage area */
|
|
622
|
+
/** DOM of the box stage area inside box body */
|
|
610
623
|
public $stage?: HTMLElement;
|
|
611
624
|
|
|
612
|
-
/** DOM of
|
|
625
|
+
/** DOM of custom box content styles */
|
|
626
|
+
public $styles!: HTMLStyleElement;
|
|
627
|
+
|
|
628
|
+
/** DOM of end user custom box content styles */
|
|
629
|
+
public $userStyles!: HTMLStyleElement;
|
|
630
|
+
|
|
631
|
+
/** DOM of the box title bar container */
|
|
613
632
|
public $titleBar!: HTMLElement;
|
|
614
633
|
|
|
615
|
-
/** DOM of the box footer */
|
|
634
|
+
/** DOM of the box footer container */
|
|
616
635
|
public $footer!: HTMLElement;
|
|
617
636
|
|
|
618
637
|
private _render(): HTMLElement {
|
|
@@ -620,35 +639,48 @@ export class TeleBox {
|
|
|
620
639
|
return this.$box;
|
|
621
640
|
}
|
|
622
641
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
642
|
+
const bindBoxStates = (el: Element, disposerID?: string): string => {
|
|
643
|
+
return this._sideEffect.addDisposer(
|
|
644
|
+
[
|
|
645
|
+
this._readonly$.subscribe((readonly) =>
|
|
646
|
+
el.classList.toggle(
|
|
647
|
+
this.wrapClassName("readonly"),
|
|
648
|
+
readonly
|
|
649
|
+
)
|
|
650
|
+
),
|
|
651
|
+
this._draggable$.subscribe((draggable) =>
|
|
652
|
+
el.classList.toggle(
|
|
653
|
+
this.wrapClassName("no-drag"),
|
|
654
|
+
!draggable
|
|
655
|
+
)
|
|
656
|
+
),
|
|
657
|
+
this._resizable$.subscribe((resizable) =>
|
|
658
|
+
el.classList.toggle(
|
|
659
|
+
this.wrapClassName("no-resize"),
|
|
660
|
+
!resizable
|
|
661
|
+
)
|
|
662
|
+
),
|
|
663
|
+
this._focus$.subscribe((focus) =>
|
|
664
|
+
el.classList.toggle(this.wrapClassName("blur"), !focus)
|
|
665
|
+
),
|
|
666
|
+
this._darkMode$.subscribe((darkMode) => {
|
|
667
|
+
el.classList.toggle(
|
|
668
|
+
this.wrapClassName("color-scheme-dark"),
|
|
669
|
+
darkMode
|
|
670
|
+
);
|
|
671
|
+
el.classList.toggle(
|
|
672
|
+
this.wrapClassName("color-scheme-light"),
|
|
673
|
+
!darkMode
|
|
674
|
+
);
|
|
675
|
+
}),
|
|
676
|
+
],
|
|
677
|
+
disposerID
|
|
678
|
+
);
|
|
639
679
|
};
|
|
640
680
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
bindClassName(this.$box, this._focus$, "blur", isFalsy);
|
|
645
|
-
bindClassName(this.$box, this._darkMode$, "color-scheme-dark");
|
|
646
|
-
bindClassName(
|
|
647
|
-
this.$box,
|
|
648
|
-
this._darkMode$,
|
|
649
|
-
"color-scheme-light",
|
|
650
|
-
isFalsy
|
|
651
|
-
);
|
|
681
|
+
this.$box = document.createElement("div");
|
|
682
|
+
this.$box.classList.add(this.wrapClassName("box"));
|
|
683
|
+
bindBoxStates(this.$box, "bind-box-state");
|
|
652
684
|
|
|
653
685
|
this._sideEffect.add(() => {
|
|
654
686
|
const minimizedClassName = this.wrapClassName("minimized");
|
|
@@ -785,8 +817,17 @@ export class TeleBox {
|
|
|
785
817
|
$titleBar.appendChild(this.titleBar.render());
|
|
786
818
|
this.$titleBar = $titleBar;
|
|
787
819
|
|
|
788
|
-
const $
|
|
789
|
-
$
|
|
820
|
+
const $body = document.createElement("div");
|
|
821
|
+
$body.className = this.wrapClassName("body-wrap");
|
|
822
|
+
this.$body = $body;
|
|
823
|
+
|
|
824
|
+
const $styles = document.createElement("style");
|
|
825
|
+
this.$styles = $styles;
|
|
826
|
+
$body.appendChild($styles);
|
|
827
|
+
|
|
828
|
+
const $userStyles = document.createElement("style");
|
|
829
|
+
this.$userStyles = $userStyles;
|
|
830
|
+
$body.appendChild($userStyles);
|
|
790
831
|
|
|
791
832
|
const $content = document.createElement("div");
|
|
792
833
|
$content.className =
|
|
@@ -794,15 +835,48 @@ export class TeleBox {
|
|
|
794
835
|
this.$content = $content;
|
|
795
836
|
this._sideEffect.addDisposer(
|
|
796
837
|
combine(
|
|
797
|
-
[this.
|
|
798
|
-
([
|
|
799
|
-
|
|
800
|
-
).subscribe((style) => ($content.style.cssText = style))
|
|
838
|
+
[this._bodyStyle$, this._defaultBoxBodyStyle$],
|
|
839
|
+
([bodyStyle, defaultBoxBodyStyle]) =>
|
|
840
|
+
bodyStyle ?? defaultBoxBodyStyle
|
|
841
|
+
).subscribe((style) => ($content.style.cssText = style || ""))
|
|
801
842
|
);
|
|
802
843
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
844
|
+
$body.appendChild($content);
|
|
845
|
+
|
|
846
|
+
const $footer = document.createElement("div");
|
|
847
|
+
$footer.className = this.wrapClassName("footer-wrap");
|
|
848
|
+
this.$footer = $footer;
|
|
849
|
+
|
|
850
|
+
$boxMain.appendChild($titleBar);
|
|
851
|
+
|
|
852
|
+
if (this.enableShadowDOM) {
|
|
853
|
+
const $quarantineWrap = document.createElement("div");
|
|
854
|
+
$quarantineWrap.className = this.wrapClassName("quarantine-wrap");
|
|
855
|
+
$boxMain.appendChild($quarantineWrap);
|
|
856
|
+
|
|
857
|
+
const $quarantine = document.createElement("div");
|
|
858
|
+
$quarantine.className = this.wrapClassName("quarantine");
|
|
859
|
+
bindBoxStates($quarantine, "bind-quarantine-state");
|
|
860
|
+
|
|
861
|
+
const $shadowStyle = document.createElement("style");
|
|
862
|
+
$shadowStyle.textContent = shadowStyles;
|
|
863
|
+
|
|
864
|
+
$quarantine.appendChild($shadowStyle);
|
|
865
|
+
$quarantine.appendChild($body);
|
|
866
|
+
$quarantine.appendChild($footer);
|
|
867
|
+
|
|
868
|
+
const shadow = $quarantineWrap.attachShadow({ mode: "open" });
|
|
869
|
+
shadow.appendChild($quarantine);
|
|
870
|
+
} else {
|
|
871
|
+
$boxMain.appendChild($body);
|
|
872
|
+
$boxMain.appendChild($footer);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
this._renderResizeHandlers();
|
|
876
|
+
|
|
877
|
+
const updateBodyRect = (): void => {
|
|
878
|
+
const rect = $body.getBoundingClientRect();
|
|
879
|
+
this._bodyRect$.setValue({
|
|
806
880
|
x: 0,
|
|
807
881
|
y: 0,
|
|
808
882
|
width: rect.width,
|
|
@@ -812,10 +886,10 @@ export class TeleBox {
|
|
|
812
886
|
this._sideEffect.add(() => {
|
|
813
887
|
const observer = new ResizeObserver(() => {
|
|
814
888
|
if (!this.minimized) {
|
|
815
|
-
|
|
889
|
+
updateBodyRect();
|
|
816
890
|
}
|
|
817
891
|
});
|
|
818
|
-
observer.observe($
|
|
892
|
+
observer.observe($body);
|
|
819
893
|
return () => observer.disconnect();
|
|
820
894
|
});
|
|
821
895
|
this._sideEffect.addDisposer(
|
|
@@ -823,7 +897,7 @@ export class TeleBox {
|
|
|
823
897
|
// correct content size when restoring from minimized
|
|
824
898
|
if (!minimized) {
|
|
825
899
|
this._sideEffect.setTimeout(
|
|
826
|
-
|
|
900
|
+
updateBodyRect,
|
|
827
901
|
400,
|
|
828
902
|
"minimized-content-rect-fix"
|
|
829
903
|
);
|
|
@@ -831,107 +905,32 @@ export class TeleBox {
|
|
|
831
905
|
})
|
|
832
906
|
);
|
|
833
907
|
|
|
834
|
-
this._sideEffect.add(() => {
|
|
835
|
-
let last$userStyles: HTMLStyleElement | undefined;
|
|
836
|
-
return this._$userStyles$.subscribe(($userStyles) => {
|
|
837
|
-
if (last$userStyles) {
|
|
838
|
-
last$userStyles.remove();
|
|
839
|
-
}
|
|
840
|
-
last$userStyles = $userStyles;
|
|
841
|
-
if ($userStyles) {
|
|
842
|
-
$contentWrap.appendChild($userStyles);
|
|
843
|
-
}
|
|
844
|
-
});
|
|
845
|
-
});
|
|
846
|
-
|
|
847
|
-
this._sideEffect.add(() => {
|
|
848
|
-
let last$userContent: HTMLElement | undefined;
|
|
849
|
-
return this._$userContent$.subscribe(($userContent) => {
|
|
850
|
-
if (last$userContent) {
|
|
851
|
-
last$userContent.remove();
|
|
852
|
-
}
|
|
853
|
-
last$userContent = $userContent;
|
|
854
|
-
if ($userContent) {
|
|
855
|
-
$content.appendChild($userContent);
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
this._sideEffect.add(() => {
|
|
861
|
-
let last$userStage: HTMLElement | undefined;
|
|
862
|
-
return this._$userStage$.subscribe(($userStage) => {
|
|
863
|
-
if (last$userStage) {
|
|
864
|
-
last$userStage.remove();
|
|
865
|
-
}
|
|
866
|
-
last$userStage = $userStage;
|
|
867
|
-
if ($userStage) {
|
|
868
|
-
if (!this.$stage) {
|
|
869
|
-
this.$stage = this._renderStage();
|
|
870
|
-
$content.appendChild(this.$stage);
|
|
871
|
-
}
|
|
872
|
-
if (!this.$stage.parentElement) {
|
|
873
|
-
$content.appendChild(this.$stage);
|
|
874
|
-
}
|
|
875
|
-
this.$stage.appendChild($userStage);
|
|
876
|
-
} else if (this.$stage?.parentElement) {
|
|
877
|
-
this.$stage.remove();
|
|
878
|
-
}
|
|
879
|
-
});
|
|
880
|
-
});
|
|
881
|
-
|
|
882
|
-
$contentWrap.appendChild($content);
|
|
883
|
-
|
|
884
|
-
const $footer = document.createElement("div");
|
|
885
|
-
$footer.className = this.wrapClassName("footer-wrap");
|
|
886
|
-
this.$footer = $footer;
|
|
887
|
-
|
|
888
|
-
this._sideEffect.add(() => {
|
|
889
|
-
let last$userFooter: HTMLElement | undefined;
|
|
890
|
-
return this._$userFooter$.subscribe(($userFooter) => {
|
|
891
|
-
if (last$userFooter) {
|
|
892
|
-
last$userFooter.remove();
|
|
893
|
-
}
|
|
894
|
-
last$userFooter = $userFooter;
|
|
895
|
-
if ($userFooter) {
|
|
896
|
-
$footer.appendChild($userFooter);
|
|
897
|
-
}
|
|
898
|
-
});
|
|
899
|
-
});
|
|
900
|
-
|
|
901
|
-
$boxMain.appendChild($titleBar);
|
|
902
|
-
$boxMain.appendChild($contentWrap);
|
|
903
|
-
$boxMain.appendChild($footer);
|
|
904
|
-
|
|
905
|
-
this._renderResizeHandlers();
|
|
906
|
-
|
|
907
908
|
return this.$box;
|
|
908
909
|
}
|
|
909
910
|
|
|
910
911
|
private _renderStage(): HTMLDivElement {
|
|
911
912
|
const $stage = document.createElement("div");
|
|
912
913
|
|
|
913
|
-
$stage.className = this.wrapClassName("
|
|
914
|
-
const
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
$stage.style.
|
|
918
|
-
$stage.style.
|
|
919
|
-
$stage.style.width = contentStageRect.width + "px";
|
|
920
|
-
$stage.style.height = contentStageRect.height + "px";
|
|
914
|
+
$stage.className = this.wrapClassName("box-stage");
|
|
915
|
+
const updateStageRect = (stageRect: TeleBoxRect): void => {
|
|
916
|
+
$stage.style.top = stageRect.y + "px";
|
|
917
|
+
$stage.style.left = stageRect.x + "px";
|
|
918
|
+
$stage.style.width = stageRect.width + "px";
|
|
919
|
+
$stage.style.height = stageRect.height + "px";
|
|
921
920
|
};
|
|
922
921
|
this._sideEffect.addDisposer(
|
|
923
922
|
[
|
|
924
923
|
combine(
|
|
925
|
-
[this.
|
|
926
|
-
([
|
|
927
|
-
|
|
924
|
+
[this._stageStyle$, this._defaultBoxStageStyle$],
|
|
925
|
+
([stageStyle, defaultBoxStageStyle]) =>
|
|
926
|
+
stageStyle ?? defaultBoxStageStyle
|
|
928
927
|
).subscribe((styles) => {
|
|
929
|
-
$stage.style.cssText = styles;
|
|
930
|
-
|
|
928
|
+
$stage.style.cssText = styles || "";
|
|
929
|
+
updateStageRect(this._stageRect$.value);
|
|
931
930
|
}),
|
|
932
|
-
this.
|
|
931
|
+
this._stageRect$.subscribe(updateStageRect),
|
|
933
932
|
],
|
|
934
|
-
"
|
|
933
|
+
"box-stage-styles"
|
|
935
934
|
);
|
|
936
935
|
return $stage;
|
|
937
936
|
}
|
|
@@ -1196,14 +1195,14 @@ export type ReadonlyTeleBox = Pick<
|
|
|
1196
1195
|
| "unmountStage"
|
|
1197
1196
|
| "mountStyles"
|
|
1198
1197
|
| "unmountStyles"
|
|
1199
|
-
| "
|
|
1200
|
-
| "setContentStageStyle"
|
|
1201
|
-
| "setContentStyle"
|
|
1198
|
+
| "setTitle"
|
|
1202
1199
|
| "setDraggable"
|
|
1203
1200
|
| "setResizable"
|
|
1204
|
-
| "setTitle"
|
|
1205
|
-
| "setBoxRatio"
|
|
1206
1201
|
| "setVisible"
|
|
1202
|
+
| "setBoxRatio"
|
|
1203
|
+
| "setStageRatio"
|
|
1204
|
+
| "setStageStyle"
|
|
1205
|
+
| "setBodyStyle"
|
|
1207
1206
|
| "handleTrackStart"
|
|
1208
1207
|
| "onValChanged"
|
|
1209
1208
|
>;
|