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