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

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.
@@ -21,8 +21,14 @@ export interface TeleBoxManagerConfig extends Pick<TeleBoxConfig, "namespace"> {
21
21
  readonly minimized?: boolean;
22
22
  /** Is box readonly */
23
23
  readonly readonly?: boolean;
24
- /** Show stage frame and grey-out the non-stage area. Default true. */
25
- readonly highlightStage?: boolean;
24
+ /** Custom styles for telebox manager container */
25
+ readonly containerStyle?: string;
26
+ /** Custom styles for telebox manager stage */
27
+ readonly stageStyle?: string;
28
+ /** Custom `style` attribute value for content area of all boxes. Can be overwritten by box. */
29
+ readonly defaultBoxBodyStyle?: string | null;
30
+ /** Custom `style` attribute value for stage area of all boxes. Can be overwritten by box. */
31
+ readonly defaultBoxStageStyle?: string | null;
26
32
  }
27
33
 
28
34
  type TeleBoxManagerBoxConfigBaseProps =
@@ -36,12 +42,18 @@ type TeleBoxManagerBoxConfigBaseProps =
36
42
  | "y"
37
43
  | "resizable"
38
44
  | "draggable"
39
- | "ratio"
40
- | "zIndex";
45
+ | "boxRatio"
46
+ | "zIndex"
47
+ | "stageRatio";
41
48
 
42
49
  export type TeleBoxManagerCreateConfig = Pick<
43
50
  TeleBoxConfig,
44
- TeleBoxManagerBoxConfigBaseProps | "content" | "footer" | "id" | "focus"
51
+ | TeleBoxManagerBoxConfigBaseProps
52
+ | "content"
53
+ | "stage"
54
+ | "footer"
55
+ | "id"
56
+ | "focus"
45
57
  >;
46
58
 
47
59
  export type TeleBoxManagerQueryConfig = Pick<
@@ -50,7 +62,8 @@ export type TeleBoxManagerQueryConfig = Pick<
50
62
  | "visible"
51
63
  | "resizable"
52
64
  | "draggable"
53
- | "ratio"
65
+ | "boxRatio"
66
+ | "stageRatio"
54
67
  | "zIndex"
55
68
  | "id"
56
69
  | "focus"
@@ -58,7 +71,7 @@ export type TeleBoxManagerQueryConfig = Pick<
58
71
 
59
72
  export type TeleBoxManagerUpdateConfig = Pick<
60
73
  TeleBoxConfig,
61
- TeleBoxManagerBoxConfigBaseProps | "content" | "footer"
74
+ TeleBoxManagerBoxConfigBaseProps | "content" | "stage" | "footer"
62
75
  >;
63
76
 
64
77
  type CheckTeleBoxManagerConfig<
@@ -14,7 +14,7 @@ import type {
14
14
  TeleTitleBarEvent,
15
15
  } from "../typings";
16
16
  import { preventEvent } from "../../utils";
17
- import { Val } from "value-enhancer";
17
+ import type { ReadonlyVal } from "value-enhancer";
18
18
 
19
19
  export type DefaultTitleBarButton = TeleTitleBarEvent & {
20
20
  readonly iconClassName: string;
@@ -29,7 +29,7 @@ export class DefaultTitleBar implements TeleTitleBar {
29
29
  public constructor({
30
30
  readonly$,
31
31
  state$,
32
- title = "",
32
+ title$,
33
33
  buttons,
34
34
  onEvent,
35
35
  onDragStart,
@@ -37,7 +37,7 @@ export class DefaultTitleBar implements TeleTitleBar {
37
37
  }: DefaultTitleBarConfig) {
38
38
  this.readonly$ = readonly$;
39
39
  this.state$ = state$;
40
- this.title$ = new Val(title);
40
+ this.title$ = title$;
41
41
  this.onEvent = onEvent;
42
42
  this.onDragStart = onDragStart;
43
43
  this.namespace = namespace;
@@ -67,14 +67,6 @@ export class DefaultTitleBar implements TeleTitleBar {
67
67
 
68
68
  public $dragArea: HTMLElement;
69
69
 
70
- public get title(): string {
71
- return this.title$.value;
72
- }
73
-
74
- public setTitle(title: string): void {
75
- this.title$.setValue(title);
76
- }
77
-
78
70
  public render(): HTMLElement {
79
71
  if (!this.$titleBar) {
80
72
  this.$titleBar = document.createElement("div");
@@ -205,7 +197,7 @@ export class DefaultTitleBar implements TeleTitleBar {
205
197
 
206
198
  protected readonly$: TeleTitleBarConfig["readonly$"];
207
199
 
208
- protected title$: Val<string>;
200
+ protected title$: ReadonlyVal<string>;
209
201
 
210
202
  protected buttons: ReadonlyArray<DefaultTitleBarButton>;
211
203
 
@@ -10,7 +10,7 @@ export type TeleTitleBarEvent<U = keyof TeleBoxDelegateEventConfig> =
10
10
 
11
11
  export interface TeleTitleBarConfig {
12
12
  readonly$: ReadonlyVal<boolean, boolean>;
13
- title?: string;
13
+ title$: ReadonlyVal<string, boolean>;
14
14
  state$: ReadonlyVal<TeleBoxState, boolean>;
15
15
  namespace?: string;
16
16
  onEvent?: (event: TeleTitleBarEvent) => void;
@@ -1,2 +1,14 @@
1
1
  $namespace: "telebox";
2
+
2
3
  $base-z-index: 100;
4
+ $max-titlebar-z-index: $base-z-index + 5000;
5
+ $stage-z-index: $max-titlebar-z-index + 10;
6
+ $collector-z-index: $stage-z-index + 10;
7
+
8
+ $color-container-background: #f9f9f9;
9
+ $color-stage-background: #fff;
10
+ $color-stage-shadow: 0px 0px 16px rgba(0, 0, 0, 0.08);
11
+
12
+ $color-container-background-dark: #25282e;
13
+ $color-stage-background-dark: #272a30;
14
+ $color-stage-shadow-dark: 0px 0px 16px rgba(0, 0, 0, 0.24);
@@ -1,21 +0,0 @@
1
- import "./style.scss";
2
- import type { ReadonlyVal } from "value-enhancer";
3
- import type { TeleBoxRect } from "../TeleBox/typings";
4
- export interface TeleStageConfig {
5
- namespace: string;
6
- root$: ReadonlyVal<HTMLElement | null>;
7
- rootRect$: ReadonlyVal<TeleBoxRect>;
8
- ratio$: ReadonlyVal<number>;
9
- highlightStage$: ReadonlyVal<boolean>;
10
- }
11
- export declare class TeleStage {
12
- private readonly _sideEffect;
13
- readonly namespace: string;
14
- readonly stageRect$: ReadonlyVal<TeleBoxRect>;
15
- readonly highlightStage$: ReadonlyVal<boolean>;
16
- $boxStage?: HTMLDivElement;
17
- constructor({ namespace, rootRect$, ratio$, highlightStage$, root$, }: TeleStageConfig);
18
- private render;
19
- destroy(): void;
20
- wrapClassName(className: string): string;
21
- }
@@ -1,178 +0,0 @@
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
- }
@@ -1,49 +0,0 @@
1
- @import "../scss/variables.scss";
2
-
3
- .#{$namespace}-box-stage-container {
4
- display: none;
5
- position: absolute;
6
- z-index: $base-z-index - 1;
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
- }