@netless/telebox-insider 0.2.25 → 1.0.0-alpha.10

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.
Files changed (53) hide show
  1. package/dist/TeleBox/constants.d.ts +0 -3
  2. package/dist/TeleBox/index.d.ts +120 -97
  3. package/dist/TeleBox/typings.d.ts +42 -55
  4. package/dist/TeleBoxCollector/index.d.ts +27 -29
  5. package/dist/TeleBoxManager/MaxTitleBar/index.d.ts +14 -18
  6. package/dist/TeleBoxManager/constants.d.ts +0 -3
  7. package/dist/TeleBoxManager/index.d.ts +64 -19
  8. package/dist/TeleBoxManager/typings.d.ts +35 -28
  9. package/dist/TeleStage/index.d.ts +21 -0
  10. package/dist/TeleTitleBar/DefaultTitleBar/index.d.ts +5 -9
  11. package/dist/TeleTitleBar/typings.d.ts +4 -6
  12. package/dist/index.d.ts +0 -1
  13. package/dist/style.css +1 -1
  14. package/dist/telebox-insider.cjs.js +1 -15
  15. package/dist/telebox-insider.cjs.js.map +1 -1
  16. package/dist/telebox-insider.es.js +1 -15
  17. package/dist/telebox-insider.es.js.map +1 -1
  18. package/dist/utils.d.ts +0 -1
  19. package/package.json +7 -19
  20. package/src/TeleBox/constants.ts +0 -3
  21. package/src/TeleBox/index.ts +518 -689
  22. package/src/TeleBox/style.scss +6 -0
  23. package/src/TeleBox/typings.ts +42 -75
  24. package/src/TeleBoxCollector/index.ts +151 -159
  25. package/src/TeleBoxCollector/style.scss +4 -1
  26. package/src/TeleBoxManager/MaxTitleBar/index.ts +88 -108
  27. package/src/TeleBoxManager/MaxTitleBar/style.scss +8 -3
  28. package/src/TeleBoxManager/constants.ts +0 -3
  29. package/src/TeleBoxManager/index.ts +330 -336
  30. package/src/TeleBoxManager/typings.ts +42 -52
  31. package/src/TeleStage/index.ts +174 -0
  32. package/src/TeleStage/style.scss +49 -0
  33. package/src/TeleTitleBar/DefaultTitleBar/index.ts +44 -65
  34. package/src/TeleTitleBar/DefaultTitleBar/style.scss +7 -0
  35. package/src/TeleTitleBar/typings.ts +4 -10
  36. package/src/index.ts +0 -1
  37. package/src/scss/mixins.scss +7 -0
  38. package/src/scss/variables.scss +3 -0
  39. package/src/utils.ts +0 -6
  40. package/dist/TeleBoxCollector/TeleBoxCollector.stories.d.ts +0 -5
  41. package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.d.ts +0 -7
  42. package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.d.ts +0 -4
  43. package/dist/TeleBoxReact/TeleBox.stories.d.ts +0 -9
  44. package/dist/TeleBoxReact/index.d.ts +0 -17
  45. package/dist/TeleBoxReact/utils.d.ts +0 -2
  46. package/dist/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.d.ts +0 -4
  47. package/src/TeleBoxCollector/TeleBoxCollector.stories.tsx +0 -23
  48. package/src/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.tsx +0 -66
  49. package/src/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.tsx +0 -34
  50. package/src/TeleBoxReact/TeleBox.stories.tsx +0 -74
  51. package/src/TeleBoxReact/index.tsx +0 -175
  52. package/src/TeleBoxReact/utils.ts +0 -14
  53. 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 { DefaultTitleBar, DefaultTitleBarConfig } from "../../TeleTitleBar";
4
+ import type { DefaultTitleBarConfig } from "../../TeleTitleBar";
5
+ import { DefaultTitleBar } from "../../TeleTitleBar";
5
6
  import { TELE_BOX_STATE } from "../../TeleBox/constants";
6
- import { TeleBoxRect, TeleBoxState } from "../../TeleBox/typings";
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 MaxTitleBarTeleBox = Pick<TeleBox, "id" | "title" | "readonly">;
11
+ export type MaxTitleBarTitle = Pick<TeleBox, "id" | "title">;
9
12
 
10
13
  export interface MaxTitleBarConfig extends DefaultTitleBarConfig {
11
- darkMode: boolean;
12
- boxes: MaxTitleBarTeleBox[];
13
- containerRect: TeleBoxRect;
14
- focusedBox?: MaxTitleBarTeleBox;
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.focusedBox = config.focusedBox;
23
- this.containerRect = config.containerRect;
24
- this.darkMode = config.darkMode;
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?: MaxTitleBarTeleBox): void {
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 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);
67
+ public render(): HTMLElement {
82
68
  if (this.$titleBar) {
83
- this.$titleBar.classList.toggle(
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
- $titleBar.classList.toggle(
115
- this.wrapClassName("max-titlebar-maximized"),
116
- this.state === TELE_BOX_STATE.Maximized
117
- );
118
- $titleBar.classList.toggle(
119
- this.wrapClassName("readonly"),
120
- this.readonly
121
- );
122
- $titleBar.classList.add(
123
- this.wrapClassName(
124
- this.darkMode ? "color-scheme-dark" : "color-scheme-light"
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
- this.$titles.addEventListener(
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.forEach((box) => {
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
- protected darkMode: boolean;
178
+ public focusedBox: TeleBox | undefined;
197
179
 
198
- protected $titles: HTMLElement | undefined;
199
-
200
- protected boxes: MaxTitleBarTeleBox[];
180
+ protected darkMode$: MaxTitleBarConfig["darkMode$"];
181
+ protected boxes$: MaxTitleBarConfig["boxes$"];
182
+ protected rootRect$: MaxTitleBarConfig["rootRect$"];
201
183
 
202
- public focusedBox: MaxTitleBarTeleBox | undefined;
203
-
204
- protected containerRect: TeleBoxRect;
184
+ protected $titles: HTMLElement | undefined;
205
185
  }
@@ -1,4 +1,5 @@
1
1
  @import "../../scss/variables.scss";
2
+ @import "../../scss/mixins.scss";
2
3
 
3
4
  $scrollbar-size: 8px;
4
5
  $scrollbar-ff-width: auto; // FF-only accepts auto, thin, none
@@ -9,12 +10,16 @@ $scrollbar-color-hover: rgba(238, 238, 247, 1);
9
10
  $scrollbar-color-active: rgba(238, 238, 247, 1);
10
11
 
11
12
  .#{$namespace}-max-titlebar {
13
+ @include no-user-select;
14
+
12
15
  display: none;
13
16
  position: absolute;
14
17
  top: 0;
15
18
  left: 0;
16
- z-index: $base-z-index * 500;
17
- user-select: none;
19
+ width: 100%;
20
+ z-index: $max-titlebar-z-index;
21
+ border-top-left-radius: 6px;
22
+ border-top-right-radius: 6px;
18
23
 
19
24
  .#{$namespace}-title {
20
25
  display: none;
@@ -93,7 +98,7 @@ $scrollbar-color-active: rgba(238, 238, 247, 1);
93
98
  height: 100%;
94
99
  overflow: hidden;
95
100
  max-width: 182px;
96
- min-width: 50px;
101
+ min-width: 150px;
97
102
  padding: 0 26px 0 16px;
98
103
  outline: none;
99
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",