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

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 (52) hide show
  1. package/dist/TeleBox/constants.d.ts +0 -3
  2. package/dist/TeleBox/index.d.ts +118 -97
  3. package/dist/TeleBox/typings.d.ts +42 -55
  4. package/dist/TeleBoxCollector/index.d.ts +25 -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 +6 -8
  11. package/dist/TeleTitleBar/typings.d.ts +3 -5
  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 +500 -690
  22. package/src/TeleBox/style.scss +6 -0
  23. package/src/TeleBox/typings.ts +42 -75
  24. package/src/TeleBoxCollector/index.ts +136 -159
  25. package/src/TeleBoxCollector/style.scss +3 -0
  26. package/src/TeleBoxManager/MaxTitleBar/index.ts +95 -108
  27. package/src/TeleBoxManager/MaxTitleBar/style.scss +3 -1
  28. package/src/TeleBoxManager/constants.ts +0 -3
  29. package/src/TeleBoxManager/index.ts +329 -336
  30. package/src/TeleBoxManager/typings.ts +42 -52
  31. package/src/TeleStage/index.ts +178 -0
  32. package/src/TeleStage/style.scss +49 -0
  33. package/src/TeleTitleBar/DefaultTitleBar/index.ts +48 -61
  34. package/src/TeleTitleBar/DefaultTitleBar/style.scss +7 -0
  35. package/src/TeleTitleBar/typings.ts +3 -9
  36. package/src/index.ts +0 -1
  37. package/src/scss/mixins.scss +7 -0
  38. package/src/utils.ts +0 -6
  39. package/dist/TeleBoxCollector/TeleBoxCollector.stories.d.ts +0 -5
  40. package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.d.ts +0 -7
  41. package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.d.ts +0 -4
  42. package/dist/TeleBoxReact/TeleBox.stories.d.ts +0 -9
  43. package/dist/TeleBoxReact/index.d.ts +0 -17
  44. package/dist/TeleBoxReact/utils.d.ts +0 -2
  45. package/dist/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.d.ts +0 -4
  46. package/src/TeleBoxCollector/TeleBoxCollector.stories.tsx +0 -23
  47. package/src/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.tsx +0 -66
  48. package/src/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.tsx +0 -34
  49. package/src/TeleBoxReact/TeleBox.stories.tsx +0 -74
  50. package/src/TeleBoxReact/index.tsx +0 -175
  51. package/src/TeleBoxReact/utils.ts +0 -14
  52. 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,85 @@ 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.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
- this.$titles.addEventListener(
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.forEach((box) => {
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
- protected darkMode: boolean;
185
+ public focusedBox: TeleBox | undefined;
197
186
 
198
- protected $titles: HTMLElement | undefined;
199
-
200
- protected boxes: MaxTitleBarTeleBox[];
187
+ protected darkMode$: MaxTitleBarConfig["darkMode$"];
188
+ protected boxes$: MaxTitleBarConfig["boxes$"];
189
+ protected rootRect$: MaxTitleBarConfig["rootRect$"];
201
190
 
202
- public focusedBox: MaxTitleBarTeleBox | undefined;
203
-
204
- protected containerRect: TeleBoxRect;
191
+ protected $titles: HTMLElement | undefined;
205
192
  }
@@ -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,13 @@ $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
19
  z-index: $base-z-index * 500;
17
- user-select: none;
18
20
 
19
21
  .#{$namespace}-title {
20
22
  display: none;
@@ -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",