@netless/telebox-insider 0.2.26 → 1.0.0-alpha.3

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 (48) 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 +1 -0
  23. package/src/TeleBox/typings.ts +42 -75
  24. package/src/TeleBoxCollector/index.ts +136 -159
  25. package/src/TeleBoxManager/MaxTitleBar/index.ts +95 -108
  26. package/src/TeleBoxManager/constants.ts +0 -3
  27. package/src/TeleBoxManager/index.ts +325 -336
  28. package/src/TeleBoxManager/typings.ts +42 -52
  29. package/src/TeleStage/index.ts +178 -0
  30. package/src/TeleStage/style.scss +49 -0
  31. package/src/TeleTitleBar/DefaultTitleBar/index.ts +48 -61
  32. package/src/TeleTitleBar/typings.ts +3 -9
  33. package/src/index.ts +0 -1
  34. package/src/utils.ts +0 -6
  35. package/dist/TeleBoxCollector/TeleBoxCollector.stories.d.ts +0 -5
  36. package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.d.ts +0 -7
  37. package/dist/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.d.ts +0 -4
  38. package/dist/TeleBoxReact/TeleBox.stories.d.ts +0 -9
  39. package/dist/TeleBoxReact/index.d.ts +0 -17
  40. package/dist/TeleBoxReact/utils.d.ts +0 -2
  41. package/dist/TeleTitleBar/DefaultTitleBar/DefaultTitleBar.stories.d.ts +0 -4
  42. package/src/TeleBoxCollector/TeleBoxCollector.stories.tsx +0 -23
  43. package/src/TeleBoxManager/MaxTitleBar/MaxTitleBar.stories.tsx +0 -66
  44. package/src/TeleBoxManager/MaxTitleBar/MaxTitleBarReact.tsx +0 -34
  45. package/src/TeleBoxReact/TeleBox.stories.tsx +0 -74
  46. package/src/TeleBoxReact/index.tsx +0 -175
  47. package/src/TeleBoxReact/utils.ts +0 -14
  48. 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,178 @@
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$, highlightStage$, ratio$],
38
+ ([rootRect, highlightStage, ratio]) => {
39
+ if (!highlightStage) {
40
+ return rootRect;
41
+ }
42
+
43
+ if (ratio <= 0 || rootRect.width <= 0 || rootRect.height <= 0) {
44
+ return rootRect;
45
+ }
46
+
47
+ const preferredHeight = rootRect.width * ratio;
48
+ if (preferredHeight === rootRect.height) {
49
+ return rootRect;
50
+ }
51
+
52
+ if (preferredHeight < rootRect.height) {
53
+ return {
54
+ x: 0,
55
+ y: (rootRect.height - preferredHeight) / 2,
56
+ width: rootRect.width,
57
+ height: preferredHeight,
58
+ };
59
+ }
60
+
61
+ const preferredWidth = rootRect.height / ratio;
62
+ return {
63
+ x: (rootRect.width - preferredWidth) / 2,
64
+ y: 0,
65
+ width: preferredWidth,
66
+ height: rootRect.height,
67
+ };
68
+ },
69
+ { compare: shallowequal }
70
+ );
71
+
72
+ this._sideEffect.addDisposer(
73
+ combine([root$, highlightStage$]).subscribe(
74
+ ([root, highlightStage]) => {
75
+ if (root && highlightStage) {
76
+ root.appendChild(this.render());
77
+ } else if (this.$boxStage?.parentNode) {
78
+ this.$boxStage.remove();
79
+ }
80
+ }
81
+ )
82
+ );
83
+ }
84
+
85
+ private render(): HTMLDivElement {
86
+ if (this.$boxStage) {
87
+ return this.$boxStage;
88
+ }
89
+
90
+ const $boxStage = document.createElement("div");
91
+ $boxStage.className = this.wrapClassName("box-stage-container");
92
+ const $boxStageMask1 = document.createElement("div");
93
+ $boxStageMask1.className = this.wrapClassName("box-stage-mask");
94
+ const $boxStageMask2 = document.createElement("div");
95
+ $boxStageMask2.className = this.wrapClassName("box-stage-mask");
96
+ const $boxStageFrame = document.createElement("div");
97
+ $boxStageFrame.className = this.wrapClassName("box-stage-frame");
98
+
99
+ const [
100
+ $topLeftCorner,
101
+ $topRightCorner,
102
+ $bottomLeftCorner,
103
+ $bottomRightCorner,
104
+ ] = [
105
+ "M0 8V0h8v2H2v6H0Z",
106
+ "M8 8V0H0v2h6v6h2Z",
107
+ "M0 0v8h8V6H2V0H0Z",
108
+ "M8 0v8H0V6h6V0h2Z",
109
+ ].map((path, i) => {
110
+ const $svg = document.createElementNS(
111
+ "http://www.w3.org/2000/svg",
112
+ "svg"
113
+ );
114
+ $svg.setAttribute("viewBox", "0 0 8 8");
115
+ $svg.setAttribute(
116
+ "class",
117
+ `${this.wrapClassName("box-stage-frame-corner")} is-${i}`
118
+ );
119
+ const $path = document.createElementNS(
120
+ "http://www.w3.org/2000/svg",
121
+ "path"
122
+ );
123
+ $path.setAttribute("d", path);
124
+ $path.setAttribute("fill", "#3381FF");
125
+ $svg.appendChild($path);
126
+ return $svg;
127
+ });
128
+
129
+ $boxStageFrame.appendChild($topLeftCorner);
130
+ $boxStageFrame.appendChild($bottomLeftCorner);
131
+ $boxStageFrame.appendChild($topRightCorner);
132
+ $boxStageFrame.appendChild($bottomRightCorner);
133
+
134
+ $boxStage.appendChild($boxStageMask1);
135
+ $boxStage.appendChild($boxStageFrame);
136
+ $boxStage.appendChild($boxStageMask2);
137
+
138
+ this._sideEffect.addDisposer(
139
+ this.highlightStage$.subscribe((highlightStage) => {
140
+ $boxStage.classList.toggle("is-active", highlightStage);
141
+ })
142
+ );
143
+
144
+ this._sideEffect.addDisposer(
145
+ combine([this.highlightStage$, this.stageRect$]).subscribe(
146
+ ([highlightStage, stageRect]) => {
147
+ if (!highlightStage) {
148
+ return;
149
+ }
150
+ if (stageRect.x > 0) {
151
+ $boxStage.style.flexDirection = "row";
152
+ $boxStageMask1.style.width = `${stageRect.x}px`;
153
+ $boxStageMask1.style.height = "";
154
+ $boxStageMask2.style.width = `${stageRect.x}px`;
155
+ $boxStageMask2.style.height = "";
156
+ } else if (stageRect.y > 0) {
157
+ $boxStage.style.flexDirection = "column";
158
+ $boxStageMask1.style.width = "";
159
+ $boxStageMask1.style.height = `${stageRect.y}px`;
160
+ $boxStageMask2.style.width = "";
161
+ $boxStageMask2.style.height = `${stageRect.y}px`;
162
+ }
163
+ }
164
+ )
165
+ );
166
+
167
+ this.$boxStage = $boxStage;
168
+ return $boxStage;
169
+ }
170
+
171
+ public destroy(): void {
172
+ this._sideEffect.flushAll();
173
+ }
174
+
175
+ public wrapClassName(className: string): string {
176
+ return `${this.namespace}-${className}`;
177
+ }
178
+ }
@@ -0,0 +1,49 @@
1
+ @import "../scss/variables.scss";
2
+
3
+ .#{$namespace}-box-stage-container {
4
+ display: none;
5
+ position: absolute;
6
+ z-index: $base-z-index + 2000;
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 { Val } 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$ = new Val(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,37 +65,14 @@ 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
- }
70
+ public get title(): string {
71
+ return this.title$.value;
92
72
  }
93
73
 
94
- public setReadonly(readonly: boolean): void {
95
- if (this.readonly !== readonly) {
96
- this.readonly = readonly;
97
- }
74
+ public setTitle(title: string): void {
75
+ this.title$.setValue(title);
98
76
  }
99
77
 
100
78
  public render(): HTMLElement {
@@ -106,21 +84,17 @@ export class DefaultTitleBar implements TeleTitleBar {
106
84
  $titleArea.className = this.wrapClassName("title-area");
107
85
  $titleArea.dataset.teleBoxHandle = TeleBoxDragHandleType;
108
86
 
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
- }
87
+ const $title = document.createElement("h1");
88
+ $title.className = this.wrapClassName("title");
89
+ $title.dataset.teleBoxHandle = TeleBoxDragHandleType;
116
90
 
117
- $titleArea.appendChild(this.$title);
91
+ $titleArea.appendChild($title);
118
92
  $titleArea.appendChild(this.$dragArea);
119
93
 
120
94
  const $buttonsContainer = document.createElement("div");
121
95
  $buttonsContainer.className = this.wrapClassName("titlebar-btns");
122
96
 
123
- this.buttons.forEach(({ iconClassName, isActive }, i) => {
97
+ this.buttons.forEach(({ iconClassName }, i) => {
124
98
  const teleTitleBarBtnIndex = String(i);
125
99
 
126
100
  const $btn = document.createElement("button");
@@ -129,21 +103,36 @@ export class DefaultTitleBar implements TeleTitleBar {
129
103
  )} ${iconClassName}`;
130
104
  $btn.dataset.teleTitleBarBtnIndex = teleTitleBarBtnIndex;
131
105
  $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
106
  $buttonsContainer.appendChild($btn);
140
107
  });
141
108
 
109
+ this.sideEffect.addDisposer(
110
+ this.title$.subscribe((title) => {
111
+ $title.textContent = title;
112
+ $title.title = title;
113
+ }),
114
+ "render-title"
115
+ );
116
+
117
+ this.sideEffect.addDisposer(
118
+ this.state$.subscribe((state) => {
119
+ this.buttons.forEach((btn, i) => {
120
+ if (btn.isActive) {
121
+ $buttonsContainer.children[i]?.classList.toggle(
122
+ "is-active",
123
+ btn.isActive(state)
124
+ );
125
+ }
126
+ });
127
+ }),
128
+ "render-state-btns"
129
+ );
130
+
142
131
  this.sideEffect.addEventListener(
143
132
  $buttonsContainer,
144
133
  "click",
145
134
  (ev) => {
146
- if (this.readonly) {
135
+ if (this.readonly$.value) {
147
136
  return;
148
137
  }
149
138
  const target = ev.target as HTMLElement;
@@ -163,7 +152,9 @@ export class DefaultTitleBar implements TeleTitleBar {
163
152
  } as TeleTitleBarEvent);
164
153
  }
165
154
  }
166
- }
155
+ },
156
+ {},
157
+ "render-btns-container-click"
167
158
  );
168
159
 
169
160
  this.$titleBar.appendChild($titleArea);
@@ -203,8 +194,6 @@ export class DefaultTitleBar implements TeleTitleBar {
203
194
  this.sideEffect.flushAll();
204
195
  if (this.$titleBar) {
205
196
  this.$titleBar = void 0;
206
- this.$title = void 0;
207
- this.$btns.length = 0;
208
197
  this.onDragStart = void 0;
209
198
  this.onEvent = void 0;
210
199
  }
@@ -214,15 +203,13 @@ export class DefaultTitleBar implements TeleTitleBar {
214
203
 
215
204
  public onDragStart?: TeleTitleBarConfig["onDragStart"];
216
205
 
217
- protected readonly: boolean;
206
+ protected readonly$: TeleTitleBarConfig["readonly$"];
218
207
 
219
- protected title?: string;
208
+ protected title$: Val<string>;
220
209
 
221
210
  protected buttons: ReadonlyArray<DefaultTitleBarButton>;
222
211
 
223
- protected state: TeleBoxState;
224
-
225
- protected $btns: HTMLButtonElement[] = [];
212
+ protected state$: TeleTitleBarConfig["state$"];
226
213
 
227
214
  protected sideEffect = new SideEffectManager();
228
215
 
@@ -233,7 +220,7 @@ export class DefaultTitleBar implements TeleTitleBar {
233
220
  };
234
221
 
235
222
  protected handleTitleBarClick = (ev: MouseEvent): void => {
236
- if (this.readonly) {
223
+ if (this.readonly$.value) {
237
224
  return;
238
225
  }
239
226
 
@@ -273,7 +260,7 @@ export class DefaultTitleBar implements TeleTitleBar {
273
260
  };
274
261
 
275
262
  protected handleTitleBarTouch = (ev: TouchEvent): void => {
276
- if (this.readonly) {
263
+ if (this.readonly$.value) {
277
264
  return;
278
265
  }
279
266
 
@@ -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
+ readonly$: ReadonlyVal<boolean, boolean>;
12
13
  title?: string;
13
- state?: TeleBoxState;
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";
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>;
@@ -1,17 +0,0 @@
1
- import { FC } from "react";
2
- import { TeleBoxConfig, TeleBoxState } from "../TeleBox/typings";
3
- export declare type TeleBoxReactProps = TeleBoxConfig & {
4
- onResize?: (event: {
5
- width: number;
6
- height: number;
7
- }) => void;
8
- onMove?: (event: {
9
- x: number;
10
- y: number;
11
- }) => void;
12
- onClose?: () => void;
13
- onFocus?: () => void;
14
- onBlur?: () => void;
15
- onStateChanged?: (state: TeleBoxState) => void;
16
- };
17
- export declare const TeleBoxReact: FC<TeleBoxReactProps>;
@@ -1,2 +0,0 @@
1
- import { useEffect } from "react";
2
- export declare const useUpdateEffect: typeof useEffect;
@@ -1,4 +0,0 @@
1
- import { Meta, Story } from "@storybook/react";
2
- declare const storyMeta: Meta;
3
- export default storyMeta;
4
- export declare const LongTitle: Story;