@netless/telebox-insider 1.0.0-alpha.3 → 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.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "private": false,
5
5
  "description": "Window widget for Whiteboard",
6
6
  "license": "MIT",
@@ -63,6 +63,6 @@
63
63
  "shallowequal": "^1.1.0",
64
64
  "side-effect-manager": "^1.1.0",
65
65
  "stylefire": "^7.0.3",
66
- "value-enhancer": "^1.1.1"
66
+ "value-enhancer": "^1.2.1"
67
67
  }
68
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 {}
@@ -129,6 +138,9 @@ export class TeleBox {
129
138
  this.id = id;
130
139
  this.namespace = namespace;
131
140
 
141
+ const valManager = new ValManager();
142
+ this._sideEffect.addDisposer(() => valManager.destroy());
143
+
132
144
  const title$ = new Val(title);
133
145
  const visible$ = new Val(visible);
134
146
  const resizable$ = new Val(resizable);
@@ -236,7 +248,7 @@ export class TeleBox {
236
248
  });
237
249
  this._sideEffect.addDisposer(() => teleStage.destroy());
238
250
 
239
- const readonlyValConfig: ReadonlyValConfig = {
251
+ const propsValConfig: PropsValConfig = {
240
252
  darkMode: darkMode$,
241
253
  fence: fence$,
242
254
  minimized: minimized$,
@@ -245,7 +257,11 @@ export class TeleBox {
245
257
  rootRect: rootRect$,
246
258
  managerStageRect: managerStageRect$,
247
259
  collectorRect: collectorRect$,
260
+ };
261
+
262
+ withReadonlyValueEnhancer(this, propsValConfig);
248
263
 
264
+ const myReadonlyValConfig: MyReadonlyValConfig = {
249
265
  zIndex: zIndex$,
250
266
  focus: focus$,
251
267
 
@@ -266,7 +282,7 @@ export class TeleBox {
266
282
  contentStageRect: teleStage.stageRect$,
267
283
  };
268
284
 
269
- withReadonlyValueEnhancer(this, readonlyValConfig);
285
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
270
286
 
271
287
  const valConfig: ValConfig = {
272
288
  title: title$,
@@ -276,14 +292,14 @@ export class TeleBox {
276
292
  ratio: ratio$,
277
293
  };
278
294
 
279
- withValueEnhancer(this, valConfig);
295
+ withValueEnhancer(this, valConfig, valManager);
280
296
 
281
297
  this.titleBar =
282
298
  titleBar ||
283
299
  new DefaultTitleBar({
284
300
  readonly$: readonly$,
285
301
  state$: state$,
286
- title: title$.value,
302
+ title$: title$,
287
303
  namespace: this.namespace,
288
304
  onDragStart: (event) => this._handleTrackStart?.(event),
289
305
  onEvent: (event) => this._delegateEvents.emit(event.type),
@@ -705,8 +721,14 @@ export class TeleBox {
705
721
  ]) => {
706
722
  if (minimized && collectorRect) {
707
723
  return {
708
- x: collectorRect.x + collectorRect.width / 2,
709
- 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,
710
732
  width: pxIntrinsicSize.width + "px",
711
733
  height: pxIntrinsicSize.height + "px",
712
734
  scaleX: collectorRect.width / pxIntrinsicSize.width,
@@ -6,10 +6,14 @@ 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
 
@@ -25,17 +29,20 @@ export interface TeleBoxCollectorConfig {
25
29
 
26
30
  type ValConfig = {
27
31
  styles: Val<TeleStyles>;
28
- el: Val<HTMLElement>;
32
+ $collector: Val<HTMLElement>;
33
+ };
34
+
35
+ type PropsValConfig = {
36
+ root: TeleBoxCollectorConfig["root$"];
29
37
  };
30
38
 
31
- type ReadonlyValConfig = {
39
+ type MyReadonlyValConfig = {
32
40
  rect: ReadonlyVal<TeleBoxRect | undefined>;
33
41
  visible: ReadonlyVal<boolean>;
34
- root: ReadonlyVal<HTMLElement | null>;
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
 
@@ -51,25 +58,33 @@ export class TeleBoxCollector {
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
67
  const el$ = new Val<HTMLElement>(document.createElement("button"));
58
68
 
59
69
  const valConfig: ValConfig = {
60
70
  styles: styles$,
61
- el: el$,
71
+ $collector: el$,
62
72
  };
63
73
 
64
- withValueEnhancer(this, valConfig);
74
+ withValueEnhancer(this, valConfig, valManager);
65
75
 
66
- const readonlyValConfig: ReadonlyValConfig = {
76
+ const propsValConfig: PropsValConfig = {
77
+ root: root$,
78
+ };
79
+
80
+ withReadonlyValueEnhancer(this, propsValConfig);
81
+
82
+ const myReadonlyValConfig: MyReadonlyValConfig = {
67
83
  rect: rect$,
68
84
  visible: visible$,
69
- root: root$,
70
85
  };
71
86
 
72
- withReadonlyValueEnhancer(this, readonlyValConfig);
87
+ withReadonlyValueEnhancer(this, myReadonlyValConfig, valManager);
73
88
 
74
89
  el$.value.className = this.wrapClassName("collector");
75
90
  el$.value.style.backgroundImage = `url('${collectorSVG}')`;
@@ -109,9 +109,7 @@ export class MaxTitleBar extends DefaultTitleBar {
109
109
  this.wrapClassName("max-titlebar-single-title"),
110
110
  titles.length === 1
111
111
  );
112
- if (titles.length === 1) {
113
- this.setTitle(titles[0].title);
114
- } else {
112
+ if (titles.length !== 1) {
115
113
  $titleBar.replaceChild(
116
114
  this.renderTitles(),
117
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 {
@@ -83,6 +85,9 @@ export class TeleBoxManager {
83
85
 
84
86
  this.namespace = namespace;
85
87
 
88
+ const valManager = new ValManager();
89
+ this._sideEffect.addDisposer(() => valManager.destroy());
90
+
86
91
  const root$ = new Val(root);
87
92
  const readonly$ = new Val(readonly);
88
93
  const minimized$ = new Val(minimized);
@@ -215,7 +220,7 @@ export class TeleBoxManager {
215
220
  stageRect: teleStage.stageRect$,
216
221
  };
217
222
 
218
- withReadonlyValueEnhancer(this, readonlyValConfig);
223
+ withReadonlyValueEnhancer(this, readonlyValConfig, valManager);
219
224
 
220
225
  const valConfig: ValConfig = {
221
226
  prefersColorScheme: prefersColorScheme$,
@@ -227,7 +232,7 @@ export class TeleBoxManager {
227
232
  highlightStage: highlightStage$,
228
233
  };
229
234
 
230
- withValueEnhancer(this, valConfig);
235
+ withValueEnhancer(this, valConfig, valManager);
231
236
 
232
237
  const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
233
238
 
@@ -276,6 +281,7 @@ export class TeleBoxManager {
276
281
 
277
282
  this.titleBar = new MaxTitleBar({
278
283
  namespace: this.namespace,
284
+ title$: derive(this.topBox$, (topBox) => topBox?.title || ""),
279
285
  boxes$: this.boxes$,
280
286
  darkMode$: darkMode$,
281
287
  readonly$: readonly$,
@@ -14,7 +14,7 @@ import type {
14
14
  TeleTitleBarEvent,
15
15
  } from "../typings";
16
16
  import { preventEvent } from "../../utils";
17
- import { Val } from "value-enhancer";
17
+ import type { ReadonlyVal } from "value-enhancer";
18
18
 
19
19
  export type DefaultTitleBarButton = TeleTitleBarEvent & {
20
20
  readonly iconClassName: string;
@@ -29,7 +29,7 @@ export class DefaultTitleBar implements TeleTitleBar {
29
29
  public constructor({
30
30
  readonly$,
31
31
  state$,
32
- title = "",
32
+ title$,
33
33
  buttons,
34
34
  onEvent,
35
35
  onDragStart,
@@ -37,7 +37,7 @@ export class DefaultTitleBar implements TeleTitleBar {
37
37
  }: DefaultTitleBarConfig) {
38
38
  this.readonly$ = readonly$;
39
39
  this.state$ = state$;
40
- this.title$ = new Val(title);
40
+ this.title$ = title$;
41
41
  this.onEvent = onEvent;
42
42
  this.onDragStart = onDragStart;
43
43
  this.namespace = namespace;
@@ -67,14 +67,6 @@ export class DefaultTitleBar implements TeleTitleBar {
67
67
 
68
68
  public $dragArea: HTMLElement;
69
69
 
70
- public get title(): string {
71
- return this.title$.value;
72
- }
73
-
74
- public setTitle(title: string): void {
75
- this.title$.setValue(title);
76
- }
77
-
78
70
  public render(): HTMLElement {
79
71
  if (!this.$titleBar) {
80
72
  this.$titleBar = document.createElement("div");
@@ -205,7 +197,7 @@ export class DefaultTitleBar implements TeleTitleBar {
205
197
 
206
198
  protected readonly$: TeleTitleBarConfig["readonly$"];
207
199
 
208
- protected title$: Val<string>;
200
+ protected title$: ReadonlyVal<string>;
209
201
 
210
202
  protected buttons: ReadonlyArray<DefaultTitleBarButton>;
211
203
 
@@ -10,7 +10,7 @@ export type TeleTitleBarEvent<U = keyof TeleBoxDelegateEventConfig> =
10
10
 
11
11
  export interface TeleTitleBarConfig {
12
12
  readonly$: ReadonlyVal<boolean, boolean>;
13
- title?: string;
13
+ title$: ReadonlyVal<string, boolean>;
14
14
  state$: ReadonlyVal<TeleBoxState, boolean>;
15
15
  namespace?: string;
16
16
  onEvent?: (event: TeleTitleBarEvent) => void;