@netless/telebox-insider 1.0.0-alpha.2 → 1.0.0-alpha.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.
- package/dist/TeleBox/index.d.ts +4 -2
- package/dist/TeleBoxCollector/index.d.ts +6 -4
- package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +3 -5
- package/dist/TeleTitleBar/typings.d.ts +1 -1
- 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 +2 -2
- package/src/TeleBox/index.ts +32 -10
- package/src/TeleBoxCollector/index.ts +29 -14
- package/src/TeleBoxManager/MaxTitleBar/index.ts +1 -3
- package/src/TeleBoxManager/index.ts +21 -19
- package/src/TeleStage/index.ts +2 -6
- package/src/TeleStage/style.scss +1 -1
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +4 -12
- package/src/TeleTitleBar/typings.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/telebox-insider",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
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.
|
|
66
|
+
"value-enhancer": "^1.2.1"
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/TeleBox/index.ts
CHANGED
|
@@ -9,8 +9,13 @@ import type {
|
|
|
9
9
|
ReadonlyValEnhancedResult,
|
|
10
10
|
ValEnhancedResult,
|
|
11
11
|
} from "value-enhancer";
|
|
12
|
-
import {
|
|
13
|
-
|
|
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
|
|
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<
|
|
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
|
|
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,
|
|
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
|
|
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:
|
|
709
|
-
|
|
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 {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
32
|
+
$collector: Val<HTMLElement>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type PropsValConfig = {
|
|
36
|
+
root: TeleBoxCollectorConfig["root$"];
|
|
29
37
|
};
|
|
30
38
|
|
|
31
|
-
type
|
|
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<
|
|
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
|
-
|
|
71
|
+
$collector: el$,
|
|
62
72
|
};
|
|
63
73
|
|
|
64
|
-
withValueEnhancer(this, valConfig);
|
|
74
|
+
withValueEnhancer(this, valConfig, valManager);
|
|
65
75
|
|
|
66
|
-
const
|
|
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,
|
|
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
|
|
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);
|
|
@@ -107,22 +112,15 @@ export class TeleBoxManager {
|
|
|
107
112
|
return () => void 0;
|
|
108
113
|
}
|
|
109
114
|
const observer = new ResizeObserver((entries) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
height: rect.height,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
50,
|
|
124
|
-
"root-resize-observer"
|
|
125
|
-
);
|
|
115
|
+
const rect = entries[0]?.contentRect;
|
|
116
|
+
if (rect) {
|
|
117
|
+
rootRect$.setValue({
|
|
118
|
+
x: rect.x,
|
|
119
|
+
y: rect.y,
|
|
120
|
+
width: rect.width,
|
|
121
|
+
height: rect.height,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
126
124
|
});
|
|
127
125
|
observer.observe(root);
|
|
128
126
|
return () => observer.disconnect();
|
|
@@ -207,7 +205,10 @@ export class TeleBoxManager {
|
|
|
207
205
|
rootRect$,
|
|
208
206
|
ratio$: stageRatio$,
|
|
209
207
|
root$,
|
|
210
|
-
highlightStage
|
|
208
|
+
highlightStage$: combine(
|
|
209
|
+
[highlightStage$, maximized$],
|
|
210
|
+
([highlightStage, maximized]) => highlightStage && !maximized
|
|
211
|
+
),
|
|
211
212
|
});
|
|
212
213
|
this._sideEffect.addDisposer(() => teleStage.destroy());
|
|
213
214
|
|
|
@@ -219,7 +220,7 @@ export class TeleBoxManager {
|
|
|
219
220
|
stageRect: teleStage.stageRect$,
|
|
220
221
|
};
|
|
221
222
|
|
|
222
|
-
withReadonlyValueEnhancer(this, readonlyValConfig);
|
|
223
|
+
withReadonlyValueEnhancer(this, readonlyValConfig, valManager);
|
|
223
224
|
|
|
224
225
|
const valConfig: ValConfig = {
|
|
225
226
|
prefersColorScheme: prefersColorScheme$,
|
|
@@ -231,7 +232,7 @@ export class TeleBoxManager {
|
|
|
231
232
|
highlightStage: highlightStage$,
|
|
232
233
|
};
|
|
233
234
|
|
|
234
|
-
withValueEnhancer(this, valConfig);
|
|
235
|
+
withValueEnhancer(this, valConfig, valManager);
|
|
235
236
|
|
|
236
237
|
const closeBtnClassName = this.wrapClassName("titlebar-icon-close");
|
|
237
238
|
|
|
@@ -280,6 +281,7 @@ export class TeleBoxManager {
|
|
|
280
281
|
|
|
281
282
|
this.titleBar = new MaxTitleBar({
|
|
282
283
|
namespace: this.namespace,
|
|
284
|
+
title$: derive(this.topBox$, (topBox) => topBox?.title || ""),
|
|
283
285
|
boxes$: this.boxes$,
|
|
284
286
|
darkMode$: darkMode$,
|
|
285
287
|
readonly$: readonly$,
|
package/src/TeleStage/index.ts
CHANGED
|
@@ -34,12 +34,8 @@ export class TeleStage {
|
|
|
34
34
|
this.highlightStage$ = highlightStage$;
|
|
35
35
|
|
|
36
36
|
this.stageRect$ = combine(
|
|
37
|
-
[rootRect$,
|
|
38
|
-
([rootRect,
|
|
39
|
-
if (!highlightStage) {
|
|
40
|
-
return rootRect;
|
|
41
|
-
}
|
|
42
|
-
|
|
37
|
+
[rootRect$, ratio$],
|
|
38
|
+
([rootRect, ratio]) => {
|
|
43
39
|
if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
|
|
44
40
|
return rootRect;
|
|
45
41
|
}
|
package/src/TeleStage/style.scss
CHANGED
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
TeleTitleBarEvent,
|
|
15
15
|
} from "../typings";
|
|
16
16
|
import { preventEvent } from "../../utils";
|
|
17
|
-
import {
|
|
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$ =
|
|
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$:
|
|
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
|
|
13
|
+
title$: ReadonlyVal<string, boolean>;
|
|
14
14
|
state$: ReadonlyVal<TeleBoxState, boolean>;
|
|
15
15
|
namespace?: string;
|
|
16
16
|
onEvent?: (event: TeleTitleBarEvent) => void;
|