@netless/telebox-insider 0.2.1 → 0.2.5

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.
@@ -3,6 +3,14 @@ import "./style.scss";
3
3
  import EventEmitter from "eventemitter3";
4
4
  import styler from "stylefire";
5
5
  import shallowequal from "shallowequal";
6
+ import { SideEffectManager } from "side-effect-manager";
7
+ import {
8
+ createSideEffectBinder,
9
+ Val,
10
+ ValEnhancedResult,
11
+ ValSideEffectBinder,
12
+ withValueEnhancer,
13
+ } from "value-enhancer";
6
14
  import { DefaultTitleBar, TeleTitleBar } from "../TeleTitleBar";
7
15
  import {
8
16
  clamp,
@@ -29,12 +37,39 @@ import type {
29
37
  TeleBoxCoord,
30
38
  TeleBoxSize,
31
39
  } from "./typings";
32
- import { SideEffectManager } from "side-effect-manager";
33
- import { Val, CombinedVal } from "../Val";
34
40
 
35
41
  export * from "./constants";
36
42
  export * from "./typings";
37
43
 
44
+ type ValConfig = {
45
+ containerRect: Val<TeleBoxRect, boolean>;
46
+ collectorRect: Val<TeleBoxRect | undefined, boolean>;
47
+ /** Box title. Default empty. */
48
+ title: Val<string, boolean>;
49
+ /** Is box visible */
50
+ visible: Val<boolean, boolean>;
51
+ /** Is box readonly */
52
+ readonly: Val<boolean, boolean>;
53
+ /** Able to resize box window */
54
+ resizable: Val<boolean, boolean>;
55
+ /** Able to drag box window */
56
+ draggable: Val<boolean, boolean>;
57
+ /** Restrict box to always be within the containing area. */
58
+ fence: Val<boolean, boolean>;
59
+ /** Fixed width/height ratio for box window. */
60
+ fixRatio: Val<boolean, boolean>;
61
+ focus: Val<boolean, boolean>;
62
+ zIndex: Val<number, boolean>;
63
+ /** Is box minimized. Default false. */
64
+ minimized: Val<boolean, boolean>;
65
+ /** Is box maximized. Default false. */
66
+ maximized: Val<boolean, boolean>;
67
+ $userContent: Val<HTMLElement | undefined>;
68
+ $userFooter: Val<HTMLElement | undefined>;
69
+ $userStyles: Val<HTMLStyleElement | undefined>;
70
+ };
71
+ export interface TeleBox extends ValEnhancedResult<ValConfig> {}
72
+
38
73
  export class TeleBox {
39
74
  public constructor({
40
75
  id = genUniqueKey(),
@@ -69,39 +104,41 @@ export class TeleBox {
69
104
  collectorRect,
70
105
  }: TeleBoxConfig = {}) {
71
106
  this._sideEffect = new SideEffectManager();
107
+ this._valSideEffectBinder = createSideEffectBinder(this._sideEffect);
108
+ const { combine, createVal } = this._valSideEffectBinder;
72
109
 
73
110
  this.id = id;
74
111
  this.namespace = namespace;
75
112
  this.events = new EventEmitter();
76
113
  this._delegateEvents = new EventEmitter();
77
114
 
78
- this._containerRect = new Val(containerRect, shallowequal);
79
- this._collectorRect = new Val(collectorRect, shallowequal);
115
+ const containerRect$ = createVal(containerRect, shallowequal);
116
+ const collectorRect$ = createVal(collectorRect, shallowequal);
80
117
 
81
- this._title = new Val(title);
118
+ const title$ = createVal(title);
82
119
 
83
- this._visible = new Val(visible);
84
- this._visible.reaction((visible, skipUpdate) => {
120
+ const visible$ = createVal(visible);
121
+ visible$.reaction((visible, _, skipUpdate) => {
85
122
  if (!skipUpdate && !visible) {
86
123
  this.events.emit(TELE_BOX_EVENT.Close);
87
124
  }
88
125
  });
89
126
 
90
- this._readonly = new Val(readonly);
91
- this._readonly.reaction((readonly, skipUpdate) => {
127
+ const readonly$ = createVal(readonly);
128
+ readonly$.reaction((readonly, _, skipUpdate) => {
92
129
  if (!skipUpdate) {
93
130
  this.events.emit(TELE_BOX_EVENT.Readonly, readonly);
94
131
  }
95
132
  });
96
133
 
97
- this._resizable = new Val(resizable);
98
- this._draggable = new Val(draggable);
99
- this._fence = new Val(fence);
100
- this._fixRatio = new Val(fixRatio);
101
- this._zIndex = new Val(zIndex);
134
+ const resizable$ = createVal(resizable);
135
+ const draggable$ = createVal(draggable);
136
+ const fence$ = createVal(fence);
137
+ const fixRatio$ = createVal(fixRatio);
138
+ const zIndex$ = createVal(zIndex);
102
139
 
103
- this._focus = new Val(focus);
104
- this._focus.reaction((focus, skipUpdate) => {
140
+ const focus$ = createVal(focus);
141
+ focus$.reaction((focus, _, skipUpdate) => {
105
142
  if (!skipUpdate) {
106
143
  this.events.emit(
107
144
  focus ? TELE_BOX_EVENT.Focus : TELE_BOX_EVENT.Blur
@@ -109,22 +146,22 @@ export class TeleBox {
109
146
  }
110
147
  });
111
148
 
112
- this._minimized = new Val(minimized);
113
- this._minimized.reaction((minimized, skipUpdate) => {
149
+ const minimized$ = createVal(minimized);
150
+ minimized$.reaction((minimized, _, skipUpdate) => {
114
151
  if (!skipUpdate) {
115
152
  this.events.emit(TELE_BOX_EVENT.Minimized, minimized);
116
153
  }
117
154
  });
118
155
 
119
- this._maximized = new Val(maximized);
120
- this._maximized.reaction((maximized, skipUpdate) => {
156
+ const maximized$ = createVal(maximized);
157
+ maximized$.reaction((maximized, _, skipUpdate) => {
121
158
  if (!skipUpdate) {
122
159
  this.events.emit(TELE_BOX_EVENT.Maximized, maximized);
123
160
  }
124
161
  });
125
162
 
126
- this._state = new CombinedVal(
127
- [this._minimized, this._maximized],
163
+ const state$ = combine(
164
+ [minimized$, maximized$],
128
165
  ([minimized, maximized]): TeleBoxState =>
129
166
  minimized
130
167
  ? TELE_BOX_STATE.Minimized
@@ -132,13 +169,13 @@ export class TeleBox {
132
169
  ? TELE_BOX_STATE.Maximized
133
170
  : TELE_BOX_STATE.Normal
134
171
  );
135
- this._state.reaction((state, skipUpdate) => {
172
+ state$.reaction((state, _, skipUpdate) => {
136
173
  if (!skipUpdate) {
137
174
  this.events.emit(TELE_BOX_EVENT.State, state);
138
175
  }
139
176
  });
140
177
 
141
- this._minSize = new Val(
178
+ const minSize$ = createVal(
142
179
  {
143
180
  width: clamp(minWidth, 0, 1),
144
181
  height: clamp(minHeight, 0, 1),
@@ -146,15 +183,15 @@ export class TeleBox {
146
183
  shallowequal
147
184
  );
148
185
 
149
- this._intrinsicSize = new Val(
186
+ const intrinsicSize$ = createVal(
150
187
  {
151
- width: clamp(width, this._minSize.value.width, 1),
152
- height: clamp(height, this._minSize.value.height, 1),
188
+ width: clamp(width, minSize$.value.width, 1),
189
+ height: clamp(height, minSize$.value.height, 1),
153
190
  },
154
191
  shallowequal
155
192
  );
156
- this._minSize.reaction((minSize, skipUpdate) => {
157
- this._intrinsicSize.setValue(
193
+ minSize$.reaction((minSize, _, skipUpdate) => {
194
+ intrinsicSize$.setValue(
158
195
  {
159
196
  width: clamp(width, minSize.width, 1),
160
197
  height: clamp(height, minSize.height, 1),
@@ -162,14 +199,14 @@ export class TeleBox {
162
199
  skipUpdate
163
200
  );
164
201
  });
165
- this._intrinsicSize.reaction((size, skipUpdate) => {
202
+ intrinsicSize$.reaction((size, _, skipUpdate) => {
166
203
  if (!skipUpdate) {
167
204
  this.events.emit(TELE_BOX_EVENT.IntrinsicResize, size);
168
205
  }
169
206
  });
170
207
 
171
- this._size = new CombinedVal(
172
- [this._intrinsicSize, this._maximized],
208
+ const size$ = combine(
209
+ [intrinsicSize$, maximized$],
173
210
  ([intrinsicSize, maximized]) => {
174
211
  if (maximized) {
175
212
  return { width: 1, height: 1 };
@@ -178,19 +215,14 @@ export class TeleBox {
178
215
  },
179
216
  shallowequal
180
217
  );
181
- this._size.reaction((size, skipUpdate) => {
218
+ size$.reaction((size, _, skipUpdate) => {
182
219
  if (!skipUpdate) {
183
220
  this.events.emit(TELE_BOX_EVENT.Resize, size);
184
221
  }
185
222
  });
186
223
 
187
- this._visualSize = new CombinedVal(
188
- [
189
- this._size,
190
- this._minimized,
191
- this._containerRect,
192
- this._collectorRect,
193
- ],
224
+ const visualSize$ = combine(
225
+ [size$, minimized$, containerRect$, collectorRect$],
194
226
  ([size, minimized, containerRect, collectorRect]) => {
195
227
  if (minimized && collectorRect) {
196
228
  return {
@@ -208,30 +240,30 @@ export class TeleBox {
208
240
  },
209
241
  shallowequal
210
242
  );
211
- this._visualSize.reaction((size, skipUpdate) => {
243
+ visualSize$.reaction((size, _, skipUpdate) => {
212
244
  if (!skipUpdate) {
213
245
  this.events.emit(TELE_BOX_EVENT.VisualResize, size);
214
246
  }
215
247
  });
216
248
 
217
- this._intrinsicCoord = new Val(
249
+ const intrinsicCoord$ = createVal(
218
250
  { x: clamp(x, 0, 1), y: clamp(y, 0, 1) },
219
251
  shallowequal
220
252
  );
221
- this._intrinsicCoord.reaction((coord, skipUpdate) => {
253
+ intrinsicCoord$.reaction((coord, _, skipUpdate) => {
222
254
  if (!skipUpdate) {
223
255
  this.events.emit(TELE_BOX_EVENT.IntrinsicMove, coord);
224
256
  }
225
257
  });
226
258
 
227
- this._coord = new CombinedVal(
259
+ const coord$ = combine(
228
260
  [
229
- this._intrinsicCoord,
230
- this._intrinsicSize,
231
- this._containerRect,
232
- this._collectorRect,
233
- this._minimized,
234
- this._maximized,
261
+ intrinsicCoord$,
262
+ intrinsicSize$,
263
+ containerRect$,
264
+ collectorRect$,
265
+ minimized$,
266
+ maximized$,
235
267
  ],
236
268
  ([
237
269
  intrinsicCoord,
@@ -272,7 +304,7 @@ export class TeleBox {
272
304
  },
273
305
  shallowequal
274
306
  );
275
- this._coord.reaction((coord, skipUpdate) => {
307
+ coord$.reaction((coord, _, skipUpdate) => {
276
308
  if (!skipUpdate) {
277
309
  this.events.emit(TELE_BOX_EVENT.Move, coord);
278
310
  }
@@ -281,8 +313,8 @@ export class TeleBox {
281
313
  this.titleBar =
282
314
  titleBar ||
283
315
  new DefaultTitleBar({
284
- readonly: this.readonly,
285
- title: this.title,
316
+ readonly: readonly$.value,
317
+ title: title$.value,
286
318
  namespace: this.namespace,
287
319
  onDragStart: (event) => this._handleTrackStart?.(event),
288
320
  onEvent: (event): void => {
@@ -291,15 +323,15 @@ export class TeleBox {
291
323
  } else {
292
324
  switch (event.type) {
293
325
  case TELE_BOX_DELEGATE_EVENT.Maximize: {
294
- this._maximized.setValue(!this._maximized);
326
+ maximized$.setValue(!maximized$.value);
295
327
  break;
296
328
  }
297
329
  case TELE_BOX_DELEGATE_EVENT.Minimize: {
298
- this._minimized.setValue(true);
330
+ minimized$.setValue(true);
299
331
  break;
300
332
  }
301
333
  case TELE_BOX_DELEGATE_EVENT.Close: {
302
- this._visible.setValue(false);
334
+ visible$.setValue(false);
303
335
  break;
304
336
  }
305
337
  default: {
@@ -313,16 +345,51 @@ export class TeleBox {
313
345
  }
314
346
  },
315
347
  });
316
- this._readonly.reaction((readonly) => {
348
+ readonly$.reaction((readonly) => {
317
349
  this.titleBar.setReadonly(readonly);
318
350
  });
319
351
 
320
- this._$userContent = new Val(content);
321
- this._$userFooter = new Val(footer);
322
- this._$userStyles = new Val(styles);
352
+ const $userContent$ = createVal(content);
353
+ const $userFooter$ = createVal(footer);
354
+ const $userStyles$ = createVal(styles);
355
+
356
+ const valConfig: ValConfig = {
357
+ containerRect: containerRect$,
358
+ collectorRect: collectorRect$,
359
+ title: title$,
360
+ visible: visible$,
361
+ readonly: readonly$,
362
+ resizable: resizable$,
363
+ draggable: draggable$,
364
+ fence: fence$,
365
+ fixRatio: fixRatio$,
366
+ focus: focus$,
367
+ zIndex: zIndex$,
368
+ minimized: minimized$,
369
+ maximized: maximized$,
370
+ $userContent: $userContent$,
371
+ $userFooter: $userFooter$,
372
+ $userStyles: $userStyles$,
373
+ };
374
+
375
+ withValueEnhancer(this, valConfig);
376
+
377
+ this._state$ = state$;
378
+ this._minSize$ = minSize$;
379
+ this._size$ = size$;
380
+ this._intrinsicSize$ = intrinsicSize$;
381
+ this._visualSize$ = visualSize$;
382
+ this._coord$ = coord$;
383
+ this._intrinsicCoord$ = intrinsicCoord$;
323
384
 
324
385
  if (this.fixRatio) {
325
- this.transform(this.x, this.y, this.width, this.height, true);
386
+ this.transform(
387
+ coord$.value.x,
388
+ coord$.value.y,
389
+ size$.value.width,
390
+ size$.value.height,
391
+ true
392
+ );
326
393
  }
327
394
 
328
395
  this.$box = this.render();
@@ -330,7 +397,7 @@ export class TeleBox {
330
397
 
331
398
  public readonly id: string;
332
399
 
333
- /** Classname Prefix. For CSS styling. Default "telebox" */
400
+ /** ClassName Prefix. For CSS styling. Default "telebox" */
334
401
  public readonly namespace: string;
335
402
 
336
403
  public readonly events: TeleBoxEvents;
@@ -339,167 +406,21 @@ export class TeleBox {
339
406
 
340
407
  protected _sideEffect: SideEffectManager;
341
408
 
342
- public titleBar: TeleTitleBar;
343
-
344
- protected _containerRect: Val<TeleBoxRect, boolean>;
345
-
346
- public get containerRect(): TeleBoxRect {
347
- return this._containerRect.value;
348
- }
349
-
350
- public setContainerRect(rect: TeleBoxRect, skipUpdate = false): this {
351
- this._containerRect.setValue(rect, skipUpdate);
352
- return this;
353
- }
354
-
355
- protected _collectorRect: Val<TeleBoxRect | undefined, boolean>;
356
-
357
- public get collectorRect(): TeleBoxRect | undefined {
358
- return this._collectorRect.value;
359
- }
360
-
361
- public setCollectorRect(rect: TeleBoxRect, skipUpdate = false): this {
362
- this._collectorRect.setValue(rect, skipUpdate);
363
- return this;
364
- }
365
-
366
- protected _title: Val<string, boolean>;
367
-
368
- /** Box title. Default empty. */
369
- public get title(): string {
370
- return this._title.value;
371
- }
372
-
373
- /**
374
- * Update box title.
375
- * @param title new box title
376
- * @returns this
377
- */
378
- public setTitle(title: string): this {
379
- this._title.setValue(title);
380
- return this;
381
- }
382
-
383
- protected _visible: Val<boolean, boolean>;
384
-
385
- public get visible(): boolean {
386
- return this._visible.value;
387
- }
388
-
389
- public setVisible(visible: boolean, skipUpdate = false): this {
390
- this._visible.setValue(visible, skipUpdate);
391
- return this;
392
- }
393
-
394
- protected _readonly: Val<boolean, boolean>;
395
-
396
- /** Is box readonly */
397
- public get readonly(): boolean {
398
- return this._readonly.value;
399
- }
400
-
401
- public setReadonly(readonly: boolean, skipUpdate = false): this {
402
- this._readonly.setValue(readonly, skipUpdate);
403
- return this;
404
- }
405
-
406
- protected _resizable: Val<boolean, boolean>;
407
-
408
- /** Able to resize box window */
409
- public get resizable(): boolean {
410
- return this._resizable.value;
411
- }
412
-
413
- public setResizable(resizable: boolean, skipUpdate = false): this {
414
- this._resizable.setValue(resizable, skipUpdate);
415
- return this;
416
- }
417
-
418
- protected _draggable: Val<boolean, boolean>;
419
-
420
- /** Able to drag box window */
421
- public get draggable(): boolean {
422
- return this._draggable.value;
423
- }
424
-
425
- public setDraggable(draggable: boolean, skipUpdate = false): this {
426
- this._draggable.setValue(draggable, skipUpdate);
427
- return this;
428
- }
429
-
430
- protected _fence: Val<boolean, boolean>;
409
+ protected _valSideEffectBinder: ValSideEffectBinder;
431
410
 
432
- /** Restrict box to always be within the containing area. */
433
- public get fence(): boolean {
434
- return this._fence.value;
435
- }
436
-
437
- public setFence(fence: boolean, skipUpdate = false): this {
438
- this._fence.setValue(fence, skipUpdate);
439
- return this;
440
- }
441
-
442
- protected _fixRatio: Val<boolean, boolean>;
443
-
444
- /** Fixed width/height ratio for box window. */
445
- public get fixRatio(): boolean {
446
- return this._fixRatio.value;
447
- }
448
-
449
- public setFixRatio(fixRatio: boolean, skipUpdate = false): this {
450
- this._fixRatio.setValue(fixRatio, skipUpdate);
451
- return this;
452
- }
453
-
454
- protected _focus: Val<boolean, boolean>;
455
-
456
- public get focus(): boolean {
457
- return this._focus.value;
458
- }
459
-
460
- public setFocus(focus: boolean, skipUpdate = false): this {
461
- this._focus.setValue(focus, skipUpdate);
462
- return this;
463
- }
464
-
465
- protected _zIndex: Val<number, boolean>;
466
-
467
- public get zIndex(): number {
468
- return this._zIndex.value;
469
- }
470
-
471
- public setZIndex(zIndex: number, skipUpdate = false): this {
472
- this._zIndex.setValue(zIndex, skipUpdate);
473
- return this;
474
- }
475
-
476
- protected _minimized: Val<boolean, boolean>;
477
-
478
- public get minimized(): boolean {
479
- return this._minimized.value;
480
- }
481
-
482
- public setMinimized(minimized: boolean, skipUpdate = false): this {
483
- this._minimized.setValue(minimized, skipUpdate);
484
- return this;
485
- }
411
+ public titleBar: TeleTitleBar;
486
412
 
487
- protected _maximized: Val<boolean, boolean>;
413
+ public _minSize$: Val<TeleBoxSize, boolean>;
414
+ public _size$: Val<TeleBoxSize, boolean>;
415
+ public _intrinsicSize$: Val<TeleBoxSize, boolean>;
416
+ public _visualSize$: Val<TeleBoxSize, boolean>;
417
+ public _coord$: Val<TeleBoxCoord, boolean>;
418
+ public _intrinsicCoord$: Val<TeleBoxCoord, boolean>;
488
419
 
489
- public get maximized(): boolean {
490
- return this._maximized.value;
491
- }
420
+ public _state$: Val<TeleBoxState, boolean>;
492
421
 
493
- public setMaximized(maximized: boolean, skipUpdate = false): this {
494
- this._maximized.setValue(maximized, skipUpdate);
495
- return this;
496
- }
497
-
498
- protected _state: Val<TeleBoxState, boolean>;
499
-
500
- /** Is box maximized. Default false. */
501
422
  public get state(): TeleBoxState {
502
- return this._state.value;
423
+ return this._state$.value;
503
424
  }
504
425
 
505
426
  /** @deprecated use setMaximized and setMinimized instead */
@@ -524,21 +445,14 @@ export class TeleBox {
524
445
  return this;
525
446
  }
526
447
 
527
- protected _minSize: Val<TeleBoxSize, boolean>;
528
-
529
448
  /** Minimum box width relative to container element. 0~1. Default 0. */
530
449
  public get minWidth(): number {
531
- return this._minSize.value.width;
450
+ return this._minSize$.value.width;
532
451
  }
533
452
 
534
453
  /** Minimum box height relative to container element. 0~1. Default 0. */
535
454
  public get minHeight(): number {
536
- return this._minSize.value.height;
537
- }
538
-
539
- public setMinSize(size: TeleBoxSize, skipUpdate = false): this {
540
- this._minSize.setValue(size, skipUpdate);
541
- return this;
455
+ return this._minSize$.value.height;
542
456
  }
543
457
 
544
458
  /**
@@ -546,7 +460,7 @@ export class TeleBox {
546
460
  * @returns this
547
461
  */
548
462
  public setMinWidth(minWidth: number, skipUpdate = false): this {
549
- this._minSize.setValue(
463
+ this._minSize$.setValue(
550
464
  { width: minWidth, height: this.minHeight },
551
465
  skipUpdate
552
466
  );
@@ -558,28 +472,21 @@ export class TeleBox {
558
472
  * @returns this
559
473
  */
560
474
  public setMinHeight(minHeight: number, skipUpdate = false): this {
561
- this._minSize.setValue(
475
+ this._minSize$.setValue(
562
476
  { width: this.minWidth, height: minHeight },
563
477
  skipUpdate
564
478
  );
565
479
  return this;
566
480
  }
567
481
 
568
- protected _intrinsicSize: Val<TeleBoxSize, boolean>;
569
-
570
482
  /** Intrinsic box width relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.5. */
571
483
  public get intrinsicWidth(): number {
572
- return this._intrinsicSize.value.width;
484
+ return this._intrinsicSize$.value.width;
573
485
  }
574
486
 
575
487
  /** Intrinsic box height relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.5. */
576
488
  public get intrinsicHeight(): number {
577
- return this._intrinsicSize.value.height;
578
- }
579
-
580
- public setIntrinsicSize(size: TeleBoxSize, skipUpdate = false): this {
581
- this._intrinsicSize.setValue(size, skipUpdate);
582
- return this;
489
+ return this._intrinsicSize$.value.height;
583
490
  }
584
491
 
585
492
  /**
@@ -590,20 +497,18 @@ export class TeleBox {
590
497
  * @returns this
591
498
  */
592
499
  public resize(width: number, height: number, skipUpdate = false): this {
593
- this._intrinsicSize.setValue({ width, height }, skipUpdate);
500
+ this._intrinsicSize$.setValue({ width, height }, skipUpdate);
594
501
  return this;
595
502
  }
596
503
 
597
- protected _size: Val<TeleBoxSize, boolean>;
598
-
599
504
  /** Box width relative to container element. 0~1. Default 0.5. */
600
505
  public get width(): number {
601
- return this._size.value.width;
506
+ return this._size$.value.width;
602
507
  }
603
508
 
604
509
  /** Box height relative to container element. 0~1. Default 0.5. */
605
510
  public get height(): number {
606
- return this._size.value.height;
511
+ return this._size$.value.height;
607
512
  }
608
513
 
609
514
  /** Box width in pixels. */
@@ -616,33 +521,24 @@ export class TeleBox {
616
521
  return this.height * this.containerRect.height;
617
522
  }
618
523
 
619
- protected _visualSize: Val<TeleBoxSize, boolean>;
620
-
621
524
  /** Actual rendered box width relative to container element. 0~1. Default 0.5. */
622
525
  public get visualWidth(): number {
623
- return this._visualSize.value.width;
526
+ return this._visualSize$.value.width;
624
527
  }
625
528
 
626
529
  /** Actual rendered box height relative to container element. 0~1. Default 0.5. */
627
530
  public get visualHeight(): number {
628
- return this._visualSize.value.height;
531
+ return this._visualSize$.value.height;
629
532
  }
630
533
 
631
- protected _intrinsicCoord: Val<TeleBoxCoord, boolean>;
632
-
633
534
  /** Intrinsic box x position relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.1. */
634
535
  public get intrinsicX(): number {
635
- return this._intrinsicCoord.value.x;
536
+ return this._intrinsicCoord$.value.x;
636
537
  }
637
538
 
638
539
  /** Intrinsic box y position relative to container element(without counting the effect of maximization or minimization). 0~1. Default 0.1. */
639
540
  public get intrinsicY(): number {
640
- return this._intrinsicCoord.value.y;
641
- }
642
-
643
- public setIntrinsicCoord(coord: TeleBoxCoord, skipUpdate = false): this {
644
- this._intrinsicCoord.setValue(coord, skipUpdate);
645
- return this;
541
+ return this._intrinsicCoord$.value.y;
646
542
  }
647
543
 
648
544
  /**
@@ -653,20 +549,18 @@ export class TeleBox {
653
549
  * @returns this
654
550
  */
655
551
  public move(x: number, y: number, skipUpdate = false): this {
656
- this._intrinsicCoord.setValue({ x, y }, skipUpdate);
552
+ this._intrinsicCoord$.setValue({ x, y }, skipUpdate);
657
553
  return this;
658
554
  }
659
555
 
660
- protected _coord: Val<TeleBoxCoord, boolean>;
661
-
662
556
  /** Box x position relative to container element. 0~1. Default 0.1. */
663
557
  public get x(): number {
664
- return this._coord.value.x;
558
+ return this._coord$.value.x;
665
559
  }
666
560
 
667
561
  /** Box y position relative to container element. 0~1. Default 0.1. */
668
562
  public get y(): number {
669
- return this._coord.value.y;
563
+ return this._coord$.value.y;
670
564
  }
671
565
 
672
566
  /**
@@ -701,14 +595,14 @@ export class TeleBox {
701
595
  }
702
596
  }
703
597
 
704
- this.setIntrinsicCoord(
598
+ this._intrinsicCoord$.setValue(
705
599
  {
706
600
  x: width >= this.minWidth ? x : this.intrinsicX,
707
601
  y: height >= this.minHeight ? y : this.intrinsicY,
708
602
  },
709
603
  skipUpdate
710
604
  );
711
- this.setIntrinsicSize(
605
+ this._intrinsicSize$.setValue(
712
606
  {
713
607
  width: clamp(width, this.minWidth, 1),
714
608
  height: clamp(height, this.minHeight, 1),
@@ -719,12 +613,6 @@ export class TeleBox {
719
613
  return this;
720
614
  }
721
615
 
722
- protected _$userContent: Val<HTMLElement | undefined>;
723
-
724
- public get $userContent(): HTMLElement | undefined {
725
- return this._$userContent.value;
726
- }
727
-
728
616
  /**
729
617
  * Mount box to a container element.
730
618
  */
@@ -747,7 +635,7 @@ export class TeleBox {
747
635
  * Mount dom to box content.
748
636
  */
749
637
  public mountContent(content: HTMLElement): this {
750
- this._$userContent.setValue(content);
638
+ this.set$userContent(content);
751
639
  return this;
752
640
  }
753
641
 
@@ -755,21 +643,15 @@ export class TeleBox {
755
643
  * Unmount content from the box.
756
644
  */
757
645
  public unmountContent(): this {
758
- this._$userContent.setValue(undefined);
646
+ this.set$userContent(undefined);
759
647
  return this;
760
648
  }
761
649
 
762
- protected _$userFooter: Val<HTMLElement | undefined>;
763
-
764
- public get $userFooter(): HTMLElement | undefined {
765
- return this._$userFooter.value;
766
- }
767
-
768
650
  /**
769
651
  * Mount dom to box Footer.
770
652
  */
771
653
  public mountFooter(footer: HTMLElement): this {
772
- this._$userFooter.setValue(footer);
654
+ this.set$userFooter(footer);
773
655
  return this;
774
656
  }
775
657
 
@@ -777,14 +659,12 @@ export class TeleBox {
777
659
  * Unmount Footer from the box.
778
660
  */
779
661
  public unmountFooter(): this {
780
- this._$userFooter.setValue(undefined);
662
+ this.set$userFooter(undefined);
781
663
  return this;
782
664
  }
783
665
 
784
- protected _$userStyles: Val<HTMLStyleElement | undefined>;
785
-
786
666
  public getUserStyles(): HTMLStyleElement | undefined {
787
- return this._$userStyles.value;
667
+ return this.$userStyles;
788
668
  }
789
669
 
790
670
  public mountStyles(styles: string | HTMLStyleElement): this {
@@ -795,12 +675,12 @@ export class TeleBox {
795
675
  } else {
796
676
  $styles = styles;
797
677
  }
798
- this._$userStyles.setValue($styles);
678
+ this.set$userStyles($styles);
799
679
  return this;
800
680
  }
801
681
 
802
682
  public unmountStyles(): this {
803
- this._$userStyles.setValue(undefined);
683
+ this.set$userStyles(undefined);
804
684
  return this;
805
685
  }
806
686
 
@@ -810,6 +690,9 @@ export class TeleBox {
810
690
  /** DOM of the box content */
811
691
  public $content!: HTMLElement;
812
692
 
693
+ /** DOM of the box title bar */
694
+ public $titleBar!: HTMLElement;
695
+
813
696
  /** DOM of the box footer */
814
697
  public $footer!: HTMLElement;
815
698
 
@@ -848,17 +731,17 @@ export class TeleBox {
848
731
  });
849
732
  };
850
733
 
851
- bindClassName(this.$box, this._readonly, "readonly");
852
- bindClassName(this.$box, this._draggable, "no-drag", isFalsy);
853
- bindClassName(this.$box, this._resizable, "no-resize", isFalsy);
854
- bindClassName(this.$box, this._focus, "blur", isFalsy);
734
+ bindClassName(this.$box, this._readonly$, "readonly");
735
+ bindClassName(this.$box, this._draggable$, "no-drag", isFalsy);
736
+ bindClassName(this.$box, this._resizable$, "no-resize", isFalsy);
737
+ bindClassName(this.$box, this._focus$, "blur", isFalsy);
855
738
 
856
739
  this._renderSideEffect.add(() => {
857
740
  const minimizedClassName = this.wrapClassName("minimized");
858
741
  const maximizedClassName = this.wrapClassName("maximized");
859
742
  const MAXIMIZED_TIMER_ID = "box-maximized-timer";
860
743
 
861
- return this._state.subscribe((state) => {
744
+ return this._state$.subscribe((state) => {
862
745
  this.$box.classList.toggle(
863
746
  minimizedClassName,
864
747
  state === TELE_BOX_STATE.Minimized
@@ -884,13 +767,13 @@ export class TeleBox {
884
767
  });
885
768
 
886
769
  this._renderSideEffect.add(() =>
887
- this._visible.subscribe((visible) => {
770
+ this._visible$.subscribe((visible) => {
888
771
  this.$box.style.display = visible ? "block" : "none";
889
772
  })
890
773
  );
891
774
 
892
775
  this._renderSideEffect.add(() =>
893
- this._zIndex.subscribe((zIndex) => {
776
+ this._zIndex$.subscribe((zIndex) => {
894
777
  this.$box.style.zIndex = String(zIndex);
895
778
  })
896
779
  );
@@ -911,14 +794,14 @@ export class TeleBox {
911
794
  translateY - 10
912
795
  }px)`;
913
796
 
914
- this._renderSideEffect.add(() => {
915
- const combined = new CombinedVal(
797
+ this._valSideEffectBinder
798
+ .combine(
916
799
  [
917
- this._coord,
918
- this._size,
919
- this._minimized,
920
- this._containerRect,
921
- this._collectorRect,
800
+ this._coord$,
801
+ this._size$,
802
+ this._minimized$,
803
+ this._containerRect$,
804
+ this._collectorRect$,
922
805
  ],
923
806
  ([coord, size, minimized, containerRect, collectorRect]) => {
924
807
  const absoluteWidth = size.width * containerRect.width;
@@ -939,17 +822,11 @@ export class TeleBox {
939
822
  };
940
823
  },
941
824
  shallowequal
942
- );
943
-
944
- combined.subscribe((styles) => {
825
+ )
826
+ .subscribe((styles) => {
945
827
  boxStyler.set(styles);
946
828
  });
947
829
 
948
- return () => {
949
- combined.destroy();
950
- };
951
- });
952
-
953
830
  boxStyler.set({ x: translateX, y: translateY });
954
831
 
955
832
  const $boxMain = document.createElement("div");
@@ -959,6 +836,7 @@ export class TeleBox {
959
836
  const $titleBar = document.createElement("div");
960
837
  $titleBar.className = this.wrapClassName("titlebar-wrap");
961
838
  $titleBar.appendChild(this.titleBar.render());
839
+ this.$titleBar = $titleBar;
962
840
 
963
841
  const $contentWrap = document.createElement("div");
964
842
  $contentWrap.className = this.wrapClassName("content-wrap");
@@ -970,7 +848,7 @@ export class TeleBox {
970
848
 
971
849
  this._renderSideEffect.add(() => {
972
850
  let last$userStyles: HTMLStyleElement | undefined;
973
- return this._$userStyles.subscribe(($userStyles) => {
851
+ return this._$userStyles$.subscribe(($userStyles) => {
974
852
  if (last$userStyles) {
975
853
  last$userStyles.remove();
976
854
  }
@@ -983,7 +861,7 @@ export class TeleBox {
983
861
 
984
862
  this._renderSideEffect.add(() => {
985
863
  let last$userContent: HTMLElement | undefined;
986
- return this._$userContent.subscribe(($userContent) => {
864
+ return this._$userContent$.subscribe(($userContent) => {
987
865
  if (last$userContent) {
988
866
  last$userContent.remove();
989
867
  }
@@ -1002,13 +880,13 @@ export class TeleBox {
1002
880
 
1003
881
  this._renderSideEffect.add(() => {
1004
882
  let last$userFooter: HTMLElement | undefined;
1005
- return this._$userFooter.subscribe(($userFooter) => {
883
+ return this._$userFooter$.subscribe(($userFooter) => {
1006
884
  if (last$userFooter) {
1007
885
  last$userFooter.remove();
1008
886
  }
1009
887
  last$userFooter = $userFooter;
1010
888
  if ($userFooter) {
1011
- $content.appendChild($userFooter);
889
+ $footer.appendChild($userFooter);
1012
890
  }
1013
891
  });
1014
892
  });
@@ -1152,7 +1030,7 @@ export class TeleBox {
1152
1030
  break;
1153
1031
  }
1154
1032
  default: {
1155
- if (this._fence) {
1033
+ if (this.fence) {
1156
1034
  this.move(
1157
1035
  clamp(trackStartX + offsetX, 0, 1 - this.width),
1158
1036
  clamp(trackStartY + offsetY, 0, 1 - this.height)
@@ -1296,12 +1174,6 @@ export class TeleBox {
1296
1174
  this._renderSideEffect.flushAll();
1297
1175
  this.events.removeAllListeners();
1298
1176
  this._delegateEvents.removeAllListeners();
1299
- Object.keys(this).forEach((key) => {
1300
- const value = this[key as keyof this];
1301
- if (value instanceof Val) {
1302
- value.destroy();
1303
- }
1304
- });
1305
1177
  }
1306
1178
 
1307
1179
  /**