@netless/telebox-insider 1.0.0-alpha.1 → 1.0.0-alpha.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/telebox-insider",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.4",
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.1.1"
66
+ "value-enhancer": "^1.2.1"
66
67
  }
67
68
  }
@@ -9,8 +9,13 @@ import type {
9
9
  ReadonlyValEnhancedResult,
10
10
  ValEnhancedResult,
11
11
  } from "value-enhancer";
12
- import { withValueEnhancer } from "value-enhancer";
13
- import { combine, Val, withReadonlyValueEnhancer } from "value-enhancer";
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";
@@ -55,7 +60,7 @@ type ValConfig = {
55
60
  ratio: Val<RequiredTeleBoxConfig["ratio"], boolean>;
56
61
  };
57
62
 
58
- type ReadonlyValConfig = {
63
+ type PropsValConfig = {
59
64
  darkMode: RequiredTeleBoxConfig["darkMode$"];
60
65
  fence: RequiredTeleBoxConfig["fence$"];
61
66
  minimized: RequiredTeleBoxConfig["minimized$"];
@@ -64,7 +69,9 @@ type ReadonlyValConfig = {
64
69
  rootRect: RequiredTeleBoxConfig["rootRect$"];
65
70
  managerStageRect: RequiredTeleBoxConfig["managerStageRect$"];
66
71
  collectorRect: RequiredTeleBoxConfig["collectorRect$"];
72
+ };
67
73
 
74
+ type MyReadonlyValConfig = {
68
75
  zIndex: Val<RequiredTeleBoxConfig["zIndex"], boolean>;
69
76
  focus: Val<RequiredTeleBoxConfig["focus"], boolean>;
70
77
 
@@ -85,7 +92,9 @@ type ReadonlyValConfig = {
85
92
  contentStageRect: ReadonlyVal<TeleBoxRect | null>;
86
93
  };
87
94
 
88
- type CombinedValEnhancedResult = ReadonlyValEnhancedResult<ReadonlyValConfig> &
95
+ type CombinedValEnhancedResult = ReadonlyValEnhancedResult<
96
+ PropsValConfig & MyReadonlyValConfig
97
+ > &
89
98
  ValEnhancedResult<ValConfig>;
90
99
 
91
100
  export interface TeleBox extends CombinedValEnhancedResult {}
@@ -117,6 +126,7 @@ export class TeleBox {
117
126
  minimized$,
118
127
  maximized$,
119
128
  readonly$,
129
+ root$,
120
130
  rootRect$,
121
131
  managerStageRect$,
122
132
  stageRatio$,
@@ -128,6 +138,9 @@ export class TeleBox {
128
138
  this.id = id;
129
139
  this.namespace = namespace;
130
140
 
141
+ const valManager = new ValManager();
142
+ this._sideEffect.addDisposer(() => valManager.destroy());
143
+
131
144
  const title$ = new Val(title);
132
145
  const visible$ = new Val(visible);
133
146
  const resizable$ = new Val(resizable);
@@ -220,19 +233,22 @@ export class TeleBox {
220
233
  : boxHighlightStage
221
234
  );
222
235
 
236
+ const contentRoot$ = new Val<HTMLElement | null>(null);
237
+
223
238
  const contentRect$ = new Val<TeleBoxRect>(rootRect$.value, {
224
239
  compare: shallowequal,
225
240
  });
226
241
 
227
242
  const teleStage = new TeleStage({
228
243
  namespace,
244
+ root$: contentRoot$,
229
245
  rootRect$: contentRect$,
230
246
  ratio$: stageRatio$,
231
247
  highlightStage$,
232
248
  });
233
249
  this._sideEffect.addDisposer(() => teleStage.destroy());
234
250
 
235
- const readonlyValConfig: ReadonlyValConfig = {
251
+ const propsValConfig: PropsValConfig = {
236
252
  darkMode: darkMode$,
237
253
  fence: fence$,
238
254
  minimized: minimized$,
@@ -241,7 +257,11 @@ export class TeleBox {
241
257
  rootRect: rootRect$,
242
258
  managerStageRect: managerStageRect$,
243
259
  collectorRect: collectorRect$,
260
+ };
261
+
262
+ withReadonlyValueEnhancer(this, propsValConfig);
244
263
 
264
+ const myReadonlyValConfig: MyReadonlyValConfig = {
245
265
  zIndex: zIndex$,
246
266
  focus: focus$,
247
267
 
@@ -262,7 +282,7 @@ export class TeleBox {
262
282
  contentStageRect: teleStage.stageRect$,
263
283
  };
264
284
 
265
- withReadonlyValueEnhancer(this, readonlyValConfig);
285
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
266
286
 
267
287
  const valConfig: ValConfig = {
268
288
  title: title$,
@@ -272,14 +292,14 @@ export class TeleBox {
272
292
  ratio: ratio$,
273
293
  };
274
294
 
275
- withValueEnhancer(this, valConfig);
295
+ withValueEnhancer(this, valConfig, valManager);
276
296
 
277
297
  this.titleBar =
278
298
  titleBar ||
279
299
  new DefaultTitleBar({
280
300
  readonly$: readonly$,
281
301
  state$: state$,
282
- title: title$.value,
302
+ title$: title$,
283
303
  namespace: this.namespace,
284
304
  onDragStart: (event) => this._handleTrackStart?.(event),
285
305
  onEvent: (event) => this._delegateEvents.emit(event.type),
@@ -312,7 +332,7 @@ export class TeleBox {
312
332
  );
313
333
 
314
334
  this.$box = this.render();
315
- teleStage.root$.setValue(this.$content.parentElement);
335
+ contentRoot$.setValue(this.$content.parentElement);
316
336
 
317
337
  const watchValEvent = <E extends TeleBoxEvent>(
318
338
  val: ReadonlyVal<TeleBoxEventConfig[E], boolean>,
@@ -336,23 +356,27 @@ export class TeleBox {
336
356
  watchValEvent(intrinsicSize$, TELE_BOX_EVENT.IntrinsicResize);
337
357
  watchValEvent(intrinsicCoord$, TELE_BOX_EVENT.IntrinsicMove);
338
358
 
339
- this._sideEffect.addDisposer(
359
+ this._sideEffect.addDisposer([
340
360
  visible$.reaction((visible, skipUpdate) => {
341
361
  if (!skipUpdate && !visible) {
342
362
  this.events.emit(TELE_BOX_EVENT.Close);
343
363
  }
344
- })
345
- );
346
-
347
- this._sideEffect.addDisposer(
364
+ }),
348
365
  focus$.reaction((focus, skipUpdate) => {
349
366
  if (!skipUpdate) {
350
367
  this.events.emit(
351
368
  focus ? TELE_BOX_EVENT.Focus : TELE_BOX_EVENT.Blur
352
369
  );
353
370
  }
354
- })
355
- );
371
+ }),
372
+ root$.subscribe((root) => {
373
+ if (root) {
374
+ root.appendChild(this.$box);
375
+ } else if (this.$box.parentNode) {
376
+ this.$box.remove();
377
+ }
378
+ }),
379
+ ]);
356
380
  }
357
381
 
358
382
  public readonly id: string;
@@ -535,22 +559,6 @@ export class TeleBox {
535
559
  );
536
560
  }
537
561
 
538
- /**
539
- * Mount box to a container element.
540
- */
541
- public mount(container: HTMLElement): void {
542
- container.appendChild(this.$box);
543
- }
544
-
545
- /**
546
- * Unmount box from the container element.
547
- */
548
- public unmount(): void {
549
- if (this.$box.parentNode) {
550
- this.$box.remove();
551
- }
552
- }
553
-
554
562
  /**
555
563
  * Mount dom to box content.
556
564
  */
@@ -713,8 +721,14 @@ export class TeleBox {
713
721
  ]) => {
714
722
  if (minimized && collectorRect) {
715
723
  return {
716
- x: collectorRect.x + collectorRect.width / 2,
717
- y: collectorRect.y + collectorRect.height / 2,
724
+ x:
725
+ collectorRect.x -
726
+ pxIntrinsicSize.width / 2 +
727
+ collectorRect.width / 2,
728
+ y:
729
+ collectorRect.y -
730
+ pxIntrinsicSize.height / 2 +
731
+ collectorRect.height / 2,
718
732
  width: pxIntrinsicSize.width + "px",
719
733
  height: pxIntrinsicSize.height + "px",
720
734
  scaleX: collectorRect.width / pxIntrinsicSize.width,
@@ -78,6 +78,8 @@ export interface TeleBoxConfig {
78
78
  readonly minimized$: ReadonlyVal<boolean, boolean>;
79
79
  /** Is box readonly */
80
80
  readonly readonly$: ReadonlyVal<boolean, boolean>;
81
+ /** Root element to mount boxes */
82
+ readonly root$: ReadonlyVal<HTMLElement | null>;
81
83
  /** Position and dimension of root element */
82
84
  readonly rootRect$: ReadonlyVal<TeleBoxRect>;
83
85
  /** Position and dimension of stage area */
@@ -6,17 +6,21 @@ import type {
6
6
  ReadonlyValEnhancedResult,
7
7
  ValEnhancedResult,
8
8
  } from "value-enhancer";
9
- import { withValueEnhancer } from "value-enhancer";
10
- import { combine } from "value-enhancer";
11
- import { Val } from "value-enhancer";
12
- import { withReadonlyValueEnhancer } from "value-enhancer";
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?: HTMLElement;
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
- root: Val<HTMLElement | undefined>;
29
- el: Val<HTMLElement>;
32
+ $collector: Val<HTMLElement>;
33
+ };
34
+
35
+ type PropsValConfig = {
36
+ root: TeleBoxCollectorConfig["root$"];
30
37
  };
31
38
 
32
- type ReadonlyValConfig = {
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<ReadonlyValConfig>;
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
- withValueEnhancer(this, valConfig);
80
+ withReadonlyValueEnhancer(this, propsValConfig);
67
81
 
68
- const readonlyValConfig: ReadonlyValConfig = {
82
+ const myReadonlyValConfig: MyReadonlyValConfig = {
69
83
  rect: rect$,
70
84
  visible: visible$,
71
85
  };
72
86
 
73
- withReadonlyValueEnhancer(this, readonlyValConfig);
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,6 +65,10 @@ 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"));
@@ -94,9 +109,7 @@ export class MaxTitleBar extends DefaultTitleBar {
94
109
  this.wrapClassName("max-titlebar-single-title"),
95
110
  titles.length === 1
96
111
  );
97
- if (titles.length === 1) {
98
- this.setTitle(titles[0].title);
99
- } else {
112
+ if (titles.length !== 1) {
100
113
  $titleBar.replaceChild(
101
114
  this.renderTitles(),
102
115
  $titleBar.firstElementChild as HTMLElement
@@ -6,11 +6,13 @@ import type {
6
6
  ValEnhancedResult,
7
7
  ReadonlyValEnhancedResult,
8
8
  } from "value-enhancer";
9
+ import { derive } from "value-enhancer";
9
10
  import {
10
11
  combine,
11
12
  Val,
12
13
  withValueEnhancer,
13
14
  withReadonlyValueEnhancer,
15
+ ValManager,
14
16
  } from "value-enhancer";
15
17
  import Emittery from "emittery";
16
18
  import type {
@@ -46,6 +48,7 @@ const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
46
48
  type ReadonlyValConfig = {
47
49
  darkMode: ReadonlyVal<boolean, boolean>;
48
50
  state: ReadonlyVal<TeleBoxState, boolean>;
51
+ root: Val<HTMLElement | null>;
49
52
  rootRect: Val<TeleBoxRect>;
50
53
  stageRect: ReadonlyVal<TeleBoxRect>;
51
54
  };
@@ -67,7 +70,7 @@ export interface TeleBoxManager extends CombinedValEnhancedResult {}
67
70
 
68
71
  export class TeleBoxManager {
69
72
  public constructor({
70
- root = document.body,
73
+ root = null,
71
74
  prefersColorScheme = TELE_BOX_COLOR_SCHEME.Light,
72
75
  minimized = false,
73
76
  maximized = false,
@@ -80,9 +83,12 @@ export class TeleBoxManager {
80
83
  }: TeleBoxManagerConfig = {}) {
81
84
  this._sideEffect = new SideEffectManager();
82
85
 
83
- this.root = root;
84
86
  this.namespace = namespace;
85
87
 
88
+ const valManager = new ValManager();
89
+ this._sideEffect.addDisposer(() => valManager.destroy());
90
+
91
+ const root$ = new Val(root);
86
92
  const readonly$ = new Val(readonly);
87
93
  const minimized$ = new Val(minimized);
88
94
  const maximized$ = new Val(maximized);
@@ -99,11 +105,13 @@ export class TeleBoxManager {
99
105
  },
100
106
  { compare: shallowequal }
101
107
  );
102
- this._sideEffect.add(() => {
103
- const observer = new ResizeObserver((entries) => {
104
- this._sideEffect.setTimeout(
105
- // debounce
106
- () => {
108
+ this._sideEffect.addDisposer(
109
+ root$.subscribe((root) => {
110
+ this._sideEffect.add(() => {
111
+ if (!root) {
112
+ return () => void 0;
113
+ }
114
+ const observer = new ResizeObserver((entries) => {
107
115
  const rect = entries[0]?.contentRect;
108
116
  if (rect) {
109
117
  rootRect$.setValue({
@@ -113,14 +121,12 @@ export class TeleBoxManager {
113
121
  height: rect.height,
114
122
  });
115
123
  }
116
- },
117
- 50,
118
- "root-resize-observer"
119
- );
120
- });
121
- observer.observe(root);
122
- return () => observer.disconnect();
123
- });
124
+ });
125
+ observer.observe(root);
126
+ return () => observer.disconnect();
127
+ }, "calc-root-rect");
128
+ })
129
+ );
124
130
 
125
131
  this.boxes$ = new Val<TeleBox[]>([]);
126
132
  this.topBox$ = new Val<TeleBox | undefined>(undefined);
@@ -190,7 +196,7 @@ export class TeleBoxManager {
190
196
  readonly$: readonly$,
191
197
  darkMode$: darkMode$,
192
198
  namespace,
193
- root,
199
+ root$,
194
200
  rootRect$,
195
201
  });
196
202
 
@@ -198,19 +204,23 @@ export class TeleBoxManager {
198
204
  namespace,
199
205
  rootRect$,
200
206
  ratio$: stageRatio$,
201
- root,
202
- highlightStage$,
207
+ root$,
208
+ highlightStage$: combine(
209
+ [highlightStage$, maximized$],
210
+ ([highlightStage, maximized]) => highlightStage && !maximized
211
+ ),
203
212
  });
204
213
  this._sideEffect.addDisposer(() => teleStage.destroy());
205
214
 
206
215
  const readonlyValConfig: ReadonlyValConfig = {
207
216
  darkMode: darkMode$,
208
217
  state: state$,
218
+ root: root$,
209
219
  rootRect: rootRect$,
210
220
  stageRect: teleStage.stageRect$,
211
221
  };
212
222
 
213
- withReadonlyValueEnhancer(this, readonlyValConfig);
223
+ withReadonlyValueEnhancer(this, readonlyValConfig, valManager);
214
224
 
215
225
  const valConfig: ValConfig = {
216
226
  prefersColorScheme: prefersColorScheme$,
@@ -222,7 +232,7 @@ export class TeleBoxManager {
222
232
  highlightStage: highlightStage$,
223
233
  };
224
234
 
225
- withValueEnhancer(this, valConfig);
235
+ withValueEnhancer(this, valConfig, valManager);
226
236
 
227
237
  const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
228
238
 
@@ -271,10 +281,12 @@ export class TeleBoxManager {
271
281
 
272
282
  this.titleBar = new MaxTitleBar({
273
283
  namespace: this.namespace,
284
+ title$: derive(this.topBox$, (topBox) => topBox?.title || ""),
274
285
  boxes$: this.boxes$,
275
286
  darkMode$: darkMode$,
276
287
  readonly$: readonly$,
277
288
  state$: state$,
289
+ root$,
278
290
  rootRect$: rootRect$,
279
291
  onEvent: (event): void => {
280
292
  switch (event.type) {
@@ -298,8 +310,6 @@ export class TeleBoxManager {
298
310
  },
299
311
  });
300
312
 
301
- this.root.appendChild(this.titleBar.render());
302
-
303
313
  this._sideEffect.addDisposer([
304
314
  state$.reaction((state, skipUpdate) => {
305
315
  if (!skipUpdate) {
@@ -345,8 +355,6 @@ export class TeleBoxManager {
345
355
 
346
356
  protected _sideEffect: SideEffectManager;
347
357
 
348
- protected root: HTMLElement;
349
-
350
358
  public readonly namespace: string;
351
359
 
352
360
  /** @deprecated use setMaximized and setMinimized instead */
@@ -380,6 +388,7 @@ export class TeleBoxManager {
380
388
  ...config,
381
389
  ...(smartPosition ? this.smartPosition(config) : {}),
382
390
  namespace: this.namespace,
391
+ root$: this._root$,
383
392
  darkMode$: this._darkMode$,
384
393
  maximized$: this._maximized$,
385
394
  minimized$: this._minimized$,
@@ -392,8 +401,6 @@ export class TeleBoxManager {
392
401
  managerHighlightStage$: this._highlightStage$,
393
402
  });
394
403
 
395
- box.mount(this.root);
396
-
397
404
  if (box.focus) {
398
405
  this.focusBox(box);
399
406
  if (smartPosition) {
@@ -522,6 +529,20 @@ export class TeleBoxManager {
522
529
  return deletedBoxes;
523
530
  }
524
531
 
532
+ /**
533
+ * Mount manager to a container element.
534
+ */
535
+ public mount(root: HTMLElement): void {
536
+ this._root$.setValue(root);
537
+ }
538
+
539
+ /**
540
+ * Unmount manager from the container element.
541
+ */
542
+ public unmount(): void {
543
+ this._root$.setValue(null);
544
+ }
545
+
525
546
  public destroy(skipUpdate = false): void {
526
547
  this.events.clearListeners();
527
548
  this._sideEffect.flushAll();
@@ -6,7 +6,7 @@ import type { TELE_BOX_MANAGER_EVENT } from "./constants";
6
6
 
7
7
  export interface TeleBoxManagerConfig extends Pick<TeleBoxConfig, "namespace"> {
8
8
  /** Element to mount boxes. */
9
- readonly root?: HTMLElement;
9
+ readonly root?: HTMLElement | null;
10
10
  /** Stage area height/with ratio. No ratio if <= 0. Default -1. */
11
11
  readonly stageRatio?: number;
12
12
  /** Where the minimized boxes go. */
@@ -3,13 +3,12 @@ import "./style.scss";
3
3
  import shallowequal from "shallowequal";
4
4
  import { SideEffectManager } from "side-effect-manager";
5
5
  import type { ReadonlyVal } from "value-enhancer";
6
- import { Val } from "value-enhancer";
7
6
  import { combine } from "value-enhancer";
8
7
  import type { TeleBoxRect } from "../TeleBox/typings";
9
8
 
10
9
  export interface TeleStageConfig {
11
10
  namespace: string;
12
- root?: HTMLElement | null;
11
+ root$: ReadonlyVal<HTMLElement | null>;
13
12
  rootRect$: ReadonlyVal<TeleBoxRect>;
14
13
  ratio$: ReadonlyVal<number>;
15
14
  highlightStage$: ReadonlyVal<boolean>;
@@ -21,7 +20,6 @@ export class TeleStage {
21
20
  public readonly namespace: string;
22
21
  public readonly stageRect$: ReadonlyVal<TeleBoxRect>;
23
22
  public readonly highlightStage$: ReadonlyVal<boolean>;
24
- public readonly root$: Val<HTMLElement | null>;
25
23
 
26
24
  public $boxStage?: HTMLDivElement;
27
25
 
@@ -30,11 +28,10 @@ export class TeleStage {
30
28
  rootRect$,
31
29
  ratio$,
32
30
  highlightStage$,
33
- root = null,
31
+ root$,
34
32
  }: TeleStageConfig) {
35
33
  this.namespace = namespace;
36
34
  this.highlightStage$ = highlightStage$;
37
- this.root$ = new Val<HTMLElement | null>(root);
38
35
 
39
36
  this.stageRect$ = combine(
40
37
  [rootRect$, highlightStage$, ratio$],
@@ -73,7 +70,7 @@ export class TeleStage {
73
70
  );
74
71
 
75
72
  this._sideEffect.addDisposer(
76
- combine([this.root$, highlightStage$]).subscribe(
73
+ combine([root$, highlightStage$]).subscribe(
77
74
  ([root, highlightStage]) => {
78
75
  if (root && highlightStage) {
79
76
  root.appendChild(this.render());
@@ -171,14 +168,6 @@ export class TeleStage {
171
168
  return $boxStage;
172
169
  }
173
170
 
174
- public mount($root: HTMLElement): void {
175
- this.root$.setValue($root);
176
- }
177
-
178
- public unmount(): void {
179
- this.root$.setValue(null);
180
- }
181
-
182
171
  public destroy(): void {
183
172
  this._sideEffect.flushAll();
184
173
  }
@@ -3,7 +3,7 @@
3
3
  .#{$namespace}-box-stage-container {
4
4
  display: none;
5
5
  position: absolute;
6
- z-index: $base-z-index - 1;
6
+ z-index: $base-z-index + 2000;
7
7
  top: 0;
8
8
  left: 0;
9
9
  width: 100%;