@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,25 +1,28 @@
1
- import type EventEmitter from "eventemitter3";
2
- import { TeleBoxColorScheme } from "..";
1
+ import type { TeleBoxColorScheme } from "..";
3
2
  import type { ReadonlyTeleBox, TeleBoxState } from "../TeleBox";
4
3
  import type { TeleBoxConfig } from "../TeleBox/typings";
5
4
  import type { TeleBoxCollector } from "../TeleBoxCollector";
6
5
  import type { TELE_BOX_MANAGER_EVENT } from "./constants";
7
6
 
8
- export interface TeleBoxManagerConfig
9
- extends Pick<
10
- TeleBoxConfig,
11
- | "prefersColorScheme"
12
- | "fence"
13
- | "containerRect"
14
- | "maximized"
15
- | "minimized"
16
- | "namespace"
17
- | "readonly"
18
- > {
7
+ export interface TeleBoxManagerConfig extends Pick<TeleBoxConfig, "namespace"> {
19
8
  /** Element to mount boxes. */
20
- root?: HTMLElement;
9
+ readonly root?: HTMLElement | null;
10
+ /** Stage area height/with ratio. No ratio if <= 0. Default -1. */
11
+ readonly stageRatio?: number;
21
12
  /** Where the minimized boxes go. */
22
- collector?: TeleBoxCollector;
13
+ readonly collector?: TeleBoxCollector;
14
+ /** Restrict box to always be within the stage area. Default false. */
15
+ readonly fence?: boolean;
16
+ /** Prefers Box color scheme. Default light. */
17
+ readonly prefersColorScheme?: TeleBoxColorScheme;
18
+ /** Maximize box. Default false. */
19
+ readonly maximized?: boolean;
20
+ /** Minimize box. Overwrites maximized state. Default false. */
21
+ readonly minimized?: boolean;
22
+ /** Is box readonly */
23
+ readonly readonly?: boolean;
24
+ /** Show stage frame and grey-out the non-stage area. Default true. */
25
+ readonly highlightStage?: boolean;
23
26
  }
24
27
 
25
28
  type TeleBoxManagerBoxConfigBaseProps =
@@ -33,7 +36,7 @@ type TeleBoxManagerBoxConfigBaseProps =
33
36
  | "y"
34
37
  | "resizable"
35
38
  | "draggable"
36
- | "fixRatio"
39
+ | "ratio"
37
40
  | "zIndex";
38
41
 
39
42
  export type TeleBoxManagerCreateConfig = Pick<
@@ -43,7 +46,14 @@ export type TeleBoxManagerCreateConfig = Pick<
43
46
 
44
47
  export type TeleBoxManagerQueryConfig = Pick<
45
48
  TeleBoxConfig,
46
- TeleBoxManagerBoxConfigBaseProps | "id" | "focus"
49
+ | "title"
50
+ | "visible"
51
+ | "resizable"
52
+ | "draggable"
53
+ | "ratio"
54
+ | "zIndex"
55
+ | "id"
56
+ | "focus"
47
57
  >;
48
58
 
49
59
  export type TeleBoxManagerUpdateConfig = Pick<
@@ -56,41 +66,21 @@ type CheckTeleBoxManagerConfig<
56
66
  > = T;
57
67
 
58
68
  export type TeleBoxManagerEventConfig = CheckTeleBoxManagerConfig<{
59
- focused: [ReadonlyTeleBox | undefined];
60
- blurred: [ReadonlyTeleBox | undefined];
61
- created: [ReadonlyTeleBox];
62
- removed: [ReadonlyTeleBox[]];
63
- state: [TeleBoxState];
64
- maximized: [boolean];
65
- minimized: [boolean];
66
- move: [ReadonlyTeleBox];
67
- resize: [ReadonlyTeleBox];
68
- intrinsic_move: [ReadonlyTeleBox];
69
- intrinsic_resize: [ReadonlyTeleBox];
70
- visual_resize: [ReadonlyTeleBox];
71
- z_index: [ReadonlyTeleBox];
72
- prefers_color_scheme: [TeleBoxColorScheme];
73
- dark_mode: [boolean];
69
+ focused: ReadonlyTeleBox | undefined;
70
+ blurred: ReadonlyTeleBox | undefined;
71
+ created: ReadonlyTeleBox;
72
+ removed: ReadonlyTeleBox[];
73
+ state: TeleBoxState;
74
+ maximized: boolean;
75
+ minimized: boolean;
76
+ move: ReadonlyTeleBox;
77
+ resize: ReadonlyTeleBox;
78
+ intrinsic_move: ReadonlyTeleBox;
79
+ intrinsic_resize: ReadonlyTeleBox;
80
+ visual_resize: ReadonlyTeleBox;
81
+ z_index: ReadonlyTeleBox;
82
+ prefers_color_scheme: TeleBoxColorScheme;
83
+ dark_mode: boolean;
74
84
  }>;
75
85
 
76
86
  export type TeleBoxManagerEvent = keyof TeleBoxManagerEventConfig;
77
-
78
- export interface TeleBoxManagerEvents
79
- extends EventEmitter<TeleBoxManagerEvent> {
80
- on<U extends TeleBoxManagerEvent>(
81
- event: U,
82
- listener: (...value: TeleBoxManagerEventConfig[U]) => void
83
- ): this;
84
- once<U extends TeleBoxManagerEvent>(
85
- event: U,
86
- listener: (...value: TeleBoxManagerEventConfig[U]) => void
87
- ): this;
88
- addListener<U extends TeleBoxManagerEvent>(
89
- event: U,
90
- listener: (...value: TeleBoxManagerEventConfig[U]) => void
91
- ): this;
92
- emit<U extends TeleBoxManagerEvent>(
93
- event: U,
94
- ...value: TeleBoxManagerEventConfig[U]
95
- ): boolean;
96
- }
@@ -0,0 +1,174 @@
1
+ import "./style.scss";
2
+
3
+ import shallowequal from "shallowequal";
4
+ import { SideEffectManager } from "side-effect-manager";
5
+ import type { ReadonlyVal } from "value-enhancer";
6
+ import { combine } from "value-enhancer";
7
+ import type { TeleBoxRect } from "../TeleBox/typings";
8
+
9
+ export interface TeleStageConfig {
10
+ namespace: string;
11
+ root$: ReadonlyVal<HTMLElement | null>;
12
+ rootRect$: ReadonlyVal<TeleBoxRect>;
13
+ ratio$: ReadonlyVal<number>;
14
+ highlightStage$: ReadonlyVal<boolean>;
15
+ }
16
+
17
+ export class TeleStage {
18
+ private readonly _sideEffect = new SideEffectManager();
19
+
20
+ public readonly namespace: string;
21
+ public readonly stageRect$: ReadonlyVal<TeleBoxRect>;
22
+ public readonly highlightStage$: ReadonlyVal<boolean>;
23
+
24
+ public $boxStage?: HTMLDivElement;
25
+
26
+ constructor({
27
+ namespace,
28
+ rootRect$,
29
+ ratio$,
30
+ highlightStage$,
31
+ root$,
32
+ }: TeleStageConfig) {
33
+ this.namespace = namespace;
34
+ this.highlightStage$ = highlightStage$;
35
+
36
+ this.stageRect$ = combine(
37
+ [rootRect$, ratio$],
38
+ ([rootRect, ratio]) => {
39
+ if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
40
+ return rootRect;
41
+ }
42
+
43
+ const preferredHeight = rootRect.width * ratio;
44
+ if (preferredHeight === rootRect.height) {
45
+ return rootRect;
46
+ }
47
+
48
+ if (preferredHeight < rootRect.height) {
49
+ return {
50
+ x: 0,
51
+ y: (rootRect.height - preferredHeight) / 2,
52
+ width: rootRect.width,
53
+ height: preferredHeight,
54
+ };
55
+ }
56
+
57
+ const preferredWidth = rootRect.height / ratio;
58
+ return {
59
+ x: (rootRect.width - preferredWidth) / 2,
60
+ y: 0,
61
+ width: preferredWidth,
62
+ height: rootRect.height,
63
+ };
64
+ },
65
+ { compare: shallowequal }
66
+ );
67
+
68
+ this._sideEffect.addDisposer(
69
+ combine([root$, highlightStage$]).subscribe(
70
+ ([root, highlightStage]) => {
71
+ if (root && highlightStage) {
72
+ root.appendChild(this.render());
73
+ } else if (this.$boxStage?.parentNode) {
74
+ this.$boxStage.remove();
75
+ }
76
+ }
77
+ )
78
+ );
79
+ }
80
+
81
+ private render(): HTMLDivElement {
82
+ if (this.$boxStage) {
83
+ return this.$boxStage;
84
+ }
85
+
86
+ const $boxStage = document.createElement("div");
87
+ $boxStage.className = this.wrapClassName("box-stage-container");
88
+ const $boxStageMask1 = document.createElement("div");
89
+ $boxStageMask1.className = this.wrapClassName("box-stage-mask");
90
+ const $boxStageMask2 = document.createElement("div");
91
+ $boxStageMask2.className = this.wrapClassName("box-stage-mask");
92
+ const $boxStageFrame = document.createElement("div");
93
+ $boxStageFrame.className = this.wrapClassName("box-stage-frame");
94
+
95
+ const [
96
+ $topLeftCorner,
97
+ $topRightCorner,
98
+ $bottomLeftCorner,
99
+ $bottomRightCorner,
100
+ ] = [
101
+ "M0 8V0h8v2H2v6H0Z",
102
+ "M8 8V0H0v2h6v6h2Z",
103
+ "M0 0v8h8V6H2V0H0Z",
104
+ "M8 0v8H0V6h6V0h2Z",
105
+ ].map((path, i) => {
106
+ const $svg = document.createElementNS(
107
+ "http://www.w3.org/2000/svg",
108
+ "svg"
109
+ );
110
+ $svg.setAttribute("viewBox", "0 0 8 8");
111
+ $svg.setAttribute(
112
+ "class",
113
+ `${this.wrapClassName("box-stage-frame-corner")} is-${i}`
114
+ );
115
+ const $path = document.createElementNS(
116
+ "http://www.w3.org/2000/svg",
117
+ "path"
118
+ );
119
+ $path.setAttribute("d", path);
120
+ $path.setAttribute("fill", "#3381FF");
121
+ $svg.appendChild($path);
122
+ return $svg;
123
+ });
124
+
125
+ $boxStageFrame.appendChild($topLeftCorner);
126
+ $boxStageFrame.appendChild($bottomLeftCorner);
127
+ $boxStageFrame.appendChild($topRightCorner);
128
+ $boxStageFrame.appendChild($bottomRightCorner);
129
+
130
+ $boxStage.appendChild($boxStageMask1);
131
+ $boxStage.appendChild($boxStageFrame);
132
+ $boxStage.appendChild($boxStageMask2);
133
+
134
+ this._sideEffect.addDisposer(
135
+ this.highlightStage$.subscribe((highlightStage) => {
136
+ $boxStage.classList.toggle("is-active", highlightStage);
137
+ })
138
+ );
139
+
140
+ this._sideEffect.addDisposer(
141
+ combine([this.highlightStage$, this.stageRect$]).subscribe(
142
+ ([highlightStage, stageRect]) => {
143
+ if (!highlightStage) {
144
+ return;
145
+ }
146
+ if (stageRect.x > 0) {
147
+ $boxStage.style.flexDirection = "row";
148
+ $boxStageMask1.style.width = `${stageRect.x}px`;
149
+ $boxStageMask1.style.height = "";
150
+ $boxStageMask2.style.width = `${stageRect.x}px`;
151
+ $boxStageMask2.style.height = "";
152
+ } else if (stageRect.y > 0) {
153
+ $boxStage.style.flexDirection = "column";
154
+ $boxStageMask1.style.width = "";
155
+ $boxStageMask1.style.height = `${stageRect.y}px`;
156
+ $boxStageMask2.style.width = "";
157
+ $boxStageMask2.style.height = `${stageRect.y}px`;
158
+ }
159
+ }
160
+ )
161
+ );
162
+
163
+ this.$boxStage = $boxStage;
164
+ return $boxStage;
165
+ }
166
+
167
+ public destroy(): void {
168
+ this._sideEffect.flushAll();
169
+ }
170
+
171
+ public wrapClassName(className: string): string {
172
+ return `${this.namespace}-${className}`;
173
+ }
174
+ }
@@ -0,0 +1,49 @@
1
+ @import "../scss/variables.scss";
2
+
3
+ .#{$namespace}-box-stage-container {
4
+ display: none;
5
+ position: absolute;
6
+ z-index: $stage-z-index;
7
+ top: 0;
8
+ left: 0;
9
+ width: 100%;
10
+ height: 100%;
11
+ overflow: hidden;
12
+ pointer-events: none;
13
+
14
+ &.is-active {
15
+ display: flex;
16
+ }
17
+ }
18
+
19
+ .#{$namespace}-box-stage-mask {
20
+ background: rgba(0, 0, 0, 0.05);
21
+ }
22
+
23
+ .#{$namespace}-box-stage-frame {
24
+ flex: 1;
25
+ position: relative;
26
+ }
27
+
28
+ .#{$namespace}-box-stage-frame-corner {
29
+ position: absolute;
30
+ width: 8px;
31
+ height: 8px;
32
+
33
+ &.is-0 {
34
+ top: 0;
35
+ left: 0;
36
+ }
37
+ &.is-1 {
38
+ top: 0;
39
+ right: 0;
40
+ }
41
+ &.is-2 {
42
+ bottom: 0;
43
+ left: 0;
44
+ }
45
+ &.is-3 {
46
+ bottom: 0;
47
+ right: 0;
48
+ }
49
+ }
@@ -14,6 +14,7 @@ import type {
14
14
  TeleTitleBarEvent,
15
15
  } from "../typings";
16
16
  import { preventEvent } from "../../utils";
17
+ import type { ReadonlyVal } from "value-enhancer";
17
18
 
18
19
  export type DefaultTitleBarButton = TeleTitleBarEvent & {
19
20
  readonly iconClassName: string;
@@ -26,20 +27,20 @@ export interface DefaultTitleBarConfig extends TeleTitleBarConfig {
26
27
 
27
28
  export class DefaultTitleBar implements TeleTitleBar {
28
29
  public constructor({
29
- readonly = false,
30
- title,
30
+ readonly$,
31
+ state$,
32
+ title$,
31
33
  buttons,
32
34
  onEvent,
33
35
  onDragStart,
34
36
  namespace = "telebox",
35
- state = TELE_BOX_STATE.Normal,
36
- }: DefaultTitleBarConfig = {}) {
37
- this.readonly = readonly;
37
+ }: DefaultTitleBarConfig) {
38
+ this.readonly$ = readonly$;
39
+ this.state$ = state$;
40
+ this.title$ = title$;
38
41
  this.onEvent = onEvent;
39
42
  this.onDragStart = onDragStart;
40
43
  this.namespace = namespace;
41
- this.title = title;
42
- this.state = state;
43
44
 
44
45
  this.buttons = buttons || [
45
46
  {
@@ -64,39 +65,8 @@ export class DefaultTitleBar implements TeleTitleBar {
64
65
 
65
66
  public $titleBar: HTMLElement | undefined;
66
67
 
67
- public $title: HTMLElement | undefined;
68
-
69
68
  public $dragArea: HTMLElement;
70
69
 
71
- public setTitle(title: string): void {
72
- this.title = title;
73
- if (this.$title) {
74
- this.$title.textContent = title;
75
- this.$title.title = title;
76
- }
77
- }
78
-
79
- public setState(state: TeleBoxState): void {
80
- if (this.state !== state) {
81
- this.state = state;
82
-
83
- this.buttons.forEach((btn, i) => {
84
- if (btn.isActive) {
85
- this.$btns[i].classList.toggle(
86
- "is-active",
87
- btn.isActive(state)
88
- );
89
- }
90
- });
91
- }
92
- }
93
-
94
- public setReadonly(readonly: boolean): void {
95
- if (this.readonly !== readonly) {
96
- this.readonly = readonly;
97
- }
98
- }
99
-
100
70
  public render(): HTMLElement {
101
71
  if (!this.$titleBar) {
102
72
  this.$titleBar = document.createElement("div");
@@ -106,21 +76,17 @@ export class DefaultTitleBar implements TeleTitleBar {
106
76
  $titleArea.className = this.wrapClassName("title-area");
107
77
  $titleArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
108
78
 
109
- this.$title = document.createElement("h1");
110
- this.$title.className = this.wrapClassName("title");
111
- this.$title.dataset.teleBoxHandle = TeleBoxDragHandleType;
112
- if (this.title) {
113
- this.$title.textContent = this.title;
114
- this.$title.title = this.title;
115
- }
79
+ const $title = document.createElement("h1");
80
+ $title.className = this.wrapClassName("title");
81
+ $title.dataset.teleBoxHandle = TeleBoxDragHandleType;
116
82
 
117
- $titleArea.appendChild(this.$title);
83
+ $titleArea.appendChild($title);
118
84
  $titleArea.appendChild(this.$dragArea);
119
85
 
120
86
  const $buttonsContainer = document.createElement("div");
121
87
  $buttonsContainer.className = this.wrapClassName("titlebar-btns");
122
88
 
123
- this.buttons.forEach(({ iconClassName, isActive }, i) => {
89
+ this.buttons.forEach(({ iconClassName }, i) => {
124
90
  const teleTitleBarBtnIndex = String(i);
125
91
 
126
92
  const $btn = document.createElement("button");
@@ -129,21 +95,36 @@ export class DefaultTitleBar implements TeleTitleBar {
129
95
  )} ${iconClassName}`;
130
96
  $btn.dataset.teleTitleBarBtnIndex = teleTitleBarBtnIndex;
131
97
  $btn.dataset.teleTitleBarNoDblClick = "true";
132
-
133
- if (isActive) {
134
- $btn.classList.toggle("is-active", isActive(this.state));
135
- }
136
-
137
- this.$btns.push($btn);
138
-
139
98
  $buttonsContainer.appendChild($btn);
140
99
  });
141
100
 
101
+ this.sideEffect.addDisposer(
102
+ this.title$.subscribe((title) => {
103
+ $title.textContent = title;
104
+ $title.title = title;
105
+ }),
106
+ "render-title"
107
+ );
108
+
109
+ this.sideEffect.addDisposer(
110
+ this.state$.subscribe((state) => {
111
+ this.buttons.forEach((btn, i) => {
112
+ if (btn.isActive) {
113
+ $buttonsContainer.children[i]?.classList.toggle(
114
+ "is-active",
115
+ btn.isActive(state)
116
+ );
117
+ }
118
+ });
119
+ }),
120
+ "render-state-btns"
121
+ );
122
+
142
123
  this.sideEffect.addEventListener(
143
124
  $buttonsContainer,
144
125
  "click",
145
126
  (ev) => {
146
- if (this.readonly) {
127
+ if (this.readonly$.value) {
147
128
  return;
148
129
  }
149
130
  const target = ev.target as HTMLElement;
@@ -163,7 +144,9 @@ export class DefaultTitleBar implements TeleTitleBar {
163
144
  } as TeleTitleBarEvent);
164
145
  }
165
146
  }
166
- }
147
+ },
148
+ {},
149
+ "render-btns-container-click"
167
150
  );
168
151
 
169
152
  this.$titleBar.appendChild($titleArea);
@@ -203,8 +186,6 @@ export class DefaultTitleBar implements TeleTitleBar {
203
186
  this.sideEffect.flushAll();
204
187
  if (this.$titleBar) {
205
188
  this.$titleBar = void 0;
206
- this.$title = void 0;
207
- this.$btns.length = 0;
208
189
  this.onDragStart = void 0;
209
190
  this.onEvent = void 0;
210
191
  }
@@ -214,15 +195,13 @@ export class DefaultTitleBar implements TeleTitleBar {
214
195
 
215
196
  public onDragStart?: TeleTitleBarConfig["onDragStart"];
216
197
 
217
- protected readonly: boolean;
198
+ protected readonly$: TeleTitleBarConfig["readonly$"];
218
199
 
219
- protected title?: string;
200
+ protected title$: ReadonlyVal<string>;
220
201
 
221
202
  protected buttons: ReadonlyArray<DefaultTitleBarButton>;
222
203
 
223
- protected state: TeleBoxState;
224
-
225
- protected $btns: HTMLButtonElement[] = [];
204
+ protected state$: TeleTitleBarConfig["state$"];
226
205
 
227
206
  protected sideEffect = new SideEffectManager();
228
207
 
@@ -233,7 +212,7 @@ export class DefaultTitleBar implements TeleTitleBar {
233
212
  };
234
213
 
235
214
  protected handleTitleBarClick = (ev: MouseEvent): void => {
236
- if (this.readonly) {
215
+ if (this.readonly$.value) {
237
216
  return;
238
217
  }
239
218
 
@@ -273,7 +252,7 @@ export class DefaultTitleBar implements TeleTitleBar {
273
252
  };
274
253
 
275
254
  protected handleTitleBarTouch = (ev: TouchEvent): void => {
276
- if (this.readonly) {
255
+ if (this.readonly$.value) {
277
256
  return;
278
257
  }
279
258
 
@@ -1,6 +1,9 @@
1
1
  @import "../../scss/variables.scss";
2
+ @import "../../scss/mixins.scss";
2
3
 
3
4
  .#{$namespace}-titlebar {
5
+ @include no-user-select;
6
+
4
7
  box-sizing: border-box;
5
8
  height: 26px;
6
9
  display: flex;
@@ -22,6 +25,8 @@
22
25
  }
23
26
 
24
27
  .#{$namespace}-title {
28
+ @include no-user-select;
29
+
25
30
  overflow: hidden;
26
31
  margin: 0;
27
32
  padding: 0;
@@ -53,6 +58,8 @@
53
58
  }
54
59
 
55
60
  .#{$namespace}-titlebar-btn {
61
+ @include no-user-select;
62
+
56
63
  width: 22px;
57
64
  height: 22px;
58
65
  padding: 0;
@@ -1,3 +1,4 @@
1
+ import type { ReadonlyVal } from "value-enhancer";
1
2
  import type { TeleBoxDelegateEventConfig, TeleBoxState } from "../TeleBox";
2
3
 
3
4
  export type TeleTitleBarEvent<U = keyof TeleBoxDelegateEventConfig> =
@@ -8,22 +9,15 @@ export type TeleTitleBarEvent<U = keyof TeleBoxDelegateEventConfig> =
8
9
  : never;
9
10
 
10
11
  export interface TeleTitleBarConfig {
11
- readonly?: boolean;
12
- title?: string;
13
- state?: TeleBoxState;
12
+ readonly$: ReadonlyVal<boolean, boolean>;
13
+ title$: ReadonlyVal<string, boolean>;
14
+ state$: ReadonlyVal<TeleBoxState, boolean>;
14
15
  namespace?: string;
15
16
  onEvent?: (event: TeleTitleBarEvent) => void;
16
17
  onDragStart?: (event: MouseEvent | TouchEvent) => void;
17
18
  }
18
19
 
19
20
  export interface TeleTitleBar {
20
- setTitle(title: string): void;
21
-
22
- setState(state: TeleBoxState): void;
23
-
24
- setReadonly(readonly: boolean): void;
25
-
26
21
  render(): HTMLElement;
27
-
28
22
  destroy(): void;
29
23
  }
package/src/index.ts CHANGED
@@ -2,6 +2,5 @@ import "./scss/fancy-scrollbar.scss";
2
2
 
3
3
  export * from "./TeleBox";
4
4
  export * from "./TeleTitleBar";
5
- export * from "./TeleBoxReact";
6
5
  export * from "./TeleBoxManager";
7
6
  export * from "./TeleBoxCollector";
@@ -0,0 +1,7 @@
1
+ @mixin no-user-select {
2
+ user-select: none;
3
+ // touch device
4
+ -webkit-touch-callout: none;
5
+ // iOS Safari
6
+ -webkit-user-select: none;
7
+ }
@@ -1,2 +1,5 @@
1
1
  $namespace: "telebox";
2
2
  $base-z-index: 100;
3
+ $max-titlebar-z-index: $base-z-index + 5000;
4
+ $stage-z-index: $max-titlebar-z-index + 10;
5
+ $collector-z-index: $stage-z-index + 10;
package/src/utils.ts CHANGED
@@ -15,12 +15,6 @@ export function flattenEvent(ev: MouseEvent | TouchEvent): MouseEvent | Touch {
15
15
  : (ev as MouseEvent);
16
16
  }
17
17
 
18
- export function genUniqueKey(): string {
19
- return (
20
- Date.now().toString().slice(6) + Math.random().toString().slice(2, 8)
21
- );
22
- }
23
-
24
18
  export function getRandomInt(min: number, max: number): number {
25
19
  min = Math.ceil(min);
26
20
  max = Math.floor(max);
@@ -1,5 +0,0 @@
1
- import { Meta, Story } from "@storybook/react";
2
- import { TeleBoxCollectorConfig } from ".";
3
- declare const storyMeta: Meta;
4
- export default storyMeta;
5
- export declare const Overview: Story<TeleBoxCollectorConfig>;
@@ -1,7 +0,0 @@
1
- import { Meta, Story } from "@storybook/react";
2
- import { MaxTitleBarReactProps } from "./MaxTitleBarReact";
3
- declare const storyMeta: Meta;
4
- export default storyMeta;
5
- export declare const Overview: Story<MaxTitleBarReactProps>;
6
- export declare const SingleBox: Story<MaxTitleBarReactProps>;
7
- export declare const BoxOverflows: Story<MaxTitleBarReactProps>;
@@ -1,4 +0,0 @@
1
- import { FC } from "react";
2
- import { MaxTitleBarConfig } from ".";
3
- export declare type MaxTitleBarReactProps = MaxTitleBarConfig;
4
- export declare const MaxTitleBarReact: FC<MaxTitleBarConfig>;
@@ -1,9 +0,0 @@
1
- import { Meta, Story } from "@storybook/react";
2
- import { TeleBoxReactProps } from ".";
3
- declare const storyMeta: Meta<TeleBoxReactProps>;
4
- export default storyMeta;
5
- export declare const Overview: Story<TeleBoxReactProps>;
6
- export declare const Resizable: Story<TeleBoxReactProps>;
7
- export declare const Draggable: Story<TeleBoxReactProps>;
8
- export declare const FixRatio: Story<TeleBoxReactProps>;
9
- export declare const Readonly: Story<TeleBoxReactProps>;