@netless/telebox-insider 0.2.26 → 1.0.0-alpha.11
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 +121 -97
- package/dist/TeleBox/typings.d.ts +44 -55
- package/dist/TeleBoxCollector/index.d.ts +27 -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 +5 -9
- package/dist/TeleTitleBar/typings.d.ts +4 -6
- 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 +527 -689
- package/src/TeleBox/style.scss +1 -0
- package/src/TeleBox/typings.ts +44 -75
- package/src/TeleBoxCollector/index.ts +151 -159
- package/src/TeleBoxCollector/style.scss +1 -1
- package/src/TeleBoxManager/MaxTitleBar/index.ts +88 -108
- package/src/TeleBoxManager/MaxTitleBar/style.scss +5 -2
- package/src/TeleBoxManager/constants.ts +0 -3
- package/src/TeleBoxManager/index.ts +333 -336
- package/src/TeleBoxManager/typings.ts +45 -53
- package/src/TeleStage/index.ts +174 -0
- package/src/TeleStage/style.scss +49 -0
- package/src/TeleTitleBar/DefaultTitleBar/index.ts +44 -65
- package/src/TeleTitleBar/typings.ts +4 -10
- package/src/index.ts +0 -1
- package/src/scss/variables.scss +3 -0
- 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,78 @@ 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.state$.subscribe((state) => {
|
|
79
|
+
$titleBar.classList.toggle(
|
|
80
|
+
this.wrapClassName("max-titlebar-maximized"),
|
|
81
|
+
state === TELE_BOX_STATE.Maximized
|
|
82
|
+
);
|
|
83
|
+
}),
|
|
84
|
+
this.readonly$.subscribe((readonly) => {
|
|
85
|
+
$titleBar.classList.toggle(
|
|
86
|
+
this.wrapClassName("readonly"),
|
|
87
|
+
readonly
|
|
88
|
+
);
|
|
89
|
+
}),
|
|
90
|
+
this.darkMode$.subscribe((darkMode) => {
|
|
91
|
+
$titleBar.classList.toggle(
|
|
92
|
+
this.wrapClassName("color-scheme-dark"),
|
|
93
|
+
darkMode
|
|
94
|
+
);
|
|
95
|
+
$titleBar.classList.toggle(
|
|
96
|
+
this.wrapClassName("color-scheme-light"),
|
|
97
|
+
!darkMode
|
|
98
|
+
);
|
|
99
|
+
}),
|
|
100
|
+
combine([this.state$, this.boxes$]).subscribe(
|
|
101
|
+
([state, titles]) => {
|
|
102
|
+
if (state === TELE_BOX_STATE.Maximized) {
|
|
103
|
+
$titleBar.classList.toggle(
|
|
104
|
+
this.wrapClassName("max-titlebar-single-title"),
|
|
105
|
+
titles.length === 1
|
|
106
|
+
);
|
|
107
|
+
if (titles.length !== 1) {
|
|
108
|
+
$titleBar.replaceChild(
|
|
109
|
+
this.renderTitles(),
|
|
110
|
+
$titleBar.firstElementChild as HTMLElement
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
),
|
|
116
|
+
],
|
|
117
|
+
"max-render"
|
|
126
118
|
);
|
|
127
119
|
|
|
128
120
|
const $titlesArea = document.createElement("div");
|
|
129
121
|
$titlesArea.classList.add(this.wrapClassName("titles-area"));
|
|
130
122
|
$titleBar.insertBefore($titlesArea, $titleBar.firstElementChild);
|
|
131
123
|
|
|
132
|
-
this.updateTitles();
|
|
133
|
-
|
|
134
124
|
return $titleBar;
|
|
135
125
|
}
|
|
136
126
|
|
|
137
127
|
public destroy(): void {
|
|
138
128
|
super.destroy();
|
|
139
129
|
this.$titles = void 0;
|
|
140
|
-
this.boxes.length = 0;
|
|
141
130
|
this.focusedBox = void 0;
|
|
142
131
|
}
|
|
143
132
|
|
|
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
133
|
protected renderTitles(): HTMLElement {
|
|
162
134
|
this.$titles = document.createElement("div");
|
|
163
135
|
this.$titles.className = this.wrapClassName("titles");
|
|
164
|
-
|
|
136
|
+
|
|
137
|
+
this.sideEffect.addEventListener(
|
|
138
|
+
this.$titles,
|
|
165
139
|
"wheel",
|
|
166
140
|
(ev) => {
|
|
167
141
|
(ev.currentTarget as HTMLElement).scrollBy({
|
|
@@ -169,14 +143,15 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
169
143
|
behavior: "smooth",
|
|
170
144
|
});
|
|
171
145
|
},
|
|
172
|
-
{ passive: false }
|
|
146
|
+
{ passive: false },
|
|
147
|
+
"max-render-wheel-titles"
|
|
173
148
|
);
|
|
174
149
|
|
|
175
150
|
const $content = document.createElement("div");
|
|
176
151
|
$content.className = this.wrapClassName("titles-content");
|
|
177
152
|
this.$titles.appendChild($content);
|
|
178
153
|
|
|
179
|
-
this.boxes.
|
|
154
|
+
const disposers = this.boxes$.value.map((box) => {
|
|
180
155
|
const $tab = document.createElement("button");
|
|
181
156
|
$tab.className = this.wrapClassName("titles-tab");
|
|
182
157
|
$tab.textContent = box.title;
|
|
@@ -188,18 +163,23 @@ export class MaxTitleBar extends DefaultTitleBar {
|
|
|
188
163
|
}
|
|
189
164
|
|
|
190
165
|
$content.appendChild($tab);
|
|
166
|
+
|
|
167
|
+
return box._title$.reaction((title) => ($tab.textContent = title));
|
|
191
168
|
});
|
|
192
169
|
|
|
170
|
+
this.sideEffect.addDisposer(
|
|
171
|
+
() => disposers.forEach((disposer) => disposer()),
|
|
172
|
+
"max-render-tab-titles"
|
|
173
|
+
);
|
|
174
|
+
|
|
193
175
|
return this.$titles;
|
|
194
176
|
}
|
|
195
177
|
|
|
196
|
-
|
|
178
|
+
public focusedBox: TeleBox | undefined;
|
|
197
179
|
|
|
198
|
-
protected $
|
|
199
|
-
|
|
200
|
-
protected
|
|
180
|
+
protected darkMode$: MaxTitleBarConfig["darkMode$"];
|
|
181
|
+
protected boxes$: MaxTitleBarConfig["boxes$"];
|
|
182
|
+
protected rootRect$: MaxTitleBarConfig["rootRect$"];
|
|
201
183
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
protected containerRect: TeleBoxRect;
|
|
184
|
+
protected $titles: HTMLElement | undefined;
|
|
205
185
|
}
|
|
@@ -16,7 +16,10 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
|
|
|
16
16
|
position: absolute;
|
|
17
17
|
top: 0;
|
|
18
18
|
left: 0;
|
|
19
|
-
|
|
19
|
+
width: 100%;
|
|
20
|
+
z-index: $max-titlebar-z-index;
|
|
21
|
+
border-top-left-radius: 6px;
|
|
22
|
+
border-top-right-radius: 6px;
|
|
20
23
|
|
|
21
24
|
.#{$namespace}-title {
|
|
22
25
|
display: none;
|
|
@@ -95,7 +98,7 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
|
|
|
95
98
|
height: 100%;
|
|
96
99
|
overflow: hidden;
|
|
97
100
|
max-width: 182px;
|
|
98
|
-
min-width:
|
|
101
|
+
min-width: 150px;
|
|
99
102
|
padding: 0 26px 0 16px;
|
|
100
103
|
outline: none;
|
|
101
104
|
font-size: 13px;
|
|
@@ -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",
|