@netless/telebox-insider 0.2.26 → 1.0.0-alpha.3
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/constants.d.ts +0 -3
- package/dist/TeleBox/index.d.ts +118 -97
- package/dist/TeleBox/typings.d.ts +42 -55
- package/dist/TeleBoxCollector/index.d.ts +25 -29
- package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +14 -18
- package/dist/TeleBoxManager/constants.d.ts +0 -3
- package/dist/TeleBoxManager/index.d.ts +64 -19
- package/dist/TeleBoxManager/typings.d.ts +35 -28
- package/dist/TeleStage/index.d.ts +21 -0
- package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +6 -8
- package/dist/TeleTitleBar/typings.d.ts +3 -5
- package/dist/index.d.ts +0 -1
- package/dist/style.css +1 -1
- package/dist/telebox-insider.cjs.js +1 -15
- package/dist/telebox-insider.cjs.js.map +1 -1
- package/dist/telebox-insider.es.js +1 -15
- package/dist/telebox-insider.es.js.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/package.json +7 -19
- package/src/TeleBox/constants.ts +0 -3
- package/src/TeleBox/index.ts +500 -690
- package/src/TeleBox/style.scss +1 -0
- package/src/TeleBox/typings.ts +42 -75
- package/src/TeleBoxCollector/index.ts +136 -159
- package/src/TeleBoxManager/MaxTitleBar/index.ts +95 -108
- package/src/TeleBoxManager/constants.ts +0 -3
- package/src/TeleBoxManager/index.ts +325 -336
- package/src/TeleBoxManager/typings.ts +42 -52
- package/src/TeleStage/index.ts +178 -0
- package/src/TeleStage/style.scss +49 -0
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +48 -61
- package/src/TeleTitleBar/typings.ts +3 -9
- package/src/index.ts +0 -1
- package/src/utils.ts +0 -6
- package/dist/TeleBoxCollector/TeleBoxCollector.stories.d.ts +0 -5
- package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.d.ts +0 -7
- package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.d.ts +0 -4
- package/dist/TeleBoxReact/TeleBox.stories.d.ts +0 -9
- package/dist/TeleBoxReact/index.d.ts +0 -17
- package/dist/TeleBoxReact/utils.d.ts +0 -2
- package/dist/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.d.ts +0 -4
- package/src/TeleBoxCollector/TeleBoxCollector.stories.tsx +0 -23
- package/src/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.tsx +0 -66
- package/src/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.tsx +0 -34
- package/src/TeleBoxReact/TeleBox.stories.tsx +0 -74
- package/src/TeleBoxReact/index.tsx +0 -175
- package/src/TeleBoxReact/utils.ts +0 -14
- package/src/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.tsx +0 -15
|
@@ -1,35 +1,47 @@
|
|
|
1
1
|
import "./style.scss";
|
|
2
2
|
|
|
3
3
|
import type { TeleBox } from "../../TeleBox";
|
|
4
|
-
import {
|
|
4
|
+
import type { DefaultTitleBarConfig } from "../../TeleTitleBar";
|
|
5
|
+
import { DefaultTitleBar } from "../../TeleTitleBar";
|
|
5
6
|
import { TELE_BOX_STATE } from "../../TeleBox/constants";
|
|
6
|
-
import { TeleBoxRect
|
|
7
|
+
import type { TeleBoxRect } from "../../TeleBox/typings";
|
|
8
|
+
import type { ReadonlyVal } from "value-enhancer";
|
|
9
|
+
import { combine } from "value-enhancer";
|
|
7
10
|
|
|
8
|
-
export type
|
|
11
|
+
export type MaxTitleBarTitle = Pick<TeleBox, "id" | "title">;
|
|
9
12
|
|
|
10
13
|
export interface MaxTitleBarConfig extends DefaultTitleBarConfig {
|
|
11
|
-
darkMode
|
|
12
|
-
boxes
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
darkMode$: ReadonlyVal<boolean>;
|
|
15
|
+
boxes$: ReadonlyVal<TeleBox[]>;
|
|
16
|
+
rootRect$: ReadonlyVal<TeleBoxRect>;
|
|
17
|
+
root$: ReadonlyVal<HTMLElement | null>;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export class MaxTitleBar extends DefaultTitleBar {
|
|
18
21
|
public constructor(config: MaxTitleBarConfig) {
|
|
19
22
|
super(config);
|
|
20
23
|
|
|
21
|
-
this.boxes = config.boxes
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
24
|
-
|
|
24
|
+
this.boxes$ = config.boxes$;
|
|
25
|
+
this.rootRect$ = config.rootRect$;
|
|
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
|
+
);
|
|
25
37
|
}
|
|
26
38
|
|
|
27
|
-
public focusBox(box?:
|
|
39
|
+
public focusBox(box?: TeleBox): void {
|
|
28
40
|
if (this.focusedBox && this.focusedBox === box) {
|
|
29
41
|
return;
|
|
30
42
|
}
|
|
31
43
|
|
|
32
|
-
if (this.$titles && this.state === TELE_BOX_STATE.Maximized) {
|
|
44
|
+
if (this.$titles && this.state$.value === TELE_BOX_STATE.Maximized) {
|
|
33
45
|
const { children } = this.$titles.firstElementChild as HTMLElement;
|
|
34
46
|
for (let i = children.length - 1; i >= 0; i -= 1) {
|
|
35
47
|
const $tab = children[i] as HTMLElement;
|
|
@@ -52,116 +64,85 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
52
64
|
this.focusedBox = box;
|
|
53
65
|
}
|
|
54
66
|
|
|
55
|
-
public
|
|
56
|
-
this.containerRect = rect;
|
|
57
|
-
if (this.$titleBar) {
|
|
58
|
-
const { x, y, width } = rect;
|
|
59
|
-
this.$titleBar.style.transform = `translate(${x}px, ${y}px)`;
|
|
60
|
-
this.$titleBar.style.width = width + "px";
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public setBoxes(boxes: MaxTitleBarTeleBox[]): void {
|
|
65
|
-
this.boxes = boxes;
|
|
66
|
-
this.updateTitles();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public setState(state: TeleBoxState): void {
|
|
70
|
-
super.setState(state);
|
|
71
|
-
if (this.$titleBar) {
|
|
72
|
-
this.$titleBar.classList.toggle(
|
|
73
|
-
this.wrapClassName("max-titlebar-maximized"),
|
|
74
|
-
state === TELE_BOX_STATE.Maximized
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
this.updateTitles();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public setReadonly(readonly: boolean): void {
|
|
81
|
-
super.setReadonly(readonly);
|
|
67
|
+
public render(): HTMLElement {
|
|
82
68
|
if (this.$titleBar) {
|
|
83
|
-
this.$titleBar
|
|
84
|
-
this.wrapClassName("readonly"),
|
|
85
|
-
this.readonly
|
|
86
|
-
);
|
|
69
|
+
return this.$titleBar;
|
|
87
70
|
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public setDarkMode(darkMode: boolean): void {
|
|
91
|
-
if (darkMode !== this.darkMode) {
|
|
92
|
-
this.darkMode = darkMode;
|
|
93
|
-
if (this.$titleBar) {
|
|
94
|
-
this.$titleBar.classList.toggle(
|
|
95
|
-
this.wrapClassName("color-scheme-dark"),
|
|
96
|
-
darkMode
|
|
97
|
-
);
|
|
98
|
-
this.$titleBar.classList.toggle(
|
|
99
|
-
this.wrapClassName("color-scheme-light"),
|
|
100
|
-
!darkMode
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
71
|
|
|
106
|
-
public render(): HTMLElement {
|
|
107
72
|
const $titleBar = super.render();
|
|
108
73
|
|
|
109
|
-
const { x, y, width } = this.containerRect;
|
|
110
|
-
$titleBar.style.transform = `translate(${x}px, ${y}px)`;
|
|
111
|
-
$titleBar.style.width = width + "px";
|
|
112
|
-
|
|
113
74
|
$titleBar.classList.add(this.wrapClassName("max-titlebar"));
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
75
|
+
|
|
76
|
+
this.sideEffect.addDisposer(
|
|
77
|
+
[
|
|
78
|
+
this.rootRect$.subscribe((rootRect) => {
|
|
79
|
+
const { x, y, width } = rootRect;
|
|
80
|
+
$titleBar.style.transform = `translate(${x}px, ${y}px)`;
|
|
81
|
+
$titleBar.style.width = width + "px";
|
|
82
|
+
}),
|
|
83
|
+
this.state$.subscribe((state) => {
|
|
84
|
+
$titleBar.classList.toggle(
|
|
85
|
+
this.wrapClassName("max-titlebar-maximized"),
|
|
86
|
+
state === TELE_BOX_STATE.Maximized
|
|
87
|
+
);
|
|
88
|
+
}),
|
|
89
|
+
this.readonly$.subscribe((readonly) => {
|
|
90
|
+
$titleBar.classList.toggle(
|
|
91
|
+
this.wrapClassName("readonly"),
|
|
92
|
+
readonly
|
|
93
|
+
);
|
|
94
|
+
}),
|
|
95
|
+
this.darkMode$.subscribe((darkMode) => {
|
|
96
|
+
$titleBar.classList.toggle(
|
|
97
|
+
this.wrapClassName("color-scheme-dark"),
|
|
98
|
+
darkMode
|
|
99
|
+
);
|
|
100
|
+
$titleBar.classList.toggle(
|
|
101
|
+
this.wrapClassName("color-scheme-light"),
|
|
102
|
+
!darkMode
|
|
103
|
+
);
|
|
104
|
+
}),
|
|
105
|
+
combine([this.state$, this.boxes$]).subscribe(
|
|
106
|
+
([state, titles]) => {
|
|
107
|
+
if (state === TELE_BOX_STATE.Maximized) {
|
|
108
|
+
$titleBar.classList.toggle(
|
|
109
|
+
this.wrapClassName("max-titlebar-single-title"),
|
|
110
|
+
titles.length === 1
|
|
111
|
+
);
|
|
112
|
+
if (titles.length === 1) {
|
|
113
|
+
this.setTitle(titles[0].title);
|
|
114
|
+
} else {
|
|
115
|
+
$titleBar.replaceChild(
|
|
116
|
+
this.renderTitles(),
|
|
117
|
+
$titleBar.firstElementChild as HTMLElement
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
),
|
|
123
|
+
],
|
|
124
|
+
"max-render"
|
|
126
125
|
);
|
|
127
126
|
|
|
128
127
|
const $titlesArea = document.createElement("div");
|
|
129
128
|
$titlesArea.classList.add(this.wrapClassName("titles-area"));
|
|
130
129
|
$titleBar.insertBefore($titlesArea, $titleBar.firstElementChild);
|
|
131
130
|
|
|
132
|
-
this.updateTitles();
|
|
133
|
-
|
|
134
131
|
return $titleBar;
|
|
135
132
|
}
|
|
136
133
|
|
|
137
134
|
public destroy(): void {
|
|
138
135
|
super.destroy();
|
|
139
136
|
this.$titles = void 0;
|
|
140
|
-
this.boxes.length = 0;
|
|
141
137
|
this.focusedBox = void 0;
|
|
142
138
|
}
|
|
143
139
|
|
|
144
|
-
public updateTitles(): void {
|
|
145
|
-
if (this.$titleBar && this.state === TELE_BOX_STATE.Maximized) {
|
|
146
|
-
this.$titleBar.classList.toggle(
|
|
147
|
-
this.wrapClassName("max-titlebar-single-title"),
|
|
148
|
-
this.boxes.length === 1
|
|
149
|
-
);
|
|
150
|
-
if (this.boxes.length === 1) {
|
|
151
|
-
this.setTitle(this.boxes[0].title);
|
|
152
|
-
} else {
|
|
153
|
-
this.$titleBar.replaceChild(
|
|
154
|
-
this.renderTitles(),
|
|
155
|
-
this.$titleBar.firstElementChild as HTMLElement
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
140
|
protected renderTitles(): HTMLElement {
|
|
162
141
|
this.$titles = document.createElement("div");
|
|
163
142
|
this.$titles.className = this.wrapClassName("titles");
|
|
164
|
-
|
|
143
|
+
|
|
144
|
+
this.sideEffect.addEventListener(
|
|
145
|
+
this.$titles,
|
|
165
146
|
"wheel",
|
|
166
147
|
(ev) => {
|
|
167
148
|
(ev.currentTarget as HTMLElement).scrollBy({
|
|
@@ -169,14 +150,15 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
169
150
|
behavior: "smooth",
|
|
170
151
|
});
|
|
171
152
|
},
|
|
172
|
-
{ passive: false }
|
|
153
|
+
{ passive: false },
|
|
154
|
+
"max-render-wheel-titles"
|
|
173
155
|
);
|
|
174
156
|
|
|
175
157
|
const $content = document.createElement("div");
|
|
176
158
|
$content.className = this.wrapClassName("titles-content");
|
|
177
159
|
this.$titles.appendChild($content);
|
|
178
160
|
|
|
179
|
-
this.boxes.
|
|
161
|
+
const disposers = this.boxes$.value.map((box) => {
|
|
180
162
|
const $tab = document.createElement("button");
|
|
181
163
|
$tab.className = this.wrapClassName("titles-tab");
|
|
182
164
|
$tab.textContent = box.title;
|
|
@@ -188,18 +170,23 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
188
170
|
}
|
|
189
171
|
|
|
190
172
|
$content.appendChild($tab);
|
|
173
|
+
|
|
174
|
+
return box._title$.reaction((title) => ($tab.textContent = title));
|
|
191
175
|
});
|
|
192
176
|
|
|
177
|
+
this.sideEffect.addDisposer(
|
|
178
|
+
() => disposers.forEach((disposer) => disposer()),
|
|
179
|
+
"max-render-tab-titles"
|
|
180
|
+
);
|
|
181
|
+
|
|
193
182
|
return this.$titles;
|
|
194
183
|
}
|
|
195
184
|
|
|
196
|
-
|
|
185
|
+
public focusedBox: TeleBox | undefined;
|
|
197
186
|
|
|
198
|
-
protected $
|
|
199
|
-
|
|
200
|
-
protected
|
|
187
|
+
protected darkMode$: MaxTitleBarConfig["darkMode$"];
|
|
188
|
+
protected boxes$: MaxTitleBarConfig["boxes$"];
|
|
189
|
+
protected rootRect$: MaxTitleBarConfig["rootRect$"];
|
|
201
190
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
protected containerRect: TeleBoxRect;
|
|
191
|
+
protected $titles: HTMLElement | undefined;
|
|
205
192
|
}
|
|
@@ -6,11 +6,8 @@ export enum TELE_BOX_MANAGER_EVENT {
|
|
|
6
6
|
State = "state",
|
|
7
7
|
Maximized = "maximized",
|
|
8
8
|
Minimized = "minimized",
|
|
9
|
-
Move = "move",
|
|
10
|
-
Resize = "resize",
|
|
11
9
|
IntrinsicMove = "intrinsic_move",
|
|
12
10
|
IntrinsicResize = "intrinsic_resize",
|
|
13
|
-
VisualResize = "visual_resize",
|
|
14
11
|
ZIndex = "z_index",
|
|
15
12
|
PrefersColorScheme = "prefers_color_scheme",
|
|
16
13
|
DarkMode = "dark_mode",
|