@netless/telebox-insider 1.0.0-alpha.18 → 1.0.0-alpha.20
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 +40 -38
- package/dist/TeleBox/typings.d.ts +14 -8
- package/dist/TeleBox/utils.d.ts +5 -0
- package/dist/TeleBoxManager/index.d.ts +8 -2
- package/dist/TeleBoxManager/typings.d.ts +10 -4
- package/dist/style.css +1 -1
- package/dist/telebox-insider.cjs.js +1 -1
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +1 -1
- package/dist/telebox-insider.es.js.map +1 -1
- package/package.json +67 -67
- package/src/TeleBox/index.ts +216 -251
- package/src/TeleBox/style.scss +14 -2
- package/src/TeleBox/typings.ts +14 -8
- package/src/TeleBox/utils.ts +32 -0
- package/src/TeleBoxManager/index.ts +85 -36
- package/src/TeleBoxManager/style.scss +39 -0
- package/src/TeleBoxManager/typings.ts +10 -4
- package/src/scss/variables.scss +9 -0
- package/dist/TeleStage/index.d.ts +0 -21
- package/src/TeleStage/index.ts +0 -174
- package/src/TeleStage/style.scss +0 -49
package/src/TeleBox/index.ts
CHANGED
|
@@ -43,7 +43,7 @@ import type {
|
|
|
43
43
|
TeleBoxDelegateEventConfig,
|
|
44
44
|
TeleBoxRect,
|
|
45
45
|
} from "./typings";
|
|
46
|
-
import {
|
|
46
|
+
import { calcStageRect } from "./utils";
|
|
47
47
|
|
|
48
48
|
export * from "./constants";
|
|
49
49
|
export * from "./typings";
|
|
@@ -57,8 +57,10 @@ type ValConfig = {
|
|
|
57
57
|
visible: Val<RequiredTeleBoxConfig["visible"], boolean>;
|
|
58
58
|
resizable: Val<RequiredTeleBoxConfig["resizable"], boolean>;
|
|
59
59
|
draggable: Val<RequiredTeleBoxConfig["draggable"], boolean>;
|
|
60
|
-
|
|
61
|
-
stageRatio: Val<
|
|
60
|
+
boxRatio: Val<RequiredTeleBoxConfig["boxRatio"], boolean>;
|
|
61
|
+
stageRatio: Val<RequiredTeleBoxConfig["stageRatio"], boolean>;
|
|
62
|
+
stageStyle: Val<RequiredTeleBoxConfig["stageStyle"], boolean>;
|
|
63
|
+
bodyStyle: Val<RequiredTeleBoxConfig["bodyStyle"], boolean>;
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
type PropsValConfig = {
|
|
@@ -69,6 +71,8 @@ type PropsValConfig = {
|
|
|
69
71
|
readonly: RequiredTeleBoxConfig["readonly$"];
|
|
70
72
|
rootRect: RequiredTeleBoxConfig["rootRect$"];
|
|
71
73
|
managerStageRect: RequiredTeleBoxConfig["managerStageRect$"];
|
|
74
|
+
defaultBoxStageStyle: RequiredTeleBoxConfig["defaultBoxStageStyle$"];
|
|
75
|
+
defaultBoxBodyStyle: RequiredTeleBoxConfig["defaultBoxBodyStyle$"];
|
|
72
76
|
collectorRect: RequiredTeleBoxConfig["collectorRect$"];
|
|
73
77
|
};
|
|
74
78
|
|
|
@@ -76,11 +80,6 @@ type MyReadonlyValConfig = {
|
|
|
76
80
|
zIndex: Val<RequiredTeleBoxConfig["zIndex"], boolean>;
|
|
77
81
|
focus: Val<RequiredTeleBoxConfig["focus"], boolean>;
|
|
78
82
|
|
|
79
|
-
$userContent: Val<TeleBoxConfig["content"], boolean>;
|
|
80
|
-
$userStage: Val<TeleBoxConfig["content"], boolean>;
|
|
81
|
-
$userFooter: Val<TeleBoxConfig["footer"], boolean>;
|
|
82
|
-
$userStyles: Val<TeleBoxConfig["styles"], boolean>;
|
|
83
|
-
|
|
84
83
|
minSize: Val<TeleBoxSize, boolean>;
|
|
85
84
|
intrinsicSize: Val<TeleBoxSize, boolean>;
|
|
86
85
|
intrinsicCoord: Val<TeleBoxCoord, boolean>;
|
|
@@ -88,10 +87,8 @@ type MyReadonlyValConfig = {
|
|
|
88
87
|
pxIntrinsicSize: ReadonlyVal<TeleBoxSize, boolean>;
|
|
89
88
|
pxIntrinsicCoord: ReadonlyVal<TeleBoxCoord, boolean>;
|
|
90
89
|
state: ReadonlyVal<TeleBoxState, boolean>;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
contentRect: Val<TeleBoxRect>;
|
|
94
|
-
contentStageRect: ReadonlyVal<TeleBoxRect>;
|
|
90
|
+
bodyRect: Val<TeleBoxRect>;
|
|
91
|
+
stageRect: ReadonlyVal<TeleBoxRect>;
|
|
95
92
|
};
|
|
96
93
|
|
|
97
94
|
type CombinedValEnhancedResult = ReadonlyValEnhancedResult<
|
|
@@ -115,7 +112,7 @@ export class TeleBox {
|
|
|
115
112
|
y = 0.1,
|
|
116
113
|
resizable = true,
|
|
117
114
|
draggable = true,
|
|
118
|
-
|
|
115
|
+
boxRatio = -1,
|
|
119
116
|
focus = false,
|
|
120
117
|
zIndex = 100,
|
|
121
118
|
stageRatio = null,
|
|
@@ -124,18 +121,21 @@ export class TeleBox {
|
|
|
124
121
|
stage,
|
|
125
122
|
footer,
|
|
126
123
|
styles,
|
|
127
|
-
|
|
124
|
+
userStyles,
|
|
125
|
+
bodyStyle = null,
|
|
126
|
+
stageStyle = null,
|
|
128
127
|
darkMode$,
|
|
129
128
|
fence$,
|
|
130
129
|
minimized$,
|
|
131
130
|
maximized$,
|
|
132
131
|
readonly$,
|
|
133
|
-
root
|
|
132
|
+
root,
|
|
134
133
|
rootRect$,
|
|
135
134
|
managerStageRect$,
|
|
136
135
|
managerStageRatio$,
|
|
136
|
+
defaultBoxBodyStyle$,
|
|
137
|
+
defaultBoxStageStyle$,
|
|
137
138
|
collectorRect$,
|
|
138
|
-
managerHighlightStage$,
|
|
139
139
|
}: TeleBoxConfig) {
|
|
140
140
|
this._sideEffect = new SideEffectManager();
|
|
141
141
|
|
|
@@ -149,13 +149,9 @@ export class TeleBox {
|
|
|
149
149
|
const visible$ = new Val(visible);
|
|
150
150
|
const resizable$ = new Val(resizable);
|
|
151
151
|
const draggable$ = new Val(draggable);
|
|
152
|
-
const
|
|
152
|
+
const boxRatio$ = new Val(boxRatio);
|
|
153
153
|
const zIndex$ = new Val(zIndex);
|
|
154
154
|
const focus$ = new Val(focus);
|
|
155
|
-
const $userContent$ = new Val(content);
|
|
156
|
-
const $userStage$ = new Val(stage);
|
|
157
|
-
const $userFooter$ = new Val(footer);
|
|
158
|
-
const $userStyles$ = new Val(styles);
|
|
159
155
|
|
|
160
156
|
const state$ = combine(
|
|
161
157
|
[minimized$, maximized$],
|
|
@@ -216,46 +212,29 @@ export class TeleBox {
|
|
|
216
212
|
const pxIntrinsicCoord$ = combine(
|
|
217
213
|
[intrinsicCoord$, managerStageRect$],
|
|
218
214
|
([intrinsicCoord, managerStageRect]) => ({
|
|
219
|
-
x:
|
|
220
|
-
|
|
221
|
-
managerStageRect.x,
|
|
222
|
-
y:
|
|
223
|
-
intrinsicCoord.y * managerStageRect.height +
|
|
224
|
-
managerStageRect.y,
|
|
215
|
+
x: intrinsicCoord.x * managerStageRect.width,
|
|
216
|
+
y: intrinsicCoord.y * managerStageRect.height,
|
|
225
217
|
}),
|
|
226
218
|
{ compare: shallowequal }
|
|
227
219
|
);
|
|
228
220
|
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
const highlightStage$ = combine(
|
|
234
|
-
[boxHighlightStage$, managerHighlightStage$],
|
|
235
|
-
([boxHighlightStage, managerHighlightStage]) =>
|
|
236
|
-
boxHighlightStage ?? managerHighlightStage
|
|
237
|
-
);
|
|
221
|
+
const bodyStyle$ = new Val<string | null>(bodyStyle);
|
|
222
|
+
const stageStyle$ = new Val<string | null>(stageStyle);
|
|
238
223
|
|
|
239
224
|
const contentRoot$ = new Val<HTMLElement | null>(null);
|
|
240
|
-
|
|
241
|
-
const contentRect$ = new Val<TeleBoxRect>(rootRect$.value, {
|
|
225
|
+
const bodyRect$ = new Val<TeleBoxRect>(managerStageRect$.value, {
|
|
242
226
|
compare: shallowequal,
|
|
243
227
|
});
|
|
244
|
-
|
|
245
228
|
const stageRatio$ = new Val(stageRatio);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
),
|
|
256
|
-
highlightStage$,
|
|
257
|
-
});
|
|
258
|
-
this._sideEffect.addDisposer(() => teleStage.destroy());
|
|
229
|
+
const finalStageRatio$ = combine(
|
|
230
|
+
[stageRatio$, managerStageRatio$],
|
|
231
|
+
([stageRatio, managerStageRatio]) => stageRatio ?? managerStageRatio
|
|
232
|
+
);
|
|
233
|
+
const stageRect$ = combine(
|
|
234
|
+
[bodyRect$, finalStageRatio$],
|
|
235
|
+
calcStageRect,
|
|
236
|
+
{ compare: shallowequal }
|
|
237
|
+
);
|
|
259
238
|
|
|
260
239
|
const propsValConfig: PropsValConfig = {
|
|
261
240
|
darkMode: darkMode$,
|
|
@@ -265,6 +244,8 @@ export class TeleBox {
|
|
|
265
244
|
readonly: readonly$,
|
|
266
245
|
rootRect: rootRect$,
|
|
267
246
|
managerStageRect: managerStageRect$,
|
|
247
|
+
defaultBoxBodyStyle: defaultBoxBodyStyle$,
|
|
248
|
+
defaultBoxStageStyle: defaultBoxStageStyle$,
|
|
268
249
|
collectorRect: collectorRect$,
|
|
269
250
|
};
|
|
270
251
|
|
|
@@ -274,11 +255,6 @@ export class TeleBox {
|
|
|
274
255
|
zIndex: zIndex$,
|
|
275
256
|
focus: focus$,
|
|
276
257
|
|
|
277
|
-
$userContent: $userContent$,
|
|
278
|
-
$userStage: $userStage$,
|
|
279
|
-
$userFooter: $userFooter$,
|
|
280
|
-
$userStyles: $userStyles$,
|
|
281
|
-
|
|
282
258
|
state: state$,
|
|
283
259
|
minSize: minSize$,
|
|
284
260
|
pxMinSize: pxMinSize$,
|
|
@@ -286,10 +262,8 @@ export class TeleBox {
|
|
|
286
262
|
intrinsicCoord: intrinsicCoord$,
|
|
287
263
|
pxIntrinsicSize: pxIntrinsicSize$,
|
|
288
264
|
pxIntrinsicCoord: pxIntrinsicCoord$,
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
contentRect: contentRect$,
|
|
292
|
-
contentStageRect: teleStage.stageRect$,
|
|
265
|
+
bodyRect: bodyRect$,
|
|
266
|
+
stageRect: stageRect$,
|
|
293
267
|
};
|
|
294
268
|
|
|
295
269
|
withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
|
|
@@ -299,8 +273,10 @@ export class TeleBox {
|
|
|
299
273
|
visible: visible$,
|
|
300
274
|
resizable: resizable$,
|
|
301
275
|
draggable: draggable$,
|
|
302
|
-
|
|
276
|
+
boxRatio: boxRatio$,
|
|
303
277
|
stageRatio: stageRatio$,
|
|
278
|
+
bodyStyle: bodyStyle$,
|
|
279
|
+
stageStyle: stageStyle$,
|
|
304
280
|
};
|
|
305
281
|
|
|
306
282
|
withValueEnhancer(this, valConfig, valManager);
|
|
@@ -317,14 +293,13 @@ export class TeleBox {
|
|
|
317
293
|
});
|
|
318
294
|
|
|
319
295
|
this._sideEffect.addDisposer(
|
|
320
|
-
|
|
321
|
-
if (
|
|
296
|
+
boxRatio$.subscribe((boxRatio) => {
|
|
297
|
+
if (boxRatio > 0) {
|
|
322
298
|
this.transform(
|
|
323
299
|
pxIntrinsicCoord$.value.x,
|
|
324
300
|
pxIntrinsicCoord$.value.y,
|
|
325
301
|
pxIntrinsicSize$.value.width,
|
|
326
|
-
pxIntrinsicSize$.value.height
|
|
327
|
-
true
|
|
302
|
+
pxIntrinsicSize$.value.height
|
|
328
303
|
);
|
|
329
304
|
}
|
|
330
305
|
})
|
|
@@ -335,15 +310,20 @@ export class TeleBox {
|
|
|
335
310
|
if (fence) {
|
|
336
311
|
this.move(
|
|
337
312
|
pxIntrinsicCoord$.value.x,
|
|
338
|
-
pxIntrinsicCoord$.value.y
|
|
339
|
-
true
|
|
313
|
+
pxIntrinsicCoord$.value.y
|
|
340
314
|
);
|
|
341
315
|
}
|
|
342
316
|
})
|
|
343
317
|
);
|
|
344
318
|
|
|
345
|
-
this.$box = this.
|
|
319
|
+
this.$box = this._render();
|
|
346
320
|
contentRoot$.setValue(this.$content.parentElement);
|
|
321
|
+
content && this.mountContent(content);
|
|
322
|
+
stage && this.mountStage(stage);
|
|
323
|
+
footer && this.mountFooter(footer);
|
|
324
|
+
styles && this.mountStyles(styles);
|
|
325
|
+
userStyles && this.mountUserStyles(userStyles);
|
|
326
|
+
root.appendChild(this.$box);
|
|
347
327
|
|
|
348
328
|
const watchValEvent = <E extends TeleBoxEvent>(
|
|
349
329
|
val: ReadonlyVal<TeleBoxEventConfig[E], boolean>,
|
|
@@ -380,13 +360,6 @@ export class TeleBox {
|
|
|
380
360
|
);
|
|
381
361
|
}
|
|
382
362
|
}),
|
|
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
363
|
]);
|
|
391
364
|
}
|
|
392
365
|
|
|
@@ -492,34 +465,25 @@ export class TeleBox {
|
|
|
492
465
|
const pxIntrinsicSize = this.pxIntrinsicSize;
|
|
493
466
|
|
|
494
467
|
if (this.fence) {
|
|
495
|
-
safeX = clamp(
|
|
496
|
-
x,
|
|
497
|
-
managerStageRect.x,
|
|
498
|
-
managerStageRect.x +
|
|
499
|
-
managerStageRect.width -
|
|
500
|
-
pxIntrinsicSize.width
|
|
501
|
-
);
|
|
468
|
+
safeX = clamp(x, 0, managerStageRect.width - pxIntrinsicSize.width);
|
|
502
469
|
safeY = clamp(
|
|
503
470
|
y,
|
|
504
|
-
|
|
505
|
-
managerStageRect.
|
|
506
|
-
managerStageRect.height -
|
|
507
|
-
pxIntrinsicSize.height
|
|
471
|
+
0,
|
|
472
|
+
managerStageRect.height - pxIntrinsicSize.height
|
|
508
473
|
);
|
|
509
474
|
} else {
|
|
510
|
-
const rootRect = this.rootRect;
|
|
511
475
|
safeX = clamp(
|
|
512
476
|
x,
|
|
513
|
-
|
|
514
|
-
0 +
|
|
477
|
+
-(pxIntrinsicSize.width - 120),
|
|
478
|
+
0 + managerStageRect.width - 20
|
|
515
479
|
);
|
|
516
|
-
safeY = clamp(y, 0, 0 +
|
|
480
|
+
safeY = clamp(y, 0, 0 + managerStageRect.height - 20);
|
|
517
481
|
}
|
|
518
482
|
|
|
519
483
|
this._intrinsicCoord$.setValue(
|
|
520
484
|
{
|
|
521
|
-
x:
|
|
522
|
-
y:
|
|
485
|
+
x: safeX / managerStageRect.width,
|
|
486
|
+
y: safeY / managerStageRect.height,
|
|
523
487
|
},
|
|
524
488
|
skipUpdate
|
|
525
489
|
);
|
|
@@ -542,21 +506,20 @@ export class TeleBox {
|
|
|
542
506
|
skipUpdate = false
|
|
543
507
|
): void {
|
|
544
508
|
const managerStageRect = this.managerStageRect;
|
|
545
|
-
const rootRect = this.rootRect;
|
|
546
509
|
|
|
547
510
|
width = Math.max(width, this.pxMinSize.width);
|
|
548
511
|
height = Math.max(height, this.pxMinSize.height);
|
|
549
512
|
|
|
550
|
-
if (this.
|
|
551
|
-
const newHeight = this.
|
|
513
|
+
if (this.boxRatio > 0) {
|
|
514
|
+
const newHeight = this.boxRatio * width;
|
|
552
515
|
if (y !== this.pxIntrinsicCoord.y) {
|
|
553
516
|
y -= newHeight - height;
|
|
554
517
|
}
|
|
555
518
|
height = newHeight;
|
|
556
519
|
}
|
|
557
520
|
|
|
558
|
-
if (y <
|
|
559
|
-
y =
|
|
521
|
+
if (y < 0) {
|
|
522
|
+
y = 0;
|
|
560
523
|
height = this.pxIntrinsicSize.height;
|
|
561
524
|
}
|
|
562
525
|
|
|
@@ -570,85 +533,109 @@ export class TeleBox {
|
|
|
570
533
|
);
|
|
571
534
|
}
|
|
572
535
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
536
|
+
private $authorContent?: HTMLElement;
|
|
537
|
+
|
|
538
|
+
/** Mount dom to box content. */
|
|
576
539
|
public mountContent(content: HTMLElement): void {
|
|
577
|
-
this
|
|
540
|
+
this.$authorContent?.remove();
|
|
541
|
+
this.$authorContent = content;
|
|
542
|
+
this.$content.appendChild(content);
|
|
578
543
|
}
|
|
579
544
|
|
|
580
|
-
/**
|
|
581
|
-
* Unmount content from the box.
|
|
582
|
-
*/
|
|
545
|
+
/** Unmount content from the box. */
|
|
583
546
|
public unmountContent(): void {
|
|
584
|
-
this
|
|
547
|
+
if (this.$authorContent) {
|
|
548
|
+
this.$authorContent.remove();
|
|
549
|
+
this.$authorContent = undefined;
|
|
550
|
+
}
|
|
585
551
|
}
|
|
586
552
|
|
|
553
|
+
private $authorStage?: HTMLElement;
|
|
554
|
+
|
|
555
|
+
/** Mount dom to box stage. */
|
|
587
556
|
public mountStage(stage: HTMLElement): void {
|
|
588
|
-
this
|
|
557
|
+
this.$authorStage?.remove();
|
|
558
|
+
this.$authorStage = stage;
|
|
559
|
+
if (!this.$stage) {
|
|
560
|
+
this.$stage = this._renderStage();
|
|
561
|
+
}
|
|
562
|
+
this.$stage.appendChild(stage);
|
|
563
|
+
if (!this.$stage.parentElement) {
|
|
564
|
+
this.$body.appendChild(this.$stage);
|
|
565
|
+
}
|
|
589
566
|
}
|
|
590
567
|
|
|
591
|
-
/**
|
|
592
|
-
* Unmount content from the box.
|
|
593
|
-
*/
|
|
568
|
+
/** Unmount content from the box. */
|
|
594
569
|
public unmountStage(): void {
|
|
595
|
-
this
|
|
570
|
+
if (this.$authorStage) {
|
|
571
|
+
this.$authorStage.remove();
|
|
572
|
+
this.$authorStage = undefined;
|
|
573
|
+
}
|
|
574
|
+
this.$stage?.remove();
|
|
596
575
|
}
|
|
597
576
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
577
|
+
private $authorFooter?: HTMLElement;
|
|
578
|
+
|
|
579
|
+
/** Mount dom to box Footer. */
|
|
601
580
|
public mountFooter(footer: HTMLElement): void {
|
|
602
|
-
this
|
|
581
|
+
this.$authorFooter?.remove();
|
|
582
|
+
this.$authorFooter = footer;
|
|
583
|
+
this.$footer.appendChild(footer);
|
|
603
584
|
}
|
|
604
585
|
|
|
605
|
-
/**
|
|
606
|
-
* Unmount Footer from the box.
|
|
607
|
-
*/
|
|
586
|
+
/** Unmount Footer from the box. */
|
|
608
587
|
public unmountFooter(): void {
|
|
609
|
-
this
|
|
588
|
+
if (this.$authorFooter) {
|
|
589
|
+
this.$authorFooter.remove();
|
|
590
|
+
this.$authorFooter = undefined;
|
|
591
|
+
}
|
|
610
592
|
}
|
|
611
593
|
|
|
612
|
-
|
|
613
|
-
|
|
594
|
+
/** Mount styles for box content */
|
|
595
|
+
public mountStyles(styles: string): void {
|
|
596
|
+
this.$styles.textContent = styles;
|
|
614
597
|
}
|
|
615
598
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
$styles = document.createElement("style");
|
|
620
|
-
$styles.textContent = styles;
|
|
621
|
-
} else {
|
|
622
|
-
$styles = styles;
|
|
623
|
-
}
|
|
624
|
-
this._$userStyles$.setValue($styles);
|
|
599
|
+
/** Umount styles for box content */
|
|
600
|
+
public unmountStyles(): void {
|
|
601
|
+
this.$styles.textContent = "";
|
|
625
602
|
}
|
|
626
603
|
|
|
627
|
-
|
|
628
|
-
|
|
604
|
+
/** Mount user styles for box content */
|
|
605
|
+
public mountUserStyles(styles: string): void {
|
|
606
|
+
this.$userStyles.textContent = styles;
|
|
629
607
|
}
|
|
630
608
|
|
|
631
|
-
/**
|
|
632
|
-
public
|
|
633
|
-
this.
|
|
609
|
+
/** Umount user styles for box content */
|
|
610
|
+
public unmountUserStyles(): void {
|
|
611
|
+
this.$userStyles.textContent = "";
|
|
634
612
|
}
|
|
635
613
|
|
|
636
614
|
/** DOM of the box */
|
|
637
615
|
public $box: HTMLElement;
|
|
638
616
|
|
|
639
|
-
/** DOM of the box
|
|
617
|
+
/** DOM of the box body */
|
|
618
|
+
public $body!: HTMLElement;
|
|
619
|
+
|
|
620
|
+
/** DOM of the box content container inside box body */
|
|
640
621
|
public $content!: HTMLElement;
|
|
641
622
|
|
|
642
|
-
/** DOM of the box stage area */
|
|
623
|
+
/** DOM of the box stage area inside box body */
|
|
643
624
|
public $stage?: HTMLElement;
|
|
644
625
|
|
|
645
|
-
/** DOM of
|
|
626
|
+
/** DOM of custom box content styles */
|
|
627
|
+
public $styles!: HTMLStyleElement;
|
|
628
|
+
|
|
629
|
+
/** DOM of end user custom box content styles */
|
|
630
|
+
public $userStyles!: HTMLStyleElement;
|
|
631
|
+
|
|
632
|
+
/** DOM of the box title bar container */
|
|
646
633
|
public $titleBar!: HTMLElement;
|
|
647
634
|
|
|
648
|
-
/** DOM of the box footer */
|
|
635
|
+
/** DOM of the box footer container */
|
|
649
636
|
public $footer!: HTMLElement;
|
|
650
637
|
|
|
651
|
-
|
|
638
|
+
private _render(): HTMLElement {
|
|
652
639
|
if (this.$box) {
|
|
653
640
|
return this.$box;
|
|
654
641
|
}
|
|
@@ -736,6 +723,8 @@ export class TeleBox {
|
|
|
736
723
|
this._pxIntrinsicSize$,
|
|
737
724
|
this._pxIntrinsicCoord$,
|
|
738
725
|
this._collectorRect$,
|
|
726
|
+
this._rootRect$,
|
|
727
|
+
this._managerStageRect$,
|
|
739
728
|
],
|
|
740
729
|
([
|
|
741
730
|
maximized,
|
|
@@ -743,28 +732,30 @@ export class TeleBox {
|
|
|
743
732
|
pxIntrinsicSize,
|
|
744
733
|
pxIntrinsicCoord,
|
|
745
734
|
collectorRect,
|
|
735
|
+
rootRect,
|
|
736
|
+
managerStageRect,
|
|
746
737
|
]) => {
|
|
747
738
|
const styles: {
|
|
748
739
|
x: number;
|
|
749
740
|
y: number;
|
|
750
|
-
width:
|
|
751
|
-
height:
|
|
741
|
+
width: number;
|
|
742
|
+
height: number;
|
|
752
743
|
scaleX: number;
|
|
753
744
|
scaleY: number;
|
|
754
745
|
} = maximized
|
|
755
746
|
? {
|
|
756
|
-
x:
|
|
757
|
-
y:
|
|
758
|
-
width:
|
|
759
|
-
height:
|
|
747
|
+
x: -managerStageRect.x,
|
|
748
|
+
y: -managerStageRect.y,
|
|
749
|
+
width: rootRect.width,
|
|
750
|
+
height: rootRect.height,
|
|
760
751
|
scaleX: 1,
|
|
761
752
|
scaleY: 1,
|
|
762
753
|
}
|
|
763
754
|
: {
|
|
764
755
|
x: pxIntrinsicCoord.x,
|
|
765
756
|
y: pxIntrinsicCoord.y,
|
|
766
|
-
width: pxIntrinsicSize.width
|
|
767
|
-
height: pxIntrinsicSize.height
|
|
757
|
+
width: pxIntrinsicSize.width,
|
|
758
|
+
height: pxIntrinsicSize.height,
|
|
768
759
|
scaleX: 1,
|
|
769
760
|
scaleY: 1,
|
|
770
761
|
};
|
|
@@ -775,11 +766,13 @@ export class TeleBox {
|
|
|
775
766
|
styles.x =
|
|
776
767
|
collectorRect.x -
|
|
777
768
|
boxWidth / 2 +
|
|
778
|
-
collectorRect.width / 2
|
|
769
|
+
collectorRect.width / 2 -
|
|
770
|
+
managerStageRect.x;
|
|
779
771
|
styles.y =
|
|
780
772
|
collectorRect.y -
|
|
781
773
|
boxHeight / 2 +
|
|
782
|
-
collectorRect.height / 2
|
|
774
|
+
collectorRect.height / 2 -
|
|
775
|
+
managerStageRect.y;
|
|
783
776
|
styles.scaleX = collectorRect.width / boxWidth;
|
|
784
777
|
styles.scaleY = collectorRect.height / boxHeight;
|
|
785
778
|
}
|
|
@@ -789,8 +782,8 @@ export class TeleBox {
|
|
|
789
782
|
);
|
|
790
783
|
|
|
791
784
|
const boxStyles = boxStyles$.value;
|
|
792
|
-
this.$box.style.width = boxStyles.width;
|
|
793
|
-
this.$box.style.height = boxStyles.height;
|
|
785
|
+
this.$box.style.width = boxStyles.width + "px";
|
|
786
|
+
this.$box.style.height = boxStyles.height + "px";
|
|
794
787
|
// Add 10px offset on first frame
|
|
795
788
|
// which creates a subtle moving effect
|
|
796
789
|
this.$box.style.transform = `translate(${boxStyles.x - 10}px,${
|
|
@@ -812,17 +805,45 @@ export class TeleBox {
|
|
|
812
805
|
$titleBar.appendChild(this.titleBar.render());
|
|
813
806
|
this.$titleBar = $titleBar;
|
|
814
807
|
|
|
815
|
-
const $
|
|
816
|
-
$
|
|
808
|
+
const $body = document.createElement("div");
|
|
809
|
+
$body.className = this.wrapClassName("content-wrap");
|
|
810
|
+
this.$body = $body;
|
|
811
|
+
|
|
812
|
+
const $styles = document.createElement("style");
|
|
813
|
+
this.$styles = $styles;
|
|
814
|
+
$body.appendChild($styles);
|
|
815
|
+
|
|
816
|
+
const $userStyles = document.createElement("style");
|
|
817
|
+
this.$userStyles = $userStyles;
|
|
818
|
+
$body.appendChild($userStyles);
|
|
817
819
|
|
|
818
820
|
const $content = document.createElement("div");
|
|
819
821
|
$content.className =
|
|
820
822
|
this.wrapClassName("content") + " tele-fancy-scrollbar";
|
|
821
823
|
this.$content = $content;
|
|
824
|
+
this._sideEffect.addDisposer(
|
|
825
|
+
combine(
|
|
826
|
+
[this._bodyStyle$, this._defaultBoxBodyStyle$],
|
|
827
|
+
([bodyStyle, defaultBoxBodyStyle]) =>
|
|
828
|
+
bodyStyle ?? defaultBoxBodyStyle
|
|
829
|
+
).subscribe((style) => ($content.style.cssText = style || ""))
|
|
830
|
+
);
|
|
831
|
+
|
|
832
|
+
$body.appendChild($content);
|
|
833
|
+
|
|
834
|
+
const $footer = document.createElement("div");
|
|
835
|
+
$footer.className = this.wrapClassName("footer-wrap");
|
|
836
|
+
this.$footer = $footer;
|
|
822
837
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
838
|
+
$boxMain.appendChild($titleBar);
|
|
839
|
+
$boxMain.appendChild($body);
|
|
840
|
+
$boxMain.appendChild($footer);
|
|
841
|
+
|
|
842
|
+
this._renderResizeHandlers();
|
|
843
|
+
|
|
844
|
+
const updateBodyRect = (): void => {
|
|
845
|
+
const rect = $body.getBoundingClientRect();
|
|
846
|
+
this._bodyRect$.setValue({
|
|
826
847
|
x: 0,
|
|
827
848
|
y: 0,
|
|
828
849
|
width: rect.width,
|
|
@@ -832,10 +853,10 @@ export class TeleBox {
|
|
|
832
853
|
this._sideEffect.add(() => {
|
|
833
854
|
const observer = new ResizeObserver(() => {
|
|
834
855
|
if (!this.minimized) {
|
|
835
|
-
|
|
856
|
+
updateBodyRect();
|
|
836
857
|
}
|
|
837
858
|
});
|
|
838
|
-
observer.observe($
|
|
859
|
+
observer.observe($body);
|
|
839
860
|
return () => observer.disconnect();
|
|
840
861
|
});
|
|
841
862
|
this._sideEffect.addDisposer(
|
|
@@ -843,7 +864,7 @@ export class TeleBox {
|
|
|
843
864
|
// correct content size when restoring from minimized
|
|
844
865
|
if (!minimized) {
|
|
845
866
|
this._sideEffect.setTimeout(
|
|
846
|
-
|
|
867
|
+
updateBodyRect,
|
|
847
868
|
400,
|
|
848
869
|
"minimized-content-rect-fix"
|
|
849
870
|
);
|
|
@@ -851,100 +872,43 @@ export class TeleBox {
|
|
|
851
872
|
})
|
|
852
873
|
);
|
|
853
874
|
|
|
854
|
-
this
|
|
855
|
-
|
|
856
|
-
return this._$userStyles$.subscribe(($userStyles) => {
|
|
857
|
-
if (last$userStyles) {
|
|
858
|
-
last$userStyles.remove();
|
|
859
|
-
}
|
|
860
|
-
last$userStyles = $userStyles;
|
|
861
|
-
if ($userStyles) {
|
|
862
|
-
$contentWrap.appendChild($userStyles);
|
|
863
|
-
}
|
|
864
|
-
});
|
|
865
|
-
});
|
|
866
|
-
|
|
867
|
-
this._sideEffect.add(() => {
|
|
868
|
-
let last$userContent: HTMLElement | undefined;
|
|
869
|
-
return this._$userContent$.subscribe(($userContent) => {
|
|
870
|
-
if (last$userContent) {
|
|
871
|
-
last$userContent.remove();
|
|
872
|
-
}
|
|
873
|
-
last$userContent = $userContent;
|
|
874
|
-
if ($userContent) {
|
|
875
|
-
$content.appendChild($userContent);
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
this._sideEffect.add(() => {
|
|
881
|
-
let last$userStage: HTMLElement | undefined;
|
|
882
|
-
return this._$userStage$.subscribe(($userStage) => {
|
|
883
|
-
if (last$userStage) {
|
|
884
|
-
last$userStage.remove();
|
|
885
|
-
}
|
|
886
|
-
last$userStage = $userStage;
|
|
887
|
-
if ($userStage) {
|
|
888
|
-
if (!this.$stage) {
|
|
889
|
-
const $stage = document.createElement("div");
|
|
890
|
-
this.$stage = $stage;
|
|
891
|
-
$stage.className = this.wrapClassName("content-stage");
|
|
892
|
-
this._sideEffect.addDisposer(
|
|
893
|
-
this._contentStageRect$.subscribe((rect) => {
|
|
894
|
-
$stage.style.top = rect.y + "px";
|
|
895
|
-
$stage.style.left = rect.x + "px";
|
|
896
|
-
$stage.style.width = rect.width + "px";
|
|
897
|
-
$stage.style.height = rect.height + "px";
|
|
898
|
-
}),
|
|
899
|
-
"content-stage-rect"
|
|
900
|
-
);
|
|
901
|
-
$content.appendChild($stage);
|
|
902
|
-
}
|
|
903
|
-
if (!this.$stage.parentElement) {
|
|
904
|
-
$content.appendChild(this.$stage);
|
|
905
|
-
}
|
|
906
|
-
this.$stage.appendChild($userStage);
|
|
907
|
-
} else if (this.$stage?.parentElement) {
|
|
908
|
-
this.$stage.remove();
|
|
909
|
-
}
|
|
910
|
-
});
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
$contentWrap.appendChild($content);
|
|
914
|
-
|
|
915
|
-
const $footer = document.createElement("div");
|
|
916
|
-
$footer.className = this.wrapClassName("footer-wrap");
|
|
917
|
-
this.$footer = $footer;
|
|
918
|
-
|
|
919
|
-
this._sideEffect.add(() => {
|
|
920
|
-
let last$userFooter: HTMLElement | undefined;
|
|
921
|
-
return this._$userFooter$.subscribe(($userFooter) => {
|
|
922
|
-
if (last$userFooter) {
|
|
923
|
-
last$userFooter.remove();
|
|
924
|
-
}
|
|
925
|
-
last$userFooter = $userFooter;
|
|
926
|
-
if ($userFooter) {
|
|
927
|
-
$footer.appendChild($userFooter);
|
|
928
|
-
}
|
|
929
|
-
});
|
|
930
|
-
});
|
|
931
|
-
|
|
932
|
-
$boxMain.appendChild($titleBar);
|
|
933
|
-
$boxMain.appendChild($contentWrap);
|
|
934
|
-
$boxMain.appendChild($footer);
|
|
875
|
+
return this.$box;
|
|
876
|
+
}
|
|
935
877
|
|
|
936
|
-
|
|
878
|
+
private _renderStage(): HTMLDivElement {
|
|
879
|
+
const $stage = document.createElement("div");
|
|
937
880
|
|
|
938
|
-
|
|
881
|
+
$stage.className = this.wrapClassName("content-stage");
|
|
882
|
+
const updateStageRect = (stageRect: TeleBoxRect): void => {
|
|
883
|
+
$stage.style.top = stageRect.y + "px";
|
|
884
|
+
$stage.style.left = stageRect.x + "px";
|
|
885
|
+
$stage.style.width = stageRect.width + "px";
|
|
886
|
+
$stage.style.height = stageRect.height + "px";
|
|
887
|
+
};
|
|
888
|
+
this._sideEffect.addDisposer(
|
|
889
|
+
[
|
|
890
|
+
combine(
|
|
891
|
+
[this._stageStyle$, this._defaultBoxStageStyle$],
|
|
892
|
+
([stageStyle, defaultBoxStageStyle]) =>
|
|
893
|
+
stageStyle ?? defaultBoxStageStyle
|
|
894
|
+
).subscribe((styles) => {
|
|
895
|
+
$stage.style.cssText = styles || "";
|
|
896
|
+
updateStageRect(this._stageRect$.value);
|
|
897
|
+
}),
|
|
898
|
+
this._stageRect$.subscribe(updateStageRect),
|
|
899
|
+
],
|
|
900
|
+
"content-stage-styles"
|
|
901
|
+
);
|
|
902
|
+
return $stage;
|
|
939
903
|
}
|
|
940
904
|
|
|
941
|
-
|
|
905
|
+
private _handleTrackStart?: (ev: MouseEvent | TouchEvent) => void;
|
|
942
906
|
|
|
943
907
|
public handleTrackStart: (ev: MouseEvent | TouchEvent) => void = (ev) => {
|
|
944
908
|
return this._handleTrackStart?.(ev);
|
|
945
909
|
};
|
|
946
910
|
|
|
947
|
-
|
|
911
|
+
private _renderResizeHandlers(): void {
|
|
948
912
|
const $resizeHandles = document.createElement("div");
|
|
949
913
|
$resizeHandles.className = this.wrapClassName("resize-handles");
|
|
950
914
|
|
|
@@ -985,8 +949,8 @@ export class TeleBox {
|
|
|
985
949
|
preventEvent(ev);
|
|
986
950
|
|
|
987
951
|
let { pageX, pageY } = flattenEvent(ev);
|
|
988
|
-
if (pageY <
|
|
989
|
-
pageY =
|
|
952
|
+
if (pageY < 0) {
|
|
953
|
+
pageY = 0;
|
|
990
954
|
}
|
|
991
955
|
|
|
992
956
|
const offsetX = pageX - trackStartPageX;
|
|
@@ -1198,13 +1162,14 @@ export type ReadonlyTeleBox = Pick<
|
|
|
1198
1162
|
| "unmountStage"
|
|
1199
1163
|
| "mountStyles"
|
|
1200
1164
|
| "unmountStyles"
|
|
1201
|
-
| "
|
|
1165
|
+
| "setTitle"
|
|
1202
1166
|
| "setDraggable"
|
|
1203
1167
|
| "setResizable"
|
|
1204
|
-
| "setHighlightStage"
|
|
1205
|
-
| "setTitle"
|
|
1206
|
-
| "setRatio"
|
|
1207
1168
|
| "setVisible"
|
|
1169
|
+
| "setBoxRatio"
|
|
1170
|
+
| "setStageRatio"
|
|
1171
|
+
| "setStageStyle"
|
|
1172
|
+
| "setBodyStyle"
|
|
1208
1173
|
| "handleTrackStart"
|
|
1209
1174
|
| "onValChanged"
|
|
1210
1175
|
>;
|